@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
@@ -1,26 +1,26 @@
1
1
  <script module lang="ts">
2
- import type { InputControllerConfig } from './index';
3
- import type { SliderProps } from '@widgetic/design-system/components';
2
+ import type { InputControllerConfig } from './index';
3
+ import type { SliderProps } from '@widgetic/design-system/components';
4
4
 
5
5
  /** Declared props contract — export lets below are annotated from it so the
6
6
  * interface cannot drift from what the component actually reads. */
7
- export interface SliderInputControllerProps {
8
- height?: number;
9
- elementsGap?: number;
10
- thumbSize?: number;
11
- sliderType?: SliderProps['type'];
12
- barHeight?: number;
13
- label?: string;
14
- value: number | number[];
15
- onChange: (newValue: number | number[]) => void;
16
- config?: InputControllerConfig;
17
- helpText?: string;
18
- min?: number;
19
- max?: number;
20
- step?: number;
21
- onFocus?: () => void;
22
- autofocus?: boolean;
23
- }
7
+ export interface SliderInputControllerProps {
8
+ height?: number;
9
+ elementsGap?: number;
10
+ thumbSize?: number;
11
+ sliderType?: SliderProps['type'];
12
+ barHeight?: number;
13
+ label?: string;
14
+ value: number | number[];
15
+ onChange: (newValue: number | number[]) => void;
16
+ config?: InputControllerConfig;
17
+ helpText?: string;
18
+ min?: number;
19
+ max?: number;
20
+ step?: number;
21
+ onFocus?: () => void;
22
+ autofocus?: boolean;
23
+ }
24
24
  </script>
25
25
 
26
26
  <script lang="ts">
@@ -34,208 +34,183 @@
34
34
  * - Value clamping and validation
35
35
  * - Smart click positioning: center thumb at clicked position on track
36
36
  */
37
-
38
37
  // Svelte imports
39
- import { onMount, onDestroy } from 'svelte';
40
-
38
+ import { onMount, onDestroy } from 'svelte';
41
39
  /**
42
40
  * Shadcn UI components from Widgetic design-system package
43
41
  */
44
- import { Slider } from '@widgetic/design-system/components';
45
- import { useTextDirection } from '@widgetic/design-system/components/textDirection';
46
- import { InputControllerHeader } from './index';
42
+ import { Slider } from '@widgetic/design-system/components';
43
+ import { useTextDirection } from '@widgetic/design-system/components/textDirection';
44
+ import InputControllerRow from './InputControllerRow.svelte';
47
45
 
48
46
  // The way the screen is read: the slider of the design system starts at the right end on a right to left screen.
49
- const textDirection = useTextDirection();
50
-
47
+ const textDirection = useTextDirection();
51
48
 
52
49
  /**
53
50
  * Component Props
54
51
  * External properties that configure the slider's behavior
55
52
  */
56
- let className = '';
57
- export { className as class };
58
- export let height: SliderInputControllerProps['height'] = 48;
59
- export let elementsGap: SliderInputControllerProps['elementsGap'] = 8;
60
- export let thumbSize: SliderInputControllerProps['thumbSize'] = 24;
61
- export let sliderType: SliderInputControllerProps['sliderType'] = "single";
62
- export let barHeight: SliderInputControllerProps['barHeight'] = 8;
63
- export let label: SliderInputControllerProps['label'] = '';
64
- export let value: SliderInputControllerProps['value'];
65
- export let onChange: SliderInputControllerProps['onChange'];
66
- export let config: SliderInputControllerProps['config'] = {};
67
- export let helpText: SliderInputControllerProps['helpText'] = undefined;
68
-
53
+ let className = '';
54
+ export { className as class };
55
+ export let height: SliderInputControllerProps['height'] = 36;
56
+ export let elementsGap: SliderInputControllerProps['elementsGap'] | undefined = undefined;
57
+ export let thumbSize: SliderInputControllerProps['thumbSize'] = 24;
58
+ export let sliderType: SliderInputControllerProps['sliderType'] = 'single';
59
+ export let barHeight: SliderInputControllerProps['barHeight'] = 8;
60
+ export let label: SliderInputControllerProps['label'] = '';
61
+ export let value: SliderInputControllerProps['value'];
62
+ export let onChange: SliderInputControllerProps['onChange'];
63
+ export let config: SliderInputControllerProps['config'] = {};
64
+ export let helpText: SliderInputControllerProps['helpText'] = undefined;
65
+
69
66
  /**
70
67
  * Configuration Options
71
68
  * Derived from config prop with fallbacks
72
69
  */
