@prosekit/react 0.0.16 → 0.0.17
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 +28 -0
- package/dist/prosekit-react.d.ts +4 -0
- package/dist/prosekit-react.js +81 -13
- package/package.json +6 -5
- package/src/index.ts +6 -0
@@ -18,18 +18,23 @@ import { ComboBoxItemProps as ComboBoxItemProps_2 } from '@prosekit/lit/combo-bo
|
|
18
18
|
import { ComboBoxList as ComboBoxList_2 } from '@prosekit/lit/combo-box-list';
|
19
19
|
import { ComboBoxListProps as ComboBoxListProps_2 } from '@prosekit/lit/combo-box-list';
|
20
20
|
import { ComboBoxProps as ComboBoxProps_2 } from '@prosekit/lit/combo-box';
|
21
|
+
import { CommandArgs } from '@prosekit/core';
|
21
22
|
import { ComponentType } from 'react';
|
22
23
|
import { Context } from 'react';
|
23
24
|
import { Editor } from '@prosekit/core';
|
24
25
|
import { Extension } from '@prosekit/core';
|
26
|
+
import { ExtensionTyping } from '@prosekit/core';
|
25
27
|
import type { ForwardRefExoticComponent } from 'react';
|
26
28
|
import { Keymap } from '@prosekit/core';
|
29
|
+
import type { NodeViewContext } from '@prosemirror-adapter/react';
|
27
30
|
import { Options } from 'tsup';
|
28
31
|
import { PopoverOptions } from '@prosekit/lit/autocomplete-popover';
|
29
32
|
import type { PropsWithoutRef } from 'react';
|
30
33
|
import { default as React_2 } from 'react';
|
31
34
|
import type { RefAttributes } from 'react';
|
32
35
|
import type { SimplifyUnion } from '@prosekit/core';
|
36
|
+
import { useNodeViewContext } from '@prosemirror-adapter/react';
|
37
|
+
import { useNodeViewFactory } from '@prosemirror-adapter/react';
|
33
38
|
import { UserProjectConfigExport } from 'vitest/dist/config.js';
|
34
39
|
|
35
40
|
declare const AutocompleteEmpty: ForwardRefExoticComponent<PropsWithoutRef<AutocompleteEmptyProps> & RefAttributes<AutocompleteEmpty_2>>;
|
@@ -115,6 +120,14 @@ export declare const default_alias: Options | Options[] | ((overrideOptions: Opt
|
|
115
120
|
|
116
121
|
export declare const default_alias_1: UserProjectConfigExport;
|
117
122
|
|
123
|
+
declare function defineReactNodeView(options: ReactNodeViewOptions): Extension;
|
124
|
+
export { defineReactNodeView }
|
125
|
+
export { defineReactNodeView as defineReactNodeView_alias_1 }
|
126
|
+
|
127
|
+
export declare function defineReactNodeViewRenderer({ nodeViewFactory, }: {
|
128
|
+
nodeViewFactory: ReturnType<typeof useNodeViewFactory>;
|
129
|
+
}): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
130
|
+
|
118
131
|
export declare interface EditorContext {
|
119
132
|
editor: Editor;
|
120
133
|
}
|
@@ -134,6 +147,19 @@ declare interface ProseKitProps {
|
|
134
147
|
export { ProseKitProps }
|
135
148
|
export { ProseKitProps as ProseKitProps_alias_1 }
|
136
149
|
|
150
|
+
declare type ReactNodeViewComponentProps = NodeViewContext;
|
151
|
+
export { ReactNodeViewComponentProps }
|
152
|
+
export { ReactNodeViewComponentProps as ReactNodeViewComponentProps_alias_1 }
|
153
|
+
|
154
|
+
declare interface ReactNodeViewOptions {
|
155
|
+
name: string;
|
156
|
+
component: React.ComponentType<ReactNodeViewComponentProps>;
|
157
|
+
dom?: string | (() => HTMLElement);
|
158
|
+
contentDOM?: string | (() => HTMLElement);
|
159
|
+
}
|
160
|
+
export { ReactNodeViewOptions }
|
161
|
+
export { ReactNodeViewOptions as ReactNodeViewOptions_alias_1 }
|
162
|
+
|
137
163
|
declare function useEditor<E extends Extension = any>(options?: UseEditorOptions): Editor<E>;
|
138
164
|
export { useEditor }
|
139
165
|
export { useEditor as useEditor_alias_1 }
|
@@ -158,4 +184,6 @@ declare function useKeymap({ keymap }: {
|
|
158
184
|
export { useKeymap }
|
159
185
|
export { useKeymap as useKeymap_alias_1 }
|
160
186
|
|
187
|
+
export { useNodeViewContext }
|
188
|
+
|
161
189
|
export { }
|
package/dist/prosekit-react.d.ts
CHANGED
@@ -1,5 +1,9 @@
|
|
1
|
+
export { useNodeViewContext } from './_tsup-dts-rollup';
|
1
2
|
export { ProseKit } from './_tsup-dts-rollup';
|
2
3
|
export { ProseKitProps } from './_tsup-dts-rollup';
|
4
|
+
export { defineReactNodeView } from './_tsup-dts-rollup';
|
5
|
+
export { ReactNodeViewComponentProps } from './_tsup-dts-rollup';
|
6
|
+
export { ReactNodeViewOptions } from './_tsup-dts-rollup';
|
3
7
|
export { useEditor } from './_tsup-dts-rollup';
|
4
8
|
export { UseEditorOptions } from './_tsup-dts-rollup';
|
5
9
|
export { useExtension } from './_tsup-dts-rollup';
|
package/dist/prosekit-react.js
CHANGED
@@ -1,17 +1,58 @@
|
|
1
|
+
// src/index.ts
|
2
|
+
import { useNodeViewContext as useNodeViewContext2 } from "@prosemirror-adapter/react";
|
3
|
+
|
1
4
|
// src/components/prosekit.ts
|
2
5
|
import "@prosekit/core";
|
3
|
-
import {
|
6
|
+
import {
|
7
|
+
ProsemirrorAdapterProvider,
|
8
|
+
useNodeViewFactory
|
9
|
+
} from "@prosemirror-adapter/react";
|
10
|
+
import { createElement as createElement2, useMemo } from "react";
|
4
11
|
|
5
12
|
// src/contexts/editor-context.ts
|
6
13
|
import { createContext } from "react";
|
7
14
|
var editorContext = createContext(null);
|
8
15
|
|
9
|
-
// src/
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
};
|
14
|
-
|
16
|
+
// src/extensions/react-node-view.ts
|
17
|
+
import { defineNodeViewEffect } from "@prosekit/core";
|
18
|
+
import {
|
19
|
+
useNodeViewContext
|
20
|
+
} from "@prosemirror-adapter/react";
|
21
|
+
import { createElement } from "react";
|
22
|
+
function defineReactNodeView(options) {
|
23
|
+
return defineNodeViewEffect({
|
24
|
+
group: "react",
|
25
|
+
name: options.name,
|
26
|
+
args: options
|
27
|
+
});
|
28
|
+
}
|
29
|
+
function defineReactNodeViewRenderer({
|
30
|
+
nodeViewFactory
|
31
|
+
}) {
|
32
|
+
return defineNodeViewEffect({
|
33
|
+
group: "react",
|
34
|
+
factory: (args) => {
|
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
|
+
}
|
50
|
+
});
|
51
|
+
}
|
52
|
+
|
53
|
+
// src/hooks/use-extension.ts
|
54
|
+
import "@prosekit/core";
|
55
|
+
import { useEffect as useEffect2 } from "react";
|
15
56
|
|
16
57
|
// src/hooks/use-editor.ts
|
17
58
|
import {
|
@@ -43,23 +84,50 @@ function useForceUpdate() {
|
|
43
84
|
}
|
44
85
|
|
45
86
|
// src/hooks/use-extension.ts
|
46
|
-
import "@prosekit/core";
|
47
|
-
import { useEffect as useEffect2 } from "react";
|
48
87
|
function useExtension({ extension }) {
|
49
88
|
const editor = useEditor();
|
50
|
-
useEffect2(() =>
|
89
|
+
useEffect2(() => {
|
90
|
+
return editor.use(extension);
|
91
|
+
}, [editor, extension]);
|
51
92
|
}
|
52
93
|
|
94
|
+
// src/components/prosekit.ts
|
95
|
+
var ProseKit = (props) => {
|
96
|
+
const { editor, children } = props;
|
97
|
+
return createElement2(
|
98
|
+
ProsemirrorAdapterProvider,
|
99
|
+
null,
|
100
|
+
createElement2(
|
101
|
+
EditorContextProvider,
|
102
|
+
{ value: { editor } },
|
103
|
+
children,
|
104
|
+
createElement2(RendererRegister)
|
105
|
+
)
|
106
|
+
);
|
107
|
+
};
|
108
|
+
function RendererRegister() {
|
109
|
+
const nodeViewFactory = useNodeViewFactory();
|
110
|
+
const extension = useMemo(
|
111
|
+
() => defineReactNodeViewRenderer({ nodeViewFactory }),
|
112
|
+
[nodeViewFactory]
|
113
|
+
);
|
114
|
+
useExtension({ extension });
|
115
|
+
return null;
|
116
|
+
}
|
117
|
+
var EditorContextProvider = editorContext.Provider;
|
118
|
+
|
53
119
|
// src/hooks/use-keymap.ts
|
54
120
|
import { defineKeymap } from "@prosekit/core";
|
55
|
-
import { useMemo } from "react";
|
121
|
+
import { useMemo as useMemo2 } from "react";
|
56
122
|
function useKeymap({ keymap }) {
|
57
|
-
const extension =
|
123
|
+
const extension = useMemo2(() => defineKeymap(keymap), [keymap]);
|
58
124
|
useExtension({ extension });
|
59
125
|
}
|
60
126
|
export {
|
61
127
|
ProseKit,
|
128
|
+
defineReactNodeView,
|
62
129
|
useEditor,
|
63
130
|
useExtension,
|
64
|
-
useKeymap
|
131
|
+
useKeymap,
|
132
|
+
useNodeViewContext2 as useNodeViewContext
|
65
133
|
};
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@prosekit/react",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.0.
|
4
|
+
"version": "0.0.17",
|
5
5
|
"private": false,
|
6
6
|
"author": {
|
7
7
|
"name": "ocavue",
|
@@ -81,8 +81,9 @@
|
|
81
81
|
],
|
82
82
|
"dependencies": {
|
83
83
|
"@lit/react": "^1.0.0",
|
84
|
-
"@prosekit/core": "^0.0.
|
85
|
-
"@prosekit/lit": "^0.0.
|
84
|
+
"@prosekit/core": "^0.0.13",
|
85
|
+
"@prosekit/lit": "^0.0.17",
|
86
|
+
"@prosemirror-adapter/react": "^0.2.6"
|
86
87
|
},
|
87
88
|
"peerDependencies": {
|
88
89
|
"react": ">= 17.0.0",
|
@@ -98,8 +99,8 @@
|
|
98
99
|
},
|
99
100
|
"devDependencies": {
|
100
101
|
"@prosekit/dev": "*",
|
101
|
-
"@types/react": "^18.2.
|
102
|
-
"@types/react-dom": "^18.2.
|
102
|
+
"@types/react": "^18.2.31",
|
103
|
+
"@types/react-dom": "^18.2.14",
|
103
104
|
"react": "^18.2.0",
|
104
105
|
"react-dom": "^18.2.0",
|
105
106
|
"tsup": "^7.2.0",
|
package/src/index.ts
CHANGED
@@ -1,4 +1,10 @@
|
|
1
|
+
export { useNodeViewContext } from '@prosemirror-adapter/react'
|
1
2
|
export { ProseKit, type ProseKitProps } from './components/prosekit'
|
3
|
+
export {
|
4
|
+
defineReactNodeView,
|
5
|
+
type ReactNodeViewComponentProps,
|
6
|
+
type ReactNodeViewOptions,
|
7
|
+
} from './extensions/react-node-view'
|
2
8
|
export { useEditor, type UseEditorOptions } from './hooks/use-editor'
|
3
9
|
export { useExtension } from './hooks/use-extension'
|
4
10
|
export { useKeymap } from './hooks/use-keymap'
|