feat:标识编辑器构件
This commit is contained in:
+2
-2
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div id="app">
|
<div id="app">
|
||||||
<div class="menu">
|
<div class="menu" editor-component="menu">
|
||||||
<div class="menu-item">
|
<div class="menu-item">
|
||||||
<div class="menu-item__undo">
|
<div class="menu-item__undo">
|
||||||
<i></i>
|
<i></i>
|
||||||
@@ -64,7 +64,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="editor">
|
<div class="editor" editor-component="main">
|
||||||
<canvas style="width: 794px;height: 1123px;"></canvas>
|
<canvas style="width: 794px;height: 1123px;"></canvas>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { EDITOR_COMPONENT } from "../../dataset/constant/Editor"
|
||||||
|
import { findParent } from "../../utils"
|
||||||
import { Cursor } from "../cursor/Cursor"
|
import { Cursor } from "../cursor/Cursor"
|
||||||
import { Draw } from "../draw/Draw"
|
import { Draw } from "../draw/Draw"
|
||||||
import { CanvasEvent } from "./CanvasEvent"
|
import { CanvasEvent } from "./CanvasEvent"
|
||||||
@@ -32,8 +34,15 @@ export class GlobalEvent {
|
|||||||
if (!this.cursor) return
|
if (!this.cursor) return
|
||||||
const cursorDom = this.cursor.getCursorDom()
|
const cursorDom = this.cursor.getCursorDom()
|
||||||
const agentDom = this.cursor.getAgentDom()
|
const agentDom = this.cursor.getAgentDom()
|
||||||
const innerDoms = [this.canvas, cursorDom, agentDom, this.canvas.parentNode, document.body]
|
const innerDoms = [this.canvas, cursorDom, agentDom, document.body]
|
||||||
if (innerDoms.includes(evt.target as any)) return
|
if (innerDoms.includes(evt.target as any)) return
|
||||||
|
// 编辑器外部dom
|
||||||
|
const outerEditorDom = findParent(
|
||||||
|
evt.target as Element,
|
||||||
|
(node: Node & Element) => !!node && node.nodeType === 1 && !!node.getAttribute(EDITOR_COMPONENT),
|
||||||
|
true
|
||||||
|
)
|
||||||
|
if (outerEditorDom) return
|
||||||
this.cursor.recoveryCursor()
|
this.cursor.recoveryCursor()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
export const EDITOR_COMPONENT = 'editor-component'
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
export enum EditorComponent {
|
||||||
|
MENU = 'menu',
|
||||||
|
MAIN = 'main'
|
||||||
|
}
|
||||||
@@ -30,3 +30,22 @@ export function deepClone(obj: any) {
|
|||||||
}
|
}
|
||||||
return newObj
|
return newObj
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isBody(node: Element): boolean {
|
||||||
|
return node && node.nodeType === 1 && node.tagName.toLowerCase() === 'body'
|
||||||
|
}
|
||||||
|
|
||||||
|
export function findParent(node: Element, filterFn: Function, includeSelf: boolean) {
|
||||||
|
if (node && !isBody(node)) {
|
||||||
|
node = includeSelf ? node : node.parentNode as Element
|
||||||
|
while (node) {
|
||||||
|
if (!filterFn || filterFn(node) || isBody(node)) {
|
||||||
|
return filterFn && !filterFn(node) && isBody(node)
|
||||||
|
? null
|
||||||
|
: node
|
||||||
|
}
|
||||||
|
node = node.parentNode as Element
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user