UNPKG

element-plus

Version:

A Component Library for Vue 3

123 lines (120 loc) 5.11 kB
import { defineComponent, inject, computed, resolveComponent, openBlock, createElementBlock, normalizeClass, withModifiers, createElementVNode, normalizeStyle, createBlock, withCtx, resolveDynamicComponent, createCommentVNode, createVNode } from 'vue'; import { CaretRight } from '@element-plus/icons-vue'; import { ElIcon } from '../../icon/index.mjs'; import { ElCheckbox } from '../../checkbox/index.mjs'; import '../../../hooks/index.mjs'; import ElNodeContent from './tree-node-content.mjs'; import { treeNodeProps, treeNodeEmits, ROOT_TREE_INJECTION_KEY, NODE_CONTEXTMENU } from './virtual-tree.mjs'; import _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs'; import { useNamespace } from '../../../hooks/use-namespace/index.mjs'; const DEFAULT_ICON = "caret-right"; const _sfc_main = defineComponent({ name: "ElTreeNode", components: { ElIcon, CaretRight, ElCheckbox, ElNodeContent }, props: treeNodeProps, emits: treeNodeEmits, setup(props, { emit }) { const tree = inject(ROOT_TREE_INJECTION_KEY); const ns = useNamespace("tree"); const indent = computed(() => { var _a; return (_a = tree == null ? void 0 : tree.props.indent) != null ? _a : 16; }); const icon = computed(() => { var _a; return (_a = tree == null ? void 0 : tree.props.icon) != null ? _a : DEFAULT_ICON; }); const handleClick = (e) => { emit("click", props.node, e); }; const handleExpandIconClick = () => { emit("toggle", props.node); }; const handleCheckChange = (value) => { emit("check", props.node, value); }; const handleContextMenu = (event) => { var _a, _b, _c, _d; if ((_c = (_b = (_a = tree == null ? void 0 : tree.instance) == null ? void 0 : _a.vnode) == null ? void 0 : _b.props) == null ? void 0 : _c["onNodeContextmenu"]) { event.stopPropagation(); event.preventDefault(); } tree == null ? void 0 : tree.ctx.emit(NODE_CONTEXTMENU, event, (_d = props.node) == null ? void 0 : _d.data, props.node); }; return { ns, indent, icon, handleClick, handleExpandIconClick, handleCheckChange, handleContextMenu }; } }); const _hoisted_1 = ["aria-expanded", "aria-disabled", "aria-checked", "data-key"]; function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { var _a, _b, _c; const _component_el_icon = resolveComponent("el-icon"); const _component_el_checkbox = resolveComponent("el-checkbox"); const _component_el_node_content = resolveComponent("el-node-content"); return openBlock(), createElementBlock("div", { ref: "node$", class: normalizeClass([ _ctx.ns.b("node"), _ctx.ns.is("expanded", _ctx.expanded), _ctx.ns.is("current", _ctx.current), _ctx.ns.is("focusable", !_ctx.disabled), _ctx.ns.is("checked", !_ctx.disabled && _ctx.checked) ]), role: "treeitem", tabindex: "-1", "aria-expanded": _ctx.expanded, "aria-disabled": _ctx.disabled, "aria-checked": _ctx.checked, "data-key": (_a = _ctx.node) == null ? void 0 : _a.key, onClick: _cache[1] || (_cache[1] = withModifiers((...args) => _ctx.handleClick && _ctx.handleClick(...args), ["stop"])), onContextmenu: _cache[2] || (_cache[2] = (...args) => _ctx.handleContextMenu && _ctx.handleContextMenu(...args)) }, [ createElementVNode("div", { class: normalizeClass(_ctx.ns.be("node", "content")), style: normalizeStyle({ paddingLeft: `${(_ctx.node.level - 1) * _ctx.indent}px` }) }, [ _ctx.icon ? (openBlock(), createBlock(_component_el_icon, { key: 0, class: normalizeClass([ _ctx.ns.is("leaf", !!((_b = _ctx.node) == null ? void 0 : _b.isLeaf)), _ctx.ns.is("hidden", _ctx.hiddenExpandIcon), { expanded: !((_c = _ctx.node) == null ? void 0 : _c.isLeaf) && _ctx.expanded }, _ctx.ns.be("node", "expand-icon") ]), onClick: withModifiers(_ctx.handleExpandIconClick, ["stop"]) }, { default: withCtx(() => [ (openBlock(), createBlock(resolveDynamicComponent(_ctx.icon))) ]), _: 1 }, 8, ["class", "onClick"])) : createCommentVNode("v-if", true), _ctx.showCheckbox ? (openBlock(), createBlock(_component_el_checkbox, { key: 1, "model-value": _ctx.checked, indeterminate: _ctx.indeterminate, disabled: _ctx.disabled, onChange: _ctx.handleCheckChange, onClick: _cache[0] || (_cache[0] = withModifiers(() => { }, ["stop"])) }, null, 8, ["model-value", "indeterminate", "disabled", "onChange"])) : createCommentVNode("v-if", true), createVNode(_component_el_node_content, { node: _ctx.node }, null, 8, ["node"]) ], 6) ], 42, _hoisted_1); } var ElTreeNode = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], ["__file", "/home/runner/work/element-plus/element-plus/packages/components/tree-v2/src/tree-node.vue"]]); export { ElTreeNode as default }; //# sourceMappingURL=tree-node.mjs.map