@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/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, 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, 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,140 @@ 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/rich-text-preset.ts
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 StarterKit = resolveExt2(_StarterKit, "StarterKit");
1892
- var Color = resolveExt2(_Color, "Color");
1893
- var Highlight = resolveExt2(_Highlight, "Highlight");
1894
- var Link2 = resolveExt2(_Link, "Link");
1895
- var TaskList2 = resolveExt2(_TaskList, "TaskList");
1896
- var TaskItem2 = resolveExt2(_TaskItem, "TaskItem");
1897
- var TextAlign = resolveExt2(_TextAlign, "TextAlign");
1898
- var TextStyle = resolveExt2(_TextStyle, "TextStyle");
1899
- var Typography = resolveExt2(_Typography, "Typography");
1900
- var Underline = resolveExt2(_Underline, "Underline");
1901
- var Placeholder = resolveExt2(_Placeholder, "Placeholder");
1902
- var CharacterCount = resolveExt2(_CharacterCount, "CharacterCount");
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 handleImageInsertion(view, file, options) {
1923
+ if (typeof options.upload === "function") {
1924
+ const hasObjectUrl = typeof URL !== "undefined" && typeof URL.createObjectURL === "function";
1925
+ const tempUrl = hasObjectUrl ? URL.createObjectURL(file) : null;
1926
+ if (tempUrl) {
1927
+ insertImageNode(view, tempUrl, file.name);
1928
+ }
1929
+ Promise.resolve(options.upload(file)).then((uploadedUrl) => {
1930
+ if (!uploadedUrl) return;
1931
+ if (tempUrl) {
1932
+ updateImageSrc(view, tempUrl, uploadedUrl);
1933
+ if (typeof URL.revokeObjectURL === "function") {
1934
+ URL.revokeObjectURL(tempUrl);
1935
+ }
1936
+ } else {
1937
+ insertImageNode(view, uploadedUrl, file.name);
1938
+ }
1939
+ }).catch((err) => {
1940
+ console.error("Failed to upload pasted image:", err);
1941
+ });
1942
+ } else if (options.allowBase64 !== false) {
1943
+ if (typeof FileReader !== "undefined") {
1944
+ const reader = new FileReader();
1945
+ reader.onload = () => {
1946
+ const src = reader.result;
1947
+ if (src) {
1948
+ insertImageNode(view, src, file.name);
1949
+ }
1950
+ };
1951
+ reader.readAsDataURL(file);
1952
+ }
1953
+ }
1954
+ }
1955
+ var Image2 = BaseImage.extend({
1956
+ addOptions() {
1957
+ return {
1958
+ ...this.parent?.(),
1959
+ allowBase64: true,
1960
+ enablePaste: true,
1961
+ enableDrop: true,
1962
+ upload: void 0,
1963
+ HTMLAttributes: {
1964
+ class: "rounded-md max-w-full h-auto my-2"
1965
+ }
1966
+ };
1967
+ },
1968
+ addProseMirrorPlugins() {
1969
+ const parentPlugins = this.parent?.() || [];
1970
+ const options = this.options;
1971
+ if (!options.enablePaste && !options.enableDrop) {
1972
+ return parentPlugins;
1973
+ }
1974
+ const pastePlugin = new Plugin5({
1975
+ key: imagePastePluginKey,
1976
+ props: {
1977
+ handlePaste(view, event) {
1978
+ if (!options.enablePaste) return false;
1979
+ const items = Array.from(event.clipboardData?.items || []);
1980
+ const imageItems = items.filter(
1981
+ (item) => item.kind === "file" && item.type.startsWith("image/")
1982
+ );
1983
+ if (imageItems.length === 0) return false;
1984
+ event.preventDefault();
1985
+ for (const item of imageItems) {
1986
+ const file = item.getAsFile();
1987
+ if (!file) continue;
1988
+ handleImageInsertion(view, file, options);
1989
+ }
1990
+ return true;
1991
+ },
1992
+ handleDrop(view, event) {
1993
+ if (!options.enableDrop) return false;
1994
+ const files = Array.from(event.dataTransfer?.files || []);
1995
+ const imageFiles = files.filter((f) => f.type.startsWith("image/"));
1996
+ if (imageFiles.length === 0) return false;
1997
+ event.preventDefault();
1998
+ for (const file of imageFiles) {
1999
+ handleImageInsertion(view, file, options);
2000
+ }
2001
+ return true;
2002
+ }
2003
+ }
2004
+ });
2005
+ return [...parentPlugins, pastePlugin];
2006
+ }
2007
+ });
2008
+
2009
+ // src/extensions/rich-text-preset.ts
2010
+ var resolveExt3 = (mod, name) => mod?.[name] || mod?.default?.[name] || mod?.default?.default || mod?.default || mod;
2011
+ var StarterKit = resolveExt3(_StarterKit, "StarterKit");
2012
+ var Color = resolveExt3(_Color, "Color");
2013
+ var Highlight = resolveExt3(_Highlight, "Highlight");
2014
+ var Link2 = resolveExt3(_Link, "Link");
2015
+ var TaskList2 = resolveExt3(_TaskList, "TaskList");
2016
+ var TaskItem2 = resolveExt3(_TaskItem, "TaskItem");
2017
+ var TextAlign = resolveExt3(_TextAlign, "TextAlign");
2018
+ var TextStyle = resolveExt3(_TextStyle, "TextStyle");
2019
+ var Typography = resolveExt3(_Typography, "Typography");
2020
+ var Underline = resolveExt3(_Underline, "Underline");
2021
+ var Placeholder = resolveExt3(_Placeholder, "Placeholder");
2022
+ var CharacterCount = resolveExt3(_CharacterCount, "CharacterCount");
1903
2023
  function createRichTextPreset(options = {}) {
1904
2024
  const {
1905
2025
  placeholder = "Start typing...",
@@ -2021,6 +2141,18 @@ function createRichTextPreset(options = {}) {
2021
2141
  })
2022
2142
  );
2023
2143
  }
2144
+ if (options.image !== false) {
2145
+ const imageConfig = typeof options.image === "object" ? options.image : {};
2146
+ extensions2.push(
2147
+ Image2.configure({
2148
+ HTMLAttributes: {
2149
+ class: "rounded-md max-w-full h-auto my-2",
2150
+ ...imageConfig.HTMLAttributes || {}
2151
+ },
2152
+ ...imageConfig
2153
+ })
2154
+ );
2155
+ }
2024
2156
  return extensions2;
2025
2157
  }
2026
2158
 
@@ -3585,6 +3717,7 @@ export {
3585
3717
  FormulaParser,
3586
3718
  GradientText,
3587
3719
  INSTRUCTION_REGEX,
3720
+ Image2 as Image,
3588
3721
  LoadingNode,
3589
3722
  Markdown2 as Markdown,
3590
3723
  Mention,
@@ -3608,8 +3741,11 @@ export {
3608
3741
  getEditorMarkdown,
3609
3742
  getEditorText,
3610
3743
  getLatestVersion,
3744
+ handleImageInsertion,
3611
3745
  htmlToPlainText,
3746
+ imagePastePluginKey,
3612
3747
  indexToColName,
3748
+ insertImageNode,
3613
3749
  instructionRegex,
3614
3750
  mapRawOffsetToResolved,
3615
3751
  mapResolvedOffsetToRaw,
@@ -3624,6 +3760,7 @@ export {
3624
3760
  templateRegex,
3625
3761
  tokenizeFormula,
3626
3762
  tokenizePrompt,
3763
+ updateImageSrc,
3627
3764
  variableRegex
3628
3765
  };
3629
3766
  //# sourceMappingURL=index.js.map