@uipath/apollo-react 7.17.1 → 7.17.3

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.
Files changed (107) hide show
  1. package/dist/canvas/components/Toolbox/ListView.cjs +7 -4
  2. package/dist/canvas/components/Toolbox/ListView.d.ts +2 -0
  3. package/dist/canvas/components/Toolbox/ListView.d.ts.map +1 -1
  4. package/dist/canvas/components/Toolbox/ListView.js +7 -4
  5. package/dist/canvas/components/Toolbox/Toolbox.cjs +1 -0
  6. package/dist/canvas/components/Toolbox/Toolbox.d.ts.map +1 -1
  7. package/dist/canvas/components/Toolbox/Toolbox.js +1 -0
  8. package/dist/canvas/styles/tailwind.canvas.css +1 -1
  9. package/dist/chat/styles/tailwind.chat.css +1 -1
  10. package/dist/decision-table/DecisionTable.cjs +232 -35
  11. package/dist/decision-table/DecisionTable.d.ts +6 -0
  12. package/dist/decision-table/DecisionTable.d.ts.map +1 -1
  13. package/dist/decision-table/DecisionTable.js +235 -38
  14. package/dist/decision-table/DragIndicator.cjs +47 -0
  15. package/dist/decision-table/DragIndicator.d.ts +6 -0
  16. package/dist/decision-table/DragIndicator.d.ts.map +1 -0
  17. package/dist/decision-table/DragIndicator.js +13 -0
  18. package/dist/decision-table/EdgeInsertButton.cjs +87 -0
  19. package/dist/decision-table/EdgeInsertButton.d.ts +11 -0
  20. package/dist/decision-table/EdgeInsertButton.d.ts.map +1 -0
  21. package/dist/decision-table/EdgeInsertButton.js +53 -0
  22. package/dist/decision-table/GridCell.cjs +2 -1
  23. package/dist/decision-table/GridCell.d.ts.map +1 -1
  24. package/dist/decision-table/GridCell.js +3 -2
  25. package/dist/decision-table/gridStyles.cjs +67 -23
  26. package/dist/decision-table/gridStyles.d.ts +14 -4
  27. package/dist/decision-table/gridStyles.d.ts.map +1 -1
  28. package/dist/decision-table/gridStyles.js +27 -13
  29. package/dist/decision-table/gridTypes.d.ts +9 -2
  30. package/dist/decision-table/gridTypes.d.ts.map +1 -1
  31. package/dist/decision-table/index.cjs +76 -68
  32. package/dist/decision-table/index.d.ts +4 -1
  33. package/dist/decision-table/index.d.ts.map +1 -1
  34. package/dist/decision-table/index.js +5 -2
  35. package/dist/decision-table/locales/de.cjs +36 -0
  36. package/dist/decision-table/locales/de.d.ts +3 -0
  37. package/dist/decision-table/locales/de.d.ts.map +1 -0
  38. package/dist/decision-table/locales/de.js +2 -0
  39. package/dist/decision-table/locales/en.cjs +36 -0
  40. package/dist/decision-table/locales/en.d.ts +3 -0
  41. package/dist/decision-table/locales/en.d.ts.map +1 -0
  42. package/dist/decision-table/locales/en.js +2 -0
  43. package/dist/decision-table/locales/es-MX.cjs +36 -0
  44. package/dist/decision-table/locales/es-MX.d.ts +3 -0
  45. package/dist/decision-table/locales/es-MX.d.ts.map +1 -0
  46. package/dist/decision-table/locales/es-MX.js +2 -0
  47. package/dist/decision-table/locales/es.cjs +36 -0
  48. package/dist/decision-table/locales/es.d.ts +3 -0
  49. package/dist/decision-table/locales/es.d.ts.map +1 -0
  50. package/dist/decision-table/locales/es.js +2 -0
  51. package/dist/decision-table/locales/fr.cjs +36 -0
  52. package/dist/decision-table/locales/fr.d.ts +3 -0
  53. package/dist/decision-table/locales/fr.d.ts.map +1 -0
  54. package/dist/decision-table/locales/fr.js +2 -0
  55. package/dist/decision-table/locales/ja.cjs +36 -0
  56. package/dist/decision-table/locales/ja.d.ts +3 -0
  57. package/dist/decision-table/locales/ja.d.ts.map +1 -0
  58. package/dist/decision-table/locales/ja.js +2 -0
  59. package/dist/decision-table/locales/ko.cjs +36 -0
  60. package/dist/decision-table/locales/ko.d.ts +3 -0
  61. package/dist/decision-table/locales/ko.d.ts.map +1 -0
  62. package/dist/decision-table/locales/ko.js +2 -0
  63. package/dist/decision-table/locales/pt-BR.cjs +36 -0
  64. package/dist/decision-table/locales/pt-BR.d.ts +3 -0
  65. package/dist/decision-table/locales/pt-BR.d.ts.map +1 -0
  66. package/dist/decision-table/locales/pt-BR.js +2 -0
  67. package/dist/decision-table/locales/pt.cjs +36 -0
  68. package/dist/decision-table/locales/pt.d.ts +3 -0
  69. package/dist/decision-table/locales/pt.d.ts.map +1 -0
  70. package/dist/decision-table/locales/pt.js +2 -0
  71. package/dist/decision-table/locales/ro.cjs +36 -0
  72. package/dist/decision-table/locales/ro.d.ts +3 -0
  73. package/dist/decision-table/locales/ro.d.ts.map +1 -0
  74. package/dist/decision-table/locales/ro.js +2 -0
  75. package/dist/decision-table/locales/ru.cjs +36 -0
  76. package/dist/decision-table/locales/ru.d.ts +3 -0
  77. package/dist/decision-table/locales/ru.d.ts.map +1 -0
  78. package/dist/decision-table/locales/ru.js +2 -0
  79. package/dist/decision-table/locales/tr.cjs +36 -0
  80. package/dist/decision-table/locales/tr.d.ts +3 -0
  81. package/dist/decision-table/locales/tr.d.ts.map +1 -0
  82. package/dist/decision-table/locales/tr.js +2 -0
  83. package/dist/decision-table/locales/zh-CN.cjs +36 -0
  84. package/dist/decision-table/locales/zh-CN.d.ts +3 -0
  85. package/dist/decision-table/locales/zh-CN.d.ts.map +1 -0
  86. package/dist/decision-table/locales/zh-CN.js +2 -0
  87. package/dist/decision-table/locales/zh-TW.cjs +36 -0
  88. package/dist/decision-table/locales/zh-TW.d.ts +3 -0
  89. package/dist/decision-table/locales/zh-TW.d.ts.map +1 -0
  90. package/dist/decision-table/locales/zh-TW.js +2 -0
  91. package/dist/decision-table/styles/tailwind.decision-table.css +1 -1
  92. package/dist/decision-table/useDragReorder.cjs +363 -52
  93. package/dist/decision-table/useDragReorder.d.ts +35 -5
  94. package/dist/decision-table/useDragReorder.d.ts.map +1 -1
  95. package/dist/decision-table/useDragReorder.js +342 -46
  96. package/dist/decision-table/useGridStrings.cjs +57 -0
  97. package/dist/decision-table/useGridStrings.d.ts +7 -0
  98. package/dist/decision-table/useGridStrings.d.ts.map +1 -0
  99. package/dist/decision-table/useGridStrings.js +23 -0
  100. package/dist/decision-table/useRowHover.cjs +89 -0
  101. package/dist/decision-table/useRowHover.d.ts +3 -0
  102. package/dist/decision-table/useRowHover.d.ts.map +1 -0
  103. package/dist/decision-table/useRowHover.js +55 -0
  104. package/dist/i18n/locale-registry.cjs +30 -0
  105. package/dist/i18n/locale-registry.d.ts.map +1 -1
  106. package/dist/i18n/locale-registry.js +32 -2
  107. package/package.json +4 -4
