@oicl/openbridge-webcomponents-full-bundle 2.1.0-next.1 → 2.1.0-next.2
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/.storybook/main.ts +2 -0
- package/bundle/openbridge-webcomponents.bundle.js +352 -244
- package/bundle/openbridge-webcomponents.bundle.js.map +1 -1
- package/custom-elements.json +1031 -97
- package/dist/building-blocks/alert-list/alert-list-base.d.ts +60 -0
- package/dist/building-blocks/alert-list/alert-list-base.d.ts.map +1 -0
- package/dist/building-blocks/alert-list/alert-list-base.js +191 -0
- package/dist/building-blocks/alert-list/alert-list-base.js.map +1 -0
- package/dist/building-blocks/alert-list/alert-list.css.js.map +1 -1
- package/dist/building-blocks/alert-list/alert-list.d.ts +13 -26
- package/dist/building-blocks/alert-list/alert-list.d.ts.map +1 -1
- package/dist/building-blocks/alert-list/alert-list.js +7 -142
- package/dist/building-blocks/alert-list/alert-list.js.map +1 -1
- package/dist/components/alert-icon/alert-icon.d.ts.map +1 -1
- package/dist/components/alert-icon/alert-icon.js +6 -5
- package/dist/components/alert-icon/alert-icon.js.map +1 -1
- package/dist/components/alert-list-details/alert-list-details.css.js +4 -1
- package/dist/components/alert-list-details/alert-list-details.css.js.map +1 -1
- package/dist/components/alert-menu/alert-menu.css.js +3 -42
- package/dist/components/alert-menu/alert-menu.css.js.map +1 -1
- package/dist/components/alert-menu/alert-menu.d.ts +28 -6
- package/dist/components/alert-menu/alert-menu.d.ts.map +1 -1
- package/dist/components/alert-menu/alert-menu.js +81 -60
- package/dist/components/alert-menu/alert-menu.js.map +1 -1
- package/dist/components/alert-menu-item/alert-menu-item.d.ts +16 -6
- package/dist/components/alert-menu-item/alert-menu-item.d.ts.map +1 -1
- package/dist/components/alert-menu-item/alert-menu-item.js +11 -2
- package/dist/components/alert-menu-item/alert-menu-item.js.map +1 -1
- package/dist/components/number-input-field/number-input-field.css.js +8 -2
- package/dist/components/number-input-field/number-input-field.css.js.map +1 -1
- package/dist/components/number-input-field/number-input-field.d.ts +15 -1
- package/dist/components/number-input-field/number-input-field.d.ts.map +1 -1
- package/dist/components/number-input-field/number-input-field.js +38 -44
- package/dist/components/number-input-field/number-input-field.js.map +1 -1
- package/dist/components/textbox/textbox.css.js +3 -9
- package/dist/components/textbox/textbox.css.js.map +1 -1
- package/dist/components/textbox/textbox.d.ts +3 -0
- package/dist/components/textbox/textbox.d.ts.map +1 -1
- package/dist/components/textbox/textbox.js.map +1 -1
- package/dist/generated/locales/es-419.d.ts +1 -1
- package/dist/generated/locales/es-419.js +1 -1
- package/dist/generated/locales/es-419.js.map +1 -1
- package/dist/navigation-instruments/readout-list-item/readout-list-item.css.js +2 -1
- package/dist/navigation-instruments/readout-list-item/readout-list-item.css.js.map +1 -1
- package/dist/pages/alert-detail-page/alert-detail-page.js +1 -1
- package/dist/pages/alert-detail-page/alert-detail-page.js.map +1 -1
- package/dist/pages/alert-list-page-small/alert-list-page-small-base.d.ts +59 -0
- package/dist/pages/alert-list-page-small/alert-list-page-small-base.d.ts.map +1 -0
- package/dist/pages/alert-list-page-small/alert-list-page-small-base.js +126 -0
- package/dist/pages/alert-list-page-small/alert-list-page-small-base.js.map +1 -0
- package/dist/pages/alert-list-page-small/alert-list-page-small.d.ts +12 -15
- package/dist/pages/alert-list-page-small/alert-list-page-small.d.ts.map +1 -1
- package/dist/pages/alert-list-page-small/alert-list-page-small.js +41 -92
- package/dist/pages/alert-list-page-small/alert-list-page-small.js.map +1 -1
- package/docs/GettingStarted.mdx +1 -0
- package/docs/MigrationGuide.mdx +2 -0
- package/package.json +1 -1
- package/src/building-blocks/alert-list/alert-list-base.ts +266 -0
- package/src/building-blocks/alert-list/alert-list.css +1 -23
- package/src/building-blocks/alert-list/alert-list.spec.ts +22 -0
- package/src/building-blocks/alert-list/alert-list.ts +15 -207
- package/src/components/alert-icon/alert-icon.spec.ts +39 -0
- package/src/components/alert-icon/alert-icon.ts +11 -7
- package/src/components/alert-list-details/alert-list-details.css +1 -20
- package/src/components/alert-menu/alert-menu.css +5 -28
- package/src/components/alert-menu/alert-menu.spec.ts +113 -0
- package/src/components/alert-menu/alert-menu.ts +142 -79
- package/src/components/alert-menu-item/alert-menu-item.spec.ts +39 -0
- package/src/components/alert-menu-item/alert-menu-item.stories.ts +22 -0
- package/src/components/alert-menu-item/alert-menu-item.ts +22 -6
- package/src/components/number-input-field/number-input-field.css +8 -2
- package/src/components/number-input-field/number-input-field.spec.ts +260 -2
- package/src/components/number-input-field/number-input-field.stories.ts +74 -0
- package/src/components/number-input-field/number-input-field.ts +45 -74
- package/src/components/textbox/textbox.css +3 -9
- package/src/components/textbox/textbox.stories.ts +24 -0
- package/src/components/textbox/textbox.ts +3 -0
- package/src/generated/locales/es-419.ts +1 -1
- package/src/mixins/alert-list-empty.css +32 -0
- package/src/navigation-instruments/readout-list-item/readout-list-item.css +2 -1
- package/src/pages/alert-detail-page/alert-detail-page.spec.ts +41 -0
- package/src/pages/alert-detail-page/alert-detail-page.ts +1 -1
- package/src/pages/alert-list-page-small/alert-list-page-small-base.ts +152 -0
- package/src/pages/alert-list-page-small/alert-list-page-small.spec.ts +84 -0
- package/src/pages/alert-list-page-small/alert-list-page-small.ts +43 -112
|
@@ -3,17 +3,13 @@ import __decorate from "../../_virtual/_@oxc-project_runtime@0.150.0/helpers/esm
|
|
|
3
3
|
import "../../icons/icon-alarm-noack-iec.js";
|
|
4
4
|
import "../../icons/icon-alerts-shelf.js";
|
|
5
5
|
import "../../icons/icon-alerts.js";
|
|
6
|
-
import "../../icons/icon-silence-iec.js";
|
|
7
6
|
import "../../icons/icon-unacknowledged.js";
|
|
8
7
|
import "../../icons/icon-warning-noack-iec.js";
|
|
9
|
-
import "../../components/icon-button/icon-button.js";
|
|
10
|
-
import { ButtonVariant } from "../../components/button/button.js";
|
|
11
8
|
import "../../building-blocks/alert-list/alert-list.js";
|
|
12
9
|
import { canAckFilter, getAlertListModeData } from "../../components/alert-list-details/alert-list-details.js";
|
|
13
|
-
import "
|
|
14
|
-
import alert_list_page_small_default from "./alert-list-page-small.css.js";
|
|
10
|
+
import { ObcAlertListPageSmallBase } from "./alert-list-page-small-base.js";
|
|
15
11
|
import { msg } from "@lit/localize";
|
|
16
|
-
import {
|
|
12
|
+
import { html } from "lit";
|
|
17
13
|
import { property, query, state } from "lit/decorators.js";
|
|
18
14
|
//#region src/pages/alert-list-page-small/alert-list-page-small.ts
|
|
19
15
|
var AlertListMode = /* @__PURE__ */ function(AlertListMode) {
|
|
@@ -22,110 +18,63 @@ var AlertListMode = /* @__PURE__ */ function(AlertListMode) {
|
|
|
22
18
|
AlertListMode["SHELVED"] = "shelved";
|
|
23
19
|
return AlertListMode;
|
|
24
20
|
}({});
|
|
25
|
-
var ObcAlertListPageSmall = class ObcAlertListPageSmall extends
|
|
21
|
+
var ObcAlertListPageSmall = class ObcAlertListPageSmall extends ObcAlertListPageSmallBase {
|
|
26
22
|
constructor(..._args) {
|
|
27
23
|
super(..._args);
|
|
28
|
-
this.hasShelved = false;
|
|
29
|
-
this.selectedMode = "all";
|
|
30
24
|
this.alerts = [];
|
|
31
|
-
this.
|
|
32
|
-
this.timeFormatter = (time) => time.toLocaleTimeString(void 0, { hour12: false });
|
|
25
|
+
this.selectedMode = "all";
|
|
33
26
|
this._mode = "all";
|
|
34
27
|
}
|
|
35
28
|
willUpdate(changedProperties) {
|
|
36
29
|
if (changedProperties.has("selectedMode") && this._mode !== this.selectedMode) this._mode = this.selectedMode;
|
|
37
30
|
}
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
31
|
+
get modes() {
|
|
32
|
+
const modes = [{
|
|
33
|
+
value: "all",
|
|
34
|
+
label: msg("All")
|
|
35
|
+
}, {
|
|
36
|
+
value: "unacked",
|
|
37
|
+
label: msg("Unacked")
|
|
38
|
+
}];
|
|
39
|
+
if (this.hasShelved) modes.push({
|
|
40
|
+
value: "shelved",
|
|
41
|
+
label: msg("Shelved")
|
|
42
|
+
});
|
|
43
|
+
return modes;
|
|
44
|
+
}
|
|
45
|
+
get mode() {
|
|
46
|
+
return this._mode;
|
|
47
|
+
}
|
|
48
|
+
selectMode(mode) {
|
|
49
|
+
this._mode = mode;
|
|
45
50
|
}
|
|
46
|
-
|
|
47
|
-
this._mode
|
|
51
|
+
get canAckAll() {
|
|
52
|
+
return this.alerts.some(canAckFilter(getAlertListModeData(this._mode).filter));
|
|
48
53
|
}
|
|
49
|
-
|
|
50
|
-
return
|
|
54
|
+
visibleAlerts() {
|
|
55
|
+
return this.alertList.getVisibleAlerts();
|
|
51
56
|
}
|
|
52
57
|
onAckClick(e) {
|
|
53
|
-
this.
|
|
58
|
+
this.dispatchAckClick(e.detail.alert);
|
|
54
59
|
}
|
|
55
60
|
onRowClick(e) {
|
|
56
|
-
this.
|
|
61
|
+
this.dispatchRowClick(e.detail.alert);
|
|
57
62
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
});
|
|
70
|
-
const metadata = this.metadata;
|
|
71
|
-
const canAckAll = this.alerts.some(canAckFilter(metadata.filter));
|
|
72
|
-
return html`
|
|
73
|
-
<div class="wrapper">
|
|
74
|
-
<obc-alert-list-details
|
|
75
|
-
class="alert-list"
|
|
76
|
-
.small=${true}
|
|
77
|
-
.alerts=${this.alerts}
|
|
78
|
-
.selectedMode=${this._mode}
|
|
79
|
-
.showTime=${this.showTime}
|
|
80
|
-
.timeFormatter=${this.timeFormatter}
|
|
81
|
-
@ack-click=${this.onAckClick}
|
|
82
|
-
@row-click=${this.onRowClick}
|
|
83
|
-
></obc-alert-list-details>
|
|
84
|
-
<div class="action">
|
|
85
|
-
<div class="btn-group">
|
|
86
|
-
<obc-dropdown-button
|
|
87
|
-
.value=${this._mode}
|
|
88
|
-
@change=${this.onModeSelect}
|
|
89
|
-
.options=${lists.map((v) => ({
|
|
90
|
-
value: v.name,
|
|
91
|
-
label: v.title
|
|
92
|
-
}))}
|
|
93
|
-
>
|
|
94
|
-
</obc-dropdown-button>
|
|
95
|
-
</div>
|
|
96
|
-
|
|
97
|
-
<div class="btn-group">
|
|
98
|
-
<obc-icon-button
|
|
99
|
-
variant="normal"
|
|
100
|
-
@click=${() => this.dispatchEvent(new CustomEvent("silence-click"))}
|
|
101
|
-
aria-label=${msg("Silence")}
|
|
102
|
-
>
|
|
103
|
-
<obi-silence-iec></obi-silence-iec>
|
|
104
|
-
</obc-icon-button>
|
|
105
|
-
<obc-button
|
|
106
|
-
.variant=${ButtonVariant.raised}
|
|
107
|
-
.disabled=${!canAckAll}
|
|
108
|
-
fullWidth
|
|
109
|
-
class="btn"
|
|
110
|
-
data-testid="ack-all-visible-button"
|
|
111
|
-
@click=${() => this.handleAckAllVisibleClick()}
|
|
112
|
-
>
|
|
113
|
-
${msg("ACK visible")}
|
|
114
|
-
</obc-button>
|
|
115
|
-
</div>
|
|
116
|
-
</div>
|
|
117
|
-
</div>
|
|
118
|
-
`;
|
|
119
|
-
}
|
|
120
|
-
static {
|
|
121
|
-
this.styles = unsafeCSS(alert_list_page_small_default);
|
|
63
|
+
renderList() {
|
|
64
|
+
return html`<obc-alert-list-details
|
|
65
|
+
class="alert-list"
|
|
66
|
+
.small=${true}
|
|
67
|
+
.alerts=${this.alerts}
|
|
68
|
+
.selectedMode=${this._mode}
|
|
69
|
+
.showTime=${this.showTime}
|
|
70
|
+
.timeFormatter=${this.timeFormatter}
|
|
71
|
+
@ack-click=${this.onAckClick}
|
|
72
|
+
@row-click=${this.onRowClick}
|
|
73
|
+
></obc-alert-list-details>`;
|
|
122
74
|
}
|
|
123
75
|
};
|
|
124
|
-
__decorate([property({ type: Boolean })], ObcAlertListPageSmall.prototype, "hasShelved", void 0);
|
|
125
|
-
__decorate([property({ type: String })], ObcAlertListPageSmall.prototype, "selectedMode", void 0);
|
|
126
76
|
__decorate([property({ type: Array })], ObcAlertListPageSmall.prototype, "alerts", void 0);
|
|
127
|
-
__decorate([property({ type:
|
|
128
|
-
__decorate([property({ attribute: false })], ObcAlertListPageSmall.prototype, "timeFormatter", void 0);
|
|
77
|
+
__decorate([property({ type: String })], ObcAlertListPageSmall.prototype, "selectedMode", void 0);
|
|
129
78
|
__decorate([state()], ObcAlertListPageSmall.prototype, "_mode", void 0);
|
|
130
79
|
__decorate([query("obc-alert-list-details")], ObcAlertListPageSmall.prototype, "alertList", void 0);
|
|
131
80
|
ObcAlertListPageSmall = __decorate([customElement("obc-alert-list-page-small")], ObcAlertListPageSmall);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"alert-list-page-small.js","names":[],"sources":["../../../src/pages/alert-list-page-small/alert-list-page-small.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"alert-list-page-small.js","names":[],"sources":["../../../src/pages/alert-list-page-small/alert-list-page-small.ts"],"sourcesContent":["import {PropertyValues, html} from 'lit';\nimport {customElement} from '../../decorator.js';\nimport {msg} from '@lit/localize';\nimport {property, query, state} from 'lit/decorators.js';\nimport {\n ObcAlertListPageSmallBase,\n type AlertListPageMode,\n} from './alert-list-page-small-base.js';\nimport '../../building-blocks/alert-list/alert-list.js';\nimport '../../icons/icon-alerts.js';\nimport '../../icons/icon-alerts-shelf.js';\nimport '../../icons/icon-unacknowledged.js';\nimport '../../icons/icon-alarm-noack-iec.js';\nimport '../../icons/icon-warning-noack-iec.js';\nimport {Alert} from '../../types.js';\nimport '../../components/alert-list-details/alert-list-details.js';\nimport {\n canAckFilter,\n getAlertListModeData,\n ObcAlertListDetails,\n} from '../../components/alert-list-details/alert-list-details.js';\n\nexport enum AlertListMode {\n UNACKED = 'unacked',\n ALL = 'all',\n SHELVED = 'shelved',\n}\n\nexport type ObcAlertListPageAckAllClickEvent = CustomEvent<{\n mode: AlertListMode;\n alerts: Alert[];\n}>;\n\nexport type ObcAckClickEvent = CustomEvent<{\n alert: Alert;\n}>;\n\nexport type ObcRowClickEvent = CustomEvent<{\n alert: Alert;\n}>;\n\n/**\n * @property alerts - Alerts to list.\n * @fires {ObcAlertListPageAckAllClickEvent} ack-all-visible-click - Fired when the user clicks the \"ACK visible\" button.\n * @fires {ObcAckClickEvent} ack-click - Fired when the user clicks the \"ACK\" button.\n * @fires {ObcRowClickEvent} row-click - Fired when the user clicks a row.\n * @fires {CustomEvent<void>} silence-click - Fired when the user clicks the \"Silence\" button.\n * @beta\n */\n@customElement('obc-alert-list-page-small')\nexport class ObcAlertListPageSmall extends ObcAlertListPageSmallBase {\n @property({type: Array}) alerts: Alert[] = [];\n @property({type: String}) selectedMode: AlertListMode = AlertListMode.ALL;\n\n @state() private _mode: AlertListMode = AlertListMode.ALL;\n\n @query('obc-alert-list-details')\n private alertList!: ObcAlertListDetails;\n\n override willUpdate(changedProperties: PropertyValues): void {\n if (\n changedProperties.has('selectedMode') &&\n this._mode !== this.selectedMode\n ) {\n this._mode = this.selectedMode;\n }\n }\n\n protected override get modes(): AlertListPageMode[] {\n const modes = [\n {value: AlertListMode.ALL, label: msg('All')},\n {value: AlertListMode.UNACKED, label: msg('Unacked')},\n ];\n if (this.hasShelved) {\n modes.push({value: AlertListMode.SHELVED, label: msg('Shelved')});\n }\n return modes;\n }\n\n protected override get mode(): AlertListMode {\n return this._mode;\n }\n\n protected override selectMode(mode: string) {\n this._mode = mode as AlertListMode;\n }\n\n protected override get canAckAll(): boolean {\n return this.alerts.some(\n canAckFilter(getAlertListModeData(this._mode).filter)\n );\n }\n\n protected override visibleAlerts(): Alert[] {\n return this.alertList.getVisibleAlerts();\n }\n\n private onAckClick(e: ObcAckClickEvent) {\n this.dispatchAckClick(e.detail.alert);\n }\n\n private onRowClick(e: ObcRowClickEvent) {\n this.dispatchRowClick(e.detail.alert);\n }\n\n protected override renderList() {\n return html`<obc-alert-list-details\n class=\"alert-list\"\n .small=${true}\n .alerts=${this.alerts}\n .selectedMode=${this._mode}\n .showTime=${this.showTime}\n .timeFormatter=${this.timeFormatter}\n @ack-click=${this.onAckClick}\n @row-click=${this.onRowClick}\n ></obc-alert-list-details>`;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'obc-alert-list-page-small': ObcAlertListPageSmall;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAsBA,IAAY,gBAAL,yBAAA,eAAA;CACL,cAAA,aAAA;CACA,cAAA,SAAA;CACA,cAAA,aAAA;;AACF,EAAA,CAAA,CAAA;AAwBO,IAAM,wBAAN,MAAM,8BAA8B,0BAA0B;;;EACxB,KAAA,SAAA,CAAC;;;;CAQ5C,WAAoB,mBAAyC;EAC3D,IACE,kBAAkB,IAAI,cAAc,KACpC,KAAK,UAAU,KAAK,cAEpB,KAAK,QAAQ,KAAK;CAEtB;CAEA,IAAuB,QAA6B;EAClD,MAAM,QAAQ,CACZ;GAAC,OAAA;GAA0B,OAAO,IAAI,KAAK;EAAC,GAC5C;GAAC,OAAA;GAA8B,OAAO,IAAI,SAAS;EAAC,CACtD;EACA,IAAI,KAAK,YACP,MAAM,KAAK;GAAC,OAAA;GAA8B,OAAO,IAAI,SAAS;EAAC,CAAC;EAElE,OAAO;CACT;CAEA,IAAuB,OAAsB;EAC3C,OAAO,KAAK;CACd;CAEA,WAA8B,MAAc;EAC1C,KAAK,QAAQ;CACf;CAEA,IAAuB,YAAqB;EAC1C,OAAO,KAAK,OAAO,KACjB,aAAa,qBAAqB,KAAK,KAAK,CAAC,CAAC,MAAM,CACtD;CACF;CAEA,gBAA4C;EAC1C,OAAO,KAAK,UAAU,iBAAiB;CACzC;CAEA,WAAmB,GAAqB;EACtC,KAAK,iBAAiB,EAAE,OAAO,KAAK;CACtC;CAEA,WAAmB,GAAqB;EACtC,KAAK,iBAAiB,EAAE,OAAO,KAAK;CACtC;CAEA,aAAgC;EAC9B,OAAO,IAAI;;eAEA,KAAK;gBACJ,KAAK,OAAO;sBACN,KAAK,MAAM;kBACf,KAAK,SAAS;uBACT,KAAK,cAAc;mBACvB,KAAK,WAAW;mBAChB,KAAK,WAAW;;CAEjC;AACF;AAlEG,WAAA,CAAA,SAAS,EAAC,MAAM,MAAK,CAAC,CAAA,GAAA,sBAAA,WAAA,UAAA,KAAA,CAAA;AACtB,WAAA,CAAA,SAAS,EAAC,MAAM,OAAM,CAAC,CAAA,GAAA,sBAAA,WAAA,gBAAA,KAAA,CAAA;AAEvB,WAAA,CAAA,MAAM,CAAA,GAAA,sBAAA,WAAA,SAAA,KAAA,CAAA;AAEN,WAAA,CAAA,MAAM,wBAAwB,CAAA,GAAA,sBAAA,WAAA,aAAA,KAAA,CAAA;AAPhC,wBAAA,WAAA,CAAA,cAAc,2BAA2B,CAAA,GAAA,qBAAA"}
|
package/docs/GettingStarted.mdx
CHANGED
package/docs/MigrationGuide.mdx
CHANGED
|
@@ -139,12 +139,14 @@ The package still loads no font. `bundle/NotoSans.ttf` is no longer published, s
|
|
|
139
139
|
@font-face {
|
|
140
140
|
font-family: 'Noto Sans';
|
|
141
141
|
src: url('/node_modules/@oicl/openbridge-webcomponents/bundle/NotoSans.ttf');
|
|
142
|
+
font-weight: 400 700;
|
|
142
143
|
}
|
|
143
144
|
|
|
144
145
|
/* 2.0 */
|
|
145
146
|
@font-face {
|
|
146
147
|
font-family: 'Noto Sans';
|
|
147
148
|
src: url('/node_modules/@oicl/openbridge-webcomponents/dist/NotoSans.ttf');
|
|
149
|
+
font-weight: 400 700;
|
|
148
150
|
}
|
|
149
151
|
```
|
|
150
152
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CSSResultGroup,
|
|
3
|
+
LitElement,
|
|
4
|
+
PropertyValues,
|
|
5
|
+
html,
|
|
6
|
+
nothing,
|
|
7
|
+
unsafeCSS,
|
|
8
|
+
} from 'lit';
|
|
9
|
+
import {queryAssignedElements, query, state} from 'lit/decorators.js';
|
|
10
|
+
import compentStyle from './alert-list.css?inline';
|
|
11
|
+
import '../../components/scrollbar/scrollbar.js';
|
|
12
|
+
import {ObcScrollbar} from '../../components/scrollbar/scrollbar.js';
|
|
13
|
+
import {ObcAlertMenuItem} from '../../components/alert-menu-item/alert-menu-item.js';
|
|
14
|
+
|
|
15
|
+
/** What an empty alert list shows where its `empty-*` slots are left unfilled. */
|
|
16
|
+
export interface AlertListEmptyFallback {
|
|
17
|
+
icon?: unknown;
|
|
18
|
+
title?: unknown;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* `ObcAlertListBase` – Scrolling list of slotted alert items that animates items
|
|
23
|
+
* into place and shows an empty state when no item passes its filter.
|
|
24
|
+
*
|
|
25
|
+
* Not registered as an element: the subclasses decide which items pass.
|
|
26
|
+
* `obc-alert-list` runs a predicate the consumer sets.
|
|
27
|
+
*
|
|
28
|
+
* ### Features
|
|
29
|
+
* - **Filter:** `matchesFilter()` decides which items count; the list re-reads
|
|
30
|
+
* it when items are added or removed, when an item attribute named by
|
|
31
|
+
* `observedItemAttributes` changes, and when `filterChanged()` reports a
|
|
32
|
+
* change of the subclass's filter inputs.
|
|
33
|
+
* - **Motion:** items that move slide to their new place; new items play
|
|
34
|
+
* their intro animation once the list has been seen.
|
|
35
|
+
* - **Empty state:** icon, title and description slots, with fallback content
|
|
36
|
+
* from `emptyFallback`.
|
|
37
|
+
* - **Visible items:** `getVisibleElements()` returns the items that pass the
|
|
38
|
+
* filter and sit inside the scroll viewport.
|
|
39
|
+
*/
|
|
40
|
+
export class ObcAlertListBase extends LitElement {
|
|
41
|
+
private oldElementTop: Map<HTMLElement, number> = new Map();
|
|
42
|
+
private mutationObserver: MutationObserver | null = null;
|
|
43
|
+
private intersectionObserver: IntersectionObserver | null = null;
|
|
44
|
+
private hasRenderedPanel = false;
|
|
45
|
+
@state() _empty = false;
|
|
46
|
+
|
|
47
|
+
@queryAssignedElements({flatten: true})
|
|
48
|
+
protected alertItems!: HTMLElement[];
|
|
49
|
+
|
|
50
|
+
@query('#scrollbar', true)
|
|
51
|
+
private scrollbar!: ObcScrollbar;
|
|
52
|
+
|
|
53
|
+
/** Whether the list counts an item as one it shows. */
|
|
54
|
+
protected matchesFilter(_item: HTMLElement): boolean {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Whether this update changed what `matchesFilter` decides. */
|
|
59
|
+
protected filterChanged(_changed: PropertyValues): boolean {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Item attributes whose changes can change what `matchesFilter` decides. */
|
|
64
|
+
protected get observedItemAttributes(): string[] {
|
|
65
|
+
return ['status', 'shelved'];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
protected get emptyFallback(): AlertListEmptyFallback {
|
|
69
|
+
return {};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
override firstUpdated() {
|
|
73
|
+
this.applyFilter();
|
|
74
|
+
this.setupMutationObserver();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
override connectedCallback() {
|
|
78
|
+
super.connectedCallback();
|
|
79
|
+
const intersectionObserver = new IntersectionObserver((entries) => {
|
|
80
|
+
// If intersectionRatio is 0, the target is out of view
|
|
81
|
+
if (entries[0].intersectionRatio === 0) {
|
|
82
|
+
this.hasRenderedPanel = false;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
intersectionObserver.observe(this);
|
|
86
|
+
this.intersectionObserver = intersectionObserver;
|
|
87
|
+
|
|
88
|
+
this.setupMutationObserver();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
override disconnectedCallback() {
|
|
92
|
+
super.disconnectedCallback();
|
|
93
|
+
if (this.mutationObserver) {
|
|
94
|
+
this.mutationObserver.disconnect();
|
|
95
|
+
this.mutationObserver = null;
|
|
96
|
+
}
|
|
97
|
+
if (this.intersectionObserver) {
|
|
98
|
+
this.intersectionObserver.disconnect();
|
|
99
|
+
this.intersectionObserver = null;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
protected override willUpdate(_changedProperties: PropertyValues): void {
|
|
104
|
+
if (this.filterChanged(_changedProperties)) {
|
|
105
|
+
this.applyFilter();
|
|
106
|
+
this.updateOldElementTop();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Runs whenever the items or the filter change; a subclass extends it to act on each item. */
|
|
111
|
+
protected applyFilter() {
|
|
112
|
+
this._empty = this.getAlertItems().length === 0;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
private getAlertItems() {
|
|
116
|
+
return this.alertItems.filter((item) => this.matchesFilter(item));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
private updateOldElementTop() {
|
|
120
|
+
const elements = this.getAlertItems();
|
|
121
|
+
if (elements.length === 0) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Get the top of the element,
|
|
126
|
+
// the element may be in an animation
|
|
127
|
+
// we therefor sum the height of each element
|
|
128
|
+
const firstElement = elements[0];
|
|
129
|
+
const firstElementRect = firstElement.getBoundingClientRect();
|
|
130
|
+
let top = firstElementRect.top;
|
|
131
|
+
this.oldElementTop.clear();
|
|
132
|
+
elements.forEach((element) => {
|
|
133
|
+
const elementRect = element.getBoundingClientRect();
|
|
134
|
+
if (elementRect.height === 0) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
this.oldElementTop.set(element, top);
|
|
138
|
+
top += elementRect.height;
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
private setupMutationObserver() {
|
|
143
|
+
if (this.mutationObserver) {
|
|
144
|
+
// Make a new observer to avoid memory leaks
|
|
145
|
+
this.mutationObserver.disconnect();
|
|
146
|
+
this.mutationObserver = null;
|
|
147
|
+
}
|
|
148
|
+
this.mutationObserver = new MutationObserver(() => {
|
|
149
|
+
this.handleElementsChange();
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
const slotElements = this.alertItems;
|
|
153
|
+
slotElements.forEach((element) => {
|
|
154
|
+
// Earlier observed elements are just updated, and not registered twice.
|
|
155
|
+
this.mutationObserver?.observe(element, {
|
|
156
|
+
attributes: true,
|
|
157
|
+
attributeFilter: this.observedItemAttributes,
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
private handleSlotChange() {
|
|
163
|
+
this.handleElementsChange();
|
|
164
|
+
this.setupMutationObserver();
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
private handleElementsChange() {
|
|
168
|
+
// Take records to ensure the observer is not triggered again
|
|
169
|
+
this.mutationObserver?.takeRecords();
|
|
170
|
+
this.applyFilter();
|
|
171
|
+
if (!this.checkVisibility()) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const elements = this.getAlertItems();
|
|
176
|
+
// Animate the elements to their new positions
|
|
177
|
+
const oldElementTop: Map<HTMLElement, number> = new Map(this.oldElementTop);
|
|
178
|
+
|
|
179
|
+
requestAnimationFrame(() => {
|
|
180
|
+
this.updateOldElementTop();
|
|
181
|
+
let hasNewElements = false;
|
|
182
|
+
elements.forEach((element) => {
|
|
183
|
+
const elementRect = element.getBoundingClientRect();
|
|
184
|
+
const oldTop = oldElementTop.get(element);
|
|
185
|
+
if (oldTop === undefined) {
|
|
186
|
+
// New element
|
|
187
|
+
(element as ObcAlertMenuItem).animateIntro = this.hasRenderedPanel;
|
|
188
|
+
hasNewElements = true;
|
|
189
|
+
setTimeout(() => {
|
|
190
|
+
(element as ObcAlertMenuItem).animateIntro = false;
|
|
191
|
+
}, 101);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
const diff = oldTop - elementRect.top;
|
|
195
|
+
if (diff === 0) return;
|
|
196
|
+
element.style.transform = `translateY(${diff}px)`;
|
|
197
|
+
element.style.transition = 'none';
|
|
198
|
+
|
|
199
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions -- the read forces the reflow that restarts the transition
|
|
200
|
+
element.offsetHeight;
|
|
201
|
+
|
|
202
|
+
// Remove the transition after the animation is complete
|
|
203
|
+
element.style.transition = 'transform 100ms ease-in-out';
|
|
204
|
+
element.style.transform = 'translateY(0px)';
|
|
205
|
+
});
|
|
206
|
+
this.hasRenderedPanel = true;
|
|
207
|
+
if (hasNewElements) {
|
|
208
|
+
setTimeout(() => {
|
|
209
|
+
this.updateOldElementTop();
|
|
210
|
+
}, 101);
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
public getVisibleElements(): {element: HTMLElement; index: number}[] {
|
|
216
|
+
// Get all slotted elements in the visible tab's scrollbar
|
|
217
|
+
|
|
218
|
+
const scrollbarRect = this.scrollbar.getBoundingClientRect();
|
|
219
|
+
const slottedElements = this.getAlertItems();
|
|
220
|
+
|
|
221
|
+
// Filter for only visible elements that are within the scrollbar viewport
|
|
222
|
+
return slottedElements
|
|
223
|
+
.map((element, index) => ({element, index}))
|
|
224
|
+
.filter(({element}) => {
|
|
225
|
+
const style = window.getComputedStyle(element);
|
|
226
|
+
if (style.display === 'none' || style.visibility === 'hidden') {
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// Check if the element is within the scrollbar's viewport
|
|
231
|
+
const elementRect = element.getBoundingClientRect();
|
|
232
|
+
|
|
233
|
+
// Check if element overlaps with scrollbar viewport
|
|
234
|
+
const isVisible = !(
|
|
235
|
+
elementRect.top < scrollbarRect.top ||
|
|
236
|
+
elementRect.bottom > scrollbarRect.bottom
|
|
237
|
+
);
|
|
238
|
+
|
|
239
|
+
return isVisible;
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
override render() {
|
|
244
|
+
const fallback = this.emptyFallback;
|
|
245
|
+
return html` <obc-scrollbar class="alert-list" id="scrollbar">
|
|
246
|
+
<slot @slotchange=${this.handleSlotChange}></slot>
|
|
247
|
+
${
|
|
248
|
+
this._empty
|
|
249
|
+
? html` <div class="empty-list">
|
|
250
|
+
<div class="icon">
|
|
251
|
+
<slot name="empty-icon">${fallback.icon}</slot>
|
|
252
|
+
</div>
|
|
253
|
+
<div class="empty-title">
|
|
254
|
+
<slot name="empty-title">${fallback.title}</slot>
|
|
255
|
+
</div>
|
|
256
|
+
<div class="empty-description">
|
|
257
|
+
<slot name="empty-description"></slot>
|
|
258
|
+
</div>
|
|
259
|
+
</div>`
|
|
260
|
+
: nothing
|
|
261
|
+
}
|
|
262
|
+
</obc-scrollbar>`;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
static override styles: CSSResultGroup = unsafeCSS(compentStyle);
|
|
266
|
+
}
|
|
@@ -11,29 +11,7 @@
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
.empty-list {
|
|
14
|
-
|
|
15
|
-
flex-direction: column;
|
|
16
|
-
align-items: center;
|
|
17
|
-
justify-content: center;
|
|
18
|
-
height: 100%;
|
|
19
|
-
gap: var(--app-components-alert-menu-button-spacing);
|
|
20
|
-
|
|
21
|
-
.icon {
|
|
22
|
-
height: 96px;
|
|
23
|
-
width: 96px;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
.empty-title {
|
|
27
|
-
color: var(--element-active-color);
|
|
28
|
-
@mixin font-body-active;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
.empty-description {
|
|
32
|
-
color: var(--element-neutral-color);
|
|
33
|
-
@mixin font-body;
|
|
34
|
-
max-width: 344px;
|
|
35
|
-
text-align: center;
|
|
36
|
-
}
|
|
14
|
+
@mixin alert-list-empty;
|
|
37
15
|
}
|
|
38
16
|
|
|
39
17
|
::slotted(*) {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {describe, expect, it} from 'vitest';
|
|
2
|
+
import {render} from 'vitest-browser-lit';
|
|
3
|
+
import {html} from 'lit';
|
|
4
|
+
import './alert-list.js';
|
|
5
|
+
import type {ObcAlertList} from './alert-list.js';
|
|
6
|
+
|
|
7
|
+
describe('obc-alert-list', () => {
|
|
8
|
+
it('tells its controllers when it is removed, as well as when it is added', async () => {
|
|
9
|
+
const screen = render(html`<obc-alert-list></obc-alert-list>`);
|
|
10
|
+
const el = screen.container.querySelector('obc-alert-list') as ObcAlertList;
|
|
11
|
+
await el.updateComplete;
|
|
12
|
+
const calls: string[] = [];
|
|
13
|
+
el.addController({
|
|
14
|
+
hostConnected: () => calls.push('connected'),
|
|
15
|
+
hostDisconnected: () => calls.push('disconnected'),
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
el.remove();
|
|
19
|
+
screen.container.append(el);
|
|
20
|
+
expect(calls).toEqual(['connected', 'disconnected', 'connected']);
|
|
21
|
+
});
|
|
22
|
+
});
|