-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjoint.ui.toolbar.min.js
More file actions
14 lines (8 loc) · 15.3 KB
/
joint.ui.toolbar.min.js
File metadata and controls
14 lines (8 loc) · 15.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/*! Rappid v3.1.1 - HTML5 Diagramming Framework - TRIAL VERSION
Copyright (c) 2015 client IO
2020-06-11
This Source Code Form is subject to the terms of the Rappid Trial License
, v. 2.0. If a copy of the Rappid License was not distributed with this
file, You can obtain one at http://jointjs.com/license/rappid_v2.txt
or from the Rappid archive as was distributed by client IO. See the LICENSE file.*/
this.joint=this.joint||{},function(t,u,o,e,i){"use strict";o=o&&o.hasOwnProperty("default")?o.default:o;var r=u.mvc.View.extend({className:"widget",references:[],constructor:function(t,e){this.availableReferences=e||{},u.mvc.View.prototype.constructor.call(this,t)},updateAttrs:function(t){u.util.setAttributesBySelector(this.$el,t)},bindEvents:function(){},validateReferences:function(){var t=this.references||[],e=[];return t.forEach(function(t){void 0===this.availableReferences[t]&&e.push(t)},this),e},getReference:function(t){return this.availableReferences[t]},getReferences:function(){return this.availableReferences},enable:function(){},disable:function(){},isDisabled:function(){return!1}}),n=r.extend({tagName:"label",events:{"change .input":"onChange",mousedown:"pointerdown",touchstart:"pointerdown",mouseup:"pointerup",touchend:"pointerup",click:"pointerclick"},documentEvents:{mouseup:"pointerup",touchend:"pointerup"},init:function(){u.util.bindAll(this,"pointerup")},render:function(){var t=this.options,e=o("<span/>").text(t.label||"");return this.$input=o("<input/>",{type:"checkbox",class:"input"}).prop("checked",!!t.value),this.$span=o("<span/>"),this.$el.append([e,this.$input,this.$span]),this},onChange:function(t){this.trigger("change",!!t.target.checked,t)},pointerdown:function(t){t=u.util.normalizeEvent(t),this.$el.addClass("is-in-action"),this.trigger("pointerdown",t),this.delegateDocumentEvents()},pointerclick:function(t){t=u.util.normalizeEvent(t),this.trigger("pointerclick",t)},pointerup:function(t){t=u.util.normalizeEvent(t),this.undelegateDocumentEvents(),this.trigger("pointerup",t),this.$el.removeClass("is-in-action"),"touchend"===t.type&&(this.$input.trigger("click"),t.preventDefault())},isDisabled:function(){return this.$input.prop("disabled")},enable:function(){this.$el.removeClass("disabled"),this.$input.prop("disabled",!1)},disable:function(){this.$el.addClass("disabled"),this.$input.prop("disabled",!0)}}),s=r.extend({tagName:"label",events:{"change input.toggle":"onChange","click input.toggle":"pointerclick",mousedown:"pointerdown",touchstart:"pointerdown",mouseup:"pointerup",touchend:"pointerup"},documentEvents:{mouseup:"pointerup",touchend:"pointerup"},init:function(){u.util.bindAll(this,"pointerup")},render:function(){var t=this.options,e=o("<span/>").text(t.label||""),i=o("<span><i/></span>");this.$input=o("<input/>",{type:"checkbox",class:"toggle"}).prop("checked",!!t.value);var n=o("<div/>").addClass(t.type);return this.$el.append([e,n.append(this.$input,i)]),this},onChange:function(t){this.trigger("change",!!t.target.checked,t)},pointerclick:function(t){t=u.util.normalizeEvent(t),this.trigger("pointerclick",t)},pointerdown:function(t){t=u.util.normalizeEvent(t),this.$el.addClass("is-in-action"),this.trigger("pointerdown",t),this.delegateDocumentEvents()},pointerup:function(t){t=u.util.normalizeEvent(t),this.undelegateDocumentEvents(),this.$el.removeClass("is-in-action"),this.trigger("pointerup",t),"touchend"===t.type&&(this.$input.trigger("click"),t.preventDefault())},isDisabled:function(){return this.$input.prop("disabled")},enable:function(){this.$el.removeClass("disabled"),this.$input.prop("disabled",!1)},disable:function(){this.$el.addClass("disabled"),this.$input.prop("disabled",!0)}}),a=r.extend({render:function(){return this.options.width&&this.$el.css({width:this.options.width}),this}}),l=r.extend({tagName:"label",render:function(){return this.$el.text(this.options.text),this}}),p=r.extend({events:{"change .input":"onChange","input .input":"onChange"},render:function(){var t,e=this.options;return this.$output=o("<output/>").text(e.value),t=o("<span/>").addClass("units").text(e.unit),this.$input=o("<input/>",{type:"range",name:e.type,min:e.min,max:e.max,step:e.step,class:"input"}).val(e.value),this.$el.append([this.$input,this.$output,t]),this},onChange:function(t){var e=this.getValue();e!==this.currentValue&&(this.currentValue=e,this.$output.text(e),this.trigger("change",e,t))},getValue:function(){return parseInt(this.$input.val(),10)},setValue:function(t,e){void 0===e&&(e={}),this.$input.val(t),e.silent?(t=this.getValue(),this.currentValue=t,this.$output.text(t)):this.$input.trigger("change")},isDisabled:function(){return this.$input.prop("disabled")},enable:function(){this.$input.prop("disabled",!1)},disable:function(){this.$input.prop("disabled",!0)}}),c=r.extend({render:function(){var t=u.util.omit(this.options,"type","group","index");return this.selectBox=new e.SelectBox(t),this.selectBox.render().$el.appendTo(this.el),this},bindEvents:function(){this.selectBox.on("all",this.trigger,this)},isDisabled:function(){return this.selectBox.isDisabled()},enable:function(){this.selectBox.enable()},disable:function(){this.selectBox.disable()}}),h=r.extend({events:{mousedown:"pointerdown",mouseup:"pointerup",touchend:"pointerup",touchstart:"pointerdown",click:"pointerclick"},tagName:"button",render:function(){var t=this.options;return this.$el.text(t.text),this},pointerclick:function(t){t=u.util.normalizeEvent(t),this.trigger("pointerclick",t)},pointerdown:function(t){t=u.util.normalizeEvent(t),this.trigger("pointerdown",t)},pointerup:function(t){t=u.util.normalizeEvent(t),this.trigger("pointerup",t),"touchend"===t.type&&(this.$el.trigger("click"),t.preventDefault())},isDisabled:function(){return this.$el.prop("disabled")},enable:function(){this.$el.prop("disabled",!1)},disable:function(){this.$el.prop("disabled",!0)}}),d=r.extend({events:{mousedown:"pointerdown",touchstart:"pointerdown",mouseup:"pointerup",touchend:"pointerup",click:"pointerclick",focusin:"pointerfocusin",focusout:"pointerfocusout"},tagName:"div",render:function(){var t=this.options;return this.$label=o("<label/>").text(t.label),this.$text=o("<input/>",{type:"text",class:"input"}).val(t.value),this.$input=o("<div/>").addClass("input-wrapper").append(this.$text),this.$el.append([this.$label,this.$input]),this},pointerclick:function(t){t=u.util.normalizeEvent(t),this.trigger("pointerclick",t)},pointerdown:function(t){t=u.util.normalizeEvent(t),this.trigger("pointerdown",t),"touchstart"===t.type&&this.$text.trigger("focus")},pointerup:function(t){t=u.util.normalizeEvent(t),this.trigger("pointerup",t),"touchend"===t.type&&(this.$text.trigger("click"),t.preventDefault())},pointerfocusin:function(t){t=u.util.normalizeEvent(t),this.$el.addClass("is-focused"),this.trigger("pointerfocusin",t)},pointerfocusout:function(t){t=u.util.normalizeEvent(t),this.$el.removeClass("is-focused"),this.trigger("pointerfocusout",t)},isDisabled:function(){return this.$text.prop("disabled")},enable:function(){this.$text.prop("disabled",!1)},disable:function(){this.$text.prop("disabled",!0)}}),g=r.extend({events:{mousedown:"pointerdown",touchstart:"pointerdown",mouseup:"pointerup",touchend:"pointerup",click:"pointerclick",focusin:"pointerfocusin",focusout:"pointerfocusout"},tagName:"div",render:function(){var t=this.options;return this.$label=o("<label/>").text(t.label),this.$number=o("<input/>",{type:"number",class:"number",max:t.max,min:t.min}).val(t.value),this.$input=o("<div/>").addClass("input-wrapper").append(this.$number),this.$el.append([this.$label,this.$input]),this},pointerclick:function(t){t=u.util.normalizeEvent(t),this.trigger("pointerclick",t)},pointerdown:function(t){t=u.util.normalizeEvent(t),this.trigger("pointerdown",t),"touchstart"===t.type&&this.$number.trigger("focus")},pointerup:function(t){t=u.util.normalizeEvent(t),this.trigger("pointerup",t),"touchend"===t.type&&(this.$number.trigger("click"),t.preventDefault())},pointerfocusin:function(t){t=u.util.normalizeEvent(t),this.$el.addClass("is-focused"),this.trigger("pointerfocusin",t)},pointerfocusout:function(t){t=u.util.normalizeEvent(t),this.$el.removeClass("is-focused"),this.trigger("pointerfocusout",t)},isDisabled:function(){return this.$number.prop("disabled")},enable:function(){this.$number.prop("disabled",!1)},disable:function(){this.$number.prop("disabled",!0)}}),f=r.extend({events:{mousedown:"pointerdown",touchstart:"pointerdown",mouseup:"pointerup",touchend:"pointerup",click:"pointerclick",focusin:"pointerfocusin",focusout:"pointerfocusout"},tagName:"div",render:function(){var t=this.options;return this.$label=o("<label/>").text(t.label),this.$textarea=o("<textarea/>",{class:"textarea"}).text(t.value),this.$input=o("<div/>").addClass("input-wrapper").append(this.$textarea),this.$el.append([this.$label,this.$input]),this},pointerclick:function(t){t.preventDefault(),t=u.util.normalizeEvent(t),this.trigger("pointerclick",t)},pointerdown:function(t){t=u.util.normalizeEvent(t),this.trigger("pointerdown",t),"touchstart"===t.type&&this.$textarea.focus()},pointerup:function(t){t=u.util.normalizeEvent(t),this.trigger("pointerup",t),"touchend"===t.type&&(this.$textarea.trigger("click"),t.preventDefault())},pointerfocusin:function(t){t=u.util.normalizeEvent(t),this.$el.addClass("is-focused"),this.trigger("pointerfocusin",t)},pointerfocusout:function(t){t=u.util.normalizeEvent(t),this.$el.removeClass("is-focused"),this.trigger("pointerfocusout",t)},isDisabled:function(){return this.$textarea.prop("disabled")},enable:function(){this.$textarea.prop("disabled",!1)},disable:function(){this.$textarea.prop("disabled",!0)}}),v=r.extend({render:function(){var t=u.util.omit(this.options,"type","group","index");return this.selectButtonGroup=new i.SelectButtonGroup(t),this.selectButtonGroup.render().$el.appendTo(this.el),this},bindEvents:function(){this.selectButtonGroup.on("all",this.trigger,this)},isDisabled:function(){return this.selectButtonGroup.isDisabled()},enable:function(){this.selectButtonGroup.enable()},disable:function(){this.selectButtonGroup.disable()}}),m=h.extend({references:["paperScroller"],options:{min:.2,max:5,step:.2},bindEvents:function(){var t=this;if(this.options.autoToggle){var e=this.getReferences().paperScroller;this.updateAvailability(e),this.listenTo(e.options.paper,"scale",function(){return t.updateAvailability(e)})}},pointerdown:function(t){var e=this.options;this.getReferences().paperScroller.zoom(e.step,{max:e.max,grid:e.step}),h.prototype.pointerdown.call(this,t)},updateAvailability:function(t){t.zoom()<this.options.max?this.enable():this.disable()}}),b=h.extend({references:["paperScroller"],options:{min:.2,max:5,step:.2},bindEvents:function(){var t=this;if(this.options.autoToggle){var e=this.getReferences().paperScroller;this.updateAvailability(e),this.listenTo(e.options.paper,"scale",function(){return t.updateAvailability(e)})}},pointerdown:function(t){var e=this.options;this.getReferences().paperScroller.zoom(-e.step,{min:e.min,grid:e.step}),h.prototype.pointerdown.call(this,t)},updateAvailability:function(t){t.zoom()>this.options.min?this.enable():this.disable()}}),$=h.extend({references:["paperScroller"],options:{min:.2,max:5,step:.2},pointerdown:function(t){var e=this.options;this.getReferences().paperScroller.zoomToFit({padding:20,scaleGrid:e.step,minScale:e.min,maxScale:e.max}),h.prototype.pointerdown.call(this,t)}}),x=p.extend({references:["paperScroller"],options:{min:20,max:500,step:20,value:100,unit:" %"},bindEvents:function(){var e=this,i=this.getReferences().paperScroller;this.on("change",function(t){i.zoom(t/100,{absolute:!0,grid:this.options.step/100})},this),this.listenTo(i.options.paper,"scale",function(t){e.setValue(Math.floor(100*t),{silent:!0})})}}),w=h.extend({references:["commandManager"],bindEvents:function(){var t=this;if(this.options.autoToggle){var e=this.getReferences().commandManager;this.updateAvailability(e),this.listenTo(e,"stack",function(){return t.updateAvailability(e)})}},pointerclick:function(){this.getReferences().commandManager.undo()},updateAvailability:function(t){t.hasUndo()?this.enable():this.disable()}}),y=h.extend({references:["commandManager"],bindEvents:function(){var t=this;if(this.options.autoToggle){var e=this.getReferences().commandManager;this.updateAvailability(e),this.listenTo(e,"stack",function(){return t.updateAvailability(e)})}},pointerclick:function(){this.getReferences().commandManager.redo()},updateAvailability:function(t){t.hasRedo()?this.enable():this.disable()}}),k=h.extend({onRender:function(){var t=this.target=o(this.options.target)[0];t&&!o.contains(window.top.document,t)&&this.$el.hide()},pointerclick:function(){u.util.toggleFullScreen(this.target)}}),E=Object.freeze({checkbox:n,toggle:s,separator:a,label:l,range:p,selectBox:c,button:h,inputText:d,inputNumber:g,textarea:f,selectButtonGroup:v,zoomIn:m,zoomOut:b,zoomToFit:$,zoomSlider:x,undo:w,redo:y,fullscreen:k});r.create=function(t,e){var i=u.util.camelCase(u.util.isString(t)?t:t.type);if(!u.util.isFunction(E[i]))throw new Error('Widget: unable to find widget: "'+i+'"');var n=new E[i](t,e),o=n.validateReferences(e);if(0<o.length)throw new Error('Widget: "'+i+'" missing dependency: '+o.join(", "));return n.render(),n.updateAttrs(t.attrs),n.bindEvents(),n.$el.attr("data-type",i),t.name&&n.$el.attr("data-name",t.name),n};var z=u.mvc.View.extend({options:{autoToggle:!1},align:["left","right"],className:"toolbar",defaultGroup:"default",widgets:[],groupViews:[],init:function(){this.tools=u.util.toArray(this.options.tools),this.groups=this.options.groups||{}},getWidgetByName:function(e){return this.widgets.find(function(t){return t.options.name===e})},getWidgets:function(){return this.widgets},groupsWithItemsPairs:function(){var i={};this.tools.forEach(function(t){var e=t.group||this.defaultGroup;i[e]=i[e]||{items:[],group:{}},i[e].items.push(t),i[e].group=this.groups[e]||{}},this);for(var t=Object.keys(i),e=[],n=0,o=t.length;n<o;n++){var s=t[n];e.push([s,i[s]])}var r=u.util.sortBy(e,function(t){return t[1].group.index});return u.util.sortBy(r,function(t){return t[1].group.align||"left"})},render:function(){var t=this.groupsWithItemsPairs(),o=!1;return t.forEach(function(t){var e=t[0],i=t[1],n=this.renderGroup(e,i);!o&&i.group.align&&"right"===i.group.align&&(o=!0,n.addClass("group-first")),n.appendTo(this.el)},this),this},renderGroup:function(t,e){var i=this.options,n=i.references,o=i.autoToggle,s=new C({name:t,align:e.group.align,items:e.items,references:n,autoToggle:o});return this.groupViews.push(s),s.on("all",function(){this.trigger.apply(this,arguments)}.bind(this)),s.render(),this.widgets=this.widgets.concat(s.widgets),s.$el},onRemove:function(){u.util.invoke(this.groupViews,"off"),u.util.invoke(this.groupViews,"remove")}}),C=u.mvc.View.extend({className:"toolbar-group",init:function(){this.widgets=[]},onRender:function(){this.$el.attr("data-group",this.options.name),this.$el.addClass(this.options.align),this.renderItems()},renderItems:function(){u.util.toArray(this.options.items).forEach(function(t){var e=this.createWidget(t);this.$el.append(e.$el)},this)},createWidget:function(i){var t=this.options,e=t.references,n=t.autoToggle,o=u.util.isString(i)?{autoToggle:n,type:i}:Object.assign({autoToggle:n},i),s=r.create(o,e);return s.on("all",function(t){var e=Array.prototype.slice.call(arguments,1);this.trigger.apply(this,[i.name+":"+t].concat(e))}.bind(this)),this.widgets.push(s),s},onRemove:function(){u.util.invoke(this.widgets,"off"),u.util.invoke(this.widgets,"remove")}});t.Toolbar=z}(this.joint.ui=this.joint.ui||{},joint,$,joint.ui,joint.ui);