SCascader.js 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232
  1. import { computed as y, shallowRef as Ee, ref as X, watchEffect as ie, provide as Fe, inject as We, watch as be, createVNode as T, defineComponent as xe, onMounted as je, toRef as pe, toRefs as He, openBlock as Be, createElementBlock as ze, unref as Xe } from "vue";
  2. import { Cascader as Ue } from "ant-design-vue";
  3. import { A as Ge, d as k, D as Ye, E as qe, F as Se, G as we, H as Je, K as q, _ as Z, J as Qe, L as Ve, M as Ze, N as Ce, h as oe, o as Ie, O as et, i as Te, Q as tt, P as ye, e as nt, g as lt, S as at, t as ot, T as st, b as it, U as rt, V as ct, W as ut, u as dt, X as vt, Y as pt, Z as ht, c as ft, $ as gt, a0 as mt, a1 as Ct, a2 as St, a3 as ke, a4 as yt, a5 as bt } from "./index2.js";
  4. import "./index5.js";
  5. const Oe = "__RC_CASCADER_SPLIT__", $e = "SHOW_PARENT", De = "SHOW_CHILD";
  6. function ee(e) {
  7. return e.join(Oe);
  8. }
  9. function se(e) {
  10. return e.map(ee);
  11. }
  12. function xt(e) {
  13. return e.split(Oe);
  14. }
  15. function wt(e) {
  16. const {
  17. label: a,
  18. value: t,
  19. children: n
  20. } = e || {}, l = t || "value";
  21. return {
  22. label: a || "label",
  23. value: l,
  24. key: l,
  25. children: n || "children"
  26. };
  27. }
  28. function ce(e, a) {
  29. var t, n;
  30. return (t = e.isLeaf) !== null && t !== void 0 ? t : !(!((n = e[a.children]) === null || n === void 0) && n.length);
  31. }
  32. function It(e) {
  33. const a = e.parentElement;
  34. if (!a)
  35. return;
  36. const t = e.offsetTop - a.offsetTop;
  37. t - a.scrollTop < 0 ? a.scrollTo({
  38. top: t
  39. }) : t + e.offsetHeight - a.scrollTop > a.offsetHeight && a.scrollTo({
  40. top: t + e.offsetHeight - a.offsetHeight
  41. });
  42. }
  43. const Ot = (e, a) => y(() => Ge(e.value, {
  44. fieldNames: a.value,
  45. initWrapper: (n) => k(k({}, n), {
  46. pathKeyEntities: {}
  47. }),
  48. processEntity: (n, l) => {
  49. const i = n.nodes.map((r) => r[a.value.value]).join(Oe);
  50. l.pathKeyEntities[i] = n, n.key = i;
  51. }
  52. }).pathKeyEntities);
  53. function Pt(e) {
  54. const a = Ee(!1), t = X({});
  55. return ie(() => {
  56. if (!e.value) {
  57. a.value = !1, t.value = {};
  58. return;
  59. }
  60. let n = {
  61. matchInputWidth: !0,
  62. limit: 50
  63. };
  64. e.value && typeof e.value == "object" && (n = k(k({}, n), e.value)), n.limit <= 0 && (delete n.limit, process.env.NODE_ENV !== "production" && Ye(!1, "'limit' of showSearch should be positive number or false.")), a.value = !0, t.value = n;
  65. }), {
  66. showSearch: a,
  67. searchConfig: t
  68. };
  69. }
  70. const ue = "__rc_cascader_search_mark__", Vt = (e, a, t) => {
  71. let {
  72. label: n
  73. } = t;
  74. return a.some((l) => String(l[n]).toLowerCase().includes(e.toLowerCase()));
  75. }, kt = (e) => {
  76. let {
  77. path: a,
  78. fieldNames: t
  79. } = e;
  80. return a.map((n) => n[t.label]).join(" / ");
  81. }, _t = (e, a, t, n, l, i) => y(() => {
  82. const {
  83. filter: r = Vt,
  84. render: d = kt,
  85. limit: v = 50,
  86. sort: c
  87. } = l.value, o = [];
  88. if (!e.value)
  89. return [];
  90. function C(O, b) {
  91. O.forEach(($) => {
  92. if (!c && v > 0 && o.length >= v)
  93. return;
  94. const g = [...b, $], x = $[t.value.children];
  95. // If is leaf option
  96. (!x || x.length === 0 || // If is changeOnSelect
  97. i.value) && r(e.value, g, {
  98. label: t.value.label
  99. }) && o.push(k(k({}, $), {
  100. [t.value.label]: d({
  101. inputValue: e.value,
  102. path: g,
  103. prefixCls: n.value,
  104. fieldNames: t.value
  105. }),
  106. [ue]: g
  107. })), x && C($[t.value.children], g);
  108. });
  109. }
  110. 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;
  111. });
  112. function _e(e, a, t) {
  113. const n = new Set(e);
  114. return e.filter((l) => {
  115. const i = a[l], r = i ? i.parent : null, d = i ? i.children : null;
  116. return t === De ? !(d && d.some((v) => v.key && n.has(v.key))) : !(r && !r.node.disabled && n.has(r.key));
  117. });
  118. }
  119. function de(e, a, t) {
  120. let n = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : !1;
  121. var l;
  122. let i = a;
  123. const r = [];
  124. for (let d = 0; d < e.length; d += 1) {
  125. const v = e[d], c = i == null ? void 0 : i.findIndex((C) => {
  126. const O = C[t.value];
  127. return n ? String(O) === String(v) : O === v;
  128. }), o = c !== -1 ? i == null ? void 0 : i[c] : null;
  129. r.push({
  130. value: (l = o == null ? void 0 : o[t.value]) !== null && l !== void 0 ? l : v,
  131. index: c,
  132. option: o
  133. }), i = o == null ? void 0 : o[t.children];
  134. }
  135. return r;
  136. }
  137. const At = (e, a, t) => y(() => {
  138. const n = [], l = [];
  139. return t.value.forEach((i) => {
  140. de(i, e.value, a.value).every((d) => d.option) ? l.push(i) : n.push(i);
  141. }), [l, n];
  142. }), Et = (e, a, t, n, l) => y(() => {
  143. const i = l.value || // Default displayRender
  144. ((r) => {
  145. let {
  146. labels: d
  147. } = r;
  148. const v = n.value ? d.slice(-1) : d, c = " / ";
  149. return v.every((o) => ["string", "number"].includes(typeof o)) ? v.join(c) : v.reduce((o, C, O) => {
  150. const b = qe(C) ? Se(C, {
  151. key: O
  152. }) : C;
  153. return O === 0 ? [b] : [...o, c, b];
  154. }, []);
  155. });
  156. return e.value.map((r) => {
  157. const d = de(r, a.value, t.value), v = i({
  158. labels: d.map((o) => {
  159. let {
  160. option: C,
  161. value: O
  162. } = o;
  163. var b;
  164. return (b = C == null ? void 0 : C[t.value.label]) !== null && b !== void 0 ? b : O;
  165. }),
  166. selectedOptions: d.map((o) => {
  167. let {
  168. option: C
  169. } = o;
  170. return C;
  171. })
  172. }), c = ee(r);
  173. return {
  174. label: v,
  175. value: c,
  176. key: c,
  177. valueCells: r
  178. };
  179. });
  180. }), Ne = Symbol("CascaderContextKey"), Tt = (e) => {
  181. Fe(Ne, e);
  182. }, he = () => We(Ne), $t = () => {
  183. const e = we(), {
  184. values: a
  185. } = he(), [t, n] = Je([]);
  186. return be(() => e.open, () => {
  187. if (e.open && !e.multiple) {
  188. const l = a.value[0];
  189. n(l || []);
  190. }
  191. }, {
  192. immediate: !0
  193. }), [t, n];
  194. }, Dt = (e, a, t, n, l, i) => {
  195. const r = we(), d = y(() => r.direction === "rtl"), [v, c, o] = [X([]), X(), X([])];
  196. ie(() => {
  197. let g = -1, x = a.value;
  198. const p = [], w = [], E = n.value.length;
  199. for (let _ = 0; _ < E && x; _ += 1) {
  200. const N = x.findIndex((D) => D[t.value.value] === n.value[_]);
  201. if (N === -1)
  202. break;
  203. g = N, p.push(g), w.push(n.value[_]), x = x[g][t.value.children];
  204. }
  205. let P = a.value;
  206. for (let _ = 0; _ < p.length - 1; _ += 1)
  207. P = P[p[_]][t.value.children];
  208. [v.value, c.value, o.value] = [w, g, P];
  209. });
  210. const C = (g) => {
  211. l(g);
  212. }, O = (g) => {
  213. const x = o.value.length;
  214. let p = c.value;
  215. p === -1 && g < 0 && (p = x);
  216. for (let w = 0; w < x; w += 1) {
  217. p = (p + g + x) % x;
  218. const E = o.value[p];
  219. if (E && !E.disabled) {
  220. const P = E[t.value.value], _ = v.value.slice(0, -1).concat(P);
  221. C(_);
  222. return;
  223. }
  224. }
  225. }, b = () => {
  226. if (v.value.length > 1) {
  227. const g = v.value.slice(0, -1);
  228. C(g);
  229. } else
  230. r.toggleOpen(!1);
  231. }, $ = () => {
  232. var g;
  233. const p = (((g = o.value[c.value]) === null || g === void 0 ? void 0 : g[t.value.children]) || []).find((w) => !w.disabled);
  234. if (p) {
  235. const w = [...v.value, p[t.value.value]];
  236. C(w);
  237. }
  238. };
  239. e.expose({
  240. // scrollTo: treeRef.current?.scrollTo,
  241. onKeydown: (g) => {
  242. const {
  243. which: x
  244. } = g;
  245. switch (x) {
  246. case q.UP:
  247. case q.DOWN: {
  248. let p = 0;
  249. x === q.UP ? p = -1 : x === q.DOWN && (p = 1), p !== 0 && O(p);
  250. break;
  251. }
  252. case q.LEFT: {
  253. d.value ? $() : b();
  254. break;
  255. }
  256. case q.RIGHT: {
  257. d.value ? b() : $();
  258. break;
  259. }
  260. case q.BACKSPACE: {
  261. r.searchValue || b();
  262. break;
  263. }
  264. case q.ENTER: {
  265. if (v.value.length) {
  266. const p = o.value[c.value], w = (p == null ? void 0 : p[ue]) || [];
  267. w.length ? i(w.map((E) => E[t.value.value]), w[w.length - 1]) : i(v.value, p);
  268. }
  269. break;
  270. }
  271. case q.ESC:
  272. r.toggleOpen(!1), open && g.stopPropagation();
  273. }
  274. },
  275. onKeyup: () => {
  276. }
  277. });
  278. };
  279. function fe(e) {
  280. let {
  281. prefixCls: a,
  282. checked: t,
  283. halfChecked: n,
  284. disabled: l,
  285. onClick: i
  286. } = e;
  287. const {
  288. customSlots: r,
  289. checkable: d
  290. } = he(), v = d.value !== !1 ? r.value.checkable : d.value, c = typeof v == "function" ? v() : typeof v == "boolean" ? null : v;
  291. return T("span", {
  292. class: {
  293. [a]: !0,
  294. [`${a}-checked`]: t,
  295. [`${a}-indeterminate`]: !t && n,
  296. [`${a}-disabled`]: l
  297. },
  298. onClick: i
  299. }, [c]);
  300. }
  301. fe.props = ["prefixCls", "checked", "halfChecked", "disabled", "onClick"];
  302. fe.displayName = "Checkbox";
  303. fe.inheritAttrs = !1;
  304. const Re = "__cascader_fix_label__";
  305. function ge(e) {
  306. let {
  307. prefixCls: a,
  308. multiple: t,
  309. options: n,
  310. activeValue: l,
  311. prevValuePath: i,
  312. onToggleOpen: r,
  313. onSelect: d,
  314. onActive: v,
  315. checkedSet: c,
  316. halfCheckedSet: o,
  317. loadingKeys: C,
  318. isSelectable: O
  319. } = e;
  320. var b, $, g, x, p, w;
  321. const E = `${a}-menu`, P = `${a}-menu-item`, {
  322. fieldNames: _,
  323. changeOnSelect: N,
  324. expandTrigger: D,
  325. expandIcon: U,
  326. loadingIcon: J,
  327. dropdownMenuColumnStyle: G,
  328. customSlots: M
  329. } = he(), F = (b = U.value) !== null && b !== void 0 ? b : (g = ($ = M.value).expandIcon) === null || g === void 0 ? void 0 : g.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";
  330. return T("ul", {
  331. class: E,
  332. role: "menu"
  333. }, [n.map((R) => {
  334. var h;
  335. const {
  336. disabled: I
  337. } = R, s = R[ue], S = (h = R[Re]) !== 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), Q = c.has(j), ne = o.has(j), le = () => {
  338. !I && (!te || !V) && v(K);
  339. }, B = () => {
  340. O(R) && d(K, V);
  341. };
  342. let Y;
  343. return typeof R.title == "string" ? Y = R.title : typeof S == "string" && (Y = S), T("li", {
  344. key: j,
  345. class: [P, {
  346. [`${P}-expand`]: !V,
  347. [`${P}-active`]: l === m,
  348. [`${P}-disabled`]: I,
  349. [`${P}-loading`]: H
  350. }],
  351. style: G.value,
  352. role: "menuitemcheckbox",
  353. title: Y,
  354. "aria-checked": Q,
  355. "data-path-key": j,
  356. onClick: () => {
  357. le(), (!t || V) && B();
  358. },
  359. onDblclick: () => {
  360. N.value && r(!1);
  361. },
  362. onMouseenter: () => {
  363. te && le();
  364. },
  365. onMousedown: (u) => {
  366. u.preventDefault();
  367. }
  368. }, [t && T(fe, {
  369. prefixCls: `${a}-checkbox`,
  370. checked: Q,
  371. halfChecked: ne,
  372. disabled: I,
  373. onClick: (u) => {
  374. u.stopPropagation(), B();
  375. }
  376. }, null), T("div", {
  377. class: `${P}-content`
  378. }, [S]), !H && F && !V && T("div", {
  379. class: `${P}-expand-icon`
  380. }, [Se(F)]), H && W && T("div", {
  381. class: `${P}-loading-icon`
  382. }, [Se(W)])]);
  383. })]);
  384. }
  385. ge.props = ["prefixCls", "multiple", "options", "activeValue", "prevValuePath", "onToggleOpen", "onSelect", "onActive", "checkedSet", "halfCheckedSet", "loadingKeys", "isSelectable"];
  386. ge.displayName = "Column";
  387. ge.inheritAttrs = !1;
  388. const Nt = xe({
  389. compatConfig: {
  390. MODE: 3
  391. },
  392. name: "OptionList",
  393. inheritAttrs: !1,
  394. setup(e, a) {
  395. const {
  396. attrs: t,
  397. slots: n
  398. } = a, l = we(), i = X(), r = y(() => l.direction === "rtl"), {
  399. options: d,
  400. values: v,
  401. halfValues: c,
  402. fieldNames: o,
  403. changeOnSelect: C,
  404. onSelect: O,
  405. searchOptions: b,
  406. dropdownPrefixCls: $,
  407. loadData: g,
  408. expandTrigger: x,
  409. customSlots: p
  410. } = he(), w = y(() => $.value || l.prefixCls), E = Ee([]), P = (h) => {
  411. if (!g.value || l.searchValue)
  412. return;
  413. const s = de(h, d.value, o.value).map((m) => {
  414. let {
  415. option: V
  416. } = m;
  417. return V;
  418. }), S = s[s.length - 1];
  419. if (S && !ce(S, o.value)) {
  420. const m = ee(h);
  421. E.value = [...E.value, m], g.value(s);
  422. }
  423. };
  424. ie(() => {
  425. E.value.length && E.value.forEach((h) => {
  426. const I = xt(h), s = de(I, d.value, o.value, !0).map((m) => {
  427. let {
  428. option: V
  429. } = m;
  430. return V;
  431. }), S = s[s.length - 1];
  432. (!S || S[o.value.children] || ce(S, o.value)) && (E.value = E.value.filter((m) => m !== h));
  433. });
  434. });
  435. const _ = y(() => new Set(se(v.value))), N = y(() => new Set(se(c.value))), [D, U] = $t(), J = (h) => {
  436. U(h), P(h);
  437. }, G = (h) => {
  438. const {
  439. disabled: I
  440. } = h, s = ce(h, o.value);
  441. return !I && (s || C.value || l.multiple);
  442. }, M = function(h, I) {
  443. let s = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : !1;
  444. O(h), !l.multiple && (I || C.value && (x.value === "hover" || s)) && l.toggleOpen(!1);
  445. }, F = y(() => l.searchValue ? b.value : d.value), W = y(() => {
  446. const h = [{
  447. options: F.value
  448. }];
  449. let I = F.value;
  450. for (let s = 0; s < D.value.length; s += 1) {
  451. const S = D.value[s], m = I.find((K) => K[o.value.value] === S), V = m == null ? void 0 : m[o.value.children];
  452. if (!(V != null && V.length))
  453. break;
  454. I = V, h.push({
  455. options: V
  456. });
  457. }
  458. return h;
  459. });
  460. Dt(a, F, o, D, J, (h, I) => {
  461. G(I) && M(h, ce(I, o.value), !0);
  462. });
  463. const R = (h) => {
  464. h.preventDefault();
  465. };
  466. return je(() => {
  467. be(D, (h) => {
  468. var I;
  469. for (let s = 0; s < h.length; s += 1) {
  470. 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, '\\"')}"]`);
  471. V && It(V);
  472. }
  473. }, {
  474. flush: "post",
  475. immediate: !0
  476. });
  477. }), () => {
  478. var h, I, s, S, m;
  479. const {
  480. 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)),
  481. multiple: K,
  482. toggleOpen: j
  483. } = l, H = !(!((m = (S = W.value[0]) === null || S === void 0 ? void 0 : S.options) === null || m === void 0) && m.length), Q = [{
  484. [o.value.value]: "__EMPTY__",
  485. [Re]: V,
  486. disabled: !0
  487. }], ne = k(k({}, t), {
  488. multiple: !H && K,
  489. onSelect: M,
  490. onActive: J,
  491. onToggleOpen: j,
  492. checkedSet: _.value,
  493. halfCheckedSet: N.value,
  494. loadingKeys: E.value,
  495. isSelectable: G
  496. }), B = (H ? [{
  497. options: Q
  498. }] : W.value).map((Y, u) => {
  499. const f = D.value.slice(0, u), A = D.value[u];
  500. return T(ge, Z(Z({
  501. key: u
  502. }, ne), {}, {
  503. prefixCls: w.value,
  504. options: Y.options,
  505. prevValuePath: f,
  506. activeValue: A
  507. }), null);
  508. });
  509. return T("div", {
  510. class: [`${w.value}-menus`, {
  511. [`${w.value}-menu-empty`]: H,
  512. [`${w.value}-rtl`]: r.value
  513. }],
  514. onMousedown: R,
  515. ref: i
  516. }, [B]);
  517. };
  518. }
  519. });
  520. function Rt() {
  521. return k(k({}, Ie(tt(), ["tokenSeparators", "mode", "showSearch"])), {
  522. // MISC
  523. id: String,
  524. prefixCls: String,
  525. fieldNames: nt(),
  526. children: Array,
  527. // Value
  528. value: {
  529. type: [String, Number, Array]
  530. },
  531. defaultValue: {
  532. type: [String, Number, Array]
  533. },
  534. changeOnSelect: {
  535. type: Boolean,
  536. default: void 0
  537. },
  538. displayRender: Function,
  539. checkable: {
  540. type: Boolean,
  541. default: void 0
  542. },
  543. showCheckedStrategy: {
  544. type: String,
  545. default: $e
  546. },
  547. // Search
  548. showSearch: {
  549. type: [Boolean, Object],
  550. default: void 0
  551. },
  552. searchValue: String,
  553. onSearch: Function,
  554. // Trigger
  555. expandTrigger: String,
  556. // Options
  557. options: Array,
  558. /** @private Internal usage. Do not use in your production. */
  559. dropdownPrefixCls: String,
  560. loadData: Function,
  561. // Open
  562. /** @deprecated Use `open` instead */
  563. popupVisible: {
  564. type: Boolean,
  565. default: void 0
  566. },
  567. dropdownClassName: String,
  568. dropdownMenuColumnStyle: {
  569. type: Object,
  570. default: void 0
  571. },
  572. /** @deprecated Use `dropdownStyle` instead */
  573. popupStyle: {
  574. type: Object,
  575. default: void 0
  576. },
  577. dropdownStyle: {
  578. type: Object,
  579. default: void 0
  580. },
  581. /** @deprecated Use `placement` instead */
  582. popupPlacement: String,
  583. placement: String,
  584. /** @deprecated Use `onDropdownVisibleChange` instead */
  585. onPopupVisibleChange: Function,
  586. onDropdownVisibleChange: Function,
  587. // Icon
  588. expandIcon: ye.any,
  589. loadingIcon: ye.any
  590. });
  591. }
  592. function Le() {
  593. return k(k({}, Rt()), {
  594. onChange: Function,
  595. customSlots: Object
  596. });
  597. }
  598. function Lt(e) {
  599. return Array.isArray(e) && Array.isArray(e[0]);
  600. }
  601. function Ae(e) {
  602. return e ? Lt(e) ? e : (e.length === 0 ? [] : [e]).map((a) => Array.isArray(a) ? a : [a]) : [];
  603. }
  604. const Kt = xe({
  605. compatConfig: {
  606. MODE: 3
  607. },
  608. name: "Cascader",
  609. inheritAttrs: !1,
  610. props: Te(Le(), {}),
  611. setup(e, a) {
  612. let {
  613. attrs: t,
  614. expose: n,
  615. slots: l
  616. } = a;
  617. const i = Qe(pe(e, "id")), r = y(() => !!e.checkable), [d, v] = Ve(e.defaultValue, {
  618. value: y(() => e.value),
  619. postState: Ae
  620. }), c = y(() => wt(e.fieldNames)), o = y(() => e.options || []), C = Ot(o, c), O = (u) => {
  621. const f = C.value;
  622. return u.map((A) => {
  623. const {
  624. nodes: L
  625. } = f[A];
  626. return L.map((z) => z[c.value.value]);
  627. });
  628. }, [b, $] = Ve("", {
  629. value: y(() => e.searchValue),
  630. postState: (u) => u || ""
  631. }), g = (u, f) => {
  632. $(u), f.source !== "blur" && e.onSearch && e.onSearch(u);
  633. }, {
  634. showSearch: x,
  635. searchConfig: p
  636. } = 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([])], {
  637. maxLevel: D,
  638. levelEntities: U
  639. } = Ze(C);
  640. ie(() => {
  641. const [u, f] = E.value;
  642. if (!r.value || !d.value.length) {
  643. [P.value, _.value, N.value] = [u, [], f];
  644. return;
  645. }
  646. const A = se(u), L = C.value, {
  647. checkedKeys: z,
  648. halfCheckedKeys: re
  649. } = Ce(A, !0, L, D.value, U.value);
  650. [P.value, _.value, N.value] = [O(z), O(re), f];
  651. });
  652. const J = y(() => {
  653. const u = se(P.value), f = _e(u, C.value, e.showCheckedStrategy);
  654. return [...N.value, ...O(f)];
  655. }), G = Et(J, o, c, r, pe(e, "displayRender")), M = (u) => {
  656. if (v(u), e.onChange) {
  657. 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];
  658. e.onChange(L, z);
  659. }
  660. }, F = (u) => {
  661. if ($(""), !r.value)
  662. M(u);
  663. else {
  664. const f = ee(u), A = se(P.value), L = se(_.value), z = A.includes(f), re = N.value.some((ae) => ee(ae) === f);
  665. let ve = P.value, Pe = N.value;
  666. if (re && !z)
  667. Pe = N.value.filter((ae) => ee(ae) !== f);
  668. else {
  669. const ae = z ? A.filter((Me) => Me !== f) : [...A, f];
  670. let me;
  671. z ? {
  672. checkedKeys: me
  673. } = Ce(ae, {
  674. halfCheckedKeys: L
  675. }, C.value, D.value, U.value) : {
  676. checkedKeys: me
  677. } = Ce(ae, !0, C.value, D.value, U.value);
  678. const Ke = _e(me, C.value, e.showCheckedStrategy);
  679. ve = O(Ke);
  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: Q,
  708. customSlots: ne,
  709. dropdownClassName: le
  710. } = He(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: Q,
  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 Y = 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(et, Z(Z(Z({}, Y.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. at(`${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({}, ot), {
  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. st(e)
  940. ];
  941. }, Ft = lt("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(Le(), ["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: Te(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 = rt(), d = ct.useInject(), v = y(() => ut(d.status, e.status)), {
  1023. prefixCls: c,
  1024. rootPrefixCls: o,
  1025. getPrefixCls: C,
  1026. direction: O,
  1027. getPopupContainer: b,
  1028. renderEmpty: $,
  1029. size: g,
  1030. disabled: x
  1031. } = dt("cascader", e), p = y(() => C("select", e.prefixCls)), {
  1032. compactSize: w,
  1033. compactItemClassnames: E
  1034. } = vt(p, O), P = y(() => w.value || g.value), _ = pt(), N = y(() => {
  1035. var s;
  1036. return (s = x.value) !== null && s !== void 0 ? s : _.value;
  1037. }), [D, U] = ht(p), [J] = 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(() => ft(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: Q,
  1079. transitionName: ne,
  1080. id: le = r.id.value
  1081. } = e, B = Wt(e, ["notFoundContent", "expandIcon", "multiple", "bordered", "allowClear", "choiceTransitionName", "transitionName", "id"]), Y = m || $("Cascader");
  1082. let u = V;
  1083. V || (u = G.value ? T(gt, null, null) : T(mt, null, null));
  1084. const f = T("span", {
  1085. class: `${p.value}-menu-item-loading-icon`
  1086. }, [T(Ct, {
  1087. spin: !0
  1088. }, null)]), {
  1089. suffixIcon: A,
  1090. removeIcon: L,
  1091. clearIcon: z
  1092. } = St(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 J(D(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. }, bt(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: Y,
  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, "", Q),
  1124. transitionName: ke(o.value, yt(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. }), Xt = it(k(zt, {
  1142. SHOW_CHILD: De,
  1143. SHOW_PARENT: $e
  1144. })), Ut = { class: "s-cascader-common" }, Qt = {
  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 = Xt;
  1211. return Be(), ze("div", Ut, [
  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: Xe(Ue).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. Qt as default
  1232. };