@salesforcedevs/docs-components 1.17.10-hover-edit → 1.17.11-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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/docs-components",
3
- "version": "1.17.10-hover-edit",
3
+ "version": "1.17.11-hover-edit",
4
4
  "description": "Docs Lightning web components for DSC",
5
5
  "license": "MIT",
6
6
  "main": "index.js",
@@ -20,6 +20,8 @@ export default class TextSelectionSearch extends LightningElement {
20
20
  private selectionEnd: number = 0;
21
21
  private initialPopoverStyle: string = ""; // Store initial position
22
22
  private mutationObserver: MutationObserver | null = null;
23
+ private lastMouseX: number = 0;
24
+ private lastMouseY: number = 0;
23
25
 
24
26
  connectedCallback() {
25
27
  console.log('TextSelectionSearch: Component connected');
@@ -46,7 +48,11 @@ export default class TextSelectionSearch extends LightningElement {
46
48
  console.log('TextSelectionSearch: Setting up text selection listeners');
47
49
  try {
48
50
  // Use capture phase to ensure we get the events
49
- document.addEventListener("mouseup", (event) => this.handleTextSelection(event), true);
51
+ document.addEventListener("mouseup", (event) => {
52
+ this.lastMouseX = event.clientX;
53
+ this.lastMouseY = event.clientY;
54
+ this.handleTextSelection(event);
55
+ }, true);
50
56
  document.addEventListener("keyup", (event) => this.handleTextSelection(event), true);
51
57
  console.log('TextSelectionSearch: Event listeners attached successfully');
52
58
  } catch (error) {
@@ -223,68 +229,28 @@ export default class TextSelectionSearch extends LightningElement {
223
229
  return;
224
230
  }
225
231
 
226
- const range = selection.getRangeAt(0);
227
- const rect = range.getBoundingClientRect();
228
-
232
+ // Use a simpler, more reliable positioning approach
233
+ const rect = selection.getRangeAt(0).getBoundingClientRect();
229
234
  console.log('TextSelectionSearch: Selection rect:', rect);
230
- console.log('TextSelectionSearch: Window dimensions:', window.innerWidth, window.innerHeight);
231
- console.log('TextSelectionSearch: Scroll position:', window.scrollX, window.scrollY);
232
- console.log('TextSelectionSearch: Document height:', document.documentElement.scrollHeight);
233
235
 
234
236
  // Check if we're on a spec-based reference page
235
237
  const isSpecBased = this.isSpecBasedReferencePage();
236
238
  console.log('TextSelectionSearch: Is spec-based reference:', isSpecBased);
237
239
 
238
- // Calculate popover position with better positioning logic
240
+ // Use mouse position as fallback for better positioning
241
+ const mouseX = this.lastMouseX || rect.left + rect.width / 2;
242
+ const mouseY = this.lastMouseY || rect.top;
243
+
244
+ console.log('TextSelectionSearch: Using mouse position:', mouseX, mouseY);
245
+
246
+ // Calculate popover position
247
+ const popoverLeft = Math.max(10, Math.min(window.innerWidth - 360, mouseX - 175)); // Center on mouse
239
248
  let popoverTop: number;
240
- let popoverLeft: number;
241
249
 
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
- }
250
+ if (this.popoverPosition === "top") {
251
+ popoverTop = Math.max(10, mouseY - 220); // Above mouse cursor
277
252
  } else {
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
- }
253
+ popoverTop = Math.min(window.innerHeight - 250, mouseY + 20); // Below mouse cursor
288
254
  }
289
255
 
290
256
  // Ensure the popover doesn't go off-screen
@@ -295,10 +261,15 @@ export default class TextSelectionSearch extends LightningElement {
295
261
  popoverTop = window.innerHeight - 250;
296
262
  }
297
263
 
298
- this.popoverStyle = `position: fixed; top: ${popoverTop}px; left: ${popoverLeft}px; z-index: 9999; width: 350px;`;
299
- this.initialPopoverStyle = this.popoverStyle; // Store the initial position
300
- console.log('TextSelectionSearch: Popover style:', this.popoverStyle);
301
- console.log('TextSelectionSearch: Calculated position - top:', popoverTop, 'left:', popoverLeft);
264
+ this.setPopoverPosition(popoverTop, popoverLeft);
265
+ }
266
+
267
+ // Set the popover position and show it
268
+ setPopoverPosition(top: number, left: number) {
269
+ this.popoverStyle = `position: fixed; top: ${top}px; left: ${left}px; z-index: 9999; width: 350px;`;
270
+ this.initialPopoverStyle = this.popoverStyle;
271
+ console.log('TextSelectionSearch: Final popover style:', this.popoverStyle);
272
+ console.log('TextSelectionSearch: Final position - top:', top, 'left:', left);
302
273
 
303
274
  this.isVisible = true;
304
275
  this.isHidden = false;
@@ -434,27 +405,6 @@ export default class TextSelectionSearch extends LightningElement {
434
405
  return this.isLoading || !this.searchQuery.trim();
435
406
  }
436
407
 
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
408
  // Check if current page is a spec-based reference
459
409
  isSpecBasedReferencePage(): boolean {
460
410
  const url = window.location.href;