@firecms/data_import_export 3.0.0-canary.40 → 3.0.0-canary.42

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,53 +1,131 @@
1
- import C, { useState as O, useRef as Ee, useEffect as de, useCallback as b, useMemo as Ie } from "react";
2
- import { jsxs as f, Fragment as M, jsx as o } from "react/jsx-runtime";
3
- import { getPropertyInPath as _, EntityReference as Ae, useSnackbarController as pe, useCustomizationController as X, getFieldConfig as fe, ErrorBoundary as Te, PropertyConfigBadge as me, useDataSource as ue, resolveCollection as he, getPropertiesWithPropertiesOrder as je, useSelectionController as Fe, EntityCollectionTable as Pe, slugify as ke, getArrayValuesCount as Me, getValueInPath as _e, useFireCMSContext as $e, useNavigationController as Re } from "@firecms/core";
4
- import { Table as Le, TableHeader as Be, TableCell as k, TableBody as Je, TableRow as He, Typography as u, ChevronRightIcon as Ue, Select as ge, SelectItem as H, FileUpload as We, UploadIcon as ze, TextField as Ve, IconButton as ee, EditIcon as Ge, CenteredView as ie, Button as E, CircularProgress as ye, Tooltip as te, FileUploadIcon as Xe, Dialog as be, DialogContent as xe, DialogActions as ve, cn as J, defaultBorderMixin as qe, GetAppIcon as Qe, Alert as Ye, focusedMixin as z, BooleanSwitchWithLabel as Ze } from "@firecms/ui";
5
- import { buildEntityPropertiesFromData as Ke } from "@firecms/schema_inference";
6
- import * as oe from "xlsx";
7
- const et = () => {
8
- const [e, r] = O(!1), [a, t] = O(), [n, i] = O([]), [s, d] = O([]), [c, l] = O({}), [p, m] = O({});
1
+ import C, { useState as S, useRef as Ee, useEffect as pe, useCallback as b, useMemo as Ie } from "react";
2
+ import { jsxs as f, Fragment as P, jsx as o } from "react/jsx-runtime";
3
+ import { getPropertyInPath as M, EntityReference as Te, useSnackbarController as fe, useCustomizationController as q, getFieldConfig as ue, ErrorBoundary as _e, PropertyConfigBadge as me, useDataSource as he, resolveCollection as ge, getPropertiesWithPropertiesOrder as je, useSelectionController as ke, EntityCollectionTable as Fe, slugify as Pe, getArrayValuesCount as Me, getValueInPath as $e, useFireCMSContext as Re, useNavigationController as Le } from "@firecms/core";
4
+ import { Table as Je, TableHeader as Be, TableCell as F, TableBody as He, TableRow as Ue, Typography as h, ChevronRightIcon as We, Select as ye, SelectItem as H, FileUpload as ze, UploadIcon as Ve, TextField as Xe, IconButton as te, EditIcon as Ge, CenteredView as oe, Button as N, CircularProgress as be, Tooltip as re, FileUploadIcon as qe, Dialog as xe, DialogContent as ve, DialogActions as Ce, cn as B, defaultBorderMixin as Qe, GetAppIcon as Ye, Alert as Ze, focusedMixin as V, BooleanSwitchWithLabel as Ke } from "@firecms/ui";
5
+ import { buildEntityPropertiesFromData as et } from "@firecms/schema_inference";
6
+ import * as U from "xlsx";
7
+ const tt = () => {
8
+ const [e, r] = S(!1), [a, t] = S(), [n, i] = S([]), [s, c] = S([]), [l, d] = S({}), [p, u] = S([]), [m, g] = S({});
9
9
  return {
10
10
  inUse: e,
11
11
  setInUse: r,
12
12
  idColumn: a,
13
13
  setIdColumn: t,
14
14
  entities: s,
15
- setEntities: d,
15
+ setEntities: c,
16
16
  importData: n,
17
17
  setImportData: i,
18
- headersMapping: c,
19
- setHeadersMapping: l,
20
- originProperties: p,
21
- setOriginProperties: m
18
+ headingsOrder: (p ?? []).length > 0 ? p : Object.keys(l),
19
+ setHeadingsOrder: u,
20
+ headersMapping: l,
21
+ setHeadersMapping: d,
22
+ originProperties: m,
23
+ setOriginProperties: g
22
24
  };
23
25
  };
24
- function tt(e) {
26
+ function rt(e) {
27
+ let r = 0;
28
+ const a = [], t = {};
29
+ if (e == null || e["!ref"] == null)
30
+ return [];
31
+ const n = t.range !== void 0 ? t.range : e["!ref"];
32
+ let i;
33
+ switch (t.header === 1 ? r = 1 : t.header === "A" ? r = 2 : Array.isArray(t.header) && (r = 3), typeof n) {
34
+ case "string":
35
+ i = se(n);
36
+ break;
37
+ case "number":
38
+ i = se(e["!ref"]), i.s.r = n;
39
+ break;
40
+ default:
41
+ i = n;
42
+ }
43
+ const s = U.utils.encode_row(i.s.r), c = new Array(i.e.c - i.s.c + 1);
44
+ for (let l = i.s.c; l <= i.e.c; ++l) {
45
+ c[l] = U.utils.encode_col(l);
46
+ const d = e[c[l] + s];
47
+ switch (r) {
48
+ case 1:
49
+ a.push(l);
50
+ break;
51
+ case 2:
52
+ a.push(c[l]);
53
+ break;
54
+ case 3:
55
+ a.push(t.header[l - i.s.c]);
56
+ break;
57
+ default:
58
+ if (d === void 0)
59
+ continue;
60
+ a.push(U.utils.format_cell(d));
61
+ }
62
+ }
63
+ return a;
64
+ }
65
+ function se(e) {
66
+ const r = {
67
+ s: {
68
+ c: 0,
69
+ r: 0
70
+ },
71
+ e: {
72
+ c: 0,
73
+ r: 0
74
+ }
75
+ };
76
+ let a = 0, t = 0, n = 0;
77
+ const i = e.length;
78
+ for (a = 0; t < i && !((n = e.charCodeAt(t) - 64) < 1 || n > 26); ++t)
79
+ a = 26 * a + n;
80
+ for (r.s.c = --a, a = 0; t < i && !((n = e.charCodeAt(t) - 48) < 0 || n > 9); ++t)
81
+ a = 10 * a + n;
82
+ if (r.s.r = --a, t === i || e.charCodeAt(++t) === 58)
83
+ return r.e.c = r.s.c, r.e.r = r.s.r, r;
84
+ for (a = 0; t !== i && !((n = e.charCodeAt(t) - 64) < 1 || n > 26); ++t)
85
+ a = 26 * a + n;
86
+ for (r.e.c = --a, a = 0; t !== i && !((n = e.charCodeAt(t) - 48) < 0 || n > 9); ++t)
87
+ a = 10 * a + n;
88
+ return r.e.r = --a, r;
89
+ }
90
+ function nt(e) {
25
91
  return new Promise((r, a) => {
26
92
  if (e.type === "application/json") {
27
93
  console.debug("Converting JSON file to JSON", e.name);
28
94
  const t = new FileReader();
29
95
  t.onload = function(n) {
30
- const i = n.target?.result, s = JSON.parse(i);
31
- Array.isArray(s) || a(new Error("JSON file should contain an array of objects")), r(s);
96
+ try {
97
+ const i = n.target?.result, s = JSON.parse(i);
98
+ if (!Array.isArray(s))
99
+ a(new Error("JSON file should contain an array of objects"));
100
+ else {
101
+ const c = s.length > 0 ? Object.keys(s[0]) : [];
102
+ r({
103
+ data: s,
104
+ propertiesOrder: c
105
+ });
106
+ }
107
+ } catch (i) {
108
+ console.error("Error parsing JSON file", i), a(i);
109
+ }
32
110
  }, t.readAsText(e);
33
111
  } else {
34
112
  console.debug("Converting Excel file to JSON", e.name);
35
113
  const t = new FileReader();
36
114
  t.onload = function(n) {
37
- const i = new Uint8Array(n.target?.result), s = oe.read(
38
- i,
39
- {
40
- type: "array",
41
- codepage: 65001,
42
- cellDates: !0
43
- }
44
- ), d = s.SheetNames[0], c = s.Sheets[d], m = oe.utils.sheet_to_json(c).map(rt).map(Ce);
45
- r(m);
115
+ const i = new Uint8Array(n.target?.result), s = U.read(i, {
116
+ type: "array",
117
+ codepage: 65001,
118
+ cellDates: !0
119
+ }), c = s.SheetNames[0], l = s.Sheets[c], d = U.utils.sheet_to_json(l), p = rt(l), m = d.map(at).map(we);
120
+ r({
121
+ data: m,
122
+ propertiesOrder: p
123
+ });
46
124
  }, t.readAsArrayBuffer(e);
47
125
  }
48
126
  });
49
127
  }
50
- function rt(e) {
128
+ function at(e) {
51
129
  return Object.keys(e).reduce((r, a) => {
52
130
  try {
53
131
  r[a] = JSON.parse(e[a]);
@@ -57,46 +135,46 @@ function rt(e) {
57
135
  return r;
58
136
  }, {});
59
137
  }
60
- function Ce(e) {
138
+ function we(e) {
61
139
  return Object.keys(e).reduce((r, a) => {
62
140
  let t = r;
63
141
  const n = a.split(".");
64
142
  return n.forEach((i, s) => {
65
143
  if (/^[\w]+\[\d+\]$/.test(i)) {
66
- const d = i.slice(0, i.indexOf("[")), c = parseInt(i.slice(i.indexOf("[") + 1, i.indexOf("]")));
67
- t[d] || (t[d] = []), s !== n.length - 1 ? (t[d][c] = t[d][c] || {}, t = t[d][c]) : t[d][c] = e[a];
144
+ const c = i.slice(0, i.indexOf("[")), l = parseInt(i.slice(i.indexOf("[") + 1, i.indexOf("]")));
145
+ t[c] || (t[c] = []), s !== n.length - 1 ? (t[c][l] = t[c][l] || {}, t = t[c][l]) : t[c][l] = e[a];
68
146
  } else
69
147
  s !== n.length - 1 ? (t[i] = t[i] || {}, t = t[i]) : t[i] = e[a];
70
148
  }), r;
71
149
  }, {});
72
150
  }
73
- function nt(e, r, a, t, n, i) {
74
- const s = we(e);
151
+ function it(e, r, a, t, n, i) {
152
+ const s = Se(e);
75
153
  r && delete s[r];
76
- const d = Object.entries(s).map(([p, m]) => {
77
- const h = a[p] ?? p;
78
- if (!_(t, h))
154
+ const c = Object.entries(s).map(([p, u]) => {
155
+ const m = a[p] ?? p;
156
+ if (!M(t, m))
79
157
  return {};
80
- const I = n[h];
81
- let A = m;
82
- return I && (A = Z(m, I)), {
83
- [h]: A
158
+ const E = n[m];
159
+ let I = u;
160
+ return E && (I = K(u, E)), {
161
+ [m]: I
84
162
  };
85
- }).reduce((p, m) => ({ ...p, ...m }), {}), c = Ce(d);
86
- let l = r ? e[r] : void 0;
87
- return typeof l == "string" ? l = l.trim() : typeof l == "number" || typeof l == "boolean" ? l = l.toString() : l instanceof Date ? l = l.toISOString() : l && "toString" in l && (l = l.toString()), {
88
- id: l,
89
- values: c,
163
+ }).reduce((p, u) => ({ ...p, ...u }), {}), l = we(c);
164
+ let d = r ? e[r] : void 0;
165
+ return typeof d == "string" ? d = d.trim() : typeof d == "number" || typeof d == "boolean" ? d = d.toString() : d instanceof Date ? d = d.toISOString() : d && "toString" in d && (d = d.toString()), {
166
+ id: d,
167
+ values: l,
90
168
  path: i
91
169
  };
92
170
  }
93
- function we(e, r = "") {
171
+ function Se(e, r = "") {
94
172
  return Object.keys(e).reduce((a, t) => {
95
173
  const n = r ? `${r}.${t}` : t;
96
- return typeof e[t] == "object" && e[t] !== null && !Array.isArray(e[t]) ? Object.assign(a, we(e[t], n)) : a[n] = e[t], a;
174
+ return typeof e[t] == "object" && e[t] !== null && !Array.isArray(e[t]) ? Object.assign(a, Se(e[t], n)) : a[n] = e[t], a;
97
175
  }, {});
98
176
  }
99
- function Z(e, r) {
177
+ function K(e, r) {
100
178
  if (r === void 0)
101
179
  return e;
102
180
  const {
@@ -104,14 +182,14 @@ function Z(e, r) {
104
182
  to: t
105
183
  } = r;
106
184
  if (a === "array" && t === "array" && r.fromSubtype && r.toSubtype && Array.isArray(e))
107
- return e.map((n) => Z(n, {
185
+ return e.map((n) => K(n, {
108
186
  from: r.fromSubtype,
109
187
  to: r.toSubtype
110
188
  }));
111
189
  if (a === "string" && t === "number" && typeof e == "string")
112
190
  return Number(e);
113
191
  if (a === "string" && t === "array" && r.toSubtype && typeof e == "string")
114
- return e.split(",").map((n) => Z(n, {
192
+ return e.split(",").map((n) => K(n, {
115
193
  from: "string",
116
194
  to: r.toSubtype
117
195
  }));
@@ -144,7 +222,7 @@ function Z(e, r) {
144
222
  }
145
223
  else if (a === "string" && t === "reference" && typeof e == "string") {
146
224
  const n = e.split("/").slice(0, -1).join("/"), i = e.split("/").slice(-1)[0];
147
- return new Ae(i, n);
225
+ return new Te(i, n);
148
226
  } else {
149
227
  if (a === t)
150
228
  return e;
@@ -154,29 +232,29 @@ function Z(e, r) {
154
232
  }
155
233
  return e;
156
234
  }
157
- function at(e) {
235
+ function ot(e) {
158
236
  return typeof e == "number" ? "number" : typeof e == "string" ? "string" : typeof e == "boolean" ? "boolean" : e instanceof Date ? "date" : Array.isArray(e) ? "array" : "map";
159
237
  }
160
- function it(e, r) {
238
+ function st(e, r) {
161
239
  function a(t, n) {
162
240
  const i = {};
163
241
  return Object.keys(t).forEach((s) => {
164
- const d = n ? `${n}.${s}` : s, c = _(t, s), l = _(e, d);
165
- if (c) {
166
- if (c.dataType === "map" && c.properties) {
167
- const p = a(c.properties, d);
168
- Object.keys(p).forEach((m) => {
169
- i[`${d}.${m}`] = p[m];
242
+ const c = n ? `${n}.${s}` : s, l = M(t, s), d = M(e, c);
243
+ if (l) {
244
+ if (l.dataType === "map" && l.properties) {
245
+ const p = a(l.properties, c);
246
+ Object.keys(p).forEach((u) => {
247
+ i[`${c}.${u}`] = p[u];
170
248
  });
171
249
  return;
172
250
  }
173
- if (l) {
174
- const p = l.dataType, m = c.dataType;
175
- let h, g;
176
- c.dataType === "array" && c.of && (g = c.of.dataType), l?.dataType === "array" && l?.of && (h = l.of.dataType), (p !== m || h !== g) && (i[s] = {
251
+ if (d) {
252
+ const p = d.dataType, u = l.dataType;
253
+ let m, g;
254
+ l.dataType === "array" && l.of && (g = l.of.dataType), d?.dataType === "array" && d?.of && (m = d.of.dataType), (p !== u || m !== g) && (i[s] = {
177
255
  from: p,
178
- to: m,
179
- fromSubtype: h,
256
+ to: u,
257
+ fromSubtype: m,
180
258
  toSubtype: g
181
259
  });
182
260
  }
@@ -185,39 +263,44 @@ function it(e, r) {
185
263
  }
186
264
  return a(r);
187
265
  }
188
- function ot({
266
+ function lt({
189
267
  idColumn: e,
190
268
  headersMapping: r,
191
- originProperties: a,
192
- destinationProperties: t,
193
- onIdPropertyChanged: n,
194
- buildPropertyView: i
269
+ headingsOrder: a,
270
+ originProperties: t,
271
+ destinationProperties: n,
272
+ onIdPropertyChanged: i,
273
+ buildPropertyView: s
195
274
  }) {
196
- return /* @__PURE__ */ f(M, { children: [
275
+ return console.log({
276
+ headersMapping: r,
277
+ headingsOrder: a
278
+ }), /* @__PURE__ */ f(P, { children: [
197
279
  /* @__PURE__ */ o(
198
- st,
280
+ ct,
199
281
  {
200
282
  idColumn: e,
201
283
  headersMapping: r,
202
- onChange: n
284
+ onChange: i
203
285
  }
204
286
  ),
205
- /* @__PURE__ */ f(Le, { style: {
287
+ /* @__PURE__ */ o("div", { className: "h-4" }),
288
+ /* @__PURE__ */ f(Je, { style: {
206
289
  tableLayout: "fixed"
207
290
  }, children: [
208
291
  /* @__PURE__ */ f(Be, { children: [
209
- /* @__PURE__ */ o(k, { header: !0, style: { width: "20%" }, children: "Column in file" }),
210
- /* @__PURE__ */ o(k, { header: !0 }),
211
- /* @__PURE__ */ o(k, { header: !0, style: { width: "75%" }, children: "Property" })
292
+ /* @__PURE__ */ o(F, { header: !0, style: { width: "20%" }, children: "Column in file" }),
293
+ /* @__PURE__ */ o(F, { header: !0 }),
294
+ /* @__PURE__ */ o(F, { header: !0, style: { width: "75%" }, children: "Map to Property" })
212
295
  ] }),
213
- /* @__PURE__ */ o(Je, { children: t && Object.entries(r).map(
214
- ([s, d]) => {
215
- const c = r[s], l = d ? _(t, d) : null, p = _(a, s), m = p ? p.dataType === "array" && typeof p.of == "object" ? `${p.dataType} - ${p.of.dataType}` : p.dataType : void 0;
216
- return /* @__PURE__ */ f(He, { style: { height: "90px" }, children: [
217
- /* @__PURE__ */ f(k, { style: { width: "20%" }, children: [
218
- /* @__PURE__ */ o(u, { variant: "body2", children: s }),
219
- p && /* @__PURE__ */ o(
220
- u,
296
+ /* @__PURE__ */ o(He, { children: n && a.map(
297
+ (c) => {
298
+ const l = r[c], d = r[c], p = l ? M(n, l) : null, u = M(t, c), m = u ? u.dataType === "array" && typeof u.of == "object" ? `${u.dataType} - ${u.of.dataType}` : u.dataType : void 0;
299
+ return /* @__PURE__ */ f(Ue, { style: { height: "90px" }, children: [
300
+ /* @__PURE__ */ f(F, { style: { width: "20%" }, children: [
301
+ /* @__PURE__ */ o(h, { variant: "body2", children: c }),
302
+ u && /* @__PURE__ */ o(
303
+ h,
221
304
  {
222
305
  variant: "caption",
223
306
  color: "secondary",
@@ -225,53 +308,54 @@ function ot({
225
308
  }
226
309
  )
227
310
  ] }),
228
- /* @__PURE__ */ o(k, { children: /* @__PURE__ */ o(Ue, {}) }),
311
+ /* @__PURE__ */ o(F, { children: /* @__PURE__ */ o(We, {}) }),
229
312
  /* @__PURE__ */ o(
230
- k,
313
+ F,
231
314
  {
232
- className: s === e ? "text-center" : void 0,
315
+ className: c === e ? "text-center" : void 0,
233
316
  style: { width: "75%" },
234
- children: i?.({
235
- isIdColumn: s === e,
236
- property: l,
237
- propertyKey: c,
238
- importKey: s
317
+ children: s?.({
318
+ isIdColumn: c === e,
319
+ property: p,
320
+ propertyKey: d,
321
+ importKey: c
239
322
  })
240
323
  }
241
324
  )
242
- ] }, s);
325
+ ] }, c);
243
326
  }
244
327
  ) })
245
328
  ] })
246
329
  ] });
247
330
  }
248
- function st({
331
+ function ct({
249
332
  idColumn: e,
250
333
  headersMapping: r,
251
334
  onChange: a
252
335
  }) {
253
336
  return /* @__PURE__ */ o("div", { children: /* @__PURE__ */ f(
254
- ge,
337
+ ye,
255
338
  {
256
339
  size: "small",
257
340
  value: e ?? "",
258
341
  onChange: (t) => {
259
342
  const n = t.target.value;
260
- a(n === "none" ? null : n);
343
+ a(n === "__none__" ? null : n);
261
344
  },
262
- renderValue: (t) => /* @__PURE__ */ o(u, { variant: "body2", children: t !== "" ? t : "Autogenerate ID" }),
345
+ placeholder: "Autogenerate ID",
346
+ renderValue: (t) => /* @__PURE__ */ o(h, { variant: "body2", children: t !== "__none__" ? t : "Autogenerate ID" }),
263
347
  label: "Column that will be used as ID for each document",
264
348
  children: [
265
- /* @__PURE__ */ o(H, { value: "none", children: "Autogenerate ID" }),
349
+ /* @__PURE__ */ o(H, { value: "__none__", children: "Autogenerate ID" }),
266
350
  Object.entries(r).map(([t, n]) => /* @__PURE__ */ o(H, { value: t, children: t }, t))
267
351
  ]
268
352
  }
269
353
  ) });
270
354
  }
271
- function lt({ onDataAdded: e }) {
272
- const r = pe();
355
+ function dt({ onDataAdded: e }) {
356
+ const r = fe();
273
357
  return /* @__PURE__ */ o(
274
- We,
358
+ ze,
275
359
  {
276
360
  accept: {
277
361
  "text/*": [".csv", ".xls", ".xlsx"],
@@ -286,21 +370,27 @@ function lt({ onDataAdded: e }) {
286
370
  preventDropOnDocument: !0,
287
371
  size: "small",
288
372
  maxFiles: 1,
289
- uploadDescription: /* @__PURE__ */ f(M, { children: [
290
- /* @__PURE__ */ o(ze, {}),
373
+ uploadDescription: /* @__PURE__ */ f(P, { children: [
374
+ /* @__PURE__ */ o(Ve, {}),
291
375
  "Drag and drop a file here or click to upload"
292
376
  ] }),
293
377
  onFilesAdded: (a) => {
294
- a.length > 0 && tt(a[0]).then((t) => {
295
- e(t);
378
+ a.length > 0 && nt(a[0]).then(({
379
+ data: t,
380
+ propertiesOrder: n
381
+ }) => {
382
+ e(t, n);
296
383
  }).catch((t) => {
297
- console.error("Error parsing file", t), r.open({ type: "error", message: t.message });
384
+ console.error("Error parsing file", t), r.open({
385
+ type: "error",
386
+ message: t.message
387
+ });
298
388
  });
299
389
  }
300
390
  }
301
391
  );
302
392
  }
303
- function Dt({
393
+ function At({
304
394
  propertyKey: e,
305
395
  property: r,
306
396
  onEditClick: a,
@@ -308,144 +398,145 @@ function Dt({
308
398
  onPropertyNameChanged: n,
309
399
  propertyTypeView: i
310
400
  }) {
311
- const { propertyConfigs: s } = X(), d = r ? fe(r, s) : null;
312
- return /* @__PURE__ */ o(Te, { children: /* @__PURE__ */ f(
401
+ const { propertyConfigs: s } = q(), c = r ? ue(r, s) : null;
402
+ return /* @__PURE__ */ o(_e, { children: /* @__PURE__ */ f(
313
403
  "div",
314
404
  {
315
405
  className: "flex flex-row w-full items-center",
316
406
  children: [
317
- /* @__PURE__ */ o("div", { className: "mx-4", children: i ?? /* @__PURE__ */ o(me, { propertyConfig: d ?? void 0 }) }),
407
+ /* @__PURE__ */ o("div", { className: "mx-4", children: i ?? /* @__PURE__ */ o(me, { propertyConfig: c ?? void 0 }) }),
318
408
  /* @__PURE__ */ o("div", { className: "w-full flex flex-col grow", children: /* @__PURE__ */ f("div", { className: "flex flex-row items-center gap-2", children: [
319
409
  t && /* @__PURE__ */ o(
320
- Ve,
410
+ Xe,
321
411
  {
322
412
  size: "small",
323
413
  className: "text-base grow",
324
414
  value: r?.name ?? "",
325
- onChange: (c) => {
326
- n && e && n(e, c.target.value);
415
+ onChange: (l) => {
416
+ n && e && n(e, l.target.value);
327
417
  }
328
418
  }
329
419
  ),
330
- /* @__PURE__ */ o(ee, { onClick: a, size: "small", children: /* @__PURE__ */ o(Ge, { size: "small" }) })
420
+ /* @__PURE__ */ o(te, { onClick: a, size: "small", children: /* @__PURE__ */ o(Ge, { size: "small" }) })
331
421
  ] }) })
332
422
  ]
333
423
  }
334
424
  ) });
335
425
  }
336
- function ct({
426
+ function pt({
337
427
  path: e,
338
428
  importConfig: r,
339
429
  collection: a,
340
430
  onImportSuccess: t
341
431
  }) {
342
- const [n, i] = O(void 0), s = ue(), d = Ee(!1), [c, l] = O(0);
432
+ const [n, i] = S(void 0), s = he(), c = Ee(!1), [l, d] = S(0);
343
433
  function p() {
344
- d.current || (d.current = !0, Se(
434
+ c.current || (c.current = !0, De(
345
435
  s,
346
436
  a,
347
437
  e,
348
438
  r.entities,
349
439
  0,
350
440
  25,
351
- l
441
+ d
352
442
  ).then(() => {
353
- t(a), d.current = !1;
354
- }).catch((m) => {
355
- i(m), d.current = !1;
443
+ t(a), c.current = !1;
444
+ }).catch((u) => {
445
+ i(u), c.current = !1;
356
446
  }));
357
447
  }
358
- return de(() => {
448
+ return pe(() => {
359
449
  p();
360
- }, []), n ? /* @__PURE__ */ f(ie, { className: "flex flex-col gap-4 items-center", children: [
361
- /* @__PURE__ */ o(u, { variant: "h6", children: "Error saving data" }),
362
- /* @__PURE__ */ o(u, { variant: "body2", color: "error", children: n.message }),
450
+ }, []), n ? /* @__PURE__ */ f(oe, { className: "flex flex-col gap-4 items-center", children: [
451
+ /* @__PURE__ */ o(h, { variant: "h6", children: "Error saving data" }),
452
+ /* @__PURE__ */ o(h, { variant: "body2", color: "error", children: n.message }),
363
453
  /* @__PURE__ */ o(
364
- E,
454
+ N,
365
455
  {
366
456
  onClick: p,
367
457
  variant: "outlined",
368
458
  children: "Retry"
369
459
  }
370
460
  )
371
- ] }) : /* @__PURE__ */ f(ie, { className: "flex flex-col gap-4 items-center", children: [
372
- /* @__PURE__ */ o(ye, {}),
373
- /* @__PURE__ */ o(u, { variant: "h6", children: "Saving data" }),
374
- /* @__PURE__ */ f(u, { variant: "body2", children: [
375
- c,
461
+ ] }) : /* @__PURE__ */ f(oe, { className: "flex flex-col gap-4 items-center", children: [
462
+ /* @__PURE__ */ o(be, {}),
463
+ /* @__PURE__ */ o(h, { variant: "h6", children: "Saving data" }),
464
+ /* @__PURE__ */ f(h, { variant: "body2", children: [
465
+ l,
376
466
  "/",
377
467
  r.entities.length,
378
468
  " entities saved"
379
469
  ] }),
380
- /* @__PURE__ */ o(u, { variant: "caption", children: "Do not close this tab or the import will be interrupted." })
470
+ /* @__PURE__ */ o(h, { variant: "caption", children: "Do not close this tab or the import will be interrupted." })
381
471
  ] });
382
472
  }
383
- function Se(e, r, a, t, n = 0, i = 25, s) {
473
+ function De(e, r, a, t, n = 0, i = 25, s) {
384
474
  console.debug("Saving imported data", n, i);
385
- const d = t.slice(n, n + i);
386
- return Promise.all(d.map((c) => e.saveEntity({
475
+ const c = t.slice(n, n + i);
476
+ return Promise.all(c.map((l) => e.saveEntity({
387
477
  path: a,
388
- values: c.values,
389
- entityId: c.id,
478
+ values: l.values,
479
+ entityId: l.id,
390
480
  collection: r,
391
481
  status: "new"
392
- }))).then(() => n + i < t.length ? (s(n + i), Se(e, r, a, t, n + i, i, s)) : (s(t.length), Promise.resolve()));
482
+ }))).then(() => n + i < t.length ? (s(n + i), De(e, r, a, t, n + i, i, s)) : (s(t.length), Promise.resolve()));
393
483
  }
394
- function dt({
484
+ function ft({
395
485
  collection: e,
396
486
  path: r,
397
487
  collectionEntitiesCount: a,
398
488
  onAnalyticsEvent: t
399
489
  }) {
400
- const n = X(), i = pe(), [s, d] = C.useState(!1), [c, l] = C.useState("initial"), p = et(), m = b(() => {
401
- d(!0), l("initial");
402
- }, [d]), h = b(() => {
403
- d(!1);
404
- }, [d]), g = b(() => {
405
- l("preview");
406
- }, []), I = b(() => {
407
- l("import_data_saving");
408
- }, []), A = async (y) => {
490
+ const n = q(), i = fe(), [s, c] = C.useState(!1), [l, d] = C.useState("initial"), p = tt(), u = b(() => {
491
+ c(!0), d("initial");
492
+ }, [c]), m = b(() => {
493
+ c(!1);
494
+ }, [c]), g = b(() => {
495
+ d("preview");
496
+ }, []), E = b(() => {
497
+ d("import_data_saving");
498
+ }, []), I = async (y) => {
409
499
  if (p.setImportData(y), y.length > 0) {
410
- const T = await Ke(y, at);
500
+ const T = await et(y, ot);
411
501
  p.setOriginProperties(T);
412
- const L = Ne(y, e?.properties);
502
+ const L = Ae(y, e?.properties);
413
503
  p.setHeadersMapping(L);
414
504
  const w = Object.keys(L)?.[0];
415
505
  (w?.includes("id") || w?.includes("key")) && p.setIdColumn(w);
416
506
  }
417
507
  setTimeout(() => {
418
- l("mapping");
508
+ d("mapping");
419
509
  }, 100);
420
- }, $ = he({
510
+ }, $ = ge({
421
511
  collection: e,
422
512
  path: r,
423
513
  fields: n.propertyConfigs
424
- }), x = je($.properties, $.propertiesOrder), U = Object.entries(x).flatMap(([y, T]) => De(y, T, 0)), R = $.propertiesOrder ?? Object.keys($.properties);
425
- return e.collectionGroup ? null : /* @__PURE__ */ f(M, { children: [
426
- /* @__PURE__ */ o(te, { title: "Import", children: /* @__PURE__ */ o(ee, { color: "primary", onClick: m, children: /* @__PURE__ */ o(Xe, {}) }) }),
514
+ }), x = je($.properties, $.propertiesOrder), W = Object.entries(x).flatMap(([y, T]) => Oe(y, T, 0)), R = $.propertiesOrder ?? Object.keys($.properties);
515
+ return e.collectionGroup ? null : /* @__PURE__ */ f(P, { children: [
516
+ /* @__PURE__ */ o(re, { title: "Import", children: /* @__PURE__ */ o(te, { color: "primary", onClick: u, children: /* @__PURE__ */ o(qe, {}) }) }),
427
517
  /* @__PURE__ */ f(
428
- be,
518
+ xe,
429
519
  {
430
520
  open: s,
431
- fullWidth: c === "preview",
432
- fullHeight: c === "preview",
433
- maxWidth: c === "initial" ? "lg" : "7xl",
521
+ fullWidth: l === "preview",
522
+ fullHeight: l === "preview",
523
+ maxWidth: l === "initial" ? "lg" : "7xl",
434
524
  children: [
435
- /* @__PURE__ */ f(xe, { className: "flex flex-col gap-4 my-4", fullHeight: c === "preview", children: [
436
- c === "initial" && /* @__PURE__ */ f(M, { children: [
437
- /* @__PURE__ */ o(u, { variant: "h6", children: "Import data" }),
438
- /* @__PURE__ */ o(u, { variant: "body2", children: "Upload a CSV, Excel or JSON file and map it to your existing schema" }),
439
- /* @__PURE__ */ o(lt, { onDataAdded: A })
525
+ /* @__PURE__ */ f(ve, { className: "flex flex-col gap-4 my-4", fullHeight: l === "preview", children: [
526
+ l === "initial" && /* @__PURE__ */ f(P, { children: [
527
+ /* @__PURE__ */ o(h, { variant: "h6", children: "Import data" }),
528
+ /* @__PURE__ */ o(h, { variant: "body2", children: "Upload a CSV, Excel or JSON file and map it to your existing schema" }),
529
+ /* @__PURE__ */ o(dt, { onDataAdded: I })
440
530
  ] }),
441
- c === "mapping" && /* @__PURE__ */ f(M, { children: [
442
- /* @__PURE__ */ o(u, { variant: "h6", children: "Map fields" }),
531
+ l === "mapping" && /* @__PURE__ */ f(P, { children: [
532
+ /* @__PURE__ */ o(h, { variant: "h6", children: "Map fields" }),
443
533
  /* @__PURE__ */ o(
444
- ot,
534
+ lt,
445
535
  {
446
536
  headersMapping: p.headersMapping,
447
537
  idColumn: p.idColumn,
448
538
  originProperties: p.originProperties,
539
+ headingsOrder: p.headingsOrder,
449
540
  destinationProperties: x,
450
541
  onIdPropertyChanged: (y) => p.setIdColumn(y ?? void 0),
451
542
  buildPropertyView: ({
@@ -454,40 +545,40 @@ function dt({
454
545
  propertyKey: L,
455
546
  importKey: w
456
547
  }) => /* @__PURE__ */ o(
457
- pt,
548
+ ut,
458
549
  {
459
550
  selectedPropertyKey: L ?? "",
460
551
  properties: x,
461
- propertiesAndLevel: U,
552
+ propertiesAndLevel: W,
462
553
  isIdColumn: y,
463
554
  onIdSelected: () => {
464
555
  p.setIdColumn(w);
465
556
  },
466
- onPropertySelected: (B) => {
467
- const j = Object.entries(p.headersMapping).map(([S, D]) => D === B ? { [S]: null } : S === w ? { [S]: B } : { [S]: D }).reduce((S, D) => ({ ...S, ...D }), {});
468
- p.setHeadersMapping(j), B === p.idColumn && p.setIdColumn(void 0);
557
+ onPropertySelected: (J) => {
558
+ const _ = Object.entries(p.headersMapping).map(([D, O]) => O === J ? { [D]: null } : D === w ? { [D]: J } : { [D]: O }).reduce((D, O) => ({ ...D, ...O }), {});
559
+ p.setHeadersMapping(_), J === p.idColumn && p.setIdColumn(void 0);
469
560
  }
470
561
  }
471
562
  )
472
563
  }
473
564
  )
474
565
  ] }),
475
- c === "preview" && /* @__PURE__ */ o(
476
- ft,
566
+ l === "preview" && /* @__PURE__ */ o(
567
+ mt,
477
568
  {
478
569
  importConfig: p,
479
570
  properties: x,
480
571
  propertiesOrder: R
481
572
  }
482
573
  ),
483
- c === "import_data_saving" && p && /* @__PURE__ */ o(
484
- ct,
574
+ l === "import_data_saving" && p && /* @__PURE__ */ o(
575
+ pt,
485
576
  {
486
577
  importConfig: p,
487
578
  collection: e,
488
579
  path: r,
489
580
  onImportSuccess: (y) => {
490
- h(), i.open({
581
+ m(), i.open({
491
582
  type: "info",
492
583
  message: "Data imported successfully"
493
584
  });
@@ -495,44 +586,44 @@ function dt({
495
586
  }
496
587
  )
497
588
  ] }),
498
- /* @__PURE__ */ f(ve, { children: [
499
- c === "mapping" && /* @__PURE__ */ o(
500
- E,
589
+ /* @__PURE__ */ f(Ce, { children: [
590
+ l === "mapping" && /* @__PURE__ */ o(
591
+ N,
501
592
  {
502
- onClick: () => l("initial"),
593
+ onClick: () => d("initial"),
503
594
  variant: "text",
504
595
  children: "Back"
505
596
  }
506
597
  ),
507
- c === "preview" && /* @__PURE__ */ o(
508
- E,
598
+ l === "preview" && /* @__PURE__ */ o(
599
+ N,
509
600
  {
510
- onClick: () => l("mapping"),
601
+ onClick: () => d("mapping"),
511
602
  variant: "text",
512
603
  children: "Back"
513
604
  }
514
605
  ),
515
606
  /* @__PURE__ */ o(
516
- E,
607
+ N,
517
608
  {
518
- onClick: h,
609
+ onClick: m,
519
610
  variant: "text",
520
611
  children: "Cancel"
521
612
  }
522
613
  ),
523
- c === "mapping" && /* @__PURE__ */ o(
524
- E,
614
+ l === "mapping" && /* @__PURE__ */ o(
615
+ N,
525
616
  {
526
617
  variant: "filled",
527
618
  onClick: g,
528
619
  children: "Next"
529
620
  }
530
621
  ),
531
- c === "preview" && /* @__PURE__ */ o(
532
- E,
622
+ l === "preview" && /* @__PURE__ */ o(
623
+ N,
533
624
  {
534
625
  variant: "filled",
535
- onClick: I,
626
+ onClick: E,
536
627
  children: "Save data"
537
628
  }
538
629
  )
@@ -542,8 +633,8 @@ function dt({
542
633
  )
543
634
  ] });
544
635
  }
545
- const V = "__internal_id__";
546
- function pt({
636
+ const X = "__internal_id__";
637
+ function ut({
547
638
  selectedPropertyKey: e,
548
639
  properties: r,
549
640
  onPropertySelected: a,
@@ -551,74 +642,74 @@ function pt({
551
642
  propertiesAndLevel: n,
552
643
  isIdColumn: i
553
644
  }) {
554
- const s = e ? _(r, e) : null, d = b((l) => l === V ? /* @__PURE__ */ o(u, { variant: "body2", className: "p-4", children: "Use this column as ID" }) : !l || !s ? /* @__PURE__ */ o(u, { variant: "body2", className: "p-4", children: "Do not import this property" }) : /* @__PURE__ */ o(
555
- se,
645
+ const s = e ? M(r, e) : null, c = b((d) => d === X ? /* @__PURE__ */ o(h, { variant: "body2", className: "p-4", children: "Use this column as ID" }) : !d || !s ? /* @__PURE__ */ o(h, { variant: "body2", className: "p-4", children: "Do not import this property" }) : /* @__PURE__ */ o(
646
+ le,
556
647
  {
557
- propertyKey: l,
648
+ propertyKey: d,
558
649
  property: s
559
650
  }
560
- ), [s]), c = b((l) => {
561
- l === V ? (t(), a(null)) : a(l === "__do_not_import" ? null : l);
651
+ ), [s]), l = b((d) => {
652
+ d === X ? (t(), a(null)) : a(d === "__do_not_import" ? null : d);
562
653
  }, []);
563
654
  return /* @__PURE__ */ f(
564
- ge,
655
+ ye,
565
656
  {
566
- value: i ? V : e ?? void 0,
567
- onValueChange: c,
568
- renderValue: d,
657
+ value: i ? X : e ?? void 0,
658
+ onValueChange: l,
659
+ renderValue: c,
569
660
  children: [
570
- /* @__PURE__ */ o(H, { value: "__do_not_import", children: /* @__PURE__ */ o(u, { variant: "body2", className: "p-4", children: "Do not import this property" }) }),
571
- /* @__PURE__ */ o(H, { value: V, children: /* @__PURE__ */ o(u, { variant: "body2", className: "p-4", children: "Use this column as ID" }) }),
661
+ /* @__PURE__ */ o(H, { value: "__do_not_import", children: /* @__PURE__ */ o(h, { variant: "body2", className: "p-4", children: "Do not import this property" }) }),
662
+ /* @__PURE__ */ o(H, { value: X, children: /* @__PURE__ */ o(h, { variant: "body2", className: "p-4", children: "Use this column as ID" }) }),
572
663
  n.map(({
573
- property: l,
664
+ property: d,
574
665
  level: p,
575
- propertyKey: m
666
+ propertyKey: u
576
667
  }) => /* @__PURE__ */ o(
577
668
  H,
578
669
  {
579
- value: m,
580
- disabled: l.dataType === "map",
670
+ value: u,
671
+ disabled: d.dataType === "map",
581
672
  children: /* @__PURE__ */ o(
582
- se,
673
+ le,
583
674
  {
584
- propertyKey: m,
585
- property: l,
675
+ propertyKey: u,
676
+ property: d,
586
677
  level: p
587
678
  }
588
679
  )
589
680
  },
590
- m
681
+ u
591
682
  ))
592
683
  ]
593
684
  }
594
685
  );
595
686
  }
596
- function De(e, r, a) {
687
+ function Oe(e, r, a) {
597
688
  const t = [];
598
689
  return t.push({
599
690
  property: r,
600
691
  level: a,
601
692
  propertyKey: e
602
693
  }), r.dataType === "map" && r.properties && Object.entries(r.properties).forEach(([n, i]) => {
603
- t.push(...De(`${e}.${n}`, i, a + 1));
694
+ t.push(...Oe(`${e}.${n}`, i, a + 1));
604
695
  }), t;
605
696
  }
606
- function se({
697
+ function le({
607
698
  propertyKey: e,
608
699
  property: r,
609
700
  level: a = 0
610
701
  }) {
611
- const { propertyConfigs: t } = X(), n = fe(r, t);
702
+ const { propertyConfigs: t } = q(), n = ue(r, t);
612
703
  return /* @__PURE__ */ f(
613
704
  "div",
614
705
  {
615
706
  className: "flex flex-row w-full text-start items-center h-full",
616
707
  children: [
617
- new Array(a).fill(0).map((i, s) => /* @__PURE__ */ o("div", { className: J(qe, "ml-8 border-l h-12") }, s)),
618
- /* @__PURE__ */ o("div", { className: "m-4", children: /* @__PURE__ */ o(te, { title: n?.name, children: /* @__PURE__ */ o(me, { propertyConfig: n }) }) }),
708
+ new Array(a).fill(0).map((i, s) => /* @__PURE__ */ o("div", { className: B(Qe, "ml-8 border-l h-12") }, s)),
709
+ /* @__PURE__ */ o("div", { className: "m-4", children: /* @__PURE__ */ o(re, { title: n?.name, children: /* @__PURE__ */ o(me, { propertyConfig: n }) }) }),
619
710
  /* @__PURE__ */ f("div", { className: "flex flex-col flex-grow p-2 pl-2", children: [
620
711
  /* @__PURE__ */ o(
621
- u,
712
+ h,
622
713
  {
623
714
  variant: "body1",
624
715
  component: "span",
@@ -627,7 +718,7 @@ function se({
627
718
  }
628
719
  ),
629
720
  /* @__PURE__ */ o(
630
- u,
721
+ h,
631
722
  {
632
723
  className: " pr-2",
633
724
  variant: "body2",
@@ -641,22 +732,22 @@ function se({
641
732
  }
642
733
  );
643
734
  }
644
- function ft({
735
+ function mt({
645
736
  importConfig: e,
646
737
  properties: r,
647
738
  propertiesOrder: a
648
739
  }) {
649
- de(() => {
650
- const n = it(e.originProperties, r), i = e.importData.map((s) => nt(s, e.idColumn, e.headersMapping, r, n, "TEMP_PATH"));
740
+ pe(() => {
741
+ const n = st(e.originProperties, r), i = e.importData.map((s) => it(s, e.idColumn, e.headersMapping, r, n, "TEMP_PATH"));
651
742
  e.setEntities(i);
652
743
  }, []);
653
- const t = Fe();
744
+ const t = ke();
654
745
  return /* @__PURE__ */ o(
655
- Pe,
746
+ Fe,
656
747
  {
657
748
  title: /* @__PURE__ */ f("div", { children: [
658
- /* @__PURE__ */ o(u, { variant: "subtitle2", children: "Imported data preview" }),
659
- /* @__PURE__ */ o(u, { variant: "caption", children: "Entities with the same id will be overwritten" })
749
+ /* @__PURE__ */ o(h, { variant: "subtitle2", children: "Imported data preview" }),
750
+ /* @__PURE__ */ o(h, { variant: "caption", children: "Entities with the same id will be overwritten" })
660
751
  ] }),
661
752
  tableController: {
662
753
  data: e.entities,
@@ -675,15 +766,15 @@ function ft({
675
766
  }
676
767
  );
677
768
  }
678
- function Ne(e, r) {
769
+ function Ae(e, r) {
679
770
  const a = {};
680
771
  return e.filter(Boolean).forEach((t) => {
681
772
  Object.keys(t).forEach((n) => {
682
773
  const i = t[n];
683
774
  if (typeof i == "object" && !Array.isArray(i)) {
684
- const s = r?.[n], d = s && "properties" in s ? s.properties : void 0, c = Ne([i], d);
685
- Object.entries(c).forEach(([l, p]) => {
686
- a[`${n}.${l}`] = `${n}.${p}`;
775
+ const s = r?.[n], c = s && "properties" in s ? s.properties : void 0, l = Ae([i], c);
776
+ Object.entries(l).forEach(([d, p]) => {
777
+ a[`${n}.${d}`] = `${n}.${p}`;
687
778
  });
688
779
  }
689
780
  if (!r)
@@ -691,59 +782,59 @@ function Ne(e, r) {
691
782
  else if (n in r)
692
783
  a[n] = n;
693
784
  else {
694
- const s = ke(n);
785
+ const s = Pe(n);
695
786
  s in r ? a[n] = s : a[n] = n;
696
787
  }
697
788
  });
698
789
  }), a;
699
790
  }
700
- function mt(e, r, a, t, n, i, s) {
791
+ function ht(e, r, a, t, n, i, s) {
701
792
  console.debug("Downloading export", { dataLength: e.length, collection: a, exportType: i, dateExportType: s });
702
- const d = a.properties;
793
+ const c = a.properties;
703
794
  if (i === "csv") {
704
- const c = t ? Me(e.map((g) => g.values)) : {}, l = gt(d, n, c), p = ut(e, r, d, l, s), m = le(l.map((g) => g.label)), h = p.map((g) => le(g));
705
- ce([m, ...h], `${a.name}.csv`, "text/csv");
795
+ const l = t ? Me(e.map((g) => g.values)) : {}, d = bt(c, n, l), p = gt(e, r, c, d, s), u = ce(d.map((g) => g.label)), m = p.map((g) => ce(g));
796
+ de([u, ...m], `${a.name}.csv`, "text/csv");
706
797
  } else {
707
- const c = ht(e, r, d, s), l = JSON.stringify(c, null, 2);
708
- ce([l], `${a.name}.json`, "application/json");
798
+ const l = yt(e, r, c, s), d = JSON.stringify(l, null, 2);
799
+ de([d], `${a.name}.json`, "application/json");
709
800
  }
710
801
  }
711
- function ut(e, r, a, t, n) {
802
+ function gt(e, r, a, t, n) {
712
803
  const i = e.map((s) => ({
713
804
  id: s.id,
714
- ...re(s.values, a, "csv", n)
805
+ ...ne(s.values, a, "csv", n)
715
806
  }));
716
- return r && r.forEach((s, d) => {
717
- i[d] = { ...i[d], ...s };
718
- }), i && i.map((s) => t.map((d) => _e(s, d.key)));
807
+ return r && r.forEach((s, c) => {
808
+ i[c] = { ...i[c], ...s };
809
+ }), i && i.map((s) => t.map((c) => $e(s, c.key)));
719
810
  }
720
- function ht(e, r, a, t) {
811
+ function yt(e, r, a, t) {
721
812
  const n = e.map((i) => ({
722
813
  id: i.id,
723
- ...re(i.values, a, "json", t)
814
+ ...ne(i.values, a, "json", t)
724
815
  }));
725
816
  return r && r.forEach((i, s) => {
726
817
  n[s] = { ...n[s], ...i };
727
818
  }), n;
728
819
  }
729
- function gt(e, r, a) {
820
+ function bt(e, r, a) {
730
821
  const t = [
731
822
  { label: "id", key: "id" },
732
823
  ...Object.entries(e).flatMap(([n, i]) => a && a[n] > 1 ? Array.from(
733
824
  { length: a[n] },
734
- (s, d) => K(i, `${n}[${d}]`, "")
735
- ).flat() : K(i, n, ""))
825
+ (s, c) => ee(i, `${n}[${c}]`, "")
826
+ ).flat() : ee(i, n, ""))
736
827
  ];
737
828
  return r && t.push(...r.map((n) => ({ label: n, key: n }))), t;
738
829
  }
739
- function K(e, r, a = "") {
830
+ function ee(e, r, a = "") {
740
831
  const t = a ? `${a}.${r}` : r;
741
- return e.dataType === "map" && e.properties ? Object.entries(e.properties).map(([n, i]) => K(i, n, t)).flat() : [{ label: t, key: t }];
832
+ return e.dataType === "map" && e.properties ? Object.entries(e.properties).map(([n, i]) => ee(i, n, t)).flat() : [{ label: t, key: t }];
742
833
  }
743
834
  function G(e, r, a, t) {
744
835
  let n;
745
836
  if (r.dataType === "map" && r.properties)
746
- n = re(e, r.properties, a, t);
837
+ n = ne(e, r.properties, a, t);
747
838
  else if (r.dataType === "array")
748
839
  r.of && Array.isArray(e) ? Array.isArray(r.of) ? n = r.of.map((i, s) => G(e[s], i, a, t)) : r.of.dataType === "map" ? n = a === "csv" ? e.map((i) => JSON.stringify(i)) : e.map((i) => G(i, r.of, a, t)) : n = e.map((i) => G(i, r.of, a, t)) : n = e;
749
840
  else if (r.dataType === "reference" && e && e.isEntityReference && e.isEntityReference()) {
@@ -753,84 +844,84 @@ function G(e, r, a, t) {
753
844
  r.dataType === "date" && e instanceof Date ? n = e ? t === "timestamp" ? e.getTime() : e.toISOString() : null : n = e;
754
845
  return n;
755
846
  }
756
- function re(e, r, a, t) {
847
+ function ne(e, r, a, t) {
757
848
  const n = Object.entries(r).map(([i, s]) => {
758
- const d = e && e[i], c = G(d, s, a, t);
759
- return c === void 0 ? {} : { [i]: c };
849
+ const c = e && e[i], l = G(c, s, a, t);
850
+ return l === void 0 ? {} : { [i]: l };
760
851
  }).reduce((i, s) => ({ ...i, ...s }), {});
761
852
  return { ...e, ...n };
762
853
  }
763
- function le(e) {
854
+ function ce(e) {
764
855
  return e.map((r) => r == null ? "" : Array.isArray(r) ? '"' + JSON.stringify(r).replaceAll('"', '\\"') + '"' : '"' + String(r).replaceAll('"', '""') + '"').join(",") + `\r
765
856
  `;
766
857
  }
767
- function ce(e, r, a) {
858
+ function de(e, r, a) {
768
859
  const t = new Blob(e, { type: a }), n = URL.createObjectURL(t), i = document.createElement("a");
769
860
  i.href = n, i.setAttribute("download", r), i.click();
770
861
  }
771
- const yt = 500;
772
- function bt({
862
+ const xt = 500;
863
+ function vt({
773
864
  collection: e,
774
865
  path: r,
775
866
  collectionEntitiesCount: a,
776
867
  exportAllowed: t,
777
868
  notAllowedView: n
778
869
  }) {
779
- const i = X(), s = typeof e.exportable == "object" ? e.exportable : void 0, d = C.useRef(/* @__PURE__ */ new Date()), [c, l] = C.useState(!0), [p, m] = C.useState("csv"), [h, g] = C.useState("string"), I = $e(), A = ue(), x = Re().resolveAliasesFrom(r), U = !t || t({
870
+ const i = q(), s = typeof e.exportable == "object" ? e.exportable : void 0, c = C.useRef(/* @__PURE__ */ new Date()), [l, d] = C.useState(!0), [p, u] = C.useState("csv"), [m, g] = C.useState("string"), E = Re(), I = he(), x = Le().resolveAliasesFrom(r), W = !t || t({
780
871
  collectionEntitiesCount: a,
781
872
  path: x,
782
873
  collection: e
783
- }), R = C.useMemo(() => he({
874
+ }), R = C.useMemo(() => ge({
784
875
  collection: e,
785
876
  path: x,
786
877
  fields: i.propertyConfigs
787
- }), [e, x]), [y, T] = C.useState(!1), [L, w] = C.useState(), [B, j] = C.useState(!1), S = b(() => {
788
- j(!0);
789
- }, [j]), D = b(() => {
790
- j(!1);
791
- }, [j]), ne = b(async (P) => {
792
- const W = s?.additionalFields, N = R.additionalFields, q = W ? await Promise.all(P.map(async (F) => (await Promise.all(W.map(async (v) => ({
878
+ }), [e, x]), [y, T] = C.useState(!1), [L, w] = C.useState(), [J, _] = C.useState(!1), D = b(() => {
879
+ _(!0);
880
+ }, [_]), O = b(() => {
881
+ _(!1);
882
+ }, [_]), ae = b(async (k) => {
883
+ const z = s?.additionalFields, A = R.additionalFields, Q = z ? await Promise.all(k.map(async (j) => (await Promise.all(z.map(async (v) => ({
793
884
  [v.key]: await v.builder({
794
- entity: F,
795
- context: I
885
+ entity: j,
886
+ context: E
796
887
  })
797
- })))).reduce((v, Y) => ({ ...v, ...Y }), {}))) : [], Q = N ? await Promise.all(P.map(async (F) => (await Promise.all(N.map(async (v) => v.value ? {
888
+ })))).reduce((v, Z) => ({ ...v, ...Z }), {}))) : [], Y = A ? await Promise.all(k.map(async (j) => (await Promise.all(A.map(async (v) => v.value ? {
798
889
  [v.key]: await v.value({
799
- entity: F,
800
- context: I
890
+ entity: j,
891
+ context: E
801
892
  })
802
- } : {}))).reduce((v, Y) => ({ ...v, ...Y }), {}))) : [];
803
- return [...q, ...Q];
804
- }, [s?.additionalFields]), ae = b(async (P, W) => {
805
- T(!0), A.fetchCollection({
893
+ } : {}))).reduce((v, Z) => ({ ...v, ...Z }), {}))) : [];
894
+ return [...Q, ...Y];
895
+ }, [s?.additionalFields]), ie = b(async (k, z) => {
896
+ T(!0), I.fetchCollection({
806
897
  path: x,
807
- collection: P
808
- }).then(async (N) => {
898
+ collection: k
899
+ }).then(async (A) => {
809
900
  w(void 0);
810
- const q = await ne(N), Q = [
811
- ...W?.additionalFields?.map((F) => F.key) ?? [],
812
- ...P.additionalFields?.map((F) => F.key) ?? []
901
+ const Q = await ae(A), Y = [
902
+ ...z?.additionalFields?.map((j) => j.key) ?? [],
903
+ ...k.additionalFields?.map((j) => j.key) ?? []
813
904
  ];
814
- mt(N, q, P, c, Q, p, h);
815
- }).catch((N) => {
816
- console.error("Error loading export data", N), w(N);
905
+ ht(A, Q, k, l, Y, p, m);
906
+ }).catch((A) => {
907
+ console.error("Error loading export data", A), w(A);
817
908
  }).finally(() => T(!1));
818
- }, [A, x, ne, c, p, h]), Oe = b(() => {
819
- ae(R, s), D();
820
- }, [ae, R, s, D]);
821
- return /* @__PURE__ */ f(M, { children: [
822
- /* @__PURE__ */ o(te, { title: "Export", children: /* @__PURE__ */ o(ee, { color: "primary", onClick: S, children: /* @__PURE__ */ o(Qe, {}) }) }),
909
+ }, [I, x, ae, l, p, m]), Ne = b(() => {
910
+ ie(R, s), O();
911
+ }, [ie, R, s, O]);
912
+ return /* @__PURE__ */ f(P, { children: [
913
+ /* @__PURE__ */ o(re, { title: "Export", children: /* @__PURE__ */ o(te, { color: "primary", onClick: D, children: /* @__PURE__ */ o(Ye, {}) }) }),
823
914
  /* @__PURE__ */ f(
824
- be,
915
+ xe,
825
916
  {
826
- open: B,
827
- onOpenChange: j,
917
+ open: J,
918
+ onOpenChange: _,
828
919
  maxWidth: "xl",
829
920
  children: [
830
- /* @__PURE__ */ f(xe, { className: "flex flex-col gap-4 my-4", children: [
831
- /* @__PURE__ */ o(u, { variant: "h6", children: "Export data" }),
921
+ /* @__PURE__ */ f(ve, { className: "flex flex-col gap-4 my-4", children: [
922
+ /* @__PURE__ */ o(h, { variant: "h6", children: "Export data" }),
832
923
  /* @__PURE__ */ o("div", { children: "Download the the content of this table as a CSV" }),
833
- a > yt && /* @__PURE__ */ o(Ye, { color: "warning", children: /* @__PURE__ */ f("div", { children: [
924
+ a > xt && /* @__PURE__ */ o(Ze, { color: "warning", children: /* @__PURE__ */ f("div", { children: [
834
925
  "This collections has a large number of documents (",
835
926
  a,
836
927
  ")."
@@ -846,8 +937,8 @@ function bt({
846
937
  value: "csv",
847
938
  name: "exportType",
848
939
  checked: p === "csv",
849
- onChange: () => m("csv"),
850
- className: J(z, "w-4 text-primary-dark bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
940
+ onChange: () => u("csv"),
941
+ className: B(V, "w-4 text-primary-dark bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
851
942
  }
852
943
  ),
853
944
  /* @__PURE__ */ o(
@@ -868,8 +959,8 @@ function bt({
868
959
  value: "json",
869
960
  name: "exportType",
870
961
  checked: p === "json",
871
- onChange: () => m("json"),
872
- className: J(z, "w-4 text-primary-dark bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
962
+ onChange: () => u("json"),
963
+ className: B(V, "w-4 text-primary-dark bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
873
964
  }
874
965
  ),
875
966
  /* @__PURE__ */ o(
@@ -891,9 +982,9 @@ function bt({
891
982
  type: "radio",
892
983
  value: "timestamp",
893
984
  name: "dateExportType",
894
- checked: h === "timestamp",
985
+ checked: m === "timestamp",
895
986
  onChange: () => g("timestamp"),
896
- className: J(z, "w-4 text-primary-dark bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
987
+ className: B(V, "w-4 text-primary-dark bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
897
988
  }
898
989
  ),
899
990
  /* @__PURE__ */ f(
@@ -903,7 +994,7 @@ function bt({
903
994
  className: "p-2 text-sm font-medium text-gray-900 dark:text-slate-300",
904
995
  children: [
905
996
  "Dates as timestamps (",
906
- d.current.getTime(),
997
+ c.current.getTime(),
907
998
  ")"
908
999
  ]
909
1000
  }
@@ -917,9 +1008,9 @@ function bt({
917
1008
  type: "radio",
918
1009
  value: "string",
919
1010
  name: "dateExportType",
920
- checked: h === "string",
1011
+ checked: m === "string",
921
1012
  onChange: () => g("string"),
922
- className: J(z, "w-4 text-primary-dark bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
1013
+ className: B(V, "w-4 text-primary-dark bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
923
1014
  }
924
1015
  ),
925
1016
  /* @__PURE__ */ f(
@@ -929,7 +1020,7 @@ function bt({
929
1020
  className: "p-2 text-sm font-medium text-gray-900 dark:text-slate-300",
930
1021
  children: [
931
1022
  "Dates as strings (",
932
- d.current.toISOString(),
1023
+ c.current.toISOString(),
933
1024
  ")"
934
1025
  ]
935
1026
  }
@@ -938,33 +1029,33 @@ function bt({
938
1029
  ] })
939
1030
  ] }),
940
1031
  /* @__PURE__ */ o(
941
- Ze,
1032
+ Ke,
942
1033
  {
943
1034
  size: "small",
944
1035
  disabled: p !== "csv",
945
- value: c,
946
- onValueChange: l,
1036
+ value: l,
1037
+ onValueChange: d,
947
1038
  label: "Flatten arrays"
948
1039
  }
949
1040
  ),
950
- !U && n
1041
+ !W && n
951
1042
  ] }),
952
- /* @__PURE__ */ f(ve, { children: [
953
- y && /* @__PURE__ */ o(ye, { size: "small" }),
1043
+ /* @__PURE__ */ f(Ce, { children: [
1044
+ y && /* @__PURE__ */ o(be, { size: "small" }),
954
1045
  /* @__PURE__ */ o(
955
- E,
1046
+ N,
956
1047
  {
957
- onClick: D,
1048
+ onClick: O,
958
1049
  variant: "text",
959
1050
  children: "Cancel"
960
1051
  }
961
1052
  ),
962
1053
  /* @__PURE__ */ o(
963
- E,
1054
+ N,
964
1055
  {
965
1056
  variant: "filled",
966
- onClick: Oe,
967
- disabled: y || !U,
1057
+ onClick: Ne,
1058
+ disabled: y || !W,
968
1059
  children: "Download"
969
1060
  }
970
1061
  )
@@ -978,24 +1069,24 @@ function Nt(e) {
978
1069
  return Ie(() => ({
979
1070
  key: "import_export",
980
1071
  collectionView: {
981
- CollectionActions: [dt, bt],
1072
+ CollectionActions: [ft, vt],
982
1073
  collectionActionsProps: e
983
1074
  }
984
1075
  }), [e]);
985
1076
  }
986
1077
  export {
987
- ot as DataNewPropertiesMapping,
988
- lt as ImportFileUpload,
989
- Dt as ImportNewPropertyFieldPreview,
990
- ct as ImportSaveInProgress,
991
- nt as convertDataToEntity,
992
- tt as convertFileToJson,
993
- we as flattenEntry,
994
- at as getInferenceType,
995
- it as getPropertiesMapping,
996
- Z as processValueMapping,
997
- Ce as unflattenObject,
998
- et as useImportConfig,
1078
+ lt as DataNewPropertiesMapping,
1079
+ dt as ImportFileUpload,
1080
+ At as ImportNewPropertyFieldPreview,
1081
+ pt as ImportSaveInProgress,
1082
+ it as convertDataToEntity,
1083
+ nt as convertFileToJson,
1084
+ Se as flattenEntry,
1085
+ ot as getInferenceType,
1086
+ st as getPropertiesMapping,
1087
+ K as processValueMapping,
1088
+ we as unflattenObject,
1089
+ tt as useImportConfig,
999
1090
  Nt as useImportExportPlugin
1000
1091
  };
1001
1092
  //# sourceMappingURL=index.es.js.map