@pie-lib/drag 4.0.3-next.36 → 4.0.3-next.38

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 (69) hide show
  1. package/dist/_virtual/_rolldown/runtime.js +11 -0
  2. package/dist/drag-in-the-blank-dp.d.ts +29 -0
  3. package/dist/drag-in-the-blank-dp.js +44 -0
  4. package/dist/drag-provider.d.ts +29 -0
  5. package/dist/drag-provider.js +31 -0
  6. package/dist/drag-type.d.ts +16 -0
  7. package/dist/draggable-choice.d.ts +43 -0
  8. package/dist/draggable-choice.js +63 -0
  9. package/dist/droppable-placeholder.d.ts +29 -0
  10. package/dist/droppable-placeholder.js +36 -0
  11. package/dist/ica-dp.d.ts +24 -0
  12. package/dist/ica-dp.js +20 -0
  13. package/dist/index.d.ts +17 -0
  14. package/dist/index.js +9 -0
  15. package/dist/match-list-dp.d.ts +26 -0
  16. package/dist/match-list-dp.js +21 -0
  17. package/dist/node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.js +16 -0
  18. package/dist/placeholder.d.ts +31 -0
  19. package/dist/placeholder.js +98 -0
  20. package/dist/preview-component.d.ts +11 -0
  21. package/dist/swap.d.ts +10 -0
  22. package/dist/swap.js +9 -0
  23. package/dist/uid-context.d.ts +13 -0
  24. package/dist/uid-context.js +15 -0
  25. package/package.json +33 -15
  26. package/CHANGELOG.json +0 -1
  27. package/CHANGELOG.md +0 -802
  28. package/LICENSE.md +0 -5
  29. package/lib/drag-in-the-blank-dp.js +0 -66
  30. package/lib/drag-in-the-blank-dp.js.map +0 -1
  31. package/lib/drag-provider.js +0 -61
  32. package/lib/drag-provider.js.map +0 -1
  33. package/lib/drag-type.js +0 -14
  34. package/lib/drag-type.js.map +0 -1
  35. package/lib/draggable-choice.js +0 -95
  36. package/lib/draggable-choice.js.map +0 -1
  37. package/lib/droppable-placeholder.js +0 -50
  38. package/lib/droppable-placeholder.js.map +0 -1
  39. package/lib/ica-dp.js +0 -37
  40. package/lib/ica-dp.js.map +0 -1
  41. package/lib/index.js +0 -61
  42. package/lib/index.js.map +0 -1
  43. package/lib/match-list-dp.js +0 -49
  44. package/lib/match-list-dp.js.map +0 -1
  45. package/lib/placeholder.js +0 -131
  46. package/lib/placeholder.js.map +0 -1
  47. package/lib/preview-component.js +0 -154
  48. package/lib/preview-component.js.map +0 -1
  49. package/lib/swap.js +0 -18
  50. package/lib/swap.js.map +0 -1
  51. package/lib/uid-context.js +0 -26
  52. package/lib/uid-context.js.map +0 -1
  53. package/src/__tests__/drag-provider.test.jsx +0 -313
  54. package/src/__tests__/placeholder.test.jsx +0 -107
  55. package/src/__tests__/preview-component.test.jsx +0 -537
  56. package/src/__tests__/swap.test.js +0 -161
  57. package/src/__tests__/uid-context.test.jsx +0 -54
  58. package/src/drag-in-the-blank-dp.jsx +0 -65
  59. package/src/drag-provider.jsx +0 -50
  60. package/src/drag-type.js +0 -7
  61. package/src/draggable-choice.jsx +0 -83
  62. package/src/droppable-placeholder.jsx +0 -41
  63. package/src/ica-dp.jsx +0 -25
  64. package/src/index.js +0 -19
  65. package/src/match-list-dp.jsx +0 -36
  66. package/src/placeholder.jsx +0 -132
  67. package/src/preview-component.jsx +0 -145
  68. package/src/swap.js +0 -14
  69. package/src/uid-context.js +0 -13
