@widgetic/editor 4.1.14 → 4.1.16

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 (76) 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 +47 -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 +418 -1338
  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/InputControllerRow.svelte +74 -0
  28. package/dist/components/ic/InputControllerRow.svelte.d.ts +14 -0
  29. package/dist/components/ic/KnowledgeDocumentsInputController.svelte +84 -47
  30. package/dist/components/ic/KnowledgeTextForm.svelte +35 -33
  31. package/dist/components/ic/NumberControls.svelte +303 -269
  32. package/dist/components/ic/NumberControls.svelte.d.ts +4 -1
  33. package/dist/components/ic/NumberInputController.svelte +361 -301
  34. package/dist/components/ic/NumberInputController.svelte.d.ts +2 -0
  35. package/dist/components/ic/PositionInputController.svelte +253 -176
  36. package/dist/components/ic/PositionInputController.svelte.d.ts +2 -0
  37. package/dist/components/ic/RadioGroupInputController.svelte +71 -137
  38. package/dist/components/ic/RadioGroupInputController.svelte.d.ts +2 -8
  39. package/dist/components/ic/RangeCalendarInputController.svelte +233 -270
  40. package/dist/components/ic/RangeCalendarInputController.svelte.d.ts +2 -2
  41. package/dist/components/ic/RoundedCornersInputController.svelte +412 -435
  42. package/dist/components/ic/RoundedCornersInputController.svelte.d.ts +2 -0
  43. package/dist/components/ic/SliderInputController.svelte +263 -332
  44. package/dist/components/ic/SliderInputController.svelte.d.ts +1 -1
  45. package/dist/components/ic/SliderRangeInputController.svelte +140 -144
  46. package/dist/components/ic/SliderRangeInputController.svelte.d.ts +3 -3
  47. package/dist/components/ic/SwitchInputController.svelte +47 -109
  48. package/dist/components/ic/TagsInputController.svelte +95 -110
  49. package/dist/components/ic/TextAreaInputController.svelte +1794 -1935
  50. package/dist/components/ic/TextAreaPreviewInputController.svelte +436 -438
  51. package/dist/components/ic/TextAreaPreviewInputController.svelte.d.ts +2 -2
  52. package/dist/components/ic/TextInputController.svelte +65 -75
  53. package/dist/components/ic/TextInputController.svelte.d.ts +2 -0
  54. package/dist/components/ic/TimeInputController.svelte +433 -431
  55. package/dist/components/ic/VectorInputController.svelte +1833 -1831
  56. package/dist/components/ic/VectorInputController.svelte.d.ts +10 -10
  57. package/dist/components/ic/index.d.ts +1 -0
  58. package/dist/components/ic/index.js +1 -0
  59. package/dist/components/ic/shared/CategoryTabs.svelte +28 -35
  60. package/dist/components/ic/shared/ItemGrid.svelte +145 -179
  61. package/dist/components/ic/shared/RecentItemsSection.svelte +208 -271
  62. package/dist/components/ic/shared/RecentItemsSection.svelte.d.ts +1 -1
  63. package/dist/components/ui/arrows/OpacitySliderArrows.svelte +23 -38
  64. package/dist/components/ui/arrows/OpacitySliderArrows.svelte.d.ts +1 -4
  65. package/dist/components/ui/calendar-editor-fit/EditorCalendarStyles.svelte +45 -0
  66. package/dist/components/ui/calendar-editor-fit/EditorCalendarStyles.svelte.d.ts +26 -0
  67. package/dist/components/ui/checkerboard-background/CheckerboardBackground.svelte +20 -12
  68. package/dist/components/ui/shadow-picker-host/ShadowPickerHost.svelte +39 -0
  69. package/dist/components/ui/shadow-picker-host/ShadowPickerHost.svelte.d.ts +10 -0
  70. package/dist/i18n/language.d.ts +44 -281
  71. package/dist/i18n/messages.d.ts +41 -34
  72. package/dist/i18n/messages.js +47 -34
  73. package/dist/i18n/translate.d.ts +1 -1
  74. package/dist/utils.d.ts +7 -0
  75. package/dist/utils.js +26 -2
  76. package/package.json +5 -5
@@ -18,380 +18,367 @@
18
18
  -->
19
19
 
20
20
  <script module lang="ts">
