@prosekit/svelte 0.9.0 → 0.9.1
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.
- package/dist/build/components/autocomplete/autocomplete-root.gen.d.ts +9 -0
- package/dist/build/components/autocomplete/autocomplete-root.gen.d.ts.map +1 -1
- package/dist/build/components/autocomplete/autocomplete-root.gen.svelte +3 -3
- package/dist/build/components/autocomplete/autocomplete-root.gen.svelte.d.ts +1 -0
- package/dist/build/components/autocomplete/autocomplete-root.gen.svelte.d.ts.map +1 -1
- package/dist/build/components/prosekit/index.d.ts +3 -2
- package/dist/build/components/prosekit/index.d.ts.map +1 -1
- package/dist/build/components/prosekit/prosekit.svelte +5 -4
- package/dist/build/components/prosekit/prosekit.svelte.d.ts +6 -27
- package/dist/build/components/prosekit/prosekit.svelte.d.ts.map +1 -1
- package/dist/build/contexts/editor-context.d.ts +1 -1
- package/dist/build/contexts/editor-context.d.ts.map +1 -1
- package/dist/build/contexts/editor-context.js +8 -6
- package/package.json +7 -7
- package/src/components/autocomplete/autocomplete-root.gen.svelte +3 -3
- package/src/components/autocomplete/autocomplete-root.gen.ts +9 -0
- package/src/components/prosekit/index.ts +3 -2
- package/src/components/prosekit/prosekit.svelte +5 -4
- package/src/contexts/editor-context.ts +8 -6
|
@@ -23,6 +23,15 @@ export interface AutocompleteRootProps {
|
|
|
23
23
|
* @default defaultItemFilter
|
|
24
24
|
*/
|
|
25
25
|
filter?: AutocompleteRootElementProps['filter'];
|
|
26
|
+
/**
|
|
27
|
+
* The reference to position the popup against. This can be a DOM element, a
|
|
28
|
+
* Floating UI virtual element, or a function that returns either of them.
|
|
29
|
+
* By default, the popup will be positioned against the text content that
|
|
30
|
+
* triggers the autocomplete.
|
|
31
|
+
*
|
|
32
|
+
* @default null
|
|
33
|
+
*/
|
|
34
|
+
anchor?: AutocompleteRootElementProps['anchor'];
|
|
26
35
|
/** Fired when the open state changes. */
|
|
27
36
|
onOpenChange?: (event: AutocompleteRootEvents['openChange']) => void;
|
|
28
37
|
/** Fired when the query changes. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"autocomplete-root.gen.d.ts","sourceRoot":"","sources":["../../../../src/components/autocomplete/autocomplete-root.gen.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,qBAAqB,IAAI,4BAA4B,EAAE,MAAM,4BAA4B,CAAC;AACzJ,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAItD,+DAA+D;AAC/D,MAAM,WAAW,qBAAqB;IACpC;;;;;OAKG;IACH,MAAM,CAAC,EAAE,4BAA4B,CAAC,QAAQ,CAAC,CAAC;IAChD;;;;OAIG;IACH,KAAK,CAAC,EAAE,4BAA4B,CAAC,OAAO,CAAC,CAAC;IAC9C;;;;;OAKG;IACH,MAAM,CAAC,EAAE,4BAA4B,CAAC,QAAQ,CAAC,CAAC;IAChD,yCAAyC;IACzC,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,sBAAsB,CAAC,YAAY,CAAC,KAAK,IAAI,CAAC;IACrE,oCAAoC;IACpC,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,sBAAsB,CAAC,aAAa,CAAC,KAAK,IAAI,CAAC;IACvE;;;OAGG;IACH,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,sBAAsB,CAAC,aAAa,CAAC,KAAK,IAAI,CAAC;IACvE;;;OAGG;IACH,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,sBAAsB,CAAC,cAAc,CAAC,KAAK,IAAI,CAAC;IACzE,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,sFAAsF;AACtF,eAAO,MAAM,gBAAgB,EAAE,SAAS,CAAC,qBAAqB,GAAG,cAAc,CAAC,uBAAuB,CAAC,CAA2G,CAAC"}
|
|
1
|
+
{"version":3,"file":"autocomplete-root.gen.d.ts","sourceRoot":"","sources":["../../../../src/components/autocomplete/autocomplete-root.gen.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,qBAAqB,IAAI,4BAA4B,EAAE,MAAM,4BAA4B,CAAC;AACzJ,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAItD,+DAA+D;AAC/D,MAAM,WAAW,qBAAqB;IACpC;;;;;OAKG;IACH,MAAM,CAAC,EAAE,4BAA4B,CAAC,QAAQ,CAAC,CAAC;IAChD;;;;OAIG;IACH,KAAK,CAAC,EAAE,4BAA4B,CAAC,OAAO,CAAC,CAAC;IAC9C;;;;;OAKG;IACH,MAAM,CAAC,EAAE,4BAA4B,CAAC,QAAQ,CAAC,CAAC;IAChD;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE,4BAA4B,CAAC,QAAQ,CAAC,CAAC;IAChD,yCAAyC;IACzC,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,sBAAsB,CAAC,YAAY,CAAC,KAAK,IAAI,CAAC;IACrE,oCAAoC;IACpC,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,sBAAsB,CAAC,aAAa,CAAC,KAAK,IAAI,CAAC;IACvE;;;OAGG;IACH,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,sBAAsB,CAAC,aAAa,CAAC,KAAK,IAAI,CAAC;IACvE;;;OAGG;IACH,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,sBAAsB,CAAC,cAAc,CAAC,KAAK,IAAI,CAAC;IACzE,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,sFAAsF;AACtF,eAAO,MAAM,gBAAgB,EAAE,SAAS,CAAC,qBAAqB,GAAG,cAAc,CAAC,uBAAuB,CAAC,CAA2G,CAAC"}
|
|
@@ -5,16 +5,16 @@
|
|
|
5
5
|
import { useEditorContext } from '../../contexts/editor-context.js'
|
|
6
6
|
registerAutocompleteRootElement()
|
|
7
7
|
|
|
8
|
-
let {
|
|
8
|
+
let { anchor: p0, editor: p1, filter: p2, regex: p3, onOpenChange: e0, onQueryChange: e1, onValueChange: e2, onValuesChange: e3, children = undefined, ...restProps } = $props()
|
|
9
9
|
let element: AutocompleteRootElement | undefined
|
|
10
10
|
const handlers: EventListener[] = []
|
|
11
11
|
|
|
12
|
-
const
|
|
12
|
+
const p1Fallback = useEditorContext()
|
|
13
13
|
|
|
14
14
|
$effect(() => {
|
|
15
15
|
if (!element) return
|
|
16
16
|
|
|
17
|
-
Object.assign(element, {
|
|
17
|
+
Object.assign(element, { anchor: p0, editor: p1 ?? p1Fallback, filter: p2, regex: p3 })
|
|
18
18
|
|
|
19
19
|
handlers.length = 0
|
|
20
20
|
handlers.push(e0)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"autocomplete-root.gen.svelte.d.ts","sourceRoot":"","sources":["../../../../src/components/autocomplete/autocomplete-root.gen.svelte.ts"],"names":[],"mappings":"AAgDA,QAAA,MAAM,gBAAgB;YAnCkE,GAAG;YAAU,GAAG;WAAS,GAAG;kBAAgB,GAAG;mBAAiB,GAAG;mBAAiB,GAAG;oBAAkB,GAAG;eAAa,GAAG;
|
|
1
|
+
{"version":3,"file":"autocomplete-root.gen.svelte.d.ts","sourceRoot":"","sources":["../../../../src/components/autocomplete/autocomplete-root.gen.svelte.ts"],"names":[],"mappings":"AAgDA,QAAA,MAAM,gBAAgB;YAnCkE,GAAG;YAAU,GAAG;YAAU,GAAG;WAAS,GAAG;kBAAgB,GAAG;mBAAiB,GAAG;mBAAiB,GAAG;oBAAkB,GAAG;eAAa,GAAG;gCAmCnK,CAAC;AAC/D,KAAK,gBAAgB,GAAG,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAC5D,eAAe,gBAAgB,CAAC"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import type { Editor } from '@prosekit/core';
|
|
2
|
-
import type {
|
|
2
|
+
import type { Component, Snippet } from 'svelte';
|
|
3
3
|
export interface ProseKitProps {
|
|
4
4
|
editor: Editor;
|
|
5
|
+
children?: Snippet;
|
|
5
6
|
}
|
|
6
7
|
/**
|
|
7
8
|
* The root component for a ProseKit editor.
|
|
8
9
|
*
|
|
9
10
|
* @public
|
|
10
11
|
*/
|
|
11
|
-
export declare const ProseKit:
|
|
12
|
+
export declare const ProseKit: Component<ProseKitProps>;
|
|
12
13
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/prosekit/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/prosekit/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAIhD,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AAED;;;;GAIG;AACH,eAAO,MAAM,QAAQ,EAAW,SAAS,CAAC,aAAa,CAAC,CAAA"}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { Editor } from '@prosekit/core'
|
|
3
|
+
import type { Snippet } from 'svelte'
|
|
3
4
|
import { setEditorContext } from '../../contexts/editor-context.js'
|
|
4
5
|
import { ViewRenderer } from '../view-renderer/index.js'
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
let props: { editor: Editor; children?: Snippet } = $props()
|
|
7
8
|
|
|
8
|
-
setEditorContext(editor)
|
|
9
|
+
setEditorContext(() => props.editor)
|
|
9
10
|
</script>
|
|
10
11
|
|
|
11
|
-
<ViewRenderer {editor}>
|
|
12
|
-
|
|
12
|
+
<ViewRenderer editor={props.editor}>
|
|
13
|
+
{@render props.children?.()}
|
|
13
14
|
</ViewRenderer>
|
|
@@ -1,31 +1,10 @@
|
|
|
1
1
|
import type { Editor } from '@prosekit/core';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
$$bindings?: Bindings;
|
|
5
|
-
} & Exports;
|
|
6
|
-
(internal: unknown, props: Props & {
|
|
7
|
-
$$events?: Events;
|
|
8
|
-
$$slots?: Slots;
|
|
9
|
-
}): Exports & {
|
|
10
|
-
$set?: any;
|
|
11
|
-
$on?: any;
|
|
12
|
-
};
|
|
13
|
-
z_$$bindings?: Bindings;
|
|
14
|
-
}
|
|
15
|
-
type $$__sveltets_2_PropsWithChildren<Props, Slots> = Props & (Slots extends {
|
|
16
|
-
default: any;
|
|
17
|
-
} ? Props extends Record<string, never> ? any : {
|
|
18
|
-
children?: any;
|
|
19
|
-
} : {});
|
|
20
|
-
declare const Prosekit: $$__sveltets_2_IsomorphicComponent<$$__sveltets_2_PropsWithChildren<{
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
type $$ComponentProps = {
|
|
21
4
|
editor: Editor;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
}, {
|
|
27
|
-
default: {};
|
|
28
|
-
}, {}, string>;
|
|
29
|
-
type Prosekit = InstanceType<typeof Prosekit>;
|
|
5
|
+
children?: Snippet;
|
|
6
|
+
};
|
|
7
|
+
declare const Prosekit: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
8
|
+
type Prosekit = ReturnType<typeof Prosekit>;
|
|
30
9
|
export default Prosekit;
|
|
31
10
|
//# sourceMappingURL=prosekit.svelte.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prosekit.svelte.d.ts","sourceRoot":"","sources":["../../../../src/components/prosekit/prosekit.svelte.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"prosekit.svelte.d.ts","sourceRoot":"","sources":["../../../../src/components/prosekit/prosekit.svelte.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAIpC,KAAK,gBAAgB,GAAI;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAkBjE,QAAA,MAAM,QAAQ,sDAAwC,CAAC;AACvD,KAAK,QAAQ,GAAG,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC;AAC5C,eAAe,QAAQ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editor-context.d.ts","sourceRoot":"","sources":["../../../src/contexts/editor-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,MAAM,EAAE,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAK3E;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,
|
|
1
|
+
{"version":3,"file":"editor-context.d.ts","sourceRoot":"","sources":["../../../src/contexts/editor-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,MAAM,EAAE,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAK3E;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,MAAM,GAAG,IAAI,CAE9D;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,SAAS,KAAK,MAAM,CAAC,CAAC,CAAC,GAAG,SAAS,CAS7E"}
|
|
@@ -4,17 +4,19 @@ const key = 'prosekit-svelte-editor-context';
|
|
|
4
4
|
/**
|
|
5
5
|
* @internal
|
|
6
6
|
*/
|
|
7
|
-
export function setEditorContext(
|
|
8
|
-
|
|
9
|
-
throw new ProseKitError('editor should not be empty');
|
|
10
|
-
}
|
|
11
|
-
setContext(key, editor);
|
|
7
|
+
export function setEditorContext(getEditor) {
|
|
8
|
+
setContext(key, getEditor);
|
|
12
9
|
}
|
|
13
10
|
/**
|
|
14
11
|
* @internal
|
|
15
12
|
*/
|
|
16
13
|
export function useEditorContext() {
|
|
17
14
|
if (hasContext(key)) {
|
|
18
|
-
|
|
15
|
+
const context = getContext(key);
|
|
16
|
+
const editor = context();
|
|
17
|
+
if (!editor) {
|
|
18
|
+
throw new ProseKitError('editor should not be empty');
|
|
19
|
+
}
|
|
20
|
+
return editor;
|
|
19
21
|
}
|
|
20
22
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prosekit/svelte",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.9.
|
|
4
|
+
"version": "0.9.1",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Svelte components and utilities for ProseKit",
|
|
7
7
|
"author": {
|
|
@@ -84,8 +84,8 @@
|
|
|
84
84
|
"@prosemirror-adapter/core": "^0.5.3",
|
|
85
85
|
"@prosemirror-adapter/svelte": "^0.5.3",
|
|
86
86
|
"@prosekit/core": "^0.12.0",
|
|
87
|
-
"@prosekit/
|
|
88
|
-
"@prosekit/
|
|
87
|
+
"@prosekit/pm": "^0.1.16",
|
|
88
|
+
"@prosekit/web": "^0.8.1"
|
|
89
89
|
},
|
|
90
90
|
"peerDependencies": {
|
|
91
91
|
"svelte": ">= 5.0.0"
|
|
@@ -97,12 +97,12 @@
|
|
|
97
97
|
},
|
|
98
98
|
"devDependencies": {
|
|
99
99
|
"@sveltejs/package": "^2.5.7",
|
|
100
|
-
"@sveltejs/vite-plugin-svelte": "^7.
|
|
101
|
-
"@types/node": "^24.
|
|
100
|
+
"@sveltejs/vite-plugin-svelte": "^7.1.2",
|
|
101
|
+
"@types/node": "^24.12.2",
|
|
102
102
|
"svelte": "^5.55.5",
|
|
103
|
-
"svelte-check": "^4.4.
|
|
103
|
+
"svelte-check": "^4.4.8",
|
|
104
104
|
"tsx": "^4.21.0",
|
|
105
|
-
"typescript": "~
|
|
105
|
+
"typescript": "~6.0.3",
|
|
106
106
|
"vitest": "^4.1.5",
|
|
107
107
|
"vitest-browser-svelte": "^2.1.1",
|
|
108
108
|
"@prosekit/config-ts": "0.0.0",
|
|
@@ -5,16 +5,16 @@
|
|
|
5
5
|
import { useEditorContext } from '../../contexts/editor-context.ts'
|
|
6
6
|
registerAutocompleteRootElement()
|
|
7
7
|
|
|
8
|
-
let {
|
|
8
|
+
let { anchor: p0, editor: p1, filter: p2, regex: p3, onOpenChange: e0, onQueryChange: e1, onValueChange: e2, onValuesChange: e3, children = undefined, ...restProps } = $props()
|
|
9
9
|
let element: AutocompleteRootElement | undefined
|
|
10
10
|
const handlers: EventListener[] = []
|
|
11
11
|
|
|
12
|
-
const
|
|
12
|
+
const p1Fallback = useEditorContext()
|
|
13
13
|
|
|
14
14
|
$effect(() => {
|
|
15
15
|
if (!element) return
|
|
16
16
|
|
|
17
|
-
Object.assign(element, {
|
|
17
|
+
Object.assign(element, { anchor: p0, editor: p1 ?? p1Fallback, filter: p2, regex: p3 })
|
|
18
18
|
|
|
19
19
|
handlers.length = 0
|
|
20
20
|
handlers.push(e0)
|
|
@@ -28,6 +28,15 @@ export interface AutocompleteRootProps {
|
|
|
28
28
|
* @default defaultItemFilter
|
|
29
29
|
*/
|
|
30
30
|
filter?: AutocompleteRootElementProps['filter'];
|
|
31
|
+
/**
|
|
32
|
+
* The reference to position the popup against. This can be a DOM element, a
|
|
33
|
+
* Floating UI virtual element, or a function that returns either of them.
|
|
34
|
+
* By default, the popup will be positioned against the text content that
|
|
35
|
+
* triggers the autocomplete.
|
|
36
|
+
*
|
|
37
|
+
* @default null
|
|
38
|
+
*/
|
|
39
|
+
anchor?: AutocompleteRootElementProps['anchor'];
|
|
31
40
|
/** Fired when the open state changes. */
|
|
32
41
|
onOpenChange?: (event: AutocompleteRootEvents['openChange']) => void;
|
|
33
42
|
/** Fired when the query changes. */
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { Editor } from '@prosekit/core'
|
|
2
|
-
import type {
|
|
2
|
+
import type { Component, Snippet } from 'svelte'
|
|
3
3
|
|
|
4
4
|
import Comp from './prosekit.svelte'
|
|
5
5
|
|
|
6
6
|
export interface ProseKitProps {
|
|
7
7
|
editor: Editor
|
|
8
|
+
children?: Snippet
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
/**
|
|
@@ -12,4 +13,4 @@ export interface ProseKitProps {
|
|
|
12
13
|
*
|
|
13
14
|
* @public
|
|
14
15
|
*/
|
|
15
|
-
export const ProseKit = Comp as
|
|
16
|
+
export const ProseKit = Comp as Component<ProseKitProps>
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { Editor } from '@prosekit/core'
|
|
3
|
+
import type { Snippet } from 'svelte'
|
|
3
4
|
import { setEditorContext } from '../../contexts/editor-context.ts'
|
|
4
5
|
import { ViewRenderer } from '../view-renderer/index.ts'
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
let props: { editor: Editor; children?: Snippet } = $props()
|
|
7
8
|
|
|
8
|
-
setEditorContext(editor)
|
|
9
|
+
setEditorContext(() => props.editor)
|
|
9
10
|
</script>
|
|
10
11
|
|
|
11
|
-
<ViewRenderer {editor}>
|
|
12
|
-
|
|
12
|
+
<ViewRenderer editor={props.editor}>
|
|
13
|
+
{@render props.children?.()}
|
|
13
14
|
</ViewRenderer>
|
|
@@ -6,11 +6,8 @@ const key = 'prosekit-svelte-editor-context'
|
|
|
6
6
|
/**
|
|
7
7
|
* @internal
|
|
8
8
|
*/
|
|
9
|
-
export function setEditorContext(
|
|
10
|
-
|
|
11
|
-
throw new ProseKitError('editor should not be empty')
|
|
12
|
-
}
|
|
13
|
-
setContext(key, editor)
|
|
9
|
+
export function setEditorContext(getEditor: () => Editor): void {
|
|
10
|
+
setContext(key, getEditor)
|
|
14
11
|
}
|
|
15
12
|
|
|
16
13
|
/**
|
|
@@ -18,6 +15,11 @@ export function setEditorContext(editor: Editor): void {
|
|
|
18
15
|
*/
|
|
19
16
|
export function useEditorContext<E extends Extension>(): Editor<E> | undefined {
|
|
20
17
|
if (hasContext(key)) {
|
|
21
|
-
|
|
18
|
+
const context: () => Editor = getContext(key)
|
|
19
|
+
const editor = context()
|
|
20
|
+
if (!editor) {
|
|
21
|
+
throw new ProseKitError('editor should not be empty')
|
|
22
|
+
}
|
|
23
|
+
return editor
|
|
22
24
|
}
|
|
23
25
|
}
|