@proyecto-viviana/solidaria-components 0.2.9 → 0.3.1
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 +39 -272
- package/dist/ActionBar.d.ts +21 -13
- package/dist/ActionBar.d.ts.map +1 -1
- package/dist/ActionGroup.d.ts +8 -8
- package/dist/ActionGroup.d.ts.map +1 -1
- package/dist/Alert.d.ts +5 -5
- package/dist/Alert.d.ts.map +1 -1
- package/dist/Autocomplete.d.ts +5 -5
- package/dist/Autocomplete.d.ts.map +1 -1
- package/dist/Breadcrumbs.d.ts +18 -7
- package/dist/Breadcrumbs.d.ts.map +1 -1
- package/dist/Button.d.ts +24 -5
- package/dist/Button.d.ts.map +1 -1
- package/dist/Calendar.d.ts +38 -7
- package/dist/Calendar.d.ts.map +1 -1
- package/dist/Checkbox.d.ts +32 -7
- package/dist/Checkbox.d.ts.map +1 -1
- package/dist/Collection.d.ts +19 -14
- package/dist/Collection.d.ts.map +1 -1
- package/dist/Color.d.ts +103 -14
- package/dist/Color.d.ts.map +1 -1
- package/dist/ColorEditor.d.ts +6 -6
- package/dist/ColorEditor.d.ts.map +1 -1
- package/dist/ComboBox.d.ts +85 -19
- package/dist/ComboBox.d.ts.map +1 -1
- package/dist/ContextualHelpTrigger.d.ts +2 -2
- package/dist/ContextualHelpTrigger.d.ts.map +1 -1
- package/dist/DateField.d.ts +8 -6
- package/dist/DateField.d.ts.map +1 -1
- package/dist/DatePicker.d.ts +53 -22
- package/dist/DatePicker.d.ts.map +1 -1
- package/dist/DateRangePickerContext.d.ts +30 -0
- package/dist/DateRangePickerContext.d.ts.map +1 -0
- package/dist/Dialog.d.ts +5 -5
- package/dist/Dialog.d.ts.map +1 -1
- package/dist/Disclosure.d.ts +23 -5
- package/dist/Disclosure.d.ts.map +1 -1
- package/dist/DragAndDrop.d.ts +6 -6
- package/dist/DragAndDrop.d.ts.map +1 -1
- package/dist/DragPreview.d.ts +2 -2
- package/dist/DragPreview.d.ts.map +1 -1
- package/dist/DropZone.d.ts +4 -4
- package/dist/DropZone.d.ts.map +1 -1
- package/dist/FieldError.d.ts +9 -5
- package/dist/FieldError.d.ts.map +1 -1
- package/dist/FileTrigger.d.ts +3 -3
- package/dist/FileTrigger.d.ts.map +1 -1
- package/dist/Focusable.d.ts +2 -2
- package/dist/Focusable.d.ts.map +1 -1
- package/dist/Form.d.ts +18 -4
- package/dist/Form.d.ts.map +1 -1
- package/dist/GridList.d.ts +32 -12
- package/dist/GridList.d.ts.map +1 -1
- package/dist/HiddenDateInput.d.ts +26 -0
- package/dist/HiddenDateInput.d.ts.map +1 -0
- package/dist/HiddenTimeInput.d.ts +25 -0
- package/dist/HiddenTimeInput.d.ts.map +1 -0
- package/dist/Icon.d.ts +5 -5
- package/dist/Icon.d.ts.map +1 -1
- package/dist/Keyboard.d.ts +1 -1
- package/dist/Landmark.d.ts +3 -3
- package/dist/Landmark.d.ts.map +1 -1
- package/dist/Link.d.ts +10 -4
- package/dist/Link.d.ts.map +1 -1
- package/dist/ListBox.d.ts +32 -12
- package/dist/ListBox.d.ts.map +1 -1
- package/dist/ListDropTargetDelegate.d.ts +6 -6
- package/dist/ListDropTargetDelegate.d.ts.map +1 -1
- package/dist/Menu.d.ts +65 -14
- package/dist/Menu.d.ts.map +1 -1
- package/dist/Meter.d.ts +3 -3
- package/dist/Meter.d.ts.map +1 -1
- package/dist/Modal.d.ts +5 -5
- package/dist/Modal.d.ts.map +1 -1
- package/dist/NumberField.d.ts +8 -12
- package/dist/NumberField.d.ts.map +1 -1
- package/dist/Popover.d.ts +28 -5
- package/dist/Popover.d.ts.map +1 -1
- package/dist/Pressable.d.ts +2 -2
- package/dist/Pressable.d.ts.map +1 -1
- package/dist/ProgressBar.d.ts +5 -3
- package/dist/ProgressBar.d.ts.map +1 -1
- package/dist/RadioGroup.d.ts +43 -9
- package/dist/RadioGroup.d.ts.map +1 -1
- package/dist/RangeCalendar.d.ts +34 -7
- package/dist/RangeCalendar.d.ts.map +1 -1
- package/dist/RouterProvider.d.ts +2 -2
- package/dist/RouterProvider.d.ts.map +1 -1
- package/dist/SearchField.d.ts +23 -20
- package/dist/SearchField.d.ts.map +1 -1
- package/dist/Select.d.ts +41 -11
- package/dist/Select.d.ts.map +1 -1
- package/dist/SelectionIndicator.d.ts +3 -3
- package/dist/SelectionIndicator.d.ts.map +1 -1
- package/dist/Separator.d.ts +9 -3
- package/dist/Separator.d.ts.map +1 -1
- package/dist/SharedElementTransition.d.ts +6 -4
- package/dist/SharedElementTransition.d.ts.map +1 -1
- package/dist/Slider.d.ts +12 -8
- package/dist/Slider.d.ts.map +1 -1
- package/dist/StepList.d.ts +90 -0
- package/dist/StepList.d.ts.map +1 -0
- package/dist/Switch.d.ts +11 -5
- package/dist/Switch.d.ts.map +1 -1
- package/dist/Table.d.ts +187 -23
- package/dist/Table.d.ts.map +1 -1
- package/dist/Tabs.d.ts +45 -9
- package/dist/Tabs.d.ts.map +1 -1
- package/dist/TagGroup.d.ts +12 -10
- package/dist/TagGroup.d.ts.map +1 -1
- package/dist/Text.d.ts +2 -2
- package/dist/TextField.d.ts +15 -11
- package/dist/TextField.d.ts.map +1 -1
- package/dist/TimeField.d.ts +6 -6
- package/dist/TimeField.d.ts.map +1 -1
- package/dist/Toast.d.ts +29 -14
- package/dist/Toast.d.ts.map +1 -1
- package/dist/ToggleButton.d.ts +11 -5
- package/dist/ToggleButton.d.ts.map +1 -1
- package/dist/ToggleButtonGroup.d.ts +7 -7
- package/dist/ToggleButtonGroup.d.ts.map +1 -1
- package/dist/Toolbar.d.ts +7 -3
- package/dist/Toolbar.d.ts.map +1 -1
- package/dist/Tooltip.d.ts +50 -8
- package/dist/Tooltip.d.ts.map +1 -1
- package/dist/Tree.d.ts +66 -17
- package/dist/Tree.d.ts.map +1 -1
- package/dist/Virtualizer.d.ts +12 -12
- package/dist/Virtualizer.d.ts.map +1 -1
- package/dist/VirtualizerLayouts.d.ts +2 -2
- package/dist/VirtualizerLayouts.d.ts.map +1 -1
- package/dist/VisuallyHidden.d.ts +1 -1
- package/dist/VisuallyHidden.d.ts.map +1 -1
- package/dist/contexts.d.ts +5 -1
- package/dist/contexts.d.ts.map +1 -1
- package/dist/index.d.ts +73 -71
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23253 -18564
- package/dist/index.js.map +1 -1
- package/dist/index.jsx +18116 -0
- package/dist/index.jsx.map +1 -0
- package/dist/useDragAndDrop.d.ts +13 -13
- package/dist/useDragAndDrop.d.ts.map +1 -1
- package/dist/utils.d.ts +2 -2
- package/dist/utils.d.ts.map +1 -1
- package/dist/virtualizer/Layout.d.ts +1 -1
- package/dist/virtualizer/Layout.d.ts.map +1 -1
- package/package.json +31 -32
- package/src/ActionBar.tsx +75 -72
- package/src/ActionGroup.tsx +53 -61
- package/src/Alert.tsx +17 -42
- package/src/Autocomplete.tsx +39 -44
- package/src/Breadcrumbs.tsx +149 -80
- package/src/Button.tsx +267 -70
- package/src/Calendar.tsx +218 -138
- package/src/Checkbox.tsx +413 -121
- package/src/Collection.tsx +67 -58
- package/src/Color.tsx +803 -380
- package/src/ColorEditor.tsx +131 -149
- package/src/ComboBox.tsx +414 -249
- package/src/ContextualHelpTrigger.tsx +86 -74
- package/src/DateField.tsx +185 -91
- package/src/DatePicker.tsx +524 -213
- package/src/DateRangePickerContext.tsx +44 -0
- package/src/Dialog.tsx +156 -118
- package/src/Disclosure.tsx +127 -80
- package/src/DragAndDrop.tsx +60 -54
- package/src/DragPreview.tsx +13 -11
- package/src/DropZone.tsx +42 -22
- package/src/FieldError.tsx +45 -23
- package/src/FileTrigger.tsx +19 -19
- package/src/Focusable.tsx +21 -24
- package/src/Form.tsx +71 -16
- package/src/GridList.tsx +273 -197
- package/src/HiddenDateInput.tsx +153 -0
- package/src/HiddenTimeInput.tsx +133 -0
- package/src/Icon.tsx +22 -43
- package/src/Keyboard.tsx +3 -3
- package/src/Landmark.tsx +37 -63
- package/src/Link.tsx +125 -75
- package/src/ListBox.tsx +332 -233
- package/src/ListDropTargetDelegate.ts +81 -80
- package/src/Menu.tsx +1023 -274
- package/src/Meter.tsx +38 -56
- package/src/Modal.tsx +251 -176
- package/src/NumberField.tsx +139 -143
- package/src/Popover.tsx +396 -234
- package/src/Pressable.tsx +21 -21
- package/src/ProgressBar.tsx +48 -57
- package/src/RadioGroup.tsx +524 -122
- package/src/RangeCalendar.tsx +157 -90
- package/src/RouterProvider.tsx +30 -47
- package/src/SearchField.tsx +362 -143
- package/src/Select.tsx +656 -233
- package/src/SelectionIndicator.tsx +18 -15
- package/src/Separator.tsx +47 -49
- package/src/SharedElementTransition.tsx +103 -97
- package/src/Slider.tsx +138 -98
- package/src/StepList.tsx +272 -0
- package/src/Switch.tsx +93 -46
- package/src/Table.tsx +1308 -342
- package/src/Tabs.tsx +324 -103
- package/src/TagGroup.tsx +139 -126
- package/src/Text.tsx +3 -3
- package/src/TextField.tsx +389 -79
- package/src/TimeField.tsx +136 -76
- package/src/Toast.tsx +216 -158
- package/src/ToggleButton.tsx +47 -37
- package/src/ToggleButtonGroup.tsx +39 -34
- package/src/Toolbar.tsx +54 -69
- package/src/Tooltip.tsx +387 -119
- package/src/Tree.tsx +651 -368
- package/src/Virtualizer.tsx +208 -180
- package/src/VirtualizerLayouts.ts +45 -30
- package/src/VisuallyHidden.tsx +19 -19
- package/src/contexts.ts +29 -37
- package/src/index.ts +110 -195
- package/src/useDragAndDrop.ts +87 -71
- package/src/utils.tsx +49 -60
- package/src/virtualizer/Layout.ts +14 -22
- package/dist/index.ssr.js +0 -16996
- package/dist/index.ssr.js.map +0 -1
package/src/useDragAndDrop.ts
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
* state and aria primitives.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type { Accessor, JSX } from
|
|
9
|
-
import { DragPreview } from
|
|
10
|
-
import { ListDropTargetDelegate } from
|
|
8
|
+
import type { Accessor, JSX } from "solid-js";
|
|
9
|
+
import { DragPreview } from "./DragPreview";
|
|
10
|
+
import { ListDropTargetDelegate } from "./ListDropTargetDelegate";
|
|
11
11
|
import {
|
|
12
12
|
createDraggableCollection,
|
|
13
13
|
createDraggableItem,
|
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
type DroppableItemOptions,
|
|
25
25
|
type DroppableItemAria,
|
|
26
26
|
type DropTargetDelegate as AriaDropTargetDelegate,
|
|
27
|
-
} from
|
|
27
|
+
} from "@proyecto-viviana/solidaria";
|
|
28
28
|
import {
|
|
29
29
|
createDraggableCollectionState,
|
|
30
30
|
createDroppableCollectionState,
|
|
@@ -37,42 +37,51 @@ import {
|
|
|
37
37
|
type DroppableCollectionProps,
|
|
38
38
|
type DroppableCollectionState,
|
|
39
39
|
type DroppableCollectionStateOptions,
|
|
40
|
-
} from
|
|
40
|
+
} from "@proyecto-viviana/solid-stately";
|
|
41
41
|
|
|
42
|
-
interface DraggableCollectionStateOpts<T = object>
|
|
43
|
-
|
|
42
|
+
interface DraggableCollectionStateOpts<T = object> extends Omit<
|
|
43
|
+
DraggableCollectionStateOptions<T>,
|
|
44
|
+
"getItems"
|
|
45
|
+
> {
|
|
44
46
|
items?: T[];
|
|
45
47
|
}
|
|
46
48
|
|
|
47
49
|
interface DragHooks<T = object> {
|
|
48
|
-
useDraggableCollectionState?: (
|
|
50
|
+
useDraggableCollectionState?: (
|
|
51
|
+
props: DraggableCollectionStateOpts<T>,
|
|
52
|
+
) => DraggableCollectionState;
|
|
49
53
|
useDraggableCollection?: (
|
|
50
|
-
props: Omit<DraggableCollectionOptions,
|
|
54
|
+
props: Omit<DraggableCollectionOptions, "ref">,
|
|
51
55
|
state: DraggableCollectionState,
|
|
52
|
-
ref: Accessor<HTMLElement | null
|
|
56
|
+
ref: Accessor<HTMLElement | null>,
|
|
53
57
|
) => DraggableCollectionAria;
|
|
54
|
-
useDraggableItem?: (
|
|
58
|
+
useDraggableItem?: (
|
|
59
|
+
props: DraggableItemOptions,
|
|
60
|
+
state: DraggableCollectionState,
|
|
61
|
+
) => DraggableItemAria;
|
|
55
62
|
DragPreview?: typeof DragPreview;
|
|
56
|
-
renderDragPreview?: DragAndDropOptions<T>[
|
|
63
|
+
renderDragPreview?: DragAndDropOptions<T>["renderDragPreview"];
|
|
57
64
|
isVirtualDragging?: () => boolean;
|
|
58
65
|
}
|
|
59
66
|
|
|
60
67
|
interface DropHooks {
|
|
61
|
-
useDroppableCollectionState?: (
|
|
68
|
+
useDroppableCollectionState?: (
|
|
69
|
+
props: DroppableCollectionStateOptions,
|
|
70
|
+
) => DroppableCollectionState;
|
|
62
71
|
useDroppableCollection?: (
|
|
63
|
-
props: Omit<DroppableCollectionOptions,
|
|
72
|
+
props: Omit<DroppableCollectionOptions, "ref">,
|
|
64
73
|
state: DroppableCollectionState,
|
|
65
|
-
ref: Accessor<HTMLElement | null
|
|
74
|
+
ref: Accessor<HTMLElement | null>,
|
|
66
75
|
) => DroppableCollectionAria;
|
|
67
76
|
useDroppableItem?: (
|
|
68
|
-
options: Omit<DroppableItemOptions,
|
|
77
|
+
options: Omit<DroppableItemOptions, "ref">,
|
|
69
78
|
state: DroppableCollectionState,
|
|
70
|
-
ref: Accessor<HTMLElement | null
|
|
79
|
+
ref: Accessor<HTMLElement | null>,
|
|
71
80
|
) => DroppableItemAria;
|
|
72
81
|
useDropIndicator?: (
|
|
73
82
|
props: { target: DropTarget },
|
|
74
83
|
state: DroppableCollectionState,
|
|
75
|
-
ref: Accessor<HTMLElement | null
|
|
84
|
+
ref: Accessor<HTMLElement | null>,
|
|
76
85
|
) => {
|
|
77
86
|
dropIndicatorProps: JSX.HTMLAttributes<HTMLElement>;
|
|
78
87
|
isDropTarget: boolean;
|
|
@@ -91,16 +100,15 @@ export interface DragAndDrop<T = object> {
|
|
|
91
100
|
}
|
|
92
101
|
|
|
93
102
|
export interface DragAndDropOptions<T = object>
|
|
94
|
-
extends Partial<Omit<DraggableCollectionProps<T>,
|
|
95
|
-
Partial<DroppableCollectionProps> {
|
|
103
|
+
extends Partial<Omit<DraggableCollectionProps<T>, "preview">>, Partial<DroppableCollectionProps> {
|
|
96
104
|
/**
|
|
97
105
|
* Optional keyboard delegate forwarded to the collection droppable hook.
|
|
98
106
|
*/
|
|
99
|
-
keyboardDelegate?: DroppableCollectionOptions[
|
|
107
|
+
keyboardDelegate?: DroppableCollectionOptions["keyboardDelegate"];
|
|
100
108
|
/**
|
|
101
109
|
* Optional keydown handler composed with collection droppable keyboard behavior.
|
|
102
110
|
*/
|
|
103
|
-
onKeyDown?: DroppableCollectionOptions[
|
|
111
|
+
onKeyDown?: DroppableCollectionOptions["onKeyDown"];
|
|
104
112
|
/**
|
|
105
113
|
* A function that returns the items being dragged.
|
|
106
114
|
* If omitted, draggable hooks are not added.
|
|
@@ -109,7 +117,9 @@ export interface DragAndDropOptions<T = object>
|
|
|
109
117
|
/**
|
|
110
118
|
* Optional custom drag preview renderer.
|
|
111
119
|
*/
|
|
112
|
-
renderDragPreview?: (
|
|
120
|
+
renderDragPreview?: (
|
|
121
|
+
items: DragItem[],
|
|
122
|
+
) => JSX.Element | { element: JSX.Element; x: number; y: number };
|
|
113
123
|
/**
|
|
114
124
|
* Optional drop indicator renderer for collection components.
|
|
115
125
|
*/
|
|
@@ -149,39 +159,44 @@ export function useDragAndDrop<T = object>(options: DragAndDropOptions<T> = {}):
|
|
|
149
159
|
dropTargetDelegate,
|
|
150
160
|
} = options;
|
|
151
161
|
|
|
152
|
-
const isDraggable = typeof getItems ===
|
|
153
|
-
const isDroppable = Boolean(
|
|
162
|
+
const isDraggable = typeof getItems === "function";
|
|
163
|
+
const isDroppable = Boolean(
|
|
164
|
+
onDrop || onInsert || onItemDrop || onReorder || onMove || onRootDrop,
|
|
165
|
+
);
|
|
154
166
|
|
|
155
167
|
const hooks: DragAndDropHooks<T> = {};
|
|
156
|
-
const hasDom = typeof HTMLElement !==
|
|
168
|
+
const hasDom = typeof HTMLElement !== "undefined";
|
|
157
169
|
const isElementNode = (value: unknown): value is HTMLElement => {
|
|
158
170
|
if (!value) return false;
|
|
159
171
|
if (hasDom && value instanceof HTMLElement) return true;
|
|
160
|
-
return typeof value ===
|
|
172
|
+
return typeof value === "object" && (value as { nodeType?: number }).nodeType === 1;
|
|
161
173
|
};
|
|
162
|
-
const resolvedPreview =
|
|
163
|
-
|
|
174
|
+
const resolvedPreview =
|
|
175
|
+
options.preview ??
|
|
176
|
+
(renderDragPreview
|
|
164
177
|
? {
|
|
165
|
-
current: (
|
|
178
|
+
current: (
|
|
179
|
+
items: DragItem[],
|
|
180
|
+
callback: (node: HTMLElement | null, x?: number, y?: number) => void,
|
|
181
|
+
) => {
|
|
166
182
|
const rendered = renderDragPreview(items);
|
|
167
183
|
if (!rendered) {
|
|
168
184
|
callback(null);
|
|
169
185
|
return;
|
|
170
186
|
}
|
|
171
|
-
if (
|
|
172
|
-
typeof rendered === 'object' &&
|
|
173
|
-
rendered !== null &&
|
|
174
|
-
'element' in rendered
|
|
175
|
-
) {
|
|
187
|
+
if (typeof rendered === "object" && rendered !== null && "element" in rendered) {
|
|
176
188
|
const previewValue = rendered as { element: unknown; x?: number; y?: number };
|
|
177
|
-
callback(
|
|
189
|
+
callback(
|
|
190
|
+
isElementNode(previewValue.element) ? previewValue.element : null,
|
|
191
|
+
previewValue.x,
|
|
192
|
+
previewValue.y,
|
|
193
|
+
);
|
|
178
194
|
return;
|
|
179
195
|
}
|
|
180
196
|
callback(isElementNode(rendered) ? rendered : null);
|
|
181
197
|
},
|
|
182
198
|
}
|
|
183
|
-
: undefined
|
|
184
|
-
);
|
|
199
|
+
: undefined);
|
|
185
200
|
|
|
186
201
|
if (isDraggable && getItems) {
|
|
187
202
|
hooks.useDraggableCollectionState = (props: DraggableCollectionStateOpts<T>) => {
|
|
@@ -189,7 +204,8 @@ export function useDragAndDrop<T = object>(options: DragAndDropOptions<T> = {}):
|
|
|
189
204
|
onDragStart: options.onDragStart ?? props.onDragStart,
|
|
190
205
|
onDragMove: options.onDragMove ?? props.onDragMove,
|
|
191
206
|
onDragEnd: options.onDragEnd ?? props.onDragEnd,
|
|
192
|
-
getAllowedDropOperations:
|
|
207
|
+
getAllowedDropOperations:
|
|
208
|
+
options.getAllowedDropOperations ?? props.getAllowedDropOperations,
|
|
193
209
|
isDisabled: options.isDisabled ?? props.isDisabled,
|
|
194
210
|
preview: resolvedPreview ?? props.preview,
|
|
195
211
|
getItems: (keys) => {
|
|
@@ -199,9 +215,9 @@ export function useDragAndDrop<T = object>(options: DragAndDropOptions<T> = {}):
|
|
|
199
215
|
}));
|
|
200
216
|
};
|
|
201
217
|
hooks.useDraggableCollection = (
|
|
202
|
-
props: Omit<DraggableCollectionOptions,
|
|
218
|
+
props: Omit<DraggableCollectionOptions, "ref">,
|
|
203
219
|
state: DraggableCollectionState,
|
|
204
|
-
ref: Accessor<HTMLElement | null
|
|
220
|
+
ref: Accessor<HTMLElement | null>,
|
|
205
221
|
) => createDraggableCollection({ ...props, ref }, state);
|
|
206
222
|
hooks.useDraggableItem = (props, state) => createDraggableItem(() => props, state);
|
|
207
223
|
hooks.DragPreview = DragPreview;
|
|
@@ -229,17 +245,19 @@ export function useDragAndDrop<T = object>(options: DragAndDropOptions<T> = {}):
|
|
|
229
245
|
}));
|
|
230
246
|
};
|
|
231
247
|
hooks.useDroppableCollection = (
|
|
232
|
-
props: Omit<DroppableCollectionOptions,
|
|
248
|
+
props: Omit<DroppableCollectionOptions, "ref">,
|
|
233
249
|
state: DroppableCollectionState,
|
|
234
|
-
ref: Accessor<HTMLElement | null
|
|
250
|
+
ref: Accessor<HTMLElement | null>,
|
|
235
251
|
) => {
|
|
236
|
-
const acceptedDragTypes =
|
|
237
|
-
const normalizedAcceptedDragTypes =
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
252
|
+
const acceptedDragTypes = options.acceptedDragTypes ?? props.acceptedDragTypes;
|
|
253
|
+
const normalizedAcceptedDragTypes =
|
|
254
|
+
acceptedDragTypes === "all"
|
|
255
|
+
? "all"
|
|
256
|
+
: acceptedDragTypes?.filter(
|
|
257
|
+
(type): type is string | symbol =>
|
|
258
|
+
typeof type === "string" || typeof type === "symbol",
|
|
259
|
+
);
|
|
260
|
+
return createDroppableCollection(
|
|
243
261
|
() => ({
|
|
244
262
|
ref,
|
|
245
263
|
dropTargetDelegate: options.dropTargetDelegate ?? props.dropTargetDelegate,
|
|
@@ -249,7 +267,7 @@ export function useDragAndDrop<T = object>(options: DragAndDropOptions<T> = {}):
|
|
|
249
267
|
isDisabled: options.isDisabled ?? props.isDisabled,
|
|
250
268
|
onDropActivate: (e) => {
|
|
251
269
|
(options.onDropActivate ?? props.onDropActivate)?.({
|
|
252
|
-
type:
|
|
270
|
+
type: "dropactivate",
|
|
253
271
|
target: e.target,
|
|
254
272
|
x: e.x,
|
|
255
273
|
y: e.y,
|
|
@@ -257,7 +275,7 @@ export function useDragAndDrop<T = object>(options: DragAndDropOptions<T> = {}):
|
|
|
257
275
|
},
|
|
258
276
|
onDrop: (e) => {
|
|
259
277
|
(options.onDrop ?? props.onDrop)?.({
|
|
260
|
-
type:
|
|
278
|
+
type: "drop",
|
|
261
279
|
target: e.target,
|
|
262
280
|
x: e.x,
|
|
263
281
|
y: e.y,
|
|
@@ -267,7 +285,7 @@ export function useDragAndDrop<T = object>(options: DragAndDropOptions<T> = {}):
|
|
|
267
285
|
},
|
|
268
286
|
onRootDrop: options.onRootDrop ?? props.onRootDrop,
|
|
269
287
|
onItemDrop: (e) => {
|
|
270
|
-
if (e.target.type ===
|
|
288
|
+
if (e.target.type === "item") {
|
|
271
289
|
(options.onItemDrop ?? props.onItemDrop)?.({
|
|
272
290
|
items: e.items,
|
|
273
291
|
target: e.target,
|
|
@@ -277,7 +295,7 @@ export function useDragAndDrop<T = object>(options: DragAndDropOptions<T> = {}):
|
|
|
277
295
|
}
|
|
278
296
|
},
|
|
279
297
|
onInsert: (e) => {
|
|
280
|
-
if (e.target.type ===
|
|
298
|
+
if (e.target.type === "item") {
|
|
281
299
|
(options.onInsert ?? props.onInsert)?.({
|
|
282
300
|
items: e.items,
|
|
283
301
|
target: e.target,
|
|
@@ -286,7 +304,7 @@ export function useDragAndDrop<T = object>(options: DragAndDropOptions<T> = {}):
|
|
|
286
304
|
}
|
|
287
305
|
},
|
|
288
306
|
onReorder: (e) => {
|
|
289
|
-
if (e.target.type ===
|
|
307
|
+
if (e.target.type === "item") {
|
|
290
308
|
(options.onReorder ?? props.onReorder)?.({
|
|
291
309
|
keys: e.keys,
|
|
292
310
|
target: e.target,
|
|
@@ -295,7 +313,7 @@ export function useDragAndDrop<T = object>(options: DragAndDropOptions<T> = {}):
|
|
|
295
313
|
}
|
|
296
314
|
},
|
|
297
315
|
onMove: (e) => {
|
|
298
|
-
if (e.target.type ===
|
|
316
|
+
if (e.target.type === "item") {
|
|
299
317
|
(options.onMove ?? props.onMove)?.({
|
|
300
318
|
keys: e.keys,
|
|
301
319
|
target: e.target,
|
|
@@ -304,37 +322,35 @@ export function useDragAndDrop<T = object>(options: DragAndDropOptions<T> = {}):
|
|
|
304
322
|
}
|
|
305
323
|
},
|
|
306
324
|
}),
|
|
307
|
-
state
|
|
308
|
-
)
|
|
325
|
+
state,
|
|
326
|
+
);
|
|
309
327
|
};
|
|
310
328
|
hooks.useDroppableItem = (
|
|
311
|
-
props: Omit<DroppableItemOptions,
|
|
329
|
+
props: Omit<DroppableItemOptions, "ref">,
|
|
312
330
|
state: DroppableCollectionState,
|
|
313
|
-
ref: Accessor<HTMLElement | null
|
|
331
|
+
ref: Accessor<HTMLElement | null>,
|
|
314
332
|
) => createDroppableItem(() => ({ ...props, ref }), state);
|
|
315
333
|
hooks.useDropIndicator = (
|
|
316
334
|
props: { target: DropTarget },
|
|
317
335
|
state: DroppableCollectionState,
|
|
318
|
-
_ref: Accessor<HTMLElement | null
|
|
336
|
+
_ref: Accessor<HTMLElement | null>,
|
|
319
337
|
) => {
|
|
320
338
|
const target = props.target;
|
|
321
339
|
const activeTarget = state.target;
|
|
322
340
|
const isDropTarget =
|
|
323
341
|
activeTarget?.type === target.type &&
|
|
324
|
-
(target.type ===
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
target.type === 'item' &&
|
|
342
|
+
(target.type === "root" ||
|
|
343
|
+
(activeTarget.type === "item" &&
|
|
344
|
+
target.type === "item" &&
|
|
328
345
|
activeTarget.key === target.key &&
|
|
329
|
-
activeTarget.dropPosition === target.dropPosition
|
|
330
|
-
));
|
|
346
|
+
activeTarget.dropPosition === target.dropPosition));
|
|
331
347
|
return {
|
|
332
348
|
dropIndicatorProps: {
|
|
333
|
-
role:
|
|
334
|
-
|
|
335
|
-
|
|
349
|
+
role: "option",
|
|
350
|
+
"aria-disabled": true,
|
|
351
|
+
"aria-hidden": isDropTarget ? undefined : "true",
|
|
336
352
|
tabIndex: -1,
|
|
337
|
-
|
|
353
|
+
"data-drop-target": isDropTarget ? "" : undefined,
|
|
338
354
|
},
|
|
339
355
|
isDropTarget,
|
|
340
356
|
isHidden: !isDropTarget,
|
package/src/utils.tsx
CHANGED
|
@@ -14,12 +14,8 @@ import {
|
|
|
14
14
|
createSignal,
|
|
15
15
|
onMount,
|
|
16
16
|
Show,
|
|
17
|
-
} from
|
|
18
|
-
import { isServer } from
|
|
19
|
-
|
|
20
|
-
// ============================================
|
|
21
|
-
// TYPES
|
|
22
|
-
// ============================================
|
|
17
|
+
} from "solid-js";
|
|
18
|
+
import { isServer } from "solid-js/web";
|
|
23
19
|
|
|
24
20
|
/**
|
|
25
21
|
* Render props pattern - children can be a function that receives state
|
|
@@ -56,11 +52,7 @@ export interface SlotProps {
|
|
|
56
52
|
slot?: string;
|
|
57
53
|
}
|
|
58
54
|
|
|
59
|
-
export const DEFAULT_SLOT =
|
|
60
|
-
|
|
61
|
-
// ============================================
|
|
62
|
-
// RENDER PROPS
|
|
63
|
-
// ============================================
|
|
55
|
+
export const DEFAULT_SLOT = "default";
|
|
64
56
|
|
|
65
57
|
/**
|
|
66
58
|
* Return type for useRenderProps
|
|
@@ -98,25 +90,23 @@ export interface RenderPropsResult<T> {
|
|
|
98
90
|
*/
|
|
99
91
|
export function useRenderProps<T extends object>(
|
|
100
92
|
props: RenderPropsBase<T> & { defaultClassName?: string },
|
|
101
|
-
values: Accessor<T
|
|
93
|
+
values: Accessor<T>,
|
|
102
94
|
): RenderPropsResult<T> {
|
|
103
95
|
// Don't destructure children — access lazily to avoid eager evaluation
|
|
104
96
|
// that would trigger child component creation before context providers mount.
|
|
105
|
-
const { class: className, style, defaultClassName =
|
|
97
|
+
const { class: className, style, defaultClassName = "" } = props;
|
|
106
98
|
|
|
107
99
|
// Compute class and style eagerly (they don't depend on context)
|
|
108
100
|
const computedClass = createMemo(() => {
|
|
109
101
|
const currentValues = values();
|
|
110
|
-
return typeof className ===
|
|
102
|
+
return typeof className === "function"
|
|
111
103
|
? className(currentValues)
|
|
112
|
-
: className ?? defaultClassName;
|
|
104
|
+
: (className ?? defaultClassName);
|
|
113
105
|
});
|
|
114
106
|
|
|
115
107
|
const computedStyle = createMemo(() => {
|
|
116
108
|
const currentValues = values();
|
|
117
|
-
return typeof style ===
|
|
118
|
-
? style(currentValues)
|
|
119
|
-
: style;
|
|
109
|
+
return typeof style === "function" ? style(currentValues) : style;
|
|
120
110
|
});
|
|
121
111
|
|
|
122
112
|
// Return object with explicit function for rendering children
|
|
@@ -127,18 +117,18 @@ export function useRenderProps<T extends object>(
|
|
|
127
117
|
renderChildren: () => {
|
|
128
118
|
const currentValues = values();
|
|
129
119
|
const children = props.children;
|
|
130
|
-
return typeof children ===
|
|
131
|
-
|
|
132
|
-
|
|
120
|
+
return typeof children === "function" ? children(currentValues) : children;
|
|
121
|
+
},
|
|
122
|
+
get children() {
|
|
123
|
+
return props.children;
|
|
133
124
|
},
|
|
134
|
-
get children() { return props.children; },
|
|
135
125
|
values,
|
|
136
126
|
};
|
|
137
127
|
}
|
|
138
128
|
|
|
139
129
|
export function composeRenderProps<T extends object>(
|
|
140
130
|
base: RenderPropsBase<T> | undefined,
|
|
141
|
-
override: RenderPropsBase<T> | undefined
|
|
131
|
+
override: RenderPropsBase<T> | undefined,
|
|
142
132
|
): RenderPropsBase<T> {
|
|
143
133
|
if (!base) return override ?? {};
|
|
144
134
|
if (!override) return base;
|
|
@@ -149,10 +139,6 @@ export function composeRenderProps<T extends object>(
|
|
|
149
139
|
};
|
|
150
140
|
}
|
|
151
141
|
|
|
152
|
-
// ============================================
|
|
153
|
-
// CONTEXT UTILITIES
|
|
154
|
-
// ============================================
|
|
155
|
-
|
|
156
142
|
/**
|
|
157
143
|
* Context value that can be null or the actual value
|
|
158
144
|
*/
|
|
@@ -168,14 +154,16 @@ export function createSlottedContext<T>() {
|
|
|
168
154
|
/**
|
|
169
155
|
* Use context with null check
|
|
170
156
|
*/
|
|
171
|
-
export function useSlottedContext<T>(
|
|
157
|
+
export function useSlottedContext<T>(
|
|
158
|
+
context: ReturnType<typeof createContext<T | null>>,
|
|
159
|
+
): T | null {
|
|
172
160
|
return useContext(context);
|
|
173
161
|
}
|
|
174
162
|
|
|
175
163
|
export function useContextProps<TProps extends object, TRef>(
|
|
176
164
|
props: TProps,
|
|
177
165
|
ref: TRef,
|
|
178
|
-
context?: ContextValue<Partial<TProps
|
|
166
|
+
context?: ContextValue<Partial<TProps>>,
|
|
179
167
|
): [TProps, TRef] {
|
|
180
168
|
if (!context) return [props, ref];
|
|
181
169
|
return [{ ...(context as TProps), ...props }, ref];
|
|
@@ -187,28 +175,24 @@ export const Provider: ParentComponent<{
|
|
|
187
175
|
return props.children;
|
|
188
176
|
};
|
|
189
177
|
|
|
190
|
-
// ============================================
|
|
191
|
-
// DATA ATTRIBUTES
|
|
192
|
-
// ============================================
|
|
193
|
-
|
|
194
178
|
/**
|
|
195
179
|
* Converts boolean state values to data attributes
|
|
196
180
|
*/
|
|
197
|
-
export function dataAttr(value: boolean | undefined):
|
|
198
|
-
return value ?
|
|
181
|
+
export function dataAttr(value: boolean | undefined): "" | undefined {
|
|
182
|
+
return value ? "" : undefined;
|
|
199
183
|
}
|
|
200
184
|
|
|
201
185
|
/**
|
|
202
186
|
* Creates data attributes from render props
|
|
203
187
|
*/
|
|
204
188
|
export function createDataAttributes<T extends Record<string, boolean | string | undefined>>(
|
|
205
|
-
values: T
|
|
189
|
+
values: T,
|
|
206
190
|
): Record<string, string | undefined> {
|
|
207
191
|
const result: Record<string, string | undefined> = {};
|
|
208
192
|
|
|
209
193
|
for (const [key, value] of Object.entries(values)) {
|
|
210
|
-
if (typeof value ===
|
|
211
|
-
result[`data-${camelToKebab(key)}`] = value ?
|
|
194
|
+
if (typeof value === "boolean") {
|
|
195
|
+
result[`data-${camelToKebab(key)}`] = value ? "" : undefined;
|
|
212
196
|
} else if (value !== undefined) {
|
|
213
197
|
result[`data-${camelToKebab(key)}`] = value;
|
|
214
198
|
}
|
|
@@ -218,13 +202,9 @@ export function createDataAttributes<T extends Record<string, boolean | string |
|
|
|
218
202
|
}
|
|
219
203
|
|
|
220
204
|
function camelToKebab(str: string): string {
|
|
221
|
-
return str.replace(/([a-z])([A-Z])/g,
|
|
205
|
+
return str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
|
222
206
|
}
|
|
223
207
|
|
|
224
|
-
// ============================================
|
|
225
|
-
// PROPS UTILITIES
|
|
226
|
-
// ============================================
|
|
227
|
-
|
|
228
208
|
/**
|
|
229
209
|
* Remove data attributes from props (for internal use)
|
|
230
210
|
*/
|
|
@@ -232,7 +212,7 @@ export function removeDataAttributes<T extends Record<string, unknown>>(props: T
|
|
|
232
212
|
const result: Record<string, unknown> = {};
|
|
233
213
|
|
|
234
214
|
for (const [key, value] of Object.entries(props)) {
|
|
235
|
-
if (!key.startsWith(
|
|
215
|
+
if (!key.startsWith("data-")) {
|
|
236
216
|
result[key] = value;
|
|
237
217
|
}
|
|
238
218
|
}
|
|
@@ -249,14 +229,25 @@ export function removeDataAttributes<T extends Record<string, unknown>>(props: T
|
|
|
249
229
|
*/
|
|
250
230
|
export function filterDOMProps<R extends object = Record<string, unknown>>(
|
|
251
231
|
props: object,
|
|
252
|
-
options: { global?: boolean } = {}
|
|
232
|
+
options: { global?: boolean } = {},
|
|
253
233
|
): R {
|
|
254
234
|
const { global = false } = options;
|
|
255
235
|
const result: Record<string, unknown> = {};
|
|
256
236
|
|
|
257
237
|
const globalAttrs = new Set([
|
|
258
|
-
|
|
259
|
-
|
|
238
|
+
"id",
|
|
239
|
+
"class",
|
|
240
|
+
"style",
|
|
241
|
+
"tabIndex",
|
|
242
|
+
"role",
|
|
243
|
+
"title",
|
|
244
|
+
"lang",
|
|
245
|
+
"dir",
|
|
246
|
+
"hidden",
|
|
247
|
+
"draggable",
|
|
248
|
+
"accessKey",
|
|
249
|
+
"contentEditable",
|
|
250
|
+
"spellcheck",
|
|
260
251
|
]);
|
|
261
252
|
|
|
262
253
|
const ariaAttrs = /^aria-/;
|
|
@@ -266,12 +257,10 @@ export function filterDOMProps<R extends object = Record<string, unknown>>(
|
|
|
266
257
|
for (const key in props) {
|
|
267
258
|
if (
|
|
268
259
|
Object.prototype.hasOwnProperty.call(props, key) &&
|
|
269
|
-
(
|
|
270
|
-
(global && globalAttrs.has(key)) ||
|
|
260
|
+
((global && globalAttrs.has(key)) ||
|
|
271
261
|
ariaAttrs.test(key) ||
|
|
272
262
|
dataAttrs.test(key) ||
|
|
273
|
-
eventHandlers.test(key)
|
|
274
|
-
)
|
|
263
|
+
eventHandlers.test(key))
|
|
275
264
|
) {
|
|
276
265
|
result[key] = (props as Record<string, unknown>)[key];
|
|
277
266
|
}
|
|
@@ -280,10 +269,6 @@ export function filterDOMProps<R extends object = Record<string, unknown>>(
|
|
|
280
269
|
return result as R;
|
|
281
270
|
}
|
|
282
271
|
|
|
283
|
-
// ============================================
|
|
284
|
-
// CLIENT-ONLY UTILITIES
|
|
285
|
-
// ============================================
|
|
286
|
-
|
|
287
272
|
export interface ClientOnlyProps {
|
|
288
273
|
/** The children to render only on the client */
|
|
289
274
|
children: JSX.Element;
|
|
@@ -349,13 +334,17 @@ export function useIsHydrated(): Accessor<boolean> {
|
|
|
349
334
|
return () => false;
|
|
350
335
|
}
|
|
351
336
|
|
|
352
|
-
// On client, start false
|
|
353
|
-
//
|
|
337
|
+
// On client, start false (so the first render matches the server, which
|
|
338
|
+
// emitted nothing for hydrated-gated content) and flip to true after mount.
|
|
354
339
|
const [isHydrated, setIsHydrated] = createSignal(false);
|
|
355
340
|
|
|
356
|
-
//
|
|
357
|
-
//
|
|
358
|
-
|
|
341
|
+
// onMount runs in the effect phase — *after* the synchronous hydration pass
|
|
342
|
+
// has finished walking the server DOM — so flipping here renders the gated
|
|
343
|
+
// content as a fresh client-side update (Portal: no getNextElement walk, no
|
|
344
|
+
// mismatch), yet fires synchronously under `render()` (unit tests / pure CSR)
|
|
345
|
+
// where requestAnimationFrame would never run. This mirrors the component
|
|
346
|
+
// gate above and is strictly earlier than a rAF tick.
|
|
347
|
+
onMount(() => {
|
|
359
348
|
setIsHydrated(true);
|
|
360
349
|
});
|
|
361
350
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Key } from
|
|
1
|
+
import type { Key } from "@proyecto-viviana/solid-stately";
|
|
2
2
|
|
|
3
3
|
export interface InvalidationContext<O = unknown> {
|
|
4
4
|
contentChanged?: boolean;
|
|
@@ -10,7 +10,10 @@ export interface InvalidationContext<O = unknown> {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export class Point {
|
|
13
|
-
constructor(
|
|
13
|
+
constructor(
|
|
14
|
+
public x = 0,
|
|
15
|
+
public y = 0,
|
|
16
|
+
) {}
|
|
14
17
|
copy(): Point {
|
|
15
18
|
return new Point(this.x, this.y);
|
|
16
19
|
}
|
|
@@ -49,7 +52,7 @@ export class Rect {
|
|
|
49
52
|
public x = 0,
|
|
50
53
|
public y = 0,
|
|
51
54
|
public width = 0,
|
|
52
|
-
public height = 0
|
|
55
|
+
public height = 0,
|
|
53
56
|
) {}
|
|
54
57
|
|
|
55
58
|
get maxX(): number {
|
|
@@ -81,30 +84,15 @@ export class Rect {
|
|
|
81
84
|
}
|
|
82
85
|
|
|
83
86
|
intersects(rect: Rect): boolean {
|
|
84
|
-
return
|
|
85
|
-
this.x <= rect.maxX &&
|
|
86
|
-
rect.x <= this.maxX &&
|
|
87
|
-
this.y <= rect.maxY &&
|
|
88
|
-
rect.y <= this.maxY
|
|
89
|
-
);
|
|
87
|
+
return this.x <= rect.maxX && rect.x <= this.maxX && this.y <= rect.maxY && rect.y <= this.maxY;
|
|
90
88
|
}
|
|
91
89
|
|
|
92
90
|
containsRect(rect: Rect): boolean {
|
|
93
|
-
return
|
|
94
|
-
this.x <= rect.x &&
|
|
95
|
-
this.y <= rect.y &&
|
|
96
|
-
this.maxX >= rect.maxX &&
|
|
97
|
-
this.maxY >= rect.maxY
|
|
98
|
-
);
|
|
91
|
+
return this.x <= rect.x && this.y <= rect.y && this.maxX >= rect.maxX && this.maxY >= rect.maxY;
|
|
99
92
|
}
|
|
100
93
|
|
|
101
94
|
containsPoint(point: Point): boolean {
|
|
102
|
-
return
|
|
103
|
-
this.x <= point.x &&
|
|
104
|
-
this.y <= point.y &&
|
|
105
|
-
this.maxX >= point.x &&
|
|
106
|
-
this.maxY >= point.y
|
|
107
|
-
);
|
|
95
|
+
return this.x <= point.x && this.y <= point.y && this.maxX >= point.x && this.maxY >= point.y;
|
|
108
96
|
}
|
|
109
97
|
|
|
110
98
|
union(other: Rect): Rect {
|
|
@@ -150,7 +138,11 @@ export class LayoutInfo {
|
|
|
150
138
|
zIndex = 0;
|
|
151
139
|
allowOverflow = false;
|
|
152
140
|
|
|
153
|
-
constructor(
|
|
141
|
+
constructor(
|
|
142
|
+
public type: string,
|
|
143
|
+
public key: Key,
|
|
144
|
+
public rect: Rect,
|
|
145
|
+
) {}
|
|
154
146
|
|
|
155
147
|
copy(): LayoutInfo {
|
|
156
148
|
const copy = new LayoutInfo(this.type, this.key, this.rect.copy());
|