@prosekit/react 0.4.5 → 0.4.6

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,4 +1,3 @@
1
- import type { Attrs } from '@prosekit/pm/model';
2
1
  import { AutocompleteEmptyElement } from '@prosekit/web/autocomplete';
3
2
  import { AutocompleteEmptyEvents } from '@prosekit/web/autocomplete';
4
3
  import { AutocompleteEmptyProps as AutocompleteEmptyProps_2 } from '@prosekit/web/autocomplete';
@@ -11,7 +10,6 @@ import { AutocompleteListProps as AutocompleteListProps_2 } from '@prosekit/web/
11
10
  import { AutocompletePopoverElement } from '@prosekit/web/autocomplete';
12
11
  import { AutocompletePopoverEvents } from '@prosekit/web/autocomplete';
13
12
  import { AutocompletePopoverProps as AutocompletePopoverProps_2 } from '@prosekit/web/autocomplete';
14
- import { BaseNodeViewOptions } from '@prosekit/core';
15
13
  import { BlockHandleAddElement } from '@prosekit/web/block-handle';
16
14
  import { BlockHandleAddEvents } from '@prosekit/web/block-handle';
17
15
  import { BlockHandleAddProps as BlockHandleAddProps_2 } from '@prosekit/web/block-handle';
@@ -22,12 +20,11 @@ import { BlockHandlePopoverElement } from '@prosekit/web/block-handle';
22
20
  import { BlockHandlePopoverEvents } from '@prosekit/web/block-handle';
23
21
  import { BlockHandlePopoverProps as BlockHandlePopoverProps_2 } from '@prosekit/web/block-handle';
24
22
  import { ComponentType } from 'react';
25
- import type { Decoration } from '@prosekit/pm/view';
26
- import type { DecorationSource } from '@prosekit/pm/view';
23
+ import type { CoreMarkViewUserOptions } from '@prosemirror-adapter/core';
24
+ import type { CoreNodeViewUserOptions } from '@prosemirror-adapter/core';
27
25
  import { config as default_alias_1 } from '@prosekit/dev/config-vitest';
28
26
  import { Editor } from '@prosekit/core';
29
27
  import type { EditorState } from '@prosekit/pm/state';
30
- import type { EditorView } from '@prosekit/pm/view';
31
28
  import { Extension } from '@prosekit/core';
32
29
  import { FC } from 'react';
33
30
  import { ForwardRefExoticComponent } from 'react';
@@ -36,6 +33,8 @@ import { InlinePopoverElement } from '@prosekit/web/inline-popover';
36
33
  import { InlinePopoverEvents } from '@prosekit/web/inline-popover';
37
34
  import { InlinePopoverProps as InlinePopoverProps_2 } from '@prosekit/web/inline-popover';
38
35
  import { Keymap } from '@prosekit/core';
36
+ import { MarkViewContext } from '@prosemirror-adapter/react';
37
+ import { NodeViewContext } from '@prosemirror-adapter/react';
39
38
  import { Options } from 'tsup';
40
39
  import { PopoverContentElement } from '@prosekit/web/popover';
41
40
  import { PopoverContentEvents } from '@prosekit/web/popover';