21
- import type { Writable } from 'svelte/store';
22
-
23
- /** Declared props contract — export lets below are annotated from it so the
24
- * interface cannot drift from what the component actually reads. */
25
- export interface DatePickerInputControllerProps {
26
- label: string;
27
- value?: any;
28
- onChange: (newValue: CalendarDate) => void;
29
- description?: string;
30
- controllerId: string;
31
- openDropdowns: Writable<Set<string>>;
32
- toggleDropdown: (id: string) => void;
33
- onFocus?: () => void;
34
- }
21
+ import type { Writable } from 'svelte/store';
22
+
23
+ /** Declared props contract — export lets below are annotated from it so the
24
+ * interface cannot drift from what the component actually reads. */
25
+ export interface DatePickerInputControllerProps {
26
+ label: string;
27
+ value?: any;
28
+ onChange: (newValue: CalendarDate) => void;
29
+ description?: string;
30
+ controllerId: string;
31
+ openDropdowns: Writable<Set<string>>;
32
+ toggleDropdown: (id: string) => void;
33
+ onFocus?: () => void;
34
+ }
35
35
  </script>
36
36
 
37
37
  <script lang="ts">
38
- // Svelte imports
39
- import { onMount, onDestroy } from 'svelte';
40
- import { listenForScroll } from '../../utils/shadowDom';
41
- import { useEditorLanguage } from '../../i18n/language';
42
- import type { EditorMessageKey } from '../../i18n/messages';
43
- import type { Translate } from '@widgetic/design-system/i18n';
44
-
45
- // The words of the editor in the language of the page, and the language itself (how a month and a date are written).
46
- const { t, locale } = useEditorLanguage();
47
-
48
- // Shadcn UI Components
49
- import { Button, Select } from '@widgetic/design-system/components';
50
- import { Popover } from '@widgetic/design-system/components';
51
- import { InputControllerHeader } from './index';
52
- import { Calendar } from '@widgetic/design-system/components';
53
-
54
- // Internationalized date imports
55
- import { CalendarDate, getLocalTimeZone, today, DateFormatter } from "@internationalized/date";
56
- import type { DateValue } from "@internationalized/date";
57
-
58
- // Lucide Icons
59
- import { IconCalendar } from '@widgetic/design-system/icons';
60
-
61
- // Component props with TypeScript types
62
- export let label: DatePickerInputControllerProps['label'];
63
- export let value: DatePickerInputControllerProps['value'];
64
- export let onChange: DatePickerInputControllerProps['onChange'];
65
- export let description: DatePickerInputControllerProps['description'] = undefined;
66
- export let controllerId: DatePickerInputControllerProps['controllerId'];
67
- export let openDropdowns: DatePickerInputControllerProps['openDropdowns'];
68
- export let toggleDropdown: DatePickerInputControllerProps['toggleDropdown'];
69
- export let onFocus: DatePickerInputControllerProps['onFocus'] = () => {};
70
-
71
- // Default to today's date in local timezone for placeholder
72
- let placeholder = today(getLocalTimeZone());
73
- let currentValue: CalendarDate | undefined;
74
-
75
- // Month and year options setup: the names of the months are written by the language of the page
76
- $: monthFmt = new DateFormatter($locale, { month: 'long' });
77
- $: monthOptions = Array.from({ length: 12 }, (_, monthIndex) => ({
78
- value: String(monthIndex + 1),
79
- label: monthFmt.format(new Date(2021, monthIndex, 1))
80
- }));
81
-
82
- const yearOptions = Array.from({ length: 100 }, (_, i) => {
83
- const year = String(new Date().getFullYear() - i);
84
- return { label: year, value: year };
85
- });
86
-
87
- $: defaultYear = placeholder ? {
88
- value: String(placeholder.year),
89
- label: String(placeholder.year)
90
- } : undefined;
91
-
92
- $: defaultMonth = placeholder ? {
93
- value: String(placeholder.month),
94
- label: monthFmt.format(placeholder.toDate(getLocalTimeZone()))
95
- } : undefined;
96
-
97
- /**
98
- * Updates the current value when the external value changes
99
- * Handles initialization and updates of the date state
100
- * Creates a new CalendarDate instance to prevent reference issues
101
- */
102
- function updateCurrentValue() {
103
- // console.log('🔄 [DatePicker] updateCurrentValue called with:', { value, type: typeof value });
104
-
105
- if (!value) {
106
- currentValue = undefined;
107
- placeholder = today(getLocalTimeZone());
108
- // console.log('✅ [DatePicker] Set to undefined, placeholder:', placeholder);
109
- return;
110
- }
111
-
112
- if (value instanceof CalendarDate) {
113
- currentValue = value;
114
- // console.log('✅ [DatePicker] Already CalendarDate:', currentValue);
115
- } else if (typeof value === 'object' && value !== null && 'year' in value && 'month' in value && 'day' in value) {
116
- try {
117
- currentValue = new CalendarDate(value.year, value.month, value.day);
118
- // console.log('✅ [DatePicker] Created CalendarDate from object:', { original: value, created: currentValue });
119
- } catch (error) {
120
- console.error('❌ [DatePicker] Failed to create CalendarDate from object:', { value, error });
121
- currentValue = undefined;
122
- }
123
- } else {
124
- console.warn('⚠️ [DatePicker] Invalid date value provided:', value);
125
- currentValue = undefined;
126
- }
127
-
128
- placeholder = currentValue ?? today(getLocalTimeZone());
129
- // console.log('🎯 [DatePicker] Final state:', { currentValue, placeholder });
130
- }
131
-
132
- // Watch for value changes and update internal state
133
- $: value, updateCurrentValue();
134
-
135
- // Track dropdown state through store subscription
136
- $: open = $openDropdowns?.has(controllerId) || false;
137
-
138
- // Computed values for Calendar component with extra safety
139
- $: calendarValue = currentValue;
140
- $: calendarDefaultMonth = placeholder;
141
- $: isCalendarReady = placeholder instanceof CalendarDate;
142
-
143
- /**
144
- * Formats a CalendarDate for display
145
- * Handles undefined dates and invalid objects
146
- * Returns a user-friendly date string
147
- * @param date - The date to format
148
- * @returns Formatted date string
149
- */
150
- function formatDate(date: CalendarDate | undefined, languageTag: string, translate: Translate<EditorMessageKey>): string {
151
- if (!date || !(date instanceof CalendarDate)) return translate('editor.date.pick');
152
- try {
153
- // Convert to JavaScript Date for localized formatting
154
- const jsDate = new Date(date.year, date.month - 1, date.day);
155
- return jsDate.toLocaleDateString(languageTag, { dateStyle: 'long' });
156
- } catch (error) {
157
- console.error('Error formatting date:', error);
158
- return translate('editor.date.pick');
159
- }
160
- }
161
-
162
- /**
163
- * Handles date selection from the calendar
164
- * Validates the selected date and updates state
165
- * Closes the dropdown after selection
166
- * @param newValue - The newly selected date
167
- */
168
- function handleSelect(newValue: DateValue | undefined) {
169
- if (newValue instanceof CalendarDate) {
170
- onChange(newValue);
171
- toggleDropdown(controllerId);
172
- }
173
- }
174
-
175
- /**
176
- * Toggles the date picker dropdown visibility
177
- * Manages dropdown state through the provided toggle function
178
- */
179
- function handleToggle() {
180
- toggleDropdown(controllerId);
181
- }
182
-
183
- /**
184
- * Closes the dropdown if it's currently open
185
- * Used for cleanup and external close triggers
186
- */
187
- function closeDropdown() {
188
- if (open) {
189
- toggleDropdown(controllerId);
190
- }
191
- }
192
-
193
- /**
194
- * Handles scroll events to prevent UI issues
195
- * Closes the dropdown when scrolling occurs outside the dropdowns
196
- */
197
- function handleScroll(event: Event) {
198
- // Ensure target is an HTMLElement
199
- if (!(event.target instanceof HTMLElement)) {
200
- return;
201
- }
202
-
203
- const target = event.target;
204
-
205
- // Check if scroll happened inside our dropdowns
206
- const isInsideDropdown = target.closest('.month-year-dropdown-content');
207
-
208
- // If scrolling is inside our dropdowns, don't close
209
- if (isInsideDropdown) {
210
- return;
211
- }
212
-
213
- // If scrolling outside our dropdowns, close
214
- if (open) {
215
- closeDropdown();
216
- }
217
- }
218
-
219
- // The control's own element, which says which tree (the page or a module's shadow root) to listen for scrolling in
220
- let controllerElement: HTMLDivElement | undefined;
221
- let stopListeningForScroll: () => void = () => {};
222
-
223
- // Setup scroll event listener on mount (the page and, inside a module, the module's own panels: a scroll never
224
- // leaves a shadow root, so a listener on the window alone does not hear about those)
225
- onMount(() => {
226
- stopListeningForScroll = listenForScroll(controllerElement, handleScroll);
227
- });
228
-
229
- // Cleanup scroll event listener on destroy
230
- onDestroy(() => {
231
- stopListeningForScroll();
232
- });
38
+ // Svelte imports
39
+ import { onMount, onDestroy } from 'svelte';
40
+ import { listenForScroll } from '../../utils/shadowDom';
41
+ import { useEditorLanguage } from '../../i18n/language';
42
+ import type { EditorMessageKey } from '../../i18n/messages';
43
+ import type { Translate } from '@widgetic/design-system/i18n';
44
+
45
+ // The words of the editor in the language of the page, and the language itself (how a month and a date are written).
46
+ const { t, locale } = useEditorLanguage();
47
+
48
+ // Shadcn UI Components
49
+ import { Select } from '@widgetic/design-system/components';
50
+ import { Popover } from '@widgetic/design-system/components';
51
+ import InputControllerRow from './InputControllerRow.svelte';
52
+ import { Calendar } from '@widgetic/design-system/components';
53
+
54
+ // Internationalized date imports
55
+ import { CalendarDate, getLocalTimeZone, today, DateFormatter } from '@internationalized/date';
56
+ import type { DateValue } from '@internationalized/date';
57
+
58
+ // Lucide Icons
59
+ import { IconCalendar } from '@widgetic/design-system/icons';
60
+ import EditorCalendarStyles from '../ui/calendar-editor-fit/EditorCalendarStyles.svelte';
61
+
62
+ // Component props with TypeScript types
63
+ export let label: DatePickerInputControllerProps['label'];
64
+ export let value: DatePickerInputControllerProps['value'];
65
+ export let onChange: DatePickerInputControllerProps['onChange'];
66
+ export let description: DatePickerInputControllerProps['description'] = undefined;
67
+ export let controllerId: DatePickerInputControllerProps['controllerId'];
68
+ export let openDropdowns: DatePickerInputControllerProps['openDropdowns'];
69
+ export let toggleDropdown: DatePickerInputControllerProps['toggleDropdown'];
70
+ export let onFocus: DatePickerInputControllerProps['onFocus'] = () => {};
71
+
72
+ // Default to today's date in local timezone for placeholder
73
+ let placeholder = today(getLocalTimeZone());
74
+ let currentValue: CalendarDate | undefined;
75
+
76
+ // Month and year options setup: the names of the months are written by the language of the page
77
+ $: monthFmt = new DateFormatter($locale, { month: 'long' });
78
+ $: monthOptions = Array.from({ length: 12 }, (_, monthIndex) => ({
79
+ value: String(monthIndex + 1),
80
+ label: monthFmt.format(new Date(2021, monthIndex, 1))
81
+ }));
82
+
83
+ const yearOptions = Array.from({ length: 100 }, (_, i) => {
84
+ const year = String(new Date().getFullYear() - i);
85
+ return { label: year, value: year };
86
+ });
87
+
88
+ $: defaultYear = placeholder
89
+ ? {
90
+ value: String(placeholder.year),
91
+ label: String(placeholder.year)
92
+ }
93
+ : undefined;
94
+
95
+ $: defaultMonth = placeholder
96
+ ? {
97
+ value: String(placeholder.month),
98
+ label: monthFmt.format(placeholder.toDate(getLocalTimeZone()))
99
+ }
100
+ : undefined;
101
+
102
+ /**
103
+ * Updates the current value when the external value changes
104
+ * Handles initialization and updates of the date state
105
+ * Creates a new CalendarDate instance to prevent reference issues
106
+ */
107
+ function updateCurrentValue() {
108
+ // console.log('🔄 [DatePicker] updateCurrentValue called with:', { value, type: typeof value });
109
+
110
+ if (!value) {
111
+ currentValue = undefined;
112
+ placeholder = today(getLocalTimeZone());
113
+ // console.log('✅ [DatePicker] Set to undefined, placeholder:', placeholder);
114
+ return;
115
+ }
116
+
117
+ if (value instanceof CalendarDate) {
118
+ currentValue = value;
119
+ // console.log('✅ [DatePicker] Already CalendarDate:', currentValue);
120
+ } else if (
121
+ typeof value === 'object' &&
122
+ value !== null &&
123
+ 'year' in value &&
124
+ 'month' in value &&
125
+ 'day' in value
126
+ ) {
127
+ try {
128
+ currentValue = new CalendarDate(value.year, value.month, value.day);
129
+ // console.log('✅ [DatePicker] Created CalendarDate from object:', { original: value, created: currentValue });
130
+ } catch (error) {
131
+ console.error('❌ [DatePicker] Failed to create CalendarDate from object:', {
132
+ value,
133
+ error
134
+ });
135
+ currentValue = undefined;
136
+ }
137
+ } else {
138
+ console.warn('⚠️ [DatePicker] Invalid date value provided:', value);
139
+ currentValue = undefined;
140
+ }
141
+
142
+ placeholder = currentValue ?? today(getLocalTimeZone());
143
+ // console.log('🎯 [DatePicker] Final state:', { currentValue, placeholder });
144
+ }
145
+
146
+ // Watch for value changes and update internal state
147
+ $: (value, updateCurrentValue());
148
+
149
+ // Track dropdown state through store subscription
150
+ $: open = $openDropdowns?.has(controllerId) || false;
151
+
152
+ // Computed values for Calendar component with extra safety
153
+ $: calendarValue = currentValue;
154
+ $: calendarDefaultMonth = placeholder;
155
+ $: isCalendarReady = placeholder instanceof CalendarDate;
156
+
157
+ /**
158
+ * Formats a CalendarDate for display
159
+ * Handles undefined dates and invalid objects
160
+ * Returns a user-friendly date string
161
+ * @param date - The date to format
162
+ * @returns Formatted date string
163
+ */
164
+ function formatDate(
165
+ date: CalendarDate | undefined,
166
+ languageTag: string,
167
+ translate: Translate<EditorMessageKey>
168
+ ): string {
169
+ if (!date || !(date instanceof CalendarDate)) return translate('editor.date.pick');
170
+ try {
171
+ // Convert to JavaScript Date for localized formatting
172
+ const jsDate = new Date(date.year, date.month - 1, date.day);
173
+ return jsDate.toLocaleDateString(languageTag, { dateStyle: 'long' });
174
+ } catch (error) {
175
+ console.error('Error formatting date:', error);
176
+ return translate('editor.date.pick');
177
+ }
178
+ }
179
+
180
+ /**
181
+ * Handles date selection from the calendar
182
+ * Validates the selected date and updates state
183
+ * Closes the dropdown after selection
184
+ * @param newValue - The newly selected date
185
+ */
186
+ function handleSelect(newValue: DateValue | undefined) {
187
+ if (newValue instanceof CalendarDate) {
188
+ onChange(newValue);
189
+ toggleDropdown(controllerId);
190
+ }
191
+ }
192
+
193
+ /**
194
+ * Toggles the date picker dropdown visibility
195
+ * Manages dropdown state through the provided toggle function
196
+ */
197
+ function handleToggle() {
198
+ toggleDropdown(controllerId);
199
+ }
200
+
201
+ /**
202
+ * Closes the dropdown if it's currently open
203
+ * Used for cleanup and external close triggers
204
+ */
205
+ function closeDropdown() {
206
+ if (open) {
207
+ toggleDropdown(controllerId);
208
+ }
209
+ }
210
+
211
+ /**
212
+ * Handles scroll events to prevent UI issues
213
+ * Closes the dropdown when scrolling occurs outside the dropdowns
214
+ */
215
+ function handleScroll(event: Event) {
216
+ // Ensure target is an HTMLElement
217
+ if (!(event.target instanceof HTMLElement)) {
218
+ return;
219
+ }
220
+
221
+ const target = event.target;
222
+
223
+ // Check if scroll happened inside our dropdowns
224
+ const isInsideDropdown = target.closest('.month-year-dropdown-content');
225
+
226
+ // If scrolling is inside our dropdowns, don't close
227
+ if (isInsideDropdown) {
228
+ return;
229
+ }
230
+
231
+ // If scrolling outside our dropdowns, close
232
+ if (open) {
233
+ closeDropdown();
234
+ }
235
+ }
236
+
237
+ // The control's own element, which says which tree (the page or a module's shadow root) to listen for scrolling in
238
+ let controllerElement: HTMLDivElement | undefined;
239
+ let stopListeningForScroll: () => void = () => {};
240
+
241
+ // Setup scroll event listener on mount (the page and, inside a module, the module's own panels: a scroll never
242
+ // leaves a shadow root, so a listener on the window alone does not hear about those)
243
+ onMount(() => {
244
+ stopListeningForScroll = listenForScroll(controllerElement, handleScroll);
245
+ });
246
+
247
+ // Cleanup scroll event listener on destroy
248
+ onDestroy(() => {
249
+ stopListeningForScroll();
250
+ });
233
251
  </script>
