@salesforcedevs/docs-components 1.34.3-final-alpha1 → 1.34.3-fix-redoc-topic-v-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.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforcedevs/docs-components",
|
|
3
|
-
"version": "1.34.3-
|
|
3
|
+
"version": "1.34.3-fix-redoc-topic-v-1",
|
|
4
4
|
"description": "Docs Lightning web components for DSC",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "index.js",
|
|
@@ -25,5 +25,6 @@
|
|
|
25
25
|
"@types/lodash.orderby": "4.6.9",
|
|
26
26
|
"@types/lodash.uniqby": "4.7.9"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "4629fdd9ca18a13480044ad43515b91945d16aad"
|
|
28
|
+
"gitHead": "4629fdd9ca18a13480044ad43515b91945d16aad",
|
|
29
|
+
"stableVersion": "1.34.3"
|
|
29
30
|
}
|
|
@@ -10,6 +10,15 @@ import { throttle } from "throttle-debounce";
|
|
|
10
10
|
import { pollUntil } from "dxUtils/async";
|
|
11
11
|
import { toJson } from "dxUtils/normalizers";
|
|
12
12
|
import { oldVersionDocInfo } from "docUtils/utils";
|
|
13
|
+
import {
|
|
14
|
+
applyVersionToHref,
|
|
15
|
+
collectSubtreeCanonicalHrefs,
|
|
16
|
+
normalizePath,
|
|
17
|
+
getTopicVersionKey,
|
|
18
|
+
persistTopicVersion,
|
|
19
|
+
toCanonicalHref
|
|
20
|
+
} from "dxUtils/topicVersion";
|
|
21
|
+
import type { VersionedNode } from "dxUtils/topicVersion";
|
|
13
22
|
import type { DocPhaseInfo, OptionWithLink } from "typings/custom";
|
|
14
23
|
|
|
15
24
|
declare global {
|
|
@@ -47,6 +56,8 @@ type ReferenceVersion = {
|
|
|
47
56
|
type ReferenceConfig = {
|
|
48
57
|
refList: ReferenceItem[];
|
|
49
58
|
versions?: ReferenceVersion[];
|
|
59
|
+
/** Sidebar topic name. Sidebar stores the selected version under this key. */
|
|
60
|
+
versionTopicKey?: string;
|
|
50
61
|
};
|
|
51
62
|
|
|
52
63
|
const SCROLL_THROTTLE_DELAY = 50;
|
|
@@ -129,6 +140,30 @@ export default class RedocReference extends LightningElement {
|
|
|
129
140
|
*/
|
|
130
141
|
@api headerHref: string | null = null;
|
|
131
142
|
|
|
143
|
+
/**
|
|
144
|
+
* Versioned topic that owns this spec, including its children.
|
|
145
|
+
* Href matches this page, so an older version still has its version
|
|
146
|
+
* in the path.
|
|
147
|
+
*/
|
|
148
|
+
@api
|
|
149
|
+
set parentTopicFamily(value: string | { topics?: VersionedNode[] } | null) {
|
|
150
|
+
try {
|
|
151
|
+
const parsed = toJson(value) as { topics?: VersionedNode[] } | null;
|
|
152
|
+
this._parentTopicFamilyNode = parsed?.topics?.[0] ?? null;
|
|
153
|
+
} catch (error) {
|
|
154
|
+
this._parentTopicFamilyNode = null;
|
|
155
|
+
console.error("Failed to parse parent topic family", error);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
get parentTopicFamily(): { topics?: VersionedNode[] } | null {
|
|
160
|
+
return this._parentTopicFamilyNode
|
|
161
|
+
? { topics: [this._parentTopicFamilyNode] }
|
|
162
|
+
: null;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
private _parentTopicFamilyNode: VersionedNode | null = null;
|
|
166
|
+
|
|
132
167
|
@api
|
|
133
168
|
get contentType(): string {
|
|
134
169
|
return this._contentType;
|
|
@@ -233,13 +268,51 @@ export default class RedocReference extends LightningElement {
|
|
|
233
268
|
private onBackClick = (event: Event): void => {
|
|
234
269
|
event.preventDefault();
|
|
235
270
|
|
|
236
|
-
const target = this.
|
|
271
|
+
const target = this.getVersionedBackTarget() ?? this.headerHref;
|
|
237
272
|
|
|
238
273
|
if (target) {
|
|
239
274
|
window.location.assign(target);
|
|
240
275
|
}
|
|
241
276
|
};
|
|
242
277
|
|
|
278
|
+
/**
|
|
279
|
+
* When the back target is in this spec's topic, return it on the
|
|
280
|
+
* selected version. With no back target, do the same for the header
|
|
281
|
+
* link when that link is the versioned parent.
|
|
282
|
+
*/
|
|
283
|
+
private getVersionedBackTarget(): string | null {
|
|
284
|
+
const stored = this.getTranslatedBackTarget();
|
|
285
|
+
const selectedVersion = this.selectedVersion;
|
|
286
|
+
const target = stored ?? this.headerHref;
|
|
287
|
+
if (!target || !selectedVersion) {
|
|
288
|
+
return stored;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// Family hrefs match this page's version. Compare them without
|
|
292
|
+
// the version segment.
|
|
293
|
+
const familyHrefs = this._parentTopicFamilyNode
|
|
294
|
+
? collectSubtreeCanonicalHrefs(this._parentTopicFamilyNode).map(
|
|
295
|
+
(href) => toCanonicalHref(href, this.versions)
|
|
296
|
+
)
|
|
297
|
+
: [];
|
|
298
|
+
|
|
299
|
+
const canonicalTarget = toCanonicalHref(target, this.versions);
|
|
300
|
+
const inFamily = familyHrefs.some(
|
|
301
|
+
(href) => normalizePath(href) === normalizePath(canonicalTarget)
|
|
302
|
+
);
|
|
303
|
+
if (!inFamily) {
|
|
304
|
+
return target;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
return (
|
|
308
|
+
applyVersionToHref(
|
|
309
|
+
canonicalTarget,
|
|
310
|
+
selectedVersion,
|
|
311
|
+
this.versions
|
|
312
|
+
) ?? target
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
|
|
243
316
|
private getTranslatedBackTarget(): string | null {
|
|
244
317
|
const stored = this.getBackTargetFromSession();
|
|
245
318
|
if (stored) {
|
|
@@ -362,6 +435,13 @@ export default class RedocReference extends LightningElement {
|
|
|
362
435
|
// Track the back target, preserving it across locale switches
|
|
363
436
|
this.trackBackTarget();
|
|
364
437
|
|
|
438
|
+
// Remember the selected version for the sidebar. Changing version
|
|
439
|
+
// reloads this page.
|
|
440
|
+
const topicKey = this.getParentTopicVersionKey();
|
|
441
|
+
if (topicKey && this.selectedVersion) {
|
|
442
|
+
persistTopicVersion(topicKey, this.selectedVersion.id);
|
|
443
|
+
}
|
|
444
|
+
|
|
365
445
|
window.addEventListener("scroll", this.handleScrollAndResize);
|
|
366
446
|
window.addEventListener("resize", this.handleScrollAndResize);
|
|
367
447
|
}
|
|
@@ -670,6 +750,18 @@ export default class RedocReference extends LightningElement {
|
|
|
670
750
|
return wrapper;
|
|
671
751
|
}
|
|
672
752
|
|
|
753
|
+
/**
|
|
754
|
+
* Key the sidebar uses for this topic's selected version.
|
|
755
|
+
* Missing `versionTopicKey` returns null so nothing is written.
|
|
756
|
+
*/
|
|
757
|
+
private getParentTopicVersionKey(): string | null {
|
|
758
|
+
const versionTopicKey = this._referenceConfig?.versionTopicKey;
|
|
759
|
+
if (!versionTopicKey) {
|
|
760
|
+
return null;
|
|
761
|
+
}
|
|
762
|
+
return getTopicVersionKey({ name: versionTopicKey }) || null;
|
|
763
|
+
}
|
|
764
|
+
|
|
673
765
|
/** Stashes the current view (URL hash) before the version link navigates. */
|
|
674
766
|
private onVersionChange = (): void => {
|
|
675
767
|
sessionStorage.setItem(
|