@svgrid/grid 1.1.0 → 1.1.2

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 (148) hide show
  1. package/dist/FlexRender.svelte +96 -96
  2. package/dist/GridMenus.svelte +205 -127
  3. package/dist/SvGrid.controller.svelte.d.ts +44 -1
  4. package/dist/SvGrid.controller.svelte.js +240 -44
  5. package/dist/SvGrid.css +325 -22
  6. package/dist/SvGrid.helpers.test.d.ts +1 -0
  7. package/dist/SvGrid.helpers.test.js +298 -0
  8. package/dist/SvGrid.svelte +729 -203
  9. package/dist/SvGrid.types.d.ts +91 -4
  10. package/dist/aligned-grids.d.ts +6 -0
  11. package/dist/aligned-grids.js +84 -0
  12. package/dist/aligned-grids.test.d.ts +1 -0
  13. package/dist/aligned-grids.test.js +75 -0
  14. package/dist/build-api.coverage.test.d.ts +20 -0
  15. package/dist/build-api.coverage.test.js +505 -0
  16. package/dist/build-api.js +61 -31
  17. package/dist/cell-render.test.d.ts +1 -0
  18. package/dist/cell-render.test.js +338 -0
  19. package/dist/cell-values.d.ts +1 -1
  20. package/dist/cell-values.js +7 -7
  21. package/dist/chart-export.test.d.ts +1 -0
  22. package/dist/chart-export.test.js +302 -0
  23. package/dist/chart.coverage.test.d.ts +1 -0
  24. package/dist/chart.coverage.test.js +748 -0
  25. package/dist/clipboard.js +88 -24
  26. package/dist/clipboard.test.d.ts +1 -0
  27. package/dist/clipboard.test.js +700 -0
  28. package/dist/collaboration.coverage.test.d.ts +1 -0
  29. package/dist/collaboration.coverage.test.js +200 -0
  30. package/dist/column-groups.d.ts +19 -0
  31. package/dist/column-groups.js +62 -0
  32. package/dist/column-groups.test.d.ts +1 -0
  33. package/dist/column-groups.test.js +56 -0
  34. package/dist/column-types.d.ts +10 -0
  35. package/dist/column-types.js +63 -0
  36. package/dist/column-types.test.d.ts +1 -0
  37. package/dist/column-types.test.js +62 -0
  38. package/dist/columns.test.d.ts +1 -0
  39. package/dist/columns.test.js +625 -0
  40. package/dist/core.d.ts +86 -1
  41. package/dist/core.js +2 -2
  42. package/dist/editing.d.ts +7 -0
  43. package/dist/editing.js +191 -5
  44. package/dist/editing.test.d.ts +1 -0
  45. package/dist/editing.test.js +732 -0
  46. package/dist/editors/cell-editors.coverage.test.d.ts +1 -0
  47. package/dist/editors/cell-editors.coverage.test.js +139 -0
  48. package/dist/facet-buckets.test.d.ts +1 -0
  49. package/dist/facet-buckets.test.js +296 -0
  50. package/dist/filter-operators.test.d.ts +1 -0
  51. package/dist/filter-operators.test.js +135 -0
  52. package/dist/hyperformula-adapter.test.d.ts +1 -0
  53. package/dist/hyperformula-adapter.test.js +205 -0
  54. package/dist/index.d.ts +5 -2
  55. package/dist/index.js +4 -1
  56. package/dist/keyboard-handlers.coverage.test.d.ts +1 -0
  57. package/dist/keyboard-handlers.coverage.test.js +495 -0
  58. package/dist/keyboard-handlers.js +7 -2
  59. package/dist/menus.js +1 -0
  60. package/dist/menus.test.d.ts +1 -0
  61. package/dist/menus.test.js +560 -0
  62. package/dist/named-views.coverage.test.d.ts +1 -0
  63. package/dist/named-views.coverage.test.js +180 -0
  64. package/dist/row-drag.d.ts +49 -0
  65. package/dist/row-drag.js +221 -0
  66. package/dist/row-drag.test.d.ts +1 -0
  67. package/dist/row-drag.test.js +142 -0
  68. package/dist/row-resize.test.d.ts +1 -0
  69. package/dist/row-resize.test.js +329 -0
  70. package/dist/scroll-sync.js +3 -0
  71. package/dist/scroll-sync.test.d.ts +1 -0
  72. package/dist/scroll-sync.test.js +290 -0
  73. package/dist/selection.d.ts +7 -1
  74. package/dist/selection.js +76 -36
  75. package/dist/selection.multi-range.test.d.ts +1 -0
  76. package/dist/selection.multi-range.test.js +55 -0
  77. package/dist/selection.test.d.ts +1 -0
  78. package/dist/selection.test.js +647 -0
  79. package/dist/server-data-source.coverage.test.d.ts +1 -0
  80. package/dist/server-data-source.coverage.test.js +154 -0
  81. package/dist/spreadsheet.d.ts +30 -0
  82. package/dist/spreadsheet.js +48 -0
  83. package/dist/spreadsheet.test.d.ts +1 -0
  84. package/dist/spreadsheet.test.js +446 -0
  85. package/dist/summaries.js +4 -4
  86. package/dist/sv-grid-scrollbar.js +13 -1
  87. package/dist/svgrid-wrapper.types.d.ts +19 -0
  88. package/dist/svgrid.behavior.test.js +20 -0
  89. package/dist/svgrid.interaction.test.js +31 -0
  90. package/dist/svgrid.new-features.wrapper.test.js +34 -2
  91. package/dist/test-setup.js +9 -3
  92. package/dist/virtualization/scroll-scaling.d.ts +17 -0
  93. package/dist/virtualization/scroll-scaling.js +35 -0
  94. package/dist/virtualization/scroll-scaling.test.js +42 -1
  95. package/package.json +2 -1
  96. package/src/FlexRender.svelte +96 -96
  97. package/src/GridMenus.svelte +205 -127
  98. package/src/SvGrid.controller.svelte.ts +204 -36
  99. package/src/SvGrid.css +277 -12
  100. package/src/SvGrid.svelte +727 -205
  101. package/src/SvGrid.types.ts +85 -4
  102. package/src/a11y.contract.test.ts +49 -49
  103. package/src/a11y.test.ts +59 -59
  104. package/src/a11y.ts +59 -59
  105. package/src/aligned-grids.test.ts +80 -0
  106. package/src/aligned-grids.ts +87 -0
  107. package/src/build-api.ts +43 -23
  108. package/src/cell-formatting.ts +169 -169
  109. package/src/cell-values.ts +4 -4
  110. package/src/clipboard.test.ts +49 -0
  111. package/src/clipboard.ts +51 -23
  112. package/src/column-groups.test.ts +59 -0
  113. package/src/column-groups.ts +80 -0
  114. package/src/column-types.test.ts +68 -0
  115. package/src/column-types.ts +82 -0
  116. package/src/core.performance.test.ts +30 -30
  117. package/src/core.ts +1077 -999
  118. package/src/createGrid.svelte.ts +42 -42
  119. package/src/createGrid.test.ts +10 -10
  120. package/src/createGridState.svelte.ts +17 -17
  121. package/src/editing.ts +161 -5
  122. package/src/flex-render.ts +3 -3
  123. package/src/index.ts +208 -196
  124. package/src/keyboard.test.ts +59 -59
  125. package/src/keyboard.ts +97 -97
  126. package/src/menus.ts +1 -0
  127. package/src/merge-objects.ts +48 -48
  128. package/src/render-component.ts +28 -28
  129. package/src/row-drag.test.ts +168 -0
  130. package/src/row-drag.ts +255 -0
  131. package/src/scroll-sync.ts +2 -0
  132. package/src/selection.multi-range.test.ts +61 -0
  133. package/src/selection.ts +71 -37
  134. package/src/spreadsheet.test.ts +46 -2
  135. package/src/spreadsheet.ts +58 -0
  136. package/src/static-functions.ts +11 -11
  137. package/src/subscribe.ts +38 -38
  138. package/src/summaries.ts +4 -4
  139. package/src/svgrid-wrapper.types.ts +412 -393
  140. package/src/svgrid.features.test.ts +157 -157
  141. package/src/svgrid.new-features.wrapper.test.ts +2 -2
  142. package/src/svgrid.wrapper.test.ts +40 -40
  143. package/src/virtualization/column-virtualizer.test.ts +27 -27
  144. package/src/virtualization/column-virtualizer.ts +30 -30
  145. package/src/virtualization/svelte-virtualizer.svelte.ts +26 -26
  146. package/src/virtualization/types.ts +30 -30
  147. package/src/virtualization/virtualizer.test.ts +47 -47
  148. package/src/virtualization/virtualizer.ts +296 -296
