@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
@@ -1,18 +1,40 @@
1
1
  import { useCallback, useEffect, useRef, useState } from "react";
2
2
  import { AUTOSCROLL_EDGE_PX, AUTOSCROLL_STEP_PX } from "./constants.js";
3
+ const toContent = (container, clientX, clientY)=>{
4
+ const rect = container.getBoundingClientRect();
5
+ return {
6
+ x: clientX - rect.left + container.scrollLeft,
7
+ y: clientY - rect.top + container.scrollTop
8
+ };
9
+ };
3
10
  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));
11
+ const dragShiftPx = (index, from, to, sizeAt)=>{
12
+ if (index === from) {
13
+ let passed = 0;
14
+ for(let other = Math.min(from, to); other <= Math.max(from, to); other++)passed += other === from ? 0 : sizeAt(other);
15
+ return to >= from ? passed : -passed;
16
+ }
17
+ if (from < index && index <= to) return -sizeAt(from);
18
+ return to <= index && index < from ? sizeAt(from) : 0;
19
+ };
20
+ const bandGeometry = (offsets, columnWidth, start)=>{
21
+ const left = (offsets[start + 1] ?? 0) - columnWidth(start);
22
+ return {
23
+ left,
24
+ offsetOf: (index)=>0 === index ? 0 : (offsets[start + index] ?? 0) - left,
25
+ sizeAt: (index)=>columnWidth(start + index)
26
+ };
7
27
  };
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;
28
+ const gapStartPx = (from, to, offsetOf, sizeAt)=>to > from ? offsetOf(to + 1) - sizeAt(from) : offsetOf(to);
29
+ const slotForCopy = (from, start, count, offsetOf, sizeAt)=>{
30
+ const centre = start + sizeAt(from) / 2;
31
+ let to = from;
32
+ for(let index = from - 1; index >= 0 && centre <= offsetOf(index) + sizeAt(index); index--)to = index;
33
+ for(let index = from + 1; index < count && centre >= offsetOf(index); index++)to = index;
34
+ return to > from ? to + 1 : to;
13
35
  };
