@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
package/dist/index.cjs
CHANGED
|
@@ -76,6 +76,7 @@ __export(src_exports, {
|
|
|
76
76
|
parseFormula: () => parseFormula,
|
|
77
77
|
parseRange: () => parseRange,
|
|
78
78
|
plainTextToTipTapHtml: () => plainTextToTipTapHtml,
|
|
79
|
+
removeImageNode: () => removeImageNode,
|
|
79
80
|
resolveTemplates: () => resolveTemplates,
|
|
80
81
|
resolveTemplatesWithMapping: () => resolveTemplatesWithMapping,
|
|
81
82
|
resolveVariables: () => resolveVariables,
|
|
@@ -2003,6 +2004,22 @@ function updateImageSrc(view, oldSrc, newSrc) {
|
|
|
2003
2004
|
view.dispatch(tr);
|
|
2004
2005
|
}
|
|
2005
2006
|
}
|
|
2007
|
+
function removeImageNode(view, src) {
|
|
2008
|
+
const { doc } = view.state;
|
|
2009
|
+
let foundPos = null;
|
|
2010
|
+
let nodeSize = 0;
|
|
2011
|
+
doc.descendants((node, pos) => {
|
|
2012
|
+
if (node.type.name === "image" && node.attrs.src === src) {
|
|
2013
|
+
foundPos = pos;
|
|
2014
|
+
nodeSize = node.nodeSize;
|
|
2015
|
+
return false;
|
|
2016
|
+
}
|
|
2017
|
+
});
|
|
2018
|
+
if (foundPos !== null) {
|
|
2019
|
+
const tr = view.state.tr.delete(foundPos, foundPos + nodeSize);
|
|
2020
|
+
view.dispatch(tr);
|
|
2021
|
+
}
|
|
2022
|
+
}
|
|
2006
2023
|
function handleImageInsertion(view, file, options) {
|
|
2007
2024
|
if (typeof options.upload === "function") {
|
|
2008
2025
|
const hasObjectUrl = typeof URL !== "undefined" && typeof URL.createObjectURL === "function";
|
|
@@ -2011,7 +2028,9 @@ function handleImageInsertion(view, file, options) {
|
|
|
2011
2028
|
insertImageNode(view, tempUrl, file.name);
|
|
2012
2029
|
}
|
|
2013
2030
|
Promise.resolve(options.upload(file)).then((uploadedUrl) => {
|
|
2014
|
-
if (!uploadedUrl)
|
|
2031
|
+
if (!uploadedUrl) {
|
|
2032
|
+
throw new Error("Upload handler returned empty URL");
|
|
2033
|
+
}
|
|
2015
2034
|
if (tempUrl) {
|
|
2016
2035
|
updateImageSrc(view, tempUrl, uploadedUrl);
|
|
2017
2036
|
if (typeof URL.revokeObjectURL === "function") {
|
|
@@ -2021,9 +2040,32 @@ function handleImageInsertion(view, file, options) {
|
|
|
2021
2040
|
insertImageNode(view, uploadedUrl, file.name);
|
|
2022
2041
|
}
|
|
2023
2042
|
}).catch((err) => {
|
|
2024
|
-
|
|
2043
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
2044
|
+
console.error("Failed to upload pasted image:", error);
|
|
2045
|
+
if (tempUrl) {
|
|
2046
|
+
removeImageNode(view, tempUrl);
|
|
2047
|
+
if (typeof URL.revokeObjectURL === "function") {
|
|
2048
|
+
URL.revokeObjectURL(tempUrl);
|
|
2049
|
+
}
|
|
2050
|
+
}
|
|
2051
|
+
if (typeof options.onUploadError === "function") {
|
|
2052
|
+
options.onUploadError(error, file);
|
|
2053
|
+
}
|
|
2025
2054
|
});
|
|
2026
2055
|
} else if (options.allowBase64 !== false) {
|
|
2056
|
+
const maxBase64Size = options.maxBase64Size ?? 65536;
|
|
2057
|
+
if (file.size > maxBase64Size) {
|
|
2058
|
+
const err = new Error(
|
|
2059
|
+
`Image size (${Math.round(file.size / 1024)}KB) exceeds maxBase64Size (${Math.round(
|
|
2060
|
+
maxBase64Size / 1024
|
|
2061
|
+
)}KB). Provide an upload handler to support large images.`
|
|
2062
|
+
);
|
|
2063
|
+
console.warn(`[Editor] ${err.message}`);
|
|
2064
|
+
if (typeof options.onUploadError === "function") {
|
|
2065
|
+
options.onUploadError(err, file);
|
|
2066
|
+
}
|
|
2067
|
+
return;
|
|
2068
|
+
}
|
|
2027
2069
|
if (typeof FileReader !== "undefined") {
|
|
2028
2070
|
const reader = new FileReader();
|
|
2029
2071
|
reader.onload = () => {
|
|
@@ -2041,9 +2083,11 @@ var Image2 = BaseImage.extend({
|
|
|
2041
2083
|
return {
|
|
2042
2084
|
...this.parent?.(),
|
|
2043
2085
|
allowBase64: true,
|
|
2086
|
+
maxBase64Size: 65536,
|
|
2044
2087
|
enablePaste: true,
|
|
2045
2088
|
enableDrop: true,
|
|
2046
2089
|
upload: void 0,
|
|
2090
|
+
onUploadError: void 0,
|
|
2047
2091
|
HTMLAttributes: {
|
|
2048
2092
|
class: "rounded-md max-w-full h-auto my-2"
|
|
2049
2093
|
}
|
|
@@ -3839,6 +3883,7 @@ var SpreadsheetController = class {
|
|
|
3839
3883
|
parseFormula,
|
|
3840
3884
|
parseRange,
|
|
3841
3885
|
plainTextToTipTapHtml,
|
|
3886
|
+
removeImageNode,
|
|
3842
3887
|
resolveTemplates,
|
|
3843
3888
|
resolveTemplatesWithMapping,
|
|
3844
3889
|
resolveVariables,
|