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/README.md
CHANGED
|
@@ -729,7 +729,7 @@ Full history: [CHANGELOG.md](./CHANGELOG.md) or the [Releases page](https://supr
|
|
|
729
729
|
|
|
730
730
|
```bash
|
|
731
731
|
npm install
|
|
732
|
-
npm run verify # lint, types,
|
|
732
|
+
npm run verify # lint, types, 568 tests at 100% coverage, build, publint + attw, size budgets
|
|
733
733
|
npm run changeset # describe your change for the changelog
|
|
734
734
|
npm run site:preview # docs site at http://localhost:3000
|
|
735
735
|
```
|
|
@@ -740,3 +740,7 @@ trusted publishing with provenance. No long-lived npm token is stored in the rep
|
|
|
740
740
|
## License
|
|
741
741
|
|
|
742
742
|
MIT
|
|
743
|
+
|
|
744
|
+
---
|
|
745
|
+
|
|
746
|
+
<p align="center">Made with ❤️ from 🇮🇳</p>
|
package/dist/core.cjs
CHANGED
|
@@ -638,12 +638,15 @@ function documentOf(target) {
|
|
|
638
638
|
function isEditableNode(node) {
|
|
639
639
|
return (node.nodeType === 1 ? node : node.parentElement)?.isContentEditable === true;
|
|
640
640
|
}
|
|
641
|
-
function
|
|
642
|
-
const ranges = [];
|
|
641
|
+
function selectedRanges(doc) {
|
|
643
642
|
const selection = doc?.getSelection();
|
|
644
|
-
if (!selection || selection.isCollapsed) return
|
|
643
|
+
if (!selection || selection.isCollapsed) return null;
|
|
644
|
+
const ranges = [];
|
|
645
645
|
for (let index = 0; index < selection.rangeCount; index += 1) ranges.push(selection.getRangeAt(index));
|
|
646
|
-
return
|
|
646
|
+
return {
|
|
647
|
+
selection,
|
|
648
|
+
ranges
|
|
649
|
+
};
|
|
647
650
|
}
|
|
648
651
|
function readSelection(event) {
|
|
649
652
|
const kind = event.type === "cut" ? "cut" : "copy";
|
|
@@ -665,13 +668,13 @@ function readSelection(event) {
|
|
|
665
668
|
};
|
|
666
669
|
}
|
|
667
670
|
const doc = documentOf(event.target);
|
|
668
|
-
const
|
|
669
|
-
const
|
|
670
|
-
if (!doc || !first) return null;
|
|
671
|
-
const text =
|
|
671
|
+
const selected = selectedRanges(doc);
|
|
672
|
+
const first = selected?.ranges[0];
|
|
673
|
+
if (!doc || !selected || !first) return null;
|
|
674
|
+
const text = selected.selection.toString();
|
|
672
675
|
if (text.length === 0) return null;
|
|
673
676
|
const container = doc.createElement("div");
|
|
674
|
-
for (const range of ranges) container.appendChild(range.cloneContents());
|
|
677
|
+
for (const range of selected.ranges) container.appendChild(range.cloneContents());
|
|
675
678
|
const html = container.innerHTML;
|
|
676
679
|
const fragment = doc.createDocumentFragment();
|
|
677
680
|
while (container.firstChild) fragment.appendChild(container.firstChild);
|
|
@@ -838,7 +841,8 @@ const registries = /* @__PURE__ */ new WeakMap();
|
|
|
838
841
|
function touches(root, event) {
|
|
839
842
|
const fieldSelection = readTextField(event.target);
|
|
840
843
|
if (fieldSelection) return root.contains(fieldSelection.field);
|
|
841
|
-
|
|
844
|
+
const selected = selectedRanges(root.ownerDocument);
|
|
845
|
+
return selected !== null && selected.ranges.some((range) => range.intersectsNode(root));
|
|
842
846
|
}
|
|
843
847
|
const priorityOf = (scope) => scope.read().priority ?? 0;
|
|
844
848
|
/**
|