@@ -190,6 +189,15 @@ export declare const default_alias: Options | Options[] | ((overrideOptions: Opt
190
189
 
191
190
  export { default_alias_1 }
192
191
 
192
+ /**
193
+ * Defines a mark view using a React component.
194
+ *
195
+ * @public
196
+ */
197
+ declare function defineReactMarkView(options: ReactMarkViewOptions): Extension;
198
+ export { defineReactMarkView }
199
+ export { defineReactMarkView as defineReactMarkView_alias_1 }
200
+
193
201
  /**
194
202
  * Defines a node view using a React component.
195
203
  *
@@ -277,6 +285,40 @@ declare interface ProseKitProps {
277
285
  export { ProseKitProps }
278
286
  export { ProseKitProps as ProseKitProps_alias_1 }
279
287
 
288
+ /**
289
+ * @public
290
+ */
291
+ declare type ReactMarkViewComponent = ComponentType<ReactMarkViewProps>;
292
+ export { ReactMarkViewComponent }
293
+ export { ReactMarkViewComponent as ReactMarkViewComponent_alias_1 }
294
+
295
+ /**
296
+ * @internal
297
+ */
298
+ export declare const ReactMarkViewConsumer: FC;
299
+
300
+ /**
301
+ * Options for {@link defineReactMarkView}.
302
+ *
303
+ * @public
304
+ */
305
+ declare interface ReactMarkViewOptions extends CoreMarkViewUserOptions<ReactMarkViewComponent> {
306
+ /**
307
+ * The name of the mark type.
308
+ */
309
+ name: string;
310
+ }
311
+ export { ReactMarkViewOptions }
312
+ export { ReactMarkViewOptions as ReactMarkViewOptions_alias_1 }
313
+
314
+ /**
315
+ * @public
316
+ */
317
+ declare interface ReactMarkViewProps extends MarkViewContext {
318
+ }
319
+ export { ReactMarkViewProps }
320
+ export { ReactMarkViewProps as ReactMarkViewProps_alias_1 }
321
+
280
322
  /**
281
323
  * @public
282
324
  */
@@ -284,20 +326,21 @@ declare type ReactNodeViewComponent = ComponentType<ReactNodeViewProps>;
284
326
  export { ReactNodeViewComponent }
285
327
  export { ReactNodeViewComponent as ReactNodeViewComponent_alias_1 }
286
328
 
329
+ /**
330
+ * @internal
331
+ */
332
+ export declare const ReactNodeViewConsumer: FC;
333
+
287
334
  /**
288
335
  * Options for {@link defineReactNodeView}.
289
336
  *
290
337
  * @public
291
338
  */
292
- declare interface ReactNodeViewOptions extends BaseNodeViewOptions {
339
+ declare interface ReactNodeViewOptions extends CoreNodeViewUserOptions<ReactNodeViewComponent> {
293
340
  /**
294
341
  * The name of the node type.
295
342
  */
296
343
  name: string;
297
- /**
298
- * The React component to render the node.
299
- */
300
- component: ReactNodeViewComponent;
301
344
  }
302
345
  export { ReactNodeViewOptions }
303
346
  export { ReactNodeViewOptions as ReactNodeViewOptions_alias_1 }
@@ -305,24 +348,11 @@ export { ReactNodeViewOptions as ReactNodeViewOptions_alias_1 }
305
348
  /**
306
349
  * @public
307
350
  */
308
- declare interface ReactNodeViewProps {
309
- contentRef: (node: HTMLElement | null) => void;
310
- view: EditorView;
311
- getPos: () => number | undefined;
312
- setAttrs: (attrs: Attrs) => void;
313
- node: ProseMirrorNode;
314
- selected: boolean;
315
- decorations: readonly Decoration[];
316
- innerDecorations: DecorationSource;
351
+ declare interface ReactNodeViewProps extends NodeViewContext {
317
352
  }
318
353
  export { ReactNodeViewProps }
319
354
  export { ReactNodeViewProps as ReactNodeViewProps_alias_1 }
320
355
 
321
- /**
322
- * @internal
323
- */
324
- export declare const ReactViewsConsumer: FC;
325
-
326
356
  declare const ResizableHandle: ForwardRefExoticComponent<ResizableHandleProps & RefAttributes<ResizableHandleElement> & HTMLAttributes<ResizableHandleElement>>;
327
357
  export { ResizableHandle }
328
358
  export { ResizableHandle as ResizableHandle_alias_1 }
@@ -1,5 +1,8 @@
1
1
  // src/contexts/editor-context.ts
2
- import { createContext, useContext } from "react";
2
+ import {
3
+ createContext,
4
+ useContext
5
+ } from "react";
3
6
  var editorContext = createContext(null);
4
7
  function useEditorContext() {
5
8
  return useContext(editorContext);
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  useEditorContext
3
- } from "./chunk-BH56NR2Q.js";
3
+ } from "./chunk-BV2MZRRU.js";
4
4
 
5
5
  // src/components/create-component.ts
6
6
  import {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  createComponent
3
- } from "./chunk-E43DMYRE.js";
4
- import "./chunk-BH56NR2Q.js";
3
+ } from "./chunk-IO5VSPOS.js";
4
+ import "./chunk-BV2MZRRU.js";
5
5
 
6
6
  // src/components/autocomplete/autocomplete-empty.gen.ts
7
7
  import {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  createComponent
3
- } from "./chunk-E43DMYRE.js";
4
- import "./chunk-BH56NR2Q.js";
3
+ } from "./chunk-IO5VSPOS.js";
4
+ import "./chunk-BV2MZRRU.js";
5
5
 
6
6
  // src/components/block-handle/block-handle-add.gen.ts
7
7
  import {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  createComponent
3
- } from "./chunk-E43DMYRE.js";
4
- import "./chunk-BH56NR2Q.js";
3
+ } from "./chunk-IO5VSPOS.js";
4
+ import "./chunk-BV2MZRRU.js";
5
5
 
