@salesforcedevs/dx-components 1.40.7-bug-fix-alpha → 1.40.7-scroll-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.
Files changed (28) hide show
  1. package/lwc.config.json +2 -3
  2. package/package.json +3 -2
  3. package/src/modules/dx/button/button.css +2 -2
  4. package/src/modules/dx/codeBlock/codeBlock.ts +6 -0
  5. package/src/modules/dx/dropdown/dropdown.css +1 -29
  6. package/src/modules/dx/dropdown/dropdown.html +1 -1
  7. package/src/modules/dx/dropdown/dropdown.ts +1 -16
  8. package/src/modules/dx/dropdownOption/dropdownOption.css +6 -29
  9. package/src/modules/dx/popover/popover.ts +7 -119
  10. package/src/modules/dx/sidebar/sidebar.html +0 -1
  11. package/src/modules/dx/sidebarOld/sidebarOld.html +0 -1
  12. package/src/modules/dx/tree/tree.html +0 -1
  13. package/src/modules/dx/tree/tree.ts +1 -5
  14. package/src/modules/dx/tree/treeHandler.ts +13 -92
  15. package/src/modules/dx/treeItem/treeItem.css +0 -38
  16. package/src/modules/dx/treeItem/treeItem.html +2 -17
  17. package/src/modules/dx/treeItem/treeItem.ts +11 -109
  18. package/src/modules/dx/treeTile/treeTile.css +0 -57
  19. package/src/modules/dx/treeTile/treeTile.ts +3 -12
  20. package/src/modules/dx/typeBadge/typeBadge.ts +2 -23
  21. package/src/modules/dxBaseElements/headerBase/headerBase.ts +6 -1
  22. package/src/modules/dxHelpers/commonSidebar/commonSidebar.css +3 -3
  23. package/src/modules/dxHelpers/commonTreeItem/commonTreeItem.css +0 -4
  24. package/src/modules/dxHelpers/typeBadge/typeBadge.css +0 -22
  25. package/src/modules/dx/versionPicker/versionPicker.css +0 -248
  26. package/src/modules/dx/versionPicker/versionPicker.html +0 -73
  27. package/src/modules/dx/versionPicker/versionPicker.ts +0 -157
  28. package/src/modules/dxUtils/topicVersion/topicVersion.ts +0 -525
