@ishibashi0112/spreadsheet-grid-core 1.11.0 → 1.12.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 (51) hide show
  1. package/dist/controllers/clipboardController.cjs +3 -1
  2. package/dist/controllers/clipboardController.d.ts +8 -0
  3. package/dist/controllers/clipboardController.js +251 -135
  4. package/dist/controllers/editController.cjs +1 -1
  5. package/dist/controllers/editController.js +109 -103
  6. package/dist/controllers/findController.cjs +1 -1
  7. package/dist/controllers/findController.d.ts +17 -0
  8. package/dist/controllers/findController.js +149 -93
  9. package/dist/controllers/findReplaceController.cjs +1 -0
  10. package/dist/controllers/findReplaceController.d.ts +61 -0
  11. package/dist/controllers/findReplaceController.js +324 -0
  12. package/dist/controllers/keyboardController.cjs +1 -1
  13. package/dist/controllers/keyboardController.d.ts +1 -0
  14. package/dist/controllers/keyboardController.js +4 -0
  15. package/dist/engine/createGridEngine.cjs +1 -1
  16. package/dist/engine/createGridEngine.d.ts +2 -0
  17. package/dist/engine/createGridEngine.js +52 -51
  18. package/dist/engine/exportCommands.cjs +2 -2
  19. package/dist/engine/exportCommands.js +10 -10
  20. package/dist/engine/features.cjs +1 -1
  21. package/dist/engine/features.d.ts +5 -0
  22. package/dist/engine/features.js +39 -15
  23. package/dist/engine/fullFeatures.cjs +1 -1
  24. package/dist/engine/fullFeatures.js +29 -27
  25. package/dist/engine/gridApi.cjs +2 -2
  26. package/dist/engine/gridApi.d.ts +6 -1
  27. package/dist/engine/gridApi.js +29 -3
  28. package/dist/index.cjs +1 -1
  29. package/dist/index.d.ts +1 -1
  30. package/dist/index.js +4 -4
  31. package/dist/locales/en.cjs +1 -1
  32. package/dist/locales/en.js +20 -0
  33. package/dist/logic/clipboardHtml.cjs +1 -0
  34. package/dist/logic/clipboardHtml.d.ts +40 -0
  35. package/dist/logic/clipboardHtml.js +168 -0
  36. package/dist/logic/find.cjs +1 -1
  37. package/dist/logic/find.js +35 -11
  38. package/dist/logic/findReplace.cjs +1 -0
  39. package/dist/logic/findReplace.d.ts +35 -0
  40. package/dist/logic/findReplace.js +84 -0
  41. package/dist/logic/localeTextFeatures.cjs +1 -1
  42. package/dist/logic/localeTextFeatures.d.ts +22 -0
  43. package/dist/logic/localeTextFeatures.js +24 -3
  44. package/dist/logic/selectionOverlayGeometry.cjs +1 -1
  45. package/dist/logic/selectionOverlayGeometry.d.ts +14 -0
  46. package/dist/logic/selectionOverlayGeometry.js +36 -4
  47. package/dist/model/gridTypes.core.d.ts +95 -3
  48. package/dist/utils/clipboard.cjs +5 -4
  49. package/dist/utils/clipboard.d.ts +10 -1
  50. package/dist/utils/clipboard.js +48 -33
  51. package/package.json +1 -1
@@ -3,100 +3,128 @@ import { createValueStore as t } from "../logic/valueStore.js";
3
3
  import { runChunked as n } from "../logic/chunkedLoop.js";
4
4
  import { buildFindIndex as r, findRangesInCell as i, isFindableColumn as a, resolveCurrentAfterRescan as o, resolveFindCellText as s, stepFindIndex as c } from "../logic/find.js";
5
5
  //#region src/controllers/findController.ts
