@widgetic/editor 4.1.13 → 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 +55 -40
- package/dist/components/editors/EditLeaseNotice.svelte +44 -33
- package/dist/components/editors/EmbedEditor.svelte +133 -259
- package/dist/components/editors/PropsEditor.svelte +426 -1333
- 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/InputControllerRenderer.svelte +5 -1
- package/dist/components/ic/InputControllerRenderer.svelte.d.ts +2 -1
- package/dist/components/ic/InputControllerRow.svelte +74 -0
- package/dist/components/ic/InputControllerRow.svelte.d.ts +14 -0
- package/dist/components/ic/KnowledgeDocumentsInputController.svelte +401 -0
- package/dist/components/ic/KnowledgeDocumentsInputController.svelte.d.ts +11 -0
- package/dist/components/ic/KnowledgeTextForm.svelte +109 -0
- package/dist/components/ic/KnowledgeTextForm.svelte.d.ts +15 -0
- 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 +2 -0
- package/dist/components/ic/index.js +2 -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/composition/compositionApi.d.ts +21 -1
- package/dist/composition/compositionApi.js +64 -5
- package/dist/composition/knowledgeDocuments.d.ts +90 -0
- package/dist/composition/knowledgeDocuments.js +94 -0
- package/dist/composition/knowledgeDocumentsPanel.d.ts +152 -0
- package/dist/composition/knowledgeDocumentsPanel.js +443 -0
- package/dist/i18n/language.d.ts +86 -36
- package/dist/i18n/messages.d.ts +97 -34
- package/dist/i18n/messages.js +104 -34
- package/dist/i18n/translate.d.ts +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/knowledgeDocumentsContext.d.ts +10 -0
- package/dist/knowledgeDocumentsContext.js +31 -0
- package/dist/utils.d.ts +7 -0
- package/dist/utils.js +26 -2
- package/package.json +4 -4
|
@@ -12,476 +12,466 @@
|
|
|
12
12
|
-->
|
|
13
13
|
|
|
14
14
|
<script module lang="ts">
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
15
|
+
import type { InputControllerConfig } from './index';
|
|
16
|
+
|
|
17
|
+
/** Declared props contract — export lets below are annotated from it so the
|
|
18
|
+
* interface cannot drift from what the component actually reads. */
|
|
19
|
+
export interface DateFieldInputControllerProps {
|
|
20
|
+
label: string;
|
|
21
|
+
value: { day: number; month: number; year: number };
|
|
22
|
+
onChange: (newValue: { day: number; month: number; year: number }) => void;
|
|
23
|
+
config?: InputControllerConfig;
|
|
24
|
+
helpText?: string;
|
|
25
|
+
onFocus?: () => void;
|
|
26
|
+
}
|
|
27
27
|
</script>
|
|
28
28
|
|
|
29
29
|
<script lang="ts">
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
30
|
+
import { onMount, tick } from 'svelte';
|
|
31
|
+
import InputControllerRow from './InputControllerRow.svelte';
|
|
32
|
+
import { activeElementIn } from '../../utils/shadowDom';
|
|
33
|
+
import { useEditorLanguage } from '../../i18n/language';
|
|
34
|
+
import type { EditorMessageKey } from '../../i18n/messages';
|
|
35
|
+
import { useTextDirection } from '@widgetic/design-system/components/textDirection';
|
|
36
|
+
|
|
37
|
+
// The words of the editor in the language of the page.
|
|
38
|
+
const { t } = useEditorLanguage();
|
|
39
|
+
|
|
40
|
+
// The way the screen is read: the row of fields turns around with it, and so do the keys that move from one field to the next.
|
|
41
|
+
const textDirection = useTextDirection();
|
|
42
|
+
|
|
43
|
+
// Constants
|
|
44
|
+
const MIN_DAY = 1;
|
|
45
|
+
const MAX_DAY = 31;
|
|
46
|
+
const MIN_MONTH = 1;
|
|
47
|
+
const MAX_MONTH = 12;
|
|
48
|
+
const MIN_YEAR = 1900;
|
|
49
|
+
const MAX_YEAR = 2100;
|
|
50
|
+
|
|
51
|
+
// Required props
|
|
52
|
+
export let label: DateFieldInputControllerProps['label'];
|
|
53
|
+
export let value: DateFieldInputControllerProps['value'];
|
|
54
|
+
export let onChange: DateFieldInputControllerProps['onChange'];
|
|
55
|
+
export let config: DateFieldInputControllerProps['config'] = {};
|
|
56
|
+
export let helpText: DateFieldInputControllerProps['helpText'] = undefined;
|
|
57
|
+
export let onFocus: DateFieldInputControllerProps['onFocus'] = () => {};
|
|
58
|
+
|
|
59
|
+
// Optional: Class prop for external styling
|
|
60
|
+
let className = '';
|
|
61
|
+
export { className as class };
|
|
62
|
+
|
|
63
|
+
// Configure field order - default to day-month-year, can be overridden in config
|
|
64
|
+
const FORMAT_DMY = 'day-month-year';
|
|
65
|
+
const FORMAT_MDY = 'month-day-year';
|
|
66
|
+
const FORMAT_YMD = 'year-month-day';
|
|
67
|
+
|
|
68
|
+
let format = config.format || FORMAT_DMY;
|
|
69
|
+
let fieldOrder = getFieldOrder(format);
|
|
70
|
+
|
|
71
|
+
// Internal state
|
|
72
|
+
let day = value?.day || '';
|
|
73
|
+
let month = value?.month || '';
|
|
74
|
+
let year = value?.year || '';
|
|
75
|
+
let focusedField: 'day' | 'month' | 'year' | null = null;
|
|
76
|
+
let hasInitialValues = false;
|
|
77
|
+
|
|
78
|
+
// Reference to the input elements
|
|
79
|
+
let inputRefs: { day?: HTMLInputElement; month?: HTMLInputElement; year?: HTMLInputElement } = {};
|
|
80
|
+
|
|
81
|
+
// Get field order based on format
|
|
82
|
+
function getFieldOrder(format: string): ('day' | 'month' | 'year')[] {
|
|
83
|
+
switch (format) {
|
|
84
|
+
case FORMAT_DMY:
|
|
85
|
+
return ['day', 'month', 'year'];
|
|
86
|
+
case FORMAT_MDY:
|
|
87
|
+
return ['month', 'day', 'year'];
|
|
88
|
+
case FORMAT_YMD:
|
|
89
|
+
return ['year', 'month', 'day'];
|
|
90
|
+
default:
|
|
91
|
+
return ['day', 'month', 'year'];
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Set initial values from prop
|
|
96
|
+
onMount(() => {
|
|
97
|
+
if (value) {
|
|
98
|
+
day = value.day || '';
|
|
99
|
+
month = value.month || '';
|
|
100
|
+
year = value.year || '';
|
|
101
|
+
hasInitialValues = true;
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// Get field configuration. The hint in a box and its name for a screen reader are messages (`hintKey`, `labelKey`).
|
|
106
|
+
function getFieldConfig(field: 'day' | 'month' | 'year') {
|
|
107
|
+
const configs: Record<
|
|
108
|
+
'day' | 'month' | 'year',
|
|
109
|
+
{
|
|
110
|
+
min: number;
|
|
111
|
+
max: number;
|
|
112
|
+
hintKey: EditorMessageKey;
|
|
113
|
+
labelKey: EditorMessageKey;
|
|
114
|
+
width: string;
|
|
115
|
+
maxLength: number;
|
|
116
|
+
}
|
|
117
|
+
> = {
|
|
118
|
+
day: {
|
|
119
|
+
min: MIN_DAY,
|
|
120
|
+
max: MAX_DAY,
|
|
121
|
+
hintKey: 'editor.dateField.dayHint',
|
|
122
|
+
labelKey: 'editor.dateField.dayLabel',
|
|
123
|
+
width: '40px',
|
|
124
|
+
maxLength: 2
|
|
125
|
+
},
|
|
126
|
+
month: {
|
|
127
|
+
min: MIN_MONTH,
|
|
128
|
+
max: MAX_MONTH,
|
|
129
|
+
hintKey: 'editor.dateField.monthHint',
|
|
130
|
+
labelKey: 'editor.dateField.monthLabel',
|
|
131
|
+
width: '40px',
|
|
132
|
+
maxLength: 2
|
|
133
|
+
},
|
|
134
|
+
year: {
|
|
135
|
+
min: MIN_YEAR,
|
|
136
|
+
max: MAX_YEAR,
|
|
137
|
+
hintKey: 'editor.dateField.yearHint',
|
|
138
|
+
labelKey: 'editor.dateField.yearLabel',
|
|
139
|
+
width: '60px',
|
|
140
|
+
maxLength: 4
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
return configs[field];
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Helper function to focus on next field
|
|
147
|
+
async function focusNextField(currentField: 'day' | 'month' | 'year') {
|
|
148
|
+
const currentIndex = fieldOrder.indexOf(currentField);
|
|
149
|
+
if (currentIndex < fieldOrder.length - 1) {
|
|
150
|
+
const nextField = fieldOrder[currentIndex + 1];
|
|
151
|
+
await tick();
|
|
152
|
+
inputRefs[nextField]?.focus();
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Helper function to focus on previous field
|
|
157
|
+
async function focusPreviousField(currentField: 'day' | 'month' | 'year') {
|
|
158
|
+
const currentIndex = fieldOrder.indexOf(currentField);
|
|
159
|
+
if (currentIndex > 0) {
|
|
160
|
+
const prevField = fieldOrder[currentIndex - 1];
|
|
161
|
+
await tick();
|
|
162
|
+
inputRefs[prevField]?.focus();
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Validate and set day value
|
|
167
|
+
function handleDayInput(e: Event) {
|
|
168
|
+
const input = e.target as HTMLInputElement;
|
|
169
|
+
let inputValue = input.value;
|
|
170
|
+
|
|
171
|
+
// Handle empty input
|
|
172
|
+
if (inputValue === '') {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Remove non-numeric characters
|
|
177
|
+
inputValue = inputValue.replace(/[^\d]/g, '');
|
|
178
|
+
|
|
179
|
+
// Handle leading zeros - normalize to single 0
|
|
180
|
+
if (inputValue.length > 1 && inputValue.startsWith('0')) {
|
|
181
|
+
inputValue = inputValue.substring(1);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Parse as number
|
|
185
|
+
const numValue = parseInt(inputValue);
|
|
186
|
+
|
|
187
|
+
// If value is too large, cap at max (31)
|
|
188
|
+
if (numValue > MAX_DAY) {
|
|
189
|
+
inputValue = MAX_DAY.toString();
|
|
190
|
+
input.value = inputValue;
|
|
191
|
+
} else {
|
|
192
|
+
input.value = inputValue;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
day = inputValue === '' ? '' : parseInt(inputValue);
|
|
196
|
+
|
|
197
|
+
// Auto-advance to next field when 2 digits are entered
|
|
198
|
+
if (inputValue.length >= 2 && parseInt(inputValue) > 0) {
|
|
199
|
+
focusNextField('day');
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Validate and set month value
|
|
204
|
+
function handleMonthInput(e: Event) {
|
|
205
|
+
const input = e.target as HTMLInputElement;
|
|
206
|
+
let inputValue = input.value;
|
|
207
|
+
|
|
208
|
+
// Handle empty input
|
|
209
|
+
if (inputValue === '') {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// Remove non-numeric characters
|
|
214
|
+
inputValue = inputValue.replace(/[^\d]/g, '');
|
|
215
|
+
|
|
216
|
+
// Handle leading zeros - normalize to single 0
|
|
217
|
+
if (inputValue.length > 1 && inputValue.startsWith('0')) {
|
|
218
|
+
inputValue = inputValue.substring(1);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// Parse as number
|
|
222
|
+
const numValue = parseInt(inputValue);
|
|
223
|
+
|
|
224
|
+
// If value is too large, cap at max (12)
|
|
225
|
+
if (numValue > MAX_MONTH) {
|
|
226
|
+
inputValue = MAX_MONTH.toString();
|
|
227
|
+
input.value = inputValue;
|
|
228
|
+
} else {
|
|
229
|
+
input.value = inputValue;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
month = inputValue === '' ? '' : parseInt(inputValue);
|
|
233
|
+
|
|
234
|
+
// Auto-advance to next field when 2 digits are entered
|
|
235
|
+
if (inputValue.length >= 2 && parseInt(inputValue) > 0) {
|
|
236
|
+
focusNextField('month');
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// Validate and set year value
|
|
241
|
+
function handleYearInput(e: Event) {
|
|
242
|
+
const input = e.target as HTMLInputElement;
|
|
243
|
+
let inputValue = input.value;
|
|
244
|
+
|
|
245
|
+
// Handle empty input
|
|
246
|
+
if (inputValue === '') {
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// Remove non-numeric characters
|
|
251
|
+
inputValue = inputValue.replace(/[^\d]/g, '');
|
|
252
|
+
|
|
253
|
+
// Handle leading zeros
|
|
254
|
+
if (inputValue.length > 1 && inputValue.startsWith('0')) {
|
|
255
|
+
inputValue = inputValue.substring(1);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// Enforce max length of 4
|
|
259
|
+
if (inputValue.length > 4) {
|
|
260
|
+
inputValue = inputValue.substring(0, 4);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const numValue = parseInt(inputValue);
|
|
264
|
+
|
|
265
|
+
// If value is too large, cap at max
|
|
266
|
+
if (numValue > MAX_YEAR) {
|
|
267
|
+
inputValue = MAX_YEAR.toString();
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
input.value = inputValue;
|
|
271
|
+
year = inputValue === '' ? '' : parseInt(inputValue);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// Handle input changes
|
|
275
|
+
function handleChange() {
|
|
276
|
+
// Only update if we have valid values for all fields
|
|
277
|
+
if (
|
|
278
|
+
day !== '' &&
|
|
279
|
+
month !== '' &&
|
|
280
|
+
year !== '' &&
|
|
281
|
+
!isNaN(Number(day)) &&
|
|
282
|
+
!isNaN(Number(month)) &&
|
|
283
|
+
!isNaN(Number(year))
|
|
284
|
+
) {
|
|
285
|
+
onChange({
|
|
286
|
+
day: Number(day),
|
|
287
|
+
month: Number(month),
|
|
288
|
+
year: Number(year)
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// Handle focus
|
|
294
|
+
function handleFocus(field: 'day' | 'month' | 'year') {
|
|
295
|
+
focusedField = field;
|
|
296
|
+
onFocus();
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// Handle blur
|
|
300
|
+
function handleBlur(field: 'day' | 'month' | 'year') {
|
|
301
|
+
const input = inputRefs[field];
|
|
302
|
+
|
|
303
|
+
if (!input) return;
|
|
304
|
+
|
|
305
|
+
// If empty, display as empty
|
|
306
|
+
if (input.value === '') {
|
|
307
|
+
if (field === 'day') day = '';
|
|
308
|
+
if (field === 'month') month = '';
|
|
309
|
+
if (field === 'year') year = '';
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// Otherwise, ensure we have a valid number
|
|
314
|
+
let min: number, max: number;
|
|
315
|
+
|
|
316
|
+
if (field === 'day') {
|
|
317
|
+
min = MIN_DAY;
|
|
318
|
+
max = MAX_DAY;
|
|
319
|
+
const numDay = parseInt(input.value);
|
|
320
|
+
day = Math.max(min, Math.min(max, numDay));
|
|
321
|
+
input.value = day.toString();
|
|
322
|
+
} else if (field === 'month') {
|
|
323
|
+
min = MIN_MONTH;
|
|
324
|
+
max = MAX_MONTH;
|
|
325
|
+
const numMonth = parseInt(input.value);
|
|
326
|
+
month = Math.max(min, Math.min(max, numMonth));
|
|
327
|
+
input.value = month.toString();
|
|
328
|
+
} else if (field === 'year') {
|
|
329
|
+
min = MIN_YEAR;
|
|
330
|
+
max = MAX_YEAR;
|
|
331
|
+
const numYear = parseInt(input.value);
|
|
332
|
+
year = Math.max(min, Math.min(max, numYear));
|
|
333
|
+
input.value = year.toString();
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// Trigger change if we have all values
|
|
337
|
+
handleChange();
|
|
338
|
+
|
|
339
|
+
// Reset focused field after a short delay to allow for focus changes
|
|
340
|
+
setTimeout(() => {
|
|
341
|
+
// The focused element of the tree this control is in: inside a module `document.activeElement` is the module's
|
|
342
|
+
// host element, which is never one of the fields
|
|
343
|
+
const focusedElement = activeElementIn(input);
|
|
344
|
+
if (
|
|
345
|
+
!focusedElement ||
|
|
346
|
+
!(focusedElement instanceof HTMLInputElement) ||
|
|
347
|
+
!Object.values(inputRefs).includes(focusedElement)
|
|
348
|
+
) {
|
|
349
|
+
focusedField = null;
|
|
350
|
+
}
|
|
351
|
+
}, 100);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// Handle keydown events
|
|
355
|
+
function handleKeyDown(field: 'day' | 'month' | 'year', e: KeyboardEvent) {
|
|
356
|
+
const input = e.target as HTMLInputElement;
|
|
357
|
+
|
|
358
|
+
// Allow selection shortcuts (Ctrl+A)
|
|
359
|
+
if ((e.metaKey || e.ctrlKey) && e.key === 'a') {
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// Allow editing keys (Backspace, Delete)
|
|
364
|
+
if (e.key === 'Backspace' || e.key === 'Delete') {
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// Handle arrow navigation. The digits of a field run left to right on every screen, so the key that leaves a field at the
|
|
369
|
+
// right end of its digits is ArrowRight on every screen, and what lies on that side is the next field on a left to right
|
|
370
|
+
// screen and the one before it on a right to left one (where the row of fields starts on the right).
|
|
371
|
+
if (e.key === 'ArrowRight') {
|
|
372
|
+
if (input.selectionStart === input.value.length) {
|
|
373
|
+
e.preventDefault();
|
|
374
|
+
if ($textDirection === 'rtl') focusPreviousField(field);
|
|
375
|
+
else focusNextField(field);
|
|
376
|
+
}
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
if (e.key === 'ArrowLeft') {
|
|
381
|
+
if (input.selectionStart === 0) {
|
|
382
|
+
e.preventDefault();
|
|
383
|
+
if ($textDirection === 'rtl') focusNextField(field);
|
|
384
|
+
else focusPreviousField(field);
|
|
385
|
+
}
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// Handle Tab navigation
|
|
390
|
+
if (e.key === 'Tab') {
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// Prevent non-numeric inputs except navigation and editing keys
|
|
395
|
+
if (
|
|
396
|
+
!/^\d$/.test(e.key) &&
|
|
397
|
+
!['Backspace', 'Delete', 'ArrowLeft', 'ArrowRight', 'Tab', 'Enter'].includes(e.key) &&
|
|
398
|
+
!(e.ctrlKey || e.metaKey)
|
|
399
|
+
) {
|
|
400
|
+
e.preventDefault();
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
// Prevent leading zeros
|
|
405
|
+
if (e.key === '0' && input.value === '') {
|
|
406
|
+
e.preventDefault();
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
function segmentHasValue(field: 'day' | 'month' | 'year'): boolean {
|
|
412
|
+
const raw = field === 'day' ? day : field === 'month' ? month : year;
|
|
413
|
+
return raw !== '' && raw !== undefined && raw !== null;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/** Get field-specific CSS classes (placeholder vs filled segment). */
|
|
417
|
+
function segmentInputClass(field: 'day' | 'month' | 'year'): string {
|
|
418
|
+
return segmentHasValue(field)
|
|
419
|
+
? 'text-body text-foreground'
|
|
420
|
+
: 'text-body text-muted-foreground placeholder:text-muted-foreground';
|
|
421
|
+
}
|
|
414
422
|
</script>
|
|
415
423
|
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
424
|
+
<!-- Date field container -->
|
|
425
|
+
<div class="date-field-container {className}" on:focusin={onFocus}>
|
|
426
|
+
<InputControllerRow {label} {helpText}>
|
|
427
|
+
<!-- Focus states: focus-within ring on the soft control surface -->
|
|
428
|
+
<div
|
|
429
|
+
class="date-field-control flex h-9 w-full items-center justify-center gap-2 rounded-lg bg-accent px-3 transition-colors duration-fast hover:bg-accent-hover focus-within:outline-hidden focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2 focus-within:ring-offset-background"
|
|
430
|
+
>
|
|
431
|
+
{#each fieldOrder as field}
|
|
432
|
+
{@const config = getFieldConfig(field)}
|
|
433
|
+
<input
|
|
434
|
+
type="text"
|
|
435
|
+
inputmode="numeric"
|
|
436
|
+
pattern="[0-9]*"
|
|
437
|
+
bind:this={inputRefs[field]}
|
|
438
|
+
value={field === 'day' ? day : field === 'month' ? month : year}
|
|
439
|
+
placeholder={$t(config.hintKey)}
|
|
440
|
+
on:input={field === 'day'
|
|
441
|
+
? handleDayInput
|
|
442
|
+
: field === 'month'
|
|
443
|
+
? handleMonthInput
|
|
444
|
+
: handleYearInput}
|
|
445
|
+
on:change={handleChange}
|
|
446
|
+
on:focus={() => handleFocus(field)}
|
|
447
|
+
on:blur={() => handleBlur(field)}
|
|
448
|
+
on:keydown={(e) => handleKeyDown(field, e)}
|
|
449
|
+
class="date-field-segment h-full shrink-0 bg-transparent text-center focus:outline-hidden {segmentInputClass(
|
|
450
|
+
field
|
|
451
|
+
)}"
|
|
452
|
+
style="width: {config.width};"
|
|
453
|
+
aria-label={$t(config.labelKey)}
|
|
454
|
+
maxlength={config.maxLength}
|
|
455
|
+
/>
|
|
456
|
+
|
|
457
|
+
{#if field !== fieldOrder[fieldOrder.length - 1]}
|
|
458
|
+
<!-- Separator style -->
|
|
459
|
+
<span class="date-separator text-body text-muted-foreground" aria-hidden="true">/</span>
|
|
460
|
+
{/if}
|
|
461
|
+
{/each}
|
|
462
|
+
</div>
|
|
463
|
+
</InputControllerRow>
|
|
455
464
|
</div>
|
|
456
465
|
|
|
457
466
|
<style>
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
/* Date field container */
|
|
471
|
-
.date-field-container {
|
|
472
|
-
position: relative;
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
/* Separator style */
|
|
476
|
-
.date-separator {
|
|
477
|
-
font-size: 14px;
|
|
478
|
-
line-height: 1.5;
|
|
479
|
-
font-weight: 400;
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
:global(.subtext) {
|
|
483
|
-
font-size: 14px;
|
|
484
|
-
line-height: 1.5;
|
|
485
|
-
font-weight: 400;
|
|
486
|
-
}
|
|
487
|
-
</style>
|
|
467
|
+
.date-field-segment {
|
|
468
|
+
-moz-appearance: textfield;
|
|
469
|
+
appearance: textfield;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
.date-field-segment::-webkit-outer-spin-button,
|
|
473
|
+
.date-field-segment::-webkit-inner-spin-button {
|
|
474
|
+
appearance: none;
|
|
475
|
+
margin: 0;
|
|
476
|
+
}
|
|
477
|
+
</style>
|