SCascader.js 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232
  1. import { computed as y, shallowRef as Te, ref as X, watchEffect as ie, provide as We, inject as je, watch as be, createVNode as T, defineComponent as xe, onMounted as He, toRef as pe, toRefs as Be, openBlock as ze, createElementBlock as Xe, unref as Ue } from "vue";
  2. import { d as k, n as Ge, p as qe, q as Se, v as we, x as Je, K as J, _ as Z, i as De, y as Qe, z as Ve, h as oe, o as Ie, B as Ye, A as Ze, f as et, P as ye, g as tt, C as nt, t as lt, D as at, b as ot, E as st, F as it, G as rt, u as ct, H as ut, I as dt, J as vt, c as pt, L as ht, M as ft, N as gt, O as mt, Q as Ct, S as ke, T as St } from "./index2.js";
  3. import { c as yt, u as bt, a as Ce } from "./useMaxLevel.js";
  4. const Oe = "__RC_CASCADER_SPLIT__", $e = "SHOW_PARENT", Ne = "SHOW_CHILD";
  5. function ee(e) {
  6. return e.join(Oe);
  7. }
  8. function se(e) {
  9. return e.map(ee);
  10. }
  11. function xt(e) {
  12. return e.split(Oe);
  13. }
  14. function wt(e) {
  15. const {
  16. label: a,
  17. value: t,
  18. children: n
  19. } = e || {}, l = t || "value";
  20. return {
  21. label: a || "label",
  22. value: l,
  23. key: l,
  24. children: n || "children"
  25. };
  26. }
  27. function ce(e, a) {
  28. var t, n;
  29. return (t = e.isLeaf) !== null && t !== void 0 ? t : !(!((n = e[a.children]) === null || n === void 0) && n.length);
  30. }
  31. function It(e) {
  32. const a = e.parentElement;
  33. if (!a)
  34. return;
  35. const t = e.offsetTop - a.offsetTop;
  36. t - a.scrollTop < 0 ? a.scrollTo({
  37. top: t
  38. }) : t + e.offsetHeight - a.scrollTop > a.offsetHeight && a.scrollTo({
  39. top: t + e.offsetHeight - a.offsetHeight
  40. });
  41. }
  42. const Ot = (e, a) => y(() => yt(e.value, {
  43. fieldNames: a.value,
  44. initWrapper: (n) => k(k({}, n), {
  45. pathKeyEntities: {}
  46. }),
  47. processEntity: (n, l) => {
  48. const i = n.nodes.map((r) => r[a.value.value]).join(Oe);
  49. l.pathKeyEntities[i] = n, n.key = i;
  50. }
  51. }).pathKeyEntities);
  52. function Pt(e) {
  53. const a = Te(!1), t = X({});
  54. return ie(() => {
  55. if (!e.value) {
  56. a.value = !1, t.value = {};
  57. return;
  58. }
  59. let n = {
  60. matchInputWidth: !0,
  61. limit: 50
  62. };
  63. e.value && typeof e.value == "object" && (n = k(k({}, n), e.value)), n.limit <= 0 && (delete n.limit, process.env.NODE_ENV !== "production" && Ge(!1, "'limit' of showSearch should be positive number or false.")), a.value = !0, t.value = n;
  64. }), {
  65. showSearch: a,
  66. searchConfig: t
  67. };
  68. }
  69. const ue = "__rc_cascader_search_mark__", Vt = (e, a, t) => {
  70. let {
  71. label: n
  72. } = t;
  73. return a.some((l) => String(l[n]).toLowerCase().includes(e.toLowerCase()));
  74. }, kt = (e) => {
  75. let {
  76. path: a,
  77. fieldNames: t
  78. } = e;
  79. return a.map((n) => n[t.label]).join(" / ");
  80. }, _t = (e, a, t, n, l, i) => y(() => {
  81. const {
  82. filter: r = Vt,
  83. render: d = kt,
  84. limit: v = 50,
  85. sort: c
  86. } = l.value, o = [];
  87. if (!e.value)
  88. return [];
  89. function C(O, b) {
  90. O.forEach((D) => {
  91. if (!c && v > 0 && o.length >= v)
  92. return;
  93. const g = [...b, D], x = D[t.value.children];
  94. // If is leaf option
  95. (!x || x.length === 0 || // If is changeOnSelect
  96. i.value) && r(e.value, g, {
  97. label: t.value.label
  98. }) && o.push(k(k({}, D), {
  99. [t.value.label]: d({
  100. inputValue: e.value,
  101. path: g,
  102. prefixCls: n.value,
  103. fieldNames: t.value
  104. }),
  105. [ue]: g
  106. })), x && C(D[t.value.children], g);
  107. });
  108. }
  109. return C(a.value, []), c && o.sort((O, b) => c(O[ue], b[ue], e.value, t.value)), v > 0 ? o.slice(0, v) : o;
  110. });
  111. function _e(e, a, t) {
  112. const n = new Set(e);
  113. return e.filter((l) => {
  114. const i = a[l], r = i ? i.parent : null, d = i ? i.children : null;
  115. return t === Ne ? !(d && d.some((v) => v.key && n.has(v.key))) : !(r && !r.node.disabled && n.has(r.key));
  116. });
  117. }
  118. function de(e, a, t) {
  119. let n = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : !1;
  120. var l;
  121. let i = a;
  122. const r = [];
  123. for (let d = 0; d < e.length; d += 1) {
  124. const v = e[d], c = i == null ? void 0 : i.findIndex((C) => {
  125. const O = C[t.value];
  126. return n ? String(O) === String(v) : O === v;
  127. }), o = c !== -1 ? i == null ? void 0 : i[c] : null;
  128. r.push({
  129. value: (l = o == null ? void 0 : o[t.value]) !== null && l !== void 0 ? l : v,
  130. index: c,
  131. option: o
  132. }), i = o == null ? void 0 : o[t.children];
  133. }
  134. return r;
  135. }
  136. const At = (e, a, t) => y(() => {
  137. const n = [], l = [];
  138. return t.value.forEach((i) => {
  139. de(i, e.value, a.value).every((d) => d.option) ? l.push(i) : n.push(i);
  140. }), [l, n];
  141. }), Et = (e, a, t, n, l) => y(() => {
  142. const i = l.value || // Default displayRender
  143. ((r) => {
  144. let {
  145. labels: d
  146. } = r;
  147. const v = n.value ? d.slice(-1) : d, c = " / ";
  148. return v.every((o) => ["string", "number"].includes(typeof o)) ? v.join(c) : v.reduce((o, C, O) => {
  149. const b = qe(C) ? Se(C, {
  150. key: O
  151. }) : C;
  152. return O === 0 ? [b] : [...o, c, b];
  153. }, []);
  154. });
  155. return e.value.map((r) => {
  156. const d = de(r, a.value, t.value), v = i({
  157. labels: d.map((o) => {
  158. let {
  159. option: C,
  160. value: O
  161. } = o;
  162. var b;
  163. return (b = C == null ? void 0 : C[t.value.label]) !== null && b !== void 0 ? b : O;
  164. }),
  165. selectedOptions: d.map((o) => {
  166. let {
  167. option: C
  168. } = o;
  169. return C;
  170. })
  171. }), c = ee(r);
  172. return {
  173. label: v,
  174. value: c,
  175. key: c,
  176. valueCells: r
  177. };
  178. });
  179. }), Re = Symbol("CascaderContextKey"), Tt = (e) => {
  180. We(Re, e);
  181. }, he = () => je(Re), Dt = () => {
  182. const e = we(), {
  183. values: a
  184. } = he(), [t, n] = Je([]);
  185. return be(() => e.open, () => {
  186. if (e.open && !e.multiple) {
  187. const l = a.value[0];
  188. n(l || []);
  189. }
  190. }, {
  191. immediate: !0
  192. }), [t, n];
  193. }, $t = (e, a, t, n, l, i) => {
  194. const r = we(), d = y(() => r.direction === "rtl"), [v, c, o] = [X([]), X(), X([])];
  195. ie(() => {
  196. let g = -1, x = a.value;
  197. const p = [], w = [], E = n.value.length;
  198. for (let _ = 0; _ < E && x; _ += 1) {
  199. const N = x.findIndex(($) => $[t.value.value] === n.value[_]);
  200. if (N === -1)
  201. break;
  202. g = N, p.push(g), w.push(n.value[_]), x = x[g][t.value.children];
  203. }
  204. let P = a.value;
  205. for (let _ = 0; _ < p.length - 1; _ += 1)
  206. P = P[p[_]][t.value.children];
  207. [v.value, c.value, o.value] = [w, g, P];
  208. });
  209. const C = (g) => {
  210. l(g);
  211. }, O = (g) => {
  212. const x = o.value.length;
  213. let p = c.value;
  214. p === -1 && g < 0 && (p = x);
  215. for (let w = 0; w < x; w += 1) {
  216. p = (p + g + x) % x;
  217. const E = o.value[p];
  218. if (E && !E.disabled) {
  219. const P = E[t.value.value], _ = v.value.slice(0, -1).concat(P);
  220. C(_);
  221. return;
  222. }
  223. }
  224. }, b = () => {
  225. if (v.value.length > 1) {
  226. const g = v.value.slice(0, -1);
  227. C(g);
  228. } else
  229. r.toggleOpen(!1);
  230. }, D = () => {
  231. var g;
  232. const p = (((g = o.value[c.value]) === null || g === void 0 ? void 0 : g[t.value.children]) || []).find((w) => !w.disabled);
  233. if (p) {
  234. const w = [...v.value, p[t.value.value]];
  235. C(w);
  236. }
  237. };
  238. e.expose({
  239. // scrollTo: treeRef.current?.scrollTo,
  240. onKeydown: (g) => {
  241. const {
  242. which: x
  243. } = g;
  244. switch (x) {
  245. case J.UP:
  246. case J.DOWN: {
  247. let p = 0;
  248. x === J.UP ? p = -1 : x === J.DOWN && (p = 1), p !== 0 && O(p);
  249. break;
  250. }
  251. case J.LEFT: {
  252. d.value ? D() : b();
  253. break;
  254. }
  255. case J.RIGHT: {
  256. d.value ? b() : D();
  257. break;
  258. }
  259. case J.BACKSPACE: {
  260. r.searchValue || b();
  261. break;
  262. }
  263. case J.ENTER: {
  264. if (v.value.length) {
  265. const p = o.value[c.value], w = (p == null ? void 0 : p[ue]) || [];
  266. w.length ? i(w.map((E) => E[t.value.value]), w[w.length - 1]) : i(v.value, p);
  267. }
  268. break;
  269. }
  270. case J.ESC:
  271. r.toggleOpen(!1), open && g.stopPropagation();
  272. }
  273. },
  274. onKeyup: () => {
  275. }
  276. });
  277. };
  278. function fe(e) {
  279. let {
  280. prefixCls: a,
  281. checked: t,
  282. halfChecked: n,
  283. disabled: l,
  284. onClick: i
  285. } = e;
  286. const {
  287. customSlots: r,
  288. checkable: d
  289. } = he(), v = d.value !== !1 ? r.value.checkable : d.value, c = typeof v == "function" ? v() : typeof v == "boolean" ? null : v;
  290. return T("span", {
  291. class: {
  292. [a]: !0,
  293. [`${a}-checked`]: t,
  294. [`${a}-indeterminate`]: !t && n,
  295. [`${a}-disabled`]: l
  296. },
  297. onClick: i
  298. }, [c]);
  299. }
  300. fe.props = ["prefixCls", "checked", "halfChecked", "disabled", "onClick"];
  301. fe.displayName = "Checkbox";
  302. fe.inheritAttrs = !1;
  303. const Le = "__cascader_fix_label__";
  304. function ge(e) {
  305. let {
  306. prefixCls: a,
  307. multiple: t,
  308. options: n,
  309. activeValue: l,
  310. prevValuePath: i,
  311. onToggleOpen: r,
  312. onSelect: d,
  313. onActive: v,
  314. checkedSet: c,
  315. halfCheckedSet: o,
  316. loadingKeys: C,
  317. isSelectable: O
  318. } = e;
  319. var b, D, g, x, p, w;
  320. const E = `${a}-menu`, P = `${a}-menu-item`, {
  321. fieldNames: _,
  322. changeOnSelect: N,
  323. expandTrigger: $,
  324. expandIcon: U,
  325. loadingIcon: Q,
  326. dropdownMenuColumnStyle: G,
  327. customSlots: M
  328. } = he(), F = (b = U.value) !== null && b !== void 0 ? b : (g = (D = M.value).expandIcon) === null || g === void 0 ? void 0 : g.call(D), W = (x = Q.value) !== null && x !== void 0 ? x : (w = (p = M.value).loadingIcon) === null || w === void 0 ? void 0 : w.call(p), te = $.value === "hover";
  329. return T("ul", {
  330. class: E,
  331. role: "menu"
  332. }, [n.map((R) => {
  333. var h;
  334. const {
  335. disabled: I
  336. } = R, s = R[ue], S = (h = R[Le]) !== null && h !== void 0 ? h : R[_.value.label], m = R[_.value.value], V = ce(R, _.value), K = s ? s.map((u) => u[_.value.value]) : [...i, m], j = ee(K), H = C.includes(j), Y = c.has(j), ne = o.has(j), le = () => {
  337. !I && (!te || !V) && v(K);
  338. }, B = () => {
  339. O(R) && d(K, V);
  340. };
  341. let q;
  342. return typeof R.title == "string" ? q = R.title : typeof S == "string" && (q = S), T("li", {
  343. key: j,
  344. class: [P, {
  345. [`${P}-expand`]: !V,
  346. [`${P}-active`]: l === m,
  347. [`${P}-disabled`]: I,
  348. [`${P}-loading`]: H
  349. }],
  350. style: G.value,
  351. role: "menuitemcheckbox",
  352. title: q,
  353. "aria-checked": Y,
  354. "data-path-key": j,
  355. onClick: () => {
  356. le(), (!t || V) && B();
  357. },
  358. onDblclick: () => {
  359. N.value && r(!1);
  360. },
  361. onMouseenter: () => {
  362. te && le();
  363. },
  364. onMousedown: (u) => {
  365. u.preventDefault();
  366. }
  367. }, [t && T(fe, {
  368. prefixCls: `${a}-checkbox`,
  369. checked: Y,
  370. halfChecked: ne,
  371. disabled: I,
  372. onClick: (u) => {
  373. u.stopPropagation(), B();
  374. }
  375. }, null), T("div", {
  376. class: `${P}-content`
  377. }, [S]), !H && F && !V && T("div", {
  378. class: `${P}-expand-icon`
  379. }, [Se(F)]), H && W && T("div", {
  380. class: `${P}-loading-icon`
  381. }, [Se(W)])]);
  382. })]);
  383. }
  384. ge.props = ["prefixCls", "multiple", "options", "activeValue", "prevValuePath", "onToggleOpen", "onSelect", "onActive", "checkedSet", "halfCheckedSet", "loadingKeys", "isSelectable"];
  385. ge.displayName = "Column";
  386. ge.inheritAttrs = !1;
  387. const Nt = xe({
  388. compatConfig: {
  389. MODE: 3
  390. },
  391. name: "OptionList",
  392. inheritAttrs: !1,
  393. setup(e, a) {
  394. const {
  395. attrs: t,
  396. slots: n
  397. } = a, l = we(), i = X(), r = y(() => l.direction === "rtl"), {
  398. options: d,
  399. values: v,
  400. halfValues: c,
  401. fieldNames: o,
  402. changeOnSelect: C,
  403. onSelect: O,
  404. searchOptions: b,
  405. dropdownPrefixCls: D,
  406. loadData: g,
  407. expandTrigger: x,
  408. customSlots: p
  409. } = he(), w = y(() => D.value || l.prefixCls), E = Te([]), P = (h) => {
  410. if (!g.value || l.searchValue)
  411. return;
  412. const s = de(h, d.value, o.value).map((m) => {
  413. let {
  414. option: V
  415. } = m;
  416. return V;
  417. }), S = s[s.length - 1];
  418. if (S && !ce(S, o.value)) {
  419. const m = ee(h);
  420. E.value = [...E.value, m], g.value(s);
  421. }
  422. };
  423. ie(() => {
  424. E.value.length && E.value.forEach((h) => {
  425. const I = xt(h), s = de(I, d.value, o.value, !0).map((m) => {
  426. let {
  427. option: V
  428. } = m;
  429. return V;
  430. }), S = s[s.length - 1];
  431. (!S || S[o.value.children] || ce(S, o.value)) && (E.value = E.value.filter((m) => m !== h));
  432. });
  433. });
  434. const _ = y(() => new Set(se(v.value))), N = y(() => new Set(se(c.value))), [$, U] = Dt(), Q = (h) => {
  435. U(h), P(h);
  436. }, G = (h) => {
  437. const {
  438. disabled: I
  439. } = h, s = ce(h, o.value);
  440. return !I && (s || C.value || l.multiple);
  441. }, M = function(h, I) {
  442. let s = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : !1;
  443. O(h), !l.multiple && (I || C.value && (x.value === "hover" || s)) && l.toggleOpen(!1);
  444. }, F = y(() => l.searchValue ? b.value : d.value), W = y(() => {
  445. const h = [{
  446. options: F.value
  447. }];
  448. let I = F.value;
  449. for (let s = 0; s < $.value.length; s += 1) {
  450. const S = $.value[s], m = I.find((K) => K[o.value.value] === S), V = m == null ? void 0 : m[o.value.children];
  451. if (!(V != null && V.length))
  452. break;
  453. I = V, h.push({
  454. options: V
  455. });
  456. }
  457. return h;
  458. });
  459. $t(a, F, o, $, Q, (h, I) => {
  460. G(I) && M(h, ce(I, o.value), !0);
  461. });
  462. const R = (h) => {
  463. h.preventDefault();
  464. };
  465. return He(() => {
  466. be($, (h) => {
  467. var I;
  468. for (let s = 0; s < h.length; s += 1) {
  469. const S = h.slice(0, s + 1), m = ee(S), V = (I = i.value) === null || I === void 0 ? void 0 : I.querySelector(`li[data-path-key="${m.replace(/\\{0,2}"/g, '\\"')}"]`);
  470. V && It(V);
  471. }
  472. }, {
  473. flush: "post",
  474. immediate: !0
  475. });
  476. }), () => {
  477. var h, I, s, S, m;
  478. const {
  479. notFoundContent: V = ((h = n.notFoundContent) === null || h === void 0 ? void 0 : h.call(n)) || ((s = (I = p.value).notFoundContent) === null || s === void 0 ? void 0 : s.call(I)),
  480. multiple: K,
  481. toggleOpen: j
  482. } = l, H = !(!((m = (S = W.value[0]) === null || S === void 0 ? void 0 : S.options) === null || m === void 0) && m.length), Y = [{
  483. [o.value.value]: "__EMPTY__",
  484. [Le]: V,
  485. disabled: !0
  486. }], ne = k(k({}, t), {
  487. multiple: !H && K,
  488. onSelect: M,
  489. onActive: Q,
  490. onToggleOpen: j,
  491. checkedSet: _.value,
  492. halfCheckedSet: N.value,
  493. loadingKeys: E.value,
  494. isSelectable: G
  495. }), B = (H ? [{
  496. options: Y
  497. }] : W.value).map((q, u) => {
  498. const f = $.value.slice(0, u), A = $.value[u];
  499. return T(ge, Z(Z({
  500. key: u
  501. }, ne), {}, {
  502. prefixCls: w.value,
  503. options: q.options,
  504. prevValuePath: f,
  505. activeValue: A
  506. }), null);
  507. });
  508. return T("div", {
  509. class: [`${w.value}-menus`, {
  510. [`${w.value}-menu-empty`]: H,
  511. [`${w.value}-rtl`]: r.value
  512. }],
  513. onMousedown: R,
  514. ref: i
  515. }, [B]);
  516. };
  517. }
  518. });
  519. function Rt() {
  520. return k(k({}, Ie(Ze(), ["tokenSeparators", "mode", "showSearch"])), {
  521. // MISC
  522. id: String,
  523. prefixCls: String,
  524. fieldNames: et(),
  525. children: Array,
  526. // Value
  527. value: {
  528. type: [String, Number, Array]
  529. },
  530. defaultValue: {
  531. type: [String, Number, Array]
  532. },
  533. changeOnSelect: {
  534. type: Boolean,
  535. default: void 0
  536. },
  537. displayRender: Function,
  538. checkable: {
  539. type: Boolean,
  540. default: void 0
  541. },
  542. showCheckedStrategy: {
  543. type: String,
  544. default: $e
  545. },
  546. // Search
  547. showSearch: {
  548. type: [Boolean, Object],
  549. default: void 0
  550. },
  551. searchValue: String,
  552. onSearch: Function,
  553. // Trigger
  554. expandTrigger: String,
  555. // Options
  556. options: Array,
  557. /** @private Internal usage. Do not use in your production. */
  558. dropdownPrefixCls: String,
  559. loadData: Function,
  560. // Open
  561. /** @deprecated Use `open` instead */
  562. popupVisible: {
  563. type: Boolean,
  564. default: void 0
  565. },
  566. dropdownClassName: String,
  567. dropdownMenuColumnStyle: {
  568. type: Object,
  569. default: void 0
  570. },
  571. /** @deprecated Use `dropdownStyle` instead */
  572. popupStyle: {
  573. type: Object,
  574. default: void 0
  575. },
  576. dropdownStyle: {
  577. type: Object,
  578. default: void 0
  579. },
  580. /** @deprecated Use `placement` instead */
  581. popupPlacement: String,
  582. placement: String,
  583. /** @deprecated Use `onDropdownVisibleChange` instead */
  584. onPopupVisibleChange: Function,
  585. onDropdownVisibleChange: Function,
  586. // Icon
  587. expandIcon: ye.any,
  588. loadingIcon: ye.any
  589. });
  590. }
  591. function Ke() {
  592. return k(k({}, Rt()), {
  593. onChange: Function,
  594. customSlots: Object
  595. });
  596. }
  597. function Lt(e) {
  598. return Array.isArray(e) && Array.isArray(e[0]);
  599. }
  600. function Ae(e) {
  601. return e ? Lt(e) ? e : (e.length === 0 ? [] : [e]).map((a) => Array.isArray(a) ? a : [a]) : [];
  602. }
  603. const Kt = xe({
  604. compatConfig: {
  605. MODE: 3
  606. },
  607. name: "Cascader",
  608. inheritAttrs: !1,
  609. props: De(Ke(), {}),
  610. setup(e, a) {
  611. let {
  612. attrs: t,
  613. expose: n,
  614. slots: l
  615. } = a;
  616. const i = Qe(pe(e, "id")), r = y(() => !!e.checkable), [d, v] = Ve(e.defaultValue, {
  617. value: y(() => e.value),
  618. postState: Ae
  619. }), c = y(() => wt(e.fieldNames)), o = y(() => e.options || []), C = Ot(o, c), O = (u) => {
  620. const f = C.value;
  621. return u.map((A) => {
  622. const {
  623. nodes: L
  624. } = f[A];
  625. return L.map((z) => z[c.value.value]);
  626. });
  627. }, [b, D] = Ve("", {
  628. value: y(() => e.searchValue),
  629. postState: (u) => u || ""
  630. }), g = (u, f) => {
  631. D(u), f.source !== "blur" && e.onSearch && e.onSearch(u);
  632. }, {
  633. showSearch: x,
  634. searchConfig: p
  635. } = Pt(pe(e, "showSearch")), w = _t(b, o, c, y(() => e.dropdownPrefixCls || e.prefixCls), p, pe(e, "changeOnSelect")), E = At(o, c, d), [P, _, N] = [X([]), X([]), X([])], {
  636. maxLevel: $,
  637. levelEntities: U
  638. } = bt(C);
  639. ie(() => {
  640. const [u, f] = E.value;
  641. if (!r.value || !d.value.length) {
  642. [P.value, _.value, N.value] = [u, [], f];
  643. return;
  644. }
  645. const A = se(u), L = C.value, {
  646. checkedKeys: z,
  647. halfCheckedKeys: re
  648. } = Ce(A, !0, L, $.value, U.value);
  649. [P.value, _.value, N.value] = [O(z), O(re), f];
  650. });
  651. const Q = y(() => {
  652. const u = se(P.value), f = _e(u, C.value, e.showCheckedStrategy);
  653. return [...N.value, ...O(f)];
  654. }), G = Et(Q, o, c, r, pe(e, "displayRender")), M = (u) => {
  655. if (v(u), e.onChange) {
  656. const f = Ae(u), A = f.map((re) => de(re, o.value, c.value).map((ve) => ve.option)), L = r.value ? f : f[0], z = r.value ? A : A[0];
  657. e.onChange(L, z);
  658. }
  659. }, F = (u) => {
  660. if (D(""), !r.value)
  661. M(u);
  662. else {
  663. const f = ee(u), A = se(P.value), L = se(_.value), z = A.includes(f), re = N.value.some((ae) => ee(ae) === f);
  664. let ve = P.value, Pe = N.value;
  665. if (re && !z)
  666. Pe = N.value.filter((ae) => ee(ae) !== f);
  667. else {
  668. const ae = z ? A.filter((Fe) => Fe !== f) : [...A, f];
  669. let me;
  670. z ? {
  671. checkedKeys: me
  672. } = Ce(ae, {
  673. checked: !1,
  674. halfCheckedKeys: L
  675. }, C.value, $.value, U.value) : {
  676. checkedKeys: me
  677. } = Ce(ae, !0, C.value, $.value, U.value);
  678. const Me = _e(me, C.value, e.showCheckedStrategy);
  679. ve = O(Me);
  680. }
  681. M([...Pe, ...ve]);
  682. }
  683. }, W = (u, f) => {
  684. if (f.type === "clear") {
  685. M([]);
  686. return;
  687. }
  688. const {
  689. valueCells: A
  690. } = f.values[0];
  691. F(A);
  692. };
  693. process.env.NODE_ENV !== "production" && ie(() => {
  694. oe(!e.onPopupVisibleChange, "Cascader", "`popupVisibleChange` is deprecated. Please use `dropdownVisibleChange` instead."), oe(e.popupVisible === void 0, "Cascader", "`popupVisible` is deprecated. Please use `open` instead."), oe(e.popupPlacement === void 0, "Cascader", "`popupPlacement` is deprecated. Please use `placement` instead."), oe(e.popupStyle === void 0, "Cascader", "`popupStyle` is deprecated. Please use `dropdownStyle` instead.");
  695. });
  696. const te = y(() => e.open !== void 0 ? e.open : e.popupVisible), R = y(() => e.dropdownStyle || e.popupStyle || {}), h = y(() => e.placement || e.popupPlacement), I = (u) => {
  697. var f, A;
  698. (f = e.onDropdownVisibleChange) === null || f === void 0 || f.call(e, u), (A = e.onPopupVisibleChange) === null || A === void 0 || A.call(e, u);
  699. }, {
  700. changeOnSelect: s,
  701. checkable: S,
  702. dropdownPrefixCls: m,
  703. loadData: V,
  704. expandTrigger: K,
  705. expandIcon: j,
  706. loadingIcon: H,
  707. dropdownMenuColumnStyle: Y,
  708. customSlots: ne,
  709. dropdownClassName: le
  710. } = Be(e);
  711. Tt({
  712. options: o,
  713. fieldNames: c,
  714. values: P,
  715. halfValues: _,
  716. changeOnSelect: s,
  717. onSelect: F,
  718. checkable: S,
  719. searchOptions: w,
  720. dropdownPrefixCls: m,
  721. loadData: V,
  722. expandTrigger: K,
  723. expandIcon: j,
  724. loadingIcon: H,
  725. dropdownMenuColumnStyle: Y,
  726. customSlots: ne
  727. });
  728. const B = X();
  729. n({
  730. focus() {
  731. var u;
  732. (u = B.value) === null || u === void 0 || u.focus();
  733. },
  734. blur() {
  735. var u;
  736. (u = B.value) === null || u === void 0 || u.blur();
  737. },
  738. scrollTo(u) {
  739. var f;
  740. (f = B.value) === null || f === void 0 || f.scrollTo(u);
  741. }
  742. });
  743. const q = y(() => Ie(e, [
  744. "id",
  745. "prefixCls",
  746. "fieldNames",
  747. // Value
  748. "defaultValue",
  749. "value",
  750. "changeOnSelect",
  751. "onChange",
  752. "displayRender",
  753. "checkable",
  754. // Search
  755. "searchValue",
  756. "onSearch",
  757. "showSearch",
  758. // Trigger
  759. "expandTrigger",
  760. // Options
  761. "options",
  762. "dropdownPrefixCls",
  763. "loadData",
  764. // Open
  765. "popupVisible",
  766. "open",
  767. "dropdownClassName",
  768. "dropdownMenuColumnStyle",
  769. "popupPlacement",
  770. "placement",
  771. "onDropdownVisibleChange",
  772. "onPopupVisibleChange",
  773. // Icon
  774. "expandIcon",
  775. "loadingIcon",
  776. "customSlots",
  777. "showCheckedStrategy",
  778. // Children
  779. "children"
  780. ]));
  781. return () => {
  782. const u = !(b.value ? w.value : o.value).length, {
  783. dropdownMatchSelectWidth: f = !1
  784. } = e, A = (
  785. // Search to match width
  786. b.value && p.value.matchInputWidth || // Empty keep the width
  787. u ? {} : {
  788. minWidth: "auto"
  789. }
  790. );
  791. return T(Ye, Z(Z(Z({}, q.value), t), {}, {
  792. ref: B,
  793. id: i,
  794. prefixCls: e.prefixCls,
  795. dropdownMatchSelectWidth: f,
  796. dropdownStyle: k(k({}, R.value), A),
  797. displayValues: G.value,
  798. onDisplayValuesChange: W,
  799. mode: r.value ? "multiple" : void 0,
  800. searchValue: b.value,
  801. onSearch: g,
  802. showSearch: x.value,
  803. OptionList: Nt,
  804. emptyOptions: u,
  805. open: te.value,
  806. dropdownClassName: le.value,
  807. placement: h.value,
  808. onDropdownVisibleChange: I,
  809. getRawInputElement: () => {
  810. var L;
  811. return (L = l.default) === null || L === void 0 ? void 0 : L.call(l);
  812. }
  813. }), l);
  814. };
  815. }
  816. }), Mt = (e) => {
  817. const {
  818. prefixCls: a,
  819. componentCls: t,
  820. antCls: n
  821. } = e, l = `${t}-menu-item`, i = `
  822. &${l}-expand ${l}-expand-icon,
  823. ${l}-loading-icon
  824. `, r = Math.round((e.controlHeight - e.fontSize * e.lineHeight) / 2);
  825. return [
  826. // =====================================================
  827. // == Control ==
  828. // =====================================================
  829. {
  830. [t]: {
  831. width: e.controlWidth
  832. }
  833. },
  834. // =====================================================
  835. // == Popup ==
  836. // =====================================================
  837. {
  838. [`${t}-dropdown`]: [
  839. // ==================== Checkbox ====================
  840. nt(`${a}-checkbox`, e),
  841. {
  842. [`&${n}-select-dropdown`]: {
  843. padding: 0
  844. }
  845. },
  846. {
  847. [t]: {
  848. // ================== Checkbox ==================
  849. "&-checkbox": {
  850. top: 0,
  851. marginInlineEnd: e.paddingXS
  852. },
  853. // ==================== Menu ====================
  854. // >>> Menus
  855. "&-menus": {
  856. display: "flex",
  857. flexWrap: "nowrap",
  858. alignItems: "flex-start",
  859. [`&${t}-menu-empty`]: {
  860. [`${t}-menu`]: {
  861. width: "100%",
  862. height: "auto",
  863. [l]: {
  864. color: e.colorTextDisabled
  865. }
  866. }
  867. }
  868. },
  869. // >>> Menu
  870. "&-menu": {
  871. flexGrow: 1,
  872. minWidth: e.controlItemWidth,
  873. height: e.dropdownHeight,
  874. margin: 0,
  875. padding: e.paddingXXS,
  876. overflow: "auto",
  877. verticalAlign: "top",
  878. listStyle: "none",
  879. "-ms-overflow-style": "-ms-autohiding-scrollbar",
  880. "&:not(:last-child)": {
  881. borderInlineEnd: `${e.lineWidth}px ${e.lineType} ${e.colorSplit}`
  882. },
  883. "&-item": k(k({}, lt), {
  884. display: "flex",
  885. flexWrap: "nowrap",
  886. alignItems: "center",
  887. padding: `${r}px ${e.paddingSM}px`,
  888. lineHeight: e.lineHeight,
  889. cursor: "pointer",
  890. transition: `all ${e.motionDurationMid}`,
  891. borderRadius: e.borderRadiusSM,
  892. "&:hover": {
  893. background: e.controlItemBgHover
  894. },
  895. "&-disabled": {
  896. color: e.colorTextDisabled,
  897. cursor: "not-allowed",
  898. "&:hover": {
  899. background: "transparent"
  900. },
  901. [i]: {
  902. color: e.colorTextDisabled
  903. }
  904. },
  905. [`&-active:not(${l}-disabled)`]: {
  906. "&, &:hover": {
  907. fontWeight: e.fontWeightStrong,
  908. backgroundColor: e.controlItemBgActive
  909. }
  910. },
  911. "&-content": {
  912. flex: "auto"
  913. },
  914. [i]: {
  915. marginInlineStart: e.paddingXXS,
  916. color: e.colorTextDescription,
  917. fontSize: e.fontSizeIcon
  918. },
  919. "&-keyword": {
  920. color: e.colorHighlight
  921. }
  922. })
  923. }
  924. }
  925. }
  926. ]
  927. },
  928. // =====================================================
  929. // == RTL ==
  930. // =====================================================
  931. {
  932. [`${t}-dropdown-rtl`]: {
  933. direction: "rtl"
  934. }
  935. },
  936. // =====================================================
  937. // == Space Compact ==
  938. // =====================================================
  939. at(e)
  940. ];
  941. }, Ft = tt("Cascader", (e) => [Mt(e)], {
  942. controlWidth: 184,
  943. controlItemWidth: 111,
  944. dropdownHeight: 180
  945. });
  946. var Wt = function(e, a) {
  947. var t = {};
  948. for (var n in e) Object.prototype.hasOwnProperty.call(e, n) && a.indexOf(n) < 0 && (t[n] = e[n]);
  949. if (e != null && typeof Object.getOwnPropertySymbols == "function") for (var l = 0, n = Object.getOwnPropertySymbols(e); l < n.length; l++)
  950. a.indexOf(n[l]) < 0 && Object.prototype.propertyIsEnumerable.call(e, n[l]) && (t[n[l]] = e[n[l]]);
  951. return t;
  952. };
  953. function jt(e, a, t) {
  954. const n = e.toLowerCase().split(a).reduce((r, d, v) => v === 0 ? [d] : [...r, a, d], []), l = [];
  955. let i = 0;
  956. return n.forEach((r, d) => {
  957. const v = i + r.length;
  958. let c = e.slice(i, v);
  959. i = v, d % 2 === 1 && (c = T("span", {
  960. class: `${t}-menu-item-keyword`,
  961. key: "seperator"
  962. }, [c])), l.push(c);
  963. }), l;
  964. }
  965. const Ht = (e) => {
  966. let {
  967. inputValue: a,
  968. path: t,
  969. prefixCls: n,
  970. fieldNames: l
  971. } = e;
  972. const i = [], r = a.toLowerCase();
  973. return t.forEach((d, v) => {
  974. v !== 0 && i.push(" / ");
  975. let c = d[l.label];
  976. const o = typeof c;
  977. (o === "string" || o === "number") && (c = jt(String(c), r, n)), i.push(c);
  978. }), i;
  979. };
  980. function Bt() {
  981. return k(k({}, Ie(Ke(), ["customSlots", "checkable", "options"])), {
  982. multiple: {
  983. type: Boolean,
  984. default: void 0
  985. },
  986. size: String,
  987. bordered: {
  988. type: Boolean,
  989. default: void 0
  990. },
  991. placement: {
  992. type: String
  993. },
  994. suffixIcon: ye.any,
  995. status: String,
  996. options: Array,
  997. popupClassName: String,
  998. /** @deprecated Please use `popupClassName` instead */
  999. dropdownClassName: String,
  1000. "onUpdate:value": Function
  1001. });
  1002. }
  1003. const zt = xe({
  1004. compatConfig: {
  1005. MODE: 3
  1006. },
  1007. name: "ACascader",
  1008. inheritAttrs: !1,
  1009. props: De(Bt(), {
  1010. bordered: !0,
  1011. choiceTransitionName: "",
  1012. allowClear: !0
  1013. }),
  1014. setup(e, a) {
  1015. let {
  1016. attrs: t,
  1017. expose: n,
  1018. slots: l,
  1019. emit: i
  1020. } = a;
  1021. process.env.NODE_ENV !== "production" && oe(!e.dropdownClassName, "Cascader", "`dropdownClassName` is deprecated. Please use `popupClassName` instead.");
  1022. const r = st(), d = it.useInject(), v = y(() => rt(d.status, e.status)), {
  1023. prefixCls: c,
  1024. rootPrefixCls: o,
  1025. getPrefixCls: C,
  1026. direction: O,
  1027. getPopupContainer: b,
  1028. renderEmpty: D,
  1029. size: g,
  1030. disabled: x
  1031. } = ct("cascader", e), p = y(() => C("select", e.prefixCls)), {
  1032. compactSize: w,
  1033. compactItemClassnames: E
  1034. } = ut(p, O), P = y(() => w.value || g.value), _ = dt(), N = y(() => {
  1035. var s;
  1036. return (s = x.value) !== null && s !== void 0 ? s : _.value;
  1037. }), [$, U] = vt(p), [Q] = Ft(c), G = y(() => O.value === "rtl");
  1038. process.env.NODE_ENV !== "production" && ie(() => {
  1039. oe(!e.multiple || !e.displayRender || !l.displayRender, "Cascader", "`displayRender` not work on `multiple`. Please use `tagRender` instead.");
  1040. });
  1041. const M = y(() => {
  1042. if (!e.showSearch)
  1043. return e.showSearch;
  1044. let s = {
  1045. render: Ht
  1046. };
  1047. return typeof e.showSearch == "object" && (s = k(k({}, s), e.showSearch)), s;
  1048. }), F = y(() => pt(e.popupClassName || e.dropdownClassName, `${c.value}-dropdown`, {
  1049. [`${c.value}-dropdown-rtl`]: G.value
  1050. }, U.value)), W = X();
  1051. n({
  1052. focus() {
  1053. var s;
  1054. (s = W.value) === null || s === void 0 || s.focus();
  1055. },
  1056. blur() {
  1057. var s;
  1058. (s = W.value) === null || s === void 0 || s.blur();
  1059. }
  1060. });
  1061. const te = function() {
  1062. for (var s = arguments.length, S = new Array(s), m = 0; m < s; m++)
  1063. S[m] = arguments[m];
  1064. i("update:value", S[0]), i("change", ...S), r.onFieldChange();
  1065. }, R = function() {
  1066. for (var s = arguments.length, S = new Array(s), m = 0; m < s; m++)
  1067. S[m] = arguments[m];
  1068. i("blur", ...S), r.onFieldBlur();
  1069. }, h = y(() => e.showArrow !== void 0 ? e.showArrow : e.loading || !e.multiple), I = y(() => e.placement !== void 0 ? e.placement : O.value === "rtl" ? "bottomRight" : "bottomLeft");
  1070. return () => {
  1071. var s, S;
  1072. const {
  1073. notFoundContent: m = (s = l.notFoundContent) === null || s === void 0 ? void 0 : s.call(l),
  1074. expandIcon: V = (S = l.expandIcon) === null || S === void 0 ? void 0 : S.call(l),
  1075. multiple: K,
  1076. bordered: j,
  1077. allowClear: H,
  1078. choiceTransitionName: Y,
  1079. transitionName: ne,
  1080. id: le = r.id.value
  1081. } = e, B = Wt(e, ["notFoundContent", "expandIcon", "multiple", "bordered", "allowClear", "choiceTransitionName", "transitionName", "id"]), q = m || D("Cascader");
  1082. let u = V;
  1083. V || (u = G.value ? T(ht, null, null) : T(ft, null, null));
  1084. const f = T("span", {
  1085. class: `${p.value}-menu-item-loading-icon`
  1086. }, [T(gt, {
  1087. spin: !0
  1088. }, null)]), {
  1089. suffixIcon: A,
  1090. removeIcon: L,
  1091. clearIcon: z
  1092. } = mt(k(k({}, e), {
  1093. hasFeedback: d.hasFeedback,
  1094. feedbackIcon: d.feedbackIcon,
  1095. multiple: K,
  1096. prefixCls: p.value,
  1097. showArrow: h.value
  1098. }), l);
  1099. return Q($(T(Kt, Z(Z(Z({}, B), t), {}, {
  1100. id: le,
  1101. prefixCls: p.value,
  1102. class: [c.value, {
  1103. [`${p.value}-lg`]: P.value === "large",
  1104. [`${p.value}-sm`]: P.value === "small",
  1105. [`${p.value}-rtl`]: G.value,
  1106. [`${p.value}-borderless`]: !j,
  1107. [`${p.value}-in-form-item`]: d.isFormItemInput
  1108. }, Ct(p.value, v.value, d.hasFeedback), E.value, t.class, U.value],
  1109. disabled: N.value,
  1110. direction: O.value,
  1111. placement: I.value,
  1112. notFoundContent: q,
  1113. allowClear: H,
  1114. showSearch: M.value,
  1115. expandIcon: u,
  1116. inputIcon: A,
  1117. removeIcon: L,
  1118. clearIcon: z,
  1119. loadingIcon: f,
  1120. checkable: !!K,
  1121. dropdownClassName: F.value,
  1122. dropdownPrefixCls: c.value,
  1123. choiceTransitionName: ke(o.value, "", Y),
  1124. transitionName: ke(o.value, St(I.value), ne),
  1125. getPopupContainer: b == null ? void 0 : b.value,
  1126. customSlots: k(k({}, l), {
  1127. checkable: () => T("span", {
  1128. class: `${c.value}-checkbox-inner`
  1129. }, null)
  1130. }),
  1131. tagRender: e.tagRender || l.tagRender,
  1132. displayRender: e.displayRender || l.displayRender,
  1133. maxTagPlaceholder: e.maxTagPlaceholder || l.maxTagPlaceholder,
  1134. showArrow: d.hasFeedback || e.showArrow,
  1135. onChange: te,
  1136. onBlur: R,
  1137. ref: W
  1138. }), l)));
  1139. };
  1140. }
  1141. }), Ee = ot(k(zt, {
  1142. SHOW_CHILD: Ne,
  1143. SHOW_PARENT: $e
  1144. })), Xt = { class: "s-cascader-common" }, Jt = {
  1145. __name: "SCascader",
  1146. props: {
  1147. // 支持清空
  1148. clear: {
  1149. type: Boolean,
  1150. default: !0
  1151. },
  1152. // 默认选中项,支持 v-model 双向绑定
  1153. modelValue: {
  1154. type: [String, Array],
  1155. default() {
  1156. return "";
  1157. }
  1158. },
  1159. // 占位符 - 文案提示
  1160. placeholder: {
  1161. type: String,
  1162. default() {
  1163. return window.$l("请选择");
  1164. }
  1165. },
  1166. // 树节点数据
  1167. options: {
  1168. type: Array,
  1169. default() {
  1170. return [];
  1171. }
  1172. },
  1173. // 禁用
  1174. disabled: {
  1175. type: Boolean,
  1176. default: !1
  1177. },
  1178. // 菜单展开方式
  1179. expandTrigger: {
  1180. type: String,
  1181. default: "click"
  1182. },
  1183. // options 配字段置项
  1184. fieldNames: {
  1185. type: Object,
  1186. default() {
  1187. return {
  1188. label: "name",
  1189. value: "value",
  1190. children: "children"
  1191. };
  1192. }
  1193. },
  1194. // 显示数量
  1195. maxTagCount: {
  1196. type: Number,
  1197. default: 1
  1198. },
  1199. // 多选
  1200. multiple: {
  1201. type: Boolean,
  1202. default: !0
  1203. }
  1204. },
  1205. setup(e) {
  1206. const a = e, t = X("");
  1207. return be(() => a.modelValue, (n) => {
  1208. n != null && n.length && (t.value = n);
  1209. }, { immediate: !0 }), (n, l) => {
  1210. const i = Ee;
  1211. return ze(), Xe("div", Xt, [
  1212. T(i, {
  1213. options: e.options,
  1214. allowClear: e.clear,
  1215. disabled: e.disabled,
  1216. multiple: e.multiple,
  1217. fieldNames: e.fieldNames,
  1218. maxTagCount: e.maxTagCount,
  1219. placeholder: e.placeholder,
  1220. value: t.value,
  1221. "onUpdate:value": l[0] || (l[0] = (r) => t.value = r),
  1222. expandTrigger: e.expandTrigger,
  1223. showCheckedStrategy: Ue(Ee).SHOW_CHILD,
  1224. style: { width: "100%" }
  1225. }, null, 8, ["options", "allowClear", "disabled", "multiple", "fieldNames", "maxTagCount", "placeholder", "value", "expandTrigger", "showCheckedStrategy"])
  1226. ]);
  1227. };
  1228. }
  1229. };
  1230. export {
  1231. Jt as default
  1232. };