@salesforcedevs/docs-components 0.0.10-edit → 0.0.11-chat

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.
@@ -1,162 +0,0 @@
1
- <template>
2
- <!-- Edit File Trigger Button -->
3
- <button
4
- class="edit-file-trigger"
5
- onclick={handleEditClick}
6
- disabled={disabled}
7
- aria-label="Edit file"
8
- title="Edit file"
9
- >
10
- <svg
11
- class="edit-file-icon"
12
- viewBox="0 0 24 24"
13
- fill="none"
14
- stroke="currentColor"
15
- >
16
- <path
17
- stroke-linecap="round"
18
- stroke-linejoin="round"
19
- stroke-width="2"
20
- d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"
21
- />
22
- </svg>
23
- <span class="edit-file-trigger-text">Edit</span>
24
- </button>
25
-
26
- <!-- Popover Overlay -->
27
- <template lwc:if={isPopoverOpen}>
28
- <div class={overlayClass} onclick={handleOverlayClick}>
29
- <div class={popoverClass}>
30
- <!-- Popover Header -->
31
- <div class="edit-file-header">
32
- <h2 class="edit-file-title">{project}</h2>
33
- <template lwc:if={fileName}>
34
- <p class="edit-file-filename">
35
- <svg
36
- class="edit-file-file-icon"
37
- viewBox="0 0 24 24"
38
- fill="none"
39
- stroke="currentColor"
40
- >
41
- <path
42
- stroke-linecap="round"
43
- stroke-linejoin="round"
44
- stroke-width="2"
45
- d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"
46
- />
47
- </svg>
48
- {fileName}
49
- </p>
50
- </template>
51
- <button
52
- class="edit-file-close"
53
- onclick={handleCancel}
54
- aria-label="Close editor"
55
- >
56
- <svg
57
- class="edit-file-close-icon"
58
- viewBox="0 0 24 24"
59
- fill="none"
60
- stroke="currentColor"
61
- >
62
- <path
63
- stroke-linecap="round"
64
- stroke-linejoin="round"
65
- stroke-width="2"
66
- d="M6 18L18 6M6 6l12 12"
67
- />
68
- </svg>
69
- </button>
70
- </div>
71
-
72
- <!-- Popover Content -->
73
- <div class="edit-file-content">
74
- <!-- Loading State -->
75
- <template lwc:if={isLoading}>
76
- <div class="edit-file-loading">
77
- <div class="edit-file-spinner"></div>
78
- <p class="edit-file-loading-text">
79
- Loading file content...
80
- </p>
81
- </div>
82
- </template>
83
-
84
- <!-- Error Message -->
85
- <template lwc:if={errorMessage}>
86
- <div class="edit-file-error">
87
- <svg
88
- class="edit-file-error-icon"
89
- viewBox="0 0 24 24"
90
- fill="none"
91
- stroke="currentColor"
92
- >
93
- <circle cx="12" cy="12" r="10"></circle>
94
- <line x1="15" y1="9" x2="9" y2="15"></line>
95
- <line x1="9" y1="9" x2="15" y2="15"></line>
96
- </svg>
97
- <span class="edit-file-error-text">
98
- {errorMessage}
99
- </span>
100
- </div>
101
- </template>
102
-
103
- <!-- Content Editor -->
104
- <template lwc:if={fileContent}>
105
- <div class="edit-file-editor">
106
- <label class="edit-file-label" for="file-content">
107
- File Content
108
- </label>
109
- <textarea
110
- id="file-content"
111
- class="edit-file-textarea"
112
- oninput={handleContentChange}
113
- placeholder="Enter file content..."
114
- rows="20"
115
- spellcheck="false"
116
- ></textarea>
117
- </div>
118
- </template>
119
- </div>
120
-
121
- <!-- Popover Footer -->
122
- <div class="edit-file-footer">
123
- <div class="edit-file-status">
124
- <template lwc:if={isSaving}>
125
- <div class="edit-file-saving">
126
- <div class="edit-file-mini-spinner"></div>
127
- <span>Saving...</span>
128
- </div>
129
- </template>
130
- <template lwc:elseif={isContentUnchanged}>
131
- <span class="edit-file-unchanged">No changes</span>
132
- </template>
133
- <template lwc:else>
134
- <span class="edit-file-modified">Modified</span>
135
- </template>
136
- </div>
137
-
138
- <div class="edit-file-actions">
139
- <button
140
- class="edit-file-button edit-file-button_secondary"
141
- onclick={handleCancel}
142
- disabled={isSaving}
143
- >
144
- Cancel
145
- </button>
146
- <button
147
- class={saveButtonClass}
148
- onclick={handleSave}
149
- disabled={isSaving}
150
- >
151
- <template lwc:if={isSaving}>
152
- <div class="edit-file-button-spinner"></div>
153
- Saving...
154
- </template>
155
- <template lwc:else>Save</template>
156
- </button>
157
- </div>
158
- </div>
159
- </div>
160
- </div>
161
- </template>
162
- </template>
@@ -1,254 +0,0 @@
1
- import { LightningElement, api, track } from "lwc";
2
- import cx from "classnames";
3
- import { normalizeBoolean } from "dxUtils/normalizers";
4
-
5
- interface ApiResponse {
6
- success: boolean;
7
- data?: {
8
- content: string;
9
- };
10
- message?: string;
11
- error?: string;
12
- }
13
-
14
- export default class EditFile extends LightningElement {
15
- @api fileName: string = "";
16
- @api repoName: string = "";
17
- @api source: string = "";
18
- @api apiEndpoint: string = "/api/edit-file";
19
- @api project: string = "Edit File";
20
-
21
- @api
22
- get disabled() {
23
- return this._disabled;
24
- }
25
-
26
- set disabled(value) {
27
- this._disabled = normalizeBoolean(value);
28
- }
29
-
30
- @track isPopoverOpen: boolean = false;
31
- @track isLoading: boolean = false;
32
- @track isSaving: boolean = false;
33
- @track fileContent: string = "";
34
- @track originalContent: string = "";
35
- @track errorMessage: string = "";
36
-
37
- private _disabled: boolean = false;
38
-
39
- // API Configuration
40
- private static readonly FETCH_ENDPOINT =
41
- "https://1208ddd77328.ngrok-free.app/api/file-retrieval/retrieve";
42
- private static readonly SAVE_ENDPOINT = "/api/file/save";
43
-
44
- get popoverClass() {
45
- return cx(
46
- "edit-file-popover",
47
- this.isPopoverOpen && "edit-file-popover_open"
48
- );
49
- }
50
-
51
- get overlayClass() {
52
- return cx(
53
- "edit-file-overlay",
54
- this.isPopoverOpen && "edit-file-overlay_open"
55
- );
56
- }
57
-
58
- get saveButtonClass() {
59
- return cx(
60
- "edit-file-button",
61
- "edit-file-button_primary",
62
- (this.isSaving || this.isContentUnchanged) &&
63
- "edit-file-button_disabled"
64
- );
65
- }
66
-
67
- get isContentUnchanged() {
68
- return this.fileContent === this.originalContent;
69
- }
70
-
71
- // Open the edit file popover
72
- async handleEditClick() {
73
- if (this.disabled) {
74
- return;
75
- }
76
-
77
- this.isPopoverOpen = true;
78
- this.errorMessage = "";
79
- await this.fetchFileContent();
80
- }
81
-
82
- // Fetch file content from API
83
- private async fetchFileContent() {
84
- if (!this.fileName) {
85
- this.errorMessage = "No file specified to edit";
86
- return;
87
- }
88
-
89
- this.isLoading = true;
90
-
91
- try {
92
- const response = await fetch(EditFile.FETCH_ENDPOINT, {
93
- method: "POST",
94
- headers: {
95
- "Content-Type": "application/json"
96
- },
97
- body: JSON.stringify({
98
- source: this.source,
99
- href: this.fileName
100
- })
101
- });
102
-
103
- if (!response.ok) {
104
- throw new Error(`Failed to fetch file: ${response.status}`);
105
- }
106
-
107
- const data: ApiResponse = await response.json();
108
-
109
- if (data.success && data.data !== undefined) {
110
- this.fileContent = data.data.content;
111
- this.originalContent = data.data.content;
112
- this.errorMessage = "";
113
-
114
- // Set textarea value directly using ref
115
- this.updateTextareaValue();
116
- } else {
117
- this.errorMessage =
118
- data.error || data.message || "Failed to load file content";
119
- }
120
- } catch (error) {
121
- console.error("Error fetching file content:", error);
122
- this.errorMessage =
123
- error instanceof Error
124
- ? error.message
125
- : "Failed to connect to server";
126
- } finally {
127
- this.isLoading = false;
128
- }
129
- }
130
-
131
- // Handle content change in textarea
132
- handleContentChange(event: Event) {
133
- const target = event.target as HTMLTextAreaElement;
134
- this.fileContent = target.value;
135
- }
136
-
137
- // Handle cancel action
138
- handleCancel() {
139
- this.isPopoverOpen = false;
140
- this.fileContent = "";
141
- this.originalContent = "";
142
- this.errorMessage = "";
143
- this.isLoading = false;
144
- this.isSaving = false;
145
-
146
- // Dispatch cancel event
147
- this.dispatchEvent(
148
- new CustomEvent("editcancel", {
149
- detail: { fileName: this.fileName }
150
- })
151
- );
152
- }
153
-
154
- // Handle save action
155
- async handleSave() {
156
- if (this.isSaving || this.isContentUnchanged || this.disabled) {
157
- return;
158
- }
159
-
160
- this.isSaving = true;
161
- this.errorMessage = "";
162
-
163
- try {
164
- const response = await fetch(EditFile.SAVE_ENDPOINT, {
165
- method: "POST",
166
- headers: {
167
- "Content-Type": "application/json"
168
- },
169
- body: JSON.stringify({
170
- fileName: this.fileName,
171
- content: this.fileContent,
172
- action: "save"
173
- })
174
- });
175
-
176
- if (!response.ok) {
177
- throw new Error(`Failed to save file: ${response.status}`);
178
- }
179
-
180
- const data: ApiResponse = await response.json();
181
-
182
- if (data.success) {
183
- this.originalContent = this.fileContent;
184
- this.isPopoverOpen = false;
185
-
186
- // Dispatch success event
187
- this.dispatchEvent(
188
- new CustomEvent("editsuccess", {
189
- detail: {
190
- fileName: this.fileName,
191
- content: this.fileContent,
192
- message: data.message || "File saved successfully"
193
- }
194
- })
195
- );
196
- } else {
197
- this.errorMessage =
198
- data.error || data.message || "Failed to save file";
199
- }
200
- } catch (error) {
201
- console.error("Error saving file:", error);
202
- this.errorMessage =
203
- error instanceof Error
204
- ? error.message
205
- : "Failed to connect to server";
206
- } finally {
207
- this.isSaving = false;
208
- }
209
- }
210
-
211
- // Handle overlay click to close popover
212
- handleOverlayClick(event: Event) {
213
- if (event.target === event.currentTarget) {
214
- this.handleCancel();
215
- }
216
- }
217
-
218
- // Handle escape key to close popover
219
- handleKeyDown(event: KeyboardEvent) {
220
- if (event.key === "Escape" && this.isPopoverOpen) {
221
- this.handleCancel();
222
- }
223
- }
224
-
225
- // Update textarea value using ref
226
- private updateTextareaValue() {
227
- // Use setTimeout to ensure DOM is updated
228
- setTimeout(() => {
229
- const textarea = this.template.querySelector(
230
- "#file-content"
231
- ) as HTMLTextAreaElement;
232
- if (textarea && this.fileContent !== undefined) {
233
- textarea.value = this.fileContent;
234
- }
235
- }, 0);
236
- }
237
-
238
- connectedCallback() {
239
- // Add escape key listener
240
- document.addEventListener("keydown", this.handleKeyDown.bind(this));
241
- }
242
-
243
- renderedCallback() {
244
- // Ensure textarea value is set correctly when component renders
245
- if (this.isPopoverOpen && this.fileContent && !this.isLoading) {
246
- this.updateTextareaValue();
247
- }
248
- }
249
-
250
- disconnectedCallback() {
251
- // Remove escape key listener
252
- document.removeEventListener("keydown", this.handleKeyDown.bind(this));
253
- }
254
- }