@pixerate/editor 0.6.0 → 0.6.1
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/extensions/index.cjs +47 -2
- package/dist/extensions/index.cjs.map +1 -1
- package/dist/extensions/index.d.cts +16 -1
- package/dist/extensions/index.d.ts +16 -1
- package/dist/extensions/index.js +46 -2
- package/dist/extensions/index.js.map +1 -1
- package/dist/index.cjs +47 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +46 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -46,6 +46,7 @@ __export(extensions_exports, {
|
|
|
46
46
|
handleImageInsertion: () => handleImageInsertion,
|
|
47
47
|
imagePastePluginKey: () => imagePastePluginKey,
|
|
48
48
|
insertImageNode: () => insertImageNode,
|
|
49
|
+
removeImageNode: () => removeImageNode,
|
|
49
50
|
updateImageSrc: () => updateImageSrc
|
|
50
51
|
});
|
|
51
52
|
module.exports = __toCommonJS(extensions_exports);
|
|
@@ -1632,6 +1633,22 @@ function updateImageSrc(view, oldSrc, newSrc) {
|
|
|
1632
1633
|
view.dispatch(tr);
|
|
1633
1634
|
}
|
|
1634
1635
|
}
|
|
1636
|
+
function removeImageNode(view, src) {
|
|
1637
|
+
const { doc } = view.state;
|
|
1638
|
+
let foundPos = null;
|
|
1639
|
+
let nodeSize = 0;
|
|
1640
|
+
doc.descendants((node, pos) => {
|
|
1641
|
+
if (node.type.name === "image" && node.attrs.src === src) {
|
|
1642
|
+
foundPos = pos;
|
|
1643
|
+
nodeSize = node.nodeSize;
|
|
1644
|
+
return false;
|
|
1645
|
+
}
|
|
1646
|
+
});
|
|
1647
|
+
if (foundPos !== null) {
|
|
1648
|
+
const tr = view.state.tr.delete(foundPos, foundPos + nodeSize);
|
|
1649
|
+
view.dispatch(tr);
|
|
1650
|
+
}
|
|
1651
|
+
}
|
|
1635
1652
|
function handleImageInsertion(view, file, options) {
|
|
1636
1653
|
if (typeof options.upload === "function") {
|
|
1637
1654
|
const hasObjectUrl = typeof URL !== "undefined" && typeof URL.createObjectURL === "function";
|
|
@@ -1640,7 +1657,9 @@ function handleImageInsertion(view, file, options) {
|
|
|
1640
1657
|
insertImageNode(view, tempUrl, file.name);
|
|
1641
1658
|
}
|
|
1642
1659
|
Promise.resolve(options.upload(file)).then((uploadedUrl) => {
|
|
1643
|
-
if (!uploadedUrl)
|
|
1660
|
+
if (!uploadedUrl) {
|
|
1661
|
+
throw new Error("Upload handler returned empty URL");
|
|
1662
|
+
}
|
|
1644
1663
|
if (tempUrl) {
|
|
1645
1664
|
updateImageSrc(view, tempUrl, uploadedUrl);
|
|
1646
1665
|
if (typeof URL.revokeObjectURL === "function") {
|
|
@@ -1650,9 +1669,32 @@ function handleImageInsertion(view, file, options) {
|
|
|
1650
1669
|
insertImageNode(view, uploadedUrl, file.name);
|
|
1651
1670
|
}
|
|
1652
1671
|
}).catch((err) => {
|
|
1653
|
-
|
|
1672
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
1673
|
+
console.error("Failed to upload pasted image:", error);
|
|
1674
|
+
if (tempUrl) {
|
|
1675
|
+
removeImageNode(view, tempUrl);
|
|
1676
|
+
if (typeof URL.revokeObjectURL === "function") {
|
|
1677
|
+
URL.revokeObjectURL(tempUrl);
|
|
1678
|
+
}
|
|
1679
|
+
}
|
|
1680
|
+
if (typeof options.onUploadError === "function") {
|
|
1681
|
+
options.onUploadError(error, file);
|
|
1682
|
+
}
|
|
1654
1683
|
});
|
|
1655
1684
|
} else if (options.allowBase64 !== false) {
|
|
1685
|
+
const maxBase64Size = options.maxBase64Size ?? 65536;
|
|
1686
|
+
if (file.size > maxBase64Size) {
|
|
1687
|
+
const err = new Error(
|
|
1688
|
+
`Image size (${Math.round(file.size / 1024)}KB) exceeds maxBase64Size (${Math.round(
|
|
1689
|
+
maxBase64Size / 1024
|
|
1690
|
+
)}KB). Provide an upload handler to support large images.`
|
|
1691
|
+
);
|
|
1692
|
+
console.warn(`[Editor] ${err.message}`);
|
|
1693
|
+
if (typeof options.onUploadError === "function") {
|
|
1694
|
+
options.onUploadError(err, file);
|
|
1695
|
+
}
|
|
1696
|
+
return;
|
|
1697
|
+
}
|
|
1656
1698
|
if (typeof FileReader !== "undefined") {
|
|
1657
1699
|
const reader = new FileReader();
|
|
1658
1700
|
reader.onload = () => {
|
|
@@ -1670,9 +1712,11 @@ var Image2 = BaseImage.extend({
|
|
|
1670
1712
|
return {
|
|
1671
1713
|
...this.parent?.(),
|
|
1672
1714
|
allowBase64: true,
|
|
1715
|
+
maxBase64Size: 65536,
|
|
1673
1716
|
enablePaste: true,
|
|
1674
1717
|
enableDrop: true,
|
|
1675
1718
|
upload: void 0,
|
|
1719
|
+
onUploadError: void 0,
|
|
1676
1720
|
HTMLAttributes: {
|
|
1677
1721
|
class: "rounded-md max-w-full h-auto my-2"
|
|
1678
1722
|
}
|
|
@@ -1886,6 +1930,7 @@ function createRichTextPreset(options = {}) {
|
|
|
1886
1930
|
handleImageInsertion,
|
|
1887
1931
|
imagePastePluginKey,
|
|
1888
1932
|
insertImageNode,
|
|
1933
|
+
removeImageNode,
|
|
1889
1934
|
updateImageSrc
|
|
1890
1935
|
});
|
|
1891
1936
|
//# sourceMappingURL=index.cjs.map
|