@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.
@@ -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> | null;
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,CAKxE"}
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"}
@@ -14,8 +14,7 @@ export function setEditorContext(editor) {
14
14
  * @internal
15
15
  */
16
16
  export function useEditorContext() {
17
- if (!hasContext(key)) {
18
- return null;
17
+ if (hasContext(key)) {
18
+ return getContext(key);
19
19
  }
20
- return getContext(key);
21
20
  }
@@ -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,QAyB3C"}
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 { onDestroy } from 'svelte';
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
- let cleanup;
11
- const unsubscribe = extensionStore.subscribe((extension) => {
12
- cleanup === null || cleanup === void 0 ? void 0 : cleanup();
13
- cleanup = undefined;
14
- const editor = maybeEditor || editorContext;
15
- if (!editor) {
16
- throw new EditorNotFoundError();
17
- }
18
- if (extension) {
19
- cleanup = editor.use(extension);
20
- }
21
- });
22
- onDestroy(() => {
23
- cleanup === null || cleanup === void 0 ? void 0 : cleanup();
24
- cleanup = undefined;
25
- unsubscribe();
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,EAIL,KAAK,MAAM,EACX,KAAK,SAAS,EAEf,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,CA2BtB"}
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, ProseKitError, } from '@prosekit/core';
2
- import { onDestroy, onMount } from 'svelte';
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
- const dispose = editor.use(extension);
28
- onDestroy(dispose);
27
+ return editor.use(extension);
29
28
  });
30
29
  }
31
30
  return readonly(editorStore);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prosekit/svelte",
3
3
  "type": "module",
4
- "version": "0.3.8",
4
+ "version": "0.3.9",
5
5
  "private": false,
6
6
  "author": {
7
7
  "name": "ocavue",