@pixerate/editor-svelte 0.2.3 → 0.2.5

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.js CHANGED
@@ -99,21 +99,30 @@ function EditableTextNodeEditor($$anchor, $$props) {
99
99
  // src/BubbleMenu.svelte
100
100
  import "svelte/internal/disclose-version";
101
101
  import * as $3 from "svelte/internal/client";
102
- import BubbleMenuPlugin from "@tiptap/extension-bubble-menu";
103
- import { onMount as onMount2, onDestroy as onDestroy2 } from "svelte";
104
- var root2 = $3.from_html(`<div><!></div>`);
102
+ import { BubbleMenuPlugin } from "@tiptap/extension-bubble-menu";
103
+ var root2 = $3.from_html(`<div style="visibility: hidden;"><!></div>`);
105
104
  function BubbleMenu($$anchor, $$props) {
106
105
  $3.push($$props, true);
107
- let className = $3.prop($$props, "class", 3, "flex items-center gap-1 bg-white border border-gray-200 shadow-md rounded-md p-1");
106
+ let className = $3.prop($$props, "class", 3, "flex h-fit w-fit items-center gap-1 rounded-md border border-gray-200 bg-white p-1 shadow-md"), pluginKey = $3.prop($$props, "pluginKey", 3, "bubbleMenu"), shouldShow = $3.prop($$props, "shouldShow", 3, null), updateDelay = $3.prop($$props, "updateDelay", 3, 250), tippyOptions = $3.prop($$props, "tippyOptions", 19, () => ({}));
108
107
  let menuElement = $3.state(void 0);
109
- onMount2(() => {
108
+ $3.user_effect(() => {
110
109
  if ($$props.editor && $3.get(menuElement)) {
111
- $$props.editor.registerPlugin(BubbleMenuPlugin.configure({ element: $3.get(menuElement), tippyOptions: { duration: 100 } }));
112
- }
113
- });
114
- onDestroy2(() => {
115
- if ($$props.editor) {
116
- $$props.editor.unregisterPlugin("bubbleMenu");
110
+ const plugin = BubbleMenuPlugin({
111
+ pluginKey: pluginKey(),
112
+ editor: $$props.editor,
113
+ element: $3.get(menuElement),
114
+ tippyOptions: {
115
+ duration: 100,
116
+ appendTo: () => document.body,
117
+ ...tippyOptions()
118
+ },
119
+ shouldShow: shouldShow(),
120
+ updateDelay: updateDelay()
121
+ });
122
+ $$props.editor.registerPlugin(plugin);
123
+ return () => {
124
+ $$props.editor.unregisterPlugin(pluginKey());
125
+ };
117
126
  }
118
127
  });
119
128
  var div = root2();
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/EditableTextNodeEditor.svelte","../src/editor.svelte.ts","../src/BubbleMenu.svelte","../src/TemplateRenderer.svelte","../src/index.ts"],"sourcesContent":["import 'EditableTextNodeEditor.svelte.css';import 'svelte/internal/disclose-version';\nimport * as $ from 'svelte/internal/client';\nimport { onDestroy, onMount } from \"svelte\";\nimport Placeholder from \"@tiptap/extension-placeholder\";\nimport { initiateEditor } from \"./editor.svelte\";\n\nvar root = $.from_html(`<div class=\"flex items-center justify-center p-4 text-sm text-gray-500\">Loading editor...</div>`);\nvar root_1 = $.from_html(`<div draggable=\"false\"><!> <div class=\"pixerate-editor-content prose w-full max-w-none focus:outline-none\"></div></div>`);\n\nexport default function EditableTextNodeEditor($$anchor, $$props) {\n\t$.push($$props, true);\n\n\tlet className = $.prop($$props, 'class', 3, \"\"),\n\t\tcontent = $.prop($$props, 'content', 3, undefined),\n\t\tshowMenu = $.prop($$props, 'showMenu', 3, true),\n\t\teditable = $.prop($$props, 'editable', 3, true),\n\t\teditor = $.prop($$props, 'editor', 15),\n\t\textensions = $.prop($$props, 'extensions', 19, () => []),\n\t\tplaceholder = $.prop($$props, 'placeholder', 3, \"\");\n\n\tlet element = $.state(void 0);\n\n\t$.user_effect(() => {\n\t\tif (editor() && editor().isEditable !== editable()) {\n\t\t\teditor().setEditable(editable());\n\t\t}\n\t});\n\n\tonMount(() => {\n\t\teditor(initiateEditor(\n\t\t\t$.get(element),\n\t\t\tcontent(),\n\t\t\t[\n\t\t\t\tPlaceholder.configure({ placeholder: placeholder() }),\n\t\t\t\t...extensions()\n\t\t\t],\n\t\t\t{\n\t\t\t\teditable: editable(),\n\t\t\t\tonCreate: $$props.onCreate,\n\t\t\t\tonUpdate: $$props.onUpdate,\n\t\t\t\tonFocus() {\n\t\t\t\t\tif ($$props.onFocus) $$props.onFocus();\n\t\t\t\t},\n\n\t\t\t\tonBlur() {\n\t\t\t\t\tif ($$props.onBlur) $$props.onBlur();\n\t\t\t\t}\n\t\t\t}\n\t\t));\n\t});\n\n\tonDestroy(() => {\n\t\tif (editor()) {\n\t\t\teditor().destroy();\n\t\t}\n\t});\n\n\tvar div = root_1();\n\tvar node = $.child(div);\n\n\t{\n\t\tvar consequent = ($$anchor) => {\n\t\t\tvar div_1 = root();\n\n\t\t\t$.append($$anchor, div_1);\n\t\t};\n\n\t\t$.if(node, ($$render) => {\n\t\t\tif (!editor()) $$render(consequent);\n\t\t});\n\t}\n\n\tvar div_2 = $.sibling(node, 2);\n\n\t$.bind_this(div_2, ($$value) => $.set(element, $$value), () => $.get(element));\n\t$.reset(div);\n\t$.template_effect(() => $.set_class(div, 1, `pixerate-editor-container ${className()}`));\n\t$.append($$anchor, div);\n\t$.pop();\n}","import { Editor } from \"@tiptap/core\";\nimport { createRichTextPreset } from \"@pixerate/editor\";\nexport const initiateEditor = (element, content, extensions, options) => {\n const { richTextOptions, ...editorOptions } = options || {};\n const defaultPreset = createRichTextPreset(richTextOptions);\n const editor = new Editor({\n element,\n content,\n extensions: [\n ...defaultPreset,\n ...extensions ?? []\n ],\n autofocus: true,\n ...editorOptions\n });\n return editor;\n};\nexport function createReactiveEditor(initialContent = \"\", extensions = [], options = {}) {\n let editorInstance;\n return {\n get current() {\n return editorInstance;\n },\n mount(element) {\n editorInstance = initiateEditor(element, initialContent, extensions, options);\n return editorInstance;\n },\n destroy() {\n if (editorInstance) {\n editorInstance.destroy();\n editorInstance = void 0;\n }\n }\n };\n}\n","import 'svelte/internal/disclose-version';\nimport * as $ from 'svelte/internal/client';\nimport BubbleMenuPlugin from \"@tiptap/extension-bubble-menu\";\nimport { onMount, onDestroy } from \"svelte\";\n\nvar root = $.from_html(`<div><!></div>`);\n\nexport default function BubbleMenu($$anchor, $$props) {\n\t$.push($$props, true);\n\n\tlet className = $.prop($$props, 'class', 3, \"flex items-center gap-1 bg-white border border-gray-200 shadow-md rounded-md p-1\");\n\tlet menuElement = $.state(void 0);\n\n\tonMount(() => {\n\t\tif ($$props.editor && $.get(menuElement)) {\n\t\t\t$$props.editor.registerPlugin(BubbleMenuPlugin.configure({ element: $.get(menuElement), tippyOptions: { duration: 100 } }));\n\t\t}\n\t});\n\n\tonDestroy(() => {\n\t\tif ($$props.editor) {\n\t\t\t$$props.editor.unregisterPlugin(\"bubbleMenu\");\n\t\t}\n\t});\n\n\tvar div = root();\n\tvar node = $.child(div);\n\n\t{\n\t\tvar consequent = ($$anchor) => {\n\t\t\tvar fragment = $.comment();\n\t\t\tvar node_1 = $.first_child(fragment);\n\n\t\t\t$.snippet(node_1, () => $$props.children);\n\t\t\t$.append($$anchor, fragment);\n\t\t};\n\n\t\t$.if(node, ($$render) => {\n\t\t\tif ($$props.children) $$render(consequent);\n\t\t});\n\t}\n\n\t$.reset(div);\n\t$.bind_this(div, ($$value) => $.set(menuElement, $$value), () => $.get(menuElement));\n\t$.template_effect(() => $.set_class(div, 1, $.clsx(className())));\n\t$.append($$anchor, div);\n\t$.pop();\n}","import 'svelte/internal/disclose-version';\nimport * as $ from 'svelte/internal/client';\nimport { tokenizePrompt, resolveTemplates } from \"@pixerate/editor\";\n\nvar root = $.from_html(`<span class=\"inline-flex items-center px-1.5 py-0.5 mx-0.5 text-xs font-semibold rounded-md border border-[var(--color-to)]/40 bg-gradient-to-r from-[var(--color-from)]/15 to-[var(--color-to)]/15 text-[var(--color-to)] hover:brightness-110 cursor-pointer transition-all\"> </span>`);\nvar root_1 = $.from_html(`<span class=\"inline-flex items-center px-1.5 py-0.5 mx-0.5 text-xs font-medium rounded-md border border-violet-400/40 bg-violet-400/15 text-violet-600 hover:brightness-110 cursor-pointer transition-all\"> </span>`);\nvar root_2 = $.from_html(`<span class=\"inline-flex items-center px-1.5 py-0.5 mx-0.5 text-xs italic font-medium rounded-md border border-rose-400/40 bg-rose-400/15 text-rose-600\"> </span>`);\nvar root_3 = $.from_html(`<span> </span>`);\nvar root_4 = $.from_html(`<div></div>`);\n\nexport default function TemplateRenderer($$anchor, $$props) {\n\t$.push($$props, true);\n\n\tlet templates = $.prop($$props, 'templates', 19, () => []),\n\t\tresolve = $.prop($$props, 'resolve', 3, false),\n\t\tclassName = $.prop($$props, 'class', 3, \"font-mono text-sm leading-relaxed whitespace-pre-wrap break-words\");\n\n\tlet displayText = $.derived(() => resolve() && templates().length > 0\n\t\t? resolveTemplates($$props.content, templates())\n\t\t: $$props.content);\n\n\tlet tokens = $.derived(() => tokenizePrompt($.get(displayText)));\n\tvar div = root_4();\n\n\t$.each(div, 21, () => $.get(tokens), $.index, ($$anchor, token) => {\n\t\tvar fragment = $.comment();\n\t\tvar node = $.first_child(fragment);\n\n\t\t{\n\t\t\tvar consequent = ($$anchor) => {\n\t\t\t\tconst colors = $.derived(() => $$props.templateColorMap?.get($.get(token).value) || { from: \"#f43f5e\", to: \"#8b5cf6\" });\n\t\t\t\tvar span = root();\n\t\t\t\tvar text = $.only_child(span, true);\n\n\t\t\t\t$.template_effect(() => {\n\t\t\t\t\t$.set_style(span, `--color-from: ${$.get(colors).from}; --color-to: ${$.get(colors).to};`);\n\t\t\t\t\t$.set_attribute(span, 'title', `Template: ${$.get(token).value}`);\n\t\t\t\t\t$.set_text(text, `{{${$.get(token).value}}}`);\n\t\t\t\t});\n\n\t\t\t\t$.delegated('click', span, () => $$props.onTemplateClick?.($.get(token).value));\n\t\t\t\t$.append($$anchor, span);\n\t\t\t};\n\n\t\t\tvar consequent_1 = ($$anchor) => {\n\t\t\t\tvar span_1 = root_1();\n\t\t\t\tvar text_1 = $.only_child(span_1, true);\n\n\t\t\t\t$.template_effect(() => {\n\t\t\t\t\t$.set_attribute(span_1, 'title', `Variable: ${$.get(token).value}`);\n\t\t\t\t\t$.set_text(text_1, `{${$.get(token).value}}`);\n\t\t\t\t});\n\n\t\t\t\t$.delegated('click', span_1, () => $$props.onVariableClick?.($.get(token).value));\n\t\t\t\t$.append($$anchor, span_1);\n\t\t\t};\n\n\t\t\tvar consequent_2 = ($$anchor) => {\n\t\t\t\tvar span_2 = root_2();\n\t\t\t\tvar text_2 = $.only_child(span_2, true);\n\n\t\t\t\t$.template_effect(() => {\n\t\t\t\t\t$.set_attribute(span_2, 'title', `Instruction: ${$.get(token).value}`);\n\t\t\t\t\t$.set_text(text_2, `__${$.get(token).value}__`);\n\t\t\t\t});\n\n\t\t\t\t$.append($$anchor, span_2);\n\t\t\t};\n\n\t\t\tvar alternate = ($$anchor) => {\n\t\t\t\tvar span_3 = root_3();\n\t\t\t\tvar text_3 = $.only_child(span_3, true);\n\n\t\t\t\t$.template_effect(() => $.set_text(text_3, $.get(token).value));\n\t\t\t\t$.append($$anchor, span_3);\n\t\t\t};\n\n\t\t\t$.if(node, ($$render) => {\n\t\t\t\tif ($.get(token).type === \"template\") $$render(consequent); else if ($.get(token).type === \"variable\") $$render(consequent_1, 1); else if ($.get(token).type === \"instruction\") $$render(consequent_2, 2); else $$render(alternate, -1);\n\t\t\t});\n\t\t}\n\n\t\t$.append($$anchor, fragment);\n\t});\n\n\t$.reset(div);\n\t$.template_effect(() => $.set_class(div, 1, $.clsx(className())));\n\t$.append($$anchor, div);\n\t$.pop();\n}\n\n$.delegate(['click']);","import type { Component } from \"svelte\";\nimport type { Editor, Content, Extensions } from \"@tiptap/core\";\nimport type { Template, ColorGradient } from \"@pixerate/editor\";\n\nimport EditableTextNodeEditorComponent from \"./EditableTextNodeEditor.svelte\";\nimport BubbleMenuComponent from \"./BubbleMenu.svelte\";\nimport TemplateRendererComponent from \"./TemplateRenderer.svelte\";\n\nexport * from \"./editor.svelte\";\n\nexport interface EditableTextNodeEditorProps {\n class?: string;\n content?: Content;\n showMenu?: boolean;\n editable?: boolean;\n editor?: Editor;\n extensions?: Extensions;\n onUpdate?: () => void;\n onFocus?: () => void;\n onBlur?: () => void;\n onCreate?: () => void;\n placeholder?: string;\n}\n\nexport interface BubbleMenuProps {\n editor?: Editor;\n class?: string;\n children?: any;\n}\n\nexport interface TemplateRendererProps {\n content: string;\n templates?: Template[];\n templateColorMap?: Map<string, ColorGradient>;\n resolve?: boolean;\n class?: string;\n onTemplateClick?: (templateName: string) => void;\n onVariableClick?: (variableName: string) => void;\n}\n\nexport const EditableTextNodeEditor = EditableTextNodeEditorComponent as unknown as Component<EditableTextNodeEditorProps>;\nexport const BubbleMenu = BubbleMenuComponent as unknown as Component<BubbleMenuProps>;\nexport const TemplateRenderer = TemplateRendererComponent as unknown as Component<TemplateRendererProps>;\n\nexport type {\n Template,\n TemplateVersion,\n Token,\n TokenType,\n ColorGradient,\n RichTextPresetOptions,\n} from \"@pixerate/editor\";\n"],"mappings":";AAA2C,OAAO;AAClD,YAAYA,QAAO;AACnB,SAAS,WAAW,eAAe;AACnC,OAAO,iBAAiB;;;;ACHxB,SAAS,cAAc;AACvB,SAAS,4BAA4B;AAC9B,IAAM,iBAAc,CAAI,SAAS,SAAS,YAAY,YAAY;AACvE,QAAM,EAAE,iBAAe,GAAK,cAAa,IAAK,WAAO,CAAA;AACrD,QAAM,gBAAgB,qBAAqB,eAAe;AAC1D,QAAM,SAAS,IAAI,OAAM;IACvB;IACA;IACA,YAAU,CAAA,GACL,eAAa,GACb,cAAU,CAAA,CAAA;IAEf,WAAW;OACR;;AAEL,SAAO;AACT;AACO,SAAS,qBAAqB,iBAAiB,IAAI,aAAU,CAAA,GAAO,UAAO,CAAA,GAAO;AACvF,MAAI;AACJ,SAAM;IACJ,IAAI,UAAU;AACZ,aAAO;IACT;IACA,MAAM,SAAS;AACb,uBAAiB,eAAe,SAAS,gBAAgB,YAAY,OAAO;AAC5E,aAAO;IACT;IACA,UAAU;AACR,UAAI,gBAAgB;AAClB,uBAAe,QAAO;AACtB,yBAAc;MAChB;IACF;;AAEJ;;;AD5BA,IAAI,OAAS,aAAU,iGAAiG;AACxH,IAAI,SAAW,aAAU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1B;AAEA,UAAI,YAAY,CAACA,cAAa;AAC7B,YAAI,SAAS,OAAO;AACpB,YAAI,SAAW,cAAW,QAAQ,IAAI;AAEtC,QAAE,mBAAgB,MAAQ,YAAS,QAAU,OAAI,KAAK,EAAE,KAAK,CAAC;AAC9D,QAAE,UAAOA,WAAU,MAAM;AAAA,MAC1B;AAEA,MAAE,MAAG,MAAM,CAAC,aAAa;AACxB,YAAM,OAAI,KAAK,EAAE,SAAS,WAAY,UAAS,UAAU;AAAA,iBAAc,OAAI,KAAK,EAAE,SAAS,WAAY,UAAS,cAAc,CAAC;AAAA,iBAAc,OAAI,KAAK,EAAE,SAAS,cAAe,UAAS,cAAc,CAAC;AAAA,YAAQ,UAAS,WAAW,EAAE;AAAA,MACvO,CAAC;AAAA,IACF;AAEA,IAAE,UAAOA,WAAU,QAAQ;AAAA,EAC5B,CAAC;AAED,EAAE,SAAM,GAAG;AACX,EAAE,mBAAgB,MAAQ,aAAU,KAAK,GAAK,QAAK,UAAU,CAAC,CAAC,CAAC;AAChE,EAAE,UAAO,UAAU,GAAG;AACtB,EAAE,OAAI;AACP;AAEE,YAAS,CAAC,OAAO,CAAC;;;ACnDb,IAAMC,0BAAyB;AAC/B,IAAMC,cAAa;AACnB,IAAMC,oBAAmB;","names":["$","$$anchor","$","onMount","onDestroy","root","$$anchor","$","root","root_1","$$anchor","EditableTextNodeEditor","BubbleMenu","TemplateRenderer"]}
1
+ {"version":3,"sources":["../src/EditableTextNodeEditor.svelte","../src/editor.svelte.ts","../src/BubbleMenu.svelte","../src/TemplateRenderer.svelte","../src/index.ts"],"sourcesContent":["import 'EditableTextNodeEditor.svelte.css';import 'svelte/internal/disclose-version';\nimport * as $ from 'svelte/internal/client';\nimport { onDestroy, onMount } from \"svelte\";\nimport Placeholder from \"@tiptap/extension-placeholder\";\nimport { initiateEditor } from \"./editor.svelte\";\n\nvar root = $.from_html(`<div class=\"flex items-center justify-center p-4 text-sm text-gray-500\">Loading editor...</div>`);\nvar root_1 = $.from_html(`<div draggable=\"false\"><!> <div class=\"pixerate-editor-content prose w-full max-w-none focus:outline-none\"></div></div>`);\n\nexport default function EditableTextNodeEditor($$anchor, $$props) {\n\t$.push($$props, true);\n\n\tlet className = $.prop($$props, 'class', 3, \"\"),\n\t\tcontent = $.prop($$props, 'content', 3, undefined),\n\t\tshowMenu = $.prop($$props, 'showMenu', 3, true),\n\t\teditable = $.prop($$props, 'editable', 3, true),\n\t\teditor = $.prop($$props, 'editor', 15),\n\t\textensions = $.prop($$props, 'extensions', 19, () => []),\n\t\tplaceholder = $.prop($$props, 'placeholder', 3, \"\");\n\n\tlet element = $.state(void 0);\n\n\t$.user_effect(() => {\n\t\tif (editor() && editor().isEditable !== editable()) {\n\t\t\teditor().setEditable(editable());\n\t\t}\n\t});\n\n\tonMount(() => {\n\t\teditor(initiateEditor(\n\t\t\t$.get(element),\n\t\t\tcontent(),\n\t\t\t[\n\t\t\t\tPlaceholder.configure({ placeholder: placeholder() }),\n\t\t\t\t...extensions()\n\t\t\t],\n\t\t\t{\n\t\t\t\teditable: editable(),\n\t\t\t\tonCreate: $$props.onCreate,\n\t\t\t\tonUpdate: $$props.onUpdate,\n\t\t\t\tonFocus() {\n\t\t\t\t\tif ($$props.onFocus) $$props.onFocus();\n\t\t\t\t},\n\n\t\t\t\tonBlur() {\n\t\t\t\t\tif ($$props.onBlur) $$props.onBlur();\n\t\t\t\t}\n\t\t\t}\n\t\t));\n\t});\n\n\tonDestroy(() => {\n\t\tif (editor()) {\n\t\t\teditor().destroy();\n\t\t}\n\t});\n\n\tvar div = root_1();\n\tvar node = $.child(div);\n\n\t{\n\t\tvar consequent = ($$anchor) => {\n\t\t\tvar div_1 = root();\n\n\t\t\t$.append($$anchor, div_1);\n\t\t};\n\n\t\t$.if(node, ($$render) => {\n\t\t\tif (!editor()) $$render(consequent);\n\t\t});\n\t}\n\n\tvar div_2 = $.sibling(node, 2);\n\n\t$.bind_this(div_2, ($$value) => $.set(element, $$value), () => $.get(element));\n\t$.reset(div);\n\t$.template_effect(() => $.set_class(div, 1, `pixerate-editor-container ${className()}`));\n\t$.append($$anchor, div);\n\t$.pop();\n}","import { Editor } from \"@tiptap/core\";\nimport { createRichTextPreset } from \"@pixerate/editor\";\nexport const initiateEditor = (element, content, extensions, options) => {\n const { richTextOptions, ...editorOptions } = options || {};\n const defaultPreset = createRichTextPreset(richTextOptions);\n const editor = new Editor({\n element,\n content,\n extensions: [\n ...defaultPreset,\n ...extensions ?? []\n ],\n autofocus: true,\n ...editorOptions\n });\n return editor;\n};\nexport function createReactiveEditor(initialContent = \"\", extensions = [], options = {}) {\n let editorInstance;\n return {\n get current() {\n return editorInstance;\n },\n mount(element) {\n editorInstance = initiateEditor(element, initialContent, extensions, options);\n return editorInstance;\n },\n destroy() {\n if (editorInstance) {\n editorInstance.destroy();\n editorInstance = void 0;\n }\n }\n };\n}\n","import 'svelte/internal/disclose-version';\nimport * as $ from 'svelte/internal/client';\nimport { BubbleMenuPlugin } from \"@tiptap/extension-bubble-menu\";\n\nvar root = $.from_html(`<div style=\"visibility: hidden;\"><!></div>`);\n\nexport default function BubbleMenu($$anchor, $$props) {\n\t$.push($$props, true);\n\n\tlet className = $.prop($$props, 'class', 3, \"flex h-fit w-fit items-center gap-1 rounded-md border border-gray-200 bg-white p-1 shadow-md\"),\n\t\tpluginKey = $.prop($$props, 'pluginKey', 3, \"bubbleMenu\"),\n\t\tshouldShow = $.prop($$props, 'shouldShow', 3, null),\n\t\tupdateDelay = $.prop($$props, 'updateDelay', 3, 250),\n\t\ttippyOptions = $.prop($$props, 'tippyOptions', 19, () => ({}));\n\n\tlet menuElement = $.state(void 0);\n\n\t$.user_effect(() => {\n\t\tif ($$props.editor && $.get(menuElement)) {\n\t\t\tconst plugin = BubbleMenuPlugin({\n\t\t\t\tpluginKey: pluginKey(),\n\t\t\t\teditor: $$props.editor,\n\t\t\t\telement: $.get(menuElement),\n\t\t\t\ttippyOptions: {\n\t\t\t\t\tduration: 100,\n\t\t\t\t\tappendTo: () => document.body,\n\t\t\t\t\t...tippyOptions()\n\t\t\t\t},\n\t\t\t\tshouldShow: shouldShow(),\n\t\t\t\tupdateDelay: updateDelay()\n\t\t\t});\n\n\t\t\t$$props.editor.registerPlugin(plugin);\n\n\t\t\treturn () => {\n\t\t\t\t$$props.editor.unregisterPlugin(pluginKey());\n\t\t\t};\n\t\t}\n\t});\n\n\tvar div = root();\n\tvar node = $.child(div);\n\n\t{\n\t\tvar consequent = ($$anchor) => {\n\t\t\tvar fragment = $.comment();\n\t\t\tvar node_1 = $.first_child(fragment);\n\n\t\t\t$.snippet(node_1, () => $$props.children);\n\t\t\t$.append($$anchor, fragment);\n\t\t};\n\n\t\t$.if(node, ($$render) => {\n\t\t\tif ($$props.children) $$render(consequent);\n\t\t});\n\t}\n\n\t$.reset(div);\n\t$.bind_this(div, ($$value) => $.set(menuElement, $$value), () => $.get(menuElement));\n\t$.template_effect(() => $.set_class(div, 1, $.clsx(className())));\n\t$.append($$anchor, div);\n\t$.pop();\n}","import 'svelte/internal/disclose-version';\nimport * as $ from 'svelte/internal/client';\nimport { tokenizePrompt, resolveTemplates } from \"@pixerate/editor\";\n\nvar root = $.from_html(`<span class=\"inline-flex items-center px-1.5 py-0.5 mx-0.5 text-xs font-semibold rounded-md border border-[var(--color-to)]/40 bg-gradient-to-r from-[var(--color-from)]/15 to-[var(--color-to)]/15 text-[var(--color-to)] hover:brightness-110 cursor-pointer transition-all\"> </span>`);\nvar root_1 = $.from_html(`<span class=\"inline-flex items-center px-1.5 py-0.5 mx-0.5 text-xs font-medium rounded-md border border-violet-400/40 bg-violet-400/15 text-violet-600 hover:brightness-110 cursor-pointer transition-all\"> </span>`);\nvar root_2 = $.from_html(`<span class=\"inline-flex items-center px-1.5 py-0.5 mx-0.5 text-xs italic font-medium rounded-md border border-rose-400/40 bg-rose-400/15 text-rose-600\"> </span>`);\nvar root_3 = $.from_html(`<span> </span>`);\nvar root_4 = $.from_html(`<div></div>`);\n\nexport default function TemplateRenderer($$anchor, $$props) {\n\t$.push($$props, true);\n\n\tlet templates = $.prop($$props, 'templates', 19, () => []),\n\t\tresolve = $.prop($$props, 'resolve', 3, false),\n\t\tclassName = $.prop($$props, 'class', 3, \"font-mono text-sm leading-relaxed whitespace-pre-wrap break-words\");\n\n\tlet displayText = $.derived(() => resolve() && templates().length > 0\n\t\t? resolveTemplates($$props.content, templates())\n\t\t: $$props.content);\n\n\tlet tokens = $.derived(() => tokenizePrompt($.get(displayText)));\n\tvar div = root_4();\n\n\t$.each(div, 21, () => $.get(tokens), $.index, ($$anchor, token) => {\n\t\tvar fragment = $.comment();\n\t\tvar node = $.first_child(fragment);\n\n\t\t{\n\t\t\tvar consequent = ($$anchor) => {\n\t\t\t\tconst colors = $.derived(() => $$props.templateColorMap?.get($.get(token).value) || { from: \"#f43f5e\", to: \"#8b5cf6\" });\n\t\t\t\tvar span = root();\n\t\t\t\tvar text = $.only_child(span, true);\n\n\t\t\t\t$.template_effect(() => {\n\t\t\t\t\t$.set_style(span, `--color-from: ${$.get(colors).from}; --color-to: ${$.get(colors).to};`);\n\t\t\t\t\t$.set_attribute(span, 'title', `Template: ${$.get(token).value}`);\n\t\t\t\t\t$.set_text(text, `{{${$.get(token).value}}}`);\n\t\t\t\t});\n\n\t\t\t\t$.delegated('click', span, () => $$props.onTemplateClick?.($.get(token).value));\n\t\t\t\t$.append($$anchor, span);\n\t\t\t};\n\n\t\t\tvar consequent_1 = ($$anchor) => {\n\t\t\t\tvar span_1 = root_1();\n\t\t\t\tvar text_1 = $.only_child(span_1, true);\n\n\t\t\t\t$.template_effect(() => {\n\t\t\t\t\t$.set_attribute(span_1, 'title', `Variable: ${$.get(token).value}`);\n\t\t\t\t\t$.set_text(text_1, `{${$.get(token).value}}`);\n\t\t\t\t});\n\n\t\t\t\t$.delegated('click', span_1, () => $$props.onVariableClick?.($.get(token).value));\n\t\t\t\t$.append($$anchor, span_1);\n\t\t\t};\n\n\t\t\tvar consequent_2 = ($$anchor) => {\n\t\t\t\tvar span_2 = root_2();\n\t\t\t\tvar text_2 = $.only_child(span_2, true);\n\n\t\t\t\t$.template_effect(() => {\n\t\t\t\t\t$.set_attribute(span_2, 'title', `Instruction: ${$.get(token).value}`);\n\t\t\t\t\t$.set_text(text_2, `__${$.get(token).value}__`);\n\t\t\t\t});\n\n\t\t\t\t$.append($$anchor, span_2);\n\t\t\t};\n\n\t\t\tvar alternate = ($$anchor) => {\n\t\t\t\tvar span_3 = root_3();\n\t\t\t\tvar text_3 = $.only_child(span_3, true);\n\n\t\t\t\t$.template_effect(() => $.set_text(text_3, $.get(token).value));\n\t\t\t\t$.append($$anchor, span_3);\n\t\t\t};\n\n\t\t\t$.if(node, ($$render) => {\n\t\t\t\tif ($.get(token).type === \"template\") $$render(consequent); else if ($.get(token).type === \"variable\") $$render(consequent_1, 1); else if ($.get(token).type === \"instruction\") $$render(consequent_2, 2); else $$render(alternate, -1);\n\t\t\t});\n\t\t}\n\n\t\t$.append($$anchor, fragment);\n\t});\n\n\t$.reset(div);\n\t$.template_effect(() => $.set_class(div, 1, $.clsx(className())));\n\t$.append($$anchor, div);\n\t$.pop();\n}\n\n$.delegate(['click']);","import type { Component } from \"svelte\";\nimport type { Editor, Content, Extensions } from \"@tiptap/core\";\nimport type { Template, ColorGradient } from \"@pixerate/editor\";\n\nimport EditableTextNodeEditorComponent from \"./EditableTextNodeEditor.svelte\";\nimport BubbleMenuComponent from \"./BubbleMenu.svelte\";\nimport TemplateRendererComponent from \"./TemplateRenderer.svelte\";\n\nexport * from \"./editor.svelte\";\n\nexport interface EditableTextNodeEditorProps {\n class?: string;\n content?: Content;\n showMenu?: boolean;\n editable?: boolean;\n editor?: Editor;\n extensions?: Extensions;\n onUpdate?: () => void;\n onFocus?: () => void;\n onBlur?: () => void;\n onCreate?: () => void;\n placeholder?: string;\n}\n\nexport interface BubbleMenuProps {\n editor?: Editor;\n class?: string;\n children?: any;\n}\n\nexport interface TemplateRendererProps {\n content: string;\n templates?: Template[];\n templateColorMap?: Map<string, ColorGradient>;\n resolve?: boolean;\n class?: string;\n onTemplateClick?: (templateName: string) => void;\n onVariableClick?: (variableName: string) => void;\n}\n\nexport const EditableTextNodeEditor = EditableTextNodeEditorComponent as unknown as Component<EditableTextNodeEditorProps>;\nexport const BubbleMenu = BubbleMenuComponent as unknown as Component<BubbleMenuProps>;\nexport const TemplateRenderer = TemplateRendererComponent as unknown as Component<TemplateRendererProps>;\n\nexport type {\n Template,\n TemplateVersion,\n Token,\n TokenType,\n ColorGradient,\n RichTextPresetOptions,\n} from \"@pixerate/editor\";\n"],"mappings":";AAA2C,OAAO;AAClD,YAAYA,QAAO;AACnB,SAAS,WAAW,eAAe;AACnC,OAAO,iBAAiB;;;;ACHxB,SAAS,cAAc;AACvB,SAAS,4BAA4B;AAC9B,IAAM,iBAAc,CAAI,SAAS,SAAS,YAAY,YAAY;AACvE,QAAM,EAAE,iBAAe,GAAK,cAAa,IAAK,WAAO,CAAA;AACrD,QAAM,gBAAgB,qBAAqB,eAAe;AAC1D,QAAM,SAAS,IAAI,OAAM;IACvB;IACA;IACA,YAAU,CAAA,GACL,eAAa,GACb,cAAU,CAAA,CAAA;IAEf,WAAW;OACR;;AAEL,SAAO;AACT;AACO,SAAS,qBAAqB,iBAAiB,IAAI,aAAU,CAAA,GAAO,UAAO,CAAA,GAAO;AACvF,MAAI;AACJ,SAAM;IACJ,IAAI,UAAU;AACZ,aAAO;IACT;IACA,MAAM,SAAS;AACb,uBAAiB,eAAe,SAAS,gBAAgB,YAAY,OAAO;AAC5E,aAAO;IACT;IACA,UAAU;AACR,UAAI,gBAAgB;AAClB,uBAAe,QAAO;AACtB,yBAAc;MAChB;IACF;;AAEJ;;;AD5BA,IAAI,OAAS,aAAU,iGAAiG;AACxH,IAAI,SAAW,aAAU,yHAAyH;AAEnI,SAAR,uBAAwC,UAAU,SAAS;AACjE,EAAE,QAAK,SAAS,IAAI;AAEpB,MAAI,YAAc,QAAK,SAAS,SAAS,GAAG,EAAE,GAC7C,U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AAS,gBAAkB,OAAI,KAAK,EAAE,KAAK,EAAE;AACrE,UAAE,YAAS,QAAQ,KAAO,OAAI,KAAK,EAAE,KAAK,IAAI;AAAA,QAC/C,CAAC;AAED,QAAE,UAAOA,WAAU,MAAM;AAAA,MAC1B;AAEA,UAAI,YAAY,CAACA,cAAa;AAC7B,YAAI,SAAS,OAAO;AACpB,YAAI,SAAW,cAAW,QAAQ,IAAI;AAEtC,QAAE,mBAAgB,MAAQ,YAAS,QAAU,OAAI,KAAK,EAAE,KAAK,CAAC;AAC9D,QAAE,UAAOA,WAAU,MAAM;AAAA,MAC1B;AAEA,MAAE,MAAG,MAAM,CAAC,aAAa;AACxB,YAAM,OAAI,KAAK,EAAE,SAAS,WAAY,UAAS,UAAU;AAAA,iBAAc,OAAI,KAAK,EAAE,SAAS,WAAY,UAAS,cAAc,CAAC;AAAA,iBAAc,OAAI,KAAK,EAAE,SAAS,cAAe,UAAS,cAAc,CAAC;AAAA,YAAQ,UAAS,WAAW,EAAE;AAAA,MACvO,CAAC;AAAA,IACF;AAEA,IAAE,UAAOA,WAAU,QAAQ;AAAA,EAC5B,CAAC;AAED,EAAE,SAAM,GAAG;AACX,EAAE,mBAAgB,MAAQ,aAAU,KAAK,GAAK,QAAK,UAAU,CAAC,CAAC,CAAC;AAChE,EAAE,UAAO,UAAU,GAAG;AACtB,EAAE,OAAI;AACP;AAEE,YAAS,CAAC,OAAO,CAAC;;;ACnDb,IAAMC,0BAAyB;AAC/B,IAAMC,cAAa;AACnB,IAAMC,oBAAmB;","names":["$","$$anchor","$","root","$$anchor","$","root","root_1","$$anchor","EditableTextNodeEditor","BubbleMenu","TemplateRenderer"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pixerate/editor-svelte",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "Svelte bindings and prompt/rich-text components for @pixerate/editor",
5
5
  "author": "Pixerate",
6
6
  "license": "MIT",
@@ -13,11 +13,11 @@
13
13
  "main": "./dist/index.js",
14
14
  "module": "./dist/index.js",
15
15
  "types": "./dist/index.d.ts",
16
- "svelte": "./src/index.ts",
16
+ "svelte": "./dist/index.js",
17
17
  "exports": {
18
18
  ".": {
19
19
  "types": "./dist/index.d.ts",
20
- "svelte": "./src/index.ts",
20
+ "svelte": "./dist/index.js",
21
21
  "import": "./dist/index.js",
22
22
  "default": "./dist/index.js"
23
23
  }
@@ -32,7 +32,7 @@
32
32
  "@tiptap/extension-placeholder": "^2.11.5",
33
33
  "@tiptap/pm": "^2.11.5",
34
34
  "@tiptap/starter-kit": "^2.11.5",
35
- "@pixerate/editor": "0.2.3"
35
+ "@pixerate/editor": "0.3.0"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "svelte": "^4.0.0 || ^5.0.0"
@@ -1,41 +1,54 @@
1
1
  <script lang="ts">
2
2
  import type { Editor } from "@tiptap/core";
3
- import BubbleMenuPlugin from "@tiptap/extension-bubble-menu";
4
- import { onMount, onDestroy } from "svelte";
3
+ import { BubbleMenuPlugin } from "@tiptap/extension-bubble-menu";
5
4
 
6
5
  interface Props {
7
6
  editor?: Editor;
8
7
  class?: string;
8
+ pluginKey?: any;
9
+ shouldShow?: ((props: any) => boolean) | null;
10
+ updateDelay?: number;
11
+ tippyOptions?: Record<string, any>;
9
12
  children?: import("svelte").Snippet;
10
13
  }
11
14
 
12
15
  let {
13
16
  editor,
14
- class: className = "flex items-center gap-1 bg-white border border-gray-200 shadow-md rounded-md p-1",
17
+ class: className = "flex h-fit w-fit items-center gap-1 rounded-md border border-gray-200 bg-white p-1 shadow-md",
18
+ pluginKey = "bubbleMenu",
19
+ shouldShow = null,
20
+ updateDelay = 250,
21
+ tippyOptions = {},
15
22
  children,
16
23
  }: Props = $props();
17
24
 
18
25
  let menuElement = $state<HTMLElement>();
19
26
 
20
- onMount(() => {
27
+ $effect(() => {
21
28
  if (editor && menuElement) {
22
- editor.registerPlugin(
23
- BubbleMenuPlugin.configure({
24
- element: menuElement,
25
- tippyOptions: { duration: 100 },
26
- })
27
- );
28
- }
29
- });
29
+ const plugin = BubbleMenuPlugin({
30
+ pluginKey,
31
+ editor,
32
+ element: menuElement,
33
+ tippyOptions: {
34
+ duration: 100,
35
+ appendTo: () => document.body,
36
+ ...tippyOptions,
37
+ },
38
+ shouldShow,
39
+ updateDelay,
40
+ });
41
+
42
+ editor.registerPlugin(plugin);
30
43
 
31
- onDestroy(() => {
32
- if (editor) {
33
- editor.unregisterPlugin("bubbleMenu");
44
+ return () => {
45
+ editor.unregisterPlugin(pluginKey);
46
+ };
34
47
  }
35
48
  });
36
49
  </script>
37
50
 
38
- <div bind:this={menuElement} class={className}>
51
+ <div bind:this={menuElement} class={className} style="visibility: hidden;">
39
52
  {#if children}
40
53
  {@render children()}
41
54
  {/if}