@prosekit/solid 0.1.1 → 0.1.3

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,16 +17,14 @@ import { Options } from 'tsup';
17
17
  import { ParentProps } from 'solid-js';
18
18
  import { PopoverOptions } from '@prosekit/lit/autocomplete-popover';
19
19
  import type { PopoverProps as PopoverProps_2 } from '@prosekit/lit/popover';
20
+ import { Priority } from '@prosekit/core';
20
21
  import { UserProjectConfigExport } from 'vitest/dist/config.js';
21
22
 
22
23
  declare const AutocompleteEmpty: Component<AutocompleteEmptyProps>;
23
24
  export { AutocompleteEmpty }
24
25
  export { AutocompleteEmpty as AutocompleteEmpty_alias_1 }
25
26
 
26
- declare type AutocompleteEmptyProps = {
27
- class?: string;
28
- children?: JSXElement;
29
- } & AutocompleteEmptyProps_2;
27
+ declare type AutocompleteEmptyProps = PropsWithChildren<PropsWithClass<AutocompleteEmptyProps_2>>;
30
28
  export { AutocompleteEmptyProps }
31
29
  export { AutocompleteEmptyProps as AutocompleteEmptyProps_alias_1 }
32
30
 
@@ -34,10 +32,7 @@ declare const AutocompleteItem: Component<AutocompleteItemProps>;
34
32
  export { AutocompleteItem }
35
33
  export { AutocompleteItem as AutocompleteItem_alias_1 }
36
34
 
37
- declare type AutocompleteItemProps = {
38
- class?: string;
39
- children?: JSXElement;
40
- } & AutocompleteItemProps_2;
35
+ declare type AutocompleteItemProps = PropsWithChildren<PropsWithClass<AutocompleteItemProps_2>>;
41
36
  export { AutocompleteItemProps }
42
37
  export { AutocompleteItemProps as AutocompleteItemProps_alias_1 }
43
38
 
@@ -45,10 +40,7 @@ declare const AutocompleteList: Component<AutocompleteListProps>;
45
40
  export { AutocompleteList }
46
41
  export { AutocompleteList as AutocompleteList_alias_1 }
47
42
 
48
- declare type AutocompleteListProps = {
49
- class?: string;
50
- children?: JSXElement;
51
- } & AutocompleteListProps_2;
43
+ declare type AutocompleteListProps = PropsWithChildren<PropsWithClass<AutocompleteListProps_2>>;
52
44
  export { AutocompleteListProps }
53
45
  export { AutocompleteListProps as AutocompleteListProps_alias_1 }
54
46
 
@@ -56,10 +48,7 @@ declare const AutocompletePopover: Component<AutocompletePopoverProps>;
56
48
  export { AutocompletePopover }
57
49
  export { AutocompletePopover as AutocompletePopover_alias_1 }
58
50
 
59
- declare type AutocompletePopoverProps = {
60
- class?: string;
61
- children?: JSXElement;
62
- } & AutocompletePopoverProps_2;
51
+ declare type AutocompletePopoverProps = PropsWithChildren<PropsWithClass<AutocompletePopoverProps_2>>;
63
52
  export { AutocompletePopoverProps }
64
53
  export { AutocompletePopoverProps as AutocompletePopoverProps_alias_1 }
65
54
 
@@ -67,29 +56,17 @@ export declare const ComboBox: Component<ComboBoxProps>;
67
56
 
68
57
  export declare const ComboBoxInput: Component<ComboBoxInputProps>;
69
58
 
70
- export declare type ComboBoxInputProps = {
71
- class?: string;
72
- children?: JSXElement;
73
- } & ComboBoxInputProps_2;
59
+ export declare type ComboBoxInputProps = PropsWithChildren<PropsWithClass<ComboBoxInputProps_2>>;
74
60
 
75
61
  export declare const ComboBoxItem: Component<ComboBoxItemProps>;
76
62
 
77
- export declare type ComboBoxItemProps = {
78
- class?: string;
79
- children?: JSXElement;
80
- } & ComboBoxItemProps_2;
63
+ export declare type ComboBoxItemProps = PropsWithChildren<PropsWithClass<ComboBoxItemProps_2>>;
81
64
 
82
65
  export declare const ComboBoxList: Component<ComboBoxListProps>;
83
66
 
84
- export declare type ComboBoxListProps = {
85
- class?: string;
86
- children?: JSXElement;
87
- } & ComboBoxListProps_2;
67
+ export declare type ComboBoxListProps = PropsWithChildren<PropsWithClass<ComboBoxListProps_2>>;
88
68
 
89
- export declare type ComboBoxProps = {
90
- class?: string;
91
- children?: JSXElement;
92
- } & ComboBoxProps_2;
69
+ export declare type ComboBoxProps = PropsWithChildren<PropsWithClass<ComboBoxProps_2>>;
93
70
 
94
71
  export declare const default_alias: Options | Options[] | ((overrideOptions: Options) => Options | Options[] | Promise<Options | Options[]>);
95
72
 
@@ -105,19 +82,31 @@ export declare function forceProps<T extends Record<string, any>>(props: T): T;
105
82
 
106
83
  export declare const InlinePopover: Component<InlinePopoverProps>;
