@salesforcedevs/docs-components 0.54.0 → 0.54.1-a01

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.
Files changed (44) hide show
  1. package/lwc.config.json +6 -2
  2. package/package.json +12 -4
  3. package/src/modules/README.md +41 -0
  4. package/src/modules/doc/amfReference/amfReference.css +5 -0
  5. package/src/modules/doc/amfReference/amfReference.html +47 -0
  6. package/src/modules/doc/amfReference/amfReference.ts +1309 -0
  7. package/src/modules/doc/amfReference/constants.ts +76 -0
  8. package/src/modules/doc/amfReference/types.ts +133 -0
  9. package/src/modules/doc/amfReference/utils.ts +669 -0
  10. package/src/modules/doc/amfTopic/amfTopic.css +1 -0
  11. package/src/modules/doc/amfTopic/amfTopic.html +3 -0
  12. package/src/modules/doc/amfTopic/amfTopic.ts +94 -0
  13. package/src/modules/doc/amfTopic/types.ts +54 -0
  14. package/src/modules/doc/amfTopic/utils.ts +130 -0
  15. package/src/modules/doc/breadcrumbItem/breadcrumbItem.css +4 -3
  16. package/src/modules/doc/breadcrumbItem/breadcrumbItem.html +1 -1
  17. package/src/modules/doc/breadcrumbItem/breadcrumbItem.ts +17 -1
  18. package/src/modules/doc/breadcrumbs/breadcrumbs.css +11 -3
  19. package/src/modules/doc/breadcrumbs/breadcrumbs.html +12 -2
  20. package/src/modules/doc/breadcrumbs/breadcrumbs.ts +50 -9
  21. package/src/modules/doc/content/content.css +35 -11
  22. package/src/modules/doc/content/content.ts +18 -3
  23. package/src/modules/doc/contentCallout/contentCallout.css +4 -4
  24. package/src/modules/doc/contentCallout/contentCallout.ts +5 -0
  25. package/src/modules/doc/contentLayout/contentLayout.css +98 -0
  26. package/src/modules/doc/contentLayout/contentLayout.html +48 -0
  27. package/src/modules/doc/contentLayout/contentLayout.ts +287 -0
  28. package/src/modules/doc/header/header.css +1 -1
  29. package/src/modules/doc/header/header.ts +5 -5
  30. package/src/modules/doc/headingAnchor/headingAnchor.css +1 -1
  31. package/src/modules/doc/headingContent/headingContent.css +5 -1
  32. package/src/modules/doc/phase/phase.css +3 -3
  33. package/src/modules/doc/phase/phase.ts +1 -1
  34. package/src/modules/doc/xmlContent/types.ts +114 -0
  35. package/src/modules/doc/xmlContent/utils.ts +161 -0
  36. package/src/modules/doc/xmlContent/xmlContent.css +32 -0
  37. package/src/modules/doc/xmlContent/xmlContent.html +39 -0
  38. package/src/modules/doc/xmlContent/xmlContent.ts +651 -0
  39. package/src/modules/docBaseElements/lightningElementWithState/lightningElementWithState.ts +93 -0
  40. package/src/modules/docHelpers/amfStyle/amfStyle.css +390 -0
  41. package/src/modules/docHelpers/phaseContentLayout/phaseContentLayout.css +39 -0
  42. package/src/modules/{helpers → docHelpers}/status/status.css +0 -0
  43. package/src/modules/docUtils/SearchSyncer/SearchSyncer.ts +85 -0
  44. package/LICENSE +0 -12
