@salesforcedevs/docs-components 1.17.8-hover-edit → 1.17.10-hover-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/package.json
CHANGED
|
@@ -19,17 +19,26 @@ export default class TextSelectionSearch extends LightningElement {
|
|
|
19
19
|
private selectionStart: number = 0;
|
|
20
20
|
private selectionEnd: number = 0;
|
|
21
21
|
private initialPopoverStyle: string = ""; // Store initial position
|
|
22
|
+
private mutationObserver: MutationObserver | null = null;
|
|
22
23
|
|
|
23
24
|
connectedCallback() {
|
|
24
25
|
console.log('TextSelectionSearch: Component connected');
|
|
25
26
|
console.log('TextSelectionSearch: Document ready state:', document.readyState);
|
|
26
27
|
console.log('TextSelectionSearch: Current page URL:', window.location.href);
|
|
27
28
|
this.setupTextSelectionListener();
|
|
29
|
+
this.setupContentObserver();
|
|
30
|
+
|
|
31
|
+
// Additional initialization for spec-based references
|
|
32
|
+
if (this.isSpecBasedReferencePage()) {
|
|
33
|
+
console.log('TextSelectionSearch: Detected spec-based reference page, setting up additional listeners');
|
|
34
|
+
this.setupSpecBasedReferenceHandling();
|
|
35
|
+
}
|
|
28
36
|
}
|
|
29
37
|
|
|
30
38
|
disconnectedCallback() {
|
|
31
39
|
console.log('TextSelectionSearch: Component disconnected');
|
|
32
40
|
this.removeTextSelectionListener();
|
|
41
|
+
this.removeContentObserver();
|
|
33
42
|
}
|
|
34
43
|
|
|
35
44
|
// Setup text selection listener
|
|
@@ -56,6 +65,84 @@ export default class TextSelectionSearch extends LightningElement {
|
|
|
56
65
|
}
|
|
57
66
|
}
|
|
58
67
|
|
|
68
|
+
// Setup observer to detect when content is dynamically loaded
|
|
69
|
+
setupContentObserver() {
|
|
70
|
+
console.log('TextSelectionSearch: Setting up content observer');
|
|
71
|
+
try {
|
|
72
|
+
this.mutationObserver = new MutationObserver((mutations) => {
|
|
73
|
+
let shouldReinitialize = false;
|
|
74
|
+
|
|
75
|
+
for (const mutation of mutations) {
|
|
76
|
+
if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
|
|
77
|
+
// Check if any added nodes contain text content
|
|
78
|
+
for (const node of Array.from(mutation.addedNodes)) {
|
|
79
|
+
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
80
|
+
const element = node as Element;
|
|
81
|
+
|
|
82
|
+
// Check for spec-based reference content (.api-documentation)
|
|
83
|
+
if (element.classList && element.classList.contains('api-documentation')) {
|
|
84
|
+
console.log('TextSelectionSearch: Detected .api-documentation container');
|
|
85
|
+
shouldReinitialize = true;
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Check for doc-amf-topic component
|
|
90
|
+
if (element.tagName && element.tagName.toLowerCase() === 'doc-amf-topic') {
|
|
91
|
+
console.log('TextSelectionSearch: Detected doc-amf-topic component');
|
|
92
|
+
shouldReinitialize = true;
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Check for shadow DOM content in spec-based references
|
|
97
|
+
if (this.isSpecBasedReferencePage() && element.shadowRoot) {
|
|
98
|
+
console.log('TextSelectionSearch: Detected shadow DOM content');
|
|
99
|
+
shouldReinitialize = true;
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Check for common content containers
|
|
104
|
+
if (element.querySelector && (
|
|
105
|
+
element.querySelector('p, h1, h2, h3, h4, h5, h6, li, td, th, div') ||
|
|
106
|
+
element.matches('p, h1, h2, h3, h4, h5, h6, li, td, th, div')
|
|
107
|
+
)) {
|
|
108
|
+
shouldReinitialize = true;
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (shouldReinitialize) {
|
|
117
|
+
console.log('TextSelectionSearch: Content detected, reinitializing listeners');
|
|
118
|
+
// Small delay to ensure content is fully rendered
|
|
119
|
+
setTimeout(() => {
|
|
120
|
+
this.setupTextSelectionListener();
|
|
121
|
+
}, 200); // Increased delay for spec-based references
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
// Observe the entire document for content changes
|
|
126
|
+
this.mutationObserver.observe(document.body, {
|
|
127
|
+
childList: true,
|
|
128
|
+
subtree: true
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
console.log('TextSelectionSearch: Content observer set up successfully');
|
|
132
|
+
} catch (error) {
|
|
133
|
+
console.error('TextSelectionSearch: Error setting up content observer:', error);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
removeContentObserver() {
|
|
138
|
+
console.log('TextSelectionSearch: Removing content observer');
|
|
139
|
+
if (this.mutationObserver) {
|
|
140
|
+
this.mutationObserver.disconnect();
|
|
141
|
+
this.mutationObserver = null;
|
|
142
|
+
console.log('TextSelectionSearch: Content observer removed successfully');
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
59
146
|
// Handle text selection
|
|
60
147
|
handleTextSelection(event?: Event) {
|
|
61
148
|
// If popover is visible, completely ignore all text selection events
|
|
@@ -97,6 +184,31 @@ export default class TextSelectionSearch extends LightningElement {
|
|
|
97
184
|
this.selectedText = selection.toString().trim();
|
|
98
185
|
console.log('TextSelectionSearch: Selected text:', this.selectedText);
|
|
99
186
|
|
|
187
|
+
// For spec-based references, check if selection is within the API documentation container
|
|
188
|
+
if (this.isSpecBasedReferencePage()) {
|
|
189
|
+
const apiDocContainer = document.querySelector('.api-documentation');
|
|
190
|
+
if (apiDocContainer) {
|
|
191
|
+
const range = selection.getRangeAt(0);
|
|
192
|
+
const rect = range.getBoundingClientRect();
|
|
193
|
+
const containerRect = apiDocContainer.getBoundingClientRect();
|
|
194
|
+
|
|
195
|
+
// Check if the selection is within the API documentation container
|
|
196
|
+
const isWithinContainer = (
|
|
197
|
+
rect.top >= containerRect.top &&
|
|
198
|
+
rect.bottom <= containerRect.bottom &&
|
|
199
|
+
rect.left >= containerRect.left &&
|
|
200
|
+
rect.right <= containerRect.right
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
console.log('TextSelectionSearch: Selection within API container:', isWithinContainer);
|
|
204
|
+
|
|
205
|
+
if (!isWithinContainer) {
|
|
206
|
+
console.log('TextSelectionSearch: Selection outside API container, ignoring');
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
100
212
|
if (this.selectedText.length > 0) {
|
|
101
213
|
this.showPopover();
|
|
102
214
|
}
|
|
@@ -119,16 +231,60 @@ export default class TextSelectionSearch extends LightningElement {
|
|
|
119
231
|
console.log('TextSelectionSearch: Scroll position:', window.scrollX, window.scrollY);
|
|
120
232
|
console.log('TextSelectionSearch: Document height:', document.documentElement.scrollHeight);
|
|
121
233
|
|
|
234
|
+
// Check if we're on a spec-based reference page
|
|
235
|
+
const isSpecBased = this.isSpecBasedReferencePage();
|
|
236
|
+
console.log('TextSelectionSearch: Is spec-based reference:', isSpecBased);
|
|
237
|
+
|
|
122
238
|
// Calculate popover position with better positioning logic
|
|
123
239
|
let popoverTop: number;
|
|
124
|
-
|
|
240
|
+
let popoverLeft: number;
|
|
125
241
|
|
|
126
|
-
if (
|
|
127
|
-
//
|
|
128
|
-
|
|
242
|
+
if (isSpecBased) {
|
|
243
|
+
// For spec-based references, we need to account for the dynamic content structure
|
|
244
|
+
// The content might be inside shadow DOM or have different positioning
|
|
245
|
+
const apiDocContainer = document.querySelector('.api-documentation');
|
|
246
|
+
if (apiDocContainer) {
|
|
247
|
+
const containerRect = apiDocContainer.getBoundingClientRect();
|
|
248
|
+
console.log('TextSelectionSearch: API documentation container rect:', containerRect);
|
|
249
|
+
|
|
250
|
+
// Position the popover relative to the selection within the container
|
|
251
|
+
popoverLeft = Math.max(10, Math.min(window.innerWidth - 360, rect.left + (rect.width / 2) - 180));
|
|
252
|
+
|
|
253
|
+
if (this.popoverPosition === "top") {
|
|
254
|
+
// Position above the selection, but ensure it's within the container bounds
|
|
255
|
+
popoverTop = Math.max(10, rect.top - 200);
|
|
256
|
+
// If it would go above the container, position it below instead
|
|
257
|
+
if (popoverTop < containerRect.top + 10) {
|
|
258
|
+
popoverTop = Math.min(window.innerHeight - 250, rect.bottom + 20);
|
|
259
|
+
}
|
|
260
|
+
} else {
|
|
261
|
+
// Position below the selection
|
|
262
|
+
popoverTop = Math.min(window.innerHeight - 250, rect.bottom + 20);
|
|
263
|
+
// If it would go below the container, position it above instead
|
|
264
|
+
if (popoverTop > containerRect.bottom - 250) {
|
|
265
|
+
popoverTop = Math.max(10, rect.top - 200);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
} else {
|
|
269
|
+
// Fallback to standard positioning if container not found
|
|
270
|
+
popoverLeft = Math.max(10, Math.min(window.innerWidth - 360, rect.left + (rect.width / 2) - 180));
|
|
271
|
+
if (this.popoverPosition === "top") {
|
|
272
|
+
popoverTop = Math.max(10, rect.top - 200);
|
|
273
|
+
} else {
|
|
274
|
+
popoverTop = Math.min(window.innerHeight - 250, rect.bottom + 20);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
129
277
|
} else {
|
|
130
|
-
//
|
|
131
|
-
|
|
278
|
+
// Standard positioning for markdown-based references
|
|
279
|
+
popoverLeft = Math.max(10, Math.min(window.innerWidth - 360, rect.left + (rect.width / 2) - 180));
|
|
280
|
+
|
|
281
|
+
if (this.popoverPosition === "top") {
|
|
282
|
+
// Position above the selection
|
|
283
|
+
popoverTop = Math.max(10, rect.top - 200); // 200px above selection
|
|
284
|
+
} else {
|
|
285
|
+
// Position below the selection
|
|
286
|
+
popoverTop = Math.min(window.innerHeight - 250, rect.bottom + 20);
|
|
287
|
+
}
|
|
132
288
|
}
|
|
133
289
|
|
|
134
290
|
// Ensure the popover doesn't go off-screen
|
|
@@ -277,4 +433,64 @@ export default class TextSelectionSearch extends LightningElement {
|
|
|
277
433
|
get searchButtonDisabled() {
|
|
278
434
|
return this.isLoading || !this.searchQuery.trim();
|
|
279
435
|
}
|
|
436
|
+
|
|
437
|
+
// Find text content within shadow DOM elements
|
|
438
|
+
findTextInShadowDOM(element: Element): boolean {
|
|
439
|
+
// Check if element has shadow root
|
|
440
|
+
if (element.shadowRoot) {
|
|
441
|
+
const shadowContent = element.shadowRoot.querySelector('p, h1, h2, h3, h4, h5, h6, li, td, th, div, span');
|
|
442
|
+
if (shadowContent) {
|
|
443
|
+
console.log('TextSelectionSearch: Found content in shadow DOM');
|
|
444
|
+
return true;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
// Recursively check child elements
|
|
449
|
+
for (const child of Array.from(element.children)) {
|
|
450
|
+
if (this.findTextInShadowDOM(child)) {
|
|
451
|
+
return true;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
return false;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
// Check if current page is a spec-based reference
|
|
459
|
+
isSpecBasedReferencePage(): boolean {
|
|
460
|
+
const url = window.location.href;
|
|
461
|
+
const hasMetaParam = url.includes('?meta=');
|
|
462
|
+
const isReferencePage = url.includes('/references/');
|
|
463
|
+
console.log('TextSelectionSearch: URL analysis - hasMetaParam:', hasMetaParam, 'isReferencePage:', isReferencePage);
|
|
464
|
+
return hasMetaParam && isReferencePage;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
// Additional setup for spec-based references
|
|
468
|
+
setupSpecBasedReferenceHandling() {
|
|
469
|
+
// Wait for the page to be fully loaded
|
|
470
|
+
if (document.readyState === 'loading') {
|
|
471
|
+
document.addEventListener('DOMContentLoaded', () => {
|
|
472
|
+
this.initializeForSpecBasedReference();
|
|
473
|
+
});
|
|
474
|
+
} else {
|
|
475
|
+
this.initializeForSpecBasedReference();
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
initializeForSpecBasedReference() {
|
|
480
|
+
console.log('TextSelectionSearch: Initializing for spec-based reference');
|
|
481
|
+
|
|
482
|
+
// Wait for the .api-documentation container to appear
|
|
483
|
+
const checkForApiDocumentation = () => {
|
|
484
|
+
const apiDocContainer = document.querySelector('.api-documentation');
|
|
485
|
+
if (apiDocContainer) {
|
|
486
|
+
console.log('TextSelectionSearch: Found .api-documentation container, setting up listeners');
|
|
487
|
+
this.setupTextSelectionListener();
|
|
488
|
+
} else {
|
|
489
|
+
console.log('TextSelectionSearch: .api-documentation container not found yet, retrying...');
|
|
490
|
+
setTimeout(checkForApiDocumentation, 500);
|
|
491
|
+
}
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
checkForApiDocumentation();
|
|
495
|
+
}
|
|
280
496
|
}
|