@pixerate/editor 0.5.0 → 0.6.0
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 +157 -15
- package/dist/extensions/index.cjs.map +1 -1
- package/dist/extensions/index.d.cts +35 -1
- package/dist/extensions/index.d.ts +35 -1
- package/dist/extensions/index.js +151 -14
- package/dist/extensions/index.js.map +1 -1
- package/dist/index.cjs +155 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +150 -13
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -39,6 +39,7 @@ __export(src_exports, {
|
|
|
39
39
|
FormulaParser: () => FormulaParser,
|
|
40
40
|
GradientText: () => GradientText,
|
|
41
41
|
INSTRUCTION_REGEX: () => INSTRUCTION_REGEX,
|
|
42
|
+
Image: () => Image2,
|
|
42
43
|
LoadingNode: () => LoadingNode,
|
|
43
44
|
Markdown: () => Markdown2,
|
|
44
45
|
Mention: () => Mention,
|
|
@@ -62,8 +63,11 @@ __export(src_exports, {
|
|
|
62
63
|
getEditorMarkdown: () => getEditorMarkdown,
|
|
63
64
|
getEditorText: () => getEditorText,
|
|
64
65
|
getLatestVersion: () => getLatestVersion,
|
|
66
|
+
handleImageInsertion: () => handleImageInsertion,
|
|
65
67
|
htmlToPlainText: () => htmlToPlainText,
|
|
68
|
+
imagePastePluginKey: () => imagePastePluginKey,
|
|
66
69
|
indexToColName: () => indexToColName,
|
|
70
|
+
insertImageNode: () => insertImageNode,
|
|
67
71
|
instructionRegex: () => instructionRegex,
|
|
68
72
|
mapRawOffsetToResolved: () => mapRawOffsetToResolved,
|
|
69
73
|
mapResolvedOffsetToRaw: () => mapResolvedOffsetToRaw,
|
|
@@ -78,6 +82,7 @@ __export(src_exports, {
|
|
|
78
82
|
templateRegex: () => templateRegex,
|
|
79
83
|
tokenizeFormula: () => tokenizeFormula,
|
|
80
84
|
tokenizePrompt: () => tokenizePrompt,
|
|
85
|
+
updateImageSrc: () => updateImageSrc,
|
|
81
86
|
variableRegex: () => variableRegex
|
|
82
87
|
});
|
|
83
88
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -1965,20 +1970,140 @@ var Markdown = import_core8.Extension.create({
|
|
|
1965
1970
|
var resolveExt = (mod, name) => mod?.[name] || mod?.default?.[name] || mod?.default?.default || mod?.default || mod;
|
|
1966
1971
|
var Markdown2 = resolveExt(Markdown, "Markdown");
|
|
1967
1972
|
|
|
1968
|
-
// src/extensions/
|
|
1973
|
+
// src/extensions/image.ts
|
|
1974
|
+
var _Image = __toESM(require("@tiptap/extension-image"), 1);
|
|
1975
|
+
var import_state5 = require("@tiptap/pm/state");
|
|
1969
1976
|
var resolveExt2 = (mod, name) => mod?.[name] || mod?.default?.[name] || mod?.default?.default || mod?.default || mod;
|
|
1970
|
-
var
|
|
1971
|
-
var
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1977
|
+
var BaseImage = resolveExt2(_Image, "Image");
|
|
1978
|
+
var imagePastePluginKey = new import_state5.PluginKey("imagePasteHandler");
|
|
1979
|
+
function insertImageNode(view, src, alt) {
|
|
1980
|
+
const { schema } = view.state;
|
|
1981
|
+
const imageType = schema.nodes.image;
|
|
1982
|
+
if (!imageType) return;
|
|
1983
|
+
const node = imageType.create({ src, alt: alt || "" });
|
|
1984
|
+
const tr = view.state.tr.replaceSelectionWith(node);
|
|
1985
|
+
view.dispatch(tr);
|
|
1986
|
+
}
|
|
1987
|
+
function updateImageSrc(view, oldSrc, newSrc) {
|
|
1988
|
+
const { doc } = view.state;
|
|
1989
|
+
let foundPos = null;
|
|
1990
|
+
let foundAttrs = null;
|
|
1991
|
+
doc.descendants((node, pos) => {
|
|
1992
|
+
if (node.type.name === "image" && node.attrs.src === oldSrc) {
|
|
1993
|
+
foundPos = pos;
|
|
1994
|
+
foundAttrs = node.attrs;
|
|
1995
|
+
return false;
|
|
1996
|
+
}
|
|
1997
|
+
});
|
|
1998
|
+
if (foundPos !== null && foundAttrs) {
|
|
1999
|
+
const tr = view.state.tr.setNodeMarkup(foundPos, void 0, {
|
|
2000
|
+
...foundAttrs,
|
|
2001
|
+
src: newSrc
|
|
2002
|
+
});
|
|
2003
|
+
view.dispatch(tr);
|
|
2004
|
+
}
|
|
2005
|
+
}
|
|
2006
|
+
function handleImageInsertion(view, file, options) {
|
|
2007
|
+
if (typeof options.upload === "function") {
|
|
2008
|
+
const hasObjectUrl = typeof URL !== "undefined" && typeof URL.createObjectURL === "function";
|
|
2009
|
+
const tempUrl = hasObjectUrl ? URL.createObjectURL(file) : null;
|
|
2010
|
+
if (tempUrl) {
|
|
2011
|
+
insertImageNode(view, tempUrl, file.name);
|
|
2012
|
+
}
|
|
2013
|
+
Promise.resolve(options.upload(file)).then((uploadedUrl) => {
|
|
2014
|
+
if (!uploadedUrl) return;
|
|
2015
|
+
if (tempUrl) {
|
|
2016
|
+
updateImageSrc(view, tempUrl, uploadedUrl);
|
|
2017
|
+
if (typeof URL.revokeObjectURL === "function") {
|
|
2018
|
+
URL.revokeObjectURL(tempUrl);
|
|
2019
|
+
}
|
|
2020
|
+
} else {
|
|
2021
|
+
insertImageNode(view, uploadedUrl, file.name);
|
|
2022
|
+
}
|
|
2023
|
+
}).catch((err) => {
|
|
2024
|
+
console.error("Failed to upload pasted image:", err);
|
|
2025
|
+
});
|
|
2026
|
+
} else if (options.allowBase64 !== false) {
|
|
2027
|
+
if (typeof FileReader !== "undefined") {
|
|
2028
|
+
const reader = new FileReader();
|
|
2029
|
+
reader.onload = () => {
|
|
2030
|
+
const src = reader.result;
|
|
2031
|
+
if (src) {
|
|
2032
|
+
insertImageNode(view, src, file.name);
|
|
2033
|
+
}
|
|
2034
|
+
};
|
|
2035
|
+
reader.readAsDataURL(file);
|
|
2036
|
+
}
|
|
2037
|
+
}
|
|
2038
|
+
}
|
|
2039
|
+
var Image2 = BaseImage.extend({
|
|
2040
|
+
addOptions() {
|
|
2041
|
+
return {
|
|
2042
|
+
...this.parent?.(),
|
|
2043
|
+
allowBase64: true,
|
|
2044
|
+
enablePaste: true,
|
|
2045
|
+
enableDrop: true,
|
|
2046
|
+
upload: void 0,
|
|
2047
|
+
HTMLAttributes: {
|
|
2048
|
+
class: "rounded-md max-w-full h-auto my-2"
|
|
2049
|
+
}
|
|
2050
|
+
};
|
|
2051
|
+
},
|
|
2052
|
+
addProseMirrorPlugins() {
|
|
2053
|
+
const parentPlugins = this.parent?.() || [];
|
|
2054
|
+
const options = this.options;
|
|
2055
|
+
if (!options.enablePaste && !options.enableDrop) {
|
|
2056
|
+
return parentPlugins;
|
|
2057
|
+
}
|
|
2058
|
+
const pastePlugin = new import_state5.Plugin({
|
|
2059
|
+
key: imagePastePluginKey,
|
|
2060
|
+
props: {
|
|
2061
|
+
handlePaste(view, event) {
|
|
2062
|
+
if (!options.enablePaste) return false;
|
|
2063
|
+
const items = Array.from(event.clipboardData?.items || []);
|
|
2064
|
+
const imageItems = items.filter(
|
|
2065
|
+
(item) => item.kind === "file" && item.type.startsWith("image/")
|
|
2066
|
+
);
|
|
2067
|
+
if (imageItems.length === 0) return false;
|
|
2068
|
+
event.preventDefault();
|
|
2069
|
+
for (const item of imageItems) {
|
|
2070
|
+
const file = item.getAsFile();
|
|
2071
|
+
if (!file) continue;
|
|
2072
|
+
handleImageInsertion(view, file, options);
|
|
2073
|
+
}
|
|
2074
|
+
return true;
|
|
2075
|
+
},
|
|
2076
|
+
handleDrop(view, event) {
|
|
2077
|
+
if (!options.enableDrop) return false;
|
|
2078
|
+
const files = Array.from(event.dataTransfer?.files || []);
|
|
2079
|
+
const imageFiles = files.filter((f) => f.type.startsWith("image/"));
|
|
2080
|
+
if (imageFiles.length === 0) return false;
|
|
2081
|
+
event.preventDefault();
|
|
2082
|
+
for (const file of imageFiles) {
|
|
2083
|
+
handleImageInsertion(view, file, options);
|
|
2084
|
+
}
|
|
2085
|
+
return true;
|
|
2086
|
+
}
|
|
2087
|
+
}
|
|
2088
|
+
});
|
|
2089
|
+
return [...parentPlugins, pastePlugin];
|
|
2090
|
+
}
|
|
2091
|
+
});
|
|
2092
|
+
|
|
2093
|
+
// src/extensions/rich-text-preset.ts
|
|
2094
|
+
var resolveExt3 = (mod, name) => mod?.[name] || mod?.default?.[name] || mod?.default?.default || mod?.default || mod;
|
|
2095
|
+
var StarterKit = resolveExt3(_StarterKit, "StarterKit");
|
|
2096
|
+
var Color = resolveExt3(_Color, "Color");
|
|
2097
|
+
var Highlight = resolveExt3(_Highlight, "Highlight");
|
|
2098
|
+
var Link2 = resolveExt3(_Link, "Link");
|
|
2099
|
+
var TaskList2 = resolveExt3(_TaskList, "TaskList");
|
|
2100
|
+
var TaskItem2 = resolveExt3(_TaskItem, "TaskItem");
|
|
2101
|
+
var TextAlign = resolveExt3(_TextAlign, "TextAlign");
|
|
2102
|
+
var TextStyle = resolveExt3(_TextStyle, "TextStyle");
|
|
2103
|
+
var Typography = resolveExt3(_Typography, "Typography");
|
|
2104
|
+
var Underline = resolveExt3(_Underline, "Underline");
|
|
2105
|
+
var Placeholder = resolveExt3(_Placeholder, "Placeholder");
|
|
2106
|
+
var CharacterCount = resolveExt3(_CharacterCount, "CharacterCount");
|
|
1982
2107
|
function createRichTextPreset(options = {}) {
|
|
1983
2108
|
const {
|
|
1984
2109
|
placeholder = "Start typing...",
|
|
@@ -2100,6 +2225,18 @@ function createRichTextPreset(options = {}) {
|
|
|
2100
2225
|
})
|
|
2101
2226
|
);
|
|
2102
2227
|
}
|
|
2228
|
+
if (options.image !== false) {
|
|
2229
|
+
const imageConfig = typeof options.image === "object" ? options.image : {};
|
|
2230
|
+
extensions2.push(
|
|
2231
|
+
Image2.configure({
|
|
2232
|
+
HTMLAttributes: {
|
|
2233
|
+
class: "rounded-md max-w-full h-auto my-2",
|
|
2234
|
+
...imageConfig.HTMLAttributes || {}
|
|
2235
|
+
},
|
|
2236
|
+
...imageConfig
|
|
2237
|
+
})
|
|
2238
|
+
);
|
|
2239
|
+
}
|
|
2103
2240
|
return extensions2;
|
|
2104
2241
|
}
|
|
2105
2242
|
|
|
@@ -3665,6 +3802,7 @@ var SpreadsheetController = class {
|
|
|
3665
3802
|
FormulaParser,
|
|
3666
3803
|
GradientText,
|
|
3667
3804
|
INSTRUCTION_REGEX,
|
|
3805
|
+
Image,
|
|
3668
3806
|
LoadingNode,
|
|
3669
3807
|
Markdown,
|
|
3670
3808
|
Mention,
|
|
@@ -3688,8 +3826,11 @@ var SpreadsheetController = class {
|
|
|
3688
3826
|
getEditorMarkdown,
|
|
3689
3827
|
getEditorText,
|
|
3690
3828
|
getLatestVersion,
|
|
3829
|
+
handleImageInsertion,
|
|
3691
3830
|
htmlToPlainText,
|
|
3831
|
+
imagePastePluginKey,
|
|
3692
3832
|
indexToColName,
|
|
3833
|
+
insertImageNode,
|
|
3693
3834
|
instructionRegex,
|
|
3694
3835
|
mapRawOffsetToResolved,
|
|
3695
3836
|
mapResolvedOffsetToRaw,
|
|
@@ -3704,6 +3845,7 @@ var SpreadsheetController = class {
|
|
|
3704
3845
|
templateRegex,
|
|
3705
3846
|
tokenizeFormula,
|
|
3706
3847
|
tokenizePrompt,
|
|
3848
|
+
updateImageSrc,
|
|
3707
3849
|
variableRegex
|
|
3708
3850
|
});
|
|
3709
3851
|
//# sourceMappingURL=index.cjs.map
|