@prosekit/react 0.0.0-next-20230709094459 → 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 +343 -0
- 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 +1 -0
- package/dist/prosekit-react-inline-popover.js +17 -0
- package/dist/prosekit-react-popover.d.ts +3 -0
- package/dist/prosekit-react-popover.js +39 -0
- 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 +13 -21
- package/dist/prosekit-react.js +317 -31
- package/package.json +52 -33
- package/dist/prosekit-react-components-menu-item.d.ts +0 -6
- package/dist/prosekit-react-components-menu-item.js +0 -13
- package/dist/prosekit-react-components-menu.d.ts +0 -16
- package/dist/prosekit-react-components-menu.js +0 -16
- package/dist/prosekit-react-components-popover-suggestion.d.ts +0 -16
- package/dist/prosekit-react-components-popover-suggestion.js +0 -27
- package/dist/prosekit-react-components-popover.d.ts +0 -6
- package/dist/prosekit-react-components-popover.js +0 -13
- package/src/index.ts +0 -8
@@ -0,0 +1,343 @@
|
|
1
|
+
/// <reference types="react" />
|
2
|
+
|
3
|
+
import type { Attrs } from '@prosekit/pm/model';
|
4
|
+
import { AutocompleteEmptyElement } from '@prosekit/web/autocomplete';
|
5
|
+
import { AutocompleteEmptyProps } from '@prosekit/web/autocomplete';
|
6
|
+
import { AutocompleteItemElement } from '@prosekit/web/autocomplete';
|
7
|
+
import { AutocompleteItemProps } from '@prosekit/web/autocomplete';
|
8
|
+
import { AutocompleteListElement } from '@prosekit/web/autocomplete';
|
9
|
+
import { AutocompleteListProps } from '@prosekit/web/autocomplete';
|
10
|
+
import { AutocompletePopoverElement } from '@prosekit/web/autocomplete';
|
11
|
+
import { AutocompletePopoverProps } from '@prosekit/web/autocomplete';
|
12
|
+
import { BaseNodeViewOptions } from '@prosekit/core';
|
13
|
+
import { BlockDragHandleElement } from '@prosekit/web/block-handle';
|
14
|
+
import { BlockDragHandleProps } from '@prosekit/web/block-handle';
|
15
|
+
import { BlockPopoverElement } from '@prosekit/web/block-handle';
|
16
|
+
import { BlockPopoverProps } from '@prosekit/web/block-handle';
|
17
|
+
import { CommandArgs } from '@prosekit/core';
|
18
|
+
import { ComponentType } from 'react';
|
19
|
+
import { Context } from 'react';
|
20
|
+
import { CoreNodeView } from '@prosemirror-adapter/core';
|
21
|
+
import type { CoreNodeViewSpec } from '@prosemirror-adapter/core';
|
22
|
+
import type { CoreNodeViewUserOptions } from '@prosemirror-adapter/core';
|
23
|
+
import type { Decoration } from '@prosekit/pm/view';
|
24
|
+
import type { DecorationSource } from '@prosekit/pm/view';
|
25
|
+
import { Editor } from '@prosekit/core';
|
26
|
+
import type { EditorState } from '@prosekit/pm/state';
|
27
|
+
import type { EditorView } from '@prosekit/pm/view';
|
28
|
+
import { Extension } from '@prosekit/core';
|
29
|
+
import { ExtensionTyping } from '@prosekit/core';
|
30
|
+
import { FC } from 'react';
|
31
|
+
import { ForwardRefExoticComponent } from 'react';
|
32
|
+
import { HTMLAttributes } from 'react';
|
33
|
+
import { InlinePopoverElement } from '@prosekit/web/inline-popover';
|
34
|
+
import { InlinePopoverProps } from '@prosekit/web/inline-popover';
|
35
|
+
import { Keymap } from '@prosekit/core';
|
36
|
+
import type { Node as Node_2 } from '@prosekit/pm/model';
|
37
|
+
import type { NodeViewConstructor } from '@prosekit/pm/view';
|
38
|
+
import { Options } from 'tsup';
|
39
|
+
import { PopoverContentElement } from '@prosekit/web/popover';
|
40
|
+
import { PopoverContentProps } from '@prosekit/web/popover';
|
41
|
+
import { PopoverRootElement } from '@prosekit/web/popover';
|
42
|
+
import { PopoverRootProps } from '@prosekit/web/popover';
|
43
|
+
import { PopoverTriggerElement } from '@prosekit/web/popover';
|
44
|
+
import { PopoverTriggerProps } from '@prosekit/web/popover';
|
45
|
+
import { Priority } from '@prosekit/core';
|
46
|
+
import type { ProseMirrorNode } from '@prosekit/pm/model';
|
47
|
+
import { Provider } from 'react';
|
48
|
+
import { ReactNode } from 'react';
|
49
|
+
import { ReactPortal } from 'react';
|
50
|
+
import { RefAttributes } from 'react';
|
51
|
+
import { ResizableHandleElement } from '@prosekit/web/resizable';
|
52
|
+
import { ResizableHandleProps } from '@prosekit/web/resizable';
|
53
|
+
import { ResizableRootElement } from '@prosekit/web/resizable';
|
54
|
+
import { ResizableRootProps } from '@prosekit/web/resizable';
|
55
|
+
import { TooltipContentElement } from '@prosekit/web/tooltip';
|
56
|
+
import { TooltipContentProps } from '@prosekit/web/tooltip';
|
57
|
+
import { TooltipRootElement } from '@prosekit/web/tooltip';
|
58
|
+
import { TooltipRootProps } from '@prosekit/web/tooltip';
|
59
|
+
import { TooltipTriggerElement } from '@prosekit/web/tooltip';
|
60
|
+
import { TooltipTriggerProps } from '@prosekit/web/tooltip';
|
61
|
+
|
62
|
+
declare const AutocompleteEmpty: ForwardRefExoticComponent<Partial<AutocompleteEmptyProps> & RefAttributes<AutocompleteEmptyElement> & HTMLAttributes<AutocompleteEmptyElement>>;
|
63
|
+
export { AutocompleteEmpty }
|
64
|
+
export { AutocompleteEmpty as AutocompleteEmpty_alias_1 }
|
65
|
+
|
66
|
+
declare const AutocompleteItem: ForwardRefExoticComponent<Partial<AutocompleteItemProps> & RefAttributes<AutocompleteItemElement> & HTMLAttributes<AutocompleteItemElement>>;
|
67
|
+
export { AutocompleteItem }
|
68
|
+
export { AutocompleteItem as AutocompleteItem_alias_1 }
|
69
|
+
|
70
|
+
declare const AutocompleteList: ForwardRefExoticComponent<Partial<AutocompleteListProps> & RefAttributes<AutocompleteListElement> & HTMLAttributes<AutocompleteListElement>>;
|
71
|
+
export { AutocompleteList }
|
72
|
+
export { AutocompleteList as AutocompleteList_alias_1 }
|
73
|
+
|
74
|
+
declare const AutocompletePopover: ForwardRefExoticComponent<Partial<AutocompletePopoverProps> & RefAttributes<AutocompletePopoverElement> & HTMLAttributes<AutocompletePopoverElement>>;
|
75
|
+
export { AutocompletePopover }
|
76
|
+
export { AutocompletePopover as AutocompletePopover_alias_1 }
|
77
|
+
|
78
|
+
declare const BlockDragHandle: ForwardRefExoticComponent<Partial<BlockDragHandleProps> & RefAttributes<BlockDragHandleElement> & HTMLAttributes<BlockDragHandleElement>>;
|
79
|
+
export { BlockDragHandle }
|
80
|
+
export { BlockDragHandle as BlockDragHandle_alias_1 }
|
81
|
+
|
82
|
+
declare const BlockPopover: ForwardRefExoticComponent<Partial<BlockPopoverProps> & RefAttributes<BlockPopoverElement> & HTMLAttributes<BlockPopoverElement>>;
|
83
|
+
export { BlockPopover }
|
84
|
+
export { BlockPopover as BlockPopover_alias_1 }
|
85
|
+
|
86
|
+
export declare function createComponent<Props extends object, CustomElement extends HTMLElement>(tagName: string, displayName: string, defaultProps: Props): ForwardRefExoticComponent<Partial<Props> & RefAttributes<CustomElement> & HTMLAttributes<CustomElement>>;
|
87
|
+
|
88
|
+
export declare const createNodeViewContext: Context<NodeViewFactory | null>;
|
89
|
+
|
90
|
+
declare type CreateReactNodeView = ReturnType<typeof useReactNodeViewCreator>;
|
91
|
+
export { CreateReactNodeView }
|
92
|
+
export { CreateReactNodeView as CreateReactNodeView_alias_1 }
|
93
|
+
|
94
|
+
export declare const default_alias: Options | Options[] | ((overrideOptions: Options) => Options | Options[] | Promise<Options | Options[]>);
|
95
|
+
|
96
|
+
export declare const default_alias_1: {
|
97
|
+
test: {
|
98
|
+
environment: "jsdom";
|
99
|
+
};
|
100
|
+
};
|
101
|
+
|
102
|
+
/**
|
103
|
+
* Defines a node view using a React component.
|
104
|
+
*
|
105
|
+
* @public
|
106
|
+
*/
|
107
|
+
declare function defineReactNodeView(options: ReactNodeViewOptions): Extension;
|
108
|
+
export { defineReactNodeView }
|
109
|
+
export { defineReactNodeView as defineReactNodeView_alias_1 }
|
110
|
+
|
111
|
+
/**
|
112
|
+
* @internal
|
113
|
+
*/
|
114
|
+
export declare function defineReactNodeViewFactory(nodeViewFactory: NodeViewFactory): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
115
|
+
|
116
|
+
/**
|
117
|
+
* @internal
|
118
|
+
*/
|
119
|
+
export declare const EditorContextProvider: Provider<Editor<any> | null>;
|
120
|
+
|
121
|
+
declare const InlinePopover: ForwardRefExoticComponent<Partial<InlinePopoverProps> & RefAttributes<InlinePopoverElement> & HTMLAttributes<InlinePopoverElement>>;
|
122
|
+
export { InlinePopover }
|
123
|
+
export { InlinePopover as InlinePopover_alias_1 }
|
124
|
+
|
125
|
+
export declare type NodeViewFactory = (options: ReactNodeViewUserOptions) => NodeViewConstructor;
|
126
|
+
|
127
|
+
declare const PopoverContent: ForwardRefExoticComponent<Partial<PopoverContentProps> & RefAttributes<PopoverContentElement> & HTMLAttributes<PopoverContentElement>>;
|
128
|
+
export { PopoverContent }
|
129
|
+
export { PopoverContent as PopoverContent_alias_1 }
|
130
|
+
|
131
|
+
declare const PopoverRoot: ForwardRefExoticComponent<Partial<PopoverRootProps> & RefAttributes<PopoverRootElement> & HTMLAttributes<PopoverRootElement>>;
|
132
|
+
export { PopoverRoot }
|
133
|
+
export { PopoverRoot as PopoverRoot_alias_1 }
|
134
|
+
|
135
|
+
declare const PopoverTrigger: ForwardRefExoticComponent<Partial<PopoverTriggerProps> & RefAttributes<PopoverTriggerElement> & HTMLAttributes<PopoverTriggerElement>>;
|
136
|
+
export { PopoverTrigger }
|
137
|
+
export { PopoverTrigger as PopoverTrigger_alias_1 }
|
138
|
+
|
139
|
+
/**
|
140
|
+
* @internal
|
141
|
+
*/
|
142
|
+
declare type PropsWithClassName<P = unknown> = P & {
|
143
|
+
className?: string | undefined;
|
144
|
+
};
|
145
|
+
export { PropsWithClassName }
|
146
|
+
export { PropsWithClassName as PropsWithClassName_alias_1 }
|
147
|
+
|
148
|
+
/**
|
149
|
+
* The root component for a ProseKit editor.
|
150
|
+
*
|
151
|
+
* @public
|
152
|
+
*/
|
153
|
+
declare const ProseKit: ComponentType<ProseKitProps>;
|
154
|
+
export { ProseKit }
|
155
|
+
export { ProseKit as ProseKit_alias_1 }
|
156
|
+
|
157
|
+
declare interface ProseKitProps {
|
158
|
+
editor: Editor;
|
159
|
+
children?: ReactNode;
|
160
|
+
}
|
161
|
+
export { ProseKitProps }
|
162
|
+
export { ProseKitProps as ProseKitProps_alias_1 }
|
163
|
+
|
164
|
+
export declare class ReactNodeView extends CoreNodeView<ReactNodeViewComponent> implements ReactRenderer<ReactNodeViewProps> {
|
165
|
+
key: string;
|
166
|
+
context: ReactNodeViewProps;
|
167
|
+
updateContext: () => void;
|
168
|
+
render: () => ReactPortal;
|
169
|
+
}
|
170
|
+
|
171
|
+
/**
|
172
|
+
* @public
|
173
|
+
*/
|
174
|
+
declare type ReactNodeViewComponent = ComponentType<ReactNodeViewProps>;
|
175
|
+
export { ReactNodeViewComponent }
|
176
|
+
export { ReactNodeViewComponent as ReactNodeViewComponent_alias_1 }
|
177
|
+
|
178
|
+
/**
|
179
|
+
* Options for {@link defineReactNodeView}.
|
180
|
+
*
|
181
|
+
* @public
|
182
|
+
*/
|
183
|
+
declare interface ReactNodeViewOptions extends BaseNodeViewOptions {
|
184
|
+
/**
|
185
|
+
* The name of the node type.
|
186
|
+
*/
|
187
|
+
name: string;
|
188
|
+
/**
|
189
|
+
* The React component to render the node.
|
190
|
+
*/
|
191
|
+
component: ReactNodeViewComponent;
|
192
|
+
}
|
193
|
+
export { ReactNodeViewOptions }
|
194
|
+
export { ReactNodeViewOptions as ReactNodeViewOptions_alias_1 }
|
195
|
+
|
196
|
+
/**
|
197
|
+
* @public
|
198
|
+
*/
|
199
|
+
declare interface ReactNodeViewProps {
|
200
|
+
contentRef: (node: HTMLElement | null) => void;
|
201
|
+
view: EditorView;
|
202
|
+
getPos: () => number | undefined;
|
203
|
+
setAttrs: (attrs: Attrs) => void;
|
204
|
+
node: Node_2;
|
205
|
+
selected: boolean;
|
206
|
+
decorations: readonly Decoration[];
|
207
|
+
innerDecorations: DecorationSource;
|
208
|
+
}
|
209
|
+
export { ReactNodeViewProps }
|
210
|
+
export { ReactNodeViewProps as ReactNodeViewProps_alias_1 }
|
211
|
+
|
212
|
+
export declare type ReactNodeViewSpec = CoreNodeViewSpec<ReactNodeViewComponent>;
|
213
|
+
|
214
|
+
export declare type ReactNodeViewUserOptions = CoreNodeViewUserOptions<ReactNodeViewComponent>;
|
215
|
+
|
216
|
+
export declare interface ReactRenderer<Context> {
|
217
|
+
key: string;
|
218
|
+
context: Context;
|
219
|
+
render: () => ReactPortal;
|
220
|
+
updateContext: () => void;
|
221
|
+
}
|
222
|
+
|
223
|
+
export declare interface ReactRendererResult {
|
224
|
+
readonly portals: Record<string, ReactPortal>;
|
225
|
+
readonly renderReactRenderer: (nodeView: ReactRenderer<unknown>, update?: boolean) => void;
|
226
|
+
readonly removeReactRenderer: (nodeView: ReactRenderer<unknown>) => void;
|
227
|
+
}
|
228
|
+
|
229
|
+
export declare const ReactViewsConsumer: FC;
|
230
|
+
|
231
|
+
declare const ReactViewsProvider: FC<{
|
232
|
+
children: ReactNode;
|
233
|
+
}>;
|
234
|
+
export { ReactViewsProvider }
|
235
|
+
export { ReactViewsProvider as ReactViewsProvider_alias_1 }
|
236
|
+
|
237
|
+
declare const ResizableHandle: ForwardRefExoticComponent<Partial<ResizableHandleProps> & RefAttributes<ResizableHandleElement> & HTMLAttributes<ResizableHandleElement>>;
|
238
|
+
export { ResizableHandle }
|
239
|
+
export { ResizableHandle as ResizableHandle_alias_1 }
|
240
|
+
|
241
|
+
declare const ResizableRoot: ForwardRefExoticComponent<Partial<ResizableRootProps> & RefAttributes<ResizableRootElement> & HTMLAttributes<ResizableRootElement>>;
|
242
|
+
export { ResizableRoot }
|
243
|
+
export { ResizableRoot as ResizableRoot_alias_1 }
|
244
|
+
|
245
|
+
declare const TooltipContent: ForwardRefExoticComponent<Partial<TooltipContentProps> & RefAttributes<TooltipContentElement> & HTMLAttributes<TooltipContentElement>>;
|
246
|
+
export { TooltipContent }
|
247
|
+
export { TooltipContent as TooltipContent_alias_1 }
|
248
|
+
|
249
|
+
declare const TooltipRoot: ForwardRefExoticComponent<Partial<TooltipRootProps> & RefAttributes<TooltipRootElement> & HTMLAttributes<TooltipRootElement>>;
|
250
|
+
export { TooltipRoot }
|
251
|
+
export { TooltipRoot as TooltipRoot_alias_1 }
|
252
|
+
|
253
|
+
declare const TooltipTrigger: ForwardRefExoticComponent<Partial<TooltipTriggerProps> & RefAttributes<TooltipTriggerElement> & HTMLAttributes<TooltipTriggerElement>>;
|
254
|
+
export { TooltipTrigger }
|
255
|
+
export { TooltipTrigger as TooltipTrigger_alias_1 }
|
256
|
+
|
257
|
+
/**
|
258
|
+
* Calls the given handler whenever the editor document changes.
|
259
|
+
*
|
260
|
+
* @public
|
261
|
+
*/
|
262
|
+
declare function useDocChange(handler: (doc: ProseMirrorNode) => void, options?: UseExtensionOptions): void;
|
263
|
+
export { useDocChange }
|
264
|
+
export { useDocChange as useDocChange_alias_1 }
|
265
|
+
|
266
|
+
/**
|
267
|
+
* Retrieves the editor instance from the nearest ProseKit component.
|
268
|
+
*
|
269
|
+
* @public
|
270
|
+
*/
|
271
|
+
declare function useEditor<E extends Extension = any>(options?: {
|
272
|
+
/**
|
273
|
+
* Whether to update the component when the editor is mounted or editor state
|
274
|
+
* is updated.
|
275
|
+
*
|
276
|
+
* @default false
|
277
|
+
*/
|
278
|
+
update?: boolean;
|
279
|
+
}): Editor<E>;
|
280
|
+
export { useEditor }
|
281
|
+
export { useEditor as useEditor_alias_1 }
|
282
|
+
|
283
|
+
/**
|
284
|
+
* @internal
|
285
|
+
*/
|
286
|
+
export declare function useEditorContext<E extends Extension>(): Editor<E> | null;
|
287
|
+
|
288
|
+
/**
|
289
|
+
* @internal
|
290
|
+
*/
|
291
|
+
export declare function useEditorExtension(editor: Editor | null | undefined, extension: Extension | null): void;
|
292
|
+
|
293
|
+
/**
|
294
|
+
* Add an extension to the editor.
|
295
|
+
*/
|
296
|
+
declare function useExtension(
|
297
|
+
/**
|
298
|
+
* The extension to add to the editor. If it changes, the previous
|
299
|
+
* extension will be removed and the new one (if not null) will be added.
|
300
|
+
*/
|
301
|
+
extension: Extension | null, options?: UseExtensionOptions): void;
|
302
|
+
export { useExtension }
|
303
|
+
export { useExtension as useExtension_alias_1 }
|
304
|
+
|
305
|
+
declare interface UseExtensionOptions {
|
306
|
+
/**
|
307
|
+
* The editor to add the extension to. If not provided, it will use the
|
308
|
+
* editor from the nearest `ProseKit` component.
|
309
|
+
*/
|
310
|
+
editor?: Editor;
|
311
|
+
/**
|
312
|
+
* Optional priority to add the extension with.
|
313
|
+
*/
|
314
|
+
priority?: Priority;
|
315
|
+
}
|
316
|
+
export { UseExtensionOptions }
|
317
|
+
export { UseExtensionOptions as UseExtensionOptions_alias_1 }
|
318
|
+
|
319
|
+
declare function useKeymap(keymap: Keymap, options?: UseExtensionOptions): void;
|
320
|
+
export { useKeymap }
|
321
|
+
export { useKeymap as useKeymap_alias_1 }
|
322
|
+
|
323
|
+
export declare function useNodeViewFactory(): NodeViewFactory;
|
324
|
+
|
325
|
+
/**
|
326
|
+
* @internal
|
327
|
+
*/
|
328
|
+
export declare function usePriorityExtension<T extends Extension = Extension>(extension: T | null, priority?: Priority | null): T | null;
|
329
|
+
|
330
|
+
export declare function useReactNodeViewCreator(renderReactRenderer: ReactRendererResult['renderReactRenderer'], removeReactRenderer: ReactRendererResult['removeReactRenderer']): (options: ReactNodeViewUserOptions) => NodeViewConstructor;
|
331
|
+
|
332
|
+
export declare function useReactRenderer(): ReactRendererResult;
|
333
|
+
|
334
|
+
/**
|
335
|
+
* Calls the given handler whenever the editor state changes.
|
336
|
+
*
|
337
|
+
* @public
|
338
|
+
*/
|
339
|
+
declare function useStateUpdate(handler: (state: EditorState) => void, options?: UseExtensionOptions): void;
|
340
|
+
export { useStateUpdate }
|
341
|
+
export { useStateUpdate as useStateUpdate_alias_1 }
|
342
|
+
|
343
|
+
export { }
|
@@ -0,0 +1,12 @@
|
|
1
|
+
// src/contexts/editor-context.ts
|
2
|
+
import { createContext, useContext } from "react";
|
3
|
+
var editorContext = createContext(null);
|
4
|
+
function useEditorContext() {
|
5
|
+
return useContext(editorContext);
|
6
|
+
}
|
7
|
+
var EditorContextProvider = editorContext.Provider;
|
8
|
+
|
9
|
+
export {
|
10
|
+
useEditorContext,
|
11
|
+
EditorContextProvider
|
12
|
+
};
|
@@ -0,0 +1,51 @@
|
|
1
|
+
import {
|
2
|
+
useEditorContext
|
3
|
+
} from "./chunk-BH56NR2Q.js";
|
4
|
+
|
5
|
+
// src/components/create-component.ts
|
6
|
+
import {
|
7
|
+
createElement,
|
8
|
+
forwardRef,
|
9
|
+
useLayoutEffect,
|
10
|
+
useState
|
11
|
+
} from "react";
|
12
|
+
import { mergeRefs } from "react-merge-refs";
|
13
|
+
function createComponent(tagName, displayName, defaultProps) {
|
14
|
+
const propertyNames = Object.keys(defaultProps);
|
15
|
+
const hasEditor = Object.hasOwn(defaultProps, "editor");
|
16
|
+
const Component = forwardRef((props, ref) => {
|
17
|
+
const [el, setEl] = useState(null);
|
18
|
+
const properties = {};
|
19
|
+
const attributes = {};
|
20
|
+
for (const [name, value] of Object.entries(props)) {
|
21
|
+
if (propertyNames.includes(name)) {
|
22
|
+
properties[name] = value;
|
23
|
+
} else {
|
24
|
+
attributes[name === "className" ? "class" : name] = value;
|
25
|
+
}
|
26
|
+
}
|
27
|
+
const editor = useEditorContext();
|
28
|
+
if (hasEditor && editor && !properties["editor"]) {
|
29
|
+
properties["editor"] = editor;
|
30
|
+
}
|
31
|
+
useLayoutEffect(() => {
|
32
|
+
if (el) {
|
33
|
+
for (const [name, value] of Object.entries(properties)) {
|
34
|
+
if (value !== void 0) {
|
35
|
+
el[name] = value;
|
36
|
+
}
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}, [el, ...propertyNames.map((name) => properties[name])]);
|
40
|
+
return createElement(tagName, {
|
41
|
+
...attributes,
|
42
|
+
ref: mergeRefs([ref, setEl])
|
43
|
+
});
|
44
|
+
});
|
45
|
+
Component.displayName = displayName;
|
46
|
+
return Component;
|
47
|
+
}
|
48
|
+
|
49
|
+
export {
|
50
|
+
createComponent
|
51
|
+
};
|
@@ -0,0 +1,4 @@
|
|
1
|
+
export { AutocompleteEmpty_alias_1 as AutocompleteEmpty } from './_tsup-dts-rollup';
|
2
|
+
export { AutocompleteItem_alias_1 as AutocompleteItem } from './_tsup-dts-rollup';
|
3
|
+
export { AutocompleteList_alias_1 as AutocompleteList } from './_tsup-dts-rollup';
|
4
|
+
export { AutocompletePopover_alias_1 as AutocompletePopover } from './_tsup-dts-rollup';
|
@@ -0,0 +1,50 @@
|
|
1
|
+
import {
|
2
|
+
createComponent
|
3
|
+
} from "./chunk-UG3RPLME.js";
|
4
|
+
import "./chunk-BH56NR2Q.js";
|
5
|
+
|
6
|
+
// src/components/autocomplete/autocomplete-empty.gen.ts
|
7
|
+
import {
|
8
|
+
defaultAutocompleteEmptyProps
|
9
|
+
} from "@prosekit/web/autocomplete";
|
10
|
+
var AutocompleteEmpty = createComponent(
|
11
|
+
"prosekit-autocomplete-empty",
|
12
|
+
"AutocompleteEmpty",
|
13
|
+
defaultAutocompleteEmptyProps
|
14
|
+
);
|
15
|
+
|
16
|
+
// src/components/autocomplete/autocomplete-item.gen.ts
|
17
|
+
import {
|
18
|
+
defaultAutocompleteItemProps
|
19
|
+
} from "@prosekit/web/autocomplete";
|
20
|
+
var AutocompleteItem = createComponent(
|
21
|
+
"prosekit-autocomplete-item",
|
22
|
+
"AutocompleteItem",
|
23
|
+
defaultAutocompleteItemProps
|
24
|
+
);
|
25
|
+
|
26
|
+
// src/components/autocomplete/autocomplete-list.gen.ts
|
27
|
+
import {
|
28
|
+
defaultAutocompleteListProps
|
29
|
+
} from "@prosekit/web/autocomplete";
|
30
|
+
var AutocompleteList = createComponent(
|
31
|
+
"prosekit-autocomplete-list",
|
32
|
+
"AutocompleteList",
|
33
|
+
defaultAutocompleteListProps
|
34
|
+
);
|
35
|
+
|
36
|
+
// src/components/autocomplete/autocomplete-popover.gen.ts
|
37
|
+
import {
|
38
|
+
defaultAutocompletePopoverProps
|
39
|
+
} from "@prosekit/web/autocomplete";
|
40
|
+
var AutocompletePopover = createComponent(
|
41
|
+
"prosekit-autocomplete-popover",
|
42
|
+
"AutocompletePopover",
|
43
|
+
defaultAutocompletePopoverProps
|
44
|
+
);
|
45
|
+
export {
|
46
|
+
AutocompleteEmpty,
|
47
|
+
AutocompleteItem,
|
48
|
+
AutocompleteList,
|
49
|
+
AutocompletePopover
|
50
|
+
};
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import {
|
2
|
+
createComponent
|
3
|
+
} from "./chunk-UG3RPLME.js";
|
4
|
+
import "./chunk-BH56NR2Q.js";
|
5
|
+
|
6
|
+
// src/components/block-handle/block-drag-handle.gen.ts
|
7
|
+
import {
|
8
|
+
defaultBlockDragHandleProps
|
9
|
+
} from "@prosekit/web/block-handle";
|
10
|
+
var BlockDragHandle = createComponent(
|
11
|
+
"prosekit-block-drag-handle",
|
12
|
+
"BlockDragHandle",
|
13
|
+
defaultBlockDragHandleProps
|
14
|
+
);
|
15
|
+
|
16
|
+
// src/components/block-handle/block-popover.gen.ts
|
17
|
+
import {
|
18
|
+
defaultBlockPopoverProps
|
19
|
+
} from "@prosekit/web/block-handle";
|
20
|
+
var BlockPopover = createComponent(
|
21
|
+
"prosekit-block-popover",
|
22
|
+
"BlockPopover",
|
23
|
+
defaultBlockPopoverProps
|
24
|
+
);
|
25
|
+
export {
|
26
|
+
BlockDragHandle,
|
27
|
+
BlockPopover
|
28
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
export { InlinePopover } from './_tsup-dts-rollup';
|
@@ -0,0 +1,17 @@
|
|
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
|
+
export {
|
16
|
+
InlinePopover
|
17
|
+
};
|
@@ -0,0 +1,39 @@
|
|
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
|
+
);
|
35
|
+
export {
|
36
|
+
PopoverContent,
|
37
|
+
PopoverRoot,
|
38
|
+
PopoverTrigger
|
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,21 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
}
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
}
|
15
|
-
declare function useExtension({ extension }: UseExtensionProps): void;
|
16
|
-
|
17
|
-
declare function useKeymap({ keymap }: {
|
18
|
-
keymap: Keymap;
|
19
|
-
}): void;
|
20
|
-
|
21
|
-
export { ProseKit, ProseKitProps, useEditor, useExtension, useKeymap };
|
1
|
+
export { ProseKit } from './_tsup-dts-rollup';
|
2
|
+
export { ProseKitProps } from './_tsup-dts-rollup';
|
3
|
+
export { defineReactNodeView } from './_tsup-dts-rollup';
|
4
|
+
export { ReactNodeViewOptions } from './_tsup-dts-rollup';
|
5
|
+
export { useEditor } from './_tsup-dts-rollup';
|
6
|
+
export { useExtension } from './_tsup-dts-rollup';
|
7
|
+
export { UseExtensionOptions } from './_tsup-dts-rollup';
|
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,49 +1,335 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
import {
|
2
|
+
EditorContextProvider,
|
3
|
+
useEditorContext
|
4
|
+
} from "./chunk-BH56NR2Q.js";
|
4
5
|
|
5
|
-
// src/components/prosekit.
|
6
|
-
import
|
6
|
+
// src/components/prosekit.ts
|
7
|
+
import "@prosekit/core";
|
8
|
+
import { createElement as createElement3 } from "react";
|
9
|
+
|
10
|
+
// src/views/react-views-consumer.ts
|
11
|
+
import { useMemo as useMemo2 } from "react";
|
12
|
+
|
13
|
+
// src/extensions/react-node-view.ts
|
14
|
+
import {
|
15
|
+
defineNodeViewFactory
|
16
|
+
} from "@prosekit/core";
|
17
|
+
function defineReactNodeView(options) {
|
18
|
+
const { name, ...userOptions } = options;
|
19
|
+
return defineNodeViewFactory({
|
20
|
+
group: "react",
|
21
|
+
name,
|
22
|
+
args: userOptions
|
23
|
+
});
|
24
|
+
}
|
25
|
+
function defineReactNodeViewFactory(nodeViewFactory) {
|
26
|
+
return defineNodeViewFactory({
|
27
|
+
group: "react",
|
28
|
+
factory: nodeViewFactory
|
29
|
+
});
|
30
|
+
}
|
31
|
+
|
32
|
+
// src/hooks/use-extension.ts
|
33
|
+
import "@prosekit/core";
|
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
|
7
250
|
var ProseKit = (props) => {
|
8
|
-
const editor = props
|
9
|
-
return
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
+
);
|
14
262
|
};
|
15
|
-
var EditorContextProvider = editorContext.Provider;
|
16
263
|
|
17
264
|
// src/hooks/use-editor.ts
|
18
|
-
import {
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
265
|
+
import {
|
266
|
+
ProseKitError as ProseKitError2,
|
267
|
+
defineMountHandler,
|
268
|
+
defineUpdateHandler,
|
269
|
+
union
|
270
|
+
} from "@prosekit/core";
|
271
|
+
import { useEffect as useEffect3, useReducer } from "react";
|
272
|
+
function useEditor(options) {
|
273
|
+
var _a;
|
274
|
+
const update = (_a = options == null ? void 0 : options.update) != null ? _a : false;
|
275
|
+
const editor = useEditorContext();
|
276
|
+
if (!editor) {
|
277
|
+
throw new ProseKitError2(
|
24
278
|
"useEditor must be used within the ProseKit component"
|
25
279
|
);
|
26
280
|
}
|
27
|
-
|
281
|
+
const forceUpdate = useForceUpdate();
|
282
|
+
useEffect3(() => {
|
283
|
+
if (update) {
|
284
|
+
const extension = union([
|
285
|
+
defineMountHandler(forceUpdate),
|
286
|
+
defineUpdateHandler(forceUpdate)
|
287
|
+
]);
|
288
|
+
return editor.use(extension);
|
289
|
+
}
|
290
|
+
}, [editor, update, forceUpdate]);
|
291
|
+
return editor;
|
28
292
|
}
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
function useExtension({ extension }) {
|
33
|
-
const editor = useEditor();
|
34
|
-
useEffect(() => editor.use(extension), [editor, extension]);
|
293
|
+
function useForceUpdate() {
|
294
|
+
const [, dispatch] = useReducer((x) => x + 1, 0);
|
295
|
+
return dispatch;
|
35
296
|
}
|
36
297
|
|
37
298
|
// src/hooks/use-keymap.ts
|
38
|
-
import {
|
39
|
-
import { useMemo } from "react";
|
40
|
-
function useKeymap(
|
41
|
-
const extension =
|
42
|
-
useExtension(
|
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);
|
304
|
+
}
|
305
|
+
|
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]
|
313
|
+
);
|
314
|
+
return useExtension(extension, options);
|
315
|
+
}
|
316
|
+
|
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);
|
43
326
|
}
|
44
327
|
export {
|
45
328
|
ProseKit,
|
329
|
+
defineReactNodeView,
|
330
|
+
useDocChange,
|
46
331
|
useEditor,
|
47
332
|
useExtension,
|
48
|
-
useKeymap
|
333
|
+
useKeymap,
|
334
|
+
useStateUpdate
|
49
335
|
};
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@prosekit/react",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.0.0-next-
|
4
|
+
"version": "0.0.0-next-20240421132240",
|
5
5
|
"private": false,
|
6
6
|
"author": {
|
7
7
|
"name": "ocavue",
|
@@ -30,34 +30,47 @@
|
|
30
30
|
"import": "./dist/prosekit-react.js",
|
31
31
|
"default": "./dist/prosekit-react.js"
|
32
32
|
},
|
33
|
-
"./
|
34
|
-
"types": "./dist/prosekit-react-
|
35
|
-
"import": "./dist/prosekit-react-
|
36
|
-
"default": "./dist/prosekit-react-
|
33
|
+
"./autocomplete": {
|
34
|
+
"types": "./dist/prosekit-react-autocomplete.d.ts",
|
35
|
+
"import": "./dist/prosekit-react-autocomplete.js",
|
36
|
+
"default": "./dist/prosekit-react-autocomplete.js"
|
37
37
|
},
|
38
|
-
"./
|
39
|
-
"types": "./dist/prosekit-react-
|
40
|
-
"import": "./dist/prosekit-react-
|
41
|
-
"default": "./dist/prosekit-react-
|
38
|
+
"./block-handle": {
|
39
|
+
"types": "./dist/prosekit-react-block-handle.d.ts",
|
40
|
+
"import": "./dist/prosekit-react-block-handle.js",
|
41
|
+
"default": "./dist/prosekit-react-block-handle.js"
|
42
42
|
},
|
43
|
-
"./
|
44
|
-
"types": "./dist/prosekit-react-
|
45
|
-
"import": "./dist/prosekit-react-
|
46
|
-
"default": "./dist/prosekit-react-
|
43
|
+
"./inline-popover": {
|
44
|
+
"types": "./dist/prosekit-react-inline-popover.d.ts",
|
45
|
+
"import": "./dist/prosekit-react-inline-popover.js",
|
46
|
+
"default": "./dist/prosekit-react-inline-popover.js"
|
47
47
|
},
|
48
|
-
"./
|
49
|
-
"types": "./dist/prosekit-react-
|
50
|
-
"import": "./dist/prosekit-react-
|
51
|
-
"default": "./dist/prosekit-react-
|
48
|
+
"./popover": {
|
49
|
+
"types": "./dist/prosekit-react-popover.d.ts",
|
50
|
+
"import": "./dist/prosekit-react-popover.js",
|
51
|
+
"default": "./dist/prosekit-react-popover.js"
|
52
|
+
},
|
53
|
+
"./resizable": {
|
54
|
+
"types": "./dist/prosekit-react-resizable.d.ts",
|
55
|
+
"import": "./dist/prosekit-react-resizable.js",
|
56
|
+
"default": "./dist/prosekit-react-resizable.js"
|
57
|
+
},
|
58
|
+
"./tooltip": {
|
59
|
+
"types": "./dist/prosekit-react-tooltip.d.ts",
|
60
|
+
"import": "./dist/prosekit-react-tooltip.js",
|
61
|
+
"default": "./dist/prosekit-react-tooltip.js"
|
52
62
|
}
|
53
63
|
},
|
54
64
|
"files": [
|
55
65
|
"dist"
|
56
66
|
],
|
57
67
|
"dependencies": {
|
58
|
-
"@lit
|
59
|
-
"@prosekit/core": "0.0.0-next-
|
60
|
-
"@prosekit/
|
68
|
+
"@lit/react": "^1.0.4",
|
69
|
+
"@prosekit/core": "0.0.0-next-20240421132240",
|
70
|
+
"@prosekit/pm": "0.0.0-next-20240421132240",
|
71
|
+
"@prosekit/web": "0.0.0-next-20240421132240",
|
72
|
+
"@prosemirror-adapter/core": "^0.2.6",
|
73
|
+
"react-merge-refs": "^2.1.1"
|
61
74
|
},
|
62
75
|
"peerDependencies": {
|
63
76
|
"react": ">= 17.0.0",
|
@@ -73,13 +86,13 @@
|
|
73
86
|
},
|
74
87
|
"devDependencies": {
|
75
88
|
"@prosekit/dev": "*",
|
76
|
-
"@types/react": "^18.2.
|
77
|
-
"@types/react-dom": "^18.2.
|
89
|
+
"@types/react": "^18.2.79",
|
90
|
+
"@types/react-dom": "^18.2.25",
|
78
91
|
"react": "^18.2.0",
|
79
92
|
"react-dom": "^18.2.0",
|
80
|
-
"tsup": "^
|
81
|
-
"typescript": "^5.
|
82
|
-
"vitest": "^
|
93
|
+
"tsup": "^8.0.2",
|
94
|
+
"typescript": "^5.4.5",
|
95
|
+
"vitest": "^1.5.0"
|
83
96
|
},
|
84
97
|
"scripts": {
|
85
98
|
"build:tsup": "tsup",
|
@@ -91,17 +104,23 @@
|
|
91
104
|
".": [
|
92
105
|
"./dist/prosekit-react.d.ts"
|
93
106
|
],
|
94
|
-
"
|
95
|
-
"./dist/prosekit-react-
|
107
|
+
"autocomplete": [
|
108
|
+
"./dist/prosekit-react-autocomplete.d.ts"
|
109
|
+
],
|
110
|
+
"block-handle": [
|
111
|
+
"./dist/prosekit-react-block-handle.d.ts"
|
112
|
+
],
|
113
|
+
"inline-popover": [
|
114
|
+
"./dist/prosekit-react-inline-popover.d.ts"
|
96
115
|
],
|
97
|
-
"
|
98
|
-
"./dist/prosekit-react-
|
116
|
+
"popover": [
|
117
|
+
"./dist/prosekit-react-popover.d.ts"
|
99
118
|
],
|
100
|
-
"
|
101
|
-
"./dist/prosekit-react-
|
119
|
+
"resizable": [
|
120
|
+
"./dist/prosekit-react-resizable.d.ts"
|
102
121
|
],
|
103
|
-
"
|
104
|
-
"./dist/prosekit-react-
|
122
|
+
"tooltip": [
|
123
|
+
"./dist/prosekit-react-tooltip.d.ts"
|
105
124
|
]
|
106
125
|
}
|
107
126
|
}
|
@@ -1,13 +0,0 @@
|
|
1
|
-
// src/components/menu-item.gen.ts
|
2
|
-
import { createComponent } from "@lit-labs/react";
|
3
|
-
import { MenuItem as MenuItemElement } from "@prosekit/lit/elements/menu-item";
|
4
|
-
import React from "react";
|
5
|
-
var MenuItem = createComponent({
|
6
|
-
tagName: "prosekit-menu-item",
|
7
|
-
elementClass: MenuItemElement,
|
8
|
-
react: React,
|
9
|
-
displayName: "MenuItem"
|
10
|
-
});
|
11
|
-
export {
|
12
|
-
MenuItem
|
13
|
-
};
|
@@ -1,16 +0,0 @@
|
|
1
|
-
import { Editor } from '@prosekit/core';
|
2
|
-
import { Menu as Menu$1 } from '@prosekit/lit/elements/menu';
|
3
|
-
import { ComponentType, ForwardedRef, ReactNode } from 'react';
|
4
|
-
|
5
|
-
/**
|
6
|
-
* @module @prosekit/react/components/menu
|
7
|
-
*/
|
8
|
-
|
9
|
-
declare const Menu: ComponentType<{
|
10
|
-
editor?: Editor;
|
11
|
-
ref?: ForwardedRef<Menu$1>;
|
12
|
-
children?: ReactNode | undefined;
|
13
|
-
className?: string;
|
14
|
-
}>;
|
15
|
-
|
16
|
-
export { Menu };
|
@@ -1,16 +0,0 @@
|
|
1
|
-
// src/components/menu.gen.ts
|
2
|
-
import { createComponent } from "@lit-labs/react";
|
3
|
-
import { Menu as MenuElement } from "@prosekit/lit/elements/menu";
|
4
|
-
import React from "react";
|
5
|
-
var Menu = createComponent({
|
6
|
-
tagName: "prosekit-menu",
|
7
|
-
elementClass: MenuElement,
|
8
|
-
react: React,
|
9
|
-
displayName: "Menu"
|
10
|
-
});
|
11
|
-
|
12
|
-
// src/components/menu.tsx
|
13
|
-
var Menu2 = Menu;
|
14
|
-
export {
|
15
|
-
Menu2 as Menu
|
16
|
-
};
|
@@ -1,16 +0,0 @@
|
|
1
|
-
import { Editor } from '@prosekit/core';
|
2
|
-
import { PredictionRule, PopoverSuggestionContext } from '@prosekit/lit/elements/popover-suggestion';
|
3
|
-
export { PopoverSuggestionContext, PredictionRule } from '@prosekit/lit/elements/popover-suggestion';
|
4
|
-
import React, { FC } from 'react';
|
5
|
-
|
6
|
-
/**
|
7
|
-
* @module @prosekit/react/components/popover-slash
|
8
|
-
*/
|
9
|
-
|
10
|
-
declare const PopoverSuggestion: FC<{
|
11
|
-
editor: Editor;
|
12
|
-
rules: PredictionRule[];
|
13
|
-
render: (context: PopoverSuggestionContext) => React.ReactNode;
|
14
|
-
}>;
|
15
|
-
|
16
|
-
export { PopoverSuggestion };
|
@@ -1,27 +0,0 @@
|
|
1
|
-
// src/components/popover-suggestion.tsx
|
2
|
-
import { useState } from "react";
|
3
|
-
|
4
|
-
// src/components/popover-suggestion.gen.ts
|
5
|
-
import { createComponent } from "@lit-labs/react";
|
6
|
-
import { PopoverSuggestion as PopoverSuggestionElement } from "@prosekit/lit/elements/popover-suggestion";
|
7
|
-
import React from "react";
|
8
|
-
var PopoverSuggestion = createComponent({
|
9
|
-
tagName: "prosekit-popover-suggestion",
|
10
|
-
elementClass: PopoverSuggestionElement,
|
11
|
-
react: React,
|
12
|
-
displayName: "PopoverSuggestion"
|
13
|
-
});
|
14
|
-
|
15
|
-
// src/components/popover-suggestion.tsx
|
16
|
-
import { jsxDEV } from "react/jsx-dev-runtime";
|
17
|
-
var PopoverSuggestion2 = ({ editor, rules, render }) => {
|
18
|
-
const [context, setContext] = useState(null);
|
19
|
-
return /* @__PURE__ */ jsxDEV(PopoverSuggestion, { editor, rules, onContext: setContext, children: context ? render(context) : null }, void 0, false, {
|
20
|
-
fileName: "src/components/popover-suggestion.tsx",
|
21
|
-
lineNumber: 23,
|
22
|
-
columnNumber: 5
|
23
|
-
}, this);
|
24
|
-
};
|
25
|
-
export {
|
26
|
-
PopoverSuggestion2 as PopoverSuggestion
|
27
|
-
};
|
@@ -1,13 +0,0 @@
|
|
1
|
-
// src/components/popover.gen.ts
|
2
|
-
import { createComponent } from "@lit-labs/react";
|
3
|
-
import { Popover as PopoverElement } from "@prosekit/lit/elements/popover";
|
4
|
-
import React from "react";
|
5
|
-
var Popover = createComponent({
|
6
|
-
tagName: "prosekit-popover",
|
7
|
-
elementClass: PopoverElement,
|
8
|
-
react: React,
|
9
|
-
displayName: "Popover"
|
10
|
-
});
|
11
|
-
export {
|
12
|
-
Popover
|
13
|
-
};
|
package/src/index.ts
DELETED