@@ -24,26 +24,53 @@ var __webpack_require__ = {};
24
24
  var __webpack_exports__ = {};
25
25
  __webpack_require__.r(__webpack_exports__);
26
26
  __webpack_require__.d(__webpack_exports__, {
27
- columnBoundaryForX: ()=>columnBoundaryForX,
27
+ bandGeometry: ()=>bandGeometry,
28
28
  useDragReorder: ()=>useDragReorder,
29
+ buildColumnPreview: ()=>buildColumnPreview,
30
+ usePressDrag: ()=>usePressDrag,
29
31
  dropIndex: ()=>dropIndex,
30
- rowBoundaryForY: ()=>rowBoundaryForY
32
+ gapStartPx: ()=>gapStartPx,
33
+ buildRowPreview: ()=>buildRowPreview,
34
+ dragShiftPx: ()=>dragShiftPx,
35
+ slotForCopy: ()=>slotForCopy
31
36
  });
32
37
  const external_react_namespaceObject = require("react");
33
38
  const external_constants_cjs_namespaceObject = require("./constants.cjs");
39
+ const toContent = (container, clientX, clientY)=>{
40
+ const rect = container.getBoundingClientRect();
41
+ return {
42
+ x: clientX - rect.left + container.scrollLeft,
43
+ y: clientY - rect.top + container.scrollTop
44
+ };
45
+ };
34
46
  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));
