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