@salesforcedevs/docs-components 1.17.6-hover-edit → 1.17.6-redoc2

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,236 +0,0 @@
1
- import { LightningElement, api, track } from "lwc";
2
-
3
- export default class TextSelectionSearch extends LightningElement {
4
- @api searchApiUrl = "";
5
- @api repoUrl = "";
6
- @api placeholder = "Search for...";
7
- @api popoverPosition = "top";
8
- @api maxResults = 10;
9
-
10
- @track isVisible = false;
11
- @track isHidden = false;
12
- @track searchQuery = "";
13
- @track isLoading = false;
14
- @track isSuccess = false;
15
- @track errorMessage = "";
16
- @track popoverStyle = "";
17
-
18
- selectedText = "";
19
- selectionStart = 0;
20
- selectionEnd = 0;
21
- initialPopoverStyle = "";
22
-
23
- connectedCallback() {
24
- this.setupTextSelectionListener();
25
- }
26
-
27
- disconnectedCallback() {
28
- this.removeTextSelectionListener();
29
- }
30
-
31
- setupTextSelectionListener() {
32
- console.log('TextSelectionSearch: Setting up text selection listeners');
33
- document.addEventListener("mouseup", (event) => this.handleTextSelection(event));
34
- document.addEventListener("keyup", (event) => this.handleTextSelection(event));
35
- }
36
-
37
- removeTextSelectionListener() {
38
- console.log('TextSelectionSearch: Removing text selection listeners');
39
- document.removeEventListener("mouseup", (event) => this.handleTextSelection(event));
40
- document.removeEventListener("keyup", (event) => this.handleTextSelection(event));
41
- }
42
-
43
- handleTextSelection(event) {
44
- if (this.isVisible) {
45
- console.log('TextSelectionSearch: Popover is visible, ignoring text selection event');
46
- return;
47
- }
48
-
49
- console.log('TextSelectionSearch: Text selection event triggered');
50
-
51
- if (event && event.target) {
52
- const target = event.target;
53
- const popover = this.template.querySelector('.text-selection-search-popover');
54
- if (popover && popover.contains(target)) {
55
- console.log('TextSelectionSearch: Click inside popover, ignoring selection event');
56
- return;
57
- }
58
- }
59
-
60
- const selection = window.getSelection();
61
-
62
- if (!selection || selection.toString().trim() === "") {
63
- if (this.isVisible) {
64
- console.log('TextSelectionSearch: No text selected, but popover is visible - keeping it open');
65
- return;
66
- }
67
- console.log('TextSelectionSearch: No text selected, hiding popover');
68
- this.hidePopover();
69
- return;
70
- }
71
-
72
- this.selectedText = selection.toString().trim();
73
- console.log('TextSelectionSearch: Selected text:', this.selectedText);
74
-
75
- if (this.selectedText.length > 0) {
76
- this.showPopover();
77
- }
78
- }
79
-
80
- showPopover() {
81
- console.log('TextSelectionSearch: Showing popover');
82
- const selection = window.getSelection();
83
- if (!selection || selection.rangeCount === 0) {
84
- console.log('TextSelectionSearch: No selection range found');
85
- return;
86
- }
87
-
88
- const range = selection.getRangeAt(0);
89
- const rect = range.getBoundingClientRect();
90
-
91
- const popoverTop = this.popoverPosition === "top"
92
- ? Math.max(10, rect.top - 80)
93
- : Math.min(window.innerHeight - 200, rect.bottom + 20);
94
-
95
- const popoverLeft = Math.max(10, Math.min(window.innerWidth - 350, rect.left + (rect.width / 2) - 175));
96
-
97
- this.popoverStyle = `position: fixed; top: ${popoverTop}px; left: ${popoverLeft}px; z-index: 9999; width: 350px;`;
98
- this.initialPopoverStyle = this.popoverStyle;
99
- console.log('TextSelectionSearch: Popover style:', this.popoverStyle);
100
-
101
- this.isVisible = true;
102
- this.isHidden = false;
103
- this.searchQuery = this.selectedText;
104
- this.errorMessage = "";
105
- this.isSuccess = false;
106
-
107
- console.log('TextSelectionSearch: Popover should now be visible');
108
- }
109
-
110
- hidePopover() {
111
- console.log('TextSelectionSearch: Hiding popover');
112
- this.isHidden = true;
113
-
114
- setTimeout(() => {
115
- this.isVisible = false;
116
- this.searchQuery = "";
117
- this.errorMessage = "";
118
- this.isSuccess = false;
119
- this.popoverStyle = "";
120
- this.initialPopoverStyle = "";
121
-
122
- const selection = window.getSelection();
123
- if (selection) {
124
- selection.removeAllRanges();
125
- }
126
- }, 100);
127
- }
128
-
129
- handlePopoverClick(event) {
130
- event.stopPropagation();
131
- }
132
-
133
- handleInputClick(event) {
134
- event.stopPropagation();
135
- }
136
-
137
- handleSearchInputChange(event) {
138
- const target = event.target;
139
- this.searchQuery = target.value;
140
- }
141
-
142
- async handleSearchSubmit(event) {
143
- event.preventDefault();
144
-
145
- if (!this.searchQuery.trim()) {
146
- this.errorMessage = "Please enter edited text";
147
- return;
148
- }
149
-
150
- if (!this.repoUrl.trim()) {
151
- this.errorMessage = "Repository URL not configured";
152
- return;
153
- }
154
-
155
- if (!this.searchApiUrl) {
156
- this.errorMessage = "Search API URL not configured";
157
- return;
158
- }
159
-
160
- await this.performSearch();
161
- }
162
-
163
- async performSearch() {
164
- this.isLoading = true;
165
- this.errorMessage = "";
166
- this.isSuccess = false;
167
-
168
- try {
169
- const response = await fetch(this.searchApiUrl, {
170
- method: "POST",
171
- headers: {
172
- "Content-Type": "application/json"
173
- },
174
- body: JSON.stringify({
175
- repoUrl: this.repoUrl,
176
- selectedText: this.selectedText,
177
- editedText: this.searchQuery
178
- })
179
- });
180
-
181
- if (response.ok) {
182
- this.isSuccess = true;
183
-
184
- this.dispatchEvent(
185
- new CustomEvent("textedited", {
186
- detail: {
187
- repoUrl: this.repoUrl,
188
- selectedText: this.selectedText,
189
- editedText: this.searchQuery,
190
- success: true
191
- }
192
- })
193
- );
194
-
195
- setTimeout(() => {
196
- this.hidePopover();
197
- }, 2000);
198
- } else {
199
- throw new Error(`Edit failed: ${response.status}`);
200
- }
201
- } catch (error) {
202
- console.error("Edit failed:", error);
203
- this.errorMessage = "Edit failed. Please try again.";
204
- } finally {
205
- this.isLoading = false;
206
- }
207
- }
208
-
209
- handleKeyDown(event) {
210
- if (event.key === "Escape") {
211
- this.hidePopover();
212
- }
213
- }
214
-
215
- get hasError() {
216
- return this.errorMessage.length > 0;
217
- }
218
-
219
- get searchButtonDisabled() {
220
- return this.isLoading || !this.searchQuery.trim();
221
- }
222
-
223
- renderedCallback() {
224
- if (this.isVisible && this.initialPopoverStyle) {
225
- const popover = this.template.querySelector('.text-selection-search-popover');
226
- if (popover) {
227
- popover.style.cssText = this.initialPopoverStyle;
228
- }
229
- } else if (!this.isVisible) {
230
- const popover = this.template.querySelector('.text-selection-search-popover');
231
- if (popover) {
232
- popover.style.cssText = '';
233
- }
234
- }
235
- }
236
- }
@@ -1,257 +0,0 @@
1
- import { LightningElement, api, track } from "lwc";
2
-
3
- export default class TextSelectionSearch extends LightningElement {
4
- @api searchApiUrl: string = "";
5
- @api repoUrl: string = "";
6
- @api placeholder: string = "Search for...";
7
- @api popoverPosition: "top" | "bottom" = "top";
8
- @api maxResults: number = 10;
9
-
10
- @track isVisible: boolean = false;
11
- @track isHidden: boolean = false;
12
- @track searchQuery: string = "";
13
- @track isLoading: boolean = false;
14
- @track isSuccess: boolean = false;
15
- @track errorMessage: string = "";
16
- @track popoverStyle: string = "";
17
-
18
- private selectedText: string = "";
19
- private selectionStart: number = 0;
20
- private selectionEnd: number = 0;
21
- private initialPopoverStyle: string = ""; // Store initial position
22
-
23
- connectedCallback() {
24
- this.setupTextSelectionListener();
25
- }
26
-
27
- disconnectedCallback() {
28
- this.removeTextSelectionListener();
29
- }
30
-
31
- // Setup text selection listener
32
- setupTextSelectionListener() {
33
- console.log('TextSelectionSearch: Setting up text selection listeners');
34
- document.addEventListener("mouseup", (event) => this.handleTextSelection(event));
35
- document.addEventListener("keyup", (event) => this.handleTextSelection(event));
36
- }
37
-
38
- removeTextSelectionListener() {
39
- console.log('TextSelectionSearch: Removing text selection listeners');
40
- document.removeEventListener("mouseup", (event) => this.handleTextSelection(event));
41
- document.removeEventListener("keyup", (event) => this.handleTextSelection(event));
42
- }
43
-
44
- // Handle text selection
45
- handleTextSelection(event?: Event) {
46
- // If popover is visible, completely ignore all text selection events
47
- if (this.isVisible) {
48
- console.log('TextSelectionSearch: Popover is visible, ignoring text selection event');
49
- return;
50
- }
51
-
52
- console.log('TextSelectionSearch: Text selection event triggered');
53
-
54
- // Check if the event target is inside our popover
55
- if (event && event.target) {
56
- const target = event.target as Element;
57
- const popover = this.template.querySelector('.text-selection-search-popover');
58
- if (popover && popover.contains(target)) {
59
- console.log('TextSelectionSearch: Click inside popover, ignoring selection event');
60
- return;
61
- }
62
- }
63
-
64
- const selection = window.getSelection();
65
-
66
- if (!selection || selection.toString().trim() === "") {
67
- // Only hide popover if it's currently visible and we're not clicking inside it
68
- if (this.isVisible) {
69
- console.log('TextSelectionSearch: No text selected, but popover is visible - keeping it open');
70
- return;
71
- }
72
- console.log('TextSelectionSearch: No text selected, hiding popover');
73
- this.hidePopover();
74
- return;
75
- }
76
-
77
- this.selectedText = selection.toString().trim();
78
- console.log('TextSelectionSearch: Selected text:', this.selectedText);
79
-
80
- if (this.selectedText.length > 0) {
81
- this.showPopover();
82
- }
83
- }
84
-
85
- // Show popover at selection position
86
- showPopover() {
87
- console.log('TextSelectionSearch: Showing popover');
88
- const selection = window.getSelection();
89
- if (!selection || selection.rangeCount === 0) {
90
- console.log('TextSelectionSearch: No selection range found');
91
- return;
92
- }
93
-
94
- const range = selection.getRangeAt(0);
95
- const rect = range.getBoundingClientRect();
96
-
97
- // Calculate popover position with more conservative positioning
98
- const popoverTop = this.popoverPosition === "top"
99
- ? Math.max(10, rect.top - 80) // Ensure it doesn't go off-screen
100
- : Math.min(window.innerHeight - 200, rect.bottom + 20);
101
-
102
- const popoverLeft = Math.max(10, Math.min(window.innerWidth - 350, rect.left + (rect.width / 2) - 175));
103
-
104
- this.popoverStyle = `position: fixed; top: ${popoverTop}px; left: ${popoverLeft}px; z-index: 9999; width: 350px;`;
105
- this.initialPopoverStyle = this.popoverStyle; // Store the initial position
106
- console.log('TextSelectionSearch: Popover style:', this.popoverStyle);
107
-
108
- this.isVisible = true;
109
- this.isHidden = false;
110
- this.searchQuery = this.selectedText;
111
- this.errorMessage = "";
112
- this.isSuccess = false;
113
-
114
- console.log('TextSelectionSearch: Popover should now be visible');
115
- }
116
-
117
- // Hide popover
118
- hidePopover() {
119
- console.log('TextSelectionSearch: Hiding popover');
120
- this.isHidden = true;
121
-
122
- // Use setTimeout to ensure the hidden class is applied before hiding
123
- setTimeout(() => {
124
- this.isVisible = false;
125
- this.searchQuery = "";
126
- this.errorMessage = "";
127
- this.isSuccess = false;
128
- this.popoverStyle = ""; // Reset the positioning style
129
- this.initialPopoverStyle = ""; // Reset the initial position
130
-
131
- // Clear any text selection to prevent immediate re-showing
132
- const selection = window.getSelection();
133
- if (selection) {
134
- selection.removeAllRanges();
135
- }
136
- }, 100);
137
- }
138
-
139
- // Handle popover click to prevent closing
140
- handlePopoverClick(event: Event) {
141
- event.stopPropagation();
142
- }
143
-
144
- // Handle input click to prevent closing
145
- handleInputClick(event: Event) {
146
- event.stopPropagation();
147
- }
148
-
149
- // Handle search input change
150
- handleSearchInputChange(event: Event) {
151
- const target = event.target as HTMLInputElement;
152
- this.searchQuery = target.value;
153
- }
154
-
155
- // Handle search submission
156
- async handleSearchSubmit(event: Event) {
157
- event.preventDefault();
158
-
159
- if (!this.searchQuery.trim()) {
160
- this.errorMessage = "Please enter edited text";
161
- return;
162
- }
163
-
164
- if (!this.repoUrl.trim()) {
165
- this.errorMessage = "Repository URL not configured";
166
- return;
167
- }
168
-
169
- if (!this.searchApiUrl) {
170
- this.errorMessage = "Search API URL not configured";
171
- return;
172
- }
173
-
174
- await this.performSearch();
175
- }
176
-
177
- // Perform search API call
178
- async performSearch() {
179
- this.isLoading = true;
180
- this.errorMessage = "";
181
- this.isSuccess = false;
182
-
183
- try {
184
- const response = await fetch(this.searchApiUrl, {
185
- method: "POST",
186
- headers: {
187
- "Content-Type": "application/json"
188
- },
189
- body: JSON.stringify({
190
- repoUrl: this.repoUrl,
191
- selectedText: this.selectedText,
192
- editedText: this.searchQuery
193
- })
194
- });
195
-
196
- if (response.ok) {
197
- this.isSuccess = true;
198
-
199
- // Dispatch success event
200
- this.dispatchEvent(
201
- new CustomEvent("textedited", {
202
- detail: {
203
- repoUrl: this.repoUrl,
204
- selectedText: this.selectedText,
205
- editedText: this.searchQuery,
206
- success: true
207
- }
208
- })
209
- );
210
-
211
- // Auto-hide popover after success
212
- setTimeout(() => {
213
- this.hidePopover();
214
- }, 2000);
215
- } else {
216
- throw new Error(`Edit failed: ${response.status}`);
217
- }
218
- } catch (error) {
219
- console.error("Edit failed:", error);
220
- this.errorMessage = "Edit failed. Please try again.";
221
- } finally {
222
- this.isLoading = false;
223
- }
224
- }
225
-
226
- // Handle escape key
227
- handleKeyDown(event: KeyboardEvent) {
228
- if (event.key === "Escape") {
229
- this.hidePopover();
230
- }
231
- }
232
-
233
- // Getters for UI state
234
- get hasError() {
235
- return this.errorMessage.length > 0;
236
- }
237
-
238
- get searchButtonDisabled() {
239
- return this.isLoading || !this.searchQuery.trim();
240
- }
241
-
242
- renderedCallback() {
243
- if (this.isVisible && this.initialPopoverStyle) {
244
- const popover = this.template.querySelector('.text-selection-search-popover') as HTMLElement;
245
- if (popover) {
246
- // Always use the initial position, never recalculate
247
- popover.style.cssText = this.initialPopoverStyle;
248
- }
249
- } else if (!this.isVisible) {
250
- // Clear the style when popover is hidden
251
- const popover = this.template.querySelector('.text-selection-search-popover') as HTMLElement;
252
- if (popover) {
253
- popover.style.cssText = '';
254
- }
255
- }
256
- }
257
- }