UNPKG

lw-json-view

Version:

使用 Vite + react 18 完成的 json 内容展示组件。

923 lines (919 loc) 35.3 kB
import Ke, { createContext as Er, useContext as Sr, useState as H, useEffect as Ge, useCallback as _r } from "react"; var Se = { exports: {} }, ne = {}; /** * @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 ze; function Rr() { if (ze) return ne; ze = 1; var r = Ke, i = Symbol.for("react.element"), s = Symbol.for("react.fragment"), l = Object.prototype.hasOwnProperty, v = r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, S = { key: !0, ref: !0, __self: !0, __source: !0 }; function R(O, f, m) { var d, T = {}, F = null, $ = null; m !== void 0 && (F = "" + m), f.key !== void 0 && (F = "" + f.key), f.ref !== void 0 && ($ = f.ref); for (d in f) l.call(f, d) && !S.hasOwnProperty(d) && (T[d] = f[d]); if (O && O.defaultProps) for (d in f = O.defaultProps, f) T[d] === void 0 && (T[d] = f[d]); return { $$typeof: i, type: O, key: F, ref: $, props: T, _owner: v.current }; } return ne.Fragment = s, ne.jsx = R, ne.jsxs = R, ne; } var ae = {}; /** * @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 Je; function Or() { return Je || (Je = 1, process.env.NODE_ENV !== "production" && function() { var r = Ke, i = Symbol.for("react.element"), s = Symbol.for("react.portal"), l = Symbol.for("react.fragment"), v = Symbol.for("react.strict_mode"), S = Symbol.for("react.profiler"), R = Symbol.for("react.provider"), O = Symbol.for("react.context"), f = Symbol.for("react.forward_ref"), m = Symbol.for("react.suspense"), d = Symbol.for("react.suspense_list"), T = Symbol.for("react.memo"), F = Symbol.for("react.lazy"), $ = Symbol.for("react.offscreen"), q = Symbol.iterator, P = "@@iterator"; function I(e) { if (e === null || typeof e != "object") return null; var t = q && e[q] || e[P]; return typeof t == "function" ? t : null; } var j = r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; function p(e) { { for (var t = arguments.length, n = new Array(t > 1 ? t - 1 : 0), o = 1; o < t; o++) n[o - 1] = arguments[o]; E("error", e, n); } } function E(e, t, n) { { var o = j.ReactDebugCurrentFrame, b = o.getStackAddendum(); b !== "" && (t += "%s", n = n.concat([b])); var x = n.map(function(g) { return String(g); }); x.unshift("Warning: " + t), Function.prototype.apply.call(console[e], console, x); } } var h = !1, k = !1, y = !1, B = !1, w = !1, _; _ = Symbol.for("react.module.reference"); function W(e) { return !!(typeof e == "string" || typeof e == "function" || e === l || e === S || w || e === v || e === m || e === d || B || e === $ || h || k || y || typeof e == "object" && e !== null && (e.$$typeof === F || e.$$typeof === T || e.$$typeof === R || e.$$typeof === O || e.$$typeof === f || // 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 === _ || e.getModuleId !== void 0)); } function re(e, t, n) { var o = e.displayName; if (o) return o; var b = t.displayName || t.name || ""; return b !== "" ? n + "(" + b + ")" : n; } function Q(e) { return e.displayName || "Context"; } function V(e) { if (e == null) return null; if (typeof e.tag == "number" && p("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 l: return "Fragment"; case s: return "Portal"; case S: return "Profiler"; case v: return "StrictMode"; case m: return "Suspense"; case d: return "SuspenseList"; } if (typeof e == "object") switch (e.$$typeof) { case O: var t = e; return Q(t) + ".Consumer"; case R: var n = e; return Q(n._context) + ".Provider"; case f: return re(e, e.render, "ForwardRef"); case T: var o = e.displayName || null; return o !== null ? o : V(e.type) || "Memo"; case F: { var b = e, x = b._payload, g = b._init; try { return V(g(x)); } catch { return null; } } } return null; } var Y = Object.assign, K = 0, A, se, M, Oe, we, Ce, Te; function ke() { } ke.__reactDisabledLog = !0; function Qe() { { if (K === 0) { A = console.log, se = console.info, M = console.warn, Oe = console.error, we = console.group, Ce = console.groupCollapsed, Te = console.groupEnd; var e = { configurable: !0, enumerable: !0, value: ke, writable: !0 }; Object.defineProperties(console, { info: e, log: e, warn: e, error: e, group: e, groupCollapsed: e, groupEnd: e }); } K++; } } function Xe() { { if (K--, K === 0) { var e = { configurable: !0, enumerable: !0, writable: !0 }; Object.defineProperties(console, { log: Y({}, e, { value: A }), info: Y({}, e, { value: se }), warn: Y({}, e, { value: M }), error: Y({}, e, { value: Oe }), group: Y({}, e, { value: we }), groupCollapsed: Y({}, e, { value: Ce }), groupEnd: Y({}, e, { value: Te }) }); } K < 0 && p("disabledDepth fell below zero. This is a bug in React. Please file an issue."); } } var be = j.ReactCurrentDispatcher, he; function le(e, t, n) { { if (he === void 0) try { throw Error(); } catch (b) { var o = b.stack.trim().match(/\n( *(at )?)/); he = o && o[1] || ""; } return ` ` + he + e; } } var ve = !1, ce; { var Ze = typeof WeakMap == "function" ? WeakMap : Map; ce = new Ze(); } function De(e, t) { if (!e || ve) return ""; { var n = ce.get(e); if (n !== void 0) return n; } var o; ve = !0; var b = Error.prepareStackTrace; Error.prepareStackTrace = void 0; var x; x = be.current, be.current = null, Qe(); try { if (t) { var g = function() { throw Error(); }; if (Object.defineProperty(g.prototype, "props", { set: function() { throw Error(); } }), typeof Reflect == "object" && Reflect.construct) { try { Reflect.construct(g, []); } catch (U) { o = U; } Reflect.construct(e, [], g); } else { try { g.call(); } catch (U) { o = U; } e.call(g.prototype); } } else { try { throw Error(); } catch (U) { o = U; } e(); } } catch (U) { if (U && o && typeof U.stack == "string") { for (var u = U.stack.split(` `), L = o.stack.split(` `), C = u.length - 1, D = L.length - 1; C >= 1 && D >= 0 && u[C] !== L[D]; ) D--; for (; C >= 1 && D >= 0; C--, D--) if (u[C] !== L[D]) { if (C !== 1 || D !== 1) do if (C--, D--, D < 0 || u[C] !== L[D]) { var N = ` ` + u[C].replace(" at new ", " at "); return e.displayName && N.includes("<anonymous>") && (N = N.replace("<anonymous>", e.displayName)), typeof e == "function" && ce.set(e, N), N; } while (C >= 1 && D >= 0); break; } } } finally { ve = !1, be.current = x, Xe(), Error.prepareStackTrace = b; } var Z = e ? e.displayName || e.name : "", Ue = Z ? le(Z) : ""; return typeof e == "function" && ce.set(e, Ue), Ue; } function er(e, t, n) { return De(e, !1); } function rr(e) { var t = e.prototype; return !!(t && t.isReactComponent); } function ue(e, t, n) { if (e == null) return ""; if (typeof e == "function") return De(e, rr(e)); if (typeof e == "string") return le(e); switch (e) { case m: return le("Suspense"); case d: return le("SuspenseList"); } if (typeof e == "object") switch (e.$$typeof) { case f: return er(e.render); case T: return ue(e.type, t, n); case F: { var o = e, b = o._payload, x = o._init; try { return ue(x(b), t, n); } catch { } } } return ""; } var fe = Object.prototype.hasOwnProperty, Pe = {}, Ae = j.ReactDebugCurrentFrame; function de(e) { if (e) { var t = e._owner, n = ue(e.type, e._source, t ? t.type : null); Ae.setExtraStackFrame(n); } else Ae.setExtraStackFrame(null); } function tr(e, t, n, o, b) { { var x = Function.call.bind(fe); for (var g in e) if (x(e, g)) { var u = void 0; try { if (typeof e[g] != "function") { var L = Error((o || "React class") + ": " + n + " type `" + g + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof e[g] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`."); throw L.name = "Invariant Violation", L; } u = e[g](t, g, o, n, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"); } catch (C) { u = C; } u && !(u instanceof Error) && (de(b), p("%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).", o || "React class", n, g, typeof u), de(null)), u instanceof Error && !(u.message in Pe) && (Pe[u.message] = !0, de(b), p("Failed %s type: %s", n, u.message), de(null)); } } } var nr = Array.isArray; function ye(e) { return nr(e); } function ar(e) { { var t = typeof Symbol == "function" && Symbol.toStringTag, n = t && e[Symbol.toStringTag] || e.constructor.name || "Object"; return n; } } function ir(e) { try { return Fe(e), !1; } catch { return !0; } } function Fe(e) { return "" + e; } function Ie(e) { if (ir(e)) return p("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", ar(e)), Fe(e); } var te = j.ReactCurrentOwner, or = { key: !0, ref: !0, __self: !0, __source: !0 }, Le, Ve, xe; xe = {}; function sr(e) { if (fe.call(e, "ref")) { var t = Object.getOwnPropertyDescriptor(e, "ref").get; if (t && t.isReactWarning) return !1; } return e.ref !== void 0; } function lr(e) { if (fe.call(e, "key")) { var t = Object.getOwnPropertyDescriptor(e, "key").get; if (t && t.isReactWarning) return !1; } return e.key !== void 0; } function cr(e, t) { if (typeof e.ref == "string" && te.current && t && te.current.stateNode !== t) { var n = V(te.current.type); xe[n] || (p('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', V(te.current.type), e.ref), xe[n] = !0); } } function ur(e, t) { { var n = function() { Le || (Le = !0, p("%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)", t)); }; n.isReactWarning = !0, Object.defineProperty(e, "key", { get: n, configurable: !0 }); } } function fr(e, t) { { var n = function() { Ve || (Ve = !0, p("%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)", t)); }; n.isReactWarning = !0, Object.defineProperty(e, "ref", { get: n, configurable: !0 }); } } var dr = function(e, t, n, o, b, x, g) { var u = { // This tag allows us to uniquely identify this as a React Element $$typeof: i, // Built-in properties that belong on the element type: e, key: t, ref: n, props: g, // Record the component responsible for creating this element. _owner: x }; return u._store = {}, Object.defineProperty(u._store, "validated", { configurable: !1, enumerable: !1, writable: !0, value: !1 }), Object.defineProperty(u, "_self", { configurable: !1, enumerable: !1, writable: !1, value: o }), Object.defineProperty(u, "_source", { configurable: !1, enumerable: !1, writable: !1, value: b }), Object.freeze && (Object.freeze(u.props), Object.freeze(u)), u; }; function pr(e, t, n, o, b) { { var x, g = {}, u = null, L = null; n !== void 0 && (Ie(n), u = "" + n), lr(t) && (Ie(t.key), u = "" + t.key), sr(t) && (L = t.ref, cr(t, b)); for (x in t) fe.call(t, x) && !or.hasOwnProperty(x) && (g[x] = t[x]); if (e && e.defaultProps) { var C = e.defaultProps; for (x in C) g[x] === void 0 && (g[x] = C[x]); } if (u || L) { var D = typeof e == "function" ? e.displayName || e.name || "Unknown" : e; u && ur(g, D), L && fr(g, D); } return dr(e, u, L, b, o, te.current, g); } } var me = j.ReactCurrentOwner, $e = j.ReactDebugCurrentFrame; function X(e) { if (e) { var t = e._owner, n = ue(e.type, e._source, t ? t.type : null); $e.setExtraStackFrame(n); } else $e.setExtraStackFrame(null); } var je; je = !1; function Ee(e) { return typeof e == "object" && e !== null && e.$$typeof === i; } function Be() { { if (me.current) { var e = V(me.current.type); if (e) return ` Check the render method of \`` + e + "`."; } return ""; } } function gr(e) { { if (e !== void 0) { var t = e.fileName.replace(/^.*[\\\/]/, ""), n = e.lineNumber; return ` Check your code at ` + t + ":" + n + "."; } return ""; } } var Ne = {}; function br(e) { { var t = Be(); if (!t) { var n = typeof e == "string" ? e : e.displayName || e.name; n && (t = ` Check the top-level render call using <` + n + ">."); } return t; } } function Me(e, t) { { if (!e._store || e._store.validated || e.key != null) return; e._store.validated = !0; var n = br(t); if (Ne[n]) return; Ne[n] = !0; var o = ""; e && e._owner && e._owner !== me.current && (o = " It was passed a child from " + V(e._owner.type) + "."), X(e), p('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', n, o), X(null); } } function We(e, t) { { if (typeof e != "object") return; if (ye(e)) for (var n = 0; n < e.length; n++) { var o = e[n]; Ee(o) && Me(o, t); } else if (Ee(e)) e._store && (e._store.validated = !0); else if (e) { var b = I(e); if (typeof b == "function" && b !== e.entries) for (var x = b.call(e), g; !(g = x.next()).done; ) Ee(g.value) && Me(g.value, t); } } } function hr(e) { { var t = e.type; if (t == null || typeof t == "string") return; var n; if (typeof t == "function") n = t.propTypes; else if (typeof t == "object" && (t.$$typeof === f || // Note: Memo only checks outer props here. // Inner props are checked in the reconciler. t.$$typeof === T)) n = t.propTypes; else return; if (n) { var o = V(t); tr(n, e.props, "prop", o, e); } else if (t.PropTypes !== void 0 && !je) { je = !0; var b = V(t); p("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", b || "Unknown"); } typeof t.getDefaultProps == "function" && !t.getDefaultProps.isReactClassApproved && p("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead."); } } function vr(e) { { for (var t = Object.keys(e.props), n = 0; n < t.length; n++) { var o = t[n]; if (o !== "children" && o !== "key") { X(e), p("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", o), X(null); break; } } e.ref !== null && (X(e), p("Invalid attribute `ref` supplied to `React.Fragment`."), X(null)); } } function Ye(e, t, n, o, b, x) { { var g = W(e); if (!g) { var u = ""; (e === void 0 || typeof e == "object" && e !== null && Object.keys(e).length === 0) && (u += " 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 L = gr(b); L ? u += L : u += Be(); var C; e === null ? C = "null" : ye(e) ? C = "array" : e !== void 0 && e.$$typeof === i ? (C = "<" + (V(e.type) || "Unknown") + " />", u = " Did you accidentally export a JSX literal instead of a component?") : C = typeof e, p("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", C, u); } var D = pr(e, t, n, b, x); if (D == null) return D; if (g) { var N = t.children; if (N !== void 0) if (o) if (ye(N)) { for (var Z = 0; Z < N.length; Z++) We(N[Z], e); Object.freeze && Object.freeze(N); } else p("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 We(N, e); } return e === l ? vr(D) : hr(D), D; } } function yr(e, t, n) { return Ye(e, t, n, !0); } function xr(e, t, n) { return Ye(e, t, n, !1); } var mr = xr, jr = yr; ae.Fragment = l, ae.jsx = mr, ae.jsxs = jr; }()), ae; } process.env.NODE_ENV === "production" ? Se.exports = Rr() : Se.exports = Or(); var a = Se.exports; const qe = { background: "#fff", primary: "#000", secondary: "#E6E6E6", string: "red", number: "#00A000", boolean: "#5558cc", null: "#FFA0CB", undefined: "#DEB887", BigInt: "#800080", Date: "", type: "#808080", ellipsis: "#DDD", link: "#0366D6" }, wr = { background: "#000", primary: "#CCC", secondary: "#333", string: "#FFA500", number: "#00A000", boolean: "#09E", null: "#FFA0CB", undefined: "#DEB887", BigInt: "#E000A0", Date: "", type: "#808080", ellipsis: "#DDD", link: "#0366D6" }, ge = (r) => r === "light" || r === "default" ? qe : r === "dark" ? wr : typeof r == "string" ? (console.warn("Invalid theme"), qe) : Object.assign({}, r), z = { indent: 54, showStringQuotes: !0, defaultExpanded: !0, defaultExpandDepth: 1, iconSize: 16, selectable: !1, showValueTypes: !0, selectedValue: null, stringMaxLength: 16, selectedInfo: { selectedDict: {}, indeterminateDict: {} }, theme: ge("light"), onSelect: () => { }, selectValueCandidate: void 0, selectableDict: {} }, He = Er(z); function J() { return Sr(He); } var c; (function(r) { r.String = "string", r.Number = "number", r.Boolean = "boolean", r.Object = "object", r.Array = "array", r.Null = "null", r.Undefined = "undefined", r.Function = "function", r.Symbol = "symbol", r.BigInt = "bigint", r.Date = "date"; })(c || (c = {})); const Cr = { boolean: c.Boolean, number: c.Number, string: c.String, object: c.Object, function: c.Function, symbol: c.Symbol, bigint: c.BigInt, undefined: c.Undefined, date: c.Date, array: c.Array }, oe = (r) => r === null ? c.Null : Array.isArray(r) ? c.Array : r instanceof Date ? c.Date : Cr[typeof r], ie = (r) => r === void 0, G = (r) => typeof r != "object" || r === null ? !0 : Object.keys(r).length > 0, pe = (r) => { const i = oe(r); return i === c.Object || i === c.Array; }, Tr = (r) => /^(https?|ftp):\/\/[^\s/$.?#].[^\s]*$/.test(r); function _e({ onClick: r, style: i }) { const { theme: s } = J(); return a.jsx("span", { onClick: r, style: Object.assign({ cursor: "pointer", background: s.ellipsis, borderRadius: "4px", padding: "0 5px", margin: "0 2px", color: s.primary }, i || {}), children: "..." }); } function kr({ value: r, depth: i, parent: s, keyName: l, toggleExpand: v, candidate: S, expanded: R = !1 }) { const O = Object.keys(r), f = R ? O.map((d, T) => a.jsx(Re, { keyName: d, value: r[d], depth: i + 1, isLast: T + 1 === O.length, parent: { keyName: l, parent: s, value: r }, candidate: S ? S[d] : r[d] }, d)) : G(r) ? a.jsx(_e, { onClick: () => v(!0) }) : null, m = { display: R ? "block" : "inline" }; return a.jsx("div", { style: m, children: f }); } function ee({ valueType: r }) { const { theme: i } = J(); return a.jsx("span", { style: { color: i.type, marginLeft: "5px", fontStyle: "italic" }, children: r }); } function Dr({ value: r, isLast: i }) { const { showValueTypes: s, theme: l, stringMaxLength: v } = J(), S = v && r.length > v, [R, O] = H(S), f = () => { O(!R); }, m = Tr(r), d = m ? l.link : l.string, T = m ? a.jsx("a", { style: { color: d }, href: r, target: "_blank", children: r.slice(0, v) }) : r.slice(0, v), F = m ? a.jsx("a", { style: { color: d }, href: r, target: "_blank", children: r }) : r; return a.jsxs("span", { style: { color: d, whiteSpace: R ? "nowrap" : "normal" }, children: ['"', R ? a.jsxs(a.Fragment, { children: [T, a.jsx(_e, { style: { background: "transparent", color: d, padding: 0 }, onClick: f })] }) : a.jsx("span", { style: { cursor: !S || R ? "text" : "pointer" }, onClick: () => S && !m ? O(!0) : void 0, children: F }), '"', i ? null : a.jsx("span", { style: { color: "gray", marginLeft: "2px" }, children: "," }), s ? a.jsx(ee, { valueType: c.String }) : null] }); } function Pr({ expanded: r = !1, color: i = "#bfbfbf", onClick: s = (v) => console.log("onClick: ", v), size: l = 22 }) { const v = r ? 0 : -90; return a.jsx("span", { children: a.jsx("svg", { className: "icon", viewBox: "0 0 1024 1024", version: "1.1", xmlns: "http://www.w3.org/2000/svg", "p-id": "4265", width: l, height: l, onClick: () => s(!r), style: { transform: `rotate(${v}deg)`, cursor: "pointer", verticalAlign: "middle" }, children: a.jsx("path", { d: "M512 704.412l311.598-311.598-73.226-73.226L512 557.441 273.627 319.588l-73.226 73.226L512 704.412z", "p-id": "4266", fill: i }) }) }); } function Ar({ value: r, isLast: i }) { const { showValueTypes: s, theme: l } = J(); return a.jsxs("span", { style: { color: l.number }, children: [r, i ? null : a.jsx("span", { style: { color: "gray", marginLeft: "5px" }, children: "," }), s ? a.jsx(ee, { valueType: c.Number }) : null] }); } function Fr({ value: r, depth: i, keyName: s, parent: l, toggleExpand: v, candidate: S, expanded: R = !1 }) { const O = R ? r.map((m, d) => a.jsx(Re, { keyName: d, value: m, depth: i + 1, isLast: d + 1 === r.length, parent: { keyName: s, parent: l, value: r }, candidate: S ? S[d] : m }, d)) : G(r) ? a.jsx(_e, { onClick: () => v(!0) }) : null, f = { display: R ? "block" : "inline" }; return a.jsx("div", { style: f, children: O }); } function Ir({ value: r, isLast: i }) { const { showValueTypes: s, theme: l } = J(); return a.jsxs("span", { style: { color: l.boolean }, children: [r ? "true" : "false", i ? null : a.jsx("span", { style: { color: "gray", marginLeft: "2px" }, children: "," }), s ? a.jsx(ee, { valueType: c.Boolean }) : null] }); } function Lr({ value: r, isLast: i }) { const { showValueTypes: s, theme: l } = J(); return a.jsxs("span", { style: { color: l.BigInt }, children: [String(r), i ? null : a.jsx("span", { style: { color: "gray", marginLeft: "2px" }, children: "," }), s ? a.jsx(ee, { valueType: c.BigInt }) : null] }); } function Vr({ value: r, isLast: i }) { const { showValueTypes: s, theme: l } = J(); return a.jsxs("span", { style: { color: l.null }, children: [r || "null", i ? null : a.jsx("span", { style: { color: "gray", marginLeft: "2px" }, children: "," }), s ? a.jsx(ee, { valueType: c.Null }) : null] }); } const $r = { border: "2px solid white", width: "6px", height: "8px", borderTop: "0", borderInlineStart: 0, insetInlineStart: "25%", top: "55%", transform: "rotate(45deg) translate(-50%,-50%)" }, Br = { width: "8px", height: "8px", background: "#1890ff", border: "0", transform: "translate(-50%,-50%)", top: "50%", left: "50%" }; function Nr({ checked: r, onChange: i, indeterminate: s, style: l }) { const v = r && s ? Br : $r; return a.jsxs("span", { style: Object.assign({ display: "inline-block", position: "relative", whiteSpace: "nowrap", verticalAlign: "middle", cursor: "pointer", height: "fit-content", boxSizing: "border-box" }, l), onClick: () => i(!(!s && r)), children: [a.jsx("input", { style: { position: "absolute", opacity: 0, pointerEvents: "none" }, type: "checkbox", checked: r, readOnly: !0 }), a.jsx("span", { style: { display: "block", width: "16px", height: "16px", border: "1px solid #d9d9d9", borderRadius: "4px", boxSizing: "border-box", background: r && !s ? "#1890ff" : "white" } }), a.jsx("span", { style: Object.assign({ display: r ? "block" : "none", position: "absolute", boxSizing: "border-box" }, v) })] }); } function Mr({ value: r, isLast: i }) { const { showValueTypes: s, theme: l } = J(); return a.jsxs("span", { style: { color: l.undefined }, children: [r || "undefined", i ? null : a.jsx("span", { style: { color: "gray", marginLeft: "2px" }, children: "," }), s ? a.jsx(ee, { valueType: c.Undefined }) : null] }); } function Re({ keyName: r, value: i, depth: s = 0, isLast: l, parent: v, candidate: S }) { const { showStringQuotes: R, indent: O, iconSize: f, defaultExpandDepth: m, defaultExpanded: d, selectedInfo: T, theme: F, onSelect: $, selectableDict: q } = J(), [P, I] = H(d && s < m), j = (A) => { I(A); }, p = a.jsx(Pr, { expanded: P, onClick: j, size: f }), E = (A) => { const se = oe(A), M = { keyName: r, isLast: l, parent: v, candidate: S }; switch (se) { case c.String: return a.jsx(Dr, Object.assign({ value: A }, M)); case c.Object: return a.jsx(kr, Object.assign({ value: A, expanded: P, depth: s, toggleExpand: j }, M)); case c.Array: return a.jsx(Fr, Object.assign({ value: A, expanded: P, depth: s, toggleExpand: j }, M)); case c.Number: return a.jsx(Ar, Object.assign({ value: A }, M)); case c.Boolean: return a.jsx(Ir, Object.assign({ value: A }, M)); case c.BigInt: return a.jsx(Lr, Object.assign({ value: A }, M)); case c.Null: return a.jsx(Vr, Object.assign({ value: A }, M)); case c.Undefined: return a.jsx(Mr, Object.assign({ value: A }, M)); default: return a.jsxs("span", { style: { color: "red" }, children: [String(A), " // TODO"] }); } }, h = oe(i), k = [c.Object, c.Array].includes(h); let y = "", B = ""; k && (h === c.Object ? (y = "{", B = "}") : h === c.Array && (y = "[", B = "]")); let w = r === void 0 ? "" : String(r), _ = v; for (; _; ) w = `${_.keyName === void 0 ? "" : _.keyName}.${w}`, _ = _.parent; const W = T.selectedDict, re = T.indeterminateDict; let Q = !1, V = !1; const Y = q[w]; re[w] && (Q = !0), W[w] ? V = !0 : (V = !1, Q = !1); const K = (s ? O : f) - (k && !Y ? f : 0); return a.jsxs("div", { style: { marginLeft: `${K}px`, padding: "2px 0", // paddingLeft: !depth ? "25px" : "0", boxSizing: "border-box", color: F.primary }, children: [Y ? a.jsx(Nr, { style: { marginRight: "4px" }, checked: V, indeterminate: Q, onChange: (A) => { $ && $({ keyPath: w.split(".").slice(1), checked: A, depth: s, candidateValue: S }); } }) : null, a.jsx("span", { children: k ? p : null }), r !== void 0 && typeof r != "number" && a.jsxs("span", { children: [R ? `"${r}"` : r, a.jsx("span", { style: { margin: "0 5px" }, children: ":" })] }), k ? a.jsx("span", { children: y }) : null, h === c.Object || h === c.Array ? a.jsx("div", { style: { display: P ? "block" : "inline-block" }, children: E(i) }) : E(i), k ? a.jsxs("span", { style: { marginLeft: P ? `${f}px` : "0" }, children: [B, l ? null : a.jsx("span", { style: { color: "gray", marginLeft: "5px" }, children: "," })] }) : null] }); } function Wr(r, i, s, l) { return typeof r == "boolean" ? r : Array.isArray(r) ? r.includes(s) : r(i, s, l); } function Yr({ selectable: r, value: i, onSelect: s }) { const v = oe(i) === "object" ? {} : [], [S, R] = H(v), [O, f] = H({ selectedDict: {}, indeterminateDict: {} }), [m, d] = H(v), [T, F] = H({}); Ge(() => { const P = structuredClone(i), I = {}, j = (p, E, h, k, y) => { const B = Wr(r, E, h, p); B ? I[k] = !0 : y && pe(y) && delete y[h], pe(p) && (Object.keys(p).forEach((_) => { const W = p[_], re = E ? y ? y[h] : void 0 : P; j(W, E + 1, _, `${k}.${_}`, re); }), B && y && !G(y[h]) && (y[h] = structuredClone(p)), !E && G(P) && (I[""] = !0)); }; j(i, 0, "", "", P), d(P), F(I); }, [i, r]); const $ = (P) => { const I = {}, j = {}, p = (E, h, k, y) => { !h && !G(E) || (I[k] = !0, pe(E) && (G(y) && Object.keys(y).length > 0 && Object.keys(y).length !== Object.keys(E).length && (j[k] = !0), Object.keys(E).forEach((w) => { const _ = E[w], W = y[w]; p(_, h + 1, `${k}.${w}`, W); }))); }; p(P, 0, "", m), f({ selectedDict: I, indeterminateDict: j }); }; return { selectedValue: S, selectedInfo: O, selectCandidate: m, innerOnSelect: ({ depth: P, candidateValue: I, checked: j, keyPath: p }) => { let E = structuredClone(S); if (!P) E = structuredClone(j ? I : v); else { let h = E, k = m; const y = []; for (let w = 0; w < p.length - 1; w++) { const _ = p[w]; pe(h) && h[_] === void 0 && (h[_] = oe(k) === "object" ? {} : []), y.push({ value: h, key: _ }), h = h[_], k = k[_]; } const B = p[p.length - 1]; if (j) h[B] = structuredClone(I); else { delete h[B]; for (let w = y.length - 1; w >= 0; w--) { const { value: _, key: W } = y[w]; G(_[W]) || delete _[W]; } } } R(E), $(E), s && s(p.pop(), E, j); }, selectableDict: T }; } const zr = function({ value: r, selectable: i, showStringQuotes: s, defaultExpanded: l, defaultExpandDepth: v, showValueTypes: S, iconSize: R, stringMaxLength: O, theme: f = "default", onSelect: m, className: d, style: T }) { const { selectedInfo: F, selectCandidate: $, innerOnSelect: q, selectableDict: P } = Yr({ selectable: i || !1, value: r, defaultSelect: !1, onSelect: m }), I = (y) => { q(y); }, j = f === "default" ? window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light" : f, [p, E] = H(ge(j)), h = _r((y) => { f === "default" && E(ge(y.matches ? "dark" : "light")); }, [f]); Ge(() => { if (E(ge(j)), f === "default") return window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", h), () => { window.matchMedia("(prefers-color-scheme: dark)").removeEventListener("change", h); }; }, [j, f, h]); const k = Object.assign(Object.assign({}, z), { selectable: ie(i) ? z.selectable : i, showStringQuotes: ie(s) ? z.showStringQuotes : s, iconSize: R || z.iconSize, defaultExpanded: ie(l) ? z.defaultExpanded : l, defaultExpandDepth: v || z.defaultExpandDepth, showValueTypes: ie(S) ? z.showValueTypes : S, stringMaxLength: ie(O) ? z.stringMaxLength : O, theme: p, selectValueCandidate: $, selectedInfo: F, selectableDict: P }); return a.jsx(He.Provider, { value: Object.assign(Object.assign({}, k), { onSelect: I }), children: a.jsx("div", { className: d, style: Object.assign({ fontSize: "14px", fontFamily: "Consolas, Menlo, Courier, monospace", boxSizing: "border-box" }, T), children: a.jsx(Re, { value: r, defaultExpanded: !1, isLast: !0, candidate: $ }) }) }); }; export { zr as default };