@ishibashi0112/spreadsheet-grid-core 1.6.0 → 1.8.0

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 (77) hide show
  1. package/dist/controllers/changeTracker.cjs +1 -0
  2. package/dist/controllers/changeTracker.d.ts +38 -0
  3. package/dist/controllers/changeTracker.js +233 -0
  4. package/dist/controllers/editController.cjs +1 -1
  5. package/dist/controllers/editController.d.ts +3 -2
  6. package/dist/controllers/editController.js +171 -152
  7. package/dist/controllers/historyController.cjs +1 -1
  8. package/dist/controllers/historyController.d.ts +1 -0
  9. package/dist/controllers/historyController.js +18 -15
  10. package/dist/controllers/searchSelectEditorController.cjs +1 -0
  11. package/dist/controllers/searchSelectEditorController.d.ts +48 -0
  12. package/dist/controllers/searchSelectEditorController.js +188 -0
  13. package/dist/engine/createGridEngine.cjs +1 -1
  14. package/dist/engine/createGridEngine.d.ts +2 -0
  15. package/dist/engine/createGridEngine.js +19 -18
  16. package/dist/engine/features.cjs +1 -1
  17. package/dist/engine/features.d.ts +5 -0
  18. package/dist/engine/features.js +24 -1
  19. package/dist/engine/fullFeatures.cjs +1 -1
  20. package/dist/engine/fullFeatures.js +33 -31
  21. package/dist/engine/gridApi.cjs +8 -7
  22. package/dist/engine/gridApi.d.ts +3 -0
  23. package/dist/engine/gridApi.js +115 -83
  24. package/dist/index.cjs +1 -1
  25. package/dist/index.d.ts +1 -1
  26. package/dist/index.js +4 -4
  27. package/dist/locales/en.cjs +1 -1
  28. package/dist/locales/en.js +12 -0
  29. package/dist/logic/cellNote.cjs +1 -1
  30. package/dist/logic/cellNote.d.ts +1 -1
  31. package/dist/logic/cellNote.js +9 -1
  32. package/dist/logic/changeTracking.cjs +1 -0
  33. package/dist/logic/changeTracking.d.ts +51 -0
  34. package/dist/logic/changeTracking.js +185 -0
  35. package/dist/logic/clearCells.cjs +1 -1
  36. package/dist/logic/clearCells.js +54 -54
  37. package/dist/logic/contextMenuTarget.cjs +1 -1
  38. package/dist/logic/contextMenuTarget.d.ts +4 -3
  39. package/dist/logic/contextMenuTarget.js +42 -36
  40. package/dist/logic/fillHandle.cjs +1 -1
  41. package/dist/logic/fillHandle.js +127 -118
  42. package/dist/logic/gridAsk.cjs +2 -2
  43. package/dist/logic/gridAsk.js +71 -71
  44. package/dist/logic/groupExport.cjs +1 -1
  45. package/dist/logic/groupExport.js +12 -12
  46. package/dist/logic/imeInput.cjs +1 -1
  47. package/dist/logic/imeInput.js +14 -13
  48. package/dist/logic/localeTextFeatures.cjs +1 -1
  49. package/dist/logic/localeTextFeatures.d.ts +16 -0
  50. package/dist/logic/localeTextFeatures.js +20 -6
  51. package/dist/logic/selectEditorState.cjs +1 -1
  52. package/dist/logic/selectEditorState.d.ts +16 -1
  53. package/dist/logic/selectEditorState.js +30 -21
  54. package/dist/logic/selectFillRow.cjs +1 -0
  55. package/dist/logic/selectFillRow.d.ts +4 -0
  56. package/dist/logic/selectFillRow.js +25 -0
  57. package/dist/logic/selectLabels.cjs +1 -1
  58. package/dist/logic/selectLabels.js +25 -22
  59. package/dist/logic/selectSearch.cjs +1 -0
  60. package/dist/logic/selectSearch.d.ts +27 -0
  61. package/dist/logic/selectSearch.js +102 -0
  62. package/dist/logic/validation.cjs +1 -1
  63. package/dist/logic/validation.js +13 -13
  64. package/dist/model/gridTypes.core.d.ts +201 -9
  65. package/dist/model/gridTypes.unbound.d.ts +1 -0
  66. package/dist/utils/clipboard.cjs +1 -1
  67. package/dist/utils/clipboard.js +65 -65
  68. package/dist/utils/editorVisibleBounds.cjs +1 -1
  69. package/dist/utils/editorVisibleBounds.d.ts +4 -0
  70. package/dist/utils/editorVisibleBounds.js +12 -2
  71. package/dist/utils/overflowTitle.cjs +1 -0
  72. package/dist/utils/overflowTitle.d.ts +1 -0
  73. package/dist/utils/overflowTitle.js +7 -0
  74. package/dist/utils/permissions.cjs +1 -1
  75. package/dist/utils/permissions.d.ts +6 -0
  76. package/dist/utils/permissions.js +11 -2
  77. package/package.json +1 -1
@@ -1,31 +1,39 @@
1
1
  import { gridActions as e } from "../model/gridActions.js";
2
- import { getCellValue as t, isCellEditable as n, isViewCellEditable as r } from "../utils/permissions.js";
3
- import { getActiveElement as i } from "../utils/shadowDom.js";
4
- import { findViewRowIndexByKey as a, isFocusInsideDetailCard as o, resolveFirstDataColIndex as s } from "../logic/detailRow.js";
5
- import { clamp as c } from "../logic/geometry.js";
6
- import { isUnchangedEditorCommit as l, parseCommittedValue as u, writeRowsCell as d } from "../logic/editorValues.js";
7
- import { decideCellWrite as f } from "../logic/validation.js";
8
- import { readLiveUiState as p } from "./liveUiState.js";
2
+ import { getCellValue as t, isCellEditable as n, isViewCellEditable as r, setCellValue as i } from "../utils/permissions.js";
3
+ import { getActiveElement as a } from "../utils/shadowDom.js";
4
+ import { findViewRowIndexByKey as o, isFocusInsideDetailCard as s, resolveFirstDataColIndex as c } from "../logic/detailRow.js";
5
+ import { clamp as l } from "../logic/geometry.js";
6
+ import { isUnchangedEditorCommit as u, parseCommittedValue as d, writeRowsCell as f } from "../logic/editorValues.js";
7
+ import { decideCellWrite as p } from "../logic/validation.js";
8
+ import { readLiveUiState as m } from "./liveUiState.js";
9
+ import { resolveSelectFillRow as h, toFillRowColumn as g } from "../logic/selectFillRow.js";
9
10
  //#region src/controllers/editController.ts