14
36
  const useDragReorder = (options)=>{
15
- const { containerRef, headerHeight, columnLeading, columnOffsets, rowHeightPx, rowCount } = options;
37
+ const { containerRef, headerHeight, columnLeading, columnOffsets, columnWidth, rowHeightPx, rowCount } = options;
16
38
  const [dragState, setDragState] = useState(null);
17
39
  const columnGroupBoundariesRef = useRef(options.columnGroupBoundaries);
18
40
  columnGroupBoundariesRef.current = options.columnGroupBoundaries;
@@ -20,38 +42,98 @@ const useDragReorder = (options)=>{
20
42
  const pointerRef = useRef(null);
21
43
  const rafRef = useRef(null);
22
44
  const cancelRef = useRef(null);
23
- const boundaryFromPointer = useCallback((state, clientX, clientY)=>{
45
+ const grabOffsetRef = useRef(0);
46
+ const columnGeometry = useCallback((groupIndex, from)=>{
47
+ const offsets = columnOffsets();
48
+ const boundaries = columnGroupBoundariesRef.current;
49
+ const start = boundaries[groupIndex] ?? 0;
50
+ const end = boundaries[groupIndex + 1] ?? start;
51
+ const band = bandGeometry(offsets, columnWidth, start);
52
+ const bandLeft = columnLeading() + band.left;
53
+ return {
54
+ left: bandLeft + band.offsetOf(from),
55
+ width: band.sizeAt(from),
56
+ bandLeft,
57
+ bandRight: columnLeading() + (offsets[end] ?? 0)
58
+ };
59
+ }, [
60
+ columnLeading,
61
+ columnOffsets,
62
+ columnWidth
63
+ ]);
64
+ const columnLeftAt = useCallback((groupIndex, from, clientX)=>{
65
+ const { left: resting, width, bandLeft, bandRight } = columnGeometry(groupIndex, from);
24
66
  const container = containerRef.current;
25
- if (!container) return state.boundary;
26
- const rect = container.getBoundingClientRect();
67
+ if (!container) return resting;
68
+ const left = toContent(container, clientX, 0).x - grabOffsetRef.current;
69
+ if (Number.isNaN(left)) return resting;
70
+ return Math.max(bandLeft, Math.min(bandRight - width, left));
71
+ }, [
72
+ containerRef,
73
+ columnGeometry
74
+ ]);
75
+ const rowTopAt = useCallback((from, clientY)=>{
76
+ const resting = headerHeight() + from * rowHeightPx;
77
+ const container = containerRef.current;
78
+ if (!container) return resting;
79
+ const top = toContent(container, 0, clientY).y - grabOffsetRef.current;
80
+ if (Number.isNaN(top)) return resting;
81
+ const highest = container.scrollTop + headerHeight();
82
+ const lowest = Math.min(headerHeight() + (rowCount - 1) * rowHeightPx, container.scrollTop + container.clientHeight - rowHeightPx);
83
+ return Math.max(highest, Math.min(lowest, top));
84
+ }, [
85
+ containerRef,
86
+ headerHeight,
87
+ rowHeightPx,
88
+ rowCount
89
+ ]);
90
+ const boundaryFromPointer = useCallback((state, clientX, clientY)=>{
27
91
  if ('row' === state.axis) {
28
- const y = clientY - rect.top + container.scrollTop - headerHeight();
29
- return rowBoundaryForY(y, rowHeightPx, rowCount, state.boundary);
92
+ const container = containerRef.current;
93
+ if (!container || Number.isNaN(clientY)) return state.boundary;
94
+ const top = toContent(container, 0, clientY).y - grabOffsetRef.current - headerHeight();
95
+ return slotForCopy(state.from, top, rowCount, (index)=>index * rowHeightPx, ()=>rowHeightPx);
30
96
  }
31
- const x = clientX - rect.left + container.scrollLeft - columnLeading();
97
+ if (Number.isNaN(clientX)) return state.boundary;
32
98
  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);
99
+ const start = boundaries[state.groupIndex] ?? 0;
100
+ const end = boundaries[state.groupIndex + 1] ?? start;
101
+ const container = containerRef.current;
102
+ if (!container) return state.boundary;
103
+ const band = bandGeometry(columnOffsets(), columnWidth, start);
104
+ const left = toContent(container, clientX, 0).x - grabOffsetRef.current - columnLeading() - band.left;
105
+ return slotForCopy(state.from, left, end - start, band.offsetOf, band.sizeAt);
37
106
  }, [
38
107
  containerRef,
39
108
  headerHeight,
40
109
  columnLeading,
41
110
  columnOffsets,
111
+ columnWidth,
42
112
  rowHeightPx,
43
113
  rowCount
44
114
  ]);
45
115
  const latestRef = useRef({
46
116
  boundaryFromPointer,
117
+ rowTopAt,
118
+ columnLeftAt,
119
+ columnGeometry,
47
120
  onDropRow: options.onDropRow,
48
- onDropColumn: options.onDropColumn
121
+ onDropColumn: options.onDropColumn,
122
+ onDragMove: options.onDragMove
49
123
  });
50
124
  latestRef.current = {
51
125
  boundaryFromPointer,
126
+ rowTopAt,
127
+ columnLeftAt,
128
+ columnGeometry,
52
129
  onDropRow: options.onDropRow,
53
- onDropColumn: options.onDropColumn
130
+ onDropColumn: options.onDropColumn,
131
+ onDragMove: options.onDragMove
54
132
  };
133
+ const reportPosition = useCallback((state, pointer)=>{
134
+ const latest = latestRef.current;
135
+ latest.onDragMove?.(state, 'row' === state.axis ? latest.rowTopAt(state.from, pointer.y) : latest.columnLeftAt(state.groupIndex, state.from, pointer.x));
136
+ }, []);
55
137
  const stopAutoscroll = useCallback(()=>{
56
138
  if (null !== rafRef.current) {
57
139
  cancelAnimationFrame(rafRef.current);
@@ -73,7 +155,8 @@ const useDragReorder = (options)=>{
73
155
  else if (pointer.x < rect.left + columnLeading() + AUTOSCROLL_EDGE_PX) container.scrollLeft -= AUTOSCROLL_STEP_PX;
74
156
  const moved = ('row' === state.axis ? container.scrollTop : container.scrollLeft) !== before;
75
157
  if (moved) {
76
- const boundary = boundaryFromPointer(state, pointer.x, pointer.y);
158
+ reportPosition(state, pointer);
159
+ const boundary = latestRef.current.boundaryFromPointer(state, pointer.x, pointer.y);
77
160
  if (boundary !== state.boundary) {
78
161
  dragRef.current = {
79
162
  ...state,
@@ -87,20 +170,56 @@ const useDragReorder = (options)=>{
87
170
  containerRef,
88
171
  headerHeight,
89
172
  columnLeading,
90
- boundaryFromPointer
173
+ reportPosition
91
174
  ]);
92
175
  const beginDrag = useCallback((initial, event)=>{
93
176
  cancelRef.current?.();
94
177
  const focused = document.activeElement;
95
178
  if (focused instanceof HTMLElement && focused.closest("input, textarea, [contenteditable='true']")) focused.blur();
96
179
  event.preventDefault();
97
- dragRef.current = initial;
98
- setDragState(initial);
180
+ const container = containerRef.current;
181
+ const pressed = event.press ?? event;
182
+ const grab = container ? toContent(container, pressed.clientX, pressed.clientY) : {
183
+ x: NaN,
184
+ y: NaN
185
+ };
186
+ const offset = 'row' === initial.axis ? grab.y - (headerHeight() + initial.from * rowHeightPx) : grab.x - latestRef.current.columnGeometry(initial.groupIndex, initial.from).left;
187
+ grabOffsetRef.current = Number.isNaN(offset) ? 0 : offset;
188
+ dragRef.current = {
189
+ ...initial,
190
+ boundary: latestRef.current.boundaryFromPointer(initial, event.clientX, event.clientY)
191
+ };
192
+ setDragState(dragRef.current);
99
193
  pointerRef.current = {
100
194
  x: event.clientX,
101
195
  y: event.clientY
102
196
  };
197
+ reportPosition(initial, {
198
+ x: event.clientX,
199
+ y: event.clientY
200
+ });
201
+ let owner = event.pointerId;
202
+ const isOwner = (pointerEvent)=>{
203
+ if (void 0 === pointerEvent.pointerId) return true;
204
+ owner ??= pointerEvent.pointerId;
205
+ return pointerEvent.pointerId === owner;
206
+ };
207
+ const retarget = (state, x, y)=>{
208
+ reportPosition(state, {
209
+ x,
210
+ y
211
+ });
212
+ const boundary = latestRef.current.boundaryFromPointer(state, x, y);
213
+ if (boundary !== state.boundary) {
214
+ dragRef.current = {
215
+ ...state,
216
+ boundary
217
+ };
218
+ setDragState(dragRef.current);
219
+ }
220
+ };
103
221
  const onPointerMove = (move)=>{
222
+ if (!isOwner(move)) return;
104
223
  if ((1 & move.buttons) === 0) return void cleanup();
105
224
  pointerRef.current = {
106
225
  x: move.clientX,
@@ -108,29 +227,39 @@ const useDragReorder = (options)=>{
108
227
  };
109
228
  const state = dragRef.current;
110
229
  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
- }
230
+ retarget(state, move.clientX, move.clientY);
119
231
  if (null === rafRef.current) rafRef.current = requestAnimationFrame(autoscrollLoop);
120
232
  };
233
+ const onScroll = ()=>{
234
+ const state = dragRef.current;
235
+ const pointer = pointerRef.current;
236
+ if (state && pointer) retarget(state, pointer.x, pointer.y);
237
+ };
238
+ const onPointerCancel = (cancel)=>{
239
+ if (isOwner(cancel)) cleanup();
240
+ };
241
+ const onVisibilityChange = ()=>{
242
+ if (document.hidden) cleanup();
243
+ };
121
244
  const cleanup = ()=>{
122
245
  document.removeEventListener('pointermove', onPointerMove);
123
246
  document.removeEventListener('pointerup', onPointerUp);
124
- document.removeEventListener('pointercancel', cleanup);
247
+ document.removeEventListener('pointercancel', onPointerCancel);
125
248
  document.removeEventListener('keydown', onKeyDown, true);
249
+ document.removeEventListener('visibilitychange', onVisibilityChange);
250
+ window.removeEventListener('blur', cleanup);
251
+ container?.removeEventListener('scroll', onScroll);
126
252
  stopAutoscroll();
253
+ const ended = dragRef.current;
254
+ if (ended) latestRef.current.onDragMove?.(ended, null);
127
255
  pointerRef.current = null;
128
256
  dragRef.current = null;
129
257
  cancelRef.current = null;
130
258
  setDragState(null);
131
259
  };
132
260
  cancelRef.current = cleanup;
133
- const onPointerUp = ()=>{
261
+ const onPointerUp = (up)=>{
262
+ if (!isOwner(up)) return;
134
263
  const state = dragRef.current;
135
264
  try {
136
265
  if (state) {
@@ -143,34 +272,55 @@ const useDragReorder = (options)=>{
143
272
  }
144
273
  };
145
274
  const onKeyDown = (key)=>{
146
- if ('Escape' === key.key) {
147
- key.stopPropagation();
148
- cleanup();
149
- }
275
+ key.stopPropagation();
276
+ key.preventDefault();
277
+ if ('Escape' === key.key) cleanup();
150
278
  };
151
279
  document.addEventListener('pointermove', onPointerMove);
152
280
  document.addEventListener('pointerup', onPointerUp);
153
- document.addEventListener('pointercancel', cleanup);
281
+ document.addEventListener('pointercancel', onPointerCancel);
154
282
  document.addEventListener('keydown', onKeyDown, true);
283
+ document.addEventListener('visibilitychange', onVisibilityChange);
284
+ window.addEventListener('blur', cleanup);
285
+ container?.addEventListener('scroll', onScroll, {
286
+ passive: true
287
+ });
288
+ if (null === rafRef.current) rafRef.current = requestAnimationFrame(autoscrollLoop);
289
+ return true;
155
290
  }, [
156
291
  autoscrollLoop,
157
- stopAutoscroll
292
+ stopAutoscroll,
293
+ containerRef,
294
+ headerHeight,
295
+ rowHeightPx,
296
+ reportPosition
158
297
  ]);
159
- const startRowDrag = useCallback((rowIndex, event)=>beginDrag({
298
+ const startRowDrag = useCallback((rowIndex, event)=>Number.isInteger(rowIndex) && rowIndex >= 0 && rowIndex < rowCount && beginDrag({
160
299
  axis: 'row',
161
300
  from: rowIndex,
162
301
  boundary: rowIndex
163
302
  }, event), [
164
- beginDrag
303
+ beginDrag,
304
+ rowCount
165
305
  ]);
166
- const startColumnDrag = useCallback((groupIndex, indexInGroup, event)=>beginDrag({
306
+ const startColumnDrag = useCallback((groupIndex, indexInGroup, event)=>{
307
+ const boundaries = columnGroupBoundariesRef.current;
308
+ const size = (boundaries[groupIndex + 1] ?? 0) - (boundaries[groupIndex] ?? 0);
309
+ return Number.isInteger(groupIndex) && Number.isInteger(indexInGroup) && groupIndex >= 0 && groupIndex < boundaries.length - 1 && indexInGroup >= 0 && indexInGroup < size && beginDrag({
167
310
  axis: 'column',
168
311
  groupIndex,
169
312
  from: indexInGroup,
170
313
  boundary: indexInGroup
171
- }, event), [
314
+ }, event);
315
+ }, [
172
316
  beginDrag
173
317
  ]);
318
+ const shapeKey = `${rowCount}|${options.columnGroupBoundaries.join(',')}`;
319
+ useEffect(()=>{
320
+ cancelRef.current?.();
321
+ }, [
322
+ shapeKey
323
+ ]);
174
324
  useEffect(()=>()=>{
175
325
  cancelRef.current?.();
176
326
  stopAutoscroll();
@@ -183,4 +333,150 @@ const useDragReorder = (options)=>{
183
333
  startColumnDrag
184
334
  };
185
335
  };
186
- export { columnBoundaryForX, dropIndex, rowBoundaryForY, useDragReorder };
336
+ const PRESS_DRAG_THRESHOLD_PX = 4;
337
+ const armPressDrag = (press, start)=>{
338
+ const { clientX: startX, clientY: startY, pointerId } = press;
339
+ const isOwn = (event)=>void 0 === pointerId || void 0 === event.pointerId || event.pointerId === pointerId;
340
+ const onEnd = (end)=>{
341
+ if (isOwn(end)) disarm();
342
+ };
343
+ const onHidden = ()=>{
344
+ if ('hidden' === document.visibilityState) disarm();
345
+ };
346
+ const disarm = ()=>{
347
+ document.removeEventListener('pointermove', onMove);
348
+ document.removeEventListener('pointerup', onEnd);
349
+ document.removeEventListener('pointercancel', onEnd);
350
+ document.removeEventListener('visibilitychange', onHidden);
351
+ window.removeEventListener('blur', disarm);
352
+ };
353
+ const onMove = (move)=>{
354
+ if (!isOwn(move)) return;
355
+ if ((1 & move.buttons) === 0) return void disarm();
356
+ if (Math.hypot(move.clientX - startX, move.clientY - startY) < PRESS_DRAG_THRESHOLD_PX) return;
357
+ disarm();
358
+ start({
359
+ clientX: move.clientX,
360
+ clientY: move.clientY,
361
+ preventDefault: ()=>move.preventDefault(),
362
+ press: {
363
+ clientX: startX,
364
+ clientY: startY
365
+ },
366
+ pointerId: move.pointerId
367
+ });
368
+ };
369
+ document.addEventListener('pointermove', onMove);
370
+ document.addEventListener('pointerup', onEnd);
371
+ document.addEventListener('pointercancel', onEnd);
372
+ document.addEventListener('visibilitychange', onHidden);
373
+ window.addEventListener('blur', disarm);
374
+ return disarm;
375
+ };
376
+ const usePressDrag = (position)=>{
377
+ const disarmRef = useRef(null);
378
+ const draggedRef = useRef(false);
379
+ useEffect(()=>()=>disarmRef.current?.(), position);
380
+ const press = useCallback((event, start)=>{
381
+ draggedRef.current = false;
382
+ disarmRef.current?.();
383
+ disarmRef.current = start ? armPressDrag(event, (move)=>{
384
+ draggedRef.current = start(move);
385
+ }) : null;
386
+ }, []);
387
+ const clickWasDrag = useCallback(()=>{
388
+ const dragged = draggedRef.current;
389
+ draggedRef.current = false;
390
+ return dragged;
391
+ }, []);
392
+ return {
393
+ press,
394
+ clickWasDrag
395
+ };
396
+ };
397
+ const buildRowPreview = (container, ariaRowIndex)=>{
398
+ const table = container?.querySelector(':scope > table');
399
+ const source = table?.querySelector(`:scope > tbody > tr[aria-rowindex="${ariaRowIndex}"]`);
400
+ if (!(table instanceof HTMLTableElement) || !(source instanceof HTMLTableRowElement)) return null;
401
+ const shell = table.cloneNode(false);
402
+ const colgroup = table.querySelector(':scope > colgroup');
403
+ if (colgroup) shell.append(colgroup.cloneNode(true));
404
+ const body = document.createElement('tbody');
405
+ body.append(source.cloneNode(true));
406
+ shell.append(body);
407
+ stripIdentity(shell);
408
+ return {
409
+ table: shell,
410
+ sources: [
411
+ source
412
+ ]
413
+ };
414
+ };
415
+ const stripIdentity = (shell)=>{
416
+ shell.removeAttribute('aria-label');
417
+ shell.removeAttribute('aria-rowcount');
418
+ shell.setAttribute('inert', '');
419
+ for (const element of [
420
+ shell,
421
+ ...shell.querySelectorAll('[id], [data-testid]')
422
+ ]){
423
+ element.removeAttribute('id');
424
+ element.removeAttribute('data-testid');
425
+ }
426
+ for (const element of shell.querySelectorAll('[data-drag-source], [style]')){
427
+ element.removeAttribute('data-drag-source');
428
+ element.style.transform = '';
429
+ element.style.transition = '';
430
+ }
431
+ };
432
+ const buildColumnPreview = (container, { headerCellIndex, bodyCellIndex, widthPx })=>{
433
+ const table = container?.querySelector(':scope > table');
434
+ if (!(table instanceof HTMLTableElement) || !table.tHead || !table.tBodies[0]) return null;
435
+ const headerRows = Array.from(table.tHead.rows);
436
+ const headerRow = headerRows[headerRows.length - 1];
437
+ const header = headerRow?.cells[headerCellIndex];
438
+ if (!header) return null;
439
+ const shell = table.cloneNode(false);
440
+ shell.style.width = `${widthPx}px`;
441
+ const colgroup = document.createElement('colgroup');
442
+ const col = document.createElement('col');
443
+ col.style.width = `${widthPx}px`;
444
+ colgroup.append(col);
445
+ const head = document.createElement('thead');
446
+ for (const row of headerRows.slice(0, -1)){
447
+ const blank = document.createElement('tr');
448
+ const cell = document.createElement('th');
449
+ cell.style.height = `${row.getBoundingClientRect().height}px`;
450
+ cell.style.padding = '0';
451
+ cell.style.border = '0';
452
+ blank.append(cell);
453
+ head.append(blank);
454
+ }
455
+ const headerCopy = document.createElement('tr');
456
+ headerCopy.append(header.cloneNode(true));
457
+ head.append(headerCopy);
458
+ const sources = [
459
+ header
460
+ ];
461
+ const body = document.createElement('tbody');
462
+ for (const row of Array.from(table.tBodies[0].rows)){
463
+ if ('presentation' === row.getAttribute('role')) {
464
+ body.append(row.cloneNode(true));
465
+ continue;
466
+ }
467
+ const cell = row.cells[bodyCellIndex];
468
+ if (!cell || 1 === row.cells.length) continue;
469
+ const copy = row.cloneNode(false);
470
+ copy.append(cell.cloneNode(true));
471
+ body.append(copy);
472
+ sources.push(cell);
473
+ }
474
+ shell.append(colgroup, head, body);
475
+ stripIdentity(shell);
476
+ for (const spacer of shell.querySelectorAll("tbody > tr[role='presentation'] > td"))spacer.colSpan = 1;
477
+ return {
478
+ table: shell,
479
+ sources
480
+ };
481
+ };
482
+ export { bandGeometry, buildColumnPreview, buildRowPreview, dragShiftPx, dropIndex, gapStartPx, slotForCopy, useDragReorder, usePressDrag };
@@ -0,0 +1,57 @@
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
+ useGridStrings: ()=>useGridStrings
28
+ });
29
+ const useSafeLingui_cjs_namespaceObject = require("../i18n/useSafeLingui.cjs");
30
+ const useGridStrings = ()=>{
31
+ const { _ } = (0, useSafeLingui_cjs_namespaceObject.useSafeLingui)();
32
+ return {
33
+ dragRow: _({
34
+ id: 'decision-table.drag_row',
35
+ message: 'Drag to reorder whole row'
36
+ }),
37
+ dragColumn: _({
38
+ id: 'decision-table.drag_column',
39
+ message: 'Drag to reorder whole column'
40
+ }),
41
+ insertRowAbove: _({
42
+ id: 'decision-table.insert_row_above',
43
+ message: 'Insert row above'
44
+ }),
45
+ insertColumnLeft: _({
46
+ id: 'decision-table.insert_column_left',
47
+ message: 'Insert column left'
48
+ })
49
+ };
50
+ };
51
+ exports.useGridStrings = __webpack_exports__.useGridStrings;
52
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
53
+ "useGridStrings"
54
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
55
+ Object.defineProperty(exports, '__esModule', {
56
+ value: true
57
+ });
@@ -0,0 +1,7 @@
1
+ export declare const useGridStrings: () => {
2
+ dragRow: string;
3
+ dragColumn: string;
4
+ insertRowAbove: string;
5
+ insertColumnLeft: string;
6
+ };
7
+ //# sourceMappingURL=useGridStrings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useGridStrings.d.ts","sourceRoot":"","sources":["../../src/decision-table/useGridStrings.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,cAAc;;;;;CAQ1B,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { useSafeLingui } from "../i18n/useSafeLingui.js";
2
+ const useGridStrings = ()=>{
3
+ const { _ } = useSafeLingui();
4
+ return {
5
+ dragRow: _({
6
+ id: 'decision-table.drag_row',
7
+ message: 'Drag to reorder whole row'
8
+ }),
9
+ dragColumn: _({
10
+ id: 'decision-table.drag_column',
11
+ message: 'Drag to reorder whole column'
12
+ }),
13
+ insertRowAbove: _({
14
+ id: 'decision-table.insert_row_above',
15
+ message: 'Insert row above'
16
+ }),
17
+ insertColumnLeft: _({
18
+ id: 'decision-table.insert_column_left',
19
+ message: 'Insert column left'
20
+ })
21
+ };
22
+ };
23
+ export { useGridStrings };
@@ -0,0 +1,89 @@
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
+ useRowHover: ()=>useRowHover
28
+ });
29
+ const external_react_namespaceObject = require("react");
30
+ const useRowHover = (containerRef, overlayRef, rowTopPx, active)=>{
31
+ const hoveredRowRef = (0, external_react_namespaceObject.useRef)(null);
32
+ (0, external_react_namespaceObject.useEffect)(()=>{
33
+ const container = containerRef.current;
34
+ const overlay = overlayRef.current;
35
+ if (!container || !overlay) return;
36
+ let shownTop = null;
37
+ const place = (top)=>{
38
+ if (top === shownTop) return;
39
+ shownTop = top;
40
+ overlay.style.display = null === top ? 'none' : '';
41
+ if (null !== top) overlay.style.transform = `translateY(${top}px)`;
42
+ };
43
+ const refresh = ()=>{
44
+ const row = hoveredRowRef.current;
45
+ const cell = row?.isConnected ? row.querySelector(':scope > [data-row]') : null;
46
+ place(active && cell instanceof HTMLElement && !row?.querySelector('[data-editing]') ? rowTopPx(Number(cell.dataset.row)) : null);
47
+ };
48
+ const onPointerOver = (event)=>{
49
+ if ('touch' === event.pointerType || !(event.target instanceof Element)) return;
50
+ hoveredRowRef.current = event.target.closest('tbody > tr');
51
+ refresh();
52
+ };
53
+ const onPointerOut = (event)=>{
54
+ if (!(event.relatedTarget instanceof Node) || !container.contains(event.relatedTarget)) {
55
+ hoveredRowRef.current = null;
56
+ place(null);
57
+ }
58
+ };
59
+ overlay.style.display = 'none';
60
+ refresh();
61
+ const editing = new MutationObserver(refresh);
62
+ editing.observe(container, {
63
+ subtree: true,
64
+ attributeFilter: [
65
+ 'data-editing'
66
+ ]
67
+ });
68
+ container.addEventListener('pointerover', onPointerOver);
69
+ container.addEventListener('pointerout', onPointerOut);
70
+ return ()=>{
71
+ editing.disconnect();
72
+ container.removeEventListener('pointerover', onPointerOver);
73
+ container.removeEventListener('pointerout', onPointerOut);
74
+ place(null);
75
+ };
76
+ }, [
77
+ containerRef,
78
+ overlayRef,
79
+ rowTopPx,
80
+ active
81
+ ]);
82
+ };
83
+ exports.useRowHover = __webpack_exports__.useRowHover;
84
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
85
+ "useRowHover"
86
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
87
+ Object.defineProperty(exports, '__esModule', {
88
+ value: true
89
+ });