@open-wysiwyg-editor/solid 0.0.0-stage → 1.0.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.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["// SolidJS directive (Solid 1.6+, SolidStart). Directives only run in the browser, so it is SSR-safe.\n//\n// import { richText } from \"@open-wysiwyg-editor/solid\";\n// <div use:richText={{ content: html(), onUpdate: (e) => setHtml(e.getHTML()) }} />\nimport { createEffect, onCleanup, untrack, type Accessor } from \"solid-js\";\nimport {\n createEditor,\n forwardCallbacks,\n pickRuntimeOptions,\n sameRuntimeOptions,\n syncContent,\n type Editor,\n type EditorOptions,\n} from \"open-wysiwyg-editor\";\n\n// One install gives the whole API: StarterKit, getUI, types…\nexport * from \"open-wysiwyg-editor\";\n\nexport type RichTextOptions = Omit<EditorOptions, \"element\">;\n\n/**\n * Mounts the full editor in the element it is used on, and destroys it with the owner.\n * When `content` changes, the editor loads it, unless it is the HTML the editor just produced.\n * Callbacks and the runtime options (`editable`, `placeholder`, `aria*`, `dir`, `contentLang`)\n * follow changes; the rest is read once. `onCreate` receives the editor instance.\n */\nexport function richText(node: HTMLElement, accessor: Accessor<RichTextOptions | undefined>): Editor {\n const current = () => accessor() ?? {};\n const initial = untrack(current);\n let applied = initial.content;\n let runtime = pickRuntimeOptions(initial);\n const editor = createEditor({\n ...initial,\n element: node,\n ...forwardCallbacks(current),\n onUpdate: (e) => {\n applied = e.getHTML();\n current().onUpdate?.(e);\n },\n });\n\n createEffect(() => {\n const next = current();\n if (next.content !== applied) {\n applied = next.content;\n syncContent(editor, next.content);\n }\n const nextRuntime = pickRuntimeOptions(next);\n if (!sameRuntimeOptions(runtime, nextRuntime)) {\n runtime = nextRuntime;\n editor.setOptions(nextRuntime);\n }\n });\n\n onCleanup(() => editor.destroy());\n return editor;\n}\n\n// Types `use:richText={…}` in JSX.\ndeclare module \"solid-js\" {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace JSX {\n interface Directives {\n richText: RichTextOptions;\n }\n }\n}\n"],"mappings":";AAIA,SAAS,cAAc,WAAW,eAA8B;AAChE;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AAGP,cAAc;AAUP,SAAS,SAAS,MAAmB,UAAyD;AACnG,QAAM,UAAU,MAAM,SAAS,KAAK,CAAC;AACrC,QAAM,UAAU,QAAQ,OAAO;AAC/B,MAAI,UAAU,QAAQ;AACtB,MAAI,UAAU,mBAAmB,OAAO;AACxC,QAAM,SAAS,aAAa;AAAA,IAC1B,GAAG;AAAA,IACH,SAAS;AAAA,IACT,GAAG,iBAAiB,OAAO;AAAA,IAC3B,UAAU,CAAC,MAAM;AACf,gBAAU,EAAE,QAAQ;AACpB,cAAQ,EAAE,WAAW,CAAC;AAAA,IACxB;AAAA,EACF,CAAC;AAED,eAAa,MAAM;AACjB,UAAM,OAAO,QAAQ;AACrB,QAAI,KAAK,YAAY,SAAS;AAC5B,gBAAU,KAAK;AACf,kBAAY,QAAQ,KAAK,OAAO;AAAA,IAClC;AACA,UAAM,cAAc,mBAAmB,IAAI;AAC3C,QAAI,CAAC,mBAAmB,SAAS,WAAW,GAAG;AAC7C,gBAAU;AACV,aAAO,WAAW,WAAW;AAAA,IAC/B;AAAA,EACF,CAAC;AAED,YAAU,MAAM,OAAO,QAAQ,CAAC;AAChC,SAAO;AACT;","names":[]}