SCascader.js 35 KB

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