6
6
  // src/components/inline-popover/inline-popover.gen.ts
7
7
  import {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  createComponent
3
- } from "./chunk-E43DMYRE.js";
4
- import "./chunk-BH56NR2Q.js";
3
+ } from "./chunk-IO5VSPOS.js";
4
+ import "./chunk-BV2MZRRU.js";
5
5
 
6
6
  // src/components/popover/popover-content.gen.ts
7
7
  import {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  createComponent
3
- } from "./chunk-E43DMYRE.js";
4
- import "./chunk-BH56NR2Q.js";
3
+ } from "./chunk-IO5VSPOS.js";
4
+ import "./chunk-BV2MZRRU.js";
5
5
 
6
6
  // src/components/resizable/resizable-handle.gen.ts
7
7
  import {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  createComponent
3
- } from "./chunk-E43DMYRE.js";
4
- import "./chunk-BH56NR2Q.js";
3
+ } from "./chunk-IO5VSPOS.js";
4
+ import "./chunk-BV2MZRRU.js";
5
5
 
6
6
  // src/components/table-handle/table-handle-column-root.gen.ts
7
7
  import {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  createComponent
3
- } from "./chunk-E43DMYRE.js";
4
- import "./chunk-BH56NR2Q.js";
3
+ } from "./chunk-IO5VSPOS.js";
4
+ import "./chunk-BV2MZRRU.js";
5
5
 
6
6
  // src/components/tooltip/tooltip-content.gen.ts
7
7
  import {
@@ -1,5 +1,9 @@
1
1
  export { ProseKit } from './_tsup-dts-rollup.js';
2
2
  export { ProseKitProps } from './_tsup-dts-rollup.js';
3
+ export { defineReactMarkView } from './_tsup-dts-rollup.js';
4
+ export { ReactMarkViewComponent } from './_tsup-dts-rollup.js';
5
+ export { ReactMarkViewOptions } from './_tsup-dts-rollup.js';
6
+ export { ReactMarkViewProps } from './_tsup-dts-rollup.js';
3
7
  export { defineReactNodeView } from './_tsup-dts-rollup.js';
4
8
  export { ReactNodeViewComponent } from './_tsup-dts-rollup.js';
5
9
  export { ReactNodeViewOptions } from './_tsup-dts-rollup.js';
@@ -1,22 +1,27 @@
1
1
  import {
2
2
  EditorContextProvider,
3
3
  useEditorContext
4
- } from "./chunk-BH56NR2Q.js";
4
+ } from "./chunk-BV2MZRRU.js";
5
5
 
6
6
  // src/components/prosekit.ts
7
7
  import { ProsemirrorAdapterProvider } from "@prosemirror-adapter/react";
