Browse Source

Up comments

pull/4389/head
Artur Arseniev 4 years ago
parent
commit
dd447fb402
  1. 1
      package.json
  2. 28
      src/canvas/model/Frame.ts
  3. 17
      src/canvas/view/FrameView.ts

1
package.json

@ -72,6 +72,7 @@
}, },
"lint-staged": { "lint-staged": {
"{src,test}/**/*.(t|j)s": [ "{src,test}/**/*.(t|j)s": [
"npm run lint -- --fix",
"prettier --single-quote --print-width 120 --arrow-parens avoid --write", "prettier --single-quote --print-width 120 --arrow-parens avoid --write",
"git add" "git add"
] ]

28
src/canvas/model/Frame.ts

@ -1,6 +1,6 @@
import { result, forEach, isEmpty, isString } from 'underscore'; import { result, forEach, isEmpty, isString } from 'underscore';
import { Model } from "../../abstract"; import { Model } from '../../abstract';
import CanvasModule from ".."; import CanvasModule from '..';
import ComponentWrapper from '../../dom_components/model/ComponentWrapper'; import ComponentWrapper from '../../dom_components/model/ComponentWrapper';
import { isComponent, isObject } from '../../utils/mixins'; import { isComponent, isObject } from '../../utils/mixins';
import FrameView from '../view/FrameView'; import FrameView from '../view/FrameView';
@ -35,6 +35,9 @@ export default class Frame extends Model<CanvasModule> {
} }
view?: FrameView; view?: FrameView;
/**
* @hideconstructor
*/
constructor(module: CanvasModule, props: any) { constructor(module: CanvasModule, props: any) {
super(module, props); super(module, props);
const { em } = this; const { em } = this;
@ -58,7 +61,7 @@ export default class Frame extends Model<CanvasModule> {
// Avoid losing styles on remapped components // Avoid losing styles on remapped components
const idMapKeys = Object.keys(idMap); const idMapKeys = Object.keys(idMap);
if (idMapKeys.length && Array.isArray(styles)) { if (idMapKeys.length && Array.isArray(styles)) {
styles.forEach((style) => { styles.forEach(style => {
const sel = style.selectors; const sel = style.selectors;
if (sel && sel.length == 1) { if (sel && sel.length == 1) {
const sSel = sel[0]; const sSel = sel[0];
@ -83,8 +86,8 @@ export default class Frame extends Model<CanvasModule> {
!props.height && this.set(keyAutoH, 1); !props.height && this.set(keyAutoH, 1);
} }
get head(): {tag: string, attributes: any}[]{ get head(): { tag: string; attributes: any }[] {
return this.get("head"); return this.get('head');
} }
onRemove() { onRemove() {
@ -120,21 +123,16 @@ export default class Frame extends Model<CanvasModule> {
return [...this.head]; return [...this.head];
} }
setHead(value: {tag: string, attributes: any}[]) { setHead(value: { tag: string; attributes: any }[]) {
return this.set("head", [...value]); return this.set('head', [...value]);
} }
addHeadItem(item: {tag: string, attributes: any}) { addHeadItem(item: { tag: string; attributes: any }) {
this.head.push(item); this.head.push(item);
} }
getHeadByAttr(attr: string, value: any, tag: string) { getHeadByAttr(attr: string, value: any, tag: string) {
return this.head.filter( return this.head.filter(item => item.attributes && item.attributes[attr] == value && (!tag || tag === item.tag))[0];
(item) =>
item.attributes &&
item.attributes[attr] == value &&
(!tag || tag === item.tag)
)[0];
} }
removeHeadByAttr(attr: string, value: any, tag: string) { removeHeadByAttr(attr: string, value: any, tag: string) {
@ -202,7 +200,7 @@ export default class Frame extends Model<CanvasModule> {
if (obj[key] === value) delete obj[key]; if (obj[key] === value) delete obj[key];
}); });
forEach(['attributes', 'head'], (prop) => { forEach(['attributes', 'head'], prop => {
if (isEmpty(obj[prop])) delete obj[prop]; if (isEmpty(obj[prop])) delete obj[prop];
}); });

17
src/canvas/view/FrameView.ts

@ -10,11 +10,14 @@ import ComponentWrapper from '../../dom_components/model/ComponentWrapper';
import FrameWrapView from './FrameWrapView'; import FrameWrapView from './FrameWrapView';
export default class FrameView extends View<Frame, HTMLIFrameElement> { export default class FrameView extends View<Frame, HTMLIFrameElement> {
//@ts-ignore //@ts-ignore
get tagName(){return 'iframe'}; get tagName() {
return 'iframe';
}
//@ts-ignore //@ts-ignore
get attributes() {return { allowfullscreen: 'allowfullscreen' }}; get attributes() {
return { allowfullscreen: 'allowfullscreen' };
}
dragging = false; dragging = false;
droppable?: Droppable; droppable?: Droppable;
@ -23,13 +26,12 @@ export default class FrameView extends View<Frame, HTMLIFrameElement> {
lastClientY?: number; lastClientY?: number;
lastMaxHeight = 0; lastMaxHeight = 0;
private jsContainer?: HTMLElement; private jsContainer?: HTMLElement;
private tools: {[key: string]: HTMLElement} = {}; private tools: { [key: string]: HTMLElement } = {};
private wrapper?: any; private wrapper?: any;
private frameWrapView?: FrameWrapView; private frameWrapView?: FrameWrapView;
constructor(model: Frame, view?: FrameWrapView) { constructor(model: Frame, view?: FrameWrapView) {
super({model}); super({ model });
bindAll(this, 'updateClientY', 'stopAutoscroll', 'autoscroll', '_emitUpdate'); bindAll(this, 'updateClientY', 'stopAutoscroll', 'autoscroll', '_emitUpdate');
const { el, em } = this; const { el, em } = this;
//el = em.config.el //el = em.config.el
@ -331,7 +333,8 @@ export default class FrameView extends View<Frame, HTMLIFrameElement> {
const body = this.getBody(); const body = this.getBody();
const win = this.getWindow(); const win = this.getWindow();
const conf = em.config; const conf = em.config;
//@ts-ignore TODO I don't understand why this needed nowhere else is used //@ts-ignore This could be used inside component-related scripts to check if the
// script is executed inside the editor.
win._isEditor = true; win._isEditor = true;
this.renderStyles({ prev: [] }); this.renderStyles({ prev: [] });

Loading…
Cancel
Save