6
- var l = 1e4, u = 5e4, d = /* @__PURE__ */ new Map(), f = [], p = (e, t) => e.length === t.length && e.every((e, n) => {
6
+ var l = (e, t, n) => t >= e.startRow && t <= e.endRow && n >= e.startCol && n <= e.endCol && (e.rows === void 0 || e.rows.has(t)), u = (e) => {
7
+ if (e.rows === void 0) return [{
8
+ startRow: e.startRow,
9
+ endRow: e.endRow
10
+ }];
11
+ let t = [...e.rows].sort((e, t) => e - t), n = [];
12
+ for (let e of t) {
13
+ let t = n[n.length - 1];
14
+ t && e === t.endRow + 1 ? t.endRow = e : n.push({
15
+ startRow: e,
16
+ endRow: e
17
+ });
18
+ }
19
+ return n;
20
+ }, d = (e, t, n) => {
21
+ if (e.length === 0) return null;
22
+ let r = e.findIndex((e) => e.rowIndex > t || e.rowIndex === t && e.colIndex > n);
23
+ return r < 0 ? 0 : r;
24
+ }, f = (e, t, n) => {
25
+ if (e.length === 0) return null;
26
+ if (n.rowKey === void 0) return d(e, n.rowIndex, n.colIndex);
27
+ let r = e.findIndex((e) => e.columnKey === n.columnKey && t.getRowKey(e.rowIndex) === n.rowKey);
28
+ if (r >= 0) return r;
29
+ let i = e.findIndex((e) => e.rowIndex > n.rowIndex || e.rowIndex === n.rowIndex && e.colIndex >= n.colIndex);
30
+ return i < 0 ? 0 : i;
31
+ }, p = 1e4, m = 5e4, h = /* @__PURE__ */ new Map(), g = [], _ = (e, t) => e.length === t.length && e.every((e, n) => {
7
32
  let r = t[n];
8
33
  return e.rowIndex === r.rowIndex && e.colIndex === r.colIndex && e.columnKey === r.columnKey && e.start === r.start && e.length === r.length;
9
- }), m = () => {
10
- let l = null, m = 0, h = null, g = !1, _, v = null, y = t({
34
+ }), v = () => {
35
+ let u = null, p = 0, v = null, y = !1, b = !1, x = null, S, C = null, w = t({
11
36
  open: !1,
12
37
  query: "",
13
38
  matches: [],
14
- index: d,
39
+ index: h,
15
40
  currentIndex: null,
16
41
  scanning: !1,
17
- truncated: !1
18
- }), b = (e) => {
19
- y.setSnapshot({
20
- ...y.getSnapshot(),
42
+ truncated: !1,
43
+ focusRequest: 0
44
+ }), T = (e) => {
45
+ w.setSnapshot({
46
+ ...w.getSnapshot(),
21
47
  ...e
22
48
  });
23
- }, x = null, S = () => {
24
- let e = y.getSnapshot(), t = {
49
+ }, E = null, D = () => {
50
+ let e = w.getSnapshot(), t = {
25
51
  query: e.query,
26
52
  matchCount: e.matches.length,
27
53
  currentIndex: e.currentIndex,
28
54
  open: e.open,
29
55
  truncated: e.truncated
30
56
  };
31
- x !== null && x.query === t.query && x.matchCount === t.matchCount && x.currentIndex === t.currentIndex && x.open === t.open && x.truncated === t.truncated || (x = t, l?.onChange?.(t));
32
- }, C = (e) => {
33
- let t = y.getSnapshot();
57
+ E !== null && E.query === t.query && E.matchCount === t.matchCount && E.currentIndex === t.currentIndex && E.open === t.open && E.truncated === t.truncated || (E = t, u?.onChange?.(t));
58
+ }, O = (e) => {
59
+ let t = w.getSnapshot();
34
60
  if (t.currentIndex === null) return;
35
61
  let n = t.matches[t.currentIndex];
36
- n && l?.onNavigate(n.rowIndex, n.colIndex, e);
37
- }, w = () => {
38
- m += 1, v = null, h = null, g = !1, b({
62
+ n && u?.onNavigate(n.rowIndex, n.colIndex, e);
63
+ }, k = () => {
64
+ p += 1, C = null, v = null, y = !1, b = !1, x = null, T({
39
65
  matches: [],
40
- index: d,
66
+ index: h,
41
67
  currentIndex: null,
42
68
  scanning: !1,
43
69
  truncated: !1
44
70
  });
45
- }, T = (t, c = !1) => {
46
- let d = l, x = y.getSnapshot();
47
- if (!d || !x.open || x.query.length === 0) {
48
- w(), S();
71
+ }, A = (t, c = !1) => {
72
+ let d = u, h = w.getSnapshot();
73
+ if (!d || !h.open || h.query.length === 0) {
74
+ k(), D();
49
75
  return;
50
76
  }
51
- m += 1;
52
- let E = m, { rowModel: D, columns: O, caseSensitive: k } = d, A = d.conditionalFormat !== !1, j = d.multiSelectSeparator, M = x.query, N = v !== null && v.query === M && v.caseSensitive === k;
53
- v = {
54
- rowModel: D,
55
- columns: O,
56
- query: M,
57
- caseSensitive: k,
58
- conditionalFormatShown: A,
59
- separator: j
60
- }, (c || h === null || h.columns !== O || h.query !== M || h.caseSensitive !== k || h.conditionalFormatShown !== A || h.separator !== j) && (h = {
61
- columns: O,
62
- query: M,
63
- caseSensitive: k,
64
- conditionalFormatShown: A,
65
- separator: j,
77
+ p += 1;
78
+ let E = p, { rowModel: j, columns: M, caseSensitive: N } = d, P = d.conditionalFormat !== !1, F = d.multiSelectSeparator, I = d.scope ?? null, L = d.toViewRow, R = h.query, z = C !== null && C.query === R && C.caseSensitive === N;
79
+ C = {
80
+ rowModel: j,
81
+ columns: M,
82
+ query: R,
83
+ caseSensitive: N,
84
+ conditionalFormatShown: P,
85
+ separator: F,
86
+ scope: I
87
+ }, (c || v === null || v.columns !== M || v.query !== R || v.caseSensitive !== N || v.conditionalFormatShown !== P || v.separator !== F) && (v = {
88
+ columns: M,
89
+ query: R,
90
+ caseSensitive: N,
91
+ conditionalFormatShown: P,
92
+ separator: F,
66
93
  byRow: /* @__PURE__ */ new WeakMap()
67
94
  });
68
- let P = h.byRow, F = 0, I = t || g;
69
- g = I;
70
- let L = x.currentIndex === null ? null : x.matches[x.currentIndex] ?? null, R = [], z = !1, B = D.getRowCount(), V = B > u, H = (t, n) => {
95
+ let B = v.byRow, V = 0, H = t || y;
96
+ y = H;
97
+ let U = h.currentIndex === null ? null : h.matches[h.currentIndex] ?? null, W = [], G = !1, K = j.getRowCount(), q = K > m, J = (t, n) => {
71
98
  let r = [];
72
- return O.forEach((o, c) => {
73
- if (e(o.key) || !a(o, A, t)) return;
74
- let l = s(o, t, !A || o.conditionalFormat?.chips === void 0 ? void 0 : {
99
+ return M.forEach((o, c) => {
100
+ if (e(o.key) || !a(o, P, t)) return;
101
+ let l = s(o, t, !P || o.conditionalFormat?.chips === void 0 ? void 0 : {
75
102
  rowIndex: n,
76
- sourceRowIndex: D.getSourceIndex(n) ?? n,
77
- rowKey: D.getRowKey(n) ?? n,
103
+ sourceRowIndex: j.getSourceIndex(n) ?? n,
104
+ rowKey: j.getRowKey(n) ?? n,
78
105
  colIndex: c
79
- }, j);
80
- for (let e of i(o, t, l, M, k, j)) r.push({
106
+ }, F);
107
+ for (let e of i(o, t, l, R, N, F)) r.push({
81
108
  colIndex: c,
82
109
  columnKey: String(o.key),
83
110
  start: e.start,
84
111
  length: e.length
85
112
  });
86
- }), r.length === 0 ? f : r;
113
+ }), r.length === 0 ? g : r;
87
114
  };
88
- !N && !x.scanning && b({ scanning: !0 }), n(B, (e) => {
89
- if (z) return;
90
- let t = D.getRow(e);
115
+ !z && !h.scanning && T({ scanning: !0 }), n(K, (e) => {
116
+ if (G) return;
117
+ let t = j.getRow(e);
91
118
  if (t === void 0) return;
92
- let n = D.getTreeRow?.(e)?.aggregates, r;
93
- V && typeof t == "object" && t ? (r = P.get(t), r === void 0 ? (r = H(t, e), P.set(t, r)) : F += 1) : r = H(t, e);
94
- for (let t of r) if (!(n !== void 0 && t.columnKey in n)) {
95
- if (R.length >= 1e4) {
96
- z = !0;
119
+ let n = j.getTreeRow?.(e)?.aggregates, r;
120
+ q && typeof t == "object" && t ? (r = B.get(t), r === void 0 ? (r = J(t, e), B.set(t, r)) : V += 1) : r = J(t, e);
121
+ let i = I === null ? e : L ? L(e) : e;
122
+ for (let t of r) if (!(n !== void 0 && t.columnKey in n) && !(I !== null && !l(I, i, t.colIndex))) {
123
+ if (W.length >= 1e4) {
124
+ G = !0;
97
125
  return;
98
126
  }
99
- R.push({
127
+ W.push({
100
128
  rowIndex: e,
101
129
  colIndex: t.colIndex,
102
130
  columnKey: t.columnKey,
@@ -104,70 +132,98 @@ var l = 1e4, u = 5e4, d = /* @__PURE__ */ new Map(), f = [], p = (e, t) => e.len
104
132
  length: t.length
105
133
  });
106
134
  }
107
- }, { isCancelled: () => m !== E }).then((e) => {
108
- if (!e || m !== E || (g = !1, c && z === y.getSnapshot().truncated && p(y.getSnapshot().matches, R))) return;
109
- let t = o(R, L);
110
- b({
111
- matches: R,
112
- index: r(R, l?.toViewRow),
113
- currentIndex: t,
135
+ }, { isCancelled: () => p !== E }).then((e) => {
136
+ if (!e || p !== E) return;
137
+ y = !1;
138
+ let t = b;
139
+ if (b = !1, c && G === w.getSnapshot().truncated && _(w.getSnapshot().matches, W)) return;
140
+ let n = x;
141
+ x = null;
142
+ let i = n === null ? o(W, U) : f(W, j, n);
143
+ T({
144
+ matches: W,
145
+ index: r(W, u?.toViewRow),
146
+ currentIndex: i,
114
147
  scanning: !1,
115
- truncated: z
116
- }), _ = l?.toViewRow, S(), I && C("query"), !c && F > 0 && T(!1, !0);
148
+ truncated: G
149
+ }), S = u?.toViewRow, D(), H ? O("query") : (n !== null || t) && O("step"), !c && V > 0 && A(!1, !0);
117
150
  });
118
- }, E = () => {
119
- let e = y.getSnapshot();
120
- return !l || !e.open || e.query.length === 0 ? !1 : v === null || v.rowModel !== l.rowModel || v.columns !== l.columns || v.query !== e.query || v.caseSensitive !== l.caseSensitive || v.conditionalFormatShown !== (l.conditionalFormat !== !1) || v.separator !== l.multiSelectSeparator;
151
+ }, j = () => {
152
+ let e = w.getSnapshot();
153
+ return !u || !e.open || e.query.length === 0 ? !1 : C === null || C.rowModel !== u.rowModel || C.columns !== u.columns || C.query !== e.query || C.caseSensitive !== u.caseSensitive || C.conditionalFormatShown !== (u.conditionalFormat !== !1) || C.separator !== u.multiSelectSeparator || C.scope !== (u.scope ?? null);
121
154
  };
122
155
  return {
123
156
  update: (e) => {
124
- let t = l;
125
- if (l = e, !e.enabled) {
126
- y.getSnapshot().open && (b({
157
+ let t = u;
158
+ if (u = e, !e.enabled) {
159
+ w.getSnapshot().open && (T({
127
160
  open: !1,
128
161
  query: ""
129
- }), w(), S());
162
+ }), k(), D());
130
163
  return;
131
164
  }
132
- if (t !== e && E()) {
133
- T(!1);
165
+ if (t !== e && j()) {
166
+ A(!1);
134
167
  return;
135
168
  }
136
- let n = y.getSnapshot();
137
- e.toViewRow !== _ && !n.scanning && (_ = e.toViewRow, n.matches.length > 0 && b({ index: r(n.matches, e.toViewRow) }));
169
+ let n = w.getSnapshot();
170
+ e.toViewRow !== S && !n.scanning && (S = e.toViewRow, n.matches.length > 0 && T({ index: r(n.matches, e.toViewRow) }));
138
171
  },
139
172
  open: (e) => {
140
- if (!l?.enabled) return;
141
- let t = y.getSnapshot(), n = e ?? t.query;
142
- b({
173
+ if (!u?.enabled) return;
174
+ let t = w.getSnapshot(), n = e ?? t.query;
175
+ T({
143
176
  open: !0,
144
- query: n
145
- }), n !== t.query || !t.open ? T(!0) : S();
177
+ query: n,
178
+ focusRequest: t.focusRequest + 1
179
+ }), n !== t.query || !t.open ? A(!0) : D();
146
180
  },
147
181
  close: () => {
148
- y.getSnapshot().open && (b({
182
+ w.getSnapshot().open && (T({
149
183
  open: !1,
150
184
  query: ""
151
- }), w(), S());
185
+ }), k(), D());
152
186
  },
153
187
  setQuery: (e) => {
154
- let t = y.getSnapshot();
155
- !t.open || e === t.query || (b({ query: e }), T(!0));
188
+ let t = w.getSnapshot();
189
+ !t.open || e === t.query || (x = null, T({ query: e }), A(!0));
156
190
  },
157
191
  next: () => {
158
- let e = y.getSnapshot(), t = c(e.currentIndex, e.matches.length, 1);
159
- b({ currentIndex: t }), S(), C("step");
192
+ let e = w.getSnapshot(), t = c(e.currentIndex, e.matches.length, 1);
193
+ T({ currentIndex: t }), D(), O("step");
160
194
  },
161
195
  prev: () => {
162
- let e = y.getSnapshot(), t = c(e.currentIndex, e.matches.length, -1);
163
- b({ currentIndex: t }), S(), C("step");
196
+ let e = w.getSnapshot(), t = c(e.currentIndex, e.matches.length, -1);
197
+ T({ currentIndex: t }), D(), O("step");
198
+ },
199
+ continueAfter: (e, t, n) => {
200
+ if (n) {
201
+ let n = w.getSnapshot(), r = d(n.matches, e, t), i = r === null ? void 0 : n.matches[r];
202
+ x = i === void 0 || !u ? {
203
+ rowIndex: e,
204
+ colIndex: t,
205
+ rowKey: void 0,
206
+ columnKey: ""
207
+ } : {
208
+ rowIndex: i.rowIndex,
209
+ colIndex: i.colIndex,
210
+ rowKey: u.rowModel.getRowKey(i.rowIndex),
211
+ columnKey: i.columnKey
212
+ };
213
+ return;
214
+ }
215
+ let r = w.getSnapshot();
216
+ T({ currentIndex: d(r.matches, e, t) }), D(), O("step");
217
+ },
218
+ navigateAfterRescan: () => {
219
+ b = !0;
164
220
  },
165
- subscribe: y.subscribe,
166
- getSnapshot: y.getSnapshot,
221
+ subscribe: w.subscribe,
222
+ getSnapshot: w.getSnapshot,
167
223
  dispose: () => {
168
- m += 1, l = null;
224
+ p += 1, u = null;
169
225
  }
170
226
  };
171
227
  };
172
228
  //#endregion
173
- export { u as FIND_HIT_CACHE_ROW_THRESHOLD, l as MAX_FIND_MATCHES, m as createFindController };
229
+ export { m as FIND_HIT_CACHE_ROW_THRESHOLD, p as MAX_FIND_MATCHES, v as createFindController, u as findScopeRowRuns, d as firstFindMatchAfter, l as isInFindScope };
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../utils/permissions.cjs"),t=require("../logic/detailRow.cjs"),n=require("../logic/valueStore.cjs"),r=require("../logic/chunkedLoop.cjs"),i=require("../logic/find.cjs"),a=require("./findController.cjs"),o=require("../logic/findReplace.cjs");var s={replaced:0,skipped:0},c=(e,t,n)=>{if(e===null||t<=0||n<=0)return null;if(e.type===`row`)return{startRow:Math.max(0,Math.min(e.startRow,e.endRow)),endRow:Math.min(t-1,Math.max(e.startRow,e.endRow)),startCol:0,endCol:n-1};if(e.type===`col`)return{startRow:0,endRow:t-1,startCol:Math.max(0,Math.min(e.startCol,e.endCol)),endCol:Math.min(n-1,Math.max(e.startCol,e.endCol))};let{start:r,end:i}=e.range;return{startRow:Math.max(0,Math.min(r.row,i.row)),endRow:Math.min(t-1,Math.max(r.row,i.row)),startCol:Math.max(0,Math.min(r.col,i.col)),endCol:Math.min(n-1,Math.max(r.col,i.col))}},l=(t,n,r,i,a)=>{let o=t.toViewRow?t.toViewRow(n):n;return e.isCellEditable(t,o>=0?o:n,r,i,a,t.canEditCell?e.resolveCanEditCellContext(t.rowModel,n):void 0)},u=(e,t)=>e.length===t.length&&e.every((e,n)=>Object.is(e,t[n])),d=()=>{let d=null,f=0,p=null,m=null,h=``,g=!1,_=null,v=null,y,b=null,x=null,S=n.createValueStore({expanded:!1,replacement:``,scope:null,running:!1,notice:null,noticeId:0}),C=e=>{let t=S.getSnapshot();S.setSnapshot({...t,...e,noticeId:e.notice?t.noticeId+1:t.noticeId})},w=()=>{let e=d;if(!e?.enabled)return;let t=c(e.getSelection(),e.viewRowCount,e.columns.length);t!==null&&(t.endRow-t.startRow+1)*(t.endCol-t.startCol+1)>=2&&(b={rect:t,signature:e.viewSignature})},T=e=>{let t=e.getSelection(),n=e.find.getSnapshot(),r=n.currentIndex===null?void 0:n.matches[n.currentIndex];if(!r)return!1;let i=e.toViewRow?e.toViewRow(r.rowIndex):r.rowIndex;if(t===null)return!0;if(t.type!==`cell`)return!1;let{start:a,end:o}=t.range;return a.row===o.row&&a.col===o.col&&a.row===i&&a.col===r.colIndex},E=()=>{let e=d?.find;if(!e)return;let t=e.getSnapshot();x!==null&&t.matches!==x.matches&&(x=null),g&&!t.open?(f+=1,_=null,x=null,b=null,C({scope:null,notice:null,running:!1})):((t.open&&!g||t.query!==h)&&w(),t.query!==h&&S.getSnapshot().notice!==null&&C({notice:null})),g=t.open,h=t.query},D=(n,r,a,s,c)=>{let{rowModel:u,columns:d,caseSensitive:f,multiSelectSeparator:p}=n,m=u.newRow;if(m!==void 0&&s>=m.index)return null;let h=u.getRow(s),g=d[c],_=n.conditionalFormat!==!1;if(h===void 0||!g||t.isSyntheticColumnKey(g.key)||!i.isFindableColumn(g,_,h))return null;let v=u.getTreeRow?.(s)?.aggregates;if(v!==void 0&&g.key in v)return null;let y=i.resolveFindCellText(g,h,!_||g.conditionalFormat?.chips===void 0?void 0:{rowIndex:s,sourceRowIndex:u.getSourceIndex(s)??s,rowKey:u.getRowKey(s)??s,colIndex:c},p),b=i.findRangesInCell(g,h,y,r,f,p),x=o.resolveCellReplacement({column:g,row:h,text:y,ranges:b,replacement:a,editable:b.length>0&&l(n,s,c,h,g),separator:p,validationTexts:n.validationTexts});return x===null?null:x.action===`write`&&Object.is(e.getCellValue(h,g),x.value)?{replacement:{action:`skip`,reason:`unchanged`,count:x.count},row:h,column:g}:{replacement:x,row:h,column:g}},O=()=>{let e=d?.find.getSnapshot();return e&&e.open&&e.query.length>0?e.query:null},k=e=>(e!==void 0&&e!==S.getSnapshot().replacement&&C({replacement:e}),S.getSnapshot().replacement),A=(e,t,n,r)=>t===null||a.isInFindScope(t,e.toViewRow?e.toViewRow(n):n,r),j=e=>{if(_===null)return null;let{rowModel:t,toViewRow:n}=e,r=t.newRow===void 0?t.getRowCount():t.newRow.index,i=new Set,a=1/0,o=-1;for(let e=0;e<r;e+=1){if(!_.rowKeys.has(t.getRowKey(e)))continue;let r=n?n(e):e;r<0||(i.add(r),a=Math.min(a,r),o=Math.max(o,r))}return o<0?{startRow:0,endRow:-1,startCol:_.startCol,endCol:_.endCol,rows:i}:{startRow:a,endRow:o,startCol:_.startCol,endCol:_.endCol,rows:i.size===o-a+1?void 0:i}},M=(e,t)=>{if(_===null||t===null||t.rows!==void 0||e.toViewRow!==void 0||t.endRow-t.startRow+1!==_.rowKeys.size)return!1;let{rowModel:n}=e,r=n.newRow===void 0?n.getRowCount():n.newRow.index;if(t.endRow>=r)return!1;for(let e=t.startRow;e<=t.endRow;e+=1)if(!_.rowKeys.has(n.getRowKey(e)))return!1;return!0},N=(e,t)=>e===null||t===null?e===t:e.startRow!==t.startRow||e.endRow!==t.endRow||e.startCol!==t.startCol||e.endCol!==t.endCol?!1:e.rows===void 0||t.rows===void 0?e.rows===t.rows:e.rows.size===t.rows.size&&[...e.rows].every(e=>t.rows?.has(e)===!0),P=()=>{_=null,v=null,y=void 0};return{update:e=>{let t=d;if(d=e,m!==e.find){p?.(),m=e.find;let t=e.find.getSnapshot();g=t.open,h=t.query,p=e.find.subscribe(E)}let n=S.getSnapshot();if(!e.enabled){P(),x=null,(n.expanded||n.scope!==null||n.running||n.notice!==null)&&(f+=1,C({expanded:!1,scope:null,running:!1,notice:null}));return}if(_!==null){if(t!==null&&!u(t.viewSignature,e.viewSignature)){P(),C({scope:null});return}if(e.rowModel!==v||e.toViewRow!==y){if(v=e.rowModel,y=e.toViewRow,M(e,n.scope))return;let t=j(e);t===null&&P(),N(t,n.scope)||C({scope:t})}}},open:(e,t)=>{let n=d;if(!n)return;let r=n.find.getSnapshot().open;r&&w(),n.enabled&&(e?C({expanded:!0}):r||C({expanded:!1})),n.find.open(t)},setExpanded:e=>{!d?.enabled||S.getSnapshot().expanded===e||(e||P(),C(e?{expanded:e}:{expanded:e,scope:null,notice:null}))},setReplacement:e=>{e!==S.getSnapshot().replacement&&C({replacement:e,notice:null})},setScopeEnabled:e=>{let t=d;if(!t?.enabled)return!1;if(!e)return P(),S.getSnapshot().scope!==null&&t.find.navigateAfterRescan(),C({scope:null,notice:null}),!0;let n=c(t.getSelection(),t.viewRowCount,t.columns.length),r=e=>e===null?0:(e.endRow-e.startRow+1)*(e.endCol-e.startCol+1);if(r(n)<2&&b!==null&&u(b.signature,t.viewSignature)&&T(t)&&(n=b.rect),n===null||r(n)<2)return C({notice:{kind:`scopeNeedsRange`}}),!1;let{rowModel:i,toViewRow:a}=t,o=i.newRow===void 0?i.getRowCount():i.newRow.index,s=new Set;if(a)for(let e=0;e<o;e+=1){let t=a(e);t>=n.startRow&&t<=n.endRow&&s.add(i.getRowKey(e))}else for(let e=n.startRow;e<=Math.min(n.endRow,o-1);e+=1)s.add(i.getRowKey(e));_={rowKeys:s,startCol:n.startCol,endCol:n.endCol},v=i,y=a;let l=j(t);return l===null?(P(),C({notice:{kind:`scopeNeedsRange`}}),!1):(t.find.navigateAfterRescan(),C({scope:l,notice:null}),!0)},replaceCurrent:e=>{let t=d,n=k(e),r=O();if(!t?.enabled||r===null||S.getSnapshot().running)return s;let i=x!==null&&t.rows===x.from?x:null,a=i?.rows??t.rows,c=t.find.getSnapshot(),l=c.currentIndex===null?void 0:c.matches[c.currentIndex];if(l&&i!==null&&l.columnKey===i.columnKey&&t.rowModel.getRowKey(l.rowIndex)===i.rowKey&&(t.find.continueAfter(l.rowIndex,l.colIndex,!1),c=t.find.getSnapshot(),l=c.currentIndex===null?void 0:c.matches[c.currentIndex],l&&l.columnKey===i.columnKey&&t.rowModel.getRowKey(l.rowIndex)===i.rowKey))return s;if(!l)return c.matches.length===0&&!c.scanning&&C({notice:{kind:`result`,replaced:0,skipped:0}}),s;let u=D(t,r,n,l.rowIndex,l.colIndex);if(u===null)return t.find.continueAfter(l.rowIndex,l.colIndex,!1),s;let f=u.replacement;if(f.action===`skip`)return C({notice:{kind:`cellSkipped`,reason:f.reason,message:f.message}}),t.find.continueAfter(l.rowIndex,l.colIndex,!1),{replaced:0,skipped:f.count};let p=t.rowModel.getSourceIndex(l.rowIndex);if(p===void 0)return s;C({notice:{kind:`result`,replaced:f.count,skipped:0}});let m=o.applyFindReplaceWrites(a,[{sourceIndex:p,column:u.column,value:f.value}]);return m===a?t.find.continueAfter(l.rowIndex,l.colIndex,!1):(t.find.continueAfter(l.rowIndex,l.colIndex,!0),x={from:t.rows,rows:m,rowKey:t.rowModel.getRowKey(l.rowIndex),columnKey:l.columnKey,matches:c.matches},t.commitRows(m)),{replaced:f.count,skipped:0}},replaceAll:async e=>{let t=k(e),n=O();if(!d?.enabled||n===null||S.getSnapshot().running)return s;f+=1;let i=f,a=_,c=()=>a!==_;C({running:!0,notice:null});for(let e=0;e<3;e+=1){let e=d;if(!e?.enabled||f!==i)return s;if(c())return C({running:!1}),s;let a=e.rows,l=S.getSnapshot().scope,u=[],p=0,m=0,h=e.columns.length,g=await r.runChunked(e.rowModel.getRowCount(),r=>{for(let i=0;i<h;i+=1){if(!A(e,l,r,i))continue;let a=D(e,n,t,r,i);if(a===null)continue;let o=a.replacement;if(o.action===`skip`){m+=o.count;continue}let s=e.rowModel.getSourceIndex(r);s!==void 0&&(p+=o.count,u.push({sourceIndex:s,column:a.column,value:o.value}))}},{isCancelled:()=>f!==i||c()});if(f!==i)return s;if(!g||c())return C({running:!1}),s;if(d!==null&&d.rows!==a)continue;C({running:!1,notice:{kind:`result`,replaced:p,skipped:m}});let _=o.applyFindReplaceWrites(a,u);return _!==a&&e.commitRows(_),{replaced:p,skipped:m}}return C({running:!1,notice:{kind:`interrupted`}}),s},subscribe:S.subscribe,getSnapshot:S.getSnapshot,dispose:()=>{f+=1,P(),x=null,b=null,p?.(),p=null,m=null,d=null}}};exports.createFindReplaceController=d,exports.resolveFindScopeFromSelection=c;
@@ -0,0 +1,61 @@
1
+ import type { GridColumn, GridSelection, RowModel, SpreadsheetGridProps } from '../model/gridTypes.unbound.js';
2
+ import type { FindController, FindScope } from './findController.js';
3
+ import { type FindReplaceSkipReason } from '../logic/findReplace.js';
4
+ import type { ValidationLocaleText } from '../logic/validation.js';
5
+ export type FindReplaceResult = {
6
+ replaced: number;
7
+ skipped: number;
8
+ };
9
+ export type FindReplaceNotice = {
10
+ kind: 'result';
11
+ replaced: number;
12
+ skipped: number;
13
+ } | {
14
+ kind: 'cellSkipped';
15
+ reason: FindReplaceSkipReason;
16
+ message?: string | undefined;
17
+ } | {
18
+ kind: 'scopeNeedsRange';
19
+ } | {
20
+ kind: 'interrupted';
21
+ };
22
+ export type FindReplaceSnapshot = {
23
+ expanded: boolean;
24
+ replacement: string;
25
+ scope: FindScope | null;
26
+ running: boolean;
27
+ notice: FindReplaceNotice | null;
28
+ noticeId: number;
29
+ };
30
+ export type FindReplaceArgs<T> = {
31
+ enabled: boolean;
32
+ find: FindController<T>;
33
+ rows: readonly T[];
34
+ rowModel: RowModel<T>;
35
+ columns: readonly GridColumn<T>[];
36
+ caseSensitive: boolean;
37
+ conditionalFormat?: boolean | undefined;
38
+ multiSelectSeparator?: string | undefined;
39
+ validationTexts?: ValidationLocaleText | undefined;
40
+ toViewRow?: ((rowIndex: number) => number) | undefined;
41
+ readOnly: boolean;
42
+ canEditCell: SpreadsheetGridProps<T>['canEditCell'];
43
+ commitRows: (nextRows: T[]) => void;
44
+ getSelection: () => GridSelection;
45
+ viewRowCount: number;
46
+ viewSignature: readonly unknown[];
47
+ };
48
+ export type FindReplaceController<T> = {
49
+ update: (args: FindReplaceArgs<T>) => void;
50
+ open: (withReplace: boolean, query?: string) => void;
51
+ setExpanded: (expanded: boolean) => void;
52
+ setReplacement: (text: string) => void;
53
+ setScopeEnabled: (enabled: boolean) => boolean;
54
+ replaceCurrent: (text?: string) => FindReplaceResult;
55
+ replaceAll: (text?: string) => Promise<FindReplaceResult>;
56
+ subscribe: (listener: () => void) => () => void;
57
+ getSnapshot: () => FindReplaceSnapshot;
58
+ dispose: () => void;
59
+ };
60
+ export declare const resolveFindScopeFromSelection: (selection: GridSelection, viewRowCount: number, columnCount: number) => FindScope | null;
61
+ export declare const createFindReplaceController: <T>() => FindReplaceController<T>;