@oicl/openbridge-webcomponents-full-bundle 2.2.0-next.16 → 2.2.0-next.17
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/bundle/openbridge-webcomponents.bundle.js +173 -20
- package/bundle/openbridge-webcomponents.bundle.js.map +1 -1
- package/custom-elements.json +1713 -14
- package/dist/automation/analog-threeway-valve/analog-threeway-valve.d.ts +4 -4
- package/dist/automation/analog-threeway-valve/analog-threeway-valve.js.map +1 -1
- package/dist/automation/automation-button/abstract-automation-button-storybook-helpers.d.ts +20 -0
- package/dist/automation/automation-button/abstract-automation-button-storybook-helpers.d.ts.map +1 -1
- package/dist/automation/automation-button/abstract-automation-button-storybook-helpers.js +1 -0
- package/dist/automation/automation-button/abstract-automation-button-storybook-helpers.js.map +1 -1
- package/dist/automation/automation-button/abstract-automation-button.d.ts +11 -2
- package/dist/automation/automation-button/abstract-automation-button.d.ts.map +1 -1
- package/dist/automation/automation-button/abstract-automation-button.js +40 -20
- package/dist/automation/automation-button/abstract-automation-button.js.map +1 -1
- package/dist/automation/automation-button/badge-layout.d.ts +34 -0
- package/dist/automation/automation-button/badge-layout.d.ts.map +1 -0
- package/dist/automation/automation-button/badge-layout.js +64 -0
- package/dist/automation/automation-button/badge-layout.js.map +1 -0
- package/dist/automation/digital-threeway-valve/digital-threeway-valve.d.ts +4 -4
- package/dist/automation/digital-threeway-valve/digital-threeway-valve.js.map +1 -1
- package/dist/automation/electricity-battery/electricity-battery.d.ts +4 -4
- package/dist/automation/electricity-battery/electricity-battery.js.map +1 -1
- package/dist/internal/global-setting.d.ts +55 -0
- package/dist/internal/global-setting.d.ts.map +1 -0
- package/dist/internal/global-setting.js +86 -0
- package/dist/internal/global-setting.js.map +1 -0
- package/package.json +1 -1
- package/src/automation/analog-threeway-valve/analog-threeway-valve.ts +4 -4
- package/src/automation/automation-button/abstract-automation-button-storybook-helpers.ts +3 -0
- package/src/automation/automation-button/abstract-automation-button.ts +57 -23
- package/src/automation/automation-button/badge-layout.spec.ts +138 -0
- package/src/automation/automation-button/badge-layout.ts +120 -0
- package/src/automation/digital-threeway-valve/digital-threeway-valve.ts +4 -4
- package/src/automation/electricity-battery/electricity-battery.ts +4 -4
- package/src/automation/pump/pump.stories.ts +59 -0
- package/src/internal/global-setting.spec.ts +119 -0
- package/src/internal/global-setting.ts +105 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"digital-threeway-valve.js","names":["_decorate"],"sources":["../../../src/automation/digital-threeway-valve/digital-threeway-valve.ts"],"sourcesContent":["import {html} from 'lit';\nimport {property} from 'lit/decorators.js';\nimport '../../icons/icon-threeway-digital-open.js';\nimport '../../icons/icon-threeway-digital-closed.js';\nimport '../../icons/icon-threeway-digital-closed-left.js';\nimport '../../icons/icon-threeway-digital-closed-bottom.js';\nimport '../../icons/icon-threeway-digital-closed-right.js';\nimport {customElement} from '../../decorator.js';\nimport {ObcAbstractAutomationButton} from '../automation-button/abstract-automation-button.js';\nimport {AutomationButtonReadoutPosition} from '../automation-button/automation-button.js';\nimport {AutomationButtonReadoutStack} from '../../components/automation-button-readout-stack/automation-button-readout-stack.js';\nimport {\n ThreewayValveFlow,\n ThreewayValveOrientation,\n threewayValveOpenSide,\n threewayValveReadouts,\n threewayValveRotation,\n} from '../threeway-valve-shared/threeway-valve-shared.js';\n\nexport enum DigitalThreewayValveVariant {\n regular = 'regular',\n flat = 'flat',\n}\n\n/**\n * `<obc-digital-threeway-valve>` – three-way on/off valve for process\n * diagrams, with one open/closed state per port.\n *\n * ## Features\n *\n * - **Three ports:** `open1`, `open2` and `open3` open or close each port.\n * Ports are numbered from the side without a port: with `orientation`\n * `bottom`, port 1 is left, port 2 is the stem at the bottom and port 3 is\n * right. The numbering turns with the symbol.\n * - **Orientation:** `bottom` and `top` lay the valve on a horizontal pipe,\n * `left` and `right` on a vertical one; the value names the side the stem\n * points to.\n * - **Flow readout:** `flows` lists one readout row per flow, each with an\n * optional arrow direction and either a value with a unit (`%` when left out)\n * or a state, `{open}`, shown as `Open` or `Closed` after the arrow, or\n * after the on/off icon when there is no direction. Without flows the\n * readout shows `Open` or `Closed`.\n * - Badges, alert frame, progress and readout placement come from the shared\n * automation button base.\n *\n * ## Usage Guidelines\n *\n * Use where a valve directs flow between three pipes and each port is either\n * open or closed. With one port closed the symbol shows that port plugged;\n * with fewer than two ports open no flow can pass, and the valve shows as\n * closed. For a valve that opens its ports continuously use\n * `obc-analog-threeway-valve`; for a two-port valve use `obc-digital-valve`.\n *\n * TODO(designer): no icon shows a single open port, so that case uses the\n * closed symbol.\n *\n * @property open1 - Opens port 1.\n * @property open2 - Opens port 2, the stem.\n * @property open3 - Opens port 3.\n * @property orientation - Side the stem points to.\n * @property flows - Readout rows, one per flow: an optional arrow direction with either a value and optional unit (default `%`) or `open` for an `Open`/`Closed` state.\n * @property variant - Visual style of the button surround.\n * @slot badge-top-right - Content projected into the top-right badge position; overrides `
|
|
1
|
+
{"version":3,"file":"digital-threeway-valve.js","names":["_decorate"],"sources":["../../../src/automation/digital-threeway-valve/digital-threeway-valve.ts"],"sourcesContent":["import {html} from 'lit';\nimport {property} from 'lit/decorators.js';\nimport '../../icons/icon-threeway-digital-open.js';\nimport '../../icons/icon-threeway-digital-closed.js';\nimport '../../icons/icon-threeway-digital-closed-left.js';\nimport '../../icons/icon-threeway-digital-closed-bottom.js';\nimport '../../icons/icon-threeway-digital-closed-right.js';\nimport {customElement} from '../../decorator.js';\nimport {ObcAbstractAutomationButton} from '../automation-button/abstract-automation-button.js';\nimport {AutomationButtonReadoutPosition} from '../automation-button/automation-button.js';\nimport {AutomationButtonReadoutStack} from '../../components/automation-button-readout-stack/automation-button-readout-stack.js';\nimport {\n ThreewayValveFlow,\n ThreewayValveOrientation,\n threewayValveOpenSide,\n threewayValveReadouts,\n threewayValveRotation,\n} from '../threeway-valve-shared/threeway-valve-shared.js';\n\nexport enum DigitalThreewayValveVariant {\n regular = 'regular',\n flat = 'flat',\n}\n\n/**\n * `<obc-digital-threeway-valve>` – three-way on/off valve for process\n * diagrams, with one open/closed state per port.\n *\n * ## Features\n *\n * - **Three ports:** `open1`, `open2` and `open3` open or close each port.\n * Ports are numbered from the side without a port: with `orientation`\n * `bottom`, port 1 is left, port 2 is the stem at the bottom and port 3 is\n * right. The numbering turns with the symbol.\n * - **Orientation:** `bottom` and `top` lay the valve on a horizontal pipe,\n * `left` and `right` on a vertical one; the value names the side the stem\n * points to.\n * - **Flow readout:** `flows` lists one readout row per flow, each with an\n * optional arrow direction and either a value with a unit (`%` when left out)\n * or a state, `{open}`, shown as `Open` or `Closed` after the arrow, or\n * after the on/off icon when there is no direction. Without flows the\n * readout shows `Open` or `Closed`.\n * - Badges, alert frame, progress and readout placement come from the shared\n * automation button base.\n *\n * ## Usage Guidelines\n *\n * Use where a valve directs flow between three pipes and each port is either\n * open or closed. With one port closed the symbol shows that port plugged;\n * with fewer than two ports open no flow can pass, and the valve shows as\n * closed. For a valve that opens its ports continuously use\n * `obc-analog-threeway-valve`; for a two-port valve use `obc-digital-valve`.\n *\n * TODO(designer): no icon shows a single open port, so that case uses the\n * closed symbol.\n *\n * @property open1 - Opens port 1.\n * @property open2 - Opens port 2, the stem.\n * @property open3 - Opens port 3.\n * @property orientation - Side the stem points to.\n * @property flows - Readout rows, one per flow: an optional arrow direction with either a value and optional unit (default `%`) or `open` for an `Open`/`Closed` state.\n * @property variant - Visual style of the button surround.\n * @slot badge-top-right - Content projected into the top-right badge position; overrides the badge `badgeLayout` puts in that corner.\n * @slot badge-top-left - Content projected into the top-left badge position; overrides the badge `badgeLayout` puts in that corner.\n * @slot badge-bottom-left - Content projected into the bottom-left badge position; overrides the badge `badgeLayout` puts in that corner.\n * @slot badge-bottom-right - Content projected into the bottom-right badge position; overrides the badge `badgeLayout` puts in that corner.\n * @fires click - Fired when the valve is clicked.\n * @experimental\n */\n@customElement('obc-digital-threeway-valve')\nexport class ObcDigitalThreewayValve extends ObcAbstractAutomationButton {\n @property({type: Boolean}) open1: boolean = false;\n @property({type: Boolean}) open2: boolean = false;\n @property({type: Boolean}) open3: boolean = false;\n @property({type: String}) orientation: ThreewayValveOrientation =\n ThreewayValveOrientation.bottom;\n @property({type: Array, attribute: false}) flows: ThreewayValveFlow[] = [];\n @property({type: String}) variant: DigitalThreewayValveVariant =\n DigitalThreewayValveVariant.regular;\n\n private get ports(): boolean[] {\n return [this.open1, this.open2, this.open3];\n }\n\n override get _on(): boolean {\n return this.ports.filter(Boolean).length >= 2;\n }\n\n override get _readoutPosition(): AutomationButtonReadoutPosition {\n return this.readoutPosition ?? threewayValveOpenSide(this.orientation);\n }\n\n override get extraReadouts(): AutomationButtonReadoutStack[] {\n if (!this.showStatus) {\n return [];\n }\n return threewayValveReadouts(this._on, this.flows, this.showStatusIcon);\n }\n\n private renderIcon(slot: string) {\n const style = `display: block; transform: rotate(${threewayValveRotation(\n this.orientation\n )}deg); line-height: 0;`;\n const ports = this.ports;\n if (!this._on) {\n return html`<obi-threeway-digital-closed\n usecsscolor\n slot=${slot}\n style=${style}\n ></obi-threeway-digital-closed>`;\n }\n switch (ports.indexOf(false)) {\n case 0:\n return html`<obi-threeway-digital-closed-left\n usecsscolor\n slot=${slot}\n style=${style}\n ></obi-threeway-digital-closed-left>`;\n case 1:\n return html`<obi-threeway-digital-closed-bottom\n usecsscolor\n slot=${slot}\n style=${style}\n ></obi-threeway-digital-closed-bottom>`;\n case 2:\n return html`<obi-threeway-digital-closed-right\n usecsscolor\n slot=${slot}\n style=${style}\n ></obi-threeway-digital-closed-right>`;\n default:\n return html`<obi-threeway-digital-open\n usecsscolor\n slot=${slot}\n style=${style}\n ></obi-threeway-digital-open>`;\n }\n }\n\n override get icon() {\n return html`${this.renderIcon('icon')}${this.renderIcon('icon-silhouette')}`;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'obc-digital-threeway-valve': ObcDigitalThreewayValve;\n }\n}\n"],"mappings":";;;;;;;;;;;;AAmBA,IAAY,8BAAL,yBAAA,6BAAA;CACL,4BAAA,aAAA;CACA,4BAAA,UAAA;;AACF,EAAA,CAAA,CAAA;AAgDO,IAAM,0BAAN,MAAM,gCAAgC,4BAA4B;;;EAC3B,KAAA,QAAA;EACA,KAAA,QAAA;EACA,KAAA,QAAA;EAE1C,KAAA,cAAA,yBAAyB;EAC6C,KAAA,QAAA,CAAC;;;CAIzE,IAAY,QAAmB;EAC7B,OAAO;GAAC,KAAK;GAAO,KAAK;GAAO,KAAK;EAAK;CAC5C;CAEA,IAAa,MAAe;EAC1B,OAAO,KAAK,MAAM,OAAO,OAAO,CAAC,CAAC,UAAU;CAC9C;CAEA,IAAa,mBAAoD;EAC/D,OAAO,KAAK,mBAAmB,sBAAsB,KAAK,WAAW;CACvE;CAEA,IAAa,gBAAgD;EAC3D,IAAI,CAAC,KAAK,YACR,OAAO,CAAC;EAEV,OAAO,sBAAsB,KAAK,KAAK,KAAK,OAAO,KAAK,cAAc;CACxE;CAEA,WAAmB,MAAc;EAC/B,MAAM,QAAQ,qCAAqC,sBACjD,KAAK,WACP,EAAE;EACF,MAAM,QAAQ,KAAK;EACnB,IAAI,CAAC,KAAK,KACR,OAAO,IAAI;;eAEF,KAAK;gBACJ,MAAM;;EAGlB,QAAQ,MAAM,QAAQ,KAAK,GAA3B;GACE,KAAK,GACH,OAAO,IAAI;;iBAEF,KAAK;kBACJ,MAAM;;GAElB,KAAK,GACH,OAAO,IAAI;;iBAEF,KAAK;kBACJ,MAAM;;GAElB,KAAK,GACH,OAAO,IAAI;;iBAEF,KAAK;kBACJ,MAAM;;GAElB,SACE,OAAO,IAAI;;iBAEF,KAAK;kBACJ,MAAM;;EAEpB;CACF;CAEA,IAAa,OAAO;EAClB,OAAO,IAAI,GAAG,KAAK,WAAW,MAAM,IAAI,KAAK,WAAW,iBAAiB;CAC3E;AACF;AAvEGA,WAAA,CAAA,SAAS,EAAC,MAAM,QAAO,CAAC,CAAA,GAAA,wBAAA,WAAA,SAAA,KAAA,CAAA;AACxBA,WAAA,CAAA,SAAS,EAAC,MAAM,QAAO,CAAC,CAAA,GAAA,wBAAA,WAAA,SAAA,KAAA,CAAA;AACxBA,WAAA,CAAA,SAAS,EAAC,MAAM,QAAO,CAAC,CAAA,GAAA,wBAAA,WAAA,SAAA,KAAA,CAAA;AACxBA,WAAA,CAAA,SAAS,EAAC,MAAM,OAAM,CAAC,CAAA,GAAA,wBAAA,WAAA,eAAA,KAAA,CAAA;AAEvBA,WAAA,CAAA,SAAS;CAAC,MAAM;CAAO,WAAW;AAAK,CAAC,CAAA,GAAA,wBAAA,WAAA,SAAA,KAAA,CAAA;AACxCA,WAAA,CAAA,SAAS,EAAC,MAAM,OAAM,CAAC,CAAA,GAAA,wBAAA,WAAA,WAAA,KAAA,CAAA;AARzB,0BAAAA,WAAA,CAAA,cAAc,4BAA4B,CAAA,GAAA,uBAAA"}
|
|
@@ -19,10 +19,10 @@ import '../../icons/icon-electricity-battery-off.js';
|
|
|
19
19
|
* Without a visible tag the button is named `Battery`, followed by the state
|
|
20
20
|
* (`Battery On`) when the state row is shown.
|
|
21
21
|
*
|
|
22
|
-
* @slot badge-top-right - Content projected into the top-right badge position; overrides `
|
|
23
|
-
* @slot badge-top-left - Content projected into the top-left badge position; overrides `
|
|
24
|
-
* @slot badge-bottom-left - Content projected into the bottom-left badge position; overrides `
|
|
25
|
-
* @slot badge-bottom-right - Content projected into the bottom-right badge position; overrides `
|
|
22
|
+
* @slot badge-top-right - Content projected into the top-right badge position; overrides the badge `badgeLayout` puts in that corner.
|
|
23
|
+
* @slot badge-top-left - Content projected into the top-left badge position; overrides the badge `badgeLayout` puts in that corner.
|
|
24
|
+
* @slot badge-bottom-left - Content projected into the bottom-left badge position; overrides the badge `badgeLayout` puts in that corner.
|
|
25
|
+
* @slot badge-bottom-right - Content projected into the bottom-right badge position; overrides the badge `badgeLayout` puts in that corner.
|
|
26
26
|
* @fires click - Fired when the battery is clicked.
|
|
27
27
|
* @experimental
|
|
28
28
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"electricity-battery.js","names":["_decorate"],"sources":["../../../src/automation/electricity-battery/electricity-battery.ts"],"sourcesContent":["import '../../icons/icon-electricity-battery-on.js';\nimport '../../icons/icon-electricity-battery-off.js';\nimport {customElement} from '../../decorator.js';\nimport {ObcAbstractAutomationButtonSquared} from '../automation-button/abstract-automation-button-squared.js';\n\n/**\n * `<obc-electricity-battery>` – Battery symbol for electrical automation diagrams.\n *\n * Shows the battery as an on/off device with the readout stack, badges and\n * alert frame of the other two-state devices.\n *\n * ## Usage Guidelines\n *\n * Use it to place a battery on an electrical one-line diagram. For a battery's\n * charge level, use `obc-indicator-battery`; for a battery tank with a fill\n * level, use `obc-automation-tank`.\n *\n * **TODO(designer):** the icons file has no static battery symbol, so a\n * `static` battery keeps its on or off icon.\n *\n * Without a visible tag the button is named `Battery`, followed by the state\n * (`Battery On`) when the state row is shown.\n *\n * @slot badge-top-right - Content projected into the top-right badge position; overrides `
|
|
1
|
+
{"version":3,"file":"electricity-battery.js","names":["_decorate"],"sources":["../../../src/automation/electricity-battery/electricity-battery.ts"],"sourcesContent":["import '../../icons/icon-electricity-battery-on.js';\nimport '../../icons/icon-electricity-battery-off.js';\nimport {customElement} from '../../decorator.js';\nimport {ObcAbstractAutomationButtonSquared} from '../automation-button/abstract-automation-button-squared.js';\n\n/**\n * `<obc-electricity-battery>` – Battery symbol for electrical automation diagrams.\n *\n * Shows the battery as an on/off device with the readout stack, badges and\n * alert frame of the other two-state devices.\n *\n * ## Usage Guidelines\n *\n * Use it to place a battery on an electrical one-line diagram. For a battery's\n * charge level, use `obc-indicator-battery`; for a battery tank with a fill\n * level, use `obc-automation-tank`.\n *\n * **TODO(designer):** the icons file has no static battery symbol, so a\n * `static` battery keeps its on or off icon.\n *\n * Without a visible tag the button is named `Battery`, followed by the state\n * (`Battery On`) when the state row is shown.\n *\n * @slot badge-top-right - Content projected into the top-right badge position; overrides the badge `badgeLayout` puts in that corner.\n * @slot badge-top-left - Content projected into the top-left badge position; overrides the badge `badgeLayout` puts in that corner.\n * @slot badge-bottom-left - Content projected into the bottom-left badge position; overrides the badge `badgeLayout` puts in that corner.\n * @slot badge-bottom-right - Content projected into the bottom-right badge position; overrides the badge `badgeLayout` puts in that corner.\n * @fires click - Fired when the battery is clicked.\n * @experimental\n */\n@customElement('obc-electricity-battery')\nexport class ObcElectricityBattery extends ObcAbstractAutomationButtonSquared {\n override get _accessibleName(): string | null {\n if (!this.showReadoutStack) return 'Battery';\n if (this.tag) return null;\n return this.showStatus\n ? `Battery ${this.turnedOn ? 'On' : 'Off'}`\n : 'Battery';\n }\n\n override get icon() {\n return this.renderDeviceIcon({\n on: 'electricity-battery-on',\n off: 'electricity-battery-off',\n });\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'obc-electricity-battery': ObcElectricityBattery;\n }\n}\n"],"mappings":";;;;;;AA+BO,IAAM,wBAAN,MAAM,8BAA8B,mCAAmC;CAC5E,IAAa,kBAAiC;EAC5C,IAAI,CAAC,KAAK,kBAAkB,OAAO;EACnC,IAAI,KAAK,KAAK,OAAO;EACrB,OAAO,KAAK,aACR,WAAW,KAAK,WAAW,OAAO,UAClC;CACN;CAEA,IAAa,OAAO;EAClB,OAAO,KAAK,iBAAiB;GAC3B,IAAI;GACJ,KAAK;EACP,CAAC;CACH;AACF;AAhBC,wBAAAA,WAAA,CAAA,cAAc,yBAAyB,CAAA,GAAA,qBAAA"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { ReactiveController, ReactiveControllerHost } from 'lit';
|
|
2
|
+
/**
|
|
3
|
+
* One app-wide setting the components render from.
|
|
4
|
+
*
|
|
5
|
+
* The application sets it once through a module setter such as
|
|
6
|
+
* `setAutomationBadgeLayout()` or `setAlertStandard()`. Every connected host
|
|
7
|
+
* that holds a controller for it re-renders on each change; a host detached
|
|
8
|
+
* while the value changed catches up on its next connect, and one reattached
|
|
9
|
+
* unchanged renders nothing extra. Setting the same value again is a no-op.
|
|
10
|
+
*
|
|
11
|
+
* It is a plain subscriber set rather than a signal: the value rarely changes
|
|
12
|
+
* and derives nothing, and the library stays off a pre-standard polyfill. A
|
|
13
|
+
* setter built on it can move to a signal later without changing its signature.
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* const alertStandard = new GlobalSetting<AlertStandard | undefined>(undefined);
|
|
17
|
+
* export const setAlertStandard = (s?: AlertStandard) => alertStandard.set(s);
|
|
18
|
+
*
|
|
19
|
+
* class ObcAlertIcon extends LitElement {
|
|
20
|
+
* private readonly standard = alertStandard.controller(this);
|
|
21
|
+
* render() { return draw(this.standard.value); }
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare class GlobalSetting<T> {
|
|
26
|
+
private value;
|
|
27
|
+
private currentVersion;
|
|
28
|
+
private readonly hosts;
|
|
29
|
+
constructor(value: T);
|
|
30
|
+
get(): T;
|
|
31
|
+
/** Stores the value and re-renders every connected host. */
|
|
32
|
+
set(value: T): void;
|
|
33
|
+
/** Re-renders `host` whenever the value changes; create it once, in the host's constructor. */
|
|
34
|
+
controller(host: ReactiveControllerHost): GlobalSettingController<T>;
|
|
35
|
+
/** Counts the changes, so a controller can tell whether its host rendered the current value. */
|
|
36
|
+
get version(): number;
|
|
37
|
+
attach(host: ReactiveControllerHost): void;
|
|
38
|
+
detach(host: ReactiveControllerHost): void;
|
|
39
|
+
}
|
|
40
|
+
/** Keeps one host rendered with the current value of a `GlobalSetting`. */
|
|
41
|
+
export declare class GlobalSettingController<T> implements ReactiveController {
|
|
42
|
+
private readonly host;
|
|
43
|
+
private readonly setting;
|
|
44
|
+
private renderedVersion;
|
|
45
|
+
private renderingVersion;
|
|
46
|
+
constructor(host: ReactiveControllerHost, setting: GlobalSetting<T>);
|
|
47
|
+
get value(): T;
|
|
48
|
+
/** A value set while the host was detached never reached it. */
|
|
49
|
+
hostConnected(): void;
|
|
50
|
+
hostDisconnected(): void;
|
|
51
|
+
/** The version a render starts from; a change while it runs detached must not count as rendered. */
|
|
52
|
+
hostUpdate(): void;
|
|
53
|
+
hostUpdated(): void;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=global-setting.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global-setting.d.ts","sourceRoot":"","sources":["../../src/internal/global-setting.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,kBAAkB,EAAE,sBAAsB,EAAC,MAAM,KAAK,CAAC;AAEpE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,aAAa,CAAC,CAAC;IAId,OAAO,CAAC,KAAK;IAHzB,OAAO,CAAC,cAAc,CAAK;IAC3B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAqC;gBAEvC,KAAK,EAAE,CAAC;IAE5B,GAAG,IAAI,CAAC;IAIR,4DAA4D;IAC5D,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI;IAWnB,+FAA+F;IAC/F,UAAU,CAAC,IAAI,EAAE,sBAAsB,GAAG,uBAAuB,CAAC,CAAC,CAAC;IAIpE,gGAAgG;IAChG,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED,MAAM,CAAC,IAAI,EAAE,sBAAsB,GAAG,IAAI;IAI1C,MAAM,CAAC,IAAI,EAAE,sBAAsB,GAAG,IAAI;CAG3C;AAED,2EAA2E;AAC3E,qBAAa,uBAAuB,CAAC,CAAC,CAAE,YAAW,kBAAkB;IAKjE,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAL1B,OAAO,CAAC,eAAe,CAAS;IAChC,OAAO,CAAC,gBAAgB,CAAS;gBAGd,IAAI,EAAE,sBAAsB,EAC5B,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC;IAO5C,IAAI,KAAK,IAAI,CAAC,CAEb;IAED,gEAAgE;IAChE,aAAa,IAAI,IAAI;IAOrB,gBAAgB,IAAI,IAAI;IAIxB,oGAAoG;IACpG,UAAU,IAAI,IAAI;IAIlB,WAAW,IAAI,IAAI;CAGpB"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// src/internal/global-setting.ts
|
|
2
|
+
/**
|
|
3
|
+
* One app-wide setting the components render from.
|
|
4
|
+
*
|
|
5
|
+
* The application sets it once through a module setter such as
|
|
6
|
+
* `setAutomationBadgeLayout()` or `setAlertStandard()`. Every connected host
|
|
7
|
+
* that holds a controller for it re-renders on each change; a host detached
|
|
8
|
+
* while the value changed catches up on its next connect, and one reattached
|
|
9
|
+
* unchanged renders nothing extra. Setting the same value again is a no-op.
|
|
10
|
+
*
|
|
11
|
+
* It is a plain subscriber set rather than a signal: the value rarely changes
|
|
12
|
+
* and derives nothing, and the library stays off a pre-standard polyfill. A
|
|
13
|
+
* setter built on it can move to a signal later without changing its signature.
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* const alertStandard = new GlobalSetting<AlertStandard | undefined>(undefined);
|
|
17
|
+
* export const setAlertStandard = (s?: AlertStandard) => alertStandard.set(s);
|
|
18
|
+
*
|
|
19
|
+
* class ObcAlertIcon extends LitElement {
|
|
20
|
+
* private readonly standard = alertStandard.controller(this);
|
|
21
|
+
* render() { return draw(this.standard.value); }
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
var GlobalSetting = class {
|
|
26
|
+
constructor(value) {
|
|
27
|
+
this.value = value;
|
|
28
|
+
this.currentVersion = 0;
|
|
29
|
+
this.hosts = /* @__PURE__ */ new Set();
|
|
30
|
+
}
|
|
31
|
+
get() {
|
|
32
|
+
return this.value;
|
|
33
|
+
}
|
|
34
|
+
/** Stores the value and re-renders every connected host. */
|
|
35
|
+
set(value) {
|
|
36
|
+
if (Object.is(value, this.value)) return;
|
|
37
|
+
this.value = value;
|
|
38
|
+
this.currentVersion++;
|
|
39
|
+
for (const host of this.hosts) host.requestUpdate();
|
|
40
|
+
}
|
|
41
|
+
/** Re-renders `host` whenever the value changes; create it once, in the host's constructor. */
|
|
42
|
+
controller(host) {
|
|
43
|
+
return new GlobalSettingController(host, this);
|
|
44
|
+
}
|
|
45
|
+
/** Counts the changes, so a controller can tell whether its host rendered the current value. */
|
|
46
|
+
get version() {
|
|
47
|
+
return this.currentVersion;
|
|
48
|
+
}
|
|
49
|
+
attach(host) {
|
|
50
|
+
this.hosts.add(host);
|
|
51
|
+
}
|
|
52
|
+
detach(host) {
|
|
53
|
+
this.hosts.delete(host);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
/** Keeps one host rendered with the current value of a `GlobalSetting`. */
|
|
57
|
+
var GlobalSettingController = class {
|
|
58
|
+
constructor(host, setting) {
|
|
59
|
+
this.host = host;
|
|
60
|
+
this.setting = setting;
|
|
61
|
+
this.renderedVersion = setting.version;
|
|
62
|
+
this.renderingVersion = setting.version;
|
|
63
|
+
host.addController(this);
|
|
64
|
+
}
|
|
65
|
+
get value() {
|
|
66
|
+
return this.setting.get();
|
|
67
|
+
}
|
|
68
|
+
/** A value set while the host was detached never reached it. */
|
|
69
|
+
hostConnected() {
|
|
70
|
+
this.setting.attach(this.host);
|
|
71
|
+
if (this.renderedVersion !== this.setting.version) this.host.requestUpdate();
|
|
72
|
+
}
|
|
73
|
+
hostDisconnected() {
|
|
74
|
+
this.setting.detach(this.host);
|
|
75
|
+
}
|
|
76
|
+
/** The version a render starts from; a change while it runs detached must not count as rendered. */
|
|
77
|
+
hostUpdate() {
|
|
78
|
+
this.renderingVersion = this.setting.version;
|
|
79
|
+
}
|
|
80
|
+
hostUpdated() {
|
|
81
|
+
this.renderedVersion = this.renderingVersion;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
export { GlobalSetting, GlobalSettingController };
|
|
85
|
+
|
|
86
|
+
//# sourceMappingURL=global-setting.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global-setting.js","names":[],"sources":["../../src/internal/global-setting.ts"],"sourcesContent":["import type {ReactiveController, ReactiveControllerHost} from 'lit';\n\n/**\n * One app-wide setting the components render from.\n *\n * The application sets it once through a module setter such as\n * `setAutomationBadgeLayout()` or `setAlertStandard()`. Every connected host\n * that holds a controller for it re-renders on each change; a host detached\n * while the value changed catches up on its next connect, and one reattached\n * unchanged renders nothing extra. Setting the same value again is a no-op.\n *\n * It is a plain subscriber set rather than a signal: the value rarely changes\n * and derives nothing, and the library stays off a pre-standard polyfill. A\n * setter built on it can move to a signal later without changing its signature.\n *\n * ```ts\n * const alertStandard = new GlobalSetting<AlertStandard | undefined>(undefined);\n * export const setAlertStandard = (s?: AlertStandard) => alertStandard.set(s);\n *\n * class ObcAlertIcon extends LitElement {\n * private readonly standard = alertStandard.controller(this);\n * render() { return draw(this.standard.value); }\n * }\n * ```\n */\nexport class GlobalSetting<T> {\n private currentVersion = 0;\n private readonly hosts = new Set<ReactiveControllerHost>();\n\n constructor(private value: T) {}\n\n get(): T {\n return this.value;\n }\n\n /** Stores the value and re-renders every connected host. */\n set(value: T): void {\n if (Object.is(value, this.value)) {\n return;\n }\n this.value = value;\n this.currentVersion++;\n for (const host of this.hosts) {\n host.requestUpdate();\n }\n }\n\n /** Re-renders `host` whenever the value changes; create it once, in the host's constructor. */\n controller(host: ReactiveControllerHost): GlobalSettingController<T> {\n return new GlobalSettingController(host, this);\n }\n\n /** Counts the changes, so a controller can tell whether its host rendered the current value. */\n get version(): number {\n return this.currentVersion;\n }\n\n attach(host: ReactiveControllerHost): void {\n this.hosts.add(host);\n }\n\n detach(host: ReactiveControllerHost): void {\n this.hosts.delete(host);\n }\n}\n\n/** Keeps one host rendered with the current value of a `GlobalSetting`. */\nexport class GlobalSettingController<T> implements ReactiveController {\n private renderedVersion: number;\n private renderingVersion: number;\n\n constructor(\n private readonly host: ReactiveControllerHost,\n private readonly setting: GlobalSetting<T>\n ) {\n this.renderedVersion = setting.version;\n this.renderingVersion = setting.version;\n host.addController(this);\n }\n\n get value(): T {\n return this.setting.get();\n }\n\n /** A value set while the host was detached never reached it. */\n hostConnected(): void {\n this.setting.attach(this.host);\n if (this.renderedVersion !== this.setting.version) {\n this.host.requestUpdate();\n }\n }\n\n hostDisconnected(): void {\n this.setting.detach(this.host);\n }\n\n /** The version a render starts from; a change while it runs detached must not count as rendered. */\n hostUpdate(): void {\n this.renderingVersion = this.setting.version;\n }\n\n hostUpdated(): void {\n this.renderedVersion = this.renderingVersion;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAyBA,IAAa,gBAAb,MAA8B;CAI5B,YAAY,OAAkB;EAAV,KAAA,QAAA;EAHK,KAAA,iBAAA;EACA,KAAA,wBAAA,IAAI,IAA4B;CAE1B;CAE/B,MAAS;EACP,OAAO,KAAK;CACd;;CAGA,IAAI,OAAgB;EAClB,IAAI,OAAO,GAAG,OAAO,KAAK,KAAK,GAC7B;EAEF,KAAK,QAAQ;EACb,KAAK;EACL,KAAK,MAAM,QAAQ,KAAK,OACtB,KAAK,cAAc;CAEvB;;CAGA,WAAW,MAA0D;EACnE,OAAO,IAAI,wBAAwB,MAAM,IAAI;CAC/C;;CAGA,IAAI,UAAkB;EACpB,OAAO,KAAK;CACd;CAEA,OAAO,MAAoC;EACzC,KAAK,MAAM,IAAI,IAAI;CACrB;CAEA,OAAO,MAAoC;EACzC,KAAK,MAAM,OAAO,IAAI;CACxB;AACF;;AAGA,IAAa,0BAAb,MAAsE;CAIpE,YACE,MACA,SACA;EAFiB,KAAA,OAAA;EACA,KAAA,UAAA;EAEjB,KAAK,kBAAkB,QAAQ;EAC/B,KAAK,mBAAmB,QAAQ;EAChC,KAAK,cAAc,IAAI;CACzB;CAEA,IAAI,QAAW;EACb,OAAO,KAAK,QAAQ,IAAI;CAC1B;;CAGA,gBAAsB;EACpB,KAAK,QAAQ,OAAO,KAAK,IAAI;EAC7B,IAAI,KAAK,oBAAoB,KAAK,QAAQ,SACxC,KAAK,KAAK,cAAc;CAE5B;CAEA,mBAAyB;EACvB,KAAK,QAAQ,OAAO,KAAK,IAAI;CAC/B;;CAGA,aAAmB;EACjB,KAAK,mBAAmB,KAAK,QAAQ;CACvC;CAEA,cAAoB;EAClB,KAAK,kBAAkB,KAAK;CAC9B;AACF"}
|
package/package.json
CHANGED
|
@@ -54,10 +54,10 @@ export enum AnalogThreewayValveVariant {
|
|
|
54
54
|
* @property orientation - Side the stem points to.
|
|
55
55
|
* @property flows - Readout rows, one per flow: an optional arrow direction with either a value and optional unit (default `%`) or `open` for an `Open`/`Closed` state.
|
|
56
56
|
* @property variant - Visual style of the button surround.
|
|
57
|
-
* @slot badge-top-right - Content projected into the top-right badge position; overrides `
|
|
58
|
-
* @slot badge-top-left - Content projected into the top-left badge position; overrides `
|
|
59
|
-
* @slot badge-bottom-left - Content projected into the bottom-left badge position; overrides `
|
|
60
|
-
* @slot badge-bottom-right - Content projected into the bottom-right badge position; overrides `
|
|
57
|
+
* @slot badge-top-right - Content projected into the top-right badge position; overrides the badge `badgeLayout` puts in that corner.
|
|
58
|
+
* @slot badge-top-left - Content projected into the top-left badge position; overrides the badge `badgeLayout` puts in that corner.
|
|
59
|
+
* @slot badge-bottom-left - Content projected into the bottom-left badge position; overrides the badge `badgeLayout` puts in that corner.
|
|
60
|
+
* @slot badge-bottom-right - Content projected into the bottom-right badge position; overrides the badge `badgeLayout` puts in that corner.
|
|
61
61
|
* @fires click - Fired when the valve is clicked.
|
|
62
62
|
* @experimental
|
|
63
63
|
*/
|
|
@@ -47,6 +47,9 @@ export const argTypesAbstractAutomationButton = {
|
|
|
47
47
|
options: Object.values(AutomationButtonBadgeAlert),
|
|
48
48
|
control: {type: 'select'},
|
|
49
49
|
},
|
|
50
|
+
badgeLayout: {
|
|
51
|
+
control: {type: 'object'},
|
|
52
|
+
},
|
|
50
53
|
progressMode: {
|
|
51
54
|
options: Object.values(CircularProgressMode),
|
|
52
55
|
control: {type: 'select'},
|
|
@@ -36,6 +36,11 @@ import {AlertType} from '../../types.js';
|
|
|
36
36
|
import '../automation-badge/automation-badge.js';
|
|
37
37
|
import {ObcAutomationBadgeType} from '../automation-badge/automation-badge.js';
|
|
38
38
|
import {CircularProgressMode} from '../../building-blocks/circular-progress/circular-progress.js';
|
|
39
|
+
import {
|
|
40
|
+
AutomationButtonBadgeKind,
|
|
41
|
+
AutomationButtonBadgeLayout,
|
|
42
|
+
BadgeLayoutController,
|
|
43
|
+
} from './badge-layout.js';
|
|
39
44
|
|
|
40
45
|
export enum AutomationButtonBadgeAlert {
|
|
41
46
|
None = 'none',
|
|
@@ -73,13 +78,18 @@ export enum AutomationButtonBadgeCommandLocked {
|
|
|
73
78
|
Simulation = 'simulation',
|
|
74
79
|
}
|
|
75
80
|
|
|
81
|
+
type BadgeCorner = keyof AutomationButtonBadgeLayout;
|
|
82
|
+
|
|
76
83
|
/**
|
|
77
84
|
* Base class for the automation device buttons.
|
|
78
85
|
*
|
|
79
86
|
* Renders an `<obc-automation-button>` with the shared surface every device
|
|
80
87
|
* button needs: the readout stack and its status row, the alert frame, the
|
|
81
|
-
* circular progress indicator, and the four badge corners
|
|
82
|
-
*
|
|
88
|
+
* circular progress indicator, and the four badge corners with their slots and
|
|
89
|
+
* enum-driven fallbacks. Which badge goes in which corner follows the badge
|
|
90
|
+
* layout (`badge-layout.ts`): control top-left, alert top-right, interlock
|
|
91
|
+
* bottom-left and command-locked bottom-right unless the app or `badgeLayout`
|
|
92
|
+
* moves them.
|
|
83
93
|
*
|
|
84
94
|
* ## Usage Guidelines
|
|
85
95
|
*
|
|
@@ -101,6 +111,7 @@ export enum AutomationButtonBadgeCommandLocked {
|
|
|
101
111
|
* @availableWhen alertFrameMode alert==true
|
|
102
112
|
* @availableWhen showAlertCategoryIcon alert==true && alertFrameType in [SmallSideFlip, LargeSideFlip, BottomFlip, TopFlip]
|
|
103
113
|
* @availableWhen showAlertIcon alert==true && alertFrameType in [LargeSideFlip, BottomFlip, TopFlip]
|
|
114
|
+
* @property badgeLayout - Which badge kind each corner shows, on top of the app-wide layout set with `setAutomationBadgeLayout()`. A corner left out keeps the app-wide badge, `null` leaves it empty, and a badge moved here leaves the corner it came from.
|
|
104
115
|
* @property progress - Shows a progress indicator, used to indicate that an user action is in progress
|
|
105
116
|
* @availableWhen progressMode progress==true
|
|
106
117
|
* @availableWhen progressValue progress==true && progressMode in [determinate, progressiveIndeterminate]
|
|
@@ -144,6 +155,10 @@ export class ObcAbstractAutomationButton extends LitElement {
|
|
|
144
155
|
AutomationButtonBadgeInterlock.None;
|
|
145
156
|
@property({type: String}) badgeAlert: AutomationButtonBadgeAlert =
|
|
146
157
|
AutomationButtonBadgeAlert.None;
|
|
158
|
+
@property({attribute: false}) badgeLayout:
|
|
159
|
+
AutomationButtonBadgeLayout | undefined = undefined;
|
|
160
|
+
|
|
161
|
+
private readonly _badgeLayout = new BadgeLayoutController(this);
|
|
147
162
|
|
|
148
163
|
get icon(): TemplateResult {
|
|
149
164
|
throw new Error('Method "icon" must be implemented in subclass');
|
|
@@ -236,20 +251,19 @@ export class ObcAbstractAutomationButton extends LitElement {
|
|
|
236
251
|
);
|
|
237
252
|
}
|
|
238
253
|
|
|
239
|
-
private getBadgeSpacer(
|
|
254
|
+
private getBadgeSpacer(
|
|
255
|
+
badges: Record<BadgeCorner, ObcAutomationBadgeType | null>
|
|
256
|
+
): boolean {
|
|
240
257
|
if (!this.showReadoutStack) {
|
|
241
258
|
return false;
|
|
242
259
|
}
|
|
243
260
|
|
|
244
|
-
const topLeft =
|
|
245
|
-
|
|
246
|
-
const topRight =
|
|
247
|
-
this.badgeTopRight.length > 0 || this.getBadgeAlertType() !== null;
|
|
261
|
+
const topLeft = this.badgeTopLeft.length > 0 || badges.topLeft !== null;
|
|
262
|
+
const topRight = this.badgeTopRight.length > 0 || badges.topRight !== null;
|
|
248
263
|
const bottomLeft =
|
|
249
|
-
this.badgeBottomLeft.length > 0 ||
|
|
264
|
+
this.badgeBottomLeft.length > 0 || badges.bottomLeft !== null;
|
|
250
265
|
const bottomRight =
|
|
251
|
-
this.badgeBottomRight.length > 0 ||
|
|
252
|
-
this.getBadgeCommandLockedType() !== null;
|
|
266
|
+
this.badgeBottomRight.length > 0 || badges.bottomRight !== null;
|
|
253
267
|
if (this._readoutPosition === AutomationButtonReadoutPosition.top) {
|
|
254
268
|
return topRight || topLeft;
|
|
255
269
|
} else if (
|
|
@@ -270,6 +284,23 @@ export class ObcAbstractAutomationButton extends LitElement {
|
|
|
270
284
|
this.requestUpdate();
|
|
271
285
|
}
|
|
272
286
|
|
|
287
|
+
private getBadgeType(
|
|
288
|
+
kind: AutomationButtonBadgeKind | null
|
|
289
|
+
): ObcAutomationBadgeType | null {
|
|
290
|
+
switch (kind) {
|
|
291
|
+
case AutomationButtonBadgeKind.Control:
|
|
292
|
+
return this.getBadgeControlType();
|
|
293
|
+
case AutomationButtonBadgeKind.Alert:
|
|
294
|
+
return this.getBadgeAlertType();
|
|
295
|
+
case AutomationButtonBadgeKind.Interlock:
|
|
296
|
+
return this.getBadgeInterlockType();
|
|
297
|
+
case AutomationButtonBadgeKind.CommandLocked:
|
|
298
|
+
return this.getBadgeCommandLockedType();
|
|
299
|
+
default:
|
|
300
|
+
return null;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
273
304
|
private getBadgeAlertType(): ObcAutomationBadgeType | null {
|
|
274
305
|
if (this.badgeAlert === AutomationButtonBadgeAlert.Silence) {
|
|
275
306
|
return ObcAutomationBadgeType.AlertSilenced;
|
|
@@ -341,10 +372,13 @@ export class ObcAbstractAutomationButton extends LitElement {
|
|
|
341
372
|
|
|
342
373
|
override render() {
|
|
343
374
|
const readouts: AutomationButtonReadoutStack[] = [...this.extraReadouts];
|
|
344
|
-
const
|
|
345
|
-
const
|
|
346
|
-
|
|
347
|
-
|
|
375
|
+
const layout = this._badgeLayout.resolve(this.badgeLayout);
|
|
376
|
+
const badges = {
|
|
377
|
+
topLeft: this.getBadgeType(layout.topLeft),
|
|
378
|
+
topRight: this.getBadgeType(layout.topRight),
|
|
379
|
+
bottomLeft: this.getBadgeType(layout.bottomLeft),
|
|
380
|
+
bottomRight: this.getBadgeType(layout.bottomRight),
|
|
381
|
+
};
|
|
348
382
|
|
|
349
383
|
return html`<obc-automation-button
|
|
350
384
|
.state=${
|
|
@@ -369,7 +403,7 @@ export class ObcAbstractAutomationButton extends LitElement {
|
|
|
369
403
|
.variant=${this._variant}
|
|
370
404
|
.direction=${this._direction}
|
|
371
405
|
.orientation=${this._orientation}
|
|
372
|
-
.hasBadgeSpacer=${this.getBadgeSpacer()}
|
|
406
|
+
.hasBadgeSpacer=${this.getBadgeSpacer(badges)}
|
|
373
407
|
.handlePosition=${this._handlePosition}
|
|
374
408
|
.static=${this.static}
|
|
375
409
|
.handleSize=${this._handleSize}
|
|
@@ -384,9 +418,9 @@ export class ObcAbstractAutomationButton extends LitElement {
|
|
|
384
418
|
@slotchange=${this.handleBadgeSlotChange}
|
|
385
419
|
>
|
|
386
420
|
${
|
|
387
|
-
|
|
421
|
+
badges.topRight
|
|
388
422
|
? html`<obc-automation-badge
|
|
389
|
-
.type=${
|
|
423
|
+
.type=${badges.topRight}
|
|
390
424
|
></obc-automation-badge>`
|
|
391
425
|
: nothing
|
|
392
426
|
}
|
|
@@ -397,9 +431,9 @@ export class ObcAbstractAutomationButton extends LitElement {
|
|
|
397
431
|
@slotchange=${this.handleBadgeSlotChange}
|
|
398
432
|
>
|
|
399
433
|
${
|
|
400
|
-
|
|
434
|
+
badges.topLeft
|
|
401
435
|
? html`<obc-automation-badge
|
|
402
|
-
.type=${
|
|
436
|
+
.type=${badges.topLeft}
|
|
403
437
|
></obc-automation-badge>`
|
|
404
438
|
: nothing
|
|
405
439
|
}
|
|
@@ -410,9 +444,9 @@ export class ObcAbstractAutomationButton extends LitElement {
|
|
|
410
444
|
@slotchange=${this.handleBadgeSlotChange}
|
|
411
445
|
>
|
|
412
446
|
${
|
|
413
|
-
|
|
447
|
+
badges.bottomLeft
|
|
414
448
|
? html`<obc-automation-badge
|
|
415
|
-
.type=${
|
|
449
|
+
.type=${badges.bottomLeft}
|
|
416
450
|
></obc-automation-badge>`
|
|
417
451
|
: nothing
|
|
418
452
|
}
|
|
@@ -423,9 +457,9 @@ export class ObcAbstractAutomationButton extends LitElement {
|
|
|
423
457
|
@slotchange=${this.handleBadgeSlotChange}
|
|
424
458
|
>
|
|
425
459
|
${
|
|
426
|
-
|
|
460
|
+
badges.bottomRight
|
|
427
461
|
? html`<obc-automation-badge
|
|
428
|
-
.type=${
|
|
462
|
+
.type=${badges.bottomRight}
|
|
429
463
|
></obc-automation-badge>`
|
|
430
464
|
: nothing
|
|
431
465
|
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import {describe, it, expect, afterEach} from 'vitest';
|
|
2
|
+
import '../pump/pump.js';
|
|
3
|
+
import type {ObcPump} from '../pump/pump.js';
|
|
4
|
+
import {
|
|
5
|
+
AutomationButtonBadgeAlert,
|
|
6
|
+
AutomationButtonBadgeCommandLocked,
|
|
7
|
+
AutomationButtonBadgeControl,
|
|
8
|
+
AutomationButtonBadgeInterlock,
|
|
9
|
+
} from './abstract-automation-button.js';
|
|
10
|
+
import {ObcAutomationBadgeType} from '../automation-badge/automation-badge.js';
|
|
11
|
+
import {
|
|
12
|
+
AutomationButtonBadgeKind as Kind,
|
|
13
|
+
defaultAutomationButtonBadgeLayout,
|
|
14
|
+
getAutomationBadgeLayout,
|
|
15
|
+
resolveBadgeLayout,
|
|
16
|
+
setAutomationBadgeLayout,
|
|
17
|
+
} from './badge-layout.js';
|
|
18
|
+
|
|
19
|
+
describe('resolveBadgeLayout', () => {
|
|
20
|
+
const base = defaultAutomationButtonBadgeLayout;
|
|
21
|
+
|
|
22
|
+
it('keeps the base when nothing overrides it', () => {
|
|
23
|
+
expect(resolveBadgeLayout(base, undefined)).toEqual(base);
|
|
24
|
+
expect(resolveBadgeLayout(base, {})).toEqual(base);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('empties a corner set to null', () => {
|
|
28
|
+
expect(resolveBadgeLayout(base, {bottomRight: null})).toEqual({
|
|
29
|
+
...base,
|
|
30
|
+
bottomRight: null,
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('moves a kind out of the corner it came from', () => {
|
|
35
|
+
expect(resolveBadgeLayout(base, {topLeft: Kind.Alert})).toEqual({
|
|
36
|
+
topLeft: Kind.Alert,
|
|
37
|
+
topRight: null,
|
|
38
|
+
bottomLeft: Kind.Interlock,
|
|
39
|
+
bottomRight: Kind.CommandLocked,
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('keeps a kind named twice in the first corner only', () => {
|
|
44
|
+
expect(
|
|
45
|
+
resolveBadgeLayout(base, {topRight: Kind.Alert, bottomLeft: Kind.Alert})
|
|
46
|
+
).toEqual({...base, bottomLeft: null});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('swaps two kinds when both corners are named', () => {
|
|
50
|
+
expect(
|
|
51
|
+
resolveBadgeLayout(base, {topLeft: Kind.Alert, topRight: Kind.Control})
|
|
52
|
+
).toEqual({...base, topLeft: Kind.Alert, topRight: Kind.Control});
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const mounted: HTMLElement[] = [];
|
|
57
|
+
afterEach(() => {
|
|
58
|
+
mounted.splice(0).forEach((el) => el.remove());
|
|
59
|
+
setAutomationBadgeLayout(undefined);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
async function mountPump() {
|
|
63
|
+
const el = document.createElement('obc-pump') as ObcPump;
|
|
64
|
+
el.badgeControl = AutomationButtonBadgeControl.Auto;
|
|
65
|
+
el.badgeAlert = AutomationButtonBadgeAlert.Alarm;
|
|
66
|
+
el.badgeInterlock = AutomationButtonBadgeInterlock.Interlock;
|
|
67
|
+
el.badgeCommandLocked = AutomationButtonBadgeCommandLocked.CommandLocked;
|
|
68
|
+
document.body.appendChild(el);
|
|
69
|
+
mounted.push(el);
|
|
70
|
+
await el.updateComplete;
|
|
71
|
+
return el;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function badgeIn(el: ObcPump, corner: string): string | null {
|
|
75
|
+
const badge = el.shadowRoot!.querySelector(
|
|
76
|
+
`slot[name="${corner}"] obc-automation-badge`
|
|
77
|
+
) as unknown as {type: ObcAutomationBadgeType} | null;
|
|
78
|
+
return badge?.type ?? null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
describe('badge layout on a device', () => {
|
|
82
|
+
it('renders the default layout', async () => {
|
|
83
|
+
const el = await mountPump();
|
|
84
|
+
expect(badgeIn(el, 'badge-top-left')).toBe(ObcAutomationBadgeType.Auto);
|
|
85
|
+
expect(badgeIn(el, 'badge-top-right')).toBe(ObcAutomationBadgeType.Alarm);
|
|
86
|
+
expect(badgeIn(el, 'badge-bottom-left')).toBe(
|
|
87
|
+
ObcAutomationBadgeType.Interlock
|
|
88
|
+
);
|
|
89
|
+
expect(badgeIn(el, 'badge-bottom-right')).toBe(
|
|
90
|
+
ObcAutomationBadgeType.CommandLocked
|
|
91
|
+
);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('re-renders a connected device when the global layout changes', async () => {
|
|
95
|
+
const el = await mountPump();
|
|
96
|
+
setAutomationBadgeLayout({topLeft: Kind.Alert, topRight: Kind.Control});
|
|
97
|
+
await el.updateComplete;
|
|
98
|
+
expect(badgeIn(el, 'badge-top-left')).toBe(ObcAutomationBadgeType.Alarm);
|
|
99
|
+
expect(badgeIn(el, 'badge-top-right')).toBe(ObcAutomationBadgeType.Auto);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('lets the local layout override corners of the global one', async () => {
|
|
103
|
+
setAutomationBadgeLayout({bottomLeft: Kind.CommandLocked});
|
|
104
|
+
expect(getAutomationBadgeLayout().bottomRight).toBeNull();
|
|
105
|
+
const el = await mountPump();
|
|
106
|
+
el.badgeLayout = {bottomRight: Kind.Interlock};
|
|
107
|
+
await el.updateComplete;
|
|
108
|
+
expect(badgeIn(el, 'badge-bottom-left')).toBe(
|
|
109
|
+
ObcAutomationBadgeType.CommandLocked
|
|
110
|
+
);
|
|
111
|
+
expect(badgeIn(el, 'badge-bottom-right')).toBe(
|
|
112
|
+
ObcAutomationBadgeType.Interlock
|
|
113
|
+
);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('stops updating a disconnected device', async () => {
|
|
117
|
+
const el = await mountPump();
|
|
118
|
+
el.remove();
|
|
119
|
+
setAutomationBadgeLayout({topLeft: null});
|
|
120
|
+
expect(el.isUpdatePending).toBe(false);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('picks up a layout set while it was detached', async () => {
|
|
124
|
+
const el = await mountPump();
|
|
125
|
+
el.remove();
|
|
126
|
+
setAutomationBadgeLayout({topLeft: null});
|
|
127
|
+
document.body.appendChild(el);
|
|
128
|
+
await el.updateComplete;
|
|
129
|
+
expect(badgeIn(el, 'badge-top-left')).toBeNull();
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('does not re-render on reconnect when nothing changed', async () => {
|
|
133
|
+
const el = await mountPump();
|
|
134
|
+
el.remove();
|
|
135
|
+
document.body.appendChild(el);
|
|
136
|
+
expect(el.isUpdatePending).toBe(false);
|
|
137
|
+
});
|
|
138
|
+
});
|