@proyecto-viviana/solid-stately 0.2.4 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/LICENSE +21 -0
  2. package/dist/autocomplete/createAutocompleteState.d.ts +2 -1
  3. package/dist/checkbox/createCheckboxGroupState.d.ts +10 -1
  4. package/dist/collections/types.d.ts +11 -0
  5. package/dist/color/getColorChannels.d.ts +20 -0
  6. package/dist/data/createAsyncList.d.ts +111 -0
  7. package/dist/data/createListData.d.ts +65 -0
  8. package/dist/data/createTreeData.d.ts +61 -0
  9. package/dist/data/index.d.ts +3 -0
  10. package/dist/datepicker/index.d.ts +10 -0
  11. package/dist/grid/types.d.ts +5 -1
  12. package/dist/index.d.ts +6 -1
  13. package/dist/index.js +3737 -2697
  14. package/dist/index.js.map +1 -7
  15. package/dist/menu/index.d.ts +8 -0
  16. package/dist/radio/createRadioGroupState.d.ts +10 -1
  17. package/dist/select/createSelectState.d.ts +17 -0
  18. package/dist/selection/index.d.ts +11 -0
  19. package/dist/toast/createToastState.d.ts +7 -1
  20. package/dist/toggle/createToggleGroupState.d.ts +45 -0
  21. package/dist/toggle/index.d.ts +1 -0
  22. package/dist/tree/TreeCollection.d.ts +3 -2
  23. package/package.json +6 -5
  24. package/src/autocomplete/createAutocompleteState.ts +10 -11
  25. package/src/calendar/createDateFieldState.ts +24 -1
  26. package/src/checkbox/createCheckboxGroupState.ts +42 -6
  27. package/src/collections/ListCollection.ts +152 -146
  28. package/src/collections/createListState.ts +266 -264
  29. package/src/collections/createMenuState.ts +106 -106
  30. package/src/collections/createSelectionState.ts +336 -336
  31. package/src/collections/index.ts +46 -46
  32. package/src/collections/types.ts +181 -169
  33. package/src/color/Color.ts +951 -951
  34. package/src/color/createColorAreaState.ts +293 -293
  35. package/src/color/createColorFieldState.ts +292 -292
  36. package/src/color/createColorSliderState.ts +241 -241
  37. package/src/color/createColorWheelState.ts +211 -211
  38. package/src/color/getColorChannels.ts +34 -0
  39. package/src/color/index.ts +47 -47
  40. package/src/color/types.ts +127 -127
  41. package/src/combobox/createComboBoxState.ts +703 -703
  42. package/src/combobox/index.ts +13 -13
  43. package/src/data/createAsyncList.ts +377 -0
  44. package/src/data/createListData.ts +298 -0
  45. package/src/data/createTreeData.ts +433 -0
  46. package/src/data/index.ts +25 -0
  47. package/src/datepicker/index.ts +36 -0
  48. package/src/disclosure/createDisclosureState.ts +4 -4
  49. package/src/dnd/createDragState.ts +153 -153
  50. package/src/dnd/createDraggableCollectionState.ts +165 -165
  51. package/src/dnd/createDropState.ts +212 -212
  52. package/src/dnd/createDroppableCollectionState.ts +357 -357
  53. package/src/dnd/index.ts +76 -76
  54. package/src/dnd/types.ts +317 -317
  55. package/src/form/createFormValidationState.ts +389 -389
  56. package/src/form/index.ts +15 -15
  57. package/src/grid/types.ts +5 -0
  58. package/src/index.ts +49 -0
  59. package/src/menu/index.ts +19 -0
  60. package/src/numberfield/createNumberFieldState.ts +427 -383
  61. package/src/numberfield/index.ts +5 -5
  62. package/src/overlays/createOverlayTriggerState.ts +67 -67
  63. package/src/overlays/index.ts +5 -5
  64. package/src/radio/createRadioGroupState.ts +44 -6
  65. package/src/searchfield/createSearchFieldState.ts +62 -62
  66. package/src/searchfield/index.ts +5 -5
  67. package/src/select/createSelectState.ts +290 -181
  68. package/src/select/index.ts +5 -5
  69. package/src/selection/index.ts +28 -0
  70. package/src/slider/createSliderState.ts +211 -211
  71. package/src/slider/index.ts +6 -6
  72. package/src/tabs/createTabListState.ts +37 -11
  73. package/src/toast/createToastState.d.ts +6 -1
  74. package/src/toast/createToastState.ts +8 -1
  75. package/src/toggle/createToggleGroupState.ts +127 -0
  76. package/src/toggle/index.ts +6 -0
  77. package/src/tooltip/createTooltipTriggerState.ts +183 -183
  78. package/src/tooltip/index.ts +6 -6
  79. package/src/tree/TreeCollection.ts +208 -175
  80. package/src/tree/createTreeState.ts +392 -392
  81. package/src/tree/index.ts +13 -13
  82. package/src/tree/types.ts +174 -174
