@pixerate/editor 0.5.1 → 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 +202 -15
- package/dist/extensions/index.cjs.map +1 -1
- package/dist/extensions/index.d.cts +50 -1
- package/dist/extensions/index.d.ts +50 -1
- package/dist/extensions/index.js +195 -14
- package/dist/extensions/index.js.map +1 -1
- package/dist/index.cjs +200 -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 +194 -13
- package/dist/index.js.map +1 -1
- package/package.json +2 -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, LoadingNode, Markdown, Mention, MentionEntity, MentionOptions, RichTextPresetOptions, SlashCommandMatchData, SlashCommands, SlashCommandsOptions, SmilieReplacer, TemplateSuggestions, TemplateSuggestionsOptions, createMentionExtension, createRichTextPreset, findHexColors } 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';
|
|
@@ -11,6 +11,8 @@ import '@tiptap/pm/view';
|
|
|
11
11
|
import '@tiptap/pm/model';
|
|
12
12
|
import '@tiptap/extension-mention';
|
|
13
13
|
import '@tiptap/suggestion';
|
|
14
|
+
import '@tiptap/extension-image';
|
|
15
|
+
import '@tiptap/pm/state';
|
|
14
16
|
|
|
15
17
|
interface EditorControllerOptions extends Partial<Omit<EditorOptions, "element" | "content">> {
|
|
16
18
|
element?: Element | HTMLElement | null;
|
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, LoadingNode, Markdown, Mention, MentionEntity, MentionOptions, RichTextPresetOptions, SlashCommandMatchData, SlashCommands, SlashCommandsOptions, SmilieReplacer, TemplateSuggestions, TemplateSuggestionsOptions, createMentionExtension, createRichTextPreset, findHexColors } 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';
|
|
@@ -11,6 +11,8 @@ import '@tiptap/pm/view';
|
|
|
11
11
|
import '@tiptap/pm/model';
|
|
12
12
|
import '@tiptap/extension-mention';
|
|
13
13
|
import '@tiptap/suggestion';
|
|
14
|
+
import '@tiptap/extension-image';
|
|
15
|
+
import '@tiptap/pm/state';
|
|
14
16
|
|
|
15
17
|
interface EditorControllerOptions extends Partial<Omit<EditorOptions, "element" | "content">> {
|
|
16
18
|
element?: Element | HTMLElement | null;
|
package/dist/index.js
CHANGED
|
@@ -1886,20 +1886,183 @@ var Markdown = Extension6.create({
|
|
|
1886
1886
|
var resolveExt = (mod, name) => mod?.[name] || mod?.default?.[name] || mod?.default?.default || mod?.default || mod;
|
|
1887
1887
|
var Markdown2 = resolveExt(Markdown, "Markdown");
|
|
1888
1888
|
|
|
1889
|
-
// src/extensions/
|
|
1889
|
+
// src/extensions/image.ts
|
|
1890
|
+
import * as _Image from "@tiptap/extension-image";
|
|
1891
|
+
import { Plugin as Plugin5, PluginKey as PluginKey2 } from "@tiptap/pm/state";
|
|
1890
1892
|
var resolveExt2 = (mod, name) => mod?.[name] || mod?.default?.[name] || mod?.default?.default || mod?.default || mod;
|
|
1891
|
-
var
|
|
1892
|
-
var
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1893
|
+
var BaseImage = resolveExt2(_Image, "Image");
|
|
1894
|
+
var imagePastePluginKey = new PluginKey2("imagePasteHandler");
|
|
1895
|
+
function insertImageNode(view, src, alt) {
|
|
1896
|
+
const { schema } = view.state;
|
|
1897
|
+
const imageType = schema.nodes.image;
|
|
1898
|
+
if (!imageType) return;
|
|
1899
|
+
const node = imageType.create({ src, alt: alt || "" });
|
|
1900
|
+
const tr = view.state.tr.replaceSelectionWith(node);
|
|
1901
|
+
view.dispatch(tr);
|
|
1902
|
+
}
|
|
1903
|
+
function updateImageSrc(view, oldSrc, newSrc) {
|
|
1904
|
+
const { doc } = view.state;
|
|
1905
|
+
let foundPos = null;
|
|
1906
|
+
let foundAttrs = null;
|
|
1907
|
+
doc.descendants((node, pos) => {
|
|
1908
|
+
if (node.type.name === "image" && node.attrs.src === oldSrc) {
|
|
1909
|
+
foundPos = pos;
|
|
1910
|
+
foundAttrs = node.attrs;
|
|
1911
|
+
return false;
|
|
1912
|
+
}
|
|
1913
|
+
});
|
|
1914
|
+
if (foundPos !== null && foundAttrs) {
|
|
1915
|
+
const tr = view.state.tr.setNodeMarkup(foundPos, void 0, {
|
|
1916
|
+
...foundAttrs,
|
|
1917
|
+
src: newSrc
|
|
1918
|
+
});
|
|
1919
|
+
view.dispatch(tr);
|
|
1920
|
+
}
|
|
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
|
+
}
|
|
1938
|
+
function handleImageInsertion(view, file, options) {
|
|
1939
|
+
if (typeof options.upload === "function") {
|
|
1940
|
+
const hasObjectUrl = typeof URL !== "undefined" && typeof URL.createObjectURL === "function";
|
|
1941
|
+
const tempUrl = hasObjectUrl ? URL.createObjectURL(file) : null;
|
|
1942
|
+
if (tempUrl) {
|
|
1943
|
+
insertImageNode(view, tempUrl, file.name);
|
|
1944
|
+
}
|
|
1945
|
+
Promise.resolve(options.upload(file)).then((uploadedUrl) => {
|
|
1946
|
+
if (!uploadedUrl) {
|
|
1947
|
+
throw new Error("Upload handler returned empty URL");
|
|
1948
|
+
}
|
|
1949
|
+
if (tempUrl) {
|
|
1950
|
+
updateImageSrc(view, tempUrl, uploadedUrl);
|
|
1951
|
+
if (typeof URL.revokeObjectURL === "function") {
|
|
1952
|
+
URL.revokeObjectURL(tempUrl);
|
|
1953
|
+
}
|
|
1954
|
+
} else {
|
|
1955
|
+
insertImageNode(view, uploadedUrl, file.name);
|
|
1956
|
+
}
|
|
1957
|
+
}).catch((err) => {
|
|
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
|
+
}
|
|
1969
|
+
});
|
|
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
|
+
}
|
|
1984
|
+
if (typeof FileReader !== "undefined") {
|
|
1985
|
+
const reader = new FileReader();
|
|
1986
|
+
reader.onload = () => {
|
|
1987
|
+
const src = reader.result;
|
|
1988
|
+
if (src) {
|
|
1989
|
+
insertImageNode(view, src, file.name);
|
|
1990
|
+
}
|
|
1991
|
+
};
|
|
1992
|
+
reader.readAsDataURL(file);
|
|
1993
|
+
}
|
|
1994
|
+
}
|
|
1995
|
+
}
|
|
1996
|
+
var Image2 = BaseImage.extend({
|
|
1997
|
+
addOptions() {
|
|
1998
|
+
return {
|
|
1999
|
+
...this.parent?.(),
|
|
2000
|
+
allowBase64: true,
|
|
2001
|
+
maxBase64Size: 65536,
|
|
2002
|
+
enablePaste: true,
|
|
2003
|
+
enableDrop: true,
|
|
2004
|
+
upload: void 0,
|
|
2005
|
+
onUploadError: void 0,
|
|
2006
|
+
HTMLAttributes: {
|
|
2007
|
+
class: "rounded-md max-w-full h-auto my-2"
|
|
2008
|
+
}
|
|
2009
|
+
};
|
|
2010
|
+
},
|
|
2011
|
+
addProseMirrorPlugins() {
|
|
2012
|
+
const parentPlugins = this.parent?.() || [];
|
|
2013
|
+
const options = this.options;
|
|
2014
|
+
if (!options.enablePaste && !options.enableDrop) {
|
|
2015
|
+
return parentPlugins;
|
|
2016
|
+
}
|
|
2017
|
+
const pastePlugin = new Plugin5({
|
|
2018
|
+
key: imagePastePluginKey,
|
|
2019
|
+
props: {
|
|
2020
|
+
handlePaste(view, event) {
|
|
2021
|
+
if (!options.enablePaste) return false;
|
|
2022
|
+
const items = Array.from(event.clipboardData?.items || []);
|
|
2023
|
+
const imageItems = items.filter(
|
|
2024
|
+
(item) => item.kind === "file" && item.type.startsWith("image/")
|
|
2025
|
+
);
|
|
2026
|
+
if (imageItems.length === 0) return false;
|
|
2027
|
+
event.preventDefault();
|
|
2028
|
+
for (const item of imageItems) {
|
|
2029
|
+
const file = item.getAsFile();
|
|
2030
|
+
if (!file) continue;
|
|
2031
|
+
handleImageInsertion(view, file, options);
|
|
2032
|
+
}
|
|
2033
|
+
return true;
|
|
2034
|
+
},
|
|
2035
|
+
handleDrop(view, event) {
|
|
2036
|
+
if (!options.enableDrop) return false;
|
|
2037
|
+
const files = Array.from(event.dataTransfer?.files || []);
|
|
2038
|
+
const imageFiles = files.filter((f) => f.type.startsWith("image/"));
|
|
2039
|
+
if (imageFiles.length === 0) return false;
|
|
2040
|
+
event.preventDefault();
|
|
2041
|
+
for (const file of imageFiles) {
|
|
2042
|
+
handleImageInsertion(view, file, options);
|
|
2043
|
+
}
|
|
2044
|
+
return true;
|
|
2045
|
+
}
|
|
2046
|
+
}
|
|
2047
|
+
});
|
|
2048
|
+
return [...parentPlugins, pastePlugin];
|
|
2049
|
+
}
|
|
2050
|
+
});
|
|
2051
|
+
|
|
2052
|
+
// src/extensions/rich-text-preset.ts
|
|
2053
|
+
var resolveExt3 = (mod, name) => mod?.[name] || mod?.default?.[name] || mod?.default?.default || mod?.default || mod;
|
|
2054
|
+
var StarterKit = resolveExt3(_StarterKit, "StarterKit");
|
|
2055
|
+
var Color = resolveExt3(_Color, "Color");
|
|
2056
|
+
var Highlight = resolveExt3(_Highlight, "Highlight");
|
|
2057
|
+
var Link2 = resolveExt3(_Link, "Link");
|
|
2058
|
+
var TaskList2 = resolveExt3(_TaskList, "TaskList");
|
|
2059
|
+
var TaskItem2 = resolveExt3(_TaskItem, "TaskItem");
|
|
2060
|
+
var TextAlign = resolveExt3(_TextAlign, "TextAlign");
|
|
2061
|
+
var TextStyle = resolveExt3(_TextStyle, "TextStyle");
|
|
2062
|
+
var Typography = resolveExt3(_Typography, "Typography");
|
|
2063
|
+
var Underline = resolveExt3(_Underline, "Underline");
|
|
2064
|
+
var Placeholder = resolveExt3(_Placeholder, "Placeholder");
|
|
2065
|
+
var CharacterCount = resolveExt3(_CharacterCount, "CharacterCount");
|
|
1903
2066
|
function createRichTextPreset(options = {}) {
|
|
1904
2067
|
const {
|
|
1905
2068
|
placeholder = "Start typing...",
|
|
@@ -2021,6 +2184,18 @@ function createRichTextPreset(options = {}) {
|
|
|
2021
2184
|
})
|
|
2022
2185
|
);
|
|
2023
2186
|
}
|
|
2187
|
+
if (options.image !== false) {
|
|
2188
|
+
const imageConfig = typeof options.image === "object" ? options.image : {};
|
|
2189
|
+
extensions2.push(
|
|
2190
|
+
Image2.configure({
|
|
2191
|
+
HTMLAttributes: {
|
|
2192
|
+
class: "rounded-md max-w-full h-auto my-2",
|
|
2193
|
+
...imageConfig.HTMLAttributes || {}
|
|
2194
|
+
},
|
|
2195
|
+
...imageConfig
|
|
2196
|
+
})
|
|
2197
|
+
);
|
|
2198
|
+
}
|
|
2024
2199
|
return extensions2;
|
|
2025
2200
|
}
|
|
2026
2201
|
|
|
@@ -3585,6 +3760,7 @@ export {
|
|
|
3585
3760
|
FormulaParser,
|
|
3586
3761
|
GradientText,
|
|
3587
3762
|
INSTRUCTION_REGEX,
|
|
3763
|
+
Image2 as Image,
|
|
3588
3764
|
LoadingNode,
|
|
3589
3765
|
Markdown2 as Markdown,
|
|
3590
3766
|
Mention,
|
|
@@ -3608,8 +3784,11 @@ export {
|
|
|
3608
3784
|
getEditorMarkdown,
|
|
3609
3785
|
getEditorText,
|
|
3610
3786
|
getLatestVersion,
|
|
3787
|
+
handleImageInsertion,
|
|
3611
3788
|
htmlToPlainText,
|
|
3789
|
+
imagePastePluginKey,
|
|
3612
3790
|
indexToColName,
|
|
3791
|
+
insertImageNode,
|
|
3613
3792
|
instructionRegex,
|
|
3614
3793
|
mapRawOffsetToResolved,
|
|
3615
3794
|
mapResolvedOffsetToRaw,
|
|
@@ -3618,12 +3797,14 @@ export {
|
|
|
3618
3797
|
parseFormula,
|
|
3619
3798
|
parseRange,
|
|
3620
3799
|
plainTextToTipTapHtml,
|
|
3800
|
+
removeImageNode,
|
|
3621
3801
|
resolveTemplates,
|
|
3622
3802
|
resolveTemplatesWithMapping,
|
|
3623
3803
|
resolveVariables,
|
|
3624
3804
|
templateRegex,
|
|
3625
3805
|
tokenizeFormula,
|
|
3626
3806
|
tokenizePrompt,
|
|
3807
|
+
updateImageSrc,
|
|
3627
3808
|
variableRegex
|
|
3628
3809
|
};
|
|
3629
3810
|
//# sourceMappingURL=index.js.map
|