@devicechain/dashboards 1.10.1 → 1.11.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.
@@ -1,6 +1,6 @@
1
1
  import { type Gutter } from './grid';
2
2
  import { type SpanLimits } from './layout-lint';
3
- import type { CanvasDensity, CanvasGrid, CanvasSizing, DashboardDefinition, GridPlacement, Placement, PlacementAnchor, WidgetInstance } from './types';
3
+ import type { CanvasDensity, CanvasPalette, CanvasGrid, CanvasSizing, DashboardDefinition, GridPlacement, Placement, PlacementAnchor, WidgetInstance } from './types';
4
4
  import { type WidgetDescriptor } from './widget-descriptor';
5
5
  export declare function basePlacement(widget: WidgetInstance): Placement;
6
6
  export declare function resolveEverywhere(def: DashboardDefinition, first: readonly string[], aside?: boolean): DashboardDefinition;
@@ -38,6 +38,7 @@ export declare function setTitle(def: DashboardDefinition, title: string): Dashb
38
38
  export declare function setCanvasGrid(def: DashboardDefinition, patch: Partial<CanvasGrid>): DashboardDefinition;
39
39
  export declare function setCanvasSizing(def: DashboardDefinition, sizing: CanvasSizing): DashboardDefinition;
40
40
  export declare function setCanvasDensity(def: DashboardDefinition, density: CanvasDensity): DashboardDefinition;
41
+ export declare function setCanvasPalette(def: DashboardDefinition, palette: CanvasPalette): DashboardDefinition;
41
42
  export declare function updateWidget(def: DashboardDefinition, id: string, next: WidgetInstance): DashboardDefinition;
