@firecms/core 3.0.0-alpha.53 → 3.0.0-alpha.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.umd.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
(function(v,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("react/jsx-runtime"),require("react"),require("notistack"),require("object-hash"),require("formik"),require("@firecms/ui"),require("react-router-dom"),require("date-fns/format"),require("date-fns/locale"),require("react-fast-compare"),require("react-window"),require("react-use-measure"),require("@hello-pangea/dnd"),require("react-dropzone"),require("react-image-file-resizer"),require("markdown-it"),require("react-markdown-editor-lite"),require("yup"),require("react-datepicker"),require("js-search"),require("@radix-ui/react-portal")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","notistack","object-hash","formik","@firecms/ui","react-router-dom","date-fns/format","date-fns/locale","react-fast-compare","react-window","react-use-measure","@hello-pangea/dnd","react-dropzone","react-image-file-resizer","markdown-it","react-markdown-editor-lite","yup","react-datepicker","js-search","@radix-ui/react-portal"],r):(v=typeof globalThis<"u"?globalThis:v||self,r(v["FireCMS Core"]={},v.jsxRuntime,v.React,v.notistack,v.hash,v.formik,v.ui,v.reactRouterDom,v.format,v.locales,v.equal,v.reactWindow,v.useMeasure,v.dnd,v.reactDropzone,v.Resizer,v.MarkdownIt,v.MdEditor,v.yup,v.reactDatepicker,v.JsSearch,v.Portal))})(this,function(v,r,c,yn,vn,Ce,f,fe,yl,vl,oe,wl,cr,lt,wn,Cl,El,Re,Bl,Cn,kl,xl){"use strict";function bt(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const o=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,o.get?o:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const Ar=bt(c),En=bt(vl),Ee=bt(Bl),Il=bt(kl),Sl=bt(xl),Fl=({children:e})=>r.jsx(yn.SnackbarProvider,{maxSnack:3,autoHideDuration:3500,children:e}),Nl={mode:"light",setMode:e=>{},toggleMode:()=>{}},Dt=c.createContext(Nl),Ql=Dt.Provider,dr=c.createContext({});function Tl(e){return e.includes("-")||e.includes("_")||!e.includes(" ")?e.replace(/[-_]/g," ").replace(/\w\S*/g,function(n){return n.charAt(0).toUpperCase()+n.substr(1)}):e}function ue(e){return Bn(kn(e))}function Bn(e){return e.startsWith("/")?e.slice(1):e}function kn(e){return e.endsWith("/")?e.slice(0,-1):e}function Ml(e){return e.startsWith("/")?e:`/${e}`}function Pl(e){const t=ue(e);if(t.includes("/")){const n=t.split("/");return n[n.length-1]}return t}function fr(e,t){const n=ue(e),o=n.split("/");if(o.length%2===0)throw Error(`Collection paths must have an odd number of segments: ${e}`);const l=t.find(s=>s.id===o[0]);let i;if(l&&(i=l.path),o.length>1){const s=Ot(i??o[0],t);if(!s?.subcollections)return n;const a=n.split("/").slice(2).join("/");return(i??o[0])+"/"+o[1]+"/"+fr(a,s.subcollections)}else return i??n}function Ot(e,t){const n=ue(e).split("/");if(n.length%2===0)throw Error(`Collection paths must have an odd number of segments: ${e}`);const o=Vt(n);let l;for(let i=0;i<o.length;i++){const s=o[i],a=t&&t.sort((A,d)=>(A.id??"").localeCompare(d.id??"")).find(A=>A.id===s||A.path===s);if(a){if(s===e)l=a;else if(a.subcollections){const A=e.replace(s,"").split("/").slice(2).join("/");A.length>0&&(l=Ot(A,a.subcollections))}}if(l)break}return l}function Vt(e){const t=e.length>0&&e.length%2===0?e.splice(0,e.length-1):e,n=t.length,o=[];for(let l=n;l>0;l=l-2)o.push(t.slice(0,l).join("/"));return o}class Pe{id;path;constructor(t,n){this.id=t,this.path=n}get pathWithId(){return`${this.path}/${this.id}`}}class Gt{latitude;longitude;constructor(t,n){this.latitude=t,this.longitude=n}}const xn=(e,...t)=>({...t.reduce((n,o)=>({...n,[o]:e[o]}),{})});function Yt(e){return e&&typeof e=="object"&&!Array.isArray(e)}function Fe(e,t){const n=Yt(e),o=n?{...e}:e;return n&&Yt(t)&&Object.keys(t).forEach(l=>{Yt(t[l])?l in e?o[l]=Fe(e[l],t[l]):Object.assign(o,{[l]:t[l]}):Object.assign(o,{[l]:t[l]})}),o}function Le(e,t){if(e&&typeof e=="object"){if(t in e)return e[t];if(t.includes(".")||t.includes("[")){let n=t.split(/[.[]/);t.includes("[")&&(n=n.map(a=>a.replace("]","")));const o=n[0],l=Array.isArray(e[o])&&!isNaN(parseInt(n[1])),i=l?e[o][parseInt(n[1])]:e[o],s=n.slice(l?2:1).join(".");return s===""?i:Le(i,s)}}}function Dl(e,t){let n={...e};const o=t.split("."),l=o.pop();for(const i of o)n=n[i];return l&&delete n[l],n}function ur(e){if(e!==void 0)return e===null?null:typeof e=="object"?Object.entries(e).filter(([t,n])=>typeof n!="function").map(([t,n])=>Array.isArray(n)?{[t]:n.map(o=>ur(o))}:typeof n=="object"?{[t]:ur(n)}:{[t]:n}).reduce((t,n)=>({...t,...n}),{}):e}function gr(e){if(!e)return null;if(typeof e=="object"){if("id"in e)return e.id;if(e instanceof Date)return e.toLocaleString();if(e instanceof Gt)return vn(e)}return vn(e,{ignoreUnknown:!0})}function hr(e,t){if(typeof e=="function")return e;if(Array.isArray(e))return e.map(n=>hr(n,t));if(typeof e=="object"){const n={};return e===null?e:(Object.keys(e).forEach(o=>{if(!pr(e)){const l=hr(e[o],t),i=typeof l=="string",s=!t||t&&!i||t&&i&&l!=="";l!==void 0&&!pr(l)&&s&&(n[o]=l)}}),n)}return e}function pr(e){return e&&Object.getPrototypeOf(e)===Object.prototype&&Object.keys(e).length===0}function In(e,t){const n=i=>typeof i=="object"&&i!==null,o=i=>Array.isArray(i);if(!n(e)||!n(t))return e;const l=o(e)?[...e]:{...e};return Object.keys(t).forEach(i=>{i in l&&(n(l[i])&&n(t[i])?l[i]=In(l[i],t[i]):l[i]===t[i]&&(o(l)?l.splice(i,1):delete l[i]))}),l}const yt="type",zt="value";function it(e){return e.readOnly||e.dataType==="date"&&e.autoValue?!0:e.dataType==="reference"?!e.path:!1}function vt(e){return typeof e.disabled=="object"&&!!e.disabled.hidden}function ve(e){return typeof e=="function"}function wt(e){return e?Object.entries(e).map(([t,n])=>{const o=Ut(n);return o===void 0?{}:{[t]:o}}).reduce((t,n)=>({...t,...n}),{}):{}}function Ut(e){if(!ve(e))if(e.dataType==="map"&&e.properties){const t=wt(e.properties);return Object.keys(t).length===0?void 0:t}else return e.defaultValue?e.defaultValue:mr(e.dataType)}function mr(e){return e==="string"||e==="number"?null:e==="boolean"?!1:e==="date"?null:e==="array"?[]:e==="map"?{}:null}function Sn({inputValues:e,properties:t,status:n,timestampNowValue:o,setDateToMidnight:l}){return br(e,t,(i,s)=>{if(s.dataType==="date"){let a;return n==="existing"&&s.autoValue==="on_update"||(n==="new"||n==="copy")&&(s.autoValue==="on_update"||s.autoValue==="on_create")?a=o:a=i,s.mode==="date"&&(a=l(a)),a}else return i})??{}}function Ol(e,t){const n=e;return Object.entries(t).forEach(([o,l])=>{e&&e[o]!==void 0?n[o]=e[o]:l.validation?.required&&(n[o]=null)}),n}function et(e){return new Pe(e.id,e.path)}function br(e,t,n){const o=Object.entries(t).map(([i,s])=>{const a=e&&e[i],A=Lt(a,s,n);if(A!==void 0)return{[i]:A}}).reduce((i,s)=>({...i,...s}),{}),l={...e,...o};if(Object.keys(l).length!==0)return l}function Lt(e,t,n){let o;if(t.dataType==="map"&&t.properties)o=br(e,t.properties,n);else if(t.dataType==="array")if(t.of&&Array.isArray(e))o=e.map(l=>Lt(l,t.of,n));else if(t.oneOf&&Array.isArray(e)){const l=t.oneOf?.typeField??yt,i=t.oneOf?.valueField??zt;o=e.map(s=>{if(s===null)return null;if(typeof s!="object")return s;const a=s[l],A=t.oneOf?.properties[a];return!a||!A?s:{[l]:a,[i]:Lt(s[i],A,n)}})}else o=e;else o=n(e,t);return o}function Fn(e){let t=0,n,o;for(n=0;n<e.length;n++)o=e.charCodeAt(n),t=(t<<5)-t+o,t|=0;return Math.abs(t)}function Nn(e){const t=Fn(e),n=Object.keys(f.CHIP_COLORS),o=t%n.length;return f.CHIP_COLORS[n[o]]}function $e(e){return Array.isArray(e)?e:Object.entries(e).map(([t,n])=>typeof n=="string"?{id:t,label:n}:{...n,id:t})}function $t(e,t){if(t)return e.find(n=>String(n.id)===String(t))}function Qn(e,t){const n=$t(e,t);if(!n?.color)return Nn(t.toString());if(typeof n=="object"&&"color"in n){if(typeof n.color=="string")return f.CHIP_COLORS[n.color];if(typeof n.color=="object")return n.color}}function Vl(e){return typeof e=="object"&&e.disabled}function Tn(e){if(e!==void 0)return typeof e=="object"?e.label:e}const Be=({collection:e,path:t,entityId:n,values:o,previousValues:l,userConfigPersistence:i,fields:s})=>{const a=i?.getCollectionConfig(t),A=Le(a,"properties"),d=wt(e.properties),g=o??d,p=l??o??d,h=Object.entries(e.properties).map(([b,y])=>{const w=g?Ce.getIn(g,b):void 0;return{[b]:ke({propertyKey:b,propertyOrBuilder:y,values:g,previousValues:p,path:t,propertyValue:w,entityId:n,fields:s})}}).filter(b=>b!==null).reduce((b,y)=>({...b,...y}),{}),u=Fe(h,A),m=Object.entries(u).filter(([b,y])=>!!y?.dataType).map(([b,y])=>({[b]:y})).reduce((b,y)=>({...b,...y}),{});return{...e,properties:m,originalCollection:e}};function ke({propertyOrBuilder:e,propertyValue:t,fromBuilder:n=!1,...o}){if(typeof e=="object"&&"resolved"in e)return e;let l=null;if(e)if(ve(e)){const i=o.path;if(!i)throw Error("Trying to resolve a property builder without specifying the entity path");const s=e({...o,path:i,propertyValue:t,values:o.values??{},previousValues:o.previousValues??o.values??{}});if(!s)return console.debug("Property builder not returning `Property` so it is not rendered",i,o.entityId,e),null;l=ke({...o,propertyValue:t,propertyOrBuilder:s,fromBuilder:!0})}else{const i=e;if(i.dataType==="map"&&i.properties){const s=yr({...o,properties:i.properties,propertyValue:t});l={...i,resolved:!0,fromBuilder:n,properties:s}}else i.dataType==="array"?l=_e({property:i,propertyValue:t,fromBuilder:n,...o}):(i.dataType==="string"||i.dataType==="number")&&i.enumValues&&(l=vr(i,n))}else return null;if(l||(l={...e,resolved:!0,fromBuilder:n}),l.propertyConfig&&!hl(l.propertyConfig)){const i=o.fields;if(!i)throw Error(`Trying to resolve a property with key ${l.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=i[l.propertyConfig];if(!s)return console.warn(`Trying to resolve a property with key ${l.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",i),null;if(s.property){const a=s.property;"propertyConfig"in a&&delete a.propertyConfig;const A=ke({propertyOrBuilder:a,propertyValue:t,...o});A&&(l=Fe(A,l))}}return l?{...l,resolved:!0}:null}function _e({propertyKey:e,property:t,propertyValue:n,...o}){if(t.of){if(Array.isArray(t.of))return{...t,resolved:!0,fromBuilder:o.fromBuilder,resolvedProperties:t.of.map((l,i)=>ke({propertyKey:`${e}.${i}`,propertyOrBuilder:l,propertyValue:Array.isArray(n)?n[i]:void 0,...o,index:i}))};{const l=t.of,i=Array.isArray(n)?n.map((a,A)=>ke({propertyKey:`${e}.${A}`,propertyOrBuilder:l,propertyValue:a,...o,index:A})).filter(a=>!!a):[],s=ke({propertyKey:`${e}`,propertyOrBuilder:l,propertyValue:void 0,...o});if(!s)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:o.fromBuilder,of:s,resolvedProperties:i}}}else if(t.oneOf){const l=t.oneOf?.typeField??yt,i=Array.isArray(n)?n.map((a,A)=>{const d=a&&a[l],g=t.oneOf?.properties[d];return!d||!g?null:ke({propertyKey:`${e}.${A}`,propertyOrBuilder:g,propertyValue:n,...o})}).filter(a=>!!a):[],s=yr({properties:t.oneOf.properties,propertyValue:void 0,...o});return{...t,resolved:!0,oneOf:{...t.oneOf,properties:s},fromBuilder:o.fromBuilder,resolvedProperties:i}}else{if(t.Field)return{...t,resolved:!0,fromBuilder:o.fromBuilder};throw Error("The array property needs to declare an 'of' or a 'oneOf' property, or provide a custom `Field`")}}function yr({properties:e,propertyValue:t,...n}){return Object.entries(e).map(([o,l])=>({[o]:ke({propertyKey:o,propertyOrBuilder:l,propertyValue:t&&typeof t=="object"?Le(t,o):void 0,...n})})).filter(o=>o!==null).reduce((o,l)=>({...o,...l}),{})}function vr(e,t){return typeof e.enumValues=="object"?{...e,resolved:!0,enumValues:$e(e.enumValues)?.filter(n=>n&&n.id&&n.label)??[],fromBuilder:t??!1}:e}function Gl(e){return typeof e=="object"?Object.entries(e).map(([t,n])=>typeof n=="string"?{id:t,label:n}:n):Array.isArray(e)?e:void 0}function wr(e,t){return typeof e=="string"?t?.find(n=>n.key===e):e}function Cr(e){const{path:t,collections:n=[],currentFullPath:o}=e,l=ue(t).split("/"),i=Vt(l),s=[];for(let a=0;a<i.length;a++){const A=i[a],d=n&&n.find(g=>g.id===A||g.path===A);if(d){const g=d.id??d.path,p=o&&o.length>0?o+"/"+g:g;s.push({type:"collection",path:p,collection:d});const h=ue(ue(t).replace(A,"")),u=h.length>0?h.split("/"):[];if(u.length>0){const m=u[0],b=p+"/"+m;if(s.push({type:"entity",entityId:m,path:p,parentCollection:d}),u.length>1){const y=u.slice(1).join("/");if(!d)throw Error("collection not found resolving path: "+d);const w=d.entityViews,C=w&&w.map(E=>wr(E,e.contextEntityViews)).filter(Boolean).find(E=>E.key===y);if(C){const E=o&&o.length>0?o+"/"+C.key:C.key;s.push({type:"custom_view",path:E,view:C})}else d.subcollections&&s.push(...Cr({path:y,collections:d.subcollections,currentFullPath:b,contextEntityViews:e.contextEntityViews}))}}break}}return s}function Er(e,t){try{const n=Object.keys(e);return(t??n).map(l=>{if(e[l]){const i=e[l];return!ve(i)&&i?.dataType==="map"&&i.properties?{[l]:{...i,properties:Er(i.properties,i.propertiesOrder)}}:{[l]:i}}else return}).filter(l=>l!==void 0).reduce((l,i)=>({...l,...i}),{})}catch(n){return console.error("Error sorting properties",n),e}}function Br(e,t){if(e)return typeof e=="string"?e:e(t)}const Yl=/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g,zl=e=>{const t=e.match(Yl);return t?t.map(n=>n.toLowerCase()).join("-"):""},Ul=/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g,Ll=e=>{const t=e.match(Ul);return t?t.map(n=>n.toLowerCase()).join("_"):""};function st(e=5){return Math.random().toString(36).slice(2,2+e)}function $l(){return Math.floor(Math.random()*16777215).toString(16)}function _t(e,t="_",n=!0){if(!e)return"";const o="ãàáäâẽèéëêìíïîõòóöôùúüûñç·/_,:;-",l=`aaaaaeeeeeiiiiooooouuuunc${t}${t}${t}${t}${t}${t}${t}`;for(let i=0,s=o.length;i<s;i++)e=e.replace(new RegExp(o.charAt(i),"g"),l.charAt(i));return e=e.toString().replace(/\s+/g,t).replace(/&/g,t).replace(/[^\w\\-]+/g,"").replace(new RegExp("\\"+t+"\\"+t+"+","g"),t).trim().replace(/^\s+|\s+$/g,""),n?e.toLowerCase():e}const Mn="MMMM dd, yyyy, HH:mm:ss",Pn="::";function kr(e){return Dn(Ne(e))}function Dn(e){return e.length===1?e[0]:e.reduce((t,n)=>`${t}${Pn}${n}`)}function Ne(e){return e.split("/").filter((t,n)=>n%2===0)}function _l(e){return e?e.toString():""}function On(e){if(!e)return;const t=e.match(/\/(.*?)\/([a-z]*)?$/i);return t?new RegExp(t[1],t[2]||""):new RegExp(e,"")}function Wl(e){return e.match(/\/((?![*+?])(?:[^\r\n[/\\]|\\.|\[(?:[^\r\n\]\\]|\\.)*])+)\/((?:g(?:im?|mi?)?|i(?:gm?|mg?)?|m(?:gi?|ig?)?)?)/)?!0:!!e.match(/((?![*+?])(?:[^\r\n[/\\]|\\.|\[(?:[^\r\n\]\\]|\\.)*])+)/)}function Wt(e,t,n,o=300){const l=c.useRef(!1),i=()=>{t(),l.current=!1},s=c.useRef(void 0);c.useEffect(()=>(l.current=!0,clearTimeout(s.current),s.current=setTimeout(i,o),()=>{n&&i()}),[n,e])}function jl(e,t=300){const[n,o]=c.useState(e);return c.useEffect(()=>{const l=setTimeout(()=>{o(e)},t);return()=>{clearTimeout(l)}},[e,t]),n}function Vn(e,t){const n=ke({propertyKey:"ignore",propertyOrBuilder:e,fields:t});return n?n.dataType==="reference"?!0:n.dataType==="array"?Array.isArray(n.of)?!1:n.of?.dataType==="reference":!1:null}function Hl(e){return r.jsx(f.CircleIcon,{size:e})}function jt(e,t){const n=e?.Icon??f.CircleIcon;return r.jsx(n,{size:t})}function he(e,t="small",n={}){if(ve(e))return r.jsx(f.FunctionsIcon,{size:t});{const o=sr(e,n);return jt(o,t)}}function Jl(e,t){return ve(e)?"#888":sr(e,t)?.color??"#666"}function tt(e,t){if(typeof e=="object"){if(t in e)return e[t];if(t.includes(".")){const n=t.split("."),o=e[n[0]];if(typeof o=="object"&&o.dataType==="map"&&o.properties)return tt(o.properties,n.slice(1).join("."))}}}function xr(e,t){if(typeof e=="object"){if(t in e)return e[t];if(t.includes(".")){const n=t.split("."),o=e[n[0]];if(o.dataType==="map"&&o.properties)return xr(o.properties,n.slice(1).join("."))}}}function ql(e){return e.replace(/\.([^.]*)/g,"[$1]")}function Gn(e,t){if(!t)return e;const n={};return t.filter(Boolean).forEach(o=>{const l=tt(e,o);typeof l=="object"&&l.dataType==="map"&&l.properties&&(n[o]={...l,properties:Gn(l.properties,l.propertiesOrder??[])}),l&&(n[o]=l)}),n}function Zl(e){return e.propertiesOrder?e.propertiesOrder:[...Object.keys(e.properties),...(e.additionalFields??[]).map(t=>t.key)]}const Ht={read:!0,edit:!0,create:!0,delete:!0};function Ct(e,t,n,o){const l=e.permissions;if(l===void 0)return Ht;if(typeof l=="object")return l;if(typeof l=="function")return l({entity:o,user:t.user,authController:t,collection:e,pathSegments:n});throw console.error("Permissions:",l),Error("New type of permission added and not mapped")}function Ir(e,t,n,o){return Ct(e,t,n,o).edit??Ht.edit}function at(e,t,n,o){return Ct(e,t,n,o).create??Ht.create}function Jt(e,t,n,o){return Ct(e,t,n,o).delete??Ht.delete}function Yn(e,t){if(e&&(e=_t(e),e in Zt))return e in Zt?r.jsx(f.Icon,{iconKey:e,size:"medium",className:t}):void 0}function qt(e,t){const n=Yn(e.icon,t);if(e?.icon&&n)return n;let o=_t(("singularName"in e?e.singularName:void 0)??e.name),l;o in Zt&&(l=o),l||(o=_t(e.path),o in Zt&&(l=o));const i=f.coolIconKeys.length;return l||(l=f.coolIconKeys[Fn(e.path)%i]),r.jsx(f.Icon,{iconKey:l,size:"medium",className:t})}const Zt=f.iconKeys.reduce((e,t)=>(e[t]=t,e),{});function Xl(e,t){if(t!==void 0&&t===1)return e;const n={"(quiz)$":"$1zes","^(ox)$":"$1en","([m|l])ouse$":"$1ice","(matr|vert|ind)ix|ex$":"$1ices","(x|ch|ss|sh)$":"$1es","([^aeiouy]|qu)y$":"$1ies","(hive)$":"$1s","(?:([^f])fe|([lr])f)$":"$1$2ves","(shea|lea|loa|thie)f$":"$1ves",sis$:"ses","([ti])um$":"$1a","(tomat|potat|ech|her|vet)o$":"$1oes","(bu)s$":"$1ses","(alias)$":"$1es","(octop)us$":"$1i","(ax|test)is$":"$1es","(us)$":"$1es","([^s]+)$":"$1s"},o={move:"moves",foot:"feet",goose:"geese",sex:"sexes",child:"children",man:"men",tooth:"teeth",person:"people"};if(["sheep","fish","deer","moose","series","species","money","rice","information","equipment","bison","cod","offspring","pike","salmon","shrimp","swine","trout","aircraft","hovercraft","spacecraft","sugar","tuna","you","wood"].indexOf(e.toLowerCase())>=0)return e;for(const i in o){const s=new RegExp(`${i}$`,"i"),a=o[i];if(s.test(e))return e.replace(s,a)}for(const i in n){const s=new RegExp(i,"i");if(s.test(e))return e.replace(s,n[i])}return e}function Kl(e,t){if(t!==void 0&&t!==1)return e;const n={"(quiz)zes$":"$1","(matr)ices$":"$1ix","(vert|ind)ices$":"$1ex","^(ox)en$":"$1","(alias)es$":"$1","(octop|vir)i$":"$1us","(cris|ax|test)es$":"$1is","(shoe)s$":"$1","(o)es$":"$1","(bus)es$":"$1","([m|l])ice$":"$1ouse","(x|ch|ss|sh)es$":"$1","(m)ovies$":"$1ovie","(s)eries$":"$1eries","([^aeiouy]|qu)ies$":"$1y","([lr])ves$":"$1f","(tive)s$":"$1","(hive)s$":"$1","(li|wi|kni)ves$":"$1fe","(shea|loa|lea|thie)ves$":"$1f","(^analy)ses$":"$1sis","((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$":"$1$2sis","([ti])a$":"$1um","(n)ews$":"$1ews","(h|bl)ouses$":"$1ouse","(corpse)s$":"$1","(us)es$":"$1",s$:""},o={move:"moves",foot:"feet",goose:"geese",sex:"sexes",child:"children",man:"men",tooth:"teeth",person:"people"};if(["sheep","fish","deer","moose","series","species","money","rice","information","equipment","bison","cod","offspring","pike","salmon","shrimp","swine","trout","aircraft","hovercraft","spacecraft","sugar","tuna","you","wood"].indexOf(e.toLowerCase())>=0)return e;for(const i in o){const s=new RegExp(`${o[i]}$`,"i");if(s.test(e))return e.replace(s,i)}for(const i in n){const s=new RegExp(i,"i");if(s.test(e))return e.replace(s,n[i])}return e}function zn(e,t,n,o=3){const l=Object.keys(e.properties);let i=n?.filter(s=>l.includes(s));return i&&i.length>0?i:(i=l,i.filter(s=>{const a=e.properties[s];return a&&!ve(a)&&!Vn(a,t)}).slice(0,o))}function Sr(e,t=""){return e&&Object.keys(e).reduce((n,o)=>{const l=t?`${t}.${o}`:o;return typeof e[o]=="object"&&e[o]!==null?Array.isArray(e[o])?e[o].forEach((i,s)=>{Object.assign(n,Sr(i,`${l}[${s}]`))}):Object.assign(n,Sr(e[o],l)):n[l]=e[o],n},{})}function Un(e){return e.reduce((t,n)=>(Object.entries(n).forEach(([o,l])=>{if(Array.isArray(l)&&(t[o]=Math.max(t[o]||0,l.length)),typeof l=="object"&&l!==null){const i=Un([l]);Object.entries(i).forEach(([s,a])=>{const A=`${o}.${s}`;t[A]=Math.max(t[A]||0,a)})}}),t),{})}function Ln(e){return Object.keys(e).forEach(t=>{const n=e[t];n.editable=!0,n.dataType==="map"&&n.properties&&Ln(n.properties)}),e}function $n(e){return Object.entries(e).reduce((t,[n,o])=>{if(!ve(o)&&o.dataType==="map"&&o.properties){const l={...o,properties:$n(o.properties)};t[n]=l}return ve(o)?t[n]=o:t[n]={...o,editable:!1},t},{})}function Fr(e,t,n){if(e){const l=e({collection:t,parentPaths:n})??t;return l.subcollections&&(l.subcollections=l.subcollections.map(i=>Fr(e,i,[...n,t.path]))),l}else return t}function _n(e,t,n=[],o){const l=(t??[]).map(s=>{const a=e?.find(A=>A.id===s.id);return a?Wn(a,s,n,o):Fr(o,s,n)}),i=e.filter(s=>!l.map(a=>a.id).includes(s.id)).map(s=>o?Fr(o,s,n):s);return[...l,...i]}function Wn(e,t,n=[],o){const l=_n(e?.subcollections??[],t?.subcollections??[],[...n,e.path],o),i={...e.properties};Object.keys(t.properties).forEach(h=>{const u=e.properties[h];u?i[h]=jn(u,t.properties[h]):i[h]=t.properties[h]});const s=Fe(e,t),a=Hn(e),A=Hn(t),d=[...new Set([...A,...a])],g=[...new Set([...e.entityViews??[],...t.entityViews??[]])];let p={...s,subcollections:l,properties:Er(i,d),propertiesOrder:d,entityViews:g};if(o){const h=o({collection:p,parentPaths:n});h&&(p=h)}return p}function jn(e,t){if(ve(t))return t;{const n=Fe(e,t),o=!!e.editable,l=!!t.editable;if(t.dataType==="map"&&t.properties){const i="properties"in e?e.properties:{},s="properties"in t?t.properties:{},a="propertiesOrder"in e&&e.propertiesOrder?e.propertiesOrder:Object.keys(i),A="propertiesOrder"in t&&t.propertiesOrder?t.propertiesOrder:"properties"in t?Object.keys(t.properties):[],d=[...new Set([...a,...A])],g={...i};return Object.keys(t.properties).forEach(p=>{const h=i[p];h&&(g[p]=jn(h,s[p]))}),{...n,editable:o&&l,properties:g,propertiesOrder:d}}return{...n,editable:o&&l}}}function Hn(e){if(e.propertiesOrder&&e.propertiesOrder.length>0){const t=e.propertiesOrder;return e.additionalFields&&e.additionalFields.forEach(n=>{t.includes(n.key)||t.push(n.key)}),t}return[...Object.keys(e.properties),...(e.additionalFields??[])?.map(t=>t.key)]}function Rl(e){return e}function ei(e){return e}function ti(e){return e}function ri(e){return e}function ni(e){return e}function oi(e){return e}function li(e){return e}function ii(e){return e}function si(e){return e}const ai="100vw",ci="55vw",Jn="768px",qn=c.createContext({}),Qe=()=>c.useContext(qn),Zn=c.createContext({}),ie=()=>c.useContext(Zn),We=()=>c.useContext(dr),Xn=c.createContext({}),Et=()=>c.useContext(Xn),Kn=c.createContext({}),je=()=>c.useContext(Kn),Rn=c.createContext({}),ct=()=>c.useContext(Rn),He=()=>{const{enqueueSnackbar:e,closeSnackbar:t}=yn.useSnackbar(),n=c.useCallback(l=>{const{type:i,message:s,autoHideDuration:a}=l;e({message:s,variant:i,autoHideDuration:a})},[]),o=c.useCallback(()=>{t()},[]);return c.useMemo(()=>({open:n,close:o}),[n,o])},eo=c.createContext(void 0),At=()=>c.useContext(eo),Ai=c.createContext({}),di=()=>c.useContext(Ai),Nr=c.createContext({}),X=()=>{const e=c.useContext(Nr),t=We(),n=Et(),o=je(),l=ie(),i=Qe(),s=ct(),a=He(),A=At(),d=di();return{...e,authController:t,sideDialogsController:n,sideEntityController:o,navigation:l,dataSource:i,storageSource:s,snackbarController:a,userConfigPersistence:A,dialogsController:d}};function to({path:e,collection:t,filterValues:n,sortBy:o,itemCount:l,searchString:i}){const s=Qe(),A=ie().resolveAliasesFrom(e),d=o?o[0]:void 0,g=o?o[1]:void 0,p=X(),[h,u]=c.useState([]),[m,b]=c.useState(!1),[y,w]=c.useState(),[C,E]=c.useState(!1);return c.useEffect(()=>{b(!0);const k=async x=>{if(t.callbacks?.onFetch)try{x=await Promise.all(x.map(B=>t.callbacks.onFetch({collection:t,path:A,entity:B,context:p})))}catch(B){console.error(B)}b(!1),w(void 0),u(x.map(B=>({...B}))),E(!l||x.length<l)},I=x=>{console.error("ERROR",x),b(!1),u([]),w(x)};return s.listenCollection?s.listenCollection({path:A,collection:t,onUpdate:k,onError:I,searchString:i,filter:n,limit:l,startAfter:void 0,orderBy:d,order:g}):(s.fetchCollection({path:A,collection:t,searchString:i,filter:n,limit:l,startAfter:void 0,orderBy:d,order:g}).then(k).catch(I),()=>{})},[A,l,g,d,n,i]),{data:h,dataLoading:m,dataLoadingError:y,noMoreToLoad:C}}const Qr={};function Tr({path:e,entityId:t,collection:n,useCache:o=!1}){const l=Qe(),s=ie().resolveAliasesFrom(e),a=X(),[A,d]=c.useState(),[g,p]=c.useState(!0),[h,u]=c.useState();return c.useEffect(()=>{p(!0);const m=async y=>{if(n.callbacks?.onFetch&&y)try{y=await n.callbacks.onFetch({collection:n,path:s,entity:y,context:a})}catch(w){console.error(w)}Qr[`${s}/${t}`]=y,d(y),p(!1),u(void 0)},b=y=>{console.error("ERROR fetching entity",y),p(!1),d(void 0),u(y)};return t&&o&&Qr[`${s}/${t}`]?(d(Qr[`${s}/${t}`]),p(!1),u(void 0),()=>{}):t&&s&&n?l.listenEntity?l.listenEntity({path:s,entityId:t,collection:n,onUpdate:m,onError:b}):(l.fetchEntity({path:s,entityId:t,collection:n}).then(m).catch(b),()=>{}):(m(void 0),()=>{})},[t,s]),{entity:A,dataLoading:g,dataLoadingError:h}}async function Mr({collection:e,path:t,entityId:n,values:o,previousValues:l,status:i,dataSource:s,context:a,onSaveSuccess:A,onSaveFailure:d,onPreSaveHookError:g,onSaveSuccessHookError:p}){let h;const u=a.navigation.resolveAliasesFrom(t),m=e.callbacks;if(m?.onPreSave)try{const b=Be({collection:e,path:t,values:l,entityId:n,fields:a.propertyConfigs});h=await m.onPreSave({collection:b,path:t,resolvedPath:u,entityId:n,values:o,previousValues:l,status:i,context:a})}catch(b){console.error(b),g&&g(b);return}else h=o;return s.saveEntity({collection:e,path:u,entityId:n,values:h,previousValues:l,status:i}).then(b=>{try{if(m?.onSaveSuccess){const y=Be({collection:e,path:t,values:h,entityId:n,fields:a.propertyConfigs});m.onSaveSuccess({collection:y,path:t,resolvedPath:u,entityId:b.id,values:h,previousValues:l,status:i,context:a})}}catch(y){p&&p(y)}A&&A(b)}).catch(b=>{if(m?.onSaveFailure){const y=Be({collection:e,path:t,values:h,entityId:n,fields:a.propertyConfigs});m.onSaveFailure({collection:y,path:t,resolvedPath:u,entityId:n,values:h,previousValues:l,status:i,context:a})}d&&d(b)})}async function ro({dataSource:e,entity:t,collection:n,callbacks:o,onDeleteSuccess:l,onDeleteFailure:i,onPreDeleteHookError:s,onDeleteSuccessHookError:a,context:A}){console.debug("Deleting entity",t.path,t.id);const d={entity:t,collection:n,entityId:t.id,path:t.path,context:A};if(o?.onPreDelete)try{await o.onPreDelete(d)}catch(g){return console.error(g),s&&s(t,g),!1}return e.deleteEntity({entity:t}).then(()=>{l&&l(t);try{return o?.onDelete&&o.onDelete(d),!0}catch(g){return a&&a(t,g),!1}}).catch(g=>(i&&i(t,g),!1))}function xe({property:e,value:t,setValue:n}){const o=c.useRef(null);c.useEffect(()=>{typeof e.disabled=="object"&&!!e.disabled.clearOnDisabled?t!=null&&(o.current=t,n(null)):o.current&&(n(o.current),o.current=null)},[e])}function no({path:e,context:t}){const n=t.dataSource,o=t.navigation;if(!o)throw Error("Calling getNavigationFrom, but main navigation has not yet been initialised");const i=Cr({path:e,collections:o.collections??[]}).map(s=>{if(s.type==="collection")return Promise.resolve(s);if(s.type==="entity"){const a=o.getCollection(s.path,s.entityId);if(!a)throw Error(`No collection defined in the navigation for the entity with path ${s.path}`);return n.fetchEntity({path:s.path,entityId:s.entityId,collection:a}).then(A=>{if(A)return{...s,entity:A}})}else{if(s.type==="custom_view")return Promise.resolve(s);throw Error("Unmapped element in useEntitiesFromPath")}}).filter(s=>!!s);return Promise.all(i)}function fi({path:e}){const t=X(),[n,o]=c.useState(),[l,i]=c.useState(!1),[s,a]=c.useState();return c.useEffect(()=>{t.navigation&&(i(!0),a(void 0),no({path:e,context:t}).then(d=>{o(d)}).catch(d=>a(d)).finally(()=>i(!1)))},[e,t]),t.navigation?{data:n,dataLoading:l,dataLoadingError:s}:{dataLoading:!0}}const Pr=()=>c.useContext(Dt),oo=e=>{const{onSuccess:t,onError:n,disableClipboardAPI:o=!1,copiedDuration:l}=e||{},i=c.useRef(null),[s,a]=c.useState(!1),[A,d]=c.useState("");c.useEffect(()=>{l&&setTimeout(()=>a(!1),l)},[s]);const g=()=>navigator.clipboard!==void 0,p=c.useCallback(C=>{if(n)n(C);else throw new Error(C)},[n]),h=c.useCallback(C=>{t&&t(C),a(!0),d(C)},[t]),u=c.useCallback(C=>{navigator.clipboard.writeText(C).then(()=>h(C)).catch(E=>{p(E),a(!1)})},[p,h]),m=()=>{g()&&navigator.clipboard.writeText("")},b=C=>w("copy",typeof C=="object"?void 0:C),y=()=>w("cut"),w=c.useCallback((C="copy",E)=>{const k=i.current,I=k&&(k.tagName==="INPUT"||k.tagName==="TEXTAREA"),x=i.current;g()&&!o&&(E?u(E):k?I?(u(x.value),C==="cut"&&(x.value="")):u(k.innerText):p("Both the ref & text were undefined"))},[o,u,p]);return{ref:i,isCoppied:s,clipboard:A,clearClipboard:m,isSupported:g,copy:b,cut:y}},ui={xs:0,sm:640,md:768,lg:1024,xl:1280,"2xl":1536,"3xl":1920},Te=(e="lg")=>{const[t,n]=c.useState(!1);return c.useEffect(()=>{const o=()=>{const l=window.matchMedia(`(min-width: ${ui[e]+1}px)`).matches;n(l)};return o(),window.addEventListener("resize",o),()=>{window.removeEventListener("resize",o)}},[]),t};function lo(e){return r.jsx(f.Tooltip,{...e,tooltipClassName:"!text-red-500 bg-red-50",children:e.children})}function pe({title:e,error:t,tooltip:n}){const o=t instanceof Error?t.message:t;console.log("ErrorView",t);const l=r.jsxs("div",{className:"flex items-center m-2",children:[r.jsx(f.ErrorIcon,{size:"small",color:"error"}),r.jsxs("div",{className:"pl-2",children:[e&&r.jsx(f.Typography,{variant:"body2",className:"font-medium",children:e}),r.jsx(f.Typography,{variant:"body2",children:o})]})]});return n?r.jsx(lo,{title:n,children:l}):l}function dt(){return r.jsx("div",{className:"rounded-full bg-gray-200 bg-opacity-30 dark:bg-opacity-20 w-5 h-2 inline-block"})}const gi=40,hi=100,pi=200;function ft(e){if(e==="tiny")return gi;if(e==="small")return hi;if(e==="medium")return pi;throw Error("Thumbnail size not mapped")}function Je(e){switch(e){case"xs":case"s":return"tiny";case"m":return"small";case"l":case"xl":return"medium";default:throw Error("Missing mapping value in getPreviewSizeFrom: "+e)}}function io({size:e,url:t}){const[n,o]=c.useState(!1),l=c.useMemo(()=>ft(e),[e]);if(e==="tiny")return r.jsx("img",{src:t,className:"rounded-md",style:{position:"relative",objectFit:"cover",width:l,height:l,maxHeight:"100%"}},"tiny_image_preview_"+t);const i={maxWidth:"100%",maxHeight:"100%"};return r.jsxs("div",{className:"relative flex items-center justify-center max-w-full max-h-full",style:{width:l,height:l},onMouseEnter:()=>o(!0),onMouseMove:()=>o(!0),onMouseLeave:()=>o(!1),children:[r.jsx("img",{src:t,className:"rounded-md",style:i}),n&&r.jsxs(r.Fragment,{children:[navigator&&r.jsx(f.Tooltip,{title:"Copy url to clipboard",children:r.jsx("div",{className:"rounded-full absolute bottom-[-4px] right-8",children:r.jsx(f.IconButton,{variant:"filled",size:"small",onClick:s=>(s.stopPropagation(),s.preventDefault(),navigator.clipboard.writeText(t)),children:r.jsx(f.ContentCopyIcon,{className:"text-gray-500",size:"small"})})})}),r.jsx(f.Tooltip,{title:"Open image in new tab",children:r.jsx(f.IconButton,{variant:"filled",component:"a",style:{position:"absolute",bottom:-4,right:-4},href:t,rel:"noopener noreferrer",target:"_blank",size:"small",onClick:s=>s.stopPropagation(),children:r.jsx(f.OpenInNewIcon,{className:"text-gray-500",size:"small"})})})]})]},"image_preview_"+t)}function Bt({url:e,previewType:t,size:n,hint:o}){return t?t==="image"?r.jsx(io,{url:e,size:n}):t==="audio"?r.jsxs("audio",{controls:!0,src:e,children:["Your browser does not support the",r.jsx("code",{children:"audio"})," element."]}):t==="video"?r.jsx("video",{className:`max-w-${n==="small"?"sm":"md"}`,controls:!0,children:r.jsx("source",{src:e})}):r.jsxs("a",{href:e,rel:"noopener noreferrer",target:"_blank",onClick:l=>l.stopPropagation(),className:"flex flex-col items-center justify-center",style:{width:ft(n),height:ft(n)},children:[r.jsx(f.DescriptionIcon,{className:"flex-grow"}),o&&r.jsx(f.Tooltip,{title:o,children:r.jsx(f.Typography,{className:"max-w-full truncate rtl text-left",variant:"caption",children:o})})]}):!e||!e.trim()?r.jsx(dt,{}):r.jsxs("a",{className:"flex gap-4 break-words items-center font-medium text-primary visited:text-primary dark:visited:text-primary dark:text-primary",href:e,rel:"noopener noreferrer",onMouseDown:l=>{l.preventDefault()},target:"_blank",children:[r.jsx(f.OpenInNewIcon,{size:"small"}),e]})}function ut({property:e,size:t}){e||console.error("No property assigned for skeleton component",e,t);let n;if(e.dataType==="string"){const o=e;o.url?n=Ci(o,t):o.storage?n=Or(t):n=Ve()}else if(e.dataType==="array"){const o=e;o.of&&(Array.isArray(o.of)?n=r.jsxs(r.Fragment,{children:[o.of.map((l,i)=>Dr(l,i))," "]}):o.of.dataType==="map"&&o.of.properties?n=bi(o.of.properties,t,o.of.previewProperties):o.of.dataType==="string"?o.of.enumValues?n=vi():o.of.storage?n=Dr(o.of):n=yi():n=Dr(o.of))}else e.dataType==="map"?n=mi(e,t):e.dataType==="date"?n=Ve():e.dataType==="reference"?n=wi():(e.dataType,n=Ve());return n||null}function mi(e,t){if(!e.properties)return r.jsx(r.Fragment,{});let n;return t==="medium"?n=Object.keys(e.properties):(n=e.previewProperties||Object.keys(e.properties),t==="small"?n=n.slice(0,3):t==="tiny"&&(n=n.slice(0,1))),t!=="medium"?r.jsx("div",{className:"w-full flex flex-col space-y-4",children:n.map((o,l)=>r.jsx("div",{children:e.properties&&e.properties[o]&&r.jsx(ut,{property:e.properties[o],size:"small"})},`map_${o}`))}):r.jsx("table",{className:"table-auto",children:r.jsx("tbody",{children:n&&n.map((o,l)=>r.jsxs("tr",{className:"border-b last:border-b-0",children:[r.jsx("th",{className:"align-top",style:{width:"30%"},children:r.jsx("p",{className:"text-xs text-secondary",children:e.properties[o].name})},`table-cell-title--${o}`),r.jsx("th",{style:{width:"70%"},children:e.properties&&e.properties[o]&&r.jsx(ut,{property:e.properties[o],size:"small"})},`table-cell-${o}`)]},`map_preview_table__${l}`))})})}function bi(e,t,n){let o=n;return(!o||!o.length)&&(o=Object.keys(e),t&&(o=o.slice(0,3))),r.jsx("table",{className:"table-auto",children:r.jsx("tbody",{children:[0,1,2].map((l,i)=>r.jsx("tr",{children:o&&o.map(s=>r.jsx("th",{children:r.jsx(ut,{property:e[s],size:"small"})},`table-cell-${s}`))},`table_${l}_${i}`))})})}function yi(){return r.jsx("div",{className:"flex flex-col gap-2",children:[0,1].map((e,t)=>Ve(t))})}function vi(){return r.jsx("div",{className:"flex flex-col gap-2",children:[0,1].map((e,t)=>r.jsx(r.Fragment,{children:Ve(t)}))})}function Dr(e,t=0){return r.jsx("div",{className:"flex flex-col gap-2",children:[0,1].map((n,o)=>r.jsx(r.Fragment,{children:r.jsx(ut,{property:e,size:"small"},`i_${o}`)}))},"array_index_"+t)}function Or(e){const t=e==="tiny"?40:e==="small"?100:200;return r.jsx(f.Skeleton,{width:t,height:t})}function wi(){return r.jsx(f.Skeleton,{width:200,height:100})}function Ci(e,t="medium"){return typeof e.url=="boolean"?r.jsxs("div",{style:{display:"flex"},children:[Vr(),Ve()]}):Ei(t)}function Ei(e){return r.jsx("div",{className:`w-${ft(e)} h-${ft(e)}`,children:Vr()})}function Ve(e,t=120){return r.jsx(f.Skeleton,{width:t},`skeleton_${e}`)}function Bi(e){return r.jsx(f.Skeleton,{height:20})}function Vr(){return r.jsx(f.Skeleton,{width:24,height:24})}const so=c.memo(co,ki);function ki(e,t){return e.size===t.size&&e.storagePathOrDownloadUrl===t.storagePathOrDownloadUrl&&e.storeUrl===t.storeUrl}const ao={};function co({storeUrl:e,storagePathOrDownloadUrl:t,size:n}){const[o,l]=c.useState(void 0),i=ct(),[s,a]=c.useState(ao[t]);if(c.useEffect(()=>{if(!t)return;let g=!1;return i.getDownloadURL(t).then(function(p){g||(a(p),ao[t]=p)}).catch(l),()=>{g=!0}},[t]),!t)return null;const A=s?.metadata?xi(s?.metadata.contentType):void 0,d=A?.startsWith("image")?"image":A?.startsWith("video")?"video":A?.startsWith("audio")?"audio":"file";return s?.fileNotFound?r.jsx(pe,{error:"File not found"}):s?.url?r.jsx(Bt,{previewType:d,url:s.url,size:n,hint:t}):Or(n)}function xi(e){return e.startsWith("image")?"image/*":e.startsWith("video")?"video/*":e.startsWith("audio")?"audio/*":e.startsWith("application")?"application/*":e.startsWith("text")?"text/*":e.startsWith("font")?"font/*":e}function we({enumValues:e,enumKey:t,size:n,className:o,children:l}){if(!e)return null;const i=$e(e),s=t!==void 0?$t(i,t):void 0,a=Tn(s),A=Qn(i,t);return r.jsxs(f.Chip,{className:o,colorScheme:A,error:!a,outlined:!1,size:n,children:[l,!l&&(a!==void 0?a:String(t))]})}function Gr({propertyKey:e,value:t,property:n,size:o}){if(n.enumValues){const l=t,i=vr(n);return r.jsx(we,{enumKey:l,enumValues:i.enumValues,size:o!=="medium"?"small":"medium"})}else if(n.previewAsTag){const l=Nn(e??"");return r.jsx(ne,{children:r.jsx(f.Chip,{colorScheme:l,size:o!=="medium"?"small":"medium",children:t})})}else{if(n.url)return r.jsx(Bt,{size:o,url:t,previewType:typeof n.url=="string"?n.url:void 0});{if(!t)return r.jsx(r.Fragment,{});const l=t.split(`
|
|
1
|
+
(function(v,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("react/jsx-runtime"),require("react"),require("notistack"),require("object-hash"),require("formik"),require("@firecms/ui"),require("react-router-dom"),require("date-fns"),require("date-fns/locale"),require("react-fast-compare"),require("react-window"),require("react-use-measure"),require("@hello-pangea/dnd"),require("react-dropzone"),require("react-image-file-resizer"),require("markdown-it"),require("react-markdown-editor-lite"),require("yup"),require("react-datepicker"),require("js-search"),require("@radix-ui/react-portal")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","notistack","object-hash","formik","@firecms/ui","react-router-dom","date-fns","date-fns/locale","react-fast-compare","react-window","react-use-measure","@hello-pangea/dnd","react-dropzone","react-image-file-resizer","markdown-it","react-markdown-editor-lite","yup","react-datepicker","js-search","@radix-ui/react-portal"],r):(v=typeof globalThis<"u"?globalThis:v||self,r(v["FireCMS Core"]={},v.jsxRuntime,v.React,v.notistack,v.hash,v.formik,v.ui,v.reactRouterDom,v.dateFns,v.locales,v.equal,v.reactWindow,v.useMeasure,v.dnd,v.reactDropzone,v.Resizer,v.MarkdownIt,v.MdEditor,v.yup,v.reactDatepicker,v.JsSearch,v.Portal))})(this,function(v,r,c,yn,vn,Ce,f,fe,yl,vl,oe,wl,cr,lt,wn,Cl,El,Re,Bl,Cn,kl,xl){"use strict";function bt(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const o=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,o.get?o:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const Ar=bt(c),En=bt(vl),Ee=bt(Bl),Il=bt(kl),Sl=bt(xl),Fl=({children:e})=>r.jsx(yn.SnackbarProvider,{maxSnack:3,autoHideDuration:3500,children:e}),Nl={mode:"light",setMode:e=>{},toggleMode:()=>{}},Dt=c.createContext(Nl),Ql=Dt.Provider,dr=c.createContext({});function Tl(e){return e.includes("-")||e.includes("_")||!e.includes(" ")?e.replace(/[-_]/g," ").replace(/\w\S*/g,function(n){return n.charAt(0).toUpperCase()+n.substr(1)}):e}function ue(e){return Bn(kn(e))}function Bn(e){return e.startsWith("/")?e.slice(1):e}function kn(e){return e.endsWith("/")?e.slice(0,-1):e}function Ml(e){return e.startsWith("/")?e:`/${e}`}function Pl(e){const t=ue(e);if(t.includes("/")){const n=t.split("/");return n[n.length-1]}return t}function fr(e,t){const n=ue(e),o=n.split("/");if(o.length%2===0)throw Error(`Collection paths must have an odd number of segments: ${e}`);const l=t.find(s=>s.id===o[0]);let i;if(l&&(i=l.path),o.length>1){const s=Ot(i??o[0],t);if(!s?.subcollections)return n;const a=n.split("/").slice(2).join("/");return(i??o[0])+"/"+o[1]+"/"+fr(a,s.subcollections)}else return i??n}function Ot(e,t){const n=ue(e).split("/");if(n.length%2===0)throw Error(`Collection paths must have an odd number of segments: ${e}`);const o=Vt(n);let l;for(let i=0;i<o.length;i++){const s=o[i],a=t&&t.sort((A,d)=>(A.id??"").localeCompare(d.id??"")).find(A=>A.id===s||A.path===s);if(a){if(s===e)l=a;else if(a.subcollections){const A=e.replace(s,"").split("/").slice(2).join("/");A.length>0&&(l=Ot(A,a.subcollections))}}if(l)break}return l}function Vt(e){const t=e.length>0&&e.length%2===0?e.splice(0,e.length-1):e,n=t.length,o=[];for(let l=n;l>0;l=l-2)o.push(t.slice(0,l).join("/"));return o}class Pe{id;path;constructor(t,n){this.id=t,this.path=n}get pathWithId(){return`${this.path}/${this.id}`}}class Gt{latitude;longitude;constructor(t,n){this.latitude=t,this.longitude=n}}const xn=(e,...t)=>({...t.reduce((n,o)=>({...n,[o]:e[o]}),{})});function Yt(e){return e&&typeof e=="object"&&!Array.isArray(e)}function Fe(e,t){const n=Yt(e),o=n?{...e}:e;return n&&Yt(t)&&Object.keys(t).forEach(l=>{Yt(t[l])?l in e?o[l]=Fe(e[l],t[l]):Object.assign(o,{[l]:t[l]}):Object.assign(o,{[l]:t[l]})}),o}function Le(e,t){if(e&&typeof e=="object"){if(t in e)return e[t];if(t.includes(".")||t.includes("[")){let n=t.split(/[.[]/);t.includes("[")&&(n=n.map(a=>a.replace("]","")));const o=n[0],l=Array.isArray(e[o])&&!isNaN(parseInt(n[1])),i=l?e[o][parseInt(n[1])]:e[o],s=n.slice(l?2:1).join(".");return s===""?i:Le(i,s)}}}function Dl(e,t){let n={...e};const o=t.split("."),l=o.pop();for(const i of o)n=n[i];return l&&delete n[l],n}function ur(e){if(e!==void 0)return e===null?null:typeof e=="object"?Object.entries(e).filter(([t,n])=>typeof n!="function").map(([t,n])=>Array.isArray(n)?{[t]:n.map(o=>ur(o))}:typeof n=="object"?{[t]:ur(n)}:{[t]:n}).reduce((t,n)=>({...t,...n}),{}):e}function gr(e){if(!e)return null;if(typeof e=="object"){if("id"in e)return e.id;if(e instanceof Date)return e.toLocaleString();if(e instanceof Gt)return vn(e)}return vn(e,{ignoreUnknown:!0})}function hr(e,t){if(typeof e=="function")return e;if(Array.isArray(e))return e.map(n=>hr(n,t));if(typeof e=="object"){const n={};return e===null?e:(Object.keys(e).forEach(o=>{if(!pr(e)){const l=hr(e[o],t),i=typeof l=="string",s=!t||t&&!i||t&&i&&l!=="";l!==void 0&&!pr(l)&&s&&(n[o]=l)}}),n)}return e}function pr(e){return e&&Object.getPrototypeOf(e)===Object.prototype&&Object.keys(e).length===0}function In(e,t){const n=i=>typeof i=="object"&&i!==null,o=i=>Array.isArray(i);if(!n(e)||!n(t))return e;const l=o(e)?[...e]:{...e};return Object.keys(t).forEach(i=>{i in l&&(n(l[i])&&n(t[i])?l[i]=In(l[i],t[i]):l[i]===t[i]&&(o(l)?l.splice(i,1):delete l[i]))}),l}const yt="type",zt="value";function it(e){return e.readOnly||e.dataType==="date"&&e.autoValue?!0:e.dataType==="reference"?!e.path:!1}function vt(e){return typeof e.disabled=="object"&&!!e.disabled.hidden}function ve(e){return typeof e=="function"}function wt(e){return e?Object.entries(e).map(([t,n])=>{const o=Ut(n);return o===void 0?{}:{[t]:o}}).reduce((t,n)=>({...t,...n}),{}):{}}function Ut(e){if(!ve(e))if(e.dataType==="map"&&e.properties){const t=wt(e.properties);return Object.keys(t).length===0?void 0:t}else return e.defaultValue?e.defaultValue:mr(e.dataType)}function mr(e){return e==="string"||e==="number"?null:e==="boolean"?!1:e==="date"?null:e==="array"?[]:e==="map"?{}:null}function Sn({inputValues:e,properties:t,status:n,timestampNowValue:o,setDateToMidnight:l}){return br(e,t,(i,s)=>{if(s.dataType==="date"){let a;return n==="existing"&&s.autoValue==="on_update"||(n==="new"||n==="copy")&&(s.autoValue==="on_update"||s.autoValue==="on_create")?a=o:a=i,s.mode==="date"&&(a=l(a)),a}else return i})??{}}function Ol(e,t){const n=e;return Object.entries(t).forEach(([o,l])=>{e&&e[o]!==void 0?n[o]=e[o]:l.validation?.required&&(n[o]=null)}),n}function et(e){return new Pe(e.id,e.path)}function br(e,t,n){const o=Object.entries(t).map(([i,s])=>{const a=e&&e[i],A=Lt(a,s,n);if(A!==void 0)return{[i]:A}}).reduce((i,s)=>({...i,...s}),{}),l={...e,...o};if(Object.keys(l).length!==0)return l}function Lt(e,t,n){let o;if(t.dataType==="map"&&t.properties)o=br(e,t.properties,n);else if(t.dataType==="array")if(t.of&&Array.isArray(e))o=e.map(l=>Lt(l,t.of,n));else if(t.oneOf&&Array.isArray(e)){const l=t.oneOf?.typeField??yt,i=t.oneOf?.valueField??zt;o=e.map(s=>{if(s===null)return null;if(typeof s!="object")return s;const a=s[l],A=t.oneOf?.properties[a];return!a||!A?s:{[l]:a,[i]:Lt(s[i],A,n)}})}else o=e;else o=n(e,t);return o}function Fn(e){let t=0,n,o;for(n=0;n<e.length;n++)o=e.charCodeAt(n),t=(t<<5)-t+o,t|=0;return Math.abs(t)}function Nn(e){const t=Fn(e),n=Object.keys(f.CHIP_COLORS),o=t%n.length;return f.CHIP_COLORS[n[o]]}function $e(e){return Array.isArray(e)?e:Object.entries(e).map(([t,n])=>typeof n=="string"?{id:t,label:n}:{...n,id:t})}function $t(e,t){if(t)return e.find(n=>String(n.id)===String(t))}function Qn(e,t){const n=$t(e,t);if(!n?.color)return Nn(t.toString());if(typeof n=="object"&&"color"in n){if(typeof n.color=="string")return f.CHIP_COLORS[n.color];if(typeof n.color=="object")return n.color}}function Vl(e){return typeof e=="object"&&e.disabled}function Tn(e){if(e!==void 0)return typeof e=="object"?e.label:e}const Be=({collection:e,path:t,entityId:n,values:o,previousValues:l,userConfigPersistence:i,fields:s})=>{const a=i?.getCollectionConfig(t),A=Le(a,"properties"),d=wt(e.properties),g=o??d,p=l??o??d,h=Object.entries(e.properties).map(([b,y])=>{const w=g?Ce.getIn(g,b):void 0;return{[b]:ke({propertyKey:b,propertyOrBuilder:y,values:g,previousValues:p,path:t,propertyValue:w,entityId:n,fields:s})}}).filter(b=>b!==null).reduce((b,y)=>({...b,...y}),{}),u=Fe(h,A),m=Object.entries(u).filter(([b,y])=>!!y?.dataType).map(([b,y])=>({[b]:y})).reduce((b,y)=>({...b,...y}),{});return{...e,properties:m,originalCollection:e}};function ke({propertyOrBuilder:e,propertyValue:t,fromBuilder:n=!1,...o}){if(typeof e=="object"&&"resolved"in e)return e;let l=null;if(e)if(ve(e)){const i=o.path;if(!i)throw Error("Trying to resolve a property builder without specifying the entity path");const s=e({...o,path:i,propertyValue:t,values:o.values??{},previousValues:o.previousValues??o.values??{}});if(!s)return console.debug("Property builder not returning `Property` so it is not rendered",i,o.entityId,e),null;l=ke({...o,propertyValue:t,propertyOrBuilder:s,fromBuilder:!0})}else{const i=e;if(i.dataType==="map"&&i.properties){const s=yr({...o,properties:i.properties,propertyValue:t});l={...i,resolved:!0,fromBuilder:n,properties:s}}else i.dataType==="array"?l=_e({property:i,propertyValue:t,fromBuilder:n,...o}):(i.dataType==="string"||i.dataType==="number")&&i.enumValues&&(l=vr(i,n))}else return null;if(l||(l={...e,resolved:!0,fromBuilder:n}),l.propertyConfig&&!hl(l.propertyConfig)){const i=o.fields;if(!i)throw Error(`Trying to resolve a property with key ${l.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=i[l.propertyConfig];if(!s)return console.warn(`Trying to resolve a property with key ${l.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",i),null;if(s.property){const a=s.property;"propertyConfig"in a&&delete a.propertyConfig;const A=ke({propertyOrBuilder:a,propertyValue:t,...o});A&&(l=Fe(A,l))}}return l?{...l,resolved:!0}:null}function _e({propertyKey:e,property:t,propertyValue:n,...o}){if(t.of){if(Array.isArray(t.of))return{...t,resolved:!0,fromBuilder:o.fromBuilder,resolvedProperties:t.of.map((l,i)=>ke({propertyKey:`${e}.${i}`,propertyOrBuilder:l,propertyValue:Array.isArray(n)?n[i]:void 0,...o,index:i}))};{const l=t.of,i=Array.isArray(n)?n.map((a,A)=>ke({propertyKey:`${e}.${A}`,propertyOrBuilder:l,propertyValue:a,...o,index:A})).filter(a=>!!a):[],s=ke({propertyKey:`${e}`,propertyOrBuilder:l,propertyValue:void 0,...o});if(!s)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:o.fromBuilder,of:s,resolvedProperties:i}}}else if(t.oneOf){const l=t.oneOf?.typeField??yt,i=Array.isArray(n)?n.map((a,A)=>{const d=a&&a[l],g=t.oneOf?.properties[d];return!d||!g?null:ke({propertyKey:`${e}.${A}`,propertyOrBuilder:g,propertyValue:n,...o})}).filter(a=>!!a):[],s=yr({properties:t.oneOf.properties,propertyValue:void 0,...o});return{...t,resolved:!0,oneOf:{...t.oneOf,properties:s},fromBuilder:o.fromBuilder,resolvedProperties:i}}else{if(t.Field)return{...t,resolved:!0,fromBuilder:o.fromBuilder};throw Error("The array property needs to declare an 'of' or a 'oneOf' property, or provide a custom `Field`")}}function yr({properties:e,propertyValue:t,...n}){return Object.entries(e).map(([o,l])=>({[o]:ke({propertyKey:o,propertyOrBuilder:l,propertyValue:t&&typeof t=="object"?Le(t,o):void 0,...n})})).filter(o=>o!==null).reduce((o,l)=>({...o,...l}),{})}function vr(e,t){return typeof e.enumValues=="object"?{...e,resolved:!0,enumValues:$e(e.enumValues)?.filter(n=>n&&n.id&&n.label)??[],fromBuilder:t??!1}:e}function Gl(e){return typeof e=="object"?Object.entries(e).map(([t,n])=>typeof n=="string"?{id:t,label:n}:n):Array.isArray(e)?e:void 0}function wr(e,t){return typeof e=="string"?t?.find(n=>n.key===e):e}function Cr(e){const{path:t,collections:n=[],currentFullPath:o}=e,l=ue(t).split("/"),i=Vt(l),s=[];for(let a=0;a<i.length;a++){const A=i[a],d=n&&n.find(g=>g.id===A||g.path===A);if(d){const g=d.id??d.path,p=o&&o.length>0?o+"/"+g:g;s.push({type:"collection",path:p,collection:d});const h=ue(ue(t).replace(A,"")),u=h.length>0?h.split("/"):[];if(u.length>0){const m=u[0],b=p+"/"+m;if(s.push({type:"entity",entityId:m,path:p,parentCollection:d}),u.length>1){const y=u.slice(1).join("/");if(!d)throw Error("collection not found resolving path: "+d);const w=d.entityViews,C=w&&w.map(E=>wr(E,e.contextEntityViews)).filter(Boolean).find(E=>E.key===y);if(C){const E=o&&o.length>0?o+"/"+C.key:C.key;s.push({type:"custom_view",path:E,view:C})}else d.subcollections&&s.push(...Cr({path:y,collections:d.subcollections,currentFullPath:b,contextEntityViews:e.contextEntityViews}))}}break}}return s}function Er(e,t){try{const n=Object.keys(e);return(t??n).map(l=>{if(e[l]){const i=e[l];return!ve(i)&&i?.dataType==="map"&&i.properties?{[l]:{...i,properties:Er(i.properties,i.propertiesOrder)}}:{[l]:i}}else return}).filter(l=>l!==void 0).reduce((l,i)=>({...l,...i}),{})}catch(n){return console.error("Error sorting properties",n),e}}function Br(e,t){if(e)return typeof e=="string"?e:e(t)}const Yl=/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g,zl=e=>{const t=e.match(Yl);return t?t.map(n=>n.toLowerCase()).join("-"):""},Ul=/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g,Ll=e=>{const t=e.match(Ul);return t?t.map(n=>n.toLowerCase()).join("_"):""};function st(e=5){return Math.random().toString(36).slice(2,2+e)}function $l(){return Math.floor(Math.random()*16777215).toString(16)}function _t(e,t="_",n=!0){if(!e)return"";const o="ãàáäâẽèéëêìíïîõòóöôùúüûñç·/_,:;-",l=`aaaaaeeeeeiiiiooooouuuunc${t}${t}${t}${t}${t}${t}${t}`;for(let i=0,s=o.length;i<s;i++)e=e.replace(new RegExp(o.charAt(i),"g"),l.charAt(i));return e=e.toString().replace(/\s+/g,t).replace(/&/g,t).replace(/[^\w\\-]+/g,"").replace(new RegExp("\\"+t+"\\"+t+"+","g"),t).trim().replace(/^\s+|\s+$/g,""),n?e.toLowerCase():e}const Mn="MMMM dd, yyyy, HH:mm:ss",Pn="::";function kr(e){return Dn(Ne(e))}function Dn(e){return e.length===1?e[0]:e.reduce((t,n)=>`${t}${Pn}${n}`)}function Ne(e){return e.split("/").filter((t,n)=>n%2===0)}function _l(e){return e?e.toString():""}function On(e){if(!e)return;const t=e.match(/\/(.*?)\/([a-z]*)?$/i);return t?new RegExp(t[1],t[2]||""):new RegExp(e,"")}function Wl(e){return e.match(/\/((?![*+?])(?:[^\r\n[/\\]|\\.|\[(?:[^\r\n\]\\]|\\.)*])+)\/((?:g(?:im?|mi?)?|i(?:gm?|mg?)?|m(?:gi?|ig?)?)?)/)?!0:!!e.match(/((?![*+?])(?:[^\r\n[/\\]|\\.|\[(?:[^\r\n\]\\]|\\.)*])+)/)}function Wt(e,t,n,o=300){const l=c.useRef(!1),i=()=>{t(),l.current=!1},s=c.useRef(void 0);c.useEffect(()=>(l.current=!0,clearTimeout(s.current),s.current=setTimeout(i,o),()=>{n&&i()}),[n,e])}function jl(e,t=300){const[n,o]=c.useState(e);return c.useEffect(()=>{const l=setTimeout(()=>{o(e)},t);return()=>{clearTimeout(l)}},[e,t]),n}function Vn(e,t){const n=ke({propertyKey:"ignore",propertyOrBuilder:e,fields:t});return n?n.dataType==="reference"?!0:n.dataType==="array"?Array.isArray(n.of)?!1:n.of?.dataType==="reference":!1:null}function Hl(e){return r.jsx(f.CircleIcon,{size:e})}function jt(e,t){const n=e?.Icon??f.CircleIcon;return r.jsx(n,{size:t})}function he(e,t="small",n={}){if(ve(e))return r.jsx(f.FunctionsIcon,{size:t});{const o=sr(e,n);return jt(o,t)}}function Jl(e,t){return ve(e)?"#888":sr(e,t)?.color??"#666"}function tt(e,t){if(typeof e=="object"){if(t in e)return e[t];if(t.includes(".")){const n=t.split("."),o=e[n[0]];if(typeof o=="object"&&o.dataType==="map"&&o.properties)return tt(o.properties,n.slice(1).join("."))}}}function xr(e,t){if(typeof e=="object"){if(t in e)return e[t];if(t.includes(".")){const n=t.split("."),o=e[n[0]];if(o.dataType==="map"&&o.properties)return xr(o.properties,n.slice(1).join("."))}}}function ql(e){return e.replace(/\.([^.]*)/g,"[$1]")}function Gn(e,t){if(!t)return e;const n={};return t.filter(Boolean).forEach(o=>{const l=tt(e,o);typeof l=="object"&&l.dataType==="map"&&l.properties&&(n[o]={...l,properties:Gn(l.properties,l.propertiesOrder??[])}),l&&(n[o]=l)}),n}function Zl(e){return e.propertiesOrder?e.propertiesOrder:[...Object.keys(e.properties),...(e.additionalFields??[]).map(t=>t.key)]}const Ht={read:!0,edit:!0,create:!0,delete:!0};function Ct(e,t,n,o){const l=e.permissions;if(l===void 0)return Ht;if(typeof l=="object")return l;if(typeof l=="function")return l({entity:o,user:t.user,authController:t,collection:e,pathSegments:n});throw console.error("Permissions:",l),Error("New type of permission added and not mapped")}function Ir(e,t,n,o){return Ct(e,t,n,o).edit??Ht.edit}function at(e,t,n,o){return Ct(e,t,n,o).create??Ht.create}function Jt(e,t,n,o){return Ct(e,t,n,o).delete??Ht.delete}function Yn(e,t){if(e&&(e=_t(e),e in Zt))return e in Zt?r.jsx(f.Icon,{iconKey:e,size:"medium",className:t}):void 0}function qt(e,t){const n=Yn(e.icon,t);if(e?.icon&&n)return n;let o=_t(("singularName"in e?e.singularName:void 0)??e.name),l;o in Zt&&(l=o),l||(o=_t(e.path),o in Zt&&(l=o));const i=f.coolIconKeys.length;return l||(l=f.coolIconKeys[Fn(e.path)%i]),r.jsx(f.Icon,{iconKey:l,size:"medium",className:t})}const Zt=f.iconKeys.reduce((e,t)=>(e[t]=t,e),{});function Xl(e,t){if(t!==void 0&&t===1)return e;const n={"(quiz)$":"$1zes","^(ox)$":"$1en","([m|l])ouse$":"$1ice","(matr|vert|ind)ix|ex$":"$1ices","(x|ch|ss|sh)$":"$1es","([^aeiouy]|qu)y$":"$1ies","(hive)$":"$1s","(?:([^f])fe|([lr])f)$":"$1$2ves","(shea|lea|loa|thie)f$":"$1ves",sis$:"ses","([ti])um$":"$1a","(tomat|potat|ech|her|vet)o$":"$1oes","(bu)s$":"$1ses","(alias)$":"$1es","(octop)us$":"$1i","(ax|test)is$":"$1es","(us)$":"$1es","([^s]+)$":"$1s"},o={move:"moves",foot:"feet",goose:"geese",sex:"sexes",child:"children",man:"men",tooth:"teeth",person:"people"};if(["sheep","fish","deer","moose","series","species","money","rice","information","equipment","bison","cod","offspring","pike","salmon","shrimp","swine","trout","aircraft","hovercraft","spacecraft","sugar","tuna","you","wood"].indexOf(e.toLowerCase())>=0)return e;for(const i in o){const s=new RegExp(`${i}$`,"i"),a=o[i];if(s.test(e))return e.replace(s,a)}for(const i in n){const s=new RegExp(i,"i");if(s.test(e))return e.replace(s,n[i])}return e}function Kl(e,t){if(t!==void 0&&t!==1)return e;const n={"(quiz)zes$":"$1","(matr)ices$":"$1ix","(vert|ind)ices$":"$1ex","^(ox)en$":"$1","(alias)es$":"$1","(octop|vir)i$":"$1us","(cris|ax|test)es$":"$1is","(shoe)s$":"$1","(o)es$":"$1","(bus)es$":"$1","([m|l])ice$":"$1ouse","(x|ch|ss|sh)es$":"$1","(m)ovies$":"$1ovie","(s)eries$":"$1eries","([^aeiouy]|qu)ies$":"$1y","([lr])ves$":"$1f","(tive)s$":"$1","(hive)s$":"$1","(li|wi|kni)ves$":"$1fe","(shea|loa|lea|thie)ves$":"$1f","(^analy)ses$":"$1sis","((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$":"$1$2sis","([ti])a$":"$1um","(n)ews$":"$1ews","(h|bl)ouses$":"$1ouse","(corpse)s$":"$1","(us)es$":"$1",s$:""},o={move:"moves",foot:"feet",goose:"geese",sex:"sexes",child:"children",man:"men",tooth:"teeth",person:"people"};if(["sheep","fish","deer","moose","series","species","money","rice","information","equipment","bison","cod","offspring","pike","salmon","shrimp","swine","trout","aircraft","hovercraft","spacecraft","sugar","tuna","you","wood"].indexOf(e.toLowerCase())>=0)return e;for(const i in o){const s=new RegExp(`${o[i]}$`,"i");if(s.test(e))return e.replace(s,i)}for(const i in n){const s=new RegExp(i,"i");if(s.test(e))return e.replace(s,n[i])}return e}function zn(e,t,n,o=3){const l=Object.keys(e.properties);let i=n?.filter(s=>l.includes(s));return i&&i.length>0?i:(i=l,i.filter(s=>{const a=e.properties[s];return a&&!ve(a)&&!Vn(a,t)}).slice(0,o))}function Sr(e,t=""){return e&&Object.keys(e).reduce((n,o)=>{const l=t?`${t}.${o}`:o;return typeof e[o]=="object"&&e[o]!==null?Array.isArray(e[o])?e[o].forEach((i,s)=>{Object.assign(n,Sr(i,`${l}[${s}]`))}):Object.assign(n,Sr(e[o],l)):n[l]=e[o],n},{})}function Un(e){return e.reduce((t,n)=>(Object.entries(n).forEach(([o,l])=>{if(Array.isArray(l)&&(t[o]=Math.max(t[o]||0,l.length)),typeof l=="object"&&l!==null){const i=Un([l]);Object.entries(i).forEach(([s,a])=>{const A=`${o}.${s}`;t[A]=Math.max(t[A]||0,a)})}}),t),{})}function Ln(e){return Object.keys(e).forEach(t=>{const n=e[t];n.editable=!0,n.dataType==="map"&&n.properties&&Ln(n.properties)}),e}function $n(e){return Object.entries(e).reduce((t,[n,o])=>{if(!ve(o)&&o.dataType==="map"&&o.properties){const l={...o,properties:$n(o.properties)};t[n]=l}return ve(o)?t[n]=o:t[n]={...o,editable:!1},t},{})}function Fr(e,t,n){if(e){const l=e({collection:t,parentPaths:n})??t;return l.subcollections&&(l.subcollections=l.subcollections.map(i=>Fr(e,i,[...n,t.path]))),l}else return t}function _n(e,t,n=[],o){const l=(t??[]).map(s=>{const a=e?.find(A=>A.id===s.id);return a?Wn(a,s,n,o):Fr(o,s,n)}),i=e.filter(s=>!l.map(a=>a.id).includes(s.id)).map(s=>o?Fr(o,s,n):s);return[...l,...i]}function Wn(e,t,n=[],o){const l=_n(e?.subcollections??[],t?.subcollections??[],[...n,e.path],o),i={...e.properties};Object.keys(t.properties).forEach(h=>{const u=e.properties[h];u?i[h]=jn(u,t.properties[h]):i[h]=t.properties[h]});const s=Fe(e,t),a=Hn(e),A=Hn(t),d=[...new Set([...A,...a])],g=[...new Set([...e.entityViews??[],...t.entityViews??[]])];let p={...s,subcollections:l,properties:Er(i,d),propertiesOrder:d,entityViews:g};if(o){const h=o({collection:p,parentPaths:n});h&&(p=h)}return p}function jn(e,t){if(ve(t))return t;{const n=Fe(e,t),o=!!e.editable,l=!!t.editable;if(t.dataType==="map"&&t.properties){const i="properties"in e?e.properties:{},s="properties"in t?t.properties:{},a="propertiesOrder"in e&&e.propertiesOrder?e.propertiesOrder:Object.keys(i),A="propertiesOrder"in t&&t.propertiesOrder?t.propertiesOrder:"properties"in t?Object.keys(t.properties):[],d=[...new Set([...a,...A])],g={...i};return Object.keys(t.properties).forEach(p=>{const h=i[p];h&&(g[p]=jn(h,s[p]))}),{...n,editable:o&&l,properties:g,propertiesOrder:d}}return{...n,editable:o&&l}}}function Hn(e){if(e.propertiesOrder&&e.propertiesOrder.length>0){const t=e.propertiesOrder;return e.additionalFields&&e.additionalFields.forEach(n=>{t.includes(n.key)||t.push(n.key)}),t}return[...Object.keys(e.properties),...(e.additionalFields??[])?.map(t=>t.key)]}function Rl(e){return e}function ei(e){return e}function ti(e){return e}function ri(e){return e}function ni(e){return e}function oi(e){return e}function li(e){return e}function ii(e){return e}function si(e){return e}const ai="100vw",ci="55vw",Jn="768px",qn=c.createContext({}),Qe=()=>c.useContext(qn),Zn=c.createContext({}),ie=()=>c.useContext(Zn),We=()=>c.useContext(dr),Xn=c.createContext({}),Et=()=>c.useContext(Xn),Kn=c.createContext({}),je=()=>c.useContext(Kn),Rn=c.createContext({}),ct=()=>c.useContext(Rn),He=()=>{const{enqueueSnackbar:e,closeSnackbar:t}=yn.useSnackbar(),n=c.useCallback(l=>{const{type:i,message:s,autoHideDuration:a}=l;e({message:s,variant:i,autoHideDuration:a})},[]),o=c.useCallback(()=>{t()},[]);return c.useMemo(()=>({open:n,close:o}),[n,o])},eo=c.createContext(void 0),At=()=>c.useContext(eo),Ai=c.createContext({}),di=()=>c.useContext(Ai),Nr=c.createContext({}),X=()=>{const e=c.useContext(Nr),t=We(),n=Et(),o=je(),l=ie(),i=Qe(),s=ct(),a=He(),A=At(),d=di();return{...e,authController:t,sideDialogsController:n,sideEntityController:o,navigation:l,dataSource:i,storageSource:s,snackbarController:a,userConfigPersistence:A,dialogsController:d}};function to({path:e,collection:t,filterValues:n,sortBy:o,itemCount:l,searchString:i}){const s=Qe(),A=ie().resolveAliasesFrom(e),d=o?o[0]:void 0,g=o?o[1]:void 0,p=X(),[h,u]=c.useState([]),[m,b]=c.useState(!1),[y,w]=c.useState(),[C,E]=c.useState(!1);return c.useEffect(()=>{b(!0);const k=async x=>{if(t.callbacks?.onFetch)try{x=await Promise.all(x.map(B=>t.callbacks.onFetch({collection:t,path:A,entity:B,context:p})))}catch(B){console.error(B)}b(!1),w(void 0),u(x.map(B=>({...B}))),E(!l||x.length<l)},I=x=>{console.error("ERROR",x),b(!1),u([]),w(x)};return s.listenCollection?s.listenCollection({path:A,collection:t,onUpdate:k,onError:I,searchString:i,filter:n,limit:l,startAfter:void 0,orderBy:d,order:g}):(s.fetchCollection({path:A,collection:t,searchString:i,filter:n,limit:l,startAfter:void 0,orderBy:d,order:g}).then(k).catch(I),()=>{})},[A,l,g,d,n,i]),{data:h,dataLoading:m,dataLoadingError:y,noMoreToLoad:C}}const Qr={};function Tr({path:e,entityId:t,collection:n,useCache:o=!1}){const l=Qe(),s=ie().resolveAliasesFrom(e),a=X(),[A,d]=c.useState(),[g,p]=c.useState(!0),[h,u]=c.useState();return c.useEffect(()=>{p(!0);const m=async y=>{if(n.callbacks?.onFetch&&y)try{y=await n.callbacks.onFetch({collection:n,path:s,entity:y,context:a})}catch(w){console.error(w)}Qr[`${s}/${t}`]=y,d(y),p(!1),u(void 0)},b=y=>{console.error("ERROR fetching entity",y),p(!1),d(void 0),u(y)};return t&&o&&Qr[`${s}/${t}`]?(d(Qr[`${s}/${t}`]),p(!1),u(void 0),()=>{}):t&&s&&n?l.listenEntity?l.listenEntity({path:s,entityId:t,collection:n,onUpdate:m,onError:b}):(l.fetchEntity({path:s,entityId:t,collection:n}).then(m).catch(b),()=>{}):(m(void 0),()=>{})},[t,s]),{entity:A,dataLoading:g,dataLoadingError:h}}async function Mr({collection:e,path:t,entityId:n,values:o,previousValues:l,status:i,dataSource:s,context:a,onSaveSuccess:A,onSaveFailure:d,onPreSaveHookError:g,onSaveSuccessHookError:p}){let h;const u=a.navigation.resolveAliasesFrom(t),m=e.callbacks;if(m?.onPreSave)try{const b=Be({collection:e,path:t,values:l,entityId:n,fields:a.propertyConfigs});h=await m.onPreSave({collection:b,path:t,resolvedPath:u,entityId:n,values:o,previousValues:l,status:i,context:a})}catch(b){console.error(b),g&&g(b);return}else h=o;return s.saveEntity({collection:e,path:u,entityId:n,values:h,previousValues:l,status:i}).then(b=>{try{if(m?.onSaveSuccess){const y=Be({collection:e,path:t,values:h,entityId:n,fields:a.propertyConfigs});m.onSaveSuccess({collection:y,path:t,resolvedPath:u,entityId:b.id,values:h,previousValues:l,status:i,context:a})}}catch(y){p&&p(y)}A&&A(b)}).catch(b=>{if(m?.onSaveFailure){const y=Be({collection:e,path:t,values:h,entityId:n,fields:a.propertyConfigs});m.onSaveFailure({collection:y,path:t,resolvedPath:u,entityId:n,values:h,previousValues:l,status:i,context:a})}d&&d(b)})}async function ro({dataSource:e,entity:t,collection:n,callbacks:o,onDeleteSuccess:l,onDeleteFailure:i,onPreDeleteHookError:s,onDeleteSuccessHookError:a,context:A}){console.debug("Deleting entity",t.path,t.id);const d={entity:t,collection:n,entityId:t.id,path:t.path,context:A};if(o?.onPreDelete)try{await o.onPreDelete(d)}catch(g){return console.error(g),s&&s(t,g),!1}return e.deleteEntity({entity:t}).then(()=>{l&&l(t);try{return o?.onDelete&&o.onDelete(d),!0}catch(g){return a&&a(t,g),!1}}).catch(g=>(i&&i(t,g),!1))}function xe({property:e,value:t,setValue:n}){const o=c.useRef(null);c.useEffect(()=>{typeof e.disabled=="object"&&!!e.disabled.clearOnDisabled?t!=null&&(o.current=t,n(null)):o.current&&(n(o.current),o.current=null)},[e])}function no({path:e,context:t}){const n=t.dataSource,o=t.navigation;if(!o)throw Error("Calling getNavigationFrom, but main navigation has not yet been initialised");const i=Cr({path:e,collections:o.collections??[]}).map(s=>{if(s.type==="collection")return Promise.resolve(s);if(s.type==="entity"){const a=o.getCollection(s.path,s.entityId);if(!a)throw Error(`No collection defined in the navigation for the entity with path ${s.path}`);return n.fetchEntity({path:s.path,entityId:s.entityId,collection:a}).then(A=>{if(A)return{...s,entity:A}})}else{if(s.type==="custom_view")return Promise.resolve(s);throw Error("Unmapped element in useEntitiesFromPath")}}).filter(s=>!!s);return Promise.all(i)}function fi({path:e}){const t=X(),[n,o]=c.useState(),[l,i]=c.useState(!1),[s,a]=c.useState();return c.useEffect(()=>{t.navigation&&(i(!0),a(void 0),no({path:e,context:t}).then(d=>{o(d)}).catch(d=>a(d)).finally(()=>i(!1)))},[e,t]),t.navigation?{data:n,dataLoading:l,dataLoadingError:s}:{dataLoading:!0}}const Pr=()=>c.useContext(Dt),oo=e=>{const{onSuccess:t,onError:n,disableClipboardAPI:o=!1,copiedDuration:l}=e||{},i=c.useRef(null),[s,a]=c.useState(!1),[A,d]=c.useState("");c.useEffect(()=>{l&&setTimeout(()=>a(!1),l)},[s]);const g=()=>navigator.clipboard!==void 0,p=c.useCallback(C=>{if(n)n(C);else throw new Error(C)},[n]),h=c.useCallback(C=>{t&&t(C),a(!0),d(C)},[t]),u=c.useCallback(C=>{navigator.clipboard.writeText(C).then(()=>h(C)).catch(E=>{p(E),a(!1)})},[p,h]),m=()=>{g()&&navigator.clipboard.writeText("")},b=C=>w("copy",typeof C=="object"?void 0:C),y=()=>w("cut"),w=c.useCallback((C="copy",E)=>{const k=i.current,I=k&&(k.tagName==="INPUT"||k.tagName==="TEXTAREA"),x=i.current;g()&&!o&&(E?u(E):k?I?(u(x.value),C==="cut"&&(x.value="")):u(k.innerText):p("Both the ref & text were undefined"))},[o,u,p]);return{ref:i,isCoppied:s,clipboard:A,clearClipboard:m,isSupported:g,copy:b,cut:y}},ui={xs:0,sm:640,md:768,lg:1024,xl:1280,"2xl":1536,"3xl":1920},Te=(e="lg")=>{const[t,n]=c.useState(!1);return c.useEffect(()=>{const o=()=>{const l=window.matchMedia(`(min-width: ${ui[e]+1}px)`).matches;n(l)};return o(),window.addEventListener("resize",o),()=>{window.removeEventListener("resize",o)}},[]),t};function lo(e){return r.jsx(f.Tooltip,{...e,tooltipClassName:"!text-red-500 bg-red-50",children:e.children})}function pe({title:e,error:t,tooltip:n}){const o=t instanceof Error?t.message:t;console.log("ErrorView",t);const l=r.jsxs("div",{className:"flex items-center m-2",children:[r.jsx(f.ErrorIcon,{size:"small",color:"error"}),r.jsxs("div",{className:"pl-2",children:[e&&r.jsx(f.Typography,{variant:"body2",className:"font-medium",children:e}),r.jsx(f.Typography,{variant:"body2",children:o})]})]});return n?r.jsx(lo,{title:n,children:l}):l}function dt(){return r.jsx("div",{className:"rounded-full bg-gray-200 bg-opacity-30 dark:bg-opacity-20 w-5 h-2 inline-block"})}const gi=40,hi=100,pi=200;function ft(e){if(e==="tiny")return gi;if(e==="small")return hi;if(e==="medium")return pi;throw Error("Thumbnail size not mapped")}function Je(e){switch(e){case"xs":case"s":return"tiny";case"m":return"small";case"l":case"xl":return"medium";default:throw Error("Missing mapping value in getPreviewSizeFrom: "+e)}}function io({size:e,url:t}){const[n,o]=c.useState(!1),l=c.useMemo(()=>ft(e),[e]);if(e==="tiny")return r.jsx("img",{src:t,className:"rounded-md",style:{position:"relative",objectFit:"cover",width:l,height:l,maxHeight:"100%"}},"tiny_image_preview_"+t);const i={maxWidth:"100%",maxHeight:"100%"};return r.jsxs("div",{className:"relative flex items-center justify-center max-w-full max-h-full",style:{width:l,height:l},onMouseEnter:()=>o(!0),onMouseMove:()=>o(!0),onMouseLeave:()=>o(!1),children:[r.jsx("img",{src:t,className:"rounded-md",style:i}),n&&r.jsxs(r.Fragment,{children:[navigator&&r.jsx(f.Tooltip,{title:"Copy url to clipboard",children:r.jsx("div",{className:"rounded-full absolute bottom-[-4px] right-8",children:r.jsx(f.IconButton,{variant:"filled",size:"small",onClick:s=>(s.stopPropagation(),s.preventDefault(),navigator.clipboard.writeText(t)),children:r.jsx(f.ContentCopyIcon,{className:"text-gray-500",size:"small"})})})}),r.jsx(f.Tooltip,{title:"Open image in new tab",children:r.jsx(f.IconButton,{variant:"filled",component:"a",style:{position:"absolute",bottom:-4,right:-4},href:t,rel:"noopener noreferrer",target:"_blank",size:"small",onClick:s=>s.stopPropagation(),children:r.jsx(f.OpenInNewIcon,{className:"text-gray-500",size:"small"})})})]})]},"image_preview_"+t)}function Bt({url:e,previewType:t,size:n,hint:o}){return t?t==="image"?r.jsx(io,{url:e,size:n}):t==="audio"?r.jsxs("audio",{controls:!0,src:e,children:["Your browser does not support the",r.jsx("code",{children:"audio"})," element."]}):t==="video"?r.jsx("video",{className:`max-w-${n==="small"?"sm":"md"}`,controls:!0,children:r.jsx("source",{src:e})}):r.jsxs("a",{href:e,rel:"noopener noreferrer",target:"_blank",onClick:l=>l.stopPropagation(),className:"flex flex-col items-center justify-center",style:{width:ft(n),height:ft(n)},children:[r.jsx(f.DescriptionIcon,{className:"flex-grow"}),o&&r.jsx(f.Tooltip,{title:o,children:r.jsx(f.Typography,{className:"max-w-full truncate rtl text-left",variant:"caption",children:o})})]}):!e||!e.trim()?r.jsx(dt,{}):r.jsxs("a",{className:"flex gap-4 break-words items-center font-medium text-primary visited:text-primary dark:visited:text-primary dark:text-primary",href:e,rel:"noopener noreferrer",onMouseDown:l=>{l.preventDefault()},target:"_blank",children:[r.jsx(f.OpenInNewIcon,{size:"small"}),e]})}function ut({property:e,size:t}){e||console.error("No property assigned for skeleton component",e,t);let n;if(e.dataType==="string"){const o=e;o.url?n=Ci(o,t):o.storage?n=Or(t):n=Ve()}else if(e.dataType==="array"){const o=e;o.of&&(Array.isArray(o.of)?n=r.jsxs(r.Fragment,{children:[o.of.map((l,i)=>Dr(l,i))," "]}):o.of.dataType==="map"&&o.of.properties?n=bi(o.of.properties,t,o.of.previewProperties):o.of.dataType==="string"?o.of.enumValues?n=vi():o.of.storage?n=Dr(o.of):n=yi():n=Dr(o.of))}else e.dataType==="map"?n=mi(e,t):e.dataType==="date"?n=Ve():e.dataType==="reference"?n=wi():(e.dataType,n=Ve());return n||null}function mi(e,t){if(!e.properties)return r.jsx(r.Fragment,{});let n;return t==="medium"?n=Object.keys(e.properties):(n=e.previewProperties||Object.keys(e.properties),t==="small"?n=n.slice(0,3):t==="tiny"&&(n=n.slice(0,1))),t!=="medium"?r.jsx("div",{className:"w-full flex flex-col space-y-4",children:n.map((o,l)=>r.jsx("div",{children:e.properties&&e.properties[o]&&r.jsx(ut,{property:e.properties[o],size:"small"})},`map_${o}`))}):r.jsx("table",{className:"table-auto",children:r.jsx("tbody",{children:n&&n.map((o,l)=>r.jsxs("tr",{className:"border-b last:border-b-0",children:[r.jsx("th",{className:"align-top",style:{width:"30%"},children:r.jsx("p",{className:"text-xs text-secondary",children:e.properties[o].name})},`table-cell-title--${o}`),r.jsx("th",{style:{width:"70%"},children:e.properties&&e.properties[o]&&r.jsx(ut,{property:e.properties[o],size:"small"})},`table-cell-${o}`)]},`map_preview_table__${l}`))})})}function bi(e,t,n){let o=n;return(!o||!o.length)&&(o=Object.keys(e),t&&(o=o.slice(0,3))),r.jsx("table",{className:"table-auto",children:r.jsx("tbody",{children:[0,1,2].map((l,i)=>r.jsx("tr",{children:o&&o.map(s=>r.jsx("th",{children:r.jsx(ut,{property:e[s],size:"small"})},`table-cell-${s}`))},`table_${l}_${i}`))})})}function yi(){return r.jsx("div",{className:"flex flex-col gap-2",children:[0,1].map((e,t)=>Ve(t))})}function vi(){return r.jsx("div",{className:"flex flex-col gap-2",children:[0,1].map((e,t)=>r.jsx(r.Fragment,{children:Ve(t)}))})}function Dr(e,t=0){return r.jsx("div",{className:"flex flex-col gap-2",children:[0,1].map((n,o)=>r.jsx(r.Fragment,{children:r.jsx(ut,{property:e,size:"small"},`i_${o}`)}))},"array_index_"+t)}function Or(e){const t=e==="tiny"?40:e==="small"?100:200;return r.jsx(f.Skeleton,{width:t,height:t})}function wi(){return r.jsx(f.Skeleton,{width:200,height:100})}function Ci(e,t="medium"){return typeof e.url=="boolean"?r.jsxs("div",{style:{display:"flex"},children:[Vr(),Ve()]}):Ei(t)}function Ei(e){return r.jsx("div",{className:`w-${ft(e)} h-${ft(e)}`,children:Vr()})}function Ve(e,t=120){return r.jsx(f.Skeleton,{width:t},`skeleton_${e}`)}function Bi(e){return r.jsx(f.Skeleton,{height:20})}function Vr(){return r.jsx(f.Skeleton,{width:24,height:24})}const so=c.memo(co,ki);function ki(e,t){return e.size===t.size&&e.storagePathOrDownloadUrl===t.storagePathOrDownloadUrl&&e.storeUrl===t.storeUrl}const ao={};function co({storeUrl:e,storagePathOrDownloadUrl:t,size:n}){const[o,l]=c.useState(void 0),i=ct(),[s,a]=c.useState(ao[t]);if(c.useEffect(()=>{if(!t)return;let g=!1;return i.getDownloadURL(t).then(function(p){g||(a(p),ao[t]=p)}).catch(l),()=>{g=!0}},[t]),!t)return null;const A=s?.metadata?xi(s?.metadata.contentType):void 0,d=A?.startsWith("image")?"image":A?.startsWith("video")?"video":A?.startsWith("audio")?"audio":"file";return s?.fileNotFound?r.jsx(pe,{error:"File not found"}):s?.url?r.jsx(Bt,{previewType:d,url:s.url,size:n,hint:t}):Or(n)}function xi(e){return e.startsWith("image")?"image/*":e.startsWith("video")?"video/*":e.startsWith("audio")?"audio/*":e.startsWith("application")?"application/*":e.startsWith("text")?"text/*":e.startsWith("font")?"font/*":e}function we({enumValues:e,enumKey:t,size:n,className:o,children:l}){if(!e)return null;const i=$e(e),s=t!==void 0?$t(i,t):void 0,a=Tn(s),A=Qn(i,t);return r.jsxs(f.Chip,{className:o,colorScheme:A,error:!a,outlined:!1,size:n,children:[l,!l&&(a!==void 0?a:String(t))]})}function Gr({propertyKey:e,value:t,property:n,size:o}){if(n.enumValues){const l=t,i=vr(n);return r.jsx(we,{enumKey:l,enumValues:i.enumValues,size:o!=="medium"?"small":"medium"})}else if(n.previewAsTag){const l=Nn(e??"");return r.jsx(ne,{children:r.jsx(f.Chip,{colorScheme:l,size:o!=="medium"?"small":"medium",children:t})})}else{if(n.url)return r.jsx(Bt,{size:o,url:t,previewType:typeof n.url=="string"?n.url:void 0});{if(!t)return r.jsx(r.Fragment,{});const l=t.split(`
|
|
2
2
|
`);return t&&t.includes(`
|
|
3
|
-
`)?r.jsx("div",{className:"overflow-x-scroll",children:l.map((i,s)=>r.jsxs(c.Fragment,{children:[r.jsx("span",{children:i}),s!==l.length-1&&r.jsx("br",{})]},`string_preview_${s}`))}):r.jsx(r.Fragment,{children:t})}}}function Yr({propertyKey:e,value:t,property:n,entity:o,size:l}){const i=X(),s=_e({propertyKey:e,property:n,propertyValue:t,fields:i.propertyConfigs});if(!s.of)throw Error(`You need to specify an 'of' prop (or specify a custom field) in your array property ${e}`);if(s.dataType!=="array")throw Error("Picked wrong preview component ArrayPreview");const a=t;if(!a)return null;const A=l==="medium"?"small":"tiny";return r.jsx("div",{className:"flex flex-col gap-2",children:a&&a.map((d,g)=>{const p=s.resolvedProperties[g]??s.resolvedProperties[g]??(Array.isArray(s.of)?s.of[g]:s.of);return p?r.jsx(c.Fragment,{children:r.jsx("div",{className:f.cn(f.defaultBorderMixin,"m-1 border-b last:border-b-0"),children:r.jsx(ne,{children:r.jsx(me,{propertyKey:e,entity:o,value:d,property:p,size:A})})})},"preview_array_"+g):null})})}const Ge=Ar.memo(function(t){const n=t.reference;return n instanceof Pe?r.jsx(Si,{...t}):(console.warn("Reference preview received value of type",typeof n),r.jsx(Xt,{onClick:t.onClick,size:t.size,children:r.jsx(pe,{error:"Unexpected value. Click to edit",tooltip:JSON.stringify(n)})}))},Ii);function Ii(e,t){return e.disabled===t.disabled&&e.size===t.size&&e.onHover===t.onHover&&e.reference?.id===t.reference?.id&&e.reference?.path===t.reference?.path&&e.allowEntityNavigation===t.allowEntityNavigation}function Si({disabled:e,reference:t,previewProperties:n,size:o,onHover:l,onClick:i,allowEntityNavigation:s=!0}){const a=X(),d=ie().getCollection(t.path);if(!d){if(a.components?.missingReference)return r.jsx(a.components.missingReference,{path:t.path});throw Error(`Couldn't find the corresponding collection view for the path: ${t.path}`)}return r.jsx(Fi,{reference:t,collection:d,previewProperties:n,size:o,disabled:e,allowEntityNavigation:s,onClick:i,onHover:l})}function Fi({reference:e,collection:t,previewProperties:n,size:o,disabled:l,allowEntityNavigation:i,onClick:s,onHover:a}){const A=X(),d=je(),{entity:g,dataLoading:p,dataLoadingError:h}=Tr({path:e.path,entityId:e.id,collection:t,useCache:!0});g&&Ao.set(e.pathWithId,g);const u=g??Ao.get(e.pathWithId),m=c.useMemo(()=>Be({collection:t,path:e.path,values:u?.values,fields:A.propertyConfigs}),[t]),b=c.useMemo(()=>zn(m,A.propertyConfigs,n,o==="small"||o==="medium"?3:1),[n,m,o]);let y;return m?(e?u&&!u.values?y=r.jsx(pe,{error:"Reference does not exist",tooltip:e.path}):y=r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"flex flex-col flex-grow w-full max-w-[calc(100%-52px)] m-1",children:[o!=="tiny"&&(e?r.jsx("div",{className:`${o!=="medium"?"block whitespace-nowrap overflow-hidden truncate":""}`,children:r.jsx(f.Typography,{variant:"caption",className:"font-mono",children:e.id})}):r.jsx(f.Skeleton,{})),b&&b.map(w=>{const C=m.properties[w];return C?r.jsx("div",{className:b.length>1?"my-0.5":"my-0",children:u?r.jsx(me,{propertyKey:w,value:Le(u.values,w),property:C,entity:u,size:"tiny"}):r.jsx(ut,{property:C,size:"tiny"})},"ref_prev_"+w):null})]}),r.jsx("div",{className:`my-${o==="tiny"?2:4}`,children:!l&&u&&i&&r.jsx(f.Tooltip,{title:`See details for ${u.id}`,children:r.jsx(f.IconButton,{color:"inherit",size:"small",onClick:w=>{w.stopPropagation(),A.onAnalyticsEvent?.("entity_click_from_reference",{path:u.path,entityId:u.id}),d.open({entityId:u.id,path:u.path,collection:m,updateUrl:!0})},children:r.jsx(f.KeyboardTabIcon,{size:"small"})})})})]}):y=r.jsx(pe,{error:"Reference not set"}),r.jsx(Xt,{onClick:l?void 0:s,onHover:l?void 0:a,size:o,children:y})):r.jsx(pe,{error:"Could not find collection with id "+m})}function Xt({children:e,onHover:t,size:n,onClick:o}){return r.jsx(f.Typography,{variant:"label",className:f.cn("bg-opacity-70 bg-gray-100 dark:bg-gray-800 dark:bg-opacity-60","w-full","flex","rounded-md","overflow-hidden",t?"hover:bg-opacity-90 dark:hover:bg-opacity-90":"",n==="medium"?"p-2":"p-1",n==="tiny"?"items-center":"","transition-colors duration-300 ease-in-out ",o?"cursor-pointer":""),style:{tabindex:0},onClick:l=>{o&&(l.preventDefault(),o(l))},children:e})}const Ao=new Map;function fo({propertyKey:e,value:t,property:n,size:o}){const l=X(),i=_e({propertyKey:e,property:n,propertyValue:t,fields:l.propertyConfigs});if(Array.isArray(i?.of))throw Error("Using array properties instead of single one in `of` in ArrayProperty");if(i?.dataType!=="array"||!i.of||i.of.dataType!=="reference")throw Error("Picked wrong preview component ArrayOfReferencesPreview");const s=o==="medium"?"small":"tiny";return r.jsx("div",{className:"flex flex-col w-full",children:t&&t.map((a,A)=>{const d=i.of;return r.jsx("div",{className:"mt-1 mb-1 w-full",children:r.jsx(Ge,{disabled:!d.path,previewProperties:d.previewProperties,size:s,reference:a})},`preview_array_ref_${e}_${A}`)})})}function uo({propertyKey:e,entity:t,value:n,property:o,size:l}){const i=X(),s=_e({propertyKey:e,property:o,propertyValue:n,fields:i.propertyConfigs});if(Array.isArray(s.of))throw Error("Using array properties instead of single one in `of` in ArrayProperty");if(s.dataType!=="array"||!s.of||s.of.dataType!=="string")throw Error("Picked wrong preview component ArrayOfStorageComponentsPreview");const a=l==="medium"?"small":"tiny";return r.jsx("div",{className:"flex flex-wrap gap-2",children:n&&n.map((A,d)=>r.jsx(ne,{children:r.jsx(me,{propertyKey:e,value:A,entity:t,property:s.of,size:a})},`preview_array_storage_${e}_${d}`))})}function zr({name:e,value:t,enumValues:n,size:o}){return r.jsx("div",{className:"flex flex-wrap gap-1.5",children:t&&t.map((l,i)=>r.jsx(ne,{children:r.jsx(we,{enumKey:l,enumValues:n,size:o!=="medium"?"small":"medium"})},`preview_array_ref_${e}_${i}`))})}function Ur({propertyKey:e,value:t,property:n,size:o}){if(n.dataType!=="array")throw Error("Picked wrong preview component ArrayEnumPreview");const l=n.of;if(!l.enumValues)throw Error("Picked wrong preview component ArrayEnumPreview");return t?r.jsx(zr,{name:e,value:t,enumValues:l.enumValues,size:o}):null}function go({propertyKey:e,value:t,property:n,entity:o,size:l}){const i=X(),s=_e({propertyKey:e,property:n,propertyValue:t,fields:i.propertyConfigs});if(Array.isArray(s.of))throw Error("Using array properties instead of single one in `of` in ArrayProperty");if(!s.of||s.dataType!=="array"||s.of.dataType!=="string")throw Error("Picked wrong preview component ArrayOfStringsPreview");if(t&&!Array.isArray(t))return r.jsx("div",{children:`Unexpected value: ${t}`});const a=s.of;return r.jsx("div",{className:"flex flex-col gap-2",children:t&&t.map((A,d)=>r.jsx("div",{children:r.jsx(ne,{children:r.jsx(Gr,{propertyKey:e,property:a,value:A,entity:o,size:l})})},`preview_array_strings_${e}_${d}`))})}function ho({propertyKey:e,value:t,property:n,size:o,entity:l}){const i=X(),s=_e({propertyKey:e,property:n,propertyValue:t,fields:i.propertyConfigs});if(s?.dataType!=="array")throw Error("Picked wrong preview component ArrayPreview");if(!s?.oneOf)throw Error(`You need to specify an 'of' or 'oneOf' prop (or specify a custom field) in your array property ${e}`);const a=t;if(!a)return null;const A=o==="medium"?"small":"tiny",d=s.oneOf.typeField??yt,g=s.oneOf.valueField??zt,p=s.oneOf.properties;return r.jsx("div",{className:"flex flex-col",children:a&&a.map((h,u)=>r.jsx(c.Fragment,{children:r.jsx("div",{className:f.cn(f.defaultBorderMixin,"m-1 border-b last:border-b-0"),children:r.jsx(ne,{children:h&&r.jsx(me,{propertyKey:e,value:h[g],entity:l,property:s.resolvedProperties[u]??p[h[d]],size:A})})})},"preview_array_"+h+"_"+u))})}function po({propertyKey:e,value:t,property:n,entity:o,size:l}){if(n.dataType!=="map")throw Error("Picked wrong preview component MapPropertyPreview");const i=n;if(!i.properties||Object.keys(i.properties??{}).length===0)return r.jsx(Lr,{value:t});if(!t)return null;const s=Object.keys(i.properties);return l==="tiny"?r.jsx("div",{className:"w-full flex flex-col space-y-1 md:space-y-2",children:s.map((a,A)=>r.jsx("div",{children:r.jsx(ne,{children:r.jsx(me,{propertyKey:a,value:t[a],property:i.properties[a],entity:o,size:l})},"map_preview_"+i.name+a+A)},`map_${a}`))}):r.jsx("div",{className:"flex flex-col gap-1 w-full",children:s&&s.map((a,A)=>{const d=i.properties[a];return r.jsxs("div",{className:f.cn(f.defaultBorderMixin,"last:border-b-0 border-b"),children:[r.jsxs("div",{className:"flex flex-row pt-0.5 pb-0.5 gap-2",children:[r.jsx("div",{className:"min-w-[140px] w-[25%] py-1",children:r.jsx(f.Typography,{variant:"caption",className:"font-mono break-words",color:"secondary",children:d.name})}),r.jsx("div",{className:"flex-grow max-w-[75%]",children:r.jsx(ne,{children:!(d.dataType==="map"||d==="array")&&r.jsx(me,{propertyKey:a,value:t[a],property:d,entity:o,size:l})})})]}),(d.dataType==="map"||d==="array")&&r.jsx("div",{className:f.cn(f.defaultBorderMixin,"border-l pl-4 ml-2 my-2"),children:r.jsx(me,{propertyKey:a,value:t[a],property:d,entity:o,size:l})})]},`map_preview_table_${a}}`)})})}function Lr({value:e}){return typeof e!="object"?null:r.jsx("div",{className:"flex flex-col gap-1 w-full",children:Object.entries(e).map(([t,n])=>r.jsxs("div",{className:f.cn(f.defaultBorderMixin,"last:border-b-0 border-b"),children:[r.jsxs("div",{className:"flex flex-row pt-0.5 pb-0.5 gap-2",children:[r.jsx("div",{className:"min-w-[140px] w-[25%] py-1",children:r.jsx(f.Typography,{variant:"caption",className:"font-mono break-words",color:"secondary",children:t})},`table-cell-title-${t}-${t}`),r.jsx("div",{className:"flex-grow max-w-[75%]",children:typeof n!="object"&&r.jsx(f.Typography,{children:r.jsx(ne,{children:n&&n.toString()})})})]}),typeof n=="object"&&r.jsx("div",{className:f.cn(f.defaultBorderMixin,"border-l pl-4"),children:r.jsx(Lr,{value:n})})]},`map_preview_table_${t}}`))})}function mo({date:e}){const t=X(),n=t?.locale?En[t?.locale]:void 0,o=t?.dateTimeFormat??Mn,l=e?yl(e,o,{locale:n}):"";return r.jsx(r.Fragment,{children:l})}function bo({value:e}){return r.jsx(f.Checkbox,{checked:e})}function yo({value:e,property:t,size:n}){if(t.enumValues){const o=e,l=$e(t.enumValues);return l?r.jsx(we,{enumKey:o,enumValues:l,size:n!=="medium"?"small":"medium"}):r.jsx(r.Fragment,{children:e})}else return r.jsx(r.Fragment,{children:e})}function me(e){const t=X();let n;const{property:o,propertyKey:l,value:i,size:s,height:a,width:A,entity:d}=e,g=ke({propertyKey:l,propertyOrBuilder:o,propertyValue:i,fields:t.propertyConfigs});if(i===void 0||g===null)n=r.jsx(dt,{});else if(g.Preview)n=c.createElement(g.Preview,{propertyKey:l,value:i,property:g,size:s,height:a,width:A,entity:d,customProps:g.customProps});else if(i===null)n=r.jsx(dt,{});else if(g.dataType==="string"){const p=g;typeof i=="string"?p.url?typeof p.url=="boolean"?n=r.jsx(Bt,{size:e.size,url:i}):typeof p.url=="string"&&(n=r.jsx(Bt,{size:e.size,url:i,previewType:p.url})):p.storage?n=r.jsx(so,{storeUrl:g.storage?.storeUrl??!1,size:e.size,storagePathOrDownloadUrl:i}):p.markdown?n=r.jsx(f.Markdown,{source:i}):n=r.jsx(Gr,{...e,property:p,value:i}):n=rt(l,g.dataType,i)}else if(g.dataType==="array")if(i instanceof Array){const p=g;if(!p.of&&!p.oneOf)throw Error(`You need to specify an 'of' or 'oneOf' prop (or specify a custom field) in your array property ${l}`);p.of?Array.isArray(p.of)?n=r.jsx(Yr,{...e,value:i,property:g}):p.of.dataType==="reference"?n=r.jsx(fo,{...e,value:i,property:g}):p.of.dataType==="string"?p.of.enumValues?n=r.jsx(Ur,{...e,value:i,property:g}):p.of.storage?n=r.jsx(uo,{...e,value:i,property:g}):n=r.jsx(go,{...e,value:i,property:g}):p.of.dataType==="number"&&p.of.enumValues?n=r.jsx(Ur,{...e,value:i,property:g}):n=r.jsx(Yr,{...e,value:i,property:g}):p.oneOf&&(n=r.jsx(ho,{...e,value:i,property:g}))}else n=rt(l,g.dataType,i);else g.dataType==="map"?typeof i=="object"?n=r.jsx(po,{...e,property:g}):n=rt(l,g.dataType,i):g.dataType==="date"?i instanceof Date?n=r.jsx(mo,{date:i}):n=rt(l,g.dataType,i):g.dataType==="reference"?typeof g.path=="string"?i instanceof Pe?n=r.jsx(Ge,{disabled:!g.path,previewProperties:g.previewProperties,size:e.size,onClick:e.onClick,reference:i}):n=rt(l,g.dataType,i):n=r.jsx(dt,{}):g.dataType==="boolean"?typeof i=="boolean"?n=r.jsx(bo,{value:i}):n=rt(l,g.dataType,i):g.dataType==="number"?typeof i=="number"?n=r.jsx(yo,{...e,value:i,property:g}):n=rt(l,g.dataType,i):n=JSON.stringify(i);return n??r.jsx(dt,{})}function rt(e,t,n){return console.warn(`Unexpected value for property ${e}, of type ${t}`,n),r.jsx(pe,{title:"Unexpected value",error:`${JSON.stringify(n)}`})}function Ni({propertyKey:e,value:t,property:n,size:o,entity:l}){const i=X(),s=_e({propertyKey:e,property:n,propertyValue:t,fields:i.propertyConfigs});if(Array.isArray(s?.of))throw Error("Using array properties instead of single one in `of` in ArrayProperty");if(s?.dataType!=="array"||!s.of||s.of.dataType!=="map")throw Error("Picked wrong preview component ArrayOfMapsPreview");const a=s.of,A=a.properties;if(!A)throw Error(`You need to specify a 'properties' prop (or specify a custom field) in your map property ${e}`);const d=t,g=a.previewProperties;if(!d)return null;let p=g;return(!p||!p.length)&&(p=Object.keys(A),o&&(p=p.slice(0,3))),r.jsx("div",{className:"table-auto text-xs",children:r.jsx("div",{children:d&&d.map((h,u)=>r.jsx("div",{className:"border-b last:border-b-0",children:p&&p.map(m=>r.jsx("div",{className:"table-cell",children:r.jsx(ne,{children:r.jsx(me,{propertyKey:m,value:h[m],property:A[m],entity:l,size:"small"})})},`table-cell-${m}`))},`table_${h}_${u}`))})})}const Qi=Ar.memo(function({builder:t}){const[n,o]=c.useState(!0),[l,i]=c.useState(null);return c.useEffect(()=>{let s=!1;return t.then(a=>{s||(o(!1),i(a))}).catch(a=>{o(!1),console.error(a)}),()=>{s=!0}},[t]),n?r.jsx(f.Skeleton,{}):r.jsx(Ar.Fragment,{children:l})});function $r({entity:e,collection:t,path:n,className:o}){const l=X(),i=c.useMemo(()=>Be({collection:t,path:n,entityId:e.id,values:e.values,fields:l.propertyConfigs}),[t,n,e]),s=X(),a=i.properties;return r.jsx("div",{className:"w-full "+o,children:r.jsxs("div",{className:"w-full mb-4",children:[r.jsxs("div",{className:f.cn(f.defaultBorderMixin,"flex justify-between py-2 border-b last:border-b-0"),children:[r.jsx("div",{className:"flex items-center w-1/4",children:r.jsx("span",{className:"pl-2 text-sm text-gray-600",children:"Id"})}),r.jsxs("div",{className:"flex-grow p-2 ml-2 w-3/4 text-gray-900 dark:text-white min-h-[56px] flex items-center",children:[r.jsx("span",{className:"flex-grow mr-2",children:e.id}),s?.entityLinkBuilder&&r.jsx("a",{href:s.entityLinkBuilder({entity:e}),rel:"noopener noreferrer",target:"_blank",children:r.jsx(f.IconButton,{children:r.jsx(f.OpenInNewIcon,{size:"small"})})})]})]}),Object.entries(a).map(([A,d])=>{const g=e.values[A];return r.jsxs("div",{className:f.cn(f.defaultBorderMixin,"flex justify-between py-2 border-b last:border-b-0"),children:[r.jsx("div",{className:"flex items-center w-1/4",children:r.jsx("span",{className:"pl-2 text-sm text-gray-600",children:d.name})}),r.jsx("div",{className:"flex-grow p-2 ml-2 w-3/4 text-gray-900 dark:text-white min-h-[56px] flex items-center",children:r.jsx(me,{propertyKey:A,value:g,entity:e,property:d,size:"medium"})})]},`reference_previews_${A}`)})]})})}function Ti(e){return e.dataType==="boolean"?"center":e.dataType==="number"?e.enumValues?"left":"right":e.dataType==="date"?"right":"left"}function vo(e){if(e.columnWidth)return e.columnWidth;if(e.dataType==="string")return e.url?280:e.storage?160:e.enumValues?200:e.multiline||e.markdown?300:(e.email,200);if(e.dataType==="array"){const t=e;return t.of?Array.isArray(e.of)?300:vo(t.of):300}else return e.dataType==="number"?e.enumValues?200:140:e.dataType==="map"?360:e.dataType==="date"?200:e.dataType==="reference"?220:e.dataType==="boolean"?140:200}function _r(e){return`subcollection:${e.id??e.path}`}function Mi(e){const t=c.useRef(null),{disabled:n,value:o,multiline:l,updateValue:i,focused:s}=e,a=c.useRef(o),[A,d]=c.useState(o),g=c.useRef(!1);c.useEffect(()=>{a.current!==o&&o!==A&&d(o),a.current=o},[o]);const p=c.useCallback(()=>{!o&&!A||A!==o&&(a.current=A,i(A))},[A,i,o]);return Wt(A,p,!s,2e3),c.useEffect(()=>{t.current&&s&&!g.current?(g.current=!0,t.current.focus({preventScroll:!0}),t.current.selectionStart=t.current.value.length,t.current.selectionEnd=t.current.value.length):g.current=s},[s,t]),r.jsx(f.TextareaAutosize,{ref:t,style:{padding:0,margin:0,width:"100%",color:"unset",fontWeight:"unset",lineHeight:"unset",fontSize:"unset",fontFamily:"unset",background:"unset",border:"unset",resize:"none",outline:"none"},value:A??"",onChange:h=>{const u=h.target.value;(l||!u.endsWith(`
|
|
3
|
+
`)?r.jsx("div",{className:"overflow-x-scroll",children:l.map((i,s)=>r.jsxs(c.Fragment,{children:[r.jsx("span",{children:i}),s!==l.length-1&&r.jsx("br",{})]},`string_preview_${s}`))}):r.jsx(r.Fragment,{children:t})}}}function Yr({propertyKey:e,value:t,property:n,entity:o,size:l}){const i=X(),s=_e({propertyKey:e,property:n,propertyValue:t,fields:i.propertyConfigs});if(!s.of)throw Error(`You need to specify an 'of' prop (or specify a custom field) in your array property ${e}`);if(s.dataType!=="array")throw Error("Picked wrong preview component ArrayPreview");const a=t;if(!a)return null;const A=l==="medium"?"small":"tiny";return r.jsx("div",{className:"flex flex-col gap-2",children:a&&a.map((d,g)=>{const p=s.resolvedProperties[g]??s.resolvedProperties[g]??(Array.isArray(s.of)?s.of[g]:s.of);return p?r.jsx(c.Fragment,{children:r.jsx("div",{className:f.cn(f.defaultBorderMixin,"m-1 border-b last:border-b-0"),children:r.jsx(ne,{children:r.jsx(me,{propertyKey:e,entity:o,value:d,property:p,size:A})})})},"preview_array_"+g):null})})}const Ge=Ar.memo(function(t){const n=t.reference;return n instanceof Pe?r.jsx(Si,{...t}):(console.warn("Reference preview received value of type",typeof n),r.jsx(Xt,{onClick:t.onClick,size:t.size,children:r.jsx(pe,{error:"Unexpected value. Click to edit",tooltip:JSON.stringify(n)})}))},Ii);function Ii(e,t){return e.disabled===t.disabled&&e.size===t.size&&e.onHover===t.onHover&&e.reference?.id===t.reference?.id&&e.reference?.path===t.reference?.path&&e.allowEntityNavigation===t.allowEntityNavigation}function Si({disabled:e,reference:t,previewProperties:n,size:o,onHover:l,onClick:i,allowEntityNavigation:s=!0}){const a=X(),d=ie().getCollection(t.path);if(!d){if(a.components?.missingReference)return r.jsx(a.components.missingReference,{path:t.path});throw Error(`Couldn't find the corresponding collection view for the path: ${t.path}`)}return r.jsx(Fi,{reference:t,collection:d,previewProperties:n,size:o,disabled:e,allowEntityNavigation:s,onClick:i,onHover:l})}function Fi({reference:e,collection:t,previewProperties:n,size:o,disabled:l,allowEntityNavigation:i,onClick:s,onHover:a}){const A=X(),d=je(),{entity:g,dataLoading:p,dataLoadingError:h}=Tr({path:e.path,entityId:e.id,collection:t,useCache:!0});g&&Ao.set(e.pathWithId,g);const u=g??Ao.get(e.pathWithId),m=c.useMemo(()=>Be({collection:t,path:e.path,values:u?.values,fields:A.propertyConfigs}),[t]),b=c.useMemo(()=>zn(m,A.propertyConfigs,n,o==="small"||o==="medium"?3:1),[n,m,o]);let y;return m?(e?u&&!u.values?y=r.jsx(pe,{error:"Reference does not exist",tooltip:e.path}):y=r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"flex flex-col flex-grow w-full max-w-[calc(100%-52px)] m-1",children:[o!=="tiny"&&(e?r.jsx("div",{className:`${o!=="medium"?"block whitespace-nowrap overflow-hidden truncate":""}`,children:r.jsx(f.Typography,{variant:"caption",className:"font-mono",children:e.id})}):r.jsx(f.Skeleton,{})),b&&b.map(w=>{const C=m.properties[w];return C?r.jsx("div",{className:b.length>1?"my-0.5":"my-0",children:u?r.jsx(me,{propertyKey:w,value:Le(u.values,w),property:C,entity:u,size:"tiny"}):r.jsx(ut,{property:C,size:"tiny"})},"ref_prev_"+w):null})]}),r.jsx("div",{className:`my-${o==="tiny"?2:4}`,children:!l&&u&&i&&r.jsx(f.Tooltip,{title:`See details for ${u.id}`,children:r.jsx(f.IconButton,{color:"inherit",size:"small",onClick:w=>{w.stopPropagation(),A.onAnalyticsEvent?.("entity_click_from_reference",{path:u.path,entityId:u.id}),d.open({entityId:u.id,path:u.path,collection:m,updateUrl:!0})},children:r.jsx(f.KeyboardTabIcon,{size:"small"})})})})]}):y=r.jsx(pe,{error:"Reference not set"}),r.jsx(Xt,{onClick:l?void 0:s,onHover:l?void 0:a,size:o,children:y})):r.jsx(pe,{error:"Could not find collection with id "+m})}function Xt({children:e,onHover:t,size:n,onClick:o}){return r.jsx(f.Typography,{variant:"label",className:f.cn("bg-opacity-70 bg-gray-100 dark:bg-gray-800 dark:bg-opacity-60","w-full","flex","rounded-md","overflow-hidden",t?"hover:bg-opacity-90 dark:hover:bg-opacity-90":"",n==="medium"?"p-2":"p-1",n==="tiny"?"items-center":"","transition-colors duration-300 ease-in-out ",o?"cursor-pointer":""),style:{tabindex:0},onClick:l=>{o&&(l.preventDefault(),o(l))},children:e})}const Ao=new Map;function fo({propertyKey:e,value:t,property:n,size:o}){const l=X(),i=_e({propertyKey:e,property:n,propertyValue:t,fields:l.propertyConfigs});if(Array.isArray(i?.of))throw Error("Using array properties instead of single one in `of` in ArrayProperty");if(i?.dataType!=="array"||!i.of||i.of.dataType!=="reference")throw Error("Picked wrong preview component ArrayOfReferencesPreview");const s=o==="medium"?"small":"tiny";return r.jsx("div",{className:"flex flex-col w-full",children:t&&t.map((a,A)=>{const d=i.of;return r.jsx("div",{className:"mt-1 mb-1 w-full",children:r.jsx(Ge,{disabled:!d.path,previewProperties:d.previewProperties,size:s,reference:a})},`preview_array_ref_${e}_${A}`)})})}function uo({propertyKey:e,entity:t,value:n,property:o,size:l}){const i=X(),s=_e({propertyKey:e,property:o,propertyValue:n,fields:i.propertyConfigs});if(Array.isArray(s.of))throw Error("Using array properties instead of single one in `of` in ArrayProperty");if(s.dataType!=="array"||!s.of||s.of.dataType!=="string")throw Error("Picked wrong preview component ArrayOfStorageComponentsPreview");const a=l==="medium"?"small":"tiny";return r.jsx("div",{className:"flex flex-wrap gap-2",children:n&&n.map((A,d)=>r.jsx(ne,{children:r.jsx(me,{propertyKey:e,value:A,entity:t,property:s.of,size:a})},`preview_array_storage_${e}_${d}`))})}function zr({name:e,value:t,enumValues:n,size:o}){return r.jsx("div",{className:"flex flex-wrap gap-1.5",children:t&&t.map((l,i)=>r.jsx(ne,{children:r.jsx(we,{enumKey:l,enumValues:n,size:o!=="medium"?"small":"medium"})},`preview_array_ref_${e}_${i}`))})}function Ur({propertyKey:e,value:t,property:n,size:o}){if(n.dataType!=="array")throw Error("Picked wrong preview component ArrayEnumPreview");const l=n.of;if(!l.enumValues)throw Error("Picked wrong preview component ArrayEnumPreview");return t?r.jsx(zr,{name:e,value:t,enumValues:l.enumValues,size:o}):null}function go({propertyKey:e,value:t,property:n,entity:o,size:l}){const i=X(),s=_e({propertyKey:e,property:n,propertyValue:t,fields:i.propertyConfigs});if(Array.isArray(s.of))throw Error("Using array properties instead of single one in `of` in ArrayProperty");if(!s.of||s.dataType!=="array"||s.of.dataType!=="string")throw Error("Picked wrong preview component ArrayOfStringsPreview");if(t&&!Array.isArray(t))return r.jsx("div",{children:`Unexpected value: ${t}`});const a=s.of;return r.jsx("div",{className:"flex flex-col gap-2",children:t&&t.map((A,d)=>r.jsx("div",{children:r.jsx(ne,{children:r.jsx(Gr,{propertyKey:e,property:a,value:A,entity:o,size:l})})},`preview_array_strings_${e}_${d}`))})}function ho({propertyKey:e,value:t,property:n,size:o,entity:l}){const i=X(),s=_e({propertyKey:e,property:n,propertyValue:t,fields:i.propertyConfigs});if(s?.dataType!=="array")throw Error("Picked wrong preview component ArrayPreview");if(!s?.oneOf)throw Error(`You need to specify an 'of' or 'oneOf' prop (or specify a custom field) in your array property ${e}`);const a=t;if(!a)return null;const A=o==="medium"?"small":"tiny",d=s.oneOf.typeField??yt,g=s.oneOf.valueField??zt,p=s.oneOf.properties;return r.jsx("div",{className:"flex flex-col",children:a&&a.map((h,u)=>r.jsx(c.Fragment,{children:r.jsx("div",{className:f.cn(f.defaultBorderMixin,"m-1 border-b last:border-b-0"),children:r.jsx(ne,{children:h&&r.jsx(me,{propertyKey:e,value:h[g],entity:l,property:s.resolvedProperties[u]??p[h[d]],size:A})})})},"preview_array_"+h+"_"+u))})}function po({propertyKey:e,value:t,property:n,entity:o,size:l}){if(n.dataType!=="map")throw Error("Picked wrong preview component MapPropertyPreview");const i=n;if(!i.properties||Object.keys(i.properties??{}).length===0)return r.jsx(Lr,{value:t});if(!t)return null;const s=Object.keys(i.properties);return l==="tiny"?r.jsx("div",{className:"w-full flex flex-col space-y-1 md:space-y-2",children:s.map((a,A)=>r.jsx("div",{children:r.jsx(ne,{children:r.jsx(me,{propertyKey:a,value:t[a],property:i.properties[a],entity:o,size:l})},"map_preview_"+i.name+a+A)},`map_${a}`))}):r.jsx("div",{className:"flex flex-col gap-1 w-full",children:s&&s.map((a,A)=>{const d=i.properties[a];return r.jsxs("div",{className:f.cn(f.defaultBorderMixin,"last:border-b-0 border-b"),children:[r.jsxs("div",{className:"flex flex-row pt-0.5 pb-0.5 gap-2",children:[r.jsx("div",{className:"min-w-[140px] w-[25%] py-1",children:r.jsx(f.Typography,{variant:"caption",className:"font-mono break-words",color:"secondary",children:d.name})}),r.jsx("div",{className:"flex-grow max-w-[75%]",children:r.jsx(ne,{children:!(d.dataType==="map"||d==="array")&&r.jsx(me,{propertyKey:a,value:t[a],property:d,entity:o,size:l})})})]}),(d.dataType==="map"||d==="array")&&r.jsx("div",{className:f.cn(f.defaultBorderMixin,"border-l pl-4 ml-2 my-2"),children:r.jsx(me,{propertyKey:a,value:t[a],property:d,entity:o,size:l})})]},`map_preview_table_${a}}`)})})}function Lr({value:e}){return typeof e!="object"?null:r.jsx("div",{className:"flex flex-col gap-1 w-full",children:Object.entries(e).map(([t,n])=>r.jsxs("div",{className:f.cn(f.defaultBorderMixin,"last:border-b-0 border-b"),children:[r.jsxs("div",{className:"flex flex-row pt-0.5 pb-0.5 gap-2",children:[r.jsx("div",{className:"min-w-[140px] w-[25%] py-1",children:r.jsx(f.Typography,{variant:"caption",className:"font-mono break-words",color:"secondary",children:t})},`table-cell-title-${t}-${t}`),r.jsx("div",{className:"flex-grow max-w-[75%]",children:typeof n!="object"&&r.jsx(f.Typography,{children:r.jsx(ne,{children:n&&n.toString()})})})]}),typeof n=="object"&&r.jsx("div",{className:f.cn(f.defaultBorderMixin,"border-l pl-4"),children:r.jsx(Lr,{value:n})})]},`map_preview_table_${t}}`))})}function mo({date:e}){const t=X(),n=t?.locale?En[t?.locale]:void 0,o=t?.dateTimeFormat??Mn,l=e?yl.format(e,o,{locale:n}):"";return r.jsx(r.Fragment,{children:l})}function bo({value:e}){return r.jsx(f.Checkbox,{checked:e})}function yo({value:e,property:t,size:n}){if(t.enumValues){const o=e,l=$e(t.enumValues);return l?r.jsx(we,{enumKey:o,enumValues:l,size:n!=="medium"?"small":"medium"}):r.jsx(r.Fragment,{children:e})}else return r.jsx(r.Fragment,{children:e})}function me(e){const t=X();let n;const{property:o,propertyKey:l,value:i,size:s,height:a,width:A,entity:d}=e,g=ke({propertyKey:l,propertyOrBuilder:o,propertyValue:i,fields:t.propertyConfigs});if(i===void 0||g===null)n=r.jsx(dt,{});else if(g.Preview)n=c.createElement(g.Preview,{propertyKey:l,value:i,property:g,size:s,height:a,width:A,entity:d,customProps:g.customProps});else if(i===null)n=r.jsx(dt,{});else if(g.dataType==="string"){const p=g;typeof i=="string"?p.url?typeof p.url=="boolean"?n=r.jsx(Bt,{size:e.size,url:i}):typeof p.url=="string"&&(n=r.jsx(Bt,{size:e.size,url:i,previewType:p.url})):p.storage?n=r.jsx(so,{storeUrl:g.storage?.storeUrl??!1,size:e.size,storagePathOrDownloadUrl:i}):p.markdown?n=r.jsx(f.Markdown,{source:i}):n=r.jsx(Gr,{...e,property:p,value:i}):n=rt(l,g.dataType,i)}else if(g.dataType==="array")if(i instanceof Array){const p=g;if(!p.of&&!p.oneOf)throw Error(`You need to specify an 'of' or 'oneOf' prop (or specify a custom field) in your array property ${l}`);p.of?Array.isArray(p.of)?n=r.jsx(Yr,{...e,value:i,property:g}):p.of.dataType==="reference"?n=r.jsx(fo,{...e,value:i,property:g}):p.of.dataType==="string"?p.of.enumValues?n=r.jsx(Ur,{...e,value:i,property:g}):p.of.storage?n=r.jsx(uo,{...e,value:i,property:g}):n=r.jsx(go,{...e,value:i,property:g}):p.of.dataType==="number"&&p.of.enumValues?n=r.jsx(Ur,{...e,value:i,property:g}):n=r.jsx(Yr,{...e,value:i,property:g}):p.oneOf&&(n=r.jsx(ho,{...e,value:i,property:g}))}else n=rt(l,g.dataType,i);else g.dataType==="map"?typeof i=="object"?n=r.jsx(po,{...e,property:g}):n=rt(l,g.dataType,i):g.dataType==="date"?i instanceof Date?n=r.jsx(mo,{date:i}):n=rt(l,g.dataType,i):g.dataType==="reference"?typeof g.path=="string"?i instanceof Pe?n=r.jsx(Ge,{disabled:!g.path,previewProperties:g.previewProperties,size:e.size,onClick:e.onClick,reference:i}):n=rt(l,g.dataType,i):n=r.jsx(dt,{}):g.dataType==="boolean"?typeof i=="boolean"?n=r.jsx(bo,{value:i}):n=rt(l,g.dataType,i):g.dataType==="number"?typeof i=="number"?n=r.jsx(yo,{...e,value:i,property:g}):n=rt(l,g.dataType,i):n=JSON.stringify(i);return n??r.jsx(dt,{})}function rt(e,t,n){return console.warn(`Unexpected value for property ${e}, of type ${t}`,n),r.jsx(pe,{title:"Unexpected value",error:`${JSON.stringify(n)}`})}function Ni({propertyKey:e,value:t,property:n,size:o,entity:l}){const i=X(),s=_e({propertyKey:e,property:n,propertyValue:t,fields:i.propertyConfigs});if(Array.isArray(s?.of))throw Error("Using array properties instead of single one in `of` in ArrayProperty");if(s?.dataType!=="array"||!s.of||s.of.dataType!=="map")throw Error("Picked wrong preview component ArrayOfMapsPreview");const a=s.of,A=a.properties;if(!A)throw Error(`You need to specify a 'properties' prop (or specify a custom field) in your map property ${e}`);const d=t,g=a.previewProperties;if(!d)return null;let p=g;return(!p||!p.length)&&(p=Object.keys(A),o&&(p=p.slice(0,3))),r.jsx("div",{className:"table-auto text-xs",children:r.jsx("div",{children:d&&d.map((h,u)=>r.jsx("div",{className:"border-b last:border-b-0",children:p&&p.map(m=>r.jsx("div",{className:"table-cell",children:r.jsx(ne,{children:r.jsx(me,{propertyKey:m,value:h[m],property:A[m],entity:l,size:"small"})})},`table-cell-${m}`))},`table_${h}_${u}`))})})}const Qi=Ar.memo(function({builder:t}){const[n,o]=c.useState(!0),[l,i]=c.useState(null);return c.useEffect(()=>{let s=!1;return t.then(a=>{s||(o(!1),i(a))}).catch(a=>{o(!1),console.error(a)}),()=>{s=!0}},[t]),n?r.jsx(f.Skeleton,{}):r.jsx(Ar.Fragment,{children:l})});function $r({entity:e,collection:t,path:n,className:o}){const l=X(),i=c.useMemo(()=>Be({collection:t,path:n,entityId:e.id,values:e.values,fields:l.propertyConfigs}),[t,n,e]),s=X(),a=i.properties;return r.jsx("div",{className:"w-full "+o,children:r.jsxs("div",{className:"w-full mb-4",children:[r.jsxs("div",{className:f.cn(f.defaultBorderMixin,"flex justify-between py-2 border-b last:border-b-0"),children:[r.jsx("div",{className:"flex items-center w-1/4",children:r.jsx("span",{className:"pl-2 text-sm text-gray-600",children:"Id"})}),r.jsxs("div",{className:"flex-grow p-2 ml-2 w-3/4 text-gray-900 dark:text-white min-h-[56px] flex items-center",children:[r.jsx("span",{className:"flex-grow mr-2",children:e.id}),s?.entityLinkBuilder&&r.jsx("a",{href:s.entityLinkBuilder({entity:e}),rel:"noopener noreferrer",target:"_blank",children:r.jsx(f.IconButton,{children:r.jsx(f.OpenInNewIcon,{size:"small"})})})]})]}),Object.entries(a).map(([A,d])=>{const g=e.values[A];return r.jsxs("div",{className:f.cn(f.defaultBorderMixin,"flex justify-between py-2 border-b last:border-b-0"),children:[r.jsx("div",{className:"flex items-center w-1/4",children:r.jsx("span",{className:"pl-2 text-sm text-gray-600",children:d.name})}),r.jsx("div",{className:"flex-grow p-2 ml-2 w-3/4 text-gray-900 dark:text-white min-h-[56px] flex items-center",children:r.jsx(me,{propertyKey:A,value:g,entity:e,property:d,size:"medium"})})]},`reference_previews_${A}`)})]})})}function Ti(e){return e.dataType==="boolean"?"center":e.dataType==="number"?e.enumValues?"left":"right":e.dataType==="date"?"right":"left"}function vo(e){if(e.columnWidth)return e.columnWidth;if(e.dataType==="string")return e.url?280:e.storage?160:e.enumValues?200:e.multiline||e.markdown?300:(e.email,200);if(e.dataType==="array"){const t=e;return t.of?Array.isArray(e.of)?300:vo(t.of):300}else return e.dataType==="number"?e.enumValues?200:140:e.dataType==="map"?360:e.dataType==="date"?200:e.dataType==="reference"?220:e.dataType==="boolean"?140:200}function _r(e){return`subcollection:${e.id??e.path}`}function Mi(e){const t=c.useRef(null),{disabled:n,value:o,multiline:l,updateValue:i,focused:s}=e,a=c.useRef(o),[A,d]=c.useState(o),g=c.useRef(!1);c.useEffect(()=>{a.current!==o&&o!==A&&d(o),a.current=o},[o]);const p=c.useCallback(()=>{!o&&!A||A!==o&&(a.current=A,i(A))},[A,i,o]);return Wt(A,p,!s,2e3),c.useEffect(()=>{t.current&&s&&!g.current?(g.current=!0,t.current.focus({preventScroll:!0}),t.current.selectionStart=t.current.value.length,t.current.selectionEnd=t.current.value.length):g.current=s},[s,t]),r.jsx(f.TextareaAutosize,{ref:t,style:{padding:0,margin:0,width:"100%",color:"unset",fontWeight:"unset",lineHeight:"unset",fontSize:"unset",fontFamily:"unset",background:"unset",border:"unset",resize:"none",outline:"none"},value:A??"",onChange:h=>{const u=h.target.value;(l||!u.endsWith(`
|
|
4
4
|
`))&&d(u)},onFocus:()=>{g.current=!0},onBlur:()=>{g.current=!1,p()}})}function Wr(e){const{name:t,enumValues:n,error:o,internalValue:l,disabled:i,small:s,focused:a,updateValue:A,multiple:d,valueType:g}=e,p=Array.isArray(l)&&d||!Array.isArray(l)&&!d,h=c.useRef(null);c.useEffect(()=>{h.current&&a&&h.current?.focus({preventScroll:!0})},[a,h]);const u=c.useCallback(b=>{if(g==="number")if(d){const y=b.map(w=>parseFloat(w));A(y)}else A(parseFloat(b));else if(g==="string")A(b||null);else throw Error("Missing mapping in TableSelect")},[d,A,g]),m=(b,y)=>d&&Array.isArray(b)?r.jsx(zr,{value:b,name:t,enumValues:n,size:s?"small":"medium"},`${b}-${y}`):r.jsx(we,{enumKey:b,enumValues:n,size:s?"small":"medium"},`${b}-${y}`);return d?r.jsx(f.MultiSelect,{inputRef:h,containerClassName:"w-full h-full",className:"w-full h-full p-0 bg-transparent",position:"item-aligned",disabled:i,padding:!1,includeFocusOutline:!1,value:p?l.map(b=>b.toString()):[],onMultiValueChange:u,renderValue:m,children:n?.map(b=>r.jsx(f.MultiSelectItem,{value:String(b.id),children:r.jsx(we,{enumKey:b.id,enumValues:n,size:s?"small":"medium"})},b.id))}):r.jsx(f.Select,{inputRef:h,className:"w-full h-full p-0 bg-transparent",position:"item-aligned",disabled:i,multiple:d,padding:!1,includeFocusOutline:!1,value:p?d?l.map(b=>b.toString()):l?.toString():d?[]:"",onValueChange:u,onMultiValueChange:u,renderValue:m,children:n?.map(b=>r.jsx(f.SelectItem,{value:String(b.id),children:r.jsx(we,{enumKey:b.id,enumValues:n,size:s?"small":"medium"})},b.id))})}function Pi(e){const{align:t,value:n,updateValue:o,focused:l}=e,i=n&&typeof n=="number"?n.toString():"",[s,a]=c.useState(i),A=c.useRef(n);c.useEffect(()=>{A.current!==n&&String(n)!==s&&a(n?n.toString():null),A.current=n},[n]);const d=c.useCallback(()=>{if(s!==i)if(s!=null){const h=parseFloat(s);if(isNaN(h))return;h!=null&&o(h)}else o(null)},[s,n]);Wt(s,d,!l,2e3),c.useEffect(()=>{!l&&i!==s&&a(n!=null?n.toString():null)},[n,l]);const g=c.useRef(null);c.useEffect(()=>{g.current&&l&&g.current.focus({preventScroll:!0})},[l,g]);const p=/^-?[0-9]+[,.]?[0-9]*$/;return r.jsx("input",{ref:g,className:"w-full text-right p-0 m-0 bg-transparent border-none resize-none outline-none font-normal leading-normal text-unset",style:{textAlign:t},value:s??"",onChange:h=>{const u=h.target.value.replace(",",".");u.length===0&&a(null),(p.test(u)||u.startsWith("-"))&&a(u)}})}function Di(e){const{internalValue:t,updateValue:n,focused:o}=e,l=c.useRef(null);return c.useEffect(()=>{l.current&&o&&l.current.focus({preventScroll:!0})},[o,l]),r.jsx(f.BooleanSwitch,{ref:l,size:"small",value:!!t,onValueChange:n})}function Oi(e){const{locale:t}=X(),{disabled:n,error:o,mode:l,internalValue:i,updateValue:s}=e;return r.jsx(f.DateTimeField,{value:i??void 0,onChange:a=>s(a),size:"medium",invisible:!0,className:"w-full h-full",inputClassName:"w-full h-full",mode:l,locale:t})}class ne extends c.Component{constructor(t){super(t),this.state={error:null}}static getDerivedStateFromError(t){return{error:t}}componentDidCatch(t,n){console.error(t)}render(){return this.state.error?r.jsxs("div",{className:"flex flex-col m-2",children:[r.jsxs("div",{className:"flex items-center m-2",children:[r.jsx(f.ErrorIcon,{color:"error",size:"small"}),r.jsx("div",{className:"ml-4",children:"Error"})]}),r.jsx(f.Typography,{variant:"caption",children:this.state.error?.message??"See the error in the console"})]}):this.props.children}}async function Vi(e,t,n,o,l,i,s,a){let A;return typeof e=="function"?(A=await e({path:l,entityId:o,values:n,property:i,file:s,storage:t,propertyKey:a}),A||console.warn("Storage callback returned empty result. Using default name value")):A=wo(s,e,o,a,l),A||(A=st()+"_"+s.name),A}function Gi(e,t,n,o,l,i,s,a){let A;return typeof e=="function"?(A=e({path:l,entityId:o,values:n,property:i,file:s,storage:t,propertyKey:a}),A||console.warn("Storage callback returned empty result. Using default name value")):A=wo(s,e,o,a,l),A||(A=st()+"_"+s.name),A}function wo(e,t,n,o,l){const i=e.name.split(".").pop();let s=t.replace("{entityId}",n).replace("{propertyKey}",o).replace("{rand}",st()).replace("{file}",e.name).replace("{file.type}",e.type).replace("{path}",l);if(i){s=s.replace("{file.ext}",i);const a=e.name.replace(`.${i}`,"");s=s.replace("{file.name}",a)}return s||(s=st()+"_"+e.name),s}function Co({entityId:e,entityValues:t,path:n,value:o,property:l,propertyKey:i,storageSource:s,disabled:a,onChange:A}){const d=l.dataType==="string"?l.storage:l.dataType==="array"&&l.of.dataType==="string"?l.of.storage:void 0,g=l.dataType==="array";if(!d)throw Error("Storage meta must be specified");const p=d?.metadata,h=g?"small":"medium",u=d?.imageCompression,m=(g?o??[]:o?[o]:[]).map(B=>({id:jr(),storagePathOrDownloadUrl:B,metadata:p,size:h})),[b,y]=c.useState(o),[w,C]=c.useState(m);c.useEffect(()=>{oe(b,o)||(y(o),C(m))},[m,o,b]);const E=c.useCallback(async B=>{if(d.fileName){const N=await Vi(d.fileName,d,t,e,n,l,B,i);if(!N||N.length===0)throw Error("You need to return a valid filename");return N}return st()+"_"+B.name},[e,t,n,l,i,d]),k=c.useCallback(B=>Gi(d.storagePath,d,t,e,n,l,B,i)??"/",[e,t,n,l,i,d]),I=c.useCallback(async(B,N,F)=>{console.debug("onFileUploadComplete",B,N);let Q=B;if(d.storeUrl&&(Q=(await s.getDownloadURL(B)).url),d.postProcess&&Q&&(Q=await d.postProcess(Q)),!Q){console.warn("uploadPathOrDownloadUrl is null");return}let S;N.storagePathOrDownloadUrl=Q,N.metadata=F,S=[...w],S=Eo(S),C(S);const T=S.filter(V=>!!V.storagePathOrDownloadUrl).map(V=>V.storagePathOrDownloadUrl);A(g?T:T?T[0]:null)},[w,g,A,d,s]),x=c.useCallback(async B=>{if(!B.length||a)return;let N;if(g)N=[...w,...await Promise.all(B.map(async F=>(u&&Hr(F)&&(F=await ko(F,u)),{id:jr(),file:F,fileName:await E(F),metadata:p,size:h})))];else{let F=B[0];u&&Hr(F)&&(F=await ko(F,u)),N=[{id:jr(),file:F,fileName:await E(F),metadata:p,size:h}]}N=Eo(N),C(N)},[a,E,w,p,g,h]);return{internalValue:w,setInternalValue:C,storage:d,fileNameBuilder:E,storagePathBuilder:k,onFileUploadComplete:I,onFilesAdded:x,multipleFilesSupported:g}}function Eo(e){return e.filter((t,n)=>(e.map(o=>o.storagePathOrDownloadUrl).indexOf(t.storagePathOrDownloadUrl)===n||!t.storagePathOrDownloadUrl)&&(e.map(o=>o.file).indexOf(t.file)===n||!t.file))}function jr(){return Math.floor(Math.random()*Math.floor(Number.MAX_SAFE_INTEGER))}const Bo={"image/jpeg":"JPEG","image/png":"PNG","image/webp":"WEBP"},Hr=e=>Bo[e.type]?Bo[e.type]:null,Yi=100,ko=(e,t)=>new Promise(n=>{const o=t.quality===void 0?Yi:t.quality,l=o>=0&&o<=100?o:100,i=Hr(e);if(!i)throw Error("resizeAndCompressImage: Unsupported image format");Cl.imageFileResizer(e,t.maxWidth||Number.MAX_VALUE,t.maxHeight||Number.MAX_VALUE,i,l,0,s=>n(s),"file")});function xo({storagePath:e,entry:t,metadata:n,onFileUploadComplete:o,imageSize:l,simple:i}){const s=ct(),a=He(),[A,d]=c.useState(),[g,p]=c.useState(!1),h=c.useRef(!1),u=c.useRef(!1),m=c.useCallback((b,y)=>{u.current||(u.current=!0,d(void 0),p(!0),s.uploadFile({file:b,fileName:y,path:e,metadata:n}).then(async({path:w})=>{console.debug("Upload successful"),await o(w,t,n),h.current&&p(!1)}).catch(w=>{console.warn("Upload error",w),h.current&&(d(w),p(!1),a.open({type:"error",message:"Error uploading file: "+w.message}))}).finally(()=>{u.current=!1}))},[t,n,o,s,e]);return c.useEffect(()=>(h.current=!0,t.file&&m(t.file,t.fileName),()=>{h.current=!1}),[t.file,t.fileName,m]),i?r.jsx("div",{className:`m-4 w-${l} h-${l}`,children:g&&r.jsx(f.Skeleton,{className:`w-${l} h-${l}`})}):r.jsxs("div",{className:f.cn(f.paperMixin,"relative m-4 border-box flex items-center justify-center",`min-w-[${l}px] min-h-[${l}px]`),children:[g&&r.jsx(f.Skeleton,{className:"w-full h-full"}),A&&r.jsx(pe,{title:"Error uploading file",error:A})]})}function Io({showError:e,disabled:t,showExpandIcon:n,selected:o,openPopup:l,children:i}){const s=c.useRef(null),a=c.useCallback(()=>{if(l){const d=s&&s?.current?.getBoundingClientRect();l(d)}},[]),A=c.useRef();return c.useEffect(()=>{A.current&&o&&A.current.focus({preventScroll:!0})},[o]),r.jsx(r.Fragment,{children:(e||!t&&n)&&r.jsxs("div",{ref:s,className:"absolute top-0.5 right-0.5 flex items-center",children:[o&&i,o&&!t&&n&&r.jsx(f.IconButton,{ref:A,color:"inherit",size:"small",onClick:a,children:r.jsxs("svg",{fill:"#888",width:"20",height:"20",viewBox:"0 0 24 24",children:[r.jsx("path",{className:"cls-2",d:"M20,5a1,1,0,0,0-1-1L14,4h0a1,1,0,0,0,0,2h2.57L13.29,9.29a1,1,0,0,0,0,1.42,1,1,0,0,0,1.42,0L18,7.42V10a1,1,0,0,0,1,1h0a1,1,0,0,0,1-1Z"}),r.jsx("path",{className:"cls-2",d:"M10.71,13.29a1,1,0,0,0-1.42,0L6,16.57V14a1,1,0,0,0-1-1H5a1,1,0,0,0-1,1l0,5a1,1,0,0,0,1,1h5a1,1,0,0,0,0-2H7.42l3.29-3.29A1,1,0,0,0,10.71,13.29Z"})]})}),e&&r.jsx(lo,{side:"left",className:"flex items-center justify-center",style:{width:32,height:32},title:e.message,children:r.jsx(f.ErrorOutlineIcon,{size:"small",color:"error"})})]})})}const zi="max-w-full box-border relative pt-[2px] items-center border border-transparent outline-none rounded-md duration-200 ease-[cubic-bezier(0.4,0,0.2,1)] focus:border-primary-solid",Ui="pt-0 border-2 border-solid",Li="transition-colors duration-200 ease-[cubic-bezier(0,0,0.2,1)] border-2 border-solid border-green-500 bg-green-50 dark:bg-green-900",$i="transition-colors duration-200 ease-[cubic-bezier(0,0,0.2,1)] border-2 border-solid border-red-500 bg-red-50 dark:bg-red-900";function _i(e){const{propertyKey:t,error:n,selected:o,openPopup:l,value:i,disabled:s,property:a,entity:A,path:d,previewSize:g,updateValue:p}=e,h=ct(),{internalValue:u,setInternalValue:m,onFilesAdded:b,storage:y,onFileUploadComplete:w,storagePathBuilder:C,multipleFilesSupported:E}=Co({entityValues:A.values,entityId:A.id,path:d,property:a,propertyKey:t,storageSource:h,onChange:p,value:i,disabled:s});return r.jsx(Wi,{internalValue:u,setInternalValue:m,name:t,disabled:s,autoFocus:!1,openPopup:l,error:n,selected:o,property:a,onChange:p,entity:A,storagePathBuilder:C,storage:y,multipleFilesSupported:E,onFilesAdded:b,onFileUploadComplete:w,previewSize:g})}function Wi({property:e,name:t,internalValue:n,setInternalValue:o,openPopup:l,entity:i,selected:s,error:a,onChange:A,multipleFilesSupported:d,previewSize:g,disabled:p,autoFocus:h,storage:u,onFilesAdded:m,onFileUploadComplete:b,storagePathBuilder:y}){const[w,C]=c.useState(!1),E=d&&g==="medium"?"small":g;if(d){const z=e;if(Array.isArray(z.of))throw Error("Using array properties instead of single one in `of` in ArrayProperty");if(z.of){if(z.of.dataType!=="string")throw Error("Storage field using array must be of data type string")}else throw Error("Storage field using array must be of data type string")}const k=u?.metadata,I=!!n,x=He(),{open:B,getRootProps:N,getInputProps:F,isDragActive:Q,isDragAccept:S,isDragReject:T}=wn.useDropzone({accept:u.acceptedFiles?u.acceptedFiles.map(z=>({[z]:[]})).reduce((z,G)=>({...z,...G}),{}):void 0,disabled:p,maxSize:u.maxSize,noClick:!0,noKeyboard:!0,onDrop:m,onDropRejected:(z,G)=>{for(const re of z)for(const W of re.errors)x.open({type:"error",message:`Error uploading file: File is larger than ${u.maxSize} bytes`})}}),{...V}=N(),H=d?"Drag 'n' drop some files here, or click here to edit":"Drag 'n' drop a file here, or click here edit",_=d?e.of:e,j=c.useMemo(()=>ft(E),[E]),te=!p&&a;return r.jsxs("div",{...V,onMouseEnter:()=>C(!0),onMouseMove:()=>C(!0),onMouseLeave:()=>C(!1),className:f.cn(zi,"relative w-full h-full flex",`justify-${I?"start":"center"}`,Q?Ui:"",S?Li:"",T?$i:""),children:[r.jsx("input",{autoFocus:h,...F()}),n.map((z,G)=>{let re;return z.storagePathOrDownloadUrl?re=r.jsx(ji,{property:_,value:z.storagePathOrDownloadUrl,entity:i,size:E},`storage_preview_${G}`):z.file&&(re=r.jsx(xo,{entry:z,metadata:k,storagePath:y(z.file),onFileUploadComplete:b,imageSize:j,simple:!0},`storage_progress_${G}`)),re}),!n&&r.jsx("div",{className:"flex-grow m-2 max-w-[200px]",onClick:B,children:r.jsx(f.Typography,{className:"text-gray-400 dark:text-gray-600",variant:"body2",align:"center",children:H})}),r.jsx(Io,{showError:te,disabled:p,showExpandIcon:!0,selected:s,openPopup:p?void 0:l,children:r.jsx(f.IconButton,{color:"inherit",size:"small",onClick:B,children:r.jsx(f.EditIcon,{size:"small",className:"text-gray-500"})})})]})}function ji({property:e,value:t,size:n,entity:o}){return r.jsx("div",{className:"relative m-2",children:t&&r.jsx(ne,{children:r.jsx(me,{propertyKey:"ignore",value:t,property:e,entity:o,size:n})})})}function So(e){const t=X(),n=ie(),{path:o}=e,l=n.getCollection(o);if(!l){if(t.components?.missingReference)return r.jsx(t.components.missingReference,{path:o});throw Error(`Couldn't find the corresponding collection view for the path: ${o}`)}return r.jsx(Hi,{...e,collection:l})}function Hi(e){const{name:t,internalValue:n,updateValue:o,multiselect:l,path:i,size:s,previewProperties:a,title:A,disabled:d,forceFilter:g,collection:p}=e,[h,u]=c.useState(!1),m=c.useCallback(()=>u(!0),[]),b=c.useCallback(()=>u(!1),[]),y=c.useCallback(N=>{o(N?et(N):null)},[o]),w=c.useCallback(N=>{o(N.map(F=>et(F)))},[o]),C=n?Array.isArray(n)?n.map(N=>N.id):n.id?[n.id]:[]:[],E=St({multiselect:l,path:i,collection:p,onMultipleEntitiesSelected:w,onSingleEntitySelected:y,selectedEntityIds:C,forceFilter:g}),k=c.useCallback(()=>{d||E.open()},[d,E]),I=!n||Array.isArray(n)&&n.length===0,x=()=>n instanceof Pe?r.jsx(Ge,{onClick:d?void 0:k,size:Je(s),reference:n,onHover:h,disabled:!i,previewProperties:a}):r.jsx(Xt,{onClick:d?void 0:k,size:Je(s),children:r.jsx(pe,{title:"Value is not a reference.",error:"Click to edit"})}),B=()=>Array.isArray(n)?r.jsx(r.Fragment,{children:n.map((N,F)=>r.jsx("div",{className:"m-1 w-full",children:r.jsx(Ge,{onClick:d?void 0:k,size:"tiny",reference:N,onHover:h,disabled:!i,previewProperties:a})},`preview_array_ref_${t}_${F}`))}):r.jsx(pe,{error:"Data is not an array of references"});return p?r.jsxs("div",{className:"w-full",onMouseEnter:m,onMouseMove:m,onMouseLeave:b,children:[n&&!l&&x(),n&&l&&B(),I&&r.jsxs(f.Button,{onClick:k,size:"small",variant:"outlined",color:"primary",children:["Edit ",A]})]}):r.jsx(pe,{error:"The specified collection does not exist"})}Ee.addMethod(Ee.array,"uniqueInArray",function(e=n=>n,t){return this.test("uniqueInArray",t,n=>!n||n.length===new Set(n.map(e)).size)});function Fo(e,t,n){const o={};return Object.entries(t).forEach(([l,i])=>{o[l]=kt({property:i,customFieldValidator:n,name:l,entityId:e})}),Ee.object().shape(o)}function kt(e){const t=e.property;if(ve(t))throw console.error("Error in property",e),Error("Trying to create a yup mapping from a property builder. Please use resolved properties only");if(t.dataType==="string")return qi(e);if(t.dataType==="number")return Zi(e);if(t.dataType==="boolean")return es(e);if(t.dataType==="map")return Ji(e);if(t.dataType==="array")return rs(e);if(t.dataType==="date")return Ki(e);if(t.dataType==="geopoint")return Xi(e);if(t.dataType==="reference")return Ri(e);throw console.error("Unsupported data type in yup mapping",t),Error("Unsupported data type in yup mapping")}function Ji({property:e,entityId:t,customFieldValidator:n,name:o}){const l={};return e.validation,e.properties&&Object.entries(e.properties).forEach(([i,s])=>{l[i]=kt({property:s,parentProperty:e,customFieldValidator:n,name:`${o}[${i}]`,entityId:t})}),Ee.object().shape(l)}function qi({property:e,parentProperty:t,customFieldValidator:n,name:o,entityId:l}){let i=Ee.string();const s=e.validation;if(e.enumValues){s?.required&&(i=i.required(s?.requiredMessage?s.requiredMessage:"Required"));const a=$e(e.enumValues);i=i.oneOf((s?.required?a:[...a,null]).map(A=>A?.id??null)).nullable(!0)}if(s){if(i=s.required?i.required(s?.requiredMessage?s.requiredMessage:"Required").nullable(!0):i.notRequired().nullable(!0),s.unique&&n&&o&&(i=i.test("unique","This value already exists and should be unique",(a,A)=>n({name:o,property:e,parentProperty:t,value:a,entityId:l}))),(s.min||s.min===0)&&(i=i.min(s.min,`${e.name} must be min ${s.min} characters long`)),(s.max||s.max===0)&&(i=i.max(s.max,`${e.name} must be max ${s.max} characters long`)),s.matches){const a=typeof s.matches=="string"?On(s.matches):s.matches;a&&(i=i.matches(a,s.matchesMessage?{message:s.matchesMessage}:void 0))}s.trim&&(i=i.trim()),s.lowercase&&(i=i.lowercase()),s.uppercase&&(i=i.uppercase()),e.email&&(i=i.email(`${e.name} must be an email`)),e.url&&(i=i.url(`${e.name} must be a url`))}else i=i.notRequired().nullable(!0);return i}function Zi({property:e,parentProperty:t,customFieldValidator:n,name:o,entityId:l}){const i=e.validation;let s=Ee.number().typeError("Must be a number");return i?(s=i.required?s.required(i.requiredMessage?i.requiredMessage:"Required").nullable(!0):s.notRequired().nullable(!0),i.unique&&n&&o&&(s=s.test("unique","This value already exists and should be unique",a=>n({name:o,property:e,parentProperty:t,value:a,entityId:l}))),(i.min||i.min===0)&&(s=s.min(i.min,`${e.name} must be higher or equal to ${i.min}`)),(i.max||i.max===0)&&(s=s.max(i.max,`${e.name} must be lower or equal to ${i.max}`)),(i.lessThan||i.lessThan===0)&&(s=s.lessThan(i.lessThan,`${e.name} must be higher than ${i.lessThan}`)),(i.moreThan||i.moreThan===0)&&(s=s.moreThan(i.moreThan,`${e.name} must be lower than ${i.moreThan}`)),i.positive&&(s=s.positive(`${e.name} must be positive`)),i.negative&&(s=s.negative(`${e.name} must be negative`)),i.integer&&(s=s.integer(`${e.name} must be an integer`))):s=s.notRequired().nullable(!0),s}function Xi({property:e,parentProperty:t,customFieldValidator:n,name:o,entityId:l}){let i=Ee.object();const s=e.validation;return s?.unique&&n&&o&&(i=i.test("unique","This value already exists and should be unique",a=>n({name:o,property:e,parentProperty:t,value:a,entityId:l}))),s?.required?i=i.required(s.requiredMessage).nullable(!0):i=i.notRequired().nullable(!0),i}function Ki({property:e,parentProperty:t,customFieldValidator:n,name:o,entityId:l}){if(e.autoValue)return Ee.object().nullable();let i=Ee.date();const s=e.validation;return s?(i=s.required?i.required(s?.requiredMessage?s.requiredMessage:"Required"):i.notRequired(),s.unique&&n&&o&&(i=i.test("unique","This value already exists and should be unique",a=>n({name:o,property:e,parentProperty:t,value:a,entityId:l}))),s.min&&(i=i.min(s.min,`${e.name} must be after ${s.min}`)),s.max&&(i=i.max(s.max,`${e.name} must be before ${s.min}`))):i=i.notRequired(),i.transform(a=>a instanceof Date?a:null).nullable()}function Ri({property:e,parentProperty:t,customFieldValidator:n,name:o,entityId:l}){let i=Ee.object();const s=e.validation;return s?(i=s.required?i.required(s?.requiredMessage?s.requiredMessage:"Required").nullable(!0):i.notRequired().nullable(!0),s.unique&&n&&o&&(i=i.test("unique","This value already exists and should be unique",a=>n({name:o,property:e,parentProperty:t,value:a,entityId:l})))):i=i.notRequired().nullable(!0),i}function es({property:e,parentProperty:t,customFieldValidator:n,name:o,entityId:l}){let i=Ee.boolean();const s=e.validation;return s?(i=s.required?i.required(s?.requiredMessage?s.requiredMessage:"Required").nullable(!0):i.notRequired().nullable(!0),s.unique&&n&&o&&(i=i.test("unique","This value already exists and should be unique",a=>n({name:o,property:e,parentProperty:t,value:a,entityId:l})))):i=i.notRequired().nullable(!0),i}function ts(e){return e.validation?.uniqueInArray?!0:e.dataType==="map"&&e.properties?Object.entries(e.properties).filter(([t,n])=>n.validation?.uniqueInArray):!1}function rs({property:e,parentProperty:t,customFieldValidator:n,name:o,entityId:l}){let i=Ee.array();if(e.of)if(Array.isArray(e.of)){const a=e.of.map((A,d)=>({[`${o}[${d}]`]:kt({property:A,parentProperty:e,entityId:l})})).reduce((A,d)=>({...A,...d}),{});return Ee.array().of(Ee.mixed().test("Dynamic object validation","Dynamic object validation error",(A,d)=>Le(a,d.path).validate(A)))}else{i=i.of(kt({property:e.of,parentProperty:e,entityId:l}));const a=ts(e.of);a&&(typeof a=="boolean"?i=i.uniqueInArray(A=>A,`${e.name} should have unique values within the array`):Array.isArray(a)&&a.forEach(([A,d])=>{i=i.uniqueInArray(g=>g&&g[A],`${e.name} → ${d.name??A}: should have unique values within the array`)}))}const s=e.validation;return s?(i=s.required?i.required(s?.requiredMessage?s.requiredMessage:"Required").nullable(!0):i.notRequired().nullable(!0),(s.min||s.min===0)&&(i=i.min(s.min,`${e.name} should be min ${s.min} entries long`)),s.max&&(i=i.max(s.max,`${e.name} should be max ${s.max} entries long`))):i=i.notRequired().nullable(!0),i}function gt(e){switch(e){case"xl":return 400;case"l":return 280;case"m":return 140;case"s":return 80;case"xs":return 54;default:throw Error("Missing mapping for collection size -> height")}}const ns=({justifyContent:e,scrollable:t,faded:n,fullHeight:o,children:l})=>r.jsx("div",{className:f.cn("flex flex-col max-h-full w-full",{"items-start":n||t}),style:{justifyContent:e,height:o?"100%":void 0,overflow:t?"auto":void 0,WebkitMaskImage:n?"linear-gradient(to bottom, black 60%, transparent 100%)":void 0,maskImage:n?"linear-gradient(to bottom, black 60%, transparent 100%)":void 0},children:l}),Jr=c.memo(function({children:t,actions:n,size:o,selected:l,disabled:i,disabledTooltip:s,saved:a,error:A,align:d,allowScroll:g,removePadding:p,fullHeight:h,onSelect:u,width:m,hideOverflow:b=!0,showExpandIcon:y=!0}){const[w,C]=cr(),E=c.useRef(null);f.useOutsideAlerter(E,()=>{l&&u&&u(void 0)},!!(l&&u));const[k,I]=c.useState(!1),x=c.useMemo(()=>gt(o),[o]),[B,N]=c.useState(!1),[F,Q]=c.useState(a),S=!i&&A;c.useEffect(()=>{a&&Q(!0);const W=setTimeout(()=>{Q(!1)},800);return()=>{clearTimeout(W)}},[a]);let T=0;if(!p)switch(o){case"l":case"xl":T=4;break;case"m":T=2;break;case"s":default:T=1;break}let V;switch(d){case"right":V="flex-end";break;case"center":V="center";break;case"left":default:V="flex-start"}const H=c.useCallback(()=>{if(!u)return;const W=E&&E?.current?.getBoundingClientRect();i?u(void 0):!l&&W&&u(W)},[E,u,l,i]),_=c.useCallback(W=>{H(),W.stopPropagation()},[H]);c.useEffect(()=>{if(C){const W=C.height>x;k!==W&&I(W)}},[C,k,x]);const j=!S&&l,te=!i&&g&&k,z=!i&&!g&&k,G=c.useCallback(()=>N(!0),[]),re=c.useCallback(()=>N(!1),[]);return r.jsxs("div",{ref:E,className:f.cn("transition-colors duration-100 ease-in-out",`flex relative h-full rounded-md p-${T} border border-4 border-opacity-75`,B&&!i?"bg-gray-50 dark:bg-gray-900":"",a?"bg-gray-100 bg-opacity-75 dark:bg-gray-800 dark:bg-opacity-75":"",!j&&!F&&!S?"border-transparent":"",b?"overflow-hidden":"",j?"bg-gray-50 dark:bg-gray-900":"",j&&!F?"border-primary":"",F?"border-green-500 ":"",S?"border-red-500":""),style:{justifyContent:V,alignItems:i||!k?"center":void 0,width:m??"100%",textAlign:d},tabIndex:l||i?void 0:0,onFocus:_,onMouseEnter:G,onMouseMove:G,onMouseLeave:re,children:[r.jsxs(ne,{children:[h&&!z&&t,(!h||z)&&r.jsx(ns,{fullHeight:h??!1,justifyContent:V,scrollable:te??!1,faded:z,children:!h&&r.jsx("div",{ref:w,style:{display:"flex",width:"100%",justifyContent:V,height:h?"100%":void 0},children:t})})]}),n,i&&B&&s&&r.jsx("div",{className:"absolute top-1 right-1 text-xs",children:r.jsx(f.Tooltip,{title:s,children:r.jsx(f.RemoveCircleIcon,{size:"smallest",color:"disabled",className:"text-gray-500"})})})]})},(e,t)=>e.error===t.error&&e.value===t.value&&e.disabled===t.disabled&&e.saved===t.saved&&e.allowScroll===t.allowScroll&&e.align===t.align&&e.size===t.size&&e.disabledTooltip===t.disabledTooltip&&e.width===t.width&&e.showExpandIcon===t.showExpandIcon&&e.removePadding===t.removePadding&&e.fullHeight===t.fullHeight&&e.selected===t.selected);function os(e){return e.dataType==="string"&&e.storage?!0:e.dataType==="array"?Array.isArray(e.of)?!1:e.of?.dataType==="string"&&e.of?.storage:!1}const ls=c.memo(function({propertyKey:t,customFieldValidator:n,value:o,property:l,align:i,width:s,height:a,path:A,entity:d,readonly:g,disabled:p}){const h=X(),{onValueChange:u,size:m,selectedCell:b,select:y,setPopupCell:w}=ws(),C=b?.propertyKey===t&&b?.entity.path===d.path&&b?.entity.id===d.id,[E,k]=c.useState(o),I=c.useRef(o),[x,B]=c.useState(),[N,F]=c.useState(!1),Q=c.useCallback(()=>{F(!0),setTimeout(()=>{F(!1)},100)},[]),S=!!l.Field,T=!!l.Preview,V=it(l),H=typeof l.disabled=="object"?l.disabled.disabledMessage:void 0,_=g||p||!!l.disabled,j=c.useMemo(()=>kt({property:l,entityId:d.id,customFieldValidator:n,name:t}),[d.id,l,t]);c.useEffect(()=>{oe(o,I.current)||(B(void 0),k(o),I.current=o,Q())},[Q,o]);const te=M=>{oe(M,I.current)||(F(!1),j.validate(M).then(()=>{B(void 0),I.current=M,u&&u({value:M,propertyKey:t,setError:B,onValueUpdated:Q,entity:d,fullPath:A,context:h})}).catch(D=>{B(D)}))};c.useEffect(()=>{j.validate(E).then(()=>B(void 0)).catch(M=>{B(M)})},[E,j,t,l,d]);const z=M=>{let D;M===void 0?D=null:D=M,k(D),te(D)};xe({property:l,value:E,setValue:z});const G=c.useCallback(M=>{y(M?{width:s,height:a,entity:d,cellRect:M,propertyKey:t}:void 0)},[d,a,t,y,s]),re=M=>{w&&w(M?{width:s,height:a,entity:d,cellRect:M,propertyKey:t}:void 0)};let W,q=!1,se=!1,U=!0,P=!1,$=!1,K=!0;const L=!_&&x;if(g||V)return r.jsx(Jr,{size:m,width:s,saved:N,value:E,align:i??"left",fullHeight:!1,disabledTooltip:H??(V?"Read only":void 0),disabled:!0,children:r.jsx(me,{width:s,height:gt(m),propertyKey:t,property:l,entity:d,value:E,size:Je(m)})},`${t}_${d.path}_${d.id}`);if(!S&&(!T||C)){if(os(l))W=r.jsx(_i,{error:x,disabled:_,focused:C,selected:C,openPopup:w?re:void 0,property:l,entity:d,path:A,value:E,previewSize:Je(m),updateValue:z,propertyKey:t}),K=!1,se=!0,$=!0,P=!0;else if(C&&l.dataType==="number"){const D=l;D.enumValues?(W=r.jsx(Wr,{name:t,multiple:!1,disabled:_,focused:C,valueType:"number",small:Je(m)!=="medium",enumValues:D.enumValues,error:x,internalValue:E,updateValue:z}),$=!0):(W=r.jsx(Pi,{align:i,error:x,focused:C,disabled:_,value:E,updateValue:z}),q=!0)}else if(C&&l.dataType==="string"){const D=l;if(D.enumValues)W=r.jsx(Wr,{name:t,multiple:!1,focused:C,disabled:_,valueType:"string",small:Je(m)!=="medium",enumValues:D.enumValues,error:x,internalValue:E,updateValue:z}),$=!0;else if(!D.storage){const Ie=!!D.multiline||!!D.markdown;W=r.jsx(Mi,{error:x,disabled:_,multiline:Ie,focused:C,value:E,updateValue:z}),q=!0}}else if(l.dataType==="boolean")W=r.jsx(Di,{error:x,disabled:_,focused:C,internalValue:E,updateValue:z});else if(l.dataType==="date")W=r.jsx(Oi,{name:t,error:x,disabled:_,mode:l.mode,focused:C,internalValue:E,updateValue:z}),$=!0,U=!1,q=!1;else if(l.dataType==="reference")typeof l.path=="string"&&(W=r.jsx(So,{name:t,internalValue:E,updateValue:z,disabled:_,size:m,path:l.path,multiselect:!1,previewProperties:l.previewProperties,title:l.name,forceFilter:l.forceFilter})),q=!1;else if(l.dataType==="array"){const D=l;if(!D.of&&!D.oneOf)throw Error(`You need to specify an 'of' or 'oneOf' prop (or specify a custom field) in your array property ${t}`);D.of&&!Array.isArray(D.of)&&(D.of.dataType==="string"||D.of.dataType==="number"?C&&D.of.enumValues&&(W=r.jsx(Wr,{name:t,multiple:!0,disabled:_,focused:C,small:Je(m)!=="medium",valueType:D.of.dataType,enumValues:D.of.enumValues,error:x,internalValue:E,updateValue:z}),q=!0,$=!0,U=!1):D.of.dataType==="reference"&&(typeof D.of.path=="string"&&(W=r.jsx(So,{name:t,disabled:_,internalValue:E,updateValue:z,size:m,multiselect:!0,path:D.of.path,previewProperties:D.of.previewProperties,title:D.of.name,forceFilter:D.of.forceFilter})),q=!1))}}return W||(q=!1,se=C&&!W&&!_&&!V,W=r.jsx(me,{width:s,height:a,entity:d,propertyKey:t,value:E,property:l,size:Je(m)})),r.jsx(Jr,{size:m,width:s,onSelect:G,selected:C,disabled:_||V,disabledTooltip:H??"Disabled",removePadding:P,fullHeight:$,saved:N,error:x,align:i,allowScroll:q,showExpandIcon:se,value:E,hideOverflow:U,actions:K&&r.jsx(Io,{showError:L,disabled:_,showExpandIcon:se,selected:C,openPopup:_?void 0:re}),children:W},`cell_${t}_${d.path}_${d.id}`)},is);function is(e,t){return e.height===t.height&&e.propertyKey===t.propertyKey&&e.align===t.align&&e.width===t.width&&oe(e.property,t.property)&&oe(e.value,t.value)&&oe(e.entity.id,t.entity.id)&&oe(e.entity.values,t.entity.values)}function xt({text:e,...t}){return r.jsx("div",{className:"flex w-full h-screen max-h-full max-w-full bg-gray-50 dark:bg-gray-900 gap-4",children:r.jsxs("div",{className:"m-auto flex flex-col gap-2 items-center",children:[r.jsx(f.CircularProgress,{...t}),e&&r.jsx(f.Typography,{color:"secondary",variant:"caption",className:"text-center",children:e})]})})}const ss=c.memo(function({resizeHandleRef:t,columnIndex:n,isResizingIndex:o,sort:l,onColumnSort:i,onFilterUpdate:s,filter:a,column:A,onClickResizeColumn:d,createFilterField:g,AdditionalHeaderWidget:p}){const[h,u]=c.useState(!1),[m,b]=c.useState(!1),[y,w]=c.useState(!1),C=c.useCallback(B=>{b(!0)},[]),E=c.useCallback((B,N)=>{s(A,B),N!==void 0&&b(N)},[A,s]),k=o===n,x=!(o!==n&&o>0)&&(h||k);return r.jsx(ne,{children:r.jsxs("div",{className:f.cn("flex py-0 px-3 h-full text-xs uppercase font-semibold relative select-none items-center bg-gray-50 dark:bg-gray-900","text-gray-600 hover:text-gray-800 dark:text-gray-400 dark:hover:text-gray-200 ","hover:bg-gray-100 dark:hover:bg-gray-800 hover:bg-opacity-50 dark:hover:bg-opacity-50",A.frozen?"sticky left-0 z-10":"relative z-0"),style:{left:A.frozen?0:void 0,minWidth:A.width,maxWidth:A.width},onMouseEnter:()=>u(!0),onMouseMove:()=>u(!0),onMouseLeave:()=>u(!1),children:[r.jsx("div",{className:"overflow-hidden flex-grow",children:r.jsxs("div",{className:`flex items-center justify-${A.headerAlign} flex-row`,children:[A.icon&&A.icon(h||m),r.jsx("div",{className:"truncate -webkit-box w-full mx-1 overflow-hidden",style:{WebkitBoxOrient:"vertical",WebkitLineClamp:2,justifyContent:A.align},children:A.title})]})}),r.jsxs(r.Fragment,{children:[p&&r.jsx(p,{onHover:h||m}),A.sortable&&(l||x||m)&&r.jsx(f.Badge,{color:"secondary",invisible:!l,children:r.jsxs(f.IconButton,{size:"small",className:h||m?"bg-white dark:bg-gray-950":void 0,onClick:()=>{i(A.key)},children:[!l&&r.jsx(f.ArrowUpwardIcon,{}),l==="asc"&&r.jsx(f.ArrowUpwardIcon,{}),l==="desc"&&r.jsx(f.ArrowUpwardIcon,{className:"rotate-180"})]})})]}),A.filter&&g&&r.jsx("div",{children:r.jsx(f.Badge,{color:"secondary",invisible:!a,children:r.jsx(f.Popover,{open:m,onOpenChange:b,className:y?"hidden":void 0,modal:!0,trigger:r.jsx(f.IconButton,{className:h||m?"bg-white dark:bg-gray-950":void 0,size:"small",onClick:C,children:r.jsx(f.FilterListIcon,{size:"small"})}),children:r.jsx(as,{column:A,filter:a,onHover:h,onFilterUpdate:E,createFilterField:g,hidden:y,setHidden:w})})})}),A.resizable&&r.jsx("div",{ref:t,className:f.cn("absolute h-full w-[6px] top-0 right-0 cursor-col-resize",x&&"bg-gray-300 dark:bg-gray-700"),onMouseDown:d?()=>d(n,A):void 0})]})})},oe);function as({column:e,onFilterUpdate:t,filter:n,onHover:o,createFilterField:l,hidden:i,setHidden:s}){const a=e.key,[A,d]=c.useState(n);if(c.useEffect(()=>{d(n)},[n]),!e.filter)return null;const g=()=>{t(A,!1)},p=m=>{t(void 0,!1)},h=!!n,u=l({id:a,filterValue:A,setFilterValue:d,column:e,hidden:i,setHidden:s});return u?r.jsxs("div",{className:"text-gray-900 dark:text-white",children:[r.jsx("div",{className:f.cn(f.defaultBorderMixin,"py-4 px-6 text-xs font-semibold uppercase border-b"),children:e.title??a}),u&&r.jsx("div",{className:"m-4",children:u}),r.jsxs("div",{className:"flex justify-end m-4",children:[r.jsx(f.Button,{className:"mr-4",disabled:!h,variant:"text",color:"primary",type:"reset","aria-label":"filter clear",onClick:p,children:"Clear"}),r.jsx(f.Button,{variant:"outlined",color:"primary",onClick:g,children:"Filter"})]})]}):null}const cs=({columns:e,currentSort:t,onColumnSort:n,onFilterUpdate:o,sortByProperty:l,filter:i,onColumnResize:s,onColumnResizeEnd:a,createFilterField:A,AddColumnComponent:d})=>{const g=e.map(()=>c.createRef()),[p,h]=c.useState(-1),u=c.useCallback((I,x,B)=>{const N=e[I],F=100,Q=800,S=x>Q?Q:x<F?F:x,T={width:S,key:N.key,column:{...N,width:S}};B?a(T):s(T)},[e,s,a]),m=c.useCallback(I=>{if(p>=0){const x=g[p].current?.parentElement?.getBoundingClientRect().left;return x?I.clientX-x:void 0}},[g,p]),b=c.useCallback(I=>{document.body.style.cursor=I?"col-resize":"auto"},[]),y=c.useCallback(I=>{I.stopPropagation(),I.preventDefault();const x=m(I);x&&u(p,x,!1)},[u,m,p]),w=c.useCallback(I=>{I.stopPropagation(),I.preventDefault();const x=m(I);x&&u(p,x,!0),h(-1),b(!1)},[u,m,p,b]),C=c.useCallback(()=>{document.removeEventListener("mousemove",y),document.removeEventListener("mouseup",w)},[y,w]),E=c.useCallback(()=>{document.addEventListener("mousemove",y),document.addEventListener("mouseup",w)},[y,w]);c.useEffect(()=>(p>=0?E():C(),()=>{C()}),[E,p,C]);const k=c.useCallback(I=>{h(I),b(!0)},[b]);return r.jsxs("div",{className:f.cn(f.defaultBorderMixin,"z-20 sticky min-w-full flex w-fit flex-row top-0 left-0 h-12 border-b bg-gray-50 dark:bg-gray-900"),children:[e.map((I,x)=>{const B=e[x],N=B&&i&&i[B.key]?i[B.key]:void 0;return r.jsx(ne,{children:r.jsx(ss,{resizeHandleRef:g[x],columnIndex:x,isResizingIndex:p,onFilterUpdate:o,filter:N,sort:l===B.key?t:void 0,onColumnSort:n,onClickResizeColumn:k,column:B,createFilterField:A,AdditionalHeaderWidget:B.AdditionalHeaderWidget})},"header_"+B.key)}),d&&r.jsx(d,{})]})},As=c.memo(function({rowData:t,rowIndex:n,children:o,onRowClick:l,size:i,style:s,hoverRow:a,rowClassName:A}){const d=c.useCallback(g=>{console.debug("VirtualTableRow click"),l&&l({rowData:t,rowIndex:n,event:g})},[l,t,n]);return r.jsx("div",{className:f.cn("flex min-w-full text-sm border-b border-gray-200 dark:border-gray-800 border-opacity-40 dark:border-opacity-40",A?A(t):"",{"hover:bg-opacity-95":a,"cursor-pointer":l}),onClick:d,style:{...s,height:gt(i),width:"fit-content"},children:o})},oe),ds=c.memo(function(t){return t.rowData&&t.cellRenderer({cellData:t.cellData,rowData:t.rowData,rowIndex:t.rowIndex,isScrolling:!1,column:t.column,columns:t.columns,columnIndex:t.columnIndex,width:t.column.width})},(e,t)=>oe(e,t)),Kt=c.createContext({});Kt.displayName="VirtualListContext";const fs=c.forwardRef(({children:e,...t},n)=>r.jsx(Kt.Consumer,{children:o=>{const l=o.customView;return r.jsxs(r.Fragment,{children:[r.jsx("div",{id:"virtual-table",style:{position:"relative",height:"100%"},children:r.jsxs("div",{ref:n,...t,style:{...t?.style,minHeight:"100%",position:"relative"},children:[r.jsx(cs,{...o}),!l&&e]})}),l&&r.jsx("div",{style:{position:"sticky",top:"56px",flexGrow:1,height:"calc(100% - 56px)",marginTop:"calc(56px - 100vh)",left:0},children:l})]})}})),No=c.memo(function({data:t,onResetPagination:n,onEndReached:o,size:l="m",columns:i,onRowClick:s,onColumnResize:a,filter:A,checkFilterCombination:d,onFilterUpdate:g,sortBy:p,error:h,emptyComponent:u,onSortByUpdate:m,loading:b,cellRenderer:y,hoverRow:w,createFilterField:C,rowClassName:E,className:k,endAdornment:I,AddColumnComponent:x}){const B=p?p[0]:void 0,N=p?p[1]:void 0,[F,Q]=c.useState(i),S=c.useRef(null),T=c.useRef(0);c.useEffect(()=>{Q(i)},[i]);const[V,H]=cr(),_=c.useCallback(M=>{Q(F.map(D=>D.key===M.column.key?M.column:D))},[F]),j=c.useCallback(M=>{Q(F.map(D=>D.key===M.column.key?M.column:D)),a&&a(M)},[F,a]),te=c.useRef();c.useEffect(()=>{te.current=A},[A]);const z=c.useCallback(()=>{T.current=0,S.current&&S.current.scrollTo(S.current?.scrollLeft,0)},[]),G=c.useCallback(M=>{const D=B===M&&N==="desc",de=B===M&&N==="asc"?"desc":D?void 0:"asc",ae=D?void 0:M,Se=te.current,qe=de&&ae?[ae,de]:void 0;Se&&d&&!d(Se,qe)&&g&&g(void 0),n&&n(),m&&m(qe),z()},[d,N,g,n,m,z,B]),re=c.useCallback(()=>{T.current=0,m&&m(void 0)},[m]),W=Math.max((t?.length??0)*gt(l)-H.height,0),q=c.useCallback(M=>{o&&(t?.length??0)>0&&M>T.current+600&&(T.current=M,o())},[t?.length,o]),se=c.useCallback(({scrollOffset:M,scrollUpdateWasRequested:D})=>{!D&&M>=W-600&&q(M)},[W,q]),U=c.useCallback((M,D)=>{T.current=0;const Ie=te.current;let de=Ie?{...Ie}:{};D?de[M.key]=D:delete de[M.key],!d||d(de,B&&N?[B,N]:void 0)||(de=D?{[M.key]:D}:{}),g&&g(de),M.key!==B&&re()},[d,N,g,re,B]),P=c.useCallback(()=>r.jsxs("div",{className:"h-full flex flex-col items-center justify-center sticky left-0",children:[r.jsx(f.Typography,{variant:"h6",children:"Error fetching data from the data source"}),h?.message&&r.jsx(f.Markdown,{className:"px-4 break-all",source:h.message})]}),[h?.message]),$=c.useCallback(()=>b?r.jsx(xt,{}):r.jsxs("div",{className:"flex flex-col overflow-auto items-center justify-center p-2 gap-2 h-full",children:[r.jsx(f.AssignmentIcon,{}),u]}),[u,b]),K=!b&&(t?.length??0)===0,L=h?P():K?$():void 0;return r.jsx("div",{ref:V,className:f.cn("h-full w-full",k),children:r.jsx(Kt.Provider,{value:{data:t,size:l,cellRenderer:y,columns:F,currentSort:N,onRowClick:s,customView:L,onColumnResize:_,onColumnResizeEnd:j,filter:te.current,onColumnSort:G,onFilterUpdate:U,sortByProperty:B,hoverRow:w??!1,createFilterField:C,rowClassName:E,endAdornment:I,AddColumnComponent:x},children:r.jsx(us,{outerRef:S,width:H.width,height:H.height,itemCount:(t?.length??0)+(I?1:0),onScroll:se,includeAddColumn:!!x,itemSize:gt(l)},l)})})},oe);function us({outerRef:e,width:t,height:n,itemCount:o,onScroll:l,itemSize:i,includeAddColumn:s}){const a=c.useCallback(({index:A,style:d})=>r.jsx(Kt.Consumer,{children:({onRowClick:g,data:p,columns:h,size:u="m",cellRenderer:m,hoverRow:b,rowClassName:y,endAdornment:w})=>{if(w&&A===(p??[]).length)return r.jsx("div",{style:{...d,height:"auto",position:"sticky",bottom:0,zIndex:1},children:w});const C=p&&p[A];return r.jsxs(As,{rowData:C,rowIndex:A,onRowClick:g,columns:h,hoverRow:b,rowClassName:y,style:{...d,top:`calc(${d.top}px + 48px)`},size:u,children:[h.map((E,k)=>{const I=C&&C[E.key];return r.jsx(ds,{dataKey:E.key,cellRenderer:m,column:E,columns:h,rowData:C,cellData:I,rowIndex:A,columnIndex:k},`cell_${E.key}`)}),s&&r.jsx("div",{className:"w-20"})]},`row_${A}`)}}),[]);return r.jsx(wl.FixedSizeList,{outerRef:e,innerElementType:fs,width:t,height:n,overscanCount:4,itemCount:o,onScroll:l,itemSize:i,children:a})}const qr=c.memo(function({entity:t,collection:n,fullPath:o,width:l,frozen:i,isSelected:s,selectionEnabled:a,size:A,highlightEntity:d,onCollectionChange:g,unhighlightEntity:p,actions:h=[],hideId:u,selectionController:m}){const b=Te(),y=X(),w=c.useCallback(B=>{m?.toggleEntitySelection(t)},[t,m?.toggleEntitySelection]),C=c.useCallback(B=>{B.stopPropagation(),m?.toggleEntitySelection(t)},[t,m?.toggleEntitySelection]),E=h.length>0,k=h.some(B=>B.collapsed||B.collapsed===void 0),I=h.filter(B=>B.collapsed||B.collapsed===void 0),x=h.filter(B=>B.collapsed===!1);return r.jsxs("div",{onClick:C,className:f.cn("h-full flex items-center justify-center flex-col bg-gray-50 dark:bg-gray-900 bg-opacity-90 dark:bg-opacity-90 z-10",i?"sticky left-0":""),style:{width:l,position:i?"sticky":"initial",left:i?0:"initial",contain:"strict"},children:[(E||a)&&r.jsxs("div",{className:"w-34 flex justify-center",children:[x.map((B,N)=>r.jsx(f.Tooltip,{title:B.name,children:r.jsx(f.IconButton,{onClick:F=>{F.stopPropagation(),B.onClick({entity:t,fullPath:o,collection:n,context:y,selectionController:m,highlightEntity:d,unhighlightEntity:p,onCollectionChange:g})},size:b?"medium":"small",children:B.icon})},N)),k&&r.jsx(f.Menu,{trigger:r.jsx(f.IconButton,{size:b?"medium":"small",children:r.jsx(f.MoreVertIcon,{})}),children:I.map((B,N)=>r.jsxs(f.MenuItem,{onClick:F=>{F.stopPropagation(),B.onClick({entity:t,fullPath:o,collection:n,context:y,selectionController:m,highlightEntity:d,unhighlightEntity:p,onCollectionChange:g})},children:[B.icon,B.name]},N))}),a&&r.jsx(f.Tooltip,{title:`Select ${t.id}`,children:r.jsx(f.Checkbox,{size:b?"medium":"small",checked:s,onCheckedChange:w})})]}),!u&&A!=="xs"&&r.jsx("div",{className:"w-[138px] text-center overflow-hidden truncate",children:t?r.jsxs(f.Typography,{onClick:B=>{B.stopPropagation()},className:"font-mono select-all",variant:"caption",color:"secondary",children:[" ",t.id," "]}):r.jsx(f.Skeleton,{})})]})},oe);function gs(e){const t=Te(),n=!e.forceFilter&&e.filterIsSet&&e.clearFilter&&r.jsxs(f.Button,{variant:"outlined",className:"h-fit-content","aria-label":"filter clear",onClick:e.clearFilter,size:"small",children:[r.jsx(f.FilterListOffIcon,{}),"Clear filter"]}),o=r.jsx(f.Select,{value:e.size,className:"w-16 h-10",size:"small",onValueChange:l=>e.onSizeChanged(l),renderValue:l=>r.jsx("div",{className:"font-medium",children:l.toUpperCase()}),children:["xs","s","m","l","xl"].map(l=>r.jsx(f.SelectItem,{value:l,className:"w-12 font-medium text-center",children:l.toUpperCase()},l))});return r.jsxs("div",{className:f.cn(f.defaultBorderMixin,"no-scrollbar min-h-[56px] overflow-x-auto px-4 bg-gray-50 dark:bg-gray-900 border-b flex flex-row justify-between items-center w-full"),children:[r.jsxs("div",{className:"flex items-center gap-2",children:[e.title&&r.jsx("div",{className:"hidden lg:block",children:e.title}),o,e.actionsStart,n]}),r.jsxs("div",{className:"flex items-center gap-2",children:[t&&r.jsx("div",{className:"w-[22px]",children:e.loading&&r.jsx(f.CircularProgress,{size:"small"})}),e.onTextSearch&&r.jsx(f.SearchBar,{onTextSearch:e.onTextSearch,expandable:!0},"search-bar"),e.actions]})]})}const Qo={"==":"==","!=":"!=",">":">","<":"<",">=":">=","<=":"<=",in:"In","not-in":"Not in","array-contains":"Contains","array-contains-any":"Contains Any"},Zr=["array-contains-any","in","not-in"];function hs({name:e,value:t,setValue:n,isArray:o,path:l,title:i,previewProperties:s,setHidden:a}){const A=o?["array-contains"]:["==","!=",">","<",">=","<="],[d,g]=c.useState(!1);o?A.push("array-contains-any"):A.push("in","not-in");const[p,h]=t||[A[0],void 0],[u,m]=c.useState(p),[b,y]=c.useState(h),w=b?Array.isArray(b)?b.map(S=>S instanceof Pe?S.id:null).filter(Boolean):[b.id]:[];function C(S,T){const V=Zr.includes(u),H=Zr.includes(S);let _=T;V!==H&&(_=H?_ instanceof Pe?[_]:[]:void 0),m(S),y(_);const j=_!==null&&Array.isArray(_)?_.length>0:_!==void 0;n(S&&j?[S,_]:void 0)}const E=ie(),k=c.useMemo(()=>l?E.getCollection(l):void 0,[l]),I=S=>{C(u,et(S))},x=S=>{C(u,S.map(T=>et(T)))},B=Zr.includes(u),N=St({multiselect:B,path:l,collection:k,onSingleEntitySelected:I,onMultipleEntitiesSelected:x,selectedEntityIds:w,onClose:()=>{a(!1)}}),F=()=>{a(!0),N.open()},Q=S=>r.jsx("div",{className:"mb-0.5",onMouseEnter:()=>g(!0),onMouseMove:()=>g(!0),onMouseLeave:()=>g(!1),children:r.jsx(Ge,{disabled:!l,previewProperties:s,size:"medium",onClick:F,reference:S,onHover:d,allowEntityNavigation:!1})});return console.log("ReferenceFilterField",{internalValue:b}),r.jsxs("div",{className:"flex w-[440px] flex-row",children:[r.jsx("div",{className:"w-[120px]",children:r.jsx(f.Select,{value:u,onValueChange:S=>{C(S,b)},renderValue:S=>Qo[S],children:A.map(S=>r.jsx(f.SelectItem,{value:S,children:Qo[S]},S))})}),r.jsxs("div",{className:"flex-grow ml-2 h-full",children:[b&&Array.isArray(b)&&r.jsx("div",{children:b.map((S,T)=>Q(S))}),b&&!Array.isArray(b)&&r.jsx("div",{children:Q(b)}),(!b||Array.isArray(b)&&b.length===0)&&r.jsx(f.Button,{onClick:F,variant:"outlined",className:"h-full w-full",children:B?"Select references":"Select reference"})]})]})}const To={"==":"==","!=":"!=",">":">","<":"<",">=":">=","<=":"<=",in:"In","not-in":"Not in","array-contains":"Contains","array-contains-any":"Any"},Xr=["array-contains-any","in","not-in"];function ps({name:e,value:t,setValue:n,dataType:o,isArray:l,enumValues:i,title:s}){const a=l?["array-contains"]:["==","!=",">","<",">=","<="];i&&(l?a.push("array-contains-any"):a.push("in","not-in"));const[A,d]=t||[a[0],void 0],[g,p]=c.useState(A),[h,u]=c.useState(d);function m(y,w){let C=w;const E=Xr.includes(g),k=Xr.includes(y);E!==k&&(C=k?typeof w=="string"||typeof w=="number"?[w]:[]:""),typeof C=="number"&&isNaN(C)&&(C=void 0),p(y),u(C);const I=C!==null&&Array.isArray(C)?C.length>0:C!==void 0;n(y&&I?[y,C]:void 0)}const b=Xr.includes(g);return r.jsxs("div",{className:"flex w-[440px] items-center",children:[r.jsx("div",{className:"w-[80px]",children:r.jsx(f.Select,{value:g,position:"item-aligned",onValueChange:y=>{m(y,h)},renderValue:y=>To[y],children:a.map(y=>r.jsx(f.SelectItem,{value:y,children:To[y]},y))})}),r.jsxs("div",{className:"flex-grow ml-2",children:[!i&&r.jsx(f.TextField,{type:o==="number"?"number":void 0,value:h!==void 0?String(h):"",onChange:y=>{const w=o==="number"?parseFloat(y.target.value):y.target.value;m(g,w)},endAdornment:h&&r.jsx(f.IconButton,{className:"absolute right-3 top-2",onClick:y=>m(g,void 0),children:r.jsx(f.ClearIcon,{})})}),i&&r.jsx(f.Select,{position:"item-aligned",value:h!==void 0?Array.isArray(h)?h.map(y=>String(y)):String(h):l?[]:"",onValueChange:y=>{m(g,o==="number"?parseInt(y):y)},multiple:b,endAdornment:h&&r.jsx(f.IconButton,{className:"absolute right-3 top-2",onClick:y=>m(g,void 0),children:r.jsx(f.ClearIcon,{})}),renderValue:y=>r.jsx(we,{enumKey:y,enumValues:i,size:"small"},`select_value_${e}_${y}`),children:i.map(y=>r.jsx(f.SelectItem,{value:String(y.id),children:r.jsx(we,{enumKey:String(y.id),enumValues:i,size:"small"})},`select_value_${e}_${y.id}`))})]})]})}function ms({name:e,title:t,value:n,setValue:o}){function l(a){o(a!==void 0?["==",a]:void 0)}const i=n&&n[1],s=!!n;return r.jsx("div",{className:"w-[200px]",children:r.jsx(f.BooleanSwitchWithLabel,{value:i,allowIndeterminate:!0,onValueChange:a=>l(a===null?void 0:a),label:s?i?`${t} is true`:`${t} is false`:"No filter"})})}const Mo={"==":"==","!=":"!=",">":">","<":"<",">=":">=","<=":"<=","not-in":"not in",in:"in","array-contains":"Contains","array-contains-any":"Any"},Po=["array-contains-any","in"];function bs({name:e,isArray:t,mode:n,value:o,setValue:l,title:i}){const{locale:s}=X(),a=t?["array-contains"]:["==","!=",">","<",">=","<="],[A,d]=o||[a[0],void 0],[g,p]=c.useState(A),[h,u]=c.useState(d);function m(b,y){let w=y;const C=Po.includes(g),E=Po.includes(b);C!==E&&(w=E?y?[y]:[]:""),p(b),u(w===null?void 0:w);const k=w!==null&&Array.isArray(w)?w.length>0:w!==void 0;l(b&&k?[b,w]:void 0)}return r.jsxs("div",{className:"flex w-[440px] items-center",children:[r.jsx("div",{className:"w-[80px]",children:r.jsx(f.Select,{value:g,onValueChange:b=>{m(b,h)},renderValue:b=>Mo[b],children:a.map(b=>r.jsx(f.SelectItem,{value:b,children:Mo[b]},b))})}),r.jsx("div",{className:"flex-grow ml-2",children:r.jsx(f.DateTimeField,{mode:n,size:"medium",locale:s,value:h,onChange:b=>{m(g,b===null?void 0:b)},clearable:!0})})]})}const Do="collectionGroupParent";function Oo(e,t){return c.useMemo(()=>e.propertiesOrder?Vo(e,e.propertiesOrder):ys(e,t),[e,t])}function Vo(e,t){return t.flatMap(n=>{const o=e.properties[n];return o?o.hideFromCollection?[null]:o.disabled&&typeof o.disabled=="object"&&o.disabled.hidden?[null]:o.dataType==="map"&&o.spreadChildren&&o.properties?Kr(o,n):[{key:n,disabled:!!o.disabled||!!o.readOnly}]:e.additionalFields?.find(i=>i.key===n)?[{key:n,disabled:!0}]:e.subcollections&&e.subcollections.find(s=>_r(s)===n)?[{key:n,disabled:!0}]:e.collectionGroup&&n===Do?[{key:n,disabled:!0}]:[null]}).filter(Boolean)}function ys(e,t){const n=Object.keys(e.properties),o=e.additionalFields??[],l=e.subcollections??[],i=[...n,...o.map(s=>s.key)];if(t){const s=l.map(a=>_r(a));i.push(...s.filter(a=>!i.includes(a)))}return e.collectionGroup&&i.push(Do),Vo(e,i)}function Kr(e,t,n){return e.dataType==="map"&&e.spreadChildren&&e.properties?Object.entries(e.properties).flatMap(([o,l])=>Kr(l,`${t}.${o}`,n||!!e.disabled||!!e.readOnly)):[{key:t,disabled:n||!!e.disabled||!!e.readOnly}]}const vs={},Go=c.createContext(vs),ws=()=>c.useContext(Go),Rr=c.memo(function({forceFilter:t,actionsStart:n,actions:o,title:l,tableRowActionsBuilder:i,uniqueFieldValidator:s,getPropertyFor:a,onValueChange:A,selectionController:d,highlightedEntities:g,onEntityClick:p,onColumnResize:h,onSizeChanged:u,textSearchEnabled:m=!1,hoverRow:b=!0,inlineEditing:y=!1,additionalFields:w,displayedColumnIds:C,defaultSize:E,properties:k,tableController:{data:I,dataLoading:x,noMoreToLoad:B,dataLoadingError:N,filterValues:F,setFilterValues:Q,sortBy:S,setSortBy:T,setSearchString:V,clearFilter:H,itemCount:_,setItemCount:j,pageSize:te=50,paginationEnabled:z,checkFilterCombination:G,setPopupCell:re},filterable:W=!0,sortable:q=!0,endAdornment:se,AddColumnComponent:U,AdditionalHeaderWidget:P,additionalIDHeaderWidget:$,emptyComponent:K,getIdColumnWidth:L}){const M=Te(),D=!!t,Ie=d?.selectedEntities?.length>0?d?.selectedEntities:g,de=X(),[ae,Se]=c.useState(E??"m"),[qe,Ye]=c.useState(void 0),Oe=Ie?.map(J=>J.id),Ft=!!F&&Object.keys(F).length>0,mt=()=>{!z||x||B||_!==void 0&&j?.(_+te)},Nt=c.useCallback(()=>{j?.(te)},[te]),Ze=c.useCallback(({rowData:J})=>{if(console.debug("EntityCollectionTable click"),!y)return p&&p(J)},[p,y]),Xe=c.useCallback(J=>{u&&u(J),Se(J)},[]),Qt=c.useCallback(J=>V?.(J),[]),Ke=c.useMemo(()=>w?w.map(J=>({[J.key]:J})).reduce((J,ge)=>({...J,...ge}),{}):{},[w]);c.useEffect(()=>{const J=ge=>{ge.keyCode===27&&Mt()};return document.addEventListener("keydown",J,!1),()=>{document.removeEventListener("keydown",J,!1)}});const Tt=c.useCallback(J=>{Ye(J)},[]),Mt=c.useCallback(()=>{Ye(void 0)},[]),Y=s,O=c.useCallback(({column:J,columnIndex:ge,rowData:Ae,rowIndex:Me})=>{const le=Ae,ze=J.key;let Ue=J.custom?.disabled;const bn=le.values?Le(le.values,ze):void 0,ot=a?.({propertyKey:ze,propertyValue:bn,entity:le})??J.custom.resolvedProperty;return ot?.disabled||(Ue=!1),ot?r.jsx(ne,{children:le?r.jsx(ls,{readonly:!y,align:J.align??"left",propertyKey:ze,property:ot,value:le?.values?Le(le.values,ze):void 0,customFieldValidator:Y,columnIndex:ge,width:J.width,height:gt(ae),entity:le,disabled:Ue,path:le.path},`property_table_cell_${le.id}_${ze}`):Ve()}):null},[Y,y,ae,Oe]),Z=c.useCallback(({column:J,rowData:ge,width:Ae})=>{const Me=ge,le=Ke[J.key],ze=le.dependencies?Object.entries(Me.values).filter(([ot,bl])=>le.dependencies.includes(ot)).reduce((ot,bl)=>({...ot,...bl}),{}):Me,Ue=le.Builder;if(!Ue&&!le.value)throw new Error("When using additional fields you need to provide a Builder or a value");const bn=Ue?r.jsx(Ue,{entity:Me,context:de}):r.jsx(r.Fragment,{children:le.value?.({entity:Me,context:de})});return r.jsx(Jr,{width:Ae,size:ae,value:ze,selected:!1,disabled:!0,align:"left",allowScroll:!1,showExpandIcon:!1,disabledTooltip:"This column can't be edited directly",children:r.jsx(ne,{children:bn})},`additional_table_cell_${Me.id}_${J.key}`)},[Ke,ae,Oe]),R=c.useMemo(()=>{const J=Object.entries(k).flatMap(([Ae,Me])=>Kr(Me,Ae)).map(({key:Ae,disabled:Me})=>{const le=xr(k,Ae);if(!le)throw Error("Internal error: no property found in path "+Ae);const ze=Yo(le);return{key:Ae,align:Ti(le),icon:Ue=>he(le,"small"),title:le.name??Ae,sortable:q&&(t?Object.keys(t).includes(Ae):!0),filter:!D&&ze,width:vo(le),resizable:!0,custom:{resolvedProperty:le,disabled:Me},AdditionalHeaderWidget:({onHover:Ue})=>P?r.jsx(P,{property:le,propertyKey:Ae,onHover:Ue}):void 0}}),ge=w?w.map(Ae=>({key:Ae.key,align:"left",sortable:!1,title:Ae.name,width:Ae.width??200})):[];return[...J,...ge]},[w,D,t,k,q]),ee=c.useMemo(()=>({key:"id_ewcfedcswdf3",width:L?.()??(M?160:130),title:"ID",resizable:!1,frozen:M,headerAlign:"center",align:"center",AdditionalHeaderWidget:()=>$}),[L,M]),ce=c.useMemo(()=>[ee,...C.map(J=>R.find(ge=>ge.key===J.key)).filter(Boolean)],[R,C,ee]),De=c.useCallback(J=>{const ge=J.column,Ae=J.columns,Me=ge.key;if(J.columnIndex===0)return i?i({entity:J.rowData,size:ae,width:ge.width,frozen:ge.frozen}):r.jsx(qr,{entity:J.rowData,width:ge.width,frozen:ge.frozen,isSelected:!1,size:ae});if(Ke[Me])return Z(J);if(J.columnIndex<Ae.length+1)return O(J);throw Error("Internal: columns not mapped properly")},[Ke,i,ae,Z,O]),Pt=c.useCallback(J=>{Q?.({...J,...t})},[t]);return r.jsx(Go.Provider,{value:{setPopupCell:re,select:Tt,onValueChange:A,size:ae,selectedCell:qe,selectedEntityIds:Oe},children:r.jsxs("div",{className:"h-full w-full flex flex-col bg-white dark:bg-gray-950",children:[r.jsx(gs,{forceFilter:D,filterIsSet:Ft,onTextSearch:m?Qt:void 0,clearFilter:H,size:ae,onSizeChanged:Xe,title:l,actionsStart:n,actions:o,loading:x}),r.jsx(No,{data:I,columns:ce,cellRenderer:De,onRowClick:y?void 0:p?Ze:void 0,onEndReached:mt,onResetPagination:Nt,error:N,paginationEnabled:z,onColumnResize:h,size:ae,loading:x,filter:F,onFilterUpdate:Q?Pt:void 0,sortBy:S,onSortByUpdate:T,hoverRow:b,emptyComponent:K,checkFilterCombination:G,createFilterField:W?Cs:void 0,rowClassName:c.useCallback(J=>Oe?.includes(J.id)?"bg-gray-100 bg-opacity-75 dark:bg-gray-800 dark:bg-opacity-75":"",[Oe]),className:"flex-grow",endAdornment:se,AddColumnComponent:U})]})})},oe);function Cs({id:e,filterValue:t,setFilterValue:n,column:o,hidden:l,setHidden:i}){if(!o.custom)return null;const{resolvedProperty:s}=o.custom,a=s?.dataType==="array",A=a?s.of:s;if(!A)return null;if(A.dataType==="reference")return r.jsx(hs,{value:t,setValue:n,name:e,isArray:a,path:A.path,title:s?.name,previewProperties:A?.previewProperties,hidden:l,setHidden:i});if(A.dataType==="number"||A.dataType==="string"){const d=A.name,g=A.enumValues?$e(A.enumValues):void 0;return r.jsx(ps,{value:t,setValue:n,name:e,dataType:A.dataType,isArray:a,enumValues:g,title:d})}else if(A.dataType==="boolean"){const d=A.name;return r.jsx(ms,{value:t,setValue:n,name:e,title:d})}else if(A.dataType==="date"){const d=A.name;return r.jsx(bs,{value:t,setValue:n,name:e,mode:A.mode,isArray:a,title:d})}return r.jsx("div",{children:`Currently the filter field ${s.dataType} is not supported`})}function Yo(e,t=!1){return t?["string","number","date","reference"].includes(e.dataType):e.dataType==="array"?e.of?Yo(e.of,!0):!1:["string","number","boolean","date","reference","array"].includes(e.dataType)}function Es({data:e,entitiesDisplayedFirst:t}){if(!t)return e;const n=new Set(t.map(o=>o.id));return[...t,...e.filter(o=>!n.has(o.id))]}function Bs(e,t,n=5e3){const[o,l]=c.useState(e),i=c.useRef(o.length??0),s=c.useRef(!1),a=c.useRef(t),A=!oe(a.current,t),d=e.length>=i.current||A;return c.useEffect(()=>{const g=()=>{oe(o,e)||(a.current=t,i.current=e.length,l(e)),s.current=!1};s.current=!0;let p;return d?g():p=setTimeout(g,n),()=>{clearTimeout(p),s.current&&d&&g()}},[e,n,t,d]),d?e:o}const ks=50;function en({fullPath:e,collection:t,entitiesDisplayedFirst:n,lastDeleteTimestamp:o,forceFilter:l}){const{initialFilter:i,initialSort:s,forceFilter:a}=t,[A,d]=c.useState(void 0),g=ie(),p=Qe(),h=c.useMemo(()=>g.resolveAliasesFrom(e),[e,g.resolveAliasesFrom]),u=l??a,m=t.pagination===void 0||!!t.pagination,b=typeof t.pagination=="number"?t.pagination:ks,[y,w]=c.useState(),[C,E]=c.useState(m?b:void 0),k=c.useCallback((z,G)=>p.isFilterCombinationValid?p.isFilterCombinationValid({path:h,collection:t,filterValues:z,sortBy:G}):!0,[]),I=c.useMemo(()=>{if(s&&u&&!k(u,s)){console.warn("Initial sort is not compatible with the force filter. Ignoring initial sort");return}return s},[s,u]),[x,B]=c.useState(u??i??void 0),[N,F]=c.useState(I),Q=c.useCallback(()=>B(u??void 0),[u]),S=c.useCallback(z=>{if(u){console.warn("Filter is not compatible with the force filter. Ignoring filter");return}z&&Object.keys(z).length===0?B(void 0):B(z)},[u]),{data:T,dataLoading:V,noMoreToLoad:H,dataLoadingError:_}=to({path:e,collection:t,filterValues:x,sortBy:N,searchString:y,itemCount:C}),j=Es({data:T,entitiesDisplayedFirst:n});return{data:Bs(j,{filterValues:x,sortBy:N,searchString:y,lastDeleteTimestamp:o}),dataLoading:V,noMoreToLoad:H,dataLoadingError:_,filterValues:x,setFilterValues:S,sortBy:N,setSortBy:F,searchString:y,setSearchString:w,clearFilter:Q,itemCount:C,setItemCount:E,paginationEnabled:m,pageSize:b,checkFilterCombination:k,popupCell:A,setPopupCell:d}}function zo({entityOrEntitiesToDelete:e,collection:t,onClose:n,open:o,callbacks:l,onEntityDelete:i,onMultipleEntitiesDelete:s,path:a}){const A=Qe(),d=He(),[g,p]=c.useState(!1),[h,u]=c.useState(),[m,b]=c.useState(),y=X();c.useEffect(()=>{if(e){const S=Array.isArray(e)&&e.length===1?e[0]:e;u(S),b(Array.isArray(S))}},[e]);const w=c.useMemo(()=>Be({collection:t,path:a,fields:y.propertyConfigs}),[t,a]),C=c.useCallback(()=>{n()},[n]),E=c.useCallback(S=>{console.debug("Deleted",S)},[]),k=c.useCallback((S,T)=>{d.open({type:"error",message:"Error deleting: "+T?.message}),console.error("Error deleting entity"),console.error(T)},[w.name]),I=c.useCallback((S,T)=>{d.open({type:"error",message:"Error before deleting: "+T?.message}),console.error(T)},[w.name]),x=c.useCallback((S,T)=>{d.open({type:"error",message:"Error after deleting: "+T?.message}),console.error(T)},[w.name]),B=c.useCallback(S=>ro({dataSource:A,entity:S,collection:w,callbacks:l,onDeleteSuccess:E,onDeleteFailure:k,onPreDeleteHookError:I,onDeleteSuccessHookError:x,context:y}),[A,w,l,E,k,I,x,y]),N=c.useCallback(async()=>{h&&(p(!0),m?Promise.all(h.map(B)).then(S=>{p(!1),s&&h&&s(a,h),S.every(Boolean)?d.open({type:"success",message:`${w.name}: multiple deleted`}):S.some(Boolean)?d.open({type:"warning",message:`${w.name}: Some of the entities have been deleted, but not all`}):d.open({type:"error",message:`${w.name}: Error deleting entities`}),n()}):B(h).then(S=>{p(!1),S&&(i&&h&&i(a,h),d.open({type:"success",message:`${w.singularName??w.name} deleted`}),n())}))},[h,m,B,s,a,n,d,w.name,i]);let F;if(h&&m)F=r.jsx(r.Fragment,{children:"Multiple entities"});else{const S=h;F=S?r.jsx($r,{entity:S,collection:t,path:a}):r.jsx(r.Fragment,{})}const Q=m?r.jsxs(r.Fragment,{children:[r.jsx("b",{children:w.name}),": Confirm multiple delete?"]}):`Would you like to delete this ${w.singularName??w.name}?`;return r.jsxs(f.Dialog,{maxWidth:"2xl","aria-labelledby":"delete-dialog",open:o,onOpenChange:S=>S?void 0:n(),children:[r.jsxs(f.DialogContent,{fullHeight:!0,children:[r.jsx(f.Typography,{variant:"subtitle2",className:"p-4",children:Q}),!m&&r.jsx("div",{className:"p-4",children:F})]}),r.jsxs(f.DialogActions,{children:[g&&r.jsx(f.CircularProgress,{size:"small"}),r.jsx(f.Button,{onClick:C,disabled:g,variant:"text",color:"primary",children:"Cancel"}),r.jsx(f.Button,{autoFocus:!0,disabled:g,onClick:N,variant:"filled",color:"primary",children:"Ok"})]})]})}function Rt(e){return Array.isArray(e)?e:e?[e]:[]}function xs({collection:e,relativePath:t,parentCollectionIds:n,onNewClick:o,onMultipleDeleteClick:l,selectionEnabled:i,path:s,selectionController:a,tableController:A,collectionEntitiesCount:d}){const g=X(),p=g.plugins??[],h=We(),u=Te(),m=a.selectedEntities,b=at(e,h,Ne(s),null)&&o&&(u?r.jsxs(f.Button,{id:`add_entity_${s}`,onClick:o,startIcon:r.jsx(f.AddIcon,{}),size:"large",variant:"filled",color:"primary",children:["Add ",e.singularName??e.name]}):r.jsx(f.Button,{id:`add_entity_${s}`,onClick:o,size:"medium",variant:"filled",color:"primary",children:r.jsx(f.AddIcon,{})})),y=Jt(e,h,Ne(s),null);let w;if(i){const k=u?r.jsxs(f.Button,{variant:"text",disabled:!m?.length||!y,startIcon:r.jsx(f.DeleteIcon,{}),onClick:l,color:"primary",className:"lg:w-20",children:["(",m?.length,")"]}):r.jsx(f.IconButton,{color:"primary",disabled:!m?.length||!y,onClick:l,children:r.jsx(f.DeleteIcon,{})});w=r.jsx(f.Tooltip,{title:y?"Delete":"You have selected at least one entity you cannot delete",children:k})}const C={path:s,relativePath:t,parentCollectionIds:n,collection:e,selectionController:a,context:g,tableController:A,collectionEntitiesCount:d},E=Rt(e.Actions).map((k,I)=>r.jsx(ne,{children:r.jsx(k,{...C})},`actions_${I}`));return p&&p.forEach((k,I)=>{k.collections?.CollectionActions&&E.push(...Rt(k.collections?.CollectionActions).map((x,B)=>r.jsx(ne,{children:r.jsx(x,{...C,...k.collections?.collectionActionsProps})},`plugin_actions_${I}_${B}`)))}),r.jsxs(r.Fragment,{children:[E,w,b]})}function Is({containerRef:e,innerRef:t,x:n,y:o,onMove:l}){let i=0,s=0;const a=c.useRef(!1),A=m=>{if(m.button!==0||!e.current||m.defaultPrevented||m.innerClicked)return;const{x:b,y}=e.current.getBoundingClientRect();i=m.screenX-b,s=m.screenY-y,document.addEventListener("mousemove",h),document.addEventListener("mouseup",p),document.addEventListener("selectstart",g),a.current=!0},d=m=>{m.innerClicked=!0},g=m=>{m.preventDefault(),m.stopPropagation()},p=m=>{document.removeEventListener("mousemove",h),document.removeEventListener("mouseup",p),document.removeEventListener("selectstart",g),m.stopPropagation(),a.current=!1},h=m=>{m.target.localName==="input"||!a.current||(l({x:m.screenX-i,y:m.screenY-s}),m.stopPropagation())},u=()=>{e.current&&(e.current.style.top=`${o}px`,e.current.style.left=`${n}px`)};c.useEffect(()=>{const m=e.current,b=t.current;if(!(!m||!b))return b&&b.addEventListener("mousedown",d),m&&m.addEventListener("mousedown",A),u(),()=>{m&&m.removeEventListener("mousedown",A),b&&b.removeEventListener("mousedown",d)}})}function Ss(){const[e,t]=c.useState({width:0,height:0});return c.useLayoutEffect(()=>{function n(){t({width:window.innerWidth,height:window.innerHeight})}return window.addEventListener("resize",n),n(),()=>window.removeEventListener("resize",n)},[]),e}const Fs=({onResize:e})=>{const t=c.useRef(0),n=c.useRef(null),o=c.useRef(e);o.current=e;const l=c.useCallback(s=>{t.current&&cancelAnimationFrame(t.current),t.current=requestAnimationFrame(()=>{o.current(s)})},[]),i=c.useCallback(()=>{const s=n.current;s&&s.contentDocument&&s.contentDocument.defaultView&&s.contentDocument.defaultView.addEventListener("resize",l)},[l]);return c.useEffect(()=>{const s=n.current;return()=>{s&&s.contentDocument&&s.contentDocument.defaultView&&s.contentDocument.defaultView.removeEventListener("resize",l)}},[l]),r.jsx("object",{onLoad:i,ref:n,tabIndex:-1,type:"text/html",data:"about:blank",title:"",style:{position:"absolute",top:0,left:0,height:"100%",width:"100%",pointerEvents:"none",zIndex:-1,opacity:0}})};function er({name:e,addLabel:t,value:n,disabled:o=!1,buildEntry:l,small:i,onInternalIdAdded:s,includeAddButton:a,newDefaultEntry:A=null,setFieldValue:d}){return r.jsx(un,{droppableId:e,addLabel:t,value:n,disabled:o,buildEntry:l,size:i?"small":"medium",onInternalIdAdded:s,includeAddButton:a,newDefaultEntry:A,onValueChange:g=>d(e,g)})}function be({icon:e,title:t,small:n,className:o,required:l}){return r.jsxs("span",{className:`inline-flex items-center my-0.5 ${n?"gap-1":"gap-2"} ${o??""}`,children:[e,r.jsx("span",{className:`font-medium text-${n?"base":"sm"} origin-top-left transform ${n?"translate-x-2 scale-75":""}`,children:(t??"")+(l?" *":"")})]})}function Ns({field:e,form:t,label:n,tooltip:o,disabled:l,size:i="small",allowIndeterminate:s}){const a=r.jsx(f.BooleanSwitchWithLabel,{label:n,size:i,position:"start",value:e.value,disabled:l,allowIndeterminate:s,onValueChange:A=>t.setFieldValue(e.name,A)});return o?r.jsx(f.Tooltip,{title:o,children:a}):a}function ye({error:e,showError:t,property:n,includeDescription:o=!0,disabled:l}){const i=n.description||n.longDescription;if(!(t&&e)&&(!o||!i))return null;if(t&&e)return r.jsx(f.Typography,{variant:"caption",className:"ml-3.5 text-red-500",children:e});const s=typeof n.disabled=="object"?n.disabled.disabledMessage:void 0;return r.jsxs("div",{className:"flex ml-3.5 mt-1",children:[r.jsx(f.Typography,{variant:"caption",color:l?"disabled":"secondary",className:"flex-grow",children:s||n.description}),n.longDescription&&r.jsx(f.Tooltip,{title:n.longDescription,side:"bottom",children:r.jsx(f.IconButton,{size:"small",className:"self-start",children:r.jsx(f.InfoIcon,{color:"disabled",size:"small"})})})]})}function tn({propertyKey:e,value:t,setValue:n,error:o,showError:l,disabled:i,autoFocus:s,touched:a,property:A,includeDescription:d}){const g=A.enumValues;xe({property:A,value:t,setValue:n});const p=c.useCallback(h=>{h.stopPropagation(),h.preventDefault(),n(null)},[n]);return r.jsxs(r.Fragment,{children:[r.jsx(f.Select,{value:t?t.toString():"",disabled:i,position:"item-aligned",inputClassName:f.cn("w-full"),label:r.jsx(be,{icon:he(A,"small"),required:A.validation?.required,title:A.name,className:"text-text-secondary dark:text-text-secondary-dark ml-3.5"}),endAdornment:A.clearable&&r.jsx(f.IconButton,{onClick:p,children:r.jsx(f.ClearIcon,{})}),onValueChange:h=>{const u=h?A.dataType==="number"?parseFloat(h):h:null;return n(u)},renderValue:h=>r.jsx(we,{enumKey:h,enumValues:g,size:"medium"}),children:g&&g.map(h=>r.jsx(f.SelectItem,{value:String(h.id),children:r.jsx(we,{enumKey:String(h.id),enumValues:g,size:"medium"})},h.id))}),r.jsx(ye,{includeDescription:d,showError:l,error:o,disabled:i,property:A})]})}function rn({propertyKey:e,value:t,setValue:n,error:o,showError:l,disabled:i,property:s,includeDescription:a,autoFocus:A}){const d=s.of;if(!d)throw Error("Using wrong component ArrayEnumSelect");if(Array.isArray(d))throw Error("Using array properties instead of single one in `of` in ArrayProperty");if(d.dataType!=="string"&&d.dataType!=="number")throw Error("Field misconfiguration: array field of type string or number");const g=$e(d.enumValues);if(!g)throw console.error(s),Error("Field misconfiguration: array field of type string or number needs to have enumValues");xe({property:s,value:t,setValue:n});const p=!!t&&Array.isArray(t),h=c.useCallback((u,m)=>{const b=u!==void 0?$t(g,u):void 0;return r.jsxs(we,{enumKey:u,enumValues:g,size:"medium",children:[b?.label??u,!m&&r.jsx("button",{className:"ml-1 ring-offset-background rounded-full outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",onMouseDown:y=>{y.preventDefault(),y.stopPropagation()},onClick:y=>{y.preventDefault(),y.stopPropagation(),n(t.filter(w=>w!==u))},children:r.jsx(f.CloseIcon,{size:"smallest"})})]},u)},[g,n,t]);return r.jsxs("div",{className:"mt-0.5 ml-0.5 mt-2",children:[r.jsx(f.MultiSelect,{value:p?t.map(u=>u.toString()):[],disabled:i,label:r.jsx(be,{icon:he(s,"small"),required:s.validation?.required,title:s.name,className:"text-text-secondary dark:text-text-secondary-dark ml-3.5"}),renderValue:c.useCallback(u=>h(u,!1),[h]),onMultiValueChange:u=>{let m;return d&&d?.dataType==="number"?m=u?u.map(b=>parseFloat(b)):[]:m=u,n(m)},children:g.map(u=>String(u.id)).map(u=>r.jsx(f.MultiSelectItem,{value:u,children:h(u,!0)},u))}),r.jsx(ye,{includeDescription:a,showError:l,error:o,disabled:i,property:s})]})}function Uo({propertyKey:e,value:t,error:n,showError:o,disabled:l,isSubmitting:i,tableMode:s,property:a,includeDescription:A,setValue:d,setFieldValue:g}){const p=a.of;if(p.dataType!=="reference")throw Error("ArrayOfReferencesField expected a property containing references");const h=a.expanded===void 0?!0:a.expanded,[u,m]=c.useState(!1),b=t&&Array.isArray(t)?t.map(N=>N.id):[];xe({property:a,value:t,setValue:d});const y=ie(),w=c.useMemo(()=>p.path?y.getCollection(p.path):void 0,[p.path]);if(!w)throw Error(`Couldn't find the corresponding collection for the path: ${p.path}`);const C=c.useCallback(N=>{console.debug("onMultipleEntitiesSelected",N),d(N.map(F=>et(F)))},[d]),E=St({multiselect:!0,path:p.path,collection:w,onMultipleEntitiesSelected:C,selectedEntityIds:b,forceFilter:p.forceFilter}),k=c.useCallback(N=>{N.preventDefault(),E.open()},[E]),I=c.useCallback((N,F)=>{const Q=t&&t.length>N?t[N]:void 0;return Q?r.jsx("div",{onMouseEnter:()=>m(!0),onMouseMove:()=>m(!0),onMouseLeave:()=>m(!1),children:r.jsx(Ge,{disabled:!p.path,previewProperties:p.previewProperties,size:"medium",onClick:k,reference:Q,onHover:u})}):r.jsx("div",{children:"Internal ERROR"})},[p.path,p.previewProperties,u,t]),x=r.jsx(be,{icon:he(a,"small"),required:a.validation?.required,title:a.name,className:"text-text-secondary dark:text-text-secondary-dark"}),B=r.jsxs(r.Fragment,{children:[!w&&r.jsx(pe,{error:"The specified collection does not exist. Check console"}),w&&r.jsxs(r.Fragment,{children:[r.jsx(er,{value:t,addLabel:a.name?"Add reference to "+a.name:"Add reference",name:e,buildEntry:I,disabled:i,setFieldValue:g,newDefaultEntry:a.of.defaultValue}),r.jsxs(f.Button,{className:"my-4 justify-center text-left",variant:"outlined",color:"primary",disabled:i,onClick:k,children:["Edit ",a.name]})]})]});return r.jsxs(r.Fragment,{children:[!s&&r.jsx(f.ExpandablePanel,{className:"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2",initiallyExpanded:h,title:x,children:B}),s&&B,r.jsx(ye,{includeDescription:A,showError:o,error:n,disabled:l,property:a})]})}function Lo({name:e,property:t,value:n,entity:o,onRemove:l,disabled:i,size:s}){return r.jsxs("div",{className:f.cn(f.paperMixin,"relative m-4 border-box flex items-center justify-center",s==="medium"?"min-w-[220px] min-h-[220px] max-w-[220px]":"min-w-[118px] min-h-[118px] max-w-[118px]"),children:[!i&&r.jsx("div",{className:"absolute rounded-full -top-2 -right-2 z-10 bg-white dark:bg-gray-900",children:r.jsx(f.Tooltip,{title:"Remove",children:r.jsx(f.IconButton,{size:"small",onClick:a=>{a.stopPropagation(),l(n)},children:r.jsx(f.RemoveIcon,{size:"small"})})})}),n&&r.jsx(ne,{children:r.jsx(me,{propertyKey:e,value:n,property:t,entity:o,size:s})})]})}const Qs="box-border relative pt-[2px] items-center border border-transparent min-h-[254px] outline-none rounded-md duration-200 ease-[cubic-bezier(0.4,0,0.2,1)] focus:border-primary-solid",Ts="border-dotted-gray",Ms="hover:bg-field-hover dark:hover:bg-field-hover-dark",Ps="pt-0 border-2 border-solid",Ds="transition-colors duration-200 ease-[cubic-bezier(0,0,0.2,1)] border-2 border-solid border-green-500",Os="transition-colors duration-200 ease-[cubic-bezier(0,0,0.2,1)] border-2 border-solid border-red-500";function nn({propertyKey:e,value:t,setValue:n,error:o,showError:l,autoFocus:i,tableMode:s,property:a,includeDescription:A,context:d,isSubmitting:g}){if(!d.entityId)throw new Error("StorageUploadFieldBinding: Entity id is null");const p=ct(),h=it(a)||!!a.disabled||g,{internalValue:u,setInternalValue:m,onFilesAdded:b,storage:y,onFileUploadComplete:w,storagePathBuilder:C,multipleFilesSupported:E}=Co({entityValues:d.values,entityId:d.entityId,path:d.path,property:a,propertyKey:e,value:t,storageSource:p,disabled:h,onChange:n});xe({property:a,value:t,setValue:n});const k={id:d.entityId,values:d.values,path:d.path};return r.jsxs(r.Fragment,{children:[!s&&r.jsx(be,{icon:he(a,"small"),required:a.validation?.required,title:a.name,className:"text-text-secondary dark:text-text-secondary-dark ml-3.5"}),r.jsx(Gs,{value:u,name:e,disabled:h,autoFocus:i,property:a,onChange:n,setInternalValue:m,onFilesAdded:b,entity:k,onFileUploadComplete:w,storagePathBuilder:C,storage:y,multipleFilesSupported:E}),r.jsx(ye,{includeDescription:A,showError:l,error:o,disabled:h,property:a})]})}function Vs({storage:e,disabled:t,isDraggingOver:n,onFilesAdded:o,multipleFilesSupported:l,droppableProvided:i,autoFocus:s,internalValue:a,property:A,entity:d,onClear:g,metadata:p,storagePathBuilder:h,onFileUploadComplete:u,size:m,name:b,helpText:y}){const w=He(),{getRootProps:C,getInputProps:E,isDragActive:k,isDragAccept:I,isDragReject:x}=wn.useDropzone({accept:e.acceptedFiles?e.acceptedFiles.map(B=>({[B]:[]})).reduce((B,N)=>({...B,...N}),{}):void 0,disabled:t||n,noDragEventsBubbling:!0,maxSize:e.maxSize,onDrop:o,onDropRejected:(B,N)=>{for(const F of B)for(const Q of F.errors)w.open({type:"error",message:`Error uploading file: File is larger than ${e.maxSize} bytes`})}});return r.jsxs("div",{...C(),className:f.cn(f.fieldBackgroundMixin,t?f.fieldBackgroundDisabledMixin:f.fieldBackgroundHoverMixin,Qs,l&&a.length?"":"flex",f.focusedMixin,{[Ms]:!k,[Ps]:k,[Os]:x,[Ds]:I,[Ts]:t}),children:[r.jsxs("div",{...i.droppableProps,ref:i.innerRef,className:f.cn("flex items-center p-1 no-scrollbar",l&&a.length?"overflow-auto":"",l&&a.length?"min-h-[180px]":"min-h-[250px]"),children:[r.jsx("input",{autoFocus:s,...E()}),a.map((B,N)=>{let F;return B.storagePathOrDownloadUrl?F=r.jsx(Lo,{name:`storage_preview_${B.storagePathOrDownloadUrl}`,property:A,disabled:t,entity:d,value:B.storagePathOrDownloadUrl,onRemove:g,size:B.size}):B.file&&(F=r.jsx(xo,{entry:B,metadata:p,storagePath:h(B.file),onFileUploadComplete:u,imageSize:m==="medium"?220:118,simple:!1})),r.jsx(lt.Draggable,{draggableId:`array_field_${b}_${B.id}`,index:N,children:(Q,S)=>r.jsx("div",{tabIndex:-1,ref:Q.innerRef,...Q.draggableProps,...Q.dragHandleProps,className:f.cn(f.focusedMixin,"rounded-md"),style:{...Q.draggableProps.style},children:F})},`array_field_${b}_${B.id}`)}),i.placeholder]}),r.jsx("div",{className:"flex-grow min-h-[38px] box-border m-2 text-center",children:r.jsx(f.Typography,{align:"center",variant:"label",children:y})})]})}function Gs({property:e,name:t,value:n,setInternalValue:o,onChange:l,multipleFilesSupported:i,onFileUploadComplete:s,disabled:a,onFilesAdded:A,autoFocus:d,storage:g,entity:p,storagePathBuilder:h}){if(i){const k=e;if(k.of){if(Array.isArray(k.of)||k.of.dataType!=="string")throw Error("Storage field using array must be of data type string")}else throw Error("Storage field using array must be of data type string")}const u=g?.metadata,m=i?"small":"medium",b=c.useCallback((k,I)=>{if(!i)return;const x=[...n],B=x[k];x.splice(k,1),x.splice(I,0,B),o(x);const N=x.filter(F=>!!F.storagePathOrDownloadUrl).map(F=>F.storagePathOrDownloadUrl);l(N)},[i,l,o,n]),y=c.useCallback(k=>{k.destination&&b(k.source.index,k.destination.index)},[b]),w=c.useCallback(k=>{if(i){const I=n.filter(x=>x.storagePathOrDownloadUrl!==k);l(I.filter(x=>!!x.storagePathOrDownloadUrl).map(x=>x.storagePathOrDownloadUrl)),o(I)}else l(null),o([])},[n,i,l]),C=i?"Drag 'n' drop some files here, or click to select files":"Drag 'n' drop a file here, or click to select one",E=i?e.of:e;return r.jsx(lt.DragDropContext,{onDragEnd:y,children:r.jsx(lt.Droppable,{droppableId:`droppable_${t}`,direction:"horizontal",renderClone:(k,I,x)=>{const B=n[x.source.index];return r.jsx("div",{ref:k.innerRef,...k.draggableProps,...k.dragHandleProps,style:k.draggableProps.style,className:"rounded",children:r.jsx(Lo,{name:`storage_preview_${B.storagePathOrDownloadUrl}`,property:E,disabled:!0,entity:p,value:B.storagePathOrDownloadUrl,onRemove:w,size:B.size})})},children:(k,I)=>r.jsx(Vs,{storage:g,disabled:a,isDraggingOver:I.isDraggingOver,droppableProvided:k,onFilesAdded:A,multipleFilesSupported:i,autoFocus:d,internalValue:n,property:E,entity:p,onClear:w,metadata:u,storagePathBuilder:h,onFileUploadComplete:s,size:m,name:t,helpText:C})})})}function ht({propertyKey:e,value:t,setValue:n,error:o,showError:l,disabled:i,autoFocus:s,property:a,includeDescription:A}){let d,g;a.dataType==="string"&&(d=a.multiline,g=a.url),xe({property:a,value:t,setValue:n});const p=c.useCallback(b=>{b.stopPropagation(),b.preventDefault(),n(null)},[n]),h=b=>{if(m==="number"){const y=b.target.value?parseFloat(b.target.value):void 0;y&&isNaN(y)?n(null):y!=null?n(y):n(null)}else n(b.target.value)},u=!!d,m=a.dataType==="number"?"number":void 0;return r.jsxs(r.Fragment,{children:[r.jsx(f.TextField,{value:t,onChange:h,autoFocus:s,label:r.jsx(be,{icon:he(a,"small"),required:a.validation?.required,title:a.name}),type:m,multiline:u,disabled:i,endAdornment:a.clearable&&r.jsx(f.IconButton,{onClick:p,children:r.jsx(f.ClearIcon,{})}),error:l?o:void 0,inputClassName:o?"text-red-500 dark:text-red-600":""}),r.jsx(ye,{includeDescription:A,showError:l,error:o,disabled:i,property:a}),g&&r.jsx(f.Collapse,{className:"mt-1 ml-1",in:!!t,children:r.jsx(me,{value:t,property:a,size:"medium"})})]})}const $o=c.forwardRef(function({propertyKey:t,value:n,setValue:o,error:l,showError:i,autoFocus:s,disabled:a,touched:A,property:d,includeDescription:g},p){return xe({property:d,value:n,setValue:o}),r.jsxs(r.Fragment,{children:[r.jsx(f.BooleanSwitchWithLabel,{value:n,onValueChange:h=>o(h),error:i,label:r.jsx(be,{icon:he(d,"small"),required:d.validation?.required,title:d.name}),disabled:a,autoFocus:s,size:"medium"}),r.jsx(ye,{includeDescription:g,showError:i,error:l,disabled:a,property:d})]})});function _o({propertyKey:e,value:t,setValue:n,autoFocus:o,error:l,showError:i,disabled:s,touched:a,property:A,includeDescription:d}){const{locale:g}=X(),p=t||null;return xe({property:A,value:t,setValue:n}),r.jsxs(r.Fragment,{children:[r.jsx(f.DateTimeField,{value:p,onChange:h=>n(h),size:"medium",mode:A.mode,clearable:A.clearable,locale:g,label:r.jsx(be,{icon:he(A,"small"),required:A.validation?.required,className:"text-text-secondary dark:text-text-secondary-dark",title:A.name})}),r.jsx(ye,{includeDescription:d,showError:i,error:l,disabled:s,property:A})]})}function on({propertyKey:e,value:t,error:n,showError:o,tableMode:l,property:i,includeDescription:s,context:a}){if(!a.entityId)throw new Error("ReadOnlyFieldBinding: Entity id is null");const A={id:a.entityId,values:a.values,path:a.path};return r.jsxs(r.Fragment,{children:[!l&&r.jsx(be,{icon:he(i,"small"),required:i.validation?.required,title:i.name,className:"text-text-secondary dark:text-text-secondary-dark ml-3.5"}),r.jsx("div",{className:f.cn(f.paperMixin,"min-h-14 p-4 md:p-6 overflow-x-scroll no-scrollbar"),children:r.jsx(ne,{children:r.jsx(me,{propertyKey:e,value:t,property:i,entity:A,size:"medium"})})}),r.jsx(ye,{includeDescription:s,showError:o,error:n,property:i})]})}function Wo(e){return typeof e.property.path!="string"?r.jsx(on,{...e}):r.jsx(Ys,{...e})}function Ys({value:e,setValue:t,error:n,showError:o,isSubmitting:l,disabled:i,touched:s,autoFocus:a,property:A,includeDescription:d,context:g}){if(!A.path)throw new Error("Property path is required for ReferenceFieldBinding");xe({property:A,value:e,setValue:t});const p=e&&e instanceof Pe,h=ie(),u=c.useMemo(()=>A.path?h.getCollection(A.path):void 0,[A.path]);if(!u)throw Error(`Couldn't find the corresponding collection for the path: ${A.path}`);const m=c.useCallback(w=>{t(w?et(w):null)},[t]),b=St({multiselect:!1,path:A.path,collection:u,onSingleEntitySelected:m,selectedEntityIds:p?[e.id]:void 0,forceFilter:A.forceFilter}),y=c.useCallback(w=>{w.preventDefault(),b.open()},[b]);return r.jsxs(r.Fragment,{children:[r.jsx(be,{icon:he(A,"small"),required:A.validation?.required,title:A.name,className:"text-text-secondary dark:text-text-secondary-dark ml-3.5"}),!u&&r.jsx(pe,{error:"The specified collection does not exist. Check console"}),u&&r.jsxs(r.Fragment,{children:[e&&r.jsx(Ge,{disabled:!A.path,previewProperties:A.previewProperties,size:"medium",onClick:i||l?void 0:y,reference:e}),!e&&r.jsx("div",{className:"justify-center text-left",children:r.jsxs(f.Button,{variant:"outlined",color:"primary",disabled:i||l,onClick:y,children:["Edit ",A.name]})})]}),r.jsx(ye,{includeDescription:d,showError:o,error:n,disabled:i,property:A})]})}const nt=c.memo(zs,(e,t)=>{if(e.propertyKey!==t.propertyKey)return!1;const n=ve(e.property)||e.property.fromBuilder,o=ve(t.property)||t.property.fromBuilder;return!((n===o||oe(e.property,t.property))&&e.disabled===t.disabled)||tr(t.property),!1});function zs({propertyKey:e,property:t,context:n,includeDescription:o,underlyingValueHasChanged:l,disabled:i,tableMode:s,partOfArray:a,partOfBlock:A,autoFocus:d}){const g=X(),h=tr(t,g.plugins)?Ce.Field:Ce.FastField;return r.jsx(h,{name:e,children:u=>{let m;const b=ke({propertyKey:e,propertyValue:u.field.value,propertyOrBuilder:t,values:u.form.values,path:n.path,entityId:n.entityId,fields:g.propertyConfigs});if(b===null||vt(b))return r.jsx(r.Fragment,{});if(it(b))m=on;else if(b.Field)typeof b.Field=="function"&&(m=b.Field);else{const w=sr(b,g.propertyConfigs);if(!w)throw console.log("INTERNAL: Could not find field config for property",{propertyKey:e,resolvedProperty:b,fields:g.propertyConfigs,propertyConfig:w}),new Error(`INTERNAL: Could not find field config for property ${e}`);m=ke({propertyOrBuilder:w.property,propertyValue:u.field.value,values:u.form.values,path:n.path,entityId:n.entityId,fields:g.propertyConfigs}).Field}if(!m)return console.warn(`No field component found for property ${e}`),console.warn("Property:",t),r.jsx("div",{children:`Currently the field ${b.dataType} is not supported`});const y={propertyKey:e,property:b,includeDescription:o,underlyingValueHasChanged:l,context:n,disabled:i,tableMode:s,partOfArray:a,partOfBlock:A,autoFocus:d};return r.jsx(Us,{Component:m,componentProps:y,fieldProps:u})}})}function Us({Component:e,componentProps:{propertyKey:t,property:n,includeDescription:o,underlyingValueHasChanged:l,tableMode:i,partOfArray:s,partOfBlock:a,autoFocus:A,context:d,disabled:g},fieldProps:p}){const{plugins:h}=X(),u=n.customProps,m=p.field.value,b=p.meta.initialValue,y=Ce.getIn(p.form.errors,t),w=Ce.getIn(p.form.touched,t),C=y&&(p.form.submitCount>0||n.validation?.unique)&&(!Array.isArray(y)||!!y.filter(F=>!!F).length),k=Ls(d.path,d.collection,t,n,e,h)??e,I=p.form.isSubmitting,x=c.useCallback((F,Q)=>{p.form.setFieldTouched(t,!0,!1),p.form.setFieldValue(t,F,Q)},[]),B=c.useCallback((F,Q,S)=>{p.form.setFieldTouched(t,!0,!1),p.form.setFieldValue(F,Q,S)},[]),N={propertyKey:t,value:m,initialValue:b,setValue:x,setFieldValue:B,error:y,touched:w,showError:C,isSubmitting:I,includeDescription:o??!0,property:n,disabled:g??!1,underlyingValueHasChanged:l??!1,tableMode:i??!1,partOfArray:s??!1,partOfBlock:a??!1,autoFocus:A??!1,customProps:u,context:d};return r.jsxs(ne,{children:[r.jsx(k,{...N}),l&&!I&&r.jsx(f.Typography,{variant:"caption",className:"ml-3.5",children:"This value has been updated elsewhere"})]})}const tr=(e,t)=>{if(t?.some(l=>l.form?.fieldBuilder)||ve(e))return!0;const n=e,o=!!n.Field||"fromBuilder"in n&&n.fromBuilder;return n.dataType==="map"&&n.properties?o||Object.values(n.properties).some(l=>tr(l,t)):n.dataType==="array"&&"resolvedProperties"in n?o||n.resolvedProperties?.some(l=>l&&tr(l,t)):o};function Ls(e,t,n,o,l,i){return c.useRef((()=>{let a=null;return i&&i.forEach(A=>{const d=mn(o);if(d&&A.form?.fieldBuilder){const g={fieldConfigId:d,propertyKey:n,property:o,Field:l,plugin:A,path:e,collection:t},p=A.form?.fieldBuilderEnabled?.(g);(p===void 0||p)&&(a=A.form.fieldBuilder(g)||a)}d||console.warn("INTERNAL: Field id not found for property",o)}),a})()).current}function jo({propertyKey:e,value:t,showError:n,error:o,disabled:l,property:i,setValue:s,partOfBlock:a,tableMode:A,includeDescription:d,underlyingValueHasChanged:g,autoFocus:p,context:h}){const u=i.pickOnlySomeKeys||!1,m=(i.expanded===void 0?!0:i.expanded)||p;if(!i.properties)throw Error(`You need to specify a 'properties' prop (or specify a custom field) in your map property ${e}`);let b;u?t?b=xn(i.properties,...Object.keys(t).filter(C=>C in i.properties)):b={}:b=i.properties;const y=r.jsx(r.Fragment,{children:r.jsx("div",{className:"py-1 flex flex-col space-y-2",children:Object.entries(b).filter(([C,E])=>!vt(E)).map(([C,E],k)=>{const I={propertyKey:`${e}.${C}`,disabled:l,property:E,includeDescription:d,underlyingValueHasChanged:g,context:h,tableMode:!1,partOfArray:!1,partOfBlock:!1,autoFocus:p&&k===0};return r.jsx("div",{children:r.jsx(nt,{...I})},`map-${e}-${k}`)})})}),w=r.jsx(be,{icon:he(i,"small"),required:i.validation?.required,title:i.name,className:"text-text-secondary dark:text-text-secondary-dark"});return r.jsxs(r.Fragment,{children:[!A&&!a&&r.jsx(f.ExpandablePanel,{initiallyExpanded:m,className:"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2",title:w,children:y}),(A||a)&&y,r.jsx(ye,{includeDescription:d,showError:n,error:o,disabled:l,property:i})]})}function Ho({propertyKey:e,value:t,showError:n,error:o,disabled:l,property:i,setValue:s,tableMode:a,includeDescription:A,underlyingValueHasChanged:d,autoFocus:g,context:p}){const h=(i.expanded===void 0?!0:i.expanded)||g;if(!i.keyValue)throw Error(`Your property ${e} needs to have the 'keyValue' prop in order to use this field binding`);const u=r.jsx(ln,{value:t,setValue:s,disabled:l,fieldName:i.name??e}),m=r.jsx(be,{icon:he(i,"small"),required:i.validation?.required,title:i.name,className:"text-text-secondary dark:text-text-secondary-dark"});return r.jsxs(r.Fragment,{children:[!a&&r.jsx(f.ExpandablePanel,{initiallyExpanded:h,title:m,className:"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2",children:u}),a&&u,r.jsx(ye,{includeDescription:A,showError:n,error:o,disabled:l,property:i})]})}function ln({value:e,setValue:t,fieldName:n,disabled:o}){const[l,i]=c.useState(Object.keys(e??{}).map(A=>[sn(),{key:A,dataType:an(e?.[A])??"string"}]));c.useEffect(()=>{const A=l.map(([u,{key:m}])=>m),d=Object.entries(e??{}).filter(([u,m])=>m!==void 0).map(([u])=>u),g=d.filter(u=>!A.includes(u)),p=A.filter(u=>!d.includes(u)),h=[...l];g.forEach(u=>{h.push([sn(),{key:u,dataType:an(e?.[u])??"string"}])}),p.forEach(u=>{const m=h.findIndex(([b,{key:y}])=>y===u);h.splice(m,1)}),i(h)},[e]);const s=c.useRef(e??{}),a=(A,d)=>{if(!A){console.warn("No key selected for data type update");return}i(l.map(g=>g[0]===A?[g[0],{key:g[1].key,dataType:d}]:g)),t({...e??{},[l.find(g=>g[0]===A)?.[1].key??""]:mr(d)})};return r.jsxs("div",{className:"py-1 flex flex-col gap-1",children:[l.map(([A,{key:d,dataType:g}],p)=>{const h=d?e?.[d]:"",u=m=>{if(i(l.map(y=>y[0]===A?[A,{key:m??"",dataType:y[1].dataType}]:y)),typeof e=="object"&&m in e)return;const b={...e??{}};typeof s.current=="object"&&d in s.current?b[d]=void 0:delete b[d],t({...b,[m??""]:h})};return r.jsx($s,{rowId:A,fieldKey:d,value:e??{},onDeleteClick:()=>{const m={...e??{}};s.current&&d in s.current?m[d]=void 0:delete m[d],i(l.filter(b=>b[0]!==A)),t({...m})},onFieldKeyChange:u,setValue:t,entryValue:h,dataType:g,disabled:o,updateDataType:a},A)}),r.jsx(f.Button,{variant:"text",size:"small",color:"primary",className:"w-full",disabled:o,startIcon:r.jsx(f.AddIcon,{}),onClick:A=>{A.preventDefault(),t({...e??{},"":null}),i([...l,[sn(),{key:"",dataType:"string"}]])},children:n?`Add to ${n}`:"Add"})]})}function $s({rowId:e,fieldKey:t,value:n,onFieldKeyChange:o,onDeleteClick:l,setValue:i,entryValue:s,dataType:a,updateDataType:A,disabled:d}){const{locale:g}=X();function p(u,m,b){return b==="string"||b==="number"?r.jsx(f.TextField,{placeholder:"value",value:u,type:b==="number"?"number":"text",size:"small",disabled:d||!m,onChange:y=>{if(b==="number"){const w=y.target.value?parseFloat(y.target.value):void 0;w&&isNaN(w)?i({...n,[m]:null}):w!=null?i({...n,[m]:w}):i({...n,[m]:null})}else i({...n,[m]:y.target.value})}},b):b==="date"?r.jsx(f.DateTimeField,{value:u,size:"small",locale:g,disabled:d||!m,onChange:y=>{i({...n,[m]:y})}}):b==="boolean"?r.jsx(f.BooleanSwitchWithLabel,{value:u,size:"small",position:"start",disabled:d||!m,onValueChange:y=>{i({...n,[m]:y})}}):b==="array"?r.jsx("div",{className:f.cn(f.defaultBorderMixin,"ml-2 pl-2 border-l border-solid"),children:r.jsx(un,{value:u,newDefaultEntry:"",droppableId:e.toString(),addLabel:m?`Add to ${m}`:"Add",size:"small",disabled:d||!m,includeAddButton:!0,onValueChange:y=>{i({...n,[m]:y})},buildEntry:(y,w)=>r.jsx(_s,{index:y,id:w,value:u[y],disabled:d||!m,setValue:C=>{const E=[...u];E[y]=C,i({...n,[m]:E})}})})}):b==="map"?r.jsx("div",{className:f.cn(f.defaultBorderMixin,"ml-2 pl-2 border-l border-solid"),children:r.jsx(ln,{value:u,fieldName:m,setValue:y=>{i({...n,[m]:y})}})}):r.jsx(f.Typography,{variant:"caption",children:`Data type ${b} not supported yet`})}function h(u){A(e,u)}return r.jsxs(r.Fragment,{children:[r.jsxs(f.Typography,{component:"div",className:"font-mono flex flex-row gap-1",children:[r.jsx("div",{className:"w-[200px] max-w-[25%]",children:r.jsx(f.TextField,{value:t,placeholder:"key",disabled:d||s!=null&&s!=="",size:"small",onChange:u=>{o(u.target.value)}})}),r.jsx("div",{className:"flex-grow",children:a!=="map"&&a!=="array"&&p(s,t,a)}),r.jsxs(f.Menu,{trigger:r.jsx(f.IconButton,{size:"small",className:"h-7 w-7",children:r.jsx(f.ArrowDropDownIcon,{})}),children:[r.jsx(f.MenuItem,{dense:!0,onClick:()=>h("string"),children:"string"}),r.jsx(f.MenuItem,{dense:!0,onClick:()=>h("number"),children:"number"}),r.jsx(f.MenuItem,{dense:!0,onClick:()=>h("boolean"),children:"boolean"}),r.jsx(f.MenuItem,{dense:!0,onClick:()=>h("date"),children:"date"}),r.jsx(f.MenuItem,{dense:!0,onClick:()=>h("map"),children:"map"}),r.jsx(f.MenuItem,{dense:!0,onClick:()=>h("array"),children:"array"})]}),r.jsx(f.IconButton,{"aria-label":"delete",size:"small",onClick:l,className:"h-7 w-7",children:r.jsx(f.RemoveIcon,{size:"small"})})]},e.toString()),(a==="map"||a==="array")&&p(s,t,a)]})}function _s({id:e,index:t,value:n,setValue:o}){const{locale:l}=X(),[i,s]=c.useState(an(n)??"string");function a(d){s(d)}function A(d,g){return g==="string"||g==="number"?r.jsx(f.TextField,{value:d,type:g==="number"?"number":"text",size:"small",onChange:p=>{if(g==="number"){const h=p.target.value?parseFloat(p.target.value):void 0;h&&isNaN(h)?o(null):h!=null?o(h):o(null)}else o(p.target.value)}}):g==="date"?r.jsx(f.DateTimeField,{value:d,size:"small",locale:l,onChange:p=>{o(p)}}):g==="boolean"?r.jsx(f.BooleanSwitchWithLabel,{value:d,size:"small",position:"start",onValueChange:p=>{o(p)}}):g==="array"?r.jsx(f.Typography,{variant:"caption",children:"Arrays of arrays are not supported."}):g==="map"?r.jsx("div",{className:f.cn(f.defaultBorderMixin,"ml-2 pl-2 border-l border-solid"),children:r.jsx(ln,{value:d,setValue:p=>{o(p)}})}):r.jsx(f.Typography,{variant:"caption",children:`Data type ${g} not supported yet`})}return r.jsxs(r.Fragment,{children:[r.jsxs(f.Typography,{component:"div",className:"font-mono flex min-h-12 flex-row gap-1 items-center",children:[r.jsx("div",{className:"flex-grow",children:i!=="map"&&A(n,i)}),r.jsxs(f.Menu,{trigger:r.jsx(f.IconButton,{size:"small",className:"h-7 w-7",children:r.jsx(f.ArrowDropDownIcon,{})}),children:[r.jsx(f.MenuItem,{dense:!0,onClick:()=>a("string"),children:"string"}),r.jsx(f.MenuItem,{dense:!0,onClick:()=>a("number"),children:"number"}),r.jsx(f.MenuItem,{dense:!0,onClick:()=>a("boolean"),children:"boolean"}),r.jsx(f.MenuItem,{dense:!0,onClick:()=>a("map"),children:"map"}),r.jsx(f.MenuItem,{dense:!0,onClick:()=>a("date"),children:"date"})]})]},e.toString()),i==="map"&&A(n,i)]})}function sn(){return Math.floor(Math.random()*Math.floor(Number.MAX_SAFE_INTEGER))}function an(e){if(typeof e=="string"||e===null)return"string";if(typeof e=="number")return"number";if(typeof e=="boolean")return"boolean";if(Array.isArray(e))return"array";if(e instanceof Date)return"date";if(e instanceof Pe)return"reference";if(e instanceof Gt)return"geopoint";if(typeof e=="object")return"map"}function Jo({propertyKey:e,value:t,error:n,showError:o,isSubmitting:l,setValue:i,setFieldValue:s,tableMode:a,property:A,includeDescription:d,underlyingValueHasChanged:g,context:p,disabled:h}){if(!A.of)throw Error("RepeatFieldBinding misconfiguration. Property `of` not set");if(!A.resolvedProperties||!Array.isArray(A.resolvedProperties))throw Error("RepeatFieldBinding - Internal error: Expected array in 'property.resolvedProperties'");const u=A.expanded===void 0?!0:A.expanded,m=A.of,[b,y]=c.useState();xe({property:A,value:t,setValue:i});const w=(k,I)=>{const x=A.resolvedProperties[k]??m,B={propertyKey:`${e}.${k}`,disabled:h,property:x,includeDescription:d,underlyingValueHasChanged:g,context:p,tableMode:!1,partOfArray:!0,partOfBlock:!1,autoFocus:I===b};return r.jsx(nt,{...B})},C=r.jsx(er,{value:t,addLabel:A.name?"Add entry to "+A.name:"Add entry",name:e,setFieldValue:s,buildEntry:w,onInternalIdAdded:y,disabled:l||!!A.disabled,includeAddButton:!A.disabled,newDefaultEntry:A.of.defaultValue}),E=r.jsx(be,{icon:he(A,"small"),required:A.validation?.required,title:A.name,className:"text-text-secondary dark:text-text-secondary-dark"});return r.jsxs(r.Fragment,{children:[!a&&r.jsx(f.ExpandablePanel,{initiallyExpanded:u,className:"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2",title:E,children:C}),a&&C,r.jsx(ye,{includeDescription:d,showError:o,error:n,disabled:h,property:A})]})}function qo({propertyKey:e,value:t,error:n,showError:o,isSubmitting:l,setValue:i,setFieldValue:s,tableMode:a,property:A,includeDescription:d,underlyingValueHasChanged:g,context:p,disabled:h}){if(!A.oneOf)throw Error("ArrayOneOfField misconfiguration. Property `oneOf` not set");const u=A.expanded===void 0?!0:A.expanded;xe({property:A,value:t,setValue:i});const[m,b]=c.useState(),y=c.useCallback((k,I)=>r.jsx(Ws,{name:`${e}.${k}`,index:k,value:t[k],typeField:A.oneOf.typeField??yt,valueField:A.oneOf.valueField??zt,properties:A.oneOf.properties,autoFocus:I===m,context:p},`array_one_of_${k}`),[p,m,A.oneOf,e,t]),w=r.jsx(be,{icon:he(A,"small"),required:A.validation?.required,title:A.name,className:"text-text-secondary dark:text-text-secondary-dark"}),C=Object.keys(A.oneOf.properties)[0],E=r.jsx(er,{value:t,name:e,addLabel:A.name?"Add entry to "+A.name:"Add entry",buildEntry:y,onInternalIdAdded:b,disabled:l||!!A.disabled,includeAddButton:!A.disabled,setFieldValue:s,newDefaultEntry:{[A.oneOf.typeField??yt]:C,[A.oneOf.valueField??zt]:Ut(A.oneOf.properties[C])}});return r.jsxs(r.Fragment,{children:[!a&&r.jsx(f.ExpandablePanel,{className:"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2",initiallyExpanded:u,title:w,children:E}),a&&E,r.jsx(ye,{includeDescription:d,showError:o,error:n,disabled:h,property:A})]})}function Ws({name:e,index:t,value:n,typeField:o,valueField:l,properties:i,autoFocus:s,context:a}){const A=n&&n[o],[d,g]=c.useState(A??void 0),p=Ce.useFormikContext();c.useEffect(()=>{A||w(Object.keys(i)[0])},[]),c.useEffect(()=>{A!==d&&g(A)},[A]);const h=d?i[d]:void 0,u=Object.entries(i).map(([C,E])=>({id:C,label:E.name??C})),m=`${e}.${o}`,b=`${e}.${l}`,y=h?{propertyKey:b,property:h,context:a,autoFocus:s,partOfArray:!1,partOfBlock:!0,tableMode:!1}:void 0,w=C=>{const E=C?i[C]:void 0;g(C),p.setFieldTouched(m),p.setFieldValue(m,C),p.setFieldValue(b,E?Ut(E):null)};return r.jsxs("div",{className:f.cn(f.paperMixin,"bg-transparent p-4 my-4 py-8"),children:[r.jsx(Ce.FastField,{required:!0,name:m,children:C=>r.jsx(r.Fragment,{children:r.jsx(f.Select,{className:"mb-2",placeholder:r.jsx(f.Typography,{variant:"caption",className:"px-4 py-2 font-medium",children:"Type"}),size:"small",position:"item-aligned",value:C.field.value!==void 0&&C.field.value!==null?C.field.value:"",renderValue:E=>r.jsx(we,{enumKey:E,enumValues:u,size:"small"}),onValueChange:E=>{w(E)},children:u.map(E=>r.jsx(f.SelectItem,{value:String(E.id),children:r.jsx(we,{enumKey:E.id,enumValues:u,size:"small"})},E.id))})})}),y&&r.jsx(nt,{...y},`form_control_${e}_${d}`)]})}const js=new El;try{Re.use(Re.Plugins.AutoResize,{min:100}),Re.unuse(Re.Plugins.FontUnderline),Re.unuse(Re.Plugins.Clear)}catch{}function Zo({propertyKey:e,value:t,setValue:n,error:o,showError:l,disabled:i,autoFocus:s,touched:a,property:A,tableMode:d,includeDescription:g,context:p}){const[h,u]=c.useState(t),m=c.useRef(t);f.useInjectStyles("MarkdownFieldBinding",Hs);const b=c.useDeferredValue({internalValue:h,value:t});return c.useEffect(()=>{m.current=t,u(t)},[t]),c.useEffect(()=>{b.internalValue!==m.current&&n(b.internalValue)},[b]),r.jsxs(r.Fragment,{children:[!d&&r.jsx(f.Typography,{variant:"caption",className:"flex-grow",children:r.jsx(be,{icon:he(A,"small"),required:A.validation?.required,title:A.name,className:"text-text-secondary dark:text-text-secondary-dark ml-3.5"})}),r.jsx(Re,{value:h??"",className:f.cn(f.fieldBackgroundMixin,i?f.fieldBackgroundDisabledMixin:f.fieldBackgroundHoverMixin,"text-base"),readOnly:i,renderHTML:y=>js.render(y),view:{menu:!0,md:!0,html:!1},onChange:({html:y,text:w})=>{u(w??null)}}),r.jsx(ye,{includeDescription:g,showError:l,error:o,disabled:i,property:A})]})}const Hs=`
|
|
5
5
|
@font-face {
|
|
6
6
|
font-family: rmel-iconfont;
|