@prosekit/react 0.4.12 → 0.4.13

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.
@@ -1,236 +1,193 @@
1
- import {
2
- EditorContextProvider,
3
- useEditorContext
4
- } from "./chunk-BV2MZRRU.js";
1
+ import { EditorContextProvider, useEditorContext } from "./editor-context-Cci4uqN_.js";
2
+ import { ProsemirrorAdapterProvider, useMarkViewContext, useMarkViewFactory, useNodeViewContext, useNodeViewFactory } from "@prosemirror-adapter/react";
3
+ import { createElement, useEffect, useMemo, useReducer } from "react";
4
+ import { EditorNotFoundError, ProseKitError, defineDocChangeHandler, defineKeymap, defineMarkViewComponent, defineMarkViewFactory, defineMountHandler, defineNodeViewComponent, defineNodeViewFactory, defineUpdateHandler, union, withPriority } from "@prosekit/core";
5
5
 
6
- // src/components/prosekit.ts
7
- import { ProsemirrorAdapterProvider } from "@prosemirror-adapter/react";
8
- import {
9
- createElement as createElement3
10
- } from "react";
11
-
12
- // src/extensions/react-mark-view.ts
13
- import {
14
- defineMarkViewComponent,
15
- defineMarkViewFactory
16
- } from "@prosekit/core";
17
- import {
18
- useMarkViewContext,
19
- useMarkViewFactory
20
- } from "@prosemirror-adapter/react";
21
- import {
22
- createElement,
23
- useMemo as useMemo2
24
- } from "react";
25
-
26
- // src/hooks/use-editor-extension.ts
27
- import {
28
- EditorNotFoundError
29
- } from "@prosekit/core";
30
- import { useEffect } from "react";
6
+ //#region src/hooks/use-editor-extension.ts
7
+ /**
8
+ * @internal
9
+ */
31
10
  function useEditorExtension(editor, extension) {
32
- if (!editor) {
33
- throw new EditorNotFoundError();
34
- }
35
- useEffect(() => {
36
- if (extension) {
37
- return editor.use(extension);
38
- }
39
- }, [editor, extension]);
11
+ if (!editor) throw new EditorNotFoundError();
12
+ useEffect(() => {
13
+ if (extension) return editor.use(extension);
14
+ }, [editor, extension]);
40
15
  }
41
16
 
42
- // src/hooks/use-priority-extension.ts
43
- import {
44
- withPriority
45
- } from "@prosekit/core";
46
- import { useMemo } from "react";
17
+ //#endregion
18
+ //#region src/hooks/use-priority-extension.ts
19
+ /**
20
+ * @internal
21
+ */
47
22
  function usePriorityExtension(extension, priority) {
48
- return useMemo(() => {
49
- return extension && priority ? withPriority(extension, priority) : extension;
50
- }, [extension, priority]);
23
+ return useMemo(() => {
24
+ return extension && priority ? withPriority(extension, priority) : extension;
25
+ }, [extension, priority]);
51
26
  }
52
27
 
53
- // src/hooks/use-extension.ts
28
+ //#endregion
29
+ //#region src/hooks/use-extension.ts
30
+ /**
31
+ * Add an extension to the editor.
32
+ */
54
33
  function useExtension(extension, options) {
55
- const editorContext = useEditorContext();
56
- useEditorExtension(
57
- options?.editor || editorContext,
58
- usePriorityExtension(extension, options?.priority)
59
- );
34
+ const editorContext = useEditorContext();
35
+ useEditorExtension(options?.editor || editorContext, usePriorityExtension(extension, options?.priority));
60
36
  }
61
37
 
62
- // src/extensions/react-mark-view.ts
38
+ //#endregion
39
+ //#region src/extensions/react-mark-view.ts
63
40
  function withMarkViewProps(component) {
64
- return function MarkViewPropsWrapper() {
65
- const props = useMarkViewContext();
66
- return createElement(component, props);
67
- };
41
+ return function MarkViewPropsWrapper() {
42
+ const props = useMarkViewContext();
43
+ return createElement(component, props);
44
+ };
68
45
  }
