@oicl/openbridge-webcomponents-full-bundle 2.0.0-next.170 → 2.0.0-next.171
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 +870 -441
- package/bundle/openbridge-webcomponents.bundle.js.map +1 -1
- package/custom-elements.json +1110 -383
- package/dist/ar/poi/poi-aton.d.ts +1 -0
- package/dist/ar/poi/poi-aton.d.ts.map +1 -1
- package/dist/ar/poi/poi-aton.js +1 -0
- package/dist/ar/poi/poi-aton.js.map +1 -1
- package/dist/ar/poi/poi-base.d.ts +39 -5
- package/dist/ar/poi/poi-base.d.ts.map +1 -1
- package/dist/ar/poi/poi-base.js +108 -37
- package/dist/ar/poi/poi-base.js.map +1 -1
- package/dist/ar/poi/poi-data.d.ts +1 -0
- package/dist/ar/poi/poi-data.d.ts.map +1 -1
- package/dist/ar/poi/poi-data.js +1 -0
- package/dist/ar/poi/poi-data.js.map +1 -1
- package/dist/ar/poi/poi-vessel.d.ts +1 -0
- package/dist/ar/poi/poi-vessel.d.ts.map +1 -1
- package/dist/ar/poi/poi-vessel.js +1 -0
- package/dist/ar/poi/poi-vessel.js.map +1 -1
- package/dist/ar/poi/poi.d.ts +4 -12
- package/dist/ar/poi/poi.d.ts.map +1 -1
- package/dist/ar/poi/poi.js +6 -72
- package/dist/ar/poi/poi.js.map +1 -1
- package/dist/ar/poi-button/poi-button.d.ts +6 -2
- package/dist/ar/poi-button/poi-button.d.ts.map +1 -1
- package/dist/ar/poi-button/poi-button.js +10 -1
- package/dist/ar/poi-button/poi-button.js.map +1 -1
- package/dist/ar/poi-card/poi-card.d.ts +12 -1
- package/dist/ar/poi-card/poi-card.d.ts.map +1 -1
- package/dist/ar/poi-card/poi-card.js +4 -1
- package/dist/ar/poi-card/poi-card.js.map +1 -1
- package/dist/ar/poi-controller/poi-controller.d.ts +45 -1
- package/dist/ar/poi-controller/poi-controller.d.ts.map +1 -1
- package/dist/ar/poi-controller/poi-controller.js +72 -14
- package/dist/ar/poi-controller/poi-controller.js.map +1 -1
- package/dist/ar/poi-group/poi-group.d.ts +28 -5
- package/dist/ar/poi-group/poi-group.d.ts.map +1 -1
- package/dist/ar/poi-group/poi-group.js +50 -7
- package/dist/ar/poi-group/poi-group.js.map +1 -1
- package/dist/ar/poi-layer/poi-layer.css.js +69 -18
- package/dist/ar/poi-layer/poi-layer.css.js.map +1 -1
- package/dist/ar/poi-layer/poi-layer.d.ts +64 -5
- package/dist/ar/poi-layer/poi-layer.d.ts.map +1 -1
- package/dist/ar/poi-layer/poi-layer.js +173 -39
- package/dist/ar/poi-layer/poi-layer.js.map +1 -1
- package/dist/ar/poi-layer-stack/poi-layer-stack.d.ts +82 -7
- package/dist/ar/poi-layer-stack/poi-layer-stack.d.ts.map +1 -1
- package/dist/ar/poi-layer-stack/poi-layer-stack.js +172 -100
- package/dist/ar/poi-layer-stack/poi-layer-stack.js.map +1 -1
- package/dist/ar/poi-projection/poi-projection.d.ts +88 -0
- package/dist/ar/poi-projection/poi-projection.d.ts.map +1 -0
- package/dist/ar/poi-projection/poi-projection.js +90 -0
- package/dist/ar/poi-projection/poi-projection.js.map +1 -0
- package/docs/MigrationGuide.mdx +61 -5
- package/docs/migration-guide/a11y-labels.md +8 -0
- package/docs/migration-guide/api-automation.md +1 -0
- package/package.json +2 -2
- package/src/ar/_test-utils.ts +18 -6
- package/src/ar/poi/poi-aton.ts +2 -0
- package/src/ar/poi/poi-base.ts +159 -70
- package/src/ar/poi/poi-data.ts +2 -0
- package/src/ar/poi/poi-dom-ownership.spec.ts +393 -0
- package/src/ar/poi/poi-vessel.ts +2 -0
- package/src/ar/poi/poi.ts +12 -113
- package/src/ar/poi-button/poi-button.ts +25 -3
- package/src/ar/poi-card/poi-card.ts +16 -2
- package/src/ar/poi-controller/poi-controller.spec.ts +54 -0
- package/src/ar/poi-controller/poi-controller.stories.ts +76 -24
- package/src/ar/poi-controller/poi-controller.ts +111 -41
- package/src/ar/poi-group/poi-group.stories.ts +18 -5
- package/src/ar/poi-group/poi-group.ts +87 -12
- package/src/ar/poi-layer/poi-layer.css +69 -18
- package/src/ar/poi-layer/poi-layer.stories.ts +30 -16
- package/src/ar/poi-layer/poi-layer.ts +289 -64
- package/src/ar/poi-layer-stack/poi-layer-stack.stories.ts +56 -23
- package/src/ar/poi-layer-stack/poi-layer-stack.ts +342 -247
- package/src/ar/poi-projection/poi-projection.stories.ts +100 -0
- package/src/ar/poi-projection/poi-projection.ts +147 -0
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
import {afterEach, describe, expect, it} from 'vitest';
|
|
2
|
+
import './poi.js';
|
|
3
|
+
import './poi-data.js';
|
|
4
|
+
import '../poi-layer/poi-layer.js';
|
|
5
|
+
import '../poi-layer-stack/poi-layer-stack.js';
|
|
6
|
+
import '../building-blocks/poi-header/poi-header.js';
|
|
7
|
+
import type {ObcPoi} from './poi.js';
|
|
8
|
+
import type {ObcPoiData} from './poi-data.js';
|
|
9
|
+
import type {ObcPoiLayer} from '../poi-layer/poi-layer.js';
|
|
10
|
+
import type {ObcPoiLayerStack} from '../poi-layer-stack/poi-layer-stack.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* DOM-ownership contract: POI components must never move, create, or remove
|
|
14
|
+
* nodes in the consumer's light DOM. These tests pin the header slot
|
|
15
|
+
* forwarding chain (and, via the layer/stack specs, grouping and selection)
|
|
16
|
+
* to slot assignment instead of physical re-parenting.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
const nextFrame = () =>
|
|
20
|
+
new Promise<void>((resolve) => requestAnimationFrame(() => resolve()));
|
|
21
|
+
|
|
22
|
+
async function settle(...elements: Array<{updateComplete: Promise<unknown>}>) {
|
|
23
|
+
for (const el of elements) {
|
|
24
|
+
await el.updateComplete;
|
|
25
|
+
}
|
|
26
|
+
await nextFrame();
|
|
27
|
+
await nextFrame();
|
|
28
|
+
for (const el of elements) {
|
|
29
|
+
await el.updateComplete;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function mount(html: string): HTMLElement {
|
|
34
|
+
const host = document.createElement('div');
|
|
35
|
+
host.innerHTML = html;
|
|
36
|
+
document.body.appendChild(host);
|
|
37
|
+
return host;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
afterEach(() => {
|
|
41
|
+
document.body.innerHTML = '';
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe('obc-poi header ownership', () => {
|
|
45
|
+
it('keeps a slotted header in the consumer light DOM', async () => {
|
|
46
|
+
const host = mount(`
|
|
47
|
+
<obc-poi has-header>
|
|
48
|
+
<obc-poi-header slot="header" content="1" state="selected"></obc-poi-header>
|
|
49
|
+
<span>icon</span>
|
|
50
|
+
</obc-poi>
|
|
51
|
+
`);
|
|
52
|
+
const poi = host.querySelector('obc-poi') as ObcPoi;
|
|
53
|
+
const header = host.querySelector('obc-poi-header') as HTMLElement;
|
|
54
|
+
await settle(poi);
|
|
55
|
+
|
|
56
|
+
expect(header.parentElement).toBe(poi);
|
|
57
|
+
expect(header.assignedSlot).not.toBeNull();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('renders the header through the slot chain into the button shadow', async () => {
|
|
61
|
+
const host = mount(`
|
|
62
|
+
<obc-poi has-header>
|
|
63
|
+
<obc-poi-header slot="header" content="1" state="selected"></obc-poi-header>
|
|
64
|
+
</obc-poi>
|
|
65
|
+
`);
|
|
66
|
+
const poi = host.querySelector('obc-poi') as ObcPoi;
|
|
67
|
+
const header = host.querySelector('obc-poi-header') as HTMLElement;
|
|
68
|
+
await settle(poi);
|
|
69
|
+
|
|
70
|
+
const button = poi.shadowRoot?.querySelector('obc-poi-button');
|
|
71
|
+
expect(button).not.toBeNull();
|
|
72
|
+
const headerSlot = button?.shadowRoot?.querySelector(
|
|
73
|
+
'slot[name="header"]'
|
|
74
|
+
) as HTMLSlotElement | null;
|
|
75
|
+
expect(headerSlot).not.toBeNull();
|
|
76
|
+
const flattened = headerSlot?.assignedElements({flatten: true}) ?? [];
|
|
77
|
+
expect(flattened).toContain(header);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('syncs header state from the button without moving the node', async () => {
|
|
81
|
+
const host = mount(`
|
|
82
|
+
<obc-poi has-header>
|
|
83
|
+
<obc-poi-header slot="header" content="1"></obc-poi-header>
|
|
84
|
+
</obc-poi>
|
|
85
|
+
`);
|
|
86
|
+
const poi = host.querySelector('obc-poi') as ObcPoi;
|
|
87
|
+
const header = host.querySelector('obc-poi-header') as HTMLElement;
|
|
88
|
+
await settle(poi);
|
|
89
|
+
|
|
90
|
+
expect(header.getAttribute('state')).toBe('selected');
|
|
91
|
+
expect(header.parentElement).toBe(poi);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('renders a header added after the first render', async () => {
|
|
95
|
+
const host = mount(`<obc-poi has-header></obc-poi>`);
|
|
96
|
+
const poi = host.querySelector('obc-poi') as ObcPoi;
|
|
97
|
+
await settle(poi);
|
|
98
|
+
const button = poi.shadowRoot?.querySelector('obc-poi-button');
|
|
99
|
+
const slotBefore = button?.shadowRoot?.querySelector('slot[name="header"]');
|
|
100
|
+
expect(slotBefore).toBeNull();
|
|
101
|
+
|
|
102
|
+
// The forwarding slot sits in obc-poi's shadow tree, so the button only
|
|
103
|
+
// learns about the new header from the slotchange that bubbles to it.
|
|
104
|
+
const header = document.createElement('obc-poi-header');
|
|
105
|
+
header.setAttribute('slot', 'header');
|
|
106
|
+
header.setAttribute('content', '2');
|
|
107
|
+
poi.appendChild(header);
|
|
108
|
+
await settle(poi);
|
|
109
|
+
|
|
110
|
+
const headerSlot = button?.shadowRoot?.querySelector(
|
|
111
|
+
'slot[name="header"]'
|
|
112
|
+
) as HTMLSlotElement | null;
|
|
113
|
+
expect(headerSlot?.assignedElements({flatten: true})).toContain(header);
|
|
114
|
+
expect(header.getAttribute('state')).toBe('selected');
|
|
115
|
+
expect(header.parentElement).toBe(poi);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
describe('obc-poi-data header ownership', () => {
|
|
120
|
+
it('keeps a slotted header in the consumer light DOM and renders it', async () => {
|
|
121
|
+
const host = mount(`
|
|
122
|
+
<obc-poi-data x="100" y="96">
|
|
123
|
+
<obc-poi-header slot="header" content="7"></obc-poi-header>
|
|
124
|
+
</obc-poi-data>
|
|
125
|
+
`);
|
|
126
|
+
const target = host.querySelector('obc-poi-data') as ObcPoiData;
|
|
127
|
+
const header = host.querySelector('obc-poi-header') as HTMLElement;
|
|
128
|
+
await settle(target);
|
|
129
|
+
|
|
130
|
+
expect(header.parentElement).toBe(target);
|
|
131
|
+
expect(target.hasHeader).toBe(true);
|
|
132
|
+
|
|
133
|
+
const innerButton = target.shadowRoot?.querySelector(
|
|
134
|
+
'obc-poi-button-data'
|
|
135
|
+
) as HTMLElement | null;
|
|
136
|
+
expect(innerButton).not.toBeNull();
|
|
137
|
+
const headerSlot = innerButton?.shadowRoot?.querySelector(
|
|
138
|
+
'slot[name="header"]'
|
|
139
|
+
) as HTMLSlotElement | null;
|
|
140
|
+
expect(headerSlot).not.toBeNull();
|
|
141
|
+
const flattened = headerSlot?.assignedElements({flatten: true}) ?? [];
|
|
142
|
+
expect(flattened).toContain(header);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('selection never re-parents targets between layers', async () => {
|
|
146
|
+
const host = mount(`
|
|
147
|
+
<obc-poi-layer-stack selection-mode="single" style="width: 640px">
|
|
148
|
+
<obc-poi-layer id="sel" is-selected style="--obc-poi-layer-min-height: 96px"></obc-poi-layer>
|
|
149
|
+
<obc-poi-layer id="vessels" style="--obc-poi-layer-min-height: 96px">
|
|
150
|
+
<obc-poi-data id="v1" x="120" y="90"></obc-poi-data>
|
|
151
|
+
<obc-poi-data id="v2" x="320" y="110"></obc-poi-data>
|
|
152
|
+
</obc-poi-layer>
|
|
153
|
+
</obc-poi-layer-stack>
|
|
154
|
+
`);
|
|
155
|
+
const stack = host.querySelector('obc-poi-layer-stack') as ObcPoiLayerStack;
|
|
156
|
+
const vesselsLayer = host.querySelector('#vessels') as HTMLElement;
|
|
157
|
+
const v1 = host.querySelector('#v1') as ObcPoiData;
|
|
158
|
+
await settle(stack, v1);
|
|
159
|
+
await new Promise((r) => setTimeout(r, 250));
|
|
160
|
+
|
|
161
|
+
const selected = stack.selectTarget(v1, {selectionId: '3'});
|
|
162
|
+
expect(selected).toBe(true);
|
|
163
|
+
await new Promise((r) => setTimeout(r, 400));
|
|
164
|
+
|
|
165
|
+
expect(v1.parentElement).toBe(vesselsLayer);
|
|
166
|
+
expect(v1.hasAttribute('data-stack-selected')).toBe(true);
|
|
167
|
+
expect(v1.style.getPropertyValue('--obc-poi-button-projection-y')).not.toBe(
|
|
168
|
+
''
|
|
169
|
+
);
|
|
170
|
+
expect(stack.selectedTargets).toContain(v1);
|
|
171
|
+
|
|
172
|
+
const deselected = stack.deselectTarget(v1);
|
|
173
|
+
expect(deselected).toBe(true);
|
|
174
|
+
await new Promise((r) => setTimeout(r, 400));
|
|
175
|
+
|
|
176
|
+
expect(v1.parentElement).toBe(vesselsLayer);
|
|
177
|
+
expect(v1.hasAttribute('data-stack-selected')).toBe(false);
|
|
178
|
+
expect(v1.style.getPropertyValue('--obc-poi-button-projection-y')).toBe('');
|
|
179
|
+
expect(stack.selectedTargets).not.toContain(v1);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it('bootstrap targets authored in the selected layer stay there', async () => {
|
|
183
|
+
const host = mount(`
|
|
184
|
+
<obc-poi-layer-stack selection-mode="single" style="width: 640px">
|
|
185
|
+
<obc-poi-layer id="sel" is-selected style="--obc-poi-layer-min-height: 96px">
|
|
186
|
+
<obc-poi-data id="seeded" x="220" y="90"></obc-poi-data>
|
|
187
|
+
</obc-poi-layer>
|
|
188
|
+
<obc-poi-layer id="others" style="--obc-poi-layer-min-height: 96px">
|
|
189
|
+
<obc-poi-data x="120" y="110"></obc-poi-data>
|
|
190
|
+
</obc-poi-layer>
|
|
191
|
+
</obc-poi-layer-stack>
|
|
192
|
+
`);
|
|
193
|
+
const stack = host.querySelector('obc-poi-layer-stack') as ObcPoiLayerStack;
|
|
194
|
+
const selLayer = host.querySelector('#sel') as HTMLElement;
|
|
195
|
+
const seeded = host.querySelector('#seeded') as ObcPoiData;
|
|
196
|
+
await settle(stack, seeded);
|
|
197
|
+
await new Promise((r) => setTimeout(r, 400));
|
|
198
|
+
|
|
199
|
+
expect(stack.selectedTargets).toContain(seeded);
|
|
200
|
+
expect(seeded.parentElement).toBe(selLayer);
|
|
201
|
+
|
|
202
|
+
stack.deselectTarget(seeded);
|
|
203
|
+
await new Promise((r) => setTimeout(r, 400));
|
|
204
|
+
expect(seeded.parentElement).toBe(selLayer);
|
|
205
|
+
expect(stack.selectedTargets).not.toContain(seeded);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it('auto-grouping never touches consumer light DOM', async () => {
|
|
209
|
+
const host = mount(`
|
|
210
|
+
<obc-poi-layer style="width: 640px; --obc-poi-layer-min-height: 96px">
|
|
211
|
+
<obc-poi-data id="g1" x="100" y="90"></obc-poi-data>
|
|
212
|
+
<obc-poi-data id="g2" x="104" y="110"></obc-poi-data>
|
|
213
|
+
<obc-poi-data id="solo" x="440" y="100"></obc-poi-data>
|
|
214
|
+
</obc-poi-layer>
|
|
215
|
+
`);
|
|
216
|
+
const layer = host.querySelector('obc-poi-layer') as ObcPoiLayer;
|
|
217
|
+
const g1 = host.querySelector('#g1') as ObcPoiData;
|
|
218
|
+
const g2 = host.querySelector('#g2') as ObcPoiData;
|
|
219
|
+
await settle(layer, g1, g2);
|
|
220
|
+
await new Promise((r) => setTimeout(r, 400));
|
|
221
|
+
|
|
222
|
+
// Light DOM untouched: targets remain direct children of the layer and
|
|
223
|
+
// no group element is injected next to them.
|
|
224
|
+
expect(g1.parentElement).toBe(layer);
|
|
225
|
+
expect(g2.parentElement).toBe(layer);
|
|
226
|
+
expect(layer.querySelector('obc-poi-group')).toBeNull();
|
|
227
|
+
|
|
228
|
+
// The auto group is shadow chrome; members are slot-assigned into it.
|
|
229
|
+
const shadowGroup = layer.shadowRoot?.querySelector(
|
|
230
|
+
'obc-poi-group[data-auto-group]'
|
|
231
|
+
);
|
|
232
|
+
expect(shadowGroup).not.toBeNull();
|
|
233
|
+
expect(g1.assignedSlot?.parentElement).toBe(shadowGroup);
|
|
234
|
+
expect(g2.assignedSlot?.parentElement).toBe(shadowGroup);
|
|
235
|
+
expect(g1.hasAttribute('data-grouped')).toBe(true);
|
|
236
|
+
|
|
237
|
+
// Separating the targets disbands the group, again without any light
|
|
238
|
+
// DOM mutation.
|
|
239
|
+
g2.x = 560;
|
|
240
|
+
await new Promise((r) => setTimeout(r, 900));
|
|
241
|
+
expect(g1.parentElement).toBe(layer);
|
|
242
|
+
expect(g2.parentElement).toBe(layer);
|
|
243
|
+
expect(layer.querySelector('obc-poi-group')).toBeNull();
|
|
244
|
+
expect(
|
|
245
|
+
layer.shadowRoot?.querySelector('obc-poi-group[data-auto-group]')
|
|
246
|
+
).toBeNull();
|
|
247
|
+
expect(g1.hasAttribute('data-grouped')).toBe(false);
|
|
248
|
+
expect(g2.hasAttribute('data-grouped')).toBe(false);
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
it('removes dissolved auto-groups while grouping keeps churning', async () => {
|
|
252
|
+
const host = mount(`
|
|
253
|
+
<obc-poi-layer style="width: 640px; --obc-poi-layer-min-height: 96px">
|
|
254
|
+
<obc-poi-data id="g1" x="100" y="90"></obc-poi-data>
|
|
255
|
+
<obc-poi-data id="g2" x="104" y="110"></obc-poi-data>
|
|
256
|
+
<obc-poi-data id="jitter" x="480" y="100"></obc-poi-data>
|
|
257
|
+
</obc-poi-layer>
|
|
258
|
+
`);
|
|
259
|
+
const layer = host.querySelector('obc-poi-layer') as ObcPoiLayer;
|
|
260
|
+
const g2 = host.querySelector('#g2') as ObcPoiData;
|
|
261
|
+
const jitter = host.querySelector('#jitter') as ObcPoiData;
|
|
262
|
+
await settle(layer, g2);
|
|
263
|
+
await new Promise((r) => setTimeout(r, 400));
|
|
264
|
+
expect(
|
|
265
|
+
layer.shadowRoot?.querySelectorAll('obc-poi-group[data-auto-group]')
|
|
266
|
+
.length
|
|
267
|
+
).toBe(1);
|
|
268
|
+
|
|
269
|
+
// Dissolve the group, then keep the grouping engine busy with position
|
|
270
|
+
// churn on an unrelated target. Every pass used to re-condemn the
|
|
271
|
+
// exiting group and reset its 250ms removal timer, so under continuous
|
|
272
|
+
// detection churn (live video) dissolved group chrome accumulated
|
|
273
|
+
// forever. The dissolved group must disappear WHILE churn continues.
|
|
274
|
+
g2.x = 560;
|
|
275
|
+
let flip = false;
|
|
276
|
+
for (let i = 0; i < 12; i++) {
|
|
277
|
+
flip = !flip;
|
|
278
|
+
jitter.x = flip ? 483 : 477;
|
|
279
|
+
await new Promise((r) => setTimeout(r, 60));
|
|
280
|
+
}
|
|
281
|
+
// ~720ms of continuous churn — far past the 250ms removal delay.
|
|
282
|
+
expect(
|
|
283
|
+
layer.shadowRoot?.querySelectorAll('obc-poi-group[data-auto-group]')
|
|
284
|
+
.length
|
|
285
|
+
).toBe(0);
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
it('reports a target joining an expanded auto-group', async () => {
|
|
289
|
+
const host = mount(`
|
|
290
|
+
<obc-poi-layer join-while-expanded style="width: 640px; --obc-poi-layer-min-height: 96px">
|
|
291
|
+
<obc-poi-data id="g1" x="300" y="90"></obc-poi-data>
|
|
292
|
+
<obc-poi-data id="g2" x="304" y="110"></obc-poi-data>
|
|
293
|
+
<obc-poi-data id="late" x="560" y="100"></obc-poi-data>
|
|
294
|
+
</obc-poi-layer>
|
|
295
|
+
`);
|
|
296
|
+
const layer = host.querySelector('obc-poi-layer') as ObcPoiLayer;
|
|
297
|
+
const late = host.querySelector('#late') as ObcPoiData;
|
|
298
|
+
await settle(layer, late);
|
|
299
|
+
await new Promise((r) => setTimeout(r, 400));
|
|
300
|
+
const [group] = layer.autoGroups as Array<HTMLElement & {expand: boolean}>;
|
|
301
|
+
expect(group).toBeDefined();
|
|
302
|
+
group.expand = true;
|
|
303
|
+
await new Promise((r) => setTimeout(r, 600));
|
|
304
|
+
|
|
305
|
+
const events: Array<{clusters: unknown[][]}> = [];
|
|
306
|
+
layer.addEventListener('grouping-change', (event) => {
|
|
307
|
+
events.push((event as CustomEvent<{clusters: unknown[][]}>).detail);
|
|
308
|
+
});
|
|
309
|
+
// Walk the target in so it reaches the spread-out buttons from outside.
|
|
310
|
+
for (let x = 560; x >= 300; x -= 20) {
|
|
311
|
+
late.x = x;
|
|
312
|
+
await new Promise((r) => setTimeout(r, 60));
|
|
313
|
+
if (late.hasAttribute('data-joined-expanded')) break;
|
|
314
|
+
}
|
|
315
|
+
await new Promise((r) => setTimeout(r, 200));
|
|
316
|
+
|
|
317
|
+
expect(late.hasAttribute('data-joined-expanded')).toBe(true);
|
|
318
|
+
expect(late.parentElement).toBe(layer);
|
|
319
|
+
expect(
|
|
320
|
+
events.some((detail) =>
|
|
321
|
+
detail.clusters.some(
|
|
322
|
+
(cluster) => cluster.length === 3 && cluster.includes(late)
|
|
323
|
+
)
|
|
324
|
+
)
|
|
325
|
+
).toBe(true);
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
it('framework re-renders can replace and reorder grouped targets', async () => {
|
|
329
|
+
const host = mount(`
|
|
330
|
+
<obc-poi-layer style="width: 640px; --obc-poi-layer-min-height: 96px">
|
|
331
|
+
<obc-poi-data id="g1" x="100" y="90"></obc-poi-data>
|
|
332
|
+
<obc-poi-data id="g2" x="104" y="110"></obc-poi-data>
|
|
333
|
+
<obc-poi-data id="solo" x="440" y="100"></obc-poi-data>
|
|
334
|
+
</obc-poi-layer>
|
|
335
|
+
`);
|
|
336
|
+
const layer = host.querySelector('obc-poi-layer') as ObcPoiLayer;
|
|
337
|
+
const g1 = host.querySelector('#g1') as ObcPoiData;
|
|
338
|
+
const g2 = host.querySelector('#g2') as ObcPoiData;
|
|
339
|
+
const solo = host.querySelector('#solo') as ObcPoiData;
|
|
340
|
+
await settle(layer, g1, g2);
|
|
341
|
+
await new Promise((r) => setTimeout(r, 400));
|
|
342
|
+
expect(g1.hasAttribute('data-grouped')).toBe(true);
|
|
343
|
+
|
|
344
|
+
// Reconciliation-style reorder of an ungrouped sibling.
|
|
345
|
+
layer.insertBefore(solo, g1);
|
|
346
|
+
// Replace a grouped member with a fresh node, as a keyed re-render does.
|
|
347
|
+
const replacement = document.createElement('obc-poi-data') as ObcPoiData;
|
|
348
|
+
replacement.setAttribute('x', '104');
|
|
349
|
+
replacement.setAttribute('y', '110');
|
|
350
|
+
layer.replaceChild(replacement, g2);
|
|
351
|
+
await new Promise((r) => setTimeout(r, 900));
|
|
352
|
+
|
|
353
|
+
expect(replacement.parentElement).toBe(layer);
|
|
354
|
+
expect(g2.isConnected).toBe(false);
|
|
355
|
+
const shadowGroup = layer.shadowRoot?.querySelector(
|
|
356
|
+
'obc-poi-group[data-auto-group][data-visible]'
|
|
357
|
+
);
|
|
358
|
+
expect(shadowGroup).not.toBeNull();
|
|
359
|
+
expect(g1.assignedSlot?.parentElement).toBe(shadowGroup);
|
|
360
|
+
expect(replacement.assignedSlot?.parentElement).toBe(shadowGroup);
|
|
361
|
+
expect(layer.querySelector('obc-poi-group')).toBeNull();
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
it('framework re-renders can replace the header node without breakage', async () => {
|
|
365
|
+
const host = mount(`
|
|
366
|
+
<obc-poi-data x="100" y="96">
|
|
367
|
+
<obc-poi-header slot="header" content="7"></obc-poi-header>
|
|
368
|
+
</obc-poi-data>
|
|
369
|
+
`);
|
|
370
|
+
const target = host.querySelector('obc-poi-data') as ObcPoiData;
|
|
371
|
+
const oldHeader = host.querySelector('obc-poi-header') as HTMLElement;
|
|
372
|
+
await settle(target);
|
|
373
|
+
|
|
374
|
+
// Simulate a declarative renderer swapping the node it owns.
|
|
375
|
+
const newHeader = document.createElement('obc-poi-header');
|
|
376
|
+
newHeader.setAttribute('slot', 'header');
|
|
377
|
+
newHeader.setAttribute('content', '8');
|
|
378
|
+
target.replaceChild(newHeader, oldHeader);
|
|
379
|
+
await settle(target);
|
|
380
|
+
|
|
381
|
+
expect(newHeader.parentElement).toBe(target);
|
|
382
|
+
expect(oldHeader.parentElement).toBeNull();
|
|
383
|
+
|
|
384
|
+
const innerButton = target.shadowRoot?.querySelector(
|
|
385
|
+
'obc-poi-button-data'
|
|
386
|
+
) as HTMLElement | null;
|
|
387
|
+
const headerSlot = innerButton?.shadowRoot?.querySelector(
|
|
388
|
+
'slot[name="header"]'
|
|
389
|
+
) as HTMLSlotElement | null;
|
|
390
|
+
const flattened = headerSlot?.assignedElements({flatten: true}) ?? [];
|
|
391
|
+
expect(flattened).toContain(newHeader);
|
|
392
|
+
});
|
|
393
|
+
});
|
package/src/ar/poi/poi-vessel.ts
CHANGED
|
@@ -21,6 +21,7 @@ export {
|
|
|
21
21
|
*
|
|
22
22
|
* Extends `PoiBase` to provide the "vessel" variant of the POI system.
|
|
23
23
|
* Renders `<obc-poi>` with a slotted `<obc-poi-button-vessel>`.
|
|
24
|
+
* See the "Coordinate Model" section in `PoiBase` (poi-base.ts) for how `x`, `y`, and `buttonY` position the marker.
|
|
24
25
|
*
|
|
25
26
|
* @slot - Icon content forwarded to the inner vessel object.
|
|
26
27
|
* @slot turn-indicator - Optional turn indicator content for speed-rot type.
|
|
@@ -70,6 +71,7 @@ export class ObcPoiVessel extends PoiBase {
|
|
|
70
71
|
></slot>
|
|
71
72
|
<slot name="turn-indicator" slot="turn-indicator"></slot>
|
|
72
73
|
<slot name="speed-indicator" slot="speed-indicator"></slot>
|
|
74
|
+
<slot name="header" slot="header"></slot>
|
|
73
75
|
</obc-poi-button-vessel>
|
|
74
76
|
`;
|
|
75
77
|
}
|
package/src/ar/poi/poi.ts
CHANGED
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
ObcPoiButtonState,
|
|
11
11
|
PoiButtonVisualState,
|
|
12
12
|
} from '../poi-button/poi-button.js';
|
|
13
|
-
import {ObcPoiHeaderState} from '../building-blocks/poi-header/poi-header.js';
|
|
14
13
|
import {POIStyle} from '../building-blocks/poi-graphic-line/poi-graphic-line.js';
|
|
15
14
|
import {poiArrow} from './arrow.js';
|
|
16
15
|
import '../building-blocks/poi-line/poi-line.js';
|
|
@@ -103,7 +102,7 @@ export enum ObcPoiState {
|
|
|
103
102
|
Alarm = 'alarm',
|
|
104
103
|
}
|
|
105
104
|
|
|
106
|
-
const DEFAULT_LINE_LENGTH_PX =
|
|
105
|
+
export const DEFAULT_LINE_LENGTH_PX = 192;
|
|
107
106
|
const POINTER_BOX_BASE_SIZE_PX = 32;
|
|
108
107
|
const POINT_POINTER_OFFSET_PX = 12;
|
|
109
108
|
|
|
@@ -148,7 +147,7 @@ const POINT_POINTER_OFFSET_PX = 12;
|
|
|
148
147
|
* Motion and layout notes:
|
|
149
148
|
* - `animatePosition` (default: `false`): when true, enables short position transition timing for line/pointer movement.
|
|
150
149
|
* - `x` (default: `0`): host horizontal position; sets `--obc-poi-x` as `${x}px`.
|
|
151
|
-
* - `y` (default: `
|
|
150
|
+
* - `y` (default: `192`): absolute local target Y; non-finite values fall back to `0` in geometry calculations. The default is shared with the top-level POI variants (`DEFAULT_LINE_LENGTH_PX`).
|
|
152
151
|
* - `buttonY` (default: `0`): when `fixedTarget=false`, anchors the button at its local Y while the target is derived below it from `y`; when `fixedTarget=true`, preserves the legacy host-anchor behavior.
|
|
153
152
|
* - `buttonOffsetX`/`targetOffsetX` (defaults: `0`/`0`): define connector bend delta via `targetOffsetX - buttonOffsetX`.
|
|
154
153
|
* - `boxWidth`/`boxHeight` (defaults: `null`/`null`): optional pointer frame size extras; invalid/non-finite values are ignored.
|
|
@@ -166,7 +165,7 @@ const POINT_POINTER_OFFSET_PX = 12;
|
|
|
166
165
|
*
|
|
167
166
|
* - Default slot: Main icon/content rendered inside `obc-poi-button`.
|
|
168
167
|
* - `button`: Optional custom button element replacing the default `obc-poi-button`.
|
|
169
|
-
* - `header`: Optional header content
|
|
168
|
+
* - `header`: Optional header content, forwarded into the default `obc-poi-button` through a `<slot name="header">` chain. Content stays in the consumer's light DOM. When a custom `button` is slotted, place header content directly inside it instead.
|
|
170
169
|
*
|
|
171
170
|
* ## Events
|
|
172
171
|
*
|
|
@@ -194,7 +193,7 @@ const POINT_POINTER_OFFSET_PX = 12;
|
|
|
194
193
|
* @availableWhen outsideAngle type==outside && hasPointer==true
|
|
195
194
|
* @slot - Default POI button content.
|
|
196
195
|
* @slot button - Optional custom button element replacing the default `obc-poi-button`.
|
|
197
|
-
* @slot header - Optional header content,
|
|
196
|
+
* @slot header - Optional header content, forwarded into the default `obc-poi-button` via a `<slot name="header">` chain.
|
|
198
197
|
* @experimental
|
|
199
198
|
*/
|
|
200
199
|
@customElement('obc-poi')
|
|
@@ -228,45 +227,6 @@ export class ObcPoi extends LitElement {
|
|
|
228
227
|
@property({type: Number, attribute: 'outside-angle'}) outsideAngle = 315;
|
|
229
228
|
@property({type: Boolean, attribute: 'animate-position'})
|
|
230
229
|
animatePosition = false;
|
|
231
|
-
private headerObserver?: MutationObserver;
|
|
232
|
-
|
|
233
|
-
override connectedCallback() {
|
|
234
|
-
super.connectedCallback();
|
|
235
|
-
this.setupHeaderObserver();
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
override disconnectedCallback() {
|
|
239
|
-
super.disconnectedCallback();
|
|
240
|
-
this.headerObserver?.disconnect();
|
|
241
|
-
this.headerObserver = undefined;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
private setupHeaderObserver() {
|
|
245
|
-
this.headerObserver?.disconnect();
|
|
246
|
-
this.headerObserver = new MutationObserver((mutations) => {
|
|
247
|
-
for (const mutation of mutations) {
|
|
248
|
-
if (mutation.type === 'childList') {
|
|
249
|
-
this.syncFallbackButtonHeaderContent();
|
|
250
|
-
this.syncAttachedHeaderState();
|
|
251
|
-
return;
|
|
252
|
-
}
|
|
253
|
-
if (
|
|
254
|
-
mutation.type === 'attributes' &&
|
|
255
|
-
mutation.target instanceof HTMLElement &&
|
|
256
|
-
mutation.target.getAttribute('slot') === 'header'
|
|
257
|
-
) {
|
|
258
|
-
this.syncFallbackButtonHeaderContent();
|
|
259
|
-
this.syncAttachedHeaderState();
|
|
260
|
-
return;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
});
|
|
264
|
-
this.headerObserver.observe(this, {
|
|
265
|
-
childList: true,
|
|
266
|
-
attributes: true,
|
|
267
|
-
attributeFilter: ['slot'],
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
230
|
|
|
271
231
|
private updatePosition() {
|
|
272
232
|
this.style.removeProperty('top');
|
|
@@ -324,22 +284,6 @@ export class ObcPoi extends LitElement {
|
|
|
324
284
|
}
|
|
325
285
|
}
|
|
326
286
|
|
|
327
|
-
private get resolvedHeaderState(): ObcPoiHeaderState {
|
|
328
|
-
switch (this.buttonState) {
|
|
329
|
-
case ObcPoiButtonState.Caution:
|
|
330
|
-
return ObcPoiHeaderState.Caution;
|
|
331
|
-
case ObcPoiButtonState.Warning:
|
|
332
|
-
return ObcPoiHeaderState.Warning;
|
|
333
|
-
case ObcPoiButtonState.Alarm:
|
|
334
|
-
return ObcPoiHeaderState.Alarm;
|
|
335
|
-
case ObcPoiButtonState.Enabled:
|
|
336
|
-
default:
|
|
337
|
-
return this.selected
|
|
338
|
-
? ObcPoiHeaderState.Selected
|
|
339
|
-
: ObcPoiHeaderState.Enabled;
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
|
|
343
287
|
private get lineStyle(): POIStyle {
|
|
344
288
|
if (this.state === ObcPoiState.Alarm) {
|
|
345
289
|
return POIStyle.Alarm;
|
|
@@ -552,58 +496,19 @@ export class ObcPoi extends LitElement {
|
|
|
552
496
|
}
|
|
553
497
|
|
|
554
498
|
private handleButtonSlotChange(e: Event) {
|
|
555
|
-
|
|
499
|
+
// slotchange from nested forwarding slots (e.g. the header slot inside
|
|
500
|
+
// the fallback button) bubbles through this slot — only react to the
|
|
501
|
+
// button slot's own assignment.
|
|
502
|
+
if (e.target !== e.currentTarget) {
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
505
|
+
const slot = e.currentTarget as HTMLSlotElement;
|
|
556
506
|
const assigned = slot.assignedElements({flatten: false});
|
|
557
507
|
this.slottedButton =
|
|
558
508
|
assigned.length > 0 ? (assigned[0] as HTMLElement) : null;
|
|
559
|
-
this.syncFallbackButtonHeaderContent();
|
|
560
509
|
this.syncSlottedButtonProps();
|
|
561
510
|
}
|
|
562
511
|
|
|
563
|
-
private syncFallbackButtonHeaderContent() {
|
|
564
|
-
if (this.slottedButton) {
|
|
565
|
-
return;
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
const button = this.renderRoot.querySelector(
|
|
569
|
-
'obc-poi-button.poi-button'
|
|
570
|
-
) as HTMLElement | null;
|
|
571
|
-
if (!button) {
|
|
572
|
-
return;
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
for (const child of Array.from(this.children)) {
|
|
576
|
-
if (
|
|
577
|
-
!(child instanceof HTMLElement) ||
|
|
578
|
-
child.getAttribute('slot') !== 'header'
|
|
579
|
-
) {
|
|
580
|
-
continue;
|
|
581
|
-
}
|
|
582
|
-
if (child.parentElement !== button) {
|
|
583
|
-
button.appendChild(child);
|
|
584
|
-
}
|
|
585
|
-
this.applyHeaderState(child);
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
private applyHeaderState(root: ParentNode) {
|
|
590
|
-
const headers = [
|
|
591
|
-
...(root instanceof Element && root.matches('obc-poi-header')
|
|
592
|
-
? [root]
|
|
593
|
-
: []),
|
|
594
|
-
...root.querySelectorAll('obc-poi-header'),
|
|
595
|
-
] as HTMLElement[];
|
|
596
|
-
|
|
597
|
-
for (const header of headers) {
|
|
598
|
-
(header as {state?: ObcPoiHeaderState}).state = this.resolvedHeaderState;
|
|
599
|
-
header.setAttribute('state', this.resolvedHeaderState);
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
private syncAttachedHeaderState() {
|
|
604
|
-
this.applyHeaderState(this.renderRoot);
|
|
605
|
-
}
|
|
606
|
-
|
|
607
512
|
private syncSlottedButtonProps() {
|
|
608
513
|
const btn = this.slottedButton;
|
|
609
514
|
if (!btn) return;
|
|
@@ -638,6 +543,7 @@ export class ObcPoi extends LitElement {
|
|
|
638
543
|
.data=${this.data}
|
|
639
544
|
>
|
|
640
545
|
<slot></slot>
|
|
546
|
+
<slot name="header" slot="header"></slot>
|
|
641
547
|
</obc-poi-button>
|
|
642
548
|
</slot>
|
|
643
549
|
`;
|
|
@@ -671,11 +577,6 @@ export class ObcPoi extends LitElement {
|
|
|
671
577
|
`;
|
|
672
578
|
}
|
|
673
579
|
|
|
674
|
-
protected override firstUpdated(_changedProperties: Map<string, unknown>) {
|
|
675
|
-
this.syncFallbackButtonHeaderContent();
|
|
676
|
-
this.syncAttachedHeaderState();
|
|
677
|
-
}
|
|
678
|
-
|
|
679
580
|
protected override updated(changedProperties: Map<string, unknown>) {
|
|
680
581
|
super.updated(changedProperties);
|
|
681
582
|
if (changedProperties.has('x')) {
|
|
@@ -689,9 +590,7 @@ export class ObcPoi extends LitElement {
|
|
|
689
590
|
) {
|
|
690
591
|
this.updatePosition();
|
|
691
592
|
}
|
|
692
|
-
this.syncFallbackButtonHeaderContent();
|
|
693
593
|
this.syncSlottedButtonProps();
|
|
694
|
-
this.syncAttachedHeaderState();
|
|
695
594
|
}
|
|
696
595
|
|
|
697
596
|
static override styles = unsafeCSS(componentStyle);
|
|
@@ -101,8 +101,7 @@ export interface ObcPoiButtonDataItem {
|
|
|
101
101
|
* - `data` (default `[]`): when non-empty, renders value/label/unit rows.
|
|
102
102
|
* - `hasHeader` + `header` slot: renders a header area and syncs slotted `obc-poi-header` state.
|
|
103
103
|
* - `hasRelation` (default `false`): enables optional relation content in data mode.
|
|
104
|
-
* - `inExpandedGroup` (default `false`):
|
|
105
|
-
* - TODO(designer): Confirm intended UX semantics for `inExpandedGroup` beyond styling.
|
|
104
|
+
* - `inExpandedGroup` (default `false`): expanded-group presentation state, applied by the owning group composition during expand/collapse orchestration; consumers should not set it directly.
|
|
106
105
|
*
|
|
107
106
|
* ## Usage Guidelines
|
|
108
107
|
* - Use `layout="anchored"` for standalone marker buttons.
|
|
@@ -131,6 +130,9 @@ export interface ObcPoiButtonDataItem {
|
|
|
131
130
|
* </obc-poi-button>
|
|
132
131
|
* ```
|
|
133
132
|
*
|
|
133
|
+
* @property inExpandedGroup - Expanded-group presentation state, applied by the owning group composition
|
|
134
|
+
* while the button is shown inside an expanded `obc-poi-group` and during
|
|
135
|
+
* its collapse animations. Consumers should not set it directly.
|
|
134
136
|
* @slot - Icon/content rendered inside `obc-poi-object`.
|
|
135
137
|
* @slot header - Optional header content rendered above the marker body.
|
|
136
138
|
* @slot relation - Optional relation icon/content in data mode when `hasRelation` is true.
|
|
@@ -158,13 +160,24 @@ export class ObcPoiButton extends LitElement {
|
|
|
158
160
|
@property({type: String, attribute: 'header-content'}) headerContent = '';
|
|
159
161
|
private headerContentObserver?: MutationObserver;
|
|
160
162
|
|
|
163
|
+
// Forwarding slots from an outer shadow tree (`<slot name="header"
|
|
164
|
+
// slot="header">` rendered by obc-poi / PoiBase variants) fire
|
|
165
|
+
// `slotchange` that bubbles through this element; re-render so
|
|
166
|
+
// `hasHeaderContent` re-evaluates the forwarded assignment.
|
|
167
|
+
private handleLightSlotChange = () => {
|
|
168
|
+
this.requestUpdate();
|
|
169
|
+
this.syncSlottedHeaderState();
|
|
170
|
+
};
|
|
171
|
+
|
|
161
172
|
override connectedCallback() {
|
|
162
173
|
super.connectedCallback();
|
|
174
|
+
this.addEventListener('slotchange', this.handleLightSlotChange);
|
|
163
175
|
this.setupHeaderContentObserver();
|
|
164
176
|
}
|
|
165
177
|
|
|
166
178
|
override disconnectedCallback() {
|
|
167
179
|
super.disconnectedCallback();
|
|
180
|
+
this.removeEventListener('slotchange', this.handleLightSlotChange);
|
|
168
181
|
this.headerContentObserver?.disconnect();
|
|
169
182
|
this.headerContentObserver = undefined;
|
|
170
183
|
}
|
|
@@ -231,7 +244,16 @@ export class ObcPoiButton extends LitElement {
|
|
|
231
244
|
}
|
|
232
245
|
|
|
233
246
|
private get hasHeaderContent(): boolean {
|
|
234
|
-
|
|
247
|
+
for (const child of this.querySelectorAll('[slot="header"]')) {
|
|
248
|
+
if (child instanceof HTMLSlotElement) {
|
|
249
|
+
if (child.assignedElements({flatten: true}).length > 0) {
|
|
250
|
+
return true;
|
|
251
|
+
}
|
|
252
|
+
} else {
|
|
253
|
+
return true;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return false;
|
|
235
257
|
}
|
|
236
258
|
|
|
237
259
|
private get hasGeneratedHeaderContent(): boolean {
|