@prosekit/react 0.1.2 → 0.1.3
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/_tsup-dts-rollup.d.ts +106 -24
- package/dist/prosekit-react.d.ts +2 -3
- package/dist/prosekit-react.js +205 -58
- package/package.json +6 -5
- package/src/index.ts +3 -3
@@ -1,5 +1,6 @@
|
|
1
1
|
/// <reference types="react" />
|
2
2
|
|
3
|
+
import type { Attrs } from '@prosekit/pm/model';
|
3
4
|
import { AutocompleteEmpty as AutocompleteEmpty_2 } from '@prosekit/lit/autocomplete-empty';
|
4
5
|
import { AutocompleteEmptyProps as AutocompleteEmptyProps_2 } from '@prosekit/lit/autocomplete-empty';
|
5
6
|
import { AutocompleteItem as AutocompleteItem_2 } from '@prosekit/lit/autocomplete-item';
|
@@ -19,22 +20,29 @@ import { ComboBoxProps as ComboBoxProps_2 } from '@prosekit/lit/combo-box';
|
|
19
20
|
import { CommandArgs } from '@prosekit/core';
|
20
21
|
import { ComponentType } from 'react';
|
21
22
|
import { Context } from 'react';
|
23
|
+
import { CoreNodeView } from '@prosemirror-adapter/core';
|
24
|
+
import type { CoreNodeViewSpec } from '@prosemirror-adapter/core';
|
25
|
+
import type { CoreNodeViewUserOptions } from '@prosemirror-adapter/core';
|
26
|
+
import type { Decoration } from '@prosekit/pm/view';
|
27
|
+
import type { DecorationSource } from '@prosekit/pm/view';
|
22
28
|
import { Editor } from '@prosekit/core';
|
29
|
+
import type { EditorView } from '@prosekit/pm/view';
|
23
30
|
import { Extension } from '@prosekit/core';
|
24
31
|
import { ExtensionTyping } from '@prosekit/core';
|
32
|
+
import { FC } from 'react';
|
25
33
|
import { InlinePopover as InlinePopover_2 } from '@prosekit/lit/inline-popover';
|
26
34
|
import { InlinePopoverProps as InlinePopoverProps_2 } from '@prosekit/lit/inline-popover';
|
27
35
|
import { Keymap } from '@prosekit/core';
|
28
|
-
import type {
|
36
|
+
import type { Node as Node_2 } from '@prosekit/pm/model';
|
37
|
+
import type { NodeViewConstructor } from '@prosekit/pm/view';
|
29
38
|
import { Options } from 'tsup';
|
30
39
|
import { Popover as Popover_2 } from '@prosekit/lit/popover';
|
31
40
|
import { PopoverOptions } from '@prosekit/lit/autocomplete-popover';
|
32
41
|
import { PopoverProps as PopoverProps_2 } from '@prosekit/lit/popover';
|
33
42
|
import { Priority } from '@prosekit/core';
|
34
43
|
import { default as React_2 } from 'react';
|
35
|
-
import {
|
36
|
-
import {
|
37
|
-
import { UserProjectConfigExport } from 'vitest/dist/config.js';
|
44
|
+
import { ReactNode } from 'react';
|
45
|
+
import { ReactPortal } from 'react';
|
38
46
|
|
39
47
|
declare const AutocompleteEmpty: React_2.ComponentType<AutocompleteEmptyProps & React_2.RefAttributes<AutocompleteEmpty_2>>;
|
40
48
|
export { AutocompleteEmpty }
|
@@ -84,17 +92,33 @@ export declare type ComboBoxListProps = React_2.PropsWithChildren<PropsWithClass
|
|
84
92
|
|
85
93
|
export declare type ComboBoxProps = React_2.PropsWithChildren<PropsWithClassName<ComboBoxProps_2>>;
|
86
94
|
|
95
|
+
export declare const createNodeViewContext: Context<NodeViewFactory | null>;
|
96
|
+
|
97
|
+
declare type CreateReactNodeView = ReturnType<typeof useReactNodeViewCreator>;
|
98
|
+
export { CreateReactNodeView }
|
99
|
+
export { CreateReactNodeView as CreateReactNodeView_alias_1 }
|
100
|
+
|
87
101
|
export declare const default_alias: Options | Options[] | ((overrideOptions: Options) => Options | Options[] | Promise<Options | Options[]>);
|
88
102
|
|
89
|
-
export declare const default_alias_1:
|
103
|
+
export declare const default_alias_1: {
|
104
|
+
test: {
|
105
|
+
environment: "jsdom";
|
106
|
+
};
|
107
|
+
};
|
90
108
|
|
109
|
+
/**
|
110
|
+
* Defines a node view using a React component.
|
111
|
+
*
|
112
|
+
* @public
|
113
|
+
*/
|
91
114
|
declare function defineReactNodeView(options: ReactNodeViewOptions): Extension;
|
92
115
|
export { defineReactNodeView }
|
93
116
|
export { defineReactNodeView as defineReactNodeView_alias_1 }
|
94
117
|
|
95
|
-
|
96
|
-
|
97
|
-
|
118
|
+
/**
|
119
|
+
* @internal
|
120
|
+
*/
|
121
|
+
export declare function defineReactNodeViewFactory(nodeViewFactory: NodeViewFactory): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
98
122
|
|
99
123
|
export declare interface EditorContext {
|
100
124
|
editor: Editor;
|
@@ -106,6 +130,8 @@ export declare const InlinePopover: React_2.ComponentType<InlinePopoverProps & R
|
|
106
130
|
|
107
131
|
export declare type InlinePopoverProps = React_2.PropsWithChildren<PropsWithClassName<InlinePopoverProps_2>>;
|
108
132
|
|
133
|
+
export declare type NodeViewFactory = (options: ReactNodeViewUserOptions) => NodeViewConstructor;
|
134
|
+
|
109
135
|
export declare const Popover: React_2.ComponentType<PopoverProps & React_2.RefAttributes<Popover_2>>;
|
110
136
|
|
111
137
|
export { PopoverOptions }
|
@@ -127,33 +153,85 @@ export { ProseKit as ProseKit_alias_1 }
|
|
127
153
|
|
128
154
|
declare interface ProseKitProps {
|
129
155
|
editor: Editor;
|
130
|
-
children?:
|
156
|
+
children?: ReactNode;
|
131
157
|
}
|
132
158
|
export { ProseKitProps }
|
133
159
|
export { ProseKitProps as ProseKitProps_alias_1 }
|
134
160
|
|
135
|
-
declare
|
136
|
-
|
137
|
-
|
161
|
+
export declare class ReactNodeView extends CoreNodeView<ReactNodeViewComponent> implements ReactRenderer<ReactNodeViewProps> {
|
162
|
+
key: string;
|
163
|
+
context: ReactNodeViewProps;
|
164
|
+
updateContext: () => void;
|
165
|
+
render: () => ReactPortal;
|
166
|
+
}
|
167
|
+
|
168
|
+
/**
|
169
|
+
* @public
|
170
|
+
*/
|
171
|
+
declare type ReactNodeViewComponent = ComponentType<ReactNodeViewProps>;
|
172
|
+
export { ReactNodeViewComponent }
|
173
|
+
export { ReactNodeViewComponent as ReactNodeViewComponent_alias_1 }
|
138
174
|
|
139
|
-
|
175
|
+
/**
|
176
|
+
* Options for {@link defineReactNodeView}.
|
177
|
+
*
|
178
|
+
* @public
|
179
|
+
*/
|
180
|
+
declare interface ReactNodeViewOptions extends ReactNodeViewUserOptions {
|
181
|
+
/**
|
182
|
+
* The name of the node.
|
183
|
+
*/
|
140
184
|
name: string;
|
141
|
-
component: React.ComponentType<ReactNodeViewComponentProps>;
|
142
|
-
dom?: string | (() => HTMLElement);
|
143
|
-
contentDOM?: string | (() => HTMLElement);
|
144
185
|
}
|
145
186
|
export { ReactNodeViewOptions }
|
146
187
|
export { ReactNodeViewOptions as ReactNodeViewOptions_alias_1 }
|
147
188
|
|
148
|
-
|
149
|
-
|
150
|
-
|
189
|
+
/**
|
190
|
+
* @public
|
191
|
+
*/
|
192
|
+
declare interface ReactNodeViewProps {
|
193
|
+
contentRef: (node: HTMLElement | null) => void;
|
194
|
+
view: EditorView;
|
195
|
+
getPos: () => number | undefined;
|
196
|
+
setAttrs: (attrs: Attrs) => void;
|
197
|
+
node: Node_2;
|
198
|
+
selected: boolean;
|
199
|
+
decorations: readonly Decoration[];
|
200
|
+
innerDecorations: DecorationSource;
|
201
|
+
}
|
202
|
+
export { ReactNodeViewProps }
|
203
|
+
export { ReactNodeViewProps as ReactNodeViewProps_alias_1 }
|
151
204
|
|
152
|
-
declare
|
153
|
-
|
205
|
+
export declare type ReactNodeViewSpec = CoreNodeViewSpec<ReactNodeViewComponent>;
|
206
|
+
|
207
|
+
export declare type ReactNodeViewUserOptions = CoreNodeViewUserOptions<ReactNodeViewComponent>;
|
208
|
+
|
209
|
+
export declare interface ReactRenderer<Context> {
|
210
|
+
key: string;
|
211
|
+
context: Context;
|
212
|
+
render: () => ReactPortal;
|
213
|
+
updateContext: () => void;
|
214
|
+
}
|
215
|
+
|
216
|
+
export declare interface ReactRendererResult {
|
217
|
+
readonly portals: Record<string, ReactPortal>;
|
218
|
+
readonly renderReactRenderer: (nodeView: ReactRenderer<unknown>, update?: boolean) => void;
|
219
|
+
readonly removeReactRenderer: (nodeView: ReactRenderer<unknown>) => void;
|
154
220
|
}
|
155
|
-
|
156
|
-
export
|
221
|
+
|
222
|
+
export declare const ReactViewsConsumer: FC;
|
223
|
+
|
224
|
+
declare const ReactViewsProvider: FC<{
|
225
|
+
children: ReactNode;
|
226
|
+
}>;
|
227
|
+
export { ReactViewsProvider }
|
228
|
+
export { ReactViewsProvider as ReactViewsProvider_alias_1 }
|
229
|
+
|
230
|
+
declare function useEditor<E extends Extension = any>(options?: {
|
231
|
+
update?: boolean;
|
232
|
+
}): Editor<E>;
|
233
|
+
export { useEditor }
|
234
|
+
export { useEditor as useEditor_alias_1 }
|
157
235
|
|
158
236
|
/**
|
159
237
|
* Add an extension to the editor.
|
@@ -171,8 +249,12 @@ declare function useKeymap(keymap: Keymap, options?: {
|
|
171
249
|
export { useKeymap }
|
172
250
|
export { useKeymap as useKeymap_alias_1 }
|
173
251
|
|
174
|
-
export
|
252
|
+
export declare function useNodeViewFactory(): NodeViewFactory;
|
175
253
|
|
176
254
|
export declare function usePriorityExtension<T extends Extension = Extension>(extension: T | null, priority?: Priority | null): void;
|
177
255
|
|
256
|
+
export declare function useReactNodeViewCreator(renderReactRenderer: ReactRendererResult['renderReactRenderer'], removeReactRenderer: ReactRendererResult['removeReactRenderer']): (options: ReactNodeViewUserOptions) => NodeViewConstructor;
|
257
|
+
|
258
|
+
export declare function useReactRenderer(): ReactRendererResult;
|
259
|
+
|
178
260
|
export { }
|
package/dist/prosekit-react.d.ts
CHANGED
@@ -1,11 +1,10 @@
|
|
1
|
-
export {
|
1
|
+
export { ReactNodeViewComponent } from './_tsup-dts-rollup';
|
2
2
|
export { ProseKit } from './_tsup-dts-rollup';
|
3
3
|
export { ProseKitProps } from './_tsup-dts-rollup';
|
4
4
|
export { defineReactNodeView } from './_tsup-dts-rollup';
|
5
|
-
export { ReactNodeViewComponentProps } from './_tsup-dts-rollup';
|
6
5
|
export { ReactNodeViewOptions } from './_tsup-dts-rollup';
|
7
6
|
export { useEditor } from './_tsup-dts-rollup';
|
8
|
-
export { UseEditorOptions } from './_tsup-dts-rollup';
|
9
7
|
export { useExtension } from './_tsup-dts-rollup';
|
10
8
|
export { useKeymap } from './_tsup-dts-rollup';
|
11
9
|
export { PropsWithClassName } from './_tsup-dts-rollup';
|
10
|
+
export { ReactNodeViewProps } from './_tsup-dts-rollup';
|
package/dist/prosekit-react.js
CHANGED
@@ -1,52 +1,28 @@
|
|
1
|
-
// src/index.ts
|
2
|
-
import { useNodeViewContext as useNodeViewContext2 } from "@prosemirror-adapter/react";
|
3
|
-
|
4
1
|
// src/components/prosekit.ts
|
5
2
|
import "@prosekit/core";
|
6
|
-
import {
|
7
|
-
ProsemirrorAdapterProvider,
|
8
|
-
useNodeViewFactory
|
9
|
-
} from "@prosemirror-adapter/react";
|
10
|
-
import { createElement as createElement2, useMemo } from "react";
|
3
|
+
import { createElement as createElement3 } from "react";
|
11
4
|
|
12
5
|
// src/contexts/editor-context.ts
|
13
6
|
import { createContext } from "react";
|
14
7
|
var editorContext = createContext(null);
|
15
8
|
|
9
|
+
// src/views/react-views-consumer.ts
|
10
|
+
import { useMemo } from "react";
|
11
|
+
|
16
12
|
// src/extensions/react-node-view.ts
|
17
|
-
import {
|
18
|
-
import {
|
19
|
-
useNodeViewContext
|
20
|
-
} from "@prosemirror-adapter/react";
|
21
|
-
import { createElement } from "react";
|
13
|
+
import { defineNodeViewFactory } from "@prosekit/core";
|
22
14
|
function defineReactNodeView(options) {
|
23
|
-
|
15
|
+
const { name, ...userOptions } = options;
|
16
|
+
return defineNodeViewFactory({
|
24
17
|
group: "react",
|
25
|
-
name
|
26
|
-
args:
|
18
|
+
name,
|
19
|
+
args: userOptions
|
27
20
|
});
|
28
21
|
}
|
29
|
-
function
|
30
|
-
|
31
|
-
}) {
|
32
|
-
return defineNodeViewEffect({
|
22
|
+
function defineReactNodeViewFactory(nodeViewFactory) {
|
23
|
+
return defineNodeViewFactory({
|
33
24
|
group: "react",
|
34
|
-
factory:
|
35
|
-
const nodeViewOptions = args;
|
36
|
-
return nodeViewFactory({
|
37
|
-
component: function ReactNodeViewWrapper() {
|
38
|
-
const context = useNodeViewContext();
|
39
|
-
return createElement(nodeViewOptions.component, context);
|
40
|
-
},
|
41
|
-
// Optional: add some options
|
42
|
-
as: () => {
|
43
|
-
const dom = document.createElement("div");
|
44
|
-
dom.style.display = "contents";
|
45
|
-
return dom;
|
46
|
-
},
|
47
|
-
contentAs: "code"
|
48
|
-
});
|
49
|
-
}
|
25
|
+
factory: nodeViewFactory
|
50
26
|
});
|
51
27
|
}
|
52
28
|
|
@@ -93,40 +69,212 @@ function useExtension(extension) {
|
|
93
69
|
}, [editor, extension]);
|
94
70
|
}
|
95
71
|
|
72
|
+
// src/views/node-view/node-view-context.ts
|
73
|
+
import { ProseKitError as ProseKitError2 } from "@prosekit/core";
|
74
|
+
import { createContext as createContext2, useContext as useContext2 } from "react";
|
75
|
+
var createNodeViewContext = createContext2(null);
|
76
|
+
function useNodeViewFactory() {
|
77
|
+
const nodeViewFactory = useContext2(createNodeViewContext);
|
78
|
+
if (!nodeViewFactory) {
|
79
|
+
throw new ProseKitError2("Cannot find node view factory context.");
|
80
|
+
}
|
81
|
+
return nodeViewFactory;
|
82
|
+
}
|
83
|
+
|
84
|
+
// src/views/react-views-consumer.ts
|
85
|
+
var ReactViewsConsumer = () => {
|
86
|
+
const nodeViewFactory = useNodeViewFactory();
|
87
|
+
const extension = useMemo(
|
88
|
+
() => defineReactNodeViewFactory(nodeViewFactory),
|
89
|
+
[nodeViewFactory]
|
90
|
+
);
|
91
|
+
useExtension(extension);
|
92
|
+
return null;
|
93
|
+
};
|
94
|
+
|
95
|
+
// src/views/react-views-provider.ts
|
96
|
+
import { createElement as createElement2, useMemo as useMemo2 } from "react";
|
97
|
+
|
98
|
+
// src/views/node-view/use-react-node-view-creator.ts
|
99
|
+
import { useCallback } from "react";
|
100
|
+
|
101
|
+
// src/views/node-view/react-node-view.ts
|
102
|
+
import { _getId } from "@prosekit/core";
|
103
|
+
import { CoreNodeView } from "@prosemirror-adapter/core";
|
104
|
+
import { createElement } from "react";
|
105
|
+
import { createPortal } from "react-dom";
|
106
|
+
var ReactNodeView = class extends CoreNodeView {
|
107
|
+
constructor() {
|
108
|
+
super(...arguments);
|
109
|
+
this.key = _getId();
|
110
|
+
this.context = {
|
111
|
+
contentRef: (element) => {
|
112
|
+
if (element && this.contentDOM && element.firstChild !== this.contentDOM)
|
113
|
+
element.appendChild(this.contentDOM);
|
114
|
+
},
|
115
|
+
view: this.view,
|
116
|
+
getPos: this.getPos,
|
117
|
+
setAttrs: this.setAttrs,
|
118
|
+
node: this.node,
|
119
|
+
selected: this.selected,
|
120
|
+
decorations: this.decorations,
|
121
|
+
innerDecorations: this.innerDecorations
|
122
|
+
};
|
123
|
+
this.updateContext = () => {
|
124
|
+
Object.assign(this.context, {
|
125
|
+
node: this.node,
|
126
|
+
selected: this.selected,
|
127
|
+
decorations: this.decorations,
|
128
|
+
innerDecorations: this.innerDecorations
|
129
|
+
});
|
130
|
+
};
|
131
|
+
this.render = () => {
|
132
|
+
const UserComponent = this.component;
|
133
|
+
return createPortal(
|
134
|
+
createElement(UserComponent, this.context),
|
135
|
+
this.dom,
|
136
|
+
this.key
|
137
|
+
);
|
138
|
+
};
|
139
|
+
}
|
140
|
+
};
|
141
|
+
|
142
|
+
// src/views/node-view/use-react-node-view-creator.ts
|
143
|
+
function useReactNodeViewCreator(renderReactRenderer, removeReactRenderer) {
|
144
|
+
const createReactNodeView = useCallback(
|
145
|
+
(options) => (node, view, getPos, decorations, innerDecorations) => {
|
146
|
+
const nodeView = new ReactNodeView({
|
147
|
+
node,
|
148
|
+
view,
|
149
|
+
getPos,
|
150
|
+
decorations,
|
151
|
+
innerDecorations,
|
152
|
+
options: {
|
153
|
+
...options,
|
154
|
+
onUpdate() {
|
155
|
+
var _a;
|
156
|
+
(_a = options.onUpdate) == null ? void 0 : _a.call(options);
|
157
|
+
renderReactRenderer(nodeView);
|
158
|
+
},
|
159
|
+
selectNode() {
|
160
|
+
var _a;
|
161
|
+
(_a = options.selectNode) == null ? void 0 : _a.call(options);
|
162
|
+
renderReactRenderer(nodeView);
|
163
|
+
},
|
164
|
+
deselectNode() {
|
165
|
+
var _a;
|
166
|
+
(_a = options.deselectNode) == null ? void 0 : _a.call(options);
|
167
|
+
renderReactRenderer(nodeView);
|
168
|
+
},
|
169
|
+
destroy() {
|
170
|
+
var _a;
|
171
|
+
(_a = options.destroy) == null ? void 0 : _a.call(options);
|
172
|
+
removeReactRenderer(nodeView);
|
173
|
+
}
|
174
|
+
}
|
175
|
+
});
|
176
|
+
renderReactRenderer(nodeView, false);
|
177
|
+
return nodeView;
|
178
|
+
},
|
179
|
+
[removeReactRenderer, renderReactRenderer]
|
180
|
+
);
|
181
|
+
return createReactNodeView;
|
182
|
+
}
|
183
|
+
|
184
|
+
// src/views/react-renderer.ts
|
185
|
+
import { useCallback as useCallback2, useEffect as useEffect3, useRef, useState } from "react";
|
186
|
+
import { flushSync } from "react-dom";
|
187
|
+
function useReactRenderer() {
|
188
|
+
const [portals, setPortals] = useState({});
|
189
|
+
const mountedRef = useRef(false);
|
190
|
+
useEffect3(() => {
|
191
|
+
requestAnimationFrame(() => {
|
192
|
+
mountedRef.current = true;
|
193
|
+
});
|
194
|
+
return () => {
|
195
|
+
mountedRef.current = false;
|
196
|
+
};
|
197
|
+
}, []);
|
198
|
+
const maybeFlushSync = useCallback2((fn) => {
|
199
|
+
if (mountedRef.current)
|
200
|
+
flushSync(fn);
|
201
|
+
else
|
202
|
+
fn();
|
203
|
+
}, []);
|
204
|
+
const renderReactRenderer = useCallback2(
|
205
|
+
(nodeView, update = true) => {
|
206
|
+
maybeFlushSync(() => {
|
207
|
+
if (update)
|
208
|
+
nodeView.updateContext();
|
209
|
+
setPortals((prev) => ({
|
210
|
+
...prev,
|
211
|
+
[nodeView.key]: nodeView.render()
|
212
|
+
}));
|
213
|
+
});
|
214
|
+
},
|
215
|
+
[maybeFlushSync]
|
216
|
+
);
|
217
|
+
const removeReactRenderer = useCallback2(
|
218
|
+
(nodeView) => {
|
219
|
+
maybeFlushSync(() => {
|
220
|
+
setPortals((prev) => {
|
221
|
+
const next = { ...prev };
|
222
|
+
delete next[nodeView.key];
|
223
|
+
return next;
|
224
|
+
});
|
225
|
+
});
|
226
|
+
},
|
227
|
+
[maybeFlushSync]
|
228
|
+
);
|
229
|
+
return {
|
230
|
+
portals,
|
231
|
+
renderReactRenderer,
|
232
|
+
removeReactRenderer
|
233
|
+
};
|
234
|
+
}
|
235
|
+
|
236
|
+
// src/views/react-views-provider.ts
|
237
|
+
var ReactViewsProvider = ({
|
238
|
+
children
|
239
|
+
}) => {
|
240
|
+
const { renderReactRenderer, removeReactRenderer, portals } = useReactRenderer();
|
241
|
+
const createReactNodeView = useReactNodeViewCreator(
|
242
|
+
renderReactRenderer,
|
243
|
+
removeReactRenderer
|
244
|
+
);
|
245
|
+
const memoizedPortals = useMemo2(() => Object.values(portals), [portals]);
|
246
|
+
return createElement2(
|
247
|
+
createNodeViewContext.Provider,
|
248
|
+
{ value: createReactNodeView },
|
249
|
+
children,
|
250
|
+
memoizedPortals
|
251
|
+
);
|
252
|
+
};
|
253
|
+
|
96
254
|
// src/components/prosekit.ts
|
97
255
|
var ProseKit = (props) => {
|
98
256
|
const { editor, children } = props;
|
99
|
-
return
|
100
|
-
|
257
|
+
return createElement3(
|
258
|
+
ReactViewsProvider,
|
101
259
|
null,
|
102
|
-
|
103
|
-
|
260
|
+
createElement3(
|
261
|
+
editorContext.Provider,
|
104
262
|
{ value: { editor } },
|
105
|
-
|
106
|
-
|
263
|
+
createElement3(ReactViewsConsumer),
|
264
|
+
children
|
107
265
|
)
|
108
266
|
);
|
109
267
|
};
|
110
|
-
function RendererRegister() {
|
111
|
-
const nodeViewFactory = useNodeViewFactory();
|
112
|
-
const extension = useMemo(
|
113
|
-
() => defineReactNodeViewRenderer({ nodeViewFactory }),
|
114
|
-
[nodeViewFactory]
|
115
|
-
);
|
116
|
-
useExtension(extension);
|
117
|
-
return null;
|
118
|
-
}
|
119
|
-
var EditorContextProvider = editorContext.Provider;
|
120
268
|
|
121
269
|
// src/hooks/use-keymap.ts
|
122
270
|
import { defineKeymap } from "@prosekit/core";
|
123
|
-
import { useMemo as
|
271
|
+
import { useMemo as useMemo4 } from "react";
|
124
272
|
|
125
273
|
// src/hooks/use-priority-extension.ts
|
126
274
|
import { withPriority } from "@prosekit/core";
|
127
|
-
import { useMemo as
|
275
|
+
import { useMemo as useMemo3 } from "react";
|
128
276
|
function usePriorityExtension(extension, priority) {
|
129
|
-
const extensionWithPriority =
|
277
|
+
const extensionWithPriority = useMemo3(() => {
|
130
278
|
return extension && priority ? withPriority(extension, priority) : extension;
|
131
279
|
}, [extension, priority]);
|
132
280
|
return useExtension(extensionWithPriority);
|
@@ -134,7 +282,7 @@ function usePriorityExtension(extension, priority) {
|
|
134
282
|
|
135
283
|
// src/hooks/use-keymap.ts
|
136
284
|
function useKeymap(keymap, options) {
|
137
|
-
const extension =
|
285
|
+
const extension = useMemo4(() => defineKeymap(keymap), [keymap]);
|
138
286
|
usePriorityExtension(extension, options == null ? void 0 : options.priority);
|
139
287
|
}
|
140
288
|
export {
|
@@ -142,6 +290,5 @@ export {
|
|
142
290
|
defineReactNodeView,
|
143
291
|
useEditor,
|
144
292
|
useExtension,
|
145
|
-
useKeymap
|
146
|
-
useNodeViewContext2 as useNodeViewContext
|
293
|
+
useKeymap
|
147
294
|
};
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@prosekit/react",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.1.
|
4
|
+
"version": "0.1.3",
|
5
5
|
"private": false,
|
6
6
|
"author": {
|
7
7
|
"name": "ocavue",
|
@@ -88,7 +88,8 @@
|
|
88
88
|
"@lit/react": "^1.0.2",
|
89
89
|
"@prosekit/core": "^0.1.0",
|
90
90
|
"@prosekit/lit": "^0.1.0",
|
91
|
-
"@
|
91
|
+
"@prosekit/pm": "^0.1.0",
|
92
|
+
"@prosemirror-adapter/core": "^0.2.6"
|
92
93
|
},
|
93
94
|
"peerDependencies": {
|
94
95
|
"react": ">= 17.0.0",
|
@@ -104,13 +105,13 @@
|
|
104
105
|
},
|
105
106
|
"devDependencies": {
|
106
107
|
"@prosekit/dev": "*",
|
107
|
-
"@types/react": "^18.2.
|
108
|
+
"@types/react": "^18.2.45",
|
108
109
|
"@types/react-dom": "^18.2.17",
|
109
110
|
"react": "^18.2.0",
|
110
111
|
"react-dom": "^18.2.0",
|
111
112
|
"tsup": "^8.0.1",
|
112
|
-
"typescript": "^5.3.
|
113
|
-
"vitest": "^0.
|
113
|
+
"typescript": "^5.3.3",
|
114
|
+
"vitest": "^1.0.4"
|
114
115
|
},
|
115
116
|
"scripts": {
|
116
117
|
"build:tsup": "tsup",
|
package/src/index.ts
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
export {
|
1
|
+
export type { ReactNodeViewComponent } from './views/node-view/react-node-view-options'
|
2
2
|
export { ProseKit, type ProseKitProps } from './components/prosekit'
|
3
3
|
export {
|
4
4
|
defineReactNodeView,
|
5
|
-
type ReactNodeViewComponentProps,
|
6
5
|
type ReactNodeViewOptions,
|
7
6
|
} from './extensions/react-node-view'
|
8
|
-
export { useEditor
|
7
|
+
export { useEditor } from './hooks/use-editor'
|
9
8
|
export { useExtension } from './hooks/use-extension'
|
10
9
|
export { useKeymap } from './hooks/use-keymap'
|
11
10
|
export { type PropsWithClassName } from './types'
|
11
|
+
export type { ReactNodeViewProps } from './views/node-view/react-node-view-props'
|