@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.
Files changed (89) hide show
  1. package/dist/components/PreviewChromeControls.svelte +15 -21
  2. package/dist/components/WidgetPreview.svelte +136 -105
  3. package/dist/components/color-select/ColorSelect.svelte +203 -224
  4. package/dist/components/color-select/constants.d.ts +4 -2
  5. package/dist/components/color-select/constants.js +4 -2
  6. package/dist/components/color-select/render.js +10 -9
  7. package/dist/components/editors/CompositionEditorApp.svelte +55 -40
  8. package/dist/components/editors/EditLeaseNotice.svelte +44 -33
  9. package/dist/components/editors/EmbedEditor.svelte +133 -259
  10. package/dist/components/editors/PropsEditor.svelte +426 -1333
  11. package/dist/components/editors/props-editor.css +5 -68
  12. package/dist/components/ic/AngleInputController.svelte +202 -277
  13. package/dist/components/ic/BrowserInputController.svelte +813 -803
  14. package/dist/components/ic/CheckboxInputController.svelte +92 -169
  15. package/dist/components/ic/CheckboxInputController.svelte.d.ts +2 -8
  16. package/dist/components/ic/ColorPickerInputController.svelte +1589 -1587
  17. package/dist/components/ic/ColorPickerInputController.svelte.d.ts +3 -3
  18. package/dist/components/ic/DateFieldInputController.svelte +455 -465
  19. package/dist/components/ic/DatePickerInputController.svelte +355 -368
  20. package/dist/components/ic/DatePickerInputController.svelte.d.ts +1 -1
  21. package/dist/components/ic/DropdownInputController.svelte +130 -200
  22. package/dist/components/ic/FixedPositionInputController.svelte +255 -276
  23. package/dist/components/ic/FixedPositionInputController.svelte.d.ts +5 -1
  24. package/dist/components/ic/FontInputController.svelte +2110 -2231
  25. package/dist/components/ic/FontInputController.svelte.d.ts +11 -11
  26. package/dist/components/ic/InputControllerHeader.svelte +141 -147
  27. package/dist/components/ic/InputControllerRenderer.svelte +5 -1
  28. package/dist/components/ic/InputControllerRenderer.svelte.d.ts +2 -1
  29. package/dist/components/ic/InputControllerRow.svelte +74 -0
  30. package/dist/components/ic/InputControllerRow.svelte.d.ts +14 -0
  31. package/dist/components/ic/KnowledgeDocumentsInputController.svelte +401 -0
  32. package/dist/components/ic/KnowledgeDocumentsInputController.svelte.d.ts +11 -0
  33. package/dist/components/ic/KnowledgeTextForm.svelte +109 -0
  34. package/dist/components/ic/KnowledgeTextForm.svelte.d.ts +15 -0
  35. package/dist/components/ic/NumberControls.svelte +303 -269
  36. package/dist/components/ic/NumberControls.svelte.d.ts +4 -1
  37. package/dist/components/ic/NumberInputController.svelte +361 -301
  38. package/dist/components/ic/NumberInputController.svelte.d.ts +2 -0
  39. package/dist/components/ic/PositionInputController.svelte +253 -176
  40. package/dist/components/ic/PositionInputController.svelte.d.ts +2 -0
  41. package/dist/components/ic/RadioGroupInputController.svelte +71 -137
  42. package/dist/components/ic/RadioGroupInputController.svelte.d.ts +2 -8
  43. package/dist/components/ic/RangeCalendarInputController.svelte +233 -270
  44. package/dist/components/ic/RangeCalendarInputController.svelte.d.ts +2 -2
  45. package/dist/components/ic/RoundedCornersInputController.svelte +412 -435
  46. package/dist/components/ic/RoundedCornersInputController.svelte.d.ts +2 -0
  47. package/dist/components/ic/SliderInputController.svelte +263 -332
  48. package/dist/components/ic/SliderInputController.svelte.d.ts +1 -1
  49. package/dist/components/ic/SliderRangeInputController.svelte +140 -144
  50. package/dist/components/ic/SliderRangeInputController.svelte.d.ts +3 -3
  51. package/dist/components/ic/SwitchInputController.svelte +47 -109
  52. package/dist/components/ic/TagsInputController.svelte +95 -110
  53. package/dist/components/ic/TextAreaInputController.svelte +1794 -1935
  54. package/dist/components/ic/TextAreaPreviewInputController.svelte +436 -438
  55. package/dist/components/ic/TextAreaPreviewInputController.svelte.d.ts +2 -2
  56. package/dist/components/ic/TextInputController.svelte +65 -75
  57. package/dist/components/ic/TextInputController.svelte.d.ts +2 -0
  58. package/dist/components/ic/TimeInputController.svelte +433 -431
  59. package/dist/components/ic/VectorInputController.svelte +1833 -1831
  60. package/dist/components/ic/VectorInputController.svelte.d.ts +10 -10
  61. package/dist/components/ic/index.d.ts +2 -0
  62. package/dist/components/ic/index.js +2 -0
  63. package/dist/components/ic/shared/CategoryTabs.svelte +28 -35
  64. package/dist/components/ic/shared/ItemGrid.svelte +145 -179
  65. package/dist/components/ic/shared/RecentItemsSection.svelte +208 -271
  66. package/dist/components/ic/shared/RecentItemsSection.svelte.d.ts +1 -1
  67. package/dist/components/ui/arrows/OpacitySliderArrows.svelte +23 -38
  68. package/dist/components/ui/arrows/OpacitySliderArrows.svelte.d.ts +1 -4
  69. package/dist/components/ui/calendar-editor-fit/EditorCalendarStyles.svelte +45 -0
  70. package/dist/components/ui/calendar-editor-fit/EditorCalendarStyles.svelte.d.ts +26 -0
  71. package/dist/components/ui/checkerboard-background/CheckerboardBackground.svelte +20 -12
  72. package/dist/components/ui/shadow-picker-host/ShadowPickerHost.svelte +39 -0
  73. package/dist/components/ui/shadow-picker-host/ShadowPickerHost.svelte.d.ts +10 -0
  74. package/dist/composition/compositionApi.d.ts +21 -1
  75. package/dist/composition/compositionApi.js +64 -5
  76. package/dist/composition/knowledgeDocuments.d.ts +90 -0
  77. package/dist/composition/knowledgeDocuments.js +94 -0
  78. package/dist/composition/knowledgeDocumentsPanel.d.ts +152 -0
  79. package/dist/composition/knowledgeDocumentsPanel.js +443 -0
  80. package/dist/i18n/language.d.ts +86 -36
  81. package/dist/i18n/messages.d.ts +97 -34
  82. package/dist/i18n/messages.js +104 -34
  83. package/dist/i18n/translate.d.ts +1 -1
  84. package/dist/index.d.ts +1 -0
  85. package/dist/knowledgeDocumentsContext.d.ts +10 -0
  86. package/dist/knowledgeDocumentsContext.js +31 -0
  87. package/dist/utils.d.ts +7 -0
  88. package/dist/utils.js +26 -2
  89. package/package.json +4 -4
