@prosekit/svelte 0.2.0 → 0.2.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.
@@ -3,5 +3,10 @@ import type { SvelteComponent } from 'svelte';
3
3
  export interface ProseKitProps {
4
4
  editor: Editor;
5
5
  }
6
+ /**
7
+ * The root component for a ProseKit editor.
8
+ *
9
+ * @public
10
+ */
6
11
  export declare const ProseKit: typeof SvelteComponent<ProseKitProps>;
7
12
  //# sourceMappingURL=prosekit.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"prosekit.d.ts","sourceRoot":"","sources":["../../../../src/components/prosekit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAA;AAI7C,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAA;CACf;AAED,eAAO,MAAM,QAAQ,EACiC,uBAAuB,aAAa,CAAC,CAAA"}
1
+ {"version":3,"file":"prosekit.d.ts","sourceRoot":"","sources":["../../../../src/components/prosekit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAA;AAI7C,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAA;CACf;AAED;;;;GAIG;AACH,eAAO,MAAM,QAAQ,EACiC,uBAAuB,aAAa,CAAC,CAAA"}
@@ -1,2 +1,7 @@
1
1
  import ProseKitComponent from './prosekit.svelte';
2
+ /**
3
+ * The root component for a ProseKit editor.
4
+ *
5
+ * @public
6
+ */
2
7
  export const ProseKit = ProseKitComponent;
@@ -1,7 +1,10 @@
1
- import { type Editor } from '@prosekit/core';
2
- export interface EditorContext {
3
- editor: Editor;
4
- }
1
+ import { type Editor, type Extension } from '@prosekit/core';
2
+ /**
3
+ * @internal
4
+ */
5
5
  export declare function setEditorContext(editor: Editor): void;
6
- export declare function getEditorContext(): EditorContext;
6
+ /**
7
+ * @internal
8
+ */
9
+ export declare function useEditorContext<E extends Extension>(): Editor<E> | null;
7
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,MAAM,gBAAgB,CAAA;AAG3D,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAA;CACf;AAID,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAMrD;AAED,wBAAgB,gBAAgB,IAAI,aAAa,CAOhD"}
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,16 +1,21 @@
1
1
  import { ProseKitError } from '@prosekit/core';
2
2
  import { getContext, hasContext, setContext } from 'svelte';
3
3
  const key = 'prosekit-svelte-editor-context';
4
+ /**
5
+ * @internal
6
+ */
4
7
  export function setEditorContext(editor) {
5
8
  if (!editor) {
6
9
  throw new ProseKitError('editor should not be empty');
7
10
  }
8
- const context = { editor };
9
- setContext(key, context);
11
+ setContext(key, editor);
10
12
  }
11
- export function getEditorContext() {
13
+ /**
14
+ * @internal
15
+ */
16
+ export function useEditorContext() {
12
17
  if (!hasContext(key)) {
13
- throw new ProseKitError('Editor context not found. You must call this function inside the ProseKit component');
18
+ return null;
14
19
  }
15
20
  return getContext(key);
16
21
  }
@@ -0,0 +1,8 @@
1
+ /// <reference types="svelte" />
2
+ import { Editor, type Extension } from '@prosekit/core';
3
+ import { type Readable } from 'svelte/store';
4
+ /**
5
+ * @internal
6
+ */
7
+ export declare function useEditorExtension(maybeEditor: Editor | null | undefined, extensionStore: Readable<Extension | null>): void;
8
+ //# sourceMappingURL=use-editor-extension.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,27 @@
1
+ import { Editor, EditorNotFoundError } from '@prosekit/core';
2
+ import { onDestroy } from 'svelte';
3
+ import {} from 'svelte/store';
4
+ import { useEditorContext } from '../contexts/editor-context';
5
+ /**
6
+ * @internal
7
+ */
8
+ export function useEditorExtension(maybeEditor, extensionStore) {
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();
26
+ });
27
+ }
@@ -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,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,CAqBtB"}
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,7 +1,7 @@
1
- import { defineMountHandler, defineUpdateHandler, union, } from '@prosekit/core';
1
+ import { defineMountHandler, defineUpdateHandler, union, ProseKitError, } from '@prosekit/core';
2
2
  import { onDestroy, onMount } from 'svelte';
3
3
  import { readonly, writable } from 'svelte/store';
