@sciphergfx/json-to-table
Version:
UI-agnostic React components for JSON to Table and JSON to Form Fields conversion with support for Chakra UI, Tailwind CSS, and shadcn/ui
3 lines (2 loc) • 22.8 kB
JavaScript
"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 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 a(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){n(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){if(null==e)return{};var r,n,o=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 a=Object.getOwnPropertySymbols(e);for(n=0;n<a.length;n++)r=a[n],-1===t.indexOf(r)&&{}.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}function i(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,o,a,l,i=[],s=!0,c=!1;try{if(a=(r=r.call(e)).next,0===t);else for(;!(s=(n=a.call(r)).done)&&(i.push(n.value),i.length!==t);s=!0);}catch(e){c=!0,o=e}finally{try{if(!s&&null!=r.return&&(l=r.return(),Object(l)!==l))return}finally{if(c)throw o}}return i}}(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 r(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 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 d=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"}},f=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 o=n[t];return"object"===c(o)?o[r]||o.default||"":o},m=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 o=t?"".concat(t,".").concat(n):n;"object"!==c(e[n])||null===e[n]||Array.isArray(e[n])?r[o]=e[n]:Object.assign(r,m(e[n],o))}return r},b=function(e){var t={};for(var r in e){for(var n=r.split("."),o=t,a=0;a<n.length-1;a++)o[n[a]]||(o[n[a]]={}),o=o[n[a]];o[n[n.length-1]]=e[r]}return t},g=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 a({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"}},x=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()},y=["uiLibrary","onSave","onCancel","onFieldChange","saveButtonText","cancelButtonText","initialJson","customStyles","showControls"],v=["uiLibrary","onSave","onCancel","onFieldChange","saveButtonText","cancelButtonText","initialJson","customStyles","showControls","showJsonInput","columns","fieldConfig"];exports.JsonToFields=function(r){var o=r.uiLibrary,c=void 0===o?"chakra":o,u=r.onSave,d=r.onCancel,y=r.onFieldChange,h=r.saveButtonText,j=void 0===h?"Save Changes":h,S=r.cancelButtonText,T=void 0===S?"Reset Form":S,w=r.initialJson,k=void 0===w?"":w,B=r.customStyles,N=void 0===B?{}:B,C=r.showControls,O=void 0===C||C,L=r.showJsonInput,I=void 0===L||L,A=r.columns,J=void 0===A?1:A,H=r.fieldConfig,F=void 0===H?{}:H,P=l(r,v),V=i(e.useState(k),2),G=V[0],E=V[1],W=i(e.useState({}),2),D=W[0],U=W[1],M=i(e.useState({}),2),$=M[0],_=M[1],q=i(e.useState(null),2)[1],z=i(e.useState(""),2),R=z[0],X=z[1],Z={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.useEffect(function(){k?(E(k),K(k)):""===k&&(E(""),U({}),_({}),q(null),X(""))},[k]);var K=function(){var e=x(arguments.length>0&&void 0!==arguments[0]?arguments[0]:G);if(e.success){q(e.data);var t=m(e.data);U(t),_(a({},t)),X("")}else X(e.error),q(null),U({}),_({})},Q=function(e,t){var r=a(a({},D),{},n({},e,t));if(U(r),y){var o=b(r);y(e,t,o)}},Y=function(e,t){var r=g(t,e,F),n=p(e);switch(r.type){case"checkbox":return ee(e,t,n);case"select":return te(e,t,n,r);case"multi-select":return re(e,t,n,r);case"textarea":return ne(e,t,n,r);case"email":case"url":case"date":case"password":return oe(e,t,n,r);case"number":return ae(e,t,n);case"array":return le(e,t,n);case"object":return ie(e,t,n);default:return se(e,t,n)}},ee=function(e,r,n,o){return t.jsx(Z.Box,{className:f(c,"Box"),style:a({marginBottom:"1rem"},N.fieldContainer),children:t.jsxs(Z.Label,{className:f(c,"Label"),style:a({display:"flex",alignItems:"center",gap:"0.5rem",cursor:"pointer"},N.label),children:[t.jsx("input",{type:"checkbox",checked:D[e]||!1,onChange:function(t){return Q(e,t.target.checked)},className:f(c,"Input","checkbox"),style:N.checkbox}),t.jsx(Z.Text,{className:f(c,"Text"),style:a({fontWeight:"500"},N.fieldLabel),children:n})]})},e)},te=function(e,r,n,o){var l;return t.jsxs(Z.Box,{className:f(c,"Box"),style:a({marginBottom:"1rem"},N.fieldContainer),children:[t.jsx(Z.Label,{className:f(c,"Label"),style:a({display:"block",fontWeight:"600",marginBottom:"0.5rem"},N.fieldLabel),children:n}),t.jsxs(Z.Select,{value:D[e]||"",onChange:function(t){return Q(e,t.target.value)},className:f(c,"Select"),style:a({width:"100%"},N.select),children:[t.jsxs("option",{value:"",children:["Select ",n]}),null===(l=o.options)||void 0===l?void 0:l.map(function(e){return t.jsx("option",{value:e,children:e},e)})]})]},e)},re=function(e,r,n,o){var l,i=Array.isArray(D[e])?D[e]:[];return t.jsxs(Z.Box,{className:f(c,"Box"),style:a({marginBottom:"1rem"},N.fieldContainer),children:[t.jsx(Z.Label,{className:f(c,"Label"),style:a({display:"block",fontWeight:"600",marginBottom:"0.5rem"},N.fieldLabel),children:n}),t.jsx(Z.Box,{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},children:null===(l=o.options)||void 0===l?void 0:l.map(function(r){return t.jsxs(Z.Label,{style:{display:"flex",alignItems:"center",gap:"0.5rem",cursor:"pointer"},children:[t.jsx("input",{type:"checkbox",checked:i.includes(r),onChange:function(t){var n=t.target.checked?[].concat(s(i),[r]):i.filter(function(e){return e!==r});Q(e,n)},style:N.checkbox}),t.jsx(Z.Text,{style:a({fontSize:"14px"},N.text),children:r})]},r)})})]},e)},ne=function(e,r,n,o){return t.jsxs(Z.Box,{className:f(c,"Box"),style:a({marginBottom:"1rem"},N.fieldContainer),children:[t.jsx(Z.Label,{className:f(c,"Label"),style:a({display:"block",fontWeight:"600",marginBottom:"0.5rem"},N.fieldLabel),children:n}),t.jsx(Z.Textarea,{value:D[e]||"",onChange:function(t){return Q(e,t.target.value)},className:f(c,"Textarea"),style:a({width:"100%",minHeight:"".concat(1.5*(o.rows||4),"rem")},N.textarea)})]},e)},oe=function(e,r,n,o){return t.jsxs(Z.Box,{className:f(c,"Box"),style:a({marginBottom:"1rem"},N.fieldContainer),children:[t.jsx(Z.Label,{className:f(c,"Label"),style:a({display:"block",fontWeight:"600",marginBottom:"0.5rem"},N.fieldLabel),children:n}),t.jsx(Z.Input,{type:o.type,value:D[e]||"",onChange:function(t){return Q(e,t.target.value)},className:f(c,"Input"),style:a({width:"100%"},N.input)})]},e)},ae=function(e,r,n,o){return t.jsxs(Z.Box,{className:f(c,"Box"),style:a({marginBottom:"1rem"},N.fieldContainer),children:[t.jsx(Z.Label,{className:f(c,"Label"),style:a({display:"block",fontWeight:"600",marginBottom:"0.5rem"},N.fieldLabel),children:n}),t.jsx(Z.Input,{type:"number",value:D[e]||"",onChange:function(t){var r=parseFloat(t.target.value)||0;Q(e,r)},className:f(c,"Input"),style:a({width:"100%"},N.input)})]},e)},le=function(e,r,n,o){return t.jsxs(Z.Box,{className:f(c,"Box"),style:a({marginBottom:"1rem"},N.fieldContainer),children:[t.jsxs(Z.Label,{className:f(c,"Label"),style:a({display:"block",fontWeight:"600",marginBottom:"0.5rem"},N.fieldLabel),children:[n," (Array)"]}),t.jsx(Z.Textarea,{value:JSON.stringify(r,null,2),onChange:function(t){try{var r=JSON.parse(t.target.value);Q(e,r)}catch(r){Q(e,t.target.value)}},className:f(c,"Textarea"),style:a({fontFamily:"monospace",minHeight:"100px",width:"100%"},N.textarea)})]},e)},ie=function(e,r,n,o){return t.jsxs(Z.Box,{className:f(c,"Box"),style:a({marginBottom:"1rem"},N.fieldContainer),children:[t.jsxs(Z.Label,{className:f(c,"Label"),style:a({display:"block",fontWeight:"600",marginBottom:"0.5rem"},N.fieldLabel),children:[n," (Object)"]}),t.jsx(Z.Textarea,{value:JSON.stringify(r,null,2),onChange:function(t){try{var r=JSON.parse(t.target.value);Q(e,r)}catch(r){Q(e,t.target.value)}},className:f(c,"Textarea"),style:a({fontFamily:"monospace",minHeight:"100px",width:"100%"},N.textarea)})]},e)},se=function(e,r,n,o){return t.jsxs(Z.Box,{className:f(c,"Box"),style:a({marginBottom:"1rem"},N.fieldContainer),children:[t.jsx(Z.Label,{className:f(c,"Label"),style:a({display:"block",fontWeight:"600",marginBottom:"0.5rem"},N.fieldLabel),children:n}),t.jsx(Z.Input,{type:"text",value:D[e]||"",onChange:function(t){return Q(e,t.target.value)},className:f(c,"Input"),style:a({width:"100%"},N.input)})]},e)};return t.jsx(Z.Container,a(a({className:f(c,"Container"),style:N.container},P),{},{children:t.jsxs(Z.VStack,{className:f(c,"VStack"),style:a({gap:"1rem"},N.stack),children:[I&&t.jsx(t.Fragment,{children:t.jsx(Z.Box,{className:f(c,"Box"),style:a({width:"100%"},N.inputContainer),children:t.jsx(Z.Textarea,{value:G,onChange:function(e){return E(e.target.value)},placeholder:"Paste your JSON data here...",className:f(c,"Textarea"),style:a({minHeight:"150px",fontFamily:"monospace"},N.textarea)})})}),R&&t.jsx(Z.Alert,{className:f(c,"Alert","error"),style:N.alert,children:t.jsx(Z.Text,{style:N.errorText,children:R})}),Object.keys(D).length>0&&t.jsx(Z.Card,{className:f(c,"Card"),style:a({width:"100%",padding:"1rem"},N.formCard),children:function(){var e=Object.entries(D);if(J<=1)return t.jsx(Z.VStack,{className:f(c,"VStack"),style:a({gap:"1rem"},N.formStack),children:e.map(function(e){var t=i(e,2),r=t[0],n=t[1];return Y(r,n)})});for(var r=Math.ceil(e.length/J),n=[],o=0;o<J;o++){var l=o*r,s=Math.min(l+r,e.length);n.push(e.slice(l,s))}var u=a({display:"grid",gridTemplateColumns:"repeat(".concat(J,", 1fr)"),gap:"2rem",width:"100%"},N.formGrid);return t.jsx(Z.Box,{className:f(c,"Box"),style:u,children:n.map(function(e,r){return t.jsx(Z.VStack,{className:f(c,"VStack"),style:a({gap:"1rem"},N.formColumn),children:e.map(function(e){var t=i(e,2),r=t[0],n=t[1];return Y(r,n)})},r)})})}()}),O&&Object.keys(D).length>0&&t.jsxs(Z.HStack,{className:f(c,"HStack"),style:a({gap:"0.5rem",marginTop:"1rem"},N.controlButtons),children:[t.jsx(Z.Button,{onClick:function(){if(u){var e=b(D);u(e,D)}},className:f(c,"Button","default"),style:N.saveButton,children:j}),t.jsx(Z.Button,{onClick:function(){U(a({},$)),d&&d()},className:f(c,"Button","secondary"),style:N.cancelButton,children:T})]})]})}))},exports.JsonToTable=function(r){var n=r.uiLibrary,o=void 0===n?"chakra":n,u=r.onSave,d=r.onCancel,m=r.onFieldChange,b=r.saveButtonText,g=void 0===b?"Save Changes":b,x=r.cancelButtonText,v=void 0===x?"Reset Form":x,h=r.initialJson,j=void 0===h?"":h,S=r.customStyles,T=void 0===S?{}:S,w=r.showControls,k=void 0===w||w,B=l(r,y),N=i(e.useState(j),2),C=N[0],O=N[1],L=i(e.useState(null),2),I=L[0],A=L[1],J=i(e.useState(""),2),H=J[0],F=J[1],P=i(e.useState(null),2),V=P[0],G=P[1],E={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.useEffect(function(){j?(O(j),W(j)):""===j&&(O(""),A(null),G(null),F(""))},[j]);var W=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:C;if(F(""),A(null),e.trim())try{var t=JSON.parse(e);if(Array.isArray(t)){if(0===t.length)return void F("The JSON array is empty");A(t),G(s(t))}else{if("object"!==c(t)||null===t)return void F("JSON must be an object or array of objects");var r=[t];A(r),G([].concat(r))}}catch(e){F("Invalid JSON: ".concat(e.message))}else F("Please enter some JSON data")};return t.jsx(E.Container,a(a({className:f(o,"Container"),style:T.container},B),{},{children:t.jsxs(E.VStack,{className:f(o,"VStack"),style:a({gap:"1rem"},T.stack),children:[t.jsx(E.Box,{className:f(o,"Box"),style:a({width:"100%"},T.inputContainer),children:t.jsx(E.Textarea,{value:C,onChange:function(e){return O(e.target.value)},placeholder:"Paste your JSON data here...",className:f(o,"Textarea"),style:a({width:"100%",minHeight:"150px",fontFamily:"monospace"},T.textarea)})}),H&&t.jsx(E.Alert,{className:f(o,"Alert","error"),style:T.alert,children:t.jsx(E.Text,{style:T.errorText,children:H})}),function(){if(!V||0===V.length)return null;var e=function(){if(!I||0===I.length)return[];var e=new Set;return I.forEach(function(t){Object.keys(t).forEach(function(t){return e.add(t)})}),Array.from(e)}();return t.jsx(E.Box,{className:f(o,"Box"),style:a({overflowX:"auto"},T.tableContainer),children:t.jsxs(E.Table,{className:f(o,"Table"),style:T.table,children:[t.jsx(E.Thead,{className:f(o,"Thead"),children:t.jsx(E.Tr,{className:f(o,"Tr"),children:e.map(function(e){return t.jsx(E.Th,{className:f(o,"Th"),style:a({textAlign:"center"},T.th),children:p(e)},e)})})}),t.jsx(E.Tbody,{className:f(o,"Tbody"),children:V.map(function(r,n){return t.jsx(E.Tr,{className:f(o,"Tr"),children:e.map(function(e){return t.jsx(E.Td,{className:f(o,"Td"),style:T.td,children:t.jsx(E.Input,{type:"text",value:r[e]||"",onChange:function(t){return function(e,t,r){var n=s(V);n[e][t]=r,G(n),m&&m(t,r,n)}(n,e,t.target.value)},className:f(o,"Input"),style:a({border:"none",background:"transparent"},T.input)})},e)})},n)})})]})})}(),k&&V&&t.jsxs(E.HStack,{gap:"2",className:f(o,"HStack"),style:a({gap:"0.5rem",marginTop:"1rem"},T.controlButtons),children:[t.jsx(E.Button,{onClick:function(){if(u&&V){var e=V.map(function(e){return a({},e)});u(V,e)}},className:f(o,"Button","default"),style:T.saveButton,children:g}),t.jsx(E.Button,{onClick:function(){I&&G(s(I)),d&&d()},className:f(o,"Button","secondary"),style:T.cancelButton,children:v})]})]})}))},exports.flattenObject=m,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=g,exports.getNestedLevel=function(e){return e.split(".").length-1},exports.getUIClasses=f,exports.getUIComponents=d,exports.parseJsonSafely=x,exports.unflattenObject=b;
//# sourceMappingURL=index.js.map