@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.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { T as Token } from './tokens-7kRTEtPb.cjs';
|
|
2
2
|
export { C as ColorGradient, I as INSTRUCTION_REGEX, a as TEMPLATE_REGEX, b as Template, c as TemplateVersion, d as TokenType, V as VARIABLE_REGEX, i as instructionRegex, t as templateRegex, v as variableRegex } from './tokens-7kRTEtPb.cjs';
|
|
3
3
|
export { ResolveTemplatesOptions, SourceMapSegment, extractInstructionNames, extractTemplateNames, extractVariableNames, getLatestVersion, mapRawOffsetToResolved, mapResolvedOffsetToRaw, resolveTemplates, resolveTemplatesWithMapping, resolveVariables, tokenizePrompt } from './grammar/index.cjs';
|
|
4
|
-
export { ColorHighlighter, FontSize, GradientText, GradientTextOptions, Image, ImageOptions, LoadingNode, Markdown, Mention, MentionEntity, MentionOptions, RichTextPresetOptions, SlashCommandMatchData, SlashCommands, SlashCommandsOptions, SmilieReplacer, TemplateSuggestions, TemplateSuggestionsOptions, createMentionExtension, createRichTextPreset, findHexColors, handleImageInsertion, imagePastePluginKey, insertImageNode, updateImageSrc } from './extensions/index.cjs';
|
|
4
|
+
export { ColorHighlighter, FontSize, GradientText, GradientTextOptions, Image, ImageOptions, LoadingNode, Markdown, Mention, MentionEntity, MentionOptions, RichTextPresetOptions, SlashCommandMatchData, SlashCommands, SlashCommandsOptions, SmilieReplacer, TemplateSuggestions, TemplateSuggestionsOptions, createMentionExtension, createRichTextPreset, findHexColors, handleImageInsertion, imagePastePluginKey, insertImageNode, removeImageNode, updateImageSrc } from './extensions/index.cjs';
|
|
5
5
|
export { ExtractedMention, escapeHtml, extractMentionsFromDoc, getEditorMarkdown, getEditorText, htmlToPlainText, markdownToTipTapHtml, plainTextToTipTapHtml } from './serializers/index.cjs';
|
|
6
6
|
import { Editor, EditorOptions, Content, Extensions } from '@tiptap/core';
|
|
7
7
|
export { Content, Editor, EditorOptions, Extensions } from '@tiptap/core';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { T as Token } from './tokens-7kRTEtPb.js';
|
|
2
2
|
export { C as ColorGradient, I as INSTRUCTION_REGEX, a as TEMPLATE_REGEX, b as Template, c as TemplateVersion, d as TokenType, V as VARIABLE_REGEX, i as instructionRegex, t as templateRegex, v as variableRegex } from './tokens-7kRTEtPb.js';
|
|
3
3
|
export { ResolveTemplatesOptions, SourceMapSegment, extractInstructionNames, extractTemplateNames, extractVariableNames, getLatestVersion, mapRawOffsetToResolved, mapResolvedOffsetToRaw, resolveTemplates, resolveTemplatesWithMapping, resolveVariables, tokenizePrompt } from './grammar/index.js';
|
|
4
|
-
export { ColorHighlighter, FontSize, GradientText, GradientTextOptions, Image, ImageOptions, LoadingNode, Markdown, Mention, MentionEntity, MentionOptions, RichTextPresetOptions, SlashCommandMatchData, SlashCommands, SlashCommandsOptions, SmilieReplacer, TemplateSuggestions, TemplateSuggestionsOptions, createMentionExtension, createRichTextPreset, findHexColors, handleImageInsertion, imagePastePluginKey, insertImageNode, updateImageSrc } from './extensions/index.js';
|
|
4
|
+
export { ColorHighlighter, FontSize, GradientText, GradientTextOptions, Image, ImageOptions, LoadingNode, Markdown, Mention, MentionEntity, MentionOptions, RichTextPresetOptions, SlashCommandMatchData, SlashCommands, SlashCommandsOptions, SmilieReplacer, TemplateSuggestions, TemplateSuggestionsOptions, createMentionExtension, createRichTextPreset, findHexColors, handleImageInsertion, imagePastePluginKey, insertImageNode, removeImageNode, updateImageSrc } from './extensions/index.js';
|
|
5
5
|
export { ExtractedMention, escapeHtml, extractMentionsFromDoc, getEditorMarkdown, getEditorText, htmlToPlainText, markdownToTipTapHtml, plainTextToTipTapHtml } from './serializers/index.js';
|
|
6
6
|
import { Editor, EditorOptions, Content, Extensions } from '@tiptap/core';
|
|
7
7
|
export { Content, Editor, EditorOptions, Extensions } from '@tiptap/core';
|
package/dist/index.js
CHANGED
|
@@ -1919,6 +1919,22 @@ function updateImageSrc(view, oldSrc, newSrc) {
|
|
|
1919
1919
|
view.dispatch(tr);
|
|
1920
1920
|
}
|
|
1921
1921
|
}
|
|
1922
|
+
function removeImageNode(view, src) {
|
|
1923
|
+
const { doc } = view.state;
|
|
1924
|
+
let foundPos = null;
|
|
1925
|
+
let nodeSize = 0;
|
|
1926
|
+
doc.descendants((node, pos) => {
|
|
1927
|
+
if (node.type.name === "image" && node.attrs.src === src) {
|
|
1928
|
+
foundPos = pos;
|
|
1929
|
+
nodeSize = node.nodeSize;
|
|
1930
|
+
return false;
|
|
1931
|
+
}
|
|
1932
|
+
});
|
|
1933
|
+
if (foundPos !== null) {
|
|
1934
|
+
const tr = view.state.tr.delete(foundPos, foundPos + nodeSize);
|
|
1935
|
+
view.dispatch(tr);
|
|
1936
|
+
}
|
|
1937
|
+
}
|
|
1922
1938
|
function handleImageInsertion(view, file, options) {
|
|
1923
1939
|
if (typeof options.upload === "function") {
|
|
1924
1940
|
const hasObjectUrl = typeof URL !== "undefined" && typeof URL.createObjectURL === "function";
|
|
@@ -1927,7 +1943,9 @@ function handleImageInsertion(view, file, options) {
|
|
|
1927
1943
|
insertImageNode(view, tempUrl, file.name);
|
|
1928
1944
|
}
|
|
1929
1945
|
Promise.resolve(options.upload(file)).then((uploadedUrl) => {
|
|
1930
|
-
if (!uploadedUrl)
|
|
1946
|
+
if (!uploadedUrl) {
|
|
1947
|
+
throw new Error("Upload handler returned empty URL");
|
|
1948
|
+
}
|
|
1931
1949
|
if (tempUrl) {
|
|
1932
1950
|
updateImageSrc(view, tempUrl, uploadedUrl);
|
|
1933
1951
|
if (typeof URL.revokeObjectURL === "function") {
|
|
@@ -1937,9 +1955,32 @@ function handleImageInsertion(view, file, options) {
|
|
|
1937
1955
|
insertImageNode(view, uploadedUrl, file.name);
|
|
1938
1956
|
}
|
|
1939
1957
|
}).catch((err) => {
|
|
1940
|
-
|
|
1958
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
1959
|
+
console.error("Failed to upload pasted image:", error);
|
|
1960
|
+
if (tempUrl) {
|
|
1961
|
+
removeImageNode(view, tempUrl);
|
|
1962
|
+
if (typeof URL.revokeObjectURL === "function") {
|
|
1963
|
+
URL.revokeObjectURL(tempUrl);
|
|
1964
|
+
}
|
|
1965
|
+
}
|
|
1966
|
+
if (typeof options.onUploadError === "function") {
|
|
1967
|
+
options.onUploadError(error, file);
|
|
1968
|
+
}
|
|
1941
1969
|
});
|
|
1942
1970
|
} else if (options.allowBase64 !== false) {
|
|
1971
|
+
const maxBase64Size = options.maxBase64Size ?? 65536;
|
|
1972
|
+
if (file.size > maxBase64Size) {
|
|
1973
|
+
const err = new Error(
|
|
1974
|
+
`Image size (${Math.round(file.size / 1024)}KB) exceeds maxBase64Size (${Math.round(
|
|
1975
|
+
maxBase64Size / 1024
|
|
1976
|
+
)}KB). Provide an upload handler to support large images.`
|
|
1977
|
+
);
|
|
1978
|
+
console.warn(`[Editor] ${err.message}`);
|
|
1979
|
+
if (typeof options.onUploadError === "function") {
|
|
1980
|
+
options.onUploadError(err, file);
|
|
1981
|
+
}
|
|
1982
|
+
return;
|
|
1983
|
+
}
|
|
1943
1984
|
if (typeof FileReader !== "undefined") {
|
|
1944
1985
|
const reader = new FileReader();
|
|
1945
1986
|
reader.onload = () => {
|
|
@@ -1957,9 +1998,11 @@ var Image2 = BaseImage.extend({
|
|
|
1957
1998
|
return {
|
|
1958
1999
|
...this.parent?.(),
|
|
1959
2000
|
allowBase64: true,
|
|
2001
|
+
maxBase64Size: 65536,
|
|
1960
2002
|
enablePaste: true,
|
|
1961
2003
|
enableDrop: true,
|
|
1962
2004
|
upload: void 0,
|
|
2005
|
+
onUploadError: void 0,
|
|
1963
2006
|
HTMLAttributes: {
|
|
1964
2007
|
class: "rounded-md max-w-full h-auto my-2"
|
|
1965
2008
|
}
|
|
@@ -3754,6 +3797,7 @@ export {
|
|
|
3754
3797
|
parseFormula,
|
|
3755
3798
|
parseRange,
|
|
3756
3799
|
plainTextToTipTapHtml,
|
|
3800
|
+
removeImageNode,
|
|
3757
3801
|
resolveTemplates,
|
|
3758
3802
|
resolveTemplatesWithMapping,
|
|
3759
3803
|
resolveVariables,
|