poe-svelte-ui-lib 0.2.0 → 1.0.0

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 (73) hide show
  1. package/dist/Accordion/Accordion.svelte +53 -0
  2. package/dist/Accordion/Accordion.svelte.d.ts +4 -0
  3. package/dist/Accordion/AccordionProps.svelte +70 -0
  4. package/dist/Accordion/AccordionProps.svelte.d.ts +10 -0
  5. package/dist/{Button.svelte → Button/Button.svelte} +43 -24
  6. package/dist/{Button.svelte.d.ts → Button/Button.svelte.d.ts} +5 -5
  7. package/dist/Button/ButtonProps.svelte +200 -0
  8. package/dist/Button/ButtonProps.svelte.d.ts +10 -0
  9. package/dist/ColorPicker/ColorPicker.svelte +207 -0
  10. package/dist/ColorPicker/ColorPicker.svelte.d.ts +4 -0
  11. package/dist/ColorPicker/ColorPickerProps.svelte +100 -0
  12. package/dist/ColorPicker/ColorPickerProps.svelte.d.ts +10 -0
  13. package/dist/FileAttach/FileAttach.svelte +103 -0
  14. package/dist/FileAttach/FileAttach.svelte.d.ts +22 -0
  15. package/dist/Graph/Graph.svelte +270 -0
  16. package/dist/Graph/Graph.svelte.d.ts +4 -0
  17. package/dist/Graph/GraphProps.svelte +56 -0
  18. package/dist/Graph/GraphProps.svelte.d.ts +10 -0
  19. package/dist/Input/Input.svelte +239 -0
  20. package/dist/Input/Input.svelte.d.ts +4 -0
  21. package/dist/Input/InputProps.svelte +221 -0
  22. package/dist/Input/InputProps.svelte.d.ts +10 -0
  23. package/dist/Loader.svelte +12 -0
  24. package/dist/Loader.svelte.d.ts +5 -0
  25. package/dist/MessageModal.svelte +54 -0
  26. package/dist/MessageModal.svelte.d.ts +10 -0
  27. package/dist/ProgressBar/ProgressBar.svelte +48 -0
  28. package/dist/ProgressBar/ProgressBar.svelte.d.ts +4 -0
  29. package/dist/ProgressBar/ProgressBarProps.svelte +145 -0
  30. package/dist/ProgressBar/ProgressBarProps.svelte.d.ts +10 -0
  31. package/dist/Select/Select.svelte +187 -0
  32. package/dist/Select/Select.svelte.d.ts +18 -0
  33. package/dist/Select/SelectProps.svelte +260 -0
  34. package/dist/Select/SelectProps.svelte.d.ts +10 -0
  35. package/dist/Slider/Slider.svelte +260 -0
  36. package/dist/Slider/Slider.svelte.d.ts +4 -0
  37. package/dist/Slider/SliderProps.svelte +161 -0
  38. package/dist/Slider/SliderProps.svelte.d.ts +10 -0
  39. package/dist/Switch/Switch.svelte +83 -0
  40. package/dist/Switch/Switch.svelte.d.ts +4 -0
  41. package/dist/Switch/SwitchProps.svelte +144 -0
  42. package/dist/Switch/SwitchProps.svelte.d.ts +10 -0
  43. package/dist/Table/Table.svelte +276 -0
  44. package/dist/Table/Table.svelte.d.ts +4 -0
  45. package/dist/Table/TableProps.svelte +286 -0
  46. package/dist/Table/TableProps.svelte.d.ts +10 -0
  47. package/dist/TextField/TextField.svelte +22 -0
  48. package/dist/TextField/TextField.svelte.d.ts +4 -0
  49. package/dist/TextField/TextFieldProps.svelte +92 -0
  50. package/dist/TextField/TextFieldProps.svelte.d.ts +10 -0
  51. package/dist/appIcons/ButtonAdd.svelte +10 -0
  52. package/dist/appIcons/ButtonAdd.svelte.d.ts +18 -0
  53. package/dist/appIcons/ButtonDelete.svelte +13 -0
  54. package/dist/appIcons/ButtonDelete.svelte.d.ts +18 -0
  55. package/dist/appIcons/LoaderRotate.svelte +9 -0
  56. package/dist/appIcons/LoaderRotate.svelte.d.ts +18 -0
  57. package/dist/index.d.ts +26 -1
  58. package/dist/index.js +27 -2
  59. package/dist/locales/CircleFlagsEn.svelte +14 -0
  60. package/dist/locales/CircleFlagsEn.svelte.d.ts +26 -0
  61. package/dist/locales/CircleFlagsRu.svelte +8 -0
  62. package/dist/locales/CircleFlagsRu.svelte.d.ts +26 -0
  63. package/dist/locales/CircleFlagsZh.svelte +8 -0
  64. package/dist/locales/CircleFlagsZh.svelte.d.ts +26 -0
  65. package/dist/locales/i18n.d.ts +10 -0
  66. package/dist/locales/i18n.js +36 -0
  67. package/dist/locales/translations.d.ts +7 -0
  68. package/dist/locales/translations.js +450 -0
  69. package/dist/options.d.ts +78 -0
  70. package/dist/options.js +71 -0
  71. package/dist/types.d.ts +284 -0
  72. package/dist/types.js +1 -0
  73. package/package.json +28 -21