@@ -1,313 +0,0 @@
1
- import React from 'react';
2
- import { render, screen } from '@testing-library/react';
3
- import { DragProvider } from '../drag-provider';
4
-
5
- jest.mock('@dnd-kit/core', () => ({
6
- DndContext: ({ children, onDragStart, onDragEnd, sensors, collisionDetection, modifiers, autoScroll }) => (
7
- <div
8
- data-testid="dnd-context"
9
- data-has-sensors={!!sensors}
10
- data-has-collision-detection={!!collisionDetection}
11
- data-has-modifiers={!!modifiers}
12
- data-has-auto-scroll={!!autoScroll}
13
- data-on-drag-start={typeof onDragStart === 'function' ? 'function' : 'undefined'}
14
- data-on-drag-end={typeof onDragEnd === 'function' ? 'function' : 'undefined'}
15
- >
16
- {children}
17
- </div>
18
- ),
19
- PointerSensor: 'PointerSensor',
20
- KeyboardSensor: 'KeyboardSensor',
21
- useSensor: jest.fn((sensor, config) => ({ sensor, config })),
22
- useSensors: jest.fn((...sensors) => sensors),
23
- }));
24
-
25
- describe('DragProvider', () => {
26
- const defaultProps = {
27
- children: <div data-testid="test-child">Test Content</div>,
28
- };
29
-
30
- beforeEach(() => {
31
- jest.clearAllMocks();
32
- });
33
-
34
- describe('rendering', () => {
35
- it('should render children correctly', () => {
36
- render(<DragProvider {...defaultProps} />);
37
- expect(screen.getByTestId('test-child')).toBeInTheDocument();
38
- expect(screen.getByText('Test Content')).toBeInTheDocument();
39
- });
40
-
41
- it('should render multiple children', () => {
42
- render(
43
- <DragProvider>
44
- <div data-testid="child-1">Child 1</div>
45
- <div data-testid="child-2">Child 2</div>
46
- </DragProvider>,
47
- );
48
- expect(screen.getByTestId('child-1')).toBeInTheDocument();
49
- expect(screen.getByTestId('child-2')).toBeInTheDocument();
50
- });
51
-
52
- it('should wrap children in DndContext', () => {
53
- render(<DragProvider {...defaultProps} />);
54
- const dndContext = screen.getByTestId('dnd-context');
55
- expect(dndContext).toBeInTheDocument();
56
- expect(dndContext).toContainElement(screen.getByTestId('test-child'));
57
- });
58
-
59
- it('should render with complex children', () => {
60
- render(
61
- <DragProvider>
62
- <div>
63
- <span data-testid="nested">Nested</span>
64
- <ul>
65
- <li data-testid="list-item">Item</li>
66
- </ul>
67
- </div>
68
- </DragProvider>,
69
- );
70
- expect(screen.getByTestId('nested')).toBeInTheDocument();
71
- expect(screen.getByTestId('list-item')).toBeInTheDocument();
72
- });
73
- });
74
-
75
- describe('DndContext props', () => {
76
- it('should pass sensors to DndContext', () => {
77
- render(<DragProvider {...defaultProps} />);
78
- const dndContext = screen.getByTestId('dnd-context');
79
- expect(dndContext).toHaveAttribute('data-has-sensors', 'true');
80
- });
81
-
82
- it('should pass onDragStart handler to DndContext', () => {
83
- const onDragStart = jest.fn();
84
- render(<DragProvider {...defaultProps} onDragStart={onDragStart} />);
85
- const dndContext = screen.getByTestId('dnd-context');
86
- expect(dndContext).toHaveAttribute('data-on-drag-start', 'function');
87
- });
88
-
89
- it('should pass onDragEnd handler to DndContext', () => {
90
- const onDragEnd = jest.fn();
91
- render(<DragProvider {...defaultProps} onDragEnd={onDragEnd} />);
92
- const dndContext = screen.getByTestId('dnd-context');
93
- expect(dndContext).toHaveAttribute('data-on-drag-end', 'function');
94
- });
95
-
96
- it('should pass collisionDetection to DndContext', () => {
97
- const collisionDetection = jest.fn();
98
- render(<DragProvider {...defaultProps} collisionDetection={collisionDetection} />);
99
- const dndContext = screen.getByTestId('dnd-context');
100
- expect(dndContext).toHaveAttribute('data-has-collision-detection', 'true');
101
- });
102
-
103
- it('should pass modifiers to DndContext', () => {
104
- const modifiers = [jest.fn()];
105
- render(<DragProvider {...defaultProps} modifiers={modifiers} />);
106
- const dndContext = screen.getByTestId('dnd-context');
107
- expect(dndContext).toHaveAttribute('data-has-modifiers', 'true');
108
- });
109
-
110
- it('should pass autoScroll to DndContext', () => {
111
- const autoScroll = { enabled: true };
112
- render(<DragProvider {...defaultProps} autoScroll={autoScroll} />);
113
- const dndContext = screen.getByTestId('dnd-context');
114
- expect(dndContext).toHaveAttribute('data-has-auto-scroll', 'true');
115
- });
116
-
117
- it('should pass all props to DndContext', () => {
118
- const onDragStart = jest.fn();
119
- const onDragEnd = jest.fn();
120
- const collisionDetection = jest.fn();
121
- const modifiers = [jest.fn()];
122
- const autoScroll = { enabled: true };
123
-
124
- render(
125
- <DragProvider
126
- {...defaultProps}
127
- onDragStart={onDragStart}
128
- onDragEnd={onDragEnd}
129
- collisionDetection={collisionDetection}
130
- modifiers={modifiers}
131
- autoScroll={autoScroll}
132
- />,
133
- );
134
-
135
- const dndContext = screen.getByTestId('dnd-context');
136
- expect(dndContext).toHaveAttribute('data-on-drag-start', 'function');
137
- expect(dndContext).toHaveAttribute('data-on-drag-end', 'function');
138
- expect(dndContext).toHaveAttribute('data-has-collision-detection', 'true');
139
- expect(dndContext).toHaveAttribute('data-has-modifiers', 'true');
140
- expect(dndContext).toHaveAttribute('data-has-auto-scroll', 'true');
141
- });
142
- });
143
-
144
- describe('optional props', () => {
145
- it('should work without onDragStart', () => {
146
- expect(() => {
147
- render(<DragProvider {...defaultProps} />);
148
- }).not.toThrow();
149
- });
150
-
151
- it('should work without onDragEnd', () => {
152
- expect(() => {
153
- render(<DragProvider {...defaultProps} />);
154
- }).not.toThrow();
155
- });
156
-
157
- it('should work without collisionDetection', () => {
158
- render(<DragProvider {...defaultProps} />);
159
- const dndContext = screen.getByTestId('dnd-context');
160
- expect(dndContext).toHaveAttribute('data-has-collision-detection', 'false');
161
- });
162
-
163
- it('should work without modifiers', () => {
164
- render(<DragProvider {...defaultProps} />);
165
- const dndContext = screen.getByTestId('dnd-context');
166
- expect(dndContext).toHaveAttribute('data-has-modifiers', 'false');
167
- });
168
-
169
- it('should work without autoScroll', () => {
170
- render(<DragProvider {...defaultProps} />);
171
- const dndContext = screen.getByTestId('dnd-context');
172
- expect(dndContext).toHaveAttribute('data-has-auto-scroll', 'false');
173
- });
174
- });
175
-
176
- describe('sensors setup', () => {
177
- it('should initialize PointerSensor with activation constraint', () => {
178
- const { useSensor } = require('@dnd-kit/core');
179
- render(<DragProvider {...defaultProps} />);
180
-
181
- expect(useSensor).toHaveBeenCalledWith('PointerSensor', { activationConstraint: { distance: 8 } });
182
- });
183
-
184
- it('should initialize KeyboardSensor', () => {
185
- const { useSensor } = require('@dnd-kit/core');
186
- render(<DragProvider {...defaultProps} />);
187
-
188
- expect(useSensor).toHaveBeenCalledWith('KeyboardSensor');
189
- });
190
-
191
- it('should combine sensors with useSensors', () => {
192
- const { useSensors } = require('@dnd-kit/core');
193
- render(<DragProvider {...defaultProps} />);
194
-
195
- expect(useSensors).toHaveBeenCalled();
196
- });
197
- });
198
-
199
- describe('re-rendering', () => {
200
- it('should update children when they change', () => {
201
- const { rerender } = render(<DragProvider {...defaultProps} />);
202
- expect(screen.getByText('Test Content')).toBeInTheDocument();
203
-
204
- rerender(
205
- <DragProvider>
206
- <div data-testid="new-child">New Content</div>
207
- </DragProvider>,
208
- );
209
- expect(screen.getByText('New Content')).toBeInTheDocument();
210
- expect(screen.queryByText('Test Content')).not.toBeInTheDocument();
211
- });
212
-
213
- it('should update handlers when they change', () => {
214
- const onDragStart1 = jest.fn();
215
- const onDragStart2 = jest.fn();
216
-
217
- const { rerender } = render(<DragProvider {...defaultProps} onDragStart={onDragStart1} />);
218
-
219
- rerender(<DragProvider {...defaultProps} onDragStart={onDragStart2} />);
220
-
221
- // Should still have the handler attribute
222
- const dndContext = screen.getByTestId('dnd-context');
223
- expect(dndContext).toHaveAttribute('data-on-drag-start', 'function');
224
- });
225
- });
226
-
227
- describe('edge cases', () => {
228
- it('should handle fragment children', () => {
229
- render(
230
- <DragProvider>
231
- <>
232
- <div data-testid="fragment-child-1">First</div>
233
- <div data-testid="fragment-child-2">Second</div>
234
- </>
235
- </DragProvider>,
236
- );
237
- expect(screen.getByTestId('fragment-child-1')).toBeInTheDocument();
238
- expect(screen.getByTestId('fragment-child-2')).toBeInTheDocument();
239
- });
240
-
241
- it('should handle null children within array', () => {
242
- render(
243
- <DragProvider>
244
- {[
245
- <div key="1" data-testid="valid-child">
246
- Valid
247
- </div>,
248
- null,
249
- <div key="2" data-testid="another-valid">
250
- Another
251
- </div>,
252
- ]}
253
- </DragProvider>,
254
- );
255
- expect(screen.getByTestId('valid-child')).toBeInTheDocument();
256
- expect(screen.getByTestId('another-valid')).toBeInTheDocument();
257
- });
258
-
259
- it('should handle empty modifiers array', () => {
260
- render(<DragProvider {...defaultProps} modifiers={[]} />);
261
- const dndContext = screen.getByTestId('dnd-context');
262
- expect(dndContext).toHaveAttribute('data-has-modifiers', 'true');
263
- });
264
-
265
- it('should handle multiple modifier functions', () => {
266
- const modifiers = [jest.fn(), jest.fn(), jest.fn()];
267
- render(<DragProvider {...defaultProps} modifiers={modifiers} />);
268
- const dndContext = screen.getByTestId('dnd-context');
269
- expect(dndContext).toHaveAttribute('data-has-modifiers', 'true');
270
- });
271
- });
272
-
273
- describe('prop types validation', () => {
274
- // Suppress console errors for prop type validation tests
275
- const originalError = console.error;
276
- beforeAll(() => {
277
- console.error = jest.fn();
278
- });
279
- afterAll(() => {
280
- console.error = originalError;
281
- });
282
-
283
- it('should accept valid children prop', () => {
284
- expect(() => {
285
- render(<DragProvider {...defaultProps} />);
286
- }).not.toThrow();
287
- });
288
-
289
- it('should accept function props for callbacks', () => {
290
- expect(() => {
291
- render(<DragProvider {...defaultProps} onDragStart={jest.fn()} onDragEnd={jest.fn()} />);
292
- }).not.toThrow();
293
- });
294
-
295
- it('should accept function prop for collisionDetection', () => {
296
- expect(() => {
297
- render(<DragProvider {...defaultProps} collisionDetection={jest.fn()} />);
298
- }).not.toThrow();
299
- });
300
-
301
- it('should accept array of functions for modifiers', () => {
302
- expect(() => {
303
- render(<DragProvider {...defaultProps} modifiers={[jest.fn(), jest.fn()]} />);
304
- }).not.toThrow();
305
- });
306
-
307
- it('should accept object for autoScroll', () => {
308
- expect(() => {
309
- render(<DragProvider {...defaultProps} autoScroll={{ enabled: true }} />);
310
- }).not.toThrow();
311
- });
312
- });
313
- });
@@ -1,107 +0,0 @@
1
- import { render, screen } from '@testing-library/react';
2
- import React from 'react';
3
- import { PlaceHolder } from '../placeholder';
4
-
5
- describe('placeholder', () => {
6
- const renderComponent = (extras = {}) => {
7
- const props = { ...extras };
8
- return render(<PlaceHolder {...props}>Foo</PlaceHolder>);
9
- };
10
-
11
- describe('rendering', () => {
12
- it('renders children content', () => {
13
- renderComponent();
14
- expect(screen.getByText('Foo')).toBeInTheDocument();
15
- });
16
-
17
- it('renders with regular placeholder class', () => {
18
- const { container } = renderComponent();
19
- const placeholder = container.firstChild;
20
- expect(placeholder).toHaveClass('placeholder');
21
- });
22
-
23
- it('applies over class when isOver is true', () => {
24
- const { container } = renderComponent({ isOver: true });
25
- const placeholder = container.firstChild;
26
- expect(placeholder).toHaveClass('over');
27
- });
28
-
29
- it('applies disabled class when disabled is true', () => {
30
- const { container } = renderComponent({ disabled: true });
31
- const placeholder = container.firstChild;
32
- expect(placeholder).toHaveClass('disabled');
33
- });
34
-
35
- it('applies custom className', () => {
36
- const { container } = renderComponent({ className: 'bar' });
37
- const placeholder = container.firstChild;
38
- expect(placeholder).toHaveClass('bar');
39
- expect(placeholder).toHaveClass('placeholder');
40
- });
41
-
42
- it('applies choice type class', () => {
43
- const { container } = renderComponent({ type: 'choice' });
44
- const placeholder = container.firstChild;
45
- expect(placeholder).toHaveClass('choice');
46
- });
47
-
48
- it('applies board class when choiceBoard is true', () => {
49
- const { container } = renderComponent({ choiceBoard: true });
50
- const placeholder = container.firstChild;
51
- expect(placeholder).toHaveClass('board');
52
- });
53
-
54
- it('applies categorizeBoard class when choiceBoard and isCategorize are true', () => {
55
- const { container } = renderComponent({ choiceBoard: true, isCategorize: true });
56
- const placeholder = container.firstChild;
57
- expect(placeholder).toHaveClass('categorizeBoard');
58
- });
59
-
60
- it('applies verticalPool class when isVerticalPool is true', () => {
61
- const { container } = renderComponent({ isVerticalPool: true });
62
- const placeholder = container.firstChild;
63
- expect(placeholder).toHaveClass('verticalPool');
64
- });
65
- });
66
-
67
- describe('grid styles', () => {
68
- it('applies grid column styles', () => {
69
- const { container } = renderComponent({
70
- grid: { columns: 3 },
71
- });
72
- const placeholder = container.firstChild;
73
- expect(placeholder).toHaveStyle({ gridTemplateColumns: 'repeat(3, 1fr)' });
74
- });
75
-
76
- it('applies grid row styles with default value', () => {
77
- const { container } = renderComponent({
78
- grid: { rows: 2 },
79
- });
80
- const placeholder = container.firstChild;
81
- expect(placeholder).toHaveStyle({ gridTemplateRows: 'repeat(2, 1fr)' });
82
- });
83
-
84
- it('applies grid row styles with custom rowsRepeatValue', () => {
85
- const { container } = renderComponent({
86
- grid: {
87
- rows: 2,
88
- columns: 1,
89
- rowsRepeatValue: 'min-content',
90
- },
91
- });
92
- const placeholder = container.firstChild;
93
- expect(placeholder).toHaveStyle({
94
- gridTemplateRows: 'repeat(2, min-content)',
95
- gridTemplateColumns: 'repeat(1, 1fr)',
96
- });
97
- });
98
- });
99
-
100
- describe('min height', () => {
101
- it('applies minHeight style when provided', () => {
102
- const { container } = renderComponent({ minHeight: 200 });
103
- const placeholder = container.firstChild;
104
- expect(placeholder).toHaveStyle({ minHeight: '200px' });
105
- });
106
- });
107
- });