@uipath/apollo-react 7.11.3 → 7.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/canvas/components/CanvasDiffView/CanvasDiffView.cjs +6 -6
- package/dist/canvas/components/CanvasDiffView/CanvasDiffView.js +6 -6
- package/dist/canvas/components/JsonTree/JsonTree.cjs +2 -2
- package/dist/canvas/components/JsonTree/JsonTree.js +2 -2
- package/dist/canvas/components/NodeVariablesPanel/NodeVariablesPanel.cjs +6 -6
- package/dist/canvas/components/NodeVariablesPanel/NodeVariablesPanel.js +6 -6
- package/dist/canvas/components/StageNode/tasks/TaskContent.cjs +1 -1
- package/dist/canvas/components/StageNode/tasks/TaskContent.js +1 -1
- package/dist/canvas/locales/de.cjs +1 -1
- package/dist/canvas/locales/de.d.ts.map +1 -1
- package/dist/canvas/locales/de.js +1 -1
- package/dist/canvas/locales/en.cjs +1 -1
- package/dist/canvas/locales/en.d.ts.map +1 -1
- package/dist/canvas/locales/en.js +1 -1
- package/dist/canvas/locales/es-MX.cjs +1 -1
- package/dist/canvas/locales/es-MX.d.ts.map +1 -1
- package/dist/canvas/locales/es-MX.js +1 -1
- package/dist/canvas/locales/es.cjs +1 -1
- package/dist/canvas/locales/es.d.ts.map +1 -1
- package/dist/canvas/locales/es.js +1 -1
- package/dist/canvas/locales/fr.cjs +1 -1
- package/dist/canvas/locales/fr.d.ts.map +1 -1
- package/dist/canvas/locales/fr.js +1 -1
- package/dist/canvas/locales/ja.cjs +1 -1
- package/dist/canvas/locales/ja.d.ts.map +1 -1
- package/dist/canvas/locales/ja.js +1 -1
- package/dist/canvas/locales/ko.cjs +1 -1
- package/dist/canvas/locales/ko.d.ts.map +1 -1
- package/dist/canvas/locales/ko.js +1 -1
- package/dist/canvas/locales/pt-BR.cjs +1 -1
- package/dist/canvas/locales/pt-BR.d.ts.map +1 -1
- package/dist/canvas/locales/pt-BR.js +1 -1
- package/dist/canvas/locales/pt.cjs +1 -1
- package/dist/canvas/locales/pt.d.ts.map +1 -1
- package/dist/canvas/locales/pt.js +1 -1
- package/dist/canvas/locales/ro.cjs +1 -1
- package/dist/canvas/locales/ro.d.ts.map +1 -1
- package/dist/canvas/locales/ro.js +1 -1
- package/dist/canvas/locales/ru.cjs +1 -1
- package/dist/canvas/locales/ru.d.ts.map +1 -1
- package/dist/canvas/locales/ru.js +1 -1
- package/dist/canvas/locales/tr.cjs +1 -1
- package/dist/canvas/locales/tr.d.ts.map +1 -1
- package/dist/canvas/locales/tr.js +1 -1
- package/dist/canvas/locales/zh-CN.cjs +1 -1
- package/dist/canvas/locales/zh-CN.d.ts.map +1 -1
- package/dist/canvas/locales/zh-CN.js +1 -1
- package/dist/canvas/locales/zh-TW.cjs +1 -1
- package/dist/canvas/locales/zh-TW.d.ts.map +1 -1
- package/dist/canvas/locales/zh-TW.js +1 -1
- package/dist/canvas/styles/tailwind.canvas.css +1 -1
- package/dist/chat/locales/de.cjs +1 -1
- package/dist/chat/locales/de.d.ts.map +1 -1
- package/dist/chat/locales/de.js +1 -1
- package/dist/chat/locales/en.cjs +1 -1
- package/dist/chat/locales/en.d.ts.map +1 -1
- package/dist/chat/locales/en.js +1 -1
- package/dist/chat/locales/es-MX.cjs +1 -1
- package/dist/chat/locales/es-MX.d.ts.map +1 -1
- package/dist/chat/locales/es-MX.js +1 -1
- package/dist/chat/locales/es.cjs +1 -1
- package/dist/chat/locales/es.d.ts.map +1 -1
- package/dist/chat/locales/es.js +1 -1
- package/dist/chat/locales/fr.cjs +1 -1
- package/dist/chat/locales/fr.d.ts.map +1 -1
- package/dist/chat/locales/fr.js +1 -1
- package/dist/chat/locales/ja.cjs +1 -1
- package/dist/chat/locales/ja.d.ts.map +1 -1
- package/dist/chat/locales/ja.js +1 -1
- package/dist/chat/locales/ko.cjs +1 -1
- package/dist/chat/locales/ko.d.ts.map +1 -1
- package/dist/chat/locales/ko.js +1 -1
- package/dist/chat/locales/pt-BR.cjs +1 -1
- package/dist/chat/locales/pt-BR.d.ts.map +1 -1
- package/dist/chat/locales/pt-BR.js +1 -1
- package/dist/chat/locales/pt.cjs +1 -1
- package/dist/chat/locales/pt.d.ts.map +1 -1
- package/dist/chat/locales/pt.js +1 -1
- package/dist/chat/locales/ro.cjs +1 -1
- package/dist/chat/locales/ro.d.ts.map +1 -1
- package/dist/chat/locales/ro.js +1 -1
- package/dist/chat/locales/ru.cjs +1 -1
- package/dist/chat/locales/ru.d.ts.map +1 -1
- package/dist/chat/locales/ru.js +1 -1
- package/dist/chat/locales/tr.cjs +1 -1
- package/dist/chat/locales/tr.d.ts.map +1 -1
- package/dist/chat/locales/tr.js +1 -1
- package/dist/chat/locales/zh-CN.cjs +1 -1
- package/dist/chat/locales/zh-CN.d.ts.map +1 -1
- package/dist/chat/locales/zh-CN.js +1 -1
- package/dist/chat/locales/zh-TW.cjs +1 -1
- package/dist/chat/locales/zh-TW.d.ts.map +1 -1
- package/dist/chat/locales/zh-TW.js +1 -1
- package/dist/chat/styles/tailwind.chat.css +1 -1
- package/dist/decision-table/DecisionTable.cjs +454 -0
- package/dist/decision-table/DecisionTable.d.ts +36 -0
- package/dist/decision-table/DecisionTable.d.ts.map +1 -0
- package/dist/decision-table/DecisionTable.js +410 -0
- package/dist/decision-table/GridCell.cjs +153 -0
- package/dist/decision-table/GridCell.d.ts +43 -0
- package/dist/decision-table/GridCell.d.ts.map +1 -0
- package/dist/decision-table/GridCell.js +116 -0
- package/dist/decision-table/GridMenu.cjs +135 -0
- package/dist/decision-table/GridMenu.d.ts +30 -0
- package/dist/decision-table/GridMenu.d.ts.map +1 -0
- package/dist/decision-table/GridMenu.js +101 -0
- package/dist/decision-table/MarkGlyph.cjs +51 -0
- package/dist/decision-table/MarkGlyph.d.ts +7 -0
- package/dist/decision-table/MarkGlyph.d.ts.map +1 -0
- package/dist/decision-table/MarkGlyph.js +17 -0
- package/dist/decision-table/clipboardCodec.cjs +123 -0
- package/dist/decision-table/clipboardCodec.d.ts +8 -0
- package/dist/decision-table/clipboardCodec.d.ts.map +1 -0
- package/dist/decision-table/clipboardCodec.js +80 -0
- package/dist/decision-table/clippedTitle.cjs +39 -0
- package/dist/decision-table/clippedTitle.d.ts +3 -0
- package/dist/decision-table/clippedTitle.d.ts.map +1 -0
- package/dist/decision-table/clippedTitle.js +5 -0
- package/dist/decision-table/columnSizing.cjs +92 -0
- package/dist/decision-table/columnSizing.d.ts +13 -0
- package/dist/decision-table/columnSizing.d.ts.map +1 -0
- package/dist/decision-table/columnSizing.js +52 -0
- package/dist/decision-table/constants.cjs +84 -0
- package/dist/decision-table/constants.d.ts +14 -0
- package/dist/decision-table/constants.d.ts.map +1 -0
- package/dist/decision-table/constants.js +14 -0
- package/dist/decision-table/gridClipboard.cjs +129 -0
- package/dist/decision-table/gridClipboard.d.ts +19 -0
- package/dist/decision-table/gridClipboard.d.ts.map +1 -0
- package/dist/decision-table/gridClipboard.js +89 -0
- package/dist/decision-table/gridEvents.cjs +72 -0
- package/dist/decision-table/gridEvents.d.ts +14 -0
- package/dist/decision-table/gridEvents.d.ts.map +1 -0
- package/dist/decision-table/gridEvents.js +23 -0
- package/dist/decision-table/gridStyles.cjs +196 -0
- package/dist/decision-table/gridStyles.d.ts +47 -0
- package/dist/decision-table/gridStyles.d.ts.map +1 -0
- package/dist/decision-table/gridStyles.js +54 -0
- package/dist/decision-table/gridTypes.cjs +18 -0
- package/dist/decision-table/gridTypes.d.ts +93 -0
- package/dist/decision-table/gridTypes.d.ts.map +1 -0
- package/dist/decision-table/gridTypes.js +0 -0
- package/dist/decision-table/index.cjs +271 -0
- package/dist/decision-table/index.d.ts +13 -0
- package/dist/decision-table/index.d.ts.map +1 -0
- package/dist/decision-table/index.js +12 -0
- package/dist/decision-table/marks.cjs +39 -0
- package/dist/decision-table/marks.d.ts +20 -0
- package/dist/decision-table/marks.d.ts.map +1 -0
- package/dist/decision-table/marks.js +5 -0
- package/dist/decision-table/styles/tailwind.decision-table.css +2 -0
- package/dist/decision-table/useColumnWidths.cjs +313 -0
- package/dist/decision-table/useColumnWidths.d.ts +21 -0
- package/dist/decision-table/useColumnWidths.d.ts.map +1 -0
- package/dist/decision-table/useColumnWidths.js +279 -0
- package/dist/decision-table/useDragReorder.cjs +229 -0
- package/dist/decision-table/useDragReorder.d.ts +31 -0
- package/dist/decision-table/useDragReorder.d.ts.map +1 -0
- package/dist/decision-table/useDragReorder.js +186 -0
- package/dist/decision-table/useDragSelection.cjs +75 -0
- package/dist/decision-table/useDragSelection.d.ts +18 -0
- package/dist/decision-table/useDragSelection.d.ts.map +1 -0
- package/dist/decision-table/useDragSelection.js +41 -0
- package/dist/decision-table/useGridClipboard.cjs +195 -0
- package/dist/decision-table/useGridClipboard.d.ts +13 -0
- package/dist/decision-table/useGridClipboard.d.ts.map +1 -0
- package/dist/decision-table/useGridClipboard.js +161 -0
- package/dist/decision-table/useGridLayout.cjs +248 -0
- package/dist/decision-table/useGridLayout.d.ts +50 -0
- package/dist/decision-table/useGridLayout.d.ts.map +1 -0
- package/dist/decision-table/useGridLayout.js +211 -0
- package/dist/decision-table/useGridNavigation.cjs +441 -0
- package/dist/decision-table/useGridNavigation.d.ts +67 -0
- package/dist/decision-table/useGridNavigation.d.ts.map +1 -0
- package/dist/decision-table/useGridNavigation.js +404 -0
- package/dist/decision-table/useVirtualizedAxis.cjs +256 -0
- package/dist/decision-table/useVirtualizedAxis.d.ts +34 -0
- package/dist/decision-table/useVirtualizedAxis.d.ts.map +1 -0
- package/dist/decision-table/useVirtualizedAxis.js +219 -0
- package/dist/test/setup.d.ts.map +1 -1
- package/package.json +20 -10
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
columnBoundaryForX: ()=>columnBoundaryForX,
|
|
28
|
+
useDragReorder: ()=>useDragReorder,
|
|
29
|
+
dropIndex: ()=>dropIndex,
|
|
30
|
+
rowBoundaryForY: ()=>rowBoundaryForY
|
|
31
|
+
});
|
|
32
|
+
const external_react_namespaceObject = require("react");
|
|
33
|
+
const external_constants_cjs_namespaceObject = require("./constants.cjs");
|
|
34
|
+
const dropIndex = (from, boundary)=>boundary > from ? boundary - 1 : boundary;
|
|
35
|
+
const rowBoundaryForY = (y, rowHeightPx, rowCount, previous)=>{
|
|
36
|
+
const boundary = Math.round(y / rowHeightPx);
|
|
37
|
+
return Number.isNaN(boundary) ? previous : Math.max(0, Math.min(rowCount, boundary));
|
|
38
|
+
};
|
|
39
|
+
const columnBoundaryForX = (x, offsets, columnCount, bandStart, bandEnd, previous)=>{
|
|
40
|
+
if (Number.isNaN(x)) return previous;
|
|
41
|
+
let boundary = 0;
|
|
42
|
+
while(boundary < columnCount && offsets[boundary] + (offsets[boundary + 1] - offsets[boundary]) / 2 < x)boundary += 1;
|
|
43
|
+
return Math.max(bandStart, Math.min(bandEnd, boundary)) - bandStart;
|
|
44
|
+
};
|
|
45
|
+
const useDragReorder = (options)=>{
|
|
46
|
+
const { containerRef, headerHeight, columnLeading, columnOffsets, rowHeightPx, rowCount } = options;
|
|
47
|
+
const [dragState, setDragState] = (0, external_react_namespaceObject.useState)(null);
|
|
48
|
+
const columnGroupBoundariesRef = (0, external_react_namespaceObject.useRef)(options.columnGroupBoundaries);
|
|
49
|
+
columnGroupBoundariesRef.current = options.columnGroupBoundaries;
|
|
50
|
+
const dragRef = (0, external_react_namespaceObject.useRef)(null);
|
|
51
|
+
const pointerRef = (0, external_react_namespaceObject.useRef)(null);
|
|
52
|
+
const rafRef = (0, external_react_namespaceObject.useRef)(null);
|
|
53
|
+
const cancelRef = (0, external_react_namespaceObject.useRef)(null);
|
|
54
|
+
const boundaryFromPointer = (0, external_react_namespaceObject.useCallback)((state, clientX, clientY)=>{
|
|
55
|
+
const container = containerRef.current;
|
|
56
|
+
if (!container) return state.boundary;
|
|
57
|
+
const rect = container.getBoundingClientRect();
|
|
58
|
+
if ('row' === state.axis) {
|
|
59
|
+
const y = clientY - rect.top + container.scrollTop - headerHeight();
|
|
60
|
+
return rowBoundaryForY(y, rowHeightPx, rowCount, state.boundary);
|
|
61
|
+
}
|
|
62
|
+
const x = clientX - rect.left + container.scrollLeft - columnLeading();
|
|
63
|
+
const boundaries = columnGroupBoundariesRef.current;
|
|
64
|
+
const groupStart = boundaries[state.groupIndex] ?? 0;
|
|
65
|
+
const groupEnd = boundaries[state.groupIndex + 1] ?? groupStart;
|
|
66
|
+
const columnCount = boundaries[boundaries.length - 1] ?? 0;
|
|
67
|
+
return columnBoundaryForX(x, columnOffsets(), columnCount, groupStart, groupEnd, state.boundary);
|
|
68
|
+
}, [
|
|
69
|
+
containerRef,
|
|
70
|
+
headerHeight,
|
|
71
|
+
columnLeading,
|
|
72
|
+
columnOffsets,
|
|
73
|
+
rowHeightPx,
|
|
74
|
+
rowCount
|
|
75
|
+
]);
|
|
76
|
+
const latestRef = (0, external_react_namespaceObject.useRef)({
|
|
77
|
+
boundaryFromPointer,
|
|
78
|
+
onDropRow: options.onDropRow,
|
|
79
|
+
onDropColumn: options.onDropColumn
|
|
80
|
+
});
|
|
81
|
+
latestRef.current = {
|
|
82
|
+
boundaryFromPointer,
|
|
83
|
+
onDropRow: options.onDropRow,
|
|
84
|
+
onDropColumn: options.onDropColumn
|
|
85
|
+
};
|
|
86
|
+
const stopAutoscroll = (0, external_react_namespaceObject.useCallback)(()=>{
|
|
87
|
+
if (null !== rafRef.current) {
|
|
88
|
+
cancelAnimationFrame(rafRef.current);
|
|
89
|
+
rafRef.current = null;
|
|
90
|
+
}
|
|
91
|
+
}, []);
|
|
92
|
+
const autoscrollLoop = (0, external_react_namespaceObject.useCallback)(()=>{
|
|
93
|
+
rafRef.current = null;
|
|
94
|
+
const container = containerRef.current;
|
|
95
|
+
const pointer = pointerRef.current;
|
|
96
|
+
const state = dragRef.current;
|
|
97
|
+
if (!container || !pointer || !state) return;
|
|
98
|
+
const rect = container.getBoundingClientRect();
|
|
99
|
+
const before = 'row' === state.axis ? container.scrollTop : container.scrollLeft;
|
|
100
|
+
if ('row' === state.axis) {
|
|
101
|
+
if (pointer.y > rect.bottom - external_constants_cjs_namespaceObject.AUTOSCROLL_EDGE_PX) container.scrollTop += external_constants_cjs_namespaceObject.AUTOSCROLL_STEP_PX;
|
|
102
|
+
else if (pointer.y < rect.top + headerHeight() + external_constants_cjs_namespaceObject.AUTOSCROLL_EDGE_PX) container.scrollTop -= external_constants_cjs_namespaceObject.AUTOSCROLL_STEP_PX;
|
|
103
|
+
} else if (pointer.x > rect.right - external_constants_cjs_namespaceObject.AUTOSCROLL_EDGE_PX) container.scrollLeft += external_constants_cjs_namespaceObject.AUTOSCROLL_STEP_PX;
|
|
104
|
+
else if (pointer.x < rect.left + columnLeading() + external_constants_cjs_namespaceObject.AUTOSCROLL_EDGE_PX) container.scrollLeft -= external_constants_cjs_namespaceObject.AUTOSCROLL_STEP_PX;
|
|
105
|
+
const moved = ('row' === state.axis ? container.scrollTop : container.scrollLeft) !== before;
|
|
106
|
+
if (moved) {
|
|
107
|
+
const boundary = boundaryFromPointer(state, pointer.x, pointer.y);
|
|
108
|
+
if (boundary !== state.boundary) {
|
|
109
|
+
dragRef.current = {
|
|
110
|
+
...state,
|
|
111
|
+
boundary
|
|
112
|
+
};
|
|
113
|
+
setDragState(dragRef.current);
|
|
114
|
+
}
|
|
115
|
+
rafRef.current = requestAnimationFrame(autoscrollLoop);
|
|
116
|
+
}
|
|
117
|
+
}, [
|
|
118
|
+
containerRef,
|
|
119
|
+
headerHeight,
|
|
120
|
+
columnLeading,
|
|
121
|
+
boundaryFromPointer
|
|
122
|
+
]);
|
|
123
|
+
const beginDrag = (0, external_react_namespaceObject.useCallback)((initial, event)=>{
|
|
124
|
+
cancelRef.current?.();
|
|
125
|
+
const focused = document.activeElement;
|
|
126
|
+
if (focused instanceof HTMLElement && focused.closest("input, textarea, [contenteditable='true']")) focused.blur();
|
|
127
|
+
event.preventDefault();
|
|
128
|
+
dragRef.current = initial;
|
|
129
|
+
setDragState(initial);
|
|
130
|
+
pointerRef.current = {
|
|
131
|
+
x: event.clientX,
|
|
132
|
+
y: event.clientY
|
|
133
|
+
};
|
|
134
|
+
const onPointerMove = (move)=>{
|
|
135
|
+
if ((1 & move.buttons) === 0) return void cleanup();
|
|
136
|
+
pointerRef.current = {
|
|
137
|
+
x: move.clientX,
|
|
138
|
+
y: move.clientY
|
|
139
|
+
};
|
|
140
|
+
const state = dragRef.current;
|
|
141
|
+
if (!state) return;
|
|
142
|
+
const boundary = latestRef.current.boundaryFromPointer(state, move.clientX, move.clientY);
|
|
143
|
+
if (boundary !== state.boundary) {
|
|
144
|
+
dragRef.current = {
|
|
145
|
+
...state,
|
|
146
|
+
boundary
|
|
147
|
+
};
|
|
148
|
+
setDragState(dragRef.current);
|
|
149
|
+
}
|
|
150
|
+
if (null === rafRef.current) rafRef.current = requestAnimationFrame(autoscrollLoop);
|
|
151
|
+
};
|
|
152
|
+
const cleanup = ()=>{
|
|
153
|
+
document.removeEventListener('pointermove', onPointerMove);
|
|
154
|
+
document.removeEventListener('pointerup', onPointerUp);
|
|
155
|
+
document.removeEventListener('pointercancel', cleanup);
|
|
156
|
+
document.removeEventListener('keydown', onKeyDown, true);
|
|
157
|
+
stopAutoscroll();
|
|
158
|
+
pointerRef.current = null;
|
|
159
|
+
dragRef.current = null;
|
|
160
|
+
cancelRef.current = null;
|
|
161
|
+
setDragState(null);
|
|
162
|
+
};
|
|
163
|
+
cancelRef.current = cleanup;
|
|
164
|
+
const onPointerUp = ()=>{
|
|
165
|
+
const state = dragRef.current;
|
|
166
|
+
try {
|
|
167
|
+
if (state) {
|
|
168
|
+
const to = dropIndex(state.from, state.boundary);
|
|
169
|
+
if (to !== state.from) if ('row' === state.axis) latestRef.current.onDropRow(state.from, to);
|
|
170
|
+
else latestRef.current.onDropColumn(state.groupIndex, state.from, to);
|
|
171
|
+
}
|
|
172
|
+
} finally{
|
|
173
|
+
cleanup();
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
const onKeyDown = (key)=>{
|
|
177
|
+
if ('Escape' === key.key) {
|
|
178
|
+
key.stopPropagation();
|
|
179
|
+
cleanup();
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
document.addEventListener('pointermove', onPointerMove);
|
|
183
|
+
document.addEventListener('pointerup', onPointerUp);
|
|
184
|
+
document.addEventListener('pointercancel', cleanup);
|
|
185
|
+
document.addEventListener('keydown', onKeyDown, true);
|
|
186
|
+
}, [
|
|
187
|
+
autoscrollLoop,
|
|
188
|
+
stopAutoscroll
|
|
189
|
+
]);
|
|
190
|
+
const startRowDrag = (0, external_react_namespaceObject.useCallback)((rowIndex, event)=>beginDrag({
|
|
191
|
+
axis: 'row',
|
|
192
|
+
from: rowIndex,
|
|
193
|
+
boundary: rowIndex
|
|
194
|
+
}, event), [
|
|
195
|
+
beginDrag
|
|
196
|
+
]);
|
|
197
|
+
const startColumnDrag = (0, external_react_namespaceObject.useCallback)((groupIndex, indexInGroup, event)=>beginDrag({
|
|
198
|
+
axis: 'column',
|
|
199
|
+
groupIndex,
|
|
200
|
+
from: indexInGroup,
|
|
201
|
+
boundary: indexInGroup
|
|
202
|
+
}, event), [
|
|
203
|
+
beginDrag
|
|
204
|
+
]);
|
|
205
|
+
(0, external_react_namespaceObject.useEffect)(()=>()=>{
|
|
206
|
+
cancelRef.current?.();
|
|
207
|
+
stopAutoscroll();
|
|
208
|
+
}, [
|
|
209
|
+
stopAutoscroll
|
|
210
|
+
]);
|
|
211
|
+
return {
|
|
212
|
+
dragState,
|
|
213
|
+
startRowDrag,
|
|
214
|
+
startColumnDrag
|
|
215
|
+
};
|
|
216
|
+
};
|
|
217
|
+
exports.columnBoundaryForX = __webpack_exports__.columnBoundaryForX;
|
|
218
|
+
exports.dropIndex = __webpack_exports__.dropIndex;
|
|
219
|
+
exports.rowBoundaryForY = __webpack_exports__.rowBoundaryForY;
|
|
220
|
+
exports.useDragReorder = __webpack_exports__.useDragReorder;
|
|
221
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
222
|
+
"columnBoundaryForX",
|
|
223
|
+
"dropIndex",
|
|
224
|
+
"rowBoundaryForY",
|
|
225
|
+
"useDragReorder"
|
|
226
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
227
|
+
Object.defineProperty(exports, '__esModule', {
|
|
228
|
+
value: true
|
|
229
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
type DragReorderState = {
|
|
2
|
+
axis: 'row';
|
|
3
|
+
from: number;
|
|
4
|
+
boundary: number;
|
|
5
|
+
} | {
|
|
6
|
+
axis: 'column';
|
|
7
|
+
groupIndex: number;
|
|
8
|
+
from: number;
|
|
9
|
+
boundary: number;
|
|
10
|
+
};
|
|
11
|
+
interface DragReorderOptions {
|
|
12
|
+
containerRef: React.RefObject<HTMLElement | null>;
|
|
13
|
+
headerHeight: () => number;
|
|
14
|
+
columnLeading: () => number;
|
|
15
|
+
columnOffsets: () => number[];
|
|
16
|
+
rowHeightPx: number;
|
|
17
|
+
rowCount: number;
|
|
18
|
+
columnGroupBoundaries: number[];
|
|
19
|
+
onDropRow: (from: number, to: number) => void;
|
|
20
|
+
onDropColumn: (groupIndex: number, from: number, to: number) => void;
|
|
21
|
+
}
|
|
22
|
+
export declare const dropIndex: (from: number, boundary: number) => number;
|
|
23
|
+
export declare const rowBoundaryForY: (y: number, rowHeightPx: number, rowCount: number, previous: number) => number;
|
|
24
|
+
export declare const columnBoundaryForX: (x: number, offsets: number[], columnCount: number, bandStart: number, bandEnd: number, previous: number) => number;
|
|
25
|
+
export declare const useDragReorder: (options: DragReorderOptions) => {
|
|
26
|
+
dragState: DragReorderState | null;
|
|
27
|
+
startRowDrag: (rowIndex: number, event: React.PointerEvent) => void;
|
|
28
|
+
startColumnDrag: (groupIndex: number, indexInGroup: number, event: React.PointerEvent) => void;
|
|
29
|
+
};
|
|
30
|
+
export {};
|
|
31
|
+
//# sourceMappingURL=useDragReorder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDragReorder.d.ts","sourceRoot":"","sources":["../../src/decision-table/useDragReorder.ts"],"names":[],"mappings":"AASA,KAAK,gBAAgB,GACjB;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAC/C;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAE3E,UAAU,kBAAkB;IAC1B,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;IAElD,YAAY,EAAE,MAAM,MAAM,CAAC;IAE3B,aAAa,EAAE,MAAM,MAAM,CAAC;IAE5B,aAAa,EAAE,MAAM,MAAM,EAAE,CAAC;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IAMjB,qBAAqB,EAAE,MAAM,EAAE,CAAC;IAChC,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IAE9C,YAAY,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;CACtE;AAeD,eAAO,MAAM,SAAS,GAAI,MAAM,MAAM,EAAE,UAAU,MAAM,KAAG,MAChB,CAAC;AAO5C,eAAO,MAAM,eAAe,GAC1B,GAAG,MAAM,EACT,aAAa,MAAM,EACnB,UAAU,MAAM,EAChB,UAAU,MAAM,KACf,MAGF,CAAC;AAQF,eAAO,MAAM,kBAAkB,GAC7B,GAAG,MAAM,EACT,SAAS,MAAM,EAAE,EACjB,aAAa,MAAM,EACnB,WAAW,MAAM,EACjB,SAAS,MAAM,EACf,UAAU,MAAM,KACf,MAYF,CAAC;AAUF,eAAO,MAAM,cAAc,GAAI,SAAS,kBAAkB;;6BAoM3C,MAAM,SAAS,KAAK,CAAC,YAAY;kCAK/B,MAAM,gBAAgB,MAAM,SAAS,KAAK,CAAC,YAAY;CAgBvE,CAAC"}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
+
import { AUTOSCROLL_EDGE_PX, AUTOSCROLL_STEP_PX } from "./constants.js";
|
|
3
|
+
const dropIndex = (from, boundary)=>boundary > from ? boundary - 1 : boundary;
|
|
4
|
+
const rowBoundaryForY = (y, rowHeightPx, rowCount, previous)=>{
|
|
5
|
+
const boundary = Math.round(y / rowHeightPx);
|
|
6
|
+
return Number.isNaN(boundary) ? previous : Math.max(0, Math.min(rowCount, boundary));
|
|
7
|
+
};
|
|
8
|
+
const columnBoundaryForX = (x, offsets, columnCount, bandStart, bandEnd, previous)=>{
|
|
9
|
+
if (Number.isNaN(x)) return previous;
|
|
10
|
+
let boundary = 0;
|
|
11
|
+
while(boundary < columnCount && offsets[boundary] + (offsets[boundary + 1] - offsets[boundary]) / 2 < x)boundary += 1;
|
|
12
|
+
return Math.max(bandStart, Math.min(bandEnd, boundary)) - bandStart;
|
|
13
|
+
};
|
|
14
|
+
const useDragReorder = (options)=>{
|
|
15
|
+
const { containerRef, headerHeight, columnLeading, columnOffsets, rowHeightPx, rowCount } = options;
|
|
16
|
+
const [dragState, setDragState] = useState(null);
|
|
17
|
+
const columnGroupBoundariesRef = useRef(options.columnGroupBoundaries);
|
|
18
|
+
columnGroupBoundariesRef.current = options.columnGroupBoundaries;
|
|
19
|
+
const dragRef = useRef(null);
|
|
20
|
+
const pointerRef = useRef(null);
|
|
21
|
+
const rafRef = useRef(null);
|
|
22
|
+
const cancelRef = useRef(null);
|
|
23
|
+
const boundaryFromPointer = useCallback((state, clientX, clientY)=>{
|
|
24
|
+
const container = containerRef.current;
|
|
25
|
+
if (!container) return state.boundary;
|
|
26
|
+
const rect = container.getBoundingClientRect();
|
|
27
|
+
if ('row' === state.axis) {
|
|
28
|
+
const y = clientY - rect.top + container.scrollTop - headerHeight();
|
|
29
|
+
return rowBoundaryForY(y, rowHeightPx, rowCount, state.boundary);
|
|
30
|
+
}
|
|
31
|
+
const x = clientX - rect.left + container.scrollLeft - columnLeading();
|
|
32
|
+
const boundaries = columnGroupBoundariesRef.current;
|
|
33
|
+
const groupStart = boundaries[state.groupIndex] ?? 0;
|
|
34
|
+
const groupEnd = boundaries[state.groupIndex + 1] ?? groupStart;
|
|
35
|
+
const columnCount = boundaries[boundaries.length - 1] ?? 0;
|
|
36
|
+
return columnBoundaryForX(x, columnOffsets(), columnCount, groupStart, groupEnd, state.boundary);
|
|
37
|
+
}, [
|
|
38
|
+
containerRef,
|
|
39
|
+
headerHeight,
|
|
40
|
+
columnLeading,
|
|
41
|
+
columnOffsets,
|
|
42
|
+
rowHeightPx,
|
|
43
|
+
rowCount
|
|
44
|
+
]);
|
|
45
|
+
const latestRef = useRef({
|
|
46
|
+
boundaryFromPointer,
|
|
47
|
+
onDropRow: options.onDropRow,
|
|
48
|
+
onDropColumn: options.onDropColumn
|
|
49
|
+
});
|
|
50
|
+
latestRef.current = {
|
|
51
|
+
boundaryFromPointer,
|
|
52
|
+
onDropRow: options.onDropRow,
|
|
53
|
+
onDropColumn: options.onDropColumn
|
|
54
|
+
};
|
|
55
|
+
const stopAutoscroll = useCallback(()=>{
|
|
56
|
+
if (null !== rafRef.current) {
|
|
57
|
+
cancelAnimationFrame(rafRef.current);
|
|
58
|
+
rafRef.current = null;
|
|
59
|
+
}
|
|
60
|
+
}, []);
|
|
61
|
+
const autoscrollLoop = useCallback(()=>{
|
|
62
|
+
rafRef.current = null;
|
|
63
|
+
const container = containerRef.current;
|
|
64
|
+
const pointer = pointerRef.current;
|
|
65
|
+
const state = dragRef.current;
|
|
66
|
+
if (!container || !pointer || !state) return;
|
|
67
|
+
const rect = container.getBoundingClientRect();
|
|
68
|
+
const before = 'row' === state.axis ? container.scrollTop : container.scrollLeft;
|
|
69
|
+
if ('row' === state.axis) {
|
|
70
|
+
if (pointer.y > rect.bottom - AUTOSCROLL_EDGE_PX) container.scrollTop += AUTOSCROLL_STEP_PX;
|
|
71
|
+
else if (pointer.y < rect.top + headerHeight() + AUTOSCROLL_EDGE_PX) container.scrollTop -= AUTOSCROLL_STEP_PX;
|
|
72
|
+
} else if (pointer.x > rect.right - AUTOSCROLL_EDGE_PX) container.scrollLeft += AUTOSCROLL_STEP_PX;
|
|
73
|
+
else if (pointer.x < rect.left + columnLeading() + AUTOSCROLL_EDGE_PX) container.scrollLeft -= AUTOSCROLL_STEP_PX;
|
|
74
|
+
const moved = ('row' === state.axis ? container.scrollTop : container.scrollLeft) !== before;
|
|
75
|
+
if (moved) {
|
|
76
|
+
const boundary = boundaryFromPointer(state, pointer.x, pointer.y);
|
|
77
|
+
if (boundary !== state.boundary) {
|
|
78
|
+
dragRef.current = {
|
|
79
|
+
...state,
|
|
80
|
+
boundary
|
|
81
|
+
};
|
|
82
|
+
setDragState(dragRef.current);
|
|
83
|
+
}
|
|
84
|
+
rafRef.current = requestAnimationFrame(autoscrollLoop);
|
|
85
|
+
}
|
|
86
|
+
}, [
|
|
87
|
+
containerRef,
|
|
88
|
+
headerHeight,
|
|
89
|
+
columnLeading,
|
|
90
|
+
boundaryFromPointer
|
|
91
|
+
]);
|
|
92
|
+
const beginDrag = useCallback((initial, event)=>{
|
|
93
|
+
cancelRef.current?.();
|
|
94
|
+
const focused = document.activeElement;
|
|
95
|
+
if (focused instanceof HTMLElement && focused.closest("input, textarea, [contenteditable='true']")) focused.blur();
|
|
96
|
+
event.preventDefault();
|
|
97
|
+
dragRef.current = initial;
|
|
98
|
+
setDragState(initial);
|
|
99
|
+
pointerRef.current = {
|
|
100
|
+
x: event.clientX,
|
|
101
|
+
y: event.clientY
|
|
102
|
+
};
|
|
103
|
+
const onPointerMove = (move)=>{
|
|
104
|
+
if ((1 & move.buttons) === 0) return void cleanup();
|
|
105
|
+
pointerRef.current = {
|
|
106
|
+
x: move.clientX,
|
|
107
|
+
y: move.clientY
|
|
108
|
+
};
|
|
109
|
+
const state = dragRef.current;
|
|
110
|
+
if (!state) return;
|
|
111
|
+
const boundary = latestRef.current.boundaryFromPointer(state, move.clientX, move.clientY);
|
|
112
|
+
if (boundary !== state.boundary) {
|
|
113
|
+
dragRef.current = {
|
|
114
|
+
...state,
|
|
115
|
+
boundary
|
|
116
|
+
};
|
|
117
|
+
setDragState(dragRef.current);
|
|
118
|
+
}
|
|
119
|
+
if (null === rafRef.current) rafRef.current = requestAnimationFrame(autoscrollLoop);
|
|
120
|
+
};
|
|
121
|
+
const cleanup = ()=>{
|
|
122
|
+
document.removeEventListener('pointermove', onPointerMove);
|
|
123
|
+
document.removeEventListener('pointerup', onPointerUp);
|
|
124
|
+
document.removeEventListener('pointercancel', cleanup);
|
|
125
|
+
document.removeEventListener('keydown', onKeyDown, true);
|
|
126
|
+
stopAutoscroll();
|
|
127
|
+
pointerRef.current = null;
|
|
128
|
+
dragRef.current = null;
|
|
129
|
+
cancelRef.current = null;
|
|
130
|
+
setDragState(null);
|
|
131
|
+
};
|
|
132
|
+
cancelRef.current = cleanup;
|
|
133
|
+
const onPointerUp = ()=>{
|
|
134
|
+
const state = dragRef.current;
|
|
135
|
+
try {
|
|
136
|
+
if (state) {
|
|
137
|
+
const to = dropIndex(state.from, state.boundary);
|
|
138
|
+
if (to !== state.from) if ('row' === state.axis) latestRef.current.onDropRow(state.from, to);
|
|
139
|
+
else latestRef.current.onDropColumn(state.groupIndex, state.from, to);
|
|
140
|
+
}
|
|
141
|
+
} finally{
|
|
142
|
+
cleanup();
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
const onKeyDown = (key)=>{
|
|
146
|
+
if ('Escape' === key.key) {
|
|
147
|
+
key.stopPropagation();
|
|
148
|
+
cleanup();
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
document.addEventListener('pointermove', onPointerMove);
|
|
152
|
+
document.addEventListener('pointerup', onPointerUp);
|
|
153
|
+
document.addEventListener('pointercancel', cleanup);
|
|
154
|
+
document.addEventListener('keydown', onKeyDown, true);
|
|
155
|
+
}, [
|
|
156
|
+
autoscrollLoop,
|
|
157
|
+
stopAutoscroll
|
|
158
|
+
]);
|
|
159
|
+
const startRowDrag = useCallback((rowIndex, event)=>beginDrag({
|
|
160
|
+
axis: 'row',
|
|
161
|
+
from: rowIndex,
|
|
162
|
+
boundary: rowIndex
|
|
163
|
+
}, event), [
|
|
164
|
+
beginDrag
|
|
165
|
+
]);
|
|
166
|
+
const startColumnDrag = useCallback((groupIndex, indexInGroup, event)=>beginDrag({
|
|
167
|
+
axis: 'column',
|
|
168
|
+
groupIndex,
|
|
169
|
+
from: indexInGroup,
|
|
170
|
+
boundary: indexInGroup
|
|
171
|
+
}, event), [
|
|
172
|
+
beginDrag
|
|
173
|
+
]);
|
|
174
|
+
useEffect(()=>()=>{
|
|
175
|
+
cancelRef.current?.();
|
|
176
|
+
stopAutoscroll();
|
|
177
|
+
}, [
|
|
178
|
+
stopAutoscroll
|
|
179
|
+
]);
|
|
180
|
+
return {
|
|
181
|
+
dragState,
|
|
182
|
+
startRowDrag,
|
|
183
|
+
startColumnDrag
|
|
184
|
+
};
|
|
185
|
+
};
|
|
186
|
+
export { columnBoundaryForX, dropIndex, rowBoundaryForY, useDragReorder };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
useDragSelection: ()=>useDragSelection
|
|
28
|
+
});
|
|
29
|
+
const external_react_namespaceObject = require("react");
|
|
30
|
+
const external_gridEvents_cjs_namespaceObject = require("./gridEvents.cjs");
|
|
31
|
+
const useDragSelection = ({ editing, hasSelection, cellAt, select, extendTo, onEmptyAreaPress, onCellPress })=>{
|
|
32
|
+
const draggingRef = (0, external_react_namespaceObject.useRef)(false);
|
|
33
|
+
(0, external_react_namespaceObject.useEffect)(()=>{
|
|
34
|
+
const endDrag = ()=>{
|
|
35
|
+
draggingRef.current = false;
|
|
36
|
+
};
|
|
37
|
+
const endDragOnEscape = (event)=>{
|
|
38
|
+
if ('Escape' === event.key) endDrag();
|
|
39
|
+
};
|
|
40
|
+
document.addEventListener('pointerup', endDrag);
|
|
41
|
+
document.addEventListener('keydown', endDragOnEscape, true);
|
|
42
|
+
return ()=>{
|
|
43
|
+
document.removeEventListener('pointerup', endDrag);
|
|
44
|
+
document.removeEventListener('keydown', endDragOnEscape, true);
|
|
45
|
+
};
|
|
46
|
+
}, []);
|
|
47
|
+
const onPointerDown = (event)=>{
|
|
48
|
+
if (editing || 0 !== event.button) return;
|
|
49
|
+
draggingRef.current = false;
|
|
50
|
+
if ((0, external_gridEvents_cjs_namespaceObject.isBlankContainerPress)(event)) return void onEmptyAreaPress();
|
|
51
|
+
const cell = cellAt(event.target);
|
|
52
|
+
if (!cell) return;
|
|
53
|
+
draggingRef.current = true;
|
|
54
|
+
const extended = event.shiftKey && hasSelection;
|
|
55
|
+
if (extended) extendTo(cell);
|
|
56
|
+
else select(cell);
|
|
57
|
+
onCellPress?.(cell, extended);
|
|
58
|
+
};
|
|
59
|
+
const onPointerOver = (event)=>{
|
|
60
|
+
if (!draggingRef.current || (1 & event.buttons) === 0) return;
|
|
61
|
+
const cell = cellAt(event.target);
|
|
62
|
+
if (cell) extendTo(cell);
|
|
63
|
+
};
|
|
64
|
+
return {
|
|
65
|
+
onPointerDown,
|
|
66
|
+
onPointerOver
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
exports.useDragSelection = __webpack_exports__.useDragSelection;
|
|
70
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
71
|
+
"useDragSelection"
|
|
72
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
73
|
+
Object.defineProperty(exports, '__esModule', {
|
|
74
|
+
value: true
|
|
75
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import type { GridPosition } from './gridTypes';
|
|
3
|
+
interface DragSelectionOptions {
|
|
4
|
+
editing: boolean;
|
|
5
|
+
hasSelection: boolean;
|
|
6
|
+
cellAt: (element: Element) => GridPosition | null;
|
|
7
|
+
select: (position: GridPosition) => void;
|
|
8
|
+
extendTo: (position: GridPosition) => void;
|
|
9
|
+
onEmptyAreaPress: () => void;
|
|
10
|
+
onCellPress?: (position: GridPosition, extended: boolean) => void;
|
|
11
|
+
}
|
|
12
|
+
export interface DragSelectionHandlers {
|
|
13
|
+
onPointerDown: (event: React.PointerEvent<HTMLElement>) => void;
|
|
14
|
+
onPointerOver: (event: React.PointerEvent) => void;
|
|
15
|
+
}
|
|
16
|
+
export declare const useDragSelection: ({ editing, hasSelection, cellAt, select, extendTo, onEmptyAreaPress, onCellPress, }: DragSelectionOptions) => DragSelectionHandlers;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=useDragSelection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDragSelection.d.ts","sourceRoot":"","sources":["../../src/decision-table/useDragSelection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,UAAU,oBAAoB;IAC5B,OAAO,EAAE,OAAO,CAAC;IAEjB,YAAY,EAAE,OAAO,CAAC;IAEtB,MAAM,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,YAAY,GAAG,IAAI,CAAC;IAClD,MAAM,EAAE,CAAC,QAAQ,EAAE,YAAY,KAAK,IAAI,CAAC;IACzC,QAAQ,EAAE,CAAC,QAAQ,EAAE,YAAY,KAAK,IAAI,CAAC;IAC3C,gBAAgB,EAAE,MAAM,IAAI,CAAC;IAE7B,WAAW,CAAC,EAAE,CAAC,QAAQ,EAAE,YAAY,EAAE,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAC;CACnE;AAGD,MAAM,WAAW,qBAAqB;IAEpC,aAAa,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,YAAY,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC;IAEhE,aAAa,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,YAAY,KAAK,IAAI,CAAC;CACpD;AAGD,eAAO,MAAM,gBAAgB,GAAI,qFAQ9B,oBAAoB,KAAG,qBAwDzB,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
import { isBlankContainerPress } from "./gridEvents.js";
|
|
3
|
+
const useDragSelection = ({ editing, hasSelection, cellAt, select, extendTo, onEmptyAreaPress, onCellPress })=>{
|
|
4
|
+
const draggingRef = useRef(false);
|
|
5
|
+
useEffect(()=>{
|
|
6
|
+
const endDrag = ()=>{
|
|
7
|
+
draggingRef.current = false;
|
|
8
|
+
};
|
|
9
|
+
const endDragOnEscape = (event)=>{
|
|
10
|
+
if ('Escape' === event.key) endDrag();
|
|
11
|
+
};
|
|
12
|
+
document.addEventListener('pointerup', endDrag);
|
|
13
|
+
document.addEventListener('keydown', endDragOnEscape, true);
|
|
14
|
+
return ()=>{
|
|
15
|
+
document.removeEventListener('pointerup', endDrag);
|
|
16
|
+
document.removeEventListener('keydown', endDragOnEscape, true);
|
|
17
|
+
};
|
|
18
|
+
}, []);
|
|
19
|
+
const onPointerDown = (event)=>{
|
|
20
|
+
if (editing || 0 !== event.button) return;
|
|
21
|
+
draggingRef.current = false;
|
|
22
|
+
if (isBlankContainerPress(event)) return void onEmptyAreaPress();
|
|
23
|
+
const cell = cellAt(event.target);
|
|
24
|
+
if (!cell) return;
|
|
25
|
+
draggingRef.current = true;
|
|
26
|
+
const extended = event.shiftKey && hasSelection;
|
|
27
|
+
if (extended) extendTo(cell);
|
|
28
|
+
else select(cell);
|
|
29
|
+
onCellPress?.(cell, extended);
|
|
30
|
+
};
|
|
31
|
+
const onPointerOver = (event)=>{
|
|
32
|
+
if (!draggingRef.current || (1 & event.buttons) === 0) return;
|
|
33
|
+
const cell = cellAt(event.target);
|
|
34
|
+
if (cell) extendTo(cell);
|
|
35
|
+
};
|
|
36
|
+
return {
|
|
37
|
+
onPointerDown,
|
|
38
|
+
onPointerOver
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
export { useDragSelection };
|