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 CHANGED
@@ -2,16 +2,24 @@
2
2
 
3
3
  > SolidJS bindings for [tiptap](https://www.tiptap.dev/)
4
4
 
5
- [![NPM](https://img.shields.io/npm/v/solid-tiptap.svg)](https://www.npmjs.com/package/solid-tiptap) [![JavaScript Style Guide](https://badgen.net/badge/code%20style/airbnb/ff5a5f?icon=airbnb)](https://github.com/airbnb/javascript) [![Open in CodeSandbox](https://img.shields.io/badge/Open%20in-CodeSandbox-blue?style=flat-square&logo=codesandbox)](https://codesandbox.io/s/github/LXSMNSYC/solid-tiptap/tree/main/examples/simple-example)
5
+ [![NPM](https://img.shields.io/npm/v/solid-tiptap.svg)](https://www.npmjs.com/package/solid-tiptap) [![JavaScript Style Guide](https://badgen.net/badge/code%20style/airbnb/ff5a5f?icon=airbnb)](https://github.com/airbnb/javascript) [![Open in StackBlitz](https://img.shields.io/badge/Open%20in-StackBlitz-blue?style=flat-square&logo=stackblitz)](https://stackblitz.com/github/lxsmnsyc/solid-tiptap/tree/main/examples/simple-example)
6
6
 
7
7
  ![solid-tiptap example](https://github.com/lxsmnsyc/solid-tiptap/blob/main/images/solid-tiptap.png?raw=true)
8
8
 
9
9
  ## Install
10
10
 
11
+ ```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 [signal, setSignal] = (0, import_solid_js.createSignal)([]);
41
+ const [depend, update] = (0, import_solid_js.createSignal)(void 0, { equals: false });
43
42
  function forceUpdate() {
44
- setSignal([]);
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
- signal();
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 useEditor,\n default as createEditor,\n default as useTiptapEditor,\n default as createTiptapEditor,\n UseEditorOptions,\n EditorRef,\n createEditorTransaction,\n useEditorCharacterCount,\n useEditorHTML,\n useEditorIsActive,\n useEditorIsEditable,\n useEditorIsEmpty,\n useEditorIsFocused,\n useEditorJSON,\n} from './Editor';\n", "import {\n createEffect,\n createSignal,\n onCleanup,\n} from 'solid-js';\nimport {\n Editor,\n EditorOptions,\n} from '@tiptap/core';\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\nexport function createEditorTransaction<T, V extends Editor | undefined>(\n instance: () => V,\n read: (value: V) => T,\n): () => T {\n const [signal, setSignal] = createSignal([]);\n\n function forceUpdate() {\n setSignal([]);\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 signal();\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<V extends Editor | undefined, R extends Record<string, any>>(\n editor: () => V,\n): () => R | undefined {\n return createEditorTransaction(editor, (instance) => instance?.getJSON() as R);\n}\n\nexport function useEditorCharacterCount<V extends Editor | undefined>(\n editor: () => V,\n): () => number | undefined {\n return createEditorTransaction(editor, (instance) => instance?.getCharacterCount());\n}\n\nexport function useEditorIsActive<V extends Editor | undefined, R extends Record<string, any>>(\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(\n args[0](),\n args[1],\n );\n }\n return instance?.isActive(\n args[0],\n );\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;AAAA;;;ACAA,sBAIO;AACP,kBAGO;AAUA,SAAS,wBACd,UACA,MACS;AACT,QAAM,CAAC,QAAQ,SAAS,QAAI,8BAAa,CAAC,CAAC;AAE3C,WAAS,cAAc;AACrB,cAAU,CAAC,CAAC;AAAA,EACd;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,CAAC,aAAa,qCAAU,SAAS;AAC1E;AAEO,SAAS,cACd,QACqB;AACrB,SAAO,wBAAwB,QAAQ,CAAC,aAAa,qCAAU,SAAc;AAC/E;AAEO,SAAS,wBACd,QAC0B;AAC1B,SAAO,wBAAwB,QAAQ,CAAC,aAAa,qCAAU,mBAAmB;AACpF;AAEO,SAAS,kBACd,WACG,MACwB;AAC3B,SAAO,wBAAwB,QAAQ,CAAC,aAAa;AACnD,QAAI,KAAK,WAAW,GAAG;AACrB,aAAO,qCAAU;AAAA,QACf,KAAK,CAAC,EAAE;AAAA,QACR,KAAK,CAAC;AAAA;AAAA,IAEV;AACA,WAAO,qCAAU;AAAA,MACf,KAAK,CAAC;AAAA;AAAA,EAEV,CAAC;AACH;AAEO,SAAS,iBACd,QAC2B;AAC3B,SAAO,wBAAwB,QAAQ,CAAC,aAAa,qCAAU,OAAO;AACxE;AAEO,SAAS,oBACd,QAC2B;AAC3B,SAAO,wBAAwB,QAAQ,CAAC,aAAa,qCAAU,UAAU;AAC3E;AAEO,SAAS,mBACd,QAC2B;AAC3B,SAAO,wBAAwB,QAAQ,CAAC,aAAa,qCAAU,SAAS;AAC1E;",
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 O=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var R=Object.prototype.hasOwnProperty;var b=(t,e)=>{for(var o in e)s(t,o,{get:e[o],enumerable:!0})},y=(t,e,o,u)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of g(e))!R.call(t,i)&&i!==o&&s(t,i,{get:()=>e[i],enumerable:!(u=O(e,i))||u.enumerable});return t};var I=t=>y(s({},"__esModule",{value:!0}),t);var C={};b(C,{createEditor:()=>n,createEditorTransaction:()=>d,createTiptapEditor:()=>n,useEditor:()=>n,useEditorCharacterCount:()=>l,useEditorHTML:()=>p,useEditorIsActive:()=>a,useEditorIsEditable:()=>T,useEditorIsEmpty:()=>V,useEditorIsFocused:()=>m,useEditorJSON:()=>x,useTiptapEditor:()=>n});module.exports=I(C);var r=require("solid-js"),f=require("@tiptap/core");function d(t,e){let[o,u]=(0,r.createSignal)([]);function i(){u([])}return(0,r.createEffect)(()=>{let E=t();E&&(E.on("transaction",i),(0,r.onCleanup)(()=>{E.off("transaction",i)}))}),()=>(o(),e(t()))}function n(t){let[e,o]=(0,r.createSignal)();return(0,r.createEffect)(()=>{let u=new f.Editor({...t()});(0,r.onCleanup)(()=>{u.destroy()}),o(u)}),e}function p(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 l(t){return d(t,e=>e==null?void 0:e.getCharacterCount())}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 V(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 m(t){return d(t,e=>e==null?void 0:e.isFocused)}
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
- createEffect,
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 [signal, setSignal] = createSignal([]);
5
+ const [depend, update] = createSignal(void 0, { equals: false });
12
6
  function forceUpdate() {
13
- setSignal([]);
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
- signal();
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 {\n createEffect,\n createSignal,\n onCleanup,\n} from 'solid-js';\nimport {\n Editor,\n EditorOptions,\n} from '@tiptap/core';\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\nexport function createEditorTransaction<T, V extends Editor | undefined>(\n instance: () => V,\n read: (value: V) => T,\n): () => T {\n const [signal, setSignal] = createSignal([]);\n\n function forceUpdate() {\n setSignal([]);\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 signal();\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<V extends Editor | undefined, R extends Record<string, any>>(\n editor: () => V,\n): () => R | undefined {\n return createEditorTransaction(editor, (instance) => instance?.getJSON() as R);\n}\n\nexport function useEditorCharacterCount<V extends Editor | undefined>(\n editor: () => V,\n): () => number | undefined {\n return createEditorTransaction(editor, (instance) => instance?.getCharacterCount());\n}\n\nexport function useEditorIsActive<V extends Editor | undefined, R extends Record<string, any>>(\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(\n args[0](),\n args[1],\n );\n }\n return instance?.isActive(\n args[0],\n );\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,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,OAEK;AAUA,SAAS,wBACd,UACA,MACS;AACT,QAAM,CAAC,QAAQ,SAAS,IAAI,aAAa,CAAC,CAAC;AAE3C,WAAS,cAAc;AACrB,cAAU,CAAC,CAAC;AAAA,EACd;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,CAAC,aAAa,qCAAU,SAAS;AAC1E;AAEO,SAAS,cACd,QACqB;AACrB,SAAO,wBAAwB,QAAQ,CAAC,aAAa,qCAAU,SAAc;AAC/E;AAEO,SAAS,wBACd,QAC0B;AAC1B,SAAO,wBAAwB,QAAQ,CAAC,aAAa,qCAAU,mBAAmB;AACpF;AAEO,SAAS,kBACd,WACG,MACwB;AAC3B,SAAO,wBAAwB,QAAQ,CAAC,aAAa;AACnD,QAAI,KAAK,WAAW,GAAG;AACrB,aAAO,qCAAU;AAAA,QACf,KAAK,CAAC,EAAE;AAAA,QACR,KAAK,CAAC;AAAA;AAAA,IAEV;AACA,WAAO,qCAAU;AAAA,MACf,KAAK,CAAC;AAAA;AAAA,EAEV,CAAC;AACH;AAEO,SAAS,iBACd,QAC2B;AAC3B,SAAO,wBAAwB,QAAQ,CAAC,aAAa,qCAAU,OAAO;AACxE;AAEO,SAAS,oBACd,QAC2B;AAC3B,SAAO,wBAAwB,QAAQ,CAAC,aAAa,qCAAU,UAAU;AAC3E;AAEO,SAAS,mBACd,QAC2B;AAC3B,SAAO,wBAAwB,QAAQ,CAAC,aAAa,qCAAU,SAAS;AAC1E;",
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";import{Editor as p}from"@tiptap/core";function r(t,e){let[o,i]=s([]);function n(){i([])}return E(()=>{let u=t();u&&(u.on("transaction",n),f(()=>{u.off("transaction",n)}))}),()=>(o(),e(t()))}function d(t){let[e,o]=s();return E(()=>{let i=new p({...t()});f(()=>{i.destroy()}),o(i)}),e}function x(t){return r(t,e=>e==null?void 0:e.getHTML())}function l(t){return r(t,e=>e==null?void 0:e.getJSON())}function a(t){return r(t,e=>e==null?void 0:e.getCharacterCount())}function V(t,...e){return r(t,o=>e.length===2?o==null?void 0:o.isActive(e[0](),e[1]):o==null?void 0:o.isActive(e[0]))}function T(t){return r(t,e=>e==null?void 0:e.isEmpty)}function m(t){return r(t,e=>e==null?void 0:e.isEditable)}function O(t){return r(t,e=>e==null?void 0:e.isFocused)}export{d as createEditor,r as createEditorTransaction,d as createTiptapEditor,d as useEditor,a as useEditorCharacterCount,x as useEditorHTML,V as useEditorIsActive,m as useEditorIsEditable,T as useEditorIsEmpty,O as useEditorIsFocused,l as useEditorJSON,d as useTiptapEditor};
1
+ import{Editor as p}from"@tiptap/core";import{createEffect as E,createSignal as s,onCleanup as f}from"solid-js";function d(t,e){let[o,i]=s(void 0,{equals:!1});function n(){i()}return E(()=>{let u=t();u&&(u.on("transaction",n),f(()=>{u.off("transaction",n)}))}),()=>(o(),e(t()))}function r(t){let[e,o]=s();return E(()=>{let i=new p({...t()});f(()=>{i.destroy()}),o(i)}),e}function l(t){return d(t,e=>e==null?void 0:e.getHTML())}function x(t){return d(t,e=>e==null?void 0:e.getJSON())}function a(t,...e){return d(t,o=>e.length===2?o==null?void 0:o.isActive(e[0](),e[1]):o==null?void 0:o.isActive(e[0]))}function m(t){return d(t,e=>e==null?void 0:e.isEmpty)}function T(t){return d(t,e=>e==null?void 0:e.isEditable)}function V(t){return d(t,e=>e==null?void 0:e.isFocused)}export{r as createEditor,d as createEditorTransaction,r as createTiptapEditor,r as useEditor,l as useEditorHTML,a as useEditorIsActive,T as useEditorIsEditable,m as useEditorIsEmpty,V as useEditorIsFocused,x as useEditorJSON,r as useTiptapEditor};
@@ -1,15 +1,16 @@
1
- import { Editor, EditorOptions } from '@tiptap/core';
2
- export type EditorRef = Editor | ((editor: Editor) => void);
3
- export type BaseEditorOptions = Omit<Partial<EditorOptions>, 'element'>;
4
- export interface UseEditorOptions<T extends HTMLElement> extends BaseEditorOptions {
5
- element: T;
6
- }
7
- export declare function createEditorTransaction<T, V extends Editor | undefined>(instance: () => V, read: (value: V) => T): () => T;
8
- export default function useEditor<T extends HTMLElement>(props: () => UseEditorOptions<T>): () => Editor | undefined;
9
- export declare function useEditorHTML<V extends Editor | undefined>(editor: () => V): () => string | undefined;
10
- export declare function useEditorJSON<V extends Editor | undefined, R extends Record<string, any>>(editor: () => V): () => R | undefined;
11
- export declare function useEditorCharacterCount<V extends Editor | undefined>(editor: () => V): () => number | 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;
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"}
@@ -1 +1,3 @@
1
- export { default as useEditor, default as createEditor, default as useTiptapEditor, default as createTiptapEditor, UseEditorOptions, EditorRef, createEditorTransaction, useEditorCharacterCount, useEditorHTML, useEditorIsActive, useEditorIsEditable, useEditorIsEmpty, useEditorIsFocused, useEditorJSON, } from './Editor';
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.5.1",
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.0.0-beta.220",
32
- "@tiptap/pm": "^2.0.0-beta.220",
33
- "@types/node": "^18.14.5",
34
- "eslint": "^8.35.0",
35
- "eslint-config-lxsmnsyc": "^0.4.8",
36
- "pridepack": "^2.4.1",
37
- "solid-js": "^1.6.11",
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.0.0-beta.220",
43
- "@tiptap/pm": "^2.0.0-beta.220",
44
- "solid-js": "^1.2"
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
- "lint": "pridepack lint",
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": "a3a2686c2fa2a04c84d4b5bdefbb1f74870b737d"
67
+ "gitHead": "6b7f27a7430bba6cb5594210cd06fb0bdad30e6b"
73
68
  }
package/src/Editor.tsx CHANGED
@@ -1,18 +1,13 @@
1
- import {
2
- createEffect,
3
- createSignal,
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> extends BaseEditorOptions {
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 [signal, setSignal] = createSignal([]);
18
+ const [depend, update] = createSignal(undefined, { equals: false });
24
19
 
25
20
  function forceUpdate() {
26
- setSignal([]);
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
- signal();
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, (instance) => instance?.getHTML());
63
+ return createEditorTransaction(editor, instance => instance?.getHTML());
69
64
  }
70
65
 
71
- export function useEditorJSON<V extends Editor | undefined, R extends Record<string, any>>(
72
- editor: () => V,
73
- ): () => R | undefined {
74
- return createEditorTransaction(editor, (instance) => instance?.getJSON() as R);
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<V extends Editor | undefined, R extends Record<string, any>>(
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, (instance) => {
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, (instance) => instance?.isEmpty);
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, (instance) => instance?.isEditable);
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, (instance) => instance?.isFocused);
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
- useEditorCharacterCount,
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';