@updog/data-editor 0.1.72 → 0.1.73

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 +2 -0
  2. package/index.js +60 -20
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -168,6 +168,8 @@ declare var export_default = {
168
168
  filteredRows_other: "{{filtered}} of {{total}} rows",
169
169
  },
170
170
  toast: {
171
+ clipboardWriteFailed:
172
+ "The browser blocked the copy to the clipboard. You can paste inside this table.",
171
173
  dismiss: "Dismiss",
172
174
  rowMayNotBeVisible:
173
175
  "Row has been added but may not be visible due to active filters or sorting",
package/index.js CHANGED
@@ -157,6 +157,7 @@ var Hr = {
157
157
  filteredRows_other: "{{filtered}} of {{total}} rows"
158
158
  },
159
159
  toast: {
160
+ clipboardWriteFailed: "The browser blocked the copy to the clipboard. You can paste inside this table.",
160
161
  dismiss: "Dismiss",
161
162
  rowMayNotBeVisible: "Row has been added but may not be visible due to active filters or sorting"
162
163
  },
@@ -12816,14 +12817,14 @@ var xf = class {
12816
12817
  return;
12817
12818
  }
12818
12819
  let s = uf(e);
12819
- t.fillStyle = n.cellBgIdle, Pd(t, 0, 0, a, o), this.paintBodyPane(s, s.panes.scrollable), this.selectionPainter.paintSelectionOutlines(s, null), this.selectionPainter.paintFocusBorder(s, null), this.lastFillHandleRect = this.selectionPainter.paintFillHandle(s, null), this.overlayPainter.paintClipboardOverlay(s), this.overlayPainter.paintFillOverlay(s);
12820
+ t.fillStyle = n.cellBgIdle, Pd(t, 0, 0, a, o), this.paintBodyPane(s, s.panes.scrollable), this.selectionPainter.paintSelectionOutlines(s, null), this.selectionPainter.paintFocusBorder(s, null), this.overlayPainter.paintClipboardOverlay(s), this.overlayPainter.paintFillOverlay(s), this.lastFillHandleRect = this.selectionPainter.paintFillHandle(s, null);
12820
12821
  let c = s.panes.pinned;
12821
12822
  if (c?.clip) {
12822
12823
  t.fillStyle = n.cellBgIdle, Pd(t, c.clip.x, c.clip.y, c.clip.w, c.clip.h), t.save(), t.beginPath(), t.rect(c.clip.x, c.clip.y, c.clip.w, c.clip.h), t.clip(), this.paintBodyPane(s, c), t.restore(), t.save(), t.beginPath();
12823
12824
  let e = Math.min(s.totalRows * 34, o - 36);
12824
- t.rect(c.clip.x, 36, c.clip.w, e), t.clip(), this.selectionPainter.paintSelectionOutlines(s, c), this.selectionPainter.paintFocusBorder(s, c);
12825
+ t.rect(c.clip.x, 36, c.clip.w, e), t.clip(), this.selectionPainter.paintSelectionOutlines(s, c), this.selectionPainter.paintFocusBorder(s, c), this.overlayPainter.paintClipboardOverlay(s);
12825
12826
  let r = this.selectionPainter.paintFillHandle(s, c);
12826
- r && (this.lastFillHandleRect = r), this.overlayPainter.paintClipboardOverlay(s), t.restore();
12827
+ r && (this.lastFillHandleRect = r), t.restore();
12827
12828
  }
12828
12829
  this.markerPainter.paint(s), this.headerPainter.paintHeaderRow(s), this.headerPainter.paintCornerCell(s), s.resizeGuideX >= 0 && this.overlayPainter.paintResizeGuide(s), this.hasSkeletons = s.hasSkeletons, this.hasPendingCells = s.hasPendingCells;
12829
12830
  }
@@ -18990,12 +18991,17 @@ function uv(e, t, n) {
18990
18991
  }
18991
18992
  o.push(r.map((e) => String(t[e.id] ?? "")).join(" "));
18992
18993
  }
18993
- navigator.clipboard.writeText(o.join("\n"));
18994
+ let s = o.join("\n");
18995
+ return {
18996
+ text: s,
18997
+ written: navigator.clipboard.writeText(s).then(() => !0).catch(() => !1)
18998
+ };
18994
18999
  }
18995
19000
  //#endregion
