Browse Source

Move getElRect

pull/5321/head
Artur Arseniev 3 years ago
parent
commit
dec472c3ab
  1. 4
      src/canvas/view/CanvasView.ts
  2. 25
      src/utils/dom.ts
  3. 21
      src/utils/mixins.ts

4
src/canvas/view/CanvasView.ts

@ -4,8 +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, isTextNode } from '../../utils/dom';
import { getComponentView, getElRect, getElement, getKeyChar, getUiClass, off, on } from '../../utils/mixins';
import { createEl, getDocumentScroll, isTextNode, getElRect } from '../../utils/dom';
import { getComponentView, getElement, getKeyChar, getUiClass, off, on } from '../../utils/mixins';
import Canvas from '../model/Canvas';
import Frame from '../model/Frame';
import FrameView from './FrameView';

25
src/utils/dom.ts

@ -152,6 +152,31 @@ export const isCommentNode = (el?: Node): el is Comment => el?.nodeType === Node
*/
export const isTaggableNode = (el?: Node) => el && !isTextNode(el) && !isCommentNode(el);
/**
* Get DOMRect of the element.
* @param el
* @returns {DOMRect}
*/
export const getElRect = (el?: Element) => {
const def = {
top: 0,
left: 0,
width: 0,
height: 0,
};
if (!el) return def;
let rectText;
if (isTextNode(el)) {
const range = document.createRange();
range.selectNode(el);
rectText = range.getBoundingClientRect();
range.detach();
}
return rectText || (el.getBoundingClientRect ? el.getBoundingClientRect() : def);
};
/**
* Get document scroll coordinates
*/

21
src/utils/mixins.ts

@ -215,26 +215,6 @@ const getModel = (el: any, $?: any) => {
return model;
};
const getElRect = (el?: HTMLElement) => {
const def = {
top: 0,
left: 0,
width: 0,
height: 0,
};
if (!el) return def;
let rectText;
if (isTextNode(el)) {
const range = document.createRange();
range.selectNode(el);
rectText = range.getBoundingClientRect();
range.detach();
}
return rectText || (el.getBoundingClientRect ? el.getBoundingClientRect() : def);
};
/**
* Get cross-device pointer event
* @param {Event} ev
@ -299,7 +279,6 @@ export {
upFirst,
matches,
getModel,
getElRect,
camelCase,
getKeyCode,
getKeyChar,

Loading…
Cancel
Save