poe-svelte-ui-lib 2.10.2 → 2.12.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/README.md +16 -2
- package/dist/GUIRenderer/DeviceTable.svelte +9 -3
- package/dist/GUIRenderer/DeviceTable.svelte.d.ts +2 -0
- package/dist/GUIRenderer/GUIRenderer.svelte +56 -50
- package/dist/GUIRenderer/GUIRenderer.svelte.d.ts +2 -0
- package/dist/componentMeta.d.ts +11 -0
- package/dist/componentMeta.js +38 -0
- package/dist/gui.d.ts +4 -1
- package/dist/gui.js +2 -0
- package/dist/guiViews.d.ts +52 -0
- package/dist/guiViews.js +54 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/locales/translations.d.ts +5 -0
- package/dist/locales/translations.js +1 -0
- package/dist/registry.d.ts +2 -8
- package/dist/registry.js +28 -36
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -122,9 +122,19 @@
|
|
|
122
122
|
Интерфейс, собранный в конструкторе, рисует компонент `GUIRenderer`. Он сам раскладывает блоки по сетке, берёт значения переменных, отправляет команды и ведёт смарт-виджеты и файлы. Приложению остаётся транспорт, выбор модуля, загрузка GUI и хранилище значений.
|
|
123
123
|
|
|
124
124
|
```svelte
|
|
125
|
-
<UI.GUIRenderer
|
|
125
|
+
<UI.GUIRenderer
|
|
126
|
+
components={module.UIBlocks}
|
|
127
|
+
{link}
|
|
128
|
+
persistKey={module.ModSN}
|
|
129
|
+
viewer={!canManage}
|
|
130
|
+
render={{ VideoViewer: video }}
|
|
131
|
+
views={UI.GUI_VIEWS}
|
|
132
|
+
onError={addMessage}
|
|
133
|
+
/>
|
|
126
134
|
```
|
|
127
135
|
|
|
136
|
+
**📦 Что попадает в сборку.** `GUIRenderer` сам не импортирует ни одного компонента: каждый тип он берёт из пропса `views`. Облако и терминал передают `UI.GUI_VIEWS` - все типы. Приложению с ограниченной памятью (веб-интерфейс прошивки) достаточно перечислить только нужные: `{ Button: UI.Button, Input: UI.Input, ... }`. Чего нет в `views`, то не попадает в сборку и рисуется заглушкой «Компонент не входит в эту сборку». Какие типы есть в GUI, возвращает `guiTypes(components)`.
|
|
137
|
+
|
|
128
138
|
**📐 Правила для автора GUI.** Рендерер понимает интерфейс по группам, поэтому при сборке в конструкторе соблюдайте правила:
|
|
129
139
|
|
|
130
140
|
1. 🧱 Группа - параметры одного объекта (мотор, канал, контур регулятора). Внутри группы блоки стоят вплотную, без пустых клеток.
|
|
@@ -159,6 +169,7 @@
|
|
|
159
169
|
| `viewer` | наблюдатель: видны только `access` `full` и `viewOnly`, управление отключено; `WidgetWiFi` и `WidgetDeviceInfo` без `onSave` - только для чтения, пароли маской |
|
|
160
170
|
| `persistKey` | ключ хранения в браузере (обычно `ModSN`): свёрнутость виджетов, планы `WidgetMap` |
|
|
161
171
|
| `render` | своя отрисовка типа: `{ VideoViewer: snippet }`, сниппет получает компонент |
|
|
172
|
+
| `views` | компоненты отрисовки по типу: `GUI_VIEWS` или только нужные; тип без компонента рисуется заглушкой |
|
|
162
173
|
| `onError` | готовый текст ошибки на языке библиотеки: команда не собрана, ошибка передачи файла, сбой поиска сетей WiFi (ER! или нет ответа) |
|
|
163
174
|
|
|
164
175
|
```ts
|
|
@@ -227,10 +238,13 @@ socket.send(valueToCbor(encodeWsEnvelope("SET", "JoinDev", { DevSN, Watch: true
|
|
|
227
238
|
| `widgetPacket(prefix, fields, values, keys)` | Payload `SET ModCfg` виджета |
|
|
228
239
|
| `WIDGET_FIELDS`, `WIDGET_SAVE_FIELDS`, `widgetPrefixes` | поля смарт-виджетов (из них выведены `IWidgetWiFiConfig` и остальные), сохраняемые поля, группы |
|
|
229
240
|
| `GUI_GRID`, `spanRows`, `isWidgetType` | сетка |
|
|
241
|
+
| `guiTypes` | типы компонентов в GUI - из них приложение собирает `views` рендерера |
|
|
230
242
|
|
|
231
243
|
**Реестр.**
|
|
232
244
|
|
|
233
|
-
- `
|
|
245
|
+
- `COMPONENT_META[type]` - `{ io, fields? }`: обмен с устройством (`none`, `read`, `write`, `readWrite`, `widget`) и поля смарт-виджета, без самих компонентов (`componentMeta.ts`). Его берёт `GUIRenderer`.
|
|
246
|
+
- `COMPONENTS[type]` - `{ view, io, fields? }`: то же плюс компонент отрисовки, для конструктора. Тянет в сборку все виджеты, поэтому в рендерере не используется.
|
|
247
|
+
- `package.json` объявляет `"sideEffects": ["**/*.css"]`: без этого сборщик приложения не может выбросить неиспользуемые модули библиотеки.
|
|
234
248
|
- `componentVariables(component)` - переменные устройства компонента (список переменных конструктора).
|
|
235
249
|
- `UIComponent` - объединение по `type`: после `component.type === "Button"` у `properties` тип `IButtonProps`, `UIComponent<"Button">` - компонент одного типа.
|
|
236
250
|
- В `poe-svelte-ui-lib/constructor`: `PANELS[type]` - панель свойств, `COMPONENT_DEFAULTS`, `COMPONENT_SIZES`, `minComponentWidth`, `createComponent(type, { col, row }, parentId, { tab, areaWidth })`, `applyPropertyChange(component, change)`.
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
<!-- $lib/GUIRenderer/DeviceTable.svelte - таблица рендерера: обычная - строки из value, журнал (dataBuffer.stashData) - каждое новое value добавляется push() -->
|
|
2
2
|
<script lang="ts">
|
|
3
|
-
import Table from "../Table/Table.svelte"
|
|
3
|
+
import type Table from "../Table/Table.svelte"
|
|
4
4
|
import type { ITableButton, ITableProps } from "../types"
|
|
5
5
|
|
|
6
6
|
type Row = Record<string, unknown>
|
|
7
|
-
|
|
7
|
+
/* view - компонент Table из views рендерера: таблица попадает в сборку, только если приложение её передало */
|
|
8
|
+
let {
|
|
9
|
+
view: TableView,
|
|
10
|
+
properties,
|
|
11
|
+
value,
|
|
12
|
+
onClick,
|
|
13
|
+
}: { view: typeof Table; properties: ITableProps<Row>; value: unknown; onClick?: (row: Row, button: ITableButton<Row>) => void } = $props()
|
|
8
14
|
|
|
9
15
|
let table: Table<Row> | undefined = $state()
|
|
10
16
|
const rows = $derived((Array.isArray(value) ? value : value && typeof value === "object" ? [value] : []) as Row[])
|
|
@@ -14,4 +20,4 @@
|
|
|
14
20
|
})
|
|
15
21
|
</script>
|
|
16
22
|
|
|
17
|
-
<
|
|
23
|
+
<TableView bind:this={table} {...properties} body={properties.dataBuffer?.stashData ? undefined : rows} {onClick} />
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import type Table from "../Table/Table.svelte";
|
|
1
2
|
import type { ITableButton, ITableProps } from "../types";
|
|
2
3
|
type Row = Record<string, unknown>;
|
|
3
4
|
type $$ComponentProps = {
|
|
5
|
+
view: typeof Table;
|
|
4
6
|
properties: ITableProps<Row>;
|
|
5
7
|
value: unknown;
|
|
6
8
|
onClick?: (row: Row, button: ITableButton<Row>) => void;
|
|
@@ -27,31 +27,9 @@
|
|
|
27
27
|
type DeviceLink,
|
|
28
28
|
type DevicePacket,
|
|
29
29
|
} from "../gui"
|
|
30
|
-
import {
|
|
31
|
-
import Accordion from "../Accordion/Accordion.svelte"
|
|
32
|
-
import Tabs from "../Tabs/Tabs.svelte"
|
|
33
|
-
import Button from "../Button/Button.svelte"
|
|
34
|
-
import Input from "../Input/Input.svelte"
|
|
35
|
-
import Select from "../Select/Select.svelte"
|
|
36
|
-
import Switch from "../Switch/Switch.svelte"
|
|
37
|
-
import Slider from "../Slider/Slider.svelte"
|
|
38
|
-
import Joystick from "../Joystick/Joystick.svelte"
|
|
39
|
-
import Widget from "../Widget/Widget.svelte"
|
|
40
|
-
import TextField from "../TextField/TextField.svelte"
|
|
41
|
-
import Divider from "../Divider/Divider.svelte"
|
|
42
|
-
import ProgressBar from "../ProgressBar/ProgressBar.svelte"
|
|
43
|
-
import Graph from "../Graph/Graph.svelte"
|
|
44
|
-
import PeriodChart from "../PeriodChart/PeriodChart.svelte"
|
|
45
|
-
import FileAttach from "../FileAttach/FileAttach.svelte"
|
|
46
|
-
import VideoViewer from "../VideoViewer/VideoViewer.svelte"
|
|
47
|
-
import WidgetWiFi from "../WidgetWiFi/WidgetWiFi.svelte"
|
|
48
|
-
import WidgetDeviceInfo from "../WidgetDeviceInfo/WidgetDeviceInfo.svelte"
|
|
49
|
-
import WidgetFileSystem from "../WidgetFileSystem/WidgetFileSystem.svelte"
|
|
50
|
-
import WidgetStackInfo from "../WidgetStackInfo/WidgetStackInfo.svelte"
|
|
51
|
-
import WidgetRGBStrip from "../WidgetRGBStrip/WidgetRGBStrip.svelte"
|
|
52
|
-
import WidgetPFD from "../WidgetPFD/WidgetPFD.svelte"
|
|
53
|
-
import WidgetMap from "../WidgetMap/WidgetMap.svelte"
|
|
30
|
+
import { COMPONENT_META } from "../componentMeta"
|
|
54
31
|
import DeviceTable from "./DeviceTable.svelte"
|
|
32
|
+
import type { GuiViews } from "../guiViews"
|
|
55
33
|
|
|
56
34
|
interface Props {
|
|
57
35
|
components: UIComponent[]
|
|
@@ -64,11 +42,13 @@
|
|
|
64
42
|
persistKey?: string
|
|
65
43
|
/* Своя отрисовка типа (например VideoViewer с потоком приложения) */
|
|
66
44
|
render?: Partial<Record<UIType, Snippet<[UIComponent]>>>
|
|
45
|
+
/* Компоненты отрисовки по типу (GUI_VIEWS или только нужные): тип без компонента рисуется заглушкой и не попадает в сборку приложения */
|
|
46
|
+
views: GuiViews
|
|
67
47
|
/* Ошибка команды или передачи файла, для уведомления */
|
|
68
48
|
onError?: (message: string) => void
|
|
69
49
|
}
|
|
70
50
|
|
|
71
|
-
let { components, link, language, viewer = false, persistKey, render, onError }: Props = $props()
|
|
51
|
+
let { components, link, language, viewer = false, persistKey, render, views, onError }: Props = $props()
|
|
72
52
|
|
|
73
53
|
/* Кэш по ссылке и языку: localizeDeep создаёт новые объекты, без кэша обновление значений сбрасывало бы раскрытые аккордеоны и вкладки */
|
|
74
54
|
let localized: { src?: UIComponent[]; lang?: string; out: UIComponent[] } = { out: [] }
|
|
@@ -234,7 +214,7 @@
|
|
|
234
214
|
}
|
|
235
215
|
|
|
236
216
|
const persist = (component: UIComponent) => (persistKey ? `${persistKey}|${component.id}` : undefined)
|
|
237
|
-
const writable = (component: UIComponent) => !viewer &&
|
|
217
|
+
const writable = (component: UIComponent) => !viewer && COMPONENT_META[component.type].io !== "none"
|
|
238
218
|
</script>
|
|
239
219
|
|
|
240
220
|
<div bind:clientWidth={width}>
|
|
@@ -296,34 +276,39 @@
|
|
|
296
276
|
<div class={component.type === "Accordion" ? "" : "flex flex-col justify-start"} style={cellStyle(component, fixedHeight)}>
|
|
297
277
|
{#if render?.[component.type]}
|
|
298
278
|
{@render render[component.type]?.(component)}
|
|
299
|
-
{:else if component.type === "Accordion"}
|
|
279
|
+
{:else if component.type === "Accordion" && views.Accordion}
|
|
280
|
+
{@const Accordion = views.Accordion}
|
|
300
281
|
<Accordion {...component.properties}>
|
|
301
282
|
<!-- Своя сетка содержимого во всю ширину аккордеона: колонок не меньше, чем у самого дальнего блока -->
|
|
302
283
|
<div class="min-w-0" style="grid-column: 1 / -1; grid-row: 1 / -1">
|
|
303
284
|
{@render Layout(childrenOf(component).filter(visible), component.properties.size?.width ?? 1, !!component.properties.image)}
|
|
304
285
|
</div>
|
|
305
286
|
</Accordion>
|
|
306
|
-
{:else if component.type === "Tabs"}
|
|
287
|
+
{:else if component.type === "Tabs" && views.Tabs}
|
|
288
|
+
{@const Tabs = views.Tabs}
|
|
307
289
|
<!-- Содержимое вкладки - через Layout, как у Accordion: на телефоне раскладка по группам, а не одна колонка сетки size.width -->
|
|
308
290
|
<Tabs {...component.properties} apiArray={childrenOf(component)}>
|
|
309
291
|
{#snippet Content(list: UIComponent[])}
|
|
310
292
|
{@render Layout(list.filter(visible), component.properties.size?.width ?? 1, false)}
|
|
311
293
|
{/snippet}
|
|
312
294
|
</Tabs>
|
|
313
|
-
{:else if component.type === "Button"}
|
|
295
|
+
{:else if component.type === "Button" && views.Button}
|
|
296
|
+
{@const Button = views.Button}
|
|
314
297
|
<Button
|
|
315
298
|
{...component.properties}
|
|
316
299
|
disabled={locked || component.properties.disabled}
|
|
317
300
|
onClick={() => dispatch(commandPacket(component.eventHandler, get))}
|
|
318
301
|
/>
|
|
319
|
-
{:else if component.type === "Input"}
|
|
302
|
+
{:else if component.type === "Input" && views.Input}
|
|
303
|
+
{@const Input = views.Input}
|
|
320
304
|
<Input
|
|
321
305
|
{...component.properties}
|
|
322
306
|
readonly={locked || component.properties.readonly}
|
|
323
307
|
value={(readBits(component, link.get(id)) as string | number | undefined) ?? component.properties.value}
|
|
324
308
|
onUpdate={(value) => change(component, value)}
|
|
325
309
|
/>
|
|
326
|
-
{:else if component.type === "Select"}
|
|
310
|
+
{:else if component.type === "Select" && views.Select}
|
|
311
|
+
{@const Select = views.Select}
|
|
327
312
|
<Select
|
|
328
313
|
{...component.properties}
|
|
329
314
|
disabled={locked || component.properties.disabled}
|
|
@@ -331,46 +316,57 @@
|
|
|
331
316
|
options={selectOptions(component)}
|
|
332
317
|
onUpdate={(value) => change(component, value)}
|
|
333
318
|
/>
|
|
334
|
-
{:else if component.type === "Switch"}
|
|
319
|
+
{:else if component.type === "Switch" && views.Switch}
|
|
320
|
+
{@const Switch = views.Switch}
|
|
335
321
|
<Switch
|
|
336
322
|
{...component.properties}
|
|
337
323
|
disabled={locked || component.properties.disabled}
|
|
338
324
|
value={link.get(id) as number}
|
|
339
325
|
onUpdate={(value) => change(component, value)}
|
|
340
326
|
/>
|
|
341
|
-
{:else if component.type === "Slider"}
|
|
327
|
+
{:else if component.type === "Slider" && views.Slider}
|
|
328
|
+
{@const Slider = views.Slider}
|
|
342
329
|
<Slider
|
|
343
330
|
{...component.properties}
|
|
344
331
|
disabled={locked || component.properties.disabled}
|
|
345
332
|
value={link.get(id) as number | [number, number]}
|
|
346
333
|
onUpdate={(value) => change(component, value)}
|
|
347
334
|
/>
|
|
348
|
-
{:else if component.type
|
|
335
|
+
{:else if !views[component.type]}
|
|
336
|
+
<p class="flex h-full items-center justify-center p-2 text-center text-[12px] text-(--muted-color)">{$T("gui.view_missing")}: {component.type}</p>
|
|
337
|
+
{:else if component.type === "Joystick" && views.Joystick}
|
|
338
|
+
{@const Joystick = views.Joystick}
|
|
349
339
|
<Joystick
|
|
350
340
|
{...component.properties}
|
|
351
341
|
readonly={locked || component.properties.readonly}
|
|
352
342
|
value={link.get(id) as number[]}
|
|
353
343
|
onUpdate={(value) => change(component, value)}
|
|
354
344
|
/>
|
|
355
|
-
{:else if component.type === "Widget"}
|
|
345
|
+
{:else if component.type === "Widget" && views.Widget}
|
|
346
|
+
{@const Widget = views.Widget}
|
|
356
347
|
<Widget
|
|
357
348
|
{...component.properties}
|
|
358
349
|
readonly={locked || component.properties.readonly}
|
|
359
350
|
value={link.get(id) as number}
|
|
360
351
|
onUpdate={(value) => change(component, value)}
|
|
361
352
|
/>
|
|
362
|
-
{:else if component.type === "TextField"}
|
|
353
|
+
{:else if component.type === "TextField" && views.TextField}
|
|
354
|
+
{@const TextField = views.TextField}
|
|
363
355
|
<TextField {...component.properties} />
|
|
364
|
-
{:else if component.type === "Divider"}
|
|
356
|
+
{:else if component.type === "Divider" && views.Divider}
|
|
357
|
+
{@const Divider = views.Divider}
|
|
365
358
|
<Divider {...component.properties} />
|
|
366
|
-
{:else if component.type === "ProgressBar"}
|
|
359
|
+
{:else if component.type === "ProgressBar" && views.ProgressBar}
|
|
360
|
+
{@const ProgressBar = views.ProgressBar}
|
|
367
361
|
<ProgressBar {...component.properties} value={link.get(id) as never} />
|
|
368
|
-
{:else if component.type === "Graph"}
|
|
362
|
+
{:else if component.type === "Graph" && views.Graph}
|
|
363
|
+
{@const Graph = views.Graph}
|
|
369
364
|
<Graph
|
|
370
365
|
{...component.properties}
|
|
371
366
|
streamingData={{ data: component.properties.isTest ? (component.properties.streamingData?.data ?? null) : (link.get(id) as never) }}
|
|
372
367
|
/>
|
|
373
|
-
{:else if component.type === "PeriodChart"}
|
|
368
|
+
{:else if component.type === "PeriodChart" && views.PeriodChart}
|
|
369
|
+
{@const PeriodChart = views.PeriodChart}
|
|
374
370
|
<PeriodChart
|
|
375
371
|
{...component.properties}
|
|
376
372
|
levels={(component.properties.levels ?? []).map((level) => ({
|
|
@@ -378,21 +374,25 @@
|
|
|
378
374
|
data: ((level.variable && link.get(level.variable)) as number[] | undefined) ?? level.data ?? [],
|
|
379
375
|
}))}
|
|
380
376
|
/>
|
|
381
|
-
{:else if component.type === "Table"}
|
|
377
|
+
{:else if component.type === "Table" && views.Table}
|
|
382
378
|
<DeviceTable
|
|
379
|
+
view={views.Table}
|
|
383
380
|
properties={component.properties}
|
|
384
381
|
value={tableRows(component)}
|
|
385
382
|
onClick={locked ? undefined : (row: Row, button: ITableButton<Row>) => dispatch(tablePacket(button.eventHandler, row))}
|
|
386
383
|
/>
|
|
387
|
-
{:else if component.type === "FileAttach"}
|
|
384
|
+
{:else if component.type === "FileAttach" && views.FileAttach}
|
|
385
|
+
{@const FileAttach = views.FileAttach}
|
|
388
386
|
<FileAttach
|
|
389
387
|
{...component.properties}
|
|
390
388
|
disabled={locked || component.properties.disabled}
|
|
391
389
|
onUpdate={(file) => file && fs().upload(file.name, file).catch(report)}
|
|
392
390
|
/>
|
|
393
|
-
{:else if component.type === "VideoViewer"}
|
|
391
|
+
{:else if component.type === "VideoViewer" && views.VideoViewer}
|
|
392
|
+
{@const VideoViewer = views.VideoViewer}
|
|
394
393
|
<VideoViewer {...component.properties} />
|
|
395
|
-
{:else if component.type === "WidgetWiFi"}
|
|
394
|
+
{:else if component.type === "WidgetWiFi" && views.WidgetWiFi}
|
|
395
|
+
{@const WidgetWiFi = views.WidgetWiFi}
|
|
396
396
|
{@const props = component.properties}
|
|
397
397
|
{@const prefix = widgetPrefixes(component.type, props)[0]}
|
|
398
398
|
<WidgetWiFi
|
|
@@ -402,7 +402,8 @@
|
|
|
402
402
|
onScan={locked ? undefined : () => scanWiFi(prefix, props.keys, props.scanCommand)}
|
|
403
403
|
onSave={locked ? undefined : (config) => saveFields(prefix, WIDGET_SAVE_FIELDS.WidgetWiFi, config, props.keys)}
|
|
404
404
|
/>
|
|
405
|
-
{:else if component.type === "WidgetDeviceInfo"}
|
|
405
|
+
{:else if component.type === "WidgetDeviceInfo" && views.WidgetDeviceInfo}
|
|
406
|
+
{@const WidgetDeviceInfo = views.WidgetDeviceInfo}
|
|
406
407
|
{@const props = component.properties}
|
|
407
408
|
{@const prefix = widgetPrefixes(component.type, props)[0]}
|
|
408
409
|
<WidgetDeviceInfo
|
|
@@ -421,7 +422,8 @@
|
|
|
421
422
|
onRestart={locked ? undefined : () => send(props.restartCommand?.header || "SET", props.restartCommand?.argument || "Restart", {})}
|
|
422
423
|
onFactoryReset={locked ? undefined : () => send(props.resetCommand?.header || "SET", props.resetCommand?.argument || "RstNVS", {})}
|
|
423
424
|
/>
|
|
424
|
-
{:else if component.type === "WidgetFileSystem"}
|
|
425
|
+
{:else if component.type === "WidgetFileSystem" && views.WidgetFileSystem}
|
|
426
|
+
{@const WidgetFileSystem = views.WidgetFileSystem}
|
|
425
427
|
{@const props = component.properties}
|
|
426
428
|
{@const argument = props.argument || "FS"}
|
|
427
429
|
{@const transfer = () => fs(argument, props.maxNameLength)}
|
|
@@ -439,7 +441,8 @@
|
|
|
439
441
|
.download(name)
|
|
440
442
|
.then((bytes) => saveFile(name, bytes), fail)}
|
|
441
443
|
/>
|
|
442
|
-
{:else if component.type === "WidgetStackInfo"}
|
|
444
|
+
{:else if component.type === "WidgetStackInfo" && views.WidgetStackInfo}
|
|
445
|
+
{@const WidgetStackInfo = views.WidgetStackInfo}
|
|
443
446
|
{@const props = component.properties}
|
|
444
447
|
<WidgetStackInfo
|
|
445
448
|
{...props}
|
|
@@ -447,7 +450,8 @@
|
|
|
447
450
|
persistKey={persist(component)}
|
|
448
451
|
onRefresh={() => send("GET", props.argument || "StackInfo", {})}
|
|
449
452
|
/>
|
|
450
|
-
{:else if component.type === "WidgetRGBStrip"}
|
|
453
|
+
{:else if component.type === "WidgetRGBStrip" && views.WidgetRGBStrip}
|
|
454
|
+
{@const WidgetRGBStrip = views.WidgetRGBStrip}
|
|
451
455
|
{@const props = component.properties}
|
|
452
456
|
{@const prefix = widgetPrefixes(component.type, props)[0]}
|
|
453
457
|
<WidgetRGBStrip
|
|
@@ -457,13 +461,15 @@
|
|
|
457
461
|
onUpdate={locked ? undefined : (value, field) => saveFields(prefix, [field], { [field]: value }, props.keys)}
|
|
458
462
|
onSave={locked ? undefined : (hardware) => saveFields(prefix, WIDGET_SAVE_FIELDS.WidgetRGBStrip, hardware, props.keys)}
|
|
459
463
|
/>
|
|
460
|
-
{:else if component.type === "WidgetPFD"}
|
|
464
|
+
{:else if component.type === "WidgetPFD" && views.WidgetPFD}
|
|
465
|
+
{@const WidgetPFD = views.WidgetPFD}
|
|
461
466
|
<WidgetPFD
|
|
462
467
|
{...component.properties}
|
|
463
468
|
value={fields(component, widgetPrefixes(component.type, component.properties)[0], WIDGET_FIELDS.WidgetPFD)}
|
|
464
469
|
persistKey={persist(component)}
|
|
465
470
|
/>
|
|
466
|
-
{:else if component.type === "WidgetMap"}
|
|
471
|
+
{:else if component.type === "WidgetMap" && views.WidgetMap}
|
|
472
|
+
{@const WidgetMap = views.WidgetMap}
|
|
467
473
|
<WidgetMap
|
|
468
474
|
{...component.properties}
|
|
469
475
|
value={stable(
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Snippet } from "svelte";
|
|
2
2
|
import type { UIComponent, UIType } from "../types";
|
|
3
3
|
import { type DeviceLink } from "../gui";
|
|
4
|
+
import type { GuiViews } from "../guiViews";
|
|
4
5
|
interface Props {
|
|
5
6
|
components: UIComponent[];
|
|
6
7
|
link: DeviceLink;
|
|
@@ -8,6 +9,7 @@ interface Props {
|
|
|
8
9
|
viewer?: boolean;
|
|
9
10
|
persistKey?: string;
|
|
10
11
|
render?: Partial<Record<UIType, Snippet<[UIComponent]>>>;
|
|
12
|
+
views: GuiViews;
|
|
11
13
|
onError?: (message: string) => void;
|
|
12
14
|
}
|
|
13
15
|
declare const GUIRenderer: import("svelte").Component<Props, {}, "">;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { UIType } from "./types";
|
|
2
|
+
export type ComponentIO = "none" | "read" | "write" | "readWrite" | "widget";
|
|
3
|
+
export interface ComponentMeta {
|
|
4
|
+
io: ComponentIO;
|
|
5
|
+
fields?: object;
|
|
6
|
+
}
|
|
7
|
+
export declare const COMPONENT_META: Record<UIType, ComponentMeta>;
|
|
8
|
+
export declare const componentVariables: (component: {
|
|
9
|
+
type: UIType;
|
|
10
|
+
properties: object;
|
|
11
|
+
}) => string[];
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/* $lib/componentMeta.ts - метаданные типов GUI без самих компонентов: обмен с устройством и поля смарт-виджетов. GUIRenderer берёт их отсюда, а не из registry.ts, иначе в сборку приложения попали бы все виджеты */
|
|
2
|
+
import { WIDGET_FIELDS, widgetKey, widgetPrefixes } from "./gui";
|
|
3
|
+
export const COMPONENT_META = {
|
|
4
|
+
Accordion: { io: "none" },
|
|
5
|
+
Tabs: { io: "none" },
|
|
6
|
+
TextField: { io: "none" },
|
|
7
|
+
Divider: { io: "none" },
|
|
8
|
+
Button: { io: "write" },
|
|
9
|
+
FileAttach: { io: "write" },
|
|
10
|
+
Input: { io: "readWrite" },
|
|
11
|
+
Select: { io: "readWrite" },
|
|
12
|
+
Switch: { io: "readWrite" },
|
|
13
|
+
Slider: { io: "readWrite" },
|
|
14
|
+
Joystick: { io: "readWrite" },
|
|
15
|
+
Widget: { io: "readWrite" },
|
|
16
|
+
ProgressBar: { io: "read" },
|
|
17
|
+
Graph: { io: "read" },
|
|
18
|
+
PeriodChart: { io: "read" },
|
|
19
|
+
Table: { io: "read" },
|
|
20
|
+
VideoViewer: { io: "none" },
|
|
21
|
+
WidgetWiFi: { io: "widget", fields: WIDGET_FIELDS.WidgetWiFi },
|
|
22
|
+
WidgetDeviceInfo: { io: "widget", fields: WIDGET_FIELDS.WidgetDeviceInfo },
|
|
23
|
+
WidgetFileSystem: { io: "widget", fields: WIDGET_FIELDS.WidgetFileSystem },
|
|
24
|
+
WidgetStackInfo: { io: "widget", fields: WIDGET_FIELDS.WidgetStackInfo },
|
|
25
|
+
WidgetRGBStrip: { io: "widget", fields: WIDGET_FIELDS.WidgetRGBStrip },
|
|
26
|
+
WidgetPFD: { io: "widget", fields: WIDGET_FIELDS.WidgetPFD },
|
|
27
|
+
WidgetMap: { io: "widget", fields: WIDGET_FIELDS.WidgetMap },
|
|
28
|
+
};
|
|
29
|
+
/* Переменные устройства компонента (без префикса модуля): поля смарт-виджета, properties.id компонента с данными, переменные уровней PeriodChart */
|
|
30
|
+
export const componentVariables = (component) => {
|
|
31
|
+
const entry = COMPONENT_META[component.type];
|
|
32
|
+
const props = component.properties;
|
|
33
|
+
if (entry.io === "widget")
|
|
34
|
+
return widgetPrefixes(component.type, props).flatMap((prefix) => Object.keys(entry.fields ?? {}).map((field) => widgetKey(prefix, field, props.keys)));
|
|
35
|
+
if (entry.io === "none" || entry.io === "write" || !props.id)
|
|
36
|
+
return [];
|
|
37
|
+
return [props.id, ...(props.levels ?? []).flatMap((level) => (level.variable ? [level.variable] : []))];
|
|
38
|
+
};
|
package/dist/gui.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DeviceTransport } from "./fsTransfer";
|
|
2
|
-
import type { IUIComponentHandler, IWidgetFileSystemInfo, IWidgetStackInfo, UIComponent } from "./types";
|
|
2
|
+
import type { IUIComponentHandler, IWidgetFileSystemInfo, IWidgetStackInfo, UIComponent, UIType } from "./types";
|
|
3
3
|
export declare const GUI_GRID: {
|
|
4
4
|
readonly columns: 23;
|
|
5
5
|
readonly cellHeight: 6;
|
|
@@ -164,3 +164,6 @@ export type FlowNode = {
|
|
|
164
164
|
export declare const layoutFlow: (list: UIComponent[]) => FlowNode;
|
|
165
165
|
export declare const flowMinWidth: (node: FlowNode) => number;
|
|
166
166
|
export declare const layoutColumns: (list: UIComponent[], total: number) => string;
|
|
167
|
+
export declare const guiTypes: (components: readonly {
|
|
168
|
+
type: UIType;
|
|
169
|
+
}[]) => UIType[];
|
package/dist/gui.js
CHANGED
|
@@ -335,3 +335,5 @@ export const layoutColumns = (list, total) => {
|
|
|
335
335
|
const last = Math.max(...used);
|
|
336
336
|
return Array.from({ length: count }, (_, i) => (i + 1 > first && i + 1 < last && !used.has(i + 1) ? GUTTER : "minmax(0, 1fr)")).join(" ");
|
|
337
337
|
};
|
|
338
|
+
/* Типы компонентов, которые встречаются в GUI (по порядку первого появления): по ним приложение собирает views для GUIRenderer, чтобы в сборку попали только они */
|
|
339
|
+
export const guiTypes = (components) => [...new Set(components.map((component) => component.type))];
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import Accordion from "./Accordion/Accordion.svelte";
|
|
2
|
+
import Button from "./Button/Button.svelte";
|
|
3
|
+
import Divider from "./Divider/Divider.svelte";
|
|
4
|
+
import FileAttach from "./FileAttach/FileAttach.svelte";
|
|
5
|
+
import Graph from "./Graph/Graph.svelte";
|
|
6
|
+
import Input from "./Input/Input.svelte";
|
|
7
|
+
import Joystick from "./Joystick/Joystick.svelte";
|
|
8
|
+
import PeriodChart from "./PeriodChart/PeriodChart.svelte";
|
|
9
|
+
import ProgressBar from "./ProgressBar/ProgressBar.svelte";
|
|
10
|
+
import Select from "./Select/Select.svelte";
|
|
11
|
+
import Slider from "./Slider/Slider.svelte";
|
|
12
|
+
import Switch from "./Switch/Switch.svelte";
|
|
13
|
+
import Table from "./Table/Table.svelte";
|
|
14
|
+
import Tabs from "./Tabs/Tabs.svelte";
|
|
15
|
+
import TextField from "./TextField/TextField.svelte";
|
|
16
|
+
import VideoViewer from "./VideoViewer/VideoViewer.svelte";
|
|
17
|
+
import Widget from "./Widget/Widget.svelte";
|
|
18
|
+
import WidgetWiFi from "./WidgetWiFi/WidgetWiFi.svelte";
|
|
19
|
+
import WidgetDeviceInfo from "./WidgetDeviceInfo/WidgetDeviceInfo.svelte";
|
|
20
|
+
import WidgetFileSystem from "./WidgetFileSystem/WidgetFileSystem.svelte";
|
|
21
|
+
import WidgetStackInfo from "./WidgetStackInfo/WidgetStackInfo.svelte";
|
|
22
|
+
import WidgetRGBStrip from "./WidgetRGBStrip/WidgetRGBStrip.svelte";
|
|
23
|
+
import WidgetPFD from "./WidgetPFD/WidgetPFD.svelte";
|
|
24
|
+
import WidgetMap from "./WidgetMap/WidgetMap.svelte";
|
|
25
|
+
export interface GuiViewsAll {
|
|
26
|
+
Accordion: typeof Accordion;
|
|
27
|
+
Button: typeof Button;
|
|
28
|
+
Divider: typeof Divider;
|
|
29
|
+
FileAttach: typeof FileAttach;
|
|
30
|
+
Graph: typeof Graph;
|
|
31
|
+
Input: typeof Input;
|
|
32
|
+
Joystick: typeof Joystick;
|
|
33
|
+
PeriodChart: typeof PeriodChart;
|
|
34
|
+
ProgressBar: typeof ProgressBar;
|
|
35
|
+
Select: typeof Select;
|
|
36
|
+
Slider: typeof Slider;
|
|
37
|
+
Switch: typeof Switch;
|
|
38
|
+
Table: typeof Table;
|
|
39
|
+
Tabs: typeof Tabs;
|
|
40
|
+
TextField: typeof TextField;
|
|
41
|
+
VideoViewer: typeof VideoViewer;
|
|
42
|
+
Widget: typeof Widget;
|
|
43
|
+
WidgetWiFi: typeof WidgetWiFi;
|
|
44
|
+
WidgetDeviceInfo: typeof WidgetDeviceInfo;
|
|
45
|
+
WidgetFileSystem: typeof WidgetFileSystem;
|
|
46
|
+
WidgetStackInfo: typeof WidgetStackInfo;
|
|
47
|
+
WidgetRGBStrip: typeof WidgetRGBStrip;
|
|
48
|
+
WidgetPFD: typeof WidgetPFD;
|
|
49
|
+
WidgetMap: typeof WidgetMap;
|
|
50
|
+
}
|
|
51
|
+
export declare const GUI_VIEWS: GuiViewsAll;
|
|
52
|
+
export type GuiViews = Partial<GuiViewsAll>;
|
package/dist/guiViews.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import Accordion from "./Accordion/Accordion.svelte";
|
|
2
|
+
import Button from "./Button/Button.svelte";
|
|
3
|
+
import Divider from "./Divider/Divider.svelte";
|
|
4
|
+
import FileAttach from "./FileAttach/FileAttach.svelte";
|
|
5
|
+
import Graph from "./Graph/Graph.svelte";
|
|
6
|
+
import Input from "./Input/Input.svelte";
|
|
7
|
+
import Joystick from "./Joystick/Joystick.svelte";
|
|
8
|
+
import PeriodChart from "./PeriodChart/PeriodChart.svelte";
|
|
9
|
+
import ProgressBar from "./ProgressBar/ProgressBar.svelte";
|
|
10
|
+
import Select from "./Select/Select.svelte";
|
|
11
|
+
import Slider from "./Slider/Slider.svelte";
|
|
12
|
+
import Switch from "./Switch/Switch.svelte";
|
|
13
|
+
import Table from "./Table/Table.svelte";
|
|
14
|
+
import Tabs from "./Tabs/Tabs.svelte";
|
|
15
|
+
import TextField from "./TextField/TextField.svelte";
|
|
16
|
+
import VideoViewer from "./VideoViewer/VideoViewer.svelte";
|
|
17
|
+
import Widget from "./Widget/Widget.svelte";
|
|
18
|
+
import WidgetWiFi from "./WidgetWiFi/WidgetWiFi.svelte";
|
|
19
|
+
import WidgetDeviceInfo from "./WidgetDeviceInfo/WidgetDeviceInfo.svelte";
|
|
20
|
+
import WidgetFileSystem from "./WidgetFileSystem/WidgetFileSystem.svelte";
|
|
21
|
+
import WidgetStackInfo from "./WidgetStackInfo/WidgetStackInfo.svelte";
|
|
22
|
+
import WidgetRGBStrip from "./WidgetRGBStrip/WidgetRGBStrip.svelte";
|
|
23
|
+
import WidgetPFD from "./WidgetPFD/WidgetPFD.svelte";
|
|
24
|
+
import WidgetMap from "./WidgetMap/WidgetMap.svelte";
|
|
25
|
+
/* Все типы - для облака, терминала и конструктора; приложению с ограниченной памятью - свой набор из отдельных компонентов */
|
|
26
|
+
export const GUI_VIEWS = {
|
|
27
|
+
Accordion,
|
|
28
|
+
Button,
|
|
29
|
+
Divider,
|
|
30
|
+
FileAttach,
|
|
31
|
+
Graph,
|
|
32
|
+
Input,
|
|
33
|
+
Joystick,
|
|
34
|
+
PeriodChart,
|
|
35
|
+
ProgressBar,
|
|
36
|
+
Select,
|
|
37
|
+
Slider,
|
|
38
|
+
Switch,
|
|
39
|
+
Table,
|
|
40
|
+
Tabs,
|
|
41
|
+
TextField,
|
|
42
|
+
VideoViewer,
|
|
43
|
+
Widget,
|
|
44
|
+
WidgetWiFi,
|
|
45
|
+
WidgetDeviceInfo,
|
|
46
|
+
WidgetFileSystem,
|
|
47
|
+
WidgetStackInfo,
|
|
48
|
+
WidgetRGBStrip,
|
|
49
|
+
WidgetPFD,
|
|
50
|
+
WidgetMap,
|
|
51
|
+
};
|
|
52
|
+
/* Каждый тип GUI есть в GuiViewsAll: новый тип без компонента - ошибка компиляции */
|
|
53
|
+
const _everyType = GUI_VIEWS;
|
|
54
|
+
void _everyType;
|
package/dist/index.d.ts
CHANGED
|
@@ -43,7 +43,9 @@ export * from "./locales/languages";
|
|
|
43
43
|
export { localizeDeep, type LocalizedText } from "./locales/localize";
|
|
44
44
|
export { accentStyle, ACCENT_COLORS, type AccentColor } from "./accent";
|
|
45
45
|
export { default as GUIRenderer } from "./GUIRenderer/GUIRenderer.svelte";
|
|
46
|
-
export {
|
|
46
|
+
export { GUI_VIEWS, type GuiViews } from "./guiViews";
|
|
47
|
+
export { COMPONENTS, type ComponentEntry } from "./registry";
|
|
48
|
+
export { COMPONENT_META, componentVariables, type ComponentMeta, type ComponentIO } from "./componentMeta";
|
|
47
49
|
export { GUI_GRID, isWidgetType, spanRows, WIDGET_FIELDS, WIDGET_SAVE_FIELDS, widgetKey, widgetPrefixes, readWidgetFields, widgetPacket, bitRange, readBits, writeBits, commandPacket, tablePacket, mergeDevicePayload, type WidgetFieldsType, type DeviceLink, type DevicePacket, } from "./gui";
|
|
48
50
|
export { createFsTransfer, sendCommand, argumentCode, FsTransferError, FsNameError, type FsErrorCode, type DeviceReply, type DeviceTransport, type FsTransfer, type FsTransferOptions, type FsProgress, } from "./fsTransfer";
|
|
49
51
|
export { copyText } from "./clipboard";
|
package/dist/index.js
CHANGED
|
@@ -44,7 +44,9 @@ export * from "./locales/languages";
|
|
|
44
44
|
export { localizeDeep } from "./locales/localize";
|
|
45
45
|
export { accentStyle, ACCENT_COLORS } from "./accent";
|
|
46
46
|
export { default as GUIRenderer } from "./GUIRenderer/GUIRenderer.svelte";
|
|
47
|
-
export {
|
|
47
|
+
export { GUI_VIEWS } from "./guiViews";
|
|
48
|
+
export { COMPONENTS } from "./registry";
|
|
49
|
+
export { COMPONENT_META, componentVariables } from "./componentMeta";
|
|
48
50
|
export { GUI_GRID, isWidgetType, spanRows, WIDGET_FIELDS, WIDGET_SAVE_FIELDS, widgetKey, widgetPrefixes, readWidgetFields, widgetPacket, bitRange, readBits, writeBits, commandPacket, tablePacket, mergeDevicePayload, } from "./gui";
|
|
49
51
|
export { createFsTransfer, sendCommand, argumentCode, FsTransferError, FsNameError, } from "./fsTransfer";
|
|
50
52
|
export { copyText } from "./clipboard";
|
|
@@ -2,6 +2,7 @@ const translations = {
|
|
|
2
2
|
"common.select_tag": { ru: "Сделайте выбор", en: "Make a choice", zh: "请选择" },
|
|
3
3
|
"common.table.clear": { ru: "Очистить таблицу", en: "Clear table", zh: "清空表格" },
|
|
4
4
|
"library.retry": { ru: "Повторить", en: "Retry", zh: "重试" },
|
|
5
|
+
"gui.view_missing": { ru: "Компонент не входит в эту сборку", en: "Component is not included in this build", zh: "此版本不包含该组件" },
|
|
5
6
|
"gui.error.event_handler": {
|
|
6
7
|
ru: "Команда компонента не собрана: проверьте eventHandler",
|
|
7
8
|
en: "Component command not built: check eventHandler",
|
package/dist/registry.d.ts
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
import type { Component } from "svelte";
|
|
2
|
+
import { type ComponentMeta } from "./componentMeta";
|
|
2
3
|
import type { UIType } from "./types";
|
|
3
|
-
export
|
|
4
|
-
export interface ComponentEntry {
|
|
4
|
+
export interface ComponentEntry extends ComponentMeta {
|
|
5
5
|
view: Component<any, any, any>;
|
|
6
|
-
io: ComponentIO;
|
|
7
|
-
fields?: object;
|
|
8
6
|
}
|
|
9
7
|
export declare const COMPONENTS: Record<UIType, ComponentEntry>;
|
|
10
|
-
export declare const componentVariables: (component: {
|
|
11
|
-
type: UIType;
|
|
12
|
-
properties: object;
|
|
13
|
-
}) => string[];
|
package/dist/registry.js
CHANGED
|
@@ -22,40 +22,32 @@ import WidgetStackInfo from "./WidgetStackInfo/WidgetStackInfo.svelte";
|
|
|
22
22
|
import WidgetRGBStrip from "./WidgetRGBStrip/WidgetRGBStrip.svelte";
|
|
23
23
|
import WidgetPFD from "./WidgetPFD/WidgetPFD.svelte";
|
|
24
24
|
import WidgetMap from "./WidgetMap/WidgetMap.svelte";
|
|
25
|
-
import {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
Divider
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
Input
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
VideoViewer
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
/* Переменные устройства компонента (без префикса модуля): поля смарт-виджета, properties.id компонента с данными, переменные уровней PeriodChart */
|
|
53
|
-
export const componentVariables = (component) => {
|
|
54
|
-
const entry = COMPONENTS[component.type];
|
|
55
|
-
const props = component.properties;
|
|
56
|
-
if (entry.io === "widget")
|
|
57
|
-
return widgetPrefixes(component.type, props).flatMap((prefix) => Object.keys(entry.fields ?? {}).map((field) => widgetKey(prefix, field, props.keys)));
|
|
58
|
-
if (entry.io === "none" || entry.io === "write" || !props.id)
|
|
59
|
-
return [];
|
|
60
|
-
return [props.id, ...(props.levels ?? []).flatMap((level) => (level.variable ? [level.variable] : []))];
|
|
25
|
+
import { COMPONENT_META } from "./componentMeta";
|
|
26
|
+
/* Компонент каждого типа - для конструктора: тянет в сборку все виджеты, поэтому GUIRenderer его не импортирует (метаданные - componentMeta.ts) */
|
|
27
|
+
const VIEWS = {
|
|
28
|
+
Accordion,
|
|
29
|
+
Button,
|
|
30
|
+
Divider,
|
|
31
|
+
FileAttach,
|
|
32
|
+
Graph,
|
|
33
|
+
Input,
|
|
34
|
+
Joystick,
|
|
35
|
+
PeriodChart,
|
|
36
|
+
ProgressBar,
|
|
37
|
+
Select,
|
|
38
|
+
Slider,
|
|
39
|
+
Switch,
|
|
40
|
+
Table,
|
|
41
|
+
Tabs,
|
|
42
|
+
TextField,
|
|
43
|
+
VideoViewer,
|
|
44
|
+
Widget,
|
|
45
|
+
WidgetWiFi,
|
|
46
|
+
WidgetDeviceInfo,
|
|
47
|
+
WidgetFileSystem,
|
|
48
|
+
WidgetStackInfo,
|
|
49
|
+
WidgetRGBStrip,
|
|
50
|
+
WidgetPFD,
|
|
51
|
+
WidgetMap,
|
|
61
52
|
};
|
|
53
|
+
export const COMPONENTS = Object.fromEntries(Object.keys(COMPONENT_META).map((type) => [type, { ...COMPONENT_META[type], view: VIEWS[type] }]));
|
package/package.json
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "poe-svelte-ui-lib",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.12.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/Oleg-Perevyshin/ElementsUI.git"
|
|
7
7
|
},
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"type": "module",
|
|
10
|
+
"sideEffects": [
|
|
11
|
+
"**/*.css"
|
|
12
|
+
],
|
|
10
13
|
"imports": {
|
|
11
14
|
"#lib": "./src/lib/index.ts",
|
|
12
15
|
"#lib/*": "./src/lib/*"
|