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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -1,9 +1,9 @@
1
+ import w, { useState as T, useRef as Ne, useEffect as le, useCallback as b, useMemo as Ie } from "react";
1
2
  import { jsxs as p, Fragment as P, jsx as s } from "react/jsx-runtime";
2
- import w, { useState as T, useRef as Ne, useEffect as le, useCallback as b } from "react";
3
- import { getPropertyInPath as M, EntityReference as ce, Table as Ie, TableHeader as Oe, TableCell as k, TableBody as Ae, TableRow as Ee, Typography as h, ChevronRightIcon as Te, Select as de, SelectItem as H, FileUpload as je, UploadIcon as Fe, useFireCMSContext as G, getFieldConfig as pe, ErrorBoundary as ke, FieldConfigBadge as fe, TextField as Pe, IconButton as K, EditIcon as Me, useDataSource as me, CenteredView as $e, CircularProgress as ue, useSnackbarController as _e, resolveCollection as he, getPropertiesWithPropertiesOrder as Le, Tooltip as ee, FileUploadIcon as Re, Dialog as ge, DialogContent as ye, DialogActions as be, Button as j, cn as B, defaultBorderMixin as Be, useSelectionController as He, EntityCollectionTable as Je, getArrayValuesCount as Ue, getValueInPath as Ve, useNavigationController as We, GetAppIcon as ze, Alert as Ge, focusedMixin as V, BooleanSwitchWithLabel as Xe } from "@firecms/core";
4
- import { buildEntityPropertiesFromData as qe } from "@firecms/schema_inference";
3
+ import { getPropertyInPath as M, EntityReference as ce, Table as Oe, TableHeader as Ae, TableCell as k, TableBody as Ee, TableRow as Te, Typography as h, ChevronRightIcon as je, Select as de, SelectItem as H, FileUpload as Fe, UploadIcon as ke, useFireCMSContext as G, getFieldConfig as pe, ErrorBoundary as Pe, FieldConfigBadge as fe, TextField as Me, IconButton as K, EditIcon as $e, useDataSource as me, CenteredView as _e, CircularProgress as ue, useSnackbarController as Le, resolveCollection as he, getPropertiesWithPropertiesOrder as Re, Tooltip as ee, FileUploadIcon as Be, Dialog as ge, DialogContent as ye, DialogActions as be, Button as j, cn as B, defaultBorderMixin as He, useSelectionController as Je, EntityCollectionTable as Ue, getArrayValuesCount as Ve, getValueInPath as We, useNavigationController as ze, GetAppIcon as Ge, Alert as Xe, focusedMixin as V, BooleanSwitchWithLabel as qe } from "@firecms/core";
4
+ import { buildEntityPropertiesFromData as Qe } from "@firecms/schema_inference";
5
5
  import * as ae from "xlsx";
6
- const Qe = () => {
6
+ const Ye = () => {
7
7
  const [e, r] = T(!1), [n, t] = T(), [a, i] = T([]), [o, l] = T([]), [d, c] = T({}), [f, m] = T({});
8
8
  return {
9
9
  inUse: e,
@@ -20,7 +20,7 @@ const Qe = () => {
20
20
  setOriginProperties: m
21
21
  };
22
22
  };
23
- function Ye(e) {
23
+ function Ze(e) {
24
24
  return new Promise((r, n) => {
25
25
  if (e.type === "application/json") {
26
26
  const t = new FileReader();
@@ -38,13 +38,13 @@ function Ye(e) {
38
38
  codepage: 65001,
39
39
  cellDates: !0
40
40
  }
41
- ), l = o.SheetNames[0], d = o.Sheets[l], m = ae.utils.sheet_to_json(d).map(Ze).map(xe);
41
+ ), l = o.SheetNames[0], d = o.Sheets[l], m = ae.utils.sheet_to_json(d).map(Ke).map(xe);
42
42
  r(m);
43
43
  }, t.readAsArrayBuffer(e);
44
44
  }
45
45
  });
46
46
  }
