@prosekit/react 0.6.7 → 0.6.9
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-D8vvwyIA.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-DHjS00Fa.js → editor-context.js} +2 -3
- package/dist/editor-context.js.map +1 -0
- package/dist/prosekit-react-autocomplete.d.ts +1 -1
- package/dist/prosekit-react-autocomplete.js +2 -6
- package/dist/prosekit-react-autocomplete.js.map +1 -1
- package/dist/prosekit-react-block-handle.d.ts +1 -1
- package/dist/prosekit-react-block-handle.js +2 -5
- package/dist/prosekit-react-block-handle.js.map +1 -1
- package/dist/prosekit-react-drop-indicator.d.ts +1 -1
- package/dist/prosekit-react-drop-indicator.js +2 -3
- package/dist/prosekit-react-drop-indicator.js.map +1 -1
- package/dist/prosekit-react-inline-popover.d.ts +1 -1
- package/dist/prosekit-react-inline-popover.js +2 -3
- package/dist/prosekit-react-inline-popover.js.map +1 -1
- package/dist/prosekit-react-popover.d.ts +1 -1
- package/dist/prosekit-react-popover.js +2 -5
- package/dist/prosekit-react-popover.js.map +1 -1
- package/dist/prosekit-react-resizable.d.ts +1 -1
- package/dist/prosekit-react-resizable.js +2 -4
- package/dist/prosekit-react-resizable.js.map +1 -1
- package/dist/prosekit-react-table-handle.d.ts +1 -1
- package/dist/prosekit-react-table-handle.js +2 -11
- package/dist/prosekit-react-table-handle.js.map +1 -1
- package/dist/prosekit-react-tooltip.d.ts +1 -1
- package/dist/prosekit-react-tooltip.js +2 -5
- package/dist/prosekit-react-tooltip.js.map +1 -1
- package/dist/prosekit-react.d.ts +22 -22
- package/dist/prosekit-react.d.ts.map +1 -1
- package/dist/prosekit-react.js +109 -118
- package/dist/prosekit-react.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 +5 -9
- 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 +27 -0
- package/src/extensions/react-mark-view.ts +29 -37
- package/src/extensions/react-node-view.ts +29 -37
- 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-D8vvwyIA.js.map +0 -1
- package/dist/create-props-PUVFMh9y.d.ts.map +0 -1
- package/dist/editor-context-DHjS00Fa.js.map +0 -1
package/dist/prosekit-react.js
CHANGED
|
@@ -1,117 +1,92 @@
|
|
|
1
|
-
import { n as useEditorContext, t as EditorContextProvider } from "./editor-context
|
|
2
|
-
import {
|
|
3
|
-
import { createElement, useCallback, useEffect, useLayoutEffect, useMemo, useReducer, useRef, useSyncExternalStore } from "react";
|
|
1
|
+
import { n as useEditorContext, t as EditorContextProvider } from "./editor-context.js";
|
|
2
|
+
import { Fragment, createElement, useCallback, useEffect, useLayoutEffect, useMemo, useReducer, useRef, useSyncExternalStore } from "react";
|
|
4
3
|
import { EditorNotFoundError, ProseKitError, defineDocChangeHandler, defineKeymap, defineMarkViewComponent, defineMarkViewFactory, defineMountHandler, defineNodeViewComponent, defineNodeViewFactory, defineUpdateHandler, union, withPriority } from "@prosekit/core";
|
|
4
|
+
import { AbstractReactMarkView, AbstractReactNodeView, buildReactMarkViewCreator, buildReactNodeViewCreator, useReactRenderer } from "@prosemirror-adapter/react";
|
|
5
|
+
import { createPortal } from "react-dom";
|
|
5
6
|
import { queueExtension } from "@prosekit/web";
|
|
6
|
-
|
|
7
|
-
//#region src/hooks/use-editor-extension.ts
|
|
8
|
-
/**
|
|
9
|
-
* @internal
|
|
10
|
-
*/
|
|
11
|
-
function useEditorExtension(editor, extension) {
|
|
12
|
-
if (!editor) throw new EditorNotFoundError();
|
|
13
|
-
useEffect(() => {
|
|
14
|
-
if (extension) return queueExtension(editor, extension);
|
|
15
|
-
}, [editor, extension]);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
//#endregion
|
|
19
|
-
//#region src/hooks/use-priority-extension.ts
|
|
20
|
-
/**
|
|
21
|
-
* @internal
|
|
22
|
-
*/
|
|
23
|
-
function usePriorityExtension(extension, priority) {
|
|
24
|
-
return useMemo(() => {
|
|
25
|
-
return extension && priority ? withPriority(extension, priority) : extension;
|
|
26
|
-
}, [extension, priority]);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
//#endregion
|
|
30
|
-
//#region src/hooks/use-extension.ts
|
|
31
|
-
/**
|
|
32
|
-
* Add an extension to the editor.
|
|
33
|
-
*/
|
|
34
|
-
function useExtension(extension, options) {
|
|
35
|
-
const editorContext = useEditorContext();
|
|
36
|
-
useEditorExtension(options?.editor || editorContext, usePriorityExtension(extension, options?.priority));
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
//#endregion
|
|
40
7
|
//#region src/extensions/react-mark-view.ts
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
8
|
+
var ProseKitReactMarkView = class extends AbstractReactMarkView {
|
|
9
|
+
constructor(..._args) {
|
|
10
|
+
super(..._args);
|
|
11
|
+
this.render = () => {
|
|
12
|
+
const UserComponent = this.component;
|
|
13
|
+
return createPortal(createElement(UserComponent, { ...this.context }), this.dom, this.key);
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
};
|
|
46
17
|
/**
|
|
47
18
|
* @internal
|
|
48
19
|
*/
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
};
|
|
20
|
+
function defineReactMarkViewFactory(renderReactRenderer, removeReactRenderer) {
|
|
21
|
+
return defineMarkViewFactory({
|
|
22
|
+
group: "react",
|
|
23
|
+
factory: buildReactMarkViewCreator(renderReactRenderer, removeReactRenderer, ProseKitReactMarkView)
|
|
24
|
+
});
|
|
25
|
+
}
|
|
54
26
|
/**
|
|
55
27
|
* Defines a mark view using a React component.
|
|
56
28
|
*
|
|
57
29
|
* @public
|
|
58
30
|
*/
|
|
59
31
|
function defineReactMarkView(options) {
|
|
60
|
-
const { name, component, ...userOptions } = options;
|
|
61
32
|
return defineMarkViewComponent({
|
|
62
33
|
group: "react",
|
|
63
|
-
name,
|
|
64
|
-
args:
|
|
65
|
-
...userOptions,
|
|
66
|
-
component: withMarkViewProps(component)
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
function defineReactMarkViewFactory(factory) {
|
|
71
|
-
return defineMarkViewFactory({
|
|
72
|
-
group: "react",
|
|
73
|
-
factory
|
|
34
|
+
name: options.name,
|
|
35
|
+
args: options
|
|
74
36
|
});
|
|
75
37
|
}
|
|
76
|
-
|
|
77
38
|
//#endregion
|
|
78
39
|
//#region src/extensions/react-node-view.ts
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
40
|
+
var ProseKitReactNodeView = class extends AbstractReactNodeView {
|
|
41
|
+
constructor(..._args) {
|
|
42
|
+
super(..._args);
|
|
43
|
+
this.render = () => {
|
|
44
|
+
const UserComponent = this.component;
|
|
45
|
+
return createPortal(createElement(UserComponent, { ...this.context }), this.dom, this.key);
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
};
|
|
84
49
|
/**
|
|
85
50
|
* @internal
|
|
86
51
|
*/
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
};
|
|
52
|
+
function defineReactNodeViewFactory(renderReactRenderer, removeReactRenderer) {
|
|
53
|
+
return defineNodeViewFactory({
|
|
54
|
+
group: "react",
|
|
55
|
+
factory: buildReactNodeViewCreator(renderReactRenderer, removeReactRenderer, ProseKitReactNodeView)
|
|
56
|
+
});
|
|
57
|
+
}
|
|
92
58
|
/**
|
|
93
59
|
* Defines a node view using a React component.
|
|
94
60
|
*
|
|
95
61
|
* @public
|
|
96
62
|
*/
|
|
97
63
|
function defineReactNodeView(options) {
|
|
98
|
-
const { name, component, ...userOptions } = options;
|
|
99
64
|
return defineNodeViewComponent({
|
|
100
65
|
group: "react",
|
|
101
|
-
name,
|
|
102
|
-
args:
|
|
103
|
-
...userOptions,
|
|
104
|
-
component: withNodeViewProps(component)
|
|
105
|
-
}
|
|
66
|
+
name: options.name,
|
|
67
|
+
args: options
|
|
106
68
|
});
|
|
107
69
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region src/hooks/use-editor-extension.ts
|
|
72
|
+
/**
|
|
73
|
+
* @internal
|
|
74
|
+
*/
|
|
75
|
+
function useEditorExtension(editor, extension) {
|
|
76
|
+
if (!editor) throw new EditorNotFoundError();
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
if (extension) return queueExtension(editor, extension);
|
|
79
|
+
}, [editor, extension]);
|
|
113
80
|
}
|
|
114
|
-
|
|
81
|
+
//#endregion
|
|
82
|
+
//#region src/components/view-renderer.ts
|
|
83
|
+
const ViewRenderer = ({ editor, children }) => {
|
|
84
|
+
const { renderReactRenderer, removeReactRenderer, render } = useReactRenderer();
|
|
85
|
+
useEditorExtension(editor, useMemo(() => {
|
|
86
|
+
return union([defineReactMarkViewFactory(renderReactRenderer, removeReactRenderer), defineReactNodeViewFactory(renderReactRenderer, removeReactRenderer)]);
|
|
87
|
+
}, [renderReactRenderer, removeReactRenderer]));
|
|
88
|
+
return createElement(Fragment, null, createElement(Fragment, null, children), createElement(Fragment, null, render()));
|
|
89
|
+
};
|
|
115
90
|
//#endregion
|
|
116
91
|
//#region src/components/prosekit.ts
|
|
117
92
|
/**
|
|
@@ -121,9 +96,11 @@ function defineReactNodeViewFactory(factory) {
|
|
|
121
96
|
*/
|
|
122
97
|
const ProseKit = (props) => {
|
|
123
98
|
const { editor, children } = props;
|
|
124
|
-
return createElement(EditorContextProvider, { value: editor }, createElement(
|
|
99
|
+
return createElement(EditorContextProvider, { value: editor }, createElement(ViewRenderer, {
|
|
100
|
+
editor,
|
|
101
|
+
children
|
|
102
|
+
}));
|
|
125
103
|
};
|
|
126
|
-
|
|
127
104
|
//#endregion
|
|
128
105
|
//#region src/hooks/use-event-callback.ts
|
|
129
106
|
/**
|
|
@@ -136,7 +113,25 @@ function useEventCallback(callback) {
|
|
|
136
113
|
}, [callback]);
|
|
137
114
|
return useCallback((...args) => callbackRef.current(...args), []);
|
|
138
115
|
}
|
|
139
|
-
|
|
116
|
+
//#endregion
|
|
117
|
+
//#region src/hooks/use-priority-extension.ts
|
|
118
|
+
/**
|
|
119
|
+
* @internal
|
|
120
|
+
*/
|
|
121
|
+
function usePriorityExtension(extension, priority) {
|
|
122
|
+
return useMemo(() => {
|
|
123
|
+
return extension && priority ? withPriority(extension, priority) : extension;
|
|
124
|
+
}, [extension, priority]);
|
|
125
|
+
}
|
|
126
|
+
//#endregion
|
|
127
|
+
//#region src/hooks/use-extension.ts
|
|
128
|
+
/**
|
|
129
|
+
* Add an extension to the editor.
|
|
130
|
+
*/
|
|
131
|
+
function useExtension(extension, options) {
|
|
132
|
+
const editorContext = useEditorContext();
|
|
133
|
+
useEditorExtension(options?.editor || editorContext, usePriorityExtension(extension, options?.priority));
|
|
134
|
+
}
|
|
140
135
|
//#endregion
|
|
141
136
|
//#region src/hooks/use-doc-change.ts
|
|
142
137
|
/**
|
|
@@ -148,36 +143,6 @@ function useDocChange(handler, options) {
|
|
|
148
143
|
const memoizedHandler = useEventCallback(handler);
|
|
149
144
|
useExtension(useMemo(() => defineDocChangeHandler((view) => memoizedHandler(view.state.doc)), [memoizedHandler]), options);
|
|
150
145
|
}
|
|
151
|
-
|
|
152
|
-
//#endregion
|
|
153
|
-
//#region src/hooks/use-editor.ts
|
|
154
|
-
/**
|
|
155
|
-
* Retrieves the editor instance from the nearest ProseKit component.
|
|
156
|
-
*
|
|
157
|
-
* @public
|
|
158
|
-
*/
|
|
159
|
-
function useEditor(options) {
|
|
160
|
-
const update = options?.update ?? false;
|
|
161
|
-
const editor = useEditorContext();
|
|
162
|
-
if (!editor) throw new ProseKitError("useEditor must be used within the ProseKit component");
|
|
163
|
-
const forceUpdate = useForceUpdate();
|
|
164
|
-
useEffect(() => {
|
|
165
|
-
if (update) {
|
|
166
|
-
const extension = union(defineMountHandler(forceUpdate), defineUpdateHandler(forceUpdate));
|
|
167
|
-
return editor.use(extension);
|
|
168
|
-
}
|
|
169
|
-
}, [
|
|
170
|
-
editor,
|
|
171
|
-
update,
|
|
172
|
-
forceUpdate
|
|
173
|
-
]);
|
|
174
|
-
return editor;
|
|
175
|
-
}
|
|
176
|
-
function useForceUpdate() {
|
|
177
|
-
const [, dispatch] = useReducer((x) => x + 1, 0);
|
|
178
|
-
return dispatch;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
146
|
//#endregion
|
|
182
147
|
//#region src/hooks/use-editor-derived-value.ts
|
|
183
148
|
/**
|
|
@@ -220,13 +185,39 @@ function createEditorStore(editor, derive) {
|
|
|
220
185
|
};
|
|
221
186
|
return [subscribe, getSnapshot];
|
|
222
187
|
}
|
|
223
|
-
|
|
188
|
+
//#endregion
|
|
189
|
+
//#region src/hooks/use-editor.ts
|
|
190
|
+
/**
|
|
191
|
+
* Retrieves the editor instance from the nearest ProseKit component.
|
|
192
|
+
*
|
|
193
|
+
* @public
|
|
194
|
+
*/
|
|
195
|
+
function useEditor(options) {
|
|
196
|
+
const update = options?.update ?? false;
|
|
197
|
+
const editor = useEditorContext();
|
|
198
|
+
if (!editor) throw new ProseKitError("useEditor must be used within the ProseKit component");
|
|
199
|
+
const forceUpdate = useForceUpdate();
|
|
200
|
+
useEffect(() => {
|
|
201
|
+
if (update) {
|
|
202
|
+
const extension = union(defineMountHandler(forceUpdate), defineUpdateHandler(forceUpdate));
|
|
203
|
+
return editor.use(extension);
|
|
204
|
+
}
|
|
205
|
+
}, [
|
|
206
|
+
editor,
|
|
207
|
+
update,
|
|
208
|
+
forceUpdate
|
|
209
|
+
]);
|
|
210
|
+
return editor;
|
|
211
|
+
}
|
|
212
|
+
function useForceUpdate() {
|
|
213
|
+
const [, dispatch] = useReducer((x) => x + 1, 0);
|
|
214
|
+
return dispatch;
|
|
215
|
+
}
|
|
224
216
|
//#endregion
|
|
225
217
|
//#region src/hooks/use-keymap.ts
|
|
226
218
|
function useKeymap(keymap, options) {
|
|
227
219
|
useExtension(useMemo(() => defineKeymap(keymap), [keymap]), options);
|
|
228
220
|
}
|
|
229
|
-
|
|
230
221
|
//#endregion
|
|
231
222
|
//#region src/hooks/use-state-update.ts
|
|
232
223
|
/**
|
|
@@ -238,7 +229,7 @@ function useStateUpdate(handler, options) {
|
|
|
238
229
|
const memoizedHandler = useEventCallback(handler);
|
|
239
230
|
useExtension(useMemo(() => defineUpdateHandler((view) => memoizedHandler(view.state)), [memoizedHandler]), options);
|
|
240
231
|
}
|
|
241
|
-
|
|
242
232
|
//#endregion
|
|
243
233
|
export { ProseKit, defineReactMarkView, defineReactNodeView, useDocChange, useEditor, useEditorDerivedValue, useExtension, useKeymap, useStateUpdate };
|
|
234
|
+
|
|
244
235
|
//# sourceMappingURL=prosekit-react.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prosekit-react.js","names":[],"sources":["../src/hooks/use-editor-extension.ts","../src/hooks/use-priority-extension.ts","../src/hooks/use-extension.ts","../src/extensions/react-mark-view.ts","../src/extensions/react-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 'react'\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 'react'\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 ReactMarkViewUserOptions } from '@prosemirror-adapter/react'\nimport { createElement, useMemo, type ComponentType, type FC } from 'react'\n\nimport { useExtension } from '../hooks/use-extension'\n\n/**\n * @public\n */\nexport interface ReactMarkViewProps extends MarkViewContext {}\n\n/**\n * @public\n */\nexport type ReactMarkViewComponent = ComponentType<ReactMarkViewProps>\n\n/**\n * Options for {@link defineReactMarkView}.\n *\n * @public\n */\nexport interface ReactMarkViewOptions extends CoreMarkViewUserOptions<ReactMarkViewComponent> {\n /**\n * The name of the mark type.\n */\n name: string\n}\n\nfunction withMarkViewProps(component: ReactMarkViewComponent) {\n return function MarkViewPropsWrapper() {\n const props: ReactMarkViewProps = useMarkViewContext()\n return createElement(component, props)\n }\n}\n\n/**\n * @internal\n */\nexport const ReactMarkViewConsumer: FC = () => {\n const markViewFactory = useMarkViewFactory()\n const extension = useMemo(\n () => defineReactMarkViewFactory(markViewFactory),\n [markViewFactory],\n )\n useExtension(extension)\n\n return null\n}\n\n/**\n * Defines a mark view using a React component.\n *\n * @public\n */\nexport function defineReactMarkView(options: ReactMarkViewOptions): Extension {\n const { name, component, ...userOptions } = options\n\n const args: ReactMarkViewUserOptions = {\n ...userOptions,\n component: withMarkViewProps(component),\n }\n\n return defineMarkViewComponent<ReactMarkViewUserOptions>({\n group: 'react',\n name,\n args,\n })\n}\n\nfunction defineReactMarkViewFactory(\n factory: (options: ReactMarkViewUserOptions) => MarkViewConstructor,\n) {\n return defineMarkViewFactory<ReactMarkViewUserOptions>({\n group: 'react',\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 ReactNodeViewUserOptions } from '@prosemirror-adapter/react'\nimport { createElement, useMemo, type ComponentType, type FC } from 'react'\n\nimport { useExtension } from '../hooks/use-extension'\n\n/**\n * @public\n */\nexport interface ReactNodeViewProps extends NodeViewContext {}\n\n/**\n * @public\n */\nexport type ReactNodeViewComponent = ComponentType<ReactNodeViewProps>\n\n/**\n * Options for {@link defineReactNodeView}.\n *\n * @public\n */\nexport interface ReactNodeViewOptions extends CoreNodeViewUserOptions<ReactNodeViewComponent> {\n /**\n * The name of the node type.\n */\n name: string\n}\n\nfunction withNodeViewProps(component: ReactNodeViewComponent) {\n return function NodeViewPropsWrapper() {\n const props: ReactNodeViewProps = useNodeViewContext()\n return createElement(component, props)\n }\n}\n\n/**\n * @internal\n */\nexport const ReactNodeViewConsumer: FC = () => {\n const nodeViewFactory = useNodeViewFactory()\n const extension = useMemo(\n () => defineReactNodeViewFactory(nodeViewFactory),\n [nodeViewFactory],\n )\n useExtension(extension)\n\n return null\n}\n\n/**\n * Defines a node view using a React component.\n *\n * @public\n */\nexport function defineReactNodeView(options: ReactNodeViewOptions): Extension {\n const { name, component, ...userOptions } = options\n\n const args: ReactNodeViewUserOptions = {\n ...userOptions,\n component: withNodeViewProps(component),\n }\n\n return defineNodeViewComponent<ReactNodeViewUserOptions>({\n group: 'react',\n name,\n args,\n })\n}\n\nfunction defineReactNodeViewFactory(\n factory: (options: ReactNodeViewUserOptions) => NodeViewConstructor,\n) {\n return defineNodeViewFactory<ReactNodeViewUserOptions>({\n group: 'react',\n factory,\n })\n}\n","import type { Editor } from '@prosekit/core'\nimport { ProsemirrorAdapterProvider } from '@prosemirror-adapter/react'\nimport { createElement, type ComponentType, type ReactNode } from 'react'\n\nimport { EditorContextProvider } from '../contexts/editor-context'\nimport { ReactMarkViewConsumer } from '../extensions/react-mark-view'\nimport { ReactNodeViewConsumer } from '../extensions/react-node-view'\n\nexport interface ProseKitProps {\n editor: Editor\n children?: ReactNode\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 ProsemirrorAdapterProvider,\n null,\n createElement(ReactNodeViewConsumer),\n createElement(ReactMarkViewConsumer),\n children,\n ),\n )\n}\n","import { useCallback, useLayoutEffect, useRef } from 'react'\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 'react'\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 'react'\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 * Note this this option doesn't work with [React\n * compiler](https://react.dev/learn/react-compiler) because the returned\n * editor will be the same instance after state updates. If you're using React\n * compiler, you should use {@link useEditorDerivedValue} instead.\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 { useMemo, useSyncExternalStore } from 'react'\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, 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 'react'\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 'react'\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":"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"}
|
|
1
|
+
{"version":3,"file":"prosekit-react.js","names":[],"sources":["../src/extensions/react-mark-view.ts","../src/extensions/react-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 AbstractReactMarkView,\n buildReactMarkViewCreator,\n type MarkViewContext,\n type ReactRendererResult,\n} from '@prosemirror-adapter/react'\nimport { createElement, type ComponentType, type ReactPortal } from 'react'\nimport { createPortal } from 'react-dom'\n\n/**\n * @public\n */\nexport interface ReactMarkViewProps extends MarkViewContext {}\n\n/**\n * @public\n */\nexport type ReactMarkViewComponent = ComponentType<ReactMarkViewProps>\n\n/**\n * Options for {@link defineReactMarkView}.\n *\n * @public\n */\nexport interface ReactMarkViewOptions extends CoreMarkViewUserOptions<ReactMarkViewComponent> {\n /**\n * The name of the mark type.\n */\n name: string\n}\n\nclass ProseKitReactMarkView extends AbstractReactMarkView<ReactMarkViewComponent> {\n render = (): ReactPortal => {\n const UserComponent = this.component\n const props = { ...this.context }\n return createPortal(\n createElement(UserComponent, props),\n this.dom,\n this.key,\n )\n }\n}\n\n/**\n * @internal\n */\nexport function defineReactMarkViewFactory(\n renderReactRenderer: ReactRendererResult['renderReactRenderer'],\n removeReactRenderer: ReactRendererResult['removeReactRenderer'],\n): Extension {\n const factory = buildReactMarkViewCreator(renderReactRenderer, removeReactRenderer, ProseKitReactMarkView)\n return defineMarkViewFactory<ReactMarkViewOptions>({\n group: 'react',\n factory,\n })\n}\n\n/**\n * Defines a mark view using a React component.\n *\n * @public\n */\nexport function defineReactMarkView(options: ReactMarkViewOptions): Extension {\n return defineMarkViewComponent<ReactMarkViewOptions>({\n group: 'react',\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 AbstractReactNodeView,\n buildReactNodeViewCreator,\n type NodeViewContext,\n type ReactRendererResult,\n} from '@prosemirror-adapter/react'\nimport { createElement, type ComponentType, type ReactPortal } from 'react'\nimport { createPortal } from 'react-dom'\n\n/**\n * @public\n */\nexport interface ReactNodeViewProps extends NodeViewContext {}\n\n/**\n * @public\n */\nexport type ReactNodeViewComponent = ComponentType<ReactNodeViewProps>\n\n/**\n * Options for {@link defineReactNodeView}.\n *\n * @public\n */\nexport interface ReactNodeViewOptions extends CoreNodeViewUserOptions<ReactNodeViewComponent> {\n /**\n * The name of the node type.\n */\n name: string\n}\n\nclass ProseKitReactNodeView extends AbstractReactNodeView<ReactNodeViewComponent> {\n render = (): ReactPortal => {\n const UserComponent = this.component\n const props = { ...this.context }\n return createPortal(\n createElement(UserComponent, props),\n this.dom,\n this.key,\n )\n }\n}\n\n/**\n * @internal\n */\nexport function defineReactNodeViewFactory(\n renderReactRenderer: ReactRendererResult['renderReactRenderer'],\n removeReactRenderer: ReactRendererResult['removeReactRenderer'],\n): Extension {\n const factory = buildReactNodeViewCreator(renderReactRenderer, removeReactRenderer, ProseKitReactNodeView)\n return defineNodeViewFactory<ReactNodeViewOptions>({\n group: 'react',\n factory,\n })\n}\n\n/**\n * Defines a node view using a React component.\n *\n * @public\n */\nexport function defineReactNodeView(options: ReactNodeViewOptions): Extension {\n return defineNodeViewComponent<ReactNodeViewOptions>({\n group: 'react',\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 'react'\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 { useReactRenderer } from '@prosemirror-adapter/react'\nimport { createElement, Fragment, useMemo, type ComponentType, type ReactNode } from 'react'\n\nimport { defineReactMarkViewFactory } from '../extensions/react-mark-view.ts'\nimport { defineReactNodeViewFactory } from '../extensions/react-node-view.ts'\nimport { useEditorExtension } from '../hooks/use-editor-extension.ts'\n\ninterface ViewRendererProps {\n editor: Editor\n children: ReactNode\n}\n\nexport const ViewRenderer: ComponentType<ViewRendererProps> = ({ editor, children }): ReactNode => {\n const { renderReactRenderer, removeReactRenderer, render } = useReactRenderer()\n\n const extension = useMemo(() => {\n return union([\n defineReactMarkViewFactory(renderReactRenderer, removeReactRenderer),\n defineReactNodeViewFactory(renderReactRenderer, removeReactRenderer),\n ])\n }, [renderReactRenderer, removeReactRenderer])\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 ComponentType, type ReactNode } from 'react'\n\nimport { EditorContextProvider } from '../contexts/editor-context.ts'\n\nimport { ViewRenderer } from './view-renderer.ts'\n\nexport interface ProseKitProps {\n editor: Editor\n children?: ReactNode\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 'react'\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 'react'\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 'react'\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 { useMemo, useSyncExternalStore } from 'react'\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, 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 'react'\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 * Note this this option doesn't work with [React\n * compiler](https://react.dev/learn/react-compiler) because the returned\n * editor will be the same instance after state updates. If you're using React\n * compiler, you should use {@link useEditorDerivedValue} instead.\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 'react'\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 'react'\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":"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"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prosekit/react",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.6.
|
|
4
|
+
"version": "0.6.9",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "React 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/react": "^0.5.
|
|
73
|
-
"@prosekit/core": "^0.
|
|
74
|
-
"@prosekit/
|
|
75
|
-
"@prosekit/
|
|
71
|
+
"@prosemirror-adapter/core": "^0.5.2",
|
|
72
|
+
"@prosemirror-adapter/react": "^0.5.2",
|
|
73
|
+
"@prosekit/core": "^0.11.0",
|
|
74
|
+
"@prosekit/web": "^0.7.13",
|
|
75
|
+
"@prosekit/pm": "^0.1.15"
|
|
76
76
|
},
|
|
77
77
|
"peerDependencies": {
|
|
78
78
|
"react": ">= 18.2.0",
|
|
@@ -91,8 +91,9 @@
|
|
|
91
91
|
"@types/react-dom": "^19.2.3",
|
|
92
92
|
"react": "^19.2.4",
|
|
93
93
|
"react-dom": "^19.2.4",
|
|
94
|
-
"tsdown": "^0.
|
|
94
|
+
"tsdown": "^0.21.4",
|
|
95
95
|
"typescript": "~5.9.3",
|
|
96
|
+
"@prosekit/config-ts": "0.0.0",
|
|
96
97
|
"@prosekit/config-tsdown": "0.0.0",
|
|
97
98
|
"@prosekit/config-vitest": "0.0.0"
|
|
98
99
|
},
|
|
@@ -11,20 +11,20 @@ import type {
|
|
|
11
11
|
RefAttributes,
|
|
12
12
|
} from 'react'
|
|
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
|
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 'react'
|
|
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
|
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 'react'
|
|
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
|
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 'react'
|
|
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
|
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 'react'
|
|
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
|
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 'react'
|
|
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
|
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 'react'
|
|
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
|
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'
|
|
@@ -12,9 +12,9 @@ import {
|
|
|
12
12
|
type RefAttributes,
|
|
13
13
|
} from 'react'
|
|
14
14
|
|
|
15
|
-
import { useEditorContext } from '../contexts/editor-context'
|
|
15
|
+
import { useEditorContext } from '../contexts/editor-context.ts'
|
|
16
16
|
|
|
17
|
-
import { mergeRefs } from './merge-refs'
|
|
17
|
+
import { mergeRefs } from './merge-refs.ts'
|
|
18
18
|
|
|
19
19
|
const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect
|
|
20
20
|
|
|
@@ -86,7 +86,6 @@ export function createComponent<
|
|
|
86
86
|
for (const [name, value] of Object.entries(properties)) {
|
|
87
87
|
if (value !== undefined) {
|
|
88
88
|
// @ts-expect-error: we know that name is a valid property name
|
|
89
|
-
// eslint-disable-next-line react-hooks/immutability
|
|
90
89
|
el[name] = value
|
|
91
90
|
}
|
|
92
91
|
}
|