@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
|
@@ -50,7 +50,7 @@ export enum OverlapMode {
|
|
|
50
50
|
*
|
|
51
51
|
* ### Features
|
|
52
52
|
* - Overlap strategies: `overlapMode="grouping"` builds overlap clusters; `overlapMode="crossing"` continuously adjusts horizontal offsets to reduce crossings.
|
|
53
|
-
* - Auto-group lifecycle: Creates/removes auto groups
|
|
53
|
+
* - Auto-group lifecycle: Creates/removes auto groups as shadow-internal chrome — the consumer's light DOM is never modified; members are placed via manual slot assignment. Reach the group elements through the `autoGroups` accessor.
|
|
54
54
|
* - Manual group support: Respects existing `obc-poi-group` elements and can optionally join nearby targets while a group is expanded (`joinWhileExpanded`).
|
|
55
55
|
* - Dynamic observation: Reacts to slot changes, target style/position mutations, and target size changes to recompute grouping and layer height.
|
|
56
56
|
* - Layer diagnostics: `debug` shows a label overlay using `label`.
|
|
@@ -62,9 +62,11 @@ export enum OverlapMode {
|
|
|
62
62
|
* - Choose `overlapMode` based on behavior:
|
|
63
63
|
* - `grouping`: best when overlaps should collapse into expandable clusters.
|
|
64
64
|
* - `crossing`: best when targets stay independent but should separate horizontally.
|
|
65
|
-
* -
|
|
65
|
+
* - Handle `layer-resize` only when using the layer standalone; inside `obc-poi-layer-stack` / `obc-poi-controller` the container handles height syncing. Example: `layer.addEventListener('layer-resize', (e) => { host.style.height = e.detail.height + 'px'; })`.
|
|
66
|
+
* - After imperatively adding, removing, or moving POI children outside the layer's own observers, call the public `requestGroupingUpdate()` method to force a recompute; it is the supported hook for imperative DOM mutations.
|
|
67
|
+
* - Set `--obc-poi-layer-min-height` when the layer starts empty, otherwise the layer collapses to 0px height until targets exist.
|
|
66
68
|
* - Enable `joinWhileExpanded` only when targets should be able to join an already expanded auto-group.
|
|
67
|
-
* - **TODO(designer):** Confirm intended user-visible behavior for `isSelected`, since it
|
|
69
|
+
* - **TODO(designer):** Confirm intended user-visible behavior for `isSelected`, since it has no runtime layout logic in this class — it only reflects the attribute and notifies containers via `layer-selection-changed` (consumed by `obc-poi-layer-stack` to pick the selected layer).
|
|
68
70
|
*
|
|
69
71
|
* ### Slots
|
|
70
72
|
* | Slot | Renders When... | Purpose |
|
|
@@ -73,10 +75,22 @@ export enum OverlapMode {
|
|
|
73
75
|
*
|
|
74
76
|
* ### Events
|
|
75
77
|
* - `layer-resize` - Fired when computed layer height changes. Detail: `{ height: number, label: string }`.
|
|
78
|
+
* - `grouping-change` - Fired when grouping membership or front/behind/pre-group state changes. Detail: `{ clusters: Poi[][], front: Poi[], behind: Poi[], pregrouped: Poi[] }`. Subscribe to this instead of observing the layer's internal `data-*` attributes.
|
|
79
|
+
*
|
|
80
|
+
* ### CSS Custom Properties
|
|
81
|
+
* | Property | Default | Purpose |
|
|
82
|
+
* | --- | --- | --- |
|
|
83
|
+
* | `--obc-poi-layer-overlap-enter` | `10px` | Max horizontal gap at which ungrouped targets start grouping. |
|
|
84
|
+
* | `--obc-poi-layer-overlap-exit` | `18px` | Gap at which grouped targets leave their group. Clamped to at least the enter threshold; keep it larger than enter so jittery positions do not oscillate in and out of groups. |
|
|
85
|
+
* | `--obc-poi-layer-overlap-pre` | `16px` | Gap at which targets get the pre-grouped visual state. |
|
|
86
|
+
* | `--obc-poi-layer-overlap-behind` | `10px` | Gap at which the shortest target gets the behind visual state. |
|
|
87
|
+
* | `--obc-poi-layer-exit-delay-ms` | `140` | Delay before exiting targets lose their exit visual state. |
|
|
88
|
+
* | `--obc-poi-layer-group-removal-delay-ms` | `250` | Delay before a dissolved auto-group element is removed. |
|
|
89
|
+
* | `--obc-poi-layer-exit-lock-duration-ms` | `500` | Duration a target is locked out of pre-group/behind states after leaving a group. |
|
|
76
90
|
*
|
|
77
91
|
* ### Best Practices
|
|
78
92
|
* - Keep POI targets as direct descendants when possible to reduce grouping ambiguity.
|
|
79
|
-
* -
|
|
93
|
+
* - Targets may update `x`/`y` every animation frame; grouping stays stable as long as the horizontal gap between targets does not oscillate across the enter/exit band faster than the group lifecycle delays (~0.5s). Smooth noisy input coordinates or widen the enter/exit band to compensate.
|
|
80
94
|
* - Avoid adding non-POI interactive wrappers inside the layer unless needed, as layer observers track POI-related descendants.
|
|
81
95
|
*
|
|
82
96
|
* ### Example
|
|
@@ -90,11 +104,22 @@ export enum OverlapMode {
|
|
|
90
104
|
*
|
|
91
105
|
* @slot - Default slot for POI targets and optional POI groups.
|
|
92
106
|
* @fires {CustomEvent<{height:number,label:string}>} layer-resize - Fired when the layer height changes.
|
|
107
|
+
* @fires {CustomEvent<{clusters:Poi[][],front:Poi[],behind:Poi[],pregrouped:Poi[]}>} grouping-change - Fired when grouping membership or overlap state changes. Bubbles and is composed.
|
|
93
108
|
* @fires {Event} layer-selection-changed - Fired when the layer's `isSelected` state changes. Bubbles.
|
|
94
109
|
* @experimental
|
|
95
110
|
*/
|
|
96
111
|
@customElement('obc-poi-layer')
|
|
97
112
|
export class ObcPoiLayer extends LitElement {
|
|
113
|
+
/**
|
|
114
|
+
* Manual slot assignment lets the layer place consumer-owned targets into
|
|
115
|
+
* shadow-internal auto-group chrome (and back) without ever re-parenting
|
|
116
|
+
* them: grouping only changes which internal slot a target is assigned to.
|
|
117
|
+
*/
|
|
118
|
+
static override shadowRootOptions: ShadowRootInit = {
|
|
119
|
+
...LitElement.shadowRootOptions,
|
|
120
|
+
slotAssignment: 'manual',
|
|
121
|
+
};
|
|
122
|
+
|
|
98
123
|
@property({type: String}) label = '';
|
|
99
124
|
@property({type: Boolean}) debug = false;
|
|
100
125
|
@property({type: String}) overlapMode: OverlapMode = OverlapMode.Grouping;
|
|
@@ -111,6 +136,9 @@ export class ObcPoiLayer extends LitElement {
|
|
|
111
136
|
private targetResizeObserver?: ResizeObserver;
|
|
112
137
|
private lastHeight = 0;
|
|
113
138
|
private isGrouping = false;
|
|
139
|
+
private lastGroupingSignature = '';
|
|
140
|
+
private groupingIds = new WeakMap<Poi, number>();
|
|
141
|
+
private nextGroupingId = 1;
|
|
114
142
|
private targetObservers = new Map<Poi, MutationObserver>();
|
|
115
143
|
private targetSizeElements = new Map<Poi, HTMLElement>();
|
|
116
144
|
private groupingRaf = 0;
|
|
@@ -406,19 +434,31 @@ export class ObcPoiLayer extends LitElement {
|
|
|
406
434
|
private setupLayerMutationObserver() {
|
|
407
435
|
this.layerMutationObserver?.disconnect();
|
|
408
436
|
this.layerMutationObserver = new MutationObserver((mutations) => {
|
|
437
|
+
let childListChanged = false;
|
|
438
|
+
let relevant = false;
|
|
409
439
|
for (const mutation of mutations) {
|
|
410
440
|
if (mutation.type !== 'childList') continue;
|
|
441
|
+
childListChanged = true;
|
|
411
442
|
const nodes = [...mutation.addedNodes, ...mutation.removedNodes];
|
|
412
443
|
for (const node of nodes) {
|
|
413
|
-
if (
|
|
414
|
-
|
|
415
|
-
this.
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
return;
|
|
444
|
+
if (
|
|
445
|
+
node instanceof HTMLElement &&
|
|
446
|
+
this.isPoiLayerRelevantNode(node)
|
|
447
|
+
) {
|
|
448
|
+
relevant = true;
|
|
449
|
+
break;
|
|
420
450
|
}
|
|
421
451
|
}
|
|
452
|
+
if (relevant) break;
|
|
453
|
+
}
|
|
454
|
+
if (childListChanged) {
|
|
455
|
+
this.syncSlotAssignments();
|
|
456
|
+
}
|
|
457
|
+
if (relevant) {
|
|
458
|
+
this.updateTargetObservers();
|
|
459
|
+
this.scheduleGrouping();
|
|
460
|
+
this.scheduleLayerHeightUpdate();
|
|
461
|
+
this.crossingTargetsDirty = true;
|
|
422
462
|
}
|
|
423
463
|
});
|
|
424
464
|
this.layerMutationObserver.observe(this, {childList: true, subtree: true});
|
|
@@ -429,6 +469,96 @@ export class ObcPoiLayer extends LitElement {
|
|
|
429
469
|
this.scheduleLayerHeightUpdate();
|
|
430
470
|
}
|
|
431
471
|
|
|
472
|
+
/* ---------- Manual slot assignment ---------- */
|
|
473
|
+
|
|
474
|
+
private getMainSlot(): HTMLSlotElement | null {
|
|
475
|
+
return (
|
|
476
|
+
(this.shadowRoot?.querySelector('slot.main') as HTMLSlotElement | null) ??
|
|
477
|
+
null
|
|
478
|
+
);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* Assign every light-DOM child that is not currently placed in an
|
|
483
|
+
* auto-group member slot to the main slot. With `slotAssignment: 'manual'`
|
|
484
|
+
* nothing renders unless explicitly assigned, so this runs after render,
|
|
485
|
+
* on child-list mutations, and after every grouping change.
|
|
486
|
+
*/
|
|
487
|
+
private syncSlotAssignments() {
|
|
488
|
+
const mainSlot = this.getMainSlot();
|
|
489
|
+
if (!mainSlot) return;
|
|
490
|
+
const groupAssigned = new Set<Node>();
|
|
491
|
+
this.getAutoGroups().forEach((group) => {
|
|
492
|
+
const slot = this.getAutoGroupMemberSlot(group);
|
|
493
|
+
slot?.assignedNodes().forEach((node) => groupAssigned.add(node));
|
|
494
|
+
});
|
|
495
|
+
const mainNodes = Array.from(this.childNodes).filter(
|
|
496
|
+
(node): node is Element | Text =>
|
|
497
|
+
!groupAssigned.has(node) &&
|
|
498
|
+
(node instanceof Element || node instanceof Text)
|
|
499
|
+
);
|
|
500
|
+
mainSlot.assign(...mainNodes);
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* Called by an auto-created `obc-poi-group` after it removed a target from
|
|
505
|
+
* its member slot, so the target immediately re-renders through the main
|
|
506
|
+
* slot instead of disappearing until the next grouping pass.
|
|
507
|
+
* @internal
|
|
508
|
+
*/
|
|
509
|
+
public releaseAssignedTarget(_target: Poi) {
|
|
510
|
+
this.syncSlotAssignments();
|
|
511
|
+
this.requestGroupingUpdate();
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* The auto-created `obc-poi-group` elements currently managed by this
|
|
516
|
+
* layer. Auto groups are shadow-internal chrome (they never appear in the
|
|
517
|
+
* consumer's light DOM); use this accessor — typically after a
|
|
518
|
+
* `grouping-change` event — to reach them, e.g. to expand a group
|
|
519
|
+
* programmatically.
|
|
520
|
+
*/
|
|
521
|
+
public get autoGroups(): HTMLElement[] {
|
|
522
|
+
return this.getAutoGroups();
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
private getAutoGroups(): PoiButtonGroupElement[] {
|
|
526
|
+
return Array.from(
|
|
527
|
+
this.shadowRoot?.querySelectorAll('obc-poi-group[data-auto-group]') ?? []
|
|
528
|
+
) as PoiButtonGroupElement[];
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
private getAutoGroupMemberSlot(group: HTMLElement): HTMLSlotElement | null {
|
|
532
|
+
return group.querySelector(
|
|
533
|
+
':scope > slot.auto-group-members'
|
|
534
|
+
) as HTMLSlotElement | null;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
/** The auto group a target is currently assigned into, if any. */
|
|
538
|
+
private getAutoGroupOf(target: Poi): HTMLElement | null {
|
|
539
|
+
const slot = target.assignedSlot;
|
|
540
|
+
if (slot?.classList.contains('auto-group-members')) {
|
|
541
|
+
return slot.parentElement;
|
|
542
|
+
}
|
|
543
|
+
return null;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* Members of a group in either mode: slot-assigned (shadow auto groups) or
|
|
548
|
+
* light-DOM children (consumer-managed manual groups).
|
|
549
|
+
*/
|
|
550
|
+
private getGroupMembers(group: ParentNode): Poi[] {
|
|
551
|
+
if (group instanceof HTMLElement) {
|
|
552
|
+
const slot = this.getAutoGroupMemberSlot(group);
|
|
553
|
+
if (slot) {
|
|
554
|
+
return slot.assignedElements().filter((el): el is Poi => isPoi(el));
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
return Array.from(group.querySelectorAll(`[${POI_ATTR}]`)).filter(
|
|
558
|
+
(node): node is Poi => isPoi(node)
|
|
559
|
+
);
|
|
560
|
+
}
|
|
561
|
+
|
|
432
562
|
private scheduleGrouping() {
|
|
433
563
|
if (this.overlapMode === OverlapMode.Crossing) {
|
|
434
564
|
this.scheduleCrossingMode();
|
|
@@ -487,6 +617,47 @@ export class ObcPoiLayer extends LitElement {
|
|
|
487
617
|
return next.shouldContinue;
|
|
488
618
|
}
|
|
489
619
|
|
|
620
|
+
private getGroupingId(target: Poi): number {
|
|
621
|
+
let id = this.groupingIds.get(target);
|
|
622
|
+
if (id === undefined) {
|
|
623
|
+
id = this.nextGroupingId++;
|
|
624
|
+
this.groupingIds.set(target, id);
|
|
625
|
+
}
|
|
626
|
+
return id;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
private notifyGroupingChange(
|
|
630
|
+
clusters: Poi[][],
|
|
631
|
+
frontTargets: Set<Poi>,
|
|
632
|
+
behindTargets: Set<Poi>,
|
|
633
|
+
preGrouped: Set<Poi>
|
|
634
|
+
) {
|
|
635
|
+
const idsOf = (targets: Iterable<Poi>) =>
|
|
636
|
+
Array.from(targets, (target) => this.getGroupingId(target)).sort(
|
|
637
|
+
(a, b) => a - b
|
|
638
|
+
);
|
|
639
|
+
const signature = JSON.stringify({
|
|
640
|
+
clusters: clusters.map((cluster) => idsOf(cluster)).sort(),
|
|
641
|
+
front: idsOf(frontTargets),
|
|
642
|
+
behind: idsOf(behindTargets),
|
|
643
|
+
pre: idsOf(preGrouped),
|
|
644
|
+
});
|
|
645
|
+
if (signature === this.lastGroupingSignature) return;
|
|
646
|
+
this.lastGroupingSignature = signature;
|
|
647
|
+
this.dispatchEvent(
|
|
648
|
+
new CustomEvent('grouping-change', {
|
|
649
|
+
detail: {
|
|
650
|
+
clusters: clusters.map((cluster) => [...cluster]),
|
|
651
|
+
front: [...frontTargets],
|
|
652
|
+
behind: [...behindTargets],
|
|
653
|
+
pregrouped: [...preGrouped],
|
|
654
|
+
},
|
|
655
|
+
bubbles: true,
|
|
656
|
+
composed: true,
|
|
657
|
+
})
|
|
658
|
+
);
|
|
659
|
+
}
|
|
660
|
+
|
|
490
661
|
private toggleGroupLayerHook(group: HTMLElement, hasTargets: boolean) {
|
|
491
662
|
if (hasTargets) {
|
|
492
663
|
group.setAttribute(ObcPoiLayer.GROUP_LAYER_HOOK_ATTR, '');
|
|
@@ -538,17 +709,23 @@ export class ObcPoiLayer extends LitElement {
|
|
|
538
709
|
const behindRaw = getComputedStyle(this).getPropertyValue(
|
|
539
710
|
'--obc-poi-layer-overlap-behind'
|
|
540
711
|
);
|
|
541
|
-
const
|
|
542
|
-
|
|
543
|
-
Number.
|
|
544
|
-
|
|
545
|
-
const
|
|
712
|
+
const parseThreshold = (raw: string, fallback: number): number => {
|
|
713
|
+
const value = Number.parseFloat(raw);
|
|
714
|
+
return Number.isFinite(value) ? value : fallback;
|
|
715
|
+
};
|
|
716
|
+
const enterThreshold = parseThreshold(enterRaw, 10);
|
|
717
|
+
const exitThreshold = Math.max(
|
|
718
|
+
parseThreshold(exitRaw, enterThreshold + 8),
|
|
719
|
+
enterThreshold
|
|
720
|
+
);
|
|
721
|
+
const preThreshold = parseThreshold(preRaw, Math.max(enterThreshold, 16));
|
|
722
|
+
const behindThreshold = parseThreshold(behindRaw, enterThreshold);
|
|
546
723
|
|
|
547
724
|
const currentGroupByTarget = new Map<Poi, HTMLElement>();
|
|
548
725
|
targets.forEach((target) => {
|
|
549
|
-
const
|
|
550
|
-
if (
|
|
551
|
-
currentGroupByTarget.set(target,
|
|
726
|
+
const group = this.getAutoGroupOf(target);
|
|
727
|
+
if (group) {
|
|
728
|
+
currentGroupByTarget.set(target, group);
|
|
552
729
|
}
|
|
553
730
|
});
|
|
554
731
|
|
|
@@ -574,9 +751,13 @@ export class ObcPoiLayer extends LitElement {
|
|
|
574
751
|
const clusters = buildClusters(targets, adjacency);
|
|
575
752
|
const behindClusters = buildClusters(targets, behindAdjacency);
|
|
576
753
|
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
754
|
+
// Exiting groups are condemned: their members are already released and
|
|
755
|
+
// a removal timer is running. Excluding them here keeps a new grouping
|
|
756
|
+
// pass from re-disbanding them, which would reset the removal timer on
|
|
757
|
+
// every pass and leak group chrome forever under continuous churn.
|
|
758
|
+
const existingGroups = this.getAutoGroups().filter(
|
|
759
|
+
(group) => !group.hasAttribute('data-exiting')
|
|
760
|
+
);
|
|
580
761
|
|
|
581
762
|
const frontTargets = new Set<Poi>();
|
|
582
763
|
clusters.forEach((cluster) => {
|
|
@@ -594,12 +775,31 @@ export class ObcPoiLayer extends LitElement {
|
|
|
594
775
|
(group) => group.expand === true || group.collapsing === true
|
|
595
776
|
);
|
|
596
777
|
if (expandedAutoGroup) {
|
|
597
|
-
|
|
598
|
-
this.tryJoinExpandedGroup(
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
778
|
+
const joined = this.joinWhileExpanded
|
|
779
|
+
? this.tryJoinExpandedGroup(
|
|
780
|
+
expandedAutoGroup,
|
|
781
|
+
targets,
|
|
782
|
+
rects,
|
|
783
|
+
enterThreshold
|
|
784
|
+
)
|
|
785
|
+
: null;
|
|
786
|
+
if (joined) {
|
|
787
|
+
// The geometric clusters predate the join; report the live groups.
|
|
788
|
+
const liveClusters = existingGroups.map((group) =>
|
|
789
|
+
this.getGroupMembers(group)
|
|
790
|
+
);
|
|
791
|
+
const liveFront = new Set<Poi>();
|
|
792
|
+
liveClusters.forEach((cluster) => {
|
|
793
|
+
const front = this.getFrontTarget(cluster, rects);
|
|
794
|
+
if (front) liveFront.add(front);
|
|
795
|
+
});
|
|
796
|
+
behindTargets.delete(joined);
|
|
797
|
+
preGrouped.delete(joined);
|
|
798
|
+
this.notifyGroupingChange(
|
|
799
|
+
liveClusters,
|
|
800
|
+
liveFront,
|
|
801
|
+
behindTargets,
|
|
802
|
+
preGrouped
|
|
603
803
|
);
|
|
604
804
|
}
|
|
605
805
|
return;
|
|
@@ -609,9 +809,7 @@ export class ObcPoiLayer extends LitElement {
|
|
|
609
809
|
const keptGroups: HTMLElement[] = [];
|
|
610
810
|
|
|
611
811
|
existingGroups.forEach((group) => {
|
|
612
|
-
const children =
|
|
613
|
-
(child): child is Poi => isPoi(child)
|
|
614
|
-
);
|
|
812
|
+
const children = this.getGroupMembers(group);
|
|
615
813
|
const matchIndex = remainingClusters.findIndex(
|
|
616
814
|
(cluster) =>
|
|
617
815
|
cluster.length === children.length &&
|
|
@@ -645,7 +843,10 @@ export class ObcPoiLayer extends LitElement {
|
|
|
645
843
|
});
|
|
646
844
|
group.removeAttribute('data-visible');
|
|
647
845
|
group.setAttribute('data-exiting', 'true');
|
|
648
|
-
|
|
846
|
+
// Release members back to the main slot — their DOM position never
|
|
847
|
+
// changed, only the slot assignment does.
|
|
848
|
+
this.getAutoGroupMemberSlot(group)?.assign();
|
|
849
|
+
this.syncSlotAssignments();
|
|
649
850
|
children.forEach((child) => {
|
|
650
851
|
if (!front || child !== front) {
|
|
651
852
|
child.getBoundingClientRect();
|
|
@@ -673,14 +874,20 @@ export class ObcPoiLayer extends LitElement {
|
|
|
673
874
|
(group as PoiButtonGroupElement).internalSwapping =
|
|
674
875
|
!!this.internalSwapping;
|
|
675
876
|
group.setAttribute(
|
|
676
|
-
'
|
|
877
|
+
'position-vertical',
|
|
677
878
|
`${this.getGroupPositionVertical(cluster, rects, layerRect, group)}px`
|
|
678
879
|
);
|
|
880
|
+
const memberSlot = document.createElement('slot');
|
|
881
|
+
memberSlot.className = 'auto-group-members';
|
|
882
|
+
group.appendChild(memberSlot);
|
|
679
883
|
cluster.forEach((target) => {
|
|
680
884
|
target.removeAttribute('data-grouped');
|
|
681
|
-
group.appendChild(target);
|
|
682
885
|
});
|
|
683
|
-
|
|
886
|
+
// The group lives in the layer's shadow root; members stay in the
|
|
887
|
+
// consumer's light DOM and are slot-assigned into the group.
|
|
888
|
+
this.wrapper?.appendChild(group);
|
|
889
|
+
memberSlot.assign(...cluster);
|
|
890
|
+
this.syncSlotAssignments();
|
|
684
891
|
requestAnimationFrame(() => {
|
|
685
892
|
cluster.forEach((target) =>
|
|
686
893
|
target.setAttribute('data-grouped', 'true')
|
|
@@ -691,8 +898,8 @@ export class ObcPoiLayer extends LitElement {
|
|
|
691
898
|
|
|
692
899
|
const groupedTargets = new Set<Poi>();
|
|
693
900
|
keptGroups.forEach((group) => {
|
|
694
|
-
|
|
695
|
-
|
|
901
|
+
this.getGroupMembers(group).forEach((child) => {
|
|
902
|
+
groupedTargets.add(child);
|
|
696
903
|
});
|
|
697
904
|
});
|
|
698
905
|
|
|
@@ -743,6 +950,12 @@ export class ObcPoiLayer extends LitElement {
|
|
|
743
950
|
});
|
|
744
951
|
|
|
745
952
|
this.refreshGroupPositions(layerRect, rects);
|
|
953
|
+
this.notifyGroupingChange(
|
|
954
|
+
clusters,
|
|
955
|
+
frontTargets,
|
|
956
|
+
behindTargets,
|
|
957
|
+
preGrouped
|
|
958
|
+
);
|
|
746
959
|
|
|
747
960
|
requestAnimationFrame(() => {
|
|
748
961
|
targets.forEach((target) => target.removeAttribute('data-front-exit'));
|
|
@@ -759,17 +972,18 @@ export class ObcPoiLayer extends LitElement {
|
|
|
759
972
|
targets: Poi[],
|
|
760
973
|
rects: Map<Poi, DOMRect>,
|
|
761
974
|
enterThreshold: number
|
|
762
|
-
) {
|
|
975
|
+
): Poi | null {
|
|
763
976
|
const groupTargets = this.getGroupTargets(group);
|
|
764
|
-
if (groupTargets.length === 0) return;
|
|
977
|
+
if (groupTargets.length === 0) return null;
|
|
765
978
|
|
|
766
979
|
const groupTargetSet = new Set(groupTargets);
|
|
767
980
|
const candidates = targets.filter(
|
|
768
981
|
(target) =>
|
|
769
982
|
!groupTargetSet.has(target) &&
|
|
770
|
-
target.parentElement?.tagName.toLowerCase() !== 'obc-poi-group'
|
|
983
|
+
target.parentElement?.tagName.toLowerCase() !== 'obc-poi-group' &&
|
|
984
|
+
this.getAutoGroupOf(target) === null
|
|
771
985
|
);
|
|
772
|
-
if (candidates.length === 0) return;
|
|
986
|
+
if (candidates.length === 0) return null;
|
|
773
987
|
|
|
774
988
|
const useButtonRects = group.expand === true || group.collapsing === true;
|
|
775
989
|
const groupCenters = groupTargets
|
|
@@ -778,7 +992,7 @@ export class ObcPoiLayer extends LitElement {
|
|
|
778
992
|
)
|
|
779
993
|
.filter((rect): rect is DOMRect => !!rect)
|
|
780
994
|
.map((rect) => rect.left + rect.width / 2);
|
|
781
|
-
if (groupCenters.length === 0) return;
|
|
995
|
+
if (groupCenters.length === 0) return null;
|
|
782
996
|
|
|
783
997
|
const leftMost = Math.min(...groupCenters);
|
|
784
998
|
const rightMost = Math.max(...groupCenters);
|
|
@@ -813,7 +1027,7 @@ export class ObcPoiLayer extends LitElement {
|
|
|
813
1027
|
}
|
|
814
1028
|
}
|
|
815
1029
|
|
|
816
|
-
if (!bestCandidate) return;
|
|
1030
|
+
if (!bestCandidate) return null;
|
|
817
1031
|
|
|
818
1032
|
bestCandidate.setAttribute('data-joined-expanded', 'true');
|
|
819
1033
|
|
|
@@ -824,7 +1038,19 @@ export class ObcPoiLayer extends LitElement {
|
|
|
824
1038
|
: 0;
|
|
825
1039
|
const insertBefore = candidateCenter < groupCenter;
|
|
826
1040
|
|
|
827
|
-
|
|
1041
|
+
const memberSlot =
|
|
1042
|
+
group instanceof HTMLElement ? this.getAutoGroupMemberSlot(group) : null;
|
|
1043
|
+
if (memberSlot) {
|
|
1044
|
+
const members = memberSlot
|
|
1045
|
+
.assignedElements()
|
|
1046
|
+
.filter((el) => el !== bestCandidate);
|
|
1047
|
+
memberSlot.assign(
|
|
1048
|
+
...(insertBefore
|
|
1049
|
+
? [bestCandidate, ...members]
|
|
1050
|
+
: [...members, bestCandidate])
|
|
1051
|
+
);
|
|
1052
|
+
this.syncSlotAssignments();
|
|
1053
|
+
} else if (insertBefore) {
|
|
828
1054
|
group.insertBefore(bestCandidate, groupTargets[0] ?? null);
|
|
829
1055
|
} else {
|
|
830
1056
|
group.appendChild(bestCandidate);
|
|
@@ -848,6 +1074,7 @@ export class ObcPoiLayer extends LitElement {
|
|
|
848
1074
|
}
|
|
849
1075
|
|
|
850
1076
|
group.refreshExpandedLayout?.(true);
|
|
1077
|
+
return bestCandidate;
|
|
851
1078
|
}
|
|
852
1079
|
|
|
853
1080
|
private applyStandaloneVisualState(target: Poi, overlap: boolean) {
|
|
@@ -875,17 +1102,16 @@ export class ObcPoiLayer extends LitElement {
|
|
|
875
1102
|
layerRect?: DOMRect,
|
|
876
1103
|
rects?: Map<Poi, DOMRect>
|
|
877
1104
|
) {
|
|
878
|
-
const groups =
|
|
879
|
-
|
|
880
|
-
|
|
1105
|
+
const groups = [
|
|
1106
|
+
...(Array.from(
|
|
1107
|
+
this.querySelectorAll('obc-poi-group')
|
|
1108
|
+
) as PoiButtonGroupElement[]),
|
|
1109
|
+
...this.getAutoGroups(),
|
|
1110
|
+
];
|
|
881
1111
|
groups.forEach((group) => {
|
|
882
|
-
const children =
|
|
883
|
-
(child): child is Poi => isPoi(child)
|
|
884
|
-
);
|
|
1112
|
+
const children = this.getGroupMembers(group);
|
|
885
1113
|
this.toggleGroupLayerHook(group, children.length > 0);
|
|
886
|
-
const hasPositionAttr =
|
|
887
|
-
group.hasAttribute('positionvertical') ||
|
|
888
|
-
group.hasAttribute('positionVertical');
|
|
1114
|
+
const hasPositionAttr = group.hasAttribute('position-vertical');
|
|
889
1115
|
if (
|
|
890
1116
|
!group.hasAttribute('data-auto-group') &&
|
|
891
1117
|
!group.hasAttribute('data-position-mode')
|
|
@@ -909,7 +1135,7 @@ export class ObcPoiLayer extends LitElement {
|
|
|
909
1135
|
])
|
|
910
1136
|
);
|
|
911
1137
|
group.setAttribute(
|
|
912
|
-
'
|
|
1138
|
+
'position-vertical',
|
|
913
1139
|
`${this.getGroupPositionVertical(children, rectMap, layerBounds, group)}px`
|
|
914
1140
|
);
|
|
915
1141
|
}
|
|
@@ -1123,15 +1349,7 @@ export class ObcPoiLayer extends LitElement {
|
|
|
1123
1349
|
}
|
|
1124
1350
|
|
|
1125
1351
|
private getGroupTargets(group: ParentNode): Poi[] {
|
|
1126
|
-
return
|
|
1127
|
-
(node): node is Poi => isPoi(node)
|
|
1128
|
-
);
|
|
1129
|
-
}
|
|
1130
|
-
|
|
1131
|
-
protected override updated(changedProperties: PropertyValues): void {
|
|
1132
|
-
if (changedProperties.has('isSelected')) {
|
|
1133
|
-
this.dispatchEvent(new Event('layer-selection-changed', {bubbles: true}));
|
|
1134
|
-
}
|
|
1352
|
+
return this.getGroupMembers(group);
|
|
1135
1353
|
}
|
|
1136
1354
|
|
|
1137
1355
|
override render() {
|
|
@@ -1142,11 +1360,18 @@ export class ObcPoiLayer extends LitElement {
|
|
|
1142
1360
|
? html`<span class="debug-label">${this.label || 'Layer'}</span>`
|
|
1143
1361
|
: nothing
|
|
1144
1362
|
}
|
|
1145
|
-
<slot></slot>
|
|
1363
|
+
<slot class="main"></slot>
|
|
1146
1364
|
</div>
|
|
1147
1365
|
`;
|
|
1148
1366
|
}
|
|
1149
1367
|
|
|
1368
|
+
protected override updated(changedProperties: PropertyValues): void {
|
|
1369
|
+
if (changedProperties.has('isSelected')) {
|
|
1370
|
+
this.dispatchEvent(new Event('layer-selection-changed', {bubbles: true}));
|
|
1371
|
+
}
|
|
1372
|
+
this.syncSlotAssignments();
|
|
1373
|
+
}
|
|
1374
|
+
|
|
1150
1375
|
static override styles = unsafeCSS(componentStyle);
|
|
1151
1376
|
}
|
|
1152
1377
|
|
|
@@ -10,9 +10,7 @@ import '../../icons/icon-placeholder.js';
|
|
|
10
10
|
import '../../icons/icon-beacon-general-east.js';
|
|
11
11
|
import '../../icons/icon-vessel-type-psv-outlined.js';
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
(globalThis as {__vitest_browser__?: unknown}).__vitest_browser__
|
|
15
|
-
);
|
|
13
|
+
import {isVitestBrowser, waitForStorySettle} from '../_test-utils.js';
|
|
16
14
|
|
|
17
15
|
type PoiLayerStackArgs = {
|
|
18
16
|
label: string;
|
|
@@ -73,26 +71,6 @@ const selectionMultiAnimatedSnapshotPose: AnimatedPoiSnapshotPose[] = [
|
|
|
73
71
|
{x: 119, y: 87, boxWidth: 36, boxHeight: 38},
|
|
74
72
|
];
|
|
75
73
|
|
|
76
|
-
const waitForStorySettle = async (
|
|
77
|
-
options: {drainTransitions?: boolean} = {}
|
|
78
|
-
) => {
|
|
79
|
-
if ('fonts' in document) {
|
|
80
|
-
await (document as Document & {fonts?: FontFaceSet}).fonts?.ready;
|
|
81
|
-
}
|
|
82
|
-
await new Promise<void>((resolve) =>
|
|
83
|
-
requestAnimationFrame(() => requestAnimationFrame(() => resolve()))
|
|
84
|
-
);
|
|
85
|
-
|
|
86
|
-
if (options.drainTransitions && isVitestBrowser) {
|
|
87
|
-
await new Promise<void>((resolve) => {
|
|
88
|
-
setTimeout(resolve, 220);
|
|
89
|
-
});
|
|
90
|
-
await new Promise<void>((resolve) =>
|
|
91
|
-
requestAnimationFrame(() => requestAnimationFrame(() => resolve()))
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
|
|
96
74
|
const renderTwoLayers = (args: PoiLayerStackArgs) => html`
|
|
97
75
|
<style>
|
|
98
76
|
obc-poi-layer-stack.stack {
|
|
@@ -424,3 +402,58 @@ export const MixedComponentTypes: Story = {
|
|
|
424
402
|
await waitForStorySettle({drainTransitions: true});
|
|
425
403
|
},
|
|
426
404
|
};
|
|
405
|
+
|
|
406
|
+
export const SelectionHandling: Story = {
|
|
407
|
+
args: {
|
|
408
|
+
selectionMode: PoiLayerSelectionMode.Single,
|
|
409
|
+
},
|
|
410
|
+
render: (args) => html`
|
|
411
|
+
<style>
|
|
412
|
+
.selection-readout {
|
|
413
|
+
margin-top: 8px;
|
|
414
|
+
font: 12px sans-serif;
|
|
415
|
+
}
|
|
416
|
+
</style>
|
|
417
|
+
<obc-poi-layer-stack
|
|
418
|
+
id="selection-handling-stack"
|
|
419
|
+
selection-mode=${args.selectionMode}
|
|
420
|
+
@selection-change=${(event: CustomEvent<{selected: unknown[]}>) => {
|
|
421
|
+
const readout = document.querySelector('#selection-readout');
|
|
422
|
+
if (readout) {
|
|
423
|
+
readout.textContent = `Selected targets: ${event.detail.selected.length}`;
|
|
424
|
+
}
|
|
425
|
+
}}
|
|
426
|
+
>
|
|
427
|
+
<obc-poi-layer
|
|
428
|
+
label="Selected"
|
|
429
|
+
is-selected
|
|
430
|
+
style="--obc-poi-layer-min-height: 140px"
|
|
431
|
+
></obc-poi-layer>
|
|
432
|
+
<obc-poi-layer label="Vessels" style="--obc-poi-layer-min-height: 140px">
|
|
433
|
+
<obc-poi-vessel .x=${120} .y=${90}>
|
|
434
|
+
<obi-vessel-type-psv-outlined></obi-vessel-type-psv-outlined>
|
|
435
|
+
</obc-poi-vessel>
|
|
436
|
+
<obc-poi-vessel .x=${320} .y=${110}>
|
|
437
|
+
<obi-vessel-type-psv-outlined></obi-vessel-type-psv-outlined>
|
|
438
|
+
</obc-poi-vessel>
|
|
439
|
+
</obc-poi-layer>
|
|
440
|
+
</obc-poi-layer-stack>
|
|
441
|
+
<div id="selection-readout" class="selection-readout">
|
|
442
|
+
Selected targets: 0
|
|
443
|
+
</div>
|
|
444
|
+
`,
|
|
445
|
+
play: async () => {
|
|
446
|
+
await waitForStorySettle({drainTransitions: true});
|
|
447
|
+
const stack = document.querySelector('#selection-handling-stack') as {
|
|
448
|
+
selectTarget?: (
|
|
449
|
+
target: Element,
|
|
450
|
+
options?: {selectionId?: string}
|
|
451
|
+
) => boolean;
|
|
452
|
+
} | null;
|
|
453
|
+
const target = document.querySelector('obc-poi-vessel');
|
|
454
|
+
if (stack?.selectTarget && target) {
|
|
455
|
+
stack.selectTarget(target, {selectionId: '7'});
|
|
456
|
+
}
|
|
457
|
+
await waitForStorySettle({drainTransitions: true});
|
|
458
|
+
},
|
|
459
|
+
};
|