8
- import { createElement as createElement2 } from "react";
8
+ import {
9
+ createElement as createElement3
10
+ } from "react";
9
11
 
10
- // src/extensions/react-node-view.ts
12
+ // src/extensions/react-mark-view.ts
11
13
  import {
12
- defineNodeViewComponent,
13
- defineNodeViewFactory
14
+ defineMarkViewComponent,
15
+ defineMarkViewFactory
14
16
  } from "@prosekit/core";
15
17
  import {
16
- useNodeViewContext,
17
- useNodeViewFactory
18
+ useMarkViewContext,
19
+ useMarkViewFactory
18
20
  } from "@prosemirror-adapter/react";
19
- import { createElement, useMemo as useMemo2 } from "react";
21
+ import {
22
+ createElement,
23
+ useMemo as useMemo2
24
+ } from "react";
20
25
 
21
26
  // src/hooks/use-editor-extension.ts
22
27
  import {
@@ -35,7 +40,9 @@ function useEditorExtension(editor, extension) {
35
40
  }
36
41
 
37
42
  // src/hooks/use-priority-extension.ts
38
- import { withPriority } from "@prosekit/core";
43
+ import {
44
+ withPriority
45
+ } from "@prosekit/core";
39
46
  import { useMemo } from "react";
40
47
  function usePriorityExtension(extension, priority) {
41
48
  return useMemo(() => {
@@ -52,16 +59,63 @@ function useExtension(extension, options) {
52
59
  );
53
60
  }
54
61
 
62
+ // src/extensions/react-mark-view.ts
63
+ function withMarkViewProps(component) {
64
+ return function MarkViewPropsWrapper() {
65
+ const props = useMarkViewContext();
66
+ return createElement(component, props);
67
+ };
68
+ }
69
+ var ReactMarkViewConsumer = () => {
70
+ const markViewFactory = useMarkViewFactory();
71
+ const extension = useMemo2(
72
+ () => defineReactMarkViewFactory(markViewFactory),
73
+ [markViewFactory]
74
+ );
75
+ useExtension(extension);
76
+ return null;
77
+ };
78
+ 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
+ });
89
+ }
90
+ function defineReactMarkViewFactory(factory) {
91
+ return defineMarkViewFactory({
92
+ group: "react",
93
+ factory
94
+ });
95
+ }
96
+
55
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";
56
110
  function withNodeViewProps(component) {
57
111
  return function NodeViewPropsWrapper() {
58
112
  const props = useNodeViewContext();
59
- return createElement(component, props);
113
+ return createElement2(component, props);
60
114
  };
61
115
  }
