@firecms/data_import_export 3.0.0-alpha.44 → 3.0.0-alpha.45

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,3 +1,3 @@
1
- (function(u,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("react/jsx-runtime"),require("react"),require("@firecms/core"),require("@firecms/schema_inference"),require("xlsx")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","@firecms/core","@firecms/schema_inference","xlsx"],t):(u=typeof globalThis<"u"?globalThis:u||self,t(u.FireCMS={},u.jsxRuntime,u.React,u.core,u.schema_inference,u.XLSX))})(this,function(u,t,f,a,ce,de){"use strict";function pe(e){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const s in e)if(s!=="default"){const r=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(n,s,r.get?r:{enumerable:!0,get:()=>e[s]})}}return n.default=e,Object.freeze(n)}const X=pe(de),z=()=>{const[e,n]=f.useState(!1),[s,r]=f.useState(),[i,l]=f.useState([]),[o,c]=f.useState([]),[p,d]=f.useState({}),[g,h]=f.useState({});return{inUse:e,setInUse:n,idColumn:s,setIdColumn:r,entities:o,setEntities:c,importData:i,setImportData:l,headersMapping:p,setHeadersMapping:d,originProperties:g,setOriginProperties:h}};function G(e){return new Promise((n,s)=>{if(e.type==="application/json"){const r=new FileReader;r.onload=function(i){const l=i.target?.result,o=JSON.parse(l);n(o)},r.readAsText(e)}else{const r=new FileReader;r.onload=function(i){const l=new Uint8Array(i.target?.result),o=X.read(l,{type:"array",codepage:65001,cellDates:!0}),c=o.SheetNames[0],p=o.Sheets[c],h=X.utils.sheet_to_json(p).map(fe).map(L);n(h)},r.readAsArrayBuffer(e)}})}function fe(e){return Object.keys(e).reduce((n,s)=>{try{n[s]=JSON.parse(e[s])}catch{n[s]=e[s]}return n},{})}function L(e){return Object.keys(e).reduce((n,s)=>{let r=n;const i=s.split(".");return i.forEach((l,o)=>{if(/^[\w]+\[\d+\]$/.test(l)){const c=l.slice(0,l.indexOf("[")),p=parseInt(l.slice(l.indexOf("[")+1,l.indexOf("]")));r[c]||(r[c]=[]),o!==i.length-1?(r[c][p]=r[c][p]||{},r=r[c][p]):r[c][p]=e[s]}else o!==i.length-1?(r[l]=r[l]||{},r=r[l]):r[l]=e[s]}),n},{})}function Q(e,n,s,r,i,l){const o=H(e);n&&delete o[n];const c=Object.entries(o).map(([d,g])=>{const h=s[d]??d;if(!a.getPropertyInPath(r,h))return{};const y=i[h];let T=g;return y&&(T=k(g,y)),{[h]:T}}).reduce((d,g)=>({...d,...g}),{}),p=L(c);return{id:n?e[n]:void 0,values:p,path:l}}function H(e,n=""){return Object.keys(e).reduce((s,r)=>{const i=n?`${n}.${r}`:r;return typeof e[r]=="object"&&e[r]!==null&&!Array.isArray(e[r])?Object.assign(s,H(e[r],i)):s[i]=e[r],s},{})}function k(e,n){if(n===void 0)return e;const{from:s,to:r}=n;if(s==="array"&&r==="array"&&n.fromSubtype&&n.toSubtype&&Array.isArray(e))return e.map(i=>k(i,{from:n.fromSubtype,to:n.toSubtype}));if(s==="string"&&r==="number"&&typeof e=="string")return Number(e);if(s==="string"&&r==="array"&&n.toSubtype&&typeof e=="string")return e.split(",").map(i=>k(i,{from:"string",to:n.toSubtype}));if(s==="string"&&r==="boolean")return e==="true";if(s==="number"&&r==="boolean")return e===1;if(s==="boolean"&&r==="number")return e?1:0;if(s==="boolean"&&r==="string")return e?"true":"false";if(s==="number"&&r==="string"&&typeof e=="number")return e.toString();if(s==="string"&&r==="array"&&typeof e=="string")return e.split(",").map(i=>i.trim());if(s==="string"&&r==="date"&&typeof e=="string")try{return new Date(e)}catch{return e}else{if(s==="date"&&r==="string")return e instanceof Date&&e.toISOString();if(s==="number"&&r==="date"&&typeof e=="number")try{return new Date(e)}catch{return e}else if(s==="string"&&r==="reference"&&typeof e=="string"){const i=e.split("/").slice(0,-1).join("/"),l=e.split("/").slice(-1)[0];return new a.EntityReference(l,i)}else{if(s===r)return e;if(s==="array"&&r==="string"&&Array.isArray(e))return e.join(",")}}return e}function Y(e){return typeof e=="number"?"number":typeof e=="string"?"string":typeof e=="boolean"?"boolean":e instanceof Date?"date":Array.isArray(e)?"array":"map"}function Z(e,n){function s(r,i){const l={};return Object.keys(r).forEach(o=>{const c=i?`${i}.${o}`:o,p=a.getPropertyInPath(r,o),d=a.getPropertyInPath(e,c);if(p){if(p.dataType==="map"&&p.properties){const g=s(p.properties,c);Object.keys(g).forEach(h=>{l[`${c}.${h}`]=g[h]});return}if(d){const g=d.dataType,h=p.dataType;let b,y;p.dataType==="array"&&p.of&&(y=p.of.dataType),d?.dataType==="array"&&d?.of&&(b=d.of.dataType),(g!==h||b!==y)&&(console.log("Mapping",{currentKey:c,inferredProperty:d,property:p,from:g,to:h,fromSubtype:b,toSubtype:y}),l[o]={from:g,to:h,fromSubtype:b,toSubtype:y})}}}),l}return s(n)}function K({idColumn:e,headersMapping:n,originProperties:s,destinationProperties:r,onIdPropertyChanged:i,buildPropertyView:l}){return t.jsxs(t.Fragment,{children:[t.jsx(ge,{idColumn:e,headersMapping:n,onChange:i}),t.jsxs(a.Table,{style:{tableLayout:"fixed"},children:[t.jsxs(a.TableHeader,{children:[t.jsx(a.TableCell,{header:!0,style:{width:"20%"},children:"Column in file"}),t.jsx(a.TableCell,{header:!0}),t.jsx(a.TableCell,{header:!0,style:{width:"75%"},children:"Property"})]}),t.jsx(a.TableBody,{children:r&&Object.entries(n).map(([o,c])=>{const p=n[o],d=c?a.getPropertyInPath(r,c):null,g=a.getPropertyInPath(s,o),h=g?g.dataType==="array"&&typeof g.of=="object"?`${g.dataType} - ${g.of.dataType}`:g.dataType:void 0;return t.jsxs(a.TableRow,{style:{height:"90px"},children:[t.jsxs(a.TableCell,{style:{width:"20%"},children:[t.jsx(a.Typography,{variant:"body2",children:o}),g&&t.jsx(a.Typography,{variant:"caption",color:"secondary",children:h})]}),t.jsx(a.TableCell,{children:t.jsx(a.ChevronRightIcon,{})}),t.jsx(a.TableCell,{className:o===e?"text-center":void 0,style:{width:"75%"},children:l?.({isIdColumn:o===e,property:d,propertyKey:p,importKey:o})})]},o)})})]})]})}function ge({idColumn:e,headersMapping:n,onChange:s}){return t.jsx("div",{children:t.jsxs(a.Select,{size:"small",value:e??"",onChange:r=>{s(r.target.value)},renderValue:r=>t.jsx(a.Typography,{variant:"body2",children:r!==""?r:"Autogenerate ID"}),label:"Column that will be used as ID for each document",children:[t.jsx(a.SelectItem,{value:"",children:"Autogenerate ID"}),Object.entries(n).map(([r,i])=>t.jsx(a.SelectItem,{value:r,children:r},r))]})})}function R({onDataAdded:e}){return t.jsx(a.FileUpload,{accept:{"text/*":[".csv",".xls",".xlsx"],"application/vnd.ms-excel":[".xls",".xlsx"],"application/msexcel":[".xls",".xlsx"],"application/vnd.ms-office":[".xls",".xlsx"],"application/xls":[".xls",".xlsx"],"application/x-xls":[".xls",".xlsx"],"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":[".xls",".xlsx"],"application/json":[".json"]},preventDropOnDocument:!0,size:"small",maxFiles:1,uploadDescription:t.jsxs(t.Fragment,{children:[t.jsx(a.UploadIcon,{}),"Drag and drop a file here or click to upload"]}),onFilesAdded:n=>{n.length>0&&G(n[0]).then(s=>{e(s)})}})}function he({propertyKey:e,property:n,onEditClick:s,includeName:r=!0,onPropertyNameChanged:i,propertyTypeView:l}){const{propertyConfigs:o}=a.useFireCMSContext(),c=n?a.getFieldConfig(n,o):null;return t.jsx(a.ErrorBoundary,{children:t.jsxs("div",{className:"flex flex-row w-full items-center",children:[t.jsx("div",{className:"mx-4",children:l??t.jsx(a.FieldConfigBadge,{propertyConfig:c??void 0})}),t.jsx("div",{className:"w-full flex flex-col grow",children:t.jsxs("div",{className:"flex flex-row items-center gap-2",children:[r&&t.jsx(a.TextField,{size:"small",className:"text-base grow",value:n?.name??"",onChange:p=>{i&&e&&i(e,p.target.value)}}),t.jsx(a.IconButton,{onClick:s,size:"small",children:t.jsx(a.EditIcon,{size:"small"})})]})})]})})}function ee({importConfig:e,collection:n,onImportSuccess:s}){const r=a.useDataSource(),i=f.useRef(!1),[l,o]=f.useState(0);function c(){i.current||(i.current=!0,te(r,n,e.entities,0,25,o).then(()=>{s(n),i.current=!1}))}return f.useEffect(()=>{c()},[]),t.jsxs(a.CenteredView,{className:"flex flex-col gap-4 items-center",children:[t.jsx(a.CircularProgress,{}),t.jsx(a.Typography,{variant:"h6",children:"Saving data"}),t.jsxs(a.Typography,{variant:"body2",children:[l,"/",e.entities.length," entities saved"]}),t.jsx(a.Typography,{variant:"caption",children:"Do not close this tab or the import will be interrupted."})]})}function te(e,n,s,r=0,i=25,l){console.debug("Saving imported data",r,i);const o=s.slice(r,r+i);return Promise.all(o.map(c=>e.saveEntity({path:n.path,values:c.values,entityId:c.id,collection:n,status:"new"}))).then(()=>r+i<s.length?(l(r+i),te(e,n,s,r+i,i,l)):(l(s.length),Promise.resolve()))}function ue({collection:e,path:n,collectionEntitiesCount:s}){const r=a.useFireCMSContext(),i=a.useSnackbarController(),[l,o]=f.useState(!1),[c,p]=f.useState("initial"),d=z(),g=f.useCallback(()=>{o(!0),p("initial")},[o]),h=f.useCallback(()=>{o(!1)},[o]),b=f.useCallback(()=>{p("preview")},[]),y=f.useCallback(()=>{p("import_data_saving")},[]),T=async m=>{if(d.setImportData(m),m.length>0){const D=await ce.buildEntityPropertiesFromData(m,Y);d.setOriginProperties(D);const A=ae(m);d.setHeadersMapping(A);const v=Object.keys(A)?.[0];if(v?.includes("id")||v?.includes("key")){const I=v;d.setIdColumn(I)}}setTimeout(()=>{p("mapping")},100)},P=a.resolveCollection({collection:e,path:n,fields:r.propertyConfigs}),x=a.getPropertiesWithPropertiesOrder(P.properties,P.propertiesOrder),_=Object.entries(x).flatMap(([m,D])=>re(m,D,0)),E=P.propertiesOrder??Object.keys(P.properties);return e.collectionGroup?null:t.jsxs(t.Fragment,{children:[t.jsx(a.Tooltip,{title:"Import",children:t.jsx(a.IconButton,{color:"primary",onClick:g,children:t.jsx(a.FileUploadIcon,{})})}),t.jsxs(a.Dialog,{open:l,fullWidth:c==="preview",fullHeight:c==="preview",maxWidth:c==="initial"?"lg":"7xl",children:[t.jsxs(a.DialogContent,{className:"flex flex-col gap-4 my-4",fullHeight:c==="preview",children:[c==="initial"&&t.jsxs(t.Fragment,{children:[t.jsx(a.Typography,{variant:"h6",children:"Import data"}),t.jsx(a.Typography,{variant:"body2",children:"Upload a CSV, Excel or JSON file and map it to your existing schema"}),t.jsx(R,{onDataAdded:T})]}),c==="mapping"&&t.jsxs(t.Fragment,{children:[t.jsx(a.Typography,{variant:"h6",children:"Map fields"}),t.jsx(K,{headersMapping:d.headersMapping,idColumn:d.idColumn,originProperties:d.originProperties,destinationProperties:x,onIdPropertyChanged:m=>d.setIdColumn(m),buildPropertyView:({isIdColumn:m,property:D,propertyKey:A,importKey:v})=>t.jsx(ye,{selectedPropertyKey:A??"",properties:x,propertiesAndLevel:_,isIdColumn:m,onIdSelected:()=>{d.setIdColumn(v)},onPropertySelected:I=>{const O=Object.entries(d.headersMapping).map(([w,S])=>S===I?{[w]:null}:w===v?{[w]:I}:{[w]:S}).reduce((w,S)=>({...w,...S}),{});d.setHeadersMapping(O),I===d.idColumn&&d.setIdColumn(void 0)}})})]}),c==="preview"&&t.jsx(me,{importConfig:d,properties:x,propertiesOrder:E}),c==="import_data_saving"&&d&&t.jsx(ee,{importConfig:d,collection:e,onImportSuccess:m=>{h(),i.open({type:"info",message:"Data imported successfully"})}})]}),t.jsxs(a.DialogActions,{children:[c==="mapping"&&t.jsx(a.Button,{onClick:()=>p("initial"),variant:"text",children:"Back"}),c==="preview"&&t.jsx(a.Button,{onClick:()=>p("mapping"),variant:"text",children:"Back"}),t.jsx(a.Button,{onClick:h,variant:"text",children:"Cancel"}),c==="mapping"&&t.jsx(a.Button,{variant:"filled",onClick:b,children:"Next"}),c==="preview"&&t.jsx(a.Button,{variant:"filled",onClick:y,children:"Save data"})]})]})]})}const M="__internal_id__";function ye({selectedPropertyKey:e,properties:n,onPropertySelected:s,onIdSelected:r,propertiesAndLevel:i,isIdColumn:l}){const o=e?a.getPropertyInPath(n,e):null,c=f.useCallback(d=>d===M?t.jsx(a.Typography,{variant:"body2",className:"p-4",children:"Use this column as ID"}):!d||!o?t.jsx(a.Typography,{variant:"body2",className:"p-4",children:"Do not import this property"}):t.jsx(ne,{propertyKey:d,property:o}),[o]),p=f.useCallback(d=>{d===M?(r(),s(null)):s(d===""?null:d)},[]);return t.jsxs(a.Select,{value:l?M:e??void 0,onValueChange:p,renderValue:c,children:[t.jsx(a.SelectItem,{value:"",children:t.jsx(a.Typography,{variant:"body2",className:"p-4",children:"Do not import this property"})}),t.jsx(a.SelectItem,{value:M,children:t.jsx(a.Typography,{variant:"body2",className:"p-4",children:"Use this column as ID"})}),i.map(({property:d,level:g,propertyKey:h})=>t.jsx(a.SelectItem,{value:h,disabled:d.dataType==="map",children:t.jsx(ne,{propertyKey:h,property:d,level:g})},h))]})}function re(e,n,s){const r=[];return r.push({property:n,level:s,propertyKey:e}),n.dataType==="map"&&n.properties&&Object.entries(n.properties).forEach(([i,l])=>{r.push(...re(`${e}.${i}`,l,s+1))}),r}function ne({propertyKey:e,property:n,level:s=0}){const{propertyConfigs:r}=a.useFireCMSContext(),i=a.getFieldConfig(n,r);return t.jsxs("div",{className:"flex flex-row w-full text-start items-center h-full",children:[new Array(s).fill(0).map((l,o)=>t.jsx("div",{className:a.cn(a.defaultBorderMixin,"ml-8 border-l h-12")},o)),t.jsx("div",{className:"m-4",children:t.jsx(a.Tooltip,{title:i?.name,children:t.jsx(a.FieldConfigBadge,{propertyConfig:i})})}),t.jsxs("div",{className:"flex flex-col flex-grow p-2 pl-2",children:[t.jsx(a.Typography,{variant:"body1",component:"span",className:"flex-grow pr-2",children:n.name?n.name:" "}),t.jsx(a.Typography,{className:" pr-2",variant:"body2",component:"span",color:"secondary",children:e})]})]})}function me({importConfig:e,properties:n,propertiesOrder:s}){f.useEffect(()=>{const i=Z(e.originProperties,n),l=e.importData.map(o=>Q(o,e.idColumn,e.headersMapping,n,i,"TEMP_PATH"));e.setEntities(l)},[]);const r=a.useSelectionController();return t.jsx(a.EntityCollectionTable,{title:t.jsxs("div",{children:[t.jsx(a.Typography,{variant:"subtitle2",children:"Imported data preview"}),t.jsx(a.Typography,{variant:"caption",children:"Entities with the same id will be overwritten"})]}),tableController:{data:e.entities,dataLoading:!1,noMoreToLoad:!1},endAdornment:t.jsx("div",{className:"h-12"}),filterable:!1,sortable:!1,selectionController:r,displayedColumnIds:s.map(i=>({key:i,disabled:!1})),properties:n})}function ae(e){const n={};return e.forEach(s=>{Object.keys(s).forEach(r=>{const i=s[r];typeof i=="object"&&!Array.isArray(i)&&Object.entries(ae([i])).forEach(([l,o])=>{n[`${r}.${l}`]=`${r}.${o}`}),n[r]=r})}),n}function be(e,n,s,r,i,l,o){const c=s.properties;if(l==="csv"){const p=r?a.getArrayValuesCount(e.map(y=>y.values)):{},d=ve(c,i,p),g=xe(e,n,c,d,o),h=se(d.map(y=>y.label)),b=g.map(y=>se(y));ie([h,...b],`${s.name}.csv`,"text/csv")}else{const p=Ce(e,n,c,o),d=JSON.stringify(p,null,2);ie([d],`${s.name}.json`,"application/json")}}function xe(e,n,s,r,i){const l=e.map(o=>({id:o.id,...U(o.values,s,"csv",i)}));return n&&n.forEach((o,c)=>{l[c]={...l[c],...o}}),l&&l.map(o=>r.map(c=>a.getValueInPath(o,c.key)))}function Ce(e,n,s,r){const i=e.map(l=>({id:l.id,...U(l.values,s,"json",r)}));return n&&n.forEach((l,o)=>{i[o]={...i[o],...l}}),i}function ve(e,n,s){const r=[{label:"id",key:"id"},...Object.entries(e).flatMap(([i,l])=>s&&s[i]>1?Array.from({length:s[i]},(o,c)=>J(l,`${i}[${c}]`,"")).flat():J(l,i,""))];return n&&r.push(...n.map(i=>({label:i,key:i}))),r}function J(e,n,s=""){const r=s?`${s}.${n}`:n;return e.dataType==="map"&&e.properties?Object.entries(e.properties).map(([i,l])=>J(l,i,r)).flat():[{label:r,key:r}]}function B(e,n,s,r){let i;if(n.dataType==="map"&&n.properties)i=U(e,n.properties,s,r);else if(n.dataType==="array")n.of&&Array.isArray(e)?Array.isArray(n.of)?i=n.of.map((l,o)=>B(e[o],l,s,r)):n.of.dataType==="map"?i=s==="csv"?e.map(l=>JSON.stringify(l)):e.map(l=>B(l,n.of,s,r)):i=e.map(l=>B(l,n.of,s,r)):i=e;else if(n.dataType==="reference"&&e instanceof a.EntityReference){const l=e||void 0;i=l?l.pathWithId:null}else n.dataType==="date"&&e instanceof Date?i=e?r==="timestamp"?e.getTime():e.toISOString():null:i=e;return i}function U(e,n,s,r){const i=Object.entries(n).map(([l,o])=>{const c=e&&e[l],p=B(c,o,s,r);return p===void 0?{}:{[l]:p}}).reduce((l,o)=>({...l,...o}),{});return{...e,...i}}function se(e){return e.map(n=>n==null?"":Array.isArray(n)?'"'+JSON.stringify(n).replaceAll('"','\\"')+'"':'"'+String(n).replaceAll('"','""')+'"').join(",")+`\r
2
- `}function ie(e,n,s){const r=new Blob(e,{type:s}),i=URL.createObjectURL(r),l=document.createElement("a");l.href=i,l.setAttribute("download",n),l.click()}const we=500;function Se({collection:e,path:n,collectionEntitiesCount:s,exportAllowed:r,notAllowedView:i}){const l=typeof e.exportable=="object"?e.exportable:void 0,o=f.useRef(new Date),[c,p]=f.useState(!0),[d,g]=f.useState("csv"),[h,b]=f.useState("string"),y=a.useFireCMSContext(),T=a.useDataSource(),x=a.useNavigationContext().resolveAliasesFrom(n),_=!r||r({collectionEntitiesCount:s,path:x,collection:e}),E=f.useMemo(()=>a.resolveCollection({collection:e,path:x,fields:y.propertyConfigs}),[e,x]),[m,D]=f.useState(!1),[A,v]=f.useState(),[I,O]=f.useState(!1),w=f.useCallback(()=>{O(!0)},[O]),S=f.useCallback(()=>{O(!1)},[O]),le=f.useCallback(async F=>{const $=l?.additionalFields,j=E.additionalFields,V=$?await Promise.all(F.map(async N=>(await Promise.all($.map(async C=>({[C.key]:await C.builder({entity:N,context:y})})))).reduce((C,q)=>({...C,...q}),{}))):[],W=j?await Promise.all(F.map(async N=>(await Promise.all(j.map(async C=>C.value?{[C.key]:await C.value({entity:N,context:y})}:{}))).reduce((C,q)=>({...C,...q}),{}))):[];return[...V,...W]},[l?.additionalFields]),oe=f.useCallback(async(F,$)=>{D(!0),T.fetchCollection({path:x,collection:F}).then(async j=>{v(void 0);const V=await le(j),W=[...$?.additionalFields?.map(N=>N.key)??[],...F.additionalFields?.map(N=>N.key)??[]];be(j,V,F,c,W,d,h)}).catch(v).finally(()=>D(!1))},[T,x,le,c,d,h]),De=f.useCallback(()=>{oe(E,l),S()},[oe,E,l,S]);return t.jsxs(t.Fragment,{children:[t.jsx(a.Tooltip,{title:"Export",children:t.jsx(a.IconButton,{color:"primary",onClick:w,children:t.jsx(a.GetAppIcon,{})})}),t.jsxs(a.Dialog,{open:I,onOpenChange:O,maxWidth:"xl",children:[t.jsxs(a.DialogContent,{className:"flex flex-col gap-4 my-4",children:[t.jsx(a.Typography,{variant:"h6",children:"Export data"}),t.jsx("div",{children:"Download the the content of this table as a CSV"}),s>we&&t.jsx(a.Alert,{color:"warning",children:t.jsxs("div",{children:["This collections has a large number of documents (",s,")."]})}),t.jsxs("div",{className:"flex flex-row gap-4",children:[t.jsxs("div",{className:"p-4 flex flex-col",children:[t.jsxs("div",{className:"flex items-center",children:[t.jsx("input",{id:"radio-csv",type:"radio",value:"csv",name:"exportType",checked:d==="csv",onChange:()=>g("csv"),className:a.cn(a.focusedMixin,"w-4 text-blue-600 bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")}),t.jsx("label",{htmlFor:"radio-csv",className:"p-2 text-sm font-medium text-gray-900 dark:text-gray-300",children:"CSV"})]}),t.jsxs("div",{className:"flex items-center",children:[t.jsx("input",{id:"radio-json",type:"radio",value:"json",name:"exportType",checked:d==="json",onChange:()=>g("json"),className:a.cn(a.focusedMixin,"w-4 text-blue-600 bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")}),t.jsx("label",{htmlFor:"radio-json",className:"p-2 text-sm font-medium text-gray-900 dark:text-gray-300",children:"JSON"})]})]}),t.jsxs("div",{className:"p-4 flex flex-col",children:[t.jsxs("div",{className:"flex items-center",children:[t.jsx("input",{id:"radio-timestamp",type:"radio",value:"timestamp",name:"dateExportType",checked:h==="timestamp",onChange:()=>b("timestamp"),className:a.cn(a.focusedMixin,"w-4 text-blue-600 bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")}),t.jsxs("label",{htmlFor:"radio-timestamp",className:"p-2 text-sm font-medium text-gray-900 dark:text-gray-300",children:["Dates as timestamps (",o.current.getTime(),")"]})]}),t.jsxs("div",{className:"flex items-center",children:[t.jsx("input",{id:"radio-string",type:"radio",value:"string",name:"dateExportType",checked:h==="string",onChange:()=>b("string"),className:a.cn(a.focusedMixin,"w-4 text-blue-600 bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")}),t.jsxs("label",{htmlFor:"radio-string",className:"p-2 text-sm font-medium text-gray-900 dark:text-gray-300",children:["Dates as strings (",o.current.toISOString(),")"]})]})]})]}),t.jsx(a.BooleanSwitchWithLabel,{size:"small",disabled:d!=="csv",value:c,onValueChange:p,label:"Flatten arrays"}),!_&&i]}),t.jsxs(a.DialogActions,{children:[m&&t.jsx(a.CircularProgress,{size:"small"}),t.jsx(a.Button,{onClick:S,variant:"text",children:"Cancel"}),t.jsx(a.Button,{variant:"filled",onClick:De,disabled:m||!_,children:"Download"})]})]})]})}function Te(e){return{name:"Import/Export",collections:{CollectionActions:[ue,Se],collectionActionsProps:e}}}u.DataNewPropertiesMapping=K,u.ImportFileUpload=R,u.ImportNewPropertyFieldPreview=he,u.ImportSaveInProgress=ee,u.convertDataToEntity=Q,u.convertFileToJson=G,u.flattenEntry=H,u.getInferenceType=Y,u.getPropertiesMapping=Z,u.processValueMapping=k,u.unflattenObject=L,u.useImportConfig=z,u.useImportExportPlugin=Te,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
1
+ (function(u,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("react/jsx-runtime"),require("react"),require("@firecms/core"),require("@firecms/schema_inference"),require("xlsx")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","@firecms/core","@firecms/schema_inference","xlsx"],t):(u=typeof globalThis<"u"?globalThis:u||self,t(u.FireCMS={},u.jsxRuntime,u.React,u.core,u.schema_inference,u.XLSX))})(this,function(u,t,f,a,ce,de){"use strict";function pe(e){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const s in e)if(s!=="default"){const r=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(n,s,r.get?r:{enumerable:!0,get:()=>e[s]})}}return n.default=e,Object.freeze(n)}const X=pe(de),z=()=>{const[e,n]=f.useState(!1),[s,r]=f.useState(),[l,i]=f.useState([]),[o,c]=f.useState([]),[p,d]=f.useState({}),[g,h]=f.useState({});return{inUse:e,setInUse:n,idColumn:s,setIdColumn:r,entities:o,setEntities:c,importData:l,setImportData:i,headersMapping:p,setHeadersMapping:d,originProperties:g,setOriginProperties:h}};function G(e){return new Promise((n,s)=>{if(e.type==="application/json"){const r=new FileReader;r.onload=function(l){const i=l.target?.result,o=JSON.parse(i);n(o)},r.readAsText(e)}else{const r=new FileReader;r.onload=function(l){const i=new Uint8Array(l.target?.result),o=X.read(i,{type:"array",codepage:65001,cellDates:!0}),c=o.SheetNames[0],p=o.Sheets[c],h=X.utils.sheet_to_json(p).map(fe).map(L);n(h)},r.readAsArrayBuffer(e)}})}function fe(e){return Object.keys(e).reduce((n,s)=>{try{n[s]=JSON.parse(e[s])}catch{n[s]=e[s]}return n},{})}function L(e){return Object.keys(e).reduce((n,s)=>{let r=n;const l=s.split(".");return l.forEach((i,o)=>{if(/^[\w]+\[\d+\]$/.test(i)){const c=i.slice(0,i.indexOf("[")),p=parseInt(i.slice(i.indexOf("[")+1,i.indexOf("]")));r[c]||(r[c]=[]),o!==l.length-1?(r[c][p]=r[c][p]||{},r=r[c][p]):r[c][p]=e[s]}else o!==l.length-1?(r[i]=r[i]||{},r=r[i]):r[i]=e[s]}),n},{})}function Q(e,n,s,r,l,i){const o=H(e);n&&delete o[n];const c=Object.entries(o).map(([d,g])=>{const h=s[d]??d;if(!a.getPropertyInPath(r,h))return{};const y=l[h];let T=g;return y&&(T=k(g,y)),{[h]:T}}).reduce((d,g)=>({...d,...g}),{}),p=L(c);return{id:n?e[n]:void 0,values:p,path:i}}function H(e,n=""){return Object.keys(e).reduce((s,r)=>{const l=n?`${n}.${r}`:r;return typeof e[r]=="object"&&e[r]!==null&&!Array.isArray(e[r])?Object.assign(s,H(e[r],l)):s[l]=e[r],s},{})}function k(e,n){if(n===void 0)return e;const{from:s,to:r}=n;if(s==="array"&&r==="array"&&n.fromSubtype&&n.toSubtype&&Array.isArray(e))return e.map(l=>k(l,{from:n.fromSubtype,to:n.toSubtype}));if(s==="string"&&r==="number"&&typeof e=="string")return Number(e);if(s==="string"&&r==="array"&&n.toSubtype&&typeof e=="string")return e.split(",").map(l=>k(l,{from:"string",to:n.toSubtype}));if(s==="string"&&r==="boolean")return e==="true";if(s==="number"&&r==="boolean")return e===1;if(s==="boolean"&&r==="number")return e?1:0;if(s==="boolean"&&r==="string")return e?"true":"false";if(s==="number"&&r==="string"&&typeof e=="number")return e.toString();if(s==="string"&&r==="array"&&typeof e=="string")return e.split(",").map(l=>l.trim());if(s==="string"&&r==="date"&&typeof e=="string")try{return new Date(e)}catch{return e}else{if(s==="date"&&r==="string")return e instanceof Date&&e.toISOString();if(s==="number"&&r==="date"&&typeof e=="number")try{return new Date(e)}catch{return e}else if(s==="string"&&r==="reference"&&typeof e=="string"){const l=e.split("/").slice(0,-1).join("/"),i=e.split("/").slice(-1)[0];return new a.EntityReference(i,l)}else{if(s===r)return e;if(s==="array"&&r==="string"&&Array.isArray(e))return e.join(",")}}return e}function Y(e){return typeof e=="number"?"number":typeof e=="string"?"string":typeof e=="boolean"?"boolean":e instanceof Date?"date":Array.isArray(e)?"array":"map"}function Z(e,n){function s(r,l){const i={};return Object.keys(r).forEach(o=>{const c=l?`${l}.${o}`:o,p=a.getPropertyInPath(r,o),d=a.getPropertyInPath(e,c);if(p){if(p.dataType==="map"&&p.properties){const g=s(p.properties,c);Object.keys(g).forEach(h=>{i[`${c}.${h}`]=g[h]});return}if(d){const g=d.dataType,h=p.dataType;let b,y;p.dataType==="array"&&p.of&&(y=p.of.dataType),d?.dataType==="array"&&d?.of&&(b=d.of.dataType),(g!==h||b!==y)&&(console.log("Mapping",{currentKey:c,inferredProperty:d,property:p,from:g,to:h,fromSubtype:b,toSubtype:y}),i[o]={from:g,to:h,fromSubtype:b,toSubtype:y})}}}),i}return s(n)}function K({idColumn:e,headersMapping:n,originProperties:s,destinationProperties:r,onIdPropertyChanged:l,buildPropertyView:i}){return t.jsxs(t.Fragment,{children:[t.jsx(ge,{idColumn:e,headersMapping:n,onChange:l}),t.jsxs(a.Table,{style:{tableLayout:"fixed"},children:[t.jsxs(a.TableHeader,{children:[t.jsx(a.TableCell,{header:!0,style:{width:"20%"},children:"Column in file"}),t.jsx(a.TableCell,{header:!0}),t.jsx(a.TableCell,{header:!0,style:{width:"75%"},children:"Property"})]}),t.jsx(a.TableBody,{children:r&&Object.entries(n).map(([o,c])=>{const p=n[o],d=c?a.getPropertyInPath(r,c):null,g=a.getPropertyInPath(s,o),h=g?g.dataType==="array"&&typeof g.of=="object"?`${g.dataType} - ${g.of.dataType}`:g.dataType:void 0;return t.jsxs(a.TableRow,{style:{height:"90px"},children:[t.jsxs(a.TableCell,{style:{width:"20%"},children:[t.jsx(a.Typography,{variant:"body2",children:o}),g&&t.jsx(a.Typography,{variant:"caption",color:"secondary",children:h})]}),t.jsx(a.TableCell,{children:t.jsx(a.ChevronRightIcon,{})}),t.jsx(a.TableCell,{className:o===e?"text-center":void 0,style:{width:"75%"},children:i?.({isIdColumn:o===e,property:d,propertyKey:p,importKey:o})})]},o)})})]})]})}function ge({idColumn:e,headersMapping:n,onChange:s}){return t.jsx("div",{children:t.jsxs(a.Select,{size:"small",value:e??"",onChange:r=>{s(r.target.value)},renderValue:r=>t.jsx(a.Typography,{variant:"body2",children:r!==""?r:"Autogenerate ID"}),label:"Column that will be used as ID for each document",children:[t.jsx(a.SelectItem,{value:"",children:"Autogenerate ID"}),Object.entries(n).map(([r,l])=>t.jsx(a.SelectItem,{value:r,children:r},r))]})})}function R({onDataAdded:e}){return t.jsx(a.FileUpload,{accept:{"text/*":[".csv",".xls",".xlsx"],"application/vnd.ms-excel":[".xls",".xlsx"],"application/msexcel":[".xls",".xlsx"],"application/vnd.ms-office":[".xls",".xlsx"],"application/xls":[".xls",".xlsx"],"application/x-xls":[".xls",".xlsx"],"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":[".xls",".xlsx"],"application/json":[".json"]},preventDropOnDocument:!0,size:"small",maxFiles:1,uploadDescription:t.jsxs(t.Fragment,{children:[t.jsx(a.UploadIcon,{}),"Drag and drop a file here or click to upload"]}),onFilesAdded:n=>{n.length>0&&G(n[0]).then(s=>{e(s)})}})}function he({propertyKey:e,property:n,onEditClick:s,includeName:r=!0,onPropertyNameChanged:l,propertyTypeView:i}){const{propertyConfigs:o}=a.useFireCMSContext(),c=n?a.getFieldConfig(n,o):null;return t.jsx(a.ErrorBoundary,{children:t.jsxs("div",{className:"flex flex-row w-full items-center",children:[t.jsx("div",{className:"mx-4",children:i??t.jsx(a.FieldConfigBadge,{propertyConfig:c??void 0})}),t.jsx("div",{className:"w-full flex flex-col grow",children:t.jsxs("div",{className:"flex flex-row items-center gap-2",children:[r&&t.jsx(a.TextField,{size:"small",className:"text-base grow",value:n?.name??"",onChange:p=>{l&&e&&l(e,p.target.value)}}),t.jsx(a.IconButton,{onClick:s,size:"small",children:t.jsx(a.EditIcon,{size:"small"})})]})})]})})}function ee({importConfig:e,collection:n,onImportSuccess:s}){const r=a.useDataSource(),l=f.useRef(!1),[i,o]=f.useState(0);function c(){l.current||(l.current=!0,te(r,n,e.entities,0,25,o).then(()=>{s(n),l.current=!1}))}return f.useEffect(()=>{c()},[]),t.jsxs(a.CenteredView,{className:"flex flex-col gap-4 items-center",children:[t.jsx(a.CircularProgress,{}),t.jsx(a.Typography,{variant:"h6",children:"Saving data"}),t.jsxs(a.Typography,{variant:"body2",children:[i,"/",e.entities.length," entities saved"]}),t.jsx(a.Typography,{variant:"caption",children:"Do not close this tab or the import will be interrupted."})]})}function te(e,n,s,r=0,l=25,i){console.debug("Saving imported data",r,l);const o=s.slice(r,r+l);return Promise.all(o.map(c=>e.saveEntity({path:n.path,values:c.values,entityId:c.id,collection:n,status:"new"}))).then(()=>r+l<s.length?(i(r+l),te(e,n,s,r+l,l,i)):(i(s.length),Promise.resolve()))}function ue({collection:e,path:n,collectionEntitiesCount:s}){const r=a.useFireCMSContext(),l=a.useSnackbarController(),[i,o]=f.useState(!1),[c,p]=f.useState("initial"),d=z(),g=f.useCallback(()=>{o(!0),p("initial")},[o]),h=f.useCallback(()=>{o(!1)},[o]),b=f.useCallback(()=>{p("preview")},[]),y=f.useCallback(()=>{p("import_data_saving")},[]),T=async m=>{if(d.setImportData(m),m.length>0){const D=await ce.buildEntityPropertiesFromData(m,Y);d.setOriginProperties(D);const A=ae(m);d.setHeadersMapping(A);const v=Object.keys(A)?.[0];if(v?.includes("id")||v?.includes("key")){const I=v;d.setIdColumn(I)}}setTimeout(()=>{p("mapping")},100)},P=a.resolveCollection({collection:e,path:n,fields:r.propertyConfigs}),x=a.getPropertiesWithPropertiesOrder(P.properties,P.propertiesOrder),_=Object.entries(x).flatMap(([m,D])=>re(m,D,0)),E=P.propertiesOrder??Object.keys(P.properties);return e.collectionGroup?null:t.jsxs(t.Fragment,{children:[t.jsx(a.Tooltip,{title:"Import",children:t.jsx(a.IconButton,{color:"primary",onClick:g,children:t.jsx(a.FileUploadIcon,{})})}),t.jsxs(a.Dialog,{open:i,fullWidth:c==="preview",fullHeight:c==="preview",maxWidth:c==="initial"?"lg":"7xl",children:[t.jsxs(a.DialogContent,{className:"flex flex-col gap-4 my-4",fullHeight:c==="preview",children:[c==="initial"&&t.jsxs(t.Fragment,{children:[t.jsx(a.Typography,{variant:"h6",children:"Import data"}),t.jsx(a.Typography,{variant:"body2",children:"Upload a CSV, Excel or JSON file and map it to your existing schema"}),t.jsx(R,{onDataAdded:T})]}),c==="mapping"&&t.jsxs(t.Fragment,{children:[t.jsx(a.Typography,{variant:"h6",children:"Map fields"}),t.jsx(K,{headersMapping:d.headersMapping,idColumn:d.idColumn,originProperties:d.originProperties,destinationProperties:x,onIdPropertyChanged:m=>d.setIdColumn(m),buildPropertyView:({isIdColumn:m,property:D,propertyKey:A,importKey:v})=>t.jsx(ye,{selectedPropertyKey:A??"",properties:x,propertiesAndLevel:_,isIdColumn:m,onIdSelected:()=>{d.setIdColumn(v)},onPropertySelected:I=>{const O=Object.entries(d.headersMapping).map(([w,S])=>S===I?{[w]:null}:w===v?{[w]:I}:{[w]:S}).reduce((w,S)=>({...w,...S}),{});d.setHeadersMapping(O),I===d.idColumn&&d.setIdColumn(void 0)}})})]}),c==="preview"&&t.jsx(me,{importConfig:d,properties:x,propertiesOrder:E}),c==="import_data_saving"&&d&&t.jsx(ee,{importConfig:d,collection:e,onImportSuccess:m=>{h(),l.open({type:"info",message:"Data imported successfully"})}})]}),t.jsxs(a.DialogActions,{children:[c==="mapping"&&t.jsx(a.Button,{onClick:()=>p("initial"),variant:"text",children:"Back"}),c==="preview"&&t.jsx(a.Button,{onClick:()=>p("mapping"),variant:"text",children:"Back"}),t.jsx(a.Button,{onClick:h,variant:"text",children:"Cancel"}),c==="mapping"&&t.jsx(a.Button,{variant:"filled",onClick:b,children:"Next"}),c==="preview"&&t.jsx(a.Button,{variant:"filled",onClick:y,children:"Save data"})]})]})]})}const M="__internal_id__";function ye({selectedPropertyKey:e,properties:n,onPropertySelected:s,onIdSelected:r,propertiesAndLevel:l,isIdColumn:i}){const o=e?a.getPropertyInPath(n,e):null,c=f.useCallback(d=>d===M?t.jsx(a.Typography,{variant:"body2",className:"p-4",children:"Use this column as ID"}):!d||!o?t.jsx(a.Typography,{variant:"body2",className:"p-4",children:"Do not import this property"}):t.jsx(ne,{propertyKey:d,property:o}),[o]),p=f.useCallback(d=>{d===M?(r(),s(null)):s(d===""?null:d)},[]);return t.jsxs(a.Select,{value:i?M:e??void 0,onValueChange:p,renderValue:c,children:[t.jsx(a.SelectItem,{value:"",children:t.jsx(a.Typography,{variant:"body2",className:"p-4",children:"Do not import this property"})}),t.jsx(a.SelectItem,{value:M,children:t.jsx(a.Typography,{variant:"body2",className:"p-4",children:"Use this column as ID"})}),l.map(({property:d,level:g,propertyKey:h})=>t.jsx(a.SelectItem,{value:h,disabled:d.dataType==="map",children:t.jsx(ne,{propertyKey:h,property:d,level:g})},h))]})}function re(e,n,s){const r=[];return r.push({property:n,level:s,propertyKey:e}),n.dataType==="map"&&n.properties&&Object.entries(n.properties).forEach(([l,i])=>{r.push(...re(`${e}.${l}`,i,s+1))}),r}function ne({propertyKey:e,property:n,level:s=0}){const{propertyConfigs:r}=a.useFireCMSContext(),l=a.getFieldConfig(n,r);return t.jsxs("div",{className:"flex flex-row w-full text-start items-center h-full",children:[new Array(s).fill(0).map((i,o)=>t.jsx("div",{className:a.cn(a.defaultBorderMixin,"ml-8 border-l h-12")},o)),t.jsx("div",{className:"m-4",children:t.jsx(a.Tooltip,{title:l?.name,children:t.jsx(a.FieldConfigBadge,{propertyConfig:l})})}),t.jsxs("div",{className:"flex flex-col flex-grow p-2 pl-2",children:[t.jsx(a.Typography,{variant:"body1",component:"span",className:"flex-grow pr-2",children:n.name?n.name:" "}),t.jsx(a.Typography,{className:" pr-2",variant:"body2",component:"span",color:"secondary",children:e})]})]})}function me({importConfig:e,properties:n,propertiesOrder:s}){f.useEffect(()=>{const l=Z(e.originProperties,n),i=e.importData.map(o=>Q(o,e.idColumn,e.headersMapping,n,l,"TEMP_PATH"));e.setEntities(i)},[]);const r=a.useSelectionController();return t.jsx(a.EntityCollectionTable,{title:t.jsxs("div",{children:[t.jsx(a.Typography,{variant:"subtitle2",children:"Imported data preview"}),t.jsx(a.Typography,{variant:"caption",children:"Entities with the same id will be overwritten"})]}),tableController:{data:e.entities,dataLoading:!1,noMoreToLoad:!1},endAdornment:t.jsx("div",{className:"h-12"}),filterable:!1,sortable:!1,selectionController:r,displayedColumnIds:s.map(l=>({key:l,disabled:!1})),properties:n})}function ae(e){const n={};return e.forEach(s=>{Object.keys(s).forEach(r=>{const l=s[r];typeof l=="object"&&!Array.isArray(l)&&Object.entries(ae([l])).forEach(([i,o])=>{n[`${r}.${i}`]=`${r}.${o}`}),n[r]=r})}),n}function be(e,n,s,r,l,i,o){const c=s.properties;if(i==="csv"){const p=r?a.getArrayValuesCount(e.map(y=>y.values)):{},d=ve(c,l,p),g=xe(e,n,c,d,o),h=se(d.map(y=>y.label)),b=g.map(y=>se(y));le([h,...b],`${s.name}.csv`,"text/csv")}else{const p=Ce(e,n,c,o),d=JSON.stringify(p,null,2);le([d],`${s.name}.json`,"application/json")}}function xe(e,n,s,r,l){const i=e.map(o=>({id:o.id,...U(o.values,s,"csv",l)}));return n&&n.forEach((o,c)=>{i[c]={...i[c],...o}}),i&&i.map(o=>r.map(c=>a.getValueInPath(o,c.key)))}function Ce(e,n,s,r){const l=e.map(i=>({id:i.id,...U(i.values,s,"json",r)}));return n&&n.forEach((i,o)=>{l[o]={...l[o],...i}}),l}function ve(e,n,s){const r=[{label:"id",key:"id"},...Object.entries(e).flatMap(([l,i])=>s&&s[l]>1?Array.from({length:s[l]},(o,c)=>J(i,`${l}[${c}]`,"")).flat():J(i,l,""))];return n&&r.push(...n.map(l=>({label:l,key:l}))),r}function J(e,n,s=""){const r=s?`${s}.${n}`:n;return e.dataType==="map"&&e.properties?Object.entries(e.properties).map(([l,i])=>J(i,l,r)).flat():[{label:r,key:r}]}function B(e,n,s,r){let l;if(n.dataType==="map"&&n.properties)l=U(e,n.properties,s,r);else if(n.dataType==="array")n.of&&Array.isArray(e)?Array.isArray(n.of)?l=n.of.map((i,o)=>B(e[o],i,s,r)):n.of.dataType==="map"?l=s==="csv"?e.map(i=>JSON.stringify(i)):e.map(i=>B(i,n.of,s,r)):l=e.map(i=>B(i,n.of,s,r)):l=e;else if(n.dataType==="reference"&&e instanceof a.EntityReference){const i=e||void 0;l=i?i.pathWithId:null}else n.dataType==="date"&&e instanceof Date?l=e?r==="timestamp"?e.getTime():e.toISOString():null:l=e;return l}function U(e,n,s,r){const l=Object.entries(n).map(([i,o])=>{const c=e&&e[i],p=B(c,o,s,r);return p===void 0?{}:{[i]:p}}).reduce((i,o)=>({...i,...o}),{});return{...e,...l}}function se(e){return e.map(n=>n==null?"":Array.isArray(n)?'"'+JSON.stringify(n).replaceAll('"','\\"')+'"':'"'+String(n).replaceAll('"','""')+'"').join(",")+`\r
2
+ `}function le(e,n,s){const r=new Blob(e,{type:s}),l=URL.createObjectURL(r),i=document.createElement("a");i.href=l,i.setAttribute("download",n),i.click()}const we=500;function Se({collection:e,path:n,collectionEntitiesCount:s,exportAllowed:r,notAllowedView:l}){const i=typeof e.exportable=="object"?e.exportable:void 0,o=f.useRef(new Date),[c,p]=f.useState(!0),[d,g]=f.useState("csv"),[h,b]=f.useState("string"),y=a.useFireCMSContext(),T=a.useDataSource(),x=a.useNavigationController().resolveAliasesFrom(n),_=!r||r({collectionEntitiesCount:s,path:x,collection:e}),E=f.useMemo(()=>a.resolveCollection({collection:e,path:x,fields:y.propertyConfigs}),[e,x]),[m,D]=f.useState(!1),[A,v]=f.useState(),[I,O]=f.useState(!1),w=f.useCallback(()=>{O(!0)},[O]),S=f.useCallback(()=>{O(!1)},[O]),ie=f.useCallback(async F=>{const $=i?.additionalFields,j=E.additionalFields,V=$?await Promise.all(F.map(async N=>(await Promise.all($.map(async C=>({[C.key]:await C.builder({entity:N,context:y})})))).reduce((C,q)=>({...C,...q}),{}))):[],W=j?await Promise.all(F.map(async N=>(await Promise.all(j.map(async C=>C.value?{[C.key]:await C.value({entity:N,context:y})}:{}))).reduce((C,q)=>({...C,...q}),{}))):[];return[...V,...W]},[i?.additionalFields]),oe=f.useCallback(async(F,$)=>{D(!0),T.fetchCollection({path:x,collection:F}).then(async j=>{v(void 0);const V=await ie(j),W=[...$?.additionalFields?.map(N=>N.key)??[],...F.additionalFields?.map(N=>N.key)??[]];be(j,V,F,c,W,d,h)}).catch(v).finally(()=>D(!1))},[T,x,ie,c,d,h]),De=f.useCallback(()=>{oe(E,i),S()},[oe,E,i,S]);return t.jsxs(t.Fragment,{children:[t.jsx(a.Tooltip,{title:"Export",children:t.jsx(a.IconButton,{color:"primary",onClick:w,children:t.jsx(a.GetAppIcon,{})})}),t.jsxs(a.Dialog,{open:I,onOpenChange:O,maxWidth:"xl",children:[t.jsxs(a.DialogContent,{className:"flex flex-col gap-4 my-4",children:[t.jsx(a.Typography,{variant:"h6",children:"Export data"}),t.jsx("div",{children:"Download the the content of this table as a CSV"}),s>we&&t.jsx(a.Alert,{color:"warning",children:t.jsxs("div",{children:["This collections has a large number of documents (",s,")."]})}),t.jsxs("div",{className:"flex flex-row gap-4",children:[t.jsxs("div",{className:"p-4 flex flex-col",children:[t.jsxs("div",{className:"flex items-center",children:[t.jsx("input",{id:"radio-csv",type:"radio",value:"csv",name:"exportType",checked:d==="csv",onChange:()=>g("csv"),className:a.cn(a.focusedMixin,"w-4 text-blue-600 bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")}),t.jsx("label",{htmlFor:"radio-csv",className:"p-2 text-sm font-medium text-gray-900 dark:text-gray-300",children:"CSV"})]}),t.jsxs("div",{className:"flex items-center",children:[t.jsx("input",{id:"radio-json",type:"radio",value:"json",name:"exportType",checked:d==="json",onChange:()=>g("json"),className:a.cn(a.focusedMixin,"w-4 text-blue-600 bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")}),t.jsx("label",{htmlFor:"radio-json",className:"p-2 text-sm font-medium text-gray-900 dark:text-gray-300",children:"JSON"})]})]}),t.jsxs("div",{className:"p-4 flex flex-col",children:[t.jsxs("div",{className:"flex items-center",children:[t.jsx("input",{id:"radio-timestamp",type:"radio",value:"timestamp",name:"dateExportType",checked:h==="timestamp",onChange:()=>b("timestamp"),className:a.cn(a.focusedMixin,"w-4 text-blue-600 bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")}),t.jsxs("label",{htmlFor:"radio-timestamp",className:"p-2 text-sm font-medium text-gray-900 dark:text-gray-300",children:["Dates as timestamps (",o.current.getTime(),")"]})]}),t.jsxs("div",{className:"flex items-center",children:[t.jsx("input",{id:"radio-string",type:"radio",value:"string",name:"dateExportType",checked:h==="string",onChange:()=>b("string"),className:a.cn(a.focusedMixin,"w-4 text-blue-600 bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")}),t.jsxs("label",{htmlFor:"radio-string",className:"p-2 text-sm font-medium text-gray-900 dark:text-gray-300",children:["Dates as strings (",o.current.toISOString(),")"]})]})]})]}),t.jsx(a.BooleanSwitchWithLabel,{size:"small",disabled:d!=="csv",value:c,onValueChange:p,label:"Flatten arrays"}),!_&&l]}),t.jsxs(a.DialogActions,{children:[m&&t.jsx(a.CircularProgress,{size:"small"}),t.jsx(a.Button,{onClick:S,variant:"text",children:"Cancel"}),t.jsx(a.Button,{variant:"filled",onClick:De,disabled:m||!_,children:"Download"})]})]})]})}function Te(e){return{name:"Import/Export",collections:{CollectionActions:[ue,Se],collectionActionsProps:e}}}u.DataNewPropertiesMapping=K,u.ImportFileUpload=R,u.ImportNewPropertyFieldPreview=he,u.ImportSaveInProgress=ee,u.convertDataToEntity=Q,u.convertFileToJson=G,u.flattenEntry=H,u.getInferenceType=Y,u.getPropertiesMapping=Z,u.processValueMapping=k,u.unflattenObject=L,u.useImportConfig=z,u.useImportExportPlugin=Te,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
3
3
  //# sourceMappingURL=index.umd.js.map