@prosekit/preact 0.1.0 → 0.1.2

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.
@@ -16,16 +16,14 @@ import { Keymap } from '@prosekit/core';
16
16
  import { Options } from 'tsup';
17
17
  import { PopoverOptions } from '@prosekit/lit/autocomplete-popover';
18
18
  import type { PopoverProps as PopoverProps_2 } from '@prosekit/lit/popover';
19
+ import { Priority } from '@prosekit/core';
19
20
  import { UserProjectConfigExport } from 'vitest/dist/config.js';
20
21
 
21
22
  declare const AutocompleteEmpty: ComponentType<AutocompleteEmptyProps>;
22
23
  export { AutocompleteEmpty }
23
24
  export { AutocompleteEmpty as AutocompleteEmpty_alias_1 }
24
25
 
25
- declare type AutocompleteEmptyProps = {
26
- class?: string;
27
- children?: ComponentChildren;
28
- } & AutocompleteEmptyProps_2;
26
+ declare type AutocompleteEmptyProps = PropsWithChildren<PropsWithClass<AutocompleteEmptyProps_2>>;
29
27
  export { AutocompleteEmptyProps }
30
28
  export { AutocompleteEmptyProps as AutocompleteEmptyProps_alias_1 }
31
29
 
@@ -33,10 +31,7 @@ declare const AutocompleteItem: ComponentType<AutocompleteItemProps>;
33
31
  export { AutocompleteItem }
34
32
  export { AutocompleteItem as AutocompleteItem_alias_1 }
35
33
 
36
- declare type AutocompleteItemProps = {
37
- class?: string;
38
- children?: ComponentChildren;
39
- } & AutocompleteItemProps_2;
34
+ declare type AutocompleteItemProps = PropsWithChildren<PropsWithClass<AutocompleteItemProps_2>>;
40
35
  export { AutocompleteItemProps }
41
36
  export { AutocompleteItemProps as AutocompleteItemProps_alias_1 }
42
37
 
@@ -44,10 +39,7 @@ declare const AutocompleteList: ComponentType<AutocompleteListProps>;
44
39
  export { AutocompleteList }
45
40
  export { AutocompleteList as AutocompleteList_alias_1 }
46
41
 
47
- declare type AutocompleteListProps = {
48
- class?: string;
49
- children?: ComponentChildren;
50
- } & AutocompleteListProps_2;
42
+ declare type AutocompleteListProps = PropsWithChildren<PropsWithClass<AutocompleteListProps_2>>;
51
43
  export { AutocompleteListProps }
52
44
  export { AutocompleteListProps as AutocompleteListProps_alias_1 }
53
45
 
@@ -55,10 +47,7 @@ declare const AutocompletePopover: ComponentType<AutocompletePopoverProps>;
55
47
  export { AutocompletePopover }
56
48
  export { AutocompletePopover as AutocompletePopover_alias_1 }
57
49
 
58
- declare type AutocompletePopoverProps = {
59
- class?: string;
60
- children?: ComponentChildren;
61
- } & AutocompletePopoverProps_2;
50
+ declare type AutocompletePopoverProps = PropsWithChildren<PropsWithClass<AutocompletePopoverProps_2>>;
62
51
  export { AutocompletePopoverProps }
63
52
  export { AutocompletePopoverProps as AutocompletePopoverProps_alias_1 }
64
53
 
@@ -66,29 +55,17 @@ export declare const ComboBox: ComponentType<ComboBoxProps>;
66
55
 
67
56
  export declare const ComboBoxInput: ComponentType<ComboBoxInputProps>;
68
57
 
69
- export declare type ComboBoxInputProps = {
70
- class?: string;
71
- children?: ComponentChildren;
72
- } & ComboBoxInputProps_2;
58
+ export declare type ComboBoxInputProps = PropsWithChildren<PropsWithClass<ComboBoxInputProps_2>>;
73
59
 
74
60
  export declare const ComboBoxItem: ComponentType<ComboBoxItemProps>;
75
61
 
76
- export declare type ComboBoxItemProps = {
77
- class?: string;
78
- children?: ComponentChildren;
79
- } & ComboBoxItemProps_2;
62
+ export declare type ComboBoxItemProps = PropsWithChildren<PropsWithClass<ComboBoxItemProps_2>>;
80
63
 
81
64
  export declare const ComboBoxList: ComponentType<ComboBoxListProps>;
82
65
 
83
- export declare type ComboBoxListProps = {
84
- class?: string;
85
- children?: ComponentChildren;
86
- } & ComboBoxListProps_2;
66
+ export declare type ComboBoxListProps = PropsWithChildren<PropsWithClass<ComboBoxListProps_2>>;
87
67
 
88
- export declare type ComboBoxProps = {
89
- class?: string;
90
- children?: ComponentChildren;
91
- } & ComboBoxProps_2;
68
+ export declare type ComboBoxProps = PropsWithChildren<PropsWithClass<ComboBoxProps_2>>;
92
69
 
93
70
  export declare const default_alias: Options | Options[] | ((overrideOptions: Options) => Options | Options[] | Promise<Options | Options[]>);
94
71
 
@@ -102,19 +79,32 @@ export declare const editorContext: Context<EditorContext | null>;
102
79
 
103
80
  export declare const InlinePopover: ComponentType<InlinePopoverProps>;
104
81
 