18996
19001
  //#region src/components/DataEditor/DataEditorGrid/controller/ClipboardManager.ts
18997
19002
  var dv = {
18998
19003
  clipboard: null,
19004
+ marqueeVisible: !1,
18999
19005
  version: 0
19000
19006
  }, fv = class {
19001
19007
  _store;
@@ -19012,6 +19018,9 @@ var dv = {
19012
19018
  _clipboardMaxRow = -1;
19013
19019
  _sourceMinRowIndex = -1;
19014
19020
  _sourceMaxRowIndex = -1;
19021
+ _marqueeVisible = !1;
19022
+ _osText = null;
19023
+ _osWrite = null;
19015
19024
  _sortState = null;
19016
19025
  _t = (e) => e;
19017
19026
  _version = 0;
@@ -19039,7 +19048,7 @@ var dv = {
19039
19048
  operation: "copy",
19040
19049
  columnIds: e.columnIds,
19041
19050
  rowIds: e.rowIds
19042
- }, this.precomputeLookup(), this.notify(), uv(this._clipboard, this._columns, this._store));
19051
+ }, this._marqueeVisible = !0, this.precomputeLookup(), this.notify(), this.writeToOs(this._clipboard));
19043
19052
  }
19044
19053
  cut() {
19045
19054
  let e = this.buildClipboardFromSnapshot();
@@ -19047,10 +19056,11 @@ var dv = {
19047
19056
  operation: "cut",
19048
19057
  columnIds: e.columnIds,
19049
19058
  rowIds: e.rowIds
19050
- }, this.precomputeLookup(), this.notify(), uv(this._clipboard, this._columns, this._store));
19059
+ }, this._marqueeVisible = !0, this.precomputeLookup(), this.notify(), this.writeToOs(this._clipboard));
19051
19060
  }
