@rucire/jxson-vue
Version:
A powerful JSON editor component for Vue 3 by Rucire
82 lines (81 loc) • 46.5 kB
JavaScript
(function(N,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(N=typeof globalThis<"u"?globalThis:N||self,e(N.Jxson={},N.Vue))})(this,function(N,e){"use strict";/**
* @license lucide-vue-next v0.468.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const ue=s=>s.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();/**
* @license lucide-vue-next v0.468.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/var K={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":2,"stroke-linecap":"round","stroke-linejoin":"round"};/**
* @license lucide-vue-next v0.468.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const ke=({size:s,strokeWidth:b=2,absoluteStrokeWidth:r,color:o,iconNode:m,name:p,class:a,...u},{slots:g})=>e.h("svg",{...K,width:s||K.width,height:s||K.height,stroke:o||K.stroke,"stroke-width":r?Number(b)*24/Number(s):b,class:["lucide",`lucide-${ue(p??"icon")}`],...u},[...m.map(h=>e.h(...h)),...g.default?[g.default()]:[]]);/**
* @license lucide-vue-next v0.468.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const z=(s,b)=>(r,{slots:o})=>e.h(ke,{...r,iconNode:b,name:s},o);/**
* @license lucide-vue-next v0.468.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const q=z("ALargeSmallIcon",[["path",{d:"M21 14h-5",key:"1vh23k"}],["path",{d:"M16 16v-3.5a2.5 2.5 0 0 1 5 0V16",key:"1wh10o"}],["path",{d:"M4.5 13h6",key:"dfilno"}],["path",{d:"m3 16 4.5-9 4.5 9",key:"2dxa0e"}]]);/**
* @license lucide-vue-next v0.468.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const X=z("BinaryIcon",[["rect",{x:"14",y:"14",width:"4",height:"6",rx:"2",key:"p02svl"}],["rect",{x:"6",y:"4",width:"4",height:"6",rx:"2",key:"xm4xkj"}],["path",{d:"M6 20h4",key:"1i6q5t"}],["path",{d:"M14 10h4",key:"ru81e7"}],["path",{d:"M6 14h2v6",key:"16z9wg"}],["path",{d:"M14 4h2v6",key:"1idq9u"}]]);/**
* @license lucide-vue-next v0.468.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const W=z("BracesIcon",[["path",{d:"M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1",key:"ezmyqa"}],["path",{d:"M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1",key:"e1hn23"}]]);/**
* @license lucide-vue-next v0.468.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const Q=z("BracketsIcon",[["path",{d:"M16 3h3v18h-3",key:"1yor1f"}],["path",{d:"M8 21H5V3h3",key:"1qrfwo"}]]);/**
* @license lucide-vue-next v0.468.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const P=z("CheckIcon",[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]);/**
* @license lucide-vue-next v0.468.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const J=z("HashIcon",[["line",{x1:"4",x2:"20",y1:"9",y2:"9",key:"4lhtct"}],["line",{x1:"4",x2:"20",y1:"15",y2:"15",key:"vyu0kd"}],["line",{x1:"10",x2:"8",y1:"3",y2:"21",key:"1ggp8o"}],["line",{x1:"16",x2:"14",y1:"3",y2:"21",key:"weycgp"}]]);/**
* @license lucide-vue-next v0.468.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const we=z("MinusIcon",[["path",{d:"M5 12h14",key:"1ays0h"}]]);/**
* @license lucide-vue-next v0.468.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const v=z("PencilIcon",[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]]);/**
* @license lucide-vue-next v0.468.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const _=z("PlusIcon",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]]);/**
* @license lucide-vue-next v0.468.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const ee=z("Trash2Icon",[["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6",key:"4alrt4"}],["path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2",key:"v07s0e"}],["line",{x1:"10",x2:"10",y1:"11",y2:"17",key:"1uufr5"}],["line",{x1:"14",x2:"14",y1:"11",y2:"17",key:"xtxkd"}]]);/**
* @license lucide-vue-next v0.468.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const le=z("TriangleAlertIcon",[["path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3",key:"wmoenq"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]]);/**
* @license lucide-vue-next v0.468.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const R=z("XIcon",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]),Y=[{label:"Object",value:"object"},{label:"String",value:"string"},{label:"Number",value:"number"},{label:"Array",value:"array"},{label:"Boolean",value:"boolean"}],ae=[{label:"String",value:"string"},{label:"Number",value:"number"},{label:"Object",value:"object"}],H={string:{backgroundClass:"bg-green-500",labelClass:"text-green-700",icon:"ALargeSmall"},number:{backgroundClass:"bg-blue-500",labelClass:"text-blue-700",icon:"Hash"},array:{backgroundClass:"bg-orange-500",labelClass:"text-orange-700",icon:"Brackets"},boolean:{backgroundClass:"bg-purple-500",labelClass:"text-purple-700",icon:"Binary"},object:{backgroundClass:"bg-yellow-500",labelClass:"text-yellow-700",icon:"Folder"}},oe={string:{backgroundClass:"bg-green-100",textClass:"text-green-800"},number:{backgroundClass:"bg-blue-100",textClass:"text-blue-800"},array:{backgroundClass:"bg-orange-100",textClass:"text-orange-800"},boolean:{backgroundClass:"bg-purple-100",textClass:"text-purple-800"},object:{backgroundClass:"bg-yellow-100",textClass:"text-yellow-800"}};function x(s){const b=[];return(!s.name||s.name.trim()==="")&&b.push({field:"name",message:"Field name is required",type:"required"}),s.name&&!/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(s.name)&&b.push({field:"name",message:"Field name must be a valid identifier",type:"invalid_type"}),s.value!==void 0&&s.value!==null&&(he(s.value,s.type)||b.push({field:"value",message:`Value does not match type ${s.type}`,type:"invalid_type"})),{isValid:b.length===0,errors:b}}function ge(s){const b=[],r=new Set;return s.forEach((o,m)=>{const p=x(o);b.push(...p.errors.map(a=>({...a,field:`fields[${m}].${a.field}`}))),r.has(o.name)&&b.push({field:`fields[${m}].name`,message:`Duplicate field name: ${o.name}`,type:"duplicate_name"}),r.add(o.name)}),{isValid:b.length===0,errors:b}}function he(s,b){switch(b){case"string":return typeof s=="string";case"number":return typeof s=="number"&&!isNaN(s);case"boolean":return typeof s=="boolean";case"array":return Array.isArray(s);case"object":return Array.isArray(s);default:return!1}}function O(s){switch(s){case"string":return"";case"number":return 0;case"boolean":return!1;case"array":case"object":return[];default:return""}}function te(s,b){const r=e.ref(!0),o=e.ref(!1),m=e.ref(!1),p=e.ref(!1),a=e.computed(()=>Array.isArray(s.value.value)?s.value.value.length:0);function u(d){var i;return((i=H[d])==null?void 0:i.backgroundClass)||"bg-gray-500"}function g(d){var i;return((i=H[d])==null?void 0:i.labelClass)||"text-gray-700"}function h(d){const i=Y.find(F=>F.value===d);return i?i.label:"String"}const B=(d,i)=>{i.type=d,i.arrayType=d==="array"?"string":i.arrayType,i.value=O(d)},T=(d,i)=>{i.arrayType=d,i.value=O("array")};function n(d,i){if(s.value.value||(s.value.value=[]),Array.isArray(s.value.value)){let F;i===null?F=s.value.value.filter((S,L)=>L!==d):F=s.value.value.map((S,L)=>L===d?i:S);const A={...s.value,value:F};b("update:field",A)}else b("update:field",s.value)}function y(){b("update:field",null)}return{open:r,showAddDropdown:o,adding:m,editing:p,fieldsCount:a,fieldBackgroundClass:u,fieldLabelClass:g,fieldTypeLabel:h,setFieldType:B,setArrayType:T,updateNestedField:n,deleteField:y,getDefaultValue:O}}const Be={class:"group mb-1 flex flex-wrap sm:flex-nowrap items-center rounded bg-white px-2 py-1 gap-1"},Ce={class:"relative mr-2 h-[16px] w-[16px] flex-shrink-0"},Ee={class:"flex flex-col sm:flex-row sm:items-center flex-1 gap-2 sm:gap-0"},Ve=["placeholder","disabled"],Ne=["placeholder","disabled"],Te={class:"flex gap-1 flex-shrink-0"},Ae=["disabled"],$e=["disabled"],De={class:"flex flex-wrap sm:flex-nowrap items-center flex-1 gap-1"},ze={key:0,class:"text-xs italic text-gray-400 flex-shrink-0"},Fe={class:"border border-gray-100 bg-[#f7f8fa] px-2 py-1 text-xs text-gray-600 truncate max-w-[120px] sm:max-w-none"},je={class:"flex items-center gap-1 flex-shrink-0"},Me=["disabled"],Se=["disabled"],Le=e.defineComponent({__name:"ArrayItem",props:{value:{},index:{},arrayType:{},editing:{type:Boolean},fieldLabelClass:{type:Function},fieldTypeLabel:{type:Function},fieldBackgroundClass:{type:Function},showTypeLabel:{type:Boolean},showItemNumber:{type:Boolean},itemNumberFormat:{type:Function},placeholder:{},disabled:{type:Boolean},readOnly:{type:Boolean}},emits:["update:value","delete","edit","save","cancel"],setup(s,{emit:b}){const r=s,o=b,m=e.ref(r.value);e.watch(()=>r.value,a=>{m.value=a});const p=a=>{switch(a){case"string":return q;case"number":return J;default:return null}};return(a,u)=>(e.openBlock(),e.createElementBlock("div",Be,[e.createElementVNode("div",Ce,[!a.readOnly&&!a.disabled?(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass(["absolute inset-0 rounded p-[2px] text-white",a.fieldBackgroundClass(a.arrayType)])},[p(a.arrayType)?(e.openBlock(),e.createBlock(e.resolveDynamicComponent(p(a.arrayType)),{key:0,size:12})):e.createCommentVNode("",!0)],2)):(e.openBlock(),e.createElementBlock("div",{key:1,class:e.normalizeClass(["absolute inset-0 rounded p-[2px] text-white",a.fieldBackgroundClass(a.arrayType)])},[p(a.arrayType)?(e.openBlock(),e.createBlock(e.resolveDynamicComponent(p(a.arrayType)),{key:0,size:12})):e.createCommentVNode("",!0)],2))]),a.editing&&!a.readOnly?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[e.createElementVNode("div",Ee,[a.arrayType==="number"?e.withDirectives((e.openBlock(),e.createElementBlock("input",{key:0,type:"number","onUpdate:modelValue":u[0]||(u[0]=g=>m.value=g),class:e.normalizeClass(["w-full sm:w-32 rounded-md border border-gray-200 bg-[#f7f8fa] sm:mr-2 px-2 py-1 text-xs focus:ring-2 focus:ring-blue-50",{"cursor-not-allowed":a.disabled}]),placeholder:a.placeholder,disabled:a.disabled},null,10,Ve)),[[e.vModelText,m.value,void 0,{number:!0}]]):a.arrayType==="string"?e.withDirectives((e.openBlock(),e.createElementBlock("input",{key:1,type:"text","onUpdate:modelValue":u[1]||(u[1]=g=>m.value=g),class:e.normalizeClass(["w-full sm:w-32 rounded-md border border-gray-200 bg-[#f7f8fa] sm:mr-2 px-2 py-1 text-xs focus:ring-2 focus:ring-blue-50",{"cursor-not-allowed":a.disabled}]),placeholder:a.placeholder,disabled:a.disabled},null,10,Ne)),[[e.vModelText,m.value]]):e.createCommentVNode("",!0),a.showTypeLabel?(e.openBlock(),e.createElementBlock("div",{key:2,class:e.normalizeClass([a.fieldLabelClass(a.arrayType),"sm:mr-2 text-xs"])}," ("+e.toDisplayString(a.fieldTypeLabel(a.arrayType))+") ",3)):e.createCommentVNode("",!0)]),e.createElementVNode("div",Te,[e.createElementVNode("button",{onClick:u[2]||(u[2]=g=>o("save",m.value)),class:e.normalizeClass(["p-1 text-base text-green-500",{"cursor-not-allowed":a.disabled,"hover:text-green-700":!a.disabled}]),disabled:a.disabled},[e.createVNode(e.unref(P),{size:12})],10,Ae),e.createElementVNode("button",{onClick:u[3]||(u[3]=g=>o("cancel")),class:e.normalizeClass(["p-1 text-base text-red-500",{"cursor-not-allowed":a.disabled,"hover:text-red-700":!a.disabled}]),disabled:a.disabled},[e.createVNode(e.unref(R),{size:12})],10,$e)])],64)):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createElementVNode("div",De,[a.showItemNumber?(e.openBlock(),e.createElementBlock("span",ze,e.toDisplayString(a.itemNumberFormat?a.itemNumberFormat(a.index):`Item ${a.index+1}:`),1)):e.createCommentVNode("",!0),e.createElementVNode("span",Fe,e.toDisplayString(a.value),1)]),e.createElementVNode("div",je,[a.readOnly?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("button",{key:0,onClick:u[4]||(u[4]=g=>o("edit")),class:e.normalizeClass(["p-1 text-gray-300",{"cursor-not-allowed":a.disabled,"hover:text-blue-400":!a.disabled}]),disabled:a.disabled},[e.createVNode(e.unref(v),{size:12})],10,Me)),a.readOnly?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("button",{key:1,onClick:u[5]||(u[5]=g=>o("delete")),class:e.normalizeClass(["p-1 text-base text-gray-300",{"cursor-not-allowed":a.disabled,"hover:text-red-400":!a.disabled}]),disabled:a.disabled},[e.createVNode(e.unref(ee),{size:12})],10,Se))])],64))]))}});function ne(s,b){const r=o=>{s.value&&!s.value.contains(o.target)&&b()};e.onMounted(()=>{document.addEventListener("click",r)}),e.onUnmounted(()=>{document.removeEventListener("click",r)})}const Ie=["disabled"],Oe={key:0,class:"absolute z-10 mt-1 w-full sm:w-32 rounded border border-gray-200 bg-white shadow-lg"},Ue=["onClick"],re=e.defineComponent({__name:"ArrayTypeSelector",props:{modelValue:{},fieldLabelClass:{type:Function},disabled:{type:Boolean}},emits:["update:modelValue"],setup(s,{emit:b}){const r=b,o=e.ref(!1),m=e.ref();ne(m,()=>{o.value=!1});const p=()=>{o.value=!o.value},a=u=>{r("update:modelValue",u),o.value=!1};return(u,g)=>(e.openBlock(),e.createElementBlock("div",{class:"relative",ref_key:"dropdownRef",ref:m},[e.createElementVNode("button",{onClick:e.withModifiers(p,["stop"]),class:e.normalizeClass([[u.fieldLabelClass(u.modelValue),{"cursor-not-allowed":u.disabled}],"flex items-center rounded-full px-2 py-1 text-xs font-medium shadow-sm w-full sm:w-auto justify-center sm:justify-start"]),disabled:u.disabled},[e.createTextVNode(e.toDisplayString(u.modelValue==="number"?"Number":u.modelValue==="object"?"Object":"String")+" ",1),g[0]||(g[0]=e.createElementVNode("svg",{class:"ml-1 h-3 w-3 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e.createElementVNode("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M19 9l-7 7-7-7"})],-1))],10,Ie),o.value?(e.openBlock(),e.createElementBlock("div",Oe,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(ae),h=>(e.openBlock(),e.createElementBlock("div",{key:h.value,onClick:B=>a(h.value),class:e.normalizeClass([u.fieldLabelClass(h.value),"m-1 flex cursor-pointer items-center rounded px-2 py-1 hover:bg-gray-100 focus:bg-gray-100 focus:outline-none"])},[e.createElementVNode("span",null,e.toDisplayString(h.label),1)],10,Ue))),128))])):e.createCommentVNode("",!0)],512))}}),Ke={class:"group mb-1 flex flex-wrap sm:flex-nowrap items-center rounded bg-white px-2 py-1 gap-1"},Pe={key:0,class:"relative mr-2 h-[16px] w-[16px] flex-shrink-0"},Re={class:"flex flex-col sm:flex-row sm:items-center flex-1 gap-2 sm:gap-0"},Ye=["disabled"],qe=["onKeydown","disabled","aria-expanded"],Je={key:0,class:"absolute z-10 mt-1 w-full sm:w-32 rounded border border-gray-200 bg-white shadow-lg",role:"listbox","aria-label":"Field type options"},He=["onClick","onKeydown","tabindex","aria-selected"],xe={key:0,class:"w-full sm:w-auto"},Ge=["disabled"],Ze=["disabled"],Xe=["disabled"],We={class:"flex gap-1 ml-auto"},Qe=["disabled"],ve=["disabled"],de=e.defineComponent({__name:"ObjectFieldAdder",props:{adding:{type:Boolean},fieldTypeLabel:{type:Function},disabled:{type:Boolean},field:{},hasDuplicateAttempt:{type:Boolean},duplicateFieldName:{}},emits:["add","cancel","update:field"],setup(s,{emit:b}){const r=s,o=b,m=e.ref(null),p=e.ref(!1),a=()=>{p.value=!p.value},u=n=>{const y={...r.field,type:n};switch(n){case"string":y.value="";break;case"number":y.value=0;break;case"boolean":y.value=!1;break;case"array":y.value=[],y.arrayType="string";break;case"object":y.value=[];break;default:y.value=""}o("update:field",y),p.value=!1},g=()=>{r.field.name&&o("add",r.field)},h=()=>{o("cancel")},B=n=>{m.value&&!m.value.contains(n.target)&&(p.value=!1)},T=n=>`${oe[n].backgroundClass} ${oe[n].textClass}`;return e.onMounted(()=>{document.addEventListener("click",B)}),e.onUnmounted(()=>{document.removeEventListener("click",B)}),(n,y)=>(e.openBlock(),e.createElementBlock("div",Ke,[n.hasDuplicateAttempt?(e.openBlock(),e.createElementBlock("div",Pe,[e.createVNode(e.unref(le),{size:12,class:"flex-shrink-0 text-amber-500"})])):e.createCommentVNode("",!0),e.createElementVNode("div",Re,[e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":y[0]||(y[0]=d=>n.field.name=d),placeholder:"Name",class:e.normalizeClass(["w-full sm:w-32 rounded-md border px-2 py-1 sm:mr-2 text-xs focus:ring-2 focus:ring-blue-50",[n.hasDuplicateAttempt?"border-amber-300 bg-amber-50 focus:border-amber-400 focus:ring-amber-50":"border-gray-200 bg-[#f7f8fa]",{"cursor-not-allowed":n.disabled}]]),disabled:n.disabled,onKeydown:[e.withKeys(g,["enter"]),e.withKeys(h,["escape"])],"aria-label":"Field name"},null,42,Ye),[[e.vModelText,n.field.name]]),e.createElementVNode("div",{class:"relative",ref_key:"addDropdownRef",ref:m},[e.createElementVNode("button",{type:"button",onClick:a,onKeydown:[e.withKeys(e.withModifiers(a,["prevent"]),["enter"]),e.withKeys(e.withModifiers(a,["prevent"]),["space"]),y[1]||(y[1]=e.withKeys(d=>p.value=!1,["escape"]))],class:e.normalizeClass([[T(n.field.type),{"cursor-not-allowed":n.disabled}],"flex items-center rounded-full px-2 py-1 text-xs font-medium sm:mr-2 shadow-sm w-full sm:w-auto justify-center sm:justify-start"]),disabled:n.disabled,"aria-expanded":p.value,"aria-label":"Select field type","aria-haspopup":"listbox"},[e.createTextVNode(e.toDisplayString(n.fieldTypeLabel(n.field.type))+" ",1),y[6]||(y[6]=e.createElementVNode("svg",{class:"ml-1 h-3 w-3 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true"},[e.createElementVNode("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M19 9l-7 7-7-7"})],-1))],42,qe),p.value?(e.openBlock(),e.createElementBlock("div",Je,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(Y),d=>(e.openBlock(),e.createElementBlock("div",{key:d.value,onClick:i=>u(d.value),onKeydown:[e.withKeys(e.withModifiers(i=>u(d.value),["prevent"]),["enter"]),e.withKeys(e.withModifiers(i=>u(d.value),["prevent"]),["space"])],class:e.normalizeClass([T(d.value),"m-1 flex cursor-pointer items-center rounded px-2 py-1 hover:bg-gray-100 focus:bg-gray-100 focus:outline-none"]),tabindex:p.value?0:-1,role:"option","aria-selected":n.field.type===d.value},[e.createElementVNode("span",null,e.toDisplayString(d.label),1)],42,He))),128))])):e.createCommentVNode("",!0)],512),n.field.type==="array"?(e.openBlock(),e.createElementBlock("div",xe,[e.createVNode(re,{modelValue:n.field.arrayType,"onUpdate:modelValue":y[2]||(y[2]=d=>n.field.arrayType=d),"field-label-class":T,disabled:n.disabled},null,8,["modelValue","disabled"])])):e.createCommentVNode("",!0),n.field.type==="number"?e.withDirectives((e.openBlock(),e.createElementBlock("input",{key:1,type:"number","onUpdate:modelValue":y[3]||(y[3]=d=>n.field.value=d),placeholder:"Value",class:e.normalizeClass(["w-full sm:w-32 rounded-md border border-gray-200 bg-[#f7f8fa] px-2 py-1 text-xs focus:ring-2 focus:ring-blue-50",{"cursor-not-allowed":n.disabled}]),disabled:n.disabled,onKeydown:[e.withKeys(g,["enter"]),e.withKeys(h,["escape"])],"aria-label":"Field value"},null,42,Ge)),[[e.vModelText,n.field.value,void 0,{number:!0}]]):n.field.type==="boolean"?e.withDirectives((e.openBlock(),e.createElementBlock("select",{key:2,"onUpdate:modelValue":y[4]||(y[4]=d=>n.field.value=d),class:e.normalizeClass(["w-full sm:w-32 rounded-md border border-gray-200 bg-[#f7f8fa] px-2 py-1 text-xs focus:ring-2 focus:ring-blue-50",{"cursor-not-allowed":n.disabled}]),disabled:n.disabled,onKeydown:[e.withKeys(g,["enter"]),e.withKeys(h,["escape"])],"aria-label":"Boolean value"},y[7]||(y[7]=[e.createElementVNode("option",{value:!0},"true",-1),e.createElementVNode("option",{value:!1},"false",-1)]),42,Ze)),[[e.vModelSelect,n.field.value]]):n.field.type==="string"?e.withDirectives((e.openBlock(),e.createElementBlock("input",{key:3,"onUpdate:modelValue":y[5]||(y[5]=d=>n.field.value=d),placeholder:"Value",class:e.normalizeClass(["w-full sm:w-32 rounded-md border border-gray-200 bg-[#f7f8fa] px-2 py-1 text-xs focus:ring-2 focus:ring-blue-50",{"cursor-not-allowed":n.disabled}]),disabled:n.disabled,onKeydown:[e.withKeys(g,["enter"]),e.withKeys(h,["escape"])],"aria-label":"Field value"},null,42,Xe)),[[e.vModelText,n.field.value]]):e.createCommentVNode("",!0)]),e.createElementVNode("div",We,[e.createElementVNode("button",{onClick:g,class:e.normalizeClass(["p-1 text-base text-green-500",{"cursor-not-allowed":n.disabled,"hover:text-green-700":!n.disabled}]),disabled:n.disabled,"aria-label":"Add field",title:"Add field"},[e.createVNode(e.unref(P),{size:12})],10,Qe),e.createElementVNode("button",{onClick:h,class:e.normalizeClass(["p-1 text-base text-red-500",{"cursor-not-allowed":n.disabled,"hover:text-red-700":!n.disabled}]),disabled:n.disabled,"aria-label":"Cancel",title:"Cancel"},[e.createVNode(e.unref(R),{size:12})],10,ve)])]))}}),_e={key:0,class:"mb-1 flex items-center rounded bg-white px-2 py-1"},el={key:0,class:"relative mr-2"},ll=["disabled"],al=["disabled"],ol=["disabled"],tl=["disabled"],nl=["disabled"],rl=e.defineComponent({__name:"ArrayItemAdder",props:{adding:{type:Boolean},field:{},newField:{},disabled:{type:Boolean},readOnly:{type:Boolean},fieldLabelClass:{type:Function}},emits:["add","cancel","update:array-type"],setup(s,{emit:b}){const r=b;return(o,m)=>o.adding&&o.field.type==="array"?(e.openBlock(),e.createElementBlock("div",_e,[o.field.arrayType===void 0?(e.openBlock(),e.createElementBlock("div",el,[e.createVNode(re,{modelValue:o.field.arrayType,"onUpdate:modelValue":m[0]||(m[0]=p=>o.field.arrayType=p),"field-label-class":o.fieldLabelClass,disabled:o.disabled},null,8,["modelValue","field-label-class","disabled"])])):e.createCommentVNode("",!0),o.field.arrayType==="number"?e.withDirectives((e.openBlock(),e.createElementBlock("input",{key:1,type:"number","onUpdate:modelValue":m[1]||(m[1]=p=>o.newField.value=p),placeholder:"Value",class:e.normalizeClass(["w-32 rounded-md border border-gray-200 bg-[#f7f8fa] px-2 py-1 text-xs focus:ring-2 focus:ring-blue-50",{"cursor-not-allowed":o.disabled}]),disabled:o.disabled},null,10,ll)),[[e.vModelText,o.newField.value,void 0,{number:!0}]]):o.field.arrayType==="string"?e.withDirectives((e.openBlock(),e.createElementBlock("input",{key:2,"onUpdate:modelValue":m[2]||(m[2]=p=>o.newField.value=p),placeholder:"Value",class:e.normalizeClass(["w-32 rounded-md border border-gray-200 bg-[#f7f8fa] px-2 py-1 text-xs focus:ring-2 focus:ring-blue-50",{"cursor-not-allowed":o.disabled}]),disabled:o.disabled},null,10,al)),[[e.vModelText,o.newField.value]]):o.field.arrayType==="object"?e.withDirectives((e.openBlock(),e.createElementBlock("input",{key:3,"onUpdate:modelValue":m[3]||(m[3]=p=>o.newField.name=p),placeholder:"Name",class:e.normalizeClass(["w-32 rounded-md border border-gray-200 bg-[#f7f8fa] px-2 py-1 text-xs focus:ring-2 focus:ring-blue-50",{"cursor-not-allowed":o.disabled}]),disabled:o.disabled},null,10,ol)),[[e.vModelText,o.newField.name]]):e.createCommentVNode("",!0),m[6]||(m[6]=e.createElementVNode("div",{class:"flex-1"},null,-1)),e.createElementVNode("button",{onClick:m[4]||(m[4]=p=>r("add")),class:e.normalizeClass(["p-1 text-base text-green-500",{"cursor-not-allowed":o.disabled,"hover:text-green-700":!o.disabled}]),disabled:o.disabled},[e.createVNode(e.unref(P),{size:12})],10,tl),e.createElementVNode("button",{onClick:m[5]||(m[5]=p=>r("cancel")),class:e.normalizeClass(["ml-1 p-1 text-base text-red-500",{"cursor-not-allowed":o.disabled,"hover:text-red-700":!o.disabled}]),disabled:o.disabled},[e.createVNode(e.unref(R),{size:12})],10,nl)])):e.createCommentVNode("",!0)}}),dl={class:"relative"},sl={class:"group mb-1 flex flex-wrap sm:flex-nowrap items-center rounded bg-white px-2 py-1 gap-1"},il=["disabled"],cl={key:0},pl={key:1},ml={class:"relative mr-2 h-[16px] w-[16px] flex-shrink-0"},fl={class:"flex flex-col sm:flex-row sm:items-center flex-1 gap-2 sm:gap-0"},yl=["placeholder","disabled"],bl=["placeholder","disabled"],ul=["disabled"],kl=["placeholder","disabled"],wl={class:"flex gap-1 ml-auto"},gl=["disabled"],hl=["disabled"],Bl={class:"flex flex-wrap sm:flex-nowrap items-center flex-1 gap-1"},Cl={key:1,class:"text-xs text-gray-400 flex-shrink-0"},El={key:2,class:"text-xs text-gray-400 flex-shrink-0"},Vl={key:3,class:"border border-gray-100 bg-[#f7f8fa] px-2 py-1 text-xs text-gray-600 flex-shrink-0"},Nl={key:4,class:"border border-gray-100 bg-[#f7f8fa] px-2 py-1 text-xs text-gray-600 truncate max-w-[120px] sm:max-w-none"},Tl={class:"flex items-center gap-1 flex-shrink-0"},Al=["disabled"],$l=["disabled"],Dl={class:"z-5 relative ml-6"},zl={key:0},Fl={key:0},jl={key:1},Ml={key:4,class:"relative flex items-center"},Sl=["disabled"],G=e.defineComponent({__name:"ObjectField",props:{field:{},level:{},showTypeLabel:{type:Boolean},showFieldCount:{type:Boolean},showArrayCount:{type:Boolean},placeholder:{},disabled:{type:Boolean},readOnly:{type:Boolean},allowDelete:{type:Boolean},allowEdit:{type:Boolean},allowAdd:{type:Boolean},allowExpand:{type:Boolean},hasDuplicateName:{type:Boolean},customIcons:{}},emits:["update:field"],setup(s,{emit:b}){const r=s,o=b,{open:m,adding:p,editing:a,fieldsCount:u,fieldBackgroundClass:g,fieldLabelClass:h,fieldTypeLabel:B,updateNestedField:T,deleteField:n,getDefaultValue:y}=te(e.toRef(r,"field"),o),d=e.reactive({name:"",type:"string",value:y("string")}),i=e.reactive({name:"",type:"string",value:y("string")}),F=e.ref(-1),A=e.ref(""),S=e.computed(()=>{if(!Array.isArray(r.field.value))return new Set;const l=new Map,w=new Set;return r.field.value.forEach(M=>{if(M&&M.name){const U=l.get(M.name)||0;l.set(M.name,U+1),U>=1&&w.add(M.name)}}),w}),L=l=>Array.isArray(r.field.value)?r.field.value.some(w=>w.name===l):!1;function t(){m.value=!m.value}function f(){p.value=!0,d.name="",d.type=r.field.arrayType||"string",d.value=y(d.type),a.value=!1,A.value=""}function c(){p.value=!1,A.value=""}function k(){if(!d.name)return;if(L(d.name)){A.value=d.name;return}A.value="";const l={...d,id:`field-${Date.now()}-${Math.random().toString(36).substr(2,9)}`};(l.type==="array"||l.type==="object")&&(l.value=[]);const w={...r.field,value:Array.isArray(r.field.value)?[...r.field.value,l]:[l]};o("update:field",w),p.value=!1}function j(){if(!Array.isArray(r.field.value))return;let l;if(r.field.arrayType==="object"){const M={name:d.name||`array-item-${Date.now()}-${r.field.value.length}`,type:"object",value:[],id:`field-${Date.now()}-${Math.random().toString(36).substr(2,9)}`};l=[...r.field.value,M]}else r.field.arrayType==="number"?l=[...r.field.value,d.value]:l=[...r.field.value,d.value];const w={...r.field,value:l};o("update:field",w),p.value=!1}function I(){a.value=!0,i.name=r.field.name,i.type=r.field.type,i.value=r.field.value,i.arrayType=r.field.arrayType,i.id=r.field.id,p.value=!1}function Ul(l){F.value=l}function Kl(){a.value=!1}function Pl(){const l={name:i.name,type:i.type,value:i.value,arrayType:i.arrayType,id:r.field.id};(l.type==="object"||l.type==="array")&&l.type===r.field.type&&Array.isArray(r.field.value)&&(l.value=r.field.value,l.type==="array"&&(l.arrayType=r.field.arrayType)),o("update:field",l),a.value=!1}return e.watch(()=>d.name,l=>{A.value&&l!==A.value&&(A.value="")}),(l,w)=>{var M,U,se,ie,ce,pe,me,fe,ye,be;return e.openBlock(),e.createElementBlock("div",dl,[e.createElementVNode("div",sl,[(l.field.type==="object"||l.field.type==="array")&&l.allowExpand?(e.openBlock(),e.createElementBlock("button",{key:0,onClick:t,class:e.normalizeClass(["mr-2 h-[16px] w-[16px] flex-shrink-0 rounded bg-gray-300 px-[2px] text-white",{"cursor-not-allowed":l.disabled,"hover:text-gray-100":!l.disabled}]),disabled:l.disabled},[e.unref(m)?(e.openBlock(),e.createElementBlock("span",cl,[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(((M=l.customIcons)==null?void 0:M.collapse)||e.unref(we)),{size:12}))])):(e.openBlock(),e.createElementBlock("span",pl,[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(((U=l.customIcons)==null?void 0:U.expand)||e.unref(_)),{size:12}))]))],10,il)):e.createCommentVNode("",!0),e.createElementVNode("div",ml,[!l.readOnly&&!l.disabled?(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass(["absolute inset-0 rounded p-[2px] text-white",e.unref(g)(l.field.type),{"cursor-not-allowed":l.disabled}])},[l.field.type==="string"?(e.openBlock(),e.createBlock(e.unref(q),{key:0,size:12})):e.createCommentVNode("",!0),l.field.type==="number"?(e.openBlock(),e.createBlock(e.unref(J),{key:1,size:12})):e.createCommentVNode("",!0),l.field.type==="boolean"?(e.openBlock(),e.createBlock(e.unref(X),{key:2,size:12})):e.createCommentVNode("",!0),l.field.type==="array"?(e.openBlock(),e.createBlock(e.unref(Q),{key:3,size:12})):e.createCommentVNode("",!0),l.field.type==="object"?(e.openBlock(),e.createBlock(e.unref(W),{key:4,size:12})):e.createCommentVNode("",!0)],2)):(e.openBlock(),e.createElementBlock("div",{key:1,class:e.normalizeClass(["absolute inset-0 rounded p-[2px] text-white",e.unref(g)(l.field.type),{"cursor-not-allowed":l.disabled}])},[l.field.type==="string"?(e.openBlock(),e.createBlock(e.unref(q),{key:0,size:12})):e.createCommentVNode("",!0),l.field.type==="number"?(e.openBlock(),e.createBlock(e.unref(J),{key:1,size:12})):e.createCommentVNode("",!0),l.field.type==="boolean"?(e.openBlock(),e.createBlock(e.unref(X),{key:2,size:12})):e.createCommentVNode("",!0),l.field.type==="array"?(e.openBlock(),e.createBlock(e.unref(Q),{key:3,size:12})):e.createCommentVNode("",!0),l.field.type==="object"?(e.openBlock(),e.createBlock(e.unref(W),{key:4,size:12})):e.createCommentVNode("",!0)],2))]),e.unref(a)&&!l.readOnly?(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createElementVNode("div",fl,[e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":w[0]||(w[0]=E=>i.name=E),class:e.normalizeClass(["w-full sm:w-32 rounded-md border border-gray-200 bg-[#f7f8fa] sm:mr-2 px-2 py-1 text-xs focus:ring-2 focus:ring-blue-50",{"cursor-not-allowed":l.disabled}]),placeholder:(se=l.placeholder)==null?void 0:se.name,disabled:l.disabled},null,10,yl),[[e.vModelText,i.name]]),l.showTypeLabel?(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass([e.unref(h)(i.type),"sm:mr-2 text-xs"])},[i.type==="array"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[e.createTextVNode(" ("+e.toDisplayString(e.unref(B)(i.type))+"["+e.toDisplayString(e.unref(B)(i.arrayType))+"]) ",1)],64)):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createTextVNode(" ("+e.toDisplayString(e.unref(B)(i.type))+") ",1)],64))],2)):e.createCommentVNode("",!0),i.type==="number"?e.withDirectives((e.openBlock(),e.createElementBlock("input",{key:1,type:"number","onUpdate:modelValue":w[1]||(w[1]=E=>i.value=E),class:e.normalizeClass(["w-full sm:w-32 rounded-md border border-gray-200 bg-[#f7f8fa] px-2 py-1 text-xs focus:ring-2 focus:ring-blue-50",{"cursor-not-allowed":l.disabled}]),placeholder:(ie=l.placeholder)==null?void 0:ie.value,disabled:l.disabled},null,10,bl)),[[e.vModelText,i.value,void 0,{number:!0}]]):i.type==="boolean"?e.withDirectives((e.openBlock(),e.createElementBlock("select",{key:2,"onUpdate:modelValue":w[2]||(w[2]=E=>i.value=E),class:e.normalizeClass(["w-full sm:w-32 rounded-md border border-gray-200 bg-[#f7f8fa] px-2 py-1 text-xs focus:ring-2 focus:ring-blue-50",{"cursor-not-allowed":l.disabled}]),disabled:l.disabled},w[7]||(w[7]=[e.createElementVNode("option",{value:!0},"true",-1),e.createElementVNode("option",{value:!1},"false",-1)]),10,ul)),[[e.vModelSelect,i.value]]):i.type==="string"?e.withDirectives((e.openBlock(),e.createElementBlock("input",{key:3,"onUpdate:modelValue":w[3]||(w[3]=E=>i.value=E),class:e.normalizeClass(["w-full sm:w-32 rounded-md border border-gray-200 bg-[#f7f8fa] px-2 py-1 text-xs focus:ring-2 focus:ring-blue-50",{"cursor-not-allowed":l.disabled}]),placeholder:(ce=l.placeholder)==null?void 0:ce.value,disabled:l.disabled},null,10,kl)),[[e.vModelText,i.value]]):e.createCommentVNode("",!0)]),e.createElementVNode("div",wl,[e.createElementVNode("button",{onClick:Pl,class:e.normalizeClass(["p-1 text-base text-green-500",{"cursor-not-allowed":l.disabled,"hover:text-green-700":!l.disabled}]),disabled:l.disabled},[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(((pe=l.customIcons)==null?void 0:pe.save)||e.unref(P)),{size:12}))],10,gl),e.createElementVNode("button",{onClick:Kl,class:e.normalizeClass(["p-1 text-base text-red-500",{"cursor-not-allowed":l.disabled,"hover:text-red-400":!l.disabled}]),disabled:l.disabled},[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(((me=l.customIcons)==null?void 0:me.cancel)||e.unref(R)),{size:12}))],10,hl)])],64)):(e.openBlock(),e.createElementBlock(e.Fragment,{key:2},[e.createElementVNode("div",Bl,[e.createElementVNode("span",{class:e.normalizeClass([e.unref(h)(l.field.type),"py-1 text-xs font-medium"])},e.toDisplayString(l.field.name),3),l.hasDuplicateName?(e.openBlock(),e.createBlock(e.unref(le),{key:0,size:12,class:"text-amber-500 flex-shrink-0",title:"Duplicate field name"})):e.createCommentVNode("",!0),l.field.type==="object"&&l.showFieldCount?(e.openBlock(),e.createElementBlock("span",Cl," { "+e.toDisplayString(e.unref(u))+" } ",1)):e.createCommentVNode("",!0),l.field.type==="array"&&l.showArrayCount?(e.openBlock(),e.createElementBlock("span",El," [ "+e.toDisplayString(e.unref(u))+" ] ",1)):e.createCommentVNode("",!0),l.field.type==="boolean"?(e.openBlock(),e.createElementBlock("span",Vl,e.toDisplayString(l.field.value?"true":"false"),1)):e.createCommentVNode("",!0),l.field.type==="number"||l.field.type==="string"?(e.openBlock(),e.createElementBlock("span",Nl,e.toDisplayString(l.field.value),1)):e.createCommentVNode("",!0)]),e.createElementVNode("div",Tl,[l.allowEdit!==!1&&!l.readOnly?(e.openBlock(),e.createElementBlock("button",{key:0,onClick:I,class:e.normalizeClass(["p-1 text-gray-300",{"cursor-not-allowed":l.disabled,"hover:text-blue-400":!l.disabled}]),disabled:l.disabled},[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(((fe=l.customIcons)==null?void 0:fe.edit)||e.unref(v)),{size:12}))],10,Al)):e.createCommentVNode("",!0),l.allowDelete!==!1&&!l.readOnly?(e.openBlock(),e.createElementBlock("button",{key:1,onClick:w[4]||(w[4]=(...E)=>e.unref(n)&&e.unref(n)(...E)),class:e.normalizeClass(["p-1 text-base text-gray-300",{"cursor-not-allowed":l.disabled,"hover:text-red-400":!l.disabled}]),disabled:l.disabled},[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(((ye=l.customIcons)==null?void 0:ye.delete)||e.unref(ee)),{size:12}))],10,$l)):e.createCommentVNode("",!0)])],64))]),l.field.type==="object"||l.field.type==="array"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[e.unref(m)?(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass(["absolute bottom-3 left-3.5 z-0 w-0.5 bg-gray-200",e.unref(a)?"top-16 sm:top-8":"top-8"])},null,2)):e.createCommentVNode("",!0),e.withDirectives(e.createElementVNode("div",Dl,[l.field.type==="object"?(e.openBlock(),e.createElementBlock("div",zl,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(l.field.value,(E,V)=>(e.openBlock(),e.createBlock(G,{key:E.id||`obj-${l.level}-${V}`,field:E,level:l.level+1,"show-type-label":l.showTypeLabel,"show-field-count":l.showFieldCount,"show-array-count":l.showArrayCount,placeholder:l.placeholder,disabled:l.disabled,"read-only":l.readOnly,"allow-delete":l.allowDelete,"allow-edit":l.allowEdit,"allow-add":l.allowAdd,"allow-expand":l.allowExpand,"custom-icons":l.customIcons,"has-duplicate-name":S.value.has(E.name),"onUpdate:field":C=>e.unref(T)(V,C)},null,8,["field","level","show-type-label","show-field-count","show-array-count","placeholder","disabled","read-only","allow-delete","allow-edit","allow-add","allow-expand","custom-icons","has-duplicate-name","onUpdate:field"]))),128))])):l.field.type==="array"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[l.field.arrayType==="object"?(e.openBlock(),e.createElementBlock("div",Fl,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(l.field.value,(E,V)=>(e.openBlock(),e.createBlock(G,{key:E.id||`arr-${l.level}-${V}`,field:E,level:l.level+1,"show-type-label":l.showTypeLabel,"show-field-count":l.showFieldCount,"show-array-count":l.showArrayCount,placeholder:l.placeholder,disabled:l.disabled,"read-only":l.readOnly,"allow-delete":l.allowDelete,"allow-edit":l.allowEdit,"allow-add":l.allowAdd,"allow-expand":l.allowExpand,"custom-icons":l.customIcons,"has-duplicate-name":S.value.has(E.name),"onUpdate:field":C=>e.unref(T)(V,C)},null,8,["field","level","show-type-label","show-field-count","show-array-count","placeholder","disabled","read-only","allow-delete","allow-edit","allow-add","allow-expand","custom-icons","has-duplicate-name","onUpdate:field"]))),128))])):(e.openBlock(),e.createElementBlock("div",jl,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(l.field.value,(E,V)=>(e.openBlock(),e.createBlock(Le,{key:V,value:E,index:V,disabled:l.disabled,"read-only":l.readOnly,"allow-delete":l.allowDelete,"allow-edit":l.allowEdit,"allow-add":l.allowAdd,"allow-expand":l.allowExpand,"custom-icons":l.customIcons,"array-type":l.field.arrayType,editing:F.value===V,"field-type-label":e.unref(B),"field-label-class":e.unref(h),"field-background-class":e.unref(g),"onUpdate:value":C=>{if(typeof C=="string"||typeof C=="number"){let $;if(l.field.arrayType==="string"&&typeof C=="string"){const D=[...l.field.value];D[V]=C,$={...l.field,value:D}}else if(l.field.arrayType==="number"&&typeof C=="number"){const D=[...l.field.value];D[V]=C,$={...l.field,value:D}}else $=l.field;o("update:field",$)}},onDelete:()=>{let C;if(l.field.arrayType==="string"){const $=l.field.value.filter((D,Z)=>Z!==V);C={...l.field,value:$}}else if(l.field.arrayType==="number"){const $=l.field.value.filter((D,Z)=>Z!==V);C={...l.field,value:$}}else C=l.field;o("update:field",C)},onEdit:()=>Ul(V),onSave:C=>{if(typeof C=="string"||typeof C=="number"){let $;if(l.field.arrayType==="string"&&typeof C=="string"){const D=[...l.field.value];D[V]=C,$={...l.field,value:D}}else if(l.field.arrayType==="number"&&typeof C=="number"){const D=[...l.field.value];D[V]=C,$={...l.field,value:D}}else $=l.field;F.value=-1,o("update:field",$)}},onCancel:w[5]||(w[5]=C=>F.value=-1)},null,8,["value","index","disabled","read-only","allow-delete","allow-edit","allow-add","allow-expand","custom-icons","array-type","editing","field-type-label","field-label-class","field-background-class","onUpdate:value","onDelete","onEdit","onSave"]))),128))]))],64)):e.createCommentVNode("",!0),e.unref(p)&&l.field.type==="object"?(e.openBlock(),e.createBlock(de,{key:2,adding:e.unref(p),field:d,"field-label-class":e.unref(h),"field-type-label":e.unref(B),disabled:l.disabled,"has-duplicate-attempt":!!A.value,"duplicate-field-name":A.value,onAdd:k,onCancel:c,"onUpdate:field":w[6]||(w[6]=E=>Object.assign(d,E))},null,8,["adding","field","field-label-class","field-type-label","disabled","has-duplicate-attempt","duplicate-field-name"])):e.createCommentVNode("",!0),e.unref(p)&&l.field.type==="array"?(e.openBlock(),e.createBlock(rl,{key:3,adding:e.unref(p),field:l.field,"new-field":d,disabled:l.disabled,"read-only":l.readOnly,"field-label-class":e.unref(h),onAdd:j,onCancel:c},null,8,["adding","field","new-field","disabled","read-only","field-label-class"])):e.createCommentVNode("",!0),l.allowAdd!==!1&&!l.readOnly?(e.openBlock(),e.createElementBlock("div",Ml,[w[9]||(w[9]=e.createElementVNode("div",{class:"absolute -left-2.5 mr-2 h-0.5 w-3 bg-gray-200"},null,-1)),e.createElementVNode("button",{onClick:f,class:e.normalizeClass(["z-5 relative ml-2 flex p-1 text-xs font-medium text-gray-400",{"cursor-not-allowed":l.disabled,"hover:underline":!l.disabled}]),disabled:l.disabled},[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(((be=l.customIcons)==null?void 0:be.add)||e.unref(_)),{size:12,class:"mr-1"})),w[8]||(w[8]=e.createTextVNode(" ADD "))],10,Sl)])):e.createCommentVNode("",!0)],512),[[e.vShow,e.unref(m)]])],64)):e.createCommentVNode("",!0)])}}}),Ll={class:"rounded bg-gray-100 p-2 sm:p-4"},Il=["disabled"],Ol=e.defineComponent({__name:"JxEditor",props:{modelValue:{},showTypeLabel:{type:Boolean,default:!0},showFieldCount:{type:Boolean,default:!0},showArrayCount:{type:Boolean,default:!0},placeholder:{},disabled:{type:Boolean,default:!1},readOnly:{type:Boolean,default:!1},allowDelete:{type:Boolean,default:!0},allowEdit:{type:Boolean,default:!0},allowAdd:{type:Boolean,default:!0},allowExpand:{type:Boolean,default:!0},customIcons:{}},emits:["update:modelValue"],setup(s,{emit:b}){const r=s,o=b;function m(t){return t.map(f=>{const c={...f,id:f.id||`field-${Date.now()}-${Math.random().toString(36).substr(2,9)}`};return c.type==="object"&&Array.isArray(c.value)?c.value=m(c.value):c.type==="array"&&c.arrayType==="object"&&Array.isArray(c.value)&&(c.value=c.value.map(k=>typeof k=="object"&&k.type==="object"?{...k,id:k.id||`field-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,value:Array.isArray(k.value)?m(k.value):k.value}:k)),c})}function p(t){if(typeof t!="object"||t===null)return[];const f=Object.keys(t).map(c=>{const k=t[c],j={name:c,type:a(k),value:g(k),id:`field-${Date.now()}-${Math.random().toString(36).substr(2,9)}`};return j.type==="array"&&Array.isArray(k)&&(j.arrayType=u(k)),j});return m(f)}function a(t){return Array.isArray(t)?"array":t===null?"string":typeof t=="object"?"object":typeof t=="boolean"?"boolean":typeof t=="number"?"number":"string"}function u(t){if(t.length===0)return"string";const f=t[0];return typeof f=="object"&&f!==null?"object":typeof f=="number"?"number":"string"}function g(t){return Array.isArray(t)?t.map(f=>typeof f=="object"&&f!==null?{name:`array-item-${Date.now()}-${Math.random()}`,type:"object",value:p(f),id:`field-${Date.now()}-${Math.random().toString(36).substr(2,9)}`}:f):typeof t=="object"&&t!==null?p(t):t}function h(t){const f={};return t.forEach(c=>{c.type==="array"&&Array.isArray(c.value)?f[c.name]=c.value.map(k=>c.arrayType==="object"&&typeof k=="object"&&k.type==="object"?h(k.value):k):c.type==="object"&&Array.isArray(c.value)?f[c.name]=h(c.value):f[c.name]=c.value}),f}const B=e.ref(p(r.modelValue)),T=e.ref(!1),n=e.ref(""),y=e.ref(!1),d=e.ref({name:"",type:"string",value:O("string"),arrayType:void 0}),i=e.computed(()=>{const t=new Map,f=new Set;return B.value.forEach(c=>{const k=t.get(c.name)||0;t.set(c.name,k+1),k>=1&&f.add(c.name)}),f});e.watch(()=>r.modelValue,(t,f)=>{if(!y.value){const c=Object.keys(t||{}).sort().join(","),k=Object.keys(f||{}).sort().join(",");(!f||c!==k)&&(B.value=p(t))}},{immediate:!0}),e.watch(()=>d.value.name,t=>{n.value&&t!==n.value&&(n.value="")});function F(t,f){let c;f===null?c=B.value.filter((j,I)=>I!==t):c=B.value.map((j,I)=>I===t?f:j),B.value=c;const k=h(B.value);y.value=!0,o("update:modelValue",k),e.nextTick(()=>{y.value=!1})}const A=t=>{if(!x(t).isValid)return;if(B.value.some(I=>I.name===t.name)){n.value=t.name;return}n.value="";const k={name:t.name,type:t.type,value:t.value,arrayType:t.arrayType,id:`field-${Date.now()}-${Math.random().toString(36).substr(2,9)}`};B.value=[...B.value,k],T.value=!1,Object.assign(t,{name:"",type:"string",value:O("string"),arrayType:void 0});const j=h(B.value);y.value=!0,o("update:modelValue",j),e.nextTick(()=>{y.value=!1})},S=()=>{T.value=!1,n.value=""},L=t=>{var f;return((f=Y.find(c=>c.value===t))==null?void 0:f.label)||t};return(t,f)=>(e.openBlock(),e.createElementBlock("div",Ll,[e.createElementVNode("div",null,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(B.value,(c,k)=>(e.openBlock(),e.createBlock(G,{key:c.id||`root-${k}`,field:c,level:0,"show-type-label":t.showTypeLabel,"show-field-count":t.showFieldCount,"show-array-count":t.showArrayCount,placeholder:t.placeholder,disabled:t.disabled,"read-only":t.readOnly,"allow-delete":t.allowDelete,"allow-edit":t.allowEdit,"allow-add":t.allowAdd,"allow-expand":t.allowExpand,"custom-icons":t.customIcons,"has-duplicate-name":i.value.has(c.name),"onUpdate:field":j=>F(k,j)},null,8,["field","show-type-label","show-field-count","show-array-count","placeholder","disabled","read-only","allow-delete","allow-edit","allow-add","allow-expand","custom-icons","has-duplicate-name","onUpdate:field"]))),128))]),T.value?(e.openBlock(),e.createBlock(de,{key:0,adding:T.value,field:d.value,"field-type-label":L,disabled:t.disabled,"has-duplicate-attempt":!!n.value,"duplicate-field-name":n.value,onAdd:A,onCancel:S,"onUpdate:field":f[0]||(f[0]=c=>Object.assign(d.value,c))},null,8,["adding","field","disabled","has-duplicate-attempt","duplicate-field-name"])):e.createCommentVNode("",!0),t.allowAdd!==!1&&!t.readOnly?(e.openBlock(),e.createElementBlock("button",{key:1,onClick:f[1]||(f[1]=c=>T.value=!0),class:e.normalizeClass(["p-1 text-xs font-medium text-gray-400 hover:underline w-full sm:w-auto text-center sm:text-left",{"cursor-not-allowed":t.disabled}]),disabled:t.disabled}," + ADD ",10,Il)):e.createCommentVNode("",!0)]))}});N.ARRAY_ELEMENT_TYPES=ae,N.FIELD_TYPES=Y,N.FIELD_TYPE_CONFIGS=H,N.JxEditor=Ol,N.getDefaultValue=O,N.useClickOutside=ne,N.useJsonField=te,N.validateField=x,N.validateFields=ge,Object.defineProperty(N,Symbol.toStringTag,{value:"Module"})});