@@ -1,212 +1,212 @@
1
- /**
2
- * Drop state management for solid-stately.
3
- *
4
- * Provides reactive state for drop target operations.
5
- */
6
-
7
- import { createSignal, createMemo, type Accessor } from 'solid-js';
8
- import type {
9
- DropItem,
10
- DropEnterEvent,
11
- DropMoveEvent,
12
- DropExitEvent,
13
- DropActivateEvent,
14
- DropEvent,
15
- DropOperation,
16
- DragTypes,
17
- } from './types';
18
-
19
- export interface DropStateOptions {
20
- /**
21
- * A function returning the drop operation to be performed.
22
- */
23
- getDropOperation?: (
24
- types: DragTypes,
25
- allowedOperations: DropOperation[]
26
- ) => DropOperation;
27
- /**
28
- * A function returning the drop operation for a specific point.
29
- */
30
- getDropOperationForPoint?: (
31
- types: DragTypes,
32
- allowedOperations: DropOperation[],
33
- x: number,
34
- y: number
35
- ) => DropOperation;
36
- /** Handler that is called when a valid drag enters the drop target. */
37
- onDropEnter?: (e: DropEnterEvent) => void;
38
- /** Handler that is called when a valid drag is moved within the drop target. */
39
- onDropMove?: (e: DropMoveEvent) => void;
40
- /** Handler that is called after a valid drag is held over the drop target. */
41
- onDropActivate?: (e: DropActivateEvent) => void;
42
- /** Handler that is called when a valid drag exits the drop target. */
43
- onDropExit?: (e: DropExitEvent) => void;
44
- /** Handler that is called when a valid drag is dropped on the drop target. */
45
- onDrop?: (e: DropEvent) => void;
46
- /** Whether there is a separate drop button affordance. */
47
- hasDropButton?: boolean;
48
- /** Whether the drop target is disabled. */
49
- isDisabled?: boolean;
50
- }
51
-
52
- export interface DropState {
53
- /** Whether the drop target is currently being hovered or focused. */
54
- readonly isDropTarget: boolean;
55
- /** Whether the drop target is disabled. */
56
- readonly isDisabled: boolean;
57
- /** Whether there is a drop button. */
58
- readonly hasDropButton: boolean;
59
- /** Enter the drop target. */
60
- enterTarget(x: number, y: number): void;
61
- /** Move within the drop target. */
62
- moveInTarget(x: number, y: number): void;
63
- /** Exit the drop target. */
64
- exitTarget(x: number, y: number): void;
65
- /** Activate the drop target (after holding). */
66
- activateTarget(x: number, y: number): void;
67
- /** Perform a drop on the target. */
68
- drop(x: number, y: number, items: DropItem[], dropOperation: DropOperation): void;
69
- /** Get the drop operation for given types. */
70
- getDropOperation(types: DragTypes, allowedOperations: DropOperation[]): DropOperation;
71
- /** Get the drop operation for a specific point. */
72
- getDropOperationForPoint(
73
- types: DragTypes,
74
- allowedOperations: DropOperation[],
75
- x: number,
76
- y: number
77
- ): DropOperation;
78
- }
79
-
80
- /**
81
- * Creates drop state for managing drop target operations.
82
- *
83
- * @param props - Accessor returning drop state options
84
- * @returns Drop state object
85
- */
86
- export function createDropState(
87
- props: Accessor<DropStateOptions>
88
- ): DropState {
89
- const getProps = createMemo(() => props());
90
-
91
- const [isDropTarget, setIsDropTarget] = createSignal(false);
92
-
93
- const enterTarget = (x: number, y: number) => {
94
- const p = getProps();
95
- if (p.isDisabled) return;
96
-
97
- setIsDropTarget(true);
98
-
99
- if (typeof p.onDropEnter === 'function') {
100
- p.onDropEnter({
101
- type: 'dropenter',
102
- x,
103
- y,
104
- });
105
- }
106
- };
107
-
108
- const moveInTarget = (x: number, y: number) => {
109
- const p = getProps();
110
- if (!isDropTarget() || p.isDisabled) return;
111
-
112
- if (typeof p.onDropMove === 'function') {
113
- p.onDropMove({
114
- type: 'dropmove',
115
- x,
116
- y,
117
- });
118
- }
119
- };
120
-
121
- const exitTarget = (x: number, y: number) => {
122
- const p = getProps();
123
-
124
- setIsDropTarget(false);
125
-
126
- if (typeof p.onDropExit === 'function') {
127
- p.onDropExit({
128
- type: 'dropexit',
129
- x,
130
- y,
131
- });
132
- }
133
- };
134
-
135
- const activateTarget = (x: number, y: number) => {
136
- const p = getProps();
137
- if (p.isDisabled) return;
138
-
139
- if (typeof p.onDropActivate === 'function') {
140
- p.onDropActivate({
141
- type: 'dropactivate',
142
- x,
143
- y,
144
- });
145
- }
146
- };
147
-
148
- const drop = (
149
- x: number,
150
- y: number,
151
- items: DropItem[],
152
- dropOperation: DropOperation
153
- ) => {
154
- const p = getProps();
155
- if (p.isDisabled) return;
156
-
157
- setIsDropTarget(false);
158
-
159
- if (typeof p.onDrop === 'function') {
160
- p.onDrop({
161
- type: 'drop',
162
- x,
163
- y,
164
- items,
165
- dropOperation,
166
- });
167
- }
168
- };
169
-
170
- const getDropOperation = (
171
- types: DragTypes,
172
- allowedOperations: DropOperation[]
173
- ): DropOperation => {
174
- const p = getProps();
175
- if (typeof p.getDropOperation === 'function') {
176
- return p.getDropOperation(types, allowedOperations);
177
- }
178
- return allowedOperations[0] ?? 'cancel';
179
- };
180
-
181
- const getDropOperationForPoint = (
182
- types: DragTypes,
183
- allowedOperations: DropOperation[],
184
- x: number,
185
- y: number
186
- ): DropOperation => {
187
- const p = getProps();
188
- if (typeof p.getDropOperationForPoint === 'function') {
189
- return p.getDropOperationForPoint(types, allowedOperations, x, y);
190
- }
191
- return getDropOperation(types, allowedOperations);
192
- };
193
-
194
- return {
195
- get isDropTarget() {
196
- return isDropTarget();
197
- },
198
- get isDisabled() {
199
- return getProps().isDisabled ?? false;
200
- },
201
- get hasDropButton() {
202
- return getProps().hasDropButton ?? false;
203
- },
204
- enterTarget,
205
- moveInTarget,
206
- exitTarget,
207
- activateTarget,
208
- drop,
209
- getDropOperation,
210
- getDropOperationForPoint,
211
- };
212
- }
1
+ /**
2
+ * Drop state management for solid-stately.
3
+ *
4
+ * Provides reactive state for drop target operations.
5
+ */
6
+
7
+ import { createSignal, createMemo, type Accessor } from 'solid-js';
8
+ import type {
9
+ DropItem,
10
+ DropEnterEvent,
11
+ DropMoveEvent,
12
+ DropExitEvent,
13
+ DropActivateEvent,
14
+ DropEvent,
15
+ DropOperation,
16
+ DragTypes,
17
+ } from './types';
18
+
19
+ export interface DropStateOptions {
20
+ /**
21
+ * A function returning the drop operation to be performed.
22
+ */
23
+ getDropOperation?: (
24
+ types: DragTypes,
25
+ allowedOperations: DropOperation[]
26
+ ) => DropOperation;
27
+ /**
28
+ * A function returning the drop operation for a specific point.
29
+ */
30
+ getDropOperationForPoint?: (
31
+ types: DragTypes,
32
+ allowedOperations: DropOperation[],
33
+ x: number,
34
+ y: number
35
+ ) => DropOperation;
36
+ /** Handler that is called when a valid drag enters the drop target. */
37
+ onDropEnter?: (e: DropEnterEvent) => void;
38
+ /** Handler that is called when a valid drag is moved within the drop target. */
39
+ onDropMove?: (e: DropMoveEvent) => void;
40
+ /** Handler that is called after a valid drag is held over the drop target. */
41
+ onDropActivate?: (e: DropActivateEvent) => void;
42
+ /** Handler that is called when a valid drag exits the drop target. */
43
+ onDropExit?: (e: DropExitEvent) => void;
44
+ /** Handler that is called when a valid drag is dropped on the drop target. */
45
+ onDrop?: (e: DropEvent) => void;
46
+ /** Whether there is a separate drop button affordance. */
47
+ hasDropButton?: boolean;
48
+ /** Whether the drop target is disabled. */
49
+ isDisabled?: boolean;
50
+ }
51
+
52
+ export interface DropState {
53
+ /** Whether the drop target is currently being hovered or focused. */
54
+ readonly isDropTarget: boolean;
55
+ /** Whether the drop target is disabled. */
56
+ readonly isDisabled: boolean;
57
+ /** Whether there is a drop button. */
58
+ readonly hasDropButton: boolean;
59
+ /** Enter the drop target. */
60
+ enterTarget(x: number, y: number): void;
61
+ /** Move within the drop target. */
62
+ moveInTarget(x: number, y: number): void;
63
+ /** Exit the drop target. */
64
+ exitTarget(x: number, y: number): void;
65
+ /** Activate the drop target (after holding). */
66
+ activateTarget(x: number, y: number): void;
67
+ /** Perform a drop on the target. */
68
+ drop(x: number, y: number, items: DropItem[], dropOperation: DropOperation): void;
69
+ /** Get the drop operation for given types. */
70
+ getDropOperation(types: DragTypes, allowedOperations: DropOperation[]): DropOperation;
71
+ /** Get the drop operation for a specific point. */
72
+ getDropOperationForPoint(
73
+ types: DragTypes,
74
+ allowedOperations: DropOperation[],
75
+ x: number,
76
+ y: number
77
+ ): DropOperation;
78
+ }
79
+
80
+ /**
81
+ * Creates drop state for managing drop target operations.
82
+ *
83
+ * @param props - Accessor returning drop state options
84
+ * @returns Drop state object
85
+ */
86
+ export function createDropState(
87
+ props: Accessor<DropStateOptions>
88
+ ): DropState {
89
+ const getProps = createMemo(() => props());
90
+
91
+ const [isDropTarget, setIsDropTarget] = createSignal(false);
92
+
93
+ const enterTarget = (x: number, y: number) => {
94
+ const p = getProps();
95
+ if (p.isDisabled) return;
96
+
97
+ setIsDropTarget(true);
98
+
99
+ if (typeof p.onDropEnter === 'function') {
100
+ p.onDropEnter({
101
+ type: 'dropenter',
102
+ x,
103
+ y,
104
+ });
105
+ }
106
+ };
107
+
108
+ const moveInTarget = (x: number, y: number) => {
109
+ const p = getProps();
110
+ if (!isDropTarget() || p.isDisabled) return;
111
+
112
+ if (typeof p.onDropMove === 'function') {
113
+ p.onDropMove({
114
+ type: 'dropmove',
115
+ x,
116
+ y,
117
+ });
118
+ }
119
+ };
120
+
121
+ const exitTarget = (x: number, y: number) => {
122
+ const p = getProps();
123
+
124
+ setIsDropTarget(false);
125
+
126
+ if (typeof p.onDropExit === 'function') {
127
+ p.onDropExit({
128
+ type: 'dropexit',
129
+ x,
130
+ y,
131
+ });
132
+ }
133
+ };
134
+
135
+ const activateTarget = (x: number, y: number) => {
136
+ const p = getProps();
137
+ if (p.isDisabled) return;
138
+
139
+ if (typeof p.onDropActivate === 'function') {
140
+ p.onDropActivate({
141
+ type: 'dropactivate',
142
+ x,
143
+ y,
144
+ });
145
+ }
146
+ };
147
+
148
+ const drop = (
149
+ x: number,
150
+ y: number,
151
+ items: DropItem[],
152
+ dropOperation: DropOperation
153
+ ) => {
154
+ const p = getProps();
155
+ if (p.isDisabled) return;
156
+
157
+ setIsDropTarget(false);
158
+
159
+ if (typeof p.onDrop === 'function') {
160
+ p.onDrop({
161
+ type: 'drop',
162
+ x,
163
+ y,
164
+ items,
165
+ dropOperation,
166
+ });
167
+ }
168
+ };
169
+
170
+ const getDropOperation = (
171
+ types: DragTypes,
172
+ allowedOperations: DropOperation[]
173
+ ): DropOperation => {
174
+ const p = getProps();
175
+ if (typeof p.getDropOperation === 'function') {
176
+ return p.getDropOperation(types, allowedOperations);
177
+ }
178
+ return allowedOperations[0] ?? 'cancel';
179
+ };
180
+
181
+ const getDropOperationForPoint = (
182
+ types: DragTypes,
183
+ allowedOperations: DropOperation[],
184
+ x: number,
185
+ y: number
186
+ ): DropOperation => {
187
+ const p = getProps();
188
+ if (typeof p.getDropOperationForPoint === 'function') {
189
+ return p.getDropOperationForPoint(types, allowedOperations, x, y);
190
+ }
191
+ return getDropOperation(types, allowedOperations);
192
+ };
193
+
194
+ return {
195
+ get isDropTarget() {
196
+ return isDropTarget();
197
+ },
198
+ get isDisabled() {
199
+ return getProps().isDisabled ?? false;
200
+ },
201
+ get hasDropButton() {
202
+ return getProps().hasDropButton ?? false;
203
+ },
204
+ enterTarget,
205
+ moveInTarget,
206
+ exitTarget,
207
+ activateTarget,
208
+ drop,
209
+ getDropOperation,
210
+ getDropOperationForPoint,
211
+ };
212
+ }