UNPKG

@sciphergfx/json-fields

Version:

UI-agnostic React component for generating Form Fields from JSON with support for Chakra UI, Tailwind CSS, and shadcn/ui

3 lines (2 loc) 28 kB
"use strict";var e=require("react"),t=require("react/jsx-runtime");function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function n(e,t,r){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t);if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function a(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function o(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?a(Object(r),!0).forEach(function(t){n(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):a(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function l(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,a,o,l,i=[],s=!0,c=!1;try{if(o=(r=r.call(e)).next,0===t);else for(;!(s=(n=o.call(r)).done)&&(i.push(n.value),i.length!==t);s=!0);}catch(e){c=!0,a=e}finally{try{if(!s&&null!=r.return&&(l=r.return(),Object(l)!==l))return}finally{if(c)throw a}}return i}}(e,t)||c(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(e){return function(e){if(Array.isArray(e))return r(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||c(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function s(e){return s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},s(e)}function c(e,t){if(e){if("string"==typeof e)return r(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(e,t):void 0}}var u=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",r={};for(var n in e)if(Object.prototype.hasOwnProperty.call(e,n)){var a=t?"".concat(t,".").concat(n):n;"object"!==s(e[n])||null===e[n]||Array.isArray(e[n])?r[a]=e[n]:Object.assign(r,u(e[n],a))}return r},d=function(e){var t={};for(var r in e){for(var n=r.split("."),a=t,o=0;o<n.length-1;o++)a[n[o]]||(a[n[o]]={}),a=a[n[o]];a[n[n.length-1]]=e[r]}return t},f=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(r[t])return o({type:r[t].type},r[t]);if("boolean"==typeof e)return{type:"checkbox"};if("number"==typeof e)return{type:"number"};if(Array.isArray(e))return{type:"array",items:e};if("object"===s(e)&&null!==e)return{type:"object"};if("string"==typeof e){if(e.length>100)return{type:"textarea",rows:4};if(e.includes("@")||t.toLowerCase().includes("email"))return{type:"email"};if(e.startsWith("http")||t.toLowerCase().includes("url"))return{type:"url"};if(e.match(/^\d{4}-\d{2}-\d{2}$/)||t.toLowerCase().includes("date"))return{type:"date"};if(t.toLowerCase().includes("password"))return{type:"password"}}return{type:"text"}},m=function(e){try{return{success:!0,data:JSON.parse(e)}}catch(e){return{success:!1,error:e.message}}},p=function(e){return e.split(".").pop().replace(/([A-Z])/g," $1").replace(/[_-]/g," ").replace(/\b\w/g,function(e){return e.toUpperCase()}).trim()},g=["_classNames","styles","renderers","uiLibrary","onSave","onCancel","onFieldChange","saveButtonText","cancelButtonText","initialJson","customStyles","showControls","columns","fieldConfig","sections","includeUnsectioned","unsectionedTitle"],x=function(r){r._classNames,r.styles;var a=r.renderers,c=void 0===a?{}:a;r.uiLibrary;var x=r.onSave,y=r.onCancel,b=r.onFieldChange,h=r.saveButtonText,v=void 0===h?"Save Changes":h,j=r.cancelButtonText,k=void 0===j?"Reset Form":j,w=r.initialJson,B=void 0===w?"":w,S=r.customStyles,C=void 0===S?{}:S,N=r.showControls,T=void 0===N||N,O=r.columns,A=void 0===O?2:O,L=r.fieldConfig,I=void 0===L?{}:L,H=r.sections,W=void 0===H?null:H,E=r.includeUnsectioned,P=void 0!==E&&E,V=r.unsectionedTitle,F=void 0===V?"Other":V,J=function(e,t){if(null==e)return{};var r,n,a=function(e,t){if(null==e)return{};var r={};for(var n in e)if({}.hasOwnProperty.call(e,n)){if(-1!==t.indexOf(n))continue;r[n]=e[n]}return r}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n<o.length;n++)r=o[n],-1===t.indexOf(r)&&{}.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}(r,g),D=l(e.useState(B),2),G=D[0],z=D[1],M=l(e.useState({}),2),R=M[0],U=M[1],_=l(e.useState({}),2),$=_[0],q=_[1],K=l(e.useState(null),2)[1],Z=l(e.useState(""),2),Q=Z[0],X=Z[1],Y=l(e.useState({}),2),ee=Y[0],te=Y[1],re=l(e.useState(function(){return new Set}),2),ne=re[0],ae=re[1],oe={Container:c.Container||"div",Box:c.Box||"div",Button:c.Button||"button",Input:c.Input||"input",Select:c.Select||"select",Textarea:c.Textarea||"textarea",Text:c.Text||"span",Heading:c.Heading||"h2",VStack:c.VStack||"div",HStack:c.HStack||"div",Card:c.Card||"div",Alert:c.Alert||"div",Label:c.Label||"label"},le=function(e,r,a){var c=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},u=Array.isArray(r),d=!u&&"object"===s(r)&&null!==r,f=u?r:d?Object.entries(r).map(function(e){var t=l(e,2);return{key:t[0],value:t[1]}}):[],m=[];if(f.length){var p=new Set;f.forEach(function(e){return Object.keys(e||{}).forEach(function(e){return p.add(e)})}),m=Array.from(p)}else m=Array.isArray(c.columns)?c.columns:["key","value"];var g=function(t){if(u)ce(e,t);else if(d){var r={};t.forEach(function(e){var t,n,a=null!==(t=e.key)&&void 0!==t?t:e.name,o=null!==(n=e.value)&&void 0!==n?n:e.val;void 0!==a&&""!==a&&(r[a]=o)}),ce(e,r)}else ce(e,t)},x={display:"grid",gridTemplateColumns:"".concat("1fr ".repeat(m.length),"auto").trim(),gap:"0.5rem",alignItems:"center",padding:"3px 0px"};return t.jsxs(oe.Box,{className:ie(),style:o({marginBottom:"1rem"},C.fieldContainer),children:[t.jsx(oe.Label,{className:ie(),style:o({display:"block",fontWeight:"600",marginBottom:"0.5rem"},C.fieldLabel),children:a}),!1!==c.showHeader&&t.jsxs(oe.Box,{style:o(o({},x),{},{fontSize:"12px",opacity:.8}),children:[m.map(function(e){return t.jsx(oe.Text,{children:e},"hdr-".concat(e))}),t.jsx("span",{})]}),t.jsxs(oe.VStack,{style:{gap:"0.5rem"},children:[f.map(function(r,l){return t.jsxs(oe.Box,{style:x,children:[m.map(function(a){var i;return t.jsx(oe.Input,{type:"text",placeholder:a,value:null!==(i=null==r?void 0:r[a])&&void 0!==i?i:"",onChange:function(e){return t=l,r=a,i=e.target.value,s=f.map(function(e,a){return a===t?o(o({},e),{},n({},r,i)):e}),void g(s);var t,r,i,s},className:ie(),style:C.input},"".concat(e,"-").concat(l,"-").concat(a))}),t.jsx(oe.Button,{"aria-label":"Remove ".concat(a," row ").concat(l+1),onClick:function(){return function(e){var t=f.filter(function(t,r){return r!==e});g(t)}(l)},className:ie(),style:{padding:"6px 10px"},children:"×"})]},"".concat(e,"-").concat(l))}),t.jsxs(oe.Button,{onClick:function(){var e=m.reduce(function(e,t){return o(o({},e),{},n({},t,""))},{});g([].concat(i(f),[e]))},className:ie(),style:{alignSelf:"flex-start",padding:"6px 10px"},children:["+ Add ",a]})]})]},e)},ie=function(){return""},se=e.useCallback(function(){var e=m(arguments.length>0&&void 0!==arguments[0]?arguments[0]:G);if(e.success){K(e.data);var t=u(e.data);U(t),q(o({},t)),X("")}else X(e.error),K(null),U({}),q({})},[G]);e.useEffect(function(){B?(z(B),se(B)):""===B&&(z(""),U({}),q({}),K(null),X(""))},[B,se]);var ce=function(e,t){var r=o(o({},R),{},n({},e,t));if(U(r),b){var a=d(r);b(e,t,a)}},ue=function(e,t){var r=f(t,e,I),n=p(e);switch(r.type){case"checkbox":return fe(e,t,n);case"select":return me(e,t,n,r);case"multi-select":return pe(e,t,n,r);case"textarea":return ge(e,t,n,r);case"email":case"url":case"date":case"password":return xe(e,t,n,r);case"number":return ye(e,t,n);case"slider":return de(e,t,n,r);case"tags":return he(e,t,n,r);case"key-value-list":return le(e,t,n,r);case"array":return be(e,t,n,r);case"object":return ve(e,t,n);default:return je(e,t,n)}},de=function(e,r,n,a){var l,i,s,c,u=null!==(l=a.min)&&void 0!==l?l:0,d=null!==(i=a.max)&&void 0!==i?i:100,f=null!==(s=a.step)&&void 0!==s?s:1,m="number"==typeof R[e]?R[e]:null!==(c=a.default)&&void 0!==c?c:u;return t.jsxs(oe.Box,{className:ie(),style:o({marginBottom:"1rem"},C.fieldContainer),children:[t.jsx(oe.Label,{className:ie(),style:C.label,children:t.jsx(oe.Text,{className:ie(),style:o({fontWeight:"500"},C.fieldLabel),children:n})}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[t.jsx("input",{type:"range",min:u,max:d,step:f,value:m,onChange:function(t){return ce(e,Number(t.target.value))},className:ie(),style:{width:"100%"}}),t.jsx(oe.Text,{className:ie(),style:{minWidth:"3rem",textAlign:"right"},children:m})]})]},e)},fe=function(e,r,n){return t.jsx(oe.Box,{className:ie(),style:o({marginBottom:"1rem"},C.fieldContainer),children:t.jsxs(oe.Label,{className:ie(),style:o({display:"flex",alignItems:"center",gap:"0.5rem",cursor:"pointer"},C.label),children:[t.jsx("input",{type:"checkbox",checked:R[e]||!1,onChange:function(t){return ce(e,t.target.checked)},className:ie(),style:C.checkbox}),t.jsx(oe.Text,{className:ie(),style:o({fontWeight:"500"},C.fieldLabel),children:n})]})},e)},me=function(e,r,n,a){var l;return t.jsxs(oe.Box,{className:ie(),style:o({marginBottom:"1rem"},C.fieldContainer),children:[t.jsx(oe.Label,{className:ie(),style:o({display:"block",fontWeight:"600",marginBottom:"0.5rem"},C.fieldLabel),children:n}),t.jsxs(oe.Select,{value:R[e]||"",onChange:function(t){return ce(e,t.target.value)},className:ie(),style:o({width:"100%"},C.select),children:[t.jsxs("option",{value:"",children:["Select ",n]}),null===(l=a.options)||void 0===l?void 0:l.map(function(e){return t.jsx("option",{value:e,children:e},e)})]})]},e)},pe=function(e,r,n,a){var l,s=Array.isArray(R[e])?R[e]:[];return t.jsxs(oe.Box,{className:ie(),style:o({marginBottom:"1rem"},C.fieldContainer),children:[t.jsx(oe.Label,{className:ie(),style:o({display:"block",fontWeight:"600",marginBottom:"0.5rem"},C.fieldLabel),children:n}),t.jsx(oe.Box,{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},children:null===(l=a.options)||void 0===l?void 0:l.map(function(r){return t.jsxs(oe.Label,{style:{display:"flex",alignItems:"center",gap:"0.5rem",cursor:"pointer"},children:[t.jsx("input",{type:"checkbox",checked:s.includes(r),onChange:function(t){var n=t.target.checked?[].concat(i(s),[r]):s.filter(function(e){return e!==r});ce(e,n)},style:C.checkbox}),t.jsx(oe.Text,{style:o({fontSize:"14px"},C.text),children:r})]},r)})})]},e)},ge=function(e,r,n,a){return t.jsxs(oe.Box,{className:ie(),style:o({marginBottom:"1rem"},C.fieldContainer),children:[t.jsx(oe.Label,{className:ie(),style:o({display:"block",fontWeight:"600",marginBottom:"0.5rem"},C.fieldLabel),children:n}),t.jsx(oe.Textarea,{value:R[e]||"",onChange:function(t){return ce(e,t.target.value)},className:ie(),style:o({width:"100%",minHeight:"".concat(1.5*(a.rows||4),"rem")},C.textarea)})]},e)},xe=function(e,r,n,a){return t.jsxs(oe.Box,{className:ie(),style:o({marginBottom:"1rem"},C.fieldContainer),children:[t.jsx(oe.Label,{className:ie(),style:o({display:"block",fontWeight:"600",marginBottom:"0.5rem"},C.fieldLabel),children:n}),t.jsx(oe.Input,{type:a.type,value:R[e]||"",onChange:function(t){return ce(e,t.target.value)},className:ie(),style:o({width:"100%"},C.input)})]},e)},ye=function(e,r,n){return t.jsxs(oe.Box,{className:ie(),style:o({marginBottom:"1rem"},C.fieldContainer),children:[t.jsx(oe.Label,{className:ie(),style:o({display:"block",fontWeight:"600",marginBottom:"0.5rem"},C.fieldLabel),children:n}),t.jsx(oe.Input,{type:"number",value:R[e]||"",onChange:function(t){var r=parseFloat(t.target.value)||0;ce(e,r)},className:ie(),style:o({width:"100%"},C.input)})]},e)},be=function(e,r,a,l){if((Array.isArray(r)?r:[]).every(function(e){return"string"==typeof e})){var s=Array.isArray(R[e])?R[e]:[],c=ee[e]||"",u=function(t){var r=(t||"").trim();r&&(s.includes(r)||(ce(e,[].concat(i(s),[r])),te(function(t){return o(o({},t),{},n({},e,""))})))},d=function(t){ce(e,s.filter(function(e){return e!==t}))},f={display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"999px",background:"#eef2ff",color:"#3730a3",border:"1px solid #c7d2fe",fontSize:"12px"},m={cursor:"pointer",border:"none",background:"transparent",color:"#4338ca",fontSize:"14px",lineHeight:1};return t.jsxs(oe.Box,{className:ie(),style:o({marginBottom:"1rem"},C.fieldContainer),children:[t.jsx(oe.Label,{className:ie(),style:o({display:"block",fontWeight:"600",marginBottom:"0.5rem"},C.fieldLabel),children:a}),t.jsxs(oe.Box,{style:{display:"flex",flexWrap:"wrap",gap:"8px",alignItems:"center"},children:[s.map(function(e){return t.jsxs("span",{style:f,children:[e,t.jsx("button",{"aria-label":"Remove ".concat(e),onClick:function(){return d(e)},style:m,children:"×"})]},e)}),t.jsx(oe.Input,{type:"text",value:c,onChange:function(t){return te(function(r){return o(o({},r),{},n({},e,t.target.value))})},onKeyDown:function(e){"Enter"===e.key||","===e.key?(e.preventDefault(),u(c)):"Backspace"===e.key&&!c&&s.length&&d(s[s.length-1])},placeholder:l.placeholder||"Add ".concat(a," and press Enter"),className:ie(),style:o({minWidth:"140px",flex:"0 1 auto"},C.input)}),t.jsx(oe.Button,{onClick:function(){return u(c)},className:ie(),style:{padding:"6px 10px"},children:"Add"})]})]},e)}return t.jsxs(oe.Box,{className:ie(),style:o({marginBottom:"1rem"},C.fieldContainer),children:[t.jsxs(oe.Label,{className:ie(),style:o({display:"block",fontWeight:"600",marginBottom:"0.5rem"},C.fieldLabel),children:[a," (Array)"]}),t.jsx(oe.Textarea,{value:JSON.stringify(r,null,2),onChange:function(t){try{var r=JSON.parse(t.target.value);ce(e,r)}catch(r){ce(e,t.target.value)}},className:ie(),style:o({fontFamily:"monospace",minHeight:"100px",width:"100%"},C.textarea)})]},e)},he=function(e,r,a,l){var s=Array.isArray(R[e])?R[e]:[],c=ee[e]||"",u=function(t){var r=(t||"").trim();r&&(s.includes(r)||(ce(e,[].concat(i(s),[r])),te(function(t){return o(o({},t),{},n({},e,""))})))},d=function(t){ce(e,s.filter(function(e){return e!==t}))},f={display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"999px",background:"#eef2ff",color:"#3730a3",border:"1px solid #c7d2fe",fontSize:"12px"},m={cursor:"pointer",border:"none",background:"transparent",color:"#4338ca",fontSize:"14px",lineHeight:1};return t.jsxs(oe.Box,{className:ie(),style:o({marginBottom:"1rem"},C.fieldContainer),children:[t.jsx(oe.Label,{className:ie(),style:o({display:"block",fontWeight:"600",marginBottom:"0.5rem"},C.fieldLabel),children:a}),t.jsxs(oe.Box,{style:{display:"flex",flexWrap:"wrap",gap:"8px",alignItems:"center"},children:[s.map(function(e){return t.jsxs("span",{style:f,children:[e,t.jsx("button",{"aria-label":"Remove ".concat(e),onClick:function(){return d(e)},style:m,children:"×"})]},e)}),t.jsx(oe.Input,{type:"text",value:c,onChange:function(t){return te(function(r){return o(o({},r),{},n({},e,t.target.value))})},onKeyDown:function(e){"Enter"===e.key||","===e.key?(e.preventDefault(),u(c)):"Backspace"===e.key&&!c&&s.length&&d(s[s.length-1])},placeholder:l.placeholder||"Add tag and press Enter",className:ie(),style:o({minWidth:"140px",flex:"0 1 auto"},C.input)}),t.jsx(oe.Button,{onClick:function(){return u(c)},className:ie(),style:{padding:"6px 10px"},children:"Add"})]})]},e)},ve=function(e,r,n){return t.jsxs(oe.Box,{className:ie(),style:o({marginBottom:"1rem"},C.fieldContainer),children:[t.jsxs(oe.Label,{className:ie(),style:o({display:"block",fontWeight:"600",marginBottom:"0.5rem"},C.fieldLabel),children:[n," (Object)"]}),t.jsx(oe.Textarea,{value:JSON.stringify(r,null,2),onChange:function(t){try{var r=JSON.parse(t.target.value);ce(e,r)}catch(r){ce(e,t.target.value)}},className:ie(),style:o({fontFamily:"monospace",minHeight:"100px",width:"100%"},C.textarea)})]},e)},je=function(e,r,n){return t.jsxs(oe.Box,{className:ie(),style:o({marginBottom:"1rem"},C.fieldContainer),children:[t.jsx(oe.Label,{className:ie(),style:o({display:"block",fontWeight:"600",marginBottom:"0.5rem"},C.fieldLabel),children:n}),t.jsx(oe.Input,{type:"text",value:R[e]||"",onChange:function(t){return ce(e,t.target.value)},className:ie(),style:o({width:"100%"},C.input)})]},e)};return t.jsx(oe.Container,o(o({className:ie(),style:C.container},J),{},{children:t.jsxs(oe.VStack,{className:ie(),style:o({gap:"1rem"},C.stack),children:[Q&&t.jsx(oe.Alert,{className:ie(),style:C.alert,children:t.jsx(oe.Text,{style:C.errorText,children:Q})}),Object.keys(R).length>0&&t.jsx(oe.Card,{className:ie(),style:o({width:"100%",padding:"1rem"},C.formCard),children:function(){if(Array.isArray(W)&&W.length){var e=Object.keys(R),r=new Set,n=W.map(function(n,a){var l=n.id||"section-".concat(a),i=Array.isArray(n.fields)?n.fields:[];i.forEach(function(e){return r.add(e)});var s=i.filter(function(t){return e.includes(t)}),c=function(){if(A<=1)return t.jsx(oe.VStack,{style:{gap:"1rem"},children:s.map(function(e){return ue(e,R[e])})},l);for(var e=Math.ceil(s.length/A),r=[],n=0;n<A;n++){var a=n*e,i=Math.min(a+e,s.length);r.push(s.slice(a,i))}var c=o({display:"grid",gridTemplateColumns:"repeat(".concat(A,", 1fr)"),gap:"2rem",width:"100%"},C.formGrid);return t.jsx(oe.Box,{className:ie(),style:c,children:r.map(function(e,r){return t.jsx(oe.VStack,{className:ie(),style:o({gap:"1rem"},C.formColumn),children:e.map(function(e){return ue(e,R[e])})},r)})},l)}(),u=!(!n.defaultOpen&&n.collapsible),d=ne.has(l)?!u:u;return t.jsxs(oe.Box,{style:{marginBottom:"1.25rem"},children:[t.jsxs(oe.Box,{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"0.5rem"},children:[t.jsxs(oe.Box,{style:{display:"flex",alignItems:"center",gap:"8px"},children:[n.collapsible&&t.jsx("button",{"aria-label":"Toggle ".concat(n.title),onClick:function(){return ae(function(e){var t=new Set(e);return t.has(l)?t.delete(l):t.add(l),t})},style:{border:"none",background:"transparent",cursor:"pointer"},children:t.jsx("span",{children:d?"▼":"▶"})}),t.jsx(oe.Heading,{className:ie(),style:{margin:0},children:n.title})]}),n.description&&t.jsx(oe.Text,{className:ie(),style:{opacity:.8},children:n.description})]}),(!n.collapsible||d)&&c]},"wrap-".concat(l))}),a=null;if(P){var i=e.filter(function(e){return!r.has(e)});if(i.length){var s="unsectioned",c=!0,u=!ne.has(s)&&c;a=t.jsxs(oe.Box,{style:{marginBottom:"1.25rem"},children:[t.jsx(oe.Box,{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"0.5rem"},children:t.jsxs(oe.Box,{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("button",{"aria-label":"Toggle ".concat(F),onClick:function(){return ae(function(e){var t=new Set(e);return t.has(s)?t.delete(s):t.add(s),t})},style:{border:"none",background:"transparent",cursor:"pointer"},children:t.jsx("span",{children:u?"▼":"▶"})}),t.jsx(oe.Heading,{className:ie(),style:{margin:0},children:F})]})}),u&&function(){if(A<=1)return t.jsx(oe.VStack,{style:{gap:"1rem"},children:i.map(function(e){return ue(e,R[e])})});for(var e=Math.ceil(i.length/A),r=[],n=0;n<A;n++){var a=n*e,l=Math.min(a+e,i.length);r.push(i.slice(a,l))}var s=o({display:"grid",gridTemplateColumns:"repeat(".concat(A,", 1fr)"),gap:"2rem",width:"100%"},C.formGrid);return t.jsx(oe.Box,{className:ie(),style:s,children:r.map(function(e,r){return t.jsx(oe.VStack,{className:ie(),style:o({gap:"1rem"},C.formColumn),children:e.map(function(e){return ue(e,R[e])})},r)})})}()]},"wrap-".concat(s))}}return t.jsxs(oe.VStack,{className:ie(),style:o({gap:"1rem"},C.formStack),children:[n,a]})}var d=Object.entries(R);if(A<=1)return t.jsx(oe.VStack,{className:ie(),style:o({gap:"1rem"},C.formStack),children:d.map(function(e){var t=l(e,2),r=t[0],n=t[1];return ue(r,n)})});for(var f=Math.ceil(d.length/A),m=[],p=0;p<A;p++){var g=p*f,x=Math.min(g+f,d.length);m.push(d.slice(g,x))}var y=o({display:"grid",gridTemplateColumns:"repeat(".concat(A,", 1fr)"),gap:"2rem",width:"100%"},C.formGrid);return t.jsx(oe.Box,{className:ie(),style:y,children:m.map(function(e,r){return t.jsx(oe.VStack,{className:ie(),style:o({gap:"1rem"},C.formColumn),children:e.map(function(e){var t=l(e,2),r=t[0],n=t[1];return ue(r,n)})},r)})})}()}),T&&Object.keys(R).length>0&&t.jsxs(oe.HStack,{className:ie(),style:o({gap:"0.5rem",marginTop:"1rem"},C.controlButtons),children:[t.jsx(oe.Button,{onClick:function(){if(x){var e=d(R);x(e,R)}},className:ie(),style:C.saveButton,children:v}),t.jsx(oe.Button,{onClick:function(){U(o({},$)),y&&y()},className:ie(),style:C.cancelButton,children:k})]})]})}))};exports.Fields=x,exports.JsonFields=x,exports.flattenObject=u,exports.formatJson=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2;return JSON.stringify(e,null,t)},exports.getDisplayName=p,exports.getInputType=f,exports.getNestedLevel=function(e){return e.split(".").length-1},exports.getUIClasses=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"chakra",t=arguments.length>1?arguments[1]:void 0,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"default";if("chakra"===e)return"";var n={tailwind:{Container:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8",Box:"block",Button:{default:"inline-flex items-center px-4 py-2 border border-transparent text-sm font-medium rounded-md shadow-sm text-white bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500",secondary:"inline-flex items-center px-4 py-2 border border-gray-300 text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500"},Input:{default:"block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm",checkbox:"h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded"},Select:"block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm",Textarea:"block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm resize-vertical",Table:"min-w-full divide-y divide-gray-200",Thead:"bg-gray-50",Tbody:"bg-white divide-y divide-gray-200",Tr:"hover:bg-gray-50",Th:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",Td:"px-6 py-4 whitespace-nowrap text-sm text-gray-900",Text:"text-gray-900",Heading:"text-2xl font-bold text-gray-900 mb-4",Stack:"space-y-4",HStack:"flex space-x-4 items-center",VStack:"flex flex-col space-y-4",Card:"bg-white overflow-hidden shadow rounded-lg p-6",Alert:{error:"bg-red-50 border border-red-200 rounded-md p-4 text-red-800",success:"bg-green-50 border border-green-200 rounded-md p-4 text-green-800",warning:"bg-yellow-50 border border-yellow-200 rounded-md p-4 text-yellow-800",info:"bg-blue-50 border border-blue-200 rounded-md p-4 text-blue-800"},Badge:"inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-blue-100 text-blue-800",Grid:"grid",GridItem:"",Flex:"flex",Label:"block text-sm font-medium text-gray-700"},shadcn:{Container:"container mx-auto px-4",Box:"block",Button:{default:"inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 bg-primary text-primary-foreground hover:bg-primary/90 h-10 px-4 py-2",secondary:"inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 bg-secondary text-secondary-foreground hover:bg-secondary/80 h-10 px-4 py-2"},Input:{default:"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",checkbox:"h-4 w-4 rounded border border-primary text-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"},Select:"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",Textarea:"flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",Table:"w-full caption-bottom text-sm",Thead:"[&_tr]:border-b",Tbody:"[&_tr:last-child]:border-0",Tr:"border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",Th:"h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0",Td:"p-4 align-middle [&:has([role=checkbox])]:pr-0",Text:"text-sm text-muted-foreground",Heading:"scroll-m-20 text-2xl font-semibold tracking-tight",Stack:"flex flex-col space-y-4",HStack:"flex space-x-4",VStack:"flex flex-col space-y-4",Card:"rounded-lg border bg-card text-card-foreground shadow-sm",Alert:{error:"relative w-full rounded-lg border p-4 [&>svg~*]:pl-7 [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive",success:"relative w-full rounded-lg border p-4 [&>svg~*]:pl-7 [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground",warning:"relative w-full rounded-lg border p-4 [&>svg~*]:pl-7 [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground",info:"relative w-full rounded-lg border p-4 [&>svg~*]:pl-7 [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground"},Badge:"inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",Grid:"grid",GridItem:"",Flex:"flex",Label:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"}}[e];if(!n||!n[t])return"";var a=n[t];return"object"===s(a)?a[r]||a.default||"":a},exports.getUIComponents=function(){return{Container:"div",Box:"div",Button:"button",Input:"input",Select:"select",Textarea:"textarea",Table:"table",Thead:"thead",Tbody:"tbody",Tr:"tr",Th:"th",Td:"td",Text:"span",Heading:"h2",Stack:"div",HStack:"div",VStack:"div",Card:"div",Alert:"div",Badge:"span",Grid:"div",GridItem:"div",Flex:"div",Label:"label"}},exports.parseJsonSafely=m,exports.unflattenObject=d; //# sourceMappingURL=index.js.map