42
43
  export declare function addWidget(def: DashboardDefinition, descriptor: Pick<WidgetDescriptor, 'id' | 'defaults' | 'version' | 'optionsVersion' | 'sdkApiVersion' | 'layout'>): {
43
44
  definition: DashboardDefinition;
package/dist/index.d.ts CHANGED
@@ -7,8 +7,9 @@ export { BIND_PARAM_PREFIX, parseBindParams, validateBinds, bindsToSelection, se
7
7
  export { migrateToSlots, bindWidgetSlot, clearWidgetDatasource, pruneSlots, widgetBinding, widgetSlotName, sameBinding, resolveConcrete, setSlotScope, setSlotCandidates, anchorSlotNames, type ConcreteSelector, } from './slots';
8
8
  export { resolveSlotCandidates } from './candidates';
9
9
  export { createEntityLister } from './entity-lister';
10
- export { WIDGET_TYPES, UNKNOWN_WIDGET_TYPE, CURRENT_SCHEMA_VERSION, PLACEMENT_ANCHORS, PLACEMENT_MODES, RESERVED_PLACEMENT_MODES, THEME_COLOR_TOKENS, SPACE_TOKEN_PX, FRAME_VARIANTS, FRAME_RADII, FRAME_BORDER_WIDTHS, FRAME_HEADERS, } from './types';
10
+ export { WIDGET_TYPES, UNKNOWN_WIDGET_TYPE, CURRENT_SCHEMA_VERSION, PALETTE_SCHEMA_VERSION, PLACEMENT_ANCHORS, PLACEMENT_MODES, RESERVED_PLACEMENT_MODES, THEME_COLOR_TOKENS, SPACE_TOKEN_PX, FRAME_VARIANTS, FRAME_RADII, FRAME_BORDER_WIDTHS, FRAME_HEADERS, } from './types';
11
11
  export { CANVAS_DENSITIES, DEFAULT_CANVAS_DENSITY, DENSITY_SCALE, isCanvasDensity, type CanvasDensity, } from './types';
12
+ export { CANVAS_PALETTES, DEFAULT_CANVAS_PALETTE, isCanvasPalette, type CanvasPalette, } from './types';
12
13
  export { sameLabel } from './same-label';
13
14
  export { ConnectionTracker, OFFLINE_AFTER_MS, type ConnectionHandle, type HubConnectionState } from './connection';
14
15
  export { DashboardHub, type DashboardHubConfig, type DeviceResolver, type WidgetStreamSink, type WidgetDataSource, type AlarmSubscription, type AlarmSnapshot, type AlarmStreamSink, type CommandSubscription, type CommandSnapshot, type CommandStreamSink, type CommandDispatch, type LocationSubscription, type LocationSnapshot, type LocationStreamSink, type WidgetActions, } from './hub';
@@ -16,7 +17,7 @@ export { SyntheticDataSource, SYNTHETIC_GENERATORS, type SyntheticGenerator, typ
16
17
  export { RECORDING_FORMAT_VERSION, RECORDING_FORMAT_VERSIONS, RECORDING_KIND, RecordingFormatError, parseBoardRecording, recordedWallTimeMs, recordingBounds, simulationScaleAt, type BoardRecording, type RecordedAnchor, type RecordedAlarm, type RecordedAlarmEvent, type RecordedAlarmSnapshot, type RecordedChannels, type RecordedChapter, type RecordedClockSegment, type RecordedDevice, type RecordedLocationColumns, type RecordedMeasurementColumns, } from './recording';
17
18
  export { PLAYBACK_RATES, RECORDED_HISTORY_WINDOW_MS, NotInRecordingError, RecordedClock, RecordedDataSource, createRecordedClock, createRecordedLister, createRecordedResolver, retimeShiftMs, type ClockEvent, type ClockTicker, type PlaybackRate, type RecordedChannel, type RecordedSiteOptions, type RecordedSourceOptions, } from './recorded';
18
19
  export { parseDashboardDefinition, type ParseDefinitionOptions, parseSlotBinding, serializeDefinition, storedDefinition, isDirty, withoutConversionMark, generateWidgetId, canScopeSlot, DashboardDefinitionError, BASE_BREAKPOINT, } from './definition';
19
- export { basePlacement, clampSpan, moveWidget, resizeWidget, setWidgetPlacement, deleteWidget, setTitle, setCanvasGrid, setCanvasSizing, setCanvasDensity, updateWidget, addWidget, canHostRelative, fitToLimits, formatSpan, OFFSET_STEP, OFFSET_STEP_FINE, placeOnGrid, placeRelative, setRelativeAnchor, setRelativeOffset, snapOffset, gridPlacementToPx, pxToGridPlacement, type EditOptions, type PixelRect, type RelativeBounds, type GridGeometry, } from './editor-model';
20
+ export { basePlacement, clampSpan, moveWidget, resizeWidget, setWidgetPlacement, deleteWidget, setTitle, setCanvasGrid, setCanvasSizing, setCanvasDensity, setCanvasPalette, updateWidget, addWidget, canHostRelative, fitToLimits, formatSpan, OFFSET_STEP, OFFSET_STEP_FINE, placeOnGrid, placeRelative, setRelativeAnchor, setRelativeOffset, snapOffset, gridPlacementToPx, pxToGridPlacement, type EditOptions, type PixelRect, type RelativeBounds, type GridGeometry, } from './editor-model';
20
21
  export { DEFAULT_HISTORY_LIMIT, canRedo, canUndo, commitEdit, createEditHistory, rebaseHistory, redoEdit, sealHistory, undoEdit, type CommitOptions, type EditHistory, type HistoryEntry, type Step, } from './editor-history';
21
22
  export { WIDGET_CLIPBOARD_FORMAT, WIDGET_CLIPBOARD_VERSION, copyWidget, duplicateWidget, parseWidgetClipboard, pasteWidgets, serializeWidgetClipboard, type ClipboardOrigin, type PasteResult, type RefusedWidget, type UnboundPaste, type WidgetClipboard, } from './editor-clipboard';
22
23
  export { createDeviceResolver } from './resolver';
package/dist/index.js CHANGED
@@ -138,7 +138,16 @@ var DENSITY_SCALE = {
138
138
  function isCanvasDensity(value) {
139
139
  return typeof value === "string" && CANVAS_DENSITIES.includes(value);
140
140
  }
141
+ var CANVAS_PALETTES = ["standard", "operator"];
142
+ var DEFAULT_CANVAS_PALETTE = "standard";
143
+ function isCanvasPalette(value) {
144
+ return typeof value === "string" && CANVAS_PALETTES.includes(value);
145
+ }
141
146
  var CURRENT_SCHEMA_VERSION = 3;
147
+ var PALETTE_SCHEMA_VERSION = 4;
148
+ function schemaVersionFor(canvas) {
149
+ return canvas.palette !== void 0 && canvas.palette !== DEFAULT_CANVAS_PALETTE ? PALETTE_SCHEMA_VERSION : CURRENT_SCHEMA_VERSION;
150
+ }
142
151
 
143
152
  // src/grid.ts
144
153
  var BASE_BREAKPOINT = "base";
@@ -771,7 +780,7 @@ function numberAt(rec, key, fallback) {
771
780
  function parseDashboardDefinition(input, options = {}) {
772
781
  if (!isRecord(input)) throw new DashboardDefinitionError("not a JSON object");
773
782
  const stored = storedSchemaVersion(input);
774
- if (stored > CURRENT_SCHEMA_VERSION) {
783
+ if (stored > CURRENT_SCHEMA_VERSION && stored !== PALETTE_SCHEMA_VERSION) {
775
784
  throw new DashboardDefinitionError(`schemaVersion ${stored} is too new`, "schemaTooNew", stored);
776
785
  }
777
786
  if (!Array.isArray(input.widgets)) throw new DashboardDefinitionError("widgets must be an array");
@@ -786,11 +795,13 @@ function parseDashboardDefinition(input, options = {}) {
786
795
  flaggedWindows = converted.flagged;
787
796
  }
788
797
  const widgetsRaw = raw.widgets;
798
+ const canvas = parseCanvas(raw.canvas);
789
799
  const def = {
790
- // The format this release writes (a newer one was refused above): a save writes that format.
791
- schemaVersion: CURRENT_SCHEMA_VERSION,
800
+ // The format this release writes for this board (a newer one was refused above): the palette
801
+ // format when it carries a palette, the current one otherwise. A save writes that format.
802
+ schemaVersion: schemaVersionFor(canvas),
792
803
  title: typeof raw.title === "string" ? raw.title : "",
793
- canvas: parseCanvas(raw.canvas),
804
+ canvas,
794
805
  widgets: widgetsRaw.map((w, i) => parseWidget(w, i, options.catalog))
795
806
  };
796
807
  const slots = parseSlots(raw.slots);
@@ -1038,6 +1049,7 @@ function parseCanvas(raw) {
1038
1049
  const frame = parseFrame(rec.frame, "canvas.frame");
1039
1050
  if (frame) canvas.frame = frame;
1040
1051
  if (isCanvasDensity(rec.density)) canvas.density = rec.density;
1052
+ if (isCanvasPalette(rec.palette)) canvas.palette = rec.palette;
1041
1053
  if (isRecord(rec.background)) {
1042
1054
  const { color, imageUrl } = rec.background;
1043
1055
  canvas.background = {
@@ -1262,7 +1274,11 @@ function isFiniteNumber(v) {
1262
1274
  return typeof v === "number" && Number.isFinite(v);
1263
1275
  }
1264
1276
  function storedDefinition(def) {
1265
- const unmarked = withoutConversionMark(def);
1277
+ let unmarked = withoutConversionMark(def);
1278
+ const version = schemaVersionFor(unmarked.canvas);
1279
+ if (unmarked.schemaVersion !== version && (version === PALETTE_SCHEMA_VERSION || unmarked.schemaVersion === PALETTE_SCHEMA_VERSION)) {
1280
+ unmarked = { ...unmarked, schemaVersion: version };
1281
+ }
1266
1282
  if (!unmarked.widgets.some((w) => w.type === UNKNOWN_WIDGET_TYPE)) return unmarked;
1267
1283
  return {
1268
1284
  ...unmarked,
@@ -5053,6 +5069,11 @@ function setCanvasDensity(def, density) {
5053
5069
  const { density: _prev, ...rest } = def.canvas;
5054
5070
  return { ...def, canvas: density === DEFAULT_CANVAS_DENSITY ? rest : { ...rest, density } };
5055
5071
  }
5072
+ function setCanvasPalette(def, palette) {
5073
+ const { palette: _prev, ...rest } = def.canvas;
5074
+ const canvas = palette === DEFAULT_CANVAS_PALETTE ? rest : { ...rest, palette };
5075
+ return { ...def, schemaVersion: schemaVersionFor(canvas), canvas };
5076
+ }
5056
5077
  function updateWidget(def, id, next) {
5057
5078
  return { ...def, widgets: def.widgets.map((w) => w.id === id ? next : w) };
5058
5079
  }
@@ -6455,10 +6476,12 @@ export {
6455
6476
  BASE_BREAKPOINT,
6456
6477
  BIND_PARAM_PREFIX,
6457
6478
  CANVAS_DENSITIES,
6479
+ CANVAS_PALETTES,
6458
6480
  COMMAND_STATUSES,
6459
6481
  CURRENT_SCHEMA_VERSION,
6460
6482
  ConnectionTracker,
6461
6483
  DEFAULT_CANVAS_DENSITY,
6484
+ DEFAULT_CANVAS_PALETTE,
6462
6485
  DEFAULT_GRID,
6463
6486
  DEFAULT_HISTORY_LIMIT,
6464
6487
  DEFAULT_TIME_RANGE_SECONDS,
@@ -6482,6 +6505,7 @@ export {
6482
6505
  OFFLINE_AFTER_MS,
6483
6506
  OFFSET_STEP,
6484
6507
  OFFSET_STEP_FINE,
6508
+ PALETTE_SCHEMA_VERSION,
6485
6509
  PHONE_MIN_COLUMNS,
6486
6510
  PLACEMENT_ANCHORS,
6487
6511
  PLACEMENT_MODES,
@@ -6573,6 +6597,7 @@ export {
6573
6597
  isBuiltinWidgetId,
6574
6598
  isCancellableCommandStatus,
6575
6599
  isCanvasDensity,
6600
+ isCanvasPalette,
6576
6601
  isDirty,
6577
6602
  isNamespacedWidgetId,
6578
6603
  isResolvedWidget,
@@ -6638,6 +6663,7 @@ export {
6638
6663
  setBoardTimeRange,
6639
6664
  setCanvasDensity,
6640
6665
  setCanvasGrid,
6666
+ setCanvasPalette,
6641
6667
  setCanvasSizing,
6642
6668
  setRelativeAnchor,
6643
6669
  setRelativeOffset,