73
- export let min: SliderInputControllerProps['min'] = config.min || 0;
74
- export let max: SliderInputControllerProps['max'] = config.max || 100;
75
- export let step: SliderInputControllerProps['step'] = config.step || 1;
76
- export let onFocus: SliderInputControllerProps['onFocus'] = () => {};
77
- export let autofocus: SliderInputControllerProps['autofocus'] = false; // Auto-focus on mount
70
+ export let min: SliderInputControllerProps['min'] = config.min || 0;
71
+ export let max: SliderInputControllerProps['max'] = config.max || 100;
72
+ export let step: SliderInputControllerProps['step'] = config.step || 1;
73
+ export let onFocus: SliderInputControllerProps['onFocus'] = () => {};
74
+ export let autofocus: SliderInputControllerProps['autofocus'] = false;
78
75
 
79
- /**
80
- * Internal State
81
- * Tracks component state for focus and value management
82
- */
83
- let sliderContainer: HTMLDivElement; // Reference to container element
84
- let sliderTrack: HTMLDivElement; // Reference to slider track element
85
- let lastValue = value; // Previous value for change detection
86
- let isCurrentlyFocused = false; // Current focus state
87
- let isClickHandled = false; // Prevents double handling of clicks
76
+ let sliderContainer: HTMLDivElement;
77
+ let lastValue = value;
78
+ let isCurrentlyFocused = false;
79
+ let isClickHandled = false;
88
80
 
89
- /**
90
- * Layout Constants
91
- * Define dimensions for slider components
92
- */
93
- const valueDisplayWidth = 26; // pixels
81
+ const valueDisplayWidth = 28;
94
82
 
95
-
96
83
  /**
97
84
  * Component Initialization
98
85
  * Sets up focus handling and event listeners
99
86
  */
