@prosekit/svelte 0.3.8 → 0.3.9
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/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 +2 -3
- package/dist/build/hooks/use-editor-extension.d.ts.map +1 -1
- package/dist/build/hooks/use-editor-extension.js +21 -17
- package/dist/build/hooks/use-editor.d.ts.map +1 -1
- package/dist/build/hooks/use-editor.js +3 -4
- package/package.json +1 -1
@@ -6,5 +6,5 @@ export declare function setEditorContext(editor: Editor): void;
|
|
6
6
|
/**
|
7
7
|
* @internal
|
8
8
|
*/
|
9
|
-
export declare function useEditorContext<E extends Extension>(): Editor<E> |
|
9
|
+
export declare function useEditorContext<E extends Extension>(): Editor<E> | void;
|
10
10
|
//# sourceMappingURL=editor-context.d.ts.map
|
@@ -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,MAAM,EAAE,MAAM,GAAG,IAAI,CAKrD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,SAAS,KAAK,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI,
|
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,MAAM,EAAE,MAAM,GAAG,IAAI,CAKrD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,SAAS,KAAK,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI,CAIxE"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-editor-extension.d.ts","sourceRoot":"","sources":["../../../../src/hooks/use-editor-extension.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAuB,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE5E,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAA;AAI5C;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,WAAW,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACtC,cAAc,EAAE,QAAQ,CAAC,SAAS,GAAG,IAAI,CAAC,
|
1
|
+
{"version":3,"file":"use-editor-extension.d.ts","sourceRoot":"","sources":["../../../../src/hooks/use-editor-extension.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAuB,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE5E,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAA;AAI5C;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,WAAW,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACtC,cAAc,EAAE,QAAQ,CAAC,SAAS,GAAG,IAAI,CAAC,QA6B3C"}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { Editor, EditorNotFoundError } from '@prosekit/core';
|
2
|
-
import {
|
2
|
+
import { onMount } from 'svelte';
|
3
3
|
import {} from 'svelte/store';
|
4
4
|
import { useEditorContext } from '../contexts/editor-context';
|
5
5
|
/**
|
@@ -7,21 +7,25 @@ import { useEditorContext } from '../contexts/editor-context';
|
|
7
7
|
*/
|
8
8
|
export function useEditorExtension(maybeEditor, extensionStore) {
|
9
9
|
const editorContext = useEditorContext();
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
10
|
+
onMount(() => {
|
11
|
+
let cleanup;
|
12
|
+
let unsubscribe;
|
13
|
+
unsubscribe = extensionStore.subscribe((extension) => {
|
14
|
+
cleanup === null || cleanup === void 0 ? void 0 : cleanup();
|
15
|
+
cleanup = undefined;
|
16
|
+
const editor = maybeEditor || editorContext;
|
17
|
+
if (!editor) {
|
18
|
+
throw new EditorNotFoundError();
|
19
|
+
}
|
20
|
+
if (extension) {
|
21
|
+
cleanup = editor.use(extension);
|
22
|
+
}
|
23
|
+
});
|
24
|
+
return () => {
|
25
|
+
cleanup === null || cleanup === void 0 ? void 0 : cleanup();
|
26
|
+
cleanup = undefined;
|
27
|
+
unsubscribe === null || unsubscribe === void 0 ? void 0 : unsubscribe();
|
28
|
+
unsubscribe = undefined;
|
29
|
+
};
|
26
30
|
});
|
27
31
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-editor.d.ts","sourceRoot":"","sources":["../../../../src/hooks/use-editor.ts"],"names":[],"mappings":"AAAA,OAAO,
|
1
|
+
{"version":3,"file":"use-editor.d.ts","sourceRoot":"","sources":["../../../../src/hooks/use-editor.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,MAAM,EACX,KAAK,SAAS,EACf,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAsB,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAA;AAIhE;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,SAAS,GAAG,GAAG,EAAE,OAAO,CAAC,EAAE;IAC7D;;;;;OAKG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CA0BtB"}
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { defineMountHandler, defineUpdateHandler, union,
|
2
|
-
import {
|
1
|
+
import { ProseKitError, defineMountHandler, defineUpdateHandler, union, } from '@prosekit/core';
|
2
|
+
import { onMount } from 'svelte';
|
3
3
|
import { readonly, writable } from 'svelte/store';
|
4
4
|
import { useEditorContext } from '../contexts/editor-context';
|
5
5
|
/**
|
@@ -24,8 +24,7 @@ export function useEditor(options) {
|
|
24
24
|
defineMountHandler(forceUpdate),
|
25
25
|
defineUpdateHandler(forceUpdate),
|
26
26
|
]);
|
27
|
-
|
28
|
-
onDestroy(dispose);
|
27
|
+
return editor.use(extension);
|
29
28
|
});
|
30
29
|
}
|
31
30
|
return readonly(editorStore);
|