@ishibashi0112/spreadsheet-grid-core 1.11.0 → 1.13.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.
- package/dist/controllers/changeTracker.cjs +1 -1
- package/dist/controllers/changeTracker.d.ts +9 -0
- package/dist/controllers/changeTracker.js +205 -145
- package/dist/controllers/clipboardController.cjs +3 -1
- package/dist/controllers/clipboardController.d.ts +8 -0
- package/dist/controllers/clipboardController.js +251 -135
- package/dist/controllers/editController.cjs +1 -1
- package/dist/controllers/editController.js +109 -103
- package/dist/controllers/findController.cjs +1 -1
- package/dist/controllers/findController.d.ts +17 -0
- package/dist/controllers/findController.js +149 -93
- package/dist/controllers/findReplaceController.cjs +1 -0
- package/dist/controllers/findReplaceController.d.ts +61 -0
- package/dist/controllers/findReplaceController.js +324 -0
- package/dist/controllers/keyboardController.cjs +1 -1
- package/dist/controllers/keyboardController.d.ts +2 -0
- package/dist/controllers/keyboardController.js +13 -1
- package/dist/controllers/rowDiffer.cjs +2 -0
- package/dist/controllers/rowDiffer.d.ts +19 -0
- package/dist/controllers/rowDiffer.js +131 -0
- package/dist/engine/createGridEngine.cjs +1 -1
- package/dist/engine/createGridEngine.d.ts +2 -0
- package/dist/engine/createGridEngine.js +52 -51
- package/dist/engine/diffStage.cjs +1 -0
- package/dist/engine/diffStage.d.ts +26 -0
- package/dist/engine/diffStage.js +117 -0
- package/dist/engine/exportCommands.cjs +2 -2
- package/dist/engine/exportCommands.js +10 -10
- package/dist/engine/features.cjs +1 -1
- package/dist/engine/features.d.ts +13 -0
- package/dist/engine/features.js +39 -15
- package/dist/engine/fullFeatures.cjs +1 -1
- package/dist/engine/fullFeatures.js +37 -27
- package/dist/engine/gridApi.cjs +9 -8
- package/dist/engine/gridApi.d.ts +11 -2
- package/dist/engine/gridApi.js +294 -217
- package/dist/engine/newRowController.cjs +1 -1
- package/dist/engine/newRowController.js +1 -0
- package/dist/engine/rowPipeline.cjs +1 -1
- package/dist/engine/rowPipeline.d.ts +8 -1
- package/dist/engine/rowPipeline.js +32 -22
- package/dist/engine/treeStage.cjs +1 -1
- package/dist/engine/treeStage.d.ts +1 -0
- package/dist/engine/treeStage.js +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -4
- package/dist/locales/en.cjs +1 -1
- package/dist/locales/en.js +32 -0
- package/dist/logic/changeNavigation.cjs +1 -0
- package/dist/logic/changeNavigation.d.ts +25 -0
- package/dist/logic/changeNavigation.js +62 -0
- package/dist/logic/changeTracking.cjs +1 -1
- package/dist/logic/changeTracking.d.ts +1 -0
- package/dist/logic/changeTracking.js +8 -5
- package/dist/logic/clipboardHtml.cjs +1 -0
- package/dist/logic/clipboardHtml.d.ts +40 -0
- package/dist/logic/clipboardHtml.js +168 -0
- package/dist/logic/diffView.cjs +1 -0
- package/dist/logic/diffView.d.ts +20 -0
- package/dist/logic/diffView.js +51 -0
- package/dist/logic/find.cjs +1 -1
- package/dist/logic/find.js +35 -11
- package/dist/logic/findReplace.cjs +1 -0
- package/dist/logic/findReplace.d.ts +35 -0
- package/dist/logic/findReplace.js +84 -0
- package/dist/logic/localeTextFeatures.cjs +1 -1
- package/dist/logic/localeTextFeatures.d.ts +36 -0
- package/dist/logic/localeTextFeatures.js +41 -7
- package/dist/logic/multiSelect.cjs +1 -1
- package/dist/logic/multiSelect.js +1 -1
- package/dist/logic/rangeDecorations.cjs +4 -0
- package/dist/logic/rangeDecorations.d.ts +78 -0
- package/dist/logic/rangeDecorations.js +223 -0
- package/dist/logic/rowDiff.cjs +1 -0
- package/dist/logic/rowDiff.d.ts +57 -0
- package/dist/logic/rowDiff.js +169 -0
- package/dist/logic/selectionOverlayGeometry.cjs +1 -1
- package/dist/logic/selectionOverlayGeometry.d.ts +14 -0
- package/dist/logic/selectionOverlayGeometry.js +36 -4
- package/dist/logic/sorting.cjs +1 -1
- package/dist/logic/sorting.d.ts +1 -0
- package/dist/logic/sorting.js +42 -27
- package/dist/model/gridStore.d.ts +4 -1
- package/dist/model/gridTypes.core.d.ts +218 -26
- package/dist/utils/clipboard.cjs +5 -4
- package/dist/utils/clipboard.d.ts +10 -1
- package/dist/utils/clipboard.js +48 -33
- 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 =
|
|
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
|
-
}),
|
|
10
|
-
let
|
|
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:
|
|
39
|
+
index: h,
|
|
15
40
|
currentIndex: null,
|
|
16
41
|
scanning: !1,
|
|
17
|
-
truncated: !1
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
42
|
+
truncated: !1,
|
|
43
|
+
focusRequest: 0
|
|
44
|
+
}), T = (e) => {
|
|
45
|
+
w.setSnapshot({
|
|
46
|
+
...w.getSnapshot(),
|
|
21
47
|
...e
|
|
22
48
|
});
|
|
23
|
-
},
|
|
24
|
-
let e =
|
|
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
|
-
|
|
32
|
-
},
|
|
33
|
-
let t =
|
|
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 &&
|
|
37
|
-
},
|
|
38
|
-
|
|
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:
|
|
66
|
+
index: h,
|
|
41
67
|
currentIndex: null,
|
|
42
68
|
scanning: !1,
|
|
43
69
|
truncated: !1
|
|
44
70
|
});
|
|
45
|
-
},
|
|
46
|
-
let d =
|
|
47
|
-
if (!d || !
|
|
48
|
-
|
|
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
|
-
|
|
52
|
-
let E =
|
|
53
|
-
|
|
54
|
-
rowModel:
|
|
55
|
-
columns:
|
|
56
|
-
query:
|
|
57
|
-
caseSensitive:
|
|
58
|
-
conditionalFormatShown:
|
|
59
|
-
separator:
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
|
69
|
-
|
|
70
|
-
let
|
|
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
|
|
73
|
-
if (e(o.key) || !a(o,
|
|
74
|
-
let l = s(o, t, !
|
|
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:
|
|
77
|
-
rowKey:
|
|
103
|
+
sourceRowIndex: j.getSourceIndex(n) ?? n,
|
|
104
|
+
rowKey: j.getRowKey(n) ?? n,
|
|
78
105
|
colIndex: c
|
|
79
|
-
},
|
|
80
|
-
for (let e of i(o, t, l,
|
|
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 ?
|
|
113
|
+
}), r.length === 0 ? g : r;
|
|
87
114
|
};
|
|
88
|
-
!
|
|
89
|
-
if (
|
|
90
|
-
let t =
|
|
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 =
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
|
|
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: () =>
|
|
108
|
-
if (!e ||
|
|
109
|
-
|
|
110
|
-
b
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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:
|
|
116
|
-
}),
|
|
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
|
-
},
|
|
119
|
-
let e =
|
|
120
|
-
return !
|
|
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 =
|
|
125
|
-
if (
|
|
126
|
-
|
|
157
|
+
let t = u;
|
|
158
|
+
if (u = e, !e.enabled) {
|
|
159
|
+
w.getSnapshot().open && (T({
|
|
127
160
|
open: !1,
|
|
128
161
|
query: ""
|
|
129
|
-
}),
|
|
162
|
+
}), k(), D());
|
|
130
163
|
return;
|
|
131
164
|
}
|
|
132
|
-
if (t !== e &&
|
|
133
|
-
|
|
165
|
+
if (t !== e && j()) {
|
|
166
|
+
A(!1);
|
|
134
167
|
return;
|
|
135
168
|
}
|
|
136
|
-
let n =
|
|
137
|
-
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 (!
|
|
141
|
-
let t =
|
|
142
|
-
|
|
173
|
+
if (!u?.enabled) return;
|
|
174
|
+
let t = w.getSnapshot(), n = e ?? t.query;
|
|
175
|
+
T({
|
|
143
176
|
open: !0,
|
|
144
|
-
query: n
|
|
145
|
-
|
|
177
|
+
query: n,
|
|
178
|
+
focusRequest: t.focusRequest + 1
|
|
179
|
+
}), n !== t.query || !t.open ? A(!0) : D();
|
|
146
180
|
},
|
|
147
181
|
close: () => {
|
|
148
|
-
|
|
182
|
+
w.getSnapshot().open && (T({
|
|
149
183
|
open: !1,
|
|
150
184
|
query: ""
|
|
151
|
-
}),
|
|
185
|
+
}), k(), D());
|
|
152
186
|
},
|
|
153
187
|
setQuery: (e) => {
|
|
154
|
-
let t =
|
|
155
|
-
!t.open || e === t.query || (
|
|
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 =
|
|
159
|
-
|
|
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 =
|
|
163
|
-
|
|
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:
|
|
166
|
-
getSnapshot:
|
|
221
|
+
subscribe: w.subscribe,
|
|
222
|
+
getSnapshot: w.getSnapshot,
|
|
167
223
|
dispose: () => {
|
|
168
|
-
|
|
224
|
+
p += 1, u = null;
|
|
169
225
|
}
|
|
170
226
|
};
|
|
171
227
|
};
|
|
172
228
|
//#endregion
|
|
173
|
-
export {
|
|
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>;
|