@widgetic/editor 4.1.14 → 4.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/PreviewChromeControls.svelte +15 -21
- package/dist/components/WidgetPreview.svelte +136 -105
- package/dist/components/color-select/ColorSelect.svelte +203 -224
- package/dist/components/color-select/constants.d.ts +4 -2
- package/dist/components/color-select/constants.js +4 -2
- package/dist/components/color-select/render.js +10 -9
- package/dist/components/editors/CompositionEditorApp.svelte +47 -40
- package/dist/components/editors/EditLeaseNotice.svelte +44 -33
- package/dist/components/editors/EmbedEditor.svelte +133 -259
- package/dist/components/editors/PropsEditor.svelte +418 -1338
- package/dist/components/editors/props-editor.css +5 -68
- package/dist/components/ic/AngleInputController.svelte +202 -277
- package/dist/components/ic/BrowserInputController.svelte +813 -803
- package/dist/components/ic/CheckboxInputController.svelte +92 -169
- package/dist/components/ic/CheckboxInputController.svelte.d.ts +2 -8
- package/dist/components/ic/ColorPickerInputController.svelte +1589 -1587
- package/dist/components/ic/ColorPickerInputController.svelte.d.ts +3 -3
- package/dist/components/ic/DateFieldInputController.svelte +455 -465
- package/dist/components/ic/DatePickerInputController.svelte +355 -368
- package/dist/components/ic/DatePickerInputController.svelte.d.ts +1 -1
- package/dist/components/ic/DropdownInputController.svelte +130 -200
- package/dist/components/ic/FixedPositionInputController.svelte +255 -276
- package/dist/components/ic/FixedPositionInputController.svelte.d.ts +5 -1
- package/dist/components/ic/FontInputController.svelte +2110 -2231
- package/dist/components/ic/FontInputController.svelte.d.ts +11 -11
- package/dist/components/ic/InputControllerHeader.svelte +141 -147
- package/dist/components/ic/InputControllerRow.svelte +74 -0
- package/dist/components/ic/InputControllerRow.svelte.d.ts +14 -0
- package/dist/components/ic/KnowledgeDocumentsInputController.svelte +84 -47
- package/dist/components/ic/KnowledgeTextForm.svelte +35 -33
- package/dist/components/ic/NumberControls.svelte +303 -269
- package/dist/components/ic/NumberControls.svelte.d.ts +4 -1
- package/dist/components/ic/NumberInputController.svelte +361 -301
- package/dist/components/ic/NumberInputController.svelte.d.ts +2 -0
- package/dist/components/ic/PositionInputController.svelte +253 -176
- package/dist/components/ic/PositionInputController.svelte.d.ts +2 -0
- package/dist/components/ic/RadioGroupInputController.svelte +71 -137
- package/dist/components/ic/RadioGroupInputController.svelte.d.ts +2 -8
- package/dist/components/ic/RangeCalendarInputController.svelte +233 -270
- package/dist/components/ic/RangeCalendarInputController.svelte.d.ts +2 -2
- package/dist/components/ic/RoundedCornersInputController.svelte +412 -435
- package/dist/components/ic/RoundedCornersInputController.svelte.d.ts +2 -0
- package/dist/components/ic/SliderInputController.svelte +263 -332
- package/dist/components/ic/SliderInputController.svelte.d.ts +1 -1
- package/dist/components/ic/SliderRangeInputController.svelte +140 -144
- package/dist/components/ic/SliderRangeInputController.svelte.d.ts +3 -3
- package/dist/components/ic/SwitchInputController.svelte +47 -109
- package/dist/components/ic/TagsInputController.svelte +95 -110
- package/dist/components/ic/TextAreaInputController.svelte +1794 -1935
- package/dist/components/ic/TextAreaPreviewInputController.svelte +436 -438
- package/dist/components/ic/TextAreaPreviewInputController.svelte.d.ts +2 -2
- package/dist/components/ic/TextInputController.svelte +65 -75
- package/dist/components/ic/TextInputController.svelte.d.ts +2 -0
- package/dist/components/ic/TimeInputController.svelte +433 -431
- package/dist/components/ic/VectorInputController.svelte +1833 -1831
- package/dist/components/ic/VectorInputController.svelte.d.ts +10 -10
- package/dist/components/ic/index.d.ts +1 -0
- package/dist/components/ic/index.js +1 -0
- package/dist/components/ic/shared/CategoryTabs.svelte +28 -35
- package/dist/components/ic/shared/ItemGrid.svelte +145 -179
- package/dist/components/ic/shared/RecentItemsSection.svelte +208 -271
- package/dist/components/ic/shared/RecentItemsSection.svelte.d.ts +1 -1
- package/dist/components/ui/arrows/OpacitySliderArrows.svelte +23 -38
- package/dist/components/ui/arrows/OpacitySliderArrows.svelte.d.ts +1 -4
- package/dist/components/ui/calendar-editor-fit/EditorCalendarStyles.svelte +45 -0
- package/dist/components/ui/calendar-editor-fit/EditorCalendarStyles.svelte.d.ts +26 -0
- package/dist/components/ui/checkerboard-background/CheckerboardBackground.svelte +20 -12
- package/dist/components/ui/shadow-picker-host/ShadowPickerHost.svelte +39 -0
- package/dist/components/ui/shadow-picker-host/ShadowPickerHost.svelte.d.ts +10 -0
- package/dist/i18n/language.d.ts +43 -36
- package/dist/i18n/messages.d.ts +41 -34
- package/dist/i18n/messages.js +47 -34
- package/dist/i18n/translate.d.ts +1 -1
- package/dist/utils.d.ts +7 -0
- package/dist/utils.js +26 -2
- package/package.json +4 -4
|
@@ -12,442 +12,444 @@
|
|
|
12
12
|
-->
|
|
13
13
|
|
|
14
14
|
<script module lang="ts">
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
/** Declared props contract — export lets below are annotated from it so the
|
|
16
|
+
* interface cannot drift from what the component actually reads. */
|
|
17
|
+
export interface TimeInputControllerProps {
|
|
18
|
+
label: string;
|
|
19
|
+
value?: string;
|
|
20
|
+
onChange: (newValue: string) => void;
|
|
21
|
+
helpText?: string;
|
|
22
|
+
onFocus?: () => void;
|
|
23
|
+
}
|
|
24
24
|
</script>
|
|
25
25
|
|
|
26
26
|
<script lang="ts">
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
27
|
+
import { onMount, onDestroy } from 'svelte';
|
|
28
|
+
import { Portal } from '@widgetic/design-system/components';
|
|
29
|
+
import InputControllerRow from './InputControllerRow.svelte';
|
|
30
|
+
import { IconCheck } from '@widgetic/design-system/icons';
|
|
31
|
+
import { useTextDirection } from '@widgetic/design-system/components/textDirection';
|
|
32
|
+
import { isEventInside, listenForScroll } from '../../utils/shadowDom';
|
|
33
|
+
|
|
34
|
+
const textDirection = useTextDirection();
|
|
35
|
+
|
|
36
|
+
export let label: TimeInputControllerProps['label'];
|
|
37
|
+
export let value: TimeInputControllerProps['value'] = '00:00';
|
|
38
|
+
export let onChange: TimeInputControllerProps['onChange'];
|
|
39
|
+
// export let config: InputControllerConfig = {};
|
|
40
|
+
export let helpText: TimeInputControllerProps['helpText'] = undefined;
|
|
41
|
+
export let onFocus: TimeInputControllerProps['onFocus'] = () => {};
|
|
42
|
+
|
|
43
|
+
let className = '';
|
|
44
|
+
export { className as class };
|
|
45
|
+
|
|
46
|
+
// Time state
|
|
47
|
+
let hours = 0;
|
|
48
|
+
let minutes = 0;
|
|
49
|
+
let isDropdownOpen = false;
|
|
50
|
+
let isDropdownPositioned = false;
|
|
51
|
+
|
|
52
|
+
// Clock interaction state
|
|
53
|
+
let isDragging = false;
|
|
54
|
+
let isDraggingHours = false;
|
|
55
|
+
let clockContainer: HTMLDivElement;
|
|
56
|
+
let dropdownContainer: HTMLDivElement;
|
|
57
|
+
let startAngle = 0;
|
|
58
|
+
let startValue = 0;
|
|
59
|
+
|
|
60
|
+
// Add button ref
|
|
61
|
+
let timeButton: HTMLButtonElement;
|
|
62
|
+
|
|
63
|
+
// Generate time options in 30-minute intervals (24h format)
|
|
64
|
+
const timeOptions = Array.from({ length: 48 }, (_, i) => {
|
|
65
|
+
const hour = Math.floor(i / 2);
|
|
66
|
+
const minute = (i % 2) * 30;
|
|
67
|
+
return `${hour.toString().padStart(2, '0')}:${minute.toString().padStart(2, '0')}`;
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// Parse time from string (handles both 12h and 24h formats)
|
|
71
|
+
function parseTimeFromValue(timeString: string) {
|
|
72
|
+
if (!timeString) {
|
|
73
|
+
hours = 0;
|
|
74
|
+
minutes = 0;
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Try 24h format first (HH:mm)
|
|
79
|
+
const [h, m] = timeString.split(':').map(Number);
|
|
80
|
+
|
|
81
|
+
if (!isNaN(h) && !isNaN(m)) {
|
|
82
|
+
hours = h;
|
|
83
|
+
minutes = m;
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Try 12h format (hh:mm am/pm)
|
|
88
|
+
const match = timeString.toLowerCase().match(/(\d+):(\d+)\s*(am|pm)/);
|
|
89
|
+
if (match) {
|
|
90
|
+
let h12 = parseInt(match[1]);
|
|
91
|
+
const m12 = parseInt(match[2]);
|
|
92
|
+
const period = match[3];
|
|
93
|
+
|
|
94
|
+
// Convert to 24h format
|
|
95
|
+
if (period === 'pm' && h12 < 12) {
|
|
96
|
+
h12 += 12;
|
|
97
|
+
} else if (period === 'am' && h12 === 12) {
|
|
98
|
+
h12 = 0;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
hours = h12;
|
|
102
|
+
minutes = m12;
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// If all parsing fails, default to 00:00
|
|
107
|
+
hours = 0;
|
|
108
|
+
minutes = 0;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Format time to string (24h format)
|
|
112
|
+
function formatTimeToString(h: number, m: number): string {
|
|
113
|
+
return `${h.toString().padStart(2, '0')}:${m.toString().padStart(2, '0')}`;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Update the value when time components change
|
|
117
|
+
function updateValue() {
|
|
118
|
+
const newValue = formatTimeToString(hours, minutes);
|
|
119
|
+
if (newValue !== value) {
|
|
120
|
+
value = newValue;
|
|
121
|
+
onChange(newValue);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Calculate clock hand angles based on current time
|
|
126
|
+
$: hourAngle = ((hours % 12) / 12) * 360 + (minutes / 60) * 30;
|
|
127
|
+
$: minuteAngle = (minutes / 60) * 360;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Calculates the angle between two points relative to a center point
|
|
131
|
+
*/
|
|
132
|
+
function calculateAngle(x: number, y: number, centerX: number, centerY: number): number {
|
|
133
|
+
const angle = Math.atan2(x - centerX, -(y - centerY)) * (180 / Math.PI);
|
|
134
|
+
return (angle + 360) % 360;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Updates time based on mouse/touch position
|
|
139
|
+
*/
|
|
140
|
+
function updateTimeFromAngle(
|
|
141
|
+
clientX: number,
|
|
142
|
+
clientY: number,
|
|
143
|
+
isHourHand: boolean,
|
|
144
|
+
shouldSnapToPosition: boolean = false
|
|
145
|
+
) {
|
|
146
|
+
if (!clockContainer || (!isDragging && !shouldSnapToPosition)) return;
|
|
147
|
+
|
|
148
|
+
const rect = clockContainer.getBoundingClientRect();
|
|
149
|
+
const centerX = rect.left + rect.width / 2;
|
|
150
|
+
const centerY = rect.top + rect.height / 2;
|
|
151
|
+
const currentAngle = calculateAngle(clientX, clientY, centerX, centerY);
|
|
152
|
+
|
|
153
|
+
if (isHourHand) {
|
|
154
|
+
// Convert angle to hour (30 degrees per hour)
|
|
155
|
+
let newHour = Math.round(currentAngle / 30) % 12;
|
|
156
|
+
// Preserve 24h format
|
|
157
|
+
if (hours >= 12) newHour += 12;
|
|
158
|
+
if (newHour !== hours) {
|
|
159
|
+
hours = newHour;
|
|
160
|
+
updateValue();
|
|
161
|
+
}
|
|
162
|
+
} else {
|
|
163
|
+
// Convert angle to minutes (6 degrees per minute), round to nearest 5
|
|
164
|
+
let newMinute = Math.round(Math.round(currentAngle / 6) / 5) * 5;
|
|
165
|
+
if (newMinute === 60) newMinute = 0;
|
|
166
|
+
if (newMinute !== minutes) {
|
|
167
|
+
minutes = newMinute;
|
|
168
|
+
updateValue();
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Mouse event handlers
|
|
174
|
+
function handleClockFaceMouseDown(event: MouseEvent) {
|
|
175
|
+
if (!clockContainer) return;
|
|
176
|
+
|
|
177
|
+
const rect = clockContainer.getBoundingClientRect();
|
|
178
|
+
const centerX = rect.left + rect.width / 2;
|
|
179
|
+
const centerY = rect.top + rect.height / 2;
|
|
180
|
+
const distance = Math.sqrt(
|
|
181
|
+
Math.pow(event.clientX - centerX, 2) + Math.pow(event.clientY - centerY, 2)
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
isDraggingHours = distance < rect.width / 4;
|
|
185
|
+
updateTimeFromAngle(event.clientX, event.clientY, isDraggingHours, true);
|
|
186
|
+
|
|
187
|
+
isDragging = true;
|
|
188
|
+
onFocus();
|
|
189
|
+
|
|
190
|
+
document.addEventListener('mousemove', handleMouseMove);
|
|
191
|
+
document.addEventListener('mouseup', handleMouseUp);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function handleMouseMove(event: MouseEvent) {
|
|
195
|
+
if (!isDragging) return;
|
|
196
|
+
event.preventDefault();
|
|
197
|
+
updateTimeFromAngle(event.clientX, event.clientY, isDraggingHours);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function handleMouseUp() {
|
|
201
|
+
isDragging = false;
|
|
202
|
+
document.removeEventListener('mousemove', handleMouseMove);
|
|
203
|
+
document.removeEventListener('mouseup', handleMouseUp);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// Touch event handlers
|
|
207
|
+
function handleTouchStart(event: TouchEvent) {
|
|
208
|
+
if (!clockContainer) return;
|
|
209
|
+
|
|
210
|
+
const touch = event.touches[0];
|
|
211
|
+
const rect = clockContainer.getBoundingClientRect();
|
|
212
|
+
const centerX = rect.left + rect.width / 2;
|
|
213
|
+
const centerY = rect.top + rect.height / 2;
|
|
214
|
+
const distance = Math.sqrt(
|
|
215
|
+
Math.pow(touch.clientX - centerX, 2) + Math.pow(touch.clientY - centerY, 2)
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
isDraggingHours = distance < rect.width / 4;
|
|
219
|
+
updateTimeFromAngle(touch.clientX, touch.clientY, isDraggingHours, true);
|
|
220
|
+
|
|
221
|
+
isDragging = true;
|
|
222
|
+
onFocus();
|
|
223
|
+
event.preventDefault();
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function handleTouchMove(event: TouchEvent) {
|
|
227
|
+
if (!isDragging) return;
|
|
228
|
+
event.preventDefault();
|
|
229
|
+
const touch = event.touches[0];
|
|
230
|
+
updateTimeFromAngle(touch.clientX, touch.clientY, isDraggingHours);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function handleTouchEnd(event: TouchEvent) {
|
|
234
|
+
event.preventDefault();
|
|
235
|
+
isDragging = false;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// Dropdown handlers
|
|
239
|
+
function toggleDropdown() {
|
|
240
|
+
if (!isDropdownOpen) {
|
|
241
|
+
isDropdownOpen = true;
|
|
242
|
+
isDropdownPositioned = false;
|
|
243
|
+
onFocus();
|
|
244
|
+
|
|
245
|
+
// Use requestAnimationFrame to ensure DOM is updated
|
|
246
|
+
requestAnimationFrame(() => {
|
|
247
|
+
if (dropdownContainer && timeButton) {
|
|
248
|
+
const rect = timeButton.getBoundingClientRect();
|
|
249
|
+
dropdownContainer.style.top = `${rect.bottom + 8}px`;
|
|
250
|
+
if ($textDirection === 'rtl') {
|
|
251
|
+
// rtl-ok: the list is as wide as the button it opens from, so the left edge of the button is both of its edges
|
|
252
|
+
dropdownContainer.style.left = `${Math.round(rect.left)}px`; // rtl-ok: end-align the menu with the field's start edge on a right to left screen
|
|
253
|
+
dropdownContainer.style.right = 'auto';
|
|
254
|
+
} else {
|
|
255
|
+
dropdownContainer.style.left = 'auto'; // rtl-ok: clear the start edge so only the end edge positions the menu on a left to right screen
|
|
256
|
+
dropdownContainer.style.right = `${Math.round(window.innerWidth - rect.right)}px`; // rtl-ok: end-align the menu with the field's end edge on a left to right screen
|
|
257
|
+
}
|
|
258
|
+
isDropdownPositioned = true;
|
|
259
|
+
}
|
|
260
|
+
document.addEventListener('click', handleClickOutside);
|
|
261
|
+
});
|
|
262
|
+
} else {
|
|
263
|
+
closeDropdown();
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function closeDropdown() {
|
|
268
|
+
isDropdownOpen = false;
|
|
269
|
+
isDropdownPositioned = false;
|
|
270
|
+
document.removeEventListener('click', handleClickOutside);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function handleClickOutside(event: MouseEvent) {
|
|
274
|
+
// Seen from the document, a click inside a shadow root has the module's host as its target, so the click's path
|
|
275
|
+
// is what says whether it was inside the dropdown
|
|
276
|
+
if (dropdownContainer && !isEventInside(event, dropdownContainer)) {
|
|
277
|
+
closeDropdown();
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function selectTime(timeOption: string) {
|
|
282
|
+
parseTimeFromValue(timeOption);
|
|
283
|
+
updateValue();
|
|
284
|
+
closeDropdown();
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// Update scroll handler function
|
|
288
|
+
function handleScroll(event: Event) {
|
|
289
|
+
// Ensure target is an HTMLElement
|
|
290
|
+
if (!(event.target instanceof HTMLElement)) {
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
const target = event.target;
|
|
295
|
+
|
|
296
|
+
// Check if scroll happened inside our dropdown
|
|
297
|
+
const isInsideDropdown = target.closest('.time-dropdown-content');
|
|
298
|
+
|
|
299
|
+
// If scrolling is inside our dropdown, don't close
|
|
300
|
+
if (isInsideDropdown) {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// If scrolling outside our dropdown, close it
|
|
305
|
+
if (isDropdownOpen) {
|
|
306
|
+
closeDropdown();
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// Stops the scroll listener (it listens to the page and, in a module, to the module's own panels)
|
|
311
|
+
let stopListeningForScroll: () => void = () => {};
|
|
312
|
+
|
|
313
|
+
// Update onMount to add scroll listener with capture phase
|
|
314
|
+
onMount(() => {
|
|
315
|
+
parseTimeFromValue(value);
|
|
316
|
+
updateValue();
|
|
317
|
+
stopListeningForScroll = listenForScroll(clockContainer, handleScroll);
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
// Update onDestroy to remove scroll listener
|
|
321
|
+
onDestroy(() => {
|
|
322
|
+
document.removeEventListener('mousemove', handleMouseMove);
|
|
323
|
+
document.removeEventListener('mouseup', handleMouseUp);
|
|
324
|
+
document.removeEventListener('click', handleClickOutside);
|
|
325
|
+
stopListeningForScroll();
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
// Watch for external value changes
|
|
329
|
+
$: if (value) {
|
|
330
|
+
const formattedTime = formatTimeToString(hours, minutes);
|
|
331
|
+
if (value !== formattedTime) {
|
|
332
|
+
parseTimeFromValue(value);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// Mouse event handlers
|
|
337
|
+
function handleHourHandMouseDown(event: MouseEvent) {
|
|
338
|
+
event.stopPropagation();
|
|
339
|
+
isDraggingHours = true;
|
|
340
|
+
handleClockFaceMouseDown(event);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
function handleMinuteHandMouseDown(event: MouseEvent) {
|
|
344
|
+
event.stopPropagation();
|
|
345
|
+
isDraggingHours = false;
|
|
346
|
+
handleClockFaceMouseDown(event);
|
|
347
|
+
}
|
|
335
348
|
</script>
|
|
336
349
|
|
|
337
|
-
<div class="
|
|
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
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
</Portal>
|
|
420
|
-
{/if}
|
|
421
|
-
</div>
|
|
422
|
-
</div>
|
|
423
|
-
</div>
|
|
424
|
-
</div>
|
|
350
|
+
<div class="time-input-controller {className}">
|
|
351
|
+
<InputControllerRow {label} {helpText} controlClass="flex justify-end">
|
|
352
|
+
<div class="flex w-full items-center justify-end gap-2">
|
|
353
|
+
<!-- Clock dial (Figma IC Time 177:1421) -->
|
|
354
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
355
|
+
<div
|
|
356
|
+
bind:this={clockContainer}
|
|
357
|
+
class="time-dial relative flex size-9 shrink-0 cursor-grab items-center justify-center rounded-full bg-accent transition-colors duration-fast hover:bg-accent-hover active:cursor-grabbing"
|
|
358
|
+
on:mousedown={handleClockFaceMouseDown}
|
|
359
|
+
on:touchstart={handleTouchStart}
|
|
360
|
+
on:touchmove={handleTouchMove}
|
|
361
|
+
on:touchend={handleTouchEnd}
|
|
362
|
+
>
|
|
363
|
+
<!-- Clock Face -->
|
|
364
|
+
<div class="pointer-events-none absolute inset-0 size-full">
|
|
365
|
+
<!-- Hour markers -->
|
|
366
|
+
{#each Array(12) as _, i}
|
|
367
|
+
<div
|
|
368
|
+
class="absolute h-1 w-px bg-muted-foreground/40 transition-colors duration-fast"
|
|
369
|
+
style="left: 50%; top: 2px; transform-origin: 50% 16px; transform: translateX(-50%) rotate({i *
|
|
370
|
+
30}deg);"
|
|
371
|
+
></div>
|
|
372
|
+
{/each}
|
|
373
|
+
</div>
|
|
374
|
+
|
|
375
|
+
<!-- Hour Hand -->
|
|
376
|
+
<div
|
|
377
|
+
class="absolute top-1/2 start-1/2 h-2 w-0.5 origin-bottom -translate-x-1/2 cursor-pointer rounded-full bg-primary transition-colors duration-fast"
|
|
378
|
+
style="transform: translate(-50%, -100%) rotate({hourAngle}deg)"
|
|
379
|
+
on:mousedown|stopPropagation={handleHourHandMouseDown}
|
|
380
|
+
></div>
|
|
381
|
+
|
|
382
|
+
<!-- Minute Hand -->
|
|
383
|
+
<div
|
|
384
|
+
class="absolute top-1/2 start-1/2 h-[13px] w-0.5 origin-bottom -translate-x-1/2 cursor-pointer rounded-full bg-primary transition-colors duration-fast"
|
|
385
|
+
style="transform: translate(-50%, -100%) rotate({minuteAngle}deg)"
|
|
386
|
+
on:mousedown|stopPropagation={handleMinuteHandMouseDown}
|
|
387
|
+
></div>
|
|
388
|
+
</div>
|
|
389
|
+
|
|
390
|
+
<div class="relative w-[141px] shrink-0">
|
|
391
|
+
<button
|
|
392
|
+
bind:this={timeButton}
|
|
393
|
+
type="button"
|
|
394
|
+
class="time-field flex h-9 w-full items-center justify-center rounded-lg bg-accent px-3 text-body text-foreground 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"
|
|
395
|
+
on:click={toggleDropdown}
|
|
396
|
+
>
|
|
397
|
+
{value}
|
|
398
|
+
</button>
|
|
399
|
+
|
|
400
|
+
<!-- Time Dropdown -->
|
|
401
|
+
{#if isDropdownOpen}
|
|
402
|
+
<Portal target="time-input-dropdown">
|
|
403
|
+
<div
|
|
404
|
+
bind:this={dropdownContainer}
|
|
405
|
+
class="time-dropdown-content fixed z-[99999999] flex max-h-[300px] w-[141px] flex-col gap-0.5 overflow-y-auto rounded-xl border border-border bg-popover p-1 text-popover-foreground shadow-none transition-opacity duration-fast"
|
|
406
|
+
class:opacity-0={!isDropdownPositioned}
|
|
407
|
+
class:opacity-100={isDropdownPositioned}
|
|
408
|
+
>
|
|
409
|
+
{#each timeOptions as timeOption}
|
|
410
|
+
<button
|
|
411
|
+
type="button"
|
|
412
|
+
class="flex h-8 w-full items-center gap-2 rounded-lg px-2 py-1.5 text-start text-body transition-colors duration-fast hover:bg-accent {timeOption ===
|
|
413
|
+
value
|
|
414
|
+
? 'bg-brand-subtle text-foreground'
|
|
415
|
+
: 'text-foreground'}"
|
|
416
|
+
on:click={() => selectTime(timeOption)}
|
|
417
|
+
>
|
|
418
|
+
<span class="flex size-4 shrink-0 items-center justify-center">
|
|
419
|
+
{#if timeOption === value}
|
|
420
|
+
<IconCheck class="size-4 stroke-[1.333]" aria-hidden="true" />
|
|
421
|
+
{/if}
|
|
422
|
+
</span>
|
|
423
|
+
<span class="min-w-0 flex-1 truncate">{timeOption}</span>
|
|
424
|
+
</button>
|
|
425
|
+
{/each}
|
|
426
|
+
</div>
|
|
427
|
+
</Portal>
|
|
428
|
+
{/if}
|
|
429
|
+
</div>
|
|
430
|
+
</div>
|
|
431
|
+
</InputControllerRow>
|
|
425
432
|
</div>
|
|
426
433
|
|
|
427
434
|
<style>
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
div::-webkit-scrollbar-thumb:hover {
|
|
451
|
-
background: hsl(var(--grey4));
|
|
452
|
-
}
|
|
453
|
-
</style>
|
|
435
|
+
/* Prevent text selection during dragging */
|
|
436
|
+
.time-dial {
|
|
437
|
+
user-select: none;
|
|
438
|
+
-webkit-user-select: none;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/* Scrollbar styling for dropdown */
|
|
442
|
+
.time-dropdown-content {
|
|
443
|
+
scrollbar-width: thin;
|
|
444
|
+
scrollbar-color: var(--input) transparent;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
.time-dropdown-content::-webkit-scrollbar {
|
|
448
|
+
width: 4px;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
.time-dropdown-content::-webkit-scrollbar-thumb {
|
|
452
|
+
background: var(--input);
|
|
453
|
+
border-radius: 9999px;
|
|
454
|
+
}
|
|
455
|
+
</style>
|