@vertesia/ui 0.74.0 → 0.76.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/esm/core/components/Center.js +1 -1
- package/lib/esm/core/components/Center.js.map +1 -1
- package/lib/esm/core/components/Overlay.js +57 -0
- package/lib/esm/core/components/Overlay.js.map +1 -0
- package/lib/esm/core/components/SidePanel.js +6 -6
- package/lib/esm/core/components/SidePanel.js.map +1 -1
- package/lib/esm/core/components/index.js +1 -0
- package/lib/esm/core/components/index.js.map +1 -1
- package/lib/esm/core/components/shadcn/tabs.js +43 -5
- package/lib/esm/core/components/shadcn/tabs.js.map +1 -1
- package/lib/esm/features/agent/PayloadBuilder.js +9 -2
- package/lib/esm/features/agent/PayloadBuilder.js.map +1 -1
- package/lib/esm/features/facets/DocumentsFacetsNav.js +4 -2
- package/lib/esm/features/facets/DocumentsFacetsNav.js.map +1 -1
- package/lib/esm/features/facets/VTypeFacet.js +2 -1
- package/lib/esm/features/facets/VTypeFacet.js.map +1 -1
- package/lib/esm/features/magic-pdf/TextPageView.js +2 -4
- package/lib/esm/features/magic-pdf/TextPageView.js.map +1 -1
- package/lib/esm/features/store/collections/CreateCollection.js +1 -1
- package/lib/esm/features/store/collections/CreateCollection.js.map +1 -1
- package/lib/esm/features/store/objects/DocumentPreviewPanel.js +2 -4
- package/lib/esm/features/store/objects/DocumentPreviewPanel.js.map +1 -1
- package/lib/esm/features/store/objects/DocumentSearchResults.js +19 -21
- package/lib/esm/features/store/objects/DocumentSearchResults.js.map +1 -1
- package/lib/esm/features/store/objects/components/ContentOverview.js +2 -4
- package/lib/esm/features/store/objects/components/ContentOverview.js.map +1 -1
- package/lib/esm/features/store/objects/components/VectorSearchWidget.js +51 -46
- package/lib/esm/features/store/objects/components/VectorSearchWidget.js.map +1 -1
- package/lib/esm/features/store/objects/search/DocumentSearchContext.js +50 -34
- package/lib/esm/features/store/objects/search/DocumentSearchContext.js.map +1 -1
- package/lib/esm/features/store/objects/search/DocumentSearchProvider.js +1 -3
- package/lib/esm/features/store/objects/search/DocumentSearchProvider.js.map +1 -1
- package/lib/esm/features/store/objects/upload/useSmartFileUploadProcessing.js +4 -11
- package/lib/esm/features/store/objects/upload/useSmartFileUploadProcessing.js.map +1 -1
- package/lib/esm/features/user/UserInfo.js +2 -2
- package/lib/esm/features/user/UserInfo.js.map +1 -1
- package/lib/esm/session/UserSessionProvider.js +6 -3
- package/lib/esm/session/UserSessionProvider.js.map +1 -1
- package/lib/esm/session/auth/composable.js +3 -3
- package/lib/esm/session/auth/composable.js.map +1 -1
- package/lib/esm/session/auth/firebase.js +7 -0
- package/lib/esm/session/auth/firebase.js.map +1 -1
- package/lib/esm/session/auth/useAuthState.js +0 -3
- package/lib/esm/session/auth/useAuthState.js.map +1 -1
- package/lib/esm/shell/apps/StandaloneApp.js +1 -1
- package/lib/esm/shell/apps/StandaloneApp.js.map +1 -1
- package/lib/esm/shell/login/EnterpriseSigninButton.js +3 -0
- package/lib/esm/shell/login/EnterpriseSigninButton.js.map +1 -1
- package/lib/esm/shell/login/InviteAcceptModal.js +1 -1
- package/lib/esm/shell/login/InviteAcceptModal.js.map +1 -1
- package/lib/esm/widgets/form/ManagedObject.js +1 -1
- package/lib/esm/widgets/index.js +1 -0
- package/lib/esm/widgets/index.js.map +1 -1
- package/lib/esm/widgets/markdown/MarkdownRenderer.js +24 -0
- package/lib/esm/widgets/markdown/MarkdownRenderer.js.map +1 -0
- package/lib/esm/widgets/markdown/index.js +2 -0
- package/lib/esm/widgets/markdown/index.js.map +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/core/components/Overlay.d.ts +25 -0
- package/lib/types/core/components/Overlay.d.ts.map +1 -0
- package/lib/types/core/components/SidePanel.d.ts +3 -1
- package/lib/types/core/components/SidePanel.d.ts.map +1 -1
- package/lib/types/core/components/index.d.ts +1 -0
- package/lib/types/core/components/index.d.ts.map +1 -1
- package/lib/types/core/components/shadcn/tabs.d.ts.map +1 -1
- package/lib/types/env/index.d.ts +2 -2
- package/lib/types/env/index.d.ts.map +1 -1
- package/lib/types/features/agent/PayloadBuilder.d.ts.map +1 -1
- package/lib/types/features/facets/DocumentsFacetsNav.d.ts.map +1 -1
- package/lib/types/features/facets/VTypeFacet.d.ts.map +1 -1
- package/lib/types/features/magic-pdf/TextPageView.d.ts.map +1 -1
- package/lib/types/features/store/objects/DocumentPreviewPanel.d.ts.map +1 -1
- package/lib/types/features/store/objects/DocumentSearchResults.d.ts.map +1 -1
- package/lib/types/features/store/objects/components/ContentOverview.d.ts.map +1 -1
- package/lib/types/features/store/objects/components/VectorSearchWidget.d.ts +4 -3
- package/lib/types/features/store/objects/components/VectorSearchWidget.d.ts.map +1 -1
- package/lib/types/features/store/objects/search/DocumentSearchContext.d.ts +5 -2
- package/lib/types/features/store/objects/search/DocumentSearchContext.d.ts.map +1 -1
- package/lib/types/features/store/objects/search/DocumentSearchProvider.d.ts +2 -4
- package/lib/types/features/store/objects/search/DocumentSearchProvider.d.ts.map +1 -1
- package/lib/types/features/store/objects/upload/useSmartFileUploadProcessing.d.ts.map +1 -1
- package/lib/types/session/UserSessionProvider.d.ts.map +1 -1
- package/lib/types/session/auth/composable.d.ts +1 -1
- package/lib/types/session/auth/composable.d.ts.map +1 -1
- package/lib/types/session/auth/firebase.d.ts.map +1 -1
- package/lib/types/session/auth/useAuthState.d.ts.map +1 -1
- package/lib/types/shell/login/EnterpriseSigninButton.d.ts.map +1 -1
- package/lib/types/widgets/index.d.ts +1 -0
- package/lib/types/widgets/index.d.ts.map +1 -1
- package/lib/types/widgets/markdown/MarkdownRenderer.d.ts +9 -0
- package/lib/types/widgets/markdown/MarkdownRenderer.d.ts.map +1 -0
- package/lib/types/widgets/markdown/index.d.ts +2 -0
- package/lib/types/widgets/markdown/index.d.ts.map +1 -0
- package/lib/vertesia-ui-core.js +1 -1
- package/lib/vertesia-ui-core.js.map +1 -1
- package/lib/vertesia-ui-features.js +1 -1
- package/lib/vertesia-ui-features.js.map +1 -1
- package/lib/vertesia-ui-session.js +1 -1
- package/lib/vertesia-ui-session.js.map +1 -1
- package/lib/vertesia-ui-shell.js +1 -1
- package/lib/vertesia-ui-shell.js.map +1 -1
- package/lib/vertesia-ui-widgets.js +1 -1
- package/lib/vertesia-ui-widgets.js.map +1 -1
- package/package.json +6 -4
- package/src/core/components/Center.tsx +1 -1
- package/src/core/components/Overlay.tsx +129 -0
- package/src/core/components/SidePanel.tsx +38 -33
- package/src/core/components/index.ts +1 -0
- package/src/core/components/shadcn/tabs.tsx +48 -5
- package/src/env/index.ts +1 -1
- package/src/features/agent/PayloadBuilder.tsx +8 -2
- package/src/features/facets/DocumentsFacetsNav.tsx +4 -2
- package/src/features/facets/VTypeFacet.tsx +2 -1
- package/src/features/magic-pdf/TextPageView.tsx +3 -4
- package/src/features/store/collections/CreateCollection.tsx +1 -1
- package/src/features/store/objects/DocumentPreviewPanel.tsx +2 -4
- package/src/features/store/objects/DocumentSearchResults.tsx +24 -26
- package/src/features/store/objects/components/ContentOverview.tsx +3 -6
- package/src/features/store/objects/components/VectorSearchWidget.tsx +88 -60
- package/src/features/store/objects/search/DocumentSearchContext.ts +57 -36
- package/src/features/store/objects/search/DocumentSearchProvider.tsx +2 -6
- package/src/features/store/objects/upload/useSmartFileUploadProcessing.ts +6 -12
- package/src/features/user/UserInfo.tsx +2 -2
- package/src/session/UserSessionProvider.tsx +5 -3
- package/src/session/auth/composable.ts +3 -3
- package/src/session/auth/firebase.ts +8 -0
- package/src/session/auth/useAuthState.ts +0 -4
- package/src/shell/apps/StandaloneApp.tsx +1 -1
- package/src/shell/login/EnterpriseSigninButton.tsx +3 -0
- package/src/shell/login/InviteAcceptModal.tsx +1 -1
- package/src/widgets/form/ManagedObject.ts +1 -1
- package/src/widgets/index.ts +1 -0
- package/src/widgets/markdown/MarkdownRenderer.tsx +45 -0
- package/src/widgets/markdown/index.ts +1 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import n from"debounce";import s,{useRef as i,useEffect as a,useMemo as o,createContext as l,useContext as c,useState as d,Children as h,isValidElement as u}from"react";import{EditorView as p}from"@codemirror/view";import{useSafeLayoutEffect as m,Styles as f,Button as g,DotBadge as y,Table as v,VTooltip as b,useToast as x,VModal as w,VModalTitle as N,VModalBody as k,VModalFooter as C,VSelectBox as j,ModalBody as S,ModalFooter as O,useFlag as A,useClickOutside as P}from"@vertesia/ui/core";import{Text as $,EditorState as E}from"@codemirror/state";import{Plus as T,Trash2 as I,Info as q,AlignLeft as M,SquarePen as L,ChevronDown as D,ChevronRight as F,UploadIcon as z,CheckCircleIcon as R,AlertCircleIcon as V,XCircleIcon as _}from"lucide-react";import U from"clsx";import K from"ajv";import{ObjectWalker as B}from"@vertesia/json";import{offset as W,shift as H,flip as J}from"@floating-ui/dom";import{useFloating as G,autoUpdate as X,useDismiss as Z,useClick as Y,useHover as Q,useInteractions as ee,useTransitionStyles as te,FloatingPortal as re,FloatingFocusManager as ne,safePolygon as se}from"@floating-ui/react";import{json as ie}from"@codemirror/lang-json";import{basicSetup as ae}from"codemirror";import{isNil as oe,omit as le,isEqual as ce}from"lodash-es";import{XMLParser as de,XMLValidator as he}from"fast-xml-parser";let ue=null;class pe{editor;constructor(e){this.editor=e}setValue(e){this.editor.dispatch({changes:{from:0,to:this.editor.state.doc.length,insert:e||""}})}getValue(){return this.editor.state.doc.toString()}}const me=[p.theme({"&":{fontSize:"14px",fontFamily:"monospace"},".cm-content":{fontFamily:"inherit"},".cm-scroller":{fontFamily:"inherit"},".cm-gutters":{backgroundColor:"transparent",color:"#ddd"},".cm-focused":{outline:"none"},".cm-cursor":{borderLeft:"2px solid #808080",borderLeftColor:"#808080",animation:"blink 1.2s step-start infinite"},"@keyframes blink":{"50%":{opacity:0}}}),p.lineWrapping];function fe({onChange:t,value:r,className:s,editorRef:l,extensions:c,debounceTimeout:d=0}){const h=i(null),u=i(void 0);a((()=>{if(t)return u.current=d>0?n(t,d):t,()=>{u.current=void 0}}),[t,d]);const f=o((()=>e("div",{ref:h,className:s})),[s]);return m((()=>{if(h.current){let t=[...me,(e=e=>{u.current?.(e)},p.updateListener.of((t=>{t.docChanged&&e(t)})))];Array.isArray(c)?t=t.concat(c):c&&t.push(c);const n=((e="",t=[])=>{const r="string"==typeof e?$.of(e.split("\n")):e;return ue?ue.doc.toString()!==r.toString()&&(ue=E.create({doc:r,extensions:t})):ue=E.create({doc:r,extensions:t}),ue})(r,t),s=new p({state:n,parent:h.current}),i=new pe(s);return l&&(l.current=i),()=>{s.destroy(),l&&(l.current=void 0)}}var e}),[f,c]),f}const ge=l(void 0),ye=ge.Provider;function ve(){const e=c(ge);if(!e)throw new Error("useFieldSet must be used within a Form or FieldSet element");return e}const be=l(void 0);function xe(){const e=c(be);if(!e)throw new Error("useForm must be used within a Form element");return e}const we=be.Provider;function Ne({htmlFor:r,required:n,children:s}){return t("label",{htmlFor:r,className:"block text-sm font-medium leading-6 text-gray-900 dark:text-gray-200",children:[s,n&&e("sup",{className:"text-red-600",children:"*"})]})}function ke({children:t}){return e("p",{className:"mt-2 text-sm text-gray-500",children:t})}function Ce({children:t}){return e("p",{className:"mt-2 text-sm text-red-600",children:t})}const je=s.forwardRef((({object:t,type:r="text",onChange:n,...s},i)=>{const[a,o]=d(null!=t.value?String(t.value):""),[l,c]=d(t.schema.isBoolean&&!0===t.value);s.className?s.className=U(f.INPUT,s.className):s.className=f.INPUT;const h=e=>{o(e.target.value),t.schema.isBoolean?(t.value=e.target.checked,c(t.value)):t.value=e.target.value,n&&n(e)};return"textarea"===r?e("textarea",{ref:i,...s,value:a,onChange:h}):e("input","checkbox"===r?{ref:i,...s,type:"checkbox",checked:l,onChange:h,className:"form-check-input"}:{ref:i,...s,type:r,value:a,onChange:h})}));function Se({object:t,components:r,onSubmit:n,children:s,onChange:i}){return t.observer=i,e(we,{value:{object:t,components:r||{}},children:e("form",{className:"w-full",onSubmit:e=>{e.stopPropagation(),e.preventDefault(),n&&n(t.value)},children:s})})}function Oe(){const t=xe();return e("div",{className:"flex flex-col gap-4 w-full",children:t.object.properties.map(Pe)})}function Ae({children:r,...n}){return t(Se,{...n,children:[e(Oe,{}),r]})}function Pe(t){return t.isList?e(Te,{object:t},t.name):t.isObject?e(Ee,{object:t},t.name):e($e,{object:t},t.name)}function $e({object:r,editor:n,inline:s=!1}){n||(n=r.schema.editor);const{components:i}=xe(),a=n&&i[n]||je,o=r.getInputType();"checkbox"===o&&(s=!0);return t("div",{className:"",children:[t("div",{className:U("flex gap-2",s?"flex-row items-center":"flex-col"),children:[!r.isListItem&&e(Ne,{required:r.schema.isRequired,children:r.title}),e(a,{object:r,type:o,onChange:e=>{const{value:t}=e.target;r.value=r.schema.isNumber?parseFloat(t):t}})]}),r.schema.description&&e(ke,{children:r.schema.description})]})}function Ee({object:r}){return t("div",{className:"flex flex-col gap-4 my-4 py-2 pl-4 border-l-4 border-l-solid border-l-slate-100 dark:border-l-slate-600",children:[!r.isListItem&&e("div",{className:"text-gray-900 dark:text-gray-200 font-semibold",children:r.title}),r.properties.map(Pe)]})}function Te({object:r}){const[n,s]=d(r.value||[]);return t("div",{className:"flex flex-col gap-4 my-4 py-2 pl-4 border-l-4 border-l-solid border-l-slate-100 darK:border-l-slate-600",children:[!r.isListItem&&e("div",{className:"text-gray-900 dark:text-gray-200 font-semibold",children:r.title}),r.items.map(((t,i)=>e(Ie,{object:t,list:r,onDelete:()=>(e=>{r.remove(e),s([...r.value])})(i)},`${i}-${n[i]??""}`))),e("div",{children:t(g,{variant:"secondary",onClick:()=>{r.add(),s([...r.value])},children:[e(T,{className:"size-6"})," Add"]})})]})}function Ie({list:r,object:n,onDelete:s}){return t("div",{className:"flex gap-2 w-full",children:[e("div",{className:"flex-1",children:(i=n,a=r.schema.arraySchema.editor,i.isList?e(Te,{object:i}):i.isObject?e(Ee,{object:i}):e($e,{object:i,editor:a}))}),e(g,{variant:"secondary",onClick:s,children:e(I,{className:"size-4"})})]});var i,a}class qe{schema;properties={};_validator;constructor(e){this.schema=e||{type:"object",properties:{}},this.load()}get validator(){if(!this._validator){const e=new K({allErrors:!0,strict:!1});this._validator=e.compile(this.schema)}return this._validator}load(){if(this.schema.properties){const e=this.schema.properties;Object.keys(e).forEach((t=>{this.loadProperty(t,e[t])}))}}hasProperties(){return Object.keys(this.properties).length>0}get title(){return this.schema.title||this.schema.name}get description(){return this.schema.description}loadProperty(e,t){let r;return r="array"===t.type?new Le(this,e,t):new Me(this,e,t),this.properties[e]=r,r}get type(){return this.schema.type}validate(e){return this.validator(e)?null:this.validator.errors||[]}addProperty(e,t,r=!1){"object"!==this.schema.type&&(this.schema.type="object"),this.schema.properties||(this.schema.properties={});const n="string"==typeof t?"object"===(s=t)?{type:"object",properties:{}}:"array"===s?{type:"array",items:{}}:{type:s}:t;var s;const i=this.loadProperty(e,n);return this.schema.properties[i.name]=i.schema,r&&(i.isRequired=!0),i}removeProperty(e){this.schema.properties&&(delete this.schema.properties[e],Array.isArray(this.schema.required)&&(this.schema.required=this.schema.required.filter((t=>t!==e)))),delete this.properties[e]}getProperty(e){return this.properties[e]}get editor(){return this.schema.editor}}class Me extends qe{parent;name;constructor(e,t,r){if(super(r),this.parent=e,this.name=t,"array"===r.type)throw new Error("Array property must be instantiated using ArrayPropertySchema");"object"!==r.type||r.properties||(r.properties={})}get isMulti(){return!1}get isReadOnly(){return!!this.schema.readOnly}set isReadOnly(e){this.schema.readOnly=e}get defaultValue(){return this.schema.default}set defaultValue(e){this.schema.default=e}get enum(){return this.schema.enum}set enum(e){this.schema.enum=e}get isRequired(){const e=this.parent.schema.required;return!!e&&e.includes(this.name)}set isRequired(e){let t=Array.isArray(this.parent.schema.required)?this.parent.schema.required:[];t=e?t.concat(this.name):t.filter((e=>e!==this.name)),this.parent.schema.required=t}get type(){return this.schema.type}set type(e){this.schema.type!==e&&(this.schema.type=e,"object"!==e&&(this.properties={},this.schema.properties=void 0))}remove(){this.parent.removeProperty(this.name)}get isBoolean(){return"boolean"===this.type}get isString(){return"string"===this.type}get isNumber(){return"number"===this.type||"integer"===this.type}get isObject(){return"object"===this.type}}class Le extends Me{arraySchema;constructor(e,t,r){super(e,t,function(e){if("array"!==e.type)throw new Error("Expecting an array schema");if(e.items){if(Array.isArray(e.items))throw new Error("Tuple arrays are not supported")}else e.items={};return e.items}(r)),this.arraySchema=r}get isMulti(){return!0}}function De(e){return(e=e.replace(/_/g," ").replace(/([a-z0-9])&([A-Z])/g,"$1 $2"))[0].toUpperCase()+e.slice(1)}function Fe(e,t){if(t.editor)return t.editor;switch(t.type){case"number":case"integer":return"number";case"boolean":return"checkbox";default:return"text"}}class ze{parent;schema;name;observer;constructor(e,t,r){this.parent=e,this.schema=t,this.name=r}get isRoot(){return!this.parent}get root(){return this.parent?this.parent.root:this}get path(){return this.parent?this.parent.path.concat(this.name):[]}get isScalar(){return!1}get isListItem(){return!1}get isObject(){return!1}get isList(){return!1}get title(){return this.schema.title||De(this.name)}onChange(e){this.observer&&!1===this.observer(this)||this.parent&&this.parent.onChange(e)}}class Re extends ze{constructor(e,t,r){super(e,t,r)}get isObject(){return!0}getProperty(e){const t=this.schema.properties[e];return t.isMulti?new Ke(this,t,this.getOrInitArrayProperty(e)):t.isObject?new _e(this,t,t.name,this.getOrInitObjectProperty(e)):new Ue(this,t)}getOrInitObjectProperty(e){let t=this.value[e];return t||(this.value[e]=t={}),t}getOrInitArrayProperty(e){let t=this.value[e];return t||(this.value[e]=t=[]),t}setPropertyValue(e,t){return this.value[e]!==t&&(this.value[e]=t,!0)}getPropertyValue(e){return this.value[e]}get properties(){const e=[];for(const t of Object.values(this.schema.properties))t.isMulti?e.push(new Ke(this,t,this.getOrInitArrayProperty(t.name))):t.isObject?e.push(new _e(this,t,t.name,this.getOrInitObjectProperty(t.name))):e.push(new Ue(this,t));return e}[Symbol.iterator](){return this.properties[Symbol.iterator]()}}class Ve extends Re{value;constructor(e,t={}){super(null,e instanceof qe?e:new qe(e),"#root"),this.value=t}}class _e extends Re{value;constructor(e,t,r,n){super(e,t,r),this.value=n}}class Ue extends ze{constructor(e,t){super(e,t,t.name),void 0===e.value[this.name]&&void 0!==t.defaultValue&&(e.value[this.name]=t.defaultValue)}get isScalar(){return!0}set value(e){this.parent.setPropertyValue(this.name,e)&&this.onChange(this)}get value(){return this.parent.getPropertyValue(this.name)}getInputType(){return Fe(this.name,this.schema)}}class Ke extends ze{value;items=[];constructor(e,t,r){super(e,t,t.name),this.value=r;for(const e of this.value)this.add()}get isList(){return!0}newItem(e){return this.schema.isObject?new Be(this,e):new We(this,e)}add(){const e=this.newItem(this.items.length);return this.items.push(e),e}remove(e){const t=this.value;if(e>=0&&e<this.items.length){this.items.splice(e,1);for(let e=0,t=this.items.length;e<t;e++){const t=this.items[e];t.index=e,t.name=String(e)}}Array.isArray(t)&&e>=0&&e<t.length&&(t.splice(e,1),this.onChange(this))}[Symbol.iterator](){return this.items[Symbol.iterator]()}item(e){if(e<0||e>=this.value.length)return;const t=this.value[e];return this.schema.isObject?new _e(this,this.schema,String(e),t):new We(this,e)}trim(){for(;void 0===this.items[this.items.length-1];)this.items.pop()}}class Be extends Re{index;key;constructor(e,t){super(e,e.schema,String(t)),this.index=t,void 0===e.value[t]&&(e.value[t]={}),this.key=this.name+"@"+Date.now()}get isListItem(){return!0}set value(e){this.parent.value[this.index]=e}get value(){return this.parent.value[this.index]}}class We extends ze{index;key;constructor(e,t){super(e,e.schema,String(t)),this.index=t,void 0===e.value[t]&&void 0!==e.schema.defaultValue&&(e.value[t]=e.schema.defaultValue),this.key=this.name+"@"+Date.now()}get isScalar(){return!0}get isListItem(){return!0}set value(e){this.parent.value[this.index]=e}get value(){return this.parent.value[this.index]}getInputType(){return Fe(this.name,this.schema)}}const He="text-pink-500 dark:text-pink-400",Je="text-purple-500 dark:text-purple-400",Ge="text-blue-500 dark:text-blue-400",Xe={code:"bg-gray-100 dark:bg-slate-800 whitespace-pre-wrap p-4 rounded-lg font-mono",comma:He,assign:He,startObject:He,endObject:He,startArray:He,endArray:He,boolean:Je,null:Je,key:Ge,index:Ge,string:"text-orange-500 dark:text-orange-400",number:"text-green-500 dark:text-green-400"};class Ze{renderer;parent;key;indent;result=[];constructor(e,t,r,n){this.renderer=e,this.parent=t,this.key=r,this.indent=n}get classMap(){return this.renderer.classMap}writeKey(e){const t=typeof e;"string"===t?(this.result.length>0&&this.result.push(`<span class='${this.classMap.comma}'>,\n</span>`),this.indent&&this.result.push(this.indent),this.result.push(`<span class="${this.classMap.key}">"${e}"</span><span class='${this.classMap.assign}'>: </span>`)):"number"===t&&(this.result.length>0&&this.result.push(`<span class='${this.classMap.comma}'>,\n</span>`),this.indent&&this.result.push(this.indent))}pushValue(e,t){if(this.writeKey(e),null===t)this.result.push(`<span class='${this.classMap.null}'>null</span>`);else if(t instanceof Ze)this.result.push(t.renderStart()+t.renderValue()+t.renderEnd());else{let e;const r=typeof t;"string"===r?(t=(t=`"${t}"`).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">"),e=this.classMap.string):"number"===r?e=this.classMap.number:"boolean"===r&&(e=this.classMap.boolean),this.result.push(`<span class='${e}'>${t}</span>`)}}renderValue(){return this.result.join("")}}class Ye extends Ze{constructor(e,t,r,n){super(e,t,r,n)}renderStart(){return`<span class='${this.classMap.startObject}'>{\n</span>`}renderEnd(){const e=this.result.length>0?"\n":"";return`<span class='${this.classMap.endObject}'>${e}${this.parent?.indent||""}}</span>`}}class Qe extends Ze{constructor(e,t,r,n){super(e,t,r,n)}renderStart(){return`<span class='${this.classMap.startArray}'>[\n</span>`}renderEnd(){const e=this.result.length>0?"\n":"";return`<span class='${this.classMap.endArray}'>${e}${this.parent?.indent||""}]</span>`}}class et{classMap;tab;stack=[];block=new Ye(this,void 0,"","");constructor(e=Xe,t=" "){this.classMap=e,this.tab=t}onStartObject(e){const t=new Ye(this,this.block,e,this.block.indent+this.tab);this.stack.push(this.block),this.block=t}onEndObject(){const e=this.block;this.block=this.stack.pop(),this.block.pushValue(e.key,e)}onStartIteration(e){const t=new Qe(this,this.block,e,this.block.indent+this.tab);this.stack.push(this.block),this.block=t}onEndIteration(){const e=this.block;this.block=this.stack.pop(),this.block.pushValue(e.key,e)}onValue(e,t){this.block.pushValue(e,t)}}function tt({data:t,className:r,classMap:n}){const[s,i]=d();return a((()=>{i(function(t,r,n){const s=new et(r);(new B).walk(t,s);const i=s.block.renderValue();return e("div",{className:n,dangerouslySetInnerHTML:{__html:`<div class='${s.classMap.code}' style='overflow-x: scroll'>${i}</div>`}})}(t,n,r))}),[t]),s}function rt({value:t}){return e("div",{className:"flex flex-col gap-4",children:Object.entries(t).map((([t,r])=>e(it,{name:t,value:r},t)))})}function nt({name:t}){return e("div",{className:"text-md font-semibold",children:De(t)})}function st({children:t,className:r}){return e("div",{className:U("flex flex-col gap-4 py-2 pl-4 border-l-4 border-l-solid border-l-slate-100 dark:border-l-slate-600",r),children:t})}function it({name:r,value:n}){const s=ct(n);switch(s.type){case lt.Inline:return t("div",{className:"w-full flex gap-2",children:[e(nt,{name:r+":"}),e("p",{children:s.value})]});case lt.Paragraph:return t("div",{children:[e(nt,{name:r}),e("p",{children:s.value})]});case lt.Prose:return t("div",{className:"prose dark:prose-invert",children:[e(nt,{name:r}),e("div",{className:"vprose dark:prose-invert",children:s.value})]});case lt.Array:return e(at,{name:r,value:n});case lt.Object:return t("div",{children:[e(nt,{name:r}),e(st,{className:"mt-2",children:Object.entries(n).map((([t,r])=>e(it,{name:t,value:r},t)))})]})}}function at({name:r,value:n}){const s=n.join(" ").length,i=s/n.length,a="string"==typeof n[0]&&(s<80||s<400&&i<32),o=n.length>9;return t("div",a?{className:"flex gap-2 flex-wrap",children:[r&&e(nt,{name:r+":"}),n.map(((t,r)=>e(y,{children:String(t)},r)))]}:{children:[r&&e(nt,{name:r}),e("div",{className:"flex flex-col gap-2",children:n.map(((t,r)=>e(ot,{index:r,value:t,useBullet:o},r)))})]})}function ot({index:r,value:n,useBullet:s}){const i=s?e("span",{className:"text-xl",children:"•"}):t("span",{children:[r+1,"."]}),a=ct(n);let o;switch(a.type){case lt.Object:o=e(st,{children:Object.entries(n).map((([t,r])=>e(it,{name:t,value:r},t)))});break;case lt.Array:o=e(at,{value:n});break;case lt.Prose:o=e("div",{className:"prose dark:prose-invert",children:a.value});break;default:o=e("div",{children:a.value})}return t("div",{className:"flex gap-4 hover:bg-slate-50 dark:hover:bg-slate-800 py-2 pr-2 pl-4",children:[e("div",{className:"font-semibold text-gray-600 dark:text-gray-400",children:i}),e("div",{children:o})]})}var lt;function ct(e){if(null==e)return{value:"-",type:lt.Inline};if(Array.isArray(e))return{value:e,type:lt.Array};const t=typeof e;if("string"===t){const t=e.length;let r;return t<80?r=lt.Inline:t>400?r=lt.Prose:(r=lt.Paragraph,e=e.replace(/(?:\n\n)+/g,"\n\n")),{type:r,value:e}}return"number"===t||"boolean"===t?{value:String(e),type:lt.Inline}:{value:e,type:lt.Object}}function dt({value:t,viewCode:r=!1}){return t?e("div",{className:"relative w-full",children:r?e(tt,{data:t}):e(rt,{value:t})}):e("pre",{className:"whitespace-pre-wrap",children:"No Data to display"})}!function(e){e[e.Inline=0]="Inline",e[e.Paragraph=1]="Paragraph",e[e.Prose=2]="Prose",e[e.Array=3]="Array",e[e.Object=4]="Object"}(lt||(lt={}));const ht=l(void 0);function ut(){return c(ht)}const pt=Symbol("__SLOT_NAME");function mt(e,t){const r=[];return h.forEach(e,(e=>{!function(e,t,r){let n;u(e)&&(n=e.type[pt])?r[n]=e:t.push(e)}(e,r,t)})),r.length>1?r:r[0]}function ft(e,t){t[pt]=e}function gt(e){return e?"boolean"==typeof e?{enabled:e}:e:{enabled:!1}}function yt(t){const r={};if(mt(t.children,r),!r.content)throw new Error("Popover must provide a content slot");const n=r.trigger?.props,s=r.content.props;return e(vt,{...t,trigger:n,content:s})}function vt({middleware:r,offset:n,trigger:s,dismiss:i=!0,content:a,placement:o,strategy:l,zIndex:c=40}){const[h,u]=d(!1),p=G({open:h,placement:o,strategy:l,onOpenChange:u,middleware:r||[W(n||4),H(),J()],whileElementsMounted:X}),{floatingStyles:m,refs:{setReference:f,setFloating:g},context:y}=p,v=Z(y,gt(i)),b=Y(y,gt(!(x=s)||x.hover||x.click?x?.click:{enabled:!0}));var x;const w=Q(y,gt(function(e){return!0===e?.hover?{enabled:!0,handleClose:se({blockPointerEvents:!0}),restMs:0}:e?.hover}(s))),{getReferenceProps:N,getFloatingProps:k}=ee([v,b,w]),{isMounted:C,styles:j}=te(y,a.transition);return t(ht.Provider,{value:{...p,close:()=>u(!1)},children:[s&&e("div",{className:U(s.className,"inline-block"),ref:f,...N(),children:s.children}),e(re,{children:C&&e("div",{ref:g,style:{...m,zIndex:c},...k(),children:e(ne,{context:y,children:e("div",{className:U(a.className,"bg-popover rounded-md text-popover-foreground max-w-md"),style:j,children:a.children})})})})]})}function bt(e){return null}function xt(e){return null}function wt({percent:t}){return e("div",{className:"w-full bg-gray-200 rounded-full h-2.5 dark:bg-gray-700",children:e("div",{className:"bg-blue-600 h-2.5 rounded-full",style:{width:`${t}%`}})})}function Nt({className:r,properties:n}){return e(v,{className:r,children:e("tbody",{children:n.map((r=>t("tr",{children:[t("td",{className:"w-1/3 font-semibold gap-2",children:[e("span",{children:r.name}),r.description&&e(b,{description:r.description,placement:"top",children:e(q,{className:"size-3 ml-2 text-muted-foreground"})})]}),e("td",{className:"w-2/3",children:r.value??"undefined"})]},r.name)))})})}ft("trigger",bt),ft("content",xt),yt.Trigger=bt,yt.Content=xt;const kt=[ae,ie()];function Ct({schema:r,isOpen:n,onClose:s,readonly:a=!1}){const l=i(void 0),c=x(),d=o((()=>function(e){return e?JSON.stringify(e,null,2):""}(r.schema)),[r]);return t(w,{onClose:s,isOpen:!!n,className:"min-w-[60vw]",children:[e(N,{children:"JSON Schema Editor"}),e(k,{children:a?e(tt,{data:r.schema||{}}):e(fe,{value:d,extensions:kt,editorRef:l})}),e(C,{children:a?null:e(g,{onClick:()=>{if(l.current){const e=l.current.getValue();try{const t=function(e){if(e&&(e=e.trim()))return JSON.parse(e)}(e);r.replaceSchema(t),s()}catch(e){c({status:"error",title:"Invalid JSON Schema",description:e.message,duration:5e3})}}},children:"Save changes"})})]})}var jt;function St(e,t){let r="any"===t.name?void 0:t.isNullable?[t.name,"null"]:t.name;if(t.isArray)if(e.type="array",e.properties=void 0,!e.items||Array.isArray(e.items))e.items={type:r,properties:t.isObject?{}:void 0};else{const n=e.items;n.type=r,t.isObject&&!n.properties&&(n.properties={})}else e.type=r,e.items=void 0,t.isObject?e.properties||(e.properties={}):e.properties=void 0}function Ot(e){let t,r=!1,n=!1;const s=e.type;if(Array.isArray(s))for(const e of s)"null"===e?r=!0:t||(t=e);else t=s;t||(t="any"),"array"===t&&(n=!0,t=function(e){if(!e)return"any";let t;t=Array.isArray(e)?At(e[0].type):At(e.type);"array"!==t&&"null"!==t||(t="any");return t}(e.items));let i=t;switch(e.editor||e.format){case"textarea":i="text";break;case"media":i="media";break;case"document":i="document"}return{isNullable:r,isArray:n,isObject:"object"===t,name:i}}function At(e){return e?Array.isArray(e)?e.find((e=>"null"!==e))||"any":e:"any"}!function(e){e.string="string",e.number="number",e.integer="integer",e.boolean="boolean",e.object="object",e.any="any",e.text="text",e.media="media",e.document="document"}(jt||(jt={}));let Pt=0;class $t{source;onChange=()=>{};schema;root;constructor(e,t){this.schema=e?"string"==typeof e?JSON.parse(e):e:{title:t,type:"object",properties:{}},this.schema.properties||(this.schema.properties={}),this.root=new Et("",this.schema,this),this.root.loadChildren()}get isEmpty(){return!this.root.children||0===this.root.children.length}get children(){return this.root.children}reload(){return this.root=new Et("",this.schema,this),this.root.loadChildren(),this.onChange?.(this),this}withSource(e,t){return this.source={uri:t,name:e},this}withChangeListener(e){return this.onChange=e,this}replaceSchema(e){this.schema=e||{title:this.schema.title,type:"object",properties:{}},this.reload()}clone(){const e=new $t(this.schema);return e.source=this.source,this.onChange&&e.withChangeListener(this.onChange),e}}class Et{schema;loader;parent;name;isRequired=!1;type;children;constructor(e,t,r,n){if(this.schema=t,this.loader=r,this.parent=n,this.name=e,this.type=Ot(t),this.parent){let t=this.parent._getPropertiesSchema().required;this.isRequired=!(!t||!Array.isArray(t))&&t.includes(e)}}get title(){return this.schema.title}set title(e){this.schema.title=e}get description(){return this.schema.description}set description(e){this.schema.description=e}get isParent(){return this.type.isObject}get isNew(){return!!this.schema.isNew}set isNew(e){e?this.schema.isNew=!0:delete this.schema.isNew}resetIsNew(){const e=this.isNew;return this.isNew=!1,e}getNameSignature(){return`${this.name}${this.isRequired?"":"?"}`}getTypeSignature(){return`${this.type.name}${this.type.isArray?"[]":""}${this.type.isNullable?"?":""}`}getSignature(){return`${this.getNameSignature()}: ${this.getTypeSignature()}`}reloadTree(){this.loader.reload()}loadChildren(){this.children=[],this.schema.items&&this.schema.items.properties?this._loadChildren(this.schema.items.properties):this.schema.properties&&this._loadChildren(this.schema.properties)}_loadChildren(e){for(const t of Object.keys(e)){const r=e[t],n=new Et(t,r,this.loader,this);this.children.push(n),n.isParent&&n.loadChildren()}}_getPropertiesSchema(){return this.type.isArray&&this.type.isObject?this.schema.items:this.schema}findAvailableChildName(e){const t=this._getPropertiesSchema().properties||{};let r;do{r=e+ ++Pt}while(t[r]);return r}addChild(e,t,r=!1){if(!this.type.isObject)throw new Error("Cannot add child to a non object node");this.children||(this.children=[]);const n=function(e,t,r,n=!1){if("object"!==e.type)throw new Error("Cannot add property to a non-object schema");e.properties||(e.properties={});const s={};return St(s,r),e.properties[t]=s,n&&(Array.isArray(e.required)?function(e,t){e.includes(t)||e.push(t)}(e.required,t):e.required=[t]),s}(this._getPropertiesSchema(),e,t,r),s=new Et(e,n,this.loader,this);return this.children.push(s),s}remove(){if(this.parent&&this.parent.type.isObject){return function(e,t){e.properties&&(delete e.properties[t],Array.isArray(e.required)&&(e.required=e.required.filter((e=>e!==t))))}(this.parent._getPropertiesSchema(),this.name),this.parent.children&&(this.parent.children=this.parent.children.filter((e=>e.name!==this.name))),!0}return!1}update(e){let t=!1;null!=e.name&&this.name!==e.name&&(this.parent&&function(e,t,r){if(e.properties){const n=e.properties,s={};for(const e of Object.keys(n)){const i=n[e];e===t?s[r]=i:s[e]=i}e.properties=s}e.required&&(e.required=e.required.map((e=>e===t?r:e)))}(this.parent._getPropertiesSchema(),this.name,e.name),this.name=e.name,t=!0),null!=e.isRequired&&this.isRequired!==e.isRequired&&(this.parent&&function(e,t,r){if(Array.isArray(e.required)){const n=e.required.indexOf(t);r?n<0&&e.required.push(t):n>-1&&e.required.splice(n,1)}else r&&(e.required=[t])}(this.parent._getPropertiesSchema(),this.name,e.isRequired),this.isRequired=e.isRequired,t=!0);let r=e.type?.name;"any"===r&&(r=void 0);const n=r!==this.schema.type;return e.type&&(St(this.schema,e.type),this.type=e.type,this.type.isObject?this.children||(this.children=[]):this.children=void 0,t=!0),this.schema.editor&&null===e.editor?(this.schema.editor=void 0,this.schema.format=void 0,t=!0):e.editor?(this.schema.editor=e.editor,this.schema.format=e.editor,t=!0):n&&(this.schema.editor=void 0,this.schema.format=void 0,t=!0),e.description!==this.description&&(this.description=e.description,t=!0),t}getUpdateFromNameAndTypeSignature(e,t){let r=e.trim(),n=!0;r.endsWith("?")&&(r=r.substring(0,r.length-1).trim(),n=!1);const s=function(e){let t=!1,r=!1;(e=e.trim()).endsWith("?")&&(r=!0,e=e.substring(0,e.length-1).trim()),e.endsWith("[]")&&(t=!0,e=e.substring(0,e.length-2).trim());const n=jt[e];if(!n)throw new Error(`Unknown type "${e}"`);return{name:n,isArray:t,isNullable:r,isObject:n===jt.object}}(t);let i;return"text"===s.name?(s.name=jt.string,i="textarea"):"media"===s.name?(s.name=jt.any,i="media"):"document"===s.name?(s.name=jt.any,i="document"):i=null,{name:r,type:s,isRequired:n,editor:i}}updateFromNameAndTypeSignature(e,t){return this.update(this.getUpdateFromNameAndTypeSignature(e,t))}updateFromSignature(e){const t=(e=e.trim()).indexOf(":");if(t<0)throw new Error("Expecting a name and a type separated by a colon");const r=e.substring(0,t),n=e.substring(t+1);return this.updateFromNameAndTypeSignature(r,n)}}function Tt(e){return{name:e.getNameSignature(),type:e.getTypeSignature(),description:e.description}}const It=function(){const e=Object.values(jt),t=[...e];for(const r of e)t.push(r+"[]");return e.sort(),t}();function qt({value:r,onChange:n,onCancel:s,onSave:i}){const[a,o]=d(!1);if(!r)return null;return t("div",{className:"flex items-center",children:[e("div",{className:"flex-1",children:e(Mt,{value:r.name,onChange:e=>{n({...r,name:e})},onCancel:s,onSave:i})}),e("div",{className:"px-1 font-semibold",children:":"}),e("div",{className:"flex-1",children:e(Lt,{value:r.type,onChange:e=>{n({...r,type:e})},onCancel:s,onSave:i})}),t("div",{children:[e(g,{variant:"ghost",size:"xs",onClick:()=>o(!0),title:"Edit description",children:e(M,{className:"size-4"})}),e(Dt,{value:r.description,isOpen:a,onClose:e=>{void 0!==e&&"string"==typeof e&&n({...r,description:e},!0),o(!1)}})]})]})}function Mt({value:t,onChange:r,onCancel:n,onSave:s}){const o=i(null);a((()=>{o.current?.focus()}),[]);return e("input",{onKeyUp:e=>{switch(e.key){case"Enter":s?.();break;case"Escape":n?.()}},ref:o,value:t,onChange:e=>{r(e.target.value)},className:f.INPUT_UNSTYLED,style:{fontSize:"inherit",width:"",display:"inline"}})}function Lt({value:t,onChange:r,onCancel:n,onSave:s}){return e(j,{className:f.INPUT_UNSTYLED,options:It,value:t||"",onBlur:()=>{s?.()},onChange:r,onKeyDown:(e,t)=>{t||("Enter"===e.key?s?.():"Escape"===e.key&&n?.())},popupClass:"schema-type-suggest-popup z-90"})}function Dt({value:r,isOpen:n,onClose:s}){return t(w,{isOpen:n,onClose:s,children:[e(N,{children:"Edit description"}),e(Ft,{value:r,onSave:s})]})}function Ft({value:n,onSave:s}){const o=i(null),[l,c]=d(n||"");return a((()=>{o.current&&o.current.focus()}),[o.current]),t(r,{children:[e(S,{className:"h-max",children:e("textarea",{ref:o,className:"dark:bg-gray-800 w-full h-full dark:text-white",value:l,onChange:e=>c(e.target.value)})}),e(O,{children:e(g,{onClick:()=>s(l),children:"Save Changes"})})]})}function zt({value:r}){return r?t("div",{className:"w-full flex items-baseline",children:[e("div",{children:r.name||""}),e("div",{className:"ml-2 text-sm text-muted",children:r.type||""})]}):null}function Rt(e){const[t,r]=d(new $t(e||{type:"object",properties:{}}).withChangeListener((e=>{r(e.clone())})));return t}const Vt="block text-sm sm:leading-6 rounded-md border-0 py-1.5 px-4",_t=`${Vt} hover:shadow-xs hover:ring-1 hover:ring-inset hover:ring-ring`,Ut=`${Vt} shadow-xs ring-1 ring-inset ring-ring`;function Kt({value:r,onChange:n,onDelete:s,outlineOnHover:i=!1,editOnClick:a=!0,placeholder:o,viewer:l,editor:c,skipClickOutside:h,isEditing:u=!1,readonly:p=!1,onValidate:m}){const{on:f,off:g,isOn:y}=A(u),[v,b]=d();return t("div",{className:"",children:[y&&!p?e(Wt,{value:r,onSave:e=>{if(m){const t=m(e);if(t)return void b(t);b(void 0)}n(e)&&g()},onCancel:g,editor:c,skipClickOutside:e=>!!h&&h(e)}):e(Bt,{value:r,onEdit:f,viewer:l,placeholder:o,outlineOnHover:i,editOnClick:a,onDelete:s,readonly:p}),v&&e("div",{className:"text-red-500 text-sm",children:v})]})}function Bt({viewer:r,value:n,onEdit:s,editOnClick:i,outlineOnHover:a,placeholder:o,onDelete:l,readonly:c}){const d="invisible group-hover:visible";return t("div",{tabIndex:0,onKeyUp:e=>{"Enter"===e.key&&s()},onClick:()=>{i&&s()},className:U("flex justify-start items-center group",a?_t:Vt,{"cursor-pointer":i}),children:[e(r,{value:n,placeholder:o}),t("div",{className:"ml-auto flex space-x-2",children:[!c&&l&&e(g,{variant:"ghost",size:"sm",className:d,onClick:l,children:e(I,{className:"size-4"})}),c?null:e(g,{variant:"ghost",size:"sm",className:d,onClick:s,children:e(L,{className:"size-4"})})]})]})}function Wt({editor:t,value:r,onSave:n,onCancel:s,skipClickOutside:a}){const[o,l]=d(r),c=i(r),[h,u]=d(null),p=()=>{n(c.current)},m=P(p,a);return e("div",{ref:m,children:e("div",{className:Ut,children:e("div",{className:"w-full",onClick:e=>e.stopPropagation(),children:e(t,{value:o,onChange:(e,t=!1)=>{l(e),c.current=e,t&&(h&&clearTimeout(h),u(setTimeout((()=>{n(e)}),500)))},onSave:p,onCancel:s})})})})}function Ht(e){const t=e.target;return!(!t.closest||!t.closest(".schema-type-suggest-popup"))}function Jt({schema:r,readonly:n=!1}){return t("ul",{className:"",children:[r.children.map((e=>Gt(e,n))),n?null:e(er,{parent:r.root})]})}function Gt(t,r){return t.isParent?e(Zt,{property:t,readonly:r},t.name):e(Xt,{node:t,readonly:r},t.name)}function Xt({node:t,readonly:r}){return e("li",{children:e(Qt,{property:t,readonly:r})})}function Zt({property:r,readonly:n}){const[s,i]=d(!0);return t("li",{children:[t("div",{className:"flex items-center w-full",children:[e("button",{onClick:()=>i(!s),children:e(s?D:F,{className:"size-4"})}),e("div",{className:"flex-1",children:e(Qt,{property:r,readonly:n})})]}),s&&t("ul",{className:"ml-4 border-l border-gray-400 border-dashed",children:[(r.children||[]).map((e=>Gt(e,n))),n?null:e(er,{parent:r})]})]})}function Yt(e){return e?/^[a-zA-Z0-9_]+[?]?$/.test(e)?void 0:"Only letters, numbers, underscores or question mark are allowed (a-zA-Z0-9_?)":"Name is required"}function Qt({property:t,readonly:r}){const n=x(),s=t.resetIsNew(),i=Tt(t);return e(Kt,{value:i,onChange:e=>{try{e.description&&"string"!=typeof e.description&&(e.description=void 0);const r=t.getUpdateFromNameAndTypeSignature(e.name,e.type);t.update({...r,description:e.description})&&t.reloadTree()}catch(e){return n({status:"error",title:"Invalid property declaration",description:e.message,duration:9e3}),!1}return!0},onDelete:()=>{t.remove(),t.reloadTree()},editor:qt,viewer:zt,outlineOnHover:!0,isEditing:s,skipClickOutside:Ht,readonly:r,onValidate:e=>Yt(e.name)})}function er({parent:r}){return t(g,{variant:"ghost",onClick:()=>{const e=r.findAvailableChildName("new_property_");r.addChild(e,{isObject:!1,isArray:!1,isNullable:!1,name:jt.string},!0).isNew=!0,r.reloadTree()},children:[e(T,{className:"size-4"}),"Add property"]})}function tr({content:t,...r}){const n=i(null);return a((()=>{if(!n.current)return;const e=(new DOMParser).parseFromString(t,"image/svg+xml").querySelector("svg");if(!e)return console.warn("SvgIcon: No <svg> element found in provided string"),void(n.current.innerHTML="");r&&Object.entries(r).forEach((([t,r])=>{if(null==r)return;const n="className"===t?"class":t;e.setAttribute(n,String(r))})),n.current.innerHTML="",n.current.appendChild(e)}),[t,r]),e("span",{ref:n})}function rr(t){return r=>e(tr,{content:t,...r})}function nr({onDrop:r,message:n,buttonLabel:s="Upload Files",allowFolders:a=!0,className:o=""}){const[l,c]=d(!1),h=i(null),u=i(null);return t("div",{className:`flex flex-col items-center justify-center py-12 border-2 rounded-lg transition-colors ${l?"border-color-primary bg-color-primary/10":"border-dashed border-color-border"} ${o}`,onDragOver:e=>{e.preventDefault(),e.dataTransfer.types.includes("Files")&&c(!0)},onDragLeave:e=>{e.preventDefault(),u.current&&!u.current.contains(e.relatedTarget)&&c(!1)},onDrop:async e=>{if(e.preventDefault(),c(!1),e.dataTransfer.items&&e.dataTransfer.items.length>0){const t=Array.from(e.dataTransfer.items),n=[],s=new Set,i=async e=>{if(e.isFile){const t=await new Promise((t=>{e.file((r=>{Object.defineProperty(r,"webkitRelativePath",{writable:!0,value:e.fullPath.substring(1)}),t(r)}))}));!t.name.startsWith(".")&&t.size>0&&n.push(t);const r=e.fullPath.substring(1).split("/").slice(0,-1).join("/");r&&s.add(r)}else if(e.isDirectory){const t=e.createReader(),r=await new Promise((e=>{t.readEntries((t=>{e(t)}))}));await Promise.all(r.map(i));const n=e.fullPath.substring(1);n&&s.add(n)}};try{if(await Promise.all(t.map((e=>{const t=e.webkitGetAsEntry?e.webkitGetAsEntry():e;return t?i(t):Promise.resolve()}))),n.length>0){const e=new Set(Array.from(s).map((e=>e.split("/")[0])).filter(Boolean)).size,t=n.length;let i="";i=e>0?1===e?`Preparing to upload 1 folder with ${t} files...`:`Preparing to upload ${e} folders with ${t} files...`:`Preparing to upload ${t} file${1===t?"":"s"}...`,r(n,{count:n.length,message:i})}}catch(t){console.error("Error processing dropped files:",t);const n=Array.from(e.dataTransfer.files);n.length>0&&r(n)}}else if(e.dataTransfer.files&&e.dataTransfer.files.length>0){const t=Array.from(e.dataTransfer.files);r(t)}},children:[e(z,{className:"h-12 w-12 mb-3 transition-colors "+(l?"text-primary":"text-muted/50")}),e("p",{className:"text-color-muted-foreground",children:n}),t("div",{className:"mt-4 text-center",children:[t("div",{className:"text-sm text-muted mb-2",children:["Drag and drop files",a?" or folders":""," here, or"]}),t(g,{onClick:()=>{h.current&&h.current.click()},children:[e(z,{className:"h-4 w-4 mr-2"}),s]}),e("input",{type:"file",ref:h,onChange:e=>{if(e.target.files&&e.target.files.length>0){const t=Array.from(e.target.files);if(t.some((e=>e.webkitRelativePath&&e.webkitRelativePath.includes("/")))){const e=new Set(t.map((e=>e.webkitRelativePath?.split("/")[0])).filter(Boolean)).size,n=t.length,s=1===e?`Preparing to upload 1 folder with ${n} files...`:`Preparing to upload ${e} folders with ${n} files...`,i={count:t.length,message:s};r(t,i)}else{const e={count:t.length,message:`Preparing to upload ${t.length} file${1===t.length?"":"s"}...`};r(t,e)}}},multiple:!0,webkitdirectory:a?"":void 0,directory:a?"":void 0,className:"hidden"})]})]})}function sr({title:r,count:n,icon:s=e(R,{className:"h-4 w-4 text-green-500"}),items:i}){const[a,o]=d(!1);return t("div",{className:"border border-color-border rounded-md overflow-hidden",children:[t("div",{className:"flex items-center justify-between p-3 bg-color-muted/10 cursor-pointer",onClick:()=>o(!a),children:[t("div",{className:"flex items-center",children:[e("span",{className:"mr-2",children:s}),e("span",{className:"font-medium",children:r}),e("span",{className:"ml-2 px-2 py-0.5 bg-color-muted/20 rounded-full text-xs",children:n})]}),e("button",{className:"text-muted",children:e("svg",{className:"h-5 w-5 transition-transform "+(a?"transform rotate-180":""),fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})})]}),a&&e("div",{className:"p-3 border-t border-color-border max-h-48 overflow-y-auto",children:i.length>0?e("ul",{className:"space-y-1",children:i.map(((t,r)=>e("li",{className:"text-sm py-1 px-2 rounded hover:bg-color-muted/10",children:t},r)))}):e("div",{className:"text-sm text-muted py-2",children:"No items to display"})})]})}function ir({files:r,className:n="",location:s,collection:i}){const a=r.filter((e=>"success"===e.status)),o=r.filter((e=>"updated"===e.status)),l=r.filter((e=>"skipped"===e.status)),c=r.filter((e=>"failed"===e.status)),d=a.length,h=o.length,u=l.length,p=c.length,m=r.length;return t("div",{className:`flex flex-col py-2 ${n}`,children:[t("div",{className:"flex items-center mb-4",children:[e("div",{className:"size-8 mr-4 rounded-full bg-success/10 flex items-center justify-center",children:e(R,{className:"size-4 text-success"})}),e("div",{children:t("p",{className:"text-muted",children:[m," file",1!==m?"s":""," processed",i?` in collection '${i}'`:"",s?` in folder '${s}'`:""]})})]}),t("div",{className:"space-y-3 mt-2",children:[d>0&&e(sr,{title:"Successfully Uploaded",count:d,icon:e(R,{className:"h-4 w-4 text-green-500"}),items:a.map((e=>e.name))}),h>0&&e(sr,{title:"Successfully Updated",count:h,icon:e(R,{className:"h-4 w-4 text-blue-500"}),items:o.map((e=>e.name))}),u>0&&e(sr,{title:"Skipped (Already Existed)",count:u,icon:e(V,{className:"h-4 w-4 text-amber-500"}),items:l.map((e=>e.name))}),p>0&&e(sr,{title:"Failed to Upload",count:p,icon:e(_,{className:"h-4 w-4 text-red-500"}),items:c.map((e=>e.name))})]})]})}const ar="#text",or="#comment",lr="#cdata",cr="DECLARATION_TAG",dr={tagColor:"#d43900",textColor:"#333",attributeKeyColor:"#2a7ab0",attributeValueColor:"#008000",separatorColor:"#333",commentColor:"#aaa",cdataColor:"#1d781d",fontFamily:"monospace"},hr=l({theme:dr,collapsible:!1,indentSize:2}),ur=()=>c(hr),pr=new de({preserveOrder:!0,ignoreAttributes:!1,attributeNamePrefix:"",allowBooleanAttributes:!0,commentPropName:or,cdataPropName:lr,parseTagValue:!1});function mr(r){const{indentation:n,children:s,isInline:i}=r,{theme:a}=ur();return t("div",{style:{color:a.cdataColor},children:[e("span",{children:`${n}<![CDATA[`}),s,e("span",{children:`${i?"":n}]]>`})]})}function fr(t){const{collapsible:r,theme:n}=ur(),{collapsed:s}=t;return r?e("span",{style:{position:"relative"},children:e("span",{style:{position:"absolute",right:"0",border:0,padding:0,background:"none"},children:e(gr,{fill:n.separatorColor,style:{transform:`rotate(${s?0:90}deg)`,transition:"transform 0.2s"}})})}):null}function gr({...t}){return e("svg",{width:"16px",height:"16px",viewBox:"0 0 24 24",...t,children:e("path",{d:"M9 17.898C9 18.972 10.2649 19.546 11.0731 18.8388L17.3838 13.3169C18.1806 12.6197 18.1806 11.3801 17.3838 10.6829L11.0731 5.16108C10.2649 4.45388 9 5.02785 9 6.1018V17.898Z"})})}function yr(e){const{collapsible:t,initialCollapsedDepth:r}=ur(),[n,s]=d((()=>!(oe(r)||!t)&&e>=r));return a((()=>{s(!(oe(r)||!t)&&e>=r)}),[r,e,t]),{collapsed:n,buttonProps:t?{onClick:()=>s((e=>!e)),role:"button",style:{cursor:"pointer"}}:{}}}function vr(r){const{indentation:n,children:s,isInline:i,level:a}=r,{theme:o}=ur(),{collapsed:l,buttonProps:c}=yr(a);return t("div",{style:{color:o.commentColor},children:[t("span",{...c,children:[e("span",{children:n}),e(fr,{collapsed:l}),e("span",{children:"\x3c!-- "})]}),!l&&s,l&&"...",e("span",{children:`${i||l?" ":n}--\x3e`})]})}function br(r){const{attributes:n}=r,{theme:s}=ur();return n?e("span",{children:Object.entries(n).map((([r,n])=>t("span",{children:[e("span",{style:{color:s.attributeKeyColor},children:` ${r}`}),e("span",{style:{color:s.separatorColor},children:"="}),e("span",{style:{color:s.attributeValueColor},children:`"${n}"`})]},`attribute-${r}`)))}):null}function xr(r){const{indentation:n,tagKey:s,attributes:i}=r,{theme:a}=ur();return t("div",{children:[e("span",{style:{color:a.separatorColor},children:`${n}<?`}),e("span",{style:{color:a.tagColor},children:`${s.slice(1)}`}),e(br,{attributes:i}),e("span",{style:{color:a.separatorColor},children:"?>"})]})}function wr(e){return"string"==typeof e&&e.includes("\n")}function Nr(e){const t=e[":@"],r=le(e,":@"),[[n,s]]=Object.entries(r),i=function(e){switch(e){case ar:case lr:case or:return e;default:return e.startsWith("?")?cr:"TAG"}}(n);return{attributes:t,tagKey:n,subElements:s,type:i}}function kr(e){return!!e&&Object.keys(e).length>0}function Cr(n){const{indentation:s,tagKey:i,attributes:a,children:o,isInline:l,hasChildren:c,level:d}=n,{collapsed:h,buttonProps:u}=yr(d),{theme:p}=ur();return t("div",{children:[t("span",{...u,children:[e("span",{children:s}),e(fr,{collapsed:h}),e("span",{style:{color:p.separatorColor},children:"<"}),e("span",{style:{color:p.tagColor},children:`${i}`}),!h&&e(br,{attributes:a}),h&&kr(a)&&" ...",e("span",{style:{color:p.separatorColor},children:c?">":" />"})]}),c&&t(r,{children:[!h&&o,h&&"...",e("span",{style:{color:p.separatorColor},children:`${l||h?"":s}</`}),e("span",{style:{color:p.tagColor},children:`${i}`}),e("span",{style:{color:p.separatorColor},children:">"})]})]})}function jr(t){const{hasSiblings:r,text:n,indentation:s,isText:i}=t,{theme:a}=ur(),o=i?{color:a.textColor}:void 0;return wr(n)||r?e("div",{style:o,children:n.split("\n").filter((e=>!!e.trim())).map(((t,r)=>e("div",{children:`${s}${t.trim()}`},`${r}`)))}):e("span",{style:o,children:n})}function Sr(t){const{elements:n,level:s=0,isText:i=!0}=t,{indentSize:a}=ur();return Array.isArray(n)&&0!==n.length?e(r,{children:n.map(((t,r)=>{const{tagKey:o,attributes:l,subElements:c,type:d}=Nr(t),h=n.length>1,u=function(e,t){return new Array(t*e+1).join(" ")}(a,s),p=`${s}-${r}`,m=function(e){return"string"!=typeof e&&1===e.length&&ar in e[0]&&!wr(e[0][ar])}(c);switch(d){case ar:return e(jr,{text:c,indentation:u,hasSiblings:h,isText:i},p);case or:return e(vr,{isInline:m,indentation:u,level:s,children:e(Sr,{elements:c,level:s+1,isText:!1})},p);case lr:return e(mr,{indentation:u,isInline:m,children:e(Sr,{elements:c,level:s+1,isText:!1})},p);case cr:return e(xr,{indentation:u,tagKey:o,attributes:l},p);default:return e(Cr,{indentation:u,tagKey:o,attributes:l,isInline:m,hasChildren:c.length>0,level:s,children:e(Sr,{elements:c,level:s+1})},p)}}))}):null}function Or(){return e("div",{children:"Invalid XML!"})}function Ar(t){const{theme:r,xml:n,collapsible:s=!1,indentSize:i=2,invalidXml:l,initalCollapsedDepth:c,initialCollapsedDepth:h}=t,[u,p]=d((()=>({...dr,...r}))),{json:m,valid:f}=function(e){return o((()=>{try{if(!he.validate(e))throw new Error("Invalid XML!");const t=pr.parse(e);if("string"==typeof e&&e.trim().length>0&&0===t.length)throw new Error("Invalid XML!");return{json:t,valid:!0}}catch(e){return{json:null,valid:!1,errorMessage:`Fail to parse: ${e.message}`}}}),[e])}(n),g=o((()=>({theme:u,collapsible:s,indentSize:i,initialCollapsedDepth:h??c})),[u,s,i,c,h]);return a((()=>{p((e=>{const t={...dr,...r};return ce(t,e)?e:t}))}),[r]),f?e(hr.Provider,{value:g,children:e("div",{className:"rxv-container",style:{whiteSpace:"pre-wrap",fontFamily:u.fontFamily,overflowWrap:"break-word"},children:e(Sr,{elements:m})})}):l||e(Or,{})}export{Le as ArrayPropertySchema,fe as CodeMirrorEditor,nr as DropZone,pe as EditorApi,ye as FieldSetContextProvider,Se as Form,we as FormContextProvider,Ce as FormError,ke as FormHelper,Ne as FormLabel,Ae as GeneratedForm,je as Input,tt as JSONCode,dt as JSONDisplay,Ct as JSONSchemaEditorModal,rt as JSONView,Be as ManageObjectEntry,Ke as ManagedListProperty,Ve as ManagedObject,Re as ManagedObjectBase,_e as ManagedObjectProperty,Ue as ManagedProperty,We as ManagedScalarEntry,$t as ManagedSchema,ze as Node,yt as Popover,ht as PopoverContext,wt as Progress,Nt as PropertiesView,qt as PropertyEditor,Mt as PropertyNameEditor,Me as PropertySchema,zt as PropertyViewer,$e as ScalarField,qe as Schema,Jt as SchemaEditor,Et as SchemaNode,tr as SvgIcon,sr as UploadResultCategory,ir as UploadSummary,Ar as XMLViewer,De as computeTitleFromName,rr as createSvgIcon,Tt as getEditableSchemaProperty,ve as useFieldSet,xe as useForm,ut as usePopoverContext,Rt as useSchema,Yt as validatePropertyName};
|
|
1
|
+
import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import n from"debounce";import s,{useRef as i,useEffect as a,useMemo as o,createContext as l,useContext as c,useState as d,Children as h,isValidElement as u}from"react";import{EditorView as p}from"@codemirror/view";import{useSafeLayoutEffect as m,Styles as f,Button as g,DotBadge as y,Table as v,VTooltip as b,useToast as x,VModal as w,VModalTitle as N,VModalBody as k,VModalFooter as C,VSelectBox as S,ModalBody as j,ModalFooter as O,useFlag as A,useClickOutside as P}from"@vertesia/ui/core";import{Text as $,EditorState as E}from"@codemirror/state";import{Plus as T,Trash2 as I,Info as q,AlignLeft as M,SquarePen as L,ChevronDown as D,ChevronRight as F,UploadIcon as z,CheckCircleIcon as R,AlertCircleIcon as V,XCircleIcon as _}from"lucide-react";import U from"clsx";import K from"ajv";import{ObjectWalker as B}from"@vertesia/json";import W from"react-markdown";import H from"remark-gfm";import{visit as J,SKIP as G}from"unist-util-visit";import{offset as X,shift as Z,flip as Y}from"@floating-ui/dom";import{useFloating as Q,autoUpdate as ee,useDismiss as te,useClick as re,useHover as ne,useInteractions as se,useTransitionStyles as ie,FloatingPortal as ae,FloatingFocusManager as oe,safePolygon as le}from"@floating-ui/react";import{json as ce}from"@codemirror/lang-json";import{basicSetup as de}from"codemirror";import{isNil as he,omit as ue,isEqual as pe}from"lodash-es";import{XMLParser as me,XMLValidator as fe}from"fast-xml-parser";let ge=null;class ye{editor;constructor(e){this.editor=e}setValue(e){this.editor.dispatch({changes:{from:0,to:this.editor.state.doc.length,insert:e||""}})}getValue(){return this.editor.state.doc.toString()}}const ve=[p.theme({"&":{fontSize:"14px",fontFamily:"monospace"},".cm-content":{fontFamily:"inherit"},".cm-scroller":{fontFamily:"inherit"},".cm-gutters":{backgroundColor:"transparent",color:"#ddd"},".cm-focused":{outline:"none"},".cm-cursor":{borderLeft:"2px solid #808080",borderLeftColor:"#808080",animation:"blink 1.2s step-start infinite"},"@keyframes blink":{"50%":{opacity:0}}}),p.lineWrapping];function be({onChange:t,value:r,className:s,editorRef:l,extensions:c,debounceTimeout:d=0}){const h=i(null),u=i(void 0);a((()=>{if(t)return u.current=d>0?n(t,d):t,()=>{u.current=void 0}}),[t,d]);const f=o((()=>e("div",{ref:h,className:s})),[s]);return m((()=>{if(h.current){let t=[...ve,(e=e=>{u.current?.(e)},p.updateListener.of((t=>{t.docChanged&&e(t)})))];Array.isArray(c)?t=t.concat(c):c&&t.push(c);const n=((e="",t=[])=>{const r="string"==typeof e?$.of(e.split("\n")):e;return ge?ge.doc.toString()!==r.toString()&&(ge=E.create({doc:r,extensions:t})):ge=E.create({doc:r,extensions:t}),ge})(r,t),s=new p({state:n,parent:h.current}),i=new ye(s);return l&&(l.current=i),()=>{s.destroy(),l&&(l.current=void 0)}}var e}),[f,c]),f}const xe=l(void 0),we=xe.Provider;function Ne(){const e=c(xe);if(!e)throw new Error("useFieldSet must be used within a Form or FieldSet element");return e}const ke=l(void 0);function Ce(){const e=c(ke);if(!e)throw new Error("useForm must be used within a Form element");return e}const Se=ke.Provider;function je({htmlFor:r,required:n,children:s}){return t("label",{htmlFor:r,className:"block text-sm font-medium leading-6 text-gray-900 dark:text-gray-200",children:[s,n&&e("sup",{className:"text-red-600",children:"*"})]})}function Oe({children:t}){return e("p",{className:"mt-2 text-sm text-gray-500",children:t})}function Ae({children:t}){return e("p",{className:"mt-2 text-sm text-red-600",children:t})}const Pe=s.forwardRef((({object:t,type:r="text",onChange:n,...s},i)=>{const[a,o]=d(null!=t.value?String(t.value):""),[l,c]=d(t.schema.isBoolean&&!0===t.value);s.className?s.className=U(f.INPUT,s.className):s.className=f.INPUT;const h=e=>{o(e.target.value),t.schema.isBoolean?(t.value=e.target.checked,c(t.value)):t.value=e.target.value,n&&n(e)};return"textarea"===r?e("textarea",{ref:i,...s,value:a,onChange:h}):e("input","checkbox"===r?{ref:i,...s,type:"checkbox",checked:l,onChange:h,className:"form-check-input"}:{ref:i,...s,type:r,value:a,onChange:h})}));function $e({object:t,components:r,onSubmit:n,children:s,onChange:i}){return t.observer=i,e(Se,{value:{object:t,components:r||{}},children:e("form",{className:"w-full",onSubmit:e=>{e.stopPropagation(),e.preventDefault(),n&&n(t.value)},children:s})})}function Ee(){const t=Ce();return e("div",{className:"flex flex-col gap-4 w-full",children:t.object.properties.map(Ie)})}function Te({children:r,...n}){return t($e,{...n,children:[e(Ee,{}),r]})}function Ie(t){return t.isList?e(Le,{object:t},t.name):t.isObject?e(Me,{object:t},t.name):e(qe,{object:t},t.name)}function qe({object:r,editor:n,inline:s=!1}){n||(n=r.schema.editor);const{components:i}=Ce(),a=n&&i[n]||Pe,o=r.getInputType();"checkbox"===o&&(s=!0);return t("div",{className:"",children:[t("div",{className:U("flex gap-2",s?"flex-row items-center":"flex-col"),children:[!r.isListItem&&e(je,{required:r.schema.isRequired,children:r.title}),e(a,{object:r,type:o,onChange:e=>{const{value:t}=e.target;r.value=r.schema.isNumber?parseFloat(t):t}})]}),r.schema.description&&e(Oe,{children:r.schema.description})]})}function Me({object:r}){return t("div",{className:"flex flex-col gap-4 my-4 py-2 pl-4 border-l-4 border-l-solid border-l-slate-100 dark:border-l-slate-600",children:[!r.isListItem&&e("div",{className:"text-gray-900 dark:text-gray-200 font-semibold",children:r.title}),r.properties.map(Ie)]})}function Le({object:r}){const[n,s]=d(r.value||[]);return t("div",{className:"flex flex-col gap-4 my-4 py-2 pl-4 border-l-4 border-l-solid border-l-slate-100 darK:border-l-slate-600",children:[!r.isListItem&&e("div",{className:"text-gray-900 dark:text-gray-200 font-semibold",children:r.title}),r.items.map(((t,i)=>e(De,{object:t,list:r,onDelete:()=>(e=>{r.remove(e),s([...r.value])})(i)},`${i}-${n[i]??""}`))),e("div",{children:t(g,{variant:"secondary",onClick:()=>{r.add(),s([...r.value])},children:[e(T,{className:"size-6"})," Add"]})})]})}function De({list:r,object:n,onDelete:s}){return t("div",{className:"flex gap-2 w-full",children:[e("div",{className:"flex-1",children:(i=n,a=r.schema.arraySchema.editor,i.isList?e(Le,{object:i}):i.isObject?e(Me,{object:i}):e(qe,{object:i,editor:a}))}),e(g,{variant:"secondary",onClick:s,children:e(I,{className:"size-4"})})]});var i,a}class Fe{schema;properties={};_validator;constructor(e){this.schema=e||{type:"object",properties:{}},this.load()}get validator(){if(!this._validator){const e=new K({allErrors:!0,strict:!1});this._validator=e.compile(this.schema)}return this._validator}load(){if(this.schema.properties){const e=this.schema.properties;Object.keys(e).forEach((t=>{this.loadProperty(t,e[t])}))}}hasProperties(){return Object.keys(this.properties).length>0}get title(){return this.schema.title||this.schema.name}get description(){return this.schema.description}loadProperty(e,t){let r;return r="array"===t.type?new Re(this,e,t):new ze(this,e,t),this.properties[e]=r,r}get type(){return this.schema.type}validate(e){return this.validator(e)?null:this.validator.errors||[]}addProperty(e,t,r=!1){"object"!==this.schema.type&&(this.schema.type="object"),this.schema.properties||(this.schema.properties={});const n="string"==typeof t?"object"===(s=t)?{type:"object",properties:{}}:"array"===s?{type:"array",items:{}}:{type:s}:t;var s;const i=this.loadProperty(e,n);return this.schema.properties[i.name]=i.schema,r&&(i.isRequired=!0),i}removeProperty(e){this.schema.properties&&(delete this.schema.properties[e],Array.isArray(this.schema.required)&&(this.schema.required=this.schema.required.filter((t=>t!==e)))),delete this.properties[e]}getProperty(e){return this.properties[e]}get editor(){return this.schema.editor}}class ze extends Fe{parent;name;constructor(e,t,r){if(super(r),this.parent=e,this.name=t,"array"===r.type)throw new Error("Array property must be instantiated using ArrayPropertySchema");"object"!==r.type||r.properties||(r.properties={})}get isMulti(){return!1}get isReadOnly(){return!!this.schema.readOnly}set isReadOnly(e){this.schema.readOnly=e}get defaultValue(){return this.schema.default}set defaultValue(e){this.schema.default=e}get enum(){return this.schema.enum}set enum(e){this.schema.enum=e}get isRequired(){const e=this.parent.schema.required;return!!e&&e.includes(this.name)}set isRequired(e){let t=Array.isArray(this.parent.schema.required)?this.parent.schema.required:[];t=e?t.concat(this.name):t.filter((e=>e!==this.name)),this.parent.schema.required=t}get type(){return this.schema.type}set type(e){this.schema.type!==e&&(this.schema.type=e,"object"!==e&&(this.properties={},this.schema.properties=void 0))}remove(){this.parent.removeProperty(this.name)}get isBoolean(){return"boolean"===this.type}get isString(){return"string"===this.type}get isNumber(){return"number"===this.type||"integer"===this.type}get isObject(){return"object"===this.type}}class Re extends ze{arraySchema;constructor(e,t,r){super(e,t,function(e){if("array"!==e.type)throw new Error("Expecting an array schema");if(e.items){if(Array.isArray(e.items))throw new Error("Tuple arrays are not supported")}else e.items={};return e.items}(r)),this.arraySchema=r}get isMulti(){return!0}}function Ve(e){return(e=e.replace(/_/g," ").replace(/([a-z0-9])&([A-Z])/g,"$1 $2"))[0].toUpperCase()+e.slice(1)}function _e(e,t){if(t.editor)return t.editor;switch(t.type){case"number":case"integer":return"number";case"boolean":return"checkbox";default:return"text"}}class Ue{parent;schema;name;observer;constructor(e,t,r){this.parent=e,this.schema=t,this.name=r}get isRoot(){return!this.parent}get root(){return this.parent?this.parent.root:this}get path(){return this.parent?this.parent.path.concat(this.name):[]}get isScalar(){return!1}get isListItem(){return!1}get isObject(){return!1}get isList(){return!1}get title(){return this.schema.title||Ve(this.name)}onChange(e){this.observer&&!1===this.observer(this)||this.parent&&this.parent.onChange(e)}}class Ke extends Ue{constructor(e,t,r){super(e,t,r)}get isObject(){return!0}getProperty(e){const t=this.schema.properties[e];return t.isMulti?new Je(this,t,this.getOrInitArrayProperty(e)):t.isObject?new We(this,t,t.name,this.getOrInitObjectProperty(e)):new He(this,t)}getOrInitObjectProperty(e){let t=this.value[e];return t||(this.value[e]=t={}),t}getOrInitArrayProperty(e){let t=this.value[e];return t||(this.value[e]=t=[]),t}setPropertyValue(e,t){return this.value[e]!==t&&(this.value[e]=t,!0)}getPropertyValue(e){return this.value[e]}get properties(){const e=[];for(const t of Object.values(this.schema.properties))t.isMulti?e.push(new Je(this,t,this.getOrInitArrayProperty(t.name))):t.isObject?e.push(new We(this,t,t.name,this.getOrInitObjectProperty(t.name))):e.push(new He(this,t));return e}[Symbol.iterator](){return this.properties[Symbol.iterator]()}}class Be extends Ke{value;constructor(e,t={}){super(null,e instanceof Fe?e:new Fe(e),"#root"),this.value=t}}class We extends Ke{value;constructor(e,t,r,n){super(e,t,r),this.value=n}}class He extends Ue{constructor(e,t){super(e,t,t.name),void 0===e.value[this.name]&&void 0!==t.defaultValue&&(e.value[this.name]=t.defaultValue)}get isScalar(){return!0}set value(e){this.parent.setPropertyValue(this.name,e)&&this.onChange(this)}get value(){return this.parent.getPropertyValue(this.name)}getInputType(){return _e(this.name,this.schema)}}class Je extends Ue{value;items=[];constructor(e,t,r){super(e,t,t.name),this.value=r;for(const e of this.value)this.add()}get isList(){return!0}newItem(e){return this.schema.isObject?new Ge(this,e):new Xe(this,e)}add(){const e=this.newItem(this.items.length);return this.items.push(e),e}remove(e){const t=this.value;if(e>=0&&e<this.items.length){this.items.splice(e,1);for(let e=0,t=this.items.length;e<t;e++){const t=this.items[e];t.index=e,t.name=String(e)}}Array.isArray(t)&&e>=0&&e<t.length&&(t.splice(e,1),this.onChange(this))}[Symbol.iterator](){return this.items[Symbol.iterator]()}item(e){if(e<0||e>=this.value.length)return;const t=this.value[e];return this.schema.isObject?new We(this,this.schema,String(e),t):new Xe(this,e)}trim(){for(;void 0===this.items[this.items.length-1];)this.items.pop()}}class Ge extends Ke{index;key;constructor(e,t){super(e,e.schema,String(t)),this.index=t,void 0===e.value[t]&&(e.value[t]={}),this.key=this.name+"@"+Date.now()}get isListItem(){return!0}set value(e){this.parent.value[this.index]=e}get value(){return this.parent.value[this.index]}}class Xe extends Ue{index;key;constructor(e,t){super(e,e.schema,String(t)),this.index=t,void 0===e.value[t]&&void 0!==e.schema.defaultValue&&(e.value[t]=e.schema.defaultValue),this.key=this.name+"@"+Date.now()}get isScalar(){return!0}get isListItem(){return!0}set value(e){this.parent.value[this.index]=e}get value(){return this.parent.value[this.index]}getInputType(){return _e(this.name,this.schema)}}const Ze="text-pink-500 dark:text-pink-400",Ye="text-purple-500 dark:text-purple-400",Qe="text-blue-500 dark:text-blue-400",et={code:"bg-gray-100 dark:bg-slate-800 whitespace-pre-wrap p-4 rounded-lg font-mono",comma:Ze,assign:Ze,startObject:Ze,endObject:Ze,startArray:Ze,endArray:Ze,boolean:Ye,null:Ye,key:Qe,index:Qe,string:"text-orange-500 dark:text-orange-400",number:"text-green-500 dark:text-green-400"};class tt{renderer;parent;key;indent;result=[];constructor(e,t,r,n){this.renderer=e,this.parent=t,this.key=r,this.indent=n}get classMap(){return this.renderer.classMap}writeKey(e){const t=typeof e;"string"===t?(this.result.length>0&&this.result.push(`<span class='${this.classMap.comma}'>,\n</span>`),this.indent&&this.result.push(this.indent),this.result.push(`<span class="${this.classMap.key}">"${e}"</span><span class='${this.classMap.assign}'>: </span>`)):"number"===t&&(this.result.length>0&&this.result.push(`<span class='${this.classMap.comma}'>,\n</span>`),this.indent&&this.result.push(this.indent))}pushValue(e,t){if(this.writeKey(e),null===t)this.result.push(`<span class='${this.classMap.null}'>null</span>`);else if(t instanceof tt)this.result.push(t.renderStart()+t.renderValue()+t.renderEnd());else{let e;const r=typeof t;"string"===r?(t=(t=`"${t}"`).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">"),e=this.classMap.string):"number"===r?e=this.classMap.number:"boolean"===r&&(e=this.classMap.boolean),this.result.push(`<span class='${e}'>${t}</span>`)}}renderValue(){return this.result.join("")}}class rt extends tt{constructor(e,t,r,n){super(e,t,r,n)}renderStart(){return`<span class='${this.classMap.startObject}'>{\n</span>`}renderEnd(){const e=this.result.length>0?"\n":"";return`<span class='${this.classMap.endObject}'>${e}${this.parent?.indent||""}}</span>`}}class nt extends tt{constructor(e,t,r,n){super(e,t,r,n)}renderStart(){return`<span class='${this.classMap.startArray}'>[\n</span>`}renderEnd(){const e=this.result.length>0?"\n":"";return`<span class='${this.classMap.endArray}'>${e}${this.parent?.indent||""}]</span>`}}class st{classMap;tab;stack=[];block=new rt(this,void 0,"","");constructor(e=et,t=" "){this.classMap=e,this.tab=t}onStartObject(e){const t=new rt(this,this.block,e,this.block.indent+this.tab);this.stack.push(this.block),this.block=t}onEndObject(){const e=this.block;this.block=this.stack.pop(),this.block.pushValue(e.key,e)}onStartIteration(e){const t=new nt(this,this.block,e,this.block.indent+this.tab);this.stack.push(this.block),this.block=t}onEndIteration(){const e=this.block;this.block=this.stack.pop(),this.block.pushValue(e.key,e)}onValue(e,t){this.block.pushValue(e,t)}}function it({data:t,className:r,classMap:n}){const[s,i]=d();return a((()=>{i(function(t,r,n){const s=new st(r);(new B).walk(t,s);const i=s.block.renderValue();return e("div",{className:n,dangerouslySetInnerHTML:{__html:`<div class='${s.classMap.code}' style='overflow-x: scroll'>${i}</div>`}})}(t,n,r))}),[t]),s}function at({value:t}){return e("div",{className:"flex flex-col gap-4",children:Object.entries(t).map((([t,r])=>e(ct,{name:t,value:r},t)))})}function ot({name:t}){return e("div",{className:"text-md font-semibold",children:Ve(t)})}function lt({children:t,className:r}){return e("div",{className:U("flex flex-col gap-4 py-2 pl-4 border-l-4 border-l-solid border-l-slate-100 dark:border-l-slate-600",r),children:t})}function ct({name:r,value:n}){const s=pt(n);switch(s.type){case ut.Inline:return t("div",{className:"w-full flex gap-2",children:[e(ot,{name:r+":"}),e("p",{children:s.value})]});case ut.Paragraph:return t("div",{children:[e(ot,{name:r}),e("p",{children:s.value})]});case ut.Prose:return t("div",{className:"prose dark:prose-invert",children:[e(ot,{name:r}),e("div",{className:"vprose dark:prose-invert",children:s.value})]});case ut.Array:return e(dt,{name:r,value:n});case ut.Object:return t("div",{children:[e(ot,{name:r}),e(lt,{className:"mt-2",children:Object.entries(n).map((([t,r])=>e(ct,{name:t,value:r},t)))})]})}}function dt({name:r,value:n}){const s=n.join(" ").length,i=s/n.length,a="string"==typeof n[0]&&(s<80||s<400&&i<32),o=n.length>9;return t("div",a?{className:"flex gap-2 flex-wrap",children:[r&&e(ot,{name:r+":"}),n.map(((t,r)=>e(y,{children:String(t)},r)))]}:{children:[r&&e(ot,{name:r}),e("div",{className:"flex flex-col gap-2",children:n.map(((t,r)=>e(ht,{index:r,value:t,useBullet:o},r)))})]})}function ht({index:r,value:n,useBullet:s}){const i=s?e("span",{className:"text-xl",children:"•"}):t("span",{children:[r+1,"."]}),a=pt(n);let o;switch(a.type){case ut.Object:o=e(lt,{children:Object.entries(n).map((([t,r])=>e(ct,{name:t,value:r},t)))});break;case ut.Array:o=e(dt,{value:n});break;case ut.Prose:o=e("div",{className:"prose dark:prose-invert",children:a.value});break;default:o=e("div",{children:a.value})}return t("div",{className:"flex gap-4 hover:bg-slate-50 dark:hover:bg-slate-800 py-2 pr-2 pl-4",children:[e("div",{className:"font-semibold text-gray-600 dark:text-gray-400",children:i}),e("div",{children:o})]})}var ut;function pt(e){if(null==e)return{value:"-",type:ut.Inline};if(Array.isArray(e))return{value:e,type:ut.Array};const t=typeof e;if("string"===t){const t=e.length;let r;return t<80?r=ut.Inline:t>400?r=ut.Prose:(r=ut.Paragraph,e=e.replace(/(?:\n\n)+/g,"\n\n")),{type:r,value:e}}return"number"===t||"boolean"===t?{value:String(e),type:ut.Inline}:{value:e,type:ut.Object}}function mt({value:t,viewCode:r=!1}){return t?e("div",{className:"relative w-full",children:r?e(it,{data:t}):e(at,{value:t})}):e("pre",{className:"whitespace-pre-wrap",children:"No Data to display"})}function ft(){return e=>{J(e,"html",((e,t,r)=>{if(e.value&&/<!--[\s\S]*?-->/.test(e.value)&&r&&"number"==typeof t&&r.children)return r.children.splice(t,1),[G,t]}))}}function gt({children:t,components:r,remarkPlugins:n=[],removeComments:s=!0}){const i=[H,...n];return s&&i.push(ft),e(W,{remarkPlugins:i,components:r,children:t})}!function(e){e[e.Inline=0]="Inline",e[e.Paragraph=1]="Paragraph",e[e.Prose=2]="Prose",e[e.Array=3]="Array",e[e.Object=4]="Object"}(ut||(ut={}));const yt=l(void 0);function vt(){return c(yt)}const bt=Symbol("__SLOT_NAME");function xt(e,t){const r=[];return h.forEach(e,(e=>{!function(e,t,r){let n;u(e)&&(n=e.type[bt])?r[n]=e:t.push(e)}(e,r,t)})),r.length>1?r:r[0]}function wt(e,t){t[bt]=e}function Nt(e){return e?"boolean"==typeof e?{enabled:e}:e:{enabled:!1}}function kt(t){const r={};if(xt(t.children,r),!r.content)throw new Error("Popover must provide a content slot");const n=r.trigger?.props,s=r.content.props;return e(Ct,{...t,trigger:n,content:s})}function Ct({middleware:r,offset:n,trigger:s,dismiss:i=!0,content:a,placement:o,strategy:l,zIndex:c=40}){const[h,u]=d(!1),p=Q({open:h,placement:o,strategy:l,onOpenChange:u,middleware:r||[X(n||4),Z(),Y()],whileElementsMounted:ee}),{floatingStyles:m,refs:{setReference:f,setFloating:g},context:y}=p,v=te(y,Nt(i)),b=re(y,Nt(!(x=s)||x.hover||x.click?x?.click:{enabled:!0}));var x;const w=ne(y,Nt(function(e){return!0===e?.hover?{enabled:!0,handleClose:le({blockPointerEvents:!0}),restMs:0}:e?.hover}(s))),{getReferenceProps:N,getFloatingProps:k}=se([v,b,w]),{isMounted:C,styles:S}=ie(y,a.transition);return t(yt.Provider,{value:{...p,close:()=>u(!1)},children:[s&&e("div",{className:U(s.className,"inline-block"),ref:f,...N(),children:s.children}),e(ae,{children:C&&e("div",{ref:g,style:{...m,zIndex:c},...k(),children:e(oe,{context:y,children:e("div",{className:U(a.className,"bg-popover rounded-md text-popover-foreground max-w-md"),style:S,children:a.children})})})})]})}function St(e){return null}function jt(e){return null}function Ot({percent:t}){return e("div",{className:"w-full bg-gray-200 rounded-full h-2.5 dark:bg-gray-700",children:e("div",{className:"bg-blue-600 h-2.5 rounded-full",style:{width:`${t}%`}})})}function At({className:r,properties:n}){return e(v,{className:r,children:e("tbody",{children:n.map((r=>t("tr",{children:[t("td",{className:"w-1/3 font-semibold gap-2",children:[e("span",{children:r.name}),r.description&&e(b,{description:r.description,placement:"top",children:e(q,{className:"size-3 ml-2 text-muted-foreground"})})]}),e("td",{className:"w-2/3",children:r.value??"undefined"})]},r.name)))})})}wt("trigger",St),wt("content",jt),kt.Trigger=St,kt.Content=jt;const Pt=[de,ce()];function $t({schema:r,isOpen:n,onClose:s,readonly:a=!1}){const l=i(void 0),c=x(),d=o((()=>function(e){return e?JSON.stringify(e,null,2):""}(r.schema)),[r]);return t(w,{onClose:s,isOpen:!!n,className:"min-w-[60vw]",children:[e(N,{children:"JSON Schema Editor"}),e(k,{children:a?e(it,{data:r.schema||{}}):e(be,{value:d,extensions:Pt,editorRef:l})}),e(C,{children:a?null:e(g,{onClick:()=>{if(l.current){const e=l.current.getValue();try{const t=function(e){if(e&&(e=e.trim()))return JSON.parse(e)}(e);r.replaceSchema(t),s()}catch(e){c({status:"error",title:"Invalid JSON Schema",description:e.message,duration:5e3})}}},children:"Save changes"})})]})}var Et;function Tt(e,t){let r="any"===t.name?void 0:t.isNullable?[t.name,"null"]:t.name;if(t.isArray)if(e.type="array",e.properties=void 0,!e.items||Array.isArray(e.items))e.items={type:r,properties:t.isObject?{}:void 0};else{const n=e.items;n.type=r,t.isObject&&!n.properties&&(n.properties={})}else e.type=r,e.items=void 0,t.isObject?e.properties||(e.properties={}):e.properties=void 0}function It(e){let t,r=!1,n=!1;const s=e.type;if(Array.isArray(s))for(const e of s)"null"===e?r=!0:t||(t=e);else t=s;t||(t="any"),"array"===t&&(n=!0,t=function(e){if(!e)return"any";let t;t=Array.isArray(e)?qt(e[0].type):qt(e.type);"array"!==t&&"null"!==t||(t="any");return t}(e.items));let i=t;switch(e.editor||e.format){case"textarea":i="text";break;case"media":i="media";break;case"document":i="document"}return{isNullable:r,isArray:n,isObject:"object"===t,name:i}}function qt(e){return e?Array.isArray(e)?e.find((e=>"null"!==e))||"any":e:"any"}!function(e){e.string="string",e.number="number",e.integer="integer",e.boolean="boolean",e.object="object",e.any="any",e.text="text",e.media="media",e.document="document"}(Et||(Et={}));let Mt=0;class Lt{source;onChange=()=>{};schema;root;constructor(e,t){this.schema=e?"string"==typeof e?JSON.parse(e):e:{title:t,type:"object",properties:{}},this.schema.properties||(this.schema.properties={}),this.root=new Dt("",this.schema,this),this.root.loadChildren()}get isEmpty(){return!this.root.children||0===this.root.children.length}get children(){return this.root.children}reload(){return this.root=new Dt("",this.schema,this),this.root.loadChildren(),this.onChange?.(this),this}withSource(e,t){return this.source={uri:t,name:e},this}withChangeListener(e){return this.onChange=e,this}replaceSchema(e){this.schema=e||{title:this.schema.title,type:"object",properties:{}},this.reload()}clone(){const e=new Lt(this.schema);return e.source=this.source,this.onChange&&e.withChangeListener(this.onChange),e}}class Dt{schema;loader;parent;name;isRequired=!1;type;children;constructor(e,t,r,n){if(this.schema=t,this.loader=r,this.parent=n,this.name=e,this.type=It(t),this.parent){let t=this.parent._getPropertiesSchema().required;this.isRequired=!(!t||!Array.isArray(t))&&t.includes(e)}}get title(){return this.schema.title}set title(e){this.schema.title=e}get description(){return this.schema.description}set description(e){this.schema.description=e}get isParent(){return this.type.isObject}get isNew(){return!!this.schema.isNew}set isNew(e){e?this.schema.isNew=!0:delete this.schema.isNew}resetIsNew(){const e=this.isNew;return this.isNew=!1,e}getNameSignature(){return`${this.name}${this.isRequired?"":"?"}`}getTypeSignature(){return`${this.type.name}${this.type.isArray?"[]":""}${this.type.isNullable?"?":""}`}getSignature(){return`${this.getNameSignature()}: ${this.getTypeSignature()}`}reloadTree(){this.loader.reload()}loadChildren(){this.children=[],this.schema.items&&this.schema.items.properties?this._loadChildren(this.schema.items.properties):this.schema.properties&&this._loadChildren(this.schema.properties)}_loadChildren(e){for(const t of Object.keys(e)){const r=e[t],n=new Dt(t,r,this.loader,this);this.children.push(n),n.isParent&&n.loadChildren()}}_getPropertiesSchema(){return this.type.isArray&&this.type.isObject?this.schema.items:this.schema}findAvailableChildName(e){const t=this._getPropertiesSchema().properties||{};let r;do{r=e+ ++Mt}while(t[r]);return r}addChild(e,t,r=!1){if(!this.type.isObject)throw new Error("Cannot add child to a non object node");this.children||(this.children=[]);const n=function(e,t,r,n=!1){if("object"!==e.type)throw new Error("Cannot add property to a non-object schema");e.properties||(e.properties={});const s={};return Tt(s,r),e.properties[t]=s,n&&(Array.isArray(e.required)?function(e,t){e.includes(t)||e.push(t)}(e.required,t):e.required=[t]),s}(this._getPropertiesSchema(),e,t,r),s=new Dt(e,n,this.loader,this);return this.children.push(s),s}remove(){if(this.parent&&this.parent.type.isObject){return function(e,t){e.properties&&(delete e.properties[t],Array.isArray(e.required)&&(e.required=e.required.filter((e=>e!==t))))}(this.parent._getPropertiesSchema(),this.name),this.parent.children&&(this.parent.children=this.parent.children.filter((e=>e.name!==this.name))),!0}return!1}update(e){let t=!1;null!=e.name&&this.name!==e.name&&(this.parent&&function(e,t,r){if(e.properties){const n=e.properties,s={};for(const e of Object.keys(n)){const i=n[e];e===t?s[r]=i:s[e]=i}e.properties=s}e.required&&(e.required=e.required.map((e=>e===t?r:e)))}(this.parent._getPropertiesSchema(),this.name,e.name),this.name=e.name,t=!0),null!=e.isRequired&&this.isRequired!==e.isRequired&&(this.parent&&function(e,t,r){if(Array.isArray(e.required)){const n=e.required.indexOf(t);r?n<0&&e.required.push(t):n>-1&&e.required.splice(n,1)}else r&&(e.required=[t])}(this.parent._getPropertiesSchema(),this.name,e.isRequired),this.isRequired=e.isRequired,t=!0);let r=e.type?.name;"any"===r&&(r=void 0);const n=r!==this.schema.type;return e.type&&(Tt(this.schema,e.type),this.type=e.type,this.type.isObject?this.children||(this.children=[]):this.children=void 0,t=!0),this.schema.editor&&null===e.editor?(this.schema.editor=void 0,this.schema.format=void 0,t=!0):e.editor?(this.schema.editor=e.editor,this.schema.format=e.editor,t=!0):n&&(this.schema.editor=void 0,this.schema.format=void 0,t=!0),e.description!==this.description&&(this.description=e.description,t=!0),t}getUpdateFromNameAndTypeSignature(e,t){let r=e.trim(),n=!0;r.endsWith("?")&&(r=r.substring(0,r.length-1).trim(),n=!1);const s=function(e){let t=!1,r=!1;(e=e.trim()).endsWith("?")&&(r=!0,e=e.substring(0,e.length-1).trim()),e.endsWith("[]")&&(t=!0,e=e.substring(0,e.length-2).trim());const n=Et[e];if(!n)throw new Error(`Unknown type "${e}"`);return{name:n,isArray:t,isNullable:r,isObject:n===Et.object}}(t);let i;return"text"===s.name?(s.name=Et.string,i="textarea"):"media"===s.name?(s.name=Et.any,i="media"):"document"===s.name?(s.name=Et.any,i="document"):i=null,{name:r,type:s,isRequired:n,editor:i}}updateFromNameAndTypeSignature(e,t){return this.update(this.getUpdateFromNameAndTypeSignature(e,t))}updateFromSignature(e){const t=(e=e.trim()).indexOf(":");if(t<0)throw new Error("Expecting a name and a type separated by a colon");const r=e.substring(0,t),n=e.substring(t+1);return this.updateFromNameAndTypeSignature(r,n)}}function Ft(e){return{name:e.getNameSignature(),type:e.getTypeSignature(),description:e.description}}const zt=function(){const e=Object.values(Et),t=[...e];for(const r of e)t.push(r+"[]");return e.sort(),t}();function Rt({value:r,onChange:n,onCancel:s,onSave:i}){const[a,o]=d(!1);if(!r)return null;return t("div",{className:"flex items-center",children:[e("div",{className:"flex-1",children:e(Vt,{value:r.name,onChange:e=>{n({...r,name:e})},onCancel:s,onSave:i})}),e("div",{className:"px-1 font-semibold",children:":"}),e("div",{className:"flex-1",children:e(_t,{value:r.type,onChange:e=>{n({...r,type:e})},onCancel:s,onSave:i})}),t("div",{children:[e(g,{variant:"ghost",size:"xs",onClick:()=>o(!0),title:"Edit description",children:e(M,{className:"size-4"})}),e(Ut,{value:r.description,isOpen:a,onClose:e=>{void 0!==e&&"string"==typeof e&&n({...r,description:e},!0),o(!1)}})]})]})}function Vt({value:t,onChange:r,onCancel:n,onSave:s}){const o=i(null);a((()=>{o.current?.focus()}),[]);return e("input",{onKeyUp:e=>{switch(e.key){case"Enter":s?.();break;case"Escape":n?.()}},ref:o,value:t,onChange:e=>{r(e.target.value)},className:f.INPUT_UNSTYLED,style:{fontSize:"inherit",width:"",display:"inline"}})}function _t({value:t,onChange:r,onCancel:n,onSave:s}){return e(S,{className:f.INPUT_UNSTYLED,options:zt,value:t||"",onBlur:()=>{s?.()},onChange:r,onKeyDown:(e,t)=>{t||("Enter"===e.key?s?.():"Escape"===e.key&&n?.())},popupClass:"schema-type-suggest-popup z-90"})}function Ut({value:r,isOpen:n,onClose:s}){return t(w,{isOpen:n,onClose:s,children:[e(N,{children:"Edit description"}),e(Kt,{value:r,onSave:s})]})}function Kt({value:n,onSave:s}){const o=i(null),[l,c]=d(n||"");return a((()=>{o.current&&o.current.focus()}),[o.current]),t(r,{children:[e(j,{className:"h-max",children:e("textarea",{ref:o,className:"dark:bg-gray-800 w-full h-full dark:text-white",value:l,onChange:e=>c(e.target.value)})}),e(O,{children:e(g,{onClick:()=>s(l),children:"Save Changes"})})]})}function Bt({value:r}){return r?t("div",{className:"w-full flex items-baseline",children:[e("div",{children:r.name||""}),e("div",{className:"ml-2 text-sm text-muted",children:r.type||""})]}):null}function Wt(e){const[t,r]=d(new Lt(e||{type:"object",properties:{}}).withChangeListener((e=>{r(e.clone())})));return t}const Ht="block text-sm sm:leading-6 rounded-md border-0 py-1.5 px-4",Jt=`${Ht} hover:shadow-xs hover:ring-1 hover:ring-inset hover:ring-ring`,Gt=`${Ht} shadow-xs ring-1 ring-inset ring-ring`;function Xt({value:r,onChange:n,onDelete:s,outlineOnHover:i=!1,editOnClick:a=!0,placeholder:o,viewer:l,editor:c,skipClickOutside:h,isEditing:u=!1,readonly:p=!1,onValidate:m}){const{on:f,off:g,isOn:y}=A(u),[v,b]=d();return t("div",{className:"",children:[y&&!p?e(Yt,{value:r,onSave:e=>{if(m){const t=m(e);if(t)return void b(t);b(void 0)}n(e)&&g()},onCancel:g,editor:c,skipClickOutside:e=>!!h&&h(e)}):e(Zt,{value:r,onEdit:f,viewer:l,placeholder:o,outlineOnHover:i,editOnClick:a,onDelete:s,readonly:p}),v&&e("div",{className:"text-red-500 text-sm",children:v})]})}function Zt({viewer:r,value:n,onEdit:s,editOnClick:i,outlineOnHover:a,placeholder:o,onDelete:l,readonly:c}){const d="invisible group-hover:visible";return t("div",{tabIndex:0,onKeyUp:e=>{"Enter"===e.key&&s()},onClick:()=>{i&&s()},className:U("flex justify-start items-center group",a?Jt:Ht,{"cursor-pointer":i}),children:[e(r,{value:n,placeholder:o}),t("div",{className:"ml-auto flex space-x-2",children:[!c&&l&&e(g,{variant:"ghost",size:"sm",className:d,onClick:l,children:e(I,{className:"size-4"})}),c?null:e(g,{variant:"ghost",size:"sm",className:d,onClick:s,children:e(L,{className:"size-4"})})]})]})}function Yt({editor:t,value:r,onSave:n,onCancel:s,skipClickOutside:a}){const[o,l]=d(r),c=i(r),[h,u]=d(null),p=()=>{n(c.current)},m=P(p,a);return e("div",{ref:m,children:e("div",{className:Gt,children:e("div",{className:"w-full",onClick:e=>e.stopPropagation(),children:e(t,{value:o,onChange:(e,t=!1)=>{l(e),c.current=e,t&&(h&&clearTimeout(h),u(setTimeout((()=>{n(e)}),500)))},onSave:p,onCancel:s})})})})}function Qt(e){const t=e.target;return!(!t.closest||!t.closest(".schema-type-suggest-popup"))}function er({schema:r,readonly:n=!1}){return t("ul",{className:"",children:[r.children.map((e=>tr(e,n))),n?null:e(ar,{parent:r.root})]})}function tr(t,r){return t.isParent?e(nr,{property:t,readonly:r},t.name):e(rr,{node:t,readonly:r},t.name)}function rr({node:t,readonly:r}){return e("li",{children:e(ir,{property:t,readonly:r})})}function nr({property:r,readonly:n}){const[s,i]=d(!0);return t("li",{children:[t("div",{className:"flex items-center w-full",children:[e("button",{onClick:()=>i(!s),children:e(s?D:F,{className:"size-4"})}),e("div",{className:"flex-1",children:e(ir,{property:r,readonly:n})})]}),s&&t("ul",{className:"ml-4 border-l border-gray-400 border-dashed",children:[(r.children||[]).map((e=>tr(e,n))),n?null:e(ar,{parent:r})]})]})}function sr(e){return e?/^[a-zA-Z0-9_]+[?]?$/.test(e)?void 0:"Only letters, numbers, underscores or question mark are allowed (a-zA-Z0-9_?)":"Name is required"}function ir({property:t,readonly:r}){const n=x(),s=t.resetIsNew(),i=Ft(t);return e(Xt,{value:i,onChange:e=>{try{e.description&&"string"!=typeof e.description&&(e.description=void 0);const r=t.getUpdateFromNameAndTypeSignature(e.name,e.type);t.update({...r,description:e.description})&&t.reloadTree()}catch(e){return n({status:"error",title:"Invalid property declaration",description:e.message,duration:9e3}),!1}return!0},onDelete:()=>{t.remove(),t.reloadTree()},editor:Rt,viewer:Bt,outlineOnHover:!0,isEditing:s,skipClickOutside:Qt,readonly:r,onValidate:e=>sr(e.name)})}function ar({parent:r}){return t(g,{variant:"ghost",onClick:()=>{const e=r.findAvailableChildName("new_property_");r.addChild(e,{isObject:!1,isArray:!1,isNullable:!1,name:Et.string},!0).isNew=!0,r.reloadTree()},children:[e(T,{className:"size-4"}),"Add property"]})}function or({content:t,...r}){const n=i(null);return a((()=>{if(!n.current)return;const e=(new DOMParser).parseFromString(t,"image/svg+xml").querySelector("svg");if(!e)return console.warn("SvgIcon: No <svg> element found in provided string"),void(n.current.innerHTML="");r&&Object.entries(r).forEach((([t,r])=>{if(null==r)return;const n="className"===t?"class":t;e.setAttribute(n,String(r))})),n.current.innerHTML="",n.current.appendChild(e)}),[t,r]),e("span",{ref:n})}function lr(t){return r=>e(or,{content:t,...r})}function cr({onDrop:r,message:n,buttonLabel:s="Upload Files",allowFolders:a=!0,className:o=""}){const[l,c]=d(!1),h=i(null),u=i(null);return t("div",{className:`flex flex-col items-center justify-center py-12 border-2 rounded-lg transition-colors ${l?"border-color-primary bg-color-primary/10":"border-dashed border-color-border"} ${o}`,onDragOver:e=>{e.preventDefault(),e.dataTransfer.types.includes("Files")&&c(!0)},onDragLeave:e=>{e.preventDefault(),u.current&&!u.current.contains(e.relatedTarget)&&c(!1)},onDrop:async e=>{if(e.preventDefault(),c(!1),e.dataTransfer.items&&e.dataTransfer.items.length>0){const t=Array.from(e.dataTransfer.items),n=[],s=new Set,i=async e=>{if(e.isFile){const t=await new Promise((t=>{e.file((r=>{Object.defineProperty(r,"webkitRelativePath",{writable:!0,value:e.fullPath.substring(1)}),t(r)}))}));!t.name.startsWith(".")&&t.size>0&&n.push(t);const r=e.fullPath.substring(1).split("/").slice(0,-1).join("/");r&&s.add(r)}else if(e.isDirectory){const t=e.createReader(),r=await new Promise((e=>{t.readEntries((t=>{e(t)}))}));await Promise.all(r.map(i));const n=e.fullPath.substring(1);n&&s.add(n)}};try{if(await Promise.all(t.map((e=>{const t=e.webkitGetAsEntry?e.webkitGetAsEntry():e;return t?i(t):Promise.resolve()}))),n.length>0){const e=new Set(Array.from(s).map((e=>e.split("/")[0])).filter(Boolean)).size,t=n.length;let i="";i=e>0?1===e?`Preparing to upload 1 folder with ${t} files...`:`Preparing to upload ${e} folders with ${t} files...`:`Preparing to upload ${t} file${1===t?"":"s"}...`,r(n,{count:n.length,message:i})}}catch(t){console.error("Error processing dropped files:",t);const n=Array.from(e.dataTransfer.files);n.length>0&&r(n)}}else if(e.dataTransfer.files&&e.dataTransfer.files.length>0){const t=Array.from(e.dataTransfer.files);r(t)}},children:[e(z,{className:"h-12 w-12 mb-3 transition-colors "+(l?"text-primary":"text-muted/50")}),e("p",{className:"text-color-muted-foreground",children:n}),t("div",{className:"mt-4 text-center",children:[t("div",{className:"text-sm text-muted mb-2",children:["Drag and drop files",a?" or folders":""," here, or"]}),t(g,{onClick:()=>{h.current&&h.current.click()},children:[e(z,{className:"h-4 w-4 mr-2"}),s]}),e("input",{type:"file",ref:h,onChange:e=>{if(e.target.files&&e.target.files.length>0){const t=Array.from(e.target.files);if(t.some((e=>e.webkitRelativePath&&e.webkitRelativePath.includes("/")))){const e=new Set(t.map((e=>e.webkitRelativePath?.split("/")[0])).filter(Boolean)).size,n=t.length,s=1===e?`Preparing to upload 1 folder with ${n} files...`:`Preparing to upload ${e} folders with ${n} files...`,i={count:t.length,message:s};r(t,i)}else{const e={count:t.length,message:`Preparing to upload ${t.length} file${1===t.length?"":"s"}...`};r(t,e)}}},multiple:!0,webkitdirectory:a?"":void 0,directory:a?"":void 0,className:"hidden"})]})]})}function dr({title:r,count:n,icon:s=e(R,{className:"h-4 w-4 text-green-500"}),items:i}){const[a,o]=d(!1);return t("div",{className:"border border-color-border rounded-md overflow-hidden",children:[t("div",{className:"flex items-center justify-between p-3 bg-color-muted/10 cursor-pointer",onClick:()=>o(!a),children:[t("div",{className:"flex items-center",children:[e("span",{className:"mr-2",children:s}),e("span",{className:"font-medium",children:r}),e("span",{className:"ml-2 px-2 py-0.5 bg-color-muted/20 rounded-full text-xs",children:n})]}),e("button",{className:"text-muted",children:e("svg",{className:"h-5 w-5 transition-transform "+(a?"transform rotate-180":""),fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})})]}),a&&e("div",{className:"p-3 border-t border-color-border max-h-48 overflow-y-auto",children:i.length>0?e("ul",{className:"space-y-1",children:i.map(((t,r)=>e("li",{className:"text-sm py-1 px-2 rounded hover:bg-color-muted/10",children:t},r)))}):e("div",{className:"text-sm text-muted py-2",children:"No items to display"})})]})}function hr({files:r,className:n="",location:s,collection:i}){const a=r.filter((e=>"success"===e.status)),o=r.filter((e=>"updated"===e.status)),l=r.filter((e=>"skipped"===e.status)),c=r.filter((e=>"failed"===e.status)),d=a.length,h=o.length,u=l.length,p=c.length,m=r.length;return t("div",{className:`flex flex-col py-2 ${n}`,children:[t("div",{className:"flex items-center mb-4",children:[e("div",{className:"size-8 mr-4 rounded-full bg-success/10 flex items-center justify-center",children:e(R,{className:"size-4 text-success"})}),e("div",{children:t("p",{className:"text-muted",children:[m," file",1!==m?"s":""," processed",i?` in collection '${i}'`:"",s?` in folder '${s}'`:""]})})]}),t("div",{className:"space-y-3 mt-2",children:[d>0&&e(dr,{title:"Successfully Uploaded",count:d,icon:e(R,{className:"h-4 w-4 text-green-500"}),items:a.map((e=>e.name))}),h>0&&e(dr,{title:"Successfully Updated",count:h,icon:e(R,{className:"h-4 w-4 text-blue-500"}),items:o.map((e=>e.name))}),u>0&&e(dr,{title:"Skipped (Already Existed)",count:u,icon:e(V,{className:"h-4 w-4 text-amber-500"}),items:l.map((e=>e.name))}),p>0&&e(dr,{title:"Failed to Upload",count:p,icon:e(_,{className:"h-4 w-4 text-red-500"}),items:c.map((e=>e.name))})]})]})}const ur="#text",pr="#comment",mr="#cdata",fr="DECLARATION_TAG",gr={tagColor:"#d43900",textColor:"#333",attributeKeyColor:"#2a7ab0",attributeValueColor:"#008000",separatorColor:"#333",commentColor:"#aaa",cdataColor:"#1d781d",fontFamily:"monospace"},yr=l({theme:gr,collapsible:!1,indentSize:2}),vr=()=>c(yr),br=new me({preserveOrder:!0,ignoreAttributes:!1,attributeNamePrefix:"",allowBooleanAttributes:!0,commentPropName:pr,cdataPropName:mr,parseTagValue:!1});function xr(r){const{indentation:n,children:s,isInline:i}=r,{theme:a}=vr();return t("div",{style:{color:a.cdataColor},children:[e("span",{children:`${n}<![CDATA[`}),s,e("span",{children:`${i?"":n}]]>`})]})}function wr(t){const{collapsible:r,theme:n}=vr(),{collapsed:s}=t;return r?e("span",{style:{position:"relative"},children:e("span",{style:{position:"absolute",right:"0",border:0,padding:0,background:"none"},children:e(Nr,{fill:n.separatorColor,style:{transform:`rotate(${s?0:90}deg)`,transition:"transform 0.2s"}})})}):null}function Nr({...t}){return e("svg",{width:"16px",height:"16px",viewBox:"0 0 24 24",...t,children:e("path",{d:"M9 17.898C9 18.972 10.2649 19.546 11.0731 18.8388L17.3838 13.3169C18.1806 12.6197 18.1806 11.3801 17.3838 10.6829L11.0731 5.16108C10.2649 4.45388 9 5.02785 9 6.1018V17.898Z"})})}function kr(e){const{collapsible:t,initialCollapsedDepth:r}=vr(),[n,s]=d((()=>!(he(r)||!t)&&e>=r));return a((()=>{s(!(he(r)||!t)&&e>=r)}),[r,e,t]),{collapsed:n,buttonProps:t?{onClick:()=>s((e=>!e)),role:"button",style:{cursor:"pointer"}}:{}}}function Cr(r){const{indentation:n,children:s,isInline:i,level:a}=r,{theme:o}=vr(),{collapsed:l,buttonProps:c}=kr(a);return t("div",{style:{color:o.commentColor},children:[t("span",{...c,children:[e("span",{children:n}),e(wr,{collapsed:l}),e("span",{children:"\x3c!-- "})]}),!l&&s,l&&"...",e("span",{children:`${i||l?" ":n}--\x3e`})]})}function Sr(r){const{attributes:n}=r,{theme:s}=vr();return n?e("span",{children:Object.entries(n).map((([r,n])=>t("span",{children:[e("span",{style:{color:s.attributeKeyColor},children:` ${r}`}),e("span",{style:{color:s.separatorColor},children:"="}),e("span",{style:{color:s.attributeValueColor},children:`"${n}"`})]},`attribute-${r}`)))}):null}function jr(r){const{indentation:n,tagKey:s,attributes:i}=r,{theme:a}=vr();return t("div",{children:[e("span",{style:{color:a.separatorColor},children:`${n}<?`}),e("span",{style:{color:a.tagColor},children:`${s.slice(1)}`}),e(Sr,{attributes:i}),e("span",{style:{color:a.separatorColor},children:"?>"})]})}function Or(e){return"string"==typeof e&&e.includes("\n")}function Ar(e){const t=e[":@"],r=ue(e,":@"),[[n,s]]=Object.entries(r),i=function(e){switch(e){case ur:case mr:case pr:return e;default:return e.startsWith("?")?fr:"TAG"}}(n);return{attributes:t,tagKey:n,subElements:s,type:i}}function Pr(e){return!!e&&Object.keys(e).length>0}function $r(n){const{indentation:s,tagKey:i,attributes:a,children:o,isInline:l,hasChildren:c,level:d}=n,{collapsed:h,buttonProps:u}=kr(d),{theme:p}=vr();return t("div",{children:[t("span",{...u,children:[e("span",{children:s}),e(wr,{collapsed:h}),e("span",{style:{color:p.separatorColor},children:"<"}),e("span",{style:{color:p.tagColor},children:`${i}`}),!h&&e(Sr,{attributes:a}),h&&Pr(a)&&" ...",e("span",{style:{color:p.separatorColor},children:c?">":" />"})]}),c&&t(r,{children:[!h&&o,h&&"...",e("span",{style:{color:p.separatorColor},children:`${l||h?"":s}</`}),e("span",{style:{color:p.tagColor},children:`${i}`}),e("span",{style:{color:p.separatorColor},children:">"})]})]})}function Er(t){const{hasSiblings:r,text:n,indentation:s,isText:i}=t,{theme:a}=vr(),o=i?{color:a.textColor}:void 0;return Or(n)||r?e("div",{style:o,children:n.split("\n").filter((e=>!!e.trim())).map(((t,r)=>e("div",{children:`${s}${t.trim()}`},`${r}`)))}):e("span",{style:o,children:n})}function Tr(t){const{elements:n,level:s=0,isText:i=!0}=t,{indentSize:a}=vr();return Array.isArray(n)&&0!==n.length?e(r,{children:n.map(((t,r)=>{const{tagKey:o,attributes:l,subElements:c,type:d}=Ar(t),h=n.length>1,u=function(e,t){return new Array(t*e+1).join(" ")}(a,s),p=`${s}-${r}`,m=function(e){return"string"!=typeof e&&1===e.length&&ur in e[0]&&!Or(e[0][ur])}(c);switch(d){case ur:return e(Er,{text:c,indentation:u,hasSiblings:h,isText:i},p);case pr:return e(Cr,{isInline:m,indentation:u,level:s,children:e(Tr,{elements:c,level:s+1,isText:!1})},p);case mr:return e(xr,{indentation:u,isInline:m,children:e(Tr,{elements:c,level:s+1,isText:!1})},p);case fr:return e(jr,{indentation:u,tagKey:o,attributes:l},p);default:return e($r,{indentation:u,tagKey:o,attributes:l,isInline:m,hasChildren:c.length>0,level:s,children:e(Tr,{elements:c,level:s+1})},p)}}))}):null}function Ir(){return e("div",{children:"Invalid XML!"})}function qr(t){const{theme:r,xml:n,collapsible:s=!1,indentSize:i=2,invalidXml:l,initalCollapsedDepth:c,initialCollapsedDepth:h}=t,[u,p]=d((()=>({...gr,...r}))),{json:m,valid:f}=function(e){return o((()=>{try{if(!fe.validate(e))throw new Error("Invalid XML!");const t=br.parse(e);if("string"==typeof e&&e.trim().length>0&&0===t.length)throw new Error("Invalid XML!");return{json:t,valid:!0}}catch(e){return{json:null,valid:!1,errorMessage:`Fail to parse: ${e.message}`}}}),[e])}(n),g=o((()=>({theme:u,collapsible:s,indentSize:i,initialCollapsedDepth:h??c})),[u,s,i,c,h]);return a((()=>{p((e=>{const t={...gr,...r};return pe(t,e)?e:t}))}),[r]),f?e(yr.Provider,{value:g,children:e("div",{className:"rxv-container",style:{whiteSpace:"pre-wrap",fontFamily:u.fontFamily,overflowWrap:"break-word"},children:e(Tr,{elements:m})})}):l||e(Ir,{})}export{Re as ArrayPropertySchema,be as CodeMirrorEditor,cr as DropZone,ye as EditorApi,we as FieldSetContextProvider,$e as Form,Se as FormContextProvider,Ae as FormError,Oe as FormHelper,je as FormLabel,Te as GeneratedForm,Pe as Input,it as JSONCode,mt as JSONDisplay,$t as JSONSchemaEditorModal,at as JSONView,Ge as ManageObjectEntry,Je as ManagedListProperty,Be as ManagedObject,Ke as ManagedObjectBase,We as ManagedObjectProperty,He as ManagedProperty,Xe as ManagedScalarEntry,Lt as ManagedSchema,gt as MarkdownRenderer,Ue as Node,kt as Popover,yt as PopoverContext,Ot as Progress,At as PropertiesView,Rt as PropertyEditor,Vt as PropertyNameEditor,ze as PropertySchema,Bt as PropertyViewer,qe as ScalarField,Fe as Schema,er as SchemaEditor,Dt as SchemaNode,or as SvgIcon,dr as UploadResultCategory,hr as UploadSummary,qr as XMLViewer,Ve as computeTitleFromName,lr as createSvgIcon,Ft as getEditableSchemaProperty,Ne as useFieldSet,Ce as useForm,vt as usePopoverContext,Wt as useSchema,sr as validatePropertyName};
|
|
2
2
|
//# sourceMappingURL=vertesia-ui-widgets.js.map
|