solid-tiptap 0.8.0 → 0.9.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,46 @@
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` 1.7 or later.
28
+ - `@tiptap/core` and `@tiptap/pm` 3.x.
29
+
30
+ Use `solid-tiptap@0.7` for Tiptap 2.
31
+
23
32
  ## Usage
24
33
 
25
- ```jsx
26
- import { createTiptapEditor } from 'solid-tiptap';
34
+ ```tsx
27
35
  import StarterKit from '@tiptap/starter-kit';
36
+ import { createTiptapEditor } from 'solid-tiptap';
28
37
 
29
38
  function App() {
30
39
  let ref!: HTMLDivElement;
31
40
 
32
41
  const editor = createTiptapEditor(() => ({
33
- element: ref!,
34
- extensions: [
35
- StarterKit,
36
- ],
42
+ element: ref,
43
+ extensions: [StarterKit],
37
44
  content: `<p>Example Text</p>`,
38
45
  }));
39
46
 
@@ -41,115 +48,168 @@ function App() {
41
48
  }
42
49
  ```
43
50
 
44
- ### Transactions
51
+ `createTiptapEditor` returns an accessor for the editor.
52
+
53
+ - The editor is created in an effect, after the element is mounted. The accessor returns `undefined` until then.
54
+ - The options function is tracked. When a signal it reads changes, the old editor is destroyed and a new one is created.
55
+ - The editor is destroyed when the owning component unmounts.
45
56
 
46
- `createEditorTransaction` provides a way to reactively subscribe to editor changes.
57
+ Because the options are tracked, read signals that should not recreate the editor with `untrack`.
58
+
59
+ ```tsx
60
+ import { untrack } from 'solid-js';
61
+
62
+ const editor = createTiptapEditor(() => ({
63
+ element: ref,
64
+ extensions: [StarterKit],
65
+ // Changing `initialContent` later does not recreate the editor.
66
+ content: untrack(initialContent),
67
+ }));
68
+ ```
69
+
70
+ Use the editor's own commands to update it after it is created.
47
71
 
48
72
  ```ts
49
- const isBold = createEditorTransaction(
50
- () => props.editor, // Editor instance from createTiptapEditor
51
- (editor) => editor.isActive("bold")
52
- );
73
+ editor()?.commands.setContent('<p>New content</p>');
74
+ editor()?.setEditable(false);
75
+ ```
53
76
 
54
- createEffect(() => {
55
- if (isBold()) {
56
- // do something
57
- }
58
- });
77
+ ### Passing the editor to other components
78
+
79
+ Render the components that need the editor inside `<Show>`, so they only run once the editor exists.
80
+
81
+ ```tsx
82
+ const editor = createTiptapEditor(() => ({ ... }));
83
+
84
+ <Show when={editor()} keyed>
85
+ {(instance) => <Toolbar editor={instance} />}
86
+ </Show>
59
87
  ```
60
88
 
