@salesforcedevs/docs-components 0.43.3-sidebar-scroll → 0.49.1-alpha.0
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 +1 -0
- package/package.json +1 -1
- package/src/modules/doc/breadcrumbItem/breadcrumbItem.css +50 -0
- package/src/modules/doc/breadcrumbItem/breadcrumbItem.html +5 -0
- package/src/modules/doc/breadcrumbItem/breadcrumbItem.ts +49 -0
- package/src/modules/doc/breadcrumbs/breadcrumbs.css +19 -0
- package/src/modules/doc/breadcrumbs/breadcrumbs.html +48 -0
- package/src/modules/doc/breadcrumbs/breadcrumbs.ts +144 -0
- package/src/modules/doc/content/content.css +2 -1
- package/src/modules/doc/content/content.ts +156 -162
package/lwc.config.json
CHANGED
package/package.json
CHANGED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
@import "helpers/reset";
|
|
2
|
+
@import "helpers/text";
|
|
3
|
+
|
|
4
|
+
:host {
|
|
5
|
+
display: flex;
|
|
6
|
+
align-items: center;
|
|
7
|
+
width: fit-content;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
:host(.breadcrumb_long) {
|
|
11
|
+
/* ensure 30 character min-width */
|
|
12
|
+
min-width: 245px;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
:host(.breadcrumb_back-arrow) {
|
|
16
|
+
gap: var(--dx-g-spacing-sm);
|
|
17
|
+
padding: var(--dx-g-spacing-sm);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
:host(.breadcrumb_back-arrow:hover) {
|
|
21
|
+
background-color: var(--dx-g-cloud-blue-vibrant-90);
|
|
22
|
+
border-radius: var(--dx-g-spacing-xs);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
:host(.breadcrumb_back-arrow) :is(a, dx-icon) {
|
|
26
|
+
color: var(--dx-g-blue-vibrant-50);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
a {
|
|
30
|
+
font-weight: var(--dx-g-font-bold);
|
|
31
|
+
text-decoration: none;
|
|
32
|
+
transition: var(--dx-g-transition-hue-1x);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
a,
|
|
36
|
+
span {
|
|
37
|
+
color: var(
|
|
38
|
+
--dx-c-breadcrumbs-breadcrumb-color,
|
|
39
|
+
var(--dx-g-blue-vibrant-20)
|
|
40
|
+
);
|
|
41
|
+
font-family: var(--dx-g-font-sans);
|
|
42
|
+
font-size: var(--dx-g-text-sm);
|
|
43
|
+
overflow: hidden;
|
|
44
|
+
text-overflow: ellipsis;
|
|
45
|
+
white-space: nowrap;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
a:hover {
|
|
49
|
+
color: var(--dx-g-blue-vibrant-40);
|
|
50
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { LightningElement, api } from "lwc";
|
|
2
|
+
import { BreadcrumbItemVariant } from "typings/custom";
|
|
3
|
+
|
|
4
|
+
const BREADCRUMB_LONG = "breadcrumb_long";
|
|
5
|
+
const BREADCRUMB_BACK_ARROW = "breadcrumb_back-arrow";
|
|
6
|
+
|
|
7
|
+
const LONG_LABEL_NUMBER = 30;
|
|
8
|
+
export default class BreadcrumbItem extends LightningElement {
|
|
9
|
+
@api href?: string;
|
|
10
|
+
|
|
11
|
+
@api
|
|
12
|
+
get label() {
|
|
13
|
+
return this._label;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
set label(value) {
|
|
17
|
+
this._label = value;
|
|
18
|
+
this.calculateClass();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@api
|
|
22
|
+
get variant() {
|
|
23
|
+
return this._variant;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
set variant(value) {
|
|
27
|
+
this._variant = value;
|
|
28
|
+
this.calculateClass();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
_label: string = "";
|
|
32
|
+
_variant: BreadcrumbItemVariant = "default";
|
|
33
|
+
|
|
34
|
+
private calculateClass(): void {
|
|
35
|
+
this.classList.remove(BREADCRUMB_LONG, BREADCRUMB_BACK_ARROW);
|
|
36
|
+
|
|
37
|
+
if (this.label?.length >= LONG_LABEL_NUMBER) {
|
|
38
|
+
this.classList.add(BREADCRUMB_LONG);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (this._variant === "back-arrow") {
|
|
42
|
+
this.classList.add(BREADCRUMB_BACK_ARROW);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private get isBackArrowVariant(): boolean {
|
|
47
|
+
return this._variant === "back-arrow";
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
@import "helpers/reset";
|
|
2
|
+
@import "helpers/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
|
+
|
|
9
|
+
nav {
|
|
10
|
+
display: flex;
|
|
11
|
+
align-items: center;
|
|
12
|
+
height: 100%;
|
|
13
|
+
position: relative;
|
|
14
|
+
gap: var(--dx-g-spacing-sm);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.breadcrumb-item_slash {
|
|
18
|
+
min-width: fit-content;
|
|
19
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<nav role="navigation" aria-label={ariaLabel}>
|
|
3
|
+
<template if:false={renderSmallVariant}>
|
|
4
|
+
<template if:true={renderFirstCrumb}>
|
|
5
|
+
<doc-breadcrumb-item
|
|
6
|
+
href={firstCrumb.href}
|
|
7
|
+
label={firstCrumb.label}
|
|
8
|
+
></doc-breadcrumb-item>
|
|
9
|
+
<span class="breadcrumb-item_slash">/</span>
|
|
10
|
+
</template>
|
|
11
|
+
<template if:true={renderDropdown}>
|
|
12
|
+
<dx-dropdown
|
|
13
|
+
if:true={renderDropdown}
|
|
14
|
+
options={dropdownOptions}
|
|
15
|
+
open-on-hover
|
|
16
|
+
placement="bottom"
|
|
17
|
+
width="200px"
|
|
18
|
+
>
|
|
19
|
+
<dx-button
|
|
20
|
+
aria-label="Open Breadcrumbs Dropdown"
|
|
21
|
+
icon-size="large"
|
|
22
|
+
icon-symbol="threedots"
|
|
23
|
+
variant="tertiary"
|
|
24
|
+
></dx-button>
|
|
25
|
+
</dx-dropdown>
|
|
26
|
+
<span class="breadcrumb-item_slash">/</span>
|
|
27
|
+
</template>
|
|
28
|
+
<template for:each={breadcrumbItems} for:item="breadcrumb">
|
|
29
|
+
<doc-breadcrumb-item
|
|
30
|
+
href={breadcrumb.href}
|
|
31
|
+
key={breadcrumb.label}
|
|
32
|
+
label={breadcrumb.label}
|
|
33
|
+
></doc-breadcrumb-item>
|
|
34
|
+
<span class="breadcrumb-item_slash" key={breadcrumb.label}>
|
|
35
|
+
/
|
|
36
|
+
</span>
|
|
37
|
+
</template>
|
|
38
|
+
<doc-breadcrumb-item label={lastCrumb.label}></doc-breadcrumb-item>
|
|
39
|
+
</template>
|
|
40
|
+
<template if:true={renderSmallVariant}>
|
|
41
|
+
<doc-breadcrumb-item
|
|
42
|
+
href={lastLinkCrump.href}
|
|
43
|
+
label={lastLinkCrump.label}
|
|
44
|
+
variant="back-arrow"
|
|
45
|
+
></doc-breadcrumb-item>
|
|
46
|
+
</template>
|
|
47
|
+
</nav>
|
|
48
|
+
</template>
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { LightningElement, api } from "lwc";
|
|
2
|
+
import { Breadcrumb, Option } from "typings/custom";
|
|
3
|
+
import { toJson } from "utils/normalizers";
|
|
4
|
+
|
|
5
|
+
type BreadcrumbConfig = {
|
|
6
|
+
minWidth: number;
|
|
7
|
+
crumbsInDropdown: number;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const GAP = 8;
|
|
11
|
+
const CONSTANTS = {
|
|
12
|
+
pixelPerCharacter: 7.2,
|
|
13
|
+
pixelPerCrumbSpace: GAP * 2 + 4.6,
|
|
14
|
+
minWidthPerCrumb: 245,
|
|
15
|
+
dropdownWidth: 32
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default class Breadcrumbs extends LightningElement {
|
|
19
|
+
@api ariaLabel: string = "Documentation Breadcrumbs";
|
|
20
|
+
|
|
21
|
+
@api
|
|
22
|
+
get breadcrumbs(): Breadcrumb[] {
|
|
23
|
+
return this._breadcrumbs;
|
|
24
|
+
}
|
|
25
|
+
set breadcrumbs(value) {
|
|
26
|
+
this._breadcrumbs = toJson(value) || [];
|
|
27
|
+
this.calculateBreadcrumbsConfigs();
|
|
28
|
+
if (this.observer) {
|
|
29
|
+
this.updateDropdownOptionAmount();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
private _breadcrumbs: Breadcrumb[] = [];
|
|
34
|
+
private navWidth = 0;
|
|
35
|
+
private observer: ResizeObserver | null = null;
|
|
36
|
+
private breadcrumbConfigs: BreadcrumbConfig[] = [];
|
|
37
|
+
private dropdownOptionAmount? = 0;
|
|
38
|
+
|
|
39
|
+
private get renderSmallVariant(): boolean {
|
|
40
|
+
return (
|
|
41
|
+
!this.dropdownOptionAmount &&
|
|
42
|
+
this.dropdownOptionAmount !== 0 &&
|
|
43
|
+
!!this.lastLinkCrump
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
private get lastLinkCrump(): Breadcrumb {
|
|
48
|
+
return this.breadcrumbs[this.breadcrumbs.length - 2];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
private get hasInternalBreadcrumbs(): boolean {
|
|
52
|
+
return this.breadcrumbs.length > 2;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
private get breadcrumbItems(): Breadcrumb[] {
|
|
56
|
+
return this.breadcrumbs!.slice(
|
|
57
|
+
this.dropdownOptionAmount! + 1,
|
|
58
|
+
this._breadcrumbs.length - 1
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
private get renderDropdown(): boolean {
|
|
63
|
+
return this.hasInternalBreadcrumbs && !!this.dropdownOptionAmount;
|
|
64
|
+
}
|
|
65
|
+
private get dropdownOptions(): Option[] {
|
|
66
|
+
return this.breadcrumbs!.slice(1, this.dropdownOptionAmount! + 1).map(
|
|
67
|
+
(link) => ({
|
|
68
|
+
id: link.href!,
|
|
69
|
+
label: link.label,
|
|
70
|
+
link: { href: link.href! }
|
|
71
|
+
})
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
private get renderFirstCrumb(): boolean {
|
|
76
|
+
return this.breadcrumbs.length > 1;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
private get firstCrumb(): Breadcrumb {
|
|
80
|
+
return this.breadcrumbs[0];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
private get lastCrumb(): Breadcrumb {
|
|
84
|
+
return this.breadcrumbs[this.breadcrumbs.length - 1];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
renderedCallback(): void {
|
|
88
|
+
if (!this.observer) {
|
|
89
|
+
this.observer = new ResizeObserver((entries) => {
|
|
90
|
+
const [nav] = entries;
|
|
91
|
+
if (this.navWidth === nav.contentRect.width) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
this.navWidth = nav.contentRect.width;
|
|
95
|
+
this.updateDropdownOptionAmount();
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
this.observer.observe(this.template.querySelector("nav")!);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
disconnectedCallback(): void {
|
|
103
|
+
this.observer?.disconnect();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
private updateDropdownOptionAmount(): void {
|
|
107
|
+
this.dropdownOptionAmount = this.breadcrumbConfigs.find(
|
|
108
|
+
({ minWidth }) => minWidth <= this.navWidth
|
|
109
|
+
)?.crumbsInDropdown;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
private calculateBreadcrumbsConfigs(): void {
|
|
113
|
+
this.breadcrumbConfigs = [
|
|
114
|
+
...Array(this._breadcrumbs.length - 1).keys()
|
|
115
|
+
].map((optionsAmount) => {
|
|
116
|
+
const breadcrumbs = [...this._breadcrumbs];
|
|
117
|
+
breadcrumbs.splice(1, optionsAmount);
|
|
118
|
+
return {
|
|
119
|
+
crumbsInDropdown: optionsAmount,
|
|
120
|
+
minWidth: this.reduceBreadcrumbs(
|
|
121
|
+
breadcrumbs,
|
|
122
|
+
optionsAmount
|
|
123
|
+
? CONSTANTS.dropdownWidth + CONSTANTS.pixelPerCrumbSpace
|
|
124
|
+
: 0
|
|
125
|
+
)
|
|
126
|
+
};
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
private reduceBreadcrumbs(
|
|
131
|
+
breadcrumbs: Breadcrumb[],
|
|
132
|
+
offset: number = 0
|
|
133
|
+
): number {
|
|
134
|
+
return breadcrumbs.reduce(
|
|
135
|
+
(previousValue, element) =>
|
|
136
|
+
previousValue +
|
|
137
|
+
Math.min(
|
|
138
|
+
element.label.length * CONSTANTS.pixelPerCharacter,
|
|
139
|
+
CONSTANTS.minWidthPerCrumb
|
|
140
|
+
),
|
|
141
|
+
(breadcrumbs.length - 1) * CONSTANTS.pixelPerCrumbSpace + offset
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -109,180 +109,174 @@ export default class Content extends LightningElement {
|
|
|
109
109
|
insertDocHtml(docContent?: string) {
|
|
110
110
|
const divEl = this.getCleanContainer();
|
|
111
111
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
if (className.startsWith("brush:")) {
|
|
128
|
-
language = className.split(":")[1];
|
|
112
|
+
if (divEl) {
|
|
113
|
+
divEl.innerHTML = docContent || this.docContent;
|
|
114
|
+
|
|
115
|
+
// Query the code blocks and create a dx-code-block component that contains the code
|
|
116
|
+
const codeBlockEls = divEl.querySelectorAll(".codeSection");
|
|
117
|
+
codeBlockEls.forEach((codeBlockEl) => {
|
|
118
|
+
codeBlockEl.setAttribute("lwc:dom", "manual");
|
|
119
|
+
const classList = codeBlockEl.firstChild.classList;
|
|
120
|
+
let language = "";
|
|
121
|
+
for (const key in classList) {
|
|
122
|
+
if (typeof classList[key] === "string") {
|
|
123
|
+
const className = classList[key];
|
|
124
|
+
if (className.startsWith("brush:")) {
|
|
125
|
+
language = className.split(":")[1];
|
|
126
|
+
}
|
|
129
127
|
}
|
|
130
128
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
129
|
+
const blockCmp = createElement("dx-code-block", {
|
|
130
|
+
is: CodeBlock
|
|
131
|
+
});
|
|
132
|
+
Object.assign(blockCmp, {
|
|
133
|
+
codeBlock: codeBlockEl.innerHTML,
|
|
134
|
+
// ! Hot fix for incoming html tags from couchdb for xml blocks, fix me soon please
|
|
135
|
+
language: LANGUAGE_MAP[language] || language,
|
|
136
|
+
theme: this.codeBlockTheme,
|
|
137
|
+
title: "", // Default no title.
|
|
138
|
+
variant: this.codeBlockType,
|
|
139
|
+
isEncoded: true
|
|
140
|
+
});
|
|
141
|
+
// eslint-disable-next-line no-use-before-define
|
|
142
|
+
codeBlockEl.innerHTML = "";
|
|
143
|
+
codeBlockEl.appendChild(blockCmp);
|
|
141
144
|
});
|
|
142
|
-
// eslint-disable-next-line no-use-before-define
|
|
143
|
-
codeBlockEl.innerHTML = "";
|
|
144
|
-
codeBlockEl.appendChild(blockCmp);
|
|
145
|
-
});
|
|
146
145
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
146
|
+
// Query the callouts and create a doc-content-callout component that contains the code
|
|
147
|
+
const calloutEls = divEl.querySelectorAll(".message");
|
|
148
|
+
calloutEls.forEach((calloutEl) => {
|
|
149
|
+
const calloutCompEl = createElement("doc-content-callout", {
|
|
150
|
+
is: ContentCallout
|
|
151
|
+
});
|
|
152
|
+
const detailEls = calloutEl.querySelectorAll(
|
|
153
|
+
"p, div.data, ol, ul, .codeSection, .mediaBd > span.ph"
|
|
154
|
+
);
|
|
155
|
+
detailEls.forEach((detailEl) => {
|
|
156
|
+
calloutCompEl.appendChild(detailEl);
|
|
157
|
+
});
|
|
158
|
+
const type = calloutEl.querySelector("h4").textContent;
|
|
159
|
+
const typeLower = type.toLowerCase();
|
|
160
|
+
Object.assign(calloutCompEl, {
|
|
161
|
+
title: type,
|
|
162
|
+
variant: typeLower
|
|
163
|
+
});
|
|
164
|
+
// eslint-disable-next-line no-use-before-define
|
|
165
|
+
calloutEl.innerHTML = "";
|
|
166
|
+
calloutEl.appendChild(calloutCompEl);
|
|
164
167
|
});
|
|
165
|
-
// eslint-disable-next-line no-use-before-define
|
|
166
|
-
calloutEl.innerHTML = "";
|
|
167
|
-
calloutEl.appendChild(calloutCompEl);
|
|
168
|
-
});
|
|
169
168
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
// ! This is a hack
|
|
187
|
-
// Normalize urls in case it doesn't come complete.
|
|
188
|
-
if (anchorEl.href.startsWith("atlas.")) {
|
|
189
|
-
anchorEl.href = "/docs/" + anchorEl.href;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
const href = anchorEl.href.split("/");
|
|
193
|
-
if (
|
|
194
|
-
(href[3] === this.pageReference.docId && this.isStorybook) ||
|
|
195
|
-
href[4] === this.pageReference.docId ||
|
|
196
|
-
href[6] === this.pageReference.docId
|
|
197
|
-
) {
|
|
198
|
-
let updatedURL;
|
|
199
|
-
switch (href.length) {
|
|
200
|
-
case 8:
|
|
201
|
-
updatedURL = href.splice(5).join("/");
|
|
202
|
-
break;
|
|
203
|
-
case 7:
|
|
204
|
-
updatedURL = href.splice(4).join("/");
|
|
205
|
-
break;
|
|
206
|
-
case 6:
|
|
207
|
-
updatedURL = href.splice(3).join("/");
|
|
208
|
-
break;
|
|
209
|
-
default:
|
|
210
|
-
updatedURL = href.splice(6).join("/");
|
|
211
|
-
break;
|
|
169
|
+
// Modify links to work with any domain, links that start with "#" are excluded
|
|
170
|
+
const anchorEls = divEl.querySelectorAll("a:not([href^='#'])");
|
|
171
|
+
|
|
172
|
+
anchorEls.forEach((anchorEl) => {
|
|
173
|
+
if (
|
|
174
|
+
anchorEl.textContent.includes("Next →") ||
|
|
175
|
+
anchorEl.textContent.includes("← Previous")
|
|
176
|
+
) {
|
|
177
|
+
if (this.showPaginationButtons) {
|
|
178
|
+
this.renderPaginationButton(anchorEl);
|
|
179
|
+
} else {
|
|
180
|
+
anchorEl.remove();
|
|
181
|
+
}
|
|
212
182
|
}
|
|
213
|
-
anchorEl.addEventListener(
|
|
214
|
-
"click",
|
|
215
|
-
// eslint-disable-next-line no-use-before-define
|
|
216
|
-
this.handleNavClick.bind(this)
|
|
217
|
-
);
|
|
218
|
-
// anchor href event is not propagated here as we want SPA nature.
|
|
219
|
-
// But in prerender.io - as javascript is not executed, we want the anchor links are proper (absolute urls).
|
|
220
|
-
anchorEl.setAttribute("href", "/docs/" + updatedURL);
|
|
221
|
-
anchorEl.setAttribute("data-id", "docs/" + updatedURL);
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
anchorEl.setAttribute("data-id", anchorEl.href);
|
|
226
|
-
});
|
|
227
183
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
const isImage = mediaEl.nodeName === "IMG";
|
|
233
|
-
let src = mediaEl.getAttribute("src");
|
|
234
|
-
if (!src) {
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
const alt = mediaEl.getAttribute("alt");
|
|
238
|
-
const title = mediaEl.getAttribute("title");
|
|
239
|
-
const label = mediaEl.getAttribute("label");
|
|
240
|
-
const width = mediaEl.getAttribute("width");
|
|
241
|
-
const height = mediaEl.getAttribute("height");
|
|
242
|
-
|
|
243
|
-
if (isImage) {
|
|
244
|
-
src = src.startsWith("/")
|
|
245
|
-
? `https://developer.salesforce.com${src}`
|
|
246
|
-
: src.replace(
|
|
247
|
-
window.location.origin,
|
|
248
|
-
"https://developer.salesforce.com"
|
|
249
|
-
);
|
|
250
|
-
|
|
251
|
-
const img: HTMLImageElement = document.createElement("img");
|
|
252
|
-
img.src = src;
|
|
253
|
-
if (alt) {
|
|
254
|
-
img.alt = alt;
|
|
184
|
+
// ! This is a hack
|
|
185
|
+
// Normalize urls in case it doesn't come complete.
|
|
186
|
+
if (anchorEl.href.startsWith("atlas.")) {
|
|
187
|
+
anchorEl.href = "/docs/" + anchorEl.href;
|
|
255
188
|
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
189
|
+
|
|
190
|
+
const href = anchorEl.href.split("/");
|
|
191
|
+
if (
|
|
192
|
+
(href[3] === this.pageReference.docId &&
|
|
193
|
+
this.isStorybook) ||
|
|
194
|
+
href[4] === this.pageReference.docId ||
|
|
195
|
+
href[6] === this.pageReference.docId
|
|
196
|
+
) {
|
|
197
|
+
let updatedURL;
|
|
198
|
+
switch (href.length) {
|
|
199
|
+
case 8:
|
|
200
|
+
updatedURL = href.splice(5).join("/");
|
|
201
|
+
break;
|
|
202
|
+
case 7:
|
|
203
|
+
updatedURL = href.splice(4).join("/");
|
|
204
|
+
break;
|
|
205
|
+
case 6:
|
|
206
|
+
updatedURL = href.splice(3).join("/");
|
|
207
|
+
break;
|
|
208
|
+
default:
|
|
209
|
+
updatedURL = href.splice(6).join("/");
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
anchorEl.addEventListener(
|
|
213
|
+
"click",
|
|
214
|
+
// eslint-disable-next-line no-use-before-define
|
|
215
|
+
this.handleNavClick.bind(this)
|
|
216
|
+
);
|
|
217
|
+
// anchor href event is not propagated here as we want SPA nature.
|
|
218
|
+
// But in prerender.io - as javascript is not executed, we want the anchor links are proper (absolute urls).
|
|
219
|
+
anchorEl.setAttribute("href", "/docs/" + updatedURL);
|
|
220
|
+
anchorEl.setAttribute("data-id", "docs/" + updatedURL);
|
|
221
|
+
return;
|
|
264
222
|
}
|
|
265
223
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
} else {
|
|
269
|
-
const contentMediaEl = createElement("doc-content-media", {
|
|
270
|
-
is: ContentMedia
|
|
271
|
-
});
|
|
272
|
-
Object.assign(contentMediaEl, {
|
|
273
|
-
contentType: "iframe",
|
|
274
|
-
contentSrc: src,
|
|
275
|
-
mediaTitle: alt || title || label
|
|
276
|
-
});
|
|
277
|
-
mediaEl.parentNode!.insertBefore(contentMediaEl, mediaEl);
|
|
278
|
-
}
|
|
279
|
-
mediaEl.remove();
|
|
280
|
-
});
|
|
224
|
+
anchorEl.setAttribute("data-id", anchorEl.href);
|
|
225
|
+
});
|
|
281
226
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
227
|
+
// Modify image src to work with any domain and replace images/iframes with doc-content-media
|
|
228
|
+
const imgEls = divEl.querySelectorAll("img, iframe");
|
|
229
|
+
|
|
230
|
+
imgEls.forEach((mediaEl) => {
|
|
231
|
+
const isImage = mediaEl.nodeName === "IMG";
|
|
232
|
+
let src = mediaEl.getAttribute("src");
|
|
233
|
+
if (!src) {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
const alt = mediaEl.getAttribute("alt");
|
|
237
|
+
const title = mediaEl.getAttribute("title");
|
|
238
|
+
const label = mediaEl.getAttribute("label");
|
|
239
|
+
const width = mediaEl.getAttribute("width");
|
|
240
|
+
const height = mediaEl.getAttribute("height");
|
|
241
|
+
|
|
242
|
+
if (isImage) {
|
|
243
|
+
src = src.startsWith("/")
|
|
244
|
+
? `https://developer.salesforce.com${src}`
|
|
245
|
+
: src.replace(
|
|
246
|
+
window.location.origin,
|
|
247
|
+
"https://developer.salesforce.com"
|
|
248
|
+
);
|
|
249
|
+
|
|
250
|
+
const img: HTMLImageElement = document.createElement("img");
|
|
251
|
+
img.src = src;
|
|
252
|
+
if (alt) {
|
|
253
|
+
img.alt = alt;
|
|
254
|
+
}
|
|
255
|
+
if (title) {
|
|
256
|
+
img.title = title;
|
|
257
|
+
}
|
|
258
|
+
if (height) {
|
|
259
|
+
img.height = parseFloat(height);
|
|
260
|
+
}
|
|
261
|
+
if (width) {
|
|
262
|
+
img.width = parseFloat(width);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
img.className = "content-image";
|
|
266
|
+
mediaEl.parentNode!.insertBefore(img, mediaEl);
|
|
267
|
+
} else {
|
|
268
|
+
const contentMediaEl = createElement("doc-content-media", {
|
|
269
|
+
is: ContentMedia
|
|
270
|
+
});
|
|
271
|
+
Object.assign(contentMediaEl, {
|
|
272
|
+
contentType: "iframe",
|
|
273
|
+
contentSrc: src,
|
|
274
|
+
mediaTitle: alt || title || label
|
|
275
|
+
});
|
|
276
|
+
mediaEl.parentNode!.insertBefore(contentMediaEl, mediaEl);
|
|
277
|
+
}
|
|
278
|
+
mediaEl.remove();
|
|
279
|
+
});
|
|
286
280
|
}
|
|
287
281
|
|
|
288
282
|
// Once the html has been corectly modified, naviage to the page reference on the page
|