UNPKG

@opensig/opendesign

Version:

<p align="center"><img src="../docs/public/opendesign-logo-light.png"/></p> <h1 align="center">opendesign</h1> <p align="center">一个 Vue 3 组件库</p> <p align="center"><b>皮肤可定制,使用 TypeScript</b></p>

60 lines (59 loc) 1.67 kB
var __defProp = Object.defineProperty; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); class VTree { constructor(value, parent, children = []) { __publicField(this, "root"); this.root = { value, parent, children }; } getNode(node, val) { if (node.value === val) { return node; } const children = node.children; for (let i = 0, len = children.length; i < len; i++) { const rlt = this.getNode(children[i], val); if (rlt) { return rlt; } } } getPath(node, val, path) { const children = node.children; for (let i = 0, len = children.length; i < len; i++) { const child = children[i]; if (child.value === val) { return [...path, child]; } const rlt = this.getPath(child, val, [...path, child]); if (rlt) { return rlt; } } } hasSameNode(nodes, val) { return nodes.some((item) => item.value === val); } addNode(node) { const parent = node.parent; if (!parent) { if (!this.hasSameNode(this.root.children, node.value)) { node.parent = this.root; this.root.children.push(node); } } else { const parentNode = this.getNode(this.root, parent.value); if (parentNode && !this.hasSameNode(parentNode.children, node.value)) { node.parent = parentNode; parentNode.children.push(node); } } } } export { VTree };