@firecms/core 3.0.0-canary.60 → 3.0.0-canary.61
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 +86 -83
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +4 -4
- package/src/form/EntityForm.tsx +6 -7
package/dist/index.umd.js
CHANGED
|
@@ -585,5 +585,5 @@
|
|
|
585
585
|
.rc-md-editor .header-list .list-item:hover {
|
|
586
586
|
}
|
|
587
587
|
|
|
588
|
-
`;function Pn({propertyKey:e,value:t,error:o,showError:a,isSubmitting:i,setValue:n,tableMode:s,property:l,includeDescription:c,underlyingValueHasChanged:u,context:f,disabled:g}){if(!Array.isArray(l.resolvedProperties))throw Error("ArrayCustomShapedFieldBinding misconfiguration. Property `of` not set");const m=l.expanded===void 0?!0:l.expanded;Te({property:l,value:t,setValue:n});const h=r.jsx(Ee,{icon:Ce(l,"small"),required:l.validation?.required,className:"text-text-secondary dark:text-text-secondary-dark",title:l.name}),A=l.resolvedProperties.map((y,b)=>{const v={propertyKey:`${e}[${b}]`,disabled:g,property:y,includeDescription:c,underlyingValueHasChanged:u,context:f,tableMode:!1,partOfArray:!0,partOfBlock:!1,autoFocus:!1};return r.jsx("div",{className:"pb-4",children:r.jsx(ot,{...v})},`custom_shaped_array_${b}`)});return r.jsxs(r.Fragment,{children:[!s&&r.jsx(p.ExpandablePanel,{initiallyExpanded:m,title:h,className:"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2",children:A}),s&&A,r.jsx(xe,{includeDescription:c,showError:a,error:o,disabled:g,property:l})]})}const Zl=({containerRef:e})=>{const{isSubmitting:t,isValidating:o,errors:a}=ke.useFormex();return d.useEffect(()=>{const i=Object.keys(a);if(i.length>0&&t&&!o){const n=e?.current?.querySelector(`#form_field_${i[0]}`);if(n&&e?.current){const s=Tn(e.current);if(s){const c=n.getBoundingClientRect().top;s.scrollTo({top:s.scrollTop+c-196,behavior:"smooth"})}const l=n.querySelector("input");l&&l.focus()}}},[t,o,a,e]),null},Xl=e=>{const t=e&&e.scrollHeight>e.clientHeight,o=e?window.getComputedStyle(e).overflowY:null,a=o&&o.indexOf("hidden")!==-1;return t&&!a},Tn=e=>!e||e===document.body?document.body:Xl(e)?e:Tn(e.parentNode);function Kl({customId:e,entityId:t,status:o,onChange:a,error:i,entity:n,loading:s}){const{errors:l}=ke.useFormex(),c=o==="existing"||!e,u=o!=="existing"&&!e,f=d.useMemo(()=>{if(!(!e||typeof e=="boolean"||e==="optional"))return We(e)},[e]),g=He(),{copy:m}=wa({onSuccess:y=>g.open({type:"success",message:`Copied ${y}`})}),h=ae(),A={label:u?"ID is set automatically":"ID",disabled:c||s,name:"id",value:(n&&o==="existing"?n.id:t)??"",endAdornment:s?r.jsx(p.CircularProgress,{size:"small"}):n?r.jsxs(r.Fragment,{children:[r.jsx(p.Tooltip,{title:"Copy",children:r.jsx(p.IconButton,{onClick:y=>m(n.id),"aria-label":"copy-id",children:r.jsx(p.ContentCopyIcon,{size:"small"})})}),h?.entityLinkBuilder&&r.jsx(p.Tooltip,{title:"Open in the console",children:r.jsx(p.IconButton,{component:"a",href:h.entityLinkBuilder({entity:n}),rel:"noopener noreferrer",target:"_blank",onClick:y=>y.stopPropagation(),"aria-label":"go-to-datasource",children:r.jsx(p.OpenInNewIcon,{size:"small"})})})]}):void 0};return r.jsxs(r.Fragment,{children:[f&&r.jsx(p.Select,{error:i,onValueChange:y=>a(y),...A,renderValue:y=>{const b=f.find(v=>v.id===y);return b?`${b.id} - ${b.label}`:y},children:f.map(y=>r.jsx(p.SelectItem,{value:String(y.id),children:r.jsx(Ie,{enumKey:y.id,enumValues:f,size:"medium"})},y.id))}),!f&&r.jsx(p.TextField,{...A,error:i,placeholder:e==="optional"?"Autogenerated ID, it can be manually changed":o==="new"||o==="copy"?"ID of the new document":"ID of the document",onChange:y=>{let b=y.target.value;return b&&(b=b.trim()),a(b.length?b:void 0)}}),l.id&&r.jsx(p.Typography,{variant:"caption",className:"ml-3.5 text-red-500 dark:text-red-500",children:l.id})]})}function Rl({propertyId:e}){const[t,o]=d.useState(!1);return r.jsxs("div",{className:"flex flex-row gap-2 items-center justify-center text-white",children:[r.jsxs("div",{children:[r.jsx(p.Typography,{variant:"caption",className:"min-w-20 text-slate-400",color:"disabled",children:t?"Copied":"Property ID"}),r.jsx(p.Typography,{variant:"caption",className:"text-white",children:r.jsx("code",{children:e})})]}),r.jsx(p.IconButton,{size:"small",children:r.jsx(p.ContentCopyIcon,{size:"smallest",className:"text-white",onClick:d.useCallback(()=>{navigator.clipboard.writeText(e),o(!0),setTimeout(()=>o(!1),2e3)},[e])})})]})}const Dn=ec;function Qn(e,t,o){const a=e.properties;if((t==="existing"||t==="copy")&&o)return o.values??vt(a);if(t==="new")return vt(a);throw console.error({status:t,entity:o}),new Error("Form has not been initialised with the correct parameters")}function ec({status:e,path:t,collection:o,entity:a,onEntitySaveRequested:i,onDiscard:n,onModified:s,onValuesChanged:l,onIdChange:c,onFormContextChange:u,hideId:f,autoSave:g,onIdUpdateError:m}){const h=ut(),A=ae(),y=Ae(),b=Qe(o),v=A.plugins,k=d.useMemo(()=>Ne({collection:o,path:t,values:a?.values,fields:A.propertyConfigs}),[a?.values,t,A.propertyConfigs]),_=(e==="new"||e==="copy")&&!!k.customId&&k.customId!=="optional",E=d.useMemo(()=>e==="new"||e==="copy"?_?void 0:b.generateEntityId(t):a?.id,[]),x=d.useRef(!1),B=d.useRef(Qn(k,e,a)),[C,S]=d.useState(E),[N,I]=d.useState(!1),[P,D]=d.useState(),[G,R]=d.useState(!1),[K,W]=d.useState(a?.values??B.current),j=te=>i({collection:re,path:t,entityId:C,values:te,previousValues:a?.values,closeAfterSave:x.current,autoSave:g??!1}).then(O=>{const ie=e==="new"?"new_entity_saved":e==="copy"?"entity_copied":e==="existing"?"entity_edited":"unmapped_event";h.onAnalyticsEvent?.(ie,{path:t})}).catch(O=>{console.error(O),D(O)}).finally(()=>{x.current=!1}),M=(te,O)=>{if(_&&!C){console.error("Missing custom Id"),I(!0),O.setSubmitting(!1);return}if(D(void 0),I(!1),e==="existing"){if(!a?.id)throw Error("Form misconfiguration when saving, no id for existing entity")}else if(e==="new"||e==="copy"){if(o.customId&&o.customId!=="optional"&&!C)throw Error("Form misconfiguration when saving, entityId should be set")}else throw Error("New FormType added, check EntityForm");return j(te)?.then(ie=>{O.resetForm({values:te,submitCount:0,touched:{}})}).finally(()=>{O.setSubmitting(!1)})},J=ke.useCreateFormex({initialValues:B.current,onSubmit:M,validation:te=>V?.validate(te,{abortEarly:!1}).then(()=>({})).catch(O=>{const ie={};return O.inner.forEach(me=>{ie[me.path]=me.message}),rc(O)})});d.useEffect(()=>{B.current=Qn(k,e,a);const te=J.initialValues;!J.isSubmitting&&te&&e==="existing"?Z(Object.entries(re.properties).map(([O,ie])=>{if(wt(ie))return{};const me=te[O],ue=B.current[O];return L(me,ue)?{}:{[O]:ue}}).reduce((O,ie)=>({...O,...ie}),{})):Z({})},[a,k,e]);const H=te=>{const O=J.initialValues;W(te),l&&l(te),g&&te&&!L(te,O)&&j(te)};d.useEffect(()=>{C&&c&&c(C)},[C,c]);const re=Ne({collection:o,path:t,entityId:C,values:K,previousValues:J.initialValues,fields:A.propertyConfigs}),oe=Fr(re,A.propertyConfigs),U=K&&oe?Ye(K,oe):void 0,X=o.callbacks?.onIdUpdate,Q=d.useCallback(async()=>{if(X&&K&&(e==="new"||e==="copy")){R(!0);try{const te=await X({collection:re,path:t,entityId:C,values:K,context:y});S(te)}catch(te){m&&m(te),console.error(te)}R(!1)}},[C,K,e]);d.useEffect(()=>{Q()},[Q]);const[ee,Z]=d.useState({}),$=d.useCallback(({name:te,value:O,property:ie})=>b.checkUniqueField(t,te,O,C),[b,t,C]),V=d.useMemo(()=>C?Ha(C,re.properties,$):void 0,[C,re.properties,$]),z=qe(),F=d.useCallback(({entity:te,customEntityActions:O})=>{const ie=ct(o,z,t,null),me=te?$t(o,z,t,te):!0,ue=[];return ie&&ue.push(no),me&&ue.push(io),O&&ue.push(...O),ue},[z,o,t]),T=[],le={setFieldValue:d.useCallback(J.setFieldValue,[]),values:J.values,collection:re,entityId:C,path:t,save:j},ve=d.useRef(null);if(d.useEffect(()=>{u&&!oc(ve.current??void 0,le)&&(u(le),ve.current=le)},[le,u]),v&&o){const te={entityId:C,path:t,status:e,collection:o,context:y,currentEntityId:C,formContext:le};T.push(...v.map((O,ie)=>O.form?.Actions?r.jsx(O.form.Actions,{...te},`actions_${O.key}`):null).filter(Boolean))}return r.jsx(ke.Formex,{value:J,children:r.jsxs("div",{className:"h-full overflow-auto",children:[T.length>0&&r.jsx("div",{className:p.cls("w-full flex justify-end items-center sticky top-0 right-0 left-0 z-10 bg-opacity-60 bg-slate-200 dark:bg-opacity-60 dark:bg-slate-800 backdrop-blur-md"),children:T}),r.jsxs("div",{className:"pt-12 pb-16 pl-8 pr-8 md:pl-10 md:pr-10",children:[r.jsxs("div",{className:`w-full py-2 flex flex-col items-start mt-${4+(T?8:0)} lg:mt-${8+(T?8:0)} mb-8`,children:[r.jsx(p.Typography,{className:"mt-4 flex-grow line-clamp-1 "+o.hideIdFromForm?"mb-2":"mb-0",variant:"h4",children:U??o.singularName??o.name}),r.jsx(p.Alert,{color:"base",className:"w-full",size:"small",children:r.jsxs("code",{className:"text-xs select-all",children:[t,"/",C]})})]}),!f&&r.jsx(Kl,{customId:o.customId,entityId:C,status:e,onChange:S,error:N,loading:G,entity:a}),C&&r.jsx(tc,{...J,initialValues:J.initialValues,onModified:s,onDiscard:n,onValuesChanged:H,underlyingChanges:ee,entity:a,resolvedCollection:re,formContext:le,status:e,savingError:P,closeAfterSaveRef:x,autoSave:g,entityActions:F({entity:a,customEntityActions:o.entityActions})})]})]})})}function tc(e){const{values:t,onDiscard:o,onModified:a,onValuesChanged:i,underlyingChanges:n,formContext:s,entity:l,touched:c,setFieldValue:u,resolvedCollection:f,isSubmitting:g,status:m,handleSubmit:h,resetForm:A,savingError:y,dirty:b,closeAfterSaveRef:v,autoSave:k,entityActions:_}=e,E=Ae(),x=_.filter(P=>P.includeInForm===void 0||P.includeInForm),B=Je(),C=b;d.useEffect(()=>{a&&a(C),i&&i(t)},[C,t]),d.useEffect(()=>{!k&&!g&&n&&l&&Object.entries(n).forEach(([P,D])=>{const G=t[P];!L(D,G)&&!c[P]&&(console.debug("Updated value from the datasource:",P,D),u(P,D!==void 0?D:null))})},[g,k,n,l,t,c,u]);const S=r.jsx("div",{className:"flex flex-col gap-8",children:(f.propertiesOrder??Object.keys(f.properties)).map(P=>{const D=f.properties[P];if(!D)return console.warn(`Property ${P} not found in collection ${f.name}`),null;const G=!!n&&Object.keys(n).includes(P)&&!!c[P],R=!k&&g||st(D)||!!D.disabled;if(wt(D))return null;const W={propertyKey:P,disabled:R,property:D,includeDescription:D.description||D.longDescription,underlyingValueHasChanged:G&&!k,context:s,tableMode:!1,partOfArray:!1,partOfBlock:!1,autoFocus:!1};return r.jsx("div",{id:`form_field_${P}`,children:r.jsx(ne,{children:r.jsx(p.Tooltip,{title:r.jsx(Rl,{propertyId:P}),delayDuration:800,side:"left",align:"start",sideOffset:16,children:r.jsx(ot,{...W})})})},`field_${f.name}_${P}`)}).filter(Boolean)}),N=g||!C&&m==="existing",I=d.useRef(null);return r.jsxs("form",{onSubmit:h,onReset:()=>(console.debug("Resetting form"),A(),o&&o()),noValidate:!0,children:[r.jsxs("div",{className:"mt-12",ref:I,children:[S,r.jsx(Zl,{containerRef:I})]}),r.jsx("div",{className:"h-14"}),!k&&r.jsxs(p.DialogActions,{position:"absolute",children:[y&&r.jsx("div",{className:"text-right",children:r.jsx(p.Typography,{color:"error",children:y.message})}),l&&x.length>0&&r.jsx("div",{className:"flex-grow flex overflow-auto no-scrollbar",children:x.map(P=>r.jsx(p.IconButton,{color:"primary",onClick:D=>{D.stopPropagation(),l&&P.onClick({entity:l,fullPath:f.path,collection:f,context:E,sideEntityController:B})},children:P.icon},P.name))}),g&&r.jsx(p.CircularProgress,{size:"small"}),r.jsx(p.Button,{variant:"text",disabled:N||g,type:"reset",children:m==="existing"?"Discard":"Clear"}),r.jsxs(p.Button,{variant:"text",color:"primary",type:"submit",disabled:N||g,onClick:()=>{v.current=!1},children:[m==="existing"&&"Save",m==="copy"&&"Create copy",m==="new"&&"Create"]}),r.jsxs(p.Button,{variant:"filled",color:"primary",type:"submit",disabled:N||g,onClick:()=>{v.current=!0},children:[m==="existing"&&"Save and close",m==="copy"&&"Create copy and close",m==="new"&&"Create and close"]})]})]})}function rc(e){let t={};if(e.inner){if(e.inner.length===0)return ke.setIn(t,e.path,e.message);for(const o of e.inner)ke.getIn(t,o.path)||(t=ke.setIn(t,o.path,o.message))}return t}function oc(e,t){return e?.path===t?.path&&e?.entityId===t?.entityId&&L(e?.values,t?.values)&&L(e?.collection,t?.collection)}function Mn(e){return Object.keys(nr).includes(e)}const nr={text_field:{key:"text_field",name:"Text field",description:"Simple short text",Icon:p.ShortTextIcon,color:"#2d7ff9",property:{dataType:"string",Field:At}},multiline:{key:"multiline",name:"Multiline",description:"Text with multiple lines",Icon:p.SubjectIcon,color:"#2d7ff9",property:{dataType:"string",multiline:!0,Field:At}},markdown:{key:"markdown",name:"Markdown",description:"Text with advanced markdown syntax",Icon:p.FormatQuoteIcon,color:"#2d7ff9",property:{dataType:"string",markdown:!0,Field:Nn}},url:{key:"url",name:"Url",description:"Text with URL validation",Icon:p.HttpIcon,color:"#154fb3",property:{dataType:"string",url:!0,Field:At}},email:{key:"email",name:"Email",description:"Text with email validation",Icon:p.EmailIcon,color:"#154fb3",property:{dataType:"string",email:!0,Field:At}},switch:{key:"switch",name:"Switch",description:"Boolean true or false field (or yes or no, 0 or 1...)",Icon:p.FlagIcon,color:"#20d9d2",property:{dataType:"boolean",Field:Cn}},select:{key:"select",name:"Select/enum",description:"Select one text value from within an enumeration",Icon:p.ListIcon,color:"#4223c9",property:{dataType:"string",enumValues:[],Field:mo}},multi_select:{key:"multi_select",name:"Multi select",description:"Select multiple text values from within an enumeration",Icon:p.ListAltIcon,color:"#4223c9",property:{dataType:"array",of:{dataType:"string",enumValues:[]},Field:ho}},number_input:{key:"number_input",name:"Number input",description:"Simple number field with validation",Icon:p.NumbersIcon,color:"#bec920",property:{dataType:"number",Field:At}},number_select:{key:"number_select",name:"Number select",description:"Select a number value from within an enumeration",Icon:p.FormatListNumberedIcon,color:"#bec920",property:{dataType:"number",enumValues:[],Field:mo}},multi_number_select:{key:"multi_number_select",name:"Multiple number select",description:"Select multiple number values from within an enumeration",Icon:p.FormatListNumberedIcon,color:"#bec920",property:{dataType:"array",of:{dataType:"number",enumValues:[]},Field:ho}},file_upload:{key:"file_upload",name:"File upload",description:"Input for uploading single files",Icon:p.UploadFileIcon,color:"#f92d9a",property:{dataType:"string",storage:{storagePath:"{path}"},Field:go}},multi_file_upload:{key:"multi_file_upload",name:"Multiple file upload",description:"Input for uploading multiple files",Icon:p.DriveFolderUploadIcon,color:"#f92d9a",property:{dataType:"array",of:{dataType:"string",storage:{storagePath:"{path}"}},Field:go}},reference:{key:"reference",name:"Reference",description:"The value refers to a different collection",Icon:p.LinkIcon,color:"#ff0042",property:{dataType:"reference",Field:En}},multi_references:{key:"multi_references",name:"Multiple references",description:"Multiple values that refer to a different collection",Icon:p.AddLinkIcon,color:"#ff0042",property:{dataType:"array",of:{dataType:"reference"},Field:kn}},date_time:{key:"date_time",name:"Date/time",description:"A date time select field",Icon:p.ScheduleIcon,color:"#8b46ff",property:{dataType:"date",Field:xn}},group:{key:"group",name:"Group",description:"Group of multiple fields",Icon:p.BallotIcon,color:"#ff9408",property:{dataType:"map",properties:{},Field:Bn}},key_value:{key:"key_value",name:"Key-value",description:"Flexible field that allows the user to add multiple key-value pairs",Icon:p.BallotIcon,color:"#ff9408",property:{dataType:"map",keyValue:!0,Field:Sn}},repeat:{key:"repeat",name:"Repeat/list",description:"A field that gets repeated multiple times (e.g. multiple text fields)",Icon:p.RepeatIcon,color:"#ff9408",property:{dataType:"array",of:{dataType:"string"},Field:In}},custom_array:{key:"custom_array",name:"Custom array",description:"A field that saved its value as an array of custom objects",Icon:p.RepeatIcon,color:"#ff9408",property:{dataType:"array",of:[],Field:Pn}},block:{key:"block",name:"Block",description:"A complex field that allows the user to compose different fields together, with a key->value format",Icon:p.ViewStreamIcon,color:"#ff9408",property:{dataType:"array",oneOf:{properties:{}},Field:Fn}}};function On(e){const t=ir(e);if(!t){console.error("No field id found for property",e);return}return nr[t]}function It(e,t){const o=ko(e),a=ir(e);if(!a){console.error("No field id found for property",e);return}const i=nr[a],n=o?t[o]:void 0;return De(i??{},n??{})}function ir(e){if(e.dataType==="string")return e.multiline?"multiline":e.markdown?"markdown":e.storage?"file_upload":e.url?"url":e.email?"email":e.enumValues?"select":"text_field";if(e.dataType==="number")return e.enumValues?"number_select":"number_input";if(e.dataType==="map")return e.keyValue?"key_value":"group";if(e.dataType==="array"){const t=e.of;return e.oneOf?"block":Array.isArray(t)?"custom_array":_e(t)?"repeat":t?.dataType==="string"&&t.enumValues?"multi_select":t?.dataType==="number"&&t.enumValues?"multi_number_select":t?.dataType==="string"&&t.storage?"multi_file_upload":t?.dataType==="reference"?"multi_references":"repeat"}else{if(e.dataType==="boolean")return"switch";if(e.dataType==="date")return"date_time";if(e.dataType==="reference")return"reference"}console.error("Unsupported field config mapping",e)}function ko(e){return e.propertyConfig?e.propertyConfig:ir(e)}const Ne=({collection:e,path:t,entityId:o,values:a,previousValues:i,userConfigPersistence:n,fields:s,ignoreMissingFields:l=!1})=>{const c=n?.getCollectionConfig(t),u=Ye(c,"properties"),f=vt(e.properties),g=a??f,m=i??a??f,h=Object.entries(e.properties).map(([b,v])=>{const k=Pe({propertyKey:b,propertyOrBuilder:v,values:g,previousValues:m,path:t,entityId:o,fields:s,ignoreMissingFields:l});return k?{[b]:k}:{}}).filter(b=>b!==null).reduce((b,v)=>({...b,...v}),{}),A=De(h,u),y=Object.entries(A).filter(([b,v])=>!!v?.dataType).map(([b,v])=>({[b]:v})).reduce((b,v)=>({...b,...v}),{});return{...e,properties:y,originalCollection:e}};function Pe({propertyOrBuilder:e,fromBuilder:t=!1,ignoreMissingFields:o=!1,...a}){if(typeof e=="object"&&"resolved"in e)return e;let i=null;if(e)if(_e(e)){const n=a.path;if(!n)throw Error("Trying to resolve a property builder without specifying the entity path");const s=a.propertyKey?ke.getIn(a.values,a.propertyKey):void 0,l=e({...a,path:n,propertyValue:s,values:a.values??{},previousValues:a.previousValues??a.values??{}});if(!l)return null;i=Pe({...a,propertyOrBuilder:l,fromBuilder:!0,ignoreMissingFields:o})}else{const n=e;if(n.dataType==="map"&&n.properties){const s=_o({ignoreMissingFields:o,...a,properties:n.properties});i={...n,resolved:!0,fromBuilder:t,properties:s}}else n.dataType==="array"?i=Xe({property:n,fromBuilder:t,ignoreMissingFields:o,...a}):(n.dataType==="string"||n.dataType==="number")&&n.enumValues&&(i=Co(n,t))}else return null;if(i||(i={...e,resolved:!0,fromBuilder:t}),i.propertyConfig&&!Mn(i.propertyConfig)){const n=a.fields;if(!n&&!o)throw Error(`Trying to resolve a property with key '${i.propertyConfig}' that inherits from a custom property config but no custom property configs were provided. Use the property 'propertyConfigs' in your app config to provide them`);const s=n?.[i.propertyConfig];if(!s)return console.warn(`Trying to resolve a property with key '${i.propertyConfig}' that inherits from a custom property config but no custom property config with that key was found. Check the 'propertyConfigs' in your app config`),console.warn("Available property configs",n),null;if(s.property){const l=s.property;"propertyConfig"in l&&delete l.propertyConfig;const c=Pe({propertyOrBuilder:l,ignoreMissingFields:o,...a});c&&(i=De(c,i))}}return i?{...i,resolved:!0}:null}function Xe({propertyKey:e,property:t,ignoreMissingFields:o=!1,...a}){const i=e?ke.getIn(a.values,e):void 0;if(t.of){if(Array.isArray(t.of))return{...t,resolved:!0,fromBuilder:a.fromBuilder,resolvedProperties:t.of.map((n,s)=>Pe({propertyKey:`${e}.${s}`,propertyOrBuilder:n,ignoreMissingFields:o,...a,index:s}))};{const n=t.of,s=Array.isArray(i)?i.map((c,u)=>Pe({propertyKey:`${e}.${u}`,propertyOrBuilder:n,ignoreMissingFields:o,...a,index:u})).filter(c=>!!c):[],l=Pe({propertyKey:`${e}`,propertyOrBuilder:n,ignoreMissingFields:o,...a});if(!l&&!o)throw Error("When using a property builder as the 'of' prop of an ArrayProperty, you must return a valid child property");return{...t,resolved:!0,fromBuilder:a.fromBuilder,of:l,resolvedProperties:s}}}else if(t.oneOf){const n=t.oneOf?.typeField??yt,s=Array.isArray(i)?i.map((c,u)=>{const f=c&&c[n],g=t.oneOf?.properties[f];return!f||!g?null:Pe({propertyKey:`${e}.${u}`,propertyOrBuilder:g,ignoreMissingFields:o,...a})}).filter(c=>!!c):[],l=_o({properties:t.oneOf.properties,ignoreMissingFields:o,...a});return{...t,resolved:!0,oneOf:{...t.oneOf,properties:l},fromBuilder:a.fromBuilder,resolvedProperties:s}}else{if(t.Field)return{...t,resolved:!0,fromBuilder:a.fromBuilder};throw Error("The array property needs to declare an 'of' or a 'oneOf' property, or provide a custom `Field`")}}function _o({properties:e,ignoreMissingFields:t,...o}){return Object.entries(e).map(([a,i])=>{const n=Pe({propertyKey:a,propertyOrBuilder:i,ignoreMissingFields:t,...o});return n?{[a]:n}:{}}).filter(a=>a!==null).reduce((a,i)=>({...a,...i}),{})}function Co(e,t){return typeof e.enumValues=="object"?{...e,resolved:!0,enumValues:We(e.enumValues)?.filter(o=>o&&(o.id||o.id===0)&&o.label)??[],fromBuilder:t??!1}:e}function ac(e){return typeof e=="object"?Object.entries(e).map(([t,o])=>typeof o=="string"?{id:t,label:o}:o):Array.isArray(e)?e:void 0}function xo(e,t){return typeof e=="string"?t?.find(o=>o.key===e):e}function Eo(e){const{path:t,collections:o=[],currentFullPath:a}=e,i=fe(t).split("/"),n=Qt(i),s=[];for(let l=0;l<n.length;l++){const c=n[l],u=o&&o.find(f=>f.id===c||f.path===c);if(u){const f=u.id??u.path,g=a&&a.length>0?a+"/"+f:f;s.push({type:"collection",path:g,collection:u});const m=fe(fe(t).replace(c,"")),h=m.length>0?m.split("/"):[];if(h.length>0){const A=h[0],y=g+"/"+A;if(s.push({type:"entity",entityId:A,path:g,parentCollection:u}),h.length>1){const b=h.slice(1).join("/");if(!u)throw Error("collection not found resolving path: "+u);const v=u.entityViews,k=v&&v.map(_=>xo(_,e.contextEntityViews)).filter(Boolean).find(_=>_.key===b);if(k){const _=a&&a.length>0?a+"/"+k.key:k.key;s.push({type:"custom_view",path:_,view:k})}else u.subcollections&&s.push(...Eo({path:b,collections:u.subcollections,currentFullPath:y,contextEntityViews:e.contextEntityViews}))}}break}}return s}const nc="100vw",ic="55vw",sr="768px",lr="main_##Q$SC^#S6";function sc({path:e,entityId:t,selectedSubPath:o,copy:a,collection:i,parentCollectionIds:n,onValuesAreModified:s,formWidth:l,onUpdate:c,onClose:u}){i.customId&&i.formAutoSave&&console.warn(`The collection ${i.path} has customId and formAutoSave enabled. This is not supported and formAutoSave will be ignored`);const[f,g]=d.useState(!1),[m,h]=d.useState(void 0);Lt(m,()=>{m&&F({entityId:U?.id,collection:i,path:e,values:m,closeAfterSave:!1})},!1,2e3);const A=Qe(i),y=cr(),b=Je(),v=He(),k=ae(),_=Ae(),E=qe(),[x,B]=d.useState(void 0),[C,S]=d.useState(a?"copy":t?"existing":"new"),N=d.useRef(void 0),I=N.current,P=(i.subcollections??[]).filter(Y=>!Y.hideFromNavigation),D=P?.length??0,G=i.entityViews,R=G?.length??0,K=i.formAutoSave&&!i.customId,W=R>0||D>0,j=o??xr(i?i.defaultSelectedView:void 0,{status:C,entityId:t}),M=d.useRef(j??lr),J=M.current===lr,{entity:H,dataLoading:re,dataLoadingError:oe}=Qr({path:e,entityId:t,collection:i,useCache:!1}),[U,X]=d.useState(H),[Q,ee]=d.useState(void 0);d.useEffect(()=>{H&&X(H)},[H]),d.useEffect(()=>{if(C==="new")ee(!1);else{const Y=U?Ir(i,E,e,U??null):!1;U&&ee(!Y)}},[E,U,C]);const Z=d.useCallback(Y=>{g(!1),v.open({type:"error",message:"Error before saving: "+Y?.message}),console.error(Y)},[v]),$=d.useCallback(Y=>{g(!1),v.open({type:"error",message:"Error after saving (entity is saved): "+Y?.message}),console.error(Y)},[v]),V=(Y,Be)=>{g(!1),K||v.open({type:"success",message:`${i.singularName??i.name}: Saved correctly`}),X(Y),S("existing"),s(!1),c&&c({entity:Y}),Be?(console.log("Closing side dialog"),y.setBlocked(!1),y.close(!0),u?.()):C!=="existing"&&b.replace({path:e,entityId:Y.id,selectedSubPath:M.current,updateUrl:!0,collection:i})},z=d.useCallback(Y=>{g(!1),v.open({type:"error",message:"Error saving: "+Y?.message}),console.error("Error saving entity",e,t),console.error(Y)},[t,e,v]),F=({values:Y,previousValues:Be,closeAfterSave:Se,entityId:$e,collection:Ft,path:Nt})=>(g(!0),Mr({path:Nt,entityId:$e,values:Y,previousValues:Be,collection:Ft,status:C,dataSource:A,context:_,onSaveSuccess:Pt=>V(Pt,Se),onSaveFailure:z,onPreSaveHookError:Z,onSaveSuccessHookError:$}).then()),T=async({collection:Y,path:Be,entityId:Se,values:$e,previousValues:Ft,closeAfterSave:Nt,autoSave:Pt})=>{if(C)if(Pt)h($e);else return F({collection:Y,path:Be,entityId:Se,values:$e,previousValues:Ft,closeAfterSave:Nt})},le=G?G.map(Y=>xo(Y,k.entityViews)).filter(Boolean):[],ve=G&&le.map((Y,Be)=>{if(!Y||M.current!==Y.key)return null;const Se=Y.Builder;return Se?r.jsx("div",{className:p.cls(p.defaultBorderMixin,"relative flex-grow w-full h-full overflow-auto "),role:"tabpanel",children:r.jsx(ne,{children:x&&r.jsx(Se,{collection:i,entity:U,modifiedValues:I??U?.values,formContext:x})})},`custom_view_${Y.key}`):(console.error("customView.Builder is not defined"),null)}).filter(Boolean),te=re&&!U||(!U||Q===void 0)&&(C==="existing"||C==="copy"),O=te||f,ie=P&&P.map((Y,Be)=>{const Se=Y.id??Y.path,$e=U?`${e}/${U?.id}/${fe(Se)}`:void 0;return M.current!==Se?null:r.jsxs("div",{className:"relative flex-grow h-full overflow-auto w-full",role:"tabpanel",children:[O&&r.jsx(rr,{}),!te&&(U&&$e?r.jsx(co,{fullPath:$e,parentCollectionIds:[...n,i.id],isSubCollection:!0,...Y}):r.jsx("div",{className:"flex items-center justify-center w-full h-full p-3",children:r.jsx(p.Typography,{variant:"label",children:"You need to save your entity before adding additional collections"})}))]},`subcol_${Se}`)}).filter(Boolean),me=d.useCallback(()=>{s(!1)},[]),ue=Y=>{M.current=Y,b.replace({path:e,entityId:t,selectedSubPath:Y===lr?void 0:Y,updateUrl:!0,collection:i})},he=d.useCallback(Y=>{N.current=Y},[]),ze=d.useCallback(Y=>{v.open({type:"error",message:"Error updating id, check the console"})},[]),Ve=d.useCallback(Y=>{X(Be=>Be?{...Be,id:Y}:void 0)},[]),Ge=Y=>{K||s(Y)};function Ue(){const Y=k.plugins;let Be=r.jsx(Dn,{status:C,path:e,collection:i,onEntitySaveRequested:T,onDiscard:me,onValuesChanged:he,onModified:Ge,entity:U,onIdChange:Ve,onFormContextChange:B,hideId:i.hideIdFromForm,autoSave:K,onIdUpdateError:ze});return Y&&Y.forEach(Se=>{Se.form?.provider&&(Be=r.jsx(Se.form.provider.Component,{status:C,path:e,collection:i,onDiscard:me,onValuesChanged:he,onModified:Ge,entity:U,context:_,formContext:x,...Se.form.provider.props,children:Be}))}),r.jsx(ne,{children:Be})}const at=Q===void 0?r.jsx(r.Fragment,{}):Q?r.jsxs(r.Fragment,{children:[r.jsx(p.Typography,{className:"mt-16 mb-8 mx-8",variant:"h4",children:i.singularName??i.name}),r.jsx($r,{className:"px-12",entity:U,path:e,collection:i})]}):Ue(),So=P&&P.map(Y=>r.jsx(p.Tab,{className:"text-sm min-w-[140px]",value:Y.id,children:Y.name},`entity_detail_collection_tab_${Y.name}`)),Io=le.map(Y=>r.jsx(p.Tab,{className:"text-sm min-w-[140px]",value:Y.key,children:Y.name},`entity_detail_collection_tab_${Y.name}`));return r.jsx("div",{className:"flex flex-col h-full w-full transition-width duration-250 ease-in-out",children:r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:p.cls(p.defaultBorderMixin,"no-scrollbar border-b pl-2 pr-2 pt-1 flex items-end overflow-scroll bg-gray-50 dark:bg-gray-950"),children:[r.jsx("div",{className:"pb-1 self-center",children:r.jsx(p.IconButton,{onClick:()=>(u?.(),y.close(!1)),size:"large",children:r.jsx(p.CloseIcon,{})})}),r.jsx("div",{className:"flex-grow"}),te&&r.jsx("div",{className:"self-center",children:r.jsx(p.CircularProgress,{size:"small"})}),r.jsxs(p.Tabs,{value:M.current,onValueChange:Y=>{ue(Y)},className:"pl-4 pr-4 pt-0",children:[r.jsx(p.Tab,{disabled:!W,value:lr,className:`${W?"":"hidden"} text-sm min-w-[140px]`,children:i.singularName??i.name}),Io,So]})]}),r.jsxs("div",{className:"flex-grow h-full flex overflow-auto flex-row w-full ",style:{},children:[r.jsx("div",{role:"tabpanel",hidden:!J,id:`form_${e}`,className:" w-full",children:te?r.jsx(rr,{}):at}),ve,ie]})]})})}function lc(e,t){const[o,a]=d.useState(),{navigator:i}=d.useContext(ge.UNSAFE_NavigationContext),n=ge.useNavigate(),s=()=>{a(void 0)},l=()=>{t(),a(void 0),n(-1)},c=d.useCallback(({action:u,location:f,retry:g})=>{switch(u){case"REPLACE":{g();return}case"POP":a(f)}},[]);return d.useEffect(()=>{if(!e||o||!("block"in i))return;const u=i.block(f=>{const g={...f,retry(){u(),f.retry()}};c(g)});return u},[i,c,e,o]),{navigationWasBlocked:!!o,handleCancel:s,handleOk:l}}function cc({open:e,handleOk:t,handleCancel:o,body:a,title:i}){return r.jsxs(p.Dialog,{open:e,onOpenChange:n=>n?o():t(),children:[r.jsxs(p.DialogContent,{children:[r.jsx(p.Typography,{variant:"h6",children:i}),a,r.jsx(p.Typography,{children:"Are you sure you want to leave this page?"})]}),r.jsxs(p.DialogActions,{children:[r.jsx(p.Button,{variant:"text",onClick:o,autoFocus:!0,children:" Cancel "}),r.jsx(p.Button,{onClick:t,children:" Ok "})]})]})}const zn=d.createContext({width:"",blocked:!1,setBlocked:e=>{},setBlockedNavigationMessage:e=>{},close:()=>{}}),cr=()=>d.useContext(zn);function dc(){const t=_t().sidePanels,o=[...t];return o.push(void 0),r.jsx(r.Fragment,{children:o.map((a,i)=>r.jsx(pc,{panel:a,offsetPosition:t.length-i-1},`side_dialog_${i}`))})}function pc({offsetPosition:e,panel:t}){const[o,a]=d.useState(!1),[i,n]=d.useState(!1),[s,l]=d.useState(),c=d.useRef(t?.width),u=c.current,f=_t(),{navigationWasBlocked:g,handleOk:m,handleCancel:h}=lc(i&&!o,()=>n(!1));d.useEffect(()=>{t&&(c.current=t.width)},[t]);const A=()=>{n(!1),a(!1),f.close(),t?.onClose?.()},y=()=>{a(!1)},b=v=>{i&&!v?a(!0):(f.close(),t?.onClose?.())};return r.jsxs(zn.Provider,{value:{blocked:i,setBlocked:n,setBlockedNavigationMessage:l,width:u,close:b},children:[r.jsxs(p.Sheet,{open:!!t,onOpenChange:v=>!v&&b(),children:[t&&r.jsx("div",{className:"transform max-w-[100vw] lg:max-w-[95vw] flex flex-col h-full transition-all duration-250 ease-in-out bg-white dark:bg-gray-900 ",style:{width:t.width,transform:`translateX(-${e*200}px)`},children:r.jsx(ne,{children:t.component})}),!t&&r.jsx("div",{style:{width:u}})]}),r.jsx(cc,{open:g||o,handleOk:o?A:m,handleCancel:o?y:h,body:s})]})}function uc(e){const{blocked:t,setBlocked:o,setBlockedNavigationMessage:a}=cr(),i=pe(),n=d.useMemo(()=>i.getParentCollectionIds(e.path),[i,e.path]),s=d.useMemo(()=>{if(!e)return;let c=e.collection;const u=i.getCollection(e.path);if(u&&(c=u),!c)throw console.error("ERROR: No collection found in path `",e.path,"`. Entity id: ",e.entityId),Error("ERROR: No collection found in path `"+e.path+"`. Make sure you have defined a collection for this path in the root navigation.");return c},[i,e]);d.useEffect(()=>{function c(u){t&&s&&(u.preventDefault(),u.returnValue=`You have unsaved changes in this ${s.name}. Are you sure you want to leave this page?`)}return typeof window<"u"&&window.addEventListener("beforeunload",c),()=>{typeof window<"u"&&window.removeEventListener("beforeunload",c)}},[t,s]);const l=d.useCallback(c=>{o(c),a(c?r.jsxs(r.Fragment,{children:[" You have unsaved changes in this ",r.jsx("b",{children:s?.singularName??s?.name}),"."]}):void 0)},[s?.name,o,a]);return!e||!s?r.jsx("div",{className:"w-full"}):r.jsx(r.Fragment,{children:r.jsx(ne,{children:r.jsx(sc,{...e,formWidth:e.width,collection:s,parentCollectionIds:n,onValuesAreModified:l})})})}const Vn="new";function fc(e,t){if(t)return nc;const o=!e.selectedSubPath;let a;return e.width?a=typeof e.width=="number"?`${e.width}px`:e.width:e.collection?.sideDialogWidth&&(a=typeof e.collection.sideDialogWidth=="number"?`${e.collection.sideDialogWidth}px`:e.collection.sideDialogWidth),o?a||(e.collection?mc(e.collection):sr):`calc(${ic} + ${a??sr})`}const Bo={};function mc(e){if(Bo[e.id])return Bo[e.id];const t=Ne({collection:e,path:"__ignored",ignoreMissingFields:!0});let o=sr;if(t?.properties){const a=Object.values(t.properties).map(n=>dr(n)),i=Math.max(...a);i<3?o=sr:o=768+32*(i-2)+"px"}return Bo[e.id]=o,o}function dr(e,t=0){if(e.dataType==="map"&&e.properties){const o=Object.values(e.properties).flatMap(a=>dr(a,t+1));return Math.max(...o)}else return e.dataType==="array"&&e.oneOf?t+3:e.dataType==="array"&&e.of?Array.isArray(e.of)?Math.max(...e.of.map(o=>dr(o,t+1))):dr(e.of,t+1):t+1}const hc=(e,t)=>{const o=ge.useLocation(),a=d.useRef(!1),i=!Me();d.useEffect(()=>{if(!e.loading&&!a.current){if(console.debug("Initialising side entity controller"),e.isUrlCollectionPath(o.pathname)){const c=o.hash===`#${Vn}`,u=e.urlPathToDataPath(o.pathname),f=gc(u,e.collections??[],c);for(let g=0;g<f.length;g++){const m=f[g];setTimeout(()=>{g===0?t.replace(pr(m,e.buildUrlCollectionPath,e.resolveAliasesFrom,i)):t.open(pr(m,e.buildUrlCollectionPath,e.resolveAliasesFrom,i))},1)}}a.current=!0}},[o,e.loading,e.isUrlCollectionPath,e.buildUrlCollectionPath,e.resolveAliasesFrom,t,i,e]);const n=d.useCallback(()=>{t.close()},[t]),s=d.useCallback(c=>{if(c.copy&&!c.entityId)throw Error("If you want to copy an entity you need to provide an entityId");const u=xr(c.collection?c.collection.defaultSelectedView:void 0,{status:c.copy?"copy":c.entityId?"existing":"new",entityId:c.entityId});t.open(pr({selectedSubPath:u,...c},e.buildUrlCollectionPath,e.resolveAliasesFrom,i))},[t,e.buildUrlCollectionPath,e.resolveAliasesFrom,i]),l=d.useCallback(c=>{if(c.copy&&!c.entityId)throw Error("If you want to copy an entity you need to provide an entityId");t.replace(pr(c,e.buildUrlCollectionPath,e.resolveAliasesFrom,i))},[e.buildUrlCollectionPath,e.resolveAliasesFrom,t,i]);return{close:n,open:s,replace:l}};function gc(e,t,o){const a=Eo({path:e,collections:t}),i=[];let n="";for(let s=0;s<a.length;s++){const l=a[s];if(l.type==="collection"&&(n=l.path),s>0){const c=a[s-1];if(l.type==="entity")i.push({path:l.path,entityId:l.entityId,copy:!1,width:l.parentCollection?.sideDialogWidth});else if(l.type==="custom_view"){if(c.type==="entity"){const u=i[i.length-1];u&&(u.selectedSubPath=l.view.key)}}else if(l.type==="collection"&&c.type==="entity"){const u=i[i.length-1];u&&(u.selectedSubPath=l.collection.id??l.collection.path)}}}return o&&i.push({path:n,copy:!1}),i}const pr=(e,t,o,a)=>{const i=fe(e.path),n=e.entityId?t(`${i}/${e.entityId}/${e.selectedSubPath||""}`):t(`${i}#${Vn}`),s=o(e.path),l={...e,path:s};return{key:`${e.path}/${e.entityId}`,component:r.jsx(uc,{...l}),urlPath:n,parentUrlPath:t(i),width:fc(e,a),onClose:e.onClose}};function Ac(){const e=ge.useLocation(),t=ge.useNavigate(),[o,a]=d.useState([]),i=d.useRef(o),n=d.useRef({}),s=d.useRef(0),l=g=>{i.current=g,a(g)};d.useEffect(()=>{const h=(e.state?.panels??[]).map(A=>n.current[A]).filter(A=>!!A);L(i.current.map(A=>A.key),h.map(A=>A.key))||l(h)},[e]);const c=d.useCallback(()=>{if(o.length===0)return;const g=o[o.length-1],m=[...o.slice(0,-1)];if(l(m),s.current>0)g.urlPath&&t(-1),s.current--;else if(g.parentUrlPath){const h=e.state?.base_location??e;t(g.parentUrlPath,{replace:!0,state:{base_location:h,panels:m.map(A=>A.key)}})}},[o,t,e]),u=d.useCallback(g=>{const m=Array.isArray(g)?g:[g];m.forEach(y=>{n.current[y.key]=y}),s.current=s.current+m.length;const h=e.state?.base_location??e,A=[...o,...m];l(A),m.forEach(y=>{y.urlPath&&t(y.urlPath,{state:{base_location:h,panels:A.map(b=>b.key)}})})},[e,t,o]),f=d.useCallback(g=>{const m=Array.isArray(g)?g:[g];m.forEach(y=>{n.current[y.key]=y});const h=e.state?.base_location??e,A=[...o.slice(0,-m.length),...m];l(A),m.forEach(y=>{y.urlPath&&t(y.urlPath,{replace:!0,state:{base_location:h,panels:A.map(b=>b.key)}})})},[e,t,o]);return{sidePanels:o,close:c,open:u,replace:f}}function bc({delegate:e,propertyConfigs:t,navigationController:o}){return{fetchCollection:d.useCallback(({path:a,collection:i,filter:n,limit:s,startAfter:l,searchString:c,orderBy:u,order:f})=>e.fetchCollection({path:a,filter:n,limit:s,startAfter:l,searchString:c,orderBy:u,order:f}),[e]),listenCollection:e.listenCollection?d.useCallback(({path:a,collection:i,filter:n,limit:s,startAfter:l,searchString:c,orderBy:u,order:f,onUpdate:g,onError:m})=>{const h=i??o.getCollection(a),A=!!h?.collectionGroup;if(!e.listenCollection)throw Error("useBuildDataSource delegate not initialised");return e.listenCollection({path:a,filter:n,limit:s,startAfter:l,searchString:c,orderBy:u,order:f,onUpdate:g,onError:m,isCollectionGroup:A,collection:h})},[e,o.getCollection]):void 0,fetchEntity:d.useCallback(({path:a,entityId:i})=>e.fetchEntity({path:a,entityId:i}),[e]),listenEntity:e.listenEntity?d.useCallback(({path:a,entityId:i,collection:n,onUpdate:s,onError:l})=>{if(!e.listenEntity)throw Error("useBuildDataSource delegate not initialised");return e.listenEntity({path:a,entityId:i,onUpdate:s,onError:l})},[e.listenEntity]):void 0,saveEntity:d.useCallback(({path:a,entityId:i,values:n,collection:s,status:l})=>{const c=s??o.getCollection(a),f=(c?Ne({collection:c,path:a,entityId:i,fields:t}):void 0)?.properties,g=e.cmsToDelegateModel(n),m=f?Go({inputValues:g,properties:f,status:l,timestampNowValue:e.currentTime(),setDateToMidnight:e.setDateToMidnight}):g;return e.saveEntity({path:a,entityId:i,values:m,status:l}).then(h=>({id:h.id,path:h.path,values:e.delegateToCMSModel(m)}))},[e.saveEntity,o.getCollection]),deleteEntity:d.useCallback(({entity:a})=>e.deleteEntity({entity:a}),[e.deleteEntity]),checkUniqueField:d.useCallback((a,i,n,s)=>e.checkUniqueField(a,i,n,s),[e.checkUniqueField]),generateEntityId:d.useCallback(a=>e.generateEntityId(a),[e.generateEntityId]),countEntities:e.countEntities?async({path:a,collection:i,filter:n,order:s,orderBy:l})=>e.countEntities({path:a,filter:n,orderBy:l,order:s,isCollectionGroup:!!i.collectionGroup}):void 0,isFilterCombinationValid:d.useCallback(({path:a,filterValues:i,sortBy:n})=>e.isFilterCombinationValid?e.isFilterCombinationValid({path:a,filterValues:i,sortBy:n}):!0,[e.isFilterCombinationValid]),initTextSearch:d.useCallback(async a=>e.initTextSearch?e.initTextSearch(a):!1,[e.initTextSearch])}}const yc="https://api-drplyi3b6q-ey.a.run.app";async function wc(e,t){const o=await e.getAuthToken();return fetch(yc+"/access_log",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Basic ${o}`},body:JSON.stringify({plugins:t})}).then(async a=>a.json())}function vc(e,t){const[o,a]=d.useState(null),i=d.useRef(null),n=t?.map(s=>s.key);return d.useEffect(()=>{e.user&&e.user.uid!==i.current&&!e.initialLoading&&(wc(e,n).then(a),i.current=e.user.uid)},[e,n]),o}function kc(e){const{children:t,entityLinkBuilder:o,userConfigPersistence:a,dateTimeFormat:i,locale:n,authController:s,storageSource:l,dataSourceDelegate:c,plugins:u,onAnalyticsEvent:f,propertyConfigs:g,entityViews:m,components:h,navigationController:A}=e;p.useLocaleConfig(n);const y=bc({delegate:c,propertyConfigs:g,navigationController:A}),b=Ac(),v=hc(A,b),k=u?.some(C=>C.loading)??!1,_=s.initialLoading||A.loading||k,E={dateTimeFormat:i,locale:n,entityLinkBuilder:o,plugins:u,entityViews:m??[],propertyConfigs:g??{},components:h},x=d.useMemo(()=>({onAnalyticsEvent:f}),[]),B=vc(s,u);return A.navigationLoadingError?r.jsx(p.CenteredView,{maxWidth:"md",children:r.jsx(ye,{title:"Error loading navigation",error:A.navigationLoadingError})}):s.authError?r.jsx(p.CenteredView,{maxWidth:"md",children:r.jsx(ye,{title:"Error loading auth",error:s.authError})}):B?.blocked?r.jsxs(p.CenteredView,{maxWidth:"md",fullScreen:!0,children:[r.jsx(p.Typography,{variant:"h4",children:"Access blocked"}),r.jsxs(p.Typography,{children:["This app has been blocked. Please reach out at ",r.jsx("a",{href:"mailto:hello@firecms.co",children:"hello@firecms.co"})," for more information."]}),B?.message&&r.jsxs(p.Typography,{children:["Response from the server: ",B?.message]})]}):r.jsx(ga.Provider,{value:x,children:r.jsx(ha.Provider,{value:E,children:r.jsx(ua.Provider,{value:a,children:r.jsx(pa.Provider,{value:l,children:r.jsx(sa.Provider,{value:y,children:r.jsx(mr.Provider,{value:s,children:r.jsx(ca.Provider,{value:b,children:r.jsx(da.Provider,{value:v,children:r.jsx(la.Provider,{value:A,children:r.jsx(Mi,{children:r.jsx(_c,{loading:_,children:t})})})})})})})})})})})}function _c({loading:e,children:t}){const o=Ae(),a=ae();let i=t({context:o,loading:e});const n=a.plugins;return!e&&n&&n.forEach(s=>{s.provider&&(i=r.jsx(s.provider.Component,{...s.provider.props,context:o,children:i}))}),r.jsx(r.Fragment,{children:i})}function Gn({name:e,icon:t,drawerOpen:o,tooltipsOpen:a,url:i,onClick:n}){const s=r.jsx("div",{className:"text-gray-600 dark:text-gray-500",children:t}),l=r.jsxs(ge.NavLink,{onClick:n,style:{width:o?"280px":"72px",transition:o?"width 150ms ease-in":void 0},className:({isActive:c})=>p.cls("rounded-r-lg truncate","hover:bg-slate-300 hover:bg-opacity-75 dark:hover:bg-gray-700 dark:hover:bg-opacity-75 text-gray-800 dark:text-gray-200 hover:text-gray-900 hover:dark:text-white","flex flex-row items-center mr-8",o?"pl-8 h-12":"pl-6 h-11","font-medium text-sm",c?"bg-slate-200 bg-opacity-60 dark:bg-gray-800 dark:bg-opacity-30":""),to:i,children:[s,r.jsx("div",{className:p.cls(o?"opacity-100":"opacity-0 hidden","ml-4 font-inherit text-inherit"),children:e.toUpperCase()})]});return r.jsx(p.Tooltip,{open:o?!1:a,side:"right",title:e,children:l})}function Yn(){const{hovered:e,drawerOpen:t,closeDrawer:o}=Un(),a=ut(),i=pe(),n=e&&!t,s=Me(),l=ge.useNavigate(),[c,u]=d.useState(!1);if(!i.topLevelNavigation)throw Error("Navigation not ready in Drawer");const{navigationEntries:f,groups:g}=i.topLevelNavigation,m=f.filter(b=>b.type==="admin")??[],h=g.filter(b=>b!=="Admin"),A=d.useCallback(b=>t?r.jsx("div",{className:"pt-8 pl-6 pr-8 pb-2 flex flex-row items-center",children:r.jsx(p.Typography,{variant:"caption",color:"secondary",className:"font-medium flex-grow line-clamp-1",children:b?b.toUpperCase():"Views".toUpperCase()})}):r.jsx("div",{className:"h-12 w-full"}),[t]),y=b=>{const v=b.type==="collection"?"drawer_navigate_to_collection":b.type==="view"?"drawer_navigate_to_view":"unmapped_event";a.onAnalyticsEvent?.(v,{url:b.url}),s||o()};return r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"flex-grow overflow-scroll no-scrollbar",children:h.map(b=>r.jsxs(d.Fragment,{children:[A(b),Object.values(f).filter(v=>v.group===b).map((v,k)=>r.jsx(Gn,{icon:r.jsx(Jt,{collectionOrView:v.collection??v.view}),tooltipsOpen:n,drawerOpen:t,onClick:()=>y(v),url:v.url,name:v.name},`navigation_${k}`))]},`drawer_group_${b}`))}),m.length>0&&r.jsx(p.Menu,{open:c,onOpenChange:u,trigger:r.jsxs(p.IconButton,{shape:"square",className:"m-4 text-gray-900 dark:text-white w-fit",children:[r.jsx(p.Tooltip,{title:"Admin",open:n,side:"right",sideOffset:28,children:r.jsx(p.MoreVertIcon,{})}),t&&r.jsx("div",{className:p.cls(t?"opacity-100":"opacity-0 hidden","mx-4 font-inherit text-inherit"),children:"ADMIN"})]}),children:m.map((b,v)=>r.jsxs(p.MenuItem,{onClick:k=>{k.preventDefault(),l(b.path)},children:[r.jsx(Jt,{collectionOrView:b.view}),b.name]},`navigation_${v}`))})]})}const Ln=280,jn=d.createContext({hovered:!1,drawerOpen:!1,openDrawer:()=>{throw new Error("openDrawer not implemented")},closeDrawer:()=>{throw new Error("closeDrawer not implemented")},autoOpenDrawer:!1});function Un(){return d.useContext(jn)}const Cc=d.memo(function(t){const{children:o,name:a,logo:i,includeDrawer:n=!0,autoOpenDrawer:s,drawer:l=r.jsx(Yn,{}),FireCMSAppBar:c=wn,fireCMSAppBarProps:u}=t,f=Me(),[g,m]=d.useState(!1),[h,A]=d.useState(!1),y=d.useCallback(()=>A(!0),[]),b=d.useCallback(()=>A(!1),[]),v=d.useCallback(()=>{m(!0)},[]),k=d.useCallback(()=>{m(!1)},[]),_=g||!!(f&&s&&h);return r.jsx(jn.Provider,{value:{hovered:h,drawerOpen:_,closeDrawer:k,openDrawer:v,autoOpenDrawer:s},children:r.jsxs("div",{className:"flex h-screen w-screen bg-gray-50 dark:bg-gray-900 text-gray-900 dark:text-white overflow-hidden",style:{paddingTop:"env(safe-area-inset-top)",paddingLeft:"env(safe-area-inset-left)",paddingRight:"env(safe-area-inset-right)",paddingBottom:"env(safe-area-inset-bottom)",height:"100dvh"},children:[r.jsx(c,{title:a,includeDrawer:n,logo:i,drawerOpen:_,...u}),r.jsx(Ec,{displayed:n,onMouseEnter:y,onMouseMove:y,onMouseLeave:b,open:_,logo:i,hovered:h,setDrawerOpen:m,children:n&&l}),r.jsxs("main",{className:"flex flex-col flex-grow overflow-auto",children:[r.jsx(xc,{}),r.jsx("div",{className:p.cls(p.defaultBorderMixin,"flex-grow overflow-auto lg:m-0 lg:mx-4 lg:mb-4 lg:rounded-lg lg:border lg:border-solid m-0 mt-1"),children:r.jsx(ne,{children:o})})]})]})})},L),xc=()=>r.jsx("div",{className:"flex flex-col min-h-[68px]"});function Ec(e){const t=pe(),o=e.displayed?e.open?Ln:72:0,a=r.jsxs("div",{className:"relative h-full no-scrollbar overflow-y-auto overflow-x-hidden",style:{width:o,transition:"left 100ms cubic-bezier(0.4, 0, 0.6, 1) 0ms, opacity 100ms cubic-bezier(0.4, 0, 0.6, 1) 0ms, width 100ms cubic-bezier(0.4, 0, 0.6, 1) 0ms"},children:[!e.open&&e.displayed&&r.jsx(p.Tooltip,{title:"Open menu",side:"right",sideOffset:12,className:"fixed top-2 left-3 !bg-gray-50 dark:!bg-gray-900 rounded-full w-fit",children:r.jsx(p.IconButton,{color:"inherit","aria-label":"Open menu",className:"sticky top-2 left-3 ",onClick:()=>e.setDrawerOpen(!0),size:"large",children:r.jsx(p.MenuIcon,{})})}),r.jsxs("div",{className:"flex flex-col h-full",children:[r.jsx("div",{style:{transition:"padding 100ms cubic-bezier(0.4, 0, 0.6, 1) 0ms",padding:e.open?"32px 144px 0px 24px":"72px 16px 0px"},className:p.cls("cursor-pointer"),children:r.jsx(p.Tooltip,{title:"Home",sideOffset:20,side:"right",children:r.jsx(ge.Link,{to:t.basePath,children:e.logo?r.jsx("img",{src:e.logo,alt:"Logo",className:p.cls("max-w-full max-h-full",e.open??"w-[112px] h-[112px]")}):r.jsx(po,{})})})}),e.children]})]});return Me()?r.jsxs("div",{className:"relative",onMouseEnter:e.onMouseEnter,onMouseMove:e.onMouseMove,onMouseLeave:e.onMouseLeave,style:{width:o,transition:"left 100ms cubic-bezier(0.4, 0, 0.6, 1) 0ms, opacity 100ms cubic-bezier(0.4, 0, 0.6, 1) 0ms, width 100ms cubic-bezier(0.4, 0, 0.6, 1) 0ms"},children:[a,r.jsx("div",{className:`absolute right-0 top-4 ${e.open?"opacity-100":"opacity-0 invisible"} transition-opacity duration-1000 ease-in-out`,children:r.jsx(p.IconButton,{"aria-label":"Close drawer",onClick:()=>e.setDrawerOpen(!1),children:r.jsx(p.ChevronLeftIcon,{})})})]}):e.displayed?r.jsxs(r.Fragment,{children:[r.jsx(p.IconButton,{color:"inherit","aria-label":"Open drawer",onClick:()=>e.setDrawerOpen(!0),size:"large",className:"absolute top-2 left-6",children:r.jsx(p.MenuIcon,{})}),r.jsx(p.Sheet,{side:"left",transparent:!0,open:e.open,onOpenChange:e.setDrawerOpen,children:a})]}):null}const Bc=d.memo(function({homePage:t=r.jsx(gn,{}),customRoutes:o}){const a=ge.useLocation(),i=pe();if(!i)return r.jsx(r.Fragment,{});const n=a.state,s=n&&n.base_location?n.base_location:a,l=[];i.views&&i.views.forEach(m=>{Array.isArray(m.path)?l.push(...m.path.map(h=>ur(h,m))):l.push(ur(m.path,m))}),i.adminViews&&i.adminViews.forEach(m=>{Array.isArray(m.path)?l.push(...m.path.map(h=>ur(h,m))):l.push(ur(m.path,m))});const u=[...i.collections??[]].sort((m,h)=>h.path.length-m.path.length).map(m=>{const h=i.buildUrlCollectionPath(m.id??m.path);return r.jsx(ge.Route,{path:h+"/*",element:r.jsx(ne,{children:r.jsx(co,{isSubCollection:!1,parentCollectionIds:[],fullPath:m.id??m.path,...m,Actions:Bt(m.Actions)},`collection_view_${m.id??m.path}`)})},`navigation_${m.id??m.path}`)}),f=r.jsx(ge.Route,{path:"/",element:t}),g=r.jsx(ge.Route,{path:"*",element:r.jsx(yn,{})});return r.jsxs(ge.Routes,{location:s,children:[u,l,f,g,o]})}),ur=(e,t)=>r.jsx(ge.Route,{path:e,element:t.view},"navigation_view_"+e);w.ArrayContainer=uo,w.ArrayContainerItem=fo,w.ArrayCustomShapedFieldBinding=Pn,w.ArrayEnumPreview=Lr,w.ArrayItemOptions=vn,w.ArrayOfMapsPreview=hs,w.ArrayOfReferencesFieldBinding=kn,w.ArrayOfReferencesPreview=Ta,w.ArrayOfStorageComponentsPreview=Da,w.ArrayOfStringsPreview=Qa,w.ArrayOneOfPreview=Ma,w.ArrayPropertyEnumPreview=jr,w.ArrayPropertyPreview=Yr,w.AsyncPreviewComponent=gs,w.AuthControllerContext=mr,w.BlockFieldBinding=Fn,w.BooleanPreview=Va,w.COLLECTION_PATH_SEPARATOR=Wo,w.CircularProgressCenter=rr,w.DEFAULT_FIELD_CONFIGS=nr,w.DRAWER_WIDTH=Ln,w.DatePreview=za,w.DateTimeFieldBinding=xn,w.DefaultHomePage=gn,w.DeleteConfirmationDialog=El,w.Drawer=Yn,w.DrawerNavigationItem=Gn,w.EmptyValue=et,w.EntityCollectionRowActions=er,w.EntityCollectionTable=to,w.EntityCollectionView=co,w.EntityCollectionViewActions=An,w.EntityForm=Dn,w.EntityReference=gr,w.EntityView=$r,w.EnumValuesChip=Ie,w.ErrorBoundary=ne,w.ErrorView=ye,w.FieldCaption=Pl,w.FieldHelperText=xe,w.FireCMS=kc,w.FireCMSAppBar=wn,w.FireCMSLogo=po,w.FormikArrayContainer=ar,w.GeoPoint=Ar,w.IconForView=Jt,w.ImagePreview=Ba,w.KeyValueFieldBinding=Sn,w.KeyValuePreview=Ur,w.LabelWithIcon=Ee,w.MapFieldBinding=Bn,w.MapPropertyPreview=Oa,w.MarkdownFieldBinding=Nn,w.ModeControllerContext=fr,w.ModeControllerProvider=ai,w.MultiSelectBinding=ho,w.NavigationCard=fn,w.NavigationCardBinding=hn,w.NavigationGroup=so,w.NavigationRoutes=Bc,w.NotFoundPage=yn,w.NumberPropertyPreview=Ga,w.PropertyConfigBadge=xl,w.PropertyFieldBinding=ot,w.PropertyPreview=we,w.PropertyTableCell=Xa,w.ReadOnlyFieldBinding=Ao,w.ReferenceFieldBinding=En,w.ReferencePreview=Oe,w.ReferenceSelectionTable=un,w.ReferenceWidget=Il,w.RepeatFieldBinding=In,w.Scaffold=Cc,w.SearchIconsView=Nl,w.SelectFieldBinding=mo,w.SelectableTable=ln,w.SelectableTableContext=Hr,w.SideDialogs=dc,w.SkeletonPropertyComponent=tt,w.SmallNavigationCard=mn,w.SnackbarProvider=ri,w.StorageThumbnail=Sa,w.StorageThumbnailInternal=Fa,w.StorageUploadFieldBinding=go,w.StringPropertyPreview=Gr,w.SwitchFieldBinding=Cn,w.TextFieldBinding=At,w.UrlComponentPreview=xt,w.Vector=si,w.VirtualTable=rn,w.addInitialSlash=ni,w.applyPermissionsFunctionIfEmpty=Uo,w.archiveEntityAction=cl,w.buildAdditionalFieldDelegate=Ti,w.buildCollection=Ei,w.buildEntityCallbacks=Pi,w.buildEnumLabel=Lo,w.buildEnumValueConfig=Ni,w.buildEnumValues=Fi,w.buildFieldConfig=Di,w.buildIdColumn=qs,w.buildProperties=Si,w.buildPropertiesOrBuilder=Ii,w.buildProperty=Bi,w.canCreateEntity=ct,w.canDeleteEntity=$t,w.canEditEntity=Ir,w.copyEntityAction=no,w.defaultDateFormat=$o,w.deleteEntityAction=io,w.deleteEntityWithCallbacks=Aa,w.editEntityAction=pn,w.enumToObjectEntries=We,w.flattenObject=Nr,w.fullPathToCollectionSegments=Br,w.getArrayValuesCount=ea,w.getBracketNotation=vi,w.getCollectionByPathOrId=Dt,w.getCollectionPathsCombinations=Qt,w.getColorForProperty=wi,w.getColorScheme=Yo,w.getColumnKeysForProperty=tr,w.getDefaultFieldConfig=On,w.getDefaultFieldId=ir,w.getDefaultPropertiesOrder=ki,w.getDefaultValueFor=zt,w.getDefaultValueForDataType=kr,w.getDefaultValuesFor=vt,w.getEntityImagePreviewPropertyKey=Ro,w.getEntityPreviewKeys=Ko,w.getEntityTitlePropertyKey=Fr,w.getFieldConfig=It,w.getFieldId=ko,w.getHashValue=yr,w.getIcon=Xo,w.getIconForProperty=Ce,w.getIconForWidget=jt,w.getIdIcon=yi,w.getLabelOrConfigFrom=Gt,w.getLastSegment=ii,w.getPropertiesWithPropertiesOrder=Zo,w.getPropertyInPath=Re,w.getRandomId=St,w.getReferenceFrom=Le,w.getResolvedPropertyInPath=Sr,w.getSidePanelKey=Wi,w.getValueInPath=Ye,w.hydrateRegExp=Jo,w.iconSynonyms=Wt,w.iconsSearch=qt,w.isDefaultFieldConfigId=Mn,w.isEmptyObject=vr,w.isEnumValueDisabled=di,w.isHidden=wt,w.isObject=Mt,w.isPropertyBuilder=_e,w.isReadOnly=st,w.isReferenceProperty=Ho,w.isValidRegExp=bi,w.joinCollectionLists=oa,w.makePropertiesEditable=ta,w.makePropertiesNonEditable=ra,w.mergeCollection=aa,w.mergeDeep=De,w.openWebsiteAction=dl,w.pick=zo,w.plural=Ci,w.printChanged=Tr,w.propertiesToColumns=en,w.randomColor=hi,w.randomString=lt,w.removeFunctions=br,w.removeInPath=li,w.removeInitialAndTrailingSlashes=fe,w.removeInitialSlash=Mo,w.removePropsIfExisting=Vo,w.removeTrailingSlash=Oo,w.removeUndefined=wr,w.renderSkeletonCaptionText=ls,w.renderSkeletonIcon=Vr,w.renderSkeletonImageThumbnail=zr,w.renderSkeletonText=je,w.resolveArrayProperty=Xe,w.resolveCollection=Ne,w.resolveCollectionPathIds=hr,w.resolveDefaultSelectedView=xr,w.resolveEntityView=xo,w.resolveEnumValues=ac,w.resolveNavigationFrom=ba,w.resolvePermissions=kt,w.resolveProperties=_o,w.resolveProperty=Pe,w.resolvePropertyEnum=Co,w.sanitizeData=ci,w.saveEntityWithCallbacks=Mr,w.segmentsToStrippedPath=qo,w.serializeRegExp=Ai,w.singular=xi,w.slugify=Yt,w.sortProperties=Cr,w.stripCollectionPath=Er,w.toKebabCase=ui,w.toSnakeCase=mi,w.traverseValueProperty=Vt,w.traverseValuesProperties=_r,w.unslugify=gi,w.updateDateAutoValues=Go,w.useAuthController=qe,w.useBrowserTitleAndIcon=Li,w.useBuildLocalConfigurationPersistence=Hi,w.useBuildModeController=Zi,w.useBuildNavigationController=$i,w.useClearRestoreValue=Te,w.useClipboard=wa,w.useCollectionFetch=Oi,w.useColumnIds=Kr,w.useCustomizationController=ae,w.useDataSource=Qe,w.useDataSourceEntityCollectionTableController=ro,w.useDebouncedCallback=Lt,w.useDebouncedData=cn,w.useDialogsController=ma,w.useDrawer=Un,w.useEntityFetch=Qr,w.useFireCMSContext=Ae,w.useLargeLayout=Me,w.useModeController=ya,w.useNavigationController=pe,w.useReferenceDialog=ft,w.useResolvedNavigationFrom=zi,w.useSelectableTableController=Za,w.useSelectionController=oo,w.useSideDialogContext=cr,w.useSideDialogsController=_t,w.useSideEntityController=Je,w.useSnackbarController=He,w.useStorageSource=dt,w.useTableSearchHelper=ao,w.useTraceUpdate=Qi,w.useValidateAuthenticator=Xi,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
|
|
588
|
+
`;function Pn({propertyKey:e,value:t,error:o,showError:a,isSubmitting:i,setValue:n,tableMode:s,property:l,includeDescription:c,underlyingValueHasChanged:u,context:f,disabled:g}){if(!Array.isArray(l.resolvedProperties))throw Error("ArrayCustomShapedFieldBinding misconfiguration. Property `of` not set");const m=l.expanded===void 0?!0:l.expanded;Te({property:l,value:t,setValue:n});const h=r.jsx(Ee,{icon:Ce(l,"small"),required:l.validation?.required,className:"text-text-secondary dark:text-text-secondary-dark",title:l.name}),A=l.resolvedProperties.map((y,b)=>{const v={propertyKey:`${e}[${b}]`,disabled:g,property:y,includeDescription:c,underlyingValueHasChanged:u,context:f,tableMode:!1,partOfArray:!0,partOfBlock:!1,autoFocus:!1};return r.jsx("div",{className:"pb-4",children:r.jsx(ot,{...v})},`custom_shaped_array_${b}`)});return r.jsxs(r.Fragment,{children:[!s&&r.jsx(p.ExpandablePanel,{initiallyExpanded:m,title:h,className:"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2",children:A}),s&&A,r.jsx(xe,{includeDescription:c,showError:a,error:o,disabled:g,property:l})]})}const Zl=({containerRef:e})=>{const{isSubmitting:t,isValidating:o,errors:a}=ke.useFormex();return d.useEffect(()=>{const i=Object.keys(a);if(i.length>0&&t&&!o){const n=e?.current?.querySelector(`#form_field_${i[0]}`);if(n&&e?.current){const s=Tn(e.current);if(s){const c=n.getBoundingClientRect().top;s.scrollTo({top:s.scrollTop+c-196,behavior:"smooth"})}const l=n.querySelector("input");l&&l.focus()}}},[t,o,a,e]),null},Xl=e=>{const t=e&&e.scrollHeight>e.clientHeight,o=e?window.getComputedStyle(e).overflowY:null,a=o&&o.indexOf("hidden")!==-1;return t&&!a},Tn=e=>!e||e===document.body?document.body:Xl(e)?e:Tn(e.parentNode);function Kl({customId:e,entityId:t,status:o,onChange:a,error:i,entity:n,loading:s}){const{errors:l}=ke.useFormex(),c=o==="existing"||!e,u=o!=="existing"&&!e,f=d.useMemo(()=>{if(!(!e||typeof e=="boolean"||e==="optional"))return We(e)},[e]),g=He(),{copy:m}=wa({onSuccess:y=>g.open({type:"success",message:`Copied ${y}`})}),h=ae(),A={label:u?"ID is set automatically":"ID",disabled:c||s,name:"id",value:(n&&o==="existing"?n.id:t)??"",endAdornment:s?r.jsx(p.CircularProgress,{size:"small"}):n?r.jsxs(r.Fragment,{children:[r.jsx(p.Tooltip,{title:"Copy",children:r.jsx(p.IconButton,{onClick:y=>m(n.id),"aria-label":"copy-id",children:r.jsx(p.ContentCopyIcon,{size:"small"})})}),h?.entityLinkBuilder&&r.jsx(p.Tooltip,{title:"Open in the console",children:r.jsx(p.IconButton,{component:"a",href:h.entityLinkBuilder({entity:n}),rel:"noopener noreferrer",target:"_blank",onClick:y=>y.stopPropagation(),"aria-label":"go-to-datasource",children:r.jsx(p.OpenInNewIcon,{size:"small"})})})]}):void 0};return r.jsxs(r.Fragment,{children:[f&&r.jsx(p.Select,{error:i,onValueChange:y=>a(y),...A,renderValue:y=>{const b=f.find(v=>v.id===y);return b?`${b.id} - ${b.label}`:y},children:f.map(y=>r.jsx(p.SelectItem,{value:String(y.id),children:r.jsx(Ie,{enumKey:y.id,enumValues:f,size:"medium"})},y.id))}),!f&&r.jsx(p.TextField,{...A,error:i,placeholder:e==="optional"?"Autogenerated ID, it can be manually changed":o==="new"||o==="copy"?"ID of the new document":"ID of the document",onChange:y=>{let b=y.target.value;return b&&(b=b.trim()),a(b.length?b:void 0)}}),l.id&&r.jsx(p.Typography,{variant:"caption",className:"ml-3.5 text-red-500 dark:text-red-500",children:l.id})]})}function Rl({propertyId:e}){const[t,o]=d.useState(!1);return r.jsxs("div",{className:"flex flex-row gap-2 items-center justify-center text-white",children:[r.jsxs("div",{children:[r.jsx(p.Typography,{variant:"caption",className:"min-w-20 text-slate-400",color:"disabled",children:t?"Copied":"Property ID"}),r.jsx(p.Typography,{variant:"caption",className:"text-white",children:r.jsx("code",{children:e})})]}),r.jsx(p.IconButton,{size:"small",children:r.jsx(p.ContentCopyIcon,{size:"smallest",className:"text-white",onClick:d.useCallback(()=>{navigator.clipboard.writeText(e),o(!0),setTimeout(()=>o(!1),2e3)},[e])})})]})}const Dn=d.memo(ec,(e,t)=>e.status===t.status&&e.path===t.path&&L(e.entity?.values,t.entity?.values));function Qn(e,t,o){const a=e.properties;if((t==="existing"||t==="copy")&&o)return o.values??vt(a);if(t==="new")return vt(a);throw console.error({status:t,entity:o}),new Error("Form has not been initialised with the correct parameters")}function ec({status:e,path:t,collection:o,entity:a,onEntitySaveRequested:i,onDiscard:n,onModified:s,onValuesChanged:l,onIdChange:c,onFormContextChange:u,hideId:f,autoSave:g,onIdUpdateError:m}){const h=ut(),A=ae(),y=Ae(),b=Qe(o),v=A.plugins,k=d.useMemo(()=>Ne({collection:o,path:t,values:a?.values,fields:A.propertyConfigs}),[a?.values,t,A.propertyConfigs]),_=(e==="new"||e==="copy")&&!!k.customId&&k.customId!=="optional",E=d.useMemo(()=>e==="new"||e==="copy"?_?void 0:b.generateEntityId(t):a?.id,[]),x=d.useRef(!1),B=d.useRef(Qn(k,e,a)),[C,S]=d.useState(E),[N,I]=d.useState(!1),[P,D]=d.useState(),[G,R]=d.useState(!1),[K,W]=d.useState(a?.values??B.current),j=te=>i({collection:re,path:t,entityId:C,values:te,previousValues:a?.values,closeAfterSave:x.current,autoSave:g??!1}).then(O=>{const ie=e==="new"?"new_entity_saved":e==="copy"?"entity_copied":e==="existing"?"entity_edited":"unmapped_event";h.onAnalyticsEvent?.(ie,{path:t})}).catch(O=>{console.error(O),D(O)}).finally(()=>{x.current=!1}),M=(te,O)=>{if(_&&!C){console.error("Missing custom Id"),I(!0),O.setSubmitting(!1);return}if(D(void 0),I(!1),e==="existing"){if(!a?.id)throw Error("Form misconfiguration when saving, no id for existing entity")}else if(e==="new"||e==="copy"){if(o.customId&&o.customId!=="optional"&&!C)throw Error("Form misconfiguration when saving, entityId should be set")}else throw Error("New FormType added, check EntityForm");return j(te)?.then(ie=>{O.resetForm({values:te,submitCount:0,touched:{}})}).finally(()=>{O.setSubmitting(!1)})},J=ke.useCreateFormex({initialValues:B.current,onSubmit:M,validation:te=>V?.validate(te,{abortEarly:!1}).then(()=>({})).catch(O=>{const ie={};return O.inner.forEach(me=>{ie[me.path]=me.message}),rc(O)})});d.useEffect(()=>{B.current=Qn(k,e,a);const te=J.initialValues;!J.isSubmitting&&te&&e==="existing"?Z(Object.entries(re.properties).map(([O,ie])=>{if(wt(ie))return{};const me=te[O],ue=B.current[O];return L(me,ue)?{}:{[O]:ue}}).reduce((O,ie)=>({...O,...ie}),{})):Z({})},[a,k,e]);const H=te=>{const O=J.initialValues;W(te),l&&l(te),g&&te&&!L(te,O)&&j(te)};d.useEffect(()=>{C&&c&&c(C)},[C,c]);const re=Ne({collection:o,path:t,entityId:C,values:K,previousValues:J.initialValues,fields:A.propertyConfigs}),oe=Fr(re,A.propertyConfigs),U=K&&oe?Ye(K,oe):void 0,X=o.callbacks?.onIdUpdate,Q=d.useCallback(async()=>{if(X&&K&&(e==="new"||e==="copy")){R(!0);try{const te=await X({collection:re,path:t,entityId:C,values:K,context:y});S(te)}catch(te){m&&m(te),console.error(te)}R(!1)}},[C,K,e]);d.useEffect(()=>{Q()},[Q]);const[ee,Z]=d.useState({}),$=d.useCallback(({name:te,value:O,property:ie})=>b.checkUniqueField(t,te,O,C),[b,t,C]),V=d.useMemo(()=>C?Ha(C,re.properties,$):void 0,[C,re.properties,$]),z=qe(),F=d.useCallback(({entity:te,customEntityActions:O})=>{const ie=ct(o,z,t,null),me=te?$t(o,z,t,te):!0,ue=[];return ie&&ue.push(no),me&&ue.push(io),O&&ue.push(...O),ue},[z,o,t]),T=[],le={setFieldValue:d.useCallback(J.setFieldValue,[]),values:J.values,collection:re,entityId:C,path:t,save:j},ve=d.useRef(null);if(d.useEffect(()=>{u&&!oc(ve.current??void 0,le)&&(u(le),ve.current=le)},[le,u]),v&&o){const te={entityId:C,path:t,status:e,collection:o,context:y,currentEntityId:C,formContext:le};T.push(...v.map((O,ie)=>O.form?.Actions?r.jsx(O.form.Actions,{...te},`actions_${O.key}`):null).filter(Boolean))}return r.jsx(ke.Formex,{value:J,children:r.jsxs("div",{className:"h-full overflow-auto",children:[T.length>0&&r.jsx("div",{className:p.cls("w-full flex justify-end items-center sticky top-0 right-0 left-0 z-10 bg-opacity-60 bg-slate-200 dark:bg-opacity-60 dark:bg-slate-800 backdrop-blur-md"),children:T}),r.jsxs("div",{className:"pt-12 pb-16 pl-8 pr-8 md:pl-10 md:pr-10",children:[r.jsxs("div",{className:`w-full py-2 flex flex-col items-start mt-${4+(T?8:0)} lg:mt-${8+(T?8:0)} mb-8`,children:[r.jsx(p.Typography,{className:"mt-4 flex-grow line-clamp-1 "+o.hideIdFromForm?"mb-2":"mb-0",variant:"h4",children:U??o.singularName??o.name}),r.jsx(p.Alert,{color:"base",className:"w-full",size:"small",children:r.jsxs("code",{className:"text-xs select-all",children:[t,"/",C]})})]}),!f&&r.jsx(Kl,{customId:o.customId,entityId:C,status:e,onChange:S,error:N,loading:G,entity:a}),C&&r.jsx(tc,{...J,initialValues:J.initialValues,onModified:s,onDiscard:n,onValuesChanged:H,underlyingChanges:ee,entity:a,resolvedCollection:re,formContext:le,status:e,savingError:P,closeAfterSaveRef:x,autoSave:g,entityActions:F({entity:a,customEntityActions:o.entityActions})})]})]})})}function tc(e){const{values:t,onDiscard:o,onModified:a,onValuesChanged:i,underlyingChanges:n,formContext:s,entity:l,touched:c,setFieldValue:u,resolvedCollection:f,isSubmitting:g,status:m,handleSubmit:h,resetForm:A,savingError:y,dirty:b,closeAfterSaveRef:v,autoSave:k,entityActions:_}=e,E=Ae(),x=_.filter(P=>P.includeInForm===void 0||P.includeInForm),B=Je(),C=b;d.useEffect(()=>{a&&a(C),i&&i(t)},[C,t]),d.useEffect(()=>{!k&&!g&&n&&l&&Object.entries(n).forEach(([P,D])=>{const G=t[P];!L(D,G)&&!c[P]&&(console.debug("Updated value from the datasource:",P,D),u(P,D!==void 0?D:null))})},[g,k,n,l,t,c,u]);const S=r.jsx("div",{className:"flex flex-col gap-8",children:(f.propertiesOrder??Object.keys(f.properties)).map(P=>{const D=f.properties[P];if(!D)return console.warn(`Property ${P} not found in collection ${f.name}`),null;const G=!!n&&Object.keys(n).includes(P)&&!!c[P],R=!k&&g||st(D)||!!D.disabled;if(wt(D))return null;const W={propertyKey:P,disabled:R,property:D,includeDescription:D.description||D.longDescription,underlyingValueHasChanged:G&&!k,context:s,tableMode:!1,partOfArray:!1,partOfBlock:!1,autoFocus:!1};return r.jsx("div",{id:`form_field_${P}`,children:r.jsx(ne,{children:r.jsx(p.Tooltip,{title:r.jsx(Rl,{propertyId:P}),delayDuration:800,side:"left",align:"start",sideOffset:16,children:r.jsx(ot,{...W})})})},`field_${f.name}_${P}`)}).filter(Boolean)}),N=g||!C&&m==="existing",I=d.useRef(null);return r.jsxs("form",{onSubmit:h,onReset:()=>(console.debug("Resetting form"),A(),o&&o()),noValidate:!0,children:[r.jsxs("div",{className:"mt-12",ref:I,children:[S,r.jsx(Zl,{containerRef:I})]}),r.jsx("div",{className:"h-14"}),!k&&r.jsxs(p.DialogActions,{position:"absolute",children:[y&&r.jsx("div",{className:"text-right",children:r.jsx(p.Typography,{color:"error",children:y.message})}),l&&x.length>0&&r.jsx("div",{className:"flex-grow flex overflow-auto no-scrollbar",children:x.map(P=>r.jsx(p.IconButton,{color:"primary",onClick:D=>{D.stopPropagation(),l&&P.onClick({entity:l,fullPath:f.path,collection:f,context:E,sideEntityController:B})},children:P.icon},P.name))}),g&&r.jsx(p.CircularProgress,{size:"small"}),r.jsx(p.Button,{variant:"text",disabled:N||g,type:"reset",children:m==="existing"?"Discard":"Clear"}),r.jsxs(p.Button,{variant:"text",color:"primary",type:"submit",disabled:N||g,onClick:()=>{v.current=!1},children:[m==="existing"&&"Save",m==="copy"&&"Create copy",m==="new"&&"Create"]}),r.jsxs(p.Button,{variant:"filled",color:"primary",type:"submit",disabled:N||g,onClick:()=>{v.current=!0},children:[m==="existing"&&"Save and close",m==="copy"&&"Create copy and close",m==="new"&&"Create and close"]})]})]})}function rc(e){let t={};if(e.inner){if(e.inner.length===0)return ke.setIn(t,e.path,e.message);for(const o of e.inner)ke.getIn(t,o.path)||(t=ke.setIn(t,o.path,o.message))}return t}function oc(e,t){return e?.path===t?.path&&e?.entityId===t?.entityId&&L(e?.values,t?.values)&&L(e?.collection,t?.collection)}function Mn(e){return Object.keys(nr).includes(e)}const nr={text_field:{key:"text_field",name:"Text field",description:"Simple short text",Icon:p.ShortTextIcon,color:"#2d7ff9",property:{dataType:"string",Field:At}},multiline:{key:"multiline",name:"Multiline",description:"Text with multiple lines",Icon:p.SubjectIcon,color:"#2d7ff9",property:{dataType:"string",multiline:!0,Field:At}},markdown:{key:"markdown",name:"Markdown",description:"Text with advanced markdown syntax",Icon:p.FormatQuoteIcon,color:"#2d7ff9",property:{dataType:"string",markdown:!0,Field:Nn}},url:{key:"url",name:"Url",description:"Text with URL validation",Icon:p.HttpIcon,color:"#154fb3",property:{dataType:"string",url:!0,Field:At}},email:{key:"email",name:"Email",description:"Text with email validation",Icon:p.EmailIcon,color:"#154fb3",property:{dataType:"string",email:!0,Field:At}},switch:{key:"switch",name:"Switch",description:"Boolean true or false field (or yes or no, 0 or 1...)",Icon:p.FlagIcon,color:"#20d9d2",property:{dataType:"boolean",Field:Cn}},select:{key:"select",name:"Select/enum",description:"Select one text value from within an enumeration",Icon:p.ListIcon,color:"#4223c9",property:{dataType:"string",enumValues:[],Field:mo}},multi_select:{key:"multi_select",name:"Multi select",description:"Select multiple text values from within an enumeration",Icon:p.ListAltIcon,color:"#4223c9",property:{dataType:"array",of:{dataType:"string",enumValues:[]},Field:ho}},number_input:{key:"number_input",name:"Number input",description:"Simple number field with validation",Icon:p.NumbersIcon,color:"#bec920",property:{dataType:"number",Field:At}},number_select:{key:"number_select",name:"Number select",description:"Select a number value from within an enumeration",Icon:p.FormatListNumberedIcon,color:"#bec920",property:{dataType:"number",enumValues:[],Field:mo}},multi_number_select:{key:"multi_number_select",name:"Multiple number select",description:"Select multiple number values from within an enumeration",Icon:p.FormatListNumberedIcon,color:"#bec920",property:{dataType:"array",of:{dataType:"number",enumValues:[]},Field:ho}},file_upload:{key:"file_upload",name:"File upload",description:"Input for uploading single files",Icon:p.UploadFileIcon,color:"#f92d9a",property:{dataType:"string",storage:{storagePath:"{path}"},Field:go}},multi_file_upload:{key:"multi_file_upload",name:"Multiple file upload",description:"Input for uploading multiple files",Icon:p.DriveFolderUploadIcon,color:"#f92d9a",property:{dataType:"array",of:{dataType:"string",storage:{storagePath:"{path}"}},Field:go}},reference:{key:"reference",name:"Reference",description:"The value refers to a different collection",Icon:p.LinkIcon,color:"#ff0042",property:{dataType:"reference",Field:En}},multi_references:{key:"multi_references",name:"Multiple references",description:"Multiple values that refer to a different collection",Icon:p.AddLinkIcon,color:"#ff0042",property:{dataType:"array",of:{dataType:"reference"},Field:kn}},date_time:{key:"date_time",name:"Date/time",description:"A date time select field",Icon:p.ScheduleIcon,color:"#8b46ff",property:{dataType:"date",Field:xn}},group:{key:"group",name:"Group",description:"Group of multiple fields",Icon:p.BallotIcon,color:"#ff9408",property:{dataType:"map",properties:{},Field:Bn}},key_value:{key:"key_value",name:"Key-value",description:"Flexible field that allows the user to add multiple key-value pairs",Icon:p.BallotIcon,color:"#ff9408",property:{dataType:"map",keyValue:!0,Field:Sn}},repeat:{key:"repeat",name:"Repeat/list",description:"A field that gets repeated multiple times (e.g. multiple text fields)",Icon:p.RepeatIcon,color:"#ff9408",property:{dataType:"array",of:{dataType:"string"},Field:In}},custom_array:{key:"custom_array",name:"Custom array",description:"A field that saved its value as an array of custom objects",Icon:p.RepeatIcon,color:"#ff9408",property:{dataType:"array",of:[],Field:Pn}},block:{key:"block",name:"Block",description:"A complex field that allows the user to compose different fields together, with a key->value format",Icon:p.ViewStreamIcon,color:"#ff9408",property:{dataType:"array",oneOf:{properties:{}},Field:Fn}}};function On(e){const t=ir(e);if(!t){console.error("No field id found for property",e);return}return nr[t]}function It(e,t){const o=ko(e),a=ir(e);if(!a){console.error("No field id found for property",e);return}const i=nr[a],n=o?t[o]:void 0;return De(i??{},n??{})}function ir(e){if(e.dataType==="string")return e.multiline?"multiline":e.markdown?"markdown":e.storage?"file_upload":e.url?"url":e.email?"email":e.enumValues?"select":"text_field";if(e.dataType==="number")return e.enumValues?"number_select":"number_input";if(e.dataType==="map")return e.keyValue?"key_value":"group";if(e.dataType==="array"){const t=e.of;return e.oneOf?"block":Array.isArray(t)?"custom_array":_e(t)?"repeat":t?.dataType==="string"&&t.enumValues?"multi_select":t?.dataType==="number"&&t.enumValues?"multi_number_select":t?.dataType==="string"&&t.storage?"multi_file_upload":t?.dataType==="reference"?"multi_references":"repeat"}else{if(e.dataType==="boolean")return"switch";if(e.dataType==="date")return"date_time";if(e.dataType==="reference")return"reference"}console.error("Unsupported field config mapping",e)}function ko(e){return e.propertyConfig?e.propertyConfig:ir(e)}const Ne=({collection:e,path:t,entityId:o,values:a,previousValues:i,userConfigPersistence:n,fields:s,ignoreMissingFields:l=!1})=>{const c=n?.getCollectionConfig(t),u=Ye(c,"properties"),f=vt(e.properties),g=a??f,m=i??a??f,h=Object.entries(e.properties).map(([b,v])=>{const k=Pe({propertyKey:b,propertyOrBuilder:v,values:g,previousValues:m,path:t,entityId:o,fields:s,ignoreMissingFields:l});return k?{[b]:k}:{}}).filter(b=>b!==null).reduce((b,v)=>({...b,...v}),{}),A=De(h,u),y=Object.entries(A).filter(([b,v])=>!!v?.dataType).map(([b,v])=>({[b]:v})).reduce((b,v)=>({...b,...v}),{});return{...e,properties:y,originalCollection:e}};function Pe({propertyOrBuilder:e,fromBuilder:t=!1,ignoreMissingFields:o=!1,...a}){if(typeof e=="object"&&"resolved"in e)return e;let i=null;if(e)if(_e(e)){const n=a.path;if(!n)throw Error("Trying to resolve a property builder without specifying the entity path");const s=a.propertyKey?ke.getIn(a.values,a.propertyKey):void 0,l=e({...a,path:n,propertyValue:s,values:a.values??{},previousValues:a.previousValues??a.values??{}});if(!l)return null;i=Pe({...a,propertyOrBuilder:l,fromBuilder:!0,ignoreMissingFields:o})}else{const n=e;if(n.dataType==="map"&&n.properties){const s=_o({ignoreMissingFields:o,...a,properties:n.properties});i={...n,resolved:!0,fromBuilder:t,properties:s}}else n.dataType==="array"?i=Xe({property:n,fromBuilder:t,ignoreMissingFields:o,...a}):(n.dataType==="string"||n.dataType==="number")&&n.enumValues&&(i=Co(n,t))}else return null;if(i||(i={...e,resolved:!0,fromBuilder:t}),i.propertyConfig&&!Mn(i.propertyConfig)){const n=a.fields;if(!n&&!o)throw Error(`Trying to resolve a property with key '${i.propertyConfig}' that inherits from a custom property config but no custom property configs were provided. Use the property 'propertyConfigs' in your app config to provide them`);const s=n?.[i.propertyConfig];if(!s)return console.warn(`Trying to resolve a property with key '${i.propertyConfig}' that inherits from a custom property config but no custom property config with that key was found. Check the 'propertyConfigs' in your app config`),console.warn("Available property configs",n),null;if(s.property){const l=s.property;"propertyConfig"in l&&delete l.propertyConfig;const c=Pe({propertyOrBuilder:l,ignoreMissingFields:o,...a});c&&(i=De(c,i))}}return i?{...i,resolved:!0}:null}function Xe({propertyKey:e,property:t,ignoreMissingFields:o=!1,...a}){const i=e?ke.getIn(a.values,e):void 0;if(t.of){if(Array.isArray(t.of))return{...t,resolved:!0,fromBuilder:a.fromBuilder,resolvedProperties:t.of.map((n,s)=>Pe({propertyKey:`${e}.${s}`,propertyOrBuilder:n,ignoreMissingFields:o,...a,index:s}))};{const n=t.of,s=Array.isArray(i)?i.map((c,u)=>Pe({propertyKey:`${e}.${u}`,propertyOrBuilder:n,ignoreMissingFields:o,...a,index:u})).filter(c=>!!c):[],l=Pe({propertyKey:`${e}`,propertyOrBuilder:n,ignoreMissingFields:o,...a});if(!l&&!o)throw Error("When using a property builder as the 'of' prop of an ArrayProperty, you must return a valid child property");return{...t,resolved:!0,fromBuilder:a.fromBuilder,of:l,resolvedProperties:s}}}else if(t.oneOf){const n=t.oneOf?.typeField??yt,s=Array.isArray(i)?i.map((c,u)=>{const f=c&&c[n],g=t.oneOf?.properties[f];return!f||!g?null:Pe({propertyKey:`${e}.${u}`,propertyOrBuilder:g,ignoreMissingFields:o,...a})}).filter(c=>!!c):[],l=_o({properties:t.oneOf.properties,ignoreMissingFields:o,...a});return{...t,resolved:!0,oneOf:{...t.oneOf,properties:l},fromBuilder:a.fromBuilder,resolvedProperties:s}}else{if(t.Field)return{...t,resolved:!0,fromBuilder:a.fromBuilder};throw Error("The array property needs to declare an 'of' or a 'oneOf' property, or provide a custom `Field`")}}function _o({properties:e,ignoreMissingFields:t,...o}){return Object.entries(e).map(([a,i])=>{const n=Pe({propertyKey:a,propertyOrBuilder:i,ignoreMissingFields:t,...o});return n?{[a]:n}:{}}).filter(a=>a!==null).reduce((a,i)=>({...a,...i}),{})}function Co(e,t){return typeof e.enumValues=="object"?{...e,resolved:!0,enumValues:We(e.enumValues)?.filter(o=>o&&(o.id||o.id===0)&&o.label)??[],fromBuilder:t??!1}:e}function ac(e){return typeof e=="object"?Object.entries(e).map(([t,o])=>typeof o=="string"?{id:t,label:o}:o):Array.isArray(e)?e:void 0}function xo(e,t){return typeof e=="string"?t?.find(o=>o.key===e):e}function Eo(e){const{path:t,collections:o=[],currentFullPath:a}=e,i=fe(t).split("/"),n=Qt(i),s=[];for(let l=0;l<n.length;l++){const c=n[l],u=o&&o.find(f=>f.id===c||f.path===c);if(u){const f=u.id??u.path,g=a&&a.length>0?a+"/"+f:f;s.push({type:"collection",path:g,collection:u});const m=fe(fe(t).replace(c,"")),h=m.length>0?m.split("/"):[];if(h.length>0){const A=h[0],y=g+"/"+A;if(s.push({type:"entity",entityId:A,path:g,parentCollection:u}),h.length>1){const b=h.slice(1).join("/");if(!u)throw Error("collection not found resolving path: "+u);const v=u.entityViews,k=v&&v.map(_=>xo(_,e.contextEntityViews)).filter(Boolean).find(_=>_.key===b);if(k){const _=a&&a.length>0?a+"/"+k.key:k.key;s.push({type:"custom_view",path:_,view:k})}else u.subcollections&&s.push(...Eo({path:b,collections:u.subcollections,currentFullPath:y,contextEntityViews:e.contextEntityViews}))}}break}}return s}const nc="100vw",ic="55vw",sr="768px",lr="main_##Q$SC^#S6";function sc({path:e,entityId:t,selectedSubPath:o,copy:a,collection:i,parentCollectionIds:n,onValuesAreModified:s,formWidth:l,onUpdate:c,onClose:u}){i.customId&&i.formAutoSave&&console.warn(`The collection ${i.path} has customId and formAutoSave enabled. This is not supported and formAutoSave will be ignored`);const[f,g]=d.useState(!1),[m,h]=d.useState(void 0);Lt(m,()=>{m&&F({entityId:U?.id,collection:i,path:e,values:m,closeAfterSave:!1})},!1,2e3);const A=Qe(i),y=cr(),b=Je(),v=He(),k=ae(),_=Ae(),E=qe(),[x,B]=d.useState(void 0),[C,S]=d.useState(a?"copy":t?"existing":"new"),N=d.useRef(void 0),I=N.current,P=(i.subcollections??[]).filter(Y=>!Y.hideFromNavigation),D=P?.length??0,G=i.entityViews,R=G?.length??0,K=i.formAutoSave&&!i.customId,W=R>0||D>0,j=o??xr(i?i.defaultSelectedView:void 0,{status:C,entityId:t}),M=d.useRef(j??lr),J=M.current===lr,{entity:H,dataLoading:re,dataLoadingError:oe}=Qr({path:e,entityId:t,collection:i,useCache:!1}),[U,X]=d.useState(H),[Q,ee]=d.useState(void 0);d.useEffect(()=>{H&&X(H)},[H]),d.useEffect(()=>{if(C==="new")ee(!1);else{const Y=U?Ir(i,E,e,U??null):!1;U&&ee(!Y)}},[E,U,C]);const Z=d.useCallback(Y=>{g(!1),v.open({type:"error",message:"Error before saving: "+Y?.message}),console.error(Y)},[v]),$=d.useCallback(Y=>{g(!1),v.open({type:"error",message:"Error after saving (entity is saved): "+Y?.message}),console.error(Y)},[v]),V=(Y,Be)=>{g(!1),K||v.open({type:"success",message:`${i.singularName??i.name}: Saved correctly`}),X(Y),S("existing"),s(!1),c&&c({entity:Y}),Be?(console.log("Closing side dialog"),y.setBlocked(!1),y.close(!0),u?.()):C!=="existing"&&b.replace({path:e,entityId:Y.id,selectedSubPath:M.current,updateUrl:!0,collection:i})},z=d.useCallback(Y=>{g(!1),v.open({type:"error",message:"Error saving: "+Y?.message}),console.error("Error saving entity",e,t),console.error(Y)},[t,e,v]),F=({values:Y,previousValues:Be,closeAfterSave:Se,entityId:$e,collection:Ft,path:Nt})=>(g(!0),Mr({path:Nt,entityId:$e,values:Y,previousValues:Be,collection:Ft,status:C,dataSource:A,context:_,onSaveSuccess:Pt=>V(Pt,Se),onSaveFailure:z,onPreSaveHookError:Z,onSaveSuccessHookError:$}).then()),T=async({collection:Y,path:Be,entityId:Se,values:$e,previousValues:Ft,closeAfterSave:Nt,autoSave:Pt})=>{if(C)if(Pt)h($e);else return F({collection:Y,path:Be,entityId:Se,values:$e,previousValues:Ft,closeAfterSave:Nt})},le=G?G.map(Y=>xo(Y,k.entityViews)).filter(Boolean):[],ve=G&&le.map((Y,Be)=>{if(!Y||M.current!==Y.key)return null;const Se=Y.Builder;return Se?r.jsx("div",{className:p.cls(p.defaultBorderMixin,"relative flex-grow w-full h-full overflow-auto "),role:"tabpanel",children:r.jsx(ne,{children:x&&r.jsx(Se,{collection:i,entity:U,modifiedValues:I??U?.values,formContext:x})})},`custom_view_${Y.key}`):(console.error("customView.Builder is not defined"),null)}).filter(Boolean),te=re&&!U||(!U||Q===void 0)&&(C==="existing"||C==="copy"),O=te||f,ie=P&&P.map((Y,Be)=>{const Se=Y.id??Y.path,$e=U?`${e}/${U?.id}/${fe(Se)}`:void 0;return M.current!==Se?null:r.jsxs("div",{className:"relative flex-grow h-full overflow-auto w-full",role:"tabpanel",children:[O&&r.jsx(rr,{}),!te&&(U&&$e?r.jsx(co,{fullPath:$e,parentCollectionIds:[...n,i.id],isSubCollection:!0,...Y}):r.jsx("div",{className:"flex items-center justify-center w-full h-full p-3",children:r.jsx(p.Typography,{variant:"label",children:"You need to save your entity before adding additional collections"})}))]},`subcol_${Se}`)}).filter(Boolean),me=d.useCallback(()=>{s(!1)},[]),ue=Y=>{M.current=Y,b.replace({path:e,entityId:t,selectedSubPath:Y===lr?void 0:Y,updateUrl:!0,collection:i})},he=d.useCallback(Y=>{N.current=Y},[]),ze=d.useCallback(Y=>{v.open({type:"error",message:"Error updating id, check the console"})},[]),Ve=d.useCallback(Y=>{X(Be=>Be?{...Be,id:Y}:void 0)},[]),Ge=Y=>{K||s(Y)};function Ue(){const Y=k.plugins;let Be=r.jsx(Dn,{status:C,path:e,collection:i,onEntitySaveRequested:T,onDiscard:me,onValuesChanged:he,onModified:Ge,entity:U,onIdChange:Ve,onFormContextChange:B,hideId:i.hideIdFromForm,autoSave:K,onIdUpdateError:ze});return Y&&Y.forEach(Se=>{Se.form?.provider&&(Be=r.jsx(Se.form.provider.Component,{status:C,path:e,collection:i,onDiscard:me,onValuesChanged:he,onModified:Ge,entity:U,context:_,formContext:x,...Se.form.provider.props,children:Be}))}),r.jsx(ne,{children:Be})}const at=Q===void 0?r.jsx(r.Fragment,{}):Q?r.jsxs(r.Fragment,{children:[r.jsx(p.Typography,{className:"mt-16 mb-8 mx-8",variant:"h4",children:i.singularName??i.name}),r.jsx($r,{className:"px-12",entity:U,path:e,collection:i})]}):Ue(),So=P&&P.map(Y=>r.jsx(p.Tab,{className:"text-sm min-w-[140px]",value:Y.id,children:Y.name},`entity_detail_collection_tab_${Y.name}`)),Io=le.map(Y=>r.jsx(p.Tab,{className:"text-sm min-w-[140px]",value:Y.key,children:Y.name},`entity_detail_collection_tab_${Y.name}`));return r.jsx("div",{className:"flex flex-col h-full w-full transition-width duration-250 ease-in-out",children:r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:p.cls(p.defaultBorderMixin,"no-scrollbar border-b pl-2 pr-2 pt-1 flex items-end overflow-scroll bg-gray-50 dark:bg-gray-950"),children:[r.jsx("div",{className:"pb-1 self-center",children:r.jsx(p.IconButton,{onClick:()=>(u?.(),y.close(!1)),size:"large",children:r.jsx(p.CloseIcon,{})})}),r.jsx("div",{className:"flex-grow"}),te&&r.jsx("div",{className:"self-center",children:r.jsx(p.CircularProgress,{size:"small"})}),r.jsxs(p.Tabs,{value:M.current,onValueChange:Y=>{ue(Y)},className:"pl-4 pr-4 pt-0",children:[r.jsx(p.Tab,{disabled:!W,value:lr,className:`${W?"":"hidden"} text-sm min-w-[140px]`,children:i.singularName??i.name}),Io,So]})]}),r.jsxs("div",{className:"flex-grow h-full flex overflow-auto flex-row w-full ",style:{},children:[r.jsx("div",{role:"tabpanel",hidden:!J,id:`form_${e}`,className:" w-full",children:te?r.jsx(rr,{}):at}),ve,ie]})]})})}function lc(e,t){const[o,a]=d.useState(),{navigator:i}=d.useContext(ge.UNSAFE_NavigationContext),n=ge.useNavigate(),s=()=>{a(void 0)},l=()=>{t(),a(void 0),n(-1)},c=d.useCallback(({action:u,location:f,retry:g})=>{switch(u){case"REPLACE":{g();return}case"POP":a(f)}},[]);return d.useEffect(()=>{if(!e||o||!("block"in i))return;const u=i.block(f=>{const g={...f,retry(){u(),f.retry()}};c(g)});return u},[i,c,e,o]),{navigationWasBlocked:!!o,handleCancel:s,handleOk:l}}function cc({open:e,handleOk:t,handleCancel:o,body:a,title:i}){return r.jsxs(p.Dialog,{open:e,onOpenChange:n=>n?o():t(),children:[r.jsxs(p.DialogContent,{children:[r.jsx(p.Typography,{variant:"h6",children:i}),a,r.jsx(p.Typography,{children:"Are you sure you want to leave this page?"})]}),r.jsxs(p.DialogActions,{children:[r.jsx(p.Button,{variant:"text",onClick:o,autoFocus:!0,children:" Cancel "}),r.jsx(p.Button,{onClick:t,children:" Ok "})]})]})}const zn=d.createContext({width:"",blocked:!1,setBlocked:e=>{},setBlockedNavigationMessage:e=>{},close:()=>{}}),cr=()=>d.useContext(zn);function dc(){const t=_t().sidePanels,o=[...t];return o.push(void 0),r.jsx(r.Fragment,{children:o.map((a,i)=>r.jsx(pc,{panel:a,offsetPosition:t.length-i-1},`side_dialog_${i}`))})}function pc({offsetPosition:e,panel:t}){const[o,a]=d.useState(!1),[i,n]=d.useState(!1),[s,l]=d.useState(),c=d.useRef(t?.width),u=c.current,f=_t(),{navigationWasBlocked:g,handleOk:m,handleCancel:h}=lc(i&&!o,()=>n(!1));d.useEffect(()=>{t&&(c.current=t.width)},[t]);const A=()=>{n(!1),a(!1),f.close(),t?.onClose?.()},y=()=>{a(!1)},b=v=>{i&&!v?a(!0):(f.close(),t?.onClose?.())};return r.jsxs(zn.Provider,{value:{blocked:i,setBlocked:n,setBlockedNavigationMessage:l,width:u,close:b},children:[r.jsxs(p.Sheet,{open:!!t,onOpenChange:v=>!v&&b(),children:[t&&r.jsx("div",{className:"transform max-w-[100vw] lg:max-w-[95vw] flex flex-col h-full transition-all duration-250 ease-in-out bg-white dark:bg-gray-900 ",style:{width:t.width,transform:`translateX(-${e*200}px)`},children:r.jsx(ne,{children:t.component})}),!t&&r.jsx("div",{style:{width:u}})]}),r.jsx(cc,{open:g||o,handleOk:o?A:m,handleCancel:o?y:h,body:s})]})}function uc(e){const{blocked:t,setBlocked:o,setBlockedNavigationMessage:a}=cr(),i=pe(),n=d.useMemo(()=>i.getParentCollectionIds(e.path),[i,e.path]),s=d.useMemo(()=>{if(!e)return;let c=e.collection;const u=i.getCollection(e.path);if(u&&(c=u),!c)throw console.error("ERROR: No collection found in path `",e.path,"`. Entity id: ",e.entityId),Error("ERROR: No collection found in path `"+e.path+"`. Make sure you have defined a collection for this path in the root navigation.");return c},[i,e]);d.useEffect(()=>{function c(u){t&&s&&(u.preventDefault(),u.returnValue=`You have unsaved changes in this ${s.name}. Are you sure you want to leave this page?`)}return typeof window<"u"&&window.addEventListener("beforeunload",c),()=>{typeof window<"u"&&window.removeEventListener("beforeunload",c)}},[t,s]);const l=d.useCallback(c=>{o(c),a(c?r.jsxs(r.Fragment,{children:[" You have unsaved changes in this ",r.jsx("b",{children:s?.singularName??s?.name}),"."]}):void 0)},[s?.name,o,a]);return!e||!s?r.jsx("div",{className:"w-full"}):r.jsx(r.Fragment,{children:r.jsx(ne,{children:r.jsx(sc,{...e,formWidth:e.width,collection:s,parentCollectionIds:n,onValuesAreModified:l})})})}const Vn="new";function fc(e,t){if(t)return nc;const o=!e.selectedSubPath;let a;return e.width?a=typeof e.width=="number"?`${e.width}px`:e.width:e.collection?.sideDialogWidth&&(a=typeof e.collection.sideDialogWidth=="number"?`${e.collection.sideDialogWidth}px`:e.collection.sideDialogWidth),o?a||(e.collection?mc(e.collection):sr):`calc(${ic} + ${a??sr})`}const Bo={};function mc(e){if(Bo[e.id])return Bo[e.id];const t=Ne({collection:e,path:"__ignored",ignoreMissingFields:!0});let o=sr;if(t?.properties){const a=Object.values(t.properties).map(n=>dr(n)),i=Math.max(...a);i<3?o=sr:o=768+32*(i-2)+"px"}return Bo[e.id]=o,o}function dr(e,t=0){if(e.dataType==="map"&&e.properties){const o=Object.values(e.properties).flatMap(a=>dr(a,t+1));return Math.max(...o)}else return e.dataType==="array"&&e.oneOf?t+3:e.dataType==="array"&&e.of?Array.isArray(e.of)?Math.max(...e.of.map(o=>dr(o,t+1))):dr(e.of,t+1):t+1}const hc=(e,t)=>{const o=ge.useLocation(),a=d.useRef(!1),i=!Me();d.useEffect(()=>{if(!e.loading&&!a.current){if(console.debug("Initialising side entity controller"),e.isUrlCollectionPath(o.pathname)){const c=o.hash===`#${Vn}`,u=e.urlPathToDataPath(o.pathname),f=gc(u,e.collections??[],c);for(let g=0;g<f.length;g++){const m=f[g];setTimeout(()=>{g===0?t.replace(pr(m,e.buildUrlCollectionPath,e.resolveAliasesFrom,i)):t.open(pr(m,e.buildUrlCollectionPath,e.resolveAliasesFrom,i))},1)}}a.current=!0}},[o,e.loading,e.isUrlCollectionPath,e.buildUrlCollectionPath,e.resolveAliasesFrom,t,i,e]);const n=d.useCallback(()=>{t.close()},[t]),s=d.useCallback(c=>{if(c.copy&&!c.entityId)throw Error("If you want to copy an entity you need to provide an entityId");const u=xr(c.collection?c.collection.defaultSelectedView:void 0,{status:c.copy?"copy":c.entityId?"existing":"new",entityId:c.entityId});t.open(pr({selectedSubPath:u,...c},e.buildUrlCollectionPath,e.resolveAliasesFrom,i))},[t,e.buildUrlCollectionPath,e.resolveAliasesFrom,i]),l=d.useCallback(c=>{if(c.copy&&!c.entityId)throw Error("If you want to copy an entity you need to provide an entityId");t.replace(pr(c,e.buildUrlCollectionPath,e.resolveAliasesFrom,i))},[e.buildUrlCollectionPath,e.resolveAliasesFrom,t,i]);return{close:n,open:s,replace:l}};function gc(e,t,o){const a=Eo({path:e,collections:t}),i=[];let n="";for(let s=0;s<a.length;s++){const l=a[s];if(l.type==="collection"&&(n=l.path),s>0){const c=a[s-1];if(l.type==="entity")i.push({path:l.path,entityId:l.entityId,copy:!1,width:l.parentCollection?.sideDialogWidth});else if(l.type==="custom_view"){if(c.type==="entity"){const u=i[i.length-1];u&&(u.selectedSubPath=l.view.key)}}else if(l.type==="collection"&&c.type==="entity"){const u=i[i.length-1];u&&(u.selectedSubPath=l.collection.id??l.collection.path)}}}return o&&i.push({path:n,copy:!1}),i}const pr=(e,t,o,a)=>{const i=fe(e.path),n=e.entityId?t(`${i}/${e.entityId}/${e.selectedSubPath||""}`):t(`${i}#${Vn}`),s=o(e.path),l={...e,path:s};return{key:`${e.path}/${e.entityId}`,component:r.jsx(uc,{...l}),urlPath:n,parentUrlPath:t(i),width:fc(e,a),onClose:e.onClose}};function Ac(){const e=ge.useLocation(),t=ge.useNavigate(),[o,a]=d.useState([]),i=d.useRef(o),n=d.useRef({}),s=d.useRef(0),l=g=>{i.current=g,a(g)};d.useEffect(()=>{const h=(e.state?.panels??[]).map(A=>n.current[A]).filter(A=>!!A);L(i.current.map(A=>A.key),h.map(A=>A.key))||l(h)},[e]);const c=d.useCallback(()=>{if(o.length===0)return;const g=o[o.length-1],m=[...o.slice(0,-1)];if(l(m),s.current>0)g.urlPath&&t(-1),s.current--;else if(g.parentUrlPath){const h=e.state?.base_location??e;t(g.parentUrlPath,{replace:!0,state:{base_location:h,panels:m.map(A=>A.key)}})}},[o,t,e]),u=d.useCallback(g=>{const m=Array.isArray(g)?g:[g];m.forEach(y=>{n.current[y.key]=y}),s.current=s.current+m.length;const h=e.state?.base_location??e,A=[...o,...m];l(A),m.forEach(y=>{y.urlPath&&t(y.urlPath,{state:{base_location:h,panels:A.map(b=>b.key)}})})},[e,t,o]),f=d.useCallback(g=>{const m=Array.isArray(g)?g:[g];m.forEach(y=>{n.current[y.key]=y});const h=e.state?.base_location??e,A=[...o.slice(0,-m.length),...m];l(A),m.forEach(y=>{y.urlPath&&t(y.urlPath,{replace:!0,state:{base_location:h,panels:A.map(b=>b.key)}})})},[e,t,o]);return{sidePanels:o,close:c,open:u,replace:f}}function bc({delegate:e,propertyConfigs:t,navigationController:o}){return{fetchCollection:d.useCallback(({path:a,collection:i,filter:n,limit:s,startAfter:l,searchString:c,orderBy:u,order:f})=>e.fetchCollection({path:a,filter:n,limit:s,startAfter:l,searchString:c,orderBy:u,order:f}),[e]),listenCollection:e.listenCollection?d.useCallback(({path:a,collection:i,filter:n,limit:s,startAfter:l,searchString:c,orderBy:u,order:f,onUpdate:g,onError:m})=>{const h=i??o.getCollection(a),A=!!h?.collectionGroup;if(!e.listenCollection)throw Error("useBuildDataSource delegate not initialised");return e.listenCollection({path:a,filter:n,limit:s,startAfter:l,searchString:c,orderBy:u,order:f,onUpdate:g,onError:m,isCollectionGroup:A,collection:h})},[e,o.getCollection]):void 0,fetchEntity:d.useCallback(({path:a,entityId:i})=>e.fetchEntity({path:a,entityId:i}),[e]),listenEntity:e.listenEntity?d.useCallback(({path:a,entityId:i,collection:n,onUpdate:s,onError:l})=>{if(!e.listenEntity)throw Error("useBuildDataSource delegate not initialised");return e.listenEntity({path:a,entityId:i,onUpdate:s,onError:l})},[e.listenEntity]):void 0,saveEntity:d.useCallback(({path:a,entityId:i,values:n,collection:s,status:l})=>{const c=s??o.getCollection(a),f=(c?Ne({collection:c,path:a,entityId:i,fields:t}):void 0)?.properties,g=e.cmsToDelegateModel(n),m=f?Go({inputValues:g,properties:f,status:l,timestampNowValue:e.currentTime(),setDateToMidnight:e.setDateToMidnight}):g;return e.saveEntity({path:a,entityId:i,values:m,status:l}).then(h=>({id:h.id,path:h.path,values:e.delegateToCMSModel(m)}))},[e.saveEntity,o.getCollection]),deleteEntity:d.useCallback(({entity:a})=>e.deleteEntity({entity:a}),[e.deleteEntity]),checkUniqueField:d.useCallback((a,i,n,s)=>e.checkUniqueField(a,i,n,s),[e.checkUniqueField]),generateEntityId:d.useCallback(a=>e.generateEntityId(a),[e.generateEntityId]),countEntities:e.countEntities?async({path:a,collection:i,filter:n,order:s,orderBy:l})=>e.countEntities({path:a,filter:n,orderBy:l,order:s,isCollectionGroup:!!i.collectionGroup}):void 0,isFilterCombinationValid:d.useCallback(({path:a,filterValues:i,sortBy:n})=>e.isFilterCombinationValid?e.isFilterCombinationValid({path:a,filterValues:i,sortBy:n}):!0,[e.isFilterCombinationValid]),initTextSearch:d.useCallback(async a=>e.initTextSearch?e.initTextSearch(a):!1,[e.initTextSearch])}}const yc="https://api-drplyi3b6q-ey.a.run.app";async function wc(e,t){const o=await e.getAuthToken();return fetch(yc+"/access_log",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Basic ${o}`},body:JSON.stringify({plugins:t})}).then(async a=>a.json())}function vc(e,t){const[o,a]=d.useState(null),i=d.useRef(null),n=t?.map(s=>s.key);return d.useEffect(()=>{e.user&&e.user.uid!==i.current&&!e.initialLoading&&(wc(e,n).then(a),i.current=e.user.uid)},[e,n]),o}function kc(e){const{children:t,entityLinkBuilder:o,userConfigPersistence:a,dateTimeFormat:i,locale:n,authController:s,storageSource:l,dataSourceDelegate:c,plugins:u,onAnalyticsEvent:f,propertyConfigs:g,entityViews:m,components:h,navigationController:A}=e;p.useLocaleConfig(n);const y=bc({delegate:c,propertyConfigs:g,navigationController:A}),b=Ac(),v=hc(A,b),k=u?.some(C=>C.loading)??!1,_=s.initialLoading||A.loading||k,E={dateTimeFormat:i,locale:n,entityLinkBuilder:o,plugins:u,entityViews:m??[],propertyConfigs:g??{},components:h},x=d.useMemo(()=>({onAnalyticsEvent:f}),[]),B=vc(s,u);return A.navigationLoadingError?r.jsx(p.CenteredView,{maxWidth:"md",children:r.jsx(ye,{title:"Error loading navigation",error:A.navigationLoadingError})}):s.authError?r.jsx(p.CenteredView,{maxWidth:"md",children:r.jsx(ye,{title:"Error loading auth",error:s.authError})}):B?.blocked?r.jsxs(p.CenteredView,{maxWidth:"md",fullScreen:!0,children:[r.jsx(p.Typography,{variant:"h4",children:"Access blocked"}),r.jsxs(p.Typography,{children:["This app has been blocked. Please reach out at ",r.jsx("a",{href:"mailto:hello@firecms.co",children:"hello@firecms.co"})," for more information."]}),B?.message&&r.jsxs(p.Typography,{children:["Response from the server: ",B?.message]})]}):r.jsx(ga.Provider,{value:x,children:r.jsx(ha.Provider,{value:E,children:r.jsx(ua.Provider,{value:a,children:r.jsx(pa.Provider,{value:l,children:r.jsx(sa.Provider,{value:y,children:r.jsx(mr.Provider,{value:s,children:r.jsx(ca.Provider,{value:b,children:r.jsx(da.Provider,{value:v,children:r.jsx(la.Provider,{value:A,children:r.jsx(Mi,{children:r.jsx(_c,{loading:_,children:t})})})})})})})})})})})}function _c({loading:e,children:t}){const o=Ae(),a=ae();let i=t({context:o,loading:e});const n=a.plugins;return!e&&n&&n.forEach(s=>{s.provider&&(i=r.jsx(s.provider.Component,{...s.provider.props,context:o,children:i}))}),r.jsx(r.Fragment,{children:i})}function Gn({name:e,icon:t,drawerOpen:o,tooltipsOpen:a,url:i,onClick:n}){const s=r.jsx("div",{className:"text-gray-600 dark:text-gray-500",children:t}),l=r.jsxs(ge.NavLink,{onClick:n,style:{width:o?"280px":"72px",transition:o?"width 150ms ease-in":void 0},className:({isActive:c})=>p.cls("rounded-r-lg truncate","hover:bg-slate-300 hover:bg-opacity-75 dark:hover:bg-gray-700 dark:hover:bg-opacity-75 text-gray-800 dark:text-gray-200 hover:text-gray-900 hover:dark:text-white","flex flex-row items-center mr-8",o?"pl-8 h-12":"pl-6 h-11","font-medium text-sm",c?"bg-slate-200 bg-opacity-60 dark:bg-gray-800 dark:bg-opacity-30":""),to:i,children:[s,r.jsx("div",{className:p.cls(o?"opacity-100":"opacity-0 hidden","ml-4 font-inherit text-inherit"),children:e.toUpperCase()})]});return r.jsx(p.Tooltip,{open:o?!1:a,side:"right",title:e,children:l})}function Yn(){const{hovered:e,drawerOpen:t,closeDrawer:o}=Un(),a=ut(),i=pe(),n=e&&!t,s=Me(),l=ge.useNavigate(),[c,u]=d.useState(!1);if(!i.topLevelNavigation)throw Error("Navigation not ready in Drawer");const{navigationEntries:f,groups:g}=i.topLevelNavigation,m=f.filter(b=>b.type==="admin")??[],h=g.filter(b=>b!=="Admin"),A=d.useCallback(b=>t?r.jsx("div",{className:"pt-8 pl-6 pr-8 pb-2 flex flex-row items-center",children:r.jsx(p.Typography,{variant:"caption",color:"secondary",className:"font-medium flex-grow line-clamp-1",children:b?b.toUpperCase():"Views".toUpperCase()})}):r.jsx("div",{className:"h-12 w-full"}),[t]),y=b=>{const v=b.type==="collection"?"drawer_navigate_to_collection":b.type==="view"?"drawer_navigate_to_view":"unmapped_event";a.onAnalyticsEvent?.(v,{url:b.url}),s||o()};return r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"flex-grow overflow-scroll no-scrollbar",children:h.map(b=>r.jsxs(d.Fragment,{children:[A(b),Object.values(f).filter(v=>v.group===b).map((v,k)=>r.jsx(Gn,{icon:r.jsx(Jt,{collectionOrView:v.collection??v.view}),tooltipsOpen:n,drawerOpen:t,onClick:()=>y(v),url:v.url,name:v.name},`navigation_${k}`))]},`drawer_group_${b}`))}),m.length>0&&r.jsx(p.Menu,{open:c,onOpenChange:u,trigger:r.jsxs(p.IconButton,{shape:"square",className:"m-4 text-gray-900 dark:text-white w-fit",children:[r.jsx(p.Tooltip,{title:"Admin",open:n,side:"right",sideOffset:28,children:r.jsx(p.MoreVertIcon,{})}),t&&r.jsx("div",{className:p.cls(t?"opacity-100":"opacity-0 hidden","mx-4 font-inherit text-inherit"),children:"ADMIN"})]}),children:m.map((b,v)=>r.jsxs(p.MenuItem,{onClick:k=>{k.preventDefault(),l(b.path)},children:[r.jsx(Jt,{collectionOrView:b.view}),b.name]},`navigation_${v}`))})]})}const Ln=280,jn=d.createContext({hovered:!1,drawerOpen:!1,openDrawer:()=>{throw new Error("openDrawer not implemented")},closeDrawer:()=>{throw new Error("closeDrawer not implemented")},autoOpenDrawer:!1});function Un(){return d.useContext(jn)}const Cc=d.memo(function(t){const{children:o,name:a,logo:i,includeDrawer:n=!0,autoOpenDrawer:s,drawer:l=r.jsx(Yn,{}),FireCMSAppBar:c=wn,fireCMSAppBarProps:u}=t,f=Me(),[g,m]=d.useState(!1),[h,A]=d.useState(!1),y=d.useCallback(()=>A(!0),[]),b=d.useCallback(()=>A(!1),[]),v=d.useCallback(()=>{m(!0)},[]),k=d.useCallback(()=>{m(!1)},[]),_=g||!!(f&&s&&h);return r.jsx(jn.Provider,{value:{hovered:h,drawerOpen:_,closeDrawer:k,openDrawer:v,autoOpenDrawer:s},children:r.jsxs("div",{className:"flex h-screen w-screen bg-gray-50 dark:bg-gray-900 text-gray-900 dark:text-white overflow-hidden",style:{paddingTop:"env(safe-area-inset-top)",paddingLeft:"env(safe-area-inset-left)",paddingRight:"env(safe-area-inset-right)",paddingBottom:"env(safe-area-inset-bottom)",height:"100dvh"},children:[r.jsx(c,{title:a,includeDrawer:n,logo:i,drawerOpen:_,...u}),r.jsx(Ec,{displayed:n,onMouseEnter:y,onMouseMove:y,onMouseLeave:b,open:_,logo:i,hovered:h,setDrawerOpen:m,children:n&&l}),r.jsxs("main",{className:"flex flex-col flex-grow overflow-auto",children:[r.jsx(xc,{}),r.jsx("div",{className:p.cls(p.defaultBorderMixin,"flex-grow overflow-auto lg:m-0 lg:mx-4 lg:mb-4 lg:rounded-lg lg:border lg:border-solid m-0 mt-1"),children:r.jsx(ne,{children:o})})]})]})})},L),xc=()=>r.jsx("div",{className:"flex flex-col min-h-[68px]"});function Ec(e){const t=pe(),o=e.displayed?e.open?Ln:72:0,a=r.jsxs("div",{className:"relative h-full no-scrollbar overflow-y-auto overflow-x-hidden",style:{width:o,transition:"left 100ms cubic-bezier(0.4, 0, 0.6, 1) 0ms, opacity 100ms cubic-bezier(0.4, 0, 0.6, 1) 0ms, width 100ms cubic-bezier(0.4, 0, 0.6, 1) 0ms"},children:[!e.open&&e.displayed&&r.jsx(p.Tooltip,{title:"Open menu",side:"right",sideOffset:12,className:"fixed top-2 left-3 !bg-gray-50 dark:!bg-gray-900 rounded-full w-fit",children:r.jsx(p.IconButton,{color:"inherit","aria-label":"Open menu",className:"sticky top-2 left-3 ",onClick:()=>e.setDrawerOpen(!0),size:"large",children:r.jsx(p.MenuIcon,{})})}),r.jsxs("div",{className:"flex flex-col h-full",children:[r.jsx("div",{style:{transition:"padding 100ms cubic-bezier(0.4, 0, 0.6, 1) 0ms",padding:e.open?"32px 144px 0px 24px":"72px 16px 0px"},className:p.cls("cursor-pointer"),children:r.jsx(p.Tooltip,{title:"Home",sideOffset:20,side:"right",children:r.jsx(ge.Link,{to:t.basePath,children:e.logo?r.jsx("img",{src:e.logo,alt:"Logo",className:p.cls("max-w-full max-h-full",e.open??"w-[112px] h-[112px]")}):r.jsx(po,{})})})}),e.children]})]});return Me()?r.jsxs("div",{className:"relative",onMouseEnter:e.onMouseEnter,onMouseMove:e.onMouseMove,onMouseLeave:e.onMouseLeave,style:{width:o,transition:"left 100ms cubic-bezier(0.4, 0, 0.6, 1) 0ms, opacity 100ms cubic-bezier(0.4, 0, 0.6, 1) 0ms, width 100ms cubic-bezier(0.4, 0, 0.6, 1) 0ms"},children:[a,r.jsx("div",{className:`absolute right-0 top-4 ${e.open?"opacity-100":"opacity-0 invisible"} transition-opacity duration-1000 ease-in-out`,children:r.jsx(p.IconButton,{"aria-label":"Close drawer",onClick:()=>e.setDrawerOpen(!1),children:r.jsx(p.ChevronLeftIcon,{})})})]}):e.displayed?r.jsxs(r.Fragment,{children:[r.jsx(p.IconButton,{color:"inherit","aria-label":"Open drawer",onClick:()=>e.setDrawerOpen(!0),size:"large",className:"absolute top-2 left-6",children:r.jsx(p.MenuIcon,{})}),r.jsx(p.Sheet,{side:"left",transparent:!0,open:e.open,onOpenChange:e.setDrawerOpen,children:a})]}):null}const Bc=d.memo(function({homePage:t=r.jsx(gn,{}),customRoutes:o}){const a=ge.useLocation(),i=pe();if(!i)return r.jsx(r.Fragment,{});const n=a.state,s=n&&n.base_location?n.base_location:a,l=[];i.views&&i.views.forEach(m=>{Array.isArray(m.path)?l.push(...m.path.map(h=>ur(h,m))):l.push(ur(m.path,m))}),i.adminViews&&i.adminViews.forEach(m=>{Array.isArray(m.path)?l.push(...m.path.map(h=>ur(h,m))):l.push(ur(m.path,m))});const u=[...i.collections??[]].sort((m,h)=>h.path.length-m.path.length).map(m=>{const h=i.buildUrlCollectionPath(m.id??m.path);return r.jsx(ge.Route,{path:h+"/*",element:r.jsx(ne,{children:r.jsx(co,{isSubCollection:!1,parentCollectionIds:[],fullPath:m.id??m.path,...m,Actions:Bt(m.Actions)},`collection_view_${m.id??m.path}`)})},`navigation_${m.id??m.path}`)}),f=r.jsx(ge.Route,{path:"/",element:t}),g=r.jsx(ge.Route,{path:"*",element:r.jsx(yn,{})});return r.jsxs(ge.Routes,{location:s,children:[u,l,f,g,o]})}),ur=(e,t)=>r.jsx(ge.Route,{path:e,element:t.view},"navigation_view_"+e);w.ArrayContainer=uo,w.ArrayContainerItem=fo,w.ArrayCustomShapedFieldBinding=Pn,w.ArrayEnumPreview=Lr,w.ArrayItemOptions=vn,w.ArrayOfMapsPreview=hs,w.ArrayOfReferencesFieldBinding=kn,w.ArrayOfReferencesPreview=Ta,w.ArrayOfStorageComponentsPreview=Da,w.ArrayOfStringsPreview=Qa,w.ArrayOneOfPreview=Ma,w.ArrayPropertyEnumPreview=jr,w.ArrayPropertyPreview=Yr,w.AsyncPreviewComponent=gs,w.AuthControllerContext=mr,w.BlockFieldBinding=Fn,w.BooleanPreview=Va,w.COLLECTION_PATH_SEPARATOR=Wo,w.CircularProgressCenter=rr,w.DEFAULT_FIELD_CONFIGS=nr,w.DRAWER_WIDTH=Ln,w.DatePreview=za,w.DateTimeFieldBinding=xn,w.DefaultHomePage=gn,w.DeleteConfirmationDialog=El,w.Drawer=Yn,w.DrawerNavigationItem=Gn,w.EmptyValue=et,w.EntityCollectionRowActions=er,w.EntityCollectionTable=to,w.EntityCollectionView=co,w.EntityCollectionViewActions=An,w.EntityForm=Dn,w.EntityReference=gr,w.EntityView=$r,w.EnumValuesChip=Ie,w.ErrorBoundary=ne,w.ErrorView=ye,w.FieldCaption=Pl,w.FieldHelperText=xe,w.FireCMS=kc,w.FireCMSAppBar=wn,w.FireCMSLogo=po,w.FormikArrayContainer=ar,w.GeoPoint=Ar,w.IconForView=Jt,w.ImagePreview=Ba,w.KeyValueFieldBinding=Sn,w.KeyValuePreview=Ur,w.LabelWithIcon=Ee,w.MapFieldBinding=Bn,w.MapPropertyPreview=Oa,w.MarkdownFieldBinding=Nn,w.ModeControllerContext=fr,w.ModeControllerProvider=ai,w.MultiSelectBinding=ho,w.NavigationCard=fn,w.NavigationCardBinding=hn,w.NavigationGroup=so,w.NavigationRoutes=Bc,w.NotFoundPage=yn,w.NumberPropertyPreview=Ga,w.PropertyConfigBadge=xl,w.PropertyFieldBinding=ot,w.PropertyPreview=we,w.PropertyTableCell=Xa,w.ReadOnlyFieldBinding=Ao,w.ReferenceFieldBinding=En,w.ReferencePreview=Oe,w.ReferenceSelectionTable=un,w.ReferenceWidget=Il,w.RepeatFieldBinding=In,w.Scaffold=Cc,w.SearchIconsView=Nl,w.SelectFieldBinding=mo,w.SelectableTable=ln,w.SelectableTableContext=Hr,w.SideDialogs=dc,w.SkeletonPropertyComponent=tt,w.SmallNavigationCard=mn,w.SnackbarProvider=ri,w.StorageThumbnail=Sa,w.StorageThumbnailInternal=Fa,w.StorageUploadFieldBinding=go,w.StringPropertyPreview=Gr,w.SwitchFieldBinding=Cn,w.TextFieldBinding=At,w.UrlComponentPreview=xt,w.Vector=si,w.VirtualTable=rn,w.addInitialSlash=ni,w.applyPermissionsFunctionIfEmpty=Uo,w.archiveEntityAction=cl,w.buildAdditionalFieldDelegate=Ti,w.buildCollection=Ei,w.buildEntityCallbacks=Pi,w.buildEnumLabel=Lo,w.buildEnumValueConfig=Ni,w.buildEnumValues=Fi,w.buildFieldConfig=Di,w.buildIdColumn=qs,w.buildProperties=Si,w.buildPropertiesOrBuilder=Ii,w.buildProperty=Bi,w.canCreateEntity=ct,w.canDeleteEntity=$t,w.canEditEntity=Ir,w.copyEntityAction=no,w.defaultDateFormat=$o,w.deleteEntityAction=io,w.deleteEntityWithCallbacks=Aa,w.editEntityAction=pn,w.enumToObjectEntries=We,w.flattenObject=Nr,w.fullPathToCollectionSegments=Br,w.getArrayValuesCount=ea,w.getBracketNotation=vi,w.getCollectionByPathOrId=Dt,w.getCollectionPathsCombinations=Qt,w.getColorForProperty=wi,w.getColorScheme=Yo,w.getColumnKeysForProperty=tr,w.getDefaultFieldConfig=On,w.getDefaultFieldId=ir,w.getDefaultPropertiesOrder=ki,w.getDefaultValueFor=zt,w.getDefaultValueForDataType=kr,w.getDefaultValuesFor=vt,w.getEntityImagePreviewPropertyKey=Ro,w.getEntityPreviewKeys=Ko,w.getEntityTitlePropertyKey=Fr,w.getFieldConfig=It,w.getFieldId=ko,w.getHashValue=yr,w.getIcon=Xo,w.getIconForProperty=Ce,w.getIconForWidget=jt,w.getIdIcon=yi,w.getLabelOrConfigFrom=Gt,w.getLastSegment=ii,w.getPropertiesWithPropertiesOrder=Zo,w.getPropertyInPath=Re,w.getRandomId=St,w.getReferenceFrom=Le,w.getResolvedPropertyInPath=Sr,w.getSidePanelKey=Wi,w.getValueInPath=Ye,w.hydrateRegExp=Jo,w.iconSynonyms=Wt,w.iconsSearch=qt,w.isDefaultFieldConfigId=Mn,w.isEmptyObject=vr,w.isEnumValueDisabled=di,w.isHidden=wt,w.isObject=Mt,w.isPropertyBuilder=_e,w.isReadOnly=st,w.isReferenceProperty=Ho,w.isValidRegExp=bi,w.joinCollectionLists=oa,w.makePropertiesEditable=ta,w.makePropertiesNonEditable=ra,w.mergeCollection=aa,w.mergeDeep=De,w.openWebsiteAction=dl,w.pick=zo,w.plural=Ci,w.printChanged=Tr,w.propertiesToColumns=en,w.randomColor=hi,w.randomString=lt,w.removeFunctions=br,w.removeInPath=li,w.removeInitialAndTrailingSlashes=fe,w.removeInitialSlash=Mo,w.removePropsIfExisting=Vo,w.removeTrailingSlash=Oo,w.removeUndefined=wr,w.renderSkeletonCaptionText=ls,w.renderSkeletonIcon=Vr,w.renderSkeletonImageThumbnail=zr,w.renderSkeletonText=je,w.resolveArrayProperty=Xe,w.resolveCollection=Ne,w.resolveCollectionPathIds=hr,w.resolveDefaultSelectedView=xr,w.resolveEntityView=xo,w.resolveEnumValues=ac,w.resolveNavigationFrom=ba,w.resolvePermissions=kt,w.resolveProperties=_o,w.resolveProperty=Pe,w.resolvePropertyEnum=Co,w.sanitizeData=ci,w.saveEntityWithCallbacks=Mr,w.segmentsToStrippedPath=qo,w.serializeRegExp=Ai,w.singular=xi,w.slugify=Yt,w.sortProperties=Cr,w.stripCollectionPath=Er,w.toKebabCase=ui,w.toSnakeCase=mi,w.traverseValueProperty=Vt,w.traverseValuesProperties=_r,w.unslugify=gi,w.updateDateAutoValues=Go,w.useAuthController=qe,w.useBrowserTitleAndIcon=Li,w.useBuildLocalConfigurationPersistence=Hi,w.useBuildModeController=Zi,w.useBuildNavigationController=$i,w.useClearRestoreValue=Te,w.useClipboard=wa,w.useCollectionFetch=Oi,w.useColumnIds=Kr,w.useCustomizationController=ae,w.useDataSource=Qe,w.useDataSourceEntityCollectionTableController=ro,w.useDebouncedCallback=Lt,w.useDebouncedData=cn,w.useDialogsController=ma,w.useDrawer=Un,w.useEntityFetch=Qr,w.useFireCMSContext=Ae,w.useLargeLayout=Me,w.useModeController=ya,w.useNavigationController=pe,w.useReferenceDialog=ft,w.useResolvedNavigationFrom=zi,w.useSelectableTableController=Za,w.useSelectionController=oo,w.useSideDialogContext=cr,w.useSideDialogsController=_t,w.useSideEntityController=Je,w.useSnackbarController=He,w.useStorageSource=dt,w.useTableSearchHelper=ao,w.useTraceUpdate=Qi,w.useValidateAuthenticator=Xi,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
|
|
589
589
|
//# sourceMappingURL=index.umd.js.map
|