Browse Source

Move a few stuff from mixins to dom

pull/5321/head
Artur Arseniev 3 years ago
parent
commit
eb55cf6509
  1. 13
      src/canvas/view/CanvasView.ts
  2. 4
      src/commands/view/SelectComponent.ts
  3. 2
      src/commands/view/ShowOffset.ts
  4. 9
      src/utils/Sorter.ts
  5. 21
      src/utils/dom.ts
  6. 28
      src/utils/mixins.ts

13
src/canvas/view/CanvasView.ts

@ -4,17 +4,8 @@ import { ModuleView } from '../../abstract';
import { BoxRect, Coordinates, ElementRect } from '../../common';
import Component from '../../dom_components/model/Component';
import ComponentView from '../../dom_components/view/ComponentView';
import { createEl, getDocumentScroll } from '../../utils/dom';
import {
getComponentView,
getElRect,
getElement,
getKeyChar,
getUiClass,
isTextNode,
off,
on,
} from '../../utils/mixins';
import { createEl, getDocumentScroll, isTextNode } from '../../utils/dom';
import { getComponentView, getElRect, getElement, getKeyChar, getUiClass, off, on } from '../../utils/mixins';
import Canvas from '../model/Canvas';
import Frame from '../model/Frame';
import FrameView from './FrameView';

4
src/commands/view/SelectComponent.ts

@ -3,8 +3,8 @@ import { $ } from '../../common';
import Component from '../../dom_components/model/Component';
import Toolbar from '../../dom_components/model/Toolbar';
import ToolbarView from '../../dom_components/view/ToolbarView';
import { isDoc, isVisible } from '../../utils/dom';
import { getComponentView, getUnitFromValue, getViewEl, hasWin, isTaggableNode, off, on } from '../../utils/mixins';
import { isDoc, isTaggableNode, isVisible } from '../../utils/dom';
import { getComponentView, getUnitFromValue, getViewEl, hasWin, off, on } from '../../utils/mixins';
import { CommandObject } from './CommandAbstract';
let showOffsets: boolean;

2
src/commands/view/ShowOffset.ts

@ -1,6 +1,6 @@
import { isUndefined } from 'underscore';
import { $ } from '../../common';
import { isTextNode } from '../../utils/mixins';
import { isTextNode } from '../../utils/dom';
import { CommandObject } from './CommandAbstract';
export default {

9
src/utils/Sorter.ts

@ -1,9 +1,10 @@
import { isString, isFunction, isArray, result, each, bindAll } from 'underscore';
import { on, off, matches, getElement, getPointerEvent, isTextNode, getModel } from './mixins';
import { View, Model, Collection, $ } from '../common';
import EditorModel from '../editor/model/Editor';
import { bindAll, each, isArray, isFunction, isString, result } from 'underscore';
import { BlockProperties } from '../block_manager/model/Block';
import CanvasModule from '../canvas';
import { $, Collection, Model, View } from '../common';
import EditorModel from '../editor/model/Editor';
import { isTextNode } from './dom';
import { getElement, getModel, getPointerEvent, matches, off, on } from './mixins';
const noop = () => {};

21
src/utils/dom.ts

@ -131,6 +131,27 @@ export const appendVNodes = (node: HTMLElement, vNodes: vNode | vNode[] = []) =>
});
};
/**
* Check if element is a text node
* @param {Node} el
* @return {Boolean}
*/
export const isTextNode = (el?: Node): el is Text => el?.nodeType === Node.TEXT_NODE;
/**
* Check if element is a comment node
* @param {Node} el
* @return {Boolean}
*/
export const isCommentNode = (el?: Node): el is Comment => el?.nodeType === Node.COMMENT_NODE;
/**
* Check if taggable node
* @param {Node} el
* @return {Boolean}
*/
export const isTaggableNode = (el?: Node) => el && !isTextNode(el) && !isCommentNode(el);
/**
* Get document scroll coordinates
*/

28
src/utils/mixins.ts

@ -1,7 +1,7 @@
import { keys, isUndefined, isElement, isArray } from 'underscore';
import EditorModel from '../editor/model/Editor';
import { View } from '../common';
import { isArray, isElement, isUndefined, keys } from 'underscore';
import ComponentView from '../dom_components/view/ComponentView';
import EditorModel from '../editor/model/Editor';
import { isTextNode } from './dom';
export const isDef = (value: any) => typeof value !== 'undefined';
@ -159,27 +159,6 @@ const getElement = (el: HTMLElement) => {
}
};
/**
* Check if element is a text node
* @param {HTMLElement} el
* @return {Boolean}
*/
const isTextNode = (el: HTMLElement) => el && el.nodeType === 3;
/**
* Check if element is a comment node
* @param {HTMLElement} el
* @return {Boolean}
*/
export const isCommentNode = (el: HTMLElement) => el && el.nodeType === 8;
/**
* Check if element is a comment node
* @param {HTMLElement} el
* @return {Boolean}
*/
export const isTaggableNode = (el: HTMLElement) => el && !isTextNode(el) && !isCommentNode(el);
export const find = (arr: any[], test: (item: any, i: number, arr: any[]) => boolean) => {
let result = null;
arr.some((el, i) => (test(el, i, arr) ? ((result = el), 1) : 0));
@ -322,7 +301,6 @@ export {
getModel,
getElRect,
camelCase,
isTextNode,
getKeyCode,
getKeyChar,
isEscKey,

Loading…
Cancel
Save