react-smart-copy 1.7.0 → 1.7.2
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/README.md +5 -1
- package/dist/core.cjs +14 -10
- package/dist/core.cjs.map +1 -1
- package/dist/core.js +14 -10
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +14 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +14 -10
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/core.js
CHANGED
|
@@ -637,12 +637,15 @@ function documentOf(target) {
|
|
|
637
637
|
function isEditableNode(node) {
|
|
638
638
|
return (node.nodeType === 1 ? node : node.parentElement)?.isContentEditable === true;
|
|
639
639
|
}
|
|
640
|
-
function
|
|
641
|
-
const ranges = [];
|
|
640
|
+
function selectedRanges(doc) {
|
|
642
641
|
const selection = doc?.getSelection();
|
|
643
|
-
if (!selection || selection.isCollapsed) return
|
|
642
|
+
if (!selection || selection.isCollapsed) return null;
|
|
643
|
+
const ranges = [];
|
|
644
644
|
for (let index = 0; index < selection.rangeCount; index += 1) ranges.push(selection.getRangeAt(index));
|
|
645
|
-
return
|
|
645
|
+
return {
|
|
646
|
+
selection,
|
|
647
|
+
ranges
|
|
648
|
+
};
|
|
646
649
|
}
|
|
647
650
|
function readSelection(event) {
|
|
648
651
|
const kind = event.type === "cut" ? "cut" : "copy";
|
|
@@ -664,13 +667,13 @@ function readSelection(event) {
|
|
|
664
667
|
};
|
|
665
668
|
}
|
|
666
669
|
const doc = documentOf(event.target);
|
|
667
|
-
const
|
|
668
|
-
const
|
|
669
|
-
if (!doc || !first) return null;
|
|
670
|
-
const text =
|
|
670
|
+
const selected = selectedRanges(doc);
|
|
671
|
+
const first = selected?.ranges[0];
|
|
672
|
+
if (!doc || !selected || !first) return null;
|
|
673
|
+
const text = selected.selection.toString();
|
|
671
674
|
if (text.length === 0) return null;
|
|
672
675
|
const container = doc.createElement("div");
|
|
673
|
-
for (const range of ranges) container.appendChild(range.cloneContents());
|
|
676
|
+
for (const range of selected.ranges) container.appendChild(range.cloneContents());
|
|
674
677
|
const html = container.innerHTML;
|
|
675
678
|
const fragment = doc.createDocumentFragment();
|
|
676
679
|
while (container.firstChild) fragment.appendChild(container.firstChild);
|
|
@@ -837,7 +840,8 @@ const registries = /* @__PURE__ */ new WeakMap();
|
|
|
837
840
|
function touches(root, event) {
|
|
838
841
|
const fieldSelection = readTextField(event.target);
|
|
839
842
|
if (fieldSelection) return root.contains(fieldSelection.field);
|
|
840
|
-
|
|
843
|
+
const selected = selectedRanges(root.ownerDocument);
|
|
844
|
+
return selected !== null && selected.ranges.some((range) => range.intersectsNode(root));
|
|
841
845
|
}
|
|
842
846
|
const priorityOf = (scope) => scope.read().priority ?? 0;
|
|
843
847
|
/**
|