poe-svelte-ui-lib 2.11.0 → 2.13.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 CHANGED
@@ -128,12 +128,12 @@
128
128
  persistKey={module.ModSN}
129
129
  viewer={!canManage}
130
130
  render={{ VideoViewer: video }}
131
- extras={UI.GUI_EXTRAS}
131
+ views={UI.GUI_VIEWS}
132
132
  onError={addMessage}
133
133
  />
134
134
  ```
135
135
 
136
- **📦 Что попадает в сборку.** Тяжёлые компоненты - `WidgetMap`, `WidgetPFD`, `VideoViewer` и `Joystick` - `GUIRenderer` берёт из пропса `extras`. Передайте `UI.GUI_EXTRAS` целиком или только нужные из них. Чего нет в `extras`, то не попадает в сборку приложения и рисуется заглушкой «Компонент не входит в эту сборку». Так веб-интерфейс прошивки без карты и пилотажного прибора меньше примерно на 48 КБ сжатого JS. Облако и терминал передают полный набор.
136
+ **📦 Что попадает в сборку.** `GUIRenderer` сам не импортирует ни одного компонента: каждый тип он берёт из пропса `views`. Облако и терминал передают `UI.GUI_VIEWS` - все типы. Приложению с ограниченной памятью (веб-интерфейс прошивки) достаточно перечислить только нужные: `{ Button: UI.Button, Input: UI.Input, ... }`. Чего нет в `views`, то не попадает в сборку и рисуется заглушкой «Компонент не входит в эту сборку». Какие типы есть в GUI, возвращает `guiTypes(components)`.
137
137
 
138
138
  **📐 Правила для автора GUI.** Рендерер понимает интерфейс по группам, поэтому при сборке в конструкторе соблюдайте правила:
139
139
 
@@ -169,7 +169,7 @@
169
169
  | `viewer` | наблюдатель: видны только `access` `full` и `viewOnly`, управление отключено; `WidgetWiFi` и `WidgetDeviceInfo` без `onSave` - только для чтения, пароли маской |
170
170
  | `persistKey` | ключ хранения в браузере (обычно `ModSN`): свёрнутость виджетов, планы `WidgetMap` |
171
171
  | `render` | своя отрисовка типа: `{ VideoViewer: snippet }`, сниппет получает компонент |
172
- | `extras` | тяжёлые компоненты: `GUI_EXTRAS` или их часть; тип без компонента рисуется заглушкой |
172
+ | `views` | компоненты отрисовки по типу: `GUI_VIEWS` или только нужные; тип без компонента рисуется заглушкой |
173
173
  | `onError` | готовый текст ошибки на языке библиотеки: команда не собрана, ошибка передачи файла, сбой поиска сетей WiFi (ER! или нет ответа) |
174
174
 
175
175
  ```ts
