@prosekit/preact 0.3.12 → 0.3.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.
@@ -0,0 +1,50 @@
1
+ import {
2
+ useEditorContext
3
+ } from "./chunk-V253IGNY.js";
4
+
5
+ // src/components/create-component.ts
6
+ import { createElement } from "preact";
7
+ import {
8
+ forwardRef
9
+ } from "preact/compat";
10
+ import { useLayoutEffect, useState } from "preact/hooks";
11
+ import { mergeRefs } from "react-merge-refs";
12
+ function createComponent(tagName, displayName, defaultProps) {
13
+ const propertyNames = Object.keys(defaultProps);
14
+ const hasEditor = Object.hasOwn(defaultProps, "editor");
15
+ const Component = forwardRef((props, ref) => {
16
+ const [el, setEl] = useState(null);
17
+ const properties = {};
18
+ const attributes = {};
19
+ for (const [name, value] of Object.entries(props)) {
20
+ if (propertyNames.includes(name)) {
21
+ properties[name] = value;
22
+ } else {
23
+ attributes[name === "className" ? "class" : name] = value;
24
+ }
25
+ }
26
+ const editor = useEditorContext();
27
+ if (hasEditor && editor && !properties["editor"]) {
28
+ properties["editor"] = editor;
29
+ }
30
+ useLayoutEffect(() => {
31
+ if (el) {
32
+ for (const [name, value] of Object.entries(properties)) {
33
+ if (value !== void 0) {
34
+ el[name] = value;
35
+ }
36
+ }
37
+ }
38
+ }, [el, ...propertyNames.map((name) => properties[name])]);
39
+ return createElement(tagName, {
40
+ ...attributes,
41
+ ref: mergeRefs([ref, setEl])
42
+ });
43
+ });
44
+ Component.displayName = displayName;
45
+ return Component;
46
+ }
47
+
48
+ export {
49
+ createComponent
50
+ };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createComponent
3
- } from "./chunk-4VB6FIF2.js";
3
+ } from "./chunk-5LWA54E4.js";
4
4
  import "./chunk-V253IGNY.js";
5
5
 
6
6
  // src/components/autocomplete/autocomplete-empty.gen.ts
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createComponent
3
- } from "./chunk-4VB6FIF2.js";
3
+ } from "./chunk-5LWA54E4.js";
4
4
  import "./chunk-V253IGNY.js";
5
5
 
6
6
  // src/components/block-handle/block-drag-handle.gen.ts
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createComponent
3
- } from "./chunk-4VB6FIF2.js";
3
+ } from "./chunk-5LWA54E4.js";
4
4
  import "./chunk-V253IGNY.js";
5
5
 
6
6
  // src/components/inline-popover/inline-popover.gen.ts
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createComponent
3
- } from "./chunk-4VB6FIF2.js";
3
+ } from "./chunk-5LWA54E4.js";
4
4
  import "./chunk-V253IGNY.js";
5
5
 
6
6
  // src/components/popover/popover-content.gen.ts
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createComponent
3
- } from "./chunk-4VB6FIF2.js";
3
+ } from "./chunk-5LWA54E4.js";
4
4
  import "./chunk-V253IGNY.js";
5
5
 
6
6
  // src/components/resizable/resizable-handle.gen.ts
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createComponent
3
- } from "./chunk-4VB6FIF2.js";
3
+ } from "./chunk-5LWA54E4.js";
4
4
  import "./chunk-V253IGNY.js";
5
5
 
6
6
  // src/components/tooltip/tooltip-content.gen.ts