105
- export declare type InlinePopoverProps = {
106
- class?: string;
107
- children?: ComponentChildren;
108
- } & InlinePopoverProps_2;
82
+ export declare type InlinePopoverProps = PropsWithChildren<PropsWithClass<InlinePopoverProps_2>>;
109
83
 
110
84
  export declare const Popover: ComponentType<PopoverProps>;
111
85
 
112
86
  export { PopoverOptions }
113
87
 
114
- export declare type PopoverProps = {
115
- class?: string;
116
- children?: ComponentChildren;
117
- } & PopoverProps_2;
88
+ export declare type PopoverProps = PropsWithChildren<PropsWithClass<PopoverProps_2>>;
89
+
90
+ /**
91
+ * @internal
92
+ */
93
+ declare type PropsWithChildren<P = unknown> = P & {
94
+ children?: ComponentChildren | undefined;
95
+ };
96
+ export { PropsWithChildren }
97
+ export { PropsWithChildren as PropsWithChildren_alias_1 }
98
+
99
+ /**
100
+ * @internal
101
+ */
102
+ declare type PropsWithClass<P = unknown> = P & {
103
+ class?: string | undefined;
104
+ className?: string | undefined;
105
+ };
106
+ export { PropsWithClass }
107
+ export { PropsWithClass as PropsWithClass_alias_1 }
118
108
 
119
109
  declare const ProseKit: ComponentType<ProseKitProps>;
120
110
  export { ProseKit }
@@ -131,12 +121,22 @@ declare function useEditor<E extends Extension = any>(): Editor<E>;
131
121
  export { useEditor }
132
122
  export { useEditor as useEditor_alias_1 }
133
123
 
134
- declare function useExtension<T extends Extension = Extension>(extension: T): void;
124
+ /**
125
+ * Add an extension to the editor.
126
+ *
127
+ * It accepts an optional extension. If the extension is changed, the previous
128
+ * extension will be removed and the new one (if not null) will be added.
129
+ */
130
+ declare function useExtension<T extends Extension = Extension>(extension: T | null): void;
135
131
  export { useExtension }
136
132
  export { useExtension as useExtension_alias_1 }
137
133
 
138
- declare function useKeymap(keymap: Keymap): void;
134
+ declare function useKeymap(keymap: Keymap, options?: {
135
+ priority?: Priority;
136
+ }): void;
139
137
  export { useKeymap }
140
138
  export { useKeymap as useKeymap_alias_1 }
141
139
 
140
+ export declare function usePriorityExtension<T extends Extension = Extension>(extension: T | null, priority?: Priority | null): void;
141
+
142
142
  export { }
@@ -3,3 +3,5 @@ export { ProseKitProps } from './_tsup-dts-rollup';
3
3
  export { useEditor } from './_tsup-dts-rollup';
4
4
  export { useExtension } from './_tsup-dts-rollup';
5
5
  export { useKeymap } from './_tsup-dts-rollup';
6
+ export { PropsWithChildren } from './_tsup-dts-rollup';
7
+ export { PropsWithClass } from './_tsup-dts-rollup';
@@ -31,16 +31,30 @@ import { useEffect } from "preact/hooks";
31
31
  function useExtension(extension) {
32
32
  const editor = useEditor();
33
33
  useEffect(() => {
34
- return editor.use(extension);
34
+ if (extension) {
35
+ return editor.use(extension);
36
+ }
35
37
  }, [editor, extension]);
36
38
  }
37
39
 
38
40
  // src/hooks/use-keymap.ts
39
41
  import { defineKeymap } from "@prosekit/core";
42
+ import { useMemo as useMemo2 } from "preact/hooks";
43
+
44
+ // src/hooks/use-priority-extension.ts
45
+ import { withPriority } from "@prosekit/core";
40
46
  import { useMemo } from "preact/hooks";
41
- function useKeymap(keymap) {
42
- const extension = useMemo(() => defineKeymap(keymap), [keymap]);
43
- useExtension(extension);
47
+ function usePriorityExtension(extension, priority) {
48
+ const extensionWithPriority = useMemo(() => {
49
+ return extension && priority ? withPriority(extension, priority) : extension;
50
+ }, [extension, priority]);
51
+ return useExtension(extensionWithPriority);
52
+ }
53
+
54
+ // src/hooks/use-keymap.ts
55
+ function useKeymap(keymap, options) {
56
+ const extension = useMemo2(() => defineKeymap(keymap), [keymap]);
57
+ usePriorityExtension(extension, options == null ? void 0 : options.priority);
44
58
  }
45
59
  export {
46
60
  ProseKit,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prosekit/preact",
3
3
  "type": "module",
4
- "version": "0.1.0",
4
+ "version": "0.1.2",
5
5
  "private": false,
6
6
  "author": {
7
7
  "name": "ocavue",
@@ -98,9 +98,9 @@
98
98
  },
99
99
  "devDependencies": {
100
100
  "@prosekit/dev": "*",
101
- "preact": "^10.18.2",
102
- "tsup": "^7.2.0",
103
- "typescript": "^5.2.2",
101
+ "preact": "^10.19.2",
102
+ "tsup": "^8.0.1",
103
+ "typescript": "^5.3.2",
104
104
  "vitest": "^0.34.6"
105
105
  },
106
106
  "scripts": {
package/src/index.ts ADDED
@@ -0,0 +1,5 @@
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'