@salesforcedevs/docs-components 0.3.12 → 0.3.14-banner-alpha1
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/lwc.config.json +12 -3
- package/package.json +17 -7
- package/src/modules/README.md +41 -0
- package/src/modules/doc/amfReference/amfReference.css +5 -0
- package/src/modules/doc/amfReference/amfReference.html +47 -0
- package/src/modules/doc/amfReference/amfReference.ts +1361 -0
- package/src/modules/doc/amfReference/constants.ts +76 -0
- package/src/modules/doc/amfReference/types.ts +133 -0
- package/src/modules/doc/amfReference/utils.ts +669 -0
- package/src/modules/doc/amfTopic/amfTopic.css +1 -0
- package/src/modules/doc/amfTopic/amfTopic.html +3 -0
- package/src/modules/doc/amfTopic/amfTopic.ts +94 -0
- package/src/modules/doc/amfTopic/types.ts +54 -0
- package/src/modules/doc/amfTopic/utils.ts +130 -0
- package/src/modules/doc/breadcrumbItem/breadcrumbItem.css +51 -0
- package/src/modules/doc/breadcrumbItem/breadcrumbItem.html +5 -0
- package/src/modules/doc/breadcrumbItem/breadcrumbItem.ts +64 -0
- package/src/modules/doc/breadcrumbs/breadcrumbs.css +27 -0
- package/src/modules/doc/breadcrumbs/breadcrumbs.html +60 -0
- package/src/modules/doc/breadcrumbs/breadcrumbs.ts +187 -0
- package/src/modules/doc/content/content.css +58 -103
- package/src/modules/doc/content/content.ts +261 -174
- package/src/modules/doc/contentCallout/contentCallout.css +7 -24
- package/src/modules/doc/contentCallout/contentCallout.html +4 -2
- package/src/modules/doc/contentCallout/contentCallout.ts +8 -2
- package/src/modules/doc/contentLayout/contentLayout.css +98 -0
- package/src/modules/doc/contentLayout/contentLayout.html +51 -0
- package/src/modules/doc/contentLayout/contentLayout.ts +322 -0
- package/src/modules/doc/header/header.css +103 -0
- package/src/modules/doc/header/header.html +160 -0
- package/src/modules/doc/header/header.ts +146 -0
- package/src/modules/doc/heading/heading.css +54 -0
- package/src/modules/doc/heading/heading.html +14 -0
- package/src/modules/doc/heading/heading.ts +65 -0
- package/src/modules/doc/headingAnchor/headingAnchor.css +33 -0
- package/src/modules/doc/headingAnchor/headingAnchor.html +19 -0
- package/src/modules/doc/headingAnchor/headingAnchor.ts +43 -0
- package/src/modules/doc/headingContent/headingContent.css +53 -0
- package/src/modules/doc/headingContent/headingContent.html +13 -0
- package/src/modules/doc/headingContent/headingContent.ts +30 -0
- package/src/modules/doc/phase/phase.css +55 -0
- package/src/modules/doc/phase/phase.html +28 -0
- package/src/modules/doc/phase/phase.ts +57 -0
- package/src/modules/doc/sprigSurvey/sprigSurvey.html +20 -0
- package/src/modules/doc/sprigSurvey/sprigSurvey.scoped.css +12 -0
- package/src/modules/doc/sprigSurvey/sprigSurvey.ts +16 -0
- package/src/modules/doc/toc/toc.html +3 -1
- package/src/modules/doc/toolbar/toolbar.ts +6 -6
- package/src/modules/doc/xmlContent/types.ts +114 -0
- package/src/modules/doc/xmlContent/utils.ts +161 -0
- package/src/modules/doc/xmlContent/xmlContent.css +32 -0
- package/src/modules/doc/xmlContent/xmlContent.html +40 -0
- package/src/modules/doc/xmlContent/xmlContent.ts +677 -0
- package/src/modules/docBaseElements/lightningElementWithState/lightningElementWithState.ts +93 -0
- package/src/modules/docHelpers/amfStyle/amfStyle.css +355 -0
- package/src/modules/docHelpers/phaseContentLayout/phaseContentLayout.css +39 -0
- package/src/modules/docHelpers/status/status.css +22 -0
- package/src/modules/docUtils/SearchSyncer/SearchSyncer.ts +85 -0
- package/LICENSE +0 -12
- package/src/modules/doc/container/__benchmarks__/container.benchmark.js +0 -43
- package/src/modules/doc/container/__mocks__/mockAvailableLanguages.js +0 -8
- package/src/modules/doc/container/__mocks__/mockAvailableVersions.js +0 -122
- package/src/modules/doc/container/__mocks__/mockContentFetchResponse.json +0 -5
- package/src/modules/doc/container/__mocks__/mockDocContent.js +0 -29
- package/src/modules/doc/container/__mocks__/mockNavigationFetchResponse.json +0 -4061
- package/src/modules/doc/container/__mocks__/mockPageReference.js +0 -8
- package/src/modules/doc/container/__mocks__/mockPdfUrl.js +0 -1
- package/src/modules/doc/container/__mocks__/mockSelectedLanguage.js +0 -8
- package/src/modules/doc/container/__mocks__/mockSelectedVersion.js +0 -8
- package/src/modules/doc/container/__mocks__/mockToc.js +0 -146
- package/src/modules/doc/container/__tests__/container.test.ts +0 -117
- package/src/modules/doc/container/container.css +0 -37
- package/src/modules/doc/container/container.html +0 -28
- package/src/modules/doc/container/container.stories.ts +0 -44
- package/src/modules/doc/container/container.ts +0 -367
- package/src/modules/doc/content/__tests__/content.test.ts +0 -99
- package/src/modules/doc/content/__tests__/mockDocContent.ts +0 -258
- package/src/modules/doc/content/__tests__/mockPageReference.ts +0 -8
- package/src/modules/doc/content/content.stories.ts +0 -82
- package/src/modules/doc/contentCallout/__tests__/contentCallout.test.ts +0 -80
- package/src/modules/doc/contentCallout/__tests__/mockProps.ts +0 -14
- package/src/modules/doc/contentCallout/contentCallout.stories.ts +0 -29
- package/src/modules/doc/contentMedia/__tests__/contentMedia.test.ts +0 -97
- package/src/modules/doc/contentMedia/contentMedia.stories.ts +0 -113
- package/src/modules/doc/landing/__tests__/landing.test.ts +0 -60
- package/src/modules/doc/landing/__tests__/mockFetch.json +0 -370
- package/src/modules/doc/landing/landing.css +0 -63
- package/src/modules/doc/landing/landing.html +0 -122
- package/src/modules/doc/landing/landing.stories.ts +0 -21
- package/src/modules/doc/landing/landing.ts +0 -222
- package/src/modules/doc/nav/__tests__/mockAvailableLanguages.ts +0 -8
- package/src/modules/doc/nav/__tests__/mockAvailableVersions.ts +0 -122
- package/src/modules/doc/nav/__tests__/mockPageReference.ts +0 -8
- package/src/modules/doc/nav/__tests__/mockPdfUrl.ts +0 -1
- package/src/modules/doc/nav/__tests__/mockSelectedLanguage.ts +0 -8
- package/src/modules/doc/nav/__tests__/mockSelectedVersion.ts +0 -8
- package/src/modules/doc/nav/__tests__/mockToc.ts +0 -146
- package/src/modules/doc/nav/__tests__/nav.test.ts +0 -58
- package/src/modules/doc/toc/__tests__/mockPageReference.ts +0 -8
- package/src/modules/doc/toc/__tests__/mockToc.ts +0 -146
- package/src/modules/doc/toc/__tests__/toc.test.ts +0 -29
- package/src/modules/doc/toolbar/__tests__/mockAvailableLanguages.ts +0 -8
- package/src/modules/doc/toolbar/__tests__/mockAvailableVersions.ts +0 -122
- package/src/modules/doc/toolbar/__tests__/mockPdfUrl.ts +0 -1
- package/src/modules/doc/toolbar/__tests__/mockSelectedLanguage.ts +0 -8
- package/src/modules/doc/toolbar/__tests__/mockSelectedVersion.ts +0 -8
- package/src/modules/doc/toolbar/__tests__/toolbar.test.ts +0 -44
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { LightningElement, api } from "lwc";
|
|
2
|
+
import {
|
|
3
|
+
createDocumentationElement,
|
|
4
|
+
createEndpointElement,
|
|
5
|
+
createMethodElement,
|
|
6
|
+
createSecurityElement,
|
|
7
|
+
createSummaryElement,
|
|
8
|
+
createTypeElement
|
|
9
|
+
} from "./utils";
|
|
10
|
+
import type { TopicModel } from "./types";
|
|
11
|
+
|
|
12
|
+
export default class AmfTopic extends LightningElement {
|
|
13
|
+
private _model;
|
|
14
|
+
private amf;
|
|
15
|
+
private type;
|
|
16
|
+
|
|
17
|
+
@api
|
|
18
|
+
get model(): TopicModel {
|
|
19
|
+
return this._model;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
set model(value: TopicModel) {
|
|
23
|
+
if (
|
|
24
|
+
!this.amf ||
|
|
25
|
+
(value && this._model && value.amf !== this._model?.amf)
|
|
26
|
+
) {
|
|
27
|
+
this.amf = value && clone(value.amf);
|
|
28
|
+
}
|
|
29
|
+
if (
|
|
30
|
+
!this.type ||
|
|
31
|
+
(value && this._model && value.type !== this._model?.type)
|
|
32
|
+
) {
|
|
33
|
+
this.type = value && clone(value.type);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
this._model = value;
|
|
37
|
+
if (this._model) {
|
|
38
|
+
this.update();
|
|
39
|
+
}
|
|
40
|
+
// else { Remove child? No model, seems like no component should be shown. }
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
update(): void {
|
|
44
|
+
const container = this.template.querySelector("div.topic-container");
|
|
45
|
+
const { id } = this.model;
|
|
46
|
+
const type = this.type;
|
|
47
|
+
const amf = this.amf;
|
|
48
|
+
const { parser } = this.model;
|
|
49
|
+
let element;
|
|
50
|
+
|
|
51
|
+
if (type === "summary") {
|
|
52
|
+
element = createSummaryElement(amf);
|
|
53
|
+
} else if (type === "endpoint") {
|
|
54
|
+
const endpointModel = parser.computeEndpointApiModel(amf, id);
|
|
55
|
+
element = createEndpointElement(amf, endpointModel, id);
|
|
56
|
+
} else if (type === "method") {
|
|
57
|
+
const endpointMethodModel = parser.computeEndpointApiMethodModel(
|
|
58
|
+
amf,
|
|
59
|
+
id
|
|
60
|
+
);
|
|
61
|
+
const methodModel = parser.computeMethodApiModel(amf, id);
|
|
62
|
+
element = createMethodElement(
|
|
63
|
+
amf,
|
|
64
|
+
endpointMethodModel,
|
|
65
|
+
methodModel
|
|
66
|
+
);
|
|
67
|
+
} else if (type === "security") {
|
|
68
|
+
const securityModel = parser.computeSecurityApiModel(amf, id);
|
|
69
|
+
element = createSecurityElement(amf, securityModel);
|
|
70
|
+
} else if (type === "type") {
|
|
71
|
+
const mediaTypes = parser.computeApiMediaTypes(amf);
|
|
72
|
+
const typeModel = parser.computeTypeApiModel(amf, id);
|
|
73
|
+
element = createTypeElement(amf, typeModel, mediaTypes);
|
|
74
|
+
} else if (type === "documentation") {
|
|
75
|
+
const docsModel = parser.computeDocsApiModel(amf, id);
|
|
76
|
+
element = createDocumentationElement(amf, docsModel);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (container.firstChild) {
|
|
80
|
+
container.firstChild.remove();
|
|
81
|
+
}
|
|
82
|
+
container.appendChild(element);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* The underlying web components we use from api-console mutate their models we pass in.
|
|
88
|
+
* Since LWC makes them Read Only, we need to copy them before passing to the Web Component.
|
|
89
|
+
* @param value JSON Serializable object to clone.
|
|
90
|
+
* @returns A copy of Value. One that has been serialized and parsed via JSON. (Functions, Regex, etc are not preserved.)
|
|
91
|
+
*/
|
|
92
|
+
function clone(value): object {
|
|
93
|
+
return JSON.parse(JSON.stringify(value));
|
|
94
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Json } from "typings/custom";
|
|
2
|
+
|
|
3
|
+
export type ApiSummaryElement = HTMLElement & {
|
|
4
|
+
amf: Json;
|
|
5
|
+
hideToc: boolean;
|
|
6
|
+
titleLevel: string;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export type ApiEndpointElement = HTMLElement & {
|
|
10
|
+
amf: Json;
|
|
11
|
+
inlineMethods: boolean;
|
|
12
|
+
noNavigation: boolean;
|
|
13
|
+
selected: string;
|
|
14
|
+
endpoint: Json;
|
|
15
|
+
noTryIt: boolean;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type ApiMethodElement = HTMLElement & {
|
|
19
|
+
amf: Json;
|
|
20
|
+
noNavigation: boolean;
|
|
21
|
+
endpoint: Json;
|
|
22
|
+
method: Json;
|
|
23
|
+
noTryIt: boolean;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type ApiSecurityElement = HTMLElement & {
|
|
27
|
+
amf: Json;
|
|
28
|
+
security: Json;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type ApiTypeElement = HTMLElement & {
|
|
32
|
+
amf: Json;
|
|
33
|
+
type: Json;
|
|
34
|
+
mediaTypes: Json;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type ApiDocElement = HTMLElement & {
|
|
38
|
+
amf: Json;
|
|
39
|
+
shape: Json;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export type AmfModel = Json;
|
|
43
|
+
|
|
44
|
+
export interface AmfParser {
|
|
45
|
+
parse(): void;
|
|
46
|
+
parsedModel: any;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface TopicModel {
|
|
50
|
+
id: string;
|
|
51
|
+
type: string;
|
|
52
|
+
amf: AmfModel;
|
|
53
|
+
parser: AmfParser;
|
|
54
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ApiDocElement,
|
|
3
|
+
ApiEndpointElement,
|
|
4
|
+
ApiMethodElement,
|
|
5
|
+
ApiSecurityElement,
|
|
6
|
+
ApiSummaryElement,
|
|
7
|
+
ApiTypeElement
|
|
8
|
+
} from "./types";
|
|
9
|
+
import { Json } from "typings/custom";
|
|
10
|
+
|
|
11
|
+
export function createSummaryElement(amf: Json): HTMLElement {
|
|
12
|
+
const summaryElement: ApiSummaryElement = document.createElement(
|
|
13
|
+
"api-summary"
|
|
14
|
+
) as ApiSummaryElement;
|
|
15
|
+
summaryElement.amf = amf;
|
|
16
|
+
summaryElement.hideToc = true;
|
|
17
|
+
summaryElement.titleLevel = "1";
|
|
18
|
+
summaryElement.setAttribute(
|
|
19
|
+
"exportparts",
|
|
20
|
+
[
|
|
21
|
+
"api-title",
|
|
22
|
+
"api-title-label",
|
|
23
|
+
"api-version",
|
|
24
|
+
"marked-description",
|
|
25
|
+
"info-section",
|
|
26
|
+
"info-inline-desc",
|
|
27
|
+
"license-section",
|
|
28
|
+
"separator",
|
|
29
|
+
"toc"
|
|
30
|
+
].join(",")
|
|
31
|
+
);
|
|
32
|
+
return summaryElement;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Creates a `api-endpoint-documentation` web element from web API and current selection.
|
|
37
|
+
*/
|
|
38
|
+
export function createEndpointElement(
|
|
39
|
+
amf: Json,
|
|
40
|
+
endpointModel: Json,
|
|
41
|
+
selected: string
|
|
42
|
+
): HTMLElement {
|
|
43
|
+
const el: ApiEndpointElement = document.createElement(
|
|
44
|
+
"api-endpoint-documentation"
|
|
45
|
+
) as ApiEndpointElement;
|
|
46
|
+
el.amf = amf;
|
|
47
|
+
el.inlineMethods = false;
|
|
48
|
+
el.noNavigation = true;
|
|
49
|
+
el.selected = selected;
|
|
50
|
+
el.endpoint = endpointModel;
|
|
51
|
+
el.noTryIt = true;
|
|
52
|
+
return el;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Creates a `api-method-documentation` web element from web API and current selection.
|
|
57
|
+
*/
|
|
58
|
+
export function createMethodElement(
|
|
59
|
+
amf: Json,
|
|
60
|
+
endpointMethodModel: Json,
|
|
61
|
+
methodModel: Json
|
|
62
|
+
): HTMLElement {
|
|
63
|
+
const el: ApiMethodElement = document.createElement(
|
|
64
|
+
"api-method-documentation"
|
|
65
|
+
) as ApiMethodElement;
|
|
66
|
+
el.amf = amf;
|
|
67
|
+
el.noNavigation = true;
|
|
68
|
+
el.endpoint = endpointMethodModel;
|
|
69
|
+
el.method = methodModel;
|
|
70
|
+
el.noTryIt = true;
|
|
71
|
+
el.setAttribute("renderSecurity", "");
|
|
72
|
+
el.setAttribute("renderCodeSnippets", "");
|
|
73
|
+
return el;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Creates a documentation element for Security AMF type
|
|
78
|
+
*
|
|
79
|
+
*/
|
|
80
|
+
export function createSecurityElement(
|
|
81
|
+
amf: Json,
|
|
82
|
+
securityModel: Json
|
|
83
|
+
): HTMLElement {
|
|
84
|
+
const el: ApiSecurityElement = document.createElement(
|
|
85
|
+
"api-security-documentation"
|
|
86
|
+
) as ApiSecurityElement;
|
|
87
|
+
el.setAttribute("exportparts", ["security-title"].join(","));
|
|
88
|
+
el.amf = amf;
|
|
89
|
+
el.security = securityModel;
|
|
90
|
+
return el;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Creates a documentation element for Type AMF type
|
|
95
|
+
*
|
|
96
|
+
* @param {string} amfId Reference ID as passed in from amfConfig
|
|
97
|
+
* @param {string} selected Currently selected `@id`.
|
|
98
|
+
*/
|
|
99
|
+
export function createTypeElement(
|
|
100
|
+
amf: Json,
|
|
101
|
+
typeModel: Json,
|
|
102
|
+
mediaTypes: Json
|
|
103
|
+
): HTMLElement {
|
|
104
|
+
const el: ApiTypeElement = document.createElement(
|
|
105
|
+
"api-type-documentation"
|
|
106
|
+
) as ApiTypeElement;
|
|
107
|
+
el.setAttribute("exportparts", ["type-title"].join(","));
|
|
108
|
+
el.amf = amf;
|
|
109
|
+
el.type = typeModel;
|
|
110
|
+
el.mediaTypes = mediaTypes;
|
|
111
|
+
return el;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Creates a documentation element for Docs AMF type
|
|
116
|
+
*
|
|
117
|
+
* @param {string} amfId Reference ID as passed in from amfConfig
|
|
118
|
+
* @param {string} selected Currently selected `@id`.
|
|
119
|
+
*/
|
|
120
|
+
export function createDocumentationElement(
|
|
121
|
+
amf: Json,
|
|
122
|
+
docsModel: Json
|
|
123
|
+
): HTMLElement {
|
|
124
|
+
const el: ApiDocElement = document.createElement(
|
|
125
|
+
"api-documentation-document"
|
|
126
|
+
) as ApiDocElement;
|
|
127
|
+
el.amf = amf;
|
|
128
|
+
el.shape = docsModel;
|
|
129
|
+
return el;
|
|
130
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
@import "dxHelpers/reset";
|
|
2
|
+
@import "dxHelpers/text";
|
|
3
|
+
|
|
4
|
+
:host {
|
|
5
|
+
display: flex;
|
|
6
|
+
align-items: center;
|
|
7
|
+
justify-content: center;
|
|
8
|
+
width: fit-content;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
:host(.breadcrumb_long) {
|
|
12
|
+
/* ensure 30 character min-width */
|
|
13
|
+
min-width: 200px;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
:host(.breadcrumb_back-arrow) {
|
|
17
|
+
gap: var(--dx-g-spacing-sm);
|
|
18
|
+
padding: var(--dx-g-spacing-sm);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
:host(.breadcrumb_back-arrow:hover) {
|
|
22
|
+
background-color: var(--dx-g-cloud-blue-vibrant-90);
|
|
23
|
+
border-radius: var(--dx-g-spacing-xs);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
:host(.breadcrumb_back-arrow) :is(a, dx-icon) {
|
|
27
|
+
color: var(--dx-g-blue-vibrant-50);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
a {
|
|
31
|
+
font-weight: var(--dx-g-font-bold);
|
|
32
|
+
text-decoration: none;
|
|
33
|
+
transition: var(--dx-g-transition-hue-1x);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
a,
|
|
37
|
+
span {
|
|
38
|
+
color: var(
|
|
39
|
+
--dx-c-breadcrumbs-breadcrumb-color,
|
|
40
|
+
var(--dx-g-blue-vibrant-20)
|
|
41
|
+
);
|
|
42
|
+
font-family: var(--dx-g-font-sans);
|
|
43
|
+
font-size: var(--dx-g-text-sm);
|
|
44
|
+
overflow: hidden;
|
|
45
|
+
text-overflow: ellipsis;
|
|
46
|
+
white-space: nowrap;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
a:hover {
|
|
50
|
+
color: var(--dx-g-blue-vibrant-40);
|
|
51
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { track } from "dxUtils/analytics";
|
|
2
|
+
import { LightningElement, api } from "lwc";
|
|
3
|
+
import { AnalyticsPayload, BreadcrumbItemVariant } from "typings/custom";
|
|
4
|
+
|
|
5
|
+
const BREADCRUMB_LONG = "breadcrumb_long";
|
|
6
|
+
const BREADCRUMB_BACK_ARROW = "breadcrumb_back-arrow";
|
|
7
|
+
|
|
8
|
+
const LONG_LABEL_NUMBER = 30;
|
|
9
|
+
export default class BreadcrumbItem extends LightningElement {
|
|
10
|
+
@api href?: string;
|
|
11
|
+
@api analyticsEvent!: string;
|
|
12
|
+
@api analyticsBasePayload!: AnalyticsPayload;
|
|
13
|
+
|
|
14
|
+
@api
|
|
15
|
+
get label() {
|
|
16
|
+
return this._label;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
set label(value) {
|
|
20
|
+
this._label = value;
|
|
21
|
+
this.calculateClass();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@api
|
|
25
|
+
get variant() {
|
|
26
|
+
return this._variant;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
set variant(value) {
|
|
30
|
+
this._variant = value;
|
|
31
|
+
this.calculateClass();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
_label: string = "";
|
|
35
|
+
_variant: BreadcrumbItemVariant = "default";
|
|
36
|
+
|
|
37
|
+
private calculateClass(): void {
|
|
38
|
+
this.classList.remove(BREADCRUMB_LONG, BREADCRUMB_BACK_ARROW);
|
|
39
|
+
|
|
40
|
+
if (this.label?.length >= LONG_LABEL_NUMBER) {
|
|
41
|
+
this.classList.add(BREADCRUMB_LONG);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (this._variant === "back-arrow") {
|
|
45
|
+
this.classList.add(BREADCRUMB_BACK_ARROW);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private get isBackArrowVariant(): boolean {
|
|
50
|
+
return this._variant === "back-arrow";
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
private onLinkClick(event: Event): void {
|
|
54
|
+
if (!this.analyticsEvent) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
track(event.target!, this.analyticsEvent, {
|
|
59
|
+
...this.analyticsBasePayload,
|
|
60
|
+
clickText: this.label,
|
|
61
|
+
clickUrl: this.href
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
@import "dxHelpers/reset";
|
|
2
|
+
@import "dxHelpers/text";
|
|
3
|
+
|
|
4
|
+
:host {
|
|
5
|
+
--dx-c-breadcrumbs-title-color: var(--dx-g-blue-vibrant-20);
|
|
6
|
+
--dx-c-breadcrumbs-breadcrumb-color: var(--dx-g-blue-vibrant-20);
|
|
7
|
+
|
|
8
|
+
font-family: var(--dx-g-font-sans);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
nav {
|
|
12
|
+
display: flex;
|
|
13
|
+
align-items: center;
|
|
14
|
+
position: relative;
|
|
15
|
+
gap: var(--dx-g-spacing-sm);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.breadcrumb-item_slash {
|
|
19
|
+
min-width: fit-content;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
dx-dropdown {
|
|
23
|
+
--dx-c-dropdown-option-font-size: var(--dx-g-text-sm);
|
|
24
|
+
--dx-c-dropdown-option-label-color: var(
|
|
25
|
+
--dx-c-breadcrumbs-breadcrumb-color
|
|
26
|
+
);
|
|
27
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<nav role="navigation" aria-label={ariaLabel}>
|
|
3
|
+
<template if:true={displayCrumbs}>
|
|
4
|
+
<template if:false={renderSmallVariant}>
|
|
5
|
+
<doc-breadcrumb-item
|
|
6
|
+
analytics-event={analyticsEventName}
|
|
7
|
+
analytics-base-payload={analyticsBasePayload}
|
|
8
|
+
href={firstCrumb.href}
|
|
9
|
+
label={firstCrumb.label}
|
|
10
|
+
></doc-breadcrumb-item>
|
|
11
|
+
<span class="breadcrumb-item_slash">/</span>
|
|
12
|
+
<template if:true={renderDropdown}>
|
|
13
|
+
<dx-dropdown
|
|
14
|
+
if:true={renderDropdown}
|
|
15
|
+
analytics-event={analyticsEventName}
|
|
16
|
+
analytics-base-payload={analyticsBasePayload}
|
|
17
|
+
options={dropdownOptions}
|
|
18
|
+
open-on-hover
|
|
19
|
+
placement="bottom"
|
|
20
|
+
suppress-gtm-nav-headings
|
|
21
|
+
variant="indented"
|
|
22
|
+
width="fit-content"
|
|
23
|
+
>
|
|
24
|
+
<dx-button
|
|
25
|
+
aria-label="Open Breadcrumbs Dropdown"
|
|
26
|
+
icon-size="large"
|
|
27
|
+
icon-symbol="threedots"
|
|
28
|
+
variant="tertiary"
|
|
29
|
+
></dx-button>
|
|
30
|
+
</dx-dropdown>
|
|
31
|
+
<span class="breadcrumb-item_slash">/</span>
|
|
32
|
+
</template>
|
|
33
|
+
<template for:each={breadcrumbItems} for:item="breadcrumb">
|
|
34
|
+
<doc-breadcrumb-item
|
|
35
|
+
analytics-event={analyticsEventName}
|
|
36
|
+
analytics-base-payload={analyticsBasePayload}
|
|
37
|
+
href={breadcrumb.href}
|
|
38
|
+
key={breadcrumb.id}
|
|
39
|
+
label={breadcrumb.label}
|
|
40
|
+
></doc-breadcrumb-item>
|
|
41
|
+
<span class="breadcrumb-item_slash" key={breadcrumb.label}>
|
|
42
|
+
/
|
|
43
|
+
</span>
|
|
44
|
+
</template>
|
|
45
|
+
<doc-breadcrumb-item
|
|
46
|
+
label={lastCrumb.label}
|
|
47
|
+
></doc-breadcrumb-item>
|
|
48
|
+
</template>
|
|
49
|
+
<template if:true={renderSmallVariant}>
|
|
50
|
+
<doc-breadcrumb-item
|
|
51
|
+
analytics-event={analyticsEventName}
|
|
52
|
+
analytics-base-payload={analyticsBasePayload}
|
|
53
|
+
href={lastLinkCrump.href}
|
|
54
|
+
label={lastLinkCrump.label}
|
|
55
|
+
variant="back-arrow"
|
|
56
|
+
></doc-breadcrumb-item>
|
|
57
|
+
</template>
|
|
58
|
+
</template>
|
|
59
|
+
</nav>
|
|
60
|
+
</template>
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { LightningElement, api } from "lwc";
|
|
2
|
+
import { Breadcrumb, OptionWithLink } from "typings/custom";
|
|
3
|
+
import { toJson } from "dxUtils/normalizers";
|
|
4
|
+
|
|
5
|
+
type BreadcrumbConfig = {
|
|
6
|
+
minWidth: number;
|
|
7
|
+
crumbsInDropdown: number;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const GAP = 8;
|
|
11
|
+
|
|
12
|
+
// Unit in pixels based on Salesforce Sans font-family.
|
|
13
|
+
const CONSTANTS = {
|
|
14
|
+
pixelPerCharacter: 7.7,
|
|
15
|
+
pixelPerCrumbSpace: GAP * 2 + 8.6,
|
|
16
|
+
minWidthPerCrumb: 200,
|
|
17
|
+
dropdownWidth: 32
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const ANALYTICS_EVENT_NAME = "custEv_breadcrumbClick";
|
|
21
|
+
export const ANALYTICS_BASE_PAYLOAD = {
|
|
22
|
+
elementType: "breadcrumb",
|
|
23
|
+
locationOnPage: "breadcrumb",
|
|
24
|
+
ctaClick: true
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export default class Breadcrumbs extends LightningElement {
|
|
28
|
+
@api ariaLabel: string = "Documentation Breadcrumbs";
|
|
29
|
+
|
|
30
|
+
@api
|
|
31
|
+
get breadcrumbs(): Breadcrumb[] {
|
|
32
|
+
return this._breadcrumbs;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
set breadcrumbs(value) {
|
|
36
|
+
this.normalizeAndAssignBreadcrumbs(value);
|
|
37
|
+
this.calculateBreadcrumbsConfigs();
|
|
38
|
+
if (this.observer) {
|
|
39
|
+
this.updateDropdownOptionAmount();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@api
|
|
44
|
+
get pixelPerCharacter(): number {
|
|
45
|
+
return this._pixelPerCharacter;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
set pixelPerCharacter(value: number | string) {
|
|
49
|
+
this._pixelPerCharacter = +value;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
private _breadcrumbs: Breadcrumb[] = [];
|
|
53
|
+
private _pixelPerCharacter = CONSTANTS.pixelPerCharacter;
|
|
54
|
+
private navWidth = 0;
|
|
55
|
+
private observer: ResizeObserver | null = null;
|
|
56
|
+
private breadcrumbConfigs: BreadcrumbConfig[] = [];
|
|
57
|
+
private dropdownOptionAmount? = 0;
|
|
58
|
+
|
|
59
|
+
private get renderSmallVariant(): boolean {
|
|
60
|
+
return (
|
|
61
|
+
!this.dropdownOptionAmount &&
|
|
62
|
+
this.dropdownOptionAmount !== 0 &&
|
|
63
|
+
!!this.lastLinkCrump
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
private get lastLinkCrump(): Breadcrumb {
|
|
68
|
+
return this.breadcrumbs[this.breadcrumbs.length - 2];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
private get hasInternalBreadcrumbs(): boolean {
|
|
72
|
+
return this.breadcrumbs.length > 2;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
private get breadcrumbItems(): Breadcrumb[] {
|
|
76
|
+
return this.breadcrumbs!.slice(
|
|
77
|
+
this.dropdownOptionAmount! + 1,
|
|
78
|
+
this._breadcrumbs.length - 1
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
private get renderDropdown(): boolean {
|
|
83
|
+
return this.hasInternalBreadcrumbs && !!this.dropdownOptionAmount;
|
|
84
|
+
}
|
|
85
|
+
private get dropdownOptions(): OptionWithLink[] {
|
|
86
|
+
return this.breadcrumbs!.slice(1, this.dropdownOptionAmount! + 1).map(
|
|
87
|
+
(link) => ({
|
|
88
|
+
id: link.id!,
|
|
89
|
+
label: link.label,
|
|
90
|
+
link: { href: link.href! }
|
|
91
|
+
})
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
private get displayCrumbs(): boolean {
|
|
96
|
+
return this.breadcrumbs.length > 1;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
private get firstCrumb(): Breadcrumb {
|
|
100
|
+
return this.breadcrumbs[0];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
private get lastCrumb(): Breadcrumb {
|
|
104
|
+
return this.breadcrumbs[this.breadcrumbs.length - 1];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
private get analyticsEventName() {
|
|
108
|
+
return ANALYTICS_EVENT_NAME;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
private get analyticsBasePayload() {
|
|
112
|
+
return {
|
|
113
|
+
...ANALYTICS_BASE_PAYLOAD,
|
|
114
|
+
itemTitle: this.breadcrumbs.map((crumb) => crumb.label).join("/")
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
renderedCallback(): void {
|
|
119
|
+
if (!this.observer) {
|
|
120
|
+
this.observer = new ResizeObserver((entries) => {
|
|
121
|
+
const [nav] = entries;
|
|
122
|
+
if (this.navWidth === nav.contentRect.width) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
this.navWidth = nav.contentRect.width;
|
|
126
|
+
this.updateDropdownOptionAmount();
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
this.observer.observe(this.template.querySelector("nav")!);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
disconnectedCallback(): void {
|
|
134
|
+
this.observer?.disconnect();
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
private normalizeAndAssignBreadcrumbs(breadcrumbs?: Breadcrumb[] | string) {
|
|
138
|
+
if (!breadcrumbs) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
this._breadcrumbs = toJson(breadcrumbs).map((crumb: Breadcrumb) => ({
|
|
143
|
+
...crumb,
|
|
144
|
+
id: crumb.id || crumb.href
|
|
145
|
+
}));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
private updateDropdownOptionAmount(): void {
|
|
149
|
+
this.dropdownOptionAmount = this.breadcrumbConfigs.find(
|
|
150
|
+
({ minWidth }) => minWidth <= this.navWidth
|
|
151
|
+
)?.crumbsInDropdown;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
private calculateBreadcrumbsConfigs(): void {
|
|
155
|
+
this.breadcrumbConfigs = [
|
|
156
|
+
...Array(this._breadcrumbs.length - 1).keys()
|
|
157
|
+
].map((optionsAmount) => {
|
|
158
|
+
const breadcrumbs = [...this._breadcrumbs];
|
|
159
|
+
breadcrumbs.splice(1, optionsAmount);
|
|
160
|
+
return {
|
|
161
|
+
crumbsInDropdown: optionsAmount,
|
|
162
|
+
minWidth: this.reduceBreadcrumbs(
|
|
163
|
+
breadcrumbs,
|
|
164
|
+
optionsAmount
|
|
165
|
+
? CONSTANTS.dropdownWidth + CONSTANTS.pixelPerCrumbSpace
|
|
166
|
+
: 0
|
|
167
|
+
)
|
|
168
|
+
};
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
private reduceBreadcrumbs(
|
|
173
|
+
breadcrumbs: Breadcrumb[],
|
|
174
|
+
offset: number = 0
|
|
175
|
+
): number {
|
|
176
|
+
return breadcrumbs.reduce(
|
|
177
|
+
(previousValue, element) =>
|
|
178
|
+
previousValue +
|
|
179
|
+
Math.min(
|
|
180
|
+
element.label.length *
|
|
181
|
+
(this.pixelPerCharacter || CONSTANTS.pixelPerCharacter),
|
|
182
|
+
CONSTANTS.minWidthPerCrumb
|
|
183
|
+
),
|
|
184
|
+
(breadcrumbs.length - 1) * CONSTANTS.pixelPerCrumbSpace + offset
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
}
|