@firecms/collection_editor 3.0.0-beta.1 → 3.0.0-beta.2-pre.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.umd.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(q,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("react/jsx-runtime"),require("@firecms/core"),require("react"),require("react-fast-compare"),require("@firecms/ui"),require("formik"),require("yup"),require("@firecms/schema_inference"),require("@hello-pangea/dnd"),require("json5"),require("prism-react-renderer"),require("@firecms/data_import_export"),require("react-router")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","@firecms/core","react","react-fast-compare","@firecms/ui","formik","yup","@firecms/schema_inference","@hello-pangea/dnd","json5","prism-react-renderer","@firecms/data_import_export","react-router"],e):(q=typeof globalThis<"u"?globalThis:q||self,e(q.FireCMS={},q.jsxRuntime,q.core,q.React,q.equal,q.ui,q.formik,q.Yup,q.schema_inference,q.dnd,q.JSON5,q.prismReactRenderer,q.data_import_export,q.reactRouter))})(this,function(q,e,i,C,xe,t,g,cr,De,_e,pr,ze,se,hr){"use strict";function Ue(r){const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const l in r)if(l!=="default"){const o=Object.getOwnPropertyDescriptor(r,l);Object.defineProperty(a,l,o.get?o:{enumerable:!0,get:()=>r[l]})}}return a.default=r,Object.freeze(a)}const me=Ue(C),Fe=Ue(cr),fr=Fe.object().shape({id:Fe.string().required("Required"),name:Fe.string().required("Required"),path:Fe.string().required("Required")});function H({error:r,children:a}){return a?e.jsx(t.Typography,{variant:"caption",color:r?"error":"secondary",className:"ml-3.5 mt-0.5",children:a}):null}function gr({isNewCollection:r,reservedGroups:a,existingPaths:l,existingIds:o,groups:s,parentCollection:n}){const d=C.useRef(null),{values:h,setFieldValue:f,handleChange:u,touched:c,errors:p,setFieldTouched:T,isSubmitting:m,submitCount:b}=g.useFormikContext(),[N,F]=C.useState(!1),[w,y]=C.useState(!1),P=O=>{f("name",O),!g.getIn(c,"path")&&r&&O&&f("path",i.toSnakeCase(O)),!g.getIn(c,"id")&&r&&O&&f("id",i.toSnakeCase(O)),!g.getIn(c,"singularName")&&r&&O&&f("singularName",i.singular(O))};C.useEffect(()=>{p.id&&y(!0)},[p.id]);const x=e.jsx(i.IconForView,{collectionOrView:h}),v=s?.filter(O=>!a?.includes(O)),{inputFocused:E,autoCompleteOpen:U,setAutoCompleteOpen:D}=t.useAutoComplete({ref:d}),V=!!n;let L;return e.jsx("div",{className:"overflow-auto my-auto",children:e.jsxs(t.Container,{maxWidth:"4xl",className:"flex flex-col gap-4 p-8 m-auto",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-row py-2 pt-3 items-center",children:[e.jsx(t.Typography,{variant:r?"h4":"h5",className:"flex-grow",children:r?"New collection":`${h?.name} collection`}),e.jsx(t.Tooltip,{title:"Change icon",children:e.jsx(t.IconButton,{shape:"square",onClick:()=>F(!0),children:x})})]}),n&&e.jsx(t.Chip,{colorScheme:"tealDarker",children:e.jsxs(t.Typography,{variant:"caption",children:["This is a subcollection of ",e.jsx("b",{children:n.name})]})})]}),e.jsxs("div",{className:"grid grid-cols-12 gap-4",children:[e.jsxs("div",{className:"col-span-12",children:[e.jsx(t.TextField,{value:h.name??"",onChange:O=>P(O.target.value),label:"Name",required:!0,error:c.name&&!!p.name}),e.jsx(H,{error:c.name&&!!p.name,children:c.name&&p.name?p.name:"Name of in this collection, usually a plural name (e.g. Products)"})]}),e.jsxs("div",{className:t.cn("col-span-12 ",V?"":"sm:col-span-8"),children:[e.jsx(g.Field,{name:"path",as:t.DebouncedTextField,label:"Path",disabled:!r,required:!0,error:c.path&&!!p.path}),e.jsx(H,{error:c.path&&!!p.path,children:c.path&&p.path?p.path:V?"Relative path to the parent (no need to include the parent path)":"Path that this collection is stored in, in the database"})]}),!V&&e.jsxs("div",{className:"col-span-12 sm:col-span-4 relative",children:[e.jsx(t.TextField,{error:c.group&&!!p.group,disabled:m,value:h.group??"",autoComplete:"off",onChange:O=>f("group",O.target.value),name:"group",inputRef:d,label:"Group"}),e.jsx(t.Autocomplete,{open:U&&(v??[]).length>0,setOpen:D,children:v?.map((O,S)=>e.jsx(t.AutocompleteItem,{onClick:()=>{D(!1),f("group",O??null)},children:e.jsx("div",{className:"flex-grow",children:O})},S+"_"+O))}),e.jsx(H,{children:c.group&&p.group?p.group:"Group of the collection"})]}),e.jsx("div",{className:"col-span-12",children:e.jsx(t.ExpandablePanel,{expanded:w,onExpandedChange:y,title:e.jsxs("div",{className:"flex flex-row text-gray-500",children:[e.jsx(t.SettingsIcon,{}),e.jsx(t.Typography,{variant:"subtitle2",className:"ml-2",children:"Advanced"})]}),initiallyExpanded:!1,children:e.jsxs("div",{className:"grid grid-cols-12 gap-4 p-4",children:[e.jsxs("div",{className:"col-span-12",children:[e.jsx(g.Field,{name:"id",as:t.DebouncedTextField,disabled:!r,label:"Collection id",error:c.id&&!!p.id}),e.jsx(H,{error:c.id&&!!p.id,children:c.id&&p.id?p.id:"This id identifies this collection"})]}),e.jsxs("div",{className:"col-span-12",children:[e.jsx(t.TextField,{error:c.singularName&&!!p.singularName,id:"singularName","aria-describedby":"singularName-helper",onChange:O=>(T("singularName",!0),u(O)),value:h.singularName??"",label:"Singular name"}),e.jsx(H,{error:c.singularName&&!!p.singularName,children:c.singularName&&p.singularName?p.singularName:"Optionally define a singular name for your entities"})]}),e.jsxs("div",{className:"col-span-12",children:[e.jsx(t.TextField,{error:c.description&&!!p.description,id:"description",value:h.description??"",onChange:u,multiline:!0,rows:2,"aria-describedby":"description-helper-text",label:"Description"}),e.jsx(H,{error:c.description&&!!p.description,children:c.description&&p.description?p.description:"Description of the collection, you can use markdown"})]}),e.jsx("div",{className:"col-span-12",children:e.jsx(t.Select,{name:"defaultSize",label:"Default row size",position:"item-aligned",onChange:u,value:h.defaultSize??"",renderValue:O=>O.toUpperCase(),children:["xs","s","m","l","xl"].map(O=>e.jsx(t.SelectItem,{value:O,children:O.toUpperCase()},`size-select-${O}`))})}),e.jsx("div",{className:"col-span-12",children:e.jsxs(t.Select,{name:"customId",label:"Data IDs generation",position:"item-aligned",disabled:L==="code_defined",onValueChange:O=>{if(O==="code_defined")throw new Error("This should not happen");O==="true"?f("customId",!0):O==="false"?f("customId",!1):O==="optional"&&f("customId","optional")},value:"",renderValue:O=>O==="code_defined"?"Code defined":O==="true"?"Users must define an ID":O==="optional"?"Users can define an ID, but it is not required":"Document ID is generated automatically",children:[e.jsx(t.SelectItem,{value:"false",children:"Document ID is generated automatically"}),e.jsx(t.SelectItem,{value:"true",children:"Users must define an ID"}),e.jsx(t.SelectItem,{value:"optional",children:"Users can define an ID, but it is not required"})]})}),e.jsxs("div",{className:"col-span-12",children:[e.jsx(t.BooleanSwitchWithLabel,{position:"start",label:"Collection group",onValueChange:O=>f("collectionGroup",O),value:h.collectionGroup??!1}),e.jsx(H,{children:"A collection group consists of all collections with the same path. This allows you to query over multiple collections at once."})]}),e.jsxs("div",{className:"col-span-12",children:[e.jsx(t.BooleanSwitchWithLabel,{position:"start",label:"Enable text search for this collection",onValueChange:O=>f("textSearchEnabled",O),value:h.textSearchEnabled??!1}),e.jsx(H,{children:"Allow text search for this collection. If you have not specified a text search delegate, this will use the built-in local text search. This is not recommended for large collections, as it may incur in performance and cost issues."})]})]})})})]}),e.jsx("div",{style:{height:"52px"}}),e.jsx(t.Dialog,{open:N,onOpenChange:F,maxWidth:"xl",fullWidth:!0,children:e.jsx("div",{className:"p-4 overflow-auto min-h-[200px]",children:e.jsx(i.SearchIconsView,{selectedIcon:h.icon,onIconSelected:O=>{F(!1),f("icon",O)}})})})]})})}function te(r){return"properties."+r.replaceAll(".",".properties.")}function qe(r){return r?"properties."+r.replaceAll(".",".properties.")+".properties":"properties"}function oe(r){return r?"properties."+r.replaceAll(".",".properties.")+".propertiesOrder":"propertiesOrder"}function K(r,a){return a?`${a}.${r}`:r}const ur=C.memo(function({enumValues:a,onValuesChanged:l,onError:o,updateIds:s,disabled:n,allowDataInference:d,getData:h}){return e.jsx(g.Formik,{initialValues:{enumValues:a},validateOnMount:!0,onSubmit:(f,u)=>{},children:({values:f,errors:u})=>(C.useEffect(()=>{l&&l(f.enumValues)},[f.enumValues]),C.useEffect(()=>{o&&o(!!(u?.enumValues??!1))},[u]),e.jsx(yr,{enumValuesPath:"enumValues",values:f,errors:u,shouldUpdateId:s,disabled:n,allowDataInference:d,getData:h}))})},function(a,l){return a.enumValues.length===l.enumValues.length&&a.onValuesChanged===l.onValuesChanged&&a.getData===l.getData});function yr({values:r,errors:a,disabled:l,enumValuesPath:o,shouldUpdateId:s,allowDataInference:n,getData:d}){const{setFieldValue:h}=g.useFormikContext(),[f,u]=C.useState(),[c,p]=C.useState(),[T,m]=C.useState(!1),N=C.useRef(new Set).current,F=(y,P)=>{const x=f===P;return e.jsx(vr,{index:y,disabled:l,enumValuesPath:o,autoFocus:x,shouldUpdateId:s||x,onDialogOpen:()=>p(y),inferredEntry:N.has(r.enumValues[y]?.id)},`${P}`)},w=async()=>{d&&(m(!0),d?.().then(y=>{if(!y)return;const P=y.flat(),x=Array.from(new Set(P)),v=r.enumValues,U=De.extractEnumFromValues(x).filter(D=>!v?.some(V=>V.id===D.id));U.forEach(D=>{N.add(D.id)}),h(o,[...U,...v])}).catch(y=>{console.error(y)}).finally(()=>m(!1)))};return e.jsxs("div",{className:"col-span-12",children:[e.jsxs("div",{className:"ml-3.5 flex flex-row items-center",children:[e.jsx(t.ListIcon,{}),e.jsx(t.Typography,{variant:"subtitle2",className:"ml-2 grow",children:"Values"}),n&&e.jsxs(t.Button,{loading:T,disabled:l||T,variant:"text",size:"small",onClick:w,children:[T?e.jsx(t.CircularProgress,{size:"small"}):e.jsx(t.AutoAwesomeIcon,{}),"Infer values from data"]})]}),e.jsxs(t.Paper,{className:"p-4 m-1",children:[e.jsx(i.FormikArrayContainer,{value:r.enumValues,addLabel:"Add enum value",name:o,buildEntry:F,disabled:l,onInternalIdAdded:u,small:!0,setFieldValue:h,includeAddButton:!0}),e.jsx(mr,{index:c,open:c!==void 0,enumValuesPath:o,onClose:()=>p(void 0)})]})]})}const vr=C.memo(function({index:a,shouldUpdateId:l,enumValuesPath:o,autoFocus:s,onDialogOpen:n,disabled:d,inferredEntry:h}){const{values:f,handleChange:u,errors:c,setFieldValue:p,touched:T}=g.useFormikContext(),m=C.useRef(!g.getIn(f,`${o}[${a}].id`)),b=l||m.current,N=g.getIn(f,`${o}[${a}].id`),F=g.getIn(f,`${o}[${a}].label`),w=g.getIn(c,`${o}[${a}].label`),y=C.useRef(F);return C.useEffect(()=>{(y.current===N||!N)&&b&&p(`${o}[${a}].id`,F),y.current=F},[F]),e.jsxs("div",{className:"flex w-full align-center justify-center",children:[e.jsx(g.FastField,{name:`${o}[${a}].label`,as:t.DebouncedTextField,className:"flex-grow",required:!0,disabled:d,size:"small",validate:br,autoFocus:s,autoComplete:"off",endAdornment:h&&e.jsx(t.AutoAwesomeIcon,{size:"small"}),error:!!w}),!d&&e.jsx(t.IconButton,{size:"small","aria-label":"edit",className:"m-1",onClick:()=>n(),children:e.jsx(t.SettingsIcon,{size:"small"})})]})},function(a,l){return a.index===l.index&&a.enumValuesPath===l.enumValuesPath&&a.shouldUpdateId===l.shouldUpdateId&&a.inferredEntry===l.inferredEntry&&a.autoFocus===l.autoFocus});function mr({index:r,open:a,onClose:l,enumValuesPath:o}){const{values:s,handleChange:n,errors:d,setFieldValue:h,touched:f}=g.useFormikContext(),u=r!==void 0?g.getIn(d,`${o}[${r}].id`):void 0;return e.jsxs(t.Dialog,{maxWidth:"md","aria-labelledby":"enum-edit-dialog",open:a,onOpenChange:c=>c?void 0:l(),children:[e.jsx(t.DialogContent,{children:r!==void 0&&e.jsxs("div",{children:[e.jsx(g.FastField,{name:`${o}[${r}]id`,as:t.DebouncedTextField,required:!0,validate:Cr,label:"ID",size:"small",autoComplete:"off",error:!!u}),e.jsx(H,{error:!!u,children:u??"Value saved in the data source"})]})}),e.jsx(t.DialogActions,{children:e.jsx(t.Button,{autoFocus:!0,variant:"outlined",onClick:l,color:"primary",children:"Ok"})})]})}function br(r){let a;return r||(a="You must specify a label"),a}function Cr(r){let a;return r||(a="You must specify an ID"),a}function fe({disabled:r}){const{values:a,handleChange:l}=g.useFormikContext(),o="validation.required",s="validation.requiredMessage",n="validation.unique";return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"col-span-6",children:e.jsx(g.FastField,{type:"checkbox",disabled:r,name:o,label:"Required",tooltip:"You won't be able to save this entity if this value is not set",component:i.SwitchControl})}),e.jsx("div",{className:"col-span-6",children:e.jsx(g.FastField,{type:"checkbox",disabled:r,name:n,label:"Unique",tooltip:"There cannot be multiple entities with the same value",component:i.SwitchControl})}),g.getIn(a,o)&&e.jsx("div",{className:"col-span-12",children:e.jsx(t.DebouncedTextField,{disabled:r,value:g.getIn(a,s),label:"Required message",name:s,size:"small",onChange:l})})]})}function be({length:r,lowercase:a,matches:l,max:o,min:s,trim:n,uppercase:d,disabled:h,showErrors:f}){const{values:u,handleChange:c,errors:p}=g.useFormikContext(),T="validation.length",m="validation.min",b="validation.max",N="validation.trim",F="validation.matches",w="validation.lowercase",y="validation.uppercase",P=g.getIn(p,F),x=g.getIn(u,F),v=typeof x=="string"?x:i.serializeRegExp(x);return e.jsxs("div",{className:"grid grid-cols-12 gap-2",children:[e.jsx(fe,{disabled:h}),e.jsxs("div",{className:"grid grid-cols-12 gap-2 col-span-12",children:[a&&e.jsx("div",{className:"col-span-4",children:e.jsx(g.FastField,{type:"checkbox",name:w,label:"Lowercase",disabled:h,component:i.SwitchControl})}),d&&e.jsx("div",{className:"col-span-4",children:e.jsx(g.FastField,{type:"checkbox",name:y,label:"Uppercase",disabled:h,component:i.SwitchControl})}),n&&e.jsx("div",{className:"col-span-4",children:e.jsx(g.FastField,{type:"checkbox",name:N,label:"Trim",disabled:h,component:i.SwitchControl})})]}),e.jsxs("div",{className:"grid grid-cols-12 gap-2 col-span-12",children:[r&&e.jsx("div",{className:"col-span-4",children:e.jsx(t.DebouncedTextField,{value:g.getIn(u,T),label:"Exact length",name:T,type:"number",size:"small",disabled:h,onChange:c})}),s&&e.jsx("div",{className:"col-span-4",children:e.jsx(t.DebouncedTextField,{value:g.getIn(u,m),label:"Min length",name:m,type:"number",size:"small",disabled:h,onChange:c})}),o&&e.jsx("div",{className:"col-span-4",children:e.jsx(t.DebouncedTextField,{value:g.getIn(u,b),label:"Max length",name:b,type:"number",size:"small",disabled:h,onChange:c})})]}),l&&e.jsxs("div",{className:"col-span-12",children:[e.jsx(g.FastField,{name:F,as:t.DebouncedTextField,validate:E=>E&&!i.isValidRegExp(E),label:"Matches regex",size:"small",disabled:h,value:v,error:!!P}),e.jsx(H,{error:!!P,children:P?"Not a valid regexp":"e.g. /^\\d+$/ for digits only"})]})]})}function ke({max:r=!0,min:a=!0,disabled:l}){const{values:o,handleChange:s}=g.useFormikContext(),n="validation.min",d="validation.max";return e.jsxs("div",{className:"grid grid-cols-12 gap-2",children:[e.jsx(fe,{disabled:l}),a&&e.jsx("div",{className:"col-span-6",children:e.jsx(t.DebouncedTextField,{value:g.getIn(o,n),disabled:l,label:"Min length",name:n,type:"number",size:"small",onChange:s})}),r&&e.jsx("div",{className:"col-span-6",children:e.jsx(t.DebouncedTextField,{value:g.getIn(o,d),disabled:l,label:"Max length",name:d,type:"number",size:"small",onChange:s})})]})}function ie({children:r}){return e.jsx(t.ExpandablePanel,{initiallyExpanded:!1,asField:!0,className:"p-4",title:e.jsxs("div",{className:"flex flex-row text-gray-500",children:[e.jsx(t.RuleIcon,{}),e.jsx(t.Typography,{variant:"subtitle2",className:"ml-2",children:"Validation"})]}),children:r})}function Le({multiselect:r,updateIds:a,disabled:l,showErrors:o,allowDataInference:s,getData:n}){const{values:d,handleChange:h,errors:f,touched:u,setFieldError:c,setFieldValue:p}=g.useFormikContext(),T=i.useSnackbarController(),m=r?"of.enumValues":"enumValues",b=g.getIn(d,"defaultValue"),N=g.getIn(d,m),F=C.useMemo(()=>!N||typeof N=="boolean"?[]:i.resolveEnumValues(N)??[],[N]),w=y=>{if(d&&(p(m,y),!r)){const P=y.filter(x=>!!x?.id).map(x=>x.id);b&&!P.includes(b)&&(p("defaultValue",void 0),T.open({type:"warning",message:"Default value was cleared"}))}};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"col-span-12",children:e.jsx(ur,{enumValues:F,updateIds:a,disabled:l,allowDataInference:s,onError:y=>{c(m,y?"":void 0)},getData:n?()=>n().then(y=>y.map(P=>d.id&&g.getIn(P,d.id)).filter(Boolean)):void 0,onValuesChanged:w})}),e.jsx("div",{className:"col-span-12",children:e.jsxs(ie,{children:[!r&&e.jsx(be,{disabled:l,showErrors:o}),r&&e.jsx(ke,{disabled:l})]})}),!r&&e.jsx("div",{className:"col-span-12",children:e.jsx(t.Select,{disabled:l,position:"item-aligned",onValueChange:y=>{p("defaultValue",y)},label:"Default value",value:b??"",children:F.filter(y=>!!y?.id).map(y=>e.jsx(t.SelectItem,{value:y.id?.toString(),children:y.label},y.id))})})]})}const Ne={"image/*":"Images","video/*":"Videos","audio/*":"Audio files","application/*":"Files (pdf, zip, csv, excel...)","text/*":"Text files"};function $e({multiple:r,existing:a,disabled:l}){const{values:o,setFieldValue:s}=g.useFormikContext(),n=r?"of.storage":"storage",d=`${n}.acceptedFiles`,h=`${n}.fileName`,f=`${n}.storagePath`,u=`${n}.storeUrl`,c=g.getIn(o,h)??"{rand}_{file}",p=g.getIn(o,f)??"/",T=g.getIn(o,d),m=Array.isArray(T)?T:void 0,b=!m||m.length===0,N=y=>{y?y.includes("all")||y.length>=Object.keys(Ne).length?s(d,void 0):b?s(d,Object.keys(Ne).filter(P=>!y.includes(P))):s(d,y):s(d,void 0)},F=typeof c=="function",w=typeof p=="function";return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"col-span-12",children:e.jsx(t.ExpandablePanel,{title:e.jsxs("div",{className:"flex flex-row text-gray-500",children:[e.jsx(t.FileUploadIcon,{}),e.jsx(t.Typography,{variant:"subtitle2",className:"ml-2",children:"File upload config"})]}),children:e.jsxs("div",{className:"grid grid-cols-12 gap-2 p-4",children:[e.jsx("div",{className:"col-span-12",children:e.jsxs(t.MultiSelect,{disabled:l,name:d,value:m??[],onMultiValueChange:N,label:b?void 0:"Allowed file types",renderValues:y=>!y||y.length===0?"All file types allowed":y.map(P=>Ne[P]).filter(P=>!!P).join(", "),children:[e.jsxs(t.MultiSelectItem,{value:"all",className:"flex items-center gap-2",children:[e.jsx(t.Checkbox,{checked:!m}),"All"]},"all"),Object.entries(Ne).map(([y,P])=>e.jsxs(t.MultiSelectItem,{value:y,className:"flex items-center gap-2",children:[e.jsx(t.Checkbox,{checked:b||m.indexOf(y)>-1}),e.jsx("div",{className:"flex-grow",children:P}),e.jsx(t.Button,{size:"small",variant:"outlined",onClick:x=>(x.preventDefault(),x.stopPropagation(),s(d,[y])),children:"Only"})]},y))]})}),e.jsx("div",{className:"col-span-12",children:e.jsx(g.Field,{name:h,as:t.DebouncedTextField,label:"File name",size:"small",disabled:F||l,value:F?"-":c})}),e.jsxs("div",{className:"col-span-12",children:[e.jsx(g.Field,{name:f,as:t.DebouncedTextField,label:"Storage path",disabled:w||l,size:"small",value:w?"-":p}),e.jsxs(t.Typography,{variant:"caption",className:"ml-3.5 mt-1 mb-2",children:[e.jsx("p",{children:"You can use the following placeholders in the file name and storage path values:"}),e.jsxs("ul",{children:[e.jsx("li",{children:"{file} - Full name of the uploaded file"}),e.jsx("li",{children:"{file.name} - Name of the uploaded file without extension"}),e.jsx("li",{children:"{file.ext} - Extension of the uploaded file"}),e.jsx("li",{children:"{entityId} - ID of the entity"}),e.jsx("li",{children:"{propertyKey} - ID of this field"}),e.jsx("li",{children:"{path} - Path of this entity"}),e.jsx("li",{children:"{rand} - Random value used to avoid name collisions"})]})]}),e.jsx(g.Field,{type:"checkbox",name:u,label:"Save URL instead of storage path",disabled:a||l,component:i.SwitchControl}),e.jsx("br",{}),e.jsx(t.Typography,{variant:"caption",className:"ml-3.5 mt-1 mb-2",children:"Turn this setting on, if you prefer to save the download URL of the uploaded file instead of the storage path. You can only change this prop upon creation."})]})]})})}),e.jsx("div",{className:"col-span-12",children:e.jsxs(ie,{children:[!r&&e.jsx("div",{className:"grid grid-cols-12 gap-2",children:e.jsx(fe,{disabled:l})}),r&&e.jsx("div",{className:"col-span-12",children:e.jsx(ke,{disabled:l})})]})})]})}function Ce(r){if(i.isPropertyBuilder(r)||i.isPropertyBuilder(r))return!1;{const a=r;return a.dataType==="array"&&typeof a.of=="function"||a.dataType==="array"&&Array.isArray(a.of)?!1:!!a.editable}}function je(r){return Object.entries(r).filter(([a,l])=>Ce(l)).map(([a,l])=>{const o=l;if(Ce(o))return o.dataType==="map"&&o.properties?{[a]:{...o,properties:je(o.properties)}}:{[a]:o}}).filter(a=>!!a).reduce((a,l)=>({...a,...l}),{})}function Ye({property:r,onClick:a,hasError:l,includeName:o,includeEditButton:s,selected:n}){const{propertyConfigs:d}=i.useCustomizationController(),h=i.getFieldConfig(r,d);Ce(r);const f=l?"border-red-500":n?"border-blue-500":"border-transparent";return e.jsx(i.ErrorBoundary,{children:e.jsxs("div",{onClick:a,className:"flex flex-row w-full cursor-pointer",children:[e.jsx("div",{className:"m-4",children:e.jsx(i.FieldConfigBadge,{propertyConfig:h})}),e.jsxs(t.Paper,{className:t.cn("pl-2 w-full flex flex-row gap-4 items-center",t.cardMixin,a?t.cardClickableMixin:"",n?t.cardSelectedMixin:"","flex-grow p-4 border transition-colors duration-200",f),children:[e.jsxs("div",{className:"w-full flex flex-col",children:[o&&e.jsx(i.ErrorBoundary,{children:e.jsx(t.Typography,{variant:"body1",component:"span",className:"flex-grow pr-2",children:r.name?r.name:" "})}),e.jsxs("div",{className:"flex flex-row items-center",children:[e.jsx(i.ErrorBoundary,{children:e.jsx(t.Typography,{className:"flex-grow pr-2",variant:o?"body2":"subtitle1",component:"span",color:"secondary",children:h?.name})}),e.jsx(i.ErrorBoundary,{children:e.jsx(t.Typography,{variant:"body2",component:"span",color:"disabled",children:r.dataType})})]})]}),s&&e.jsx(t.Typography,{variant:"button",children:"EDIT"})]})]})})}function Tr({name:r,selected:a,onClick:l,property:o}){const{propertyConfigs:s}=i.useCustomizationController(),n=!i.isPropertyBuilder(o)&&o?i.getFieldConfig(o,s):void 0;return e.jsxs("div",{onClick:l,className:"flex flex-row w-full cursor-pointer",children:[e.jsxs("div",{className:"relative m-4",children:[n&&e.jsx(i.FieldConfigBadge,{propertyConfig:n}),!n&&e.jsx("div",{className:"h-8 w-8 p-1 rounded-full shadow text-white bg-gray-500",children:e.jsx(t.FunctionsIcon,{color:"inherit",size:"medium"})}),e.jsx(t.RemoveCircleIcon,{color:"disabled",size:"small",className:"absolute -right-2 -top-2"})]}),e.jsx(t.Paper,{className:t.cn("pl-2 w-full flex flex-row gap-4 items-center",t.cardMixin,l?t.cardClickableMixin:"",a?t.cardSelectedMixin:"","flex-grow p-4 border transition-colors duration-200",a?"border-blue-500":"border-transparent"),children:e.jsxs("div",{className:"w-full flex flex-col",children:[e.jsx(t.Typography,{variant:"body1",component:"span",className:"flex-grow pr-2",children:o?.name?o.name:r}),e.jsxs("div",{className:"flex flex-row items-center",children:[n&&e.jsx(t.Typography,{className:"flex-grow pr-2",variant:"body2",component:"span",color:"secondary",children:n?.name}),o&&!i.isPropertyBuilder(o)&&e.jsx(i.ErrorBoundary,{children:e.jsx(t.Typography,{variant:"body2",component:"span",color:"disabled",children:o.dataType})}),o&&i.isPropertyBuilder(o)&&e.jsx(i.ErrorBoundary,{children:e.jsx(t.Typography,{variant:"body2",component:"span",color:"disabled",children:"This property is defined as a property builder in code"})}),!o&&e.jsx(i.ErrorBoundary,{children:e.jsx(t.Typography,{variant:"body2",component:"span",color:"disabled",children:"This field is defined as an additional field in code"})})]})]})})]})}function we({namespace:r,selectedPropertyKey:a,onPropertyClick:l,properties:o,propertiesOrder:s,additionalFields:n,errors:d,onPropertyMove:h,onPropertyRemove:f,className:u,inferredPropertyKeys:c,collectionEditable:p}){const T=s??Object.keys(o),m=C.useCallback(b=>{if(!b.destination)return;const N=b.source.index,F=b.destination.index,w=Array.from(T),[y]=w.splice(N,1);w.splice(F,0,y),h&&h(w,r)},[r,h,T]);return e.jsx(e.Fragment,{children:e.jsx(_e.DragDropContext,{onDragEnd:m,children:e.jsx(_e.Droppable,{droppableId:`droppable_${r}`,children:(b,N)=>e.jsxs("div",{...b.droppableProps,ref:b.innerRef,className:u,children:[T&&T.map((F,w)=>{const y=o[F],P=n?.find(x=>x.key===F);return!y&&!P?(console.warn(`Property ${F} not found in properties or additionalFields`),null):e.jsx(_e.Draggable,{draggableId:`array_field_${r}_${F}}`,index:w,children:(x,v)=>e.jsx(i.ErrorBoundary,{children:e.jsx(Pr,{propertyKey:F,propertyOrBuilder:y,additionalField:P,provided:x,errors:d,namespace:r,inferredPropertyKeys:c,onPropertyMove:h,onPropertyRemove:f,onPropertyClick:v.isDragging?void 0:l,selectedPropertyKey:a,collectionEditable:p})})},`array_field_${r}_${F}}`)}).filter(Boolean),b.placeholder]})})})})}function Pr({propertyKey:r,namespace:a,propertyOrBuilder:l,additionalField:o,provided:s,selectedPropertyKey:n,errors:d,onPropertyClick:h,onPropertyMove:f,onPropertyRemove:u,inferredPropertyKeys:c,collectionEditable:p}){const T=c?.includes(a?`${a}.${r}`:r),m=K(r,a);let b;if(typeof l=="object"){const y=l;y.dataType==="map"&&y.properties&&(b=e.jsx(we,{selectedPropertyKey:n,namespace:m,properties:y.properties,propertiesOrder:y.propertiesOrder,errors:d,onPropertyClick:h,onPropertyMove:f,onPropertyRemove:u,collectionEditable:p}))}const N=m?g.getIn(d,te(m)):!1,F=n===m,w=l&&(p&&!i.isPropertyBuilder(l)||Ce(l));return e.jsxs("div",{ref:s.innerRef,...s.draggableProps,...s.dragHandleProps,className:"relative -ml-8",children:[b&&e.jsx("div",{className:"absolute border-l "+t.defaultBorderMixin,style:{left:"32px",top:"64px",bottom:"16px"}}),!i.isPropertyBuilder(l)&&!o&&w?e.jsx(Ye,{property:l,onClick:h?()=>h(r,a):void 0,includeName:!0,selected:F,hasError:N}):e.jsx(Tr,{name:r,property:l,onClick:h?()=>h(r,a):void 0,selected:F}),e.jsxs("div",{className:"absolute top-2 right-2 flex flex-row ",children:[T&&e.jsx(t.Tooltip,{title:"Inferred property",children:e.jsx(t.AutoAwesomeIcon,{size:"small",className:"p-2"})}),u&&e.jsx(t.Tooltip,{title:"Remove",children:e.jsx(t.IconButton,{size:"small",color:"inherit",onClick:()=>u(r,a),children:e.jsx(t.RemoveIcon,{size:"small"})})}),f&&e.jsx(t.Tooltip,{title:"Move",children:e.jsx(t.IconButton,{component:"span",size:"small",children:e.jsx(t.DragHandleIcon,{size:"small"})})})]}),b&&e.jsx("div",{className:"ml-16",children:b})]})}function xr({disabled:r,getData:a,allowDataInference:l,propertyConfigs:o,collectionEditable:s}){const{values:n,setFieldValue:d}=g.useFormikContext(),[h,f]=C.useState(!1),[u,c]=C.useState(),[p,T]=C.useState(),m=n.propertiesOrder??Object.keys(n.properties??{}),b=C.useCallback(({id:v,property:E})=>{if(!v)throw Error();d("properties",{...n.properties??{},[v]:E},!1),d("propertiesOrder",[...m,v],!1),f(!1)},[n.properties,m]),N=C.useCallback((v,E)=>{const U=v?K(v,E):void 0;if(!U)throw Error("collection editor miss config");const D=te(U),V=oe(E),L=g.getIn(n,V)??Object.keys(g.getIn(n,qe(E)));d(D,void 0,!1),d(V,L.filter(O=>O!==v),!1),f(!1),c(void 0),T(void 0)},[d,n]),F=u?K(u,p):void 0,w=F?g.getIn(n.properties,F.replaceAll(".",".properties.")):void 0,y=e.jsxs(t.Button,{color:"primary",variant:"outlined",onClick:()=>f(!0),startIcon:e.jsx(t.AddIcon,{}),children:["Add property to ",n.name??"this group"]}),P=!m||m.length<1,x=C.useCallback((v,E)=>{d(oe(E),v,!1)},[]);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"col-span-12",children:[e.jsxs("div",{className:"flex justify-between items-end my-4",children:[e.jsx(t.Typography,{variant:"subtitle2",children:"Properties in this group"}),y]}),e.jsxs(t.Paper,{className:"p-2 pl-8",children:[e.jsx(we,{properties:n.properties??{},propertiesOrder:m,errors:{},collectionEditable:s,onPropertyClick:(v,E)=>{c(v),T(E),f(!0)},onPropertyMove:x}),P&&e.jsx(t.Typography,{variant:"label",className:"h-full flex items-center justify-center p-4",children:"Add the first property to this group"})]})]}),e.jsxs("div",{className:"col-span-12",children:[e.jsx(t.BooleanSwitchWithLabel,{position:"start",size:"small",label:"Spread children as columns",onValueChange:v=>d("spreadChildren",v),value:n.spreadChildren??!1}),e.jsx(H,{children:"Set this flag to true if you want to display the children of this group as individual columns."})]}),e.jsx(ge,{inArray:!1,forceShowErrors:!1,open:h,allowDataInference:l,collectionEditable:s,onCancel:()=>{f(!1),c(void 0),T(void 0)},onOkClicked:()=>{f(!1),c(void 0),T(void 0)},getData:a,onDelete:N,propertyKey:u,propertyNamespace:p,property:w,existingProperty:!!u,autoUpdateId:!u,autoOpenTypeSelect:!u,onPropertyChanged:b,existingPropertyKeys:u?void 0:m,propertyConfigs:o})]})}function Fr({showErrors:r,existing:a,disabled:l,getData:o,allowDataInference:s,propertyConfigs:n,collectionEditable:d}){const{values:h,handleChange:f,errors:u,setFieldValue:c,touched:p}=g.useFormikContext(),[T,m]=C.useState(!1),b=g.getIn(h,"of"),N=g.getIn(p,"of")&&g.getIn(u,"of"),F=C.useCallback(({id:y,property:P,namespace:x})=>{c("of",P)},[]),w=b&&i.getFieldConfig(b,n);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"col-span-12",children:[e.jsx(t.Typography,{variant:"subtitle2",children:"Repeat component"}),e.jsx(g.Field,{name:"of",value:b,validate:y=>y?.dataType?void 0:"You need to specify a repeat field",children:()=>e.jsxs(t.Paper,{className:"p-2 mt-4",children:[b&&e.jsx(Ye,{property:b,onClick:l?void 0:()=>m(!0),includeName:!1,includeEditButton:!0,selected:!1,hasError:!1}),!l&&!b&&e.jsxs(t.Button,{variant:"text",size:"large",color:N?"error":"primary",onClick:()=>m(!0),children:["Edit ",`${w?w.name:"repeat component"}`]}),e.jsx(ge,{inArray:!0,open:T,existingProperty:a,getData:o,autoUpdateId:!a,autoOpenTypeSelect:!a,onOkClicked:()=>m(!1),allowDataInference:s,property:b,includeIdAndName:!1,onPropertyChanged:F,forceShowErrors:r,propertyConfigs:n,collectionEditable:d})]})})]}),e.jsx("div",{className:"col-span-12",children:e.jsx(ie,{children:e.jsx(ke,{disabled:l})})})]})}const Nr=C.forwardRef(function({showErrors:a,disabledId:l,existingPropertyKeys:o,disabled:s,autoUpdateId:n,isNewProperty:d},h){const{errors:f,values:u,setFieldValue:c,setFieldTouched:p,touched:T}=g.useFormikContext(),m="name",b=a&&g.getIn(f,m),N="id",F=a&&g.getIn(f,N),w="description",y=a&&g.getIn(f,w);return e.jsxs("div",{className:"flex flex-col gap-2 col-span-12",children:[e.jsxs("div",{children:[e.jsx(g.Field,{inputRef:h,as:t.DebouncedTextField,value:u[m],onChange:P=>{const x=P.target.value;c(m,x),p(m,!0,!0),!g.getIn(T,N)&&n&&c(N,x?i.toSnakeCase(x):"")},style:{fontSize:20},validate:Sr,placeholder:"Field name",required:!0,disabled:s,error:!!b}),e.jsx(H,{error:!!b,children:b})]}),e.jsxs("div",{children:[e.jsx(g.Field,{as:t.DebouncedTextField,label:"ID",value:u[N],onChange:P=>{const x=P.target.value;c(N,x),p(N,!0,!0),!g.getIn(T,m)&&n&&c(m,x?i.unslugify(x):"")},validate:()=>Ir(u[N],o),disabled:l||s,required:!0,size:"small",error:!!F}),e.jsx(H,{error:!!F,children:F})]}),e.jsxs("div",{children:[e.jsx(g.Field,{name:w,as:t.DebouncedTextField,label:"Description",disabled:s,error:!!y}),e.jsx(H,{error:!!y,children:y})]})]})}),wr=/^[a-zA-Z_][a-zA-Z0-9_]*$/;function Ir(r,a){let l;return r||(l="You must specify an id for the field"),r&&!r.match(wr)&&(l="The id can only contain letters, numbers and underscores (_), and not start with a number"),r&&a&&a.includes(r)&&(l="There is another field with this ID already"),l}function Sr(r){let a;return r||(a="You must specify a title for the field"),a}function Or({widgetId:r,disabled:a,showErrors:l}){const{values:o,setFieldValue:s}=g.useFormikContext();return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"col-span-12",children:e.jsxs(ie,{children:[r==="text_field"&&e.jsx(be,{disabled:a,length:!0,lowercase:!0,matches:!0,max:!0,min:!0,trim:!0,uppercase:!0,showErrors:l}),r==="multiline"&&e.jsx(be,{disabled:a,length:!0,lowercase:!0,max:!0,min:!0,trim:!0,uppercase:!0,showErrors:l}),r==="markdown"&&e.jsx(be,{disabled:a,length:!0,lowercase:!0,max:!0,min:!0,trim:!0,uppercase:!0,showErrors:l}),r==="email"&&e.jsx(be,{disabled:a,max:!0,min:!0,trim:!0,showErrors:l})]})}),e.jsx("div",{className:"col-span-12",children:e.jsx(t.TextField,{name:"defaultValue",disabled:a,onChange:n=>{s("defaultValue",n.target.value===""?void 0:n.target.value)},label:"Default value",value:g.getIn(o,"defaultValue")??""})})]})}function Vr({disabled:r}){const{values:a}=g.useFormikContext(),l=g.getIn(a,"defaultValue");return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"col-span-12",children:e.jsx(ie,{children:e.jsx(fe,{disabled:r})})}),e.jsx("div",{className:"col-span-12",children:e.jsx(g.FastField,{type:"checkbox",name:"defaultValue",label:l==null?"Default value not set":"Default value is "+l.toString(),disabled:r,allowIndeterminate:!0,component:i.SwitchControl})})]})}function Er({disabled:r,getData:a,allowDataInference:l,propertyConfigs:o,collectionEditable:s}){const{values:n,setFieldValue:d}=g.useFormikContext(),[h,f]=C.useState(!1),[u,c]=C.useState(),[p,T]=C.useState(),m=C.useCallback(({id:P,property:x})=>{if(!P)throw Error();d("oneOf.properties",{...n.oneOf?.properties??{},[P]:x},!1),d("oneOf.propertiesOrder",[...n.oneOf?.propertiesOrder??Object.keys(n.oneOf?.properties??{}),P],!1),f(!1)},[n.oneOf?.properties,n.oneOf?.propertiesOrder]),b=u?K(u,p):void 0,N=b?g.getIn(n.oneOf?.properties,b.replaceAll(".",".properties.")):void 0,F=C.useCallback((P,x)=>{const v=P?K(P,x):void 0;if(!v)throw Error("collection editor miss config");d(`oneOf.${te(v)}`,void 0,!1);const E=`oneOf.${oe(x)}`,U=g.getIn(n,E);d(E,U.filter(D=>D!==P),!1),f(!1),c(void 0),T(void 0)},[d,n]),w=e.jsxs(t.Button,{autoFocus:!0,color:"primary",onClick:()=>f(!0),startIcon:e.jsx(t.AddIcon,{}),children:["Add property to ",n.name??"this block"]}),y=C.useCallback((P,x)=>{d(`oneOf.${oe(x)}`,P,!1)},[]);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"col-span-12",children:[e.jsxs("div",{className:"flex justify-between items-end mt-8 mb-4",children:[e.jsx(t.Typography,{variant:"subtitle2",children:"Properties in this block"}),w]}),e.jsxs(t.Paper,{className:"p-2 pl-8",children:[e.jsx(we,{properties:n.oneOf?.properties??{},propertiesOrder:n.oneOf?.propertiesOrder,errors:{},collectionEditable:s,onPropertyClick:r?void 0:(P,x)=>{c(P),T(x),f(!0)},onPropertyMove:r?void 0:y}),!r&&!n.oneOf?.propertiesOrder?.length&&e.jsx("div",{className:"h-full flex items-center justify-center p-4",children:"Add the first property to this block"})]})]}),!r&&e.jsx(ge,{inArray:!1,forceShowErrors:!1,open:h,getData:a,allowDataInference:l,onCancel:()=>{f(!1),c(void 0),T(void 0)},onOkClicked:()=>{f(!1),c(void 0),T(void 0)},collectionEditable:s,onDelete:F,propertyKey:u,propertyNamespace:p,property:N,existingProperty:!!u,autoUpdateId:!u,autoOpenTypeSelect:!u,onPropertyChanged:m,existingPropertyKeys:u?void 0:n.oneOf?.propertiesOrder,propertyConfigs:o})]})}function Br({disabled:r}){const{values:a,handleChange:l}=g.useFormikContext(),o="validation.min",s="validation.max",n="validation.lessThan",d="validation.moreThan",h="validation.positive",f="validation.negative",u="validation.integer";return e.jsxs("div",{className:"grid grid-cols-12 gap-2",children:[e.jsx(fe,{disabled:r}),e.jsx("div",{className:"col-span-6",children:e.jsx(t.DebouncedTextField,{value:g.getIn(a,o),label:"Min value",name:o,type:"number",size:"small",disabled:r,onChange:l})}),e.jsx("div",{className:"col-span-6",children:e.jsx(t.DebouncedTextField,{value:g.getIn(a,s),label:"Max value",name:s,type:"number",size:"small",disabled:r,onChange:l})}),e.jsx("div",{className:"col-span-6",children:e.jsx(t.DebouncedTextField,{value:g.getIn(a,n),label:"Less than",name:n,type:"number",size:"small",disabled:r,onChange:l})}),e.jsx("div",{className:"col-span-6",children:e.jsx(t.DebouncedTextField,{value:g.getIn(a,d),label:"More than",name:d,type:"number",size:"small",disabled:r,onChange:l})}),e.jsx("div",{className:"col-span-4",children:e.jsx(g.FastField,{type:"checkbox",name:h,label:"Positive value",disabled:r,component:i.SwitchControl})}),e.jsx("div",{className:"col-span-4",children:e.jsx(g.FastField,{type:"checkbox",name:f,label:"Negative value",disabled:r,component:i.SwitchControl})}),e.jsx("div",{className:"col-span-4",children:e.jsx(g.FastField,{type:"checkbox",name:u,label:"Integer value",disabled:r,component:i.SwitchControl})})]})}function Dr({disabled:r}){const{values:a,setFieldValue:l}=g.useFormikContext();return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"col-span-12",children:e.jsx(ie,{children:e.jsx(Br,{disabled:r})})}),e.jsx("div",{className:"col-span-12",children:e.jsx(t.TextField,{name:"defaultValue",disabled:r,type:"number",onChange:o=>{l("defaultValue",o.target.value===""?void 0:parseFloat(o.target.value))},label:"Default value",value:g.getIn(a,"defaultValue")??""})})]})}function Ge({existing:r,multiple:a,disabled:l,showErrors:o}){const{values:s,handleChange:n,errors:d}=g.useFormikContext();if(!i.useNavigationController())return e.jsx("div",{className:"col-span-12",children:e.jsx(t.CircularProgress,{})});const f=a?"of.path":"path",u=g.getIn(s,f),c=o&&g.getIn(d,f);return e.jsx(e.Fragment,{children:e.jsx("div",{className:"col-span-12",children:e.jsx(g.Field,{required:!0,name:f,pathPath:f,type:"select",validate:_r,disabled:r||l,value:u,error:c,handleChange:n,component:kr})})})}function _r(r){let a;return r||(a="You must specify a target collection for the field"),a}function kr({disabled:r,pathPath:a,value:l,handleChange:o,error:s,...n}){const d=i.useNavigationController();if(!d)return e.jsx("div",{className:"col-span-12",children:e.jsx(t.CircularProgress,{})});const h=d?.collections??[],f=Array.from(new Set(Object.values(h).map(c=>c.group).filter(Boolean)).values()),u=h.filter(c=>!c.group);return e.jsxs(e.Fragment,{children:[e.jsxs(t.Select,{error:!!s,disabled:r,value:l??"",position:"item-aligned",name:a,onChange:o,label:"Target collection",renderValue:c=>{const p=h.find(T=>T.id===c||T.path===c);return p?e.jsxs("div",{className:"flex flex-row",children:[e.jsx(i.IconForView,{collectionOrView:p}),e.jsx(t.Typography,{variant:"subtitle2",className:"font-medium ml-4",children:p?.name.toUpperCase()})]}):null},...n,children:[f.flatMap(c=>e.jsx(t.SelectGroup,{label:c||"Views",children:h.filter(p=>p.group===c).map(p=>e.jsx(t.SelectItem,{value:p.id??p.path,children:e.jsxs("div",{className:"flex flex-row",children:[e.jsx(i.IconForView,{collectionOrView:p}),e.jsx(t.Typography,{variant:"subtitle2",className:"font-medium ml-4",children:p?.name.toUpperCase()})]})},`${p.id??p.path}-${c}`))},`group_${c}`)),u&&e.jsx(t.SelectGroup,{label:"Views",children:u.map(c=>e.jsx(t.SelectItem,{value:c.id??c.path,children:e.jsxs("div",{className:"flex flex-row",children:[e.jsx(i.IconForView,{collectionOrView:c}),e.jsx(t.Typography,{variant:"subtitle2",className:"font-medium ml-4",children:c?.name.toUpperCase()})]})},c.id??c.path))})]}),e.jsx(H,{children:"You can only edit the reference collection upon field creation."})]})}function Ar({disabled:r}){const{values:a,errors:l,touched:o,setFieldValue:s}=g.useFormikContext(),n="mode",d=g.getIn(a,n),h=g.getIn(o,n)&&g.getIn(l,n),f="autoValue",u=g.getIn(a,f),c=g.getIn(o,f)&&g.getIn(l,f);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col col-span-12",children:[e.jsxs(t.Select,{name:n,value:d??"date",error:!!h,onValueChange:p=>s(n,p),label:"Mode",renderValue:p=>{switch(p){case"date_time":return"Date/Time";case"date":return"Date";default:return""}},disabled:r,children:[e.jsx(t.SelectItem,{value:"date_time",children:" Date/Time "}),e.jsx(t.SelectItem,{value:"date",children:" Date "})]}),e.jsx(H,{error:!!h,children:h}),e.jsxs(t.Select,{name:f,disabled:r,value:u??"",onValueChange:p=>s(f,p),renderValue:p=>{switch(p){case"on_create":return"On create";case"on_update":return"On any update";default:return"None"}},error:!!c,label:"Automatic value",children:[e.jsx(t.SelectItem,{value:"",children:" None "}),e.jsx(t.SelectItem,{value:"on_create",children:" On create "}),e.jsx(t.SelectItem,{value:"on_update",children:" On any update "})]}),e.jsx(H,{error:!!c,children:c??"Update this field automatically when creating or updating the entity"})]}),e.jsx("div",{className:"col-span-12",children:e.jsx(ie,{children:e.jsx(fe,{disabled:r})})})]})}function Mr({disabled:r}){g.useFormikContext();const a="hideFromCollection",l="readOnly";return e.jsxs("div",{className:"grid grid-cols-12 gap-2",children:[e.jsx("div",{className:"col-span-12",children:e.jsx(g.FastField,{type:"checkbox",name:a,label:"Hide from collection",disabled:r,tooltip:"Hide this field from the collection view. It will still be visible in the form view",component:i.SwitchControl})}),e.jsx("div",{className:"col-span-12",children:e.jsx(g.FastField,{type:"checkbox",name:l,label:"Read only",disabled:r,tooltip:"Is this a read only field. Display only as a preview",component:i.SwitchControl})})]})}function zr({disabled:r}){return e.jsx(e.Fragment,{children:e.jsx("div",{className:"col-span-12",children:e.jsx(ie,{children:e.jsx(fe,{disabled:r})})})})}function He(r,a,l){let o;return a==="text_field"?o=i.mergeDeep(r,{dataType:"string",propertyConfig:"text_field",editable:r.editable!==void 0?r.editable:!0,storage:void 0,multiline:void 0,markdown:void 0,email:void 0,url:void 0,enumValues:void 0}):a==="multiline"?o=i.mergeDeep(r,{dataType:"string",propertyConfig:"multiline",editable:r.editable!==void 0?r.editable:!0,multiline:!0,storage:void 0,markdown:void 0,email:void 0,url:void 0,enumValues:void 0}):a==="markdown"?o=i.mergeDeep(r,{dataType:"string",propertyConfig:"markdown",editable:r.editable!==void 0?r.editable:!0,storage:void 0,multiline:void 0,markdown:!0,email:void 0,url:void 0}):a==="url"?o=i.mergeDeep(r,{dataType:"string",propertyConfig:"url",editable:r.editable!==void 0?r.editable:!0,storage:void 0,multiline:void 0,markdown:void 0,email:void 0,url:!0,enumValues:void 0}):a==="email"?o=i.mergeDeep(r,{dataType:"string",propertyConfig:"email",editable:r.editable!==void 0?r.editable:!0,storage:void 0,multiline:void 0,markdown:void 0,email:!0,url:void 0,enumValues:void 0}):a==="select"?o=i.mergeDeep(r,{dataType:"string",propertyConfig:"select",editable:r.editable!==void 0?r.editable:!0,storage:void 0,multiline:void 0,markdown:void 0,email:void 0,url:void 0,enumValues:r.enumValues??[]}):a==="multi_select"?o=i.mergeDeep(r,{dataType:"array",propertyConfig:"multi_select",editable:r.editable!==void 0?r.editable:!0,of:{dataType:"string",enumValues:r.of?.enumValues??[]}}):a==="number_input"?o=i.mergeDeep(r,{dataType:"number",propertyConfig:"number_input",editable:r.editable!==void 0?r.editable:!0,enumValues:void 0}):a==="number_select"?o=i.mergeDeep(r,{dataType:"number",propertyConfig:"number_select",editable:r.editable!==void 0?r.editable:!0,enumValues:r.enumValues??[]}):a==="multi_number_select"?o=i.mergeDeep(r,{dataType:"array",propertyConfig:"multi_number_select",editable:r.editable!==void 0?r.editable:!0,of:{dataType:"number",enumValues:r.of?.enumValues??[]}}):a==="file_upload"?o=i.mergeDeep(r,{dataType:"string",propertyConfig:"file_upload",editable:r.editable!==void 0?r.editable:!0,storage:{storagePath:"/"}}):a==="multi_file_upload"?o=i.mergeDeep(r,{dataType:"array",propertyConfig:"multi_file_upload",editable:r.editable!==void 0?r.editable:!0,of:{dataType:"string",storage:r.of?.storage??{storagePath:"/"}}}):a==="group"?o=i.mergeDeep(r,{dataType:"map",propertyConfig:"group",editable:r.editable!==void 0?r.editable:!0,keyValue:!1,properties:r.properties??{}}):a==="key_value"?o=i.mergeDeep(r,{dataType:"map",propertyConfig:"key_value",editable:r.editable!==void 0?r.editable:!0,keyValue:!0,properties:void 0}):a==="reference"?o=i.mergeDeep(r,{dataType:"reference",propertyConfig:"reference",editable:r.editable!==void 0?r.editable:!0}):a==="multi_references"?o=i.mergeDeep(r,{dataType:"array",propertyConfig:"multi_references",editable:r.editable!==void 0?r.editable:!0,of:{dataType:"reference"}}):a==="switch"?o=i.mergeDeep(r,{dataType:"boolean",propertyConfig:"switch",editable:r.editable!==void 0?r.editable:!0}):a==="date_time"?o=i.mergeDeep(r,{dataType:"date",propertyConfig:"date_time",editable:r.editable!==void 0?r.editable:!0,mode:"date_time"}):a==="repeat"?o=i.mergeDeep(r,{dataType:"array",propertyConfig:"repeat",editable:r.editable!==void 0?r.editable:!0}):a==="block"?o=i.mergeDeep(r,{dataType:"array",propertyConfig:"block",editable:r.editable!==void 0?r.editable:!0,oneOf:{properties:{}}}):a&&l[a]&&(o={...l[a].property,propertyConfig:a}),o}function Ke({value:r,optionDisabled:a,propertyConfig:l,existing:o}){return e.jsx(t.SelectItem,{value:r,disabled:a,className:"flex flex-row items-center",children:e.jsxs("div",{className:t.cn("flex flex-row items-center text-base min-h-[52px]",a?"w-full":""),children:[e.jsx("div",{className:"mr-8",children:e.jsx(i.FieldConfigBadge,{propertyConfig:l})}),e.jsxs("div",{children:[e.jsx("div",{children:l.name}),e.jsx(t.Typography,{variant:"caption",color:"disabled",className:"max-w-sm",children:o&&a?"You can only switch to widgets that use the same data type":l.description})]})]})})}function Ur({disabled:r,showErrors:a}){const{values:l,setFieldValue:o}=g.useFormikContext(),s=g.getIn(l,"url");return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"col-span-12",children:e.jsxs(t.Select,{disabled:r,position:"item-aligned",onValueChange:n=>{n==="[NONE]"?o("url",!0):o("url",n)},label:"Preview type",renderValue:n=>{switch(n){case"image":return"Image";case"video":return"Video";case"audio":return"Audio";default:return"Display URL"}},value:s??"[NONE]",children:[e.jsx(t.SelectItem,{value:"[NONE]",children:"Display URL"}),e.jsx(t.SelectItem,{value:"image",children:"Image"}),e.jsx(t.SelectItem,{value:"video",children:"Video"}),e.jsx(t.SelectItem,{value:"audio",children:"Audio"})]})}),e.jsx("div",{className:"col-span-12",children:e.jsx(ie,{children:e.jsx(be,{disabled:r,max:!0,min:!0,trim:!0,showErrors:a})})}),e.jsx("div",{className:"col-span-12",children:e.jsx(t.TextField,{name:"defaultValue",disabled:r,onChange:n=>{o("defaultValue",n.target.value===""?void 0:n.target.value)},label:"Default value",value:g.getIn(l,"defaultValue")??""})})]})}const qr=["text_field","multiline","markdown","url","email","select","multi_select","number_input","number_select","multi_number_select","file_upload","multi_file_upload","reference","multi_references","switch","date_time","group","key_value","repeat","block"],We=Object.entries(i.DEFAULT_FIELD_CONFIGS).filter(([r])=>qr.includes(r)).map(([r,a])=>({[r]:a})).reduce((r,a)=>({...r,...a}),{}),Ze=C.memo(function({includeIdAndName:a=!0,autoOpenTypeSelect:l,existingProperty:o,autoUpdateId:s,inArray:n,propertyKey:d,propertyNamespace:h,property:f,onPropertyChanged:u,onPropertyChangedImmediate:c=!0,onDelete:p,onError:T,initialErrors:m,forceShowErrors:b,existingPropertyKeys:N,allowDataInference:F,getHelpers:w,getData:y,propertyConfigs:P,collectionEditable:x}){const v={id:"",name:""},E=!!(f&&!Ce(f))&&!x,U=C.useRef(f?{id:d,previousId:d,property:f}:void 0),D=({id:V,property:L})=>{const O={id:V,previousId:U.current?.id,property:L,namespace:h};U.current=O,u?.(O)};return e.jsx(g.Formik,{initialErrors:m,initialValues:f?{id:d,...f}:v,onSubmit:(V,L)=>{console.debug("onSubmit",V);const{id:O,...S}=V;D({id:O,property:{...S,editable:S.editable??!0}}),o||L.resetForm({values:v})},children:V=>(C.useEffect(()=>{w?.(V)},[V]),e.jsx(Lr,{onPropertyChanged:c?D:void 0,onDelete:p,includeIdAndTitle:a,propertyNamespace:h,onError:T,showErrors:b||V.submitCount>0,existing:o,autoUpdateId:s,inArray:n,autoOpenTypeSelect:l,existingPropertyKeys:N,disabled:E,getData:y,allowDataInference:F,propertyConfigs:P,collectionEditable:x,...V}))},`property_view_${d}`)},(r,a)=>r.getData===a.getData&&r.includeIdAndName===a.includeIdAndName&&r.autoOpenTypeSelect===a.autoOpenTypeSelect&&r.autoUpdateId===a.autoUpdateId&&r.existingProperty===a.existingProperty);function ge({open:r,onCancel:a,onOkClicked:l,onPropertyChanged:o,getData:s,collectionEditable:n,...d}){const h=C.useRef(),f=u=>{h.current=u};return e.jsxs(t.Dialog,{open:r??!1,maxWidth:"xl",fullWidth:!0,children:[e.jsx(t.DialogContent,{children:e.jsx(Ze,{...d,onPropertyChanged:u=>{o?.(u),l?.()},collectionEditable:n,onPropertyChangedImmediate:!1,getHelpers:f,getData:s})}),e.jsxs(t.DialogActions,{children:[a&&e.jsx(t.Button,{variant:"text",onClick:()=>{a(),h.current?.resetForm()},children:"Cancel"}),e.jsx(t.Button,{variant:"outlined",color:"primary",onClick:()=>h.current?.submitForm(),children:"Ok"})]})]})}function Lr({values:r,errors:a,touched:l,setValues:o,setFieldValue:s,existing:n,autoUpdateId:d=!1,autoOpenTypeSelect:h,includeIdAndTitle:f,onPropertyChanged:u,onDelete:c,propertyNamespace:p,onError:T,showErrors:m,disabled:b,inArray:N,existingPropertyKeys:F,getData:w,allowDataInference:y,propertyConfigs:P,collectionEditable:x}){const[v,E]=C.useState(h),[U,D]=C.useState(!1),[V,L]=C.useState(r?.dataType?i.getFieldId(r):void 0),O=Object.entries(We).concat(Object.entries(P)),S=N?O.filter(([G,Z])=>!i.isPropertyBuilder(Z.property)&&Z.property?.dataType!=="array"):O,z=C.useDeferredValue(r),I=C.useRef(null),k=C.useRef(r),ae=m&&g.getIn(a,"selectedWidget");C.useEffect(()=>{if(u&&(!f||z.id)){const{id:G,...Z}=z;xe(z,k.current)||(u({id:G,property:Z,namespace:p}),k.current=z)}},[z,f,u,p]),C.useEffect(()=>{r?.id&&T&&Object.keys(a).length>0&&T(r?.id,p,a)},[a,T,p,r?.id]);const ce=G=>{L(G),o(He(r,G,P)),setTimeout(()=>{I.current?.focus()},0)};let M;return V==="text_field"||V==="multiline"||V==="markdown"||V==="email"?M=e.jsx(Or,{widgetId:V,disabled:b,showErrors:m}):V==="url"?M=e.jsx(Ur,{disabled:b,showErrors:m}):V==="select"||V==="number_select"?M=e.jsx(Le,{multiselect:!1,allowDataInference:y,updateIds:!n,disabled:b,getData:w,showErrors:m}):V==="multi_select"||V==="multi_number_select"?M=e.jsx(Le,{multiselect:!0,updateIds:!n,disabled:b,allowDataInference:y,getData:w,showErrors:m}):V==="file_upload"?M=e.jsx($e,{existing:n,multiple:!1,disabled:b}):V==="multi_file_upload"?M=e.jsx($e,{existing:n,multiple:!0,disabled:b}):V==="switch"?M=e.jsx(Vr,{disabled:b}):V==="number_input"?M=e.jsx(Dr,{disabled:b}):V==="group"?M=e.jsx(xr,{disabled:b,getData:w,allowDataInference:y,collectionEditable:x,propertyConfigs:P}):V==="block"?M=e.jsx(Er,{disabled:b,getData:w,allowDataInference:y,collectionEditable:x,propertyConfigs:P}):V==="reference"?M=e.jsx(Ge,{showErrors:m,existing:n,multiple:!1,disabled:b}):V==="date_time"?M=e.jsx(Ar,{disabled:b}):V==="multi_references"?M=e.jsx(Ge,{showErrors:m,existing:n,multiple:!0,disabled:b}):V==="repeat"?M=e.jsx(Fr,{showErrors:m,existing:n,getData:w,allowDataInference:y,disabled:b,collectionEditable:x,propertyConfigs:P}):V==="key_value"?M=e.jsx(zr,{disabled:b}):M=null,e.jsxs(e.Fragment,{children:[b&&e.jsxs(t.InfoLabel,{mode:"warn",children:[e.jsx(t.Typography,{children:"This property can't be edited"}),e.jsxs(t.Typography,{variant:"caption",children:["You may not have permission to edit it or it is defined in code with no ",e.jsx("code",{children:"editable"})," flag"]})]}),e.jsxs("div",{className:"flex mt-2 justify-between",children:[e.jsxs("div",{className:"w-full flex flex-col gap-2",children:[e.jsx(t.Select,{error:!!ae,value:V??"",placeholder:"Select a property widget",open:v,onOpenChange:E,position:"item-aligned",disabled:b,renderValue:G=>{if(!G)return e.jsx("em",{children:"Select a property widget"});const Z=G,ee=i.DEFAULT_FIELD_CONFIGS[Z]??P[Z],X=ee.property,ue=X&&!i.isPropertyBuilder(X)?i.getFieldConfig(X,P):void 0,re=i.isPropertyBuilder(X)||n&&X.dataType!==r?.dataType,ne=ue?i.mergeDeep(ue,ee):ee;return e.jsxs("div",{onClick:he=>{re&&(he.stopPropagation(),he.preventDefault())},className:t.cn("flex items-center",re?"w-full pointer-events-none opacity-50":""),children:[e.jsx("div",{className:"mr-8",children:e.jsx(i.FieldConfigBadge,{propertyConfig:ne})}),e.jsxs("div",{className:"flex flex-col items-start text-base text-left",children:[e.jsx("div",{children:ne.name}),e.jsx(t.Typography,{variant:"caption",color:"disabled",children:re?"You can only switch to widgets that use the same data type":ne.description})]})]})},onValueChange:G=>{ce(G)},children:S.map(([G,Z])=>{const ee=Z.property,X=n&&!i.isPropertyBuilder(ee)&&ee.dataType!==r?.dataType;return e.jsx(Ke,{value:G,optionDisabled:X,propertyConfig:Z,existing:n},G)})}),ae&&e.jsx(t.Typography,{variant:"caption",className:"ml-3.5",color:"error",children:"Required"})]}),c&&r?.id&&e.jsx(t.IconButton,{variant:"ghost",className:"m-4",disabled:b,onClick:()=>D(!0),children:e.jsx(t.DeleteIcon,{})})]}),e.jsxs("div",{className:"grid grid-cols-12 gap-y-12 mt-8 mb-8",children:[f&&e.jsx(Nr,{showErrors:m,disabledId:n,isNewProperty:!n,existingPropertyKeys:F,disabled:b,autoUpdateId:d,ref:I}),M,e.jsx("div",{className:"col-span-12",children:e.jsx(Mr,{disabled:b})})]}),c&&e.jsx(i.DeleteConfirmationDialog,{open:U,onAccept:()=>c(r?.id,p),onCancel:()=>D(!1),title:e.jsx("div",{children:"Delete this property?"}),body:e.jsxs("div",{children:[" This will ",e.jsx("b",{children:"not delete any data"}),", only modify the collection."]})})]})}function $r(r){return(r.slice(0,1).toLowerCase()+r.slice(1)).replace(/([-_ ]){1,}/g," ").split(/[-_ ]/).reduce((a,l)=>a+l[0].toUpperCase()+l.substring(1),"")}function jr({collection:r,onOpenChange:a,open:l}){const o=i.useSnackbarController(),s=`import { EntityCollection } from "firecms";
1
+ (function(q,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("react/jsx-runtime"),require("@firecms/core"),require("react"),require("react-fast-compare"),require("@firecms/ui"),require("formik"),require("yup"),require("@firecms/schema_inference"),require("@hello-pangea/dnd"),require("json5"),require("prism-react-renderer"),require("@firecms/data_import_export"),require("react-router")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","@firecms/core","react","react-fast-compare","@firecms/ui","formik","yup","@firecms/schema_inference","@hello-pangea/dnd","json5","prism-react-renderer","@firecms/data_import_export","react-router"],e):(q=typeof globalThis<"u"?globalThis:q||self,e(q.FireCMS={},q.jsxRuntime,q.core,q.React,q.equal,q.ui,q.formik,q.Yup,q.schema_inference,q.dnd,q.JSON5,q.prismReactRenderer,q.data_import_export,q.reactRouter))})(this,function(q,e,i,C,xe,t,g,cr,De,_e,pr,ze,se,hr){"use strict";function Ue(r){const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const l in r)if(l!=="default"){const o=Object.getOwnPropertyDescriptor(r,l);Object.defineProperty(a,l,o.get?o:{enumerable:!0,get:()=>r[l]})}}return a.default=r,Object.freeze(a)}const me=Ue(C),Fe=Ue(cr),fr=Fe.object().shape({id:Fe.string().required("Required"),name:Fe.string().required("Required"),path:Fe.string().required("Required")});function H({error:r,children:a}){return a?e.jsx(t.Typography,{variant:"caption",color:r?"error":"secondary",className:"ml-3.5 mt-0.5",children:a}):null}function gr({isNewCollection:r,reservedGroups:a,existingPaths:l,existingIds:o,groups:s,parentCollection:n}){const d=C.useRef(null),{values:h,setFieldValue:f,handleChange:u,touched:c,errors:p,setFieldTouched:T,isSubmitting:m,submitCount:b}=g.useFormikContext(),[N,F]=C.useState(!1),[w,y]=C.useState(!1),P=O=>{f("name",O),!g.getIn(c,"path")&&r&&O&&f("path",i.toSnakeCase(O)),!g.getIn(c,"id")&&r&&O&&f("id",i.toSnakeCase(O)),!g.getIn(c,"singularName")&&r&&O&&f("singularName",i.singular(O))};C.useEffect(()=>{p.id&&y(!0)},[p.id]);const x=e.jsx(i.IconForView,{collectionOrView:h}),v=s?.filter(O=>!a?.includes(O)),{inputFocused:E,autoCompleteOpen:U,setAutoCompleteOpen:D}=t.useAutoComplete({ref:d}),V=!!n;let L;return e.jsx("div",{className:"overflow-auto my-auto",children:e.jsxs(t.Container,{maxWidth:"4xl",className:"flex flex-col gap-4 p-8 m-auto",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-row py-2 pt-3 items-center",children:[e.jsx(t.Typography,{variant:r?"h4":"h5",className:"flex-grow",children:r?"New collection":`${h?.name} collection`}),e.jsx(t.Tooltip,{title:"Change icon",children:e.jsx(t.IconButton,{shape:"square",onClick:()=>F(!0),children:x})})]}),n&&e.jsx(t.Chip,{colorScheme:"tealDarker",children:e.jsxs(t.Typography,{variant:"caption",children:["This is a subcollection of ",e.jsx("b",{children:n.name})]})})]}),e.jsxs("div",{className:"grid grid-cols-12 gap-4",children:[e.jsxs("div",{className:"col-span-12",children:[e.jsx(t.TextField,{value:h.name??"",onChange:O=>P(O.target.value),label:"Name",required:!0,error:c.name&&!!p.name}),e.jsx(H,{error:c.name&&!!p.name,children:c.name&&p.name?p.name:"Name of in this collection, usually a plural name (e.g. Products)"})]}),e.jsxs("div",{className:t.cn("col-span-12 ",V?"":"sm:col-span-8"),children:[e.jsx(g.Field,{name:"path",as:t.DebouncedTextField,label:"Path",disabled:!r,required:!0,error:c.path&&!!p.path}),e.jsx(H,{error:c.path&&!!p.path,children:c.path&&p.path?p.path:V?"Relative path to the parent (no need to include the parent path)":"Path that this collection is stored in, in the database"})]}),!V&&e.jsxs("div",{className:"col-span-12 sm:col-span-4 relative",children:[e.jsx(t.TextField,{error:c.group&&!!p.group,disabled:m,value:h.group??"",autoComplete:"off",onChange:O=>f("group",O.target.value),name:"group",inputRef:d,label:"Group"}),e.jsx(t.Autocomplete,{open:U&&(v??[]).length>0,setOpen:D,children:v?.map((O,S)=>e.jsx(t.AutocompleteItem,{onClick:()=>{D(!1),f("group",O??null)},children:e.jsx("div",{className:"flex-grow",children:O})},S+"_"+O))}),e.jsx(H,{children:c.group&&p.group?p.group:"Group of the collection"})]}),e.jsx("div",{className:"col-span-12",children:e.jsx(t.ExpandablePanel,{expanded:w,onExpandedChange:y,title:e.jsxs("div",{className:"flex flex-row text-gray-500",children:[e.jsx(t.SettingsIcon,{}),e.jsx(t.Typography,{variant:"subtitle2",className:"ml-2",children:"Advanced"})]}),initiallyExpanded:!1,children:e.jsxs("div",{className:"grid grid-cols-12 gap-4 p-4",children:[e.jsxs("div",{className:"col-span-12",children:[e.jsx(g.Field,{name:"id",as:t.DebouncedTextField,disabled:!r,label:"Collection id",error:c.id&&!!p.id}),e.jsx(H,{error:c.id&&!!p.id,children:c.id&&p.id?p.id:"This id identifies this collection"})]}),e.jsxs("div",{className:"col-span-12",children:[e.jsx(t.TextField,{error:c.singularName&&!!p.singularName,id:"singularName","aria-describedby":"singularName-helper",onChange:O=>(T("singularName",!0),u(O)),value:h.singularName??"",label:"Singular name"}),e.jsx(H,{error:c.singularName&&!!p.singularName,children:c.singularName&&p.singularName?p.singularName:"Optionally define a singular name for your entities"})]}),e.jsxs("div",{className:"col-span-12",children:[e.jsx(t.TextField,{error:c.description&&!!p.description,id:"description",value:h.description??"",onChange:u,multiline:!0,rows:2,"aria-describedby":"description-helper-text",label:"Description"}),e.jsx(H,{error:c.description&&!!p.description,children:c.description&&p.description?p.description:"Description of the collection, you can use markdown"})]}),e.jsx("div",{className:"col-span-12",children:e.jsx(t.Select,{name:"defaultSize",label:"Default row size",position:"item-aligned",onChange:u,value:h.defaultSize??"",renderValue:O=>O.toUpperCase(),children:["xs","s","m","l","xl"].map(O=>e.jsx(t.SelectItem,{value:O,children:O.toUpperCase()},`size-select-${O}`))})}),e.jsx("div",{className:"col-span-12",children:e.jsxs(t.Select,{name:"customId",label:"Data IDs generation",position:"item-aligned",disabled:L==="code_defined",onValueChange:O=>{if(O==="code_defined")throw new Error("This should not happen");O==="true"?f("customId",!0):O==="false"?f("customId",!1):O==="optional"&&f("customId","optional")},value:"",renderValue:O=>O==="code_defined"?"Code defined":O==="true"?"Users must define an ID":O==="optional"?"Users can define an ID, but it is not required":"Document ID is generated automatically",children:[e.jsx(t.SelectItem,{value:"false",children:"Document ID is generated automatically"}),e.jsx(t.SelectItem,{value:"true",children:"Users must define an ID"}),e.jsx(t.SelectItem,{value:"optional",children:"Users can define an ID, but it is not required"})]})}),e.jsxs("div",{className:"col-span-12",children:[e.jsx(t.BooleanSwitchWithLabel,{position:"start",label:"Collection group",onValueChange:O=>f("collectionGroup",O),value:h.collectionGroup??!1}),e.jsx(H,{children:"A collection group consists of all collections with the same path. This allows you to query over multiple collections at once."})]}),e.jsxs("div",{className:"col-span-12",children:[e.jsx(t.BooleanSwitchWithLabel,{position:"start",label:"Enable text search for this collection",onValueChange:O=>f("textSearchEnabled",O),value:h.textSearchEnabled??!1}),e.jsx(H,{children:"Allow text search for this collection. If you have not specified a text search delegate, this will use the built-in local text search. This is not recommended for large collections, as it may incur in performance and cost issues."})]})]})})})]}),e.jsx("div",{style:{height:"52px"}}),e.jsx(t.Dialog,{open:N,onOpenChange:F,maxWidth:"xl",fullWidth:!0,children:e.jsx("div",{className:"p-4 overflow-auto min-h-[200px]",children:e.jsx(i.SearchIconsView,{selectedIcon:h.icon,onIconSelected:O=>{F(!1),f("icon",O)}})})})]})})}function te(r){return"properties."+r.replaceAll(".",".properties.")}function qe(r){return r?"properties."+r.replaceAll(".",".properties.")+".properties":"properties"}function oe(r){return r?"properties."+r.replaceAll(".",".properties.")+".propertiesOrder":"propertiesOrder"}function K(r,a){return a?`${a}.${r}`:r}const ur=C.memo(function({enumValues:a,onValuesChanged:l,onError:o,updateIds:s,disabled:n,allowDataInference:d,getData:h}){return e.jsx(g.Formik,{initialValues:{enumValues:a},validateOnMount:!0,onSubmit:(f,u)=>{},children:({values:f,errors:u})=>(C.useEffect(()=>{l&&l(f.enumValues)},[f.enumValues]),C.useEffect(()=>{o&&o(!!(u?.enumValues??!1))},[u]),e.jsx(yr,{enumValuesPath:"enumValues",values:f,errors:u,shouldUpdateId:s,disabled:n,allowDataInference:d,getData:h}))})},function(a,l){return a.enumValues.length===l.enumValues.length&&a.onValuesChanged===l.onValuesChanged&&a.getData===l.getData});function yr({values:r,errors:a,disabled:l,enumValuesPath:o,shouldUpdateId:s,allowDataInference:n,getData:d}){const{setFieldValue:h}=g.useFormikContext(),[f,u]=C.useState(),[c,p]=C.useState(),[T,m]=C.useState(!1),N=C.useRef(new Set).current,F=(y,P)=>{const x=f===P;return e.jsx(vr,{index:y,disabled:l,enumValuesPath:o,autoFocus:x,shouldUpdateId:s||x,onDialogOpen:()=>p(y),inferredEntry:N.has(r.enumValues[y]?.id)},`${P}`)},w=async()=>{d&&(m(!0),d?.().then(y=>{if(!y)return;const P=y.flat(),x=Array.from(new Set(P)),v=r.enumValues,U=De.extractEnumFromValues(x).filter(D=>!v?.some(V=>V.id===D.id));U.forEach(D=>{N.add(D.id)}),h(o,[...U,...v])}).catch(y=>{console.error(y)}).finally(()=>m(!1)))};return e.jsxs("div",{className:"col-span-12",children:[e.jsxs("div",{className:"ml-3.5 flex flex-row items-center",children:[e.jsx(t.ListIcon,{}),e.jsx(t.Typography,{variant:"subtitle2",className:"ml-2 grow",children:"Values"}),n&&e.jsxs(t.Button,{loading:T,disabled:l||T,variant:"text",size:"small",onClick:w,children:[T?e.jsx(t.CircularProgress,{size:"small"}):e.jsx(t.AutoAwesomeIcon,{}),"Infer values from data"]})]}),e.jsxs(t.Paper,{className:"p-4 m-1",children:[e.jsx(i.FormikArrayContainer,{value:r.enumValues,addLabel:"Add enum value",name:o,buildEntry:F,disabled:l,onInternalIdAdded:u,small:!0,setFieldValue:h,includeAddButton:!0}),e.jsx(mr,{index:c,open:c!==void 0,enumValuesPath:o,onClose:()=>p(void 0)})]})]})}const vr=C.memo(function({index:a,shouldUpdateId:l,enumValuesPath:o,autoFocus:s,onDialogOpen:n,disabled:d,inferredEntry:h}){const{values:f,handleChange:u,errors:c,setFieldValue:p,touched:T}=g.useFormikContext(),m=C.useRef(!g.getIn(f,`${o}[${a}].id`)),b=l||m.current,N=g.getIn(f,`${o}[${a}].id`),F=g.getIn(f,`${o}[${a}].label`),w=g.getIn(c,`${o}[${a}].label`),y=C.useRef(F);return C.useEffect(()=>{(y.current===N||!N)&&b&&p(`${o}[${a}].id`,F),y.current=F},[F]),e.jsxs("div",{className:"flex w-full align-center justify-center",children:[e.jsx(g.FastField,{name:`${o}[${a}].label`,as:t.DebouncedTextField,className:"flex-grow",required:!0,disabled:d,size:"small",validate:br,autoFocus:s,autoComplete:"off",endAdornment:h&&e.jsx(t.AutoAwesomeIcon,{size:"small"}),error:!!w}),!d&&e.jsx(t.IconButton,{size:"small","aria-label":"edit",className:"m-1",onClick:()=>n(),children:e.jsx(t.SettingsIcon,{size:"small"})})]})},function(a,l){return a.index===l.index&&a.enumValuesPath===l.enumValuesPath&&a.shouldUpdateId===l.shouldUpdateId&&a.inferredEntry===l.inferredEntry&&a.autoFocus===l.autoFocus});function mr({index:r,open:a,onClose:l,enumValuesPath:o}){const{values:s,handleChange:n,errors:d,setFieldValue:h,touched:f}=g.useFormikContext(),u=r!==void 0?g.getIn(d,`${o}[${r}].id`):void 0;return e.jsxs(t.Dialog,{maxWidth:"md","aria-labelledby":"enum-edit-dialog",open:a,onOpenChange:c=>c?void 0:l(),children:[e.jsx(t.DialogContent,{children:r!==void 0&&e.jsxs("div",{children:[e.jsx(g.FastField,{name:`${o}[${r}]id`,as:t.DebouncedTextField,required:!0,validate:Cr,label:"ID",size:"small",autoComplete:"off",error:!!u}),e.jsx(H,{error:!!u,children:u??"Value saved in the data source"})]})}),e.jsx(t.DialogActions,{children:e.jsx(t.Button,{autoFocus:!0,variant:"outlined",onClick:l,color:"primary",children:"Ok"})})]})}function br(r){let a;return r||(a="You must specify a label"),a}function Cr(r){let a;return r||(a="You must specify an ID"),a}function fe({disabled:r}){const{values:a,handleChange:l}=g.useFormikContext(),o="validation.required",s="validation.requiredMessage",n="validation.unique";return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"col-span-6",children:e.jsx(g.FastField,{type:"checkbox",disabled:r,name:o,label:"Required",tooltip:"You won't be able to save this entity if this value is not set",component:i.SwitchControl})}),e.jsx("div",{className:"col-span-6",children:e.jsx(g.FastField,{type:"checkbox",disabled:r,name:n,label:"Unique",tooltip:"There cannot be multiple entities with the same value",component:i.SwitchControl})}),g.getIn(a,o)&&e.jsx("div",{className:"col-span-12",children:e.jsx(t.DebouncedTextField,{disabled:r,value:g.getIn(a,s),label:"Required message",name:s,size:"small",onChange:l})})]})}function be({length:r,lowercase:a,matches:l,max:o,min:s,trim:n,uppercase:d,disabled:h,showErrors:f}){const{values:u,handleChange:c,errors:p}=g.useFormikContext(),T="validation.length",m="validation.min",b="validation.max",N="validation.trim",F="validation.matches",w="validation.lowercase",y="validation.uppercase",P=g.getIn(p,F),x=g.getIn(u,F),v=typeof x=="string"?x:i.serializeRegExp(x);return e.jsxs("div",{className:"grid grid-cols-12 gap-2",children:[e.jsx(fe,{disabled:h}),e.jsxs("div",{className:"grid grid-cols-12 gap-2 col-span-12",children:[a&&e.jsx("div",{className:"col-span-4",children:e.jsx(g.FastField,{type:"checkbox",name:w,label:"Lowercase",disabled:h,component:i.SwitchControl})}),d&&e.jsx("div",{className:"col-span-4",children:e.jsx(g.FastField,{type:"checkbox",name:y,label:"Uppercase",disabled:h,component:i.SwitchControl})}),n&&e.jsx("div",{className:"col-span-4",children:e.jsx(g.FastField,{type:"checkbox",name:N,label:"Trim",disabled:h,component:i.SwitchControl})})]}),e.jsxs("div",{className:"grid grid-cols-12 gap-2 col-span-12",children:[r&&e.jsx("div",{className:"col-span-4",children:e.jsx(t.DebouncedTextField,{value:g.getIn(u,T),label:"Exact length",name:T,type:"number",size:"small",disabled:h,onChange:c})}),s&&e.jsx("div",{className:"col-span-4",children:e.jsx(t.DebouncedTextField,{value:g.getIn(u,m),label:"Min length",name:m,type:"number",size:"small",disabled:h,onChange:c})}),o&&e.jsx("div",{className:"col-span-4",children:e.jsx(t.DebouncedTextField,{value:g.getIn(u,b),label:"Max length",name:b,type:"number",size:"small",disabled:h,onChange:c})})]}),l&&e.jsxs("div",{className:"col-span-12",children:[e.jsx(g.FastField,{name:F,as:t.DebouncedTextField,validate:E=>E&&!i.isValidRegExp(E),label:"Matches regex",size:"small",disabled:h,value:v,error:!!P}),e.jsx(H,{error:!!P,children:P?"Not a valid regexp":"e.g. /^\\d+$/ for digits only"})]})]})}function ke({max:r=!0,min:a=!0,disabled:l}){const{values:o,handleChange:s}=g.useFormikContext(),n="validation.min",d="validation.max";return e.jsxs("div",{className:"grid grid-cols-12 gap-2",children:[e.jsx(fe,{disabled:l}),a&&e.jsx("div",{className:"col-span-6",children:e.jsx(t.DebouncedTextField,{value:g.getIn(o,n),disabled:l,label:"Min length",name:n,type:"number",size:"small",onChange:s})}),r&&e.jsx("div",{className:"col-span-6",children:e.jsx(t.DebouncedTextField,{value:g.getIn(o,d),disabled:l,label:"Max length",name:d,type:"number",size:"small",onChange:s})})]})}function ie({children:r}){return e.jsx(t.ExpandablePanel,{initiallyExpanded:!1,asField:!0,className:"p-4",title:e.jsxs("div",{className:"flex flex-row text-gray-500",children:[e.jsx(t.RuleIcon,{}),e.jsx(t.Typography,{variant:"subtitle2",className:"ml-2",children:"Validation"})]}),children:r})}function Le({multiselect:r,updateIds:a,disabled:l,showErrors:o,allowDataInference:s,getData:n}){const{values:d,handleChange:h,errors:f,touched:u,setFieldError:c,setFieldValue:p}=g.useFormikContext(),T=i.useSnackbarController(),m=r?"of.enumValues":"enumValues",b=g.getIn(d,"defaultValue"),N=g.getIn(d,m),F=C.useMemo(()=>!N||typeof N=="boolean"?[]:i.resolveEnumValues(N)??[],[N]),w=y=>{if(d&&(p(m,y),!r)){const P=y.filter(x=>!!x?.id).map(x=>x.id);b&&!P.includes(b)&&(p("defaultValue",void 0),T.open({type:"warning",message:"Default value was cleared"}))}};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"col-span-12",children:e.jsx(ur,{enumValues:F,updateIds:a,disabled:l,allowDataInference:s,onError:y=>{c(m,y?"":void 0)},getData:n?()=>n().then(y=>y.map(P=>d.id&&g.getIn(P,d.id)).filter(Boolean)):void 0,onValuesChanged:w})}),e.jsx("div",{className:"col-span-12",children:e.jsxs(ie,{children:[!r&&e.jsx(be,{disabled:l,showErrors:o}),r&&e.jsx(ke,{disabled:l})]})}),!r&&e.jsx("div",{className:"col-span-12",children:e.jsx(t.Select,{disabled:l,position:"item-aligned",onValueChange:y=>{p("defaultValue",y)},label:"Default value",value:b??"",children:F.filter(y=>!!y?.id).map(y=>e.jsx(t.SelectItem,{value:y.id?.toString(),children:y.label},y.id))})})]})}const Ne={"image/*":"Images","video/*":"Videos","audio/*":"Audio files","application/*":"Files (pdf, zip, csv, excel...)","text/*":"Text files"};function $e({multiple:r,existing:a,disabled:l}){const{values:o,setFieldValue:s}=g.useFormikContext(),n=r?"of.storage":"storage",d=`${n}.acceptedFiles`,h=`${n}.fileName`,f=`${n}.storagePath`,u=`${n}.storeUrl`,c=g.getIn(o,h)??"{rand}_{file}",p=g.getIn(o,f)??"/",T=g.getIn(o,d),m=Array.isArray(T)?T:void 0,b=!m||m.length===0,N=y=>{y?y.includes("all")||y.length>=Object.keys(Ne).length?s(d,void 0):b?s(d,Object.keys(Ne).filter(P=>!y.includes(P))):s(d,y):s(d,void 0)},F=typeof c=="function",w=typeof p=="function";return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"col-span-12",children:e.jsx(t.ExpandablePanel,{title:e.jsxs("div",{className:"flex flex-row text-gray-500",children:[e.jsx(t.FileUploadIcon,{}),e.jsx(t.Typography,{variant:"subtitle2",className:"ml-2",children:"File upload config"})]}),children:e.jsxs("div",{className:"grid grid-cols-12 gap-2 p-4",children:[e.jsx("div",{className:"col-span-12",children:e.jsxs(t.MultiSelect,{disabled:l,name:d,value:m??[],onMultiValueChange:N,label:b?void 0:"Allowed file types",renderValues:y=>!y||y.length===0?"All file types allowed":y.map(P=>Ne[P]).filter(P=>!!P).join(", "),children:[e.jsxs(t.MultiSelectItem,{value:"all",className:"flex items-center gap-2",children:[e.jsx(t.Checkbox,{checked:!m}),"All"]},"all"),Object.entries(Ne).map(([y,P])=>e.jsxs(t.MultiSelectItem,{value:y,className:"flex items-center gap-2",children:[e.jsx(t.Checkbox,{checked:b||m.indexOf(y)>-1}),e.jsx("div",{className:"flex-grow",children:P}),e.jsx(t.Button,{size:"small",variant:"outlined",onClick:x=>(x.preventDefault(),x.stopPropagation(),s(d,[y])),children:"Only"})]},y))]})}),e.jsx("div",{className:"col-span-12",children:e.jsx(g.Field,{name:h,as:t.DebouncedTextField,label:"File name",size:"small",disabled:F||l,value:F?"-":c})}),e.jsxs("div",{className:"col-span-12",children:[e.jsx(g.Field,{name:f,as:t.DebouncedTextField,label:"Storage path",disabled:w||l,size:"small",value:w?"-":p}),e.jsxs(t.Typography,{variant:"caption",className:"ml-3.5 mt-1 mb-2",children:[e.jsx("p",{children:"You can use the following placeholders in the file name and storage path values:"}),e.jsxs("ul",{children:[e.jsx("li",{children:"{file} - Full name of the uploaded file"}),e.jsx("li",{children:"{file.name} - Name of the uploaded file without extension"}),e.jsx("li",{children:"{file.ext} - Extension of the uploaded file"}),e.jsx("li",{children:"{entityId} - ID of the entity"}),e.jsx("li",{children:"{propertyKey} - ID of this field"}),e.jsx("li",{children:"{path} - Path of this entity"}),e.jsx("li",{children:"{rand} - Random value used to avoid name collisions"})]})]}),e.jsx(g.Field,{type:"checkbox",name:u,label:"Save URL instead of storage path",disabled:a||l,component:i.SwitchControl}),e.jsx("br",{}),e.jsx(t.Typography,{variant:"caption",className:"ml-3.5 mt-1 mb-2",children:"Turn this setting on, if you prefer to save the download URL of the uploaded file instead of the storage path. You can only change this prop upon creation."})]})]})})}),e.jsx("div",{className:"col-span-12",children:e.jsxs(ie,{children:[!r&&e.jsx("div",{className:"grid grid-cols-12 gap-2",children:e.jsx(fe,{disabled:l})}),r&&e.jsx("div",{className:"col-span-12",children:e.jsx(ke,{disabled:l})})]})})]})}function Ce(r){if(i.isPropertyBuilder(r)||i.isPropertyBuilder(r))return!1;{const a=r;return a.dataType==="array"&&typeof a.of=="function"||a.dataType==="array"&&Array.isArray(a.of)?!1:!!a.editable}}function je(r){return Object.entries(r).filter(([a,l])=>Ce(l)).map(([a,l])=>{const o=l;if(Ce(o))return o.dataType==="map"&&o.properties?{[a]:{...o,properties:je(o.properties)}}:{[a]:o}}).filter(a=>!!a).reduce((a,l)=>({...a,...l}),{})}function Ye({property:r,onClick:a,hasError:l,includeName:o,includeEditButton:s,selected:n}){const{propertyConfigs:d}=i.useCustomizationController(),h=i.getFieldConfig(r,d);Ce(r);const f=l?"border-red-500":n?"border-primary":"border-transparent";return e.jsx(i.ErrorBoundary,{children:e.jsxs("div",{onClick:a,className:"flex flex-row w-full cursor-pointer",children:[e.jsx("div",{className:"m-4",children:e.jsx(i.PropertyConfigBadge,{propertyConfig:h})}),e.jsxs(t.Paper,{className:t.cn("pl-2 w-full flex flex-row gap-4 items-center",t.cardMixin,a?t.cardClickableMixin:"",n?t.cardSelectedMixin:"","flex-grow p-4 border transition-colors duration-200",f),children:[e.jsxs("div",{className:"w-full flex flex-col",children:[o&&e.jsx(i.ErrorBoundary,{children:e.jsx(t.Typography,{variant:"body1",component:"span",className:"flex-grow pr-2",children:r.name?r.name:" "})}),e.jsxs("div",{className:"flex flex-row items-center",children:[e.jsx(i.ErrorBoundary,{children:e.jsx(t.Typography,{className:"flex-grow pr-2",variant:o?"body2":"subtitle1",component:"span",color:"secondary",children:h?.name})}),e.jsx(i.ErrorBoundary,{children:e.jsx(t.Typography,{variant:"body2",component:"span",color:"disabled",children:r.dataType})})]})]}),s&&e.jsx(t.Typography,{variant:"button",children:"EDIT"})]})]})})}function Tr({name:r,selected:a,onClick:l,property:o}){const{propertyConfigs:s}=i.useCustomizationController(),n=!i.isPropertyBuilder(o)&&o?i.getFieldConfig(o,s):void 0;return e.jsxs("div",{onClick:l,className:"flex flex-row w-full cursor-pointer",children:[e.jsxs("div",{className:"relative m-4",children:[n&&e.jsx(i.PropertyConfigBadge,{propertyConfig:n}),!n&&e.jsx("div",{className:"h-8 w-8 p-1 rounded-full shadow text-white bg-gray-500",children:e.jsx(t.FunctionsIcon,{color:"inherit",size:"medium"})}),e.jsx(t.RemoveCircleIcon,{color:"disabled",size:"small",className:"absolute -right-2 -top-2"})]}),e.jsx(t.Paper,{className:t.cn("pl-2 w-full flex flex-row gap-4 items-center",t.cardMixin,l?t.cardClickableMixin:"",a?t.cardSelectedMixin:"","flex-grow p-4 border transition-colors duration-200",a?"border-primary":"border-transparent"),children:e.jsxs("div",{className:"w-full flex flex-col",children:[e.jsx(t.Typography,{variant:"body1",component:"span",className:"flex-grow pr-2",children:o?.name?o.name:r}),e.jsxs("div",{className:"flex flex-row items-center",children:[n&&e.jsx(t.Typography,{className:"flex-grow pr-2",variant:"body2",component:"span",color:"secondary",children:n?.name}),o&&!i.isPropertyBuilder(o)&&e.jsx(i.ErrorBoundary,{children:e.jsx(t.Typography,{variant:"body2",component:"span",color:"disabled",children:o.dataType})}),o&&i.isPropertyBuilder(o)&&e.jsx(i.ErrorBoundary,{children:e.jsx(t.Typography,{variant:"body2",component:"span",color:"disabled",children:"This property is defined as a property builder in code"})}),!o&&e.jsx(i.ErrorBoundary,{children:e.jsx(t.Typography,{variant:"body2",component:"span",color:"disabled",children:"This field is defined as an additional field in code"})})]})]})})]})}function we({namespace:r,selectedPropertyKey:a,onPropertyClick:l,properties:o,propertiesOrder:s,additionalFields:n,errors:d,onPropertyMove:h,onPropertyRemove:f,className:u,inferredPropertyKeys:c,collectionEditable:p}){const T=s??Object.keys(o),m=C.useCallback(b=>{if(!b.destination)return;const N=b.source.index,F=b.destination.index,w=Array.from(T),[y]=w.splice(N,1);w.splice(F,0,y),h&&h(w,r)},[r,h,T]);return e.jsx(e.Fragment,{children:e.jsx(_e.DragDropContext,{onDragEnd:m,children:e.jsx(_e.Droppable,{droppableId:`droppable_${r}`,children:(b,N)=>e.jsxs("div",{...b.droppableProps,ref:b.innerRef,className:u,children:[T&&T.map((F,w)=>{const y=o[F],P=n?.find(x=>x.key===F);return!y&&!P?(console.warn(`Property ${F} not found in properties or additionalFields`),null):e.jsx(_e.Draggable,{draggableId:`array_field_${r}_${F}}`,index:w,children:(x,v)=>e.jsx(i.ErrorBoundary,{children:e.jsx(Pr,{propertyKey:F,propertyOrBuilder:y,additionalField:P,provided:x,errors:d,namespace:r,inferredPropertyKeys:c,onPropertyMove:h,onPropertyRemove:f,onPropertyClick:v.isDragging?void 0:l,selectedPropertyKey:a,collectionEditable:p})})},`array_field_${r}_${F}}`)}).filter(Boolean),b.placeholder]})})})})}function Pr({propertyKey:r,namespace:a,propertyOrBuilder:l,additionalField:o,provided:s,selectedPropertyKey:n,errors:d,onPropertyClick:h,onPropertyMove:f,onPropertyRemove:u,inferredPropertyKeys:c,collectionEditable:p}){const T=c?.includes(a?`${a}.${r}`:r),m=K(r,a);let b;if(typeof l=="object"){const y=l;y.dataType==="map"&&y.properties&&(b=e.jsx(we,{selectedPropertyKey:n,namespace:m,properties:y.properties,propertiesOrder:y.propertiesOrder,errors:d,onPropertyClick:h,onPropertyMove:f,onPropertyRemove:u,collectionEditable:p}))}const N=m?g.getIn(d,te(m)):!1,F=n===m,w=l&&(p&&!i.isPropertyBuilder(l)||Ce(l));return e.jsxs("div",{ref:s.innerRef,...s.draggableProps,...s.dragHandleProps,className:"relative -ml-8",children:[b&&e.jsx("div",{className:"absolute border-l "+t.defaultBorderMixin,style:{left:"32px",top:"64px",bottom:"16px"}}),!i.isPropertyBuilder(l)&&!o&&w?e.jsx(Ye,{property:l,onClick:h?()=>h(r,a):void 0,includeName:!0,selected:F,hasError:N}):e.jsx(Tr,{name:r,property:l,onClick:h?()=>h(r,a):void 0,selected:F}),e.jsxs("div",{className:"absolute top-2 right-2 flex flex-row ",children:[T&&e.jsx(t.Tooltip,{title:"Inferred property",children:e.jsx(t.AutoAwesomeIcon,{size:"small",className:"p-2"})}),u&&e.jsx(t.Tooltip,{title:"Remove",children:e.jsx(t.IconButton,{size:"small",color:"inherit",onClick:()=>u(r,a),children:e.jsx(t.RemoveIcon,{size:"small"})})}),f&&e.jsx(t.Tooltip,{title:"Move",children:e.jsx(t.IconButton,{component:"span",size:"small",children:e.jsx(t.DragHandleIcon,{size:"small"})})})]}),b&&e.jsx("div",{className:"ml-16",children:b})]})}function xr({disabled:r,getData:a,allowDataInference:l,propertyConfigs:o,collectionEditable:s}){const{values:n,setFieldValue:d}=g.useFormikContext(),[h,f]=C.useState(!1),[u,c]=C.useState(),[p,T]=C.useState(),m=n.propertiesOrder??Object.keys(n.properties??{}),b=C.useCallback(({id:v,property:E})=>{if(!v)throw Error();d("properties",{...n.properties??{},[v]:E},!1),d("propertiesOrder",[...m,v],!1),f(!1)},[n.properties,m]),N=C.useCallback((v,E)=>{const U=v?K(v,E):void 0;if(!U)throw Error("collection editor miss config");const D=te(U),V=oe(E),L=g.getIn(n,V)??Object.keys(g.getIn(n,qe(E)));d(D,void 0,!1),d(V,L.filter(O=>O!==v),!1),f(!1),c(void 0),T(void 0)},[d,n]),F=u?K(u,p):void 0,w=F?g.getIn(n.properties,F.replaceAll(".",".properties.")):void 0,y=e.jsxs(t.Button,{color:"primary",variant:"outlined",onClick:()=>f(!0),startIcon:e.jsx(t.AddIcon,{}),children:["Add property to ",n.name??"this group"]}),P=!m||m.length<1,x=C.useCallback((v,E)=>{d(oe(E),v,!1)},[]);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"col-span-12",children:[e.jsxs("div",{className:"flex justify-between items-end my-4",children:[e.jsx(t.Typography,{variant:"subtitle2",children:"Properties in this group"}),y]}),e.jsxs(t.Paper,{className:"p-2 pl-8",children:[e.jsx(we,{properties:n.properties??{},propertiesOrder:m,errors:{},collectionEditable:s,onPropertyClick:(v,E)=>{c(v),T(E),f(!0)},onPropertyMove:x}),P&&e.jsx(t.Typography,{variant:"label",className:"h-full flex items-center justify-center p-4",children:"Add the first property to this group"})]})]}),e.jsxs("div",{className:"col-span-12",children:[e.jsx(t.BooleanSwitchWithLabel,{position:"start",size:"small",label:"Spread children as columns",onValueChange:v=>d("spreadChildren",v),value:n.spreadChildren??!1}),e.jsx(H,{children:"Set this flag to true if you want to display the children of this group as individual columns."})]}),e.jsx(ge,{inArray:!1,forceShowErrors:!1,open:h,allowDataInference:l,collectionEditable:s,onCancel:()=>{f(!1),c(void 0),T(void 0)},onOkClicked:()=>{f(!1),c(void 0),T(void 0)},getData:a,onDelete:N,propertyKey:u,propertyNamespace:p,property:w,existingProperty:!!u,autoUpdateId:!u,autoOpenTypeSelect:!u,onPropertyChanged:b,existingPropertyKeys:u?void 0:m,propertyConfigs:o})]})}function Fr({showErrors:r,existing:a,disabled:l,getData:o,allowDataInference:s,propertyConfigs:n,collectionEditable:d}){const{values:h,handleChange:f,errors:u,setFieldValue:c,touched:p}=g.useFormikContext(),[T,m]=C.useState(!1),b=g.getIn(h,"of"),N=g.getIn(p,"of")&&g.getIn(u,"of"),F=C.useCallback(({id:y,property:P,namespace:x})=>{c("of",P)},[]),w=b&&i.getFieldConfig(b,n);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"col-span-12",children:[e.jsx(t.Typography,{variant:"subtitle2",children:"Repeat component"}),e.jsx(g.Field,{name:"of",value:b,validate:y=>y?.dataType?void 0:"You need to specify a repeat field",children:()=>e.jsxs(t.Paper,{className:"p-2 mt-4",children:[b&&e.jsx(Ye,{property:b,onClick:l?void 0:()=>m(!0),includeName:!1,includeEditButton:!0,selected:!1,hasError:!1}),!l&&!b&&e.jsxs(t.Button,{variant:"text",size:"large",color:N?"error":"primary",onClick:()=>m(!0),children:["Edit ",`${w?w.name:"repeat component"}`]}),e.jsx(ge,{inArray:!0,open:T,existingProperty:a,getData:o,autoUpdateId:!a,autoOpenTypeSelect:!a,onOkClicked:()=>m(!1),allowDataInference:s,property:b,includeIdAndName:!1,onPropertyChanged:F,forceShowErrors:r,propertyConfigs:n,collectionEditable:d})]})})]}),e.jsx("div",{className:"col-span-12",children:e.jsx(ie,{children:e.jsx(ke,{disabled:l})})})]})}const Nr=C.forwardRef(function({showErrors:a,disabledId:l,existingPropertyKeys:o,disabled:s,autoUpdateId:n,isNewProperty:d},h){const{errors:f,values:u,setFieldValue:c,setFieldTouched:p,touched:T}=g.useFormikContext(),m="name",b=a&&g.getIn(f,m),N="id",F=a&&g.getIn(f,N),w="description",y=a&&g.getIn(f,w);return e.jsxs("div",{className:"flex flex-col gap-2 col-span-12",children:[e.jsxs("div",{children:[e.jsx(g.Field,{inputRef:h,as:t.DebouncedTextField,value:u[m],onChange:P=>{const x=P.target.value;c(m,x),p(m,!0,!0),!g.getIn(T,N)&&n&&c(N,x?i.toSnakeCase(x):"")},style:{fontSize:20},validate:Sr,placeholder:"Field name",required:!0,disabled:s,error:!!b}),e.jsx(H,{error:!!b,children:b})]}),e.jsxs("div",{children:[e.jsx(g.Field,{as:t.DebouncedTextField,label:"ID",value:u[N],onChange:P=>{const x=P.target.value;c(N,x),p(N,!0,!0),!g.getIn(T,m)&&n&&c(m,x?i.unslugify(x):"")},validate:()=>Ir(u[N],o),disabled:l||s,required:!0,size:"small",error:!!F}),e.jsx(H,{error:!!F,children:F})]}),e.jsxs("div",{children:[e.jsx(g.Field,{name:w,as:t.DebouncedTextField,label:"Description",disabled:s,error:!!y}),e.jsx(H,{error:!!y,children:y})]})]})}),wr=/^[a-zA-Z_][a-zA-Z0-9_]*$/;function Ir(r,a){let l;return r||(l="You must specify an id for the field"),r&&!r.match(wr)&&(l="The id can only contain letters, numbers and underscores (_), and not start with a number"),r&&a&&a.includes(r)&&(l="There is another field with this ID already"),l}function Sr(r){let a;return r||(a="You must specify a title for the field"),a}function Or({widgetId:r,disabled:a,showErrors:l}){const{values:o,setFieldValue:s}=g.useFormikContext();return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"col-span-12",children:e.jsxs(ie,{children:[r==="text_field"&&e.jsx(be,{disabled:a,length:!0,lowercase:!0,matches:!0,max:!0,min:!0,trim:!0,uppercase:!0,showErrors:l}),r==="multiline"&&e.jsx(be,{disabled:a,length:!0,lowercase:!0,max:!0,min:!0,trim:!0,uppercase:!0,showErrors:l}),r==="markdown"&&e.jsx(be,{disabled:a,length:!0,lowercase:!0,max:!0,min:!0,trim:!0,uppercase:!0,showErrors:l}),r==="email"&&e.jsx(be,{disabled:a,max:!0,min:!0,trim:!0,showErrors:l})]})}),e.jsx("div",{className:"col-span-12",children:e.jsx(t.TextField,{name:"defaultValue",disabled:a,onChange:n=>{s("defaultValue",n.target.value===""?void 0:n.target.value)},label:"Default value",value:g.getIn(o,"defaultValue")??""})})]})}function Vr({disabled:r}){const{values:a}=g.useFormikContext(),l=g.getIn(a,"defaultValue");return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"col-span-12",children:e.jsx(ie,{children:e.jsx(fe,{disabled:r})})}),e.jsx("div",{className:"col-span-12",children:e.jsx(g.FastField,{type:"checkbox",name:"defaultValue",label:l==null?"Default value not set":"Default value is "+l.toString(),disabled:r,allowIndeterminate:!0,component:i.SwitchControl})})]})}function Er({disabled:r,getData:a,allowDataInference:l,propertyConfigs:o,collectionEditable:s}){const{values:n,setFieldValue:d}=g.useFormikContext(),[h,f]=C.useState(!1),[u,c]=C.useState(),[p,T]=C.useState(),m=C.useCallback(({id:P,property:x})=>{if(!P)throw Error();d("oneOf.properties",{...n.oneOf?.properties??{},[P]:x},!1),d("oneOf.propertiesOrder",[...n.oneOf?.propertiesOrder??Object.keys(n.oneOf?.properties??{}),P],!1),f(!1)},[n.oneOf?.properties,n.oneOf?.propertiesOrder]),b=u?K(u,p):void 0,N=b?g.getIn(n.oneOf?.properties,b.replaceAll(".",".properties.")):void 0,F=C.useCallback((P,x)=>{const v=P?K(P,x):void 0;if(!v)throw Error("collection editor miss config");d(`oneOf.${te(v)}`,void 0,!1);const E=`oneOf.${oe(x)}`,U=g.getIn(n,E);d(E,U.filter(D=>D!==P),!1),f(!1),c(void 0),T(void 0)},[d,n]),w=e.jsxs(t.Button,{autoFocus:!0,color:"primary",onClick:()=>f(!0),startIcon:e.jsx(t.AddIcon,{}),children:["Add property to ",n.name??"this block"]}),y=C.useCallback((P,x)=>{d(`oneOf.${oe(x)}`,P,!1)},[]);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"col-span-12",children:[e.jsxs("div",{className:"flex justify-between items-end mt-8 mb-4",children:[e.jsx(t.Typography,{variant:"subtitle2",children:"Properties in this block"}),w]}),e.jsxs(t.Paper,{className:"p-2 pl-8",children:[e.jsx(we,{properties:n.oneOf?.properties??{},propertiesOrder:n.oneOf?.propertiesOrder,errors:{},collectionEditable:s,onPropertyClick:r?void 0:(P,x)=>{c(P),T(x),f(!0)},onPropertyMove:r?void 0:y}),!r&&!n.oneOf?.propertiesOrder?.length&&e.jsx("div",{className:"h-full flex items-center justify-center p-4",children:"Add the first property to this block"})]})]}),!r&&e.jsx(ge,{inArray:!1,forceShowErrors:!1,open:h,getData:a,allowDataInference:l,onCancel:()=>{f(!1),c(void 0),T(void 0)},onOkClicked:()=>{f(!1),c(void 0),T(void 0)},collectionEditable:s,onDelete:F,propertyKey:u,propertyNamespace:p,property:N,existingProperty:!!u,autoUpdateId:!u,autoOpenTypeSelect:!u,onPropertyChanged:m,existingPropertyKeys:u?void 0:n.oneOf?.propertiesOrder,propertyConfigs:o})]})}function Br({disabled:r}){const{values:a,handleChange:l}=g.useFormikContext(),o="validation.min",s="validation.max",n="validation.lessThan",d="validation.moreThan",h="validation.positive",f="validation.negative",u="validation.integer";return e.jsxs("div",{className:"grid grid-cols-12 gap-2",children:[e.jsx(fe,{disabled:r}),e.jsx("div",{className:"col-span-6",children:e.jsx(t.DebouncedTextField,{value:g.getIn(a,o),label:"Min value",name:o,type:"number",size:"small",disabled:r,onChange:l})}),e.jsx("div",{className:"col-span-6",children:e.jsx(t.DebouncedTextField,{value:g.getIn(a,s),label:"Max value",name:s,type:"number",size:"small",disabled:r,onChange:l})}),e.jsx("div",{className:"col-span-6",children:e.jsx(t.DebouncedTextField,{value:g.getIn(a,n),label:"Less than",name:n,type:"number",size:"small",disabled:r,onChange:l})}),e.jsx("div",{className:"col-span-6",children:e.jsx(t.DebouncedTextField,{value:g.getIn(a,d),label:"More than",name:d,type:"number",size:"small",disabled:r,onChange:l})}),e.jsx("div",{className:"col-span-4",children:e.jsx(g.FastField,{type:"checkbox",name:h,label:"Positive value",disabled:r,component:i.SwitchControl})}),e.jsx("div",{className:"col-span-4",children:e.jsx(g.FastField,{type:"checkbox",name:f,label:"Negative value",disabled:r,component:i.SwitchControl})}),e.jsx("div",{className:"col-span-4",children:e.jsx(g.FastField,{type:"checkbox",name:u,label:"Integer value",disabled:r,component:i.SwitchControl})})]})}function Dr({disabled:r}){const{values:a,setFieldValue:l}=g.useFormikContext();return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"col-span-12",children:e.jsx(ie,{children:e.jsx(Br,{disabled:r})})}),e.jsx("div",{className:"col-span-12",children:e.jsx(t.TextField,{name:"defaultValue",disabled:r,type:"number",onChange:o=>{l("defaultValue",o.target.value===""?void 0:parseFloat(o.target.value))},label:"Default value",value:g.getIn(a,"defaultValue")??""})})]})}function Ge({existing:r,multiple:a,disabled:l,showErrors:o}){const{values:s,handleChange:n,errors:d}=g.useFormikContext();if(!i.useNavigationController())return e.jsx("div",{className:"col-span-12",children:e.jsx(t.CircularProgress,{})});const f=a?"of.path":"path",u=g.getIn(s,f),c=o&&g.getIn(d,f);return e.jsx(e.Fragment,{children:e.jsx("div",{className:"col-span-12",children:e.jsx(g.Field,{required:!0,name:f,pathPath:f,type:"select",validate:_r,disabled:r||l,value:u,error:c,handleChange:n,component:kr})})})}function _r(r){let a;return r||(a="You must specify a target collection for the field"),a}function kr({disabled:r,pathPath:a,value:l,handleChange:o,error:s,...n}){const d=i.useNavigationController();if(!d)return e.jsx("div",{className:"col-span-12",children:e.jsx(t.CircularProgress,{})});const h=d?.collections??[],f=Array.from(new Set(Object.values(h).map(c=>c.group).filter(Boolean)).values()),u=h.filter(c=>!c.group);return e.jsxs(e.Fragment,{children:[e.jsxs(t.Select,{error:!!s,disabled:r,value:l??"",position:"item-aligned",name:a,onChange:o,label:"Target collection",renderValue:c=>{const p=h.find(T=>T.id===c||T.path===c);return p?e.jsxs("div",{className:"flex flex-row",children:[e.jsx(i.IconForView,{collectionOrView:p}),e.jsx(t.Typography,{variant:"subtitle2",className:"font-medium ml-4",children:p?.name.toUpperCase()})]}):null},...n,children:[f.flatMap(c=>e.jsx(t.SelectGroup,{label:c||"Views",children:h.filter(p=>p.group===c).map(p=>e.jsx(t.SelectItem,{value:p.id??p.path,children:e.jsxs("div",{className:"flex flex-row",children:[e.jsx(i.IconForView,{collectionOrView:p}),e.jsx(t.Typography,{variant:"subtitle2",className:"font-medium ml-4",children:p?.name.toUpperCase()})]})},`${p.id??p.path}-${c}`))},`group_${c}`)),u&&e.jsx(t.SelectGroup,{label:"Views",children:u.map(c=>e.jsx(t.SelectItem,{value:c.id??c.path,children:e.jsxs("div",{className:"flex flex-row",children:[e.jsx(i.IconForView,{collectionOrView:c}),e.jsx(t.Typography,{variant:"subtitle2",className:"font-medium ml-4",children:c?.name.toUpperCase()})]})},c.id??c.path))})]}),e.jsx(H,{children:"You can only edit the reference collection upon field creation."})]})}function Ar({disabled:r}){const{values:a,errors:l,touched:o,setFieldValue:s}=g.useFormikContext(),n="mode",d=g.getIn(a,n),h=g.getIn(o,n)&&g.getIn(l,n),f="autoValue",u=g.getIn(a,f),c=g.getIn(o,f)&&g.getIn(l,f);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col col-span-12",children:[e.jsxs(t.Select,{name:n,value:d??"date",error:!!h,onValueChange:p=>s(n,p),label:"Mode",renderValue:p=>{switch(p){case"date_time":return"Date/Time";case"date":return"Date";default:return""}},disabled:r,children:[e.jsx(t.SelectItem,{value:"date_time",children:" Date/Time "}),e.jsx(t.SelectItem,{value:"date",children:" Date "})]}),e.jsx(H,{error:!!h,children:h}),e.jsxs(t.Select,{name:f,disabled:r,value:u??"",onValueChange:p=>s(f,p),renderValue:p=>{switch(p){case"on_create":return"On create";case"on_update":return"On any update";default:return"None"}},error:!!c,label:"Automatic value",children:[e.jsx(t.SelectItem,{value:"",children:" None "}),e.jsx(t.SelectItem,{value:"on_create",children:" On create "}),e.jsx(t.SelectItem,{value:"on_update",children:" On any update "})]}),e.jsx(H,{error:!!c,children:c??"Update this field automatically when creating or updating the entity"})]}),e.jsx("div",{className:"col-span-12",children:e.jsx(ie,{children:e.jsx(fe,{disabled:r})})})]})}function Mr({disabled:r}){g.useFormikContext();const a="hideFromCollection",l="readOnly";return e.jsxs("div",{className:"grid grid-cols-12 gap-2",children:[e.jsx("div",{className:"col-span-12",children:e.jsx(g.FastField,{type:"checkbox",name:a,label:"Hide from collection",disabled:r,tooltip:"Hide this field from the collection view. It will still be visible in the form view",component:i.SwitchControl})}),e.jsx("div",{className:"col-span-12",children:e.jsx(g.FastField,{type:"checkbox",name:l,label:"Read only",disabled:r,tooltip:"Is this a read only field. Display only as a preview",component:i.SwitchControl})})]})}function zr({disabled:r}){return e.jsx(e.Fragment,{children:e.jsx("div",{className:"col-span-12",children:e.jsx(ie,{children:e.jsx(fe,{disabled:r})})})})}function He(r,a,l){let o;return a==="text_field"?o=i.mergeDeep(r,{dataType:"string",propertyConfig:"text_field",editable:r.editable!==void 0?r.editable:!0,storage:void 0,multiline:void 0,markdown:void 0,email:void 0,url:void 0,enumValues:void 0}):a==="multiline"?o=i.mergeDeep(r,{dataType:"string",propertyConfig:"multiline",editable:r.editable!==void 0?r.editable:!0,multiline:!0,storage:void 0,markdown:void 0,email:void 0,url:void 0,enumValues:void 0}):a==="markdown"?o=i.mergeDeep(r,{dataType:"string",propertyConfig:"markdown",editable:r.editable!==void 0?r.editable:!0,storage:void 0,multiline:void 0,markdown:!0,email:void 0,url:void 0}):a==="url"?o=i.mergeDeep(r,{dataType:"string",propertyConfig:"url",editable:r.editable!==void 0?r.editable:!0,storage:void 0,multiline:void 0,markdown:void 0,email:void 0,url:!0,enumValues:void 0}):a==="email"?o=i.mergeDeep(r,{dataType:"string",propertyConfig:"email",editable:r.editable!==void 0?r.editable:!0,storage:void 0,multiline:void 0,markdown:void 0,email:!0,url:void 0,enumValues:void 0}):a==="select"?o=i.mergeDeep(r,{dataType:"string",propertyConfig:"select",editable:r.editable!==void 0?r.editable:!0,storage:void 0,multiline:void 0,markdown:void 0,email:void 0,url:void 0,enumValues:r.enumValues??[]}):a==="multi_select"?o=i.mergeDeep(r,{dataType:"array",propertyConfig:"multi_select",editable:r.editable!==void 0?r.editable:!0,of:{dataType:"string",enumValues:r.of?.enumValues??[]}}):a==="number_input"?o=i.mergeDeep(r,{dataType:"number",propertyConfig:"number_input",editable:r.editable!==void 0?r.editable:!0,enumValues:void 0}):a==="number_select"?o=i.mergeDeep(r,{dataType:"number",propertyConfig:"number_select",editable:r.editable!==void 0?r.editable:!0,enumValues:r.enumValues??[]}):a==="multi_number_select"?o=i.mergeDeep(r,{dataType:"array",propertyConfig:"multi_number_select",editable:r.editable!==void 0?r.editable:!0,of:{dataType:"number",enumValues:r.of?.enumValues??[]}}):a==="file_upload"?o=i.mergeDeep(r,{dataType:"string",propertyConfig:"file_upload",editable:r.editable!==void 0?r.editable:!0,storage:{storagePath:"/"}}):a==="multi_file_upload"?o=i.mergeDeep(r,{dataType:"array",propertyConfig:"multi_file_upload",editable:r.editable!==void 0?r.editable:!0,of:{dataType:"string",storage:r.of?.storage??{storagePath:"/"}}}):a==="group"?o=i.mergeDeep(r,{dataType:"map",propertyConfig:"group",editable:r.editable!==void 0?r.editable:!0,keyValue:!1,properties:r.properties??{}}):a==="key_value"?o=i.mergeDeep(r,{dataType:"map",propertyConfig:"key_value",editable:r.editable!==void 0?r.editable:!0,keyValue:!0,properties:void 0}):a==="reference"?o=i.mergeDeep(r,{dataType:"reference",propertyConfig:"reference",editable:r.editable!==void 0?r.editable:!0}):a==="multi_references"?o=i.mergeDeep(r,{dataType:"array",propertyConfig:"multi_references",editable:r.editable!==void 0?r.editable:!0,of:{dataType:"reference"}}):a==="switch"?o=i.mergeDeep(r,{dataType:"boolean",propertyConfig:"switch",editable:r.editable!==void 0?r.editable:!0}):a==="date_time"?o=i.mergeDeep(r,{dataType:"date",propertyConfig:"date_time",editable:r.editable!==void 0?r.editable:!0,mode:"date_time"}):a==="repeat"?o=i.mergeDeep(r,{dataType:"array",propertyConfig:"repeat",editable:r.editable!==void 0?r.editable:!0}):a==="block"?o=i.mergeDeep(r,{dataType:"array",propertyConfig:"block",editable:r.editable!==void 0?r.editable:!0,oneOf:{properties:{}}}):a&&l[a]&&(o={...l[a].property,propertyConfig:a}),o}function Ke({value:r,optionDisabled:a,propertyConfig:l,existing:o}){return e.jsx(t.SelectItem,{value:r,disabled:a,className:"flex flex-row items-center",children:e.jsxs("div",{className:t.cn("flex flex-row items-center text-base min-h-[52px]",a?"w-full":""),children:[e.jsx("div",{className:"mr-8",children:e.jsx(i.PropertyConfigBadge,{propertyConfig:l})}),e.jsxs("div",{children:[e.jsx("div",{children:l.name}),e.jsx(t.Typography,{variant:"caption",color:"disabled",className:"max-w-sm",children:o&&a?"You can only switch to widgets that use the same data type":l.description})]})]})})}function Ur({disabled:r,showErrors:a}){const{values:l,setFieldValue:o}=g.useFormikContext(),s=g.getIn(l,"url");return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"col-span-12",children:e.jsxs(t.Select,{disabled:r,position:"item-aligned",onValueChange:n=>{n==="[NONE]"?o("url",!0):o("url",n)},label:"Preview type",renderValue:n=>{switch(n){case"image":return"Image";case"video":return"Video";case"audio":return"Audio";default:return"Display URL"}},value:s??"[NONE]",children:[e.jsx(t.SelectItem,{value:"[NONE]",children:"Display URL"}),e.jsx(t.SelectItem,{value:"image",children:"Image"}),e.jsx(t.SelectItem,{value:"video",children:"Video"}),e.jsx(t.SelectItem,{value:"audio",children:"Audio"})]})}),e.jsx("div",{className:"col-span-12",children:e.jsx(ie,{children:e.jsx(be,{disabled:r,max:!0,min:!0,trim:!0,showErrors:a})})}),e.jsx("div",{className:"col-span-12",children:e.jsx(t.TextField,{name:"defaultValue",disabled:r,onChange:n=>{o("defaultValue",n.target.value===""?void 0:n.target.value)},label:"Default value",value:g.getIn(l,"defaultValue")??""})})]})}const qr=["text_field","multiline","markdown","url","email","select","multi_select","number_input","number_select","multi_number_select","file_upload","multi_file_upload","reference","multi_references","switch","date_time","group","key_value","repeat","block"],We=Object.entries(i.DEFAULT_FIELD_CONFIGS).filter(([r])=>qr.includes(r)).map(([r,a])=>({[r]:a})).reduce((r,a)=>({...r,...a}),{}),Ze=C.memo(function({includeIdAndName:a=!0,autoOpenTypeSelect:l,existingProperty:o,autoUpdateId:s,inArray:n,propertyKey:d,propertyNamespace:h,property:f,onPropertyChanged:u,onPropertyChangedImmediate:c=!0,onDelete:p,onError:T,initialErrors:m,forceShowErrors:b,existingPropertyKeys:N,allowDataInference:F,getHelpers:w,getData:y,propertyConfigs:P,collectionEditable:x}){const v={id:"",name:""},E=!!(f&&!Ce(f))&&!x,U=C.useRef(f?{id:d,previousId:d,property:f}:void 0),D=({id:V,property:L})=>{const O={id:V,previousId:U.current?.id,property:L,namespace:h};U.current=O,u?.(O)};return e.jsx(g.Formik,{initialErrors:m,initialValues:f?{id:d,...f}:v,onSubmit:(V,L)=>{console.debug("onSubmit",V);const{id:O,...S}=V;D({id:O,property:{...S,editable:S.editable??!0}}),o||L.resetForm({values:v})},children:V=>(C.useEffect(()=>{w?.(V)},[V]),e.jsx(Lr,{onPropertyChanged:c?D:void 0,onDelete:p,includeIdAndTitle:a,propertyNamespace:h,onError:T,showErrors:b||V.submitCount>0,existing:o,autoUpdateId:s,inArray:n,autoOpenTypeSelect:l,existingPropertyKeys:N,disabled:E,getData:y,allowDataInference:F,propertyConfigs:P,collectionEditable:x,...V}))},`property_view_${d}`)},(r,a)=>r.getData===a.getData&&r.includeIdAndName===a.includeIdAndName&&r.autoOpenTypeSelect===a.autoOpenTypeSelect&&r.autoUpdateId===a.autoUpdateId&&r.existingProperty===a.existingProperty);function ge({open:r,onCancel:a,onOkClicked:l,onPropertyChanged:o,getData:s,collectionEditable:n,...d}){const h=C.useRef(),f=u=>{h.current=u};return e.jsxs(t.Dialog,{open:r??!1,maxWidth:"xl",fullWidth:!0,children:[e.jsx(t.DialogContent,{children:e.jsx(Ze,{...d,onPropertyChanged:u=>{o?.(u),l?.()},collectionEditable:n,onPropertyChangedImmediate:!1,getHelpers:f,getData:s})}),e.jsxs(t.DialogActions,{children:[a&&e.jsx(t.Button,{variant:"text",onClick:()=>{a(),h.current?.resetForm()},children:"Cancel"}),e.jsx(t.Button,{variant:"outlined",color:"primary",onClick:()=>h.current?.submitForm(),children:"Ok"})]})]})}function Lr({values:r,errors:a,touched:l,setValues:o,setFieldValue:s,existing:n,autoUpdateId:d=!1,autoOpenTypeSelect:h,includeIdAndTitle:f,onPropertyChanged:u,onDelete:c,propertyNamespace:p,onError:T,showErrors:m,disabled:b,inArray:N,existingPropertyKeys:F,getData:w,allowDataInference:y,propertyConfigs:P,collectionEditable:x}){const[v,E]=C.useState(h),[U,D]=C.useState(!1),[V,L]=C.useState(r?.dataType?i.getFieldId(r):void 0),O=Object.entries(We).concat(Object.entries(P)),S=N?O.filter(([G,Z])=>!i.isPropertyBuilder(Z.property)&&Z.property?.dataType!=="array"):O,z=C.useDeferredValue(r),I=C.useRef(null),k=C.useRef(r),ae=m&&g.getIn(a,"selectedWidget");C.useEffect(()=>{if(u&&(!f||z.id)){const{id:G,...Z}=z;xe(z,k.current)||(u({id:G,property:Z,namespace:p}),k.current=z)}},[z,f,u,p]),C.useEffect(()=>{r?.id&&T&&Object.keys(a).length>0&&T(r?.id,p,a)},[a,T,p,r?.id]);const ce=G=>{L(G),o(He(r,G,P)),setTimeout(()=>{I.current?.focus()},0)};let M;return V==="text_field"||V==="multiline"||V==="markdown"||V==="email"?M=e.jsx(Or,{widgetId:V,disabled:b,showErrors:m}):V==="url"?M=e.jsx(Ur,{disabled:b,showErrors:m}):V==="select"||V==="number_select"?M=e.jsx(Le,{multiselect:!1,allowDataInference:y,updateIds:!n,disabled:b,getData:w,showErrors:m}):V==="multi_select"||V==="multi_number_select"?M=e.jsx(Le,{multiselect:!0,updateIds:!n,disabled:b,allowDataInference:y,getData:w,showErrors:m}):V==="file_upload"?M=e.jsx($e,{existing:n,multiple:!1,disabled:b}):V==="multi_file_upload"?M=e.jsx($e,{existing:n,multiple:!0,disabled:b}):V==="switch"?M=e.jsx(Vr,{disabled:b}):V==="number_input"?M=e.jsx(Dr,{disabled:b}):V==="group"?M=e.jsx(xr,{disabled:b,getData:w,allowDataInference:y,collectionEditable:x,propertyConfigs:P}):V==="block"?M=e.jsx(Er,{disabled:b,getData:w,allowDataInference:y,collectionEditable:x,propertyConfigs:P}):V==="reference"?M=e.jsx(Ge,{showErrors:m,existing:n,multiple:!1,disabled:b}):V==="date_time"?M=e.jsx(Ar,{disabled:b}):V==="multi_references"?M=e.jsx(Ge,{showErrors:m,existing:n,multiple:!0,disabled:b}):V==="repeat"?M=e.jsx(Fr,{showErrors:m,existing:n,getData:w,allowDataInference:y,disabled:b,collectionEditable:x,propertyConfigs:P}):V==="key_value"?M=e.jsx(zr,{disabled:b}):M=null,e.jsxs(e.Fragment,{children:[b&&e.jsxs(t.InfoLabel,{mode:"warn",children:[e.jsx(t.Typography,{children:"This property can't be edited"}),e.jsxs(t.Typography,{variant:"caption",children:["You may not have permission to edit it or it is defined in code with no ",e.jsx("code",{children:"editable"})," flag"]})]}),e.jsxs("div",{className:"flex mt-2 justify-between",children:[e.jsxs("div",{className:"w-full flex flex-col gap-2",children:[e.jsx(t.Select,{error:!!ae,value:V??"",placeholder:"Select a property widget",open:v,onOpenChange:E,position:"item-aligned",disabled:b,renderValue:G=>{if(!G)return e.jsx("em",{children:"Select a property widget"});const Z=G,ee=i.DEFAULT_FIELD_CONFIGS[Z]??P[Z],X=ee.property,ue=X&&!i.isPropertyBuilder(X)?i.getFieldConfig(X,P):void 0,re=i.isPropertyBuilder(X)||n&&X.dataType!==r?.dataType,ne=ue?i.mergeDeep(ue,ee):ee;return e.jsxs("div",{onClick:he=>{re&&(he.stopPropagation(),he.preventDefault())},className:t.cn("flex items-center",re?"w-full pointer-events-none opacity-50":""),children:[e.jsx("div",{className:"mr-8",children:e.jsx(i.PropertyConfigBadge,{propertyConfig:ne})}),e.jsxs("div",{className:"flex flex-col items-start text-base text-left",children:[e.jsx("div",{children:ne.name}),e.jsx(t.Typography,{variant:"caption",color:"disabled",children:re?"You can only switch to widgets that use the same data type":ne.description})]})]})},onValueChange:G=>{ce(G)},children:S.map(([G,Z])=>{const ee=Z.property,X=n&&!i.isPropertyBuilder(ee)&&ee.dataType!==r?.dataType;return e.jsx(Ke,{value:G,optionDisabled:X,propertyConfig:Z,existing:n},G)})}),ae&&e.jsx(t.Typography,{variant:"caption",className:"ml-3.5",color:"error",children:"Required"})]}),c&&r?.id&&e.jsx(t.IconButton,{variant:"ghost",className:"m-4",disabled:b,onClick:()=>D(!0),children:e.jsx(t.DeleteIcon,{})})]}),e.jsxs("div",{className:"grid grid-cols-12 gap-y-12 mt-8 mb-8",children:[f&&e.jsx(Nr,{showErrors:m,disabledId:n,isNewProperty:!n,existingPropertyKeys:F,disabled:b,autoUpdateId:d,ref:I}),M,e.jsx("div",{className:"col-span-12",children:e.jsx(Mr,{disabled:b})})]}),c&&e.jsx(i.DeleteConfirmationDialog,{open:U,onAccept:()=>c(r?.id,p),onCancel:()=>D(!1),title:e.jsx("div",{children:"Delete this property?"}),body:e.jsxs("div",{children:[" This will ",e.jsx("b",{children:"not delete any data"}),", only modify the collection."]})})]})}function $r(r){return(r.slice(0,1).toLowerCase()+r.slice(1)).replace(/([-_ ]){1,}/g," ").split(/[-_ ]/).reduce((a,l)=>a+l[0].toUpperCase()+l.substring(1),"")}function jr({collection:r,onOpenChange:a,open:l}){const o=i.useSnackbarController(),s=`import { EntityCollection } from "firecms";
2
2
 
3
- const `+$r(r.name)+"Collection:EntityCollection = "+pr.stringify(Je(r),null," ");return e.jsxs(t.Dialog,{open:l,onOpenChange:a,maxWidth:"4xl",children:[e.jsxs(t.DialogContent,{children:[e.jsxs(t.Typography,{variant:"h6",className:"my-4",children:["Code for ",r.name]}),e.jsxs(t.Typography,{variant:"body2",className:"my-4 mb-8",children:["If you want to customise the collection in code, you can add this collection code to your CMS app configuration. More info in the ",e.jsx("a",{rel:"noopener noreferrer",href:"https://firecms.co/docs/customization_quickstart",children:"docs"}),"."]}),e.jsx(ze.Highlight,{theme:ze.themes.vsDark,code:s,language:"typescript",children:({className:n,style:d,tokens:h,getLineProps:f,getTokenProps:u})=>e.jsx("pre",{style:d,className:"p-4 rounded text-sm",children:h.map((c,p)=>e.jsx("div",{...f({line:c}),children:c.map((T,m)=>e.jsx("span",{...u({token:T})},m))},p))})})]}),e.jsxs(t.DialogActions,{children:[e.jsxs(t.Button,{variant:"text",size:"small",onClick:n=>(n.stopPropagation(),n.preventDefault(),o.open({type:"success",message:"Copied"}),navigator.clipboard.writeText(s)),children:[e.jsx(t.ContentCopyIcon,{size:"small"}),"Copy to clipboard"]}),e.jsx(t.Button,{onClick:()=>a(!1),children:"Close"})]})]})}function Je(r){const a=l=>{const o={...l};return delete o.fromBuilder,delete o.resolved,delete o.propertiesOrder,delete o.editable,o.type==="map"?{...o,properties:o.properties.map(a)}:o};return{id:r.id,name:r.name,singularName:r.singularName,path:r.path,description:r.description,editable:!0,collectionGroup:r.collectionGroup,icon:r.icon,group:r.group,customId:r.customId,initialFilter:r.initialFilter,initialSort:r.initialSort,properties:Object.entries(r.properties).map(([l,o])=>({[l]:a(o)})).reduce((l,o)=>({...l,...o}),{}),subcollections:(r.subcollections??[]).map(Je)}}function Yr({showErrors:r,isNewCollection:a,propertyErrorsRef:l,onPropertyError:o,setDirty:s,reservedGroups:n,extraIcon:d,getUser:h,getData:f,doCollectionInference:u,propertyConfigs:c,collectionEditable:p}){const{values:T,setFieldValue:m,setFieldError:b,setFieldTouched:N,errors:F,dirty:w}=g.useFormikContext(),y=i.useSnackbarController(),P=i.useLargeLayout(),x=!P,[v,E]=C.useState(),[U,D]=C.useState(),[V,L]=C.useState(),O=U?K(U,V):void 0,S=O?g.getIn(T.properties,O.replaceAll(".",".properties.")):void 0,[z,I]=C.useState(!1),[k,ae]=C.useState(!1),[ce,M]=C.useState(!1),[G,Z]=C.useState([]),ee=C.useRef(T.propertiesOrder?{"":T.propertiesOrder}:{});C.useEffect(()=>{s&&s(w)},[w]);const X=u?()=>{u&&(ae(!0),u(T).then(B=>{if(B&&i.makePropertiesEditable(B.properties),!B){y.open({type:"error",message:"Could not infer properties from data"});return}const j=(B.properties?Object.keys(B.properties):[]).filter(W=>!T.properties[W]);if(j.length===0){y.open({type:"info",message:"No new properties found in existing data"});return}const $={...j.reduce((W,le)=>(W[le]=(B.properties??{})[le],W),{}),...T.properties},J=[...j,...T.propertiesOrder??[]];m("properties",$,!1),re(J),Z(j)}).finally(()=>{ae(!1)}))}:void 0,ue=B=>B?ee.current[B]??g.getIn(T,oe(B)):ee.current[""],re=(B,j)=>{const $=oe(j);m($,B,!1),ee.current[j??""]=B},ne=(B,j)=>{const $=B?K(B,j):void 0;if(!$)throw Error("collection editor miss config");m(te($),void 0,!1);const W=ue(j).filter(le=>le!==B);re(W,j),M(!1),E(void 0),D(void 0),L(void 0)},he=(B,j)=>{m(oe(j),B,!1)},R=({id:B,property:j})=>{if(!B)throw Error("Need to include an ID when creating a new property");m("properties",{...T.properties??{},[B]:j},!1);const $=[...T.propertiesOrder??Object.keys(T.properties),B];re($),M(!1),P&&(E($.indexOf(B)),D(B)),L(void 0)},ye=({id:B,property:j,previousId:$,namespace:J})=>{const W=B?K(B,J):void 0,le=W?te(W):void 0;if($&&$!==B){const Ve=K($,J),Ee=te(Ve),Be=ue(J).map(Te=>Te===$?B:Te).filter(Te=>Te!==void 0);re(Be,J),B&&(E(Be.indexOf(B)),D(B)),m(Ee,void 0,!1),N(Ee,!1,!1)}console.debug("onPropertyChanged",{id:B,property:j,previousId:$,namespace:J,propertyPath:le}),le&&(m(le,j,!1),N(le,!0,!1))},Oe=C.useCallback((B,j,$)=>{const J=B?K(B,j):void 0;if(console.warn("onPropertyErrorInternal",{id:B,namespace:j,error:$,propertyPath:J}),J){const W=$&&Object.keys($).length>0;o(B,j,W?$:void 0),b(te(J),W?"Property error":void 0)}},[]),Me=()=>{E(void 0),D(void 0)},_=U&&l?.current?.properties?l.current.properties[U]:void 0,A=T?.propertiesOrder===void 0||T.propertiesOrder.length===0,Y=T.propertiesOrder?T.propertiesOrder:Object.keys(T.properties),pe=C.useMemo(()=>h(T.ownerId),[h,T.ownerId]),Pe=e.jsxs("div",{className:"grid grid-cols-12 gap-2 h-full bg-gray-50 dark:bg-gray-900",children:[e.jsxs("div",{className:t.cn("p-4 md:p-8 pb-20 md:pb-20","col-span-12 lg:col-span-5 h-full overflow-auto",!x&&"border-r "+t.defaultBorderMixin),children:[e.jsxs("div",{className:"flex my-2",children:[e.jsxs("div",{className:"flex-grow mb-4",children:[e.jsx(g.Field,{name:"name",as:t.DebouncedTextField,invisible:!0,className:"-ml-1",inputClassName:"text-2xl font-headers",placeholder:"Collection name",size:"small",required:!0,error:!!F?.name}),pe&&e.jsxs(t.Typography,{variant:"body2",className:"ml-2",color:"secondary",children:["Created by ",pe.displayName]})]}),d&&e.jsx("div",{className:"ml-4",children:d}),e.jsxs("div",{className:"ml-1 mt-2 flex flex-row gap-2",children:[e.jsx(t.Tooltip,{title:"Get the code for this collection",children:e.jsx(t.IconButton,{variant:"filled",disabled:k,onClick:()=>I(!0),children:e.jsx(t.CodeIcon,{})})}),X&&e.jsx(t.Tooltip,{title:"Add new properties based on data",children:e.jsx(t.IconButton,{variant:"filled",disabled:k,onClick:X,children:k?e.jsx(t.CircularProgress,{size:"small"}):e.jsx(t.AutoAwesomeIcon,{})})}),e.jsx(t.Tooltip,{title:"Add new property",children:e.jsx(t.Button,{variant:"outlined",onClick:()=>M(!0),children:e.jsx(t.AddIcon,{})})})]})]}),e.jsx(i.ErrorBoundary,{children:e.jsx(we,{className:"pl-8",onPropertyClick:(B,j)=>{E(Y.indexOf(B)),D(B),L(j)},inferredPropertyKeys:G,selectedPropertyKey:U?K(U,V):void 0,properties:T.properties,additionalFields:T.additionalFields,propertiesOrder:Y,onPropertyMove:he,onPropertyRemove:a?ne:void 0,collectionEditable:p,errors:r?F:{}})}),e.jsx(t.Button,{className:"mt-8 w-full",color:"primary",variant:"outlined",size:"large",onClick:()=>M(!0),startIcon:e.jsx(t.AddIcon,{}),children:"Add new property"})]}),!x&&e.jsx("div",{className:"col-span-12 lg:col-span-7 ml-2 p-4 md:p-8 h-full overflow-auto pb-20 md:pb-20",children:e.jsxs(t.Paper,{className:"sticky top-8 p-4 min-h-full border border-transparent w-full flex flex-col justify-center ",children:[O&&S&&!i.isPropertyBuilder(S)&&e.jsx(Ze,{inArray:!1,existingProperty:!a,autoUpdateId:!1,allowDataInference:!a,autoOpenTypeSelect:!1,propertyKey:U,propertyNamespace:V,property:S,onPropertyChanged:ye,onDelete:ne,onError:Oe,forceShowErrors:r,initialErrors:_,getData:f,propertyConfigs:c,collectionEditable:p},`edit_view_${v}`),!S&&e.jsx(t.Typography,{variant:"label",className:"flex items-center justify-center h-full",children:A?"Now you can add your first property":"Select a property to edit it"}),S&&i.isPropertyBuilder(S)&&e.jsx(t.Typography,{variant:"label",className:"flex items-center justify-center",children:"This property is defined as a property builder in code"})]})}),x&&e.jsx(ge,{inArray:!1,open:v!==void 0,autoUpdateId:!S,allowDataInference:!a,existingProperty:!0,autoOpenTypeSelect:!1,propertyKey:U,propertyNamespace:V,property:S,onPropertyChanged:ye,onDelete:ne,onError:Oe,forceShowErrors:r,initialErrors:_,getData:f,propertyConfigs:c,collectionEditable:p,onOkClicked:x?Me:void 0},`edit_view_${v}`)]});return e.jsxs(e.Fragment,{children:[Pe,e.jsx(ge,{inArray:!1,existingProperty:!1,autoOpenTypeSelect:!0,autoUpdateId:!0,forceShowErrors:r,open:ce,onCancel:()=>M(!1),onPropertyChanged:R,getData:f,allowDataInference:!a,propertyConfigs:c,collectionEditable:p,existingPropertyKeys:T.propertiesOrder}),e.jsx(jr,{collection:T,open:z,onOpenChange:I})]})}function Gr({open:r,handleOk:a,handleCancel:l,body:o,title:s}){return e.jsxs(t.Dialog,{open:r,onOpenChange:n=>n?l():a(),"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[e.jsxs(t.DialogContent,{children:[e.jsx(t.Typography,{variant:"h6",children:s??"Unsaved changes"}),o&&e.jsx(t.Typography,{children:o}),e.jsx(t.Typography,{children:"Are you sure?"})]}),e.jsxs(t.DialogActions,{children:[e.jsx(t.Button,{variant:"text",onClick:l,autoFocus:!0,children:" Cancel "}),e.jsx(t.Button,{onClick:a,children:" Ok "})]})]})}function Hr({open:r,onClose:a}){const{entityViews:l}=i.useCustomizationController();return e.jsxs(t.Dialog,{maxWidth:"md",open:r,children:[e.jsxs(t.DialogContent,{className:"flex flex-col gap-4",children:[e.jsx(t.Typography,{variant:"h6",children:"Select view"}),l?.map(o=>e.jsxs(t.Button,{onClick:()=>a(o.key),fullWidth:!0,variant:"text",children:[o.name," (",o.key,")"]},o.key)),(l??[]).length===0&&e.jsx(t.Typography,{variant:"body2",children:"No custom views defined"})]}),e.jsx(t.DialogActions,{children:e.jsx(t.Button,{variant:"outlined",onClick:()=>a(),children:"Cancel"})})]})}function Kr({collection:r,parentCollection:a,configController:l,collectionInference:o,getUser:s,parentCollectionIds:n}){const{entityViews:d}=i.useCustomizationController(),[h,f]=C.useState(),[u,c]=C.useState(!1),[p,T]=C.useState(),[m,b]=C.useState(),{values:N,setFieldValue:F}=g.useFormikContext(),w=r.subcollections??[],y=N.entityViews?.filter(v=>typeof v=="string").map(v=>i.resolveEntityView(v,d)).filter(Boolean)??[],P=r.entityViews?.filter(v=>typeof v!="string")??[],x=y.length+P.length;return e.jsxs("div",{className:"overflow-auto my-auto",children:[e.jsx(t.Container,{maxWidth:"2xl",className:"flex flex-col gap-4 p-8 m-auto",children:e.jsxs("div",{className:"flex flex-col gap-16",children:[e.jsxs("div",{className:"flex-grow flex flex-col gap-4 items-start",children:[e.jsxs(t.Typography,{variant:"h5",children:["Subcollections of ",N.name]}),w&&w.length>0&&e.jsx(t.Paper,{className:"flex flex-col gap-4 p-2 w-full",children:e.jsx(t.Table,{children:e.jsx(t.TableBody,{children:w.map(v=>e.jsxs(t.TableRow,{onClick:()=>b({isNewCollection:!1,editedCollectionPath:v.path}),children:[e.jsx(t.TableCell,{align:"left",children:e.jsx(t.Typography,{variant:"subtitle2",className:"flex-grow",children:v.name})}),e.jsx(t.TableCell,{align:"right",children:e.jsx(t.Tooltip,{title:"Remove",children:e.jsx(t.IconButton,{size:"small",onClick:E=>{E.preventDefault(),E.stopPropagation(),f(v.path)},color:"inherit",children:e.jsx(t.DeleteIcon,{size:"small"})})})})]},v.path))})})}),e.jsx(t.Button,{onClick:()=>{b({isNewCollection:!0})},variant:"outlined",startIcon:e.jsx(t.AddIcon,{}),children:"Add subcollection"})]}),e.jsxs("div",{className:"flex-grow flex flex-col gap-4 items-start",children:[e.jsx(t.Typography,{variant:"h5",children:"Custom views"}),x>0&&e.jsx(e.Fragment,{children:e.jsx(t.Paper,{className:"flex flex-col gap-4 p-2 w-full",children:e.jsx(t.Table,{children:e.jsxs(t.TableBody,{children:[y.map(v=>e.jsxs(t.TableRow,{children:[e.jsx(t.TableCell,{align:"left",children:e.jsx(t.Typography,{variant:"subtitle2",className:"flex-grow",children:v.name})}),e.jsx(t.TableCell,{align:"right",children:e.jsx(t.Tooltip,{title:"Remove",children:e.jsx(t.IconButton,{size:"small",onClick:E=>{E.preventDefault(),E.stopPropagation(),T(v.key)},color:"inherit",children:e.jsx(t.DeleteIcon,{size:"small"})})})})]},v.key)),P.map(v=>e.jsx(t.TableRow,{children:e.jsxs(t.TableCell,{align:"left",children:[e.jsx(t.Typography,{variant:"subtitle2",className:"flex-grow",children:v.name}),e.jsxs(t.Typography,{variant:"caption",className:"flex-grow",children:["This view is defined in code with key ",e.jsx("code",{children:v.key})]})]})},v.key))]})})})}),x===0&&e.jsxs(t.InfoLabel,{children:[e.jsx("b",{children:"COMING SOON"})," Define your own custom views by uploading it with the CLI"]}),e.jsx(t.Button,{onClick:()=>{c(!0)},variant:"outlined",startIcon:e.jsx(t.AddIcon,{}),children:"Add custom entity view"})]})]})}),e.jsx("div",{style:{height:"52px"}}),h&&e.jsx(i.DeleteConfirmationDialog,{open:!!h,onAccept:()=>{l.deleteCollection({path:h,parentCollectionIds:[...n??[],r.path]}),f(void 0)},onCancel:()=>f(void 0),title:e.jsx(e.Fragment,{children:"Delete this subcollection?"}),body:e.jsxs(e.Fragment,{children:[" This will ",e.jsx("b",{children:"not delete any data"}),", only the collection in the CMS"]})}),p&&e.jsx(i.DeleteConfirmationDialog,{open:!!p,onAccept:()=>{F("entityViews",N.entityViews?.filter(v=>v!==p)),T(void 0)},onCancel:()=>T(void 0),title:e.jsx(e.Fragment,{children:"Remove this view?"}),body:e.jsxs(e.Fragment,{children:["This will ",e.jsx("b",{children:"not delete any data"}),", only the view in the CMS"]})}),e.jsx(tr,{open:!!m,configController:l,parentCollection:r,collectionInference:o,parentCollectionIds:[...n??[],N.id],isNewCollection:!1,...m,getUser:s,handleClose:()=>{b(void 0)}}),e.jsx(Hr,{open:u,onClose:v=>{v&&F("entityViews",[...N.entityViews??[],v]),c(!1)}})]})}const Qe={id:"products",path:"products",name:"Products",singularName:"Product",icon:"shopping_cart",description:"List of the products currently sold in your shop",properties:i.makePropertiesEditable({name:{dataType:"string",name:"Name",description:"Name of this product",validation:{required:!0}},brand:{dataType:"string",name:"Brand",validation:{required:!0}},description:{dataType:"string",name:"Description",description:"Description of this product, supports markdown",markdown:!0},main_image:{dataType:"string",name:"Image",storage:{storagePath:"images",acceptedFiles:["image/*"]},description:"Upload field for images"},available:{dataType:"boolean",name:"Available",columnWidth:100,description:"Is this product available in the website"},price:{dataType:"number",name:"Price",validation:{requiredMessage:"You must set a positive price",min:0}},images:{dataType:"array",name:"Images",hideFromCollection:!0,of:{dataType:"string",storage:{storagePath:"images",acceptedFiles:["image/*"]}}},related_products:{dataType:"array",name:"Related products",description:"Products related to this one",of:{dataType:"reference",path:"products"}},metadata:{name:"Metadata",description:"This is an example of a map property",dataType:"map",keyValue:!0},added_on:{dataType:"date",name:"Added on",autoValue:"on_create"}})},Xe={id:"blog",path:"blog",name:"Blog",singularName:"Blog entry",icon:"article",description:"A collection of blog entries",defaultSize:"l",properties:i.makePropertiesEditable({name:{name:"Name",validation:{required:!0},dataType:"string"},header_image:{name:"Header image",dataType:"string",storage:{storagePath:"images",acceptedFiles:["image/*"],metadata:{cacheControl:"max-age=1000000"}}},content:{name:"Content",description:"Content blocks for the blog entry",validation:{required:!0},dataType:"array",oneOf:{typeField:"type",valueField:"value",properties:{text:{dataType:"string",name:"Text",markdown:!0},quote:{dataType:"string",name:"Quote",multiline:!0},images:{name:"Images",dataType:"array",of:{dataType:"string",storage:{storagePath:"images",acceptedFiles:["image/*"],metadata:{cacheControl:"max-age=1000000"}}},description:"This fields allows uploading multiple images at once and reordering"},products:{name:"Products",dataType:"array",of:{dataType:"reference",path:"products",previewProperties:["name","main_image"]}}},propertiesOrder:["text","quote","images","products"]}},created_on:{name:"Created on",dataType:"date",autoValue:"on_create"},status:{name:"Status",validation:{required:!0},dataType:"string",enumValues:{published:{id:"published",label:"Published"},draft:"Draft"},defaultValue:"draft"},publish_date:{name:"Publish date",dataType:"date",clearable:!0},reviewed:{name:"Reviewed",dataType:"boolean"},tags:{name:"Tags",description:"Example of generic array",dataType:"array",of:{dataType:"string",previewAsTag:!0}}}),initialFilter:{status:["==","published"]}},Re={id:"users",path:"users",name:"Users",singularName:"User",description:"Registered users in the app/web",icon:"person",properties:i.makePropertiesEditable({displayName:{name:"Display name",dataType:"string"},email:{name:"Email",dataType:"string",email:!0},emailVerified:{name:"Email verified",dataType:"boolean"},phone:{name:"Phone",dataType:"string"},favourite_products:{name:"Favourite products",dataType:"array",of:{dataType:"reference",path:"products"}},photoURL:{name:"Photo URL",dataType:"string",url:"image"}})},er={id:"pages",path:"pages",name:"Pages",singularName:"Page",icon:"insert_drive_file",description:"List of website pages that can be edited here",properties:{title:{dataType:"string",name:"Page Title",validation:{required:!0}},slug:{dataType:"string",name:"URL Slug",validation:{required:!0,unique:!0,matches:/^[a-z0-9]+(?:-[a-z0-9]+)*$/,matchesMessage:"Must be lowercase, alphanumeric, and hyphenated"}},hero_section:{dataType:"map",name:"Hero Section",properties:{headline:{dataType:"string",name:"Headline",validation:{required:!0}},subhead:{dataType:"string",name:"Subheadline"},background_image:{dataType:"string",name:"Background Image",storage:{storagePath:"page_hero/images",acceptedFiles:["image/*"]}},call_to_action:{dataType:"string",name:"Call to Action"},call_to_action_link:{dataType:"string",name:"CTA Link",url:!0}}},content:{dataType:"array",name:"Content",oneOf:{properties:{section:{dataType:"map",name:"Section",properties:{title:{dataType:"string",name:"Section Title",validation:{required:!0}},content:{dataType:"string",name:"Section Content",markdown:!0},image:{dataType:"string",name:"Section Image",storage:{storagePath:"page_sections/images",acceptedFiles:["image/*"]}},link:{dataType:"string",name:"Section Link",url:!0}}},image:{dataType:"string",name:"Image",storage:{storagePath:"page_sections/images",acceptedFiles:["image/*"]}},slider:{dataType:"array",name:"Slider",of:{dataType:"map",properties:{title:{dataType:"string",name:"Title",validation:{required:!0}},image:{dataType:"string",storage:{storagePath:"page_sections/images",acceptedFiles:["image/*"]}}}}}}}},sidebar:{dataType:"map",name:"Sidebar",properties:{title:{dataType:"string",name:"Sidebar Title",validation:{required:!1}},content:{dataType:"string",name:"Sidebar Content",markdown:!0}}},seo_metadata:{dataType:"map",name:"SEO Metadata",properties:{meta_title:{dataType:"string",name:"Meta Title"},meta_description:{dataType:"string",name:"Meta Description"},focus_keywords:{dataType:"array",name:"Focus Keywords",of:{dataType:"string"}}}},footer_override:{dataType:"string",name:"Footer Override",markdown:!0},publish_date:{dataType:"date",name:"Publish Date",validation:{required:!0}},last_updated:{dataType:"date",name:"Last Updated",autoValue:"on_update"},is_published:{dataType:"boolean",name:"Is Published",columnWidth:100,description:"Should this page be live on the site?"},author_uid:{dataType:"reference",name:"Author",path:"users"}}};function Wr({path:r,pathSuggestions:a,parentCollection:l,onContinue:o,collections:s}){const[n,d]=C.useState(!1),[h,f]=C.useState();C.useEffect(()=>{a&&s&&(d(!0),a(r).then(y=>{const P=y.filter(x=>!s.find(v=>v.path.trim().toLowerCase()===x.trim().toLowerCase()));f(P)}).finally(()=>d(!1)))},[s,r,a]);const{values:u,setFieldValue:c,setValues:p,handleChange:T,touched:m,errors:b,setFieldTouched:N,isSubmitting:F,submitCount:w}=g.useFormikContext();return e.jsx("div",{className:"overflow-auto my-auto",children:e.jsxs(t.Container,{maxWidth:"4xl",className:"flex flex-col gap-4 p-8 m-auto",children:[e.jsx("div",{className:"flex flex-row py-2 pt-3 items-center",children:e.jsx(t.Typography,{variant:"h4",className:"flex-grow",children:"New collection"})}),l&&e.jsx(t.Chip,{colorScheme:"tealDarker",children:e.jsxs(t.Typography,{variant:"caption",children:["This is a subcollection of ",e.jsx("b",{children:l.name})]})}),e.jsxs("div",{className:"my-2",children:[e.jsx(t.Typography,{variant:"caption",color:"secondary",children:"● Use one of the existing paths in your database:"}),e.jsxs("div",{className:"flex flex-wrap gap-x-2 gap-y-1 items-center my-2 min-h-7",children:[n&&!h&&e.jsx(t.CircularProgress,{size:"small"}),h?.map((y,P)=>e.jsx(t.Chip,{colorScheme:"cyanLighter",onClick:()=>{c("name",i.unslugify(y)),c("id",y),c("path",y),c("properties",void 0),o()},size:"small",children:y},y)),!n&&(h??[])?.length===0&&e.jsx(t.Typography,{variant:"caption",children:"No suggestions"})]})]}),e.jsxs("div",{className:"my-2",children:[e.jsx(t.Typography,{variant:"caption",color:"secondary",children:"● Select a template:"}),e.jsxs("div",{className:"flex gap-4",children:[e.jsx(Ie,{title:"Products",subtitle:"A collection of products with images, prices and stock",icon:e.jsx(t.Icon,{size:"small",iconKey:Qe.icon}),onClick:()=>{p(Qe),o()}}),e.jsx(Ie,{title:"Users",subtitle:"A collection of users with emails, names and roles",icon:e.jsx(t.Icon,{size:"small",iconKey:Re.icon}),onClick:()=>{p(Re),o()}}),e.jsx(Ie,{title:"Blog posts",subtitle:"A collection of blog posts with images, authors and complex content",icon:e.jsx(t.Icon,{size:"small",iconKey:Xe.icon}),onClick:()=>{p(Xe),o()}}),e.jsx(Ie,{title:"Pages",subtitle:"A collection of pages with images, authors and complex content",icon:e.jsx(t.Icon,{size:"small",iconKey:er.icon}),onClick:()=>{p(er),o()}})]})]}),!l&&e.jsxs("div",{children:[e.jsx(t.Typography,{variant:"caption",color:"secondary",className:"mb-2",children:"● Create a collection from a file (csv, json, xls, xslx...)"}),e.jsx(se.ImportFileUpload,{onDataAdded:y=>o(y)})]}),e.jsx("div",{children:e.jsx(t.Button,{variant:"text",onClick:()=>o(),className:"my-2",children:"Continue from scratch"})})]})})}function Ie({title:r,subtitle:a,icon:l,onClick:o}){return e.jsx(t.Tooltip,{title:a,children:e.jsxs(t.Card,{onClick:o,className:t.cn("my-2 rounded-md border mx-0 p-6 px-4 focus:outline-none transition ease-in-out duration-150 flex flex-row gap-4 items-center","text-gray-700 dark:text-gray-300","hover:border-primary-dark hover:text-primary-dark dark:hover:text-primary focus:ring-primary hover:ring-1 hover:ring-primary","border-gray-400 dark:border-gray-600 "),children:[l,e.jsx("div",{className:"flex flex-col items-start",children:e.jsx(t.Typography,{variant:"subtitle1",children:r})})]})})}function Zr({importConfig:r,propertyConfigs:a,collectionEditable:l}){const{setFieldValue:o,setFieldTouched:s,values:n}=g.useFormikContext(),[d,h]=C.useState(void 0),f=C.useRef(n.propertiesOrder?{"":n.propertiesOrder}:{}),u=d?d.id:void 0,c=d||void 0,p=({id:m,property:b,previousId:N,namespace:F})=>{const w=m?K(m,F):void 0,y=w?te(w):void 0,P=v=>v?f.current[v]??g.getIn(n,oe(v)):f.current[""],x=(v,E)=>{const U=oe(E);o(U,v,!1),f.current[E??""]=v};if(N&&N!==m){const v=K(N,F),E=te(v),D=P(F).map(L=>L===N?m:L).filter(L=>L!==void 0);x(D,F);const V={...r.headersMapping};Object.keys(V).forEach(L=>{V[L]===N&&(V[L]=m??"")}),r.setHeadersMapping(V),o(E,void 0,!1),s(E,!1,!1)}y&&(o(y,b,!1),s(y,!0,!1))},T=async({id:m,importKey:b,property:N,namespace:F})=>{const w=m?K(m,F):void 0,y=w?te(w):void 0,P=r.importData.map(v=>g.getIn(v,b)),x={...De.buildPropertyFromData(P,N,se.getInferenceType),editable:!0};y&&(x?o(y,x,!1):o(y,N,!1),s(y,!0,!1))};return e.jsxs("div",{className:"overflow-auto my-auto bg-gray-50 dark:bg-gray-900",children:[e.jsxs(t.Container,{maxWidth:"6xl",className:"flex flex-col gap-4 p-8 m-auto",children:[e.jsx(t.Typography,{variant:"h6",className:"mt-4",children:"Data property mapping"}),e.jsx(se.DataNewPropertiesMapping,{headersMapping:r.headersMapping,idColumn:r.idColumn,originProperties:r.originProperties,destinationProperties:n.properties,onIdPropertyChanged:m=>r.setIdColumn(m),buildPropertyView:({property:m,propertyKey:b,importKey:N})=>e.jsx(se.ImportNewPropertyFieldPreview,{property:m,propertyKey:b,onPropertyNameChanged:(F,w)=>o(`properties.${F}.name`,w,!1),onEditClick:()=>{!b||!m||h({...m,id:b,editable:!0})},propertyTypeView:e.jsx(Jr,{property:m,disabled:!1,onPropertyChanged:F=>T({...F,importKey:N}),propertyKey:b,propertyConfigs:a})})})]}),e.jsx(ge,{open:d!==void 0,propertyKey:u,property:c,inArray:!1,autoUpdateId:!1,onPropertyChanged:p,allowDataInference:!1,collectionEditable:l,onOkClicked:()=>{h(void 0)},onCancel:()=>{h(void 0)},autoOpenTypeSelect:!1,existingProperty:!1,propertyConfigs:a}),e.jsx("div",{style:{height:"52px"}})]})}function Jr({property:r,onPropertyChanged:a,propertyKey:l,propertyConfigs:o,disabled:s}){const n=r?i.getFieldId(r):null,d=r?i.getFieldConfig(r,o):null,[h,f]=C.useState(!1);return e.jsx(t.Tooltip,{title:r&&d?`${d?.name} - ${r.dataType}`:void 0,open:h?!1:void 0,children:e.jsx(t.Select,{open:h,onOpenChange:f,invisible:!0,className:"w-full",disabled:s,error:!d,value:n??"",placeholder:"Select a property widget",position:"item-aligned",renderValue:u=>d?e.jsx(i.FieldConfigBadge,{propertyConfig:d}):null,onValueChange:u=>{const c=He(r,u,o);l&&a({id:l,property:c,previousId:l,namespace:void 0})},children:Object.entries(We).map(([u,c])=>e.jsx(Ke,{value:u,optionDisabled:!1,propertyConfig:c,existing:!1},u))})})}function Qr({importConfig:r,properties:a,propertiesOrder:l}){C.useEffect(()=>{const s=se.getPropertiesMapping(r.originProperties,a),n=r.importData.map(d=>se.convertDataToEntity(d,r.idColumn,r.headersMapping,a,s,"TEMP_PATH"));r.setEntities(n)},[]);const o=i.useSelectionController();return e.jsx(i.EntityCollectionTable,{title:e.jsxs("div",{children:[e.jsx(t.Typography,{variant:"subtitle2",children:"Imported data preview"}),e.jsx(t.Typography,{variant:"caption",children:"Entities with the same id will be overwritten"})]}),tableController:{data:r.entities,dataLoading:!1,noMoreToLoad:!1},endAdornment:e.jsx("div",{className:"h-12"}),filterable:!1,sortable:!1,selectionController:o,displayedColumnIds:l.map(s=>({key:s,disabled:!1})),properties:a})}function rr(r,a=""){const l=Object.keys(r).reduce((n,d)=>{const h=r[d],f=i.slugify(d),u=a?`${a}.${f}`:f;if(h.dataType==="map"&&h.properties){const T=rr(h.properties,u);return{headersMapping:{...n.headersMapping,[d]:u},properties:{...n.properties,[f]:{...h,properties:T.properties,propertiesOrder:Object.keys(T.properties)}}}}const c={...n.properties,[f]:h};return{headersMapping:{...n.headersMapping,[d]:u},properties:c}},{headersMapping:{},properties:{}}),o=Object.keys(l.headersMapping)?.[0];let s;return(o?.includes("id")||o?.includes("key"))&&(s=o),{...l,idColumn:s}}function tr(r){const a=r.open,[l,o]=me.useState(!1),[s,n]=me.useState(!1),d=C.useCallback(()=>{l?n(!0):r.handleClose(void 0)},[l,r.handleClose]);return C.useEffect(()=>{a||(o(!1),n(!1))},[a]),e.jsxs(t.Dialog,{open:a,fullWidth:!0,fullHeight:!0,scrollable:!1,maxWidth:"7xl",onOpenChange:h=>h?void 0:d(),children:[a&&e.jsx(Xr,{...r,handleCancel:d,setFormDirty:o}),e.jsx(Gr,{open:s,handleOk:()=>r.handleClose(void 0),handleCancel:()=>n(!1),body:"There are unsaved changes in this collection"})]})}function Xr({isNewCollection:r,initialValues:a,configController:l,editedCollectionPath:o,parentCollectionIds:s,fullPath:n,collectionInference:d,handleClose:h,reservedGroups:f,extraView:u,handleCancel:c,setFormDirty:p,pathSuggestions:T,getUser:m,parentCollection:b,getData:N}){const{propertyConfigs:F}=i.useCustomizationController(),w=i.useNavigationController(),{topLevelNavigation:y,collections:P}=w,x=!a?.path&&(s??[]).length===0,v=(b?b.subcollections:P)??[],E=v.map(_=>_.path.trim().toLowerCase()),U=v.map(_=>_.id?.trim().toLowerCase()).filter(Boolean),D=se.useImportConfig();if(!y)throw Error("Internal: Navigation not ready in collection editor");const{groups:V}=y,L=i.useSnackbarController(),O=i.useAuthController(),S=C.useRef({}),z=r?x?"welcome":"details":"properties",[I,k]=C.useState(z),[ae,ce]=me.useState(),[M,G]=me.useState(),[Z,ee]=me.useState(!1),[X,ue]=me.useState();C.useEffect(()=>{try{w.initialised&&(G(o?w.getCollectionFromPaths([...s??[],o]):void 0),ee(!0))}catch(_){console.error(_),ue(X)}},[w.getCollectionFromPaths,o,X,w.initialised]);const re=_=>{const A=_.id||_.path;return l.saveCollection({id:A,collectionData:_,previousPath:o,parentCollectionIds:s}).then(()=>(ce(void 0),!0)).catch(Y=>(ce(Y),console.error(Y),L.open({type:"error",message:"Error persisting collection: "+(Y.message??"Details in the console")}),!1))},ne=M?{...M,id:M.id??M.path??i.randomString(16)}:void 0,he=ne?Rr(ne,F):{id:a?.path??i.randomString(16),path:a?.path??"",name:a?.name??"",group:a?.group??"",properties:{},propertiesOrder:[],icon:t.coolIconKeys[Math.floor(Math.random()*t.coolIconKeys.length)],ownerId:O.user?.uid??""},R=C.useCallback(()=>{I==="details"?D.inUse?k("import_data_saving"):k(u?"extra_view":"properties"):k(I==="welcome"?"details":I==="import_data_mapping"?"import_data_preview":I==="import_data_preview"?"details":I==="extra_view"?"properties":"details")},[I,D.inUse,u]),ye=C.useCallback(_=>{if(d)return d?.(_.path,_.collectionGroup??!1,s??[])},[d,s]),Oe=C.useCallback(async _=>{try{if(!ye)return G(_),Promise.resolve(_);k("loading");const A=await ye?.(_);if(!A)return G(_),Promise.resolve(_);const Y={..._??{}};return Object.keys(A.properties??{}).length>0&&(Y.properties=A.properties,Y.propertiesOrder=A.propertiesOrder),Y.propertiesOrder?(G(Y),console.log("Inferred collection",{newCollection:_??{},values:Y}),Y):(Y.propertiesOrder=Object.keys(Y.properties),Y)}catch(A){return console.error(A),L.open({type:"error",message:"Error inferring collection: "+(A.message??"Details in the console")}),_}},[s,ye]),Me=(_,A)=>{try{if(console.log("Submitting collection",_),!r){re(_).then(()=>{A.resetForm({values:he}),h(_)});return}I==="welcome"?(R(),A.resetForm({values:_})):I==="details"?u||D.inUse?(A.resetForm({values:_}),R()):r?Oe(_).then(Y=>{A.resetForm({values:Y??_,touched:{path:!0,name:!0}})}).finally(()=>{R()}):(A.resetForm({values:_}),R()):I==="extra_view"?(R(),A.resetForm({values:_})):I==="import_data_mapping"||I==="import_data_preview"?R():I==="properties"?re(_).then(()=>{A.resetForm({values:he}),R(),h(_)}):(R(),A.resetForm({values:_}))}catch(Y){L.open({type:"error",message:"Error persisting collection: "+(Y.message??"Details in the console")}),console.error(Y),A.resetForm({values:_})}};return!r&&(!w.initialised||!Z)?e.jsx(i.CircularProgressCenter,{}):e.jsx(t.DialogContent,{fullHeight:!0,children:e.jsx(g.Formik,{initialValues:he,validationSchema:(I==="properties"||I==="subcollections"||I==="details")&&fr,validate:_=>{if(I==="properties")return S.current;const A={};if(I==="details"){const Y=lr(_.path,r,E,_.id);Y&&(A.path=Y);const pe=et(_.id,r,E,U);pe&&(A.id=pe)}return A},onSubmit:Me,children:_=>{const{values:A,errors:Y,setFieldValue:pe,isSubmitting:Pe,dirty:B,submitCount:j}=_,$=A.path??o,J=n?.includes("/")?n?.split("/").slice(0,-1).join("/")+"/"+$:$,W=lr($,r,E,A.id),le=!W&&s?w.convertIdsToPaths(s):void 0,Ve=W?void 0:w.resolveAliasesFrom(J),Ee=Ve&&N?()=>N(Ve,le??[]):void 0;C.useEffect(()=>{p(B)},[B]);function sr(Q){D.setInUse(!0),De.buildEntityPropertiesFromData(Q,se.getInferenceType).then(dr=>{const ve=rr(dr);pe("properties",ve.properties),pe("propertiesOrder",Object.keys(ve.properties)),D.setIdColumn(ve.idColumn),D.setImportData(Q),D.setHeadersMapping(ve.headersMapping),D.setOriginProperties(ve.properties)})}const Be=!!A.name&&!!A.id,Te=()=>{const Q={...A.properties};D.idColumn&&delete Q[D.idColumn],pe("properties",Q),R()},ir=M?.editable===void 0||M?.editable===!0||r;return e.jsxs(e.Fragment,{children:[!r&&e.jsxs(t.Tabs,{value:I,className:t.cn(t.defaultBorderMixin,"justify-end bg-gray-50 dark:bg-gray-950 border-b"),onValueChange:Q=>k(Q),children:[e.jsx(t.Tab,{value:"details",children:"Details"}),e.jsx(t.Tab,{value:"properties",children:"Properties"}),e.jsx(t.Tab,{value:"subcollections",children:"Additional views"})]}),e.jsxs(g.Form,{noValidate:!0,className:t.cn(r?"h-full":"h-[calc(100%-48px)]","flex-grow flex flex-col relative"),children:[I==="loading"&&e.jsx(i.CircularProgressCenter,{}),I==="extra_view"&&$&&u?.View&&e.jsx(u.View,{path:$}),I==="welcome"&&e.jsx(Wr,{path:$,onContinue:Q=>{Q?(sr(Q),k("import_data_mapping")):k("details")},collections:P,parentCollection:b,pathSuggestions:T}),I==="import_data_mapping"&&D&&e.jsx(Zr,{importConfig:D,collectionEditable:ir,propertyConfigs:F}),I==="import_data_preview"&&D&&e.jsx(Qr,{importConfig:D,properties:A.properties,propertiesOrder:A.propertiesOrder}),I==="import_data_saving"&&D&&e.jsx(se.ImportSaveInProgress,{importConfig:D,collection:A,onImportSuccess:Q=>{h(Q),L.open({type:"info",message:"Data imported successfully"})}}),I==="details"&&e.jsx(gr,{existingPaths:E,existingIds:U,groups:V,parentCollectionIds:s,parentCollection:b,isNewCollection:r}),I==="subcollections"&&M&&e.jsx(Kr,{parentCollection:b,configController:l,getUser:m,collectionInference:d,parentCollectionIds:s,collection:M}),I==="properties"&&e.jsx(Yr,{showErrors:j>0,isNewCollection:r,reservedGroups:f,onPropertyError:(Q,dr,ve)=>{S.current=i.removeUndefined({...S.current,[Q]:ve},!0)},getUser:m,getData:Ee,doCollectionInference:ye,propertyConfigs:F,collectionEditable:ir,extraIcon:u?.icon&&e.jsx(t.IconButton,{color:"primary",onClick:()=>k("extra_view"),children:u.icon})}),I!=="welcome"&&e.jsxs(t.DialogActions,{position:"absolute",children:[ae&&e.jsx(i.ErrorView,{error:ae}),r&&x&&I==="import_data_mapping"&&e.jsxs(t.Button,{variant:"text",type:"button",onClick:()=>(D.setInUse(!1),k("welcome")),children:[e.jsx(t.ArrowBackIcon,{}),"Back"]}),r&&x&&I==="import_data_preview"&&e.jsxs(t.Button,{variant:"text",type:"button",onClick:()=>{re(A),k("import_data_mapping")},children:[e.jsx(t.ArrowBackIcon,{}),"Back"]}),r&&x&&I==="details"&&e.jsxs(t.Button,{variant:"text",type:"button",onClick:()=>k("welcome"),children:[e.jsx(t.ArrowBackIcon,{}),"Back"]}),r&&I==="properties"&&e.jsxs(t.Button,{variant:"text",type:"button",onClick:()=>k("details"),children:[e.jsx(t.ArrowBackIcon,{}),"Back"]}),e.jsx(t.Button,{variant:"text",onClick:()=>{c()},children:"Cancel"}),r&&I==="import_data_mapping"&&e.jsx(t.Button,{variant:"filled",color:"primary",onClick:Te,children:"Next"}),r&&I==="import_data_preview"&&e.jsx(t.Button,{variant:"filled",color:"primary",onClick:()=>{R()},children:"Next"}),r&&(I==="details"||I==="properties")&&e.jsxs(t.LoadingButton,{variant:"filled",color:"primary",type:"submit",loading:Pe,disabled:Pe||I==="details"&&!Be,startIcon:I==="properties"?e.jsx(t.DoneIcon,{}):void 0,children:[I==="details"&&"Next",I==="properties"&&"Create collection"]}),!r&&e.jsx(t.LoadingButton,{variant:"filled",color:"primary",type:"submit",loading:Pe,children:"Update collection"})]})]})]})}})})}function Rr(r,a){const{properties:l,...o}=r,s={};return Object.keys(l).forEach(n=>{s[n]=ar(l[n],a)}),{...o,properties:s}}function ar(r,a){let l=r;if(a&&typeof l=="object"&&l.propertyConfig){const o=a[l.propertyConfig];if(o&&i.isPropertyBuilder(o.property))l=o.property;else if(o&&(l=i.mergeDeep(o.property,l)),!i.isPropertyBuilder(l)&&l.dataType==="map"&&l.properties){const s={};Object.keys(l.properties).forEach(n=>{s[n]=ar(l.properties[n],a)}),l={...l,properties:s}}}return l}const lr=(r,a,l,o)=>{let s;return r||(s="You must specify a path in the database for this collection"),a&&l?.includes(r.trim().toLowerCase())&&!o&&(s="There is already a collection with the specified path. If you want to have multiple collections referring to the same database path, make sure the have different ids"),i.removeInitialAndTrailingSlashes(r).split("/").length%2===0&&(s=`Collection paths must have an odd number of segments: ${r}`),s},et=(r,a,l,o)=>{if(!r)return;let s;return a&&l?.includes(r.trim().toLowerCase())&&(s="There is already a collection that uses this value as a path"),a&&o?.includes(r.trim().toLowerCase())&&(s="There is already a collection which uses this id"),s},or=C.createContext({}),nr=C.createContext({}),rt=C.memo(function({children:a,collectionConfigController:l,configPermissions:o,reservedGroups:s,collectionInference:n,extraView:d,pathSuggestions:h,getUser:f,getData:u,onAnalyticsEvent:c}){const p=i.useNavigationController(),T=hr.useNavigate(),m=i.useSnackbarController(),{propertyConfigs:b}=i.useCustomizationController(),{collections:N}=p,F=N.map(S=>S.path.trim().toLowerCase()),[w,y]=C.useState();C.useEffect(()=>{h&&h().then(S=>{y(S.filter(z=>!F.includes(z.trim().toLowerCase())))})},[h]);const[P,x]=C.useState(),[v,E]=C.useState(),U=C.useCallback(()=>({createCollections:!0,editCollections:!0,deleteCollections:!0}),[]),D=C.useCallback(({path:S,fullPath:z,parentCollectionIds:I,parentCollection:k})=>{console.debug("edit collection",S,z,I,k),c?.("edit_collection",{path:S,fullPath:z}),x({editedCollectionPath:S,fullPath:z,parentCollectionIds:I,isNewCollection:!1,parentCollection:k,redirect:!1})},[]),V=C.useCallback(({propertyKey:S,property:z,editedCollectionPath:I,currentPropertiesOrder:k,parentCollectionIds:ae,collection:ce})=>{console.debug("edit property",S,z,I,k,ae,ce),c?.("edit_property",{propertyKey:S,editedCollectionPath:I});const M=S&&S.includes(".")?S.substring(0,S.lastIndexOf(".")):void 0,G=S&&S.includes(".")?S.substring(S.lastIndexOf(".")+1):S;E({propertyKey:G,property:z,namespace:M,currentPropertiesOrder:k,editedCollectionPath:I,parentCollectionIds:ae,collectionEditable:ce?.editable??!1})},[]),L=C.useCallback(({parentCollectionIds:S,parentCollection:z,initialValues:I,redirect:k})=>{console.debug("create collection",S,z,I,k),c?.("create_collection",{parentCollectionIds:S,parentCollection:z,initialValues:I,redirect:k}),x({isNewCollection:!0,parentCollectionIds:S,parentCollection:z,initialValues:I,redirect:k})},[]),O=h?S=>!S&&w?Promise.resolve(w):h?.(S):void 0;return e.jsx(or.Provider,{value:l,children:e.jsxs(nr.Provider,{value:{editCollection:D,createCollection:L,editProperty:V,configPermissions:o??U,rootPathSuggestions:w},children:[a,e.jsx(tr,{open:!!P,configController:l,isNewCollection:!1,collectionInference:n,...P,getData:u,reservedGroups:s,extraView:d,pathSuggestions:O,getUser:f,handleClose:S=>{if(P?.redirect&&S&&P?.isNewCollection&&!P.parentCollectionIds.length){const z=p.buildUrlCollectionPath(S.id??S.path);T(z)}x(void 0)}}),e.jsx(ge,{open:!!v,includeIdAndName:!0,existingProperty:!!v?.propertyKey,autoUpdateId:v?!v?.propertyKey:!1,autoOpenTypeSelect:v?!v?.propertyKey:!1,inArray:!1,collectionEditable:v?.collectionEditable??!1,getData:u&&v?.editedCollectionPath?()=>{console.debug("get data for property",v?.editedCollectionPath);const S=p.resolveAliasesFrom(v.editedCollectionPath);return u(S,[])}:void 0,onPropertyChanged:({id:S,property:z})=>{if(!v||!S)return;const I=!v.propertyKey;return l.saveProperty({path:v?.editedCollectionPath,property:z,propertyKey:S,newPropertiesOrder:I&&v.currentPropertiesOrder?[...v.currentPropertiesOrder,S]:void 0,namespace:v.namespace,parentCollectionIds:v.parentCollectionIds}).catch(k=>(console.error(k),m.open({type:"error",message:"Error persisting property: "+(k.message??"Details in the console")}),!1))},onPropertyChangedImmediate:!1,onDelete:()=>{if(!v?.propertyKey)return;const S=v?.currentPropertiesOrder?.filter(z=>z!==v?.propertyKey);return l.deleteProperty({path:v?.editedCollectionPath,propertyKey:v?.propertyKey,namespace:v?.namespace,newPropertiesOrder:S,parentCollectionIds:v?.parentCollectionIds}).then(()=>{E(void 0)}).catch(z=>(console.error(z),m.open({type:"error",message:"Error deleting property: "+(z.message??"Details in the console")}),!1))},onError:()=>{},onOkClicked:()=>{E(void 0)},onCancel:()=>{E(void 0)},initialErrors:{},forceShowErrors:!1,existingPropertyKeys:[],allowDataInference:!0,propertyConfigs:b,property:v?.property,propertyKey:v?.propertyKey})]})})},xe),de=()=>C.useContext(nr),Ae=()=>C.useContext(or);function tt({path:r,parentCollectionIds:a,collection:l,tableController:o}){const s=i.useAuthController(),n=i.useNavigationController(),d=de(),h=Ae(),f=i.useSnackbarController(),u=n.getCollectionFromIds(a),c=d.configPermissions?d.configPermissions({user:s.user,collection:l}).editCollections:!0;let p=null;(!xe(Se(o.filterValues),Se(l.initialFilter))||!xe(Se(o.sortBy),Se(l.initialSort)))&&(p=e.jsxs(e.Fragment,{children:[l.initialFilter||l.initialSort&&e.jsx(t.Tooltip,{title:"Reset to default filter and sort",children:e.jsx(t.Button,{color:"primary",size:"small",variant:"text",onClick:()=>{o.clearFilter?.(),l?.initialFilter&&o.setFilterValues?.(l?.initialFilter),l?.initialSort&&o.setSortBy?.(l?.initialSort)},children:e.jsx(t.UndoIcon,{})})}),e.jsx(t.Tooltip,{title:o.sortBy||o.filterValues?"Save default filter and sort":"Clear default filter and sort",children:e.jsx(t.Button,{color:"primary",size:"small",variant:"outlined",onClick:()=>h?.saveCollection({id:l.path,parentCollectionIds:a,collectionData:i.mergeDeep(l,{initialFilter:o.filterValues??null,initialSort:o.sortBy??null})}).then(()=>{f.open({type:"success",message:"Default config saved"})}),children:e.jsx(t.SaveIcon,{})})})]}));const T=e.jsx(t.Tooltip,{title:c?"Edit collection":"You don't have permissions to edit this collection",children:e.jsx(t.IconButton,{color:"primary",disabled:!c,onClick:c?()=>d?.editCollection({path:l.path,fullPath:r,parentCollectionIds:a,parentCollection:u}):void 0,children:e.jsx(t.SettingsIcon,{})})});return e.jsxs(e.Fragment,{children:[c&&p,T]})}function Se(r){return r&&Object.keys(r).length===0?r:r??null}function at({path:r,collection:a}){const l=i.useSnackbarController(),o=i.useAuthController(),s=Ae(),n=de(),d=n.configPermissions({user:o.user,collection:a}),h=C.useCallback(()=>{n?.editCollection({path:r,parentCollectionIds:[]})},[n,r]),[f,u]=C.useState(!1),c=C.useCallback(()=>{s?.deleteCollection({path:r}).then(()=>{u(!1),l.open({message:"Collection deleted",type:"success"})})},[r,s]);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[d.deleteCollections&&e.jsx(t.Menu,{trigger:e.jsx(t.IconButton,{children:e.jsx(t.MoreVertIcon,{size:"small"})}),children:e.jsxs(t.MenuItem,{onClick:p=>{p.preventDefault(),p.stopPropagation(),u(!0)},children:[e.jsx(t.DeleteIcon,{}),"Delete"]})}),d.editCollections&&e.jsx(t.IconButton,{onClick:p=>{h()},children:e.jsx(t.SettingsIcon,{size:"small"})})]}),e.jsx(i.DeleteConfirmationDialog,{open:f,onAccept:c,onCancel:()=>u(!1),title:e.jsx(e.Fragment,{children:"Delete this collection?"}),body:e.jsxs(e.Fragment,{children:[" This will ",e.jsx("b",{children:"not delete any data"}),", only the collection in the CMS"]})})]})}function lt({group:r,context:a}){if(!a.navigation.topLevelNavigation)throw Error("Navigation not ready in FireCMSHomePage");const l=i.useAuthController(),o=de(),s=o.configPermissions?o.configPermissions({user:l.user}).createCollections:!0;return e.jsx(t.Card,{className:t.cn("h-full p-4 min-h-[124px]"),onClick:o&&s?()=>o.createCollection({initialValues:r?{group:r}:void 0,parentCollectionIds:[],redirect:!0}):void 0,children:e.jsxs("div",{className:"flex flex-col items-start h-full w-full items-center justify-center h-full w-full flex-grow flex-col",children:[e.jsx(t.AddIcon,{color:"primary",size:"large"}),e.jsx(t.Typography,{color:"primary",variant:"caption",className:"font-medium",children:"Add new collection".toUpperCase()}),!s&&e.jsx(t.Typography,{variant:"caption",children:"You don't have permissions to create collections"})]})})}function ot(){const r=i.useAuthController(),a=i.useNavigationController(),l=de(),o=l.configPermissions?l.configPermissions({user:r.user}).createCollections:!0,s=l.rootPathSuggestions??[],n=s.length>3||a.collections.length===0&&s.length>0;return e.jsx(t.Collapse,{in:n,children:e.jsxs("div",{className:"flex flex-col gap-1 p-2 my-4",children:[e.jsx(t.Typography,{variant:"body2",color:"secondary",children:"Create a collection from your data:"}),e.jsx("div",{className:"flex flex-row gap-1 overflow-scroll no-scrollbar ",children:s.map(d=>e.jsx("div",{children:e.jsx(t.Chip,{icon:e.jsx(t.AddIcon,{size:"small"}),colorScheme:"cyanLighter",onClick:l&&o?()=>l.createCollection({initialValues:{path:d,name:i.unslugify(d)},parentCollectionIds:[],redirect:!0}):void 0,size:"small",children:d})},d))})]})})}function nt({propertyKey:r,onHover:a,property:l,fullPath:o,parentCollectionIds:s,collection:n}){const d=de();return e.jsx(t.Tooltip,{title:"Edit",children:e.jsx(t.IconButton,{className:a?"bg-white dark:bg-gray-950":"hidden",onClick:()=>{d.editProperty({propertyKey:r,property:l,editedCollectionPath:o,parentCollectionIds:s,collection:n})},size:"small",children:e.jsx(t.SettingsIcon,{size:"small"})})})}function st({fullPath:r,parentCollectionIds:a,collection:l}){const o=i.useAuthController(),s=de(),n=s.configPermissions?s.configPermissions({user:o.user,collection:l}).editCollections:!0;return e.jsx(t.Tooltip,{title:n?"Add new property":"You don't have permission to add new properties",children:e.jsx("div",{className:"p-0.5 w-20 h-full flex items-center justify-center cursor-pointer bg-gray-100 bg-opacity-40 hover:bg-gray-100 dark:bg-gray-950 dark:bg-opacity-40 dark:hover:bg-gray-950",onClick:()=>{s.editProperty({editedCollectionPath:r,parentCollectionIds:a,currentPropertiesOrder:i.getDefaultPropertiesOrder(l),collection:l})},children:e.jsx(t.AddIcon,{color:"inherit"})})})}function it(){const r=de();return e.jsxs(t.Button,{className:"min-w-fit",variant:"outlined",onClick:()=>r.createCollection({parentCollectionIds:[],redirect:!0}),children:[e.jsx(t.AddIcon,{}),"New collection"]})}function dt({collectionConfigController:r,modifyCollection:a,configPermissions:l,reservedGroups:o,extraView:s,pathSuggestions:n,getUser:d,collectionInference:h,getData:f,onAnalyticsEvent:u}){const c=p=>{const T=N=>{i.makePropertiesEditable(N.properties),N.subcollections?.forEach(T)},m=r.collections??[];m.forEach(T),console.debug("Collections specified in code:",p),console.debug("Collections stored in the backend",m);const b=i.joinCollectionLists(p,m,[],a);return console.debug("Collections after joining:",b),b};return{name:"Collection Editor",loading:r.loading,collections:{injectCollections:c,CollectionActions:tt},provider:{Component:rt,props:{collectionConfigController:r,configPermissions:l,collectionInference:h,reservedGroups:o,extraView:s,pathSuggestions:n,getUser:d,getData:f,onAnalyticsEvent:u}},homePage:{additionalActions:e.jsx(it,{}),additionalChildrenEnd:e.jsx(ot,{}),CollectionActions:at,AdditionalCards:lt},collectionView:{HeaderAction:nt,AddColumnComponent:st}}}function ct({path:r}){const a=i.useNavigationController(),l=pt(r),o=a.getParentCollectionIds(r),s=de();return e.jsxs("div",{className:"p-1 flex flex-col items-center",children:[e.jsx(i.ErrorView,{error:"No collection for path: "+l}),e.jsx(t.Button,{className:"mx-2",variant:"outlined",size:"small",onClick:()=>{s.createCollection({initialValues:{path:l,name:i.unslugify(l)},parentCollectionIds:o,redirect:!1})},children:"Create"})]})}function pt(r){const a=r.split("/");return a[a.length-1]}q.MissingReferenceWidget=ct,q.editableProperty=Ce,q.getFullId=K,q.idToPropertiesPath=te,q.namespaceToPropertiesOrderPath=oe,q.namespaceToPropertiesPath=qe,q.removeNonEditableProperties=je,q.useCollectionEditorController=de,q.useCollectionEditorPlugin=dt,q.useCollectionsConfigController=Ae,Object.defineProperty(q,Symbol.toStringTag,{value:"Module"})});
3
+ const `+$r(r.name)+"Collection:EntityCollection = "+pr.stringify(Je(r),null," ");return e.jsxs(t.Dialog,{open:l,onOpenChange:a,maxWidth:"4xl",children:[e.jsxs(t.DialogContent,{children:[e.jsxs(t.Typography,{variant:"h6",className:"my-4",children:["Code for ",r.name]}),e.jsxs(t.Typography,{variant:"body2",className:"my-4 mb-8",children:["If you want to customise the collection in code, you can add this collection code to your CMS app configuration. More info in the ",e.jsx("a",{rel:"noopener noreferrer",href:"https://firecms.co/docs/customization_quickstart",children:"docs"}),"."]}),e.jsx(ze.Highlight,{theme:ze.themes.vsDark,code:s,language:"typescript",children:({className:n,style:d,tokens:h,getLineProps:f,getTokenProps:u})=>e.jsx("pre",{style:d,className:"p-4 rounded text-sm",children:h.map((c,p)=>e.jsx("div",{...f({line:c}),children:c.map((T,m)=>e.jsx("span",{...u({token:T})},m))},p))})})]}),e.jsxs(t.DialogActions,{children:[e.jsxs(t.Button,{variant:"text",size:"small",onClick:n=>(n.stopPropagation(),n.preventDefault(),o.open({type:"success",message:"Copied"}),navigator.clipboard.writeText(s)),children:[e.jsx(t.ContentCopyIcon,{size:"small"}),"Copy to clipboard"]}),e.jsx(t.Button,{onClick:()=>a(!1),children:"Close"})]})]})}function Je(r){const a=l=>{const o={...l};return delete o.fromBuilder,delete o.resolved,delete o.propertiesOrder,delete o.editable,o.type==="map"?{...o,properties:o.properties.map(a)}:o};return{id:r.id,name:r.name,singularName:r.singularName,path:r.path,description:r.description,editable:!0,collectionGroup:r.collectionGroup,icon:r.icon,group:r.group,customId:r.customId,initialFilter:r.initialFilter,initialSort:r.initialSort,properties:Object.entries(r.properties).map(([l,o])=>({[l]:a(o)})).reduce((l,o)=>({...l,...o}),{}),subcollections:(r.subcollections??[]).map(Je)}}function Yr({showErrors:r,isNewCollection:a,propertyErrorsRef:l,onPropertyError:o,setDirty:s,reservedGroups:n,extraIcon:d,getUser:h,getData:f,doCollectionInference:u,propertyConfigs:c,collectionEditable:p}){const{values:T,setFieldValue:m,setFieldError:b,setFieldTouched:N,errors:F,dirty:w}=g.useFormikContext(),y=i.useSnackbarController(),P=i.useLargeLayout(),x=!P,[v,E]=C.useState(),[U,D]=C.useState(),[V,L]=C.useState(),O=U?K(U,V):void 0,S=O?g.getIn(T.properties,O.replaceAll(".",".properties.")):void 0,[z,I]=C.useState(!1),[k,ae]=C.useState(!1),[ce,M]=C.useState(!1),[G,Z]=C.useState([]),ee=C.useRef(T.propertiesOrder?{"":T.propertiesOrder}:{});C.useEffect(()=>{s&&s(w)},[w]);const X=u?()=>{u&&(ae(!0),u(T).then(B=>{if(B&&i.makePropertiesEditable(B.properties),!B){y.open({type:"error",message:"Could not infer properties from data"});return}const j=(B.properties?Object.keys(B.properties):[]).filter(W=>!T.properties[W]);if(j.length===0){y.open({type:"info",message:"No new properties found in existing data"});return}const $={...j.reduce((W,le)=>(W[le]=(B.properties??{})[le],W),{}),...T.properties},J=[...j,...T.propertiesOrder??[]];m("properties",$,!1),re(J),Z(j)}).finally(()=>{ae(!1)}))}:void 0,ue=B=>B?ee.current[B]??g.getIn(T,oe(B)):ee.current[""],re=(B,j)=>{const $=oe(j);m($,B,!1),ee.current[j??""]=B},ne=(B,j)=>{const $=B?K(B,j):void 0;if(!$)throw Error("collection editor miss config");m(te($),void 0,!1);const W=ue(j).filter(le=>le!==B);re(W,j),M(!1),E(void 0),D(void 0),L(void 0)},he=(B,j)=>{m(oe(j),B,!1)},R=({id:B,property:j})=>{if(!B)throw Error("Need to include an ID when creating a new property");m("properties",{...T.properties??{},[B]:j},!1);const $=[...T.propertiesOrder??Object.keys(T.properties),B];re($),M(!1),P&&(E($.indexOf(B)),D(B)),L(void 0)},ye=({id:B,property:j,previousId:$,namespace:J})=>{const W=B?K(B,J):void 0,le=W?te(W):void 0;if($&&$!==B){const Ve=K($,J),Ee=te(Ve),Be=ue(J).map(Te=>Te===$?B:Te).filter(Te=>Te!==void 0);re(Be,J),B&&(E(Be.indexOf(B)),D(B)),m(Ee,void 0,!1),N(Ee,!1,!1)}console.debug("onPropertyChanged",{id:B,property:j,previousId:$,namespace:J,propertyPath:le}),le&&(m(le,j,!1),N(le,!0,!1))},Oe=C.useCallback((B,j,$)=>{const J=B?K(B,j):void 0;if(console.warn("onPropertyErrorInternal",{id:B,namespace:j,error:$,propertyPath:J}),J){const W=$&&Object.keys($).length>0;o(B,j,W?$:void 0),b(te(J),W?"Property error":void 0)}},[]),Me=()=>{E(void 0),D(void 0)},_=U&&l?.current?.properties?l.current.properties[U]:void 0,A=T?.propertiesOrder===void 0||T.propertiesOrder.length===0,Y=T.propertiesOrder?T.propertiesOrder:Object.keys(T.properties),pe=C.useMemo(()=>h(T.ownerId),[h,T.ownerId]),Pe=e.jsxs("div",{className:"grid grid-cols-12 gap-2 h-full bg-gray-50 dark:bg-gray-900",children:[e.jsxs("div",{className:t.cn("p-4 md:p-8 pb-20 md:pb-20","col-span-12 lg:col-span-5 h-full overflow-auto",!x&&"border-r "+t.defaultBorderMixin),children:[e.jsxs("div",{className:"flex my-2",children:[e.jsxs("div",{className:"flex-grow mb-4",children:[e.jsx(g.Field,{name:"name",as:t.DebouncedTextField,invisible:!0,className:"-ml-1",inputClassName:"text-2xl font-headers",placeholder:"Collection name",size:"small",required:!0,error:!!F?.name}),pe&&e.jsxs(t.Typography,{variant:"body2",className:"ml-2",color:"secondary",children:["Created by ",pe.displayName]})]}),d&&e.jsx("div",{className:"ml-4",children:d}),e.jsxs("div",{className:"ml-1 mt-2 flex flex-row gap-2",children:[e.jsx(t.Tooltip,{title:"Get the code for this collection",children:e.jsx(t.IconButton,{variant:"filled",disabled:k,onClick:()=>I(!0),children:e.jsx(t.CodeIcon,{})})}),X&&e.jsx(t.Tooltip,{title:"Add new properties based on data",children:e.jsx(t.IconButton,{variant:"filled",disabled:k,onClick:X,children:k?e.jsx(t.CircularProgress,{size:"small"}):e.jsx(t.AutoAwesomeIcon,{})})}),e.jsx(t.Tooltip,{title:"Add new property",children:e.jsx(t.Button,{variant:"outlined",onClick:()=>M(!0),children:e.jsx(t.AddIcon,{})})})]})]}),e.jsx(i.ErrorBoundary,{children:e.jsx(we,{className:"pl-8",onPropertyClick:(B,j)=>{E(Y.indexOf(B)),D(B),L(j)},inferredPropertyKeys:G,selectedPropertyKey:U?K(U,V):void 0,properties:T.properties,additionalFields:T.additionalFields,propertiesOrder:Y,onPropertyMove:he,onPropertyRemove:a?ne:void 0,collectionEditable:p,errors:r?F:{}})}),e.jsx(t.Button,{className:"mt-8 w-full",color:"primary",variant:"outlined",size:"large",onClick:()=>M(!0),startIcon:e.jsx(t.AddIcon,{}),children:"Add new property"})]}),!x&&e.jsx("div",{className:"col-span-12 lg:col-span-7 ml-2 p-4 md:p-8 h-full overflow-auto pb-20 md:pb-20",children:e.jsxs(t.Paper,{className:"sticky top-8 p-4 min-h-full border border-transparent w-full flex flex-col justify-center ",children:[O&&S&&!i.isPropertyBuilder(S)&&e.jsx(Ze,{inArray:!1,existingProperty:!a,autoUpdateId:!1,allowDataInference:!a,autoOpenTypeSelect:!1,propertyKey:U,propertyNamespace:V,property:S,onPropertyChanged:ye,onDelete:ne,onError:Oe,forceShowErrors:r,initialErrors:_,getData:f,propertyConfigs:c,collectionEditable:p},`edit_view_${v}`),!S&&e.jsx(t.Typography,{variant:"label",className:"flex items-center justify-center h-full",children:A?"Now you can add your first property":"Select a property to edit it"}),S&&i.isPropertyBuilder(S)&&e.jsx(t.Typography,{variant:"label",className:"flex items-center justify-center",children:"This property is defined as a property builder in code"})]})}),x&&e.jsx(ge,{inArray:!1,open:v!==void 0,autoUpdateId:!S,allowDataInference:!a,existingProperty:!0,autoOpenTypeSelect:!1,propertyKey:U,propertyNamespace:V,property:S,onPropertyChanged:ye,onDelete:ne,onError:Oe,forceShowErrors:r,initialErrors:_,getData:f,propertyConfigs:c,collectionEditable:p,onOkClicked:x?Me:void 0},`edit_view_${v}`)]});return e.jsxs(e.Fragment,{children:[Pe,e.jsx(ge,{inArray:!1,existingProperty:!1,autoOpenTypeSelect:!0,autoUpdateId:!0,forceShowErrors:r,open:ce,onCancel:()=>M(!1),onPropertyChanged:R,getData:f,allowDataInference:!a,propertyConfigs:c,collectionEditable:p,existingPropertyKeys:T.propertiesOrder}),e.jsx(jr,{collection:T,open:z,onOpenChange:I})]})}function Gr({open:r,handleOk:a,handleCancel:l,body:o,title:s}){return e.jsxs(t.Dialog,{open:r,onOpenChange:n=>n?l():a(),"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[e.jsxs(t.DialogContent,{children:[e.jsx(t.Typography,{variant:"h6",children:s??"Unsaved changes"}),o&&e.jsx(t.Typography,{children:o}),e.jsx(t.Typography,{children:"Are you sure?"})]}),e.jsxs(t.DialogActions,{children:[e.jsx(t.Button,{variant:"text",onClick:l,autoFocus:!0,children:" Cancel "}),e.jsx(t.Button,{onClick:a,children:" Ok "})]})]})}function Hr({open:r,onClose:a}){const{entityViews:l}=i.useCustomizationController();return e.jsxs(t.Dialog,{maxWidth:"md",open:r,children:[e.jsxs(t.DialogContent,{className:"flex flex-col gap-4",children:[e.jsx(t.Typography,{variant:"h6",children:"Select view"}),l?.map(o=>e.jsxs(t.Button,{onClick:()=>a(o.key),fullWidth:!0,variant:"text",children:[o.name," (",o.key,")"]},o.key)),(l??[]).length===0&&e.jsx(t.Typography,{variant:"body2",children:"No custom views defined"})]}),e.jsx(t.DialogActions,{children:e.jsx(t.Button,{variant:"outlined",onClick:()=>a(),children:"Cancel"})})]})}function Kr({collection:r,parentCollection:a,configController:l,collectionInference:o,getUser:s,parentCollectionIds:n}){const{entityViews:d}=i.useCustomizationController(),[h,f]=C.useState(),[u,c]=C.useState(!1),[p,T]=C.useState(),[m,b]=C.useState(),{values:N,setFieldValue:F}=g.useFormikContext(),w=r.subcollections??[],y=N.entityViews?.filter(v=>typeof v=="string").map(v=>i.resolveEntityView(v,d)).filter(Boolean)??[],P=r.entityViews?.filter(v=>typeof v!="string")??[],x=y.length+P.length;return e.jsxs("div",{className:"overflow-auto my-auto",children:[e.jsx(t.Container,{maxWidth:"2xl",className:"flex flex-col gap-4 p-8 m-auto",children:e.jsxs("div",{className:"flex flex-col gap-16",children:[e.jsxs("div",{className:"flex-grow flex flex-col gap-4 items-start",children:[e.jsxs(t.Typography,{variant:"h5",children:["Subcollections of ",N.name]}),w&&w.length>0&&e.jsx(t.Paper,{className:"flex flex-col gap-4 p-2 w-full",children:e.jsx(t.Table,{children:e.jsx(t.TableBody,{children:w.map(v=>e.jsxs(t.TableRow,{onClick:()=>b({isNewCollection:!1,editedCollectionPath:v.path}),children:[e.jsx(t.TableCell,{align:"left",children:e.jsx(t.Typography,{variant:"subtitle2",className:"flex-grow",children:v.name})}),e.jsx(t.TableCell,{align:"right",children:e.jsx(t.Tooltip,{title:"Remove",children:e.jsx(t.IconButton,{size:"small",onClick:E=>{E.preventDefault(),E.stopPropagation(),f(v.path)},color:"inherit",children:e.jsx(t.DeleteIcon,{size:"small"})})})})]},v.path))})})}),e.jsx(t.Button,{onClick:()=>{b({isNewCollection:!0})},variant:"outlined",startIcon:e.jsx(t.AddIcon,{}),children:"Add subcollection"})]}),e.jsxs("div",{className:"flex-grow flex flex-col gap-4 items-start",children:[e.jsx(t.Typography,{variant:"h5",children:"Custom views"}),x>0&&e.jsx(e.Fragment,{children:e.jsx(t.Paper,{className:"flex flex-col gap-4 p-2 w-full",children:e.jsx(t.Table,{children:e.jsxs(t.TableBody,{children:[y.map(v=>e.jsxs(t.TableRow,{children:[e.jsx(t.TableCell,{align:"left",children:e.jsx(t.Typography,{variant:"subtitle2",className:"flex-grow",children:v.name})}),e.jsx(t.TableCell,{align:"right",children:e.jsx(t.Tooltip,{title:"Remove",children:e.jsx(t.IconButton,{size:"small",onClick:E=>{E.preventDefault(),E.stopPropagation(),T(v.key)},color:"inherit",children:e.jsx(t.DeleteIcon,{size:"small"})})})})]},v.key)),P.map(v=>e.jsx(t.TableRow,{children:e.jsxs(t.TableCell,{align:"left",children:[e.jsx(t.Typography,{variant:"subtitle2",className:"flex-grow",children:v.name}),e.jsxs(t.Typography,{variant:"caption",className:"flex-grow",children:["This view is defined in code with key ",e.jsx("code",{children:v.key})]})]})},v.key))]})})})}),x===0&&e.jsxs(t.InfoLabel,{children:[e.jsx("b",{children:"COMING SOON"})," Define your own custom views by uploading it with the CLI"]}),e.jsx(t.Button,{onClick:()=>{c(!0)},variant:"outlined",startIcon:e.jsx(t.AddIcon,{}),children:"Add custom entity view"})]})]})}),e.jsx("div",{style:{height:"52px"}}),h&&e.jsx(i.DeleteConfirmationDialog,{open:!!h,onAccept:()=>{l.deleteCollection({path:h,parentCollectionIds:[...n??[],r.path]}),f(void 0)},onCancel:()=>f(void 0),title:e.jsx(e.Fragment,{children:"Delete this subcollection?"}),body:e.jsxs(e.Fragment,{children:[" This will ",e.jsx("b",{children:"not delete any data"}),", only the collection in the CMS"]})}),p&&e.jsx(i.DeleteConfirmationDialog,{open:!!p,onAccept:()=>{F("entityViews",N.entityViews?.filter(v=>v!==p)),T(void 0)},onCancel:()=>T(void 0),title:e.jsx(e.Fragment,{children:"Remove this view?"}),body:e.jsxs(e.Fragment,{children:["This will ",e.jsx("b",{children:"not delete any data"}),", only the view in the CMS"]})}),e.jsx(tr,{open:!!m,configController:l,parentCollection:r,collectionInference:o,parentCollectionIds:[...n??[],N.id],isNewCollection:!1,...m,getUser:s,handleClose:()=>{b(void 0)}}),e.jsx(Hr,{open:u,onClose:v=>{v&&F("entityViews",[...N.entityViews??[],v]),c(!1)}})]})}const Qe={id:"products",path:"products",name:"Products",singularName:"Product",icon:"shopping_cart",description:"List of the products currently sold in your shop",properties:i.makePropertiesEditable({name:{dataType:"string",name:"Name",description:"Name of this product",validation:{required:!0}},brand:{dataType:"string",name:"Brand",validation:{required:!0}},description:{dataType:"string",name:"Description",description:"Description of this product, supports markdown",markdown:!0},main_image:{dataType:"string",name:"Image",storage:{storagePath:"images",acceptedFiles:["image/*"]},description:"Upload field for images"},available:{dataType:"boolean",name:"Available",columnWidth:100,description:"Is this product available in the website"},price:{dataType:"number",name:"Price",validation:{requiredMessage:"You must set a positive price",min:0}},images:{dataType:"array",name:"Images",hideFromCollection:!0,of:{dataType:"string",storage:{storagePath:"images",acceptedFiles:["image/*"]}}},related_products:{dataType:"array",name:"Related products",description:"Products related to this one",of:{dataType:"reference",path:"products"}},metadata:{name:"Metadata",description:"This is an example of a map property",dataType:"map",keyValue:!0},added_on:{dataType:"date",name:"Added on",autoValue:"on_create"}})},Xe={id:"blog",path:"blog",name:"Blog",singularName:"Blog entry",icon:"article",description:"A collection of blog entries",defaultSize:"l",properties:i.makePropertiesEditable({name:{name:"Name",validation:{required:!0},dataType:"string"},header_image:{name:"Header image",dataType:"string",storage:{storagePath:"images",acceptedFiles:["image/*"],metadata:{cacheControl:"max-age=1000000"}}},content:{name:"Content",description:"Content blocks for the blog entry",validation:{required:!0},dataType:"array",oneOf:{typeField:"type",valueField:"value",properties:{text:{dataType:"string",name:"Text",markdown:!0},quote:{dataType:"string",name:"Quote",multiline:!0},images:{name:"Images",dataType:"array",of:{dataType:"string",storage:{storagePath:"images",acceptedFiles:["image/*"],metadata:{cacheControl:"max-age=1000000"}}},description:"This fields allows uploading multiple images at once and reordering"},products:{name:"Products",dataType:"array",of:{dataType:"reference",path:"products",previewProperties:["name","main_image"]}}},propertiesOrder:["text","quote","images","products"]}},created_on:{name:"Created on",dataType:"date",autoValue:"on_create"},status:{name:"Status",validation:{required:!0},dataType:"string",enumValues:{published:{id:"published",label:"Published"},draft:"Draft"},defaultValue:"draft"},publish_date:{name:"Publish date",dataType:"date",clearable:!0},reviewed:{name:"Reviewed",dataType:"boolean"},tags:{name:"Tags",description:"Example of generic array",dataType:"array",of:{dataType:"string",previewAsTag:!0}}}),initialFilter:{status:["==","published"]}},Re={id:"users",path:"users",name:"Users",singularName:"User",description:"Registered users in the app/web",icon:"person",properties:i.makePropertiesEditable({displayName:{name:"Display name",dataType:"string"},email:{name:"Email",dataType:"string",email:!0},emailVerified:{name:"Email verified",dataType:"boolean"},phone:{name:"Phone",dataType:"string"},favourite_products:{name:"Favourite products",dataType:"array",of:{dataType:"reference",path:"products"}},photoURL:{name:"Photo URL",dataType:"string",url:"image"}})},er={id:"pages",path:"pages",name:"Pages",singularName:"Page",icon:"insert_drive_file",description:"List of website pages that can be edited here",properties:{title:{dataType:"string",name:"Page Title",validation:{required:!0}},slug:{dataType:"string",name:"URL Slug",validation:{required:!0,unique:!0,matches:/^[a-z0-9]+(?:-[a-z0-9]+)*$/,matchesMessage:"Must be lowercase, alphanumeric, and hyphenated"}},hero_section:{dataType:"map",name:"Hero Section",properties:{headline:{dataType:"string",name:"Headline",validation:{required:!0}},subhead:{dataType:"string",name:"Subheadline"},background_image:{dataType:"string",name:"Background Image",storage:{storagePath:"page_hero/images",acceptedFiles:["image/*"]}},call_to_action:{dataType:"string",name:"Call to Action"},call_to_action_link:{dataType:"string",name:"CTA Link",url:!0}}},content:{dataType:"array",name:"Content",oneOf:{properties:{section:{dataType:"map",name:"Section",properties:{title:{dataType:"string",name:"Section Title",validation:{required:!0}},content:{dataType:"string",name:"Section Content",markdown:!0},image:{dataType:"string",name:"Section Image",storage:{storagePath:"page_sections/images",acceptedFiles:["image/*"]}},link:{dataType:"string",name:"Section Link",url:!0}}},image:{dataType:"string",name:"Image",storage:{storagePath:"page_sections/images",acceptedFiles:["image/*"]}},slider:{dataType:"array",name:"Slider",of:{dataType:"map",properties:{title:{dataType:"string",name:"Title",validation:{required:!0}},image:{dataType:"string",storage:{storagePath:"page_sections/images",acceptedFiles:["image/*"]}}}}}}}},sidebar:{dataType:"map",name:"Sidebar",properties:{title:{dataType:"string",name:"Sidebar Title",validation:{required:!1}},content:{dataType:"string",name:"Sidebar Content",markdown:!0}}},seo_metadata:{dataType:"map",name:"SEO Metadata",properties:{meta_title:{dataType:"string",name:"Meta Title"},meta_description:{dataType:"string",name:"Meta Description"},focus_keywords:{dataType:"array",name:"Focus Keywords",of:{dataType:"string"}}}},footer_override:{dataType:"string",name:"Footer Override",markdown:!0},publish_date:{dataType:"date",name:"Publish Date",validation:{required:!0}},last_updated:{dataType:"date",name:"Last Updated",autoValue:"on_update"},is_published:{dataType:"boolean",name:"Is Published",columnWidth:100,description:"Should this page be live on the site?"},author_uid:{dataType:"reference",name:"Author",path:"users"}}};function Wr({path:r,pathSuggestions:a,parentCollection:l,onContinue:o,collections:s}){const[n,d]=C.useState(!1),[h,f]=C.useState();C.useEffect(()=>{a&&s&&(d(!0),a(r).then(y=>{const P=y.filter(x=>!s.find(v=>v.path.trim().toLowerCase()===x.trim().toLowerCase()));f(P)}).finally(()=>d(!1)))},[s,r,a]);const{values:u,setFieldValue:c,setValues:p,handleChange:T,touched:m,errors:b,setFieldTouched:N,isSubmitting:F,submitCount:w}=g.useFormikContext();return e.jsx("div",{className:"overflow-auto my-auto",children:e.jsxs(t.Container,{maxWidth:"4xl",className:"flex flex-col gap-4 p-8 m-auto",children:[e.jsx("div",{className:"flex flex-row py-2 pt-3 items-center",children:e.jsx(t.Typography,{variant:"h4",className:"flex-grow",children:"New collection"})}),l&&e.jsx(t.Chip,{colorScheme:"tealDarker",children:e.jsxs(t.Typography,{variant:"caption",children:["This is a subcollection of ",e.jsx("b",{children:l.name})]})}),e.jsxs("div",{className:"my-2",children:[e.jsx(t.Typography,{variant:"caption",color:"secondary",children:"● Use one of the existing paths in your database:"}),e.jsxs("div",{className:"flex flex-wrap gap-x-2 gap-y-1 items-center my-2 min-h-7",children:[n&&!h&&e.jsx(t.CircularProgress,{size:"small"}),h?.map((y,P)=>e.jsx(t.Chip,{colorScheme:"cyanLighter",onClick:()=>{c("name",i.unslugify(y)),c("id",y),c("path",y),c("properties",void 0),o()},size:"small",children:y},y)),!n&&(h??[])?.length===0&&e.jsx(t.Typography,{variant:"caption",children:"No suggestions"})]})]}),e.jsxs("div",{className:"my-2",children:[e.jsx(t.Typography,{variant:"caption",color:"secondary",children:"● Select a template:"}),e.jsxs("div",{className:"flex gap-4",children:[e.jsx(Ie,{title:"Products",subtitle:"A collection of products with images, prices and stock",icon:e.jsx(t.Icon,{size:"small",iconKey:Qe.icon}),onClick:()=>{p(Qe),o()}}),e.jsx(Ie,{title:"Users",subtitle:"A collection of users with emails, names and roles",icon:e.jsx(t.Icon,{size:"small",iconKey:Re.icon}),onClick:()=>{p(Re),o()}}),e.jsx(Ie,{title:"Blog posts",subtitle:"A collection of blog posts with images, authors and complex content",icon:e.jsx(t.Icon,{size:"small",iconKey:Xe.icon}),onClick:()=>{p(Xe),o()}}),e.jsx(Ie,{title:"Pages",subtitle:"A collection of pages with images, authors and complex content",icon:e.jsx(t.Icon,{size:"small",iconKey:er.icon}),onClick:()=>{p(er),o()}})]})]}),!l&&e.jsxs("div",{children:[e.jsx(t.Typography,{variant:"caption",color:"secondary",className:"mb-2",children:"● Create a collection from a file (csv, json, xls, xslx...)"}),e.jsx(se.ImportFileUpload,{onDataAdded:y=>o(y)})]}),e.jsx("div",{children:e.jsx(t.Button,{variant:"text",onClick:()=>o(),className:"my-2",children:"Continue from scratch"})})]})})}function Ie({title:r,subtitle:a,icon:l,onClick:o}){return e.jsx(t.Tooltip,{title:a,children:e.jsxs(t.Card,{onClick:o,className:t.cn("my-2 rounded-md border mx-0 p-6 px-4 focus:outline-none transition ease-in-out duration-150 flex flex-row gap-4 items-center","text-gray-700 dark:text-gray-300","hover:border-primary-dark hover:text-primary-dark dark:hover:text-primary focus:ring-primary hover:ring-1 hover:ring-primary","border-gray-400 dark:border-gray-600 "),children:[l,e.jsx("div",{className:"flex flex-col items-start",children:e.jsx(t.Typography,{variant:"subtitle1",children:r})})]})})}function Zr({importConfig:r,propertyConfigs:a,collectionEditable:l}){const{setFieldValue:o,setFieldTouched:s,values:n}=g.useFormikContext(),[d,h]=C.useState(void 0),f=C.useRef(n.propertiesOrder?{"":n.propertiesOrder}:{}),u=d?d.id:void 0,c=d||void 0,p=({id:m,property:b,previousId:N,namespace:F})=>{const w=m?K(m,F):void 0,y=w?te(w):void 0,P=v=>v?f.current[v]??g.getIn(n,oe(v)):f.current[""],x=(v,E)=>{const U=oe(E);o(U,v,!1),f.current[E??""]=v};if(N&&N!==m){const v=K(N,F),E=te(v),D=P(F).map(L=>L===N?m:L).filter(L=>L!==void 0);x(D,F);const V={...r.headersMapping};Object.keys(V).forEach(L=>{V[L]===N&&(V[L]=m??"")}),r.setHeadersMapping(V),o(E,void 0,!1),s(E,!1,!1)}y&&(o(y,b,!1),s(y,!0,!1))},T=async({id:m,importKey:b,property:N,namespace:F})=>{const w=m?K(m,F):void 0,y=w?te(w):void 0,P=r.importData.map(v=>g.getIn(v,b)),x={...De.buildPropertyFromData(P,N,se.getInferenceType),editable:!0};y&&(x?o(y,x,!1):o(y,N,!1),s(y,!0,!1))};return e.jsxs("div",{className:"overflow-auto my-auto bg-gray-50 dark:bg-gray-900",children:[e.jsxs(t.Container,{maxWidth:"6xl",className:"flex flex-col gap-4 p-8 m-auto",children:[e.jsx(t.Typography,{variant:"h6",className:"mt-4",children:"Data property mapping"}),e.jsx(se.DataNewPropertiesMapping,{headersMapping:r.headersMapping,idColumn:r.idColumn,originProperties:r.originProperties,destinationProperties:n.properties,onIdPropertyChanged:m=>r.setIdColumn(m),buildPropertyView:({property:m,propertyKey:b,importKey:N})=>e.jsx(se.ImportNewPropertyFieldPreview,{property:m,propertyKey:b,onPropertyNameChanged:(F,w)=>o(`properties.${F}.name`,w,!1),onEditClick:()=>{!b||!m||h({...m,id:b,editable:!0})},propertyTypeView:e.jsx(Jr,{property:m,disabled:!1,onPropertyChanged:F=>T({...F,importKey:N}),propertyKey:b,propertyConfigs:a})})})]}),e.jsx(ge,{open:d!==void 0,propertyKey:u,property:c,inArray:!1,autoUpdateId:!1,onPropertyChanged:p,allowDataInference:!1,collectionEditable:l,onOkClicked:()=>{h(void 0)},onCancel:()=>{h(void 0)},autoOpenTypeSelect:!1,existingProperty:!1,propertyConfigs:a}),e.jsx("div",{style:{height:"52px"}})]})}function Jr({property:r,onPropertyChanged:a,propertyKey:l,propertyConfigs:o,disabled:s}){const n=r?i.getFieldId(r):null,d=r?i.getFieldConfig(r,o):null,[h,f]=C.useState(!1);return e.jsx(t.Tooltip,{title:r&&d?`${d?.name} - ${r.dataType}`:void 0,open:h?!1:void 0,children:e.jsx(t.Select,{open:h,onOpenChange:f,invisible:!0,className:"w-full",disabled:s,error:!d,value:n??"",placeholder:"Select a property widget",position:"item-aligned",renderValue:u=>d?e.jsx(i.PropertyConfigBadge,{propertyConfig:d}):null,onValueChange:u=>{const c=He(r,u,o);l&&a({id:l,property:c,previousId:l,namespace:void 0})},children:Object.entries(We).map(([u,c])=>e.jsx(Ke,{value:u,optionDisabled:!1,propertyConfig:c,existing:!1},u))})})}function Qr({importConfig:r,properties:a,propertiesOrder:l}){C.useEffect(()=>{const s=se.getPropertiesMapping(r.originProperties,a),n=r.importData.map(d=>se.convertDataToEntity(d,r.idColumn,r.headersMapping,a,s,"TEMP_PATH"));r.setEntities(n)},[]);const o=i.useSelectionController();return e.jsx(i.EntityCollectionTable,{title:e.jsxs("div",{children:[e.jsx(t.Typography,{variant:"subtitle2",children:"Imported data preview"}),e.jsx(t.Typography,{variant:"caption",children:"Entities with the same id will be overwritten"})]}),tableController:{data:r.entities,dataLoading:!1,noMoreToLoad:!1},endAdornment:e.jsx("div",{className:"h-12"}),filterable:!1,sortable:!1,selectionController:o,displayedColumnIds:l.map(s=>({key:s,disabled:!1})),properties:a})}function rr(r,a=""){const l=Object.keys(r).reduce((n,d)=>{const h=r[d],f=i.slugify(d),u=a?`${a}.${f}`:f;if(h.dataType==="map"&&h.properties){const T=rr(h.properties,u);return{headersMapping:{...n.headersMapping,[d]:u},properties:{...n.properties,[f]:{...h,properties:T.properties,propertiesOrder:Object.keys(T.properties)}}}}const c={...n.properties,[f]:h};return{headersMapping:{...n.headersMapping,[d]:u},properties:c}},{headersMapping:{},properties:{}}),o=Object.keys(l.headersMapping)?.[0];let s;return(o?.includes("id")||o?.includes("key"))&&(s=o),{...l,idColumn:s}}function tr(r){const a=r.open,[l,o]=me.useState(!1),[s,n]=me.useState(!1),d=C.useCallback(()=>{l?n(!0):r.handleClose(void 0)},[l,r.handleClose]);return C.useEffect(()=>{a||(o(!1),n(!1))},[a]),e.jsxs(t.Dialog,{open:a,fullWidth:!0,fullHeight:!0,scrollable:!1,maxWidth:"7xl",onOpenChange:h=>h?void 0:d(),children:[a&&e.jsx(Xr,{...r,handleCancel:d,setFormDirty:o}),e.jsx(Gr,{open:s,handleOk:()=>r.handleClose(void 0),handleCancel:()=>n(!1),body:"There are unsaved changes in this collection"})]})}function Xr({isNewCollection:r,initialValues:a,configController:l,editedCollectionPath:o,parentCollectionIds:s,fullPath:n,collectionInference:d,handleClose:h,reservedGroups:f,extraView:u,handleCancel:c,setFormDirty:p,pathSuggestions:T,getUser:m,parentCollection:b,getData:N}){const{propertyConfigs:F}=i.useCustomizationController(),w=i.useNavigationController(),{topLevelNavigation:y,collections:P}=w,x=!a?.path&&(s??[]).length===0,v=(b?b.subcollections:P)??[],E=v.map(_=>_.path.trim().toLowerCase()),U=v.map(_=>_.id?.trim().toLowerCase()).filter(Boolean),D=se.useImportConfig();if(!y)throw Error("Internal: Navigation not ready in collection editor");const{groups:V}=y,L=i.useSnackbarController(),O=i.useAuthController(),S=C.useRef({}),z=r?x?"welcome":"details":"properties",[I,k]=C.useState(z),[ae,ce]=me.useState(),[M,G]=me.useState(),[Z,ee]=me.useState(!1),[X,ue]=me.useState();C.useEffect(()=>{try{w.initialised&&(G(o?w.getCollectionFromPaths([...s??[],o]):void 0),ee(!0))}catch(_){console.error(_),ue(X)}},[w.getCollectionFromPaths,o,X,w.initialised]);const re=_=>{const A=_.id||_.path;return l.saveCollection({id:A,collectionData:_,previousPath:o,parentCollectionIds:s}).then(()=>(ce(void 0),!0)).catch(Y=>(ce(Y),console.error(Y),L.open({type:"error",message:"Error persisting collection: "+(Y.message??"Details in the console")}),!1))},ne=M?{...M,id:M.id??M.path??i.randomString(16)}:void 0,he=ne?Rr(ne,F):{id:a?.path??i.randomString(16),path:a?.path??"",name:a?.name??"",group:a?.group??"",properties:{},propertiesOrder:[],icon:t.coolIconKeys[Math.floor(Math.random()*t.coolIconKeys.length)],ownerId:O.user?.uid??""},R=C.useCallback(()=>{I==="details"?D.inUse?k("import_data_saving"):k(u?"extra_view":"properties"):k(I==="welcome"?"details":I==="import_data_mapping"?"import_data_preview":I==="import_data_preview"?"details":I==="extra_view"?"properties":"details")},[I,D.inUse,u]),ye=C.useCallback(_=>{if(d)return d?.(_.path,_.collectionGroup??!1,s??[])},[d,s]),Oe=C.useCallback(async _=>{try{if(!ye)return G(_),Promise.resolve(_);k("loading");const A=await ye?.(_);if(!A)return G(_),Promise.resolve(_);const Y={..._??{}};return Object.keys(A.properties??{}).length>0&&(Y.properties=A.properties,Y.propertiesOrder=A.propertiesOrder),Y.propertiesOrder?(G(Y),console.log("Inferred collection",{newCollection:_??{},values:Y}),Y):(Y.propertiesOrder=Object.keys(Y.properties),Y)}catch(A){return console.error(A),L.open({type:"error",message:"Error inferring collection: "+(A.message??"Details in the console")}),_}},[s,ye]),Me=(_,A)=>{try{if(console.log("Submitting collection",_),!r){re(_).then(()=>{A.resetForm({values:he}),h(_)});return}I==="welcome"?(R(),A.resetForm({values:_})):I==="details"?u||D.inUse?(A.resetForm({values:_}),R()):r?Oe(_).then(Y=>{A.resetForm({values:Y??_,touched:{path:!0,name:!0}})}).finally(()=>{R()}):(A.resetForm({values:_}),R()):I==="extra_view"?(R(),A.resetForm({values:_})):I==="import_data_mapping"||I==="import_data_preview"?R():I==="properties"?re(_).then(()=>{A.resetForm({values:he}),R(),h(_)}):(R(),A.resetForm({values:_}))}catch(Y){L.open({type:"error",message:"Error persisting collection: "+(Y.message??"Details in the console")}),console.error(Y),A.resetForm({values:_})}};return!r&&(!w.initialised||!Z)?e.jsx(i.CircularProgressCenter,{}):e.jsx(t.DialogContent,{fullHeight:!0,children:e.jsx(g.Formik,{initialValues:he,validationSchema:(I==="properties"||I==="subcollections"||I==="details")&&fr,validate:_=>{if(I==="properties")return S.current;const A={};if(I==="details"){const Y=lr(_.path,r,E,_.id);Y&&(A.path=Y);const pe=et(_.id,r,E,U);pe&&(A.id=pe)}return A},onSubmit:Me,children:_=>{const{values:A,errors:Y,setFieldValue:pe,isSubmitting:Pe,dirty:B,submitCount:j}=_,$=A.path??o,J=n?.includes("/")?n?.split("/").slice(0,-1).join("/")+"/"+$:$,W=lr($,r,E,A.id),le=!W&&s?w.convertIdsToPaths(s):void 0,Ve=W?void 0:w.resolveAliasesFrom(J),Ee=Ve&&N?()=>N(Ve,le??[]):void 0;C.useEffect(()=>{p(B)},[B]);function sr(Q){D.setInUse(!0),De.buildEntityPropertiesFromData(Q,se.getInferenceType).then(dr=>{const ve=rr(dr);pe("properties",ve.properties),pe("propertiesOrder",Object.keys(ve.properties)),D.setIdColumn(ve.idColumn),D.setImportData(Q),D.setHeadersMapping(ve.headersMapping),D.setOriginProperties(ve.properties)})}const Be=!!A.name&&!!A.id,Te=()=>{const Q={...A.properties};D.idColumn&&delete Q[D.idColumn],pe("properties",Q),R()},ir=M?.editable===void 0||M?.editable===!0||r;return e.jsxs(e.Fragment,{children:[!r&&e.jsxs(t.Tabs,{value:I,className:t.cn(t.defaultBorderMixin,"justify-end bg-gray-50 dark:bg-gray-950 border-b"),onValueChange:Q=>k(Q),children:[e.jsx(t.Tab,{value:"details",children:"Details"}),e.jsx(t.Tab,{value:"properties",children:"Properties"}),e.jsx(t.Tab,{value:"subcollections",children:"Additional views"})]}),e.jsxs(g.Form,{noValidate:!0,className:t.cn(r?"h-full":"h-[calc(100%-48px)]","flex-grow flex flex-col relative"),children:[I==="loading"&&e.jsx(i.CircularProgressCenter,{}),I==="extra_view"&&$&&u?.View&&e.jsx(u.View,{path:$}),I==="welcome"&&e.jsx(Wr,{path:$,onContinue:Q=>{Q?(sr(Q),k("import_data_mapping")):k("details")},collections:P,parentCollection:b,pathSuggestions:T}),I==="import_data_mapping"&&D&&e.jsx(Zr,{importConfig:D,collectionEditable:ir,propertyConfigs:F}),I==="import_data_preview"&&D&&e.jsx(Qr,{importConfig:D,properties:A.properties,propertiesOrder:A.propertiesOrder}),I==="import_data_saving"&&D&&e.jsx(se.ImportSaveInProgress,{importConfig:D,collection:A,onImportSuccess:Q=>{h(Q),L.open({type:"info",message:"Data imported successfully"})}}),I==="details"&&e.jsx(gr,{existingPaths:E,existingIds:U,groups:V,parentCollectionIds:s,parentCollection:b,isNewCollection:r}),I==="subcollections"&&M&&e.jsx(Kr,{parentCollection:b,configController:l,getUser:m,collectionInference:d,parentCollectionIds:s,collection:M}),I==="properties"&&e.jsx(Yr,{showErrors:j>0,isNewCollection:r,reservedGroups:f,onPropertyError:(Q,dr,ve)=>{S.current=i.removeUndefined({...S.current,[Q]:ve},!0)},getUser:m,getData:Ee,doCollectionInference:ye,propertyConfigs:F,collectionEditable:ir,extraIcon:u?.icon&&e.jsx(t.IconButton,{color:"primary",onClick:()=>k("extra_view"),children:u.icon})}),I!=="welcome"&&e.jsxs(t.DialogActions,{position:"absolute",children:[ae&&e.jsx(i.ErrorView,{error:ae}),r&&x&&I==="import_data_mapping"&&e.jsxs(t.Button,{variant:"text",type:"button",onClick:()=>(D.setInUse(!1),k("welcome")),children:[e.jsx(t.ArrowBackIcon,{}),"Back"]}),r&&x&&I==="import_data_preview"&&e.jsxs(t.Button,{variant:"text",type:"button",onClick:()=>{re(A),k("import_data_mapping")},children:[e.jsx(t.ArrowBackIcon,{}),"Back"]}),r&&x&&I==="details"&&e.jsxs(t.Button,{variant:"text",type:"button",onClick:()=>k("welcome"),children:[e.jsx(t.ArrowBackIcon,{}),"Back"]}),r&&I==="properties"&&e.jsxs(t.Button,{variant:"text",type:"button",onClick:()=>k("details"),children:[e.jsx(t.ArrowBackIcon,{}),"Back"]}),e.jsx(t.Button,{variant:"text",onClick:()=>{c()},children:"Cancel"}),r&&I==="import_data_mapping"&&e.jsx(t.Button,{variant:"filled",color:"primary",onClick:Te,children:"Next"}),r&&I==="import_data_preview"&&e.jsx(t.Button,{variant:"filled",color:"primary",onClick:()=>{R()},children:"Next"}),r&&(I==="details"||I==="properties")&&e.jsxs(t.LoadingButton,{variant:"filled",color:"primary",type:"submit",loading:Pe,disabled:Pe||I==="details"&&!Be,startIcon:I==="properties"?e.jsx(t.DoneIcon,{}):void 0,children:[I==="details"&&"Next",I==="properties"&&"Create collection"]}),!r&&e.jsx(t.LoadingButton,{variant:"filled",color:"primary",type:"submit",loading:Pe,children:"Update collection"})]})]})]})}})})}function Rr(r,a){const{properties:l,...o}=r,s={};return Object.keys(l).forEach(n=>{s[n]=ar(l[n],a)}),{...o,properties:s}}function ar(r,a){let l=r;if(a&&typeof l=="object"&&l.propertyConfig){const o=a[l.propertyConfig];if(o&&i.isPropertyBuilder(o.property))l=o.property;else if(o&&(l=i.mergeDeep(o.property,l)),!i.isPropertyBuilder(l)&&l.dataType==="map"&&l.properties){const s={};Object.keys(l.properties).forEach(n=>{s[n]=ar(l.properties[n],a)}),l={...l,properties:s}}}return l}const lr=(r,a,l,o)=>{let s;return r||(s="You must specify a path in the database for this collection"),a&&l?.includes(r.trim().toLowerCase())&&!o&&(s="There is already a collection with the specified path. If you want to have multiple collections referring to the same database path, make sure the have different ids"),i.removeInitialAndTrailingSlashes(r).split("/").length%2===0&&(s=`Collection paths must have an odd number of segments: ${r}`),s},et=(r,a,l,o)=>{if(!r)return;let s;return a&&l?.includes(r.trim().toLowerCase())&&(s="There is already a collection that uses this value as a path"),a&&o?.includes(r.trim().toLowerCase())&&(s="There is already a collection which uses this id"),s},or=C.createContext({}),nr=C.createContext({}),rt=C.memo(function({children:a,collectionConfigController:l,configPermissions:o,reservedGroups:s,collectionInference:n,extraView:d,pathSuggestions:h,getUser:f,getData:u,onAnalyticsEvent:c}){const p=i.useNavigationController(),T=hr.useNavigate(),m=i.useSnackbarController(),{propertyConfigs:b}=i.useCustomizationController(),{collections:N}=p,F=N.map(S=>S.path.trim().toLowerCase()),[w,y]=C.useState();C.useEffect(()=>{h&&h().then(S=>{y(S.filter(z=>!F.includes(z.trim().toLowerCase())))})},[h]);const[P,x]=C.useState(),[v,E]=C.useState(),U=C.useCallback(()=>({createCollections:!0,editCollections:!0,deleteCollections:!0}),[]),D=C.useCallback(({path:S,fullPath:z,parentCollectionIds:I,parentCollection:k})=>{console.debug("edit collection",S,z,I,k),c?.("edit_collection",{path:S,fullPath:z}),x({editedCollectionPath:S,fullPath:z,parentCollectionIds:I,isNewCollection:!1,parentCollection:k,redirect:!1})},[]),V=C.useCallback(({propertyKey:S,property:z,editedCollectionPath:I,currentPropertiesOrder:k,parentCollectionIds:ae,collection:ce})=>{console.debug("edit property",S,z,I,k,ae,ce),c?.("edit_property",{propertyKey:S,editedCollectionPath:I});const M=S&&S.includes(".")?S.substring(0,S.lastIndexOf(".")):void 0,G=S&&S.includes(".")?S.substring(S.lastIndexOf(".")+1):S;E({propertyKey:G,property:z,namespace:M,currentPropertiesOrder:k,editedCollectionPath:I,parentCollectionIds:ae,collectionEditable:ce?.editable??!1})},[]),L=C.useCallback(({parentCollectionIds:S,parentCollection:z,initialValues:I,redirect:k})=>{console.debug("create collection",S,z,I,k),c?.("create_collection",{parentCollectionIds:S,parentCollection:z,initialValues:I,redirect:k}),x({isNewCollection:!0,parentCollectionIds:S,parentCollection:z,initialValues:I,redirect:k})},[]),O=h?S=>!S&&w?Promise.resolve(w):h?.(S):void 0;return e.jsx(or.Provider,{value:l,children:e.jsxs(nr.Provider,{value:{editCollection:D,createCollection:L,editProperty:V,configPermissions:o??U,rootPathSuggestions:w},children:[a,e.jsx(tr,{open:!!P,configController:l,isNewCollection:!1,collectionInference:n,...P,getData:u,reservedGroups:s,extraView:d,pathSuggestions:O,getUser:f,handleClose:S=>{if(P?.redirect&&S&&P?.isNewCollection&&!P.parentCollectionIds.length){const z=p.buildUrlCollectionPath(S.id??S.path);T(z)}x(void 0)}}),e.jsx(ge,{open:!!v,includeIdAndName:!0,existingProperty:!!v?.propertyKey,autoUpdateId:v?!v?.propertyKey:!1,autoOpenTypeSelect:v?!v?.propertyKey:!1,inArray:!1,collectionEditable:v?.collectionEditable??!1,getData:u&&v?.editedCollectionPath?()=>{console.debug("get data for property",v?.editedCollectionPath);const S=p.resolveAliasesFrom(v.editedCollectionPath);return u(S,[])}:void 0,onPropertyChanged:({id:S,property:z})=>{if(!v||!S)return;const I=!v.propertyKey;return l.saveProperty({path:v?.editedCollectionPath,property:z,propertyKey:S,newPropertiesOrder:I&&v.currentPropertiesOrder?[...v.currentPropertiesOrder,S]:void 0,namespace:v.namespace,parentCollectionIds:v.parentCollectionIds}).catch(k=>(console.error(k),m.open({type:"error",message:"Error persisting property: "+(k.message??"Details in the console")}),!1))},onPropertyChangedImmediate:!1,onDelete:()=>{if(!v?.propertyKey)return;const S=v?.currentPropertiesOrder?.filter(z=>z!==v?.propertyKey);return l.deleteProperty({path:v?.editedCollectionPath,propertyKey:v?.propertyKey,namespace:v?.namespace,newPropertiesOrder:S,parentCollectionIds:v?.parentCollectionIds}).then(()=>{E(void 0)}).catch(z=>(console.error(z),m.open({type:"error",message:"Error deleting property: "+(z.message??"Details in the console")}),!1))},onError:()=>{},onOkClicked:()=>{E(void 0)},onCancel:()=>{E(void 0)},initialErrors:{},forceShowErrors:!1,existingPropertyKeys:[],allowDataInference:!0,propertyConfigs:b,property:v?.property,propertyKey:v?.propertyKey})]})})},xe),de=()=>C.useContext(nr),Ae=()=>C.useContext(or);function tt({path:r,parentCollectionIds:a,collection:l,tableController:o}){const s=i.useAuthController(),n=i.useNavigationController(),d=de(),h=Ae(),f=i.useSnackbarController(),u=n.getCollectionFromIds(a),c=d.configPermissions?d.configPermissions({user:s.user,collection:l}).editCollections:!0;let p=null;(!xe(Se(o.filterValues),Se(l.initialFilter))||!xe(Se(o.sortBy),Se(l.initialSort)))&&(p=e.jsxs(e.Fragment,{children:[l.initialFilter||l.initialSort&&e.jsx(t.Tooltip,{title:"Reset to default filter and sort",children:e.jsx(t.Button,{color:"primary",size:"small",variant:"text",onClick:()=>{o.clearFilter?.(),l?.initialFilter&&o.setFilterValues?.(l?.initialFilter),l?.initialSort&&o.setSortBy?.(l?.initialSort)},children:e.jsx(t.UndoIcon,{})})}),e.jsx(t.Tooltip,{title:o.sortBy||o.filterValues?"Save default filter and sort":"Clear default filter and sort",children:e.jsx(t.Button,{color:"primary",size:"small",variant:"outlined",onClick:()=>h?.saveCollection({id:l.path,parentCollectionIds:a,collectionData:i.mergeDeep(l,{initialFilter:o.filterValues??null,initialSort:o.sortBy??null})}).then(()=>{f.open({type:"success",message:"Default config saved"})}),children:e.jsx(t.SaveIcon,{})})})]}));const T=e.jsx(t.Tooltip,{title:c?"Edit collection":"You don't have permissions to edit this collection",children:e.jsx(t.IconButton,{color:"primary",disabled:!c,onClick:c?()=>d?.editCollection({path:l.path,fullPath:r,parentCollectionIds:a,parentCollection:u}):void 0,children:e.jsx(t.SettingsIcon,{})})});return e.jsxs(e.Fragment,{children:[c&&p,T]})}function Se(r){return r&&Object.keys(r).length===0?r:r??null}function at({path:r,collection:a}){const l=i.useSnackbarController(),o=i.useAuthController(),s=Ae(),n=de(),d=n.configPermissions({user:o.user,collection:a}),h=C.useCallback(()=>{n?.editCollection({path:r,parentCollectionIds:[]})},[n,r]),[f,u]=C.useState(!1),c=C.useCallback(()=>{s?.deleteCollection({path:r}).then(()=>{u(!1),l.open({message:"Collection deleted",type:"success"})})},[r,s]);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[d.deleteCollections&&e.jsx(t.Menu,{trigger:e.jsx(t.IconButton,{children:e.jsx(t.MoreVertIcon,{size:"small"})}),children:e.jsxs(t.MenuItem,{onClick:p=>{p.preventDefault(),p.stopPropagation(),u(!0)},children:[e.jsx(t.DeleteIcon,{}),"Delete"]})}),d.editCollections&&e.jsx(t.IconButton,{onClick:p=>{h()},children:e.jsx(t.SettingsIcon,{size:"small"})})]}),e.jsx(i.DeleteConfirmationDialog,{open:f,onAccept:c,onCancel:()=>u(!1),title:e.jsx(e.Fragment,{children:"Delete this collection?"}),body:e.jsxs(e.Fragment,{children:[" This will ",e.jsx("b",{children:"not delete any data"}),", only the collection in the CMS"]})})]})}function lt({group:r,context:a}){if(!a.navigation.topLevelNavigation)throw Error("Navigation not ready in FireCMSHomePage");const l=i.useAuthController(),o=de(),s=o.configPermissions?o.configPermissions({user:l.user}).createCollections:!0;return e.jsx(t.Card,{className:t.cn("h-full p-4 min-h-[124px]"),onClick:o&&s?()=>o.createCollection({initialValues:r?{group:r}:void 0,parentCollectionIds:[],redirect:!0}):void 0,children:e.jsxs("div",{className:"flex flex-col items-start h-full w-full items-center justify-center h-full w-full flex-grow flex-col",children:[e.jsx(t.AddIcon,{color:"primary",size:"large"}),e.jsx(t.Typography,{color:"primary",variant:"caption",className:"font-medium",children:"Add new collection".toUpperCase()}),!s&&e.jsx(t.Typography,{variant:"caption",children:"You don't have permissions to create collections"})]})})}function ot(){const r=i.useAuthController(),a=i.useNavigationController(),l=de(),o=l.configPermissions?l.configPermissions({user:r.user}).createCollections:!0,s=l.rootPathSuggestions??[],n=s.length>3||a.collections.length===0&&s.length>0;return e.jsx(t.Collapse,{in:n,children:e.jsxs("div",{className:"flex flex-col gap-1 p-2 my-4",children:[e.jsx(t.Typography,{variant:"body2",color:"secondary",children:"Create a collection from your data:"}),e.jsx("div",{className:"flex flex-row gap-1 overflow-scroll no-scrollbar ",children:s.map(d=>e.jsx("div",{children:e.jsx(t.Chip,{icon:e.jsx(t.AddIcon,{size:"small"}),colorScheme:"cyanLighter",onClick:l&&o?()=>l.createCollection({initialValues:{path:d,name:i.unslugify(d)},parentCollectionIds:[],redirect:!0}):void 0,size:"small",children:d})},d))})]})})}function nt({propertyKey:r,onHover:a,property:l,fullPath:o,parentCollectionIds:s,collection:n}){const d=de();return e.jsx(t.Tooltip,{title:"Edit",children:e.jsx(t.IconButton,{className:a?"bg-white dark:bg-gray-950":"hidden",onClick:()=>{d.editProperty({propertyKey:r,property:l,editedCollectionPath:o,parentCollectionIds:s,collection:n})},size:"small",children:e.jsx(t.SettingsIcon,{size:"small"})})})}function st({fullPath:r,parentCollectionIds:a,collection:l}){const o=i.useAuthController(),s=de(),n=s.configPermissions?s.configPermissions({user:o.user,collection:l}).editCollections:!0;return e.jsx(t.Tooltip,{title:n?"Add new property":"You don't have permission to add new properties",children:e.jsx("div",{className:"p-0.5 w-20 h-full flex items-center justify-center cursor-pointer bg-gray-100 bg-opacity-40 hover:bg-gray-100 dark:bg-gray-950 dark:bg-opacity-40 dark:hover:bg-gray-950",onClick:()=>{s.editProperty({editedCollectionPath:r,parentCollectionIds:a,currentPropertiesOrder:i.getDefaultPropertiesOrder(l),collection:l})},children:e.jsx(t.AddIcon,{color:"inherit"})})})}function it(){const r=de();return e.jsxs(t.Button,{className:"min-w-fit",variant:"outlined",onClick:()=>r.createCollection({parentCollectionIds:[],redirect:!0}),children:[e.jsx(t.AddIcon,{}),"New collection"]})}function dt({collectionConfigController:r,modifyCollection:a,configPermissions:l,reservedGroups:o,extraView:s,pathSuggestions:n,getUser:d,collectionInference:h,getData:f,onAnalyticsEvent:u}){const c=p=>{const T=N=>{i.makePropertiesEditable(N.properties),N.subcollections?.forEach(T)},m=r.collections??[];m.forEach(T),console.debug("Collections specified in code:",p),console.debug("Collections stored in the backend",m);const b=i.joinCollectionLists(p,m,[],a);return console.debug("Collections after joining:",b),b};return{name:"Collection Editor",loading:r.loading,collections:{injectCollections:c,CollectionActions:tt},provider:{Component:rt,props:{collectionConfigController:r,configPermissions:l,collectionInference:h,reservedGroups:o,extraView:s,pathSuggestions:n,getUser:d,getData:f,onAnalyticsEvent:u}},homePage:{additionalActions:e.jsx(it,{}),additionalChildrenEnd:e.jsx(ot,{}),CollectionActions:at,AdditionalCards:lt},collectionView:{HeaderAction:nt,AddColumnComponent:st}}}function ct({path:r}){const a=i.useNavigationController(),l=pt(r),o=a.getParentCollectionIds(r),s=de();return e.jsxs("div",{className:"p-1 flex flex-col items-center",children:[e.jsx(i.ErrorView,{error:"No collection for path: "+l}),e.jsx(t.Button,{className:"mx-2",variant:"outlined",size:"small",onClick:()=>{s.createCollection({initialValues:{path:l,name:i.unslugify(l)},parentCollectionIds:o,redirect:!1})},children:"Create"})]})}function pt(r){const a=r.split("/");return a[a.length-1]}q.MissingReferenceWidget=ct,q.editableProperty=Ce,q.getFullId=K,q.idToPropertiesPath=te,q.namespaceToPropertiesOrderPath=oe,q.namespaceToPropertiesPath=qe,q.removeNonEditableProperties=je,q.useCollectionEditorController=de,q.useCollectionEditorPlugin=dt,q.useCollectionsConfigController=Ae,Object.defineProperty(q,Symbol.toStringTag,{value:"Module"})});
4
4
  //# sourceMappingURL=index.umd.js.map