@sixbell-telco/sdk 4.3.0 → 4.5.0
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/CHANGELOG.md +35 -1
- package/components/dropdown/README.md +1 -1
- package/components/dropdown/dropdown-chevron/dropdown-chevron.component.d.ts +1 -1
- package/components/dropdown/dropdown-trigger/dropdown-trigger.component.d.ts +10 -13
- package/components/dropdown-menu/README.md +1 -1
- package/components/dropdown-menu/bar/dropdown-menu-bar-content/dropdown-menu-bar-content.component.d.ts +5 -1
- package/components/dropdown-menu/bar/dropdown-menu-bar-sub-trigger/dropdown-menu-bar-sub-trigger.component.d.ts +2 -0
- package/components/dropdown-menu/bar/dropdown-menu-bar-trigger/dropdown-menu-bar-trigger.component.d.ts +2 -0
- package/components/dropdown-menu/context/dropdown-context-menu-trigger/dropdown-context-menu-trigger.component.d.ts +1 -0
- package/components/dropdown-menu/src/dropdown-menu-content/dropdown-menu-content.component.d.ts +2 -0
- package/components/dropdown-menu/src/dropdown-menu-sub-content/dropdown-menu-sub-content.component.d.ts +2 -0
- package/components/dropdown-menu/src/dropdown-menu-sub-trigger/dropdown-menu-sub-trigger.component.d.ts +1 -0
- package/components/dropdown-menu/src/dropdown-menu-trigger/dropdown-menu-trigger.component.d.ts +1 -0
- package/components/forms/combobox/README.md +1 -1
- package/components/forms/combobox/src/combobox.component.d.ts +10 -11
- package/components/forms/select/README.md +1 -1
- package/components/forms/select/src/select.component.d.ts +10 -11
- package/components/overlay/README.md +6 -1
- package/components/overlay/src/overlay.component.d.ts +9 -8
- package/components/tooltip/README.md +3 -2
- package/components/tooltip/src/tooltip.component.d.ts +8 -8
- package/fesm2022/sixbell-telco-sdk-components-dropdown-menu-bar.mjs +18 -9
- package/fesm2022/sixbell-telco-sdk-components-dropdown-menu-bar.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-dropdown-menu-context.mjs +5 -1
- package/fesm2022/sixbell-telco-sdk-components-dropdown-menu-context.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-dropdown-menu.mjs +20 -9
- package/fesm2022/sixbell-telco-sdk-components-dropdown-menu.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-dropdown.mjs +26 -55
- package/fesm2022/sixbell-telco-sdk-components-dropdown.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-combobox.mjs +35 -49
- package/fesm2022/sixbell-telco-sdk-components-forms-combobox.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-select.mjs +35 -43
- package/fesm2022/sixbell-telco-sdk-components-forms-select.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-overlay.mjs +39 -77
- package/fesm2022/sixbell-telco-sdk-components-overlay.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-tooltip.mjs +33 -52
- package/fesm2022/sixbell-telco-sdk-components-tooltip.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-layouts.mjs +35 -13
- package/fesm2022/sixbell-telco-sdk-layouts.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-utils-popover-motion.mjs +186 -0
- package/fesm2022/sixbell-telco-sdk-utils-popover-motion.mjs.map +1 -0
- package/fesm2022/sixbell-telco-sdk-utils-translation.mjs +129 -14
- package/fesm2022/sixbell-telco-sdk-utils-translation.mjs.map +1 -1
- package/layouts/README.md +15 -1
- package/layouts/public-api.d.ts +2 -2
- package/layouts/src/layout-account.d.ts +16 -0
- package/layouts/src/menu/menu-active.d.ts +2 -1
- package/layouts/src/menu/menu-url.d.ts +2 -0
- package/layouts/src/page-banner/page-banner.component.d.ts +13 -1
- package/layouts/src/user-menu/user-menu.component.d.ts +4 -2
- package/package.json +41 -37
- package/src/_index.css +85 -0
- package/utils/popover-motion/README.md +38 -0
- package/utils/popover-motion/index.d.ts +5 -0
- package/utils/popover-motion/public-api.d.ts +2 -0
- package/utils/popover-motion/src/popover-menu-motion.d.ts +37 -0
- package/utils/popover-motion/src/popover-motion.d.ts +31 -0
- package/utils/translation/README.md +2 -0
- package/utils/translation/src/translation.service.d.ts +24 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { CDK_MENU, MENU_TRIGGER } from '@angular/cdk/menu';
|
|
2
|
+
import { STANDARD_DROPDOWN_BELOW_POSITIONS, STANDARD_DROPDOWN_ADJACENT_POSITIONS } from '@angular/cdk/overlay';
|
|
3
|
+
import * as i0 from '@angular/core';
|
|
4
|
+
import { inject, ElementRef, input, signal, afterNextRender, DestroyRef, Directive } from '@angular/core';
|
|
5
|
+
import { ThemeDomService } from '@sixbell-telco/sdk/utils/theme';
|
|
6
|
+
|
|
7
|
+
/** Keyframe names the `popover-motion` utility plays while opening and closing. */
|
|
8
|
+
const POPOVER_MOTION_ANIMATIONS = { opening: 'st-popover-in', closing: 'st-popover-out' };
|
|
9
|
+
const ALIGN_FROM_Y = { top: 'start', center: 'center', bottom: 'end' };
|
|
10
|
+
/**
|
|
11
|
+
* Placement of a panel from the CDK connection pair it was applied with (`positionChange`).
|
|
12
|
+
* A pair that overlaps the trigger instead of sitting beside it falls back to its vertical anchor.
|
|
13
|
+
*/
|
|
14
|
+
function popoverPlacement(pair) {
|
|
15
|
+
if (pair.originY === 'bottom' && pair.overlayY === 'top')
|
|
16
|
+
return { side: 'bottom', align: pair.overlayX };
|
|
17
|
+
if (pair.originY === 'top' && pair.overlayY === 'bottom')
|
|
18
|
+
return { side: 'top', align: pair.overlayX };
|
|
19
|
+
if (pair.originX === 'end' && pair.overlayX === 'start')
|
|
20
|
+
return { side: 'right', align: ALIGN_FROM_Y[pair.overlayY] };
|
|
21
|
+
if (pair.originX === 'start' && pair.overlayX === 'end')
|
|
22
|
+
return { side: 'left', align: ALIGN_FROM_Y[pair.overlayY] };
|
|
23
|
+
return { side: pair.overlayY === 'bottom' ? 'top' : 'bottom', align: pair.overlayX };
|
|
24
|
+
}
|
|
25
|
+
/** Whether an `animationend` / `animationcancel` belongs to the `popover-motion` phase. */
|
|
26
|
+
function isPopoverMotionAnimation(event, phase) {
|
|
27
|
+
return event.animationName === POPOVER_MOTION_ANIMATIONS[phase];
|
|
28
|
+
}
|
|
29
|
+
const OPPOSITE_EDGES = { top: 'bottom', bottom: 'top', start: 'end', end: 'start' };
|
|
30
|
+
/**
|
|
31
|
+
* Offset for a fallback position derived from a primary one: negated when the fallback anchors the
|
|
32
|
+
* opposite edge (a flip), so a gap between trigger and panel stays a gap on either side.
|
|
33
|
+
*/
|
|
34
|
+
function mirrorPopoverOffset(offset, from, to) {
|
|
35
|
+
const value = offset ?? 0;
|
|
36
|
+
return OPPOSITE_EDGES[from] === to && value !== 0 ? -value : value;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const SIDE_CLASS = 'st-popover-side-';
|
|
40
|
+
const ALIGN_CLASS = 'st-popover-align-';
|
|
41
|
+
const SIDES = ['top', 'right', 'bottom', 'left'];
|
|
42
|
+
const ALIGNS = ['start', 'center', 'end'];
|
|
43
|
+
/** Gap in pixels between a menu trigger and a menu opened below or above it */
|
|
44
|
+
const MENU_GAP = 4;
|
|
45
|
+
/** Tag each position with pane classes naming its placement, so the menu panel can read where the CDK put it */
|
|
46
|
+
function withPlacementClasses(positions) {
|
|
47
|
+
return positions.map((position) => {
|
|
48
|
+
const { side, align } = popoverPlacement(position);
|
|
49
|
+
const own = position.panelClass ? [].concat(position.panelClass) : [];
|
|
50
|
+
return { ...position, panelClass: [...own, `${SIDE_CLASS}${side}`, `${ALIGN_CLASS}${align}`] };
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
const MENU_BELOW_POSITIONS = withPlacementClasses(STANDARD_DROPDOWN_BELOW_POSITIONS.map((position) => ({ ...position, offsetY: position.overlayY === 'top' ? MENU_GAP : -MENU_GAP })));
|
|
54
|
+
const MENU_ADJACENT_POSITIONS = withPlacementClasses(STANDARD_DROPDOWN_ADJACENT_POSITIONS);
|
|
55
|
+
const CONTEXT_MENU_POSITIONS = withPlacementClasses(STANDARD_DROPDOWN_BELOW_POSITIONS.map((position) => ({
|
|
56
|
+
...position,
|
|
57
|
+
offsetX: position.overlayX === 'start' ? 2 : -2,
|
|
58
|
+
offsetY: position.overlayY === 'top' ? 2 : -2,
|
|
59
|
+
})));
|
|
60
|
+
/**
|
|
61
|
+
* Positions for a CDK menu trigger, the same placements the CDK picks by default (below a root or
|
|
62
|
+
* menu-bar trigger with a 4px gap, beside a trigger inside a vertical menu), tagged for `popover-motion`.
|
|
63
|
+
* Call it in the injection context of the trigger.
|
|
64
|
+
*/
|
|
65
|
+
function popoverMenuPositions() {
|
|
66
|
+
const parentMenu = inject(CDK_MENU, { optional: true });
|
|
67
|
+
return parentMenu?.orientation === 'vertical' ? MENU_ADJACENT_POSITIONS : MENU_BELOW_POSITIONS;
|
|
68
|
+
}
|
|
69
|
+
/** Positions for a CDK context menu trigger (the CDK defaults), tagged for `popover-motion` */
|
|
70
|
+
function popoverContextMenuPositions() {
|
|
71
|
+
return CONTEXT_MENU_POSITIONS;
|
|
72
|
+
}
|
|
73
|
+
function readPlacement(pane) {
|
|
74
|
+
const classes = pane?.classList;
|
|
75
|
+
const side = SIDES.find((value) => classes?.contains(`${SIDE_CLASS}${value}`));
|
|
76
|
+
const align = ALIGNS.find((value) => classes?.contains(`${ALIGN_CLASS}${value}`)) ?? 'start';
|
|
77
|
+
if (side)
|
|
78
|
+
return { side, align };
|
|
79
|
+
// Untagged positions (a trigger with its own cdkMenuPosition): the CDK pins `bottom` only for panels above the trigger.
|
|
80
|
+
return { side: pane?.style.bottom ? 'top' : 'bottom', align };
|
|
81
|
+
}
|
|
82
|
+
function longestAnimationMs(element) {
|
|
83
|
+
const style = getComputedStyle(element);
|
|
84
|
+
const toMs = (value) => {
|
|
85
|
+
const parsed = Number.parseFloat(value);
|
|
86
|
+
if (!Number.isFinite(parsed))
|
|
87
|
+
return 0;
|
|
88
|
+
return value.trim().endsWith('ms') ? parsed : parsed * 1000;
|
|
89
|
+
};
|
|
90
|
+
const durations = (style.animationDuration ?? '').split(',').map(toMs);
|
|
91
|
+
const delays = (style.animationDelay ?? '').split(',').map(toMs);
|
|
92
|
+
return Math.max(0, ...durations.map((duration, index) => duration + (delays[index] ?? delays[0] ?? 0)));
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* `popover-motion` for a CDK menu panel (`cdkMenu`). The entrance starts once the CDK placed the pane.
|
|
96
|
+
* The CDK detaches a menu the moment it closes, so the exit plays on an inert, hidden-from-AT snapshot
|
|
97
|
+
* of the panel at the same spot, removed when its animation ends.
|
|
98
|
+
* The panel is portaled out of its page, so it takes the theme of `stPopoverMenuMotionTheme` (the element
|
|
99
|
+
* that declares the menu), as `st-dropdown` does for its panel; the snapshot keeps it.
|
|
100
|
+
*/
|
|
101
|
+
class PopoverMenuMotionDirective {
|
|
102
|
+
element = inject(ElementRef).nativeElement;
|
|
103
|
+
trigger = inject(MENU_TRIGGER, { optional: true });
|
|
104
|
+
themeDom = inject(ThemeDomService);
|
|
105
|
+
/** Element whose nearest `data-theme` the portaled panel takes */
|
|
106
|
+
stPopoverMenuMotionTheme = input(null);
|
|
107
|
+
/** @internal */
|
|
108
|
+
theme() {
|
|
109
|
+
return this.themeDom.themeOf(this.stPopoverMenuMotionTheme());
|
|
110
|
+
}
|
|
111
|
+
/** @internal */
|
|
112
|
+
state = signal(this.trigger ? 'opening' : 'open');
|
|
113
|
+
/** @internal */
|
|
114
|
+
placement = signal(null);
|
|
115
|
+
constructor() {
|
|
116
|
+
if (!this.trigger)
|
|
117
|
+
return;
|
|
118
|
+
afterNextRender({ read: () => this.placement.set(readPlacement(this.element.parentElement)) });
|
|
119
|
+
const subscription = this.trigger.closed.subscribe(() => this.playExit());
|
|
120
|
+
inject(DestroyRef).onDestroy(() => subscription.unsubscribe());
|
|
121
|
+
}
|
|
122
|
+
/** @internal */
|
|
123
|
+
onAnimationEnd(event) {
|
|
124
|
+
if (event.target === this.element && this.state() === 'opening' && isPopoverMotionAnimation(event, 'opening')) {
|
|
125
|
+
this.state.set('open');
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
playExit() {
|
|
129
|
+
const pane = this.element.parentElement;
|
|
130
|
+
const layer = pane?.parentElement?.parentElement;
|
|
131
|
+
if (!pane || !layer || !this.element.isConnected)
|
|
132
|
+
return;
|
|
133
|
+
const rect = this.element.getBoundingClientRect();
|
|
134
|
+
const holder = this.element.ownerDocument.createElement('div');
|
|
135
|
+
holder.setAttribute('aria-hidden', 'true');
|
|
136
|
+
holder.setAttribute('inert', '');
|
|
137
|
+
Object.assign(holder.style, {
|
|
138
|
+
position: 'fixed',
|
|
139
|
+
left: `${rect.left}px`,
|
|
140
|
+
top: `${rect.top}px`,
|
|
141
|
+
width: `${rect.width}px`,
|
|
142
|
+
pointerEvents: 'none',
|
|
143
|
+
zIndex: getComputedStyle(pane.parentElement).zIndex || '1000',
|
|
144
|
+
});
|
|
145
|
+
const snapshot = this.element.cloneNode(true);
|
|
146
|
+
[snapshot, ...Array.from(snapshot.querySelectorAll('[id]'))].forEach((node) => node.removeAttribute('id'));
|
|
147
|
+
snapshot.setAttribute('data-state', 'closing');
|
|
148
|
+
holder.appendChild(snapshot);
|
|
149
|
+
layer.appendChild(holder);
|
|
150
|
+
let timer = null;
|
|
151
|
+
const remove = () => {
|
|
152
|
+
if (timer !== null)
|
|
153
|
+
clearTimeout(timer);
|
|
154
|
+
holder.remove();
|
|
155
|
+
};
|
|
156
|
+
snapshot.addEventListener('animationend', (event) => {
|
|
157
|
+
if (event.target === snapshot && isPopoverMotionAnimation(event, 'closing'))
|
|
158
|
+
remove();
|
|
159
|
+
});
|
|
160
|
+
timer = setTimeout(remove, longestAnimationMs(snapshot) + 50);
|
|
161
|
+
}
|
|
162
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: PopoverMenuMotionDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
163
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "19.2.25", type: PopoverMenuMotionDirective, isStandalone: true, selector: "[stPopoverMenuMotion]", inputs: { stPopoverMenuMotionTheme: { classPropertyName: "stPopoverMenuMotionTheme", publicName: "stPopoverMenuMotionTheme", isSignal: true, isRequired: false, transformFunction: null } }, host: { listeners: { "animationend": "onAnimationEnd($event)" }, properties: { "attr.data-state": "state()", "attr.data-side": "placement()?.side", "attr.data-align": "placement()?.align", "attr.data-theme": "theme()" }, classAttribute: "popover-motion" }, ngImport: i0 });
|
|
164
|
+
}
|
|
165
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: PopoverMenuMotionDirective, decorators: [{
|
|
166
|
+
type: Directive,
|
|
167
|
+
args: [{
|
|
168
|
+
selector: '[stPopoverMenuMotion]',
|
|
169
|
+
standalone: true,
|
|
170
|
+
host: {
|
|
171
|
+
class: 'popover-motion',
|
|
172
|
+
'[attr.data-state]': 'state()',
|
|
173
|
+
'[attr.data-side]': 'placement()?.side',
|
|
174
|
+
'[attr.data-align]': 'placement()?.align',
|
|
175
|
+
'[attr.data-theme]': 'theme()',
|
|
176
|
+
'(animationend)': 'onAnimationEnd($event)',
|
|
177
|
+
},
|
|
178
|
+
}]
|
|
179
|
+
}], ctorParameters: () => [] });
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Generated bundle index. Do not edit.
|
|
183
|
+
*/
|
|
184
|
+
|
|
185
|
+
export { POPOVER_MOTION_ANIMATIONS, PopoverMenuMotionDirective, isPopoverMotionAnimation, mirrorPopoverOffset, popoverContextMenuPositions, popoverMenuPositions, popoverPlacement };
|
|
186
|
+
//# sourceMappingURL=sixbell-telco-sdk-utils-popover-motion.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sixbell-telco-sdk-utils-popover-motion.mjs","sources":["../../../projects/sdk/utils/popover-motion/src/popover-motion.ts","../../../projects/sdk/utils/popover-motion/src/popover-menu-motion.ts","../../../projects/sdk/utils/popover-motion/sixbell-telco-sdk-utils-popover-motion.ts"],"sourcesContent":["import type { ConnectedPosition } from '@angular/cdk/overlay';\n\n/** Side of the trigger the panel was placed on. */\nexport type PopoverSide = 'top' | 'right' | 'bottom' | 'left';\n\n/** Edge of the trigger the panel lines up with, along the side. */\nexport type PopoverAlign = 'start' | 'center' | 'end';\n\n/** Where the CDK placed a panel, as `data-side` / `data-align` on a `popover-motion` element. */\nexport interface PopoverPlacement {\n\treadonly side: PopoverSide;\n\treadonly align: PopoverAlign;\n}\n\n/** Lifecycle of a `popover-motion` panel, bound to its `data-state`. */\nexport type PopoverMotionState = 'closed' | 'opening' | 'open' | 'closing';\n\n/** Keyframe names the `popover-motion` utility plays while opening and closing. */\nexport const POPOVER_MOTION_ANIMATIONS = { opening: 'st-popover-in', closing: 'st-popover-out' } as const;\n\ntype PositionPair = Pick<ConnectedPosition, 'originX' | 'originY' | 'overlayX' | 'overlayY'>;\n\nconst ALIGN_FROM_Y = { top: 'start', center: 'center', bottom: 'end' } as const satisfies Record<ConnectedPosition['overlayY'], PopoverAlign>;\n\n/**\n * Placement of a panel from the CDK connection pair it was applied with (`positionChange`).\n * A pair that overlaps the trigger instead of sitting beside it falls back to its vertical anchor.\n */\nexport function popoverPlacement(pair: PositionPair): PopoverPlacement {\n\tif (pair.originY === 'bottom' && pair.overlayY === 'top') return { side: 'bottom', align: pair.overlayX };\n\tif (pair.originY === 'top' && pair.overlayY === 'bottom') return { side: 'top', align: pair.overlayX };\n\tif (pair.originX === 'end' && pair.overlayX === 'start') return { side: 'right', align: ALIGN_FROM_Y[pair.overlayY] };\n\tif (pair.originX === 'start' && pair.overlayX === 'end') return { side: 'left', align: ALIGN_FROM_Y[pair.overlayY] };\n\treturn { side: pair.overlayY === 'bottom' ? 'top' : 'bottom', align: pair.overlayX };\n}\n\n/** Whether an `animationend` / `animationcancel` belongs to the `popover-motion` phase. */\nexport function isPopoverMotionAnimation(event: Pick<AnimationEvent, 'animationName'>, phase: 'opening' | 'closing'): boolean {\n\treturn event.animationName === POPOVER_MOTION_ANIMATIONS[phase];\n}\n\nconst OPPOSITE_EDGES: Readonly<Record<string, string>> = { top: 'bottom', bottom: 'top', start: 'end', end: 'start' };\n\n/**\n * Offset for a fallback position derived from a primary one: negated when the fallback anchors the\n * opposite edge (a flip), so a gap between trigger and panel stays a gap on either side.\n */\nexport function mirrorPopoverOffset(offset: number | undefined, from: string, to: string): number {\n\tconst value = offset ?? 0;\n\treturn OPPOSITE_EDGES[from] === to && value !== 0 ? -value : value;\n}\n","import { CDK_MENU, MENU_TRIGGER } from '@angular/cdk/menu';\nimport { ConnectedPosition, STANDARD_DROPDOWN_ADJACENT_POSITIONS, STANDARD_DROPDOWN_BELOW_POSITIONS } from '@angular/cdk/overlay';\nimport { afterNextRender, DestroyRef, Directive, ElementRef, inject, input, signal } from '@angular/core';\nimport { ThemeDomService } from '@sixbell-telco/sdk/utils/theme';\nimport { isPopoverMotionAnimation, PopoverAlign, PopoverMotionState, PopoverPlacement, popoverPlacement, PopoverSide } from './popover-motion';\n\nconst SIDE_CLASS = 'st-popover-side-';\nconst ALIGN_CLASS = 'st-popover-align-';\nconst SIDES: readonly PopoverSide[] = ['top', 'right', 'bottom', 'left'];\nconst ALIGNS: readonly PopoverAlign[] = ['start', 'center', 'end'];\n\n/** Gap in pixels between a menu trigger and a menu opened below or above it */\nconst MENU_GAP = 4;\n\n/** Tag each position with pane classes naming its placement, so the menu panel can read where the CDK put it */\nfunction withPlacementClasses(positions: readonly ConnectedPosition[]): ConnectedPosition[] {\n\treturn positions.map((position) => {\n\t\tconst { side, align } = popoverPlacement(position);\n\t\tconst own = position.panelClass ? ([] as string[]).concat(position.panelClass) : [];\n\t\treturn { ...position, panelClass: [...own, `${SIDE_CLASS}${side}`, `${ALIGN_CLASS}${align}`] };\n\t});\n}\n\nconst MENU_BELOW_POSITIONS = withPlacementClasses(\n\tSTANDARD_DROPDOWN_BELOW_POSITIONS.map((position) => ({ ...position, offsetY: position.overlayY === 'top' ? MENU_GAP : -MENU_GAP })),\n);\nconst MENU_ADJACENT_POSITIONS = withPlacementClasses(STANDARD_DROPDOWN_ADJACENT_POSITIONS);\nconst CONTEXT_MENU_POSITIONS = withPlacementClasses(\n\tSTANDARD_DROPDOWN_BELOW_POSITIONS.map((position) => ({\n\t\t...position,\n\t\toffsetX: position.overlayX === 'start' ? 2 : -2,\n\t\toffsetY: position.overlayY === 'top' ? 2 : -2,\n\t})),\n);\n\n/**\n * Positions for a CDK menu trigger, the same placements the CDK picks by default (below a root or\n * menu-bar trigger with a 4px gap, beside a trigger inside a vertical menu), tagged for `popover-motion`.\n * Call it in the injection context of the trigger.\n */\nexport function popoverMenuPositions(): ConnectedPosition[] {\n\tconst parentMenu = inject(CDK_MENU, { optional: true });\n\treturn parentMenu?.orientation === 'vertical' ? MENU_ADJACENT_POSITIONS : MENU_BELOW_POSITIONS;\n}\n\n/** Positions for a CDK context menu trigger (the CDK defaults), tagged for `popover-motion` */\nexport function popoverContextMenuPositions(): ConnectedPosition[] {\n\treturn CONTEXT_MENU_POSITIONS;\n}\n\nfunction readPlacement(pane: HTMLElement | null): PopoverPlacement {\n\tconst classes = pane?.classList;\n\tconst side = SIDES.find((value) => classes?.contains(`${SIDE_CLASS}${value}`));\n\tconst align = ALIGNS.find((value) => classes?.contains(`${ALIGN_CLASS}${value}`)) ?? 'start';\n\tif (side) return { side, align };\n\t// Untagged positions (a trigger with its own cdkMenuPosition): the CDK pins `bottom` only for panels above the trigger.\n\treturn { side: pane?.style.bottom ? 'top' : 'bottom', align };\n}\n\nfunction longestAnimationMs(element: Element): number {\n\tconst style = getComputedStyle(element);\n\tconst toMs = (value: string) => {\n\t\tconst parsed = Number.parseFloat(value);\n\t\tif (!Number.isFinite(parsed)) return 0;\n\t\treturn value.trim().endsWith('ms') ? parsed : parsed * 1000;\n\t};\n\tconst durations = (style.animationDuration ?? '').split(',').map(toMs);\n\tconst delays = (style.animationDelay ?? '').split(',').map(toMs);\n\treturn Math.max(0, ...durations.map((duration, index) => duration + (delays[index] ?? delays[0] ?? 0)));\n}\n\n/**\n * `popover-motion` for a CDK menu panel (`cdkMenu`). The entrance starts once the CDK placed the pane.\n * The CDK detaches a menu the moment it closes, so the exit plays on an inert, hidden-from-AT snapshot\n * of the panel at the same spot, removed when its animation ends.\n * The panel is portaled out of its page, so it takes the theme of `stPopoverMenuMotionTheme` (the element\n * that declares the menu), as `st-dropdown` does for its panel; the snapshot keeps it.\n */\n@Directive({\n\tselector: '[stPopoverMenuMotion]',\n\tstandalone: true,\n\thost: {\n\t\tclass: 'popover-motion',\n\t\t'[attr.data-state]': 'state()',\n\t\t'[attr.data-side]': 'placement()?.side',\n\t\t'[attr.data-align]': 'placement()?.align',\n\t\t'[attr.data-theme]': 'theme()',\n\t\t'(animationend)': 'onAnimationEnd($event)',\n\t},\n})\nexport class PopoverMenuMotionDirective {\n\tprivate readonly element: HTMLElement = inject(ElementRef).nativeElement;\n\tprivate readonly trigger = inject(MENU_TRIGGER, { optional: true });\n\tprivate readonly themeDom = inject(ThemeDomService);\n\n\t/** Element whose nearest `data-theme` the portaled panel takes */\n\treadonly stPopoverMenuMotionTheme = input<Element | null>(null);\n\n\t/** @internal */\n\tprotected theme(): string | null {\n\t\treturn this.themeDom.themeOf(this.stPopoverMenuMotionTheme());\n\t}\n\n\t/** @internal */\n\tprotected readonly state = signal<PopoverMotionState>(this.trigger ? 'opening' : 'open');\n\n\t/** @internal */\n\tprotected readonly placement = signal<PopoverPlacement | null>(null);\n\n\tconstructor() {\n\t\tif (!this.trigger) return;\n\t\tafterNextRender({ read: () => this.placement.set(readPlacement(this.element.parentElement)) });\n\n\t\tconst subscription = this.trigger.closed.subscribe(() => this.playExit());\n\t\tinject(DestroyRef).onDestroy(() => subscription.unsubscribe());\n\t}\n\n\t/** @internal */\n\tprotected onAnimationEnd(event: AnimationEvent): void {\n\t\tif (event.target === this.element && this.state() === 'opening' && isPopoverMotionAnimation(event, 'opening')) {\n\t\t\tthis.state.set('open');\n\t\t}\n\t}\n\n\tprivate playExit(): void {\n\t\tconst pane = this.element.parentElement;\n\t\tconst layer = pane?.parentElement?.parentElement;\n\t\tif (!pane || !layer || !this.element.isConnected) return;\n\n\t\tconst rect = this.element.getBoundingClientRect();\n\t\tconst holder = this.element.ownerDocument.createElement('div');\n\t\tholder.setAttribute('aria-hidden', 'true');\n\t\tholder.setAttribute('inert', '');\n\t\tObject.assign(holder.style, {\n\t\t\tposition: 'fixed',\n\t\t\tleft: `${rect.left}px`,\n\t\t\ttop: `${rect.top}px`,\n\t\t\twidth: `${rect.width}px`,\n\t\t\tpointerEvents: 'none',\n\t\t\tzIndex: getComputedStyle(pane.parentElement as HTMLElement).zIndex || '1000',\n\t\t});\n\n\t\tconst snapshot = this.element.cloneNode(true) as HTMLElement;\n\t\t[snapshot, ...Array.from(snapshot.querySelectorAll<HTMLElement>('[id]'))].forEach((node) => node.removeAttribute('id'));\n\t\tsnapshot.setAttribute('data-state', 'closing');\n\t\tholder.appendChild(snapshot);\n\t\tlayer.appendChild(holder);\n\n\t\tlet timer: ReturnType<typeof setTimeout> | null = null;\n\t\tconst remove = () => {\n\t\t\tif (timer !== null) clearTimeout(timer);\n\t\t\tholder.remove();\n\t\t};\n\t\tsnapshot.addEventListener('animationend', (event) => {\n\t\t\tif (event.target === snapshot && isPopoverMotionAnimation(event, 'closing')) remove();\n\t\t});\n\t\ttimer = setTimeout(remove, longestAnimationMs(snapshot) + 50);\n\t}\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;AAiBA;AACO,MAAM,yBAAyB,GAAG,EAAE,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,gBAAgB;AAI9F,MAAM,YAAY,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAyE;AAE7I;;;AAGG;AACG,SAAU,gBAAgB,CAAC,IAAkB,EAAA;IAClD,IAA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+
bundleRefreshId = 0;
|
|
284
|
+
inactiveRefreshIds = new Map();
|
|
283
285
|
runtimeHash = null;
|
|
284
286
|
runtimeLoader;
|
|
285
287
|
runtimeMeta;
|
|
@@ -332,17 +334,9 @@ class TranslationService {
|
|
|
332
334
|
action: 'configure',
|
|
333
335
|
newPaths,
|
|
334
336
|
});
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
const url = `${normalized}${targetLang}.json`;
|
|
339
|
-
return this.fetchTranslation(url)
|
|
340
|
-
.then(() => undefined)
|
|
341
|
-
.catch(() => undefined);
|
|
342
|
-
});
|
|
343
|
-
Promise.all(preloadPromises).then(() => {
|
|
344
|
-
this.translate.reloadLang(targetLang);
|
|
345
|
-
});
|
|
337
|
+
if (!this.isApplyingRuntimeConfig) {
|
|
338
|
+
this.reloadForNewPaths(this.getCurrentLanguage());
|
|
339
|
+
}
|
|
346
340
|
}
|
|
347
341
|
this.config = {
|
|
348
342
|
availableLanguages,
|
|
@@ -395,7 +389,32 @@ class TranslationService {
|
|
|
395
389
|
}
|
|
396
390
|
this.currentLanguage.set(this.config.defaultLanguage);
|
|
397
391
|
}
|
|
392
|
+
reloadForNewPaths(targetLang) {
|
|
393
|
+
if (this.ready()) {
|
|
394
|
+
void this.refreshLoadedLanguage(targetLang);
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
const preloadPromises = this.currentTranslationPaths.map((path) => {
|
|
398
|
+
const normalized = path.endsWith('/') ? path : `${path}/`;
|
|
399
|
+
const url = `${normalized}${targetLang}.json`;
|
|
400
|
+
return this.fetchTranslation(url)
|
|
401
|
+
.then(() => undefined)
|
|
402
|
+
.catch(() => undefined);
|
|
403
|
+
});
|
|
404
|
+
Promise.all(preloadPromises).then(() => {
|
|
405
|
+
this.translate.reloadLang(targetLang);
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Applies a runtime config. On the first load `ready()` stays false until the bundle is in. Once
|
|
410
|
+
* translations are ready, a refresh (e.g. a host adding a remote's i18n path) fetches the new bundle
|
|
411
|
+
* first and merges it over the loaded one, so `ready()` and the visible translations never drop.
|
|
412
|
+
*/
|
|
398
413
|
async setRuntimeConfig(config) {
|
|
414
|
+
if (this.ready()) {
|
|
415
|
+
await this.refreshRuntimeConfig(config);
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
399
418
|
this.ready.set(false);
|
|
400
419
|
this.logger.debug('setRuntimeConfig - starting', {
|
|
401
420
|
component: 'TranslationService',
|
|
@@ -422,6 +441,104 @@ class TranslationService {
|
|
|
422
441
|
currentLanguage: this.getCurrentLanguage(),
|
|
423
442
|
});
|
|
424
443
|
}
|
|
444
|
+
async refreshRuntimeConfig(config) {
|
|
445
|
+
this.logger.debug('setRuntimeConfig - refreshing loaded translations', {
|
|
446
|
+
component: 'TranslationService',
|
|
447
|
+
action: 'setRuntimeConfig',
|
|
448
|
+
configPath: config.translationPaths,
|
|
449
|
+
});
|
|
450
|
+
const refresh = ++this.bundleRefreshId;
|
|
451
|
+
this.isApplyingRuntimeConfig = true;
|
|
452
|
+
let switchedLanguage = null;
|
|
453
|
+
try {
|
|
454
|
+
this.configure(config);
|
|
455
|
+
const targetLang = this.currentLanguage();
|
|
456
|
+
const languageUnchanged = this.translate.getCurrentLang() === targetLang;
|
|
457
|
+
const bundle = await this.fetchBundle(targetLang);
|
|
458
|
+
if (refresh !== this.bundleRefreshId) {
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
if (bundle) {
|
|
462
|
+
this.translate.setTranslation(targetLang, bundle, true);
|
|
463
|
+
}
|
|
464
|
+
if (this.currentLanguage() !== targetLang) {
|
|
465
|
+
switchedLanguage = this.currentLanguage();
|
|
466
|
+
}
|
|
467
|
+
else if (!languageUnchanged) {
|
|
468
|
+
this.applyLanguage();
|
|
469
|
+
}
|
|
470
|
+
else {
|
|
471
|
+
this.translate.setFallbackLang(this.config.defaultLanguage);
|
|
472
|
+
if (bundle) {
|
|
473
|
+
this.announceRefreshedLanguage(targetLang);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
if (this.prefetchLanguages) {
|
|
477
|
+
this.prefetchRemainingLanguages();
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
finally {
|
|
481
|
+
if (refresh === this.bundleRefreshId) {
|
|
482
|
+
this.isApplyingRuntimeConfig = false;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
if (switchedLanguage) {
|
|
486
|
+
void this.refreshLoadedLanguage(switchedLanguage);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
async refreshLoadedLanguage(lang) {
|
|
490
|
+
const refresh = ++this.bundleRefreshId;
|
|
491
|
+
const bundle = await this.fetchBundle(lang);
|
|
492
|
+
if (!bundle || refresh !== this.bundleRefreshId) {
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
this.translate.setTranslation(lang, bundle, true);
|
|
496
|
+
if (this.currentLanguage() === lang) {
|
|
497
|
+
this.announceRefreshedLanguage(lang);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* Re-selects the refreshed active language so `onLangChange` fires once, as it did when a refresh
|
|
502
|
+
* went through `use()`. Its listener ticks `changes()` and `onLanguageChange`; before `init()`
|
|
503
|
+
* subscribes, they are ticked here instead.
|
|
504
|
+
*/
|
|
505
|
+
announceRefreshedLanguage(lang) {
|
|
506
|
+
const tick = this.translationTick();
|
|
507
|
+
this.translate.use(lang);
|
|
508
|
+
if (this.translationTick() === tick) {
|
|
509
|
+
this.notifyTranslationsChanged();
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* Fetches `lang` through the active loader without touching the loaded bundle. Unlike
|
|
514
|
+
* `TranslateService.reloadLang`, nothing is deleted first, so `instant()` keeps returning the
|
|
515
|
+
* previous values until the caller merges the result, and a failed fetch returns `null`.
|
|
516
|
+
*/
|
|
517
|
+
async fetchBundle(lang) {
|
|
518
|
+
try {
|
|
519
|
+
return await firstValueFrom(this.translate.currentLoader.getTranslation(lang));
|
|
520
|
+
}
|
|
521
|
+
catch (error) {
|
|
522
|
+
this.logger.error('Translation bundle refresh failed; keeping the loaded translations', error, {
|
|
523
|
+
component: 'TranslationService',
|
|
524
|
+
action: 'fetchBundle',
|
|
525
|
+
language: lang,
|
|
526
|
+
});
|
|
527
|
+
return null;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
async swapTranslations(lang) {
|
|
531
|
+
const refresh = (this.inactiveRefreshIds.get(lang) ?? 0) + 1;
|
|
532
|
+
this.inactiveRefreshIds.set(lang, refresh);
|
|
533
|
+
const bundle = await this.fetchBundle(lang);
|
|
534
|
+
if (bundle && refresh === this.inactiveRefreshIds.get(lang)) {
|
|
535
|
+
this.translate.setTranslation(lang, bundle, true);
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
notifyTranslationsChanged() {
|
|
539
|
+
this.onLanguageChange.update((value) => value + 1);
|
|
540
|
+
this.translationTick.update((value) => value + 1);
|
|
541
|
+
}
|
|
425
542
|
enablePrefetch(enable) {
|
|
426
543
|
this.prefetchLanguages = enable;
|
|
427
544
|
}
|
|
@@ -458,7 +575,7 @@ class TranslationService {
|
|
|
458
575
|
return;
|
|
459
576
|
}
|
|
460
577
|
const available = new Set(this.getAvailableLanguageCodes());
|
|
461
|
-
await Promise.all(unique.filter((lang) => available.has(lang)).map((lang) =>
|
|
578
|
+
await Promise.all(unique.filter((lang) => available.has(lang)).map((lang) => this.swapTranslations(lang)));
|
|
462
579
|
}
|
|
463
580
|
async refreshInactiveLanguages() {
|
|
464
581
|
const current = this.currentLanguage();
|
|
@@ -489,8 +606,6 @@ class TranslationService {
|
|
|
489
606
|
this.updateAvailable.set(false);
|
|
490
607
|
await this.setRuntimeConfig(result.data);
|
|
491
608
|
this.ready.set(true);
|
|
492
|
-
const current = this.currentLanguage();
|
|
493
|
-
await this.reloadLanguages([current]);
|
|
494
609
|
void this.refreshInactiveLanguages();
|
|
495
610
|
}
|
|
496
611
|
catch (error) {
|