Browse Source

eslint fix

pull/4313/head
Artur Arseniev 4 years ago
parent
commit
28937a2af7
  1. 32
      src/abstract/Module.ts
  2. 8
      src/abstract/index.ts
  3. 32
      src/canvas/model/Canvas.ts
  4. 80
      src/canvas/model/Frame.ts
  5. 18
      src/canvas/model/Frames.ts
  6. 32
      src/editor/index.ts
  7. 262
      src/editor/model/Editor.ts
  8. 44
      src/pages/index.ts
  9. 22
      src/pages/model/Page.ts
  10. 8
      src/pages/model/Pages.ts

32
src/abstract/Module.ts

@ -1,7 +1,7 @@
import { isElement, isUndefined } from "underscore";
import { Collection } from "../common";
import EditorModel from "../editor/model/Editor";
import { createId, isDef } from "../utils/mixins";
import { isElement, isUndefined } from 'underscore';
import { Collection } from '../common';
import EditorModel from '../editor/model/Editor';
import { createId, isDef } from '../utils/mixins';
export interface IModule<TConfig extends any = any>
extends IBaseModule<TConfig> {
@ -48,7 +48,7 @@ export default abstract class Module<T extends ModuleConfig = ModuleConfig>
? em.config[name]
: em.config[this.name];
const cfg = cfgParent === true ? {} : cfgParent || {};
cfg.pStylePrefix = em.config.pStylePrefix || "";
cfg.pStylePrefix = em.config.pStylePrefix || '';
if (!isUndefined(cfgParent) && !cfgParent) {
cfg._disable = 1;
@ -120,15 +120,15 @@ export abstract class ItemManagerModule<
) {
const { all, onResult, reset } = param;
const key = this.storageKey;
const opts: any = { action: "load" };
const opts: any = { action: 'load' };
const coll = all || this.all;
let result = data[key];
if (typeof result == "string") {
if (typeof result == 'string') {
try {
result = JSON.parse(result);
} catch (err) {
this.__logWarn("Data parsing failed", { input: result });
this.__logWarn('Data parsing failed', { input: result });
}
}
@ -167,19 +167,19 @@ export abstract class ItemManagerModule<
all &&
em &&
all
.on("add", (m: any, c: any, o: any) => em.trigger(events.add, m, o))
.on("remove", (m: any, c: any, o: any) =>
.on('add', (m: any, c: any, o: any) => em.trigger(events.add, m, o))
.on('remove', (m: any, c: any, o: any) =>
em.trigger(events.remove, m, o)
)
.on("change", (p: any, c: any) =>
.on('change', (p: any, c: any) =>
em.trigger(events.update, p, p.changedAttributes(), c)
)
.on("all", this.__catchAllEvent, this);
.on('all', this.__catchAllEvent, this);
// Register collections
this.cls = [all].concat(opts.collections || []);
// Propagate events
((opts.propagate as any[]) || []).forEach(({ entity, event }) => {
entity.on("all", (ev: any, model: any, coll: any, opts: any) => {
entity.on('all', (ev: any, model: any, coll: any, opts: any) => {
const options = opts || coll;
const opt = { event: ev, ...options };
[em, all].map((md) => md.trigger(event, model, opt));
@ -233,15 +233,15 @@ export abstract class ItemManagerModule<
}
__listenAdd(model: TCollection, event: string) {
model.on("add", (m, c, o) => this.em.trigger(event, m, o));
model.on('add', (m, c, o) => this.em.trigger(event, m, o));
}
__listenRemove(model: TCollection, event: string) {
model.on("remove", (m, c, o) => this.em.trigger(event, m, o));
model.on('remove', (m, c, o) => this.em.trigger(event, m, o));
}
__listenUpdate(model: TCollection, event: string) {
model.on("change", (p, c) =>
model.on('change', (p, c) =>
this.em.trigger(event, p, p.changedAttributes(), c)
);
}

8
src/abstract/index.ts

@ -1,4 +1,4 @@
export { default as Model } from "./Model";
export { default as Collection } from "./Collection";
export { default as View } from "./View";
export { default as Module } from "./Module";
export { default as Model } from './Model';
export { default as Collection } from './Collection';
export { default as View } from './View';
export { default as Module } from './Module';

32
src/canvas/model/Canvas.ts

@ -1,14 +1,14 @@
import { Model } from "../../common";
import Backbone from "backbone";
import { evPageSelect } from "../../pages";
import Frames from "./Frames";
import EditorModel from "../../editor/model/Editor";
import Page from "../../pages/model/Page";
import { Model } from '../../common';
import Backbone from 'backbone';
import { evPageSelect } from '../../pages';
import Frames from './Frames';
import EditorModel from '../../editor/model/Editor';
import Page from '../../pages/model/Page';
export default class Canvas extends Backbone.Model {
defaults() {
return {
frame: "",
frame: '',
frames: new Frames(),
rulers: false,
zoom: 100,
@ -28,29 +28,29 @@ export default class Canvas extends Backbone.Model {
const { em } = config;
this.config = config;
this.em = em;
this.listenTo(this, "change:zoom", this.onZoomChange);
this.listenTo(em, "change:device", this.updateDevice);
this.listenTo(this, 'change:zoom', this.onZoomChange);
this.listenTo(em, 'change:device', this.updateDevice);
this.listenTo(em, evPageSelect, this._pageUpdated);
}
get frames(): Frames {
return this.get("frames");
return this.get('frames');
}
init() {
const { em } = this;
const mainPage = em.get("PageManager").getMain();
const mainPage = em.get('PageManager').getMain();
const frame = mainPage.getMainFrame();
this.set("frames", mainPage.getFrames());
this.set('frames', mainPage.getFrames());
this.updateDevice({ frame });
}
_pageUpdated(page: Page, prev?: Page) {
const { em } = this;
em.setSelected();
em.get("readyCanvas") && em.stopDefault(); // We have to stop before changing current frames
em.get('readyCanvas') && em.stopDefault(); // We have to stop before changing current frames
//@ts-ignore
prev?.getFrames().map((frame) => frame.disable());
this.set("frames", page.getFrames());
this.set('frames', page.getFrames());
}
updateDevice(opts: any = {}) {
@ -65,7 +65,7 @@ export default class Canvas extends Backbone.Model {
}
onZoomChange() {
const zoom = this.get("zoom");
zoom < 1 && this.set("zoom", 1);
const zoom = this.get('zoom');
zoom < 1 && this.set('zoom', 1);
}
}

80
src/canvas/model/Frame.ts

@ -1,15 +1,15 @@
import { result, forEach, isEmpty, isString } from "underscore";
import { Model } from "../../common";
import { Component } from "../../dom_components/model/Component";
import Components from "../../dom_components/model/Components";
import ComponentWrapper from "../../dom_components/model/ComponentWrapper";
import EditorModel from "../../editor/model/Editor";
import { isComponent, isObject } from "../../utils/mixins";
import FrameView from "../view/FrameView";
import Frames from "./Frames";
const keyAutoW = "__aw";
const keyAutoH = "__ah";
import { result, forEach, isEmpty, isString } from 'underscore';
import { Model } from '../../common';
import { Component } from '../../dom_components/model/Component';
import Components from '../../dom_components/model/Components';
import ComponentWrapper from '../../dom_components/model/ComponentWrapper';
import EditorModel from '../../editor/model/Editor';
import { isComponent, isObject } from '../../utils/mixins';
import FrameView from '../view/FrameView';
import Frames from './Frames';
const keyAutoW = '__aw';
const keyAutoH = '__ah';
/**
* @property {Object|String} component Wrapper component definition. You can also pass an HTML string as components of the default wrapper component.
@ -29,10 +29,10 @@ export default class Frame extends Model {
width: null,
height: null,
head: [],
component: "",
styles: "",
component: '',
styles: '',
_undo: true,
_undoexc: ["changesCount"],
_undoexc: ['changesCount'],
};
}
em: EditorModel;
@ -42,22 +42,22 @@ export default class Frame extends Model {
super(props);
const { em } = opts;
const { styles, component } = this.attributes;
const domc = em.get("DomComponents");
const domc = em.get('DomComponents');
const conf = domc.getConfig();
const allRules = em.get("CssComposer").getAll();
const allRules = em.get('CssComposer').getAll();
const idMap: any = {};
this.em = em;
const modOpts = { em, config: conf, frame: this, idMap };
if (!isComponent(component)) {
const wrp = isObject(component) ? component : { components: component };
!wrp.type && (wrp.type = "wrapper");
const Wrapper = domc.getType("wrapper").model;
this.set("component", new Wrapper(wrp, modOpts));
!wrp.type && (wrp.type = 'wrapper');
const Wrapper = domc.getType('wrapper').model;
this.set('component', new Wrapper(wrp, modOpts));
}
if (!styles) {
this.set("styles", allRules);
this.set('styles', allRules);
} else if (!isObject(styles)) {
// Avoid losing styles on remapped components
const idMapKeys = Object.keys(idMap);
@ -69,7 +69,7 @@ export default class Frame extends Model {
const idSel = sSel.name && sSel.type === 2 && sSel;
if (idSel && idMap[idSel.name]) {
idSel.name = idMap[idSel.name];
} else if (isString(sSel) && sSel[0] === "#") {
} else if (isString(sSel) && sSel[0] === '#') {
const prevId = sSel.substring(1);
if (prevId && idMap[prevId]) {
sel[0] = `#${idMap[prevId]}`;
@ -80,7 +80,7 @@ export default class Frame extends Model {
}
allRules.add(styles);
this.set("styles", allRules);
this.set('styles', allRules);
}
!props.width && this.set(keyAutoW, 1);
@ -95,19 +95,19 @@ export default class Frame extends Model {
if (opt.temporary || opt.noCount || opt.avoidStore) {
return;
}
this.set("changesCount", this.get("changesCount") + 1);
this.set('changesCount', this.get('changesCount') + 1);
}
getComponent(): ComponentWrapper {
return this.get("component");
return this.get('component');
}
getStyles() {
return this.get("styles");
return this.get('styles');
}
disable() {
this.trigger("disable");
this.trigger('disable');
}
remove() {
@ -117,12 +117,12 @@ export default class Frame extends Model {
}
getHead() {
const head = this.get("head") || [];
const head = this.get('head') || [];
return [...head];
}
setHead(value: any) {
return this.set("head", [...value]);
return this.set('head', [...value]);
}
addHeadItem(item: any) {
@ -153,24 +153,24 @@ export default class Frame extends Model {
}
addLink(href: string) {
const tag = "link";
!this.getHeadByAttr("href", href, tag) &&
const tag = 'link';
!this.getHeadByAttr('href', href, tag) &&
this.addHeadItem({
tag,
attributes: {
href,
rel: "stylesheet",
rel: 'stylesheet',
},
});
}
removeLink(href: string) {
this.removeHeadByAttr("href", href, "link");
this.removeHeadByAttr('href', href, 'link');
}
addScript(src: string) {
const tag = "script";
!this.getHeadByAttr("src", src, tag) &&
const tag = 'script';
!this.getHeadByAttr('src', src, tag) &&
this.addHeadItem({
tag,
attributes: { src },
@ -178,7 +178,7 @@ export default class Frame extends Model {
}
removeScript(src: string) {
this.removeHeadByAttr("src", src, "script");
this.removeHeadByAttr('src', src, 'script');
}
getPage() {
@ -186,12 +186,12 @@ export default class Frame extends Model {
}
_emitUpdated(data = {}) {
this.em.trigger("frame:updated", { frame: this, ...data });
this.em.trigger('frame:updated', { frame: this, ...data });
}
toJSON(opts: any = {}) {
const obj = Model.prototype.toJSON.call(this, opts);
const defaults = result(this, "defaults");
const defaults = result(this, 'defaults');
if (opts.fromUndo) delete obj.component;
delete obj.styles;
@ -201,14 +201,14 @@ export default class Frame extends Model {
// Remove private keys
forEach(obj, (value, key) => {
key.indexOf("_") === 0 && delete obj[key];
key.indexOf('_') === 0 && delete obj[key];
});
forEach(defaults, (value, key) => {
if (obj[key] === value) delete obj[key];
});
forEach(["attributes", "head"], (prop) => {
forEach(['attributes', 'head'], (prop) => {
if (isEmpty(obj[prop])) delete obj[prop];
});

18
src/canvas/model/Frames.ts

@ -1,7 +1,7 @@
import { bindAll } from "underscore";
import { Collection } from "../../common";
import Page from "../../pages/model/Page";
import Frame from "./Frame";
import { bindAll } from 'underscore';
import { Collection } from '../../common';
import Page from '../../pages/model/Page';
import Frame from './Frame';
export default class Frames extends Collection<Frame> {
loadedItems = 0;
@ -10,9 +10,9 @@ export default class Frames extends Collection<Frame> {
constructor(models?: Frame[]) {
super(models);
bindAll(this, "itemLoaded");
this.on("reset", this.onReset);
this.on("remove", this.onRemove);
bindAll(this, 'itemLoaded');
this.on('reset', this.onReset);
this.on('remove', this.onRemove);
}
onReset(m: Frame, opts?: { previousModels?: Frame[] }) {
@ -28,7 +28,7 @@ export default class Frames extends Collection<Frame> {
this.loadedItems++;
if (this.loadedItems >= this.itemsToLoad) {
this.trigger("loaded:all");
this.trigger('loaded:all');
this.listenToLoadItems(false);
}
}
@ -40,6 +40,6 @@ export default class Frames extends Collection<Frame> {
}
listenToLoadItems(on: boolean) {
this.forEach((item) => item[on ? "on" : "off"]("loaded", this.itemLoaded));
this.forEach((item) => item[on ? 'on' : 'off']('loaded', this.itemLoaded));
}
}

32
src/editor/index.ts

@ -54,14 +54,14 @@
* ## Methods
* @module Editor
*/
import { EventHandler } from "backbone";
import { isUndefined } from "underscore";
import { IBaseModule } from "../abstract/Module";
import cash from "../utils/cash-dom";
import html from "../utils/html";
import defaults from "./config/config";
import EditorModel from "./model/Editor";
import EditorView from "./view/EditorView";
import { EventHandler } from 'backbone';
import { isUndefined } from 'underscore';
import { IBaseModule } from '../abstract/Module';
import cash from '../utils/cash-dom';
import html from '../utils/html';
import defaults from './config/config';
import EditorModel from './model/Editor';
import EditorView from './view/EditorView';
export default class EditorModule implements IBaseModule<typeof defaults> {
constructor(config = {}, opts: any = {}) {
@ -264,7 +264,7 @@ export default class EditorModule implements IBaseModule<typeof defaults> {
* @return {Components}
*/
getComponents() {
return this.em.get("DomComponents").getComponents();
return this.em.get('DomComponents').getComponents();
}
/**
@ -272,7 +272,7 @@ export default class EditorModule implements IBaseModule<typeof defaults> {
* @return {Component}
*/
getWrapper() {
return this.em.get("DomComponents").getWrapper();
return this.em.get('DomComponents').getWrapper();
}
/**
@ -320,7 +320,7 @@ export default class EditorModule implements IBaseModule<typeof defaults> {
* @return {Object}
*/
getStyle() {
return this.em.get("CssComposer").getAll();
return this.em.get('CssComposer').getAll();
}
/**
@ -458,7 +458,7 @@ export default class EditorModule implements IBaseModule<typeof defaults> {
* editor.setDevice('Tablet');
*/
setDevice(name: string) {
this.em.set("device", name);
this.em.set('device', name);
return this;
}
@ -471,7 +471,7 @@ export default class EditorModule implements IBaseModule<typeof defaults> {
* // 'Tablet'
*/
getDevice() {
return this.em.get("device");
return this.em.get('device');
}
/**
@ -483,7 +483,7 @@ export default class EditorModule implements IBaseModule<typeof defaults> {
* editor.runCommand('myCommand', {someValue: 1});
*/
runCommand(id: string, options = {}) {
return this.em.get("Commands").run(id, options);
return this.em.get('Commands').run(id, options);
}
/**
@ -495,7 +495,7 @@ export default class EditorModule implements IBaseModule<typeof defaults> {
* editor.stopCommand('myCommand', {someValue: 1});
*/
stopCommand(id: string, options = {}) {
return this.em.get("Commands").stop(id, options);
return this.em.get('Commands').stop(id, options);
}
/**
@ -784,7 +784,7 @@ export default class EditorModule implements IBaseModule<typeof defaults> {
* });
*/
onReady(clb: EventHandler) {
this.em.get("ready") ? clb(this) : this.em.on("load", clb);
this.em.get('ready') ? clb(this) : this.em.on('load', clb);
}
/**

262
src/editor/model/Editor.ts

@ -5,44 +5,44 @@ import {
toArray,
keys,
bindAll,
} from "underscore";
import Backbone from "backbone";
import $ from "../../utils/cash-dom";
import Extender from "../../utils/extender";
import { getModel, hasWin, isEmptyObj } from "../../utils/mixins";
import { Model } from "../../common";
import Selected from "./Selected";
import FrameView from "../../canvas/view/FrameView";
import EditorModule from "..";
import EditorView from "../view/EditorView";
import { IModule } from "../../abstract/Module";
} from 'underscore';
import Backbone from 'backbone';
import $ from '../../utils/cash-dom';
import Extender from '../../utils/extender';
import { getModel, hasWin, isEmptyObj } from '../../utils/mixins';
import { Model } from '../../common';
import Selected from './Selected';
import FrameView from '../../canvas/view/FrameView';
import EditorModule from '..';
import EditorView from '../view/EditorView';
import { IModule } from '../../abstract/Module';
//@ts-ignore
Backbone.$ = $;
const deps = [
require("utils"),
require("i18n"),
require("keymaps"),
require("undo_manager"),
require("storage_manager"),
require("device_manager"),
require("parser"),
require("style_manager"),
require("selector_manager"),
require("modal_dialog"),
require("code_manager"),
require("panels"),
require("rich_text_editor"),
require("asset_manager"),
require("css_composer"),
require("pages"),
require("trait_manager"),
require("dom_components"),
require("navigator"),
require("canvas"),
require("commands"),
require("block_manager"),
require('utils'),
require('i18n'),
require('keymaps'),
require('undo_manager'),
require('storage_manager'),
require('device_manager'),
require('parser'),
require('style_manager'),
require('selector_manager'),
require('modal_dialog'),
require('code_manager'),
require('panels'),
require('rich_text_editor'),
require('asset_manager'),
require('css_composer'),
require('pages'),
require('trait_manager'),
require('dom_components'),
require('navigator'),
require('canvas'),
require('commands'),
require('block_manager'),
];
const ts_deps: any[] = [];
@ -74,7 +74,7 @@ export default class EditorModel extends Model {
modules: [],
toLoad: [],
opened: {},
device: "",
device: '',
};
}
@ -106,15 +106,15 @@ export default class EditorModel extends Model {
super();
this._config = conf;
const { config } = this;
this.set("Config", conf);
this.set("modules", []);
this.set("toLoad", []);
this.set("storables", []);
this.set("selected", new Selected());
this.set("dmode", config.dragMode);
this.set('Config', conf);
this.set('modules', []);
this.set('toLoad', []);
this.set('storables', []);
this.set('selected', new Selected());
this.set('dmode', config.dragMode);
const { el, log } = config;
const toLog = log === true ? keys(logs) : isArray(log) ? log : [];
bindAll(this, "initBaseColorPicker");
bindAll(this, 'initBaseColorPicker');
if (el && config.fromElement) {
config.components = el.innerHTML;
@ -125,7 +125,7 @@ export default class EditorModel extends Model {
res[next.nodeName] = next.nodeValue;
return res;
}, {})
: "";
: '';
// Move components to pages
if (config.components && !config.pageManager) {
@ -135,13 +135,13 @@ export default class EditorModel extends Model {
// Load modules
deps.forEach((name) => this.loadModule(name));
ts_deps.forEach((name) => this.tsLoadModule(name));
this.on("change:componentHovered", this.componentHovered, this);
this.on("change:changesCount", this.updateChanges, this);
this.on("change:readyLoad change:readyCanvas", this._checkReady, this);
this.on('change:componentHovered', this.componentHovered, this);
this.on('change:changesCount', this.updateChanges, this);
this.on('change:readyLoad change:readyCanvas', this._checkReady, this);
toLog.forEach((e) => this.listenLog(e));
// Deprecations
[{ from: "change:selectedComponent", to: "component:toggled" }].forEach(
[{ from: 'change:selectedComponent', to: 'component:toggled' }].forEach(
(event) => {
const eventFrom = event.from;
const eventTo = event.to;
@ -157,11 +157,11 @@ export default class EditorModel extends Model {
_checkReady() {
if (
this.get("readyLoad") &&
this.get("readyCanvas") &&
!this.get("ready")
this.get('readyLoad') &&
this.get('readyCanvas') &&
!this.get('ready')
) {
this.set("ready", true);
this.set('ready', true);
}
}
@ -195,7 +195,7 @@ export default class EditorModel extends Model {
*/
loadOnStart() {
const { projectData, headless } = this.config;
const sm = this.get("StorageManager");
const sm = this.get('StorageManager');
// In `onLoad`, the module will try to load the data from its configurations.
this.toLoad.forEach((mdl) => mdl.onLoad());
@ -203,7 +203,7 @@ export default class EditorModel extends Model {
// Stuff to do post load
const postLoad = () => {
this.modules.forEach((mdl) => mdl.postLoad && mdl.postLoad(this));
this.set("readyLoad", 1);
this.set('readyLoad', 1);
};
if (headless) {
@ -233,8 +233,8 @@ export default class EditorModel extends Model {
undoManager: false,
});
// We only need to load a few modules
["PageManager", "Canvas"].forEach((key) => shallow.get(key).onLoad());
this.set("shallow", shallow);
['PageManager', 'Canvas'].forEach((key) => shallow.get(key).onLoad());
this.set('shallow', shallow);
}
/**
@ -243,11 +243,11 @@ export default class EditorModel extends Model {
* @private
*/
updateChanges() {
const stm = this.get("StorageManager");
const stm = this.get('StorageManager');
const changes = this.getDirtyCount();
this.updateItr && clearTimeout(this.updateItr);
//@ts-ignore
this.updateItr = setTimeout(() => this.trigger("update"));
this.updateItr = setTimeout(() => this.trigger('update'));
if (this.config.noticeOnUnload) {
window.onbeforeunload = changes ? () => true : null;
@ -273,7 +273,7 @@ export default class EditorModel extends Model {
? config[name]
: config[Mod.name];
const cfg = cfgParent === true ? {} : cfgParent || {};
cfg.pStylePrefix = config.pStylePrefix || "";
cfg.pStylePrefix = config.pStylePrefix || '';
if (!isUndefined(cfgParent) && !cfgParent) {
cfg._disable = 1;
@ -324,11 +324,11 @@ export default class EditorModel extends Model {
this.initialize(opts);
this.destroyed = false;
}
this.set("Editor", editor);
this.set('Editor', editor);
}
getEditor() {
return this.get("Editor");
return this.get('Editor');
}
/**
@ -346,7 +346,7 @@ export default class EditorModel extends Model {
opt.temporary ||
opt.noCount ||
opt.avoidStore ||
!this.get("ready")
!this.get('ready')
) {
return;
}
@ -356,7 +356,7 @@ export default class EditorModel extends Model {
this.timedInterval = setTimeout(() => {
const curr = this.getDirtyCount() || 0;
const { unset, ...opts } = opt;
this.set("changesCount", curr + 1, opts);
this.set('changesCount', curr + 1, opts);
}, 0);
}
@ -372,9 +372,9 @@ export default class EditorModel extends Model {
* @private
* */
componentHovered(editor: any, component: any, options: any) {
const prev = this.previous("componentHovered");
prev && this.trigger("component:unhovered", prev, options);
component && this.trigger("component:hovered", component, options);
const prev = this.previous('componentHovered');
prev && this.trigger('component:unhovered', prev, options);
component && this.trigger('component:hovered', component, options);
}
/**
@ -419,13 +419,13 @@ export default class EditorModel extends Model {
let model = getModel(el, undefined);
if (model) {
this.trigger("component:select:before", model, opts);
this.trigger('component:select:before', model, opts);
// Check for valid selectable
if (!model.get("selectable") || opts.abort) {
if (!model.get('selectable') || opts.abort) {
if (opts.useValid) {
let parent = model.parent();
while (parent && !parent.get("selectable"))
while (parent && !parent.get('selectable'))
parent = parent.parent();
model = parent;
} else {
@ -438,7 +438,7 @@ export default class EditorModel extends Model {
if (ctrlKey && mltSel) {
return this.toggleSelected(model);
} else if (shiftKey && mltSel) {
this.clearSelection(this.get("Canvas").getWindow());
this.clearSelection(this.get('Canvas').getWindow());
const coll = model.collection;
const index = model.index();
let min: number | undefined, max: number | undefined;
@ -496,7 +496,7 @@ export default class EditorModel extends Model {
const { selected } = this;
opts.forceChange && this.removeSelected(model, opts);
selected.addComponent(model, opts);
model && this.trigger("component:select", model, opts);
model && this.trigger('component:select', model, opts);
});
}
@ -536,21 +536,21 @@ export default class EditorModel extends Model {
* @private
*/
setHovered(el: any, opts: any = {}) {
if (!el) return this.set("componentHovered", "");
if (!el) return this.set('componentHovered', '');
const ev = "component:hover";
const ev = 'component:hover';
let model = getModel(el, undefined);
if (!model) return;
opts.forceChange && this.set("componentHovered", "");
opts.forceChange && this.set('componentHovered', '');
this.trigger(`${ev}:before`, model, opts);
// Check for valid hoverable
if (!model.get("hoverable")) {
if (!model.get('hoverable')) {
if (opts.useValid && !opts.abort) {
let parent = model && model.parent();
while (parent && !parent.get("hoverable")) parent = parent.parent();
while (parent && !parent.get('hoverable')) parent = parent.parent();
model = parent;
} else {
return;
@ -558,13 +558,13 @@ export default class EditorModel extends Model {
}
if (!opts.abort) {
this.set("componentHovered", model, opts);
this.set('componentHovered', model, opts);
this.trigger(ev, model, opts);
}
}
getHovered() {
return this.get("componentHovered");
return this.get('componentHovered');
}
/**
@ -575,7 +575,7 @@ export default class EditorModel extends Model {
* @public
*/
setComponents(components: any, opt = {}) {
return this.get("DomComponents").setComponents(components, opt);
return this.get('DomComponents').setComponents(components, opt);
}
/**
@ -584,13 +584,13 @@ export default class EditorModel extends Model {
* @private
*/
getComponents() {
var cmp = this.get("DomComponents");
var cm = this.get("CodeManager");
var cmp = this.get('DomComponents');
var cm = this.get('CodeManager');
if (!cmp || !cm) return;
var wrp = cmp.getComponents();
return cm.getCode(wrp, "json");
return cm.getCode(wrp, 'json');
}
/**
@ -601,7 +601,7 @@ export default class EditorModel extends Model {
* @public
*/
setStyle(style: any, opt = {}) {
const cssc = this.get("CssComposer");
const cssc = this.get('CssComposer');
cssc.clear(opt);
cssc.getAll().add(style, opt);
return this;
@ -624,7 +624,7 @@ export default class EditorModel extends Model {
* @private
*/
getStyle() {
return this.get("CssComposer").getAll();
return this.get('CssComposer').getAll();
}
/**
@ -633,7 +633,7 @@ export default class EditorModel extends Model {
* @returns {this}
*/
setState(value: string) {
this.set("state", value);
this.set('state', value);
return this;
}
@ -642,7 +642,7 @@ export default class EditorModel extends Model {
* @returns {String}
*/
getState() {
return this.get("state") || "";
return this.get('state') || '';
}
/**
@ -654,15 +654,15 @@ export default class EditorModel extends Model {
getHtml(opts: any = {}) {
const { config } = this;
const { optsHtml } = config;
const js = config.jsInHtml ? this.getJs(opts) : "";
const cmp = opts.component || this.get("DomComponents").getComponent();
const js = config.jsInHtml ? this.getJs(opts) : '';
const cmp = opts.component || this.get('DomComponents').getComponent();
let html = cmp
? this.get("CodeManager").getCode(cmp, "html", {
? this.get('CodeManager').getCode(cmp, 'html', {
...optsHtml,
...opts,
})
: "";
html += js ? `<script>${js}</script>` : "";
: '';
html += js ? `<script>${js}</script>` : '';
return html;
}
@ -679,18 +679,18 @@ export default class EditorModel extends Model {
const keepUnusedStyles = !isUndefined(opts.keepUnusedStyles)
? opts.keepUnusedStyles
: config.keepUnusedStyles;
const cssc = this.get("CssComposer");
const wrp = opts.component || this.get("DomComponents").getComponent();
const protCss = !avoidProt ? config.protectedCss : "";
const cssc = this.get('CssComposer');
const wrp = opts.component || this.get('DomComponents').getComponent();
const protCss = !avoidProt ? config.protectedCss : '';
const css =
wrp &&
this.get("CodeManager").getCode(wrp, "css", {
this.get('CodeManager').getCode(wrp, 'css', {
cssc,
keepUnusedStyles,
...optsCss,
...opts,
});
return wrp ? (opts.json ? css : protCss + css) : "";
return wrp ? (opts.json ? css : protCss + css) : '';
}
/**
@ -699,8 +699,8 @@ export default class EditorModel extends Model {
* @public
*/
getJs(opts: any = {}) {
var wrp = opts.component || this.get("DomComponents").getWrapper();
return wrp ? this.get("CodeManager").getCode(wrp, "js").trim() : "";
var wrp = opts.component || this.get('DomComponents').getWrapper();
return wrp ? this.get('CodeManager').getCode(wrp, 'js').trim() : '';
}
/**
@ -709,7 +709,7 @@ export default class EditorModel extends Model {
*/
async store(options?: any) {
const data = this.storeData();
await this.get("StorageManager").store(data, options);
await this.get('StorageManager').store(data, options);
this.clearDirtyCount();
return data;
}
@ -719,7 +719,7 @@ export default class EditorModel extends Model {
* @public
*/
async load(options?: any) {
const result = await this.get("StorageManager").load(options);
const result = await this.get('StorageManager').load(options);
this.loadData(result);
return result;
}
@ -728,7 +728,7 @@ export default class EditorModel extends Model {
let result = {};
// Sync content if there is an active RTE
const editingCmp = this.getEditing();
editingCmp && editingCmp.trigger("sync:content", { noCount: true });
editingCmp && editingCmp.trigger('sync:content', { noCount: true });
this.storables.forEach((m) => {
result = { ...result, ...m.store(1) };
@ -750,8 +750,8 @@ export default class EditorModel extends Model {
* @private
*/
getDeviceModel() {
var name = this.get("device");
return this.get("DeviceManager").get(name);
var name = this.get('device');
return this.get('DeviceManager').get(name);
}
/**
@ -760,7 +760,7 @@ export default class EditorModel extends Model {
* @private
*/
runDefault(opts = {}) {
var command = this.get("Commands").get(this.config.defaultCommand);
var command = this.get('Commands').get(this.config.defaultCommand);
if (!command || this.defaultRunning) return;
command.stop(this, this, opts);
command.run(this, this, opts);
@ -773,7 +773,7 @@ export default class EditorModel extends Model {
* @private
*/
stopDefault(opts = {}) {
const commands = this.get("Commands");
const commands = this.get('Commands');
const command = commands.get(this.config.defaultCommand);
if (!command || !this.defaultRunning) return;
command.stop(this, this, opts);
@ -785,9 +785,9 @@ export default class EditorModel extends Model {
* @public
*/
refreshCanvas(opts: any = {}) {
this.set("canvasOffset", null);
this.set("canvasOffset", this.get("Canvas").getOffset());
opts.tools && this.trigger("canvas:updateTools");
this.set('canvasOffset', null);
this.set('canvasOffset', this.get('Canvas').getOffset());
opts.tools && this.trigger('canvas:updateTools');
}
/**
@ -810,8 +810,8 @@ export default class EditorModel extends Model {
const device = this.getDeviceModel();
const condition = config.mediaCondition;
const preview = config.devicePreviewMode;
const width = device && device.get("widthMedia");
return device && width && !preview ? `(${condition}: ${width})` : "";
const width = device && device.get('widthMedia');
return device && width && !preview ? `(${condition}: ${width})` : '';
}
/**
@ -819,15 +819,15 @@ export default class EditorModel extends Model {
* @return {Component}
*/
getWrapper() {
return this.get("DomComponents").getWrapper();
return this.get('DomComponents').getWrapper();
}
setCurrentFrame(frameView: FrameView) {
return this.set("currentFrame", frameView);
return this.set('currentFrame', frameView);
}
getCurrentFrame(): FrameView {
return this.get("currentFrame");
return this.get('currentFrame');
}
getCurrentFrameModel() {
@ -836,7 +836,7 @@ export default class EditorModel extends Model {
getIcon(icon: string) {
const icons = this.config.icons || {};
return icons[icon] || "";
return icons[icon] || '';
}
/**
@ -849,23 +849,23 @@ export default class EditorModel extends Model {
}
clearDirtyCount() {
return this.set("changesCount", 0);
return this.set('changesCount', 0);
}
getZoomDecimal() {
return this.get("Canvas").getZoomDecimal();
return this.get('Canvas').getZoomDecimal();
}
getZoomMultiplier() {
return this.get("Canvas").getZoomMultiplier();
return this.get('Canvas').getZoomMultiplier();
}
setDragMode(value: string) {
return this.set("dmode", value);
return this.set('dmode', value);
}
t(...args: any[]) {
const i18n = this.get("I18n");
const i18n = this.get('I18n');
return i18n?.t(...args);
}
@ -874,7 +874,7 @@ export default class EditorModel extends Model {
* @returns {Boolean}
*/
inAbsoluteMode() {
return this.get("dmode") === "absolute";
return this.get('dmode') === 'absolute';
}
/**
@ -884,7 +884,7 @@ export default class EditorModel extends Model {
const { config, view } = this;
const editor = this.getEditor();
const { editors = [] } = config.grapesjs || {};
const shallow = this.get("shallow");
const shallow = this.get('shallow');
shallow?.destroyAll();
this.stopListening();
this.stopDefault();
@ -905,22 +905,22 @@ export default class EditorModel extends Model {
}
getEditing() {
const res = this.get("editing");
const res = this.get('editing');
return (res && res.model) || null;
}
setEditing(value: boolean) {
this.set("editing", value);
this.set('editing', value);
return this;
}
isEditing() {
return !!this.get("editing");
return !!this.get('editing');
}
log(msg: string, opts: any = {}) {
const { ns, level = "debug" } = opts;
this.trigger("log", msg, opts);
const { ns, level = 'debug' } = opts;
this.trigger('log', msg, opts);
level && this.trigger(`log:${level}`, msg, opts);
if (ns) {
@ -931,7 +931,7 @@ export default class EditorModel extends Model {
}
logInfo(msg: string, opts?: any) {
this.log(msg, { ...opts, level: "info" });
this.log(msg, { ...opts, level: 'info' });
}
logWarning(msg: string, opts?: any) {
@ -939,7 +939,7 @@ export default class EditorModel extends Model {
}
logError(msg: string, opts?: any) {
this.log(msg, { ...opts, level: "error" });
this.log(msg, { ...opts, level: 'error' });
}
initBaseColorPicker(el: any, opts = {}) {
@ -951,13 +951,13 @@ export default class EditorModel extends Model {
//@ts-ignore
return $(el).spectrum({
containerClassName: `${ppfx}one-bg ${ppfx}two-color`,
appendTo: elToAppend || "body",
appendTo: elToAppend || 'body',
maxSelectionSize: 8,
showPalette: true,
palette: [],
showAlpha: true,
chooseText: "Ok",
cancelText: "⨯",
chooseText: 'Ok',
cancelText: '⨯',
...opts,
...colorPicker,
});
@ -970,7 +970,7 @@ export default class EditorModel extends Model {
*/
skip(clb: Function) {
this.__skip = true;
const um = this.get("UndoManager");
const um = this.get('UndoManager');
um ? um.skip(clb) : clb();
this.__skip = false;
}
@ -984,7 +984,7 @@ export default class EditorModel extends Model {
* @private
*/
data(el: any, name: string, value: any) {
const varName = "_gjs-data";
const varName = '_gjs-data';
if (!el[varName]) {
el[varName] = {};

44
src/pages/index.ts

@ -44,15 +44,15 @@
* @module Pages
*/
import { isString, bindAll, unique, flatten } from "underscore";
import { createId } from "../utils/mixins";
import { Model, Module } from "../abstract";
import { ItemManagerModule, ModuleConfig } from "../abstract/Module";
import Pages from "./model/Pages";
import Page from "./model/Page";
import EditorModel from "../editor/model/Editor";
import { isString, bindAll, unique, flatten } from 'underscore';
import { createId } from '../utils/mixins';
import { Model, Module } from '../abstract';
import { ItemManagerModule, ModuleConfig } from '../abstract/Module';
import Pages from './model/Pages';
import Page from './model/Page';
import EditorModel from '../editor/model/Editor';
export const evAll = "page";
export const evAll = 'page';
export const evPfx = `${evAll}:`;
export const evPageSelect = `${evPfx}select`;
export const evPageSelectBefore = `${evPageSelect}:before`;
@ -61,8 +61,8 @@ export const evPageAdd = `${evPfx}add`;
export const evPageAddBefore = `${evPageAdd}:before`;
export const evPageRemove = `${evPfx}remove`;
export const evPageRemoveBefore = `${evPageRemove}:before`;
const chnSel = "change:selected";
const typeMain = "main";
const chnSel = 'change:selected';
const typeMain = 'main';
const events = {
all: evAll,
select: evPageSelect,
@ -78,7 +78,7 @@ interface Config extends ModuleConfig {
pages?: string[];
}
export default class PageManager extends ItemManagerModule<Config, Pages> {
storageKey = "pages";
storageKey = 'pages';
get pages() {
return this.all;
@ -91,12 +91,12 @@ export default class PageManager extends ItemManagerModule<Config, Pages> {
* @private
*/
constructor(em: EditorModel) {
super(em, "PageManager", new Pages([]), events);
bindAll(this, "_onPageChange");
super(em, 'PageManager', new Pages([]), events);
bindAll(this, '_onPageChange');
const model = new Model({ _undo: true } as any);
this.model = model;
this.pages.on("reset", (coll) => coll.at(0) && this.select(coll.at(0)));
this.pages.on("all", this.__onChange, this);
this.pages.on('reset', (coll) => coll.at(0) && this.select(coll.at(0)));
this.pages.on('all', this.__onChange, this);
model.on(chnSel, this._onPageChange);
return this;
@ -124,16 +124,16 @@ export default class PageManager extends ItemManagerModule<Config, Pages> {
_onPageChange(m: any, page: Page, opts: any) {
const { em } = this;
const lm = em.get("LayerManager");
const lm = em.get('LayerManager');
const mainComp = page.getMainComponent();
lm && mainComp && lm.setRoot(mainComp);
em.trigger(evPageSelect, page, m.previous("selected"));
em.trigger(evPageSelect, page, m.previous('selected'));
this.__onChange(chnSel, page, opts);
}
postLoad() {
const { em, model } = this;
const um = em.get("UndoManager");
const um = em.get('UndoManager');
um && um.add(model);
um && um.add(this.pages);
}
@ -208,7 +208,7 @@ export default class PageManager extends ItemManagerModule<Config, Pages> {
*/
getMain() {
const { pages } = this;
return pages.filter((p) => p.get("type") === typeMain)[0] || pages.at(0);
return pages.filter((p) => p.get('type') === typeMain)[0] || pages.at(0);
}
/**
@ -244,7 +244,7 @@ export default class PageManager extends ItemManagerModule<Config, Pages> {
const pg = isString(page) ? this.get(page) : page;
if (pg) {
this.em.trigger(evPageSelectBefore, pg, opts);
this.model.set("selected", pg, opts);
this.model.set('selected', pg, opts);
}
return this;
}
@ -256,7 +256,7 @@ export default class PageManager extends ItemManagerModule<Config, Pages> {
* const selectedPage = pageManager.getSelected();
*/
getSelected() {
return this.model.get("selected");
return this.model.get('selected');
}
destroy() {
@ -264,7 +264,7 @@ export default class PageManager extends ItemManagerModule<Config, Pages> {
this.model.stopListening();
this.model.clear({ silent: true });
//@ts-ignore
["selected", "model"].map((i) => (this[i] = 0));
['selected', 'model'].map((i) => (this[i] = 0));
}
store() {

22
src/pages/model/Page.ts

@ -1,8 +1,8 @@
import { result, forEach } from "underscore";
import { Model } from "../../common";
import Frames from "../../canvas/model/Frames";
import Frame from "../../canvas/model/Frame";
import EditorModel from "../../editor/model/Editor";
import { result, forEach } from 'underscore';
import { Model } from '../../common';
import Frames from '../../canvas/model/Frames';
import Frame from '../../canvas/model/Frame';
import EditorModel from '../../editor/model/Editor';
export default class Page extends Model {
defaults() {
@ -22,7 +22,7 @@ export default class Page extends Model {
if (!props.frames) {
defFrame.component = props.component;
defFrame.styles = props.styles;
["component", "styles"].map((i) => this.unset(i));
['component', 'styles'].map((i) => this.unset(i));
}
const frms: any[] = props.frames || [defFrame];
const frames = new Frames(
@ -37,11 +37,11 @@ export default class Page extends Model {
}
onRemove() {
this.get("frames").reset();
this.get('frames').reset();
}
getFrames(): Frames {
return this.get("frames");
return this.get('frames');
}
/**
@ -57,7 +57,7 @@ export default class Page extends Model {
* @returns {String}
*/
getName(): string {
return this.get("name");
return this.get('name');
}
/**
@ -106,11 +106,11 @@ export default class Page extends Model {
toJSON(opts = {}) {
const obj = Model.prototype.toJSON.call(this, opts);
const defaults = result(this, "defaults");
const defaults = result(this, 'defaults');
// Remove private keys
forEach(obj, (value, key) => {
key.indexOf("_") === 0 && delete obj[key];
key.indexOf('_') === 0 && delete obj[key];
});
forEach(defaults, (value, key) => {

8
src/pages/model/Pages.ts

@ -1,11 +1,11 @@
import { Collection } from "../../common";
import Page from "./Page";
import { Collection } from '../../common';
import Page from './Page';
export default class Pages extends Collection<Page> {
constructor(models: any) {
super(models);
this.on("reset", this.onReset);
this.on("remove", this.onRemove);
this.on('reset', this.onReset);
this.on('remove', this.onRemove);
}
onReset(m: Page, opts?: { previousModels?: Pages }) {

Loading…
Cancel
Save