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/index.js
CHANGED
|
@@ -640,12 +640,15 @@ function documentOf(target) {
|
|
|
640
640
|
function isEditableNode(node) {
|
|
641
641
|
return (node.nodeType === 1 ? node : node.parentElement)?.isContentEditable === true;
|
|
642
642
|
}
|
|
643
|
-
function
|
|
644
|
-
const ranges = [];
|
|
643
|
+
function selectedRanges(doc) {
|
|
645
644
|
const selection = doc?.getSelection();
|
|
646
|
-
if (!selection || selection.isCollapsed) return
|
|
645
|
+
if (!selection || selection.isCollapsed) return null;
|
|
646
|
+
const ranges = [];
|
|
647
647
|
for (let index = 0; index < selection.rangeCount; index += 1) ranges.push(selection.getRangeAt(index));
|
|
648
|
-
return
|
|
648
|
+
return {
|
|
649
|
+
selection,
|
|
650
|
+
ranges
|
|
651
|
+
};
|
|
649
652
|
}
|
|
650
653
|
function readSelection(event) {
|
|
651
654
|
const kind = event.type === "cut" ? "cut" : "copy";
|
|
@@ -667,13 +670,13 @@ function readSelection(event) {
|
|
|
667
670
|
};
|
|
668
671
|
}
|
|
669
672
|
const doc = documentOf(event.target);
|
|
670
|
-
const
|
|
671
|
-
const
|
|
672
|
-
if (!doc || !first) return null;
|
|
673
|
-
const text =
|
|
673
|
+
const selected = selectedRanges(doc);
|
|
674
|
+
const first = selected?.ranges[0];
|
|
675
|
+
if (!doc || !selected || !first) return null;
|
|
676
|
+
const text = selected.selection.toString();
|
|
674
677
|
if (text.length === 0) return null;
|
|
675
678
|
const container = doc.createElement("div");
|
|
676
|
-
for (const range of ranges) container.appendChild(range.cloneContents());
|
|
679
|
+
for (const range of selected.ranges) container.appendChild(range.cloneContents());
|
|
677
680
|
const html = container.innerHTML;
|
|
678
681
|
const fragment = doc.createDocumentFragment();
|
|
679
682
|
while (container.firstChild) fragment.appendChild(container.firstChild);
|
|
@@ -840,7 +843,8 @@ const registries = /* @__PURE__ */ new WeakMap();
|
|
|
840
843
|
function touches(root, event) {
|
|
841
844
|
const fieldSelection = readTextField(event.target);
|
|
842
845
|
if (fieldSelection) return root.contains(fieldSelection.field);
|
|
843
|
-
|
|
846
|
+
const selected = selectedRanges(root.ownerDocument);
|
|
847
|
+
return selected !== null && selected.ranges.some((range) => range.intersectsNode(root));
|
|
844
848
|
}
|
|
845
849
|
const priorityOf = (scope) => scope.read().priority ?? 0;
|
|
846
850
|
/**
|