@prosekit/react 0.0.0-next-20231120040948 → 0.0.0-next-20240421132240
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 +283 -132
- package/dist/chunk-BH56NR2Q.js +12 -0
- package/dist/chunk-UG3RPLME.js +51 -0
- package/dist/prosekit-react-autocomplete.d.ts +4 -0
- package/dist/prosekit-react-autocomplete.js +50 -0
- package/dist/prosekit-react-block-handle.d.ts +2 -0
- package/dist/prosekit-react-block-handle.js +28 -0
- package/dist/prosekit-react-inline-popover.d.ts +0 -1
- package/dist/prosekit-react-inline-popover.js +14 -14
- package/dist/prosekit-react-popover.d.ts +3 -2
- package/dist/prosekit-react-popover.js +37 -15
- package/dist/prosekit-react-resizable.d.ts +2 -0
- package/dist/prosekit-react-resizable.js +28 -0
- package/dist/prosekit-react-tooltip.d.ts +3 -0
- package/dist/prosekit-react-tooltip.js +39 -0
- package/dist/prosekit-react.d.ts +6 -3
- package/dist/prosekit-react.js +284 -82
- package/package.json +40 -70
- package/dist/prosekit-react-autocomplete-empty.d.ts +0 -2
- package/dist/prosekit-react-autocomplete-empty.js +0 -17
- package/dist/prosekit-react-autocomplete-item.d.ts +0 -2
- package/dist/prosekit-react-autocomplete-item.js +0 -17
- package/dist/prosekit-react-autocomplete-list.d.ts +0 -2
- package/dist/prosekit-react-autocomplete-list.js +0 -17
- package/dist/prosekit-react-autocomplete-popover.d.ts +0 -3
- package/dist/prosekit-react-autocomplete-popover.js +0 -17
- package/dist/prosekit-react-combo-box-input.d.ts +0 -2
- package/dist/prosekit-react-combo-box-input.js +0 -17
- package/dist/prosekit-react-combo-box-item.d.ts +0 -2
- package/dist/prosekit-react-combo-box-item.js +0 -17
- package/dist/prosekit-react-combo-box-list.d.ts +0 -2
- package/dist/prosekit-react-combo-box-list.js +0 -17
- package/dist/prosekit-react-combo-box.d.ts +0 -2
- package/dist/prosekit-react-combo-box.js +0 -17
- package/src/index.ts +0 -10
@@ -1,17 +1,17 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
import
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
1
|
+
import {
|
2
|
+
createComponent
|
3
|
+
} from "./chunk-UG3RPLME.js";
|
4
|
+
import "./chunk-BH56NR2Q.js";
|
5
|
+
|
6
|
+
// src/components/inline-popover/inline-popover.gen.ts
|
7
|
+
import {
|
8
|
+
defaultInlinePopoverProps
|
9
|
+
} from "@prosekit/web/inline-popover";
|
10
|
+
var InlinePopover = createComponent(
|
11
|
+
"prosekit-inline-popover",
|
12
|
+
"InlinePopover",
|
13
|
+
defaultInlinePopoverProps
|
14
|
+
);
|
15
15
|
export {
|
16
16
|
InlinePopover
|
17
17
|
};
|
@@ -1,2 +1,3 @@
|
|
1
|
-
export {
|
2
|
-
export {
|
1
|
+
export { PopoverContent } from './_tsup-dts-rollup';
|
2
|
+
export { PopoverRoot } from './_tsup-dts-rollup';
|
3
|
+
export { PopoverTrigger } from './_tsup-dts-rollup';
|
@@ -1,17 +1,39 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
import
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
1
|
+
import {
|
2
|
+
createComponent
|
3
|
+
} from "./chunk-UG3RPLME.js";
|
4
|
+
import "./chunk-BH56NR2Q.js";
|
5
|
+
|
6
|
+
// src/components/popover/popover-content.gen.ts
|
7
|
+
import {
|
8
|
+
defaultPopoverContentProps
|
9
|
+
} from "@prosekit/web/popover";
|
10
|
+
var PopoverContent = createComponent(
|
11
|
+
"prosekit-popover-content",
|
12
|
+
"PopoverContent",
|
13
|
+
defaultPopoverContentProps
|
14
|
+
);
|
15
|
+
|
16
|
+
// src/components/popover/popover-root.gen.ts
|
17
|
+
import {
|
18
|
+
defaultPopoverRootProps
|
19
|
+
} from "@prosekit/web/popover";
|
20
|
+
var PopoverRoot = createComponent(
|
21
|
+
"prosekit-popover-root",
|
22
|
+
"PopoverRoot",
|
23
|
+
defaultPopoverRootProps
|
24
|
+
);
|
25
|
+
|
26
|
+
// src/components/popover/popover-trigger.gen.ts
|
27
|
+
import {
|
28
|
+
defaultPopoverTriggerProps
|
29
|
+
} from "@prosekit/web/popover";
|
30
|
+
var PopoverTrigger = createComponent(
|
31
|
+
"prosekit-popover-trigger",
|
32
|
+
"PopoverTrigger",
|
33
|
+
defaultPopoverTriggerProps
|
34
|
+
);
|
15
35
|
export {
|
16
|
-
|
36
|
+
PopoverContent,
|
37
|
+
PopoverRoot,
|
38
|
+
PopoverTrigger
|
17
39
|
};
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import {
|
2
|
+
createComponent
|
3
|
+
} from "./chunk-UG3RPLME.js";
|
4
|
+
import "./chunk-BH56NR2Q.js";
|
5
|
+
|
6
|
+
// src/components/resizable/resizable-handle.gen.ts
|
7
|
+
import {
|
8
|
+
defaultResizableHandleProps
|
9
|
+
} from "@prosekit/web/resizable";
|
10
|
+
var ResizableHandle = createComponent(
|
11
|
+
"prosekit-resizable-handle",
|
12
|
+
"ResizableHandle",
|
13
|
+
defaultResizableHandleProps
|
14
|
+
);
|
15
|
+
|
16
|
+
// src/components/resizable/resizable-root.gen.ts
|
17
|
+
import {
|
18
|
+
defaultResizableRootProps
|
19
|
+
} from "@prosekit/web/resizable";
|
20
|
+
var ResizableRoot = createComponent(
|
21
|
+
"prosekit-resizable-root",
|
22
|
+
"ResizableRoot",
|
23
|
+
defaultResizableRootProps
|
24
|
+
);
|
25
|
+
export {
|
26
|
+
ResizableHandle,
|
27
|
+
ResizableRoot
|
28
|
+
};
|
@@ -0,0 +1,39 @@
|
|
1
|
+
import {
|
2
|
+
createComponent
|
3
|
+
} from "./chunk-UG3RPLME.js";
|
4
|
+
import "./chunk-BH56NR2Q.js";
|
5
|
+
|
6
|
+
// src/components/tooltip/tooltip-content.gen.ts
|
7
|
+
import {
|
8
|
+
defaultTooltipContentProps
|
9
|
+
} from "@prosekit/web/tooltip";
|
10
|
+
var TooltipContent = createComponent(
|
11
|
+
"prosekit-tooltip-content",
|
12
|
+
"TooltipContent",
|
13
|
+
defaultTooltipContentProps
|
14
|
+
);
|
15
|
+
|
16
|
+
// src/components/tooltip/tooltip-root.gen.ts
|
17
|
+
import {
|
18
|
+
defaultTooltipRootProps
|
19
|
+
} from "@prosekit/web/tooltip";
|
20
|
+
var TooltipRoot = createComponent(
|
21
|
+
"prosekit-tooltip-root",
|
22
|
+
"TooltipRoot",
|
23
|
+
defaultTooltipRootProps
|
24
|
+
);
|
25
|
+
|
26
|
+
// src/components/tooltip/tooltip-trigger.gen.ts
|
27
|
+
import {
|
28
|
+
defaultTooltipTriggerProps
|
29
|
+
} from "@prosekit/web/tooltip";
|
30
|
+
var TooltipTrigger = createComponent(
|
31
|
+
"prosekit-tooltip-trigger",
|
32
|
+
"TooltipTrigger",
|
33
|
+
defaultTooltipTriggerProps
|
34
|
+
);
|
35
|
+
export {
|
36
|
+
TooltipContent,
|
37
|
+
TooltipRoot,
|
38
|
+
TooltipTrigger
|
39
|
+
};
|
package/dist/prosekit-react.d.ts
CHANGED
@@ -1,10 +1,13 @@
|
|
1
|
-
export { useNodeViewContext } from './_tsup-dts-rollup';
|
2
1
|
export { ProseKit } from './_tsup-dts-rollup';
|
3
2
|
export { ProseKitProps } from './_tsup-dts-rollup';
|
4
3
|
export { defineReactNodeView } from './_tsup-dts-rollup';
|
5
|
-
export { ReactNodeViewComponentProps } from './_tsup-dts-rollup';
|
6
4
|
export { ReactNodeViewOptions } from './_tsup-dts-rollup';
|
7
5
|
export { useEditor } from './_tsup-dts-rollup';
|
8
|
-
export { UseEditorOptions } from './_tsup-dts-rollup';
|
9
6
|
export { useExtension } from './_tsup-dts-rollup';
|
7
|
+
export { UseExtensionOptions } from './_tsup-dts-rollup';
|
10
8
|
export { useKeymap } from './_tsup-dts-rollup';
|
9
|
+
export { useStateUpdate } from './_tsup-dts-rollup';
|
10
|
+
export { useDocChange } from './_tsup-dts-rollup';
|
11
|
+
export { PropsWithClassName } from './_tsup-dts-rollup';
|
12
|
+
export { ReactNodeViewComponent } from './_tsup-dts-rollup';
|
13
|
+
export { ReactNodeViewProps } from './_tsup-dts-rollup';
|
package/dist/prosekit-react.js
CHANGED
@@ -1,79 +1,291 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
import {
|
2
|
+
EditorContextProvider,
|
3
|
+
useEditorContext
|
4
|
+
} from "./chunk-BH56NR2Q.js";
|
3
5
|
|
4
6
|
// src/components/prosekit.ts
|
5
7
|
import "@prosekit/core";
|
6
|
-
import {
|
7
|
-
ProsemirrorAdapterProvider,
|
8
|
-
useNodeViewFactory
|
9
|
-
} from "@prosemirror-adapter/react";
|
10
|
-
import { createElement as createElement2, useMemo } from "react";
|
8
|
+
import { createElement as createElement3 } from "react";
|
11
9
|
|
12
|
-
// src/
|
13
|
-
import {
|
14
|
-
var editorContext = createContext(null);
|
10
|
+
// src/views/react-views-consumer.ts
|
11
|
+
import { useMemo as useMemo2 } from "react";
|
15
12
|
|
16
13
|
// src/extensions/react-node-view.ts
|
17
|
-
import { defineNodeViewEffect } from "@prosekit/core";
|
18
14
|
import {
|
19
|
-
|
20
|
-
} from "@
|
21
|
-
import { createElement } from "react";
|
15
|
+
defineNodeViewFactory
|
16
|
+
} from "@prosekit/core";
|
22
17
|
function defineReactNodeView(options) {
|
23
|
-
|
18
|
+
const { name, ...userOptions } = options;
|
19
|
+
return defineNodeViewFactory({
|
24
20
|
group: "react",
|
25
|
-
name
|
26
|
-
args:
|
21
|
+
name,
|
22
|
+
args: userOptions
|
27
23
|
});
|
28
24
|
}
|
29
|
-
function
|
30
|
-
|
31
|
-
}) {
|
32
|
-
return defineNodeViewEffect({
|
25
|
+
function defineReactNodeViewFactory(nodeViewFactory) {
|
26
|
+
return defineNodeViewFactory({
|
33
27
|
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
|
-
}
|
28
|
+
factory: nodeViewFactory
|
50
29
|
});
|
51
30
|
}
|
52
31
|
|
53
32
|
// src/hooks/use-extension.ts
|
54
33
|
import "@prosekit/core";
|
55
|
-
|
34
|
+
|
35
|
+
// src/hooks/use-editor-extension.ts
|
36
|
+
import { EditorNotFoundError } from "@prosekit/core";
|
37
|
+
import { useEffect } from "react";
|
38
|
+
function useEditorExtension(editor, extension) {
|
39
|
+
if (!editor) {
|
40
|
+
throw new EditorNotFoundError();
|
41
|
+
}
|
42
|
+
useEffect(() => {
|
43
|
+
if (extension) {
|
44
|
+
return editor.use(extension);
|
45
|
+
}
|
46
|
+
}, [editor, extension]);
|
47
|
+
}
|
48
|
+
|
49
|
+
// src/hooks/use-priority-extension.ts
|
50
|
+
import { withPriority } from "@prosekit/core";
|
51
|
+
import { useMemo } from "react";
|
52
|
+
function usePriorityExtension(extension, priority) {
|
53
|
+
return useMemo(() => {
|
54
|
+
return extension && priority ? withPriority(extension, priority) : extension;
|
55
|
+
}, [extension, priority]);
|
56
|
+
}
|
57
|
+
|
58
|
+
// src/hooks/use-extension.ts
|
59
|
+
function useExtension(extension, options) {
|
60
|
+
const editorContext = useEditorContext();
|
61
|
+
useEditorExtension(
|
62
|
+
(options == null ? void 0 : options.editor) || editorContext,
|
63
|
+
usePriorityExtension(extension, options == null ? void 0 : options.priority)
|
64
|
+
);
|
65
|
+
}
|
66
|
+
|
67
|
+
// src/views/node-view/node-view-context.ts
|
68
|
+
import { ProseKitError } from "@prosekit/core";
|
69
|
+
import { createContext, useContext } from "react";
|
70
|
+
var createNodeViewContext = createContext(null);
|
71
|
+
function useNodeViewFactory() {
|
72
|
+
const nodeViewFactory = useContext(createNodeViewContext);
|
73
|
+
if (!nodeViewFactory) {
|
74
|
+
throw new ProseKitError("Cannot find node view factory context.");
|
75
|
+
}
|
76
|
+
return nodeViewFactory;
|
77
|
+
}
|
78
|
+
|
79
|
+
// src/views/react-views-consumer.ts
|
80
|
+
var ReactViewsConsumer = () => {
|
81
|
+
const nodeViewFactory = useNodeViewFactory();
|
82
|
+
const extension = useMemo2(
|
83
|
+
() => defineReactNodeViewFactory(nodeViewFactory),
|
84
|
+
[nodeViewFactory]
|
85
|
+
);
|
86
|
+
useExtension(extension);
|
87
|
+
return null;
|
88
|
+
};
|
89
|
+
|
90
|
+
// src/views/react-views-provider.ts
|
91
|
+
import { createElement as createElement2, useMemo as useMemo3 } from "react";
|
92
|
+
|
93
|
+
// src/views/node-view/use-react-node-view-creator.ts
|
94
|
+
import { useCallback } from "react";
|
95
|
+
|
96
|
+
// src/views/node-view/react-node-view.ts
|
97
|
+
import { _getId } from "@prosekit/core";
|
98
|
+
import { CoreNodeView } from "@prosemirror-adapter/core";
|
99
|
+
import { createElement } from "react";
|
100
|
+
import { createPortal } from "react-dom";
|
101
|
+
var ReactNodeView = class extends CoreNodeView {
|
102
|
+
constructor() {
|
103
|
+
super(...arguments);
|
104
|
+
this.key = _getId();
|
105
|
+
this.context = {
|
106
|
+
contentRef: (element) => {
|
107
|
+
if (element && this.contentDOM && element.firstChild !== this.contentDOM)
|
108
|
+
element.appendChild(this.contentDOM);
|
109
|
+
},
|
110
|
+
view: this.view,
|
111
|
+
getPos: this.getPos,
|
112
|
+
setAttrs: this.setAttrs,
|
113
|
+
node: this.node,
|
114
|
+
selected: this.selected,
|
115
|
+
decorations: this.decorations,
|
116
|
+
innerDecorations: this.innerDecorations
|
117
|
+
};
|
118
|
+
this.updateContext = () => {
|
119
|
+
Object.assign(this.context, {
|
120
|
+
node: this.node,
|
121
|
+
selected: this.selected,
|
122
|
+
decorations: this.decorations,
|
123
|
+
innerDecorations: this.innerDecorations
|
124
|
+
});
|
125
|
+
};
|
126
|
+
this.render = () => {
|
127
|
+
const UserComponent = this.component;
|
128
|
+
return createPortal(
|
129
|
+
createElement(UserComponent, this.context),
|
130
|
+
this.dom,
|
131
|
+
this.key
|
132
|
+
);
|
133
|
+
};
|
134
|
+
}
|
135
|
+
};
|
136
|
+
|
137
|
+
// src/views/node-view/use-react-node-view-creator.ts
|
138
|
+
function useReactNodeViewCreator(renderReactRenderer, removeReactRenderer) {
|
139
|
+
const createReactNodeView = useCallback(
|
140
|
+
(options) => (node, view, getPos, decorations, innerDecorations) => {
|
141
|
+
const nodeView = new ReactNodeView({
|
142
|
+
node,
|
143
|
+
view,
|
144
|
+
getPos,
|
145
|
+
decorations,
|
146
|
+
innerDecorations,
|
147
|
+
options: {
|
148
|
+
...options,
|
149
|
+
onUpdate() {
|
150
|
+
var _a;
|
151
|
+
(_a = options.onUpdate) == null ? void 0 : _a.call(options);
|
152
|
+
renderReactRenderer(nodeView);
|
153
|
+
},
|
154
|
+
selectNode() {
|
155
|
+
var _a;
|
156
|
+
(_a = options.selectNode) == null ? void 0 : _a.call(options);
|
157
|
+
renderReactRenderer(nodeView);
|
158
|
+
},
|
159
|
+
deselectNode() {
|
160
|
+
var _a;
|
161
|
+
(_a = options.deselectNode) == null ? void 0 : _a.call(options);
|
162
|
+
renderReactRenderer(nodeView);
|
163
|
+
},
|
164
|
+
destroy() {
|
165
|
+
var _a;
|
166
|
+
(_a = options.destroy) == null ? void 0 : _a.call(options);
|
167
|
+
removeReactRenderer(nodeView);
|
168
|
+
}
|
169
|
+
}
|
170
|
+
});
|
171
|
+
renderReactRenderer(nodeView, false);
|
172
|
+
return nodeView;
|
173
|
+
},
|
174
|
+
[removeReactRenderer, renderReactRenderer]
|
175
|
+
);
|
176
|
+
return createReactNodeView;
|
177
|
+
}
|
178
|
+
|
179
|
+
// src/views/react-renderer.ts
|
180
|
+
import { useCallback as useCallback2, useEffect as useEffect2, useRef, useState } from "react";
|
181
|
+
import { flushSync } from "react-dom";
|
182
|
+
function useReactRenderer() {
|
183
|
+
const [portals, setPortals] = useState({});
|
184
|
+
const mountedRef = useRef(false);
|
185
|
+
useEffect2(() => {
|
186
|
+
requestAnimationFrame(() => {
|
187
|
+
mountedRef.current = true;
|
188
|
+
});
|
189
|
+
return () => {
|
190
|
+
mountedRef.current = false;
|
191
|
+
};
|
192
|
+
}, []);
|
193
|
+
const maybeFlushSync = useCallback2((fn) => {
|
194
|
+
if (mountedRef.current)
|
195
|
+
flushSync(fn);
|
196
|
+
else
|
197
|
+
fn();
|
198
|
+
}, []);
|
199
|
+
const renderReactRenderer = useCallback2(
|
200
|
+
(nodeView, update = true) => {
|
201
|
+
maybeFlushSync(() => {
|
202
|
+
if (update)
|
203
|
+
nodeView.updateContext();
|
204
|
+
setPortals((prev) => ({
|
205
|
+
...prev,
|
206
|
+
[nodeView.key]: nodeView.render()
|
207
|
+
}));
|
208
|
+
});
|
209
|
+
},
|
210
|
+
[maybeFlushSync]
|
211
|
+
);
|
212
|
+
const removeReactRenderer = useCallback2(
|
213
|
+
(nodeView) => {
|
214
|
+
maybeFlushSync(() => {
|
215
|
+
setPortals((prev) => {
|
216
|
+
const next = { ...prev };
|
217
|
+
delete next[nodeView.key];
|
218
|
+
return next;
|
219
|
+
});
|
220
|
+
});
|
221
|
+
},
|
222
|
+
[maybeFlushSync]
|
223
|
+
);
|
224
|
+
return {
|
225
|
+
portals,
|
226
|
+
renderReactRenderer,
|
227
|
+
removeReactRenderer
|
228
|
+
};
|
229
|
+
}
|
230
|
+
|
231
|
+
// src/views/react-views-provider.ts
|
232
|
+
var ReactViewsProvider = ({
|
233
|
+
children
|
234
|
+
}) => {
|
235
|
+
const { renderReactRenderer, removeReactRenderer, portals } = useReactRenderer();
|
236
|
+
const createReactNodeView = useReactNodeViewCreator(
|
237
|
+
renderReactRenderer,
|
238
|
+
removeReactRenderer
|
239
|
+
);
|
240
|
+
const memoizedPortals = useMemo3(() => Object.values(portals), [portals]);
|
241
|
+
return createElement2(
|
242
|
+
createNodeViewContext.Provider,
|
243
|
+
{ value: createReactNodeView },
|
244
|
+
children,
|
245
|
+
memoizedPortals
|
246
|
+
);
|
247
|
+
};
|
248
|
+
|
249
|
+
// src/components/prosekit.ts
|
250
|
+
var ProseKit = (props) => {
|
251
|
+
const { editor, children } = props;
|
252
|
+
return createElement3(
|
253
|
+
ReactViewsProvider,
|
254
|
+
null,
|
255
|
+
createElement3(
|
256
|
+
EditorContextProvider,
|
257
|
+
{ value: editor },
|
258
|
+
createElement3(ReactViewsConsumer),
|
259
|
+
children
|
260
|
+
)
|
261
|
+
);
|
262
|
+
};
|
56
263
|
|
57
264
|
// src/hooks/use-editor.ts
|
58
265
|
import {
|
59
|
-
ProseKitError,
|
60
|
-
|
266
|
+
ProseKitError as ProseKitError2,
|
267
|
+
defineMountHandler,
|
268
|
+
defineUpdateHandler,
|
269
|
+
union
|
61
270
|
} from "@prosekit/core";
|
62
|
-
import {
|
271
|
+
import { useEffect as useEffect3, useReducer } from "react";
|
63
272
|
function useEditor(options) {
|
64
273
|
var _a;
|
65
274
|
const update = (_a = options == null ? void 0 : options.update) != null ? _a : false;
|
66
|
-
const
|
67
|
-
if (!
|
68
|
-
throw new
|
275
|
+
const editor = useEditorContext();
|
276
|
+
if (!editor) {
|
277
|
+
throw new ProseKitError2(
|
69
278
|
"useEditor must be used within the ProseKit component"
|
70
279
|
);
|
71
280
|
}
|
72
|
-
const editor = value.editor;
|
73
281
|
const forceUpdate = useForceUpdate();
|
74
|
-
|
282
|
+
useEffect3(() => {
|
75
283
|
if (update) {
|
76
|
-
|
284
|
+
const extension = union([
|
285
|
+
defineMountHandler(forceUpdate),
|
286
|
+
defineUpdateHandler(forceUpdate)
|
287
|
+
]);
|
288
|
+
return editor.use(extension);
|
77
289
|
}
|
78
290
|
}, [editor, update, forceUpdate]);
|
79
291
|
return editor;
|
@@ -83,51 +295,41 @@ function useForceUpdate() {
|
|
83
295
|
return dispatch;
|
84
296
|
}
|
85
297
|
|
86
|
-
// src/hooks/use-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
298
|
+
// src/hooks/use-keymap.ts
|
299
|
+
import { defineKeymap } from "@prosekit/core";
|
300
|
+
import { useMemo as useMemo4 } from "react";
|
301
|
+
function useKeymap(keymap, options) {
|
302
|
+
const extension = useMemo4(() => defineKeymap(keymap), [keymap]);
|
303
|
+
return useExtension(extension, options);
|
92
304
|
}
|
93
305
|
|
94
|
-
// src/
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
EditorContextProvider,
|
102
|
-
{ value: { editor } },
|
103
|
-
children,
|
104
|
-
createElement2(RendererRegister)
|
105
|
-
)
|
306
|
+
// src/hooks/use-state-update.ts
|
307
|
+
import { defineUpdateHandler as defineUpdateHandler2 } from "@prosekit/core";
|
308
|
+
import { useMemo as useMemo5 } from "react";
|
309
|
+
function useStateUpdate(handler, options) {
|
310
|
+
const extension = useMemo5(
|
311
|
+
() => defineUpdateHandler2((view) => handler(view.state)),
|
312
|
+
[handler]
|
106
313
|
);
|
107
|
-
|
108
|
-
function RendererRegister() {
|
109
|
-
const nodeViewFactory = useNodeViewFactory();
|
110
|
-
const extension = useMemo(
|
111
|
-
() => defineReactNodeViewRenderer({ nodeViewFactory }),
|
112
|
-
[nodeViewFactory]
|
113
|
-
);
|
114
|
-
useExtension(extension);
|
115
|
-
return null;
|
314
|
+
return useExtension(extension, options);
|
116
315
|
}
|
117
|
-
var EditorContextProvider = editorContext.Provider;
|
118
316
|
|
119
|
-
// src/hooks/use-
|
120
|
-
import {
|
121
|
-
import { useMemo as
|
122
|
-
function
|
123
|
-
const extension =
|
124
|
-
|
317
|
+
// src/hooks/use-doc-change.ts
|
318
|
+
import { defineDocChangeHandler } from "@prosekit/core";
|
319
|
+
import { useMemo as useMemo6 } from "react";
|
320
|
+
function useDocChange(handler, options) {
|
321
|
+
const extension = useMemo6(
|
322
|
+
() => defineDocChangeHandler((view) => handler(view.state.doc)),
|
323
|
+
[handler]
|
324
|
+
);
|
325
|
+
return useExtension(extension, options);
|
125
326
|
}
|
126
327
|
export {
|
127
328
|
ProseKit,
|
128
329
|
defineReactNodeView,
|
330
|
+
useDocChange,
|
129
331
|
useEditor,
|
130
332
|
useExtension,
|
131
333
|
useKeymap,
|
132
|
-
|
334
|
+
useStateUpdate
|
133
335
|
};
|