starlight-versions 0.3.0 → 0.3.1
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.
|
@@ -15,7 +15,7 @@ const pageVersion = getVersionFromSlug(starlightVersionsConfig, starlightConfig,
|
|
|
15
15
|
<label>
|
|
16
16
|
<span class="sr-only">Select version</span>
|
|
17
17
|
<Icon name="seti:clock" class="icon label-icon" />
|
|
18
|
-
<select value={pageVersion?.label ?? 'current'}>
|
|
18
|
+
<select value={pageVersion?.label ?? 'current'} autocomplete="off">
|
|
19
19
|
<option
|
|
20
20
|
selected={pageVersion === undefined}
|
|
21
21
|
value={getVersionURL(starlightVersionsConfig, starlightConfig, Astro.url, undefined).pathname}
|
|
@@ -101,11 +101,25 @@ const pageVersion = getVersionFromSlug(starlightVersionsConfig, starlightConfig,
|
|
|
101
101
|
constructor() {
|
|
102
102
|
super()
|
|
103
103
|
|
|
104
|
-
this.querySelector('select')
|
|
104
|
+
const select = this.querySelector('select')
|
|
105
|
+
if (!select) return
|
|
106
|
+
|
|
107
|
+
select?.addEventListener('change', (event) => {
|
|
105
108
|
if (event.currentTarget instanceof HTMLSelectElement) {
|
|
106
109
|
window.location.pathname = event.currentTarget.value
|
|
107
110
|
}
|
|
108
111
|
})
|
|
112
|
+
|
|
113
|
+
window.addEventListener('pageshow', (event) => {
|
|
114
|
+
if (!event.persisted) return
|
|
115
|
+
const markupSelectedIndex = select.querySelector<HTMLOptionElement>('option[selected]')?.index
|
|
116
|
+
|
|
117
|
+
// If the page was loaded from a cache, the version select selected index might not be in sync with the
|
|
118
|
+
// current page.
|
|
119
|
+
if (markupSelectedIndex !== select.selectedIndex) {
|
|
120
|
+
select.selectedIndex = markupSelectedIndex ?? 0
|
|
121
|
+
}
|
|
122
|
+
})
|
|
109
123
|
}
|
|
110
124
|
},
|
|
111
125
|
)
|