UNPKG

zent

Version:

一套前端设计语言和基于React的实现

69 lines (68 loc) 2 kB
import { __assign } from "tslib"; import { clone as _clone, insertPath as _insertPath } from './forest'; export function clone(options) { return _clone(options, createNode); } export function insertPath(options, path) { return _insertPath(options, path, createNode); } export function getNode(options, path) { var node = null; var children = options; var _loop_1 = function (i) { var value = path[i].value; node = children.find(function (x) { return x.value === value; }); if (!node) { return { value: null }; } children = node.children; }; for (var i = 0; i < path.length; i++) { var state_1 = _loop_1(i); if (typeof state_1 === "object") return state_1.value; } return node; } export function merge(options, anotherOptions) { var merged = []; var stack = [ { x: options, y: anotherOptions, xy: merged, }, ]; while (stack.length > 0) { var frame = stack.pop(); var _a = frame.x, x = _a === void 0 ? [] : _a, _b = frame.y, y = _b === void 0 ? [] : _b, xy = frame.xy; for (var _i = 0, x_1 = x; _i < x_1.length; _i++) { var i = x_1[_i]; xy.push(i); } var _loop_2 = function (i) { var value = i.value; var j = x.find(function (node) { return node.value === value; }); if (!j) { xy.push(i); } else { var x_2 = j.children; j.children = []; stack.push({ x: x_2, y: i.children, xy: j.children, }); } }; for (var _c = 0, y_1 = y; _c < y_1.length; _c++) { var i = y_1[_c]; _loop_2(i); } } return merged; } function createNode(node) { return __assign(__assign({}, node), { children: [] }); }