@prosekit/svelte 0.7.1 → 0.8.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/client-update/index.d.ts +1 -2
- package/dist/build/components/client-update/index.d.ts.map +1 -1
- package/dist/build/components/client-update/index.js +1 -2
- package/dist/build/hooks/use-editor-derived-value.d.ts +30 -0
- package/dist/build/hooks/use-editor-derived-value.d.ts.map +1 -0
- package/dist/build/hooks/use-editor-derived-value.js +28 -0
- package/dist/build/hooks/use-extension.d.ts +1 -1
- package/dist/build/index.d.ts +1 -0
- package/dist/build/index.d.ts.map +1 -1
- package/dist/build/index.js +1 -0
- package/package.json +11 -11
- package/src/components/client-update/index.ts +1 -3
- package/src/hooks/use-editor-derived-value.ts +49 -0
- package/src/hooks/use-extension.ts +1 -1
- package/src/index.ts +4 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/client-update/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/client-update/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,wBAAwB,CAAA"}
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { ClientUpdate };
|
|
1
|
+
export { default as ClientUpdate } from './client-update.svelte';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Editor, Extension } from '@prosekit/core';
|
|
2
|
+
import { type Readable } from 'svelte/store';
|
|
3
|
+
export interface UseEditorDerivedOptions<E extends Extension = any> {
|
|
4
|
+
/**
|
|
5
|
+
* The editor to add the extension to. If not provided, it will use the
|
|
6
|
+
* editor from the nearest `<ProseKit>` component.
|
|
7
|
+
*/
|
|
8
|
+
editor?: Editor<E>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Runs a function to derive a value from the editor instance after editor state
|
|
12
|
+
* changes.
|
|
13
|
+
*
|
|
14
|
+
* This is useful when you need to render something based on the editor state,
|
|
15
|
+
* for example, whether the selected text is wrapped in an italic mark.
|
|
16
|
+
*
|
|
17
|
+
* It returns a Svelte store that stores the derived value and updates whenever
|
|
18
|
+
* the editor state changes.
|
|
19
|
+
*
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
export declare function useEditorDerivedValue<E extends Extension, Derived>(
|
|
23
|
+
/**
|
|
24
|
+
* A function that receives the editor instance and returns a derived value.
|
|
25
|
+
*
|
|
26
|
+
* It will be called whenever the editor's document state changes, or when it
|
|
27
|
+
* mounts.
|
|
28
|
+
*/
|
|
29
|
+
derive: (editor: Editor<E>) => Derived, options?: UseEditorDerivedOptions<E>): Readable<Derived>;
|
|
30
|
+
//# sourceMappingURL=use-editor-derived-value.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-editor-derived-value.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-editor-derived-value.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,MAAM,EACN,SAAS,EACV,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAGL,KAAK,QAAQ,EACd,MAAM,cAAc,CAAA;AAIrB,MAAM,WAAW,uBAAuB,CAAC,CAAC,SAAS,SAAS,GAAG,GAAG;IAChE;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAA;CACnB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,SAAS,EAAE,OAAO;AAChE;;;;;GAKG;AACH,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,KAAK,OAAO,EACtC,OAAO,CAAC,EAAE,uBAAuB,CAAC,CAAC,CAAC,GACnC,QAAQ,CAAC,OAAO,CAAC,CAOnB"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { derived, readable, } from 'svelte/store';
|
|
2
|
+
import { useEditor } from './use-editor';
|
|
3
|
+
/**
|
|
4
|
+
* Runs a function to derive a value from the editor instance after editor state
|
|
5
|
+
* changes.
|
|
6
|
+
*
|
|
7
|
+
* This is useful when you need to render something based on the editor state,
|
|
8
|
+
* for example, whether the selected text is wrapped in an italic mark.
|
|
9
|
+
*
|
|
10
|
+
* It returns a Svelte store that stores the derived value and updates whenever
|
|
11
|
+
* the editor state changes.
|
|
12
|
+
*
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
export function useEditorDerivedValue(
|
|
16
|
+
/**
|
|
17
|
+
* A function that receives the editor instance and returns a derived value.
|
|
18
|
+
*
|
|
19
|
+
* It will be called whenever the editor's document state changes, or when it
|
|
20
|
+
* mounts.
|
|
21
|
+
*/
|
|
22
|
+
derive, options) {
|
|
23
|
+
const initialEditor = options?.editor;
|
|
24
|
+
const editorStore = initialEditor
|
|
25
|
+
? readable(initialEditor)
|
|
26
|
+
: useEditor({ update: true });
|
|
27
|
+
return derived(editorStore, derive);
|
|
28
|
+
}
|
|
@@ -3,7 +3,7 @@ import type { Readable } from 'svelte/store';
|
|
|
3
3
|
export interface UseExtensionOptions {
|
|
4
4
|
/**
|
|
5
5
|
* The editor to add the extension to. If not provided, it will use the
|
|
6
|
-
* editor from the nearest
|
|
6
|
+
* editor from the nearest `<ProseKit>` component.
|
|
7
7
|
*/
|
|
8
8
|
editor?: Editor;
|
|
9
9
|
/**
|
package/dist/build/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export { defineSvelteMarkView, type SvelteMarkViewComponent, type SvelteMarkView
|
|
|
3
3
|
export { defineSvelteNodeView, type SvelteNodeViewComponent, type SvelteNodeViewOptions, type SvelteNodeViewProps, } from './extensions/svelte-node-view';
|
|
4
4
|
export { useDocChange } from './hooks/use-doc-change';
|
|
5
5
|
export { useEditor } from './hooks/use-editor';
|
|
6
|
+
export { useEditorDerivedValue, type UseEditorDerivedOptions, } from './hooks/use-editor-derived-value';
|
|
6
7
|
export { useExtension, type UseExtensionOptions, } from './hooks/use-extension';
|
|
7
8
|
export { useKeymap } from './hooks/use-keymap';
|
|
8
9
|
export { useStateUpdate } from './hooks/use-state-update';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,KAAK,aAAa,GACnB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EACL,oBAAoB,EACpB,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,GACzB,MAAM,+BAA+B,CAAA;AACtC,OAAO,EACL,oBAAoB,EACpB,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,GACzB,MAAM,+BAA+B,CAAA;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EACL,YAAY,EACZ,KAAK,mBAAmB,GACzB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AACzD,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,KAAK,aAAa,GACnB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EACL,oBAAoB,EACpB,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,GACzB,MAAM,+BAA+B,CAAA;AACtC,OAAO,EACL,oBAAoB,EACpB,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,GACzB,MAAM,+BAA+B,CAAA;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EACL,qBAAqB,EACrB,KAAK,uBAAuB,GAC7B,MAAM,kCAAkC,CAAA;AACzC,OAAO,EACL,YAAY,EACZ,KAAK,mBAAmB,GACzB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AACzD,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA"}
|
package/dist/build/index.js
CHANGED
|
@@ -3,6 +3,7 @@ export { defineSvelteMarkView, } from './extensions/svelte-mark-view';
|
|
|
3
3
|
export { defineSvelteNodeView, } from './extensions/svelte-node-view';
|
|
4
4
|
export { useDocChange } from './hooks/use-doc-change';
|
|
5
5
|
export { useEditor } from './hooks/use-editor';
|
|
6
|
+
export { useEditorDerivedValue, } from './hooks/use-editor-derived-value';
|
|
6
7
|
export { useExtension, } from './hooks/use-extension';
|
|
7
8
|
export { useKeymap } from './hooks/use-keymap';
|
|
8
9
|
export { useStateUpdate } from './hooks/use-state-update';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prosekit/svelte",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.8.1",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Svelte components and utilities for ProseKit",
|
|
7
7
|
"author": {
|
|
@@ -76,11 +76,11 @@
|
|
|
76
76
|
"src"
|
|
77
77
|
],
|
|
78
78
|
"dependencies": {
|
|
79
|
-
"@prosemirror-adapter/core": "^0.4.
|
|
80
|
-
"@prosemirror-adapter/svelte": "^0.4.
|
|
81
|
-
"@prosekit/core": "^0.8.
|
|
82
|
-
"@prosekit/
|
|
83
|
-
"@prosekit/
|
|
79
|
+
"@prosemirror-adapter/core": "^0.4.6",
|
|
80
|
+
"@prosemirror-adapter/svelte": "^0.4.6",
|
|
81
|
+
"@prosekit/core": "^0.8.6",
|
|
82
|
+
"@prosekit/pm": "^0.1.14",
|
|
83
|
+
"@prosekit/web": "^0.7.6"
|
|
84
84
|
},
|
|
85
85
|
"peerDependencies": {
|
|
86
86
|
"svelte": ">= 5.0.0"
|
|
@@ -91,13 +91,13 @@
|
|
|
91
91
|
}
|
|
92
92
|
},
|
|
93
93
|
"devDependencies": {
|
|
94
|
-
"@sveltejs/package": "^2.5.
|
|
94
|
+
"@sveltejs/package": "^2.5.4",
|
|
95
95
|
"@types/node": "^20.19.11",
|
|
96
96
|
"read-pkg": "^9.0.1",
|
|
97
|
-
"svelte": "^5.
|
|
98
|
-
"svelte-check": "^4.3.
|
|
99
|
-
"tsx": "^4.20.
|
|
100
|
-
"typescript": "~5.9.
|
|
97
|
+
"svelte": "^5.43.6",
|
|
98
|
+
"svelte-check": "^4.3.4",
|
|
99
|
+
"tsx": "^4.20.6",
|
|
100
|
+
"typescript": "~5.9.3"
|
|
101
101
|
},
|
|
102
102
|
"publishConfig": {
|
|
103
103
|
"dev": {}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Editor,
|
|
3
|
+
Extension,
|
|
4
|
+
} from '@prosekit/core'
|
|
5
|
+
import {
|
|
6
|
+
derived,
|
|
7
|
+
readable,
|
|
8
|
+
type Readable,
|
|
9
|
+
} from 'svelte/store'
|
|
10
|
+
|
|
11
|
+
import { useEditor } from './use-editor'
|
|
12
|
+
|
|
13
|
+
export interface UseEditorDerivedOptions<E extends Extension = any> {
|
|
14
|
+
/**
|
|
15
|
+
* The editor to add the extension to. If not provided, it will use the
|
|
16
|
+
* editor from the nearest `<ProseKit>` component.
|
|
17
|
+
*/
|
|
18
|
+
editor?: Editor<E>
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Runs a function to derive a value from the editor instance after editor state
|
|
23
|
+
* changes.
|
|
24
|
+
*
|
|
25
|
+
* This is useful when you need to render something based on the editor state,
|
|
26
|
+
* for example, whether the selected text is wrapped in an italic mark.
|
|
27
|
+
*
|
|
28
|
+
* It returns a Svelte store that stores the derived value and updates whenever
|
|
29
|
+
* the editor state changes.
|
|
30
|
+
*
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
export function useEditorDerivedValue<E extends Extension, Derived>(
|
|
34
|
+
/**
|
|
35
|
+
* A function that receives the editor instance and returns a derived value.
|
|
36
|
+
*
|
|
37
|
+
* It will be called whenever the editor's document state changes, or when it
|
|
38
|
+
* mounts.
|
|
39
|
+
*/
|
|
40
|
+
derive: (editor: Editor<E>) => Derived,
|
|
41
|
+
options?: UseEditorDerivedOptions<E>,
|
|
42
|
+
): Readable<Derived> {
|
|
43
|
+
const initialEditor = options?.editor
|
|
44
|
+
const editorStore: Readable<Editor<E>> = initialEditor
|
|
45
|
+
? readable(initialEditor)
|
|
46
|
+
: useEditor<E>({ update: true })
|
|
47
|
+
|
|
48
|
+
return derived(editorStore, derive)
|
|
49
|
+
}
|
|
@@ -11,7 +11,7 @@ import { usePriorityExtension } from './use-priority-extension'
|
|
|
11
11
|
export interface UseExtensionOptions {
|
|
12
12
|
/**
|
|
13
13
|
* The editor to add the extension to. If not provided, it will use the
|
|
14
|
-
* editor from the nearest
|
|
14
|
+
* editor from the nearest `<ProseKit>` component.
|
|
15
15
|
*/
|
|
16
16
|
editor?: Editor
|
|
17
17
|
|
package/src/index.ts
CHANGED
|
@@ -16,6 +16,10 @@ export {
|
|
|
16
16
|
} from './extensions/svelte-node-view'
|
|
17
17
|
export { useDocChange } from './hooks/use-doc-change'
|
|
18
18
|
export { useEditor } from './hooks/use-editor'
|
|
19
|
+
export {
|
|
20
|
+
useEditorDerivedValue,
|
|
21
|
+
type UseEditorDerivedOptions,
|
|
22
|
+
} from './hooks/use-editor-derived-value'
|
|
19
23
|
export {
|
|
20
24
|
useExtension,
|
|
21
25
|
type UseExtensionOptions,
|