solid-tiptap 0.6.0 → 0.8.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 +17 -15
- package/dist/cjs/development/index.cjs +3 -8
- package/dist/cjs/development/index.cjs.map +2 -2
- package/dist/cjs/production/index.cjs +1 -1
- package/dist/esm/development/index.mjs +4 -15
- package/dist/esm/development/index.mjs.map +2 -2
- package/dist/esm/production/index.mjs +1 -1
- package/dist/types/Editor.d.ts +16 -14
- package/dist/types/Editor.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -1
- package/dist/types/index.d.ts.map +1 -0
- package/package.json +14 -19
- package/src/Editor.tsx +22 -28
- package/src/index.ts +7 -5
package/README.md
CHANGED
|
@@ -2,16 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
> SolidJS bindings for [tiptap](https://www.tiptap.dev/)
|
|
4
4
|
|
|
5
|
-
[](https://www.npmjs.com/package/solid-tiptap) [](https://github.com/airbnb/javascript) [](https://www.npmjs.com/package/solid-tiptap) [](https://github.com/airbnb/javascript) [](https://stackblitz.com/github/lxsmnsyc/solid-tiptap/tree/main/examples/simple-example)
|
|
6
6
|
|
|
7
7
|

|
|
8
8
|
|
|
9
9
|
## Install
|
|
10
10
|
|
|
11
|
+
```bash
|
|
12
|
+
npm i @tiptap/core @tiptap/pm solid-tiptap
|
|
13
|
+
```
|
|
14
|
+
|
|
11
15
|
```bash
|
|
12
16
|
yarn add @tiptap/core @tiptap/pm solid-tiptap
|
|
13
17
|
```
|
|
14
18
|
|
|
19
|
+
```bash
|
|
20
|
+
pnpm add @tiptap/core @tiptap/pm solid-tiptap
|
|
21
|
+
```
|
|
22
|
+
|
|
15
23
|
## Usage
|
|
16
24
|
|
|
17
25
|
```jsx
|
|
@@ -40,7 +48,7 @@ function App() {
|
|
|
40
48
|
```ts
|
|
41
49
|
const isBold = createEditorTransaction(
|
|
42
50
|
() => props.editor, // Editor instance from createTiptapEditor
|
|
43
|
-
(editor) => editor.isActive(
|
|
51
|
+
(editor) => editor.isActive("bold")
|
|
44
52
|
);
|
|
45
53
|
|
|
46
54
|
createEffect(() => {
|
|
@@ -52,16 +60,6 @@ createEffect(() => {
|
|
|
52
60
|
|
|
53
61
|
There are out-of-the-box utilities that wraps `createEditorTransaction` based on the [Editor API](https://www.tiptap.dev/api/editor):
|
|
54
62
|
|
|
55
|
-
- `useEditorCharacterCount`: reactively subscribe to `getCharacterCount`.
|
|
56
|
-
|
|
57
|
-
```js
|
|
58
|
-
const count = useEditorCharacterCount(() => props.editor);
|
|
59
|
-
|
|
60
|
-
createEffect(() => {
|
|
61
|
-
console.log('Character Count:', count());
|
|
62
|
-
});
|
|
63
|
-
```
|
|
64
|
-
|
|
65
63
|
- `useEditorHTML`: reactively subscribe to `getEditorHTML`.
|
|
66
64
|
|
|
67
65
|
```js
|
|
@@ -75,9 +73,13 @@ createEffect(() => {
|
|
|
75
73
|
- `useEditorIsActive`: reactively subscribe to `isActive`.
|
|
76
74
|
|
|
77
75
|
```js
|
|
78
|
-
const isHeading = useEditorIsActive(
|
|
79
|
-
|
|
80
|
-
|
|
76
|
+
const isHeading = useEditorIsActive(
|
|
77
|
+
() => props.editor,
|
|
78
|
+
() => "heading",
|
|
79
|
+
{
|
|
80
|
+
level: 1,
|
|
81
|
+
}
|
|
82
|
+
);
|
|
81
83
|
|
|
82
84
|
createEffect(() => {
|
|
83
85
|
if (isHeading()) {
|
|
@@ -35,8 +35,8 @@ __export(src_exports, {
|
|
|
35
35
|
module.exports = __toCommonJS(src_exports);
|
|
36
36
|
|
|
37
37
|
// src/Editor.tsx
|
|
38
|
-
var import_solid_js = require("solid-js");
|
|
39
38
|
var import_core = require("@tiptap/core");
|
|
39
|
+
var import_solid_js = require("solid-js");
|
|
40
40
|
function createEditorTransaction(instance, read) {
|
|
41
41
|
const [depend, update] = (0, import_solid_js.createSignal)(void 0, { equals: false });
|
|
42
42
|
function forceUpdate() {
|
|
@@ -78,14 +78,9 @@ function useEditorJSON(editor) {
|
|
|
78
78
|
function useEditorIsActive(editor, ...args) {
|
|
79
79
|
return createEditorTransaction(editor, (instance) => {
|
|
80
80
|
if (args.length === 2) {
|
|
81
|
-
return instance == null ? void 0 : instance.isActive(
|
|
82
|
-
args[0](),
|
|
83
|
-
args[1]
|
|
84
|
-
);
|
|
81
|
+
return instance == null ? void 0 : instance.isActive(args[0](), args[1]);
|
|
85
82
|
}
|
|
86
|
-
return instance == null ? void 0 : instance.isActive(
|
|
87
|
-
args[0]
|
|
88
|
-
);
|
|
83
|
+
return instance == null ? void 0 : instance.isActive(args[0]);
|
|
89
84
|
});
|
|
90
85
|
}
|
|
91
86
|
function useEditorIsEmpty(editor) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/index.ts", "../../../src/Editor.tsx"],
|
|
4
|
-
"sourcesContent": ["export {\n default as
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;
|
|
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;AAA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cAAY,qCAAU,UAAU;AACzE;AAEO,SAAS,mBACd,QAC2B;AAC3B,SAAO,wBAAwB,QAAQ,cAAY,qCAAU,SAAS;AACxE;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var s=Object.defineProperty;var
|
|
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,12 +1,6 @@
|
|
|
1
1
|
// src/Editor.tsx
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
createSignal,
|
|
5
|
-
onCleanup
|
|
6
|
-
} from "solid-js";
|
|
7
|
-
import {
|
|
8
|
-
Editor
|
|
9
|
-
} from "@tiptap/core";
|
|
2
|
+
import { Editor } from "@tiptap/core";
|
|
3
|
+
import { createEffect, createSignal, onCleanup } from "solid-js";
|
|
10
4
|
function createEditorTransaction(instance, read) {
|
|
11
5
|
const [depend, update] = createSignal(void 0, { equals: false });
|
|
12
6
|
function forceUpdate() {
|
|
@@ -48,14 +42,9 @@ function useEditorJSON(editor) {
|
|
|
48
42
|
function useEditorIsActive(editor, ...args) {
|
|
49
43
|
return createEditorTransaction(editor, (instance) => {
|
|
50
44
|
if (args.length === 2) {
|
|
51
|
-
return instance == null ? void 0 : instance.isActive(
|
|
52
|
-
args[0](),
|
|
53
|
-
args[1]
|
|
54
|
-
);
|
|
45
|
+
return instance == null ? void 0 : instance.isActive(args[0](), args[1]);
|
|
55
46
|
}
|
|
56
|
-
return instance == null ? void 0 : instance.isActive(
|
|
57
|
-
args[0]
|
|
58
|
-
);
|
|
47
|
+
return instance == null ? void 0 : instance.isActive(args[0]);
|
|
59
48
|
});
|
|
60
49
|
}
|
|
61
50
|
function useEditorIsEmpty(editor) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/Editor.tsx"],
|
|
4
|
-
"sourcesContent": ["import {
|
|
5
|
-
"mappings": ";
|
|
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,iBAA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QAC2B;AAC3B,SAAO,wBAAwB,QAAQ,cAAY,qCAAU,SAAS;AACxE;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createEffect as E,createSignal as s,onCleanup as f}from"solid-js";
|
|
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
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export type
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export declare function
|
|
11
|
-
export declare function
|
|
12
|
-
export declare function
|
|
13
|
-
export declare function
|
|
14
|
-
export declare function
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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,uBA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AC7D,MAAM,EAAE,MAAM,CAAC,GACd,MAAM,OAAO,GAAG,SAAS,CAE3B"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1 +1,3 @@
|
|
|
1
|
-
export { default as
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
2
|
+
"version": "0.8.0",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"types": "./dist/types/index.d.ts",
|
|
5
5
|
"main": "./dist/cjs/production/index.cjs",
|
|
6
6
|
"module": "./dist/esm/production/index.mjs",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": {
|
|
9
|
+
"types": "./dist/types/index.d.ts",
|
|
9
10
|
"development": {
|
|
10
11
|
"require": "./dist/cjs/development/index.cjs",
|
|
11
12
|
"import": "./dist/esm/development/index.mjs"
|
|
12
13
|
},
|
|
13
14
|
"require": "./dist/cjs/production/index.cjs",
|
|
14
|
-
"import": "./dist/esm/production/index.mjs"
|
|
15
|
-
"types": "./dist/types/index.d.ts"
|
|
15
|
+
"import": "./dist/esm/production/index.mjs"
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
18
|
"files": [
|
|
@@ -28,29 +28,24 @@
|
|
|
28
28
|
],
|
|
29
29
|
"name": "solid-tiptap",
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@tiptap/core": "^
|
|
32
|
-
"@tiptap/pm": "^
|
|
33
|
-
"@types/node": "^
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"tslib": "^2.5.0",
|
|
39
|
-
"typescript": "^4.9.5"
|
|
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"
|
|
40
38
|
},
|
|
41
39
|
"peerDependencies": {
|
|
42
|
-
"@tiptap/core": "^
|
|
43
|
-
"@tiptap/pm": "^
|
|
40
|
+
"@tiptap/core": "^3",
|
|
41
|
+
"@tiptap/pm": "^3",
|
|
44
42
|
"solid-js": "^1.7"
|
|
45
43
|
},
|
|
46
44
|
"scripts": {
|
|
47
45
|
"prepublishOnly": "pridepack clean && pridepack build",
|
|
48
46
|
"build": "pridepack build",
|
|
49
47
|
"type-check": "pridepack check",
|
|
50
|
-
"
|
|
51
|
-
"test": "pridepack test --passWithNoTests",
|
|
52
|
-
"clean": "pridepack clean",
|
|
53
|
-
"watch": "pridepack watch"
|
|
48
|
+
"clean": "pridepack clean"
|
|
54
49
|
},
|
|
55
50
|
"description": "SolidJS bindings for Tiptap",
|
|
56
51
|
"repository": {
|
|
@@ -69,5 +64,5 @@
|
|
|
69
64
|
"typesVersions": {
|
|
70
65
|
"*": {}
|
|
71
66
|
},
|
|
72
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "2ed0a8715a8c1c2e537626f02c17e60a34a70257"
|
|
73
68
|
}
|
package/src/Editor.tsx
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
onCleanup,
|
|
5
|
-
} from 'solid-js';
|
|
6
|
-
import {
|
|
7
|
-
Editor,
|
|
8
|
-
EditorOptions,
|
|
9
|
-
} from '@tiptap/core';
|
|
1
|
+
import type { EditorOptions } from '@tiptap/core';
|
|
2
|
+
import { Editor } from '@tiptap/core';
|
|
3
|
+
import { createEffect, createSignal, onCleanup } from 'solid-js';
|
|
10
4
|
|
|
11
5
|
export type EditorRef = Editor | ((editor: Editor) => void);
|
|
12
6
|
|
|
13
7
|
export type BaseEditorOptions = Omit<Partial<EditorOptions>, 'element'>;
|
|
14
8
|
|
|
15
|
-
export interface UseEditorOptions<T extends HTMLElement>
|
|
9
|
+
export interface UseEditorOptions<T extends HTMLElement>
|
|
10
|
+
extends BaseEditorOptions {
|
|
16
11
|
element: T;
|
|
17
12
|
}
|
|
18
13
|
|
|
@@ -23,7 +18,7 @@ export function createEditorTransaction<T, V extends Editor | undefined>(
|
|
|
23
18
|
const [depend, update] = createSignal(undefined, { equals: false });
|
|
24
19
|
|
|
25
20
|
function forceUpdate() {
|
|
26
|
-
update()
|
|
21
|
+
update();
|
|
27
22
|
}
|
|
28
23
|
|
|
29
24
|
createEffect(() => {
|
|
@@ -65,46 +60,45 @@ export default function useEditor<T extends HTMLElement>(
|
|
|
65
60
|
export function useEditorHTML<V extends Editor | undefined>(
|
|
66
61
|
editor: () => V,
|
|
67
62
|
): () => string | undefined {
|
|
68
|
-
return createEditorTransaction(editor,
|
|
63
|
+
return createEditorTransaction(editor, instance => instance?.getHTML());
|
|
69
64
|
}
|
|
70
65
|
|
|
71
|
-
export function useEditorJSON<
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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);
|
|
75
71
|
}
|
|
76
72
|
|
|
77
|
-
export function useEditorIsActive<
|
|
73
|
+
export function useEditorIsActive<
|
|
74
|
+
V extends Editor | undefined,
|
|
75
|
+
R extends Record<string, any>,
|
|
76
|
+
>(
|
|
78
77
|
editor: () => V,
|
|
79
78
|
...args: [name: () => string, options?: R] | [options: R]
|
|
80
79
|
): () => boolean | undefined {
|
|
81
|
-
return createEditorTransaction(editor,
|
|
80
|
+
return createEditorTransaction(editor, instance => {
|
|
82
81
|
if (args.length === 2) {
|
|
83
|
-
return instance?.isActive(
|
|
84
|
-
args[0](),
|
|
85
|
-
args[1],
|
|
86
|
-
);
|
|
82
|
+
return instance?.isActive(args[0](), args[1]);
|
|
87
83
|
}
|
|
88
|
-
return instance?.isActive(
|
|
89
|
-
args[0],
|
|
90
|
-
);
|
|
84
|
+
return instance?.isActive(args[0]);
|
|
91
85
|
});
|
|
92
86
|
}
|
|
93
87
|
|
|
94
88
|
export function useEditorIsEmpty<V extends Editor | undefined>(
|
|
95
89
|
editor: () => V,
|
|
96
90
|
): () => boolean | undefined {
|
|
97
|
-
return createEditorTransaction(editor,
|
|
91
|
+
return createEditorTransaction(editor, instance => instance?.isEmpty);
|
|
98
92
|
}
|
|
99
93
|
|
|
100
94
|
export function useEditorIsEditable<V extends Editor | undefined>(
|
|
101
95
|
editor: () => V,
|
|
102
96
|
): () => boolean | undefined {
|
|
103
|
-
return createEditorTransaction(editor,
|
|
97
|
+
return createEditorTransaction(editor, instance => instance?.isEditable);
|
|
104
98
|
}
|
|
105
99
|
|
|
106
100
|
export function useEditorIsFocused<V extends Editor | undefined>(
|
|
107
101
|
editor: () => V,
|
|
108
102
|
): () => boolean | undefined {
|
|
109
|
-
return createEditorTransaction(editor,
|
|
103
|
+
return createEditorTransaction(editor, instance => instance?.isFocused);
|
|
110
104
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
export {
|
|
2
|
-
default as useEditor,
|
|
3
2
|
default as createEditor,
|
|
4
|
-
default as useTiptapEditor,
|
|
5
|
-
default as createTiptapEditor,
|
|
6
|
-
UseEditorOptions,
|
|
7
|
-
EditorRef,
|
|
8
3
|
createEditorTransaction,
|
|
4
|
+
default as createTiptapEditor,
|
|
5
|
+
default as useEditor,
|
|
9
6
|
useEditorHTML,
|
|
10
7
|
useEditorIsActive,
|
|
11
8
|
useEditorIsEditable,
|
|
12
9
|
useEditorIsEmpty,
|
|
13
10
|
useEditorIsFocused,
|
|
14
11
|
useEditorJSON,
|
|
12
|
+
default as useTiptapEditor,
|
|
13
|
+
} from './Editor';
|
|
14
|
+
export type {
|
|
15
|
+
EditorRef,
|
|
16
|
+
UseEditorOptions,
|
|
15
17
|
} from './Editor';
|