19052
19061
  async paste() {
19053
- if (this._clipboard) {
19062
+ let e = await this.readOsClipboard();
19063
+ if (this._clipboard && (!e.ok || e.ours)) {
19054
19064
  let e = this.resolveTargetFromSnapshot();
19055
19065
  if (!e) return;
19056
19066
  let t = this._clipboard, n = this._store, r = dl(t.columnIds, e.columnIds, t.rowIds ?? null, e.rowIds, this._columns, (e) => n.getRowId(e), n.getSnapshot().filteredCount, t.operation === "cut"), i = await n.pasteInternal(r, e.rowIds, {
@@ -19060,27 +19070,28 @@ var dv = {
19060
19070
  i && (this.syncInternalPasteToServer(i, t, e), this._sortState && Fs.info(this._t("dataEditor.toast.rowMayNotBeVisible")), this.clear());
19061
19071
  return;
19062
19072
  }
19063
- let e;
19064
- try {
19065
- e = await navigator.clipboard.readText();
19066
- } catch (e) {
19073
+ if (!e.ok) {
19067
19074
  this._store.errorHandler.handleError({
19068
19075
  code: "OPERATION_ERROR",
19069
19076
  message: "Failed to read clipboard",
19070
19077
  source: "clipboard-manager",
19071
- originalError: e
19078
+ originalError: e.error
19072
19079
  });
19073
19080
  return;
19074
19081
  }
19075
- if (!e) return;
19076
- let { row: t, col: n } = this.resolveAnchor(), r = await this._store.pasteFromText(e, t, n, this._validator);
19077
- r && this.syncExternalPasteToServer(r, t, n, e);
19082
+ let t = e.text;
19083
+ if (!t) return;
19084
+ let { row: n, col: r } = this.resolveAnchor(), i = await this._store.pasteFromText(t, n, r, this._validator);
19085
+ i && this.syncExternalPasteToServer(i, n, r, t);
19078
19086
  }
19079
19087
  clear() {
19080
- this._clipboard && (this._clipboard = null, this._clipboardColIndices = null, this._clipboardRowSet = null, this._clipboardIsWholeColumn = !1, this._clipboardMinCol = -1, this._clipboardMaxCol = -1, this._clipboardMinRow = -1, this._clipboardMaxRow = -1, this._sourceMinRowIndex = -1, this._sourceMaxRowIndex = -1, this.notify());
19088
+ this._clipboard && (this._clipboard = null, this._clipboardColIndices = null, this._clipboardRowSet = null, this._clipboardIsWholeColumn = !1, this._clipboardMinCol = -1, this._clipboardMaxCol = -1, this._clipboardMinRow = -1, this._clipboardMaxRow = -1, this._sourceMinRowIndex = -1, this._sourceMaxRowIndex = -1, this._marqueeVisible = !1, this._osText = null, this._osWrite = null, this.notify());
19089
+ }
19090
+ hideMarquee() {
19091
+ this._marqueeVisible && (this._marqueeVisible = !1, this.notify());
19081
19092
  }
19082
19093
  isCellInClipboard(e, t) {
19083
- if (!this._clipboard || !this._clipboardColIndices || !this._clipboardColIndices.has(e)) return !1;
19094
+ if (!this._marqueeVisible || !this._clipboard || !this._clipboardColIndices || !this._clipboardColIndices.has(e)) return !1;
19084
19095
  if (this._clipboardIsWholeColumn) return !0;
19085
19096
  if (!this._clipboardRowSet) return !1;
19086
19097
  let n = this._store.getRowId(t);
@@ -19090,7 +19101,7 @@ var dv = {
19090
19101
  return this._clipboard?.operation ?? null;
19091
19102
  }
19092
19103
  getClipboardBounds() {
19093
- if (!this._clipboard) return null;
19104
+ if (!this._clipboard || !this._marqueeVisible) return null;
19094
19105
  let e = this._clipboardIsWholeColumn ? this._store.getSnapshot().filteredCount - 1 : this._clipboardMaxRow;
19095
19106
  return {
19096
19107
  minCol: this._clipboardMinCol,
@@ -19099,6 +19110,32 @@ var dv = {
19099
19110
  maxRow: e
19100
19111
  };
19101
19112
  }
19113
+ writeToOs(e) {
19114
+ let t = uv(e, this._columns, this._store);
19115
+ this._osText = t.text, this._osWrite = t.written, t.written.then((e) => {
19116
+ e || (this._store.errorHandler.handleError({
19117
+ code: "OPERATION_ERROR",
19118
+ message: "Failed to write clipboard",
19119
+ source: "clipboard-manager"
19120
+ }), Fs.error(this._t("dataEditor.toast.clipboardWriteFailed")));
19121
+ });
19122
+ }
19123
+ async readOsClipboard() {
19124
+ let e = this._osWrite ? await this._osWrite : !0;
19125
+ try {
19126
+ let t = await navigator.clipboard.readText();
19127
+ return {
19128
+ ok: !0,
19129
+ text: t,
19130
+ ours: !e || t === this._osText
19131
+ };
19132
+ } catch (e) {
19133
+ return {
19134
+ ok: !1,
19135
+ error: e
19136
+ };
19137
+ }
19138
+ }
19102
19139
  buildClipboardFromSnapshot() {
19103
19140
  let e = yd(this._selection.getSelection(), this.resolveContext());
19104
19141
  return e === null ? null : {
@@ -19201,6 +19238,7 @@ var dv = {
19201
19238
  notify() {
19202
19239
  this._version++, this._snapshot = {
19203
19240
  clipboard: this._clipboard,
19241
+ marqueeVisible: this._marqueeVisible,
19204
19242
  version: this._version
19205
19243
  };
19206
19244
  for (let e of this._listeners) e();
@@ -19588,8 +19626,8 @@ var Tv = class {
19588
19626
  return;
19589
19627
  }
19590
19628
  if (e.key === "Escape") {
19591
- if (this._clipboard.getSnapshot().clipboard) {
19592
- this._clipboard.clear();
19629
+ if (this._clipboard.getSnapshot().marqueeVisible) {
19630
+ this._clipboard.hideMarquee();
19593
19631
  return;
19594
19632
  }
19595
19633
  this._selection.clear();
@@ -20402,6 +20440,8 @@ var Lv = {
20402
20440
  }, [j]), m(() => {
20403
20441
  H.clipboard.setSortState(E);
20404
20442
  }, [H, E]), m(() => {
20443
+ H.clipboard.hideMarquee();
20444
+ }, [H, j]), m(() => {
20405
20445
  H.clipboard.setTranslate(N);
20406
20446
  }, [H, N]), m(() => {
20407
20447
  H.setBounds(g, ae.columns.length);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@updog/data-editor",
3
- "version": "0.1.72",
3
+ "version": "0.1.73",
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",