@updog/data-editor 0.1.90 → 0.1.91

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.
Files changed (3) hide show
  1. package/index.d.ts +7 -0
  2. package/index.js +99 -91
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -524,6 +524,8 @@ declare var export_default = {
524
524
  showSampleValues: "Show example values from {{column}}",
525
525
  unmatchedWarning:
526
526
  "Unmatched columns won't be imported. Match this column to keep the data. You can transform columns after importing.",
527
+ unmatchedWarningWithRowHook:
528
+ "The import can read this column without a match. If you match it, the import may still change the values.",
527
529
  },
528
530
  sheetPreview: {
529
531
  cancel: "Cancel processing",
@@ -953,6 +955,11 @@ type DataEditorColumn = {
953
955
  editor?: CellEditor;
954
956
  /** Adds a filter control for this column in the sidebar Filters panel. */
955
957
  filter?: ColumnFilter;
958
+ /**
959
+ * Whether this column is offered as a target on the column-matching step.
960
+ * Set false for fields your `onRowImport` callback fills. @default true
961
+ */
962
+ mappable?: boolean;
956
963
  /**
957
964
  * Whether this column can be pinned to the left (right in RTL) via the
958
965
  * header context menu. @default true
package/index.js CHANGED
@@ -494,7 +494,8 @@ var vi = {
494
494
  sampleValues: "Example values",
495
495
  sampleValuesEmpty: "No values in this column",
496
496
  showSampleValues: "Show example values from {{column}}",
497
- unmatchedWarning: "Unmatched columns won't be imported. Match this column to keep the data. You can transform columns after importing."
497
+ unmatchedWarning: "Unmatched columns won't be imported. Match this column to keep the data. You can transform columns after importing.",
498
+ unmatchedWarningWithRowHook: "The import can read this column without a match. If you match it, the import may still change the values."
498
499
  },
499
500
  sheetPreview: {
500
501
  cancel: "Cancel processing",
@@ -11466,7 +11467,9 @@ var Dh = (e, t, n) => {
11466
11467
  if (!e) return "";
11467
11468
  if (t.length === 0) return "[updog] primaryKey is empty, so imported rows are appended instead of merged.";
11468
11469
  let r = gc(t, n.map((e) => e.id));
11469
- return r.length === 0 ? "" : `[updog] primaryKey names ${r.map((e) => `"${e}"`).join(", ")}, which no column declares. Imported rows are appended instead of merged.`;
11470
+ if (r.length > 0) return `[updog] primaryKey names ${r.map((e) => `"${e}"`).join(", ")}, which no column declares. Imported rows are appended instead of merged.`;
11471
+ let i = t.filter((e) => n.some((t) => t.id === e && t.mappable === !1));
11472
+ return i.length === 0 ? "" : `[updog] primaryKey names ${i.map((e) => `"${e}"`).join(", ")}, which is not mappable (mappable: false). It never receives a match, so imported rows are appended instead of merged.`;
11470
11473
  };
11471
11474
  function Oh({ columns: e, primaryKey: t, loadData: n, onComplete: r, variant: i, showUploader: a, setShowUploader: o, storeRef: s, enableDeleteRow: c, enableAddRow: l, enableAddSource: u, blockSubmitOnError: d, importFormats: f, exportFormats: p, rowHeight: h, headerHeight: _, readonly: v, enableCreateColumn: y, onColumnMatch: b, onValueMatch: x, onRowImport: w, context: T, synonyms: E, sampleData: D, chat: O, remoteSources: k, customFormats: A, onUnstructuredFile: j, onError: M, errorHandler: N }) {
11472
11475
  let P = vh(N ?? new lc(M)), { t: F, locale: I } = q();
@@ -24573,7 +24576,10 @@ var ED = (e, t) => {
24573
24576
  seqByWorkbook = /* @__PURE__ */ new Map();
24574
24577
  _state = tO;
24575
24578
  constructor(e, t) {
24576
- this.deps = e, this.notify = t;
24579
+ this.deps = {
24580
+ ...e,
24581
+ columns: e.columns.filter((e) => e.mappable !== !1)
24582
+ }, this.notify = t;
24577
24583
  }
24578
24584
  get state() {
24579
24585
  return this._state;
@@ -26822,95 +26828,96 @@ var Fk = (t) => {
26822
26828
  allMatched: n === e.headers.length
26823
26829
  };
26824
26830
  }, dA = {}, fA = {}, pA = [], mA = () => {
26825
- let { columns: e, enableCreateColumn: t } = Q(), { t: n } = q(), r = nE(), i = pE(r, fE), a = pE(r, iE), o = i ? a.find((e) => e.id === i.workbookId) ?? null : null, { byWorkbook: s, pendingColumns: c, autoMatched: l, isMatching: u } = pE(r, aE), d = o ? s[o.id] ?? dA : dA, f = o?.id ?? null, p = m((e, t) => {
26826
- f !== null && r.updateColumnMapping(f, e, t);
26827
- }, [r, f]), h = m((e) => {
26828
- r.setPendingColumns(e);
26829
- }, [r]), g = b(() => o ? uA(o, d) : null, [o, d]), _ = (i?.total ?? 0) > 1, v = g?.headers ?? pA, [y, C] = S(null), { value: w, setTrue: E, setFalse: D } = nc(!1), [O, k] = S({}), A = x(null), j = m((e) => O[e] ?? !0, [O]), M = m((e, t) => {
26830
- k((n) => ({
26831
+ let { columns: e, enableCreateColumn: t, onRowImport: n } = Q(), r = b(() => e.filter((e) => e.mappable !== !1), [e]), { t: i } = q(), a = nE(), o = pE(a, fE), s = pE(a, iE), c = o ? s.find((e) => e.id === o.workbookId) ?? null : null, { byWorkbook: l, pendingColumns: u, autoMatched: d, isMatching: f } = pE(a, aE), p = c ? l[c.id] ?? dA : dA, h = c?.id ?? null, g = m((e, t) => {
26832
+ h !== null && a.updateColumnMapping(h, e, t);
26833
+ }, [a, h]), _ = m((e) => {
26834
+ a.setPendingColumns(e);
26835
+ }, [a]), v = b(() => c ? uA(c, p) : null, [c, p]), y = (o?.total ?? 0) > 1, C = v?.headers ?? pA, [w, E] = S(null), { value: D, setTrue: O, setFalse: k } = nc(!1), [A, j] = S({}), M = x(null), N = m((e) => A[e] ?? !0, [A]), P = m((e, t) => {
26836
+ j((n) => ({
26831
26837
  ...n,
26832
26838
  [e]: t
26833
26839
  }));
26834
- }, []), N = m((e, t) => {
26840
+ }, []), F = m((e, t) => {
26835
26841
  if (t === "action:create") {
26836
- A.current = e, C({ title: e }), E();
26842
+ M.current = e, E({ title: e }), O();
26837
26843
  return;
26838
26844
  }
26839
- p(e, t);
26840
- }, [p, E]), P = m((e) => {
26841
- if (A.current === null) return;
26845
+ g(e, t);
26846
+ }, [g, O]), I = m((e) => {
26847
+ if (M.current === null) return;
26842
26848
  let t = crypto.randomUUID(), n = `${oc}${e.title}-${t}`;
26843
- h((t) => [...t, {
26849
+ _((t) => [...t, {
26844
26850
  ...e,
26845
26851
  id: n,
26846
26852
  size: 150
26847
- }]), p(A.current, n), A.current = null, D();
26853
+ }]), g(M.current, n), M.current = null, k();
26848
26854
  }, [
26849
- p,
26850
- h,
26851
- D
26852
- ]), F = m(() => {
26853
- A.current = null, D();
26854
- }, [D]), I = b(() => [...e.map((e) => e.title), ...c.map((e) => e.title)], [e, c]), L = f ? l[f] ?? fA : fA, R = b(() => {
26855
- let r = {
26856
- text: n("dataEditor.uploader.matchColumns.bestMatch"),
26855
+ g,
26856
+ _,
26857
+ k
26858
+ ]), L = m(() => {
26859
+ M.current = null, k();
26860
+ }, [k]), R = b(() => [...e.map((e) => e.title), ...u.map((e) => e.title)], [e, u]), z = h ? d[h] ?? fA : fA, B = b(() => {
26861
+ let e = {
26862
+ text: i("dataEditor.uploader.matchColumns.bestMatch"),
26857
26863
  color: "green"
26858
- }, i = {
26859
- text: n("dataEditor.uploader.matchColumns.newColumnTag"),
26864
+ }, n = {
26865
+ text: i("dataEditor.uploader.matchColumns.newColumnTag"),
26860
26866
  color: "blue"
26861
- }, a = n("dataEditor.uploader.matchColumns.createColumn");
26862
- return Object.fromEntries(v.map((n) => {
26863
- let o = L[n], s = e.map((e) => ({
26864
- id: e.id,
26865
- text: e.title,
26866
- ...e.id === o && { tag: r }
26867
+ }, a = i("dataEditor.uploader.matchColumns.createColumn");
26868
+ return Object.fromEntries(C.map((i) => {
26869
+ let o = z[i], s = r.map((t) => ({
26870
+ id: t.id,
26871
+ text: t.title,
26872
+ ...t.id === o && { tag: e }
26867
26873
  }));
26868
- for (let e of c) s.push({
26874
+ for (let e of u) s.push({
26869
26875
  id: e.id,
26870
26876
  text: e.title,
26871
- tag: i
26877
+ tag: n
26872
26878
  });
26873
26879
  return t && s.push({
26874
- id: `${n}_d`,
26880
+ id: `${i}_d`,
26875
26881
  type: "divider"
26876
26882
  }, {
26877
26883
  id: YE,
26878
26884
  text: a,
26879
26885
  icon: /* @__PURE__ */ T(Te, { size: "1rem" })
26880
- }), [n, s];
26886
+ }), [i, s];
26881
26887
  }));
26882
26888
  }, [
26883
- v,
26884
- e,
26885
- c,
26886
- n,
26889
+ C,
26890
+ r,
26891
+ u,
26892
+ i,
26887
26893
  t,
26888
- L
26889
- ]), z = n("dataEditor.uploader.matchColumns.selectColumnPlaceholder"), B = m((e, t) => o ? RD(o, e, t) : [], [o]), V = m((e) => ({
26890
- mappedValue: d[e],
26891
- options: R[e],
26892
- autoMatchId: L[e]
26894
+ z
26895
+ ]), V = i("dataEditor.uploader.matchColumns.selectColumnPlaceholder"), ee = m((e, t) => c ? RD(c, e, t) : [], [c]), te = m((e) => ({
26896
+ mappedValue: p[e],
26897
+ options: B[e],
26898
+ autoMatchId: z[e]
26893
26899
  }), [
26894
- d,
26895
- R,
26896
- L
26900
+ p,
26901
+ B,
26902
+ z
26897
26903
  ]);
26898
26904
  return {
26899
- view: g,
26900
- isMultiWorkbook: _,
26901
- isMatching: f ? u[f] ?? !1 : !1,
26902
- isShowMatched: j,
26903
- setShowMatched: M,
26904
- placeholder: z,
26905
- existingNames: I,
26906
- createModalValues: y,
26907
- createModalOpen: w,
26908
- getRowData: V,
26909
- getSampleValues: B,
26910
- onSelectChange: N,
26911
- onClear: p,
26912
- submitCreate: P,
26913
- closeCreate: F
26905
+ view: v,
26906
+ isMultiWorkbook: y,
26907
+ hasRowHook: !!n,
26908
+ isMatching: h ? f[h] ?? !1 : !1,
26909
+ isShowMatched: N,
26910
+ setShowMatched: P,
26911
+ placeholder: V,
26912
+ existingNames: R,
26913
+ createModalValues: w,
26914
+ createModalOpen: D,
26915
+ getRowData: te,
26916
+ getSampleValues: ee,
26917
+ onSelectChange: F,
26918
+ onClear: g,
26919
+ submitCreate: I,
26920
+ closeCreate: L
26914
26921
  };
26915
26922
  }, hA = l(null);
26916
26923
  function gA({ children: e }) {
@@ -27065,28 +27072,28 @@ var _A = () => {
27065
27072
  })]
27066
27073
  })
27067
27074
  });
27068
- }, CA = f(({ csvHeader: e, mappedValue: t, options: n, autoMatchId: r, placeholder: i, isMatching: a, getSampleValues: o, onSelectChange: s, onClear: c }) => {
27069
- let { t: l } = q(), u = _(), d = !t, f = t?.startsWith("__dynamic__:") && !!r && !a, p = d && !a, h = m((t) => {
27070
- s(e, t);
27071
- }, [e, s]), g = m(() => {
27072
- c(e, void 0);
27073
- }, [e, c]);
27075
+ }, CA = f(({ csvHeader: e, mappedValue: t, options: n, autoMatchId: r, placeholder: i, isMatching: a, hasRowHook: o, getSampleValues: s, onSelectChange: c, onClear: l }) => {
27076
+ let { t: u } = q(), d = _(), f = !t, p = t?.startsWith("__dynamic__:") && !!r && !a, h = f && !a, g = m((t) => {
27077
+ c(e, t);
27078
+ }, [e, c]), v = m(() => {
27079
+ l(e, void 0);
27080
+ }, [e, l]);
27074
27081
  return /* @__PURE__ */ E("div", {
27075
27082
  className: "updog__column-matching__row",
27076
27083
  children: [
27077
27084
  /* @__PURE__ */ T("div", {
27078
27085
  className: "updog__column-matching__column",
27079
27086
  children: /* @__PURE__ */ T(SA, {
27080
- labelId: u,
27087
+ labelId: d,
27081
27088
  csvHeader: e,
27082
- getSampleValues: o
27089
+ getSampleValues: s
27083
27090
  })
27084
27091
  }),
27085
27092
  /* @__PURE__ */ T("div", {
27086
27093
  className: "updog__column-matching__arrow-container",
27087
27094
  children: /* @__PURE__ */ T(M, {
27088
27095
  size: "1.25rem",
27089
- className: O("updog__column-matching__arrow", "rtl-mirror", d || a ? "updog__column-matching__arrow--unmatched" : "updog__column-matching__arrow--matched")
27096
+ className: O("updog__column-matching__arrow", "rtl-mirror", f || a ? "updog__column-matching__arrow--unmatched" : "updog__column-matching__arrow--matched")
27090
27097
  })
27091
27098
  }),
27092
27099
  /* @__PURE__ */ T("div", {
@@ -27095,30 +27102,30 @@ var _A = () => {
27095
27102
  width: "100%",
27096
27103
  height: "2.5rem"
27097
27104
  }) : /* @__PURE__ */ T(Ts, {
27098
- ariaLabelledby: u,
27105
+ ariaLabelledby: d,
27099
27106
  options: n,
27100
27107
  value: t,
27101
- onChange: h,
27102
- onClear: g,
27108
+ onChange: g,
27109
+ onClear: v,
27103
27110
  placeholder: i
27104
27111
  })
27105
27112
  }),
27106
27113
  /* @__PURE__ */ E("div", {
27107
27114
  className: "updog__column-matching__action",
27108
- children: [f && /* @__PURE__ */ T(Za, {
27115
+ children: [p && /* @__PURE__ */ T(Za, {
27109
27116
  content: /* @__PURE__ */ T(J, {
27110
27117
  size: "sm",
27111
- children: l("dataEditor.uploader.matchColumns.createColumnWarning")
27118
+ children: u("dataEditor.uploader.matchColumns.createColumnWarning")
27112
27119
  }),
27113
27120
  placement: "bottom-end",
27114
27121
  children: /* @__PURE__ */ T(k, {
27115
27122
  size: "1.25rem",
27116
27123
  className: "updog__column-matching__action-icon"
27117
27124
  })
27118
- }), p && /* @__PURE__ */ T(Za, {
27125
+ }), h && /* @__PURE__ */ T(Za, {
27119
27126
  content: /* @__PURE__ */ T(J, {
27120
27127
  size: "sm",
27121
- children: l("dataEditor.uploader.matchColumns.unmatchedWarning")
27128
+ children: u(o ? "dataEditor.uploader.matchColumns.unmatchedWarningWithRowHook" : "dataEditor.uploader.matchColumns.unmatchedWarning")
27122
27129
  }),
27123
27130
  placement: "bottom-end",
27124
27131
  children: /* @__PURE__ */ T(he, {
@@ -27130,34 +27137,35 @@ var _A = () => {
27130
27137
  ]
27131
27138
  });
27132
27139
  }), wA = ({ view: e }) => {
27133
- let { isMatching: t, isShowMatched: n, placeholder: r, getRowData: i, getSampleValues: a, onSelectChange: o, onClear: s } = _A(), { t: c } = q(), l = n(e.workbookId), u = e.headers.map((e) => ({
27140
+ let { isMatching: t, isShowMatched: n, hasRowHook: r, placeholder: i, getRowData: a, getSampleValues: o, onSelectChange: s, onClear: c } = _A(), { t: l } = q(), u = n(e.workbookId), d = e.headers.map((e) => ({
27134
27141
  csvHeader: e,
27135
- ...i(e)
27136
- })).filter((e) => l || !e.mappedValue);
27137
- return u.length === 0 ? /* @__PURE__ */ T("div", {
27142
+ ...a(e)
27143
+ })).filter((e) => u || !e.mappedValue);
27144
+ return d.length === 0 ? /* @__PURE__ */ T("div", {
27138
27145
  className: "updog__column-matching__content",
27139
27146
  children: /* @__PURE__ */ T("div", {
27140
27147
  className: "updog__column-matching__empty",
27141
27148
  children: /* @__PURE__ */ T(J, {
27142
27149
  size: "sm",
27143
27150
  color: "secondary",
27144
- children: c("dataEditor.uploader.matchColumns.allMatched")
27151
+ children: l("dataEditor.uploader.matchColumns.allMatched")
27145
27152
  })
27146
27153
  })
27147
27154
  }) : /* @__PURE__ */ T("div", {
27148
27155
  className: "updog__column-matching__content",
27149
27156
  children: /* @__PURE__ */ T("div", {
27150
27157
  className: "updog__column-matching__content-inner",
27151
- children: u.map(({ csvHeader: e, mappedValue: n, options: i, autoMatchId: c }) => /* @__PURE__ */ T(CA, {
27158
+ children: d.map(({ csvHeader: e, mappedValue: n, options: a, autoMatchId: l }) => /* @__PURE__ */ T(CA, {
27152
27159
  csvHeader: e,
27153
27160
  mappedValue: n,
27154
- options: i,
27155
- autoMatchId: c,
27156
- placeholder: r,
27161
+ options: a,
27162
+ autoMatchId: l,
27163
+ placeholder: i,
27157
27164
  isMatching: t,
27158
- getSampleValues: a,
27159
- onSelectChange: o,
27160
- onClear: s
27165
+ hasRowHook: r,
27166
+ getSampleValues: o,
27167
+ onSelectChange: s,
27168
+ onClear: c
27161
27169
  }, e))
27162
27170
  })
27163
27171
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@updog/data-editor",
3
- "version": "0.1.90",
3
+ "version": "0.1.91",
4
4
  "description": "Client-side CSV importer and spreadsheet editor for React. Import CSV, Excel, JSON, TSV, and XML, match columns, validate, and edit 1M+ rows entirely in the browser.",
5
5
  "author": "Mikhail Kutateladze <admin@updog.tech>",
6
6
  "homepage": "https://updog.tech",