@prosekit/preact 0.2.2 → 0.2.4

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.
@@ -17,6 +17,7 @@ import { Options } from 'tsup';
17
17
  import type { PopoverProps as PopoverProps_2 } from '@prosekit/lit/popover';
18
18
  import { PositioningOptions } from '@prosekit/lit/autocomplete-popover';
19
19
  import { Priority } from '@prosekit/core';
20
+ import type { ProseMirrorNode } from '@prosekit/pm/model';
20
21
  import { Provider } from 'preact';
21
22
  import type { ResizableHandleProps as ResizableHandleProps_2 } from '@prosekit/lit/resizable-handle';
22
23
  import type { ResizableProps as ResizableProps_2 } from '@prosekit/lit/resizable';
@@ -135,6 +136,15 @@ export declare type ResizableHandleProps = PropsWithChildren<PropsWithClass<Resi
135
136
 
136
137
  export declare type ResizableProps = PropsWithChildren<PropsWithClass<ResizableProps_2>>;
137
138
 
139
+ /**
140
+ * Calls the given handler whenever the editor document changes.
141
+ *
142
+ * @public
143
+ */
144
+ declare function useDocChange(handler: (doc: ProseMirrorNode) => void, options?: UseExtensionOptions): void;
145
+ export { useDocChange }
146
+ export { useDocChange as useDocChange_alias_1 }
147
+
138
148
  /**
139
149
  * Retrieves the editor instance from the nearest ProseKit component.
140
150
  *
@@ -5,5 +5,6 @@ export { useExtension } from './_tsup-dts-rollup';
5
5
  export { UseExtensionOptions } from './_tsup-dts-rollup';
6
6
  export { useKeymap } from './_tsup-dts-rollup';
7
7
  export { useStateUpdate } from './_tsup-dts-rollup';
8
+ export { useDocChange } from './_tsup-dts-rollup';
8
9
  export { PropsWithChildren } from './_tsup-dts-rollup';
9
10
  export { PropsWithClass } from './_tsup-dts-rollup';
@@ -95,12 +95,28 @@ function useKeymap(keymap, options) {
95
95
 
96
96
  // src/hooks/use-state-update.ts
97
97
  import { defineUpdateHandler as defineUpdateHandler2 } from "@prosekit/core";
98
+ import { useMemo as useMemo3 } from "preact/hooks";
98
99
  function useStateUpdate(handler, options) {
99
- const extension = defineUpdateHandler2((view) => handler(view.state));
100
+ const extension = useMemo3(
101
+ () => defineUpdateHandler2((view) => handler(view.state)),
102
+ [handler]
103
+ );
104
+ return useExtension(extension, options);
105
+ }
106
+
107
+ // src/hooks/use-doc-change.ts
108
+ import { defineDocChangeHandler } from "@prosekit/core";
109
+ import { useMemo as useMemo4 } from "preact/hooks";
110
+ function useDocChange(handler, options) {
111
+ const extension = useMemo4(
112
+ () => defineDocChangeHandler((view) => handler(view.state.doc)),
113
+ [handler]
114
+ );
100
115
  return useExtension(extension, options);
101
116
  }
102
117
  export {
103
118
  ProseKit,
119
+ useDocChange,
104
120
  useEditor,
105
121
  useExtension,
106
122
  useKeymap,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prosekit/preact",
3
3
  "type": "module",
4
- "version": "0.2.2",
4
+ "version": "0.2.4",
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.7",
99
- "@prosekit/lit": "^0.2.1",
98
+ "@prosekit/core": "^0.3.0",
99
+ "@prosekit/lit": "^0.2.2",
100
100
  "@prosekit/pm": "^0.1.1"
101
101
  },
102
102
  "peerDependencies": {
@@ -112,7 +112,7 @@
112
112
  "preact": "^10.19.3",
113
113
  "tsup": "^8.0.1",
114
114
  "typescript": "^5.3.3",
115
- "vitest": "^1.2.1"
115
+ "vitest": "^1.2.2"
116
116
  },
117
117
  "scripts": {
118
118
  "build:tsup": "tsup",