@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.
Files changed (36) hide show
  1. package/bundle/openbridge-webcomponents.bundle.js +173 -20
  2. package/bundle/openbridge-webcomponents.bundle.js.map +1 -1
  3. package/custom-elements.json +1713 -14
  4. package/dist/automation/analog-threeway-valve/analog-threeway-valve.d.ts +4 -4
  5. package/dist/automation/analog-threeway-valve/analog-threeway-valve.js.map +1 -1
  6. package/dist/automation/automation-button/abstract-automation-button-storybook-helpers.d.ts +20 -0
  7. package/dist/automation/automation-button/abstract-automation-button-storybook-helpers.d.ts.map +1 -1
  8. package/dist/automation/automation-button/abstract-automation-button-storybook-helpers.js +1 -0
  9. package/dist/automation/automation-button/abstract-automation-button-storybook-helpers.js.map +1 -1
  10. package/dist/automation/automation-button/abstract-automation-button.d.ts +11 -2
  11. package/dist/automation/automation-button/abstract-automation-button.d.ts.map +1 -1
  12. package/dist/automation/automation-button/abstract-automation-button.js +40 -20
  13. package/dist/automation/automation-button/abstract-automation-button.js.map +1 -1
  14. package/dist/automation/automation-button/badge-layout.d.ts +34 -0
  15. package/dist/automation/automation-button/badge-layout.d.ts.map +1 -0
  16. package/dist/automation/automation-button/badge-layout.js +64 -0
  17. package/dist/automation/automation-button/badge-layout.js.map +1 -0
  18. package/dist/automation/digital-threeway-valve/digital-threeway-valve.d.ts +4 -4
  19. package/dist/automation/digital-threeway-valve/digital-threeway-valve.js.map +1 -1
  20. package/dist/automation/electricity-battery/electricity-battery.d.ts +4 -4
  21. package/dist/automation/electricity-battery/electricity-battery.js.map +1 -1
  22. package/dist/internal/global-setting.d.ts +55 -0
  23. package/dist/internal/global-setting.d.ts.map +1 -0
  24. package/dist/internal/global-setting.js +86 -0
  25. package/dist/internal/global-setting.js.map +1 -0
  26. package/package.json +1 -1
  27. package/src/automation/analog-threeway-valve/analog-threeway-valve.ts +4 -4
  28. package/src/automation/automation-button/abstract-automation-button-storybook-helpers.ts +3 -0
  29. package/src/automation/automation-button/abstract-automation-button.ts +57 -23
  30. package/src/automation/automation-button/badge-layout.spec.ts +138 -0
  31. package/src/automation/automation-button/badge-layout.ts +120 -0
  32. package/src/automation/digital-threeway-valve/digital-threeway-valve.ts +4 -4
  33. package/src/automation/electricity-battery/electricity-battery.ts +4 -4
  34. package/src/automation/pump/pump.stories.ts +59 -0
  35. package/src/internal/global-setting.spec.ts +119 -0
  36. package/src/internal/global-setting.ts +105 -0
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Badge layout of the automation buttons.
3
+ *
4
+ * Says which badge kind each corner of an automation button shows. The app
5
+ * sets one layout for every button with `setAutomationBadgeLayout()`; a
6
+ * button's own `badgeLayout` property changes single corners on top of it.
7
+ *
8
+ * Merge rules, for both the global and the local layout:
9
+ * - a corner left out keeps the layout underneath it,
10
+ * - `null` leaves the corner empty,
11
+ * - a kind moved to a new corner leaves the corner it came from, so it is
12
+ * never shown twice.
13
+ *
14
+ * ```ts
15
+ * setAutomationBadgeLayout({
16
+ * topLeft: AutomationButtonBadgeKind.Alert,
17
+ * topRight: AutomationButtonBadgeKind.Control,
18
+ * });
19
+ * ```
20
+ *
21
+ * @module
22
+ */
23
+ import type {ReactiveControllerHost} from 'lit';
24
+ import {
25
+ GlobalSetting,
26
+ GlobalSettingController,
27
+ } from '../../internal/global-setting.js';
28
+
29
+ export enum AutomationButtonBadgeKind {
30
+ Control = 'control',
31
+ Alert = 'alert',
32
+ Interlock = 'interlock',
33
+ CommandLocked = 'command-locked',
34
+ }
35
+
36
+ /** Which badge kind each corner shows. `null` leaves the corner empty. */
37
+ export interface AutomationButtonBadgeLayout {
38
+ topLeft?: AutomationButtonBadgeKind | null;
39
+ topRight?: AutomationButtonBadgeKind | null;
40
+ bottomLeft?: AutomationButtonBadgeKind | null;
41
+ bottomRight?: AutomationButtonBadgeKind | null;
42
+ }
43
+
44
+ export type ResolvedAutomationButtonBadgeLayout =
45
+ Required<AutomationButtonBadgeLayout>;
46
+
47
+ const corners = ['topLeft', 'topRight', 'bottomLeft', 'bottomRight'] as const;
48
+
49
+ export const defaultAutomationButtonBadgeLayout: Readonly<ResolvedAutomationButtonBadgeLayout> =
50
+ Object.freeze({
51
+ topLeft: AutomationButtonBadgeKind.Control,
52
+ topRight: AutomationButtonBadgeKind.Alert,
53
+ bottomLeft: AutomationButtonBadgeKind.Interlock,
54
+ bottomRight: AutomationButtonBadgeKind.CommandLocked,
55
+ });
56
+
57
+ /**
58
+ * The `base` layout with the corners `override` names put on top of it.
59
+ * A kind `override` names twice stays in the first corner, in reading order.
60
+ */
61
+ export function resolveBadgeLayout(
62
+ base: ResolvedAutomationButtonBadgeLayout,
63
+ override: AutomationButtonBadgeLayout | undefined
64
+ ): ResolvedAutomationButtonBadgeLayout {
65
+ const result = {...base};
66
+ if (!override) {
67
+ return result;
68
+ }
69
+ const placed = new Set<AutomationButtonBadgeKind>();
70
+ for (const corner of corners) {
71
+ const kind = override[corner];
72
+ if (kind === undefined) {
73
+ continue;
74
+ }
75
+ result[corner] = kind !== null && placed.has(kind) ? null : kind;
76
+ if (kind !== null) {
77
+ placed.add(kind);
78
+ }
79
+ }
80
+ for (const corner of corners) {
81
+ const kind = result[corner];
82
+ if (override[corner] === undefined && kind !== null && placed.has(kind)) {
83
+ result[corner] = null;
84
+ }
85
+ }
86
+ return result;
87
+ }
88
+
89
+ const globalLayout = new GlobalSetting<ResolvedAutomationButtonBadgeLayout>({
90
+ ...defaultAutomationButtonBadgeLayout,
91
+ });
92
+
93
+ /**
94
+ * Sets the badge layout of every automation button on the page, and
95
+ * re-renders the ones already connected. `undefined` restores the default.
96
+ */
97
+ export function setAutomationBadgeLayout(
98
+ layout: AutomationButtonBadgeLayout | undefined
99
+ ): void {
100
+ globalLayout.set(
101
+ resolveBadgeLayout(defaultAutomationButtonBadgeLayout, layout)
102
+ );
103
+ }
104
+
105
+ export function getAutomationBadgeLayout(): ResolvedAutomationButtonBadgeLayout {
106
+ return {...globalLayout.get()};
107
+ }
108
+
109
+ /** Re-renders its host when the global badge layout changes, and puts the host's own corners on top of it. */
110
+ export class BadgeLayoutController extends GlobalSettingController<ResolvedAutomationButtonBadgeLayout> {
111
+ constructor(host: ReactiveControllerHost) {
112
+ super(host, globalLayout);
113
+ }
114
+
115
+ resolve(
116
+ local: AutomationButtonBadgeLayout | undefined
117
+ ): ResolvedAutomationButtonBadgeLayout {
118
+ return resolveBadgeLayout(this.value, local);
119
+ }
120
+ }
@@ -60,10 +60,10 @@ export enum DigitalThreewayValveVariant {
60
60
  * @property orientation - Side the stem points to.
61
61
  * @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.
62
62
  * @property variant - Visual style of the button surround.
63
- * @slot badge-top-right - Content projected into the top-right badge position; overrides `badgeAlert`.
64
- * @slot badge-top-left - Content projected into the top-left badge position; overrides `badgeControl`.
65
- * @slot badge-bottom-left - Content projected into the bottom-left badge position; overrides `badgeInterlock`.
66
- * @slot badge-bottom-right - Content projected into the bottom-right badge position; overrides `badgeCommandLocked`.
63
+ * @slot badge-top-right - Content projected into the top-right badge position; overrides the badge `badgeLayout` puts in that corner.
64
+ * @slot badge-top-left - Content projected into the top-left badge position; overrides the badge `badgeLayout` puts in that corner.
65
+ * @slot badge-bottom-left - Content projected into the bottom-left badge position; overrides the badge `badgeLayout` puts in that corner.
66
+ * @slot badge-bottom-right - Content projected into the bottom-right badge position; overrides the badge `badgeLayout` puts in that corner.
67
67
  * @fires click - Fired when the valve is clicked.
68
68
  * @experimental
69
69
  */
@@ -21,10 +21,10 @@ import {ObcAbstractAutomationButtonSquared} from '../automation-button/abstract-
21
21
  * Without a visible tag the button is named `Battery`, followed by the state
22
22
  * (`Battery On`) when the state row is shown.
23
23
  *
24
- * @slot badge-top-right - Content projected into the top-right badge position; overrides `badgeAlert`.
25
- * @slot badge-top-left - Content projected into the top-left badge position; overrides `badgeControl`.
26
- * @slot badge-bottom-left - Content projected into the bottom-left badge position; overrides `badgeInterlock`.
27
- * @slot badge-bottom-right - Content projected into the bottom-right badge position; overrides `badgeCommandLocked`.
24
+ * @slot badge-top-right - Content projected into the top-right badge position; overrides the badge `badgeLayout` puts in that corner.
25
+ * @slot badge-top-left - Content projected into the top-left badge position; overrides the badge `badgeLayout` puts in that corner.
26
+ * @slot badge-bottom-left - Content projected into the bottom-left badge position; overrides the badge `badgeLayout` puts in that corner.
27
+ * @slot badge-bottom-right - Content projected into the bottom-right badge position; overrides the badge `badgeLayout` puts in that corner.
28
28
  * @fires click - Fired when the battery is clicked.
29
29
  * @experimental
30
30
  */
@@ -10,6 +10,16 @@ import {
10
10
  } from '../automation-button/automation-button.js';
11
11
  import {AutomationButtonReadoutStackSize} from '../../components/automation-button-readout-stack/automation-button-readout-stack.js';
12
12
  import {argTypesAbstractAutomationButtonMotorized} from '../automation-button/abstract-automation-button-storybook-helpers.js';
13
+ import {
14
+ AutomationButtonBadgeAlert,
15
+ AutomationButtonBadgeCommandLocked,
16
+ AutomationButtonBadgeControl,
17
+ AutomationButtonBadgeInterlock,
18
+ } from '../automation-button/abstract-automation-button.js';
19
+ import {
20
+ AutomationButtonBadgeKind,
21
+ setAutomationBadgeLayout,
22
+ } from '../automation-button/badge-layout.js';
13
23
 
14
24
  const meta: Meta<typeof ObcPump> = {
15
25
  title: 'Automation/Automation Devices/Pump',
@@ -79,3 +89,52 @@ export const VariantDoubleSizeLarge: Story = {
79
89
  componentSize: 'obc-component-size-large',
80
90
  },
81
91
  };
92
+
93
+ const allBadges = {
94
+ turnedOn: true,
95
+ vertical: false,
96
+ direction: AutomationButtonDirection.forward,
97
+ labelDirection: AutomationButtonLabelDirection.left,
98
+ badgeControl: AutomationButtonBadgeControl.Auto,
99
+ badgeAlert: AutomationButtonBadgeAlert.Alarm,
100
+ badgeInterlock: AutomationButtonBadgeInterlock.Interlock,
101
+ badgeCommandLocked: AutomationButtonBadgeCommandLocked.CommandLocked,
102
+ };
103
+
104
+ export const BadgeLayoutLocal: Story = {
105
+ args: {
106
+ ...allBadges,
107
+ badgeLayout: {
108
+ topLeft: AutomationButtonBadgeKind.Alert,
109
+ topRight: AutomationButtonBadgeKind.Control,
110
+ bottomRight: null,
111
+ },
112
+ },
113
+ parameters: {
114
+ docs: {
115
+ description: {
116
+ story:
117
+ 'Alert and control swap corners on this pump only, and command-locked is hidden.',
118
+ },
119
+ },
120
+ },
121
+ };
122
+
123
+ export const BadgeLayoutGlobal: Story = {
124
+ args: allBadges,
125
+ beforeEach: () => {
126
+ setAutomationBadgeLayout({
127
+ topLeft: AutomationButtonBadgeKind.Interlock,
128
+ bottomLeft: AutomationButtonBadgeKind.Control,
129
+ });
130
+ return () => setAutomationBadgeLayout(undefined);
131
+ },
132
+ parameters: {
133
+ docs: {
134
+ description: {
135
+ story:
136
+ 'The app-wide layout from `setAutomationBadgeLayout()` puts interlock top-left and control bottom-left on every device.',
137
+ },
138
+ },
139
+ },
140
+ };
@@ -0,0 +1,119 @@
1
+ import {beforeEach, describe, expect, it} from 'vitest';
2
+ import {LitElement, html, type PropertyValues} from 'lit';
3
+ import {GlobalSetting} from './global-setting.js';
4
+
5
+ const label = new GlobalSetting('one');
6
+
7
+ type SettingHost = LitElement & {renders: number};
8
+
9
+ // Registered on first use rather than at module scope: the wrapper
10
+ // generators read every module-level element definition, specs included.
11
+ function settingHost(leavesDuringUpdate = false): SettingHost {
12
+ const tag = leavesDuringUpdate
13
+ ? 'test-global-setting-leaving-host'
14
+ : 'test-global-setting-host';
15
+ if (!customElements.get(tag)) {
16
+ const Host = class extends LitElement {
17
+ private readonly label = label.controller(this);
18
+ renders = 0;
19
+
20
+ override render() {
21
+ this.renders++;
22
+ return html`${this.label.value}`;
23
+ }
24
+ };
25
+ customElements.define(
26
+ tag,
27
+ leavesDuringUpdate
28
+ ? class extends Host {
29
+ private left = false;
30
+
31
+ /** Leaves the page from inside its own update, and changes the setting before the update completes. */
32
+ override update(changed: PropertyValues) {
33
+ super.update(changed);
34
+ if (!this.left) {
35
+ this.left = true;
36
+ this.remove();
37
+ label.set('two');
38
+ }
39
+ }
40
+ }
41
+ : Host
42
+ );
43
+ }
44
+ const host = document.createElement(tag) as SettingHost;
45
+ document.body.appendChild(host);
46
+ return host;
47
+ }
48
+
49
+ describe('GlobalSetting', () => {
50
+ beforeEach(() => {
51
+ label.set('one');
52
+ document.body.replaceChildren();
53
+ });
54
+
55
+ it('renders the value, and set() re-renders every connected host', async () => {
56
+ const first = settingHost();
57
+ const second = settingHost();
58
+ await first.updateComplete;
59
+ await second.updateComplete;
60
+ expect(first.shadowRoot!.textContent).toBe('one');
61
+
62
+ label.set('two');
63
+ await first.updateComplete;
64
+ await second.updateComplete;
65
+
66
+ expect(first.shadowRoot!.textContent).toBe('two');
67
+ expect(second.shadowRoot!.textContent).toBe('two');
68
+ expect(first.renders).toBe(2);
69
+ });
70
+
71
+ it('does nothing when the same value is set again', async () => {
72
+ const host = settingHost();
73
+ await host.updateComplete;
74
+
75
+ label.set('one');
76
+ await host.updateComplete;
77
+
78
+ expect(host.renders).toBe(1);
79
+ });
80
+
81
+ it('leaves a detached host alone and lets it catch up on reconnect', async () => {
82
+ const host = settingHost();
83
+ await host.updateComplete;
84
+
85
+ host.remove();
86
+ label.set('two');
87
+ await host.updateComplete;
88
+ expect(host.renders).toBe(1);
89
+
90
+ document.body.appendChild(host);
91
+ await host.updateComplete;
92
+ expect(host.renders).toBe(2);
93
+ expect(host.shadowRoot!.textContent).toBe('two');
94
+ });
95
+
96
+ it('counts a change during a render that left the page as not rendered', async () => {
97
+ const host = settingHost(true);
98
+ await host.updateComplete;
99
+ expect(host.isConnected).toBe(false);
100
+ expect(host.shadowRoot!.textContent).toBe('one');
101
+
102
+ document.body.appendChild(host);
103
+ await host.updateComplete;
104
+
105
+ expect(host.shadowRoot!.textContent).toBe('two');
106
+ expect(host.renders).toBe(2);
107
+ });
108
+
109
+ it('does not re-render a host reattached while nothing changed', async () => {
110
+ const host = settingHost();
111
+ await host.updateComplete;
112
+
113
+ host.remove();
114
+ document.body.appendChild(host);
115
+ await host.updateComplete;
116
+
117
+ expect(host.renders).toBe(1);
118
+ });
119
+ });
@@ -0,0 +1,105 @@
1
+ import type {ReactiveController, ReactiveControllerHost} from 'lit';
2
+
3
+ /**
4
+ * One app-wide setting the components render from.
5
+ *
6
+ * The application sets it once through a module setter such as
7
+ * `setAutomationBadgeLayout()` or `setAlertStandard()`. Every connected host
8
+ * that holds a controller for it re-renders on each change; a host detached
9
+ * while the value changed catches up on its next connect, and one reattached
10
+ * unchanged renders nothing extra. Setting the same value again is a no-op.
11
+ *
12
+ * It is a plain subscriber set rather than a signal: the value rarely changes
13
+ * and derives nothing, and the library stays off a pre-standard polyfill. A
14
+ * setter built on it can move to a signal later without changing its signature.
15
+ *
16
+ * ```ts
17
+ * const alertStandard = new GlobalSetting<AlertStandard | undefined>(undefined);
18
+ * export const setAlertStandard = (s?: AlertStandard) => alertStandard.set(s);
19
+ *
20
+ * class ObcAlertIcon extends LitElement {
21
+ * private readonly standard = alertStandard.controller(this);
22
+ * render() { return draw(this.standard.value); }
23
+ * }
24
+ * ```
25
+ */
26
+ export class GlobalSetting<T> {
27
+ private currentVersion = 0;
28
+ private readonly hosts = new Set<ReactiveControllerHost>();
29
+
30
+ constructor(private value: T) {}
31
+
32
+ get(): T {
33
+ return this.value;
34
+ }
35
+
36
+ /** Stores the value and re-renders every connected host. */
37
+ set(value: T): void {
38
+ if (Object.is(value, this.value)) {
39
+ return;
40
+ }
41
+ this.value = value;
42
+ this.currentVersion++;
43
+ for (const host of this.hosts) {
44
+ host.requestUpdate();
45
+ }
46
+ }
47
+
48
+ /** Re-renders `host` whenever the value changes; create it once, in the host's constructor. */
49
+ controller(host: ReactiveControllerHost): GlobalSettingController<T> {
50
+ return new GlobalSettingController(host, this);
51
+ }
52
+
53
+ /** Counts the changes, so a controller can tell whether its host rendered the current value. */
54
+ get version(): number {
55
+ return this.currentVersion;
56
+ }
57
+
58
+ attach(host: ReactiveControllerHost): void {
59
+ this.hosts.add(host);
60
+ }
61
+
62
+ detach(host: ReactiveControllerHost): void {
63
+ this.hosts.delete(host);
64
+ }
65
+ }
66
+
67
+ /** Keeps one host rendered with the current value of a `GlobalSetting`. */
68
+ export class GlobalSettingController<T> implements ReactiveController {
69
+ private renderedVersion: number;
70
+ private renderingVersion: number;
71
+
72
+ constructor(
73
+ private readonly host: ReactiveControllerHost,
74
+ private readonly setting: GlobalSetting<T>
75
+ ) {
76
+ this.renderedVersion = setting.version;
77
+ this.renderingVersion = setting.version;
78
+ host.addController(this);
79
+ }
80
+
81
+ get value(): T {
82
+ return this.setting.get();
83
+ }
84
+
85
+ /** A value set while the host was detached never reached it. */
86
+ hostConnected(): void {
87
+ this.setting.attach(this.host);
88
+ if (this.renderedVersion !== this.setting.version) {
89
+ this.host.requestUpdate();
90
+ }
91
+ }
92
+
93
+ hostDisconnected(): void {
94
+ this.setting.detach(this.host);
95
+ }
96
+
97
+ /** The version a render starts from; a change while it runs detached must not count as rendered. */
98
+ hostUpdate(): void {
99
+ this.renderingVersion = this.setting.version;
100
+ }
101
+
102
+ hostUpdated(): void {
103
+ this.renderedVersion = this.renderingVersion;
104
+ }
105
+ }