poe-svelte-ui-lib 0.2.0 → 0.3.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.
- package/dist/Accordion/Accordion.svelte +53 -0
- package/dist/Accordion/Accordion.svelte.d.ts +14 -0
- package/dist/Accordion/AccordionProps.svelte +70 -0
- package/dist/Accordion/AccordionProps.svelte.d.ts +14 -0
- package/dist/{Button.svelte → Button/Button.svelte} +34 -45
- package/dist/Button/Button.svelte.d.ts +14 -0
- package/dist/Button/ButtonProps.svelte +200 -0
- package/dist/Button/ButtonProps.svelte.d.ts +14 -0
- package/dist/ColorPicker/ColorPicker.svelte +207 -0
- package/dist/ColorPicker/ColorPicker.svelte.d.ts +14 -0
- package/dist/ColorPicker/ColorPickerProps.svelte +100 -0
- package/dist/ColorPicker/ColorPickerProps.svelte.d.ts +14 -0
- package/dist/FileAttach/FileAttach.svelte +103 -0
- package/dist/FileAttach/FileAttach.svelte.d.ts +14 -0
- package/dist/Graph/Graph.svelte +270 -0
- package/dist/Graph/Graph.svelte.d.ts +14 -0
- package/dist/Graph/GraphProps.svelte +56 -0
- package/dist/Graph/GraphProps.svelte.d.ts +14 -0
- package/dist/Input/Input.svelte +239 -0
- package/dist/Input/Input.svelte.d.ts +14 -0
- package/dist/Input/InputProps.svelte +221 -0
- package/dist/Input/InputProps.svelte.d.ts +14 -0
- package/dist/Loader.svelte +12 -0
- package/dist/Loader.svelte.d.ts +14 -0
- package/dist/MessageModal.svelte +54 -0
- package/dist/MessageModal.svelte.d.ts +14 -0
- package/dist/ProgressBar/ProgressBar.svelte +48 -0
- package/dist/ProgressBar/ProgressBar.svelte.d.ts +14 -0
- package/dist/ProgressBar/ProgressBarProps.svelte +145 -0
- package/dist/ProgressBar/ProgressBarProps.svelte.d.ts +14 -0
- package/dist/Select/Select.svelte +187 -0
- package/dist/Select/Select.svelte.d.ts +14 -0
- package/dist/Select/SelectProps.svelte +260 -0
- package/dist/Select/SelectProps.svelte.d.ts +14 -0
- package/dist/Slider/Slider.svelte +260 -0
- package/dist/Slider/Slider.svelte.d.ts +14 -0
- package/dist/Slider/SliderProps.svelte +161 -0
- package/dist/Slider/SliderProps.svelte.d.ts +14 -0
- package/dist/Switch/Switch.svelte +83 -0
- package/dist/Switch/Switch.svelte.d.ts +14 -0
- package/dist/Switch/SwitchProps.svelte +144 -0
- package/dist/Switch/SwitchProps.svelte.d.ts +14 -0
- package/dist/Table/Table.svelte +276 -0
- package/dist/Table/Table.svelte.d.ts +14 -0
- package/dist/Table/TableProps.svelte +286 -0
- package/dist/Table/TableProps.svelte.d.ts +14 -0
- package/dist/TextField/TextField.svelte +22 -0
- package/dist/TextField/TextField.svelte.d.ts +14 -0
- package/dist/TextField/TextFieldProps.svelte +92 -0
- package/dist/TextField/TextFieldProps.svelte.d.ts +14 -0
- package/dist/appIcons/ButtonAdd.svelte +10 -0
- package/dist/appIcons/ButtonAdd.svelte.d.ts +14 -0
- package/dist/appIcons/ButtonDelete.svelte +13 -0
- package/dist/appIcons/ButtonDelete.svelte.d.ts +14 -0
- package/dist/appIcons/LoaderRotate.svelte +9 -0
- package/dist/appIcons/LoaderRotate.svelte.d.ts +14 -0
- package/dist/index.d.ts +25 -1
- package/dist/index.js +26 -2
- package/dist/locales/CircleFlagsEn.svelte +14 -0
- package/dist/locales/CircleFlagsEn.svelte.d.ts +23 -0
- package/dist/locales/CircleFlagsRu.svelte +8 -0
- package/dist/locales/CircleFlagsRu.svelte.d.ts +23 -0
- package/dist/locales/CircleFlagsZh.svelte +8 -0
- package/dist/locales/CircleFlagsZh.svelte.d.ts +23 -0
- package/dist/locales/i18n.d.ts +10 -0
- package/dist/locales/i18n.js +36 -0
- package/dist/locales/translations.d.ts +7 -0
- package/dist/locales/translations.js +450 -0
- package/dist/options.d.ts +78 -0
- package/dist/options.js +71 -0
- package/dist/types.d.ts +284 -0
- package/dist/types.js +1 -0
- package/package.json +24 -20
- package/dist/Button.svelte.d.ts +0 -37
|
@@ -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,14 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
declare const __propDef: {
|
|
3
|
+
props: Record<string, never>;
|
|
4
|
+
events: {
|
|
5
|
+
[evt: string]: CustomEvent<any>;
|
|
6
|
+
};
|
|
7
|
+
slots: {};
|
|
8
|
+
};
|
|
9
|
+
export type SliderProps = typeof __propDef.props;
|
|
10
|
+
export type SliderEvents = typeof __propDef.events;
|
|
11
|
+
export type SliderSlots = typeof __propDef.slots;
|
|
12
|
+
export default class Slider extends SvelteComponentTyped<SliderProps, SliderEvents, SliderSlots> {
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
@@ -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,14 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
declare const __propDef: {
|
|
3
|
+
props: Record<string, never>;
|
|
4
|
+
events: {
|
|
5
|
+
[evt: string]: CustomEvent<any>;
|
|
6
|
+
};
|
|
7
|
+
slots: {};
|
|
8
|
+
};
|
|
9
|
+
export type SliderPropsProps = typeof __propDef.props;
|
|
10
|
+
export type SliderPropsEvents = typeof __propDef.events;
|
|
11
|
+
export type SliderPropsSlots = typeof __propDef.slots;
|
|
12
|
+
export default class SliderProps extends SvelteComponentTyped<SliderPropsProps, SliderPropsEvents, SliderPropsSlots> {
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
@@ -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,14 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
declare const __propDef: {
|
|
3
|
+
props: Record<string, never>;
|
|
4
|
+
events: {
|
|
5
|
+
[evt: string]: CustomEvent<any>;
|
|
6
|
+
};
|
|
7
|
+
slots: {};
|
|
8
|
+
};
|
|
9
|
+
export type SwitchProps = typeof __propDef.props;
|
|
10
|
+
export type SwitchEvents = typeof __propDef.events;
|
|
11
|
+
export type SwitchSlots = typeof __propDef.slots;
|
|
12
|
+
export default class Switch extends SvelteComponentTyped<SwitchProps, SwitchEvents, SwitchSlots> {
|
|
13
|
+
}
|
|
14
|
+
export {};
|