1 line
14 KiB
JavaScript
1 line
14 KiB
JavaScript
"use strict";var e=function(e){return e&&e.__esModule?e["default"]:e},t=function(){function e(e,t){for(var i in t){var a=t[i];a.configurable=!0,a.value&&(a.writable=!0)}Object.defineProperties(e,t)}return function(t,i,a){return i&&e(t.prototype,i),a&&e(t,a),t}}(),i=function v(e,t,i){var a=Object.getOwnPropertyDescriptor(e,t);if(void 0===a){var r=Object.getPrototypeOf(e);return null===r?void 0:v(r,t,i)}if("value"in a&&a.writable)return a.value;var n=a.get;if(void 0!==n)return n.call(i)},a=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(e.__proto__=t)},r=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},n=e(require("./event-emitter")),o=e(require("react")),s=e(require("../atom-react/core/react-editor")),d=e(require("./description-editor")),c=e(require("fs")),l=e(require("../common/clipboard")),h=e(require("path")),u=function(e){function n(e,t,a){r(this,n),i(Object.getPrototypeOf(n.prototype),"constructor",this).call(this),this.schema=t,this.uri=a,this.selectionState={},this.selectedElement=void 0,this.selectedDecorator=void 0,this._clearDescription(),this.reload(e,t)}return a(n,e),t(n,{getSchemaByElement:{value:function(e){if(!e["asset-pack"]){var t=this.schema.core.schema[e["class"]];return t||(t=this.schema.project.schema[e["class"]]),t}var i=e["asset-pack"];return this.schema[i].schema[e["class"]]}},addRedoUndoEntry:{value:function(){}},getMutationFunctionNames:{value:function(){return["moveUp","moveDown","addRedoUndoEntry"]}},reload:{value:function(e){var t=this;this.data=e,this.projectRoot=s.getProjectRoot(this.uri);var i=h.join(this.projectRoot,"node_modules","jibo");if(!c.existsSync(i))return void(this.installJibo=!0);this.installJibo=!1,this.nextId=0;var a=void 0===e?[]:Object.keys(e);a.forEach(function(i){var a=e[i];t.nextId=Math.max(t.nextId,a.id)});for(var r=0;r<a.length;r++){var n=e[a[r]],o=this.getSchemaByElement(n).type;if("leaf"===o||"composite"===o){for(this.root=n;this.root.parent;)this.root=e[this.root.parent];break}}this._clearDescription(),this._validateSelections()}},_validateSelections:{value:function(){var e=this,t=Object.keys(this.selectionState);if(t.forEach(function(t){var i=e.data[t],a=e.data[e.selectionState[t]];(void 0===i||void 0===a)&&(e.selectionState[i]=void 0)}),void 0!==this.selectedElement){var i=this.data[this.selectedElement.id];if(void 0===i)this.setSelectedElement(this.getRoot());else if(this.setSelectedElement(i),void 0!==this.selectedDecorator&&void 0===this.data[this.selectedDecorator.id]){var a=this._getFirstDecorator(this.selectedElement);this.setSelectedDecorator(a)}}}},getData:{value:function(){return this.data}},setSelectedElement:{value:function(e){this.selectedElement=e;var t=void 0;void 0!==e&&(t=void 0!==this.selectionState[e.id]?this.selectionState[e.id]:this._getFirstDecorator(e)),this.setSelectedDecorator(t)}},getSelectedBehavior:{value:function(){return this.selectedElement}},setSelectedDecorator:{value:function(e){this.selectedDecorator=e,this._setSelectionState(this.selectedElement,e)&&this.emit("ondatachanged")}},getSelectedDecorator:{value:function(){return this.selectedDecorator}},_getFirstDecorator:{value:function(e){if(void 0!==e){var t=void 0;if(this.data[e.id].decorators&&this.data[e.id].decorators.length>0){var i=this.data[e.id].decorators[0];t=this.data[i]}return t}}},_setSelectionState:{value:function(e,t){return void 0!==e&&this.selectionState[e.id]!==t?(this.selectionState[e.id]=t,!0):!1}},setRenderDescription:{value:function(e){this._setAndClearDescriptionElement(),this.description.element=e,this.description.newValue=void 0}},_setAndClearDescriptionElement:{value:function(){this.description.element&&this.description.newValue&&(this.description.element.name=this.description.newValue,this.addRedoUndoEntry()),this._clearDescription()}},_clearDescription:{value:function(){this.description={element:void 0,newValue:void 0}}},isSelected:{value:function(e){return this.selectedElement&&e.id===this.selectedElement.id}},getNextId:{value:function(){return this.nextId++,this.nextId}},createNewElement:{value:function(e,t,i){var a={id:this.getNextId(),"class":t["class"],name:""};return a["asset-pack"]=e,i&&(a.parent=i.id),a.args=[],t.args&&t.args.forEach(function(e,i){var r=t.meta[i].defaultValue;if(Array.isArray(e)){var o=e;e=e[0],"enum"===e&&void 0===r&&(r=o[1].value)}a.args.push(n.getDefaultValueForType(e.toLowerCase(),r))}),a}},deleteRow:{value:function(e,t){var i=this;if("undefined"==typeof e&&(e=this.selectedElement),"undefined"==typeof t){var a=this.data[e.parent];t=a.children.indexOf(e.id)}var r=e.parent,n=this.data[r],o=this.isSelected(e);this.selectionState[e.id]=void 0;for(var s=[n.children.splice(t,1)[0]];s.length>0;){var d=s.pop();o||(o=this.isSelected(this.data[d])),this.data[d].decorators&&this.data[d].decorators.forEach(function(e){delete i.data[e]}),this.data[d].children&&(s=s.concat(this.data[d].children)),delete this.data[d]}o&&this.setSelectedElement(n),this.addRedoUndoEntry(),this.emit("ondatachanged")}},addDecoratorAbove:{value:function(e,t,i,a){e.decorators=e.decorators?e.decorators:[];var r=this.createNewElement(i,a);e.decorators.splice(t,0,r.id),this.data[r.id]=r,this.selectedElement===e&&this.setSelectedDecorator(r),this.addRedoUndoEntry(),this.emit("ondatachanged")}},addDecoratorBelow:{value:function(e,t,i,a){this.addDecoratorAbove(e,t+1,a)}},deleteDecorator:{value:function(e,t){if("undefined"==typeof e&&(e=this.selectedElement),"undefined"==typeof t){var i=this.data[e.parent];t=i.children.indexOf(e.id)}var a=e.decorators.splice(t,1)[0];this.selectedDecorator&&a===this.selectedDecorator.id&&(this.selectedDecorator=void 0),delete this.data[a];var r=this._getFirstDecorator(e);this.setSelectedDecorator(r),this.addRedoUndoEntry(),this.emit("ondatachanged")}},addSiblingAbove:{value:function(e,t,i,a){var r=this.getParent(e),n=this.createNewElement(i,a,r);this.data[n.id]=n,r.children.splice(t,0,n.id),this.addRedoUndoEntry(),this.setSelectedElement(n)}},addSiblingBelow:{value:function(e,t,i,a){this.addSiblingAbove(e,t+1,i,a)}},addChild:{value:function(e,t,i){var a=this.createNewElement(t,i,e);e.children=e.children?e.children:[],e.children.unshift(a.id),this.data[a.id]=a,this.setSelectedElement(a),this.addRedoUndoEntry(),this.emit("ondatachanged")}},skip:{value:function(e){e.skipped=e.skipped?!1:!0,this.addRedoUndoEntry(),this.getParent(e)?this.emit("ondatachanged"):e.skipped=!1,this.addRedoUndoEntry()}},swap:{value:function(e,t,i){var a=this.getParent(e),r=this.getRoot()==e,n=this.createNewElement(t,i,a);n.parent=void 0===a?void 0:a.id,n.id=e.id,n.children=e.children,n.decorators=e.decorators,this.data[n.id]=n,r&&(this.root=n),this.setSelectedElement(n),this.addRedoUndoEntry(),this.emit("ondatachanged")}},moveUp:{value:function(e,t){var i=t-1,a=this.data[e.parent];a.children.splice(t,1),a.children.splice(i,0,e.id),this.addRedoUndoEntry(),this.emit("ondatachagned")}},canMoveUp:{value:function(e,t){return 0!==t}},isSkipped:{value:function(e){return e.skipped}},moveDown:{value:function(e,t){if(this.canMoveDown(e,t)){var i=t+1,a=this.data[e.parent];a.children.splice(t,1),a.children.splice(i,0,e.id),this.emit("ondatachagned")}}},canMoveDown:{value:function(e,t){var i=this.data[e.parent];return t<i.children.length-1}},moveRow:{value:function(e,t,i){var a=e.parent,r=this.data[a],n=r.children.indexOf(e.id);r.id===t.id&&i>n&&i--,r.children.splice(n,1),t.children=t.children?t.children:[],t.children.splice(i,0,e.id),e.parent=t.id,this.addRedoUndoEntry(),this.emit("ondatachanged")}},canPaste:{value:function(){return void 0!==l.behaviorData}},paste:{value:function(){if(l.behaviorData){var e=JSON.parse(l.behaviorData),t=Object.keys(e),i=this.getSchemaByElement(e[t[0]]).type;"decorator"!==i?this._pasteBehavior(e):1===t.length&&"decorator"===i&&this._pasteDecorator(e,t),this.addRedoUndoEntry()}}},_pasteBehavior:{value:function(e){var t=this.getSchemaByElement(this.selectedElement).type,i=void 0,a=0;"leaf"===t?(i=this.getParent(this.selectedElement),a=i.children.indexOf(this.selectedElement.id)+1):"composite"===t&&(i=this.selectedElement);var r=Number.MAX_VALUE,n=0;Object.keys(e).forEach(function(e){r=Math.min(e,r),n=Math.max(e,n)});var o=this.getNextId(),s=0;o>=r?(s=o-r,this.nextId+=s-1):this.nextId=n;var d=[];Object.keys(e).forEach(function(t){var i=e[t];i.id+=s,i.parent+=s,i.children&&i.children.forEach(function(e,t){i.children[t]+=s}),i.decorators&&i.decorators.forEach(function(e,t){i.decorators[t]+=s}),d.push(i)}),e={},d.forEach(function(t){e[t.id]=t});for(var c=d[0];e[c.parent];)c=e[c.parent];c.parent=i.id,i.children=i.children?i.children:[],i.children.splice(a,0,c.id),Object.assign(this.data,e),this.setSelectedElement(c)}},pasteDecorator:{value:function(){if(l.behaviorData){var e=JSON.parse(l.behaviorData),t=Object.keys(e);1===t.length&&"decorator"===this.getSchemaByElement(e[t[0]]).type&&this._pasteDecorator(e,t)}}},_pasteDecorator:{value:function(e,t){var i=this.selectedElement;if(void 0!==i){var a=t[0],r=e[a],n=0;i.decorators&&(n=i.decorators.indexOf(this.selectedDecorator.id)+1),r.id=this.getNextId(),i.decorators=i.decorators?i.decorators:[],i.decorators.splice(n,0,r.id),this.data[r.id]=r,this.setSelectedDecorator(r)}}},copy:{value:function(){var e=this;if(void 0!==this.selectedElement){for(var t={},i=[this.selectedElement.id];i.length>0;)!function(){var a=i.pop(),r=e.data[a];r.decorators&&r.decorators.forEach(function(i,a){var n=r.decorators[a],o=e.data[n];t[o.id]=o}),t[a]=r,r.children&&(i=i.concat(r.children))}();l.behaviorData=JSON.stringify(t)}}},copyDecorator:{value:function(){if(void 0!==this.selectedDecorator){var e=this.selectedDecorator.id,t=this.data[e],i={};i[e]=t,l.behaviorData=JSON.stringify(i)}}},cut:{value:function(){if(void 0!==this.selectedElement){this.copy();var e=this.selectedElement,t=this.data[e.parent],i=t.children.indexOf(e.id),a=t;if(this.deleteRow(e,i),t.children.length>0){i=Math.max(0,i-1);var r=t.children[i];a=this.data[r]}this.addRedoUndoEntry(),this.setSelectedElement(a)}}},cutDecorator:{value:function(){if(void 0!==this.selectedDecorator&&void 0!==this.selectedElement){this.copyDecorator();var e=this.selectedDecorator,t=this.selectedElement.decorators.indexOf(e.id);this.addRedoUndoEntry(),this.deleteDecorator(this.selectedElement,t)}}},skipDecorator:{value:function(){if(void 0!==this.selectedDecorator&&void 0!==this.selectedElement){var e=this.selectedDecorator;e.skipped=e.skipped?!1:!0,this.emit("ondatachanged"),this.addRedoUndoEntry()}}},up:{value:function(){if(void 0!==this.selectedElement){var e=this.selectedElement,t=this.data[e.parent];if(t){var i=t.children.indexOf(e.id);if(0===i)this.setSelectedElement(t);else{for(i--,e=this.data[t.children[i]];e.children&&0!==e.children.length;)e=this.data[e.children[e.children.length-1]];this.setSelectedElement(e)}this.emit("ondatachanged")}}}},upDecorator:{value:function(){if(this.selectedDecorator){var e=this.selectedElement.decorators.indexOf(this.selectedDecorator.id);e>0&&(e--,this.setSelectedDecorator(this.data[this.selectedElement.decorators[e]]),this.emit("ondatachanged"))}}},down:{value:function(){if(void 0!==this.selectedElement){var e=!1,t=this.selectedElement,i=this.data[t.parent],a=void 0;if(i&&(a=i.children.indexOf(t.id)),t.children&&t.children.length>0)this.setSelectedElement(this.data[t.children[0]]),e=!0;else if(i&&a<i.children.length-1)a++,this.setSelectedElement(this.data[i.children[a]]),e=!0;else for(;i&&this.getParent(i);)if(t=i,i=this.getParent(t),a=i.children.indexOf(t.id),a<i.children.length-1){a++,this.setSelectedElement(this.data[i.children[a]]),e=!0;break}e&&this.emit("ondatachanged")}}},downDecorator:{value:function(){if(this.selectedDecorator){var e=this.selectedElement.decorators.indexOf(this.selectedDecorator.id);e<this.selectedElement.decorators.length-1&&(e++,this.setSelectedDecorator(this.data[this.selectedElement.decorators[e]]))}}},behavior:{get:function(){return this.selectedDecorator?this.selectedDecorator:this.selectedElement}},getParent:{value:function(e){var t=e.parent,i=this.data[t];return i}},shouldSkip:{value:function(e){return void 0===e?!1:e.skipped?!0:this.shouldSkip(this.getParent(e))}},getHeaderLabel:{value:function(e){switch(e){case 0:return"";case 1:return"";case 2:return"Behavior Type";case 3:return"Description"}}},getRowCount:{value:function(e){return e.children.length}},getColumnCount:{value:function(){return 4}},canHaveChildren:{value:function(e){return"composite"===this.getSchemaByElement(e).type}},hasChildren:{value:function(e){return e.children&&e.children.length>0}},getChildElement:{value:function(e,t){return this.data[e.children[t]]}},shouldNotIndent:{value:function(e){return 0===e}},getLabel:{value:function(e,t,i,a){var r=this;switch(t){case 0:return String(a);case 1:return"";case 2:var n=[];n.push(e["class"]),e.decorators&&e.decorators.length>0&&(n.push(" *("),e.decorators.forEach(function(t,i){var a={};r.data[t].skipped&&(a={"font-style":"italic",color:"#555555"}),n.push(o.createElement("span",{style:a},r.data[t]["class"])),i!=e.decorators.length-1&&n.push(", ")}),n.push(")"));var s="";this.isSelected(e)&&(s="row-selected-text");var c={},l="";"leaf"===this.getSchemaByElement(e).type?(c.className="icon-stack-base fa fa-leaf",l="green"):"composite"===this.getSchemaByElement(e).type&&(c.className="fa fa-sitemap",l="lightblue"),e.skipped&&(c.className="fa fa-eye-slash"),this.shouldSkip(e)&&(l="#555555"),c.style={color:l};var h=this.shouldSkip(e)?{"font-style":"italic",color:"#555555"}:{};return o.createElement("p",{className:s,style:h},o.createElement("i",c)," ",n);case 3:return e===this.description.element?o.createElement(d,{content:e.name,onChange:function(e){r.description.newValue=e},width:i,onConfirm:function(){r._setAndClearDescriptionElement(),r.emit("ondatachanged")}}):e.name}}},getRoot:{value:function(){return this.root}}},{getDefaultValueForType:{value:function(e,t){var i={"int":0,number:0,animation:"null",audio:"null","function":"() => {\n}",string:"null","boolean":!1,"enum":"null"};return t?t:i[e]}},createNewFile:{value:function(e,t){var i={id:1,"class":t["class"],name:""};i.args=[],t.args&&t.args.forEach(function(e,a){var r=t.meta[a].defaultValue;if(Array.isArray(e)){var o=e;e=e[0],"enum"===e&&void 0===r&&(r=o[1].value)}i.args.push(n.getDefaultValueForType(e.toLowerCase(),r))});var a={};a[i.id]=i,c.writeFileSync(e,JSON.stringify(a,null," "),"utf8")}}}),n}(n);module.exports=u; |