@salesforcedevs/dx-components 1.40.7-tlv-alpha → 1.40.8

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