@prosekit/react 0.0.12 → 0.0.14

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.
@@ -122,10 +122,16 @@ declare interface ProseKitProps {
122
122
  export { ProseKitProps }
123
123
  export { ProseKitProps as ProseKitProps_alias_1 }
124
124
 
125
- declare function useEditor<E extends Extension = any>(): Editor<E>;
125
+ declare function useEditor<E extends Extension = any>(options?: UseEditorOptions): Editor<E>;
126
126
  export { useEditor }
127
127
  export { useEditor as useEditor_alias_1 }
128
128
 
129
+ declare interface UseEditorOptions {
130
+ update?: boolean;
131
+ }
132
+ export { UseEditorOptions }
133
+ export { UseEditorOptions as UseEditorOptions_alias_1 }
134
+
129
135
  declare function useExtension({ extension }: UseExtensionProps): void;
130
136
  export { useExtension }
131
137
  export { useExtension as useExtension_alias_1 }
@@ -1,5 +1,6 @@
1
1
  export { ProseKit } from './_tsup-dts-rollup';
2
2
  export { ProseKitProps } from './_tsup-dts-rollup';
3
3
  export { useEditor } from './_tsup-dts-rollup';
4
+ export { UseEditorOptions } from './_tsup-dts-rollup';
4
5
  export { useExtension } from './_tsup-dts-rollup';
5
6
  export { useKeymap } from './_tsup-dts-rollup';
@@ -14,24 +14,40 @@ var ProseKit = (props) => {
14
14
  var EditorContextProvider = editorContext.Provider;
15
15
 
16
16
  // src/hooks/use-editor.ts
17
- import { ProseKitError } from "@prosekit/core";
18
- import { useContext } from "react";
19
- function useEditor() {
17
+ import {
18
+ ProseKitError,
19
+ addEventHandler
20
+ } from "@prosekit/core";
21
+ import { useContext, useEffect, useReducer } from "react";
22
+ function useEditor(options) {
23
+ var _a;
24
+ const update = (_a = options == null ? void 0 : options.update) != null ? _a : false;
20
25
  const value = useContext(editorContext);
21
26
  if (!value) {
22
27
  throw new ProseKitError(
23
28
  "useEditor must be used within the ProseKit component"
24
29
  );
25
30
  }
26
- return value.editor;
31
+ const editor = value.editor;
32
+ const forceUpdate = useForceUpdate();
33
+ useEffect(() => {
34
+ if (update) {
35
+ return editor.use(addEventHandler({ update: forceUpdate }));
36
+ }
37
+ }, [editor, update, forceUpdate]);
38
+ return editor;
39
+ }
40
+ function useForceUpdate() {
41
+ const [, dispatch] = useReducer((x) => x + 1, 0);
42
+ return dispatch;
27
43
  }
28
44
 
29
45
  // src/hooks/use-extension.ts
30
46
  import "@prosekit/core";
31
- import { useEffect } from "react";
47
+ import { useEffect as useEffect2 } from "react";
32
48
  function useExtension({ extension }) {
33
49
  const editor = useEditor();
34
- useEffect(() => editor.use(extension), [editor, extension]);
50
+ useEffect2(() => editor.use(extension), [editor, extension]);
35
51
  }
36
52
 
37
53
  // src/hooks/use-keymap.ts
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prosekit/react",
3
3
  "type": "module",
4
- "version": "0.0.12",
4
+ "version": "0.0.14",
5
5
  "private": false,
6
6
  "author": {
7
7
  "name": "ocavue",
@@ -80,9 +80,9 @@
80
80
  "dist"
81
81
  ],
82
82
  "dependencies": {
83
- "@lit-labs/react": "^2.0.2",
84
- "@prosekit/core": "^0.0.9",
85
- "@prosekit/lit": "^0.0.12"
83
+ "@lit-labs/react": "^2.0.3",
84
+ "@prosekit/core": "^0.0.11",
85
+ "@prosekit/lit": "^0.0.14"
86
86
  },
87
87
  "peerDependencies": {
88
88
  "react": ">= 17.0.0",
@@ -98,13 +98,13 @@
98
98
  },
99
99
  "devDependencies": {
100
100
  "@prosekit/dev": "*",
101
- "@types/react": "^18.2.21",
101
+ "@types/react": "^18.2.22",
102
102
  "@types/react-dom": "^18.2.7",
103
103
  "react": "^18.2.0",
104
104
  "react-dom": "^18.2.0",
105
105
  "tsup": "^7.2.0",
106
106
  "typescript": "^5.2.2",
107
- "vitest": "^0.34.3"
107
+ "vitest": "^0.34.5"
108
108
  },
109
109
  "scripts": {
110
110
  "build:tsup": "tsup",
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export { ProseKit, type ProseKitProps } from './components/prosekit'
2
- export { useEditor } from './hooks/use-editor'
2
+ export { useEditor, type UseEditorOptions } from './hooks/use-editor'
3
3
  export { useExtension } from './hooks/use-extension'
4
4
  export { useKeymap } from './hooks/use-keymap'