@@ -0,0 +1,1309 @@
1
+ import { LightningElement, api, track } from "lwc";
2
+ import { noCase } from "no-case";
3
+ import { sentenceCase } from "sentence-case";
4
+ import qs from "query-string";
5
+ import { AmfModelParser } from "./utils";
6
+ import { normalizeBoolean } from "dxUtils/normalizers";
7
+ import type {
8
+ AmfConfig,
9
+ AmfMetadataTopic,
10
+ AmfModel,
11
+ AmfModelRecord,
12
+ NavItem,
13
+ ParsedTopicModel,
14
+ TopicModel,
15
+ ReferenceVersion,
16
+ ReferenceSetConfig,
17
+ AmfMetaTopicType,
18
+ RouteMeta,
19
+ ParsedMarkdownTopic
20
+ } from "./types";
21
+
22
+ import {
23
+ NAVIGATION_ITEMS,
24
+ URL_CONFIG,
25
+ REFERENCE_TYPES,
26
+ oldReferenceIdNewReferenceIdMap
27
+ } from "./constants";
28
+
29
+ export default class AmfReference extends LightningElement {
30
+ @api breadcrumbs?: string | null | undefined = null;
31
+ @api sidebarHeader!: string;
32
+ @api coveoOrganizationId!: string;
33
+ @api coveoPublicAccessToken!: string;
34
+ @api coveoAdvancedQueryConfig!: string;
35
+ @api coveoSearchHub!: string;
36
+ @api useOldSidebar?: boolean = false;
37
+ @api tocTitle?: string;
38
+ @api tocOptions?: string;
39
+ @track navigation = [];
40
+ @track versions: Array<ReferenceVersion> = [];
41
+
42
+ // Update this to update what component gets rendered in the content block
43
+ @track
44
+ protected topicModel!: TopicModel;
45
+
46
+ get isVersionEnabled(): boolean {
47
+ return !!this._referenceSetConfig?.versions?.length;
48
+ }
49
+
50
+ /**
51
+ * Gives if the currently selected reference is spec based or not
52
+ */
53
+ get showSpecBasedReference(): boolean {
54
+ return this.isSpecBasedReference(this._currentReferenceId);
55
+ }
56
+
57
+ @api
58
+ get referenceSetConfig(): ReferenceSetConfig {
59
+ return this._referenceSetConfig;
60
+ }
61
+
62
+ set referenceSetConfig(value: ReferenceSetConfig) {
63
+ // No change, do nothing.
64
+ if (value === this._referenceSetConfig) {
65
+ return;
66
+ }
67
+
68
+ try {
69
+ const refConfig =
70
+ typeof value === "string" ? JSON.parse(value) : value;
71
+ if (!(<ReferenceSetConfig>refConfig).versions) {
72
+ return;
73
+ }
74
+ this._referenceSetConfig = refConfig;
75
+ } catch (e) {
76
+ this._referenceSetConfig = {
77
+ refList: [],
78
+ versions: []
79
+ };
80
+ }
81
+
82
+ this._amfConfigList = this._referenceSetConfig.refList || [];
83
+
84
+ this._amfConfigList.forEach((amfConfig) => {
85
+ this._amfConfigMap.set(amfConfig.id, amfConfig);
86
+ });
87
+
88
+ if (this._amfConfigList.length > 0) {
89
+ this._currentReferenceId =
90
+ this._referenceSetConfig.refId || this._amfConfigList[0].id;
91
+ }
92
+
93
+ if (this.isVersionEnabled) {
94
+ const selectedVersion = this.getSelectedVersion();
95
+
96
+ /**
97
+ * If current selected is markdown based reference,
98
+ * We will assign versions once the selected item url is updated
99
+ */
100
+ if (this.isSpecBasedReference(this._currentReferenceId)) {
101
+ this.versions = this.getVersions();
102
+ }
103
+ this.selectedVersion = selectedVersion;
104
+ }
105
+
106
+ // This is to check if the url is hash based and redirect if needed
107
+ const redirectUrl = this.getHashBasedRedirectUrl();
108
+ if (redirectUrl) {
109
+ window.location.href = redirectUrl;
110
+ } else {
111
+ this.updateAmfConfigInView();
112
+ }
113
+ }
114
+
115
+ @api
116
+ get docPhaseInfo() {
117
+ return this.selectedReferenceDocPhase;
118
+ }
119
+
120
+ set docPhaseInfo(value: string) {
121
+ if (value) {
122
+ this.isParentLevelDocPhaseEnabled = true;
123
+ this.selectedReferenceDocPhase = value;
124
+ }
125
+ }
126
+
127
+ @api
128
+ get expandChildren() {
129
+ return this._expandChildren;
130
+ }
131
+
132
+ set expandChildren(value) {
133
+ this._expandChildren = normalizeBoolean(value);
134
+ }
135
+
136
+ // model
137
+ protected _amfConfigList: AmfConfig[] = [];
138
+ protected _amfConfigMap: Map<string, AmfConfig> = new Map();
139
+ protected _referenceSetConfig!: ReferenceSetConfig;
140
+ protected _currentReferenceId = "";
141
+
142
+ protected parentReferenceUrls = [];
143
+ protected amfMap: Record<string, AmfModelRecord> = {};
144
+ protected amfFetchPromiseMap = {};
145
+ protected metadata: { [key: string]: AmfMetadataTopic } = {};
146
+ protected selectedTopic?: AmfMetaTopicType = undefined;
147
+ protected selectedSidebarValue = undefined;
148
+
149
+ protected selectedVersion: ReferenceVersion | null = null;
150
+
151
+ private hasRendered = false;
152
+
153
+ private isParentLevelDocPhaseEnabled = false;
154
+ private selectedReferenceDocPhase?: string | null = null;
155
+ private _expandChildren?: boolean = false;
156
+
157
+ /**
158
+ * Key for storing the currently selected reference url. This will be used to save the
159
+ * previously selected reference url and restoring it when changing between reference versions.
160
+ */
161
+ private readonly docsReferenceUrlSessionKey: string = "docsReferenceUrl";
162
+
163
+ _boundOnApiNavigationChanged;
164
+ _boundUpdateSelectedItemFromUrlQuery;
165
+
166
+ constructor() {
167
+ super();
168
+ this._boundOnApiNavigationChanged =
169
+ this.onApiNavigationChanged.bind(this);
170
+ this._boundUpdateSelectedItemFromUrlQuery =
171
+ this.updateSelectedItemFromUrlQuery.bind(this);
172
+ }
173
+
174
+ connectedCallback(): void {
175
+ this.addEventListener(
176
+ "api-navigation-selection-changed",
177
+ this._boundOnApiNavigationChanged
178
+ );
179
+ window.addEventListener(
180
+ "popstate",
181
+ this._boundUpdateSelectedItemFromUrlQuery
182
+ );
183
+ }
184
+
185
+ disconnectedCallback(): void {
186
+ this.removeEventListener(
187
+ "api-navigation-selection-changed",
188
+ this._boundOnApiNavigationChanged
189
+ );
190
+ window.removeEventListener(
191
+ "popstate",
192
+ this._boundUpdateSelectedItemFromUrlQuery
193
+ );
194
+ }
195
+
196
+ renderedCallback(): void {
197
+ if (!this.hasRendered) {
198
+ this.hasRendered = true;
199
+ if (this._amfConfigList && this._amfConfigList.length) {
200
+ // If amfConfig has a value and length, it is assumed that fetch
201
+ // has already been called and promises stored.
202
+ this.updateView();
203
+ }
204
+ }
205
+ }
206
+
207
+ /**
208
+ * Check if the URL hash to see whether this is one we want to redirect
209
+ * See GUS W-10718771 for references where we want hash-based redirects
210
+ * Return if we needs to redirect url to updated url
211
+ */
212
+ private getHashBasedRedirectUrl(): string | undefined {
213
+ const { hash } = window.location;
214
+ let hashBasedRedirectUrl = "";
215
+ if (hash) {
216
+ const strippedHash = hash.startsWith("#") ? hash.slice(1) : hash;
217
+ const strippedHashItems = strippedHash
218
+ ? strippedHash.split(":")
219
+ : [];
220
+ if (strippedHashItems.length) {
221
+ const referenceId = strippedHashItems[0];
222
+ const meta = strippedHashItems[1];
223
+ const encodedMeta = this.getUrlEncoded(meta);
224
+ const updatedReferenceId =
225
+ oldReferenceIdNewReferenceIdMap[referenceId];
226
+ const newReferenceId = updatedReferenceId || referenceId;
227
+ const referenceItemConfig =
228
+ this.getAmfConfigWithId(newReferenceId);
229
+ if (referenceItemConfig) {
230
+ hashBasedRedirectUrl = `${referenceItemConfig.href}?meta=${encodedMeta}`;
231
+ }
232
+ }
233
+ }
234
+ return hashBasedRedirectUrl;
235
+ }
236
+
237
+ /**
238
+ * @param referenceId
239
+ * @returns AMFConfig with given reference Id
240
+ */
241
+ private getAmfConfigWithId(referenceId: string): AmfConfig | undefined {
242
+ return this._amfConfigMap.get(referenceId);
243
+ }
244
+
245
+ /**
246
+ * @param referenceId
247
+ * @returns if the reference is spec based one or not with given referenceId.
248
+ */
249
+ private isSpecBasedReference(referenceId: string): boolean {
250
+ const selectedReference = this.getAmfConfigWithId(referenceId);
251
+ return selectedReference
252
+ ? selectedReference.referenceType !== REFERENCE_TYPES.markdown
253
+ : false;
254
+ }
255
+
256
+ /*
257
+ * Refactor below method when sidebar allows sending extraData along with the name for each item.
258
+ * See if we can refactor the below method using regex.
259
+ */
260
+
261
+ /**
262
+ * @param url
263
+ * @returns reference Id from url path / selected sidebar item.
264
+ */
265
+ private getReferenceIdFromUrl(url: string): string {
266
+ let referenceId = "";
267
+ const urlItems = url.split("/references/");
268
+ if (urlItems.length > 1) {
269
+ const rightSidePart = urlItems[1];
270
+
271
+ //This covers urls like "/project-name/references/reference-id/..."
272
+ const slashSeparatorItems = rightSidePart.split("/");
273
+
274
+ //This covers urls like "/project-name/references/reference-id?meta=Summary"
275
+ const querySeparatorItems = slashSeparatorItems[0].split("?");
276
+
277
+ referenceId = querySeparatorItems[0];
278
+ }
279
+
280
+ return referenceId;
281
+ }
282
+
283
+ /**
284
+ * @returns versions to be shown in the dropdown
285
+ * For markdown based specs, Adds selected markdown topic url to same references
286
+ */
287
+ private getVersions(): Array<ReferenceVersion> {
288
+ const allVersions = this._referenceSetConfig.versions;
289
+ if (!this.isSpecBasedReference(this._currentReferenceId)) {
290
+ const currentRefMeta = this.getMarkdownReferenceMeta(
291
+ window.location.href
292
+ );
293
+ if (currentRefMeta) {
294
+ for (let i = 0; i < allVersions.length; i++) {
295
+ const versionItem = allVersions[i];
296
+ const referenceLink = versionItem.link.href;
297
+ const referenceId =
298
+ this.getReferenceIdFromUrl(referenceLink);
299
+ if (this._currentReferenceId === referenceId) {
300
+ // This is to navigate to respective topic in the changed version
301
+ versionItem.link.href = `${referenceLink}/${currentRefMeta}`;
302
+ allVersions[i] = versionItem;
303
+ }
304
+ }
305
+ }
306
+ }
307
+ return allVersions;
308
+ }
309
+
310
+ /**
311
+ * Returns the selected version or the first available version.
312
+ */
313
+ private getSelectedVersion(): ReferenceVersion {
314
+ const versions = this._referenceSetConfig?.versions || [];
315
+ const selectedVersion = versions.find(
316
+ (v: ReferenceVersion) => v.selected
317
+ );
318
+ // return a selected version if there is one, else return the first one.
319
+ return selectedVersion || (versions.length && versions[0]);
320
+ }
321
+
322
+ private updateAmfConfigInView(): void {
323
+ if (this._amfConfigList && this._amfConfigList.length) {
324
+ // fetch AMF Json as soon as config is set
325
+ this.populateReferenceItems();
326
+ // update() must be called after renderedCallback.
327
+ if (this.hasRendered) {
328
+ this.updateView();
329
+ }
330
+ }
331
+ }
332
+
333
+ private async fetchAmf(amfConfig): Promise<AmfModel | AmfModel[]> {
334
+ const { amf } = amfConfig;
335
+ const response = await fetch(amf, {
336
+ headers: {
337
+ "Cache-Control": `max-age=86400`
338
+ }
339
+ });
340
+ const json = await response.json();
341
+ return json;
342
+ }
343
+
344
+ /**
345
+ * Returns whether current location is project root path like ../example-project/references
346
+ */
347
+ private isProjectRootPath(): boolean {
348
+ return this.getReferenceIdFromUrl(window.location.href) === "";
349
+ }
350
+
351
+ /**
352
+ * Returns whether given url is parent reference path like ../example-project/references/reference-id
353
+ */
354
+ private isParentReferencePath(urlPath: string): boolean {
355
+ if (!urlPath) {
356
+ return false;
357
+ }
358
+ const parentReferenceIndex = this.parentReferenceUrls.findIndex(
359
+ (referenceUrl: string) => {
360
+ return urlPath.endsWith(referenceUrl);
361
+ }
362
+ );
363
+ return parentReferenceIndex !== -1;
364
+ }
365
+
366
+ /**
367
+ * Populates reference Items from amfConfigList and assigns it to navigation for sidebar
368
+ */
369
+ private populateReferenceItems(): void {
370
+ const navAmfOrder = [];
371
+ for (const [index, amfConfig] of this._amfConfigList.entries()) {
372
+ let navItemChildren = [];
373
+ let isChildrenLoading = false;
374
+ if (amfConfig.referenceType !== REFERENCE_TYPES.markdown) {
375
+ if (amfConfig.isSelected) {
376
+ const amfPromise = this.fetchAmf(amfConfig).then(
377
+ (amfJson) => {
378
+ this.updateModel(amfConfig.id, amfJson);
379
+ this.assignNavigationItemsFromAmf(amfConfig, index);
380
+ }
381
+ );
382
+ this.amfFetchPromiseMap[amfConfig.id] = amfPromise;
383
+ }
384
+ isChildrenLoading = true;
385
+ } else {
386
+ navItemChildren = amfConfig.topic.children;
387
+ }
388
+ // store nav items for each spec in order
389
+ navAmfOrder[index] = {
390
+ label: amfConfig.title,
391
+ name: amfConfig.href,
392
+ isExpanded:
393
+ amfConfig.isSelected ||
394
+ this.isExpandChildrenEnabled(amfConfig.id),
395
+ children: navItemChildren,
396
+ isChildrenLoading
397
+ };
398
+ this.parentReferenceUrls.push(amfConfig.href);
399
+ }
400
+ this.navigation = navAmfOrder;
401
+ }
402
+
403
+ /**
404
+ * Returns a boolean indicating whether the children should be expanded or not.
405
+ */
406
+ private isExpandChildrenEnabled(referenceId: string): boolean {
407
+ return this.expandChildren && this._currentReferenceId === referenceId;
408
+ }
409
+
410
+ /**
411
+ * Stores fetched AMF JSON value.
412
+ * Creates and stores a new AmfModelParser instance for the AMF spec.
413
+ * @param {*} referenceId
414
+ * @param {*} amf
415
+ */
416
+ private updateModel(referenceId: string, amf: AmfModel | AmfModel[]): void {
417
+ const parser = new AmfModelParser(amf);
418
+ this.amfMap[referenceId] = {
419
+ model: amf,
420
+ parser: parser,
421
+ parsedModel: parser.parsedModel
422
+ };
423
+ }
424
+
425
+ /**
426
+ * Convert any case to a readable Title
427
+ * ex: snake_case => Snake case
428
+ * ex: camelCase => Camel case
429
+ * ex: PascalCase => Pascal case
430
+ * @param label
431
+ * @returns string
432
+ */
433
+ private getTitleForLabel(label: string): string {
434
+ return sentenceCase(noCase(label));
435
+ }
436
+
437
+ /**
438
+ * Transforms a list of model data for endpoints into corresponding
439
+ * navigation list items that are compatible with dx-sidebar.
440
+ * Compatible with transforming AMF data parsed from both RAML and OAS spec.
441
+ * Transforms a flat list of endpoints into a nested list based on indentation level
442
+ * for RAML spec.
443
+ * @param {Array<Object>} items An array of endpoints.
444
+ * @returns {array<Object>} List of navigation items
445
+ */
446
+ private assignEndpointNavItems(
447
+ parentReferencePath: string,
448
+ referenceId: string,
449
+ items: ParsedTopicModel[]
450
+ ): NavItem[] {
451
+ const methodList = [];
452
+
453
+ items.forEach((item) => {
454
+ item.methods?.forEach((method) => {
455
+ const title =
456
+ this.getTitleForLabel(method.label) || method.method;
457
+ const meta = this.addToMetadata(
458
+ parentReferencePath,
459
+ referenceId,
460
+ "method",
461
+ method,
462
+ title
463
+ );
464
+ methodList.push(
465
+ Object.assign(method, {
466
+ name: this.getReferencePathWithMeta(
467
+ parentReferencePath,
468
+ meta
469
+ ),
470
+ label: title
471
+ })
472
+ );
473
+ });
474
+ });
475
+ return methodList;
476
+ }
477
+
478
+ /**
479
+ * Gives URL path for reference items, Which can be used to push to the history
480
+ */
481
+ private getReferencePathWithMeta(
482
+ parentReferencePath: string,
483
+ meta: string
484
+ ): string {
485
+ // update the encoded url meta param
486
+ const encodedMeta = meta ? this.getUrlEncoded(meta) : "";
487
+ return encodedMeta ? `${parentReferencePath}?meta=${encodedMeta}` : "";
488
+ }
489
+
490
+ /**
491
+ * Assigns Navigation Items to dx-sidebar from the parsed AMF model.
492
+ * Adds each nav item to the Metadata by type.
493
+ * The 'summary' nav item has no children.
494
+ * The 'endpoint' nav item may have nested children.
495
+ */
496
+ private assignNavigationItemsFromAmf(
497
+ amfConfig: AmfConfig,
498
+ amfIdx: number
499
+ ): void {
500
+ const referenceId = amfConfig.id;
501
+ const parentReferencePath = amfConfig.href;
502
+ const model = this.amfMap[referenceId].parser.parsedModel;
503
+
504
+ const children = [];
505
+ const expandChildren = this.isExpandChildrenEnabled(referenceId);
506
+
507
+ NAVIGATION_ITEMS.forEach(
508
+ ({ label, name, childrenPropertyName, type }) => {
509
+ const indexedName = `${name}-${amfIdx}`;
510
+ switch (type) {
511
+ case "summary": {
512
+ const summary = model[type];
513
+ const meta = this.addToMetadata(
514
+ parentReferencePath,
515
+ referenceId,
516
+ type,
517
+ summary,
518
+ label
519
+ );
520
+ children.push({
521
+ label,
522
+ name: this.getReferencePathWithMeta(
523
+ parentReferencePath,
524
+ meta
525
+ )
526
+ });
527
+ break;
528
+ }
529
+ case "endpoint":
530
+ if (
531
+ model[childrenPropertyName] &&
532
+ model[childrenPropertyName].length
533
+ ) {
534
+ const amfTopicId = this.getFormattedIdentifier(
535
+ referenceId,
536
+ indexedName
537
+ );
538
+ const childTopics = this.assignEndpointNavItems(
539
+ parentReferencePath,
540
+ referenceId,
541
+ model[childrenPropertyName]
542
+ );
543
+ children.push({
544
+ label,
545
+ name: this.getReferencePathWithMeta(
546
+ parentReferencePath,
547
+ this.metadata[amfTopicId]?.meta
548
+ ),
549
+ isExpanded: expandChildren,
550
+ children: childTopics
551
+ });
552
+ }
553
+ break;
554
+ case "security":
555
+ case "type":
556
+ if (model[childrenPropertyName]?.length) {
557
+ // Sorting the types alphabetically
558
+ model[childrenPropertyName].sort((typeA, typeB) => {
559
+ const typeALbl = typeA.label.toLowerCase();
560
+ const typeBLbl = typeB.label.toLowerCase();
561
+ return typeALbl < typeBLbl
562
+ ? -1
563
+ : typeALbl > typeBLbl
564
+ ? 1
565
+ : 0;
566
+ });
567
+ }
568
+ // eslint-disable-next-line no-fallthrough
569
+ default:
570
+ if (
571
+ model[childrenPropertyName] &&
572
+ model[childrenPropertyName].length
573
+ ) {
574
+ const amfTopicId = this.getFormattedIdentifier(
575
+ referenceId,
576
+ indexedName
577
+ );
578
+ children.push({
579
+ label,
580
+ name: this.getReferencePathWithMeta(
581
+ parentReferencePath,
582
+ this.metadata[amfTopicId]?.meta
583
+ ),
584
+ isExpanded: expandChildren,
585
+ children: model[childrenPropertyName].map(
586
+ (topic) => {
587
+ const meta = this.addToMetadata(
588
+ parentReferencePath,
589
+ referenceId,
590
+ type,
591
+ topic,
592
+ topic.label
593
+ );
594
+ return {
595
+ label: topic.label,
596
+ name: this.getReferencePathWithMeta(
597
+ parentReferencePath,
598
+ meta
599
+ )
600
+ };
601
+ }
602
+ )
603
+ });
604
+ }
605
+ }
606
+ }
607
+ );
608
+
609
+ this.navigation[amfIdx] = {
610
+ ...this.navigation[amfIdx],
611
+ children,
612
+ isChildrenLoading: false
613
+ };
614
+ this.navigation = [...this.navigation];
615
+ }
616
+
617
+ protected addToMetadata(
618
+ parentReferencePath: string,
619
+ referenceId: string,
620
+ type: string,
621
+ topic: { id: string; domId: string },
622
+ navTitle: string
623
+ ): string | undefined {
624
+ const { urlIdentifer, prefix } = URL_CONFIG[type];
625
+
626
+ // encodeURI to avoid special characters in the URL meta.
627
+ const identifier =
628
+ topic[urlIdentifer] && this.encodeIdentifier(topic[urlIdentifer]);
629
+ let meta;
630
+ // Assuming that there will be an identifier always
631
+ if (identifier) {
632
+ meta = prefix ? `${prefix}${identifier}` : `${identifier}`;
633
+ this.metadata[meta] = {
634
+ parentReferencePath,
635
+ meta,
636
+ referenceId,
637
+ amfId: topic.id,
638
+ elementId: topic.domId,
639
+ identifier,
640
+ type,
641
+ navTitle
642
+ };
643
+ }
644
+ return meta;
645
+ }
646
+
647
+ /**
648
+ * Returns metadata given route meta
649
+ */
650
+ protected getMetadataByUrlQuery(routeMeta: RouteMeta): AmfMetadataTopic {
651
+ return Object.values(this.metadata).find(
652
+ (metadata: AmfMetadataTopic) => {
653
+ return routeMeta.meta === metadata.meta;
654
+ }
655
+ );
656
+ }
657
+
658
+ /**
659
+ * Returns metadata given reference ID and topic amf ID
660
+ */
661
+ protected getMetadataByAmfId(
662
+ referenceId: string,
663
+ amfId: string
664
+ ): AmfMetadataTopic {
665
+ // Lets make a map based on the hash values so we don't need to loop like this.
666
+ return Object.values(this.metadata).find(
667
+ (metadata: AmfMetadataTopic) =>
668
+ referenceId === metadata.referenceId && amfId === metadata.amfId
669
+ );
670
+ }
671
+
672
+ /**
673
+ * Returns metadata given reference ID and topic identifier
674
+ */
675
+ protected getMetadataByIdentifier(
676
+ referenceId: string,
677
+ identifier: string
678
+ ): AmfMetadataTopic {
679
+ // Lets make a map based on the hash values so we don't need to loop like this.
680
+ return Object.values(this.metadata).find(
681
+ (metadata: AmfMetadataTopic) =>
682
+ referenceId === metadata.referenceId &&
683
+ identifier === metadata.identifier
684
+ );
685
+ }
686
+
687
+ /**
688
+ * Returns metadata given reference ID and topic type
689
+ */
690
+ protected getMetadataByType(
691
+ referenceId: string,
692
+ type: string
693
+ ): AmfMetadataTopic {
694
+ // Lets make a map based on the hash values so we don't need to loop like this.
695
+ return Object.values(this.metadata).find(
696
+ (metadata: AmfMetadataTopic) =>
697
+ referenceId === metadata.referenceId && type === metadata.type
698
+ );
699
+ }
700
+
701
+ /**
702
+ * Parses URL query params without decoding of params
703
+ */
704
+ private parseParams(params: string): qs.ParsedQuery<string> {
705
+ if (!params) {
706
+ return {};
707
+ }
708
+ return qs.parse(params, {
709
+ decode: false
710
+ });
711
+ }
712
+
713
+ /**
714
+ * Normalizes topic identifier by replacing spaces with '+'
715
+ * and running encodeURI() on it
716
+ * @param identifier raw identifier for a topic as parsed from the spec file
717
+ * @returns normalized and encoded identifier
718
+ */
719
+ protected encodeIdentifier(identifier: string): string {
720
+ let result = identifier.trim();
721
+ result = result.replace(new RegExp(/\s+/, "g"), "+");
722
+ return encodeURI(result);
723
+ }
724
+
725
+ /**
726
+ * Constructs a Reference Topic ID
727
+ */
728
+ protected getFormattedIdentifier(referenceId: string, id: string): string {
729
+ return `${referenceId}:${id}`;
730
+ }
731
+
732
+ protected updateUrlWithSelected(
733
+ parentReferencePath: string,
734
+ meta?: string
735
+ ): void {
736
+ if (meta) {
737
+ // update the encoded url meta param
738
+ const encodedMeta = this.getUrlEncoded(meta);
739
+ window.history.pushState(
740
+ {},
741
+ "",
742
+ `${parentReferencePath}?meta=${encodedMeta}`
743
+ );
744
+ }
745
+ }
746
+
747
+ /**
748
+ * Does a replace on the URL meta, so it does not create a history entry.
749
+ */
750
+ protected replaceUrlWithSelected(
751
+ parentReferencePath: string,
752
+ meta?: string
753
+ ): void {
754
+ if (meta) {
755
+ // update the encoded url meta param
756
+ const encodedMeta = this.getUrlEncoded(meta);
757
+ window.history.replaceState(
758
+ {},
759
+ "",
760
+ `${parentReferencePath}?meta=${encodedMeta}`
761
+ );
762
+ }
763
+ }
764
+
765
+ /**
766
+ * This method gets called when the user navigates back and forth using browser arrows
767
+ * Updates content depending on the type of reference - spec based or markdown
768
+ */
769
+ protected updateSelectedItemFromUrlQuery(): void {
770
+ const specBasedReference = this.isSpecBasedReference(
771
+ this._currentReferenceId
772
+ );
773
+ if (specBasedReference) {
774
+ const currentMeta: RouteMeta | null = this.getReferenceMetaInfo(
775
+ window.location.href
776
+ );
777
+ const metadata =
778
+ currentMeta && this.getMetadataByUrlQuery(currentMeta);
779
+ if (metadata) {
780
+ const {
781
+ parentReferencePath,
782
+ referenceId,
783
+ amfId,
784
+ type,
785
+ elementId
786
+ }: AmfMetadataTopic = metadata;
787
+ this.loadSpecReferenceContent(
788
+ parentReferencePath,
789
+ referenceId,
790
+ amfId,
791
+ type,
792
+ elementId,
793
+ currentMeta.meta
794
+ );
795
+ }
796
+ } else {
797
+ this.loadMarkdownBasedReference();
798
+ }
799
+ }
800
+
801
+ /**
802
+ * The API Navigation event will always intend to navigate within the current reference
803
+ * @param event
804
+ */
805
+ protected onApiNavigationChanged(): void {
806
+ const specBasedReference = this.isSpecBasedReference(
807
+ this._currentReferenceId
808
+ );
809
+ if (specBasedReference) {
810
+ const { meta } = this.selectedTopic;
811
+ const metadata = this.metadata[meta];
812
+ if (metadata) {
813
+ const {
814
+ parentReferencePath,
815
+ referenceId,
816
+ amfId,
817
+ type,
818
+ elementId
819
+ }: AmfMetadataTopic = metadata;
820
+ this.loadSpecReferenceContent(
821
+ parentReferencePath,
822
+ referenceId,
823
+ amfId,
824
+ type,
825
+ elementId,
826
+ metadata.meta
827
+ );
828
+ }
829
+ } else {
830
+ this.loadMarkdownBasedReference();
831
+ }
832
+ }
833
+
834
+ /**
835
+ * Updates the currently selected amf and topic
836
+ */
837
+ protected loadSpecReferenceContent(
838
+ parentReferencePath: string,
839
+ referenceId: string,
840
+ amfId: string,
841
+ type: string,
842
+ elementId: string,
843
+ meta: string
844
+ ): void {
845
+ this.selectedTopic = {
846
+ referenceId,
847
+ parentReferencePath,
848
+ amfId,
849
+ elementId,
850
+ type,
851
+ meta
852
+ };
853
+ this.selectedSidebarValue = this.getReferencePathWithMeta(
854
+ parentReferencePath,
855
+ meta
856
+ );
857
+
858
+ this.handleSelectedItem();
859
+
860
+ this.updateDocPhase();
861
+ }
862
+
863
+ /**
864
+ * Updates doc phase of selected reference
865
+ */
866
+ updateDocPhase(): void {
867
+ /* If parent level doc phase is enabled, Individual reference level doc phase should not be considered */
868
+
869
+ if (!this.isParentLevelDocPhaseEnabled) {
870
+ const selectedReference = this._amfConfigList.find(
871
+ (referenceItem: AmfConfig) => {
872
+ return referenceItem.id === this._currentReferenceId;
873
+ }
874
+ );
875
+ if (selectedReference) {
876
+ this.selectedReferenceDocPhase = JSON.stringify(
877
+ selectedReference.docPhase
878
+ );
879
+ }
880
+ }
881
+ }
882
+
883
+ /**
884
+ * Returns the decoded meta query param from given Url as it is being used internally.
885
+ */
886
+ getMetaFromUrl(referenceUrl: string): string {
887
+ const indexOfQueryParam = referenceUrl.indexOf("?");
888
+ const urlPath = referenceUrl.substring(
889
+ indexOfQueryParam >= 0 ? indexOfQueryParam : referenceUrl.length
890
+ );
891
+ const meta = this.parseParams(urlPath).meta as string;
892
+ // Always get the meta query param encoded and decode it and store it for internal use
893
+ // This has 2 advantages,
894
+ // 1. Supports backward compatible meta query param, so there is no need for redirects.
895
+ // 2. Supports Prerender and Coveo for their crawling.
896
+ const encodedMeta = meta && this.getUrlEncoded(meta);
897
+ const decodedMeta = encodedMeta && decodeURIComponent(encodedMeta);
898
+ return decodedMeta || "";
899
+ }
900
+
901
+ /**
902
+ *
903
+ * @returns meta for given markdown based referenceUrl
904
+ * Consider last topic url in ../references/reference-name/example.html
905
+ */
906
+ getMarkdownReferenceMeta(referenceUrl: string): string {
907
+ let meta = "";
908
+ if (referenceUrl) {
909
+ const slashSeparatorItems = referenceUrl.split("/");
910
+ const lastItem =
911
+ slashSeparatorItems[slashSeparatorItems.length - 1];
912
+ if (lastItem.endsWith(".html")) {
913
+ meta = lastItem;
914
+ }
915
+ }
916
+ return meta;
917
+ }
918
+
919
+ /**
920
+ * Gets the encoded url.
921
+ * This method will return the encoded url for 2 cases,
922
+ * 1. If the url is encoded already
923
+ * 2. If the url is decoded
924
+ */
925
+ getUrlEncoded(url: string) {
926
+ // if url matches, then return the encoded url.
927
+ if (decodeURIComponent(url) === url) {
928
+ return encodeURIComponent(url);
929
+ }
930
+ // return the encoded url.
931
+ return this.getUrlEncoded(decodeURIComponent(url));
932
+ }
933
+
934
+ /**
935
+ *
936
+ * @returns RouteMeta object for given referenceUrl
937
+ * referenceId - gets referenceId from url
938
+ * For spec based references gets meta parm from url and then topicId & type from meta
939
+ * For markdown based references gets topicId as last html path in the name, meta & type will be empty
940
+ */
941
+ getReferenceMetaInfo(referenceUrl: string): RouteMeta | undefined {
942
+ let metaReferenceInfo;
943
+ if (referenceUrl) {
944
+ const referenceId = this.getReferenceIdFromUrl(referenceUrl);
945
+ let meta = "";
946
+ let topicId = "";
947
+ let type = "";
948
+ if (this.isSpecBasedReference(referenceId)) {
949
+ meta = this.getMetaFromUrl(referenceUrl);
950
+ if (meta) {
951
+ if (meta.includes(":")) {
952
+ const metaInfo = meta.split(":");
953
+ type = metaInfo[0];
954
+ topicId = metaInfo[1] || type;
955
+ } else {
956
+ topicId = meta;
957
+ }
958
+ }
959
+ } else {
960
+ topicId = this.getMarkdownReferenceMeta(referenceUrl);
961
+ }
962
+ metaReferenceInfo = {
963
+ referenceId,
964
+ meta,
965
+ topicId,
966
+ type
967
+ };
968
+ }
969
+ return metaReferenceInfo;
970
+ }
971
+
972
+ /**
973
+ * Finds and returns referenceUrl and topicTitle if given topic url matches
974
+ */
975
+ getReferenceDetailsInGivenTopics(
976
+ topics: ParsedMarkdownTopic[],
977
+ topicMeta: string
978
+ ): { referenceUrl: string; topicTitle: string } {
979
+ let referenceUrl = "";
980
+ let topicTitle = "";
981
+ for (let i = 0; i < topics.length; i++) {
982
+ const topic = topics[i];
983
+ const meta = this.getMarkdownReferenceMeta(topic.link.href);
984
+ const childTopics = topic.children;
985
+ if (meta === topicMeta) {
986
+ referenceUrl = topic.link.href;
987
+ topicTitle = topic.label;
988
+ } else if (childTopics && childTopics.length) {
989
+ const referenceDetails = this.getReferenceDetailsInGivenTopics(
990
+ childTopics,
991
+ topicMeta
992
+ );
993
+ referenceUrl = referenceDetails.referenceUrl;
994
+ topicTitle = referenceDetails.topicTitle;
995
+ }
996
+ if (referenceUrl && topicTitle) {
997
+ break;
998
+ }
999
+ }
1000
+ return {
1001
+ referenceUrl,
1002
+ topicTitle
1003
+ };
1004
+ }
1005
+
1006
+ /**
1007
+ * Gives referenceUrl and topicTitle for given markdown topic url
1008
+ */
1009
+ getRefDetailsForGivenTopicMeta(
1010
+ referenceId: string,
1011
+ topicMeta: string
1012
+ ): { referenceUrl: string; topicTitle: string } | undefined {
1013
+ const amfConfig = this.getAmfConfigWithId(referenceId);
1014
+ let referenceDetails;
1015
+ if (amfConfig) {
1016
+ const topics = amfConfig.topic?.children || [];
1017
+ referenceDetails = this.getReferenceDetailsInGivenTopics(
1018
+ topics,
1019
+ topicMeta
1020
+ );
1021
+ }
1022
+ return referenceDetails;
1023
+ }
1024
+
1025
+ /**
1026
+ * Updates the DOM on the first load
1027
+ */
1028
+ updateView(): void {
1029
+ const previousRefUrlInSession = window.sessionStorage.getItem(
1030
+ this.docsReferenceUrlSessionKey
1031
+ );
1032
+ window.sessionStorage.removeItem(this.docsReferenceUrlSessionKey);
1033
+ let previousRefInfo = this.getReferenceMetaInfo(
1034
+ previousRefUrlInSession
1035
+ );
1036
+
1037
+ // For spec based reference, We should consider urlData to show same topic when user reloads after navigating to specific topic
1038
+ if (!previousRefInfo) {
1039
+ const currentUrl = window.location.href;
1040
+ const urlReferenceId = this.getReferenceIdFromUrl(currentUrl);
1041
+ if (urlReferenceId && this.isSpecBasedReference(urlReferenceId)) {
1042
+ if (
1043
+ !this.isProjectRootPath() &&
1044
+ !this.isParentReferencePath(currentUrl)
1045
+ ) {
1046
+ previousRefInfo = this.getReferenceMetaInfo(currentUrl);
1047
+ }
1048
+ }
1049
+ }
1050
+
1051
+ let referenceId: string;
1052
+ let topicId = "";
1053
+
1054
+ if (
1055
+ previousRefInfo &&
1056
+ this._amfConfigMap.has(previousRefInfo.referenceId)
1057
+ ) {
1058
+ referenceId = previousRefInfo.referenceId;
1059
+ topicId = previousRefInfo.topicId;
1060
+ } else {
1061
+ referenceId = this._currentReferenceId;
1062
+ }
1063
+
1064
+ const specBasedReference = this.isSpecBasedReference(referenceId);
1065
+ if (specBasedReference) {
1066
+ // Wait till the AMF is loaded.
1067
+ this.amfFetchPromiseMap[referenceId].then(() => {
1068
+ let selectedItemMetaData = this.getMetadataByIdentifier(
1069
+ referenceId,
1070
+ topicId
1071
+ );
1072
+ if (!selectedItemMetaData) {
1073
+ // Doesn't exist, let's use the summary.
1074
+ selectedItemMetaData = this.getMetadataByType(
1075
+ referenceId,
1076
+ "summary"
1077
+ );
1078
+ }
1079
+
1080
+ if (selectedItemMetaData) {
1081
+ this.loadSpecReferenceContent(
1082
+ selectedItemMetaData.parentReferencePath,
1083
+ selectedItemMetaData.referenceId,
1084
+ selectedItemMetaData.amfId,
1085
+ selectedItemMetaData.type,
1086
+ "",
1087
+ selectedItemMetaData.meta
1088
+ );
1089
+ this.updateUrlWithSelected(
1090
+ selectedItemMetaData.parentReferencePath,
1091
+ selectedItemMetaData.meta
1092
+ );
1093
+ this.updateNavTitleMetaTag(selectedItemMetaData.navTitle);
1094
+ }
1095
+ });
1096
+ } else {
1097
+ let invalidTopicReferenceUrl = "";
1098
+ if (topicId) {
1099
+ const referenceDetails = this.getRefDetailsForGivenTopicMeta(
1100
+ referenceId,
1101
+ topicId
1102
+ );
1103
+ const selectedItemUrl = referenceDetails?.referenceUrl;
1104
+ if (!selectedItemUrl) {
1105
+ invalidTopicReferenceUrl = previousRefUrlInSession;
1106
+ }
1107
+ }
1108
+ this.loadMarkdownBasedReference(invalidTopicReferenceUrl);
1109
+ }
1110
+ }
1111
+
1112
+ /**
1113
+ * Navigates to reference of the given URL
1114
+ * @param url
1115
+ */
1116
+ private loadNewReferenceItem(url: string): void {
1117
+ const referenceId = this.getReferenceIdFromUrl(url);
1118
+ const referenceItem = this.getAmfConfigWithId(referenceId);
1119
+ if (referenceItem) {
1120
+ window.location.href = referenceItem.href;
1121
+ }
1122
+ }
1123
+
1124
+ /**
1125
+ * @param referenceUrl to which user wants to navigate
1126
+ * Redirect to first sub item if it's root level item, otherwise content will be loaded
1127
+ * Push the history as a first child item
1128
+ * set selected sidebar value as a pathname
1129
+ */
1130
+
1131
+ private loadMarkdownBasedReference(referenceUrl?: string): void {
1132
+ let referenceId = "";
1133
+ const currentUrl = window.location.href;
1134
+ if (this.isProjectRootPath()) {
1135
+ /**
1136
+ * CASE1: This case is to consider when the user navigates to references by clicking a project card
1137
+ * Ex: /docs/example-project/references should navigate to the first topic in the first reference
1138
+ */
1139
+ referenceId = this._currentReferenceId;
1140
+ } else if (this.isParentReferencePath(referenceUrl)) {
1141
+ /**
1142
+ * CASE2: This case is to navigate to respective reference when the user clicked on root item
1143
+ * Ex: .../references/markdown-ref should navigate to first topic.
1144
+ */
1145
+ referenceId = this.getReferenceIdFromUrl(referenceUrl);
1146
+ } else if (this.isParentReferencePath(currentUrl)) {
1147
+ /**
1148
+ * CASE3: This case is to navigate to respective reference when the user entered url with reference id
1149
+ * Ex: .../references/markdown-ref should navigate to first topic.
1150
+ */
1151
+ referenceId = this.getReferenceIdFromUrl(currentUrl);
1152
+ } else if (referenceUrl) {
1153
+ /**
1154
+ * CASE4: This case is to navigate to first item when we don't have topic in the selected version
1155
+ * Ex: .../references/markdown-ref/not-existed-topic-url should navigate to first topic.
1156
+ */
1157
+ const referenceMeta = this.getMarkdownReferenceMeta(referenceUrl);
1158
+ const selectedItemRefId = this.getReferenceIdFromUrl(referenceUrl);
1159
+ const referenceDetails = this.getRefDetailsForGivenTopicMeta(
1160
+ selectedItemRefId,
1161
+ referenceMeta
1162
+ );
1163
+ const selectedItemUrl = referenceDetails?.referenceUrl;
1164
+ if (!selectedItemUrl) {
1165
+ referenceId = this.getReferenceIdFromUrl(referenceUrl);
1166
+ }
1167
+ }
1168
+
1169
+ let isRedirecting = false;
1170
+ if (referenceId) {
1171
+ const amfConfig = this.getAmfConfigWithId(referenceId);
1172
+ let redirectReferenceUrl = "";
1173
+ if (amfConfig) {
1174
+ const childrenItems = amfConfig.topic.children;
1175
+ if (childrenItems.length > 0) {
1176
+ redirectReferenceUrl = childrenItems[0].link.href;
1177
+ }
1178
+ }
1179
+ if (redirectReferenceUrl) {
1180
+ if (this.isParentReferencePath(referenceUrl)) {
1181
+ // This is for CASE2 mentioned above, Where we need to navigate user to respective href
1182
+ isRedirecting = true;
1183
+ window.location.href = redirectReferenceUrl;
1184
+ } else {
1185
+ // This is for CASE 1,3 and 4 mentioned above, Where we need to update the browser history
1186
+ window.history.replaceState({}, "", redirectReferenceUrl);
1187
+ }
1188
+ }
1189
+ }
1190
+ if (!isRedirecting) {
1191
+ const currentReferenceUrl = window.location.href;
1192
+ const referenceMeta =
1193
+ this.getMarkdownReferenceMeta(currentReferenceUrl);
1194
+ const selectedItemRefId =
1195
+ this.getReferenceIdFromUrl(currentReferenceUrl);
1196
+ const referenceDetails = this.getRefDetailsForGivenTopicMeta(
1197
+ selectedItemRefId,
1198
+ referenceMeta
1199
+ );
1200
+ if (referenceDetails) {
1201
+ this.updateNavTitleMetaTag(referenceDetails.topicTitle);
1202
+ }
1203
+
1204
+ this.versions = this.getVersions();
1205
+ this.updateDocPhase();
1206
+ this.selectedSidebarValue = window.location.pathname;
1207
+ }
1208
+ }
1209
+
1210
+ /**
1211
+ * Currently, used to handle the version change and store the current reference Url.
1212
+ */
1213
+ handleVersionChange(): void {
1214
+ const currentUrl = window.location.href;
1215
+ window.sessionStorage.setItem(
1216
+ this.docsReferenceUrlSessionKey,
1217
+ currentUrl
1218
+ );
1219
+ }
1220
+
1221
+ private updateNavTitleMetaTag(navTitle = ""): void {
1222
+ // this is required to update the nav title meta tag.
1223
+ // eslint-disable-next-line @lwc/lwc/no-document-query
1224
+ const metaNavTitle = document.querySelector('meta[name="nav-title"]');
1225
+ if (metaNavTitle && navTitle) {
1226
+ metaNavTitle.setAttribute("content", navTitle);
1227
+ }
1228
+ }
1229
+
1230
+ onNavSelect(event: CustomEvent): void {
1231
+ const name = event.detail.name;
1232
+ if (name) {
1233
+ const urlReferenceId = this.getReferenceIdFromUrl(name);
1234
+ const specBasedReference =
1235
+ this.isSpecBasedReference(urlReferenceId);
1236
+ if (specBasedReference) {
1237
+ const metaVal = this.getMetaFromUrl(name);
1238
+ const currentSelectedMeta = this.selectedTopic
1239
+ ? this.selectedTopic.meta
1240
+ : "";
1241
+
1242
+ if (metaVal && metaVal === currentSelectedMeta) {
1243
+ // selecting the same nav item, skip update
1244
+ return;
1245
+ }
1246
+
1247
+ const metadata = this.metadata[metaVal];
1248
+ if (metadata) {
1249
+ const {
1250
+ parentReferencePath,
1251
+ referenceId,
1252
+ amfId,
1253
+ type,
1254
+ elementId
1255
+ } = metadata;
1256
+ this.loadSpecReferenceContent(
1257
+ parentReferencePath,
1258
+ referenceId,
1259
+ amfId,
1260
+ type,
1261
+ elementId,
1262
+ metaVal
1263
+ );
1264
+ this.updateUrlWithSelected(parentReferencePath, metaVal);
1265
+ this.updateNavTitleMetaTag(metadata.navTitle);
1266
+ } else {
1267
+ if (this.isParentReferencePath(name)) {
1268
+ this.loadNewReferenceItem(name);
1269
+ }
1270
+ }
1271
+ } else {
1272
+ this.loadMarkdownBasedReference(name);
1273
+ }
1274
+ }
1275
+ }
1276
+
1277
+ onExpandCollapse(event: CustomEvent): void {
1278
+ const { name, isSelectAction, isExpanded } = event.detail;
1279
+ if (!isSelectAction && isExpanded) {
1280
+ const referenceId = this.getReferenceIdFromUrl(name);
1281
+ const currentUrl = window.location.href;
1282
+ const currentReferenceId = this.getReferenceIdFromUrl(currentUrl);
1283
+ //No need to do anything if user is expanding currently selected reference
1284
+ if (referenceId !== currentReferenceId) {
1285
+ const isSpecBasedReference =
1286
+ this.isSpecBasedReference(referenceId);
1287
+ if (isSpecBasedReference) {
1288
+ // Perform functionality same as item selection
1289
+ this.onNavSelect(event);
1290
+ }
1291
+ }
1292
+ }
1293
+ }
1294
+
1295
+ handleSelectedItem(): void {
1296
+ // update topic view
1297
+ const { referenceId, amfId, type } = this.selectedTopic;
1298
+
1299
+ // This updates the component in the content section.
1300
+ this.topicModel = {
1301
+ type,
1302
+ amf: this.amfMap[referenceId].model,
1303
+ parser: this.amfMap[referenceId].parser,
1304
+ id: amfId
1305
+ };
1306
+
1307
+ window.scrollTo({ top: 0, behavior: "smooth" });
1308
+ }
1309
+ }