index19.js 12 KB

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