lw-json-view
Version:
使用 Vite + react 18 完成的 json 内容展示组件。
28 lines (24 loc) • 24.9 kB
JavaScript
(function(P,G){typeof exports=="object"&&typeof module<"u"?module.exports=G(require("react")):typeof define=="function"&&define.amd?define(["react"],G):(P=typeof globalThis<"u"?globalThis:P||self,P["json-view"]=G(P.require$$0))})(this,function(P){"use strict";var G={exports:{}},re={};/**
* @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 Oe;function He(){if(Oe)return re;Oe=1;var t=P,o=Symbol.for("react.element"),s=Symbol.for("react.fragment"),c=Object.prototype.hasOwnProperty,v=t.__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={},I=null,N=null;m!==void 0&&(I=""+m),f.key!==void 0&&(I=""+f.key),f.ref!==void 0&&(N=f.ref);for(d in f)c.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:o,type:O,key:I,ref:N,props:T,_owner:v.current}}return re.Fragment=s,re.jsx=R,re.jsxs=R,re}var ne={};/**
* @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 we;function Qe(){return we||(we=1,process.env.NODE_ENV!=="production"&&function(){var t=P,o=Symbol.for("react.element"),s=Symbol.for("react.portal"),c=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"),I=Symbol.for("react.lazy"),N=Symbol.for("react.offscreen"),Q=Symbol.iterator,A="@@iterator";function V(e){if(e===null||typeof e!="object")return null;var r=Q&&e[Q]||e[A];return typeof r=="function"?r:null}var j=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function p(e){{for(var r=arguments.length,n=new Array(r>1?r-1:0),i=1;i<r;i++)n[i-1]=arguments[i];E("error",e,n)}}function E(e,r,n){{var i=j.ReactDebugCurrentFrame,b=i.getStackAddendum();b!==""&&(r+="%s",n=n.concat([b]));var x=n.map(function(g){return String(g)});x.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,x)}}var h=!1,k=!1,y=!1,M=!1,w=!1,_;_=Symbol.for("react.module.reference");function U(e){return!!(typeof e=="string"||typeof e=="function"||e===c||e===S||w||e===v||e===m||e===d||M||e===N||h||k||y||typeof e=="object"&&e!==null&&(e.$$typeof===I||e.$$typeof===T||e.$$typeof===R||e.$$typeof===O||e.$$typeof===f||e.$$typeof===_||e.getModuleId!==void 0))}function ie(e,r,n){var i=e.displayName;if(i)return i;var b=r.displayName||r.name||"";return b!==""?n+"("+b+")":n}function q(e){return e.displayName||"Context"}function B(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 c: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 r=e;return q(r)+".Consumer";case R:var n=e;return q(n._context)+".Provider";case f:return ie(e,e.render,"ForwardRef");case T:var i=e.displayName||null;return i!==null?i:B(e.type)||"Memo";case I:{var b=e,x=b._payload,g=b._init;try{return B(g(x))}catch{return null}}}return null}var z=Object.assign,X=0,F,ue,Y,ke,De,Pe,Ae;function Fe(){}Fe.__reactDisabledLog=!0;function gt(){{if(X===0){F=console.log,ue=console.info,Y=console.warn,ke=console.error,De=console.group,Pe=console.groupCollapsed,Ae=console.groupEnd;var e={configurable:!0,enumerable:!0,value:Fe,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}X++}}function bt(){{if(X--,X===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:z({},e,{value:F}),info:z({},e,{value:ue}),warn:z({},e,{value:Y}),error:z({},e,{value:ke}),group:z({},e,{value:De}),groupCollapsed:z({},e,{value:Pe}),groupEnd:z({},e,{value:Ae})})}X<0&&p("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var ye=j.ReactCurrentDispatcher,xe;function fe(e,r,n){{if(xe===void 0)try{throw Error()}catch(b){var i=b.stack.trim().match(/\n( *(at )?)/);xe=i&&i[1]||""}return`
`+xe+e}}var me=!1,de;{var ht=typeof WeakMap=="function"?WeakMap:Map;de=new ht}function Ie(e,r){if(!e||me)return"";{var n=de.get(e);if(n!==void 0)return n}var i;me=!0;var b=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var x;x=ye.current,ye.current=null,gt();try{if(r){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(K){i=K}Reflect.construct(e,[],g)}else{try{g.call()}catch(K){i=K}e.call(g.prototype)}}else{try{throw Error()}catch(K){i=K}e()}}catch(K){if(K&&i&&typeof K.stack=="string"){for(var u=K.stack.split(`
`),L=i.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 W=`
`+u[C].replace(" at new "," at ");return e.displayName&&W.includes("<anonymous>")&&(W=W.replace("<anonymous>",e.displayName)),typeof e=="function"&&de.set(e,W),W}while(C>=1&&D>=0);break}}}finally{me=!1,ye.current=x,bt(),Error.prepareStackTrace=b}var te=e?e.displayName||e.name:"",Ge=te?fe(te):"";return typeof e=="function"&&de.set(e,Ge),Ge}function vt(e,r,n){return Ie(e,!1)}function yt(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function pe(e,r,n){if(e==null)return"";if(typeof e=="function")return Ie(e,yt(e));if(typeof e=="string")return fe(e);switch(e){case m:return fe("Suspense");case d:return fe("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case f:return vt(e.render);case T:return pe(e.type,r,n);case I:{var i=e,b=i._payload,x=i._init;try{return pe(x(b),r,n)}catch{}}}return""}var ge=Object.prototype.hasOwnProperty,Ve={},Le=j.ReactDebugCurrentFrame;function be(e){if(e){var r=e._owner,n=pe(e.type,e._source,r?r.type:null);Le.setExtraStackFrame(n)}else Le.setExtraStackFrame(null)}function xt(e,r,n,i,b){{var x=Function.call.bind(ge);for(var g in e)if(x(e,g)){var u=void 0;try{if(typeof e[g]!="function"){var L=Error((i||"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](r,g,i,n,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(C){u=C}u&&!(u instanceof Error)&&(be(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).",i||"React class",n,g,typeof u),be(null)),u instanceof Error&&!(u.message in Ve)&&(Ve[u.message]=!0,be(b),p("Failed %s type: %s",n,u.message),be(null))}}}var mt=Array.isArray;function je(e){return mt(e)}function jt(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,n=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return n}}function Et(e){try{return Be(e),!1}catch{return!0}}function Be(e){return""+e}function Ne(e){if(Et(e))return p("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",jt(e)),Be(e)}var se=j.ReactCurrentOwner,St={key:!0,ref:!0,__self:!0,__source:!0},Me,We,Ee;Ee={};function _t(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 Rt(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 Ot(e,r){if(typeof e.ref=="string"&&se.current&&r&&se.current.stateNode!==r){var n=B(se.current.type);Ee[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',B(se.current.type),e.ref),Ee[n]=!0)}}function wt(e,r){{var n=function(){Me||(Me=!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)",r))};n.isReactWarning=!0,Object.defineProperty(e,"key",{get:n,configurable:!0})}}function Ct(e,r){{var n=function(){We||(We=!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)",r))};n.isReactWarning=!0,Object.defineProperty(e,"ref",{get:n,configurable:!0})}}var Tt=function(e,r,n,i,b,x,g){var u={$$typeof:o,type:e,key:r,ref:n,props:g,_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:i}),Object.defineProperty(u,"_source",{configurable:!1,enumerable:!1,writable:!1,value:b}),Object.freeze&&(Object.freeze(u.props),Object.freeze(u)),u};function kt(e,r,n,i,b){{var x,g={},u=null,L=null;n!==void 0&&(Ne(n),u=""+n),Rt(r)&&(Ne(r.key),u=""+r.key),_t(r)&&(L=r.ref,Ot(r,b));for(x in r)ge.call(r,x)&&!St.hasOwnProperty(x)&&(g[x]=r[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&&wt(g,D),L&&Ct(g,D)}return Tt(e,u,L,b,i,se.current,g)}}var Se=j.ReactCurrentOwner,Ye=j.ReactDebugCurrentFrame;function ee(e){if(e){var r=e._owner,n=pe(e.type,e._source,r?r.type:null);Ye.setExtraStackFrame(n)}else Ye.setExtraStackFrame(null)}var _e;_e=!1;function Re(e){return typeof e=="object"&&e!==null&&e.$$typeof===o}function Ue(){{if(Se.current){var e=B(Se.current.type);if(e)return`
Check the render method of \``+e+"`."}return""}}function Dt(e){{if(e!==void 0){var r=e.fileName.replace(/^.*[\\\/]/,""),n=e.lineNumber;return`
Check your code at `+r+":"+n+"."}return""}}var ze={};function Pt(e){{var r=Ue();if(!r){var n=typeof e=="string"?e:e.displayName||e.name;n&&(r=`
Check the top-level render call using <`+n+">.")}return r}}function $e(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var n=Pt(r);if(ze[n])return;ze[n]=!0;var i="";e&&e._owner&&e._owner!==Se.current&&(i=" It was passed a child from "+B(e._owner.type)+"."),ee(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,i),ee(null)}}function Je(e,r){{if(typeof e!="object")return;if(je(e))for(var n=0;n<e.length;n++){var i=e[n];Re(i)&&$e(i,r)}else if(Re(e))e._store&&(e._store.validated=!0);else if(e){var b=V(e);if(typeof b=="function"&&b!==e.entries)for(var x=b.call(e),g;!(g=x.next()).done;)Re(g.value)&&$e(g.value,r)}}}function At(e){{var r=e.type;if(r==null||typeof r=="string")return;var n;if(typeof r=="function")n=r.propTypes;else if(typeof r=="object"&&(r.$$typeof===f||r.$$typeof===T))n=r.propTypes;else return;if(n){var i=B(r);xt(n,e.props,"prop",i,e)}else if(r.PropTypes!==void 0&&!_e){_e=!0;var b=B(r);p("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",b||"Unknown")}typeof r.getDefaultProps=="function"&&!r.getDefaultProps.isReactClassApproved&&p("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Ft(e){{for(var r=Object.keys(e.props),n=0;n<r.length;n++){var i=r[n];if(i!=="children"&&i!=="key"){ee(e),p("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",i),ee(null);break}}e.ref!==null&&(ee(e),p("Invalid attribute `ref` supplied to `React.Fragment`."),ee(null))}}function Ke(e,r,n,i,b,x){{var g=U(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=Dt(b);L?u+=L:u+=Ue();var C;e===null?C="null":je(e)?C="array":e!==void 0&&e.$$typeof===o?(C="<"+(B(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=kt(e,r,n,b,x);if(D==null)return D;if(g){var W=r.children;if(W!==void 0)if(i)if(je(W)){for(var te=0;te<W.length;te++)Je(W[te],e);Object.freeze&&Object.freeze(W)}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 Je(W,e)}return e===c?Ft(D):At(D),D}}function It(e,r,n){return Ke(e,r,n,!0)}function Vt(e,r,n){return Ke(e,r,n,!1)}var Lt=Vt,Bt=It;ne.Fragment=c,ne.jsx=Lt,ne.jsxs=Bt}()),ne}process.env.NODE_ENV==="production"?G.exports=He():G.exports=Qe();var a=G.exports;const Ce={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"},Xe={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"},le=t=>t==="light"||t==="default"?Ce:t==="dark"?Xe:typeof t=="string"?(console.warn("Invalid theme"),Ce):Object.assign({},t),$={indent:54,showStringQuotes:!0,defaultExpanded:!0,defaultExpandDepth:1,iconSize:16,selectable:!1,showValueTypes:!0,selectedValue:null,stringMaxLength:16,selectedInfo:{selectedDict:{},indeterminateDict:{}},theme:le("light"),onSelect:()=>{},selectValueCandidate:void 0,selectableDict:{}},Te=P.createContext($);function J(){return P.useContext(Te)}var l;(function(t){t.String="string",t.Number="number",t.Boolean="boolean",t.Object="object",t.Array="array",t.Null="null",t.Undefined="undefined",t.Function="function",t.Symbol="symbol",t.BigInt="bigint",t.Date="date"})(l||(l={}));const Ze={boolean:l.Boolean,number:l.Number,string:l.String,object:l.Object,function:l.Function,symbol:l.Symbol,bigint:l.BigInt,undefined:l.Undefined,date:l.Date,array:l.Array},ae=t=>t===null?l.Null:Array.isArray(t)?l.Array:t instanceof Date?l.Date:Ze[typeof t],oe=t=>t===void 0,H=t=>typeof t!="object"||t===null?!0:Object.keys(t).length>0,ce=t=>{const o=ae(t);return o===l.Object||o===l.Array},qe=t=>/^(https?|ftp):\/\/[^\s/$.?#].[^\s]*$/.test(t);function he({onClick:t,style:o}){const{theme:s}=J();return a.jsx("span",{onClick:t,style:Object.assign({cursor:"pointer",background:s.ellipsis,borderRadius:"4px",padding:"0 5px",margin:"0 2px",color:s.primary},o||{}),children:"..."})}function et({value:t,depth:o,parent:s,keyName:c,toggleExpand:v,candidate:S,expanded:R=!1}){const O=Object.keys(t),f=R?O.map((d,T)=>a.jsx(ve,{keyName:d,value:t[d],depth:o+1,isLast:T+1===O.length,parent:{keyName:c,parent:s,value:t},candidate:S?S[d]:t[d]},d)):H(t)?a.jsx(he,{onClick:()=>v(!0)}):null,m={display:R?"block":"inline"};return a.jsx("div",{style:m,children:f})}function Z({valueType:t}){const{theme:o}=J();return a.jsx("span",{style:{color:o.type,marginLeft:"5px",fontStyle:"italic"},children:t})}function tt({value:t,isLast:o}){const{showValueTypes:s,theme:c,stringMaxLength:v}=J(),S=v&&t.length>v,[R,O]=P.useState(S),f=()=>{O(!R)},m=qe(t),d=m?c.link:c.string,T=m?a.jsx("a",{style:{color:d},href:t,target:"_blank",children:t.slice(0,v)}):t.slice(0,v),I=m?a.jsx("a",{style:{color:d},href:t,target:"_blank",children:t}):t;return a.jsxs("span",{style:{color:d,whiteSpace:R?"nowrap":"normal"},children:['"',R?a.jsxs(a.Fragment,{children:[T,a.jsx(he,{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:I}),'"',o?null:a.jsx("span",{style:{color:"gray",marginLeft:"2px"},children:","}),s?a.jsx(Z,{valueType:l.String}):null]})}function rt({expanded:t=!1,color:o="#bfbfbf",onClick:s=v=>console.log("onClick: ",v),size:c=22}){const v=t?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:c,height:c,onClick:()=>s(!t),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:o})})})}function nt({value:t,isLast:o}){const{showValueTypes:s,theme:c}=J();return a.jsxs("span",{style:{color:c.number},children:[t,o?null:a.jsx("span",{style:{color:"gray",marginLeft:"5px"},children:","}),s?a.jsx(Z,{valueType:l.Number}):null]})}function at({value:t,depth:o,keyName:s,parent:c,toggleExpand:v,candidate:S,expanded:R=!1}){const O=R?t.map((m,d)=>a.jsx(ve,{keyName:d,value:m,depth:o+1,isLast:d+1===t.length,parent:{keyName:s,parent:c,value:t},candidate:S?S[d]:m},d)):H(t)?a.jsx(he,{onClick:()=>v(!0)}):null,f={display:R?"block":"inline"};return a.jsx("div",{style:f,children:O})}function ot({value:t,isLast:o}){const{showValueTypes:s,theme:c}=J();return a.jsxs("span",{style:{color:c.boolean},children:[t?"true":"false",o?null:a.jsx("span",{style:{color:"gray",marginLeft:"2px"},children:","}),s?a.jsx(Z,{valueType:l.Boolean}):null]})}function it({value:t,isLast:o}){const{showValueTypes:s,theme:c}=J();return a.jsxs("span",{style:{color:c.BigInt},children:[String(t),o?null:a.jsx("span",{style:{color:"gray",marginLeft:"2px"},children:","}),s?a.jsx(Z,{valueType:l.BigInt}):null]})}function st({value:t,isLast:o}){const{showValueTypes:s,theme:c}=J();return a.jsxs("span",{style:{color:c.null},children:[t||"null",o?null:a.jsx("span",{style:{color:"gray",marginLeft:"2px"},children:","}),s?a.jsx(Z,{valueType:l.Null}):null]})}const lt={border:"2px solid white",width:"6px",height:"8px",borderTop:"0",borderInlineStart:0,insetInlineStart:"25%",top:"55%",transform:"rotate(45deg) translate(-50%,-50%)"},ct={width:"8px",height:"8px",background:"#1890ff",border:"0",transform:"translate(-50%,-50%)",top:"50%",left:"50%"};function ut({checked:t,onChange:o,indeterminate:s,style:c}){const v=t&&s?ct:lt;return a.jsxs("span",{style:Object.assign({display:"inline-block",position:"relative",whiteSpace:"nowrap",verticalAlign:"middle",cursor:"pointer",height:"fit-content",boxSizing:"border-box"},c),onClick:()=>o(!(!s&&t)),children:[a.jsx("input",{style:{position:"absolute",opacity:0,pointerEvents:"none"},type:"checkbox",checked:t,readOnly:!0}),a.jsx("span",{style:{display:"block",width:"16px",height:"16px",border:"1px solid #d9d9d9",borderRadius:"4px",boxSizing:"border-box",background:t&&!s?"#1890ff":"white"}}),a.jsx("span",{style:Object.assign({display:t?"block":"none",position:"absolute",boxSizing:"border-box"},v)})]})}function ft({value:t,isLast:o}){const{showValueTypes:s,theme:c}=J();return a.jsxs("span",{style:{color:c.undefined},children:[t||"undefined",o?null:a.jsx("span",{style:{color:"gray",marginLeft:"2px"},children:","}),s?a.jsx(Z,{valueType:l.Undefined}):null]})}function ve({keyName:t,value:o,depth:s=0,isLast:c,parent:v,candidate:S}){const{showStringQuotes:R,indent:O,iconSize:f,defaultExpandDepth:m,defaultExpanded:d,selectedInfo:T,theme:I,onSelect:N,selectableDict:Q}=J(),[A,V]=P.useState(d&&s<m),j=F=>{V(F)},p=a.jsx(rt,{expanded:A,onClick:j,size:f}),E=F=>{const ue=ae(F),Y={keyName:t,isLast:c,parent:v,candidate:S};switch(ue){case l.String:return a.jsx(tt,Object.assign({value:F},Y));case l.Object:return a.jsx(et,Object.assign({value:F,expanded:A,depth:s,toggleExpand:j},Y));case l.Array:return a.jsx(at,Object.assign({value:F,expanded:A,depth:s,toggleExpand:j},Y));case l.Number:return a.jsx(nt,Object.assign({value:F},Y));case l.Boolean:return a.jsx(ot,Object.assign({value:F},Y));case l.BigInt:return a.jsx(it,Object.assign({value:F},Y));case l.Null:return a.jsx(st,Object.assign({value:F},Y));case l.Undefined:return a.jsx(ft,Object.assign({value:F},Y));default:return a.jsxs("span",{style:{color:"red"},children:[String(F)," // TODO"]})}},h=ae(o),k=[l.Object,l.Array].includes(h);let y="",M="";k&&(h===l.Object?(y="{",M="}"):h===l.Array&&(y="[",M="]"));let w=t===void 0?"":String(t),_=v;for(;_;)w=`${_.keyName===void 0?"":_.keyName}.${w}`,_=_.parent;const U=T.selectedDict,ie=T.indeterminateDict;let q=!1,B=!1;const z=Q[w];ie[w]&&(q=!0),U[w]?B=!0:(B=!1,q=!1);const X=(s?O:f)-(k&&!z?f:0);return a.jsxs("div",{style:{marginLeft:`${X}px`,padding:"2px 0",boxSizing:"border-box",color:I.primary},children:[z?a.jsx(ut,{style:{marginRight:"4px"},checked:B,indeterminate:q,onChange:F=>{N&&N({keyPath:w.split(".").slice(1),checked:F,depth:s,candidateValue:S})}}):null,a.jsx("span",{children:k?p:null}),t!==void 0&&typeof t!="number"&&a.jsxs("span",{children:[R?`"${t}"`:t,a.jsx("span",{style:{margin:"0 5px"},children:":"})]}),k?a.jsx("span",{children:y}):null,h===l.Object||h===l.Array?a.jsx("div",{style:{display:A?"block":"inline-block"},children:E(o)}):E(o),k?a.jsxs("span",{style:{marginLeft:A?`${f}px`:"0"},children:[M,c?null:a.jsx("span",{style:{color:"gray",marginLeft:"5px"},children:","})]}):null]})}function dt(t,o,s,c){return typeof t=="boolean"?t:Array.isArray(t)?t.includes(s):t(o,s,c)}function pt({selectable:t,value:o,onSelect:s}){const v=ae(o)==="object"?{}:[],[S,R]=P.useState(v),[O,f]=P.useState({selectedDict:{},indeterminateDict:{}}),[m,d]=P.useState(v),[T,I]=P.useState({});P.useEffect(()=>{const A=structuredClone(o),V={},j=(p,E,h,k,y)=>{const M=dt(t,E,h,p);M?V[k]=!0:y&&ce(y)&&delete y[h],ce(p)&&(Object.keys(p).forEach(_=>{const U=p[_],ie=E?y?y[h]:void 0:A;j(U,E+1,_,`${k}.${_}`,ie)}),M&&y&&!H(y[h])&&(y[h]=structuredClone(p)),!E&&H(A)&&(V[""]=!0))};j(o,0,"","",A),d(A),I(V)},[o,t]);const N=A=>{const V={},j={},p=(E,h,k,y)=>{!h&&!H(E)||(V[k]=!0,ce(E)&&(H(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],U=y[w];p(_,h+1,`${k}.${w}`,U)})))};p(A,0,"",m),f({selectedDict:V,indeterminateDict:j})};return{selectedValue:S,selectedInfo:O,selectCandidate:m,innerOnSelect:({depth:A,candidateValue:V,checked:j,keyPath:p})=>{let E=structuredClone(S);if(!A)E=structuredClone(j?V:v);else{let h=E,k=m;const y=[];for(let w=0;w<p.length-1;w++){const _=p[w];ce(h)&&h[_]===void 0&&(h[_]=ae(k)==="object"?{}:[]),y.push({value:h,key:_}),h=h[_],k=k[_]}const M=p[p.length-1];if(j)h[M]=structuredClone(V);else{delete h[M];for(let w=y.length-1;w>=0;w--){const{value:_,key:U}=y[w];H(_[U])||delete _[U]}}}R(E),N(E),s&&s(p.pop(),E,j)},selectableDict:T}}return function({value:t,selectable:o,showStringQuotes:s,defaultExpanded:c,defaultExpandDepth:v,showValueTypes:S,iconSize:R,stringMaxLength:O,theme:f="default",onSelect:m,className:d,style:T}){const{selectedInfo:I,selectCandidate:N,innerOnSelect:Q,selectableDict:A}=pt({selectable:o||!1,value:t,defaultSelect:!1,onSelect:m}),V=y=>{Q(y)},j=f==="default"?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":f,[p,E]=P.useState(le(j)),h=P.useCallback(y=>{f==="default"&&E(le(y.matches?"dark":"light"))},[f]);P.useEffect(()=>{if(E(le(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({},$),{selectable:oe(o)?$.selectable:o,showStringQuotes:oe(s)?$.showStringQuotes:s,iconSize:R||$.iconSize,defaultExpanded:oe(c)?$.defaultExpanded:c,defaultExpandDepth:v||$.defaultExpandDepth,showValueTypes:oe(S)?$.showValueTypes:S,stringMaxLength:oe(O)?$.stringMaxLength:O,theme:p,selectValueCandidate:N,selectedInfo:I,selectableDict:A});return a.jsx(Te.Provider,{value:Object.assign(Object.assign({},k),{onSelect:V}),children:a.jsx("div",{className:d,style:Object.assign({fontSize:"14px",fontFamily:"Consolas, Menlo, Courier, monospace",boxSizing:"border-box"},T),children:a.jsx(ve,{value:t,defaultExpanded:!1,isLast:!0,candidate:N})})})}});