62
- var ReactViewsConsumer = () => {
116
+ var ReactNodeViewConsumer = () => {
63
117
  const nodeViewFactory = useNodeViewFactory();
64
- const extension = useMemo2(
118
+ const extension = useMemo3(
65
119
  () => defineReactNodeViewFactory(nodeViewFactory),
66
120
  [nodeViewFactory]
67
121
  );
@@ -90,13 +144,14 @@ function defineReactNodeViewFactory(factory) {
90
144
  // src/components/prosekit.ts
91
145
  var ProseKit = (props) => {
92
146
  const { editor, children } = props;
93
- return createElement2(
147
+ return createElement3(
94
148
  ProsemirrorAdapterProvider,
95
149
  null,
96
- createElement2(
150
+ createElement3(
97
151
  EditorContextProvider,
98
152
  { value: editor },
99
- createElement2(ReactViewsConsumer),
153
+ createElement3(ReactNodeViewConsumer),
154
+ createElement3(ReactMarkViewConsumer),
100
155
  children
101
156
  )
102
157
  );
@@ -104,9 +159,9 @@ var ProseKit = (props) => {
104
159
 
105
160
  // src/hooks/use-doc-change.ts
106
161
  import { defineDocChangeHandler } from "@prosekit/core";
107
- import { useMemo as useMemo3 } from "react";
162
+ import { useMemo as useMemo4 } from "react";
108
163
  function useDocChange(handler, options) {
109
- const extension = useMemo3(
164
+ const extension = useMemo4(
110
165
  () => defineDocChangeHandler((view) => handler(view.state.doc)),
111
166
  [handler]
112
167
  );
@@ -115,12 +170,15 @@ function useDocChange(handler, options) {
115
170
 
116
171
  // src/hooks/use-editor.ts
117
172
  import {
118
- ProseKitError,
119
173
  defineMountHandler,
120
174
  defineUpdateHandler,
175
+ ProseKitError,
121
176
  union
122
177
  } from "@prosekit/core";
123
- import { useEffect as useEffect2, useReducer } from "react";
178
+ import {
179
+ useEffect as useEffect2,
180
+ useReducer
181
+ } from "react";
124
182
  function useEditor(options) {
125
183
  var _a;
126
184
  const update = (_a = options == null ? void 0 : options.update) != null ? _a : false;
@@ -148,18 +206,20 @@ function useForceUpdate() {
148
206
  }
149
207
 
150
208
  // src/hooks/use-keymap.ts
151
- import { defineKeymap } from "@prosekit/core";
152
- import { useMemo as useMemo4 } from "react";
209
+ import {
210
+ defineKeymap
211
+ } from "@prosekit/core";
212
+ import { useMemo as useMemo5 } from "react";
153
213
  function useKeymap(keymap, options) {
154
- const extension = useMemo4(() => defineKeymap(keymap), [keymap]);
214
+ const extension = useMemo5(() => defineKeymap(keymap), [keymap]);
155
215
  return useExtension(extension, options);
156
216
  }
157
217
 
158
218
  // src/hooks/use-state-update.ts
159
219
  import { defineUpdateHandler as defineUpdateHandler2 } from "@prosekit/core";
160
- import { useMemo as useMemo5 } from "react";
220
+ import { useMemo as useMemo6 } from "react";
161
221
  function useStateUpdate(handler, options) {
162
- const extension = useMemo5(
222
+ const extension = useMemo6(
163
223
  () => defineUpdateHandler2((view) => handler(view.state)),
164
224
  [handler]
165
225
  );
@@ -167,6 +227,7 @@ function useStateUpdate(handler, options) {
167
227
  }
168
228
  export {
169
229
  ProseKit,
230
+ defineReactMarkView,
170
231
  defineReactNodeView,
171
232
  useDocChange,
172
233
  useEditor,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prosekit/react",
3
3
  "type": "module",
4
- "version": "0.4.5",
4
+ "version": "0.4.6",
5
5
  "private": false,
6
6
  "author": {
7
7
  "name": "ocavue",
@@ -70,7 +70,8 @@
70
70
  "dist"
71
71
  ],
72
72
  "dependencies": {
73
- "@prosemirror-adapter/react": "^0.2.6",
73
+ "@prosemirror-adapter/core": "^0.4.0",
74
+ "@prosemirror-adapter/react": "^0.4.0",
74
75
  "react-merge-refs": "^2.1.1",
75
76
  "@prosekit/core": "^0.7.13",
76
77
  "@prosekit/web": "^0.5.1",
@@ -89,13 +90,13 @@
89
90
  }
90
91
  },
91
92
  "devDependencies": {
92
- "@types/react": "^18.3.12",
93
- "@types/react-dom": "^18.3.1",
93
+ "@types/react": "^18.3.17",
94
+ "@types/react-dom": "^18.3.5",
94
95
  "react": "^18.3.1",
95
96
  "react-dom": "^18.3.1",
96
97
  "tsup": "^8.3.5",
97
- "typescript": "^5.6.3",
98
- "vitest": "^2.1.6",
98
+ "typescript": "~5.6.3",
99
+ "vitest": "^2.1.8",
99
100
  "@prosekit/dev": "0.0.0"
100
101
  },
101
102
  "scripts": {