@prosekit/extensions 0.13.0 → 0.14.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/{drop-indicator-B1QHFb5m.js → drop-indicator-DJq8pF92.js} +11 -10
- package/dist/drop-indicator-DJq8pF92.js.map +1 -0
- package/dist/{file-DrfcSid-.js → file-upload-I9m1EJAM.js} +3 -3
- package/dist/file-upload-I9m1EJAM.js.map +1 -0
- package/dist/{index-oIc1a2f2.d.ts → file-upload-dr3IXUty.d.ts} +1 -1
- package/dist/file-upload-dr3IXUty.d.ts.map +1 -0
- package/dist/{paste-rule-pVb4sqvJ.js → mark-paste-rule-n_2Ehmb5.js} +7 -7
- package/dist/mark-paste-rule-n_2Ehmb5.js.map +1 -0
- package/dist/{mark-rule-BcLB4Uv2.js → mark-rule-CUnXwBuy.js} +6 -6
- package/dist/mark-rule-CUnXwBuy.js.map +1 -0
- package/dist/prosekit-extensions-autocomplete.d.ts.map +1 -1
- package/dist/prosekit-extensions-autocomplete.js.map +1 -1
- package/dist/prosekit-extensions-background-color.d.ts +62 -0
- package/dist/prosekit-extensions-background-color.d.ts.map +1 -0
- package/dist/prosekit-extensions-background-color.js +76 -0
- package/dist/prosekit-extensions-background-color.js.map +1 -0
- package/dist/prosekit-extensions-blockquote.d.ts.map +1 -1
- package/dist/prosekit-extensions-blockquote.js +1 -1
- package/dist/prosekit-extensions-blockquote.js.map +1 -1
- package/dist/prosekit-extensions-bold.d.ts.map +1 -1
- package/dist/prosekit-extensions-bold.js +1 -1
- package/dist/prosekit-extensions-bold.js.map +1 -1
- package/dist/prosekit-extensions-code-block.d.ts +1 -1
- package/dist/prosekit-extensions-code-block.d.ts.map +1 -1
- package/dist/prosekit-extensions-code-block.js +4 -4
- package/dist/prosekit-extensions-code-block.js.map +1 -1
- package/dist/prosekit-extensions-code.d.ts.map +1 -1
- package/dist/prosekit-extensions-code.js +1 -1
- package/dist/prosekit-extensions-code.js.map +1 -1
- package/dist/prosekit-extensions-commit.d.ts +0 -1
- package/dist/prosekit-extensions-commit.d.ts.map +1 -1
- package/dist/prosekit-extensions-commit.js.map +1 -1
- package/dist/prosekit-extensions-doc.d.ts +0 -1
- package/dist/prosekit-extensions-doc.d.ts.map +1 -1
- package/dist/prosekit-extensions-doc.js.map +1 -1
- package/dist/prosekit-extensions-drop-cursor.d.ts.map +1 -1
- package/dist/prosekit-extensions-drop-cursor.js.map +1 -1
- package/dist/prosekit-extensions-drop-indicator.d.ts +0 -1
- package/dist/prosekit-extensions-drop-indicator.d.ts.map +1 -1
- package/dist/prosekit-extensions-drop-indicator.js +1 -1
- package/dist/prosekit-extensions-enter-rule.d.ts +6 -79
- package/dist/prosekit-extensions-enter-rule.d.ts.map +1 -1
- package/dist/prosekit-extensions-enter-rule.js +37 -2
- package/dist/prosekit-extensions-enter-rule.js.map +1 -0
- package/dist/prosekit-extensions-file.d.ts +2 -2
- package/dist/prosekit-extensions-file.js +1 -1
- package/dist/prosekit-extensions-gap-cursor.d.ts +0 -1
- package/dist/prosekit-extensions-gap-cursor.d.ts.map +1 -1
- package/dist/prosekit-extensions-gap-cursor.js.map +1 -1
- package/dist/prosekit-extensions-hard-break.d.ts.map +1 -1
- package/dist/prosekit-extensions-hard-break.js.map +1 -1
- package/dist/prosekit-extensions-heading.d.ts.map +1 -1
- package/dist/prosekit-extensions-heading.js +1 -1
- package/dist/prosekit-extensions-heading.js.map +1 -1
- package/dist/prosekit-extensions-horizontal-rule.d.ts.map +1 -1
- package/dist/prosekit-extensions-horizontal-rule.js +1 -1
- package/dist/prosekit-extensions-horizontal-rule.js.map +1 -1
- package/dist/prosekit-extensions-image.d.ts +10 -2
- package/dist/prosekit-extensions-image.d.ts.map +1 -1
- package/dist/prosekit-extensions-image.js +17 -4
- package/dist/prosekit-extensions-image.js.map +1 -1
- package/dist/prosekit-extensions-input-rule.d.ts +0 -1
- package/dist/prosekit-extensions-input-rule.d.ts.map +1 -1
- package/dist/prosekit-extensions-input-rule.js +89 -2
- package/dist/prosekit-extensions-input-rule.js.map +1 -0
- package/dist/prosekit-extensions-italic.d.ts.map +1 -1
- package/dist/prosekit-extensions-italic.js +1 -1
- package/dist/prosekit-extensions-italic.js.map +1 -1
- package/dist/prosekit-extensions-link.d.ts +0 -1
- package/dist/prosekit-extensions-link.d.ts.map +1 -1
- package/dist/prosekit-extensions-link.js +4 -4
- package/dist/prosekit-extensions-link.js.map +1 -1
- package/dist/prosekit-extensions-list.d.ts +0 -1
- package/dist/prosekit-extensions-list.d.ts.map +1 -1
- package/dist/prosekit-extensions-list.js +3 -3
- package/dist/prosekit-extensions-list.js.map +1 -1
- package/dist/prosekit-extensions-loro.d.ts.map +1 -1
- package/dist/prosekit-extensions-loro.js +2 -2
- package/dist/prosekit-extensions-loro.js.map +1 -1
- package/dist/prosekit-extensions-mark-rule.d.ts +0 -1
- package/dist/prosekit-extensions-mark-rule.d.ts.map +1 -1
- package/dist/prosekit-extensions-mark-rule.js +1 -1
- package/dist/prosekit-extensions-math.d.ts +154 -0
- package/dist/prosekit-extensions-math.d.ts.map +1 -0
- package/dist/prosekit-extensions-math.js +104 -0
- package/dist/prosekit-extensions-math.js.map +1 -0
- package/dist/prosekit-extensions-mention.d.ts.map +1 -1
- package/dist/prosekit-extensions-mention.js.map +1 -1
- package/dist/prosekit-extensions-mod-click-prevention.d.ts +0 -1
- package/dist/prosekit-extensions-mod-click-prevention.d.ts.map +1 -1
- package/dist/prosekit-extensions-mod-click-prevention.js.map +1 -1
- package/dist/prosekit-extensions-paragraph.d.ts.map +1 -1
- package/dist/prosekit-extensions-paragraph.js.map +1 -1
- package/dist/prosekit-extensions-paste-rule.d.ts +0 -1
- package/dist/prosekit-extensions-paste-rule.d.ts.map +1 -1
- package/dist/prosekit-extensions-paste-rule.js +1 -1
- package/dist/prosekit-extensions-placeholder.d.ts.map +1 -1
- package/dist/prosekit-extensions-placeholder.js +1 -1
- package/dist/prosekit-extensions-placeholder.js.map +1 -1
- package/dist/prosekit-extensions-readonly.d.ts +0 -1
- package/dist/prosekit-extensions-readonly.d.ts.map +1 -1
- package/dist/prosekit-extensions-readonly.js.map +1 -1
- package/dist/prosekit-extensions-search.d.ts +0 -1
- package/dist/prosekit-extensions-search.d.ts.map +1 -1
- package/dist/prosekit-extensions-search.js.map +1 -1
- package/dist/prosekit-extensions-strike.d.ts +0 -1
- package/dist/prosekit-extensions-strike.d.ts.map +1 -1
- package/dist/prosekit-extensions-strike.js +1 -1
- package/dist/prosekit-extensions-table.d.ts.map +1 -1
- package/dist/prosekit-extensions-table.js +1 -1
- package/dist/prosekit-extensions-text-align.d.ts +0 -1
- package/dist/prosekit-extensions-text-align.d.ts.map +1 -1
- package/dist/prosekit-extensions-text-align.js +2 -2
- package/dist/prosekit-extensions-text-align.js.map +1 -1
- package/dist/prosekit-extensions-text-color.d.ts +62 -0
- package/dist/prosekit-extensions-text-color.d.ts.map +1 -0
- package/dist/prosekit-extensions-text-color.js +76 -0
- package/dist/prosekit-extensions-text-color.js.map +1 -0
- package/dist/prosekit-extensions-text.d.ts +0 -1
- package/dist/prosekit-extensions-text.d.ts.map +1 -1
- package/dist/prosekit-extensions-text.js.map +1 -1
- package/dist/prosekit-extensions-underline.d.ts +0 -1
- package/dist/prosekit-extensions-underline.d.ts.map +1 -1
- package/dist/prosekit-extensions-virtual-selection.d.ts +0 -1
- package/dist/prosekit-extensions-virtual-selection.d.ts.map +1 -1
- package/dist/prosekit-extensions-virtual-selection.js.map +1 -1
- package/dist/prosekit-extensions-yjs.d.ts +9 -2
- package/dist/prosekit-extensions-yjs.d.ts.map +1 -1
- package/dist/prosekit-extensions-yjs.js.map +1 -1
- package/dist/shiki-highlighter-chunk.d.ts +19 -2
- package/dist/shiki-highlighter-chunk.d.ts.map +1 -0
- package/dist/shiki-highlighter-chunk.js.map +1 -1
- package/dist/{table-BRDh_9mG.js → table-UJVYsrB7.js} +2 -2
- package/dist/table-UJVYsrB7.js.map +1 -0
- package/package.json +42 -17
- package/src/autocomplete/autocomplete-helpers.ts +1 -5
- package/src/autocomplete/autocomplete-plugin.ts +3 -13
- package/src/autocomplete/autocomplete.spec.ts +4 -19
- package/src/autocomplete/autocomplete.ts +1 -7
- package/src/background-color/background-color-commands.spec.ts +71 -0
- package/src/background-color/background-color-commands.ts +35 -0
- package/src/background-color/background-color-spec.spec.ts +286 -0
- package/src/background-color/background-color-spec.ts +58 -0
- package/src/background-color/background-color.ts +21 -0
- package/src/background-color/index.ts +8 -0
- package/src/blockquote/blockquote-commands.ts +1 -7
- package/src/blockquote/blockquote-keymap.spec.ts +1 -5
- package/src/blockquote/blockquote-keymap.ts +1 -6
- package/src/blockquote/blockquote-spec.ts +1 -4
- package/src/blockquote/blockquote.ts +3 -12
- package/src/blockquote/index.ts +3 -12
- package/src/bold/bold-commands.ts +1 -5
- package/src/bold/bold-input-rule.spec.ts +1 -5
- package/src/bold/bold-input-rule.ts +1 -4
- package/src/bold/bold-keymap.ts +1 -5
- package/src/bold/bold-spec.ts +1 -4
- package/src/bold/bold.ts +3 -12
- package/src/bold/index.ts +3 -12
- package/src/code/code-commands.ts +1 -5
- package/src/code/code-input-rule.ts +1 -4
- package/src/code/code-keymap.ts +1 -5
- package/src/code/code-spec.ts +1 -4
- package/src/code/code.ts +3 -12
- package/src/code/index.ts +3 -12
- package/src/code-block/code-block-commands.ts +1 -8
- package/src/code-block/code-block-highlight.ts +2 -8
- package/src/code-block/code-block-keymap.ts +2 -9
- package/src/code-block/code-block-shiki.ts +1 -4
- package/src/code-block/code-block-spec.spec.ts +4 -11
- package/src/code-block/code-block-spec.ts +1 -4
- package/src/code-block/code-block.ts +4 -16
- package/src/code-block/index.ts +5 -21
- package/src/code-block/shiki-highlighter-chunk.ts +1 -7
- package/src/code-block/shiki-highlighter.ts +1 -4
- package/src/code-block/shiki-parser.ts +1 -4
- package/src/commit/index.ts +6 -35
- package/src/doc/index.ts +1 -4
- package/src/drop-cursor/drop-cursor.ts +1 -4
- package/src/drop-cursor/index.ts +1 -5
- package/src/drop-indicator/drop-indicator-facet.ts +12 -21
- package/src/drop-indicator/index.ts +1 -5
- package/src/enter-rule/index.ts +18 -200
- package/src/file/file-paste-handler.spec.ts +3 -16
- package/src/file/index.ts +3 -16
- package/src/gap-cursor/gap-cursor.ts +1 -4
- package/src/gap-cursor/index.ts +1 -4
- package/src/hard-break/hard-break-commands.ts +1 -5
- package/src/hard-break/hard-break-keymap.spec.ts +1 -5
- package/src/hard-break/hard-break-keymap.ts +1 -4
- package/src/hard-break/hard-break-spec.ts +1 -4
- package/src/hard-break/hard-break.ts +3 -12
- package/src/hard-break/index.ts +3 -12
- package/src/heading/heading-commands.ts +1 -7
- package/src/heading/heading-keymap.spec.ts +1 -5
- package/src/heading/heading-keymap.ts +1 -8
- package/src/heading/heading-spec.ts +1 -4
- package/src/heading/heading.ts +3 -12
- package/src/heading/index.ts +3 -12
- package/src/horizontal-rule/horizontal-rule-commands.spec.ts +1 -5
- package/src/horizontal-rule/horizontal-rule-commands.ts +2 -9
- package/src/horizontal-rule/horizontal-rule-input-rule.spec.ts +5 -9
- package/src/horizontal-rule/horizontal-rule-input-rule.ts +1 -5
- package/src/horizontal-rule/horizontal-rule-spec.ts +1 -4
- package/src/horizontal-rule/horizontal-rule.ts +3 -12
- package/src/horizontal-rule/index.ts +3 -13
- package/src/image/image-commands/upload-image.spec.ts +245 -0
- package/src/image/image-commands/upload-image.ts +46 -11
- package/src/image/image-commands.ts +2 -8
- package/src/image/image-spec.ts +1 -4
- package/src/image/image-upload-handler.ts +2 -8
- package/src/image/image.ts +3 -12
- package/src/image/index.ts +3 -13
- package/src/input-rule/index.ts +2 -13
- package/src/italic/index.ts +3 -12
- package/src/italic/italic-commands.spec.ts +2 -10
- package/src/italic/italic-commands.ts +1 -5
- package/src/italic/italic-input-rule.spec.ts +1 -5
- package/src/italic/italic-input-rule.ts +1 -4
- package/src/italic/italic-keymap.ts +1 -5
- package/src/italic/italic-spec.ts +1 -4
- package/src/italic/italic.ts +3 -12
- package/src/link/index.spec.ts +1 -5
- package/src/link/index.ts +1 -5
- package/src/link/link-paste-rule.spec.ts +2 -9
- package/src/link/link-regex.spec.ts +1 -5
- package/src/list/index.ts +3 -12
- package/src/list/list-commands.ts +1 -5
- package/src/list/list-input-rules.ts +1 -4
- package/src/list/list-keymap.spec.ts +1 -5
- package/src/list/list-keymap.ts +2 -8
- package/src/list/list-plugins.ts +1 -4
- package/src/list/list-serializer.ts +2 -9
- package/src/list/list-spec.ts +3 -13
- package/src/list/list.spec.ts +10 -21
- package/src/list/list.ts +3 -12
- package/src/loro/index.ts +3 -13
- package/src/loro/loro-commands.ts +2 -8
- package/src/loro/loro-cursor-plugin.ts +3 -13
- package/src/loro/loro-keymap.ts +2 -10
- package/src/loro/loro-sync-plugin.ts +2 -8
- package/src/loro/loro-undo-plugin.ts +2 -8
- package/src/loro/loro.ts +2 -11
- package/src/mark-rule/apply.ts +3 -13
- package/src/mark-rule/mark-rule.spec.ts +2 -13
- package/src/mark-rule/mark-rule.ts +2 -13
- package/src/mark-rule/range.ts +2 -8
- package/src/mark-rule/types.ts +1 -4
- package/src/math/index.ts +22 -0
- package/src/math/math-block.ts +89 -0
- package/src/math/math-inline.ts +89 -0
- package/src/math/math-plugin.ts +8 -0
- package/src/math/math.ts +39 -0
- package/src/mention/index.ts +1 -8
- package/src/mod-click-prevention/index.ts +2 -9
- package/src/paragraph/paragraph-commands.ts +1 -5
- package/src/paragraph/paragraph-keymap.ts +1 -4
- package/src/paragraph/paragraph-spec.ts +1 -4
- package/src/paragraph/paragraph.ts +3 -14
- package/src/paste-rule/index.ts +2 -10
- package/src/paste-rule/mark-paste-rule.spec.ts +3 -13
- package/src/paste-rule/mark-paste-rule.ts +4 -14
- package/src/paste-rule/paste-rule-plugin.ts +2 -11
- package/src/paste-rule/paste-rule.spec.ts +4 -19
- package/src/paste-rule/split-text-by-regex.spec.ts +1 -5
- package/src/placeholder/index.ts +3 -16
- package/src/readonly/index.ts +2 -8
- package/src/search/index.ts +1 -6
- package/src/table/index.ts +10 -40
- package/src/table/table-commands/delete-cell-selection.spec.ts +1 -5
- package/src/table/table-commands/exit-table.spec.ts +1 -5
- package/src/table/table-commands/insert-table.spec.ts +1 -5
- package/src/table/table-commands/insert-table.ts +1 -4
- package/src/table/table-commands/move-table-column.spec.ts +1 -5
- package/src/table/table-commands/move-table-column.ts +1 -4
- package/src/table/table-commands/move-table-row.spec.ts +1 -5
- package/src/table/table-commands/move-table-row.ts +1 -4
- package/src/table/table-commands/select-table-cell.spec.ts +1 -5
- package/src/table/table-commands/select-table-column.spec.ts +1 -5
- package/src/table/table-commands/select-table-row.spec.ts +1 -5
- package/src/table/table-commands/select-table.spec.ts +1 -5
- package/src/table/table-commands/select-table.ts +1 -4
- package/src/table/table-commands.ts +8 -32
- package/src/table/table-plugins.ts +2 -8
- package/src/table/table-spec.spec.ts +2 -11
- package/src/table/table-spec.ts +2 -8
- package/src/table/table-utils.ts +2 -6
- package/src/table/table.ts +2 -8
- package/src/table/test-utils.ts +1 -4
- package/src/testing/clipboard.ts +1 -2
- package/src/testing/index.ts +10 -12
- package/src/testing/katex.ts +9 -0
- package/src/text/index.ts +1 -4
- package/src/text-align/index.ts +2 -2
- package/src/text-color/index.ts +3 -0
- package/src/text-color/text-color-commands.spec.ts +71 -0
- package/src/text-color/text-color-commands.ts +35 -0
- package/src/text-color/text-color-spec.spec.ts +297 -0
- package/src/text-color/text-color-spec.ts +58 -0
- package/src/text-color/text-color.ts +21 -0
- package/src/virtual-selection/index.ts +3 -14
- package/src/yjs/index.ts +5 -20
- package/src/yjs/yjs-commands.ts +2 -8
- package/src/yjs/yjs-cursor-plugin.ts +3 -5
- package/src/yjs/yjs-keymap.ts +2 -10
- package/src/yjs/yjs-sync-plugin.ts +1 -4
- package/src/yjs/yjs-types.ts +8 -0
- package/src/yjs/yjs-undo-plugin.ts +2 -8
- package/src/yjs/yjs.ts +6 -24
- package/dist/drop-indicator-B1QHFb5m.js.map +0 -1
- package/dist/enter-rule-CzWOZF_Z.js +0 -96
- package/dist/enter-rule-CzWOZF_Z.js.map +0 -1
- package/dist/file-DrfcSid-.js.map +0 -1
- package/dist/index-oIc1a2f2.d.ts.map +0 -1
- package/dist/input-rule-dmsb3j6w.js +0 -90
- package/dist/input-rule-dmsb3j6w.js.map +0 -1
- package/dist/mark-rule-BcLB4Uv2.js.map +0 -1
- package/dist/paste-rule-pVb4sqvJ.js.map +0 -1
- package/dist/shiki-highlighter-chunk-rkzofy4z.d.ts +0 -19
- package/dist/shiki-highlighter-chunk-rkzofy4z.d.ts.map +0 -1
- package/dist/table-BRDh_9mG.js.map +0 -1
- package/src/testing/format-html.ts +0 -5
package/src/text-align/index.ts
CHANGED
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
defineCommands,
|
|
3
3
|
defineKeymap,
|
|
4
4
|
defineNodeAttr,
|
|
5
|
-
|
|
5
|
+
setNodeAttrsBetween,
|
|
6
6
|
union,
|
|
7
7
|
type Extension,
|
|
8
8
|
type PlainExtension,
|
|
@@ -74,7 +74,7 @@ export function setTextAlign({
|
|
|
74
74
|
types: string[]
|
|
75
75
|
value: string | null
|
|
76
76
|
}): Command {
|
|
77
|
-
return
|
|
77
|
+
return setNodeAttrsBetween({ type: types, attrs: { textAlign: value } })
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
/**
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { defineTextColor, type TextColorExtension } from './text-color'
|
|
2
|
+
export { addTextColor, defineTextColorCommands, removeTextColor, type TextColorCommandsExtension } from './text-color-commands'
|
|
3
|
+
export { defineTextColorSpec, type TextColorAttrs, type TextColorSpecExtension } from './text-color-spec'
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import { setupTest } from '../testing'
|
|
4
|
+
|
|
5
|
+
describe('addTextColor', () => {
|
|
6
|
+
it('can add color to text', () => {
|
|
7
|
+
const { editor, n, m } = setupTest()
|
|
8
|
+
|
|
9
|
+
const doc1 = n.doc(
|
|
10
|
+
n.p('Hello <a>world<b>'),
|
|
11
|
+
)
|
|
12
|
+
const doc2 = n.doc(
|
|
13
|
+
n.p('Hello ', m.textColor({ color: 'red' }, 'world')),
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
editor.set(doc1)
|
|
17
|
+
editor.commands.addTextColor({ color: 'red' })
|
|
18
|
+
expect(editor.getDocJSON()).toEqual(doc2.toJSON())
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
it('can override existing color', () => {
|
|
22
|
+
const { editor, n, m } = setupTest()
|
|
23
|
+
|
|
24
|
+
const doc1 = n.doc(
|
|
25
|
+
n.p(
|
|
26
|
+
'A',
|
|
27
|
+
m.textColor({ color: 'red' }, 'B<a>C'),
|
|
28
|
+
m.textColor({ color: 'red' }, 'DE'),
|
|
29
|
+
'F<b>G',
|
|
30
|
+
),
|
|
31
|
+
)
|
|
32
|
+
const doc2 = n.doc(
|
|
33
|
+
n.p(
|
|
34
|
+
'A',
|
|
35
|
+
m.textColor({ color: 'red' }, 'B'),
|
|
36
|
+
m.textColor({ color: 'blue' }, 'CDEF'),
|
|
37
|
+
'G',
|
|
38
|
+
),
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
editor.set(doc1)
|
|
42
|
+
editor.commands.addTextColor({ color: 'blue' })
|
|
43
|
+
expect(editor.getDocJSON()).toEqual(doc2.toJSON())
|
|
44
|
+
})
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
describe('removeColor', () => {
|
|
48
|
+
it('can remove color from text', () => {
|
|
49
|
+
const { editor, n, m } = setupTest()
|
|
50
|
+
|
|
51
|
+
const doc1 = n.doc(
|
|
52
|
+
n.p(
|
|
53
|
+
'A',
|
|
54
|
+
m.textColor({ color: 'red' }, 'B<a>C'),
|
|
55
|
+
m.textColor({ color: 'blue' }, 'DE'),
|
|
56
|
+
'F<b>G',
|
|
57
|
+
),
|
|
58
|
+
)
|
|
59
|
+
const doc2 = n.doc(
|
|
60
|
+
n.p(
|
|
61
|
+
'A',
|
|
62
|
+
m.textColor({ color: 'red' }, 'B'),
|
|
63
|
+
'CDEFG',
|
|
64
|
+
),
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
editor.set(doc1)
|
|
68
|
+
editor.commands.removeTextColor()
|
|
69
|
+
expect(editor.getDocJSON()).toEqual(doc2.toJSON())
|
|
70
|
+
})
|
|
71
|
+
})
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { addMark, defineCommands, removeMark, type Extension } from '@prosekit/core'
|
|
2
|
+
import type { Command } from '@prosekit/pm/state'
|
|
3
|
+
|
|
4
|
+
import type { TextColorAttrs } from './text-color-spec'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export function addTextColor(attrs: TextColorAttrs): Command {
|
|
10
|
+
return addMark({ type: 'textColor', attrs })
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
export function removeTextColor(): Command {
|
|
17
|
+
return removeMark({ type: 'textColor' })
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
export type TextColorCommandsExtension = Extension<{
|
|
24
|
+
Commands: {
|
|
25
|
+
addTextColor: [attrs: TextColorAttrs]
|
|
26
|
+
removeTextColor: []
|
|
27
|
+
}
|
|
28
|
+
}>
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
export function defineTextColorCommands(): TextColorCommandsExtension {
|
|
34
|
+
return defineCommands({ addTextColor, removeTextColor })
|
|
35
|
+
}
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import { formatHTML } from 'diffable-html-snapshot'
|
|
2
|
+
import { describe, expect, it } from 'vitest'
|
|
3
|
+
|
|
4
|
+
import { setupTest } from '../testing'
|
|
5
|
+
|
|
6
|
+
describe('defineTextColorSpec', () => {
|
|
7
|
+
it('should render color as inline span with style attribute', () => {
|
|
8
|
+
const { editor, n, m } = setupTest()
|
|
9
|
+
|
|
10
|
+
const doc = n.doc(
|
|
11
|
+
n.p(
|
|
12
|
+
'Default',
|
|
13
|
+
m.textColor({ color: '#0000ff' }, 'hex'),
|
|
14
|
+
m.textColor({ color: 'blue' }, 'named'),
|
|
15
|
+
m.textColor({ color: 'rgb(0, 0, 255)' }, 'rgb'),
|
|
16
|
+
m.textColor({ color: 'rgba(0 0 255 / 0.5)' }, 'rgba'),
|
|
17
|
+
m.textColor({ color: 'hsl(240 100% 50% / 0.5)' }, 'hsl'),
|
|
18
|
+
m.textColor({ color: 'var(--color-variable)' }, 'variable'),
|
|
19
|
+
),
|
|
20
|
+
)
|
|
21
|
+
editor.set(doc)
|
|
22
|
+
expect(formatHTML(editor.view.dom.innerHTML)).toMatchInlineSnapshot(
|
|
23
|
+
`
|
|
24
|
+
"
|
|
25
|
+
<p>
|
|
26
|
+
Default
|
|
27
|
+
<span
|
|
28
|
+
data-text-color="#0000ff"
|
|
29
|
+
style="color: rgb(0, 0, 255);"
|
|
30
|
+
>
|
|
31
|
+
hex
|
|
32
|
+
</span>
|
|
33
|
+
<span
|
|
34
|
+
data-text-color="blue"
|
|
35
|
+
style="color: blue;"
|
|
36
|
+
>
|
|
37
|
+
named
|
|
38
|
+
</span>
|
|
39
|
+
<span
|
|
40
|
+
data-text-color="rgb(0, 0, 255)"
|
|
41
|
+
style="color: rgb(0, 0, 255);"
|
|
42
|
+
>
|
|
43
|
+
rgb
|
|
44
|
+
</span>
|
|
45
|
+
<span
|
|
46
|
+
data-text-color="rgba(0 0 255 / 0.5)"
|
|
47
|
+
style="color: rgba(0, 0, 255, 0.5);"
|
|
48
|
+
>
|
|
49
|
+
rgba
|
|
50
|
+
</span>
|
|
51
|
+
<span
|
|
52
|
+
data-text-color="hsl(240 100% 50% / 0.5)"
|
|
53
|
+
style="color: rgba(0, 0, 255, 0.5);"
|
|
54
|
+
>
|
|
55
|
+
hsl
|
|
56
|
+
</span>
|
|
57
|
+
<span
|
|
58
|
+
data-text-color="var(--color-variable)"
|
|
59
|
+
style="color: var(--color-variable);"
|
|
60
|
+
>
|
|
61
|
+
variable
|
|
62
|
+
</span>
|
|
63
|
+
</p>
|
|
64
|
+
"
|
|
65
|
+
`,
|
|
66
|
+
)
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
it('should parse color from style attribute', () => {
|
|
70
|
+
const { editor } = setupTest()
|
|
71
|
+
|
|
72
|
+
const html = `<p><span style="color: #0000ff;">text</span></p>`
|
|
73
|
+
editor.setContent(html)
|
|
74
|
+
expect(editor.state.doc.firstChild?.firstChild?.toJSON()).toMatchInlineSnapshot(`
|
|
75
|
+
{
|
|
76
|
+
"marks": [
|
|
77
|
+
{
|
|
78
|
+
"attrs": {
|
|
79
|
+
"color": "rgb(0, 0, 255)",
|
|
80
|
+
},
|
|
81
|
+
"type": "textColor",
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
"text": "text",
|
|
85
|
+
"type": "text",
|
|
86
|
+
}
|
|
87
|
+
`)
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
it('should parse color from data-text-color attribute', () => {
|
|
91
|
+
const { editor } = setupTest()
|
|
92
|
+
|
|
93
|
+
const html = `<p><span data-text-color="rgb(0 0 255 / 0.5)">text</span></p>`
|
|
94
|
+
editor.setContent(html)
|
|
95
|
+
expect(editor.state.doc.firstChild?.firstChild?.toJSON()).toMatchInlineSnapshot(`
|
|
96
|
+
{
|
|
97
|
+
"marks": [
|
|
98
|
+
{
|
|
99
|
+
"attrs": {
|
|
100
|
+
"color": "rgb(0 0 255 / 0.5)",
|
|
101
|
+
},
|
|
102
|
+
"type": "textColor",
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
"text": "text",
|
|
106
|
+
"type": "text",
|
|
107
|
+
}
|
|
108
|
+
`)
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
it('should prioritize data-text-color attribute over style attribute', () => {
|
|
112
|
+
const { editor } = setupTest()
|
|
113
|
+
|
|
114
|
+
const html = `<p><span style="color: blue;" data-text-color="red">This should be red</span></p>`
|
|
115
|
+
editor.setContent(html)
|
|
116
|
+
expect(editor.state.doc.firstChild?.firstChild?.toJSON()).toMatchInlineSnapshot(`
|
|
117
|
+
{
|
|
118
|
+
"marks": [
|
|
119
|
+
{
|
|
120
|
+
"attrs": {
|
|
121
|
+
"color": "red",
|
|
122
|
+
},
|
|
123
|
+
"type": "textColor",
|
|
124
|
+
},
|
|
125
|
+
],
|
|
126
|
+
"text": "This should be red",
|
|
127
|
+
"type": "text",
|
|
128
|
+
}
|
|
129
|
+
`)
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
it('can handle non-span inline elements', () => {
|
|
133
|
+
const { editor } = setupTest()
|
|
134
|
+
|
|
135
|
+
const html = `<p>`
|
|
136
|
+
+ `<i><span style="color: red;">This should be red and italic</span></i>`
|
|
137
|
+
+ `<span style="color: green;"><i>This should be green and italic</i></span>`
|
|
138
|
+
+ `<b style="color: blue;">This should be blue and bold</b>`
|
|
139
|
+
+ `</p>`
|
|
140
|
+
editor.setContent(html)
|
|
141
|
+
expect(editor.state.doc.firstChild?.toJSON()).toMatchInlineSnapshot(`
|
|
142
|
+
{
|
|
143
|
+
"content": [
|
|
144
|
+
{
|
|
145
|
+
"marks": [
|
|
146
|
+
{
|
|
147
|
+
"attrs": {
|
|
148
|
+
"color": "red",
|
|
149
|
+
},
|
|
150
|
+
"type": "textColor",
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
"type": "italic",
|
|
154
|
+
},
|
|
155
|
+
],
|
|
156
|
+
"text": "This should be red and italic",
|
|
157
|
+
"type": "text",
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
"marks": [
|
|
161
|
+
{
|
|
162
|
+
"attrs": {
|
|
163
|
+
"color": "green",
|
|
164
|
+
},
|
|
165
|
+
"type": "textColor",
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
"type": "italic",
|
|
169
|
+
},
|
|
170
|
+
],
|
|
171
|
+
"text": "This should be green and italic",
|
|
172
|
+
"type": "text",
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
"marks": [
|
|
176
|
+
{
|
|
177
|
+
"attrs": {
|
|
178
|
+
"color": "blue",
|
|
179
|
+
},
|
|
180
|
+
"type": "textColor",
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
"type": "bold",
|
|
184
|
+
},
|
|
185
|
+
],
|
|
186
|
+
"text": "This should be blue and bold",
|
|
187
|
+
"type": "text",
|
|
188
|
+
},
|
|
189
|
+
],
|
|
190
|
+
"type": "paragraph",
|
|
191
|
+
}
|
|
192
|
+
`)
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
it('should ignore empty attributes', () => {
|
|
196
|
+
const { editor } = setupTest()
|
|
197
|
+
|
|
198
|
+
const html = `<p><span data-text-color="" style="color: ;">This should be plain text</span></p>`
|
|
199
|
+
editor.setContent(html)
|
|
200
|
+
expect(editor.state.doc.firstChild?.firstChild?.toJSON()).toMatchInlineSnapshot(`
|
|
201
|
+
{
|
|
202
|
+
"text": "This should be plain text",
|
|
203
|
+
"type": "text",
|
|
204
|
+
}
|
|
205
|
+
`)
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
it('should ignore inherit attributes', () => {
|
|
209
|
+
const { editor } = setupTest()
|
|
210
|
+
|
|
211
|
+
const html = `<p><span data-text-color="inherit" style="color: inherit;">This should be plain text</span></p>`
|
|
212
|
+
editor.setContent(html)
|
|
213
|
+
expect(editor.state.doc.firstChild?.firstChild?.toJSON()).toMatchInlineSnapshot(`
|
|
214
|
+
{
|
|
215
|
+
"text": "This should be plain text",
|
|
216
|
+
"type": "text",
|
|
217
|
+
}
|
|
218
|
+
`)
|
|
219
|
+
})
|
|
220
|
+
|
|
221
|
+
it('can handle block elements', () => {
|
|
222
|
+
const { editor } = setupTest()
|
|
223
|
+
|
|
224
|
+
const html = `<blockquote style="color: red;">`
|
|
225
|
+
+ `<p>This should be red</p>`
|
|
226
|
+
+ `<blockquote style="color: blue;">`
|
|
227
|
+
+ `<p>This should be blue</p>`
|
|
228
|
+
+ `</blockquote>`
|
|
229
|
+
+ `<p>This should be red again</p>`
|
|
230
|
+
+ `</blockquote>`
|
|
231
|
+
|
|
232
|
+
editor.setContent(html)
|
|
233
|
+
expect(editor.state.doc.firstChild?.toJSON()).toMatchInlineSnapshot(`
|
|
234
|
+
{
|
|
235
|
+
"content": [
|
|
236
|
+
{
|
|
237
|
+
"content": [
|
|
238
|
+
{
|
|
239
|
+
"marks": [
|
|
240
|
+
{
|
|
241
|
+
"attrs": {
|
|
242
|
+
"color": "red",
|
|
243
|
+
},
|
|
244
|
+
"type": "textColor",
|
|
245
|
+
},
|
|
246
|
+
],
|
|
247
|
+
"text": "This should be red",
|
|
248
|
+
"type": "text",
|
|
249
|
+
},
|
|
250
|
+
],
|
|
251
|
+
"type": "paragraph",
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
"content": [
|
|
255
|
+
{
|
|
256
|
+
"content": [
|
|
257
|
+
{
|
|
258
|
+
"marks": [
|
|
259
|
+
{
|
|
260
|
+
"attrs": {
|
|
261
|
+
"color": "blue",
|
|
262
|
+
},
|
|
263
|
+
"type": "textColor",
|
|
264
|
+
},
|
|
265
|
+
],
|
|
266
|
+
"text": "This should be blue",
|
|
267
|
+
"type": "text",
|
|
268
|
+
},
|
|
269
|
+
],
|
|
270
|
+
"type": "paragraph",
|
|
271
|
+
},
|
|
272
|
+
],
|
|
273
|
+
"type": "blockquote",
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
"content": [
|
|
277
|
+
{
|
|
278
|
+
"marks": [
|
|
279
|
+
{
|
|
280
|
+
"attrs": {
|
|
281
|
+
"color": "red",
|
|
282
|
+
},
|
|
283
|
+
"type": "textColor",
|
|
284
|
+
},
|
|
285
|
+
],
|
|
286
|
+
"text": "This should be red again",
|
|
287
|
+
"type": "text",
|
|
288
|
+
},
|
|
289
|
+
],
|
|
290
|
+
"type": "paragraph",
|
|
291
|
+
},
|
|
292
|
+
],
|
|
293
|
+
"type": "blockquote",
|
|
294
|
+
}
|
|
295
|
+
`)
|
|
296
|
+
})
|
|
297
|
+
})
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { defineMarkSpec, type Extension } from '@prosekit/core'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Attributes for the `textColor` mark.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export interface TextColorAttrs {
|
|
9
|
+
color: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
export type TextColorSpecExtension = Extension<{
|
|
16
|
+
Marks: {
|
|
17
|
+
textColor: TextColorAttrs
|
|
18
|
+
}
|
|
19
|
+
}>
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export function defineTextColorSpec(): TextColorSpecExtension {
|
|
25
|
+
return defineMarkSpec<'textColor', TextColorAttrs>({
|
|
26
|
+
name: 'textColor',
|
|
27
|
+
attrs: {
|
|
28
|
+
color: {
|
|
29
|
+
validate: 'string',
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
parseDOM: [
|
|
33
|
+
{
|
|
34
|
+
tag: ':where([style*="color:"], [data-text-color])',
|
|
35
|
+
getAttrs: (node): TextColorAttrs | false => {
|
|
36
|
+
// When both `data-text-color` and `style="color"` are present, we
|
|
37
|
+
// prioritize the `data-text-color` attribute. This avoids the
|
|
38
|
+
// browser's default behavior of changing hex colors to rgba in style
|
|
39
|
+
// attribute.
|
|
40
|
+
const value = node.getAttribute('data-text-color')
|
|
41
|
+
if (value && value !== 'inherit') {
|
|
42
|
+
return { color: value }
|
|
43
|
+
}
|
|
44
|
+
const color = node.style.color
|
|
45
|
+
if (color && color !== 'inherit') {
|
|
46
|
+
return { color }
|
|
47
|
+
}
|
|
48
|
+
return false
|
|
49
|
+
},
|
|
50
|
+
consuming: false,
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
toDOM(mark) {
|
|
54
|
+
const color = (mark.attrs as TextColorAttrs).color
|
|
55
|
+
return ['span', { 'style': `color: ${color};`, 'data-text-color': color }, 0]
|
|
56
|
+
},
|
|
57
|
+
})
|
|
58
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { union, type Union } from '@prosekit/core'
|
|
2
|
+
|
|
3
|
+
import { defineTextColorCommands, type TextColorCommandsExtension } from './text-color-commands'
|
|
4
|
+
import { defineTextColorSpec, type TextColorSpecExtension } from './text-color-spec'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export type TextColorExtension = Union<[TextColorSpecExtension, TextColorCommandsExtension]>
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Defines the `textColor` mark and some commands for it.
|
|
13
|
+
*
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export function defineTextColor(): TextColorExtension {
|
|
17
|
+
return union(
|
|
18
|
+
defineTextColorSpec(),
|
|
19
|
+
defineTextColorCommands(),
|
|
20
|
+
)
|
|
21
|
+
}
|
|
@@ -1,17 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from '@prosekit/core'
|
|
5
|
-
import {
|
|
6
|
-
PluginKey,
|
|
7
|
-
ProseMirrorPlugin,
|
|
8
|
-
type EditorState,
|
|
9
|
-
type Transaction,
|
|
10
|
-
} from '@prosekit/pm/state'
|
|
11
|
-
import {
|
|
12
|
-
Decoration,
|
|
13
|
-
DecorationSet,
|
|
14
|
-
} from '@prosekit/pm/view'
|
|
1
|
+
import { definePlugin, type PlainExtension } from '@prosekit/core'
|
|
2
|
+
import { PluginKey, ProseMirrorPlugin, type EditorState, type Transaction } from '@prosekit/pm/state'
|
|
3
|
+
import { Decoration, DecorationSet } from '@prosekit/pm/view'
|
|
15
4
|
|
|
16
5
|
/**
|
|
17
6
|
* @internal
|
package/src/yjs/index.ts
CHANGED
|
@@ -1,22 +1,7 @@
|
|
|
1
|
-
export {
|
|
2
|
-
defineYjs,
|
|
3
|
-
type YjsExtension,
|
|
4
|
-
type YjsOptions,
|
|
5
|
-
} from './yjs'
|
|
1
|
+
export { defineYjs, type YjsExtension, type YjsOptions } from './yjs'
|
|
6
2
|
export { defineYjsCommands } from './yjs-commands'
|
|
7
|
-
export {
|
|
8
|
-
defineYjsCursorPlugin,
|
|
9
|
-
type YjsCursorOptions,
|
|
10
|
-
type YjsCursorPluginOptions,
|
|
11
|
-
} from './yjs-cursor-plugin'
|
|
3
|
+
export { defineYjsCursorPlugin, type YjsCursorOptions, type YjsCursorPluginOptions } from './yjs-cursor-plugin'
|
|
12
4
|
export { defineYjsKeymap } from './yjs-keymap'
|
|
13
|
-
export {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
type YjsSyncPluginOptions,
|
|
17
|
-
} from './yjs-sync-plugin'
|
|
18
|
-
export {
|
|
19
|
-
defineYjsUndoPlugin,
|
|
20
|
-
type YjsUndoOptions,
|
|
21
|
-
type YjsUndoPluginOptions,
|
|
22
|
-
} from './yjs-undo-plugin'
|
|
5
|
+
export { defineYjsSyncPlugin, type YjsSyncOptions, type YjsSyncPluginOptions } from './yjs-sync-plugin'
|
|
6
|
+
export type { Awareness } from './yjs-types'
|
|
7
|
+
export { defineYjsUndoPlugin, type YjsUndoOptions, type YjsUndoPluginOptions } from './yjs-undo-plugin'
|
package/src/yjs/yjs-commands.ts
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
type Extension,
|
|
4
|
-
} from '@prosekit/core'
|
|
5
|
-
import {
|
|
6
|
-
redoCommand,
|
|
7
|
-
undoCommand,
|
|
8
|
-
} from 'y-prosemirror'
|
|
1
|
+
import { defineCommands, type Extension } from '@prosekit/core'
|
|
2
|
+
import { redoCommand, undoCommand } from 'y-prosemirror'
|
|
9
3
|
|
|
10
4
|
const commands = {
|
|
11
5
|
undo: () => undoCommand,
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
definePlugin,
|
|
3
|
-
type PlainExtension,
|
|
4
|
-
} from '@prosekit/core'
|
|
1
|
+
import { definePlugin, type PlainExtension } from '@prosekit/core'
|
|
5
2
|
import type { Plugin } from '@prosekit/pm/state'
|
|
6
3
|
import { yCursorPlugin } from 'y-prosemirror'
|
|
7
|
-
|
|
4
|
+
|
|
5
|
+
import type { Awareness } from './yjs-types'
|
|
8
6
|
|
|
9
7
|
/**
|
|
10
8
|
* Options for `y-prosemirror`'s `yCursorPlugin`.
|
package/src/yjs/yjs-keymap.ts
CHANGED
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
isApple,
|
|
4
|
-
type Keymap,
|
|
5
|
-
type PlainExtension,
|
|
6
|
-
} from '@prosekit/core'
|
|
7
|
-
import {
|
|
8
|
-
redoCommand,
|
|
9
|
-
undoCommand,
|
|
10
|
-
} from 'y-prosemirror'
|
|
1
|
+
import { defineKeymap, isApple, type Keymap, type PlainExtension } from '@prosekit/core'
|
|
2
|
+
import { redoCommand, undoCommand } from 'y-prosemirror'
|
|
11
3
|
|
|
12
4
|
const keymap: Keymap = {
|
|
13
5
|
'Mod-z': undoCommand,
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
definePlugin,
|
|
3
|
-
type PlainExtension,
|
|
4
|
-
} from '@prosekit/core'
|
|
1
|
+
import { definePlugin, type PlainExtension } from '@prosekit/core'
|
|
5
2
|
import type { Plugin } from '@prosekit/pm/state'
|
|
6
3
|
import { ySyncPlugin } from 'y-prosemirror'
|
|
7
4
|
import type * as Y from 'yjs'
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
definePlugin,
|
|
3
|
-
type PlainExtension,
|
|
4
|
-
} from '@prosekit/core'
|
|
1
|
+
import { definePlugin, type PlainExtension } from '@prosekit/core'
|
|
5
2
|
import type { ProseMirrorPlugin } from '@prosekit/pm/state'
|
|
6
3
|
import type { EditorView } from '@prosekit/pm/view'
|
|
7
|
-
import {
|
|
8
|
-
yUndoPlugin as originalYUndoPlugin,
|
|
9
|
-
yUndoPluginKey,
|
|
10
|
-
} from 'y-prosemirror'
|
|
4
|
+
import { yUndoPlugin as originalYUndoPlugin, yUndoPluginKey } from 'y-prosemirror'
|
|
11
5
|
import type { UndoManager as YjsUndoManager } from 'yjs'
|
|
12
6
|
|
|
13
7
|
type UndoManager = YjsUndoManager & { restore: () => void }
|
package/src/yjs/yjs.ts
CHANGED
|
@@ -1,30 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Priority,
|
|
3
|
-
union,
|
|
4
|
-
withPriority,
|
|
5
|
-
type PlainExtension,
|
|
6
|
-
type Union,
|
|
7
|
-
} from '@prosekit/core'
|
|
8
|
-
import type { Awareness } from 'y-protocols/awareness'
|
|
1
|
+
import { Priority, union, withPriority, type PlainExtension, type Union } from '@prosekit/core'
|
|
9
2
|
import type * as Y from 'yjs'
|
|
10
3
|
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
type YjsCommandsExtension,
|
|
14
|
-
} from './yjs-commands'
|
|
15
|
-
import {
|
|
16
|
-
defineYjsCursorPlugin,
|
|
17
|
-
type YjsCursorPluginOptions,
|
|
18
|
-
} from './yjs-cursor-plugin'
|
|
4
|
+
import { defineYjsCommands, type YjsCommandsExtension } from './yjs-commands'
|
|
5
|
+
import { defineYjsCursorPlugin, type YjsCursorPluginOptions } from './yjs-cursor-plugin'
|
|
19
6
|
import { defineYjsKeymap } from './yjs-keymap'
|
|
20
|
-
import {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
} from './yjs-sync-plugin'
|
|
24
|
-
import {
|
|
25
|
-
defineYjsUndoPlugin,
|
|
26
|
-
type YjsUndoPluginOptions,
|
|
27
|
-
} from './yjs-undo-plugin'
|
|
7
|
+
import { defineYjsSyncPlugin, type YjsSyncPluginOptions } from './yjs-sync-plugin'
|
|
8
|
+
import type { Awareness } from './yjs-types'
|
|
9
|
+
import { defineYjsUndoPlugin, type YjsUndoPluginOptions } from './yjs-undo-plugin'
|
|
28
10
|
|
|
29
11
|
export interface YjsOptions {
|
|
30
12
|
/**
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"drop-indicator-B1QHFb5m.js","names":["showHandler: ShowHandler","hideHandler: VoidFunction","dragHandler: DragEventHandler"],"sources":["../src/drop-indicator/drop-indicator-facet.ts","../src/drop-indicator/drop-indicator.ts"],"sourcesContent":["import {\n defineFacet,\n defineFacetPayload,\n pluginFacet,\n type PlainExtension,\n type PluginPayload,\n} from '@prosekit/core'\nimport type {\n DragEventHandler,\n DropIndicatorPluginOptions,\n ShowHandler,\n} from 'prosemirror-drop-indicator'\nimport { createDropIndicatorPlugin } from 'prosemirror-drop-indicator'\n\n/**\n * @internal\n */\nexport function defineDropIndicatorPayload(\n payload: DropIndicatorPluginOptions,\n): PlainExtension {\n return defineFacetPayload(dropIndicatorFacet, [payload]) as PlainExtension\n}\n\nconst dropIndicatorFacet = defineFacet<DropIndicatorPluginOptions, PluginPayload>({\n parent: pluginFacet,\n singleton: true,\n reducer: (payloads: DropIndicatorPluginOptions[]): PluginPayload => {\n let showHandlers = payloads.map(p => p.onShow).filter(x => !!x)\n let hideHandlers = payloads.map(p => p.onHide).filter(x => !!x)\n let dragHandlers = payloads.map(p => p.onDrag).filter(x => !!x)\n\n let showHandler: ShowHandler = (options) => {\n for (let fn of showHandlers) {\n fn(options)\n }\n }\n\n let hideHandler: VoidFunction = () => {\n for (let fn of hideHandlers) {\n fn()\n }\n }\n\n let dragHandler: DragEventHandler = (options): boolean => {\n for (let fn of dragHandlers) {\n if (fn(options) === false) return false\n }\n return true\n }\n\n if (showHandlers.length === 0) {\n // No `onShow` event handler, so we don't need to create a plugin.\n return []\n }\n\n return createDropIndicatorPlugin({\n onDrag: dragHandler,\n onShow: showHandler,\n onHide: hideHandler,\n })\n },\n})\n","import type { PlainExtension } from '@prosekit/core'\nimport type { DropIndicatorPluginOptions } from 'prosemirror-drop-indicator'\n\nimport { defineDropIndicatorPayload } from './drop-indicator-facet'\n\n/**\n * @internal\n */\nexport type DropIndicatorExtension = PlainExtension\n\n/**\n * Defines an extension that controls the behavior of the drop indicator.\n *\n * This extension itself doesn't draw the drop indicator, but it provides the\n * necessary callbacks to do so. You probably don't want to use this extension\n * directly, but rather use the `<DropIndicator>` component.\n *\n * You can add this extension multiple times. If any extension has `onDrag`\n * callback defined, and it returns `false`, then the drop point will be\n * discarded.\n *\n * @public\n */\nexport function defineDropIndicator(\n options?: DropIndicatorOptions,\n): DropIndicatorExtension {\n return defineDropIndicatorPayload(options ?? {})\n}\n\n/**\n * Options for {@link defineDropIndicator}.\n *\n * @public\n */\nexport interface DropIndicatorOptions extends DropIndicatorPluginOptions {}\n"],"mappings":";;;;;;;AAiBA,SAAgB,2BACd,SACgB;AAChB,QAAO,mBAAmB,oBAAoB,CAAC,QAAQ,CAAC;;AAG1D,MAAM,qBAAqB,YAAuD;CAChF,QAAQ;CACR,WAAW;CACX,UAAU,aAA0D;EAClE,IAAI,eAAe,SAAS,KAAI,MAAK,EAAE,OAAO,CAAC,QAAO,MAAK,CAAC,CAAC,EAAE;EAC/D,IAAI,eAAe,SAAS,KAAI,MAAK,EAAE,OAAO,CAAC,QAAO,MAAK,CAAC,CAAC,EAAE;EAC/D,IAAI,eAAe,SAAS,KAAI,MAAK,EAAE,OAAO,CAAC,QAAO,MAAK,CAAC,CAAC,EAAE;EAE/D,IAAIA,eAA4B,YAAY;AAC1C,QAAK,IAAI,MAAM,aACb,IAAG,QAAQ;;EAIf,IAAIC,oBAAkC;AACpC,QAAK,IAAI,MAAM,aACb,KAAI;;EAIR,IAAIC,eAAiC,YAAqB;AACxD,QAAK,IAAI,MAAM,aACb,KAAI,GAAG,QAAQ,KAAK,MAAO,QAAO;AAEpC,UAAO;;AAGT,MAAI,aAAa,WAAW,EAE1B,QAAO,EAAE;AAGX,SAAO,0BAA0B;GAC/B,QAAQ;GACR,QAAQ;GACR,QAAQ;GACT,CAAC;;CAEL,CAAC;;;;;;;;;;;;;;;;;ACtCF,SAAgB,oBACd,SACwB;AACxB,QAAO,2BAA2B,WAAW,EAAE,CAAC"}
|