UNPKG

vuestic-ui

Version:
129 lines (128 loc) 2.93 kB
import { a as getValueByKey } from "../../../utils/value-by-key.js"; const useTreeViewProps = { nodes: { type: Array, default: [] }, stateful: { type: Boolean, default: true }, selectable: { type: Boolean, default: false }, selectionType: { type: String, default: "leaf", validator: (v) => ["leaf", "independent"].includes(v) }, valueBy: { type: [String, Function], default: "id" }, textBy: { type: [String, Function], default: "label" }, trackBy: { type: [String, Function], default: "id" }, iconBy: { type: [String, Function], default: "icon" }, disabledBy: { type: [String, Function], default: "disabled" }, expandedBy: { type: [String, Function], default: "expanded" }, checkedBy: { type: [String, Function], default: "checked" }, childrenBy: { type: [String, Function], default: "children" }, expandAll: { type: Boolean, default: false }, expanded: { type: Array, default: [] }, expandNodeBy: { type: String, default: "leaf" }, filter: { type: String, default: "" }, filterMethod: { type: Function, default: void 0 }, checked: { type: Array, default: [] }, color: { type: String, default: "primary" } }; const useTreeViewEmits = ["update:modelValue", "update:checked", "update:expanded", "update:selected"]; const useTreeHelpers = (props) => { const isStringOrNumber = (node) => { const typeOfNode = typeof node; return typeOfNode === "string" || typeOfNode === "number"; }; const getNodeProperty = (node, key) => !key || isStringOrNumber(node) ? node : getValueByKey(node, key); const getValue = (node) => getNodeProperty(node, props.valueBy); const getNodeByValue = (value) => { if (!props.valueBy) { return value; } return props.nodes.find((node) => value === getValue(node)) || value; }; const getText = (node) => getNodeProperty(node, props.textBy); const getChecked = (node) => getNodeProperty(node, props.checkedBy); const getDisabled = (node) => getNodeProperty(node, props.disabledBy); const getExpanded = (node) => getNodeProperty(node, props.expandedBy); const getTrackBy = (node) => getNodeProperty(node, props.trackBy); const getChildren = (node) => getNodeProperty(node, props.childrenBy) ?? []; const iterateNodes = (nodes, cb) => { nodes.forEach((node) => { const children = node.children || []; if (children.length) { iterateNodes(children, cb); } cb(node); }); }; return { getText, getValue, getChecked, getTrackBy, getChildren, getDisabled, getExpanded, iterateNodes, getNodeByValue, getNodeProperty }; }; export { useTreeViewEmits as a, useTreeHelpers as b, useTreeViewProps as u }; //# sourceMappingURL=useTreeHelpers.js.map