10
- var m = (e, t) => t.activeCell !== e.activeCell || t.selection !== e.selection, h = (e) => {
11
- if (o(e)) return !1;
12
- let t = e.ownerDocument, n = i(e);
11
+ var _ = (e, t) => t.activeCell !== e.activeCell || t.selection !== e.selection, v = (e) => {
12
+ if (s(e)) return !1;
13
+ let t = e.ownerDocument, n = a(e);
13
14
  return n === null || n === t.body || n === t.documentElement || e.contains(n);
14
- }, g = (e) => {
15
- let t = e.ownerDocument, n = i(e);
15
+ }, y = (e) => {
16
+ let t = e.ownerDocument, n = a(e);
16
17
  return n === null || n === t.body || n === t.documentElement;
17
- }, _ = (e) => {
18
+ }, b = (e) => {
18
19
  if (e === null) return !1;
19
- let t = i(e);
20
- return t !== null && t !== e && e.contains(t) && typeof t.closest == "function" && t.closest(".ssg-cell-editor") !== null && !o(e);
21
- }, v = () => {
22
- let i = null, o = null, v = null, y = null, b = !1, x = !1, S = null, C = null, w = null, T = (e, t) => {
20
+ let t = a(e);
21
+ return t !== null && t !== e && e.contains(t) && typeof t.closest == "function" && t.closest(".ssg-cell-editor") !== null && !s(e);
22
+ }, x = (e, t, n, r, a) => e.map((e, o) => o === t ? {
23
+ ...i(e, n, r),
24
+ ...a
25
+ } : e), S = (e, t) => e === null ? [] : Object.keys(e).map((n) => ({
26
+ viewIndex: t,
27
+ column: g(n),
28
+ value: e[n]
29
+ })), C = () => {
30
+ let i = null, a = null, s = null, g = null, C = !1, w = !1, T = null, E = null, D = null, O = (e, t) => {
23
31
  let n = e.visibleColumns[t.col];
24
32
  return !n || t.row < 0 || t.row >= e.rowModel.getRowCount() || e.rowModel.getRow(t.row) === void 0 ? null : {
25
33
  rowKey: e.rowModel.getRowKey(t.row),
26
34
  columnKey: n.key
27
35
  };
28
- }, E = (e, t) => {
36
+ }, k = (e, t) => {
29
37
  let n = e.visibleColumns.findIndex((e) => e.key === t.columnKey);
30
38
  if (n < 0) return null;
31
39
  let r = e.rowModel.getRowCount();
@@ -34,199 +42,210 @@ var m = (e, t) => t.activeCell !== e.activeCell || t.selection !== e.selection,
34
42
  col: n
35
43
  };
36
44
  return null;
37
- }, D = (t) => {
45
+ }, A = (t) => {
38
46
  i = t;
39
47
  let n = t.uiState.editingCell;
40
48
  if (!n) {
41
- o = null, S = null;
49
+ a = null, T = null;
42
50
  return;
43
51
  }
44
- let r = T(t, n);
45
- if (o !== null && r !== null && Object.is(r.rowKey, o.rowKey) && r.columnKey === o.columnKey) {
46
- o = {
47
- ...o,
52
+ let r = O(t, n);
53
+ if (a !== null && r !== null && Object.is(r.rowKey, a.rowKey) && r.columnKey === a.columnKey) {
54
+ a = {
55
+ ...a,
48
56
  cell: n
49
57
  };
50
58
  return;
51
59
  }
52
- let a = o !== null && o.cell.row === n.row && o.cell.col === n.col;
53
- if (o === null || !a) {
54
- o = r ? {
60
+ let o = a !== null && a.cell.row === n.row && a.cell.col === n.col;
61
+ if (a === null || !o) {
62
+ a = r ? {
55
63
  ...r,
56
64
  cell: n
57
- } : null, v !== null && (v.superseded = !0, v = null, t.editorActionGuardRef.current = !1);
65
+ } : null, s !== null && (s.superseded = !0, s = null, t.editorActionGuardRef.current = !1);
58
66
  return;
59
67
  }
60
- let s = E(t, o);
61
- if (s) o = {
62
- ...o,
63
- cell: s
64
- }, t.dispatch(e.retargetEdit(s, t.rowModel.getRowCount()));
68
+ let c = k(t, a);
69
+ if (c) a = {
70
+ ...a,
71
+ cell: c
72
+ }, t.dispatch(e.retargetEdit(c, t.rowModel.getRowCount()));
65
73
  else {
66
- let e = o;
67
- o = null, O(t, e);
74
+ let e = a;
75
+ a = null, j(t, e);
68
76
  }
69
- }, O = (t, n) => {
77
+ }, j = (t, n) => {
70
78
  if (t.editorActionGuardRef.current) {
71
79
  t.dispatch(e.stopEdit());
72
80
  return;
73
81
  }
74
- y = n, b = !1;
75
- let r = S;
76
- S = null, x = !0;
82
+ g = n, C = !1;
83
+ let r = T;
84
+ T = null, w = !0;
77
85
  let i;
78
86
  try {
79
- r !== null && (r(), y = null), i = P();
87
+ r !== null && (r(), g = null), i = R();
80
88
  } finally {
81
- x = !1, y = null;
89
+ w = !1, g = null;
82
90
  }
83
91
  let a = t.gridRootRef.current;
84
- if (!i && a !== null && a.isConnected && g(a) && (a.focus({ preventScroll: !0 }), i = !0), b && t.editorActionGuardRef.current) {
85
- b = !1;
92
+ if (!i && a !== null && a.isConnected && y(a) && (a.focus({ preventScroll: !0 }), i = !0), C && t.editorActionGuardRef.current) {
93
+ C = !1;
86
94
  return;
87
95
  }
88
- b = !1, t.editorActionGuardRef.current = !0, t.dispatch(e.stopEdit()), N(null, null, void 0, i);
89
- }, k = (e, t) => {
96
+ C = !1, t.editorActionGuardRef.current = !0, t.dispatch(e.stopEdit()), L(null, null, void 0, i);
97
+ }, M = (e, t) => {
90
98
  let { rows: n, rowKeyGetter: r } = e;
91
99
  for (let e = 0; e < n.length; e += 1) {
92
100
  let i = n[e];
93
101
  if (i !== void 0 && Object.is(r ? r(i, e) : e, t)) return e;
94
102
  }
95
103
  return -1;
96
- }, A = (t) => {
104
+ }, N = (t) => {
97
105
  i !== null && (i.dispatch(e.startSelection(t)), i.dispatch(e.endSelection()), i.dispatch(e.activateCell(t)));
98
- }, j = (t, n) => {
106
+ }, P = (t, n) => {
99
107
  i !== null && (i.setEditorInitialValue(n), i.dispatch(e.startEdit(t)));
100
- }, M = (e, t, n) => {
101
- let r = e.getRowCount(), i = c(t, 0, Math.max(r - 1, 0)), { getLabelRow: a } = e;
108
+ }, F = (e, t) => {
109
+ if (i === null) return;
110
+ let n = i.rowModel.getRow(e.row), a = i.visibleColumns[e.col];
111
+ !n || !a || a.editor?.type === "checkbox" || !r({
112
+ readOnly: i.readOnly,
113
+ canEditCell: i.canEditCell
114
+ }, i.rowModel, e.row, e.col, n, a) || P(e, t);
115
+ }, I = (e, t, n) => {
116
+ let r = e.getRowCount(), i = l(t, 0, Math.max(r - 1, 0)), { getLabelRow: a } = e;
102
117
  if (a && n !== void 0 && i !== n) {
103
118
  let e = i > n ? 1 : -1;
104
119
  for (; i >= 0 && i < r && a(i);) i += e;
105
- (i < 0 || i >= r) && (i = c(n, 0, Math.max(r - 1, 0)));
120
+ (i < 0 || i >= r) && (i = l(n, 0, Math.max(r - 1, 0)));
106
121
  }
107
122
  return i;
108
- }, N = (e, t = null, n, r = !1, o) => {
109
- let s = i;
110
- if (s === null) return;
111
- let l = !1, u = { superseded: !1 };
112
- v = u;
113
- let d = s.uiState.editingCell, f = (r) => {
114
- if (l) return;
115
- if (u.superseded) {
116
- l = !0;
123
+ }, L = (e, t = null, n, r = !1, a, c) => {
124
+ let u = i;
125
+ if (u === null) return;
126
+ let d = !1, f = { superseded: !1 };
127
+ s = f;
128
+ let p = u.uiState.editingCell, m = (r) => {
129
+ if (d) return;
130
+ if (f.superseded) {
131
+ d = !0;
117
132
  return;
118
133
  }
119
- let f = i === null ? null : i.getUiState?.() ?? null;
120
- if (f !== null && f.editingCell !== null && f.editingCell !== d) {
121
- l = !0, v === u && (v = null), s.editorActionGuardRef.current = !1;
134
+ let m = i === null ? null : i.getUiState?.() ?? null;
135
+ if (m !== null && m.editingCell !== null && m.editingCell !== p) {
136
+ d = !0, s === f && (s = null), u.editorActionGuardRef.current = !1;
122
137
  return;
123
138
  }
124
139
  if (!r && (i === null || i.uiState.editingCell !== null)) return;
125
- l = !0, v === u && (v = null);
126
- let p = s.gridRootRef.current;
127
- if (p !== null && h(p) && p.focus(), e !== null && i !== null && !(t !== null && m(t, i.uiState))) {
128
- let t = i.visibleColumns.length, r = o === void 0 ? -1 : a(i.rowModel, o, /* @__PURE__ */ new Map()), s = r >= 0 ? r : M(i.rowModel, e.row, n);
129
- A({
130
- row: s,
131
- col: c(e.col, 0, Math.max(t - 1, 0))
132
- });
140
+ d = !0, s === f && (s = null);
141
+ let h = u.gridRootRef.current;
142
+ if (h !== null && v(h) && h.focus(), e !== null && i !== null && !(t !== null && _(t, i.uiState))) {
143
+ let t = i.visibleColumns.length, r = a === void 0 ? -1 : o(i.rowModel, a, /* @__PURE__ */ new Map()), s = {
144
+ row: r >= 0 ? r : I(i.rowModel, e.row, n),
145
+ col: l(e.col, 0, Math.max(t - 1, 0))
146
+ };
147
+ N(s), u.editorActionGuardRef.current = !1, c !== void 0 && c !== "" && F(s, c);
148
+ return;
133
149
  }
134
- s.editorActionGuardRef.current = !1;
150
+ u.editorActionGuardRef.current = !1;
135
151
  };
136
- r && queueMicrotask(() => f(!1)), requestAnimationFrame(() => f(!0));
137
- }, P = () => {
152
+ r && queueMicrotask(() => m(!1)), requestAnimationFrame(() => m(!0));
153
+ }, R = () => {
138
154
  let e = i?.gridRootRef.current ?? null;
139
- return _(e) ? (e.focus({ preventScroll: !0 }), !0) : !1;
140
- }, F = (n, a) => {
155
+ return b(e) ? (e.focus({ preventScroll: !0 }), !0) : !1;
156
+ }, z = (e, t, n, r, i) => i === void 0 ? null : h(t, n, e.rowModel.getRowKey(r), i, e.columns ?? e.visibleColumns, e.localeTexts), B = (n, a, o, s) => {
141
157
  if (i === null) return { status: "noop" };
142
- let { uiState: o, visibleColumns: c, rowModel: p, rows: m, applyServerSideCellEdits: h, onRowsChange: g, dispatch: _, editorActionGuardRef: v } = i;
143
- if (v.current || !o.editingCell) return { status: "noop" };
144
- if (x) {
145
- let e = y;
146
- return y = null, e === null ? { status: "noop" } : R(i, e, n, !0);
158
+ let { uiState: l, visibleColumns: m, rowModel: h, rows: _, applyServerSideCellEdits: v, onRowsChange: y, dispatch: b, editorActionGuardRef: C } = i;
159
+ if (C.current || !l.editingCell) return { status: "noop" };
160
+ if (w) {
161
+ let e = g;
162
+ return g = null, e === null ? { status: "noop" } : U(i, e, n, !0, o);
147
163
  }
148
- let b = o.editingCell, S = a === "down" ? {
149
- row: b.row + 1,
150
- col: b.col
164
+ let T = l.editingCell, E = a === "down" ? {
165
+ row: T.row + 1,
166
+ col: T.col
151
167
  } : a === "up" ? {
152
- row: b.row - 1,
153
- col: b.col
168
+ row: T.row - 1,
169
+ col: T.col
154
170
  } : a === "right" ? {
155
- row: b.row,
156
- col: b.col + 1
171
+ row: T.row,
172
+ col: T.col + 1
157
173
  } : a === "left" ? {
158
- row: b.row,
159
- col: Math.max(b.col - 1, s(c))
160
- } : b, C = c[b.col], w = p.getSourceIndex(b.row), T = h ? p.getRow(b.row) : m[w];
161
- if (!C || !T) return _(e.stopEdit()), { status: "noop" };
174
+ row: T.row,
175
+ col: Math.max(T.col - 1, c(m))
176
+ } : T, D = m[T.col], O = h.getSourceIndex(T.row), k = v ? h.getRow(T.row) : _[O];
177
+ if (!D || !k) return b(e.stopEdit()), { status: "noop" };
162
178
  if (!r({
163
179
  readOnly: i.readOnly,
164
180
  canEditCell: i.canEditCell
165
- }, p, b.row, b.col, T, C)) return v.current = !0, _(e.stopEdit()), N(null), { status: "noop" };
166
- let E = l(C, t(T, C), n);
167
- if (!E && h) {
168
- let e = u(C, n, T), t = f(C, T, e, i.localeTexts);
181
+ }, h, T.row, T.col, k, D)) return C.current = !0, b(e.stopEdit()), L(null), { status: "noop" };
182
+ let A = u(D, t(k, D), n);
183
+ if (!A && v) {
184
+ let e = d(D, n, k), t = p(D, k, e, i.localeTexts);
169
185
  if (t.action === "reject") return {
170
186
  status: "rejected",
171
187
  message: t.message
172
188
  };
173
- h([{
174
- viewIndex: b.row,
175
- column: C,
189
+ let r = z(i, D, k, T.row, o);
190
+ v([{
191
+ viewIndex: T.row,
192
+ column: D,
176
193
  value: e
177
- }]);
178
- } else if (!E && g) {
179
- let e = u(C, n, T), t = f(C, T, e, i.localeTexts);
194
+ }, ...S(r, T.row)]);
195
+ } else if (!A && y) {
196
+ let e = d(D, n, k), t = p(D, k, e, i.localeTexts);
180
197
  if (t.action === "reject") return {
181
198
  status: "rejected",
182
199
  message: t.message
183
200
  };
184
- g(d(m, w, C, e));
201
+ let r = z(i, D, k, T.row, o);
202
+ y(r === null ? f(_, O, D, e) : x(_, O, D, e, r));
185
203
  }
186
- v.current = !0;
187
- let D = P(), O;
204
+ C.current = !0;
205
+ let j = R(), M;
188
206
  if (i.followsRow === !0) {
189
- let e = M(p, S.row, b.row);
190
- (p.getRow(e) != null || p.getLabelRow?.(e) !== void 0) && (O = p.getRowKey(e));
207
+ let e = I(h, E.row, T.row);
208
+ (h.getRow(e) != null || h.getLabelRow?.(e) !== void 0) && (M = h.getRowKey(e));
191
209
  }
192
- return N(S, a === void 0 ? {
193
- activeCell: o.activeCell,
194
- selection: o.selection
195
- } : null, b.row, D, O), _(e.stopEdit()), { status: "committed" };
196
- }, I = () => {
210
+ return L(E, a === void 0 ? {
211
+ activeCell: l.activeCell,
212
+ selection: l.selection
213
+ } : null, T.row, j, M, a === void 0 ? void 0 : s), b(e.stopEdit()), { status: "committed" };
214
+ }, V = () => {
197
215
  if (i === null || i.editorActionGuardRef.current) return;
198
- b = !0, y = null, i.editorActionGuardRef.current = !0;
199
- let t = P();
200
- i.dispatch(e.stopEdit()), N(null, null, void 0, t);
201
- }, L = (e) => {
202
- S = e;
203
- }, R = (e, r, i, a) => {
204
- let o = e.visibleColumns.find((e) => e.key === r.columnKey), s = a ? null : p(e).editingCell, c = s && T(e, s);
205
- if (o === void 0 || c && Object.is(c.rowKey, r.rowKey) && c.columnKey === r.columnKey) return { status: "noop" };
206
- let m = E(e, r), h, g = -1, _ = w !== null && w.from === e.rows ? w.rows : e.rows;
207
- e.applyServerSideCellEdits === void 0 ? e.onRowsChange !== void 0 && (g = k(e, r.rowKey), h = g < 0 ? void 0 : _[g]) : h = m === null ? void 0 : e.rowModel.getRow(m.row);
208
- let v = m ?? r.cell;
209
- if (h === void 0 || !n({
216
+ C = !0, g = null, i.editorActionGuardRef.current = !0;
217
+ let t = R();
218
+ i.dispatch(e.stopEdit()), L(null, null, void 0, t);
219
+ }, H = (e) => {
220
+ T = e;
221
+ }, U = (e, r, i, a, o) => {
222
+ let s = e.visibleColumns.find((e) => e.key === r.columnKey), c = a ? null : m(e).editingCell, l = c && O(e, c);
223
+ if (s === void 0 || l && Object.is(l.rowKey, r.rowKey) && l.columnKey === r.columnKey) return { status: "noop" };
224
+ let g = k(e, r), _, v = -1, y = D !== null && D.from === e.rows ? D.rows : e.rows;
225
+ e.applyServerSideCellEdits === void 0 ? e.onRowsChange !== void 0 && (v = M(e, r.rowKey), _ = v < 0 ? void 0 : y[v]) : _ = g === null ? void 0 : e.rowModel.getRow(g.row);
226
+ let b = g ?? r.cell;
227
+ if (_ === void 0 || !n({
210
228
  readOnly: e.readOnly,
211
229
  canEditCell: e.canEditCell
212
- }, v.row, v.col, h, o, {
213
- sourceRowIndex: g >= 0 ? g : e.rowModel.getSourceIndex(v.row),
230
+ }, b.row, b.col, _, s, {
231
+ sourceRowIndex: v >= 0 ? v : e.rowModel.getSourceIndex(b.row),
214
232
  rowKey: r.rowKey
215
233
  })) return { status: "noop" };
216
- if (l(o, t(h, o), i)) return { status: "committed" };
217
- let y = u(o, i, h), b = f(o, h, y, e.localeTexts);
218
- if (b.action === "reject") return a ? { status: "noop" } : {
234
+ if (u(s, t(_, s), i)) return { status: "committed" };
235
+ let C = d(s, i, _), w = p(s, _, C, e.localeTexts);
236
+ if (w.action === "reject") return a ? { status: "noop" } : {
219
237
  status: "rejected",
220
- message: b.message
238
+ message: w.message
221
239
  };
222
- if (e.applyServerSideCellEdits !== void 0 && m !== null) e.applyServerSideCellEdits([{
223
- viewIndex: m.row,
224
- column: o,
225
- value: y
226
- }]);
227
- else if (e.onRowsChange !== void 0 && g >= 0) {
228
- let t = d(_, g, o, y);
229
- w = {
240
+ let T = o === void 0 ? null : h(s, _, r.rowKey, o, e.columns ?? e.visibleColumns, e.localeTexts);
241
+ if (e.applyServerSideCellEdits !== void 0 && g !== null) e.applyServerSideCellEdits([{
242
+ viewIndex: g.row,
243
+ column: s,
244
+ value: C
245
+ }, ...S(T, g.row)]);
246
+ else if (e.onRowsChange !== void 0 && v >= 0) {
247
+ let t = T === null ? f(y, v, s, C) : x(y, v, s, C, T);
248
+ D = {
230
249
  from: e.rows,
231
250
  rows: t
232
251
  }, e.onRowsChange(t);
@@ -234,34 +253,34 @@ var m = (e, t) => t.activeCell !== e.activeCell || t.selection !== e.selection,
234
253
  return { status: "committed" };
235
254
  };
236
255
  return {
237
- update: D,
238
- activateSingleCell: A,
239
- startEditWithValue: j,
240
- commitEdit: F,
241
- cancelEdit: I,
242
- registerDraftFlush: L,
256
+ update: A,
257
+ activateSingleCell: N,
258
+ startEditWithValue: P,
259
+ commitEdit: B,
260
+ cancelEdit: V,
261
+ registerDraftFlush: H,
243
262
  endEditLeftOpen: () => {
244
263
  let t = i;
245
264
  if (t === null || t.editorActionGuardRef.current) return;
246
- let n = p(t).editingCell;
265
+ let n = m(t).editingCell;
247
266
  if (n === null || t.visibleColumns[n.col]?.editor?.type !== "custom") return;
248
- let r = o ?? T(t, n), a = C;
249
- if (r !== null && a !== null) {
267
+ let r = a ?? O(t, n), o = E;
268
+ if (r !== null && o !== null) {
250
269
  let e = {
251
270
  ...r,
252
271
  cell: n
253
272
  }, t = !1;
254
- a((n) => t || i === null ? { status: "noop" } : (t = !0, R(i, e, n)));
273
+ o((n) => t || i === null ? { status: "noop" } : (t = !0, U(i, e, n)));
255
274
  }
256
- t.editorActionGuardRef.current = !0, t.dispatch(e.stopEdit()), N(null);
275
+ t.editorActionGuardRef.current = !0, t.dispatch(e.stopEdit()), L(null);
257
276
  },
258
- registerLateCommitReceiver: (e) => (C = e, () => {
259
- C === e && (C = null);
277
+ registerLateCommitReceiver: (e) => (E = e, () => {
278
+ E === e && (E = null);
260
279
  }),
261
280
  dispose: () => {
262
- i = null, C = null;
281
+ i = null, E = null;
263
282
  }
264
283
  };
265
284
  };
266
285
  //#endregion
267
- export { v as createEditController };
286
+ export { C as createEditController };
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../model/gridActions.cjs"),t=require("../logic/historyRebase.cjs"),n=require("../logic/history.cjs");var r=()=>{let r=null,i=n.createHistoryStack(),a=null,o=null,s={canUndo:!1,canRedo:!1},c=null,l=!1,u=()=>r!==null&&r.enabled&&r.onRowsChange!=null,d=()=>u()&&n.canUndoHistory(i),f=()=>u()&&n.canRedoHistory(i),p=()=>{let e={canUndo:d(),canRedo:f()};e.canUndo===s.canUndo&&e.canRedo===s.canRedo||(s=e,r?.onUndoRedoStateChange?.(e))},m=e=>{r=e,e.rows!==o&&(c=null),o===null?o=e.rows:e.rows!==o&&(o=e.rows,a===e.rows?a=null:(a=null,i=n.createHistoryStack(),l=!1)),p()},h=t=>{if(r===null)return;let{dispatch:n}=r,i=t.selection;i?.type===`cell`?(n(e.gridActions.startSelection(i.range.start)),n(e.gridActions.updateSelection(i.range.end)),n(e.gridActions.endSelection())):i?.type===`row`?(n(e.gridActions.startRowSelection(i.startRow)),n(e.gridActions.updateRowSelection(i.endRow)),n(e.gridActions.endSelection())):i?.type===`col`?(n(e.gridActions.startColumnSelection(i.startCol)),n(e.gridActions.updateColumnSelection(i.endCol)),n(e.gridActions.endSelection())):n(e.gridActions.clearSelection()),n(e.gridActions.activateCell(t.activeCell))},g=(e,t)=>{r===null||!r.onRowsChange||(r.enabled&&(i=n.pushHistory(i,{rows:e,after:t,selection:r.selection,activeCell:r.activeCell},r.limit),a=t,p()),c=t,r.onRowsChange(t))},_=e=>{r===null||!r.onRowsChange||g(r.rows,e)},v=e=>{if(!(r===null||!r.onRowsChange)){if(r.enabled){a=e;let t=i.past[i.past.length-1];t&&(i={...i,past:[...i.past.slice(0,-1),{...t,after:e}]})}c=e,r.onRowsChange(e)}},y=(e,t)=>{if(r===null||!r.onRowsChange)return;let n=c??r.rows,i=Array.isArray(e)?e:e(n);if(t?.undoable!==!1){g(n,i);return}r.enabled&&(a=i,l=!0),c=i,r.onRowsChange(i)},b=(e,n)=>{if(!e)return null;if(!l||e.after===n)return e.rows;let i=r?.rowKeyGetter;return!i&&(e.rows.length!==e.after.length||e.after.length!==n.length)?e.rows:t.revertRowsChange(e.rows,e.after,n,i??((e,t)=>t))},x=e=>{e===null||r===null||!r.onRowsChange||(i=e.stack,a=e.snapshot.rows,c=e.snapshot.rows,r.onRowsChange(e.snapshot.rows),h(e.snapshot),r.onAfterRestore?.(e.snapshot.activeCell),p())},S=(e,t)=>r===null?null:{rows:e,after:t,selection:r.selection,activeCell:r.activeCell},C=(e,t)=>{if(!u()||r===null)return;let n=c??r.rows,a=b(e,n),o=a===null?null:S(n,a);if(a===null||o===null)return;let s=t(i,o);x(s===null?null:{stack:s.stack,snapshot:{...s.snapshot,rows:a}})};return{update:m,handleRowsChange:_,amendRowsChange:v,applyRows:y,undo:()=>{C(i.past[i.past.length-1],n.undoHistory)},redo:()=>{C(i.future[i.future.length-1],n.redoHistory)},canUndo:d,canRedo:f,clearHistory:()=>{i=n.createHistoryStack(),l=!1,p()}}};exports.createHistoryController=r;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../model/gridActions.cjs"),t=require("../logic/historyRebase.cjs"),n=require("../logic/history.cjs");var r=()=>{let r=null,i=n.createHistoryStack(),a=null,o=null,s={canUndo:!1,canRedo:!1},c=null,l=!1,u=()=>r!==null&&r.enabled&&r.onRowsChange!=null,d=()=>u()&&n.canUndoHistory(i),f=()=>u()&&n.canRedoHistory(i),p=()=>{let e={canUndo:d(),canRedo:f()};e.canUndo===s.canUndo&&e.canRedo===s.canRedo||(s=e,r?.onUndoRedoStateChange?.(e))},m=e=>{r=e,e.rows!==o&&(c=null),o===null?o=e.rows:e.rows!==o&&(o=e.rows,a===e.rows?a=null:(a=null,i=n.createHistoryStack(),l=!1)),p()},h=t=>{if(r===null)return;let{dispatch:n}=r,i=t.selection;i?.type===`cell`?(n(e.gridActions.startSelection(i.range.start)),n(e.gridActions.updateSelection(i.range.end)),n(e.gridActions.endSelection())):i?.type===`row`?(n(e.gridActions.startRowSelection(i.startRow)),n(e.gridActions.updateRowSelection(i.endRow)),n(e.gridActions.endSelection())):i?.type===`col`?(n(e.gridActions.startColumnSelection(i.startCol)),n(e.gridActions.updateColumnSelection(i.endCol)),n(e.gridActions.endSelection())):n(e.gridActions.clearSelection()),n(e.gridActions.activateCell(t.activeCell))},g=(e,t)=>{r===null||!r.onRowsChange||(r.enabled&&(i=n.pushHistory(i,{rows:e,after:t,selection:r.selection,activeCell:r.activeCell},r.limit),a=t,p()),c=t,r.onGridRowsChange?.(e,t),r.onRowsChange(t))},_=e=>{r===null||!r.onRowsChange||g(r.rows,e)},v=e=>{if(r===null||!r.onRowsChange)return;if(r.enabled){a=e;let t=i.past[i.past.length-1];t&&(i={...i,past:[...i.past.slice(0,-1),{...t,after:e}]})}let t=c??r.rows;c=e,r.onGridRowsChange?.(t,e),r.onRowsChange(e)},y=(e,t)=>{if(r===null||!r.onRowsChange)return;let n=c??r.rows,i=Array.isArray(e)?e:e(n);if(t?.undoable!==!1){g(n,i);return}r.enabled&&(a=i,l=!0),c=i,r.onRowsChange(i)},b=(e,n)=>{if(!e)return null;if(!l||e.after===n)return e.rows;let i=r?.rowKeyGetter;return!i&&(e.rows.length!==e.after.length||e.after.length!==n.length)?e.rows:t.revertRowsChange(e.rows,e.after,n,i??((e,t)=>t))},x=e=>{if(e===null||r===null||!r.onRowsChange)return;i=e.stack,a=e.snapshot.rows;let t=c??r.rows;c=e.snapshot.rows,r.onGridRowsChange?.(t,e.snapshot.rows),r.onRowsChange(e.snapshot.rows),h(e.snapshot),r.onAfterRestore?.(e.snapshot.activeCell),p()},S=(e,t)=>r===null?null:{rows:e,after:t,selection:r.selection,activeCell:r.activeCell},C=(e,t)=>{if(!u()||r===null)return;let n=c??r.rows,a=b(e,n),o=a===null?null:S(n,a);if(a===null||o===null)return;let s=t(i,o);x(s===null?null:{stack:s.stack,snapshot:{...s.snapshot,rows:a}})};return{update:m,handleRowsChange:_,amendRowsChange:v,applyRows:y,undo:()=>{C(i.past[i.past.length-1],n.undoHistory)},redo:()=>{C(i.future[i.future.length-1],n.redoHistory)},canUndo:d,canRedo:f,clearHistory:()=>{i=n.createHistoryStack(),l=!1,p()}}};exports.createHistoryController=r;
@@ -20,6 +20,7 @@ export type HistoryControllerArgs<T> = {
20
20
  onUndoRedoStateChange?: (state: UndoRedoState) => void;
21
21
  onAfterRestore?: (activeCell: CellCoord | null) => void;
22
22
  rowKeyGetter?: ((row: T, index: number) => unknown) | undefined;
23
+ onGridRowsChange?: ((prevRows: T[], nextRows: T[]) => void) | undefined;
23
24
  };
24
25
  export type HistoryController<T> = {
25
26
  update: (args: HistoryControllerArgs<T>) => void;
@@ -24,24 +24,24 @@ var c = () => {
24
24
  after: t,
25
25
  selection: c.selection,
26
26
  activeCell: c.activeCell
27
- }, c.limit), u = t, v()), p = t, c.onRowsChange(t));
27
+ }, c.limit), u = t, v()), p = t, c.onGridRowsChange?.(e, t), c.onRowsChange(t));
28
28
  }, S = (e) => {
29
29
  c === null || !c.onRowsChange || x(c.rows, e);
30
30
  }, C = (e) => {
31
- if (!(c === null || !c.onRowsChange)) {
32
- if (c.enabled) {
33
- u = e;
34
- let t = l.past[l.past.length - 1];
35
- t && (l = {
36
- ...l,
37
- past: [...l.past.slice(0, -1), {
38
- ...t,
39
- after: e
40
- }]
41
- });
42
- }
43
- p = e, c.onRowsChange(e);
31
+ if (c === null || !c.onRowsChange) return;
32
+ if (c.enabled) {
33
+ u = e;
34
+ let t = l.past[l.past.length - 1];
35
+ t && (l = {
36
+ ...l,
37
+ past: [...l.past.slice(0, -1), {
38
+ ...t,
39
+ after: e
40
+ }]
41
+ });
44
42
  }
43
+ let t = p ?? c.rows;
44
+ p = e, c.onGridRowsChange?.(t, e), c.onRowsChange(e);
45
45
  }, w = (e, t) => {
46
46
  if (c === null || !c.onRowsChange) return;
47
47
  let n = p ?? c.rows, r = Array.isArray(e) ? e : e(n);
@@ -56,7 +56,10 @@ var c = () => {
56
56
  let r = c?.rowKeyGetter;
57
57
  return !r && (e.rows.length !== e.after.length || e.after.length !== n.length) ? e.rows : t(e.rows, e.after, n, r ?? ((e, t) => t));
58
58
  }, E = (e) => {
59
- e === null || c === null || !c.onRowsChange || (l = e.stack, u = e.snapshot.rows, p = e.snapshot.rows, c.onRowsChange(e.snapshot.rows), b(e.snapshot), c.onAfterRestore?.(e.snapshot.activeCell), v());
59
+ if (e === null || c === null || !c.onRowsChange) return;
60
+ l = e.stack, u = e.snapshot.rows;
61
+ let t = p ?? c.rows;
62
+ p = e.snapshot.rows, c.onGridRowsChange?.(t, e.snapshot.rows), c.onRowsChange(e.snapshot.rows), b(e.snapshot), c.onAfterRestore?.(e.snapshot.activeCell), v();
60
63
  }, D = (e, t) => c === null ? null : {
61
64
  rows: e,
62
65
  after: t,
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../logic/valueStore.cjs"),t=require("../logic/editorKeys.cjs"),n=require("../logic/selectEditorState.cjs"),r=require("../logic/selectSearch.cjs");var i=200,a=e=>e instanceof Error?e.message||e.name:typeof e==`string`?e:String(e),o=i=>{let{allowFreeText:o}=i,s=i.load!==void 0,c={onCommit:i.onCommit,onCancel:i.onCancel,load:i.load},l=i.debounceMs??200,u=String(i.value??``),d=i.options,f=e=>d.find(t=>t.value===e)?.label,p=i.initialText!==void 0,m=i.initialText??f(u)??i.displayText??u,h=p?r.foldSearchQuery(m):``,g=0,_=null,v=null,y=p?m.trim():``,b=!1,x=null,S=``,C=()=>{x=null,S=``},w=(e,t)=>{if(e.length===0)return-1;if(t===``){if(o&&p)return-1;let t=e.findIndex(e=>e.option.value===u);if(t>=0)return t;if(!p)return-1}return o?-1:0},T=s?[]:r.searchSelectOptions(d,h),E=e.createValueStore({text:m,results:T,highlight:w(T,h),status:s?`loading`:`ready`,errorMessage:null,filtered:h!==``}),D=e=>{E.setSnapshot({...E.getSnapshot(),...e})},O=()=>{v!==null&&(clearTimeout(v),v=null)},k=e=>{let t=c.load;if(!t||!b)return;O(),_?.abort();let n=++g,i=new AbortController;_=i,y=e;let o=r.foldSearchQuery(e);D({status:`loading`,errorMessage:null});let s;try{s=Promise.resolve(t(e,i.signal))}catch(e){s=Promise.reject(e)}s.then(e=>{if(n!==g||i.signal.aborted)return;_=null;let t=r.markSelectSearchMatches(Array.isArray(e)?e:[],o),a=w(t,o);D({results:t,highlight:a,status:`ready`,errorMessage:null,filtered:o!==``});let s=x,l=S;C();let u=t[a];s!==null&&u!==void 0&&(l===``?c.onCommit(u.option.value,s.direction,u.option):c.onCommit(u.option.value,s.direction,u.option,l))},e=>{n!==g||i.signal.aborted||(_=null,C(),D({results:[],highlight:-1,status:`error`,errorMessage:a(e),filtered:o!==``}))})},A=e=>p?e.trim():``,j=e=>{let t=r.foldSearchQuery(e);if(t===h&&!(s&&E.getSnapshot().status===`error`)){o&&t===``&&E.getSnapshot().highlight>=0&&D({highlight:-1});return}if(h=t,C(),s){O(),_?.abort(),_=null,g+=1,D({status:`loading`,errorMessage:null,highlight:-1}),v=setTimeout(()=>{v=null,k(A(e))},l);return}let n=r.searchSelectOptions(d,t);D({results:n,highlight:w(n,t),filtered:t!==``})},M=e=>{if(!p)return c.onCommit(i.value,e);let{text:t,results:n}=E.getSnapshot(),a=r.findSelectOptionByLabel(n.map(e=>e.option),t)??r.findSelectOptionByLabel(d,t);return a?c.onCommit(a.value,e,a):c.onCommit(t,e)},N=e=>{let{results:t,highlight:n}=E.getSnapshot(),r=t[n];if(n>=0&&r){c.onCommit(r.option.value,e,r.option);return}if(!p){c.onCommit(i.value,e);return}if(o){M(e);return}s&&E.getSnapshot().status===`loading`&&(x={direction:e},v!==null&&k(A(E.getSnapshot().text)))},P=e=>{let{results:t,highlight:n,status:r}=E.getSnapshot();t.length===0||s&&r===`loading`||D({highlight:e(n,t.length)})};return{getSnapshot:E.getSnapshot,subscribe:E.subscribe,input:(e,t)=>{p=!0,e!==E.getSnapshot().text&&D({text:e}),t||j(e)},keyDown:(e,r)=>{let{key:i}=e;if(x!==null){if(i.length===1&&!e.ctrlKey&&!e.metaKey&&!e.altKey)return e.preventDefault(),S+=i,!0;if(i===`Backspace`&&S!==``)return e.preventDefault(),S=S.slice(0,-1),!0;if(i===`Enter`||i===`Tab`||i===`ArrowDown`||i===`ArrowUp`||i===`PageDown`||i===`PageUp`)return e.preventDefault(),!0}if(i===`ArrowDown`)return e.preventDefault(),P((e,t)=>n.moveHighlight(e,1,t)),!0;if(i===`ArrowUp`)return e.preventDefault(),P((e,t)=>o&&e<=0?-1:n.moveHighlight(e,-1,t)),!0;if(i===`PageDown`||i===`PageUp`){e.preventDefault();let t=i===`PageDown`?8:-8;return P((e,n)=>Math.min(Math.max((e<0?0:e)+t,0),n-1)),!0}return i===`Enter`&&s&&!o&&p&&E.getSnapshot().status===`error`?(e.preventDefault(),k(y),!0):i===`Enter`||i===`Tab`?(e.preventDefault(),N(i===`Enter`?t.resolveEnterDirection(r):e.shiftKey?`left`:`right`),!0):i===`Escape`?(e.preventDefault(),c.onCancel(),!0):!1},hover:e=>{let{results:t,highlight:n,status:r}=E.getSnapshot();s&&r===`loading`||e!==n&&e>=0&&e<t.length&&D({highlight:e})},choose:e=>{let t=E.getSnapshot().results[e];t&&c.onCommit(t.option.value,void 0,t.option)},blur:()=>{if(C(),o&&p){let e=M(void 0);e&&e.status===`rejected`&&c.onCancel();return}c.onCancel()},retry:()=>{s&&k(y)},flush:()=>{C(),o&&p&&M(void 0)},setOptions:e=>{if(e===d)return;let t=e.length===d.length&&e.every((e,t)=>e===d[t]);if(d=e,s||t)return;let{results:n,highlight:i}=E.getSnapshot(),a=n[i]?.option.value,o=r.searchSelectOptions(d,h),c=a===void 0?-1:o.findIndex(e=>e.option.value===a);D({results:o,highlight:c>=0?c:w(o,h)})},setHandlers:e=>{c=e.load===void 0&&s?{...e,load:c.load}:e},attach:()=>(b=!0,s&&k(y),()=>{b=!1,C(),O(),_?.abort(),_=null,g+=1})}};exports.SELECT_SEARCH_DEBOUNCE_MS=i,exports.createSearchSelectEditorController=o;
@@ -0,0 +1,48 @@
1
+ import type { EditorCommitDirection, EditorCommitResult, EditorEnterMove, GridSelectEditorOption } from '../model/gridTypes.unbound.js';
2
+ import { type SelectSearchResult } from '../logic/selectSearch.js';
3
+ export declare const SELECT_SEARCH_DEBOUNCE_MS = 200;
4
+ export type SearchSelectStatus = 'ready' | 'loading' | 'error';
5
+ export type SearchSelectSnapshot = {
6
+ text: string;
7
+ results: readonly SelectSearchResult[];
8
+ highlight: number;
9
+ status: SearchSelectStatus;
10
+ errorMessage: string | null;
11
+ filtered: boolean;
12
+ };
13
+ export type SearchSelectLoad = (query: string, signal: AbortSignal) => Promise<readonly GridSelectEditorOption[]>;
14
+ export type SearchSelectEditorInit = {
15
+ options: readonly GridSelectEditorOption[];
16
+ value: unknown;
17
+ initialText: string | undefined;
18
+ displayText?: string | undefined;
19
+ allowFreeText: boolean;
20
+ load?: SearchSelectLoad | undefined;
21
+ debounceMs?: number | undefined;
22
+ onCommit: (value: unknown, direction: EditorCommitDirection | undefined, option?: GridSelectEditorOption, typedAfter?: string) => EditorCommitResult | void;
23
+ onCancel: () => void;
24
+ };
25
+ export type SearchSelectEditorHandlers = Pick<SearchSelectEditorInit, 'onCommit' | 'onCancel' | 'load'>;
26
+ export type SearchSelectKeyEventLike = {
27
+ key: string;
28
+ shiftKey: boolean;
29
+ ctrlKey?: boolean | undefined;
30
+ metaKey?: boolean | undefined;
31
+ altKey?: boolean | undefined;
32
+ preventDefault: () => void;
33
+ };
34
+ export type SearchSelectEditorController = {
35
+ getSnapshot: () => SearchSelectSnapshot;
36
+ subscribe: (listener: () => void) => () => void;
37
+ input: (text: string, composing: boolean) => void;
38
+ keyDown: (event: SearchSelectKeyEventLike, enterMove: EditorEnterMove | undefined) => boolean;
39
+ hover: (index: number) => void;
40
+ choose: (index: number) => void;
41
+ blur: () => void;
42
+ retry: () => void;
43
+ flush: () => void;
44
+ setOptions: (options: readonly GridSelectEditorOption[]) => void;
45
+ setHandlers: (handlers: SearchSelectEditorHandlers) => void;
46
+ attach: () => () => void;
47
+ };
48
+ export declare const createSearchSelectEditorController: (init: SearchSelectEditorInit) => SearchSelectEditorController;