@proyecto-viviana/solid-stately 0.2.4 → 0.2.7

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 (82) hide show
  1. package/LICENSE +21 -0
  2. package/dist/autocomplete/createAutocompleteState.d.ts +2 -1
  3. package/dist/checkbox/createCheckboxGroupState.d.ts +10 -1
  4. package/dist/collections/types.d.ts +11 -0
  5. package/dist/color/getColorChannels.d.ts +20 -0
  6. package/dist/data/createAsyncList.d.ts +111 -0
  7. package/dist/data/createListData.d.ts +65 -0
  8. package/dist/data/createTreeData.d.ts +61 -0
  9. package/dist/data/index.d.ts +3 -0
  10. package/dist/datepicker/index.d.ts +10 -0
  11. package/dist/grid/types.d.ts +5 -1
  12. package/dist/index.d.ts +6 -1
  13. package/dist/index.js +3737 -2697
  14. package/dist/index.js.map +1 -7
  15. package/dist/menu/index.d.ts +8 -0
  16. package/dist/radio/createRadioGroupState.d.ts +10 -1
  17. package/dist/select/createSelectState.d.ts +17 -0
  18. package/dist/selection/index.d.ts +11 -0
  19. package/dist/toast/createToastState.d.ts +7 -1
  20. package/dist/toggle/createToggleGroupState.d.ts +45 -0
  21. package/dist/toggle/index.d.ts +1 -0
  22. package/dist/tree/TreeCollection.d.ts +3 -2
  23. package/package.json +6 -5
  24. package/src/autocomplete/createAutocompleteState.ts +10 -11
  25. package/src/calendar/createDateFieldState.ts +24 -1
  26. package/src/checkbox/createCheckboxGroupState.ts +42 -6
  27. package/src/collections/ListCollection.ts +152 -146
  28. package/src/collections/createListState.ts +266 -264
  29. package/src/collections/createMenuState.ts +106 -106
  30. package/src/collections/createSelectionState.ts +336 -336
  31. package/src/collections/index.ts +46 -46
  32. package/src/collections/types.ts +181 -169
  33. package/src/color/Color.ts +951 -951
  34. package/src/color/createColorAreaState.ts +293 -293
  35. package/src/color/createColorFieldState.ts +292 -292
  36. package/src/color/createColorSliderState.ts +241 -241
  37. package/src/color/createColorWheelState.ts +211 -211
  38. package/src/color/getColorChannels.ts +34 -0
  39. package/src/color/index.ts +47 -47
  40. package/src/color/types.ts +127 -127
  41. package/src/combobox/createComboBoxState.ts +703 -703
  42. package/src/combobox/index.ts +13 -13
  43. package/src/data/createAsyncList.ts +377 -0
  44. package/src/data/createListData.ts +298 -0
  45. package/src/data/createTreeData.ts +433 -0
  46. package/src/data/index.ts +25 -0
  47. package/src/datepicker/index.ts +36 -0
  48. package/src/disclosure/createDisclosureState.ts +4 -4
  49. package/src/dnd/createDragState.ts +153 -153
  50. package/src/dnd/createDraggableCollectionState.ts +165 -165
  51. package/src/dnd/createDropState.ts +212 -212
  52. package/src/dnd/createDroppableCollectionState.ts +357 -357
  53. package/src/dnd/index.ts +76 -76
  54. package/src/dnd/types.ts +317 -317
  55. package/src/form/createFormValidationState.ts +389 -389
  56. package/src/form/index.ts +15 -15
  57. package/src/grid/types.ts +5 -0
  58. package/src/index.ts +49 -0
  59. package/src/menu/index.ts +19 -0
  60. package/src/numberfield/createNumberFieldState.ts +427 -383
  61. package/src/numberfield/index.ts +5 -5
  62. package/src/overlays/createOverlayTriggerState.ts +67 -67
  63. package/src/overlays/index.ts +5 -5
  64. package/src/radio/createRadioGroupState.ts +44 -6
  65. package/src/searchfield/createSearchFieldState.ts +62 -62
  66. package/src/searchfield/index.ts +5 -5
  67. package/src/select/createSelectState.ts +290 -181
  68. package/src/select/index.ts +5 -5
  69. package/src/selection/index.ts +28 -0
  70. package/src/slider/createSliderState.ts +211 -211
  71. package/src/slider/index.ts +6 -6
  72. package/src/tabs/createTabListState.ts +37 -11
  73. package/src/toast/createToastState.d.ts +6 -1
  74. package/src/toast/createToastState.ts +8 -1
  75. package/src/toggle/createToggleGroupState.ts +127 -0
  76. package/src/toggle/index.ts +6 -0
  77. package/src/tooltip/createTooltipTriggerState.ts +183 -183
  78. package/src/tooltip/index.ts +6 -6
  79. package/src/tree/TreeCollection.ts +208 -175
  80. package/src/tree/createTreeState.ts +392 -392
  81. package/src/tree/index.ts +13 -13
  82. package/src/tree/types.ts +174 -174