47
+ const dragShiftPx = (index, from, to, sizeAt)=>{
48
+ if (index === from) {
49
+ let passed = 0;
50
+ for(let other = Math.min(from, to); other <= Math.max(from, to); other++)passed += other === from ? 0 : sizeAt(other);
51
+ return to >= from ? passed : -passed;
52
+ }
53
+ if (from < index && index <= to) return -sizeAt(from);
54
+ return to <= index && index < from ? sizeAt(from) : 0;
55
+ };
56
+ const bandGeometry = (offsets, columnWidth, start)=>{
57
+ const left = (offsets[start + 1] ?? 0) - columnWidth(start);
58
+ return {
59
+ left,
60
+ offsetOf: (index)=>0 === index ? 0 : (offsets[start + index] ?? 0) - left,
61
+ sizeAt: (index)=>columnWidth(start + index)
62
+ };
38
63
  };
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;
64
+ const gapStartPx = (from, to, offsetOf, sizeAt)=>to > from ? offsetOf(to + 1) - sizeAt(from) : offsetOf(to);
65
+ const slotForCopy = (from, start, count, offsetOf, sizeAt)=>{
66
+ const centre = start + sizeAt(from) / 2;
67
+ let to = from;
68
+ for(let index = from - 1; index >= 0 && centre <= offsetOf(index) + sizeAt(index); index--)to = index;
69
+ for(let index = from + 1; index < count && centre >= offsetOf(index); index++)to = index;
70
+ return to > from ? to + 1 : to;
44
71
  };
