-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjoint.dia.command.min.js
More file actions
14 lines (8 loc) · 5.46 KB
/
joint.dia.command.min.js
File metadata and controls
14 lines (8 loc) · 5.46 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,a,c){"use strict";var i=(a=a&&a.hasOwnProperty("default")?a.default:a).Model.extend({defaults:{cmdBeforeAdd:null,cmdNameRegex:/^(?:add|remove|change:\w+)$/,applyOptionsList:["propertyPath"],revertOptionsList:["propertyPath"]},PREFIX_LENGTH:7,initialize:function(t){c.util.bindAll(this,"initBatchCommand","storeBatchCommand"),this.graph=t.graph,this.reset(),this.listen()},listen:function(){this.listenTo(this.graph,"all",this.addCommand,this),this.listenTo(this.graph,"batch:start",this.initBatchCommand,this),this.listenTo(this.graph,"batch:stop",this.storeBatchCommand,this)},createCommand:function(t){return{action:void 0,data:{id:void 0,type:void 0,previous:{},next:{}},batch:t&&t.batch}},push:function(t,a){this.redoStack=[],t.batch?(this.lastCmdIndex=Math.max(this.lastCmdIndex,0),this.trigger("batch",t)):(this.undoStack.push(t),this.notifyStackChange("push",t,a),this.trigger("add",t))},addCommand:function(i,n,t,a){if((!a||!a.dry)&&this.get("cmdNameRegex").test(i)&&("function"!=typeof this.get("cmdBeforeAdd")||this.get("cmdBeforeAdd").apply(this,arguments))){var e=void 0,s=n instanceof c.dia.Graph;if(this.batchCommand){e=this.batchCommand[Math.max(this.lastCmdIndex,0)];var h=s&&!e.graphChange||e.data.id!==n.id,o=e.action!==i;if(0<=this.lastCmdIndex&&(h||o)){var d=this.batchCommand.findIndex(function(t,a){return(s&&t.graphChange||t.data.id===n.id)&&t.action===i});d<0||"add"===i||"remove"===i?e=this.createCommand({batch:!0}):(e=this.batchCommand[d],this.batchCommand.splice(d,1)),this.lastCmdIndex=this.batchCommand.push(e)-1}}else e=this.createCommand({batch:!1});if("add"===i||"remove"===i)return e.action=i,e.data.id=n.id,e.data.type=n.attributes.type,e.data.attributes=c.util.merge({},n.toJSON()),e.options=a||{},void this.push(e,a);var r=i.substr(this.PREFIX_LENGTH);e.batch&&e.action||(e.action=i,e.data.previous[r]=c.util.clone(n.previous(r)),e.options=a||{},s?e.graphChange=!0:(e.data.id=n.id,e.data.type=n.attributes.type)),e.data.next[r]=c.util.clone(n.get(r)),this.push(e,a)}},initBatchCommand:function(){this.batchCommand?this.batchLevel++:(this.batchCommand=[this.createCommand({batch:!0})],this.lastCmdIndex=-1,this.batchLevel=0)},storeBatchCommand:function(t){if(this.batchCommand&&this.batchLevel<=0){var a=this.filterBatchCommand(this.batchCommand);0<a.length&&(this.redoStack=[],this.undoStack.push(a),this.notifyStackChange("push",a,t),this.trigger("add",a)),this.batchCommand=null,this.lastCmdIndex=null,this.batchLevel=null}else this.batchCommand&&0<this.batchLevel&&this.batchLevel--},filterBatchCommand:function(t){for(var a=t.slice(),i=[];0<a.length;){var n=a.shift(),e=n.data.id;if(null!=n.action&&(null!=e||n.graphChange)){if("add"===n.action){var s=a.findIndex(function(t){return"remove"===t.action&&t.data&&t.data.id===e});if(0<=s){a=a.filter(function(t,a){return s<a||t.data.id!==e});continue}}else if("remove"===n.action){var h=a.findIndex(function(t){return"add"===t.action&&t.data&&t.data.id==e});if(0<=h){a.splice(h,1);continue}}else if(0===n.action.indexOf("change")&&c.util.isEqual(n.data.previous,n.data.next))continue;i.push(n)}}return i},revertCommand:function(t,a){var i;this.stopListening(),i=Array.isArray(t)?this.constructor.sortBatchCommands(t):[t];for(var n=this.graph,e=i.length-1;0<=e;e--){var s=i[e],h=s.graphChange?n:n.getCell(s.data.id),o=c.util.assign({commandManager:this.id||this.cid},a,c.util.pick(s.options,this.get("revertOptionsList")));switch(s.action){case"add":h.remove(o);break;case"remove":n.addCell(s.data.attributes,o);break;default:var d=s.action.substr(this.PREFIX_LENGTH);h.set(d,s.data.previous[d],o)}}this.listen()},applyCommand:function(t,a){var i;this.stopListening(),i=Array.isArray(t)?this.constructor.sortBatchCommands(t):[t];for(var n=this.graph,e=0;e<i.length;e++){var s=i[e],h=s.graphChange?n:n.getCell(s.data.id),o=c.util.assign({commandManager:this.id||this.cid},a,c.util.pick(s.options,this.get("applyOptionsList")));switch(s.action){case"add":n.addCell(s.data.attributes,o);break;case"remove":h.remove(o);break;default:var d=s.action.substr(this.PREFIX_LENGTH);h.set(d,s.data.next[d],o)}}this.listen()},undo:function(t){var a=this.undoStack.pop();a&&(this.revertCommand(a,t),this.redoStack.push(a),this.notifyStackChange("undo",a,t))},redo:function(t){var a=this.redoStack.pop();a&&(this.applyCommand(a,t),this.undoStack.push(a),this.notifyStackChange("redo",a,t))},cancel:function(t){var a=this.undoStack.pop();a&&(this.revertCommand(a,t),this.redoStack=[],this.notifyStackChange("cancel",a,t))},reset:function(t){this.undoStack=[],this.redoStack=[],this.notifyStackChange("reset",null,t)},hasUndo:function(){return 0<this.undoStack.length},hasRedo:function(){return 0<this.redoStack.length},notifyStackChange:function(t,a,i){var n,e;void 0===i&&(i={}),e=a?[Array.isArray(a)?a:[a],i]:[i],(n=this).trigger.apply(n,["stack:"+t].concat(e)),this.trigger("stack",i)}},{sortBatchCommands:function(t){for(var a=[],i=0;i<t.length;i++){var n=t[i],e=null;if("add"===n.action)for(var s=n.data.id,h=0;h<i;h++)if(t[h].data.id===s){e=h;break}null!==e?a.splice(e,0,n):a.push(n)}return a}});t.CommandManager=i}(this.joint.dia=this.joint.dia||{},Backbone,joint);