package/src/keyboard.ts CHANGED
@@ -1,97 +1,97 @@
1
- import type { ActiveCellState } from './core'
2
-
3
- export type GridKeyboardIntent =
4
- | 'moveLeft'
5
- | 'moveRight'
6
- | 'moveUp'
7
- | 'moveDown'
8
- | 'tabNext'
9
- | 'tabPrev'
10
- | 'rowStart'
11
- | 'rowEnd'
12
- | 'gridStart'
13
- | 'gridEnd'
14
- | 'pageUp'
15
- | 'pageDown'
16
- | 'activate'
17
- | 'clearCells'
18
- | 'noop'
19
-
20
- export function getKeyboardIntent(event: KeyboardEvent): GridKeyboardIntent {
21
- // Ctrl+Home / Ctrl+End come before plain Home / End so the modifier wins.
22
- if (event.ctrlKey && event.key === 'Home') return 'gridStart'
23
- if (event.ctrlKey && event.key === 'End') return 'gridEnd'
24
-
25
- if (event.key === 'ArrowLeft') return 'moveLeft'
26
- if (event.key === 'ArrowRight') return 'moveRight'
27
- if (event.key === 'ArrowUp') return 'moveUp'
28
- if (event.key === 'ArrowDown') return 'moveDown'
29
- if (event.key === 'Home') return 'rowStart'
30
- if (event.key === 'End') return 'rowEnd'
31
- if (event.key === 'PageUp') return 'pageUp'
32
- if (event.key === 'PageDown') return 'pageDown'
33
-
34
- // Excel-style data-entry navigation:
35
- // Enter → move down (Shift+Enter → up)
36
- // Tab → move right (Shift+Tab → left), wraps at row boundaries
37
- // Delete → clear contents of the selected cells
38
- // F2 / Space → start editing the active cell
39
- if (event.key === 'Enter') return event.shiftKey ? 'moveUp' : 'moveDown'
40
- if (event.key === 'Tab') return event.shiftKey ? 'tabPrev' : 'tabNext'
41
- if (event.key === 'F2') return 'activate'
42
- if (event.key === ' ') return 'activate'
43
- if (event.key === 'Delete') return 'clearCells'
44
-
45
- return 'noop'
46
- }
47
-
48
- export function getNextActiveCell(
49
- current: ActiveCellState,
50
- intent: GridKeyboardIntent,
51
- bounds: { maxRow: number; maxCol: number; pageSize?: number },
52
- ): ActiveCellState {
53
- const pageSize = bounds.pageSize ?? 10
54
- let rowIndex = current.rowIndex
55
- let colIndex = current.colIndex
56
-
57
- if (intent === 'moveLeft') colIndex -= 1
58
- if (intent === 'moveRight') colIndex += 1
59
- if (intent === 'moveUp') rowIndex -= 1
60
- if (intent === 'moveDown') rowIndex += 1
61
- if (intent === 'tabNext') {
62
- // Right one column; if we fall off the right edge, wrap to the
63
- // first column of the next row - Excel's "data entry" behavior.
64
- colIndex += 1
65
- if (colIndex > bounds.maxCol) {
66
- colIndex = 0
67
- rowIndex += 1
68
- }
69
- }
70
- if (intent === 'tabPrev') {
71
- colIndex -= 1
72
- if (colIndex < 0) {
73
- colIndex = bounds.maxCol
74
- rowIndex -= 1
75
- }
76
- }
77
- if (intent === 'rowStart') colIndex = 0
78
- if (intent === 'rowEnd') colIndex = bounds.maxCol
79
- if (intent === 'gridStart') {
80
- rowIndex = 0
81
- colIndex = 0
82
- }
83
- if (intent === 'gridEnd') {
84
- rowIndex = bounds.maxRow
85
- colIndex = bounds.maxCol
86
- }
87
- if (intent === 'pageUp') rowIndex -= pageSize
88
- if (intent === 'pageDown') rowIndex += pageSize
89
-
90
- rowIndex = Math.min(Math.max(rowIndex, 0), Math.max(bounds.maxRow, 0))
91
- colIndex = Math.min(Math.max(colIndex, 0), Math.max(bounds.maxCol, 0))
92
- return {
93
- rowIndex,
94
- colIndex,
95
- cellId: current.cellId,
96
- }
97
- }
1
+ import type { ActiveCellState } from './core'
2
+
3
+ export type GridKeyboardIntent =
4
+ | 'moveLeft'
5
+ | 'moveRight'
6
+ | 'moveUp'
7
+ | 'moveDown'
8
+ | 'tabNext'
9
+ | 'tabPrev'
10
+ | 'rowStart'
11
+ | 'rowEnd'
12
+ | 'gridStart'
13
+ | 'gridEnd'
14
+ | 'pageUp'
15
+ | 'pageDown'
16
+ | 'activate'
17
+ | 'clearCells'
18
+ | 'noop'
19
+
20
+ export function getKeyboardIntent(event: KeyboardEvent): GridKeyboardIntent {
21
+ // Ctrl+Home / Ctrl+End come before plain Home / End so the modifier wins.
22
+ if (event.ctrlKey && event.key === 'Home') return 'gridStart'
23
+ if (event.ctrlKey && event.key === 'End') return 'gridEnd'
24
+
25
+ if (event.key === 'ArrowLeft') return 'moveLeft'
26
+ if (event.key === 'ArrowRight') return 'moveRight'
27
+ if (event.key === 'ArrowUp') return 'moveUp'
28
+ if (event.key === 'ArrowDown') return 'moveDown'
29
+ if (event.key === 'Home') return 'rowStart'
30
+ if (event.key === 'End') return 'rowEnd'
31
+ if (event.key === 'PageUp') return 'pageUp'
32
+ if (event.key === 'PageDown') return 'pageDown'
33
+
34
+ // Excel-style data-entry navigation:
35
+ // Enter → move down (Shift+Enter → up)
36
+ // Tab → move right (Shift+Tab → left), wraps at row boundaries
37
+ // Delete → clear contents of the selected cells
38
+ // F2 / Space → start editing the active cell
39
+ if (event.key === 'Enter') return event.shiftKey ? 'moveUp' : 'moveDown'
40
+ if (event.key === 'Tab') return event.shiftKey ? 'tabPrev' : 'tabNext'
41
+ if (event.key === 'F2') return 'activate'
42
+ if (event.key === ' ') return 'activate'
43
+ if (event.key === 'Delete') return 'clearCells'
44
+
45
+ return 'noop'
46
+ }
47
+
48
+ export function getNextActiveCell(
49
+ current: ActiveCellState,
50
+ intent: GridKeyboardIntent,
51
+ bounds: { maxRow: number; maxCol: number; pageSize?: number },
52
+ ): ActiveCellState {
53
+ const pageSize = bounds.pageSize ?? 10
54
+ let rowIndex = current.rowIndex
55
+ let colIndex = current.colIndex
56
+
57
+ if (intent === 'moveLeft') colIndex -= 1
58
+ if (intent === 'moveRight') colIndex += 1
59
+ if (intent === 'moveUp') rowIndex -= 1
60
+ if (intent === 'moveDown') rowIndex += 1
61
+ if (intent === 'tabNext') {
62
+ // Right one column; if we fall off the right edge, wrap to the
63
+ // first column of the next row - Excel's "data entry" behavior.
64
+ colIndex += 1
65
+ if (colIndex > bounds.maxCol) {
66
+ colIndex = 0
67
+ rowIndex += 1
68
+ }
69
+ }
70
+ if (intent === 'tabPrev') {
71
+ colIndex -= 1
72
+ if (colIndex < 0) {
73
+ colIndex = bounds.maxCol
74
+ rowIndex -= 1
75
+ }
76
+ }
77
+ if (intent === 'rowStart') colIndex = 0
78
+ if (intent === 'rowEnd') colIndex = bounds.maxCol
79
+ if (intent === 'gridStart') {
80
+ rowIndex = 0
81
+ colIndex = 0
82
+ }
83
+ if (intent === 'gridEnd') {
84
+ rowIndex = bounds.maxRow
85
+ colIndex = bounds.maxCol
86
+ }
87
+ if (intent === 'pageUp') rowIndex -= pageSize
88
+ if (intent === 'pageDown') rowIndex += pageSize
89
+
90
+ rowIndex = Math.min(Math.max(rowIndex, 0), Math.max(bounds.maxRow, 0))
91
+ colIndex = Math.min(Math.max(colIndex, 0), Math.max(bounds.maxCol, 0))
92
+ return {
93
+ rowIndex,
94
+ colIndex,
95
+ cellId: current.cellId,
96
+ }
97
+ }
package/src/menus.ts CHANGED
@@ -231,6 +231,7 @@ export function createMenus<
231
231
  x: clampMenuX(rect.right - 240, 240),
