@gsa-tts/graymatter-ui 0.3.16 → 0.3.18
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gsa-tts/graymatter-ui",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.18",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"@fontsource/space-mono": "^5.2.8",
|
|
68
68
|
"@uswds/uswds": "3.12.0",
|
|
69
69
|
"slugify": "^1.6.6",
|
|
70
|
-
"@gsa-tts/graymatter-style-tokens": "0.3.
|
|
70
|
+
"@gsa-tts/graymatter-style-tokens": "0.3.17"
|
|
71
71
|
},
|
|
72
72
|
"scripts": {
|
|
73
73
|
"build": "gulp update && vite build",
|
|
@@ -148,9 +148,9 @@
|
|
|
148
148
|
parent: SubNavItem | null
|
|
149
149
|
): SubNavItem | null {
|
|
150
150
|
for (const it of items) {
|
|
151
|
-
if (it.id === item.id) return parent
|
|
152
|
-
if (it.children) {
|
|
153
|
-
const found = search(it.children,
|
|
151
|
+
if (it.id === item.id) return parent || it;
|
|
152
|
+
if (it.children && it.children.length > 0) {
|
|
153
|
+
const found = search(it.children, it);
|
|
154
154
|
if (found) return found;
|
|
155
155
|
}
|
|
156
156
|
}
|
|
@@ -179,6 +179,7 @@
|
|
|
179
179
|
|
|
180
180
|
let currentSelectedId = $state<string | null>(null);
|
|
181
181
|
let hydrated = $state(false);
|
|
182
|
+
let pageLoadComplete = $state(false);
|
|
182
183
|
|
|
183
184
|
const effectiveSelectedId = $derived(() => {
|
|
184
185
|
if (!hydrated || !data) return null;
|
|
@@ -195,28 +196,28 @@
|
|
|
195
196
|
}
|
|
196
197
|
}
|
|
197
198
|
|
|
198
|
-
// Second priority: sessionStorage
|
|
199
|
+
// Second priority: Check if we have a persisted selectedId from sessionStorage
|
|
199
200
|
if (typeof window !== 'undefined') {
|
|
200
201
|
const storedId = sessionStorage.getItem('subNav-selectedId');
|
|
201
202
|
if (storedId) {
|
|
202
203
|
try {
|
|
203
204
|
const parsedId = JSON.parse(storedId);
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
return targetItem.id;
|
|
208
|
-
}
|
|
205
|
+
const targetItem = findItemById(data, parsedId);
|
|
206
|
+
if (targetItem) {
|
|
207
|
+
return parsedId;
|
|
209
208
|
}
|
|
210
|
-
} catch
|
|
211
|
-
|
|
209
|
+
} catch {
|
|
210
|
+
// Invalid JSON, ignore
|
|
212
211
|
}
|
|
213
212
|
}
|
|
214
213
|
}
|
|
215
214
|
|
|
216
|
-
//
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
215
|
+
// Fallback: use first item when no other selection method works
|
|
216
|
+
if (pageLoadComplete) {
|
|
217
|
+
const firstItem = findFirstItem(data);
|
|
218
|
+
if (firstItem && firstItem.title) {
|
|
219
|
+
return firstItem.id;
|
|
220
|
+
}
|
|
220
221
|
}
|
|
221
222
|
|
|
222
223
|
return null;
|
|
@@ -226,6 +227,27 @@
|
|
|
226
227
|
$effect(() => {
|
|
227
228
|
if (effectiveSelectedId() && effectiveSelectedId() !== currentSelectedId) {
|
|
228
229
|
currentSelectedId = effectiveSelectedId();
|
|
230
|
+
|
|
231
|
+
// When restoring from sessionStorage, also restore the correct header
|
|
232
|
+
// Only do this if we're on the API documentation page (where this component exists)
|
|
233
|
+
if (data && effectiveSelectedId() && typeof window !== 'undefined') {
|
|
234
|
+
const currentPath = window.location.pathname;
|
|
235
|
+
const isApiDocumentationPage =
|
|
236
|
+
currentPath.includes('/api/documentation');
|
|
237
|
+
|
|
238
|
+
if (isApiDocumentationPage) {
|
|
239
|
+
const restoredItem = findItemById(data, effectiveSelectedId()!);
|
|
240
|
+
if (restoredItem) {
|
|
241
|
+
const topLevel =
|
|
242
|
+
findTopLevelParent(restoredItem, data) || restoredItem;
|
|
243
|
+
import('@gsa-tts/graymatter-ui/stores/navigationStore')
|
|
244
|
+
.then(({ selectedSubNavItemTitle }) => {
|
|
245
|
+
selectedSubNavItemTitle.set(topLevel.title || '');
|
|
246
|
+
})
|
|
247
|
+
.catch();
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
229
251
|
}
|
|
230
252
|
});
|
|
231
253
|
|
|
@@ -234,53 +256,46 @@
|
|
|
234
256
|
|
|
235
257
|
if (!data) return;
|
|
236
258
|
|
|
237
|
-
//
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
//
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
JSON.stringify(topLevel.id)
|
|
255
|
-
);
|
|
256
|
-
sessionStorage.setItem(
|
|
257
|
-
'subNav-topLevelTitle',
|
|
258
|
-
JSON.stringify(topLevel.title || '')
|
|
259
|
-
);
|
|
260
|
-
}
|
|
261
|
-
})
|
|
262
|
-
.catch();
|
|
263
|
-
|
|
264
|
-
// Handle scrolling if we have a URL hash
|
|
265
|
-
if (targetItem.href && targetItem.href.includes('#')) {
|
|
266
|
-
const hash = targetItem.href.split('#')[1];
|
|
267
|
-
if (hash) {
|
|
268
|
-
setTimeout(() => scrollToAnchorWithOffset(hash), 100);
|
|
259
|
+
// Check if we're navigating TO the documentation page (vs refreshing while on it)
|
|
260
|
+
if (typeof window !== 'undefined') {
|
|
261
|
+
const currentPath = window.location.pathname;
|
|
262
|
+
const isDocumentationPage = currentPath.includes('/api/documentation');
|
|
263
|
+
|
|
264
|
+
// If we're on the documentation page, check if we came from a different page
|
|
265
|
+
if (isDocumentationPage) {
|
|
266
|
+
const referrer = document.referrer;
|
|
267
|
+
const isFromDifferentPage =
|
|
268
|
+
referrer && !referrer.includes('/api/documentation');
|
|
269
|
+
|
|
270
|
+
// If we came from a different page, clear sessionStorage to reset to initial values
|
|
271
|
+
if (isFromDifferentPage) {
|
|
272
|
+
sessionStorage.removeItem('subNav-selectedId');
|
|
273
|
+
sessionStorage.removeItem('subNav-selectedTitle');
|
|
274
|
+
sessionStorage.removeItem('subNav-topLevelId');
|
|
275
|
+
sessionStorage.removeItem('subNav-topLevelTitle');
|
|
269
276
|
}
|
|
270
277
|
}
|
|
271
278
|
|
|
272
|
-
//
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
279
|
+
// Clean up any leftover sessionStorage items
|
|
280
|
+
sessionStorage.removeItem('__subNavPageLoaded');
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// Reset currentSelectedId to ensure clean state
|
|
284
|
+
currentSelectedId = null;
|
|
285
|
+
|
|
286
|
+
// Handle scrolling if we have a URL hash
|
|
287
|
+
const targetItem = currentSelectedId
|
|
288
|
+
? findItemById(data, currentSelectedId)
|
|
289
|
+
: null;
|
|
290
|
+
if (targetItem && targetItem.href && targetItem.href.includes('#')) {
|
|
291
|
+
const hash = targetItem.href.split('#')[1];
|
|
292
|
+
if (hash) {
|
|
293
|
+
setTimeout(() => scrollToAnchorWithOffset(hash), 100);
|
|
282
294
|
}
|
|
283
295
|
}
|
|
296
|
+
|
|
297
|
+
// Mark page load as complete
|
|
298
|
+
pageLoadComplete = true;
|
|
284
299
|
subNavReady.set(true);
|
|
285
300
|
});
|
|
286
301
|
|
|
@@ -293,22 +308,17 @@
|
|
|
293
308
|
}
|
|
294
309
|
currentSelectedId = item.id;
|
|
295
310
|
const topLevel = findTopLevelParent(item, data) || item;
|
|
311
|
+
|
|
296
312
|
import('@gsa-tts/graymatter-ui/stores/navigationStore')
|
|
297
313
|
.then(({ selectedSubNavItemTitle }) => {
|
|
298
314
|
selectedSubNavItemTitle.set(topLevel.title || '');
|
|
299
|
-
if (typeof window !== 'undefined') {
|
|
300
|
-
sessionStorage.setItem('subNav-selectedId', JSON.stringify(item.id));
|
|
301
|
-
sessionStorage.setItem(
|
|
302
|
-
'subNav-topLevelId',
|
|
303
|
-
JSON.stringify(topLevel.id)
|
|
304
|
-
);
|
|
305
|
-
sessionStorage.setItem(
|
|
306
|
-
'subNav-topLevelTitle',
|
|
307
|
-
JSON.stringify(topLevel.title || '')
|
|
308
|
-
);
|
|
309
|
-
}
|
|
310
315
|
})
|
|
311
316
|
.catch();
|
|
317
|
+
|
|
318
|
+
// Save selectedId to sessionStorage for persistence
|
|
319
|
+
if (typeof window !== 'undefined') {
|
|
320
|
+
sessionStorage.setItem('subNav-selectedId', JSON.stringify(item.id));
|
|
321
|
+
}
|
|
312
322
|
if (typeof window !== 'undefined') {
|
|
313
323
|
if (item.href && item.href.includes('#')) {
|
|
314
324
|
const hash = item.href.split('#')[1];
|