@@ -12,476 +12,466 @@
12
12
  -->
13
13
 
14
14
  <script module lang="ts">
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
- }
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
- import { onMount, tick } from 'svelte';
31
- import InputControllerHeader from './InputControllerHeader.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<'day' | 'month' | 'year', { min: number; max: number; hintKey: EditorMessageKey; labelKey: EditorMessageKey; width: string; maxLength: number }> = {
108
- day: {
109
- min: MIN_DAY,
110
- max: MAX_DAY,
111
- hintKey: 'editor.dateField.dayHint',
112
- labelKey: 'editor.dateField.dayLabel',
113
- width: '40px',
114
- maxLength: 2
115
- },
116
- month: {
117
- min: MIN_MONTH,
118
- max: MAX_MONTH,
119
- hintKey: 'editor.dateField.monthHint',
120
- labelKey: 'editor.dateField.monthLabel',
121
- width: '40px',
122
- maxLength: 2
123
- },
124
- year: {
125
- min: MIN_YEAR,
126
- max: MAX_YEAR,
127
- hintKey: 'editor.dateField.yearHint',
128
- labelKey: 'editor.dateField.yearLabel',
129
- width: '60px',
130
- maxLength: 4
131
- }
132
- };
133
- return configs[field];
134
- }
135
-
136
- // Helper function to focus on next field
137
- async function focusNextField(currentField: 'day' | 'month' | 'year') {
138
- const currentIndex = fieldOrder.indexOf(currentField);
139
- if (currentIndex < fieldOrder.length - 1) {
140
- const nextField = fieldOrder[currentIndex + 1];
141
- await tick();
142
- inputRefs[nextField]?.focus();
143
- }
144
- }
145
-
146
- // Helper function to focus on previous field
147
- async function focusPreviousField(currentField: 'day' | 'month' | 'year') {
148
- const currentIndex = fieldOrder.indexOf(currentField);
149
- if (currentIndex > 0) {
150
- const prevField = fieldOrder[currentIndex - 1];
151
- await tick();
152
- inputRefs[prevField]?.focus();
153
- }
154
- }
155
-
156
- // Validate and set day value
157
- function handleDayInput(e: Event) {
158
- const input = e.target as HTMLInputElement;
159
- let inputValue = input.value;
160
-
161
- // Handle empty input
162
- if (inputValue === '') {
163
- return;
164
- }
165
-
166
- // Remove non-numeric characters
167
- inputValue = inputValue.replace(/[^\d]/g, '');
168
-
169
- // Handle leading zeros - normalize to single 0
170
- if (inputValue.length > 1 && inputValue.startsWith('0')) {
171
- inputValue = inputValue.substring(1);
172
- }
173
-
174
- // Parse as number
175
- const numValue = parseInt(inputValue);
176
-
177
- // If value is too large, cap at max (31)
178
- if (numValue > MAX_DAY) {
179
- inputValue = MAX_DAY.toString();
180
- input.value = inputValue;
181
- } else {
182
- input.value = inputValue;
183
- }
184
-
185
- day = inputValue === '' ? '' : parseInt(inputValue);
186
-
187
- // Auto-advance to next field when 2 digits are entered
188
- if (inputValue.length >= 2 && parseInt(inputValue) > 0) {
189
- focusNextField('day');
190
- }
191
- }
192
-
193
- // Validate and set month value
194
- function handleMonthInput(e: Event) {
195
- const input = e.target as HTMLInputElement;
196
- let inputValue = input.value;
197
-
198
- // Handle empty input
199
- if (inputValue === '') {
200
- return;
201
- }
202
-
203
- // Remove non-numeric characters
204
- inputValue = inputValue.replace(/[^\d]/g, '');
205
-
206
- // Handle leading zeros - normalize to single 0
207
- if (inputValue.length > 1 && inputValue.startsWith('0')) {
208
- inputValue = inputValue.substring(1);
209
- }
210
-
211
- // Parse as number
212
- const numValue = parseInt(inputValue);
213
-
214
- // If value is too large, cap at max (12)
215
- if (numValue > MAX_MONTH) {
216
- inputValue = MAX_MONTH.toString();
217
- input.value = inputValue;
218
- } else {
219
- input.value = inputValue;
220
- }
221
-
222
- month = inputValue === '' ? '' : parseInt(inputValue);
223
-
224
- // Auto-advance to next field when 2 digits are entered
225
- if (inputValue.length >= 2 && parseInt(inputValue) > 0) {
226
- focusNextField('month');
227
- }
228
- }
229
-
230
- // Validate and set year value
231
- function handleYearInput(e: Event) {
232
- const input = e.target as HTMLInputElement;
233
- let inputValue = input.value;
234
-
235
- // Handle empty input
236
- if (inputValue === '') {
237
- return;
238
- }
239
-
240
- // Remove non-numeric characters
241
- inputValue = inputValue.replace(/[^\d]/g, '');
242
-
243
- // Handle leading zeros
244
- if (inputValue.length > 1 && inputValue.startsWith('0')) {
245
- inputValue = inputValue.substring(1);
246
- }
247
-
248
- // Enforce max length of 4
249
- if (inputValue.length > 4) {
250
- inputValue = inputValue.substring(0, 4);
251
- }
252
-
253
- const numValue = parseInt(inputValue);
254
-
255
- // If value is too large, cap at max
256
- if (numValue > MAX_YEAR) {
257
- inputValue = MAX_YEAR.toString();
258
- }
259
-
260
- input.value = inputValue;
261
- year = inputValue === '' ? '' : parseInt(inputValue);
262
- }
263
-
264
- // Handle input changes
265
- function handleChange() {
266
- // Only update if we have valid values for all fields
267
- if (
268
- day !== '' && month !== '' && year !== '' &&
269
- !isNaN(Number(day)) && !isNaN(Number(month)) && !isNaN(Number(year))
270
- ) {
271
- onChange({
272
- day: Number(day),
273
- month: Number(month),
274
- year: Number(year)
275
- });
276
- }
277
- }
278
-
279
- // Handle focus
280
- function handleFocus(field: 'day' | 'month' | 'year') {
281
- focusedField = field;
282
- onFocus();
283
- }
284
-
285
- // Handle blur
286
- function handleBlur(field: 'day' | 'month' | 'year') {
287
- const input = inputRefs[field];
288
-
289
- if (!input) return;
290
-
291
- // If empty, display as empty
292
- if (input.value === '') {
293
- if (field === 'day') day = '';
294
- if (field === 'month') month = '';
295
- if (field === 'year') year = '';
296
- return;
297
- }
298
-
299
- // Otherwise, ensure we have a valid number
300
- let min: number, max: number;
301
-
302
- if (field === 'day') {
303
- min = MIN_DAY;
304
- max = MAX_DAY;
305
- const numDay = parseInt(input.value);
306
- day = Math.max(min, Math.min(max, numDay));
307
- input.value = day.toString();
308
- } else if (field === 'month') {
309
- min = MIN_MONTH;
310
- max = MAX_MONTH;
311
- const numMonth = parseInt(input.value);
312
- month = Math.max(min, Math.min(max, numMonth));
313
- input.value = month.toString();
314
- } else if (field === 'year') {
315
- min = MIN_YEAR;
316
- max = MAX_YEAR;
317
- const numYear = parseInt(input.value);
318
- year = Math.max(min, Math.min(max, numYear));
319
- input.value = year.toString();
320
- }
321
-
322
- // Trigger change if we have all values
323
- handleChange();
324
-
325
- // Reset focused field after a short delay to allow for focus changes
326
- setTimeout(() => {
327
- // The focused element of the tree this control is in: inside a module `document.activeElement` is the module's
328
- // host element, which is never one of the fields
329
- const focusedElement = activeElementIn(input);
330
- if (!focusedElement ||
331
- !(focusedElement instanceof HTMLInputElement) ||
332
- !Object.values(inputRefs).includes(focusedElement)) {
333
- focusedField = null;
334
- }
335
- }, 100);
336
- }
337
-
338
- // Handle keydown events
339
- function handleKeyDown(field: 'day' | 'month' | 'year', e: KeyboardEvent) {
340
- const input = e.target as HTMLInputElement;
341
-
342
- // Allow selection shortcuts (Ctrl+A)
343
- if ((e.metaKey || e.ctrlKey) && e.key === 'a') {
344
- return;
345
- }
346
-
347
- // Allow editing keys (Backspace, Delete)
348
- if (e.key === 'Backspace' || e.key === 'Delete') {
349
- return;
350
- }
351
-
352
- // Handle arrow navigation. The digits of a field run left to right on every screen, so the key that leaves a field at the
353
- // 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
354
- // screen and the one before it on a right to left one (where the row of fields starts on the right).
355
- if (e.key === 'ArrowRight') {
356
- if (input.selectionStart === input.value.length) {
357
- e.preventDefault();
358
- if ($textDirection === 'rtl') focusPreviousField(field);
359
- else focusNextField(field);
360
- }
361
- return;
362
- }
363
-
364
- if (e.key === 'ArrowLeft') {
365
- if (input.selectionStart === 0) {
366
- e.preventDefault();
367
- if ($textDirection === 'rtl') focusNextField(field);
368
- else focusPreviousField(field);
369
- }
370
- return;
371
- }
372
-
373
- // Handle Tab navigation
374
- if (e.key === 'Tab') {
375
- return;
376
- }
377
-
378
- // Prevent non-numeric inputs except navigation and editing keys
379
- if (!/^\d$/.test(e.key) &&
380
- !['Backspace', 'Delete', 'ArrowLeft', 'ArrowRight', 'Tab', 'Enter'].includes(e.key) &&
381
- !(e.ctrlKey || e.metaKey)) {
382
- e.preventDefault();
383
- return;
384
- }
385
-
386
- // Prevent leading zeros
387
- if (e.key === '0' && input.value === '') {
388
- e.preventDefault();
389
- return;
390
- }
391
- }
392
-
393
- // Get field-specific CSS classes
394
- function getFieldClasses(field: 'day' | 'month' | 'year') {
395
- return {
396
- container: `
397
- relative
398
- ${focusedField === field ? 'bg-sage-green' : 'bg-grey1'}
399
- transition-colors
400
- rounded-small
401
- `,
402
- input: `
403
- w-full
404
- h-full
405
- bg-transparent
406
- text-center
407
- focus:outline-none
408
- subtext
409
- ${focusedField === field ? 'text-white' : 'text-grey7'}
410
- placeholder:text-grey3
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
- <div class="date-field-container widgetic-colors {className}" on:focusin={onFocus}>
417
- <div class="flex items-center w-full relative">
418
- <div class="flex-1 min-w-0">
419
- <InputControllerHeader {label} {helpText} />
420
- </div>
421
-
422
- <div class="absolute end-0">
423
- <div class="h-[48px] w-[185px] rounded-large border border-grey2 bg-grey1 flex items-center transition-colors duration-200 hover:border-forest-green">
424
- <div class="flex items-center justify-between px-4 w-full">
425
- {#each fieldOrder as field}
426
- {@const config = getFieldConfig(field)}
427
-
428
- <div class={getFieldClasses(field).container} style="width: {config.width}; min-height: 34px;">
429
- <input
430
- type="text"
431
- inputmode="numeric"
432
- pattern="[0-9]*"
433
- bind:this={inputRefs[field]}
434
- value={field === 'day' ? day : field === 'month' ? month : year}
435
- placeholder={$t(config.hintKey)}
436
- on:input={field === 'day' ? handleDayInput : field === 'month' ? handleMonthInput : handleYearInput}
437
- on:change={handleChange}
438
- on:focus={() => handleFocus(field)}
439
- on:blur={() => handleBlur(field)}
440
- on:keydown={(e) => handleKeyDown(field, e)}
441
- class={getFieldClasses(field).input}
442
- aria-label={$t(config.labelKey)}
443
- maxlength={config.maxLength}
444
- />
445
- </div>
446
-
447
- {#if field !== fieldOrder[fieldOrder.length - 1]}
448
- <span class="date-separator subtext text-grey3">/</span>
449
- {/if}
450
- {/each}
451
- </div>
452
- </div>
453
- </div>
454
- </div>
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
- input {
459
- -moz-appearance: textfield;
460
- appearance: textfield;
461
- padding: 8px 4px;
462
- font-size: 16px;
463
- }
464
-
465
- /* Focus states */
466
- input:focus {
467
- outline: none !important;
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>