100
- onMount(() => {
87
+ onMount(() => {
101
88
  // console.log('SliderIC sliderType:', sliderType, sliderValue);
102
89
  // Handle autofocus if enabled
103
- if (autofocus && sliderContainer) {
104
- const thumbElement = sliderContainer.querySelector('[role="slider"]');
105
- if (thumbElement instanceof HTMLElement) {
106
- thumbElement.focus();
107
- handleFocus();
108
- }
109
- }
90
+ if (autofocus && sliderContainer) {
91
+ const thumbElement = sliderContainer.querySelector('[role="slider"]');
92
+ if (thumbElement instanceof HTMLElement) {
93
+ thumbElement.focus();
94
+ // Focus the slider
95
+ handleFocus();
96
+ }
97
+ }
110
98
 
111
- // Add mousedown handler to the slider component for track click positioning
112
- const sliderElement = sliderContainer.querySelector('.slider-component');
113
- if (sliderElement) {
114
- sliderElement.addEventListener('mousedown', handleSliderMouseDown);
115
- }
99
+ const sliderElement = sliderContainer?.querySelector('.slider-component');
100
+ // Clean up slider mousedown listener
101
+ if (sliderElement) {
102
+ sliderElement.addEventListener('mousedown', handleSliderMouseDown);
103
+ }
116
104
 
117
105
  /**
118
106
  * Blur Event Handler
119
107
  * Resets focus state when focus leaves the component
120
108
  */
121
- const handleBlur = (e: FocusEvent) => {
122
- if (!sliderContainer.contains(e.relatedTarget as Node)) {
123
- isCurrentlyFocused = false;
124
- }
125
- };
126
-
127
- sliderContainer.addEventListener('blur', handleBlur, true);
128
-
109
+ const handleBlur = (e: FocusEvent) => {
110
+ if (!sliderContainer.contains(e.relatedTarget as Node)) {
111
+ isCurrentlyFocused = false;
112
+ }
113
+ };
114
+
115
+ sliderContainer.addEventListener('blur', handleBlur, true);
116
+
129
117
  // Add global mouse up handler to reset click state
130
- const handleGlobalMouseUp = () => {
131
- isClickHandled = false;
132
- };
133
-
134
- document.addEventListener('mouseup', handleGlobalMouseUp);
135
-
136
- return () => {
137
- sliderContainer.removeEventListener('blur', handleBlur, true);
138
- document.removeEventListener('mouseup', handleGlobalMouseUp);
139
-
140
- // Clean up slider mousedown listener
141
- if (sliderElement) {
142
- sliderElement.removeEventListener('mousedown', handleSliderMouseDown);
143
- }
144
- };
145
- });
118
+ const handleGlobalMouseUp = () => {
119
+ isClickHandled = false;
120
+ };
121
+
122
+ document.addEventListener('mouseup', handleGlobalMouseUp);
123
+
124
+ return () => {
125
+ sliderContainer.removeEventListener('blur', handleBlur, true);
126
+ document.removeEventListener('mouseup', handleGlobalMouseUp);
127
+ if (sliderElement) {
128
+ sliderElement.removeEventListener('mousedown', handleSliderMouseDown);
129
+ }
130
+ };
131
+ });
146
132
 
147
- onDestroy(() => {
148
- isClickHandled = false;
149
- });
133
+ onDestroy(() => {
134
+ isClickHandled = false;
135
+ });
150
136
 
151
137
  /**
152
138
  * Value Change Handler
153
139
  * Updates value and manages focus state
154
140
  * @param newValue - New slider value(s)
155
141
  */
156
- function handleChange(newValue: number | number[]) {
157
- // Only trigger focus if value actually changed and we're not already focused
158
- if ((newValue !== lastValue) && !isCurrentlyFocused) {
159
- handleFocus();
160
- isCurrentlyFocused = true;
161
- }
162
-
142
+ function handleChange(newValue: number | number[]) {
143
+ if (newValue !== lastValue && !isCurrentlyFocused) {
144
+ handleFocus();
145
+ isCurrentlyFocused = true;
146
+ }
163
147
  // call the onChange callback
164
- onChange(newValue);
165
-
148
+ onChange(newValue);
166
149
  // update the lastValue
167
- lastValue = newValue;
168
- }
150
+ lastValue = newValue;
151
+ }
169
152
 
170
153
  /**
171
154
  * Custom Track Click Handler
172
155
  * Positions the thumb so that the clicked point becomes the center of the thumb
173
156
  * @param event - Mouse event (cast to MouseEvent internally)
174
157
  */