@@ -1,525 +0,0 @@
1
- export const TOPIC_VERSION_SESSION_KEY = "sfdocs-topic-version-selections";
2
- export const DOCS_PATH_SEGMENT = "docs";
3
- // Locale position in the path segments: `/docs/<locale>` for Docs,
4
- // `/docs/<brand>/<locale>` for Guides/References.
5
- export const DOCS_LOCALE_SEGMENT_INDEX = 1;
6
- export const REFERENCES_LOCALE_SEGMENT_INDEX = 2;
7
-
8
- export type TopicVersionOption = {
9
- id: string;
10
- label: string;
11
- deprecated?: boolean;
12
- selected?: boolean;
13
- link?: {
14
- href?: string;
15
- target?: string;
16
- };
17
- /** Topics authored under this version. Absent when the client only rewrites hrefs. */
18
- // VersionedNode also points back here through `versions`.
19
- // eslint-disable-next-line no-use-before-define
20
- children?: VersionedNode[];
21
- };
22
-
23
- export type VersionedNode = {
24
- name?: string;
25
- label?: string;
26
- key?: string;
27
- link?: {
28
- href?: string;
29
- target?: string;
30
- };
31
- children?: VersionedNode[];
32
- versions?: TopicVersionOption[];
33
- /** Set on Redoc spec tiles after the docs layout decorates the TOC. */
34
- showForwardArrow?: boolean;
35
- /** Docs TOC topic type (`markdown` | `spec`). May be stripped after decoration. */
36
- topicType?: string;
37
- };
38
-
39
- type VersionPathDelta = {
40
- prefix: string;
41
- inserted: string;
42
- };
43
-
44
- function isBrowser(): boolean {
45
- return typeof window !== "undefined";
46
- }
47
-
48
- export function normalizePath(href?: string): string {
49
- if (!href) {
50
- return "";
51
- }
52
-
53
- try {
54
- const url = href.startsWith("http")
55
- ? new URL(href)
56
- : new URL(
57
- href,
58
- isBrowser() ? window.location.origin : "http://localhost"
59
- );
60
- return url.pathname.replace(/\/$/, "") || "/";
61
- } catch {
62
- return href.replace(/\/$/, "");
63
- }
64
- }
65
-
66
- export function hrefMatchesCurrentPage(href?: string): boolean {
67
- if (!isBrowser()) {
68
- return false;
69
- }
70
- return normalizePath(href) === normalizePath(window.location.pathname);
71
- }
72
-
73
- export function readTopicVersionSelections(): Record<string, string> {
74
- if (!isBrowser() || !window.sessionStorage) {
75
- return {};
76
- }
77
-
78
- try {
79
- const raw = window.sessionStorage.getItem(TOPIC_VERSION_SESSION_KEY);
80
- return raw ? JSON.parse(raw) : {};
81
- } catch {
82
- return {};
83
- }
84
- }
85
-
86
- export function persistTopicVersion(
87
- topicName: string,
88
- versionId: string
89
- ): void {
90
- if (!topicName || !versionId || !isBrowser() || !window.sessionStorage) {
91
- return;
92
- }
93
-
94
- const stored = readTopicVersionSelections();
95
- stored[topicName] = versionId;
96
- window.sessionStorage.setItem(
97
- TOPIC_VERSION_SESSION_KEY,
98
- JSON.stringify(stored)
99
- );
100
- }
101
-
102
- /**
103
- * Normalizes the path, then removes `locale` when it sits in the docs or
104
- * references locale position, so every locale shares one session key.
105
- */
106
- function stripLocaleFromPath(path: string, locale?: string): string {
107
- const normalized = normalizePath(path);
108
- const segments = normalized.split("/").filter(Boolean);
109
- const normalizedLocale = locale?.toLowerCase();
110
- if (!normalizedLocale || segments[0] !== DOCS_PATH_SEGMENT) {
111
- return normalized;
112
- }
113
-
114
- const localeIndex = [
115
- DOCS_LOCALE_SEGMENT_INDEX,
116
- REFERENCES_LOCALE_SEGMENT_INDEX
117
- ].find((index) => segments[index]?.toLowerCase() === normalizedLocale);
118
- if (localeIndex === undefined) {
119
- return normalized;
120
- }
121
-
122
- segments.splice(localeIndex, 1);
123
- return `/${segments.join("/")}`;
124
- }
125
-
126
- /**
127
- * Stable session key for a versioned topic. Parent-only sections have an empty
128
- * `name`/`href`, so fall back to the latest switching URL (then the label).
129
- * The locale is stripped so a selection carries across locales.
130
- */
131
- export function getTopicVersionKey(
132
- node: VersionedNode | undefined,
133
- locale?: string
134
- ): string {
135
- if (!node) {
136
- return "";
137
- }
138
- if (node.name) {
139
- return stripLocaleFromPath(node.name, locale);
140
- }
141
- const latestHref = node.versions?.[0]?.link?.href;
142
- if (latestHref) {
143
- return stripLocaleFromPath(latestHref, locale);
144
- }
145
- return node.label || "";
146
- }
147
-
148
- /** Section header with children but no page of its own. */
149
- export function isParentOnlyTopic(node: VersionedNode | undefined): boolean {
150
- if (!node) {
151
- return false;
152
- }
153
- const ownHref = node.link?.href || node.name;
154
- return !ownHref && !!node.children?.length;
155
- }
156
-
157
- function isSpecNode(node: VersionedNode): boolean {
158
- return node.showForwardArrow === true || node.topicType === "spec";
159
- }
160
-
161
- /**
162
- * First descendant that has a markdown page (own href/name). Specs (Redoc)
163
- * and external links are skipped so parent-only sections land on the first
164
- * markdown topic even when a spec is authored first in the TOC.
165
- */
166
- export function firstContentNode(
167
- node: VersionedNode | undefined
168
- ): VersionedNode | undefined {
169
- if (!node || node.link?.target === "_blank" || isSpecNode(node)) {
170
- return undefined;
171
- }
172
- if (node.link?.href || node.name) {
173
- return node;
174
- }
175
- for (const child of node.children || []) {
176
- const found = firstContentNode(child);
177
- if (found) {
178
- return found;
179
- }
180
- }
181
- return undefined;
182
- }
183
-
184
- export function shouldShowTopicVersionPicker(
185
- versions?: TopicVersionOption[],
186
- showForwardArrow?: boolean
187
- ): boolean {
188
- return !showForwardArrow && Array.isArray(versions) && versions.length > 1;
189
- }
190
-
191
- /**
192
- * Difference between a picker's latest switching URL and an older one.
193
- *
194
- * latest: /docs/project/errors.html
195
- * v1: /docs/project/v1/errors.html
196
- * → prefix `/docs/project/`, inserted `v1/`
197
- */
198
- function getVersionPathDelta(
199
- latestPath: string,
200
- selectedPath: string
201
- ): VersionPathDelta | undefined {
202
- const latestDirEnd = latestPath.lastIndexOf("/") + 1;
203
- if (latestDirEnd <= 0) {
204
- return undefined;
205
- }
206
-
207
- const prefix = latestPath.slice(0, latestDirEnd);
208
- const latestSlug = latestPath.slice(latestDirEnd);
209
- if (!selectedPath.startsWith(prefix) || !latestSlug) {
210
- return undefined;
211
- }
212
-
213
- const selectedAfterPrefix = selectedPath.slice(prefix.length);
214
- if (!selectedAfterPrefix.endsWith(latestSlug)) {
215
- return undefined;
216
- }
217
-
218
- const inserted = selectedAfterPrefix.slice(
219
- 0,
220
- selectedAfterPrefix.length - latestSlug.length
221
- );
222
- if (!inserted) {
223
- return undefined;
224
- }
225
-
226
- return { prefix, inserted };
227
- }
228
-
229
- function applyVersionPathDelta(
230
- hrefPath: string,
231
- delta: VersionPathDelta
232
- ): string | undefined {
233
- if (!hrefPath.startsWith(delta.prefix)) {
234
- return undefined;
235
- }
236
-
237
- const rest = hrefPath.slice(delta.prefix.length);
238
- if (rest.startsWith(delta.inserted)) {
239
- return hrefPath;
240
- }
241
-
242
- return delta.prefix + delta.inserted + rest;
243
- }
244
-
245
- function stripVersionPathDelta(
246
- hrefPath: string,
247
- delta: VersionPathDelta
248
- ): string | undefined {
249
- if (!hrefPath.startsWith(delta.prefix)) {
250
- return undefined;
251
- }
252
-
253
- const rest = hrefPath.slice(delta.prefix.length);
254
- if (!rest.startsWith(delta.inserted)) {
255
- return undefined;
256
- }
257
-
258
- return delta.prefix + rest.slice(delta.inserted.length);
259
- }
260
-
261
- /**
262
- * Maps a canonical (latest) href onto another version using the picker's
263
- * latest vs selected switching URLs as the template.
264
- *
265
- * latest parent: /docs/project/errors.html
266
- * v1 parent: /docs/project/v1/errors.html
267
- * latest child: /docs/project/extra-child-a.html
268
- * → v1 child: /docs/project/v1/extra-child-a.html
269
- */
270
- export function applyVersionToHref(
271
- canonicalHref: string | undefined,
272
- selectedVersion: TopicVersionOption | undefined,
273
- versions?: TopicVersionOption[]
274
- ): string | undefined {
275
- if (!canonicalHref) {
276
- return canonicalHref;
277
- }
278
- if (!selectedVersion || !versions?.length) {
279
- return canonicalHref;
280
- }
281
-
282
- const latest = versions[0];
283
- if (!latest || selectedVersion.id === latest.id) {
284
- return canonicalHref;
285
- }
286
-
287
- const latestPath = normalizePath(latest.link?.href);
288
- const selectedPath = normalizePath(selectedVersion.link?.href);
289
- const hrefPath = normalizePath(canonicalHref);
290
-
291
- if (!latestPath || !selectedPath || latestPath === selectedPath) {
292
- return insertVersionBeforeSlug(canonicalHref, selectedVersion.id);
293
- }
294
-
295
- const delta = getVersionPathDelta(latestPath, selectedPath);
296
- return (
297
- (delta && applyVersionPathDelta(hrefPath, delta)) ||
298
- insertVersionBeforeSlug(canonicalHref, selectedVersion.id)
299
- );
300
- }
301
-
302
- function insertVersionBeforeSlug(href: string, versionId: string): string {
303
- const path = normalizePath(href);
304
- const lastSlash = path.lastIndexOf("/");
305
- if (lastSlash <= 0 || !versionId) {
306
- return href;
307
- }
308
- const dir = path.slice(0, lastSlash);
309
- const slug = path.slice(lastSlash);
310
- if (dir.endsWith(`/${versionId}`)) {
311
- return path;
312
- }
313
- return `${dir}/${versionId}${slug}`;
314
- }
315
-
316
- export function toCanonicalHref(
317
- href: string | undefined,
318
- versions?: TopicVersionOption[]
319
- ): string {
320
- if (!href) {
321
- return "";
322
- }
323
- if (!versions?.length) {
324
- return normalizePath(href);
325
- }
326
-
327
- const latestPath = normalizePath(versions[0].link?.href);
328
- const hrefPath = normalizePath(href);
329
- if (!latestPath) {
330
- return hrefPath;
331
- }
332
-
333
- for (const version of versions) {
334
- // The latest is also served under `/<latestId>/`, so that form is
335
- // stripped too.
336
- const versionedPath =
337
- version.id === versions[0].id
338
- ? insertVersionBeforeSlug(latestPath, version.id)
339
- : normalizePath(version.link?.href);
340
- const delta = getVersionPathDelta(latestPath, versionedPath);
341
- const stripped = delta && stripVersionPathDelta(hrefPath, delta);
342
- if (stripped) {
343
- return stripped;
344
- }
345
- }
346
-
347
- return hrefPath;
348
- }
349
-
350
- function hrefMatchesVersion(
351
- href: string | undefined,
352
- version: TopicVersionOption,
353
- versions: TopicVersionOption[]
354
- ): boolean {
355
- if (hrefMatchesCurrentPage(applyVersionToHref(href, version, versions))) {
356
- return true;
357
- }
358
- // The server serves the latest under its canonical URL and also under
359
- // `/<latestId>/`, so the versioned form must select the latest too.
360
- return (
361
- !!href &&
362
- version.id === versions[0]?.id &&
363
- hrefMatchesCurrentPage(insertVersionBeforeSlug(href, version.id))
364
- );
365
- }
366
-
367
- export function collectSubtreeCanonicalHrefs(
368
- node: VersionedNode,
369
- includeSelf = true
370
- ): string[] {
371
- const hrefs: string[] = [];
372
- const own = node.link?.href || node.name;
373
- if (includeSelf && own) {
374
- hrefs.push(own);
375
- }
376
- const collectChildHrefs = (children?: VersionedNode[]) => {
377
- for (const child of children || []) {
378
- if (child.versions?.length || child.link?.target === "_blank") {
379
- continue;
380
- }
381
- hrefs.push(...collectSubtreeCanonicalHrefs(child));
382
- }
383
- };
384
- collectChildHrefs(node.children);
385
- // Topics that exist only on an older version are not in `children`.
386
- for (const version of node.versions || []) {
387
- collectChildHrefs(version.children);
388
- }
389
- return hrefs;
390
- }
391
-
392
- export function isCurrentPageInSubtree(
393
- node: VersionedNode,
394
- versions?: TopicVersionOption[]
395
- ): boolean {
396
- if (!isBrowser() || !versions?.length) {
397
- return false;
398
- }
399
-
400
- return collectSubtreeCanonicalHrefs(node).some((href) =>
401
- versions.some((version) => hrefMatchesVersion(href, version, versions))
402
- );
403
- }
404
-
405
- /**
406
- * Picker option hrefs. When the current page is this topic or a descendant,
407
- * each option points at that same topic in the chosen version so the child
408
- * stays selected. Otherwise keep the backend switching URL (parent page, or
409
- * first content child for parent-only sections).
410
- */
411
- export function getVersionPickerOptions(
412
- node: VersionedNode | undefined
413
- ): TopicVersionOption[] | undefined {
414
- const versions = node?.versions;
415
- if (!node || !versions?.length) {
416
- return versions;
417
- }
418
- if (!isCurrentPageInSubtree(node, versions)) {
419
- return versions;
420
- }
421
-
422
- const canonical = toCanonicalHref(window.location.pathname, versions);
423
- return versions.map((version) => ({
424
- ...version,
425
- link: {
426
- ...version.link,
427
- href:
428
- applyVersionToHref(canonical, version, versions) ||
429
- version.link?.href
430
- }
431
- }));
432
- }
433
-
434
- /**
435
- * Version whose page (or a descendant of it) is the current URL.
436
- * Ignores the session-stored picker selection, which can remember an older
437
- * version while the reader is still on the latest page.
438
- */
439
- export function versionForCurrentPage(
440
- node: VersionedNode | undefined
441
- ): TopicVersionOption | undefined {
442
- const versions = node?.versions;
443
- if (!node || !versions?.length || !isBrowser()) {
444
- return undefined;
445
- }
446
-
447
- const hrefs = collectSubtreeCanonicalHrefs(node);
448
- const matches = (version: TopicVersionOption) =>
449
- hrefMatchesCurrentPage(version.link?.href) ||
450
- hrefs.some((href) => hrefMatchesVersion(href, version, versions));
451
-
452
- // Older versions first so a rewritten child URL is not mistaken for latest.
453
- const older = versions.find(
454
- (version) => version.id !== versions[0].id && matches(version)
455
- );
456
- if (older) {
457
- return older;
458
- }
459
-
460
- return matches(versions[0]) ? versions[0] : undefined;
461
- }
462
-
463
- /**
464
- * Deepest versioned topic that contains the current page, with the version
465
- * the URL selects. Nested versioned topics own their pages.
466
- */
467
- export function findTopicVersionForCurrentPage(
468
- nodes: VersionedNode[] | undefined | null
469
- ): { node: VersionedNode; version: TopicVersionOption } | undefined {
470
- let match: { node: VersionedNode; version: TopicVersionOption } | undefined;
471
- const walk = (list?: VersionedNode[] | null) => {
472
- for (const node of list || []) {
473
- const version = versionForCurrentPage(node);
474
- if (version) {
475
- match = { node, version };
476
- }
477
- walk(node.children);
478
- for (const versionOption of node.versions || []) {
479
- walk(versionOption.children);
480
- }
481
- }
482
- };
483
- walk(nodes);
484
- return match;
485
- }
486
-
487
- /**
488
- * Current page rewritten onto the latest topic version. Falls back to the
489
- * latest switching URL when the path delta cannot be applied.
490
- */
491
- export function latestHrefForCurrentPage(
492
- versions: TopicVersionOption[] | undefined
493
- ): string | undefined {
494
- const latest = versions?.[0];
495
- if (!latest) {
496
- return undefined;
497
- }
498
- if (!isBrowser()) {
499
- return latest.link?.href;
500
- }
501
-
502
- const canonical = toCanonicalHref(window.location.pathname, versions);
503
- return applyVersionToHref(canonical, latest, versions) || latest.link?.href;
504
- }
505
-
506
- export function resolveSelectedVersion(
507
- node: VersionedNode | undefined,
508
- locale?: string
509
- ): TopicVersionOption | undefined {
510
- const versions = node?.versions;
511
- if (!node || !versions?.length) {
512
- return undefined;
513
- }
514
-
515
- // The open page wins, including a canonical child opened from "View Latest".
516
- // Session is only for a picker whose topic is not the current page.
517
- const fromUrl = versionForCurrentPage(node);
518
- if (fromUrl) {
519
- return fromUrl;
520
- }
521
-
522
- const storedId =
523
- readTopicVersionSelections()[getTopicVersionKey(node, locale)];
524
- return versions.find((version) => version.id === storedId) || versions[0];
525
- }