react-cascader-popover
Version:
react级联选择器/支持多选/单选
1,045 lines (1,041 loc) • 41.3 kB
JavaScript
import './index.css';
import { __spreadArray as P, __rest as pr, __awaiter as gr, __generator as br, __assign as Te } from "tslib";
import ze, { useRef as _r, useState as q, useEffect as te, memo as mr, forwardRef as Er, useImperativeHandle as yr } from "react";
import { createPortal as xr } from "react-dom";
var Pe = { exports: {} }, ce = {};
/**
* @license React
* react-jsx-runtime.development.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var Ie;
function Cr() {
return Ie || (Ie = 1, process.env.NODE_ENV !== "production" && function() {
var d = ze, y = Symbol.for("react.element"), _ = Symbol.for("react.portal"), p = Symbol.for("react.fragment"), m = Symbol.for("react.strict_mode"), C = Symbol.for("react.profiler"), i = Symbol.for("react.provider"), j = Symbol.for("react.context"), v = Symbol.for("react.forward_ref"), T = Symbol.for("react.suspense"), S = Symbol.for("react.suspense_list"), w = Symbol.for("react.memo"), N = Symbol.for("react.lazy"), A = Symbol.for("react.offscreen"), $ = Symbol.iterator, B = "@@iterator";
function V(e) {
if (e === null || typeof e != "object")
return null;
var r = $ && e[$] || e[B];
return typeof r == "function" ? r : null;
}
var M = d.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
function O(e) {
{
for (var r = arguments.length, a = new Array(r > 1 ? r - 1 : 0), h = 1; h < r; h++)
a[h - 1] = arguments[h];
Z("error", e, a);
}
}
function Z(e, r, a) {
{
var h = M.ReactDebugCurrentFrame, R = h.getStackAddendum();
R !== "" && (r += "%s", a = a.concat([R]));
var k = a.map(function(x) {
return String(x);
});
k.unshift("Warning: " + r), Function.prototype.apply.call(console[e], console, k);
}
}
var ie = !1, me = !1, ue = !1, Ee = !1, le = !1, fe;
fe = Symbol.for("react.module.reference");
function ye(e) {
return !!(typeof e == "string" || typeof e == "function" || e === p || e === C || le || e === m || e === T || e === S || Ee || e === A || ie || me || ue || typeof e == "object" && e !== null && (e.$$typeof === N || e.$$typeof === w || e.$$typeof === i || e.$$typeof === j || e.$$typeof === v || // This needs to include all possible module reference object
// types supported by any Flight configuration anywhere since
// we don't know which Flight build this will end up being used
// with.
e.$$typeof === fe || e.getModuleId !== void 0));
}
function xe(e, r, a) {
var h = e.displayName;
if (h)
return h;
var R = r.displayName || r.name || "";
return R !== "" ? a + "(" + R + ")" : a;
}
function de(e) {
return e.displayName || "Context";
}
function U(e) {
if (e == null)
return null;
if (typeof e.tag == "number" && O("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), typeof e == "function")
return e.displayName || e.name || null;
if (typeof e == "string")
return e;
switch (e) {
case p:
return "Fragment";
case _:
return "Portal";
case C:
return "Profiler";
case m:
return "StrictMode";
case T:
return "Suspense";
case S:
return "SuspenseList";
}
if (typeof e == "object")
switch (e.$$typeof) {
case j:
var r = e;
return de(r) + ".Consumer";
case i:
var a = e;
return de(a._context) + ".Provider";
case v:
return xe(e, e.render, "ForwardRef");
case w:
var h = e.displayName || null;
return h !== null ? h : U(e.type) || "Memo";
case N: {
var R = e, k = R._payload, x = R._init;
try {
return U(x(k));
} catch {
return null;
}
}
}
return null;
}
var J = Object.assign, K = 0, Q, ve, he, pe, l, s, n;
function c() {
}
c.__reactDisabledLog = !0;
function u() {
{
if (K === 0) {
Q = console.log, ve = console.info, he = console.warn, pe = console.error, l = console.group, s = console.groupCollapsed, n = console.groupEnd;
var e = {
configurable: !0,
enumerable: !0,
value: c,
writable: !0
};
Object.defineProperties(console, {
info: e,
log: e,
warn: e,
error: e,
group: e,
groupCollapsed: e,
groupEnd: e
});
}
K++;
}
}
function t() {
{
if (K--, K === 0) {
var e = {
configurable: !0,
enumerable: !0,
writable: !0
};
Object.defineProperties(console, {
log: J({}, e, {
value: Q
}),
info: J({}, e, {
value: ve
}),
warn: J({}, e, {
value: he
}),
error: J({}, e, {
value: pe
}),
group: J({}, e, {
value: l
}),
groupCollapsed: J({}, e, {
value: s
}),
groupEnd: J({}, e, {
value: n
})
});
}
K < 0 && O("disabledDepth fell below zero. This is a bug in React. Please file an issue.");
}
}
var g = M.ReactCurrentDispatcher, W;
function f(e, r, a) {
{
if (W === void 0)
try {
throw Error();
} catch (R) {
var h = R.stack.trim().match(/\n( *(at )?)/);
W = h && h[1] || "";
}
return `
` + W + e;
}
}
var z = !1, H;
{
var ee = typeof WeakMap == "function" ? WeakMap : Map;
H = new ee();
}
function b(e, r) {
if (!e || z)
return "";
{
var a = H.get(e);
if (a !== void 0)
return a;
}
var h;
z = !0;
var R = Error.prepareStackTrace;
Error.prepareStackTrace = void 0;
var k;
k = g.current, g.current = null, u();
try {
if (r) {
var x = function() {
throw Error();
};
if (Object.defineProperty(x.prototype, "props", {
set: function() {
throw Error();
}
}), typeof Reflect == "object" && Reflect.construct) {
try {
Reflect.construct(x, []);
} catch (G) {
h = G;
}
Reflect.construct(e, [], x);
} else {
try {
x.call();
} catch (G) {
h = G;
}
e.call(x.prototype);
}
} else {
try {
throw Error();
} catch (G) {
h = G;
}
e();
}
} catch (G) {
if (G && h && typeof G.stack == "string") {
for (var E = G.stack.split(`
`), Y = h.stack.split(`
`), D = E.length - 1, L = Y.length - 1; D >= 1 && L >= 0 && E[D] !== Y[L]; )
L--;
for (; D >= 1 && L >= 0; D--, L--)
if (E[D] !== Y[L]) {
if (D !== 1 || L !== 1)
do
if (D--, L--, L < 0 || E[D] !== Y[L]) {
var I = `
` + E[D].replace(" at new ", " at ");
return e.displayName && I.includes("<anonymous>") && (I = I.replace("<anonymous>", e.displayName)), typeof e == "function" && H.set(e, I), I;
}
while (D >= 1 && L >= 0);
break;
}
}
} finally {
z = !1, g.current = k, t(), Error.prepareStackTrace = R;
}
var ae = e ? e.displayName || e.name : "", Be = ae ? f(ae) : "";
return typeof e == "function" && H.set(e, Be), Be;
}
function F(e, r, a) {
return b(e, !1);
}
function re(e) {
var r = e.prototype;
return !!(r && r.isReactComponent);
}
function X(e, r, a) {
if (e == null)
return "";
if (typeof e == "function")
return b(e, re(e));
if (typeof e == "string")
return f(e);
switch (e) {
case T:
return f("Suspense");
case S:
return f("SuspenseList");
}
if (typeof e == "object")
switch (e.$$typeof) {
case v:
return F(e.render);
case w:
return X(e.type, r, a);
case N: {
var h = e, R = h._payload, k = h._init;
try {
return X(k(R), r, a);
} catch {
}
}
}
return "";
}
var ge = Object.prototype.hasOwnProperty, Se = {}, Oe = M.ReactDebugCurrentFrame;
function be(e) {
if (e) {
var r = e._owner, a = X(e.type, e._source, r ? r.type : null);
Oe.setExtraStackFrame(a);
} else
Oe.setExtraStackFrame(null);
}
function Ge(e, r, a, h, R) {
{
var k = Function.call.bind(ge);
for (var x in e)
if (k(e, x)) {
var E = void 0;
try {
if (typeof e[x] != "function") {
var Y = Error((h || "React class") + ": " + a + " type `" + x + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof e[x] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");
throw Y.name = "Invariant Violation", Y;
}
E = e[x](r, x, h, a, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED");
} catch (D) {
E = D;
}
E && !(E instanceof Error) && (be(R), O("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).", h || "React class", a, x, typeof E), be(null)), E instanceof Error && !(E.message in Se) && (Se[E.message] = !0, be(R), O("Failed %s type: %s", a, E.message), be(null));
}
}
}
var Ke = Array.isArray;
function Ce(e) {
return Ke(e);
}
function Xe(e) {
{
var r = typeof Symbol == "function" && Symbol.toStringTag, a = r && e[Symbol.toStringTag] || e.constructor.name || "Object";
return a;
}
}
function Ze(e) {
try {
return Ne(e), !1;
} catch {
return !0;
}
}
function Ne(e) {
return "" + e;
}
function De(e) {
if (Ze(e))
return O("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", Xe(e)), Ne(e);
}
var oe = M.ReactCurrentOwner, Qe = {
key: !0,
ref: !0,
__self: !0,
__source: !0
}, Le, Fe, Re;
Re = {};
function er(e) {
if (ge.call(e, "ref")) {
var r = Object.getOwnPropertyDescriptor(e, "ref").get;
if (r && r.isReactWarning)
return !1;
}
return e.ref !== void 0;
}
function rr(e) {
if (ge.call(e, "key")) {
var r = Object.getOwnPropertyDescriptor(e, "key").get;
if (r && r.isReactWarning)
return !1;
}
return e.key !== void 0;
}
function nr(e, r) {
if (typeof e.ref == "string" && oe.current && r && oe.current.stateNode !== r) {
var a = U(oe.current.type);
Re[a] || (O('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref', U(oe.current.type), e.ref), Re[a] = !0);
}
}
function ar(e, r) {
{
var a = function() {
Le || (Le = !0, O("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r));
};
a.isReactWarning = !0, Object.defineProperty(e, "key", {
get: a,
configurable: !0
});
}
}
function tr(e, r) {
{
var a = function() {
Fe || (Fe = !0, O("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r));
};
a.isReactWarning = !0, Object.defineProperty(e, "ref", {
get: a,
configurable: !0
});
}
}
var ir = function(e, r, a, h, R, k, x) {
var E = {
// This tag allows us to uniquely identify this as a React Element
$$typeof: y,
// Built-in properties that belong on the element
type: e,
key: r,
ref: a,
props: x,
// Record the component responsible for creating this element.
_owner: k
};
return E._store = {}, Object.defineProperty(E._store, "validated", {
configurable: !1,
enumerable: !1,
writable: !0,
value: !1
}), Object.defineProperty(E, "_self", {
configurable: !1,
enumerable: !1,
writable: !1,
value: h
}), Object.defineProperty(E, "_source", {
configurable: !1,
enumerable: !1,
writable: !1,
value: R
}), Object.freeze && (Object.freeze(E.props), Object.freeze(E)), E;
};
function lr(e, r, a, h, R) {
{
var k, x = {}, E = null, Y = null;
a !== void 0 && (De(a), E = "" + a), rr(r) && (De(r.key), E = "" + r.key), er(r) && (Y = r.ref, nr(r, R));
for (k in r)
ge.call(r, k) && !Qe.hasOwnProperty(k) && (x[k] = r[k]);
if (e && e.defaultProps) {
var D = e.defaultProps;
for (k in D)
x[k] === void 0 && (x[k] = D[k]);
}
if (E || Y) {
var L = typeof e == "function" ? e.displayName || e.name || "Unknown" : e;
E && ar(x, L), Y && tr(x, L);
}
return ir(e, E, Y, R, h, oe.current, x);
}
}
var we = M.ReactCurrentOwner, Ae = M.ReactDebugCurrentFrame;
function ne(e) {
if (e) {
var r = e._owner, a = X(e.type, e._source, r ? r.type : null);
Ae.setExtraStackFrame(a);
} else
Ae.setExtraStackFrame(null);
}
var ke;
ke = !1;
function je(e) {
return typeof e == "object" && e !== null && e.$$typeof === y;
}
function Ve() {
{
if (we.current) {
var e = U(we.current.type);
if (e)
return `
Check the render method of \`` + e + "`.";
}
return "";
}
}
function or(e) {
{
if (e !== void 0) {
var r = e.fileName.replace(/^.*[\\\/]/, ""), a = e.lineNumber;
return `
Check your code at ` + r + ":" + a + ".";
}
return "";
}
}
var We = {};
function cr(e) {
{
var r = Ve();
if (!r) {
var a = typeof e == "string" ? e : e.displayName || e.name;
a && (r = `
Check the top-level render call using <` + a + ">.");
}
return r;
}
}
function $e(e, r) {
{
if (!e._store || e._store.validated || e.key != null)
return;
e._store.validated = !0;
var a = cr(r);
if (We[a])
return;
We[a] = !0;
var h = "";
e && e._owner && e._owner !== we.current && (h = " It was passed a child from " + U(e._owner.type) + "."), ne(e), O('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', a, h), ne(null);
}
}
function Me(e, r) {
{
if (typeof e != "object")
return;
if (Ce(e))
for (var a = 0; a < e.length; a++) {
var h = e[a];
je(h) && $e(h, r);
}
else if (je(e))
e._store && (e._store.validated = !0);
else if (e) {
var R = V(e);
if (typeof R == "function" && R !== e.entries)
for (var k = R.call(e), x; !(x = k.next()).done; )
je(x.value) && $e(x.value, r);
}
}
}
function sr(e) {
{
var r = e.type;
if (r == null || typeof r == "string")
return;
var a;
if (typeof r == "function")
a = r.propTypes;
else if (typeof r == "object" && (r.$$typeof === v || // Note: Memo only checks outer props here.
// Inner props are checked in the reconciler.
r.$$typeof === w))
a = r.propTypes;
else
return;
if (a) {
var h = U(r);
Ge(a, e.props, "prop", h, e);
} else if (r.PropTypes !== void 0 && !ke) {
ke = !0;
var R = U(r);
O("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", R || "Unknown");
}
typeof r.getDefaultProps == "function" && !r.getDefaultProps.isReactClassApproved && O("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.");
}
}
function ur(e) {
{
for (var r = Object.keys(e.props), a = 0; a < r.length; a++) {
var h = r[a];
if (h !== "children" && h !== "key") {
ne(e), O("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", h), ne(null);
break;
}
}
e.ref !== null && (ne(e), O("Invalid attribute `ref` supplied to `React.Fragment`."), ne(null));
}
}
function Ye(e, r, a, h, R, k) {
{
var x = ye(e);
if (!x) {
var E = "";
(e === void 0 || typeof e == "object" && e !== null && Object.keys(e).length === 0) && (E += " You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");
var Y = or(R);
Y ? E += Y : E += Ve();
var D;
e === null ? D = "null" : Ce(e) ? D = "array" : e !== void 0 && e.$$typeof === y ? (D = "<" + (U(e.type) || "Unknown") + " />", E = " Did you accidentally export a JSX literal instead of a component?") : D = typeof e, O("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", D, E);
}
var L = lr(e, r, a, R, k);
if (L == null)
return L;
if (x) {
var I = r.children;
if (I !== void 0)
if (h)
if (Ce(I)) {
for (var ae = 0; ae < I.length; ae++)
Me(I[ae], e);
Object.freeze && Object.freeze(I);
} else
O("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");
else
Me(I, e);
}
return e === p ? ur(L) : sr(L), L;
}
}
function fr(e, r, a) {
return Ye(e, r, a, !0);
}
function dr(e, r, a) {
return Ye(e, r, a, !1);
}
var vr = dr, hr = fr;
ce.Fragment = p, ce.jsx = vr, ce.jsxs = hr;
}()), ce;
}
var se = {};
/**
* @license React
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var Ue;
function Rr() {
if (Ue)
return se;
Ue = 1;
var d = ze, y = Symbol.for("react.element"), _ = Symbol.for("react.fragment"), p = Object.prototype.hasOwnProperty, m = d.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, C = { key: !0, ref: !0, __self: !0, __source: !0 };
function i(j, v, T) {
var S, w = {}, N = null, A = null;
T !== void 0 && (N = "" + T), v.key !== void 0 && (N = "" + v.key), v.ref !== void 0 && (A = v.ref);
for (S in v)
p.call(v, S) && !C.hasOwnProperty(S) && (w[S] = v[S]);
if (j && j.defaultProps)
for (S in v = j.defaultProps, v)
w[S] === void 0 && (w[S] = v[S]);
return { $$typeof: y, type: j, key: N, ref: A, props: w, _owner: m.current };
}
return se.Fragment = _, se.jsx = i, se.jsxs = i, se;
}
process.env.NODE_ENV === "production" ? Pe.exports = Rr() : Pe.exports = Cr();
var o = Pe.exports, _e = function(d) {
if (d === null || typeof d != "object")
return d;
var y = Array.isArray(d) ? [] : {};
for (var _ in d)
Object.prototype.hasOwnProperty.call(d, _) && (y[_] = _e(d[_]));
return Array.isArray(d) && (y.length = d.length), y;
}, wr = function(d, y) {
for (var _ = [], p = [], m = function(v, T, S) {
if (y.includes(v.value) && (_.push(P(P([], T, !0), [v.value], !1)), p.push(P(P([], S, !0), [v.label], !1))), v.children)
for (var w = 0, N = v.children; w < N.length; w++) {
var A = N[w];
m(A, P(P([], T, !0), [v.value], !1), P(P([], S, !0), [v.label], !1));
}
}, C = 0, i = d; C < i.length; C++) {
var j = i[C];
m(j, [], []);
}
return { valueResult: _, labelResult: p };
}, He = function(d, y, _) {
_ === void 0 && (_ = ""), d.forEach(function(p, m) {
var C, i = _ !== "" ? "".concat(_, "-").concat(m + 1) : "".concat(m + 1);
p.cascaderNodeId = i, p.checked = !1, p.indeterminateChecked = !1, y.forEach(function(j) {
j.includes(p.value) && (p.checked = !1, p.indeterminateChecked = !0);
}), p.parentCascaderNodeId = _, p.children && p.children.length ? (He(p.children, y, i), !((C = p.children) === null || C === void 0) && C.every(function(j) {
return j.checked;
}) && (p.checked = !0, p.indeterminateChecked = !1)) : y.forEach(function(j) {
j.includes(p.value) && (p.checked = !0, p.indeterminateChecked = !1);
});
});
};
function kr(d, y) {
var _;
return function() {
for (var p = this, m = [], C = 0; C < arguments.length; C++)
m[C] = arguments[C];
clearTimeout(_), _ = setTimeout(function() {
d.apply(p, m);
}, y);
};
}
var qe = function(d, y, _, p) {
return y === void 0 && (y = ""), _ === void 0 && (_ = ""), p === void 0 && (p = []), d.forEach(function(m) {
var C, i = y ? "".concat(y, " / ").concat(m.label) : m.label, j = _ ? "".concat(_, "/").concat(m.value) : m.value;
m.children && m.children.length > 0 && !m.disabled ? qe(m.children, i, j, p) : !m.isLoad && (!m.children || ((C = m.children) === null || C === void 0 ? void 0 : C.length) === 0) && p.push({
value: "",
disabled: m.disabled,
pathName: i,
pathValue: j
});
}), p;
}, jr = function(d) {
var y = _r(null), _ = q(!1), p = _[0], m = _[1], C = q(window.innerWidth), i = C[0], j = C[1], v = q(!0), T = v[0], S = v[1], w = q({
top: 0,
left: 0
}), N = w[0], A = w[1], $ = function(V) {
V.isDefaultPrevented(), setTimeout(function() {
d.onClose();
}, 100);
}, B = function(V) {
V.preventDefault();
};
return te(function() {
var V = function() {
j(window.innerWidth);
};
return window.addEventListener("resize", kr(V, 200)), function() {
window.removeEventListener("resize", V);
};
}, []), te(function() {
if (y.current && d.anchorEl) {
var V = d.anchorEl.getBoundingClientRect(), M = V.top + d.anchorEl.offsetHeight, O = window.innerHeight - M;
if (O > y.current.offsetHeight)
A({
top: M,
left: V.left
});
else {
var Z = M - (y.current.offsetHeight - O);
A({
top: Z - 20,
left: V.left
});
}
}
}, [y.current, i]), te(function() {
if (d.open) {
m(d.open), setTimeout(function() {
S(!1);
}, 100);
var V = window.innerWidth - document.documentElement.clientWidth;
document.body.style.overflow = "hidden", document.body.style.paddingRight = "".concat(V, "px"), window.addEventListener("scroll", B, { passive: !1 });
} else
S(!0), setTimeout(function() {
m(d.open);
}, 100), document.body.style.overflow = "", document.body.style.paddingRight = "", window.removeEventListener("scroll", B);
return function() {
window.removeEventListener("scroll", B);
};
}, [d.open]), xr(o.jsx(o.Fragment, { children: p ? o.jsxs("div", { id: "popover-cascader", className: "Popover", children: [o.jsx("div", { onClick: $, className: "Popover-invisible" }), o.jsx("div", { ref: y, className: (T ? "Popover-root-hide" : "Popover-root-show") + " Popover-root", style: { top: N.top, left: N.left }, children: d.children })] }) : o.jsx(o.Fragment, {}) }), document.body);
}, Tr = function() {
return o.jsx("svg", { color: "#8190b8", className: "svgIcon-root arrow-icon", focusable: "false", "aria-hidden": "true", viewBox: "0 0 24 24", children: o.jsx("path", { d: "M7.38 21.01c.49.49 1.28.49 1.77 0l8.31-8.31c.39-.39.39-1.02 0-1.41L9.15 2.98c-.49-.49-1.28-.49-1.77 0s-.49 1.28 0 1.77L14.62 12l-7.25 7.25c-.48.48-.48 1.28.01 1.76" }) });
}, Je = function(d) {
var y = d.checked, _ = y === void 0 ? !1 : y, p = d.indeterminate, m = p === void 0 ? !1 : p, C = d.onClick, i = C === void 0 ? function() {
} : C;
return o.jsx("span", { onClick: i, className: "svgBox", children: m ? o.jsx("svg", { className: "svgIcon-root checkbox indeterminate-checkbox", focusable: "false", "aria-hidden": "true", viewBox: "0 0 24 24", children: o.jsx("path", { d: "M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-2 10H7v-2h10v2z" }) }) : _ ? o.jsx("svg", { className: "svgIcon-root checkbox checked-checkbox ", focusable: "false", "aria-hidden": "true", viewBox: "0 0 24 24", children: o.jsx("path", { d: "M19 3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.11 0 2-.9 2-2V5c0-1.1-.89-2-2-2zm-9 14l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z" }) }) : o.jsx("svg", { className: "svgIcon-root checkbox", focusable: "false", "aria-hidden": "true", viewBox: "0 0 24 24", children: o.jsx("path", { d: "M19 5v14H5V5h14m0-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2z" }) }) });
}, Pr = function() {
return o.jsx("svg", { className: "load-icon", width: "54.408", height: "54.408", viewBox: "0 0 54.408 54.408", children: o.jsxs("g", { transform: "translate(727.5 -147.5)", children: [o.jsx("path", { d: "M1276.926-1326.907a27.035,27.035,0,0,1-10.59-2.139,27.11,27.11,0,0,1-8.646-5.829,27.111,27.111,0,0,1-5.829-8.646,27.035,27.035,0,0,1-2.139-10.589,27.037,27.037,0,0,1,2.139-10.59,27.111,27.111,0,0,1,5.829-8.646,27.111,27.111,0,0,1,8.646-5.829,27.037,27.037,0,0,1,10.59-2.139v5a22.229,22.229,0,0,0-22.2,22.2,22.229,22.229,0,0,0,22.2,22.2,22.229,22.229,0,0,0,22.2-22.2h5a27.033,27.033,0,0,1-2.139,10.589,27.11,27.11,0,0,1-5.829,8.646,27.11,27.11,0,0,1-8.646,5.829A27.033,27.033,0,0,1,1276.926-1326.907Z", transform: "translate(-1977.222 1528.815)", fill: "rgba(23,26,29,0.4)", opacity: "0" }), o.jsx("path", { d: "M1301.63-1351.611a2.5,2.5,0,0,1-2.5-2.5,22.229,22.229,0,0,0-22.2-22.2,2.5,2.5,0,0,1-2.5-2.5,2.5,2.5,0,0,1,2.5-2.5,27.035,27.035,0,0,1,10.589,2.139,27.111,27.111,0,0,1,8.646,5.829,27.11,27.11,0,0,1,5.829,8.646,27.035,27.035,0,0,1,2.139,10.59A2.5,2.5,0,0,1,1301.63-1351.611Z", transform: "translate(-1977.222 1528.815)", fill: "rgba(23,26,29,0.4)" })] }) });
}, Sr = mr(function(d) {
var y = d.list, _ = d.searchValue, p = d.multipleValue, m = d.searchEmptyText, C = d.multiple, i = d.onChoose, j = q([]), v = j[0], T = j[1];
te(function() {
if (!(_.length < 2)) {
var w = setTimeout(function() {
var N = y[0].list, A = qe(N);
T(A.filter(function($) {
var B = $.pathValue.split("/");
return $.value = B[B.length - 1], $.pathName.toLowerCase().includes(_.toLowerCase());
}));
}, 500);
return function() {
clearTimeout(w);
};
}
}, [_]);
var S = function(w) {
if (!w.disabled) {
var N = w.pathValue.split("/");
i(N[N.length - 1]);
}
};
return o.jsx(o.Fragment, { children: v.length ? o.jsx("div", { className: "searchList", children: o.jsx("div", { className: "cascader_popover_cell", children: v.map(function(w, N) {
return o.jsx("div", { onClick: function() {
return S(w);
}, children: o.jsx("div", { className: w.disabled ? "cascader_popover_cell_label_box_disabled" : "cascader_popover_cell_label_box", children: o.jsxs("div", { className: "label", children: [C ? o.jsx("span", { className: "icon", children: o.jsx(Je, { checked: !!p.includes(w.value) }) }) : o.jsx(o.Fragment, {}), w.pathName.split("").map(function(A, $) {
return o.jsx("span", { children: A === "/" ? o.jsx("span", { className: "slash", children: " / " }) : o.jsx("span", { className: _.split("").includes(A) ? "search_text_ac" : "", children: A }) }, $);
})] }) }) }, N);
}) }) }) : o.jsx("div", { className: "empty_data", children: m }) });
}), Lr = Er(function(d, y) {
var _ = d.searchPlaceholder, p = _ === void 0 ? "请输入关键词" : _, m = d.searchEmptyText, C = m === void 0 ? "暂无数据" : m, i = pr(d, ["searchPlaceholder", "searchEmptyText"]), j = q([]), v = j[0], T = j[1], S = q(""), w = S[0], N = S[1], A = q([]), $ = A[0], B = A[1], V = q(""), M = V[0], O = V[1], Z = q({}), ie = Z[0], me = Z[1], ue = q(!0), Ee = ue[0], le = ue[1];
yr(y, function() {
return {
setValue: Q,
clearValue: fe
};
});
var fe = function() {
var l = P([], v, !0);
function s(n) {
n.forEach(function(c) {
c.checked = !1, c.indeterminateChecked = !1, c.children && c.children.length && s(c.children);
});
}
i.multiple ? s(l[0].list) : l.forEach(function(n) {
n.index = -1;
}), T(l), O(""), B([]), i.onChange(null, []);
}, ye = function(l, s, n) {
return gr(void 0, void 0, void 0, function() {
var c, u, t, g, W;
return br(this, function(f) {
switch (f.label) {
case 0:
if (l.value === M || l.disabled || !l.isLoad && i.multiple)
return [
2
/*return*/
];
if (c = P([], v, !0), !l.isLoad)
return c[s].index = n, u = [], c.forEach(function(z, H) {
H <= s && u.push(z.list[z.index]);
}), O(l.value), i.onChange(l, u), i.onClose(), [
2
/*return*/
];
if (!(i.loadData && Ee))
return [3, 3];
for (le(!1), c[s].index = n, t = c.length - 1; t >= 0; t--)
t > s && c.splice(t, 1);
return ie[l.value] ? (c[s + 1] = {
list: ie[l.value],
index: -1
}, T(c), le(!0), [3, 3]) : [3, 1];
case 1:
return l.isLoad && (c[s].list[n].isLoading = !0, T(c)), [4, i.loadData(l)];
case 2:
g = f.sent(), me(Te(Te({}, ie), (W = {}, W[l.value] = g, W))), c[s].list[n].isLoading = !1, c[s].list[n].children = g, c[s + 1] = {
list: g,
index: -1
}, T(function() {
return P([], c, !0);
}), le(!0), f.label = 3;
case 3:
return [
2
/*return*/
];
}
});
});
}, xe = function(l, s, n) {
var c;
if (!(l.value === M || l.disabled)) {
var u = P([], v, !0);
if ((!l.children || l.children.length === 0) && (u[s].index = n, !i.multiple)) {
var t = [];
u.forEach(function(W, f) {
f <= s && t.push(W.list[W.index]);
}), T(u), O(l.value), i.onChange(l, t), i.onClose();
}
for (var g = u.length - 1; g >= 0; g--)
g > s && g != s && u.splice(g, 1);
!((c = l.children) === null || c === void 0) && c.length && (u[s + 1] = {
list: l.children,
index: l.children.findIndex(function(W) {
return W.value === M;
})
}, u[s].index = n, T(u));
}
}, de = function(l) {
var s = [];
function n(c) {
c.forEach(function(u) {
var t;
if (u.checked && !(!((t = u.children) === null || t === void 0) && t.length)) {
var g = Te({}, u);
delete g.cascaderNodeId, delete g.parentCascaderNodeId, delete g.checked, delete g.indeterminateChecked, delete g.isLoading, s.push(g);
}
u.children && u.children.length && n(u.children);
});
}
n(l), B(s.map(function(c) {
return c.value;
})), i.onChange(null, s);
}, U = function(l, s, n) {
var c, u;
if (v[s].list[n].disabled)
return;
l.stopPropagation();
var t = P([], v, !0);
t[s].list[n].checked = !t[s].list[n].checked;
var g = t[s].list[n].children;
function W(ee) {
ee.forEach(function(b) {
t[s].list[n].checked ? b.checked = !0 : b.checked = !1, b.indeterminateChecked = !1, b.children && W(b.children);
});
}
if (g && g.length)
t[s].list[n].indeterminateChecked = !1, W(g);
else {
t[s].index = -1;
for (var f = t.length - 1; f >= 0; f--)
f > s && t.splice(f, 1);
}
for (var f = s; f > 0; f--) {
var z = t[f].list.every(function(b) {
return b.checked;
}), H = t[f].list.some(function(b) {
return b.indeterminateChecked || b.checked;
});
t[f - 1].list[t[f - 1].index].checked = z, H ? (t[f - 1].list[t[f - 1].index].indeterminateChecked = !0, t[f].list[t[f].index] && (t[f].list[t[f].index].indeterminateChecked = !0)) : t[f - 1].list[t[f - 1].index].indeterminateChecked = !1;
}
for (var f = 0; f < t.length; f++)
t[f].list[t[f].index] && (t[f].list[t[f].index].indeterminateChecked = (c = t[f].list[t[f].index].children) === null || c === void 0 ? void 0 : c.some(function(b) {
return b.indeterminateChecked || b.checked;
}), !((u = t[f].list[t[f].index].children) === null || u === void 0) && u.every(function(b) {
return b.checked;
}) && (t[f].list[t[f].index].indeterminateChecked = !1));
de(t[0].list), T(t);
}, J = function(l, s, n, c) {
for (var u = 0; u < l.length; u++) {
var t = l[u];
if (t.value === s)
return {
parentItems: P(P([], n, !0), [t], !1),
parentIndexes: P(P([], c, !0), [u], !1)
};
if (t.children) {
var g = J(t.children, s, P(P([], n, !0), [t], !1), P(P([], c, !0), [u], !1));
if (g)
return g;
}
}
return null;
}, K = function(l) {
if (M !== l) {
var s = _e(i.options), n = J(i.loadData ? v[0].list : s, l, [], []);
if (n) {
var c = [];
n.parentItems.forEach(function(t, g) {
t.children && t.children.length && c.push({
list: t.children,
index: n.parentIndexes[g + 1]
});
});
var u = c.length ? c[c.length - 1].list.filter(function(t) {
return t.value === l;
}) : [];
u.length && (O(u[0].value + ""), i.onChange(u[0], n.parentItems)), T(P([
{
list: i.loadData ? v[0].list : i.options,
index: n.parentIndexes[0]
}
], c, !0));
}
}
};
te(function() {
i.anchorEl && (N(""), setTimeout(function() {
var l = document.getElementsByClassName("cascader_popover_cell");
l.length && v.forEach(function(s, n) {
var c, u = l[n].querySelector(".cascader_popover_cell_label_box_ac"), t = (c = u == null ? void 0 : u.parentElement) === null || c === void 0 ? void 0 : c.getBoundingClientRect(), g = t ? u.getBoundingClientRect().top - t.top : 0;
u ? l[n].scrollTop = g - 5 || 0 : l[n].scrollTop = 0;
});
}));
}, [i.anchorEl]);
var Q = function(l) {
if (l.length === 0) {
i.onChange(null, []), B([]);
return;
}
if ($.join(",") !== l.join(",")) {
var s = _e(i.options), n = P([], v, !0), c = [];
if (n.length)
if (n.length === 1)
n.forEach(function(b) {
b.list.forEach(function(F) {
F.checked = !1, F.indeterminateChecked = !1;
});
});
else {
var u = function(b) {
b.forEach(function(F) {
F.checked = !1, F.indeterminateChecked = !1, F.children && F.children.length && u(F.children);
});
};
u(n[0].list);
}
var t = wr(v.length ? v[0].list : s, l), g = t.valueResult, W = t.labelResult;
if (He(v.length ? v[0].list : s, g), g.length) {
var f = n.length ? n[0].list.filter(function(b) {
return b.value === g[0][0];
}) : s.filter(function(b) {
return b.value === g[0][0];
}), z = function(b, F) {
b.forEach(function(re, X) {
re.value === g[0][F] && (v.length ? n[F] = {
list: b,
index: X
} : c[F] = {
list: b,
index: X
}, F++), re.children && re.children.length && z(re.children, F);
});
};
f.length && f[0].children && z(f[0].children, 1);
}
var H = W.map(function(b, F) {
return {
label: b[b.length - 1],
value: g[F][g[F].length - 1]
};
});
if (B(H.map(function(b) {
return b.value;
})), i.onChange(null, H), n.length) {
var ee = g[0].length;
n.length > ee && (n = n.slice(0, ee)), n[0] = {
list: n[0].list,
index: n[0].list.findIndex(function(b) {
return b.value === g[0][0];
})
}, T(n);
} else
c[0] = {
list: s,
index: s.findIndex(function(b) {
return b.value === g[0][0];
})
}, T(c);
}
};
te(function() {
var l = _e(i.options);
i.multiple ? i.value == "" ? T([{ list: l, index: -1 }]) : Q(i.value ? i.value.split(",") : []) : i.value ? K(i.value) : T([{ list: l, index: -1 }]);
}, [i.value]);
var ve = function() {
i.onClose && i.onClose();
}, he = function(l) {
N(l.target.value);
}, pe = function(l) {
if (!i.multiple)
O(l), K(l), i.onClose();
else {
var s = $.includes(l) ? $.filter(function(n) {
return n !== l;
}) : P(P([], $, !0), [l], !1);
Q(s);
}
};
return o.jsx(o.Fragment, { children: o.jsxs(jr, { anchorEl: i.anchorEl, open: i.open, onClose: ve, children: [i.search ? o.jsx("div", { className: "cascader_search_box", children: o.jsx("input", { type: "text", placeholder: p, value: w, onChange: he, className: "cascader_search_input" }) }) : o.jsx(o.Fragment, {}), w === "" ? o.jsx("div", { className: "cascader_popover", children: v.map(function(l, s) {
return o.jsx("div", { className: "cascader_popover_cell", children: l.list.map(function(n, c) {
var u;
return o.jsxs("div", { "data-ischeckedall": (u = n.children) === null || u === void 0 ? void 0 : u.every(function(t) {
return t.checked;
}), className: n.disabled ? "cascader_popover_cell_label_box_disabled" : l.index === c || !n.children && n.checked ? "cascader_popover_cell_label_box cascader_popover_cell_label_box_ac" : "cascader_popover_cell_label_box", onClick: function() {
i.loadData ? ye(n, s, c) : xe(n, s, c);
}, children: [o.jsx("div", { className: "label", children: i.multiple ? o.jsxs(o.Fragment, { children: [o.jsx("span", { className: "icon", children: o.jsx(Je, { onClick: function(t) {
(!n.isLoad || n.children && n.children.length) && U(t, s, c);
}, checked: !!n.checked, indeterminate: n.indeterminateChecked }) }), o.jsx("div", { children: n.label })] }) : o.jsx("div", { children: n.label }) }), n.children && n.children.length > 0 || i.loadData ? o.jsx("div", { className: "cascader_popover_cell_label_box_icon", children: i.loadData && n.isLoading && n.isLoad ? o.jsx("div", { className: "cascader_popover_cell_label_box_arrow", children: o.jsx(Pr, {}) }) : n.children && n.children.length > 0 || n.isLoad ? o.jsx("div", { className: "cascader_popover_cell_label_box_arrow", children: o.jsx(Tr, {}) }) : o.jsx(o.Fragment, {}) }) : o.jsx(o.Fragment, {})] }, n.value);
}) }, s);
}) }) : o.jsx(Sr, { searchEmptyText: C, multiple: i.multiple, multipleValue: $, list: v, searchValue: w, onChoose: pe })] }) });
});
export {
Lr as Cascader
};