@@ -0,0 +1,260 @@
1
+ <!-- $lib/ElementsUI/Slider.svelte -->
2
+ <script lang="ts">
3
+ import type { ISliderProps } from '../types'
4
+
5
+ let {
6
+ id = { name: '', value: crypto.randomUUID() },
7
+ wrapperClass = '',
8
+ label = { name: '', class: '' },
9
+ type = 'single',
10
+ value = 0,
11
+ number = { minNum: 0, maxNum: 10, step: 1 },
12
+ disabled = false,
13
+ onUpdate = () => {},
14
+ }: ISliderProps = $props()
15
+
16
+ const isRange = $derived(type === 'range' || (Array.isArray(value) && value.length === 2))
17
+
18
+ const maxDigits = String(number.maxNum ?? 100).length
19
+ const valueWidth = `${maxDigits + 1}ch` /* +1 на запас */
20
+
21
+ /* Инициализация значений с проверкой типа */
22
+ let singleValue = $derived(!isRange && typeof value === 'number' ? value : number.minNum)
23
+ let lowerValue = $derived(isRange && Array.isArray(value) ? value[0] : number.minNum)
24
+ let upperValue = $derived(isRange && Array.isArray(value) ? value[1] : number.maxNum)
25
+
26
+ /* Расчет позиций */
27
+ const singlePosition = $derived(((singleValue - number.minNum) / (number.maxNum - number.minNum)) * 100)
28
+ const lowerPosition = $derived(((lowerValue - number.minNum) / (number.maxNum - number.minNum)) * 100)
29
+ const upperPosition = $derived(((upperValue - number.minNum) / (number.maxNum - number.minNum)) * 100)
30
+
31
+ $effect(() => {
32
+ if (value === undefined || value === null) {
33
+ if (type === 'single' && !value) value = number.minNum
34
+ if (type === 'range' && !value) value = [number.minNum, number.maxNum]
35
+ }
36
+ })
37
+
38
+ const adjustValue = (target: 'lower' | 'upper' | 'single', direction: 'increment' | 'decrement') => {
39
+ const stepValue = direction === 'increment' ? number.step : -number.step
40
+ if (isRange && target !== 'single') {
41
+ if (target === 'lower') {
42
+ lowerValue = Math.max(number.minNum, Math.min(lowerValue + stepValue, upperValue))
43
+ } else {
44
+ upperValue = Math.min(number.maxNum, Math.max(upperValue + stepValue, lowerValue))
45
+ }
46
+ onUpdate([lowerValue, upperValue])
47
+ } else {
48
+ singleValue = Math.max(number.minNum, Math.min(singleValue + stepValue, number.maxNum))
49
+ onUpdate(singleValue)
50
+ }
51
+ }
52
+
53
+ $effect(() => {
54
+ if (Array.isArray(value)) {
55
+ lowerValue = value[0]
56
+ upperValue = value[1]
57
+ } else if (typeof value === 'number') {
58
+ singleValue = value
59
+ }
60
+ })
61
+
62
+ let activeThumb = $state<'lower' | 'upper'>('lower')
63
+ const handleTrackClick = (e: MouseEvent) => {
64
+ e.stopPropagation()
65
+ const track = e.currentTarget as HTMLElement
66
+ const rect = track.getBoundingClientRect()
67
+ const clickPercent = ((e.clientX - rect.left) / rect.width) * 100
68
+ const rawValue = number.minNum + (clickPercent / 100) * (number.maxNum - number.minNum)
69
+ const clickValue = Math.round((rawValue - number.minNum) / number.step) * number.step + number.minNum
70
+
71
+ if (isRange) {
72
+ const lowerDiff = Math.abs(clickValue - lowerValue)
73
+ const upperDiff = Math.abs(clickValue - upperValue)
74
+
75
+ activeThumb = lowerDiff < upperDiff ? 'lower' : 'upper'
76
+
77
+ if (activeThumb === 'lower') {
78
+ lowerValue = Math.max(number.minNum, Math.min(clickValue, upperValue))
79
+ } else {
80
+ upperValue = Math.min(number.maxNum, Math.max(clickValue, lowerValue))
81
+ }
82
+
83
+ onUpdate([lowerValue, upperValue])
84
+ } else {
85
+ singleValue = Math.max(number.minNum, Math.min(clickValue, number.maxNum))
86
+ onUpdate(singleValue)
87
+ }
88
+ }
89
+ </script>
90
+
91
+ <div class={`relative flex w-full flex-col items-center gap-2 ${wrapperClass}`}>
92
+ {#if label.name}
93
+ <h5 class={`w-full px-4 text-center ${label.class}`}>{label.name}</h5>
94
+ {/if}
95
+
96
+ <!-- Слайдер -->
97
+ <div class="relative flex h-2 w-full justify-center {disabled ? 'opacity-50' : ''}" id={id.value}>
98
+ {#if isRange}
99
+ <!-- Трек и активная зона -->
100
+ <div
101
+ class={`absolute h-full w-full rounded bg-gray-400 ${disabled ? '' : 'cursor-pointer'}`}
102
+ role="button"
103
+ tabindex={null}
104
+ onkeydown={null}
105
+ onclick={disabled ? undefined : handleTrackClick}
106
+ >
107
+ <div class="absolute h-full rounded" style={`left: ${lowerPosition}%; right: ${100 - upperPosition}%; background-color: var(--bg-color)`}></div>
108
+ </div>
109
+
110
+ <!-- Ползунки -->
111
+ <input
112
+ type="range"
113
+ min={number.minNum}
114
+ max={number.maxNum}
115
+ step={number.step}
116
+ bind:value={lowerValue}
117
+ oninput={disabled
118
+ ? undefined
119
+ : (e) => {
120
+ const newValue = Math.min(Number((e.target as HTMLInputElement).value), upperValue)
121
+ lowerValue = newValue
122
+ activeThumb = 'lower'
123
+ }}
124
+ onmouseup={disabled ? undefined : () => onUpdate([lowerValue, upperValue])}
125
+ {disabled}
126
+ class={`absolute h-full w-full appearance-none bg-transparent ${activeThumb === 'lower' ? 'z-30' : 'z-20'}`}
127
+ />
128
+
129
+ <input
130
+ type="range"
131
+ min={number.minNum}
132
+ max={number.maxNum}
133
+ step={number.step}
134
+ bind:value={upperValue}
135
+ oninput={disabled
136
+ ? undefined
137
+ : (e) => {
138
+ const newValue = Math.max(Number((e.target as HTMLInputElement).value), lowerValue)
139
+ upperValue = newValue
140
+ activeThumb = 'upper'
141
+ }}
142
+ onmouseup={disabled ? undefined : () => onUpdate([lowerValue, upperValue])}
143
+ {disabled}
144
+ class={`absolute h-full w-full appearance-none bg-transparent ${activeThumb === 'upper' ? 'z-30' : 'z-20'}`}
145
+ />
146
+ {:else}
147
+ <!-- Одиночный слайдер -->
148
+ <div
149
+ class={`absolute h-full w-full rounded bg-gray-400 ${disabled ? '' : 'cursor-pointer'}`}
150
+ role="button"
151
+ tabindex={null}
152
+ onkeydown={null}
153
+ onclick={disabled ? undefined : handleTrackClick}
154
+ >
155
+ <div class="absolute h-full rounded" style={`width: ${singlePosition}%; background-color: var(--bg-color)`}></div>
156
+ </div>
157
+
158
+ <input
159
+ type="range"
160
+ min={number.minNum}
161
+ max={number.maxNum}
162
+ step={number.step}
163
+ bind:value={singleValue}
164
+ oninput={disabled
165
+ ? undefined
166
+ : (e) => {
167
+ singleValue = Number((e.target as HTMLInputElement).value)
168
+ }}
169
+ onmouseup={disabled ? undefined : () => onUpdate(singleValue)}
170
+ {disabled}
171
+ class="absolute z-30 h-full w-full appearance-none bg-transparent"
172
+ />
173
+ {/if}
174
+ </div>
175
+
176
+ <!-- Кнопки управления -->
177
+ <div class={`flex w-full ${isRange ? 'justify-between' : 'justify-center'} gap-2`}>
178
+ {#if isRange}
179
+ {#each ['lower', 'upper'] as type (type)}
180
+ <div class={`flex items-center justify-center gap-2 rounded-full px-2 ${disabled ? 'opacity-70' : ''}`} style="background-color: var(--bg-color)">
181
+ <button
182
+ class="h-full w-4 {disabled ? '' : 'cursor-pointer'}"
183
+ onclick={disabled ? undefined : () => adjustValue(type as 'lower' | 'upper', 'decrement')}
184
+ disabled={disabled || (type === 'lower' ? lowerValue <= number.minNum : upperValue <= lowerValue)}>−</button
185
+ >
186
+ <span class="inline-block text-center tabular-nums" style={`width: ${valueWidth}`}>
187
+ {type === 'lower' ? lowerValue : upperValue}
188
+ </span>
189
+ <button
190
+ class="h-full w-4 {disabled ? '' : 'cursor-pointer'}"
191
+ onclick={disabled ? undefined : () => adjustValue(type as 'lower' | 'upper', 'increment')}
192
+ disabled={disabled || (type === 'lower' ? lowerValue >= upperValue : upperValue >= number.maxNum)}>+</button
193
+ >
194
+ </div>
195
+ {/each}
196
+ {:else}
197
+ <div class={`flex items-center justify-center gap-2 rounded-full px-2 ${disabled ? 'opacity-70' : ''}`} style="background-color: var(--bg-color)">
198
+ <button
199
+ class="h-full w-4 {disabled ? '' : 'cursor-pointer'}"
200
+ onclick={disabled ? undefined : () => adjustValue('single', 'decrement')}
201
+ disabled={disabled || singleValue <= number.minNum}>−</button
202
+ >
203
+ <span class="inline-block text-center tabular-nums" style={`width: ${valueWidth}`}>
204
+ {singleValue}
205
+ </span>
206
+ <button
207
+ class="h-full w-4 {disabled ? '' : 'cursor-pointer'}"
208
+ onclick={disabled ? undefined : () => adjustValue('single', 'increment')}
209
+ disabled={disabled || singleValue >= number.maxNum}>+</button
210
+ >
211
+ </div>
212
+ {/if}
213
+ </div>
214
+ </div>
215
+
216
+ <!-- <style>
217
+ input[type='range'] {
218
+ -webkit-appearance: none;
219
+ appearance: none;
220
+ margin: 0;
221
+ padding: 0;
222
+ pointer-events: none;
223
+ }
224
+
225
+ input[type='range']:disabled::-webkit-slider-thumb {
226
+ cursor: auto;
227
+ }
228
+
229
+ input[type='range']::-webkit-slider-thumb {
230
+ -webkit-appearance: none;
231
+ appearance: none;
232
+ width: 1rem;
233
+ height: 1rem;
234
+ border-radius: 50%;
235
+ background: var(--border-color);
236
+ cursor: pointer;
237
+ pointer-events: auto;
238
+ transition: all 0.2s ease;
239
+ }
240
+
241
+ input[type='range']:disabled::-webkit-slider-thumb {
242
+ background: var(--gray-color);
243
+ }
244
+
245
+ input[type='range']::-moz-range-thumb {
246
+ width: 1rem;
247
+ height: 1rem;
248
+ border-radius: 50%;
249
+ background: var(--border-color);
250
+ cursor: pointer;
251
+ pointer-events: auto;
252
+ border: none;
253
+ transition: all 0.2s ease;
254
+ }
255
+
256
+ input[type='range']:disabled::-moz-range-thumb {
257
+ background: var(--gray-color);
258
+ cursor: not-allowed;
259
+ }
260
+ </style> -->
@@ -0,0 +1,4 @@
1
+ import type { ISliderProps } from '../types';
2
+ declare const Slider: import("svelte").Component<ISliderProps, {}, "">;
3
+ type Slider = ReturnType<typeof Slider>;
4
+ export default Slider;
@@ -0,0 +1,161 @@
1
+ <!-- $lib/ElementsUI/SwitchProps.svelte -->
2
+ <script lang="ts">
3
+ import { getContext } from 'svelte'
4
+ import { t } from '../locales/i18n'
5
+ import type { UIComponent, ISliderProps } from '../types'
6
+ import * as UI from '../index'
7
+ import { optionsStore } from '../options'
8
+
9
+ const { component, onPropertyChange } = $props<{
10
+ component: UIComponent & { properties: Partial<ISliderProps> }
11
+ onPropertyChange: (value: string | object) => void
12
+ }>()
13
+
14
+ const DeviceVariables = getContext<{ value: string; name: string }[]>('DeviceVariables')
15
+ let VARIABLE_OPTIONS = $derived(
16
+ DeviceVariables.map((variable: { value: string; name: string }) => ({
17
+ id: variable.name,
18
+ value: variable.value,
19
+ name: `${variable.value} | ${variable.name}`,
20
+ })),
21
+ )
22
+
23
+ const initialAlign = $derived(
24
+ $optionsStore.ALIGN_OPTIONS.find((a) =>
25
+ (a.value as string).includes(component.properties.label?.class?.split(' ').find((cls: string) => cls.startsWith('text-'))),
26
+ ),
27
+ )
28
+
29
+ const initialColor = $derived(
30
+ $optionsStore.COLOR_OPTIONS.find((c) =>
31
+ (c.value as string).includes(component.properties.wrapperClass?.split(' ').find((cls: string) => cls.startsWith('bg-'))),
32
+ ),
33
+ )
34
+
35
+ const handleLabelAlign = (align: string) => {
36
+ let labelClass = component.properties.label.class || ''
37
+ labelClass = labelClass
38
+ .split(' ')
39
+ .filter((cls: string) => !cls.startsWith('text-'))
40
+ .join(' ')
41
+ if (align) {
42
+ labelClass += ` ${align}`
43
+ }
44
+ updateProperty('label.class', labelClass)
45
+ }
46
+
47
+ const handleOptionColorChange = (color: string) => {
48
+ let wrapperClass = component.properties.wrapperClass || ''
49
+ wrapperClass = wrapperClass
50
+ .split(' ')
51
+ .filter((cls: string) => !cls.startsWith('bg-'))
52
+ .join(' ')
53
+ if (color) {
54
+ wrapperClass += ` ${color}`
55
+ }
56
+ updateProperty('wrapperClass', wrapperClass)
57
+ }
58
+
59
+ /* Обновление свойства */
60
+ const updateProperty = (path: string, value: number | string | object) => {
61
+ const newProperties = JSON.parse(JSON.stringify(component.properties))
62
+ const parts = path.split('.')
63
+ let obj = newProperties
64
+
65
+ for (let i = 0; i < parts.length - 1; i++) {
66
+ const part = parts[i]
67
+ if (!obj[part]) obj[part] = {}
68
+ obj = obj[part]
69
+ }
70
+
71
+ obj[parts[parts.length - 1]] = value
72
+ onPropertyChange(newProperties)
73
+ }
74
+ </script>
75
+
76
+ {#if component && component.properties}
77
+ <div class="relative flex flex-row items-start justify-center">
78
+ <div class="flex w-1/3 flex-col items-center px-2">
79
+ <UI.Select
80
+ label={{ name: $t('service.constructor.props.variable') }}
81
+ options={VARIABLE_OPTIONS}
82
+ value={VARIABLE_OPTIONS.find((opt) => opt.value === component.properties.id.value)}
83
+ onUpdate={(value) => {
84
+ updateProperty('id.name', (value.name as string).split('|')[1].trim())
85
+ updateProperty('id.value', value.value as string)
86
+ updateProperty('eventHandler.Variables', value.value as string)
87
+ }}
88
+ />
89
+ <UI.Select
90
+ wrapperClass="w-full"
91
+ label={{ name: $t('service.constructor.props.action') }}
92
+ type="buttons"
93
+ value={$optionsStore.SHORT_ARGUMENT_OPTION.find((h) => h.value === component.properties.eventHandler.Argument)}
94
+ options={$optionsStore.SHORT_ARGUMENT_OPTION}
95
+ onUpdate={(option) => {
96
+ updateProperty('eventHandler.Argument', option.value as string)
97
+ }}
98
+ />
99
+ </div>
100
+ <div class="flex w-1/3 flex-col px-2">
101
+ <UI.Select
102
+ wrapperClass="w-full"
103
+ label={{ name: $t('service.constructor.props.type') }}
104
+ type="buttons"
105
+ value={$optionsStore.SLIDER_TYPE_OPTIONS.find((opt) => opt.value === (component.properties.type || 'single'))}
106
+ options={$optionsStore.SLIDER_TYPE_OPTIONS}
107
+ onUpdate={(type) => {
108
+ updateProperty('value', type.value === 'single' ? 5 : [2, 7])
109
+ updateProperty('type', type.value as string)
110
+ }}
111
+ />
112
+ <UI.Input
113
+ wrapperClass="w-full"
114
+ label={{ name: $t('service.constructor.props.minnum') }}
115
+ value={component.properties.number.minNum as number}
116
+ type="number"
117
+ onUpdate={(value) => updateProperty('number.minNum', Number(value))}
118
+ />
119
+ <UI.Input
120
+ wrapperClass="w-full"
121
+ label={{ name: $t('service.constructor.props.maxnum') }}
122
+ value={component.properties.number.maxNum as number}
123
+ type="number"
124
+ onUpdate={(value) => updateProperty('number.maxNum', Number(value))}
125
+ />
126
+ <UI.Input
127
+ wrapperClass="w-full"
128
+ label={{ name: $t('service.constructor.props.step') }}
129
+ value={component.properties.number.step as number}
130
+ type="number"
131
+ onUpdate={(value) => updateProperty('number.step', Number(value))}
132
+ />
133
+ </div>
134
+ <div class="flex w-1/3 flex-col px-2">
135
+ <UI.Input
136
+ wrapperClass="w-full"
137
+ label={{ name: $t('service.constructor.props.label') }}
138
+ value={component.properties.label.name}
139
+ type="text"
140
+ componentClass="w-full"
141
+ onUpdate={(value) => updateProperty('label.name', value as string)}
142
+ />
143
+ <UI.Select
144
+ wrapperClass="w-full"
145
+ label={{ name: $t('service.constructor.props.align') }}
146
+ type="buttons"
147
+ value={initialAlign}
148
+ options={$optionsStore.ALIGN_OPTIONS}
149
+ onUpdate={(option) => handleLabelAlign(option.value as string)}
150
+ />
151
+ <UI.Select
152
+ wrapperClass="!h-14"
153
+ label={{ name: $t('service.constructor.props.colors') }}
154
+ type="buttons"
155
+ options={$optionsStore.COLOR_OPTIONS}
156
+ value={initialColor}
157
+ onUpdate={(option) => handleOptionColorChange(option.value as string)}
158
+ />
159
+ </div>
160
+ </div>
161
+ {/if}
@@ -0,0 +1,10 @@
1
+ import type { UIComponent, ISliderProps } from '../types';
2
+ type $$ComponentProps = {
3
+ component: UIComponent & {
4
+ properties: Partial<ISliderProps>;
5
+ };
6
+ onPropertyChange: (value: string | object) => void;
7
+ };
8
+ declare const SliderProps: import("svelte").Component<$$ComponentProps, {}, "">;
9
+ type SliderProps = ReturnType<typeof SliderProps>;
10
+ export default SliderProps;
@@ -0,0 +1,83 @@
1
+ <!-- $lib/ElementsUI/Switch.svelte -->
2
+ <script lang="ts">
3
+ import type { ISwitchProps } from '../types'
4
+
5
+ let {
6
+ id = { name: '', value: crypto.randomUUID() },
7
+ wrapperClass = '',
8
+ disabled = false,
9
+ label = { name: '', captionLeft: '', captionRight: '', class: '' },
10
+ height = '2rem',
11
+ value = $bindable(),
12
+ onChange = () => {},
13
+ }: ISwitchProps = $props()
14
+
15
+ const options = [1, 2]
16
+ let checked = $derived(value === options[1])
17
+
18
+ let knobTransform = $derived(checked ? `translateX(calc(${height} * 0.9))` : 'translateX(0)')
19
+
20
+ $effect(() => {
21
+ if (value === undefined || value === null) value = options[0]
22
+ })
23
+
24
+ const handleToggle = () => {
25
+ if (disabled) return
26
+ const newValue = checked ? options[1] : options[0]
27
+
28
+ value = newValue
29
+
30
+ onChange(newValue)
31
+ }
32
+
33
+ const handleCaptionClick = (newValue: number) => {
34
+ if (disabled || value === newValue) return
35
+ value = newValue
36
+ onChange(newValue)
37
+ }
38
+
39
+ const maxCaptionWidth = $derived(
40
+ Math.max(label.captionLeft?.length ?? 0, label.captionRight?.length ?? 0) > 0
41
+ ? `${Math.max(label.captionLeft?.length ?? 0, label.captionRight?.length ?? 0)}ch`
42
+ : 'auto',
43
+ )
44
+ </script>
45
+
46
+ <div class="bg-blue relative flex w-full flex-col items-center justify-center {wrapperClass}">
47
+ {#if label.name}
48
+ <h5 class={`w-full px-4 text-center ${label.class}`}>{label.name}</h5>
49
+ {/if}
50
+
51
+ <div class="relative flex w-full grow items-center justify-center !bg-transparent" id={id.value}>
52
+ <button class="mr-2 {disabled ? 'opacity-60' : 'cursor-pointer'}" style="width: {maxCaptionWidth}; text-align: end;" onclick={() => handleCaptionClick(1)}
53
+ >{label.captionLeft}</button
54
+ >
55
+ <label
56
+ class="relative flex items-center justify-between rounded-full border-1
57
+ {checked ? '!border-[var(--bg-color)]' : '!border-[var(--gray-color)]'}
58
+ {disabled ? 'opacity-60' : ''}"
59
+ >
60
+ <input
61
+ type="checkbox"
62
+ class="absolute left-1/2 h-full w-full -translate-x-1/2 cursor-pointer appearance-none rounded-md"
63
+ bind:checked
64
+ {disabled}
65
+ onchange={handleToggle}
66
+ />
67
+ <span
68
+ class="relative flex items-center rounded-full transition-all duration-250 {checked ? '!bg-[var(--bg-color)]' : '!bg-[var(--gray-color)]'} {disabled
69
+ ? ''
70
+ : 'cursor-pointer'}"
71
+ style="width: {`calc(${height} * 2)`}; height: {height};"
72
+ >
73
+ <span
74
+ class="absolute rounded-full bg-[var(--back-color)] transition-all duration-250 {disabled ? 'opacity-60' : 'cursor-pointer'}"
75
+ style="width: {`calc(${height} * 0.8)`}; height: {`calc(${height} * 0.8)`}; margin: 0 {`calc(${height} * 0.1)`}; transform: {knobTransform};"
76
+ ></span>
77
+ </span>
78
+ </label>
79
+ <button class="ml-2 {disabled ? 'opacity-60' : 'cursor-pointer'}" style="width: {maxCaptionWidth}; text-align: start;" onclick={() => handleCaptionClick(2)}
80
+ >{label.captionRight}</button
81
+ >
82
+ </div>
83
+ </div>
@@ -0,0 +1,4 @@
1
+ import type { ISwitchProps } from '../types';
2
+ declare const Switch: import("svelte").Component<ISwitchProps, {}, "value">;
3
+ type Switch = ReturnType<typeof Switch>;
4
+ export default Switch;
@@ -0,0 +1,144 @@
1
+ <!-- $lib/ElementsUI/SwitchProps.svelte -->
2
+ <script lang="ts">
3
+ import { getContext } from 'svelte'
4
+ import { t } from '../locales/i18n'
5
+ import type { UIComponent, ISwitchProps } from '../types'
6
+ import * as UI from '../index'
7
+ import { optionsStore } from '../options'
8
+
9
+ const { component, onPropertyChange } = $props<{
10
+ component: UIComponent & { properties: Partial<ISwitchProps> }
11
+ onPropertyChange: (value: string | object) => void
12
+ }>()
13
+
14
+ const DeviceVariables = getContext<{ value: string; name: string }[]>('DeviceVariables')
15
+ let VARIABLE_OPTIONS = $derived(
16
+ DeviceVariables.map((variable: { value: string; name: string }) => ({
17
+ id: variable.name,
18
+ value: variable.value,
19
+ name: `${variable.value} | ${variable.name}`,
20
+ })),
21
+ )
22
+
23
+ const initialColor = $derived(
24
+ $optionsStore.COLOR_OPTIONS.find((c) =>
25
+ (c.value as string).includes(component.properties.wrapperClass?.split(' ').find((cls: string) => cls.startsWith('bg-'))),
26
+ ),
27
+ )
28
+
29
+ const initialAlign = $derived(
30
+ $optionsStore.ALIGN_OPTIONS.find((a) =>
31
+ (a.value as string).includes(component.properties.label?.class?.split(' ').find((cls: string) => cls.startsWith('text-'))),
32
+ ),
33
+ )
34
+
35
+ /* Добавление цветов через селект */
36
+ const handleOptionColorChange = (color: string) => {
37
+ let componentClass = component.properties.componentClass || ''
38
+ componentClass = componentClass
39
+ .split(' ')
40
+ .filter((cls: string) => !cls.startsWith('bg-'))
41
+ .join(' ')
42
+ if (color) {
43
+ componentClass += ` ${color}`
44
+ }
45
+ updateProperty('wrapperClass', componentClass)
46
+ }
47
+
48
+ const handleLabelAlign = (align: string) => {
49
+ let labelClass = component.properties.label.class || ''
50
+ labelClass = labelClass
51
+ .split(' ')
52
+ .filter((cls: string) => !cls.startsWith('text-'))
53
+ .join(' ')
54
+ if (align) {
55
+ labelClass += ` ${align}`
56
+ }
57
+ updateProperty('label.class', labelClass)
58
+ }
59
+
60
+ /* Обновление свойства */
61
+ const updateProperty = (path: string, value: string | object | boolean | number) => {
62
+ const newProperties = JSON.parse(JSON.stringify(component.properties))
63
+ const parts = path.split('.')
64
+ let obj = newProperties
65
+
66
+ for (let i = 0; i < parts.length - 1; i++) {
67
+ const part = parts[i]
68
+ if (!obj[part]) obj[part] = {}
69
+ obj = obj[part]
70
+ }
71
+
72
+ obj[parts[parts.length - 1]] = value
73
+ onPropertyChange(newProperties)
74
+ }
75
+ </script>
76
+
77
+ {#if component && component.properties}
78
+ <div class="relative flex flex-row items-start justify-center">
79
+ <!-- Сообщение для отправки в ws по нажатию кнопки -->
80
+ <div class="flex w-1/3 flex-col items-center px-2">
81
+ <UI.Select
82
+ label={{ name: $t('service.constructor.props.variable') }}
83
+ options={VARIABLE_OPTIONS}
84
+ value={VARIABLE_OPTIONS.find((opt) => opt.value === component.properties.id.value)}
85
+ onUpdate={(value) => {
86
+ updateProperty('id.name', (value.name as string).split('|')[1].trim())
87
+ updateProperty('id.value', value.value as string)
88
+ updateProperty('eventHandler.Variables', value.value as string)
89
+ }}
90
+ />
91
+ <UI.Select
92
+ label={{ name: $t('service.constructor.props.action') }}
93
+ type="buttons"
94
+ value={$optionsStore.SHORT_ARGUMENT_OPTION.find((h) => h.value === component.properties.eventHandler.Argument)}
95
+ options={$optionsStore.SHORT_ARGUMENT_OPTION}
96
+ onUpdate={(option) => {
97
+ updateProperty('eventHandler.Argument', option.value as string)
98
+ }}
99
+ />
100
+ </div>
101
+ <div class="flex w-1/3 flex-col px-2">
102
+ <UI.Input
103
+ label={{ name: $t('service.constructor.props.caption.left') }}
104
+ value={component.properties.label.captionLeft}
105
+ type="text"
106
+ onUpdate={(value) => updateProperty('label.captionLeft', value as string)}
107
+ />
108
+ <UI.Input
109
+ label={{ name: $t('service.constructor.props.caption.right') }}
110
+ value={component.properties.label.captionRight}
111
+ type="text"
112
+ onUpdate={(value) => updateProperty('label.captionRight', value as string)}
113
+ />
114
+ <UI.Switch
115
+ label={{ name: $t('service.constructor.props.disabled') }}
116
+ value={component.properties.disabled ? 2 : 1}
117
+ onChange={(value) => updateProperty('disabled', value === 2)}
118
+ />
119
+ </div>
120
+ <div class="flex w-1/3 flex-col px-2">
121
+ <UI.Input
122
+ label={{ name: $t('service.constructor.props.label') }}
123
+ value={component.properties.label.name}
124
+ type="text"
125
+ onUpdate={(value) => updateProperty('label.name', value as string)}
126
+ />
127
+ <UI.Select
128
+ label={{ name: $t('service.constructor.props.align') }}
129
+ type="buttons"
130
+ value={initialAlign}
131
+ options={$optionsStore.ALIGN_OPTIONS}
132
+ onUpdate={(option) => handleLabelAlign(option.value as string)}
133
+ />
134
+ <UI.Select
135
+ wrapperClass="!h-14"
136
+ label={{ name: $t('service.constructor.props.colors') }}
137
+ type="buttons"
138
+ options={$optionsStore.COLOR_OPTIONS}
139
+ value={initialColor}
140
+ onUpdate={(option) => handleOptionColorChange(option.value as string)}
141
+ />
142
+ </div>
143
+ </div>
144
+ {/if}
@@ -0,0 +1,10 @@
1
+ import type { UIComponent, ISwitchProps } from '../types';
2
+ type $$ComponentProps = {
3
+ component: UIComponent & {
4
+ properties: Partial<ISwitchProps>;
5
+ };
6
+ onPropertyChange: (value: string | object) => void;
7
+ };
8
+ declare const SwitchProps: import("svelte").Component<$$ComponentProps, {}, "">;
9
+ type SwitchProps = ReturnType<typeof SwitchProps>;
10
+ export default SwitchProps;