107
84
 
108
- export declare type InlinePopoverProps = {
109
- class?: string;
110
- children?: JSXElement;
111
- } & InlinePopoverProps_2;
85
+ export declare type InlinePopoverProps = PropsWithChildren<PropsWithClass<InlinePopoverProps_2>>;
112
86
 
113
87
  export declare const Popover: Component<PopoverProps>;
114
88
 
115
89
  export { PopoverOptions }
116
90
 
117
- export declare type PopoverProps = {
118
- class?: string;
119
- children?: JSXElement;
120
- } & PopoverProps_2;
91
+ export declare type PopoverProps = PropsWithChildren<PropsWithClass<PopoverProps_2>>;
92
+
93
+ /**
94
+ * @internal
95
+ */
96
+ declare type PropsWithChildren<P = unknown> = P & {
97
+ children?: JSXElement | undefined;
98
+ };
99
+ export { PropsWithChildren }
100
+ export { PropsWithChildren as PropsWithChildren_alias_1 }
101
+
102
+ /**
103
+ * @internal
104
+ */
105
+ declare type PropsWithClass<P = unknown> = P & {
106
+ class?: string | undefined;
107
+ };
108
+ export { PropsWithClass }
109
+ export { PropsWithClass as PropsWithClass_alias_1 }
121
110
 
122
111
  declare const ProseKit: Component<ProseKitProps>;
123
112
  export { ProseKit }
@@ -137,12 +126,23 @@ export declare interface UseEditorOptions {
137
126
  update?: boolean;
138
127
  }
139
128
 
140
- declare function useExtension<T extends Extension = Extension>(extension: T): void;
129
+ /**
130
+ * Add an extension to the editor.
131
+ *
132
+ * It accepts an accessor to an optional extension. If the extension is changed,
133
+ * the previous extension will be removed and the new one (if not null) will be
134
+ * added.
135
+ */
136
+ declare function useExtension<T extends Extension = Extension>(extension: (T | null) | (() => T | null)): void;
141
137
  export { useExtension }
142
138
  export { useExtension as useExtension_alias_1 }
143
139
 
144
- declare function useKeymap(keymap: Keymap): void;
140
+ declare function useKeymap(keymap: Keymap | (() => Keymap), options?: {
141
+ priority?: Priority;
142
+ }): void;
145
143
  export { useKeymap }
146
144
  export { useKeymap as useKeymap_alias_1 }
147
145
 
146
+ export declare function usePriorityExtension<T extends Extension = Extension>(extension: () => T | null, priority?: Priority | null): void;
147
+
148
148
  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';
@@ -54,17 +54,44 @@ function useForceUpdate() {
54
54
  import "@prosekit/core";
55
55
  import { createEffect as createEffect2, onCleanup } from "solid-js";
56
56
  function useExtension(extension) {
57
+ if (typeof extension !== "function") {
58
+ console.warn(
59
+ "useExtension should accept a function that returns an extension or null"
60
+ );
61
+ return useExtension(() => extension);
62
+ }
63
+ const extensionAccessor = extension;
57
64
  const editor = useEditor();
58
65
  createEffect2(() => {
59
- onCleanup(editor().use(extension));
66
+ const extension2 = extensionAccessor();
67
+ if (extension2) {
68
+ onCleanup(editor().use(extension2));
69
+ }
60
70
  });
61
71
  }
62
72
 
63
73
  // src/hooks/use-keymap.ts
64
74
  import { defineKeymap } from "@prosekit/core";
65
- function useKeymap(keymap) {
66
- const extension = defineKeymap(keymap);
67
- useExtension(extension);
75
+
76
+ // src/hooks/use-priority-extension.ts
77
+ import { withPriority } from "@prosekit/core";
78
+ function usePriorityExtension(extension, priority) {
79
+ const extensionWithPriority = () => {
80
+ const ext = extension();
81
+ return ext && priority ? withPriority(ext, priority) : ext;
82
+ };
83
+ return useExtension(extensionWithPriority);
84
+ }
85
+
86
+ // src/hooks/use-keymap.ts
87
+ function useKeymap(keymap, options) {
88
+ if (typeof keymap !== "function") {
89
+ console.warn(
90
+ "useKeymap should accept a function that returns a keymap object"
91
+ );
92
+ return useKeymap(() => keymap);
93
+ }
94
+ return usePriorityExtension(() => defineKeymap(keymap()), options == null ? void 0 : options.priority);
68
95
  }
69
96
  export {
70
97
  ProseKit,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prosekit/solid",
3
3
  "type": "module",
4
- "version": "0.1.1",
4
+ "version": "0.1.3",
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
- "solid-js": "^1.8.5",
102
- "tsup": "^7.2.0",
103
- "typescript": "^5.2.2",
101
+ "solid-js": "^1.8.6",
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 CHANGED
@@ -2,3 +2,4 @@ export { ProseKit, type ProseKitProps } from './components/prosekit'
2
2
  export { useEditor } from './hooks/use-editor'
3
3
  export { useExtension } from './hooks/use-extension'
4
4
  export { useKeymap } from './hooks/use-keymap'
5
+ export type { PropsWithChildren, PropsWithClass } from './types'