@widgetic/editor 4.1.14 → 4.1.15
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/dist/components/PreviewChromeControls.svelte +15 -21
- package/dist/components/WidgetPreview.svelte +136 -105
- package/dist/components/color-select/ColorSelect.svelte +203 -224
- package/dist/components/color-select/constants.d.ts +4 -2
- package/dist/components/color-select/constants.js +4 -2
- package/dist/components/color-select/render.js +10 -9
- package/dist/components/editors/CompositionEditorApp.svelte +47 -40
- package/dist/components/editors/EditLeaseNotice.svelte +44 -33
- package/dist/components/editors/EmbedEditor.svelte +133 -259
- package/dist/components/editors/PropsEditor.svelte +418 -1338
- package/dist/components/editors/props-editor.css +5 -68
- package/dist/components/ic/AngleInputController.svelte +202 -277
- package/dist/components/ic/BrowserInputController.svelte +813 -803
- package/dist/components/ic/CheckboxInputController.svelte +92 -169
- package/dist/components/ic/CheckboxInputController.svelte.d.ts +2 -8
- package/dist/components/ic/ColorPickerInputController.svelte +1589 -1587
- package/dist/components/ic/ColorPickerInputController.svelte.d.ts +3 -3
- package/dist/components/ic/DateFieldInputController.svelte +455 -465
- package/dist/components/ic/DatePickerInputController.svelte +355 -368
- package/dist/components/ic/DatePickerInputController.svelte.d.ts +1 -1
- package/dist/components/ic/DropdownInputController.svelte +130 -200
- package/dist/components/ic/FixedPositionInputController.svelte +255 -276
- package/dist/components/ic/FixedPositionInputController.svelte.d.ts +5 -1
- package/dist/components/ic/FontInputController.svelte +2110 -2231
- package/dist/components/ic/FontInputController.svelte.d.ts +11 -11
- package/dist/components/ic/InputControllerHeader.svelte +141 -147
- package/dist/components/ic/InputControllerRow.svelte +74 -0
- package/dist/components/ic/InputControllerRow.svelte.d.ts +14 -0
- package/dist/components/ic/KnowledgeDocumentsInputController.svelte +84 -47
- package/dist/components/ic/KnowledgeTextForm.svelte +35 -33
- package/dist/components/ic/NumberControls.svelte +303 -269
- package/dist/components/ic/NumberControls.svelte.d.ts +4 -1
- package/dist/components/ic/NumberInputController.svelte +361 -301
- package/dist/components/ic/NumberInputController.svelte.d.ts +2 -0
- package/dist/components/ic/PositionInputController.svelte +253 -176
- package/dist/components/ic/PositionInputController.svelte.d.ts +2 -0
- package/dist/components/ic/RadioGroupInputController.svelte +71 -137
- package/dist/components/ic/RadioGroupInputController.svelte.d.ts +2 -8
- package/dist/components/ic/RangeCalendarInputController.svelte +233 -270
- package/dist/components/ic/RangeCalendarInputController.svelte.d.ts +2 -2
- package/dist/components/ic/RoundedCornersInputController.svelte +412 -435
- package/dist/components/ic/RoundedCornersInputController.svelte.d.ts +2 -0
- package/dist/components/ic/SliderInputController.svelte +263 -332
- package/dist/components/ic/SliderInputController.svelte.d.ts +1 -1
- package/dist/components/ic/SliderRangeInputController.svelte +140 -144
- package/dist/components/ic/SliderRangeInputController.svelte.d.ts +3 -3
- package/dist/components/ic/SwitchInputController.svelte +47 -109
- package/dist/components/ic/TagsInputController.svelte +95 -110
- package/dist/components/ic/TextAreaInputController.svelte +1794 -1935
- package/dist/components/ic/TextAreaPreviewInputController.svelte +436 -438
- package/dist/components/ic/TextAreaPreviewInputController.svelte.d.ts +2 -2
- package/dist/components/ic/TextInputController.svelte +65 -75
- package/dist/components/ic/TextInputController.svelte.d.ts +2 -0
- package/dist/components/ic/TimeInputController.svelte +433 -431
- package/dist/components/ic/VectorInputController.svelte +1833 -1831
- package/dist/components/ic/VectorInputController.svelte.d.ts +10 -10
- package/dist/components/ic/index.d.ts +1 -0
- package/dist/components/ic/index.js +1 -0
- package/dist/components/ic/shared/CategoryTabs.svelte +28 -35
- package/dist/components/ic/shared/ItemGrid.svelte +145 -179
- package/dist/components/ic/shared/RecentItemsSection.svelte +208 -271
- package/dist/components/ic/shared/RecentItemsSection.svelte.d.ts +1 -1
- package/dist/components/ui/arrows/OpacitySliderArrows.svelte +23 -38
- package/dist/components/ui/arrows/OpacitySliderArrows.svelte.d.ts +1 -4
- package/dist/components/ui/calendar-editor-fit/EditorCalendarStyles.svelte +45 -0
- package/dist/components/ui/calendar-editor-fit/EditorCalendarStyles.svelte.d.ts +26 -0
- package/dist/components/ui/checkerboard-background/CheckerboardBackground.svelte +20 -12
- package/dist/components/ui/shadow-picker-host/ShadowPickerHost.svelte +39 -0
- package/dist/components/ui/shadow-picker-host/ShadowPickerHost.svelte.d.ts +10 -0
- package/dist/i18n/language.d.ts +43 -36
- package/dist/i18n/messages.d.ts +41 -34
- package/dist/i18n/messages.js +47 -34
- package/dist/i18n/translate.d.ts +1 -1
- package/dist/utils.d.ts +7 -0
- package/dist/utils.js +26 -2
- package/package.json +4 -4
|
@@ -1,20 +1,33 @@
|
|
|
1
1
|
<script module lang="ts">
|
|
2
|
-
|
|
2
|
+
import type { InputControllerConfig } from './index';
|
|
3
3
|
|
|
4
|
+
/** Declared props contract — export lets below are annotated from it so the
|
|
5
|
+
* interface cannot drift from what the component actually reads. */
|
|
4
6
|
/** Declared props contract — export lets below are annotated from it so the
|
|
5
7
|
* interface cannot drift from what the component actually reads. */
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
export interface NumberInputControllerProps {
|
|
9
|
+
label: string;
|
|
10
|
+
value?: number;
|
|
11
|
+
onChange: (newValue: number) => void;
|
|
12
|
+
config?: InputControllerConfig;
|
|
13
|
+
helpText?: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
onFocus?: () => void;
|
|
16
|
+
}
|
|
15
17
|
</script>
|
|
16
18
|
|
|
17
19
|
<script lang="ts">
|
|
20
|
+
/**
|
|
21
|
+
* NumberInputController Component
|
|
22
|
+
* A specialized input controller for numeric values with increment/decrement buttons.
|
|
23
|
+
* Features:
|
|
24
|
+
* - Increment/decrement buttons with auto-repeat
|
|
25
|
+
* - Value validation and bounds checking
|
|
26
|
+
* - Support for negative numbers
|
|
27
|
+
* - Keyboard navigation and shortcuts
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
// Svelte imports
|
|
18
31
|
/**
|
|
19
32
|
* NumberInputController Component
|
|
20
33
|
* A specialized input controller for numeric values with increment/decrement buttons.
|
|
@@ -24,128 +37,168 @@
|
|
|
24
37
|
* - Support for negative numbers
|
|
25
38
|
* - Keyboard navigation and shortcuts
|
|
26
39
|
*/
|
|
27
|
-
|
|
28
40
|
// Svelte imports
|
|
29
|
-
|
|
41
|
+
import { onDestroy } from 'svelte';
|
|
30
42
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
import NumberControls from './NumberControls.svelte';
|
|
43
|
+
import InputControllerRow from './InputControllerRow.svelte';
|
|
44
|
+
import NumberControls from './NumberControls.svelte';
|
|
34
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Component Props
|
|
48
|
+
* External properties that configure the number input's behavior
|
|
49
|
+
*/
|
|
35
50
|
/**
|
|
36
51
|
* Component Props
|
|
37
52
|
* External properties that configure the number input's behavior
|
|
38
53
|
*/
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
54
|
+
export let label: NumberInputControllerProps['label'];
|
|
55
|
+
export let value: NumberInputControllerProps['value'] = 0;
|
|
56
|
+
export let onChange: NumberInputControllerProps['onChange'];
|
|
57
|
+
export let config: NumberInputControllerProps['config'] = {};
|
|
58
|
+
export let helpText: NumberInputControllerProps['helpText'] = undefined;
|
|
59
|
+
export let description: NumberInputControllerProps['description'] = undefined;
|
|
60
|
+
export let onFocus: NumberInputControllerProps['onFocus'] = () => {};
|
|
46
61
|
|
|
62
|
+
/**
|
|
63
|
+
* Configuration Options
|
|
64
|
+
* Derived from config prop with fallbacks.
|
|
65
|
+
* When both min and max are unspecified, the input is unbounded (not locked).
|
|
66
|
+
*/
|
|
47
67
|
/**
|
|
48
68
|
* Configuration Options
|
|
49
69
|
* Derived from config prop with fallbacks.
|
|
50
70
|
* When both min and max are unspecified, the input is unbounded (not locked).
|
|
51
71
|
*/
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
72
|
+
const bothBoundsUndefined = config.min === undefined && config.max === undefined;
|
|
73
|
+
$: min = config.min ?? 0;
|
|
74
|
+
$: max = bothBoundsUndefined ? Number.MAX_SAFE_INTEGER : (config.max ?? 0);
|
|
75
|
+
$: step = config.step || 1;
|
|
76
|
+
$: isLocked = !bothBoundsUndefined && min === max;
|
|
77
|
+
$: isAtMin = value <= min;
|
|
78
|
+
$: isAtMax = value >= max;
|
|
59
79
|
|
|
80
|
+
/**
|
|
81
|
+
* Reactive Statements
|
|
82
|
+
* Handle min/max validation and value constraints
|
|
83
|
+
*/
|
|
84
|
+
/**
|
|
85
|
+
* Step Validation
|
|
86
|
+
* Ensures step value is always positive
|
|
87
|
+
*/
|
|
60
88
|
/**
|
|
61
89
|
* Reactive Statements
|
|
62
90
|
* Handle min/max validation and value constraints
|
|
63
91
|
*/
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
92
|
+
$: {
|
|
93
|
+
if (min !== undefined && max !== undefined && min > max) {
|
|
94
|
+
[min, max] = [max, min];
|
|
95
|
+
}
|
|
68
96
|
|
|
69
|
-
|
|
70
|
-
|
|
97
|
+
const minValue = min ?? 0;
|
|
98
|
+
const maxValue = max ?? Number.MAX_SAFE_INTEGER;
|
|
71
99
|
|
|
72
|
-
|
|
73
|
-
|
|
100
|
+
if (!isEditing && !bothBoundsUndefined) {
|
|
101
|
+
if (value < minValue || value > maxValue) {
|
|
102
|
+
// console.log('Value out of bounds, adjusting:', {
|
|
103
|
+
// value, minValue, maxValue, isEditing
|
|
104
|
+
// });
|
|
74
105
|
// console.log('Value out of bounds, adjusting:', {
|
|
75
106
|
// value, minValue, maxValue, isEditing
|
|
76
107
|
// });
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
108
|
+
const clampedValue = Math.max(minValue, Math.min(maxValue, value));
|
|
109
|
+
value = clampedValue;
|
|
110
|
+
if (typeof onChange === 'function') {
|
|
111
|
+
setTimeout(() => onChange(clampedValue), 0);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
85
116
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
117
|
+
/**
|
|
118
|
+
* Step Validation
|
|
119
|
+
* Ensures step value is always positive
|
|
120
|
+
*/
|
|
121
|
+
$: {
|
|
122
|
+
if (step < 0) {
|
|
123
|
+
console.warn('Step value should be positive. Converting negative step to positive.');
|
|
124
|
+
step = Math.abs(step);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
96
127
|
|
|
128
|
+
/**
|
|
129
|
+
* Internal State
|
|
130
|
+
* Manages component behavior and auto-repeat functionality
|
|
131
|
+
*/
|
|
97
132
|
/**
|
|
98
133
|
* Internal State
|
|
99
134
|
* Manages component behavior and auto-repeat functionality
|
|
100
135
|
*/
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
136
|
+
let autoRepeatTimer: ReturnType<typeof setTimeout> | undefined;
|
|
137
|
+
let autoRepeatInterval: ReturnType<typeof setInterval> | undefined;
|
|
138
|
+
let isPressed = false;
|
|
139
|
+
// console.log('handleBlur:', { value, isEditing, min, max });
|
|
140
|
+
let isEditing = false; // Tracks if user is currently editing the input
|
|
141
|
+
let disabledOpacity = 60;
|
|
142
|
+
const HOLD_DELAY = 400;
|
|
143
|
+
const REPEAT_INTERVAL = 80;
|
|
108
144
|
|
|
145
|
+
/**
|
|
146
|
+
* Value Change Handler
|
|
147
|
+
* Processes increment/decrement operations with bounds checking
|
|
148
|
+
*/
|
|
109
149
|
/**
|
|
110
150
|
* Value Change Handler
|
|
111
151
|
* Processes increment/decrement operations with bounds checking
|
|
112
152
|
*/
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
if (max !== undefined && newValue > max) {
|
|
126
|
-
// console.log('⚠️ Value would exceed max, clamping to:', max);
|
|
127
|
-
value = max;
|
|
128
|
-
if (onChange) onChange(max);
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// console.log('✅ Setting new value:', newValue);
|
|
133
|
-
value = newValue;
|
|
134
|
-
if (onChange) onChange(newValue);
|
|
135
|
-
} catch (error) {
|
|
136
|
-
console.error('❌ Error in handleValueChange:', error);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
153
|
+
function handleValueChange(adjustment: number) {
|
|
154
|
+
try {
|
|
155
|
+
// console.log('🔄 handleValueChange:', { currentValue: value, adjustment, min, max });
|
|
156
|
+
const newValue = value + adjustment;
|
|
157
|
+
|
|
158
|
+
if (min !== undefined && newValue < min) {
|
|
159
|
+
// console.log('⚠️ Value would go below min, clamping to:', min);
|
|
160
|
+
value = min;
|
|
161
|
+
if (onChange) onChange(min);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
139
164
|
|
|
165
|
+
if (max !== undefined && newValue > max) {
|
|
166
|
+
// console.log('⚠️ Value would exceed max, clamping to:', max);
|
|
167
|
+
value = max;
|
|
168
|
+
if (onChange) onChange(max);
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// console.log('✅ Setting new value:', newValue);
|
|
173
|
+
value = newValue;
|
|
174
|
+
if (onChange) onChange(newValue);
|
|
175
|
+
} catch (error) {
|
|
176
|
+
console.error('❌ Error in handleValueChange:', error);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Input Event Handler
|
|
182
|
+
* Manages direct user input with validation
|
|
183
|
+
*/
|
|
140
184
|
/**
|
|
141
185
|
* Input Event Handler
|
|
142
186
|
* Manages direct user input with validation
|
|
143
187
|
*/
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
188
|
+
function handleInput(e: Event) {
|
|
189
|
+
try {
|
|
190
|
+
const input = e.currentTarget as HTMLInputElement;
|
|
191
|
+
const inputValue = input.value;
|
|
192
|
+
|
|
193
|
+
// console.log('handleInput start:', {
|
|
194
|
+
// inputValue,
|
|
195
|
+
// isEditing,
|
|
196
|
+
// currentValue: value,
|
|
197
|
+
// min,
|
|
198
|
+
// max
|
|
199
|
+
// });
|
|
200
|
+
|
|
201
|
+
// Handle empty input
|
|
149
202
|
// console.log('handleInput start:', {
|
|
150
203
|
// inputValue,
|
|
151
204
|
// isEditing,
|
|
@@ -153,261 +206,268 @@
|
|
|
153
206
|
// min,
|
|
154
207
|
// max
|
|
155
208
|
// });
|
|
156
|
-
|
|
157
209
|
// Handle empty input
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// Prevent multiple minus signs
|
|
165
|
-
if (inputValue.split('-').length > 2) {
|
|
166
|
-
// console.log('Multiple minus signs detected, preventing');
|
|
167
|
-
input.value = inputValue.charAt(0) === '-' ?
|
|
168
|
-
'-' + inputValue.replace(/-/g, '') :
|
|
169
|
-
inputValue.replace(/-/g, '');
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// Allow single minus sign for negative numbers
|
|
174
|
-
if (inputValue === '-' && min! < 0) {
|
|
210
|
+
if (inputValue === '') {
|
|
211
|
+
// console.log('Empty input detected - allowing editing');
|
|
212
|
+
// console.log('CMD+A detected, setting editing mode');
|
|
175
213
|
// console.log('Single minus sign detected');
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
214
|
+
// console.log('Empty input detected - allowing editing');
|
|
215
|
+
isEditing = true;
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// Prevent multiple minus signs
|
|
220
|
+
if (inputValue.split('-').length > 2) {
|
|
221
|
+
// console.log('Multiple minus signs detected, preventing');
|
|
222
|
+
input.value =
|
|
223
|
+
inputValue.charAt(0) === '-'
|
|
224
|
+
? '-' + inputValue.replace(/-/g, '')
|
|
225
|
+
: inputValue.replace(/-/g, '');
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// Allow single minus sign for negative numbers
|
|
230
|
+
if (inputValue === '-' && min! < 0) {
|
|
231
|
+
// console.log('Single minus sign detected');
|
|
232
|
+
isEditing = true;
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// Validate numeric input
|
|
237
|
+
if (!/^-?\d*$/.test(inputValue)) {
|
|
238
|
+
// console.log('Invalid character detected');
|
|
239
|
+
input.value = inputValue.replace(/[^\d-]/g, '');
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const numValue = parseFloat(inputValue);
|
|
244
|
+
if (!isNaN(numValue)) {
|
|
245
|
+
if (max !== undefined && numValue > max) {
|
|
246
|
+
// console.log('Number exceeds max:', { numValue, max });
|
|
247
|
+
input.value = String(max);
|
|
248
|
+
value = max;
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
value = numValue;
|
|
252
|
+
}
|
|
253
|
+
} catch (error) {
|
|
254
|
+
console.error('Error in handleInput:', error);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
201
257
|
|
|
258
|
+
/**
|
|
259
|
+
* Blur Event Handler
|
|
260
|
+
* Validates and normalizes input when focus is lost
|
|
261
|
+
*/
|
|
202
262
|
/**
|
|
203
263
|
* Blur Event Handler
|
|
204
264
|
* Validates and normalizes input when focus is lost
|
|
205
265
|
*/
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
266
|
+
function handleBlur(event: FocusEvent) {
|
|
267
|
+
// console.log('handleBlur:', { value, isEditing, min, max });
|
|
268
|
+
|
|
269
|
+
isEditing = false;
|
|
270
|
+
// The input that lost the focus. (It used to be looked up by the id "number-input" in the whole document, which is
|
|
271
|
+
// another input when there are several, and nothing inside a module's shadow root.)
|
|
210
272
|
// The input that lost the focus. (It used to be looked up by the id "number-input" in the whole document, which is
|
|
211
273
|
// another input when there are several, and nothing inside a module's shadow root.)
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
// Validate and clamp final value
|
|
223
|
-
const finalValue = parseFloat(input.value);
|
|
224
|
-
if (isNaN(finalValue)) {
|
|
225
|
-
value = min!;
|
|
226
|
-
input.value = String(min!);
|
|
227
|
-
if (onChange) onChange(min!);
|
|
228
|
-
} else if (finalValue < min!) {
|
|
229
|
-
value = min!;
|
|
230
|
-
input.value = String(min!);
|
|
231
|
-
if (onChange) onChange(min!);
|
|
232
|
-
} else if (finalValue > max!) {
|
|
233
|
-
value = max!;
|
|
234
|
-
input.value = String(max!);
|
|
235
|
-
if (onChange) onChange(max!);
|
|
236
|
-
} else {
|
|
237
|
-
value = finalValue;
|
|
238
|
-
if (onChange) onChange(finalValue);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
274
|
+
const input = event.currentTarget as HTMLInputElement;
|
|
275
|
+
|
|
276
|
+
// Handle empty or invalid input
|
|
277
|
+
if (input.value === '' || input.value === '-') {
|
|
278
|
+
value = min!;
|
|
279
|
+
input.value = String(min!);
|
|
280
|
+
if (onChange) onChange(min!);
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
241
283
|
|
|
284
|
+
// Validate and clamp final value
|
|
285
|
+
const finalValue = parseFloat(input.value);
|
|
286
|
+
if (isNaN(finalValue)) {
|
|
287
|
+
value = min!;
|
|
288
|
+
input.value = String(min!);
|
|
289
|
+
if (onChange) onChange(min!);
|
|
290
|
+
} else if (finalValue < min!) {
|
|
291
|
+
value = min!;
|
|
292
|
+
input.value = String(min!);
|
|
293
|
+
if (onChange) onChange(min!);
|
|
294
|
+
} else if (finalValue > max!) {
|
|
295
|
+
value = max!;
|
|
296
|
+
input.value = String(max!);
|
|
297
|
+
if (onChange) onChange(max!);
|
|
298
|
+
} else {
|
|
299
|
+
value = finalValue;
|
|
300
|
+
if (onChange) onChange(finalValue);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Auto-Repeat Functionality
|
|
306
|
+
* Handles continuous increment/decrement while button is held
|
|
307
|
+
*/
|
|
242
308
|
/**
|
|
243
309
|
* Auto-Repeat Functionality
|
|
244
310
|
* Handles continuous increment/decrement while button is held
|
|
245
311
|
*/
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
312
|
+
function startAutoRepeat(operation: 'increment' | 'decrement', event: MouseEvent) {
|
|
313
|
+
// console.log('🎯 startAutoRepeat called:', { operation });
|
|
314
|
+
event.preventDefault();
|
|
315
|
+
event.stopPropagation();
|
|
316
|
+
|
|
317
|
+
// Clear any existing timers first
|
|
318
|
+
// console.log('♻️ Component destroying, cleaning up timers');
|
|
251
319
|
// Clear any existing timers first
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
320
|
+
stopAutoRepeat();
|
|
321
|
+
|
|
322
|
+
const adjustment = operation === 'increment' ? step : -step;
|
|
323
|
+
isPressed = true;
|
|
324
|
+
|
|
325
|
+
// Handle initial click
|
|
326
|
+
// console.log('👆 Initial click, applying adjustment:', adjustment);
|
|
327
|
+
// console.log('⚡ Interval tick - applying adjustment:', adjustment);
|
|
257
328
|
// Handle initial click
|
|
258
329
|
// console.log('👆 Initial click, applying adjustment:', adjustment);
|
|
259
|
-
|
|
260
|
-
|
|
330
|
+
handleValueChange(adjustment);
|
|
331
|
+
|
|
332
|
+
// Set up auto-repeat
|
|
333
|
+
// console.log('⏳ Setting up auto-repeat timer for', HOLD_DELAY, 'ms');
|
|
334
|
+
|
|
335
|
+
// Start auto-repeat after hold delay
|
|
261
336
|
// Set up auto-repeat
|
|
262
337
|
// console.log('⏳ Setting up auto-repeat timer for', HOLD_DELAY, 'ms');
|
|
263
|
-
|
|
264
338
|
// Start auto-repeat after hold delay
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
339
|
+
autoRepeatTimer = setTimeout(() => {
|
|
340
|
+
// console.log('⌛ Hold delay completed, isPressed:', isPressed);
|
|
341
|
+
if (isPressed) {
|
|
342
|
+
// console.log('🔄 Starting interval timer with delay:', REPEAT_INTERVAL);
|
|
343
|
+
autoRepeatInterval = setInterval(() => {
|
|
344
|
+
if (isPressed) {
|
|
345
|
+
// console.log('⚡ Interval tick - applying adjustment:', adjustment);
|
|
346
|
+
handleValueChange(adjustment);
|
|
347
|
+
}
|
|
348
|
+
}, REPEAT_INTERVAL);
|
|
349
|
+
}
|
|
350
|
+
}, HOLD_DELAY);
|
|
351
|
+
}
|
|
278
352
|
|
|
353
|
+
/**
|
|
354
|
+
* Stop Auto-Repeat
|
|
355
|
+
* Cleans up auto-repeat timer and interval
|
|
356
|
+
*/
|
|
279
357
|
/**
|
|
280
358
|
* Stop Auto-Repeat
|
|
281
359
|
* Cleans up auto-repeat timer and interval
|
|
282
360
|
*/
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
361
|
+
function stopAutoRepeat(event?: MouseEvent | FocusEvent) {
|
|
362
|
+
if (event) {
|
|
363
|
+
event.preventDefault();
|
|
364
|
+
event.stopPropagation();
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// console.log('🛑 stopAutoRepeat called');
|
|
368
|
+
|
|
289
369
|
// console.log('🛑 stopAutoRepeat called');
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
}
|
|
370
|
+
if (autoRepeatTimer) {
|
|
371
|
+
// console.log('🧹 Clearing auto-repeat timer');
|
|
372
|
+
clearTimeout(autoRepeatTimer);
|
|
373
|
+
autoRepeatTimer = undefined;
|
|
374
|
+
}
|
|
375
|
+
if (autoRepeatInterval) {
|
|
376
|
+
// console.log('🧹 Clearing auto-repeat interval');
|
|
377
|
+
clearInterval(autoRepeatInterval);
|
|
378
|
+
autoRepeatInterval = undefined;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
isPressed = false;
|
|
382
|
+
}
|
|
304
383
|
|
|
384
|
+
/**
|
|
385
|
+
* Cleanup
|
|
386
|
+
* Ensures auto-repeat timer is cleared when component is destroyed
|
|
387
|
+
*/
|
|
305
388
|
/**
|
|
306
389
|
* Cleanup
|
|
307
390
|
* Ensures auto-repeat timer is cleared when component is destroyed
|
|
308
391
|
*/
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
392
|
+
onDestroy(() => {
|
|
393
|
+
// console.log('♻️ Component destroying, cleaning up timers');
|
|
394
|
+
stopAutoRepeat();
|
|
395
|
+
});
|
|
313
396
|
|
|
397
|
+
/**
|
|
398
|
+
* Input Validation
|
|
399
|
+
* Validates numeric input format
|
|
400
|
+
*/
|
|
314
401
|
/**
|
|
315
402
|
* Input Validation
|
|
316
403
|
* Validates numeric input format
|
|
317
404
|
*/
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
405
|
+
function isValidNumber(value: string): boolean {
|
|
406
|
+
// Allow empty string during typing
|
|
407
|
+
if (value === '') return true;
|
|
408
|
+
// Allow single minus sign during typing if negatives are allowed
|
|
409
|
+
if (value === '-' && (min === undefined || min < 0)) return true;
|
|
410
|
+
|
|
411
|
+
// Strict number format validation
|
|
412
|
+
const numberRegex = /^-?\d*\.?\d*$/;
|
|
413
|
+
if (!numberRegex.test(value)) return false;
|
|
414
|
+
// Prevent multiple decimal points
|
|
415
|
+
if ((value.match(/\./g) || []).length > 1) return false;
|
|
416
|
+
// Prevent multiple minus signs
|
|
417
|
+
if ((value.match(/-/g) || []).length > 1) return false;
|
|
418
|
+
|
|
419
|
+
return true;
|
|
420
|
+
}
|
|
334
421
|
|
|
422
|
+
/**
|
|
423
|
+
* Keyboard Event Handler
|
|
424
|
+
* Manages keyboard interactions and shortcuts
|
|
425
|
+
*/
|
|
335
426
|
/**
|
|
336
427
|
* Keyboard Event Handler
|
|
337
428
|
* Manages keyboard interactions and shortcuts
|
|
338
429
|
*/
|
|
339
|
-
|
|
430
|
+
function handleKeyDown(e: KeyboardEvent) {
|
|
431
|
+
// console.log('handleKeyDown:', {
|
|
432
|
+
// key: e.key,
|
|
433
|
+
// metaKey: e.metaKey,
|
|
434
|
+
// ctrlKey: e.ctrlKey,
|
|
435
|
+
// isEditing
|
|
436
|
+
// });
|
|
437
|
+
|
|
438
|
+
// Handle selection shortcuts
|
|
340
439
|
// console.log('handleKeyDown:', {
|
|
341
440
|
// key: e.key,
|
|
342
441
|
// metaKey: e.metaKey,
|
|
343
442
|
// ctrlKey: e.ctrlKey,
|
|
344
443
|
// isEditing
|
|
345
444
|
// });
|
|
346
|
-
|
|
347
445
|
// Handle selection shortcuts
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
446
|
+
if ((e.metaKey || e.ctrlKey) && e.key === 'a') {
|
|
447
|
+
// console.log('CMD+A detected, setting editing mode');
|
|
448
|
+
isEditing = true;
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// Allow navigation keys
|
|
453
|
+
if (
|
|
454
|
+
e.key === 'Backspace' ||
|
|
455
|
+
e.key === 'Delete' ||
|
|
456
|
+
e.key === 'ArrowLeft' ||
|
|
457
|
+
e.key === 'ArrowRight' ||
|
|
458
|
+
e.key === 'Tab'
|
|
459
|
+
) {
|
|
460
|
+
isEditing = true;
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
// Allow copy/paste operations
|
|
465
|
+
if (e.metaKey || e.ctrlKey) {
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
367
469
|
</script>
|
|
368
470
|
|
|
369
|
-
|
|
370
|
-
<
|
|
371
|
-
|
|
372
|
-
<div class="flex-1 min-w-0">
|
|
373
|
-
<InputControllerHeader {label} helpText={helpText} />
|
|
374
|
-
</div>
|
|
375
|
-
|
|
376
|
-
<div class="absolute end-0">
|
|
377
|
-
<NumberControls
|
|
378
|
-
{value}
|
|
379
|
-
{onChange}
|
|
380
|
-
{min}
|
|
381
|
-
{max}
|
|
382
|
-
{step}
|
|
383
|
-
{isLocked}
|
|
384
|
-
{onFocus}
|
|
385
|
-
/>
|
|
386
|
-
</div>
|
|
387
|
-
</div>
|
|
388
|
-
|
|
389
|
-
{#if description}
|
|
390
|
-
<p class="subtext text-grey5">{description}</p>
|
|
391
|
-
{/if}
|
|
392
|
-
</div>
|
|
393
|
-
|
|
394
|
-
<style>
|
|
395
|
-
:global(#number-input) {
|
|
396
|
-
text-align: start;
|
|
397
|
-
appearance: textfield;
|
|
398
|
-
-moz-appearance: textfield;
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
:global(#number-input::-webkit-outer-spin-button),
|
|
402
|
-
:global(#number-input::-webkit-inner-spin-button) {
|
|
403
|
-
-webkit-appearance: none;
|
|
404
|
-
appearance: none;
|
|
405
|
-
margin: 0;
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
/* Remove focus ring from buttons */
|
|
409
|
-
:global(.number-input-button:focus-visible) {
|
|
410
|
-
outline: none !important;
|
|
411
|
-
box-shadow: none !important;
|
|
412
|
-
}
|
|
413
|
-
</style>
|
|
471
|
+
<InputControllerRow {label} {helpText} {description}>
|
|
472
|
+
<NumberControls {value} {onChange} {min} {max} {step} {isLocked} {onFocus} />
|
|
473
|
+
</InputControllerRow>
|