@hagicode/hagilight 0.2.1-dev.15.1.e6bdd48 → 0.2.2-dev.17.1.e7bfdb3
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/package.json +1 -1
- package/promoto-banner.ts +11 -1
package/package.json
CHANGED
package/promoto-banner.ts
CHANGED
|
@@ -110,6 +110,7 @@ export function definePromotoBannerElement(): void {
|
|
|
110
110
|
private motionQuery: MediaQueryList | undefined;
|
|
111
111
|
private resizeObserver: ResizeObserver | undefined;
|
|
112
112
|
private footer: HTMLElement | null = null;
|
|
113
|
+
private loadedLocale: string | null = null;
|
|
113
114
|
|
|
114
115
|
private readonly onPrevious = () => this.move(-1);
|
|
115
116
|
private readonly onNext = () => this.move(1);
|
|
@@ -146,6 +147,12 @@ export function definePromotoBannerElement(): void {
|
|
|
146
147
|
this.updateControls();
|
|
147
148
|
this.syncRotation();
|
|
148
149
|
};
|
|
150
|
+
private readonly onPageLoad = () => {
|
|
151
|
+
// Re-fetch in the current page locale after a Starlight view-transition
|
|
152
|
+
// navigation. The element may persist across a soft language switch, so
|
|
153
|
+
// its previously loaded locale can differ from the new page's data-locale.
|
|
154
|
+
if (this.dataset.locale !== this.loadedLocale) void this.reload();
|
|
155
|
+
};
|
|
149
156
|
|
|
150
157
|
connectedCallback(): void {
|
|
151
158
|
this.footer = document.querySelector('footer');
|
|
@@ -159,6 +166,7 @@ export function definePromotoBannerElement(): void {
|
|
|
159
166
|
window.addEventListener('resize', this.onLayoutChange);
|
|
160
167
|
document.addEventListener('visibilitychange', this.onVisibilityChange);
|
|
161
168
|
this.motionQuery?.addEventListener('change', this.onMotionChange);
|
|
169
|
+
document.addEventListener('astro:page-load', this.onPageLoad);
|
|
162
170
|
if (typeof ResizeObserver !== 'undefined') {
|
|
163
171
|
this.resizeObserver = new ResizeObserver(this.onLayoutChange);
|
|
164
172
|
if (this.footer) this.resizeObserver.observe(this.footer);
|
|
@@ -178,6 +186,7 @@ export function definePromotoBannerElement(): void {
|
|
|
178
186
|
window.removeEventListener('resize', this.onLayoutChange);
|
|
179
187
|
document.removeEventListener('visibilitychange', this.onVisibilityChange);
|
|
180
188
|
this.motionQuery?.removeEventListener('change', this.onMotionChange);
|
|
189
|
+
document.removeEventListener('astro:page-load', this.onPageLoad);
|
|
181
190
|
this.resizeObserver?.disconnect();
|
|
182
191
|
this.stopRotation();
|
|
183
192
|
this.stopRefresh();
|
|
@@ -185,6 +194,7 @@ export function definePromotoBannerElement(): void {
|
|
|
185
194
|
|
|
186
195
|
private async reload(): Promise<void> {
|
|
187
196
|
const previousId = this.cards[this.currentIndex]?.id;
|
|
197
|
+
this.loadedLocale = this.dataset.locale ?? null;
|
|
188
198
|
const remote = await loadActivePromotions({ locale: this.dataset.locale });
|
|
189
199
|
if (!this.isConnected) return;
|
|
190
200
|
const fallback = this.readFallback();
|
|
@@ -355,4 +365,4 @@ export function definePromotoBannerElement(): void {
|
|
|
355
365
|
}
|
|
356
366
|
|
|
357
367
|
customElements.define(ELEMENT_NAME, PromotoBannerElement);
|
|
358
|
-
}
|
|
368
|
+
}
|