61
- There are out-of-the-box utilities that wraps `createEditorTransaction` based on the [Editor API](https://www.tiptap.dev/api/editor):
89
+ `keyed` passes the editor itself to the children. Without it, Solid passes an accessor, so you would write `editor={instance()}`.
62
90
 
63
- - `useEditorHTML`: reactively subscribe to `getEditorHTML`.
91
+ ### Bubble and floating menus
64
92
 
65
- ```js
66
- const html = useEditorHTML(() => props.editor);
93
+ Tiptap's `BubbleMenu` and `FloatingMenu` extensions take an `element` option. Pass a mounted element the same way you pass the editor element.
67
94
 
68
- createEffect(() => {
69
- updateHTML(html());
70
- });
95
+ ```tsx
96
+ import BubbleMenu from '@tiptap/extension-bubble-menu';
97
+
98
+ function App() {
99
+ let container!: HTMLDivElement;
100
+ let menu!: HTMLDivElement;
101
+
102
+ const editor = createTiptapEditor(() => ({
103
+ element: container,
104
+ extensions: [StarterKit, BubbleMenu.configure({ element: menu })],
105
+ }));
106
+
107
+ return (
108
+ <>
109
+ <div ref={menu}>
110
+ <Show when={editor()} keyed>
111
+ {(instance) => <Toolbar editor={instance} />}
112
+ </Show>
113
+ </div>
114
+ <div ref={container} />
115
+ </>
116
+ );
117
+ }
71
118
  ```
72
119
 
73
- - `useEditorIsActive`: reactively subscribe to `isActive`.
120
+ ### Reading editor state
121
+
122
+ 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.
74
123
 
75
- ```js
76
- const isHeading = useEditorIsActive(
124
+ ```ts
125
+ import { createEditorTransaction } from 'solid-tiptap';
126
+
127
+ const isBold = createEditorTransaction(
77
128
  () => props.editor,
78
- () => "heading",
79
- {
80
- level: 1,
81
- }
129
+ (editor) => editor.isActive('bold'),
82
130
  );
83
131
 
84
132
  createEffect(() => {
85
- if (isHeading()) {
86
- // do something
133
+ if (isBold()) {
134
+ // ...
87
135
  }
88
136
  });
89
137
  ```
90
138
 
91
- - `useEditorIsEditable`: reactively subscribe to `isEditable`.
92
-
93
- ```js
94
- const isEditable = useEditorIsEditable(() => props.editor);
139
+ The read function receives whatever the first accessor returns. If that can be `undefined`, handle it in the read function.
95
140
 
96
- createEffect(() => {
97
- if (isEditable()) {
98
- // do something
99
- }
100
- });
141
+ ```ts
142
+ const length = createEditorTransaction(
143
+ editor,
144
+ (instance) => instance?.state.doc.textContent.length ?? 0,
145
+ );
101
146
  ```
102
147
 
103
- - `useEditorIsEmpty`: reactively subscribe to `isEmpty`.
104
-
105
- ```js
106
- const isEmpty = useEditorIsEmpty(() => props.editor);
148
+ ### Helpers
107
149
 
108
- createEffect(() => {
109
- if (isEmpty()) {
110
- // do something
111
- }
112
- });
113
- ```
150
+ 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.
114
151
 
115
- - `useEditorIsFocused`: reactively subscribe to `isFocused`.
152
+ | Helper | Reads | Returns |
153
+ | --------------------- | ---------------------- | ------------- |
154
+ | `useEditorHTML` | `editor.getHTML()` | `string` |
155
+ | `useEditorJSON` | `editor.getJSON()` | `JSONContent` |
156
+ | `useEditorIsActive` | `editor.isActive(...)` | `boolean` |
157
+ | `useEditorIsEmpty` | `editor.isEmpty` | `boolean` |
158
+ | `useEditorIsEditable` | `editor.isEditable` | `boolean` |
159
+ | `useEditorIsFocused` | `editor.isFocused` | `boolean` |
116
160
 
117
- ```js
118
- const isFocused = useEditorIsFocused(() => props.editor);
161
+ ```ts
162
+ const html = useEditorHTML(editor);
119
163
 
120
164
  createEffect(() => {
121
- if (isFocused()) {
122
- // do something
123
- }
165
+ saveHTML(html());
124
166
  });
125
167
  ```
126
168
 
127
- - `useEditorJSON`: reactively subscribe to `getJSON`.
128
-
129
- ```js
130
- const json = useEditorJSON(() => props.editor);
169
+ ```ts
170
+ const json = useEditorJSON(editor);
131
171
 
132
172
  createEffect(() => {
133
173
  const data = json();
134
-
135
174
  if (data) {
136
175
  uploadJSON(data);
137
176
  }
138
177
  });
139
178
  ```
140
179
 
141
- ## Tips
180
+ `useEditorIsActive` takes a name accessor with optional attributes, a name accessor alone, or attributes alone.
142
181
 
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.
182
+ ```ts
183
+ // A node or mark by name.
184
+ const isBold = useEditorIsActive(editor, () => 'bold');
144
185
 
145
- ```js
146
- const editor = createTiptapEditor(() => ({ ... }));
186
+ // A node or mark by name and attributes.
187
+ const isHeading = useEditorIsActive(editor, () => 'heading', { level: 1 });
147
188
 
148
- <Show when={editor()}>
149
- {(instance) => <EditorMenu editor={instance} />}
150
- </Show>
189
+ // Any node or mark with these attributes.
190
+ const isCentered = useEditorIsActive(editor, { textAlign: 'center' });
151
191
  ```
152
192
 
193
+ ## API
194
+
195
+ ### `createTiptapEditor(options)`
196
+
197
+ Creates a Tiptap editor. Also exported as `createEditor`, `useEditor` and `useTiptapEditor`.
198
+
199
+ - `options` is a function that returns Tiptap's [editor options](https://tiptap.dev/docs/editor/api/editor#settings). `element` is required.
200
+ - Returns `() => Editor | undefined`.
201
+
202
+ ### `createEditorTransaction(editor, read)`
203
+
204
+ - `editor` is a function that returns an `Editor` or `undefined`.
205
+ - `read` is called with the result of `editor()`. Its result is returned by the accessor.
206
+ - Returns an accessor that runs `read` again after every editor transaction.
207
+
208
+ ### Types
209
+
210
+ - `UseEditorOptions<T extends HTMLElement>` is the options type for `createTiptapEditor`.
211
+ - `BaseEditorOptions` is Tiptap's `EditorOptions` without `element`, with every field optional.
212
+
153
213
  ## Sponsors
154
214
 
155
215
  ![Sponsors](https://github.com/lxsmnsyc/sponsors/blob/main/sponsors.svg?raw=true)
package/dist/index.cjs ADDED
@@ -0,0 +1,89 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let _tiptap_core = require("@tiptap/core");
3
+ let solid_js = require("solid-js");
4
+ //#region src/Editor.ts
5
+ /**
6
+ * Reads a value from the editor and reads it again after every transaction.
7
+ * `read` also receives `undefined` while `instance` returns no editor.
8
+ */
9
+ function createEditorTransaction(instance, read) {
10
+ const [depend, update] = (0, solid_js.createSignal)(void 0, { equals: false });
11
+ function forceUpdate() {
12
+ update();
13
+ }
14
+ (0, solid_js.createEffect)(() => {
15
+ const editor = instance();
16
+ if (editor) {
17
+ editor.on("transaction", forceUpdate);
18
+ (0, solid_js.onCleanup)(() => {
19
+ editor.off("transaction", forceUpdate);
20
+ });
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 destroyed and created again when a signal read by `props` changes.
31
+ * It is also destroyed when the owner is disposed.
32
+ */
33
+ function useEditor(props) {
34
+ const [signal, setSignal] = (0, solid_js.createSignal)();
35
+ (0, solid_js.createEffect)(() => {
36
+ const instance = new _tiptap_core.Editor({ ...props() });
37
+ (0, solid_js.onCleanup)(() => {
38
+ instance.destroy();
39
+ });
40
+ setSignal(instance);
41
+ });
42
+ return signal;
43
+ }
44
+ /** Returns the editor content as HTML. */
45
+ function useEditorHTML(editor) {
46
+ return createEditorTransaction(editor, (instance) => instance === null || instance === void 0 ? void 0 : instance.getHTML());
47
+ }
48
+ /** Returns the editor content as Tiptap JSON. */
49
+ function useEditorJSON(editor) {
50
+ return createEditorTransaction(editor, (instance) => instance === null || instance === void 0 ? void 0 : instance.getJSON());
51
+ }
52
+ /**
53
+ * Returns whether the node or mark at the selection is active.
54
+ * Pass a node or mark name with optional attributes, or only the attributes.
55
+ */
56
+ function useEditorIsActive(editor, ...args) {
57
+ return createEditorTransaction(editor, (instance) => {
58
+ if (args.length === 2) return instance === null || instance === void 0 ? void 0 : instance.isActive(args[0](), args[1]);
59
+ const [first] = args;
60
+ if (typeof first === "function") return instance === null || instance === void 0 ? void 0 : instance.isActive(first());
61
+ return instance === null || instance === void 0 ? void 0 : instance.isActive(first);
62
+ });
63
+ }
64
+ /** Returns whether the editor has no content. */
65
+ function useEditorIsEmpty(editor) {
66
+ return createEditorTransaction(editor, (instance) => instance === null || instance === void 0 ? void 0 : instance.isEmpty);
67
+ }
68
+ /** Returns whether the editor accepts input. */
69
+ function useEditorIsEditable(editor) {
70
+ return createEditorTransaction(editor, (instance) => instance === null || instance === void 0 ? void 0 : instance.isEditable);
71
+ }
72
+ /** Returns whether the editor has focus. */
73
+ function useEditorIsFocused(editor) {
74
+ return createEditorTransaction(editor, (instance) => instance === null || instance === void 0 ? void 0 : instance.isFocused);
75
+ }
76
+ //#endregion
77
+ exports.createEditor = useEditor;
78
+ exports.createEditorTransaction = createEditorTransaction;
79
+ exports.createTiptapEditor = useEditor;
80
+ exports.useEditor = useEditor;
81
+ exports.useEditorHTML = useEditorHTML;
82
+ exports.useEditorIsActive = useEditorIsActive;
83
+ exports.useEditorIsEditable = useEditorIsEditable;
84
+ exports.useEditorIsEmpty = useEditorIsEmpty;
85
+ exports.useEditorIsFocused = useEditorIsFocused;
86
+ exports.useEditorJSON = useEditorJSON;
87
+ exports.useTiptapEditor = useEditor;
88
+
89
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["createSignal","Editor"],"sources":["../src/Editor.ts"],"sourcesContent":["import type { EditorOptions, JSONContent } 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> extends BaseEditorOptions {\n element: T;\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 const [depend, update] = createSignal(undefined, { equals: false });\n\n function forceUpdate(): void {\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\n/**\n * Creates a Tiptap editor from the given options.\n * The editor 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<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\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":";;;;;;;;AAgBA,SAAgB,wBACd,UACA,MACS;CACT,MAAM,CAAC,QAAQ,WAAA,GAAUA,SAAAA,aAAAA,CAAa,KAAA,GAAW,EAAE,QAAQ,MAAM,CAAC;CAElE,SAAS,cAAoB;EAC3B,OAAO;CACT;CAEA,CAAA,GAAA,SAAA,aAAA,OAAmB;EACjB,MAAM,SAAS,SAAS;EACxB,IAAI,QAAQ;GACV,OAAO,GAAG,eAAe,WAAW;GACpC,CAAA,GAAA,SAAA,UAAA,OAAgB;IACd,OAAO,IAAI,eAAe,WAAW;GACvC,CAAC;EACH;CACF,CAAC;CAED,aAAa;EACX,OAAO;EACP,OAAO,KAAK,SAAS,CAAC;CACxB;AACF;;;;;;AAOA,SAAwB,UACtB,OAC0B;CAC1B,MAAM,CAAC,QAAQ,cAAA,GAAaA,SAAAA,aAAAA,CAAqB;CAEjD,CAAA,GAAA,SAAA,aAAA,OAAmB;EACjB,MAAM,WAAW,IAAIC,aAAAA,OAAO,EAC1B,GAAG,MAAM,EACX,CAAC;EAED,CAAA,GAAA,SAAA,UAAA,OAAgB;GACd,SAAS,QAAQ;EACnB,CAAC;EAED,UAAU,QAAQ;CACpB,CAAC;CAED,OAAO;AACT;;AAGA,SAAgB,cAAc,QAA4D;CACxF,OAAO,wBAAwB,SAAS,aAAA,aAAA,QAAA,aAAA,KAAA,IAAA,KAAA,IAAa,SAAU,QAAQ,CAAC;AAC1E;;AAGA,SAAgB,cAAc,QAAiE;CAC7F,OAAO,wBAAwB,SAAS,aAAA,aAAA,QAAA,aAAA,KAAA,IAAA,KAAA,IAAa,SAAU,QAAQ,CAAC;AAC1E;;;;;AAMA,SAAgB,kBACd,QACA,GAAG,MAGwB;CAC3B,OAAO,wBAAwB,SAAS,aAAa;EACnD,IAAI,KAAK,WAAW,GAClB,OAAA,aAAA,QAAA,aAAA,KAAA,IAAA,KAAA,IAAO,SAAU,SAAS,KAAK,EAAE,CAAC,GAAG,KAAK,EAAE;EAE9C,MAAM,CAAC,SAAS;EAChB,IAAI,OAAO,UAAU,YACnB,OAAA,aAAA,QAAA,aAAA,KAAA,IAAA,KAAA,IAAO,SAAU,SAAS,MAAM,CAAC;EAEnC,OAAA,aAAA,QAAA,aAAA,KAAA,IAAA,KAAA,IAAO,SAAU,SAAS,KAAK;CACjC,CAAC;AACH;;AAGA,SAAgB,iBAAiB,QAA6D;CAC5F,OAAO,wBAAwB,SAAS,aAAA,aAAA,QAAA,aAAA,KAAA,IAAA,KAAA,IAAa,SAAU,OAAO;AACxE;;AAGA,SAAgB,oBAAoB,QAA6D;CAC/F,OAAO,wBAAwB,SAAS,aAAA,aAAA,QAAA,aAAA,KAAA,IAAA,KAAA,IAAa,SAAU,UAAU;AAC3E;;AAGA,SAAgB,mBAAmB,QAA6D;CAC9F,OAAO,wBAAwB,SAAS,aAAA,aAAA,QAAA,aAAA,KAAA,IAAA,KAAA,IAAa,SAAU,SAAS;AAC1E"}
@@ -0,0 +1,36 @@
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<T extends HTMLElement> extends BaseEditorOptions {
6
+ element: T;
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 destroyed and created again when a signal read by `props` changes.
16
+ * It is also destroyed when the owner is disposed.
17
+ */
18
+ declare function useEditor<T extends HTMLElement>(props: () => UseEditorOptions<T>): () => Editor | undefined;
19
+ /** Returns the editor content as HTML. */
20
+ export declare function useEditorHTML(editor: () => Editor | undefined): () => string | undefined;
21
+ /** Returns the editor content as Tiptap JSON. */
22
+ export declare function useEditorJSON(editor: () => Editor | undefined): () => JSONContent | undefined;
23
+ /**
24
+ * Returns whether the node or mark at the selection is active.
25
+ * Pass a node or mark name with optional attributes, or only the attributes.
26
+ */
27
+ export declare function useEditorIsActive(editor: () => Editor | undefined, ...args: [name: () => string, options?: Record<string, unknown>] | [options: Record<string, unknown>]): () => boolean | undefined;
28
+ /** Returns whether the editor has no content. */
29
+ export declare function useEditorIsEmpty(editor: () => Editor | undefined): () => boolean | undefined;
30
+ /** Returns whether the editor accepts input. */
31
+ export declare function useEditorIsEditable(editor: () => Editor | undefined): () => boolean | undefined;
32
+ /** Returns whether the editor has focus. */
33
+ export declare function useEditorIsFocused(editor: () => Editor | undefined): () => boolean | undefined;
34
+ //#endregion
35
+ export { type BaseEditorOptions, type EditorRef, type UseEditorOptions, useEditor as createEditor, useEditor as createTiptapEditor, useEditor, useEditor as useTiptapEditor };
36
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/Editor.ts"],"mappings":";;KAIY,YAAY,WAAW,QAAQ;KAE/B,oBAAoB,KAAK,QAAQ;UAE5B,iBAAiB,UAAU,qBAAqB;EAC/D,SAAS;;;;;;wBAOK,wBAAwB,GAAG,UAAU,oBACnD,gBAAgB,GAChB,OAAO,OAAO,MAAM,UACb;;;;;;iBA4Be,UAAU,UAAU,aAC1C,aAAa,iBAAiB,WACvB;;wBAmBO,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"}
@@ -0,0 +1,36 @@
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<T extends HTMLElement> extends BaseEditorOptions {
6
+ element: T;
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 destroyed and created again when a signal read by `props` changes.
16
+ * It is also destroyed when the owner is disposed.
17
+ */
18
+ declare function useEditor<T extends HTMLElement>(props: () => UseEditorOptions<T>): () => Editor | undefined;
19
+ /** Returns the editor content as HTML. */
20
+ export declare function useEditorHTML(editor: () => Editor | undefined): () => string | undefined;
21
+ /** Returns the editor content as Tiptap JSON. */
22
+ export declare function useEditorJSON(editor: () => Editor | undefined): () => JSONContent | undefined;
23
+ /**
24
+ * Returns whether the node or mark at the selection is active.
25
+ * Pass a node or mark name with optional attributes, or only the attributes.
26
+ */
27
+ export declare function useEditorIsActive(editor: () => Editor | undefined, ...args: [name: () => string, options?: Record<string, unknown>] | [options: Record<string, unknown>]): () => boolean | undefined;
28
+ /** Returns whether the editor has no content. */
29
+ export declare function useEditorIsEmpty(editor: () => Editor | undefined): () => boolean | undefined;
30
+ /** Returns whether the editor accepts input. */
31
+ export declare function useEditorIsEditable(editor: () => Editor | undefined): () => boolean | undefined;
32
+ /** Returns whether the editor has focus. */
33
+ export declare function useEditorIsFocused(editor: () => Editor | undefined): () => boolean | undefined;
34
+ //#endregion
35
+ export { type BaseEditorOptions, type EditorRef, type UseEditorOptions, useEditor as createEditor, useEditor as createTiptapEditor, useEditor, useEditor as useTiptapEditor };
36
+ //# 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,iBAAiB,UAAU,qBAAqB;EAC/D,SAAS;;;;;;wBAOK,wBAAwB,GAAG,UAAU,oBACnD,gBAAgB,GAChB,OAAO,OAAO,MAAM,UACb;;;;;;iBA4Be,UAAU,UAAU,aAC1C,aAAa,iBAAiB,WACvB;;wBAmBO,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,78 @@
1
+ import { Editor } from "@tiptap/core";
2
+ import { createEffect, createSignal, onCleanup } 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, { equals: false });
10
+ function forceUpdate() {
11
+ update();
12
+ }
13
+ createEffect(() => {
14
+ const editor = instance();
15
+ if (editor) {
16
+ editor.on("transaction", forceUpdate);
17
+ onCleanup(() => {
18
+ editor.off("transaction", forceUpdate);
19
+ });
20
+ }
21
+ });
22
+ return () => {
23
+ depend();
24
+ return read(instance());
25
+ };
26
+ }
27
+ /**
28
+ * Creates a Tiptap editor from the given options.
29
+ * The editor is destroyed and created again when a signal read by `props` changes.
30
+ * It is also destroyed when the owner is disposed.
31
+ */
32
+ function useEditor(props) {
33
+ const [signal, setSignal] = createSignal();
34
+ createEffect(() => {
35
+ const instance = new Editor({ ...props() });
36
+ onCleanup(() => {
37
+ instance.destroy();
38
+ });
39
+ setSignal(instance);
40
+ });
41
+ return signal;
42
+ }
43
+ /** Returns the editor content as HTML. */
44
+ function useEditorHTML(editor) {
45
+ return createEditorTransaction(editor, (instance) => instance === null || instance === void 0 ? void 0 : instance.getHTML());
46
+ }
47
+ /** Returns the editor content as Tiptap JSON. */
48
+ function useEditorJSON(editor) {
49
+ return createEditorTransaction(editor, (instance) => instance === null || instance === void 0 ? void 0 : instance.getJSON());
50
+ }
51
+ /**
52
+ * Returns whether the node or mark at the selection is active.
53
+ * Pass a node or mark name with optional attributes, or only the attributes.
54
+ */
55
+ function useEditorIsActive(editor, ...args) {
56
+ return createEditorTransaction(editor, (instance) => {
57
+ if (args.length === 2) return instance === null || instance === void 0 ? void 0 : instance.isActive(args[0](), args[1]);
58
+ const [first] = args;
59
+ if (typeof first === "function") return instance === null || instance === void 0 ? void 0 : instance.isActive(first());
60
+ return instance === null || instance === void 0 ? void 0 : instance.isActive(first);
61
+ });
62
+ }
63
+ /** Returns whether the editor has no content. */
64
+ function useEditorIsEmpty(editor) {
65
+ return createEditorTransaction(editor, (instance) => instance === null || instance === void 0 ? void 0 : instance.isEmpty);
66
+ }
67
+ /** Returns whether the editor accepts input. */
68
+ function useEditorIsEditable(editor) {
69
+ return createEditorTransaction(editor, (instance) => instance === null || instance === void 0 ? void 0 : instance.isEditable);
70
+ }
71
+ /** Returns whether the editor has focus. */
72
+ function useEditorIsFocused(editor) {
73
+ return createEditorTransaction(editor, (instance) => instance === null || instance === void 0 ? void 0 : instance.isFocused);
74
+ }
75
+ //#endregion
76
+ export { useEditor as createEditor, useEditor as createTiptapEditor, useEditor, useEditor as useTiptapEditor, createEditorTransaction, useEditorHTML, useEditorIsActive, useEditorIsEditable, useEditorIsEmpty, useEditorIsFocused, useEditorJSON };
77
+
78
+ //# 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, 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> extends BaseEditorOptions {\n element: T;\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 const [depend, update] = createSignal(undefined, { equals: false });\n\n function forceUpdate(): void {\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\n/**\n * Creates a Tiptap editor from the given options.\n * The editor 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<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\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":";;;;;;;AAgBA,SAAgB,wBACd,UACA,MACS;CACT,MAAM,CAAC,QAAQ,UAAU,aAAa,KAAA,GAAW,EAAE,QAAQ,MAAM,CAAC;CAElE,SAAS,cAAoB;EAC3B,OAAO;CACT;CAEA,mBAAmB;EACjB,MAAM,SAAS,SAAS;EACxB,IAAI,QAAQ;GACV,OAAO,GAAG,eAAe,WAAW;GACpC,gBAAgB;IACd,OAAO,IAAI,eAAe,WAAW;GACvC,CAAC;EACH;CACF,CAAC;CAED,aAAa;EACX,OAAO;EACP,OAAO,KAAK,SAAS,CAAC;CACxB;AACF;;;;;;AAOA,SAAwB,UACtB,OAC0B;CAC1B,MAAM,CAAC,QAAQ,aAAa,aAAqB;CAEjD,mBAAmB;EACjB,MAAM,WAAW,IAAI,OAAO,EAC1B,GAAG,MAAM,EACX,CAAC;EAED,gBAAgB;GACd,SAAS,QAAQ;EACnB,CAAC;EAED,UAAU,QAAQ;CACpB,CAAC;CAED,OAAO;AACT;;AAGA,SAAgB,cAAc,QAA4D;CACxF,OAAO,wBAAwB,SAAS,aAAA,aAAA,QAAA,aAAA,KAAA,IAAA,KAAA,IAAa,SAAU,QAAQ,CAAC;AAC1E;;AAGA,SAAgB,cAAc,QAAiE;CAC7F,OAAO,wBAAwB,SAAS,aAAA,aAAA,QAAA,aAAA,KAAA,IAAA,KAAA,IAAa,SAAU,QAAQ,CAAC;AAC1E;;;;;AAMA,SAAgB,kBACd,QACA,GAAG,MAGwB;CAC3B,OAAO,wBAAwB,SAAS,aAAa;EACnD,IAAI,KAAK,WAAW,GAClB,OAAA,aAAA,QAAA,aAAA,KAAA,IAAA,KAAA,IAAO,SAAU,SAAS,KAAK,EAAE,CAAC,GAAG,KAAK,EAAE;EAE9C,MAAM,CAAC,SAAS;EAChB,IAAI,OAAO,UAAU,YACnB,OAAA,aAAA,QAAA,aAAA,KAAA,IAAA,KAAA,IAAO,SAAU,SAAS,MAAM,CAAC;EAEnC,OAAA,aAAA,QAAA,aAAA,KAAA,IAAA,KAAA,IAAO,SAAU,SAAS,KAAK;CACjC,CAAC;AACH;;AAGA,SAAgB,iBAAiB,QAA6D;CAC5F,OAAO,wBAAwB,SAAS,aAAA,aAAA,QAAA,aAAA,KAAA,IAAA,KAAA,IAAa,SAAU,OAAO;AACxE;;AAGA,SAAgB,oBAAoB,QAA6D;CAC/F,OAAO,wBAAwB,SAAS,aAAA,aAAA,QAAA,aAAA,KAAA,IAAA,KAAA,IAAa,SAAU,UAAU;AAC3E;;AAGA,SAAgB,mBAAmB,QAA6D;CAC9F,OAAO,wBAAwB,SAAS,aAAA,aAAA,QAAA,aAAA,KAAA,IAAA,KAAA,IAAa,SAAU,SAAS;AAC1E"}
package/package.json CHANGED
@@ -1,68 +1,63 @@
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": "0.9.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
+ "main": "./dist/index.cjs",
30
+ "module": "./dist/index.js",
31
+ "types": "./dist/index.d.cts",
32
+ "exports": {
33
+ ".": {
34
+ "import": "./dist/index.js",
35
+ "require": "./dist/index.cjs"
36
+ },
37
+ "./package.json": "./package.json"
38
+ },
39
+ "publishConfig": {
40
+ "access": "public"
24
41
  },
25
- "license": "MIT",
26
- "keywords": [
27
- "pridepack"
28
- ],
29
- "name": "solid-tiptap",
30
42
  "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"
43
+ "@tiptap/core": "^3.31.4",
44
+ "@tiptap/pm": "^3.31.4",
45
+ "publint": "^0.3.25",
46
+ "solid-js": "^1.9.15",
47
+ "tsdown": "^0.23.0",
48
+ "typescript": "^7.0.2"
38
49
  },
39
50
  "peerDependencies": {
40
51
  "@tiptap/core": "^3",
41
52
  "@tiptap/pm": "^3",
42
53
  "solid-js": "^1.7"
43
54
  },
44
- "scripts": {
45
- "prepublishOnly": "pridepack clean && pridepack build",
46
- "build": "pridepack build",
47
- "type-check": "pridepack check",
48
- "clean": "pridepack clean"
49
- },
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": ">=18"
66
57
  },
67
- "gitHead": "2ed0a8715a8c1c2e537626f02c17e60a34a70257"
68
- }
58
+ "scripts": {
59
+ "build": "tsdown",
60
+ "type-check": "tsc --noEmit",
61
+ "watch": "tsdown --watch"
62
+ }
63
+ }
package/src/Editor.ts ADDED
@@ -0,0 +1,113 @@
1
+ import type { EditorOptions, JSONContent } 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> extends BaseEditorOptions {
10
+ element: T;
11
+ }
12
+
13
+ /**
14
+ * Reads a value from the editor and reads it again after every transaction.
15
+ * `read` also receives `undefined` while `instance` returns no editor.
16
+ */
17
+ export function createEditorTransaction<T, V extends Editor | undefined>(
18
+ instance: () => V,
19
+ read: (value: V) => T,
20
+ ): () => T {
21
+ const [depend, update] = createSignal(undefined, { equals: false });
22
+
23
+ function forceUpdate(): void {
24
+ update();
25
+ }
26
+
27
+ createEffect(() => {
28
+ const editor = instance();
29
+ if (editor) {
30
+ editor.on('transaction', forceUpdate);
31
+ onCleanup(() => {
32
+ editor.off('transaction', forceUpdate);
33
+ });
34
+ }
35
+ });
36
+
37
+ return () => {
38
+ depend();
39
+ return read(instance());
40
+ };
41
+ }
42
+
43
+ /**
44
+ * Creates a Tiptap editor from the given options.
45
+ * The editor is destroyed and created again when a signal read by `props` changes.
46
+ * It is also destroyed when the owner is disposed.
47
+ */
48
+ export default function useEditor<T extends HTMLElement>(
49
+ props: () => UseEditorOptions<T>,
50
+ ): () => Editor | undefined {
51
+ const [signal, setSignal] = createSignal<Editor>();
52
+
53
+ createEffect(() => {
54
+ const instance = new Editor({
55
+ ...props(),
56
+ });
57
+
58
+ onCleanup(() => {
59
+ instance.destroy();
60
+ });
61
+
62
+ setSignal(instance);
63
+ });
64
+
65
+ return signal;
66
+ }
67
+
68
+ /** Returns the editor content as HTML. */
69
+ export function useEditorHTML(editor: () => Editor | undefined): () => string | undefined {
70
+ return createEditorTransaction(editor, (instance) => instance?.getHTML());
71
+ }
72
+
73
+ /** Returns the editor content as Tiptap JSON. */
74
+ export function useEditorJSON(editor: () => Editor | undefined): () => JSONContent | undefined {
75
+ return createEditorTransaction(editor, (instance) => instance?.getJSON());
76
+ }
77
+
78
+ /**
79
+ * Returns whether the node or mark at the selection is active.
80
+ * Pass a node or mark name with optional attributes, or only the attributes.
81
+ */
82
+ export function useEditorIsActive(
83
+ editor: () => Editor | undefined,
84
+ ...args:
85
+ | [name: () => string, options?: Record<string, unknown>]
86
+ | [options: Record<string, unknown>]
87
+ ): () => boolean | undefined {
88
+ return createEditorTransaction(editor, (instance) => {
89
+ if (args.length === 2) {
90
+ return instance?.isActive(args[0](), args[1]);
91
+ }
92
+ const [first] = args;
93
+ if (typeof first === 'function') {
94
+ return instance?.isActive(first());
95
+ }
96
+ return instance?.isActive(first);
97
+ });
98
+ }
99
+
100
+ /** Returns whether the editor has no content. */
101
+ export function useEditorIsEmpty(editor: () => Editor | undefined): () => boolean | undefined {
102
+ return createEditorTransaction(editor, (instance) => instance?.isEmpty);
103
+ }
104
+
105
+ /** Returns whether the editor accepts input. */
106
+ export function useEditorIsEditable(editor: () => Editor | undefined): () => boolean | undefined {
107
+ return createEditorTransaction(editor, (instance) => instance?.isEditable);
108
+ }
109
+
110
+ /** Returns whether the editor has focus. */
111
+ export function useEditorIsFocused(editor: () => Editor | undefined): () => boolean | undefined {
112
+ return createEditorTransaction(editor, (instance) => instance?.isFocused);
113
+ }
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
- }