@oicl/openbridge-webcomponents-full-bundle 2.1.0-next.1 → 2.1.0-next.3
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 +390 -301
- package/bundle/openbridge-webcomponents.bundle.js.map +1 -1
- package/custom-elements.json +1066 -102
- package/dist/automation/valve-analoge-two-way-icon/valve-analog-two-way-icon.d.ts +21 -0
- package/dist/automation/valve-analoge-two-way-icon/valve-analog-two-way-icon.d.ts.map +1 -1
- package/dist/automation/valve-analoge-two-way-icon/valve-analog-two-way-icon.js +39 -58
- package/dist/automation/valve-analoge-two-way-icon/valve-analog-two-way-icon.js.map +1 -1
- 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/automation/valve-analoge-two-way-icon/valve-analog-two-way-icon.stories.ts +63 -0
- package/src/automation/valve-analoge-two-way-icon/valve-analog-two-way-icon.ts +58 -60
- 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
|
@@ -2,10 +2,35 @@ import {LitElement, html, svg, unsafeCSS} from 'lit';
|
|
|
2
2
|
import {property} from 'lit/decorators.js';
|
|
3
3
|
import compentStyle from './valve-analog-two-way-icon.css?inline';
|
|
4
4
|
import {customElement} from '../../decorator.js';
|
|
5
|
+
import {clampPercent} from '../../svghelpers/math.js';
|
|
5
6
|
import '../../icons/icon-twoway-analog-closed.js';
|
|
6
7
|
|
|
8
|
+
const OUTLINE =
|
|
9
|
+
'M11 11L3.5547 6.03645C2.89015 5.59342 2 6.06981 2 6.8685V19.1315C2 19.9302 2.89015 20.4066 3.5547 19.9635L11 15H13L20.4453 19.9635C21.1099 20.4066 22 19.9302 22 19.1315V6.8685C22 6.06981 21.1099 5.59342 20.4453 6.03645L13 11H11ZM3 6.8685L3 19.1315L10.6972 14H13.3028L21 19.1315V6.8685L13.3028 12H10.6972L3 6.8685Z';
|
|
10
|
+
const BODY =
|
|
11
|
+
'M10.6972 12H13.3028L21 6.8685V19.1315L13.3028 14H10.6972L3 19.1315V6.8685L10.6972 12Z';
|
|
12
|
+
|
|
13
|
+
/** Width of the shut band at each port end when the opening is 0 %, in icon units. */
|
|
14
|
+
const BAND_RANGE = 7;
|
|
15
|
+
|
|
16
|
+
const SECONDARY = 'fill: var(--automation-device-secondary-color)';
|
|
17
|
+
const TERTIARY = 'fill: var(--automation-device-tertiary-color)';
|
|
18
|
+
const PRIMARY = 'fill: var(--automation-device-primary-color)';
|
|
19
|
+
|
|
7
20
|
/**
|
|
21
|
+
* Two-way analog valve symbol whose opening moves continuously from 0 to
|
|
22
|
+
* 100 %.
|
|
23
|
+
*
|
|
24
|
+
* Draws the same symbol as the `obi-twoway-analog-*` icons. The shut bands at
|
|
25
|
+
* the port ends and the handle are linear in the opening: exact at 100 %
|
|
26
|
+
* (`obi-twoway-analog-open`) and at 0 % (vertical handle, ports shut to the
|
|
27
|
+
* centre), and close to the icons' 10/25/50/75 % steps in between. Used as
|
|
28
|
+
* the icon of `obc-analog-valve`.
|
|
29
|
+
*
|
|
30
|
+
* @property value - Opening in percent (0–100).
|
|
8
31
|
* @availableWhen value closed==false
|
|
32
|
+
* @property closed - Shows the closed symbol.
|
|
33
|
+
* @property vertical - Turns the symbol 90° for a vertical pipe.
|
|
9
34
|
* @stable
|
|
10
35
|
*/
|
|
11
36
|
@customElement('obc-valve-analog-two-way-icon')
|
|
@@ -14,6 +39,33 @@ export class ObcValveAnalogTwoWayIcon extends LitElement {
|
|
|
14
39
|
@property({type: Boolean}) closed: boolean = false;
|
|
15
40
|
@property({type: Boolean}) vertical: boolean = false;
|
|
16
41
|
|
|
42
|
+
private renderBands(width: number) {
|
|
43
|
+
if (width <= 0) return null;
|
|
44
|
+
const left = 3 + width;
|
|
45
|
+
const right = 21 - width;
|
|
46
|
+
return svg`<g clip-path="url(#body)">
|
|
47
|
+
<rect x="2" y="0" width=${left - 2} height="24" style=${SECONDARY}/>
|
|
48
|
+
<rect x=${left} y="0" width="1" height="24" style=${TERTIARY}/>
|
|
49
|
+
<rect x=${right} y="0" width=${22 - right} height="24" style=${SECONDARY}/>
|
|
50
|
+
<rect x=${right - 1} y="0" width="1" height="24" style=${TERTIARY}/>
|
|
51
|
+
</g>`;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Horizontal at the top when open, turning to vertical and moving 2 units
|
|
56
|
+
* down as the valve shuts, matching `obi-twoway-analog-open` at 100 %.
|
|
57
|
+
*/
|
|
58
|
+
private renderHandle(value: number) {
|
|
59
|
+
const shut = 1 - value / 100;
|
|
60
|
+
const angle = -90 * shut;
|
|
61
|
+
const cx = 12;
|
|
62
|
+
const cy = 3.5 + 2 * shut;
|
|
63
|
+
return svg`<g transform="rotate(${angle} ${cx} ${cy})">
|
|
64
|
+
<rect x=${cx - 4} y=${cy - 1.5} width="8" height="3" rx="1.5" style=${TERTIARY}/>
|
|
65
|
+
<rect x=${cx - 3} y=${cy - 0.5} width="6" height="1" rx="0.5" style=${PRIMARY}/>
|
|
66
|
+
</g>`;
|
|
67
|
+
}
|
|
68
|
+
|
|
17
69
|
override render() {
|
|
18
70
|
const transform = this.vertical ? 'transform: rotate(90deg);' : '';
|
|
19
71
|
if (this.closed) {
|
|
@@ -22,19 +74,7 @@ export class ObcValveAnalogTwoWayIcon extends LitElement {
|
|
|
22
74
|
</div>`;
|
|
23
75
|
}
|
|
24
76
|
|
|
25
|
-
const
|
|
26
|
-
const handleTranslation = (1 - this.value / 100) * 2;
|
|
27
|
-
const handle = svg`
|
|
28
|
-
<g transform="translate(0, ${handleTranslation}) rotate(${handleRotation} 12 3.5) ">
|
|
29
|
-
<path fill-rule="evenodd" clip-rule="evenodd" d="M9.5 5H14.5C15.3284 5 16 4.32843 16 3.5C16 2.67157 15.3284 2 14.5 2H9.5C8.67157 2 8 2.67157 8 3.5C8 4.32843 8.67157 5 9.5 5ZM9.5 4L14.5 4C14.7761 4 15 3.77614 15 3.5C15 3.22386 14.7761 3 14.5 3L9.5 3C9.22386 3 9 3.22386 9 3.5C9 3.77614 9.22386 4 9.5 4Z" fill="var(--automation-device-tertiary-color)"/>
|
|
30
|
-
<path d="M9.5 4L14.5 4C14.7761 4 15 3.77614 15 3.5C15 3.22386 14.7761 3 14.5 3L9.5 3C9.22386 3 9 3.22386 9 3.5C9 3.77614 9.22386 4 9.5 4Z" fill="var(--automation-device-primary-color)"/>
|
|
31
|
-
</g>
|
|
32
|
-
`;
|
|
33
|
-
|
|
34
|
-
const xmin = 10.5;
|
|
35
|
-
const xmax = 2.5;
|
|
36
|
-
const x = xmin + ((xmax - xmin) * this.value) / 100;
|
|
37
|
-
|
|
77
|
+
const value = clampPercent(this.value);
|
|
38
78
|
return html`
|
|
39
79
|
<div class="wrapper" style="${transform}">
|
|
40
80
|
<svg
|
|
@@ -44,55 +84,13 @@ export class ObcValveAnalogTwoWayIcon extends LitElement {
|
|
|
44
84
|
fill="none"
|
|
45
85
|
xmlns="http://www.w3.org/2000/svg"
|
|
46
86
|
>
|
|
47
|
-
<path
|
|
48
|
-
d="M11 11L3.5547 6.03645C2.89015 5.59342 2 6.06981 2 6.8685V19.1315C2 19.9302 2.89015 20.4066 3.5547 19.9635L11 15H13L20.4453 19.9635C21.1099 20.4066 22 19.9302 22 19.1315V6.8685C22 6.06981 21.1099 5.59342 20.4453 6.03645L13 11H11ZM3 6.8685L3 19.1315L10.6972 14H13.3028L21 19.1315V6.8685L13.3028 12H10.6972L3 6.8685Z"
|
|
49
|
-
fill="var(--automation-device-tertiary-color)"
|
|
50
|
-
/>
|
|
51
|
-
<path
|
|
52
|
-
d="M10.6972 12H13.3028L21 6.8685V19.1315L13.3028 14H10.6972L3 19.1315V6.8685L10.6972 12Z"
|
|
53
|
-
fill="var(--automation-device-primary-color)"
|
|
54
|
-
/>
|
|
55
|
-
${handle}
|
|
56
|
-
<g clip-path="url(#clip0)">
|
|
57
|
-
<rect
|
|
58
|
-
x=${xmax}
|
|
59
|
-
y="0"
|
|
60
|
-
width=${x - xmax}
|
|
61
|
-
height="24"
|
|
62
|
-
fill="var(--automation-device-secondary-color)"
|
|
63
|
-
/>
|
|
64
|
-
<line
|
|
65
|
-
x1=${x}
|
|
66
|
-
y1="0"
|
|
67
|
-
x2=${x}
|
|
68
|
-
y2="24"
|
|
69
|
-
stroke="var(--automation-device-tertiary-color)"
|
|
70
|
-
stroke-width="1"
|
|
71
|
-
/>
|
|
72
|
-
|
|
73
|
-
<rect
|
|
74
|
-
x=${24 - x}
|
|
75
|
-
y="0"
|
|
76
|
-
width=${x - xmax}
|
|
77
|
-
height="24"
|
|
78
|
-
fill="var(--automation-device-secondary-color)"
|
|
79
|
-
/>
|
|
80
|
-
<line
|
|
81
|
-
x1=${24 - x}
|
|
82
|
-
y1="0"
|
|
83
|
-
x2=${24 - x}
|
|
84
|
-
y2="24"
|
|
85
|
-
stroke="var(--automation-device-tertiary-color)"
|
|
86
|
-
stroke-width="1"
|
|
87
|
-
/>
|
|
88
|
-
</g>
|
|
89
87
|
<defs>
|
|
90
|
-
<clipPath id="
|
|
91
|
-
<path
|
|
92
|
-
d="M10.6972 12H13.3028L21 6.8685V19.1315L13.3028 14H10.6972L3 19.1315V6.8685L10.6972 12Z"
|
|
93
|
-
/>
|
|
94
|
-
</clipPath>
|
|
88
|
+
<clipPath id="body"><path d=${BODY} /></clipPath>
|
|
95
89
|
</defs>
|
|
90
|
+
<path d=${OUTLINE} style=${TERTIARY} />
|
|
91
|
+
<path d=${BODY} style=${PRIMARY} />
|
|
92
|
+
${this.renderBands((BAND_RANGE * (100 - value)) / 100)}
|
|
93
|
+
${this.renderHandle(value)}
|
|
96
94
|
</svg>
|
|
97
95
|
</div>
|
|
98
96
|
`;
|
|
@@ -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
|
+
});
|