feat:标识编辑器构件

This commit is contained in:
黄云飞
2021-11-15 19:45:24 +08:00
parent b532c94438
commit 9462ba06fb
7 changed files with 62 additions and 3 deletions
+19
View File
@@ -29,4 +29,23 @@ export function deepClone(obj: any) {
})
}
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
}