@prosekit/preact 0.1.4 → 0.2.0
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.
@@ -14,8 +14,8 @@ import { Extension } from '@prosekit/core';
|
|
14
14
|
import type { InlinePopoverProps as InlinePopoverProps_2 } from '@prosekit/lit/inline-popover';
|
15
15
|
import { Keymap } from '@prosekit/core';
|
16
16
|
import { Options } from 'tsup';
|
17
|
-
import { PopoverOptions } from '@prosekit/lit/autocomplete-popover';
|
18
17
|
import type { PopoverProps as PopoverProps_2 } from '@prosekit/lit/popover';
|
18
|
+
import { PositioningOptions } from '@prosekit/lit/autocomplete-popover';
|
19
19
|
import { Priority } from '@prosekit/core';
|
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';
|
@@ -88,10 +88,10 @@ export declare type InlinePopoverProps = PropsWithChildren<PropsWithClass<Inline
|
|
88
88
|
|
89
89
|
export declare const Popover: ComponentType<PopoverProps>;
|
90
90
|
|
91
|
-
export { PopoverOptions }
|
92
|
-
|
93
91
|
export declare type PopoverProps = PropsWithChildren<PropsWithClass<PopoverProps_2>>;
|
94
92
|
|
93
|
+
export { PositioningOptions }
|
94
|
+
|
95
95
|
/**
|
96
96
|
* @internal
|
97
97
|
*/
|
@@ -130,7 +130,20 @@ export declare type ResizableHandleProps = PropsWithChildren<PropsWithClass<Resi
|
|
130
130
|
|
131
131
|
export declare type ResizableProps = PropsWithChildren<PropsWithClass<ResizableProps_2>>;
|
132
132
|
|
133
|
-
|
133
|
+
/**
|
134
|
+
* Retrieves the editor instance from the nearest ProseKit component.
|
135
|
+
*
|
136
|
+
* @public
|
137
|
+
*/
|
138
|
+
declare function useEditor<E extends Extension = any>(options?: {
|
139
|
+
/**
|
140
|
+
* Whether to update the component when the editor is mounted or editor state
|
141
|
+
* is updated.
|
142
|
+
*
|
143
|
+
* @default false
|
144
|
+
*/
|
145
|
+
update?: boolean;
|
146
|
+
}): Editor<E>;
|
134
147
|
export { useEditor }
|
135
148
|
export { useEditor as useEditor_alias_1 }
|
136
149
|
|
@@ -1,3 +1,3 @@
|
|
1
|
-
export {
|
1
|
+
export { PositioningOptions } from './_tsup-dts-rollup';
|
2
2
|
export { AutocompletePopover_alias_1 as AutocompletePopover } from './_tsup-dts-rollup';
|
3
3
|
export { AutocompletePopoverProps_alias_1 as AutocompletePopoverProps } from './_tsup-dts-rollup';
|
package/dist/prosekit-preact.js
CHANGED
@@ -13,24 +13,46 @@ var ProseKit = (props) => {
|
|
13
13
|
var EditorContextProvider = editorContext.Provider;
|
14
14
|
|
15
15
|
// src/hooks/use-editor.ts
|
16
|
-
import {
|
17
|
-
|
18
|
-
|
16
|
+
import {
|
17
|
+
ProseKitError,
|
18
|
+
defineMountHandler,
|
19
|
+
defineUpdateHandler,
|
20
|
+
union
|
21
|
+
} from "@prosekit/core";
|
22
|
+
import { useContext, useEffect, useReducer } from "preact/hooks";
|
23
|
+
function useEditor(options) {
|
24
|
+
var _a;
|
25
|
+
const update = (_a = options == null ? void 0 : options.update) != null ? _a : false;
|
19
26
|
const value = useContext(editorContext);
|
20
27
|
if (!value) {
|
21
28
|
throw new ProseKitError(
|
22
29
|
"useEditor must be used within the ProseKit component"
|
23
30
|
);
|
24
31
|
}
|
25
|
-
|
32
|
+
const editor = value.editor;
|
33
|
+
const forceUpdate = useForceUpdate();
|
34
|
+
useEffect(() => {
|
35
|
+
if (update) {
|
36
|
+
const extension = union([
|
37
|
+
defineMountHandler(forceUpdate),
|
38
|
+
defineUpdateHandler(forceUpdate)
|
39
|
+
]);
|
40
|
+
return editor.use(extension);
|
41
|
+
}
|
42
|
+
}, [editor, update, forceUpdate]);
|
43
|
+
return editor;
|
44
|
+
}
|
45
|
+
function useForceUpdate() {
|
46
|
+
const [, dispatch] = useReducer((x) => x + 1, 0);
|
47
|
+
return dispatch;
|
26
48
|
}
|
27
49
|
|
28
50
|
// src/hooks/use-extension.ts
|
29
51
|
import "@prosekit/core";
|
30
|
-
import { useEffect } from "preact/hooks";
|
52
|
+
import { useEffect as useEffect2 } from "preact/hooks";
|
31
53
|
function useExtension(extension) {
|
32
54
|
const editor = useEditor();
|
33
|
-
|
55
|
+
useEffect2(() => {
|
34
56
|
if (extension) {
|
35
57
|
return editor.use(extension);
|
36
58
|
}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@prosekit/preact",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.
|
4
|
+
"version": "0.2.0",
|
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.
|
98
|
+
"@prosekit/core": "^0.2.5",
|
99
|
+
"@prosekit/lit": "^0.2.0"
|
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.
|
114
|
+
"vitest": "^1.2.0"
|
115
115
|
},
|
116
116
|
"scripts": {
|
117
117
|
"build:tsup": "tsup",
|