4
- import { getEditorContext } from '../contexts/editor-context';
4
+ import { useEditorContext } from '../contexts/editor-context';
5
5
  /**
6
6
  * Retrieves the editor instance from the nearest ProseKit component.
7
7
  *
@@ -10,7 +10,10 @@ import { getEditorContext } from '../contexts/editor-context';
10
10
  export function useEditor(options) {
11
11
  var _a;
12
12
  const update = (_a = options === null || options === void 0 ? void 0 : options.update) !== null && _a !== void 0 ? _a : false;
13
- const editor = getEditorContext().editor;
13
+ const editor = useEditorContext();
14
+ if (!editor) {
15
+ throw new ProseKitError('useEditor must be used within the ProseKit component');
16
+ }
14
17
  const editorStore = writable(editor);
15
18
  if (update) {
16
19
  onMount(() => {
@@ -1,12 +1,24 @@
1
1
  /// <reference types="svelte" />
2
- import { type Extension } from '@prosekit/core';
2
+ import { Editor, Priority, type Extension } from '@prosekit/core';
3
3
  import { type Readable } from 'svelte/store';
4
+ export interface UseExtensionOptions {
5
+ /**
6
+ * The editor to add the extension to. If not provided, it will use the
7
+ * editor from the nearest `ProseKit` component.
8
+ */
9
+ editor?: Editor;
10
+ /**
11
+ * Optional priority to add the extension with.
12
+ */
13
+ priority?: Priority;
14
+ }
4
15
  /**
5
16
  * Add an extension to the editor.
6
- *
7
- * It accepts a store to an optional extension. If the extension is changed, the
8
- * previous extension will be removed and the new one (if not null) will be
9
- * added.
10
17
  */
11
- export declare function useExtension<T extends Extension = Extension>(extensionStore: Readable<T | null>): void;
18
+ export declare function useExtension<T extends Extension = Extension>(
19
+ /**
20
+ * The store to an extension to add to the editor. If it changes, the previous
21
+ * extension will be removed and the new one (if not null) will be added.
22
+ */
23
+ extension: Readable<T | null>, options?: UseExtensionOptions): void;
12
24
  //# sourceMappingURL=use-extension.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-extension.d.ts","sourceRoot":"","sources":["../../../../src/hooks/use-extension.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,EAAW,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAA;AAIrD;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS,EAC1D,cAAc,EAAE,QAAQ,CAAC,CAAC,GAAG,IAAI,CAAC,GACjC,IAAI,CAWN"}
