@proyecto-viviana/solid-stately 0.1.5 → 0.2.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/{src → dist}/autocomplete/createAutocompleteState.d.ts +0 -1
- package/{src → dist}/autocomplete/index.d.ts +0 -1
- package/{src → dist}/calendar/createCalendarState.d.ts +0 -1
- package/{src → dist}/calendar/createDateFieldState.d.ts +0 -1
- package/{src → dist}/calendar/createRangeCalendarState.d.ts +0 -1
- package/{src → dist}/calendar/createTimeFieldState.d.ts +0 -1
- package/{src → dist}/calendar/index.d.ts +0 -1
- package/{src → dist}/checkbox/createCheckboxGroupState.d.ts +0 -1
- package/{src → dist}/checkbox/index.d.ts +0 -1
- package/{src → dist}/collections/ListCollection.d.ts +0 -1
- package/{src → dist}/collections/createListState.d.ts +0 -1
- package/{src → dist}/collections/createMenuState.d.ts +0 -1
- package/{src → dist}/collections/createSelectionState.d.ts +0 -1
- package/{src → dist}/collections/index.d.ts +0 -1
- package/{src → dist}/collections/types.d.ts +0 -1
- package/{src → dist}/color/Color.d.ts +0 -1
- package/{src → dist}/color/createColorAreaState.d.ts +0 -1
- package/{src → dist}/color/createColorFieldState.d.ts +0 -1
- package/{src → dist}/color/createColorSliderState.d.ts +0 -1
- package/{src → dist}/color/createColorWheelState.d.ts +0 -1
- package/{src → dist}/color/index.d.ts +0 -1
- package/{src → dist}/color/types.d.ts +0 -1
- package/{src → dist}/combobox/createComboBoxState.d.ts +0 -1
- package/{src → dist}/combobox/index.d.ts +0 -1
- package/{src → dist}/disclosure/createDisclosureState.d.ts +0 -1
- package/{src → dist}/disclosure/index.d.ts +0 -1
- package/{src → dist}/dnd/createDragState.d.ts +0 -1
- package/{src → dist}/dnd/createDraggableCollectionState.d.ts +0 -1
- package/{src → dist}/dnd/createDropState.d.ts +0 -1
- package/{src → dist}/dnd/createDroppableCollectionState.d.ts +0 -1
- package/{src → dist}/dnd/index.d.ts +0 -1
- package/{src → dist}/dnd/types.d.ts +0 -1
- package/{src → dist}/form/createFormValidationState.d.ts +0 -1
- package/{src → dist}/form/index.d.ts +0 -1
- package/{src → dist}/grid/createGridState.d.ts +0 -1
- package/{src → dist}/grid/index.d.ts +0 -1
- package/{src → dist}/grid/types.d.ts +0 -1
- package/dist/index.d.ts +25 -3363
- package/dist/index.js +2 -2
- package/dist/index.js.map +7 -1
- package/{src → dist}/numberfield/createNumberFieldState.d.ts +0 -1
- package/{src → dist}/numberfield/index.d.ts +0 -1
- package/{src → dist}/overlays/createOverlayTriggerState.d.ts +0 -1
- package/{src → dist}/overlays/index.d.ts +0 -1
- package/{src → dist}/radio/createRadioGroupState.d.ts +0 -1
- package/{src → dist}/radio/index.d.ts +0 -1
- package/{src → dist}/searchfield/createSearchFieldState.d.ts +0 -1
- package/{src → dist}/searchfield/index.d.ts +0 -1
- package/{src → dist}/select/createSelectState.d.ts +0 -1
- package/{src → dist}/select/index.d.ts +0 -1
- package/{src → dist}/slider/createSliderState.d.ts +0 -1
- package/{src → dist}/slider/index.d.ts +0 -1
- package/{src → dist}/ssr/index.d.ts +0 -1
- package/{src → dist}/table/TableCollection.d.ts +0 -1
- package/{src → dist}/table/createTableState.d.ts +0 -1
- package/{src → dist}/table/index.d.ts +0 -1
- package/{src → dist}/table/types.d.ts +0 -1
- package/{src → dist}/tabs/createTabListState.d.ts +0 -1
- package/{src → dist}/tabs/index.d.ts +0 -1
- package/{src → dist}/textfield/createTextFieldState.d.ts +0 -1
- package/{src → dist}/textfield/index.d.ts +0 -1
- package/{src → dist}/toast/createToastState.d.ts +0 -1
- package/{src → dist}/toast/index.d.ts +0 -1
- package/{src → dist}/toggle/createToggleState.d.ts +0 -1
- package/{src → dist}/toggle/index.d.ts +0 -1
- package/{src → dist}/tooltip/createTooltipTriggerState.d.ts +0 -1
- package/{src → dist}/tooltip/index.d.ts +0 -1
- package/{src → dist}/tree/TreeCollection.d.ts +0 -1
- package/{src → dist}/tree/createTreeState.d.ts +0 -1
- package/{src → dist}/tree/index.d.ts +0 -1
- package/{src → dist}/tree/types.d.ts +0 -1
- package/{src → dist}/utils/reactivity.d.ts +0 -1
- package/package.json +5 -7
- package/src/autocomplete/createAutocompleteState.d.ts.map +0 -1
- package/src/autocomplete/createAutocompleteState.ts +0 -90
- package/src/autocomplete/index.d.ts.map +0 -1
- package/src/autocomplete/index.ts +0 -5
- package/src/calendar/createCalendarState.d.ts.map +0 -1
- package/src/calendar/createCalendarState.ts +0 -461
- package/src/calendar/createDateFieldState.d.ts.map +0 -1
- package/src/calendar/createDateFieldState.ts +0 -562
- package/src/calendar/createRangeCalendarState.d.ts.map +0 -1
- package/src/calendar/createRangeCalendarState.ts +0 -535
- package/src/calendar/createTimeFieldState.d.ts.map +0 -1
- package/src/calendar/createTimeFieldState.ts +0 -483
- package/src/calendar/index.d.ts.map +0 -1
- package/src/calendar/index.ts +0 -81
- package/src/checkbox/createCheckboxGroupState.d.ts.map +0 -1
- package/src/checkbox/createCheckboxGroupState.ts +0 -193
- package/src/checkbox/index.d.ts.map +0 -1
- package/src/checkbox/index.ts +0 -5
- package/src/collections/ListCollection.d.ts.map +0 -1
- package/src/collections/ListCollection.ts +0 -146
- package/src/collections/createListState.d.ts.map +0 -1
- package/src/collections/createListState.ts +0 -264
- package/src/collections/createMenuState.d.ts.map +0 -1
- package/src/collections/createMenuState.ts +0 -106
- package/src/collections/createSelectionState.d.ts.map +0 -1
- package/src/collections/createSelectionState.ts +0 -336
- package/src/collections/index.d.ts.map +0 -1
- package/src/collections/index.ts +0 -46
- package/src/collections/types.d.ts.map +0 -1
- package/src/collections/types.ts +0 -169
- package/src/color/Color.d.ts.map +0 -1
- package/src/color/Color.ts +0 -951
- package/src/color/createColorAreaState.d.ts.map +0 -1
- package/src/color/createColorAreaState.ts +0 -293
- package/src/color/createColorFieldState.d.ts.map +0 -1
- package/src/color/createColorFieldState.ts +0 -292
- package/src/color/createColorSliderState.d.ts.map +0 -1
- package/src/color/createColorSliderState.ts +0 -241
- package/src/color/createColorWheelState.d.ts.map +0 -1
- package/src/color/createColorWheelState.ts +0 -211
- package/src/color/index.d.ts.map +0 -1
- package/src/color/index.ts +0 -47
- package/src/color/types.d.ts.map +0 -1
- package/src/color/types.ts +0 -127
- package/src/combobox/createComboBoxState.d.ts.map +0 -1
- package/src/combobox/createComboBoxState.ts +0 -703
- package/src/combobox/index.d.ts.map +0 -1
- package/src/combobox/index.ts +0 -13
- package/src/disclosure/createDisclosureState.d.ts.map +0 -1
- package/src/disclosure/createDisclosureState.ts +0 -193
- package/src/disclosure/index.d.ts.map +0 -1
- package/src/disclosure/index.ts +0 -9
- package/src/dnd/createDragState.d.ts.map +0 -1
- package/src/dnd/createDragState.ts +0 -153
- package/src/dnd/createDraggableCollectionState.d.ts.map +0 -1
- package/src/dnd/createDraggableCollectionState.ts +0 -165
- package/src/dnd/createDropState.d.ts.map +0 -1
- package/src/dnd/createDropState.ts +0 -212
- package/src/dnd/createDroppableCollectionState.d.ts.map +0 -1
- package/src/dnd/createDroppableCollectionState.ts +0 -357
- package/src/dnd/index.d.ts.map +0 -1
- package/src/dnd/index.ts +0 -76
- package/src/dnd/types.d.ts.map +0 -1
- package/src/dnd/types.ts +0 -317
- package/src/form/createFormValidationState.d.ts.map +0 -1
- package/src/form/createFormValidationState.ts +0 -389
- package/src/form/index.d.ts.map +0 -1
- package/src/form/index.ts +0 -15
- package/src/grid/createGridState.d.ts.map +0 -1
- package/src/grid/createGridState.ts +0 -327
- package/src/grid/index.d.ts.map +0 -1
- package/src/grid/index.ts +0 -13
- package/src/grid/types.d.ts.map +0 -1
- package/src/grid/types.ts +0 -179
- package/src/index.d.ts +0 -26
- package/src/index.d.ts.map +0 -1
- package/src/index.ts +0 -383
- package/src/numberfield/createNumberFieldState.d.ts.map +0 -1
- package/src/numberfield/createNumberFieldState.ts +0 -383
- package/src/numberfield/index.d.ts.map +0 -1
- package/src/numberfield/index.ts +0 -5
- package/src/overlays/createOverlayTriggerState.d.ts.map +0 -1
- package/src/overlays/createOverlayTriggerState.ts +0 -67
- package/src/overlays/index.d.ts.map +0 -1
- package/src/overlays/index.ts +0 -5
- package/src/radio/createRadioGroupState.d.ts.map +0 -1
- package/src/radio/createRadioGroupState.ts +0 -201
- package/src/radio/index.d.ts.map +0 -1
- package/src/radio/index.ts +0 -6
- package/src/searchfield/createSearchFieldState.d.ts.map +0 -1
- package/src/searchfield/createSearchFieldState.ts +0 -62
- package/src/searchfield/index.d.ts.map +0 -1
- package/src/searchfield/index.ts +0 -5
- package/src/select/createSelectState.d.ts.map +0 -1
- package/src/select/createSelectState.ts +0 -181
- package/src/select/index.d.ts.map +0 -1
- package/src/select/index.ts +0 -5
- package/src/slider/createSliderState.d.ts.map +0 -1
- package/src/slider/createSliderState.ts +0 -211
- package/src/slider/index.d.ts.map +0 -1
- package/src/slider/index.ts +0 -6
- package/src/ssr/index.d.ts.map +0 -1
- package/src/ssr/index.ts +0 -41
- package/src/table/TableCollection.d.ts.map +0 -1
- package/src/table/TableCollection.ts +0 -388
- package/src/table/createTableState.d.ts.map +0 -1
- package/src/table/createTableState.ts +0 -127
- package/src/table/index.d.ts.map +0 -1
- package/src/table/index.ts +0 -18
- package/src/table/types.d.ts.map +0 -1
- package/src/table/types.ts +0 -150
- package/src/tabs/createTabListState.d.ts.map +0 -1
- package/src/tabs/createTabListState.ts +0 -240
- package/src/tabs/index.d.ts.map +0 -1
- package/src/tabs/index.ts +0 -7
- package/src/textfield/createTextFieldState.d.ts.map +0 -1
- package/src/textfield/createTextFieldState.ts +0 -75
- package/src/textfield/index.d.ts.map +0 -1
- package/src/textfield/index.ts +0 -5
- package/src/toast/createToastState.d.ts.map +0 -1
- package/src/toast/createToastState.ts +0 -316
- package/src/toast/index.d.ts.map +0 -1
- package/src/toast/index.ts +0 -11
- package/src/toggle/createToggleState.d.ts.map +0 -1
- package/src/toggle/createToggleState.ts +0 -94
- package/src/toggle/index.d.ts.map +0 -1
- package/src/toggle/index.ts +0 -5
- package/src/tooltip/createTooltipTriggerState.d.ts.map +0 -1
- package/src/tooltip/createTooltipTriggerState.ts +0 -183
- package/src/tooltip/index.d.ts.map +0 -1
- package/src/tooltip/index.ts +0 -6
- package/src/tree/TreeCollection.d.ts.map +0 -1
- package/src/tree/TreeCollection.ts +0 -175
- package/src/tree/createTreeState.d.ts.map +0 -1
- package/src/tree/createTreeState.ts +0 -392
- package/src/tree/index.d.ts.map +0 -1
- package/src/tree/index.ts +0 -13
- package/src/tree/types.d.ts.map +0 -1
- package/src/tree/types.ts +0 -174
- package/src/utils/index.d.ts +0 -2
- package/src/utils/index.d.ts.map +0 -1
- package/src/utils/reactivity.d.ts.map +0 -1
- package/src/utils/reactivity.ts +0 -36
- /package/{src/utils/index.ts → dist/utils/index.d.ts} +0 -0
package/src/dnd/types.ts
DELETED
|
@@ -1,317 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Drag and Drop types for solid-stately.
|
|
3
|
-
*
|
|
4
|
-
* Core types for drag and drop operations, matching React Aria's DnD API.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/** The type of drop operation to perform. */
|
|
8
|
-
export type DropOperation = 'copy' | 'link' | 'move' | 'cancel';
|
|
9
|
-
|
|
10
|
-
/** Drag item data as key-value pairs where keys are MIME types or custom types. */
|
|
11
|
-
export interface DragItem {
|
|
12
|
-
[type: string]: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/** Base event for drag/drop operations with coordinates. */
|
|
16
|
-
export interface DragDropEvent {
|
|
17
|
-
/** The x coordinate of the event, relative to the target element. */
|
|
18
|
-
x: number;
|
|
19
|
-
/** The y coordinate of the event, relative to the target element. */
|
|
20
|
-
y: number;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/** Event fired when a drag operation starts. */
|
|
24
|
-
export interface DragStartEvent extends DragDropEvent {
|
|
25
|
-
/** The event type. */
|
|
26
|
-
type: 'dragstart';
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/** Event fired as a drag moves. */
|
|
30
|
-
export interface DragMoveEvent extends DragDropEvent {
|
|
31
|
-
/** The event type. */
|
|
32
|
-
type: 'dragmove';
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/** Event fired when a drag operation ends. */
|
|
36
|
-
export interface DragEndEvent extends DragDropEvent {
|
|
37
|
-
/** The event type. */
|
|
38
|
-
type: 'dragend';
|
|
39
|
-
/** The drop operation that occurred. */
|
|
40
|
-
dropOperation: DropOperation;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/** Event fired when a drag enters a drop target. */
|
|
44
|
-
export interface DropEnterEvent extends DragDropEvent {
|
|
45
|
-
/** The event type. */
|
|
46
|
-
type: 'dropenter';
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/** Event fired as a drag moves within a drop target. */
|
|
50
|
-
export interface DropMoveEvent extends DragDropEvent {
|
|
51
|
-
/** The event type. */
|
|
52
|
-
type: 'dropmove';
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/** Event fired when a drag is held over a drop target. */
|
|
56
|
-
export interface DropActivateEvent extends DragDropEvent {
|
|
57
|
-
/** The event type. */
|
|
58
|
-
type: 'dropactivate';
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/** Event fired when a drag exits a drop target. */
|
|
62
|
-
export interface DropExitEvent extends DragDropEvent {
|
|
63
|
-
/** The event type. */
|
|
64
|
-
type: 'dropexit';
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/** A text item in a drop operation. */
|
|
68
|
-
export interface TextDropItem {
|
|
69
|
-
/** The item kind. */
|
|
70
|
-
kind: 'text';
|
|
71
|
-
/** The drag types available for this item. */
|
|
72
|
-
types: Set<string>;
|
|
73
|
-
/** Returns the data for the given type as a string. */
|
|
74
|
-
getText(type: string): Promise<string>;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/** A file item in a drop operation. */
|
|
78
|
-
export interface FileDropItem {
|
|
79
|
-
/** The item kind. */
|
|
80
|
-
kind: 'file';
|
|
81
|
-
/** The file type (usually a mime type). */
|
|
82
|
-
type: string;
|
|
83
|
-
/** The file name. */
|
|
84
|
-
name: string;
|
|
85
|
-
/** Returns the contents of the file as a blob. */
|
|
86
|
-
getFile(): Promise<File>;
|
|
87
|
-
/** Returns the contents of the file as a string. */
|
|
88
|
-
getText(): Promise<string>;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/** A directory item in a drop operation. */
|
|
92
|
-
export interface DirectoryDropItem {
|
|
93
|
-
/** The item kind. */
|
|
94
|
-
kind: 'directory';
|
|
95
|
-
/** The directory name. */
|
|
96
|
-
name: string;
|
|
97
|
-
/** Returns the entries contained within the directory. */
|
|
98
|
-
getEntries(): AsyncIterable<FileDropItem | DirectoryDropItem>;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/** Union of all drop item types. */
|
|
102
|
-
export type DropItem = TextDropItem | FileDropItem | DirectoryDropItem;
|
|
103
|
-
|
|
104
|
-
/** Event fired when items are dropped. */
|
|
105
|
-
export interface DropEvent extends DragDropEvent {
|
|
106
|
-
/** The event type. */
|
|
107
|
-
type: 'drop';
|
|
108
|
-
/** The drop operation that should occur. */
|
|
109
|
-
dropOperation: DropOperation;
|
|
110
|
-
/** The dropped items. */
|
|
111
|
-
items: DropItem[];
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/** Position relative to an item for drop operations. */
|
|
115
|
-
export type DropPosition = 'on' | 'before' | 'after';
|
|
116
|
-
|
|
117
|
-
/** Drop target representing the root of a collection. */
|
|
118
|
-
export interface RootDropTarget {
|
|
119
|
-
/** The drop target type. */
|
|
120
|
-
type: 'root';
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/** Drop target representing an item in a collection. */
|
|
124
|
-
export interface ItemDropTarget {
|
|
125
|
-
/** The drop target type. */
|
|
126
|
-
type: 'item';
|
|
127
|
-
/** The item key. */
|
|
128
|
-
key: string | number;
|
|
129
|
-
/** The drop position relative to the item. */
|
|
130
|
-
dropPosition: DropPosition;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/** Union of drop target types. */
|
|
134
|
-
export type DropTarget = RootDropTarget | ItemDropTarget;
|
|
135
|
-
|
|
136
|
-
// Collection drag/drop events
|
|
137
|
-
|
|
138
|
-
/** Event fired when a drag enters a droppable collection. */
|
|
139
|
-
export interface DroppableCollectionEnterEvent extends DropEnterEvent {
|
|
140
|
-
/** The drop target. */
|
|
141
|
-
target: DropTarget;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/** Event fired as a drag moves within a droppable collection. */
|
|
145
|
-
export interface DroppableCollectionMoveEvent extends DropMoveEvent {
|
|
146
|
-
/** The drop target. */
|
|
147
|
-
target: DropTarget;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/** Event fired when a drag is held over a droppable collection item. */
|
|
151
|
-
export interface DroppableCollectionActivateEvent extends DropActivateEvent {
|
|
152
|
-
/** The drop target. */
|
|
153
|
-
target: DropTarget;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/** Event fired when a drag exits a droppable collection. */
|
|
157
|
-
export interface DroppableCollectionExitEvent extends DropExitEvent {
|
|
158
|
-
/** The drop target. */
|
|
159
|
-
target: DropTarget;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/** Event fired when items are dropped on a droppable collection. */
|
|
163
|
-
export interface DroppableCollectionDropEvent extends DropEvent {
|
|
164
|
-
/** The drop target. */
|
|
165
|
-
target: DropTarget;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/** Event for inserting items between existing collection items. */
|
|
169
|
-
export interface DroppableCollectionInsertDropEvent {
|
|
170
|
-
/** The dropped items. */
|
|
171
|
-
items: DropItem[];
|
|
172
|
-
/** The drop operation that should occur. */
|
|
173
|
-
dropOperation: DropOperation;
|
|
174
|
-
/** The drop target. */
|
|
175
|
-
target: ItemDropTarget;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/** Event for dropping on the root of a collection. */
|
|
179
|
-
export interface DroppableCollectionRootDropEvent {
|
|
180
|
-
/** The dropped items. */
|
|
181
|
-
items: DropItem[];
|
|
182
|
-
/** The drop operation that should occur. */
|
|
183
|
-
dropOperation: DropOperation;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/** Event for dropping on a specific item. */
|
|
187
|
-
export interface DroppableCollectionOnItemDropEvent {
|
|
188
|
-
/** The dropped items. */
|
|
189
|
-
items: DropItem[];
|
|
190
|
-
/** The drop operation that should occur. */
|
|
191
|
-
dropOperation: DropOperation;
|
|
192
|
-
/** Whether the drag originated within the same collection as the drop. */
|
|
193
|
-
isInternal: boolean;
|
|
194
|
-
/** The drop target. */
|
|
195
|
-
target: ItemDropTarget;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
/** Event for reordering items within a collection. */
|
|
199
|
-
export interface DroppableCollectionReorderEvent {
|
|
200
|
-
/** The keys of the items that were reordered. */
|
|
201
|
-
keys: Set<string | number>;
|
|
202
|
-
/** The drop operation that should occur. */
|
|
203
|
-
dropOperation: DropOperation;
|
|
204
|
-
/** The drop target. */
|
|
205
|
-
target: ItemDropTarget;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
/** Interface for checking drag types. */
|
|
209
|
-
export interface DragTypes {
|
|
210
|
-
/** Returns whether the drag contains data of the given type. */
|
|
211
|
-
has(type: string | symbol): boolean;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
/** Delegate for determining drop targets within a collection. */
|
|
215
|
-
export interface DropTargetDelegate {
|
|
216
|
-
/**
|
|
217
|
-
* Returns a drop target within a collection for the given coordinates.
|
|
218
|
-
* @param x - X coordinate relative to the collection container
|
|
219
|
-
* @param y - Y coordinate relative to the collection container
|
|
220
|
-
* @param isValidDropTarget - Function to check if a target is valid
|
|
221
|
-
*/
|
|
222
|
-
getDropTargetFromPoint(
|
|
223
|
-
x: number,
|
|
224
|
-
y: number,
|
|
225
|
-
isValidDropTarget: (target: DropTarget) => boolean
|
|
226
|
-
): DropTarget | null;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// Draggable collection types
|
|
230
|
-
|
|
231
|
-
/** Event fired when a collection drag starts. */
|
|
232
|
-
export interface DraggableCollectionStartEvent extends DragStartEvent {
|
|
233
|
-
/** The keys of the items that were dragged. */
|
|
234
|
-
keys: Set<string | number>;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
/** Event fired as a collection drag moves. */
|
|
238
|
-
export interface DraggableCollectionMoveEvent extends DragMoveEvent {
|
|
239
|
-
/** The keys of the items that were dragged. */
|
|
240
|
-
keys: Set<string | number>;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
/** Event fired when a collection drag ends. */
|
|
244
|
-
export interface DraggableCollectionEndEvent extends DragEndEvent {
|
|
245
|
-
/** The keys of the items that were dragged. */
|
|
246
|
-
keys: Set<string | number>;
|
|
247
|
-
/** Whether the drop ended within the same collection as it originated. */
|
|
248
|
-
isInternal: boolean;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
/** Function to render a custom drag preview. */
|
|
252
|
-
export type DragPreviewRenderer = (
|
|
253
|
-
items: DragItem[],
|
|
254
|
-
callback: (node: HTMLElement | null, x?: number, y?: number) => void
|
|
255
|
-
) => void;
|
|
256
|
-
|
|
257
|
-
// Props interfaces
|
|
258
|
-
|
|
259
|
-
/** Props for droppable collection utility handlers. */
|
|
260
|
-
export interface DroppableCollectionUtilityOptions {
|
|
261
|
-
/**
|
|
262
|
-
* The drag types that the droppable collection accepts.
|
|
263
|
-
* @default 'all'
|
|
264
|
-
*/
|
|
265
|
-
acceptedDragTypes?: 'all' | Array<string | symbol>;
|
|
266
|
-
/** Handler that is called when external items are dropped "between" items. */
|
|
267
|
-
onInsert?: (e: DroppableCollectionInsertDropEvent) => void;
|
|
268
|
-
/** Handler that is called when external items are dropped on the collection's root. */
|
|
269
|
-
onRootDrop?: (e: DroppableCollectionRootDropEvent) => void;
|
|
270
|
-
/** Handler that is called when items are dropped "on" an item. */
|
|
271
|
-
onItemDrop?: (e: DroppableCollectionOnItemDropEvent) => void;
|
|
272
|
-
/** Handler that is called when items are reordered within the collection. */
|
|
273
|
-
onReorder?: (e: DroppableCollectionReorderEvent) => void;
|
|
274
|
-
/** Handler that is called when items are moved within the source collection. */
|
|
275
|
-
onMove?: (e: DroppableCollectionReorderEvent) => void;
|
|
276
|
-
/** A function returning whether a given target is a valid "on" drop target. */
|
|
277
|
-
shouldAcceptItemDrop?: (target: ItemDropTarget, types: DragTypes) => boolean;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
/** Base props for droppable collections. */
|
|
281
|
-
export interface DroppableCollectionBaseProps {
|
|
282
|
-
/** Handler that is called when a valid drag enters a drop target. */
|
|
283
|
-
onDropEnter?: (e: DroppableCollectionEnterEvent) => void;
|
|
284
|
-
/** Handler that is called after a valid drag is held over a drop target. */
|
|
285
|
-
onDropActivate?: (e: DroppableCollectionActivateEvent) => void;
|
|
286
|
-
/** Handler that is called when a valid drag exits a drop target. */
|
|
287
|
-
onDropExit?: (e: DroppableCollectionExitEvent) => void;
|
|
288
|
-
/** Handler that is called when a valid drag is dropped on a drop target. */
|
|
289
|
-
onDrop?: (e: DroppableCollectionDropEvent) => void;
|
|
290
|
-
/** A function returning the drop operation to be performed. */
|
|
291
|
-
getDropOperation?: (
|
|
292
|
-
target: DropTarget,
|
|
293
|
-
types: DragTypes,
|
|
294
|
-
allowedOperations: DropOperation[]
|
|
295
|
-
) => DropOperation;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
/** Combined props for droppable collections. */
|
|
299
|
-
export interface DroppableCollectionProps
|
|
300
|
-
extends DroppableCollectionUtilityOptions,
|
|
301
|
-
DroppableCollectionBaseProps {}
|
|
302
|
-
|
|
303
|
-
/** Props for draggable collections. */
|
|
304
|
-
export interface DraggableCollectionProps<T = object> {
|
|
305
|
-
/** Handler that is called when a drag operation is started. */
|
|
306
|
-
onDragStart?: (e: DraggableCollectionStartEvent) => void;
|
|
307
|
-
/** Handler that is called when the drag is moved. */
|
|
308
|
-
onDragMove?: (e: DraggableCollectionMoveEvent) => void;
|
|
309
|
-
/** Handler that is called when the drag operation ends. */
|
|
310
|
-
onDragEnd?: (e: DraggableCollectionEndEvent) => void;
|
|
311
|
-
/** A function that returns the items being dragged. */
|
|
312
|
-
getItems: (keys: Set<string | number>, items: T[]) => DragItem[];
|
|
313
|
-
/** The ref of the element that will be rendered as the drag preview. */
|
|
314
|
-
preview?: { current: DragPreviewRenderer | null };
|
|
315
|
-
/** Function that returns the allowed drop operations. */
|
|
316
|
-
getAllowedDropOperations?: () => DropOperation[];
|
|
317
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createFormValidationState.d.ts","sourceRoot":"","sources":["createFormValidationState.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACL,KAAK,QAAQ,EAMd,MAAM,UAAU,CAAC;AAMlB,6CAA6C;AAC7C,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,OAAO,CAAC;IAClB,WAAW,EAAE,OAAO,CAAC;IACrB,eAAe,EAAE,OAAO,CAAC;IACzB,aAAa,EAAE,OAAO,CAAC;IACvB,cAAc,EAAE,OAAO,CAAC;IACxB,YAAY,EAAE,OAAO,CAAC;IACtB,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;IAClB,YAAY,EAAE,OAAO,CAAC;IACtB,YAAY,EAAE,OAAO,CAAC;IACtB,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,4BAA4B;AAC5B,MAAM,WAAW,gBAAgB;IAC/B,oCAAoC;IACpC,SAAS,EAAE,OAAO,CAAC;IACnB,yDAAyD;IACzD,iBAAiB,EAAE,aAAa,CAAC;IACjC,iCAAiC;IACjC,gBAAgB,EAAE,MAAM,EAAE,CAAC;CAC5B;AAED,qDAAqD;AACrD,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;AAEjE,qEAAqE;AACrE,MAAM,MAAM,kBAAkB,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,GAAG,SAAS,CAAC;AAEjG,gCAAgC;AAChC,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,QAAQ,CAAC;AAEnD,MAAM,WAAW,mBAAmB,CAAC,CAAC;IACpC,iDAAiD;IACjD,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,yCAAyC;IACzC,eAAe,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACtC,kCAAkC;IAClC,QAAQ,CAAC,EAAE,kBAAkB,CAAC,CAAC,CAAC,CAAC;IACjC,wEAAwE;IACxE,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IACxC,oDAAoD;IACpD,iBAAiB,CAAC,EAAE,gBAAgB,CAAC;IACrC,6CAA6C;IAC7C,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACzB,2BAA2B;IAC3B,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;CACjB;AAED,MAAM,WAAW,mBAAmB;IAClC,wEAAwE;IACxE,kBAAkB,EAAE,QAAQ,CAAC,gBAAgB,CAAC,CAAC;IAC/C,2FAA2F;IAC3F,iBAAiB,EAAE,QAAQ,CAAC,gBAAgB,CAAC,CAAC;IAC9C,2GAA2G;IAC3G,gBAAgB,CAAC,MAAM,EAAE,gBAAgB,GAAG,IAAI,CAAC;IACjD,oFAAoF;IACpF,eAAe,IAAI,IAAI,CAAC;IACxB,sEAAsE;IACtE,gBAAgB,IAAI,IAAI,CAAC;CAC1B;AAMD,8BAA8B;AAC9B,eAAO,MAAM,oBAAoB,EAAE,aAYlC,CAAC;AASF,yCAAyC;AACzC,eAAO,MAAM,yBAAyB,EAAE,gBAIvC,CAAC;AAMF,iDAAiD;AACjD,eAAO,MAAM,qBAAqB,8CAAsC,CAAC;AAEzE,iEAAiE;AACjE,eAAO,MAAM,0BAA0B,QAAuC,CAAC;AAwD/E;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,yBAAyB,CAAC,CAAC,EACzC,KAAK,EAAE,mBAAmB,CAAC,CAAC,CAAC,GAC5B,mBAAmB,CAwJrB;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,GAAG,OAAO,EAAE,gBAAgB,EAAE,GAC7B,gBAAgB,CAwBlB"}
|
|
@@ -1,389 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* createFormValidationState for solid-stately
|
|
3
|
-
*
|
|
4
|
-
* Manages form validation state including realtime and displayed validation results.
|
|
5
|
-
* Supports both ARIA (live) and native (on submit) validation behaviors.
|
|
6
|
-
*
|
|
7
|
-
* Port of react-stately's useFormValidationState.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import {
|
|
11
|
-
type Accessor,
|
|
12
|
-
createContext,
|
|
13
|
-
createEffect,
|
|
14
|
-
createMemo,
|
|
15
|
-
createSignal,
|
|
16
|
-
useContext,
|
|
17
|
-
} from 'solid-js';
|
|
18
|
-
|
|
19
|
-
// ============================================
|
|
20
|
-
// TYPES
|
|
21
|
-
// ============================================
|
|
22
|
-
|
|
23
|
-
/** Standard HTML ValidityState interface. */
|
|
24
|
-
export interface ValidityState {
|
|
25
|
-
badInput: boolean;
|
|
26
|
-
customError: boolean;
|
|
27
|
-
patternMismatch: boolean;
|
|
28
|
-
rangeOverflow: boolean;
|
|
29
|
-
rangeUnderflow: boolean;
|
|
30
|
-
stepMismatch: boolean;
|
|
31
|
-
tooLong: boolean;
|
|
32
|
-
tooShort: boolean;
|
|
33
|
-
typeMismatch: boolean;
|
|
34
|
-
valueMissing: boolean;
|
|
35
|
-
valid: boolean;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/** Result of validation. */
|
|
39
|
-
export interface ValidationResult {
|
|
40
|
-
/** Whether the value is invalid. */
|
|
41
|
-
isInvalid: boolean;
|
|
42
|
-
/** Details about which validation constraints failed. */
|
|
43
|
-
validationDetails: ValidityState;
|
|
44
|
-
/** Error messages to display. */
|
|
45
|
-
validationErrors: string[];
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/** Map of field names to their validation errors. */
|
|
49
|
-
export type ValidationErrors = Record<string, string | string[]>;
|
|
50
|
-
|
|
51
|
-
/** Validation function that returns error messages or true/false. */
|
|
52
|
-
export type ValidationFunction<T> = (value: T) => boolean | string | string[] | null | undefined;
|
|
53
|
-
|
|
54
|
-
/** Validation behavior mode. */
|
|
55
|
-
export type ValidationBehavior = 'aria' | 'native';
|
|
56
|
-
|
|
57
|
-
export interface FormValidationProps<T> {
|
|
58
|
-
/** Whether the value is invalid (controlled). */
|
|
59
|
-
isInvalid?: boolean;
|
|
60
|
-
/** @deprecated Use isInvalid instead. */
|
|
61
|
-
validationState?: 'valid' | 'invalid';
|
|
62
|
-
/** Custom validation function. */
|
|
63
|
-
validate?: ValidationFunction<T>;
|
|
64
|
-
/** Validation behavior: 'aria' for realtime, 'native' for on submit. */
|
|
65
|
-
validationBehavior?: ValidationBehavior;
|
|
66
|
-
/** Built-in validation result from native input. */
|
|
67
|
-
builtinValidation?: ValidationResult;
|
|
68
|
-
/** Field name(s) for server error lookup. */
|
|
69
|
-
name?: string | string[];
|
|
70
|
-
/** Current field value. */
|
|
71
|
-
value: T | null;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export interface FormValidationState {
|
|
75
|
-
/** Realtime validation results, updated as the user edits the value. */
|
|
76
|
-
realtimeValidation: Accessor<ValidationResult>;
|
|
77
|
-
/** Currently displayed validation results, updated when the user commits their changes. */
|
|
78
|
-
displayValidation: Accessor<ValidationResult>;
|
|
79
|
-
/** Updates the current validation result. Not displayed to the user until `commitValidation` is called. */
|
|
80
|
-
updateValidation(result: ValidationResult): void;
|
|
81
|
-
/** Resets the displayed validation state to valid when the user resets the form. */
|
|
82
|
-
resetValidation(): void;
|
|
83
|
-
/** Commits the realtime validation so it is displayed to the user. */
|
|
84
|
-
commitValidation(): void;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// ============================================
|
|
88
|
-
// CONSTANTS
|
|
89
|
-
// ============================================
|
|
90
|
-
|
|
91
|
-
/** A valid validity state. */
|
|
92
|
-
export const VALID_VALIDITY_STATE: ValidityState = {
|
|
93
|
-
badInput: false,
|
|
94
|
-
customError: false,
|
|
95
|
-
patternMismatch: false,
|
|
96
|
-
rangeOverflow: false,
|
|
97
|
-
rangeUnderflow: false,
|
|
98
|
-
stepMismatch: false,
|
|
99
|
-
tooLong: false,
|
|
100
|
-
tooShort: false,
|
|
101
|
-
typeMismatch: false,
|
|
102
|
-
valueMissing: false,
|
|
103
|
-
valid: true,
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
/** A custom error validity state. */
|
|
107
|
-
const CUSTOM_VALIDITY_STATE: ValidityState = {
|
|
108
|
-
...VALID_VALIDITY_STATE,
|
|
109
|
-
customError: true,
|
|
110
|
-
valid: false,
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
/** Default validation result (valid). */
|
|
114
|
-
export const DEFAULT_VALIDATION_RESULT: ValidationResult = {
|
|
115
|
-
isInvalid: false,
|
|
116
|
-
validationDetails: VALID_VALIDITY_STATE,
|
|
117
|
-
validationErrors: [],
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
// ============================================
|
|
121
|
-
// CONTEXT
|
|
122
|
-
// ============================================
|
|
123
|
-
|
|
124
|
-
/** Context for server-side validation errors. */
|
|
125
|
-
export const FormValidationContext = createContext<ValidationErrors>({});
|
|
126
|
-
|
|
127
|
-
/** Private prop key for passing validation state to children. */
|
|
128
|
-
export const privateValidationStateProp = '__formValidationState' + Date.now();
|
|
129
|
-
|
|
130
|
-
// ============================================
|
|
131
|
-
// HELPERS
|
|
132
|
-
// ============================================
|
|
133
|
-
|
|
134
|
-
function asArray<T>(v: T | T[] | undefined): T[] {
|
|
135
|
-
if (!v) {
|
|
136
|
-
return [];
|
|
137
|
-
}
|
|
138
|
-
return Array.isArray(v) ? v : [v];
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
function runValidate<T>(validate: ValidationFunction<T>, value: T): string[] {
|
|
142
|
-
if (typeof validate === 'function') {
|
|
143
|
-
const e = validate(value);
|
|
144
|
-
if (e && typeof e !== 'boolean') {
|
|
145
|
-
return asArray(e);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
return [];
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
function getValidationResult(errors: string[]): ValidationResult | null {
|
|
152
|
-
return errors.length
|
|
153
|
-
? {
|
|
154
|
-
isInvalid: true,
|
|
155
|
-
validationErrors: errors,
|
|
156
|
-
validationDetails: CUSTOM_VALIDITY_STATE,
|
|
157
|
-
}
|
|
158
|
-
: null;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
function isEqualValidation(
|
|
162
|
-
a: ValidationResult | null,
|
|
163
|
-
b: ValidationResult | null
|
|
164
|
-
): boolean {
|
|
165
|
-
if (a === b) {
|
|
166
|
-
return true;
|
|
167
|
-
}
|
|
168
|
-
return (
|
|
169
|
-
!!a &&
|
|
170
|
-
!!b &&
|
|
171
|
-
a.isInvalid === b.isInvalid &&
|
|
172
|
-
a.validationErrors.length === b.validationErrors.length &&
|
|
173
|
-
a.validationErrors.every((ae, i) => ae === b.validationErrors[i]) &&
|
|
174
|
-
Object.entries(a.validationDetails).every(
|
|
175
|
-
([k, v]) => b.validationDetails[k as keyof ValidityState] === v
|
|
176
|
-
)
|
|
177
|
-
);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
// ============================================
|
|
181
|
-
// HOOK
|
|
182
|
-
// ============================================
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Creates form validation state for a field.
|
|
186
|
-
*
|
|
187
|
-
* @example
|
|
188
|
-
* ```tsx
|
|
189
|
-
* const validationState = createFormValidationState({
|
|
190
|
-
* value: inputValue(),
|
|
191
|
-
* validate: (value) => {
|
|
192
|
-
* if (!value) return 'This field is required';
|
|
193
|
-
* if (value.length < 3) return 'Must be at least 3 characters';
|
|
194
|
-
* return null;
|
|
195
|
-
* },
|
|
196
|
-
* validationBehavior: 'aria',
|
|
197
|
-
* });
|
|
198
|
-
*
|
|
199
|
-
* // Access validation state
|
|
200
|
-
* const isInvalid = () => validationState.displayValidation().isInvalid;
|
|
201
|
-
* const errors = () => validationState.displayValidation().validationErrors;
|
|
202
|
-
* ```
|
|
203
|
-
*/
|
|
204
|
-
export function createFormValidationState<T>(
|
|
205
|
-
props: FormValidationProps<T>
|
|
206
|
-
): FormValidationState {
|
|
207
|
-
const {
|
|
208
|
-
isInvalid,
|
|
209
|
-
validationState,
|
|
210
|
-
name,
|
|
211
|
-
builtinValidation: builtinValidationProp,
|
|
212
|
-
validate,
|
|
213
|
-
validationBehavior = 'aria',
|
|
214
|
-
} = props;
|
|
215
|
-
|
|
216
|
-
// Backward compatibility
|
|
217
|
-
const isInvalidProp = createMemo(
|
|
218
|
-
() => isInvalid ?? (validationState === 'invalid' ? true : undefined)
|
|
219
|
-
);
|
|
220
|
-
|
|
221
|
-
// Controlled error from isInvalid prop
|
|
222
|
-
const controlledError = createMemo<ValidationResult | null>(() =>
|
|
223
|
-
isInvalidProp() !== undefined
|
|
224
|
-
? {
|
|
225
|
-
isInvalid: isInvalidProp()!,
|
|
226
|
-
validationErrors: [],
|
|
227
|
-
validationDetails: CUSTOM_VALIDITY_STATE,
|
|
228
|
-
}
|
|
229
|
-
: null
|
|
230
|
-
);
|
|
231
|
-
|
|
232
|
-
// Client-side validation
|
|
233
|
-
const clientError = createMemo<ValidationResult | null>(() => {
|
|
234
|
-
if (!validate || props.value == null) {
|
|
235
|
-
return null;
|
|
236
|
-
}
|
|
237
|
-
const validateErrors = runValidate(validate, props.value);
|
|
238
|
-
return getValidationResult(validateErrors);
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
// Built-in validation (skip if valid)
|
|
242
|
-
const builtinValidation = createMemo<ValidationResult | undefined>(() => {
|
|
243
|
-
if (builtinValidationProp?.validationDetails.valid) {
|
|
244
|
-
return undefined;
|
|
245
|
-
}
|
|
246
|
-
return builtinValidationProp;
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
// Server errors from context
|
|
250
|
-
const serverErrors = useContext(FormValidationContext);
|
|
251
|
-
const serverErrorMessages = createMemo(() => {
|
|
252
|
-
if (name) {
|
|
253
|
-
return Array.isArray(name)
|
|
254
|
-
? name.flatMap((n) => asArray(serverErrors[n]))
|
|
255
|
-
: asArray(serverErrors[name]);
|
|
256
|
-
}
|
|
257
|
-
return [];
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
// Track server errors clearing
|
|
261
|
-
const [lastServerErrors, setLastServerErrors] = createSignal(serverErrors);
|
|
262
|
-
const [isServerErrorCleared, setServerErrorCleared] = createSignal(false);
|
|
263
|
-
|
|
264
|
-
createEffect(() => {
|
|
265
|
-
if (serverErrors !== lastServerErrors()) {
|
|
266
|
-
setLastServerErrors(serverErrors);
|
|
267
|
-
setServerErrorCleared(false);
|
|
268
|
-
}
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
const serverError = createMemo<ValidationResult | null>(() =>
|
|
272
|
-
getValidationResult(isServerErrorCleared() ? [] : serverErrorMessages())
|
|
273
|
-
);
|
|
274
|
-
|
|
275
|
-
// Track validation state
|
|
276
|
-
const [currentValidity, setCurrentValidity] = createSignal(
|
|
277
|
-
DEFAULT_VALIDATION_RESULT
|
|
278
|
-
);
|
|
279
|
-
const [commitQueued, setCommitQueued] = createSignal(false);
|
|
280
|
-
|
|
281
|
-
let nextValidation = DEFAULT_VALIDATION_RESULT;
|
|
282
|
-
let lastError = DEFAULT_VALIDATION_RESULT;
|
|
283
|
-
|
|
284
|
-
// Commit validation effect
|
|
285
|
-
createEffect(() => {
|
|
286
|
-
if (!commitQueued()) {
|
|
287
|
-
return;
|
|
288
|
-
}
|
|
289
|
-
setCommitQueued(false);
|
|
290
|
-
const error = clientError() || builtinValidation() || nextValidation;
|
|
291
|
-
if (!isEqualValidation(error, lastError)) {
|
|
292
|
-
lastError = error;
|
|
293
|
-
setCurrentValidity(error);
|
|
294
|
-
}
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
// Realtime validation (for native input state)
|
|
298
|
-
const realtimeValidation = createMemo<ValidationResult>(
|
|
299
|
-
() =>
|
|
300
|
-
controlledError() ||
|
|
301
|
-
serverError() ||
|
|
302
|
-
clientError() ||
|
|
303
|
-
builtinValidation() ||
|
|
304
|
-
DEFAULT_VALIDATION_RESULT
|
|
305
|
-
);
|
|
306
|
-
|
|
307
|
-
// Display validation (what the user sees)
|
|
308
|
-
const displayValidation = createMemo<ValidationResult>(() => {
|
|
309
|
-
if (validationBehavior === 'native') {
|
|
310
|
-
return (
|
|
311
|
-
controlledError() || serverError() || currentValidity()
|
|
312
|
-
);
|
|
313
|
-
}
|
|
314
|
-
return (
|
|
315
|
-
controlledError() ||
|
|
316
|
-
serverError() ||
|
|
317
|
-
clientError() ||
|
|
318
|
-
builtinValidation() ||
|
|
319
|
-
currentValidity()
|
|
320
|
-
);
|
|
321
|
-
});
|
|
322
|
-
|
|
323
|
-
return {
|
|
324
|
-
realtimeValidation,
|
|
325
|
-
displayValidation,
|
|
326
|
-
updateValidation(value: ValidationResult) {
|
|
327
|
-
// If validationBehavior is 'aria', update in realtime. Otherwise, store until commit.
|
|
328
|
-
if (
|
|
329
|
-
validationBehavior === 'aria' &&
|
|
330
|
-
!isEqualValidation(currentValidity(), value)
|
|
331
|
-
) {
|
|
332
|
-
setCurrentValidity(value);
|
|
333
|
-
} else {
|
|
334
|
-
nextValidation = value;
|
|
335
|
-
}
|
|
336
|
-
},
|
|
337
|
-
resetValidation() {
|
|
338
|
-
// Update the currently displayed validation state to valid on form reset.
|
|
339
|
-
const error = DEFAULT_VALIDATION_RESULT;
|
|
340
|
-
if (!isEqualValidation(error, lastError)) {
|
|
341
|
-
lastError = error;
|
|
342
|
-
setCurrentValidity(error);
|
|
343
|
-
}
|
|
344
|
-
// Do not commit validation after the next render for native behavior.
|
|
345
|
-
if (validationBehavior === 'native') {
|
|
346
|
-
setCommitQueued(false);
|
|
347
|
-
}
|
|
348
|
-
setServerErrorCleared(true);
|
|
349
|
-
},
|
|
350
|
-
commitValidation() {
|
|
351
|
-
// Commit validation state so the user sees it on blur/change/submit.
|
|
352
|
-
if (validationBehavior === 'native') {
|
|
353
|
-
setCommitQueued(true);
|
|
354
|
-
}
|
|
355
|
-
setServerErrorCleared(true);
|
|
356
|
-
},
|
|
357
|
-
};
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
/**
|
|
361
|
-
* Merges multiple validation results into one.
|
|
362
|
-
*/
|
|
363
|
-
export function mergeValidation(
|
|
364
|
-
...results: ValidationResult[]
|
|
365
|
-
): ValidationResult {
|
|
366
|
-
const errors = new Set<string>();
|
|
367
|
-
let isInvalid = false;
|
|
368
|
-
const validationDetails: ValidityState = { ...VALID_VALIDITY_STATE };
|
|
369
|
-
|
|
370
|
-
for (const v of results) {
|
|
371
|
-
for (const e of v.validationErrors) {
|
|
372
|
-
errors.add(e);
|
|
373
|
-
}
|
|
374
|
-
isInvalid = isInvalid || v.isInvalid;
|
|
375
|
-
for (const key in validationDetails) {
|
|
376
|
-
const k = key as keyof ValidityState;
|
|
377
|
-
(validationDetails as unknown as Record<string, boolean>)[k] =
|
|
378
|
-
(validationDetails as unknown as Record<string, boolean>)[k] ||
|
|
379
|
-
(v.validationDetails as unknown as Record<string, boolean>)[k];
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
validationDetails.valid = !isInvalid;
|
|
384
|
-
return {
|
|
385
|
-
isInvalid,
|
|
386
|
-
validationErrors: [...errors],
|
|
387
|
-
validationDetails,
|
|
388
|
-
};
|
|
389
|
-
}
|