@prosekit/preact 0.6.6 → 0.6.8
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/{create-component-_3OMD_6h.js → create-component.js} +3 -5
- package/dist/create-component.js.map +1 -0
- package/dist/{create-props-PUVFMh9y.d.ts → create-props.d.ts} +1 -1
- package/dist/create-props.d.ts.map +1 -0
- package/dist/{editor-context-DJZHNwgB.js → editor-context.js} +2 -3
- package/dist/editor-context.js.map +1 -0
- package/dist/prosekit-preact-autocomplete.d.ts +1 -1
- package/dist/prosekit-preact-autocomplete.js +2 -6
- package/dist/prosekit-preact-autocomplete.js.map +1 -1
- package/dist/prosekit-preact-block-handle.d.ts +1 -1
- package/dist/prosekit-preact-block-handle.js +2 -5
- package/dist/prosekit-preact-block-handle.js.map +1 -1
- package/dist/prosekit-preact-drop-indicator.d.ts +1 -1
- package/dist/prosekit-preact-drop-indicator.js +2 -3
- package/dist/prosekit-preact-drop-indicator.js.map +1 -1
- package/dist/prosekit-preact-inline-popover.d.ts +1 -1
- package/dist/prosekit-preact-inline-popover.js +2 -3
- package/dist/prosekit-preact-inline-popover.js.map +1 -1
- package/dist/prosekit-preact-popover.d.ts +1 -1
- package/dist/prosekit-preact-popover.js +2 -5
- package/dist/prosekit-preact-popover.js.map +1 -1
- package/dist/prosekit-preact-resizable.d.ts +1 -1
- package/dist/prosekit-preact-resizable.js +2 -4
- package/dist/prosekit-preact-resizable.js.map +1 -1
- package/dist/prosekit-preact-table-handle.d.ts +1 -1
- package/dist/prosekit-preact-table-handle.js +2 -11
- package/dist/prosekit-preact-table-handle.js.map +1 -1
- package/dist/prosekit-preact-tooltip.d.ts +1 -1
- package/dist/prosekit-preact-tooltip.js +2 -5
- package/dist/prosekit-preact-tooltip.js.map +1 -1
- package/dist/prosekit-preact.d.ts +17 -17
- package/dist/prosekit-preact.d.ts.map +1 -1
- package/dist/prosekit-preact.js +109 -119
- package/dist/prosekit-preact.js.map +1 -1
- package/package.json +8 -7
- package/src/components/autocomplete/autocomplete-empty.gen.ts +4 -4
- package/src/components/autocomplete/autocomplete-item.gen.ts +4 -4
- package/src/components/autocomplete/autocomplete-list.gen.ts +4 -4
- package/src/components/autocomplete/autocomplete-popover.gen.ts +4 -4
- package/src/components/autocomplete/index.gen.ts +4 -4
- package/src/components/block-handle/block-handle-add.gen.ts +4 -4
- package/src/components/block-handle/block-handle-draggable.gen.ts +4 -4
- package/src/components/block-handle/block-handle-popover.gen.ts +4 -4
- package/src/components/block-handle/index.gen.ts +3 -3
- package/src/components/create-component.ts +2 -3
- package/src/components/drop-indicator/drop-indicator.gen.ts +4 -4
- package/src/components/drop-indicator/index.gen.ts +1 -1
- package/src/components/inline-popover/index.gen.ts +1 -1
- package/src/components/inline-popover/inline-popover.gen.ts +4 -4
- package/src/components/popover/index.gen.ts +3 -3
- package/src/components/popover/popover-content.gen.ts +4 -4
- package/src/components/popover/popover-root.gen.ts +4 -4
- package/src/components/popover/popover-trigger.gen.ts +4 -4
- package/src/components/prosekit.ts +8 -12
- package/src/components/resizable/index.gen.ts +2 -2
- package/src/components/resizable/resizable-handle.gen.ts +4 -4
- package/src/components/resizable/resizable-root.gen.ts +4 -4
- package/src/components/table-handle/index.gen.ts +9 -9
- package/src/components/table-handle/table-handle-column-root.gen.ts +4 -4
- package/src/components/table-handle/table-handle-column-trigger.gen.ts +4 -4
- package/src/components/table-handle/table-handle-drag-preview.gen.ts +4 -4
- package/src/components/table-handle/table-handle-drop-indicator.gen.ts +4 -4
- package/src/components/table-handle/table-handle-popover-content.gen.ts +4 -4
- package/src/components/table-handle/table-handle-popover-item.gen.ts +4 -4
- package/src/components/table-handle/table-handle-root.gen.ts +4 -4
- package/src/components/table-handle/table-handle-row-root.gen.ts +4 -4
- package/src/components/table-handle/table-handle-row-trigger.gen.ts +4 -4
- package/src/components/tooltip/index.gen.ts +3 -3
- package/src/components/tooltip/tooltip-content.gen.ts +4 -4
- package/src/components/tooltip/tooltip-root.gen.ts +4 -4
- package/src/components/tooltip/tooltip-trigger.gen.ts +4 -4
- package/src/components/view-renderer.ts +28 -0
- package/src/extensions/preact-mark-view.ts +28 -38
- package/src/extensions/preact-node-view.ts +28 -38
- package/src/hooks/use-doc-change.ts +2 -2
- package/src/hooks/use-editor-derived-value.ts +1 -1
- package/src/hooks/use-editor.ts +1 -1
- package/src/hooks/use-extension.ts +3 -3
- package/src/hooks/use-keymap.ts +1 -1
- package/src/hooks/use-state-update.ts +2 -2
- package/src/index.ts +10 -10
- package/dist/create-component-_3OMD_6h.js.map +0 -1
- package/dist/create-props-PUVFMh9y.d.ts.map +0 -1
- package/dist/editor-context-DJZHNwgB.js.map +0 -1
package/dist/prosekit-preact.js
CHANGED
|
@@ -1,119 +1,93 @@
|
|
|
1
|
-
import { n as useEditorContext, t as EditorContextProvider } from "./editor-context
|
|
2
|
-
import {
|
|
3
|
-
import { h } from "preact";
|
|
1
|
+
import { n as useEditorContext, t as EditorContextProvider } from "./editor-context.js";
|
|
2
|
+
import { Fragment, createElement } from "preact";
|
|
4
3
|
import { useCallback, useEffect, useLayoutEffect, useMemo, useReducer, useRef } from "preact/hooks";
|
|
5
4
|
import { EditorNotFoundError, ProseKitError, defineDocChangeHandler, defineKeymap, defineMarkViewComponent, defineMarkViewFactory, defineMountHandler, defineNodeViewComponent, defineNodeViewFactory, defineUpdateHandler, union, withPriority } from "@prosekit/core";
|
|
5
|
+
import { AbstractPreactMarkView, AbstractPreactNodeView, buildPreactMarkViewCreator, buildPreactNodeViewCreator, usePreactRenderer } from "@prosemirror-adapter/preact";
|
|
6
|
+
import { createPortal, useSyncExternalStore } from "preact/compat";
|
|
6
7
|
import { queueExtension } from "@prosekit/web";
|
|
7
|
-
import { useSyncExternalStore } from "preact/compat";
|
|
8
|
-
|
|
9
|
-
//#region src/hooks/use-editor-extension.ts
|
|
10
|
-
/**
|
|
11
|
-
* @internal
|
|
12
|
-
*/
|
|
13
|
-
function useEditorExtension(editor, extension) {
|
|
14
|
-
if (!editor) throw new EditorNotFoundError();
|
|
15
|
-
useEffect(() => {
|
|
16
|
-
if (extension) return queueExtension(editor, extension);
|
|
17
|
-
}, [editor, extension]);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
//#endregion
|
|
21
|
-
//#region src/hooks/use-priority-extension.ts
|
|
22
|
-
/**
|
|
23
|
-
* @internal
|
|
24
|
-
*/
|
|
25
|
-
function usePriorityExtension(extension, priority) {
|
|
26
|
-
return useMemo(() => {
|
|
27
|
-
return extension && priority ? withPriority(extension, priority) : extension;
|
|
28
|
-
}, [extension, priority]);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
//#endregion
|
|
32
|
-
//#region src/hooks/use-extension.ts
|
|
33
|
-
/**
|
|
34
|
-
* Add an extension to the editor.
|
|
35
|
-
*/
|
|
36
|
-
function useExtension(extension, options) {
|
|
37
|
-
const editorContext = useEditorContext();
|
|
38
|
-
useEditorExtension(options?.editor || editorContext, usePriorityExtension(extension, options?.priority));
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
//#endregion
|
|
42
8
|
//#region src/extensions/preact-mark-view.ts
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
9
|
+
var ProseKitPreactMarkView = class extends AbstractPreactMarkView {
|
|
10
|
+
constructor(..._args) {
|
|
11
|
+
super(..._args);
|
|
12
|
+
this.render = () => {
|
|
13
|
+
const UserComponent = this.component;
|
|
14
|
+
return createPortal(createElement(UserComponent, { ...this.context }), this.dom);
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
};
|
|
48
18
|
/**
|
|
49
19
|
* @internal
|
|
50
20
|
*/
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
};
|
|
21
|
+
function definePreactMarkViewFactory(renderPreactRenderer, removePreactRenderer) {
|
|
22
|
+
return defineMarkViewFactory({
|
|
23
|
+
group: "preact",
|
|
24
|
+
factory: buildPreactMarkViewCreator(renderPreactRenderer, removePreactRenderer, ProseKitPreactMarkView)
|
|
25
|
+
});
|
|
26
|
+
}
|
|
56
27
|
/**
|
|
57
28
|
* Defines a mark view using a Preact component.
|
|
58
29
|
*
|
|
59
30
|
* @public
|
|
60
31
|
*/
|
|
61
32
|
function definePreactMarkView(options) {
|
|
62
|
-
const { name, component, ...userOptions } = options;
|
|
63
33
|
return defineMarkViewComponent({
|
|
64
34
|
group: "preact",
|
|
65
|
-
name,
|
|
66
|
-
args:
|
|
67
|
-
...userOptions,
|
|
68
|
-
component: withMarkViewProps(component)
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
function definePreactMarkViewFactory(factory) {
|
|
73
|
-
return defineMarkViewFactory({
|
|
74
|
-
group: "preact",
|
|
75
|
-
factory
|
|
35
|
+
name: options.name,
|
|
36
|
+
args: options
|
|
76
37
|
});
|
|
77
38
|
}
|
|
78
|
-
|
|
79
39
|
//#endregion
|
|
80
40
|
//#region src/extensions/preact-node-view.ts
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
41
|
+
var ProseKitPreactNodeView = class extends AbstractPreactNodeView {
|
|
42
|
+
constructor(..._args) {
|
|
43
|
+
super(..._args);
|
|
44
|
+
this.render = () => {
|
|
45
|
+
const UserComponent = this.component;
|
|
46
|
+
return createPortal(createElement(UserComponent, { ...this.context }), this.dom);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
};
|
|
86
50
|
/**
|
|
87
51
|
* @internal
|
|
88
52
|
*/
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
};
|
|
53
|
+
function definePreactNodeViewFactory(renderPreactRenderer, removePreactRenderer) {
|
|
54
|
+
return defineNodeViewFactory({
|
|
55
|
+
group: "preact",
|
|
56
|
+
factory: buildPreactNodeViewCreator(renderPreactRenderer, removePreactRenderer, ProseKitPreactNodeView)
|
|
57
|
+
});
|
|
58
|
+
}
|
|
94
59
|
/**
|
|
95
60
|
* Defines a node view using a Preact component.
|
|
96
61
|
*
|
|
97
62
|
* @public
|
|
98
63
|
*/
|
|
99
64
|
function definePreactNodeView(options) {
|
|
100
|
-
const { name, component, ...userOptions } = options;
|
|
101
65
|
return defineNodeViewComponent({
|
|
102
66
|
group: "preact",
|
|
103
|
-
name,
|
|
104
|
-
args:
|
|
105
|
-
...userOptions,
|
|
106
|
-
component: withNodeViewProps(component)
|
|
107
|
-
}
|
|
67
|
+
name: options.name,
|
|
68
|
+
args: options
|
|
108
69
|
});
|
|
109
70
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/hooks/use-editor-extension.ts
|
|
73
|
+
/**
|
|
74
|
+
* @internal
|
|
75
|
+
*/
|
|
76
|
+
function useEditorExtension(editor, extension) {
|
|
77
|
+
if (!editor) throw new EditorNotFoundError();
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
if (extension) return queueExtension(editor, extension);
|
|
80
|
+
}, [editor, extension]);
|
|
115
81
|
}
|
|
116
|
-
|
|
82
|
+
//#endregion
|
|
83
|
+
//#region src/components/view-renderer.ts
|
|
84
|
+
const ViewRenderer = ({ editor, children }) => {
|
|
85
|
+
const { renderPreactRenderer, removePreactRenderer, render } = usePreactRenderer();
|
|
86
|
+
useEditorExtension(editor, useMemo(() => {
|
|
87
|
+
return union([definePreactMarkViewFactory(renderPreactRenderer, removePreactRenderer), definePreactNodeViewFactory(renderPreactRenderer, removePreactRenderer)]);
|
|
88
|
+
}, [renderPreactRenderer, removePreactRenderer]));
|
|
89
|
+
return createElement(Fragment, null, createElement(Fragment, null, children), createElement(Fragment, null, render()));
|
|
90
|
+
};
|
|
117
91
|
//#endregion
|
|
118
92
|
//#region src/components/prosekit.ts
|
|
119
93
|
/**
|
|
@@ -123,9 +97,11 @@ function definePreactNodeViewFactory(factory) {
|
|
|
123
97
|
*/
|
|
124
98
|
const ProseKit = (props) => {
|
|
125
99
|
const { editor, children } = props;
|
|
126
|
-
return
|
|
100
|
+
return createElement(EditorContextProvider, { value: editor }, createElement(ViewRenderer, {
|
|
101
|
+
editor,
|
|
102
|
+
children
|
|
103
|
+
}));
|
|
127
104
|
};
|
|
128
|
-
|
|
129
105
|
//#endregion
|
|
130
106
|
//#region src/hooks/use-event-callback.ts
|
|
131
107
|
/**
|
|
@@ -138,7 +114,25 @@ function useEventCallback(callback) {
|
|
|
138
114
|
}, [callback]);
|
|
139
115
|
return useCallback((...args) => callbackRef.current(...args), []);
|
|
140
116
|
}
|
|
141
|
-
|
|
117
|
+
//#endregion
|
|
118
|
+
//#region src/hooks/use-priority-extension.ts
|
|
119
|
+
/**
|
|
120
|
+
* @internal
|
|
121
|
+
*/
|
|
122
|
+
function usePriorityExtension(extension, priority) {
|
|
123
|
+
return useMemo(() => {
|
|
124
|
+
return extension && priority ? withPriority(extension, priority) : extension;
|
|
125
|
+
}, [extension, priority]);
|
|
126
|
+
}
|
|
127
|
+
//#endregion
|
|
128
|
+
//#region src/hooks/use-extension.ts
|
|
129
|
+
/**
|
|
130
|
+
* Add an extension to the editor.
|
|
131
|
+
*/
|
|
132
|
+
function useExtension(extension, options) {
|
|
133
|
+
const editorContext = useEditorContext();
|
|
134
|
+
useEditorExtension(options?.editor || editorContext, usePriorityExtension(extension, options?.priority));
|
|
135
|
+
}
|
|
142
136
|
//#endregion
|
|
143
137
|
//#region src/hooks/use-doc-change.ts
|
|
144
138
|
/**
|
|
@@ -150,36 +144,6 @@ function useDocChange(handler, options) {
|
|
|
150
144
|
const memoizedHandler = useEventCallback(handler);
|
|
151
145
|
useExtension(useMemo(() => defineDocChangeHandler((view) => memoizedHandler(view.state.doc)), [memoizedHandler]), options);
|
|
152
146
|
}
|
|
153
|
-
|
|
154
|
-
//#endregion
|
|
155
|
-
//#region src/hooks/use-editor.ts
|
|
156
|
-
/**
|
|
157
|
-
* Retrieves the editor instance from the nearest ProseKit component.
|
|
158
|
-
*
|
|
159
|
-
* @public
|
|
160
|
-
*/
|
|
161
|
-
function useEditor(options) {
|
|
162
|
-
const update = options?.update ?? false;
|
|
163
|
-
const editor = useEditorContext();
|
|
164
|
-
if (!editor) throw new ProseKitError("useEditor must be used within the ProseKit component");
|
|
165
|
-
const forceUpdate = useForceUpdate();
|
|
166
|
-
useEffect(() => {
|
|
167
|
-
if (update) {
|
|
168
|
-
const extension = union(defineMountHandler(forceUpdate), defineUpdateHandler(forceUpdate));
|
|
169
|
-
return editor.use(extension);
|
|
170
|
-
}
|
|
171
|
-
}, [
|
|
172
|
-
editor,
|
|
173
|
-
update,
|
|
174
|
-
forceUpdate
|
|
175
|
-
]);
|
|
176
|
-
return editor;
|
|
177
|
-
}
|
|
178
|
-
function useForceUpdate() {
|
|
179
|
-
const [, dispatch] = useReducer((x) => x + 1, 0);
|
|
180
|
-
return dispatch;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
147
|
//#endregion
|
|
184
148
|
//#region src/hooks/use-editor-derived-value.ts
|
|
185
149
|
/**
|
|
@@ -222,13 +186,39 @@ function createEditorStore(editor, derive) {
|
|
|
222
186
|
};
|
|
223
187
|
return [subscribe, getSnapshot];
|
|
224
188
|
}
|
|
225
|
-
|
|
189
|
+
//#endregion
|
|
190
|
+
//#region src/hooks/use-editor.ts
|
|
191
|
+
/**
|
|
192
|
+
* Retrieves the editor instance from the nearest ProseKit component.
|
|
193
|
+
*
|
|
194
|
+
* @public
|
|
195
|
+
*/
|
|
196
|
+
function useEditor(options) {
|
|
197
|
+
const update = options?.update ?? false;
|
|
198
|
+
const editor = useEditorContext();
|
|
199
|
+
if (!editor) throw new ProseKitError("useEditor must be used within the ProseKit component");
|
|
200
|
+
const forceUpdate = useForceUpdate();
|
|
201
|
+
useEffect(() => {
|
|
202
|
+
if (update) {
|
|
203
|
+
const extension = union(defineMountHandler(forceUpdate), defineUpdateHandler(forceUpdate));
|
|
204
|
+
return editor.use(extension);
|
|
205
|
+
}
|
|
206
|
+
}, [
|
|
207
|
+
editor,
|
|
208
|
+
update,
|
|
209
|
+
forceUpdate
|
|
210
|
+
]);
|
|
211
|
+
return editor;
|
|
212
|
+
}
|
|
213
|
+
function useForceUpdate() {
|
|
214
|
+
const [, dispatch] = useReducer((x) => x + 1, 0);
|
|
215
|
+
return dispatch;
|
|
216
|
+
}
|
|
226
217
|
//#endregion
|
|
227
218
|
//#region src/hooks/use-keymap.ts
|
|
228
219
|
function useKeymap(keymap, options) {
|
|
229
220
|
useExtension(useMemo(() => defineKeymap(keymap), [keymap]), options);
|
|
230
221
|
}
|
|
231
|
-
|
|
232
222
|
//#endregion
|
|
233
223
|
//#region src/hooks/use-state-update.ts
|
|
234
224
|
/**
|
|
@@ -240,7 +230,7 @@ function useStateUpdate(handler, options) {
|
|
|
240
230
|
const memoizedHandler = useEventCallback(handler);
|
|
241
231
|
useExtension(useMemo(() => defineUpdateHandler((view) => memoizedHandler(view.state)), [memoizedHandler]), options);
|
|
242
232
|
}
|
|
243
|
-
|
|
244
233
|
//#endregion
|
|
245
234
|
export { ProseKit, definePreactMarkView, definePreactNodeView, useDocChange, useEditor, useEditorDerivedValue, useExtension, useKeymap, useStateUpdate };
|
|
235
|
+
|
|
246
236
|
//# sourceMappingURL=prosekit-preact.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prosekit-preact.js","names":[],"sources":["../src/hooks/use-editor-extension.ts","../src/hooks/use-priority-extension.ts","../src/hooks/use-extension.ts","../src/extensions/preact-mark-view.ts","../src/extensions/preact-node-view.ts","../src/components/prosekit.ts","../src/hooks/use-event-callback.ts","../src/hooks/use-doc-change.ts","../src/hooks/use-editor.ts","../src/hooks/use-editor-derived-value.ts","../src/hooks/use-keymap.ts","../src/hooks/use-state-update.ts"],"sourcesContent":["import { EditorNotFoundError, type Editor, type Extension } from '@prosekit/core'\nimport { queueExtension } from '@prosekit/web'\nimport { useEffect } from 'preact/hooks'\n\n/**\n * @internal\n */\nexport function useEditorExtension(\n editor: Editor | null | undefined,\n extension: Extension | null,\n): void {\n if (!editor) {\n throw new EditorNotFoundError()\n }\n\n useEffect(() => {\n if (extension) {\n return queueExtension(editor, extension)\n }\n }, [editor, extension])\n}\n","import { withPriority, type Extension, type Priority } from '@prosekit/core'\nimport { useMemo } from 'preact/hooks'\n\n/**\n * @internal\n */\nexport function usePriorityExtension<T extends Extension = Extension>(\n extension: T | null,\n priority?: Priority | null,\n): T | null {\n return useMemo(() => {\n return extension && priority ? withPriority(extension, priority) : extension\n }, [extension, priority])\n}\n","import type { Editor, Extension, Priority } from '@prosekit/core'\n\nimport { useEditorContext } from '../contexts/editor-context'\n\nimport { useEditorExtension } from './use-editor-extension'\nimport { usePriorityExtension } from './use-priority-extension'\n\nexport interface UseExtensionOptions {\n /**\n * The editor to add the extension to. If not provided, it will use the\n * editor from the nearest `<ProseKit>` component.\n */\n editor?: Editor\n\n /**\n * Optional priority to add the extension with.\n */\n priority?: Priority\n}\n\n/**\n * Add an extension to the editor.\n */\nexport function useExtension(\n /**\n * The extension to add to the editor. If it changes, the previous\n * extension will be removed and the new one (if not null) will be added.\n */\n extension: Extension | null,\n options?: UseExtensionOptions,\n): void {\n const editorContext = useEditorContext()\n useEditorExtension(\n options?.editor || editorContext,\n usePriorityExtension(extension, options?.priority),\n )\n}\n","import { defineMarkViewComponent, defineMarkViewFactory, type Extension } from '@prosekit/core'\nimport type { MarkViewConstructor } from '@prosekit/pm/view'\nimport type { CoreMarkViewUserOptions } from '@prosemirror-adapter/core'\nimport { useMarkViewContext, useMarkViewFactory, type MarkViewContext, type PreactMarkViewUserOptions } from '@prosemirror-adapter/preact'\nimport { h, type ComponentType, type FunctionComponent } from 'preact'\nimport { useMemo } from 'preact/hooks'\n\nimport { useExtension } from '../hooks/use-extension'\n\n/**\n * @public\n */\nexport interface PreactMarkViewProps extends MarkViewContext {}\n\n/**\n * @public\n */\nexport type PreactMarkViewComponent = ComponentType<PreactMarkViewProps>\n\n/**\n * Options for {@link definePreactMarkView}.\n *\n * @public\n */\nexport interface PreactMarkViewOptions extends CoreMarkViewUserOptions<PreactMarkViewComponent> {\n /**\n * The name of the mark type.\n */\n name: string\n}\n\nfunction withMarkViewProps(component: PreactMarkViewComponent) {\n return function MarkViewPropsWrapper() {\n const props: PreactMarkViewProps = useMarkViewContext()\n return h(component, props)\n }\n}\n\n/**\n * @internal\n */\nexport const PreactMarkViewConsumer: FunctionComponent = () => {\n const markViewFactory = useMarkViewFactory()\n const extension = useMemo(\n () => definePreactMarkViewFactory(markViewFactory),\n [markViewFactory],\n )\n useExtension(extension)\n\n return null\n}\n\n/**\n * Defines a mark view using a Preact component.\n *\n * @public\n */\nexport function definePreactMarkView(options: PreactMarkViewOptions): Extension {\n const { name, component, ...userOptions } = options\n\n const args: PreactMarkViewUserOptions = {\n ...userOptions,\n component: withMarkViewProps(component),\n }\n\n return defineMarkViewComponent<PreactMarkViewUserOptions>({\n group: 'preact',\n name,\n args,\n })\n}\n\nfunction definePreactMarkViewFactory(\n factory: (options: PreactMarkViewUserOptions) => MarkViewConstructor,\n) {\n return defineMarkViewFactory<PreactMarkViewUserOptions>({\n group: 'preact',\n factory,\n })\n}\n","import { defineNodeViewComponent, defineNodeViewFactory, type Extension } from '@prosekit/core'\nimport type { NodeViewConstructor } from '@prosekit/pm/view'\nimport type { CoreNodeViewUserOptions } from '@prosemirror-adapter/core'\nimport { useNodeViewContext, useNodeViewFactory, type NodeViewContext, type PreactNodeViewUserOptions } from '@prosemirror-adapter/preact'\nimport { h, type ComponentType, type FunctionComponent } from 'preact'\nimport { useMemo } from 'preact/hooks'\n\nimport { useExtension } from '../hooks/use-extension'\n\n/**\n * @public\n */\nexport interface PreactNodeViewProps extends NodeViewContext {}\n\n/**\n * @public\n */\nexport type PreactNodeViewComponent = ComponentType<PreactNodeViewProps>\n\n/**\n * Options for {@link definePreactNodeView}.\n *\n * @public\n */\nexport interface PreactNodeViewOptions extends CoreNodeViewUserOptions<PreactNodeViewComponent> {\n /**\n * The name of the node type.\n */\n name: string\n}\n\nfunction withNodeViewProps(component: PreactNodeViewComponent) {\n return function NodeViewPropsWrapper() {\n const props: PreactNodeViewProps = useNodeViewContext()\n return h(component, props)\n }\n}\n\n/**\n * @internal\n */\nexport const PreactNodeViewConsumer: FunctionComponent = () => {\n const nodeViewFactory = useNodeViewFactory()\n const extension = useMemo(\n () => definePreactNodeViewFactory(nodeViewFactory),\n [nodeViewFactory],\n )\n useExtension(extension)\n\n return null\n}\n\n/**\n * Defines a node view using a Preact component.\n *\n * @public\n */\nexport function definePreactNodeView(options: PreactNodeViewOptions): Extension {\n const { name, component, ...userOptions } = options\n\n const args: PreactNodeViewUserOptions = {\n ...userOptions,\n component: withNodeViewProps(component),\n }\n\n return defineNodeViewComponent<PreactNodeViewUserOptions>({\n group: 'preact',\n name,\n args,\n })\n}\n\nfunction definePreactNodeViewFactory(\n factory: (options: PreactNodeViewUserOptions) => NodeViewConstructor,\n) {\n return defineNodeViewFactory<PreactNodeViewUserOptions>({\n group: 'preact',\n factory,\n })\n}\n","import type { Editor } from '@prosekit/core'\nimport { ProsemirrorAdapterProvider } from '@prosemirror-adapter/preact'\nimport { h, type ComponentChildren, type ComponentType } from 'preact'\n\nimport { EditorContextProvider } from '../contexts/editor-context'\nimport { PreactMarkViewConsumer } from '../extensions/preact-mark-view'\nimport { PreactNodeViewConsumer } from '../extensions/preact-node-view'\n\nexport interface ProseKitProps {\n editor: Editor\n children?: ComponentChildren\n}\n\n/**\n * The root component for a ProseKit editor.\n *\n * @public\n */\nexport const ProseKit: ComponentType<ProseKitProps> = (props) => {\n const { editor, children } = props\n\n return h(\n EditorContextProvider,\n { value: editor },\n h(\n ProsemirrorAdapterProvider,\n null,\n h(PreactNodeViewConsumer, null),\n h(PreactMarkViewConsumer, null),\n children,\n ),\n )\n}\n","import { useCallback, useLayoutEffect, useRef } from 'preact/hooks'\n\n/**\n * @internal\n */\nexport function useEventCallback<Args extends unknown[], Return>(\n callback: (...args: Args) => Return,\n): (...args: Args) => Return {\n const callbackRef = useRef(callback)\n useLayoutEffect(() => {\n callbackRef.current = callback\n }, [callback])\n return useCallback((...args: Args) => callbackRef.current(...args), [])\n}\n","import { defineDocChangeHandler } from '@prosekit/core'\nimport type { ProseMirrorNode } from '@prosekit/pm/model'\nimport { useMemo } from 'preact/hooks'\n\nimport { useEventCallback } from './use-event-callback'\nimport { useExtension, type UseExtensionOptions } from './use-extension'\n\n/**\n * Calls the given handler whenever the editor document changes.\n *\n * @public\n */\nexport function useDocChange(\n handler: (doc: ProseMirrorNode) => void,\n options?: UseExtensionOptions,\n): void {\n const memoizedHandler = useEventCallback(handler)\n const extension = useMemo(\n () => defineDocChangeHandler((view) => memoizedHandler(view.state.doc)),\n [memoizedHandler],\n )\n useExtension(extension, options)\n}\n","import { defineMountHandler, defineUpdateHandler, ProseKitError, union, type Editor, type Extension } from '@prosekit/core'\nimport { useEffect, useReducer } from 'preact/hooks'\n\nimport { useEditorContext } from '../contexts/editor-context'\n\n/**\n * Retrieves the editor instance from the nearest ProseKit component.\n *\n * @public\n */\nexport function useEditor<E extends Extension = any>(options?: {\n /**\n * Whether to update the component when the editor is mounted or editor state\n * is updated.\n *\n * @default false\n */\n update?: boolean\n}): Editor<E> {\n const update = options?.update ?? false\n\n const editor = useEditorContext<E>()\n if (!editor) {\n throw new ProseKitError(\n 'useEditor must be used within the ProseKit component',\n )\n }\n\n const forceUpdate = useForceUpdate()\n\n useEffect(() => {\n if (update) {\n const extension = union(\n defineMountHandler(forceUpdate),\n defineUpdateHandler(forceUpdate),\n )\n return editor.use(extension)\n }\n }, [editor, update, forceUpdate])\n\n return editor\n}\n\nfunction useForceUpdate() {\n const [, dispatch] = useReducer((x: number) => x + 1, 0)\n return dispatch\n}\n","import { defineMountHandler, defineUpdateHandler, EditorNotFoundError, union, type Editor, type Extension } from '@prosekit/core'\nimport { useSyncExternalStore } from 'preact/compat'\nimport { useMemo } from 'preact/hooks'\n\nimport { useEditorContext } from '../contexts/editor-context'\n\nexport interface UseEditorDerivedOptions<E extends Extension = any> {\n /**\n * The editor to add the extension to. If not provided, it will use the\n * editor from the nearest `<ProseKit>` component.\n */\n editor?: Editor<E>\n}\n\n/**\n * Runs a function to derive a value from the editor instance after editor state\n * changes.\n *\n * This is useful when you need to render something based on the editor state,\n * for example, whether the selected text is wrapped in an italic mark.\n *\n * It returns the derived value that updates whenever the editor state changes.\n *\n * @public\n */\nexport function useEditorDerivedValue<E extends Extension, Derived>(\n /**\n * A function that receives the editor instance and returns a derived value.\n *\n * It will be called whenever the editor's document state changes, or when it\n * mounts.\n *\n * This function should be memoized.\n */\n derive: (editor: Editor<E>) => Derived,\n options?: UseEditorDerivedOptions<E>,\n): Derived {\n const editorContext = useEditorContext<E>()\n const editor = options?.editor ?? editorContext\n if (!editor) {\n throw new EditorNotFoundError()\n }\n\n const [subscribe, getSnapshot] = useMemo(() => {\n return createEditorStore(editor, derive)\n }, [editor, derive])\n\n return useSyncExternalStore(subscribe, getSnapshot)\n}\n\nfunction createEditorStore<Derived, E extends Extension = any>(editor: Editor<E>, derive: (editor: Editor<E>) => Derived) {\n let dirty = true\n let derived: Derived\n\n const subscribe = (onChange: VoidFunction): VoidFunction => {\n const handleChange = () => {\n dirty = true\n onChange()\n }\n const extension = union(\n defineUpdateHandler(handleChange),\n defineMountHandler(handleChange),\n )\n return editor.use(extension)\n }\n\n const getSnapshot = () => {\n if (dirty) {\n dirty = false\n derived = derive(editor)\n }\n return derived\n }\n\n return [subscribe, getSnapshot] as const\n}\n","import { defineKeymap, type Keymap } from '@prosekit/core'\nimport { useMemo } from 'preact/hooks'\n\nimport { useExtension, type UseExtensionOptions } from './use-extension'\n\nexport function useKeymap(keymap: Keymap, options?: UseExtensionOptions): void {\n const extension = useMemo(() => defineKeymap(keymap), [keymap])\n useExtension(extension, options)\n}\n","import { defineUpdateHandler } from '@prosekit/core'\nimport type { EditorState } from '@prosekit/pm/state'\nimport { useMemo } from 'preact/hooks'\n\nimport { useEventCallback } from './use-event-callback'\nimport { useExtension, type UseExtensionOptions } from './use-extension'\n\n/**\n * Calls the given handler whenever the editor state changes.\n *\n * @public\n */\nexport function useStateUpdate(\n handler: (state: EditorState) => void,\n options?: UseExtensionOptions,\n): void {\n const memoizedHandler = useEventCallback(handler)\n const extension = useMemo(\n () => defineUpdateHandler((view) => memoizedHandler(view.state)),\n [memoizedHandler],\n )\n useExtension(extension, options)\n}\n"],"mappings":";;;;;;;;;;;;AAOA,SAAgB,mBACd,QACA,WACM;AACN,KAAI,CAAC,OACH,OAAM,IAAI,qBAAqB;AAGjC,iBAAgB;AACd,MAAI,UACF,QAAO,eAAe,QAAQ,UAAU;IAEzC,CAAC,QAAQ,UAAU,CAAC;;;;;;;;ACbzB,SAAgB,qBACd,WACA,UACU;AACV,QAAO,cAAc;AACnB,SAAO,aAAa,WAAW,aAAa,WAAW,SAAS,GAAG;IAClE,CAAC,WAAW,SAAS,CAAC;;;;;;;;ACW3B,SAAgB,aAKd,WACA,SACM;CACN,MAAM,gBAAgB,kBAAkB;AACxC,oBACE,SAAS,UAAU,eACnB,qBAAqB,WAAW,SAAS,SAAS,CACnD;;;;;ACJH,SAAS,kBAAkB,WAAoC;AAC7D,QAAO,SAAS,uBAAuB;AAErC,SAAO,EAAE,WAD0B,oBAAoB,CAC7B;;;;;;AAO9B,MAAa,+BAAkD;CAC7D,MAAM,kBAAkB,oBAAoB;AAK5C,cAJkB,cACV,4BAA4B,gBAAgB,EAClD,CAAC,gBAAgB,CAClB,CACsB;AAEvB,QAAO;;;;;;;AAQT,SAAgB,qBAAqB,SAA2C;CAC9E,MAAM,EAAE,MAAM,WAAW,GAAG,gBAAgB;AAO5C,QAAO,wBAAmD;EACxD,OAAO;EACP;EACA,MARsC;GACtC,GAAG;GACH,WAAW,kBAAkB,UAAU;GACxC;EAMA,CAAC;;AAGJ,SAAS,4BACP,SACA;AACA,QAAO,sBAAiD;EACtD,OAAO;EACP;EACD,CAAC;;;;;AC/CJ,SAAS,kBAAkB,WAAoC;A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extensions/preact-mark-view.ts","../src/extensions/preact-node-view.ts","../src/hooks/use-editor-extension.ts","../src/components/view-renderer.ts","../src/components/prosekit.ts","../src/hooks/use-event-callback.ts","../src/hooks/use-priority-extension.ts","../src/hooks/use-extension.ts","../src/hooks/use-doc-change.ts","../src/hooks/use-editor-derived-value.ts","../src/hooks/use-editor.ts","../src/hooks/use-keymap.ts","../src/hooks/use-state-update.ts"],"sourcesContent":["import { defineMarkViewComponent, defineMarkViewFactory, type Extension } from '@prosekit/core'\nimport type { CoreMarkViewUserOptions } from '@prosemirror-adapter/core'\nimport {\n AbstractPreactMarkView,\n buildPreactMarkViewCreator,\n type MarkViewContext,\n type PreactRendererResult,\n} from '@prosemirror-adapter/preact'\nimport { createElement, type ComponentType } from 'preact'\nimport { createPortal } from 'preact/compat'\n\n/**\n * @public\n */\nexport interface PreactMarkViewProps extends MarkViewContext {}\n\n/**\n * @public\n */\nexport type PreactMarkViewComponent = ComponentType<PreactMarkViewProps>\n\n/**\n * Options for {@link definePreactMarkView}.\n *\n * @public\n */\nexport interface PreactMarkViewOptions extends CoreMarkViewUserOptions<PreactMarkViewComponent> {\n /**\n * The name of the mark type.\n */\n name: string\n}\n\nclass ProseKitPreactMarkView extends AbstractPreactMarkView<PreactMarkViewComponent> {\n render = () => {\n const UserComponent = this.component\n const props = { ...this.context }\n return createPortal(\n createElement(UserComponent, props),\n this.dom,\n )\n }\n}\n\n/**\n * @internal\n */\nexport function definePreactMarkViewFactory(\n renderPreactRenderer: PreactRendererResult['renderPreactRenderer'],\n removePreactRenderer: PreactRendererResult['removePreactRenderer'],\n): Extension {\n const factory = buildPreactMarkViewCreator(renderPreactRenderer, removePreactRenderer, ProseKitPreactMarkView)\n return defineMarkViewFactory<PreactMarkViewOptions>({\n group: 'preact',\n factory,\n })\n}\n\n/**\n * Defines a mark view using a Preact component.\n *\n * @public\n */\nexport function definePreactMarkView(options: PreactMarkViewOptions): Extension {\n return defineMarkViewComponent<PreactMarkViewOptions>({\n group: 'preact',\n name: options.name,\n args: options,\n })\n}\n","import { defineNodeViewComponent, defineNodeViewFactory, type Extension } from '@prosekit/core'\nimport type { CoreNodeViewUserOptions } from '@prosemirror-adapter/core'\nimport {\n AbstractPreactNodeView,\n buildPreactNodeViewCreator,\n type NodeViewContext,\n type PreactRendererResult,\n} from '@prosemirror-adapter/preact'\nimport { createElement, type ComponentType } from 'preact'\nimport { createPortal } from 'preact/compat'\n\n/**\n * @public\n */\nexport interface PreactNodeViewProps extends NodeViewContext {}\n\n/**\n * @public\n */\nexport type PreactNodeViewComponent = ComponentType<PreactNodeViewProps>\n\n/**\n * Options for {@link definePreactNodeView}.\n *\n * @public\n */\nexport interface PreactNodeViewOptions extends CoreNodeViewUserOptions<PreactNodeViewComponent> {\n /**\n * The name of the node type.\n */\n name: string\n}\n\nclass ProseKitPreactNodeView extends AbstractPreactNodeView<PreactNodeViewComponent> {\n render = () => {\n const UserComponent = this.component\n const props = { ...this.context }\n return createPortal(\n createElement(UserComponent, props),\n this.dom,\n )\n }\n}\n\n/**\n * @internal\n */\nexport function definePreactNodeViewFactory(\n renderPreactRenderer: PreactRendererResult['renderPreactRenderer'],\n removePreactRenderer: PreactRendererResult['removePreactRenderer'],\n): Extension {\n const factory = buildPreactNodeViewCreator(renderPreactRenderer, removePreactRenderer, ProseKitPreactNodeView)\n return defineNodeViewFactory<PreactNodeViewOptions>({\n group: 'preact',\n factory,\n })\n}\n\n/**\n * Defines a node view using a Preact component.\n *\n * @public\n */\nexport function definePreactNodeView(options: PreactNodeViewOptions): Extension {\n return defineNodeViewComponent<PreactNodeViewOptions>({\n group: 'preact',\n name: options.name,\n args: options,\n })\n}\n","import { EditorNotFoundError, type Editor, type Extension } from '@prosekit/core'\nimport { queueExtension } from '@prosekit/web'\nimport { useEffect } from 'preact/hooks'\n\n/**\n * @internal\n */\nexport function useEditorExtension(\n editor: Editor | null | undefined,\n extension: Extension | null,\n): void {\n if (!editor) {\n throw new EditorNotFoundError()\n }\n\n useEffect(() => {\n if (extension) {\n return queueExtension(editor, extension)\n }\n }, [editor, extension])\n}\n","import { union, type Editor } from '@prosekit/core'\nimport { usePreactRenderer } from '@prosemirror-adapter/preact'\nimport { createElement, Fragment, type ComponentChildren, type ComponentType } from 'preact'\nimport { useMemo } from 'preact/hooks'\n\nimport { definePreactMarkViewFactory } from '../extensions/preact-mark-view.ts'\nimport { definePreactNodeViewFactory } from '../extensions/preact-node-view.ts'\nimport { useEditorExtension } from '../hooks/use-editor-extension.ts'\n\ninterface ViewRendererProps {\n editor: Editor\n children: ComponentChildren\n}\n\nexport const ViewRenderer: ComponentType<ViewRendererProps> = ({ editor, children }) => {\n const { renderPreactRenderer, removePreactRenderer, render } = usePreactRenderer()\n\n const extension = useMemo(() => {\n return union([\n definePreactMarkViewFactory(renderPreactRenderer, removePreactRenderer),\n definePreactNodeViewFactory(renderPreactRenderer, removePreactRenderer),\n ])\n }, [renderPreactRenderer, removePreactRenderer])\n\n useEditorExtension(editor, extension)\n\n return createElement(Fragment, null, createElement(Fragment, null, children), createElement(Fragment, null, render()))\n}\n","import type { Editor } from '@prosekit/core'\nimport { createElement, type ComponentChildren, type ComponentType } from 'preact'\n\nimport { EditorContextProvider } from '../contexts/editor-context.ts'\n\nimport { ViewRenderer } from './view-renderer.ts'\n\nexport interface ProseKitProps {\n editor: Editor\n children?: ComponentChildren\n}\n\n/**\n * The root component for a ProseKit editor.\n *\n * @public\n */\nexport const ProseKit: ComponentType<ProseKitProps> = (props) => {\n const { editor, children } = props\n\n return createElement(\n EditorContextProvider,\n { value: editor },\n createElement(\n ViewRenderer,\n { editor, children },\n ),\n )\n}\n","import { useCallback, useLayoutEffect, useRef } from 'preact/hooks'\n\n/**\n * @internal\n */\nexport function useEventCallback<Args extends unknown[], Return>(\n callback: (...args: Args) => Return,\n): (...args: Args) => Return {\n const callbackRef = useRef(callback)\n useLayoutEffect(() => {\n callbackRef.current = callback\n }, [callback])\n return useCallback((...args: Args) => callbackRef.current(...args), [])\n}\n","import { withPriority, type Extension, type Priority } from '@prosekit/core'\nimport { useMemo } from 'preact/hooks'\n\n/**\n * @internal\n */\nexport function usePriorityExtension<T extends Extension = Extension>(\n extension: T | null,\n priority?: Priority | null,\n): T | null {\n return useMemo(() => {\n return extension && priority ? withPriority(extension, priority) : extension\n }, [extension, priority])\n}\n","import type { Editor, Extension, Priority } from '@prosekit/core'\n\nimport { useEditorContext } from '../contexts/editor-context.ts'\n\nimport { useEditorExtension } from './use-editor-extension.ts'\nimport { usePriorityExtension } from './use-priority-extension.ts'\n\nexport interface UseExtensionOptions {\n /**\n * The editor to add the extension to. If not provided, it will use the\n * editor from the nearest `<ProseKit>` component.\n */\n editor?: Editor\n\n /**\n * Optional priority to add the extension with.\n */\n priority?: Priority\n}\n\n/**\n * Add an extension to the editor.\n */\nexport function useExtension(\n /**\n * The extension to add to the editor. If it changes, the previous\n * extension will be removed and the new one (if not null) will be added.\n */\n extension: Extension | null,\n options?: UseExtensionOptions,\n): void {\n const editorContext = useEditorContext()\n useEditorExtension(\n options?.editor || editorContext,\n usePriorityExtension(extension, options?.priority),\n )\n}\n","import { defineDocChangeHandler } from '@prosekit/core'\nimport type { ProseMirrorNode } from '@prosekit/pm/model'\nimport { useMemo } from 'preact/hooks'\n\nimport { useEventCallback } from './use-event-callback.ts'\nimport { useExtension, type UseExtensionOptions } from './use-extension.ts'\n\n/**\n * Calls the given handler whenever the editor document changes.\n *\n * @public\n */\nexport function useDocChange(\n handler: (doc: ProseMirrorNode) => void,\n options?: UseExtensionOptions,\n): void {\n const memoizedHandler = useEventCallback(handler)\n const extension = useMemo(\n () => defineDocChangeHandler((view) => memoizedHandler(view.state.doc)),\n [memoizedHandler],\n )\n useExtension(extension, options)\n}\n","import { defineMountHandler, defineUpdateHandler, EditorNotFoundError, union, type Editor, type Extension } from '@prosekit/core'\nimport { useSyncExternalStore } from 'preact/compat'\nimport { useMemo } from 'preact/hooks'\n\nimport { useEditorContext } from '../contexts/editor-context.ts'\n\nexport interface UseEditorDerivedOptions<E extends Extension = any> {\n /**\n * The editor to add the extension to. If not provided, it will use the\n * editor from the nearest `<ProseKit>` component.\n */\n editor?: Editor<E>\n}\n\n/**\n * Runs a function to derive a value from the editor instance after editor state\n * changes.\n *\n * This is useful when you need to render something based on the editor state,\n * for example, whether the selected text is wrapped in an italic mark.\n *\n * It returns the derived value that updates whenever the editor state changes.\n *\n * @public\n */\nexport function useEditorDerivedValue<E extends Extension, Derived>(\n /**\n * A function that receives the editor instance and returns a derived value.\n *\n * It will be called whenever the editor's document state changes, or when it\n * mounts.\n *\n * This function should be memoized.\n */\n derive: (editor: Editor<E>) => Derived,\n options?: UseEditorDerivedOptions<E>,\n): Derived {\n const editorContext = useEditorContext<E>()\n const editor = options?.editor ?? editorContext\n if (!editor) {\n throw new EditorNotFoundError()\n }\n\n const [subscribe, getSnapshot] = useMemo(() => {\n return createEditorStore(editor, derive)\n }, [editor, derive])\n\n return useSyncExternalStore(subscribe, getSnapshot)\n}\n\nfunction createEditorStore<Derived, E extends Extension = any>(editor: Editor<E>, derive: (editor: Editor<E>) => Derived) {\n let dirty = true\n let derived: Derived\n\n const subscribe = (onChange: VoidFunction): VoidFunction => {\n const handleChange = () => {\n dirty = true\n onChange()\n }\n const extension = union(\n defineUpdateHandler(handleChange),\n defineMountHandler(handleChange),\n )\n return editor.use(extension)\n }\n\n const getSnapshot = () => {\n if (dirty) {\n dirty = false\n derived = derive(editor)\n }\n return derived\n }\n\n return [subscribe, getSnapshot] as const\n}\n","import { defineMountHandler, defineUpdateHandler, ProseKitError, union, type Editor, type Extension } from '@prosekit/core'\nimport { useEffect, useReducer } from 'preact/hooks'\n\nimport { useEditorContext } from '../contexts/editor-context.ts'\n\n/**\n * Retrieves the editor instance from the nearest ProseKit component.\n *\n * @public\n */\nexport function useEditor<E extends Extension = any>(options?: {\n /**\n * Whether to update the component when the editor is mounted or editor state\n * is updated.\n *\n * @default false\n */\n update?: boolean\n}): Editor<E> {\n const update = options?.update ?? false\n\n const editor = useEditorContext<E>()\n if (!editor) {\n throw new ProseKitError(\n 'useEditor must be used within the ProseKit component',\n )\n }\n\n const forceUpdate = useForceUpdate()\n\n useEffect(() => {\n if (update) {\n const extension = union(\n defineMountHandler(forceUpdate),\n defineUpdateHandler(forceUpdate),\n )\n return editor.use(extension)\n }\n }, [editor, update, forceUpdate])\n\n return editor\n}\n\nfunction useForceUpdate() {\n const [, dispatch] = useReducer((x: number) => x + 1, 0)\n return dispatch\n}\n","import { defineKeymap, type Keymap } from '@prosekit/core'\nimport { useMemo } from 'preact/hooks'\n\nimport { useExtension, type UseExtensionOptions } from './use-extension.ts'\n\nexport function useKeymap(keymap: Keymap, options?: UseExtensionOptions): void {\n const extension = useMemo(() => defineKeymap(keymap), [keymap])\n useExtension(extension, options)\n}\n","import { defineUpdateHandler } from '@prosekit/core'\nimport type { EditorState } from '@prosekit/pm/state'\nimport { useMemo } from 'preact/hooks'\n\nimport { useEventCallback } from './use-event-callback.ts'\nimport { useExtension, type UseExtensionOptions } from './use-extension.ts'\n\n/**\n * Calls the given handler whenever the editor state changes.\n *\n * @public\n */\nexport function useStateUpdate(\n handler: (state: EditorState) => void,\n options?: UseExtensionOptions,\n): void {\n const memoizedHandler = useEventCallback(handler)\n const extension = useMemo(\n () => defineUpdateHandler((view) => memoizedHandler(view.state)),\n [memoizedHandler],\n )\n useExtension(extension, options)\n}\n"],"mappings":";;;;;;;;AAiCA,IAAM,yBAAN,cAAqC,uBAAgD;;;sBACpE;GACb,MAAM,gBAAgB,KAAK;AAE3B,UAAO,aACL,cAAc,eAFF,EAAE,GAAG,KAAK,SAAS,CAEI,EACnC,KAAK,IACN;;;;;;;AAOL,SAAgB,4BACd,sBACA,sBACW;AAEX,QAAO,sBAA6C;EAClD,OAAO;EACP,SAHc,2BAA2B,sBAAsB,sBAAsB,uBAAuB;EAI7G,CAAC;;;;;;;AAQJ,SAAgB,qBAAqB,SAA2C;AAC9E,QAAO,wBAA+C;EACpD,OAAO;EACP,MAAM,QAAQ;EACd,M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,KAAI,CAAC,OACH,OAAM,IAAI,cACR,uDACD;CAGH,MAAM,cAAc,gBAAgB;AAEpC,iBAAgB;AACd,MAAI,QAAQ;GACV,MAAM,YAAY,MAChB,mBAAmB,YAAY,EAC/B,oBAAoB,YAAY,CACjC;AACD,UAAO,OAAO,IAAI,UAAU;;IAE7B;EAAC;EAAQ;EAAQ;EAAY,CAAC;AAEjC,QAAO;;AAGT,SAAS,iBAAiB;CACxB,MAAM,GAAG,YAAY,YAAY,MAAc,IAAI,GAAG,EAAE;AACxD,QAAO;;;;ACxCT,SAAgB,UAAU,QAAgB,SAAqC;AAE7E,cADkB,cAAc,aAAa,OAAO,EAAE,CAAC,OAAO,CAAC,EACvC,QAAQ;;;;;;;;;ACKlC,SAAgB,eACd,SACA,SACM;CACN,MAAM,kBAAkB,iBAAiB,QAAQ;AAKjD,cAJkB,cACV,qBAAqB,SAAS,gBAAgB,KAAK,MAAM,CAAC,EAChE,CAAC,gBAAgB,CAClB,EACuB,QAAQ"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prosekit/preact",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.6.
|
|
4
|
+
"version": "0.6.8",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Preact components and utilities for ProseKit",
|
|
7
7
|
"author": {
|
|
@@ -68,11 +68,11 @@
|
|
|
68
68
|
"src"
|
|
69
69
|
],
|
|
70
70
|
"dependencies": {
|
|
71
|
-
"@prosemirror-adapter/core": "^0.
|
|
72
|
-
"@prosemirror-adapter/preact": "^0.5.
|
|
73
|
-
"@prosekit/core": "^0.
|
|
71
|
+
"@prosemirror-adapter/core": "^0.5.2",
|
|
72
|
+
"@prosemirror-adapter/preact": "^0.5.2",
|
|
73
|
+
"@prosekit/core": "^0.11.0",
|
|
74
74
|
"@prosekit/pm": "^0.1.15",
|
|
75
|
-
"@prosekit/web": "^0.7.
|
|
75
|
+
"@prosekit/web": "^0.7.13"
|
|
76
76
|
},
|
|
77
77
|
"peerDependencies": {
|
|
78
78
|
"preact": ">= 10.11.0"
|
|
@@ -83,9 +83,10 @@
|
|
|
83
83
|
}
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
|
-
"preact": "^10.
|
|
87
|
-
"tsdown": "^0.
|
|
86
|
+
"preact": "^10.29.0",
|
|
87
|
+
"tsdown": "^0.21.4",
|
|
88
88
|
"typescript": "~5.9.3",
|
|
89
|
+
"@prosekit/config-ts": "0.0.0",
|
|
89
90
|
"@prosekit/config-tsdown": "0.0.0",
|
|
90
91
|
"@prosekit/config-vitest": "0.0.0"
|
|
91
92
|
},
|
|
@@ -11,20 +11,20 @@ import type {
|
|
|
11
11
|
RefAttributes,
|
|
12
12
|
} from 'preact/compat'
|
|
13
13
|
|
|
14
|
-
import { createComponent } from '../create-component'
|
|
15
|
-
import type { CreateProps } from '../create-props'
|
|
14
|
+
import { createComponent } from '../create-component.ts'
|
|
15
|
+
import type { CreateProps } from '../create-props.ts'
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Props for the {@link AutocompleteEmpty} component.
|
|
19
19
|
*/
|
|
20
20
|
export interface AutocompleteEmptyProps extends Partial<CreateProps<Props, Events>> {}
|
|
21
|
-
|
|
21
|
+
|
|
22
22
|
export const AutocompleteEmpty: ForwardRefExoticComponent<
|
|
23
23
|
Partial<AutocompleteEmptyProps> &
|
|
24
24
|
RefAttributes<AutocompleteEmptyElement> &
|
|
25
25
|
HTMLAttributes<AutocompleteEmptyElement>
|
|
26
26
|
> = createComponent<
|
|
27
|
-
AutocompleteEmptyProps,
|
|
27
|
+
AutocompleteEmptyProps,
|
|
28
28
|
AutocompleteEmptyElement
|
|
29
29
|
>(
|
|
30
30
|
'prosekit-autocomplete-empty',
|
|
@@ -11,20 +11,20 @@ import type {
|
|
|
11
11
|
RefAttributes,
|
|
12
12
|
} from 'preact/compat'
|
|
13
13
|
|
|
14
|
-
import { createComponent } from '../create-component'
|
|
15
|
-
import type { CreateProps } from '../create-props'
|
|
14
|
+
import { createComponent } from '../create-component.ts'
|
|
15
|
+
import type { CreateProps } from '../create-props.ts'
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Props for the {@link AutocompleteItem} component.
|
|
19
19
|
*/
|
|
20
20
|
export interface AutocompleteItemProps extends Partial<CreateProps<Props, Events>> {}
|
|
21
|
-
|
|
21
|
+
|
|
22
22
|
export const AutocompleteItem: ForwardRefExoticComponent<
|
|
23
23
|
Partial<AutocompleteItemProps> &
|
|
24
24
|
RefAttributes<AutocompleteItemElement> &
|
|
25
25
|
HTMLAttributes<AutocompleteItemElement>
|
|
26
26
|
> = createComponent<
|
|
27
|
-
AutocompleteItemProps,
|
|
27
|
+
AutocompleteItemProps,
|
|
28
28
|
AutocompleteItemElement
|
|
29
29
|
>(
|
|
30
30
|
'prosekit-autocomplete-item',
|
|
@@ -11,20 +11,20 @@ import type {
|
|
|
11
11
|
RefAttributes,
|
|
12
12
|
} from 'preact/compat'
|
|
13
13
|
|
|
14
|
-
import { createComponent } from '../create-component'
|
|
15
|
-
import type { CreateProps } from '../create-props'
|
|
14
|
+
import { createComponent } from '../create-component.ts'
|
|
15
|
+
import type { CreateProps } from '../create-props.ts'
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Props for the {@link AutocompleteList} component.
|
|
19
19
|
*/
|
|
20
20
|
export interface AutocompleteListProps extends Partial<CreateProps<Props, Events>> {}
|
|
21
|
-
|
|
21
|
+
|
|
22
22
|
export const AutocompleteList: ForwardRefExoticComponent<
|
|
23
23
|
Partial<AutocompleteListProps> &
|
|
24
24
|
RefAttributes<AutocompleteListElement> &
|
|
25
25
|
HTMLAttributes<AutocompleteListElement>
|
|
26
26
|
> = createComponent<
|
|
27
|
-
AutocompleteListProps,
|
|
27
|
+
AutocompleteListProps,
|
|
28
28
|
AutocompleteListElement
|
|
29
29
|
>(
|
|
30
30
|
'prosekit-autocomplete-list',
|
|
@@ -11,20 +11,20 @@ import type {
|
|
|
11
11
|
RefAttributes,
|
|
12
12
|
} from 'preact/compat'
|
|
13
13
|
|
|
14
|
-
import { createComponent } from '../create-component'
|
|
15
|
-
import type { CreateProps } from '../create-props'
|
|
14
|
+
import { createComponent } from '../create-component.ts'
|
|
15
|
+
import type { CreateProps } from '../create-props.ts'
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Props for the {@link AutocompletePopover} component.
|
|
19
19
|
*/
|
|
20
20
|
export interface AutocompletePopoverProps extends Partial<CreateProps<Props, Events>> {}
|
|
21
|
-
|
|
21
|
+
|
|
22
22
|
export const AutocompletePopover: ForwardRefExoticComponent<
|
|
23
23
|
Partial<AutocompletePopoverProps> &
|
|
24
24
|
RefAttributes<AutocompletePopoverElement> &
|
|
25
25
|
HTMLAttributes<AutocompletePopoverElement>
|
|
26
26
|
> = createComponent<
|
|
27
|
-
AutocompletePopoverProps,
|
|
27
|
+
AutocompletePopoverProps,
|
|
28
28
|
AutocompletePopoverElement
|
|
29
29
|
>(
|
|
30
30
|
'prosekit-autocomplete-popover',
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { AutocompleteEmpty, type AutocompleteEmptyProps } from './autocomplete-empty.gen'
|
|
1
|
+
export { AutocompleteEmpty, type AutocompleteEmptyProps } from './autocomplete-empty.gen.ts'
|
|
2
2
|
|
|
3
|
-
export { AutocompleteItem, type AutocompleteItemProps } from './autocomplete-item.gen'
|
|
3
|
+
export { AutocompleteItem, type AutocompleteItemProps } from './autocomplete-item.gen.ts'
|
|
4
4
|
|
|
5
|
-
export { AutocompleteList, type AutocompleteListProps } from './autocomplete-list.gen'
|
|
5
|
+
export { AutocompleteList, type AutocompleteListProps } from './autocomplete-list.gen.ts'
|
|
6
6
|
|
|
7
|
-
export { AutocompletePopover, type AutocompletePopoverProps } from './autocomplete-popover.gen'
|
|
7
|
+
export { AutocompletePopover, type AutocompletePopoverProps } from './autocomplete-popover.gen.ts'
|
|
@@ -11,20 +11,20 @@ import type {
|
|
|
11
11
|
RefAttributes,
|
|
12
12
|
} from 'preact/compat'
|
|
13
13
|
|
|
14
|
-
import { createComponent } from '../create-component'
|
|
15
|
-
import type { CreateProps } from '../create-props'
|
|
14
|
+
import { createComponent } from '../create-component.ts'
|
|
15
|
+
import type { CreateProps } from '../create-props.ts'
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Props for the {@link BlockHandleAdd} component.
|
|
19
19
|
*/
|
|
20
20
|
export interface BlockHandleAddProps extends Partial<CreateProps<Props, Events>> {}
|
|
21
|
-
|
|
21
|
+
|
|
22
22
|
export const BlockHandleAdd: ForwardRefExoticComponent<
|
|
23
23
|
Partial<BlockHandleAddProps> &
|
|
24
24
|
RefAttributes<BlockHandleAddElement> &
|
|
25
25
|
HTMLAttributes<BlockHandleAddElement>
|
|
26
26
|
> = createComponent<
|
|
27
|
-
BlockHandleAddProps,
|
|
27
|
+
BlockHandleAddProps,
|
|
28
28
|
BlockHandleAddElement
|
|
29
29
|
>(
|
|
30
30
|
'prosekit-block-handle-add',
|
|
@@ -11,20 +11,20 @@ import type {
|
|
|
11
11
|
RefAttributes,
|
|
12
12
|
} from 'preact/compat'
|
|
13
13
|
|
|
14
|
-
import { createComponent } from '../create-component'
|
|
15
|
-
import type { CreateProps } from '../create-props'
|
|
14
|
+
import { createComponent } from '../create-component.ts'
|
|
15
|
+
import type { CreateProps } from '../create-props.ts'
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Props for the {@link BlockHandleDraggable} component.
|
|
19
19
|
*/
|
|
20
20
|
export interface BlockHandleDraggableProps extends Partial<CreateProps<Props, Events>> {}
|
|
21
|
-
|
|
21
|
+
|
|
22
22
|
export const BlockHandleDraggable: ForwardRefExoticComponent<
|
|
23
23
|
Partial<BlockHandleDraggableProps> &
|
|
24
24
|
RefAttributes<BlockHandleDraggableElement> &
|
|
25
25
|
HTMLAttributes<BlockHandleDraggableElement>
|
|
26
26
|
> = createComponent<
|
|
27
|
-
BlockHandleDraggableProps,
|
|
27
|
+
BlockHandleDraggableProps,
|
|
28
28
|
BlockHandleDraggableElement
|
|
29
29
|
>(
|
|
30
30
|
'prosekit-block-handle-draggable',
|
|
@@ -11,20 +11,20 @@ import type {
|
|
|
11
11
|
RefAttributes,
|
|
12
12
|
} from 'preact/compat'
|
|
13
13
|
|
|
14
|
-
import { createComponent } from '../create-component'
|
|
15
|
-
import type { CreateProps } from '../create-props'
|
|
14
|
+
import { createComponent } from '../create-component.ts'
|
|
15
|
+
import type { CreateProps } from '../create-props.ts'
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Props for the {@link BlockHandlePopover} component.
|
|
19
19
|
*/
|
|
20
20
|
export interface BlockHandlePopoverProps extends Partial<CreateProps<Props, Events>> {}
|
|
21
|
-
|
|
21
|
+
|
|
22
22
|
export const BlockHandlePopover: ForwardRefExoticComponent<
|
|
23
23
|
Partial<BlockHandlePopoverProps> &
|
|
24
24
|
RefAttributes<BlockHandlePopoverElement> &
|
|
25
25
|
HTMLAttributes<BlockHandlePopoverElement>
|
|
26
26
|
> = createComponent<
|
|
27
|
-
BlockHandlePopoverProps,
|
|
27
|
+
BlockHandlePopoverProps,
|
|
28
28
|
BlockHandlePopoverElement
|
|
29
29
|
>(
|
|
30
30
|
'prosekit-block-handle-popover',
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { BlockHandleAdd, type BlockHandleAddProps } from './block-handle-add.gen'
|
|
1
|
+
export { BlockHandleAdd, type BlockHandleAddProps } from './block-handle-add.gen.ts'
|
|
2
2
|
|
|
3
|
-
export { BlockHandleDraggable, type BlockHandleDraggableProps } from './block-handle-draggable.gen'
|
|
3
|
+
export { BlockHandleDraggable, type BlockHandleDraggableProps } from './block-handle-draggable.gen.ts'
|
|
4
4
|
|
|
5
|
-
export { BlockHandlePopover, type BlockHandlePopoverProps } from './block-handle-popover.gen'
|
|
5
|
+
export { BlockHandlePopover, type BlockHandlePopoverProps } from './block-handle-popover.gen.ts'
|
|
@@ -3,9 +3,9 @@ import { createElement } from 'preact'
|
|
|
3
3
|
import { forwardRef, type ForwardRefExoticComponent, type HTMLAttributes, type RefAttributes } from 'preact/compat'
|
|
4
4
|
import { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'preact/hooks'
|
|
5
5
|
|
|
6
|
-
import { useEditorContext } from '../contexts/editor-context'
|
|
6
|
+
import { useEditorContext } from '../contexts/editor-context.ts'
|
|
7
7
|
|
|
8
|
-
import { mergeRefs } from './merge-refs'
|
|
8
|
+
import { mergeRefs } from './merge-refs.ts'
|
|
9
9
|
|
|
10
10
|
const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect
|
|
11
11
|
|
|
@@ -77,7 +77,6 @@ export function createComponent<
|
|
|
77
77
|
for (const [name, value] of Object.entries(properties)) {
|
|
78
78
|
if (value !== undefined) {
|
|
79
79
|
// @ts-expect-error: we know that name is a valid property name
|
|
80
|
-
// eslint-disable-next-line react-hooks/immutability
|
|
81
80
|
el[name] = value
|
|
82
81
|
}
|
|
83
82
|
}
|