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

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.
Files changed (71) hide show
  1. package/dist/form/Field.d.ts +53 -0
  2. package/dist/form/Formex.d.ts +4 -0
  3. package/dist/form/index.d.ts +5 -0
  4. package/dist/form/types.d.ts +25 -0
  5. package/dist/form/useCreateFormex.d.ts +9 -0
  6. package/dist/form/utils.d.ts +44 -0
  7. package/dist/index.es.js +2612 -2328
  8. package/dist/index.es.js.map +1 -1
  9. package/dist/index.umd.js +2 -2
  10. package/dist/index.umd.js.map +1 -1
  11. package/dist/types/collection_editor_controller.d.ts +3 -2
  12. package/dist/types/config_controller.d.ts +3 -3
  13. package/dist/ui/collection_editor/CollectionEditorDialog.d.ts +3 -5
  14. package/dist/ui/collection_editor/CollectionEditorWelcomeView.d.ts +2 -2
  15. package/dist/ui/collection_editor/CollectionPropertiesEditorForm.d.ts +1 -2
  16. package/dist/ui/collection_editor/EnumForm.d.ts +1 -2
  17. package/dist/ui/collection_editor/PropertyEditView.d.ts +5 -5
  18. package/dist/ui/collection_editor/PropertyTree.d.ts +14 -13
  19. package/dist/ui/collection_editor/SwitchControl.d.ts +8 -0
  20. package/dist/ui/collection_editor/properties/CommonPropertyFields.d.ts +0 -1
  21. package/dist/ui/collection_editor/util.d.ts +1 -0
  22. package/package.json +5 -5
  23. package/src/ConfigControllerProvider.tsx +23 -21
  24. package/src/form/Field.tsx +162 -0
  25. package/src/form/Formex.tsx +8 -0
  26. package/src/form/README.md +165 -0
  27. package/src/form/index.ts +5 -0
  28. package/src/form/types.ts +27 -0
  29. package/src/form/useCreateFormex.tsx +137 -0
  30. package/src/form/utils.ts +169 -0
  31. package/src/types/collection_editor_controller.tsx +4 -3
  32. package/src/types/config_controller.tsx +3 -3
  33. package/src/ui/CollectionViewHeaderAction.tsx +1 -1
  34. package/src/ui/EditorCollectionAction.tsx +3 -3
  35. package/src/ui/HomePageEditorCollectionAction.tsx +2 -2
  36. package/src/ui/MissingReferenceWidget.tsx +2 -1
  37. package/src/ui/NewCollectionButton.tsx +3 -3
  38. package/src/ui/NewCollectionCard.tsx +2 -1
  39. package/src/ui/PropertyAddColumnComponent.tsx +1 -1
  40. package/src/ui/RootCollectionSuggestions.tsx +2 -1
  41. package/src/ui/collection_editor/CollectionDetailsForm.tsx +2 -2
  42. package/src/ui/collection_editor/CollectionEditorDialog.tsx +422 -374
  43. package/src/ui/collection_editor/CollectionEditorWelcomeView.tsx +19 -12
  44. package/src/ui/collection_editor/CollectionPropertiesEditorForm.tsx +26 -18
  45. package/src/ui/collection_editor/EnumForm.tsx +118 -114
  46. package/src/ui/collection_editor/GetCodeDialog.tsx +1 -1
  47. package/src/ui/collection_editor/PropertyEditView.tsx +198 -142
  48. package/src/ui/collection_editor/PropertyFieldPreview.tsx +5 -1
  49. package/src/ui/collection_editor/PropertyTree.tsx +132 -113
  50. package/src/ui/collection_editor/SubcollectionsEditTab.tsx +18 -11
  51. package/src/ui/collection_editor/SwitchControl.tsx +39 -0
  52. package/src/ui/collection_editor/import/CollectionEditorImportMapping.tsx +10 -2
  53. package/src/ui/collection_editor/properties/BlockPropertyField.tsx +2 -2
  54. package/src/ui/collection_editor/properties/BooleanPropertyField.tsx +13 -9
  55. package/src/ui/collection_editor/properties/CommonPropertyFields.tsx +11 -37
  56. package/src/ui/collection_editor/properties/DateTimePropertyField.tsx +2 -2
  57. package/src/ui/collection_editor/properties/EnumPropertyField.tsx +3 -6
  58. package/src/ui/collection_editor/properties/MapPropertyField.tsx +2 -2
  59. package/src/ui/collection_editor/properties/NumberPropertyField.tsx +2 -2
  60. package/src/ui/collection_editor/properties/ReferencePropertyField.tsx +11 -14
  61. package/src/ui/collection_editor/properties/RepeatPropertyField.tsx +10 -9
  62. package/src/ui/collection_editor/properties/StoragePropertyField.tsx +15 -9
  63. package/src/ui/collection_editor/properties/StringPropertyField.tsx +2 -2
  64. package/src/ui/collection_editor/properties/UrlPropertyField.tsx +2 -2
  65. package/src/ui/collection_editor/properties/advanced/AdvancedPropertyValidation.tsx +27 -18
  66. package/src/ui/collection_editor/properties/validation/ArrayPropertyValidation.tsx +2 -2
  67. package/src/ui/collection_editor/properties/validation/GeneralPropertyValidation.tsx +27 -16
  68. package/src/ui/collection_editor/properties/validation/NumberPropertyValidation.tsx +33 -18
  69. package/src/ui/collection_editor/properties/validation/StringPropertyValidation.tsx +99 -80
  70. package/src/ui/collection_editor/util.ts +7 -0
  71. package/src/ui/collection_editor/utils/strings.ts +2 -1
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-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";
1
+ (function(j,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("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","yup","@firecms/schema_inference","@hello-pangea/dnd","json5","prism-react-renderer","@firecms/data_import_export","react-router"],e):(j=typeof globalThis<"u"?globalThis:j||self,e(j.FireCMS={},j.jsxRuntime,j.core,j.React,j.equal,j.ui,j.Yup,j.schema_inference,j.dnd,j.JSON5,j.prismReactRenderer,j.data_import_export,j.reactRouter))})(this,function(j,e,f,b,oe,t,yr,Ee,Ve,vr,qe,ae,mr){"use strict";function $e(r){const o=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const a in r)if(a!=="default"){const l=Object.getOwnPropertyDescriptor(r,a);Object.defineProperty(o,a,l.get?l:{enumerable:!0,get:()=>r[a]})}}return o.default=r,Object.freeze(o)}const ce=$e(b),be=$e(yr),br=be.object().shape({id:be.string().required("Required"),name:be.string().required("Required"),path:be.string().required("Required")});function W({error:r,children:o}){return o?e.jsx(t.Typography,{variant:"caption",color:r?"error":"secondary",className:"ml-3.5 mt-0.5",children:o}):null}const je=b.createContext({}),H=()=>b.useContext(je),Be=je.Provider,Cr=r=>typeof r=="function",Ye=r=>r!==null&&typeof r=="object",Pr=r=>String(Math.floor(Number(r)))===r;function E(r,o,a,l=0){const s=Ge(o);for(;r&&l<s.length;)r=r[s[l++]];return l!==s.length&&!r||r===void 0?a:r}function Tr(r,o,a){const l=He(r);let s=l,n=0;const i=Ge(o);for(;n<i.length-1;n++){const p=i[n],h=E(r,i.slice(0,n+1));if(h&&(Ye(h)||Array.isArray(h)))s=s[p]=He(h);else{const g=i[n+1];s=s[p]=Pr(g)&&Number(g)>=0?[]:{}}}return(n===0?r:s)[i[n]]===a?r:(a===void 0?delete s[i[n]]:s[i[n]]=a,n===0&&a===void 0&&delete l[i[n]],l)}function He(r){return Array.isArray(r)?[...r]:typeof r=="object"&&r!==null?{...r}:r}function Ge(r){return Array.isArray(r)?r:r.replace(/\[(\d+)]/g,".$1").replace(/^\./,"").replace(/\.$/,"").split(".")}function G({validate:r,name:o,children:a,as:l,className:s,...n}){const i=H(),p=Nr({name:o,...n},i);if(Cr(a))return a({field:p,form:i});const h=l||"input";if(typeof h=="string"){const{innerRef:g,...c}=n;return ce.createElement(h,{ref:g,...p,...c,className:s},a)}return ce.createElement(h,{...p,...n,className:s},a)}const Nr=(r,o)=>{const a=Ye(r),l=a?r.name:r,s=E(o.values,l),n={name:l,value:s,onChange:o.handleChange,onBlur:o.handleBlur};if(a){const{type:i,value:p,as:h,multiple:g}=r;i==="checkbox"?p===void 0?n.checked=!!s:(n.checked=!!(Array.isArray(s)&&~s.indexOf(p)),n.value=p):i==="radio"?(n.checked=s===p,n.value=p):h==="select"&&g&&(n.value=n.value||[],n.multiple=!0)}return n};function _e({initialValues:r,initialErrors:o,validation:a,validateOnChange:l=!1,onSubmit:s,validateOnInitialRender:n=!1}){const i=b.useRef(r),[p,h]=b.useState(r),[g,c]=b.useState({}),[d,u]=b.useState(o??{}),[m,w]=b.useState(!1),[C,T]=b.useState(0),[k,P]=b.useState(!1);b.useEffect(()=>{n&&S()},[]);const N=_=>{i.current=_,h(_)},S=()=>{const _=i.current,O=a?.(_);return u(O??{}),O},y=(_,O,z)=>{const U=Tr(i.current,_,O);i.current=U,N(U),z&&S()},x=(_,O)=>{console.log("setFieldError",{key:_,error:O,errors:d});const z={...d};O?z[_]=O:delete z[_],u(z)},B=(_,O,z)=>{const U={...g};U[_]=O,c(U),z&&S()},v={values:p,handleChange:_=>{const O=_.target,z=O.type==="checkbox"?O.checked:O.value,U=O.name;y(U,z,l),B(U,!0)},isSubmitting:k,setValues:N,setFieldValue:y,errors:d,setFieldError:x,touched:g,setFieldTouched:B,dirty:m,setDirty:w,submitForm:async _=>{_?.preventDefault(),_?.stopPropagation(),P(!0),T(C+1);const O=a?.(i.current);O&&Object.keys(O).length>0?u(O):(u({}),await s?.(i.current,V.current)),P(!1)},submitCount:C,setSubmitCount:T,handleBlur:_=>{console.log("handleBlur");const z=_.target.name;B(z,!0)},validate:S,resetForm:_=>{const{values:O,errors:z,touched:U}=_??{};i.current=O??r,N(O??r),u(z??{}),c(U??{}),w(!1),T(0)}},V=b.useRef(v);return V.current=v,v}function wr({isNewCollection:r,reservedGroups:o,existingPaths:a,existingIds:l,groups:s,parentCollection:n}){const i=b.useRef(null),{values:p,setFieldValue:h,handleChange:g,touched:c,errors:d,setFieldTouched:u,isSubmitting:m,submitCount:w}=H(),[C,T]=b.useState(!1),[k,P]=b.useState(!1),N=F=>{h("name",F),!E(c,"path")&&r&&F&&h("path",f.toSnakeCase(F)),!E(c,"id")&&r&&F&&h("id",f.toSnakeCase(F)),!E(c,"singularName")&&r&&F&&h("singularName",f.singular(F))};b.useEffect(()=>{d.id&&P(!0)},[d.id]);const S=e.jsx(f.IconForView,{collectionOrView:p}),y=s?.filter(F=>!o?.includes(F)),{inputFocused:x,autoCompleteOpen:B,setAutoCompleteOpen:$}=t.useAutoComplete({ref:i}),q=!!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":`${p?.name} collection`}),e.jsx(t.Tooltip,{title:"Change icon",children:e.jsx(t.IconButton,{shape:"square",onClick:()=>T(!0),children:S})})]}),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:p.name??"",onChange:F=>N(F.target.value),label:"Name",required:!0,error:c.name&&!!d.name}),e.jsx(W,{error:c.name&&!!d.name,children:c.name&&d.name?d.name:"Name of in this collection, usually a plural name (e.g. Products)"})]}),e.jsxs("div",{className:t.cn("col-span-12 ",q?"":"sm:col-span-8"),children:[e.jsx(G,{name:"path",as:t.DebouncedTextField,label:"Path",disabled:!r,required:!0,error:c.path&&!!d.path}),e.jsx(W,{error:c.path&&!!d.path,children:c.path&&d.path?d.path:q?"Relative path to the parent (no need to include the parent path)":"Path that this collection is stored in, in the database"})]}),!q&&e.jsxs("div",{className:"col-span-12 sm:col-span-4 relative",children:[e.jsx(t.TextField,{error:c.group&&!!d.group,disabled:m,value:p.group??"",autoComplete:"off",onChange:F=>h("group",F.target.value),name:"group",inputRef:i,label:"Group"}),e.jsx(t.Autocomplete,{open:B&&(y??[]).length>0,setOpen:$,children:y?.map((F,v)=>e.jsx(t.AutocompleteItem,{onClick:()=>{$(!1),h("group",F??null)},children:e.jsx("div",{className:"flex-grow",children:F})},v+"_"+F))}),e.jsx(W,{children:c.group&&d.group?d.group:"Group of the collection"})]}),e.jsx("div",{className:"col-span-12",children:e.jsx(t.ExpandablePanel,{expanded:k,onExpandedChange:P,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,{name:"id",as:t.DebouncedTextField,disabled:!r,label:"Collection id",error:c.id&&!!d.id}),e.jsx(W,{error:c.id&&!!d.id,children:c.id&&d.id?d.id:"This id identifies this collection"})]}),e.jsxs("div",{className:"col-span-12",children:[e.jsx(t.TextField,{error:c.singularName&&!!d.singularName,id:"singularName","aria-describedby":"singularName-helper",onChange:F=>(u("singularName",!0),g(F)),value:p.singularName??"",label:"Singular name"}),e.jsx(W,{error:c.singularName&&!!d.singularName,children:c.singularName&&d.singularName?d.singularName:"Optionally define a singular name for your entities"})]}),e.jsxs("div",{className:"col-span-12",children:[e.jsx(t.TextField,{error:c.description&&!!d.description,id:"description",value:p.description??"",onChange:g,multiline:!0,rows:2,"aria-describedby":"description-helper-text",label:"Description"}),e.jsx(W,{error:c.description&&!!d.description,children:c.description&&d.description?d.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:g,value:p.defaultSize??"",renderValue:F=>F.toUpperCase(),children:["xs","s","m","l","xl"].map(F=>e.jsx(t.SelectItem,{value:F,children:F.toUpperCase()},`size-select-${F}`))})}),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:F=>{if(F==="code_defined")throw new Error("This should not happen");F==="true"?h("customId",!0):F==="false"?h("customId",!1):F==="optional"&&h("customId","optional")},value:"",renderValue:F=>F==="code_defined"?"Code defined":F==="true"?"Users must define an ID":F==="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:F=>h("collectionGroup",F),value:p.collectionGroup??!1}),e.jsx(W,{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:F=>h("textSearchEnabled",F),value:p.textSearchEnabled??!1}),e.jsx(W,{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:C,onOpenChange:T,maxWidth:"xl",fullWidth:!0,children:e.jsx("div",{className:"p-4 overflow-auto min-h-[200px]",children:e.jsx(f.SearchIconsView,{selectedIcon:p.icon,onIconSelected:F=>{T(!1),h("icon",F)}})})})]})})}function ee(r){return"properties."+r.replaceAll(".",".properties.")}function Ke(r){return r?"properties."+r.replaceAll(".",".properties.")+".properties":"properties"}function te(r){return r?"properties."+r.replaceAll(".",".properties.")+".propertiesOrder":"propertiesOrder"}function Q(r,o){return o?`${o}.${r}`:r}function De(r,o){const a=o?`${o}.${r}`:r;return ee(a)}function xr({enumValues:r,onValuesChanged:o,onError:a,updateIds:l,disabled:s,allowDataInference:n,getData:i}){const p=_e({initialValues:{enumValues:r},validateOnChange:!0,validation:c=>{const d={};c.enumValues&&c.enumValues.forEach((m,w)=>{m?.label||(d.enumValues=d.enumValues??[],d.enumValues[w]=d.enumValues[w]??{},d.enumValues[w].label="You must specify a label for this enum value entry"),m?.id||(d.enumValues=d.enumValues??[],d.enumValues[w]=d.enumValues[w]??{},d.enumValues[w].id="You must specify an ID for this enum value entry")});const u=!!(d?.enumValues&&Object.keys(d?.enumValues).length>0);return a?.(u),d}}),{values:h,errors:g}=p;return b.useEffect(()=>{o&&o(h.enumValues)},[h.enumValues]),e.jsx(Be,{value:p,children:e.jsx(kr,{enumValuesPath:"enumValues",values:h,errors:g,shouldUpdateId:l,disabled:s,allowDataInference:n,getData:i})})}function kr({values:r,errors:o,disabled:a,enumValuesPath:l,shouldUpdateId:s,allowDataInference:n,getData:i}){const{setFieldValue:p}=H(),[h,g]=b.useState(),[c,d]=b.useState(),[u,m]=b.useState(!1),C=b.useRef(new Set).current,T=(P,N)=>{const S=h===N,y=o?.enumValues&&o?.enumValues[P];return e.jsx(Fr,{index:P,disabled:a,enumValuesPath:l,autoFocus:S,entryError:y,shouldUpdateId:s||S,onDialogOpen:()=>d(P),inferredEntry:C.has(r.enumValues[P]?.id)},`${N}`)},k=async()=>{i&&(m(!0),i?.().then(P=>{if(!P)return;const N=P.flat(),S=Array.from(new Set(N)),y=r.enumValues,B=Ee.extractEnumFromValues(S).filter($=>!y?.some(q=>q.id===$.id));B.forEach($=>{C.add($.id)}),p(l,[...B,...y],!0)}).catch(P=>{console.error(P)}).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:u,disabled:a||u,variant:"text",size:"small",onClick:k,children:[u?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(f.ArrayContainer,{droppableId:l,addLabel:"Add enum value",value:r.enumValues,disabled:a,size:"small",buildEntry:T,onInternalIdAdded:g,includeAddButton:!0,onValueChange:P=>p(l,P),newDefaultEntry:{id:"",label:""}}),e.jsx(Ir,{index:c,open:c!==void 0,enumValuesPath:l,onClose:()=>d(void 0)})]})]})}const Fr=b.memo(function({index:o,shouldUpdateId:a,enumValuesPath:l,autoFocus:s,onDialogOpen:n,disabled:i,inferredEntry:p,entryError:h}){const{values:g,handleChange:c,errors:d,setFieldValue:u,touched:m}=H(),w=b.useRef(!E(g,`${l}[${o}].id`)),C=a||w.current,T=E(g,`${l}[${o}].id`),k=E(g,`${l}[${o}].label`),P=b.useRef(k);return b.useEffect(()=>{(P.current===T||!T)&&C&&u(`${l}[${o}].id`,k),P.current=k},[k]),e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex w-full align-center justify-center",children:[e.jsx(G,{name:`${l}[${o}].label`,as:t.DebouncedTextField,className:"flex-grow",required:!0,disabled:i,size:"small",autoFocus:s,autoComplete:"off",endAdornment:p&&e.jsx(t.AutoAwesomeIcon,{size:"small"}),error:!!h?.label}),!i&&e.jsx(t.Badge,{color:"error",invisible:!h?.id,children:e.jsx(t.IconButton,{size:"small","aria-label":"edit",className:"m-1",onClick:()=>n(),children:e.jsx(t.SettingsIcon,{size:"small"})})})]}),h?.label&&e.jsx(t.Typography,{variant:"caption",className:"ml-3.5 text-red-500 dark:text-red-500",children:h?.label}),h?.id&&e.jsx(t.Typography,{variant:"caption",className:"ml-3.5 text-red-500 dark:text-red-500",children:h?.id})]})},function(o,a){return o.index===a.index&&o.enumValuesPath===a.enumValuesPath&&o.shouldUpdateId===a.shouldUpdateId&&o.inferredEntry===a.inferredEntry&&oe(o.entryError,a.entryError)&&o.autoFocus===a.autoFocus});function Ir({index:r,open:o,onClose:a,enumValuesPath:l}){const{errors:s}=H(),n=r!==void 0?E(s,`${l}[${r}].id`):void 0;return e.jsxs(t.Dialog,{maxWidth:"md","aria-labelledby":"enum-edit-dialog",open:o,onOpenChange:i=>i?void 0:a(),children:[e.jsx(t.DialogContent,{children:r!==void 0&&e.jsxs("div",{children:[e.jsx(G,{name:`${l}[${r}].id`,as:t.DebouncedTextField,required:!0,label:"ID",size:"small",autoComplete:"off",error:!!n}),e.jsx(W,{error:!!n,children:n??"Value saved in the data source"})]})}),e.jsx(t.DialogActions,{children:e.jsx(t.Button,{autoFocus:!0,variant:"outlined",onClick:a,color:"primary",children:"Ok"})})]})}function R({field:r,form:o,label:a,tooltip:l,disabled:s,size:n="small",allowIndeterminate:i}){const p=e.jsx(t.BooleanSwitchWithLabel,{label:a,size:n,position:"start",value:r.value,disabled:s,allowIndeterminate:i,onValueChange:h=>o.setFieldValue(r.name,h)});return l?e.jsx(t.Tooltip,{title:l,children:p}):p}function pe({disabled:r}){const{values:o,handleChange:a}=H(),l="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,{name:l,type:"checkbox",children:({field:i,form:p})=>e.jsx(R,{disabled:r,label:"Required",tooltip:"You won't be able to save this entity if this value is not set",form:p,field:i})})}),e.jsx("div",{className:"col-span-6",children:e.jsx(G,{name:n,type:"checkbox",children:({field:i,form:p})=>e.jsx(R,{disabled:r,label:"Unique",tooltip:"There cannot be multiple entities with the same value",form:p,field:i})})}),E(o,l)&&e.jsx("div",{className:"col-span-12",children:e.jsx(t.DebouncedTextField,{disabled:r,value:E(o,s),label:"Required message",name:s,size:"small",onChange:a})})]})}function ue({length:r,lowercase:o,matches:a,max:l,min:s,trim:n,uppercase:i,disabled:p,showErrors:h}){const{values:g,handleChange:c,errors:d}=H(),u="validation.length",m="validation.min",w="validation.max",C="validation.trim",T="validation.matches",k="validation.lowercase",P="validation.uppercase",N=E(d,T),S=E(g,T),y=typeof S=="string"?S:f.serializeRegExp(S);return e.jsxs("div",{className:"grid grid-cols-12 gap-2",children:[e.jsx(pe,{disabled:p}),e.jsxs("div",{className:"grid grid-cols-12 gap-2 col-span-12",children:[o&&e.jsx("div",{className:"col-span-4",children:e.jsx(G,{name:k,type:"checkbox",children:({field:x,form:B})=>e.jsx(R,{label:"Lowercase",disabled:p,form:B,field:x})})}),i&&e.jsx("div",{className:"col-span-4",children:e.jsx(G,{name:P,type:"checkbox",children:({field:x,form:B})=>e.jsx(R,{label:"Uppercase",disabled:p,form:B,field:x})})}),n&&e.jsx("div",{className:"col-span-4",children:e.jsx(G,{name:C,type:"checkbox",children:({field:x,form:B})=>e.jsx(R,{label:"Trim",disabled:p,form:B,field:x})})})]}),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:E(g,u),label:"Exact length",name:u,type:"number",size:"small",disabled:p,onChange:c})}),s&&e.jsx("div",{className:"col-span-4",children:e.jsx(t.DebouncedTextField,{value:E(g,m),label:"Min length",name:m,type:"number",size:"small",disabled:p,onChange:c})}),l&&e.jsx("div",{className:"col-span-4",children:e.jsx(t.DebouncedTextField,{value:E(g,w),label:"Max length",name:w,type:"number",size:"small",disabled:p,onChange:c})})]}),a&&e.jsxs("div",{className:"col-span-12",children:[e.jsx(G,{name:T,as:t.DebouncedTextField,label:"Matches regex",size:"small",disabled:p,value:y,error:!!N}),e.jsx(W,{error:!!N,children:N?"Not a valid regexp":"e.g. /^\\d+$/ for digits only"})]})]})}function Ae({max:r=!0,min:o=!0,disabled:a}){const{values:l,handleChange:s}=H(),n="validation.min",i="validation.max";return e.jsxs("div",{className:"grid grid-cols-12 gap-2",children:[e.jsx(pe,{disabled:a}),o&&e.jsx("div",{className:"col-span-6",children:e.jsx(t.DebouncedTextField,{value:E(l,n),disabled:a,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:E(l,i),disabled:a,label:"Max length",name:i,type:"number",size:"small",onChange:s})})]})}function le({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 We({multiselect:r,updateIds:o,disabled:a,showErrors:l,allowDataInference:s,getData:n}){const{values:i,setFieldError:p,setFieldValue:h}=H(),g=f.useSnackbarController(),c=r?"of.enumValues":"enumValues",d=E(i,"defaultValue"),u=E(i,c),m=b.useMemo(()=>!u||typeof u=="boolean"?[]:f.resolveEnumValues(u)??[],[u]),w=C=>{if(i&&(h(c,C),!r)){const T=C.filter(k=>!!k?.id).map(k=>k.id);d&&!T.includes(d)&&(h("defaultValue",void 0),g.open({type:"warning",message:"Default value was cleared"}))}};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"col-span-12",children:e.jsx(xr,{enumValues:m,updateIds:o,disabled:a,allowDataInference:s,onError:C=>{p(c,C?"This enum property is missing some values":void 0)},getData:n?()=>n().then(C=>C.map(T=>i.id&&E(T,i.id)).filter(Boolean)):void 0,onValuesChanged:w})}),e.jsx("div",{className:"col-span-12",children:e.jsxs(le,{children:[!r&&e.jsx(ue,{disabled:a,showErrors:l}),r&&e.jsx(Ae,{disabled:a})]})}),!r&&e.jsx("div",{className:"col-span-12",children:e.jsx(t.Select,{disabled:a,position:"item-aligned",onValueChange:C=>{h("defaultValue",C)},label:"Default value",value:d??"",children:m.filter(C=>!!C?.id).map(C=>e.jsx(t.SelectItem,{value:C.id?.toString(),children:C.label},C.id))})})]})}const Ce={"image/*":"Images","video/*":"Videos","audio/*":"Audio files","application/*":"Files (pdf, zip, csv, excel...)","text/*":"Text files"};function Ze({multiple:r,existing:o,disabled:a}){const{values:l,setFieldValue:s}=H(),n=r?"of.storage":"storage",i=`${n}.acceptedFiles`,p=`${n}.fileName`,h=`${n}.storagePath`,g=`${n}.storeUrl`,c=E(l,p)??"{rand}_{file}",d=E(l,h)??"/",u=E(l,i),m=Array.isArray(u)?u:void 0,w=!m||m.length===0,C=P=>{P?P.includes("all")||P.length>=Object.keys(Ce).length?s(i,void 0):w?s(i,Object.keys(Ce).filter(N=>!P.includes(N))):s(i,P):s(i,void 0)},T=typeof c=="function",k=typeof d=="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:a,name:i,value:m??[],onMultiValueChange:C,label:w?void 0:"Allowed file types",renderValues:P=>!P||P.length===0?"All file types allowed":P.map(N=>Ce[N]).filter(N=>!!N).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(Ce).map(([P,N])=>e.jsxs(t.MultiSelectItem,{value:P,className:"flex items-center gap-2",children:[e.jsx(t.Checkbox,{checked:w||m.indexOf(P)>-1}),e.jsx("div",{className:"flex-grow",children:N}),e.jsx(t.Button,{size:"small",variant:"outlined",onClick:S=>(S.preventDefault(),S.stopPropagation(),s(i,[P])),children:"Only"})]},P))]})}),e.jsx("div",{className:"col-span-12",children:e.jsx(G,{name:p,as:t.DebouncedTextField,label:"File name",size:"small",disabled:T||a,value:T?"-":c})}),e.jsxs("div",{className:"col-span-12",children:[e.jsx(G,{name:h,as:t.DebouncedTextField,label:"Storage path",disabled:k||a,size:"small",value:k?"-":d}),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,{name:g,type:"checkbox",children:({field:P,form:N})=>e.jsx(R,{label:"Save URL instead of storage path",disabled:o||a,form:N,field:P})}),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(le,{children:[!r&&e.jsx("div",{className:"grid grid-cols-12 gap-2",children:e.jsx(pe,{disabled:a})}),r&&e.jsx("div",{className:"col-span-12",children:e.jsx(Ae,{disabled:a})})]})})]})}function ye(r){if(f.isPropertyBuilder(r)||f.isPropertyBuilder(r))return!1;{const o=r;return o.dataType==="array"&&typeof o.of=="function"||o.dataType==="array"&&Array.isArray(o.of)?!1:!!o.editable}}function Je(r){return Object.entries(r).filter(([o,a])=>ye(a)).map(([o,a])=>{const l=a;if(ye(l))return l.dataType==="map"&&l.properties?{[o]:{...l,properties:Je(l.properties)}}:{[o]:l}}).filter(o=>!!o).reduce((o,a)=>({...o,...a}),{})}function Qe({property:r,onClick:o,hasError:a,includeName:l,includeEditButton:s,selected:n}){const{propertyConfigs:i}=f.useCustomizationController(),p=f.getFieldConfig(r,i);ye(r);const h=a?"border-red-500 dark:border-red-500 border-opacity-100 dark:border-opacity-100 ring-0 dark:ring-0":n?"border-primary":"border-transparent";return a&&console.log("PropertyFieldPreview",r),e.jsx(f.ErrorBoundary,{children:e.jsxs("div",{onClick:o,className:"flex flex-row w-full cursor-pointer",children:[e.jsx("div",{className:"m-4",children:e.jsx(f.PropertyConfigBadge,{propertyConfig:p})}),e.jsxs(t.Paper,{className:t.cn("border","pl-2 w-full flex flex-row gap-4 items-center",t.cardMixin,o?t.cardClickableMixin:"",n?t.cardSelectedMixin:"","flex-grow p-4 border transition-colors duration-200",h),children:[e.jsxs("div",{className:"w-full flex flex-col",children:[l&&e.jsx(f.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(f.ErrorBoundary,{children:e.jsx(t.Typography,{className:"flex-grow pr-2",variant:l?"body2":"subtitle1",component:"span",color:"secondary",children:p?.name})}),e.jsx(f.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 Sr({name:r,selected:o,onClick:a,property:l}){const{propertyConfigs:s}=f.useCustomizationController(),n=!f.isPropertyBuilder(l)&&l?f.getFieldConfig(l,s):void 0;return e.jsxs("div",{onClick:a,className:"flex flex-row w-full cursor-pointer",children:[e.jsxs("div",{className:"relative m-4",children:[n&&e.jsx(f.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,a?t.cardClickableMixin:"",o?t.cardSelectedMixin:"","flex-grow p-4 border transition-colors duration-200",o?"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:l?.name?l.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}),l&&!f.isPropertyBuilder(l)&&e.jsx(f.ErrorBoundary,{children:e.jsx(t.Typography,{variant:"body2",component:"span",color:"disabled",children:l.dataType})}),l&&f.isPropertyBuilder(l)&&e.jsx(f.ErrorBoundary,{children:e.jsx(t.Typography,{variant:"body2",component:"span",color:"disabled",children:"This property is defined as a property builder in code"})}),!l&&e.jsx(f.ErrorBoundary,{children:e.jsx(t.Typography,{variant:"body2",component:"span",color:"disabled",children:"This field is defined as an additional field in code"})})]})]})})]})}const Pe=b.memo(function({namespace:o,selectedPropertyKey:a,onPropertyClick:l,properties:s,propertiesOrder:n,additionalFields:i,errors:p,onPropertyMove:h,onPropertyRemove:g,className:c,inferredPropertyKeys:d,collectionEditable:u}){const m=n??Object.keys(s),w=b.useCallback(C=>{if(!C.destination)return;const T=C.source.index,k=C.destination.index,P=Array.from(m),[N]=P.splice(T,1);P.splice(k,0,N),h&&h(P,o)},[o,h,m]);return e.jsx(e.Fragment,{children:e.jsx(Ve.DragDropContext,{onDragEnd:w,children:e.jsx(Ve.Droppable,{droppableId:`droppable_${o}`,children:(C,T)=>e.jsxs("div",{...C.droppableProps,ref:C.innerRef,className:c,children:[m&&m.map((k,P)=>{const N=s[k],S=i?.find(y=>y.key===k);return!N&&!S?(console.warn(`Property ${k} not found in properties or additionalFields`),null):e.jsx(Ve.Draggable,{draggableId:`array_field_${o}_${k}}`,index:P,children:(y,x)=>e.jsx(f.ErrorBoundary,{children:e.jsx(Or,{propertyKey:k,propertyOrBuilder:N,additionalField:S,provided:y,errors:p,namespace:o,inferredPropertyKeys:d,onPropertyMove:h,onPropertyRemove:g,onPropertyClick:x.isDragging?void 0:l,selectedPropertyKey:a,collectionEditable:u})})},`array_field_${o}_${k}}`)}).filter(Boolean),C.placeholder]})})})})},(r,o)=>{const a=o.selectedPropertyKey?.startsWith(o.namespace??""),l=r.selectedPropertyKey?.startsWith(r.namespace??"");return a||l?!1:oe(r.properties,o.properties)&&r.propertiesOrder===o.propertiesOrder&&oe(r.additionalFields,o.additionalFields)&&oe(r.errors,o.errors)&&oe(r.onPropertyClick,o.onPropertyClick)&&r.namespace===o.namespace&&r.collectionEditable===o.collectionEditable});function Or({propertyKey:r,namespace:o,propertyOrBuilder:a,additionalField:l,provided:s,selectedPropertyKey:n,errors:i,onPropertyClick:p,onPropertyMove:h,onPropertyRemove:g,inferredPropertyKeys:c,collectionEditable:d}){const u=c?.includes(o?`${o}.${r}`:r),m=Q(r,o),C=De(r,o)in i;let T;if(typeof a=="object"){const N=a;N.dataType==="map"&&N.properties&&(T=e.jsx(Pe,{selectedPropertyKey:n,namespace:m,properties:N.properties,propertiesOrder:N.propertiesOrder,errors:i,onPropertyClick:p,onPropertyMove:h,onPropertyRemove:g,collectionEditable:d}))}const k=n===m,P=a&&(d&&!f.isPropertyBuilder(a)||ye(a));return e.jsxs("div",{ref:s.innerRef,...s.draggableProps,...s.dragHandleProps,className:"relative -ml-8",children:[T&&e.jsx("div",{className:"absolute border-l "+t.defaultBorderMixin,style:{left:"32px",top:"64px",bottom:"16px"}}),!f.isPropertyBuilder(a)&&!l&&P?e.jsx(Qe,{property:a,onClick:p?()=>p(r,o):void 0,includeName:!0,selected:k,hasError:C}):e.jsx(Sr,{name:r,property:a,onClick:p?()=>p(r,o):void 0,selected:k}),e.jsxs("div",{className:"absolute top-2 right-2 flex flex-row ",children:[u&&e.jsx(t.Tooltip,{title:"Inferred property",children:e.jsx(t.AutoAwesomeIcon,{size:"small",className:"p-2"})}),g&&e.jsx(t.Tooltip,{title:"Remove",children:e.jsx(t.IconButton,{size:"small",color:"inherit",onClick:()=>g(r,o),children:e.jsx(t.RemoveIcon,{size:"small"})})}),h&&e.jsx(t.Tooltip,{title:"Move",children:e.jsx(t.IconButton,{component:"span",size:"small",children:e.jsx(t.DragHandleIcon,{size:"small"})})})]}),T&&e.jsx("div",{className:"ml-16",children:T})]})}function Er({disabled:r,getData:o,allowDataInference:a,propertyConfigs:l,collectionEditable:s}){const{values:n,setFieldValue:i}=H(),[p,h]=b.useState(!1),[g,c]=b.useState(),[d,u]=b.useState(),m=n.propertiesOrder??Object.keys(n.properties??{}),w=b.useCallback(({id:y,property:x})=>{if(!y)throw Error();i("properties",{...n.properties??{},[y]:x},!1),i("propertiesOrder",[...m,y],!1),h(!1)},[n.properties,m]),C=b.useCallback((y,x)=>{const B=y?Q(y,x):void 0;if(!B)throw Error("collection editor miss config");const $=ee(B),q=te(x),L=E(n,q)??Object.keys(E(n,Ke(x)));i($,void 0,!1),i(q,L.filter(F=>F!==y),!1),h(!1),c(void 0),u(void 0)},[i,n]),T=g?Q(g,d):void 0,k=T?E(n.properties,T.replaceAll(".",".properties.")):void 0,P=e.jsxs(t.Button,{color:"primary",variant:"outlined",onClick:()=>h(!0),startIcon:e.jsx(t.AddIcon,{}),children:["Add property to ",n.name??"this group"]}),N=!m||m.length<1,S=b.useCallback((y,x)=>{i(te(x),y,!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"}),P]}),e.jsxs(t.Paper,{className:"p-2 pl-8",children:[e.jsx(Pe,{properties:n.properties??{},propertiesOrder:m,errors:{},collectionEditable:s,onPropertyClick:(y,x)=>{c(y),u(x),h(!0)},onPropertyMove:S}),N&&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:y=>i("spreadChildren",y),value:n.spreadChildren??!1}),e.jsx(W,{children:"Set this flag to true if you want to display the children of this group as individual columns."})]}),e.jsx(he,{inArray:!1,forceShowErrors:!1,open:p,allowDataInference:a,collectionEditable:s,onCancel:()=>{h(!1),c(void 0),u(void 0)},onOkClicked:()=>{h(!1),c(void 0),u(void 0)},getData:o,onDelete:C,propertyKey:g,propertyNamespace:d,property:k,existingProperty:!!g,autoUpdateId:!g,autoOpenTypeSelect:!g,onPropertyChanged:w,existingPropertyKeys:g?void 0:m,propertyConfigs:l})]})}function Vr({showErrors:r,existing:o,disabled:a,getData:l,allowDataInference:s,propertyConfigs:n,collectionEditable:i}){const{values:p,handleChange:h,errors:g,setFieldValue:c,touched:d}=H(),[u,m]=b.useState(!1),w=E(p,"of"),C=E(d,"of")&&E(g,"of"),T=({id:P,property:N,namespace:S})=>{console.log("onPropertyChanged",P,N,S),c("of",N)},k=w&&f.getFieldConfig(w,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,{name:"of",value:w,children:({})=>e.jsxs(t.Paper,{className:"p-2 mt-4",children:[w&&e.jsx(Qe,{property:w,onClick:a?void 0:()=>m(!0),includeName:!1,includeEditButton:!0,selected:!1,hasError:!1}),!a&&!w&&e.jsxs(t.Button,{variant:"text",size:"large",color:C?"error":"primary",onClick:()=>m(!0),children:["Edit ",`${k?k.name:"repeat component"}`]}),e.jsx(he,{inArray:!0,open:u,existingProperty:o,getData:l,autoUpdateId:!o,autoOpenTypeSelect:!o,onOkClicked:()=>m(!1),allowDataInference:s,property:w,includeIdAndName:!1,onPropertyChanged:T,forceShowErrors:r,propertyConfigs:n,collectionEditable:i})]})})]}),e.jsx("div",{className:"col-span-12",children:e.jsx(le,{children:e.jsx(Ae,{disabled:a})})})]})}const Br=b.forwardRef(function({showErrors:o,disabledId:a,disabled:l,autoUpdateId:s,isNewProperty:n},i){const{errors:p,values:h,setFieldValue:g,setFieldTouched:c,touched:d,validate:u}=H(),m="name",w=o&&E(p,m),C="id",T=o&&E(p,C),k="description",P=o&&E(p,k);return e.jsxs("div",{className:"flex flex-col gap-2 col-span-12",children:[e.jsxs("div",{children:[e.jsx(G,{name:m,inputRef:i,as:t.DebouncedTextField,value:h[m],onChange:N=>{const S=N.target.value;!E(d,C)&&s&&g(C,S?f.toSnakeCase(S):"",!1),g(m,S,!0),c(m,!0)},style:{fontSize:20},placeholder:"Field name",required:!0,disabled:l,error:!!w}),e.jsx(W,{error:!!w,children:w})]}),e.jsxs("div",{children:[e.jsx(G,{name:C,as:t.DebouncedTextField,label:"ID",value:h[C],onChange:N=>{const S=N.target.value;!E(d,m)&&s&&g(m,S?f.unslugify(S):""),g(C,S,!0),c(C,!0)},disabled:a||l,required:!0,size:"small",error:!!T}),e.jsx(W,{error:!!T,children:T})]}),e.jsxs("div",{children:[e.jsx(G,{name:k,as:t.DebouncedTextField,label:"Description",disabled:l,error:!!P}),e.jsx(W,{error:!!P,children:P})]})]})});function _r({widgetId:r,disabled:o,showErrors:a}){const{values:l,setFieldValue:s}=H();return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"col-span-12",children:e.jsxs(le,{children:[r==="text_field"&&e.jsx(ue,{disabled:o,length:!0,lowercase:!0,matches:!0,max:!0,min:!0,trim:!0,uppercase:!0,showErrors:a}),r==="multiline"&&e.jsx(ue,{disabled:o,length:!0,lowercase:!0,max:!0,min:!0,trim:!0,uppercase:!0,showErrors:a}),r==="markdown"&&e.jsx(ue,{disabled:o,length:!0,lowercase:!0,max:!0,min:!0,trim:!0,uppercase:!0,showErrors:a}),r==="email"&&e.jsx(ue,{disabled:o,max:!0,min:!0,trim:!0,showErrors:a})]})}),e.jsx("div",{className:"col-span-12",children:e.jsx(t.TextField,{name:"defaultValue",disabled:o,onChange:n=>{s("defaultValue",n.target.value===""?void 0:n.target.value)},label:"Default value",value:E(l,"defaultValue")??""})})]})}function Dr({disabled:r}){const{values:o}=H(),a=E(o,"defaultValue");return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"col-span-12",children:e.jsx(le,{children:e.jsx(pe,{disabled:r})})}),e.jsx("div",{className:"col-span-12",children:e.jsx(G,{name:"defaultValue",children:({field:l,form:s})=>e.jsx(R,{label:a==null?"Default value not set":"Default value is "+a.toString(),disabled:r,allowIndeterminate:!0,field:l,form:s})})})]})}function Ar({disabled:r,getData:o,allowDataInference:a,propertyConfigs:l,collectionEditable:s}){const{values:n,setFieldValue:i}=H(),[p,h]=b.useState(!1),[g,c]=b.useState(),[d,u]=b.useState(),m=b.useCallback(({id:N,property:S})=>{if(!N)throw Error();i("oneOf.properties",{...n.oneOf?.properties??{},[N]:S},!1),i("oneOf.propertiesOrder",[...n.oneOf?.propertiesOrder??Object.keys(n.oneOf?.properties??{}),N],!1),h(!1)},[n.oneOf?.properties,n.oneOf?.propertiesOrder]),w=g?Q(g,d):void 0,C=w?E(n.oneOf?.properties,w.replaceAll(".",".properties.")):void 0,T=b.useCallback((N,S)=>{const y=N?Q(N,S):void 0;if(!y)throw Error("collection editor miss config");i(`oneOf.${ee(y)}`,void 0,!1);const x=`oneOf.${te(S)}`,B=E(n,x);i(x,B.filter($=>$!==N),!1),h(!1),c(void 0),u(void 0)},[i,n]),k=e.jsxs(t.Button,{autoFocus:!0,color:"primary",onClick:()=>h(!0),startIcon:e.jsx(t.AddIcon,{}),children:["Add property to ",n.name??"this block"]}),P=b.useCallback((N,S)=>{i(`oneOf.${te(S)}`,N,!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"}),k]}),e.jsxs(t.Paper,{className:"p-2 pl-8",children:[e.jsx(Pe,{properties:n.oneOf?.properties??{},propertiesOrder:n.oneOf?.propertiesOrder,errors:{},collectionEditable:s,onPropertyClick:r?void 0:(N,S)=>{c(N),u(S),h(!0)},onPropertyMove:r?void 0:P}),!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(he,{inArray:!1,forceShowErrors:!1,open:p,getData:o,allowDataInference:a,onCancel:()=>{h(!1),c(void 0),u(void 0)},onOkClicked:()=>{h(!1),c(void 0),u(void 0)},collectionEditable:s,onDelete:T,propertyKey:g,propertyNamespace:d,property:C,existingProperty:!!g,autoUpdateId:!g,autoOpenTypeSelect:!g,onPropertyChanged:m,existingPropertyKeys:g?void 0:n.oneOf?.propertiesOrder,propertyConfigs:l})]})}function Mr({disabled:r}){const{values:o,handleChange:a}=H(),l="validation.min",s="validation.max",n="validation.lessThan",i="validation.moreThan",p="validation.positive",h="validation.negative",g="validation.integer";return e.jsxs("div",{className:"grid grid-cols-12 gap-2",children:[e.jsx(pe,{disabled:r}),e.jsx("div",{className:"col-span-6",children:e.jsx(t.DebouncedTextField,{value:E(o,l),label:"Min value",name:l,type:"number",size:"small",disabled:r,onChange:a})}),e.jsx("div",{className:"col-span-6",children:e.jsx(t.DebouncedTextField,{value:E(o,s),label:"Max value",name:s,type:"number",size:"small",disabled:r,onChange:a})}),e.jsx("div",{className:"col-span-6",children:e.jsx(t.DebouncedTextField,{value:E(o,n),label:"Less than",name:n,type:"number",size:"small",disabled:r,onChange:a})}),e.jsx("div",{className:"col-span-6",children:e.jsx(t.DebouncedTextField,{value:E(o,i),label:"More than",name:i,type:"number",size:"small",disabled:r,onChange:a})}),e.jsx("div",{className:"col-span-4",children:e.jsx(G,{name:p,type:"checkbox",children:({field:c,form:d})=>e.jsx(R,{label:"Positive value",disabled:r,form:d,field:c})})}),e.jsx("div",{className:"col-span-4",children:e.jsx(G,{name:h,type:"checkbox",children:({field:c,form:d})=>e.jsx(R,{label:"Negative value",disabled:r,form:d,field:c})})}),e.jsx("div",{className:"col-span-4",children:e.jsx(G,{name:g,type:"checkbox",children:({field:c,form:d})=>e.jsx(R,{label:"Integer value",disabled:r,form:d,field:c})})})]})}function zr({disabled:r}){const{values:o,setFieldValue:a}=H();return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"col-span-12",children:e.jsx(le,{children:e.jsx(Mr,{disabled:r})})}),e.jsx("div",{className:"col-span-12",children:e.jsx(t.TextField,{name:"defaultValue",disabled:r,type:"number",onChange:l=>{a("defaultValue",l.target.value===""?void 0:parseFloat(l.target.value))},label:"Default value",value:E(o,"defaultValue")??""})})]})}function Xe({existing:r,multiple:o,disabled:a,showErrors:l}){const{values:s,handleChange:n,errors:i}=H();if(!f.useNavigationController())return e.jsx("div",{className:"col-span-12",children:e.jsx(t.CircularProgress,{})});const h=o?"of.path":"path",g=E(s,h),c=l&&E(i,h);return e.jsx(e.Fragment,{children:e.jsx("div",{className:"col-span-12",children:e.jsx(G,{name:h,pathPath:h,type:"select",disabled:r||a,value:g,error:c,handleChange:n,as:Ur})})})}function Ur({disabled:r,pathPath:o,value:a,handleChange:l,error:s,...n}){const i=f.useNavigationController();if(!i)return e.jsx("div",{className:"col-span-12",children:e.jsx(t.CircularProgress,{})});const p=i?.collections??[],h=Array.from(new Set(Object.values(p).map(c=>c.group).filter(Boolean)).values()),g=p.filter(c=>!c.group);return e.jsxs(e.Fragment,{children:[e.jsxs(t.Select,{error:!!s,disabled:r,value:a??"",position:"item-aligned",name:o,onChange:l,label:"Target collection",renderValue:c=>{const d=p.find(u=>u.id===c||u.path===c);return d?e.jsxs("div",{className:"flex flex-row",children:[e.jsx(f.IconForView,{collectionOrView:d}),e.jsx(t.Typography,{variant:"subtitle2",className:"font-medium ml-4",children:d?.name.toUpperCase()})]}):null},...n,children:[h.flatMap(c=>e.jsx(t.SelectGroup,{label:c||"Views",children:p.filter(d=>d.group===c).map(d=>e.jsx(t.SelectItem,{value:d.id??d.path,children:e.jsxs("div",{className:"flex flex-row",children:[e.jsx(f.IconForView,{collectionOrView:d}),e.jsx(t.Typography,{variant:"subtitle2",className:"font-medium ml-4",children:d?.name.toUpperCase()})]})},`${d.id??d.path}-${c}`))},`group_${c}`)),g&&e.jsx(t.SelectGroup,{label:"Views",children:g.map(c=>e.jsx(t.SelectItem,{value:c.id??c.path,children:e.jsxs("div",{className:"flex flex-row",children:[e.jsx(f.IconForView,{collectionOrView:c}),e.jsx(t.Typography,{variant:"subtitle2",className:"font-medium ml-4",children:c?.name.toUpperCase()})]})},c.id??c.path))})]}),e.jsx(W,{children:"You can only edit the reference collection upon field creation."})]})}function Lr({disabled:r}){const{values:o,errors:a,touched:l,setFieldValue:s}=H(),n="mode",i=E(o,n),p=E(l,n)&&E(a,n),h="autoValue",g=E(o,h),c=E(l,h)&&E(a,h);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col col-span-12",children:[e.jsxs(t.Select,{name:n,value:i??"date",error:!!p,onValueChange:d=>s(n,d),label:"Mode",renderValue:d=>{switch(d){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(W,{error:!!p,children:p}),e.jsxs(t.Select,{name:h,disabled:r,value:g??"",onValueChange:d=>s(h,d),renderValue:d=>{switch(d){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(W,{error:!!c,children:c??"Update this field automatically when creating or updating the entity"})]}),e.jsx("div",{className:"col-span-12",children:e.jsx(le,{children:e.jsx(pe,{disabled:r})})})]})}function qr({disabled:r}){const o="hideFromCollection",a="readOnly";return e.jsxs("div",{className:"grid grid-cols-12 gap-2",children:[e.jsx("div",{className:"col-span-12",children:e.jsx(G,{type:"checkbox",name:o,children:({field:l,form:s})=>e.jsx(R,{label:"Hide from collection",disabled:r,form:s,tooltip:"Hide this field from the collection view. It will still be visible in the form view",field:l})})}),e.jsx("div",{className:"col-span-12",children:e.jsx(G,{name:a,type:"checkbox",children:({field:l,form:s})=>e.jsx(R,{label:"Read only",disabled:r,tooltip:"Is this a read only field. Display only as a preview",form:s,field:l})})})]})}function $r({disabled:r}){return e.jsx(e.Fragment,{children:e.jsx("div",{className:"col-span-12",children:e.jsx(le,{children:e.jsx(pe,{disabled:r})})})})}function Re(r,o,a){let l;return o==="text_field"?l=f.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}):o==="multiline"?l=f.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}):o==="markdown"?l=f.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}):o==="url"?l=f.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}):o==="email"?l=f.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}):o==="select"?l=f.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??[]}):o==="multi_select"?l=f.mergeDeep(r,{dataType:"array",propertyConfig:"multi_select",editable:r.editable!==void 0?r.editable:!0,of:{dataType:"string",enumValues:r.of?.enumValues??[]}}):o==="number_input"?l=f.mergeDeep(r,{dataType:"number",propertyConfig:"number_input",editable:r.editable!==void 0?r.editable:!0,enumValues:void 0}):o==="number_select"?l=f.mergeDeep(r,{dataType:"number",propertyConfig:"number_select",editable:r.editable!==void 0?r.editable:!0,enumValues:r.enumValues??[]}):o==="multi_number_select"?l=f.mergeDeep(r,{dataType:"array",propertyConfig:"multi_number_select",editable:r.editable!==void 0?r.editable:!0,of:{dataType:"number",enumValues:r.of?.enumValues??[]}}):o==="file_upload"?l=f.mergeDeep(r,{dataType:"string",propertyConfig:"file_upload",editable:r.editable!==void 0?r.editable:!0,storage:{storagePath:"/"}}):o==="multi_file_upload"?l=f.mergeDeep(r,{dataType:"array",propertyConfig:"multi_file_upload",editable:r.editable!==void 0?r.editable:!0,of:{dataType:"string",storage:r.of?.storage??{storagePath:"/"}}}):o==="group"?l=f.mergeDeep(r,{dataType:"map",propertyConfig:"group",editable:r.editable!==void 0?r.editable:!0,keyValue:!1,properties:r.properties??{}}):o==="key_value"?l=f.mergeDeep(r,{dataType:"map",propertyConfig:"key_value",editable:r.editable!==void 0?r.editable:!0,keyValue:!0,properties:void 0}):o==="reference"?l=f.mergeDeep(r,{dataType:"reference",propertyConfig:"reference",editable:r.editable!==void 0?r.editable:!0}):o==="multi_references"?l=f.mergeDeep(r,{dataType:"array",propertyConfig:"multi_references",editable:r.editable!==void 0?r.editable:!0,of:{dataType:"reference"}}):o==="switch"?l=f.mergeDeep(r,{dataType:"boolean",propertyConfig:"switch",editable:r.editable!==void 0?r.editable:!0}):o==="date_time"?l=f.mergeDeep(r,{dataType:"date",propertyConfig:"date_time",editable:r.editable!==void 0?r.editable:!0,mode:"date_time"}):o==="repeat"?l=f.mergeDeep(r,{dataType:"array",propertyConfig:"repeat",editable:r.editable!==void 0?r.editable:!0}):o==="block"?l=f.mergeDeep(r,{dataType:"array",propertyConfig:"block",editable:r.editable!==void 0?r.editable:!0,oneOf:{properties:{}}}):o&&a[o]&&(l={...a[o].property,propertyConfig:o}),l}function er({value:r,optionDisabled:o,propertyConfig:a,existing:l}){return e.jsx(t.SelectItem,{value:r,disabled:o,className:"flex flex-row items-center",children:e.jsxs("div",{className:t.cn("flex flex-row items-center text-base min-h-[52px]",o?"w-full":""),children:[e.jsx("div",{className:"mr-8",children:e.jsx(f.PropertyConfigBadge,{propertyConfig:a})}),e.jsxs("div",{children:[e.jsx("div",{children:a.name}),e.jsx(t.Typography,{variant:"caption",color:"disabled",className:"max-w-sm",children:l&&o?"You can only switch to widgets that use the same data type":a.description})]})]})})}function jr({disabled:r,showErrors:o}){const{values:a,setFieldValue:l}=H(),s=E(a,"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]"?l("url",!0):l("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(le,{children:e.jsx(ue,{disabled:r,max:!0,min:!0,trim:!0,showErrors:o})})}),e.jsx("div",{className:"col-span-12",children:e.jsx(t.TextField,{name:"defaultValue",disabled:r,onChange:n=>{l("defaultValue",n.target.value===""?void 0:n.target.value)},label:"Default value",value:E(a,"defaultValue")??""})})]})}const Yr=["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"],rr=Object.entries(f.DEFAULT_FIELD_CONFIGS).filter(([r])=>Yr.includes(r)).map(([r,o])=>({[r]:o})).reduce((r,o)=>({...r,...o}),{}),tr=b.memo(function(o){const{includeIdAndName:a=!0,autoOpenTypeSelect:l,existingProperty:s,autoUpdateId:n,inArray:i,propertyKey:p,existingPropertyKeys:h,propertyNamespace:g,property:c,onPropertyChanged:d,onPropertyChangedImmediate:u=!0,onDelete:m,onError:w,initialErrors:C,forceShowErrors:T,allowDataInference:k,getController:P,getData:N,propertyConfigs:S,collectionEditable:y}=o,x={id:"",name:""},B=!!(c&&!ye(c))&&!y,$=b.useRef(c?{id:p,previousId:p,property:c}:void 0),q=({id:F,property:v})=>{const V={id:F,previousId:$.current?.id,property:v,namespace:g};$.current=V,d?.(V)},L=_e({initialValues:c?{id:p,...c}:x,initialErrors:C,validateOnChange:!0,validateOnInitialRender:!0,onSubmit:(F,v)=>{console.debug("onSubmit",F);const{id:V,..._}=F;q({id:V,property:{..._,editable:_.editable??!0}}),s||v.resetForm({values:x})},validation:F=>{const v={};if(a){if(!F.name)v.name="Required";else{const V=Wr(F.name);V&&(v.name=V)}if(!F.id)v.id="Required";else{const V=Kr(F.id,h);V&&(v.id=V)}}return F.dataType==="string"&&F.validation?.matches&&!f.isValidRegExp(F.validation?.matches.toString())&&(v.validation={matches:"Invalid regular expression"}),F.dataType==="reference"&&!F.path&&(v.path="You must specify a target collection for the field"),F.propertyConfig==="repeat"&&(F.of||(v.of="You need to specify a repeat field")),F.propertyConfig==="block"&&(F.oneOf||(v.oneOf="You need to specify the properties of this block")),v}});return b.useEffect(()=>{P?.(L)},[L,P]),e.jsx(Be,{value:L,children:e.jsx(Hr,{onPropertyChanged:u?q:void 0,onDelete:m,includeIdAndTitle:a,propertyNamespace:g,onError:w,showErrors:T||L.submitCount>0,existing:s,autoUpdateId:n,inArray:i,autoOpenTypeSelect:l,disabled:B,getData:N,allowDataInference:k,propertyConfigs:S,collectionEditable:y,...L})})},(r,o)=>r.getData===o.getData&&r.propertyKey===o.propertyKey&&r.propertyNamespace===o.propertyNamespace&&r.includeIdAndName===o.includeIdAndName&&r.autoOpenTypeSelect===o.autoOpenTypeSelect&&r.autoUpdateId===o.autoUpdateId&&r.existingProperty===o.existingProperty);function he({open:r,onCancel:o,onOkClicked:a,onPropertyChanged:l,getData:s,collectionEditable:n,...i}){const p=b.useRef(),h=g=>{p.current=g};return e.jsx(t.Dialog,{open:r??!1,maxWidth:"xl",fullWidth:!0,children:e.jsxs("form",{noValidate:!0,onSubmit:g=>{g.preventDefault(),g.stopPropagation(),p.current?.submitForm(g)},children:[e.jsx(t.DialogContent,{children:e.jsx(tr,{...i,onPropertyChanged:g=>{l?.(g),a?.()},collectionEditable:n,onPropertyChangedImmediate:!1,getController:h,getData:s})}),e.jsxs(t.DialogActions,{children:[o&&e.jsx(t.Button,{variant:"text",onClick:()=>{o(),p.current?.resetForm()},children:"Cancel"}),e.jsx(t.Button,{variant:"outlined",type:"submit",color:"primary",children:"Ok"})]})]})})}function Hr({values:r,errors:o,setValues:a,existing:l,autoUpdateId:s=!1,autoOpenTypeSelect:n,includeIdAndTitle:i,onPropertyChanged:p,onDelete:h,propertyNamespace:g,onError:c,showErrors:d,disabled:u,inArray:m,getData:w,allowDataInference:C,propertyConfigs:T,collectionEditable:k}){const[P,N]=b.useState(n),[S,y]=b.useState(!1),[x,B]=b.useState(r?.dataType?f.getFieldId(r):void 0),$=Object.entries(rr).concat(Object.entries(T)),q=m?$.filter(([z,U])=>!f.isPropertyBuilder(U.property)&&U.property?.dataType!=="array"):$,L=b.useDeferredValue(r),F=b.useRef(null),v=b.useRef(r),V=d&&E(o,"selectedWidget");b.useEffect(()=>{if(p&&(!i||L.id)){const{id:z,...U}=L;oe(L,v.current)||(p({id:z,property:U,namespace:g}),v.current=L)}},[L,i,p,g]),b.useEffect(()=>{r?.id&&c&&c(r?.id,g,o)},[o,c,g,r?.id]);const _=z=>{B(z),a(Re(r,z,T)),setTimeout(()=>{F.current?.focus()},0)};let O;return x==="text_field"||x==="multiline"||x==="markdown"||x==="email"?O=e.jsx(_r,{widgetId:x,disabled:u,showErrors:d}):x==="url"?O=e.jsx(jr,{disabled:u,showErrors:d}):x==="select"||x==="number_select"?O=e.jsx(We,{multiselect:!1,allowDataInference:C,updateIds:!l,disabled:u,getData:w,showErrors:d}):x==="multi_select"||x==="multi_number_select"?O=e.jsx(We,{multiselect:!0,updateIds:!l,disabled:u,allowDataInference:C,getData:w,showErrors:d}):x==="file_upload"?O=e.jsx(Ze,{existing:l,multiple:!1,disabled:u}):x==="multi_file_upload"?O=e.jsx(Ze,{existing:l,multiple:!0,disabled:u}):x==="switch"?O=e.jsx(Dr,{disabled:u}):x==="number_input"?O=e.jsx(zr,{disabled:u}):x==="group"?O=e.jsx(Er,{disabled:u,getData:w,allowDataInference:C,collectionEditable:k,propertyConfigs:T}):x==="block"?O=e.jsx(Ar,{disabled:u,getData:w,allowDataInference:C,collectionEditable:k,propertyConfigs:T}):x==="reference"?O=e.jsx(Xe,{showErrors:d,existing:l,multiple:!1,disabled:u}):x==="date_time"?O=e.jsx(Lr,{disabled:u}):x==="multi_references"?O=e.jsx(Xe,{showErrors:d,existing:l,multiple:!0,disabled:u}):x==="repeat"?O=e.jsx(Vr,{showErrors:d,existing:l,getData:w,allowDataInference:C,disabled:u,collectionEditable:k,propertyConfigs:T}):x==="key_value"?O=e.jsx($r,{disabled:u}):O=null,e.jsxs(e.Fragment,{children:[u&&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:!!V,value:x??"",placeholder:"Select a property widget",open:P,onOpenChange:N,position:"item-aligned",disabled:u,renderValue:z=>{if(!z)return e.jsx("em",{children:"Select a property widget"});const U=z,K=f.DEFAULT_FIELD_CONFIGS[U]??T[U],X=K.property,ve=X&&!f.isPropertyBuilder(X)?f.getFieldConfig(X,T):void 0,de=f.isPropertyBuilder(X)||l&&X.dataType!==r?.dataType,re=ve?f.mergeDeep(ve,K):K;return e.jsxs("div",{onClick:J=>{de&&(J.stopPropagation(),J.preventDefault())},className:t.cn("flex items-center",de?"w-full pointer-events-none opacity-50":""),children:[e.jsx("div",{className:"mr-8",children:e.jsx(f.PropertyConfigBadge,{propertyConfig:re})}),e.jsxs("div",{className:"flex flex-col items-start text-base text-left",children:[e.jsx("div",{children:re.name}),e.jsx(t.Typography,{variant:"caption",color:"disabled",children:de?"You can only switch to widgets that use the same data type":re.description})]})]})},onValueChange:z=>{_(z)},children:q.map(([z,U])=>{const K=U.property,X=l&&!f.isPropertyBuilder(K)&&K.dataType!==r?.dataType;return e.jsx(er,{value:z,optionDisabled:X,propertyConfig:U,existing:l},z)})}),V&&e.jsx(t.Typography,{variant:"caption",className:"ml-3.5",color:"error",children:"Required"})]}),h&&r?.id&&e.jsx(t.IconButton,{variant:"ghost",className:"m-4",disabled:u,onClick:()=>y(!0),children:e.jsx(t.DeleteIcon,{})})]}),e.jsxs("div",{className:"grid grid-cols-12 gap-y-12 mt-8 mb-8",children:[i&&e.jsx(Br,{showErrors:d,disabledId:l,isNewProperty:!l,disabled:u,autoUpdateId:s,ref:F}),O,e.jsx("div",{className:"col-span-12",children:e.jsx(qr,{disabled:u})})]}),h&&e.jsx(f.DeleteConfirmationDialog,{open:S,onAccept:()=>h(r?.id,g),onCancel:()=>y(!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."]})})]})}const Gr=/^[a-zA-Z_][a-zA-Z0-9_]*$/;function Kr(r,o){let a;return r||(a="You must specify an id for the field"),r&&!r.match(Gr)&&(a="The id can only contain letters, numbers and underscores (_), and not start with a number"),r&&o&&o.includes(r)&&(a="There is another field with this ID already"),a}function Wr(r){let o;return r||(o="You must specify a title for the field"),o}function Zr(r){return r?(r.slice(0,1).toLowerCase()+r.slice(1)).replace(/([-_ ]){1,}/g," ").split(/[-_ ]/).reduce((o,a)=>o+a[0].toUpperCase()+a.substring(1),""):""}function Jr({collection:r,onOpenChange:o,open:a}){const l=f.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.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"})});
3
+ const `+(r.name?Zr(r.name):"my")+"Collection:EntityCollection = "+vr.stringify(or(r),null," ");return e.jsxs(t.Dialog,{open:a,onOpenChange:o,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(qe.Highlight,{theme:qe.themes.vsDark,code:s,language:"typescript",children:({className:n,style:i,tokens:p,getLineProps:h,getTokenProps:g})=>e.jsx("pre",{style:i,className:"p-4 rounded text-sm",children:p.map((c,d)=>e.jsx("div",{...h({line:c}),children:c.map((u,m)=>e.jsx("span",{...g({token:u})},m))},d))})})]}),e.jsxs(t.DialogActions,{children:[e.jsxs(t.Button,{variant:"text",size:"small",onClick:n=>(n.stopPropagation(),n.preventDefault(),l.open({type:"success",message:"Copied"}),navigator.clipboard.writeText(s)),children:[e.jsx(t.ContentCopyIcon,{size:"small"}),"Copy to clipboard"]}),e.jsx(t.Button,{onClick:()=>o(!1),children:"Close"})]})]})}function or(r){const o=a=>{const l={...a};return delete l.fromBuilder,delete l.resolved,delete l.propertiesOrder,delete l.editable,l.type==="map"?{...l,properties:l.properties.map(o)}:l};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(([a,l])=>({[a]:o(l)})).reduce((a,l)=>({...a,...l}),{}),subcollections:(r.subcollections??[]).map(or)}}function Qr({showErrors:r,isNewCollection:o,propertyErrorsRef:a,onPropertyError:l,setDirty:s,reservedGroups:n,extraIcon:i,getUser:p,getData:h,doCollectionInference:g,propertyConfigs:c,collectionEditable:d}){const{values:u,setFieldValue:m,setFieldError:w,setFieldTouched:C,errors:T,dirty:k}=H(),P=f.useSnackbarController(),N=f.useLargeLayout(),S=!N,[y,x]=b.useState(),[B,$]=b.useState(),[q,L]=b.useState(),F=B?Q(B,q):void 0,v=F?E(u.properties,F.replaceAll(".",".properties.")):void 0,[V,_]=b.useState(!1),[O,z]=b.useState(!1),[U,K]=b.useState(!1),[X,ve]=b.useState([]),de=b.useRef(u.propertiesOrder?{"":u.propertiesOrder}:{});b.useEffect(()=>{s&&s(k)},[k]);const re=g?()=>{g&&(z(!0),g(u).then(D=>{if(D&&f.makePropertiesEditable(D.properties),!D){P.open({type:"error",message:"Could not infer properties from data"});return}const Y=(D.properties?Object.keys(D.properties):[]).filter(M=>!u.properties[M]);if(Y.length===0){P.open({type:"info",message:"No new properties found in existing data"});return}const I={...Y.reduce((M,Z)=>(M[Z]=(D.properties??{})[Z],M),{}),...u.properties},A=[...Y,...u.propertiesOrder??[]];m("properties",I,!1),se(A),ve(Y)}).finally(()=>{z(!1)}))}:void 0,J=b.useCallback(D=>D?de.current[D]??E(u,te(D)):de.current[""],[u]),se=b.useCallback((D,Y)=>{const I=te(Y);m(I,D,!1),de.current[Y??""]=D},[m]),fe=b.useCallback((D,Y)=>{const I=D?Q(D,Y):void 0;if(!I)throw Error("collection editor miss config");m(ee(I),void 0,!1);const M=J(Y).filter(Z=>Z!==D);se(M,Y),K(!1),x(void 0),$(void 0),L(void 0)},[J,m,se]),we=(D,Y)=>{m(te(Y),D,!1)},ze=({id:D,property:Y})=>{if(!D)throw Error("Need to include an ID when creating a new property");m("properties",{...u.properties??{},[D]:Y},!1);const I=[...u.propertiesOrder??Object.keys(u.properties),D];se(I),K(!1),N&&(x(I.indexOf(D)),$(D)),L(void 0)},ie=({id:D,property:Y,previousId:I,namespace:A})=>{const M=D?Q(D,A):void 0,Z=M?ee(M):void 0;if(I&&I!==D){const ge=Q(I,A),gr=ee(ge),ur=J(A).map(Oe=>Oe===I?D:Oe).filter(Oe=>Oe!==void 0);se(ur,A),D&&(x(ur.indexOf(D)),$(D)),m(gr,void 0,!1),C(gr,!1,!1)}console.debug("onPropertyChanged",{id:D,property:Y,previousId:I,namespace:A,propertyPath:Z}),Z&&(m(Z,Y,!1),C(Z,!0,!1))},xe=b.useCallback((D,Y,I)=>{const A=D?Q(D,Y):void 0;if(console.debug("onPropertyErrorInternal",{id:D,namespace:Y,error:I,propertyPath:A}),A){const M=I&&Object.keys(I).length>0;l(D,Y,M?I:void 0),w(ee(A),M?"Property error":void 0)}},[]),ke=()=>{x(void 0),$(void 0)},Fe=B&&a?.current?.properties?a.current.properties[B]:void 0,Ie=u?.propertiesOrder===void 0||u.propertiesOrder.length===0,me=u.propertiesOrder?u.propertiesOrder:Object.keys(u.properties),Se=b.useMemo(()=>p(u.ownerId),[p,u.ownerId]),Ue=b.useCallback((D,Y)=>{console.debug("CollectionEditor: onPropertyClick",{propertyKey:D,namespace:Y}),x(me.indexOf(D)),$(D),L(Y)},[me]),Le=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",!S&&"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,{name:"name",as:t.DebouncedTextField,invisible:!0,className:"-ml-1",inputClassName:"text-2xl font-headers",placeholder:"Collection name",size:"small",required:!0,error:!!T?.name}),Se&&e.jsxs(t.Typography,{variant:"body2",className:"ml-2",color:"secondary",children:["Created by ",Se.displayName]})]}),i&&e.jsx("div",{className:"ml-4",children:i}),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:O,onClick:()=>_(!0),children:e.jsx(t.CodeIcon,{})})}),re&&e.jsx(t.Tooltip,{title:"Add new properties based on data",children:e.jsx(t.IconButton,{variant:"filled",disabled:O,onClick:re,children:O?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:()=>K(!0),children:e.jsx(t.AddIcon,{})})})]})]}),e.jsx(f.ErrorBoundary,{children:e.jsx(Pe,{className:"pl-8",inferredPropertyKeys:X,selectedPropertyKey:B?Q(B,q):void 0,properties:u.properties,additionalFields:u.additionalFields,propertiesOrder:me,onPropertyClick:Ue,onPropertyMove:we,onPropertyRemove:o?fe:void 0,collectionEditable:d,errors:T})}),e.jsx(t.Button,{className:"mt-8 w-full",color:"primary",variant:"outlined",size:"large",onClick:()=>K(!0),startIcon:e.jsx(t.AddIcon,{}),children:"Add new property"})]}),!S&&e.jsx("div",{className:"col-span-12 lg:col-span-7 p-4 md:py-8 md:px-4 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:[F&&v&&!f.isPropertyBuilder(v)&&e.jsx(tr,{inArray:!1,existingProperty:!o,autoUpdateId:!1,allowDataInference:!o,autoOpenTypeSelect:!1,propertyKey:B,propertyNamespace:q,property:v,onPropertyChanged:ie,onDelete:fe,onError:xe,forceShowErrors:r,initialErrors:Fe,getData:h,propertyConfigs:c,collectionEditable:d},`edit_view_${y}`),!v&&e.jsx(t.Typography,{variant:"label",className:"flex items-center justify-center h-full",children:Ie?"Now you can add your first property":"Select a property to edit it"}),v&&f.isPropertyBuilder(v)&&e.jsx(t.Typography,{variant:"label",className:"flex items-center justify-center",children:"This property is defined as a property builder in code"})]})}),S&&e.jsx(he,{inArray:!1,open:y!==void 0,autoUpdateId:!v,allowDataInference:!o,existingProperty:!0,autoOpenTypeSelect:!1,propertyKey:B,propertyNamespace:q,property:v,onPropertyChanged:ie,onDelete:fe,onError:xe,forceShowErrors:r,initialErrors:Fe,getData:h,propertyConfigs:c,collectionEditable:d,onOkClicked:S?ke:void 0},`edit_view_${y}`)]});return e.jsxs(e.Fragment,{children:[Le,e.jsx(he,{inArray:!1,existingProperty:!1,autoOpenTypeSelect:!0,autoUpdateId:!0,forceShowErrors:r,open:U,onCancel:()=>K(!1),onPropertyChanged:ze,getData:h,allowDataInference:!o,propertyConfigs:c,collectionEditable:d,existingPropertyKeys:u.propertiesOrder}),e.jsx(Jr,{collection:u,open:V,onOpenChange:_})]})}function Xr({open:r,handleOk:o,handleCancel:a,body:l,title:s}){return e.jsxs(t.Dialog,{open:r,onOpenChange:n=>n?a():o(),"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"}),l&&e.jsx(t.Typography,{children:l}),e.jsx(t.Typography,{children:"Are you sure?"})]}),e.jsxs(t.DialogActions,{children:[e.jsx(t.Button,{variant:"text",onClick:a,autoFocus:!0,children:" Cancel "}),e.jsx(t.Button,{onClick:o,children:" Ok "})]})]})}function Rr({open:r,onClose:o}){const{entityViews:a}=f.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"}),a?.map(l=>e.jsxs(t.Button,{onClick:()=>o(l.key),fullWidth:!0,variant:"text",children:[l.name," (",l.key,")"]},l.key)),(a??[]).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:()=>o(),children:"Cancel"})})]})}function et({collection:r,parentCollection:o,configController:a,collectionInference:l,getUser:s,parentCollectionIds:n}){const{entityViews:i}=f.useCustomizationController(),[p,h]=b.useState(),[g,c]=b.useState(!1),[d,u]=b.useState(),[m,w]=b.useState(),{values:C,setFieldValue:T}=H(),k=r.subcollections??[],P=C.entityViews?.filter(y=>typeof y=="string").map(y=>f.resolveEntityView(y,i)).filter(Boolean)??[],N=r.entityViews?.filter(y=>typeof y!="string")??[],S=P.length+N.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 ",C.name]}),k&&k.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:k.map(y=>e.jsxs(t.TableRow,{onClick:()=>w({isNewCollection:!1,editedCollectionPath:y.path}),children:[e.jsx(t.TableCell,{align:"left",children:e.jsx(t.Typography,{variant:"subtitle2",className:"flex-grow",children:y.name})}),e.jsx(t.TableCell,{align:"right",children:e.jsx(t.Tooltip,{title:"Remove",children:e.jsx(t.IconButton,{size:"small",onClick:x=>{x.preventDefault(),x.stopPropagation(),h(y.id)},color:"inherit",children:e.jsx(t.DeleteIcon,{size:"small"})})})})]},y.path))})})}),e.jsx(t.Button,{onClick:()=>{w({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"}),S>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:[P.map(y=>e.jsxs(t.TableRow,{children:[e.jsx(t.TableCell,{align:"left",children:e.jsx(t.Typography,{variant:"subtitle2",className:"flex-grow",children:y.name})}),e.jsx(t.TableCell,{align:"right",children:e.jsx(t.Tooltip,{title:"Remove",children:e.jsx(t.IconButton,{size:"small",onClick:x=>{x.preventDefault(),x.stopPropagation(),u(y.key)},color:"inherit",children:e.jsx(t.DeleteIcon,{size:"small"})})})})]},y.key)),N.map(y=>e.jsx(t.TableRow,{children:e.jsxs(t.TableCell,{align:"left",children:[e.jsx(t.Typography,{variant:"subtitle2",className:"flex-grow",children:y.name}),e.jsxs(t.Typography,{variant:"caption",className:"flex-grow",children:["This view is defined in code with key ",e.jsx("code",{children:y.key})]})]})},y.key))]})})})}),S===0&&e.jsx(t.Alert,{action:e.jsx(t.Button,{variant:"text",size:"small",href:"https://firecms.co/docs/customization_quickstart",component:"a",rel:"noopener noreferrer",target:"_blank",children:"More info"}),children:"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"}}),p&&e.jsx(f.DeleteConfirmationDialog,{open:!!p,onAccept:()=>{const y={id:p,parentCollectionIds:[...n??[],r.id]};console.debug("Deleting subcollection",y),a.deleteCollection(y),h(void 0)},onCancel:()=>h(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"]})}),d&&e.jsx(f.DeleteConfirmationDialog,{open:!!d,onAccept:()=>{T("entityViews",C.entityViews?.filter(y=>y!==d)),u(void 0)},onCancel:()=>u(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(dr,{open:!!m,configController:a,parentCollection:r,collectionInference:l,parentCollectionIds:[...n??[],C.id],isNewCollection:!1,...m,getUser:s,handleClose:()=>{w(void 0)}}),e.jsx(Rr,{open:g,onClose:y=>{y&&T("entityViews",[...C.entityViews??[],y]),c(!1)}})]})}const ar={id:"products",path:"products",name:"Products",singularName:"Product",icon:"shopping_cart",description:"List of the products currently sold in your shop",properties:f.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"}})},lr={id:"blog",path:"blog",name:"Blog",singularName:"Blog entry",icon:"article",description:"A collection of blog entries",defaultSize:"l",properties:f.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"]}},nr={id:"users",path:"users",name:"Users",singularName:"User",description:"Registered users in the app/web",icon:"person",properties:f.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"}})},sr={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 rt({path:r,pathSuggestions:o,parentCollection:a,onContinue:l,existingCollectionPaths:s}){const[n,i]=b.useState(!1),[p,h]=b.useState();b.useEffect(()=>{o&&s&&(i(!0),o(r).then(m=>{const w=m.filter(C=>!(s??[]).find(T=>T.trim().toLowerCase()===C.trim().toLowerCase()));h(w)}).finally(()=>i(!1)))},[s,r,o]);const{values:g,setFieldValue:c,setValues:d,submitCount:u}=H();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"})}),a&&e.jsx(t.Chip,{colorScheme:"tealDarker",children:e.jsxs(t.Typography,{variant:"caption",children:["This is a subcollection of ",e.jsx("b",{children:a.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&&!p&&e.jsx(t.CircularProgress,{size:"small"}),p?.map((m,w)=>e.jsx(t.Chip,{colorScheme:"cyanLighter",onClick:()=>{c("name",f.unslugify(m)),c("id",m),c("path",m),c("properties",void 0),l()},size:"small",children:m},m)),!n&&(p??[])?.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(Te,{title:"Products",subtitle:"A collection of products with images, prices and stock",icon:e.jsx(t.Icon,{size:"small",iconKey:ar.icon}),onClick:()=>{d(ar),l()}}),e.jsx(Te,{title:"Users",subtitle:"A collection of users with emails, names and roles",icon:e.jsx(t.Icon,{size:"small",iconKey:nr.icon}),onClick:()=>{d(nr),l()}}),e.jsx(Te,{title:"Blog posts",subtitle:"A collection of blog posts with images, authors and complex content",icon:e.jsx(t.Icon,{size:"small",iconKey:lr.icon}),onClick:()=>{d(lr),l()}}),e.jsx(Te,{title:"Pages",subtitle:"A collection of pages with images, authors and complex content",icon:e.jsx(t.Icon,{size:"small",iconKey:sr.icon}),onClick:()=>{d(sr),l()}})]})]}),!a&&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(ae.ImportFileUpload,{onDataAdded:m=>l(m)})]}),e.jsx("div",{children:e.jsx(t.Button,{variant:"text",onClick:()=>l(),className:"my-2",children:"Continue from scratch"})})]})})}function Te({title:r,subtitle:o,icon:a,onClick:l}){return e.jsx(t.Tooltip,{title:o,children:e.jsxs(t.Card,{onClick:l,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:[a,e.jsx("div",{className:"flex flex-col items-start",children:e.jsx(t.Typography,{variant:"subtitle1",children:r})})]})})}function tt({importConfig:r,propertyConfigs:o,collectionEditable:a}){const{setFieldValue:l,setFieldTouched:s,values:n}=H(),[i,p]=b.useState(void 0),h=b.useRef(n.propertiesOrder?{"":n.propertiesOrder}:{}),g=i?i.id:void 0,c=i||void 0,d=({id:m,property:w,previousId:C,namespace:T})=>{const k=m?Q(m,T):void 0,P=k?ee(k):void 0,N=y=>y?h.current[y]??E(n,te(y)):h.current[""],S=(y,x)=>{const B=te(x);l(B,y,!1),h.current[x??""]=y};if(C&&C!==m){const y=Q(C,T),x=ee(y),$=N(T).map(L=>L===C?m:L).filter(L=>L!==void 0);S($,T);const q={...r.headersMapping};Object.keys(q).forEach(L=>{q[L]===C&&(q[L]=m??"")}),r.setHeadersMapping(q),l(x,void 0,!1),s(x,!1,!1)}P&&(l(P,w,!1),s(P,!0,!1))},u=async({id:m,importKey:w,property:C,namespace:T})=>{const k=m?Q(m,T):void 0,P=k?ee(k):void 0,N=r.importData.map(y=>E(y,w)),S={...Ee.buildPropertyFromData(N,C,ae.getInferenceType),editable:!0};P&&(S?l(P,S,!1):l(P,C,!1),s(P,!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(ae.DataNewPropertiesMapping,{headersMapping:r.headersMapping,idColumn:r.idColumn,originProperties:r.originProperties,destinationProperties:n.properties,onIdPropertyChanged:m=>r.setIdColumn(m),buildPropertyView:({property:m,propertyKey:w,importKey:C})=>e.jsx(ae.ImportNewPropertyFieldPreview,{property:m,propertyKey:w,onPropertyNameChanged:(T,k)=>l(`properties.${T}.name`,k,!1),onEditClick:()=>{!w||!m||p({...m,id:w,editable:!0})},propertyTypeView:e.jsx(ot,{property:m,disabled:!1,onPropertyChanged:T=>u({...T,importKey:C}),propertyKey:w,propertyConfigs:o})})})]}),e.jsx(he,{open:i!==void 0,propertyKey:g,property:c,inArray:!1,autoUpdateId:!1,onPropertyChanged:d,allowDataInference:!1,collectionEditable:a,onOkClicked:()=>{p(void 0)},onCancel:()=>{p(void 0)},autoOpenTypeSelect:!1,existingProperty:!1,propertyConfigs:o}),e.jsx("div",{style:{height:"52px"}})]})}function ot({property:r,onPropertyChanged:o,propertyKey:a,propertyConfigs:l,disabled:s}){const n=r?f.getFieldId(r):null,i=r?f.getFieldConfig(r,l):null,[p,h]=b.useState(!1);return e.jsx(t.Tooltip,{title:r&&i?`${i?.name} - ${r.dataType}`:void 0,open:p?!1:void 0,children:e.jsx(t.Select,{open:p,onOpenChange:h,invisible:!0,className:"w-full",disabled:s,error:!i,value:n??"",placeholder:"Select a property widget",position:"item-aligned",renderValue:g=>i?e.jsx(f.PropertyConfigBadge,{propertyConfig:i}):null,onValueChange:g=>{const c=Re(r,g,l);a&&o({id:a,property:c,previousId:a,namespace:void 0})},children:Object.entries(rr).map(([g,c])=>e.jsx(er,{value:g,optionDisabled:!1,propertyConfig:c,existing:!1},g))})})}function at({importConfig:r,properties:o,propertiesOrder:a}){b.useEffect(()=>{const s=ae.getPropertiesMapping(r.originProperties,o),n=r.importData.map(i=>ae.convertDataToEntity(i,r.idColumn,r.headersMapping,o,s,"TEMP_PATH"));r.setEntities(n)},[]);const l=f.useSelectionController();return e.jsx(f.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:l,displayedColumnIds:a.map(s=>({key:s,disabled:!1})),properties:o})}function ir(r,o=""){const a=Object.keys(r).reduce((n,i)=>{const p=r[i],h=f.slugify(i),g=o?`${o}.${h}`:h;if(p.dataType==="map"&&p.properties){const u=ir(p.properties,g);return{headersMapping:{...n.headersMapping,[i]:g},properties:{...n.properties,[h]:{...p,properties:u.properties,propertiesOrder:Object.keys(u.properties)}}}}const c={...n.properties,[h]:p};return{headersMapping:{...n.headersMapping,[i]:g},properties:c}},{headersMapping:{},properties:{}}),l=Object.keys(a.headersMapping)?.[0];let s;return(l?.includes("id")||l?.includes("key"))&&(s=l),{...a,idColumn:s}}function dr(r){const o=r.open,[a,l]=ce.useState(!1),[s,n]=ce.useState(!1),i=b.useCallback(()=>{a?n(!0):r.handleClose(void 0)},[a,r.handleClose]);return b.useEffect(()=>{o||(l(!1),n(!1))},[o]),e.jsxs(t.Dialog,{open:o,fullWidth:!0,fullHeight:!0,scrollable:!1,maxWidth:"7xl",onOpenChange:p=>p?void 0:i(),children:[o&&e.jsx(lt,{...r,handleCancel:i,setFormDirty:l}),e.jsx(Xr,{open:s,handleOk:()=>r.handleClose(void 0),handleCancel:()=>n(!1),body:"There are unsaved changes in this collection"})]})}function lt(r){const{propertyConfigs:o}=f.useCustomizationController(),a=f.useNavigationController(),l=f.useAuthController(),{topLevelNavigation:s,collections:n}=a,i=r.initialValues,p=!i?.path&&(r.parentCollectionIds??[]).length===0,h=(r.parentCollection?r.parentCollection.subcollections:n)??[],g=h.map(P=>P.path.trim().toLowerCase()),c=h.map(P=>P.id?.trim().toLowerCase()).filter(Boolean),[d,u]=ce.useState(),[m,w]=ce.useState(!1);if(b.useEffect(()=>{try{a.initialised&&(r.editedCollectionId?u(a.getCollectionFromPaths([...r.parentCollectionIds??[],r.editedCollectionId])):u(void 0),w(!0))}catch(P){console.error(P)}},[a.getCollectionFromPaths,r.editedCollectionId,r.parentCollectionIds,a.initialised]),!s)throw Error("Internal: Navigation not ready in collection editor");const{groups:C}=s,T=d?{...d,id:d.id??d.path??f.randomString(16)}:void 0,k=T?st(T,o):{id:i?.path??f.randomString(16),path:i?.path??"",name:i?.name??"",group:i?.group??"",properties:{},propertiesOrder:[],icon:t.coolIconKeys[Math.floor(Math.random()*t.coolIconKeys.length)],ownerId:l.user?.uid??""};return m?!r.isNewCollection&&(!a.initialised||!m)?e.jsx(f.CircularProgressCenter,{}):e.jsx(nt,{...r,initialValues:k,existingPaths:g,existingIds:c,includeTemplates:p,collection:d,setCollection:u,groups:C,propertyConfigs:o}):e.jsx(f.CircularProgressCenter,{})}function nt({isNewCollection:r,configController:o,editedCollectionId:a,parentCollectionIds:l,fullPath:s,collectionInference:n,handleClose:i,reservedGroups:p,extraView:h,handleCancel:g,setFormDirty:c,pathSuggestions:d,getUser:u,parentCollection:m,getData:w,existingPaths:C,existingIds:T,includeTemplates:k,collection:P,setCollection:N,initialValues:S,propertyConfigs:y,groups:x}){const B=ae.useImportConfig(),$=f.useNavigationController(),q=f.useSnackbarController(),L=b.useRef({}),F=r?k?"welcome":"details":"properties",[v,V]=b.useState(F),[_,O]=ce.useState(),z=I=>{const A=I.id||I.path;return o.saveCollection({id:A,collectionData:I,previousId:a,parentCollectionIds:l}).then(()=>(O(void 0),!0)).catch(M=>(O(M),console.error(M),q.open({type:"error",message:"Error persisting collection: "+(M.message??"Details in the console")}),!1))},U=b.useCallback(()=>{v==="details"?B.inUse?V("import_data_saving"):V(h?"extra_view":"properties"):V(v==="welcome"?"details":v==="import_data_mapping"?"import_data_preview":v==="import_data_preview"?"details":v==="extra_view"?"properties":"details")},[v,B.inUse,h]),K=b.useCallback(I=>{if(n)return n?.(I.path,I.collectionGroup??!1,l??[])},[n,l]),X=b.useCallback(async I=>{try{if(!K)return N(I),Promise.resolve(I);V("loading");const A=await K?.(I);if(!A)return N(I),Promise.resolve(I);const M={...I??{}};return Object.keys(A.properties??{}).length>0&&(M.properties=A.properties,M.propertiesOrder=A.propertiesOrder),M.propertiesOrder?(N(M),console.debug("Inferred collection",{newCollection:I??{},values:M}),M):(M.propertiesOrder=Object.keys(M.properties),M)}catch(A){return console.error(A),q.open({type:"error",message:"Error inferring collection: "+(A.message??"Details in the console")}),I}},[l,K]),re=_e({initialValues:S,onSubmit:(I,A)=>{console.log("Submitting collection",I);try{if(!r){z(I).then(()=>{A.resetForm({values:S}),i(I)});return}v==="welcome"?(U(),A.resetForm({values:I})):v==="details"?h||B.inUse?(A.resetForm({values:I}),U()):r?X(I).then(M=>{A.resetForm({values:M??I,touched:{path:!0,name:!0}})}).finally(()=>{U()}):(A.resetForm({values:I}),U()):v==="extra_view"?(U(),A.resetForm({values:I})):v==="import_data_mapping"||v==="import_data_preview"?U():v==="properties"?z(I).then(()=>{A.resetForm({values:S}),U(),i(I)}):(U(),A.resetForm({values:I}))}catch(M){q.open({type:"error",message:"Error persisting collection: "+(M.message??"Details in the console")}),console.error(M),A.resetForm({values:I})}},validation:I=>{let A={};const M=(v==="properties"||v==="subcollections"||v==="details")&&br;if(M)try{M.validateSync(I,{abortEarly:!1})}catch(Z){Z.inner.forEach(ge=>{A[ge.path]=ge.message})}if(v==="properties"&&(A={...A,...L.current}),v==="details"){const Z=pr(I.path,r,C,I.id);Z&&(A.path=Z);const ge=it(I.id,r,C,T);ge&&(A.id=ge)}return A}}),{values:J,setFieldValue:se,isSubmitting:fe,dirty:we,submitCount:ze}=re,ie=J.path??a,xe=s?.includes("/")?s?.split("/").slice(0,-1).join("/")+"/"+ie:ie,ke=pr(ie,r,C,J.id),Fe=!ke&&l?$.convertIdsToPaths(l):void 0,Ie=ke?void 0:$.resolveAliasesFrom(xe),me=Ie&&w?()=>w(Ie,Fe??[]):void 0;b.useEffect(()=>{c(we)},[we]);function Se(I){B.setInUse(!0),Ee.buildEntityPropertiesFromData(I,ae.getInferenceType).then(A=>{const M=ir(A);se("properties",M.properties),se("propertiesOrder",Object.keys(M.properties)),B.setIdColumn(M.idColumn),B.setImportData(I),B.setHeadersMapping(M.headersMapping),B.setOriginProperties(M.properties)})}const Ue=!!J.name&&!!J.id,Le=()=>{const I={...J.properties};B.idColumn&&delete I[B.idColumn],se("properties",I),U()},Y=P?.editable===void 0||P?.editable===!0||r;return e.jsx(t.DialogContent,{fullHeight:!0,children:e.jsx(Be,{value:re,children:e.jsxs(e.Fragment,{children:[!r&&e.jsxs(t.Tabs,{value:v,className:t.cn(t.defaultBorderMixin,"justify-end bg-gray-50 dark:bg-gray-950 border-b"),onValueChange:I=>V(I),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("form",{noValidate:!0,onSubmit:re.submitForm,className:t.cn(r?"h-full":"h-[calc(100%-48px)]","flex-grow flex flex-col relative"),children:[v==="loading"&&e.jsx(f.CircularProgressCenter,{}),v==="extra_view"&&ie&&h?.View&&e.jsx(h.View,{path:ie}),v==="welcome"&&e.jsx(rt,{path:ie,onContinue:I=>{I?(Se(I),V("import_data_mapping")):V("details")},existingCollectionPaths:C,parentCollection:m,pathSuggestions:d}),v==="import_data_mapping"&&B&&e.jsx(tt,{importConfig:B,collectionEditable:Y,propertyConfigs:y}),v==="import_data_preview"&&B&&e.jsx(at,{importConfig:B,properties:J.properties,propertiesOrder:J.propertiesOrder}),v==="import_data_saving"&&B&&e.jsx(ae.ImportSaveInProgress,{importConfig:B,collection:J,onImportSuccess:I=>{i(I),q.open({type:"info",message:"Data imported successfully"})}}),v==="details"&&e.jsx(wr,{existingPaths:C,existingIds:T,groups:x,parentCollectionIds:l,parentCollection:m,isNewCollection:r}),v==="subcollections"&&P&&e.jsx(et,{parentCollection:m,configController:o,getUser:u,collectionInference:n,parentCollectionIds:l,collection:P}),v==="properties"&&e.jsx(Qr,{showErrors:ze>0,isNewCollection:r,reservedGroups:p,onPropertyError:(I,A,M)=>{console.debug("!!!onPropertyError",{propertyKey:I,namespace:A,error:M});const Z=f.removeUndefined({...L.current,[De(I,A)]:f.removeUndefined(M,!0)},!0);console.debug("aa!!!onPropertyError",{current:Z}),L.current=Z,re.validate()},getUser:u,getData:me,doCollectionInference:K,propertyConfigs:y,collectionEditable:Y,extraIcon:h?.icon&&e.jsx(t.IconButton,{color:"primary",onClick:()=>V("extra_view"),children:h.icon})}),v!=="welcome"&&e.jsxs(t.DialogActions,{position:"absolute",children:[_&&e.jsx(f.ErrorView,{error:_}),r&&k&&v==="import_data_mapping"&&e.jsxs(t.Button,{variant:"text",type:"button",onClick:()=>(B.setInUse(!1),V("welcome")),children:[e.jsx(t.ArrowBackIcon,{}),"Back"]}),r&&k&&v==="import_data_preview"&&e.jsxs(t.Button,{variant:"text",type:"button",onClick:()=>{z(J),V("import_data_mapping")},children:[e.jsx(t.ArrowBackIcon,{}),"Back"]}),r&&k&&v==="details"&&e.jsxs(t.Button,{variant:"text",type:"button",onClick:()=>V("welcome"),children:[e.jsx(t.ArrowBackIcon,{}),"Back"]}),r&&v==="properties"&&e.jsxs(t.Button,{variant:"text",type:"button",onClick:()=>V("details"),children:[e.jsx(t.ArrowBackIcon,{}),"Back"]}),e.jsx(t.Button,{variant:"text",onClick:()=>{g()},children:"Cancel"}),r&&v==="import_data_mapping"&&e.jsx(t.Button,{variant:"filled",color:"primary",onClick:Le,children:"Next"}),r&&v==="import_data_preview"&&e.jsx(t.Button,{variant:"filled",color:"primary",onClick:()=>{U()},children:"Next"}),r&&(v==="details"||v==="properties")&&e.jsxs(t.LoadingButton,{variant:"filled",color:"primary",type:"submit",loading:fe,disabled:fe||v==="details"&&!Ue,startIcon:v==="properties"?e.jsx(t.DoneIcon,{}):void 0,children:[v==="details"&&"Next",v==="properties"&&"Create collection"]}),!r&&e.jsx(t.LoadingButton,{variant:"filled",color:"primary",type:"submit",loading:fe,children:"Update collection"})]})]})]})})})}function st(r,o){const{properties:a,...l}=r,s={};return Object.keys(a).forEach(n=>{s[n]=cr(a[n],o)}),{...l,properties:s}}function cr(r,o){let a=r;if(o&&typeof a=="object"&&a.propertyConfig){const l=o[a.propertyConfig];if(l&&f.isPropertyBuilder(l.property))a=l.property;else if(l&&(a=f.mergeDeep(l.property,a)),!f.isPropertyBuilder(a)&&a.dataType==="map"&&a.properties){const s={};Object.keys(a.properties).forEach(n=>{s[n]=cr(a.properties[n],o)}),a={...a,properties:s}}}return a}const pr=(r,o,a,l)=>{let s;return r||(s="You must specify a path in the database for this collection"),o&&a?.includes(r.trim().toLowerCase())&&!l&&(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"),f.removeInitialAndTrailingSlashes(r).split("/").length%2===0&&(s=`Collection paths must have an odd number of segments: ${r}`),s},it=(r,o,a,l)=>{if(!r)return;let s;return o&&a?.includes(r.trim().toLowerCase())&&(s="There is already a collection that uses this value as a path"),o&&l?.includes(r.trim().toLowerCase())&&(s="There is already a collection which uses this id"),s},hr=b.createContext({}),fr=b.createContext({}),dt=b.memo(function({children:o,collectionConfigController:a,configPermissions:l,reservedGroups:s,collectionInference:n,extraView:i,pathSuggestions:p,getUser:h,getData:g,onAnalyticsEvent:c}){const d=f.useNavigationController(),u=mr.useNavigate(),m=f.useSnackbarController(),{propertyConfigs:w}=f.useCustomizationController(),{collections:C}=d,T=C.map(v=>v.path.trim().toLowerCase()),[k,P]=b.useState();b.useEffect(()=>{p&&p().then(v=>{P(v.filter(V=>!T.includes(V.trim().toLowerCase())))})},[p]);const[N,S]=b.useState(),[y,x]=b.useState(),B=b.useCallback(()=>({createCollections:!0,editCollections:!0,deleteCollections:!0}),[]),$=b.useCallback(({id:v,fullPath:V,parentCollectionIds:_,parentCollection:O})=>{console.debug("Edit collection",v,V,_,O),c?.("edit_collection",{id:v,fullPath:V}),S({editedCollectionId:v,fullPath:V,parentCollectionIds:_,isNewCollection:!1,parentCollection:O,redirect:!1})},[]),q=b.useCallback(({propertyKey:v,property:V,editedCollectionId:_,currentPropertiesOrder:O,parentCollectionIds:z,collection:U})=>{console.debug("edit property",v,V,_,O,z,U),c?.("edit_property",{propertyKey:v,editedCollectionId:_});const K=v&&v.includes(".")?v.substring(0,v.lastIndexOf(".")):void 0,X=v&&v.includes(".")?v.substring(v.lastIndexOf(".")+1):v;x({propertyKey:X,property:V,namespace:K,currentPropertiesOrder:O,editedCollectionId:_,parentCollectionIds:z,collectionEditable:U?.editable??!1})},[]),L=b.useCallback(({parentCollectionIds:v,parentCollection:V,initialValues:_,redirect:O,sourceClick:z})=>{console.debug("Create collection",{parentCollectionIds:v,parentCollection:V,initialValues:_,redirect:O,sourceClick:z}),c?.("create_collection",{parentCollectionIds:v,parentCollection:V,initialValues:_,redirect:O,sourceClick:z}),S({isNewCollection:!0,parentCollectionIds:v,parentCollection:V,initialValues:_,redirect:O})},[]),F=p?v=>!v&&k?Promise.resolve(k):p?.(v):void 0;return e.jsx(hr.Provider,{value:a,children:e.jsxs(fr.Provider,{value:{editCollection:$,createCollection:L,editProperty:q,configPermissions:l??B,rootPathSuggestions:k},children:[o,e.jsx(dr,{open:!!N,configController:a,isNewCollection:!1,collectionInference:n,...N,getData:g,reservedGroups:s,extraView:i,pathSuggestions:F,getUser:h,handleClose:v=>{if(N?.redirect&&v&&N?.isNewCollection&&!N.parentCollectionIds.length){const V=d.buildUrlCollectionPath(v.id??v.path);u(V)}S(void 0)}}),e.jsx(he,{open:!!y,includeIdAndName:!0,existingProperty:!!y?.propertyKey,autoUpdateId:y?!y?.propertyKey:!1,autoOpenTypeSelect:y?!y?.propertyKey:!1,inArray:!1,collectionEditable:y?.collectionEditable??!1,getData:g&&y?.editedCollectionId?()=>{console.debug("get data for property",y?.editedCollectionId);const v=d.resolveAliasesFrom(y.editedCollectionId);return g(v,[])}:void 0,onPropertyChanged:({id:v,property:V})=>{if(!y||!v)return;const _=!y.propertyKey;return a.saveProperty({path:y?.editedCollectionId,property:V,propertyKey:v,newPropertiesOrder:_&&y.currentPropertiesOrder?[...y.currentPropertiesOrder,v]:void 0,namespace:y.namespace,parentCollectionIds:y.parentCollectionIds}).catch(O=>(console.error(O),m.open({type:"error",message:"Error persisting property: "+(O.message??"Details in the console")}),!1))},onPropertyChangedImmediate:!1,onDelete:()=>{if(!y?.propertyKey)return;const v=y?.currentPropertiesOrder?.filter(V=>V!==y?.propertyKey);return a.deleteProperty({path:y?.editedCollectionId,propertyKey:y?.propertyKey,namespace:y?.namespace,newPropertiesOrder:v,parentCollectionIds:y?.parentCollectionIds}).then(()=>{x(void 0)}).catch(V=>(console.error(V),m.open({type:"error",message:"Error deleting property: "+(V.message??"Details in the console")}),!1))},onError:()=>{},onOkClicked:()=>{x(void 0)},onCancel:()=>{x(void 0)},initialErrors:{},forceShowErrors:!1,existingPropertyKeys:[],allowDataInference:!0,propertyConfigs:w,property:y?.property,propertyKey:y?.propertyKey})]})})},oe),ne=()=>b.useContext(fr),Me=()=>b.useContext(hr);function ct({path:r,parentCollectionIds:o,collection:a,tableController:l}){const s=f.useAuthController(),n=f.useNavigationController(),i=ne(),p=Me(),h=f.useSnackbarController(),g=n.getCollectionFromIds(o),c=i.configPermissions?i.configPermissions({user:s.user,collection:a}).editCollections:!0;let d=null;(!oe(Ne(l.filterValues),Ne(a.initialFilter))||!oe(Ne(l.sortBy),Ne(a.initialSort)))&&(d=e.jsxs(e.Fragment,{children:[(a.initialFilter||a.initialSort)&&e.jsx(t.Tooltip,{title:"Reset to default filter and sort",children:e.jsx(t.Button,{color:"primary",size:"small",variant:"text",onClick:()=>{l.clearFilter?.(),a?.initialFilter&&l.setFilterValues?.(a?.initialFilter),a?.initialSort&&l.setSortBy?.(a?.initialSort)},children:e.jsx(t.UndoIcon,{})})}),e.jsx(t.Tooltip,{title:l.sortBy||l.filterValues?"Save default filter and sort":"Clear default filter and sort",children:e.jsx(t.Button,{color:"primary",size:"small",variant:"outlined",onClick:()=>p?.saveCollection({id:a.id,parentCollectionIds:o,collectionData:f.mergeDeep(a,{initialFilter:l.filterValues??null,initialSort:l.sortBy??null})}).then(()=>{h.open({type:"success",message:"Default config saved"})}),children:e.jsx(t.SaveIcon,{})})})]}));const u=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?()=>i?.editCollection({id:a.id,fullPath:r,parentCollectionIds:o,parentCollection:g}):void 0,children:e.jsx(t.SettingsIcon,{})})});return e.jsxs(e.Fragment,{children:[c&&d,u]})}function Ne(r){return r&&Object.keys(r).length===0?r:r??null}function pt({path:r,collection:o}){const a=f.useSnackbarController(),l=f.useAuthController(),s=Me(),n=ne(),i=n.configPermissions({user:l.user,collection:o}),p=b.useCallback(()=>{n?.editCollection({id:o.id,parentCollectionIds:[]})},[n,r]),[h,g]=b.useState(!1),c=b.useCallback(()=>{s?.deleteCollection({id:o.id}).then(()=>{g(!1),a.open({message:"Collection deleted",type:"success"})})},[r,s]);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[i.deleteCollections&&e.jsx(t.Menu,{trigger:e.jsx(t.IconButton,{children:e.jsx(t.MoreVertIcon,{size:"small"})}),children:e.jsxs(t.MenuItem,{onClick:d=>{d.preventDefault(),d.stopPropagation(),g(!0)},children:[e.jsx(t.DeleteIcon,{}),"Delete"]})}),i.editCollections&&e.jsx(t.IconButton,{onClick:d=>{p()},children:e.jsx(t.SettingsIcon,{size:"small"})})]}),e.jsx(f.DeleteConfirmationDialog,{open:h,onAccept:c,onCancel:()=>g(!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 ht({group:r,context:o}){if(!o.navigation.topLevelNavigation)throw Error("Navigation not ready in FireCMSHomePage");const a=f.useAuthController(),l=ne(),s=l.configPermissions?l.configPermissions({user:a.user}).createCollections:!0;return e.jsx(t.Card,{className:t.cn("h-full p-4 min-h-[124px]"),onClick:l&&s?()=>l.createCollection({initialValues:r?{group:r}:void 0,parentCollectionIds:[],redirect:!0,sourceClick:"new_collection_card"}):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 ft(){const r=f.useAuthController(),o=f.useNavigationController(),a=ne(),l=a.configPermissions?a.configPermissions({user:r.user}).createCollections:!0,s=a.rootPathSuggestions??[],n=s.length>3||o.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(i=>e.jsx("div",{children:e.jsx(t.Chip,{icon:e.jsx(t.AddIcon,{size:"small"}),colorScheme:"cyanLighter",onClick:a&&l?()=>a.createCollection({initialValues:{path:i,name:f.unslugify(i)},parentCollectionIds:[],redirect:!0,sourceClick:"root_collection_suggestion"}):void 0,size:"small",children:i})},i))})]})})}function gt({propertyKey:r,onHover:o,property:a,fullPath:l,parentCollectionIds:s,collection:n}){const i=ne();return e.jsx(t.Tooltip,{title:"Edit",children:e.jsx(t.IconButton,{className:o?"bg-white dark:bg-gray-950":"hidden",onClick:()=>{i.editProperty({propertyKey:r,property:a,editedCollectionId:n.id,parentCollectionIds:s,collection:n})},size:"small",children:e.jsx(t.SettingsIcon,{size:"small"})})})}function ut({fullPath:r,parentCollectionIds:o,collection:a}){const l=f.useAuthController(),s=ne(),n=s.configPermissions?s.configPermissions({user:l.user,collection:a}).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({editedCollectionId:a.id,parentCollectionIds:o,currentPropertiesOrder:f.getDefaultPropertiesOrder(a),collection:a})},children:e.jsx(t.AddIcon,{color:"inherit"})})})}function yt(){const r=ne();return e.jsxs(t.Button,{className:"min-w-fit",variant:"outlined",onClick:()=>r.createCollection({parentCollectionIds:[],redirect:!0,sourceClick:"new_collection_button"}),children:[e.jsx(t.AddIcon,{}),"New collection"]})}function vt({collectionConfigController:r,modifyCollection:o,configPermissions:a,reservedGroups:l,extraView:s,pathSuggestions:n,getUser:i,collectionInference:p,getData:h,onAnalyticsEvent:g}){const c=d=>{const u=C=>{f.makePropertiesEditable(C.properties),C.subcollections?.forEach(u)},m=r.collections??[];m.forEach(u),console.debug("Collections specified in code:",d),console.debug("Collections stored in the backend",m);const w=f.joinCollectionLists(d,m,[],o);return console.debug("Collections after joining:",w),w};return{name:"Collection Editor",loading:r.loading,collections:{injectCollections:c,CollectionActions:ct},provider:{Component:dt,props:{collectionConfigController:r,configPermissions:a,collectionInference:p,reservedGroups:l,extraView:s,pathSuggestions:n,getUser:i,getData:h,onAnalyticsEvent:g}},homePage:{additionalActions:e.jsx(yt,{}),additionalChildrenEnd:e.jsx(ft,{}),CollectionActions:pt,AdditionalCards:ht},collectionView:{HeaderAction:gt,AddColumnComponent:ut}}}function mt({path:r}){const o=f.useNavigationController(),a=bt(r),l=o.getParentCollectionIds(r),s=ne();return e.jsxs("div",{className:"p-1 flex flex-col items-center",children:[e.jsx(f.ErrorView,{error:"No collection for path: "+a}),e.jsx(t.Button,{className:"mx-2",variant:"outlined",size:"small",onClick:()=>{s.createCollection({initialValues:{path:a,name:f.unslugify(a)},parentCollectionIds:l,redirect:!1,sourceClick:"missing_reference"})},children:"Create"})]})}function bt(r){const o=r.split("/");return o[o.length-1]}j.MissingReferenceWidget=mt,j.editableProperty=ye,j.getFullId=Q,j.getFullIdPath=De,j.idToPropertiesPath=ee,j.namespaceToPropertiesOrderPath=te,j.namespaceToPropertiesPath=Ke,j.removeNonEditableProperties=Je,j.useCollectionEditorController=ne,j.useCollectionEditorPlugin=vt,j.useCollectionsConfigController=Me,Object.defineProperty(j,Symbol.toStringTag,{value:"Module"})});
4
4
  //# sourceMappingURL=index.umd.js.map