@prosekit/react 0.0.16 → 0.0.18
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.
@@ -18,18 +18,25 @@ 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';
|
31
|
+
import { Popover as Popover_2 } from '@prosekit/lit/popover';
|
28
32
|
import { PopoverOptions } from '@prosekit/lit/autocomplete-popover';
|
33
|
+
import { PopoverProps as PopoverProps_2 } from '@prosekit/lit/popover';
|
29
34
|
import type { PropsWithoutRef } from 'react';
|
30
35
|
import { default as React_2 } from 'react';
|
31
36
|
import type { RefAttributes } from 'react';
|
32
37
|
import type { SimplifyUnion } from '@prosekit/core';
|
38
|
+
import { useNodeViewContext } from '@prosemirror-adapter/react';
|
39
|
+
import { useNodeViewFactory } from '@prosemirror-adapter/react';
|
33
40
|
import { UserProjectConfigExport } from 'vitest/dist/config.js';
|
34
41
|
|
35
42
|
declare const AutocompleteEmpty: ForwardRefExoticComponent<PropsWithoutRef<AutocompleteEmptyProps> & RefAttributes<AutocompleteEmpty_2>>;
|
@@ -115,14 +122,29 @@ export declare const default_alias: Options | Options[] | ((overrideOptions: Opt
|
|
115
122
|
|
116
123
|
export declare const default_alias_1: UserProjectConfigExport;
|
117
124
|
|
125
|
+
declare function defineReactNodeView(options: ReactNodeViewOptions): Extension;
|
126
|
+
export { defineReactNodeView }
|
127
|
+
export { defineReactNodeView as defineReactNodeView_alias_1 }
|
128
|
+
|
129
|
+
export declare function defineReactNodeViewRenderer({ nodeViewFactory, }: {
|
130
|
+
nodeViewFactory: ReturnType<typeof useNodeViewFactory>;
|
131
|
+
}): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
132
|
+
|
118
133
|
export declare interface EditorContext {
|
119
134
|
editor: Editor;
|
120
135
|
}
|
121
136
|
|
122
137
|
export declare const editorContext: Context<EditorContext | null>;
|
123
138
|
|
139
|
+
export declare const Popover: ForwardRefExoticComponent<PropsWithoutRef<PopoverProps> & RefAttributes<Popover_2>>;
|
140
|
+
|
124
141
|
export { PopoverOptions }
|
125
142
|
|
143
|
+
export declare type PopoverProps = SimplifyUnion<{
|
144
|
+
className?: string;
|
145
|
+
children?: React_2.ReactNode;
|
146
|
+
} & PopoverProps_2>;
|
147
|
+
|
126
148
|
declare const ProseKit: ComponentType<ProseKitProps>;
|
127
149
|
export { ProseKit }
|
128
150
|
export { ProseKit as ProseKit_alias_1 }
|
@@ -134,6 +156,19 @@ declare interface ProseKitProps {
|
|
134
156
|
export { ProseKitProps }
|
135
157
|
export { ProseKitProps as ProseKitProps_alias_1 }
|
136
158
|
|
159
|
+
declare type ReactNodeViewComponentProps = NodeViewContext;
|
160
|
+
export { ReactNodeViewComponentProps }
|
161
|
+
export { ReactNodeViewComponentProps as ReactNodeViewComponentProps_alias_1 }
|
162
|
+
|
163
|
+
declare interface ReactNodeViewOptions {
|
164
|
+
name: string;
|
165
|
+
component: React.ComponentType<ReactNodeViewComponentProps>;
|
166
|
+
dom?: string | (() => HTMLElement);
|
167
|
+
contentDOM?: string | (() => HTMLElement);
|
168
|
+
}
|
169
|
+
export { ReactNodeViewOptions }
|
170
|
+
export { ReactNodeViewOptions as ReactNodeViewOptions_alias_1 }
|
171
|
+
|
137
172
|
declare function useEditor<E extends Extension = any>(options?: UseEditorOptions): Editor<E>;
|
138
173
|
export { useEditor }
|
139
174
|
export { useEditor as useEditor_alias_1 }
|
@@ -158,4 +193,6 @@ declare function useKeymap({ keymap }: {
|
|
158
193
|
export { useKeymap }
|
159
194
|
export { useKeymap as useKeymap_alias_1 }
|
160
195
|
|
196
|
+
export { useNodeViewContext }
|
197
|
+
|
161
198
|
export { }
|
@@ -0,0 +1,17 @@
|
|
1
|
+
// src/components/popover.gen.ts
|
2
|
+
import { createComponent } from "@lit/react";
|
3
|
+
import { Popover as PopoverElement } from "@prosekit/lit/popover";
|
4
|
+
import React from "react";
|
5
|
+
var PopoverInner = createComponent({
|
6
|
+
tagName: "prosekit-popover",
|
7
|
+
elementClass: PopoverElement,
|
8
|
+
react: React,
|
9
|
+
displayName: "PopoverInner"
|
10
|
+
});
|
11
|
+
var Popover = React.forwardRef((props, ref) => {
|
12
|
+
return React.createElement(PopoverInner, { ...props, ref });
|
13
|
+
});
|
14
|
+
Popover.displayName = "Popover";
|
15
|
+
export {
|
16
|
+
Popover
|
17
|
+
};
|
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.18",
|
5
5
|
"private": false,
|
6
6
|
"author": {
|
7
7
|
"name": "ocavue",
|
@@ -74,6 +74,11 @@
|
|
74
74
|
"types": "./dist/prosekit-react-combo-box-list.d.ts",
|
75
75
|
"import": "./dist/prosekit-react-combo-box-list.js",
|
76
76
|
"default": "./dist/prosekit-react-combo-box-list.js"
|
77
|
+
},
|
78
|
+
"./popover": {
|
79
|
+
"types": "./dist/prosekit-react-popover.d.ts",
|
80
|
+
"import": "./dist/prosekit-react-popover.js",
|
81
|
+
"default": "./dist/prosekit-react-popover.js"
|
77
82
|
}
|
78
83
|
},
|
79
84
|
"files": [
|
@@ -81,8 +86,9 @@
|
|
81
86
|
],
|
82
87
|
"dependencies": {
|
83
88
|
"@lit/react": "^1.0.0",
|
84
|
-
"@prosekit/core": "^0.0.
|
85
|
-
"@prosekit/lit": "^0.0.
|
89
|
+
"@prosekit/core": "^0.0.14",
|
90
|
+
"@prosekit/lit": "^0.0.18",
|
91
|
+
"@prosemirror-adapter/react": "^0.2.6"
|
86
92
|
},
|
87
93
|
"peerDependencies": {
|
88
94
|
"react": ">= 17.0.0",
|
@@ -98,8 +104,8 @@
|
|
98
104
|
},
|
99
105
|
"devDependencies": {
|
100
106
|
"@prosekit/dev": "*",
|
101
|
-
"@types/react": "^18.2.
|
102
|
-
"@types/react-dom": "^18.2.
|
107
|
+
"@types/react": "^18.2.31",
|
108
|
+
"@types/react-dom": "^18.2.14",
|
103
109
|
"react": "^18.2.0",
|
104
110
|
"react-dom": "^18.2.0",
|
105
111
|
"tsup": "^7.2.0",
|
@@ -142,6 +148,9 @@
|
|
142
148
|
],
|
143
149
|
"combo-box-list": [
|
144
150
|
"./dist/prosekit-react-combo-box-list.d.ts"
|
151
|
+
],
|
152
|
+
"popover": [
|
153
|
+
"./dist/prosekit-react-popover.d.ts"
|
145
154
|
]
|
146
155
|
}
|
147
156
|
}
|
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'
|