@oicl/openbridge-webcomponents-full-bundle 2.2.0-next.15 → 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 +320 -64
- package/bundle/openbridge-webcomponents.bundle.js.map +1 -1
- package/custom-elements.json +1752 -15
- 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-badge/automation-badge.css_inline.js +6 -0
- package/dist/automation/automation-badge/automation-badge.d.ts +61 -1
- package/dist/automation/automation-badge/automation-badge.d.ts.map +1 -1
- package/dist/automation/automation-badge/automation-badge.js +83 -1
- package/dist/automation/automation-badge/automation-badge.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 +16 -4
- package/dist/automation/automation-button/abstract-automation-button.d.ts.map +1 -1
- package/dist/automation/automation-button/abstract-automation-button.js +46 -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/automation-tank/automation-tank.d.ts.map +1 -1
- package/dist/automation/automation-tank/automation-tank.js +7 -2
- package/dist/automation/automation-tank/automation-tank.js.map +1 -1
- 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/automation/specialty-tank/abstract-specialty-tank.d.ts.map +1 -1
- package/dist/automation/specialty-tank/abstract-specialty-tank.js +7 -2
- package/dist/automation/specialty-tank/abstract-specialty-tank.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 +3 -2
- package/script/check-typography-ramp.ts +144 -0
- package/script/typography/ramp.ts +237 -0
- package/script/typography-ramp.test.ts +267 -0
- package/src/automation/analog-threeway-valve/analog-threeway-valve.ts +4 -4
- package/src/automation/analog-valve/analog-valve.stories.ts +8 -0
- package/src/automation/automation-badge/automation-badge.css +6 -0
- package/src/automation/automation-badge/automation-badge.stories.ts +47 -3
- package/src/automation/automation-badge/automation-badge.ts +124 -1
- package/src/automation/automation-button/abstract-automation-button-storybook-helpers.ts +3 -0
- package/src/automation/automation-button/abstract-automation-button.ts +70 -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/automation-tank/automation-tank.ts +11 -6
- 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/automation/specialty-tank/abstract-specialty-tank.ts +11 -6
- package/src/internal/global-setting.spec.ts +119 -0
- package/src/internal/global-setting.ts +105 -0
|
@@ -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
|
+
}
|