UNPKG

tdesign-mobile-vue

Version:
320 lines (305 loc) 10.3 kB
/** * tdesign v1.7.0 * (c) 2024 TDesign Group * @license MIT */ import { _ as _defineProperty } from '../../../_chunks/dep-219bb5a7.mjs'; import { i as isUndefined_1 } from '../../../_chunks/dep-1bbfa76e.mjs'; import { i as isBoolean_1 } from '../../../_chunks/dep-ea9a17dc.mjs'; import '../../../_chunks/dep-8bf3054e.mjs'; import { _ as _baseGet, a as _castPath, b as _toKey } from '../../../_chunks/dep-c51d4905.mjs'; import { _ as _baseSet } from '../../../_chunks/dep-df48d24d.mjs'; import { i as isArguments_1 } from '../../../_chunks/dep-e57d46f3.mjs'; import { i as isArray_1 } from '../../../_chunks/dep-019e292f.mjs'; import '../../../_chunks/dep-32364550.mjs'; import { _ as _isIndex } from '../../../_chunks/dep-933f3a85.mjs'; import { a as isLength_1 } from '../../../_chunks/dep-4f44985d.mjs'; import { a as _flatRest, o as omit_1 } from '../../../_chunks/dep-55c9adc0.mjs'; import log from '../log/log.mjs'; import '../../../_chunks/dep-620d73f7.mjs'; import '../../../_chunks/dep-3d249f65.mjs'; import '../../../_chunks/dep-9b2de386.mjs'; import '../../../_chunks/dep-a836a38c.mjs'; import '../../../_chunks/dep-89951f45.mjs'; import '../../../_chunks/dep-08bc7a4c.mjs'; import '../../../_chunks/dep-91d696ea.mjs'; import '../../../_chunks/dep-e6c129ab.mjs'; import '../../../_chunks/dep-6bc862af.mjs'; import '../../../_chunks/dep-4931819d.mjs'; import '../../../_chunks/dep-8140c29b.mjs'; import '../../../_chunks/dep-0d52e58f.mjs'; import '../../../_chunks/dep-10f4d030.mjs'; import '../../../_chunks/dep-8ee6f5cd.mjs'; import '../../../_chunks/dep-b84be35c.mjs'; import '../../../_chunks/dep-6c53a3e4.mjs'; import '../../../_chunks/dep-d2161895.mjs'; import '../../../_chunks/dep-2bce42ea.mjs'; import '../../../_chunks/dep-0ea7bbde.mjs'; import '../../../_chunks/dep-ba131d9c.mjs'; var baseGet = _baseGet, baseSet = _baseSet, castPath$1 = _castPath; /** * The base implementation of `_.pickBy` without support for iteratee shorthands. * * @private * @param {Object} object The source object. * @param {string[]} paths The property paths to pick. * @param {Function} predicate The function invoked per property. * @returns {Object} Returns the new object. */ function basePickBy$1(object, paths, predicate) { var index = -1, length = paths.length, result = {}; while (++index < length) { var path = paths[index], value = baseGet(object, path); if (predicate(value, path)) { baseSet(result, castPath$1(path, object), value); } } return result; } var _basePickBy = basePickBy$1; /** * The base implementation of `_.hasIn` without support for deep paths. * * @private * @param {Object} [object] The object to query. * @param {Array|string} key The key to check. * @returns {boolean} Returns `true` if `key` exists, else `false`. */ function baseHasIn$1(object, key) { return object != null && key in Object(object); } var _baseHasIn = baseHasIn$1; var castPath = _castPath, isArguments = isArguments_1, isArray = isArray_1, isIndex = _isIndex, isLength = isLength_1, toKey = _toKey; /** * Checks if `path` exists on `object`. * * @private * @param {Object} object The object to query. * @param {Array|string} path The path to check. * @param {Function} hasFunc The function to check properties. * @returns {boolean} Returns `true` if `path` exists, else `false`. */ function hasPath$1(object, path, hasFunc) { path = castPath(path, object); var index = -1, length = path.length, result = false; while (++index < length) { var key = toKey(path[index]); if (!(result = object != null && hasFunc(object, key))) { break; } object = object[key]; } if (result || ++index != length) { return result; } length = object == null ? 0 : object.length; return !!length && isLength(length) && isIndex(key, length) && (isArray(object) || isArguments(object)); } var _hasPath = hasPath$1; var baseHasIn = _baseHasIn, hasPath = _hasPath; /** * Checks if `path` is a direct or inherited property of `object`. * * @static * @memberOf _ * @since 4.0.0 * @category Object * @param {Object} object The object to query. * @param {Array|string} path The path to check. * @returns {boolean} Returns `true` if `path` exists, else `false`. * @example * * var object = _.create({ 'a': _.create({ 'b': 2 }) }); * * _.hasIn(object, 'a'); * // => true * * _.hasIn(object, 'a.b'); * // => true * * _.hasIn(object, ['a', 'b']); * // => true * * _.hasIn(object, 'b'); * // => false */ function hasIn$1(object, path) { return object != null && hasPath(object, path, baseHasIn); } var hasIn_1 = hasIn$1; var basePickBy = _basePickBy, hasIn = hasIn_1; /** * The base implementation of `_.pick` without support for individual * property identifiers. * * @private * @param {Object} object The source object. * @param {string[]} paths The property paths to pick. * @returns {Object} Returns the new object. */ function basePick$1(object, paths) { return basePickBy(object, paths, function (value, path) { return hasIn(object, path); }); } var _basePick = basePick$1; var basePick = _basePick, flatRest = _flatRest; /** * Creates an object composed of the picked `object` properties. * * @static * @since 0.1.0 * @memberOf _ * @category Object * @param {Object} object The source object. * @param {...(string|string[])} [paths] The property paths to pick. * @returns {Object} Returns the new object. * @example * * var object = { 'a': 1, 'b': '2', 'c': 3 }; * * _.pick(object, ['a', 'c']); * // => { 'a': 1, 'c': 3 } */ var pick = flatRest(function (object, paths) { return object == null ? {} : basePick(object, paths); }); var pick_1 = pick; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function getExposedProps(node) { var props = pick_1(node, ["value", "label", "data", "actived", "expanded", "checked", "indeterminate", "loading"]); return props; } function createNodeModel(node) { var props = getExposedProps(node); var model = _objectSpread(_objectSpread({}, props), {}, { getLevel: function getLevel() { return node.getLevel(); }, getIndex: function getIndex() { return node.getIndex(); }, isFirst: function isFirst() { return node.isFirst(); }, isLast: function isLast() { return node.isLast(); }, isLeaf: function isLeaf() { return node.isLeaf(); }, insertBefore: function insertBefore(newData) { return node.insertBefore(newData); }, insertAfter: function insertAfter(newData) { return node.insertAfter(newData); }, appendData: function appendData(data) { return node.append(data); }, getPath: function getPath() { var nodes = node.getPath(); return nodes.map(function (item) { return item.getModel(); }); }, getParent: function getParent() { var _node$parent; return (_node$parent = node.parent) === null || _node$parent === void 0 ? void 0 : _node$parent.getModel(); }, getParents: function getParents() { var nodes = node.getParents(); return nodes.map(function (item) { return item.getModel(); }); }, getRoot: function getRoot() { var root = node.getRoot(); return root === null || root === void 0 ? void 0 : root.getModel(); }, getSiblings: function getSiblings() { var nodes = node.getSiblings(); return nodes.map(function (item) { return item.getModel(); }); }, getChildren: function getChildren(deep) { var childrenModel = false; var children = node.children; if (Array.isArray(children)) { if (children.length > 0) { if (deep) { var nodes = node.walk(); nodes.shift(); childrenModel = nodes.map(function (item) { return item.getModel(); }); } else { childrenModel = children.map(function (item) { return item.getModel(); }); } } else { childrenModel = false; } } else if (isBoolean_1(children)) { childrenModel = children; } return childrenModel; }, remove: function remove(value) { if (!value) { node.remove(); return; } var tree = node.tree; var targetNode = tree.getNode(value); if (!targetNode) { log.warnOnce("Tree", "`".concat(value, "` is not exist")); return; } var parents = targetNode.getParents(); var parentValues = parents.map(function (pnode) { return pnode.value; }); if (parentValues.indexOf(node.value) < 0) { log.warnOnce("Tree", "`".concat(value, "` is not a childNode of current node")); return; } targetNode.remove(); }, setData: function setData(data) { var _data = omit_1(data, ["children", "value", "label"]); var keys = node.tree.config.keys; var dataValue = data[(keys === null || keys === void 0 ? void 0 : keys.value) || "value"]; var dataLabel = data[(keys === null || keys === void 0 ? void 0 : keys.label) || "label"]; if (!isUndefined_1(dataValue)) _data.value = dataValue; if (!isUndefined_1(dataLabel)) _data.label = dataLabel; Object.assign(node.data, _data); Object.assign(node, _data); } }); return model; } function updateNodeModel(model, node) { var props = getExposedProps(node); Object.assign(model, props); } export { createNodeModel, updateNodeModel }; //# sourceMappingURL=tree-node-model.mjs.map