@sanmid/flux 0.1.2 → 0.1.3

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/dist/index.d.ts CHANGED
@@ -87,10 +87,9 @@ declare function getUniqueSelector(el: Element): string;
87
87
  declare function getDirectChildSelector(parent: Element, child: Element): string;
88
88
  /**
89
89
  * Selector used for {@link PreviewEngine} rules. Verifies each candidate with
90
- * `document.querySelector(sel) === el` so previews (e.g. background) hit the
91
- * intended node; @medv/finder can occasionally produce a selector that matches
92
- * a different element. Last resort: a temporary `data-flux-preview-target` id
93
- * on the element — call {@link removePreviewTargetAttribute} when deselecting.
90
+ * `querySelectorAll(sel).length === 1` and that node is `el`, so injected rules
91
+ * cannot hit multiple elements (e.g. all `button`s). Last resort: a temporary
92
+ * `data-flux-preview-target` id — call {@link removePreviewTargetAttribute} when deselecting.
94
93
  */
95
94
  declare function getReliableSelectorForPreview(el: Element): {
96
95
  selector: string;
package/dist/index.js CHANGED
@@ -2578,9 +2578,10 @@ function getDirectChildSelector(parent, child) {
2578
2578
  return getUniqueSelector(child);
2579
2579
  }
2580
2580
  var PREVIEW_TARGET_ATTR = "data-flux-preview-target";
2581
- function selectorMatchesElement(sel, el) {
2581
+ function selectorUniquelyTargetsElement(sel, el) {
2582
2582
  try {
2583
- return document.querySelector(sel) === el;
2583
+ const all = document.querySelectorAll(sel);
2584
+ return all.length === 1 && all[0] === el;
2584
2585
  } catch {
2585
2586
  return false;
2586
2587
  }
@@ -2605,7 +2606,7 @@ function getReliableSelectorForPreview(el) {
2605
2606
  push(getDirectChildSelector(p, el));
2606
2607
  }
2607
2608
  for (const s of candidates) {
2608
- if (selectorMatchesElement(s, el)) {
2609
+ if (selectorUniquelyTargetsElement(s, el)) {
2609
2610
  return { selector: s, usedAttrFallback: false };
2610
2611
  }
2611
2612
  }