@salesforcedevs/dx-components 1.40.0-alpha → 1.40.0-banner-alpha
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
|
@@ -378,31 +378,88 @@ export function getVersionPickerOptions(
|
|
|
378
378
|
}));
|
|
379
379
|
}
|
|
380
380
|
|
|
381
|
-
|
|
381
|
+
/**
|
|
382
|
+
* Version whose page (or a descendant of it) is the current URL.
|
|
383
|
+
* Ignores the session-stored picker selection, which can remember an older
|
|
384
|
+
* version while the reader is still on the latest page.
|
|
385
|
+
*/
|
|
386
|
+
export function versionForCurrentPage(
|
|
382
387
|
node: VersionedNode | undefined
|
|
383
388
|
): TopicVersionOption | undefined {
|
|
384
389
|
const versions = node?.versions;
|
|
385
|
-
if (!node || !versions?.length) {
|
|
390
|
+
if (!node || !versions?.length || !isBrowser()) {
|
|
386
391
|
return undefined;
|
|
387
392
|
}
|
|
388
393
|
|
|
389
|
-
const
|
|
390
|
-
|
|
394
|
+
const hrefs = collectSubtreeCanonicalHrefs(node);
|
|
395
|
+
const matches = (version: TopicVersionOption) =>
|
|
396
|
+
hrefMatchesCurrentPage(version.link?.href) ||
|
|
397
|
+
hrefs.some((href) => hrefMatchesVersion(href, version, versions));
|
|
398
|
+
|
|
399
|
+
// Older versions first so a rewritten child URL is not mistaken for latest.
|
|
400
|
+
const older = versions.find(
|
|
401
|
+
(version) => version.id !== versions[0].id && matches(version)
|
|
391
402
|
);
|
|
392
|
-
if (
|
|
393
|
-
return
|
|
403
|
+
if (older) {
|
|
404
|
+
return older;
|
|
394
405
|
}
|
|
395
406
|
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
407
|
+
return matches(versions[0]) ? versions[0] : undefined;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* Deepest versioned topic that contains the current page, with the version
|
|
412
|
+
* the URL selects. Nested versioned topics own their pages.
|
|
413
|
+
*/
|
|
414
|
+
export function findTopicVersionForCurrentPage(
|
|
415
|
+
nodes: VersionedNode[] | undefined | null
|
|
416
|
+
): { node: VersionedNode; version: TopicVersionOption } | undefined {
|
|
417
|
+
let match: { node: VersionedNode; version: TopicVersionOption } | undefined;
|
|
418
|
+
const walk = (list?: VersionedNode[] | null) => {
|
|
419
|
+
for (const node of list || []) {
|
|
420
|
+
const version = versionForCurrentPage(node);
|
|
421
|
+
if (version) {
|
|
422
|
+
match = { node, version };
|
|
423
|
+
}
|
|
424
|
+
walk(node.children);
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
walk(nodes);
|
|
428
|
+
return match;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Current page rewritten onto the latest topic version. Falls back to the
|
|
433
|
+
* latest switching URL when the path delta cannot be applied.
|
|
434
|
+
*/
|
|
435
|
+
export function latestHrefForCurrentPage(
|
|
436
|
+
versions: TopicVersionOption[] | undefined
|
|
437
|
+
): string | undefined {
|
|
438
|
+
const latest = versions?.[0];
|
|
439
|
+
if (!latest) {
|
|
440
|
+
return undefined;
|
|
441
|
+
}
|
|
442
|
+
if (!isBrowser()) {
|
|
443
|
+
return latest.link?.href;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
const canonical = toCanonicalHref(window.location.pathname, versions);
|
|
447
|
+
return applyVersionToHref(canonical, latest, versions) || latest.link?.href;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
export function resolveSelectedVersion(
|
|
451
|
+
node: VersionedNode | undefined
|
|
452
|
+
): TopicVersionOption | undefined {
|
|
453
|
+
const versions = node?.versions;
|
|
454
|
+
if (!node || !versions?.length) {
|
|
455
|
+
return undefined;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
// The open page wins, including a canonical child opened from "View Latest".
|
|
459
|
+
// Session is only for a picker whose topic is not the current page.
|
|
460
|
+
const fromUrl = versionForCurrentPage(node);
|
|
461
|
+
if (fromUrl) {
|
|
462
|
+
return fromUrl;
|
|
406
463
|
}
|
|
407
464
|
|
|
408
465
|
const storedId = readTopicVersionSelections()[getTopicVersionKey(node)];
|