@@ -1,357 +1,357 @@
1
- /**
2
- * Droppable collection state management for solid-stately.
3
- *
4
- * Provides reactive state for accepting drops onto a collection.
5
- */
6
-
7
- import { createSignal, createMemo, type Accessor } from 'solid-js';
8
- import type {
9
- DropItem,
10
- DropTarget,
11
- DropOperation,
12
- DragTypes,
13
- DroppableCollectionEnterEvent,
14
- DroppableCollectionMoveEvent,
15
- DroppableCollectionActivateEvent,
16
- DroppableCollectionExitEvent,
17
- DroppableCollectionDropEvent,
18
- DroppableCollectionInsertDropEvent,
19
- DroppableCollectionRootDropEvent,
20
- DroppableCollectionOnItemDropEvent,
21
- DroppableCollectionReorderEvent,
22
- ItemDropTarget,
23
- } from './types';
24
-
25
- export interface DroppableCollectionStateOptions {
26
- /**
27
- * The drag types that the droppable collection accepts.
28
- * @default 'all'
29
- */
30
- acceptedDragTypes?: 'all' | Array<string | symbol>;
31
- /**
32
- * A function returning the drop operation to be performed.
33
- */
34
- getDropOperation?: (
35
- target: DropTarget,
36
- types: DragTypes,
37
- allowedOperations: DropOperation[]
38
- ) => DropOperation;
39
- /** Handler that is called when a valid drag enters a drop target. */
40
- onDropEnter?: (e: DroppableCollectionEnterEvent) => void;
41
- /** Handler that is called after a valid drag is held over a drop target. */
42
- onDropActivate?: (e: DroppableCollectionActivateEvent) => void;
43
- /** Handler that is called when a valid drag exits a drop target. */
44
- onDropExit?: (e: DroppableCollectionExitEvent) => void;
45
- /** Handler that is called when a valid drag is dropped. */
46
- onDrop?: (e: DroppableCollectionDropEvent) => void;
47
- /** Handler that is called when external items are dropped "between" items. */
48
- onInsert?: (e: DroppableCollectionInsertDropEvent) => void;
49
- /** Handler that is called when external items are dropped on the collection's root. */
50
- onRootDrop?: (e: DroppableCollectionRootDropEvent) => void;
51
- /** Handler that is called when items are dropped "on" an item. */
52
- onItemDrop?: (e: DroppableCollectionOnItemDropEvent) => void;
53
- /** Handler that is called when items are reordered within the collection. */
54
- onReorder?: (e: DroppableCollectionReorderEvent) => void;
55
- /** Handler that is called when items are moved within the source collection. */
56
- onMove?: (e: DroppableCollectionReorderEvent) => void;
57
- /** A function returning whether a given target is a valid "on" drop target. */
58
- shouldAcceptItemDrop?: (target: ItemDropTarget, types: DragTypes) => boolean;
59
- /** Whether the droppable collection is disabled. */
60
- isDisabled?: boolean;
61
- }
62
-
63
- export interface DroppableCollectionState {
64
- /** Whether a drag is currently over the collection. */
65
- readonly isDropTarget: boolean;
66
- /** The current drop target within the collection. */
67
- readonly target: DropTarget | null;
68
- /** Whether the collection is disabled for drops. */
69
- readonly isDisabled: boolean;
70
- /** Set the current drop target. */
71
- setTarget(target: DropTarget | null): void;
72
- /** Check if a drag type is accepted. */
73
- isAccepted(types: DragTypes): boolean;
74
- /** Enter the collection with a drop target. */
75
- enterTarget(target: DropTarget, x: number, y: number): void;
76
- /** Move to a new target within the collection. */
77
- moveToTarget(target: DropTarget, x: number, y: number): void;
78
- /** Exit the collection. */
79
- exitTarget(x: number, y: number): void;
80
- /** Activate the current target. */
81
- activateTarget(x: number, y: number): void;
82
- /** Perform a drop on the collection. */
83
- drop(
84
- items: DropItem[],
85
- dropOperation: DropOperation,
86
- isInternal: boolean,
87
- draggingKeys?: Set<string | number>
88
- ): void;
89
- /** Get the drop operation for a target. */
90
- getDropOperation(
91
- target: DropTarget,
92
- types: DragTypes,
93
- allowedOperations: DropOperation[]
94
- ): DropOperation;
95
- /** Check if an item drop should be accepted. */
96
- shouldAcceptItemDrop(target: ItemDropTarget, types: DragTypes): boolean;
97
- }
98
-
99
- /**
100
- * Symbol for directory drag type.
101
- */
102
- export const DIRECTORY_DRAG_TYPE: symbol = Symbol('directory');
103
-
104
- /**
105
- * Creates state for accepting drops onto a collection.
106
- *
107
- * @param props - Accessor returning droppable collection options
108
- * @returns Droppable collection state object
109
- */
110
- export function createDroppableCollectionState(
111
- props: Accessor<DroppableCollectionStateOptions>
112
- ): DroppableCollectionState {
113
- const getProps = createMemo(() => props());
114
-
115
- const [isDropTarget, setIsDropTarget] = createSignal(false);
116
- const [target, setTarget] = createSignal<DropTarget | null>(null);
117
-
118
- const isAccepted = (types: DragTypes): boolean => {
119
- const p = getProps();
120
- const acceptedTypes = p.acceptedDragTypes ?? 'all';
121
-
122
- if (acceptedTypes === 'all') {
123
- return true;
124
- }
125
-
126
- for (const type of acceptedTypes) {
127
- if (types.has(type)) {
128
- return true;
129
- }
130
- }
131
-
132
- return false;
133
- };
134
-
135
- const enterTarget = (dropTarget: DropTarget, x: number, y: number) => {
136
- const p = getProps();
137
- if (p.isDisabled) return;
138
-
139
- setIsDropTarget(true);
140
- setTarget(dropTarget);
141
-
142
- if (typeof p.onDropEnter === 'function') {
143
- p.onDropEnter({
144
- type: 'dropenter',
145
- x,
146
- y,
147
- target: dropTarget,
148
- });
149
- }
150
- };
151
-
152
- const moveToTarget = (dropTarget: DropTarget, x: number, y: number) => {
153
- const p = getProps();
154
- if (p.isDisabled) return;
155
-
156
- const prevTarget = target();
157
- setTarget(dropTarget);
158
-
159
- // Fire exit/enter events if target changed
160
- if (prevTarget && !targetsEqual(prevTarget, dropTarget)) {
161
- if (typeof p.onDropExit === 'function') {
162
- p.onDropExit({
163
- type: 'dropexit',
164
- x,
165
- y,
166
- target: prevTarget,
167
- });
168
- }
169
-
170
- if (typeof p.onDropEnter === 'function') {
171
- p.onDropEnter({
172
- type: 'dropenter',
173
- x,
174
- y,
175
- target: dropTarget,
176
- });
177
- }
178
- }
179
- };
180
-
181
- const exitTarget = (x: number, y: number) => {
182
- const p = getProps();
183
- const currentTarget = target();
184
-
185
- setIsDropTarget(false);
186
- setTarget(null);
187
-
188
- if (currentTarget && typeof p.onDropExit === 'function') {
189
- p.onDropExit({
190
- type: 'dropexit',
191
- x,
192
- y,
193
- target: currentTarget,
194
- });
195
- }
196
- };
197
-
198
- const activateTarget = (x: number, y: number) => {
199
- const p = getProps();
200
- const currentTarget = target();
201
- if (p.isDisabled || !currentTarget) return;
202
-
203
- if (typeof p.onDropActivate === 'function') {
204
- p.onDropActivate({
205
- type: 'dropactivate',
206
- x,
207
- y,
208
- target: currentTarget,
209
- });
210
- }
211
- };
212
-
213
- const drop = (
214
- items: DropItem[],
215
- dropOperation: DropOperation,
216
- isInternal: boolean,
217
- draggingKeys?: Set<string | number>
218
- ) => {
219
- const p = getProps();
220
- const currentTarget = target();
221
- if (p.isDisabled || !currentTarget) return;
222
-
223
- setIsDropTarget(false);
224
- setTarget(null);
225
-
226
- // Call the generic onDrop handler
227
- if (typeof p.onDrop === 'function') {
228
- p.onDrop({
229
- type: 'drop',
230
- x: 0,
231
- y: 0,
232
- items,
233
- dropOperation,
234
- target: currentTarget,
235
- });
236
- }
237
-
238
- // Call specific handlers based on the drop type
239
- if (currentTarget.type === 'root') {
240
- if (typeof p.onRootDrop === 'function') {
241
- p.onRootDrop({
242
- items,
243
- dropOperation,
244
- });
245
- }
246
- } else if (currentTarget.type === 'item') {
247
- if (isInternal && draggingKeys) {
248
- // Reorder or move within the same collection
249
- if (currentTarget.dropPosition === 'on') {
250
- if (typeof p.onMove === 'function') {
251
- p.onMove({
252
- keys: draggingKeys,
253
- dropOperation,
254
- target: currentTarget,
255
- });
256
- }
257
- } else {
258
- if (typeof p.onReorder === 'function') {
259
- p.onReorder({
260
- keys: draggingKeys,
261
- dropOperation,
262
- target: currentTarget,
263
- });
264
- }
265
- }
266
- } else {
267
- // External drop
268
- if (currentTarget.dropPosition === 'on') {
269
- if (typeof p.onItemDrop === 'function') {
270
- p.onItemDrop({
271
- items,
272
- dropOperation,
273
- isInternal,
274
- target: currentTarget,
275
- });
276
- }
277
- } else {
278
- if (typeof p.onInsert === 'function') {
279
- p.onInsert({
280
- items,
281
- dropOperation,
282
- target: currentTarget,
283
- });
284
- }
285
- }
286
- }
287
- }
288
- };
289
-
290
- const getDropOperation = (
291
- dropTarget: DropTarget,
292
- types: DragTypes,
293
- allowedOperations: DropOperation[]
294
- ): DropOperation => {
295
- const p = getProps();
296
-
297
- if (!isAccepted(types)) {
298
- return 'cancel';
299
- }
300
-
301
- if (typeof p.getDropOperation === 'function') {
302
- return p.getDropOperation(dropTarget, types, allowedOperations);
303
- }
304
-
305
- return allowedOperations[0] ?? 'cancel';
306
- };
307
-
308
- const shouldAcceptItemDrop = (
309
- dropTarget: ItemDropTarget,
310
- types: DragTypes
311
- ): boolean => {
312
- const p = getProps();
313
-
314
- if (!isAccepted(types)) {
315
- return false;
316
- }
317
-
318
- if (typeof p.shouldAcceptItemDrop === 'function') {
319
- return p.shouldAcceptItemDrop(dropTarget, types);
320
- }
321
-
322
- return true;
323
- };
324
-
325
- return {
326
- get isDropTarget() {
327
- return isDropTarget();
328
- },
329
- get target() {
330
- return target();
331
- },
332
- get isDisabled() {
333
- return getProps().isDisabled ?? false;
334
- },
335
- setTarget,
336
- isAccepted,
337
- enterTarget,
338
- moveToTarget,
339
- exitTarget,
340
- activateTarget,
341
- drop,
342
- getDropOperation,
343
- shouldAcceptItemDrop,
344
- };
345
- }
346
-
347
- /**
348
- * Check if two drop targets are equal.
349
- */
350
- function targetsEqual(a: DropTarget, b: DropTarget): boolean {
351
- if (a.type !== b.type) return false;
352
- if (a.type === 'root' && b.type === 'root') return true;
353
- if (a.type === 'item' && b.type === 'item') {
354
- return a.key === b.key && a.dropPosition === b.dropPosition;
355
- }
356
- return false;
357
- }
1
+ /**
2
+ * Droppable collection state management for solid-stately.
3
+ *
4
+ * Provides reactive state for accepting drops onto a collection.
5
+ */
6
+
7
+ import { createSignal, createMemo, type Accessor } from 'solid-js';
8
+ import type {
9
+ DropItem,
10
+ DropTarget,
11
+ DropOperation,
12
+ DragTypes,
13
+ DroppableCollectionEnterEvent,
14
+ DroppableCollectionMoveEvent,
15
+ DroppableCollectionActivateEvent,
16
+ DroppableCollectionExitEvent,
17
+ DroppableCollectionDropEvent,
18
+ DroppableCollectionInsertDropEvent,
19
+ DroppableCollectionRootDropEvent,
20
+ DroppableCollectionOnItemDropEvent,
21
+ DroppableCollectionReorderEvent,
22
+ ItemDropTarget,
23
+ } from './types';
24
+
25
+ export interface DroppableCollectionStateOptions {
26
+ /**
27
+ * The drag types that the droppable collection accepts.
28
+ * @default 'all'
29
+ */
30
+ acceptedDragTypes?: 'all' | Array<string | symbol>;
31
+ /**
32
+ * A function returning the drop operation to be performed.
33
+ */
34
+ getDropOperation?: (
35
+ target: DropTarget,
36
+ types: DragTypes,
37
+ allowedOperations: DropOperation[]
38
+ ) => DropOperation;
39
+ /** Handler that is called when a valid drag enters a drop target. */
40
+ onDropEnter?: (e: DroppableCollectionEnterEvent) => void;
41
+ /** Handler that is called after a valid drag is held over a drop target. */
42
+ onDropActivate?: (e: DroppableCollectionActivateEvent) => void;
43
+ /** Handler that is called when a valid drag exits a drop target. */
44
+ onDropExit?: (e: DroppableCollectionExitEvent) => void;
45
+ /** Handler that is called when a valid drag is dropped. */
46
+ onDrop?: (e: DroppableCollectionDropEvent) => void;
47
+ /** Handler that is called when external items are dropped "between" items. */
48
+ onInsert?: (e: DroppableCollectionInsertDropEvent) => void;
49
+ /** Handler that is called when external items are dropped on the collection's root. */
50
+ onRootDrop?: (e: DroppableCollectionRootDropEvent) => void;
51
+ /** Handler that is called when items are dropped "on" an item. */
52
+ onItemDrop?: (e: DroppableCollectionOnItemDropEvent) => void;
53
+ /** Handler that is called when items are reordered within the collection. */
54
+ onReorder?: (e: DroppableCollectionReorderEvent) => void;
55
+ /** Handler that is called when items are moved within the source collection. */
56
+ onMove?: (e: DroppableCollectionReorderEvent) => void;
57
+ /** A function returning whether a given target is a valid "on" drop target. */
58
+ shouldAcceptItemDrop?: (target: ItemDropTarget, types: DragTypes) => boolean;
59
+ /** Whether the droppable collection is disabled. */
60
+ isDisabled?: boolean;
61
+ }
62
+
63
+ export interface DroppableCollectionState {
64
+ /** Whether a drag is currently over the collection. */
65
+ readonly isDropTarget: boolean;
66
+ /** The current drop target within the collection. */
67
+ readonly target: DropTarget | null;
68
+ /** Whether the collection is disabled for drops. */
69
+ readonly isDisabled: boolean;
70
+ /** Set the current drop target. */
71
+ setTarget(target: DropTarget | null): void;
72
+ /** Check if a drag type is accepted. */
73
+ isAccepted(types: DragTypes): boolean;
74
+ /** Enter the collection with a drop target. */
75
+ enterTarget(target: DropTarget, x: number, y: number): void;
76
+ /** Move to a new target within the collection. */
77
+ moveToTarget(target: DropTarget, x: number, y: number): void;
78
+ /** Exit the collection. */
79
+ exitTarget(x: number, y: number): void;
80
+ /** Activate the current target. */
81
+ activateTarget(x: number, y: number): void;
82
+ /** Perform a drop on the collection. */
83
+ drop(
84
+ items: DropItem[],
85
+ dropOperation: DropOperation,
86
+ isInternal: boolean,
87
+ draggingKeys?: Set<string | number>
88
+ ): void;
89
+ /** Get the drop operation for a target. */
90
+ getDropOperation(
91
+ target: DropTarget,
92
+ types: DragTypes,
93
+ allowedOperations: DropOperation[]
94
+ ): DropOperation;
95
+ /** Check if an item drop should be accepted. */
96
+ shouldAcceptItemDrop(target: ItemDropTarget, types: DragTypes): boolean;
97
+ }
98
+
99
+ /**
100
+ * Symbol for directory drag type.
101
+ */
102
+ export const DIRECTORY_DRAG_TYPE: symbol = Symbol('directory');
103
+
104
+ /**
105
+ * Creates state for accepting drops onto a collection.
106
+ *
107
+ * @param props - Accessor returning droppable collection options
108
+ * @returns Droppable collection state object
109
+ */
110
+ export function createDroppableCollectionState(
111
+ props: Accessor<DroppableCollectionStateOptions>
112
+ ): DroppableCollectionState {
113
+ const getProps = createMemo(() => props());
114
+
115
+ const [isDropTarget, setIsDropTarget] = createSignal(false);
116
+ const [target, setTarget] = createSignal<DropTarget | null>(null);
117
+
118
+ const isAccepted = (types: DragTypes): boolean => {
119
+ const p = getProps();
120
+ const acceptedTypes = p.acceptedDragTypes ?? 'all';
121
+
122
+ if (acceptedTypes === 'all') {
123
+ return true;
124
+ }
125
+
126
+ for (const type of acceptedTypes) {
127
+ if (types.has(type)) {
128
+ return true;
129
+ }
130
+ }
131
+
132
+ return false;
133
+ };
134
+
135
+ const enterTarget = (dropTarget: DropTarget, x: number, y: number) => {
136
+ const p = getProps();
137
+ if (p.isDisabled) return;
138
+
139
+ setIsDropTarget(true);
140
+ setTarget(dropTarget);
141
+
142
+ if (typeof p.onDropEnter === 'function') {
143
+ p.onDropEnter({
144
+ type: 'dropenter',
145
+ x,
146
+ y,
147
+ target: dropTarget,
148
+ });
149
+ }
150
+ };
151
+
152
+ const moveToTarget = (dropTarget: DropTarget, x: number, y: number) => {
153
+ const p = getProps();
154
+ if (p.isDisabled) return;
155
+
156
+ const prevTarget = target();
157
+ setTarget(dropTarget);
158
+
159
+ // Fire exit/enter events if target changed
160
+ if (prevTarget && !targetsEqual(prevTarget, dropTarget)) {
161
+ if (typeof p.onDropExit === 'function') {
162
+ p.onDropExit({
163
+ type: 'dropexit',
164
+ x,
165
+ y,
166
+ target: prevTarget,
167
+ });
168
+ }
169
+
170
+ if (typeof p.onDropEnter === 'function') {
171
+ p.onDropEnter({
172
+ type: 'dropenter',
173
+ x,
174
+ y,
175
+ target: dropTarget,
176
+ });
177
+ }
178
+ }
179
+ };
180
+
181
+ const exitTarget = (x: number, y: number) => {
182
+ const p = getProps();
183
+ const currentTarget = target();
184
+
185
+ setIsDropTarget(false);
186
+ setTarget(null);
187
+
188
+ if (currentTarget && typeof p.onDropExit === 'function') {
189
+ p.onDropExit({
190
+ type: 'dropexit',
191
+ x,
192
+ y,
193
+ target: currentTarget,
194
+ });
195
+ }
196
+ };
197
+
198
+ const activateTarget = (x: number, y: number) => {
199
+ const p = getProps();
200
+ const currentTarget = target();
201
+ if (p.isDisabled || !currentTarget) return;
202
+
203
+ if (typeof p.onDropActivate === 'function') {
204
+ p.onDropActivate({
205
+ type: 'dropactivate',
206
+ x,
207
+ y,
208
+ target: currentTarget,
209
+ });
210
+ }
211
+ };
212
+
213
+ const drop = (
214
+ items: DropItem[],
215
+ dropOperation: DropOperation,
216
+ isInternal: boolean,
217
+ draggingKeys?: Set<string | number>
218
+ ) => {
219
+ const p = getProps();
220
+ const currentTarget = target();
221
+ if (p.isDisabled || !currentTarget) return;
222
+
223
+ setIsDropTarget(false);
224
+ setTarget(null);
225
+
226
+ // Call the generic onDrop handler
227
+ if (typeof p.onDrop === 'function') {
228
+ p.onDrop({
229
+ type: 'drop',
230
+ x: 0,
231
+ y: 0,
232
+ items,
233
+ dropOperation,
234
+ target: currentTarget,
235
+ });
236
+ }
237
+
238
+ // Call specific handlers based on the drop type
239
+ if (currentTarget.type === 'root') {
240
+ if (typeof p.onRootDrop === 'function') {
241
+ p.onRootDrop({
242
+ items,
243
+ dropOperation,
244
+ });
245
+ }
246
+ } else if (currentTarget.type === 'item') {
247
+ if (isInternal && draggingKeys) {
248
+ // Reorder or move within the same collection
249
+ if (currentTarget.dropPosition === 'on') {
250
+ if (typeof p.onMove === 'function') {
251
+ p.onMove({
252
+ keys: draggingKeys,
253
+ dropOperation,
254
+ target: currentTarget,
255
+ });
256
+ }
257
+ } else {
258
+ if (typeof p.onReorder === 'function') {
259
+ p.onReorder({
260
+ keys: draggingKeys,
261
+ dropOperation,
262
+ target: currentTarget,
263
+ });
264
+ }
265
+ }
266
+ } else {
267
+ // External drop
268
+ if (currentTarget.dropPosition === 'on') {
269
+ if (typeof p.onItemDrop === 'function') {
270
+ p.onItemDrop({
271
+ items,
272
+ dropOperation,
273
+ isInternal,
274
+ target: currentTarget,
275
+ });
276
+ }
277
+ } else {
278
+ if (typeof p.onInsert === 'function') {
279
+ p.onInsert({
280
+ items,
281
+ dropOperation,
282
+ target: currentTarget,
283
+ });
284
+ }
285
+ }
286
+ }
287
+ }
288
+ };
289
+
290
+ const getDropOperation = (
291
+ dropTarget: DropTarget,
292
+ types: DragTypes,
293
+ allowedOperations: DropOperation[]
294
+ ): DropOperation => {
295
+ const p = getProps();
296
+
297
+ if (!isAccepted(types)) {
298
+ return 'cancel';
299
+ }
300
+
301
+ if (typeof p.getDropOperation === 'function') {
302
+ return p.getDropOperation(dropTarget, types, allowedOperations);
303
+ }
304
+
305
+ return allowedOperations[0] ?? 'cancel';
306
+ };
307
+
308
+ const shouldAcceptItemDrop = (
309
+ dropTarget: ItemDropTarget,
310
+ types: DragTypes
311
+ ): boolean => {
312
+ const p = getProps();
313
+
314
+ if (!isAccepted(types)) {
315
+ return false;
316
+ }
317
+
318
+ if (typeof p.shouldAcceptItemDrop === 'function') {
319
+ return p.shouldAcceptItemDrop(dropTarget, types);
320
+ }
321
+
322
+ return true;
323
+ };
324
+
325
+ return {
326
+ get isDropTarget() {
327
+ return isDropTarget();
328
+ },
329
+ get target() {
330
+ return target();
331
+ },
332
+ get isDisabled() {
333
+ return getProps().isDisabled ?? false;
334
+ },
335
+ setTarget,
336
+ isAccepted,
337
+ enterTarget,
338
+ moveToTarget,
339
+ exitTarget,
340
+ activateTarget,
341
+ drop,
342
+ getDropOperation,
343
+ shouldAcceptItemDrop,
344
+ };
345
+ }
346
+
347
+ /**
348
+ * Check if two drop targets are equal.
349
+ */
350
+ function targetsEqual(a: DropTarget, b: DropTarget): boolean {
351
+ if (a.type !== b.type) return false;
352
+ if (a.type === 'root' && b.type === 'root') return true;
353
+ if (a.type === 'item' && b.type === 'item') {
354
+ return a.key === b.key && a.dropPosition === b.dropPosition;
355
+ }
356
+ return false;
357
+ }