hongluan-ui
Version:
Hongluan Component Library for Vue 3
147 lines (144 loc) • 4.87 kB
JavaScript
import { defineComponent, useSlots, provide, getCurrentInstance, openBlock, createElementBlock, normalizeClass, unref, createBlock, withCtx, normalizeStyle, createSlots, renderSlot, normalizeProps, guardReactiveProps, createElementVNode, toDisplayString } from 'vue';
import '../../../hooks/index.mjs';
import '../../../tokens/index.mjs';
import '../../virtual-list/index.mjs';
import { useTree } from './composables/useTree.mjs';
import _sfc_main$1 from './tree-node.mjs';
import { treeProps, treeEmits, ROOT_TREE_INJECTION_KEY } from './virtual-tree.mjs';
import { useNamespace } from '../../../hooks/use-namespace/index.mjs';
import { formItemContextKey } from '../../../tokens/form.mjs';
import { useLocale } from '../../../hooks/use-locale/index.mjs';
import FixedSizeList from '../../virtual-list/src/components/fixed-size-list.mjs';
const __default__ = defineComponent({
name: "TreeV2"
});
const _sfc_main = /* @__PURE__ */ defineComponent({
...__default__,
props: treeProps,
emits: treeEmits,
setup(__props, { expose, emit }) {
const props = __props;
const slots = useSlots();
const { namespace } = useNamespace("tree");
provide(ROOT_TREE_INJECTION_KEY, {
ctx: {
emit,
slots
},
props,
instance: getCurrentInstance()
});
provide(formItemContextKey, void 0);
const { t } = useLocale();
const {
flattenTree,
isNotEmpty,
listRef,
toggleExpand,
isExpanded,
isIndeterminate,
isChecked,
isDisabled,
isCurrent,
isForceHiddenExpandIcon,
toggleCheckbox,
handleNodeClick,
handleNodeCheck,
getCurrentNode,
getCurrentKey,
setCurrentKey,
getCheckedKeys,
getCheckedNodes,
getHalfCheckedKeys,
getHalfCheckedNodes,
setChecked,
setCheckedKeys,
filter,
setData,
getNode,
expandNode,
collapseNode,
setExpandedKeys,
scrollToNode,
scrollTo
} = useTree(props, emit);
expose({
getCurrentNode,
getCurrentKey,
setCurrentKey,
getCheckedKeys,
getCheckedNodes,
getHalfCheckedKeys,
getHalfCheckedNodes,
setChecked,
setCheckedKeys,
filter,
setData,
getNode,
expandNode,
collapseNode,
setExpandedKeys,
scrollToNode,
scrollTo
});
return (_ctx, _cache) => {
return openBlock(), createElementBlock("div", {
class: normalizeClass({
[unref(namespace)]: true,
"highlight-current": _ctx.highlightCurrent
}),
role: "tree"
}, [
unref(isNotEmpty) ? (openBlock(), createBlock(unref(FixedSizeList), {
key: 0,
ref_key: "listRef",
ref: listRef,
"class-name": "tree-virtual-list",
data: unref(flattenTree),
total: unref(flattenTree).length,
height: _ctx.height,
"item-size": _ctx.itemSize,
"perf-mode": _ctx.perfMode
}, {
default: withCtx(({ data, index, style }) => [
(openBlock(), createBlock(_sfc_main$1, {
key: data[index].key,
style: normalizeStyle(style),
node: data[index],
expanded: unref(isExpanded)(data[index]),
"show-checkbox": _ctx.showCheckbox,
checked: unref(isChecked)(data[index]),
indeterminate: unref(isIndeterminate)(data[index]),
disabled: unref(isDisabled)(data[index]),
current: unref(isCurrent)(data[index]),
"hidden-expand-icon": unref(isForceHiddenExpandIcon)(data[index]),
onClick: unref(handleNodeClick),
onToggle: unref(toggleExpand),
onCheck: unref(handleNodeCheck)
}, createSlots({ _: 2 }, [
_ctx.$slots.icon ? {
name: "icon",
fn: withCtx((params) => [
renderSlot(_ctx.$slots, "icon", normalizeProps(guardReactiveProps(params)))
])
} : void 0
]), 1032, ["style", "node", "expanded", "show-checkbox", "checked", "indeterminate", "disabled", "current", "hidden-expand-icon", "onClick", "onToggle", "onCheck"]))
]),
_: 3
}, 8, ["data", "total", "height", "item-size", "perf-mode"])) : (openBlock(), createElementBlock("div", {
key: 1,
class: "tree-empty-block"
}, [
renderSlot(_ctx.$slots, "empty", {}, () => {
var _a;
return [
createElementVNode("span", { class: "tree-empty-text" }, toDisplayString((_a = _ctx.emptyText) != null ? _a : unref(t)("hl.tree.emptyText")), 1)
];
})
]))
], 2);
};
}
});
export { _sfc_main as default };
//# sourceMappingURL=tree.mjs.map