@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.
Files changed (55) hide show
  1. package/dist/list/style.css +5 -5
  2. package/dist/list/style.css.map +1 -1
  3. package/dist/prosekit-extensions-autocomplete.d.ts +11 -3
  4. package/dist/prosekit-extensions-autocomplete.d.ts.map +1 -1
  5. package/dist/prosekit-extensions-autocomplete.js +171 -60
  6. package/dist/prosekit-extensions-autocomplete.js.map +1 -1
  7. package/dist/prosekit-extensions-blockquote.js +1 -1
  8. package/dist/prosekit-extensions-blockquote.js.map +1 -1
  9. package/dist/prosekit-extensions-code.d.ts.map +1 -1
  10. package/dist/prosekit-extensions-commit.js +1 -1
  11. package/dist/prosekit-extensions-commit.js.map +1 -1
  12. package/dist/prosekit-extensions-heading.d.ts.map +1 -1
  13. package/dist/prosekit-extensions-heading.js +6 -6
  14. package/dist/prosekit-extensions-heading.js.map +1 -1
  15. package/dist/prosekit-extensions-loro.d.ts +16 -17
  16. package/dist/prosekit-extensions-loro.d.ts.map +1 -1
  17. package/dist/prosekit-extensions-loro.js +13 -6
  18. package/dist/prosekit-extensions-loro.js.map +1 -1
  19. package/dist/prosekit-extensions-paragraph.js +1 -1
  20. package/dist/prosekit-extensions-paragraph.js.map +1 -1
  21. package/dist/prosekit-extensions-placeholder.d.ts.map +1 -1
  22. package/dist/prosekit-extensions-placeholder.js +2 -3
  23. package/dist/prosekit-extensions-placeholder.js.map +1 -1
  24. package/dist/prosekit-extensions-strike.js +2 -2
  25. package/dist/prosekit-extensions-strike.js.map +1 -1
  26. package/dist/prosekit-extensions-table.js +0 -1
  27. package/dist/prosekit-extensions-text-align.js +4 -4
  28. package/dist/prosekit-extensions-text-align.js.map +1 -1
  29. package/dist/prosekit-extensions-yjs.js +1 -1
  30. package/dist/prosekit-extensions-yjs.js.map +1 -1
  31. package/package.json +15 -14
  32. package/src/autocomplete/autocomplete-helpers.ts +18 -9
  33. package/src/autocomplete/autocomplete-plugin.ts +261 -117
  34. package/src/autocomplete/autocomplete-rule.ts +3 -3
  35. package/src/autocomplete/autocomplete.spec.ts +239 -20
  36. package/src/autocomplete/autocomplete.ts +8 -0
  37. package/src/blockquote/blockquote-keymap.spec.ts +4 -4
  38. package/src/blockquote/blockquote-keymap.ts +1 -1
  39. package/src/commit/index.ts +1 -1
  40. package/src/hard-break/hard-break-keymap.spec.ts +5 -7
  41. package/src/heading/heading-keymap.spec.ts +7 -7
  42. package/src/heading/heading-keymap.ts +6 -6
  43. package/src/link/index.spec.ts +9 -8
  44. package/src/list/list-keymap.spec.ts +5 -5
  45. package/src/list/style.css +5 -5
  46. package/src/loro/loro-cursor-plugin.ts +23 -13
  47. package/src/loro/loro-keymap.ts +1 -1
  48. package/src/loro/loro.ts +14 -10
  49. package/src/paragraph/paragraph-keymap.ts +1 -1
  50. package/src/placeholder/index.ts +2 -1
  51. package/src/strike/index.ts +2 -2
  52. package/src/testing/index.ts +2 -2
  53. package/src/testing/keyboard.ts +0 -30
  54. package/src/text-align/index.ts +4 -4
  55. package/src/yjs/yjs-keymap.ts +1 -1
@@ -11,7 +11,7 @@ import {
11
11
 
12
12
  const keymap: Keymap = {
13
13
  'Mod-z': undo,
14
- 'Shift-Mod-z': redo,
14
+ 'Mod-Z': redo,
15
15
  }
16
16
 
17
17
  if (!isApple) {
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
- awareness: CursorAwareness
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?: Omit<LoroCursorOptions, 'awareness'>
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
  ]),
@@ -10,6 +10,6 @@ import { setParagraph } from './paragraph-commands'
10
10
  */
11
11
  export function defineParagraphKeymap(): PlainExtension {
12
12
  return defineKeymap({
13
- 'mod-alt-0': setParagraph(),
13
+ 'Mod-Alt-0': setParagraph(),
14
14
  })
15
15
  }
@@ -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
@@ -64,8 +64,8 @@ export function defineStrikeCommands(): StrikeCommandsExtension {
64
64
  */
65
65
  export function defineStrikeKeymap(): PlainExtension {
66
66
  return defineKeymap({
67
- 'Mod-shift-s': toggleMark({ type: 'strike' }),
68
- 'Mod-shift-x': toggleMark({ type: 'strike' }),
67
+ 'Mod-S': toggleMark({ type: 'strike' }),
68
+ 'Mod-X': toggleMark({ type: 'strike' }),
69
69
  })
70
70
  }
71
71
 
@@ -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 pressKey('mod-C')
127
+ await keyboard.press('ControlOrMeta+C')
128
128
  const html = await readHtmlTextFromClipboard()
129
129
  const plain = await readPlainTextFromClipboard()
130
130
  return { html, plain }
@@ -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
  }
@@ -102,10 +102,10 @@ export function defineTextAlignCommands(
102
102
  */
103
103
  export function defineTextAlignKeymap(types: string[]): PlainExtension {
104
104
  return defineKeymap({
105
- 'mod-shift-l': setTextAlign({ types, value: 'left' }),
106
- 'mod-shift-e': setTextAlign({ types, value: 'center' }),
107
- 'mod-shift-r': setTextAlign({ types, value: 'right' }),
108
- 'mod-shift-j': setTextAlign({ types, value: 'justify' }),
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
 
@@ -11,7 +11,7 @@ import {
11
11
 
12
12
  const keymap: Keymap = {
13
13
  'Mod-z': undoCommand,
14
- 'Shift-Mod-z': redoCommand,
14
+ 'Mod-Z': redoCommand,
15
15
  }
16
16
 
17
17
  if (!isApple) {