From eb55cf6509b55e4341f88dfef4373836841a3a7d Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Thu, 17 Aug 2023 13:17:15 +0400 Subject: [PATCH] Move a few stuff from mixins to dom --- src/canvas/view/CanvasView.ts | 13 ++----------- src/commands/view/SelectComponent.ts | 4 ++-- src/commands/view/ShowOffset.ts | 2 +- src/utils/Sorter.ts | 9 +++++---- src/utils/dom.ts | 21 +++++++++++++++++++++ src/utils/mixins.ts | 28 +++------------------------- 6 files changed, 34 insertions(+), 43 deletions(-) diff --git a/src/canvas/view/CanvasView.ts b/src/canvas/view/CanvasView.ts index 1807eb54c..4cf06f41c 100644 --- a/src/canvas/view/CanvasView.ts +++ b/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'; diff --git a/src/commands/view/SelectComponent.ts b/src/commands/view/SelectComponent.ts index c44a99ded..e1a05d48c 100644 --- a/src/commands/view/SelectComponent.ts +++ b/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; diff --git a/src/commands/view/ShowOffset.ts b/src/commands/view/ShowOffset.ts index d26089865..7c99fac7e 100644 --- a/src/commands/view/ShowOffset.ts +++ b/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 { diff --git a/src/utils/Sorter.ts b/src/utils/Sorter.ts index 00d08c84e..b87bfc37b 100644 --- a/src/utils/Sorter.ts +++ b/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 = () => {}; diff --git a/src/utils/dom.ts b/src/utils/dom.ts index 4da47c8c1..82ffd7d88 100644 --- a/src/utils/dom.ts +++ b/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 */ diff --git a/src/utils/mixins.ts b/src/utils/mixins.ts index bc1f650f6..9b81db751 100644 --- a/src/utils/mixins.ts +++ b/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,