175
- function handleSliderMouseDown(event: Event) {
176
- if (isClickHandled) return;
177
-
158
+ function handleSliderMouseDown(event: Event) {
159
+ // Click was on thumb, let it handle normally
160
+ if (isClickHandled) return;
161
+
178
162
  // Cast event to MouseEvent
179
- const mouseEvent = event as MouseEvent;
180
-
163
+ const mouseEvent = event as MouseEvent;
181
164
  // Check if click was on the thumb itself
182
- const target = mouseEvent.target as HTMLElement;
183
- if (target.getAttribute('role') === 'slider') {
184
- // Click was on thumb, let it handle normally
185
- return;
186
- }
165
+ const target = mouseEvent.target as HTMLElement;
166
+ if (target.getAttribute('role') === 'slider') {
167
+ return;
168
+ }
187
169
 
188
170
  // This was a click on the track, so we'll position the thumb
189
- const sliderElement = sliderContainer.querySelector('.slider-component');
190
- if (!sliderElement) return;
171
+ // Add mousedown handler to the slider component for track click positioning
172
+ const sliderElement = sliderContainer.querySelector('.slider-component');
173
+ if (!sliderElement) return;
191
174
 
192
- const rect = sliderElement.getBoundingClientRect();
193
- // The distance from the end where the track starts: its left end, or its right end when the screen is read from the right
194
- const clickX = $textDirection === 'rtl' ? rect.right - mouseEvent.clientX : mouseEvent.clientX - rect.left;
195
- const trackWidth = rect.width;
175
+ const rect = sliderElement.getBoundingClientRect();
176
+ const clickX =
177
+ $textDirection === 'rtl' ? rect.right - mouseEvent.clientX : mouseEvent.clientX - rect.left;
178
+ const trackWidth = rect.width;
196
179
 
197
180
  // Calculate the percentage position of the click
198
- let percentage = (clickX / trackWidth) * 100;
199
-
181
+ let percentage = (clickX / trackWidth) * 100;
200
182
  // Clamp to valid range
201
- percentage = Math.max(0, Math.min(100, percentage));
202
-
183
+ percentage = Math.max(0, Math.min(100, percentage));
184
+
203
185
  // Convert percentage to value
204
- const rawValue = min + (percentage / 100) * (max - min);
205
-
186
+ const rawValue = min + (percentage / 100) * (max - min);
206
187
  // Round to nearest step
207
- const steppedValue = Math.round((rawValue - min) / step) * step + min;
208
-
188
+ const steppedValue = Math.round((rawValue - min) / step) * step + min;
209
189
  // Ensure value is within bounds
210
- const clampedValue = Math.max(min, Math.min(max, steppedValue));
190
+ const clampedValue = Math.max(min, Math.min(max, steppedValue));
211
191
 
212
192
  // Handle different slider types
213
- if (sliderType === 'single') {
214
- handleChange(clampedValue);
215
- } else if (sliderType === 'multiple' && Array.isArray(value)) {
193
+ if (sliderType === 'single') {
194
+ handleChange(clampedValue);
195
+ } else if (sliderType === 'multiple' && Array.isArray(value)) {
216
196
  // For range sliders, determine which thumb to move based on proximity
217
- const currentValue = value as [number, number];
218
- const distanceToStart = Math.abs(clampedValue - currentValue[0]);
219
- const distanceToEnd = Math.abs(clampedValue - currentValue[1]);
220
-
221
- if (distanceToStart < distanceToEnd) {
197
+ const currentValue = value as [number, number];
198
+ const distanceToStart = Math.abs(clampedValue - currentValue[0]);
199
+ const distanceToEnd = Math.abs(clampedValue - currentValue[1]);
200
+
201
+ if (distanceToStart < distanceToEnd) {
222
202
  // Move start thumb
223
- handleChange([clampedValue, currentValue[1]]);
224
- } else {
203
+ handleChange([clampedValue, currentValue[1]]);
204
+ } else {
225
205
  // Move end thumb
226
- handleChange([currentValue[0], clampedValue]);
227
- }
228
- }
206
+ handleChange([currentValue[0], clampedValue]);
207
+ }
208
+ }
229
209
 
230
210
  // Mark click as handled
231
- isClickHandled = true;
232
-
233
- // Focus the slider
234
- handleFocus();
235
-
236
- // Allow the event to continue to the slider component for drag handling
237
- // Don't prevent default or stop propagation
238
- }
211
+ isClickHandled = true;
212
+ handleFocus();
213
+ }
239
214
 
240
215
  /**
241
216
  * Value Formatting
@@ -243,197 +218,153 @@
243
218
  * @param val - Number to format
244
219
  * @returns Formatted string representation
245
220
  */
