solid-tiptap 0.5.1 → 0.7.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 +9 -1
- package/dist/cjs/development/index.cjs +6 -15
- package/dist/cjs/development/index.cjs.map +2 -2
- package/dist/cjs/production/index.cjs +1 -1
- package/dist/esm/development/index.mjs +7 -22
- package/dist/esm/development/index.mjs.map +2 -2
- package/dist/esm/production/index.mjs +1 -1
- package/dist/types/Editor.d.ts +16 -15
- 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 +13 -18
- package/src/Editor.tsx +24 -36
- package/src/index.ts +7 -6
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
|
|
@@ -24,7 +24,6 @@ __export(src_exports, {
|
|
|
24
24
|
createEditorTransaction: () => createEditorTransaction,
|
|
25
25
|
createTiptapEditor: () => useEditor,
|
|
26
26
|
useEditor: () => useEditor,
|
|
27
|
-
useEditorCharacterCount: () => useEditorCharacterCount,
|
|
28
27
|
useEditorHTML: () => useEditorHTML,
|
|
29
28
|
useEditorIsActive: () => useEditorIsActive,
|
|
30
29
|
useEditorIsEditable: () => useEditorIsEditable,
|
|
@@ -36,12 +35,12 @@ __export(src_exports, {
|
|
|
36
35
|
module.exports = __toCommonJS(src_exports);
|
|
37
36
|
|
|
38
37
|
// src/Editor.tsx
|
|
39
|
-
var import_solid_js = require("solid-js");
|
|
40
38
|
var import_core = require("@tiptap/core");
|
|
39
|
+
var import_solid_js = require("solid-js");
|
|
41
40
|
function createEditorTransaction(instance, read) {
|
|
42
|
-
const [
|
|
41
|
+
const [depend, update] = (0, import_solid_js.createSignal)(void 0, { equals: false });
|
|
43
42
|
function forceUpdate() {
|
|
44
|
-
|
|
43
|
+
update();
|
|
45
44
|
}
|
|
46
45
|
(0, import_solid_js.createEffect)(() => {
|
|
47
46
|
const editor = instance();
|
|
@@ -53,7 +52,7 @@ function createEditorTransaction(instance, read) {
|
|
|
53
52
|
}
|
|
54
53
|
});
|
|
55
54
|
return () => {
|
|
56
|
-
|
|
55
|
+
depend();
|
|
57
56
|
return read(instance());
|
|
58
57
|
};
|
|
59
58
|
}
|
|
@@ -76,20 +75,12 @@ function useEditorHTML(editor) {
|
|
|
76
75
|
function useEditorJSON(editor) {
|
|
77
76
|
return createEditorTransaction(editor, (instance) => instance == null ? void 0 : instance.getJSON());
|
|
78
77
|
}
|
|
79
|
-
function useEditorCharacterCount(editor) {
|
|
80
|
-
return createEditorTransaction(editor, (instance) => instance == null ? void 0 : instance.getCharacterCount());
|
|
81
|
-
}
|
|
82
78
|
function useEditorIsActive(editor, ...args) {
|
|
83
79
|
return createEditorTransaction(editor, (instance) => {
|
|
84
80
|
if (args.length === 2) {
|
|
85
|
-
return instance == null ? void 0 : instance.isActive(
|
|
86
|
-
args[0](),
|
|
87
|
-
args[1]
|
|
88
|
-
);
|
|
81
|
+
return instance == null ? void 0 : instance.isActive(args[0](), args[1]);
|
|
89
82
|
}
|
|
90
|
-
return instance == null ? void 0 : instance.isActive(
|
|
91
|
-
args[0]
|
|
92
|
-
);
|
|
83
|
+
return instance == null ? void 0 : instance.isActive(args[0]);
|
|
93
84
|
});
|
|
94
85
|
}
|
|
95
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);\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
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,16 +1,10 @@
|
|
|
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
|
-
const [
|
|
5
|
+
const [depend, update] = createSignal(void 0, { equals: false });
|
|
12
6
|
function forceUpdate() {
|
|
13
|
-
|
|
7
|
+
update();
|
|
14
8
|
}
|
|
15
9
|
createEffect(() => {
|
|
16
10
|
const editor = instance();
|
|
@@ -22,7 +16,7 @@ function createEditorTransaction(instance, read) {
|
|
|
22
16
|
}
|
|
23
17
|
});
|
|
24
18
|
return () => {
|
|
25
|
-
|
|
19
|
+
depend();
|
|
26
20
|
return read(instance());
|
|
27
21
|
};
|
|
28
22
|
}
|
|
@@ -45,20 +39,12 @@ function useEditorHTML(editor) {
|
|
|
45
39
|
function useEditorJSON(editor) {
|
|
46
40
|
return createEditorTransaction(editor, (instance) => instance == null ? void 0 : instance.getJSON());
|
|
47
41
|
}
|
|
48
|
-
function useEditorCharacterCount(editor) {
|
|
49
|
-
return createEditorTransaction(editor, (instance) => instance == null ? void 0 : instance.getCharacterCount());
|
|
50
|
-
}
|
|
51
42
|
function useEditorIsActive(editor, ...args) {
|
|
52
43
|
return createEditorTransaction(editor, (instance) => {
|
|
53
44
|
if (args.length === 2) {
|
|
54
|
-
return instance == null ? void 0 : instance.isActive(
|
|
55
|
-
args[0](),
|
|
56
|
-
args[1]
|
|
57
|
-
);
|
|
45
|
+
return instance == null ? void 0 : instance.isActive(args[0](), args[1]);
|
|
58
46
|
}
|
|
59
|
-
return instance == null ? void 0 : instance.isActive(
|
|
60
|
-
args[0]
|
|
61
|
-
);
|
|
47
|
+
return instance == null ? void 0 : instance.isActive(args[0]);
|
|
62
48
|
});
|
|
63
49
|
}
|
|
64
50
|
function useEditorIsEmpty(editor) {
|
|
@@ -75,7 +61,6 @@ export {
|
|
|
75
61
|
createEditorTransaction,
|
|
76
62
|
useEditor as createTiptapEditor,
|
|
77
63
|
useEditor,
|
|
78
|
-
useEditorCharacterCount,
|
|
79
64
|
useEditorHTML,
|
|
80
65
|
useEditorIsActive,
|
|
81
66
|
useEditorIsEditable,
|
|
@@ -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);\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
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,15 +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 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;
|
|
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,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
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,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
2
|
+
"version": "0.7.0",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"types": "./dist/types/index.d.ts",
|
|
5
5
|
"main": "./dist/cjs/production/index.cjs",
|
|
@@ -28,29 +28,24 @@
|
|
|
28
28
|
],
|
|
29
29
|
"name": "solid-tiptap",
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@tiptap/core": "^2.
|
|
32
|
-
"@tiptap/pm": "^2.
|
|
33
|
-
"@types/node": "^
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"tslib": "^2.5.0",
|
|
39
|
-
"typescript": "^4.9.5"
|
|
31
|
+
"@tiptap/core": "^2.1.16",
|
|
32
|
+
"@tiptap/pm": "^2.1.16",
|
|
33
|
+
"@types/node": "^20.11.8",
|
|
34
|
+
"pridepack": "2.6.0",
|
|
35
|
+
"solid-js": "^1.8.12",
|
|
36
|
+
"tslib": "^2.6.0",
|
|
37
|
+
"typescript": "^5.3.3"
|
|
40
38
|
},
|
|
41
39
|
"peerDependencies": {
|
|
42
|
-
"@tiptap/core": "^2
|
|
43
|
-
"@tiptap/pm": "^2
|
|
44
|
-
"solid-js": "^1.
|
|
40
|
+
"@tiptap/core": "^2",
|
|
41
|
+
"@tiptap/pm": "^2",
|
|
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": "6b7f27a7430bba6cb5594210cd06fb0bdad30e6b"
|
|
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
|
|
|
@@ -20,10 +15,10 @@ export function createEditorTransaction<T, V extends Editor | undefined>(
|
|
|
20
15
|
instance: () => V,
|
|
21
16
|
read: (value: V) => T,
|
|
22
17
|
): () => T {
|
|
23
|
-
const [
|
|
18
|
+
const [depend, update] = createSignal(undefined, { equals: false });
|
|
24
19
|
|
|
25
20
|
function forceUpdate() {
|
|
26
|
-
|
|
21
|
+
update();
|
|
27
22
|
}
|
|
28
23
|
|
|
29
24
|
createEffect(() => {
|
|
@@ -37,7 +32,7 @@ export function createEditorTransaction<T, V extends Editor | undefined>(
|
|
|
37
32
|
});
|
|
38
33
|
|
|
39
34
|
return () => {
|
|
40
|
-
|
|
35
|
+
depend();
|
|
41
36
|
return read(instance());
|
|
42
37
|
};
|
|
43
38
|
}
|
|
@@ -65,52 +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
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
export function useEditorCharacterCount<V extends Editor | undefined>(
|
|
78
|
-
editor: () => V,
|
|
79
|
-
): () => number | undefined {
|
|
80
|
-
return createEditorTransaction(editor, (instance) => instance?.getCharacterCount());
|
|
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);
|
|
81
71
|
}
|
|
82
72
|
|
|
83
|
-
export function useEditorIsActive<
|
|
73
|
+
export function useEditorIsActive<
|
|
74
|
+
V extends Editor | undefined,
|
|
75
|
+
R extends Record<string, any>,
|
|
76
|
+
>(
|
|
84
77
|
editor: () => V,
|
|
85
78
|
...args: [name: () => string, options?: R] | [options: R]
|
|
86
79
|
): () => boolean | undefined {
|
|
87
|
-
return createEditorTransaction(editor,
|
|
80
|
+
return createEditorTransaction(editor, instance => {
|
|
88
81
|
if (args.length === 2) {
|
|
89
|
-
return instance?.isActive(
|
|
90
|
-
args[0](),
|
|
91
|
-
args[1],
|
|
92
|
-
);
|
|
82
|
+
return instance?.isActive(args[0](), args[1]);
|
|
93
83
|
}
|
|
94
|
-
return instance?.isActive(
|
|
95
|
-
args[0],
|
|
96
|
-
);
|
|
84
|
+
return instance?.isActive(args[0]);
|
|
97
85
|
});
|
|
98
86
|
}
|
|
99
87
|
|
|
100
88
|
export function useEditorIsEmpty<V extends Editor | undefined>(
|
|
101
89
|
editor: () => V,
|
|
102
90
|
): () => boolean | undefined {
|
|
103
|
-
return createEditorTransaction(editor,
|
|
91
|
+
return createEditorTransaction(editor, instance => instance?.isEmpty);
|
|
104
92
|
}
|
|
105
93
|
|
|
106
94
|
export function useEditorIsEditable<V extends Editor | undefined>(
|
|
107
95
|
editor: () => V,
|
|
108
96
|
): () => boolean | undefined {
|
|
109
|
-
return createEditorTransaction(editor,
|
|
97
|
+
return createEditorTransaction(editor, instance => instance?.isEditable);
|
|
110
98
|
}
|
|
111
99
|
|
|
112
100
|
export function useEditorIsFocused<V extends Editor | undefined>(
|
|
113
101
|
editor: () => V,
|
|
114
102
|
): () => boolean | undefined {
|
|
115
|
-
return createEditorTransaction(editor,
|
|
103
|
+
return createEditorTransaction(editor, instance => instance?.isFocused);
|
|
116
104
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,16 +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,
|
|
9
|
-
|
|
4
|
+
default as createTiptapEditor,
|
|
5
|
+
default as useEditor,
|
|
10
6
|
useEditorHTML,
|
|
11
7
|
useEditorIsActive,
|
|
12
8
|
useEditorIsEditable,
|
|
13
9
|
useEditorIsEmpty,
|
|
14
10
|
useEditorIsFocused,
|
|
15
11
|
useEditorJSON,
|
|
12
|
+
default as useTiptapEditor,
|
|
13
|
+
} from './Editor';
|
|
14
|
+
export type {
|
|
15
|
+
EditorRef,
|
|
16
|
+
UseEditorOptions,
|
|
16
17
|
} from './Editor';
|