solid-tiptap 0.8.0 → 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.
package/README.md CHANGED
@@ -1,39 +1,47 @@
1
1
  # solid-tiptap
2
2
 
3
- > SolidJS bindings for [tiptap](https://www.tiptap.dev/)
3
+ > SolidJS bindings for [Tiptap](https://tiptap.dev/)
4
4
 
5
- [![NPM](https://img.shields.io/npm/v/solid-tiptap.svg)](https://www.npmjs.com/package/solid-tiptap) [![JavaScript Style Guide](https://badgen.net/badge/code%20style/airbnb/ff5a5f?icon=airbnb)](https://github.com/airbnb/javascript) [![Open in StackBlitz](https://img.shields.io/badge/Open%20in-StackBlitz-blue?style=flat-square&logo=stackblitz)](https://stackblitz.com/github/lxsmnsyc/solid-tiptap/tree/main/examples/simple-example)
5
+ [![NPM](https://img.shields.io/npm/v/solid-tiptap.svg)](https://www.npmjs.com/package/solid-tiptap) [![Open in StackBlitz](https://img.shields.io/badge/Open%20in-StackBlitz-blue?style=flat-square&logo=stackblitz)](https://stackblitz.com/github/lxsmnsyc/solid-tiptap/tree/main/examples/simple-example)
6
6
 
7
7
  ![solid-tiptap example](https://github.com/lxsmnsyc/solid-tiptap/blob/main/images/solid-tiptap.png?raw=true)
8
8
 
9
9
  ## Install
10
10
 
11
11
  ```bash
12
- npm i @tiptap/core @tiptap/pm solid-tiptap
12
+ npm i solid-tiptap @tiptap/core @tiptap/pm
13
13
  ```
14
14
 
15
15
  ```bash
16
- yarn add @tiptap/core @tiptap/pm solid-tiptap
16
+ yarn add solid-tiptap @tiptap/core @tiptap/pm
17
17
  ```
18
18
 
19
19
  ```bash
20
- pnpm add @tiptap/core @tiptap/pm solid-tiptap
20
+ pnpm add solid-tiptap @tiptap/core @tiptap/pm
21
21
  ```
22
22
 
23
+ You also need the Tiptap extensions you plan to use, such as `@tiptap/starter-kit`.
24
+
25
+ ## Requirements
26
+
27
+ - `solid-js` 2.0 or later.
28
+ - `@tiptap/core` and `@tiptap/pm` 3.x.
29
+ - Node.js 22.12 or later, if you import the package in Node.js.
30
+
31
+ Solid 1.x users: use the `solid-1` branch, or the previous major (`solid-tiptap@0.9` for Solid 1.x, `solid-tiptap@0.7` for Solid 1.x with Tiptap 2).
32
+
23
33
  ## Usage
24
34
 
25
- ```jsx
26
- import { createTiptapEditor } from 'solid-tiptap';
35
+ ```tsx
27
36
  import StarterKit from '@tiptap/starter-kit';
37
+ import { createTiptapEditor } from 'solid-tiptap';
28
38
 
29
39
  function App() {
30
40
  let ref!: HTMLDivElement;
31
41
 
32
42
  const editor = createTiptapEditor(() => ({
33
- element: ref!,
34
- extensions: [
35
- StarterKit,
36
- ],
43
+ element: ref,
44
+ extensions: [StarterKit],
37
45
  content: `<p>Example Text</p>`,
38
46
  }));
39
47
 
@@ -41,115 +49,190 @@ function App() {
41
49
  }
42
50
  ```
43
51
 
44
- ### Transactions
52
+ `createTiptapEditor` returns an accessor for the editor.
45
53
 
46
- `createEditorTransaction` provides a way to reactively subscribe to editor changes.
54
+ - The editor is created after the component mounts, once `element` is set. The accessor returns `undefined` until then.
55
+ - The options function is tracked. When a signal it reads changes, the old editor is destroyed and a new one is created.
56
+ - The editor is destroyed when the owning component unmounts.
47
57
 
48
- ```ts
49
- const isBold = createEditorTransaction(
50
- () => props.editor, // Editor instance from createTiptapEditor
51
- (editor) => editor.isActive("bold")
52
- );
58
+ Because the options are tracked, read signals that should not recreate the editor with `untrack`.
53
59
 
54
- createEffect(() => {
55
- if (isBold()) {
56
- // do something
57
- }
58
- });
60
+ ```tsx
61
+ import { untrack } from 'solid-js';
62
+
63
+ const editor = createTiptapEditor(() => ({
64
+ element: ref,
65
+ extensions: [StarterKit],
66
+ // Changing `initialContent` later does not recreate the editor.
67
+ content: untrack(initialContent),
68
+ }));
59
69
  ```
60
70
 
61
- There are out-of-the-box utilities that wraps `createEditorTransaction` based on the [Editor API](https://www.tiptap.dev/api/editor):
71
+ Use the editor's own commands to update it after it is created.
72
+
73
+ ```ts
74
+ editor()?.commands.setContent('<p>New content</p>');
75
+ editor()?.setEditable(false);
76
+ ```
62
77
 
63
- - `useEditorHTML`: reactively subscribe to `getEditorHTML`.
78
+ ### Passing the editor to other components
64
79
 
65
- ```js
66
- const html = useEditorHTML(() => props.editor);
80
+ Render the components that need the editor inside `<Show>`, so they only run once the editor exists.
67
81
 
68
- createEffect(() => {
69
- updateHTML(html());
70
- });
82
+ ```tsx
83
+ const editor = createTiptapEditor(() => ({ ... }));
84
+
85
+ <Show when={editor()} keyed>
86
+ {(instance) => <Toolbar editor={instance} />}
87
+ </Show>
71
88
  ```
72
89
 
73
- - `useEditorIsActive`: reactively subscribe to `isActive`.
90
+ `keyed` passes the editor itself to the children. Without it, Solid passes an accessor, so you would write `editor={instance()}`.
74
91
 
75
- ```js
76
- const isHeading = useEditorIsActive(
77
- () => props.editor,
78
- () => "heading",
79
- {
80
- level: 1,
81
- }
82
- );
92
+ ### Signal refs
83
93
 
84
- createEffect(() => {
85
- if (isHeading()) {
86
- // do something
87
- }
88
- });
94
+ `element` also accepts `undefined` and `null`. The editor waits until the element is set, so a signal ref works without a non-null assertion.
95
+
96
+ ```tsx
97
+ const [element, setElement] = createSignal<HTMLDivElement>();
98
+
99
+ const editor = createTiptapEditor(() => ({
100
+ element: element(),
101
+ extensions: [StarterKit],
102
+ }));
103
+
104
+ return <div ref={setElement} />;
89
105
  ```
90
106
 
91
- - `useEditorIsEditable`: reactively subscribe to `isEditable`.
107
+ ### Bubble and floating menus
92
108
 
93
- ```js
94
- const isEditable = useEditorIsEditable(() => props.editor);
109
+ Tiptap's `BubbleMenu` and `FloatingMenu` extensions take an `element` option. Pass a mounted element the same way you pass the editor element.
95
110
 
96
- createEffect(() => {
97
- if (isEditable()) {
98
- // do something
99
- }
100
- });
111
+ ```tsx
112
+ import BubbleMenu from '@tiptap/extension-bubble-menu';
113
+
114
+ function App() {
115
+ let container!: HTMLDivElement;
116
+ let menu!: HTMLDivElement;
117
+
118
+ const editor = createTiptapEditor(() => ({
119
+ element: container,
120
+ extensions: [StarterKit, BubbleMenu.configure({ element: menu })],
121
+ }));
122
+
123
+ return (
124
+ <>
125
+ <div ref={menu}>
126
+ <Show when={editor()} keyed>
127
+ {(instance) => <Toolbar editor={instance} />}
128
+ </Show>
129
+ </div>
130
+ <div ref={container} />
131
+ </>
132
+ );
133
+ }
101
134
  ```
102
135
 
103
- - `useEditorIsEmpty`: reactively subscribe to `isEmpty`.
136
+ ### Reading editor state
104
137
 
105
- ```js
106
- const isEmpty = useEditorIsEmpty(() => props.editor);
138
+ Tiptap does not notify Solid when the editor changes. `createEditorTransaction` reads a value again after every editor transaction, so you can use it in JSX and effects.
107
139
 
108
- createEffect(() => {
109
- if (isEmpty()) {
110
- // do something
140
+ ```ts
141
+ import { createEditorTransaction } from 'solid-tiptap';
142
+
143
+ const isBold = createEditorTransaction(
144
+ () => props.editor,
145
+ (editor) => editor.isActive('bold'),
146
+ );
147
+
148
+ createEffect(isBold, (bold) => {
149
+ if (bold) {
150
+ // ...
111
151
  }
112
152
  });
113
153
  ```
114
154
 
115
- - `useEditorIsFocused`: reactively subscribe to `isFocused`.
155
+ Like any Solid 2 signal, the new value is visible after Solid applies queued updates. Call `flush()` from `solid-js` if you need it right away, for example in a test.
116
156
 
117
- ```js
118
- const isFocused = useEditorIsFocused(() => props.editor);
157
+ ```ts
158
+ editor.commands.setContent('<p>Bye</p>');
159
+ flush();
160
+ html(); // '<p>Bye</p>'
161
+ ```
119
162
 
120
- createEffect(() => {
121
- if (isFocused()) {
122
- // do something
123
- }
124
- });
163
+ The read function receives whatever the first accessor returns. If that can be `undefined`, handle it in the read function.
164
+
165
+ ```ts
166
+ const length = createEditorTransaction(
167
+ editor,
168
+ (instance) => instance?.state.doc.textContent.length ?? 0,
169
+ );
125
170
  ```
126
171
 
127
- - `useEditorJSON`: reactively subscribe to `getJSON`.
172
+ ### Helpers
128
173
 
129
- ```js
130
- const json = useEditorJSON(() => props.editor);
174
+ Each helper wraps `createEditorTransaction` for one part of the [Editor API](https://tiptap.dev/docs/editor/api/editor). Each takes an editor accessor, which may return `undefined`. Each returns an accessor that returns `undefined` while there is no editor.
131
175
 
132
- createEffect(() => {
133
- const data = json();
176
+ | Helper | Reads | Returns |
177
+ | --------------------- | ---------------------- | ------------- |
178
+ | `useEditorHTML` | `editor.getHTML()` | `string` |
179
+ | `useEditorJSON` | `editor.getJSON()` | `JSONContent` |
180
+ | `useEditorIsActive` | `editor.isActive(...)` | `boolean` |
181
+ | `useEditorIsEmpty` | `editor.isEmpty` | `boolean` |
182
+ | `useEditorIsEditable` | `editor.isEditable` | `boolean` |
183
+ | `useEditorIsFocused` | `editor.isFocused` | `boolean` |
184
+
185
+ ```ts
186
+ const html = useEditorHTML(editor);
134
187
 
188
+ createEffect(html, (value) => {
189
+ saveHTML(value);
190
+ });
191
+ ```
192
+
193
+ ```ts
194
+ const json = useEditorJSON(editor);
195
+
196
+ createEffect(json, (data) => {
135
197
  if (data) {
136
198
  uploadJSON(data);
137
199
  }
138
200
  });
139
201
  ```
140
202
 
141
- ## Tips
203
+ `useEditorIsActive` takes a name accessor with optional attributes, a name accessor alone, or attributes alone.
142
204
 
143
- Since `createTiptapEditor` may return `undefined` (the instanciation is scheduled), and you're planning to pass it to another component (e.g. creating `BubbleMenu` or Toolbar), it is recommended to use ternary evaluation (e.g. `<Show>`) to check if the editor is `undefined` or not.
205
+ ```ts
206
+ // A node or mark by name.
207
+ const isBold = useEditorIsActive(editor, () => 'bold');
144
208
 
145
- ```js
146
- const editor = createTiptapEditor(() => ({ ... }));
209
+ // A node or mark by name and attributes.
210
+ const isHeading = useEditorIsActive(editor, () => 'heading', { level: 1 });
147
211
 
148
- <Show when={editor()}>
149
- {(instance) => <EditorMenu editor={instance} />}
150
- </Show>
212
+ // Any node or mark with these attributes.
213
+ const isCentered = useEditorIsActive(editor, { textAlign: 'center' });
151
214
  ```
152
215
 
216
+ ## API
217
+
218
+ ### `createTiptapEditor(options)`
219
+
220
+ Creates a Tiptap editor. Also exported as `createEditor`, `useEditor` and `useTiptapEditor`.
221
+
222
+ - `options` is a function that returns Tiptap's [editor options](https://tiptap.dev/docs/editor/api/editor#settings). No editor is created while `element` is `undefined` or `null`.
223
+ - Returns `() => Editor | undefined`.
224
+
225
+ ### `createEditorTransaction(editor, read)`
226
+
227
+ - `editor` is a function that returns an `Editor` or `undefined`.
228
+ - `read` is called with the result of `editor()`. Its result is returned by the accessor.
229
+ - Returns an accessor that runs `read` again after every editor transaction.
230
+
231
+ ### Types
232
+
233
+ - `UseEditorOptions` is the options type for `createTiptapEditor`. Its `element` is `HTMLElement | null | undefined`.
234
+ - `BaseEditorOptions` is Tiptap's `EditorOptions` without `element`, with every field optional.
235
+
153
236
  ## Sponsors
154
237
 
155
238
  ![Sponsors](https://github.com/lxsmnsyc/sponsors/blob/main/sponsors.svg?raw=true)
@@ -0,0 +1,37 @@
1
+ import { Editor, EditorOptions, JSONContent } from "@tiptap/core";
2
+ //#region src/Editor.d.ts
3
+ type EditorRef = Editor | ((editor: Editor) => void);
4
+ type BaseEditorOptions = Omit<Partial<EditorOptions>, 'element'>;
5
+ interface UseEditorOptions extends BaseEditorOptions {
6
+ element: HTMLElement | null | undefined;
7
+ }
8
+ /**
9
+ * Reads a value from the editor and reads it again after every transaction.
10
+ * `read` also receives `undefined` while `instance` returns no editor.
11
+ */
12
+ export declare function createEditorTransaction<T, V extends Editor | undefined>(instance: () => V, read: (value: V) => T): () => T;
13
+ /**
14
+ * Creates a Tiptap editor from the given options.
15
+ * The editor is created once `element` is set.
16
+ * It is destroyed and created again when a signal read by `props` changes.
17
+ * It is also destroyed when the owner is disposed.
18
+ */
19
+ declare function useEditor(props: () => UseEditorOptions): () => Editor | undefined;
20
+ /** Returns the editor content as HTML. */
21
+ export declare function useEditorHTML(editor: () => Editor | undefined): () => string | undefined;
22
+ /** Returns the editor content as Tiptap JSON. */
23
+ export declare function useEditorJSON(editor: () => Editor | undefined): () => JSONContent | undefined;
24
+ /**
25
+ * Returns whether the node or mark at the selection is active.
26
+ * Pass a node or mark name with optional attributes, or only the attributes.
27
+ */
28
+ export declare function useEditorIsActive(editor: () => Editor | undefined, ...args: [name: () => string, options?: Record<string, unknown>] | [options: Record<string, unknown>]): () => boolean | undefined;
29
+ /** Returns whether the editor has no content. */
30
+ export declare function useEditorIsEmpty(editor: () => Editor | undefined): () => boolean | undefined;
31
+ /** Returns whether the editor accepts input. */
32
+ export declare function useEditorIsEditable(editor: () => Editor | undefined): () => boolean | undefined;
33
+ /** Returns whether the editor has focus. */
34
+ export declare function useEditorIsFocused(editor: () => Editor | undefined): () => boolean | undefined;
35
+ //#endregion
36
+ export { type BaseEditorOptions, type EditorRef, type UseEditorOptions, useEditor as createEditor, useEditor as createTiptapEditor, useEditor, useEditor as useTiptapEditor };
37
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/Editor.ts"],"mappings":";;KAIY,YAAY,WAAW,QAAQ;KAE/B,oBAAoB,KAAK,QAAQ;UAE5B,yBAAyB;EAExC,SAAS;;;;;;wBAOK,wBAAwB,GAAG,UAAU,oBACnD,gBAAgB,GAChB,OAAO,OAAO,MAAM,UACb;;;;;;;iBA8Be,UAAU,aAAa,yBAAyB;;wBA6BxD,cAAc,cAAc;;wBAK5B,cAAc,cAAc,2BAA2B;;;;;wBAQvD,kBACd,cAAc,uBACX,OACE,oBAAoB,UAAU,4BAC9B,SAAS;;wBAeA,iBAAiB,cAAc;;wBAK/B,oBAAoB,cAAc;;wBAKlC,mBAAmB,cAAc"}
package/dist/index.js ADDED
@@ -0,0 +1,85 @@
1
+ import { Editor } from "@tiptap/core";
2
+ import { createEffect, createSignal, onSettled } from "solid-js";
3
+ //#region src/Editor.ts
4
+ /**
5
+ * Reads a value from the editor and reads it again after every transaction.
6
+ * `read` also receives `undefined` while `instance` returns no editor.
7
+ */
8
+ function createEditorTransaction(instance, read) {
9
+ const [depend, update] = createSignal(void 0, {
10
+ equals: false,
11
+ ownedWrite: true
12
+ });
13
+ createEffect(instance, (editor) => {
14
+ if (!editor) return;
15
+ const forceUpdate = () => {
16
+ update();
17
+ };
18
+ editor.on("transaction", forceUpdate);
19
+ return () => {
20
+ editor.off("transaction", forceUpdate);
21
+ };
22
+ });
23
+ return () => {
24
+ depend();
25
+ return read(instance());
26
+ };
27
+ }
28
+ /**
29
+ * Creates a Tiptap editor from the given options.
30
+ * The editor is created once `element` is set.
31
+ * It is destroyed and created again when a signal read by `props` changes.
32
+ * It is also destroyed when the owner is disposed.
33
+ */
34
+ function useEditor(props) {
35
+ const [signal, setSignal] = createSignal(void 0, { ownedWrite: true });
36
+ const [settled, setSettled] = createSignal(false, { ownedWrite: true });
37
+ onSettled(() => {
38
+ setSettled(true);
39
+ });
40
+ createEffect(() => settled() ? props() : void 0, (options) => {
41
+ if (!options?.element) return;
42
+ const instance = new Editor({ ...options });
43
+ setSignal(instance);
44
+ return () => {
45
+ instance.destroy();
46
+ };
47
+ });
48
+ return signal;
49
+ }
50
+ /** Returns the editor content as HTML. */
51
+ function useEditorHTML(editor) {
52
+ return createEditorTransaction(editor, (instance) => instance?.getHTML());
53
+ }
54
+ /** Returns the editor content as Tiptap JSON. */
55
+ function useEditorJSON(editor) {
56
+ return createEditorTransaction(editor, (instance) => instance?.getJSON());
57
+ }
58
+ /**
59
+ * Returns whether the node or mark at the selection is active.
60
+ * Pass a node or mark name with optional attributes, or only the attributes.
61
+ */
62
+ function useEditorIsActive(editor, ...args) {
63
+ return createEditorTransaction(editor, (instance) => {
64
+ if (args.length === 2) return instance?.isActive(args[0](), args[1]);
65
+ const [first] = args;
66
+ if (typeof first === "function") return instance?.isActive(first());
67
+ return instance?.isActive(first);
68
+ });
69
+ }
70
+ /** Returns whether the editor has no content. */
71
+ function useEditorIsEmpty(editor) {
72
+ return createEditorTransaction(editor, (instance) => instance?.isEmpty);
73
+ }
74
+ /** Returns whether the editor accepts input. */
75
+ function useEditorIsEditable(editor) {
76
+ return createEditorTransaction(editor, (instance) => instance?.isEditable);
77
+ }
78
+ /** Returns whether the editor has focus. */
79
+ function useEditorIsFocused(editor) {
80
+ return createEditorTransaction(editor, (instance) => instance?.isFocused);
81
+ }
82
+ //#endregion
83
+ export { useEditor as createEditor, useEditor as createTiptapEditor, useEditor, useEditor as useTiptapEditor, createEditorTransaction, useEditorHTML, useEditorIsActive, useEditorIsEditable, useEditorIsEmpty, useEditorIsFocused, useEditorJSON };
84
+
85
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/Editor.ts"],"sourcesContent":["import type { EditorOptions, JSONContent } from '@tiptap/core';\nimport { Editor } from '@tiptap/core';\nimport { createEffect, createSignal, onSettled } from 'solid-js';\n\nexport type EditorRef = Editor | ((editor: Editor) => void);\n\nexport type BaseEditorOptions = Omit<Partial<EditorOptions>, 'element'>;\n\nexport interface UseEditorOptions extends BaseEditorOptions {\n // The editor is created once this is set.\n element: HTMLElement | null | undefined;\n}\n\n/**\n * Reads a value from the editor and reads it again after every transaction.\n * `read` also receives `undefined` while `instance` returns no editor.\n */\nexport function createEditorTransaction<T, V extends Editor | undefined>(\n instance: () => V,\n read: (value: V) => T,\n): () => T {\n // Tiptap emits transactions from its own listeners, which can run inside a\n // reactive scope, so the signal allows writes from owned scopes.\n const [depend, update] = createSignal(undefined, { equals: false, ownedWrite: true });\n\n createEffect(instance, (editor) => {\n if (!editor) {\n return undefined;\n }\n const forceUpdate = (): void => {\n update();\n };\n editor.on('transaction', forceUpdate);\n return () => {\n editor.off('transaction', forceUpdate);\n };\n });\n\n return () => {\n depend();\n return read(instance());\n };\n}\n\n/**\n * Creates a Tiptap editor from the given options.\n * The editor is created once `element` is set.\n * It is destroyed and created again when a signal read by `props` changes.\n * It is also destroyed when the owner is disposed.\n */\nexport default function useEditor(props: () => UseEditorOptions): () => Editor | undefined {\n // The editor is written from the effect, which runs in an owned scope.\n const [signal, setSignal] = createSignal<Editor | undefined>(undefined, { ownedWrite: true });\n\n // Refs are assigned after the component body runs. Reading the options only\n // after the first settle lets `element` come from a plain `let` ref too.\n const [settled, setSettled] = createSignal(false, { ownedWrite: true });\n onSettled(() => {\n setSettled(true);\n });\n\n createEffect(\n () => (settled() ? props() : undefined),\n (options) => {\n if (!options?.element) {\n return undefined;\n }\n const instance = new Editor({ ...options });\n setSignal(instance);\n return () => {\n instance.destroy();\n };\n },\n );\n\n return signal;\n}\n\n/** Returns the editor content as HTML. */\nexport function useEditorHTML(editor: () => Editor | undefined): () => string | undefined {\n return createEditorTransaction(editor, (instance) => instance?.getHTML());\n}\n\n/** Returns the editor content as Tiptap JSON. */\nexport function useEditorJSON(editor: () => Editor | undefined): () => JSONContent | undefined {\n return createEditorTransaction(editor, (instance) => instance?.getJSON());\n}\n\n/**\n * Returns whether the node or mark at the selection is active.\n * Pass a node or mark name with optional attributes, or only the attributes.\n */\nexport function useEditorIsActive(\n editor: () => Editor | undefined,\n ...args:\n | [name: () => string, options?: Record<string, unknown>]\n | [options: Record<string, unknown>]\n): () => boolean | undefined {\n return createEditorTransaction(editor, (instance) => {\n if (args.length === 2) {\n return instance?.isActive(args[0](), args[1]);\n }\n const [first] = args;\n if (typeof first === 'function') {\n return instance?.isActive(first());\n }\n return instance?.isActive(first);\n });\n}\n\n/** Returns whether the editor has no content. */\nexport function useEditorIsEmpty(editor: () => Editor | undefined): () => boolean | undefined {\n return createEditorTransaction(editor, (instance) => instance?.isEmpty);\n}\n\n/** Returns whether the editor accepts input. */\nexport function useEditorIsEditable(editor: () => Editor | undefined): () => boolean | undefined {\n return createEditorTransaction(editor, (instance) => instance?.isEditable);\n}\n\n/** Returns whether the editor has focus. */\nexport function useEditorIsFocused(editor: () => Editor | undefined): () => boolean | undefined {\n return createEditorTransaction(editor, (instance) => instance?.isFocused);\n}\n"],"mappings":";;;;;;;AAiBA,SAAgB,wBACd,UACA,MACS;CAGT,MAAM,CAAC,QAAQ,UAAU,aAAa,KAAA,GAAW;EAAE,QAAQ;EAAO,YAAY;CAAK,CAAC;CAEpF,aAAa,WAAW,WAAW;EACjC,IAAI,CAAC,QACH;EAEF,MAAM,oBAA0B;GAC9B,OAAO;EACT;EACA,OAAO,GAAG,eAAe,WAAW;EACpC,aAAa;GACX,OAAO,IAAI,eAAe,WAAW;EACvC;CACF,CAAC;CAED,aAAa;EACX,OAAO;EACP,OAAO,KAAK,SAAS,CAAC;CACxB;AACF;;;;;;;AAQA,SAAwB,UAAU,OAAyD;CAEzF,MAAM,CAAC,QAAQ,aAAa,aAAiC,KAAA,GAAW,EAAE,YAAY,KAAK,CAAC;CAI5F,MAAM,CAAC,SAAS,cAAc,aAAa,OAAO,EAAE,YAAY,KAAK,CAAC;CACtE,gBAAgB;EACd,WAAW,IAAI;CACjB,CAAC;CAED,mBACS,QAAQ,IAAI,MAAM,IAAI,KAAA,IAC5B,YAAY;EACX,IAAI,CAAC,SAAS,SACZ;EAEF,MAAM,WAAW,IAAI,OAAO,EAAE,GAAG,QAAQ,CAAC;EAC1C,UAAU,QAAQ;EAClB,aAAa;GACX,SAAS,QAAQ;EACnB;CACF,CACF;CAEA,OAAO;AACT;;AAGA,SAAgB,cAAc,QAA4D;CACxF,OAAO,wBAAwB,SAAS,aAAa,UAAU,QAAQ,CAAC;AAC1E;;AAGA,SAAgB,cAAc,QAAiE;CAC7F,OAAO,wBAAwB,SAAS,aAAa,UAAU,QAAQ,CAAC;AAC1E;;;;;AAMA,SAAgB,kBACd,QACA,GAAG,MAGwB;CAC3B,OAAO,wBAAwB,SAAS,aAAa;EACnD,IAAI,KAAK,WAAW,GAClB,OAAO,UAAU,SAAS,KAAK,EAAE,CAAC,GAAG,KAAK,EAAE;EAE9C,MAAM,CAAC,SAAS;EAChB,IAAI,OAAO,UAAU,YACnB,OAAO,UAAU,SAAS,MAAM,CAAC;EAEnC,OAAO,UAAU,SAAS,KAAK;CACjC,CAAC;AACH;;AAGA,SAAgB,iBAAiB,QAA6D;CAC5F,OAAO,wBAAwB,SAAS,aAAa,UAAU,OAAO;AACxE;;AAGA,SAAgB,oBAAoB,QAA6D;CAC/F,OAAO,wBAAwB,SAAS,aAAa,UAAU,UAAU;AAC3E;;AAGA,SAAgB,mBAAmB,QAA6D;CAC9F,OAAO,wBAAwB,SAAS,aAAa,UAAU,SAAS;AAC1E"}
package/package.json CHANGED
@@ -1,68 +1,65 @@
1
1
  {
2
- "version": "0.8.0",
3
- "type": "module",
4
- "types": "./dist/types/index.d.ts",
5
- "main": "./dist/cjs/production/index.cjs",
6
- "module": "./dist/esm/production/index.mjs",
7
- "exports": {
8
- ".": {
9
- "types": "./dist/types/index.d.ts",
10
- "development": {
11
- "require": "./dist/cjs/development/index.cjs",
12
- "import": "./dist/esm/development/index.mjs"
13
- },
14
- "require": "./dist/cjs/production/index.cjs",
15
- "import": "./dist/esm/production/index.mjs"
16
- }
2
+ "name": "solid-tiptap",
3
+ "version": "1.0.0",
4
+ "description": "SolidJS bindings for Tiptap",
5
+ "keywords": [
6
+ "editor",
7
+ "prosemirror",
8
+ "rich-text",
9
+ "solid-js",
10
+ "tiptap"
11
+ ],
12
+ "homepage": "https://github.com/lxsmnsyc/solid-tiptap/tree/main/packages/solid-tiptap",
13
+ "bugs": {
14
+ "url": "https://github.com/lxsmnsyc/solid-tiptap/issues"
15
+ },
16
+ "license": "MIT",
17
+ "author": "Alexis Munsayac",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/lxsmnsyc/solid-tiptap.git",
21
+ "directory": "packages/solid-tiptap"
17
22
  },
18
23
  "files": [
19
24
  "dist",
20
25
  "src"
21
26
  ],
22
- "engines": {
23
- "node": ">=10"
27
+ "type": "module",
28
+ "sideEffects": false,
29
+ "exports": {
30
+ ".": "./dist/index.js",
31
+ "./package.json": "./package.json"
32
+ },
33
+ "publishConfig": {
34
+ "access": "public"
24
35
  },
25
- "license": "MIT",
26
- "keywords": [
27
- "pridepack"
28
- ],
29
- "name": "solid-tiptap",
30
36
  "devDependencies": {
31
- "@tiptap/core": "^3.0.1",
32
- "@tiptap/pm": "^3.0.1",
33
- "@types/node": "^24.2.0",
34
- "pridepack": "2.6.4",
35
- "solid-js": "^1.9.7",
36
- "tslib": "^2.8.1",
37
- "typescript": "^5.9.2"
37
+ "@solidjs/vite-plugin": "3.0.0",
38
+ "@solidjs/web": "2.0.0",
39
+ "@tiptap/core": "^3.31.4",
40
+ "@tiptap/pm": "^3.31.4",
41
+ "@tiptap/starter-kit": "^3.31.4",
42
+ "@types/node": "^26.6.4",
43
+ "jsdom": "^30.1.1",
44
+ "publint": "^0.3.25",
45
+ "solid-js": "2.0.0",
46
+ "tsdown": "^0.23.0",
47
+ "typescript": "^7.0.2",
48
+ "vitest": "^5.0.3"
38
49
  },
39
50
  "peerDependencies": {
40
51
  "@tiptap/core": "^3",
41
52
  "@tiptap/pm": "^3",
42
- "solid-js": "^1.7"
43
- },
44
- "scripts": {
45
- "prepublishOnly": "pridepack clean && pridepack build",
46
- "build": "pridepack build",
47
- "type-check": "pridepack check",
48
- "clean": "pridepack clean"
53
+ "solid-js": "^2.0.0"
49
54
  },
50
- "description": "SolidJS bindings for Tiptap",
51
- "repository": {
52
- "url": "https://github.com/lxsmnsyc/solid-tiptap.git",
53
- "type": "git"
54
- },
55
- "homepage": "https://github.com/lxsmnsyc/solid-tiptap/tree/main/packages/solid-tiptap",
56
- "bugs": {
57
- "url": "https://github.com/lxsmnsyc/solid-tiptap/issues"
58
- },
59
- "publishConfig": {
60
- "access": "public"
61
- },
62
- "author": "Alexis Munsayac",
63
- "private": false,
64
- "typesVersions": {
65
- "*": {}
55
+ "engines": {
56
+ "node": ">=22.12.0"
66
57
  },
67
- "gitHead": "2ed0a8715a8c1c2e537626f02c17e60a34a70257"
68
- }
58
+ "scripts": {
59
+ "build": "tsdown",
60
+ "test": "vitest run",
61
+ "test:watch": "vitest",
62
+ "type-check": "tsc --noEmit",
63
+ "watch": "tsdown --watch"
64
+ }
65
+ }
package/src/Editor.ts ADDED
@@ -0,0 +1,124 @@
1
+ import type { EditorOptions, JSONContent } from '@tiptap/core';
2
+ import { Editor } from '@tiptap/core';
3
+ import { createEffect, createSignal, onSettled } from 'solid-js';
4
+
5
+ export type EditorRef = Editor | ((editor: Editor) => void);
6
+
7
+ export type BaseEditorOptions = Omit<Partial<EditorOptions>, 'element'>;
8
+
9
+ export interface UseEditorOptions extends BaseEditorOptions {
10
+ // The editor is created once this is set.
11
+ element: HTMLElement | null | undefined;
12
+ }
13
+
14
+ /**
15
+ * Reads a value from the editor and reads it again after every transaction.
16
+ * `read` also receives `undefined` while `instance` returns no editor.
17
+ */
18
+ export function createEditorTransaction<T, V extends Editor | undefined>(
19
+ instance: () => V,
20
+ read: (value: V) => T,
21
+ ): () => T {
22
+ // Tiptap emits transactions from its own listeners, which can run inside a
23
+ // reactive scope, so the signal allows writes from owned scopes.
24
+ const [depend, update] = createSignal(undefined, { equals: false, ownedWrite: true });
25
+
26
+ createEffect(instance, (editor) => {
27
+ if (!editor) {
28
+ return undefined;
29
+ }
30
+ const forceUpdate = (): void => {
31
+ update();
32
+ };
33
+ editor.on('transaction', forceUpdate);
34
+ return () => {
35
+ editor.off('transaction', forceUpdate);
36
+ };
37
+ });
38
+
39
+ return () => {
40
+ depend();
41
+ return read(instance());
42
+ };
43
+ }
44
+
45
+ /**
46
+ * Creates a Tiptap editor from the given options.
47
+ * The editor is created once `element` is set.
48
+ * It is destroyed and created again when a signal read by `props` changes.
49
+ * It is also destroyed when the owner is disposed.
50
+ */
51
+ export default function useEditor(props: () => UseEditorOptions): () => Editor | undefined {
52
+ // The editor is written from the effect, which runs in an owned scope.
53
+ const [signal, setSignal] = createSignal<Editor | undefined>(undefined, { ownedWrite: true });
54
+
55
+ // Refs are assigned after the component body runs. Reading the options only
56
+ // after the first settle lets `element` come from a plain `let` ref too.
57
+ const [settled, setSettled] = createSignal(false, { ownedWrite: true });
58
+ onSettled(() => {
59
+ setSettled(true);
60
+ });
61
+
62
+ createEffect(
63
+ () => (settled() ? props() : undefined),
64
+ (options) => {
65
+ if (!options?.element) {
66
+ return undefined;
67
+ }
68
+ const instance = new Editor({ ...options });
69
+ setSignal(instance);
70
+ return () => {
71
+ instance.destroy();
72
+ };
73
+ },
74
+ );
75
+
76
+ return signal;
77
+ }
78
+
79
+ /** Returns the editor content as HTML. */
80
+ export function useEditorHTML(editor: () => Editor | undefined): () => string | undefined {
81
+ return createEditorTransaction(editor, (instance) => instance?.getHTML());
82
+ }
83
+
84
+ /** Returns the editor content as Tiptap JSON. */
85
+ export function useEditorJSON(editor: () => Editor | undefined): () => JSONContent | undefined {
86
+ return createEditorTransaction(editor, (instance) => instance?.getJSON());
87
+ }
88
+
89
+ /**
90
+ * Returns whether the node or mark at the selection is active.
91
+ * Pass a node or mark name with optional attributes, or only the attributes.
92
+ */
93
+ export function useEditorIsActive(
94
+ editor: () => Editor | undefined,
95
+ ...args:
96
+ | [name: () => string, options?: Record<string, unknown>]
97
+ | [options: Record<string, unknown>]
98
+ ): () => boolean | undefined {
99
+ return createEditorTransaction(editor, (instance) => {
100
+ if (args.length === 2) {
101
+ return instance?.isActive(args[0](), args[1]);
102
+ }
103
+ const [first] = args;
104
+ if (typeof first === 'function') {
105
+ return instance?.isActive(first());
106
+ }
107
+ return instance?.isActive(first);
108
+ });
109
+ }
110
+
111
+ /** Returns whether the editor has no content. */
112
+ export function useEditorIsEmpty(editor: () => Editor | undefined): () => boolean | undefined {
113
+ return createEditorTransaction(editor, (instance) => instance?.isEmpty);
114
+ }
115
+
116
+ /** Returns whether the editor accepts input. */
117
+ export function useEditorIsEditable(editor: () => Editor | undefined): () => boolean | undefined {
118
+ return createEditorTransaction(editor, (instance) => instance?.isEditable);
119
+ }
120
+
121
+ /** Returns whether the editor has focus. */
122
+ export function useEditorIsFocused(editor: () => Editor | undefined): () => boolean | undefined {
123
+ return createEditorTransaction(editor, (instance) => instance?.isFocused);
124
+ }
package/src/index.ts CHANGED
@@ -11,7 +11,4 @@ export {
11
11
  useEditorJSON,
12
12
  default as useTiptapEditor,
13
13
  } from './Editor';
14
- export type {
15
- EditorRef,
16
- UseEditorOptions,
17
- } from './Editor';
14
+ export type { BaseEditorOptions, EditorRef, UseEditorOptions } from './Editor';
@@ -1,95 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
23
- createEditor: () => useEditor,
24
- createEditorTransaction: () => createEditorTransaction,
25
- createTiptapEditor: () => useEditor,
26
- useEditor: () => useEditor,
27
- useEditorHTML: () => useEditorHTML,
28
- useEditorIsActive: () => useEditorIsActive,
29
- useEditorIsEditable: () => useEditorIsEditable,
30
- useEditorIsEmpty: () => useEditorIsEmpty,
31
- useEditorIsFocused: () => useEditorIsFocused,
32
- useEditorJSON: () => useEditorJSON,
33
- useTiptapEditor: () => useEditor
34
- });
35
- module.exports = __toCommonJS(src_exports);
36
-
37
- // src/Editor.tsx
38
- var import_core = require("@tiptap/core");
39
- var import_solid_js = require("solid-js");
40
- function createEditorTransaction(instance, read) {
41
- const [depend, update] = (0, import_solid_js.createSignal)(void 0, { equals: false });
42
- function forceUpdate() {
43
- update();
44
- }
45
- (0, import_solid_js.createEffect)(() => {
46
- const editor = instance();
47
- if (editor) {
48
- editor.on("transaction", forceUpdate);
49
- (0, import_solid_js.onCleanup)(() => {
50
- editor.off("transaction", forceUpdate);
51
- });
52
- }
53
- });
54
- return () => {
55
- depend();
56
- return read(instance());
57
- };
58
- }
59
- function useEditor(props) {
60
- const [signal, setSignal] = (0, import_solid_js.createSignal)();
61
- (0, import_solid_js.createEffect)(() => {
62
- const instance = new import_core.Editor({
63
- ...props()
64
- });
65
- (0, import_solid_js.onCleanup)(() => {
66
- instance.destroy();
67
- });
68
- setSignal(instance);
69
- });
70
- return signal;
71
- }
72
- function useEditorHTML(editor) {
73
- return createEditorTransaction(editor, (instance) => instance == null ? void 0 : instance.getHTML());
74
- }
75
- function useEditorJSON(editor) {
76
- return createEditorTransaction(editor, (instance) => instance == null ? void 0 : instance.getJSON());
77
- }
78
- function useEditorIsActive(editor, ...args) {
79
- return createEditorTransaction(editor, (instance) => {
80
- if (args.length === 2) {
81
- return instance == null ? void 0 : instance.isActive(args[0](), args[1]);
82
- }
83
- return instance == null ? void 0 : instance.isActive(args[0]);
84
- });
85
- }
86
- function useEditorIsEmpty(editor) {
87
- return createEditorTransaction(editor, (instance) => instance == null ? void 0 : instance.isEmpty);
88
- }
89
- function useEditorIsEditable(editor) {
90
- return createEditorTransaction(editor, (instance) => instance == null ? void 0 : instance.isEditable);
91
- }
92
- function useEditorIsFocused(editor) {
93
- return createEditorTransaction(editor, (instance) => instance == null ? void 0 : instance.isFocused);
94
- }
95
- //# sourceMappingURL=index.cjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/index.ts", "../../../src/Editor.tsx"],
4
- "sourcesContent": ["export {\n default as createEditor,\n createEditorTransaction,\n default as createTiptapEditor,\n default as useEditor,\n useEditorHTML,\n useEditorIsActive,\n useEditorIsEditable,\n useEditorIsEmpty,\n useEditorIsFocused,\n useEditorJSON,\n default as useTiptapEditor,\n} from './Editor';\nexport type {\n EditorRef,\n UseEditorOptions,\n} from './Editor';\n", "import type { EditorOptions } from '@tiptap/core';\nimport { Editor } from '@tiptap/core';\nimport { createEffect, createSignal, onCleanup } from 'solid-js';\n\nexport type EditorRef = Editor | ((editor: Editor) => void);\n\nexport type BaseEditorOptions = Omit<Partial<EditorOptions>, 'element'>;\n\nexport interface UseEditorOptions<T extends HTMLElement>\n extends BaseEditorOptions {\n element: T;\n}\n\nexport function createEditorTransaction<T, V extends Editor | undefined>(\n instance: () => V,\n read: (value: V) => T,\n): () => T {\n const [depend, update] = createSignal(undefined, { equals: false });\n\n function forceUpdate() {\n update();\n }\n\n createEffect(() => {\n const editor = instance();\n if (editor) {\n editor.on('transaction', forceUpdate);\n onCleanup(() => {\n editor.off('transaction', forceUpdate);\n });\n }\n });\n\n return () => {\n depend();\n return read(instance());\n };\n}\n\nexport default function useEditor<T extends HTMLElement>(\n props: () => UseEditorOptions<T>,\n): () => Editor | undefined {\n const [signal, setSignal] = createSignal<Editor>();\n\n createEffect(() => {\n const instance = new Editor({\n ...props(),\n });\n\n onCleanup(() => {\n instance.destroy();\n });\n\n setSignal(instance);\n });\n\n return signal;\n}\n\nexport function useEditorHTML<V extends Editor | undefined>(\n editor: () => V,\n): () => string | undefined {\n return createEditorTransaction(editor, instance => instance?.getHTML());\n}\n\nexport function useEditorJSON<\n V extends Editor | undefined,\n R extends Record<string, any>,\n>(editor: () => V): () => R | undefined {\n return createEditorTransaction(editor, instance => instance?.getJSON() as R | undefined);\n}\n\nexport function useEditorIsActive<\n V extends Editor | undefined,\n R extends Record<string, any>,\n>(\n editor: () => V,\n ...args: [name: () => string, options?: R] | [options: R]\n): () => boolean | undefined {\n return createEditorTransaction(editor, instance => {\n if (args.length === 2) {\n return instance?.isActive(args[0](), args[1]);\n }\n return instance?.isActive(args[0]);\n });\n}\n\nexport function useEditorIsEmpty<V extends Editor | undefined>(\n editor: () => V,\n): () => boolean | undefined {\n return createEditorTransaction(editor, instance => instance?.isEmpty);\n}\n\nexport function useEditorIsEditable<V extends Editor | undefined>(\n editor: () => V,\n): () => boolean | undefined {\n return createEditorTransaction(editor, instance => instance?.isEditable);\n}\n\nexport function useEditorIsFocused<V extends Editor | undefined>(\n editor: () => V,\n): () => boolean | undefined {\n return createEditorTransaction(editor, instance => instance?.isFocused);\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,kBAAuB;AACvB,sBAAsD;AAW/C,SAAS,wBACd,UACA,MACS;AACT,QAAM,CAAC,QAAQ,MAAM,QAAI,8BAAa,QAAW,EAAE,QAAQ,MAAM,CAAC;AAElE,WAAS,cAAc;AACrB,WAAO;AAAA,EACT;AAEA,oCAAa,MAAM;AACjB,UAAM,SAAS,SAAS;AACxB,QAAI,QAAQ;AACV,aAAO,GAAG,eAAe,WAAW;AACpC,qCAAU,MAAM;AACd,eAAO,IAAI,eAAe,WAAW;AAAA,MACvC,CAAC;AAAA,IACH;AAAA,EACF,CAAC;AAED,SAAO,MAAM;AACX,WAAO;AACP,WAAO,KAAK,SAAS,CAAC;AAAA,EACxB;AACF;AAEe,SAAR,UACL,OAC0B;AAC1B,QAAM,CAAC,QAAQ,SAAS,QAAI,8BAAqB;AAEjD,oCAAa,MAAM;AACjB,UAAM,WAAW,IAAI,mBAAO;AAAA,MAC1B,GAAG,MAAM;AAAA,IACX,CAAC;AAED,mCAAU,MAAM;AACd,eAAS,QAAQ;AAAA,IACnB,CAAC;AAED,cAAU,QAAQ;AAAA,EACpB,CAAC;AAED,SAAO;AACT;AAEO,SAAS,cACd,QAC0B;AAC1B,SAAO,wBAAwB,QAAQ,cAAY,qCAAU,SAAS;AACxE;AAEO,SAAS,cAGd,QAAsC;AACtC,SAAO,wBAAwB,QAAQ,cAAY,qCAAU,SAA0B;AACzF;AAEO,SAAS,kBAId,WACG,MACwB;AAC3B,SAAO,wBAAwB,QAAQ,cAAY;AACjD,QAAI,KAAK,WAAW,GAAG;AACrB,aAAO,qCAAU,SAAS,KAAK,CAAC,EAAE,GAAG,KAAK,CAAC;AAAA,IAC7C;AACA,WAAO,qCAAU,SAAS,KAAK,CAAC;AAAA,EAClC,CAAC;AACH;AAEO,SAAS,iBACd,QAC2B;AAC3B,SAAO,wBAAwB,QAAQ,cAAY,qCAAU,OAAO;AACtE;AAEO,SAAS,oBACd,QAC2B;AAC3B,SAAO,wBAAwB,QAAQ,cAAY,qCAAU,UAAU;AACzE;AAEO,SAAS,mBACd,QAC2B;AAC3B,SAAO,wBAAwB,QAAQ,cAAY,qCAAU,SAAS;AACxE;",
6
- "names": []
7
- }
@@ -1 +0,0 @@
1
- "use strict";var s=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var R=(t,e)=>{for(var o in e)s(t,o,{get:e[o],enumerable:!0})},I=(t,e,o,u)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of O(e))!y.call(t,r)&&r!==o&&s(t,r,{get:()=>e[r],enumerable:!(u=V(e,r))||u.enumerable});return t};var b=t=>I(s({},"__esModule",{value:!0}),t);var c={};R(c,{createEditor:()=>n,createEditorTransaction:()=>i,createTiptapEditor:()=>n,useEditor:()=>n,useEditorHTML:()=>p,useEditorIsActive:()=>x,useEditorIsEditable:()=>m,useEditorIsEmpty:()=>a,useEditorIsFocused:()=>T,useEditorJSON:()=>l,useTiptapEditor:()=>n});module.exports=b(c);var f=require("@tiptap/core"),d=require("solid-js");function i(t,e){let[o,u]=(0,d.createSignal)(void 0,{equals:!1});function r(){u()}return(0,d.createEffect)(()=>{let E=t();E&&(E.on("transaction",r),(0,d.onCleanup)(()=>{E.off("transaction",r)}))}),()=>(o(),e(t()))}function n(t){let[e,o]=(0,d.createSignal)();return(0,d.createEffect)(()=>{let u=new f.Editor({...t()});(0,d.onCleanup)(()=>{u.destroy()}),o(u)}),e}function p(t){return i(t,e=>e==null?void 0:e.getHTML())}function l(t){return i(t,e=>e==null?void 0:e.getJSON())}function x(t,...e){return i(t,o=>e.length===2?o==null?void 0:o.isActive(e[0](),e[1]):o==null?void 0:o.isActive(e[0]))}function a(t){return i(t,e=>e==null?void 0:e.isEmpty)}function m(t){return i(t,e=>e==null?void 0:e.isEditable)}function T(t){return i(t,e=>e==null?void 0:e.isFocused)}
@@ -1,72 +0,0 @@
1
- // src/Editor.tsx
2
- import { Editor } from "@tiptap/core";
3
- import { createEffect, createSignal, onCleanup } from "solid-js";
4
- function createEditorTransaction(instance, read) {
5
- const [depend, update] = createSignal(void 0, { equals: false });
6
- function forceUpdate() {
7
- update();
8
- }
9
- createEffect(() => {
10
- const editor = instance();
11
- if (editor) {
12
- editor.on("transaction", forceUpdate);
13
- onCleanup(() => {
14
- editor.off("transaction", forceUpdate);
15
- });
16
- }
17
- });
18
- return () => {
19
- depend();
20
- return read(instance());
21
- };
22
- }
23
- function useEditor(props) {
24
- const [signal, setSignal] = createSignal();
25
- createEffect(() => {
26
- const instance = new Editor({
27
- ...props()
28
- });
29
- onCleanup(() => {
30
- instance.destroy();
31
- });
32
- setSignal(instance);
33
- });
34
- return signal;
35
- }
36
- function useEditorHTML(editor) {
37
- return createEditorTransaction(editor, (instance) => instance == null ? void 0 : instance.getHTML());
38
- }
39
- function useEditorJSON(editor) {
40
- return createEditorTransaction(editor, (instance) => instance == null ? void 0 : instance.getJSON());
41
- }
42
- function useEditorIsActive(editor, ...args) {
43
- return createEditorTransaction(editor, (instance) => {
44
- if (args.length === 2) {
45
- return instance == null ? void 0 : instance.isActive(args[0](), args[1]);
46
- }
47
- return instance == null ? void 0 : instance.isActive(args[0]);
48
- });
49
- }
50
- function useEditorIsEmpty(editor) {
51
- return createEditorTransaction(editor, (instance) => instance == null ? void 0 : instance.isEmpty);
52
- }
53
- function useEditorIsEditable(editor) {
54
- return createEditorTransaction(editor, (instance) => instance == null ? void 0 : instance.isEditable);
55
- }
56
- function useEditorIsFocused(editor) {
57
- return createEditorTransaction(editor, (instance) => instance == null ? void 0 : instance.isFocused);
58
- }
59
- export {
60
- useEditor as createEditor,
61
- createEditorTransaction,
62
- useEditor as createTiptapEditor,
63
- useEditor,
64
- useEditorHTML,
65
- useEditorIsActive,
66
- useEditorIsEditable,
67
- useEditorIsEmpty,
68
- useEditorIsFocused,
69
- useEditorJSON,
70
- useEditor as useTiptapEditor
71
- };
72
- //# sourceMappingURL=index.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/Editor.tsx"],
4
- "sourcesContent": ["import type { EditorOptions } from '@tiptap/core';\nimport { Editor } from '@tiptap/core';\nimport { createEffect, createSignal, onCleanup } from 'solid-js';\n\nexport type EditorRef = Editor | ((editor: Editor) => void);\n\nexport type BaseEditorOptions = Omit<Partial<EditorOptions>, 'element'>;\n\nexport interface UseEditorOptions<T extends HTMLElement>\n extends BaseEditorOptions {\n element: T;\n}\n\nexport function createEditorTransaction<T, V extends Editor | undefined>(\n instance: () => V,\n read: (value: V) => T,\n): () => T {\n const [depend, update] = createSignal(undefined, { equals: false });\n\n function forceUpdate() {\n update();\n }\n\n createEffect(() => {\n const editor = instance();\n if (editor) {\n editor.on('transaction', forceUpdate);\n onCleanup(() => {\n editor.off('transaction', forceUpdate);\n });\n }\n });\n\n return () => {\n depend();\n return read(instance());\n };\n}\n\nexport default function useEditor<T extends HTMLElement>(\n props: () => UseEditorOptions<T>,\n): () => Editor | undefined {\n const [signal, setSignal] = createSignal<Editor>();\n\n createEffect(() => {\n const instance = new Editor({\n ...props(),\n });\n\n onCleanup(() => {\n instance.destroy();\n });\n\n setSignal(instance);\n });\n\n return signal;\n}\n\nexport function useEditorHTML<V extends Editor | undefined>(\n editor: () => V,\n): () => string | undefined {\n return createEditorTransaction(editor, instance => instance?.getHTML());\n}\n\nexport function useEditorJSON<\n V extends Editor | undefined,\n R extends Record<string, any>,\n>(editor: () => V): () => R | undefined {\n return createEditorTransaction(editor, instance => instance?.getJSON() as R | undefined);\n}\n\nexport function useEditorIsActive<\n V extends Editor | undefined,\n R extends Record<string, any>,\n>(\n editor: () => V,\n ...args: [name: () => string, options?: R] | [options: R]\n): () => boolean | undefined {\n return createEditorTransaction(editor, instance => {\n if (args.length === 2) {\n return instance?.isActive(args[0](), args[1]);\n }\n return instance?.isActive(args[0]);\n });\n}\n\nexport function useEditorIsEmpty<V extends Editor | undefined>(\n editor: () => V,\n): () => boolean | undefined {\n return createEditorTransaction(editor, instance => instance?.isEmpty);\n}\n\nexport function useEditorIsEditable<V extends Editor | undefined>(\n editor: () => V,\n): () => boolean | undefined {\n return createEditorTransaction(editor, instance => instance?.isEditable);\n}\n\nexport function useEditorIsFocused<V extends Editor | undefined>(\n editor: () => V,\n): () => boolean | undefined {\n return createEditorTransaction(editor, instance => instance?.isFocused);\n}\n"],
5
- "mappings": ";AACA,SAAS,cAAc;AACvB,SAAS,cAAc,cAAc,iBAAiB;AAW/C,SAAS,wBACd,UACA,MACS;AACT,QAAM,CAAC,QAAQ,MAAM,IAAI,aAAa,QAAW,EAAE,QAAQ,MAAM,CAAC;AAElE,WAAS,cAAc;AACrB,WAAO;AAAA,EACT;AAEA,eAAa,MAAM;AACjB,UAAM,SAAS,SAAS;AACxB,QAAI,QAAQ;AACV,aAAO,GAAG,eAAe,WAAW;AACpC,gBAAU,MAAM;AACd,eAAO,IAAI,eAAe,WAAW;AAAA,MACvC,CAAC;AAAA,IACH;AAAA,EACF,CAAC;AAED,SAAO,MAAM;AACX,WAAO;AACP,WAAO,KAAK,SAAS,CAAC;AAAA,EACxB;AACF;AAEe,SAAR,UACL,OAC0B;AAC1B,QAAM,CAAC,QAAQ,SAAS,IAAI,aAAqB;AAEjD,eAAa,MAAM;AACjB,UAAM,WAAW,IAAI,OAAO;AAAA,MAC1B,GAAG,MAAM;AAAA,IACX,CAAC;AAED,cAAU,MAAM;AACd,eAAS,QAAQ;AAAA,IACnB,CAAC;AAED,cAAU,QAAQ;AAAA,EACpB,CAAC;AAED,SAAO;AACT;AAEO,SAAS,cACd,QAC0B;AAC1B,SAAO,wBAAwB,QAAQ,cAAY,qCAAU,SAAS;AACxE;AAEO,SAAS,cAGd,QAAsC;AACtC,SAAO,wBAAwB,QAAQ,cAAY,qCAAU,SAA0B;AACzF;AAEO,SAAS,kBAId,WACG,MACwB;AAC3B,SAAO,wBAAwB,QAAQ,cAAY;AACjD,QAAI,KAAK,WAAW,GAAG;AACrB,aAAO,qCAAU,SAAS,KAAK,CAAC,EAAE,GAAG,KAAK,CAAC;AAAA,IAC7C;AACA,WAAO,qCAAU,SAAS,KAAK,CAAC;AAAA,EAClC,CAAC;AACH;AAEO,SAAS,iBACd,QAC2B;AAC3B,SAAO,wBAAwB,QAAQ,cAAY,qCAAU,OAAO;AACtE;AAEO,SAAS,oBACd,QAC2B;AAC3B,SAAO,wBAAwB,QAAQ,cAAY,qCAAU,UAAU;AACzE;AAEO,SAAS,mBACd,QAC2B;AAC3B,SAAO,wBAAwB,QAAQ,cAAY,qCAAU,SAAS;AACxE;",
6
- "names": []
7
- }
@@ -1 +0,0 @@
1
- import{Editor as p}from"@tiptap/core";import{createEffect as E,createSignal as s,onCleanup as f}from"solid-js";function d(t,e){let[o,i]=s(void 0,{equals:!1});function n(){i()}return E(()=>{let u=t();u&&(u.on("transaction",n),f(()=>{u.off("transaction",n)}))}),()=>(o(),e(t()))}function r(t){let[e,o]=s();return E(()=>{let i=new p({...t()});f(()=>{i.destroy()}),o(i)}),e}function l(t){return d(t,e=>e==null?void 0:e.getHTML())}function x(t){return d(t,e=>e==null?void 0:e.getJSON())}function a(t,...e){return d(t,o=>e.length===2?o==null?void 0:o.isActive(e[0](),e[1]):o==null?void 0:o.isActive(e[0]))}function m(t){return d(t,e=>e==null?void 0:e.isEmpty)}function T(t){return d(t,e=>e==null?void 0:e.isEditable)}function V(t){return d(t,e=>e==null?void 0:e.isFocused)}export{r as createEditor,d as createEditorTransaction,r as createTiptapEditor,r as useEditor,l as useEditorHTML,a as useEditorIsActive,T as useEditorIsEditable,m as useEditorIsEmpty,V as useEditorIsFocused,x as useEditorJSON,r as useTiptapEditor};
@@ -1,16 +0,0 @@
1
- import type { EditorOptions } from '@tiptap/core';
2
- import { Editor } from '@tiptap/core';
3
- export type EditorRef = Editor | ((editor: Editor) => void);
4
- export type BaseEditorOptions = Omit<Partial<EditorOptions>, 'element'>;
5
- export interface UseEditorOptions<T extends HTMLElement> extends BaseEditorOptions {
6
- element: T;
7
- }
8
- export declare function createEditorTransaction<T, V extends Editor | undefined>(instance: () => V, read: (value: V) => T): () => T;
9
- export default function useEditor<T extends HTMLElement>(props: () => UseEditorOptions<T>): () => Editor | undefined;
10
- export declare function useEditorHTML<V extends Editor | undefined>(editor: () => V): () => string | undefined;
11
- export declare function useEditorJSON<V extends Editor | undefined, R extends Record<string, any>>(editor: () => V): () => R | undefined;
12
- export declare function useEditorIsActive<V extends Editor | undefined, R extends Record<string, any>>(editor: () => V, ...args: [name: () => string, options?: R] | [options: R]): () => boolean | undefined;
13
- export declare function useEditorIsEmpty<V extends Editor | undefined>(editor: () => V): () => boolean | undefined;
14
- export declare function useEditorIsEditable<V extends Editor | undefined>(editor: () => V): () => boolean | undefined;
15
- export declare function useEditorIsFocused<V extends Editor | undefined>(editor: () => V): () => boolean | undefined;
16
- //# sourceMappingURL=Editor.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Editor.d.ts","sourceRoot":"","sources":["../../src/Editor.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAGtC,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC,CAAC;AAE5D,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,SAAS,CAAC,CAAC;AAExE,MAAM,WAAW,gBAAgB,CAAC,CAAC,SAAS,WAAW,CACrD,SAAQ,iBAAiB;IACzB,OAAO,EAAE,CAAC,CAAC;CACZ;AAED,wBAAgB,uBAAuB,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,GAAG,SAAS,EACrE,QAAQ,EAAE,MAAM,CAAC,EACjB,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GACpB,MAAM,CAAC,CAqBT;AAED,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,CAAC,SAAS,WAAW,EACrD,KAAK,EAAE,MAAM,gBAAgB,CAAC,CAAC,CAAC,GAC/B,MAAM,MAAM,GAAG,SAAS,CAgB1B;AAED,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,GAAG,SAAS,EACxD,MAAM,EAAE,MAAM,CAAC,GACd,MAAM,MAAM,GAAG,SAAS,CAE1B;AAED,wBAAgB,aAAa,CAC3B,CAAC,SAAS,MAAM,GAAG,SAAS,EAC5B,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC7B,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,SAAS,CAEtC;AAED,wBAAgB,iBAAiB,CAC/B,CAAC,SAAS,MAAM,GAAG,SAAS,EAC5B,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAE7B,MAAM,EAAE,MAAM,CAAC,EACf,GAAG,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,GACxD,MAAM,OAAO,GAAG,SAAS,CAO3B;AAED,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,GAAG,SAAS,EAC3D,MAAM,EAAE,MAAM,CAAC,GACd,MAAM,OAAO,GAAG,SAAS,CAE3B;AAED,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,MAAM,GAAG,SAAS,EAC9D,MAAM,EAAE,MAAM,CAAC,GACd,MAAM,OAAO,GAAG,SAAS,CAE3B;AAED,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,MAAM,GAAG,SAAS,EAC7D,MAAM,EAAE,MAAM,CAAC,GACd,MAAM,OAAO,GAAG,SAAS,CAE3B"}
@@ -1,3 +0,0 @@
1
- export { default as createEditor, createEditorTransaction, default as createTiptapEditor, default as useEditor, useEditorHTML, useEditorIsActive, useEditorIsEditable, useEditorIsEmpty, useEditorIsFocused, useEditorJSON, default as useTiptapEditor, } from './Editor';
2
- export type { EditorRef, UseEditorOptions, } from './Editor';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,IAAI,YAAY,EACvB,uBAAuB,EACvB,OAAO,IAAI,kBAAkB,EAC7B,OAAO,IAAI,SAAS,EACpB,aAAa,EACb,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,aAAa,EACb,OAAO,IAAI,eAAe,GAC3B,MAAM,UAAU,CAAC;AAClB,YAAY,EACV,SAAS,EACT,gBAAgB,GACjB,MAAM,UAAU,CAAC"}
package/src/Editor.tsx DELETED
@@ -1,104 +0,0 @@
1
- import type { EditorOptions } from '@tiptap/core';
2
- import { Editor } from '@tiptap/core';
3
- import { createEffect, createSignal, onCleanup } from 'solid-js';
4
-
5
- export type EditorRef = Editor | ((editor: Editor) => void);
6
-
7
- export type BaseEditorOptions = Omit<Partial<EditorOptions>, 'element'>;
8
-
9
- export interface UseEditorOptions<T extends HTMLElement>
10
- extends BaseEditorOptions {
11
- element: T;
12
- }
13
-
14
- export function createEditorTransaction<T, V extends Editor | undefined>(
15
- instance: () => V,
16
- read: (value: V) => T,
17
- ): () => T {
18
- const [depend, update] = createSignal(undefined, { equals: false });
19
-
20
- function forceUpdate() {
21
- update();
22
- }
23
-
24
- createEffect(() => {
25
- const editor = instance();
26
- if (editor) {
27
- editor.on('transaction', forceUpdate);
28
- onCleanup(() => {
29
- editor.off('transaction', forceUpdate);
30
- });
31
- }
32
- });
33
-
34
- return () => {
35
- depend();
36
- return read(instance());
37
- };
38
- }
39
-
40
- export default function useEditor<T extends HTMLElement>(
41
- props: () => UseEditorOptions<T>,
42
- ): () => Editor | undefined {
43
- const [signal, setSignal] = createSignal<Editor>();
44
-
45
- createEffect(() => {
46
- const instance = new Editor({
47
- ...props(),
48
- });
49
-
50
- onCleanup(() => {
51
- instance.destroy();
52
- });
53
-
54
- setSignal(instance);
55
- });
56
-
57
- return signal;
58
- }
59
-
60
- export function useEditorHTML<V extends Editor | undefined>(
61
- editor: () => V,
62
- ): () => string | undefined {
63
- return createEditorTransaction(editor, instance => instance?.getHTML());
64
- }
65
-
66
- export function useEditorJSON<
67
- V extends Editor | undefined,
68
- R extends Record<string, any>,
69
- >(editor: () => V): () => R | undefined {
70
- return createEditorTransaction(editor, instance => instance?.getJSON() as R | undefined);
71
- }
72
-
73
- export function useEditorIsActive<
74
- V extends Editor | undefined,
75
- R extends Record<string, any>,
76
- >(
77
- editor: () => V,
78
- ...args: [name: () => string, options?: R] | [options: R]
79
- ): () => boolean | undefined {
80
- return createEditorTransaction(editor, instance => {
81
- if (args.length === 2) {
82
- return instance?.isActive(args[0](), args[1]);
83
- }
84
- return instance?.isActive(args[0]);
85
- });
86
- }
87
-
88
- export function useEditorIsEmpty<V extends Editor | undefined>(
89
- editor: () => V,
90
- ): () => boolean | undefined {
91
- return createEditorTransaction(editor, instance => instance?.isEmpty);
92
- }
93
-
94
- export function useEditorIsEditable<V extends Editor | undefined>(
95
- editor: () => V,
96
- ): () => boolean | undefined {
97
- return createEditorTransaction(editor, instance => instance?.isEditable);
98
- }
99
-
100
- export function useEditorIsFocused<V extends Editor | undefined>(
101
- editor: () => V,
102
- ): () => boolean | undefined {
103
- return createEditorTransaction(editor, instance => instance?.isFocused);
104
- }