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