"use strict";Object.defineProperty(exports,"__esModule",{value:true});var _typeof=typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol==="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};var _createClass=function(){function t(t,e){for(var i=0;i<e.length;i++){var l=e[i];l.enumerable=l.enumerable||false;l.configurable=true;if("value"in l)l.writable=true;Object.defineProperty(t,l.key,l)}}return function(e,i,l){if(i)t(e.prototype,i);if(l)t(e,l);return e}}();/* @preserve TW-Guard */
/*\

title: $:/plugins/felixhayashi/tiddlymap/js/MapElementType
type: application/javascript
module-type: library

@preserve

\*/
/* @preserve TW-Guard */var _utils=require("$:/plugins/felixhayashi/tiddlymap/js/utils");var _utils2=_interopRequireDefault(_utils);function _interopRequireDefault(t){return t&&t.__esModule?t:{default:t}}function _classCallCheck(t,e){if(!(t instanceof e)){throw new TypeError("Cannot call a class as a function")}}var MapElementType=function(){function t(e,i,l,s){_classCallCheck(this,t);this.id=e;this.root=i;this._fieldMeta=l;this.fullPath=this.root+"/"+this.id;this.isShipped=$tw.wiki.getSubTiddler($tm.path.pluginRoot,this.fullPath);this._load(s||this.fullPath)}_createClass(t,[{key:"_load",value:function t(e){if(!e){return}if(typeof e==="string"){var i=_utils2.default.startsWith(e,this.root);var l=i?e:this.root+"/"+e;this._loadFromTiddler(l)}else if(e instanceof $tw.Tiddler){this._loadFromTiddler(e)}else if((typeof e==="undefined"?"undefined":_typeof(e))==="object"){for(var s in this._fieldMeta){this[s]=e[s]}}}},{key:"_loadFromTiddler",value:function t(e){var i=_utils2.default.getTiddler(e);if(!i){return}var l=$tw.wiki.getSubTiddler($tm.path.pluginRoot,this.fullPath)||{};var s=$tw.utils.extend({},l.fields,i.fields);for(var r in this._fieldMeta){var a=this._fieldMeta[r].parse;var f=s[r];this[r]=a?a.call(this,f):f}}},{key:"exists",value:function t(){return _utils2.default.tiddlerExists(this.fullPath)}},{key:"setStyle",value:function t(e,i){if(typeof e==="string"){e=_utils2.default.parseJSON(e)}if((typeof e==="undefined"?"undefined":_typeof(e))==="object"){if(i){_utils2.default.merge(this.style,e)}else{this.style=e}}}},{key:"save",value:function t(e,i){if(!e){e=this.fullPath}else if(typeof e!=="string"){return}var l={title:e,text:""};if(!_utils2.default.startsWith(e,this.root)){l.id=this.id}for(var s in this._fieldMeta){var r=this._fieldMeta[s].stringify;l[s]=r?r.call(this,this[s]):this[s]}if(!this.exists()){Object.assign(l,$tw.wiki.getCreationFields())}if(i!==true){Object.assign(l,$tw.wiki.getModificationFields())}$tw.wiki.addTiddler(new $tw.Tiddler(l))}}]);return t}();MapElementType.fieldMeta={description:{},style:{parse:_utils2.default.parseJSON,stringify:JSON.stringify},modified:{},created:{}};exports.default=MapElementType;
//# sourceMappingURL=./maps/felixhayashi/tiddlymap/js/graph/MapElementType.js.map
