index10.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. import { i as Y, n as de, u as Z, h as ce, d as p, o as se, ac as q, _ as P, c as ee, a1 as z, a3 as b, j as D, a4 as $, P as J, f as ie, bA as re, bB as ue, bC as fe, bD as ve } from "./index2.js";
  2. import { createVNode as N, defineComponent as te, ref as T, computed as h, watchEffect as ye, watch as M, onUpdated as Ke, nextTick as he } from "vue";
  3. import { u as pe, T as xe, r as ke, t as be, V as me } from "./index11.js";
  4. import { e as Q, f as Ee, c as Te, g as Ne } from "./useMaxLevel.js";
  5. const X = 4;
  6. function _e(e) {
  7. const {
  8. dropPosition: r,
  9. dropLevelOffset: s,
  10. prefixCls: a,
  11. indent: l,
  12. direction: u = "ltr"
  13. } = e, d = u === "ltr" ? "left" : "right", c = u === "ltr" ? "right" : "left", v = {
  14. [d]: `${-s * l + X}px`,
  15. [c]: 0
  16. };
  17. switch (r) {
  18. case -1:
  19. v.top = "-3px";
  20. break;
  21. case 1:
  22. v.bottom = "-3px";
  23. break;
  24. default:
  25. v.bottom = "-3px", v[d] = `${l + X}px`;
  26. break;
  27. }
  28. return N("div", {
  29. style: v,
  30. class: `${a}-drop-indicator`
  31. }, null);
  32. }
  33. const ne = () => {
  34. const e = be();
  35. return p(p({}, e), {
  36. showLine: z([Boolean, Object]),
  37. /** 是否支持多选 */
  38. multiple: b(),
  39. /** 是否自动展开父节点 */
  40. autoExpandParent: b(),
  41. /** checkable状态下节点选择完全受控(父子节点选中状态不再关联)*/
  42. checkStrictly: b(),
  43. /** 是否支持选中 */
  44. checkable: b(),
  45. /** 是否禁用树 */
  46. disabled: b(),
  47. /** 默认展开所有树节点 */
  48. defaultExpandAll: b(),
  49. /** 默认展开对应树节点 */
  50. defaultExpandParent: b(),
  51. /** 默认展开指定的树节点 */
  52. defaultExpandedKeys: D(),
  53. /** (受控)展开指定的树节点 */
  54. expandedKeys: D(),
  55. /** (受控)选中复选框的树节点 */
  56. checkedKeys: z([Array, Object]),
  57. /** 默认选中复选框的树节点 */
  58. defaultCheckedKeys: D(),
  59. /** (受控)设置选中的树节点 */
  60. selectedKeys: D(),
  61. /** 默认选中的树节点 */
  62. defaultSelectedKeys: D(),
  63. selectable: b(),
  64. loadedKeys: D(),
  65. draggable: b(),
  66. showIcon: b(),
  67. icon: $(),
  68. switcherIcon: J.any,
  69. prefixCls: String,
  70. /**
  71. * @default{title,key,children}
  72. * deprecated, please use `fieldNames` instead
  73. * 替换treeNode中 title,key,children字段为treeData中对应的字段
  74. */
  75. replaceFields: ie(),
  76. blockNode: b(),
  77. openAnimation: J.any,
  78. onDoubleclick: e.onDblclick,
  79. "onUpdate:selectedKeys": $(),
  80. "onUpdate:checkedKeys": $(),
  81. "onUpdate:expandedKeys": $()
  82. });
  83. }, A = te({
  84. compatConfig: {
  85. MODE: 3
  86. },
  87. name: "ATree",
  88. inheritAttrs: !1,
  89. props: Y(ne(), {
  90. checkable: !1,
  91. selectable: !0,
  92. showIcon: !1,
  93. blockNode: !1
  94. }),
  95. slots: Object,
  96. setup(e, r) {
  97. let {
  98. attrs: s,
  99. expose: a,
  100. emit: l,
  101. slots: u
  102. } = r;
  103. de(!(e.treeData === void 0 && u.default), "`children` of Tree is deprecated. Please use `treeData` instead.");
  104. const {
  105. prefixCls: d,
  106. direction: c,
  107. virtual: v
  108. } = Z("tree", e), [y, E] = pe(d), i = T();
  109. a({
  110. treeRef: i,
  111. onNodeExpand: function() {
  112. var n;
  113. (n = i.value) === null || n === void 0 || n.onNodeExpand(...arguments);
  114. },
  115. scrollTo: (n) => {
  116. var f;
  117. (f = i.value) === null || f === void 0 || f.scrollTo(n);
  118. },
  119. selectedKeys: h(() => {
  120. var n;
  121. return (n = i.value) === null || n === void 0 ? void 0 : n.selectedKeys;
  122. }),
  123. checkedKeys: h(() => {
  124. var n;
  125. return (n = i.value) === null || n === void 0 ? void 0 : n.checkedKeys;
  126. }),
  127. halfCheckedKeys: h(() => {
  128. var n;
  129. return (n = i.value) === null || n === void 0 ? void 0 : n.halfCheckedKeys;
  130. }),
  131. loadedKeys: h(() => {
  132. var n;
  133. return (n = i.value) === null || n === void 0 ? void 0 : n.loadedKeys;
  134. }),
  135. loadingKeys: h(() => {
  136. var n;
  137. return (n = i.value) === null || n === void 0 ? void 0 : n.loadingKeys;
  138. }),
  139. expandedKeys: h(() => {
  140. var n;
  141. return (n = i.value) === null || n === void 0 ? void 0 : n.expandedKeys;
  142. })
  143. }), ye(() => {
  144. ce(e.replaceFields === void 0, "Tree", "`replaceFields` is deprecated, please use fieldNames instead");
  145. });
  146. const j = (n, f) => {
  147. l("update:checkedKeys", n), l("check", n, f);
  148. }, S = (n, f) => {
  149. l("update:expandedKeys", n), l("expand", n, f);
  150. }, _ = (n, f) => {
  151. l("update:selectedKeys", n), l("select", n, f);
  152. };
  153. return () => {
  154. const {
  155. showIcon: n,
  156. showLine: f,
  157. switcherIcon: F = u.switcherIcon,
  158. icon: U = u.icon,
  159. blockNode: L,
  160. checkable: B,
  161. selectable: O,
  162. fieldNames: w = e.replaceFields,
  163. motion: V = e.openAnimation,
  164. itemHeight: t = 28,
  165. onDoubleclick: o,
  166. onDblclick: K
  167. } = e, C = p(p(p({}, s), se(e, ["onUpdate:checkedKeys", "onUpdate:expandedKeys", "onUpdate:selectedKeys", "onDoubleclick"])), {
  168. showLine: !!f,
  169. dropIndicatorRender: _e,
  170. fieldNames: w,
  171. icon: U,
  172. itemHeight: t
  173. }), x = u.default ? q(u.default()) : void 0;
  174. return y(N(xe, P(P({}, C), {}, {
  175. virtual: v.value,
  176. motion: V,
  177. ref: i,
  178. prefixCls: d.value,
  179. class: ee({
  180. [`${d.value}-icon-hide`]: !n,
  181. [`${d.value}-block-node`]: L,
  182. [`${d.value}-unselectable`]: !O,
  183. [`${d.value}-rtl`]: c.value === "rtl"
  184. }, s.class, E.value),
  185. direction: c.value,
  186. checkable: B,
  187. selectable: O,
  188. switcherIcon: (g) => ke(d.value, F, g, u.leafIcon, f),
  189. onCheck: j,
  190. onExpand: S,
  191. onSelect: _,
  192. onDblclick: K || o,
  193. children: x
  194. }), p(p({}, u), {
  195. checkable: () => N("span", {
  196. class: `${d.value}-checkbox-inner`
  197. }, null)
  198. })));
  199. };
  200. }
  201. });
  202. var m;
  203. (function(e) {
  204. e[e.None = 0] = "None", e[e.Start = 1] = "Start", e[e.End = 2] = "End";
  205. })(m || (m = {}));
  206. function G(e, r, s) {
  207. function a(l) {
  208. const u = l[r.key], d = l[r.children];
  209. s(u, l) !== !1 && G(d || [], r, s);
  210. }
  211. e.forEach(a);
  212. }
  213. function ge(e) {
  214. let {
  215. treeData: r,
  216. expandedKeys: s,
  217. startKey: a,
  218. endKey: l,
  219. fieldNames: u = {
  220. title: "title",
  221. key: "key",
  222. children: "children"
  223. }
  224. } = e;
  225. const d = [];
  226. let c = m.None;
  227. if (a && a === l)
  228. return [a];
  229. if (!a || !l)
  230. return [];
  231. function v(y) {
  232. return y === a || y === l;
  233. }
  234. return G(r, u, (y) => {
  235. if (c === m.End)
  236. return !1;
  237. if (v(y)) {
  238. if (d.push(y), c === m.None)
  239. c = m.Start;
  240. else if (c === m.Start)
  241. return c = m.End, !1;
  242. } else c === m.Start && d.push(y);
  243. return s.includes(y);
  244. }), d;
  245. }
  246. function H(e, r, s) {
  247. const a = [...r], l = [];
  248. return G(e, s, (u, d) => {
  249. const c = a.indexOf(u);
  250. return c !== -1 && (l.push(d), a.splice(c, 1)), !!a.length;
  251. }), l;
  252. }
  253. var De = function(e, r) {
  254. var s = {};
  255. for (var a in e) Object.prototype.hasOwnProperty.call(e, a) && r.indexOf(a) < 0 && (s[a] = e[a]);
  256. if (e != null && typeof Object.getOwnPropertySymbols == "function") for (var l = 0, a = Object.getOwnPropertySymbols(e); l < a.length; l++)
  257. r.indexOf(a[l]) < 0 && Object.prototype.propertyIsEnumerable.call(e, a[l]) && (s[a[l]] = e[a[l]]);
  258. return s;
  259. };
  260. const Se = () => p(p({}, ne()), {
  261. expandAction: z([Boolean, String])
  262. });
  263. function we(e) {
  264. const {
  265. isLeaf: r,
  266. expanded: s
  267. } = e;
  268. return r ? N(ue, null, null) : s ? N(fe, null, null) : N(ve, null, null);
  269. }
  270. const R = te({
  271. compatConfig: {
  272. MODE: 3
  273. },
  274. name: "ADirectoryTree",
  275. inheritAttrs: !1,
  276. props: Y(Se(), {
  277. showIcon: !0,
  278. expandAction: "click"
  279. }),
  280. slots: Object,
  281. // emits: [
  282. // 'update:selectedKeys',
  283. // 'update:checkedKeys',
  284. // 'update:expandedKeys',
  285. // 'expand',
  286. // 'select',
  287. // 'check',
  288. // 'doubleclick',
  289. // 'dblclick',
  290. // 'click',
  291. // ],
  292. setup(e, r) {
  293. let {
  294. attrs: s,
  295. slots: a,
  296. emit: l,
  297. expose: u
  298. } = r;
  299. var d;
  300. const c = T(e.treeData || Q(q((d = a.default) === null || d === void 0 ? void 0 : d.call(a))));
  301. M(() => e.treeData, () => {
  302. c.value = e.treeData;
  303. }), Ke(() => {
  304. he(() => {
  305. var t;
  306. e.treeData === void 0 && a.default && (c.value = Q(q((t = a.default) === null || t === void 0 ? void 0 : t.call(a))));
  307. });
  308. });
  309. const v = T(), y = T(), E = h(() => Ee(e.fieldNames)), i = T();
  310. u({
  311. scrollTo: (t) => {
  312. var o;
  313. (o = i.value) === null || o === void 0 || o.scrollTo(t);
  314. },
  315. selectedKeys: h(() => {
  316. var t;
  317. return (t = i.value) === null || t === void 0 ? void 0 : t.selectedKeys;
  318. }),
  319. checkedKeys: h(() => {
  320. var t;
  321. return (t = i.value) === null || t === void 0 ? void 0 : t.checkedKeys;
  322. }),
  323. halfCheckedKeys: h(() => {
  324. var t;
  325. return (t = i.value) === null || t === void 0 ? void 0 : t.halfCheckedKeys;
  326. }),
  327. loadedKeys: h(() => {
  328. var t;
  329. return (t = i.value) === null || t === void 0 ? void 0 : t.loadedKeys;
  330. }),
  331. loadingKeys: h(() => {
  332. var t;
  333. return (t = i.value) === null || t === void 0 ? void 0 : t.loadingKeys;
  334. }),
  335. expandedKeys: h(() => {
  336. var t;
  337. return (t = i.value) === null || t === void 0 ? void 0 : t.expandedKeys;
  338. })
  339. });
  340. const j = () => {
  341. const {
  342. keyEntities: t
  343. } = Te(c.value, {
  344. fieldNames: E.value
  345. });
  346. let o;
  347. return e.defaultExpandAll ? o = Object.keys(t) : e.defaultExpandParent ? o = Ne(e.expandedKeys || e.defaultExpandedKeys || [], t) : o = e.expandedKeys || e.defaultExpandedKeys, o;
  348. }, S = T(e.selectedKeys || e.defaultSelectedKeys || []), _ = T(j());
  349. M(() => e.selectedKeys, () => {
  350. e.selectedKeys !== void 0 && (S.value = e.selectedKeys);
  351. }, {
  352. immediate: !0
  353. }), M(() => e.expandedKeys, () => {
  354. e.expandedKeys !== void 0 && (_.value = e.expandedKeys);
  355. }, {
  356. immediate: !0
  357. });
  358. const f = re((t, o) => {
  359. const {
  360. isLeaf: K
  361. } = o;
  362. K || t.shiftKey || t.metaKey || t.ctrlKey || i.value.onNodeExpand(t, o);
  363. }, 200, {
  364. leading: !0
  365. }), F = (t, o) => {
  366. e.expandedKeys === void 0 && (_.value = t), l("update:expandedKeys", t), l("expand", t, o);
  367. }, U = (t, o) => {
  368. const {
  369. expandAction: K
  370. } = e;
  371. K === "click" && f(t, o), l("click", t, o);
  372. }, L = (t, o) => {
  373. const {
  374. expandAction: K
  375. } = e;
  376. (K === "dblclick" || K === "doubleclick") && f(t, o), l("doubleclick", t, o), l("dblclick", t, o);
  377. }, B = (t, o) => {
  378. const {
  379. multiple: K
  380. } = e, {
  381. node: C,
  382. nativeEvent: x
  383. } = o, g = C[E.value.key], I = p(p({}, o), {
  384. selected: !0
  385. }), ae = (x == null ? void 0 : x.ctrlKey) || (x == null ? void 0 : x.metaKey), oe = x == null ? void 0 : x.shiftKey;
  386. let k;
  387. K && ae ? (k = t, v.value = g, y.value = k, I.selectedNodes = H(c.value, k, E.value)) : K && oe ? (k = Array.from(/* @__PURE__ */ new Set([...y.value || [], ...ge({
  388. treeData: c.value,
  389. expandedKeys: _.value,
  390. startKey: g,
  391. endKey: v.value,
  392. fieldNames: E.value
  393. })])), I.selectedNodes = H(c.value, k, E.value)) : (k = [g], v.value = g, y.value = k, I.selectedNodes = H(c.value, k, E.value)), l("update:selectedKeys", k), l("select", k, I), e.selectedKeys === void 0 && (S.value = k);
  394. }, O = (t, o) => {
  395. l("update:checkedKeys", t), l("check", t, o);
  396. }, {
  397. prefixCls: w,
  398. direction: V
  399. } = Z("tree", e);
  400. return () => {
  401. const t = ee(`${w.value}-directory`, {
  402. [`${w.value}-directory-rtl`]: V.value === "rtl"
  403. }, s.class), {
  404. icon: o = a.icon,
  405. blockNode: K = !0
  406. } = e, C = De(e, ["icon", "blockNode"]);
  407. return N(A, P(P(P({}, s), {}, {
  408. icon: o || we,
  409. ref: i,
  410. blockNode: K
  411. }, C), {}, {
  412. prefixCls: w.value,
  413. class: t,
  414. expandedKeys: _.value,
  415. selectedKeys: S.value,
  416. onSelect: B,
  417. onClick: U,
  418. onDblclick: L,
  419. onExpand: F,
  420. onCheck: O
  421. }), a);
  422. };
  423. }
  424. }), W = me, $e = p(A, {
  425. DirectoryTree: R,
  426. TreeNode: W,
  427. install: (e) => (e.component(A.name, A), e.component(W.name, W), e.component(R.name, R), e)
  428. });
  429. export {
  430. $e as T,
  431. R as _
  432. };