234
252
 
235
- <!-- Date Picker Container -->
236
- <div bind:this={controllerElement} class="flex flex-col gap-2 widgetic-colors">
237
- <div class="flex items-center w-full relative">
238
- <div class="flex-1 min-w-0">
239
- <InputControllerHeader {label} />
240
- </div>
241
-
242
- <div class="absolute end-0">
243
- <div
244
- class="h-[48px] w-[185px] rounded-large border border-grey2 flex items-center bg-grey1 transition-colors duration-200 hover:border-forest-green"
245
- on:focusin={onFocus}
246
- >
247
- <Popover.Root {open} onOpenChange={handleToggle}>
248
- <Popover.Trigger class="w-full h-full">
249
- <div class="w-full h-full px-[16px] flex items-center">
250
- <Button
251
- id="date-picker"
252
- variant="ghost"
253
- class="w-full h-full justify-between text-start border-0 bg-transparent hover:bg-transparent focus:bg-transparent p-0 group"
254
- >
255
- <span class="subtext text-grey7 {!currentValue ? 'text-grey3' : ''}">{formatDate(currentValue, $locale, $t)}</span>
256
- <IconCalendar class="w-[20px] h-[20px] text-grey5 transition-colors duration-200 group-hover:text-grey7" />
257
- </Button>
258
- </div>
259
- </Popover.Trigger>
260
-
261
- <Popover.Content class="w-auto p-0 z-50" sideOffset={4}>
262
- <div class="rounded-md border p-3">
263
- <div class="flex w-full items-center justify-between gap-2 mb-3">
264
- <Select.Root
265
- type="single"
266
- value={defaultMonth?.value}
267
- onValueChange={(value: string) => {
268
- if (!value || !placeholder) return;
269
- const monthValue = parseInt(value, 10);
270
- if (monthValue === placeholder?.month) return;
271
- // Re-create placeholder/currValue using explicit CalendarDate constructor to ensure
272
- // we pass a plain CalendarDate instance that the Calendar component can recognise.
273
- placeholder = new CalendarDate(
274
- placeholder.year,
275
- monthValue,
276
- placeholder.day
277
- );
278
- if (currentValue) {
279
- const newValue = new CalendarDate(
280
- currentValue.year,
281
- monthValue,
282
- currentValue.day
283
- );
284
- currentValue = newValue;
285
- onChange(newValue);
286
- }
287
- }}
288
- >
289
- <Select.Trigger aria-label={$t('editor.date.selectMonth')} class="w-[60%] month-year-dropdown-content">
290
- <span class="text-sm">{defaultMonth?.label || $t('editor.date.selectMonth')}</span>
291
- </Select.Trigger>
292
- <Select.Content class="max-h-[200px] overflow-y-auto month-year-dropdown-content">
293
- {#each monthOptions as { value, label }}
294
- <Select.Item {value} {label}>
295
- {label}
296
- </Select.Item>
297
- {/each}
298
- </Select.Content>
299
- </Select.Root>
300
- <Select.Root
301
- type="single"
302
- value={defaultYear?.value}
303
- onValueChange={(value: string) => {
304
- if (!value || !placeholder) return;
305
- const yearValue = parseInt(value, 10);
306
- if (yearValue === placeholder?.year) return;
307
- // Same fix as above – ensure a clean CalendarDate instance.
308
- placeholder = new CalendarDate(
309
- yearValue,
310
- placeholder.month,
311
- placeholder.day
312
- );
313
- if (currentValue) {
314
- const newValue = new CalendarDate(
315
- yearValue,
316
- currentValue.month,
317
- currentValue.day
318
- );
319
- currentValue = newValue;
320
- onChange(newValue);
321
- }
322
- }}
323
- >
324
- <Select.Trigger aria-label={$t('editor.date.selectYear')} class="w-[40%] month-year-dropdown-content">
325
- <span class="text-sm">{defaultYear?.label || $t('editor.date.selectYear')}</span>
326
- </Select.Trigger>
327
- <Select.Content class="max-h-[200px] overflow-y-auto month-year-dropdown-content">
328
- {#each yearOptions as { value, label }}
329
- <Select.Item {value} {label}>
330
- {label}
331
- </Select.Item>
332
- {/each}
333
- </Select.Content>
334
- </Select.Root>
335
- </div>
336
- <div class="calendar-no-header">
337
- <Calendar
338
- mode="single"
339
- locale={$locale}
340
- calendarLabel={$t('editor.date.calendarLabel')}
341
- previousLabel={$t('editor.date.previousMonth')}
342
- nextLabel={$t('editor.date.nextMonth')}
343
- onValueChange={(date: DateValue | undefined) => {
344
- // console.log('📅 [DatePicker] Calendar onValueChange:', { date, isCalendarDate: date instanceof CalendarDate });
345
- if (date instanceof CalendarDate) {
346
- currentValue = date;
347
- placeholder = date;
348
- onChange(date);
349
- closeDropdown();
350
- }
351
- }}
352
- fixedWeeks
353
- />
354
- </div>
355
- </div>
356
- </Popover.Content>
357
- </Popover.Root>
358
- </div>
359
- </div>
360
- </div>
361
-
362
- {#if description}
363
- <p class="subtext text-grey5">{description}</p>
364
- {/if}
253
+ <EditorCalendarStyles />
254
+
255
+ <!-- Date Picker Container (Figma IC Date Picker 172:399 + Calendar 210:3967) -->
256
+ <div bind:this={controllerElement} class="date-picker-input-controller">
257
+ <InputControllerRow {label} {description}>
258
+ <Popover.Root {open} onOpenChange={handleToggle}>
259
+ <Popover.Trigger
260
+ class="date-picker-trigger group flex h-9 w-full items-center gap-2 rounded-lg bg-accent pe-2 ps-3 transition-colors duration-fast hover:bg-accent-hover focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background"
261
+ onfocusin={onFocus}
262
+ >
263
+ <span
264
+ class="min-w-0 flex-1 truncate text-start text-body {currentValue
265
+ ? 'text-foreground'
266
+ : 'text-muted-foreground'}"
267
+ >
268
+ {formatDate(currentValue, $locale, $t)}
269
+ </span>
270
+ <IconCalendar
271
+ class="size-4 shrink-0 stroke-[1.333] text-muted-foreground transition-colors duration-fast group-hover:text-foreground"
272
+ aria-hidden="true"
273
+ />
274
+ </Popover.Trigger>
275
+
276
+ <Popover.Content
277
+ class="date-picker-popover z-50 w-[248px] border border-border p-3 shadow-none"
278
+ align="end"
279
+ sideOffset={8}
280
+ >
281
+ <div class="flex w-full flex-col gap-3">
282
+ <div class="flex w-full items-center gap-2">
283
+ <Select.Root
284
+ type="single"
285
+ value={defaultMonth?.value}
286
+ onValueChange={(value: string) => {
287
+ if (!value || !placeholder) return;
288
+ const monthValue = parseInt(value, 10);
289
+ if (monthValue === placeholder?.month) return;
290
+ // Re-create placeholder/currValue using explicit CalendarDate constructor to ensure
291
+ // we pass a plain CalendarDate instance that the Calendar component can recognise.
292
+ placeholder = new CalendarDate(placeholder.year, monthValue, placeholder.day);
293
+ if (currentValue) {
294
+ const newValue = new CalendarDate(
295
+ currentValue.year,
296
+ monthValue,
297
+ currentValue.day
298
+ );
299
+ currentValue = newValue;
300
+ onChange(newValue);
301
+ }
302
+ }}
303
+ >
304
+ <Select.Trigger
305
+ aria-label={$t('editor.date.selectMonth')}
306
+ class="month-year-dropdown-content h-9 min-w-0 flex-[1.5] rounded-lg bg-accent px-3 text-body hover:bg-accent-hover"
307
+ >
308
+ <span class="truncate">{defaultMonth?.label || $t('editor.date.selectMonth')}</span>
309
+ </Select.Trigger>
310
+ <Select.Content class="month-year-dropdown-content max-h-[200px] overflow-y-auto">
311
+ {#each monthOptions as { value, label }}
312
+ <Select.Item {value} {label}>
313
+ {label}
314
+ </Select.Item>
315
+ {/each}
316
+ </Select.Content>
317
+ </Select.Root>
318
+ <Select.Root
319
+ type="single"
320
+ value={defaultYear?.value}
321
+ onValueChange={(value: string) => {
322
+ if (!value || !placeholder) return;
323
+ const yearValue = parseInt(value, 10);
324
+ if (yearValue === placeholder?.year) return;
325
+ // Same fix as above – ensure a clean CalendarDate instance.
326
+ placeholder = new CalendarDate(yearValue, placeholder.month, placeholder.day);
327
+ if (currentValue) {
328
+ const newValue = new CalendarDate(
329
+ yearValue,
330
+ currentValue.month,
331
+ currentValue.day
332
+ );
333
+ currentValue = newValue;
334
+ onChange(newValue);
335
+ }
336
+ }}
337
+ >
338
+ <Select.Trigger
339
+ aria-label={$t('editor.date.selectYear')}
340
+ class="month-year-dropdown-content h-9 min-w-0 flex-1 rounded-lg bg-accent px-3 text-body hover:bg-accent-hover"
341
+ >
342
+ <span class="truncate">{defaultYear?.label || $t('editor.date.selectYear')}</span>
343
+ </Select.Trigger>
344
+ <Select.Content class="month-year-dropdown-content max-h-[200px] overflow-y-auto">
345
+ {#each yearOptions as { value, label }}
346
+ <Select.Item {value} {label}>
347
+ {label}
348
+ </Select.Item>
349
+ {/each}
350
+ </Select.Content>
351
+ </Select.Root>
352
+ </div>
353
+ <!-- Style the calendar content -->
354
+ <div class="calendar-no-header">
355
+ <Calendar
356
+ mode="single"
357
+ locale={$locale}
358
+ calendarLabel={$t('editor.date.calendarLabel')}
359
+ previousLabel={$t('editor.date.previousMonth')}
360
+ nextLabel={$t('editor.date.nextMonth')}
361
+ onValueChange={(date: DateValue | undefined) => {
362
+ if (date instanceof CalendarDate) {
363
+ currentValue = date;
364
+ placeholder = date;
365
+ onChange(date);
366
+ closeDropdown();
367
+ }
368
+ }}
369
+ fixedWeeks
370
+ class="calendar-editor-fit p-0"
371
+ />
372
+ </div>
373
+ </div>
374
+ </Popover.Content>
375
+ </Popover.Root>
376
+ </InputControllerRow>
365
377
  </div>
366
378
 
367
379
  <style>
368
- /* Remove focus ring from trigger */
369
- :global(.date-picker-trigger:focus-visible) {
370
- outline: none !important;
371
- box-shadow: none !important;
372
- }
373
-
374
- /* Style the calendar content */
375
- :global(.calendar-content) {
376
- border: 1px solid hsl(var(--grey2)) !important;
377
- background: white !important;
378
- border-radius: var(--radius) !important;
379
- margin-top: 4px !important;
380
- }
381
-
382
- /* Remove button styles */
383
- :global(button.bg-transparent) {
384
- outline: none !important;
385
- box-shadow: none !important;
386
- }
387
-
388
- :global(button.bg-transparent:hover),
389
- :global(button.bg-transparent:focus) {
390
- background-color: transparent !important;
391
- }
392
-
393
- /* Hide calendar header */
394
- :global(.calendar-no-header header) {
395
- display: none !important;
396
- }
380
+ /* Hide calendar header (month nav lives in the dropdown row above) */
381
+ :global(.calendar-no-header header) {
382
+ display: none !important;
383
+ }
397
384
  </style>