@firecms/collection_editor 3.0.0-canary.2 → 3.0.0-canary.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.es.js +390 -397
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +2 -2
- package/dist/index.umd.js.map +1 -1
- package/dist/types/persisted_collection.d.ts +1 -1
- package/dist/ui/collection_editor/CollectionEditorDialog.d.ts +1 -1
- package/dist/ui/collection_editor/utils/supported_fields.d.ts +2 -2
- package/package.json +18 -18
- package/src/ConfigControllerProvider.tsx +1 -1
- package/src/types/persisted_collection.ts +1 -1
- package/src/ui/MissingReferenceWidget.tsx +2 -1
- package/src/ui/NewCollectionButton.tsx +12 -10
- package/src/ui/collection_editor/CollectionDetailsForm.tsx +17 -18
- package/src/ui/collection_editor/CollectionEditorDialog.tsx +13 -9
- package/src/ui/collection_editor/CollectionEditorWelcomeView.tsx +1 -1
- package/src/ui/collection_editor/CollectionPropertiesEditorForm.tsx +1 -1
- package/src/ui/collection_editor/EnumForm.tsx +3 -4
- package/src/ui/collection_editor/PropertyEditView.tsx +4 -4
- package/src/ui/collection_editor/import/CollectionEditorImportMapping.tsx +1 -1
- package/src/ui/collection_editor/properties/CommonPropertyFields.tsx +7 -8
- package/src/ui/collection_editor/properties/DateTimePropertyField.tsx +7 -8
- package/src/ui/collection_editor/properties/MapPropertyField.tsx +3 -4
- package/src/ui/collection_editor/properties/ReferencePropertyField.tsx +3 -4
- package/src/ui/collection_editor/properties/validation/StringPropertyValidation.tsx +3 -4
- package/src/ui/collection_editor/utils/supported_fields.tsx +3 -3
- package/src/useCollectionEditorPlugin.tsx +2 -4
- package/dist/ui/collection_editor/properties/FieldHelperView.d.ts +0 -4
- package/src/ui/collection_editor/properties/FieldHelperView.tsx +0 -13
package/dist/index.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(U,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/formex"),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/formex","@firecms/schema_inference","@hello-pangea/dnd","json5","prism-react-renderer","@firecms/data_import_export","react-router"],e):(U=typeof globalThis<"u"?globalThis:U||self,e(U["FireCMS collection editor"]={},U.jsxRuntime,U.core,U.React,U.equal,U.ui,U.Yup,U.formex,U.schema_inference,U.dnd,U.JSON5,U.prismReactRenderer,U.data_import_export,U.reactRouter))})(this,function(U,e,f,C,te,t,ir,u,Oe,xe,dr,Me,ae,cr){"use strict";function ze(r){const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const o in r)if(o!=="default"){const l=Object.getOwnPropertyDescriptor(r,o);Object.defineProperty(a,o,l.get?l:{enumerable:!0,get:()=>r[o]})}}return a.default=r,Object.freeze(a)}const ue=ze(C),ve=ze(ir),pr=ve.object().shape({id:ve.string().required("Required"),name:ve.string().required("Required"),path:ve.string().required("Required")});function G({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 hr({isNewCollection:r,reservedGroups:a,existingPaths:o,existingIds:l,groups:s,parentCollection:n}){const c=C.useRef(null),{values:p,setFieldValue:h,handleChange:y,touched:g,errors:d,setFieldTouched:v,isSubmitting:b,submitCount:F}=u.useFormex(),[T,N]=C.useState(!1),[S,P]=C.useState(!1),I=i=>{h("name",i),!u.getIn(g,"path")&&r&&i&&h("path",f.toSnakeCase(i)),!u.getIn(g,"id")&&r&&i&&h("id",f.toSnakeCase(i)),!u.getIn(g,"singularName")&&r&&i&&h("singularName",f.singular(i))};C.useEffect(()=>{d.id&&P(!0)},[d.id]);const w=e.jsx(f.IconForView,{collectionOrView:p}),m=s?.filter(i=>!a?.includes(i)),{inputFocused:k,autoCompleteOpen:V,setAutoCompleteOpen:z}=t.useAutoComplete({ref:c}),L=!!n;let A;typeof p.customId=="object"?A="code_defined":p.customId===!0?A="true":p.customId===!1?A="false":p.customId==="optional"&&(A="optional");const D=F>0;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:()=>N(!0),children:w})})]}),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:i=>I(i.target.value),label:"Name",required:!0,error:D&&!!d.name}),e.jsx(G,{error:g.name&&!!d.name,children:g.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 ",L?"":"sm:col-span-8"),children:[e.jsx(u.Field,{name:"path",as:t.DebouncedTextField,label:"Path",disabled:!r,required:!0,error:D&&!!d.path}),e.jsx(G,{error:g.path&&!!d.path,children:g.path&&d.path?d.path:L?"Relative path to the parent (no need to include the parent path)":"Path that this collection is stored in, in the database"})]}),!L&&e.jsxs("div",{className:"col-span-12 sm:col-span-4 relative",children:[e.jsx(t.TextField,{error:D&&!!d.group,disabled:b,value:p.group??"",autoComplete:"off",onChange:i=>h("group",i.target.value),name:"group",inputRef:c,label:"Group"}),e.jsx(t.Autocomplete,{open:V&&(m??[]).length>0,setOpen:z,children:m?.map((i,x)=>e.jsx(t.AutocompleteItem,{onClick:()=>{z(!1),h("group",i??null)},children:e.jsx("div",{className:"flex-grow",children:i})},x+"_"+i))}),e.jsx(G,{children:D&&d.group?d.group:"Group of the collection"})]}),e.jsx("div",{className:"col-span-12",children:e.jsx(t.ExpandablePanel,{expanded:S,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(u.Field,{name:"id",as:t.DebouncedTextField,disabled:!r,label:"Collection id",error:D&&!!d.id}),e.jsx(G,{error:g.id&&!!d.id,children:g.id&&d.id?d.id:"This id identifies this collection"})]}),e.jsxs("div",{className:"col-span-12",children:[e.jsx(t.TextField,{error:D&&!!d.singularName,name:"singularName","aria-describedby":"singularName-helper",onChange:i=>(v("singularName",!0),y(i)),value:p.singularName??"",label:"Singular name"}),e.jsx(G,{error:D&&!!d.singularName,children:D&&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:D&&!!d.description,name:"description",value:p.description??"",onChange:y,multiline:!0,rows:2,"aria-describedby":"description-helper-text",label:"Description"}),e.jsx(G,{error:D&&!!d.description,children:D&&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:y,value:p.defaultSize??"",renderValue:i=>i.toUpperCase(),children:["xs","s","m","l","xl"].map(i=>e.jsx(t.SelectItem,{value:i,children:i.toUpperCase()},`size-select-${i}`))})}),e.jsx("div",{className:"col-span-12",children:e.jsxs(t.Select,{name:"customId",label:"Data IDs generation",position:"item-aligned",disabled:A==="code_defined",onValueChange:i=>{if(i==="code_defined")throw new Error("This should not happen");i==="true"?h("customId",!0):i==="false"?h("customId",!1):i==="optional"&&h("customId","optional")},value:A??"",renderValue:i=>i==="code_defined"?"Code defined":i==="true"?"Users must define an ID":i==="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:i=>h("collectionGroup",i),value:p.collectionGroup??!1}),e.jsx(G,{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:i=>h("textSearchEnabled",i),value:p.textSearchEnabled??!1}),e.jsx(G,{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:T,onOpenChange:N,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:i=>{N(!1),h("icon",i)}})})})]})})}function X(r){return"properties."+r.replaceAll(".",".properties.")}function Ue(r){return r?"properties."+r.replaceAll(".",".properties.")+".properties":"properties"}function ee(r){return r?"properties."+r.replaceAll(".",".properties.")+".propertiesOrder":"propertiesOrder"}function Z(r,a){return a?`${a}.${r}`:r}function Ve(r,a){const o=a?`${a}.${r}`:r;return X(o)}function fr({enumValues:r,onValuesChanged:a,onError:o,updateIds:l,disabled:s,allowDataInference:n,getData:c}){const p=u.useCreateFormex({initialValues:{enumValues:r},validateOnChange:!0,validation:g=>{const d={};g.enumValues&&g.enumValues.forEach((b,F)=>{b?.label||(d.enumValues=d.enumValues??[],d.enumValues[F]=d.enumValues[F]??{},d.enumValues[F].label="You must specify a label for this enum value entry"),b?.id||(d.enumValues=d.enumValues??[],d.enumValues[F]=d.enumValues[F]??{},d.enumValues[F].id="You must specify an ID for this enum value entry")});const v=!!(d?.enumValues&&Object.keys(d?.enumValues).length>0);return o?.(v),d}}),{values:h,errors:y}=p;return C.useEffect(()=>{a&&a(h.enumValues)},[h.enumValues]),e.jsx(u.Formex,{value:p,children:e.jsx(gr,{enumValuesPath:"enumValues",values:h,errors:y,shouldUpdateId:l,disabled:s,allowDataInference:n,getData:c})})}function gr({values:r,errors:a,disabled:o,enumValuesPath:l,shouldUpdateId:s,allowDataInference:n,getData:c}){const{setFieldValue:p}=u.useFormex(),[h,y]=C.useState(),[g,d]=C.useState(),[v,b]=C.useState(!1),T=C.useRef(new Set).current,N=(P,I)=>{const w=h===I,m=a?.enumValues&&a?.enumValues[P];return e.jsx(ur,{index:P,disabled:o,enumValuesPath:l,autoFocus:w,entryError:m,shouldUpdateId:s||w,onDialogOpen:()=>d(P),inferredEntry:T.has(r.enumValues[P]?.id)},`${I}`)},S=async()=>{c&&(b(!0),c?.().then(P=>{if(!P)return;const I=P.flat(),w=Array.from(new Set(I)),m=r.enumValues,V=Oe.extractEnumFromValues(w).filter(z=>!m?.some(L=>L.id===z.id));V.forEach(z=>{T.add(z.id)}),p(l,[...V,...m],!0)}).catch(P=>{console.error(P)}).finally(()=>b(!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:v,disabled:o||v,variant:"text",size:"small",onClick:S,children:[v?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:o,size:"small",buildEntry:N,onInternalIdAdded:y,includeAddButton:!0,onValueChange:P=>p(l,P),newDefaultEntry:{id:"",label:""}}),e.jsx(yr,{index:g,open:g!==void 0,enumValuesPath:l,onClose:()=>d(void 0)})]})]})}const ur=C.memo(function({index:a,shouldUpdateId:o,enumValuesPath:l,autoFocus:s,onDialogOpen:n,disabled:c,inferredEntry:p,entryError:h}){const{values:y,handleChange:g,errors:d,setFieldValue:v,touched:b}=u.useFormex(),F=C.useRef(!u.getIn(y,`${l}[${a}].id`)),T=o||F.current,N=u.getIn(y,`${l}[${a}].id`),S=u.getIn(y,`${l}[${a}].label`),P=C.useRef(S);return C.useEffect(()=>{(P.current===N||!N)&&T&&v(`${l}[${a}].id`,S),P.current=S},[S]),e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex w-full align-center justify-center",children:[e.jsx(u.Field,{name:`${l}[${a}].label`,as:t.DebouncedTextField,className:"flex-grow",required:!0,disabled:c,size:"small",autoFocus:s,autoComplete:"off",endAdornment:p&&e.jsx(t.AutoAwesomeIcon,{size:"small"}),error:!!h?.label}),!c&&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(a,o){return a.index===o.index&&a.enumValuesPath===o.enumValuesPath&&a.shouldUpdateId===o.shouldUpdateId&&a.inferredEntry===o.inferredEntry&&te(a.entryError,o.entryError)&&a.autoFocus===o.autoFocus});function yr({index:r,open:a,onClose:o,enumValuesPath:l}){const{errors:s}=u.useFormex(),n=r!==void 0?u.getIn(s,`${l}[${r}].id`):void 0;return e.jsxs(t.Dialog,{maxWidth:"md","aria-labelledby":"enum-edit-dialog",open:a,onOpenChange:c=>c?void 0:o(),children:[e.jsx(t.DialogContent,{children:r!==void 0&&e.jsxs("div",{children:[e.jsx(u.Field,{name:`${l}[${r}].id`,as:t.DebouncedTextField,required:!0,label:"ID",size:"small",autoComplete:"off",error:!!n}),e.jsx(G,{error:!!n,children:n??"Value saved in the data source"})]})}),e.jsx(t.DialogActions,{children:e.jsx(t.Button,{autoFocus:!0,variant:"outlined",onClick:o,color:"primary",children:"Ok"})})]})}function Q({field:r,form:a,label:o,tooltip:l,disabled:s,size:n="small",allowIndeterminate:c}){const p=e.jsx(t.BooleanSwitchWithLabel,{label:o,size:n,position:"start",value:r.value,disabled:s,allowIndeterminate:c,onValueChange:h=>a.setFieldValue(r.name,h)});return l?e.jsx(t.Tooltip,{title:l,children:p}):p}function ie({disabled:r}){const{values:a,handleChange:o}=u.useFormex(),l="validation.required",s="validation.requiredMessage";return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"col-span-6",children:e.jsx(u.Field,{name:l,type:"checkbox",children:({field:c,form:p})=>e.jsx(Q,{disabled:r,label:"Required",tooltip:"You won't be able to save this entity if this value is not set",form:p,field:c})})}),e.jsx("div",{className:"col-span-6",children:e.jsx(u.Field,{name:"validation.unique",type:"checkbox",children:({field:c,form:p})=>e.jsx(Q,{disabled:r,label:"Unique",tooltip:"There cannot be multiple entities with the same value",form:p,field:c})})}),u.getIn(a,l)&&e.jsx("div",{className:"col-span-12",children:e.jsx(t.DebouncedTextField,{disabled:r,value:u.getIn(a,s),label:"Required message",name:s,size:"small",onChange:o})})]})}function he({length:r,lowercase:a,matches:o,max:l,min:s,trim:n,uppercase:c,disabled:p,showErrors:h}){const{values:y,handleChange:g,errors:d}=u.useFormex(),v="validation.length",b="validation.min",F="validation.max",T="validation.trim",N="validation.matches",S="validation.lowercase",P="validation.uppercase",I=u.getIn(d,N),w=u.getIn(y,N),m=typeof w=="string"?w:f.serializeRegExp(w);return e.jsxs("div",{className:"grid grid-cols-12 gap-2",children:[e.jsx(ie,{disabled:p}),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(u.Field,{name:S,type:"checkbox",children:({field:k,form:V})=>e.jsx(Q,{label:"Lowercase",disabled:p,form:V,field:k})})}),c&&e.jsx("div",{className:"col-span-4",children:e.jsx(u.Field,{name:P,type:"checkbox",children:({field:k,form:V})=>e.jsx(Q,{label:"Uppercase",disabled:p,form:V,field:k})})}),n&&e.jsx("div",{className:"col-span-4",children:e.jsx(u.Field,{name:T,type:"checkbox",children:({field:k,form:V})=>e.jsx(Q,{label:"Trim",disabled:p,form:V,field:k})})})]}),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:u.getIn(y,v),label:"Exact length",name:v,type:"number",size:"small",disabled:p,onChange:g})}),s&&e.jsx("div",{className:"col-span-4",children:e.jsx(t.DebouncedTextField,{value:u.getIn(y,b),label:"Min length",name:b,type:"number",size:"small",disabled:p,onChange:g})}),l&&e.jsx("div",{className:"col-span-4",children:e.jsx(t.DebouncedTextField,{value:u.getIn(y,F),label:"Max length",name:F,type:"number",size:"small",disabled:p,onChange:g})})]}),o&&e.jsxs("div",{className:"col-span-12",children:[e.jsx(u.Field,{name:N,as:t.DebouncedTextField,label:"Matches regex",size:"small",disabled:p,value:m,error:!!I}),e.jsx(G,{error:!!I,children:I?"Not a valid regexp":"e.g. /^\\d+$/ for digits only"})]})]})}function Ee({max:r=!0,min:a=!0,disabled:o}){const{values:l,handleChange:s}=u.useFormex(),n="validation.min",c="validation.max";return e.jsxs("div",{className:"grid grid-cols-12 gap-2",children:[e.jsx(ie,{disabled:o}),a&&e.jsx("div",{className:"col-span-6",children:e.jsx(t.DebouncedTextField,{value:u.getIn(l,n),disabled:o,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:u.getIn(l,c),disabled:o,label:"Max length",name:c,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 Le({multiselect:r,updateIds:a,disabled:o,showErrors:l,allowDataInference:s,getData:n}){const{values:c,setFieldError:p,setFieldValue:h}=u.useFormex(),y=f.useSnackbarController(),g=r?"of.enumValues":"enumValues",d=u.getIn(c,"defaultValue"),v=u.getIn(c,g),b=C.useMemo(()=>!v||typeof v=="boolean"?[]:f.resolveEnumValues(v)??[],[v]),F=T=>{if(c&&(h(g,T),!r)){const N=T.filter(S=>!!S?.id).map(S=>S.id);d&&!N.includes(d)&&(h("defaultValue",void 0),y.open({type:"warning",message:"Default value was cleared"}))}};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"col-span-12",children:e.jsx(fr,{enumValues:b,updateIds:a,disabled:o,allowDataInference:s,onError:T=>{p(g,T?"This enum property is missing some values":void 0)},getData:n?()=>n().then(T=>T.map(N=>c.id&&u.getIn(N,c.id)).filter(Boolean)):void 0,onValuesChanged:F})}),e.jsx("div",{className:"col-span-12",children:e.jsxs(le,{children:[!r&&e.jsx(he,{disabled:o,showErrors:l}),r&&e.jsx(Ee,{disabled:o})]})}),!r&&e.jsx("div",{className:"col-span-12",children:e.jsx(t.Select,{disabled:o,position:"item-aligned",onValueChange:T=>{h("defaultValue",T)},label:"Default value",value:d??"",children:b.filter(T=>!!T?.id).map(T=>e.jsx(t.SelectItem,{value:T.id?.toString(),children:T.label},T.id))})})]})}const me={"image/*":"Images","video/*":"Videos","audio/*":"Audio files","application/*":"Files (pdf, zip, csv, excel...)","text/*":"Text files"};function qe({multiple:r,existing:a,disabled:o}){const{values:l,setFieldValue:s}=u.useFormex(),n=r?"of.storage":"storage",c=`${n}.acceptedFiles`,p=`${n}.fileName`,h=`${n}.storagePath`,y=`${n}.storeUrl`,g=u.getIn(l,p)??"{rand}_{file}",d=u.getIn(l,h)??"/",v=u.getIn(l,c),b=Array.isArray(v)?v:void 0,F=!b||b.length===0,T=P=>{P?P.includes("all")||P.length>=Object.keys(me).length?s(c,void 0):F?s(c,Object.keys(me).filter(I=>!P.includes(I))):s(c,P):s(c,void 0)},N=typeof g=="function",S=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:o,name:c,value:b??[],onMultiValueChange:T,label:F?void 0:"Allowed file types",renderValues:P=>!P||P.length===0?"All file types allowed":P.map(I=>me[I]).filter(I=>!!I).join(", "),children:[e.jsxs(t.MultiSelectItem,{value:"all",className:"flex items-center gap-2",children:[e.jsx(t.Checkbox,{checked:!b}),"All"]},"all"),Object.entries(me).map(([P,I])=>e.jsxs(t.MultiSelectItem,{value:P,className:"flex items-center gap-2",children:[e.jsx(t.Checkbox,{checked:F||b.indexOf(P)>-1}),e.jsx("div",{className:"flex-grow",children:I}),e.jsx(t.Button,{size:"small",variant:"outlined",onClick:w=>(w.preventDefault(),w.stopPropagation(),s(c,[P])),children:"Only"})]},P))]})}),e.jsx("div",{className:"col-span-12",children:e.jsx(u.Field,{name:p,as:t.DebouncedTextField,label:"File name",size:"small",disabled:N||o,value:N?"-":g})}),e.jsxs("div",{className:"col-span-12",children:[e.jsx(u.Field,{name:h,as:t.DebouncedTextField,label:"Storage path",disabled:S||o,size:"small",value:S?"-":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(u.Field,{name:y,type:"checkbox",children:({field:P,form:I})=>e.jsx(Q,{label:"Save URL instead of storage path",disabled:a||o,form:I,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(ie,{disabled:o})}),r&&e.jsx("div",{className:"col-span-12",children:e.jsx(Ee,{disabled:o})})]})})]})}function fe(r){if(f.isPropertyBuilder(r)||f.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 $e(r){return Object.entries(r).filter(([a,o])=>fe(o)).map(([a,o])=>{const l=o;if(fe(l))return l.dataType==="map"&&l.properties?{[a]:{...l,properties:$e(l.properties)}}:{[a]:l}}).filter(a=>!!a).reduce((a,o)=>({...a,...o}),{})}function je({property:r,onClick:a,hasError:o,includeName:l,includeEditButton:s,selected:n}){const{propertyConfigs:c}=f.useCustomizationController(),p=f.getFieldConfig(r,c);fe(r);const h=o?"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 o&&console.log("PropertyFieldPreview",r),e.jsx(f.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(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,a?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 vr({name:r,selected:a,onClick:o,property:l}){const{propertyConfigs:s}=f.useCustomizationController(),n=!f.isPropertyBuilder(l)&&l?f.getFieldConfig(l,s):void 0;return e.jsxs("div",{onClick:o,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,o?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: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 be=C.memo(function({namespace:a,selectedPropertyKey:o,onPropertyClick:l,properties:s,propertiesOrder:n,additionalFields:c,errors:p,onPropertyMove:h,onPropertyRemove:y,className:g,inferredPropertyKeys:d,collectionEditable:v}){const b=n??Object.keys(s),F=C.useCallback(T=>{if(!T.destination)return;const N=T.source.index,S=T.destination.index,P=Array.from(b),[I]=P.splice(N,1);P.splice(S,0,I),h&&h(P,a)},[a,h,b]);return e.jsx(e.Fragment,{children:e.jsx(xe.DragDropContext,{onDragEnd:F,children:e.jsx(xe.Droppable,{droppableId:`droppable_${a}`,children:(T,N)=>e.jsxs("div",{...T.droppableProps,ref:T.innerRef,className:g,children:[b&&b.map((S,P)=>{const I=s[S],w=c?.find(m=>m.key===S);return!I&&!w?(console.warn(`Property ${S} not found in properties or additionalFields`),null):e.jsx(xe.Draggable,{draggableId:`array_field_${a}_${S}}`,index:P,children:(m,k)=>e.jsx(f.ErrorBoundary,{children:e.jsx(mr,{propertyKey:S,propertyOrBuilder:I,additionalField:w,provided:m,errors:p,namespace:a,inferredPropertyKeys:d,onPropertyMove:h,onPropertyRemove:y,onPropertyClick:k.isDragging?void 0:l,selectedPropertyKey:o,collectionEditable:v})})},`array_field_${a}_${S}}`)}).filter(Boolean),T.placeholder]})})})})},(r,a)=>{const o=a.selectedPropertyKey?.startsWith(a.namespace??""),l=r.selectedPropertyKey?.startsWith(r.namespace??"");return o||l?!1:te(r.properties,a.properties)&&r.propertiesOrder===a.propertiesOrder&&te(r.additionalFields,a.additionalFields)&&te(r.errors,a.errors)&&te(r.onPropertyClick,a.onPropertyClick)&&r.namespace===a.namespace&&r.collectionEditable===a.collectionEditable});function mr({propertyKey:r,namespace:a,propertyOrBuilder:o,additionalField:l,provided:s,selectedPropertyKey:n,errors:c,onPropertyClick:p,onPropertyMove:h,onPropertyRemove:y,inferredPropertyKeys:g,collectionEditable:d}){const v=g?.includes(a?`${a}.${r}`:r),b=Z(r,a),T=Ve(r,a)in c;let N;if(typeof o=="object"){const I=o;I.dataType==="map"&&I.properties&&(N=e.jsx(be,{selectedPropertyKey:n,namespace:b,properties:I.properties,propertiesOrder:I.propertiesOrder,errors:c,onPropertyClick:p,onPropertyMove:h,onPropertyRemove:y,collectionEditable:d}))}const S=n===b,P=o&&(d&&!f.isPropertyBuilder(o)||fe(o));return e.jsxs("div",{ref:s.innerRef,...s.draggableProps,...s.dragHandleProps,className:"relative -ml-8",children:[N&&e.jsx("div",{className:"absolute border-l "+t.defaultBorderMixin,style:{left:"32px",top:"64px",bottom:"16px"}}),!f.isPropertyBuilder(o)&&!l&&P?e.jsx(je,{property:o,onClick:p?()=>p(r,a):void 0,includeName:!0,selected:S,hasError:T}):e.jsx(vr,{name:r,property:o,onClick:p?()=>p(r,a):void 0,selected:S}),e.jsxs("div",{className:"absolute top-2 right-2 flex flex-row ",children:[v&&e.jsx(t.Tooltip,{title:"Inferred property",children:e.jsx(t.AutoAwesomeIcon,{size:"small",className:"p-2"})}),y&&e.jsx(t.Tooltip,{title:"Remove",children:e.jsx(t.IconButton,{size:"small",color:"inherit",onClick:()=>y(r,a),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"})})})]}),N&&e.jsx("div",{className:"ml-16",children:N})]})}function br({disabled:r,getData:a,allowDataInference:o,propertyConfigs:l,collectionEditable:s}){const{values:n,setFieldValue:c}=u.useFormex(),[p,h]=C.useState(!1),[y,g]=C.useState(),[d,v]=C.useState(),b=n.propertiesOrder??Object.keys(n.properties??{}),F=({id:w,property:m})=>{if(!w)throw Error();c("properties",{...n.properties??{},[w]:m},!1);const k=n.propertiesOrder??Object.keys(n.properties??{}),V=k.includes(w)?k:[...k,w];c("propertiesOrder",V,!1),h(!1)},T=C.useCallback((w,m)=>{const k=w?Z(w,m):void 0;if(!k)throw Error("collection editor miss config");const V=X(k),z=ee(m),L=u.getIn(n,z)??Object.keys(u.getIn(n,Ue(m)));c(V,void 0,!1),c(z,L.filter(A=>A!==w),!1),h(!1),g(void 0),v(void 0)},[c,n]),N=y?Z(y,d):void 0,S=N?u.getIn(n.properties,N.replaceAll(".",".properties.")):void 0,P=!b||b.length<1,I=C.useCallback((w,m)=>{c(ee(m),w,!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"}),e.jsxs(t.Button,{color:"primary",variant:"outlined",onClick:()=>h(!0),startIcon:e.jsx(t.AddIcon,{}),children:["Add property to ",n.name??"this group"]})]}),e.jsxs(t.Paper,{className:"p-2 pl-8",children:[e.jsx(be,{properties:n.properties??{},propertiesOrder:b,errors:{},collectionEditable:s,onPropertyClick:(w,m)=>{g(w),v(m),h(!0)},onPropertyMove:I}),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:w=>c("spreadChildren",w),value:n.spreadChildren??!1}),e.jsx(G,{children:"Set this flag to true if you want to display the children of this group as individual columns."})]}),e.jsx(de,{inArray:!1,forceShowErrors:!1,open:p,allowDataInference:o,collectionEditable:s,onCancel:()=>{h(!1),g(void 0),v(void 0)},onOkClicked:()=>{h(!1),g(void 0),v(void 0)},getData:a,onDelete:T,propertyKey:y,propertyNamespace:d,property:S,existingProperty:!!y,autoUpdateId:!y,autoOpenTypeSelect:!y,onPropertyChanged:F,existingPropertyKeys:y?void 0:b,propertyConfigs:l})]})}function Cr({showErrors:r,existing:a,disabled:o,getData:l,allowDataInference:s,propertyConfigs:n,collectionEditable:c}){const{values:p,handleChange:h,errors:y,setFieldValue:g,touched:d}=u.useFormex(),[v,b]=C.useState(!1),F=u.getIn(p,"of"),T=u.getIn(d,"of")&&u.getIn(y,"of"),N=({id:P,property:I,namespace:w})=>{console.log("onPropertyChanged",P,I,w),g("of",I)},S=F&&f.getFieldConfig(F,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(u.Field,{name:"of",value:F,children:({})=>e.jsxs(t.Paper,{className:"p-2 mt-4",children:[F&&e.jsx(je,{property:F,onClick:o?void 0:()=>b(!0),includeName:!1,includeEditButton:!0,selected:!1,hasError:!1}),!o&&!F&&e.jsxs(t.Button,{variant:"text",size:"large",color:T?"error":"primary",onClick:()=>b(!0),children:["Edit ",`${S?S.name:"repeat component"}`]}),e.jsx(de,{inArray:!0,open:v,existingProperty:a,getData:l,autoUpdateId:!a,autoOpenTypeSelect:!a,onOkClicked:()=>b(!1),allowDataInference:s,property:F,includeIdAndName:!1,onPropertyChanged:N,forceShowErrors:r,propertyConfigs:n,collectionEditable:c})]})})]}),e.jsx("div",{className:"col-span-12",children:e.jsx(le,{children:e.jsx(Ee,{disabled:o})})})]})}const Tr=C.forwardRef(function({showErrors:a,disabledId:o,disabled:l,autoUpdateId:s,isNewProperty:n},c){const{errors:p,values:h,setFieldValue:y,setFieldTouched:g,touched:d,validate:v}=u.useFormex(),b="name",F=a&&u.getIn(p,b),T="id",N=a&&u.getIn(p,T),S="description",P=a&&u.getIn(p,S);return e.jsxs("div",{className:"flex flex-col gap-2 col-span-12",children:[e.jsxs("div",{children:[e.jsx(u.Field,{name:b,inputRef:c,as:t.DebouncedTextField,value:h[b],onChange:I=>{const w=I.target.value;!u.getIn(d,T)&&s&&y(T,w?f.toSnakeCase(w):"",!1),y(b,w,!0),g(b,!0)},style:{fontSize:20},placeholder:"Field name",required:!0,disabled:l,error:!!F}),e.jsx(G,{error:!!F,children:F})]}),e.jsxs("div",{children:[e.jsx(u.Field,{name:T,as:t.DebouncedTextField,label:"ID",value:h[T],onChange:I=>{const w=I.target.value;!u.getIn(d,b)&&s&&y(b,w?f.unslugify(w):""),y(T,w,!0),g(T,!0)},disabled:o||l,required:!0,size:"small",error:!!N}),e.jsx(G,{error:!!N,children:N})]}),e.jsxs("div",{children:[e.jsx(u.Field,{name:S,as:t.DebouncedTextField,label:"Description",disabled:l,error:!!P}),e.jsx(G,{error:!!P,children:P})]})]})});function Pr({widgetId:r,disabled:a,showErrors:o}){const{values:l,setFieldValue:s}=u.useFormex();return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"col-span-12",children:e.jsxs(le,{children:[r==="text_field"&&e.jsx(he,{disabled:a,length:!0,lowercase:!0,matches:!0,max:!0,min:!0,trim:!0,uppercase:!0,showErrors:o}),r==="multiline"&&e.jsx(he,{disabled:a,length:!0,lowercase:!0,max:!0,min:!0,trim:!0,uppercase:!0,showErrors:o}),r==="markdown"&&e.jsx(he,{disabled:a,length:!0,lowercase:!0,max:!0,min:!0,trim:!0,uppercase:!0,showErrors:o}),r==="email"&&e.jsx(he,{disabled:a,max:!0,min:!0,trim:!0,showErrors:o})]})}),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:u.getIn(l,"defaultValue")??""})})]})}function Ir({disabled:r}){const{values:a}=u.useFormex(),o=u.getIn(a,"defaultValue");return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"col-span-12",children:e.jsx(le,{children:e.jsx(ie,{disabled:r})})}),e.jsx("div",{className:"col-span-12",children:e.jsx(u.Field,{name:"defaultValue",children:({field:l,form:s})=>e.jsx(Q,{label:o==null?"Default value not set":"Default value is "+o.toString(),disabled:r,allowIndeterminate:!0,field:l,form:s})})})]})}function Nr({disabled:r,getData:a,allowDataInference:o,propertyConfigs:l,collectionEditable:s}){const{values:n,setFieldValue:c}=u.useFormex(),[p,h]=C.useState(!1),[y,g]=C.useState(),[d,v]=C.useState(),b=({id:I,property:w})=>{if(!I)throw Error();c("oneOf.properties",{...n.oneOf?.properties??{},[I]:w},!1);const m=n.oneOf?.propertiesOrder??Object.keys(n.oneOf?.properties??{}),k=m.includes(I)?m:[...m,I];c("oneOf.propertiesOrder",k,!1),h(!1)},F=y?Z(y,d):void 0,T=F?u.getIn(n.oneOf?.properties,F.replaceAll(".",".properties.")):void 0,N=C.useCallback((I,w)=>{const m=I?Z(I,w):void 0;if(!m)throw Error("collection editor miss config");c(`oneOf.${X(m)}`,void 0,!1);const k=`oneOf.${ee(w)}`,V=u.getIn(n,k);c(k,V.filter(z=>z!==I),!1),h(!1),g(void 0),v(void 0)},[c,n]),S=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=C.useCallback((I,w)=>{c(`oneOf.${ee(w)}`,I,!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"}),S]}),e.jsxs(t.Paper,{className:"p-2 pl-8",children:[e.jsx(be,{properties:n.oneOf?.properties??{},propertiesOrder:n.oneOf?.propertiesOrder,errors:{},collectionEditable:s,onPropertyClick:r?void 0:(I,w)=>{g(I),v(w),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(de,{inArray:!1,forceShowErrors:!1,open:p,getData:a,allowDataInference:o,onCancel:()=>{h(!1),g(void 0),v(void 0)},onOkClicked:()=>{h(!1),g(void 0),v(void 0)},collectionEditable:s,onDelete:N,propertyKey:y,propertyNamespace:d,property:T,existingProperty:!!y,autoUpdateId:!y,autoOpenTypeSelect:!y,onPropertyChanged:b,existingPropertyKeys:y?void 0:n.oneOf?.propertiesOrder,propertyConfigs:l})]})}function wr({disabled:r}){const{values:a,handleChange:o}=u.useFormex(),l="validation.min",s="validation.max",n="validation.lessThan",c="validation.moreThan";return e.jsxs("div",{className:"grid grid-cols-12 gap-2",children:[e.jsx(ie,{disabled:r}),e.jsx("div",{className:"col-span-6",children:e.jsx(t.DebouncedTextField,{value:u.getIn(a,l),label:"Min value",name:l,type:"number",size:"small",disabled:r,onChange:o})}),e.jsx("div",{className:"col-span-6",children:e.jsx(t.DebouncedTextField,{value:u.getIn(a,s),label:"Max value",name:s,type:"number",size:"small",disabled:r,onChange:o})}),e.jsx("div",{className:"col-span-6",children:e.jsx(t.DebouncedTextField,{value:u.getIn(a,n),label:"Less than",name:n,type:"number",size:"small",disabled:r,onChange:o})}),e.jsx("div",{className:"col-span-6",children:e.jsx(t.DebouncedTextField,{value:u.getIn(a,c),label:"More than",name:c,type:"number",size:"small",disabled:r,onChange:o})}),e.jsx("div",{className:"col-span-4",children:e.jsx(u.Field,{name:"validation.positive",type:"checkbox",children:({field:g,form:d})=>e.jsx(Q,{label:"Positive value",disabled:r,form:d,field:g})})}),e.jsx("div",{className:"col-span-4",children:e.jsx(u.Field,{name:"validation.negative",type:"checkbox",children:({field:g,form:d})=>e.jsx(Q,{label:"Negative value",disabled:r,form:d,field:g})})}),e.jsx("div",{className:"col-span-4",children:e.jsx(u.Field,{name:"validation.integer",type:"checkbox",children:({field:g,form:d})=>e.jsx(Q,{label:"Integer value",disabled:r,form:d,field:g})})})]})}function Fr({disabled:r}){const{values:a,setFieldValue:o}=u.useFormex();return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"col-span-12",children:e.jsx(le,{children:e.jsx(wr,{disabled:r})})}),e.jsx("div",{className:"col-span-12",children:e.jsx(t.TextField,{name:"defaultValue",disabled:r,type:"number",onChange:l=>{o("defaultValue",l.target.value===""?void 0:parseFloat(l.target.value))},label:"Default value",value:u.getIn(a,"defaultValue")??""})})]})}function Ye({existing:r,multiple:a,disabled:o,showErrors:l}){const{values:s,handleChange:n,errors:c}=u.useFormex();if(!f.useNavigationController())return e.jsx("div",{className:"col-span-12",children:e.jsx(t.CircularProgress,{})});const h=a?"of.path":"path",y=u.getIn(s,h),g=l&&u.getIn(c,h);return e.jsx(e.Fragment,{children:e.jsx("div",{className:"col-span-12",children:e.jsx(u.Field,{name:h,pathPath:h,type:"select",disabled:r&&!!y||o,value:y,error:g,handleChange:n,as:kr})})})}function kr({disabled:r,pathPath:a,value:o,handleChange:l,error:s,...n}){const c=f.useNavigationController();if(!c)return e.jsx("div",{className:"col-span-12",children:e.jsx(t.CircularProgress,{})});const p=c?.collections??[],h=Array.from(new Set(Object.values(p).map(g=>g.group).filter(Boolean)).values()),y=p.filter(g=>!g.group);return e.jsxs(e.Fragment,{children:[e.jsxs(t.Select,{error:!!s,disabled:r,value:o??"",position:"item-aligned",name:a,onChange:l,label:"Target collection",renderValue:g=>{const d=p.find(v=>v.id===g||v.path===g);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(g=>e.jsx(t.SelectGroup,{label:g||"Views",children:p.filter(d=>d.group===g).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}-${g}`))},`group_${g}`)),y&&e.jsx(t.SelectGroup,{label:"Views",children:y.map(g=>e.jsx(t.SelectItem,{value:g.id??g.path,children:e.jsxs("div",{className:"flex flex-row",children:[e.jsx(f.IconForView,{collectionOrView:g}),e.jsx(t.Typography,{variant:"subtitle2",className:"font-medium ml-4",children:g?.name.toUpperCase()})]})},g.id??g.path))})]}),e.jsx(G,{children:"You can only edit the reference collection upon field creation."})]})}function Sr({disabled:r}){const{values:a,errors:o,touched:l,setFieldValue:s}=u.useFormex(),n="mode",c=u.getIn(a,n),p=u.getIn(l,n)&&u.getIn(o,n),h="autoValue",y=u.getIn(a,h),g=u.getIn(l,h)&&u.getIn(o,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:c??"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(G,{error:!!p,children:p}),e.jsxs(t.Select,{name:h,disabled:r,value:y??"",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:!!g,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(G,{error:!!g,children:g??"Update this field automatically when creating or updating the entity"})]}),e.jsx("div",{className:"col-span-12",children:e.jsx(le,{children:e.jsx(ie,{disabled:r})})})]})}function Or({disabled:r}){return e.jsxs("div",{className:"grid grid-cols-12 gap-2",children:[e.jsx("div",{className:"col-span-12",children:e.jsx(u.Field,{type:"checkbox",name:"hideFromCollection",children:({field:l,form:s})=>e.jsx(Q,{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(u.Field,{name:"readOnly",type:"checkbox",children:({field:l,form:s})=>e.jsx(Q,{label:"Read only",disabled:r,tooltip:"Is this a read only field. Display only as a preview",form:s,field:l})})})]})}function xr({disabled:r}){return e.jsx(e.Fragment,{children:e.jsx("div",{className:"col-span-12",children:e.jsx(le,{children:e.jsx(ie,{disabled:r})})})})}function He(r,a,o){let l;return a==="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}):a==="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}):a==="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}):a==="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}):a==="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}):a==="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??[]}):a==="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??[]}}):a==="number_input"?l=f.mergeDeep(r,{dataType:"number",propertyConfig:"number_input",editable:r.editable!==void 0?r.editable:!0,enumValues:void 0}):a==="number_select"?l=f.mergeDeep(r,{dataType:"number",propertyConfig:"number_select",editable:r.editable!==void 0?r.editable:!0,enumValues:r.enumValues??[]}):a==="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??[]}}):a==="file_upload"?l=f.mergeDeep(r,{dataType:"string",propertyConfig:"file_upload",editable:r.editable!==void 0?r.editable:!0,storage:{storagePath:"/"}}):a==="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:"/"}}}):a==="group"?l=f.mergeDeep(r,{dataType:"map",propertyConfig:"group",editable:r.editable!==void 0?r.editable:!0,keyValue:!1,properties:r.properties??{}}):a==="key_value"?l=f.mergeDeep(r,{dataType:"map",propertyConfig:"key_value",editable:r.editable!==void 0?r.editable:!0,keyValue:!0,properties:void 0}):a==="reference"?l=f.mergeDeep(r,{dataType:"reference",propertyConfig:"reference",editable:r.editable!==void 0?r.editable:!0}):a==="multi_references"?l=f.mergeDeep(r,{dataType:"array",propertyConfig:"multi_references",editable:r.editable!==void 0?r.editable:!0,of:{dataType:"reference"}}):a==="switch"?l=f.mergeDeep(r,{dataType:"boolean",propertyConfig:"switch",editable:r.editable!==void 0?r.editable:!0}):a==="date_time"?l=f.mergeDeep(r,{dataType:"date",propertyConfig:"date_time",editable:r.editable!==void 0?r.editable:!0,mode:"date_time"}):a==="repeat"?l=f.mergeDeep(r,{dataType:"array",propertyConfig:"repeat",editable:r.editable!==void 0?r.editable:!0}):a==="block"?l=f.mergeDeep(r,{dataType:"array",propertyConfig:"block",editable:r.editable!==void 0?r.editable:!0,oneOf:{properties:{}}}):a&&o[a]&&(l={...o[a].property,propertyConfig:a}),l}function Ge({value:r,optionDisabled:a,propertyConfig:o,existing:l}){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(f.PropertyConfigBadge,{propertyConfig:o})}),e.jsxs("div",{children:[e.jsx("div",{children:o.name}),e.jsx(t.Typography,{variant:"caption",color:"disabled",className:"max-w-sm",children:l&&a?"You can only switch to widgets that use the same data type":o.description})]})]})})}function Vr({disabled:r,showErrors:a}){const{values:o,setFieldValue:l}=u.useFormex(),s=u.getIn(o,"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(he,{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=>{l("defaultValue",n.target.value===""?void 0:n.target.value)},label:"Default value",value:u.getIn(o,"defaultValue")??""})})]})}const Er=["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"],Ke=Object.entries(f.DEFAULT_FIELD_CONFIGS).filter(([r])=>Er.includes(r)).map(([r,a])=>({[r]:a})).reduce((r,a)=>({...r,...a}),{}),We=C.memo(function(a){const{includeIdAndName:o=!0,autoOpenTypeSelect:l,existingProperty:s,autoUpdateId:n,inArray:c,propertyKey:p,existingPropertyKeys:h,propertyNamespace:y,property:g,onPropertyChanged:d,onPropertyChangedImmediate:v=!0,onDelete:b,onError:F,initialErrors:T,forceShowErrors:N,allowDataInference:S,getController:P,getData:I,propertyConfigs:w,collectionEditable:m}=a,k={id:"",name:""},V=!!(g&&!fe(g))&&!m,z=C.useRef(g?{id:p,previousId:p,property:g}:void 0),L=({id:D,property:i})=>{const x={id:D,previousId:z.current?.id,property:i,namespace:y};z.current=x,d?.(x)},A=u.useCreateFormex({initialValues:g?{id:p,...g}:k,initialErrors:T,validateOnChange:!0,validateOnInitialRender:!0,onSubmit:(D,i)=>{console.debug("onSubmit",D);const{id:x,...Y}=D;L({id:x,property:{...Y,editable:Y.editable??!0}}),s||i.resetForm({values:k})},validation:D=>{const i={};if(o){if(!D.name)i.name="Required";else{const x=Ar(D.name);x&&(i.name=x)}if(!D.id)i.id="Required";else{const x=Dr(D.id,h);x&&(i.id=x)}}return D.dataType==="string"&&D.validation?.matches&&!f.isValidRegExp(D.validation?.matches.toString())&&(i.validation={matches:"Invalid regular expression"}),D.dataType==="reference"&&!D.path&&(i.path="You must specify a target collection for the field"),D.propertyConfig==="repeat"&&(D.of||(i.of="You need to specify a repeat field")),D.propertyConfig==="block"&&(D.oneOf||(i.oneOf="You need to specify the properties of this block")),i}});return C.useEffect(()=>{P?.(A)},[A,P]),e.jsx(u.Formex,{value:A,children:e.jsx(_r,{onPropertyChanged:v?L:void 0,onDelete:b,includeIdAndTitle:o,propertyNamespace:y,onError:F,showErrors:N||A.submitCount>0,existing:s,autoUpdateId:n,inArray:c,autoOpenTypeSelect:l,disabled:V,getData:I,allowDataInference:S,propertyConfigs:w,collectionEditable:m,...A})})},(r,a)=>r.getData===a.getData&&r.propertyKey===a.propertyKey&&r.propertyNamespace===a.propertyNamespace&&r.includeIdAndName===a.includeIdAndName&&r.autoOpenTypeSelect===a.autoOpenTypeSelect&&r.autoUpdateId===a.autoUpdateId&&r.existingProperty===a.existingProperty);function de({open:r,onCancel:a,onOkClicked:o,onPropertyChanged:l,getData:s,collectionEditable:n,...c}){const p=C.useRef(),h=y=>{p.current=y};return e.jsx(t.Dialog,{open:r??!1,maxWidth:"xl",fullWidth:!0,children:e.jsxs("form",{noValidate:!0,autoComplete:"off",onSubmit:y=>{y.preventDefault(),y.stopPropagation(),p.current?.handleSubmit(y)},children:[e.jsx(t.DialogContent,{children:e.jsx(We,{...c,onPropertyChanged:y=>{l?.(y),o?.()},collectionEditable:n,onPropertyChangedImmediate:!1,getController:h,getData:s})}),e.jsxs(t.DialogActions,{children:[a&&e.jsx(t.Button,{variant:"text",onClick:()=>{a(),p.current?.resetForm()},children:"Cancel"}),e.jsx(t.Button,{variant:"outlined",type:"submit",color:"primary",children:"Ok"})]})]})})}function _r({values:r,errors:a,setValues:o,existing:l,autoUpdateId:s=!1,autoOpenTypeSelect:n,includeIdAndTitle:c,onPropertyChanged:p,onDelete:h,propertyNamespace:y,onError:g,showErrors:d,disabled:v,inArray:b,getData:F,allowDataInference:T,propertyConfigs:N,collectionEditable:S}){const[P,I]=C.useState(n),[w,m]=C.useState(!1),[k,V]=C.useState(r?.dataType?f.getFieldId(r):void 0),z=Object.entries(Ke).concat(Object.entries(N)),L=b?z.filter(([j,$])=>!f.isPropertyBuilder($.property)&&$.property?.dataType!=="array"):z,A=C.useDeferredValue(r),D=C.useRef(null),i=C.useRef(r),x=d&&u.getIn(a,"selectedWidget");C.useEffect(()=>{if(p&&(!c||A.id)){const{id:j,...$}=A;te(A,i.current)||(p({id:j,property:$,namespace:y}),i.current=A)}},[A,c,p,y]),C.useEffect(()=>{r?.id&&g&&g(r?.id,y,a)},[a,g,y,r?.id]);const Y=j=>{V(j),o(He(r,j,N)),setTimeout(()=>{D.current?.focus()},0)};let M;return k==="text_field"||k==="multiline"||k==="markdown"||k==="email"?M=e.jsx(Pr,{widgetId:k,disabled:v,showErrors:d}):k==="url"?M=e.jsx(Vr,{disabled:v,showErrors:d}):k==="select"||k==="number_select"?M=e.jsx(Le,{multiselect:!1,allowDataInference:T,updateIds:!l,disabled:v,getData:F,showErrors:d}):k==="multi_select"||k==="multi_number_select"?M=e.jsx(Le,{multiselect:!0,updateIds:!l,disabled:v,allowDataInference:T,getData:F,showErrors:d}):k==="file_upload"?M=e.jsx(qe,{existing:l,multiple:!1,disabled:v}):k==="multi_file_upload"?M=e.jsx(qe,{existing:l,multiple:!0,disabled:v}):k==="switch"?M=e.jsx(Ir,{disabled:v}):k==="number_input"?M=e.jsx(Fr,{disabled:v}):k==="group"?M=e.jsx(br,{disabled:v,getData:F,allowDataInference:T,collectionEditable:S,propertyConfigs:N}):k==="block"?M=e.jsx(Nr,{disabled:v,getData:F,allowDataInference:T,collectionEditable:S,propertyConfigs:N}):k==="reference"?M=e.jsx(Ye,{showErrors:d,existing:l,multiple:!1,disabled:v}):k==="date_time"?M=e.jsx(Sr,{disabled:v}):k==="multi_references"?M=e.jsx(Ye,{showErrors:d,existing:l,multiple:!0,disabled:v}):k==="repeat"?M=e.jsx(Cr,{showErrors:d,existing:l,getData:F,allowDataInference:T,disabled:v,collectionEditable:S,propertyConfigs:N}):k==="key_value"?M=e.jsx(xr,{disabled:v}):M=null,e.jsxs(e.Fragment,{children:[v&&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:!!x,value:k??"",placeholder:"Select a property widget",open:P,onOpenChange:I,position:"item-aligned",disabled:v,renderValue:j=>{if(!j)return e.jsx("em",{children:"Select a property widget"});const $=j,H=f.DEFAULT_FIELD_CONFIGS[$]??N[$],J=H.property,ge=J&&!f.isPropertyBuilder(J)?f.getFieldConfig(J,N):void 0,oe=f.isPropertyBuilder(J)||l&&J.dataType!==r?.dataType,R=ge?f.mergeDeep(ge,H):H;return e.jsxs("div",{onClick:K=>{oe&&(K.stopPropagation(),K.preventDefault())},className:t.cn("flex items-center",oe?"w-full pointer-events-none opacity-50":""),children:[e.jsx("div",{className:"mr-8",children:e.jsx(f.PropertyConfigBadge,{propertyConfig:R})}),e.jsxs("div",{className:"flex flex-col items-start text-base text-left",children:[e.jsx("div",{children:R.name}),e.jsx(t.Typography,{variant:"caption",color:"disabled",children:oe?"You can only switch to widgets that use the same data type":R.description})]})]})},onValueChange:j=>{Y(j)},children:L.map(([j,$])=>{const H=$.property,J=l&&!f.isPropertyBuilder(H)&&H.dataType!==r?.dataType;return e.jsx(Ge,{value:j,optionDisabled:J,propertyConfig:$,existing:l},j)})}),x&&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:v,onClick:()=>m(!0),children:e.jsx(t.DeleteIcon,{})})]}),e.jsxs("div",{className:"grid grid-cols-12 gap-y-12 mt-8 mb-8",children:[c&&e.jsx(Tr,{showErrors:d,disabledId:l,isNewProperty:!l,disabled:v,autoUpdateId:s,ref:D}),M,e.jsx("div",{className:"col-span-12",children:e.jsx(Or,{disabled:v})})]}),h&&e.jsx(f.DeleteConfirmationDialog,{open:w,onAccept:()=>h(r?.id,y),onCancel:()=>m(!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 Br=/^[a-zA-Z_][a-zA-Z0-9_]*$/;function Dr(r,a){let o;return r||(o="You must specify an id for the field"),r&&!r.match(Br)&&(o="The id can only contain letters, numbers and underscores (_), and not start with a number"),r&&a&&a.includes(r)&&(o="There is another field with this ID already"),o}function Ar(r){let a;return r||(a="You must specify a title for the field"),a}function Mr(r){return r?(r.slice(0,1).toLowerCase()+r.slice(1)).replace(/([-_ ]){1,}/g," ").split(/[-_ ]/).reduce((a,o)=>a+o[0].toUpperCase()+o.substring(1),""):""}function zr({collection:r,onOpenChange:a,open:o}){const l=f.useSnackbarController(),s=`import { EntityCollection } from "firecms";
|
|
1
|
+
(function(U,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/formex"),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/formex","@firecms/schema_inference","@hello-pangea/dnd","json5","prism-react-renderer","@firecms/data_import_export","react-router"],e):(U=typeof globalThis<"u"?globalThis:U||self,e(U["FireCMS collection editor"]={},U.jsxRuntime,U.core,U.React,U.equal,U.ui,U.Yup,U.formex,U.schema_inference,U.dnd,U.JSON5,U.prismReactRenderer,U.data_import_export,U.reactRouter))})(this,function(U,e,i,C,te,t,sr,u,Se,Oe,ir,Ae,ae,dr){"use strict";function Me(r){const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const o in r)if(o!=="default"){const l=Object.getOwnPropertyDescriptor(r,o);Object.defineProperty(a,o,l.get?l:{enumerable:!0,get:()=>r[o]})}}return a.default=r,Object.freeze(a)}const ge=Me(C),ye=Me(sr),cr=ye.object().shape({id:ye.string().required("Required"),name:ye.string().required("Required"),path:ye.string().required("Required")});function pr({isNewCollection:r,reservedGroups:a,existingPaths:o,existingIds:l,groups:s,parentCollection:n}){const p=C.useRef(null),{values:h,setFieldValue:f,handleChange:y,touched:g,errors:d,setFieldTouched:v,isSubmitting:b,submitCount:w}=u.useFormex(),[T,F]=C.useState(!1),[S,P]=C.useState(!1),I=c=>{f("name",c),!u.getIn(g,"path")&&r&&c&&f("path",i.toSnakeCase(c)),!u.getIn(g,"id")&&r&&c&&f("id",i.toSnakeCase(c)),!u.getIn(g,"singularName")&&r&&c&&f("singularName",i.singular(c))};C.useEffect(()=>{d.id&&P(!0)},[d.id]);const N=e.jsx(i.IconForView,{collectionOrView:h}),m=s?.filter(c=>!a?.includes(c)),{inputFocused:k,autoCompleteOpen:V,setAutoCompleteOpen:z}=t.useAutoComplete({ref:p}),L=!!n;let A;typeof h.customId=="object"?A="code_defined":h.customId===!0?A="true":h.customId===!1?A="false":h.customId==="optional"&&(A="optional");const D=w>0;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:N})})]}),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:c=>I(c.target.value),label:"Name",required:!0,error:D&&!!d.name}),e.jsx(i.FieldCaption,{error:g.name&&!!d.name,children:g.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 ",L?"":"sm:col-span-8"),children:[e.jsx(u.Field,{name:"path",as:t.DebouncedTextField,label:"Path",disabled:!r,required:!0,error:D&&!!d.path}),e.jsx(i.FieldCaption,{error:g.path&&!!d.path,children:g.path&&d.path?d.path:L?"Relative path to the parent (no need to include the parent path)":"Path that this collection is stored in, in the database"})]}),!L&&e.jsxs("div",{className:"col-span-12 sm:col-span-4 relative",children:[e.jsx(t.TextField,{error:D&&!!d.group,disabled:b,value:h.group??"",autoComplete:"off",onChange:c=>f("group",c.target.value),name:"group",inputRef:p,label:"Group"}),e.jsx(t.Autocomplete,{open:V&&(m??[]).length>0,setOpen:z,children:m?.map((c,x)=>e.jsx(t.AutocompleteItem,{onClick:()=>{z(!1),f("group",c??null)},children:e.jsx("div",{className:"flex-grow",children:c})},x+"_"+c))}),e.jsx(i.FieldCaption,{children:D&&d.group?d.group:"Group of the collection"})]}),e.jsx("div",{className:"col-span-12",children:e.jsx(t.ExpandablePanel,{expanded:S,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(u.Field,{name:"id",as:t.DebouncedTextField,disabled:!r,label:"Collection id",error:D&&!!d.id}),e.jsx(i.FieldCaption,{error:g.id&&!!d.id,children:g.id&&d.id?d.id:"This id identifies this collection"})]}),e.jsxs("div",{className:"col-span-12",children:[e.jsx(t.TextField,{error:D&&!!d.singularName,name:"singularName","aria-describedby":"singularName-helper",onChange:c=>(v("singularName",!0),y(c)),value:h.singularName??"",label:"Singular name"}),e.jsx(i.FieldCaption,{error:D&&!!d.singularName,children:D&&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:D&&!!d.description,name:"description",value:h.description??"",onChange:y,multiline:!0,rows:2,"aria-describedby":"description-helper-text",label:"Description"}),e.jsx(i.FieldCaption,{error:D&&!!d.description,children:D&&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:y,value:h.defaultSize??"",renderValue:c=>c.toUpperCase(),children:["xs","s","m","l","xl"].map(c=>e.jsx(t.SelectItem,{value:c,children:c.toUpperCase()},`size-select-${c}`))})}),e.jsx("div",{className:"col-span-12",children:e.jsxs(t.Select,{name:"customId",label:"Data IDs generation",position:"item-aligned",disabled:A==="code_defined",onValueChange:c=>{if(c==="code_defined")throw new Error("This should not happen");c==="true"?f("customId",!0):c==="false"?f("customId",!1):c==="optional"&&f("customId","optional")},value:A??"",renderValue:c=>c==="code_defined"?"Code defined":c==="true"?"Users must define an ID":c==="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:c=>f("collectionGroup",c),value:h.collectionGroup??!1}),e.jsx(i.FieldCaption,{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:c=>f("textSearchEnabled",c),value:h.textSearchEnabled??!1}),e.jsx(i.FieldCaption,{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:T,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:c=>{F(!1),f("icon",c)}})})})]})})}function Q(r){return"properties."+r.replaceAll(".",".properties.")}function ze(r){return r?"properties."+r.replaceAll(".",".properties.")+".properties":"properties"}function R(r){return r?"properties."+r.replaceAll(".",".properties.")+".propertiesOrder":"propertiesOrder"}function W(r,a){return a?`${a}.${r}`:r}function xe(r,a){const o=a?`${a}.${r}`:r;return Q(o)}function hr({enumValues:r,onValuesChanged:a,onError:o,updateIds:l,disabled:s,allowDataInference:n,getData:p}){const h=u.useCreateFormex({initialValues:{enumValues:r},validateOnChange:!0,validation:g=>{const d={};g.enumValues&&g.enumValues.forEach((b,w)=>{b?.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"),b?.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 v=!!(d?.enumValues&&Object.keys(d?.enumValues).length>0);return o?.(v),d}}),{values:f,errors:y}=h;return C.useEffect(()=>{a&&a(f.enumValues)},[f.enumValues]),e.jsx(u.Formex,{value:h,children:e.jsx(fr,{enumValuesPath:"enumValues",values:f,errors:y,shouldUpdateId:l,disabled:s,allowDataInference:n,getData:p})})}function fr({values:r,errors:a,disabled:o,enumValuesPath:l,shouldUpdateId:s,allowDataInference:n,getData:p}){const{setFieldValue:h}=u.useFormex(),[f,y]=C.useState(),[g,d]=C.useState(),[v,b]=C.useState(!1),T=C.useRef(new Set).current,F=(P,I)=>{const N=f===I,m=a?.enumValues&&a?.enumValues[P];return e.jsx(gr,{index:P,disabled:o,enumValuesPath:l,autoFocus:N,entryError:m,shouldUpdateId:s||N,onDialogOpen:()=>d(P),inferredEntry:T.has(r.enumValues[P]?.id)},`${I}`)},S=async()=>{p&&(b(!0),p?.().then(P=>{if(!P)return;const I=P.flat(),N=Array.from(new Set(I)),m=r.enumValues,V=Se.extractEnumFromValues(N).filter(z=>!m?.some(L=>L.id===z.id));V.forEach(z=>{T.add(z.id)}),h(l,[...V,...m],!0)}).catch(P=>{console.error(P)}).finally(()=>b(!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:v,disabled:o||v,variant:"text",size:"small",onClick:S,children:[v?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.ArrayContainer,{droppableId:l,addLabel:"Add enum value",value:r.enumValues,disabled:o,size:"small",buildEntry:F,onInternalIdAdded:y,includeAddButton:!0,onValueChange:P=>h(l,P),newDefaultEntry:{id:"",label:""}}),e.jsx(ur,{index:g,open:g!==void 0,enumValuesPath:l,onClose:()=>d(void 0)})]})]})}const gr=C.memo(function({index:a,shouldUpdateId:o,enumValuesPath:l,autoFocus:s,onDialogOpen:n,disabled:p,inferredEntry:h,entryError:f}){const{values:y,handleChange:g,errors:d,setFieldValue:v,touched:b}=u.useFormex(),w=C.useRef(!u.getIn(y,`${l}[${a}].id`)),T=o||w.current,F=u.getIn(y,`${l}[${a}].id`),S=u.getIn(y,`${l}[${a}].label`),P=C.useRef(S);return C.useEffect(()=>{(P.current===F||!F)&&T&&v(`${l}[${a}].id`,S),P.current=S},[S]),e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex w-full align-center justify-center",children:[e.jsx(u.Field,{name:`${l}[${a}].label`,as:t.DebouncedTextField,className:"flex-grow",required:!0,disabled:p,size:"small",autoFocus:s,autoComplete:"off",endAdornment:h&&e.jsx(t.AutoAwesomeIcon,{size:"small"}),error:!!f?.label}),!p&&e.jsx(t.Badge,{color:"error",invisible:!f?.id,children:e.jsx(t.IconButton,{size:"small","aria-label":"edit",className:"m-1",onClick:()=>n(),children:e.jsx(t.SettingsIcon,{size:"small"})})})]}),f?.label&&e.jsx(t.Typography,{variant:"caption",className:"ml-3.5 text-red-500 dark:text-red-500",children:f?.label}),f?.id&&e.jsx(t.Typography,{variant:"caption",className:"ml-3.5 text-red-500 dark:text-red-500",children:f?.id})]})},function(a,o){return a.index===o.index&&a.enumValuesPath===o.enumValuesPath&&a.shouldUpdateId===o.shouldUpdateId&&a.inferredEntry===o.inferredEntry&&te(a.entryError,o.entryError)&&a.autoFocus===o.autoFocus});function ur({index:r,open:a,onClose:o,enumValuesPath:l}){const{errors:s}=u.useFormex(),n=r!==void 0?u.getIn(s,`${l}[${r}].id`):void 0;return e.jsxs(t.Dialog,{maxWidth:"md","aria-labelledby":"enum-edit-dialog",open:a,onOpenChange:p=>p?void 0:o(),children:[e.jsx(t.DialogContent,{children:r!==void 0&&e.jsxs("div",{children:[e.jsx(u.Field,{name:`${l}[${r}].id`,as:t.DebouncedTextField,required:!0,label:"ID",size:"small",autoComplete:"off",error:!!n}),e.jsx(i.FieldCaption,{error:!!n,children:n??"Value saved in the data source"})]})}),e.jsx(t.DialogActions,{children:e.jsx(t.Button,{autoFocus:!0,variant:"outlined",onClick:o,color:"primary",children:"Ok"})})]})}function J({field:r,form:a,label:o,tooltip:l,disabled:s,size:n="small",allowIndeterminate:p}){const h=e.jsx(t.BooleanSwitchWithLabel,{label:o,size:n,position:"start",value:r.value,disabled:s,allowIndeterminate:p,onValueChange:f=>a.setFieldValue(r.name,f)});return l?e.jsx(t.Tooltip,{title:l,children:h}):h}function se({disabled:r}){const{values:a,handleChange:o}=u.useFormex(),l="validation.required",s="validation.requiredMessage";return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"col-span-6",children:e.jsx(u.Field,{name:l,type:"checkbox",children:({field:p,form:h})=>e.jsx(J,{disabled:r,label:"Required",tooltip:"You won't be able to save this entity if this value is not set",form:h,field:p})})}),e.jsx("div",{className:"col-span-6",children:e.jsx(u.Field,{name:"validation.unique",type:"checkbox",children:({field:p,form:h})=>e.jsx(J,{disabled:r,label:"Unique",tooltip:"There cannot be multiple entities with the same value",form:h,field:p})})}),u.getIn(a,l)&&e.jsx("div",{className:"col-span-12",children:e.jsx(t.DebouncedTextField,{disabled:r,value:u.getIn(a,s),label:"Required message",name:s,size:"small",onChange:o})})]})}function pe({length:r,lowercase:a,matches:o,max:l,min:s,trim:n,uppercase:p,disabled:h,showErrors:f}){const{values:y,handleChange:g,errors:d}=u.useFormex(),v="validation.length",b="validation.min",w="validation.max",T="validation.trim",F="validation.matches",S="validation.lowercase",P="validation.uppercase",I=u.getIn(d,F),N=u.getIn(y,F),m=typeof N=="string"?N:i.serializeRegExp(N);return e.jsxs("div",{className:"grid grid-cols-12 gap-2",children:[e.jsx(se,{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(u.Field,{name:S,type:"checkbox",children:({field:k,form:V})=>e.jsx(J,{label:"Lowercase",disabled:h,form:V,field:k})})}),p&&e.jsx("div",{className:"col-span-4",children:e.jsx(u.Field,{name:P,type:"checkbox",children:({field:k,form:V})=>e.jsx(J,{label:"Uppercase",disabled:h,form:V,field:k})})}),n&&e.jsx("div",{className:"col-span-4",children:e.jsx(u.Field,{name:T,type:"checkbox",children:({field:k,form:V})=>e.jsx(J,{label:"Trim",disabled:h,form:V,field:k})})})]}),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:u.getIn(y,v),label:"Exact length",name:v,type:"number",size:"small",disabled:h,onChange:g})}),s&&e.jsx("div",{className:"col-span-4",children:e.jsx(t.DebouncedTextField,{value:u.getIn(y,b),label:"Min length",name:b,type:"number",size:"small",disabled:h,onChange:g})}),l&&e.jsx("div",{className:"col-span-4",children:e.jsx(t.DebouncedTextField,{value:u.getIn(y,w),label:"Max length",name:w,type:"number",size:"small",disabled:h,onChange:g})})]}),o&&e.jsxs("div",{className:"col-span-12",children:[e.jsx(u.Field,{name:F,as:t.DebouncedTextField,label:"Matches regex",size:"small",disabled:h,value:m,error:!!I}),e.jsx(i.FieldCaption,{error:!!I,children:I?"Not a valid regexp":"e.g. /^\\d+$/ for digits only"})]})]})}function Ve({max:r=!0,min:a=!0,disabled:o}){const{values:l,handleChange:s}=u.useFormex(),n="validation.min",p="validation.max";return e.jsxs("div",{className:"grid grid-cols-12 gap-2",children:[e.jsx(se,{disabled:o}),a&&e.jsx("div",{className:"col-span-6",children:e.jsx(t.DebouncedTextField,{value:u.getIn(l,n),disabled:o,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:u.getIn(l,p),disabled:o,label:"Max length",name:p,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 Ue({multiselect:r,updateIds:a,disabled:o,showErrors:l,allowDataInference:s,getData:n}){const{values:p,setFieldError:h,setFieldValue:f}=u.useFormex(),y=i.useSnackbarController(),g=r?"of.enumValues":"enumValues",d=u.getIn(p,"defaultValue"),v=u.getIn(p,g),b=C.useMemo(()=>!v||typeof v=="boolean"?[]:i.resolveEnumValues(v)??[],[v]),w=T=>{if(p&&(f(g,T),!r)){const F=T.filter(S=>!!S?.id).map(S=>S.id);d&&!F.includes(d)&&(f("defaultValue",void 0),y.open({type:"warning",message:"Default value was cleared"}))}};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"col-span-12",children:e.jsx(hr,{enumValues:b,updateIds:a,disabled:o,allowDataInference:s,onError:T=>{h(g,T?"This enum property is missing some values":void 0)},getData:n?()=>n().then(T=>T.map(F=>p.id&&u.getIn(F,p.id)).filter(Boolean)):void 0,onValuesChanged:w})}),e.jsx("div",{className:"col-span-12",children:e.jsxs(le,{children:[!r&&e.jsx(pe,{disabled:o,showErrors:l}),r&&e.jsx(Ve,{disabled:o})]})}),!r&&e.jsx("div",{className:"col-span-12",children:e.jsx(t.Select,{disabled:o,position:"item-aligned",onValueChange:T=>{f("defaultValue",T)},label:"Default value",value:d??"",children:b.filter(T=>!!T?.id).map(T=>e.jsx(t.SelectItem,{value:T.id?.toString(),children:T.label},T.id))})})]})}const ve={"image/*":"Images","video/*":"Videos","audio/*":"Audio files","application/*":"Files (pdf, zip, csv, excel...)","text/*":"Text files"};function Le({multiple:r,existing:a,disabled:o}){const{values:l,setFieldValue:s}=u.useFormex(),n=r?"of.storage":"storage",p=`${n}.acceptedFiles`,h=`${n}.fileName`,f=`${n}.storagePath`,y=`${n}.storeUrl`,g=u.getIn(l,h)??"{rand}_{file}",d=u.getIn(l,f)??"/",v=u.getIn(l,p),b=Array.isArray(v)?v:void 0,w=!b||b.length===0,T=P=>{P?P.includes("all")||P.length>=Object.keys(ve).length?s(p,void 0):w?s(p,Object.keys(ve).filter(I=>!P.includes(I))):s(p,P):s(p,void 0)},F=typeof g=="function",S=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:o,name:p,value:b??[],onMultiValueChange:T,label:w?void 0:"Allowed file types",renderValues:P=>!P||P.length===0?"All file types allowed":P.map(I=>ve[I]).filter(I=>!!I).join(", "),children:[e.jsxs(t.MultiSelectItem,{value:"all",className:"flex items-center gap-2",children:[e.jsx(t.Checkbox,{checked:!b}),"All"]},"all"),Object.entries(ve).map(([P,I])=>e.jsxs(t.MultiSelectItem,{value:P,className:"flex items-center gap-2",children:[e.jsx(t.Checkbox,{checked:w||b.indexOf(P)>-1}),e.jsx("div",{className:"flex-grow",children:I}),e.jsx(t.Button,{size:"small",variant:"outlined",onClick:N=>(N.preventDefault(),N.stopPropagation(),s(p,[P])),children:"Only"})]},P))]})}),e.jsx("div",{className:"col-span-12",children:e.jsx(u.Field,{name:h,as:t.DebouncedTextField,label:"File name",size:"small",disabled:F||o,value:F?"-":g})}),e.jsxs("div",{className:"col-span-12",children:[e.jsx(u.Field,{name:f,as:t.DebouncedTextField,label:"Storage path",disabled:S||o,size:"small",value:S?"-":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(u.Field,{name:y,type:"checkbox",children:({field:P,form:I})=>e.jsx(J,{label:"Save URL instead of storage path",disabled:a||o,form:I,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(se,{disabled:o})}),r&&e.jsx("div",{className:"col-span-12",children:e.jsx(Ve,{disabled:o})})]})})]})}function he(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 qe(r){return Object.entries(r).filter(([a,o])=>he(o)).map(([a,o])=>{const l=o;if(he(l))return l.dataType==="map"&&l.properties?{[a]:{...l,properties:qe(l.properties)}}:{[a]:l}}).filter(a=>!!a).reduce((a,o)=>({...a,...o}),{})}function $e({property:r,onClick:a,hasError:o,includeName:l,includeEditButton:s,selected:n}){const{propertyConfigs:p}=i.useCustomizationController(),h=i.getFieldConfig(r,p);he(r);const f=o?"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 o&&console.log("PropertyFieldPreview",r),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("border","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:[l&&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:l?"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 yr({name:r,selected:a,onClick:o,property:l}){const{propertyConfigs:s}=i.useCustomizationController(),n=!i.isPropertyBuilder(l)&&l?i.getFieldConfig(l,s):void 0;return e.jsxs("div",{onClick:o,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,o?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: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&&!i.isPropertyBuilder(l)&&e.jsx(i.ErrorBoundary,{children:e.jsx(t.Typography,{variant:"body2",component:"span",color:"disabled",children:l.dataType})}),l&&i.isPropertyBuilder(l)&&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"})}),!l&&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"})})]})]})})]})}const me=C.memo(function({namespace:a,selectedPropertyKey:o,onPropertyClick:l,properties:s,propertiesOrder:n,additionalFields:p,errors:h,onPropertyMove:f,onPropertyRemove:y,className:g,inferredPropertyKeys:d,collectionEditable:v}){const b=n??Object.keys(s),w=C.useCallback(T=>{if(!T.destination)return;const F=T.source.index,S=T.destination.index,P=Array.from(b),[I]=P.splice(F,1);P.splice(S,0,I),f&&f(P,a)},[a,f,b]);return e.jsx(e.Fragment,{children:e.jsx(Oe.DragDropContext,{onDragEnd:w,children:e.jsx(Oe.Droppable,{droppableId:`droppable_${a}`,children:(T,F)=>e.jsxs("div",{...T.droppableProps,ref:T.innerRef,className:g,children:[b&&b.map((S,P)=>{const I=s[S],N=p?.find(m=>m.key===S);return!I&&!N?(console.warn(`Property ${S} not found in properties or additionalFields`),null):e.jsx(Oe.Draggable,{draggableId:`array_field_${a}_${S}}`,index:P,children:(m,k)=>e.jsx(i.ErrorBoundary,{children:e.jsx(vr,{propertyKey:S,propertyOrBuilder:I,additionalField:N,provided:m,errors:h,namespace:a,inferredPropertyKeys:d,onPropertyMove:f,onPropertyRemove:y,onPropertyClick:k.isDragging?void 0:l,selectedPropertyKey:o,collectionEditable:v})})},`array_field_${a}_${S}}`)}).filter(Boolean),T.placeholder]})})})})},(r,a)=>{const o=a.selectedPropertyKey?.startsWith(a.namespace??""),l=r.selectedPropertyKey?.startsWith(r.namespace??"");return o||l?!1:te(r.properties,a.properties)&&r.propertiesOrder===a.propertiesOrder&&te(r.additionalFields,a.additionalFields)&&te(r.errors,a.errors)&&te(r.onPropertyClick,a.onPropertyClick)&&r.namespace===a.namespace&&r.collectionEditable===a.collectionEditable});function vr({propertyKey:r,namespace:a,propertyOrBuilder:o,additionalField:l,provided:s,selectedPropertyKey:n,errors:p,onPropertyClick:h,onPropertyMove:f,onPropertyRemove:y,inferredPropertyKeys:g,collectionEditable:d}){const v=g?.includes(a?`${a}.${r}`:r),b=W(r,a),T=xe(r,a)in p;let F;if(typeof o=="object"){const I=o;I.dataType==="map"&&I.properties&&(F=e.jsx(me,{selectedPropertyKey:n,namespace:b,properties:I.properties,propertiesOrder:I.propertiesOrder,errors:p,onPropertyClick:h,onPropertyMove:f,onPropertyRemove:y,collectionEditable:d}))}const S=n===b,P=o&&(d&&!i.isPropertyBuilder(o)||he(o));return e.jsxs("div",{ref:s.innerRef,...s.draggableProps,...s.dragHandleProps,className:"relative -ml-8",children:[F&&e.jsx("div",{className:"absolute border-l "+t.defaultBorderMixin,style:{left:"32px",top:"64px",bottom:"16px"}}),!i.isPropertyBuilder(o)&&!l&&P?e.jsx($e,{property:o,onClick:h?()=>h(r,a):void 0,includeName:!0,selected:S,hasError:T}):e.jsx(yr,{name:r,property:o,onClick:h?()=>h(r,a):void 0,selected:S}),e.jsxs("div",{className:"absolute top-2 right-2 flex flex-row ",children:[v&&e.jsx(t.Tooltip,{title:"Inferred property",children:e.jsx(t.AutoAwesomeIcon,{size:"small",className:"p-2"})}),y&&e.jsx(t.Tooltip,{title:"Remove",children:e.jsx(t.IconButton,{size:"small",color:"inherit",onClick:()=>y(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"})})})]}),F&&e.jsx("div",{className:"ml-16",children:F})]})}function mr({disabled:r,getData:a,allowDataInference:o,propertyConfigs:l,collectionEditable:s}){const{values:n,setFieldValue:p}=u.useFormex(),[h,f]=C.useState(!1),[y,g]=C.useState(),[d,v]=C.useState(),b=n.propertiesOrder??Object.keys(n.properties??{}),w=({id:N,property:m})=>{if(!N)throw Error();p("properties",{...n.properties??{},[N]:m},!1);const k=n.propertiesOrder??Object.keys(n.properties??{}),V=k.includes(N)?k:[...k,N];p("propertiesOrder",V,!1),f(!1)},T=C.useCallback((N,m)=>{const k=N?W(N,m):void 0;if(!k)throw Error("collection editor miss config");const V=Q(k),z=R(m),L=u.getIn(n,z)??Object.keys(u.getIn(n,ze(m)));p(V,void 0,!1),p(z,L.filter(A=>A!==N),!1),f(!1),g(void 0),v(void 0)},[p,n]),F=y?W(y,d):void 0,S=F?u.getIn(n.properties,F.replaceAll(".",".properties.")):void 0,P=!b||b.length<1,I=C.useCallback((N,m)=>{p(R(m),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 my-4",children:[e.jsx(t.Typography,{variant:"subtitle2",children:"Properties in this group"}),e.jsxs(t.Button,{color:"primary",variant:"outlined",onClick:()=>f(!0),startIcon:e.jsx(t.AddIcon,{}),children:["Add property to ",n.name??"this group"]})]}),e.jsxs(t.Paper,{className:"p-2 pl-8",children:[e.jsx(me,{properties:n.properties??{},propertiesOrder:b,errors:{},collectionEditable:s,onPropertyClick:(N,m)=>{g(N),v(m),f(!0)},onPropertyMove:I}),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:N=>p("spreadChildren",N),value:n.spreadChildren??!1}),e.jsx(i.FieldCaption,{children:"Set this flag to true if you want to display the children of this group as individual columns."})]}),e.jsx(ie,{inArray:!1,forceShowErrors:!1,open:h,allowDataInference:o,collectionEditable:s,onCancel:()=>{f(!1),g(void 0),v(void 0)},onOkClicked:()=>{f(!1),g(void 0),v(void 0)},getData:a,onDelete:T,propertyKey:y,propertyNamespace:d,property:S,existingProperty:!!y,autoUpdateId:!y,autoOpenTypeSelect:!y,onPropertyChanged:w,existingPropertyKeys:y?void 0:b,propertyConfigs:l})]})}function br({showErrors:r,existing:a,disabled:o,getData:l,allowDataInference:s,propertyConfigs:n,collectionEditable:p}){const{values:h,handleChange:f,errors:y,setFieldValue:g,touched:d}=u.useFormex(),[v,b]=C.useState(!1),w=u.getIn(h,"of"),T=u.getIn(d,"of")&&u.getIn(y,"of"),F=({id:P,property:I,namespace:N})=>{console.log("onPropertyChanged",P,I,N),g("of",I)},S=w&&i.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(u.Field,{name:"of",value:w,children:({})=>e.jsxs(t.Paper,{className:"p-2 mt-4",children:[w&&e.jsx($e,{property:w,onClick:o?void 0:()=>b(!0),includeName:!1,includeEditButton:!0,selected:!1,hasError:!1}),!o&&!w&&e.jsxs(t.Button,{variant:"text",size:"large",color:T?"error":"primary",onClick:()=>b(!0),children:["Edit ",`${S?S.name:"repeat component"}`]}),e.jsx(ie,{inArray:!0,open:v,existingProperty:a,getData:l,autoUpdateId:!a,autoOpenTypeSelect:!a,onOkClicked:()=>b(!1),allowDataInference:s,property:w,includeIdAndName:!1,onPropertyChanged:F,forceShowErrors:r,propertyConfigs:n,collectionEditable:p})]})})]}),e.jsx("div",{className:"col-span-12",children:e.jsx(le,{children:e.jsx(Ve,{disabled:o})})})]})}const Cr=C.forwardRef(function({showErrors:a,disabledId:o,disabled:l,autoUpdateId:s,isNewProperty:n},p){const{errors:h,values:f,setFieldValue:y,setFieldTouched:g,touched:d,validate:v}=u.useFormex(),b="name",w=a&&u.getIn(h,b),T="id",F=a&&u.getIn(h,T),S="description",P=a&&u.getIn(h,S);return e.jsxs("div",{className:"flex flex-col gap-2 col-span-12",children:[e.jsxs("div",{children:[e.jsx(u.Field,{name:b,inputRef:p,as:t.DebouncedTextField,value:f[b],onChange:I=>{const N=I.target.value;!u.getIn(d,T)&&s&&y(T,N?i.toSnakeCase(N):"",!1),y(b,N,!0),g(b,!0)},style:{fontSize:20},placeholder:"Field name",required:!0,disabled:l,error:!!w}),e.jsx(i.FieldCaption,{error:!!w,children:w})]}),e.jsxs("div",{children:[e.jsx(u.Field,{name:T,as:t.DebouncedTextField,label:"ID",value:f[T],onChange:I=>{const N=I.target.value;!u.getIn(d,b)&&s&&y(b,N?i.unslugify(N):""),y(T,N,!0),g(T,!0)},disabled:o||l,required:!0,size:"small",error:!!F}),e.jsx(i.FieldCaption,{error:!!F,children:F})]}),e.jsxs("div",{children:[e.jsx(u.Field,{name:S,as:t.DebouncedTextField,label:"Description",disabled:l,error:!!P}),e.jsx(i.FieldCaption,{error:!!P,children:P})]})]})});function Tr({widgetId:r,disabled:a,showErrors:o}){const{values:l,setFieldValue:s}=u.useFormex();return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"col-span-12",children:e.jsxs(le,{children:[r==="text_field"&&e.jsx(pe,{disabled:a,length:!0,lowercase:!0,matches:!0,max:!0,min:!0,trim:!0,uppercase:!0,showErrors:o}),r==="multiline"&&e.jsx(pe,{disabled:a,length:!0,lowercase:!0,max:!0,min:!0,trim:!0,uppercase:!0,showErrors:o}),r==="markdown"&&e.jsx(pe,{disabled:a,length:!0,lowercase:!0,max:!0,min:!0,trim:!0,uppercase:!0,showErrors:o}),r==="email"&&e.jsx(pe,{disabled:a,max:!0,min:!0,trim:!0,showErrors:o})]})}),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:u.getIn(l,"defaultValue")??""})})]})}function Pr({disabled:r}){const{values:a}=u.useFormex(),o=u.getIn(a,"defaultValue");return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"col-span-12",children:e.jsx(le,{children:e.jsx(se,{disabled:r})})}),e.jsx("div",{className:"col-span-12",children:e.jsx(u.Field,{name:"defaultValue",children:({field:l,form:s})=>e.jsx(J,{label:o==null?"Default value not set":"Default value is "+o.toString(),disabled:r,allowIndeterminate:!0,field:l,form:s})})})]})}function Ir({disabled:r,getData:a,allowDataInference:o,propertyConfigs:l,collectionEditable:s}){const{values:n,setFieldValue:p}=u.useFormex(),[h,f]=C.useState(!1),[y,g]=C.useState(),[d,v]=C.useState(),b=({id:I,property:N})=>{if(!I)throw Error();p("oneOf.properties",{...n.oneOf?.properties??{},[I]:N},!1);const m=n.oneOf?.propertiesOrder??Object.keys(n.oneOf?.properties??{}),k=m.includes(I)?m:[...m,I];p("oneOf.propertiesOrder",k,!1),f(!1)},w=y?W(y,d):void 0,T=w?u.getIn(n.oneOf?.properties,w.replaceAll(".",".properties.")):void 0,F=C.useCallback((I,N)=>{const m=I?W(I,N):void 0;if(!m)throw Error("collection editor miss config");p(`oneOf.${Q(m)}`,void 0,!1);const k=`oneOf.${R(N)}`,V=u.getIn(n,k);p(k,V.filter(z=>z!==I),!1),f(!1),g(void 0),v(void 0)},[p,n]),S=e.jsxs(t.Button,{autoFocus:!0,color:"primary",onClick:()=>f(!0),startIcon:e.jsx(t.AddIcon,{}),children:["Add property to ",n.name??"this block"]}),P=C.useCallback((I,N)=>{p(`oneOf.${R(N)}`,I,!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"}),S]}),e.jsxs(t.Paper,{className:"p-2 pl-8",children:[e.jsx(me,{properties:n.oneOf?.properties??{},propertiesOrder:n.oneOf?.propertiesOrder,errors:{},collectionEditable:s,onPropertyClick:r?void 0:(I,N)=>{g(I),v(N),f(!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(ie,{inArray:!1,forceShowErrors:!1,open:h,getData:a,allowDataInference:o,onCancel:()=>{f(!1),g(void 0),v(void 0)},onOkClicked:()=>{f(!1),g(void 0),v(void 0)},collectionEditable:s,onDelete:F,propertyKey:y,propertyNamespace:d,property:T,existingProperty:!!y,autoUpdateId:!y,autoOpenTypeSelect:!y,onPropertyChanged:b,existingPropertyKeys:y?void 0:n.oneOf?.propertiesOrder,propertyConfigs:l})]})}function Fr({disabled:r}){const{values:a,handleChange:o}=u.useFormex(),l="validation.min",s="validation.max",n="validation.lessThan",p="validation.moreThan";return e.jsxs("div",{className:"grid grid-cols-12 gap-2",children:[e.jsx(se,{disabled:r}),e.jsx("div",{className:"col-span-6",children:e.jsx(t.DebouncedTextField,{value:u.getIn(a,l),label:"Min value",name:l,type:"number",size:"small",disabled:r,onChange:o})}),e.jsx("div",{className:"col-span-6",children:e.jsx(t.DebouncedTextField,{value:u.getIn(a,s),label:"Max value",name:s,type:"number",size:"small",disabled:r,onChange:o})}),e.jsx("div",{className:"col-span-6",children:e.jsx(t.DebouncedTextField,{value:u.getIn(a,n),label:"Less than",name:n,type:"number",size:"small",disabled:r,onChange:o})}),e.jsx("div",{className:"col-span-6",children:e.jsx(t.DebouncedTextField,{value:u.getIn(a,p),label:"More than",name:p,type:"number",size:"small",disabled:r,onChange:o})}),e.jsx("div",{className:"col-span-4",children:e.jsx(u.Field,{name:"validation.positive",type:"checkbox",children:({field:g,form:d})=>e.jsx(J,{label:"Positive value",disabled:r,form:d,field:g})})}),e.jsx("div",{className:"col-span-4",children:e.jsx(u.Field,{name:"validation.negative",type:"checkbox",children:({field:g,form:d})=>e.jsx(J,{label:"Negative value",disabled:r,form:d,field:g})})}),e.jsx("div",{className:"col-span-4",children:e.jsx(u.Field,{name:"validation.integer",type:"checkbox",children:({field:g,form:d})=>e.jsx(J,{label:"Integer value",disabled:r,form:d,field:g})})})]})}function Nr({disabled:r}){const{values:a,setFieldValue:o}=u.useFormex();return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"col-span-12",children:e.jsx(le,{children:e.jsx(Fr,{disabled:r})})}),e.jsx("div",{className:"col-span-12",children:e.jsx(t.TextField,{name:"defaultValue",disabled:r,type:"number",onChange:l=>{o("defaultValue",l.target.value===""?void 0:parseFloat(l.target.value))},label:"Default value",value:u.getIn(a,"defaultValue")??""})})]})}function je({existing:r,multiple:a,disabled:o,showErrors:l}){const{values:s,handleChange:n,errors:p}=u.useFormex();if(!i.useNavigationController())return e.jsx("div",{className:"col-span-12",children:e.jsx(t.CircularProgress,{})});const f=a?"of.path":"path",y=u.getIn(s,f),g=l&&u.getIn(p,f);return e.jsx(e.Fragment,{children:e.jsx("div",{className:"col-span-12",children:e.jsx(u.Field,{name:f,pathPath:f,type:"select",disabled:r&&!!y||o,value:y,error:g,handleChange:n,as:wr})})})}function wr({disabled:r,pathPath:a,value:o,handleChange:l,error:s,...n}){const p=i.useNavigationController();if(!p)return e.jsx("div",{className:"col-span-12",children:e.jsx(t.CircularProgress,{})});const h=p?.collections??[],f=Array.from(new Set(Object.values(h).map(g=>g.group).filter(Boolean)).values()),y=h.filter(g=>!g.group);return e.jsxs(e.Fragment,{children:[e.jsxs(t.Select,{error:!!s,disabled:r,value:o??"",position:"item-aligned",name:a,onChange:l,label:"Target collection",renderValue:g=>{const d=h.find(v=>v.id===g||v.path===g);return d?e.jsxs("div",{className:"flex flex-row",children:[e.jsx(i.IconForView,{collectionOrView:d}),e.jsx(t.Typography,{variant:"subtitle2",className:"font-medium ml-4",children:d?.name.toUpperCase()})]}):null},...n,children:[f.flatMap(g=>e.jsx(t.SelectGroup,{label:g||"Views",children:h.filter(d=>d.group===g).map(d=>e.jsx(t.SelectItem,{value:d.id??d.path,children:e.jsxs("div",{className:"flex flex-row",children:[e.jsx(i.IconForView,{collectionOrView:d}),e.jsx(t.Typography,{variant:"subtitle2",className:"font-medium ml-4",children:d?.name.toUpperCase()})]})},`${d.id??d.path}-${g}`))},`group_${g}`)),y&&e.jsx(t.SelectGroup,{label:"Views",children:y.map(g=>e.jsx(t.SelectItem,{value:g.id??g.path,children:e.jsxs("div",{className:"flex flex-row",children:[e.jsx(i.IconForView,{collectionOrView:g}),e.jsx(t.Typography,{variant:"subtitle2",className:"font-medium ml-4",children:g?.name.toUpperCase()})]})},g.id??g.path))})]}),e.jsx(i.FieldCaption,{children:"You can only edit the reference collection upon field creation."})]})}function kr({disabled:r}){const{values:a,errors:o,touched:l,setFieldValue:s}=u.useFormex(),n="mode",p=u.getIn(a,n),h=u.getIn(l,n)&&u.getIn(o,n),f="autoValue",y=u.getIn(a,f),g=u.getIn(l,f)&&u.getIn(o,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:p??"date",error:!!h,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(i.FieldCaption,{error:!!h,children:h}),e.jsxs(t.Select,{name:f,disabled:r,value:y??"",onValueChange:d=>s(f,d==="none"?null:d),renderValue:d=>{switch(d){case"on_create":return"On create";case"on_update":return"On any update";default:return"None"}},error:!!g,label:"Automatic value",children:[e.jsx(t.SelectItem,{value:"none",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(i.FieldCaption,{error:!!g,children:g??"Update this field automatically when creating or updating the entity"})]}),e.jsx("div",{className:"col-span-12",children:e.jsx(le,{children:e.jsx(se,{disabled:r})})})]})}function Sr({disabled:r}){return e.jsxs("div",{className:"grid grid-cols-12 gap-2",children:[e.jsx("div",{className:"col-span-12",children:e.jsx(u.Field,{type:"checkbox",name:"hideFromCollection",children:({field:l,form:s})=>e.jsx(J,{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(u.Field,{name:"readOnly",type:"checkbox",children:({field:l,form:s})=>e.jsx(J,{label:"Read only",disabled:r,tooltip:"Is this a read only field. Display only as a preview",form:s,field:l})})})]})}function Or({disabled:r}){return e.jsx(e.Fragment,{children:e.jsx("div",{className:"col-span-12",children:e.jsx(le,{children:e.jsx(se,{disabled:r})})})})}function Ye(r,a,o){let l;return a==="text_field"?l=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"?l=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"?l=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"?l=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"?l=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"?l=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"?l=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"?l=i.mergeDeep(r,{dataType:"number",propertyConfig:"number_input",editable:r.editable!==void 0?r.editable:!0,enumValues:void 0}):a==="number_select"?l=i.mergeDeep(r,{dataType:"number",propertyConfig:"number_select",editable:r.editable!==void 0?r.editable:!0,enumValues:r.enumValues??[]}):a==="multi_number_select"?l=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"?l=i.mergeDeep(r,{dataType:"string",propertyConfig:"file_upload",editable:r.editable!==void 0?r.editable:!0,storage:{storagePath:"/"}}):a==="multi_file_upload"?l=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"?l=i.mergeDeep(r,{dataType:"map",propertyConfig:"group",editable:r.editable!==void 0?r.editable:!0,keyValue:!1,properties:r.properties??{}}):a==="key_value"?l=i.mergeDeep(r,{dataType:"map",propertyConfig:"key_value",editable:r.editable!==void 0?r.editable:!0,keyValue:!0,properties:void 0}):a==="reference"?l=i.mergeDeep(r,{dataType:"reference",propertyConfig:"reference",editable:r.editable!==void 0?r.editable:!0}):a==="multi_references"?l=i.mergeDeep(r,{dataType:"array",propertyConfig:"multi_references",editable:r.editable!==void 0?r.editable:!0,of:{dataType:"reference"}}):a==="switch"?l=i.mergeDeep(r,{dataType:"boolean",propertyConfig:"switch",editable:r.editable!==void 0?r.editable:!0}):a==="date_time"?l=i.mergeDeep(r,{dataType:"date",propertyConfig:"date_time",editable:r.editable!==void 0?r.editable:!0,mode:"date_time"}):a==="repeat"?l=i.mergeDeep(r,{dataType:"array",propertyConfig:"repeat",editable:r.editable!==void 0?r.editable:!0}):a==="block"?l=i.mergeDeep(r,{dataType:"array",propertyConfig:"block",editable:r.editable!==void 0?r.editable:!0,oneOf:{properties:{}}}):a&&o[a]&&(l={...o[a].property,propertyConfig:a}),l}function He({value:r,optionDisabled:a,propertyConfig:o,existing:l}){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:o})}),e.jsxs("div",{children:[e.jsx("div",{children:o.name}),e.jsx(t.Typography,{variant:"caption",color:"disabled",className:"max-w-sm",children:l&&a?"You can only switch to widgets that use the same data type":o.description})]})]})})}function xr({disabled:r,showErrors:a}){const{values:o,setFieldValue:l}=u.useFormex(),s=u.getIn(o,"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(pe,{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=>{l("defaultValue",n.target.value===""?void 0:n.target.value)},label:"Default value",value:u.getIn(o,"defaultValue")??""})})]})}const Vr=["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"],Ge=Object.entries(i.DEFAULT_FIELD_CONFIGS).filter(([r])=>Vr.includes(r)).map(([r,a])=>({[r]:a})).reduce((r,a)=>({...r,...a}),{}),Ke=C.memo(function(a){const{includeIdAndName:o=!0,autoOpenTypeSelect:l,existingProperty:s,autoUpdateId:n,inArray:p,propertyKey:h,existingPropertyKeys:f,propertyNamespace:y,property:g,onPropertyChanged:d,onPropertyChangedImmediate:v=!0,onDelete:b,onError:w,initialErrors:T,forceShowErrors:F,allowDataInference:S,getController:P,getData:I,propertyConfigs:N,collectionEditable:m}=a,k={id:"",name:""},V=!!(g&&!he(g))&&!m,z=C.useRef(g?{id:h,previousId:h,property:g}:void 0),L=({id:D,property:c})=>{const x={id:D,previousId:z.current?.id,property:c,namespace:y};z.current=x,d?.(x)},A=u.useCreateFormex({initialValues:g?{id:h,...g}:k,initialErrors:T,validateOnChange:!0,validateOnInitialRender:!0,onSubmit:(D,c)=>{console.debug("onSubmit",D);const{id:x,...Y}=D;L({id:x,property:{...Y,editable:Y.editable??!0}}),s||c.resetForm({values:k})},validation:D=>{const c={};if(o){if(!D.name)c.name="Required";else{const x=Dr(D.name);x&&(c.name=x)}if(!D.id)c.id="Required";else{const x=Br(D.id,f);x&&(c.id=x)}}return D.dataType==="string"&&D.validation?.matches&&!i.isValidRegExp(D.validation?.matches.toString())&&(c.validation={matches:"Invalid regular expression"}),D.dataType==="reference"&&!D.path&&(c.path="You must specify a target collection for the field"),D.propertyConfig==="repeat"&&(D.of||(c.of="You need to specify a repeat field")),D.propertyConfig==="block"&&(D.oneOf||(c.oneOf="You need to specify the properties of this block")),c}});return C.useEffect(()=>{P?.(A)},[A,P]),e.jsx(u.Formex,{value:A,children:e.jsx(Er,{onPropertyChanged:v?L:void 0,onDelete:b,includeIdAndTitle:o,propertyNamespace:y,onError:w,showErrors:F||A.submitCount>0,existing:s,autoUpdateId:n,inArray:p,autoOpenTypeSelect:l,disabled:V,getData:I,allowDataInference:S,propertyConfigs:N,collectionEditable:m,...A})})},(r,a)=>r.getData===a.getData&&r.propertyKey===a.propertyKey&&r.propertyNamespace===a.propertyNamespace&&r.includeIdAndName===a.includeIdAndName&&r.autoOpenTypeSelect===a.autoOpenTypeSelect&&r.autoUpdateId===a.autoUpdateId&&r.existingProperty===a.existingProperty);function ie({open:r,onCancel:a,onOkClicked:o,onPropertyChanged:l,getData:s,collectionEditable:n,...p}){const h=C.useRef(),f=y=>{h.current=y};return e.jsx(t.Dialog,{open:r??!1,maxWidth:"xl",fullWidth:!0,children:e.jsxs("form",{noValidate:!0,autoComplete:"off",onSubmit:y=>{y.preventDefault(),y.stopPropagation(),h.current?.handleSubmit(y)},children:[e.jsx(t.DialogContent,{children:e.jsx(Ke,{...p,onPropertyChanged:y=>{l?.(y),o?.()},collectionEditable:n,onPropertyChangedImmediate:!1,getController: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",type:"submit",color:"primary",children:"Ok"})]})]})})}function Er({values:r,errors:a,setValues:o,existing:l,autoUpdateId:s=!1,autoOpenTypeSelect:n,includeIdAndTitle:p,onPropertyChanged:h,onDelete:f,propertyNamespace:y,onError:g,showErrors:d,disabled:v,inArray:b,getData:w,allowDataInference:T,propertyConfigs:F,collectionEditable:S}){const[P,I]=C.useState(n),[N,m]=C.useState(!1),[k,V]=C.useState(r?.dataType?i.getFieldId(r):void 0),z=Object.entries(Ge).concat(Object.entries(F)),L=b?z.filter(([j,$])=>!i.isPropertyBuilder($.property)&&$.property?.dataType!=="array"):z,A=C.useDeferredValue(r),D=C.useRef(null),c=C.useRef(r),x=d&&u.getIn(a,"selectedWidget");C.useEffect(()=>{if(h&&(!p||A.id)){const{id:j,...$}=A;te(A,c.current)||(h({id:j,property:$,namespace:y}),c.current=A)}},[A,p,h,y]),C.useEffect(()=>{r?.id&&g&&g(r?.id,y,a)},[a,g,y,r?.id]);const Y=j=>{V(j),o(Ye(r,j,F)),setTimeout(()=>{D.current?.focus()},0)};let M;return k==="text_field"||k==="multiline"||k==="markdown"||k==="email"?M=e.jsx(Tr,{widgetId:k,disabled:v,showErrors:d}):k==="url"?M=e.jsx(xr,{disabled:v,showErrors:d}):k==="select"||k==="number_select"?M=e.jsx(Ue,{multiselect:!1,allowDataInference:T,updateIds:!l,disabled:v,getData:w,showErrors:d}):k==="multi_select"||k==="multi_number_select"?M=e.jsx(Ue,{multiselect:!0,updateIds:!l,disabled:v,allowDataInference:T,getData:w,showErrors:d}):k==="file_upload"?M=e.jsx(Le,{existing:l,multiple:!1,disabled:v}):k==="multi_file_upload"?M=e.jsx(Le,{existing:l,multiple:!0,disabled:v}):k==="switch"?M=e.jsx(Pr,{disabled:v}):k==="number_input"?M=e.jsx(Nr,{disabled:v}):k==="group"?M=e.jsx(mr,{disabled:v,getData:w,allowDataInference:T,collectionEditable:S,propertyConfigs:F}):k==="block"?M=e.jsx(Ir,{disabled:v,getData:w,allowDataInference:T,collectionEditable:S,propertyConfigs:F}):k==="reference"?M=e.jsx(je,{showErrors:d,existing:l,multiple:!1,disabled:v}):k==="date_time"?M=e.jsx(kr,{disabled:v}):k==="multi_references"?M=e.jsx(je,{showErrors:d,existing:l,multiple:!0,disabled:v}):k==="repeat"?M=e.jsx(br,{showErrors:d,existing:l,getData:w,allowDataInference:T,disabled:v,collectionEditable:S,propertyConfigs:F}):k==="key_value"?M=e.jsx(Or,{disabled:v}):M=null,e.jsxs(e.Fragment,{children:[v&&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:!!x,value:k??"",placeholder:"Select a property widget",open:P,onOpenChange:I,position:"item-aligned",disabled:v,renderValue:j=>{if(!j)return e.jsx("em",{children:"Select a property widget"});const $=j,H=i.DEFAULT_FIELD_CONFIGS[$]??F[$],Z=H.property,fe=Z&&!i.isPropertyBuilder(Z)?i.getFieldConfig(Z,F):void 0,oe=i.isPropertyBuilder(Z)||l&&Z.dataType!==r?.dataType,X=fe?i.mergeDeep(fe,H):H;return e.jsxs("div",{onClick:G=>{oe&&(G.stopPropagation(),G.preventDefault())},className:t.cn("flex items-center",oe?"w-full pointer-events-none opacity-50":""),children:[e.jsx("div",{className:"mr-8",children:e.jsx(i.PropertyConfigBadge,{propertyConfig:X})}),e.jsxs("div",{className:"flex flex-col items-start text-base text-left",children:[e.jsx("div",{children:X.name}),e.jsx(t.Typography,{variant:"caption",color:"disabled",children:oe?"You can only switch to widgets that use the same data type":X.description})]})]})},onValueChange:j=>{Y(j)},children:L.map(([j,$])=>{const H=$.property,Z=l&&!i.isPropertyBuilder(H)&&H.dataType!==r?.dataType;return e.jsx(He,{value:j,optionDisabled:Z,propertyConfig:$,existing:l},j)})}),x&&e.jsx(t.Typography,{variant:"caption",className:"ml-3.5",color:"error",children:"Required"})]}),f&&r?.id&&e.jsx(t.IconButton,{variant:"ghost",className:"m-4",disabled:v,onClick:()=>m(!0),children:e.jsx(t.DeleteIcon,{})})]}),e.jsxs("div",{className:"grid grid-cols-12 gap-y-12 mt-8 mb-8",children:[p&&e.jsx(Cr,{showErrors:d,disabledId:l,isNewProperty:!l,disabled:v,autoUpdateId:s,ref:D}),M,e.jsx("div",{className:"col-span-12",children:e.jsx(Sr,{disabled:v})})]}),f&&e.jsx(i.DeleteConfirmationDialog,{open:N,onAccept:()=>f(r?.id,y),onCancel:()=>m(!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 _r=/^[a-zA-Z_][a-zA-Z0-9_]*$/;function Br(r,a){let o;return r||(o="You must specify an id for the field"),r&&!r.match(_r)&&(o="The id can only contain letters, numbers and underscores (_), and not start with a number"),r&&a&&a.includes(r)&&(o="There is another field with this ID already"),o}function Dr(r){let a;return r||(a="You must specify a title for the field"),a}function Ar(r){return r?(r.slice(0,1).toLowerCase()+r.slice(1)).replace(/([-_ ]){1,}/g," ").split(/[-_ ]/).reduce((a,o)=>a+o[0].toUpperCase()+o.substring(1),""):""}function Mr({collection:r,onOpenChange:a,open:o}){const l=i.useSnackbarController(),s=`import { EntityCollection } from "firecms";
|
|
2
2
|
|
|
3
|
-
const `+(r.name?Mr(r.name):"my")+"Collection:EntityCollection = "+dr.stringify(Ze(r),null," ");return e.jsxs(t.Dialog,{open:o,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(Me.Highlight,{theme:Me.themes.vsDark,code:s,language:"typescript",children:({className:n,style:c,tokens:p,getLineProps:h,getTokenProps:y})=>e.jsx("pre",{style:c,className:"p-4 rounded text-sm",children:p.map((g,d)=>e.jsx("div",{...h({line:g}),children:g.map((v,b)=>e.jsx("span",{...y({token:v})},b))},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:()=>a(!1),children:"Close"})]})]})}function Ze(r){const a=o=>{const l={...o};return delete l.fromBuilder,delete l.resolved,delete l.propertiesOrder,delete l.editable,l.type==="map"?{...l,properties:l.properties.map(a)}: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(([o,l])=>({[o]:a(l)})).reduce((o,l)=>({...o,...l}),{}),subcollections:(r.subcollections??[]).map(Ze)}}function Ur({showErrors:r,isNewCollection:a,propertyErrorsRef:o,onPropertyError:l,setDirty:s,reservedGroups:n,extraIcon:c,getUser:p,getData:h,doCollectionInference:y,propertyConfigs:g,collectionEditable:d}){const{values:v,setFieldValue:b,setFieldError:F,setFieldTouched:T,errors:N,dirty:S}=u.useFormex(),P=f.useSnackbarController(),I=f.useLargeLayout(),w=!I,[m,k]=C.useState(),[V,z]=C.useState(),[L,A]=C.useState(),D=V?Z(V,L):void 0,i=D?u.getIn(v.properties,D.replaceAll(".",".properties.")):void 0,[x,Y]=C.useState(!1),[M,j]=C.useState(!1),[$,H]=C.useState(!1),[J,ge]=C.useState([]),oe=C.useRef(v.propertiesOrder?{"":v.propertiesOrder}:{});C.useEffect(()=>{s&&s(S)},[S]);const R=y?()=>{y&&(j(!0),y(v).then(E=>{if(E&&f.makePropertiesEditable(E.properties),!E){P.open({type:"error",message:"Could not infer properties from data"});return}const q=(E.properties?Object.keys(E.properties):[]).filter(B=>!v.properties[B]);if(q.length===0){P.open({type:"info",message:"No new properties found in existing data"});return}const O={...q.reduce((B,W)=>(B[W]=(E.properties??{})[W],B),{}),...v.properties},_=[...q,...v.propertiesOrder??[]];b("properties",O,!1),ne(_),ge(q)}).finally(()=>{j(!1)}))}:void 0,K=C.useCallback(E=>E?oe.current[E]??u.getIn(v,ee(E)):oe.current[""],[v]),ne=C.useCallback((E,q)=>{const O=ee(q);b(O,E,!1),oe.current[q??""]=E},[b]),ce=C.useCallback((E,q)=>{const O=E?Z(E,q):void 0;if(!O)throw Error("collection editor miss config");b(X(O),void 0,!1);const B=K(q).filter(W=>W!==E);ne(B,q),H(!1),k(void 0),z(void 0),A(void 0)},[K,b,ne]),Pe=(E,q)=>{b(ee(q),E,!1)},Be=({id:E,property:q})=>{if(!E)throw Error("Need to include an ID when creating a new property");b("properties",{...v.properties??{},[E]:q},!1);const O=[...v.propertiesOrder??Object.keys(v.properties),E];ne(O),H(!1),I&&(k(O.indexOf(E)),z(E)),A(void 0)},se=({id:E,property:q,previousId:O,namespace:_})=>{const B=E?Z(E,_):void 0,W=B?X(B):void 0;if(O&&O!==E){console.debug("onPropertyChanged, id change",{id:E,property:q,previousId:O,namespace:_});const pe=Z(O,_),nr=X(pe),sr=K(_).map(Se=>Se===O?E:Se).filter(Se=>Se!==void 0);ne(sr,_),E&&(k(sr.indexOf(E)),z(E)),b(nr,void 0,!1),T(nr,!1,!1)}console.debug("onPropertyChanged",{id:E,property:q,previousId:O,namespace:_,propertyPath:W}),W&&(b(W,q,!1),T(W,!0,!1))},Ie=C.useCallback((E,q,O)=>{const _=E?Z(E,q):void 0;if(console.debug("onPropertyErrorInternal",{id:E,namespace:q,error:O,propertyPath:_}),_){const B=O&&Object.keys(O).length>0;l(E,q,B?O:void 0),F(X(_),B?"Property error":void 0)}},[]),Ne=()=>{k(void 0),z(void 0)},we=V&&o?.current?.properties?o.current.properties[V]:void 0,Fe=v?.propertiesOrder===void 0||v.propertiesOrder.length===0,ye=v.propertiesOrder?v.propertiesOrder:Object.keys(v.properties),ke=C.useMemo(()=>p(v.ownerId),[p,v.ownerId]),De=C.useCallback((E,q)=>{console.debug("CollectionEditor: onPropertyClick",{propertyKey:E,namespace:q}),k(ye.indexOf(E)),z(E),A(q)},[ye]),Ae=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",!w&&"border-r "+t.defaultBorderMixin),children:[e.jsxs("div",{className:"flex my-2",children:[e.jsxs("div",{className:"flex-grow mb-4",children:[e.jsx(u.Field,{name:"name",as:t.DebouncedTextField,invisible:!0,className:"-ml-1",inputClassName:"text-2xl font-headers",placeholder:"Collection name",size:"small",required:!0,error:!!N?.name}),ke&&e.jsxs(t.Typography,{variant:"body2",className:"ml-2",color:"secondary",children:["Created by ",ke.displayName]})]}),c&&e.jsx("div",{className:"ml-4",children:c}),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:M,onClick:()=>Y(!0),children:e.jsx(t.CodeIcon,{})})}),R&&e.jsx(t.Tooltip,{title:"Add new properties based on data",children:e.jsx(t.IconButton,{variant:"filled",disabled:M,onClick:R,children:M?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:()=>H(!0),children:e.jsx(t.AddIcon,{})})})]})]}),e.jsx(f.ErrorBoundary,{children:e.jsx(be,{className:"pl-8",inferredPropertyKeys:J,selectedPropertyKey:V?Z(V,L):void 0,properties:v.properties,additionalFields:v.additionalFields,propertiesOrder:ye,onPropertyClick:De,onPropertyMove:Pe,onPropertyRemove:a?ce:void 0,collectionEditable:d,errors:N})}),e.jsx(t.Button,{className:"mt-8 w-full",color:"primary",variant:"outlined",size:"large",onClick:()=>H(!0),startIcon:e.jsx(t.AddIcon,{}),children:"Add new property"})]}),!w&&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:[D&&i&&!f.isPropertyBuilder(i)&&e.jsx(We,{inArray:!1,existingProperty:!a,autoUpdateId:!1,allowDataInference:!a,autoOpenTypeSelect:!1,propertyKey:V,propertyNamespace:L,property:i,onPropertyChanged:se,onDelete:ce,onError:Ie,forceShowErrors:r,initialErrors:we,getData:h,propertyConfigs:g,collectionEditable:d},`edit_view_${m}`),!i&&e.jsxs("div",{className:"w-full flex flex-col items-center justify-center h-full gap-4",children:[e.jsx(t.Typography,{variant:"label",className:"",children:Fe?"Now you can add your first property":"Select a property to edit it"}),e.jsxs(t.Button,{variant:"outlined",onClick:()=>H(!0),children:[e.jsx(t.AddIcon,{}),"Add new property"]})]}),i&&f.isPropertyBuilder(i)&&e.jsx(t.Typography,{variant:"label",className:"flex items-center justify-center",children:"This property is defined as a property builder in code"})]})}),w&&e.jsx(de,{inArray:!1,open:m!==void 0,autoUpdateId:!i,allowDataInference:!a,existingProperty:!0,autoOpenTypeSelect:!1,propertyKey:V,propertyNamespace:L,property:i,onPropertyChanged:se,onDelete:ce,onError:Ie,forceShowErrors:r,initialErrors:we,getData:h,propertyConfigs:g,collectionEditable:d,onOkClicked:w?Ne:void 0},`edit_view_${m}`)]});return e.jsxs(e.Fragment,{children:[Ae,e.jsx(de,{inArray:!1,existingProperty:!1,autoOpenTypeSelect:!0,autoUpdateId:!0,forceShowErrors:r,open:$,onCancel:()=>H(!1),onPropertyChanged:Be,getData:h,allowDataInference:!a,propertyConfigs:g,collectionEditable:d,existingPropertyKeys:v.propertiesOrder}),e.jsx(zr,{collection:v,open:x,onOpenChange:Y})]})}function Lr({open:r,handleOk:a,handleCancel:o,body:l,title:s}){return e.jsxs(t.Dialog,{open:r,onOpenChange:n=>n?o():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"}),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:o,autoFocus:!0,children:" Cancel "}),e.jsx(t.Button,{onClick:a,children:" Ok "})]})]})}function qr({open:r,onClose:a}){const{entityViews:o}=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"}),o?.map(l=>e.jsxs(t.Button,{onClick:()=>a(l.key),fullWidth:!0,variant:"text",children:[l.name," (",l.key,")"]},l.key)),(o??[]).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 $r({collection:r,parentCollection:a,configController:o,collectionInference:l,getUser:s,parentCollectionIds:n}){const{entityViews:c}=f.useCustomizationController(),[p,h]=C.useState(),[y,g]=C.useState(!1),[d,v]=C.useState(),[b,F]=C.useState(),{values:T,setFieldValue:N}=u.useFormex(),S=r.subcollections??[],P=T.entityViews?.filter(m=>typeof m=="string").map(m=>f.resolveEntityView(m,c)).filter(Boolean)??[],I=r.entityViews?.filter(m=>typeof m!="string")??[],w=P.length+I.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 ",T.name]}),e.jsxs(t.Paper,{className:"flex flex-col gap-4 p-2 w-full",children:[S&&S.length>0&&e.jsx(t.Table,{children:e.jsx(t.TableBody,{children:S.map(m=>e.jsxs(t.TableRow,{onClick:()=>F({isNewCollection:!1,editedCollectionId:m.id}),children:[e.jsx(t.TableCell,{align:"left",children:e.jsx(t.Typography,{variant:"subtitle2",className:"flex-grow",children:m.name})}),e.jsx(t.TableCell,{align:"right",children:e.jsx(t.Tooltip,{title:"Remove",children:e.jsx(t.IconButton,{size:"small",onClick:k=>{k.preventDefault(),k.stopPropagation(),h(m.id)},color:"inherit",children:e.jsx(t.DeleteIcon,{size:"small"})})})})]},m.path))})}),e.jsx(t.Button,{onClick:()=>{F({isNewCollection:!0})},variant:"text",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"}),w===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 them with the CLI."}),e.jsx(e.Fragment,{children:e.jsxs(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(m=>e.jsxs(t.TableRow,{children:[e.jsx(t.TableCell,{align:"left",children:e.jsx(t.Typography,{variant:"subtitle2",className:"flex-grow",children:m.name})}),e.jsx(t.TableCell,{align:"right",children:e.jsx(t.Tooltip,{title:"Remove",children:e.jsx(t.IconButton,{size:"small",onClick:k=>{k.preventDefault(),k.stopPropagation(),v(m.key)},color:"inherit",children:e.jsx(t.DeleteIcon,{size:"small"})})})})]},m.key)),I.map(m=>e.jsx(t.TableRow,{children:e.jsxs(t.TableCell,{align:"left",children:[e.jsx(t.Typography,{variant:"subtitle2",className:"flex-grow",children:m.name}),e.jsxs(t.Typography,{variant:"caption",className:"flex-grow",children:["This view is defined in code with key ",e.jsx("code",{children:m.key})]})]})},m.key))]})}),e.jsx(t.Button,{onClick:()=>{g(!0)},variant:"text",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 m={id:p,parentCollectionIds:[...n??[],r.id]};console.debug("Deleting subcollection",m),o.deleteCollection(m),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:()=>{N("entityViews",T.entityViews?.filter(m=>m!==d)),v(void 0)},onCancel:()=>v(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(rr,{open:!!b,configController:o,parentCollection:r,collectionInference:l,parentCollectionIds:[...n??[],T.id],isNewCollection:!1,...b,getUser:s,handleClose:()=>{F(void 0)}}),e.jsx(qr,{open:y,onClose:m=>{m&&N("entityViews",[...T.entityViews??[],m]),g(!1)}})]})}const Je={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"}})},Qe={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"]}},Xe={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"}})},Re={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 jr({path:r,pathSuggestions:a,parentCollection:o,onContinue:l,existingCollectionPaths:s}){const[n,c]=C.useState(!1),[p,h]=C.useState();C.useEffect(()=>{a&&s&&(c(!0),a(r).then(b=>{const F=b.filter(T=>!(s??[]).find(N=>N.trim().toLowerCase()===T.trim().toLowerCase()));h(F)}).finally(()=>c(!1)))},[s,r,a]);const{values:y,setFieldValue:g,setValues:d,submitCount:v}=u.useFormex();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"})}),o&&e.jsx(t.Chip,{colorScheme:"tealDarker",children:e.jsxs(t.Typography,{variant:"caption",children:["This is a subcollection of ",e.jsx("b",{children:o.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((b,F)=>e.jsx(t.Chip,{colorScheme:"cyanLighter",onClick:()=>{g("name",f.unslugify(b)),g("id",b),g("path",b),g("properties",void 0),l()},size:"small",children:b},b)),!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(Ce,{title:"Products",subtitle:"A collection of products with images, prices and stock",icon:e.jsx(t.Icon,{size:"small",iconKey:Je.icon}),onClick:()=>{d(Je),l()}}),e.jsx(Ce,{title:"Users",subtitle:"A collection of users with emails, names and roles",icon:e.jsx(t.Icon,{size:"small",iconKey:Xe.icon}),onClick:()=>{d(Xe),l()}}),e.jsx(Ce,{title:"Blog posts",subtitle:"A collection of blog posts with images, authors and complex content",icon:e.jsx(t.Icon,{size:"small",iconKey:Qe.icon}),onClick:()=>{d(Qe),l()}}),e.jsx(Ce,{title:"Pages",subtitle:"A collection of pages with images, authors and complex content",icon:e.jsx(t.Icon,{size:"small",iconKey:Re.icon}),onClick:()=>{d(Re),l()}})]})]}),!o&&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:b=>l(b)})]}),e.jsx("div",{children:e.jsx(t.Button,{variant:"text",onClick:()=>l(),className:"my-2",children:"Continue from scratch"})})]})})}function Ce({title:r,subtitle:a,icon:o,onClick:l}){return e.jsx(t.Tooltip,{title:a,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:[o,e.jsx("div",{className:"flex flex-col items-start",children:e.jsx(t.Typography,{variant:"subtitle1",children:r})})]})})}function Yr({importConfig:r,propertyConfigs:a,collectionEditable:o}){const{setFieldValue:l,setFieldTouched:s,values:n}=u.useFormex(),[c,p]=C.useState(void 0),h=C.useRef(n.propertiesOrder?{"":n.propertiesOrder}:{}),y=c?c.id:void 0,g=c||void 0,d=({id:b,property:F,previousId:T,namespace:N})=>{const S=b?Z(b,N):void 0,P=S?X(S):void 0,I=m=>m?h.current[m]??u.getIn(n,ee(m)):h.current[""],w=(m,k)=>{const V=ee(k);l(V,m,!1),h.current[k??""]=m};if(T&&T!==b){const m=Z(T,N),k=X(m),z=I(N).map(A=>A===T?b:A).filter(A=>A!==void 0);w(z,N);const L={...r.headersMapping};Object.keys(L).forEach(A=>{L[A]===T&&(L[A]=b??"")}),r.setHeadersMapping(L),l(k,void 0,!1),s(k,!1,!1)}P&&(l(P,F,!1),s(P,!0,!1))},v=async({id:b,importKey:F,property:T,namespace:N})=>{const S=b?Z(b,N):void 0,P=S?X(S):void 0,I=r.importData.map(m=>u.getIn(m,F)),w={...Oe.buildPropertyFromData(I,T,ae.getInferenceType),editable:!0};P&&(w?l(P,w,!1):l(P,T,!1),s(P,!0,!1))};return e.jsxs("div",{className:"overflow-auto my-auto",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:b=>r.setIdColumn(b),buildPropertyView:({property:b,propertyKey:F,importKey:T})=>e.jsx(ae.ImportNewPropertyFieldPreview,{property:b,propertyKey:F,onPropertyNameChanged:(N,S)=>l(`properties.${N}.name`,S,!1),onEditClick:()=>{!F||!b||p({...b,id:F,editable:!0})},propertyTypeView:e.jsx(Hr,{property:b,disabled:!1,onPropertyChanged:N=>v({...N,importKey:T}),propertyKey:F,propertyConfigs:a})})})]}),e.jsx(de,{open:c!==void 0,propertyKey:y,property:g,inArray:!1,autoUpdateId:!1,onPropertyChanged:d,allowDataInference:!1,collectionEditable:o,onOkClicked:()=>{p(void 0)},onCancel:()=>{p(void 0)},autoOpenTypeSelect:!1,existingProperty:!1,propertyConfigs:a}),e.jsx("div",{style:{height:"52px"}})]})}function Hr({property:r,onPropertyChanged:a,propertyKey:o,propertyConfigs:l,disabled:s}){const n=r?f.getFieldId(r):null,c=r?f.getFieldConfig(r,l):null,[p,h]=C.useState(!1);return e.jsx(t.Tooltip,{title:r&&c?`${c?.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:!c,value:n??"",placeholder:"Select a property widget",position:"item-aligned",renderValue:y=>c?e.jsx(f.PropertyConfigBadge,{propertyConfig:c}):null,onValueChange:y=>{const g=He(r,y,l);o&&a({id:o,property:g,previousId:o,namespace:void 0})},children:Object.entries(Ke).map(([y,g])=>e.jsx(Ge,{value:y,optionDisabled:!1,propertyConfig:g,existing:!1},y))})})}function Gr({importConfig:r,properties:a,propertiesOrder:o}){C.useEffect(()=>{const s=ae.getPropertiesMapping(r.originProperties,a),n=r.importData.map(c=>ae.convertDataToEntity(c,r.idColumn,r.headersMapping,a,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:o.map(s=>({key:s,disabled:!1})),properties:a})}function er(r,a=""){const o=Object.keys(r).reduce((n,c)=>{const p=r[c],h=f.slugify(c),y=a?`${a}.${h}`:h;if(p.dataType==="map"&&p.properties){const v=er(p.properties,y);return{headersMapping:{...n.headersMapping,[c]:y},properties:{...n.properties,[h]:{...p,properties:v.properties,propertiesOrder:Object.keys(v.properties)}}}}const g={...n.properties,[h]:p};return{headersMapping:{...n.headersMapping,[c]:y},properties:g}},{headersMapping:{},properties:{}}),l=Object.keys(o.headersMapping)?.[0];let s;return(l?.includes("id")||l?.includes("key"))&&(s=l),{...o,idColumn:s}}function rr(r){const a=r.open,[o,l]=ue.useState(!1),[s,n]=ue.useState(!1),c=C.useCallback(()=>{o?n(!0):r.handleClose(void 0)},[o,r.handleClose]);return C.useEffect(()=>{a||(l(!1),n(!1))},[a]),e.jsxs(t.Dialog,{open:a,fullWidth:!0,fullHeight:!0,scrollable:!1,maxWidth:"7xl",onOpenChange:p=>p?void 0:c(),children:[a&&e.jsx(Kr,{...r,handleCancel:c,setFormDirty:l}),e.jsx(Lr,{open:s,handleOk:()=>r.handleClose(void 0),handleCancel:()=>n(!1),body:"There are unsaved changes in this collection"})]})}function Kr(r){const{propertyConfigs:a}=f.useCustomizationController(),o=f.useNavigationController(),l=f.useAuthController(),{topLevelNavigation:s,collections:n}=o,c=r.initialValues,p=!c?.path&&(r.parentCollectionIds??[]).length===0,h=(r.parentCollection?r.parentCollection.subcollections:n)??[],y=h.map(P=>P.path.trim().toLowerCase()),g=h.map(P=>P.id?.trim().toLowerCase()).filter(Boolean),[d,v]=ue.useState(),[b,F]=ue.useState(!1);if(C.useEffect(()=>{try{o.initialised&&(r.editedCollectionId?v(o.getCollectionFromPaths([...r.parentCollectionIds??[],r.editedCollectionId])):v(void 0),F(!0))}catch(P){console.error(P)}},[o.getCollectionFromPaths,r.editedCollectionId,r.parentCollectionIds,o.initialised]),!s)throw Error("Internal: Navigation not ready in collection editor");const{groups:T}=s,N=d?{...d,id:d.id??d.path??f.randomString(16)}:void 0,S=N?Zr(N,a):{id:c?.path??f.randomString(16),path:c?.path??"",name:c?.name??"",group:c?.group??"",properties:{},propertiesOrder:[],icon:t.coolIconKeys[Math.floor(Math.random()*t.coolIconKeys.length)],ownerId:l.user?.uid??""};return b?!r.isNewCollection&&(!o.initialised||!b)?e.jsx(f.CircularProgressCenter,{}):e.jsx(Wr,{...r,initialValues:S,existingPaths:y,existingIds:g,includeTemplates:p,collection:d,setCollection:v,groups:T,propertyConfigs:a}):e.jsx(f.CircularProgressCenter,{})}function Wr({isNewCollection:r,configController:a,editedCollectionId:o,parentCollectionIds:l,fullPath:s,collectionInference:n,handleClose:c,reservedGroups:p,extraView:h,handleCancel:y,setFormDirty:g,pathSuggestions:d,getUser:v,parentCollection:b,getData:F,existingPaths:T,existingIds:N,includeTemplates:S,collection:P,setCollection:I,initialValues:w,propertyConfigs:m,groups:k}){const V=ae.useImportConfig(),z=f.useNavigationController(),L=f.useSnackbarController(),A=C.useRef({}),D=r?S?"welcome":"details":"properties",[i,x]=C.useState(D),[Y,M]=ue.useState(),j=O=>{const _=O.id||O.path;return a.saveCollection({id:_,collectionData:O,previousId:o,parentCollectionIds:l}).then(()=>(M(void 0),!0)).catch(B=>(M(B),console.error(B),L.open({type:"error",message:"Error persisting collection: "+(B.message??"Details in the console")}),!1))},$=C.useCallback(()=>{i==="details"?V.inUse?x("import_data_saving"):x(h?"extra_view":"properties"):x(i==="welcome"?"details":i==="import_data_mapping"?"import_data_preview":i==="import_data_preview"?"details":i==="extra_view"?"properties":"details")},[i,V.inUse,h]),H=C.useCallback(O=>{if(n)return n?.(O.path,O.collectionGroup??!1,l??[])},[n,l]),J=C.useCallback(async O=>{try{if(!H)return I(O),Promise.resolve(O);x("loading");const _=await H?.(O);if(!_)return I(O),Promise.resolve(O);const B={...O??{}};return Object.keys(_.properties??{}).length>0&&(B.properties=_.properties,B.propertiesOrder=_.propertiesOrder),B.propertiesOrder?(I(B),console.debug("Inferred collection",{newCollection:O??{},values:B}),B):(B.propertiesOrder=Object.keys(B.properties),B)}catch(_){return console.error(_),L.open({type:"error",message:"Error inferring collection: "+(_.message??"Details in the console")}),O}},[l,H]),ge=(O,_)=>{console.log("Submitting collection",O);try{if(!r){j(O).then(()=>{_.resetForm({values:w}),c(O)});return}i==="welcome"?($(),_.resetForm({values:O})):i==="details"?h||V.inUse?(_.resetForm({values:O}),$()):r?J(O).then(B=>{_.resetForm({values:B??O,touched:{path:!0,name:!0}})}).finally(()=>{$()}):(_.resetForm({values:O}),$()):i==="extra_view"?($(),_.resetForm({values:O})):i==="import_data_mapping"||i==="import_data_preview"?$():i==="properties"?j(O).then(()=>{_.resetForm({values:w}),$(),c(O)}):($(),_.resetForm({values:O}))}catch(B){L.open({type:"error",message:"Error persisting collection: "+(B.message??"Details in the console")}),console.error(B),_.resetForm({values:O})}},oe=O=>{let _={};const B=(i==="properties"||i==="subcollections"||i==="details")&≺if(B)try{B.validateSync(O,{abortEarly:!1})}catch(W){W.inner.forEach(pe=>{_[pe.path]=pe.message})}if(i==="properties"&&(_={..._,...A.current}),i==="details"){const W=ar(O.path,r,T,O.id);W&&(_.path=W);const pe=Jr(O.id,r,T,N);pe&&(_.id=pe)}return _},R=u.useCreateFormex({initialValues:w,onSubmit:ge,validation:oe}),{values:K,setFieldValue:ne,isSubmitting:ce,dirty:Pe,submitCount:Be}=R,se=K.path??o,Ie=s?.includes("/")?s?.split("/").slice(0,-1).join("/")+"/"+se:se,Ne=ar(se,r,T,K.id),we=!Ne&&l?z.convertIdsToPaths(l):void 0,Fe=Ne?void 0:z.resolveAliasesFrom(Ie),ye=Fe&&F?()=>F(Fe,we??[]):void 0;C.useEffect(()=>{g(Pe)},[Pe]);function ke(O){V.setInUse(!0),Oe.buildEntityPropertiesFromData(O,ae.getInferenceType).then(_=>{const B=er(_);ne("properties",B.properties),ne("propertiesOrder",Object.keys(B.properties)),V.setIdColumn(B.idColumn),V.setImportData(O),V.setHeadersMapping(B.headersMapping),V.setOriginProperties(B.properties)})}const De=!!K.name&&!!K.id,Ae=()=>{const O={...K.properties};V.idColumn&&delete O[V.idColumn],ne("properties",O),$()},q=P?.editable===void 0||P?.editable===!0||r;return e.jsx(t.DialogContent,{fullHeight:!0,children:e.jsx(u.Formex,{value:R,children: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:O=>x(O),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:R.handleSubmit,className:t.cn(r?"h-full":"h-[calc(100%-48px)]","flex-grow flex flex-col relative"),children:[i==="loading"&&e.jsx(f.CircularProgressCenter,{}),i==="extra_view"&&se&&h?.View&&e.jsx(h.View,{path:se}),i==="welcome"&&e.jsx(jr,{path:se,onContinue:O=>{O?(ke(O),x("import_data_mapping")):x("details")},existingCollectionPaths:T,parentCollection:b,pathSuggestions:d}),i==="import_data_mapping"&&V&&e.jsx(Yr,{importConfig:V,collectionEditable:q,propertyConfigs:m}),i==="import_data_preview"&&V&&e.jsx(Gr,{importConfig:V,properties:K.properties,propertiesOrder:K.propertiesOrder}),i==="import_data_saving"&&V&&e.jsx(ae.ImportSaveInProgress,{importConfig:V,collection:K,onImportSuccess:async O=>{L.open({type:"info",message:"Data imported successfully"}),await j(K),c(O)}}),i==="details"&&e.jsx(hr,{existingPaths:T,existingIds:N,groups:k,parentCollectionIds:l,parentCollection:b,isNewCollection:r}),i==="subcollections"&&P&&e.jsx($r,{parentCollection:b,configController:a,getUser:v,collectionInference:n,parentCollectionIds:l,collection:P}),i==="properties"&&e.jsx(Ur,{showErrors:Be>0,isNewCollection:r,reservedGroups:p,onPropertyError:(O,_,B)=>{const W=f.removeUndefined({...A.current,[Ve(O,_)]:f.removeUndefined(B,!0)},!0);A.current=W,R.validate()},getUser:v,getData:ye,doCollectionInference:H,propertyConfigs:m,collectionEditable:q,extraIcon:h?.icon&&e.jsx(t.IconButton,{color:"primary",onClick:()=>x("extra_view"),children:h.icon})}),i!=="welcome"&&e.jsxs(t.DialogActions,{position:"absolute",children:[Y&&e.jsx(f.ErrorView,{error:Y}),r&&S&&i==="import_data_mapping"&&e.jsxs(t.Button,{variant:"text",type:"button",onClick:()=>(V.setInUse(!1),x("welcome")),children:[e.jsx(t.ArrowBackIcon,{}),"Back"]}),r&&S&&i==="import_data_preview"&&e.jsxs(t.Button,{variant:"text",type:"button",onClick:()=>{x("import_data_mapping")},children:[e.jsx(t.ArrowBackIcon,{}),"Back"]}),r&&S&&i==="details"&&e.jsxs(t.Button,{variant:"text",type:"button",onClick:()=>x("welcome"),children:[e.jsx(t.ArrowBackIcon,{}),"Back"]}),r&&i==="properties"&&e.jsxs(t.Button,{variant:"text",type:"button",onClick:()=>x("details"),children:[e.jsx(t.ArrowBackIcon,{}),"Back"]}),e.jsx(t.Button,{variant:"text",onClick:()=>{y()},children:"Cancel"}),r&&i==="import_data_mapping"&&e.jsx(t.Button,{variant:"filled",color:"primary",onClick:Ae,children:"Next"}),r&&i==="import_data_preview"&&e.jsx(t.Button,{variant:"filled",color:"primary",onClick:()=>{$()},children:"Next"}),r&&(i==="details"||i==="properties")&&e.jsxs(t.LoadingButton,{variant:"filled",color:"primary",type:"submit",loading:ce,disabled:ce||i==="details"&&!De,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:ce,children:"Update collection"})]})]})]})})})}function Zr(r,a){const{properties:o,...l}=r,s={};return Object.keys(o).forEach(n=>{s[n]=tr(o[n],a)}),{...l,properties:s}}function tr(r,a){let o=r;if(a&&typeof o=="object"&&o.propertyConfig){const l=a[o.propertyConfig];if(l&&f.isPropertyBuilder(l.property))o=l.property;else if(l&&(o=f.mergeDeep(l.property,o)),!f.isPropertyBuilder(o)&&o.dataType==="map"&&o.properties){const s={};Object.keys(o.properties).forEach(n=>{s[n]=tr(o.properties[n],a)}),o={...o,properties:s}}}return o}const ar=(r,a,o,l)=>{let s;return r||(s="You must specify a path in the database for this collection"),a&&o?.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},Jr=(r,a,o,l)=>{if(!r)return;let s;return a&&o?.includes(r.trim().toLowerCase())&&(s="There is already a collection that uses this value as a path"),a&&l?.includes(r.trim().toLowerCase())&&(s="There is already a collection which uses this id"),s},lr=C.createContext({}),or=C.createContext({}),Qr=C.memo(function({children:a,collectionConfigController:o,configPermissions:l,reservedGroups:s,collectionInference:n,extraView:c,pathSuggestions:p,getUser:h,getData:y,onAnalyticsEvent:g}){const d=f.useNavigationController(),v=cr.useNavigate(),b=f.useSnackbarController(),{propertyConfigs:F}=f.useCustomizationController(),{collections:T}=d,N=(T??[]).map(i=>i.path.trim().toLowerCase()),[S,P]=C.useState();C.useEffect(()=>{p&&p().then(i=>{P(i.filter(x=>!N.includes(x.trim().toLowerCase())))})},[p]);const[I,w]=C.useState(),[m,k]=C.useState(),V=C.useCallback(()=>({createCollections:!0,editCollections:!0,deleteCollections:!0}),[]),z=C.useCallback(({id:i,fullPath:x,parentCollectionIds:Y,parentCollection:M})=>{console.debug("Edit collection",i,x,Y,M),g?.("edit_collection",{id:i,fullPath:x}),w({editedCollectionId:i,fullPath:x,parentCollectionIds:Y,isNewCollection:!1,parentCollection:M,redirect:!1})},[]),L=C.useCallback(({propertyKey:i,property:x,editedCollectionId:Y,currentPropertiesOrder:M,parentCollectionIds:j,collection:$})=>{console.debug("edit property",i,x,Y,M,j,$),g?.("edit_property",{propertyKey:i,editedCollectionId:Y});const H=i&&i.includes(".")?i.substring(0,i.lastIndexOf(".")):void 0,J=i&&i.includes(".")?i.substring(i.lastIndexOf(".")+1):i;k({propertyKey:J,property:x,namespace:H,currentPropertiesOrder:M,editedCollectionId:Y,parentCollectionIds:j,collectionEditable:$?.editable??!1})},[]),A=C.useCallback(({parentCollectionIds:i,parentCollection:x,initialValues:Y,redirect:M,sourceClick:j})=>{console.debug("Create collection",{parentCollectionIds:i,parentCollection:x,initialValues:Y,redirect:M,sourceClick:j}),g?.("create_collection",{parentCollectionIds:i,parentCollection:x,initialValues:Y,redirect:M,sourceClick:j}),w({isNewCollection:!0,parentCollectionIds:i,parentCollection:x,initialValues:Y,redirect:M})},[]),D=p?i=>!i&&S?Promise.resolve(S):p?.(i):void 0;return e.jsx(lr.Provider,{value:o,children:e.jsxs(or.Provider,{value:{editCollection:z,createCollection:A,editProperty:L,configPermissions:l??V,rootPathSuggestions:S},children:[a,e.jsx(rr,{open:!!I,configController:o,isNewCollection:!1,collectionInference:n,...I,getData:y,reservedGroups:s,extraView:c,pathSuggestions:D,getUser:h,handleClose:i=>{if(I?.redirect&&i&&I?.isNewCollection&&!I.parentCollectionIds.length){const x=d.buildUrlCollectionPath(i.id??i.path);v(x)}w(void 0)}}),e.jsx(de,{open:!!m,includeIdAndName:!0,existingProperty:!!m?.propertyKey,autoUpdateId:m?!m?.propertyKey:!1,autoOpenTypeSelect:m?!m?.propertyKey:!1,inArray:!1,collectionEditable:m?.collectionEditable??!1,getData:y&&m?.editedCollectionId?()=>{console.debug("get data for property",m?.editedCollectionId);const i=d.resolveAliasesFrom(m.editedCollectionId);return y(i,[])}:void 0,onPropertyChanged:({id:i,property:x})=>{if(!m||!i)return;const Y=!m.propertyKey;return o.saveProperty({path:m?.editedCollectionId,property:x,propertyKey:i,newPropertiesOrder:Y&&m.currentPropertiesOrder?[...m.currentPropertiesOrder,i]:void 0,namespace:m.namespace,parentCollectionIds:m.parentCollectionIds}).catch(M=>(console.error(M),b.open({type:"error",message:"Error persisting property: "+(M.message??"Details in the console")}),!1))},onPropertyChangedImmediate:!1,onDelete:()=>{if(!m?.propertyKey)return;const i=m?.currentPropertiesOrder?.filter(x=>x!==m?.propertyKey);return o.deleteProperty({path:m?.editedCollectionId,propertyKey:m?.propertyKey,namespace:m?.namespace,newPropertiesOrder:i,parentCollectionIds:m?.parentCollectionIds}).then(()=>{k(void 0)}).catch(x=>(console.error(x),b.open({type:"error",message:"Error deleting property: "+(x.message??"Details in the console")}),!1))},onError:()=>{},onOkClicked:()=>{k(void 0)},onCancel:()=>{k(void 0)},initialErrors:{},forceShowErrors:!1,existingPropertyKeys:[],allowDataInference:!0,propertyConfigs:F,property:m?.property,propertyKey:m?.propertyKey})]})})},te),re=()=>C.useContext(or),_e=()=>C.useContext(lr);function Xr({path:r,parentCollectionIds:a,collection:o,tableController:l}){const s=f.useAuthController(),n=f.useNavigationController(),c=re(),p=_e(),h=f.useSnackbarController(),y=n.getCollectionFromIds(a),g=c.configPermissions?c.configPermissions({user:s.user,collection:o}).editCollections:!0;let d=null;(!te(Te(l.filterValues),Te(o.initialFilter))||!te(Te(l.sortBy),Te(o.initialSort)))&&(d=e.jsxs(e.Fragment,{children:[(o.initialFilter||o.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?.(),o?.initialFilter&&l.setFilterValues?.(o?.initialFilter),o?.initialSort&&l.setSortBy?.(o?.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:o.id,parentCollectionIds:a,collectionData:f.mergeDeep(o,{initialFilter:l.filterValues??null,initialSort:l.sortBy??null})}).then(()=>{h.open({type:"success",message:"Default config saved"})}),children:e.jsx(t.SaveIcon,{})})})]}));const v=e.jsx(t.Tooltip,{title:g?"Edit collection":"You don't have permissions to edit this collection",children:e.jsx(t.IconButton,{color:"primary",disabled:!g,onClick:g?()=>c?.editCollection({id:o.id,fullPath:r,parentCollectionIds:a,parentCollection:y}):void 0,children:e.jsx(t.SettingsIcon,{})})});return e.jsxs(e.Fragment,{children:[g&&d,v]})}function Te(r){return r&&Object.keys(r).length===0?r:r??null}function Rr({path:r,collection:a}){const o=f.useSnackbarController(),l=f.useAuthController(),s=_e(),n=re(),c=n.configPermissions({user:l.user,collection:a}),p=C.useCallback(()=>{n?.editCollection({id:a.id,parentCollectionIds:[]})},[n,r]),[h,y]=C.useState(!1),g=C.useCallback(()=>{s?.deleteCollection({id:a.id}).then(()=>{y(!1),o.open({message:"Collection deleted",type:"success"})})},[r,s]);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[c.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(),y(!0)},children:[e.jsx(t.DeleteIcon,{}),"Delete"]})}),c.editCollections&&e.jsx(t.IconButton,{onClick:d=>{p()},children:e.jsx(t.SettingsIcon,{size:"small"})})]}),e.jsx(f.DeleteConfirmationDialog,{open:h,onAccept:g,onCancel:()=>y(!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 et({group:r,context:a}){if(!a.navigation.topLevelNavigation)throw Error("Navigation not ready in FireCMSHomePage");const o=f.useAuthController(),l=re(),s=l.configPermissions?l.configPermissions({user:o.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 rt({introMode:r}){const a=f.useAuthController(),o=f.useNavigationController(),l=re(),s=l.configPermissions?l.configPermissions({user:a.user}).createCollections:!0,n=l.rootPathSuggestions,c=(n??[]).length>3||(o.collections??[]).length===0&&(n??[]).length>0,p=r==="existing_project";return e.jsx(t.Collapse,{in:p||c,children:e.jsxs("div",{className:"flex flex-col gap-1 p-2 my-4",children:[!r&&e.jsxs(t.Typography,{variant:"body2",color:"secondary",children:["Create a collection ",e.jsx("b",{children:"automatically"})," from your data:"]}),r==="existing_project"&&e.jsxs(t.Typography,{children:["You will see your ",e.jsx("b",{children:"database collections"})," here, a few seconds after project creation"]}),e.jsxs("div",{className:"flex flex-row gap-1 overflow-scroll no-scrollbar ",children:[(n??[]).map(h=>e.jsx("div",{children:e.jsx(t.Chip,{icon:e.jsx(t.AddIcon,{size:"small"}),colorScheme:"cyanLighter",onClick:l&&s?()=>l.createCollection({initialValues:{path:h,name:f.unslugify(h)},parentCollectionIds:[],redirect:!0,sourceClick:"root_collection_suggestion"}):void 0,size:"small",children:h})},h)),n===void 0&&e.jsx(t.CircularProgress,{size:"small"}),n?.length===0&&e.jsx(t.Typography,{variant:"caption",children:"No suggestions"})]})]})})}function tt({propertyKey:r,onHover:a,property:o,fullPath:l,parentCollectionIds:s,collection:n}){const c=re();return e.jsx(t.Tooltip,{title:"Edit",children:e.jsx(t.IconButton,{className:a?"bg-white dark:bg-gray-950":"hidden",onClick:()=>{c.editProperty({propertyKey:r,property:o,editedCollectionId:n.id,parentCollectionIds:s,collection:n})},size:"small",children:e.jsx(t.SettingsIcon,{size:"small"})})})}function at({fullPath:r,parentCollectionIds:a,collection:o}){const l=f.useAuthController(),s=re(),n=s.configPermissions?s.configPermissions({user:l.user,collection:o}).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:o.id,parentCollectionIds:a,currentPropertiesOrder:f.getDefaultPropertiesOrder(o),collection:o})},children:e.jsx(t.AddIcon,{color:"inherit"})})})}function lt(){const r=re();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 ot({collectionConfigController:r,introMode:a,configPermissions:o,reservedGroups:l,extraView:s,pathSuggestions:n,getUser:c,collectionInference:p,getData:h,onAnalyticsEvent:y}){return{name:"Collection Editor",loading:r.loading,collections:{CollectionActions:Xr},provider:{Component:Qr,props:{collectionConfigController:r,configPermissions:o,collectionInference:p,reservedGroups:l,extraView:s,pathSuggestions:n,getUser:c,getData:h,onAnalyticsEvent:y}},homePage:{additionalActions:e.jsx(lt,{}),additionalChildrenStart:a?e.jsx(nt,{introMode:a}):void 0,additionalChildrenEnd:e.jsx(rt,{introMode:a}),CollectionActions:Rr,AdditionalCards:a?void 0:et},collectionView:{HeaderAction:tt,AddColumnComponent:at}}}function nt({introMode:r}){if(!f.useNavigationController().topLevelNavigation)throw Error("Navigation not ready in FireCMSHomePage");const o=f.useAuthController(),l=re(),s=l.configPermissions?l.configPermissions({user:o.user}).createCollections:!0;return e.jsxs("div",{className:"mt-8 flex flex-col mt-8 p-2",children:[e.jsx(t.Typography,{variant:"h4",className:"mb-4",children:"Welcome"}),e.jsx(t.Typography,{paragraph:!0,children:"Your admin panel is ready ✌️"}),e.jsx(t.Typography,{paragraph:!0,children:"Start building collections in FireCMS easily. Map them to your existing database data, import from files, or use our templates. Simplify your data management process now."}),s&&e.jsxs(t.Button,{className:"mt-4",onClick:l&&s?()=>l.createCollection({parentCollectionIds:[],redirect:!0,sourceClick:"new_collection_card"}):void 0,children:[e.jsx(t.AddIcon,{}),"Create your first collection"]})]})}function st({path:r}){const a=f.useNavigationController(),o=it(r),l=a.getParentCollectionIds(r),s=re();return e.jsxs("div",{className:"p-1 flex flex-col items-center",children:[e.jsx(f.ErrorView,{error:"No collection for path: "+o}),e.jsx(t.Button,{className:"mx-2",variant:"outlined",size:"small",onClick:()=>{s.createCollection({initialValues:{path:o,name:f.unslugify(o)},parentCollectionIds:l,redirect:!1,sourceClick:"missing_reference"})},children:"Create"})]})}function it(r){const a=r.split("/");return a[a.length-1]}U.MissingReferenceWidget=st,U.editableProperty=fe,U.getFullId=Z,U.getFullIdPath=Ve,U.idToPropertiesPath=X,U.namespaceToPropertiesOrderPath=ee,U.namespaceToPropertiesPath=Ue,U.removeNonEditableProperties=$e,U.useCollectionEditorController=re,U.useCollectionEditorPlugin=ot,U.useCollectionsConfigController=_e,Object.defineProperty(U,Symbol.toStringTag,{value:"Module"})});
|
|
3
|
+
const `+(r.name?Ar(r.name):"my")+"Collection:EntityCollection = "+ir.stringify(We(r),null," ");return e.jsxs(t.Dialog,{open:o,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(Ae.Highlight,{theme:Ae.themes.vsDark,code:s,language:"typescript",children:({className:n,style:p,tokens:h,getLineProps:f,getTokenProps:y})=>e.jsx("pre",{style:p,className:"p-4 rounded text-sm",children:h.map((g,d)=>e.jsx("div",{...f({line:g}),children:g.map((v,b)=>e.jsx("span",{...y({token:v})},b))},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:()=>a(!1),children:"Close"})]})]})}function We(r){const a=o=>{const l={...o};return delete l.fromBuilder,delete l.resolved,delete l.propertiesOrder,delete l.editable,l.type==="map"?{...l,properties:l.properties.map(a)}: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(([o,l])=>({[o]:a(l)})).reduce((o,l)=>({...o,...l}),{}),subcollections:(r.subcollections??[]).map(We)}}function zr({showErrors:r,isNewCollection:a,propertyErrorsRef:o,onPropertyError:l,setDirty:s,reservedGroups:n,extraIcon:p,getUser:h,getData:f,doCollectionInference:y,propertyConfigs:g,collectionEditable:d}){const{values:v,setFieldValue:b,setFieldError:w,setFieldTouched:T,errors:F,dirty:S}=u.useFormex(),P=i.useSnackbarController(),I=i.useLargeLayout(),N=!I,[m,k]=C.useState(),[V,z]=C.useState(),[L,A]=C.useState(),D=V?W(V,L):void 0,c=D?u.getIn(v.properties,D.replaceAll(".",".properties.")):void 0,[x,Y]=C.useState(!1),[M,j]=C.useState(!1),[$,H]=C.useState(!1),[Z,fe]=C.useState([]),oe=C.useRef(v.propertiesOrder?{"":v.propertiesOrder}:{});C.useEffect(()=>{s&&s(S)},[S]);const X=y?()=>{y&&(j(!0),y(v).then(E=>{if(E&&i.makePropertiesEditable(E.properties),!E){P.open({type:"error",message:"Could not infer properties from data"});return}const q=(E.properties?Object.keys(E.properties):[]).filter(B=>!v.properties[B]);if(q.length===0){P.open({type:"info",message:"No new properties found in existing data"});return}const O={...q.reduce((B,K)=>(B[K]=(E.properties??{})[K],B),{}),...v.properties},_=[...q,...v.propertiesOrder??[]];b("properties",O,!1),ne(_),fe(q)}).finally(()=>{j(!1)}))}:void 0,G=C.useCallback(E=>E?oe.current[E]??u.getIn(v,R(E)):oe.current[""],[v]),ne=C.useCallback((E,q)=>{const O=R(q);b(O,E,!1),oe.current[q??""]=E},[b]),de=C.useCallback((E,q)=>{const O=E?W(E,q):void 0;if(!O)throw Error("collection editor miss config");b(Q(O),void 0,!1);const B=G(q).filter(K=>K!==E);ne(B,q),H(!1),k(void 0),z(void 0),A(void 0)},[G,b,ne]),Te=(E,q)=>{b(R(q),E,!1)},_e=({id:E,property:q})=>{if(!E)throw Error("Need to include an ID when creating a new property");b("properties",{...v.properties??{},[E]:q},!1);const O=[...v.propertiesOrder??Object.keys(v.properties),E];ne(O),H(!1),I&&(k(O.indexOf(E)),z(E)),A(void 0)},re=({id:E,property:q,previousId:O,namespace:_})=>{const B=E?W(E,_):void 0,K=B?Q(B):void 0;if(O&&O!==E){console.debug("onPropertyChanged, id change",{id:E,property:q,previousId:O,namespace:_});const ce=W(O,_),or=Q(ce),nr=G(_).map(ke=>ke===O?E:ke).filter(ke=>ke!==void 0);ne(nr,_),E&&(k(nr.indexOf(E)),z(E)),b(or,void 0,!1),T(or,!1,!1)}console.debug("onPropertyChanged",{id:E,property:q,previousId:O,namespace:_,propertyPath:K}),K&&(b(K,q,!1),T(K,!0,!1))},Pe=C.useCallback((E,q,O)=>{const _=E?W(E,q):void 0;if(console.debug("onPropertyErrorInternal",{id:E,namespace:q,error:O,propertyPath:_}),_){const B=O&&Object.keys(O).length>0;l(E,q,B?O:void 0),w(Q(_),B?"Property error":void 0)}},[]),Ie=()=>{k(void 0),z(void 0)},Fe=V&&o?.current?.properties?o.current.properties[V]:void 0,Ne=v?.propertiesOrder===void 0||v.propertiesOrder.length===0,ue=v.propertiesOrder?v.propertiesOrder:Object.keys(v.properties),we=C.useMemo(()=>v.ownerId?h(v.ownerId):null,[h,v.ownerId]),Be=C.useCallback((E,q)=>{console.debug("CollectionEditor: onPropertyClick",{propertyKey:E,namespace:q}),k(ue.indexOf(E)),z(E),A(q)},[ue]),De=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",!N&&"border-r "+t.defaultBorderMixin),children:[e.jsxs("div",{className:"flex my-2",children:[e.jsxs("div",{className:"flex-grow mb-4",children:[e.jsx(u.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}),we&&e.jsxs(t.Typography,{variant:"body2",className:"ml-2",color:"secondary",children:["Created by ",we.displayName]})]}),p&&e.jsx("div",{className:"ml-4",children:p}),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:M,onClick:()=>Y(!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:M,onClick:X,children:M?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:()=>H(!0),children:e.jsx(t.AddIcon,{})})})]})]}),e.jsx(i.ErrorBoundary,{children:e.jsx(me,{className:"pl-8",inferredPropertyKeys:Z,selectedPropertyKey:V?W(V,L):void 0,properties:v.properties,additionalFields:v.additionalFields,propertiesOrder:ue,onPropertyClick:Be,onPropertyMove:Te,onPropertyRemove:a?de:void 0,collectionEditable:d,errors:F})}),e.jsx(t.Button,{className:"mt-8 w-full",color:"primary",variant:"outlined",size:"large",onClick:()=>H(!0),startIcon:e.jsx(t.AddIcon,{}),children:"Add new property"})]}),!N&&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:[D&&c&&!i.isPropertyBuilder(c)&&e.jsx(Ke,{inArray:!1,existingProperty:!a,autoUpdateId:!1,allowDataInference:!a,autoOpenTypeSelect:!1,propertyKey:V,propertyNamespace:L,property:c,onPropertyChanged:re,onDelete:de,onError:Pe,forceShowErrors:r,initialErrors:Fe,getData:f,propertyConfigs:g,collectionEditable:d},`edit_view_${m}`),!c&&e.jsxs("div",{className:"w-full flex flex-col items-center justify-center h-full gap-4",children:[e.jsx(t.Typography,{variant:"label",className:"",children:Ne?"Now you can add your first property":"Select a property to edit it"}),e.jsxs(t.Button,{variant:"outlined",onClick:()=>H(!0),children:[e.jsx(t.AddIcon,{}),"Add new property"]})]}),c&&i.isPropertyBuilder(c)&&e.jsx(t.Typography,{variant:"label",className:"flex items-center justify-center",children:"This property is defined as a property builder in code"})]})}),N&&e.jsx(ie,{inArray:!1,open:m!==void 0,autoUpdateId:!c,allowDataInference:!a,existingProperty:!0,autoOpenTypeSelect:!1,propertyKey:V,propertyNamespace:L,property:c,onPropertyChanged:re,onDelete:de,onError:Pe,forceShowErrors:r,initialErrors:Fe,getData:f,propertyConfigs:g,collectionEditable:d,onOkClicked:N?Ie:void 0},`edit_view_${m}`)]});return e.jsxs(e.Fragment,{children:[De,e.jsx(ie,{inArray:!1,existingProperty:!1,autoOpenTypeSelect:!0,autoUpdateId:!0,forceShowErrors:r,open:$,onCancel:()=>H(!1),onPropertyChanged:_e,getData:f,allowDataInference:!a,propertyConfigs:g,collectionEditable:d,existingPropertyKeys:v.propertiesOrder}),e.jsx(Mr,{collection:v,open:x,onOpenChange:Y})]})}function Ur({open:r,handleOk:a,handleCancel:o,body:l,title:s}){return e.jsxs(t.Dialog,{open:r,onOpenChange:n=>n?o():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"}),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:o,autoFocus:!0,children:" Cancel "}),e.jsx(t.Button,{onClick:a,children:" Ok "})]})]})}function Lr({open:r,onClose:a}){const{entityViews:o}=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"}),o?.map(l=>e.jsxs(t.Button,{onClick:()=>a(l.key),fullWidth:!0,variant:"text",children:[l.name," (",l.key,")"]},l.key)),(o??[]).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 qr({collection:r,parentCollection:a,configController:o,collectionInference:l,getUser:s,parentCollectionIds:n}){const{entityViews:p}=i.useCustomizationController(),[h,f]=C.useState(),[y,g]=C.useState(!1),[d,v]=C.useState(),[b,w]=C.useState(),{values:T,setFieldValue:F}=u.useFormex(),S=r.subcollections??[],P=T.entityViews?.filter(m=>typeof m=="string").map(m=>i.resolveEntityView(m,p)).filter(Boolean)??[],I=r.entityViews?.filter(m=>typeof m!="string")??[],N=P.length+I.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 ",T.name]}),e.jsxs(t.Paper,{className:"flex flex-col gap-4 p-2 w-full",children:[S&&S.length>0&&e.jsx(t.Table,{children:e.jsx(t.TableBody,{children:S.map(m=>e.jsxs(t.TableRow,{onClick:()=>w({isNewCollection:!1,editedCollectionId:m.id}),children:[e.jsx(t.TableCell,{align:"left",children:e.jsx(t.Typography,{variant:"subtitle2",className:"flex-grow",children:m.name})}),e.jsx(t.TableCell,{align:"right",children:e.jsx(t.Tooltip,{title:"Remove",children:e.jsx(t.IconButton,{size:"small",onClick:k=>{k.preventDefault(),k.stopPropagation(),f(m.id)},color:"inherit",children:e.jsx(t.DeleteIcon,{size:"small"})})})})]},m.path))})}),e.jsx(t.Button,{onClick:()=>{w({isNewCollection:!0})},variant:"text",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"}),N===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 them with the CLI."}),e.jsx(e.Fragment,{children:e.jsxs(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(m=>e.jsxs(t.TableRow,{children:[e.jsx(t.TableCell,{align:"left",children:e.jsx(t.Typography,{variant:"subtitle2",className:"flex-grow",children:m.name})}),e.jsx(t.TableCell,{align:"right",children:e.jsx(t.Tooltip,{title:"Remove",children:e.jsx(t.IconButton,{size:"small",onClick:k=>{k.preventDefault(),k.stopPropagation(),v(m.key)},color:"inherit",children:e.jsx(t.DeleteIcon,{size:"small"})})})})]},m.key)),I.map(m=>e.jsx(t.TableRow,{children:e.jsxs(t.TableCell,{align:"left",children:[e.jsx(t.Typography,{variant:"subtitle2",className:"flex-grow",children:m.name}),e.jsxs(t.Typography,{variant:"caption",className:"flex-grow",children:["This view is defined in code with key ",e.jsx("code",{children:m.key})]})]})},m.key))]})}),e.jsx(t.Button,{onClick:()=>{g(!0)},variant:"text",startIcon:e.jsx(t.AddIcon,{}),children:"Add custom entity view"})]})})]})]})}),e.jsx("div",{style:{height:"52px"}}),h&&e.jsx(i.DeleteConfirmationDialog,{open:!!h,onAccept:()=>{const m={id:h,parentCollectionIds:[...n??[],r.id]};console.debug("Deleting subcollection",m),o.deleteCollection(m),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"]})}),d&&e.jsx(i.DeleteConfirmationDialog,{open:!!d,onAccept:()=>{F("entityViews",T.entityViews?.filter(m=>m!==d)),v(void 0)},onCancel:()=>v(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(er,{open:!!b,configController:o,parentCollection:r,collectionInference:l,parentCollectionIds:[...n??[],T.id],isNewCollection:!1,...b,getUser:s,handleClose:()=>{w(void 0)}}),e.jsx(Lr,{open:y,onClose:m=>{m&&F("entityViews",[...T.entityViews??[],m]),g(!1)}})]})}const Ze={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"}})},Je={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"]}},Qe={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"}})},Xe={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 $r({path:r,pathSuggestions:a,parentCollection:o,onContinue:l,existingCollectionPaths:s}){const[n,p]=C.useState(!1),[h,f]=C.useState();C.useEffect(()=>{a&&s&&(p(!0),a(r).then(b=>{const w=b.filter(T=>!(s??[]).find(F=>F.trim().toLowerCase()===T.trim().toLowerCase()));f(w)}).finally(()=>p(!1)))},[s,r,a]);const{values:y,setFieldValue:g,setValues:d,submitCount:v}=u.useFormex();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"})}),o&&e.jsx(t.Chip,{colorScheme:"tealDarker",children:e.jsxs(t.Typography,{variant:"caption",children:["This is a subcollection of ",e.jsx("b",{children:o.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((b,w)=>e.jsx(t.Chip,{colorScheme:"cyanLighter",onClick:()=>{g("name",i.unslugify(b)),g("id",b),g("path",b),g("properties",void 0),l()},size:"small",children:b},b)),!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(be,{title:"Products",subtitle:"A collection of products with images, prices and stock",icon:e.jsx(t.Icon,{size:"small",iconKey:Ze.icon}),onClick:()=>{d(Ze),l()}}),e.jsx(be,{title:"Users",subtitle:"A collection of users with emails, names and roles",icon:e.jsx(t.Icon,{size:"small",iconKey:Qe.icon}),onClick:()=>{d(Qe),l()}}),e.jsx(be,{title:"Blog posts",subtitle:"A collection of blog posts with images, authors and complex content",icon:e.jsx(t.Icon,{size:"small",iconKey:Je.icon}),onClick:()=>{d(Je),l()}}),e.jsx(be,{title:"Pages",subtitle:"A collection of pages with images, authors and complex content",icon:e.jsx(t.Icon,{size:"small",iconKey:Xe.icon}),onClick:()=>{d(Xe),l()}})]})]}),!o&&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:b=>l(b)})]}),e.jsx("div",{children:e.jsx(t.Button,{variant:"text",onClick:()=>l(),className:"my-2",children:"Continue from scratch"})})]})})}function be({title:r,subtitle:a,icon:o,onClick:l}){return e.jsx(t.Tooltip,{title:a,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-slate-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:[o,e.jsx("div",{className:"flex flex-col items-start",children:e.jsx(t.Typography,{variant:"subtitle1",children:r})})]})})}function jr({importConfig:r,propertyConfigs:a,collectionEditable:o}){const{setFieldValue:l,setFieldTouched:s,values:n}=u.useFormex(),[p,h]=C.useState(void 0),f=C.useRef(n.propertiesOrder?{"":n.propertiesOrder}:{}),y=p?p.id:void 0,g=p||void 0,d=({id:b,property:w,previousId:T,namespace:F})=>{const S=b?W(b,F):void 0,P=S?Q(S):void 0,I=m=>m?f.current[m]??u.getIn(n,R(m)):f.current[""],N=(m,k)=>{const V=R(k);l(V,m,!1),f.current[k??""]=m};if(T&&T!==b){const m=W(T,F),k=Q(m),z=I(F).map(A=>A===T?b:A).filter(A=>A!==void 0);N(z,F);const L={...r.headersMapping};Object.keys(L).forEach(A=>{L[A]===T&&(L[A]=b??"")}),r.setHeadersMapping(L),l(k,void 0,!1),s(k,!1,!1)}P&&(l(P,w,!1),s(P,!0,!1))},v=async({id:b,importKey:w,property:T,namespace:F})=>{const S=b?W(b,F):void 0,P=S?Q(S):void 0,I=r.importData.map(m=>u.getIn(m,w)),N={...Se.buildPropertyFromData(I,T,ae.getInferenceType),editable:!0};P&&(N?l(P,N,!1):l(P,T,!1),s(P,!0,!1))};return e.jsxs("div",{className:"overflow-auto my-auto",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:b=>r.setIdColumn(b??void 0),buildPropertyView:({property:b,propertyKey:w,importKey:T})=>e.jsx(ae.ImportNewPropertyFieldPreview,{property:b,propertyKey:w,onPropertyNameChanged:(F,S)=>l(`properties.${F}.name`,S,!1),onEditClick:()=>{!w||!b||h({...b,id:w,editable:!0})},propertyTypeView:e.jsx(Yr,{property:b,disabled:!1,onPropertyChanged:F=>v({...F,importKey:T}),propertyKey:w,propertyConfigs:a})})})]}),e.jsx(ie,{open:p!==void 0,propertyKey:y,property:g,inArray:!1,autoUpdateId:!1,onPropertyChanged:d,allowDataInference:!1,collectionEditable:o,onOkClicked:()=>{h(void 0)},onCancel:()=>{h(void 0)},autoOpenTypeSelect:!1,existingProperty:!1,propertyConfigs:a}),e.jsx("div",{style:{height:"52px"}})]})}function Yr({property:r,onPropertyChanged:a,propertyKey:o,propertyConfigs:l,disabled:s}){const n=r?i.getFieldId(r):null,p=r?i.getFieldConfig(r,l):null,[h,f]=C.useState(!1);return e.jsx(t.Tooltip,{title:r&&p?`${p?.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:!p,value:n??"",placeholder:"Select a property widget",position:"item-aligned",renderValue:y=>p?e.jsx(i.PropertyConfigBadge,{propertyConfig:p}):null,onValueChange:y=>{const g=Ye(r,y,l);o&&a({id:o,property:g,previousId:o,namespace:void 0})},children:Object.entries(Ge).map(([y,g])=>e.jsx(He,{value:y,optionDisabled:!1,propertyConfig:g,existing:!1},y))})})}function Hr({importConfig:r,properties:a,propertiesOrder:o}){C.useEffect(()=>{const s=ae.getPropertiesMapping(r.originProperties,a),n=r.importData.map(p=>ae.convertDataToEntity(p,r.idColumn,r.headersMapping,a,s,"TEMP_PATH"));r.setEntities(n)},[]);const l=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:l,displayedColumnIds:o.map(s=>({key:s,disabled:!1})),properties:a})}function Re(r,a=""){const o=Object.keys(r).reduce((n,p)=>{const h=r[p],f=i.slugify(p),y=a?`${a}.${f}`:f;if(h.dataType==="map"&&h.properties){const v=Re(h.properties,y);return{headersMapping:{...n.headersMapping,[p]:y},properties:{...n.properties,[f]:{...h,properties:v.properties,propertiesOrder:Object.keys(v.properties)}}}}const g={...n.properties,[f]:h};return{headersMapping:{...n.headersMapping,[p]:y},properties:g}},{headersMapping:{},properties:{}}),l=Object.keys(o.headersMapping)?.[0];let s;return(l?.includes("id")||l?.includes("key"))&&(s=l),{...o,idColumn:s}}function er(r){const a=r.open,[o,l]=ge.useState(!1),[s,n]=ge.useState(!1),p=C.useCallback(()=>{o?n(!0):r.handleClose(void 0)},[o,r.handleClose]);return C.useEffect(()=>{a||(l(!1),n(!1))},[a]),e.jsxs(t.Dialog,{open:a,fullWidth:!0,fullHeight:!0,scrollable:!1,maxWidth:"7xl",onOpenChange:h=>h?void 0:p(),children:[a&&e.jsx(Gr,{...r,handleCancel:p,setFormDirty:l}),e.jsx(Ur,{open:s,handleOk:()=>r.handleClose(void 0),handleCancel:()=>n(!1),body:"There are unsaved changes in this collection"})]})}function Gr(r){const{propertyConfigs:a}=i.useCustomizationController(),o=i.useNavigationController(),l=i.useAuthController(),{topLevelNavigation:s,collections:n}=o,p=r.initialValues,h=!p?.path&&(r.parentCollectionIds??[]).length===0,f=(r.parentCollection?r.parentCollection.subcollections:n)??[],y=f.map(P=>P.path.trim().toLowerCase()),g=f.map(P=>P.id?.trim().toLowerCase()).filter(Boolean),[d,v]=ge.useState(),[b,w]=ge.useState(!1);if(C.useEffect(()=>{try{o.initialised&&(r.editedCollectionId?v(o.getCollectionFromPaths([...r.parentCollectionIds??[],r.editedCollectionId])):v(void 0),w(!0))}catch(P){console.error(P)}},[o.getCollectionFromPaths,r.editedCollectionId,r.parentCollectionIds,o.initialised]),!s)throw Error("Internal: Navigation not ready in collection editor");const{groups:T}=s,F=d?{...d,id:d.id??d.path??i.randomString(16)}:void 0,S=F?Wr(F,a):{id:p?.path??i.randomString(16),path:p?.path??"",name:p?.name??"",group:p?.group??"",properties:{},propertiesOrder:[],icon:t.coolIconKeys[Math.floor(Math.random()*t.coolIconKeys.length)],ownerId:l.user?.uid??""};return b?!r.isNewCollection&&(!o.initialised||!b)?e.jsx(i.CircularProgressCenter,{}):e.jsx(Kr,{...r,initialValues:S,existingPaths:y,existingIds:g,includeTemplates:h,collection:d,setCollection:v,groups:T,propertyConfigs:a}):e.jsx(i.CircularProgressCenter,{})}function Kr({isNewCollection:r,configController:a,editedCollectionId:o,parentCollectionIds:l,fullPath:s,collectionInference:n,handleClose:p,reservedGroups:h,extraView:f,handleCancel:y,setFormDirty:g,pathSuggestions:d,getUser:v,parentCollection:b,getData:w,existingPaths:T,existingIds:F,includeTemplates:S,collection:P,setCollection:I,initialValues:N,propertyConfigs:m,groups:k}){const V=ae.useImportConfig(),z=i.useNavigationController(),L=i.useSnackbarController(),A=C.useRef({}),D=r?S?"welcome":"details":"properties",[c,x]=C.useState(D),[Y,M]=ge.useState(),j=O=>{const _=O.id||O.path;return a.saveCollection({id:_,collectionData:O,previousId:o,parentCollectionIds:l}).then(()=>(M(void 0),!0)).catch(B=>(M(B),console.error(B),L.open({type:"error",message:"Error persisting collection: "+(B.message??"Details in the console")}),!1))},$=C.useCallback(()=>{c==="details"?V.inUse?x("import_data_saving"):x(f?"extra_view":"properties"):x(c==="welcome"?"details":c==="import_data_mapping"?"import_data_preview":c==="import_data_preview"?"details":c==="extra_view"?"properties":"details")},[c,V.inUse,f]),H=C.useCallback(O=>{if(n)return n?.(O.path,O.collectionGroup??!1,l??[])},[n,l]),Z=C.useCallback(async O=>{try{if(!H)return I(O),Promise.resolve(O);x("loading");const _=await H?.(O);if(!_)return I(O),Promise.resolve(O);const B={...O??{}};return Object.keys(_.properties??{}).length>0&&(B.properties=_.properties,B.propertiesOrder=_.propertiesOrder),B.propertiesOrder?(I(B),console.debug("Inferred collection",{newCollection:O??{},values:B}),B):(B.propertiesOrder=Object.keys(B.properties),B)}catch(_){return console.error(_),L.open({type:"error",message:"Error inferring collection: "+(_.message??"Details in the console")}),O}},[l,H]),fe=(O,_)=>{console.log("Submitting collection",O);try{if(!r){j(O).then(()=>{_.resetForm({values:N}),p(O)});return}c==="welcome"?($(),_.resetForm({values:O})):c==="details"?f||V.inUse?(_.resetForm({values:O}),$()):r?Z(O).then(B=>{_.resetForm({values:B??O,touched:{path:!0,name:!0}})}).finally(()=>{$()}):(_.resetForm({values:O}),$()):c==="extra_view"?($(),_.resetForm({values:O})):c==="import_data_mapping"||c==="import_data_preview"?$():c==="properties"?j(O).then(()=>{_.resetForm({values:N}),$(),p(O)}):($(),_.resetForm({values:O}))}catch(B){L.open({type:"error",message:"Error persisting collection: "+(B.message??"Details in the console")}),console.error(B),_.resetForm({values:O})}},oe=O=>{let _={};const B=(c==="properties"||c==="subcollections"||c==="details")&&cr;if(B)try{B.validateSync(O,{abortEarly:!1})}catch(K){K.inner.forEach(ce=>{_[ce.path]=ce.message})}if(c==="properties"&&(_={..._,...A.current}),c==="details"){const K=tr(O.path,r,T,O.id);K&&(_.path=K);const ce=Zr(O.id,r,T,F);ce&&(_.id=ce)}return _},X=u.useCreateFormex({initialValues:N,onSubmit:fe,validation:oe}),{values:G,setFieldValue:ne,isSubmitting:de,dirty:Te,submitCount:_e}=X,re=G.path,Pe=s?.includes("/")?s?.split("/").slice(0,-1).join("/")+"/"+re:re,Ie=tr(re,r,T,G.id),Fe=!Ie&&l?z.convertIdsToPaths(l):void 0,Ne=Ie?void 0:z.resolveAliasesFrom(Pe),ue=Ne&&w?()=>w(Ne,Fe??[]):void 0;C.useEffect(()=>{g(Te)},[Te]);function we(O){V.setInUse(!0),Se.buildEntityPropertiesFromData(O,ae.getInferenceType).then(_=>{const B=Re(_);ne("properties",B.properties),ne("propertiesOrder",Object.keys(B.properties)),V.setIdColumn(B.idColumn),V.setImportData(O),V.setHeadersMapping(B.headersMapping),V.setOriginProperties(B.properties)})}const Be=!!G.name&&!!G.id,De=()=>{const O={...G.properties};V.idColumn&&delete O[V.idColumn],ne("properties",O),$()},q=P?.editable===void 0||P?.editable===!0||r;return e.jsx(t.DialogContent,{fullHeight:!0,children:e.jsx(u.Formex,{value:X,children:e.jsxs(e.Fragment,{children:[!r&&e.jsxs(t.Tabs,{value:c,className:t.cn(t.defaultBorderMixin,"justify-end bg-gray-50 dark:bg-gray-950 border-b"),onValueChange:O=>x(O),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:X.handleSubmit,className:t.cn(r?"h-full":"h-[calc(100%-48px)]","flex-grow flex flex-col relative"),children:[c==="loading"&&e.jsx(i.CircularProgressCenter,{}),c==="extra_view"&&re&&f?.View&&e.jsx(f.View,{path:re}),c==="welcome"&&e.jsx($r,{path:re,onContinue:O=>{O?(we(O),x("import_data_mapping")):x("details")},existingCollectionPaths:T,parentCollection:b,pathSuggestions:d}),c==="import_data_mapping"&&V&&e.jsx(jr,{importConfig:V,collectionEditable:q,propertyConfigs:m}),c==="import_data_preview"&&V&&e.jsx(Hr,{importConfig:V,properties:G.properties,propertiesOrder:G.propertiesOrder}),c==="import_data_saving"&&V&&e.jsx(ae.ImportSaveInProgress,{importConfig:V,collection:G,path:re,onImportSuccess:async O=>{L.open({type:"info",message:"Data imported successfully"}),await j(G),p(O)}}),c==="details"&&e.jsx(pr,{existingPaths:T,existingIds:F,groups:k,parentCollectionIds:l,parentCollection:b,isNewCollection:r}),c==="subcollections"&&P&&e.jsx(qr,{parentCollection:b,configController:a,getUser:v,collectionInference:n,parentCollectionIds:l,collection:P}),c==="properties"&&e.jsx(zr,{showErrors:_e>0,isNewCollection:r,reservedGroups:h,onPropertyError:(O,_,B)=>{const K=i.removeUndefined({...A.current,[xe(O,_)]:i.removeUndefined(B,!0)},!0);A.current=K,X.validate()},getUser:v,getData:ue,doCollectionInference:H,propertyConfigs:m,collectionEditable:q,extraIcon:f?.icon&&e.jsx(t.IconButton,{color:"primary",onClick:()=>x("extra_view"),children:f.icon})}),c!=="welcome"&&e.jsxs(t.DialogActions,{position:"absolute",children:[Y&&e.jsx(i.ErrorView,{error:Y}),r&&S&&c==="import_data_mapping"&&e.jsxs(t.Button,{variant:"text",type:"button",onClick:()=>(V.setInUse(!1),x("welcome")),children:[e.jsx(t.ArrowBackIcon,{}),"Back"]}),r&&S&&c==="import_data_preview"&&e.jsxs(t.Button,{variant:"text",type:"button",onClick:()=>{x("import_data_mapping")},children:[e.jsx(t.ArrowBackIcon,{}),"Back"]}),r&&S&&c==="details"&&e.jsxs(t.Button,{variant:"text",type:"button",onClick:()=>x("welcome"),children:[e.jsx(t.ArrowBackIcon,{}),"Back"]}),r&&c==="properties"&&e.jsxs(t.Button,{variant:"text",type:"button",onClick:()=>x("details"),children:[e.jsx(t.ArrowBackIcon,{}),"Back"]}),e.jsx(t.Button,{variant:"text",onClick:()=>{y()},children:"Cancel"}),r&&c==="import_data_mapping"&&e.jsx(t.Button,{variant:"filled",color:"primary",onClick:De,children:"Next"}),r&&c==="import_data_preview"&&e.jsx(t.Button,{variant:"filled",color:"primary",onClick:()=>{$()},children:"Next"}),r&&(c==="details"||c==="properties")&&e.jsxs(t.LoadingButton,{variant:"filled",color:"primary",type:"submit",loading:de,disabled:de||c==="details"&&!Be,startIcon:c==="properties"?e.jsx(t.DoneIcon,{}):void 0,children:[c==="details"&&"Next",c==="properties"&&"Create collection"]}),!r&&e.jsx(t.LoadingButton,{variant:"filled",color:"primary",type:"submit",loading:de,children:"Update collection"})]})]})]})})})}function Wr(r,a){const{properties:o,...l}=r,s={};return o&&Object.keys(o).forEach(n=>{s[n]=rr(o[n],a)}),{...l,properties:s}}function rr(r,a){let o=r;if(a&&typeof o=="object"&&o.propertyConfig){const l=a[o.propertyConfig];if(l&&i.isPropertyBuilder(l.property))o=l.property;else if(l&&(o=i.mergeDeep(l.property,o)),!i.isPropertyBuilder(o)&&o.dataType==="map"&&o.properties){const s={};Object.keys(o.properties).forEach(n=>{s[n]=rr(o.properties[n],a)}),o={...o,properties:s}}}return o}const tr=(r,a,o,l)=>{let s;return r||(s="You must specify a path in the database for this collection"),a&&o?.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"),i.removeInitialAndTrailingSlashes(r).split("/").length%2===0&&(s=`Collection paths must have an odd number of segments: ${r}`),s},Zr=(r,a,o,l)=>{if(!r)return;let s;return a&&o?.includes(r.trim().toLowerCase())&&(s="There is already a collection that uses this value as a path"),a&&l?.includes(r.trim().toLowerCase())&&(s="There is already a collection which uses this id"),s},ar=C.createContext({}),lr=C.createContext({}),Jr=C.memo(function({children:a,collectionConfigController:o,configPermissions:l,reservedGroups:s,collectionInference:n,extraView:p,pathSuggestions:h,getUser:f,getData:y,onAnalyticsEvent:g}){const d=i.useNavigationController(),v=dr.useNavigate(),b=i.useSnackbarController(),{propertyConfigs:w}=i.useCustomizationController(),{collections:T}=d,F=(T??[]).map(c=>c.path.trim().toLowerCase()),[S,P]=C.useState();C.useEffect(()=>{h&&h().then(c=>{P(c.filter(x=>!F.includes(x.trim().toLowerCase())))})},[h]);const[I,N]=C.useState(),[m,k]=C.useState(),V=C.useCallback(()=>({createCollections:!0,editCollections:!0,deleteCollections:!0}),[]),z=C.useCallback(({id:c,fullPath:x,parentCollectionIds:Y,parentCollection:M})=>{console.debug("Edit collection",c,x,Y,M),g?.("edit_collection",{id:c,fullPath:x}),N({editedCollectionId:c,fullPath:x,parentCollectionIds:Y,isNewCollection:!1,parentCollection:M,redirect:!1})},[]),L=C.useCallback(({propertyKey:c,property:x,editedCollectionId:Y,currentPropertiesOrder:M,parentCollectionIds:j,collection:$})=>{console.debug("Edit property",c,x,Y,M,j,$),g?.("edit_property",{propertyKey:c,editedCollectionId:Y});const H=c&&c.includes(".")?c.substring(0,c.lastIndexOf(".")):void 0,Z=c&&c.includes(".")?c.substring(c.lastIndexOf(".")+1):c;k({propertyKey:Z,property:x,namespace:H,currentPropertiesOrder:M,editedCollectionId:Y,parentCollectionIds:j,collectionEditable:$?.editable??!1})},[]),A=C.useCallback(({parentCollectionIds:c,parentCollection:x,initialValues:Y,redirect:M,sourceClick:j})=>{console.debug("Create collection",{parentCollectionIds:c,parentCollection:x,initialValues:Y,redirect:M,sourceClick:j}),g?.("create_collection",{parentCollectionIds:c,parentCollection:x,initialValues:Y,redirect:M,sourceClick:j}),N({isNewCollection:!0,parentCollectionIds:c,parentCollection:x,initialValues:Y,redirect:M})},[]),D=h?c=>!c&&S?Promise.resolve(S):h?.(c):void 0;return e.jsx(ar.Provider,{value:o,children:e.jsxs(lr.Provider,{value:{editCollection:z,createCollection:A,editProperty:L,configPermissions:l??V,rootPathSuggestions:S},children:[a,e.jsx(er,{open:!!I,configController:o,isNewCollection:!1,collectionInference:n,...I,getData:y,reservedGroups:s,extraView:p,pathSuggestions:D,getUser:f,handleClose:c=>{if(I?.redirect&&c&&I?.isNewCollection&&!I.parentCollectionIds.length){const x=d.buildUrlCollectionPath(c.id??c.path);v(x)}N(void 0)}}),e.jsx(ie,{open:!!m,includeIdAndName:!0,existingProperty:!!m?.propertyKey,autoUpdateId:m?!m?.propertyKey:!1,autoOpenTypeSelect:m?!m?.propertyKey:!1,inArray:!1,collectionEditable:m?.collectionEditable??!1,getData:y&&m?.editedCollectionId?()=>{console.debug("get data for property",m?.editedCollectionId);const c=d.resolveAliasesFrom(m.editedCollectionId);return y(c,[])}:void 0,onPropertyChanged:({id:c,property:x})=>{if(!m||!c)return;const Y=!m.propertyKey;return o.saveProperty({path:m?.editedCollectionId,property:x,propertyKey:c,newPropertiesOrder:Y&&m.currentPropertiesOrder?[...m.currentPropertiesOrder,c]:void 0,namespace:m.namespace,parentCollectionIds:m.parentCollectionIds}).catch(M=>(console.error(M),b.open({type:"error",message:"Error persisting property: "+(M.message??"Details in the console")}),!1))},onPropertyChangedImmediate:!1,onDelete:()=>{if(!m?.propertyKey)return;const c=m?.currentPropertiesOrder?.filter(x=>x!==m?.propertyKey);return o.deleteProperty({path:m?.editedCollectionId,propertyKey:m?.propertyKey,namespace:m?.namespace,newPropertiesOrder:c,parentCollectionIds:m?.parentCollectionIds}).then(()=>{k(void 0)}).catch(x=>(console.error(x),b.open({type:"error",message:"Error deleting property: "+(x.message??"Details in the console")}),!1))},onError:()=>{},onOkClicked:()=>{k(void 0)},onCancel:()=>{k(void 0)},initialErrors:{},forceShowErrors:!1,existingPropertyKeys:[],allowDataInference:!0,propertyConfigs:w,property:m?.property,propertyKey:m?.propertyKey})]})})},te),ee=()=>C.useContext(lr),Ee=()=>C.useContext(ar);function Qr({path:r,parentCollectionIds:a,collection:o,tableController:l}){const s=i.useAuthController(),n=i.useNavigationController(),p=ee(),h=Ee(),f=i.useSnackbarController(),y=n.getCollectionFromIds(a),g=p.configPermissions?p.configPermissions({user:s.user,collection:o}).editCollections:!0;let d=null;(!te(Ce(l.filterValues),Ce(o.initialFilter))||!te(Ce(l.sortBy),Ce(o.initialSort)))&&(d=e.jsxs(e.Fragment,{children:[(o.initialFilter||o.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?.(),o?.initialFilter&&l.setFilterValues?.(o?.initialFilter),o?.initialSort&&l.setSortBy?.(o?.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:()=>h?.saveCollection({id:o.id,parentCollectionIds:a,collectionData:i.mergeDeep(o,{initialFilter:l.filterValues??null,initialSort:l.sortBy??null})}).then(()=>{f.open({type:"success",message:"Default config saved"})}),children:e.jsx(t.SaveIcon,{})})})]}));const v=e.jsx(t.Tooltip,{title:g?"Edit collection":"You don't have permissions to edit this collection",children:e.jsx(t.IconButton,{color:"primary",disabled:!g,onClick:g?()=>p?.editCollection({id:o.id,fullPath:r,parentCollectionIds:a,parentCollection:y}):void 0,children:e.jsx(t.SettingsIcon,{})})});return e.jsxs(e.Fragment,{children:[g&&d,v]})}function Ce(r){return r&&Object.keys(r).length===0?r:r??null}function Xr({path:r,collection:a}){const o=i.useSnackbarController(),l=i.useAuthController(),s=Ee(),n=ee(),p=n.configPermissions({user:l.user,collection:a}),h=C.useCallback(()=>{n?.editCollection({id:a.id,parentCollectionIds:[]})},[n,r]),[f,y]=C.useState(!1),g=C.useCallback(()=>{s?.deleteCollection({id:a.id}).then(()=>{y(!1),o.open({message:"Collection deleted",type:"success"})})},[r,s]);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[p.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(),y(!0)},children:[e.jsx(t.DeleteIcon,{}),"Delete"]})}),p.editCollections&&e.jsx(t.IconButton,{onClick:d=>{h()},children:e.jsx(t.SettingsIcon,{size:"small"})})]}),e.jsx(i.DeleteConfirmationDialog,{open:f,onAccept:g,onCancel:()=>y(!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 Rr({group:r,context:a}){if(!a.navigation.topLevelNavigation)throw Error("Navigation not ready in FireCMSHomePage");const o=i.useAuthController(),l=ee(),s=l.configPermissions?l.configPermissions({user:o.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 et({introMode:r}){const a=i.useAuthController(),o=i.useNavigationController(),l=ee(),s=l.configPermissions?l.configPermissions({user:a.user}).createCollections:!0,n=l.rootPathSuggestions,p=(n??[]).length>3||(o.collections??[]).length===0&&(n??[]).length>0,h=r==="existing_project";return e.jsx(t.Collapse,{in:h||p,children:e.jsxs("div",{className:"flex flex-col gap-1 p-2 my-4",children:[!r&&e.jsxs(t.Typography,{variant:"body2",color:"secondary",children:["Create a collection ",e.jsx("b",{children:"automatically"})," from your data:"]}),r==="existing_project"&&e.jsxs(t.Typography,{children:["You will see your ",e.jsx("b",{children:"database collections"})," here, a few seconds after project creation"]}),e.jsxs("div",{className:"flex flex-row gap-1 overflow-scroll no-scrollbar ",children:[(n??[]).map(f=>e.jsx("div",{children:e.jsx(t.Chip,{icon:e.jsx(t.AddIcon,{size:"small"}),colorScheme:"cyanLighter",onClick:l&&s?()=>l.createCollection({initialValues:{path:f,name:i.unslugify(f)},parentCollectionIds:[],redirect:!0,sourceClick:"root_collection_suggestion"}):void 0,size:"small",children:f})},f)),n===void 0&&e.jsx(t.CircularProgress,{size:"small"}),n?.length===0&&e.jsx(t.Typography,{variant:"caption",children:"No suggestions"})]})]})})}function rt({propertyKey:r,onHover:a,property:o,fullPath:l,parentCollectionIds:s,collection:n}){const p=ee();return e.jsx(t.Tooltip,{title:"Edit",children:e.jsx(t.IconButton,{className:a?"bg-white dark:bg-gray-950":"hidden",onClick:()=>{p.editProperty({propertyKey:r,property:o,editedCollectionId:n.id,parentCollectionIds:s,collection:n})},size:"small",children:e.jsx(t.SettingsIcon,{size:"small"})})})}function tt({fullPath:r,parentCollectionIds:a,collection:o}){const l=i.useAuthController(),s=ee(),n=s.configPermissions?s.configPermissions({user:l.user,collection:o}).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:o.id,parentCollectionIds:a,currentPropertiesOrder:i.getDefaultPropertiesOrder(o),collection:o})},children:e.jsx(t.AddIcon,{color:"inherit"})})})}function at(){const r=ee();return e.jsx("div",{className:"bg-gray-50 dark:bg-gray-900 min-w-fit rounded",children: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 lt({collectionConfigController:r,introMode:a,configPermissions:o,reservedGroups:l,extraView:s,pathSuggestions:n,getUser:p,collectionInference:h,getData:f,onAnalyticsEvent:y}){return{key:"collection_editor",loading:r.loading,provider:{Component:Jr,props:{collectionConfigController:r,configPermissions:o,collectionInference:h,reservedGroups:l,extraView:s,pathSuggestions:n,getUser:p,getData:f,onAnalyticsEvent:y}},homePage:{additionalActions:e.jsx(at,{}),additionalChildrenStart:a?e.jsx(ot,{introMode:a}):void 0,additionalChildrenEnd:e.jsx(et,{introMode:a}),CollectionActions:Xr,AdditionalCards:a?void 0:Rr},collectionView:{CollectionActions:Qr,HeaderAction:rt,AddColumnComponent:tt}}}function ot({introMode:r}){if(!i.useNavigationController().topLevelNavigation)throw Error("Navigation not ready in FireCMSHomePage");const o=i.useAuthController(),l=ee(),s=l.configPermissions?l.configPermissions({user:o.user}).createCollections:!0;return e.jsxs("div",{className:"mt-8 flex flex-col mt-8 p-2",children:[e.jsx(t.Typography,{variant:"h4",className:"mb-4",children:"Welcome"}),e.jsx(t.Typography,{paragraph:!0,children:"Your admin panel is ready ✌️"}),e.jsx(t.Typography,{paragraph:!0,children:"Start building collections in FireCMS easily. Map them to your existing database data, import from files, or use our templates. Simplify your data management process now."}),s&&e.jsxs(t.Button,{className:"mt-4",onClick:l&&s?()=>l.createCollection({parentCollectionIds:[],redirect:!0,sourceClick:"new_collection_card"}):void 0,children:[e.jsx(t.AddIcon,{}),"Create your first collection"]})]})}function nt({path:r}){const a=i.useNavigationController(),o=st(r),l=a.getParentCollectionIds(r),s=ee();return e.jsxs("div",{className:"p-1 flex flex-col items-center",children:[e.jsx(i.ErrorView,{error:"No collection for path: "+o}),e.jsx(t.Button,{className:"mx-2",variant:"outlined",size:"small",onClick:()=>{s.createCollection({initialValues:{path:o,name:i.unslugify(o)},parentCollectionIds:l,redirect:!1,sourceClick:"missing_reference"})},children:"Create"})]})}function st(r){const a=r.split("/");return a[a.length-1]}U.MissingReferenceWidget=nt,U.editableProperty=he,U.getFullId=W,U.getFullIdPath=xe,U.idToPropertiesPath=Q,U.namespaceToPropertiesOrderPath=R,U.namespaceToPropertiesPath=ze,U.removeNonEditableProperties=qe,U.useCollectionEditorController=ee,U.useCollectionEditorPlugin=lt,U.useCollectionsConfigController=Ee,Object.defineProperty(U,Symbol.toStringTag,{value:"Module"})});
|
|
4
4
|
//# sourceMappingURL=index.umd.js.map
|