@ishibashi0112/spreadsheet-grid-core 1.2.0 → 1.3.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/clipboardController.cjs +1 -1
- package/dist/controllers/clipboardController.d.ts +1 -0
- package/dist/controllers/clipboardController.js +79 -70
- package/dist/controllers/columnMenuController.cjs +1 -1
- package/dist/controllers/columnMenuController.js +75 -73
- package/dist/controllers/contextMenuController.cjs +1 -1
- package/dist/controllers/contextMenuController.js +63 -61
- package/dist/controllers/detailRowController.cjs +1 -0
- package/dist/controllers/detailRowController.d.ts +41 -0
- package/dist/controllers/detailRowController.js +97 -0
- package/dist/controllers/detailTabOrder.cjs +1 -1
- package/dist/controllers/detailTabOrder.js +17 -16
- package/dist/controllers/editController.cjs +1 -1
- package/dist/controllers/editController.d.ts +4 -1
- package/dist/controllers/editController.js +163 -91
- package/dist/controllers/escapeClaimController.cjs +1 -1
- package/dist/controllers/escapeClaimController.js +23 -19
- package/dist/controllers/fillHandleController.cjs +1 -1
- package/dist/controllers/fillHandleController.js +107 -106
- package/dist/controllers/filterPopoverController.cjs +1 -1
- package/dist/controllers/filterPopoverController.js +1 -0
- package/dist/controllers/imeInputController.cjs +1 -1
- package/dist/controllers/imeInputController.js +87 -76
- package/dist/controllers/keyboardController.cjs +1 -1
- package/dist/controllers/keyboardController.d.ts +4 -0
- package/dist/controllers/keyboardController.js +101 -97
- 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/controllers/popoverSupport.cjs +1 -1
- package/dist/controllers/popoverSupport.d.ts +3 -0
- package/dist/controllers/popoverSupport.js +62 -41
- package/dist/controllers/toolPanelController.cjs +1 -1
- package/dist/controllers/toolPanelController.js +74 -73
- package/dist/controllers/tooltipController.cjs +1 -1
- package/dist/controllers/tooltipController.d.ts +1 -1
- package/dist/controllers/tooltipController.js +122 -97
- package/dist/controllers/viewportSyncController.cjs +1 -1
- package/dist/controllers/viewportSyncController.js +55 -54
- 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/columnCommands.cjs +1 -1
- package/dist/engine/columnCommands.d.ts +2 -1
- package/dist/engine/columnCommands.js +98 -67
- package/dist/engine/exportCommands.cjs +1 -1
- package/dist/engine/exportCommands.js +2 -2
- package/dist/engine/gridApi.cjs +6 -5
- package/dist/engine/gridApi.d.ts +3 -0
- package/dist/engine/gridApi.js +158 -144
- package/dist/engine/rowSelectionCommands.cjs +1 -1
- package/dist/engine/rowSelectionCommands.d.ts +5 -0
- package/dist/engine/rowSelectionCommands.js +73 -38
- package/dist/locales/en.cjs +1 -1
- package/dist/locales/en.js +2 -2
- 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/contextMenuTarget.cjs +1 -1
- package/dist/logic/contextMenuTarget.d.ts +20 -2
- package/dist/logic/contextMenuTarget.js +62 -3
- package/dist/logic/dateFilterCondition.cjs +1 -1
- package/dist/logic/dateFilterCondition.d.ts +1 -0
- package/dist/logic/dateFilterCondition.js +17 -13
- 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 +6 -1
- package/dist/logic/detailRow.js +21 -17
- package/dist/logic/domGuards.cjs +1 -1
- package/dist/logic/domGuards.d.ts +10 -0
- package/dist/logic/domGuards.js +18 -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/editorValues.cjs +1 -1
- package/dist/logic/editorValues.d.ts +1 -0
- package/dist/logic/editorValues.js +10 -7
- 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/gridState.cjs +1 -1
- package/dist/logic/gridState.d.ts +1 -0
- package/dist/logic/gridState.js +19 -16
- package/dist/logic/localeText.cjs +1 -1
- package/dist/logic/localeText.js +2 -2
- package/dist/logic/rowDragTarget.cjs +1 -0
- package/dist/logic/rowDragTarget.d.ts +14 -0
- package/dist/logic/rowDragTarget.js +47 -0
- package/dist/logic/selectEditorState.cjs +1 -1
- package/dist/logic/selectEditorState.d.ts +27 -4
- package/dist/logic/selectEditorState.js +29 -14
- package/dist/logic/valueFormatters.d.ts +8 -3
- package/dist/model/gridTypes.core.d.ts +31 -12
- package/dist/utils/clipboard.cjs +4 -4
- package/dist/utils/clipboard.js +60 -59
- 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/dist/utils/popupContainer.cjs +1 -1
- package/dist/utils/popupContainer.js +35 -28
- package/dist/utils/shadowDom.cjs +1 -0
- package/dist/utils/shadowDom.d.ts +5 -0
- package/dist/utils/shadowDom.js +33 -0
- package/package.json +1 -1
|
@@ -1,112 +1,123 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { getActiveElement as e, getEventTarget as t } from "../utils/shadowDom.js";
|
|
2
|
+
import { isInsideDetailCardOf as n } from "../logic/detailRow.js";
|
|
3
|
+
import { isImeComposingKeyEvent as r } from "../logic/domGuards.js";
|
|
4
|
+
import { resolveElementScale as i } from "../logic/elementScale.js";
|
|
5
|
+
import { resolveGridVisibleBand as a } from "../utils/gridVisibleBand.js";
|
|
6
|
+
import { alignInputTextToTop as o } from "../utils/topAlignedInput.js";
|
|
6
7
|
//#region src/controllers/imeInputController.ts
|
|
7
|
-
var
|
|
8
|
-
let i =
|
|
9
|
-
for (let
|
|
10
|
-
if (e
|
|
11
|
-
let i =
|
|
8
|
+
var s = 24, c = "ssg-ime-input--composing", l = (e, t, r) => {
|
|
9
|
+
let i = e.querySelectorAll(`.ssg-body-row[data-row-index="${t.row}"]`);
|
|
10
|
+
for (let t of Array.from(i)) {
|
|
11
|
+
if (n(e, t)) continue;
|
|
12
|
+
let i = t.querySelectorAll(".ssg-body-cell");
|
|
12
13
|
for (let e of Array.from(i)) if (e.getAttribute("data-ssg-col-key") === r) return e;
|
|
13
14
|
}
|
|
14
15
|
return null;
|
|
15
|
-
},
|
|
16
|
-
let
|
|
17
|
-
|
|
18
|
-
},
|
|
19
|
-
let
|
|
20
|
-
if (!
|
|
21
|
-
let
|
|
22
|
-
if (!
|
|
23
|
-
let f =
|
|
24
|
-
if (
|
|
25
|
-
let e =
|
|
16
|
+
}, u = (e, t) => e === t || e !== null && t !== null && e.row === t.row && e.col === t.col, d = () => {
|
|
17
|
+
let n = null, d = null, f = null, p = null, m = !1, h = null, g = !1, _ = !1, v = !1, y = null, b = null, x = () => n?.gridRootRef.current ?? null, S = () => {
|
|
18
|
+
d && e(d) !== d && d.focus({ preventScroll: !0 });
|
|
19
|
+
}, C = (e, t) => {
|
|
20
|
+
let r = x(), c = n?.resolveCell(e) ?? null;
|
|
21
|
+
if (!d || !r || !c) return !1;
|
|
22
|
+
let u = l(r, e, c.colKey);
|
|
23
|
+
if (!u) return !1;
|
|
24
|
+
let f = r.getBoundingClientRect(), p = u.getBoundingClientRect(), m = i(r, f), h = p.top, g = p.bottom;
|
|
25
|
+
if (t) {
|
|
26
|
+
let e = a(u);
|
|
26
27
|
if (e !== null) {
|
|
27
28
|
let t = Math.max(h, e.top), n = Math.min(g, e.bottom);
|
|
28
|
-
n - t >=
|
|
29
|
+
n - t >= s * m.y && (h = t, g = n);
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
32
|
let _ = (g - h) / m.y;
|
|
32
|
-
return
|
|
33
|
-
},
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
33
|
+
return d.style.left = `${(p.left - f.left) / m.x - r.clientLeft}px`, d.style.top = `${(h - f.top) / m.y - r.clientTop}px`, d.style.width = `${p.width / m.x}px`, d.style.height = `${_}px`, d.style.textAlign = t && c.align ? c.align : "", o(d, t && u.classList.contains("ssg-body-cell--valign-top"), _), !0;
|
|
34
|
+
}, w = () => {
|
|
35
|
+
let e = d?.ownerDocument.defaultView ?? null;
|
|
36
|
+
e === null || b !== null || (b = {
|
|
37
|
+
view: e,
|
|
38
|
+
id: e.requestAnimationFrame(() => {
|
|
39
|
+
b = null, !(n === null || !n.enabled || h !== null || g || n.activeCell === null) && u(y, n.activeCell) && (C(n.activeCell, !1) || (y = null));
|
|
40
|
+
})
|
|
41
|
+
});
|
|
42
|
+
}, T = () => {
|
|
43
|
+
b !== null && (b.view.cancelAnimationFrame(b.id), b = null);
|
|
44
|
+
}, E = () => {
|
|
45
|
+
d && (d.classList.remove(c), d.value = "", d.style.textAlign = "", o(d, !1, 0));
|
|
46
|
+
}, D = (e) => {
|
|
47
|
+
n === null || !n.enabled || n.editing || _ || e.target === f && S();
|
|
48
|
+
}, O = () => {
|
|
49
|
+
if (n === null || !n.enabled || n.editing || n.activeCell === null) {
|
|
50
|
+
h = null;
|
|
40
51
|
return;
|
|
41
52
|
}
|
|
42
|
-
let
|
|
43
|
-
|
|
44
|
-
cell:
|
|
45
|
-
allowed:
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
let
|
|
49
|
-
|
|
50
|
-
let
|
|
51
|
-
if (
|
|
52
|
-
|
|
53
|
+
let e = n.activeCell, t = n.canStartEdit(e);
|
|
54
|
+
h = {
|
|
55
|
+
cell: e,
|
|
56
|
+
allowed: t
|
|
57
|
+
}, v = !1, t && (d?.classList.add(c), C(e, !0), y = e);
|
|
58
|
+
}, k = (t) => {
|
|
59
|
+
let r = h;
|
|
60
|
+
h = null;
|
|
61
|
+
let i = v;
|
|
62
|
+
if (v = !1, !d || r === null || !r.allowed || i) {
|
|
63
|
+
E();
|
|
53
64
|
return;
|
|
54
65
|
}
|
|
55
|
-
let
|
|
66
|
+
let a = d.value || t.data || "";
|
|
56
67
|
queueMicrotask(() => {
|
|
57
|
-
let t =
|
|
58
|
-
if (
|
|
59
|
-
|
|
68
|
+
let t = d;
|
|
69
|
+
if (n === null || !n.enabled || !t || a === "" || e(t) !== t || !n.canStartEdit(r.cell)) {
|
|
70
|
+
E();
|
|
60
71
|
return;
|
|
61
72
|
}
|
|
62
|
-
let
|
|
63
|
-
if (
|
|
64
|
-
|
|
73
|
+
let i = n.resolveEditText ? n.resolveEditText(r.cell, a) : a;
|
|
74
|
+
if (i === null || i === "") {
|
|
75
|
+
E();
|
|
65
76
|
return;
|
|
66
77
|
}
|
|
67
|
-
|
|
68
|
-
|
|
78
|
+
g = !0, n.startEdit(r.cell, i), requestAnimationFrame(() => {
|
|
79
|
+
g && n !== null && !n.editing && (g = !1, E());
|
|
69
80
|
});
|
|
70
81
|
});
|
|
71
|
-
},
|
|
72
|
-
|
|
73
|
-
},
|
|
74
|
-
if (
|
|
75
|
-
let
|
|
76
|
-
if (
|
|
77
|
-
|
|
82
|
+
}, A = () => {
|
|
83
|
+
h === null && !g && d && (d.value = "");
|
|
84
|
+
}, j = (n) => {
|
|
85
|
+
if (t(n, d) !== d || n.key !== "Tab" || n.defaultPrevented || r(n) || e(d) !== d) return;
|
|
86
|
+
let i = x();
|
|
87
|
+
if (i) {
|
|
88
|
+
_ = !0;
|
|
78
89
|
try {
|
|
79
|
-
|
|
90
|
+
i.focus({ preventScroll: !0 });
|
|
80
91
|
} finally {
|
|
81
|
-
|
|
92
|
+
_ = !1;
|
|
82
93
|
}
|
|
83
94
|
}
|
|
84
|
-
},
|
|
85
|
-
|
|
86
|
-
},
|
|
87
|
-
|
|
88
|
-
},
|
|
89
|
-
typeof document > "u" ||
|
|
90
|
-
},
|
|
91
|
-
|
|
95
|
+
}, M = () => {
|
|
96
|
+
h !== null && (v = !0);
|
|
97
|
+
}, N = (e) => {
|
|
98
|
+
f !== e && (f?.removeEventListener("focus", D), f = e, f?.addEventListener("focus", D));
|
|
99
|
+
}, P = (e) => {
|
|
100
|
+
typeof document > "u" || m === e || (m = e, e ? (document.addEventListener("keydown", j), document.addEventListener("pointerdown", M, !0)) : (document.removeEventListener("keydown", j), document.removeEventListener("pointerdown", M, !0)));
|
|
101
|
+
}, F = (e) => {
|
|
102
|
+
p !== e && (p && (p.removeEventListener("compositionstart", O), p.removeEventListener("compositionend", k), p.removeEventListener("input", A)), p = e, p && (p.addEventListener("compositionstart", O), p.addEventListener("compositionend", k), p.addEventListener("input", A)));
|
|
92
103
|
};
|
|
93
104
|
return {
|
|
94
105
|
update: (t) => {
|
|
95
|
-
|
|
96
|
-
let
|
|
97
|
-
if (
|
|
98
|
-
|
|
106
|
+
n = t;
|
|
107
|
+
let r = t.gridRootRef.current;
|
|
108
|
+
if (N(t.enabled ? r : null), F(t.enabled ? d : null), P(t.enabled), !t.enabled) {
|
|
109
|
+
h = null, g = !1, E(), d && r && e(d) === d && r.focus({ preventScroll: !0 });
|
|
99
110
|
return;
|
|
100
111
|
}
|
|
101
|
-
|
|
112
|
+
g && t.editing && (g = !1, E()), !(h !== null || g) && (t.activeCell !== null && !u(y, t.activeCell) && C(t.activeCell, !1) && (y = t.activeCell, w()), !t.editing && r && e(r) === r && S());
|
|
102
113
|
},
|
|
103
|
-
attach: (
|
|
104
|
-
|
|
114
|
+
attach: (e) => {
|
|
115
|
+
d !== e && (d = e, F(n?.enabled ? d : null), d && (typeof matchMedia == "function" && matchMedia("(pointer: coarse)").matches && (d.inputMode = "none"), y = null));
|
|
105
116
|
},
|
|
106
117
|
dispose: () => {
|
|
107
|
-
|
|
118
|
+
T(), F(null), N(null), P(!1), h = null, g = !1, n = null;
|
|
108
119
|
}
|
|
109
120
|
};
|
|
110
121
|
};
|
|
111
122
|
//#endregion
|
|
112
|
-
export {
|
|
123
|
+
export { c as IME_INPUT_COMPOSING_CLASS, d as createImeInputController };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../model/gridActions.cjs"),t=require("../utils/permissions.cjs"),n=require("../logic/detailRow.cjs"),r=require("../logic/geometry.cjs"),i=require("../logic/domGuards.cjs"),a=require("./escapeClaimController.cjs");var
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../model/gridActions.cjs"),t=require("../utils/permissions.cjs"),n=require("../logic/detailRow.cjs"),r=require("../logic/geometry.cjs"),i=require("../logic/domGuards.cjs"),a=require("./liveUiState.cjs"),o=require("./clipboardController.cjs"),s=require("./escapeClaimController.cjs");var c=10,l=(e,t,n,r)=>{if(!e.getLabelRow)return t;let i=e.getRowCount(),a=t;for(;a>=0&&a<i&&e.getLabelRow(a);)a+=n;return a>=0&&a<i?a:r},u=e=>l(e,0,1,0),d=e=>n.resolveFirstDataColIndex(e),f=(e,t)=>({row:u(e),col:d(t)}),p=()=>{let n=null,p=e=>{n=e},m=(e,t)=>l(e,t,-1,l(e,t,1,t)),h=e=>{let t=e.getRowCount()-1;return l(e,t,-1,t)},g=(t,r,i)=>{if(n===null)return;let{dispatch:o}=n,s=a.readLiveUiState(n);if(i){let n=s.selection?.type===`cell`?s.selection.range.start:t;o(e.gridActions.startSelection(n)),o(e.gridActions.updateSelection(r)),o(e.gridActions.endSelection()),o(e.gridActions.activateCell(r));return}o(e.gridActions.startSelection(r)),o(e.gridActions.endSelection()),o(e.gridActions.activateCell(r))},_=()=>{if(n===null||a.readLiveUiState(n).activeCell)return!1;let{rowModel:e,visibleColumns:t}=n;if(e.getRowCount()===0||t.length===0)return!0;let r=f(e,t);return g(r,r,!1),!0},v=e=>{let t=n===null?void 0:a.readLiveUiState(n);return e&&t?.selection?.type===`cell`?t.selection.range.end:t?.activeCell??{row:0,col:0}},y=(e,t,i)=>{if(n===null)return;let{rowModel:a,visibleColumns:o}=n,s=a.getRowCount();if(s===0||o.length===0||_())return;let c=v(i),u=r.clamp(c.row+e,0,s-1);u=e===0?m(a,u):l(a,u,e>0?1:-1,c.row);let d={row:u,col:r.clamp(c.col+t,0,o.length-1)};g(c,d,i)},b=(e,t,i)=>{if(n===null)return;let{rowModel:o,visibleColumns:s}=n,c=a.readLiveUiState(n);if(o.getRowCount()===0||s.length===0)return;let l=c.activeCell?v(t):{row:u(o),col:d(s)},f=e(l,o,s),p=r.clamp(f.col,0,s.length-1);g(l,{row:m(o,r.clamp(f.row,0,o.getRowCount()-1)),col:p},t&&c.activeCell!==null);let h=i===void 0?null:n.scrollContainerRef?.current??null,_=s[p]?.pinned;h!==null&&(i===`start`?_===`left`:_===`right`)&&(h.scrollLeft=i===`start`?0:Math.max(h.scrollWidth-h.clientWidth,0))},x=(e,t,i)=>{let a=t.getRowCount(),o=n?.resolvePageRow?n.resolvePageRow(e.row,i):e.row+i*c,s=r.clamp(i>0?Math.max(o,e.row+1):Math.min(o,e.row-1),0,a-1),u=l(t,s,i,-1);return u>=0?u:l(t,s,i>0?-1:1,e.row)};return{update:p,handleKeyDown:async r=>{if(n===null)return;let{rowModel:c,visibleColumns:l,readOnly:f,canEditCell:p,setEditorInitialValue:m,dispatch:g,handleCopy:v,openFind:S,handleCellDoubleClick:C,selectEntireGrid:w,onUndo:T,onRedo:E,onClearSelection:D,enableClearOnDelete:O,onToggleCheckboxCell:k,onToggleGroup:A,onToggleDetailRow:j}=n,M=a.readLiveUiState(n),N=n.getUiState?o.computeIsWholeGridSelected(M.selection,c.getRowCount(),l.length):n.isWholeGridSelected;if(i.shouldIgnoreGridKeydown(r.target)||a.isEditingAtEvent(n)||r.isComposing&&i.isImeInputTarget(r.target))return;if((r.ctrlKey||r.metaKey)&&r.key.toLowerCase()===`c`){r.preventDefault(),await v();return}if((r.ctrlKey||r.metaKey)&&r.key.toLowerCase()===`f`&&S){r.preventDefault(),S();return}if((r.ctrlKey||r.metaKey)&&r.key.toLowerCase()===`a`){if(r.preventDefault(),N){g(e.gridActions.clearSelection()),g(e.gridActions.activateCell(null));return}w();return}if((r.ctrlKey||r.metaKey)&&!r.isComposing){if(r.key.toLowerCase()===`z`){r.preventDefault(),r.shiftKey?E():T();return}if(r.key.toLowerCase()===`y`&&!r.shiftKey){r.preventDefault(),E();return}}let P=r.ctrlKey||r.metaKey;if((r.key===`ContextMenu`||r.key===`F10`&&r.shiftKey)&&!P&&!r.altKey&&M.activeCell&&n.openContextMenu?.(M.activeCell)){r.preventDefault();return}if(r.key===`ArrowDown`&&r.altKey&&!P&&!r.shiftKey&&M.activeCell&&n.openColumnMenu?.(M.activeCell.col)){r.preventDefault();return}if(P&&!r.altKey&&(r.key===`ArrowUp`||r.key===`ArrowDown`)){r.preventDefault();let e=r.key===`ArrowDown`;b((t,n)=>({row:e?h(n):u(n),col:t.col}),r.shiftKey);return}if(P&&!r.altKey&&(r.key===`ArrowLeft`||r.key===`ArrowRight`)){r.preventDefault();let e=r.key===`ArrowRight`;b((t,n,r)=>({row:t.row,col:e?r.length-1:d(r)}),r.shiftKey,e?`end`:`start`);return}if((r.key===`Home`||r.key===`End`)&&!r.altKey){r.preventDefault();let e=r.key===`End`;b((t,n,r)=>({row:P?e?h(n):u(n):t.row,col:e?r.length-1:d(r)}),r.shiftKey,e?`end`:`start`);return}if((r.key===`PageDown`||r.key===`PageUp`)&&!P&&!r.altKey){if(r.preventDefault(),_())return;let e=r.key===`PageDown`?1:-1;b((t,n)=>({row:x(t,n,e),col:t.col}),r.shiftKey);return}if(r.key===`ArrowUp`){r.preventDefault(),y(-1,0,r.shiftKey);return}if(r.key===`ArrowDown`){r.preventDefault(),y(1,0,r.shiftKey);return}if(r.key===`ArrowLeft`){r.preventDefault(),y(0,-1,r.shiftKey);return}if(r.key===`ArrowRight`){r.preventDefault(),y(0,1,r.shiftKey);return}if(r.key===`Tab`){if(!M.activeCell&&!r.shiftKey){if(n.rowModel.getRowCount()===0||n.visibleColumns.length===0)return;r.preventDefault(),_();return}let e=M.activeCell?.col??0;if(r.shiftKey?e<=d(n.visibleColumns):e>=n.visibleColumns.length-1){!r.shiftKey&&M.activeCell&&n.onTabPastLastColumn?.(M.activeCell.row)&&r.preventDefault();return}r.preventDefault(),y(0,r.shiftKey?-1:1,!1);return}if(r.key===`Escape`){s.isClearableSelection(M.selection)&&r.preventDefault(),g(e.gridActions.clearSelection());return}if((r.key===`Delete`||r.key===`Backspace`)&&O){r.preventDefault(),D();return}if((r.key===`Enter`||r.key===` `)&&M.activeCell){let e=c.getGroupRow?.(M.activeCell.row);if(e){r.preventDefault(),A(e.groupKey);return}if(j&&l[M.activeCell.col]?.key===`__ssg_detail_toggle__`&&j(M.activeCell)){r.preventDefault();return}}if(r.key===`Enter`||r.key===`F2`){if(r.preventDefault(),M.activeCell){C(M.activeCell);return}r.key===`Enter`&&_();return}if(r.key===` `&&!r.ctrlKey&&!r.metaKey&&!r.altKey&&r.preventDefault(),i.isPrintableKey(r)&&M.activeCell){let n=c.getRow(M.activeCell.row),i=l[M.activeCell.col];if(!n||!i||!t.isViewCellEditable({readOnly:f,canEditCell:p},c,M.activeCell.row,M.activeCell.col,n,i))return;if(i.editor?.type===`checkbox`){r.preventDefault(),r.key===` `&&k(M.activeCell);return}r.preventDefault(),m(r.key),g(e.gridActions.startEdit(M.activeCell))}}}};exports.createKeyboardController=p,exports.resolveFirstDataCell=f;
|
|
@@ -12,6 +12,7 @@ export type GridKeyboardEventLike = {
|
|
|
12
12
|
};
|
|
13
13
|
export type KeyboardControllerArgs<T> = {
|
|
14
14
|
uiState: GridUiState;
|
|
15
|
+
getUiState?: (() => GridUiState) | undefined;
|
|
15
16
|
rowModel: RowModel<T>;
|
|
16
17
|
visibleColumns: GridColumn<T>[];
|
|
17
18
|
readOnly: boolean;
|
|
@@ -34,6 +35,9 @@ export type KeyboardControllerArgs<T> = {
|
|
|
34
35
|
openColumnMenu?: (col: number) => boolean;
|
|
35
36
|
openContextMenu?: (cell: CellCoord) => boolean;
|
|
36
37
|
onTabPastLastColumn?: (viewRowIndex: number) => boolean;
|
|
38
|
+
scrollContainerRef?: {
|
|
39
|
+
readonly current: HTMLElement | null;
|
|
40
|
+
} | undefined;
|
|
37
41
|
};
|
|
38
42
|
export declare const resolveFirstDataCell: <T>(rowModel: RowModel<T>, visibleColumns: GridColumn<T>[]) => CellCoord;
|
|
39
43
|
export type KeyboardController<T> = {
|
|
@@ -3,218 +3,222 @@ 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, i) => {
|
|
55
57
|
if (n === null) return;
|
|
56
|
-
let {
|
|
58
|
+
let { rowModel: a, visibleColumns: o } = n, s = c(n);
|
|
57
59
|
if (a.getRowCount() === 0 || o.length === 0) return;
|
|
58
|
-
let
|
|
59
|
-
row:
|
|
60
|
-
col:
|
|
61
|
-
},
|
|
62
|
-
|
|
63
|
-
row:
|
|
64
|
-
col:
|
|
65
|
-
}, t &&
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
60
|
+
let l = s.activeCell ? x(t) : {
|
|
61
|
+
row: p(a),
|
|
62
|
+
col: m(o)
|
|
63
|
+
}, u = e(l, a, o), d = r(u.col, 0, o.length - 1);
|
|
64
|
+
y(l, {
|
|
65
|
+
row: _(a, r(u.row, 0, a.getRowCount() - 1)),
|
|
66
|
+
col: d
|
|
67
|
+
}, t && s.activeCell !== null);
|
|
68
|
+
let f = i === void 0 ? null : n.scrollContainerRef?.current ?? null, h = o[d]?.pinned;
|
|
69
|
+
f !== null && (i === "start" ? h === "left" : h === "right") && (f.scrollLeft = i === "start" ? 0 : Math.max(f.scrollWidth - f.clientWidth, 0));
|
|
70
|
+
}, w = (e, t, i) => {
|
|
71
|
+
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);
|
|
72
|
+
return c >= 0 ? c : f(t, s, i > 0 ? -1 : 1, e.row);
|
|
69
73
|
};
|
|
70
74
|
return {
|
|
71
|
-
update:
|
|
75
|
+
update: g,
|
|
72
76
|
handleKeyDown: async (r) => {
|
|
73
77
|
if (n === null) return;
|
|
74
|
-
let {
|
|
75
|
-
if (o(r.target) ||
|
|
78
|
+
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;
|
|
79
|
+
if (o(r.target) || s(n) || r.isComposing && i(r.target)) return;
|
|
76
80
|
if ((r.ctrlKey || r.metaKey) && r.key.toLowerCase() === "c") {
|
|
77
|
-
r.preventDefault(), await
|
|
81
|
+
r.preventDefault(), await x();
|
|
78
82
|
return;
|
|
79
83
|
}
|
|
80
|
-
if ((r.ctrlKey || r.metaKey) && r.key.toLowerCase() === "f" &&
|
|
81
|
-
r.preventDefault(),
|
|
84
|
+
if ((r.ctrlKey || r.metaKey) && r.key.toLowerCase() === "f" && T) {
|
|
85
|
+
r.preventDefault(), T();
|
|
82
86
|
return;
|
|
83
87
|
}
|
|
84
88
|
if ((r.ctrlKey || r.metaKey) && r.key.toLowerCase() === "a") {
|
|
85
|
-
if (r.preventDefault(),
|
|
86
|
-
|
|
89
|
+
if (r.preventDefault(), I) {
|
|
90
|
+
y(e.clearSelection()), y(e.activateCell(null));
|
|
87
91
|
return;
|
|
88
92
|
}
|
|
89
|
-
|
|
93
|
+
D();
|
|
90
94
|
return;
|
|
91
95
|
}
|
|
92
96
|
if ((r.ctrlKey || r.metaKey) && !r.isComposing) {
|
|
93
97
|
if (r.key.toLowerCase() === "z") {
|
|
94
|
-
r.preventDefault(), r.shiftKey ?
|
|
98
|
+
r.preventDefault(), r.shiftKey ? k() : O();
|
|
95
99
|
return;
|
|
96
100
|
}
|
|
97
101
|
if (r.key.toLowerCase() === "y" && !r.shiftKey) {
|
|
98
|
-
r.preventDefault(),
|
|
102
|
+
r.preventDefault(), k();
|
|
99
103
|
return;
|
|
100
104
|
}
|
|
101
105
|
}
|
|
102
|
-
let
|
|
103
|
-
if ((r.key === "ContextMenu" || r.key === "F10" && r.shiftKey) && !
|
|
106
|
+
let L = r.ctrlKey || r.metaKey;
|
|
107
|
+
if ((r.key === "ContextMenu" || r.key === "F10" && r.shiftKey) && !L && !r.altKey && F.activeCell && n.openContextMenu?.(F.activeCell)) {
|
|
104
108
|
r.preventDefault();
|
|
105
109
|
return;
|
|
106
110
|
}
|
|
107
|
-
if (r.key === "ArrowDown" && r.altKey && !
|
|
111
|
+
if (r.key === "ArrowDown" && r.altKey && !L && !r.shiftKey && F.activeCell && n.openColumnMenu?.(F.activeCell.col)) {
|
|
108
112
|
r.preventDefault();
|
|
109
113
|
return;
|
|
110
114
|
}
|
|
111
|
-
if (
|
|
115
|
+
if (L && !r.altKey && (r.key === "ArrowUp" || r.key === "ArrowDown")) {
|
|
112
116
|
r.preventDefault();
|
|
113
117
|
let e = r.key === "ArrowDown";
|
|
114
|
-
|
|
115
|
-
row: e ?
|
|
118
|
+
C((t, n) => ({
|
|
119
|
+
row: e ? v(n) : p(n),
|
|
116
120
|
col: t.col
|
|
117
121
|
}), r.shiftKey);
|
|
118
122
|
return;
|
|
119
123
|
}
|
|
120
|
-
if (
|
|
124
|
+
if (L && !r.altKey && (r.key === "ArrowLeft" || r.key === "ArrowRight")) {
|
|
121
125
|
r.preventDefault();
|
|
122
126
|
let e = r.key === "ArrowRight";
|
|
123
|
-
|
|
127
|
+
C((t, n, r) => ({
|
|
124
128
|
row: t.row,
|
|
125
|
-
col: e ? r.length - 1 :
|
|
126
|
-
}), r.shiftKey);
|
|
129
|
+
col: e ? r.length - 1 : m(r)
|
|
130
|
+
}), r.shiftKey, e ? "end" : "start");
|
|
127
131
|
return;
|
|
128
132
|
}
|
|
129
133
|
if ((r.key === "Home" || r.key === "End") && !r.altKey) {
|
|
130
134
|
r.preventDefault();
|
|
131
135
|
let e = r.key === "End";
|
|
132
|
-
|
|
133
|
-
row:
|
|
134
|
-
col: e ? r.length - 1 :
|
|
135
|
-
}), r.shiftKey);
|
|
136
|
+
C((t, n, r) => ({
|
|
137
|
+
row: L ? e ? v(n) : p(n) : t.row,
|
|
138
|
+
col: e ? r.length - 1 : m(r)
|
|
139
|
+
}), r.shiftKey, e ? "end" : "start");
|
|
136
140
|
return;
|
|
137
141
|
}
|
|
138
|
-
if ((r.key === "PageDown" || r.key === "PageUp") && !
|
|
139
|
-
if (r.preventDefault(),
|
|
142
|
+
if ((r.key === "PageDown" || r.key === "PageUp") && !L && !r.altKey) {
|
|
143
|
+
if (r.preventDefault(), b()) return;
|
|
140
144
|
let e = r.key === "PageDown" ? 1 : -1;
|
|
141
|
-
|
|
142
|
-
row:
|
|
145
|
+
C((t, n) => ({
|
|
146
|
+
row: w(t, n, e),
|
|
143
147
|
col: t.col
|
|
144
148
|
}), r.shiftKey);
|
|
145
149
|
return;
|
|
146
150
|
}
|
|
147
151
|
if (r.key === "ArrowUp") {
|
|
148
|
-
r.preventDefault(),
|
|
152
|
+
r.preventDefault(), S(-1, 0, r.shiftKey);
|
|
149
153
|
return;
|
|
150
154
|
}
|
|
151
155
|
if (r.key === "ArrowDown") {
|
|
152
|
-
r.preventDefault(),
|
|
156
|
+
r.preventDefault(), S(1, 0, r.shiftKey);
|
|
153
157
|
return;
|
|
154
158
|
}
|
|
155
159
|
if (r.key === "ArrowLeft") {
|
|
156
|
-
r.preventDefault(),
|
|
160
|
+
r.preventDefault(), S(0, -1, r.shiftKey);
|
|
157
161
|
return;
|
|
158
162
|
}
|
|
159
163
|
if (r.key === "ArrowRight") {
|
|
160
|
-
r.preventDefault(),
|
|
164
|
+
r.preventDefault(), S(0, 1, r.shiftKey);
|
|
161
165
|
return;
|
|
162
166
|
}
|
|
163
167
|
if (r.key === "Tab") {
|
|
164
|
-
if (!
|
|
168
|
+
if (!F.activeCell && !r.shiftKey) {
|
|
165
169
|
if (n.rowModel.getRowCount() === 0 || n.visibleColumns.length === 0) return;
|
|
166
|
-
r.preventDefault(),
|
|
170
|
+
r.preventDefault(), b();
|
|
167
171
|
return;
|
|
168
172
|
}
|
|
169
|
-
let e =
|
|
170
|
-
if (r.shiftKey ? e <=
|
|
171
|
-
!r.shiftKey &&
|
|
173
|
+
let e = F.activeCell?.col ?? 0;
|
|
174
|
+
if (r.shiftKey ? e <= m(n.visibleColumns) : e >= n.visibleColumns.length - 1) {
|
|
175
|
+
!r.shiftKey && F.activeCell && n.onTabPastLastColumn?.(F.activeCell.row) && r.preventDefault();
|
|
172
176
|
return;
|
|
173
177
|
}
|
|
174
|
-
r.preventDefault(),
|
|
178
|
+
r.preventDefault(), S(0, r.shiftKey ? -1 : 1, !1);
|
|
175
179
|
return;
|
|
176
180
|
}
|
|
177
181
|
if (r.key === "Escape") {
|
|
178
|
-
|
|
182
|
+
u(F.selection) && r.preventDefault(), y(e.clearSelection());
|
|
179
183
|
return;
|
|
180
184
|
}
|
|
181
|
-
if ((r.key === "Delete" || r.key === "Backspace") &&
|
|
182
|
-
r.preventDefault(),
|
|
185
|
+
if ((r.key === "Delete" || r.key === "Backspace") && j) {
|
|
186
|
+
r.preventDefault(), A();
|
|
183
187
|
return;
|
|
184
188
|
}
|
|
185
|
-
if ((r.key === "Enter" || r.key === " ") &&
|
|
186
|
-
let e =
|
|
189
|
+
if ((r.key === "Enter" || r.key === " ") && F.activeCell) {
|
|
190
|
+
let e = d.getGroupRow?.(F.activeCell.row);
|
|
187
191
|
if (e) {
|
|
188
|
-
r.preventDefault(),
|
|
192
|
+
r.preventDefault(), N(e.groupKey);
|
|
189
193
|
return;
|
|
190
194
|
}
|
|
191
|
-
if (
|
|
195
|
+
if (P && f[F.activeCell.col]?.key === "__ssg_detail_toggle__" && P(F.activeCell)) {
|
|
192
196
|
r.preventDefault();
|
|
193
197
|
return;
|
|
194
198
|
}
|
|
195
199
|
}
|
|
196
200
|
if (r.key === "Enter" || r.key === "F2") {
|
|
197
|
-
if (r.preventDefault(),
|
|
198
|
-
|
|
201
|
+
if (r.preventDefault(), F.activeCell) {
|
|
202
|
+
E(F.activeCell);
|
|
199
203
|
return;
|
|
200
204
|
}
|
|
201
|
-
r.key === "Enter" &&
|
|
205
|
+
r.key === "Enter" && b();
|
|
202
206
|
return;
|
|
203
207
|
}
|
|
204
|
-
if (r.key === " " && !r.ctrlKey && !r.metaKey && !r.altKey && r.preventDefault(), a(r) &&
|
|
205
|
-
let n =
|
|
208
|
+
if (r.key === " " && !r.ctrlKey && !r.metaKey && !r.altKey && r.preventDefault(), a(r) && F.activeCell) {
|
|
209
|
+
let n = d.getRow(F.activeCell.row), i = f[F.activeCell.col];
|
|
206
210
|
if (!n || !i || !t({
|
|
207
|
-
readOnly:
|
|
208
|
-
canEditCell:
|
|
209
|
-
},
|
|
211
|
+
readOnly: h,
|
|
212
|
+
canEditCell: g
|
|
213
|
+
}, d, F.activeCell.row, F.activeCell.col, n, i)) return;
|
|
210
214
|
if (i.editor?.type === "checkbox") {
|
|
211
|
-
r.preventDefault(), r.key === " " &&
|
|
215
|
+
r.preventDefault(), r.key === " " && M(F.activeCell);
|
|
212
216
|
return;
|
|
213
217
|
}
|
|
214
|
-
r.preventDefault(),
|
|
218
|
+
r.preventDefault(), _(r.key), y(e.startEdit(F.activeCell));
|
|
215
219
|
}
|
|
216
220
|
}
|
|
217
221
|
};
|
|
218
222
|
};
|
|
219
223
|
//#endregion
|
|
220
|
-
export {
|
|
224
|
+
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;
|