solid-tiptap 0.7.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 +133 -79
- package/dist/index.cjs +89 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +36 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +78 -0
- package/dist/index.js.map +1 -0
- package/package.json +50 -55
- package/src/Editor.ts +113 -0
- package/src/index.ts +1 -4
- package/dist/cjs/development/index.cjs +0 -95
- package/dist/cjs/development/index.cjs.map +0 -7
- package/dist/cjs/production/index.cjs +0 -1
- package/dist/esm/development/index.mjs +0 -72
- package/dist/esm/development/index.mjs.map +0 -7
- package/dist/esm/production/index.mjs +0 -1
- package/dist/types/Editor.d.ts +0 -16
- package/dist/types/Editor.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -3
- package/dist/types/index.d.ts.map +0 -1
- package/src/Editor.tsx +0 -104
package/README.md
CHANGED
|
@@ -1,39 +1,46 @@
|
|
|
1
1
|
# solid-tiptap
|
|
2
2
|
|
|
3
|
-
> SolidJS bindings for [
|
|
3
|
+
> SolidJS bindings for [Tiptap](https://tiptap.dev/)
|
|
4
4
|
|
|
5
|
-
[](https://www.npmjs.com/package/solid-tiptap) [](https://www.npmjs.com/package/solid-tiptap) [](https://stackblitz.com/github/lxsmnsyc/solid-tiptap/tree/main/examples/simple-example)
|
|
6
6
|
|
|
7
7
|

|
|
8
8
|
|
|
9
9
|
## Install
|
|
10
10
|
|
|
11
11
|
```bash
|
|
12
|
-
npm i @tiptap/core @tiptap/pm
|
|
12
|
+
npm i solid-tiptap @tiptap/core @tiptap/pm
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
|
-
yarn add @tiptap/core @tiptap/pm
|
|
16
|
+
yarn add solid-tiptap @tiptap/core @tiptap/pm
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
```bash
|
|
20
|
-
pnpm add @tiptap/core @tiptap/pm
|
|
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
|
-
```
|
|
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,121 +48,168 @@ function App() {
|
|
|
41
48
|
}
|
|
42
49
|
```
|
|
43
50
|
|
|
44
|
-
|
|
51
|
+
`createTiptapEditor` returns an accessor for the editor.
|
|
45
52
|
|
|
46
|
-
|
|
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.
|
|
47
56
|
|
|
48
|
-
|
|
49
|
-
const isBold = createEditorTransaction(
|
|
50
|
-
() => props.editor, // Editor instance from createTiptapEditor
|
|
51
|
-
(editor) => editor.isActive('bold'),
|
|
52
|
-
);
|
|
57
|
+
Because the options are tracked, read signals that should not recreate the editor with `untrack`.
|
|
53
58
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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.
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
editor()?.commands.setContent('<p>New content</p>');
|
|
74
|
+
editor()?.setEditable(false);
|
|
59
75
|
```
|
|
60
76
|
|
|
61
|
-
|
|
77
|
+
### Passing the editor to other components
|
|
62
78
|
|
|
63
|
-
|
|
79
|
+
Render the components that need the editor inside `<Show>`, so they only run once the editor exists.
|
|
64
80
|
|
|
65
|
-
```
|
|
66
|
-
const
|
|
81
|
+
```tsx
|
|
82
|
+
const editor = createTiptapEditor(() => ({ ... }));
|
|
67
83
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
84
|
+
<Show when={editor()} keyed>
|
|
85
|
+
{(instance) => <Toolbar editor={instance} />}
|
|
86
|
+
</Show>
|
|
71
87
|
```
|
|
72
88
|
|
|
73
|
-
|
|
89
|
+
`keyed` passes the editor itself to the children. Without it, Solid passes an accessor, so you would write `editor={instance()}`.
|
|
74
90
|
|
|
75
|
-
|
|
76
|
-
const html = useEditorHTML(() => props.editor);
|
|
91
|
+
### Bubble and floating menus
|
|
77
92
|
|
|
78
|
-
|
|
79
|
-
updateHTML(html());
|
|
80
|
-
});
|
|
81
|
-
```
|
|
93
|
+
Tiptap's `BubbleMenu` and `FloatingMenu` extensions take an `element` option. Pass a mounted element the same way you pass the editor element.
|
|
82
94
|
|
|
83
|
-
|
|
95
|
+
```tsx
|
|
96
|
+
import BubbleMenu from '@tiptap/extension-bubble-menu';
|
|
84
97
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
});
|
|
98
|
+
function App() {
|
|
99
|
+
let container!: HTMLDivElement;
|
|
100
|
+
let menu!: HTMLDivElement;
|
|
89
101
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
|
|
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
|
+
}
|
|
95
118
|
```
|
|
96
119
|
|
|
97
|
-
|
|
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.
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
import { createEditorTransaction } from 'solid-tiptap';
|
|
98
126
|
|
|
99
|
-
|
|
100
|
-
|
|
127
|
+
const isBold = createEditorTransaction(
|
|
128
|
+
() => props.editor,
|
|
129
|
+
(editor) => editor.isActive('bold'),
|
|
130
|
+
);
|
|
101
131
|
|
|
102
132
|
createEffect(() => {
|
|
103
|
-
if (
|
|
104
|
-
//
|
|
133
|
+
if (isBold()) {
|
|
134
|
+
// ...
|
|
105
135
|
}
|
|
106
136
|
});
|
|
107
137
|
```
|
|
108
138
|
|
|
109
|
-
|
|
139
|
+
The read function receives whatever the first accessor returns. If that can be `undefined`, handle it in the read function.
|
|
110
140
|
|
|
111
|
-
```
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
// do something
|
|
117
|
-
}
|
|
118
|
-
});
|
|
141
|
+
```ts
|
|
142
|
+
const length = createEditorTransaction(
|
|
143
|
+
editor,
|
|
144
|
+
(instance) => instance?.state.doc.textContent.length ?? 0,
|
|
145
|
+
);
|
|
119
146
|
```
|
|
120
147
|
|
|
121
|
-
|
|
148
|
+
### Helpers
|
|
149
|
+
|
|
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.
|
|
151
|
+
|
|
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` |
|
|
122
160
|
|
|
123
|
-
```
|
|
124
|
-
const
|
|
161
|
+
```ts
|
|
162
|
+
const html = useEditorHTML(editor);
|
|
125
163
|
|
|
126
164
|
createEffect(() => {
|
|
127
|
-
|
|
128
|
-
// do something
|
|
129
|
-
}
|
|
165
|
+
saveHTML(html());
|
|
130
166
|
});
|
|
131
167
|
```
|
|
132
168
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
```js
|
|
136
|
-
const json = useEditorJSON(() => props.editor);
|
|
169
|
+
```ts
|
|
170
|
+
const json = useEditorJSON(editor);
|
|
137
171
|
|
|
138
172
|
createEffect(() => {
|
|
139
173
|
const data = json();
|
|
140
|
-
|
|
141
174
|
if (data) {
|
|
142
175
|
uploadJSON(data);
|
|
143
176
|
}
|
|
144
177
|
});
|
|
145
178
|
```
|
|
146
179
|
|
|
147
|
-
|
|
180
|
+
`useEditorIsActive` takes a name accessor with optional attributes, a name accessor alone, or attributes alone.
|
|
148
181
|
|
|
149
|
-
|
|
182
|
+
```ts
|
|
183
|
+
// A node or mark by name.
|
|
184
|
+
const isBold = useEditorIsActive(editor, () => 'bold');
|
|
150
185
|
|
|
151
|
-
|
|
152
|
-
const
|
|
186
|
+
// A node or mark by name and attributes.
|
|
187
|
+
const isHeading = useEditorIsActive(editor, () => 'heading', { level: 1 });
|
|
153
188
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
</Show>
|
|
189
|
+
// Any node or mark with these attributes.
|
|
190
|
+
const isCentered = useEditorIsActive(editor, { textAlign: 'center' });
|
|
157
191
|
```
|
|
158
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
|
+
|
|
159
213
|
## Sponsors
|
|
160
214
|
|
|
161
215
|

|
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"}
|
package/dist/index.d.cts
ADDED
|
@@ -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"}
|
package/dist/index.d.ts
ADDED
|
@@ -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
|
-
"
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
"
|
|
23
|
-
|
|
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": "^
|
|
32
|
-
"@tiptap/pm": "^
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"typescript": "^5.3.3"
|
|
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
|
-
"@tiptap/core": "^
|
|
41
|
-
"@tiptap/pm": "^
|
|
51
|
+
"@tiptap/core": "^3",
|
|
52
|
+
"@tiptap/pm": "^3",
|
|
42
53
|
"solid-js": "^1.7"
|
|
43
54
|
},
|
|
44
|
-
"
|
|
45
|
-
"
|
|
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
|
-
"
|
|
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
|
@@ -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);\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,SAAc;AAC7E;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);\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,SAAc;AAC7E;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};
|
package/dist/types/Editor.d.ts
DELETED
|
@@ -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"}
|
package/dist/types/index.d.ts
DELETED
|
@@ -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);
|
|
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
|
-
}
|