232
232
  y: rect.bottom + 4,
233
233
  };
234
+ ctx.columnMenuTab = "general";
234
235
  ctx.columnMenuFor = columnId;
235
236
  }
236
237
 
@@ -1,48 +1,48 @@
1
- /**
2
- * Merges objects together while keeping their getters alive.
3
- * Taken from SolidJS:
4
- * https://github.com/solidjs/solid/blob/24abc825c0996fd2bc8c1de1491efe9a7e743aff/packages/solid/src/server/rendering.ts#L82-L115
5
- */
6
- export function mergeObjects<T>(source: T): T
7
- export function mergeObjects<T, U>(source: T, source1: U): T & U
8
- export function mergeObjects<T, U, V>(
9
- source: T,
10
- source1: U,
11
- source2: V,
12
- ): T & U & V
13
- export function mergeObjects<T, U, V, W>(
14
- source: T,
15
- source1: U,
16
- source2: V,
17
- source3: W,
18
- ): T & U & V & W
19
- export function mergeObjects(...sources: any): any {
20
- const target = {}
21
-
22
- for (let source of sources) {
23
- if (typeof source === 'function') source = source()
24
-
25
- if (source) {
26
- const descriptors = Object.getOwnPropertyDescriptors(source)
27
-
28
- for (const key in descriptors) {
29
- if (key in target) continue
30
-
31
- Object.defineProperty(target, key, {
32
- enumerable: true,
33
- get() {
34
- for (let i = sources.length - 1; i >= 0; i--) {
35
- let scopedSource = sources[i]
36
- if (typeof scopedSource === 'function') scopedSource = scopedSource()
37
-
38
- const value = (scopedSource || {})[key]
39
- if (value !== undefined) return value
40
- }
41
- },
42
- })
43
- }
44
- }
45
- }
46
-
47
- return target
48
- }
1
+ /**
2
+ * Merges objects together while keeping their getters alive.
3
+ * Taken from SolidJS:
4
+ * https://github.com/solidjs/solid/blob/24abc825c0996fd2bc8c1de1491efe9a7e743aff/packages/solid/src/server/rendering.ts#L82-L115
5
+ */
6
+ export function mergeObjects<T>(source: T): T
7
+ export function mergeObjects<T, U>(source: T, source1: U): T & U
8
+ export function mergeObjects<T, U, V>(
9
+ source: T,
10
+ source1: U,
11
+ source2: V,
12
+ ): T & U & V
13
+ export function mergeObjects<T, U, V, W>(
14
+ source: T,
15
+ source1: U,
16
+ source2: V,
17
+ source3: W,
18
+ ): T & U & V & W
19
+ export function mergeObjects(...sources: any): any {
20
+ const target = {}
21
+
22
+ for (let source of sources) {
23
+ if (typeof source === 'function') source = source()
24
+
25
+ if (source) {
26
+ const descriptors = Object.getOwnPropertyDescriptors(source)
27
+
28
+ for (const key in descriptors) {
29
+ if (key in target) continue
30
+
31
+ Object.defineProperty(target, key, {
32
+ enumerable: true,
33
+ get() {
34
+ for (let i = sources.length - 1; i >= 0; i--) {
35
+ let scopedSource = sources[i]
36
+ if (typeof scopedSource === 'function') scopedSource = scopedSource()
37
+
38
+ const value = (scopedSource || {})[key]
39
+ if (value !== undefined) return value
40
+ }
41
+ },
42
+ })
43
+ }
44
+ }
45
+ }
46
+
47
+ return target
48
+ }
@@ -1,28 +1,28 @@
1
- import type { Component, ComponentProps, Snippet } from 'svelte'
2
-
3
- export class RenderComponentConfig<TComponent extends Component> {
4
- constructor(
5
- public component: TComponent,
6
- public props?: ComponentProps<TComponent> | Record<string, never>,
7
- ) {}
8
- }
9
-
10
- export class RenderSnippetConfig<TProps> {
11
- constructor(
12
- public snippet: Snippet<[TProps]>,
13
- public params?: TProps,
14
- ) {}
15
- }
16
-
17
- export const renderComponent = <
18
- TComponent extends Component<any>,
19
- TProps extends ComponentProps<TComponent>,
20
- >(
21
- component: TComponent,
22
- props?: TProps,
23
- ) => new RenderComponentConfig(component, props)
24
-
25
- export const renderSnippet = <TProps>(
26
- snippet: Snippet<[TProps]>,
27
- params?: TProps,
28
- ) => new RenderSnippetConfig(snippet, params)
1
+ import type { Component, ComponentProps, Snippet } from 'svelte'
2
+
3
+ export class RenderComponentConfig<TComponent extends Component> {
4
+ constructor(
5
+ public component: TComponent,
6
+ public props?: ComponentProps<TComponent> | Record<string, never>,
7
+ ) {}
8
+ }
9
+
10
+ export class RenderSnippetConfig<TProps> {
11
+ constructor(
12
+ public snippet: Snippet<[TProps]>,
13
+ public params?: TProps,
14
+ ) {}
15
+ }
16
+
17
+ export const renderComponent = <
18
+ TComponent extends Component<any>,
19
+ TProps extends ComponentProps<TComponent>,
20
+ >(
21
+ component: TComponent,
22
+ props?: TProps,
23
+ ) => new RenderComponentConfig(component, props)
24
+
25
+ export const renderSnippet = <TProps>(
26
+ snippet: Snippet<[TProps]>,
27
+ params?: TProps,
28
+ ) => new RenderSnippetConfig(snippet, params)
@@ -0,0 +1,168 @@
1
+ /**
2
+ * Unit tests for the managed row-drag handlers produced by createRowDrag(ctx).
3
+ *
4
+ * createRowDrag is a factory closing over a mutable `ctx` handle and a
5
+ * module-level singleton "bus" that carries the dragged row between grids.
6
+ * Because the bus is shared, we can create TWO fake ctxs (two grids) and drive
7
+ * a genuine grid-to-grid move without mounting anything.
8
+ */
9
+ import { beforeEach, describe, expect, it, vi } from 'vitest'
10
+ import { createRowDrag, rowDropZone } from './row-drag'
11
+
12
+ type AnyCtx = Record<string, any>
13
+ type Task = { id: number; title: string }
14
+
15
+ function makeCtx(rows: Task[], props: AnyCtx = {}): AnyCtx {
16
+ return {
17
+ props,
18
+ internalData: rows,
19
+ get allRows() {
20
+ // allRows tracks internalData order; each Row wraps `.original`.
21
+ return (this.internalData as Task[]).map((r) => ({ original: r }))
22
+ },
23
+ rowDragActive: false,
24
+ rowDropIndex: null,
25
+ rowDropSide: null,
26
+ }
27
+ }
28
+
29
+ function fakeEvent(clientY = 0, rectTop = 0, rectHeight = 40): any {
30
+ return {
31
+ clientY,
32
+ preventDefault: vi.fn(),
33
+ stopPropagation: vi.fn(),
34
+ dataTransfer: { setData: vi.fn(), effectAllowed: '', dropEffect: '' },
35
+ currentTarget: {
36
+ getBoundingClientRect: () => ({ top: rectTop, height: rectHeight, bottom: rectTop + rectHeight, left: 0 }),
37
+ },
38
+ }
39
+ }
40
+
41
+ const P = { rowDragManaged: true }
42
+
43
+ describe('createRowDrag - same-grid reorder', () => {
44
+ it('moves a dragged row after the drop target', () => {
45
+ const rows: Task[] = [
46
+ { id: 1, title: 'a' },
47
+ { id: 2, title: 'b' },
48
+ { id: 3, title: 'c' },
49
+ { id: 4, title: 'd' },
50
+ ]
51
+ const ctx = makeCtx(rows, { ...P })
52
+ const h = createRowDrag(ctx)
53
+
54
+ h.onRowDragStart(fakeEvent(), 0) // drag "a"
55
+ ctx.rowDropSide = 'after'
56
+ h.onRowDrop(fakeEvent(), 2) // drop after "c"
57
+
58
+ expect((ctx.internalData as Task[]).map((r) => r.title)).toEqual(['b', 'c', 'a', 'd'])
59
+ })
60
+
61
+ it('drops before the target when the side is "before"', () => {
62
+ const rows: Task[] = [
63
+ { id: 1, title: 'a' },
64
+ { id: 2, title: 'b' },
65
+ { id: 3, title: 'c' },
66
+ ]
67
+ const ctx = makeCtx(rows, { ...P })
68
+ const h = createRowDrag(ctx)
69
+ h.onRowDragStart(fakeEvent(), 2) // drag "c"
70
+ ctx.rowDropSide = 'before'
71
+ h.onRowDrop(fakeEvent(), 0) // before "a"
72
+ expect((ctx.internalData as Task[]).map((r) => r.title)).toEqual(['c', 'a', 'b'])
73
+ })
74
+ })
75
+
76
+ describe('createRowDrag - grid-to-grid', () => {
77
+ it('moves a row from source into target when groups match', () => {
78
+ const a = makeCtx([{ id: 1, title: 'a1' }, { id: 2, title: 'a2' }], { ...P, rowDragGroup: 'g' })
79
+ const b = makeCtx([{ id: 9, title: 'b1' }], { ...P, rowDragGroup: 'g', onRowDragEnd: vi.fn() })
80
+ const ha = createRowDrag(a)
81
+ const hb = createRowDrag(b)
82
+
83
+ ha.onRowDragStart(fakeEvent(), 1) // drag "a2" out of grid A
84
+ b.rowDropSide = 'before'
85
+ hb.onRowDrop(fakeEvent(), 0) // drop onto grid B before "b1"
86
+
87
+ expect((a.internalData as Task[]).map((r) => r.title)).toEqual(['a1'])
88
+ expect((b.internalData as Task[]).map((r) => r.title)).toEqual(['a2', 'b1'])
89
+ expect(b.props.onRowDragEnd).toHaveBeenCalledWith(
90
+ expect.objectContaining({ sameGrid: false, toIndex: 0, row: expect.objectContaining({ title: 'a2' }) }),
91
+ )
92
+ })
93
+
94
+ it('does NOT accept a drop when groups differ', () => {
95
+ const a = makeCtx([{ id: 1, title: 'a1' }, { id: 2, title: 'a2' }], { ...P, rowDragGroup: 'g' })
96
+ const b = makeCtx([{ id: 9, title: 'b1' }], { ...P, rowDragGroup: 'other' })
97
+ const ha = createRowDrag(a)
98
+ const hb = createRowDrag(b)
99
+
100
+ ha.onRowDragStart(fakeEvent(), 0)
101
+ const ev = fakeEvent()
102
+ hb.onRowDragOver(ev, 0)
103
+ expect(ev.preventDefault).not.toHaveBeenCalled() // over rejected
104
+ hb.onRowDrop(fakeEvent(), 0)
105
+ expect((b.internalData as Task[]).map((r) => r.title)).toEqual(['b1']) // unchanged
106
+ expect((a.internalData as Task[]).length).toBe(2) // source untouched
107
+ })
108
+
109
+ it('appends to the target on an empty-space (container) drop', () => {
110
+ const a = makeCtx([{ id: 1, title: 'a1' }, { id: 2, title: 'a2' }], { ...P, rowDragGroup: 'g' })
111
+ const b = makeCtx([{ id: 9, title: 'b1' }], { ...P, rowDragGroup: 'g' })
112
+ const ha = createRowDrag(a)
113
+ const hb = createRowDrag(b)
114
+ ha.onRowDragStart(fakeEvent(), 0) // drag "a1"
115
+ hb.onRowsContainerDrop(fakeEvent())
116
+ expect((b.internalData as Task[]).map((r) => r.title)).toEqual(['b1', 'a1'])
117
+ expect((a.internalData as Task[]).map((r) => r.title)).toEqual(['a2'])
118
+ })
119
+ })
120
+
121
+ describe('createRowDrag - disabled', () => {
122
+ it('is inert when rowDragManaged is off', () => {
123
+ const ctx = makeCtx([{ id: 1, title: 'a' }, { id: 2, title: 'b' }], {})
124
+ const h = createRowDrag(ctx)
125
+ h.onRowDragStart(fakeEvent(), 0)
126
+ ctx.rowDropSide = 'after'
127
+ h.onRowDrop(fakeEvent(), 1)
128
+ expect((ctx.internalData as Task[]).map((r) => r.title)).toEqual(['a', 'b'])
129
+ })
130
+ })
131
+
132
+ describe('rowDropZone (external drop target)', () => {
133
+ function dropOn(el: HTMLElement) {
134
+ const ev = new Event('drop', { bubbles: true, cancelable: true })
135
+ el.dispatchEvent(ev)
136
+ }
137
+
138
+ it('removes the dragged row from its source grid and calls onDrop', () => {
139
+ const a = makeCtx([{ id: 1, title: 'a1' }, { id: 2, title: 'a2' }], { ...P, rowDragGroup: 'g' })
140
+ const ha = createRowDrag(a)
141
+ ha.onRowDragStart(fakeEvent(), 0) // start dragging "a1"
142
+
143
+ const el = document.createElement('div')
144
+ const dropped: any[] = []
145
+ const action = rowDropZone(el, { group: 'g', onDrop: (e) => dropped.push(e) })
146
+ dropOn(el)
147
+
148
+ expect(dropped.length).toBe(1)
149
+ expect(dropped[0].row.title).toBe('a1')
150
+ expect((a.internalData as Task[]).map((r) => r.title)).toEqual(['a2']) // removed from source
151
+ action.destroy()
152
+ })
153
+
154
+ it('ignores drops when the group does not match', () => {
155
+ const a = makeCtx([{ id: 1, title: 'a1' }], { ...P, rowDragGroup: 'g' })
156
+ const ha = createRowDrag(a)
157
+ ha.onRowDragStart(fakeEvent(), 0)
158
+
159
+ const el = document.createElement('div')
160
+ const dropped: any[] = []
161
+ const action = rowDropZone(el, { group: 'other', onDrop: (e) => dropped.push(e) })
162
+ dropOn(el)
163
+
164
+ expect(dropped.length).toBe(0)
165
+ expect((a.internalData as Task[]).length).toBe(1) // untouched
166
+ action.destroy()
167
+ })
168
+ })