@@ -6,7 +6,7 @@ import {
6
6
  // src/components/prosekit.ts
7
7
  import { h } from "preact";
8
8
  var ProseKit = (props) => {
9
- let { editor, children } = props;
9
+ const { editor, children } = props;
10
10
  return h(EditorContextProvider, { value: editor, children });
11
11
  };
12
12
 
@@ -20,24 +20,27 @@ import {
20
20
  import { useEffect, useReducer } from "preact/hooks";
21
21
  function useEditor(options) {
22
22
  var _a;
23
- let update = (_a = options == null ? void 0 : options.update) != null ? _a : !1, editor = useEditorContext();
24
- if (!editor)
23
+ const update = (_a = options == null ? void 0 : options.update) != null ? _a : false;
24
+ const editor = useEditorContext();
25
+ if (!editor) {
25
26
  throw new ProseKitError(
26
27
  "useEditor must be used within the ProseKit component"
27
28
  );
28
- let forceUpdate = useForceUpdate();
29
- return useEffect(() => {
29
+ }
30
+ const forceUpdate = useForceUpdate();
31
+ useEffect(() => {
30
32
  if (update) {
31
- let extension = union([
33
+ const extension = union([
32
34
  defineMountHandler(forceUpdate),
33
35
  defineUpdateHandler(forceUpdate)
34
36
  ]);
35
37
  return editor.use(extension);
36
38
  }
37
- }, [editor, update, forceUpdate]), editor;
39
+ }, [editor, update, forceUpdate]);
40
+ return editor;
38
41
  }
39
42
  function useForceUpdate() {
40
- let [, dispatch] = useReducer((x) => x + 1, 0);
43
+ const [, dispatch] = useReducer((x) => x + 1, 0);
41
44
  return dispatch;
42
45
  }
43
46
 
@@ -48,11 +51,13 @@ import "@prosekit/core";
48
51
  import { EditorNotFoundError } from "@prosekit/core";
49
52
  import { useEffect as useEffect2 } from "preact/hooks";
50
53
  function useEditorExtension(editor, extension) {
51
- if (!editor)
54
+ if (!editor) {
52
55
  throw new EditorNotFoundError();
56
+ }
53
57
  useEffect2(() => {
54
- if (extension)
58
+ if (extension) {
55
59
  return editor.use(extension);
60
+ }
56
61
  }, [editor, extension]);
57
62
  }
58
63
 
@@ -60,12 +65,14 @@ function useEditorExtension(editor, extension) {
60
65
  import { withPriority } from "@prosekit/core";
61
66
  import { useMemo } from "preact/hooks";
62
67
  function usePriorityExtension(extension, priority) {
63
- return useMemo(() => extension && priority ? withPriority(extension, priority) : extension, [extension, priority]);
68
+ return useMemo(() => {
69
+ return extension && priority ? withPriority(extension, priority) : extension;
70
+ }, [extension, priority]);
64
71
  }
65
72
 
66
73
  // src/hooks/use-extension.ts
67
74
  function useExtension(extension, options) {
68
- let editorContext = useEditorContext();
75
+ const editorContext = useEditorContext();
69
76
  useEditorExtension(
70
77
  (options == null ? void 0 : options.editor) || editorContext,
71
78
  usePriorityExtension(extension, options == null ? void 0 : options.priority)
@@ -76,7 +83,7 @@ function useExtension(extension, options) {
76
83
  import { defineKeymap } from "@prosekit/core";
77
84
  import { useMemo as useMemo2 } from "preact/hooks";
78
85
  function useKeymap(keymap, options) {
79
- let extension = useMemo2(() => defineKeymap(keymap), [keymap]);
86
+ const extension = useMemo2(() => defineKeymap(keymap), [keymap]);
80
87
  return useExtension(extension, options);
81
88
  }
82
89
 
@@ -84,7 +91,7 @@ function useKeymap(keymap, options) {
84
91
  import { defineUpdateHandler as defineUpdateHandler2 } from "@prosekit/core";
85
92
  import { useMemo as useMemo3 } from "preact/hooks";
86
93
  function useStateUpdate(handler, options) {
87
- let extension = useMemo3(
94
+ const extension = useMemo3(
88
95
  () => defineUpdateHandler2((view) => handler(view.state)),
89
96
  [handler]
90
97
  );
@@ -95,7 +102,7 @@ function useStateUpdate(handler, options) {
95
102
  import { defineDocChangeHandler } from "@prosekit/core";
96
103
  import { useMemo as useMemo4 } from "preact/hooks";
97
104
  function useDocChange(handler, options) {
98
- let extension = useMemo4(
105
+ const extension = useMemo4(
99
106
  () => defineDocChangeHandler((view) => handler(view.state.doc)),
100
107
  [handler]
101
108
  );
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prosekit/preact",
3
3
  "type": "module",
4
- "version": "0.3.12",
4
+ "version": "0.3.14",
5
5
  "private": false,
6
6
  "author": {
7
7
  "name": "ocavue",
@@ -66,9 +66,9 @@
66
66
  ],
67
67
  "dependencies": {
68
68
  "react-merge-refs": "^2.1.1",
69
- "@prosekit/pm": "^0.1.5",
70
- "@prosekit/web": "^0.3.1",
71
- "@prosekit/core": "^0.7.2"
69
+ "@prosekit/pm": "^0.1.6",
70
+ "@prosekit/core": "^0.7.3",
71
+ "@prosekit/web": "^0.3.3"
72
72
  },
73
73
  "peerDependencies": {
74
74
  "preact": ">= 10.11.0"
@@ -1,32 +0,0 @@
1
- import {
2
- useEditorContext
3
- } from "./chunk-V253IGNY.js";
4
-
5
- // src/components/create-component.ts
6
- import { createElement } from "preact";
7
- import {
8
- forwardRef
9
- } from "preact/compat";
10
- import { useLayoutEffect, useState } from "preact/hooks";
11
- import { mergeRefs } from "react-merge-refs";
12
- function createComponent(tagName, displayName, defaultProps) {
13
- let propertyNames = Object.keys(defaultProps), hasEditor = Object.hasOwn(defaultProps, "editor"), Component = forwardRef((props, ref) => {
14
- let [el, setEl] = useState(null), properties = {}, attributes = {};
15
- for (let [name, value] of Object.entries(props))
16
- propertyNames.includes(name) ? properties[name] = value : attributes[name === "className" ? "class" : name] = value;
17
- let editor = useEditorContext();
18
- return hasEditor && editor && !properties.editor && (properties.editor = editor), useLayoutEffect(() => {
19
- if (el)
20
- for (let [name, value] of Object.entries(properties))
21
- value !== void 0 && (el[name] = value);
22
- }, [el, ...propertyNames.map((name) => properties[name])]), createElement(tagName, {
23
- ...attributes,
24
- ref: mergeRefs([ref, setEl])
25
- });
26
- });
27
- return Component.displayName = displayName, Component;
28
- }
29
-
30
- export {
31
- createComponent
32
- };