@@ -238,6 +238,7 @@ socket.send(valueToCbor(encodeWsEnvelope("SET", "JoinDev", { DevSN, Watch: true
238
238
  | `widgetPacket(prefix, fields, values, keys)` | Payload `SET ModCfg` виджета |
239
239
  | `WIDGET_FIELDS`, `WIDGET_SAVE_FIELDS`, `widgetPrefixes` | поля смарт-виджетов (из них выведены `IWidgetWiFiConfig` и остальные), сохраняемые поля, группы |
240
240
  | `GUI_GRID`, `spanRows`, `isWidgetType` | сетка |
241
+ | `guiTypes` | типы компонентов в GUI - из них приложение собирает `views` рендерера |
241
242
 
242
243
  **Реестр.**
243
244
 
@@ -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
- let { properties, value, onClick }: { properties: ITableProps<Row>; value: unknown; onClick?: (row: Row, button: ITableButton<Row>) => void } = $props()
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
- <Table bind:this={table} {...properties} body={properties.dataBuffer?.stashData ? undefined : rows} {onClick} />
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;
@@ -28,27 +28,8 @@
28
28
  type DevicePacket,
29
29
  } from "../gui"
30
30
  import { COMPONENT_META } from "../componentMeta"
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 Widget from "../Widget/Widget.svelte"
39
- import TextField from "../TextField/TextField.svelte"
40
- import Divider from "../Divider/Divider.svelte"
41
- import ProgressBar from "../ProgressBar/ProgressBar.svelte"
42
- import Graph from "../Graph/Graph.svelte"
43
- import PeriodChart from "../PeriodChart/PeriodChart.svelte"
44
- import FileAttach from "../FileAttach/FileAttach.svelte"
45
- import WidgetWiFi from "../WidgetWiFi/WidgetWiFi.svelte"
46
- import WidgetDeviceInfo from "../WidgetDeviceInfo/WidgetDeviceInfo.svelte"
47
- import WidgetFileSystem from "../WidgetFileSystem/WidgetFileSystem.svelte"
48
- import WidgetStackInfo from "../WidgetStackInfo/WidgetStackInfo.svelte"
49
- import WidgetRGBStrip from "../WidgetRGBStrip/WidgetRGBStrip.svelte"
50
31
  import DeviceTable from "./DeviceTable.svelte"
51
- import type { GuiExtras } from "./extras"
32
+ import type { GuiViews } from "../guiViews"
52
33
 
53
34
  interface Props {
54
35
  components: UIComponent[]
@@ -61,16 +42,13 @@
61
42
  persistKey?: string
62
43
  /* Своя отрисовка типа (например VideoViewer с потоком приложения) */
63
44
  render?: Partial<Record<UIType, Snippet<[UIComponent]>>>
64
- /* Тяжёлые компоненты (GUI_EXTRAS или их часть): без них тип рисуется заглушкой и не попадает в сборку приложения */
65
- extras?: GuiExtras
45
+ /* Компоненты отрисовки по типу (GUI_VIEWS или только нужные): тип без компонента рисуется заглушкой и не попадает в сборку приложения */
46
+ views: GuiViews
66
47
  /* Ошибка команды или передачи файла, для уведомления */
67
48
  onError?: (message: string) => void
68
49
  }
69
50
 
70
- let { components, link, language, viewer = false, persistKey, render, extras, onError }: Props = $props()
71
-
72
- /* Типы из GUI_EXTRAS - списком, а не из модуля: импорт GUI_EXTRAS сюда затянул бы их в любую сборку */
73
- const EXTRA_TYPES: readonly UIType[] = ["Joystick", "VideoViewer", "WidgetPFD", "WidgetMap"]
51
+ let { components, link, language, viewer = false, persistKey, render, views, onError }: Props = $props()
74
52
 
75
53
  /* Кэш по ссылке и языку: localizeDeep создаёт новые объекты, без кэша обновление значений сбрасывало бы раскрытые аккордеоны и вкладки */
76
54
  let localized: { src?: UIComponent[]; lang?: string; out: UIComponent[] } = { out: [] }
@@ -298,34 +276,39 @@
298
276
  <div class={component.type === "Accordion" ? "" : "flex flex-col justify-start"} style={cellStyle(component, fixedHeight)}>
299
277
  {#if render?.[component.type]}
300
278
  {@render render[component.type]?.(component)}
301
- {:else if component.type === "Accordion"}
279
+ {:else if component.type === "Accordion" && views.Accordion}
280
+ {@const Accordion = views.Accordion}
302
281
  <Accordion {...component.properties}>
303
282
  <!-- Своя сетка содержимого во всю ширину аккордеона: колонок не меньше, чем у самого дальнего блока -->
304
283
  <div class="min-w-0" style="grid-column: 1 / -1; grid-row: 1 / -1">
305
284
  {@render Layout(childrenOf(component).filter(visible), component.properties.size?.width ?? 1, !!component.properties.image)}
306
285
  </div>
307
286
  </Accordion>
308
- {:else if component.type === "Tabs"}
287
+ {:else if component.type === "Tabs" && views.Tabs}
288
+ {@const Tabs = views.Tabs}
309
289
  <!-- Содержимое вкладки - через Layout, как у Accordion: на телефоне раскладка по группам, а не одна колонка сетки size.width -->
310
290
  <Tabs {...component.properties} apiArray={childrenOf(component)}>
311
291
  {#snippet Content(list: UIComponent[])}
312
292
  {@render Layout(list.filter(visible), component.properties.size?.width ?? 1, false)}
313
293
  {/snippet}
314
294
  </Tabs>
315
- {:else if component.type === "Button"}
295
+ {:else if component.type === "Button" && views.Button}
296
+ {@const Button = views.Button}
316
297
  <Button
317
298
  {...component.properties}
318
299
  disabled={locked || component.properties.disabled}
319
300
  onClick={() => dispatch(commandPacket(component.eventHandler, get))}
320
301
  />
321
- {:else if component.type === "Input"}
302
+ {:else if component.type === "Input" && views.Input}
303
+ {@const Input = views.Input}
322
304
  <Input
323
305
  {...component.properties}
324
306
  readonly={locked || component.properties.readonly}
325
307
  value={(readBits(component, link.get(id)) as string | number | undefined) ?? component.properties.value}
326
308
  onUpdate={(value) => change(component, value)}
327
309
  />
328
- {:else if component.type === "Select"}
310
+ {:else if component.type === "Select" && views.Select}
311
+ {@const Select = views.Select}
329
312
  <Select
330
313
  {...component.properties}
331
314
  disabled={locked || component.properties.disabled}
@@ -333,49 +316,57 @@
333
316
  options={selectOptions(component)}
334
317
  onUpdate={(value) => change(component, value)}
335
318
  />
336
- {:else if component.type === "Switch"}
319
+ {:else if component.type === "Switch" && views.Switch}
320
+ {@const Switch = views.Switch}
337
321
  <Switch
338
322
  {...component.properties}
339
323
  disabled={locked || component.properties.disabled}
340
324
  value={link.get(id) as number}
341
325
  onUpdate={(value) => change(component, value)}
342
326
  />
343
- {:else if component.type === "Slider"}
327
+ {:else if component.type === "Slider" && views.Slider}
328
+ {@const Slider = views.Slider}
344
329
  <Slider
345
330
  {...component.properties}
346
331
  disabled={locked || component.properties.disabled}
347
332
  value={link.get(id) as number | [number, number]}
348
333
  onUpdate={(value) => change(component, value)}
349
334
  />
350
- {:else if EXTRA_TYPES.includes(component.type) && !extras?.[component.type as keyof GuiExtras]}
351
- <p class="flex h-full items-center justify-center p-2 text-center text-[12px] text-(--muted-color)">{$T("gui.extra_missing")}: {component.type}</p>
352
- {:else if component.type === "Joystick" && extras?.Joystick}
353
- {@const Joystick = extras.Joystick}
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}
354
339
  <Joystick
355
340
  {...component.properties}
356
341
  readonly={locked || component.properties.readonly}
357
342
  value={link.get(id) as number[]}
358
343
  onUpdate={(value) => change(component, value)}
359
344
  />
360
- {:else if component.type === "Widget"}
345
+ {:else if component.type === "Widget" && views.Widget}
346
+ {@const Widget = views.Widget}
361
347
  <Widget
362
348
  {...component.properties}
363
349
  readonly={locked || component.properties.readonly}
364
350
  value={link.get(id) as number}
365
351
  onUpdate={(value) => change(component, value)}
366
352
  />
367
- {:else if component.type === "TextField"}
353
+ {:else if component.type === "TextField" && views.TextField}
354
+ {@const TextField = views.TextField}
368
355
  <TextField {...component.properties} />
369
- {:else if component.type === "Divider"}
356
+ {:else if component.type === "Divider" && views.Divider}
357
+ {@const Divider = views.Divider}
370
358
  <Divider {...component.properties} />
371
- {:else if component.type === "ProgressBar"}
359
+ {:else if component.type === "ProgressBar" && views.ProgressBar}
360
+ {@const ProgressBar = views.ProgressBar}
372
361
  <ProgressBar {...component.properties} value={link.get(id) as never} />
373
- {:else if component.type === "Graph"}
362
+ {:else if component.type === "Graph" && views.Graph}
363
+ {@const Graph = views.Graph}
374
364
  <Graph
375
365
  {...component.properties}
376
366
  streamingData={{ data: component.properties.isTest ? (component.properties.streamingData?.data ?? null) : (link.get(id) as never) }}
377
367
  />
378
- {:else if component.type === "PeriodChart"}
368
+ {:else if component.type === "PeriodChart" && views.PeriodChart}
369
+ {@const PeriodChart = views.PeriodChart}
379
370
  <PeriodChart
380
371
  {...component.properties}
381
372
  levels={(component.properties.levels ?? []).map((level) => ({
@@ -383,22 +374,25 @@
383
374
  data: ((level.variable && link.get(level.variable)) as number[] | undefined) ?? level.data ?? [],
384
375
  }))}
385
376
  />
386
- {:else if component.type === "Table"}
377
+ {:else if component.type === "Table" && views.Table}
387
378
  <DeviceTable
379
+ view={views.Table}
388
380
  properties={component.properties}
389
381
  value={tableRows(component)}
390
382
  onClick={locked ? undefined : (row: Row, button: ITableButton<Row>) => dispatch(tablePacket(button.eventHandler, row))}
391
383
  />
392
- {:else if component.type === "FileAttach"}
384
+ {:else if component.type === "FileAttach" && views.FileAttach}
385
+ {@const FileAttach = views.FileAttach}
393
386
  <FileAttach
394
387
  {...component.properties}
395
388
  disabled={locked || component.properties.disabled}
396
389
  onUpdate={(file) => file && fs().upload(file.name, file).catch(report)}
397
390
  />
398
- {:else if component.type === "VideoViewer" && extras?.VideoViewer}
399
- {@const VideoViewer = extras.VideoViewer}
391
+ {:else if component.type === "VideoViewer" && views.VideoViewer}
392
+ {@const VideoViewer = views.VideoViewer}
400
393
  <VideoViewer {...component.properties} />
401
- {:else if component.type === "WidgetWiFi"}
394
+ {:else if component.type === "WidgetWiFi" && views.WidgetWiFi}
395
+ {@const WidgetWiFi = views.WidgetWiFi}
402
396
  {@const props = component.properties}
403
397
  {@const prefix = widgetPrefixes(component.type, props)[0]}
404
398
  <WidgetWiFi
@@ -408,7 +402,8 @@
408
402
  onScan={locked ? undefined : () => scanWiFi(prefix, props.keys, props.scanCommand)}
409
403
  onSave={locked ? undefined : (config) => saveFields(prefix, WIDGET_SAVE_FIELDS.WidgetWiFi, config, props.keys)}
410
404
  />
411
- {:else if component.type === "WidgetDeviceInfo"}
405
+ {:else if component.type === "WidgetDeviceInfo" && views.WidgetDeviceInfo}
406
+ {@const WidgetDeviceInfo = views.WidgetDeviceInfo}
412
407
  {@const props = component.properties}
413
408
  {@const prefix = widgetPrefixes(component.type, props)[0]}
414
409
  <WidgetDeviceInfo
@@ -427,7 +422,8 @@
427
422
  onRestart={locked ? undefined : () => send(props.restartCommand?.header || "SET", props.restartCommand?.argument || "Restart", {})}
428
423
  onFactoryReset={locked ? undefined : () => send(props.resetCommand?.header || "SET", props.resetCommand?.argument || "RstNVS", {})}
429
424
  />
430
- {:else if component.type === "WidgetFileSystem"}
425
+ {:else if component.type === "WidgetFileSystem" && views.WidgetFileSystem}
426
+ {@const WidgetFileSystem = views.WidgetFileSystem}
431
427
  {@const props = component.properties}
432
428
  {@const argument = props.argument || "FS"}
433
429
  {@const transfer = () => fs(argument, props.maxNameLength)}
@@ -445,7 +441,8 @@
445
441
  .download(name)
446
442
  .then((bytes) => saveFile(name, bytes), fail)}
447
443
  />
448
- {:else if component.type === "WidgetStackInfo"}
444
+ {:else if component.type === "WidgetStackInfo" && views.WidgetStackInfo}
445
+ {@const WidgetStackInfo = views.WidgetStackInfo}
449
446
  {@const props = component.properties}
450
447
  <WidgetStackInfo
451
448
  {...props}
@@ -453,7 +450,8 @@
453
450
  persistKey={persist(component)}
454
451
  onRefresh={() => send("GET", props.argument || "StackInfo", {})}
455
452
  />
456
- {:else if component.type === "WidgetRGBStrip"}
453
+ {:else if component.type === "WidgetRGBStrip" && views.WidgetRGBStrip}
454
+ {@const WidgetRGBStrip = views.WidgetRGBStrip}
457
455
  {@const props = component.properties}
458
456
  {@const prefix = widgetPrefixes(component.type, props)[0]}
459
457
  <WidgetRGBStrip
@@ -463,15 +461,15 @@
463
461
  onUpdate={locked ? undefined : (value, field) => saveFields(prefix, [field], { [field]: value }, props.keys)}
464
462
  onSave={locked ? undefined : (hardware) => saveFields(prefix, WIDGET_SAVE_FIELDS.WidgetRGBStrip, hardware, props.keys)}
465
463
  />
466
- {:else if component.type === "WidgetPFD" && extras?.WidgetPFD}
467
- {@const WidgetPFD = extras.WidgetPFD}
464
+ {:else if component.type === "WidgetPFD" && views.WidgetPFD}
465
+ {@const WidgetPFD = views.WidgetPFD}
468
466
  <WidgetPFD
469
467
  {...component.properties}
470
468
  value={fields(component, widgetPrefixes(component.type, component.properties)[0], WIDGET_FIELDS.WidgetPFD)}
471
469
  persistKey={persist(component)}
472
470
  />
473
- {:else if component.type === "WidgetMap" && extras?.WidgetMap}
474
- {@const WidgetMap = extras.WidgetMap}
471
+ {:else if component.type === "WidgetMap" && views.WidgetMap}
472
+ {@const WidgetMap = views.WidgetMap}
475
473
  <WidgetMap
476
474
  {...component.properties}
477
475
  value={stable(
@@ -1,7 +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 { GuiExtras } from "./extras";
4
+ import type { GuiViews } from "../guiViews";
5
5
  interface Props {
6
6
  components: UIComponent[];
7
7
  link: DeviceLink;
@@ -9,7 +9,7 @@ interface Props {
9
9
  viewer?: boolean;
10
10
  persistKey?: string;
11
11
  render?: Partial<Record<UIType, Snippet<[UIComponent]>>>;
12
- extras?: GuiExtras;
12
+ views: GuiViews;
13
13
  onError?: (message: string) => void;
14
14
  }
15
15
  declare const GUIRenderer: import("svelte").Component<Props, {}, "">;
@@ -1,31 +1,12 @@
1
1
  /* $lib/componentMeta.ts - метаданные типов GUI без самих компонентов: обмен с устройством и поля смарт-виджетов. GUIRenderer берёт их отсюда, а не из registry.ts, иначе в сборку приложения попали бы все виджеты */
2
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
- };
3
+ import { COMPONENT_IO, COMPONENT_TYPES } from "./dictionaries/generated/components";
4
+ /* Типы и обмен - из списка компонентов dictionaries/components.yaml: присваивания ниже не скомпилируются, если список и UIType разошлись в любую сторону */
5
+ const LISTED_TYPES = COMPONENT_TYPES;
6
+ const LISTED_IO = COMPONENT_IO;
7
+ /* Поля смарт-виджетов (io: widget) - из WIDGET_FIELDS */
8
+ const WIDGET_TYPE_FIELDS = WIDGET_FIELDS;
9
+ export const COMPONENT_META = Object.fromEntries(LISTED_TYPES.map((type) => [type, LISTED_IO[type] === "widget" ? { io: LISTED_IO[type], fields: WIDGET_TYPE_FIELDS[type] } : { io: LISTED_IO[type] }]));
29
10
  /* Переменные устройства компонента (без префикса модуля): поля смарт-виджета, properties.id компонента с данными, переменные уровней PeriodChart */
30
11
  export const componentVariables = (component) => {
31
12
  const entry = COMPONENT_META[component.type];
@@ -1,13 +1,14 @@
1
1
  # 📚 Словари протокола
2
2
 
3
- Единые словари команд и сообщений устройств для всего стека: прошивок ESP и STM, облака DevCloud, терминала DevTerminal и веб-интерфейса прошивок.
3
+ Единые словари команд и сообщений устройств и список компонентов GUI для всего стека: прошивок ESP и STM, облака DevCloud, терминала DevTerminal и веб-интерфейса прошивок.
4
4
 
5
5
  ## ✨ Что умеет
6
6
 
7
7
  - 📖 `commands.yaml` - словарь команд: имя аргумента, имя в перечислении C и код поля HAR.
8
8
  - 💬 `messages.yaml` - словарь сообщений устройств: группы с диапазонами кодов и сообщения (код, группа, имя, уровень, короткий понятный текст на RU, EN, ZH).
9
+ - 🧩 `components.yaml` - список компонентов GUI: тип (значение `type` в GUI и имя экспорта компонента) и обмен с устройством.
9
10
  - ⚙️ Из словарей генерируется код для JS (`generated/`) и заголовки для прошивок (`firmware/api_har.h`, `firmware/api_msg.h`).
10
- - 📦 Файлы поставляются в пакете: `poe-svelte-ui-lib/dictionaries/commands.yaml`, `poe-svelte-ui-lib/dictionaries/messages.yaml`, `poe-svelte-ui-lib/dictionaries/firmware/api_har.h`, `poe-svelte-ui-lib/dictionaries/firmware/api_msg.h`.
11
+ - 📦 Файлы поставляются в пакете: `poe-svelte-ui-lib/dictionaries/commands.yaml`, `poe-svelte-ui-lib/dictionaries/messages.yaml`, `poe-svelte-ui-lib/dictionaries/components.yaml`, `poe-svelte-ui-lib/dictionaries/firmware/api_har.h`, `poe-svelte-ui-lib/dictionaries/firmware/api_msg.h`.
11
12
 
12
13
  ## 🧩 Как пользоваться
13
14
 
@@ -23,6 +24,12 @@
23
24
  2. `npm run Dictionary`.
24
25
  3. Скопировать `messages.yaml` в `.framework/Messages.yaml` и `firmware/api_msg.h` в `components/core/api_service/api_msg.h` обоих фреймворков.
25
26
 
27
+ Новый компонент GUI:
28
+
29
+ 1. Добавить строку в `components.yaml`: `- [Тип, обмен] # описание`, обмен - `none`, `read`, `write`, `readWrite` или `widget`.
30
+ 2. `npm run Dictionary`. Тип должен быть и в `UIComponentPropsMap` (`types.ts`), и в `GUI_VIEWS` (`guiViews.ts`), иначе библиотека не скомпилируется.
31
+ 3. Скопировать `components.yaml` в `.framework/Components.yaml` фреймворков: сборка веб-интерфейса прошивки сверяет с ним GUI устройства.
32
+
26
33
  В JS словари доступны через `poe-svelte-ui-lib/protocols`: `DEFAULT_ARGUMENT_CODES`, `DEFAULT_DICTIONARY`, `DEVICE_MESSAGES`, `MESSAGE_GROUPS`, `MESSAGE_CODES`, `formatDeviceMessage`.
27
34
 
28
35
  | Группа | Коды | Что |
@@ -53,6 +60,16 @@
53
60
 
54
61
  </details>
55
62
 
63
+ <details>
64
+ <summary>🧩 Список компонентов</summary>
65
+
66
+ - Строка: `- [Тип, обмен]`, комментарий после `#` - описание. Тип в PascalCase - это и значение `type` в GUI, и имя экспорта компонента.
67
+ - Генератор падает на повторе типа и на обмене не из списка.
68
+ - `generated/components.ts` - `COMPONENT_TYPES` (кортеж типов) и `COMPONENT_IO` (тип -> обмен). Из них `componentMeta.ts` строит `COMPONENT_META`; присваивания там не скомпилируются, если список и `UIType` разошлись в любую сторону.
69
+ - Во фреймворках `.framework/Components.yaml` - копия: сборка веба прошивки останавливается, если в GUI устройства тип не из списка.
70
+
71
+ </details>
72
+
56
73
  <details>
57
74
  <summary>💬 Словарь сообщений</summary>
58
75
 
@@ -0,0 +1,35 @@
1
+ # Список компонентов GUI устройства - единый для библиотеки, облака, терминала и прошивок
2
+ # Строка: - [Тип, обмен с устройством] # описание. Тип - значение type в GUI (web_ui.yaml.gz) и имя экспорта компонента в poe-svelte-ui-lib
3
+ # Обмен: none - оформление, read - показывает переменную properties.id, write - только отправляет команду, readWrite - показывает и меняет, widget - смарт-виджет с набором полей группы
4
+ # Источник - poe-svelte-ui-lib (src/lib/dictionaries/components.yaml); .framework/Components.yaml фреймворков - копии, не править
5
+ # После правки - npm run Dictionary (generated/components.ts), затем копии во фреймворки
6
+
7
+ components:
8
+ # Контейнеры и оформление
9
+ - [Accordion, none] # сворачиваемая группа блоков
10
+ - [Tabs, none] # вкладки с блоками
11
+ - [TextField, none] # текст
12
+ - [Divider, none] # разделитель
13
+ # Управление
14
+ - [Button, write] # кнопка команды
15
+ - [FileAttach, write] # передача файла в устройство
16
+ - [Input, readWrite] # поле ввода
17
+ - [Select, readWrite] # выбор из списка или кнопками
18
+ - [Switch, readWrite] # переключатель
19
+ - [Slider, readWrite] # ползунок
20
+ - [Joystick, readWrite] # джойстик
21
+ - [Widget, readWrite] # значок с состоянием
22
+ # Отображение
23
+ - [ProgressBar, read] # шкала
24
+ - [Graph, read] # график
25
+ - [PeriodChart, read] # столбики по периодам
26
+ - [Table, read] # таблица
27
+ - [VideoViewer, none] # видео
28
+ # Смарт-виджеты
29
+ - [WidgetWiFi, widget] # настройки Wi-Fi
30
+ - [WidgetDeviceInfo, widget] # об устройстве
31
+ - [WidgetFileSystem, widget] # файлы устройства
32
+ - [WidgetStackInfo, widget] # задачи и память
33
+ - [WidgetRGBStrip, widget] # светодиодная лента
34
+ - [WidgetPFD, widget] # пилотажный прибор
35
+ - [WidgetMap, widget] # карта
@@ -0,0 +1,27 @@
1
+ export declare const COMPONENT_TYPES: readonly ["Accordion", "Tabs", "TextField", "Divider", "Button", "FileAttach", "Input", "Select", "Switch", "Slider", "Joystick", "Widget", "ProgressBar", "Graph", "PeriodChart", "Table", "VideoViewer", "WidgetWiFi", "WidgetDeviceInfo", "WidgetFileSystem", "WidgetStackInfo", "WidgetRGBStrip", "WidgetPFD", "WidgetMap"];
2
+ export declare const COMPONENT_IO: {
3
+ readonly Accordion: "none";
4
+ readonly Tabs: "none";
5
+ readonly TextField: "none";
6
+ readonly Divider: "none";
7
+ readonly Button: "write";
8
+ readonly FileAttach: "write";
9
+ readonly Input: "readWrite";
10
+ readonly Select: "readWrite";
11
+ readonly Switch: "readWrite";
12
+ readonly Slider: "readWrite";
13
+ readonly Joystick: "readWrite";
14
+ readonly Widget: "readWrite";
15
+ readonly ProgressBar: "read";
16
+ readonly Graph: "read";
17
+ readonly PeriodChart: "read";
18
+ readonly Table: "read";
19
+ readonly VideoViewer: "none";
20
+ readonly WidgetWiFi: "widget";
21
+ readonly WidgetDeviceInfo: "widget";
22
+ readonly WidgetFileSystem: "widget";
23
+ readonly WidgetStackInfo: "widget";
24
+ readonly WidgetRGBStrip: "widget";
25
+ readonly WidgetPFD: "widget";
26
+ readonly WidgetMap: "widget";
27
+ };
@@ -0,0 +1,28 @@
1
+ /* $lib/dictionaries/generated/components.ts - СГЕНЕРИРОВАНО из components.yaml (npm run Dictionary), руками не править */
2
+ export const COMPONENT_TYPES = ["Accordion", "Tabs", "TextField", "Divider", "Button", "FileAttach", "Input", "Select", "Switch", "Slider", "Joystick", "Widget", "ProgressBar", "Graph", "PeriodChart", "Table", "VideoViewer", "WidgetWiFi", "WidgetDeviceInfo", "WidgetFileSystem", "WidgetStackInfo", "WidgetRGBStrip", "WidgetPFD", "WidgetMap"];
3
+ export const COMPONENT_IO = {
4
+ Accordion: "none",
5
+ Tabs: "none",
6
+ TextField: "none",
7
+ Divider: "none",
8
+ Button: "write",
9
+ FileAttach: "write",
10
+ Input: "readWrite",
11
+ Select: "readWrite",
12
+ Switch: "readWrite",
13
+ Slider: "readWrite",
14
+ Joystick: "readWrite",
15
+ Widget: "readWrite",
16
+ ProgressBar: "read",
17
+ Graph: "read",
18
+ PeriodChart: "read",
19
+ Table: "read",
20
+ VideoViewer: "none",
21
+ WidgetWiFi: "widget",
22
+ WidgetDeviceInfo: "widget",
23
+ WidgetFileSystem: "widget",
24
+ WidgetStackInfo: "widget",
25
+ WidgetRGBStrip: "widget",
26
+ WidgetPFD: "widget",
27
+ WidgetMap: "widget",
28
+ };
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>;
@@ -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,7 @@ 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 { GUI_EXTRAS, type GuiExtras } from "./GUIRenderer/extras";
46
+ export { GUI_VIEWS, type GuiViews } from "./guiViews";
47
47
  export { COMPONENTS, type ComponentEntry } from "./registry";
48
48
  export { COMPONENT_META, componentVariables, type ComponentMeta, type ComponentIO } from "./componentMeta";
49
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";
package/dist/index.js CHANGED
@@ -44,7 +44,7 @@ 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 { GUI_EXTRAS } from "./GUIRenderer/extras";
47
+ export { GUI_VIEWS } from "./guiViews";
48
48
  export { COMPONENTS } from "./registry";
49
49
  export { COMPONENT_META, componentVariables } from "./componentMeta";
50
50
  export { GUI_GRID, isWidgetType, spanRows, WIDGET_FIELDS, WIDGET_SAVE_FIELDS, widgetKey, widgetPrefixes, readWidgetFields, widgetPacket, bitRange, readBits, writeBits, commandPacket, tablePacket, mergeDevicePayload, } from "./gui";
@@ -14,7 +14,7 @@ declare const translations: {
14
14
  en: string;
15
15
  zh: string;
16
16
  };
17
- "gui.extra_missing": {
17
+ "gui.view_missing": {
18
18
  ru: string;
19
19
  en: string;
20
20
  zh: string;
@@ -2,7 +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.extra_missing": { ru: "Компонент не входит в эту сборку", en: "Component is not included in this build", zh: "此版本不包含该组件" },
5
+ "gui.view_missing": { ru: "Компонент не входит в эту сборку", en: "Component is not included in this build", zh: "此版本不包含该组件" },
6
6
  "gui.error.event_handler": {
7
7
  ru: "Команда компонента не собрана: проверьте eventHandler",
8
8
  en: "Component command not built: check eventHandler",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "poe-svelte-ui-lib",
3
- "version": "2.11.0",
3
+ "version": "2.13.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/Oleg-Perevyshin/ElementsUI.git"
@@ -1,11 +0,0 @@
1
- export declare const GUI_EXTRAS: {
2
- Joystick: import("svelte").Component<import("..").IJoystickProps, {}, "value">;
3
- VideoViewer: import("svelte").Component<import("..").IVideoViewerProps, {
4
- getDevices: () => Promise<MediaDeviceInfo[]>;
5
- startStream: (devId?: string) => Promise<void>;
6
- stopStream: () => void;
7
- }, "">;
8
- WidgetPFD: import("svelte").Component<import("..").IWidgetPFDProps, {}, "collapsed">;
9
- WidgetMap: import("svelte").Component<import("..").IWidgetMapProps, {}, "collapsed" | "plan" | "route" | "trackEnabled" | "trackLength" | "markerTimeout">;
10
- };
11
- export type GuiExtras = Partial<typeof GUI_EXTRAS>;
@@ -1,6 +0,0 @@
1
- /* src/lib/GUIRenderer/extras.ts - тяжёлые компоненты GUI (карта, пилотажный прибор, видео, джойстик): GUIRenderer получает их через extras, без них они не попадают в сборку приложения */
2
- import Joystick from "../Joystick/Joystick.svelte";
3
- import VideoViewer from "../VideoViewer/VideoViewer.svelte";
4
- import WidgetPFD from "../WidgetPFD/WidgetPFD.svelte";
5
- import WidgetMap from "../WidgetMap/WidgetMap.svelte";
6
- export const GUI_EXTRAS = { Joystick, VideoViewer, WidgetPFD, WidgetMap };