tree-node.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. var index$1 = require('../../icon/index.js');
  5. var iconsVue = require('@element-plus/icons-vue');
  6. var index$2 = require('../../checkbox/index.js');
  7. require('../../../hooks/index.js');
  8. var treeNodeContent = require('./tree-node-content.js');
  9. var virtualTree = require('./virtual-tree.js');
  10. var pluginVue_exportHelper = require('../../../_virtual/plugin-vue_export-helper.js');
  11. var index = require('../../../hooks/use-namespace/index.js');
  12. const _hoisted_1 = ["aria-expanded", "aria-disabled", "aria-checked", "data-key", "onClick"];
  13. const __default__ = vue.defineComponent({
  14. name: "ElTreeNode"
  15. });
  16. const _sfc_main = /* @__PURE__ */ vue.defineComponent({
  17. ...__default__,
  18. props: virtualTree.treeNodeProps,
  19. emits: virtualTree.treeNodeEmits,
  20. setup(__props, { emit }) {
  21. const props = __props;
  22. const tree = vue.inject(virtualTree.ROOT_TREE_INJECTION_KEY);
  23. const ns = index.useNamespace("tree");
  24. const indent = vue.computed(() => {
  25. var _a;
  26. return (_a = tree == null ? void 0 : tree.props.indent) != null ? _a : 16;
  27. });
  28. const icon = vue.computed(() => {
  29. var _a;
  30. return (_a = tree == null ? void 0 : tree.props.icon) != null ? _a : iconsVue.CaretRight;
  31. });
  32. const handleClick = (e) => {
  33. emit("click", props.node, e);
  34. };
  35. const handleExpandIconClick = () => {
  36. emit("toggle", props.node);
  37. };
  38. const handleCheckChange = (value) => {
  39. emit("check", props.node, value);
  40. };
  41. const handleContextMenu = (event) => {
  42. var _a, _b, _c, _d;
  43. 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"]) {
  44. event.stopPropagation();
  45. event.preventDefault();
  46. }
  47. tree == null ? void 0 : tree.ctx.emit(virtualTree.NODE_CONTEXTMENU, event, (_d = props.node) == null ? void 0 : _d.data, props.node);
  48. };
  49. return (_ctx, _cache) => {
  50. var _a, _b, _c;
  51. return vue.openBlock(), vue.createElementBlock("div", {
  52. ref: "node$",
  53. class: vue.normalizeClass([
  54. vue.unref(ns).b("node"),
  55. vue.unref(ns).is("expanded", _ctx.expanded),
  56. vue.unref(ns).is("current", _ctx.current),
  57. vue.unref(ns).is("focusable", !_ctx.disabled),
  58. vue.unref(ns).is("checked", !_ctx.disabled && _ctx.checked)
  59. ]),
  60. role: "treeitem",
  61. tabindex: "-1",
  62. "aria-expanded": _ctx.expanded,
  63. "aria-disabled": _ctx.disabled,
  64. "aria-checked": _ctx.checked,
  65. "data-key": (_a = _ctx.node) == null ? void 0 : _a.key,
  66. onClick: vue.withModifiers(handleClick, ["stop"]),
  67. onContextmenu: handleContextMenu
  68. }, [
  69. vue.createElementVNode("div", {
  70. class: vue.normalizeClass(vue.unref(ns).be("node", "content")),
  71. style: vue.normalizeStyle({ paddingLeft: `${(_ctx.node.level - 1) * vue.unref(indent)}px` })
  72. }, [
  73. vue.unref(icon) ? (vue.openBlock(), vue.createBlock(vue.unref(index$1.ElIcon), {
  74. key: 0,
  75. class: vue.normalizeClass([
  76. vue.unref(ns).is("leaf", !!((_b = _ctx.node) == null ? void 0 : _b.isLeaf)),
  77. vue.unref(ns).is("hidden", _ctx.hiddenExpandIcon),
  78. {
  79. expanded: !((_c = _ctx.node) == null ? void 0 : _c.isLeaf) && _ctx.expanded
  80. },
  81. vue.unref(ns).be("node", "expand-icon")
  82. ]),
  83. onClick: vue.withModifiers(handleExpandIconClick, ["stop"])
  84. }, {
  85. default: vue.withCtx(() => [
  86. (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(vue.unref(icon))))
  87. ]),
  88. _: 1
  89. }, 8, ["class", "onClick"])) : vue.createCommentVNode("v-if", true),
  90. _ctx.showCheckbox ? (vue.openBlock(), vue.createBlock(vue.unref(index$2.ElCheckbox), {
  91. key: 1,
  92. "model-value": _ctx.checked,
  93. indeterminate: _ctx.indeterminate,
  94. disabled: _ctx.disabled,
  95. onChange: handleCheckChange,
  96. onClick: _cache[0] || (_cache[0] = vue.withModifiers(() => {
  97. }, ["stop"]))
  98. }, null, 8, ["model-value", "indeterminate", "disabled"])) : vue.createCommentVNode("v-if", true),
  99. vue.createVNode(vue.unref(treeNodeContent["default"]), { node: _ctx.node }, null, 8, ["node"])
  100. ], 6)
  101. ], 42, _hoisted_1);
  102. };
  103. }
  104. });
  105. var ElTreeNode = /* @__PURE__ */ pluginVue_exportHelper["default"](_sfc_main, [["__file", "/home/runner/work/element-plus/element-plus/packages/components/tree-v2/src/tree-node.vue"]]);
  106. exports["default"] = ElTreeNode;
  107. //# sourceMappingURL=tree-node.js.map