@affino/datagrid-vue-app 0.1.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/LICENSE +21 -0
- package/README.md +1062 -0
- package/dist/DataGrid.d.ts +430 -0
- package/dist/DataGrid.js +565 -0
- package/dist/DataGridDefaultRenderer.d.ts +2 -0
- package/dist/DataGridDefaultRenderer.js +2 -0
- package/dist/DataGridModuleHost.d.ts +2 -0
- package/dist/DataGridModuleHost.js +2 -0
- package/dist/DataGridRuntimeHost.d.ts +1 -0
- package/dist/DataGridRuntimeHost.js +1 -0
- package/dist/config/dataGridAdvancedFilter.d.ts +9 -0
- package/dist/config/dataGridAdvancedFilter.js +21 -0
- package/dist/config/dataGridAggregations.d.ts +17 -0
- package/dist/config/dataGridAggregations.js +21 -0
- package/dist/config/dataGridColumnLayout.d.ts +9 -0
- package/dist/config/dataGridColumnLayout.js +21 -0
- package/dist/config/dataGridFormulaOptions.d.ts +25 -0
- package/dist/config/dataGridFormulaOptions.js +137 -0
- package/dist/config/dataGridPublicProps.d.ts +6 -0
- package/dist/config/dataGridPublicProps.js +58 -0
- package/dist/config/dataGridSavedView.d.ts +17 -0
- package/dist/config/dataGridSavedView.js +73 -0
- package/dist/config/dataGridVirtualization.d.ts +14 -0
- package/dist/config/dataGridVirtualization.js +32 -0
- package/dist/dataGridAdvancedFilter.d.ts +1 -0
- package/dist/dataGridAdvancedFilter.js +1 -0
- package/dist/dataGridAggregations.d.ts +1 -0
- package/dist/dataGridAggregations.js +1 -0
- package/dist/dataGridAppContext.d.ts +2 -0
- package/dist/dataGridAppContext.js +1 -0
- package/dist/dataGridCellComboboxState.d.ts +10 -0
- package/dist/dataGridCellComboboxState.js +67 -0
- package/dist/dataGridColumnLayout.d.ts +1 -0
- package/dist/dataGridColumnLayout.js +1 -0
- package/dist/dataGridColumnMenu.d.ts +9 -0
- package/dist/dataGridColumnMenu.js +21 -0
- package/dist/dataGridEditability.d.ts +9 -0
- package/dist/dataGridEditability.js +1 -0
- package/dist/dataGridFilterableCombobox.d.ts +1 -0
- package/dist/dataGridFilterableCombobox.js +1 -0
- package/dist/dataGridFormulaOptions.d.ts +1 -0
- package/dist/dataGridFormulaOptions.js +1 -0
- package/dist/dataGridGantt.d.ts +3 -0
- package/dist/dataGridGantt.js +1 -0
- package/dist/dataGridGanttDependencySelection.d.ts +7 -0
- package/dist/dataGridGanttDependencySelection.js +46 -0
- package/dist/dataGridGanttLabel.d.ts +2 -0
- package/dist/dataGridGanttLabel.js +30 -0
- package/dist/dataGridGanttSplit.d.ts +20 -0
- package/dist/dataGridGanttSplit.js +31 -0
- package/dist/dataGridGanttWheel.d.ts +10 -0
- package/dist/dataGridGanttWheel.js +30 -0
- package/dist/dataGridOverlayThemeVars.d.ts +1 -0
- package/dist/dataGridOverlayThemeVars.js +32 -0
- package/dist/dataGridPublicProps.d.ts +1 -0
- package/dist/dataGridPublicProps.js +1 -0
- package/dist/dataGridTableStage.types.d.ts +1 -0
- package/dist/dataGridTableStage.types.js +1 -0
- package/dist/dataGridTableStageBody.types.d.ts +1 -0
- package/dist/dataGridTableStageBody.types.js +1 -0
- package/dist/dataGridTableStageContext.d.ts +1 -0
- package/dist/dataGridTableStageContext.js +1 -0
- package/dist/dataGridTheme.d.ts +1 -0
- package/dist/dataGridTheme.js +1 -0
- package/dist/dataGridVirtualization.d.ts +1 -0
- package/dist/dataGridVirtualization.js +1 -0
- package/dist/ensureDataGridAppStyles.d.ts +1 -0
- package/dist/ensureDataGridAppStyles.js +1 -0
- package/dist/gantt/dataGridGantt.d.ts +3 -0
- package/dist/gantt/dataGridGantt.js +1 -0
- package/dist/gantt/dataGridGanttDependencySelection.d.ts +7 -0
- package/dist/gantt/dataGridGanttDependencySelection.js +46 -0
- package/dist/gantt/dataGridGanttLabel.d.ts +2 -0
- package/dist/gantt/dataGridGanttLabel.js +30 -0
- package/dist/gantt/dataGridGanttSplit.d.ts +20 -0
- package/dist/gantt/dataGridGanttSplit.js +31 -0
- package/dist/gantt/dataGridGanttWheel.d.ts +10 -0
- package/dist/gantt/dataGridGanttWheel.js +30 -0
- package/dist/host/DataGridDefaultRenderer.d.ts +298 -0
- package/dist/host/DataGridDefaultRenderer.js +1847 -0
- package/dist/host/DataGridModuleHost.d.ts +24 -0
- package/dist/host/DataGridModuleHost.js +23 -0
- package/dist/host/DataGridRuntimeHost.d.ts +104 -0
- package/dist/host/DataGridRuntimeHost.js +174 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +4 -0
- package/dist/internal.d.ts +21 -0
- package/dist/internal.js +14 -0
- package/dist/overlays/dataGridCellComboboxState.d.ts +10 -0
- package/dist/overlays/dataGridCellComboboxState.js +67 -0
- package/dist/overlays/dataGridColumnMenu.d.ts +47 -0
- package/dist/overlays/dataGridColumnMenu.js +190 -0
- package/dist/overlays/dataGridContextMenu.d.ts +80 -0
- package/dist/overlays/dataGridContextMenu.js +218 -0
- package/dist/overlays/dataGridFilterableCombobox.d.ts +5 -0
- package/dist/overlays/dataGridFilterableCombobox.js +74 -0
- package/dist/overlays/dataGridOverlayThemeVars.d.ts +1 -0
- package/dist/overlays/dataGridOverlayThemeVars.js +32 -0
- package/dist/stage/dataGridTableStage.types.d.ts +160 -0
- package/dist/stage/dataGridTableStage.types.js +1 -0
- package/dist/stage/dataGridTableStageBody.types.d.ts +105 -0
- package/dist/stage/dataGridTableStageBody.types.js +1 -0
- package/dist/stage/dataGridTableStageContext.d.ts +45 -0
- package/dist/stage/dataGridTableStageContext.js +88 -0
- package/dist/stage/useDataGridTableStageBindings.d.ts +11 -0
- package/dist/stage/useDataGridTableStageBindings.js +162 -0
- package/dist/stage/useDataGridTableStageCellIo.d.ts +28 -0
- package/dist/stage/useDataGridTableStageCellIo.js +62 -0
- package/dist/stage/useDataGridTableStageColumns.d.ts +22 -0
- package/dist/stage/useDataGridTableStageColumns.js +124 -0
- package/dist/stage/useDataGridTableStageFillAction.d.ts +19 -0
- package/dist/stage/useDataGridTableStageFillAction.js +28 -0
- package/dist/stage/useDataGridTableStageHistory.d.ts +31 -0
- package/dist/stage/useDataGridTableStageHistory.js +46 -0
- package/dist/stage/useDataGridTableStageRowSelection.d.ts +28 -0
- package/dist/stage/useDataGridTableStageRowSelection.js +107 -0
- package/dist/stage/useDataGridTableStageRuntime.d.ts +92 -0
- package/dist/stage/useDataGridTableStageRuntime.js +526 -0
- package/dist/stage/useDataGridTableStageScrollSync.d.ts +17 -0
- package/dist/stage/useDataGridTableStageScrollSync.js +49 -0
- package/dist/stage/useDataGridTableStageViewportKeyboard.d.ts +20 -0
- package/dist/stage/useDataGridTableStageViewportKeyboard.js +58 -0
- package/dist/stage/useDataGridTableStageVisualSelection.d.ts +24 -0
- package/dist/stage/useDataGridTableStageVisualSelection.js +83 -0
- package/dist/theme/dataGridTheme.d.ts +6 -0
- package/dist/theme/dataGridTheme.js +84 -0
- package/dist/theme/ensureDataGridAppStyles.d.ts +1 -0
- package/dist/theme/ensureDataGridAppStyles.js +2656 -0
- package/dist/useDataGridAppControlledState.d.ts +59 -0
- package/dist/useDataGridAppControlledState.js +390 -0
- package/dist/useDataGridAppRowModel.d.ts +14 -0
- package/dist/useDataGridAppRowModel.js +85 -0
- package/dist/useDataGridTableStageBindings.d.ts +1 -0
- package/dist/useDataGridTableStageBindings.js +1 -0
- package/dist/useDataGridTableStageCellIo.d.ts +28 -0
- package/dist/useDataGridTableStageCellIo.js +62 -0
- package/dist/useDataGridTableStageColumns.d.ts +21 -0
- package/dist/useDataGridTableStageColumns.js +122 -0
- package/dist/useDataGridTableStageFillAction.d.ts +19 -0
- package/dist/useDataGridTableStageFillAction.js +28 -0
- package/dist/useDataGridTableStageHistory.d.ts +31 -0
- package/dist/useDataGridTableStageHistory.js +46 -0
- package/dist/useDataGridTableStageRowSelection.d.ts +28 -0
- package/dist/useDataGridTableStageRowSelection.js +103 -0
- package/dist/useDataGridTableStageRuntime.d.ts +1 -0
- package/dist/useDataGridTableStageRuntime.js +1 -0
- package/dist/useDataGridTableStageScrollSync.d.ts +17 -0
- package/dist/useDataGridTableStageScrollSync.js +49 -0
- package/dist/useDataGridTableStageViewportKeyboard.d.ts +20 -0
- package/dist/useDataGridTableStageViewportKeyboard.js +58 -0
- package/dist/useDataGridTableStageVisualSelection.d.ts +24 -0
- package/dist/useDataGridTableStageVisualSelection.js +70 -0
- package/package.json +55 -0
|
@@ -0,0 +1,526 @@
|
|
|
1
|
+
import { computed, nextTick, ref } from "vue";
|
|
2
|
+
import { createDataGridAppRowHeightMetrics, useDataGridAppActiveCellViewport, useDataGridAppCellSelection, useDataGridAppClipboard, useDataGridAppHeaderResize, useDataGridAppInlineEditing, useDataGridAppInteractionController, useDataGridAppRowPresentation, useDataGridAppRowSizing, useDataGridAppViewport, useDataGridAppRuntimeSync, useDataGridAppViewportLifecycle, } from "@affino/datagrid-vue";
|
|
3
|
+
import { useDataGridTableStageBindings } from "./useDataGridTableStageBindings";
|
|
4
|
+
import { useDataGridTableStageCellIo } from "./useDataGridTableStageCellIo";
|
|
5
|
+
import { useDataGridTableStageColumns } from "./useDataGridTableStageColumns";
|
|
6
|
+
import { useDataGridTableStageFillAction } from "./useDataGridTableStageFillAction";
|
|
7
|
+
import { useDataGridTableStageHistory } from "./useDataGridTableStageHistory";
|
|
8
|
+
import { useDataGridTableStageRowSelection } from "./useDataGridTableStageRowSelection";
|
|
9
|
+
import { useDataGridTableStageScrollSync } from "./useDataGridTableStageScrollSync";
|
|
10
|
+
import { useDataGridTableStageViewportKeyboard } from "./useDataGridTableStageViewportKeyboard";
|
|
11
|
+
import { useDataGridTableStageVisualSelection } from "./useDataGridTableStageVisualSelection";
|
|
12
|
+
const DEFAULT_COLUMN_WIDTH = 140;
|
|
13
|
+
const INDEX_COLUMN_WIDTH = 72;
|
|
14
|
+
const MIN_COLUMN_WIDTH = 80;
|
|
15
|
+
const MIN_ROW_HEIGHT = 24;
|
|
16
|
+
const AUTO_RESIZE_SAMPLE_LIMIT = 400;
|
|
17
|
+
export function useDataGridTableStageRuntime(options) {
|
|
18
|
+
const syncRowSelectionSnapshotFromRuntime = options.syncRowSelectionSnapshotFromRuntime ?? (() => undefined);
|
|
19
|
+
const rowSelectionSnapshotRef = options.rowSelectionSnapshot ?? ref(null);
|
|
20
|
+
const showRowIndex = computed(() => options.showRowIndex?.value !== false);
|
|
21
|
+
const totalBodyRows = computed(() => options.runtime.rowPartition.value.bodyRowCount);
|
|
22
|
+
const totalSelectableRows = computed(() => Math.max(0, options.totalRuntimeRows.value));
|
|
23
|
+
const effectiveIndexColumnWidth = computed(() => (showRowIndex.value ? INDEX_COLUMN_WIDTH : 0));
|
|
24
|
+
const columnService = useDataGridTableStageColumns({
|
|
25
|
+
runtime: options.runtime,
|
|
26
|
+
visibleColumns: options.visibleColumns,
|
|
27
|
+
showRowSelection: options.showRowSelection,
|
|
28
|
+
isCellEditable: options.isCellEditable,
|
|
29
|
+
});
|
|
30
|
+
const { orderedVisibleColumns, centerColumns, resolveColumnWidth, isRowSelectionColumnKey, isRowSelectionColumn, isCellEditable, isCellEditableByKey, rowSelectionColumn, } = columnService;
|
|
31
|
+
const rowHeightMetrics = createDataGridAppRowHeightMetrics({
|
|
32
|
+
totalRows: () => totalBodyRows.value,
|
|
33
|
+
resolveBaseRowHeight: () => options.normalizedBaseRowHeight.value,
|
|
34
|
+
resolveRowHeightOverride: rowIndex => options.runtime.api.view.getRowHeightOverride(rowIndex),
|
|
35
|
+
resolveRowHeightVersion: () => options.runtime.api.view.getRowHeightVersion(),
|
|
36
|
+
hasRowHeightOverrides: () => options.runtime.api.view.getRowHeightVersion() > 0,
|
|
37
|
+
});
|
|
38
|
+
let isEditingCellForSelection = () => false;
|
|
39
|
+
const { headerViewportRef, bodyViewportRef, displayRows, pinnedBottomRows, renderedColumns, viewportRowStart, viewportColumnStart, topSpacerHeight, bottomSpacerHeight, leftColumnSpacerWidth, rightColumnSpacerWidth, gridContentStyle, mainTrackStyle, indexColumnStyle, columnStyle: _viewportColumnStyle, handleViewportScroll, syncViewportFromDom, scheduleViewportSync, cancelScheduledViewportSync, } = useDataGridAppViewport({
|
|
40
|
+
runtime: options.runtime,
|
|
41
|
+
mode: options.mode,
|
|
42
|
+
rowRenderMode: options.rowRenderMode,
|
|
43
|
+
rowVirtualizationEnabled: computed(() => options.virtualization.value.rows),
|
|
44
|
+
columnVirtualizationEnabled: computed(() => options.virtualization.value.columns),
|
|
45
|
+
totalRows: totalBodyRows,
|
|
46
|
+
visibleColumns: centerColumns,
|
|
47
|
+
sizingColumns: orderedVisibleColumns,
|
|
48
|
+
normalizedBaseRowHeight: options.normalizedBaseRowHeight,
|
|
49
|
+
resolveColumnWidth,
|
|
50
|
+
defaultColumnWidth: DEFAULT_COLUMN_WIDTH,
|
|
51
|
+
indexColumnWidth: 0,
|
|
52
|
+
flexFillOffsetWidth: effectiveIndexColumnWidth.value,
|
|
53
|
+
rowOverscan: computed(() => options.virtualization.value.rowOverscan),
|
|
54
|
+
columnOverscan: computed(() => options.virtualization.value.columnOverscan),
|
|
55
|
+
measureVisibleRowHeights: () => measureVisibleRowHeights(),
|
|
56
|
+
resolveRowHeight: rowHeightMetrics.resolveRowHeight,
|
|
57
|
+
resolveRowOffset: rowHeightMetrics.resolveRowOffset,
|
|
58
|
+
resolveRowIndexAtOffset: rowHeightMetrics.resolveRowIndexAtOffset,
|
|
59
|
+
resolveTotalRowHeight: rowHeightMetrics.resolveTotalHeight,
|
|
60
|
+
});
|
|
61
|
+
const resolveStageColumnStyle = (columnKey) => {
|
|
62
|
+
return _viewportColumnStyle(columnKey);
|
|
63
|
+
};
|
|
64
|
+
const getSelectableRowAtIndex = (rowIndex) => {
|
|
65
|
+
if (totalSelectableRows.value <= 0) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
const normalizedIndex = Math.max(0, Math.min(totalSelectableRows.value - 1, Math.trunc(rowIndex)));
|
|
69
|
+
return options.runtime.api.rows.get(normalizedIndex) ?? null;
|
|
70
|
+
};
|
|
71
|
+
const resolveSelectableRowIndexById = (rowId) => {
|
|
72
|
+
for (let rowIndex = 0; rowIndex < totalSelectableRows.value; rowIndex += 1) {
|
|
73
|
+
if (options.runtime.api.rows.get(rowIndex)?.rowId === rowId) {
|
|
74
|
+
return rowIndex;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return options.runtime.resolveBodyRowIndexById(rowId);
|
|
78
|
+
};
|
|
79
|
+
const selectableRuntime = {
|
|
80
|
+
...options.runtime,
|
|
81
|
+
getBodyRowAtIndex: getSelectableRowAtIndex,
|
|
82
|
+
resolveBodyRowIndexById: resolveSelectableRowIndexById,
|
|
83
|
+
};
|
|
84
|
+
const { rowStyle, isRowAutosizeProbe, measureVisibleRowHeights, startRowResize, autosizeRow, dispose: disposeRowSizing, } = useDataGridAppRowSizing({
|
|
85
|
+
mode: options.mode,
|
|
86
|
+
rowHeightMode: options.rowHeightMode,
|
|
87
|
+
normalizedBaseRowHeight: options.normalizedBaseRowHeight,
|
|
88
|
+
viewportRowStart,
|
|
89
|
+
bodyViewportRef,
|
|
90
|
+
runtime: options.runtime,
|
|
91
|
+
minRowHeight: MIN_ROW_HEIGHT,
|
|
92
|
+
syncViewport: () => syncViewportFromDom(),
|
|
93
|
+
});
|
|
94
|
+
const selectionController = useDataGridAppCellSelection({
|
|
95
|
+
mode: options.mode,
|
|
96
|
+
runtime: selectableRuntime,
|
|
97
|
+
totalRows: totalSelectableRows,
|
|
98
|
+
visibleColumns: orderedVisibleColumns,
|
|
99
|
+
viewportRowStart,
|
|
100
|
+
selectionSnapshot: options.selectionSnapshot,
|
|
101
|
+
selectionAnchor: options.selectionAnchor,
|
|
102
|
+
isEditingCell: (row, columnKey) => isEditingCellForSelection(row, columnKey),
|
|
103
|
+
});
|
|
104
|
+
const { normalizeRowId, normalizeCellCoord, resolveSelectionRange: resolveSelectionRangeForClipboard, resolveCurrentCellCoord: resolveCurrentCellCoordForClipboard, applySelectionRange: applyClipboardSelectionRange, applyCellSelectionByCoord, setCellSelection, clearCellSelection, isCellSelected: isCommittedCellSelected, } = selectionController;
|
|
105
|
+
const isCommittedSelectionAnchorCell = selectionController.isSelectionAnchorCell ?? (() => false);
|
|
106
|
+
const shouldHighlightCommittedSelectedCell = selectionController.shouldHighlightSelectedCell
|
|
107
|
+
?? ((rowOffset, columnIndex) => isCommittedCellSelected(rowOffset, columnIndex));
|
|
108
|
+
const isCommittedCellOnSelectionEdge = selectionController.isCellOnSelectionEdge
|
|
109
|
+
?? (() => false);
|
|
110
|
+
const selectionAnchorCell = computed(() => {
|
|
111
|
+
const snapshot = options.selectionSnapshot.value;
|
|
112
|
+
if (!snapshot || snapshot.ranges.length === 0) {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
const activeIndex = snapshot.activeRangeIndex ?? 0;
|
|
116
|
+
const anchor = snapshot.ranges[activeIndex]?.anchor ?? snapshot.ranges[0]?.anchor ?? null;
|
|
117
|
+
if (!anchor
|
|
118
|
+
|| typeof anchor.rowIndex !== "number"
|
|
119
|
+
|| typeof anchor.colIndex !== "number"
|
|
120
|
+
|| !Number.isFinite(anchor.rowIndex)
|
|
121
|
+
|| !Number.isFinite(anchor.colIndex)) {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
rowIndex: Math.trunc(anchor.rowIndex),
|
|
126
|
+
columnIndex: Math.trunc(anchor.colIndex),
|
|
127
|
+
};
|
|
128
|
+
});
|
|
129
|
+
const rowSelectionService = useDataGridTableStageRowSelection({
|
|
130
|
+
runtime: options.runtime,
|
|
131
|
+
rowSelectionColumn,
|
|
132
|
+
orderedVisibleColumns,
|
|
133
|
+
displayRows,
|
|
134
|
+
rowSelectionSnapshot: rowSelectionSnapshotRef,
|
|
135
|
+
viewportRowStart,
|
|
136
|
+
selectionAnchorCell,
|
|
137
|
+
applySelectionRange: applyClipboardSelectionRange,
|
|
138
|
+
});
|
|
139
|
+
const { readRowSelectionCell, readRowSelectionDisplayCell, toggleRowCheckboxSelected, } = rowSelectionService;
|
|
140
|
+
const stageIndexColumnStyle = computed(() => {
|
|
141
|
+
const width = `${effectiveIndexColumnWidth.value}px`;
|
|
142
|
+
return {
|
|
143
|
+
...indexColumnStyle.value,
|
|
144
|
+
width,
|
|
145
|
+
minWidth: width,
|
|
146
|
+
maxWidth: width,
|
|
147
|
+
};
|
|
148
|
+
});
|
|
149
|
+
const historyService = useDataGridTableStageHistory({
|
|
150
|
+
runtime: options.runtime,
|
|
151
|
+
cloneRowData: options.cloneRowData,
|
|
152
|
+
syncViewport: () => syncViewportFromDom(),
|
|
153
|
+
history: options.history,
|
|
154
|
+
});
|
|
155
|
+
const { captureHistorySnapshot, recordHistoryIntentTransaction, canUndoHistory, canRedoHistory, runHistoryAction, } = historyService;
|
|
156
|
+
const { rowIndexLabel, readCell, readDisplayCell, rowClass, toggleGroupRow, } = useDataGridAppRowPresentation({
|
|
157
|
+
mode: options.mode,
|
|
158
|
+
runtime: options.runtime,
|
|
159
|
+
viewportRowStart,
|
|
160
|
+
firstColumnKey: options.firstColumnKey,
|
|
161
|
+
});
|
|
162
|
+
const cellIoService = useDataGridTableStageCellIo({
|
|
163
|
+
runtime: options.runtime,
|
|
164
|
+
viewportRowStart,
|
|
165
|
+
isRowSelectionColumnKey,
|
|
166
|
+
isRowSelectionColumn,
|
|
167
|
+
isCellEditableByKey,
|
|
168
|
+
readRowSelectionCell,
|
|
169
|
+
readRowSelectionDisplayCell,
|
|
170
|
+
readCell,
|
|
171
|
+
readDisplayCell,
|
|
172
|
+
toggleRowCheckboxSelected,
|
|
173
|
+
captureHistorySnapshot,
|
|
174
|
+
recordHistoryIntentTransaction,
|
|
175
|
+
syncViewport: () => syncViewportFromDom(),
|
|
176
|
+
});
|
|
177
|
+
const { readStageCell, } = cellIoService;
|
|
178
|
+
const clipboard = useDataGridAppClipboard({
|
|
179
|
+
mode: options.mode,
|
|
180
|
+
runtime: selectableRuntime,
|
|
181
|
+
totalRows: totalSelectableRows,
|
|
182
|
+
visibleColumns: orderedVisibleColumns,
|
|
183
|
+
viewportRowStart,
|
|
184
|
+
resolveSelectionRange: resolveSelectionRangeForClipboard,
|
|
185
|
+
resolveCurrentCellCoord: resolveCurrentCellCoordForClipboard,
|
|
186
|
+
applySelectionRange: applyClipboardSelectionRange,
|
|
187
|
+
clearCellSelection,
|
|
188
|
+
captureRowsSnapshot: captureHistorySnapshot,
|
|
189
|
+
recordEditTransaction: beforeSnapshot => {
|
|
190
|
+
recordHistoryIntentTransaction({
|
|
191
|
+
intent: "edit",
|
|
192
|
+
label: "Cell edit",
|
|
193
|
+
}, beforeSnapshot);
|
|
194
|
+
},
|
|
195
|
+
readCell: (row, columnKey) => readStageCell(row, columnKey),
|
|
196
|
+
readClipboardCell: options.readClipboardCell
|
|
197
|
+
? (row, columnKey) => options.readClipboardCell?.(row, columnKey) ?? ""
|
|
198
|
+
: undefined,
|
|
199
|
+
isCellEditable: isCellEditableByKey,
|
|
200
|
+
syncViewport: () => syncViewportFromDom(),
|
|
201
|
+
applyClipboardEdits: options.applyClipboardEdits,
|
|
202
|
+
buildFillMatrixFromRange: options.buildFillMatrixFromRange,
|
|
203
|
+
});
|
|
204
|
+
const { normalizeClipboardRange, applyClipboardEdits, rangesEqual, buildFillMatrixFromRange, clearPendingClipboardOperation, copySelectedCells, pasteSelectedCells, cutSelectedCells, isCellInPendingClipboardRange, isCellOnPendingClipboardEdge, } = clipboard;
|
|
205
|
+
const { ensureKeyboardActiveCellVisible, } = useDataGridAppActiveCellViewport({
|
|
206
|
+
bodyViewportRef,
|
|
207
|
+
visibleColumns: orderedVisibleColumns,
|
|
208
|
+
resolveColumnWidth,
|
|
209
|
+
normalizedBaseRowHeight: options.normalizedBaseRowHeight,
|
|
210
|
+
resolveRowHeight: rowHeightMetrics.resolveRowHeight,
|
|
211
|
+
resolveRowOffset: rowHeightMetrics.resolveRowOffset,
|
|
212
|
+
indexColumnWidth: effectiveIndexColumnWidth.value,
|
|
213
|
+
defaultColumnWidth: DEFAULT_COLUMN_WIDTH,
|
|
214
|
+
syncViewport: () => syncViewportFromDom(),
|
|
215
|
+
});
|
|
216
|
+
const { editingCell, editingCellValue, editingCellInitialFilter, editingCellOpenOnMount, isEditingCell, startInlineEdit, commitInlineEdit, cancelInlineEdit, handleEditorKeydown, } = useDataGridAppInlineEditing({
|
|
217
|
+
mode: options.mode,
|
|
218
|
+
bodyViewportRef,
|
|
219
|
+
visibleColumns: orderedVisibleColumns,
|
|
220
|
+
totalRows: totalSelectableRows,
|
|
221
|
+
runtime: selectableRuntime,
|
|
222
|
+
readCell: (row, columnKey) => readStageCell(row, columnKey),
|
|
223
|
+
resolveRowIndexById: resolveSelectableRowIndexById,
|
|
224
|
+
applyCellSelection: coord => {
|
|
225
|
+
applyCellSelectionByCoord(coord, false);
|
|
226
|
+
},
|
|
227
|
+
ensureActiveCellVisible: (rowIndex, columnIndex) => {
|
|
228
|
+
ensureKeyboardActiveCellVisible(rowIndex, columnIndex);
|
|
229
|
+
},
|
|
230
|
+
isCellEditable: isCellEditableByKey,
|
|
231
|
+
captureRowsSnapshot: captureHistorySnapshot,
|
|
232
|
+
recordEditTransaction: beforeSnapshot => {
|
|
233
|
+
recordHistoryIntentTransaction({
|
|
234
|
+
intent: "edit",
|
|
235
|
+
label: "Cell edit",
|
|
236
|
+
}, beforeSnapshot);
|
|
237
|
+
},
|
|
238
|
+
});
|
|
239
|
+
isEditingCellForSelection = isEditingCell;
|
|
240
|
+
const editingCellRef = computed(() => editingCell.value);
|
|
241
|
+
const interactionControllerOptions = {
|
|
242
|
+
mode: options.mode,
|
|
243
|
+
runtime: selectableRuntime,
|
|
244
|
+
totalRows: totalSelectableRows,
|
|
245
|
+
visibleColumns: orderedVisibleColumns,
|
|
246
|
+
viewportRowStart,
|
|
247
|
+
selectionSnapshot: options.selectionSnapshot,
|
|
248
|
+
bodyViewportRef,
|
|
249
|
+
indexColumnWidth: effectiveIndexColumnWidth.value,
|
|
250
|
+
resolveColumnWidth,
|
|
251
|
+
resolveRowHeight: rowHeightMetrics.resolveRowHeight,
|
|
252
|
+
resolveRowIndexAtOffset: rowHeightMetrics.resolveRowIndexAtOffset,
|
|
253
|
+
normalizeRowId,
|
|
254
|
+
normalizeCellCoord,
|
|
255
|
+
resolveSelectionRange: resolveSelectionRangeForClipboard,
|
|
256
|
+
applySelectionRange: applyClipboardSelectionRange,
|
|
257
|
+
applyCellSelectionByCoord,
|
|
258
|
+
setCellSelection,
|
|
259
|
+
clearCellSelection,
|
|
260
|
+
readCell: (row, columnKey) => readStageCell(row, columnKey),
|
|
261
|
+
isCellEditable: isCellEditableByKey,
|
|
262
|
+
cloneRowData: options.cloneRowData,
|
|
263
|
+
resolveRowIndexById: resolveSelectableRowIndexById,
|
|
264
|
+
captureRowsSnapshot: captureHistorySnapshot,
|
|
265
|
+
recordIntentTransaction: (descriptor, beforeSnapshot) => {
|
|
266
|
+
recordHistoryIntentTransaction(descriptor, beforeSnapshot);
|
|
267
|
+
},
|
|
268
|
+
clearPendingClipboardOperation,
|
|
269
|
+
clearExternalPendingClipboardOperation: options.clearExternalPendingClipboardOperation,
|
|
270
|
+
copySelectedCells,
|
|
271
|
+
pasteSelectedCells,
|
|
272
|
+
cutSelectedCells,
|
|
273
|
+
normalizeClipboardRange,
|
|
274
|
+
applyClipboardEdits,
|
|
275
|
+
rangesEqual,
|
|
276
|
+
buildFillMatrixFromRange,
|
|
277
|
+
applyRangeMove: options.applyRangeMove,
|
|
278
|
+
syncViewport: () => syncViewportFromDom(),
|
|
279
|
+
editingCell: editingCellRef,
|
|
280
|
+
startInlineEdit,
|
|
281
|
+
commitInlineEdit,
|
|
282
|
+
canUndo: canUndoHistory,
|
|
283
|
+
canRedo: canRedoHistory,
|
|
284
|
+
runHistoryAction,
|
|
285
|
+
ensureKeyboardActiveCellVisible,
|
|
286
|
+
isContextMenuVisible: options.isContextMenuVisible,
|
|
287
|
+
closeContextMenu: options.closeContextMenu,
|
|
288
|
+
openContextMenuFromCurrentCell: options.openContextMenuFromCurrentCell,
|
|
289
|
+
runRowIndexKeyboardAction: options.runRowIndexKeyboardAction,
|
|
290
|
+
handleToggleCellAction: (row, rowIndex, columnIndex, column) => {
|
|
291
|
+
if (!isRowSelectionColumn(column)) {
|
|
292
|
+
return false;
|
|
293
|
+
}
|
|
294
|
+
void rowIndex;
|
|
295
|
+
void columnIndex;
|
|
296
|
+
toggleRowCheckboxSelected(row);
|
|
297
|
+
return true;
|
|
298
|
+
},
|
|
299
|
+
};
|
|
300
|
+
const interactionController = (useDataGridAppInteractionController(interactionControllerOptions));
|
|
301
|
+
const { isPointerSelectingCells, isFillDragging, fillPreviewRange, lastAppliedFill, isRangeMoving, selectionRange: interactionSelectionRange, rangeMovePreviewRange, stopPointerSelection, stopFillSelection, startFillHandleDrag, startFillHandleDoubleClick, applyLastFillBehavior, handleCellMouseDown, handleCellKeydown, handleRowIndexKeydown, handleWindowMouseMove: handleInteractionWindowMouseMove, handleWindowMouseUp: handleInteractionWindowMouseUp, isCellInFillPreview, isFillHandleCell, clearSelectedCells, dispose: disposeInteractionController, } = interactionController;
|
|
302
|
+
const viewportKeyboardService = useDataGridTableStageViewportKeyboard({
|
|
303
|
+
runtime: selectableRuntime,
|
|
304
|
+
selectionSnapshot: options.selectionSnapshot,
|
|
305
|
+
totalRows: totalSelectableRows,
|
|
306
|
+
orderedVisibleColumns,
|
|
307
|
+
viewportRowStart,
|
|
308
|
+
applySelectionRange: applyClipboardSelectionRange,
|
|
309
|
+
handleCellKeydown,
|
|
310
|
+
});
|
|
311
|
+
const { isColumnResizing, startResize, handleResizeDoubleClick, applyColumnResizeFromPointer, stopColumnResize, dispose: disposeHeaderResize, } = useDataGridAppHeaderResize({
|
|
312
|
+
visibleColumns: orderedVisibleColumns,
|
|
313
|
+
rows: options.rows,
|
|
314
|
+
persistColumnWidth: (columnKey, width) => {
|
|
315
|
+
options.runtime.api.columns.setWidth(columnKey, width);
|
|
316
|
+
},
|
|
317
|
+
defaultColumnWidth: DEFAULT_COLUMN_WIDTH,
|
|
318
|
+
minColumnWidth: MIN_COLUMN_WIDTH,
|
|
319
|
+
autoSizeSampleLimit: AUTO_RESIZE_SAMPLE_LIMIT,
|
|
320
|
+
autoSizeCharWidth: 7.2,
|
|
321
|
+
autoSizeHorizontalPadding: 42,
|
|
322
|
+
autoSizeMaxWidth: 640,
|
|
323
|
+
isFillDragging: () => isFillDragging.value,
|
|
324
|
+
stopFillSelection: () => {
|
|
325
|
+
stopFillSelection(false);
|
|
326
|
+
},
|
|
327
|
+
isDragSelecting: () => isPointerSelectingCells.value,
|
|
328
|
+
stopDragSelection: () => {
|
|
329
|
+
stopPointerSelection();
|
|
330
|
+
},
|
|
331
|
+
readCellText: (row, columnKey) => {
|
|
332
|
+
const value = row[columnKey];
|
|
333
|
+
return value == null ? "" : String(value);
|
|
334
|
+
},
|
|
335
|
+
});
|
|
336
|
+
const visualSelectionService = useDataGridTableStageVisualSelection({
|
|
337
|
+
mode: options.mode,
|
|
338
|
+
viewportRowStart,
|
|
339
|
+
selectionAnchorCell,
|
|
340
|
+
fillPreviewRange,
|
|
341
|
+
isFillDragging,
|
|
342
|
+
interactionSelectionRange,
|
|
343
|
+
resolveCommittedSelectionRange: resolveSelectionRangeForClipboard,
|
|
344
|
+
isCommittedSelectionAnchorCell,
|
|
345
|
+
isCommittedCellSelected,
|
|
346
|
+
shouldHighlightCommittedSelectedCell,
|
|
347
|
+
isCommittedCellOnSelectionEdge,
|
|
348
|
+
});
|
|
349
|
+
const { selectionRange } = visualSelectionService;
|
|
350
|
+
const fillActionService = useDataGridTableStageFillAction({
|
|
351
|
+
lastAppliedFill,
|
|
352
|
+
selectionRange,
|
|
353
|
+
isFillDragging,
|
|
354
|
+
});
|
|
355
|
+
const scrollSyncService = useDataGridTableStageScrollSync({
|
|
356
|
+
bodyViewportRef,
|
|
357
|
+
isColumnResizing,
|
|
358
|
+
applyColumnResizeFromPointer,
|
|
359
|
+
stopColumnResize,
|
|
360
|
+
handleInteractionWindowMouseMove,
|
|
361
|
+
handleInteractionWindowMouseUp,
|
|
362
|
+
syncViewport: syncViewportFromDom,
|
|
363
|
+
});
|
|
364
|
+
const stageServices = {
|
|
365
|
+
columns: columnService,
|
|
366
|
+
rowSelection: rowSelectionService,
|
|
367
|
+
history: historyService,
|
|
368
|
+
cellIo: cellIoService,
|
|
369
|
+
viewportKeyboard: viewportKeyboardService,
|
|
370
|
+
visualSelection: visualSelectionService,
|
|
371
|
+
fillAction: fillActionService,
|
|
372
|
+
scrollSync: scrollSyncService,
|
|
373
|
+
};
|
|
374
|
+
const { tableStageProps, tableStageContext, } = useDataGridTableStageBindings({
|
|
375
|
+
mode: options.mode,
|
|
376
|
+
rowHeightMode: options.rowHeightMode,
|
|
377
|
+
visibleColumns: orderedVisibleColumns,
|
|
378
|
+
renderedColumns,
|
|
379
|
+
displayRows,
|
|
380
|
+
pinnedBottomRows,
|
|
381
|
+
sourceRows: options.sourceRows ?? options.rows,
|
|
382
|
+
showRowIndex,
|
|
383
|
+
rowHover: computed(() => options.rowHover?.value === true),
|
|
384
|
+
stripedRows: computed(() => options.stripedRows?.value === true),
|
|
385
|
+
columnFilterTextByKey: options.columnFilterTextByKey,
|
|
386
|
+
gridContentStyle,
|
|
387
|
+
mainTrackStyle,
|
|
388
|
+
indexColumnStyle: stageIndexColumnStyle,
|
|
389
|
+
topSpacerHeight,
|
|
390
|
+
bottomSpacerHeight,
|
|
391
|
+
viewportRowStart,
|
|
392
|
+
columnWindowStart: viewportColumnStart,
|
|
393
|
+
leftColumnSpacerWidth,
|
|
394
|
+
rightColumnSpacerWidth,
|
|
395
|
+
editingCellValueRef: editingCellValue,
|
|
396
|
+
editingCellInitialFilter,
|
|
397
|
+
editingCellOpenOnMount,
|
|
398
|
+
selectionRange,
|
|
399
|
+
selectionAnchorCell,
|
|
400
|
+
fillPreviewRange,
|
|
401
|
+
rangeMovePreviewRange,
|
|
402
|
+
isFillDragging,
|
|
403
|
+
isRangeMoving,
|
|
404
|
+
headerViewportRef,
|
|
405
|
+
bodyViewportRef,
|
|
406
|
+
columnStyle: resolveStageColumnStyle,
|
|
407
|
+
toggleSortForColumn: options.toggleSortForColumn,
|
|
408
|
+
sortIndicator: options.sortIndicator,
|
|
409
|
+
setColumnFilterText: options.setColumnFilterText,
|
|
410
|
+
columnMenuEnabled: options.columnMenuEnabled,
|
|
411
|
+
columnMenuValueFilterEnabled: options.columnMenuValueFilterEnabled,
|
|
412
|
+
columnMenuValueFilterRowLimit: options.columnMenuValueFilterRowLimit,
|
|
413
|
+
columnMenuMaxFilterValues: options.columnMenuMaxFilterValues,
|
|
414
|
+
resolveColumnMenuItems: options.resolveColumnMenuItems,
|
|
415
|
+
resolveColumnMenuDisabledItems: options.resolveColumnMenuDisabledItems,
|
|
416
|
+
resolveColumnMenuDisabledReasons: options.resolveColumnMenuDisabledReasons,
|
|
417
|
+
resolveColumnMenuLabels: options.resolveColumnMenuLabels,
|
|
418
|
+
resolveColumnMenuActionOptions: options.resolveColumnMenuActionOptions,
|
|
419
|
+
isColumnFilterActive: options.isColumnFilterActive,
|
|
420
|
+
isColumnGrouped: options.isColumnGrouped,
|
|
421
|
+
resolveColumnGroupOrder: options.resolveColumnGroupOrder,
|
|
422
|
+
resolveColumnMenuSortDirection: options.resolveColumnMenuSortDirection,
|
|
423
|
+
resolveColumnMenuSelectedTokens: options.resolveColumnMenuSelectedTokens,
|
|
424
|
+
applyColumnMenuSort: options.applyColumnMenuSort,
|
|
425
|
+
applyColumnMenuPin: options.applyColumnMenuPin,
|
|
426
|
+
applyColumnMenuGroupBy: options.applyColumnMenuGroupBy,
|
|
427
|
+
applyColumnMenuFilter: options.applyColumnMenuFilter,
|
|
428
|
+
clearColumnMenuFilter: options.clearColumnMenuFilter,
|
|
429
|
+
handleHeaderWheel: stageServices.scrollSync.handleHeaderWheel,
|
|
430
|
+
handleHeaderScroll: stageServices.scrollSync.handleHeaderScroll,
|
|
431
|
+
handleViewportScroll,
|
|
432
|
+
handleViewportKeydown: stageServices.viewportKeyboard.handleViewportKeydown,
|
|
433
|
+
rowClass,
|
|
434
|
+
isRowAutosizeProbe,
|
|
435
|
+
rowStyle,
|
|
436
|
+
isRowInPendingClipboardCut: options.isRowInPendingClipboardCut,
|
|
437
|
+
isRowFocused: stageServices.rowSelection.isRowFocused,
|
|
438
|
+
isRowCheckboxSelected: stageServices.rowSelection.isRowCheckboxSelected,
|
|
439
|
+
allVisibleRowsSelected: stageServices.rowSelection.areAllVisibleRowsSelected,
|
|
440
|
+
someVisibleRowsSelected: stageServices.rowSelection.areSomeVisibleRowsSelected,
|
|
441
|
+
handleRowClick: stageServices.rowSelection.focusRow,
|
|
442
|
+
handleRowIndexClick: stageServices.rowSelection.selectRowRange,
|
|
443
|
+
handleRowIndexKeydown,
|
|
444
|
+
handleToggleAllVisibleRows: stageServices.rowSelection.toggleVisibleRowsSelected,
|
|
445
|
+
toggleGroupRow,
|
|
446
|
+
rowIndexLabel,
|
|
447
|
+
startResize,
|
|
448
|
+
handleResizeDoubleClick,
|
|
449
|
+
startRowResize,
|
|
450
|
+
autosizeRow,
|
|
451
|
+
isCellSelected: stageServices.visualSelection.isCellSelected,
|
|
452
|
+
isSelectionAnchorCell: stageServices.visualSelection.isSelectionAnchorCell,
|
|
453
|
+
shouldHighlightSelectedCell: stageServices.visualSelection.shouldHighlightSelectedCell,
|
|
454
|
+
isCellOnSelectionEdge: stageServices.visualSelection.isCellOnSelectionEdge,
|
|
455
|
+
isCellInFillPreview,
|
|
456
|
+
isCellInPendingClipboardRange,
|
|
457
|
+
isCellOnPendingClipboardEdge,
|
|
458
|
+
isEditingCell,
|
|
459
|
+
isCellEditable: (row, rowOffset, column, columnIndex) => {
|
|
460
|
+
void columnIndex;
|
|
461
|
+
return isCellEditable(row, viewportRowStart.value + rowOffset, column);
|
|
462
|
+
},
|
|
463
|
+
handleCellMouseDown,
|
|
464
|
+
handleCellClick: stageServices.cellIo.handleCellClick,
|
|
465
|
+
handleCellKeydown,
|
|
466
|
+
startInlineEdit,
|
|
467
|
+
isFillHandleCell,
|
|
468
|
+
startFillHandleDrag,
|
|
469
|
+
startFillHandleDoubleClick,
|
|
470
|
+
fillActionAnchorCell: stageServices.fillAction.fillActionAnchorCell,
|
|
471
|
+
fillActionBehavior: stageServices.fillAction.fillActionBehavior,
|
|
472
|
+
applyFillActionBehavior: applyLastFillBehavior,
|
|
473
|
+
handleEditorKeydown,
|
|
474
|
+
commitInlineEdit,
|
|
475
|
+
cancelInlineEdit,
|
|
476
|
+
readCell: stageServices.cellIo.readStageCell,
|
|
477
|
+
readDisplayCell: stageServices.cellIo.readStageDisplayCell,
|
|
478
|
+
});
|
|
479
|
+
useDataGridAppRuntimeSync({
|
|
480
|
+
mode: options.mode,
|
|
481
|
+
rows: options.rows,
|
|
482
|
+
runtime: options.runtime,
|
|
483
|
+
totalRows: totalBodyRows,
|
|
484
|
+
rowVersion: options.rowVersion,
|
|
485
|
+
rowHeightMode: options.rowHeightMode,
|
|
486
|
+
normalizedBaseRowHeight: options.normalizedBaseRowHeight,
|
|
487
|
+
syncSelectionSnapshotFromRuntime: options.syncSelectionSnapshotFromRuntime,
|
|
488
|
+
syncRowSelectionSnapshotFromRuntime,
|
|
489
|
+
syncViewport: syncViewportFromDom,
|
|
490
|
+
scheduleViewportSync,
|
|
491
|
+
measureVisibleRowHeights,
|
|
492
|
+
applyRowHeightSettings: options.applyRowHeightSettings,
|
|
493
|
+
});
|
|
494
|
+
useDataGridAppViewportLifecycle({
|
|
495
|
+
bodyViewportRef,
|
|
496
|
+
syncViewport: syncViewportFromDom,
|
|
497
|
+
handleWindowMouseMove: stageServices.scrollSync.handleWindowMouseMove,
|
|
498
|
+
handleWindowMouseUp: stageServices.scrollSync.handleWindowMouseUp,
|
|
499
|
+
cancelScheduledViewportSync,
|
|
500
|
+
onAfterMount: () => {
|
|
501
|
+
options.syncSelectionSnapshotFromRuntime();
|
|
502
|
+
syncRowSelectionSnapshotFromRuntime();
|
|
503
|
+
void nextTick(() => {
|
|
504
|
+
options.applyRowHeightSettings();
|
|
505
|
+
syncViewportFromDom();
|
|
506
|
+
});
|
|
507
|
+
},
|
|
508
|
+
dispose: [
|
|
509
|
+
disposeRowSizing,
|
|
510
|
+
disposeHeaderResize,
|
|
511
|
+
disposeInteractionController,
|
|
512
|
+
stageServices.history.disposeIntentHistory,
|
|
513
|
+
],
|
|
514
|
+
});
|
|
515
|
+
return {
|
|
516
|
+
tableStageProps,
|
|
517
|
+
tableStageContext,
|
|
518
|
+
syncViewportFromDom,
|
|
519
|
+
copySelectedCells,
|
|
520
|
+
pasteSelectedCells,
|
|
521
|
+
cutSelectedCells,
|
|
522
|
+
clearSelectedCells,
|
|
523
|
+
captureHistorySnapshot,
|
|
524
|
+
recordHistoryIntentTransaction,
|
|
525
|
+
};
|
|
526
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Ref } from "vue";
|
|
2
|
+
export interface UseDataGridTableStageScrollSyncOptions {
|
|
3
|
+
bodyViewportRef: Ref<HTMLElement | null>;
|
|
4
|
+
isColumnResizing: Ref<boolean>;
|
|
5
|
+
applyColumnResizeFromPointer: (clientX: number) => void;
|
|
6
|
+
stopColumnResize: () => void;
|
|
7
|
+
handleInteractionWindowMouseMove: (event: MouseEvent) => void;
|
|
8
|
+
handleInteractionWindowMouseUp: () => void;
|
|
9
|
+
syncViewport: () => void;
|
|
10
|
+
}
|
|
11
|
+
export interface UseDataGridTableStageScrollSyncResult {
|
|
12
|
+
handleWindowMouseMove: (event: MouseEvent) => void;
|
|
13
|
+
handleHeaderWheel: (event: WheelEvent) => void;
|
|
14
|
+
handleHeaderScroll: (event: Event) => void;
|
|
15
|
+
handleWindowMouseUp: () => void;
|
|
16
|
+
}
|
|
17
|
+
export declare function useDataGridTableStageScrollSync(options: UseDataGridTableStageScrollSyncOptions): UseDataGridTableStageScrollSyncResult;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export function useDataGridTableStageScrollSync(options) {
|
|
2
|
+
const handleWindowMouseMove = (event) => {
|
|
3
|
+
if (options.isColumnResizing.value) {
|
|
4
|
+
options.applyColumnResizeFromPointer(event.clientX);
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
options.handleInteractionWindowMouseMove(event);
|
|
8
|
+
};
|
|
9
|
+
const handleHeaderWheel = (event) => {
|
|
10
|
+
const bodyViewport = options.bodyViewportRef.value;
|
|
11
|
+
if (!bodyViewport) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const horizontalDelta = Math.abs(event.deltaX) > 0 ? event.deltaX : (event.shiftKey ? event.deltaY : 0);
|
|
15
|
+
const verticalDelta = horizontalDelta === 0 ? event.deltaY : 0;
|
|
16
|
+
if (horizontalDelta === 0 && verticalDelta === 0) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
event.preventDefault();
|
|
20
|
+
if (horizontalDelta !== 0) {
|
|
21
|
+
bodyViewport.scrollLeft += horizontalDelta;
|
|
22
|
+
}
|
|
23
|
+
if (verticalDelta !== 0) {
|
|
24
|
+
bodyViewport.scrollTop += verticalDelta;
|
|
25
|
+
}
|
|
26
|
+
options.syncViewport();
|
|
27
|
+
};
|
|
28
|
+
const handleHeaderScroll = (event) => {
|
|
29
|
+
const headerViewport = event.target;
|
|
30
|
+
const bodyViewport = options.bodyViewportRef.value;
|
|
31
|
+
if (!headerViewport || !bodyViewport) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (bodyViewport.scrollLeft !== headerViewport.scrollLeft) {
|
|
35
|
+
bodyViewport.scrollLeft = headerViewport.scrollLeft;
|
|
36
|
+
}
|
|
37
|
+
options.syncViewport();
|
|
38
|
+
};
|
|
39
|
+
const handleWindowMouseUp = () => {
|
|
40
|
+
options.stopColumnResize();
|
|
41
|
+
options.handleInteractionWindowMouseUp();
|
|
42
|
+
};
|
|
43
|
+
return {
|
|
44
|
+
handleWindowMouseMove,
|
|
45
|
+
handleHeaderWheel,
|
|
46
|
+
handleHeaderScroll,
|
|
47
|
+
handleWindowMouseUp,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ComputedRef, Ref } from "vue";
|
|
2
|
+
import type { DataGridColumnSnapshot, DataGridSelectionSnapshot } from "@affino/datagrid-vue";
|
|
3
|
+
export interface UseDataGridTableStageViewportKeyboardOptions<TRow extends Record<string, unknown>> {
|
|
4
|
+
runtime: Pick<import("@affino/datagrid-vue").UseDataGridRuntimeResult<TRow>, "getBodyRowAtIndex">;
|
|
5
|
+
selectionSnapshot: Ref<DataGridSelectionSnapshot | null>;
|
|
6
|
+
totalRows: Ref<number>;
|
|
7
|
+
orderedVisibleColumns: ComputedRef<readonly DataGridColumnSnapshot[]>;
|
|
8
|
+
viewportRowStart: Ref<number>;
|
|
9
|
+
applySelectionRange: (range: {
|
|
10
|
+
startRow: number;
|
|
11
|
+
endRow: number;
|
|
12
|
+
startColumn: number;
|
|
13
|
+
endColumn: number;
|
|
14
|
+
}) => void;
|
|
15
|
+
handleCellKeydown: (event: KeyboardEvent, row: import("@affino/datagrid-vue").DataGridRowNode<TRow>, rowOffset: number, columnIndex: number) => void;
|
|
16
|
+
}
|
|
17
|
+
export interface UseDataGridTableStageViewportKeyboardResult {
|
|
18
|
+
handleViewportKeydown: (event: KeyboardEvent) => void;
|
|
19
|
+
}
|
|
20
|
+
export declare function useDataGridTableStageViewportKeyboard<TRow extends Record<string, unknown>>(options: UseDataGridTableStageViewportKeyboardOptions<TRow>): UseDataGridTableStageViewportKeyboardResult;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export function useDataGridTableStageViewportKeyboard(options) {
|
|
2
|
+
const isViewportOwnedKeyboardEvent = (event) => {
|
|
3
|
+
if (event.ctrlKey || event.metaKey || event.altKey) {
|
|
4
|
+
return false;
|
|
5
|
+
}
|
|
6
|
+
return (event.key.startsWith("Arrow")
|
|
7
|
+
|| event.key === "Home"
|
|
8
|
+
|| event.key === "End"
|
|
9
|
+
|| event.key === "PageUp"
|
|
10
|
+
|| event.key === "PageDown"
|
|
11
|
+
|| event.key === "Tab"
|
|
12
|
+
|| event.key === "Enter"
|
|
13
|
+
|| event.key === " "
|
|
14
|
+
|| event.key === "Spacebar"
|
|
15
|
+
|| event.key === "F2"
|
|
16
|
+
|| event.key === "Escape"
|
|
17
|
+
|| event.key.length === 1);
|
|
18
|
+
};
|
|
19
|
+
const isViewportSelectAllKeyboardEvent = (event) => {
|
|
20
|
+
return (event.ctrlKey || event.metaKey)
|
|
21
|
+
&& !event.altKey
|
|
22
|
+
&& !event.shiftKey
|
|
23
|
+
&& event.key.toLowerCase() === "a";
|
|
24
|
+
};
|
|
25
|
+
const selectAllVisibleCells = () => {
|
|
26
|
+
const lastRowIndex = options.totalRows.value - 1;
|
|
27
|
+
const lastColumnIndex = options.orderedVisibleColumns.value.length - 1;
|
|
28
|
+
if (lastRowIndex < 0 || lastColumnIndex < 0) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
options.applySelectionRange({
|
|
32
|
+
startRow: 0,
|
|
33
|
+
endRow: lastRowIndex,
|
|
34
|
+
startColumn: 0,
|
|
35
|
+
endColumn: lastColumnIndex,
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
const handleViewportKeydown = (event) => {
|
|
39
|
+
if (isViewportOwnedKeyboardEvent(event) || isViewportSelectAllKeyboardEvent(event)) {
|
|
40
|
+
event.preventDefault();
|
|
41
|
+
}
|
|
42
|
+
const activeCell = options.selectionSnapshot.value?.activeCell;
|
|
43
|
+
if (!activeCell) {
|
|
44
|
+
if (isViewportSelectAllKeyboardEvent(event)) {
|
|
45
|
+
selectAllVisibleCells();
|
|
46
|
+
}
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const row = options.runtime.getBodyRowAtIndex(activeCell.rowIndex);
|
|
50
|
+
if (!row) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
options.handleCellKeydown(event, row, activeCell.rowIndex - options.viewportRowStart.value, activeCell.colIndex);
|
|
54
|
+
};
|
|
55
|
+
return {
|
|
56
|
+
handleViewportKeydown,
|
|
57
|
+
};
|
|
58
|
+
}
|