58c2d3678f6a3b7b89cad7e7007dd4841cc44ebf1475e8f5a4ba79479a05125aa25d373e58cee81054525c2a2ecdcb5a97238f02059005feeb74c95d1cd1a4 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. var index$1 = require('../../checkbox/index.js');
  5. var index$2 = require('../../radio/index.js');
  6. var index$3 = require('../../icon/index.js');
  7. var iconsVue = require('@element-plus/icons-vue');
  8. var nodeContent = require('./node-content.js');
  9. var types = require('./types.js');
  10. var pluginVue_exportHelper = require('../../../_virtual/plugin-vue_export-helper.js');
  11. var index = require('../../../hooks/use-namespace/index.js');
  12. const __default__ = vue.defineComponent({
  13. name: "ElCascaderNode"
  14. });
  15. const _sfc_main = /* @__PURE__ */ vue.defineComponent({
  16. ...__default__,
  17. props: {
  18. node: {
  19. type: Object,
  20. required: true
  21. },
  22. menuId: String
  23. },
  24. emits: ["expand"],
  25. setup(__props, { emit }) {
  26. const props = __props;
  27. const panel = vue.inject(types.CASCADER_PANEL_INJECTION_KEY);
  28. const ns = index.useNamespace("cascader-node");
  29. const isHoverMenu = vue.computed(() => panel.isHoverMenu);
  30. const multiple = vue.computed(() => panel.config.multiple);
  31. const checkStrictly = vue.computed(() => panel.config.checkStrictly);
  32. const showPrefix = vue.computed(() => panel.config.showPrefix);
  33. const checkedNodeId = vue.computed(() => {
  34. var _a;
  35. return (_a = panel.checkedNodes[0]) == null ? void 0 : _a.uid;
  36. });
  37. const isDisabled = vue.computed(() => props.node.isDisabled);
  38. const isLeaf = vue.computed(() => props.node.isLeaf);
  39. const expandable = vue.computed(() => checkStrictly.value && !isLeaf.value || !isDisabled.value);
  40. const inExpandingPath = vue.computed(() => isInPath(panel.expandingNode));
  41. const inCheckedPath = vue.computed(() => checkStrictly.value && panel.checkedNodes.some(isInPath));
  42. const isInPath = (node) => {
  43. var _a;
  44. const { level, uid } = props.node;
  45. return ((_a = node == null ? void 0 : node.pathNodes[level - 1]) == null ? void 0 : _a.uid) === uid;
  46. };
  47. const doExpand = () => {
  48. if (inExpandingPath.value)
  49. return;
  50. panel.expandNode(props.node);
  51. };
  52. const doCheck = (checked) => {
  53. const { node } = props;
  54. if (checked === node.checked)
  55. return;
  56. panel.handleCheckChange(node, checked);
  57. };
  58. const doLoad = () => {
  59. panel.lazyLoad(props.node, () => {
  60. if (!isLeaf.value)
  61. doExpand();
  62. });
  63. };
  64. const handleHoverExpand = (e) => {
  65. if (!isHoverMenu.value)
  66. return;
  67. handleExpand();
  68. !isLeaf.value && emit("expand", e);
  69. };
  70. const handleExpand = () => {
  71. const { node } = props;
  72. if (!expandable.value || node.loading)
  73. return;
  74. node.loaded ? doExpand() : doLoad();
  75. };
  76. const handleClick = () => {
  77. if (isLeaf.value && !isDisabled.value && !checkStrictly.value && !multiple.value) {
  78. handleCheck(true);
  79. } else if ((panel.config.checkOnClickNode && (multiple.value || checkStrictly.value) || isLeaf.value && panel.config.checkOnClickLeaf) && !isDisabled.value) {
  80. handleSelectCheck(!props.node.checked);
  81. } else if (!isHoverMenu.value) {
  82. handleExpand();
  83. }
  84. };
  85. const handleSelectCheck = (checked) => {
  86. if (checkStrictly.value) {
  87. doCheck(checked);
  88. if (props.node.loaded) {
  89. doExpand();
  90. }
  91. } else {
  92. handleCheck(checked);
  93. }
  94. };
  95. const handleCheck = (checked) => {
  96. if (!props.node.loaded) {
  97. doLoad();
  98. } else {
  99. doCheck(checked);
  100. !checkStrictly.value && doExpand();
  101. }
  102. };
  103. return (_ctx, _cache) => {
  104. return vue.openBlock(), vue.createElementBlock("li", {
  105. id: `${__props.menuId}-${__props.node.uid}`,
  106. role: "menuitem",
  107. "aria-haspopup": !vue.unref(isLeaf),
  108. "aria-owns": vue.unref(isLeaf) ? void 0 : __props.menuId,
  109. "aria-expanded": vue.unref(inExpandingPath),
  110. tabindex: vue.unref(expandable) ? -1 : void 0,
  111. class: vue.normalizeClass([
  112. vue.unref(ns).b(),
  113. vue.unref(ns).is("selectable", vue.unref(checkStrictly)),
  114. vue.unref(ns).is("active", __props.node.checked),
  115. vue.unref(ns).is("disabled", !vue.unref(expandable)),
  116. vue.unref(inExpandingPath) && "in-active-path",
  117. vue.unref(inCheckedPath) && "in-checked-path"
  118. ]),
  119. onMouseenter: handleHoverExpand,
  120. onFocus: handleHoverExpand,
  121. onClick: handleClick
  122. }, [
  123. vue.createCommentVNode(" prefix "),
  124. vue.unref(multiple) && vue.unref(showPrefix) ? (vue.openBlock(), vue.createBlock(vue.unref(index$1.ElCheckbox), {
  125. key: 0,
  126. "model-value": __props.node.checked,
  127. indeterminate: __props.node.indeterminate,
  128. disabled: vue.unref(isDisabled),
  129. onClick: vue.withModifiers(() => {
  130. }, ["stop"]),
  131. "onUpdate:modelValue": handleSelectCheck
  132. }, null, 8, ["model-value", "indeterminate", "disabled", "onClick"])) : vue.unref(checkStrictly) && vue.unref(showPrefix) ? (vue.openBlock(), vue.createBlock(vue.unref(index$2.ElRadio), {
  133. key: 1,
  134. "model-value": vue.unref(checkedNodeId),
  135. label: __props.node.uid,
  136. disabled: vue.unref(isDisabled),
  137. "onUpdate:modelValue": handleSelectCheck,
  138. onClick: vue.withModifiers(() => {
  139. }, ["stop"])
  140. }, {
  141. default: vue.withCtx(() => [
  142. vue.createCommentVNode("\n Add an empty element to avoid render label,\n do not use empty fragment here for https://github.com/vuejs/vue-next/pull/2485\n "),
  143. vue.createElementVNode("span")
  144. ]),
  145. _: 1
  146. }, 8, ["model-value", "label", "disabled", "onClick"])) : vue.unref(isLeaf) && __props.node.checked ? (vue.openBlock(), vue.createBlock(vue.unref(index$3.ElIcon), {
  147. key: 2,
  148. class: vue.normalizeClass(vue.unref(ns).e("prefix"))
  149. }, {
  150. default: vue.withCtx(() => [
  151. vue.createVNode(vue.unref(iconsVue.Check))
  152. ]),
  153. _: 1
  154. }, 8, ["class"])) : vue.createCommentVNode("v-if", true),
  155. vue.createCommentVNode(" content "),
  156. vue.createVNode(vue.unref(nodeContent["default"]), { node: __props.node }, null, 8, ["node"]),
  157. vue.createCommentVNode(" postfix "),
  158. !vue.unref(isLeaf) ? (vue.openBlock(), vue.createElementBlock(vue.Fragment, { key: 3 }, [
  159. __props.node.loading ? (vue.openBlock(), vue.createBlock(vue.unref(index$3.ElIcon), {
  160. key: 0,
  161. class: vue.normalizeClass([vue.unref(ns).is("loading"), vue.unref(ns).e("postfix")])
  162. }, {
  163. default: vue.withCtx(() => [
  164. vue.createVNode(vue.unref(iconsVue.Loading))
  165. ]),
  166. _: 1
  167. }, 8, ["class"])) : (vue.openBlock(), vue.createBlock(vue.unref(index$3.ElIcon), {
  168. key: 1,
  169. class: vue.normalizeClass(["arrow-right", vue.unref(ns).e("postfix")])
  170. }, {
  171. default: vue.withCtx(() => [
  172. vue.createVNode(vue.unref(iconsVue.ArrowRight))
  173. ]),
  174. _: 1
  175. }, 8, ["class"]))
  176. ], 64)) : vue.createCommentVNode("v-if", true)
  177. ], 42, ["id", "aria-haspopup", "aria-owns", "aria-expanded", "tabindex"]);
  178. };
  179. }
  180. });
  181. var ElCascaderNode = /* @__PURE__ */ pluginVue_exportHelper["default"](_sfc_main, [["__file", "node.vue"]]);
  182. exports["default"] = ElCascaderNode;
  183. //# sourceMappingURL=node2.js.map