246
- function formatValue(val: number | undefined): string {
247
- if (val === undefined) return '';
248
- return val % 1 === 0 ? val.toFixed(0) : val.toFixed(1);
249
- }
221
+ function formatValue(val: number | undefined): string {
222
+ if (val === undefined) return '';
223
+ return val % 1 === 0 ? val.toFixed(0) : val.toFixed(1);
224
+ }
250
225
 
251
226
  /**
252
227
  * Focus Handler
253
228
  * Manages focus state and triggers focus callback
254
229
  */
255
- function handleFocus() {
256
- if (!isCurrentlyFocused) {
230
+ function handleFocus() {
231
+ if (!isCurrentlyFocused) {
257
232
  // console.log('Slider focused through interaction, value:', lastValue);
258
- onFocus();
259
- isCurrentlyFocused = true;
260
- }
261
- }
262
-
263
- // Reactive slider value derived from prop or min value
264
- $: sliderValue = sliderType === 'single'
265
- ? (typeof value === 'number' ? value : min)
266
- : (Array.isArray(value) ? value : [min, max]);
233
+ onFocus();
234
+ isCurrentlyFocused = true;
235
+ }
236
+ }
237
+
238
+ $: sliderValue =
239
+ sliderType === 'single'
240
+ ? typeof value === 'number'
241
+ ? value
242
+ : min
243
+ : Array.isArray(value)
244
+ ? value
245
+ : [min, max];
267
246
 
268
247
  // Helper function to safely get array value
269
- function getArrayValue(arr: number | number[], index: number): number {
270
- if (Array.isArray(arr)) {
271
- return arr[index] ?? min;
272
- }
273
- return arr;
274
- }
248
+ function getArrayValue(arr: number | number[], index: number): number {
249
+ if (Array.isArray(arr)) {
250
+ return arr[index] ?? min;
251
+ }
252
+ return arr;
253
+ }
275
254
 
276
255
  // Update lastValue when prop changes
277
- $: if (value !== undefined) {
278
- lastValue = value;
279
- }
280
-
281
- /**
282
- * Input Field Handlers
283
- * Manage direct numeric input
284
- */
285
- function handleInputChange(event: Event) {
286
- const input = event.target as HTMLInputElement;
287
- let newValue = parseFloat(input.value);
288
-
289
- // Validate input
290
- if (input.value === '' || isNaN(newValue)) {
291
- return;
292
- }
293
-
294
- // Clamp value within bounds
295
- newValue = Math.min(Math.max(newValue, min), max);
296
-
297
- // update the input value
298
- input.value = newValue.toString();
299
-
300
- // call the onChange callback
301
- handleChange(newValue);
302
- }
303
-
304
- /**
305
- * Input Blur Handler
306
- * Validates and normalizes input on blur
307
- */
308
- function handleInputBlur(event: Event) {
309
- const input = event.target as HTMLInputElement;
310
-
311
- if (input.value === '') {
312
- input.value = value?.toString() || min.toString();
313
- return;
314
- }
315
-
316
- let newValue = parseFloat(input.value);
317
- if (isNaN(newValue)) {
318
- input.value = value?.toString() || min.toString();
319
- } else {
320
- newValue = Math.min(Math.max(newValue, min), max);
321
- input.value = newValue.toString();
322
-
323
- // call the handleChange function
324
- handleChange(newValue);
325
- }
326
- }
256
+ $: if (value !== undefined) {
257
+ lastValue = value;
258
+ }
259
+
260
+ $: displayIndex = sliderType === 'multiple' ? 1 : 0;
261
+ $: rowGap = elementsGap ?? (sliderType === 'multiple' ? 8 : 12);
262
+ $: rowClass =
263
+ 'slider-input-controller slider-main-container flex h-9 w-full items-center transition-colors duration-fast disabled:pointer-events-none disabled:opacity-50 ' +
264
+ className;
327
265
  </script>
