@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.3 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("react/jsx-runtime")):"function"==typeof define&&define.amd?define(["exports","react","react/jsx-runtime"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).JsonFields={},e.React,e.jsxRuntime)}(this,function(e,t,r){"use strict";function n(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 a(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 o(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 i(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?o(Object(r),!0).forEach(function(t){a(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):o(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,i,l=[],s=!0,c=!1;try{if(o=(r=r.call(e)).next,0===t);else for(;!(s=(n=o.call(r)).done)&&(l.push(n.value),l.length!==t);s=!0);}catch(e){c=!0,a=e}finally{try{if(!s&&null!=r.return&&(i=r.return(),Object(i)!==i))return}finally{if(c)throw a}}return l}}(e,t)||u(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 s(e){return function(e){if(Array.isArray(e))return n(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||u(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 c(e){return c="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},c(e)}function u(e,t){if(e){if("string"==typeof e)return n(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(e,t):void 0}}var d=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"!==c(e[n])||null===e[n]||Array.isArray(e[n])?r[a]=e[n]:Object.assign(r,d(e[n],a))}return r},f=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},m=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 i({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"===c(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"}},p=function(e){try{return{success:!0,data:JSON.parse(e)}}catch(e){return{success:!1,error:e.message}}},g=function(e){return e.split(".").pop().replace(/([A-Z])/g," $1").replace(/[_-]/g," ").replace(/\b\w/g,function(e){return e.toUpperCase()}).trim()},x=["_classNames","styles","renderers","uiLibrary","onSave","onCancel","onFieldChange","saveButtonText","cancelButtonText","initialJson","customStyles","showControls","columns","fieldConfig","sections","includeUnsectioned","unsectionedTitle"],y=function(e){e._classNames,e.styles;var n=e.renderers,o=void 0===n?{}:n;e.uiLibrary;var u=e.onSave,y=e.onCancel,b=e.onFieldChange,h=e.saveButtonText,v=void 0===h?"Save Changes":h,j=e.cancelButtonText,k=void 0===j?"Reset Form":j,w=e.initialJson,B=void 0===w?"":w,S=e.customStyles,C=void 0===S?{}:S,N=e.showControls,T=void 0===N||N,O=e.columns,A=void 0===O?2:O,L=e.fieldConfig,I=void 0===L?{}:L,H=e.sections,W=void 0===H?null:H,E=e.includeUnsectioned,P=void 0!==E&&E,V=e.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}(e,x),D=l(t.useState(B),2),G=D[0],R=D[1],z=l(t.useState({}),2),M=z[0],U=z[1],_=l(t.useState({}),2),$=_[0],q=_[1],K=l(t.useState(null),2)[1],Z=l(t.useState(""),2),Q=Z[0],X=Z[1],Y=l(t.useState({}),2),ee=Y[0],te=Y[1],re=l(t.useState(function(){return new Set}),2),ne=re[0],ae=re[1],oe={Container:o.Container||"div",Box:o.Box||"div",Button:o.Button||"button",Input:o.Input||"input",Select:o.Select||"select",Textarea:o.Textarea||"textarea",Text:o.Text||"span",Heading:o.Heading||"h2",VStack:o.VStack||"div",HStack:o.HStack||"div",Card:o.Card||"div",Alert:o.Alert||"div",Label:o.Label||"label"},ie=function(e,t,n){var o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},u=Array.isArray(t),d=!u&&"object"===c(t)&&null!==t,f=u?t:d?Object.entries(t).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(o.columns)?o.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 r.jsxs(oe.Box,{className:le(),style:i({marginBottom:"1rem"},C.fieldContainer),children:[r.jsx(oe.Label,{className:le(),style:i({display:"block",fontWeight:"600",marginBottom:"0.5rem"},C.fieldLabel),children:n}),!1!==o.showHeader&&r.jsxs(oe.Box,{style:i(i({},x),{},{fontSize:"12px",opacity:.8}),children:[m.map(function(e){return r.jsx(oe.Text,{children:e},"hdr-".concat(e))}),r.jsx("span",{})]}),r.jsxs(oe.VStack,{style:{gap:"0.5rem"},children:[f.map(function(t,o){return r.jsxs(oe.Box,{style:x,children:[m.map(function(n){var l;return r.jsx(oe.Input,{type:"text",placeholder:n,value:null!==(l=null==t?void 0:t[n])&&void 0!==l?l:"",onChange:function(e){return t=o,r=n,l=e.target.value,s=f.map(function(e,n){return n===t?i(i({},e),{},a({},r,l)):e}),void g(s);var t,r,l,s},className:le(),style:C.input},"".concat(e,"-").concat(o,"-").concat(n))}),r.jsx(oe.Button,{"aria-label":"Remove ".concat(n," row ").concat(o+1),onClick:function(){return function(e){var t=f.filter(function(t,r){return r!==e});g(t)}(o)},className:le(),style:{padding:"6px 10px"},children:"×"})]},"".concat(e,"-").concat(o))}),r.jsxs(oe.Button,{onClick:function(){var e=m.reduce(function(e,t){return i(i({},e),{},a({},t,""))},{});g([].concat(s(f),[e]))},className:le(),style:{alignSelf:"flex-start",padding:"6px 10px"},children:["+ Add ",n]})]})]},e)},le=function(){return""},se=t.useCallback(function(){var e=p(arguments.length>0&&void 0!==arguments[0]?arguments[0]:G);if(e.success){K(e.data);var t=d(e.data);U(t),q(i({},t)),X("")}else X(e.error),K(null),U({}),q({})},[G]);t.useEffect(function(){B?(R(B),se(B)):""===B&&(R(""),U({}),q({}),K(null),X(""))},[B,se]);var ce=function(e,t){var r=i(i({},M),{},a({},e,t));if(U(r),b){var n=f(r);b(e,t,n)}},ue=function(e,t){var r=m(t,e,I),n=g(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 ie(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,t,n,a){var o,l,s,c,u=null!==(o=a.min)&&void 0!==o?o:0,d=null!==(l=a.max)&&void 0!==l?l:100,f=null!==(s=a.step)&&void 0!==s?s:1,m="number"==typeof M[e]?M[e]:null!==(c=a.default)&&void 0!==c?c:u;return r.jsxs(oe.Box,{className:le(),style:i({marginBottom:"1rem"},C.fieldContainer),children:[r.jsx(oe.Label,{className:le(),style:C.label,children:r.jsx(oe.Text,{className:le(),style:i({fontWeight:"500"},C.fieldLabel),children:n})}),r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[r.jsx("input",{type:"range",min:u,max:d,step:f,value:m,onChange:function(t){return ce(e,Number(t.target.value))},className:le(),style:{width:"100%"}}),r.jsx(oe.Text,{className:le(),style:{minWidth:"3rem",textAlign:"right"},children:m})]})]},e)},fe=function(e,t,n){return r.jsx(oe.Box,{className:le(),style:i({marginBottom:"1rem"},C.fieldContainer),children:r.jsxs(oe.Label,{className:le(),style:i({display:"flex",alignItems:"center",gap:"0.5rem",cursor:"pointer"},C.label),children:[r.jsx("input",{type:"checkbox",checked:M[e]||!1,onChange:function(t){return ce(e,t.target.checked)},className:le(),style:C.checkbox}),r.jsx(oe.Text,{className:le(),style:i({fontWeight:"500"},C.fieldLabel),children:n})]})},e)},me=function(e,t,n,a){var o;return r.jsxs(oe.Box,{className:le(),style:i({marginBottom:"1rem"},C.fieldContainer),children:[r.jsx(oe.Label,{className:le(),style:i({display:"block",fontWeight:"600",marginBottom:"0.5rem"},C.fieldLabel),children:n}),r.jsxs(oe.Select,{value:M[e]||"",onChange:function(t){return ce(e,t.target.value)},className:le(),style:i({width:"100%"},C.select),children:[r.jsxs("option",{value:"",children:["Select ",n]}),null===(o=a.options)||void 0===o?void 0:o.map(function(e){return r.jsx("option",{value:e,children:e},e)})]})]},e)},pe=function(e,t,n,a){var o,l=Array.isArray(M[e])?M[e]:[];return r.jsxs(oe.Box,{className:le(),style:i({marginBottom:"1rem"},C.fieldContainer),children:[r.jsx(oe.Label,{className:le(),style:i({display:"block",fontWeight:"600",marginBottom:"0.5rem"},C.fieldLabel),children:n}),r.jsx(oe.Box,{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},children:null===(o=a.options)||void 0===o?void 0:o.map(function(t){return r.jsxs(oe.Label,{style:{display:"flex",alignItems:"center",gap:"0.5rem",cursor:"pointer"},children:[r.jsx("input",{type:"checkbox",checked:l.includes(t),onChange:function(r){var n=r.target.checked?[].concat(s(l),[t]):l.filter(function(e){return e!==t});ce(e,n)},style:C.checkbox}),r.jsx(oe.Text,{style:i({fontSize:"14px"},C.text),children:t})]},t)})})]},e)},ge=function(e,t,n,a){return r.jsxs(oe.Box,{className:le(),style:i({marginBottom:"1rem"},C.fieldContainer),children:[r.jsx(oe.Label,{className:le(),style:i({display:"block",fontWeight:"600",marginBottom:"0.5rem"},C.fieldLabel),children:n}),r.jsx(oe.Textarea,{value:M[e]||"",onChange:function(t){return ce(e,t.target.value)},className:le(),style:i({width:"100%",minHeight:"".concat(1.5*(a.rows||4),"rem")},C.textarea)})]},e)},xe=function(e,t,n,a){return r.jsxs(oe.Box,{className:le(),style:i({marginBottom:"1rem"},C.fieldContainer),children:[r.jsx(oe.Label,{className:le(),style:i({display:"block",fontWeight:"600",marginBottom:"0.5rem"},C.fieldLabel),children:n}),r.jsx(oe.Input,{type:a.type,value:M[e]||"",onChange:function(t){return ce(e,t.target.value)},className:le(),style:i({width:"100%"},C.input)})]},e)},ye=function(e,t,n){return r.jsxs(oe.Box,{className:le(),style:i({marginBottom:"1rem"},C.fieldContainer),children:[r.jsx(oe.Label,{className:le(),style:i({display:"block",fontWeight:"600",marginBottom:"0.5rem"},C.fieldLabel),children:n}),r.jsx(oe.Input,{type:"number",value:M[e]||"",onChange:function(t){var r=parseFloat(t.target.value)||0;ce(e,r)},className:le(),style:i({width:"100%"},C.input)})]},e)},be=function(e,t,n,o){if((Array.isArray(t)?t:[]).every(function(e){return"string"==typeof e})){var l=Array.isArray(M[e])?M[e]:[],c=ee[e]||"",u=function(t){var r=(t||"").trim();r&&(l.includes(r)||(ce(e,[].concat(s(l),[r])),te(function(t){return i(i({},t),{},a({},e,""))})))},d=function(t){ce(e,l.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 r.jsxs(oe.Box,{className:le(),style:i({marginBottom:"1rem"},C.fieldContainer),children:[r.jsx(oe.Label,{className:le(),style:i({display:"block",fontWeight:"600",marginBottom:"0.5rem"},C.fieldLabel),children:n}),r.jsxs(oe.Box,{style:{display:"flex",flexWrap:"wrap",gap:"8px",alignItems:"center"},children:[l.map(function(e){return r.jsxs("span",{style:f,children:[e,r.jsx("button",{"aria-label":"Remove ".concat(e),onClick:function(){return d(e)},style:m,children:"×"})]},e)}),r.jsx(oe.Input,{type:"text",value:c,onChange:function(t){return te(function(r){return i(i({},r),{},a({},e,t.target.value))})},onKeyDown:function(e){"Enter"===e.key||","===e.key?(e.preventDefault(),u(c)):"Backspace"===e.key&&!c&&l.length&&d(l[l.length-1])},placeholder:o.placeholder||"Add ".concat(n," and press Enter"),className:le(),style:i({minWidth:"140px",flex:"0 1 auto"},C.input)}),r.jsx(oe.Button,{onClick:function(){return u(c)},className:le(),style:{padding:"6px 10px"},children:"Add"})]})]},e)}return r.jsxs(oe.Box,{className:le(),style:i({marginBottom:"1rem"},C.fieldContainer),children:[r.jsxs(oe.Label,{className:le(),style:i({display:"block",fontWeight:"600",marginBottom:"0.5rem"},C.fieldLabel),children:[n," (Array)"]}),r.jsx(oe.Textarea,{value:JSON.stringify(t,null,2),onChange:function(t){try{var r=JSON.parse(t.target.value);ce(e,r)}catch(r){ce(e,t.target.value)}},className:le(),style:i({fontFamily:"monospace",minHeight:"100px",width:"100%"},C.textarea)})]},e)},he=function(e,t,n,o){var l=Array.isArray(M[e])?M[e]:[],c=ee[e]||"",u=function(t){var r=(t||"").trim();r&&(l.includes(r)||(ce(e,[].concat(s(l),[r])),te(function(t){return i(i({},t),{},a({},e,""))})))},d=function(t){ce(e,l.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 r.jsxs(oe.Box,{className:le(),style:i({marginBottom:"1rem"},C.fieldContainer),children:[r.jsx(oe.Label,{className:le(),style:i({display:"block",fontWeight:"600",marginBottom:"0.5rem"},C.fieldLabel),children:n}),r.jsxs(oe.Box,{style:{display:"flex",flexWrap:"wrap",gap:"8px",alignItems:"center"},children:[l.map(function(e){return r.jsxs("span",{style:f,children:[e,r.jsx("button",{"aria-label":"Remove ".concat(e),onClick:function(){return d(e)},style:m,children:"×"})]},e)}),r.jsx(oe.Input,{type:"text",value:c,onChange:function(t){return te(function(r){return i(i({},r),{},a({},e,t.target.value))})},onKeyDown:function(e){"Enter"===e.key||","===e.key?(e.preventDefault(),u(c)):"Backspace"===e.key&&!c&&l.length&&d(l[l.length-1])},placeholder:o.placeholder||"Add tag and press Enter",className:le(),style:i({minWidth:"140px",flex:"0 1 auto"},C.input)}),r.jsx(oe.Button,{onClick:function(){return u(c)},className:le(),style:{padding:"6px 10px"},children:"Add"})]})]},e)},ve=function(e,t,n){return r.jsxs(oe.Box,{className:le(),style:i({marginBottom:"1rem"},C.fieldContainer),children:[r.jsxs(oe.Label,{className:le(),style:i({display:"block",fontWeight:"600",marginBottom:"0.5rem"},C.fieldLabel),children:[n," (Object)"]}),r.jsx(oe.Textarea,{value:JSON.stringify(t,null,2),onChange:function(t){try{var r=JSON.parse(t.target.value);ce(e,r)}catch(r){ce(e,t.target.value)}},className:le(),style:i({fontFamily:"monospace",minHeight:"100px",width:"100%"},C.textarea)})]},e)},je=function(e,t,n){return r.jsxs(oe.Box,{className:le(),style:i({marginBottom:"1rem"},C.fieldContainer),children:[r.jsx(oe.Label,{className:le(),style:i({display:"block",fontWeight:"600",marginBottom:"0.5rem"},C.fieldLabel),children:n}),r.jsx(oe.Input,{type:"text",value:M[e]||"",onChange:function(t){return ce(e,t.target.value)},className:le(),style:i({width:"100%"},C.input)})]},e)};return r.jsx(oe.Container,i(i({className:le(),style:C.container},J),{},{children:r.jsxs(oe.VStack,{className:le(),style:i({gap:"1rem"},C.stack),children:[Q&&r.jsx(oe.Alert,{className:le(),style:C.alert,children:r.jsx(oe.Text,{style:C.errorText,children:Q})}),Object.keys(M).length>0&&r.jsx(oe.Card,{className:le(),style:i({width:"100%",padding:"1rem"},C.formCard),children:function(){if(Array.isArray(W)&&W.length){var e=Object.keys(M),t=new Set,n=W.map(function(n,a){var o=n.id||"section-".concat(a),l=Array.isArray(n.fields)?n.fields:[];l.forEach(function(e){return t.add(e)});var s=l.filter(function(t){return e.includes(t)}),c=function(){if(A<=1)return r.jsx(oe.VStack,{style:{gap:"1rem"},children:s.map(function(e){return ue(e,M[e])})},o);for(var e=Math.ceil(s.length/A),t=[],n=0;n<A;n++){var a=n*e,l=Math.min(a+e,s.length);t.push(s.slice(a,l))}var c=i({display:"grid",gridTemplateColumns:"repeat(".concat(A,", 1fr)"),gap:"2rem",width:"100%"},C.formGrid);return r.jsx(oe.Box,{className:le(),style:c,children:t.map(function(e,t){return r.jsx(oe.VStack,{className:le(),style:i({gap:"1rem"},C.formColumn),children:e.map(function(e){return ue(e,M[e])})},t)})},o)}(),u=!(!n.defaultOpen&&n.collapsible),d=ne.has(o)?!u:u;return r.jsxs(oe.Box,{style:{marginBottom:"1.25rem"},children:[r.jsxs(oe.Box,{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"0.5rem"},children:[r.jsxs(oe.Box,{style:{display:"flex",alignItems:"center",gap:"8px"},children:[n.collapsible&&r.jsx("button",{"aria-label":"Toggle ".concat(n.title),onClick:function(){return ae(function(e){var t=new Set(e);return t.has(o)?t.delete(o):t.add(o),t})},style:{border:"none",background:"transparent",cursor:"pointer"},children:r.jsx("span",{children:d?"▼":"▶"})}),r.jsx(oe.Heading,{className:le(),style:{margin:0},children:n.title})]}),n.description&&r.jsx(oe.Text,{className:le(),style:{opacity:.8},children:n.description})]}),(!n.collapsible||d)&&c]},"wrap-".concat(o))}),a=null;if(P){var o=e.filter(function(e){return!t.has(e)});if(o.length){var s="unsectioned",c=!0,u=!ne.has(s)&&c;a=r.jsxs(oe.Box,{style:{marginBottom:"1.25rem"},children:[r.jsx(oe.Box,{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"0.5rem"},children:r.jsxs(oe.Box,{style:{display:"flex",alignItems:"center",gap:"8px"},children:[r.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:r.jsx("span",{children:u?"▼":"▶"})}),r.jsx(oe.Heading,{className:le(),style:{margin:0},children:F})]})}),u&&function(){if(A<=1)return r.jsx(oe.VStack,{style:{gap:"1rem"},children:o.map(function(e){return ue(e,M[e])})});for(var e=Math.ceil(o.length/A),t=[],n=0;n<A;n++){var a=n*e,l=Math.min(a+e,o.length);t.push(o.slice(a,l))}var s=i({display:"grid",gridTemplateColumns:"repeat(".concat(A,", 1fr)"),gap:"2rem",width:"100%"},C.formGrid);return r.jsx(oe.Box,{className:le(),style:s,children:t.map(function(e,t){return r.jsx(oe.VStack,{className:le(),style:i({gap:"1rem"},C.formColumn),children:e.map(function(e){return ue(e,M[e])})},t)})})}()]},"wrap-".concat(s))}}return r.jsxs(oe.VStack,{className:le(),style:i({gap:"1rem"},C.formStack),children:[n,a]})}var d=Object.entries(M);if(A<=1)return r.jsx(oe.VStack,{className:le(),style:i({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=i({display:"grid",gridTemplateColumns:"repeat(".concat(A,", 1fr)"),gap:"2rem",width:"100%"},C.formGrid);return r.jsx(oe.Box,{className:le(),style:y,children:m.map(function(e,t){return r.jsx(oe.VStack,{className:le(),style:i({gap:"1rem"},C.formColumn),children:e.map(function(e){var t=l(e,2),r=t[0],n=t[1];return ue(r,n)})},t)})})}()}),T&&Object.keys(M).length>0&&r.jsxs(oe.HStack,{className:le(),style:i({gap:"0.5rem",marginTop:"1rem"},C.controlButtons),children:[r.jsx(oe.Button,{onClick:function(){if(u){var e=f(M);u(e,M)}},className:le(),style:C.saveButton,children:v}),r.jsx(oe.Button,{onClick:function(){U(i({},$)),y&&y()},className:le(),style:C.cancelButton,children:k})]})]})}))};e.Fields=y,e.JsonFields=y,e.flattenObject=d,e.formatJson=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2;return JSON.stringify(e,null,t)},e.getDisplayName=g,e.getInputType=m,e.getNestedLevel=function(e){return e.split(".").length-1},e.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"===c(a)?a[r]||a.default||"":a},e.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"}},e.parseJsonSafely=p,e.unflattenObject=f});
//# sourceMappingURL=json-fields.umd.min.js.map