@proyecto-viviana/solid-stately 0.0.5 → 0.1.0
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.
- package/README.md +312 -0
- package/dist/index.d.ts +3363 -6
- package/dist/index.js +6194 -19
- package/dist/index.js.map +1 -1
- package/package.json +52 -48
- package/src/autocomplete/createAutocompleteState.d.ts +46 -0
- package/src/autocomplete/createAutocompleteState.d.ts.map +1 -0
- package/src/autocomplete/createAutocompleteState.ts +90 -0
- package/src/autocomplete/index.d.ts +2 -0
- package/src/autocomplete/index.d.ts.map +1 -0
- package/src/autocomplete/index.ts +5 -0
- package/src/calendar/createCalendarState.d.ts +130 -0
- package/src/calendar/createCalendarState.d.ts.map +1 -0
- package/src/calendar/createCalendarState.ts +461 -0
- package/src/calendar/createDateFieldState.d.ts +110 -0
- package/src/calendar/createDateFieldState.d.ts.map +1 -0
- package/src/calendar/createDateFieldState.ts +562 -0
- package/src/calendar/createRangeCalendarState.d.ts +146 -0
- package/src/calendar/createRangeCalendarState.d.ts.map +1 -0
- package/src/calendar/createRangeCalendarState.ts +535 -0
- package/src/calendar/createTimeFieldState.d.ts +95 -0
- package/src/calendar/createTimeFieldState.d.ts.map +1 -0
- package/src/calendar/createTimeFieldState.ts +483 -0
- package/src/calendar/index.d.ts +7 -0
- package/src/calendar/index.d.ts.map +1 -0
- package/src/calendar/index.ts +81 -0
- package/{dist → src}/checkbox/createCheckboxGroupState.d.ts +1 -0
- package/src/checkbox/createCheckboxGroupState.d.ts.map +1 -0
- package/{dist → src}/checkbox/index.d.ts +1 -0
- package/src/checkbox/index.d.ts.map +1 -0
- package/src/collections/ListCollection.d.ts +37 -0
- package/src/collections/ListCollection.d.ts.map +1 -0
- package/src/collections/ListCollection.ts +146 -0
- package/src/collections/createListState.d.ts +79 -0
- package/src/collections/createListState.d.ts.map +1 -0
- package/src/collections/createListState.ts +264 -0
- package/src/collections/createMenuState.d.ts +50 -0
- package/src/collections/createMenuState.d.ts.map +1 -0
- package/src/collections/createMenuState.ts +106 -0
- package/src/collections/createSelectionState.d.ts +76 -0
- package/src/collections/createSelectionState.d.ts.map +1 -0
- package/src/collections/createSelectionState.ts +336 -0
- package/src/collections/index.d.ts +6 -0
- package/src/collections/index.d.ts.map +1 -0
- package/src/collections/index.ts +46 -0
- package/src/collections/types.d.ts +147 -0
- package/src/collections/types.d.ts.map +1 -0
- package/src/collections/types.ts +169 -0
- package/src/color/Color.d.ts +28 -0
- package/src/color/Color.d.ts.map +1 -0
- package/src/color/Color.ts +951 -0
- package/src/color/createColorAreaState.d.ts +76 -0
- package/src/color/createColorAreaState.d.ts.map +1 -0
- package/src/color/createColorAreaState.ts +293 -0
- package/src/color/createColorFieldState.d.ts +55 -0
- package/src/color/createColorFieldState.d.ts.map +1 -0
- package/src/color/createColorFieldState.ts +292 -0
- package/src/color/createColorSliderState.d.ts +67 -0
- package/src/color/createColorSliderState.d.ts.map +1 -0
- package/src/color/createColorSliderState.ts +241 -0
- package/src/color/createColorWheelState.d.ts +51 -0
- package/src/color/createColorWheelState.d.ts.map +1 -0
- package/src/color/createColorWheelState.ts +211 -0
- package/src/color/index.d.ts +10 -0
- package/src/color/index.d.ts.map +1 -0
- package/src/color/index.ts +47 -0
- package/src/color/types.d.ts +106 -0
- package/src/color/types.d.ts.map +1 -0
- package/src/color/types.ts +127 -0
- package/src/combobox/createComboBoxState.d.ts +125 -0
- package/src/combobox/createComboBoxState.d.ts.map +1 -0
- package/src/combobox/createComboBoxState.ts +703 -0
- package/src/combobox/index.d.ts +5 -0
- package/src/combobox/index.d.ts.map +1 -0
- package/src/combobox/index.ts +13 -0
- package/src/disclosure/createDisclosureState.d.ts +64 -0
- package/src/disclosure/createDisclosureState.d.ts.map +1 -0
- package/src/disclosure/createDisclosureState.ts +193 -0
- package/src/disclosure/index.d.ts +2 -0
- package/src/disclosure/index.d.ts.map +1 -0
- package/src/disclosure/index.ts +9 -0
- package/src/dnd/createDragState.d.ts +59 -0
- package/src/dnd/createDragState.d.ts.map +1 -0
- package/src/dnd/createDragState.ts +153 -0
- package/src/dnd/createDraggableCollectionState.d.ts +57 -0
- package/src/dnd/createDraggableCollectionState.d.ts.map +1 -0
- package/src/dnd/createDraggableCollectionState.ts +165 -0
- package/src/dnd/createDropState.d.ts +61 -0
- package/src/dnd/createDropState.d.ts.map +1 -0
- package/src/dnd/createDropState.ts +212 -0
- package/src/dnd/createDroppableCollectionState.d.ts +78 -0
- package/src/dnd/createDroppableCollectionState.d.ts.map +1 -0
- package/src/dnd/createDroppableCollectionState.ts +357 -0
- package/src/dnd/index.d.ts +11 -0
- package/src/dnd/index.d.ts.map +1 -0
- package/src/dnd/index.ts +76 -0
- package/src/dnd/types.d.ts +264 -0
- package/src/dnd/types.d.ts.map +1 -0
- package/src/dnd/types.ts +317 -0
- package/src/form/createFormValidationState.d.ts +100 -0
- package/src/form/createFormValidationState.d.ts.map +1 -0
- package/src/form/createFormValidationState.ts +389 -0
- package/src/form/index.d.ts +2 -0
- package/src/form/index.d.ts.map +1 -0
- package/src/form/index.ts +15 -0
- package/src/grid/createGridState.d.ts +12 -0
- package/src/grid/createGridState.d.ts.map +1 -0
- package/src/grid/createGridState.ts +327 -0
- package/src/grid/index.d.ts +7 -0
- package/src/grid/index.d.ts.map +1 -0
- package/src/grid/index.ts +13 -0
- package/src/grid/types.d.ts +156 -0
- package/src/grid/types.d.ts.map +1 -0
- package/src/grid/types.ts +179 -0
- package/src/index.d.ts +26 -0
- package/src/index.d.ts.map +1 -0
- package/src/index.ts +350 -1
- package/src/numberfield/createNumberFieldState.d.ts +65 -0
- package/src/numberfield/createNumberFieldState.d.ts.map +1 -0
- package/src/numberfield/createNumberFieldState.ts +383 -0
- package/src/numberfield/index.d.ts +2 -0
- package/src/numberfield/index.d.ts.map +1 -0
- package/src/numberfield/index.ts +5 -0
- package/src/overlays/createOverlayTriggerState.d.ts +32 -0
- package/src/overlays/createOverlayTriggerState.d.ts.map +1 -0
- package/src/overlays/createOverlayTriggerState.ts +67 -0
- package/src/overlays/index.d.ts +2 -0
- package/src/overlays/index.d.ts.map +1 -0
- package/src/overlays/index.ts +5 -0
- package/{dist → src}/radio/createRadioGroupState.d.ts +1 -0
- package/src/radio/createRadioGroupState.d.ts.map +1 -0
- package/{dist → src}/radio/index.d.ts +1 -0
- package/src/radio/index.d.ts.map +1 -0
- package/src/searchfield/createSearchFieldState.d.ts +25 -0
- package/src/searchfield/createSearchFieldState.d.ts.map +1 -0
- package/src/searchfield/createSearchFieldState.ts +62 -0
- package/src/searchfield/index.d.ts +3 -0
- package/src/searchfield/index.d.ts.map +1 -0
- package/src/searchfield/index.ts +5 -0
- package/src/select/createSelectState.d.ts +73 -0
- package/src/select/createSelectState.d.ts.map +1 -0
- package/src/select/createSelectState.ts +181 -0
- package/src/select/index.d.ts +2 -0
- package/src/select/index.d.ts.map +1 -0
- package/src/select/index.ts +5 -0
- package/src/slider/createSliderState.d.ts +72 -0
- package/src/slider/createSliderState.d.ts.map +1 -0
- package/src/slider/createSliderState.ts +211 -0
- package/src/slider/index.d.ts +3 -0
- package/src/slider/index.d.ts.map +1 -0
- package/src/slider/index.ts +6 -0
- package/{dist → src}/ssr/index.d.ts +5 -0
- package/src/ssr/index.d.ts.map +1 -0
- package/src/ssr/index.ts +6 -1
- package/src/table/TableCollection.d.ts +52 -0
- package/src/table/TableCollection.d.ts.map +1 -0
- package/src/table/TableCollection.ts +388 -0
- package/src/table/createTableState.d.ts +12 -0
- package/src/table/createTableState.d.ts.map +1 -0
- package/src/table/createTableState.ts +127 -0
- package/src/table/index.d.ts +8 -0
- package/src/table/index.d.ts.map +1 -0
- package/src/table/index.ts +18 -0
- package/src/table/types.d.ts +139 -0
- package/src/table/types.d.ts.map +1 -0
- package/src/table/types.ts +150 -0
- package/src/tabs/createTabListState.d.ts +68 -0
- package/src/tabs/createTabListState.d.ts.map +1 -0
- package/src/tabs/createTabListState.ts +240 -0
- package/src/tabs/index.d.ts +2 -0
- package/src/tabs/index.d.ts.map +1 -0
- package/src/tabs/index.ts +7 -0
- package/{dist → src}/textfield/createTextFieldState.d.ts +1 -0
- package/src/textfield/createTextFieldState.d.ts.map +1 -0
- package/{dist → src}/textfield/index.d.ts +1 -0
- package/src/textfield/index.d.ts.map +1 -0
- package/src/toast/createToastState.d.ts +118 -0
- package/src/toast/createToastState.d.ts.map +1 -0
- package/src/toast/createToastState.ts +316 -0
- package/src/toast/index.d.ts +2 -0
- package/src/toast/index.d.ts.map +1 -0
- package/src/toast/index.ts +11 -0
- package/{dist → src}/toggle/createToggleState.d.ts +1 -0
- package/src/toggle/createToggleState.d.ts.map +1 -0
- package/{dist → src}/toggle/index.d.ts +1 -0
- package/src/toggle/index.d.ts.map +1 -0
- package/src/tooltip/createTooltipTriggerState.d.ts +39 -0
- package/src/tooltip/createTooltipTriggerState.d.ts.map +1 -0
- package/src/tooltip/createTooltipTriggerState.ts +183 -0
- package/src/tooltip/index.d.ts +2 -0
- package/src/tooltip/index.d.ts.map +1 -0
- package/src/tooltip/index.ts +6 -0
- package/src/tree/TreeCollection.d.ts +40 -0
- package/src/tree/TreeCollection.d.ts.map +1 -0
- package/src/tree/TreeCollection.ts +175 -0
- package/src/tree/createTreeState.d.ts +14 -0
- package/src/tree/createTreeState.d.ts.map +1 -0
- package/src/tree/createTreeState.ts +392 -0
- package/src/tree/index.d.ts +7 -0
- package/src/tree/index.d.ts.map +1 -0
- package/src/tree/index.ts +13 -0
- package/src/tree/types.d.ts +157 -0
- package/src/tree/types.d.ts.map +1 -0
- package/src/tree/types.ts +174 -0
- package/{dist → src}/utils/index.d.ts +1 -0
- package/src/utils/index.d.ts.map +1 -0
- package/{dist → src}/utils/reactivity.d.ts +1 -0
- package/src/utils/reactivity.d.ts.map +1 -0
|
@@ -0,0 +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
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drag and Drop state management for solid-stately.
|
|
3
|
+
*
|
|
4
|
+
* Exports for DnD functionality.
|
|
5
|
+
*/
|
|
6
|
+
export type { DropOperation, DragItem, DragDropEvent, DragStartEvent, DragMoveEvent, DragEndEvent, DropEnterEvent, DropMoveEvent, DropActivateEvent, DropExitEvent, TextDropItem, FileDropItem, DirectoryDropItem, DropItem, DropEvent, DropPosition, RootDropTarget, ItemDropTarget, DropTarget, DroppableCollectionEnterEvent, DroppableCollectionMoveEvent, DroppableCollectionActivateEvent, DroppableCollectionExitEvent, DroppableCollectionDropEvent, DroppableCollectionInsertDropEvent, DroppableCollectionRootDropEvent, DroppableCollectionOnItemDropEvent, DroppableCollectionReorderEvent, DragTypes, DropTargetDelegate, DraggableCollectionStartEvent, DraggableCollectionMoveEvent, DraggableCollectionEndEvent, DragPreviewRenderer, DroppableCollectionUtilityOptions, DroppableCollectionBaseProps, DroppableCollectionProps, DraggableCollectionProps, } from './types';
|
|
7
|
+
export { createDragState, type DragStateOptions, type DragState, } from './createDragState';
|
|
8
|
+
export { createDropState, type DropStateOptions, type DropState, } from './createDropState';
|
|
9
|
+
export { createDraggableCollectionState, type DraggableCollectionStateOptions, type DraggableCollectionState, } from './createDraggableCollectionState';
|
|
10
|
+
export { createDroppableCollectionState, DIRECTORY_DRAG_TYPE, type DroppableCollectionStateOptions, type DroppableCollectionState, } from './createDroppableCollectionState';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,YAAY,EACV,aAAa,EACb,QAAQ,EACR,aAAa,EACb,cAAc,EACd,aAAa,EACb,YAAY,EACZ,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,iBAAiB,EACjB,QAAQ,EACR,SAAS,EACT,YAAY,EACZ,cAAc,EACd,cAAc,EACd,UAAU,EACV,6BAA6B,EAC7B,4BAA4B,EAC5B,gCAAgC,EAChC,4BAA4B,EAC5B,4BAA4B,EAC5B,kCAAkC,EAClC,gCAAgC,EAChC,kCAAkC,EAClC,+BAA+B,EAC/B,SAAS,EACT,kBAAkB,EAClB,6BAA6B,EAC7B,4BAA4B,EAC5B,2BAA2B,EAC3B,mBAAmB,EACnB,iCAAiC,EACjC,4BAA4B,EAC5B,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,eAAe,EACf,KAAK,gBAAgB,EACrB,KAAK,SAAS,GACf,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EACL,eAAe,EACf,KAAK,gBAAgB,EACrB,KAAK,SAAS,GACf,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EACL,8BAA8B,EAC9B,KAAK,+BAA+B,EACpC,KAAK,wBAAwB,GAC9B,MAAM,kCAAkC,CAAC;AAG1C,OAAO,EACL,8BAA8B,EAC9B,mBAAmB,EACnB,KAAK,+BAA+B,EACpC,KAAK,wBAAwB,GAC9B,MAAM,kCAAkC,CAAC"}
|
package/src/dnd/index.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drag and Drop state management for solid-stately.
|
|
3
|
+
*
|
|
4
|
+
* Exports for DnD functionality.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// Types
|
|
8
|
+
export type {
|
|
9
|
+
DropOperation,
|
|
10
|
+
DragItem,
|
|
11
|
+
DragDropEvent,
|
|
12
|
+
DragStartEvent,
|
|
13
|
+
DragMoveEvent,
|
|
14
|
+
DragEndEvent,
|
|
15
|
+
DropEnterEvent,
|
|
16
|
+
DropMoveEvent,
|
|
17
|
+
DropActivateEvent,
|
|
18
|
+
DropExitEvent,
|
|
19
|
+
TextDropItem,
|
|
20
|
+
FileDropItem,
|
|
21
|
+
DirectoryDropItem,
|
|
22
|
+
DropItem,
|
|
23
|
+
DropEvent,
|
|
24
|
+
DropPosition,
|
|
25
|
+
RootDropTarget,
|
|
26
|
+
ItemDropTarget,
|
|
27
|
+
DropTarget,
|
|
28
|
+
DroppableCollectionEnterEvent,
|
|
29
|
+
DroppableCollectionMoveEvent,
|
|
30
|
+
DroppableCollectionActivateEvent,
|
|
31
|
+
DroppableCollectionExitEvent,
|
|
32
|
+
DroppableCollectionDropEvent,
|
|
33
|
+
DroppableCollectionInsertDropEvent,
|
|
34
|
+
DroppableCollectionRootDropEvent,
|
|
35
|
+
DroppableCollectionOnItemDropEvent,
|
|
36
|
+
DroppableCollectionReorderEvent,
|
|
37
|
+
DragTypes,
|
|
38
|
+
DropTargetDelegate,
|
|
39
|
+
DraggableCollectionStartEvent,
|
|
40
|
+
DraggableCollectionMoveEvent,
|
|
41
|
+
DraggableCollectionEndEvent,
|
|
42
|
+
DragPreviewRenderer,
|
|
43
|
+
DroppableCollectionUtilityOptions,
|
|
44
|
+
DroppableCollectionBaseProps,
|
|
45
|
+
DroppableCollectionProps,
|
|
46
|
+
DraggableCollectionProps,
|
|
47
|
+
} from './types';
|
|
48
|
+
|
|
49
|
+
// Drag state
|
|
50
|
+
export {
|
|
51
|
+
createDragState,
|
|
52
|
+
type DragStateOptions,
|
|
53
|
+
type DragState,
|
|
54
|
+
} from './createDragState';
|
|
55
|
+
|
|
56
|
+
// Drop state
|
|
57
|
+
export {
|
|
58
|
+
createDropState,
|
|
59
|
+
type DropStateOptions,
|
|
60
|
+
type DropState,
|
|
61
|
+
} from './createDropState';
|
|
62
|
+
|
|
63
|
+
// Draggable collection state
|
|
64
|
+
export {
|
|
65
|
+
createDraggableCollectionState,
|
|
66
|
+
type DraggableCollectionStateOptions,
|
|
67
|
+
type DraggableCollectionState,
|
|
68
|
+
} from './createDraggableCollectionState';
|
|
69
|
+
|
|
70
|
+
// Droppable collection state
|
|
71
|
+
export {
|
|
72
|
+
createDroppableCollectionState,
|
|
73
|
+
DIRECTORY_DRAG_TYPE,
|
|
74
|
+
type DroppableCollectionStateOptions,
|
|
75
|
+
type DroppableCollectionState,
|
|
76
|
+
} from './createDroppableCollectionState';
|