solid-tiptap 0.3.3 → 0.4.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 +20 -20
- package/README.md +7 -11
- package/dist/cjs/development/{index.js → index.cjs} +21 -61
- 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} +9 -31
- 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 +23 -40
- package/src/Editor.tsx +2 -32
- 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
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2021 Alexis Munsayac
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Alexis Munsayac
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
21
|
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -19,17 +19,13 @@ import StarterKit from '@tiptap/starter-kit';
|
|
|
19
19
|
function App() {
|
|
20
20
|
let ref!: HTMLDivElement;
|
|
21
21
|
|
|
22
|
-
const editor = createTiptapEditor({
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return [
|
|
28
|
-
StarterKit,
|
|
29
|
-
];
|
|
30
|
-
},
|
|
22
|
+
const editor = createTiptapEditor(() => ({
|
|
23
|
+
element: ref!,
|
|
24
|
+
extensions: [
|
|
25
|
+
StarterKit,
|
|
26
|
+
],
|
|
31
27
|
content: `<p>Example Text</p>`,
|
|
32
|
-
});
|
|
28
|
+
}));
|
|
33
29
|
|
|
34
30
|
return <div id="editor" ref={ref} />;
|
|
35
31
|
}
|
|
@@ -143,7 +139,7 @@ createEffect(() => {
|
|
|
143
139
|
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
140
|
|
|
145
141
|
```js
|
|
146
|
-
const editor = createTiptapEditor({ ... });
|
|
142
|
+
const editor = createTiptapEditor(() => ({ ... }));
|
|
147
143
|
|
|
148
144
|
<Show when={editor()}>
|
|
149
145
|
{(instance) => <EditorMenu editor={instance} />}
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
|
-
var __defProps = Object.defineProperties;
|
|
5
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
5
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
10
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
7
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
8
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
@@ -21,27 +17,23 @@ var __spreadValues = (a, b) => {
|
|
|
21
17
|
}
|
|
22
18
|
return a;
|
|
23
19
|
};
|
|
24
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
-
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
26
20
|
var __export = (target, all) => {
|
|
27
|
-
__markAsModule(target);
|
|
28
21
|
for (var name in all)
|
|
29
22
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
30
23
|
};
|
|
31
|
-
var
|
|
32
|
-
if (
|
|
33
|
-
for (let key of __getOwnPropNames(
|
|
34
|
-
if (!__hasOwnProp.call(
|
|
35
|
-
__defProp(
|
|
24
|
+
var __copyProps = (to, from, except, desc) => {
|
|
25
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
26
|
+
for (let key of __getOwnPropNames(from))
|
|
27
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
28
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
36
29
|
}
|
|
37
|
-
return
|
|
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);
|
|
30
|
+
return to;
|
|
41
31
|
};
|
|
32
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
42
33
|
|
|
43
34
|
// src/index.ts
|
|
44
|
-
|
|
35
|
+
var src_exports = {};
|
|
36
|
+
__export(src_exports, {
|
|
45
37
|
createEditor: () => useEditor,
|
|
46
38
|
createEditorTransaction: () => createEditorTransaction,
|
|
47
39
|
createTiptapEditor: () => useEditor,
|
|
@@ -55,28 +47,11 @@ __export(exports, {
|
|
|
55
47
|
useEditorJSON: () => useEditorJSON,
|
|
56
48
|
useTiptapEditor: () => useEditor
|
|
57
49
|
});
|
|
50
|
+
module.exports = __toCommonJS(src_exports);
|
|
58
51
|
|
|
59
52
|
// src/Editor.tsx
|
|
60
|
-
var import_solid_js =
|
|
61
|
-
var import_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
|
-
}
|
|
53
|
+
var import_solid_js = require("solid-js");
|
|
54
|
+
var import_core = require("@tiptap/core");
|
|
80
55
|
function createEditorTransaction(instance, read) {
|
|
81
56
|
const [signal, setSignal] = (0, import_solid_js.createSignal)([]);
|
|
82
57
|
function forceUpdate() {
|
|
@@ -99,12 +74,7 @@ function createEditorTransaction(instance, read) {
|
|
|
99
74
|
function useEditor(props) {
|
|
100
75
|
const [signal, setSignal] = (0, import_solid_js.createSignal)();
|
|
101
76
|
(0, import_solid_js.createEffect)(() => {
|
|
102
|
-
const instance = new import_core.Editor(
|
|
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
|
-
}
|
|
77
|
+
const instance = new import_core.Editor(__spreadValues({}, props()));
|
|
108
78
|
(0, import_solid_js.onCleanup)(() => {
|
|
109
79
|
instance.destroy();
|
|
110
80
|
});
|
|
@@ -124,9 +94,14 @@ function useEditorCharacterCount(editor) {
|
|
|
124
94
|
function useEditorIsActive(editor, ...args) {
|
|
125
95
|
return createEditorTransaction(editor, (instance) => {
|
|
126
96
|
if (args.length === 2) {
|
|
127
|
-
return instance == null ? void 0 : instance.isActive(
|
|
97
|
+
return instance == null ? void 0 : instance.isActive(
|
|
98
|
+
args[0](),
|
|
99
|
+
args[1]
|
|
100
|
+
);
|
|
128
101
|
}
|
|
129
|
-
return instance == null ? void 0 : instance.isActive(
|
|
102
|
+
return instance == null ? void 0 : instance.isActive(
|
|
103
|
+
args[0]
|
|
104
|
+
);
|
|
130
105
|
});
|
|
131
106
|
}
|
|
132
107
|
function useEditorIsEmpty(editor) {
|
|
@@ -138,19 +113,4 @@ function useEditorIsEditable(editor) {
|
|
|
138
113
|
function useEditorIsFocused(editor) {
|
|
139
114
|
return createEditorTransaction(editor, (instance) => instance == null ? void 0 : instance.isFocused);
|
|
140
115
|
}
|
|
141
|
-
|
|
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
|
|
116
|
+
//# 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,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,mBACvB,MAAM,EACV;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,GAAG;AAAA,QACR,KAAK;AAAA;AAAA,IAET;AACA,WAAO,qCAAU;AAAA,MACf,KAAK;AAAA;AAAA,EAET,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
|
+
"use strict";var E=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames,f=Object.getOwnPropertySymbols;var x=Object.prototype.hasOwnProperty,C=Object.prototype.propertyIsEnumerable;var p=(t,e,o)=>e in t?E(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,l=(t,e)=>{for(var o in e||(e={}))x.call(e,o)&&p(t,o,e[o]);if(f)for(var o of f(e))C.call(e,o)&&p(t,o,e[o]);return t};var c=(t,e)=>{for(var o in e)E(t,o,{get:e[o],enumerable:!0})},v=(t,e,o,u)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of I(e))!x.call(t,i)&&i!==o&&E(t,i,{get:()=>e[i],enumerable:!(u=y(e,i))||u.enumerable});return t};var S=t=>v(E({},"__esModule",{value:!0}),t);var H={};c(H,{createEditor:()=>n,createEditorTransaction:()=>d,createTiptapEditor:()=>n,useEditor:()=>n,useEditorCharacterCount:()=>m,useEditorHTML:()=>V,useEditorIsActive:()=>O,useEditorIsEditable:()=>R,useEditorIsEmpty:()=>g,useEditorIsFocused:()=>b,useEditorJSON:()=>T,useTiptapEditor:()=>n});module.exports=S(H);var r=require("solid-js"),a=require("@tiptap/core");function d(t,e){let[o,u]=(0,r.createSignal)([]);function i(){u([])}return(0,r.createEffect)(()=>{let s=t();s&&(s.on("transaction",i),(0,r.onCleanup)(()=>{s.off("transaction",i)}))}),()=>(o(),e(t()))}function n(t){let[e,o]=(0,r.createSignal)();return(0,r.createEffect)(()=>{let u=new a.Editor(l({},t()));(0,r.onCleanup)(()=>{u.destroy()}),o(u)}),e}function V(t){return d(t,e=>e==null?void 0:e.getHTML())}function T(t){return d(t,e=>e==null?void 0:e.getJSON())}function m(t){return d(t,e=>e==null?void 0:e.getCharacterCount())}function O(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 g(t){return d(t,e=>e==null?void 0:e.isEmpty)}function R(t){return d(t,e=>e==null?void 0:e.isEditable)}function b(t){return d(t,e=>e==null?void 0:e.isFocused)}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
2
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
3
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
4
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
@@ -16,36 +14,16 @@ var __spreadValues = (a, b) => {
|
|
|
16
14
|
}
|
|
17
15
|
return a;
|
|
18
16
|
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
17
|
|
|
21
18
|
// src/Editor.tsx
|
|
22
19
|
import {
|
|
23
20
|
createEffect,
|
|
24
21
|
createSignal,
|
|
25
|
-
on,
|
|
26
22
|
onCleanup
|
|
27
23
|
} from "solid-js";
|
|
28
24
|
import {
|
|
29
25
|
Editor
|
|
30
26
|
} 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
27
|
function createEditorTransaction(instance, read) {
|
|
50
28
|
const [signal, setSignal] = createSignal([]);
|
|
51
29
|
function forceUpdate() {
|
|
@@ -68,12 +46,7 @@ function createEditorTransaction(instance, read) {
|
|
|
68
46
|
function useEditor(props) {
|
|
69
47
|
const [signal, setSignal] = createSignal();
|
|
70
48
|
createEffect(() => {
|
|
71
|
-
const instance = new Editor(
|
|
72
|
-
element: props.element
|
|
73
|
-
}));
|
|
74
|
-
for (let i = 0, len = WATCHED_PROPERTIES.length; i < len; i += 1) {
|
|
75
|
-
createOptionPatch(instance, WATCHED_PROPERTIES[i], props);
|
|
76
|
-
}
|
|
49
|
+
const instance = new Editor(__spreadValues({}, props()));
|
|
77
50
|
onCleanup(() => {
|
|
78
51
|
instance.destroy();
|
|
79
52
|
});
|
|
@@ -93,9 +66,14 @@ function useEditorCharacterCount(editor) {
|
|
|
93
66
|
function useEditorIsActive(editor, ...args) {
|
|
94
67
|
return createEditorTransaction(editor, (instance) => {
|
|
95
68
|
if (args.length === 2) {
|
|
96
|
-
return instance == null ? void 0 : instance.isActive(
|
|
69
|
+
return instance == null ? void 0 : instance.isActive(
|
|
70
|
+
args[0](),
|
|
71
|
+
args[1]
|
|
72
|
+
);
|
|
97
73
|
}
|
|
98
|
-
return instance == null ? void 0 : instance.isActive(
|
|
74
|
+
return instance == null ? void 0 : instance.isActive(
|
|
75
|
+
args[0]
|
|
76
|
+
);
|
|
99
77
|
});
|
|
100
78
|
}
|
|
101
79
|
function useEditorIsEmpty(editor) {
|
|
@@ -121,4 +99,4 @@ export {
|
|
|
121
99
|
useEditorJSON,
|
|
122
100
|
useEditor as useTiptapEditor
|
|
123
101
|
};
|
|
124
|
-
//# sourceMappingURL=index.
|
|
102
|
+
//# 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,mBACvB,MAAM,EACV;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,GAAG;AAAA,QACR,KAAK;AAAA;AAAA,IAET;AACA,WAAO,qCAAU;AAAA,MACf,KAAK;AAAA;AAAA,EAET,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
|
+
var a=Object.defineProperty;var E=Object.getOwnPropertySymbols;var V=Object.prototype.hasOwnProperty,T=Object.prototype.propertyIsEnumerable;var s=(t,e,o)=>e in t?a(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,f=(t,e)=>{for(var o in e||(e={}))V.call(e,o)&&s(t,o,e[o]);if(E)for(var o of E(e))T.call(e,o)&&s(t,o,e[o]);return t};import{createEffect as p,createSignal as x,onCleanup as l}from"solid-js";import{Editor as m}from"@tiptap/core";function r(t,e){let[o,i]=x([]);function n(){i([])}return p(()=>{let u=t();u&&(u.on("transaction",n),l(()=>{u.off("transaction",n)}))}),()=>(o(),e(t()))}function d(t){let[e,o]=x();return p(()=>{let i=new m(f({},t()));l(()=>{i.destroy()}),o(i)}),e}function O(t){return r(t,e=>e==null?void 0:e.getHTML())}function g(t){return r(t,e=>e==null?void 0:e.getJSON())}function R(t){return r(t,e=>e==null?void 0:e.getCharacterCount())}function b(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 y(t){return r(t,e=>e==null?void 0:e.isEmpty)}function I(t){return r(t,e=>e==null?void 0:e.isEditable)}function C(t){return r(t,e=>e==null?void 0:e.isFocused)}export{d as createEditor,r as createEditorTransaction,d as createTiptapEditor,d as useEditor,R as useEditorCharacterCount,O as useEditorHTML,b as useEditorIsActive,I as useEditorIsEditable,y as useEditorIsEmpty,C as useEditorIsFocused,g 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 declare type EditorRef = Editor | ((editor: Editor) => void);
|
|
3
|
-
export declare 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 { Editor, EditorOptions } from '@tiptap/core';
|
|
2
|
+
export declare type EditorRef = Editor | ((editor: Editor) => void);
|
|
3
|
+
export declare 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.4.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,18 @@
|
|
|
48
28
|
],
|
|
49
29
|
"name": "solid-tiptap",
|
|
50
30
|
"devDependencies": {
|
|
51
|
-
"@tiptap/core": "^2.0.0-beta.
|
|
52
|
-
"@types/node": "^
|
|
53
|
-
"eslint": "^
|
|
54
|
-
"eslint-config-lxsmnsyc": "^0.
|
|
55
|
-
"pridepack": "^
|
|
56
|
-
"solid-js": "^1.
|
|
57
|
-
"tslib": "^2.
|
|
58
|
-
"typescript": "^4.
|
|
31
|
+
"@tiptap/core": "^2.0.0-beta.199",
|
|
32
|
+
"@types/node": "^18.8.5",
|
|
33
|
+
"eslint": "^8.25.0",
|
|
34
|
+
"eslint-config-lxsmnsyc": "^0.4.8",
|
|
35
|
+
"pridepack": "^2.3.0",
|
|
36
|
+
"solid-js": "^1.5.7",
|
|
37
|
+
"tslib": "^2.4.0",
|
|
38
|
+
"typescript": "^4.8.4"
|
|
59
39
|
},
|
|
60
40
|
"peerDependencies": {
|
|
61
|
-
"@tiptap/core": "^2.0.0-beta.
|
|
62
|
-
"solid-js": "^1.2
|
|
41
|
+
"@tiptap/core": "^2.0.0-beta.199",
|
|
42
|
+
"solid-js": "^1.2"
|
|
63
43
|
},
|
|
64
44
|
"scripts": {
|
|
65
45
|
"prepublishOnly": "pridepack clean && pridepack build",
|
|
@@ -84,5 +64,8 @@
|
|
|
84
64
|
},
|
|
85
65
|
"author": "Alexis Munsayac",
|
|
86
66
|
"private": false,
|
|
87
|
-
"
|
|
67
|
+
"typesVersions": {
|
|
68
|
+
"*": {}
|
|
69
|
+
},
|
|
70
|
+
"gitHead": "2441d77ae2cc4fb448f5e6961f2656b23035f119"
|
|
88
71
|
}
|
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,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;AACzB,qCAAU,MAAM;AACd,eAAO,IAAI,eAAe;AAAA;AAAA;AAAA;AAKhC,SAAO,MAAM;AACX;AACA,WAAO,KAAK;AAAA;AAAA;AAID,mBACb,OAC0B;AAC1B,QAAM,CAAC,QAAQ,aAAa;AAE5B,oCAAa,MAAM;AACjB,UAAM,WAAW,IAAI,mBAAO,iCACvB,QADuB;AAAA,MAE1B,SAAS,MAAM;AAAA;AAGjB,aAAS,IAAI,GAAG,MAAM,mBAAmB,QAAQ,IAAI,KAAK,KAAK,GAAG;AAChE,wBAAkB,UAAU,mBAAmB,IAAI;AAAA;AAGrD,mCAAU,MAAM;AACd,eAAS;AAAA;AAGX,cAAU;AAAA;AAGZ,SAAO;AAAA;AAGF,uBACL,QAC0B;AAC1B,SAAO,wBAAwB,QAAQ,CAAC,aAAa,qCAAU;AAAA;AAG1D,uBACL,QACqB;AACrB,SAAO,wBAAwB,QAAQ,CAAC,aAAa,qCAAU;AAAA;AAG1D,iCACL,QAC0B;AAC1B,SAAO,wBAAwB,QAAQ,CAAC,aAAa,qCAAU;AAAA;AAG1D,2BACL,WACG,MACwB;AAC3B,SAAO,wBAAwB,QAAQ,CAAC,aAAa;AACnD,QAAI,KAAK,WAAW,GAAG;AACrB,aAAO,qCAAU,SACf,KAAK,MACL,KAAK;AAAA;AAGT,WAAO,qCAAU,SACf,KAAK;AAAA;AAAA;AAKJ,0BACL,QAC2B;AAC3B,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,3 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var S=Object.create;var E=Object.defineProperty,v=Object.defineProperties,h=Object.getOwnPropertyDescriptor,H=Object.getOwnPropertyDescriptors,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;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAGF,2BACE,UACA,OACA,OACM;AACN,eAAa,GAAG,MAAM,MAAM,QAAQ,CAAC,UAAU;AAC7C,aAAS,WAAW;AAAA,OACjB,QAAQ;AAAA;AAAA;AAAA;AAKR,iCACL,UACA,MACS;AACT,QAAM,CAAC,QAAQ,aAAa,aAAa;AAEzC,yBAAuB;AACrB,cAAU;AAAA;AAGZ,eAAa,MAAM;AACjB,UAAM,SAAS;AACf,QAAI,QAAQ;AACV,aAAO,GAAG,eAAe;AACzB,gBAAU,MAAM;AACd,eAAO,IAAI,eAAe;AAAA;AAAA;AAAA;AAKhC,SAAO,MAAM;AACX;AACA,WAAO,KAAK;AAAA;AAAA;AAID,mBACb,OAC0B;AAC1B,QAAM,CAAC,QAAQ,aAAa;AAE5B,eAAa,MAAM;AACjB,UAAM,WAAW,IAAI,OAAO,iCACvB,QADuB;AAAA,MAE1B,SAAS,MAAM;AAAA;AAGjB,aAAS,IAAI,GAAG,MAAM,mBAAmB,QAAQ,IAAI,KAAK,KAAK,GAAG;AAChE,wBAAkB,UAAU,mBAAmB,IAAI;AAAA;AAGrD,cAAU,MAAM;AACd,eAAS;AAAA;AAGX,cAAU;AAAA;AAGZ,SAAO;AAAA;AAGF,uBACL,QAC0B;AAC1B,SAAO,wBAAwB,QAAQ,CAAC,aAAa,qCAAU;AAAA;AAG1D,uBACL,QACqB;AACrB,SAAO,wBAAwB,QAAQ,CAAC,aAAa,qCAAU;AAAA;AAG1D,iCACL,QAC0B;AAC1B,SAAO,wBAAwB,QAAQ,CAAC,aAAa,qCAAU;AAAA;AAG1D,2BACL,WACG,MACwB;AAC3B,SAAO,wBAAwB,QAAQ,CAAC,aAAa;AACnD,QAAI,KAAK,WAAW,GAAG;AACrB,aAAO,qCAAU,SACf,KAAK,MACL,KAAK;AAAA;AAGT,WAAO,qCAAU,SACf,KAAK;AAAA;AAAA;AAKJ,0BACL,QAC2B;AAC3B,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,EAAQ,GAAa,EAAa,IAEzC,YAAuB,CACrB,EAAU,IAGZ,SAAa,IAAM,CACjB,GAAM,GAAS,IACf,AAAI,GACF,GAAO,GAAG,cAAe,GACzB,EAAU,IAAM,CACd,EAAO,IAAI,cAAe,QAKzB,IACL,KACO,EAAK,MAID,WACb,EAC0B,CAC1B,GAAM,CAAC,EAAQ,GAAa,IAE5B,SAAa,IAAM,CACjB,GAAM,GAAW,GAAI,GAAO,OACvB,GADuB,CAE1B,QAAS,EAAM,WAGjB,OAAS,GAAI,EAAG,EAAM,EAAmB,OAAQ,EAAI,EAAK,GAAK,EAC7D,EAAkB,EAAU,EAAmB,GAAI,GAGrD,EAAU,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
|
-
}
|