srcdev-nuxt-components 6.1.6 → 6.1.8
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.
|
@@ -154,12 +154,22 @@ const props = defineProps({
|
|
|
154
154
|
},
|
|
155
155
|
})
|
|
156
156
|
|
|
157
|
-
const slots = useSlots()
|
|
158
157
|
const collapseNavigationBelowWidth = computed(
|
|
159
158
|
() => props.collapseBreakpoint !== null || props.collapseAtMainNavIntersection
|
|
160
159
|
)
|
|
161
160
|
const collapseBreakpoint = ref(props.collapseBreakpoint)
|
|
162
|
-
|
|
161
|
+
|
|
162
|
+
// Use global navigation state for caching between route changes
|
|
163
|
+
const {
|
|
164
|
+
navLoaded,
|
|
165
|
+
navigationInitialized,
|
|
166
|
+
navigationWrapperRects: cachedNavigationWrapperRects,
|
|
167
|
+
secondaryNavRects: cachedSecondaryNavRects,
|
|
168
|
+
clearNavigationCache,
|
|
169
|
+
} = useNavigationState()
|
|
170
|
+
|
|
171
|
+
const slots = useSlots()
|
|
172
|
+
|
|
163
173
|
const navigationWrapperRef = useTemplateRef("navigationWrapper")
|
|
164
174
|
|
|
165
175
|
const closeAllNavigationDetails = () => {
|
|
@@ -215,6 +225,7 @@ const handleSummaryAction = (event: MouseEvent | KeyboardEvent) => {
|
|
|
215
225
|
toggleDetailsElement(event)
|
|
216
226
|
}
|
|
217
227
|
|
|
228
|
+
// Initialize main navigation state
|
|
218
229
|
const mainNavigationState = ref<ResponsiveHeaderState>({
|
|
219
230
|
navListVisibility: {
|
|
220
231
|
firstNav: false,
|
|
@@ -230,7 +241,13 @@ const setNavRef = (key: string, el: HTMLUListElement | null) => {
|
|
|
230
241
|
navRefs.value[key] = el
|
|
231
242
|
}
|
|
232
243
|
|
|
233
|
-
const navigationWrapperRects =
|
|
244
|
+
const navigationWrapperRects = computed({
|
|
245
|
+
get: () => cachedNavigationWrapperRects.value,
|
|
246
|
+
set: (value: IFlooredRect | null) => {
|
|
247
|
+
cachedNavigationWrapperRects.value = value
|
|
248
|
+
},
|
|
249
|
+
})
|
|
250
|
+
|
|
234
251
|
const firstNavRef = ref<HTMLUListElement | null>(null)
|
|
235
252
|
const firstNavRects = ref<IFlooredRect | null>(null)
|
|
236
253
|
|
|
@@ -238,7 +255,12 @@ const secondNavRef = ref<HTMLUListElement | null>(null)
|
|
|
238
255
|
const secondNavRects = ref<IFlooredRect | null>(null)
|
|
239
256
|
|
|
240
257
|
const secondaryNavRef = useTemplateRef("secondaryNav")
|
|
241
|
-
const secondaryNavRects =
|
|
258
|
+
const secondaryNavRects = computed({
|
|
259
|
+
get: () => cachedSecondaryNavRects.value,
|
|
260
|
+
set: (value: IFlooredRect | null) => {
|
|
261
|
+
cachedSecondaryNavRects.value = value
|
|
262
|
+
},
|
|
263
|
+
})
|
|
242
264
|
|
|
243
265
|
const mainNavigationItemsRefs = useTemplateRef<HTMLLIElement[]>("mainNavigationItems")
|
|
244
266
|
|
|
@@ -323,7 +345,8 @@ const determineNavigationItemVisibility = (rect: DOMRect) => {
|
|
|
323
345
|
const initMainNavigationState = () => {
|
|
324
346
|
if (!mainNavigationItemsRefs.value) return
|
|
325
347
|
|
|
326
|
-
mainNavigationItemsRefs.value.forEach((item, index) => {
|
|
348
|
+
mainNavigationItemsRefs.value.forEach(async (item, index) => {
|
|
349
|
+
// await nextTick()
|
|
327
350
|
const rect = item.getBoundingClientRect()
|
|
328
351
|
|
|
329
352
|
const groupKey = item.dataset.groupKey
|
|
@@ -361,13 +384,8 @@ const initMainNavigationState = () => {
|
|
|
361
384
|
})
|
|
362
385
|
}
|
|
363
386
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
setTimeout(() => {
|
|
367
|
-
navLoaded.value = true
|
|
368
|
-
}, 100)
|
|
369
|
-
})
|
|
370
|
-
|
|
387
|
+
// Function to set up click outside listeners
|
|
388
|
+
const setupClickOutsideListeners = () => {
|
|
371
389
|
navigationDetailsRefs.value?.forEach((element, index) => {
|
|
372
390
|
onClickOutside(element, () => {
|
|
373
391
|
navigationDetailsRefs.value?.[index]?.removeAttribute("open")
|
|
@@ -378,6 +396,23 @@ onMounted(async () => {
|
|
|
378
396
|
onClickOutside(overflowDetailsRef.value, () => {
|
|
379
397
|
overflowDetailsRef.value?.removeAttribute("open")
|
|
380
398
|
})
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
onMounted(async () => {
|
|
402
|
+
// If navigation is already initialized and loaded, skip the template refs setup
|
|
403
|
+
if (navigationInitialized.value && navLoaded.value) {
|
|
404
|
+
// But still set up click outside listeners as DOM elements may have changed
|
|
405
|
+
await nextTick()
|
|
406
|
+
setupClickOutsideListeners()
|
|
407
|
+
return
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
await initTemplateRefs().then(() => {
|
|
411
|
+
navLoaded.value = true
|
|
412
|
+
navigationInitialized.value = true
|
|
413
|
+
})
|
|
414
|
+
|
|
415
|
+
setupClickOutsideListeners()
|
|
381
416
|
})
|
|
382
417
|
|
|
383
418
|
useResizeObserver(navigationWrapperRef, async () => {
|
|
@@ -465,7 +500,7 @@ watch(
|
|
|
465
500
|
}
|
|
466
501
|
|
|
467
502
|
.main-navigation-item {
|
|
468
|
-
width: var(--_main-navigation-item-width);
|
|
503
|
+
/* width: var(--_main-navigation-item-width); */
|
|
469
504
|
overflow: hidden;
|
|
470
505
|
transition: opacity 0.2s ease-in-out, visibility 0.2s ease-in-out;
|
|
471
506
|
padding-block: var(--_link-focus-visible-outline-width);
|
|
@@ -478,7 +513,7 @@ watch(
|
|
|
478
513
|
color: inherit;
|
|
479
514
|
text-decoration: none;
|
|
480
515
|
margin-inline-start: 0;
|
|
481
|
-
transition: var(--_link-visibility-transition);
|
|
516
|
+
/* transition: var(--_link-visibility-transition); */
|
|
482
517
|
|
|
483
518
|
padding-block: var(--_link-padding-block);
|
|
484
519
|
padding-inline: var(--_link-padding-inline);
|
|
@@ -496,7 +531,7 @@ watch(
|
|
|
496
531
|
--_icon-transform: scaleY(1);
|
|
497
532
|
|
|
498
533
|
margin-inline-start: 0;
|
|
499
|
-
transition: var(--_link-visibility-transition);
|
|
534
|
+
/* transition: var(--_link-visibility-transition); */
|
|
500
535
|
|
|
501
536
|
&[open] {
|
|
502
537
|
--_icon-transform: scaleY(-1);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { IFlooredRect } from "@/types/responsiveHeader"
|
|
2
|
+
|
|
3
|
+
export const useNavigationState = () => {
|
|
4
|
+
// Simple reactive refs that persist across route changes using useState
|
|
5
|
+
const navLoaded = useState<boolean>("nav-loaded", () => false)
|
|
6
|
+
const navigationInitialized = useState<boolean>("nav-initialized", () => false)
|
|
7
|
+
|
|
8
|
+
// Navigation rects cache
|
|
9
|
+
const navigationWrapperRects = useState<IFlooredRect | null>("nav-wrapper-rects", () => null)
|
|
10
|
+
const secondaryNavRects = useState<IFlooredRect | null>("secondary-nav-rects", () => null)
|
|
11
|
+
|
|
12
|
+
const clearNavigationCache = () => {
|
|
13
|
+
navLoaded.value = false
|
|
14
|
+
navigationInitialized.value = false
|
|
15
|
+
navigationWrapperRects.value = null
|
|
16
|
+
secondaryNavRects.value = null
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
navLoaded,
|
|
21
|
+
navigationInitialized,
|
|
22
|
+
navigationWrapperRects,
|
|
23
|
+
secondaryNavRects,
|
|
24
|
+
clearNavigationCache,
|
|
25
|
+
}
|
|
26
|
+
}
|
package/nuxt.config.ts
CHANGED
package/package.json
CHANGED