47
- function Ze(e) {
47
+ function Ke(e) {
48
48
  return Object.keys(e).reduce((r, n) => {
49
49
  try {
50
50
  r[n] = JSON.parse(e[n]);
@@ -67,7 +67,7 @@ function xe(e) {
67
67
  }), r;
68
68
  }, {});
69
69
  }
70
- function Ke(e, r, n, t, a, i) {
70
+ function et(e, r, n, t, a, i) {
71
71
  const o = ve(e);
72
72
  r && delete o[r];
73
73
  const l = Object.entries(o).map(([c, f]) => {
@@ -150,10 +150,10 @@ function Y(e, r) {
150
150
  }
151
151
  return e;
152
152
  }
153
- function et(e) {
153
+ function tt(e) {
154
154
  return typeof e == "number" ? "number" : typeof e == "string" ? "string" : typeof e == "boolean" ? "boolean" : e instanceof Date ? "date" : Array.isArray(e) ? "array" : "map";
155
155
  }
156
- function tt(e, r) {
156
+ function rt(e, r) {
157
157
  function n(t, a) {
158
158
  const i = {};
159
159
  return Object.keys(t).forEach((o) => {
@@ -181,7 +181,7 @@ function tt(e, r) {
181
181
  }
182
182
  return n(r);
183
183
  }
184
- function rt({
184
+ function nt({
185
185
  idColumn: e,
186
186
  headersMapping: r,
187
187
  originProperties: n,
@@ -191,25 +191,25 @@ function rt({
191
191
  }) {
192
192
  return /* @__PURE__ */ p(P, { children: [
193
193
  /* @__PURE__ */ s(
194
- nt,
194
+ at,
195
195
  {
196
196
  idColumn: e,
197
197
  headersMapping: r,
198
198
  onChange: a
199
199
  }
200
200
  ),
201
- /* @__PURE__ */ p(Ie, { style: {
201
+ /* @__PURE__ */ p(Oe, { style: {
202
202
  tableLayout: "fixed"
203
203
  }, children: [
204
- /* @__PURE__ */ p(Oe, { children: [
204
+ /* @__PURE__ */ p(Ae, { children: [
205
205
  /* @__PURE__ */ s(k, { header: !0, style: { width: "20%" }, children: "Column in file" }),
206
206
  /* @__PURE__ */ s(k, { header: !0 }),
207
207
  /* @__PURE__ */ s(k, { header: !0, style: { width: "75%" }, children: "Property" })
208
208
  ] }),
209
- /* @__PURE__ */ s(Ae, { children: t && Object.entries(r).map(
209
+ /* @__PURE__ */ s(Ee, { children: t && Object.entries(r).map(
210
210
  ([o, l]) => {
211
211
  const d = r[o], c = l ? M(t, l) : null, f = M(n, o), m = f ? f.dataType === "array" && typeof f.of == "object" ? `${f.dataType} - ${f.of.dataType}` : f.dataType : void 0;
212
- return /* @__PURE__ */ p(Ee, { style: { height: "90px" }, children: [
212
+ return /* @__PURE__ */ p(Te, { style: { height: "90px" }, children: [
213
213
  /* @__PURE__ */ p(k, { style: { width: "20%" }, children: [
214
214
  /* @__PURE__ */ s(h, { variant: "body2", children: o }),
215
215
  f && /* @__PURE__ */ s(
@@ -221,7 +221,7 @@ function rt({
221
221
  }
222
222
  )
223
223
  ] }),
224
- /* @__PURE__ */ s(k, { children: /* @__PURE__ */ s(Te, {}) }),
224
+ /* @__PURE__ */ s(k, { children: /* @__PURE__ */ s(je, {}) }),
225
225
  /* @__PURE__ */ s(
226
226
  k,
227
227
  {
@@ -241,7 +241,7 @@ function rt({
241
241
  ] })
242
242
  ] });
243
243
  }
244
- function nt({
244
+ function at({
245
245
  idColumn: e,
246
246
  headersMapping: r,
247
247
  onChange: n
@@ -263,9 +263,9 @@ function nt({
263
263
  }
264
264
  ) });
265
265
  }
266
- function at({ onDataAdded: e }) {
266
+ function it({ onDataAdded: e }) {
267
267
  return /* @__PURE__ */ s(
268
- je,
268
+ Fe,
269
269
  {
270
270
  accept: {
271
271
  "text/*": [".csv", ".xls", ".xlsx"],
@@ -281,18 +281,18 @@ function at({ onDataAdded: e }) {
281
281
  size: "small",
282
282
  maxFiles: 1,
283
283
  uploadDescription: /* @__PURE__ */ p(P, { children: [
284
- /* @__PURE__ */ s(Fe, {}),
284
+ /* @__PURE__ */ s(ke, {}),
285
285
  "Drag and drop a file here or click to upload"
286
286
  ] }),
287
287
  onFilesAdded: (r) => {
288
- r.length > 0 && Ye(r[0]).then((n) => {
288
+ r.length > 0 && Ze(r[0]).then((n) => {
289
289
  e(n);
290
290
  });
291
291
  }
292
292
  }
293
293
  );
294
294
  }
295
- function xt({
295
+ function vt({
296
296
  propertyKey: e,
297
297
  property: r,
298
298
  onEditClick: n,
@@ -301,7 +301,7 @@ function xt({
301
301
  propertyTypeView: i
302
302
  }) {
303
303
  const { propertyConfigs: o } = G(), l = r ? pe(r, o) : null;
304
- return /* @__PURE__ */ s(ke, { children: /* @__PURE__ */ p(
304
+ return /* @__PURE__ */ s(Pe, { children: /* @__PURE__ */ p(
305
305
  "div",
306
306
  {
307
307
  className: "flex flex-row w-full items-center",
@@ -309,7 +309,7 @@ function xt({
309
309
  /* @__PURE__ */ s("div", { className: "mx-4", children: i ?? /* @__PURE__ */ s(fe, { propertyConfig: l ?? void 0 }) }),
310
310
  /* @__PURE__ */ s("div", { className: "w-full flex flex-col grow", children: /* @__PURE__ */ p("div", { className: "flex flex-row items-center gap-2", children: [
311
311
  t && /* @__PURE__ */ s(
312
- Pe,
312
+ Me,
313
313
  {
314
314
  size: "small",
315
315
  className: "text-base grow",
@@ -319,13 +319,13 @@ function xt({
319
319
  }
320
320
  }
321
321
  ),
322
- /* @__PURE__ */ s(K, { onClick: n, size: "small", children: /* @__PURE__ */ s(Me, { size: "small" }) })
322
+ /* @__PURE__ */ s(K, { onClick: n, size: "small", children: /* @__PURE__ */ s($e, { size: "small" }) })
323
323
  ] }) })
324
324
  ]
325
325
  }
326
326
  ) });
327
327
  }
328
- function it({
328
+ function st({
329
329
  importConfig: e,
330
330
  collection: r,
331
331
  onImportSuccess: n
@@ -345,7 +345,7 @@ function it({
345
345
  }
346
346
  return le(() => {
347
347
  l();
348
- }, []), /* @__PURE__ */ p($e, { className: "flex flex-col gap-4 items-center", children: [
348
+ }, []), /* @__PURE__ */ p(_e, { className: "flex flex-col gap-4 items-center", children: [
349
349
  /* @__PURE__ */ s(ue, {}),
350
350
  /* @__PURE__ */ s(h, { variant: "h6", children: "Saving data" }),
351
351
  /* @__PURE__ */ p(h, { variant: "body2", children: [
@@ -369,12 +369,12 @@ function we(e, r, n, t = 0, a = 25, i) {
369
369
  status: "new"
370
370
  }))).then(() => t + a < n.length ? (i(t + a), we(e, r, n, t + a, a, i)) : (i(n.length), Promise.resolve()));
371
371
  }
372
- function st({
372
+ function ot({
373
373
  collection: e,
374
374
  path: r,
375
375
  collectionEntitiesCount: n
376
376
  }) {
377
- const t = G(), a = _e(), [i, o] = w.useState(!1), [l, d] = w.useState("initial"), c = Qe(), f = b(() => {
377
+ const t = G(), a = Le(), [i, o] = w.useState(!1), [l, d] = w.useState("initial"), c = Ye(), f = b(() => {
378
378
  o(!0), d("initial");
379
379
  }, [o]), m = b(() => {
380
380
  o(!1);
@@ -384,7 +384,7 @@ function st({
384
384
  d("import_data_saving");
385
385
  }, []), N = async (g) => {
386
386
  if (c.setImportData(g), g.length > 0) {
387
- const I = await qe(g, et);
387
+ const I = await Qe(g, tt);
388
388
  c.setOriginProperties(I);
389
389
  const L = De(g);
390
390
  c.setHeadersMapping(L);
@@ -401,9 +401,9 @@ function st({
401
401
  collection: e,
402
402
  path: r,
403
403
  fields: t.propertyConfigs
404
- }), x = Le($.properties, $.propertiesOrder), J = Object.entries(x).flatMap(([g, I]) => Ce(g, I, 0)), _ = $.propertiesOrder ?? Object.keys($.properties);
404
+ }), x = Re($.properties, $.propertiesOrder), J = Object.entries(x).flatMap(([g, I]) => Ce(g, I, 0)), _ = $.propertiesOrder ?? Object.keys($.properties);
405
405
  return e.collectionGroup ? null : /* @__PURE__ */ p(P, { children: [
406
- /* @__PURE__ */ s(ee, { title: "Import", children: /* @__PURE__ */ s(K, { color: "primary", onClick: f, children: /* @__PURE__ */ s(Re, {}) }) }),
406
+ /* @__PURE__ */ s(ee, { title: "Import", children: /* @__PURE__ */ s(K, { color: "primary", onClick: f, children: /* @__PURE__ */ s(Be, {}) }) }),
407
407
  /* @__PURE__ */ p(
408
408
  ge,
409
409
  {
@@ -416,12 +416,12 @@ function st({
416
416
  l === "initial" && /* @__PURE__ */ p(P, { children: [
417
417
  /* @__PURE__ */ s(h, { variant: "h6", children: "Import data" }),
418
418
  /* @__PURE__ */ s(h, { variant: "body2", children: "Upload a CSV, Excel or JSON file and map it to your existing schema" }),
419
- /* @__PURE__ */ s(at, { onDataAdded: N })
419
+ /* @__PURE__ */ s(it, { onDataAdded: N })
420
420
  ] }),
421
421
  l === "mapping" && /* @__PURE__ */ p(P, { children: [
422
422
  /* @__PURE__ */ s(h, { variant: "h6", children: "Map fields" }),
423
423
  /* @__PURE__ */ s(
424
- rt,
424
+ nt,
425
425
  {
426
426
  headersMapping: c.headersMapping,
427
427
  idColumn: c.idColumn,
@@ -434,7 +434,7 @@ function st({
434
434
  propertyKey: L,
435
435
  importKey: C
436
436
  }) => /* @__PURE__ */ s(
437
- ot,
437
+ lt,
438
438
  {
439
439
  selectedPropertyKey: L ?? "",
440
440
  properties: x,
@@ -453,7 +453,7 @@ function st({
453
453
  )
454
454
  ] }),
455
455
  l === "preview" && /* @__PURE__ */ s(
456
- lt,
456
+ ct,
457
457
  {
458
458
  importConfig: c,
459
459
  properties: x,
@@ -461,7 +461,7 @@ function st({
461
461
  }
462
462
  ),
463
463
  l === "import_data_saving" && c && /* @__PURE__ */ s(
464
- it,
464
+ st,
465
465
  {
466
466
  importConfig: c,
467
467
  collection: e,
@@ -522,7 +522,7 @@ function st({
522
522
  ] });
523
523
  }
524
524
  const W = "__internal_id__";
525
- function ot({
525
+ function lt({
526
526
  selectedPropertyKey: e,
527
527
  properties: r,
528
528
  onPropertySelected: n,
@@ -593,7 +593,7 @@ function ie({
593
593
  {
594
594
  className: "flex flex-row w-full text-start items-center h-full",
595
595
  children: [
596
- new Array(n).fill(0).map((i, o) => /* @__PURE__ */ s("div", { className: B(Be, "ml-8 border-l h-12") }, o)),
596
+ new Array(n).fill(0).map((i, o) => /* @__PURE__ */ s("div", { className: B(He, "ml-8 border-l h-12") }, o)),
597
597
  /* @__PURE__ */ s("div", { className: "m-4", children: /* @__PURE__ */ s(ee, { title: a?.name, children: /* @__PURE__ */ s(fe, { propertyConfig: a }) }) }),
598
598
  /* @__PURE__ */ p("div", { className: "flex flex-col flex-grow p-2 pl-2", children: [
599
599
  /* @__PURE__ */ s(
@@ -620,18 +620,18 @@ function ie({
620
620
  }
621
621
  );
622
622
  }
623
- function lt({
623
+ function ct({
624
624
  importConfig: e,
625
625
  properties: r,
626
626
  propertiesOrder: n
627
627
  }) {
628
628
  le(() => {
629
- const a = tt(e.originProperties, r), i = e.importData.map((o) => Ke(o, e.idColumn, e.headersMapping, r, a, "TEMP_PATH"));
629
+ const a = rt(e.originProperties, r), i = e.importData.map((o) => et(o, e.idColumn, e.headersMapping, r, a, "TEMP_PATH"));
630
630
  e.setEntities(i);
631
631
  }, []);
632
- const t = He();
632
+ const t = Je();
633
633
  return /* @__PURE__ */ s(
634
- Je,
634
+ Ue,
635
635
  {
636
636
  title: /* @__PURE__ */ p("div", { children: [
637
637
  /* @__PURE__ */ s(h, { variant: "subtitle2", children: "Imported data preview" }),
@@ -665,26 +665,26 @@ function De(e) {
665
665
  });
666
666
  }), r;
667
667
  }
668
- function ct(e, r, n, t, a, i, o) {
668
+ function dt(e, r, n, t, a, i, o) {
669
669
  const l = n.properties;
670
670
  if (i === "csv") {
671
- const d = t ? Ue(e.map((u) => u.values)) : {}, c = ft(l, a, d), f = dt(e, r, l, c, o), m = se(c.map((u) => u.label)), y = f.map((u) => se(u));
671
+ const d = t ? Ve(e.map((u) => u.values)) : {}, c = mt(l, a, d), f = pt(e, r, l, c, o), m = se(c.map((u) => u.label)), y = f.map((u) => se(u));
672
672
  oe([m, ...y], `${n.name}.csv`, "text/csv");
673
673
  } else {
674
- const d = pt(e, r, l, o), c = JSON.stringify(d, null, 2);
674
+ const d = ft(e, r, l, o), c = JSON.stringify(d, null, 2);
675
675
  oe([c], `${n.name}.json`, "application/json");
676
676
  }
677
677
  }
678
- function dt(e, r, n, t, a) {
678
+ function pt(e, r, n, t, a) {
679
679
  const i = e.map((o) => ({
680
680
  id: o.id,
681
681
  ...te(o.values, n, "csv", a)
682
682
  }));
683
683
  return r && r.forEach((o, l) => {
684
684
  i[l] = { ...i[l], ...o };
685
- }), i && i.map((o) => t.map((l) => Ve(o, l.key)));
685
+ }), i && i.map((o) => t.map((l) => We(o, l.key)));
686
686
  }
687
- function pt(e, r, n, t) {
687
+ function ft(e, r, n, t) {
688
688
  const a = e.map((i) => ({
689
689
  id: i.id,
690
690
  ...te(i.values, n, "json", t)
@@ -693,7 +693,7 @@ function pt(e, r, n, t) {
693
693
  a[o] = { ...a[o], ...i };
694
694
  }), a;
695
695
  }
696
- function ft(e, r, n) {
696
+ function mt(e, r, n) {
697
697
  const t = [
698
698
  { label: "id", key: "id" },
699
699
  ...Object.entries(e).flatMap(([a, i]) => n && n[a] > 1 ? Array.from(
@@ -735,15 +735,15 @@ function oe(e, r, n) {
735
735
  const t = new Blob(e, { type: n }), a = URL.createObjectURL(t), i = document.createElement("a");
736
736
  i.href = a, i.setAttribute("download", r), i.click();
737
737
  }
738
- const mt = 500;
739
- function ut({
738
+ const ut = 500;
739
+ function ht({
740
740
  collection: e,
741
741
  path: r,
742
742
  collectionEntitiesCount: n,
743
743
  exportAllowed: t,
744
744
  notAllowedView: a
745
745
  }) {
746
- const i = typeof e.exportable == "object" ? e.exportable : void 0, o = w.useRef(/* @__PURE__ */ new Date()), [l, d] = w.useState(!0), [c, f] = w.useState("csv"), [m, y] = w.useState("string"), u = G(), N = me(), x = We().resolveAliasesFrom(r), J = !t || t({
746
+ const i = typeof e.exportable == "object" ? e.exportable : void 0, o = w.useRef(/* @__PURE__ */ new Date()), [l, d] = w.useState(!0), [c, f] = w.useState("csv"), [m, y] = w.useState("string"), u = G(), N = me(), x = ze().resolveAliasesFrom(r), J = !t || t({
747
747
  collectionEntitiesCount: n,
748
748
  path: x,
749
749
  collection: e
@@ -778,13 +778,13 @@ function ut({
778
778
  ...U?.additionalFields?.map((E) => E.key) ?? [],
779
779
  ...F.additionalFields?.map((E) => E.key) ?? []
780
780
  ];
781
- ct(R, X, F, l, q, c, m);
781
+ dt(R, X, F, l, q, c, m);
782
782
  }).catch(C).finally(() => I(!1));
783
783
  }, [N, x, re, l, c, m]), Se = b(() => {
784
784
  ne(_, i), S();
785
785
  }, [ne, _, i, S]);
786
786
  return /* @__PURE__ */ p(P, { children: [
787
- /* @__PURE__ */ s(ee, { title: "Export", children: /* @__PURE__ */ s(K, { color: "primary", onClick: D, children: /* @__PURE__ */ s(ze, {}) }) }),
787
+ /* @__PURE__ */ s(ee, { title: "Export", children: /* @__PURE__ */ s(K, { color: "primary", onClick: D, children: /* @__PURE__ */ s(Ge, {}) }) }),
788
788
  /* @__PURE__ */ p(
789
789
  ge,
790
790
  {
@@ -795,7 +795,7 @@ function ut({
795
795
  /* @__PURE__ */ p(ye, { className: "flex flex-col gap-4 my-4", children: [
796
796
  /* @__PURE__ */ s(h, { variant: "h6", children: "Export data" }),
797
797
  /* @__PURE__ */ s("div", { children: "Download the the content of this table as a CSV" }),
798
- n > mt && /* @__PURE__ */ s(Ge, { color: "warning", children: /* @__PURE__ */ p("div", { children: [
798
+ n > ut && /* @__PURE__ */ s(Xe, { color: "warning", children: /* @__PURE__ */ p("div", { children: [
799
799
  "This collections has a large number of documents (",
800
800
  n,
801
801
  ")."
@@ -903,7 +903,7 @@ function ut({
903
903
  ] })
904
904
  ] }),
905
905
  /* @__PURE__ */ s(
906
- Xe,
906
+ qe,
907
907
  {
908
908
  size: "small",
909
909
  disabled: c !== "csv",
@@ -939,28 +939,28 @@ function ut({
939
939
  )
940
940
  ] });
941
941
  }
942
- function vt(e) {
943
- return {
942
+ function wt(e) {
943
+ return Ie(() => ({
944
944
  name: "Import/Export",
945
945
  collections: {
946
- CollectionActions: [st, ut],
946
+ CollectionActions: [ot, ht],
947
947
  collectionActionsProps: e
948
948
  }
949
- };
949
+ }), [e]);
950
950
  }
951
951
  export {
952
- rt as DataNewPropertiesMapping,
953
- at as ImportFileUpload,
954
- xt as ImportNewPropertyFieldPreview,
955
- it as ImportSaveInProgress,
956
- Ke as convertDataToEntity,
957
- Ye as convertFileToJson,
952
+ nt as DataNewPropertiesMapping,
953
+ it as ImportFileUpload,
954
+ vt as ImportNewPropertyFieldPreview,
955
+ st as ImportSaveInProgress,
956
+ et as convertDataToEntity,
957
+ Ze as convertFileToJson,
958
958
  ve as flattenEntry,
959
- et as getInferenceType,
960
- tt as getPropertiesMapping,
959
+ tt as getInferenceType,
960
+ rt as getPropertiesMapping,
961
961
  Y as processValueMapping,
962
962
  xe as unflattenObject,
963
- Qe as useImportConfig,
964
- vt as useImportExportPlugin
963
+ Ye as useImportConfig,
964
+ wt as useImportExportPlugin
965
965
  };
966
966
  //# sourceMappingURL=index.es.js.map