@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
|
@@ -1,383 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* State management for NumberField.
|
|
3
|
-
* Based on @react-stately/numberfield useNumberFieldState.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { createSignal, createMemo, type Accessor } from 'solid-js';
|
|
7
|
-
import { access, type MaybeAccessor } from '../utils';
|
|
8
|
-
|
|
9
|
-
export interface NumberFieldStateProps {
|
|
10
|
-
/** The current value (controlled). */
|
|
11
|
-
value?: number;
|
|
12
|
-
/** The default value (uncontrolled). */
|
|
13
|
-
defaultValue?: number;
|
|
14
|
-
/** Handler called when the value changes. */
|
|
15
|
-
onChange?: (value: number) => void;
|
|
16
|
-
/** The minimum value. */
|
|
17
|
-
minValue?: number;
|
|
18
|
-
/** The maximum value. */
|
|
19
|
-
maxValue?: number;
|
|
20
|
-
/** The step value for increment/decrement. */
|
|
21
|
-
step?: number;
|
|
22
|
-
/** Whether the field is disabled. */
|
|
23
|
-
isDisabled?: boolean;
|
|
24
|
-
/** Whether the field is read-only. */
|
|
25
|
-
isReadOnly?: boolean;
|
|
26
|
-
/** The locale for number formatting. */
|
|
27
|
-
locale?: string;
|
|
28
|
-
/** Number format options. */
|
|
29
|
-
formatOptions?: Intl.NumberFormatOptions;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export interface NumberFieldState {
|
|
33
|
-
/** The current input value as a string. */
|
|
34
|
-
inputValue: Accessor<string>;
|
|
35
|
-
/** The current numeric value. */
|
|
36
|
-
numberValue: Accessor<number>;
|
|
37
|
-
/** Whether the value can be incremented. */
|
|
38
|
-
canIncrement: Accessor<boolean>;
|
|
39
|
-
/** Whether the value can be decremented. */
|
|
40
|
-
canDecrement: Accessor<boolean>;
|
|
41
|
-
/** Whether the field is disabled. */
|
|
42
|
-
isDisabled: Accessor<boolean>;
|
|
43
|
-
/** Whether the field is read-only. */
|
|
44
|
-
isReadOnly: Accessor<boolean>;
|
|
45
|
-
/** The minimum value. */
|
|
46
|
-
minValue: Accessor<number | undefined>;
|
|
47
|
-
/** The maximum value. */
|
|
48
|
-
maxValue: Accessor<number | undefined>;
|
|
49
|
-
/** Set the input value. */
|
|
50
|
-
setInputValue: (value: string) => void;
|
|
51
|
-
/** Validate a partial input value. */
|
|
52
|
-
validate: (value: string) => boolean;
|
|
53
|
-
/** Commit the current input value. */
|
|
54
|
-
commit: () => void;
|
|
55
|
-
/** Increment the value by step. */
|
|
56
|
-
increment: () => void;
|
|
57
|
-
/** Decrement the value by step. */
|
|
58
|
-
decrement: () => void;
|
|
59
|
-
/** Set to maximum value. */
|
|
60
|
-
incrementToMax: () => void;
|
|
61
|
-
/** Set to minimum value. */
|
|
62
|
-
decrementToMin: () => void;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Handles decimal operations to avoid floating point errors.
|
|
67
|
-
*/
|
|
68
|
-
function handleDecimalOperation(
|
|
69
|
-
operator: '+' | '-',
|
|
70
|
-
value1: number,
|
|
71
|
-
value2: number
|
|
72
|
-
): number {
|
|
73
|
-
// Find the number of decimal places
|
|
74
|
-
const getDecimals = (n: number) => {
|
|
75
|
-
const str = String(n);
|
|
76
|
-
const idx = str.indexOf('.');
|
|
77
|
-
return idx === -1 ? 0 : str.length - idx - 1;
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
const decimals = Math.max(getDecimals(value1), getDecimals(value2));
|
|
81
|
-
const multiplier = Math.pow(10, decimals);
|
|
82
|
-
|
|
83
|
-
const int1 = Math.round(value1 * multiplier);
|
|
84
|
-
const int2 = Math.round(value2 * multiplier);
|
|
85
|
-
|
|
86
|
-
const result = operator === '+' ? int1 + int2 : int1 - int2;
|
|
87
|
-
return result / multiplier;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Clamps a value between min and max.
|
|
92
|
-
*/
|
|
93
|
-
function clamp(value: number, min?: number, max?: number): number {
|
|
94
|
-
let result = value;
|
|
95
|
-
if (min != null && result < min) result = min;
|
|
96
|
-
if (max != null && result > max) result = max;
|
|
97
|
-
return result;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Snaps a value to the nearest step.
|
|
102
|
-
*/
|
|
103
|
-
function snapToStep(value: number, step: number, min?: number): number {
|
|
104
|
-
const base = min ?? 0;
|
|
105
|
-
const diff = value - base;
|
|
106
|
-
const steps = Math.round(diff / step);
|
|
107
|
-
return handleDecimalOperation('+', base, steps * step);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Creates state for a number field.
|
|
112
|
-
*/
|
|
113
|
-
export function createNumberFieldState(
|
|
114
|
-
props: MaybeAccessor<NumberFieldStateProps>
|
|
115
|
-
): NumberFieldState {
|
|
116
|
-
const getProps = () => access(props);
|
|
117
|
-
|
|
118
|
-
// Get locale and formatter
|
|
119
|
-
const locale = () => getProps().locale ?? 'en-US';
|
|
120
|
-
const formatOptions = () => getProps().formatOptions ?? {};
|
|
121
|
-
|
|
122
|
-
// Create number formatter
|
|
123
|
-
const formatter = createMemo(() => {
|
|
124
|
-
return new Intl.NumberFormat(locale(), formatOptions());
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
// Create number parser (simplified - real implementation would be more robust)
|
|
128
|
-
const parseNumber = (value: string): number => {
|
|
129
|
-
if (!value || value === '' || value === '-') return NaN;
|
|
130
|
-
|
|
131
|
-
// Handle locale-specific decimal separators
|
|
132
|
-
const opts = formatOptions();
|
|
133
|
-
const testNumber = formatter().format(1.1);
|
|
134
|
-
const decimalSeparator = testNumber.charAt(1);
|
|
135
|
-
|
|
136
|
-
// Normalize the input
|
|
137
|
-
let normalized = value;
|
|
138
|
-
if (decimalSeparator !== '.') {
|
|
139
|
-
normalized = normalized.replace(decimalSeparator, '.');
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// Remove grouping separators and currency symbols
|
|
143
|
-
normalized = normalized.replace(/[^\d.\-]/g, '');
|
|
144
|
-
|
|
145
|
-
const parsed = parseFloat(normalized);
|
|
146
|
-
return parsed;
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
// Format a number to string
|
|
150
|
-
const formatNumber = (value: number): string => {
|
|
151
|
-
if (isNaN(value)) return '';
|
|
152
|
-
return formatter().format(value);
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
// Determine step value
|
|
156
|
-
const step = createMemo(() => {
|
|
157
|
-
const p = getProps();
|
|
158
|
-
if (p.step != null) return p.step;
|
|
159
|
-
// Default step for percent is 0.01
|
|
160
|
-
if (p.formatOptions?.style === 'percent') return 0.01;
|
|
161
|
-
return 1;
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
// Internal signals
|
|
165
|
-
const [inputValue, setInputValueInternal] = createSignal<string>('');
|
|
166
|
-
const [numberValue, setNumberValue] = createSignal<number>(NaN);
|
|
167
|
-
|
|
168
|
-
// Initialize from props
|
|
169
|
-
const initValue = () => {
|
|
170
|
-
const p = getProps();
|
|
171
|
-
const initial = p.value ?? p.defaultValue;
|
|
172
|
-
if (initial != null) {
|
|
173
|
-
setNumberValue(initial);
|
|
174
|
-
setInputValueInternal(formatNumber(initial));
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
// Call init on first access
|
|
179
|
-
let initialized = false;
|
|
180
|
-
const ensureInitialized = () => {
|
|
181
|
-
if (!initialized) {
|
|
182
|
-
initialized = true;
|
|
183
|
-
initValue();
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
// Controlled mode: sync with props.value
|
|
188
|
-
const actualNumberValue = createMemo(() => {
|
|
189
|
-
ensureInitialized();
|
|
190
|
-
const p = getProps();
|
|
191
|
-
if (p.value !== undefined) {
|
|
192
|
-
return p.value;
|
|
193
|
-
}
|
|
194
|
-
return numberValue();
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
// Validate partial input
|
|
198
|
-
const validate = (value: string): boolean => {
|
|
199
|
-
if (value === '' || value === '-') return true;
|
|
200
|
-
|
|
201
|
-
// Allow partial decimal input like "1."
|
|
202
|
-
const opts = formatOptions();
|
|
203
|
-
const testNumber = formatter().format(1.1);
|
|
204
|
-
const decimalSeparator = testNumber.charAt(1);
|
|
205
|
-
|
|
206
|
-
// Check if it's a valid partial number
|
|
207
|
-
const pattern = new RegExp(
|
|
208
|
-
`^-?\\d*${decimalSeparator === '.' ? '\\.' : decimalSeparator}?\\d*$`
|
|
209
|
-
);
|
|
210
|
-
return pattern.test(value);
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
// Set input value with validation
|
|
214
|
-
const setInputValue = (value: string) => {
|
|
215
|
-
ensureInitialized();
|
|
216
|
-
setInputValueInternal(value);
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
// Commit the current input value
|
|
220
|
-
const commit = () => {
|
|
221
|
-
ensureInitialized();
|
|
222
|
-
const p = getProps();
|
|
223
|
-
const input = inputValue();
|
|
224
|
-
|
|
225
|
-
if (input === '' || input === '-') {
|
|
226
|
-
// Clear value
|
|
227
|
-
setNumberValue(NaN);
|
|
228
|
-
setInputValueInternal('');
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
let parsed = parseNumber(input);
|
|
233
|
-
|
|
234
|
-
if (isNaN(parsed)) {
|
|
235
|
-
// Invalid input - revert to current value
|
|
236
|
-
setInputValueInternal(formatNumber(actualNumberValue()));
|
|
237
|
-
return;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
// Clamp and snap
|
|
241
|
-
parsed = clamp(parsed, p.minValue, p.maxValue);
|
|
242
|
-
parsed = snapToStep(parsed, step(), p.minValue);
|
|
243
|
-
|
|
244
|
-
// Update state
|
|
245
|
-
setNumberValue(parsed);
|
|
246
|
-
setInputValueInternal(formatNumber(parsed));
|
|
247
|
-
|
|
248
|
-
// Notify change
|
|
249
|
-
if (p.value === undefined) {
|
|
250
|
-
p.onChange?.(parsed);
|
|
251
|
-
} else {
|
|
252
|
-
p.onChange?.(parsed);
|
|
253
|
-
}
|
|
254
|
-
};
|
|
255
|
-
|
|
256
|
-
// Check if can increment
|
|
257
|
-
const canIncrement = createMemo(() => {
|
|
258
|
-
ensureInitialized();
|
|
259
|
-
const p = getProps();
|
|
260
|
-
if (p.isDisabled || p.isReadOnly) return false;
|
|
261
|
-
|
|
262
|
-
const current = actualNumberValue();
|
|
263
|
-
if (isNaN(current)) return true; // Can start from min
|
|
264
|
-
|
|
265
|
-
if (p.maxValue == null) return true;
|
|
266
|
-
return handleDecimalOperation('+', current, step()) <= p.maxValue;
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
// Check if can decrement
|
|
270
|
-
const canDecrement = createMemo(() => {
|
|
271
|
-
ensureInitialized();
|
|
272
|
-
const p = getProps();
|
|
273
|
-
if (p.isDisabled || p.isReadOnly) return false;
|
|
274
|
-
|
|
275
|
-
const current = actualNumberValue();
|
|
276
|
-
if (isNaN(current)) return true; // Can start from max
|
|
277
|
-
|
|
278
|
-
if (p.minValue == null) return true;
|
|
279
|
-
return handleDecimalOperation('-', current, step()) >= p.minValue;
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
// Increment by step
|
|
283
|
-
const increment = () => {
|
|
284
|
-
ensureInitialized();
|
|
285
|
-
const p = getProps();
|
|
286
|
-
if (p.isDisabled || p.isReadOnly) return;
|
|
287
|
-
|
|
288
|
-
let current = actualNumberValue();
|
|
289
|
-
|
|
290
|
-
if (isNaN(current)) {
|
|
291
|
-
// Start from min or 0
|
|
292
|
-
current = p.minValue ?? 0;
|
|
293
|
-
} else {
|
|
294
|
-
// Snap and increment
|
|
295
|
-
current = snapToStep(current, step(), p.minValue);
|
|
296
|
-
current = handleDecimalOperation('+', current, step());
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
// Clamp
|
|
300
|
-
current = clamp(current, p.minValue, p.maxValue);
|
|
301
|
-
|
|
302
|
-
// Update
|
|
303
|
-
setNumberValue(current);
|
|
304
|
-
setInputValueInternal(formatNumber(current));
|
|
305
|
-
p.onChange?.(current);
|
|
306
|
-
};
|
|
307
|
-
|
|
308
|
-
// Decrement by step
|
|
309
|
-
const decrement = () => {
|
|
310
|
-
ensureInitialized();
|
|
311
|
-
const p = getProps();
|
|
312
|
-
if (p.isDisabled || p.isReadOnly) return;
|
|
313
|
-
|
|
314
|
-
let current = actualNumberValue();
|
|
315
|
-
|
|
316
|
-
if (isNaN(current)) {
|
|
317
|
-
// Start from max or 0
|
|
318
|
-
current = p.maxValue ?? 0;
|
|
319
|
-
} else {
|
|
320
|
-
// Snap and decrement
|
|
321
|
-
current = snapToStep(current, step(), p.minValue);
|
|
322
|
-
current = handleDecimalOperation('-', current, step());
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
// Clamp
|
|
326
|
-
current = clamp(current, p.minValue, p.maxValue);
|
|
327
|
-
|
|
328
|
-
// Update
|
|
329
|
-
setNumberValue(current);
|
|
330
|
-
setInputValueInternal(formatNumber(current));
|
|
331
|
-
p.onChange?.(current);
|
|
332
|
-
};
|
|
333
|
-
|
|
334
|
-
// Set to max
|
|
335
|
-
const incrementToMax = () => {
|
|
336
|
-
ensureInitialized();
|
|
337
|
-
const p = getProps();
|
|
338
|
-
if (p.isDisabled || p.isReadOnly) return;
|
|
339
|
-
|
|
340
|
-
if (p.maxValue == null) return;
|
|
341
|
-
|
|
342
|
-
const snapped = snapToStep(p.maxValue, step(), p.minValue);
|
|
343
|
-
setNumberValue(snapped);
|
|
344
|
-
setInputValueInternal(formatNumber(snapped));
|
|
345
|
-
p.onChange?.(snapped);
|
|
346
|
-
};
|
|
347
|
-
|
|
348
|
-
// Set to min
|
|
349
|
-
const decrementToMin = () => {
|
|
350
|
-
ensureInitialized();
|
|
351
|
-
const p = getProps();
|
|
352
|
-
if (p.isDisabled || p.isReadOnly) return;
|
|
353
|
-
|
|
354
|
-
if (p.minValue == null) return;
|
|
355
|
-
|
|
356
|
-
setNumberValue(p.minValue);
|
|
357
|
-
setInputValueInternal(formatNumber(p.minValue));
|
|
358
|
-
p.onChange?.(p.minValue);
|
|
359
|
-
};
|
|
360
|
-
|
|
361
|
-
return {
|
|
362
|
-
get inputValue() {
|
|
363
|
-
ensureInitialized();
|
|
364
|
-
return inputValue;
|
|
365
|
-
},
|
|
366
|
-
get numberValue() {
|
|
367
|
-
return actualNumberValue;
|
|
368
|
-
},
|
|
369
|
-
canIncrement,
|
|
370
|
-
canDecrement,
|
|
371
|
-
isDisabled: () => getProps().isDisabled ?? false,
|
|
372
|
-
isReadOnly: () => getProps().isReadOnly ?? false,
|
|
373
|
-
minValue: () => getProps().minValue,
|
|
374
|
-
maxValue: () => getProps().maxValue,
|
|
375
|
-
setInputValue,
|
|
376
|
-
validate,
|
|
377
|
-
commit,
|
|
378
|
-
increment,
|
|
379
|
-
decrement,
|
|
380
|
-
incrementToMax,
|
|
381
|
-
decrementToMin,
|
|
382
|
-
};
|
|
383
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,gBAAgB,GACtB,MAAM,0BAA0B,CAAC"}
|
package/src/numberfield/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createOverlayTriggerState.d.ts","sourceRoot":"","sources":["createOverlayTriggerState.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAgB,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAC;AACvD,OAAO,EAAU,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AAEtD,MAAM,WAAW,mBAAmB;IAClC,6DAA6D;IAC7D,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,gDAAgD;IAChD,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,oEAAoE;IACpE,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;CAC1C;AAED,MAAM,WAAW,mBAAmB;IAClC,6CAA6C;IAC7C,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;IACnC,wCAAwC;IACxC,OAAO,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI,CAAC;IAC/B,yBAAyB;IACzB,IAAI,IAAI,IAAI,CAAC;IACb,0BAA0B;IAC1B,KAAK,IAAI,IAAI,CAAC;IACd,wCAAwC;IACxC,MAAM,IAAI,IAAI,CAAC;CAChB;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CACvC,KAAK,GAAE,aAAa,CAAC,mBAAmB,CAAM,GAC7C,mBAAmB,CA8BrB"}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Manages state for an overlay trigger.
|
|
3
|
-
* Based on @react-stately/overlays useOverlayTriggerState.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { createSignal, type Accessor } from 'solid-js';
|
|
7
|
-
import { access, type MaybeAccessor } from '../utils';
|
|
8
|
-
|
|
9
|
-
export interface OverlayTriggerProps {
|
|
10
|
-
/** Whether the overlay is open by default (uncontrolled). */
|
|
11
|
-
defaultOpen?: boolean;
|
|
12
|
-
/** Whether the overlay is open (controlled). */
|
|
13
|
-
isOpen?: boolean;
|
|
14
|
-
/** Handler that is called when the overlay's open state changes. */
|
|
15
|
-
onOpenChange?: (isOpen: boolean) => void;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface OverlayTriggerState {
|
|
19
|
-
/** Whether the overlay is currently open. */
|
|
20
|
-
readonly isOpen: Accessor<boolean>;
|
|
21
|
-
/** Sets whether the overlay is open. */
|
|
22
|
-
setOpen(isOpen: boolean): void;
|
|
23
|
-
/** Opens the overlay. */
|
|
24
|
-
open(): void;
|
|
25
|
-
/** Closes the overlay. */
|
|
26
|
-
close(): void;
|
|
27
|
-
/** Toggles the overlay's visibility. */
|
|
28
|
-
toggle(): void;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Manages state for an overlay trigger. Tracks whether the overlay is open, and provides
|
|
33
|
-
* methods to toggle this state.
|
|
34
|
-
*/
|
|
35
|
-
export function createOverlayTriggerState(
|
|
36
|
-
props: MaybeAccessor<OverlayTriggerProps> = {}
|
|
37
|
-
): OverlayTriggerState {
|
|
38
|
-
const propsAccessor = () => access(props);
|
|
39
|
-
|
|
40
|
-
// Use controlled state if isOpen is provided, otherwise use internal state
|
|
41
|
-
const [internalOpen, setInternalOpen] = createSignal(propsAccessor().defaultOpen ?? false);
|
|
42
|
-
|
|
43
|
-
const isOpen: Accessor<boolean> = () => {
|
|
44
|
-
const p = propsAccessor();
|
|
45
|
-
return p.isOpen !== undefined ? p.isOpen : internalOpen();
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const setOpen = (open: boolean) => {
|
|
49
|
-
const p = propsAccessor();
|
|
50
|
-
if (p.isOpen === undefined) {
|
|
51
|
-
setInternalOpen(open);
|
|
52
|
-
}
|
|
53
|
-
p.onOpenChange?.(open);
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const open = () => setOpen(true);
|
|
57
|
-
const close = () => setOpen(false);
|
|
58
|
-
const toggle = () => setOpen(!isOpen());
|
|
59
|
-
|
|
60
|
-
return {
|
|
61
|
-
isOpen,
|
|
62
|
-
setOpen,
|
|
63
|
-
open,
|
|
64
|
-
close,
|
|
65
|
-
toggle,
|
|
66
|
-
};
|
|
67
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,GACzB,MAAM,6BAA6B,CAAC"}
|
package/src/overlays/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createRadioGroupState.d.ts","sourceRoot":"","sources":["createRadioGroupState.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAgB,QAAQ,EAAW,MAAM,UAAU,CAAC;AAC3D,OAAO,EAAE,KAAK,aAAa,EAAU,MAAM,UAAU,CAAC;AAOtD,MAAM,WAAW,eAAe;IAC9B,+CAA+C;IAC/C,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,iDAAiD;IACjD,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,qDAAqD;IACrD,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,2CAA2C;IAC3C,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,4CAA4C;IAC5C,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,2CAA2C;IAC3C,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,0CAA0C;IAC1C,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,sEAAsE;IACtE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,kDAAkD;IAClD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,qCAAqC;IACrC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,sCAAsC;IACtC,WAAW,CAAC,EAAE,YAAY,GAAG,UAAU,CAAC;IACxC,kEAAkE;IAClE,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,IAAI,CAAC;IAClC,+DAA+D;IAC/D,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,IAAI,CAAC;IACjC,0EAA0E;IAC1E,aAAa,CAAC,EAAE,CAAC,SAAS,EAAE,OAAO,KAAK,IAAI,CAAC;CAC9C;AAED,MAAM,WAAW,eAAe;IAC9B,+DAA+D;IAC/D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,2CAA2C;IAC3C,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAE7B,4CAA4C;IAC5C,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAE7B,2CAA2C;IAC3C,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAE7B,0CAA0C;IAC1C,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAE5B,oCAAoC;IACpC,QAAQ,CAAC,aAAa,EAAE,QAAQ,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAEhD,kCAAkC;IAClC,QAAQ,CAAC,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAC;IAE7C,+BAA+B;IAC/B,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;IAE7C,2CAA2C;IAC3C,QAAQ,CAAC,gBAAgB,EAAE,QAAQ,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAEnD,mCAAmC;IACnC,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;CACjD;AAMD;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,EAAE,OAAO,CAAC,eAAe,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAiB,CAAC;AAM/F;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,GAAE,aAAa,CAAC,eAAe,CAAM,GACzC,eAAe,CAgGjB"}
|
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Radio group state for Solid Stately
|
|
3
|
-
*
|
|
4
|
-
* Provides state management for a radio group component.
|
|
5
|
-
* Provides a name for the group, and manages selection and focus state.
|
|
6
|
-
*
|
|
7
|
-
* This is a 1:1 port of @react-stately/radio's useRadioGroupState.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { createSignal, Accessor, untrack } from 'solid-js';
|
|
11
|
-
import { type MaybeAccessor, access } from '../utils';
|
|
12
|
-
import { createId } from '../ssr';
|
|
13
|
-
|
|
14
|
-
// ============================================
|
|
15
|
-
// TYPES
|
|
16
|
-
// ============================================
|
|
17
|
-
|
|
18
|
-
export interface RadioGroupProps {
|
|
19
|
-
/** The current selected value (controlled). */
|
|
20
|
-
value?: string | null;
|
|
21
|
-
/** The default selected value (uncontrolled). */
|
|
22
|
-
defaultValue?: string | null;
|
|
23
|
-
/** Handler that is called when the value changes. */
|
|
24
|
-
onChange?: (value: string) => void;
|
|
25
|
-
/** Whether the radio group is disabled. */
|
|
26
|
-
isDisabled?: boolean;
|
|
27
|
-
/** Whether the radio group is read only. */
|
|
28
|
-
isReadOnly?: boolean;
|
|
29
|
-
/** Whether the radio group is required. */
|
|
30
|
-
isRequired?: boolean;
|
|
31
|
-
/** Whether the radio group is invalid. */
|
|
32
|
-
isInvalid?: boolean;
|
|
33
|
-
/** The name of the radio group, used when submitting an HTML form. */
|
|
34
|
-
name?: string;
|
|
35
|
-
/** The form to associate the radio group with. */
|
|
36
|
-
form?: string;
|
|
37
|
-
/** The label for the radio group. */
|
|
38
|
-
label?: string;
|
|
39
|
-
/** Orientation of the radio group. */
|
|
40
|
-
orientation?: 'horizontal' | 'vertical';
|
|
41
|
-
/** Handler that is called when the radio group receives focus. */
|
|
42
|
-
onFocus?: (e: FocusEvent) => void;
|
|
43
|
-
/** Handler that is called when the radio group loses focus. */
|
|
44
|
-
onBlur?: (e: FocusEvent) => void;
|
|
45
|
-
/** Handler that is called when the radio group's focus status changes. */
|
|
46
|
-
onFocusChange?: (isFocused: boolean) => void;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export interface RadioGroupState {
|
|
50
|
-
/** The name for the group, used for native form submission. */
|
|
51
|
-
readonly name: string;
|
|
52
|
-
|
|
53
|
-
/** Whether the radio group is disabled. */
|
|
54
|
-
readonly isDisabled: boolean;
|
|
55
|
-
|
|
56
|
-
/** Whether the radio group is read only. */
|
|
57
|
-
readonly isReadOnly: boolean;
|
|
58
|
-
|
|
59
|
-
/** Whether the radio group is required. */
|
|
60
|
-
readonly isRequired: boolean;
|
|
61
|
-
|
|
62
|
-
/** Whether the radio group is invalid. */
|
|
63
|
-
readonly isInvalid: boolean;
|
|
64
|
-
|
|
65
|
-
/** The currently selected value. */
|
|
66
|
-
readonly selectedValue: Accessor<string | null>;
|
|
67
|
-
|
|
68
|
-
/** The default selected value. */
|
|
69
|
-
readonly defaultSelectedValue: string | null;
|
|
70
|
-
|
|
71
|
-
/** Sets the selected value. */
|
|
72
|
-
setSelectedValue(value: string | null): void;
|
|
73
|
-
|
|
74
|
-
/** The value of the last focused radio. */
|
|
75
|
-
readonly lastFocusedValue: Accessor<string | null>;
|
|
76
|
-
|
|
77
|
-
/** Sets the last focused value. */
|
|
78
|
-
setLastFocusedValue(value: string | null): void;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// ============================================
|
|
82
|
-
// INTERNAL: SolidJS-specific sync mechanism
|
|
83
|
-
// ============================================
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Internal WeakMap to store sync version accessors for each radio group state.
|
|
87
|
-
* This is used by createRadio to trigger DOM sync when native radio behavior
|
|
88
|
-
* causes the DOM checked state to desync from our reactive state.
|
|
89
|
-
*
|
|
90
|
-
* This is kept separate from RadioGroupState to maintain API parity with React-Stately.
|
|
91
|
-
* @internal
|
|
92
|
-
*/
|
|
93
|
-
export const radioGroupSyncVersion: WeakMap<RadioGroupState, Accessor<number>> = new WeakMap();
|
|
94
|
-
|
|
95
|
-
// ============================================
|
|
96
|
-
// IMPLEMENTATION
|
|
97
|
-
// ============================================
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Provides state management for a radio group component.
|
|
101
|
-
* Provides a name for the group, and manages selection and focus state.
|
|
102
|
-
*/
|
|
103
|
-
export function createRadioGroupState(
|
|
104
|
-
props: MaybeAccessor<RadioGroupProps> = {}
|
|
105
|
-
): RadioGroupState {
|
|
106
|
-
const getProps = () => access(props);
|
|
107
|
-
|
|
108
|
-
// Get initial props using untrack to avoid setting up dependencies
|
|
109
|
-
// This ensures we capture the initial defaultValue without reactivity issues
|
|
110
|
-
const initialProps = untrack(() => getProps());
|
|
111
|
-
|
|
112
|
-
// Generate name - preserved for backward compatibility
|
|
113
|
-
// React Aria now generates the name instead of stately
|
|
114
|
-
const name = initialProps.name || `radio-group-${createId()}`;
|
|
115
|
-
|
|
116
|
-
// Create internal signal for uncontrolled mode
|
|
117
|
-
// Initialize with defaultValue only (not value, which is for controlled mode)
|
|
118
|
-
const [internalValue, setInternalValue] = createSignal<string | null>(
|
|
119
|
-
initialProps.defaultValue ?? null
|
|
120
|
-
);
|
|
121
|
-
const [lastFocusedValue, setLastFocusedValueInternal] = createSignal<string | null>(null);
|
|
122
|
-
|
|
123
|
-
// SolidJS-specific: Version counter for triggering DOM sync across all radios
|
|
124
|
-
// This handles the case where native radio behavior causes DOM state to desync
|
|
125
|
-
// from our reactive state (e.g., clicking a radio unchecks siblings in the DOM)
|
|
126
|
-
const [syncVersion, setSyncVersion] = createSignal(0);
|
|
127
|
-
|
|
128
|
-
// Determine if controlled - must be reactive to handle dynamic props
|
|
129
|
-
const isControlled = () => getProps().value !== undefined;
|
|
130
|
-
|
|
131
|
-
// Get current value - reactive for both controlled and uncontrolled modes
|
|
132
|
-
const selectedValue: Accessor<string | null> = () => {
|
|
133
|
-
const p = getProps();
|
|
134
|
-
// In controlled mode, always read from props.value reactively
|
|
135
|
-
// In uncontrolled mode, read from internal signal
|
|
136
|
-
if (p.value !== undefined) {
|
|
137
|
-
return p.value ?? null;
|
|
138
|
-
}
|
|
139
|
-
return internalValue();
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
// Check if invalid
|
|
143
|
-
const isInvalid = () => {
|
|
144
|
-
return getProps().isInvalid ?? false;
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
// Set value
|
|
148
|
-
function setSelectedValue(value: string | null): void {
|
|
149
|
-
const p = getProps();
|
|
150
|
-
if (p.isReadOnly || p.isDisabled) {
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// Always increment syncVersion to trigger DOM sync across all radios
|
|
155
|
-
// This is crucial for SolidJS because:
|
|
156
|
-
// 1. Native radio behavior unchecks siblings when one is checked
|
|
157
|
-
// 2. In controlled mode, isSelected() may not change even though DOM changed
|
|
158
|
-
// 3. We need ALL radios to re-sync their checked state after any click
|
|
159
|
-
setSyncVersion((v) => v + 1);
|
|
160
|
-
|
|
161
|
-
if (!isControlled()) {
|
|
162
|
-
setInternalValue(value);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
if (value != null) {
|
|
166
|
-
p.onChange?.(value);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// Set last focused value
|
|
171
|
-
function setLastFocusedValue(value: string | null): void {
|
|
172
|
-
setLastFocusedValueInternal(value);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
const state: RadioGroupState = {
|
|
176
|
-
name,
|
|
177
|
-
selectedValue,
|
|
178
|
-
defaultSelectedValue: initialProps.defaultValue ?? null,
|
|
179
|
-
setSelectedValue,
|
|
180
|
-
lastFocusedValue,
|
|
181
|
-
setLastFocusedValue,
|
|
182
|
-
get isDisabled() {
|
|
183
|
-
return getProps().isDisabled ?? false;
|
|
184
|
-
},
|
|
185
|
-
get isReadOnly() {
|
|
186
|
-
return getProps().isReadOnly ?? false;
|
|
187
|
-
},
|
|
188
|
-
get isRequired() {
|
|
189
|
-
return getProps().isRequired ?? false;
|
|
190
|
-
},
|
|
191
|
-
get isInvalid() {
|
|
192
|
-
return isInvalid();
|
|
193
|
-
},
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
// Store syncVersion in internal WeakMap (not part of public API)
|
|
197
|
-
// This maintains API parity with React-Stately while supporting SolidJS's reactivity needs
|
|
198
|
-
radioGroupSyncVersion.set(state, syncVersion);
|
|
199
|
-
|
|
200
|
-
return state;
|
|
201
|
-
}
|
package/src/radio/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,qBAAqB,EACrB,KAAK,eAAe,EACpB,KAAK,eAAe,GACrB,MAAM,yBAAyB,CAAC"}
|
package/src/radio/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createSearchFieldState.d.ts","sourceRoot":"","sources":["createSearchFieldState.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,QAAQ,EAA4B,MAAM,UAAU,CAAC;AACnE,OAAO,EAAU,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AAEtD,MAAM,WAAW,qBAAqB;IACpC,sCAAsC;IACtC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wCAAwC;IACxC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,qDAAqD;IACrD,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACpC;AAED,MAAM,WAAW,gBAAgB;IAC/B,6CAA6C;IAC7C,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IACxB,0CAA0C;IAC1C,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACnC;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,aAAa,CAAC,qBAAqB,CAAC,GAC1C,gBAAgB,CAgClB"}
|