@prosekit/preact 0.3.5 → 0.3.7
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/dist/chunk-4VB6FIF2.js +32 -0
- package/dist/prosekit-preact-autocomplete.js +1 -1
- package/dist/prosekit-preact-block-handle.js +1 -1
- package/dist/prosekit-preact-inline-popover.js +1 -1
- package/dist/prosekit-preact-popover.js +1 -1
- package/dist/prosekit-preact-resizable.js +1 -1
- package/dist/prosekit-preact-tooltip.js +1 -1
- package/dist/prosekit-preact.js +15 -22
- package/package.json +7 -7
- package/dist/chunk-5LWA54E4.js +0 -50
@@ -0,0 +1,32 @@
|
|
1
|
+
import {
|
2
|
+
useEditorContext
|
3
|
+
} from "./chunk-V253IGNY.js";
|
4
|
+
|
5
|
+
// src/components/create-component.ts
|
6
|
+
import { createElement } from "preact";
|
7
|
+
import {
|
8
|
+
forwardRef
|
9
|
+
} from "preact/compat";
|
10
|
+
import { useLayoutEffect, useState } from "preact/hooks";
|
11
|
+
import { mergeRefs } from "react-merge-refs";
|
12
|
+
function createComponent(tagName, displayName, defaultProps) {
|
13
|
+
let propertyNames = Object.keys(defaultProps), hasEditor = Object.hasOwn(defaultProps, "editor"), Component = forwardRef((props, ref) => {
|
14
|
+
let [el, setEl] = useState(null), properties = {}, attributes = {};
|
15
|
+
for (let [name, value] of Object.entries(props))
|
16
|
+
propertyNames.includes(name) ? properties[name] = value : attributes[name === "className" ? "class" : name] = value;
|
17
|
+
let editor = useEditorContext();
|
18
|
+
return hasEditor && editor && !properties.editor && (properties.editor = editor), useLayoutEffect(() => {
|
19
|
+
if (el)
|
20
|
+
for (let [name, value] of Object.entries(properties))
|
21
|
+
value !== void 0 && (el[name] = value);
|
22
|
+
}, [el, ...propertyNames.map((name) => properties[name])]), createElement(tagName, {
|
23
|
+
...attributes,
|
24
|
+
ref: mergeRefs([ref, setEl])
|
25
|
+
});
|
26
|
+
});
|
27
|
+
return Component.displayName = displayName, Component;
|
28
|
+
}
|
29
|
+
|
30
|
+
export {
|
31
|
+
createComponent
|
32
|
+
};
|
package/dist/prosekit-preact.js
CHANGED
@@ -6,7 +6,7 @@ import {
|
|
6
6
|
// src/components/prosekit.ts
|
7
7
|
import { h } from "preact";
|
8
8
|
var ProseKit = (props) => {
|
9
|
-
|
9
|
+
let { editor, children } = props;
|
10
10
|
return h(EditorContextProvider, { value: editor, children });
|
11
11
|
};
|
12
12
|
|
@@ -20,27 +20,24 @@ import {
|
|
20
20
|
import { useEffect, useReducer } from "preact/hooks";
|
21
21
|
function useEditor(options) {
|
22
22
|
var _a;
|
23
|
-
|
24
|
-
|
25
|
-
if (!editor) {
|
23
|
+
let update = (_a = options == null ? void 0 : options.update) != null ? _a : !1, editor = useEditorContext();
|
24
|
+
if (!editor)
|
26
25
|
throw new ProseKitError(
|
27
26
|
"useEditor must be used within the ProseKit component"
|
28
27
|
);
|
29
|
-
|
30
|
-
|
31
|
-
useEffect(() => {
|
28
|
+
let forceUpdate = useForceUpdate();
|
29
|
+
return useEffect(() => {
|
32
30
|
if (update) {
|
33
|
-
|
31
|
+
let extension = union([
|
34
32
|
defineMountHandler(forceUpdate),
|
35
33
|
defineUpdateHandler(forceUpdate)
|
36
34
|
]);
|
37
35
|
return editor.use(extension);
|
38
36
|
}
|
39
|
-
}, [editor, update, forceUpdate]);
|
40
|
-
return editor;
|
37
|
+
}, [editor, update, forceUpdate]), editor;
|
41
38
|
}
|
42
39
|
function useForceUpdate() {
|
43
|
-
|
40
|
+
let [, dispatch] = useReducer((x) => x + 1, 0);
|
44
41
|
return dispatch;
|
45
42
|
}
|
46
43
|
|
@@ -51,13 +48,11 @@ import "@prosekit/core";
|
|
51
48
|
import { EditorNotFoundError } from "@prosekit/core";
|
52
49
|
import { useEffect as useEffect2 } from "preact/hooks";
|
53
50
|
function useEditorExtension(editor, extension) {
|
54
|
-
if (!editor)
|
51
|
+
if (!editor)
|
55
52
|
throw new EditorNotFoundError();
|
56
|
-
}
|
57
53
|
useEffect2(() => {
|
58
|
-
if (extension)
|
54
|
+
if (extension)
|
59
55
|
return editor.use(extension);
|
60
|
-
}
|
61
56
|
}, [editor, extension]);
|
62
57
|
}
|
63
58
|
|
@@ -65,14 +60,12 @@ function useEditorExtension(editor, extension) {
|
|
65
60
|
import { withPriority } from "@prosekit/core";
|
66
61
|
import { useMemo } from "preact/hooks";
|
67
62
|
function usePriorityExtension(extension, priority) {
|
68
|
-
return useMemo(() =>
|
69
|
-
return extension && priority ? withPriority(extension, priority) : extension;
|
70
|
-
}, [extension, priority]);
|
63
|
+
return useMemo(() => extension && priority ? withPriority(extension, priority) : extension, [extension, priority]);
|
71
64
|
}
|
72
65
|
|
73
66
|
// src/hooks/use-extension.ts
|
74
67
|
function useExtension(extension, options) {
|
75
|
-
|
68
|
+
let editorContext = useEditorContext();
|
76
69
|
useEditorExtension(
|
77
70
|
(options == null ? void 0 : options.editor) || editorContext,
|
78
71
|
usePriorityExtension(extension, options == null ? void 0 : options.priority)
|
@@ -83,7 +76,7 @@ function useExtension(extension, options) {
|
|
83
76
|
import { defineKeymap } from "@prosekit/core";
|
84
77
|
import { useMemo as useMemo2 } from "preact/hooks";
|
85
78
|
function useKeymap(keymap, options) {
|
86
|
-
|
79
|
+
let extension = useMemo2(() => defineKeymap(keymap), [keymap]);
|
87
80
|
return useExtension(extension, options);
|
88
81
|
}
|
89
82
|
|
@@ -91,7 +84,7 @@ function useKeymap(keymap, options) {
|
|
91
84
|
import { defineUpdateHandler as defineUpdateHandler2 } from "@prosekit/core";
|
92
85
|
import { useMemo as useMemo3 } from "preact/hooks";
|
93
86
|
function useStateUpdate(handler, options) {
|
94
|
-
|
87
|
+
let extension = useMemo3(
|
95
88
|
() => defineUpdateHandler2((view) => handler(view.state)),
|
96
89
|
[handler]
|
97
90
|
);
|
@@ -102,7 +95,7 @@ function useStateUpdate(handler, options) {
|
|
102
95
|
import { defineDocChangeHandler } from "@prosekit/core";
|
103
96
|
import { useMemo as useMemo4 } from "preact/hooks";
|
104
97
|
function useDocChange(handler, options) {
|
105
|
-
|
98
|
+
let extension = useMemo4(
|
106
99
|
() => defineDocChangeHandler((view) => handler(view.state.doc)),
|
107
100
|
[handler]
|
108
101
|
);
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@prosekit/preact",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.3.
|
4
|
+
"version": "0.3.7",
|
5
5
|
"private": false,
|
6
6
|
"author": {
|
7
7
|
"name": "ocavue",
|
@@ -65,10 +65,10 @@
|
|
65
65
|
"dist"
|
66
66
|
],
|
67
67
|
"dependencies": {
|
68
|
-
"
|
69
|
-
"@prosekit/
|
70
|
-
"@prosekit/
|
71
|
-
"
|
68
|
+
"react-merge-refs": "^2.1.1",
|
69
|
+
"@prosekit/core": "^0.6.0",
|
70
|
+
"@prosekit/pm": "^0.1.5",
|
71
|
+
"@prosekit/web": "^0.2.0"
|
72
72
|
},
|
73
73
|
"peerDependencies": {
|
74
74
|
"preact": ">= 10.11.0"
|
@@ -80,8 +80,8 @@
|
|
80
80
|
},
|
81
81
|
"devDependencies": {
|
82
82
|
"preact": "^10.22.0",
|
83
|
-
"tsup": "^8.0
|
84
|
-
"typescript": "^5.
|
83
|
+
"tsup": "^8.1.0",
|
84
|
+
"typescript": "^5.5.2",
|
85
85
|
"vitest": "^1.6.0",
|
86
86
|
"@prosekit/dev": "0.0.0"
|
87
87
|
},
|
package/dist/chunk-5LWA54E4.js
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
useEditorContext
|
3
|
-
} from "./chunk-V253IGNY.js";
|
4
|
-
|
5
|
-
// src/components/create-component.ts
|
6
|
-
import { createElement } from "preact";
|
7
|
-
import {
|
8
|
-
forwardRef
|
9
|
-
} from "preact/compat";
|
10
|
-
import { useLayoutEffect, useState } from "preact/hooks";
|
11
|
-
import { mergeRefs } from "react-merge-refs";
|
12
|
-
function createComponent(tagName, displayName, defaultProps) {
|
13
|
-
const propertyNames = Object.keys(defaultProps);
|
14
|
-
const hasEditor = Object.hasOwn(defaultProps, "editor");
|
15
|
-
const Component = forwardRef((props, ref) => {
|
16
|
-
const [el, setEl] = useState(null);
|
17
|
-
const properties = {};
|
18
|
-
const attributes = {};
|
19
|
-
for (const [name, value] of Object.entries(props)) {
|
20
|
-
if (propertyNames.includes(name)) {
|
21
|
-
properties[name] = value;
|
22
|
-
} else {
|
23
|
-
attributes[name === "className" ? "class" : name] = value;
|
24
|
-
}
|
25
|
-
}
|
26
|
-
const editor = useEditorContext();
|
27
|
-
if (hasEditor && editor && !properties["editor"]) {
|
28
|
-
properties["editor"] = editor;
|
29
|
-
}
|
30
|
-
useLayoutEffect(() => {
|
31
|
-
if (el) {
|
32
|
-
for (const [name, value] of Object.entries(properties)) {
|
33
|
-
if (value !== void 0) {
|
34
|
-
el[name] = value;
|
35
|
-
}
|
36
|
-
}
|
37
|
-
}
|
38
|
-
}, [el, ...propertyNames.map((name) => properties[name])]);
|
39
|
-
return createElement(tagName, {
|
40
|
-
...attributes,
|
41
|
-
ref: mergeRefs([ref, setEl])
|
42
|
-
});
|
43
|
-
});
|
44
|
-
Component.displayName = displayName;
|
45
|
-
return Component;
|
46
|
-
}
|
47
|
-
|
48
|
-
export {
|
49
|
-
createComponent
|
50
|
-
};
|