45
72
  const useDragReorder = (options)=>{
46
- const { containerRef, headerHeight, columnLeading, columnOffsets, rowHeightPx, rowCount } = options;
73
+ const { containerRef, headerHeight, columnLeading, columnOffsets, columnWidth, rowHeightPx, rowCount } = options;
47
74
  const [dragState, setDragState] = (0, external_react_namespaceObject.useState)(null);
48
75
  const columnGroupBoundariesRef = (0, external_react_namespaceObject.useRef)(options.columnGroupBoundaries);
49
76
  columnGroupBoundariesRef.current = options.columnGroupBoundaries;
@@ -51,38 +78,98 @@ const useDragReorder = (options)=>{
51
78
  const pointerRef = (0, external_react_namespaceObject.useRef)(null);
52
79
  const rafRef = (0, external_react_namespaceObject.useRef)(null);
53
80
  const cancelRef = (0, external_react_namespaceObject.useRef)(null);
54
- const boundaryFromPointer = (0, external_react_namespaceObject.useCallback)((state, clientX, clientY)=>{
81
+ const grabOffsetRef = (0, external_react_namespaceObject.useRef)(0);
82
+ const columnGeometry = (0, external_react_namespaceObject.useCallback)((groupIndex, from)=>{
83
+ const offsets = columnOffsets();
84
+ const boundaries = columnGroupBoundariesRef.current;
85
+ const start = boundaries[groupIndex] ?? 0;
86
+ const end = boundaries[groupIndex + 1] ?? start;
87
+ const band = bandGeometry(offsets, columnWidth, start);
88
+ const bandLeft = columnLeading() + band.left;
89
+ return {
90
+ left: bandLeft + band.offsetOf(from),
91
+ width: band.sizeAt(from),
92
+ bandLeft,
93
+ bandRight: columnLeading() + (offsets[end] ?? 0)
94
+ };
95
+ }, [
96
+ columnLeading,
97
+ columnOffsets,
98
+ columnWidth
99
+ ]);
100
+ const columnLeftAt = (0, external_react_namespaceObject.useCallback)((groupIndex, from, clientX)=>{
101
+ const { left: resting, width, bandLeft, bandRight } = columnGeometry(groupIndex, from);
55
102
  const container = containerRef.current;
56
- if (!container) return state.boundary;
57
- const rect = container.getBoundingClientRect();
103
+ if (!container) return resting;
104
+ const left = toContent(container, clientX, 0).x - grabOffsetRef.current;
105
+ if (Number.isNaN(left)) return resting;
106
+ return Math.max(bandLeft, Math.min(bandRight - width, left));
107
+ }, [
108
+ containerRef,
109
+ columnGeometry
110
+ ]);
111
+ const rowTopAt = (0, external_react_namespaceObject.useCallback)((from, clientY)=>{
112
+ const resting = headerHeight() + from * rowHeightPx;
113
+ const container = containerRef.current;
114
+ if (!container) return resting;
115
+ const top = toContent(container, 0, clientY).y - grabOffsetRef.current;
116
+ if (Number.isNaN(top)) return resting;
117
+ const highest = container.scrollTop + headerHeight();
118
+ const lowest = Math.min(headerHeight() + (rowCount - 1) * rowHeightPx, container.scrollTop + container.clientHeight - rowHeightPx);
119
+ return Math.max(highest, Math.min(lowest, top));
120
+ }, [
121
+ containerRef,
122
+ headerHeight,
123
+ rowHeightPx,
124
+ rowCount
125
+ ]);
126
+ const boundaryFromPointer = (0, external_react_namespaceObject.useCallback)((state, clientX, clientY)=>{
58
127
  if ('row' === state.axis) {
59
- const y = clientY - rect.top + container.scrollTop - headerHeight();
60
- return rowBoundaryForY(y, rowHeightPx, rowCount, state.boundary);
128
+ const container = containerRef.current;
129
+ if (!container || Number.isNaN(clientY)) return state.boundary;
130
+ const top = toContent(container, 0, clientY).y - grabOffsetRef.current - headerHeight();
131
+ return slotForCopy(state.from, top, rowCount, (index)=>index * rowHeightPx, ()=>rowHeightPx);
61
132
  }
62
- const x = clientX - rect.left + container.scrollLeft - columnLeading();
133
+ if (Number.isNaN(clientX)) return state.boundary;
63
134
  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);
135
+ const start = boundaries[state.groupIndex] ?? 0;
136
+ const end = boundaries[state.groupIndex + 1] ?? start;
137
+ const container = containerRef.current;
138
+ if (!container) return state.boundary;
139
+ const band = bandGeometry(columnOffsets(), columnWidth, start);
140
+ const left = toContent(container, clientX, 0).x - grabOffsetRef.current - columnLeading() - band.left;
141
+ return slotForCopy(state.from, left, end - start, band.offsetOf, band.sizeAt);
68
142
  }, [
69
143
  containerRef,
70
144
  headerHeight,
71
145
  columnLeading,
72
146
  columnOffsets,
147
+ columnWidth,
73
148
  rowHeightPx,
74
149
  rowCount
75
150
  ]);
76
151
  const latestRef = (0, external_react_namespaceObject.useRef)({
77
152
  boundaryFromPointer,
153
+ rowTopAt,
154
+ columnLeftAt,
155
+ columnGeometry,
78
156
  onDropRow: options.onDropRow,
79
- onDropColumn: options.onDropColumn
157
+ onDropColumn: options.onDropColumn,
158
+ onDragMove: options.onDragMove
80
159
  });
81
160
  latestRef.current = {
82
161
  boundaryFromPointer,
162
+ rowTopAt,
163
+ columnLeftAt,
164
+ columnGeometry,
83
165
  onDropRow: options.onDropRow,
84
- onDropColumn: options.onDropColumn
166
+ onDropColumn: options.onDropColumn,
167
+ onDragMove: options.onDragMove
85
168
  };
169
+ const reportPosition = (0, external_react_namespaceObject.useCallback)((state, pointer)=>{
170
+ const latest = latestRef.current;
171
+ latest.onDragMove?.(state, 'row' === state.axis ? latest.rowTopAt(state.from, pointer.y) : latest.columnLeftAt(state.groupIndex, state.from, pointer.x));
172
+ }, []);
86
173
  const stopAutoscroll = (0, external_react_namespaceObject.useCallback)(()=>{
87
174
  if (null !== rafRef.current) {
88
175
  cancelAnimationFrame(rafRef.current);
@@ -104,7 +191,8 @@ const useDragReorder = (options)=>{
104
191
  else if (pointer.x < rect.left + columnLeading() + external_constants_cjs_namespaceObject.AUTOSCROLL_EDGE_PX) container.scrollLeft -= external_constants_cjs_namespaceObject.AUTOSCROLL_STEP_PX;
105
192
  const moved = ('row' === state.axis ? container.scrollTop : container.scrollLeft) !== before;
106
193
  if (moved) {
107
- const boundary = boundaryFromPointer(state, pointer.x, pointer.y);
194
+ reportPosition(state, pointer);
195
+ const boundary = latestRef.current.boundaryFromPointer(state, pointer.x, pointer.y);
108
196
  if (boundary !== state.boundary) {
109
197
  dragRef.current = {
110
198
  ...state,
@@ -118,20 +206,56 @@ const useDragReorder = (options)=>{
118
206
  containerRef,
119
207
  headerHeight,
120
208
  columnLeading,
121
- boundaryFromPointer
209
+ reportPosition
122
210
  ]);
123
211
  const beginDrag = (0, external_react_namespaceObject.useCallback)((initial, event)=>{
124
212
  cancelRef.current?.();
125
213
  const focused = document.activeElement;
126
214
  if (focused instanceof HTMLElement && focused.closest("input, textarea, [contenteditable='true']")) focused.blur();
127
215
  event.preventDefault();
128
- dragRef.current = initial;
129
- setDragState(initial);
216
+ const container = containerRef.current;
217
+ const pressed = event.press ?? event;
218
+ const grab = container ? toContent(container, pressed.clientX, pressed.clientY) : {
219
+ x: NaN,
220
+ y: NaN
221
+ };
222
+ const offset = 'row' === initial.axis ? grab.y - (headerHeight() + initial.from * rowHeightPx) : grab.x - latestRef.current.columnGeometry(initial.groupIndex, initial.from).left;
223
+ grabOffsetRef.current = Number.isNaN(offset) ? 0 : offset;
224
+ dragRef.current = {
225
+ ...initial,
226
+ boundary: latestRef.current.boundaryFromPointer(initial, event.clientX, event.clientY)
227
+ };
228
+ setDragState(dragRef.current);
130
229
  pointerRef.current = {
131
230
  x: event.clientX,
132
231
  y: event.clientY
133
232
  };
233
+ reportPosition(initial, {
234
+ x: event.clientX,
235
+ y: event.clientY
236
+ });
237
+ let owner = event.pointerId;
238
+ const isOwner = (pointerEvent)=>{
239
+ if (void 0 === pointerEvent.pointerId) return true;
240
+ owner ??= pointerEvent.pointerId;
241
+ return pointerEvent.pointerId === owner;
242
+ };
243
+ const retarget = (state, x, y)=>{
244
+ reportPosition(state, {
245
+ x,
246
+ y
247
+ });
248
+ const boundary = latestRef.current.boundaryFromPointer(state, x, y);
249
+ if (boundary !== state.boundary) {
250
+ dragRef.current = {
251
+ ...state,
252
+ boundary
253
+ };
254
+ setDragState(dragRef.current);
255
+ }
256
+ };
134
257
  const onPointerMove = (move)=>{
258
+ if (!isOwner(move)) return;
135
259
  if ((1 & move.buttons) === 0) return void cleanup();
136
260
  pointerRef.current = {
137
261
  x: move.clientX,
@@ -139,29 +263,39 @@ const useDragReorder = (options)=>{
139
263
  };
140
264
  const state = dragRef.current;
141
265
  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
- }
266
+ retarget(state, move.clientX, move.clientY);
150
267
  if (null === rafRef.current) rafRef.current = requestAnimationFrame(autoscrollLoop);
151
268
  };
269
+ const onScroll = ()=>{
270
+ const state = dragRef.current;
271
+ const pointer = pointerRef.current;
272
+ if (state && pointer) retarget(state, pointer.x, pointer.y);
273
+ };
274
+ const onPointerCancel = (cancel)=>{
275
+ if (isOwner(cancel)) cleanup();
276
+ };
277
+ const onVisibilityChange = ()=>{
278
+ if (document.hidden) cleanup();
279
+ };
152
280
  const cleanup = ()=>{
153
281
  document.removeEventListener('pointermove', onPointerMove);
154
282
  document.removeEventListener('pointerup', onPointerUp);
155
- document.removeEventListener('pointercancel', cleanup);
283
+ document.removeEventListener('pointercancel', onPointerCancel);
156
284
  document.removeEventListener('keydown', onKeyDown, true);
285
+ document.removeEventListener('visibilitychange', onVisibilityChange);
286
+ window.removeEventListener('blur', cleanup);
287
+ container?.removeEventListener('scroll', onScroll);
157
288
  stopAutoscroll();
289
+ const ended = dragRef.current;
290
+ if (ended) latestRef.current.onDragMove?.(ended, null);
158
291
  pointerRef.current = null;
159
292
  dragRef.current = null;
160
293
  cancelRef.current = null;
161
294
  setDragState(null);
162
295
  };
163
296
  cancelRef.current = cleanup;
164
- const onPointerUp = ()=>{
297
+ const onPointerUp = (up)=>{
298
+ if (!isOwner(up)) return;
165
299
  const state = dragRef.current;
166
300
  try {
167
301
  if (state) {
@@ -174,34 +308,55 @@ const useDragReorder = (options)=>{
174
308
  }
175
309
  };
176
310
  const onKeyDown = (key)=>{
177
- if ('Escape' === key.key) {
178
- key.stopPropagation();
179
- cleanup();
180
- }
311
+ key.stopPropagation();
312
+ key.preventDefault();
313
+ if ('Escape' === key.key) cleanup();
181
314
  };
182
315
  document.addEventListener('pointermove', onPointerMove);
183
316
  document.addEventListener('pointerup', onPointerUp);
184
- document.addEventListener('pointercancel', cleanup);
317
+ document.addEventListener('pointercancel', onPointerCancel);
185
318
  document.addEventListener('keydown', onKeyDown, true);
319
+ document.addEventListener('visibilitychange', onVisibilityChange);
320
+ window.addEventListener('blur', cleanup);
321
+ container?.addEventListener('scroll', onScroll, {
322
+ passive: true
323
+ });
324
+ if (null === rafRef.current) rafRef.current = requestAnimationFrame(autoscrollLoop);
325
+ return true;
186
326
  }, [
187
327
  autoscrollLoop,
188
- stopAutoscroll
328
+ stopAutoscroll,
329
+ containerRef,
330
+ headerHeight,
331
+ rowHeightPx,
332
+ reportPosition
189
333
  ]);
190
- const startRowDrag = (0, external_react_namespaceObject.useCallback)((rowIndex, event)=>beginDrag({
334
+ const startRowDrag = (0, external_react_namespaceObject.useCallback)((rowIndex, event)=>Number.isInteger(rowIndex) && rowIndex >= 0 && rowIndex < rowCount && beginDrag({
191
335
  axis: 'row',
192
336
  from: rowIndex,
193
337
  boundary: rowIndex
194
338
  }, event), [
195
- beginDrag
339
+ beginDrag,
340
+ rowCount
196
341
  ]);
197
- const startColumnDrag = (0, external_react_namespaceObject.useCallback)((groupIndex, indexInGroup, event)=>beginDrag({
342
+ const startColumnDrag = (0, external_react_namespaceObject.useCallback)((groupIndex, indexInGroup, event)=>{
343
+ const boundaries = columnGroupBoundariesRef.current;
344
+ const size = (boundaries[groupIndex + 1] ?? 0) - (boundaries[groupIndex] ?? 0);
345
+ return Number.isInteger(groupIndex) && Number.isInteger(indexInGroup) && groupIndex >= 0 && groupIndex < boundaries.length - 1 && indexInGroup >= 0 && indexInGroup < size && beginDrag({
198
346
  axis: 'column',
199
347
  groupIndex,
200
348
  from: indexInGroup,
201
349
  boundary: indexInGroup
202
- }, event), [
350
+ }, event);
351
+ }, [
203
352
  beginDrag
204
353
  ]);
354
+ const shapeKey = `${rowCount}|${options.columnGroupBoundaries.join(',')}`;
355
+ (0, external_react_namespaceObject.useEffect)(()=>{
356
+ cancelRef.current?.();
357
+ }, [
358
+ shapeKey
359
+ ]);
205
360
  (0, external_react_namespaceObject.useEffect)(()=>()=>{
206
361
  cancelRef.current?.();
207
362
  stopAutoscroll();
@@ -214,15 +369,171 @@ const useDragReorder = (options)=>{
214
369
  startColumnDrag
215
370
  };
216
371
  };
217
- exports.columnBoundaryForX = __webpack_exports__.columnBoundaryForX;
372
+ const PRESS_DRAG_THRESHOLD_PX = 4;
373
+ const armPressDrag = (press, start)=>{
374
+ const { clientX: startX, clientY: startY, pointerId } = press;
375
+ const isOwn = (event)=>void 0 === pointerId || void 0 === event.pointerId || event.pointerId === pointerId;
376
+ const onEnd = (end)=>{
377
+ if (isOwn(end)) disarm();
378
+ };
379
+ const onHidden = ()=>{
380
+ if ('hidden' === document.visibilityState) disarm();
381
+ };
382
+ const disarm = ()=>{
383
+ document.removeEventListener('pointermove', onMove);
384
+ document.removeEventListener('pointerup', onEnd);
385
+ document.removeEventListener('pointercancel', onEnd);
386
+ document.removeEventListener('visibilitychange', onHidden);
387
+ window.removeEventListener('blur', disarm);
388
+ };
389
+ const onMove = (move)=>{
390
+ if (!isOwn(move)) return;
391
+ if ((1 & move.buttons) === 0) return void disarm();
392
+ if (Math.hypot(move.clientX - startX, move.clientY - startY) < PRESS_DRAG_THRESHOLD_PX) return;
393
+ disarm();
394
+ start({
395
+ clientX: move.clientX,
396
+ clientY: move.clientY,
397
+ preventDefault: ()=>move.preventDefault(),
398
+ press: {
399
+ clientX: startX,
400
+ clientY: startY
401
+ },
402
+ pointerId: move.pointerId
403
+ });
404
+ };
405
+ document.addEventListener('pointermove', onMove);
406
+ document.addEventListener('pointerup', onEnd);
407
+ document.addEventListener('pointercancel', onEnd);
408
+ document.addEventListener('visibilitychange', onHidden);
409
+ window.addEventListener('blur', disarm);
410
+ return disarm;
411
+ };
412
+ const usePressDrag = (position)=>{
413
+ const disarmRef = (0, external_react_namespaceObject.useRef)(null);
414
+ const draggedRef = (0, external_react_namespaceObject.useRef)(false);
415
+ (0, external_react_namespaceObject.useEffect)(()=>()=>disarmRef.current?.(), position);
416
+ const press = (0, external_react_namespaceObject.useCallback)((event, start)=>{
417
+ draggedRef.current = false;
418
+ disarmRef.current?.();
419
+ disarmRef.current = start ? armPressDrag(event, (move)=>{
420
+ draggedRef.current = start(move);
421
+ }) : null;
422
+ }, []);
423
+ const clickWasDrag = (0, external_react_namespaceObject.useCallback)(()=>{
424
+ const dragged = draggedRef.current;
425
+ draggedRef.current = false;
426
+ return dragged;
427
+ }, []);
428
+ return {
429
+ press,
430
+ clickWasDrag
431
+ };
432
+ };
433
+ const buildRowPreview = (container, ariaRowIndex)=>{
434
+ const table = container?.querySelector(':scope > table');
435
+ const source = table?.querySelector(`:scope > tbody > tr[aria-rowindex="${ariaRowIndex}"]`);
436
+ if (!(table instanceof HTMLTableElement) || !(source instanceof HTMLTableRowElement)) return null;
437
+ const shell = table.cloneNode(false);
438
+ const colgroup = table.querySelector(':scope > colgroup');
439
+ if (colgroup) shell.append(colgroup.cloneNode(true));
440
+ const body = document.createElement('tbody');
441
+ body.append(source.cloneNode(true));
442
+ shell.append(body);
443
+ stripIdentity(shell);
444
+ return {
445
+ table: shell,
446
+ sources: [
447
+ source
448
+ ]
449
+ };
450
+ };
451
+ const stripIdentity = (shell)=>{
452
+ shell.removeAttribute('aria-label');
453
+ shell.removeAttribute('aria-rowcount');
454
+ shell.setAttribute('inert', '');
455
+ for (const element of [
456
+ shell,
457
+ ...shell.querySelectorAll('[id], [data-testid]')
458
+ ]){
459
+ element.removeAttribute('id');
460
+ element.removeAttribute('data-testid');
461
+ }
462
+ for (const element of shell.querySelectorAll('[data-drag-source], [style]')){
463
+ element.removeAttribute('data-drag-source');
464
+ element.style.transform = '';
465
+ element.style.transition = '';
466
+ }
467
+ };
468
+ const buildColumnPreview = (container, { headerCellIndex, bodyCellIndex, widthPx })=>{
469
+ const table = container?.querySelector(':scope > table');
470
+ if (!(table instanceof HTMLTableElement) || !table.tHead || !table.tBodies[0]) return null;
471
+ const headerRows = Array.from(table.tHead.rows);
472
+ const headerRow = headerRows[headerRows.length - 1];
473
+ const header = headerRow?.cells[headerCellIndex];
474
+ if (!header) return null;
475
+ const shell = table.cloneNode(false);
476
+ shell.style.width = `${widthPx}px`;
477
+ const colgroup = document.createElement('colgroup');
478
+ const col = document.createElement('col');
479
+ col.style.width = `${widthPx}px`;
480
+ colgroup.append(col);
481
+ const head = document.createElement('thead');
482
+ for (const row of headerRows.slice(0, -1)){
483
+ const blank = document.createElement('tr');
484
+ const cell = document.createElement('th');
485
+ cell.style.height = `${row.getBoundingClientRect().height}px`;
486
+ cell.style.padding = '0';
487
+ cell.style.border = '0';
488
+ blank.append(cell);
489
+ head.append(blank);
490
+ }
491
+ const headerCopy = document.createElement('tr');
492
+ headerCopy.append(header.cloneNode(true));
493
+ head.append(headerCopy);
494
+ const sources = [
495
+ header
496
+ ];
497
+ const body = document.createElement('tbody');
498
+ for (const row of Array.from(table.tBodies[0].rows)){
499
+ if ('presentation' === row.getAttribute('role')) {
500
+ body.append(row.cloneNode(true));
501
+ continue;
502
+ }
503
+ const cell = row.cells[bodyCellIndex];
504
+ if (!cell || 1 === row.cells.length) continue;
505
+ const copy = row.cloneNode(false);
506
+ copy.append(cell.cloneNode(true));
507
+ body.append(copy);
508
+ sources.push(cell);
509
+ }
510
+ shell.append(colgroup, head, body);
511
+ stripIdentity(shell);
512
+ for (const spacer of shell.querySelectorAll("tbody > tr[role='presentation'] > td"))spacer.colSpan = 1;
513
+ return {
514
+ table: shell,
515
+ sources
516
+ };
517
+ };
518
+ exports.bandGeometry = __webpack_exports__.bandGeometry;
519
+ exports.buildColumnPreview = __webpack_exports__.buildColumnPreview;
520
+ exports.buildRowPreview = __webpack_exports__.buildRowPreview;
521
+ exports.dragShiftPx = __webpack_exports__.dragShiftPx;
218
522
  exports.dropIndex = __webpack_exports__.dropIndex;
219
- exports.rowBoundaryForY = __webpack_exports__.rowBoundaryForY;
523
+ exports.gapStartPx = __webpack_exports__.gapStartPx;
524
+ exports.slotForCopy = __webpack_exports__.slotForCopy;
220
525
  exports.useDragReorder = __webpack_exports__.useDragReorder;
526
+ exports.usePressDrag = __webpack_exports__.usePressDrag;
221
527
  for(var __rspack_i in __webpack_exports__)if (-1 === [
222
- "columnBoundaryForX",
528
+ "bandGeometry",
529
+ "buildColumnPreview",
530
+ "buildRowPreview",
531
+ "dragShiftPx",
223
532
  "dropIndex",
224
- "rowBoundaryForY",
225
- "useDragReorder"
533
+ "gapStartPx",
534
+ "slotForCopy",
535
+ "useDragReorder",
536
+ "usePressDrag"
226
537
  ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
227
538
  Object.defineProperty(exports, '__esModule', {
228
539
  value: true
@@ -1,4 +1,6 @@
1
- type DragReorderState = {
1
+ import { type DependencyList } from 'react';
2
+ import type { DragStartEvent } from './gridTypes';
3
+ export type DragReorderState = {
2
4
  axis: 'row';
3
5
  from: number;
4
6
  boundary: number;
@@ -13,19 +15,47 @@ interface DragReorderOptions {
13
15
  headerHeight: () => number;
14
16
  columnLeading: () => number;
15
17
  columnOffsets: () => number[];
18
+ columnWidth: (dataIndex: number) => number;
16
19
  rowHeightPx: number;
17
20
  rowCount: number;
18
21
  columnGroupBoundaries: number[];
19
22
  onDropRow: (from: number, to: number) => void;
20
23
  onDropColumn: (groupIndex: number, from: number, to: number) => void;
24
+ onDragMove?: (state: DragReorderState, px: number | null) => void;
21
25
  }
22
26
  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;
27
+ export declare const dragShiftPx: (index: number, from: number, to: number, sizeAt: (index: number) => number) => number;
28
+ export declare const bandGeometry: (offsets: number[], columnWidth: (dataIndex: number) => number, start: number) => {
29
+ left: number;
30
+ offsetOf: (index: number) => number;
31
+ sizeAt: (index: number) => number;
32
+ };
33
+ export declare const gapStartPx: (from: number, to: number, offsetOf: (index: number) => number, sizeAt: (index: number) => number) => number;
34
+ export declare const slotForCopy: (from: number, start: number, count: number, offsetOf: (index: number) => number, sizeAt: (index: number) => number) => number;
25
35
  export declare const useDragReorder: (options: DragReorderOptions) => {
26
36
  dragState: DragReorderState | null;
27
- startRowDrag: (rowIndex: number, event: React.PointerEvent) => void;
28
- startColumnDrag: (groupIndex: number, indexInGroup: number, event: React.PointerEvent) => void;
37
+ startRowDrag: (rowIndex: number, event: DragStartEvent) => boolean;
38
+ startColumnDrag: (groupIndex: number, indexInGroup: number, event: DragStartEvent) => boolean;
39
+ };
40
+ export declare const usePressDrag: (position: DependencyList) => {
41
+ press: (event: {
42
+ clientX: number;
43
+ clientY: number;
44
+ pointerId?: number;
45
+ }, start: ((move: DragStartEvent) => boolean) | null) => void;
46
+ clickWasDrag: () => boolean;
29
47
  };
48
+ export declare const buildRowPreview: (container: HTMLElement | null, ariaRowIndex: number) => {
49
+ table: HTMLTableElement;
50
+ sources: HTMLElement[];
51
+ } | null;
52
+ export declare const buildColumnPreview: (container: HTMLElement | null, { headerCellIndex, bodyCellIndex, widthPx, }: {
53
+ headerCellIndex: number;
54
+ bodyCellIndex: number;
55
+ widthPx: number;
56
+ }) => {
57
+ table: HTMLTableElement;
58
+ sources: HTMLElement[];
59
+ } | null;
30
60
  export {};
31
61
  //# sourceMappingURL=useDragReorder.d.ts.map
@@ -1 +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,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