@ishibashi0112/spreadsheet-grid-core 1.2.0 → 1.2.1
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/clipboardController.cjs +1 -1
- package/dist/controllers/clipboardController.d.ts +1 -0
- package/dist/controllers/clipboardController.js +35 -34
- package/dist/controllers/detailRowController.cjs +1 -0
- package/dist/controllers/detailRowController.d.ts +41 -0
- package/dist/controllers/detailRowController.js +96 -0
- package/dist/controllers/keyboardController.cjs +1 -1
- package/dist/controllers/keyboardController.d.ts +1 -0
- package/dist/controllers/keyboardController.js +98 -96
- package/dist/controllers/liveUiState.cjs +1 -0
- package/dist/controllers/liveUiState.d.ts +7 -0
- package/dist/controllers/liveUiState.js +4 -0
- package/dist/controllers/pointerInteractionsController.cjs +1 -1
- package/dist/controllers/pointerInteractionsController.d.ts +1 -0
- package/dist/controllers/pointerInteractionsController.js +127 -126
- package/dist/engine/cellCommands.cjs +1 -0
- package/dist/engine/cellCommands.d.ts +27 -0
- package/dist/engine/cellCommands.js +89 -0
- package/dist/engine/gridApi.cjs +3 -3
- package/dist/engine/gridApi.d.ts +2 -0
- package/dist/engine/gridApi.js +72 -66
- package/dist/logic/cellPlacement.cjs +1 -0
- package/dist/logic/cellPlacement.d.ts +22 -0
- package/dist/logic/cellPlacement.js +44 -0
- package/dist/logic/density.cjs +1 -0
- package/dist/logic/density.d.ts +5 -0
- package/dist/logic/density.js +17 -0
- package/dist/logic/detailRow.cjs +1 -1
- package/dist/logic/detailRow.d.ts +4 -0
- package/dist/logic/detailRow.js +10 -7
- package/dist/logic/domGuards.cjs +1 -1
- package/dist/logic/domGuards.d.ts +5 -0
- package/dist/logic/domGuards.js +8 -2
- package/dist/logic/editorKeys.cjs +1 -0
- package/dist/logic/editorKeys.d.ts +30 -0
- package/dist/logic/editorKeys.js +34 -0
- package/dist/logic/editorStart.cjs +1 -0
- package/dist/logic/editorStart.d.ts +7 -0
- package/dist/logic/editorStart.js +23 -0
- package/dist/logic/gridBarSummary.cjs +1 -0
- package/dist/logic/gridBarSummary.d.ts +27 -0
- package/dist/logic/gridBarSummary.js +137 -0
- package/dist/logic/selectEditorState.cjs +1 -1
- package/dist/logic/selectEditorState.d.ts +24 -1
- package/dist/logic/selectEditorState.js +29 -14
- package/dist/utils/editorVisibleBounds.cjs +1 -0
- package/dist/utils/editorVisibleBounds.d.ts +10 -0
- package/dist/utils/editorVisibleBounds.js +40 -0
- package/dist/utils/errorBubblePlacement.cjs +1 -0
- package/dist/utils/errorBubblePlacement.d.ts +8 -0
- package/dist/utils/errorBubblePlacement.js +26 -0
- package/dist/utils/multilineEditor.cjs +2 -0
- package/dist/utils/multilineEditor.d.ts +7 -0
- package/dist/utils/multilineEditor.js +22 -0
- package/package.json +1 -1
|
@@ -3,218 +3,220 @@ import { isViewCellEditable as t } from "../utils/permissions.js";
|
|
|
3
3
|
import { resolveFirstDataColIndex as n } from "../logic/detailRow.js";
|
|
4
4
|
import { clamp as r } from "../logic/geometry.js";
|
|
5
5
|
import { isImeInputTarget as i, isPrintableKey as a, shouldIgnoreGridKeydown as o } from "../logic/domGuards.js";
|
|
6
|
-
import {
|
|
6
|
+
import { isEditingAtEvent as s, readLiveUiState as c } from "./liveUiState.js";
|
|
7
|
+
import { computeIsWholeGridSelected as l } from "./clipboardController.js";
|
|
8
|
+
import { isClearableSelection as u } from "./escapeClaimController.js";
|
|
7
9
|
//#region src/controllers/keyboardController.ts
|
|
8
|
-
var
|
|
10
|
+
var d = 10, f = (e, t, n, r) => {
|
|
9
11
|
if (!e.getLabelRow) return t;
|
|
10
12
|
let i = e.getRowCount(), a = t;
|
|
11
13
|
for (; a >= 0 && a < i && e.getLabelRow(a);) a += n;
|
|
12
14
|
return a >= 0 && a < i ? a : r;
|
|
13
|
-
},
|
|
14
|
-
row:
|
|
15
|
-
col:
|
|
16
|
-
}),
|
|
17
|
-
let n = null,
|
|
15
|
+
}, p = (e) => f(e, 0, 1, 0), m = (e) => n(e), h = (e, t) => ({
|
|
16
|
+
row: p(e),
|
|
17
|
+
col: m(t)
|
|
18
|
+
}), g = () => {
|
|
19
|
+
let n = null, g = (e) => {
|
|
18
20
|
n = e;
|
|
19
|
-
},
|
|
21
|
+
}, _ = (e, t) => f(e, t, -1, f(e, t, 1, t)), v = (e) => {
|
|
20
22
|
let t = e.getRowCount() - 1;
|
|
21
|
-
return
|
|
22
|
-
},
|
|
23
|
+
return f(e, t, -1, t);
|
|
24
|
+
}, y = (t, r, i) => {
|
|
23
25
|
if (n === null) return;
|
|
24
|
-
let {
|
|
26
|
+
let { dispatch: a } = n, o = c(n);
|
|
25
27
|
if (i) {
|
|
26
|
-
let n =
|
|
27
|
-
|
|
28
|
+
let n = o.selection?.type === "cell" ? o.selection.range.start : t;
|
|
29
|
+
a(e.startSelection(n)), a(e.updateSelection(r)), a(e.endSelection()), a(e.activateCell(r));
|
|
28
30
|
return;
|
|
29
31
|
}
|
|
30
|
-
|
|
31
|
-
},
|
|
32
|
-
if (n === null || n.
|
|
32
|
+
a(e.startSelection(r)), a(e.endSelection()), a(e.activateCell(r));
|
|
33
|
+
}, b = () => {
|
|
34
|
+
if (n === null || c(n).activeCell) return !1;
|
|
33
35
|
let { rowModel: e, visibleColumns: t } = n;
|
|
34
36
|
if (e.getRowCount() === 0 || t.length === 0) return !0;
|
|
35
|
-
let r =
|
|
36
|
-
return
|
|
37
|
-
},
|
|
38
|
-
let t = n
|
|
37
|
+
let r = h(e, t);
|
|
38
|
+
return y(r, r, !1), !0;
|
|
39
|
+
}, x = (e) => {
|
|
40
|
+
let t = n === null ? void 0 : c(n);
|
|
39
41
|
return e && t?.selection?.type === "cell" ? t.selection.range.end : t?.activeCell ?? {
|
|
40
42
|
row: 0,
|
|
41
43
|
col: 0
|
|
42
44
|
};
|
|
43
|
-
},
|
|
45
|
+
}, S = (e, t, i) => {
|
|
44
46
|
if (n === null) return;
|
|
45
47
|
let { rowModel: a, visibleColumns: o } = n, s = a.getRowCount();
|
|
46
|
-
if (s === 0 || o.length === 0 ||
|
|
47
|
-
let c =
|
|
48
|
-
|
|
49
|
-
let
|
|
50
|
-
row:
|
|
48
|
+
if (s === 0 || o.length === 0 || b()) return;
|
|
49
|
+
let c = x(i), l = r(c.row + e, 0, s - 1);
|
|
50
|
+
l = e === 0 ? _(a, l) : f(a, l, e > 0 ? 1 : -1, c.row);
|
|
51
|
+
let u = {
|
|
52
|
+
row: l,
|
|
51
53
|
col: r(c.col + t, 0, o.length - 1)
|
|
52
54
|
};
|
|
53
|
-
|
|
54
|
-
},
|
|
55
|
+
y(c, u, i);
|
|
56
|
+
}, C = (e, t) => {
|
|
55
57
|
if (n === null) return;
|
|
56
|
-
let {
|
|
57
|
-
if (
|
|
58
|
-
let s =
|
|
59
|
-
row:
|
|
60
|
-
col:
|
|
61
|
-
},
|
|
62
|
-
|
|
63
|
-
row:
|
|
64
|
-
col: r(
|
|
65
|
-
}, t &&
|
|
66
|
-
},
|
|
67
|
-
let a = t.getRowCount(), o = n?.resolvePageRow ? n.resolvePageRow(e.row, i) : e.row + i *
|
|
68
|
-
return
|
|
58
|
+
let { rowModel: i, visibleColumns: a } = n, o = c(n);
|
|
59
|
+
if (i.getRowCount() === 0 || a.length === 0) return;
|
|
60
|
+
let s = o.activeCell ? x(t) : {
|
|
61
|
+
row: p(i),
|
|
62
|
+
col: m(a)
|
|
63
|
+
}, l = e(s, i, a);
|
|
64
|
+
y(s, {
|
|
65
|
+
row: _(i, r(l.row, 0, i.getRowCount() - 1)),
|
|
66
|
+
col: r(l.col, 0, a.length - 1)
|
|
67
|
+
}, t && o.activeCell !== null);
|
|
68
|
+
}, w = (e, t, i) => {
|
|
69
|
+
let a = t.getRowCount(), o = n?.resolvePageRow ? n.resolvePageRow(e.row, i) : e.row + i * d, s = r(i > 0 ? Math.max(o, e.row + 1) : Math.min(o, e.row - 1), 0, a - 1), c = f(t, s, i, -1);
|
|
70
|
+
return c >= 0 ? c : f(t, s, i > 0 ? -1 : 1, e.row);
|
|
69
71
|
};
|
|
70
72
|
return {
|
|
71
|
-
update:
|
|
73
|
+
update: g,
|
|
72
74
|
handleKeyDown: async (r) => {
|
|
73
75
|
if (n === null) return;
|
|
74
|
-
let {
|
|
75
|
-
if (o(r.target) ||
|
|
76
|
+
let { rowModel: d, visibleColumns: f, readOnly: h, canEditCell: g, setEditorInitialValue: _, dispatch: y, handleCopy: x, openFind: T, handleCellDoubleClick: E, selectEntireGrid: D, onUndo: O, onRedo: k, onClearSelection: A, enableClearOnDelete: j, onToggleCheckboxCell: M, onToggleGroup: N, onToggleDetailRow: P } = n, F = c(n), I = n.getUiState ? l(F.selection, d.getRowCount(), f.length) : n.isWholeGridSelected;
|
|
77
|
+
if (o(r.target) || s(n) || r.isComposing && i(r.target)) return;
|
|
76
78
|
if ((r.ctrlKey || r.metaKey) && r.key.toLowerCase() === "c") {
|
|
77
|
-
r.preventDefault(), await
|
|
79
|
+
r.preventDefault(), await x();
|
|
78
80
|
return;
|
|
79
81
|
}
|
|
80
|
-
if ((r.ctrlKey || r.metaKey) && r.key.toLowerCase() === "f" &&
|
|
81
|
-
r.preventDefault(),
|
|
82
|
+
if ((r.ctrlKey || r.metaKey) && r.key.toLowerCase() === "f" && T) {
|
|
83
|
+
r.preventDefault(), T();
|
|
82
84
|
return;
|
|
83
85
|
}
|
|
84
86
|
if ((r.ctrlKey || r.metaKey) && r.key.toLowerCase() === "a") {
|
|
85
|
-
if (r.preventDefault(),
|
|
86
|
-
|
|
87
|
+
if (r.preventDefault(), I) {
|
|
88
|
+
y(e.clearSelection()), y(e.activateCell(null));
|
|
87
89
|
return;
|
|
88
90
|
}
|
|
89
|
-
|
|
91
|
+
D();
|
|
90
92
|
return;
|
|
91
93
|
}
|
|
92
94
|
if ((r.ctrlKey || r.metaKey) && !r.isComposing) {
|
|
93
95
|
if (r.key.toLowerCase() === "z") {
|
|
94
|
-
r.preventDefault(), r.shiftKey ?
|
|
96
|
+
r.preventDefault(), r.shiftKey ? k() : O();
|
|
95
97
|
return;
|
|
96
98
|
}
|
|
97
99
|
if (r.key.toLowerCase() === "y" && !r.shiftKey) {
|
|
98
|
-
r.preventDefault(),
|
|
100
|
+
r.preventDefault(), k();
|
|
99
101
|
return;
|
|
100
102
|
}
|
|
101
103
|
}
|
|
102
|
-
let
|
|
103
|
-
if ((r.key === "ContextMenu" || r.key === "F10" && r.shiftKey) && !
|
|
104
|
+
let L = r.ctrlKey || r.metaKey;
|
|
105
|
+
if ((r.key === "ContextMenu" || r.key === "F10" && r.shiftKey) && !L && !r.altKey && F.activeCell && n.openContextMenu?.(F.activeCell)) {
|
|
104
106
|
r.preventDefault();
|
|
105
107
|
return;
|
|
106
108
|
}
|
|
107
|
-
if (r.key === "ArrowDown" && r.altKey && !
|
|
109
|
+
if (r.key === "ArrowDown" && r.altKey && !L && !r.shiftKey && F.activeCell && n.openColumnMenu?.(F.activeCell.col)) {
|
|
108
110
|
r.preventDefault();
|
|
109
111
|
return;
|
|
110
112
|
}
|
|
111
|
-
if (
|
|
113
|
+
if (L && !r.altKey && (r.key === "ArrowUp" || r.key === "ArrowDown")) {
|
|
112
114
|
r.preventDefault();
|
|
113
115
|
let e = r.key === "ArrowDown";
|
|
114
|
-
|
|
115
|
-
row: e ?
|
|
116
|
+
C((t, n) => ({
|
|
117
|
+
row: e ? v(n) : p(n),
|
|
116
118
|
col: t.col
|
|
117
119
|
}), r.shiftKey);
|
|
118
120
|
return;
|
|
119
121
|
}
|
|
120
|
-
if (
|
|
122
|
+
if (L && !r.altKey && (r.key === "ArrowLeft" || r.key === "ArrowRight")) {
|
|
121
123
|
r.preventDefault();
|
|
122
124
|
let e = r.key === "ArrowRight";
|
|
123
|
-
|
|
125
|
+
C((t, n, r) => ({
|
|
124
126
|
row: t.row,
|
|
125
|
-
col: e ? r.length - 1 :
|
|
127
|
+
col: e ? r.length - 1 : m(r)
|
|
126
128
|
}), r.shiftKey);
|
|
127
129
|
return;
|
|
128
130
|
}
|
|
129
131
|
if ((r.key === "Home" || r.key === "End") && !r.altKey) {
|
|
130
132
|
r.preventDefault();
|
|
131
133
|
let e = r.key === "End";
|
|
132
|
-
|
|
133
|
-
row:
|
|
134
|
-
col: e ? r.length - 1 :
|
|
134
|
+
C((t, n, r) => ({
|
|
135
|
+
row: L ? e ? v(n) : p(n) : t.row,
|
|
136
|
+
col: e ? r.length - 1 : m(r)
|
|
135
137
|
}), r.shiftKey);
|
|
136
138
|
return;
|
|
137
139
|
}
|
|
138
|
-
if ((r.key === "PageDown" || r.key === "PageUp") && !
|
|
139
|
-
if (r.preventDefault(),
|
|
140
|
+
if ((r.key === "PageDown" || r.key === "PageUp") && !L && !r.altKey) {
|
|
141
|
+
if (r.preventDefault(), b()) return;
|
|
140
142
|
let e = r.key === "PageDown" ? 1 : -1;
|
|
141
|
-
|
|
142
|
-
row:
|
|
143
|
+
C((t, n) => ({
|
|
144
|
+
row: w(t, n, e),
|
|
143
145
|
col: t.col
|
|
144
146
|
}), r.shiftKey);
|
|
145
147
|
return;
|
|
146
148
|
}
|
|
147
149
|
if (r.key === "ArrowUp") {
|
|
148
|
-
r.preventDefault(),
|
|
150
|
+
r.preventDefault(), S(-1, 0, r.shiftKey);
|
|
149
151
|
return;
|
|
150
152
|
}
|
|
151
153
|
if (r.key === "ArrowDown") {
|
|
152
|
-
r.preventDefault(),
|
|
154
|
+
r.preventDefault(), S(1, 0, r.shiftKey);
|
|
153
155
|
return;
|
|
154
156
|
}
|
|
155
157
|
if (r.key === "ArrowLeft") {
|
|
156
|
-
r.preventDefault(),
|
|
158
|
+
r.preventDefault(), S(0, -1, r.shiftKey);
|
|
157
159
|
return;
|
|
158
160
|
}
|
|
159
161
|
if (r.key === "ArrowRight") {
|
|
160
|
-
r.preventDefault(),
|
|
162
|
+
r.preventDefault(), S(0, 1, r.shiftKey);
|
|
161
163
|
return;
|
|
162
164
|
}
|
|
163
165
|
if (r.key === "Tab") {
|
|
164
|
-
if (!
|
|
166
|
+
if (!F.activeCell && !r.shiftKey) {
|
|
165
167
|
if (n.rowModel.getRowCount() === 0 || n.visibleColumns.length === 0) return;
|
|
166
|
-
r.preventDefault(),
|
|
168
|
+
r.preventDefault(), b();
|
|
167
169
|
return;
|
|
168
170
|
}
|
|
169
|
-
let e =
|
|
170
|
-
if (r.shiftKey ? e <=
|
|
171
|
-
!r.shiftKey &&
|
|
171
|
+
let e = F.activeCell?.col ?? 0;
|
|
172
|
+
if (r.shiftKey ? e <= m(n.visibleColumns) : e >= n.visibleColumns.length - 1) {
|
|
173
|
+
!r.shiftKey && F.activeCell && n.onTabPastLastColumn?.(F.activeCell.row) && r.preventDefault();
|
|
172
174
|
return;
|
|
173
175
|
}
|
|
174
|
-
r.preventDefault(),
|
|
176
|
+
r.preventDefault(), S(0, r.shiftKey ? -1 : 1, !1);
|
|
175
177
|
return;
|
|
176
178
|
}
|
|
177
179
|
if (r.key === "Escape") {
|
|
178
|
-
|
|
180
|
+
u(F.selection) && r.preventDefault(), y(e.clearSelection());
|
|
179
181
|
return;
|
|
180
182
|
}
|
|
181
|
-
if ((r.key === "Delete" || r.key === "Backspace") &&
|
|
182
|
-
r.preventDefault(),
|
|
183
|
+
if ((r.key === "Delete" || r.key === "Backspace") && j) {
|
|
184
|
+
r.preventDefault(), A();
|
|
183
185
|
return;
|
|
184
186
|
}
|
|
185
|
-
if ((r.key === "Enter" || r.key === " ") &&
|
|
186
|
-
let e =
|
|
187
|
+
if ((r.key === "Enter" || r.key === " ") && F.activeCell) {
|
|
188
|
+
let e = d.getGroupRow?.(F.activeCell.row);
|
|
187
189
|
if (e) {
|
|
188
|
-
r.preventDefault(),
|
|
190
|
+
r.preventDefault(), N(e.groupKey);
|
|
189
191
|
return;
|
|
190
192
|
}
|
|
191
|
-
if (
|
|
193
|
+
if (P && f[F.activeCell.col]?.key === "__ssg_detail_toggle__" && P(F.activeCell)) {
|
|
192
194
|
r.preventDefault();
|
|
193
195
|
return;
|
|
194
196
|
}
|
|
195
197
|
}
|
|
196
198
|
if (r.key === "Enter" || r.key === "F2") {
|
|
197
|
-
if (r.preventDefault(),
|
|
198
|
-
|
|
199
|
+
if (r.preventDefault(), F.activeCell) {
|
|
200
|
+
E(F.activeCell);
|
|
199
201
|
return;
|
|
200
202
|
}
|
|
201
|
-
r.key === "Enter" &&
|
|
203
|
+
r.key === "Enter" && b();
|
|
202
204
|
return;
|
|
203
205
|
}
|
|
204
|
-
if (r.key === " " && !r.ctrlKey && !r.metaKey && !r.altKey && r.preventDefault(), a(r) &&
|
|
205
|
-
let n =
|
|
206
|
+
if (r.key === " " && !r.ctrlKey && !r.metaKey && !r.altKey && r.preventDefault(), a(r) && F.activeCell) {
|
|
207
|
+
let n = d.getRow(F.activeCell.row), i = f[F.activeCell.col];
|
|
206
208
|
if (!n || !i || !t({
|
|
207
|
-
readOnly:
|
|
208
|
-
canEditCell:
|
|
209
|
-
},
|
|
209
|
+
readOnly: h,
|
|
210
|
+
canEditCell: g
|
|
211
|
+
}, d, F.activeCell.row, F.activeCell.col, n, i)) return;
|
|
210
212
|
if (i.editor?.type === "checkbox") {
|
|
211
|
-
r.preventDefault(), r.key === " " &&
|
|
213
|
+
r.preventDefault(), r.key === " " && M(F.activeCell);
|
|
212
214
|
return;
|
|
213
215
|
}
|
|
214
|
-
r.preventDefault(),
|
|
216
|
+
r.preventDefault(), _(r.key), y(e.startEdit(F.activeCell));
|
|
215
217
|
}
|
|
216
218
|
}
|
|
217
219
|
};
|
|
218
220
|
};
|
|
219
221
|
//#endregion
|
|
220
|
-
export {
|
|
222
|
+
export { g as createKeyboardController, h as resolveFirstDataCell };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=e=>e.getUiState?.()??e.uiState,t=t=>t.uiState.editingCell!==null||e(t).editingCell!==null;exports.isEditingAtEvent=t,exports.readLiveUiState=e;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { GridUiState } from '../model/gridTypes.unbound.js';
|
|
2
|
+
export type LiveUiStateArgs = {
|
|
3
|
+
uiState: GridUiState;
|
|
4
|
+
getUiState?: (() => GridUiState) | undefined;
|
|
5
|
+
};
|
|
6
|
+
export declare const readLiveUiState: (args: LiveUiStateArgs) => GridUiState;
|
|
7
|
+
export declare const isEditingAtEvent: (args: LiveUiStateArgs) => boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../model/gridActions.cjs"),t=require("../logic/sorting.cjs"),n=require("../logic/detailRow.cjs"),r=require("../logic/geometry.cjs"),i=require("../logic/autoScrollGeometry.cjs"),
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../model/gridActions.cjs"),t=require("../logic/sorting.cjs"),n=require("../logic/detailRow.cjs"),r=require("../logic/geometry.cjs"),i=require("./liveUiState.cjs"),a=require("../logic/autoScrollGeometry.cjs"),o=require("../logic/elementScale.cjs"),s=require("../logic/verticalGeometry.cjs");var c=10,l=300,u=()=>{let c=null,l=!1,u=!1,d=null,f=null,p=`mouse`,m=null,h=null,g=!1,_=!1,v=()=>c===null?null:i.readLiveUiState(c).dragState??null,y=null,b=e=>{let t=c?.footerHeight??0,n=c?.stickyTopHeight??0,r=c?.scrollContainerRef.current??null;if(t<=0&&n<=0||!r)return e;let i=r.getBoundingClientRect(),s=o.resolveElementScale(r,i);return a.clampClientYBelowHeader(a.clampClientYAboveFooter(e,i.top+(r.clientTop+r.clientHeight)*s.y,t*s.y),i.top+r.clientTop*s.y,n*s.y)},x=(e,t)=>{if(c===null)return null;let{bodyScrollRef:n,scrollContainerRef:i,leftPaneScrollRef:a,rightPaneScrollRef:l,filteredRowsLength:u,visibleColumnsLength:d,paneLayout:f,leftLeadingWidth:p,centerLeadingWidth:m,rightLeadingWidth:h,headerHeight:g,rowMetrics:_,verticalScaleFactor:v}=c,y=n.current;if(!y||u===0||d===0)return null;let x=y.getBoundingClientRect(),S=o.resolveElementScale(y,x),C=s.clientYToRowIndex(y.scrollTop+(b(t)-x.top)/S.y-g,i.current?.scrollTop??0,v,_),w=null,T=a.current;if(w===null&&T&&f.left.entries.length>0){let t=T.getBoundingClientRect();if(e<t.right){let n=(e-t.left)/S.x-p;w=r.findLogicalIndexFromPaneOffset(f.left,n)}}let E=l.current;if(w===null&&E&&f.right.entries.length>0){let t=E.getBoundingClientRect();if(e>=t.left){let n=(e-t.left)/S.x-h;w=r.findLogicalIndexFromPaneOffset(f.right,n)}}if(w===null&&f.center.entries.length>0){let t=T&&f.left.entries.length===0?Math.max(e,T.getBoundingClientRect().left+p*S.x):e,n=y.scrollLeft+(t-x.left)/S.x-m;w=r.findLogicalIndexFromPaneOffset(f.center,Math.max(n,0))}return w===null?null:{row:C,col:r.clamp(w,0,d-1)}},S=(t,n)=>{let r=v();if(c===null||!r||r.type!==`selection`)return;let i=x(t,n);if(i){if(r.selectionKind===`cell`){c.dispatch(e.gridActions.updateSelection(i));return}if(r.selectionKind===`row`){c.dispatch(e.gridActions.updateRowSelection(i.row));return}r.selectionKind===`col`&&c.dispatch(e.gridActions.updateColumnSelection(i.col))}},C=(t,n)=>{let r=n.timeStamp;if(c===null)return;let{gridRootRef:i,dispatch:a,enableRangeSelection:o,enableRowSelection:s,onGutterRowSelect:l,onCellDoubleClickRef:u,resolveFirstDataCell:d}=c;i.current?.focus({preventScroll:!0});let{target:p}=t;if(p.kind===`cell`){let t=f;if(t&&t.cell.row===p.cell.row&&t.cell.col===p.cell.col&&r-t.time<300){f=null,u.current(p.cell,n);return}f={cell:p.cell,time:r},a(e.gridActions.activateCell(p.cell)),o&&(a(e.gridActions.startSelection(p.cell)),a(e.gridActions.endSelection()));return}if(f=null,p.kind===`row`){if(s){l(p.rowIndex,{shiftKey:!1});return}a(e.gridActions.startRowSelection(p.rowIndex,d?.().col)),a(e.gridActions.endSelection());return}a(e.gridActions.startColumnSelection(p.colIndex,d?.().row)),a(e.gridActions.endSelection())},w=()=>{c!==null&&(u=!1,c.dispatch(e.gridActions.endSelection()),c.dispatch(e.gridActions.endColumnResize()))},T=t=>{if(c===null)return;c.pointerClientRef.current={x:t.clientX,y:t.clientY};let n=v();if(n?.type===`columnResize`){(y===null||y.drag!==n)&&(y={drag:n,x:o.resolveElementScale(c.scrollContainerRef.current).x});let r=y.x===1?t.clientX:n.startX+(t.clientX-n.startX)/y.x;c.dispatch(e.gridActions.updateColumnResize(r))}},E=e=>{let t=d;t&&(d=null,e.pointerId===t.pointerId&&Math.abs(e.clientX-t.x)<10&&Math.abs(e.clientY-t.y)<10&&C(t,e)),w()},D=()=>{d=null,w()},O=()=>{l||(l=!0,window.addEventListener(`pointermove`,T),window.addEventListener(`pointerup`,E),window.addEventListener(`pointercancel`,D))},k=()=>{l&&(l=!1,window.removeEventListener(`pointermove`,T),window.removeEventListener(`pointerup`,E),window.removeEventListener(`pointercancel`,D))},A=()=>{_=!1,c!==null&&c.autoScrollFrameRef.current!==null&&(cancelAnimationFrame(c.autoScrollFrameRef.current),c.autoScrollFrameRef.current=null)},j=()=>{if(c===null||!_)return;let{scrollContainerRef:e,pointerClientRef:t,autoScrollFrameRef:n}=c,r=e.current,i=t.current;if(!r||!i){n.current=requestAnimationFrame(j);return}if(!g){let e=h;if(e&&!a.hasPointerLeftActivationRadius(e,i,6)){n.current=requestAnimationFrame(j);return}g=!0}let s=r.getBoundingClientRect(),l=o.resolveElementScale(r,s),u=a.resolveScrollContentBox({rectLeft:s.left,rectTop:s.top,clientLeft:r.clientLeft,clientTop:r.clientTop,clientWidth:r.clientWidth,clientHeight:r.clientHeight,scale:l}),d=v(),f=d?.type===`selection`&&d.selectionKind===`col`,p=d?.type===`selection`&&d.selectionKind===`row`,m=f?0:a.resolveAutoScrollAxisDirection(i.y,a.resolveTopAutoScrollStart(u.top,(c.stickyTopHeight??0)*l.y,24),u.bottom-(c.footerHeight??0),24),y=p?0:a.resolveAutoScrollAxisDirection(i.x,u.left,u.right,24),b=a.computeNextScrollPosition(r.scrollTop,m,18,r.scrollHeight-r.clientHeight),x=a.computeNextScrollPosition(r.scrollLeft,y,18,r.scrollWidth-r.clientWidth);(b!==r.scrollTop||x!==r.scrollLeft)&&(r.scrollTo({top:b,left:x,behavior:`auto`}),S(i.x,i.y)),n.current=requestAnimationFrame(j)},M=()=>{let e=v()?.type===`selection`;e&&!_?(_=!0,c!==null&&(c.autoScrollFrameRef.current=requestAnimationFrame(j))):!e&&_&&A()},N=()=>{if(m!==null)return;let e=()=>{if(!u||c===null){m=null;return}let{scrollContainerRef:t,pointerClientRef:n,onGutterRowSelectDrag:r}=c,i=t.current,s=n.current;if(!i||!s){m=requestAnimationFrame(e);return}if(!g){let t=h;if(t&&!a.hasPointerLeftActivationRadius(t,s,6)){m=requestAnimationFrame(e);return}g=!0}let l=i.getBoundingClientRect(),d=o.resolveElementScale(i,l),f=a.resolveScrollContentBox({rectLeft:l.left,rectTop:l.top,clientLeft:i.clientLeft,clientTop:i.clientTop,clientWidth:i.clientWidth,clientHeight:i.clientHeight,scale:d}),p=a.resolveAutoScrollAxisDirection(s.y,a.resolveTopAutoScrollStart(f.top,(c.stickyTopHeight??0)*d.y,24),f.bottom-(c.footerHeight??0),24),_=a.computeNextScrollPosition(i.scrollTop,p,18,i.scrollHeight-i.clientHeight);if(_!==i.scrollTop){i.scrollTo({top:_,left:i.scrollLeft,behavior:`auto`});let e=x(s.x,s.y);e&&r(e.row)}m=requestAnimationFrame(e)};m=requestAnimationFrame(e)},P=(e,t)=>(e.preventDefault(),c===null||e.button!==0?!1:(p=e.pointerType,e.pointerType===`touch`?(d={pointerId:e.pointerId,x:e.clientX,y:e.clientY,target:t},!1):(c.gridRootRef.current?.focus({preventScroll:!0}),c.pointerClientRef.current={x:e.clientX,y:e.clientY},h={x:e.clientX,y:e.clientY},g=!1,!0)));return{update:e=>{c=e,O(),M()},getCellCoordFromClientPoint:x,updateSelectionFromPointer:S,handleCellPointerDown:(t,n)=>{if(!(!P(n,{kind:`cell`,cell:t})||c===null)){if(n.shiftKey&&c.enableRangeSelection){let{selection:n,activeCell:r}=i.readLiveUiState(c),a=n?.type===`cell`?n.range.start:r;if(a){c.dispatch(e.gridActions.startSelection(a)),c.dispatch(e.gridActions.updateSelection(t));return}}c.dispatch(e.gridActions.activateCell(t)),c.enableRangeSelection&&c.dispatch(e.gridActions.startSelection(t))}},handleCellDoubleClick:(e,t)=>{p===`touch`||c===null||c.onCellDoubleClickRef.current(e,t)},handleCellPointerEnter:(t,n)=>{if(c===null||(c.enableRowHover&&c.setHoveredRowIndex(t.row),c.enableColumnHover&&c.setHoveredColumnIndex(t.col),!c.enableRangeSelection))return;let r=v();r?.type!==`selection`||r.selectionKind!==`cell`||(c.pointerClientRef.current={x:n.clientX,y:n.clientY},c.dispatch(e.gridActions.updateSelection(t)))},handleNativeDragStart:e=>{e.preventDefault()},handleRowHeaderPointerDown:(t,n)=>{if(!(!P(n,{kind:`row`,rowIndex:t})||c===null)){if(c.enableRowSelection){u=!0,c.onGutterRowSelect(t,{shiftKey:n.shiftKey}),N();return}if(n.shiftKey){let{selection:n,activeCell:r}=i.readLiveUiState(c),a=n?.type===`row`?n.startRow:r?.row;if(a!==void 0){c.dispatch(e.gridActions.startRowSelection(a,c.resolveFirstDataCell?.().col)),c.dispatch(e.gridActions.updateRowSelection(t));return}}c.dispatch(e.gridActions.startRowSelection(t,c.resolveFirstDataCell?.().col))}},handleRowHeaderPointerEnter:(t,n)=>{if(c===null)return;if(c.enableRowHover&&c.setHoveredRowIndex(t),u){c.pointerClientRef.current={x:n.clientX,y:n.clientY},c.onGutterRowSelectDrag(t);return}let r=v();r?.type!==`selection`||r.selectionKind!==`row`||(c.pointerClientRef.current={x:n.clientX,y:n.clientY},c.dispatch(e.gridActions.updateRowSelection(t)))},handleColumnHeaderPointerDown:(r,a)=>{if(!(!P(a,{kind:`col`,colIndex:r})||c===null)){if(a.shiftKey&&c.enableSorting){let a=c.orderedColumns[r];if(a&&!n.isSyntheticColumnKey(a.key)){let n=i.readLiveUiState(c).sort,r=n.find(e=>e.columnKey===a.key)?.direction?`desc`:`asc`,o=t.nextSortEntries(n,a.key,r,!0);c.dispatch(o.length===0?e.gridActions.clearSort():e.gridActions.setSort(o))}return}c.dispatch(e.gridActions.startColumnSelection(r,c.resolveFirstDataCell?.().row))}},handleColumnHeaderPointerEnter:(t,n)=>{if(c===null)return;c.setHoveredRowIndex(null),c.enableColumnHeaderHover&&c.setHoveredColumnIndex(t);let r=v();r?.type!==`selection`||r.selectionKind!==`col`||(c.pointerClientRef.current={x:n.clientX,y:n.clientY},c.dispatch(e.gridActions.updateColumnSelection(t)))},dispose:()=>{k(),A(),m!==null&&(cancelAnimationFrame(m),m=null)}}};exports.TOUCH_DOUBLE_TAP_MS=l,exports.TOUCH_TAP_SLOP_PX=c,exports.createPointerInteractionsController=u;
|
|
@@ -31,6 +31,7 @@ export type PointerInteractionsArgs<T> = {
|
|
|
31
31
|
} | null>;
|
|
32
32
|
autoScrollFrameRef: MutableRef<number | null>;
|
|
33
33
|
uiState: GridUiState;
|
|
34
|
+
getUiState?: (() => GridUiState) | undefined;
|
|
34
35
|
dispatch: (action: GridUiAction) => void;
|
|
35
36
|
enableRangeSelection: boolean;
|
|
36
37
|
enableSorting: boolean;
|