solid-tiptap 0.3.3 → 0.5.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/LICENSE +1 -1
- package/README.md +15 -13
- package/dist/cjs/development/index.cjs +104 -0
- package/dist/cjs/development/index.cjs.map +7 -0
- package/dist/cjs/production/index.cjs +1 -0
- package/dist/esm/development/{index.js → index.mjs} +11 -48
- package/dist/esm/development/index.mjs.map +7 -0
- package/dist/esm/production/index.mjs +1 -0
- package/dist/types/Editor.d.ts +15 -15
- package/dist/types/index.d.ts +1 -1
- package/package.json +25 -40
- package/src/Editor.tsx +2 -32
- package/dist/cjs/development/index.js +0 -156
- package/dist/cjs/development/index.js.map +0 -7
- package/dist/cjs/production/index.js +0 -3
- package/dist/cjs/production/index.js.map +0 -7
- package/dist/esm/development/index.js.map +0 -7
- package/dist/esm/production/index.js +0 -2
- package/dist/esm/production/index.js.map +0 -7
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -2,12 +2,14 @@
|
|
|
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://codesandbox.io/s/github/LXSMNSYC/solid-tiptap/tree/main/examples/simple-example)
|
|
5
|
+
[](https://www.npmjs.com/package/solid-tiptap) [](https://github.com/airbnb/javascript) [](https://codesandbox.io/s/github/LXSMNSYC/solid-tiptap/tree/main/examples/simple-example)
|
|
6
|
+
|
|
7
|
+

|
|
6
8
|
|
|
7
9
|
## Install
|
|
8
10
|
|
|
9
11
|
```bash
|
|
10
|
-
yarn add @tiptap/core solid-tiptap
|
|
12
|
+
yarn add @tiptap/core @tiptap/pm solid-tiptap
|
|
11
13
|
```
|
|
12
14
|
|
|
13
15
|
## Usage
|
|
@@ -19,17 +21,13 @@ import StarterKit from '@tiptap/starter-kit';
|
|
|
19
21
|
function App() {
|
|
20
22
|
let ref!: HTMLDivElement;
|
|
21
23
|
|
|
22
|
-
const editor = createTiptapEditor({
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return [
|
|
28
|
-
StarterKit,
|
|
29
|
-
];
|
|
30
|
-
},
|
|
24
|
+
const editor = createTiptapEditor(() => ({
|
|
25
|
+
element: ref!,
|
|
26
|
+
extensions: [
|
|
27
|
+
StarterKit,
|
|
28
|
+
],
|
|
31
29
|
content: `<p>Example Text</p>`,
|
|
32
|
-
});
|
|
30
|
+
}));
|
|
33
31
|
|
|
34
32
|
return <div id="editor" ref={ref} />;
|
|
35
33
|
}
|
|
@@ -143,13 +141,17 @@ createEffect(() => {
|
|
|
143
141
|
Since `createTiptapEditor` may return `undefined` (the instanciation is scheduled), and you're planning to pass it to another component (e.g. creating `BubbleMenu` or Toolbar), it is recommended to use ternary evaluation (e.g. `<Show>`) to check if the editor is `undefined` or not.
|
|
144
142
|
|
|
145
143
|
```js
|
|
146
|
-
const editor = createTiptapEditor({ ... });
|
|
144
|
+
const editor = createTiptapEditor(() => ({ ... }));
|
|
147
145
|
|
|
148
146
|
<Show when={editor()}>
|
|
149
147
|
{(instance) => <EditorMenu editor={instance} />}
|
|
150
148
|
</Show>
|
|
151
149
|
```
|
|
152
150
|
|
|
151
|
+
## Sponsors
|
|
152
|
+
|
|
153
|
+

|
|
154
|
+
|
|
153
155
|
## License
|
|
154
156
|
|
|
155
157
|
MIT © [lxsmnsyc](https://github.com/lxsmnsyc)
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
createEditor: () => useEditor,
|
|
24
|
+
createEditorTransaction: () => createEditorTransaction,
|
|
25
|
+
createTiptapEditor: () => useEditor,
|
|
26
|
+
useEditor: () => useEditor,
|
|
27
|
+
useEditorCharacterCount: () => useEditorCharacterCount,
|
|
28
|
+
useEditorHTML: () => useEditorHTML,
|
|
29
|
+
useEditorIsActive: () => useEditorIsActive,
|
|
30
|
+
useEditorIsEditable: () => useEditorIsEditable,
|
|
31
|
+
useEditorIsEmpty: () => useEditorIsEmpty,
|
|
32
|
+
useEditorIsFocused: () => useEditorIsFocused,
|
|
33
|
+
useEditorJSON: () => useEditorJSON,
|
|
34
|
+
useTiptapEditor: () => useEditor
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(src_exports);
|
|
37
|
+
|
|
38
|
+
// src/Editor.tsx
|
|
39
|
+
var import_solid_js = require("solid-js");
|
|
40
|
+
var import_core = require("@tiptap/core");
|
|
41
|
+
function createEditorTransaction(instance, read) {
|
|
42
|
+
const [signal, setSignal] = (0, import_solid_js.createSignal)([]);
|
|
43
|
+
function forceUpdate() {
|
|
44
|
+
setSignal([]);
|
|
45
|
+
}
|
|
46
|
+
(0, import_solid_js.createEffect)(() => {
|
|
47
|
+
const editor = instance();
|
|
48
|
+
if (editor) {
|
|
49
|
+
editor.on("transaction", forceUpdate);
|
|
50
|
+
(0, import_solid_js.onCleanup)(() => {
|
|
51
|
+
editor.off("transaction", forceUpdate);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
return () => {
|
|
56
|
+
signal();
|
|
57
|
+
return read(instance());
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function useEditor(props) {
|
|
61
|
+
const [signal, setSignal] = (0, import_solid_js.createSignal)();
|
|
62
|
+
(0, import_solid_js.createEffect)(() => {
|
|
63
|
+
const instance = new import_core.Editor({
|
|
64
|
+
...props()
|
|
65
|
+
});
|
|
66
|
+
(0, import_solid_js.onCleanup)(() => {
|
|
67
|
+
instance.destroy();
|
|
68
|
+
});
|
|
69
|
+
setSignal(instance);
|
|
70
|
+
});
|
|
71
|
+
return signal;
|
|
72
|
+
}
|
|
73
|
+
function useEditorHTML(editor) {
|
|
74
|
+
return createEditorTransaction(editor, (instance) => instance == null ? void 0 : instance.getHTML());
|
|
75
|
+
}
|
|
76
|
+
function useEditorJSON(editor) {
|
|
77
|
+
return createEditorTransaction(editor, (instance) => instance == null ? void 0 : instance.getJSON());
|
|
78
|
+
}
|
|
79
|
+
function useEditorCharacterCount(editor) {
|
|
80
|
+
return createEditorTransaction(editor, (instance) => instance == null ? void 0 : instance.getCharacterCount());
|
|
81
|
+
}
|
|
82
|
+
function useEditorIsActive(editor, ...args) {
|
|
83
|
+
return createEditorTransaction(editor, (instance) => {
|
|
84
|
+
if (args.length === 2) {
|
|
85
|
+
return instance == null ? void 0 : instance.isActive(
|
|
86
|
+
args[0](),
|
|
87
|
+
args[1]
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
return instance == null ? void 0 : instance.isActive(
|
|
91
|
+
args[0]
|
|
92
|
+
);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
function useEditorIsEmpty(editor) {
|
|
96
|
+
return createEditorTransaction(editor, (instance) => instance == null ? void 0 : instance.isEmpty);
|
|
97
|
+
}
|
|
98
|
+
function useEditorIsEditable(editor) {
|
|
99
|
+
return createEditorTransaction(editor, (instance) => instance == null ? void 0 : instance.isEditable);
|
|
100
|
+
}
|
|
101
|
+
function useEditorIsFocused(editor) {
|
|
102
|
+
return createEditorTransaction(editor, (instance) => instance == null ? void 0 : instance.isFocused);
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 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,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U,SAAS;AAC1E;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +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,51 +1,12 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
|
|
21
1
|
// src/Editor.tsx
|
|
22
2
|
import {
|
|
23
3
|
createEffect,
|
|
24
4
|
createSignal,
|
|
25
|
-
on,
|
|
26
5
|
onCleanup
|
|
27
6
|
} from "solid-js";
|
|
28
7
|
import {
|
|
29
8
|
Editor
|
|
30
9
|
} from "@tiptap/core";
|
|
31
|
-
var WATCHED_PROPERTIES = [
|
|
32
|
-
"autofocus",
|
|
33
|
-
"content",
|
|
34
|
-
"editable",
|
|
35
|
-
"editorProps",
|
|
36
|
-
"enableInputRules",
|
|
37
|
-
"enablePasteRules",
|
|
38
|
-
"extensions",
|
|
39
|
-
"injectCSS",
|
|
40
|
-
"parseOptions"
|
|
41
|
-
];
|
|
42
|
-
function createOptionPatch(instance, field, props) {
|
|
43
|
-
createEffect(on(() => props[field], (value) => {
|
|
44
|
-
instance.setOptions({
|
|
45
|
-
[field]: value
|
|
46
|
-
});
|
|
47
|
-
}));
|
|
48
|
-
}
|
|
49
10
|
function createEditorTransaction(instance, read) {
|
|
50
11
|
const [signal, setSignal] = createSignal([]);
|
|
51
12
|
function forceUpdate() {
|
|
@@ -68,12 +29,9 @@ function createEditorTransaction(instance, read) {
|
|
|
68
29
|
function useEditor(props) {
|
|
69
30
|
const [signal, setSignal] = createSignal();
|
|
70
31
|
createEffect(() => {
|
|
71
|
-
const instance = new Editor(
|
|
72
|
-
|
|
73
|
-
})
|
|
74
|
-
for (let i = 0, len = WATCHED_PROPERTIES.length; i < len; i += 1) {
|
|
75
|
-
createOptionPatch(instance, WATCHED_PROPERTIES[i], props);
|
|
76
|
-
}
|
|
32
|
+
const instance = new Editor({
|
|
33
|
+
...props()
|
|
34
|
+
});
|
|
77
35
|
onCleanup(() => {
|
|
78
36
|
instance.destroy();
|
|
79
37
|
});
|
|
@@ -93,9 +51,14 @@ function useEditorCharacterCount(editor) {
|
|
|
93
51
|
function useEditorIsActive(editor, ...args) {
|
|
94
52
|
return createEditorTransaction(editor, (instance) => {
|
|
95
53
|
if (args.length === 2) {
|
|
96
|
-
return instance == null ? void 0 : instance.isActive(
|
|
54
|
+
return instance == null ? void 0 : instance.isActive(
|
|
55
|
+
args[0](),
|
|
56
|
+
args[1]
|
|
57
|
+
);
|
|
97
58
|
}
|
|
98
|
-
return instance == null ? void 0 : instance.isActive(
|
|
59
|
+
return instance == null ? void 0 : instance.isActive(
|
|
60
|
+
args[0]
|
|
61
|
+
);
|
|
99
62
|
});
|
|
100
63
|
}
|
|
101
64
|
function useEditorIsEmpty(editor) {
|
|
@@ -121,4 +84,4 @@ export {
|
|
|
121
84
|
useEditorJSON,
|
|
122
85
|
useEditor as useTiptapEditor
|
|
123
86
|
};
|
|
124
|
-
//# sourceMappingURL=index.
|
|
87
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 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;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +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};
|
package/dist/types/Editor.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { Editor, EditorOptions } from '@tiptap/core';
|
|
2
|
-
export
|
|
3
|
-
export
|
|
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 { 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;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
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 useEditor, default as createEditor, default as useTiptapEditor, default as createTiptapEditor, UseEditorOptions, EditorRef, createEditorTransaction, useEditorCharacterCount, useEditorHTML, useEditorIsActive, useEditorIsEditable, useEditorIsEmpty, useEditorIsFocused, useEditorJSON, } from './Editor';
|
package/package.json
CHANGED
|
@@ -1,37 +1,17 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
2
|
+
"version": "0.5.0",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"types": "./dist/types/index.d.ts",
|
|
5
|
+
"main": "./dist/cjs/production/index.cjs",
|
|
6
|
+
"module": "./dist/esm/production/index.mjs",
|
|
6
7
|
"exports": {
|
|
7
8
|
".": {
|
|
8
9
|
"development": {
|
|
9
|
-
"require": "./dist/cjs/development/index.
|
|
10
|
-
"import": "./dist/esm/development/index.
|
|
10
|
+
"require": "./dist/cjs/development/index.cjs",
|
|
11
|
+
"import": "./dist/esm/development/index.mjs"
|
|
11
12
|
},
|
|
12
|
-
"require": "./dist/cjs/production/index.
|
|
13
|
-
"import": "./dist/esm/production/index.
|
|
14
|
-
"types": "./dist/types/index.d.ts"
|
|
15
|
-
},
|
|
16
|
-
"./dev": {
|
|
17
|
-
"production": {
|
|
18
|
-
"require": "./dist/cjs/production/index.js",
|
|
19
|
-
"import": "./dist/esm/production/index.js"
|
|
20
|
-
},
|
|
21
|
-
"require": "./dist/cjs/development/index.js",
|
|
22
|
-
"import": "./dist/esm/development/index.js",
|
|
23
|
-
"types": "./dist/types/index.d.ts"
|
|
24
|
-
},
|
|
25
|
-
"./esm": {
|
|
26
|
-
"development": "./dist/esm/development/index.js",
|
|
27
|
-
"production": "./dist/esm/production/index.js",
|
|
28
|
-
"default": "./dist/esm/production/index.js",
|
|
29
|
-
"types": "./dist/types/index.d.ts"
|
|
30
|
-
},
|
|
31
|
-
"./cjs": {
|
|
32
|
-
"development": "./dist/cjs/development/index.js",
|
|
33
|
-
"production": "./dist/cjs/production/index.js",
|
|
34
|
-
"default": "./dist/cjs/production/index.js",
|
|
13
|
+
"require": "./dist/cjs/production/index.cjs",
|
|
14
|
+
"import": "./dist/esm/production/index.mjs",
|
|
35
15
|
"types": "./dist/types/index.d.ts"
|
|
36
16
|
}
|
|
37
17
|
},
|
|
@@ -48,18 +28,20 @@
|
|
|
48
28
|
],
|
|
49
29
|
"name": "solid-tiptap",
|
|
50
30
|
"devDependencies": {
|
|
51
|
-
"@tiptap/core": "^2.0.0-beta.
|
|
52
|
-
"@
|
|
53
|
-
"
|
|
54
|
-
"eslint
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
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"
|
|
59
40
|
},
|
|
60
41
|
"peerDependencies": {
|
|
61
|
-
"@tiptap/core": "^2.0.0-beta.
|
|
62
|
-
"
|
|
42
|
+
"@tiptap/core": "^2.0.0-beta.220",
|
|
43
|
+
"@tiptap/pm": "^2.0.0-beta.220",
|
|
44
|
+
"solid-js": "^1.2"
|
|
63
45
|
},
|
|
64
46
|
"scripts": {
|
|
65
47
|
"prepublishOnly": "pridepack clean && pridepack build",
|
|
@@ -84,5 +66,8 @@
|
|
|
84
66
|
},
|
|
85
67
|
"author": "Alexis Munsayac",
|
|
86
68
|
"private": false,
|
|
87
|
-
"
|
|
69
|
+
"typesVersions": {
|
|
70
|
+
"*": {}
|
|
71
|
+
},
|
|
72
|
+
"gitHead": "834b9023575db727cfe451d664a6184d2db4cdfe"
|
|
88
73
|
}
|
package/src/Editor.tsx
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createEffect,
|
|
3
3
|
createSignal,
|
|
4
|
-
on,
|
|
5
4
|
onCleanup,
|
|
6
5
|
} from 'solid-js';
|
|
7
6
|
import {
|
|
@@ -17,30 +16,6 @@ export interface UseEditorOptions<T extends HTMLElement> extends BaseEditorOptio
|
|
|
17
16
|
element: T;
|
|
18
17
|
}
|
|
19
18
|
|
|
20
|
-
const WATCHED_PROPERTIES: (keyof BaseEditorOptions)[] = [
|
|
21
|
-
'autofocus',
|
|
22
|
-
'content',
|
|
23
|
-
'editable',
|
|
24
|
-
'editorProps',
|
|
25
|
-
'enableInputRules',
|
|
26
|
-
'enablePasteRules',
|
|
27
|
-
'extensions',
|
|
28
|
-
'injectCSS',
|
|
29
|
-
'parseOptions',
|
|
30
|
-
];
|
|
31
|
-
|
|
32
|
-
function createOptionPatch(
|
|
33
|
-
instance: Editor,
|
|
34
|
-
field: keyof BaseEditorOptions,
|
|
35
|
-
props: BaseEditorOptions,
|
|
36
|
-
): void {
|
|
37
|
-
createEffect(on(() => props[field], (value) => {
|
|
38
|
-
instance.setOptions({
|
|
39
|
-
[field]: value,
|
|
40
|
-
});
|
|
41
|
-
}));
|
|
42
|
-
}
|
|
43
|
-
|
|
44
19
|
export function createEditorTransaction<T, V extends Editor | undefined>(
|
|
45
20
|
instance: () => V,
|
|
46
21
|
read: (value: V) => T,
|
|
@@ -68,20 +43,15 @@ export function createEditorTransaction<T, V extends Editor | undefined>(
|
|
|
68
43
|
}
|
|
69
44
|
|
|
70
45
|
export default function useEditor<T extends HTMLElement>(
|
|
71
|
-
props: UseEditorOptions<T>,
|
|
46
|
+
props: () => UseEditorOptions<T>,
|
|
72
47
|
): () => Editor | undefined {
|
|
73
48
|
const [signal, setSignal] = createSignal<Editor>();
|
|
74
49
|
|
|
75
50
|
createEffect(() => {
|
|
76
51
|
const instance = new Editor({
|
|
77
|
-
...props,
|
|
78
|
-
element: props.element,
|
|
52
|
+
...props(),
|
|
79
53
|
});
|
|
80
54
|
|
|
81
|
-
for (let i = 0, len = WATCHED_PROPERTIES.length; i < len; i += 1) {
|
|
82
|
-
createOptionPatch(instance, WATCHED_PROPERTIES[i], props);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
55
|
onCleanup(() => {
|
|
86
56
|
instance.destroy();
|
|
87
57
|
});
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __defProps = Object.defineProperties;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
10
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
-
var __spreadValues = (a, b) => {
|
|
14
|
-
for (var prop in b || (b = {}))
|
|
15
|
-
if (__hasOwnProp.call(b, prop))
|
|
16
|
-
__defNormalProp(a, prop, b[prop]);
|
|
17
|
-
if (__getOwnPropSymbols)
|
|
18
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
-
if (__propIsEnum.call(b, prop))
|
|
20
|
-
__defNormalProp(a, prop, b[prop]);
|
|
21
|
-
}
|
|
22
|
-
return a;
|
|
23
|
-
};
|
|
24
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
-
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
26
|
-
var __export = (target, all) => {
|
|
27
|
-
__markAsModule(target);
|
|
28
|
-
for (var name in all)
|
|
29
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
30
|
-
};
|
|
31
|
-
var __reExport = (target, module2, desc) => {
|
|
32
|
-
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
33
|
-
for (let key of __getOwnPropNames(module2))
|
|
34
|
-
if (!__hasOwnProp.call(target, key) && key !== "default")
|
|
35
|
-
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
36
|
-
}
|
|
37
|
-
return target;
|
|
38
|
-
};
|
|
39
|
-
var __toModule = (module2) => {
|
|
40
|
-
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
// src/index.ts
|
|
44
|
-
__export(exports, {
|
|
45
|
-
createEditor: () => useEditor,
|
|
46
|
-
createEditorTransaction: () => createEditorTransaction,
|
|
47
|
-
createTiptapEditor: () => useEditor,
|
|
48
|
-
useEditor: () => useEditor,
|
|
49
|
-
useEditorCharacterCount: () => useEditorCharacterCount,
|
|
50
|
-
useEditorHTML: () => useEditorHTML,
|
|
51
|
-
useEditorIsActive: () => useEditorIsActive,
|
|
52
|
-
useEditorIsEditable: () => useEditorIsEditable,
|
|
53
|
-
useEditorIsEmpty: () => useEditorIsEmpty,
|
|
54
|
-
useEditorIsFocused: () => useEditorIsFocused,
|
|
55
|
-
useEditorJSON: () => useEditorJSON,
|
|
56
|
-
useTiptapEditor: () => useEditor
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
// src/Editor.tsx
|
|
60
|
-
var import_solid_js = __toModule(require("solid-js"));
|
|
61
|
-
var import_core = __toModule(require("@tiptap/core"));
|
|
62
|
-
var WATCHED_PROPERTIES = [
|
|
63
|
-
"autofocus",
|
|
64
|
-
"content",
|
|
65
|
-
"editable",
|
|
66
|
-
"editorProps",
|
|
67
|
-
"enableInputRules",
|
|
68
|
-
"enablePasteRules",
|
|
69
|
-
"extensions",
|
|
70
|
-
"injectCSS",
|
|
71
|
-
"parseOptions"
|
|
72
|
-
];
|
|
73
|
-
function createOptionPatch(instance, field, props) {
|
|
74
|
-
(0, import_solid_js.createEffect)((0, import_solid_js.on)(() => props[field], (value) => {
|
|
75
|
-
instance.setOptions({
|
|
76
|
-
[field]: value
|
|
77
|
-
});
|
|
78
|
-
}));
|
|
79
|
-
}
|
|
80
|
-
function createEditorTransaction(instance, read) {
|
|
81
|
-
const [signal, setSignal] = (0, import_solid_js.createSignal)([]);
|
|
82
|
-
function forceUpdate() {
|
|
83
|
-
setSignal([]);
|
|
84
|
-
}
|
|
85
|
-
(0, import_solid_js.createEffect)(() => {
|
|
86
|
-
const editor = instance();
|
|
87
|
-
if (editor) {
|
|
88
|
-
editor.on("transaction", forceUpdate);
|
|
89
|
-
(0, import_solid_js.onCleanup)(() => {
|
|
90
|
-
editor.off("transaction", forceUpdate);
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
return () => {
|
|
95
|
-
signal();
|
|
96
|
-
return read(instance());
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
function useEditor(props) {
|
|
100
|
-
const [signal, setSignal] = (0, import_solid_js.createSignal)();
|
|
101
|
-
(0, import_solid_js.createEffect)(() => {
|
|
102
|
-
const instance = new import_core.Editor(__spreadProps(__spreadValues({}, props), {
|
|
103
|
-
element: props.element
|
|
104
|
-
}));
|
|
105
|
-
for (let i = 0, len = WATCHED_PROPERTIES.length; i < len; i += 1) {
|
|
106
|
-
createOptionPatch(instance, WATCHED_PROPERTIES[i], props);
|
|
107
|
-
}
|
|
108
|
-
(0, import_solid_js.onCleanup)(() => {
|
|
109
|
-
instance.destroy();
|
|
110
|
-
});
|
|
111
|
-
setSignal(instance);
|
|
112
|
-
});
|
|
113
|
-
return signal;
|
|
114
|
-
}
|
|
115
|
-
function useEditorHTML(editor) {
|
|
116
|
-
return createEditorTransaction(editor, (instance) => instance == null ? void 0 : instance.getHTML());
|
|
117
|
-
}
|
|
118
|
-
function useEditorJSON(editor) {
|
|
119
|
-
return createEditorTransaction(editor, (instance) => instance == null ? void 0 : instance.getJSON());
|
|
120
|
-
}
|
|
121
|
-
function useEditorCharacterCount(editor) {
|
|
122
|
-
return createEditorTransaction(editor, (instance) => instance == null ? void 0 : instance.getCharacterCount());
|
|
123
|
-
}
|
|
124
|
-
function useEditorIsActive(editor, ...args) {
|
|
125
|
-
return createEditorTransaction(editor, (instance) => {
|
|
126
|
-
if (args.length === 2) {
|
|
127
|
-
return instance == null ? void 0 : instance.isActive(args[0](), args[1]);
|
|
128
|
-
}
|
|
129
|
-
return instance == null ? void 0 : instance.isActive(args[0]);
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
function useEditorIsEmpty(editor) {
|
|
133
|
-
return createEditorTransaction(editor, (instance) => instance == null ? void 0 : instance.isEmpty);
|
|
134
|
-
}
|
|
135
|
-
function useEditorIsEditable(editor) {
|
|
136
|
-
return createEditorTransaction(editor, (instance) => instance == null ? void 0 : instance.isEditable);
|
|
137
|
-
}
|
|
138
|
-
function useEditorIsFocused(editor) {
|
|
139
|
-
return createEditorTransaction(editor, (instance) => instance == null ? void 0 : instance.isFocused);
|
|
140
|
-
}
|
|
141
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
142
|
-
0 && (module.exports = {
|
|
143
|
-
createEditor,
|
|
144
|
-
createEditorTransaction,
|
|
145
|
-
createTiptapEditor,
|
|
146
|
-
useEditor,
|
|
147
|
-
useEditorCharacterCount,
|
|
148
|
-
useEditorHTML,
|
|
149
|
-
useEditorIsActive,
|
|
150
|
-
useEditorIsEditable,
|
|
151
|
-
useEditorIsEmpty,
|
|
152
|
-
useEditorIsFocused,
|
|
153
|
-
useEditorJSON,
|
|
154
|
-
useTiptapEditor
|
|
155
|
-
});
|
|
156
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 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 on,\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\nconst WATCHED_PROPERTIES: (keyof BaseEditorOptions)[] = [\n 'autofocus',\n 'content',\n 'editable',\n 'editorProps',\n 'enableInputRules',\n 'enablePasteRules',\n 'extensions',\n 'injectCSS',\n 'parseOptions',\n];\n\nfunction createOptionPatch(\n instance: Editor,\n field: keyof BaseEditorOptions,\n props: BaseEditorOptions,\n): void {\n createEffect(on(() => props[field], (value) => {\n instance.setOptions({\n [field]: value,\n });\n }));\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 element: props.element,\n });\n\n for (let i = 0, len = WATCHED_PROPERTIES.length; i < len; i += 1) {\n createOptionPatch(instance, WATCHED_PROPERTIES[i], 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;;;ACAA,sBAKO;AACP,kBAGO;AAUP,IAAM,qBAAkD;AAAA,EACtD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAGF,2BACE,UACA,OACA,OACM;AACN,oCAAa,wBAAG,MAAM,MAAM,QAAQ,CAAC,UAAU;AAC7C,aAAS,WAAW;AAAA,OACjB,QAAQ;AAAA;AAAA;AAAA;AAKR,iCACL,UACA,MACS;AACT,QAAM,CAAC,QAAQ,aAAa,kCAAa;AAEzC,yBAAuB;AACrB,cAAU;AAAA;AAGZ,oCAAa,MAAM;AACjB,UAAM,SAAS;AACf,QAAI,QAAQ;AACV,aAAO,GAAG,eAAe;AAC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OwnPropertyDescriptors,P=Object.getOwnPropertyNames,f=Object.getOwnPropertySymbols,A=Object.getPrototypeOf,p=Object.prototype.hasOwnProperty,B=Object.prototype.propertyIsEnumerable;var l=(t,e,o)=>e in t?E(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,a=(t,e)=>{for(var o in e||(e={}))p.call(e,o)&&l(t,o,e[o]);if(f)for(var o of f(e))B.call(e,o)&&l(t,o,e[o]);return t},x=(t,e)=>v(t,H(e)),O=t=>E(t,"__esModule",{value:!0});var L=(t,e)=>{O(t);for(var o in e)E(t,o,{get:e[o],enumerable:!0})},M=(t,e,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of P(e))!p.call(t,r)&&r!=="default"&&E(t,r,{get:()=>e[r],enumerable:!(o=h(e,r))||o.enumerable});return t},T=t=>M(O(E(t!=null?S(A(t)):{},"default",t&&t.__esModule&&"default"in t?{get:()=>t.default,enumerable:!0}:{value:t,enumerable:!0})),t);L(exports,{createEditor:()=>u,createEditorTransaction:()=>i,createTiptapEditor:()=>u,useEditor:()=>u,useEditorCharacterCount:()=>b,useEditorHTML:()=>c,useEditorIsActive:()=>g,useEditorIsEditable:()=>I,useEditorIsEmpty:()=>y,useEditorIsFocused:()=>C,useEditorJSON:()=>R,useTiptapEditor:()=>u});var d=T(require("solid-js")),m=T(require("@tiptap/core")),V=["autofocus","content","editable","editorProps","enableInputRules","enablePasteRules","extensions","injectCSS","parseOptions"];function U(t,e,o){(0,d.createEffect)((0,d.on)(()=>o[e],r=>{t.setOptions({[e]:r})}))}function i(t,e){let[o,r]=(0,d.createSignal)([]);function n(){r([])}return(0,d.createEffect)(()=>{let s=t();s&&(s.on("transaction",n),(0,d.onCleanup)(()=>{s.off("transaction",n)}))}),()=>(o(),e(t()))}function u(t){let[e,o]=(0,d.createSignal)();return(0,d.createEffect)(()=>{let r=new m.Editor(x(a({},t),{element:t.element}));for(let n=0,s=V.length;n<s;n+=1)U(r,V[n],t);(0,d.onCleanup)(()=>{r.destroy()}),o(r)}),e}function c(t){return i(t,e=>e==null?void 0:e.getHTML())}function R(t){return i(t,e=>e==null?void 0:e.getJSON())}function b(t){return i(t,e=>e==null?void 0:e.getCharacterCount())}function g(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 y(t){return i(t,e=>e==null?void 0:e.isEmpty)}function I(t){return i(t,e=>e==null?void 0:e.isEditable)}function C(t){return i(t,e=>e==null?void 0:e.isFocused)}0&&(module.exports={createEditor,createEditorTransaction,createTiptapEditor,useEditor,useEditorCharacterCount,useEditorHTML,useEditorIsActive,useEditorIsEditable,useEditorIsEmpty,useEditorIsFocused,useEditorJSON,useTiptapEditor});
|
|
3
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 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 on,\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\nconst WATCHED_PROPERTIES: (keyof BaseEditorOptions)[] = [\n 'autofocus',\n 'content',\n 'editable',\n 'editorProps',\n 'enableInputRules',\n 'enablePasteRules',\n 'extensions',\n 'injectCSS',\n 'parseOptions',\n];\n\nfunction createOptionPatch(\n instance: Editor,\n field: keyof BaseEditorOptions,\n props: BaseEditorOptions,\n): void {\n createEffect(on(() => props[field], (value) => {\n instance.setOptions({\n [field]: value,\n });\n }));\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 element: props.element,\n });\n\n for (let i = 0, len = WATCHED_PROPERTIES.length; i < len; i += 1) {\n createOptionPatch(instance, WATCHED_PROPERTIES[i], 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": ";s6BAAA,qSCAA,MAKO,uBACP,EAGO,2BAUD,EAAkD,CACtD,YACA,UACA,WACA,cACA,mBACA,mBACA,aACA,YACA,gBAGF,WACE,EACA,EACA,EACM,CACN,mBAAa,SAAG,IAAM,EAAM,GAAQ,AAAC,GAAU,CAC7C,EAAS,WAAW,EACjB,GAAQ,OAKR,WACL,EACA,EACS,CACT,GAAM,CAAC,EAAQ,GAAa,mBAAa,IAEzC,YAAuB,CACrB,EAAU,IAGZ,yBAAa,IAAM,CACjB,GAAM,GAAS,IACf,AAAI,GACF,GAAO,GAAG,cAAe,GACzB,gBAAU,IAAM,CACd,EAAO,IAAI,cAAe,QAKzB,IACL,KACO,EAAK,MAID,WACb,EAC0B,CAC1B,GAAM,CAAC,EAAQ,GAAa,qBAE5B,yBAAa,IAAM,CACjB,GAAM,GAAW,GAAI,UAAO,OACvB,GADuB,CAE1B,QAAS,EAAM,WAGjB,OAAS,GAAI,EAAG,EAAM,EAAmB,OAAQ,EAAI,EAAK,GAAK,EAC7D,EAAkB,EAAU,EAAmB,GAAI,GAGrD,gBAAU,IAAM,CACd,EAAS,YAGX,EAAU,KAGL,EAGF,WACL,EAC0B,CAC1B,MAAO,GAAwB,EAAQ,AAAC,GAAa,iBAAU,WAG1D,WACL,EACqB,CACrB,MAAO,GAAwB,EAAQ,AAAC,GAAa,iBAAU,WAG1D,WACL,EAC0B,CAC1B,MAAO,GAAwB,EAAQ,AAAC,GAAa,iBAAU,qBAG1D,WACL,KACG,EACwB,CAC3B,MAAO,GAAwB,EAAQ,AAAC,GAClC,EAAK,SAAW,EACX,iBAAU,SACf,EAAK,KACL,EAAK,IAGF,iBAAU,SACf,EAAK,KAKJ,WACL,EAC2B,CAC3B,MAAO,GAAwB,EAAQ,AAAC,GAAa,iBAAU,SAG1D,WACL,EAC2B,CAC3B,MAAO,GAAwB,EAAQ,AAAC,GAAa,iBAAU,YAG1D,WACL,EAC2B,CAC3B,MAAO,GAAwB,EAAQ,AAAC,GAAa,iBAAU",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/Editor.tsx"],
|
|
4
|
-
"sourcesContent": ["import {\n createEffect,\n createSignal,\n on,\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\nconst WATCHED_PROPERTIES: (keyof BaseEditorOptions)[] = [\n 'autofocus',\n 'content',\n 'editable',\n 'editorProps',\n 'enableInputRules',\n 'enablePasteRules',\n 'extensions',\n 'injectCSS',\n 'parseOptions',\n];\n\nfunction createOptionPatch(\n instance: Editor,\n field: keyof BaseEditorOptions,\n props: BaseEditorOptions,\n): void {\n createEffect(on(() => props[field], (value) => {\n instance.setOptions({\n [field]: value,\n });\n }));\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 element: props.element,\n });\n\n for (let i = 0, len = WATCHED_PROPERTIES.length; i < len; i += 1) {\n createOptionPatch(instance, WATCHED_PROPERTIES[i], 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;AAMA;AAAA;AAAA;AAaA,IAAM,qBAAkD;AAAA,EACtD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AA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,SAAO,wBAAwB,QAAQ,CAAC,aAAa,qCAAU;AAAA;AAG1D,6BACL,QAC2B;AAC3B,SAAO,wBAAwB,QAAQ,CAAC,aAAa,qCAAU;AAAA;AAG1D,4BACL,QAC2B;AAC3B,SAAO,wBAAwB,QAAQ,CAAC,aAAa,qCAAU;AAAA;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
var T=Object.defineProperty,m=Object.defineProperties;var V=Object.getOwnPropertyDescriptors;var E=Object.getOwnPropertySymbols;var c=Object.prototype.hasOwnProperty,R=Object.prototype.propertyIsEnumerable;var f=(t,e,o)=>e in t?T(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,p=(t,e)=>{for(var o in e||(e={}))c.call(e,o)&&f(t,o,e[o]);if(E)for(var o of E(e))R.call(e,o)&&f(t,o,e[o]);return t},l=(t,e)=>m(t,V(e));import{createEffect as s,createSignal as a,on as b,onCleanup as x}from"solid-js";import{Editor as g}from"@tiptap/core";var O=["autofocus","content","editable","editorProps","enableInputRules","enablePasteRules","extensions","injectCSS","parseOptions"];function y(t,e,o){s(b(()=>o[e],d=>{t.setOptions({[e]:d})}))}function r(t,e){let[o,d]=a([]);function i(){d([])}return s(()=>{let n=t();n&&(n.on("transaction",i),x(()=>{n.off("transaction",i)}))}),()=>(o(),e(t()))}function u(t){let[e,o]=a();return s(()=>{let d=new g(l(p({},t),{element:t.element}));for(let i=0,n=O.length;i<n;i+=1)y(d,O[i],t);x(()=>{d.destroy()}),o(d)}),e}function I(t){return r(t,e=>e==null?void 0:e.getHTML())}function C(t){return r(t,e=>e==null?void 0:e.getJSON())}function S(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 h(t){return r(t,e=>e==null?void 0:e.isEmpty)}function H(t){return r(t,e=>e==null?void 0:e.isEditable)}function P(t){return r(t,e=>e==null?void 0:e.isFocused)}export{u as createEditor,r as createEditorTransaction,u as createTiptapEditor,u as useEditor,S as useEditorCharacterCount,I as useEditorHTML,v as useEditorIsActive,H as useEditorIsEditable,h as useEditorIsEmpty,P as useEditorIsFocused,C as useEditorJSON,u as useTiptapEditor};
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/Editor.tsx"],
|
|
4
|
-
"sourcesContent": ["import {\n createEffect,\n createSignal,\n on,\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\nconst WATCHED_PROPERTIES: (keyof BaseEditorOptions)[] = [\n 'autofocus',\n 'content',\n 'editable',\n 'editorProps',\n 'enableInputRules',\n 'enablePasteRules',\n 'extensions',\n 'injectCSS',\n 'parseOptions',\n];\n\nfunction createOptionPatch(\n instance: Editor,\n field: keyof BaseEditorOptions,\n props: BaseEditorOptions,\n): void {\n createEffect(on(() => props[field], (value) => {\n instance.setOptions({\n [field]: value,\n });\n }));\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 element: props.element,\n });\n\n for (let i = 0, len = WATCHED_PROPERTIES.length; i < len; i += 1) {\n createOptionPatch(instance, WATCHED_PROPERTIES[i], 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": "6aAAA,iFAMA,sCAaA,GAAM,GAAkD,CACtD,YACA,UACA,WACA,cACA,mBACA,mBACA,aACA,YACA,gBAGF,WACE,EACA,EACA,EACM,CACN,EAAa,EAAG,IAAM,EAAM,GAAQ,AAAC,GAAU,CAC7C,EAAS,WAAW,EACjB,GAAQ,OAKR,WACL,EACA,EACS,CACT,GAAM,CAAC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