328
266
 
329
- <!-- Slider Input Controller -->
330
- <div class="slider-input-controller{className ? className + ' ' : ''} w-full flex flex-col widgetic-colors" style="gap: {elementsGap}px;">
331
267
  <!-- Header -->
332
- {#if label}
333
- <InputControllerHeader class="flex-1 min-w-0" style="height: {height}px;" {label} helpText={helpText} />
334
- {/if}
335
-
268
+ {#if label}
269
+ <InputControllerRow {label} {helpText}>
270
+ <!-- Slider Container with Extensions -->
336
271
  <!-- Main Container with subcomponents -->
337
- <div
338
- class="slider-main-container flex items-center justify-between rounded-large transition-colors duration-200"
339
- style="height: {height}px; padding-inline-start: 16px; padding-inline-end: 16px; gap: {elementsGap}px; border: 1px solid hsl(var(--grey2)); background: hsl(var(--grey1));"
340
- onfocusin={onFocus}
341
- bind:this={sliderContainer}
342
- >
272
+ <div
273
+ class={rowClass}
274
+ style="min-height: {height}px; gap: {rowGap}px;"
275
+ data-thumb-size={thumbSize}
276
+ data-bar-height={barHeight}
277
+ onfocusin={onFocus}
278
+ bind:this={sliderContainer}
279
+ >
343
280
  <!-- Min Value Display -->
344
- {#if sliderType === 'multiple'}
345
- <span style="width: {valueDisplayWidth}px; color: hsl(var(--grey7));" class="value-display flex-none subtext text-center">
346
- {formatValue(getArrayValue(sliderValue, 0))}
347
- </span>
348
- {/if}
349
-
350
- <!-- Slider Container with Extensions -->
351
- <div
352
- class="slider-container relative h-full flex items-center"
353
- style="width: calc(100% - {(sliderType === 'multiple' ? 2 : 1) * (valueDisplayWidth + elementsGap)}px);"
354
- bind:this={sliderTrack}
355
- >
281
+ {#if sliderType === 'multiple'}
282
+ <span
283
+ class="value-display shrink-0 text-center text-body text-foreground"
284
+ style="width: {valueDisplayWidth}px;"
285
+ >
286
+ {formatValue(getArrayValue(sliderValue, 0))}
287
+ </span>
288
+ {/if}
289
+
290
+ <div class="relative flex min-w-0 flex-1 items-center">
356
291
  <!-- Slider Component -->
357
- <svelte:component
358
- this={Slider}
359
- {...{
360
- type: sliderType,
361
- value: sliderValue,
362
- onValueChange: handleChange,
363
- min,
364
- max,
365
- step,
366
- class: "slider-component relative",
367
- style: `--thumb-size: ${thumbSize}px; --bar-height: ${barHeight}px; z-index: 3;`,
368
- tabindex: -1,
369
- } as SliderProps}
370
- />
371
- </div>
372
-
373
- <!-- Max Value Display -->
374
- <span style="width: {valueDisplayWidth}px; color: hsl(var(--grey7));" class="value-display flex-none subtext text-center">
375
- {formatValue(getArrayValue(sliderValue, sliderType === 'multiple' ? 1 : 0))}
376
- </span>
377
-
378
- </div>
379
- </div>
292
+ <svelte:component
293
+ this={Slider}
294
+ {...{
295
+ type: sliderType,
296
+ value: sliderValue,
297
+ onValueChange: handleChange,
298
+ min,
299
+ max,
300
+ step,
301
+ class: 'slider-component w-full',
302
+ tabindex: -1
303
+ } as SliderProps}
304
+ />
305
+ </div>
306
+
307
+ <span
308
+ class="value-display shrink-0 text-end text-body text-foreground"
309
+ style="width: {valueDisplayWidth}px;"
310
+ >
311
+ {formatValue(getArrayValue(sliderValue, displayIndex))}
312
+ </span>
313
+ </div>
314
+ </InputControllerRow>
315
+ {:else}
316
+ <div
317
+ class={rowClass}
318
+ style="min-height: {height}px; gap: {rowGap}px;"
319
+ data-thumb-size={thumbSize}
320
+ data-bar-height={barHeight}
321
+ onfocusin={onFocus}
322
+ bind:this={sliderContainer}
323
+ >
324
+ {#if sliderType === 'multiple'}
325
+ <span
326
+ class="value-display shrink-0 text-center text-body text-foreground"
327
+ style="width: {valueDisplayWidth}px;"
328
+ >
329
+ {formatValue(getArrayValue(sliderValue, 0))}
330
+ </span>
331
+ {/if}
332
+
333
+ <div class="relative flex min-w-0 flex-1 items-center">
334
+ <svelte:component
335
+ this={Slider}
336
+ {...{
337
+ type: sliderType,
338
+ value: sliderValue,
339
+ onValueChange: handleChange,
340
+ min,
341
+ max,
342
+ step,
343
+ class: 'slider-component w-full',
344
+ tabindex: -1
345
+ } as SliderProps}
346
+ />
347
+ </div>
348
+
349
+ <span
350
+ class="value-display shrink-0 text-end text-body text-foreground"
351
+ style="width: {valueDisplayWidth}px;"
352
+ >
353
+ {formatValue(getArrayValue(sliderValue, displayIndex))}
354
+ </span>
355
+ </div>
356
+ {/if}
380
357
 
381
358
  <style>
382
- .slider-main-container:hover {
383
- border-color: hsl(var(--forest-green));
384
- }
385
-
386
- .value-display {
387
- user-select: none;
388
- }
389
-
390
- /* THUMB Styles */
391
- :global(.slider-component [role="slider"]) {
392
- outline: none !important;
393
- cursor: grab;
394
- width: var(--thumb-size) !important;
395
- height: var(--thumb-size) !important;
396
- background-color: white !important;
397
- border: 2px solid hsl(var(--grey5)) !important;
398
- box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1) !important;
399
- pointer-events: auto !important;
400
- }
401
-
402
- :global(.slider-component [role="slider"]:active) {
403
- cursor: grabbing;
404
- }
405
-
406
- :global(.slider-component [role="slider"]:hover) {
407
- border-color: hsl(var(--grey7)) !important;
408
- }
409
-
410
- /* Remove focus outline while maintaining accessibility */
411
- :global(.slider-component [role="slider"]:focus),
412
- :global(.slider-component [role="slider"]:focus-visible) {
413
- outline: none !important;
414
- box-shadow: none !important;
415
- }
416
-
417
- /* TRACK BAR Styles */
418
- :global(.slider-component .bg-secondary) {
419
- background-color: hsl(var(--grey5)) !important;
420
- height: var(--bar-height) !important;
421
- border-radius: var(--bar-height) !important; /* rounded ends */
422
- cursor: pointer !important;
423
- }
424
-
425
- /* PROGRESS BAR Styles */
426
- :global(.slider-component [data-slider-range]) {
427
- background-color: hsl(var(--grey7)) !important;
428
- cursor: pointer !important;
429
- }
430
-
431
- /* Thumb should override track cursor when hovering */
432
- :global(.slider-component [role="slider"]:hover) {
433
- cursor: grab !important;
434
- }
435
-
436
- :global(.slider-component [role="slider"]:active) {
437
- cursor: grabbing !important;
438
- }
359
+ .value-display {
360
+ user-select: none;
361
+ }
362
+
363
+ :global(.slider-component [role='slider']) {
364
+ cursor: grab;
365
+ }
366
+
367
+ :global(.slider-component [role='slider']:active) {
368
+ cursor: grabbing;
369
+ }
439
370
  </style>