@salesforcedevs/docs-components 1.16.0 → 1.17.0-edit
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 +2 -2
- package/src/modules/doc/content/content.ts +7 -32
- package/src/modules/doc/markdownEditor/markdownEditor.css +166 -0
- package/src/modules/doc/markdownEditor/markdownEditor.html +68 -0
- package/src/modules/doc/markdownEditor/markdownEditor.ts +118 -0
- package/LICENSE +0 -12
package/lwc.config.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforcedevs/docs-components",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.17.0-edit",
|
|
4
4
|
"description": "Docs Lightning web components for DSC",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "index.js",
|
|
@@ -25,5 +25,5 @@
|
|
|
25
25
|
"@types/lodash.orderby": "4.6.9",
|
|
26
26
|
"@types/lodash.uniqby": "4.7.9"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "4629fdd9ca18a13480044ad43515b91945d16aad"
|
|
29
29
|
}
|
|
@@ -43,26 +43,10 @@ export default class Content extends LightningElement {
|
|
|
43
43
|
return this.docContent;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
@api
|
|
47
|
-
set codeBlockTheme(value) {
|
|
48
|
-
this._codeBlockTheme = value;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
get codeBlockTheme() {
|
|
52
|
-
return this._codeBlockTheme;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
46
|
@track docContent: DocContent = "";
|
|
56
|
-
_codeBlockTheme: string = "dark";
|
|
57
47
|
_docRendered: boolean = false;
|
|
58
|
-
originalCodeBlockThemeValue: String = "";
|
|
59
48
|
|
|
60
49
|
connectedCallback() {
|
|
61
|
-
this.template.addEventListener(
|
|
62
|
-
"themechange",
|
|
63
|
-
this.updateTheme.bind(this) // eslint-disableline no-use-before-define
|
|
64
|
-
);
|
|
65
|
-
|
|
66
50
|
window.addEventListener(
|
|
67
51
|
"highlightedtermchange",
|
|
68
52
|
this.updateHighlighted
|
|
@@ -76,15 +60,6 @@ export default class Content extends LightningElement {
|
|
|
76
60
|
);
|
|
77
61
|
}
|
|
78
62
|
|
|
79
|
-
updateTheme() {
|
|
80
|
-
this._codeBlockTheme =
|
|
81
|
-
this._codeBlockTheme === "dark" ? "light" : "dark";
|
|
82
|
-
const codeBlockEls = this.template.querySelectorAll("dx-code-block");
|
|
83
|
-
codeBlockEls.forEach((codeBlockEl) => {
|
|
84
|
-
codeBlockEl.setAttribute("theme", this._codeBlockTheme);
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
|
|
88
63
|
renderPaginationButton(anchorEl: HTMLElement) {
|
|
89
64
|
const isNext = anchorEl.textContent!.includes("Next →");
|
|
90
65
|
anchorEl.innerHTML = "";
|
|
@@ -116,11 +91,11 @@ export default class Content extends LightningElement {
|
|
|
116
91
|
const codeBlockEls = divEl.querySelectorAll(".codeSection");
|
|
117
92
|
codeBlockEls.forEach((codeBlockEl) => {
|
|
118
93
|
codeBlockEl.setAttribute("lwc:dom", "manual");
|
|
119
|
-
const classList =
|
|
94
|
+
const classList = codeBlockEl.firstElementChild?.classList;
|
|
120
95
|
let language = "";
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
const className = classList[
|
|
96
|
+
if (classList) {
|
|
97
|
+
for (let i = 0; i < classList.length; i++) {
|
|
98
|
+
const className = classList[i];
|
|
124
99
|
if (className.startsWith("brush:")) {
|
|
125
100
|
language = className.split(":")[1];
|
|
126
101
|
}
|
|
@@ -133,7 +108,6 @@ export default class Content extends LightningElement {
|
|
|
133
108
|
codeBlock: codeBlockEl.innerHTML,
|
|
134
109
|
// ! Hot fix for incoming html tags from couchdb for xml blocks, fix me soon please
|
|
135
110
|
language: LANGUAGE_MAP[language] || language,
|
|
136
|
-
theme: this.codeBlockTheme,
|
|
137
111
|
header: "", // Default no title.
|
|
138
112
|
variant: this.codeBlockType,
|
|
139
113
|
isEncoded: true
|
|
@@ -158,6 +132,7 @@ export default class Content extends LightningElement {
|
|
|
158
132
|
}
|
|
159
133
|
});
|
|
160
134
|
|
|
135
|
+
// Set a flag to 1 (true) if and only if all detailEls have no content.
|
|
161
136
|
let flag = 1;
|
|
162
137
|
for (let i: number = 0; i < detailEls.length; i++) {
|
|
163
138
|
flag &= (detailEls[i].innerHTML.trim() === "") as any; // Dark Magic TM
|
|
@@ -359,7 +334,7 @@ export default class Content extends LightningElement {
|
|
|
359
334
|
);
|
|
360
335
|
|
|
361
336
|
@api
|
|
362
|
-
public navigateToHash(hash: String) {
|
|
337
|
+
public navigateToHash = (hash: String) => {
|
|
363
338
|
const splitHash = hash.split("#");
|
|
364
339
|
if (splitHash.length === 2) {
|
|
365
340
|
hash = splitHash[1];
|
|
@@ -370,7 +345,7 @@ export default class Content extends LightningElement {
|
|
|
370
345
|
} else {
|
|
371
346
|
window.scrollTo({ top: 0, behavior: "smooth" });
|
|
372
347
|
}
|
|
373
|
-
}
|
|
348
|
+
};
|
|
374
349
|
|
|
375
350
|
renderedCallback() {
|
|
376
351
|
if (this._docRendered) {
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
.markdown-editor {
|
|
2
|
+
border: 1px solid #e1e5e9;
|
|
3
|
+
border-radius: 4px;
|
|
4
|
+
overflow: hidden;
|
|
5
|
+
background: #fff;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/* Editor Toolbar */
|
|
9
|
+
.editor-toolbar {
|
|
10
|
+
display: flex;
|
|
11
|
+
align-items: center;
|
|
12
|
+
justify-content: flex-end;
|
|
13
|
+
gap: 0.5rem;
|
|
14
|
+
padding: 0.75rem 1rem;
|
|
15
|
+
background: #f8f9fa;
|
|
16
|
+
border-bottom: 1px solid #e1e5e9;
|
|
17
|
+
flex-wrap: wrap;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.edit-button,
|
|
21
|
+
.cancel-button,
|
|
22
|
+
.save-button {
|
|
23
|
+
min-width: 80px;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.status-indicator {
|
|
27
|
+
margin-left: 0.5rem;
|
|
28
|
+
font-size: 0.875rem;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.status-saving {
|
|
32
|
+
color: #0176d3;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.status-success {
|
|
36
|
+
color: #04844b;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.status-error {
|
|
40
|
+
color: #ea001e;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/* Content Viewer */
|
|
44
|
+
.content-viewer {
|
|
45
|
+
padding: 1rem;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.content-display {
|
|
49
|
+
line-height: 1.6;
|
|
50
|
+
color: #3e3e3c;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.content-display h1,
|
|
54
|
+
.content-display h2,
|
|
55
|
+
.content-display h3,
|
|
56
|
+
.content-display h4,
|
|
57
|
+
.content-display h5,
|
|
58
|
+
.content-display h6 {
|
|
59
|
+
margin-top: 1.5rem;
|
|
60
|
+
margin-bottom: 0.5rem;
|
|
61
|
+
color: #181818;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.content-display p {
|
|
65
|
+
margin-bottom: 1rem;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.content-display ul,
|
|
69
|
+
.content-display ol {
|
|
70
|
+
margin-bottom: 1rem;
|
|
71
|
+
padding-left: 2rem;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.content-display code {
|
|
75
|
+
background-color: #f3f2f2;
|
|
76
|
+
padding: 0.125rem 0.25rem;
|
|
77
|
+
border-radius: 0.25rem;
|
|
78
|
+
font-family: Monaco, Menlo, "Ubuntu Mono", monospace;
|
|
79
|
+
font-size: 0.875rem;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.content-display pre {
|
|
83
|
+
background-color: #f3f2f2;
|
|
84
|
+
padding: 1rem;
|
|
85
|
+
border-radius: 0.25rem;
|
|
86
|
+
overflow-x: auto;
|
|
87
|
+
margin-bottom: 1rem;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.content-display pre code {
|
|
91
|
+
background-color: transparent;
|
|
92
|
+
padding: 0;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/* Editor Wrapper */
|
|
96
|
+
.editor-wrapper {
|
|
97
|
+
position: relative;
|
|
98
|
+
min-height: 300px;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.simple-editor {
|
|
102
|
+
width: 100%;
|
|
103
|
+
min-height: 300px;
|
|
104
|
+
padding: 1rem;
|
|
105
|
+
border: none;
|
|
106
|
+
outline: none;
|
|
107
|
+
font-family: Monaco, Menlo, "Ubuntu Mono", monospace;
|
|
108
|
+
font-size: 0.875rem;
|
|
109
|
+
line-height: 1.5;
|
|
110
|
+
resize: vertical;
|
|
111
|
+
background: #fff;
|
|
112
|
+
color: #3e3e3c;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.simple-editor:focus {
|
|
116
|
+
outline: none;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.simple-editor::placeholder {
|
|
120
|
+
color: #706e6b;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/* Loading Overlay */
|
|
124
|
+
.loading-overlay {
|
|
125
|
+
position: absolute;
|
|
126
|
+
top: 0;
|
|
127
|
+
left: 0;
|
|
128
|
+
right: 0;
|
|
129
|
+
bottom: 0;
|
|
130
|
+
background: rgb(255 255 255 / 80%);
|
|
131
|
+
display: flex;
|
|
132
|
+
align-items: center;
|
|
133
|
+
justify-content: center;
|
|
134
|
+
z-index: 1000;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/* Responsive Design */
|
|
138
|
+
@media (max-width: 768px) {
|
|
139
|
+
.editor-toolbar {
|
|
140
|
+
flex-wrap: wrap;
|
|
141
|
+
gap: 0.25rem;
|
|
142
|
+
justify-content: flex-end;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
.status-indicator {
|
|
146
|
+
margin-left: 0.25rem;
|
|
147
|
+
width: auto;
|
|
148
|
+
text-align: right;
|
|
149
|
+
margin-top: 0;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
.simple-editor {
|
|
153
|
+
min-height: 250px;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
.content-viewer {
|
|
157
|
+
padding: 0.75rem;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/* Empty state */
|
|
162
|
+
.content-display:empty::before {
|
|
163
|
+
content: "No content to display";
|
|
164
|
+
color: #706e6b;
|
|
165
|
+
font-style: italic;
|
|
166
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="markdown-editor">
|
|
3
|
+
<!-- Editor Toolbar -->
|
|
4
|
+
<div class="editor-toolbar">
|
|
5
|
+
<template if:true={showViewer}>
|
|
6
|
+
<dx-button
|
|
7
|
+
onclick={handleEdit}
|
|
8
|
+
variant="tertiary"
|
|
9
|
+
class="edit-button"
|
|
10
|
+
>
|
|
11
|
+
Edit Content
|
|
12
|
+
</dx-button>
|
|
13
|
+
</template>
|
|
14
|
+
|
|
15
|
+
<template if:true={showEditor}>
|
|
16
|
+
<dx-button
|
|
17
|
+
onclick={handleCancel}
|
|
18
|
+
variant="secondary"
|
|
19
|
+
class="cancel-button"
|
|
20
|
+
>
|
|
21
|
+
Cancel
|
|
22
|
+
</dx-button>
|
|
23
|
+
|
|
24
|
+
<dx-button
|
|
25
|
+
onclick={handleSave}
|
|
26
|
+
variant="primary"
|
|
27
|
+
disabled={saveButtonDisabled}
|
|
28
|
+
class="save-button"
|
|
29
|
+
>
|
|
30
|
+
Save
|
|
31
|
+
</dx-button>
|
|
32
|
+
|
|
33
|
+
<div class="status-indicator">
|
|
34
|
+
<span class={statusClass}>{statusMessage}</span>
|
|
35
|
+
</div>
|
|
36
|
+
</template>
|
|
37
|
+
</div>
|
|
38
|
+
|
|
39
|
+
<!-- Content Viewer (Read-only) -->
|
|
40
|
+
<template if:true={showViewer}>
|
|
41
|
+
<div class="content-viewer">
|
|
42
|
+
<div class="content-display" innerhtml={content}></div>
|
|
43
|
+
</div>
|
|
44
|
+
</template>
|
|
45
|
+
|
|
46
|
+
<!-- Simple Editor -->
|
|
47
|
+
<template if:true={showEditor}>
|
|
48
|
+
<div class="editor-wrapper">
|
|
49
|
+
<textarea
|
|
50
|
+
class="simple-editor"
|
|
51
|
+
value={markdownContent}
|
|
52
|
+
onchange={handleContentChange}
|
|
53
|
+
placeholder="Enter your markdown content here..."
|
|
54
|
+
></textarea>
|
|
55
|
+
</div>
|
|
56
|
+
</template>
|
|
57
|
+
|
|
58
|
+
<!-- Loading Overlay -->
|
|
59
|
+
<template if:true={isLoading}>
|
|
60
|
+
<div class="loading-overlay">
|
|
61
|
+
<dx-spinner
|
|
62
|
+
size="medium"
|
|
63
|
+
alternative-text="Loading"
|
|
64
|
+
></dx-spinner>
|
|
65
|
+
</div>
|
|
66
|
+
</template>
|
|
67
|
+
</div>
|
|
68
|
+
</template>
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { LightningElement, api, track } from "lwc";
|
|
2
|
+
|
|
3
|
+
export default class MarkdownEditor extends LightningElement {
|
|
4
|
+
@api content: string = "";
|
|
5
|
+
@api filePath: string = "";
|
|
6
|
+
@api saveEndpoint: string = "";
|
|
7
|
+
@api authToken: string = "";
|
|
8
|
+
|
|
9
|
+
@track isEditing: boolean = false;
|
|
10
|
+
@track markdownContent: string = "";
|
|
11
|
+
@track isLoading: boolean = false;
|
|
12
|
+
@track saveStatus: "idle" | "saving" | "success" | "error" = "idle";
|
|
13
|
+
|
|
14
|
+
connectedCallback() {
|
|
15
|
+
this.markdownContent = this.content; // Simple fallback for now
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Event Handlers
|
|
19
|
+
handleEdit() {
|
|
20
|
+
this.isEditing = true;
|
|
21
|
+
this.saveStatus = "idle";
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
handleCancel() {
|
|
25
|
+
this.isEditing = false;
|
|
26
|
+
this.saveStatus = "idle";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async handleSave() {
|
|
30
|
+
if (!this.saveEndpoint) {
|
|
31
|
+
console.error("Save endpoint not configured");
|
|
32
|
+
this.saveStatus = "error";
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
this.saveStatus = "saving";
|
|
37
|
+
this.isLoading = true;
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
const response = await fetch(this.saveEndpoint, {
|
|
41
|
+
method: "POST",
|
|
42
|
+
headers: {
|
|
43
|
+
"Content-Type": "application/json",
|
|
44
|
+
Authorization: this.authToken
|
|
45
|
+
? `Bearer ${this.authToken}`
|
|
46
|
+
: ""
|
|
47
|
+
},
|
|
48
|
+
body: JSON.stringify({
|
|
49
|
+
content: this.markdownContent,
|
|
50
|
+
filePath: this.filePath,
|
|
51
|
+
originalContent: this.content
|
|
52
|
+
})
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
if (response.ok) {
|
|
56
|
+
this.saveStatus = "success";
|
|
57
|
+
this.isEditing = false;
|
|
58
|
+
|
|
59
|
+
// Dispatch save success event
|
|
60
|
+
this.dispatchEvent(
|
|
61
|
+
new CustomEvent("saved", {
|
|
62
|
+
detail: {
|
|
63
|
+
success: true,
|
|
64
|
+
content: this.markdownContent,
|
|
65
|
+
filePath: this.filePath
|
|
66
|
+
}
|
|
67
|
+
})
|
|
68
|
+
);
|
|
69
|
+
} else {
|
|
70
|
+
throw new Error(`Save failed: ${response.status}`);
|
|
71
|
+
}
|
|
72
|
+
} catch (error) {
|
|
73
|
+
console.error("Save failed:", error);
|
|
74
|
+
this.saveStatus = "error";
|
|
75
|
+
} finally {
|
|
76
|
+
this.isLoading = false;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Getters for UI state
|
|
81
|
+
get showEditor() {
|
|
82
|
+
return this.isEditing;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
get showViewer() {
|
|
86
|
+
return !this.isEditing;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
get saveButtonDisabled() {
|
|
90
|
+
return this.saveStatus === "saving" || this.isLoading;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
get statusMessage() {
|
|
94
|
+
switch (this.saveStatus) {
|
|
95
|
+
case "saving":
|
|
96
|
+
return "Saving...";
|
|
97
|
+
case "success":
|
|
98
|
+
return "Saved successfully!";
|
|
99
|
+
case "error":
|
|
100
|
+
return "Save failed. Please try again.";
|
|
101
|
+
default:
|
|
102
|
+
return "";
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
get statusClass() {
|
|
107
|
+
switch (this.saveStatus) {
|
|
108
|
+
case "saving":
|
|
109
|
+
return "status-saving";
|
|
110
|
+
case "success":
|
|
111
|
+
return "status-success";
|
|
112
|
+
case "error":
|
|
113
|
+
return "status-error";
|
|
114
|
+
default:
|
|
115
|
+
return "";
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
Copyright (c) 2020, Salesforce.com, Inc.
|
|
2
|
-
All rights reserved.
|
|
3
|
-
|
|
4
|
-
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
5
|
-
|
|
6
|
-
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
7
|
-
|
|
8
|
-
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
9
|
-
|
|
10
|
-
* Neither the name of Salesforce.com nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
11
|
-
|
|
12
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|