@prosekit/preact 0.2.0 → 0.2.1
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 +43 -12
- package/dist/prosekit-preact.d.ts +1 -0
- package/dist/prosekit-preact.js +29 -15
- package/package.json +4 -4
- package/src/index.ts +0 -5
@@ -8,7 +8,6 @@ import type { ComboBoxListProps as ComboBoxListProps_2 } from '@prosekit/lit/com
|
|
8
8
|
import type { ComboBoxProps as ComboBoxProps_2 } from '@prosekit/lit/combo-box';
|
9
9
|
import { ComponentChildren } from 'preact';
|
10
10
|
import { ComponentType } from 'preact';
|
11
|
-
import { Context } from 'preact';
|
12
11
|
import { Editor } from '@prosekit/core';
|
13
12
|
import { Extension } from '@prosekit/core';
|
14
13
|
import type { InlinePopoverProps as InlinePopoverProps_2 } from '@prosekit/lit/inline-popover';
|
@@ -17,6 +16,7 @@ import { Options } from 'tsup';
|
|
17
16
|
import type { PopoverProps as PopoverProps_2 } from '@prosekit/lit/popover';
|
18
17
|
import { PositioningOptions } from '@prosekit/lit/autocomplete-popover';
|
19
18
|
import { Priority } from '@prosekit/core';
|
19
|
+
import { Provider } from 'preact';
|
20
20
|
import type { ResizableHandleProps as ResizableHandleProps_2 } from '@prosekit/lit/resizable-handle';
|
21
21
|
import type { ResizableProps as ResizableProps_2 } from '@prosekit/lit/resizable';
|
22
22
|
|
@@ -76,11 +76,10 @@ export declare const default_alias_1: {
|
|
76
76
|
};
|
77
77
|
};
|
78
78
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
export declare const editorContext: Context<EditorContext | null>;
|
79
|
+
/**
|
80
|
+
* @internal
|
81
|
+
*/
|
82
|
+
export declare const EditorContextProvider: Provider<Editor<any> | null>;
|
84
83
|
|
85
84
|
export declare const InlinePopover: ComponentType<InlinePopoverProps>;
|
86
85
|
|
@@ -111,6 +110,11 @@ declare type PropsWithClass<P = unknown> = P & {
|
|
111
110
|
export { PropsWithClass }
|
112
111
|
export { PropsWithClass as PropsWithClass_alias_1 }
|
113
112
|
|
113
|
+
/**
|
114
|
+
* The root component for a ProseKit editor.
|
115
|
+
*
|
116
|
+
* @public
|
117
|
+
*/
|
114
118
|
declare const ProseKit: ComponentType<ProseKitProps>;
|
115
119
|
export { ProseKit }
|
116
120
|
export { ProseKit as ProseKit_alias_1 }
|
@@ -147,22 +151,49 @@ declare function useEditor<E extends Extension = any>(options?: {
|
|
147
151
|
export { useEditor }
|
148
152
|
export { useEditor as useEditor_alias_1 }
|
149
153
|
|
154
|
+
/**
|
155
|
+
* @internal
|
156
|
+
*/
|
157
|
+
export declare function useEditorContext<E extends Extension>(): Editor<E> | null;
|
158
|
+
|
159
|
+
/**
|
160
|
+
* @internal
|
161
|
+
*/
|
162
|
+
export declare function useEditorExtension(editor: Editor | null | undefined, extension: Extension | null): void;
|
163
|
+
|
150
164
|
/**
|
151
165
|
* Add an extension to the editor.
|
152
|
-
|
153
|
-
|
166
|
+
*/
|
167
|
+
declare function useExtension(
|
168
|
+
/**
|
169
|
+
* The extension to add to the editor. If it changes, the previous
|
154
170
|
* extension will be removed and the new one (if not null) will be added.
|
155
171
|
*/
|
156
|
-
|
172
|
+
extension: Extension | null, options?: UseExtensionOptions): void;
|
157
173
|
export { useExtension }
|
158
174
|
export { useExtension as useExtension_alias_1 }
|
159
175
|
|
160
|
-
declare
|
176
|
+
declare interface UseExtensionOptions {
|
177
|
+
/**
|
178
|
+
* The editor to add the extension to. If not provided, it will use the
|
179
|
+
* editor from the nearest `ProseKit` component.
|
180
|
+
*/
|
181
|
+
editor?: Editor;
|
182
|
+
/**
|
183
|
+
* Optional priority to add the extension with.
|
184
|
+
*/
|
161
185
|
priority?: Priority;
|
162
|
-
}
|
186
|
+
}
|
187
|
+
export { UseExtensionOptions }
|
188
|
+
export { UseExtensionOptions as UseExtensionOptions_alias_1 }
|
189
|
+
|
190
|
+
declare function useKeymap(keymap: Keymap, options?: UseExtensionOptions): void;
|
163
191
|
export { useKeymap }
|
164
192
|
export { useKeymap as useKeymap_alias_1 }
|
165
193
|
|
166
|
-
|
194
|
+
/**
|
195
|
+
* @internal
|
196
|
+
*/
|
197
|
+
export declare function usePriorityExtension<T extends Extension = Extension>(extension: T | null, priority?: Priority | null): T | null;
|
167
198
|
|
168
199
|
export { }
|
@@ -2,6 +2,7 @@ export { ProseKit } from './_tsup-dts-rollup';
|
|
2
2
|
export { ProseKitProps } from './_tsup-dts-rollup';
|
3
3
|
export { useEditor } from './_tsup-dts-rollup';
|
4
4
|
export { useExtension } from './_tsup-dts-rollup';
|
5
|
+
export { UseExtensionOptions } from './_tsup-dts-rollup';
|
5
6
|
export { useKeymap } from './_tsup-dts-rollup';
|
6
7
|
export { PropsWithChildren } from './_tsup-dts-rollup';
|
7
8
|
export { PropsWithClass } from './_tsup-dts-rollup';
|
package/dist/prosekit-preact.js
CHANGED
@@ -3,14 +3,18 @@ import { h } from "preact";
|
|
3
3
|
|
4
4
|
// src/contexts/editor-context.ts
|
5
5
|
import { createContext } from "preact";
|
6
|
+
import { useContext } from "preact/hooks";
|
6
7
|
var editorContext = createContext(null);
|
8
|
+
function useEditorContext() {
|
9
|
+
return useContext(editorContext);
|
10
|
+
}
|
11
|
+
var EditorContextProvider = editorContext.Provider;
|
7
12
|
|
8
13
|
// src/components/prosekit.ts
|
9
14
|
var ProseKit = (props) => {
|
10
15
|
const { editor, children } = props;
|
11
|
-
return h(EditorContextProvider, { value:
|
16
|
+
return h(EditorContextProvider, { value: editor, children });
|
12
17
|
};
|
13
|
-
var EditorContextProvider = editorContext.Provider;
|
14
18
|
|
15
19
|
// src/hooks/use-editor.ts
|
16
20
|
import {
|
@@ -19,17 +23,16 @@ import {
|
|
19
23
|
defineUpdateHandler,
|
20
24
|
union
|
21
25
|
} from "@prosekit/core";
|
22
|
-
import {
|
26
|
+
import { useEffect, useReducer } from "preact/hooks";
|
23
27
|
function useEditor(options) {
|
24
28
|
var _a;
|
25
29
|
const update = (_a = options == null ? void 0 : options.update) != null ? _a : false;
|
26
|
-
const
|
27
|
-
if (!
|
30
|
+
const editor = useEditorContext();
|
31
|
+
if (!editor) {
|
28
32
|
throw new ProseKitError(
|
29
33
|
"useEditor must be used within the ProseKit component"
|
30
34
|
);
|
31
35
|
}
|
32
|
-
const editor = value.editor;
|
33
36
|
const forceUpdate = useForceUpdate();
|
34
37
|
useEffect(() => {
|
35
38
|
if (update) {
|
@@ -49,9 +52,14 @@ function useForceUpdate() {
|
|
49
52
|
|
50
53
|
// src/hooks/use-extension.ts
|
51
54
|
import "@prosekit/core";
|
55
|
+
|
56
|
+
// src/hooks/use-editor-extension.ts
|
57
|
+
import { EditorNotFoundError } from "@prosekit/core";
|
52
58
|
import { useEffect as useEffect2 } from "preact/hooks";
|
53
|
-
function
|
54
|
-
|
59
|
+
function useEditorExtension(editor, extension) {
|
60
|
+
if (!editor) {
|
61
|
+
throw new EditorNotFoundError();
|
62
|
+
}
|
55
63
|
useEffect2(() => {
|
56
64
|
if (extension) {
|
57
65
|
return editor.use(extension);
|
@@ -59,24 +67,30 @@ function useExtension(extension) {
|
|
59
67
|
}, [editor, extension]);
|
60
68
|
}
|
61
69
|
|
62
|
-
// src/hooks/use-keymap.ts
|
63
|
-
import { defineKeymap } from "@prosekit/core";
|
64
|
-
import { useMemo as useMemo2 } from "preact/hooks";
|
65
|
-
|
66
70
|
// src/hooks/use-priority-extension.ts
|
67
71
|
import { withPriority } from "@prosekit/core";
|
68
72
|
import { useMemo } from "preact/hooks";
|
69
73
|
function usePriorityExtension(extension, priority) {
|
70
|
-
|
74
|
+
return useMemo(() => {
|
71
75
|
return extension && priority ? withPriority(extension, priority) : extension;
|
72
76
|
}, [extension, priority]);
|
73
|
-
|
77
|
+
}
|
78
|
+
|
79
|
+
// src/hooks/use-extension.ts
|
80
|
+
function useExtension(extension, options) {
|
81
|
+
const editorContext2 = useEditorContext();
|
82
|
+
useEditorExtension(
|
83
|
+
(options == null ? void 0 : options.editor) || editorContext2,
|
84
|
+
usePriorityExtension(extension, options == null ? void 0 : options.priority)
|
85
|
+
);
|
74
86
|
}
|
75
87
|
|
76
88
|
// src/hooks/use-keymap.ts
|
89
|
+
import { defineKeymap } from "@prosekit/core";
|
90
|
+
import { useMemo as useMemo2 } from "preact/hooks";
|
77
91
|
function useKeymap(keymap, options) {
|
78
92
|
const extension = useMemo2(() => defineKeymap(keymap), [keymap]);
|
79
|
-
|
93
|
+
return useExtension(extension, options);
|
80
94
|
}
|
81
95
|
export {
|
82
96
|
ProseKit,
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@prosekit/preact",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.2.
|
4
|
+
"version": "0.2.1",
|
5
5
|
"private": false,
|
6
6
|
"author": {
|
7
7
|
"name": "ocavue",
|
@@ -95,8 +95,8 @@
|
|
95
95
|
"dist"
|
96
96
|
],
|
97
97
|
"dependencies": {
|
98
|
-
"@prosekit/core": "^0.2.
|
99
|
-
"@prosekit/lit": "^0.2.
|
98
|
+
"@prosekit/core": "^0.2.7",
|
99
|
+
"@prosekit/lit": "^0.2.1"
|
100
100
|
},
|
101
101
|
"peerDependencies": {
|
102
102
|
"preact": ">= 9.0.0"
|
@@ -111,7 +111,7 @@
|
|
111
111
|
"preact": "^10.19.3",
|
112
112
|
"tsup": "^8.0.1",
|
113
113
|
"typescript": "^5.3.3",
|
114
|
-
"vitest": "^1.2.
|
114
|
+
"vitest": "^1.2.1"
|
115
115
|
},
|
116
116
|
"scripts": {
|
117
117
|
"build:tsup": "tsup",
|
package/src/index.ts
DELETED
@@ -1,5 +0,0 @@
|
|
1
|
-
export { ProseKit, type ProseKitProps } from './components/prosekit'
|
2
|
-
export { useEditor } from './hooks/use-editor'
|
3
|
-
export { useExtension } from './hooks/use-extension'
|
4
|
-
export { useKeymap } from './hooks/use-keymap'
|
5
|
-
export type { PropsWithChildren, PropsWithClass } from './types'
|