`).get(0);\n var marginEls = ppfx + marginName + '-el';\n var paddingEls = ppfx + paddingName + '-el';\n const fullMargName = `${marginEls} ${ppfx + marginName}`;\n const fullPadName = `${paddingEls} ${ppfx + paddingName}`;\n marginT = $(`
`).get(0);\n marginB = $(`
`).get(0);\n marginL = $(`
`).get(0);\n marginR = $(`
`).get(0);\n padT = $(`
`).get(0);\n padB = $(`
`).get(0);\n padL = $(`
`).get(0);\n padR = $(`
`).get(0);\n this['marginT' + state] = marginT;\n this['marginB' + state] = marginB;\n this['marginL' + state] = marginL;\n this['marginR' + state] = marginR;\n this['padT' + state] = padT;\n this['padB' + state] = padB;\n this['padL' + state] = padL;\n this['padR' + state] = padR;\n marginV.appendChild(marginT);\n marginV.appendChild(marginB);\n marginV.appendChild(marginL);\n marginV.appendChild(marginR);\n paddingV.appendChild(padT);\n paddingV.appendChild(padB);\n paddingV.appendChild(padL);\n paddingV.appendChild(padR);\n offsetViewer.appendChild(marginV);\n offsetViewer.appendChild(paddingV);\n this[stateVar] = '1';\n }\n\n var unit = 'px';\n var marginLeftSt = parseFloat(style.marginLeft.replace(unit, '')) * zoom;\n var marginRightSt = parseFloat(style.marginRight.replace(unit, '')) * zoom;\n var marginTopSt = parseFloat(style.marginTop.replace(unit, '')) * zoom;\n var marginBottomSt =\n parseFloat(style.marginBottom.replace(unit, '')) * zoom;\n var mtStyle = marginT.style;\n var mbStyle = marginB.style;\n var mlStyle = marginL.style;\n var mrStyle = marginR.style;\n var ptStyle = padT.style;\n var pbStyle = padB.style;\n var plStyle = padL.style;\n var prStyle = padR.style;\n var posLeft = parseFloat(pos.left);\n var widthEl = parseFloat(style.width) * zoom + unit;\n\n // Margin style\n mtStyle.height = marginTopSt + unit;\n mtStyle.width = widthEl;\n mtStyle.top = pos.top - marginTopSt + unit;\n mtStyle.left = posLeft + unit;\n\n mbStyle.height = marginBottomSt + unit;\n mbStyle.width = widthEl;\n mbStyle.top = pos.top + pos.height + unit;\n mbStyle.left = posLeft + unit;\n\n var marginSideH = pos.height + marginTopSt + marginBottomSt + unit;\n var marginSideT = pos.top - marginTopSt + unit;\n mlStyle.height = marginSideH;\n mlStyle.width = marginLeftSt + unit;\n mlStyle.top = marginSideT;\n mlStyle.left = posLeft - marginLeftSt + unit;\n\n mrStyle.height = marginSideH;\n mrStyle.width = marginRightSt + unit;\n mrStyle.top = marginSideT;\n mrStyle.left = posLeft + pos.width + unit;\n\n // Padding style\n var padTop = parseFloat(style.paddingTop) * zoom;\n ptStyle.height = padTop + unit;\n // ptStyle.width = widthEl;\n // ptStyle.top = pos.top + unit;\n // ptStyle.left = posLeft + unit;\n\n var padBot = parseFloat(style.paddingBottom) * zoom;\n pbStyle.height = padBot + unit;\n // pbStyle.width = widthEl;\n // pbStyle.top = pos.top + pos.height - padBot + unit;\n // pbStyle.left = posLeft + unit;\n\n var padSideH = pos.height - padBot - padTop + unit;\n var padSideT = pos.top + padTop + unit;\n plStyle.height = padSideH;\n plStyle.width = parseFloat(style.paddingLeft) * zoom + unit;\n plStyle.top = padSideT;\n // plStyle.left = pos.left + unit;\n // plStyle.right = 0;\n\n var padRight = parseFloat(style.paddingRight) * zoom;\n prStyle.height = padSideH;\n prStyle.width = padRight + unit;\n prStyle.top = padSideT;\n // prStyle.left = pos.left + pos.width - padRight + unit;\n // prStyle.left = 0;\n },\n\n stop(editor, sender, opts = {}) {\n var opt = opts || {};\n var state = opt.state || '';\n var method = this.getOffsetMethod(state);\n var canvas = editor.Canvas;\n var offsetViewer = canvas[method](opts.view);\n offsetViewer.style.opacity = 0;\n }\n};\n","export default {\n run(ed) {\n this.toggleVis(ed);\n },\n\n stop(ed) {\n this.toggleVis(ed, 0);\n },\n\n toggleVis(ed, active = 1) {\n if (!ed.Commands.isActive('preview')) {\n const method = active ? 'add' : 'remove';\n\n ed.Canvas.getFrames().forEach(frame => {\n frame.view.getBody().classList[method](`${this.ppfx}dashed`);\n });\n }\n }\n};\n","export default {\n stylePrefix: '',\n\n // Specify the element to use as a container, string (query) or HTMLElement\n // With the empty value, nothing will be rendered\n appendTo: '',\n\n // Enable/Disable globally the possibility to sort layers\n sortable: 1,\n\n // Enable/Disable globally the possibility to hide layers\n hidable: 1,\n\n // Hide textnodes\n hideTextnode: 1,\n\n // Indicate a query string of the element to be selected as the root of layers.\n // By default the root is the wrapper\n root: '',\n\n // Indicates if the wrapper is visible in layers\n showWrapper: 1,\n\n // Show hovered components in canvas\n showHover: 1,\n\n // Scroll to selected component in Canvas when it's selected in Layers\n // true, false or `scrollIntoView`-like options,\n // `block: 'nearest'` avoids the issue of window scolling\n scrollCanvas: { behavior: 'smooth', block: 'nearest' },\n\n // Scroll to selected component in Layers when it's selected in Canvas\n // true, false or `scrollIntoView`-like options\n scrollLayers: { behavior: 'auto', block: 'nearest' },\n\n // Highlight when a layer component is hovered\n highlightHover: 1\n};\n","import defaults from './config/config';\nimport ItemView from './view/ItemView';\nimport { isElement } from 'underscore';\n\nexport default () => {\n let em;\n let layers;\n let config = {};\n\n return {\n name: 'LayerManager',\n\n init(opts = {}) {\n config = { ...defaults, ...opts };\n config.stylePrefix = opts.pStylePrefix;\n em = config.em;\n\n return this;\n },\n\n getConfig() {\n return config;\n },\n\n onLoad() {\n layers = new ItemView({\n level: 0,\n config,\n opened: config.opened || {},\n model: em.get('DomComponents').getWrapper()\n });\n em && em.on('component:selected', this.componentChanged);\n this.componentChanged();\n },\n\n postRender() {\n const elTo = config.appendTo;\n const root = config.root;\n root && this.setRoot(root);\n\n if (elTo) {\n const el = isElement(elTo) ? elTo : document.querySelector(elTo);\n el.appendChild(this.render());\n }\n },\n\n /**\n * Set new root for layers\n * @param {HTMLElement|Component|String} el Component to be set as the root\n * @return {self}\n */\n setRoot(el) {\n layers.setRoot(el);\n return this;\n },\n\n /**\n * Get the root of layers\n * @return {Component}\n */\n getRoot() {\n return layers.model;\n },\n\n /**\n * Return the view of layers\n * @return {View}\n */\n getAll() {\n return layers;\n },\n\n /**\n * Triggered when the selected component is changed\n * @private\n */\n componentChanged(selected, opts = {}) {\n if (opts.fromLayers) return;\n const opened = em.get('opened');\n const model = em.getSelected();\n const scroll = config.scrollLayers;\n let parent = model && model.collection ? model.collection.parent : null;\n for (let cid in opened) opened[cid].set('open', 0);\n\n while (parent) {\n parent.set('open', 1);\n opened[parent.cid] = parent;\n parent = parent.collection ? parent.collection.parent : null;\n }\n\n if (model && scroll) {\n const el = model.viewLayer && model.viewLayer.el;\n el && el.scrollIntoView(scroll);\n }\n },\n\n render() {\n return layers.render().el;\n }\n };\n};\n","/*!\n * Backbone.Undo.js v0.2\n * \n * Copyright (c)2013 Oliver Sartun\n * Released under the MIT License\n *\n * Documentation and full license available at\n * https://github.com/osartun/Backbone.Undo.js\n */\n\n\n(function (factory) {\n\tif (typeof define === \"function\" && define.amd) {\n\t\t// AMD support\n\t\tdefine([\"underscore\", \"backbone\"], factory);\n\t} else if (typeof exports !== 'undefined') {\n\t\t// CommonJS support\n\t\tmodule.exports = factory(\n\t\t\trequire(\"underscore\"),\n\t\t\trequire(\"backbone\")\n\t\t);\n\t} else {\n\t\t// Non-modular execution\n\t\tfactory(_, Backbone);\n }\n})(function (_, Backbone) {\n\n\tvar core_slice = Array.prototype.slice;\n\n\t/**\n\t * As call is faster than apply, this is a faster version of apply as it uses call.\n\t * \n\t * @param {Function} fn \tThe function to execute \n\t * @param {Object} ctx \tThe context the function should be called in\n\t * @param {Array} args \tThe array of arguments that should be applied to the function\n\t * @return Forwards whatever the called function returns\n\t */\n\tfunction apply (fn, ctx, args) {\n\t\treturn args.length <= 4 ?\n\t\t\tfn.call(ctx, args[0], args[1], args[2], args[3]) :\n\t\t\tfn.apply(ctx, args);\n\t}\n\n\t/**\n\t * Uses slice on an array or an array-like object.\n\t * \n\t * @param {Array|Object} \tarr \tThe array or array-like object.\n\t * @param {Number} \t\t[index]\tThe index from where the array should be sliced. Default is 0.\n\t * @return {Array} The sliced array\n\t */\n\tfunction slice (arr, index) {\n\t\treturn core_slice.call(arr, index);\n\t}\n\n\t/**\n\t * Checks if an object has one or more specific keys. The keys \n\t * don't have to be an owned property.\n\t * You can call this function either this way:\n\t * hasKeys(obj, [\"a\", \"b\", \"c\"])\n\t * or this way:\n\t * hasKeys(obj, \"a\", \"b\", \"c\")\n\t * \n\t * @param {Object} \tobj \tThe object to check on\n\t * @param {Array} \tkeys \tThe keys to check for\n\t * @return {Boolean} True, if the object has all those keys\n\t */\n\tfunction hasKeys (obj, keys) {\n\t\tif (obj == null) return false;\n\t\tif (!_.isArray(keys)) {\n\t\t\tkeys = slice(arguments, 1);\n\t\t}\n\t\treturn _.all(keys, function (key) {\n\t\t\treturn key in obj;\n\t\t});\n\t}\n\n\t/**\n\t * Returns a number that is unique per call stack. The number gets \n\t * changed after the call stack has been completely processed.\n\t * \n\t * @return {number} MagicFusionIndex\n\t */\n\tvar getMagicFusionIndex = (function () {\n\t\t// If you add several models to a collection or set several\n\t\t// attributes on a model all in sequence and yet all for\n\t\t// example in one function, then several Undo-Actions are\n\t\t// generated.\n\t\t// If you want to undo your last action only the last model\n\t\t// would be removed from the collection or the last set\n\t\t// attribute would be changed back to its previous value.\n\t\t// To prevent that we have to figure out a way to combine\n\t\t// all those actions that happened \"at the same time\". \n\t\t// Timestamps aren't exact enough. A complex routine could \n\t\t// run several milliseconds and in that time produce a lot \n\t\t// of actions with different timestamps.\n\t\t// Instead we take advantage of the single-threadedness of\n\t\t// JavaScript:\n\n\t\tvar callstackWasIndexed = false, magicFusionIndex = -1;\n\t\tfunction indexCycle() {\n\t\t\tmagicFusionIndex++;\n\t\t\tcallstackWasIndexed = true;\n\t\t\t_.defer(function () {\n\t\t\t\t// Here comes the magic. With a Timeout of 0 \n\t\t\t\t// milliseconds this function gets called whenever\n\t\t\t\t// the current callstack is completed\n\t\t\t\tcallstackWasIndexed = false;\n\t\t\t})\n\t\t}\n\t\treturn function () {\n\t\t\tif (!callstackWasIndexed) {\n\t\t\t\tindexCycle();\n\t\t\t}\n\t\t\treturn magicFusionIndex;\n\t\t}\n\t})();\n\n\t/**\n\t * To prevent binding a listener several times to one \n\t * object, we register the objects in an ObjectRegistry\n\t *\n\t * @constructor\n\t */\n\tfunction ObjectRegistry () {\n\t\t// This uses two different ways of storing\n\t\t// objects: In case the object has a cid\n\t\t// (which Backbone objects typically have)\n\t\t// it uses this cid as an index. That way\n\t\t// the Array's length attribute doesn't \n\t\t// change and the object isn't an item \n\t\t// in the array, but an object-property.\n\t\t// Otherwise it's added to the Array as an\n\t\t// item.\n\t\t// That way we can use the fast property-\n\t\t// lookup and only have to fall back to \n\t\t// iterating over the array in case \n\t\t// non-Backbone-objects are registered.\n\t\tthis.registeredObjects = [];\n\t\t// To return a list of all registered \n\t\t// objects in the 'get' method we have to\n\t\t// store the objects that have a cid in\n\t\t// an additional array. \n\t\tthis.cidIndexes = [];\n\t}\n\tObjectRegistry.prototype = {\n\t\t/**\n\t\t * Returns whether the object is already registered in this ObjectRegistry or not.\n\t\t * \n\t\t * @this \t{ObjectRegistry}\n\t\t * @param \t{Object} \t\t obj \tThe object to check\n\t\t * @return \t{Boolean} True if the object is already registered\n\t\t */\n\t\tisRegistered: function (obj) {\n\t\t\t// This is where we get a performance boost \n\t\t\t// by using the two different ways of storing \n\t\t\t// objects.\n\t\t\treturn obj && obj.cid ? this.registeredObjects[obj.cid] : _.contains(this.registeredObjects, obj);\n\t\t},\n\t\t/**\n\t\t * Registers an object in this ObjectRegistry.\n\t\t * \n\t\t * @this \t{ObjectRegistry}\n\t\t * @param \t{Object} \t\t obj \tThe object to register\n\t\t * @return \t{undefined}\n\t\t */\n\t\tregister: function (obj) {\n\t\t\tif (!this.isRegistered(obj)) {\n\t\t\t\tif (obj && obj.cid) {\n\t\t\t\t\tthis.registeredObjects[obj.cid] = obj;\n\t\t\t\t\tthis.cidIndexes.push(obj.cid);\n\t\t\t\t} else {\n\t\t\t\t\tthis.registeredObjects.push(obj);\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\treturn false;\n\t\t},\n\t\t/**\n\t\t * Unregisters an object from this ObjectRegistry.\n\t\t * \n\t\t * @this {ObjectRegistry}\n\t\t * @param {Object} obj The object to unregister\n\t\t * @return {undefined}\n\t\t */\n\t\tunregister: function (obj) {\n\t\t\tif (this.isRegistered(obj)) {\n\t\t\t\tif (obj && obj.cid) {\n\t\t\t\t\tdelete this.registeredObjects[obj.cid];\n\t\t\t\t\tthis.cidIndexes.splice(_.indexOf(this.cidIndexes, obj.cid), 1);\n\t\t\t\t} else {\n\t\t\t\t\tvar i = _.indexOf(this.registeredObjects, obj);\n\t\t\t\t\tthis.registeredObjects.splice(i, 1);\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\treturn false;\n\t\t},\n\t\t/**\n\t\t * Returns an array of all objects that are currently in this ObjectRegistry.\n\t\t * \n\t\t * @return {Array} An array of all the objects which are currently in the ObjectRegistry\n\t\t */\n\t\tget: function () {\n\t\t\treturn (_.map(this.cidIndexes, function (cid) {return this.registeredObjects[cid];}, this)).concat(this.registeredObjects);\n\t\t}\n\t}\n\n\t/**\n\t * Binds or unbinds the \"all\"-listener for one or more objects.\n\t * \n\t * @param {String} which \tEither \"on\" or \"off\"\n\t * @param {Object[]} objects \tArray of the objects on which the \"all\"-listener should be bound / unbound to\n\t * @param {Function} [fn] \t\tThe function that should be bound / unbound. Optional in case of \"off\"\n\t * @param {Object} [ctx] \tThe context the function should be called in\n\t * @return {undefined}\n\t */\n\tfunction onoff(which, objects, fn, ctx) {\n\t\tfor (var i = 0, l = objects.length, obj; i < l; i++) {\n\t\t\tobj = objects[i];\n\t\t\tif (!obj) continue;\n\t\t\tif (which === \"on\") {\n\t\t\t\tif (!ctx.objectRegistry.register(obj)) {\n\t\t\t\t\t// register returned false, so obj was already registered\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (!ctx.objectRegistry.unregister(obj)) {\n\t\t\t\t\t// unregister returned false, so obj wasn't registered\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (_.isFunction(obj[which])) {\n\t\t\t\tobj[which](\"all\", fn, ctx);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Calls the undo/redo-function for a specific action.\n\t * \n\t * @param {String} which \tEither \"undo\" or \"redo\"\n\t * @param {Object} action \tThe Action's attributes\n\t * @return {undefined}\n\t */\n\tfunction actionUndoRedo (which, action) {\n\t\tvar type = action.type, undoTypes = action.undoTypes, fn = !undoTypes[type] || undoTypes[type][which];\n\t\tif (_.isFunction(fn)) {\n\t\t\tfn(action.object, action.before, action.after, action.options);\n\t\t}\n\t}\n\n\t/**\n\t * The main undo/redo function.\n\t *\n\t * @param {String} \t\twhich \t Either \"undo\" or \"redo\"\n\t * @param {UndoManager} \tmanager\t The UndoManager-instance on which an \"undo\"/\"redo\"-Event is triggered afterwards\n\t * @param {UndoStack} \t\tstack \t The UndoStack on which we perform\n\t * @param {Boolean} \t\tmagic \t If true, undoes / redoes all actions with the same magicFusionIndex\n\t * @param {Boolean} \t\teverything If true, undoes / redoes every action that had been tracked\n\t * @return {undefined}\n\t */\n\tfunction managerUndoRedo (which, manager, stack, magic, everything) {\n\t\tif (stack.isCurrentlyUndoRedoing || \n\t\t\t(which === \"undo\" && stack.pointer === -1) ||\n\t\t\t(which === \"redo\" && stack.pointer === stack.length - 1)) {\n\t\t\t// We're either currently in an undo- / redo-process or \n\t\t\t// we reached the end of the stack\n\t\t\treturn;\n\t\t}\n\t\tstack.isCurrentlyUndoRedoing = true;\n\t\tvar action, actions, isUndo = which === \"undo\";\n\t\tif (everything) {\n\t\t\t// Undo / Redo all steps until you reach the stack's beginning / end\n\t\t\tactions = isUndo && stack.pointer === stack.length - 1 || // If at the stack's end calling undo\n\t\t\t\t\t !isUndo && stack.pointer === -1 ? // or at the stack's beginning calling redo\n\t\t\t\t\t _.clone(stack.models) : // => Take all the models. Otherwise:\n\t\t\t\t\t core_slice.apply(stack.models, isUndo ? [0, stack.pointer] : [stack.pointer, stack.length - 1]);\n\t\t} else {\n\t\t\t// Undo / Redo only one step\n\t\t\taction = stack.at(isUndo ? stack.pointer : stack.pointer + 1);\n\t\t\tactions = magic ? stack.where({\"magicFusionIndex\": action.get(\"magicFusionIndex\")}) : [action];\n\t\t}\n\t\t\n\t\tstack.pointer += (isUndo ? -1 : 1) * actions.length;\n\t\twhile (action = isUndo ? actions.pop() : actions.shift()) {\n\t\t\t// Here we're calling the Action's undo / redo method\n\t\t\taction[which]();\n\t\t}\n\t\tstack.isCurrentlyUndoRedoing = false;\n\n\t\tmanager.trigger(which, manager);\n\t}\n\n\t/**\n\t * Checks whether an UndoAction should be created or not. Therefore it checks\n\t * whether a \"condition\" property is set in the undoTypes-object of the specific\n\t * event type. If not, it returns true. If it's set and a boolean, it returns it.\n\t * If it's a function, it returns its result, converting it into a boolean. \n\t * Otherwise it returns true.\n\t * \n\t * @param {Object} \tundoTypesType \tThe object within the UndoTypes that holds the function for this event type (i.e. \"change\")\n\t * @param {Arguments} \targs \t\tThe arguments the \"condition\" function is called with\n\t * @return {Boolean} \tTrue, if an UndoAction should be created\n\t */\n\tfunction validateUndoActionCreation (undoTypesType, args) {\n\t\tvar condition = undoTypesType.condition, type = typeof condition;\n\t\treturn type === \"function\" ? !!apply(condition, undoTypesType, args) :\n\t\t\ttype === \"boolean\" ? condition : true;\n\t}\n\n\t/**\n\t * Adds an Undo-Action to the stack.\n\t * \n\t * @param {UndoStack} \t\tstack \t\tThe undostack the action should be added to.\n\t * @param {String} \t\t\ttype \t\tThe event type (i.e. \"change\")\n\t * @param {Arguments} \t\targs \t\tThe arguments passed to the undoTypes' \"on\"-handler\n\t * @param {OwnedUndoTypes} \tundoTypes \tThe undoTypes-object which has the \"on\"-handler\n\t * @return {undefined}\n\t */\n\tfunction addToStack(stack, type, args, undoTypes) {\n\t\tif (stack.track && !stack.isCurrentlyUndoRedoing && type in undoTypes &&\n\t\t\tvalidateUndoActionCreation(undoTypes[type], args)) {\n\t\t\t// An UndoAction should be created\n\t\t\tvar res = apply(undoTypes[type][\"on\"], undoTypes[type], args), diff;\n\t\t\tif (hasKeys(res, \"object\", \"before\", \"after\")) {\n\t\t\t\tres.type = type;\n\t\t\t\tres.magicFusionIndex = getMagicFusionIndex();\n\t\t\t\tres.undoTypes = undoTypes;\n\t\t\t\tif (stack.pointer < stack.length - 1) {\n\t\t\t\t\t// New Actions must always be added to the end of the stack.\n\t\t\t\t\t// If the pointer is not pointed to the last action in the\n\t\t\t\t\t// stack, presumably because actions were undone before, then\n\t\t\t\t\t// all following actions must be discarded\n\t\t\t\t\tvar diff = stack.length - stack.pointer - 1;\n\t\t\t\t\twhile (diff--) {\n\t\t\t\t\t\tstack.pop();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tstack.pointer = stack.length;\n\t\t\t\tstack.add(res);\n\t\t\t\tif (stack.length > stack.maximumStackLength) {\n\t\t\t\t\tstack.shift();\n\t\t\t\t\tstack.pointer--;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\n\t/**\n\t * Predefined UndoTypes object with default handlers for the most common events.\n\t * @type {Object}\n\t */\n\tvar UndoTypes = {\n\t\t\"add\": {\n\t\t\t\"undo\": function (collection, ignore, model, options) {\n\t\t\t\t// Undo add = remove\n\t\t\t\tcollection.remove(model, options);\n\t\t\t},\n\t\t\t\"redo\": function (collection, ignore, model, options) {\n\t\t\t\t// Redo add = add\n\t\t\t\tif (options.index) {\n\t\t\t\t\toptions.at = options.index;\n\t\t\t\t}\n\t\t\t\tcollection.add(model, options);\n\t\t\t},\n\t\t\t\"on\": function (model, collection, options) {\n\t\t\t\treturn {\n\t\t\t\t\tobject: collection,\n\t\t\t\t\tbefore: undefined,\n\t\t\t\t\tafter: model,\n\t\t\t\t\toptions: _.clone(options)\n\t\t\t\t};\n\t\t\t}\n\t\t},\n\t\t\"remove\": {\n\t\t\t\"undo\": function (collection, model, ignore, options) {\n\t\t\t\tif (\"index\" in options) {\n\t\t\t\t\toptions.at = options.index;\n\t\t\t\t}\n\t\t\t\tcollection.add(model, options);\n\t\t\t},\n\t\t\t\"redo\": function (collection, model, ignore, options) {\n\t\t\t\tcollection.remove(model, options);\n\t\t\t},\n\t\t\t\"on\": function (model, collection, options) {\n\t\t\t\treturn {\n\t\t\t\t\tobject: collection,\n\t\t\t\t\tbefore: model,\n\t\t\t\t\tafter: undefined,\n\t\t\t\t\toptions: _.clone(options)\n\t\t\t\t};\n\t\t\t}\n\t\t},\n\t\t\"change\": {\n\t\t\t\"undo\": function (model, before, after, options) {\n\t\t\t\tif (_.isEmpty(before)) {\n\t\t\t\t\t_.each(_.keys(after), model.unset, model);\n\t\t\t\t} else {\n\t\t\t\t\tmodel.set(before);\n\t\t\t\t\tif (options && options.unsetData && options.unsetData.before && options.unsetData.before.length) {\n\t\t\t\t\t\t_.each(options.unsetData.before, model.unset, model);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t\t\"redo\": function (model, before, after, options) {\n\t\t\t\tif (_.isEmpty(after)) {\n\t\t\t\t\t_.each(_.keys(before), model.unset, model);\n\t\t\t\t} else {\n\t\t\t\t\tmodel.set(after);\n\t\t\t\t\tif (options && options.unsetData && options.unsetData.after && options.unsetData.after.length) {\n\t\t\t\t\t\t_.each(options.unsetData.after, model.unset, model);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t\t\"on\": function (model, options) {\n\t\t\t\tvar\n\t\t\t\tafterAttributes = model.changedAttributes(),\n\t\t\t\tkeysAfter = _.keys(afterAttributes),\n\t\t\t\tpreviousAttributes = _.pick(model.previousAttributes(), keysAfter),\n\t\t\t\tkeysPrevious = _.keys(previousAttributes),\n\t\t\t\tunsetData = (options || (options = {})).unsetData = {\n\t\t\t\t\tafter: [],\n\t\t\t\t\tbefore: []\n\t\t\t\t};\n\n\t\t\t\tif (keysAfter.length != keysPrevious.length) {\n\t\t\t\t\t// There are new attributes or old attributes have been unset\n\t\t\t\t\tif (keysAfter.length > keysPrevious.length) {\n\t\t\t\t\t\t// New attributes have been added\n\t\t\t\t\t\t_.each(keysAfter, function (val) {\n\t\t\t\t\t\t\tif (!(val in previousAttributes)) {\n\t\t\t\t\t\t\t\tunsetData.before.push(val);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}, this);\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Old attributes have been unset\n\t\t\t\t\t\t_.each(keysPrevious, function (val) {\n\t\t\t\t\t\t\tif (!(val in afterAttributes)) {\n\t\t\t\t\t\t\t\tunsetData.after.push(val);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tobject: model,\n\t\t\t\t\tbefore: previousAttributes,\n\t\t\t\t\tafter: afterAttributes,\n\t\t\t\t\toptions: _.clone(options)\n\t\t\t\t};\n\t\t\t}\n\t\t},\n\t\t\"reset\": {\n\t\t\t\"undo\": function (collection, before, after) {\n\t\t\t\tcollection.reset(before);\n\t\t\t},\n\t\t\t\"redo\": function (collection, before, after) {\n\t\t\t\tcollection.reset(after);\n\t\t\t},\n\t\t\t\"on\": function (collection, options) {\n\t\t\t\treturn {\n\t\t\t\t\tobject: collection,\n\t\t\t\t\tbefore: options.previousModels,\n\t\t\t\t\tafter: _.clone(collection.models)\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t};\n\n\t/**\n\t * Every UndoManager instance has an own undoTypes object\n\t * which is an instance of OwnedUndoTypes. OwnedUndoTypes' \n\t * prototype is the global UndoTypes object. Changes to the \n\t * global UndoTypes object take effect on every instance of\n\t * UndoManager as the object is its prototype. And yet every \n\t * local UndoTypes object can be changed individually.\n\t *\n\t * @constructor\n\t */\n\tfunction OwnedUndoTypes () {}\n\tOwnedUndoTypes.prototype = UndoTypes;\n\n\t/**\n\t * Adds, changes or removes an undo-type from an UndoTypes-object.\n\t * You can call it this way:\n\t * manipulateUndoType (1, \"reset\", {\"on\": function () {}}, undoTypes)\n\t * or this way to perform bulk actions:\n\t * manipulateUndoType (1, {\"reset\": {\"on\": function () {}}}, undoTypes)\n\t * In case of removing undo-types you can pass an Array for performing\n\t * bulk actions:\n\t * manipulateUndoType(2, [\"reset\", \"change\"], undoTypes)\n\t * \n\t * @param {Number} \t\t\t\t manipType \t\tIndicates the kind of action to execute: 0 for add, 1 for change, 2 for remove\n\t * @param {String|Object|Array} \t undoType \t\t\tThe type of undoType that should be added/changed/removed. Can be an object / array to perform bulk actions\n\t * @param {Object} \t\t\t\t [fns] \t\t\tObject with the functions to add / change. Is optional in case you passed an object as undoType that contains these functions\n\t * @param {OwnedUndoTypes|UndoTypes} undoTypesInstance The undoTypes object to act on\n\t * @return {undefined}\n\t */\n\tfunction manipulateUndoType (manipType, undoType, fns, undoTypesInstance) {\n\t\t// manipType, passed by the calling function\n\t\t// 0: add\n\t\t// 1: change\n\t\t// 2: remove\n\t\tif (typeof undoType === \"object\") {\n\t\t\t// bulk action. Iterate over this data.\n\t\t\treturn _.each(undoType, function (val, key) {\n\t\t\t\t\tif (manipType === 2) { // remove\n\t\t\t\t\t\t// undoType is an array\n\t\t\t\t\t\tmanipulateUndoType (manipType, val, fns, undoTypesInstance);\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// undoType is an object\n\t\t\t\t\t\tmanipulateUndoType (manipType, key, val, fns);\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t}\n\n\t\tswitch (manipType) {\n\t\t\tcase 0: // add\n\t\t\t\tif (hasKeys(fns, \"undo\", \"redo\", \"on\") && _.all(_.pick(fns, \"undo\", \"redo\", \"on\"), _.isFunction)) {\n\t\t\t\t\tundoTypesInstance[undoType] = fns;\n\t\t\t\t} \n\t\t\tbreak;\n\t\t\tcase 1: // change\n\t\t\t\tif (undoTypesInstance[undoType] && _.isObject(fns)) {\n\t\t\t\t\t// undoTypeInstance[undoType] may be a prototype's property\n\t\t\t\t\t// So, if we did this _.extend(undoTypeInstance[undoType], fns)\n\t\t\t\t\t// we would extend the object on the prototype which means\n\t\t\t\t\t// that this change would have a global effect\n\t\t\t\t\t// Instead we just want to manipulate this instance. That's why\n\t\t\t\t\t// we're doing this:\n\t\t\t\t\tundoTypesInstance[undoType] = _.extend({}, undoTypesInstance[undoType], fns);\n\t\t\t\t} \n\t\t\tbreak;\n\t\t\tcase 2: // remove\n\t\t\t\tdelete undoTypesInstance[undoType]; \n\t\t\tbreak;\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Instantiating \"Action\" creates the UndoActions that \n\t * are collected in an UndoStack. It holds all relevant \n\t * data to undo / redo an action and has an undo / redo \n\t * method.\n\t */\n\tvar Action = Backbone.Model.extend({\n\t\tdefaults: {\n\t\t\ttype: null, // \"add\", \"change\", \"reset\", etc.\n\t\t\tobject: null, // The object on which the action occurred\n\t\t\tbefore: null, // The previous values which were changed with this action\n\t\t\tafter: null, // The values after this action\n\t\t\tmagicFusionIndex: null // The magicFusionIndex helps to combine \n\t\t\t// all actions that occurred \"at the same time\" to undo/redo them altogether\n\t\t},\n\t\t/**\n\t\t * Undoes this action.\n\t\t * @param {OwnedUndoTypes|UndoTypes} undoTypes The undoTypes object which contains the \"undo\"-handler that should be used\n\t\t * @return {undefined}\n\t\t */\n\t\tundo: function (undoTypes) {\n\t\t\tactionUndoRedo(\"undo\", this.attributes);\n\t\t},\n\t\t/**\n\t\t * Redoes this action.\n\t\t * @param {OwnedUndoTypes|UndoTypes} undoTypes The undoTypes object which contains the \"redo\"-handler that should be used\n\t\t * @return {undefined}\n\t\t */\n\t\tredo: function (undoTypes) {\n\t\t\tactionUndoRedo(\"redo\", this.attributes);\n\t\t}\n\t}),\n\t/**\n\t * An UndoStack is a collection of UndoActions in \n\t * chronological order.\n\t */\n\tUndoStack = Backbone.Collection.extend({\n\t\tmodel: Action,\n\t\tpointer: -1, // The pointer indicates the index where we are located within the stack. We start at -1\n\t\ttrack: false,\n\t\tisCurrentlyUndoRedoing: false,\n\t\tmaximumStackLength: Infinity,\n\t\tsetMaxLength: function (val) {\n\t\t\tthis.maximumStackLength = val;\n\t\t}\n\t}),\n\t/**\n\t * An instance of UndoManager can keep track of \n\t * changes to objects and helps to undo them.\n\t */\n\tUndoManager = Backbone.Model.extend({\n\t\tdefaults: {\n\t\t\tmaximumStackLength: Infinity,\n\t\t\ttrack: false\n\t\t},\n\t\t/**\n\t\t * The constructor function.\n\t\t * @param {attr} \t\t[attr] Object with parameters. The available parameters are:\n\t\t * \t - maximumStackLength {number} \tSet the undo-stack's maximum size\n\t\t * - track \t\t\t\t{boolean}\tStart tracking changes right away\n\t\t * @return {undefined}\n\t\t */\n\t\tinitialize: function (attr) {\n\t\t\tthis.stack = new UndoStack;\n\t\t\tthis.objectRegistry = new ObjectRegistry();\n\t\t\tthis.undoTypes = new OwnedUndoTypes();\n\n\t\t\t// sync the maximumStackLength attribute with our stack\n\t\t\tthis.stack.setMaxLength(this.get(\"maximumStackLength\"));\n\t\t\tthis.on(\"change:maximumStackLength\", function (model, value) {\n\t\t\t\tthis.stack.setMaxLength(value);\n\t\t\t}, this);\n\n\t\t\t// Start tracking, if attr.track == true\n\t\t\tif (attr && attr.track) {\n\t\t\t\tthis.startTracking();\n\t\t\t}\n\n\t\t\t// Register objects passed in the \"register\" attribute\n\t\t\tif (attr && attr.register) {\n\t\t\t\tif (_.isArray(attr.register) || _.isArguments(attr.register)) {\n\t\t\t\t\tapply(this.register, this, attr.register);\n\t\t\t\t} else {\n\t\t\t\t\tthis.register(attr.register);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t/**\n\t\t * Starts tracking. Changes of registered objects won't be processed until you've called this function\n\t\t * @return {undefined}\n\t\t */\n\t\tstartTracking: function () {\n\t\t\tthis.set(\"track\", true);\n\t\t\tthis.stack.track = true;\n\t\t},\n\t\t/**\n\t\t * Stops tracking. Afterwards changes of registered objects won't be processed.\n\t\t * @return {undefined}\n\t\t */\n\t\tstopTracking: function () {\n\t\t\tthis.set(\"track\", false);\n\t\t\tthis.stack.track = false;\n\t\t},\n\t\t/**\n\t\t * Return the state of the tracking\n\t\t * @return {boolean}\n\t\t */\n\t\tisTracking: function () {\n\t\t\treturn this.get(\"track\");\n\t\t},\n\t\t/**\n\t\t * This is the \"all\"-handler which is bound to registered \n\t\t * objects. It creates an UndoAction from the event and adds \n\t\t * it to the stack.\n\t\t * \n\t\t * @param {String} \ttype \tThe event type\n\t\t * @return {undefined}\n\t\t */\n\t\t_addToStack: function (type) {\n\t\t\taddToStack(this.stack, type, slice(arguments, 1), this.undoTypes);\n\t\t},\n\t\t/**\n\t\t * Registers one or more objects to track their changes.\n\t\t * @param {...Object} \tobj \tThe object or objects of which changes should be tracked\n\t\t * @return {undefined}\n\t\t */\n\t\tregister: function () {\n\t\t\tonoff(\"on\", arguments, this._addToStack, this);\n\t\t},\n\t\t/**\n\t\t * Unregisters one or more objects.\n\t\t * @param {...Object} \tobj \tThe object or objects of which changes shouldn't be tracked any longer\n\t\t * @return {undefined}\n\t\t */\n\t\tunregister: function () {\n\t\t\tonoff(\"off\", arguments, this._addToStack, this);\n\t\t},\n\t\t/**\n\t\t * Unregisters all previously registered objects.\n\t\t * @return {undefined}\n\t\t */\n\t\tunregisterAll: function () {\n\t\t\tapply(this.unregister, this, this.objectRegistry.get());\n\t\t},\n\t\t/**\n\t\t * Undoes the last action or the last set of actions in case 'magic' is true.\n\t\t * @param {Boolean} \t[magic] \tIf true, all actions that happened basically at the same time are undone together\n\t\t * @return {undefined}\n\t\t */\n\t\tundo: function (magic) {\n\t\t\tmanagerUndoRedo(\"undo\", this, this.stack, magic);\n\t\t},\n\n\t\t/**\n\t\t * Undoes all actions ever tracked by the undo manager\n\t\t * @return {undefined}\n\t\t */\n\t\tundoAll: function () {\n\t\t\tmanagerUndoRedo(\"undo\", this, this.stack, false, true);\n\t\t},\n\n\t\t/**\n\t\t * Redoes a previously undone action or a set of actions.\n\t\t * @param {Boolean} \t[magic] \tIf true, all actions that happened basically at the same time are redone together\n\t\t * @return {undefined}\n\t\t */\n\t\tredo: function (magic) {\n\t\t\tmanagerUndoRedo(\"redo\", this, this.stack, magic);\n\t\t},\n\n\t\t/**\n\t\t * Redoes all actions ever tracked by the undo manager\n\t\t * @return {undefined}\n\t\t */\n\t\tredoAll: function () {\n\t\t\tmanagerUndoRedo(\"redo\", this, this.stack, false, true);\n\t\t},\n\t\t/**\n\t\t * Checks if there's an action in the stack that can be undone / redone\n\t\t * @param {String} \ttype \tEither \"undo\" or \"redo\"\n\t\t * @return {Boolean} True if there is a set of actions which can be undone / redone\n\t\t */\n\t\tisAvailable: function (type) {\n\t\t\tvar s = this.stack, l = s.length;\n\n\t\t\tswitch (type) {\n\t\t\t\tcase \"undo\": return l > 0 && s.pointer > -1;\n\t\t\t\tcase \"redo\": return l > 0 && s.pointer < l - 1;\n\t\t\t\tdefault: return false;\n\t\t\t}\n\t\t},\n\t\t/**\n\t\t * Sets the stack-reference to the stack of another undoManager.\n\t\t * @param {UndoManager} \tundoManager \tThe undoManager whose stack-reference is set to this stack\n\t\t * @return {undefined}\n\t\t */\n\t\tmerge: function (undoManager) {\n\t\t\t// This sets the stack-reference to the stack of another \n\t\t\t// undoManager so that the stack of this other undoManager \n\t\t\t// is used by two different managers.\n\t\t\t// This enables to set up a main-undoManager and besides it\n\t\t\t// several others for special, exceptional cases (by using\n\t\t\t// instance-based custom UndoTypes). Models / collections \n\t\t\t// which need this special treatment are only registered at \n\t\t\t// those special undoManagers. Those special ones are then \n\t\t\t// merged into the main-undoManager to write on its stack. \n\t\t\t// That way it's easier to manage exceptional cases.\n\t\t\tvar args = _.isArray(undoManager) ? undoManager : slice(arguments), manager;\n\t\t\twhile (manager = args.pop()) {\n\t\t\t\tif (manager instanceof UndoManager &&\n\t\t\t\t\tmanager.stack instanceof UndoStack) {\n\t\t\t\t\t// set the stack reference to our stack\n\t\t\t\t\tmanager.stack = this.stack;\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t/**\n\t\t * Add an UndoType to this specific UndoManager-instance.\n\t\t * @param {String} type The event this UndoType is made for\n\t\t * @param {Object} fns An object of functions that are called to generate the data for an UndoAction or to process it. Must have the properties \"undo\", \"redo\" and \"on\". Can have the property \"condition\".\n\t\t * @return {undefined}\n\t\t */\n\t\taddUndoType: function (type, fns) {\n\t\t\tmanipulateUndoType(0, type, fns, this.undoTypes);\n\t\t},\n\t\t/**\n\t\t * Overwrite properties of an existing UndoType for this specific UndoManager-instance.\n\t\t * @param {String} type The event the UndoType is made for\n\t\t * @param {Object} fns An object of functions that are called to generate the data for an UndoAction or to process it. It extends the existing object.\n\t\t * @return {undefined}\n\t\t */\n\t\tchangeUndoType: function (type, fns) {\n\t\t\tmanipulateUndoType(1, type, fns, this.undoTypes);\n\t\t},\n\t\t/**\n\t\t * Remove one or more UndoTypes of this specific UndoManager-instance to fall back to the global UndoTypes.\n\t\t * @param {String|Array} type The event the UndoType that should be removed is made for. You can also pass an array of events.\n\t\t * @return {undefined}\n\t\t */\n\t\tremoveUndoType: function (type) {\n\t\t\tmanipulateUndoType(2, type, undefined, this.undoTypes);\n\t\t},\n\n\t\t/**\n\t\t * Removes all actions from the stack.\n\t\t * @return {undefined}\n\t\t */\n\t\tclear: function() {\n\t\t\tthis.stack.reset();\n\t\t\tthis.stack.pointer = -1;\n\t\t}\n\t});\n\n\t_.extend(UndoManager, {\n\t\t/**\n\t\t * Change the UndoManager's default attributes\n\t\t * @param {Object} defaultAttributes An object with the new default values.\n\t\t * @return {undefined}\n\t\t */\n\t\tdefaults: function (defaultAttributes) {\n\t\t\t_.extend(UndoManager.prototype.defaults, defaultAttributes);\n\t\t},\n\t\t/**\n\t\t * Add an UndoType to the global UndoTypes-object.\n\t\t * @param {String} type The event this UndoType is made for\n\t\t * @param {Object} fns An object of functions that are called to generate the data for an UndoAction or to process it. Must have the properties \"undo\", \"redo\" and \"on\". Can have the property \"condition\".\n\t\t * @return {undefined}\n\t\t */\n\t\t\"addUndoType\": function (type, fns) {\n\t\t\tmanipulateUndoType(0, type, fns, UndoTypes);\n\t\t},\n\t\t/**\n\t\t * Overwrite properties of an existing UndoType in the global UndoTypes-object.\n\t\t * @param {String} type The event the UndoType is made for\n\t\t * @param {Object} fns An object of functions that are called to generate the data for an UndoAction or to process it. It extends the existing object.\n\t\t * @return {undefined}\n\t\t */\n\t\t\"changeUndoType\": function (type, fns) {\n\t\t\tmanipulateUndoType(1, type, fns, UndoTypes)\n\t\t},\n\t\t/**\n\t\t * Remove one or more UndoTypes of this specific UndoManager-instance to fall back to the global UndoTypes.\n\t\t * @param {String|Array} type The event the UndoType that should be removed is made for. You can also pass an array of events.\n\t\t * @return {undefined}\n\t\t */\n\t\t\"removeUndoType\": function (type) {\n\t\t\tmanipulateUndoType(2, type, undefined, UndoTypes);\n\t\t}\n\t})\n\n\treturn Backbone.UndoManager = UndoManager;\n\n});\n","/**\n * @this {Promise}\n */\nfunction finallyConstructor(callback) {\n var constructor = this.constructor;\n return this.then(\n function(value) {\n // @ts-ignore\n return constructor.resolve(callback()).then(function() {\n return value;\n });\n },\n function(reason) {\n // @ts-ignore\n return constructor.resolve(callback()).then(function() {\n // @ts-ignore\n return constructor.reject(reason);\n });\n }\n );\n}\n\nexport default finallyConstructor;\n","var arrayWithHoles = require(\"./arrayWithHoles\");\n\nvar iterableToArrayLimit = require(\"./iterableToArrayLimit\");\n\nvar nonIterableRest = require(\"./nonIterableRest\");\n\nfunction _slicedToArray(arr, i) {\n return arrayWithHoles(arr) || iterableToArrayLimit(arr, i) || nonIterableRest();\n}\n\nmodule.exports = _slicedToArray;","module.exports = function(module) {\n\tif (!module.webpackPolyfill) {\n\t\tmodule.deprecate = function() {};\n\t\tmodule.paths = [];\n\t\t// module.parent = undefined by default\n\t\tif (!module.children) module.children = [];\n\t\tObject.defineProperty(module, \"loaded\", {\n\t\t\tenumerable: true,\n\t\t\tget: function() {\n\t\t\t\treturn module.l;\n\t\t\t}\n\t\t});\n\t\tObject.defineProperty(module, \"id\", {\n\t\t\tenumerable: true,\n\t\t\tget: function() {\n\t\t\t\treturn module.i;\n\t\t\t}\n\t\t});\n\t\tmodule.webpackPolyfill = 1;\n\t}\n\treturn module;\n};\n","function _arrayWithoutHoles(arr) {\n if (Array.isArray(arr)) {\n for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {\n arr2[i] = arr[i];\n }\n\n return arr2;\n }\n}\n\nmodule.exports = _arrayWithoutHoles;","function _iterableToArray(iter) {\n if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === \"[object Arguments]\") return Array.from(iter);\n}\n\nmodule.exports = _iterableToArray;","function _nonIterableSpread() {\n throw new TypeError(\"Invalid attempt to spread non-iterable instance\");\n}\n\nmodule.exports = _nonIterableSpread;","/**\n * You can customize the initial state of the module from the editor initialization\n * ```js\n * const editor = grapesjs.init({\n * keymaps: {\n * // Object of keymaps\n * defaults: {\n * 'your-namespace:keymap-name' {\n * keys: '⌘+z, ctrl+z',\n * handler: 'some-command-id'\n * },\n * ...\n * }\n * }\n * })\n * ```\n *\n * Once the editor is instantiated you can use its API. Before using these methods you should get the module from the instance\n *\n * ```js\n * const keymaps = editor.Keymaps;\n * ```\n *\n * * [getConfig](#getconfig)\n * * [add](#add)\n * * [get](#get)\n * * [getAll](#getAll)\n * * [remove](#remove)\n * * [removeAll](#removeall)\n *\n * @module Keymaps\n */\n\nimport { isString } from 'underscore';\nimport keymaster from 'keymaster';\n\nexport default () => {\n let em;\n let config;\n const keymaps = {};\n const configDef = {\n defaults: {\n 'core:undo': {\n keys: '⌘+z, ctrl+z',\n handler: 'core:undo'\n },\n 'core:redo': {\n keys: '⌘+shift+z, ctrl+shift+z',\n handler: 'core:redo'\n },\n 'core:copy': {\n keys: '⌘+c, ctrl+c',\n handler: 'core:copy'\n },\n 'core:paste': {\n keys: '⌘+v, ctrl+v',\n handler: 'core:paste'\n },\n 'core:component-next': {\n keys: 's',\n handler: 'core:component-next'\n },\n 'core:component-prev': {\n keys: 'w',\n handler: 'core:component-prev'\n },\n 'core:component-enter': {\n keys: 'd',\n handler: 'core:component-enter'\n },\n 'core:component-exit': {\n keys: 'a',\n handler: 'core:component-exit'\n },\n 'core:component-delete': {\n keys: 'backspace, delete',\n handler: 'core:component-delete'\n }\n }\n };\n\n return {\n keymaster,\n\n name: 'Keymaps',\n\n /**\n * Get module configurations\n * @return {Object} Configuration object\n */\n getConfig() {\n return config;\n },\n\n /**\n * Initialize module\n * @param {Object} config Configurations\n * @private\n */\n init(opts = {}) {\n config = { ...configDef, ...opts };\n em = config.em;\n this.em = em;\n return this;\n },\n\n onLoad() {\n const defKeys = config.defaults;\n\n for (let id in defKeys) {\n const value = defKeys[id];\n this.add(id, value.keys, value.handler);\n }\n },\n\n /**\n * Add new keymap\n * @param {string} id Keymap id\n * @param {string} keys Keymap keys, eg. `ctrl+a`, `⌘+z, ctrl+z`\n * @param {Function|string} handler Keymap handler, might be a function\n * @param {Object} [opts={}] Options\n * @return {Object} Added keymap\n * or just a command id as a string\n * @example\n * // 'ns' is just a custom namespace\n * keymaps.add('ns:my-keymap', '⌘+j, ⌘+u, ctrl+j, alt+u', editor => {\n * console.log('do stuff');\n * });\n * // or\n * keymaps.add('ns:my-keymap', '⌘+s, ctrl+s', 'some-gjs-command');\n *\n * // listen to events\n * editor.on('keymap:emit', (id, shortcut, e) => {\n * // ...\n * })\n */\n add(id, keys, handler, opts = {}) {\n const { em } = this;\n const cmd = em.get('Commands');\n const editor = em.getEditor();\n const canvas = em.get('Canvas');\n const keymap = { id, keys, handler };\n const pk = keymaps[id];\n pk && this.remove(id);\n keymaps[id] = keymap;\n keymaster(keys, (e, h) => {\n // It's safer putting handlers resolution inside the callback\n const opt = { event: e, h };\n handler = isString(handler) ? cmd.get(handler) : handler;\n opts.prevent && canvas.getCanvasView().preventDefault(e);\n const ableTorun = !em.isEditing() && !editor.Canvas.isInputFocused();\n if (ableTorun || opts.force) {\n typeof handler == 'object'\n ? handler.run(editor, 0, opt)\n : handler(editor, 0, opt);\n const args = [id, h.shortcut, e];\n em.trigger('keymap:emit', ...args);\n em.trigger(`keymap:emit:${id}`, ...args);\n }\n });\n em.trigger('keymap:add', keymap);\n return keymap;\n },\n\n /**\n * Get the keymap by id\n * @param {string} id Keymap id\n * @return {Object} Keymap object\n * @example\n * keymaps.get('ns:my-keymap');\n * // -> {keys, handler};\n */\n get(id) {\n return keymaps[id];\n },\n\n /**\n * Get all keymaps\n * @return {Object}\n * @example\n * keymaps.getAll();\n * // -> {id1: {}, id2: {}};\n */\n getAll() {\n return keymaps;\n },\n\n /**\n * Remove the keymap by id\n * @param {string} id Keymap id\n * @return {Object} Removed keymap\n * @example\n * keymaps.remove('ns:my-keymap');\n * // -> {keys, handler};\n */\n remove(id) {\n const em = this.em;\n const keymap = this.get(id);\n\n if (keymap) {\n delete keymaps[id];\n keymaster.unbind(keymap.keys);\n em && em.trigger('keymap:remove', keymap);\n return keymap;\n }\n },\n\n /**\n * Remove all binded keymaps\n * @return {this}\n */\n removeAll() {\n Object.keys(keymaps).forEach(keymap => this.remove(keymap));\n return this;\n }\n };\n};\n","/**\n * This module allows to manage the stack of changes applied in canvas.\n * Once the editor is instantiated you can use its API. Before using these methods you should get the module from the instance\n *\n * ```js\n * const um = editor.UndoManager;\n * ```\n *\n * * [getConfig](#getconfig)\n * * [add](#add)\n * * [remove](#remove)\n * * [removeAll](#removeall)\n * * [start](#start)\n * * [stop](#stop)\n * * [undo](#undo)\n * * [undoAll](#undoall)\n * * [redo](#redo)\n * * [redoAll](#redoall)\n * * [hasUndo](#hasundo)\n * * [hasRedo](#hasredo)\n * * [getStack](#getstack)\n * * [clear](#clear)\n *\n * @module UndoManager\n */\n\nimport UndoManager from 'backbone-undo';\n\nexport default () => {\n let em;\n let um;\n let config;\n let beforeCache;\n const configDef = {\n maximumStackLength: 500\n };\n\n return {\n name: 'UndoManager',\n\n /**\n * Initialize module\n * @param {Object} config Configurations\n * @private\n */\n init(opts = {}) {\n config = { ...opts, ...configDef };\n em = config.em;\n this.em = em;\n um = new UndoManager({ track: true, register: [], ...config });\n um.changeUndoType('change', { condition: false });\n um.changeUndoType('add', {\n on(model, collection, options = {}) {\n if (options.avoidStore) return;\n return {\n object: collection,\n before: undefined,\n after: model,\n options: { ...options }\n };\n }\n });\n um.changeUndoType('remove', {\n on(model, collection, options = {}) {\n if (options.avoidStore) return;\n return {\n object: collection,\n before: model,\n after: undefined,\n options: { ...options }\n };\n }\n });\n const customUndoType = {\n on(object, value, opt = {}) {\n !beforeCache && (beforeCache = object.previousAttributes());\n\n if (opt.avoidStore) {\n return;\n } else {\n const result = {\n object,\n before: beforeCache,\n after: object.toJSON()\n };\n beforeCache = null;\n return result;\n }\n },\n\n undo(model, bf, af, opt) {\n model.set(bf);\n },\n\n redo(model, bf, af, opt) {\n model.set(af);\n }\n };\n\n const events = ['style', 'attributes', 'content', 'src'];\n events.forEach(ev => um.addUndoType(`change:${ev}`, customUndoType));\n um.on('undo redo', () =>\n em.trigger('component:toggled change:canvasOffset')\n );\n ['undo', 'redo'].forEach(ev => um.on(ev, () => em.trigger(ev)));\n\n return this;\n },\n\n /**\n * Get module configurations\n * @return {Object} Configuration object\n * @example\n * const config = um.getConfig();\n * // { ... }\n */\n getConfig() {\n return config;\n },\n\n /**\n * Add an entity (Model/Collection) to track\n * Note: New Components and CSSRules will be added automatically\n * @param {Model|Collection} entity Entity to track\n * @return {this}\n * @example\n * um.add(someModelOrCollection);\n */\n add(entity) {\n um.register(entity);\n return this;\n },\n\n /**\n * Remove and stop tracking the entity (Model/Collection)\n * @param {Model|Collection} entity Entity to remove\n * @return {this}\n * @example\n * um.remove(someModelOrCollection);\n */\n remove(entity) {\n um.unregister(entity);\n return this;\n },\n\n /**\n * Remove all entities\n * @return {this}\n * @example\n * um.removeAll();\n */\n removeAll() {\n um.unregisterAll();\n return this;\n },\n\n /**\n * Start/resume tracking changes\n * @return {this}\n * @example\n * um.start();\n */\n start() {\n um.startTracking();\n return this;\n },\n\n /**\n * Stop tracking changes\n * @return {this}\n * @example\n * um.stop();\n */\n stop() {\n um.stopTracking();\n return this;\n },\n\n /**\n * Undo last change\n * @return {this}\n * @example\n * um.undo();\n */\n undo(all = true) {\n !em.isEditing() && um.undo(all);\n return this;\n },\n\n /**\n * Undo all changes\n * @return {this}\n * @example\n * um.undoAll();\n */\n undoAll() {\n um.undoAll();\n return this;\n },\n\n /**\n * Redo last change\n * @return {this}\n * @example\n * um.redo();\n */\n redo(all = true) {\n !em.isEditing() && um.redo(all);\n return this;\n },\n\n /**\n * Redo all changes\n * @return {this}\n * @example\n * um.redoAll();\n */\n redoAll() {\n um.redoAll();\n return this;\n },\n\n /**\n * Checks if exists an available undo\n * @return {Boolean}\n * @example\n * um.hasUndo();\n */\n hasUndo() {\n return um.isAvailable('undo');\n },\n\n /**\n * Checks if exists an available redo\n * @return {Boolean}\n * @example\n * um.hasRedo();\n */\n hasRedo() {\n return um.isAvailable('redo');\n },\n\n /**\n * Get stack of changes\n * @return {Collection}\n * @example\n * const stack = um.getStack();\n * stack.each(item => ...);\n */\n getStack() {\n return um.stack;\n },\n\n /**\n * Get grouped undo manager stack.\n * The difference between `getStack` is when you do multiple operations at a time,\n * like appending multiple components:\n * `editor.getWrapper().append(`
C1
C2
`);`\n * `getStack` will return a collection length of 2.\n * `getStackGroup` instead will group them as a single operation (the first\n * inserted component will be returned in the list) by returning an array length of 1.\n * @return {Array}\n */\n getStackGroup() {\n const result = [];\n const inserted = [];\n\n this.getStack().forEach(item => {\n const index = item.get('magicFusionIndex');\n if (inserted.indexOf(index) < 0) {\n inserted.push(index);\n result.push(item);\n }\n });\n\n return result;\n },\n\n getPointer() {\n return this.getStack().pointer;\n },\n\n /**\n * Clear the stack\n * @return {this}\n * @example\n * um.clear();\n */\n clear() {\n um.clear();\n return this;\n },\n\n getInstance() {\n return um;\n }\n };\n};\n","var scope = (typeof global !== \"undefined\" && global) ||\n (typeof self !== \"undefined\" && self) ||\n window;\nvar apply = Function.prototype.apply;\n\n// DOM APIs, for completeness\n\nexports.setTimeout = function() {\n return new Timeout(apply.call(setTimeout, scope, arguments), clearTimeout);\n};\nexports.setInterval = function() {\n return new Timeout(apply.call(setInterval, scope, arguments), clearInterval);\n};\nexports.clearTimeout =\nexports.clearInterval = function(timeout) {\n if (timeout) {\n timeout.close();\n }\n};\n\nfunction Timeout(id, clearFn) {\n this._id = id;\n this._clearFn = clearFn;\n}\nTimeout.prototype.unref = Timeout.prototype.ref = function() {};\nTimeout.prototype.close = function() {\n this._clearFn.call(scope, this._id);\n};\n\n// Does not start the time, just sets up the members needed.\nexports.enroll = function(item, msecs) {\n clearTimeout(item._idleTimeoutId);\n item._idleTimeout = msecs;\n};\n\nexports.unenroll = function(item) {\n clearTimeout(item._idleTimeoutId);\n item._idleTimeout = -1;\n};\n\nexports._unrefActive = exports.active = function(item) {\n clearTimeout(item._idleTimeoutId);\n\n var msecs = item._idleTimeout;\n if (msecs >= 0) {\n item._idleTimeoutId = setTimeout(function onTimeout() {\n if (item._onTimeout)\n item._onTimeout();\n }, msecs);\n }\n};\n\n// setimmediate attaches itself to the global object\nrequire(\"setimmediate\");\n// On some exotic environments, it's not clear which object `setimmediate` was\n// able to install onto. Search each possibility in the same order as the\n// `setimmediate` library.\nexports.setImmediate = (typeof self !== \"undefined\" && self.setImmediate) ||\n (typeof global !== \"undefined\" && global.setImmediate) ||\n (this && this.setImmediate);\nexports.clearImmediate = (typeof self !== \"undefined\" && self.clearImmediate) ||\n (typeof global !== \"undefined\" && global.clearImmediate) ||\n (this && this.clearImmediate);\n","(function (global, undefined) {\n \"use strict\";\n\n if (global.setImmediate) {\n return;\n }\n\n var nextHandle = 1; // Spec says greater than zero\n var tasksByHandle = {};\n var currentlyRunningATask = false;\n var doc = global.document;\n var registerImmediate;\n\n function setImmediate(callback) {\n // Callback can either be a function or a string\n if (typeof callback !== \"function\") {\n callback = new Function(\"\" + callback);\n }\n // Copy function arguments\n var args = new Array(arguments.length - 1);\n for (var i = 0; i < args.length; i++) {\n args[i] = arguments[i + 1];\n }\n // Store and register the task\n var task = { callback: callback, args: args };\n tasksByHandle[nextHandle] = task;\n registerImmediate(nextHandle);\n return nextHandle++;\n }\n\n function clearImmediate(handle) {\n delete tasksByHandle[handle];\n }\n\n function run(task) {\n var callback = task.callback;\n var args = task.args;\n switch (args.length) {\n case 0:\n callback();\n break;\n case 1:\n callback(args[0]);\n break;\n case 2:\n callback(args[0], args[1]);\n break;\n case 3:\n callback(args[0], args[1], args[2]);\n break;\n default:\n callback.apply(undefined, args);\n break;\n }\n }\n\n function runIfPresent(handle) {\n // From the spec: \"Wait until any invocations of this algorithm started before this one have completed.\"\n // So if we're currently running a task, we'll need to delay this invocation.\n if (currentlyRunningATask) {\n // Delay by doing a setTimeout. setImmediate was tried instead, but in Firefox 7 it generated a\n // \"too much recursion\" error.\n setTimeout(runIfPresent, 0, handle);\n } else {\n var task = tasksByHandle[handle];\n if (task) {\n currentlyRunningATask = true;\n try {\n run(task);\n } finally {\n clearImmediate(handle);\n currentlyRunningATask = false;\n }\n }\n }\n }\n\n function installNextTickImplementation() {\n registerImmediate = function(handle) {\n process.nextTick(function () { runIfPresent(handle); });\n };\n }\n\n function canUsePostMessage() {\n // The test against `importScripts` prevents this implementation from being installed inside a web worker,\n // where `global.postMessage` means something completely different and can't be used for this purpose.\n if (global.postMessage && !global.importScripts) {\n var postMessageIsAsynchronous = true;\n var oldOnMessage = global.onmessage;\n global.onmessage = function() {\n postMessageIsAsynchronous = false;\n };\n global.postMessage(\"\", \"*\");\n global.onmessage = oldOnMessage;\n return postMessageIsAsynchronous;\n }\n }\n\n function installPostMessageImplementation() {\n // Installs an event handler on `global` for the `message` event: see\n // * https://developer.mozilla.org/en/DOM/window.postMessage\n // * http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html#crossDocumentMessages\n\n var messagePrefix = \"setImmediate$\" + Math.random() + \"$\";\n var onGlobalMessage = function(event) {\n if (event.source === global &&\n typeof event.data === \"string\" &&\n event.data.indexOf(messagePrefix) === 0) {\n runIfPresent(+event.data.slice(messagePrefix.length));\n }\n };\n\n if (global.addEventListener) {\n global.addEventListener(\"message\", onGlobalMessage, false);\n } else {\n global.attachEvent(\"onmessage\", onGlobalMessage);\n }\n\n registerImmediate = function(handle) {\n global.postMessage(messagePrefix + handle, \"*\");\n };\n }\n\n function installMessageChannelImplementation() {\n var channel = new MessageChannel();\n channel.port1.onmessage = function(event) {\n var handle = event.data;\n runIfPresent(handle);\n };\n\n registerImmediate = function(handle) {\n channel.port2.postMessage(handle);\n };\n }\n\n function installReadyStateChangeImplementation() {\n var html = doc.documentElement;\n registerImmediate = function(handle) {\n // Create a ` : '';\n return html;\n },\n\n /**\n * Returns CSS built inside canvas\n * @param {Object} [opts={}] Options\n * @return {string} CSS string\n * @private\n */\n getCss(opts = {}) {\n const config = this.config;\n const wrapperIsBody = config.wrapperIsBody;\n const avoidProt = opts.avoidProtected;\n const keepUnusedStyles = !isUndefined(opts.keepUnusedStyles)\n ? opts.keepUnusedStyles\n : config.keepUnusedStyles;\n const cssc = this.get('CssComposer');\n const wrp = this.get('DomComponents').getComponent();\n const protCss = !avoidProt ? config.protectedCss : '';\n\n return (\n protCss +\n this.get('CodeManager').getCode(wrp, 'css', {\n cssc,\n wrapperIsBody,\n keepUnusedStyles\n })\n );\n },\n\n /**\n * Returns JS of all components\n * @return {string} JS string\n * @private\n */\n getJs() {\n var wrp = this.get('DomComponents').getWrapper();\n return this.get('CodeManager')\n .getCode(wrp, 'js')\n .trim();\n },\n\n /**\n * Store data to the current storage\n * @param {Function} clb Callback function\n * @return {Object} Stored data\n * @private\n */\n store(clb) {\n var sm = this.get('StorageManager');\n var store = {};\n if (!sm) return;\n\n // Fetch what to store\n this.get('storables').forEach(m => {\n var obj = m.store(1);\n for (var el in obj) store[el] = obj[el];\n });\n\n sm.store(store, res => {\n clb && clb(res);\n this.set('changesCount', 0);\n this.trigger('storage:store', store);\n });\n\n return store;\n },\n\n /**\n * Load data from the current storage\n * @param {Function} clb Callback function\n * @private\n */\n load(clb = null) {\n this.getCacheLoad(1, res => {\n this.get('storables').forEach(module => module.load(res));\n clb && clb(res);\n });\n },\n\n /**\n * Returns cached load\n * @param {Boolean} force Force to reload\n * @param {Function} clb Callback function\n * @return {Object}\n * @private\n */\n getCacheLoad(force, clb) {\n if (this.cacheLoad && !force) return this.cacheLoad;\n const sm = this.get('StorageManager');\n const load = [];\n\n if (!sm) return {};\n\n this.get('storables').forEach(m => {\n let key = m.storageKey;\n key = isFunction(key) ? key() : key;\n const keys = isArray(key) ? key : [key];\n keys.forEach(k => load.push(k));\n });\n\n sm.load(load, res => {\n this.cacheLoad = res;\n clb && clb(res);\n setTimeout(() => this.trigger('storage:load', res));\n });\n },\n\n /**\n * Returns device model by name\n * @return {Device|null}\n * @private\n */\n getDeviceModel() {\n var name = this.get('device');\n return this.get('DeviceManager').get(name);\n },\n\n /**\n * Run default command if setted\n * @param {Object} [opts={}] Options\n * @private\n */\n runDefault(opts = {}) {\n var command = this.get('Commands').get(this.config.defaultCommand);\n if (!command || this.defaultRunning) return;\n command.stop(this, this, opts);\n command.run(this, this, opts);\n this.defaultRunning = 1;\n },\n\n /**\n * Stop default command\n * @param {Object} [opts={}] Options\n * @private\n */\n stopDefault(opts = {}) {\n const commands = this.get('Commands');\n const command = commands.get(this.config.defaultCommand);\n if (!command) return;\n command.stop(this, this, opts);\n this.defaultRunning = 0;\n },\n\n /**\n * Update canvas dimensions and refresh data useful for tools positioning\n * @private\n */\n refreshCanvas() {\n this.set('canvasOffset', null);\n this.set('canvasOffset', this.get('Canvas').getOffset());\n },\n\n /**\n * Clear all selected stuf inside the window, sometimes is useful to call before\n * doing some dragging opearation\n * @param {Window} win If not passed the current one will be used\n * @private\n */\n clearSelection(win) {\n var w = win || window;\n w.getSelection().removeAllRanges();\n },\n\n /**\n * Get the current media text\n * @return {string}\n */\n getCurrentMedia() {\n const config = this.config;\n const device = this.getDeviceModel();\n const condition = config.mediaCondition;\n const preview = config.devicePreviewMode;\n const width = device && device.get('widthMedia');\n return device && width && !preview ? `(${condition}: ${width})` : '';\n },\n\n /**\n * Return the component wrapper\n * @return {Component}\n */\n getWrapper() {\n return this.get('DomComponents').getWrapper();\n },\n\n setCurrentFrame(frameView) {\n return this.set('currentFrame', frameView);\n },\n\n getCurrentFrame() {\n return this.get('currentFrame');\n },\n\n getCurrentFrameModel() {\n return (this.getCurrentFrame() || {}).model;\n },\n\n /**\n * Return the count of changes made to the content and not yet stored.\n * This count resets at any `store()`\n * @return {number}\n */\n getDirtyCount() {\n return this.get('changesCount');\n },\n\n getZoomDecimal() {\n return this.get('Canvas').getZoomDecimal();\n },\n\n getZoomMultiplier() {\n return this.get('Canvas').getZoomMultiplier();\n },\n\n setDragMode(value) {\n return this.set('dmode', value);\n },\n\n t(...args) {\n return this.get('I18n').t(...args);\n },\n\n /**\n * Returns true if the editor is in absolute mode\n * @returns {Boolean}\n */\n inAbsoluteMode() {\n return this.get('dmode') === 'absolute';\n },\n\n /**\n * Destroy editor\n */\n destroyAll() {\n const { config } = this;\n const editor = this.getEditor();\n const { editors = [] } = config.grapesjs || {};\n const {\n DomComponents,\n CssComposer,\n UndoManager,\n Panels,\n Canvas,\n Keymaps,\n RichTextEditor\n } = this.attributes;\n this.stopDefault();\n DomComponents.clear();\n CssComposer.clear();\n UndoManager.clear().removeAll();\n Panels.getPanels().reset();\n Canvas.getCanvasView().remove();\n Keymaps.removeAll();\n RichTextEditor.destroy();\n this.view.remove();\n this.stopListening();\n this.clear({ silent: true });\n this.destroyed = 1;\n editors.splice(editors.indexOf(editor), 1);\n $(config.el)\n .empty()\n .attr(this.attrsOrig);\n },\n\n setEditing(value) {\n this.set('editing', value);\n return this;\n },\n\n isEditing() {\n return !!this.get('editing');\n },\n\n log(msg, opts = {}) {\n const { ns, level = 'debug' } = opts;\n this.trigger('log', msg, opts);\n level && this.trigger(`log:${level}`, msg, opts);\n\n if (ns) {\n const logNs = `log-${ns}`;\n this.trigger(logNs, msg, opts);\n level && this.trigger(`${logNs}:${level}`, msg, opts);\n }\n },\n\n logInfo(msg, opts) {\n this.log(msg, { ...opts, level: 'info' });\n },\n\n logWarning(msg, opts) {\n this.log(msg, { ...opts, level: 'warning' });\n },\n\n logError(msg, opts) {\n this.log(msg, { ...opts, level: 'error' });\n },\n\n initBaseColorPicker(el, opts = {}) {\n const config = this.getConfig();\n const { colorPicker = {} } = config;\n const elToAppend = config.el;\n const ppfx = config.stylePrefix;\n\n return $(el).spectrum({\n containerClassName: `${ppfx}one-bg ${ppfx}two-color`,\n appendTo: elToAppend || 'body',\n maxSelectionSize: 8,\n showPalette: true,\n palette: [],\n showAlpha: true,\n chooseText: 'Ok',\n cancelText: '⨯',\n ...opts,\n ...colorPicker\n });\n },\n\n /**\n * Set/get data from the HTMLElement\n * @param {HTMLElement} el\n * @param {string} name Data name\n * @param {any} value Date value\n * @return {any}\n * @private\n */\n data(el, name, value) {\n const varName = '_gjs-data';\n\n if (!el[varName]) {\n el[varName] = {};\n }\n\n if (isUndefined(value)) {\n return el[varName][name];\n } else {\n el[varName][name] = value;\n }\n }\n});\n","import { isObject, isString, each, isUndefined } from 'underscore';\n\nexport default ({ $ }) => {\n if ($ && $.prototype.constructor.name !== 'jQuery') {\n const fn = $.fn;\n\n // Additional helpers\n\n fn.hide = function() {\n return this.css('display', 'none');\n };\n\n fn.show = function() {\n return this.css('display', 'block');\n };\n\n fn.focus = function() {\n const el = this.get(0);\n el && el.focus();\n return this;\n };\n\n // For SVGs in IE\n // (fn.removeClass = function(c) {\n // if (!arguments.length) {\n // return this.attr('class', '');\n // }\n // const classes = isString(c) && c.match(/\\S+/g);\n // return classes\n // ? this.each(function(el) {\n // each(classes, function(c) {\n // if (el.classList) {\n // el.classList.remove(c);\n // } else {\n // const val = el.className;\n // const bval = el.className.baseVal;\n\n // if (!isUndefined(bval)) {\n // val.baseVal = bval.replace(c, '');\n // } else {\n // el.className = val.replace(c, '');\n // }\n // }\n // });\n // })\n // : this;\n // }),\n // (fn.remove = function() {\n // return this.each(node => {\n // return node.parentNode && node.parentNode.removeChild(node);\n // });\n // }),\n\n // For spectrum compatibility\n\n fn.bind = function(ev, h) {\n return this.on(ev, h);\n };\n\n fn.unbind = function(ev, h) {\n if (isObject(ev)) {\n for (let name in ev) {\n ev.hasOwnProperty(name) && this.off(name, ev[name]);\n }\n\n return this;\n } else {\n return this.off(ev, h);\n }\n };\n\n fn.click = function(h) {\n return h ? this.on('click', h) : this.trigger('click');\n };\n\n fn.change = function(h) {\n return h ? this.on('change', h) : this.trigger('change');\n };\n\n fn.keydown = function(h) {\n return h ? this.on('keydown', h) : this.trigger('keydown');\n };\n\n fn.delegate = function(selector, events, data, handler) {\n if (!handler) {\n handler = data;\n }\n\n return this.on(events, selector, function(e) {\n e.data = data;\n handler(e);\n });\n };\n\n fn.scrollLeft = function() {\n let el = this.get(0);\n el = el.nodeType == 9 ? el.defaultView : el;\n let win = el instanceof Window ? el : null;\n return win ? win.pageXOffset : el.scrollLeft || 0;\n };\n\n fn.scrollTop = function() {\n let el = this.get(0);\n el = el.nodeType == 9 ? el.defaultView : el;\n let win = el instanceof Window ? el : null;\n return win ? win.pageYOffset : el.scrollTop || 0;\n };\n\n const offset = $.prototype.offset;\n fn.offset = function(coords) {\n let top, left;\n\n if (coords) {\n top = coords.top;\n left = coords.left;\n }\n\n if (typeof top != 'undefined') {\n this.css('top', `${top}px`);\n }\n if (typeof left != 'undefined') {\n this.css('left', `${left}px`);\n }\n\n return offset.call(this);\n };\n\n $.map = function(items, clb) {\n const ar = [];\n\n for (var i = 0; i < items.length; i++) {\n ar.push(clb(items[i], i));\n }\n\n return ar;\n };\n\n const indexOf = Array.prototype.indexOf;\n\n $.inArray = function(val, arr, i) {\n return arr == null ? -1 : indexOf.call(arr, val, i);\n };\n\n $.Event = function(src, props) {\n if (!(this instanceof $.Event)) {\n return new $.Event(src, props);\n }\n\n this.type = src;\n this.isDefaultPrevented = () => false;\n };\n }\n};\n","import Backbone from 'backbone';\nimport { appendStyles } from 'utils/mixins';\n\nconst $ = Backbone.$;\n\nexport default Backbone.View.extend({\n initialize() {\n const { model } = this;\n model.view = this;\n this.conf = model.config;\n this.pn = model.get('Panels');\n this.cv = model.get('Canvas');\n model.on('loaded', () => {\n this.pn.active();\n this.pn.disableButtons();\n setTimeout(() => {\n model.runDefault();\n model.trigger('load', model.get('Editor'));\n });\n });\n },\n\n render() {\n const { model, $el, conf } = this;\n const pfx = conf.stylePrefix;\n const contEl = $(conf.el || `body ${conf.container}`);\n appendStyles(conf.cssIcons, { unique: 1, prepand: 1 });\n $el.empty();\n\n if (conf.width) contEl.css('width', conf.width);\n if (conf.height) contEl.css('height', conf.height);\n\n $el.append(this.cv.render());\n $el.append(this.pn.render());\n $el.attr('class', `${pfx}editor ${pfx}one-bg ${pfx}two-color`);\n contEl\n .addClass(`${pfx}editor-cont`)\n .empty()\n .append($el);\n\n return this;\n }\n});\n","/**\n * Editor contains the top level API which you'll probably use to customize the editor or extend it with plugins.\n * You get the Editor instance on init method and you can pass options via its [Configuration Object](https://github.com/artf/grapesjs/blob/master/src/editor/config/config.js)\n *\n * ```js\n * const editor = grapesjs.init({\n * // options\n * });\n * ```\n *\n * ## Available Events\n *\n * You can make use of available events in this way\n * ```js\n * editor.on('EVENT-NAME', (some, argument) => {\n * // do something\n * })\n * ```\n *\n * ### Components\n * * `component:create` - Component is created (only the model, is not yet mounted in the canvas), called after the init() method\n * * `component:mount` - Component is mounted to an element and rendered in canvas\n * * `component:add` - Triggered when a new component is added to the editor, the model is passed as an argument to the callback\n * * `component:remove` - Triggered when a component is removed, the model is passed as an argument to the callback\n * * `component:clone` - Triggered when a component is cloned, the new model is passed as an argument to the callback\n * * `component:update` - Triggered when a component is updated (moved, styled, etc.), the model is passed as an argument to the callback\n * * `component:update:{propertyName}` - Listen any property change, the model is passed as an argument to the callback\n * * `component:styleUpdate` - Triggered when the style of the component is updated, the model is passed as an argument to the callback\n * * `component:styleUpdate:{propertyName}` - Listen for a specific style property change, the model is passed as an argument to the callback\n * * `component:selected` - New component selected, the selected model is passed as an argument to the callback\n * * `component:deselected` - Component deselected, the deselected model is passed as an argument to the callback\n * * `component:toggled` - Component selection changed, toggled model is passed as an argument to the callback\n * * `component:type:add` - New component type added, the new type is passed as an argument to the callback\n * * `component:type:update` - Component type updated, the updated type is passed as an argument to the callback\n * * `component:drag:start` - Component drag started. Passed an object, to the callback, containing the `target` (component to drag), `parent` (parent of the component) and `index` (component index in the parent)\n * * `component:drag` - During component drag. Passed the same object as in `component:drag:start` event, but in this case, `parent` and `index` are updated by the current pointer\n * * `component:drag:end` - Component drag ended. Passed the same object as in `component:drag:start` event, but in this case, `parent` and `index` are updated by the final pointer\n * ### Blocks\n * * `block:add` - New block added\n * * `block:remove` - Block removed\n * * `block:drag:start` - Started dragging block, model of the block is passed as an argument\n * * `block:drag` - Dragging block, the block's model and the drag event are passed as arguments\n * * `block:drag:stop` - Dragging of the block is stopped. As agruments for the callback you get, the dropped component model (if dropped successfully) and the model of the block\n * ### Assets\n * * `asset:add` - New asset added\n * * `asset:remove` - Asset removed\n * * `asset:upload:start` - Before the upload is started\n * * `asset:upload:end` - After the upload is ended\n * * `asset:upload:error` - On any error in upload, passes the error as an argument\n * * `asset:upload:response` - On upload response, passes the result as an argument\n * ### Keymaps\n * * `keymap:add` - New keymap added. The new keyamp object is passed as an argument\n * * `keymap:remove` - Keymap removed. The removed keyamp object is passed as an argument\n * * `keymap:emit` - Some keymap emitted, in arguments you get keymapId, shortcutUsed, Event\n * * `keymap:emit:{keymapId}` - `keymapId` emitted, in arguments you get keymapId, shortcutUsed, Event\n * ### Style Manager\n * * `styleManager:update:target` - The target (Component or CSSRule) is changed\n * * `styleManager:change` - Triggered on style property change from new selected component, the view of the property is passed as an argument to the callback\n * * `styleManager:change:{propertyName}` - As above but for a specific style property\n * ### Storages\n * * `storage:start` - Before the storage request is started\n * * `storage:start:store` - Before the store request. The object to store is passed as an argumnet (which you can edit)\n * * `storage:start:load` - Before the load request. Items to load are passed as an argumnet (which you can edit)\n * * `storage:load` - Triggered when something was loaded from the storage, loaded object passed as an argumnet\n * * `storage:store` - Triggered when something is stored to the storage, stored object passed as an argumnet\n * * `storage:end` - After the storage request is ended\n * * `storage:end:store` - After the store request\n * * `storage:end:load` - After the load request\n * * `storage:error` - On any error on storage request, passes the error as an argument\n * * `storage:error:store` - Error on store request, passes the error as an argument\n * * `storage:error:load` - Error on load request, passes the error as an argument\n * ### Canvas\n * * `canvas:dragenter` - When something is dragged inside the canvas, `DataTransfer` instance passed as an argument\n * * `canvas:dragover` - When something is dragging on canvas, `DataTransfer` instance passed as an argument\n * * `canvas:drop` - Something is dropped in canvas, `DataTransfer` instance and the dropped model are passed as arguments\n * * `canvas:dragend` - When a drag operation is ended, `DataTransfer` instance passed as an argument\n * * `canvas:dragdata` - On any dataTransfer parse, `DataTransfer` instance and the `result` are passed as arguments.\n * By changing `result.content` you're able to customize what is dropped\n * ### Selectors\n * * `selector:add` - New selector is add. Passes the new selector as an argument\n * * `selector:remove` - Selector removed. Passes the removed selector as an argument\n * * `selector:update` - Selector updated. Passes the updated selector as an argument\n * * `selector:state` - State changed. Passes the new state value as an argument\n * ### RTE\n * * `rte:enable` - RTE enabled. The view, on which RTE is enabled, is passed as an argument\n * * `rte:disable` - RTE disabled. The view, on which RTE is disabled, is passed as an argument\n * ### Modal\n * * `modal:open` - Modal is opened\n * * `modal:close` - Modal is closed\n * ### Commands\n * * `run:{commandName}` - Triggered when some command is called to run (eg. editor.runCommand('preview'))\n * * `stop:{commandName}` - Triggered when some command is called to stop (eg. editor.stopCommand('preview'))\n * * `run:{commandName}:before` - Triggered before the command is called\n * * `stop:{commandName}:before` - Triggered before the command is called to stop\n * * `abort:{commandName}` - Triggered when the command execution is aborted (`editor.on(`run:preview:before`, opts => opts.abort = 1);`)\n * * `run` - Triggered on run of any command. The id and the result are passed as arguments to the callback\n * * `stop` - Triggered on stop of any command. The id and the result are passed as arguments to the callback\n * ### General\n * * `canvasScroll` - Canvas is scrolled\n * * `update` - The structure of the template is updated (its HTML/CSS)\n * * `undo` - Undo executed\n * * `redo` - Redo executed\n * * `load` - Editor is loaded\n *\n * @module Editor\n */\nimport $ from 'cash-dom';\nimport defaults from './config/config';\nimport EditorModel from './model/Editor';\nimport EditorView from './view/EditorView';\n\nexport default (config = {}) => {\n const c = {\n ...defaults,\n ...config\n };\n\n c.pStylePrefix = c.stylePrefix;\n var em = new EditorModel(c);\n var editorView = new EditorView({\n model: em,\n config: c\n });\n\n return {\n $,\n\n /**\n * @property {EditorModel}\n * @private\n */\n editor: em,\n\n /**\n * Initialize editor model\n * @return {this}\n * @private\n */\n init(opts = {}) {\n em.init(this, { ...c, ...opts });\n\n [\n 'I18n',\n 'Utils',\n 'Config',\n 'Commands',\n 'Keymaps',\n 'Modal',\n 'Panels',\n 'Canvas',\n 'Parser',\n 'CodeManager',\n 'UndoManager',\n 'RichTextEditor',\n 'DomComponents',\n ['Components', 'DomComponents'],\n 'LayerManager',\n ['Layers', 'LayerManager'],\n 'CssComposer',\n ['Css', 'CssComposer'],\n 'StorageManager',\n ['Storage', 'StorageManager'],\n 'AssetManager',\n ['Assets', 'AssetManager'],\n 'BlockManager',\n ['Blocks', 'BlockManager'],\n 'TraitManager',\n ['Traits', 'TraitManager'],\n 'SelectorManager',\n ['Selectors', 'SelectorManager'],\n 'StyleManager',\n ['Styles', 'StyleManager'],\n 'DeviceManager',\n ['Devices', 'DeviceManager']\n ].forEach(prop => {\n if (Array.isArray(prop)) {\n this[prop[0]] = em.get(prop[1]);\n } else {\n this[prop] = em.get(prop);\n }\n });\n\n // Do post render stuff after the iframe is loaded otherwise it'll\n // be empty during tests\n em.on('loaded', () => {\n this.UndoManager.clear();\n em.get('modules').forEach(module => {\n module.postRender && module.postRender(editorView);\n });\n });\n\n return this;\n },\n\n /**\n * Returns configuration object\n * @param {string} [prop] Property name\n * @return {any} Returns the configuration object or\n * the value of the specified property\n */\n getConfig(prop) {\n return em.getConfig(prop);\n },\n\n /**\n * Returns HTML built inside canvas\n * @return {string} HTML string\n */\n getHtml(opts) {\n return em.getHtml(opts);\n },\n\n /**\n * Returns CSS built inside canvas\n * @param {Object} [opts={}] Options\n * @param {Boolean} [opts.avoidProtected=false] Don't include protected CSS\n * @return {string} CSS string\n */\n getCss(opts) {\n return em.getCss(opts);\n },\n\n /**\n * Returns JS of all components\n * @return {string} JS string\n */\n getJs() {\n return em.getJs();\n },\n\n /**\n * Return the complete tree of components. Use `getWrapper` to include also the wrapper\n * @return {Components}\n */\n getComponents() {\n return em.get('DomComponents').getComponents();\n },\n\n /**\n * Return the wrapper and its all components\n * @return {Component}\n */\n getWrapper() {\n return em.get('DomComponents').getWrapper();\n },\n\n /**\n * Set components inside editor's canvas. This method overrides actual components\n * @param {Array