@prosekit/extensions 0.12.2 → 0.13.0
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/list/style.css +5 -5
- package/dist/list/style.css.map +1 -1
- package/dist/prosekit-extensions-autocomplete.d.ts +11 -3
- package/dist/prosekit-extensions-autocomplete.d.ts.map +1 -1
- package/dist/prosekit-extensions-autocomplete.js +171 -60
- package/dist/prosekit-extensions-autocomplete.js.map +1 -1
- package/dist/prosekit-extensions-blockquote.js +1 -1
- package/dist/prosekit-extensions-blockquote.js.map +1 -1
- package/dist/prosekit-extensions-code.d.ts.map +1 -1
- package/dist/prosekit-extensions-commit.js +1 -1
- package/dist/prosekit-extensions-commit.js.map +1 -1
- package/dist/prosekit-extensions-heading.d.ts.map +1 -1
- package/dist/prosekit-extensions-heading.js +6 -6
- package/dist/prosekit-extensions-heading.js.map +1 -1
- package/dist/prosekit-extensions-loro.d.ts +16 -17
- package/dist/prosekit-extensions-loro.d.ts.map +1 -1
- package/dist/prosekit-extensions-loro.js +13 -6
- package/dist/prosekit-extensions-loro.js.map +1 -1
- package/dist/prosekit-extensions-paragraph.js +1 -1
- package/dist/prosekit-extensions-paragraph.js.map +1 -1
- package/dist/prosekit-extensions-placeholder.d.ts.map +1 -1
- package/dist/prosekit-extensions-placeholder.js +2 -3
- package/dist/prosekit-extensions-placeholder.js.map +1 -1
- package/dist/prosekit-extensions-strike.js +2 -2
- package/dist/prosekit-extensions-strike.js.map +1 -1
- package/dist/prosekit-extensions-table.js +0 -1
- package/dist/prosekit-extensions-text-align.js +4 -4
- package/dist/prosekit-extensions-text-align.js.map +1 -1
- package/dist/prosekit-extensions-yjs.js +1 -1
- package/dist/prosekit-extensions-yjs.js.map +1 -1
- package/package.json +15 -14
- package/src/autocomplete/autocomplete-helpers.ts +18 -9
- package/src/autocomplete/autocomplete-plugin.ts +261 -117
- package/src/autocomplete/autocomplete-rule.ts +3 -3
- package/src/autocomplete/autocomplete.spec.ts +239 -20
- package/src/autocomplete/autocomplete.ts +8 -0
- package/src/blockquote/blockquote-keymap.spec.ts +4 -4
- package/src/blockquote/blockquote-keymap.ts +1 -1
- package/src/commit/index.ts +1 -1
- package/src/hard-break/hard-break-keymap.spec.ts +5 -7
- package/src/heading/heading-keymap.spec.ts +7 -7
- package/src/heading/heading-keymap.ts +6 -6
- package/src/link/index.spec.ts +9 -8
- package/src/list/list-keymap.spec.ts +5 -5
- package/src/list/style.css +5 -5
- package/src/loro/loro-cursor-plugin.ts +23 -13
- package/src/loro/loro-keymap.ts +1 -1
- package/src/loro/loro.ts +14 -10
- package/src/paragraph/paragraph-keymap.ts +1 -1
- package/src/placeholder/index.ts +2 -1
- package/src/strike/index.ts +2 -2
- package/src/testing/index.ts +2 -2
- package/src/testing/keyboard.ts +0 -30
- package/src/text-align/index.ts +4 -4
- package/src/yjs/yjs-keymap.ts +1 -1
package/src/loro/loro-keymap.ts
CHANGED
package/src/loro/loro.ts
CHANGED
|
@@ -7,6 +7,8 @@ import {
|
|
|
7
7
|
} from '@prosekit/core'
|
|
8
8
|
import type {
|
|
9
9
|
CursorAwareness,
|
|
10
|
+
CursorEphemeralStore,
|
|
11
|
+
CursorPluginOptions,
|
|
10
12
|
LoroDocType,
|
|
11
13
|
LoroSyncPluginProps,
|
|
12
14
|
LoroUndoPluginProps,
|
|
@@ -16,10 +18,7 @@ import {
|
|
|
16
18
|
defineLoroCommands,
|
|
17
19
|
type LoroCommandsExtension,
|
|
18
20
|
} from './loro-commands'
|
|
19
|
-
import {
|
|
20
|
-
defineLoroCursorPlugin,
|
|
21
|
-
type LoroCursorOptions,
|
|
22
|
-
} from './loro-cursor-plugin'
|
|
21
|
+
import { defineLoroCursorPlugin } from './loro-cursor-plugin'
|
|
23
22
|
import { defineLoroKeymap } from './loro-keymap'
|
|
24
23
|
import { defineLoroSyncPlugin } from './loro-sync-plugin'
|
|
25
24
|
import { defineLoroUndoPlugin } from './loro-undo-plugin'
|
|
@@ -31,9 +30,14 @@ export interface LoroOptions {
|
|
|
31
30
|
doc: LoroDocType
|
|
32
31
|
|
|
33
32
|
/**
|
|
34
|
-
* The Awareness instance.
|
|
33
|
+
* The (legacy) Awareness instance. One of `awareness` or `presence` must be provided.
|
|
34
|
+
*/
|
|
35
|
+
awareness?: CursorAwareness
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The CursorEphemeralStore instance. One of `awareness` or `presence` must be provided.
|
|
35
39
|
*/
|
|
36
|
-
|
|
40
|
+
presence?: CursorEphemeralStore
|
|
37
41
|
|
|
38
42
|
/**
|
|
39
43
|
* Extra options for `LoroSyncPlugin`.
|
|
@@ -46,9 +50,9 @@ export interface LoroOptions {
|
|
|
46
50
|
undo?: Omit<LoroUndoPluginProps, 'doc'>
|
|
47
51
|
|
|
48
52
|
/**
|
|
49
|
-
* Extra options for `LoroCursorPlugin`.
|
|
53
|
+
* Extra options for `LoroCursorPlugin` or `LoroEphemeralCursorPlugin`.
|
|
50
54
|
*/
|
|
51
|
-
cursor?:
|
|
55
|
+
cursor?: CursorPluginOptions
|
|
52
56
|
}
|
|
53
57
|
|
|
54
58
|
/**
|
|
@@ -60,13 +64,13 @@ export type LoroExtension = Union<[LoroCommandsExtension, PlainExtension]>
|
|
|
60
64
|
* @public
|
|
61
65
|
*/
|
|
62
66
|
export function defineLoro(options: LoroOptions): LoroExtension {
|
|
63
|
-
const { doc, awareness, sync, undo, cursor } = options
|
|
67
|
+
const { doc, awareness, presence, sync, undo, cursor } = options
|
|
64
68
|
|
|
65
69
|
return withPriority(
|
|
66
70
|
union([
|
|
67
71
|
defineLoroKeymap(),
|
|
68
72
|
defineLoroCommands(),
|
|
69
|
-
defineLoroCursorPlugin({ ...cursor, awareness }),
|
|
73
|
+
defineLoroCursorPlugin({ ...cursor, awareness, presence }),
|
|
70
74
|
defineLoroUndoPlugin({ ...undo, doc }),
|
|
71
75
|
defineLoroSyncPlugin({ ...sync, doc }),
|
|
72
76
|
]),
|
package/src/placeholder/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
definePlugin,
|
|
3
3
|
isInCodeBlock,
|
|
4
|
+
isTextSelection,
|
|
4
5
|
maybeRun,
|
|
5
6
|
type PlainExtension,
|
|
6
7
|
} from '@prosekit/core'
|
|
@@ -98,7 +99,7 @@ function createPlaceholderDecoration(
|
|
|
98
99
|
if (!placeholderText) return null
|
|
99
100
|
|
|
100
101
|
const { selection } = state
|
|
101
|
-
if (!selection.empty) return null
|
|
102
|
+
if (!selection.empty || !isTextSelection(selection)) return null
|
|
102
103
|
|
|
103
104
|
const $pos = selection.$anchor
|
|
104
105
|
const node = $pos.parent
|
package/src/strike/index.ts
CHANGED
|
@@ -64,8 +64,8 @@ export function defineStrikeCommands(): StrikeCommandsExtension {
|
|
|
64
64
|
*/
|
|
65
65
|
export function defineStrikeKeymap(): PlainExtension {
|
|
66
66
|
return defineKeymap({
|
|
67
|
-
'Mod-
|
|
68
|
-
'Mod-
|
|
67
|
+
'Mod-S': toggleMark({ type: 'strike' }),
|
|
68
|
+
'Mod-X': toggleMark({ type: 'strike' }),
|
|
69
69
|
})
|
|
70
70
|
}
|
|
71
71
|
|
package/src/testing/index.ts
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
createTestEditor,
|
|
15
15
|
type TestEditor,
|
|
16
16
|
} from '@prosekit/core/test'
|
|
17
|
+
import { keyboard } from 'vitest-browser-commands/playwright'
|
|
17
18
|
|
|
18
19
|
import { defineBlockquote } from '../blockquote'
|
|
19
20
|
import { defineBold } from '../bold'
|
|
@@ -41,7 +42,6 @@ import {
|
|
|
41
42
|
readHtmlTextFromClipboard,
|
|
42
43
|
readPlainTextFromClipboard,
|
|
43
44
|
} from './clipboard'
|
|
44
|
-
import { pressKey } from './keyboard'
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
47
|
* @internal
|
|
@@ -124,7 +124,7 @@ export function setupTest() {
|
|
|
124
124
|
|
|
125
125
|
const copy = async () => {
|
|
126
126
|
editor.view.dom.focus()
|
|
127
|
-
await
|
|
127
|
+
await keyboard.press('ControlOrMeta+C')
|
|
128
128
|
const html = await readHtmlTextFromClipboard()
|
|
129
129
|
const plain = await readPlainTextFromClipboard()
|
|
130
130
|
return { html, plain }
|
package/src/testing/keyboard.ts
CHANGED
|
@@ -1,35 +1,5 @@
|
|
|
1
|
-
import { isApple } from '@prosekit/core'
|
|
2
1
|
import { userEvent } from 'vitest/browser'
|
|
3
2
|
|
|
4
|
-
/**
|
|
5
|
-
* @example
|
|
6
|
-
*
|
|
7
|
-
* ```ts
|
|
8
|
-
* await pressKey('mod-1')
|
|
9
|
-
* await pressKey('Backspace')
|
|
10
|
-
* ```
|
|
11
|
-
*
|
|
12
|
-
* @internal
|
|
13
|
-
*/
|
|
14
|
-
export async function pressKey(input: string): Promise<void> {
|
|
15
|
-
const keys = input.split('-').map((key) => {
|
|
16
|
-
if (key.toLowerCase() === 'mod') {
|
|
17
|
-
return isApple ? 'Meta' : 'Control'
|
|
18
|
-
}
|
|
19
|
-
return key
|
|
20
|
-
})
|
|
21
|
-
const seq: string[] = []
|
|
22
|
-
for (const key of keys) {
|
|
23
|
-
// Press key without releasing it
|
|
24
|
-
seq.push('{' + key + '>}')
|
|
25
|
-
}
|
|
26
|
-
for (const key of keys.toReversed()) {
|
|
27
|
-
// Release a previously pressed key
|
|
28
|
-
seq.push('{/' + key + '}')
|
|
29
|
-
}
|
|
30
|
-
return await userEvent.keyboard(seq.join(''))
|
|
31
|
-
}
|
|
32
|
-
|
|
33
3
|
export async function inputText(input: string): Promise<void> {
|
|
34
4
|
return await userEvent.keyboard(input)
|
|
35
5
|
}
|
package/src/text-align/index.ts
CHANGED
|
@@ -102,10 +102,10 @@ export function defineTextAlignCommands(
|
|
|
102
102
|
*/
|
|
103
103
|
export function defineTextAlignKeymap(types: string[]): PlainExtension {
|
|
104
104
|
return defineKeymap({
|
|
105
|
-
'
|
|
106
|
-
'
|
|
107
|
-
'
|
|
108
|
-
'
|
|
105
|
+
'Mod-L': setTextAlign({ types, value: 'left' }),
|
|
106
|
+
'Mod-E': setTextAlign({ types, value: 'center' }),
|
|
107
|
+
'Mod-R': setTextAlign({ types, value: 'right' }),
|
|
108
|
+
'Mod-J': setTextAlign({ types, value: 'justify' }),
|
|
109
109
|
})
|
|
110
110
|
}
|
|
111
111
|
|