1
+ {"version":3,"file":"use-extension.d.ts","sourceRoot":"","sources":["../../../../src/hooks/use-extension.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAA;AACjE,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAA;AAK5C,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IAEf;;OAEG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAA;CACpB;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS;AAC1D;;;GAGG;AACH,SAAS,EAAE,QAAQ,CAAC,CAAC,GAAG,IAAI,CAAC,EAC7B,OAAO,CAAC,EAAE,mBAAmB,GAC5B,IAAI,CAKN"}
@@ -1,22 +1,15 @@
1
- import {} from '@prosekit/core';
2
- import { derived } from 'svelte/store';
3
- import { useEditor } from './use-editor';
1
+ import { Editor, Priority } from '@prosekit/core';
2
+ import {} from 'svelte/store';
3
+ import { useEditorExtension } from './use-editor-extension';
4
+ import { usePriorityExtension } from './use-priority-extension';
4
5
  /**
5
6
  * Add an extension to the editor.
6
- *
7
- * It accepts a store to an optional extension. If the extension is changed, the
8
- * previous extension will be removed and the new one (if not null) will be
9
- * added.
10
7
  */
11
- export function useExtension(extensionStore) {
12
- const editorStore = useEditor();
13
- const store = derived([editorStore, extensionStore], (values) => values);
14
- let cleanup = null;
15
- store.subscribe(([editor, extension]) => {
16
- cleanup === null || cleanup === void 0 ? void 0 : cleanup();
17
- cleanup = null;
18
- if (extension) {
19
- cleanup = editor.use(extension);
20
- }
21
- });
8
+ export function useExtension(
9
+ /**
10
+ * The store to an extension to add to the editor. If it changes, the previous
11
+ * extension will be removed and the new one (if not null) will be added.
12
+ */
13
+ extension, options) {
14
+ useEditorExtension(options === null || options === void 0 ? void 0 : options.editor, usePriorityExtension(extension, options === null || options === void 0 ? void 0 : options.priority));
22
15
  }
@@ -1,7 +1,6 @@
1
1
  /// <reference types="svelte" />
2
- import { Priority, type Keymap } from '@prosekit/core';
2
+ import { type Keymap } from '@prosekit/core';
3
3
  import { type Readable } from 'svelte/store';
4
- export declare function useKeymap(keymapStore: Readable<Keymap>, options?: {
5
- priority?: Priority;
6
- }): void;
4
+ import { type UseExtensionOptions } from './use-extension';
5
+ export declare function useKeymap(keymapStore: Readable<Keymap>, options?: UseExtensionOptions): void;
7
6
  //# sourceMappingURL=use-keymap.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-keymap.d.ts","sourceRoot":"","sources":["../../../../src/hooks/use-keymap.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAgB,KAAK,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACpE,OAAO,EAAW,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAA;AAIrD,wBAAgB,SAAS,CACvB,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,EAC7B,OAAO,CAAC,EAAE;IAAE,QAAQ,CAAC,EAAE,QAAQ,CAAA;CAAE,GAChC,IAAI,CAGN"}
1
+ {"version":3,"file":"use-keymap.d.ts","sourceRoot":"","sources":["../../../../src/hooks/use-keymap.ts"],"names":[],"mappings":";AAAA,OAAO,EAAgB,KAAK,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAC1D,OAAO,EAAW,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAA;AAErD,OAAO,EAAgB,KAAK,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAExE,wBAAgB,SAAS,CACvB,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,EAC7B,OAAO,CAAC,EAAE,mBAAmB,GAC5B,IAAI,CAGN"}
@@ -1,7 +1,7 @@
1
- import { Priority, defineKeymap } from '@prosekit/core';
1
+ import { defineKeymap } from '@prosekit/core';
2
2
  import { derived } from 'svelte/store';
3
- import { usePriorityExtension } from './use-priority-extension';
3
+ import { useExtension } from './use-extension';
4
4
  export function useKeymap(keymapStore, options) {
5
5
  const extension = derived(keymapStore, (keymap) => defineKeymap(keymap));
6
- usePriorityExtension(extension, options === null || options === void 0 ? void 0 : options.priority);
6
+ return useExtension(extension, options);
7
7
  }
@@ -1,5 +1,8 @@
1
1
  /// <reference types="svelte" />
2
2
  import { Priority, type Extension } from '@prosekit/core';
3
3
  import { type Readable } from 'svelte/store';
4
- export declare function usePriorityExtension<T extends Extension = Extension>(extensionStore: Readable<T | null>, priority?: Priority | null): void;
4
+ /**
5
+ * @internal
6
+ */
7
+ export declare function usePriorityExtension<T extends Extension = Extension>(extensionStore: Readable<T | null>, priority?: Priority | null): Readable<T | null>;
5
8
  //# sourceMappingURL=use-priority-extension.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-priority-extension.d.ts","sourceRoot":"","sources":["../../../../src/hooks/use-priority-extension.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAgB,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAA;AACvE,OAAO,EAAW,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAA;AAIrD,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS,EAClE,cAAc,EAAE,QAAQ,CAAC,CAAC,GAAG,IAAI,CAAC,EAClC,QAAQ,CAAC,EAAE,QAAQ,GAAG,IAAI,GACzB,IAAI,CAKN"}
1
+ {"version":3,"file":"use-priority-extension.d.ts","sourceRoot":"","sources":["../../../../src/hooks/use-priority-extension.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAgB,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAA;AACvE,OAAO,EAAW,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAA;AAErD;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS,EAClE,cAAc,EAAE,QAAQ,CAAC,CAAC,GAAG,IAAI,CAAC,EAClC,QAAQ,CAAC,EAAE,QAAQ,GAAG,IAAI,GACzB,QAAQ,CAAC,CAAC,GAAG,IAAI,CAAC,CAIpB"}
@@ -1,9 +1,10 @@
1
1
  import { Priority, withPriority } from '@prosekit/core';
2
2
  import { derived } from 'svelte/store';
3
- import { useExtension } from './use-extension';
3
+ /**
4
+ * @internal
5
+ */
4
6
  export function usePriorityExtension(extensionStore, priority) {
5
- const extensionWithPriorityStore = derived(extensionStore, (extension) => {
7
+ return derived(extensionStore, (extension) => {
6
8
  return extension && priority ? withPriority(extension, priority) : extension;
7
9
  });
8
- return useExtension(extensionWithPriorityStore);
9
10
  }
@@ -1,6 +1,6 @@
1
1
  export { ProseKit } from './components/prosekit';
2
2
  export { useEditor } from './hooks/use-editor';
3
- export { useExtension } from './hooks/use-extension';
3
+ export { useExtension, type UseExtensionOptions } from './hooks/use-extension';
4
4
  export { useKeymap } from './hooks/use-keymap';
5
5
  export type { PropsWithClass } from './types';
6
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,YAAY,EAAE,KAAK,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAC9E,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prosekit/svelte",
3
3
  "type": "module",
4
- "version": "0.2.0",
4
+ "version": "0.2.1",
5
5
  "private": false,
6
6
  "author": {
7
7
  "name": "ocavue",
@@ -107,8 +107,8 @@
107
107
  "dist"
108
108
  ],
109
109
  "dependencies": {
110
- "@prosekit/core": "^0.2.5",
111
- "@prosekit/lit": "^0.2.0"
110
+ "@prosekit/core": "^0.2.7",
111
+ "@prosekit/lit": "^0.2.1"
112
112
  },
113
113
  "peerDependencies": {
114
114
  "svelte": ">= 3.0.0"
@@ -120,14 +120,14 @@
120
120
  },
121
121
  "devDependencies": {
122
122
  "@prosekit/dev": "*",
123
- "@sveltejs/package": "^2.2.5",
124
- "@types/node": "^20.11.0",
123
+ "@sveltejs/package": "^2.2.6",
124
+ "@types/node": "^20.11.7",
125
125
  "read-pkg": "^9.0.1",
126
- "svelte": "^4.2.8",
126
+ "svelte": "^4.2.9",
127
127
  "svelte-check": "^3.6.3",
128
128
  "tsx": "^4.7.0",
129
129
  "typescript": "^5.3.3",
130
- "vitest": "^1.2.0"
130
+ "vitest": "^1.2.1"
131
131
  },
132
132
  "scripts": {
133
133
  "build": "svelte-package -i src -o dist/build && tsx scripts/re-export.ts"
package/src/index.ts DELETED
@@ -1,5 +0,0 @@
1
- export { ProseKit } 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 { PropsWithClass } from './types'