69
- var ReactMarkViewConsumer = () => {
70
- const markViewFactory = useMarkViewFactory();
71
- const extension = useMemo2(
72
- () => defineReactMarkViewFactory(markViewFactory),
73
- [markViewFactory]
74
- );
75
- useExtension(extension);
76
- return null;
46
+ /**
47
+ * @internal
48
+ */
49
+ const ReactMarkViewConsumer = () => {
50
+ const markViewFactory = useMarkViewFactory();
51
+ const extension = useMemo(() => defineReactMarkViewFactory(markViewFactory), [markViewFactory]);
52
+ useExtension(extension);
53
+ return null;
77
54
  };
55
+ /**
56
+ * Defines a mark view using a React component.
57
+ *
58
+ * @public
59
+ */
78
60
  function defineReactMarkView(options) {
79
- const { name, component, ...userOptions } = options;
80
- const args = {
81
- ...userOptions,
82
- component: withMarkViewProps(component)
83
- };
84
- return defineMarkViewComponent({
85
- group: "react",
86
- name,
87
- args
88
- });
61
+ const { name, component,...userOptions } = options;
62
+ const args = {
63
+ ...userOptions,
64
+ component: withMarkViewProps(component)
65
+ };
66
+ return defineMarkViewComponent({
67
+ group: "react",
68
+ name,
69
+ args
70
+ });
89
71
  }
90
72
  function defineReactMarkViewFactory(factory) {
91
- return defineMarkViewFactory({
92
- group: "react",
93
- factory
94
- });
73
+ return defineMarkViewFactory({
74
+ group: "react",
75
+ factory
76
+ });
95
77
  }
96
78
 
97
- // src/extensions/react-node-view.ts
98
- import {
99
- defineNodeViewComponent,
100
- defineNodeViewFactory
101
- } from "@prosekit/core";
102
- import {
103
- useNodeViewContext,
104
- useNodeViewFactory
105
- } from "@prosemirror-adapter/react";
106
- import {
107
- createElement as createElement2,
108
- useMemo as useMemo3
109
- } from "react";
79
+ //#endregion
80
+ //#region src/extensions/react-node-view.ts
110
81
  function withNodeViewProps(component) {
111
- return function NodeViewPropsWrapper() {
112
- const props = useNodeViewContext();
113
- return createElement2(component, props);
114
- };
82
+ return function NodeViewPropsWrapper() {
83
+ const props = useNodeViewContext();
84
+ return createElement(component, props);
85
+ };
115
86
  }
116
- var ReactNodeViewConsumer = () => {
117
- const nodeViewFactory = useNodeViewFactory();
118
- const extension = useMemo3(
119
- () => defineReactNodeViewFactory(nodeViewFactory),
120
- [nodeViewFactory]
121
- );
122
- useExtension(extension);
123
- return null;
87
+ /**
88
+ * @internal
89
+ */
90
+ const ReactNodeViewConsumer = () => {
91
+ const nodeViewFactory = useNodeViewFactory();
92
+ const extension = useMemo(() => defineReactNodeViewFactory(nodeViewFactory), [nodeViewFactory]);
93
+ useExtension(extension);
94
+ return null;
124
95
  };
96
+ /**
97
+ * Defines a node view using a React component.
98
+ *
99
+ * @public
100
+ */
125
101
  function defineReactNodeView(options) {
126
- const { name, component, ...userOptions } = options;
127
- const args = {
128
- ...userOptions,
129
- component: withNodeViewProps(component)
130
- };
131
- return defineNodeViewComponent({
132
- group: "react",
133
- name,
134
- args
135
- });
102
+ const { name, component,...userOptions } = options;
103
+ const args = {
104
+ ...userOptions,
105
+ component: withNodeViewProps(component)
106
+ };
107
+ return defineNodeViewComponent({
108
+ group: "react",
109
+ name,
110
+ args
111
+ });
136
112
  }
137
113
  function defineReactNodeViewFactory(factory) {
138
- return defineNodeViewFactory({
139
- group: "react",
140
- factory
141
- });
114
+ return defineNodeViewFactory({
115
+ group: "react",
116
+ factory
117
+ });
142
118
  }
143
119
 
144
- // src/components/prosekit.ts
145
- var ProseKit = (props) => {
146
- const { editor, children } = props;
147
- return createElement3(
148
- ProsemirrorAdapterProvider,
149
- null,
150
- createElement3(
151
- EditorContextProvider,
152
- { value: editor },
153
- createElement3(ReactNodeViewConsumer),
154
- createElement3(ReactMarkViewConsumer),
155
- children
156
- )
157
- );
120
+ //#endregion
121
+ //#region src/components/prosekit.ts
122
+ /**
123
+ * The root component for a ProseKit editor.
124
+ *
125
+ * @public
126
+ */
127
+ const ProseKit = (props) => {
128
+ const { editor, children } = props;
129
+ return createElement(ProsemirrorAdapterProvider, null, createElement(EditorContextProvider, { value: editor }, createElement(ReactNodeViewConsumer), createElement(ReactMarkViewConsumer), children));
158
130
  };
159
131
 
160
- // src/hooks/use-doc-change.ts
161
- import { defineDocChangeHandler } from "@prosekit/core";
162
- import { useMemo as useMemo4 } from "react";
132
+ //#endregion
133
+ //#region src/hooks/use-doc-change.ts
134
+ /**
135
+ * Calls the given handler whenever the editor document changes.
136
+ *
137
+ * @public
138
+ */
163
139
  function useDocChange(handler, options) {
164
- const extension = useMemo4(
165
- () => defineDocChangeHandler((view) => handler(view.state.doc)),
166
- [handler]
167
- );
168
- return useExtension(extension, options);
140
+ const extension = useMemo(() => defineDocChangeHandler((view) => handler(view.state.doc)), [handler]);
141
+ useExtension(extension, options);
169
142
  }
170
143
 
171
- // src/hooks/use-editor.ts
172
- import {
173
- defineMountHandler,
174
- defineUpdateHandler,
175
- ProseKitError,
176
- union
177
- } from "@prosekit/core";
178
- import {
179
- useEffect as useEffect2,
180
- useReducer
181
- } from "react";
144
+ //#endregion
145
+ //#region src/hooks/use-editor.ts
146
+ /**
147
+ * Retrieves the editor instance from the nearest ProseKit component.
148
+ *
149
+ * @public
150
+ */
182
151
  function useEditor(options) {
183
- const update = options?.update ?? false;
184
- const editor = useEditorContext();
185
- if (!editor) {
186
- throw new ProseKitError(
187
- "useEditor must be used within the ProseKit component"
188
- );
189
- }
190
- const forceUpdate = useForceUpdate();
191
- useEffect2(() => {
192
- if (update) {
193
- const extension = union(
194
- defineMountHandler(forceUpdate),
195
- defineUpdateHandler(forceUpdate)
196
- );
197
- return editor.use(extension);
198
- }
199
- }, [editor, update, forceUpdate]);
200
- return editor;
152
+ const update = options?.update ?? false;
153
+ const editor = useEditorContext();
154
+ if (!editor) throw new ProseKitError("useEditor must be used within the ProseKit component");
155
+ const forceUpdate = useForceUpdate();
156
+ useEffect(() => {
157
+ if (update) {
158
+ const extension = union(defineMountHandler(forceUpdate), defineUpdateHandler(forceUpdate));
159
+ return editor.use(extension);
160
+ }
161
+ }, [
162
+ editor,
163
+ update,
164
+ forceUpdate
165
+ ]);
166
+ return editor;
201
167
  }
202
168
  function useForceUpdate() {
203
- const [, dispatch] = useReducer((x) => x + 1, 0);
204
- return dispatch;
169
+ const [, dispatch] = useReducer((x) => x + 1, 0);
170
+ return dispatch;
205
171
  }
206
172
 
207
- // src/hooks/use-keymap.ts
208
- import {
209
- defineKeymap
210
- } from "@prosekit/core";
211
- import { useMemo as useMemo5 } from "react";
173
+ //#endregion
174
+ //#region src/hooks/use-keymap.ts
212
175
  function useKeymap(keymap, options) {
213
- const extension = useMemo5(() => defineKeymap(keymap), [keymap]);
214
- return useExtension(extension, options);
176
+ const extension = useMemo(() => defineKeymap(keymap), [keymap]);
177
+ useExtension(extension, options);
215
178
  }
216
179
 
217
- // src/hooks/use-state-update.ts
218
- import { defineUpdateHandler as defineUpdateHandler2 } from "@prosekit/core";
219
- import { useMemo as useMemo6 } from "react";
180
+ //#endregion
181
+ //#region src/hooks/use-state-update.ts
182
+ /**
183
+ * Calls the given handler whenever the editor state changes.
184
+ *
185
+ * @public
186
+ */
220
187
  function useStateUpdate(handler, options) {
221
- const extension = useMemo6(
222
- () => defineUpdateHandler2((view) => handler(view.state)),
223
- [handler]
224
- );
225
- return useExtension(extension, options);
188
+ const extension = useMemo(() => defineUpdateHandler((view) => handler(view.state)), [handler]);
189
+ useExtension(extension, options);
226
190
  }
227
- export {
228
- ProseKit,
229
- defineReactMarkView,
230
- defineReactNodeView,
231
- useDocChange,
232
- useEditor,
233
- useExtension,
234
- useKeymap,
235
- useStateUpdate
236
- };
191
+
192
+ //#endregion
193
+ export { ProseKit, defineReactMarkView, defineReactNodeView, useDocChange, useEditor, useExtension, useKeymap, useStateUpdate };
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@prosekit/react",
3
3
  "type": "module",
4
- "version": "0.4.12",
4
+ "version": "0.4.13",
5
5
  "private": false,
6
+ "description": "React components and utilities for ProseKit",
6
7
  "author": {
7
8
  "name": "ocavue",
8
9
  "email": "ocavue@gmail.com"
@@ -64,10 +65,10 @@
64
65
  "dependencies": {
65
66
  "@prosemirror-adapter/core": "^0.4.0",
66
67
  "@prosemirror-adapter/react": "^0.4.1",
67
- "react-merge-refs": "^2.1.1",
68
- "@prosekit/core": "^0.8.0",
69
- "@prosekit/pm": "^0.1.9",
70
- "@prosekit/web": "^0.5.7"
68
+ "react-merge-refs": "^3.0.1",
69
+ "@prosekit/core": "^0.8.1",
70
+ "@prosekit/pm": "^0.1.10",
71
+ "@prosekit/web": "^0.5.8"
71
72
  },
72
73
  "peerDependencies": {
73
74
  "react": ">= 18.2.0",
@@ -82,18 +83,34 @@
82
83
  }
83
84
  },
84
85
  "devDependencies": {
85
- "@types/react": "^19.0.12",
86
- "@types/react-dom": "^19.0.4",
87
- "react": "^19.0.0",
88
- "react-dom": "^19.0.0",
89
- "tsup": "^8.4.0",
90
- "typescript": "~5.7.3",
91
- "vitest": "^3.0.9",
92
- "@prosekit/dev": "0.0.0"
86
+ "@types/react": "^19.1.3",
87
+ "@types/react-dom": "^19.1.3",
88
+ "react": "^19.1.0",
89
+ "react-dom": "^19.1.0",
90
+ "tsdown": "^0.11.1",
91
+ "typescript": "~5.8.3",
92
+ "vitest": "^3.1.3",
93
+ "@prosekit/config-tsdown": "0.0.0",
94
+ "@prosekit/config-vitest": "0.0.0"
95
+ },
96
+ "publishConfig": {
97
+ "dev": {}
98
+ },
99
+ "dev": {
100
+ "entry": {
101
+ "prosekit-react": "./src/index.ts",
102
+ "prosekit-react-autocomplete": "./src/components/autocomplete/index.gen.ts",
103
+ "prosekit-react-block-handle": "./src/components/block-handle/index.gen.ts",
104
+ "prosekit-react-inline-popover": "./src/components/inline-popover/index.gen.ts",
105
+ "prosekit-react-popover": "./src/components/popover/index.gen.ts",
106
+ "prosekit-react-resizable": "./src/components/resizable/index.gen.ts",
107
+ "prosekit-react-table-handle": "./src/components/table-handle/index.gen.ts",
108
+ "prosekit-react-tooltip": "./src/components/tooltip/index.gen.ts"
109
+ }
93
110
  },
94
111
  "scripts": {
95
112
  "build:tsc": "tsc -b tsconfig.json",
96
- "build:tsup": "tsup"
113
+ "build:tsdown": "tsdown"
97
114
  },
98
115
  "types": "./dist/prosekit-react.d.ts",
99
116
  "typesVersions": {