@prosekit/extensions 0.14.0 → 0.14.2
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-B_oMfeVP.js → drop-indicator-DJq8pF92.js} +1 -1
- package/dist/{drop-indicator-B_oMfeVP.js.map → drop-indicator-DJq8pF92.js.map} +1 -1
- package/dist/{file-iLVR0eM0.js → file-upload-I9m1EJAM.js} +1 -1
- package/dist/file-upload-I9m1EJAM.js.map +1 -0
- package/dist/{index-cp1u4e0e.d.ts → file-upload-dr3IXUty.d.ts} +1 -1
- package/dist/file-upload-dr3IXUty.d.ts.map +1 -0
- package/dist/{paste-rule-BaDghcaU.js → mark-paste-rule--F1QPUcU.js} +2 -2
- package/dist/mark-paste-rule--F1QPUcU.js.map +1 -0
- package/dist/{mark-rule-CYe8zk4q.js → mark-rule-Bqdm49Eq.js} +2 -2
- package/dist/mark-rule-Bqdm49Eq.js.map +1 -0
- package/dist/prosekit-extensions-autocomplete.d.ts +1 -1
- package/dist/prosekit-extensions-autocomplete.js +17 -17
- package/dist/prosekit-extensions-autocomplete.js.map +1 -1
- package/dist/prosekit-extensions-background-color.d.ts +1 -1
- package/dist/prosekit-extensions-background-color.js.map +1 -1
- package/dist/prosekit-extensions-blockquote.d.ts +13 -13
- package/dist/prosekit-extensions-blockquote.d.ts.map +1 -1
- package/dist/prosekit-extensions-blockquote.js +6 -5
- package/dist/prosekit-extensions-blockquote.js.map +1 -1
- package/dist/prosekit-extensions-bold.d.ts +12 -12
- 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 +53 -36
- package/dist/prosekit-extensions-code-block.d.ts.map +1 -1
- package/dist/prosekit-extensions-code-block.js +78 -72
- package/dist/prosekit-extensions-code-block.js.map +1 -1
- package/dist/prosekit-extensions-code.d.ts +12 -12
- 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 +1 -1
- package/dist/prosekit-extensions-commit.js +1 -1
- package/dist/prosekit-extensions-drop-indicator.js +1 -1
- package/dist/prosekit-extensions-enter-rule.d.ts +6 -78
- 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-hard-break.d.ts +7 -7
- 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 +15 -15
- 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 +7 -7
- package/dist/prosekit-extensions-horizontal-rule.d.ts.map +1 -1
- package/dist/prosekit-extensions-horizontal-rule.js +11 -10
- package/dist/prosekit-extensions-horizontal-rule.js.map +1 -1
- package/dist/prosekit-extensions-image.d.ts +13 -12
- package/dist/prosekit-extensions-image.d.ts.map +1 -1
- package/dist/prosekit-extensions-image.js +10 -10
- package/dist/prosekit-extensions-image.js.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 +12 -12
- 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.js +4 -4
- package/dist/prosekit-extensions-link.js.map +1 -1
- package/dist/prosekit-extensions-list.d.ts +26 -26
- package/dist/prosekit-extensions-list.d.ts.map +1 -1
- package/dist/prosekit-extensions-list.js +27 -27
- package/dist/prosekit-extensions-list.js.map +1 -1
- package/dist/prosekit-extensions-loro.d.ts +16 -16
- package/dist/prosekit-extensions-loro.d.ts.map +1 -1
- package/dist/prosekit-extensions-loro.js.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 +108 -0
- package/dist/prosekit-extensions-math.js.map +1 -0
- package/dist/prosekit-extensions-mod-click-prevention.js +1 -1
- package/dist/prosekit-extensions-paragraph.d.ts +7 -7
- 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.js +1 -1
- package/dist/prosekit-extensions-placeholder.d.ts +1 -1
- package/dist/prosekit-extensions-placeholder.js +2 -2
- package/dist/prosekit-extensions-placeholder.js.map +1 -1
- package/dist/prosekit-extensions-readonly.js +1 -1
- package/dist/prosekit-extensions-strike.js +1 -1
- package/dist/prosekit-extensions-strike.js.map +1 -1
- package/dist/prosekit-extensions-table.d.ts +47 -47
- 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 +1 -1
- package/dist/prosekit-extensions-text-color.d.ts +1 -1
- package/dist/prosekit-extensions-text-color.js.map +1 -1
- package/dist/prosekit-extensions-virtual-selection.js +1 -1
- package/dist/prosekit-extensions-yjs.d.ts +3 -3
- 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/{table-4oHfV-Ql.js → table-B81i9oH9.js} +29 -29
- package/dist/table-B81i9oH9.js.map +1 -0
- package/package.json +22 -10
- package/src/autocomplete/autocomplete-helpers.ts +1 -1
- package/src/autocomplete/autocomplete-plugin.ts +2 -2
- package/src/autocomplete/autocomplete-rule.ts +1 -1
- package/src/autocomplete/autocomplete.spec.ts +4 -4
- package/src/autocomplete/autocomplete.ts +2 -2
- package/src/autocomplete/index.ts +2 -2
- package/src/background-color/background-color-commands.spec.ts +1 -1
- package/src/background-color/background-color-commands.ts +1 -1
- package/src/background-color/background-color-spec.spec.ts +1 -1
- package/src/background-color/background-color.ts +2 -2
- package/src/background-color/index.ts +3 -3
- package/src/blockquote/blockquote-input-rule.ts +1 -1
- package/src/blockquote/blockquote-keymap.spec.ts +1 -1
- package/src/blockquote/blockquote-keymap.ts +9 -7
- package/src/blockquote/blockquote.ts +4 -4
- package/src/blockquote/index.ts +5 -5
- package/src/bold/bold-input-rule.spec.ts +2 -2
- package/src/bold/bold-input-rule.ts +1 -1
- package/src/bold/bold.ts +4 -4
- package/src/bold/index.ts +5 -5
- package/src/code/code-input-rule.ts +1 -1
- package/src/code/code.ts +4 -4
- package/src/code/index.ts +5 -5
- package/src/code-block/code-block-commands.ts +1 -1
- package/src/code-block/code-block-highlight.ts +11 -1
- package/src/code-block/code-block-input-rule.ts +3 -3
- package/src/code-block/code-block-shiki.ts +13 -5
- package/src/code-block/code-block-spec.spec.ts +2 -2
- package/src/code-block/code-block-spec.ts +1 -1
- package/src/code-block/code-block.ts +4 -4
- package/src/code-block/index.ts +9 -9
- package/src/code-block/shiki-highlighter.ts +2 -2
- package/src/code-block/shiki-parser.ts +2 -2
- package/src/drop-cursor/index.ts +1 -1
- package/src/drop-indicator/drop-indicator.ts +1 -1
- package/src/drop-indicator/index.ts +1 -1
- package/src/enter-rule/index.ts +18 -191
- package/src/file/file-drop-handler.ts +1 -1
- package/src/file/file-paste-handler.spec.ts +3 -3
- package/src/file/file-paste-handler.ts +1 -1
- package/src/file/index.ts +3 -3
- package/src/gap-cursor/index.ts +1 -1
- package/src/hard-break/hard-break-keymap.spec.ts +2 -2
- package/src/hard-break/hard-break-keymap.ts +1 -1
- package/src/hard-break/hard-break.ts +3 -3
- package/src/hard-break/index.ts +4 -4
- package/src/heading/heading-commands.ts +1 -1
- package/src/heading/heading-input-rule.ts +2 -2
- package/src/heading/heading-keymap.spec.ts +1 -1
- package/src/heading/heading-spec.ts +1 -1
- package/src/heading/heading.ts +4 -4
- package/src/heading/index.ts +6 -6
- package/src/horizontal-rule/horizontal-rule-commands.spec.ts +1 -1
- package/src/horizontal-rule/horizontal-rule-commands.ts +13 -11
- package/src/horizontal-rule/horizontal-rule-input-rule.spec.ts +2 -2
- package/src/horizontal-rule/horizontal-rule-input-rule.ts +1 -1
- package/src/horizontal-rule/horizontal-rule.ts +3 -3
- package/src/horizontal-rule/index.ts +4 -4
- package/src/image/image-commands/insert-image.ts +1 -1
- package/src/image/image-commands/upload-image.spec.ts +4 -4
- package/src/image/image-commands/upload-image.ts +2 -2
- package/src/image/image-commands.ts +3 -3
- package/src/image/image-upload-handler.ts +2 -2
- package/src/image/image.ts +2 -2
- package/src/image/index.ts +6 -6
- package/src/italic/index.ts +5 -5
- package/src/italic/italic-commands.spec.ts +4 -4
- package/src/italic/italic-input-rule.spec.ts +2 -2
- package/src/italic/italic-input-rule.ts +1 -1
- package/src/italic/italic.ts +4 -4
- package/src/link/index.spec.ts +2 -2
- package/src/link/index.ts +6 -6
- package/src/link/link-paste-rule.spec.ts +2 -2
- package/src/link/link-paste-rule.ts +3 -3
- package/src/link/link-regex.spec.ts +1 -1
- package/src/list/index.ts +8 -8
- package/src/list/list-drop-indicator.ts +2 -2
- package/src/list/list-input-rules.ts +1 -1
- package/src/list/list-keymap.spec.ts +1 -1
- package/src/list/list-spec.ts +1 -1
- package/src/list/list-types.spec.ts +2 -2
- package/src/list/list.spec.ts +6 -6
- package/src/list/list.ts +7 -7
- package/src/loro/index.ts +6 -6
- package/src/loro/loro.ts +5 -5
- package/src/mark-rule/apply.ts +2 -2
- package/src/mark-rule/index.ts +2 -2
- package/src/mark-rule/mark-rule.spec.ts +4 -4
- package/src/mark-rule/mark-rule.ts +2 -2
- package/src/math/index.ts +22 -0
- package/src/math/math-block.ts +96 -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/paragraph/index.ts +7 -7
- package/src/paragraph/paragraph-keymap.ts +1 -1
- package/src/paragraph/paragraph.ts +3 -3
- package/src/paste-rule/index.ts +2 -2
- package/src/paste-rule/mark-paste-rule.spec.ts +8 -8
- package/src/paste-rule/mark-paste-rule.ts +2 -2
- package/src/paste-rule/paste-rule.spec.ts +2 -2
- package/src/paste-rule/paste-rule.ts +1 -1
- package/src/paste-rule/split-text-by-regex.spec.ts +1 -1
- package/src/placeholder/index.ts +1 -1
- package/src/strike/index.ts +1 -1
- package/src/table/index.ts +14 -14
- package/src/table/table-commands/delete-cell-selection.spec.ts +3 -3
- package/src/table/table-commands/exit-table.spec.ts +2 -2
- package/src/table/table-commands/insert-table.spec.ts +1 -1
- package/src/table/table-commands/move-table-column.spec.ts +2 -2
- package/src/table/table-commands/move-table-row.spec.ts +2 -2
- package/src/table/table-commands/select-table-cell.spec.ts +3 -3
- package/src/table/table-commands/select-table-cell.ts +1 -1
- package/src/table/table-commands/select-table-column.spec.ts +2 -2
- package/src/table/table-commands/select-table-column.ts +1 -1
- package/src/table/table-commands/select-table-row.spec.ts +2 -2
- package/src/table/table-commands/select-table-row.ts +1 -1
- package/src/table/table-commands/select-table.spec.ts +2 -2
- package/src/table/table-commands/select-table.ts +1 -1
- package/src/table/table-commands.ts +9 -9
- package/src/table/table-drop-indicator.ts +2 -2
- package/src/table/table-spec.spec.ts +4 -4
- package/src/table/table.ts +4 -4
- package/src/table/test-utils.ts +1 -1
- package/src/testing/index.ts +25 -22
- package/src/testing/katex.ts +9 -0
- package/src/text-color/index.ts +3 -3
- package/src/text-color/text-color-commands.spec.ts +1 -1
- package/src/text-color/text-color-commands.ts +1 -1
- package/src/text-color/text-color-spec.spec.ts +1 -1
- package/src/text-color/text-color.ts +2 -2
- package/src/yjs/index.ts +7 -7
- package/src/yjs/yjs-cursor-plugin.ts +1 -1
- package/src/yjs/yjs-types.ts +0 -2
- package/src/yjs/yjs-undo-plugin.ts +3 -2
- package/src/yjs/yjs.ts +6 -6
- package/dist/enter-rule-D-p4ykfv.js +0 -96
- package/dist/enter-rule-D-p4ykfv.js.map +0 -1
- package/dist/file-iLVR0eM0.js.map +0 -1
- package/dist/index-cp1u4e0e.d.ts.map +0 -1
- package/dist/input-rule-COGr_GBb.js +0 -90
- package/dist/input-rule-COGr_GBb.js.map +0 -1
- package/dist/mark-rule-CYe8zk4q.js.map +0 -1
- package/dist/paste-rule-BaDghcaU.js.map +0 -1
- package/dist/shiki-highlighter-chunk-DNNm2Vow.d.ts +0 -19
- package/dist/shiki-highlighter-chunk-DNNm2Vow.d.ts.map +0 -1
- package/dist/table-4oHfV-Ql.js.map +0 -1
package/src/enter-rule/index.ts
CHANGED
|
@@ -1,104 +1,28 @@
|
|
|
1
|
+
import { defineFacet, defineFacetPayload, pluginFacet, type PlainExtension, type PluginPayload } from '@prosekit/core'
|
|
1
2
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
type PlainExtension,
|
|
10
|
-
type PluginPayload,
|
|
11
|
-
} from '@prosekit/core'
|
|
12
|
-
import { keydownHandler } from '@prosekit/pm/keymap'
|
|
13
|
-
import type { Attrs, NodeType } from '@prosekit/pm/model'
|
|
14
|
-
import { PluginKey, ProseMirrorPlugin, type Command, type EditorState, type Transaction } from '@prosekit/pm/state'
|
|
15
|
-
import type { EditorView } from '@prosekit/pm/view'
|
|
3
|
+
createEnterRulePlugin,
|
|
4
|
+
createTextBlockEnterRule,
|
|
5
|
+
type EnterRule,
|
|
6
|
+
type EnterRuleHandler,
|
|
7
|
+
type EnterRuleHandlerOptions,
|
|
8
|
+
type TextBlockEnterRuleOptions as TextBlockEnterRuleOptionsBase,
|
|
9
|
+
} from 'prosemirror-enter-rules'
|
|
16
10
|
|
|
17
|
-
|
|
18
|
-
* @public
|
|
19
|
-
*
|
|
20
|
-
* Options for {@link EnterRuleHandler}.
|
|
21
|
-
*/
|
|
22
|
-
export interface EnterRuleHandlerOptions {
|
|
23
|
-
/**
|
|
24
|
-
* The current editor state.
|
|
25
|
-
*/
|
|
26
|
-
state: EditorState
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* The start position of the matched text.
|
|
30
|
-
*/
|
|
31
|
-
from: number
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* The end position of the matched text.
|
|
35
|
-
*/
|
|
36
|
-
to: number
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* The matched result from the regular expression.
|
|
40
|
-
*/
|
|
41
|
-
match: RegExpExecArray
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* @public
|
|
46
|
-
*/
|
|
47
|
-
export type EnterRuleHandler = (options: EnterRuleHandlerOptions) => Transaction | null
|
|
11
|
+
export type { EnterRuleHandler, EnterRuleHandlerOptions }
|
|
48
12
|
|
|
49
13
|
/**
|
|
50
14
|
* Options for {@link defineEnterRule}.
|
|
51
15
|
*
|
|
52
16
|
* @public
|
|
53
17
|
*/
|
|
54
|
-
export
|
|
55
|
-
/**
|
|
56
|
-
* The regular expression to match against. It should end with `$`.
|
|
57
|
-
*/
|
|
58
|
-
regex: RegExp
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* A function to be called when an enter rule is triggered.
|
|
62
|
-
*/
|
|
63
|
-
handler: EnterRuleHandler
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Whether to stop further handlers from being called if this rule is triggered.
|
|
67
|
-
*
|
|
68
|
-
* @default false
|
|
69
|
-
*/
|
|
70
|
-
stop?: boolean
|
|
71
|
-
}
|
|
18
|
+
export interface EnterRuleOptions extends EnterRule {}
|
|
72
19
|
|
|
73
20
|
/**
|
|
74
21
|
* Options for {@link defineTextBlockEnterRule}.
|
|
75
22
|
*
|
|
76
23
|
* @public
|
|
77
24
|
*/
|
|
78
|
-
export interface TextBlockEnterRuleOptions {
|
|
79
|
-
/**
|
|
80
|
-
* The regular expression to match against. It should end with `$`.
|
|
81
|
-
*/
|
|
82
|
-
regex: RegExp
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* The node type to replace the matched text with.
|
|
86
|
-
*/
|
|
87
|
-
type: string | NodeType
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Attributes to set on the node. If a function is provided, it will be called
|
|
91
|
-
* with the matched result from the regular expression.
|
|
92
|
-
*/
|
|
93
|
-
attrs?: Attrs | null | ((match: RegExpMatchArray) => Attrs | null)
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Whether to stop further handlers from being called if this rule is triggered.
|
|
97
|
-
*
|
|
98
|
-
* @default true
|
|
99
|
-
*/
|
|
100
|
-
stop?: boolean
|
|
101
|
-
}
|
|
25
|
+
export interface TextBlockEnterRuleOptions extends TextBlockEnterRuleOptionsBase {}
|
|
102
26
|
|
|
103
27
|
/**
|
|
104
28
|
* Defines an enter rule. An enter rule applies when the text directly in front of
|
|
@@ -109,13 +33,8 @@ export interface TextBlockEnterRuleOptions {
|
|
|
109
33
|
*
|
|
110
34
|
* @public
|
|
111
35
|
*/
|
|
112
|
-
export function defineEnterRule({
|
|
113
|
-
|
|
114
|
-
handler,
|
|
115
|
-
stop = false,
|
|
116
|
-
}: EnterRuleOptions): PlainExtension {
|
|
117
|
-
const rule: EnterRule = new EnterRule(regex, handler, stop)
|
|
118
|
-
return defineFacetPayload(enterRule, [rule]) as PlainExtension
|
|
36
|
+
export function defineEnterRule(options: EnterRuleOptions): PlainExtension {
|
|
37
|
+
return defineFacetPayload(enterRuleFacet, [options]) as PlainExtension
|
|
119
38
|
}
|
|
120
39
|
|
|
121
40
|
/**
|
|
@@ -127,106 +46,14 @@ export function defineEnterRule({
|
|
|
127
46
|
*
|
|
128
47
|
* @public
|
|
129
48
|
*/
|
|
130
|
-
export function defineTextBlockEnterRule({
|
|
131
|
-
|
|
132
|
-
type,
|
|
133
|
-
attrs,
|
|
134
|
-
stop = true,
|
|
135
|
-
}: TextBlockEnterRuleOptions): PlainExtension {
|
|
136
|
-
return defineEnterRule({
|
|
137
|
-
regex,
|
|
138
|
-
handler: ({ state, from, to, match }) => {
|
|
139
|
-
const nodeType = getNodeType(state.schema, type)
|
|
140
|
-
const $start = state.doc.resolve(from)
|
|
141
|
-
|
|
142
|
-
if (
|
|
143
|
-
!$start
|
|
144
|
-
.node(-1)
|
|
145
|
-
.canReplaceWith($start.index(-1), $start.indexAfter(-1), nodeType)
|
|
146
|
-
) {
|
|
147
|
-
return null
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
const nodeAttrs = maybeRun(attrs, match)
|
|
151
|
-
return state.tr
|
|
152
|
-
.delete(from, to)
|
|
153
|
-
.setBlockType(from, from, nodeType, nodeAttrs)
|
|
154
|
-
},
|
|
155
|
-
stop,
|
|
156
|
-
})
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* @internal
|
|
161
|
-
*/
|
|
162
|
-
class EnterRule {
|
|
163
|
-
constructor(
|
|
164
|
-
readonly regex: RegExp,
|
|
165
|
-
readonly handler: EnterRuleHandler,
|
|
166
|
-
readonly stop: boolean,
|
|
167
|
-
) {}
|
|
49
|
+
export function defineTextBlockEnterRule(options: TextBlockEnterRuleOptions): PlainExtension {
|
|
50
|
+
return defineEnterRule(createTextBlockEnterRule(options))
|
|
168
51
|
}
|
|
169
52
|
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
const command: Command = (state, dispatch, view) => {
|
|
175
|
-
if (!view) return false
|
|
176
|
-
return execRules(view, rules, dispatch)
|
|
177
|
-
}
|
|
178
|
-
const handler = keydownHandler({ Enter: command })
|
|
179
|
-
const plugin = new ProseMirrorPlugin({
|
|
180
|
-
key: new PluginKey('prosekit-enter-rule'),
|
|
181
|
-
props: { handleKeyDown: handler },
|
|
182
|
-
})
|
|
183
|
-
|
|
184
|
-
return function reducer(inputs) {
|
|
185
|
-
rules = inputs
|
|
186
|
-
return plugin
|
|
187
|
-
}
|
|
53
|
+
const enterRuleFacet = defineFacet<EnterRule, PluginPayload>({
|
|
54
|
+
reducer: (rules: EnterRule[]): PluginPayload => {
|
|
55
|
+
return createEnterRulePlugin({ rules })
|
|
188
56
|
},
|
|
189
57
|
|
|
190
58
|
parent: pluginFacet,
|
|
191
59
|
})
|
|
192
|
-
|
|
193
|
-
function execRules(
|
|
194
|
-
view: EditorView,
|
|
195
|
-
rules: readonly EnterRule[],
|
|
196
|
-
dispatch?: (tr: Transaction) => void,
|
|
197
|
-
): boolean {
|
|
198
|
-
if (view.composing) return false
|
|
199
|
-
const state = view.state
|
|
200
|
-
const selection = state.selection
|
|
201
|
-
if (!isTextSelection(selection)) return false
|
|
202
|
-
const $cursor = selection.$cursor
|
|
203
|
-
if (!$cursor || $cursor.parent.type.spec.code) return false
|
|
204
|
-
|
|
205
|
-
const textBefore = $cursor.parent.textBetween(
|
|
206
|
-
Math.max(0, $cursor.parentOffset - MAX_MATCH),
|
|
207
|
-
$cursor.parentOffset,
|
|
208
|
-
null,
|
|
209
|
-
OBJECT_REPLACEMENT_CHARACTER,
|
|
210
|
-
)
|
|
211
|
-
|
|
212
|
-
for (const rule of rules) {
|
|
213
|
-
rule.regex.lastIndex = 0
|
|
214
|
-
const match = rule.regex.exec(textBefore)
|
|
215
|
-
const tr = match
|
|
216
|
-
&& rule.handler({
|
|
217
|
-
state,
|
|
218
|
-
from: $cursor.pos - match[0].length,
|
|
219
|
-
to: $cursor.pos,
|
|
220
|
-
match,
|
|
221
|
-
})
|
|
222
|
-
if (!tr) continue
|
|
223
|
-
dispatch?.(tr)
|
|
224
|
-
|
|
225
|
-
if (rule.stop) {
|
|
226
|
-
return true
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
return false
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
const MAX_MATCH = 200
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Priority, union, withPriority } from '@prosekit/core'
|
|
2
2
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { pasteFiles } from '../testing/clipboard.ts'
|
|
5
|
+
import { defineTestExtension, setupTestFromExtension } from '../testing/index.ts'
|
|
6
6
|
|
|
7
|
-
import { defineFilePasteHandler } from './file-paste-handler'
|
|
7
|
+
import { defineFilePasteHandler } from './file-paste-handler.ts'
|
|
8
8
|
|
|
9
9
|
function definePngPasteHandler(handler: VoidFunction) {
|
|
10
10
|
const extension = defineFilePasteHandler((options) => {
|
package/src/file/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { defineFileDropHandler, type FileDropHandler, type FileDropHandlerOptions } from './file-drop-handler'
|
|
2
|
-
export { defineFilePasteHandler, type FilePasteHandler, type FilePasteHandlerOptions } from './file-paste-handler'
|
|
3
|
-
export { UploadTask, type Uploader, type UploaderOptions, type UploadProgress } from './file-upload'
|
|
1
|
+
export { defineFileDropHandler, type FileDropHandler, type FileDropHandlerOptions } from './file-drop-handler.ts'
|
|
2
|
+
export { defineFilePasteHandler, type FilePasteHandler, type FilePasteHandlerOptions } from './file-paste-handler.ts'
|
|
3
|
+
export { UploadTask, type Uploader, type UploaderOptions, type UploadProgress } from './file-upload.ts'
|
package/src/gap-cursor/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { defineGapCursor, type GapCursorExtension } from './gap-cursor'
|
|
1
|
+
export { defineGapCursor, type GapCursorExtension } from './gap-cursor.ts'
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest'
|
|
2
2
|
import { keyboard } from 'vitest-browser-commands/playwright'
|
|
3
3
|
|
|
4
|
-
import { setupTest } from '../testing'
|
|
5
|
-
import { inputText } from '../testing/keyboard'
|
|
4
|
+
import { setupTest } from '../testing/index.ts'
|
|
5
|
+
import { inputText } from '../testing/keyboard.ts'
|
|
6
6
|
|
|
7
7
|
describe('defineHardBreakKeymap', () => {
|
|
8
8
|
it('should insert hard break', async () => {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { union, type Union } from '@prosekit/core'
|
|
2
2
|
|
|
3
|
-
import { defineHardBreakCommands, type HardBreakCommandsExtension } from './hard-break-commands'
|
|
4
|
-
import { defineHardBreakKeymap } from './hard-break-keymap'
|
|
5
|
-
import { defineHardBreakSpec, type HardBreakSpecExtension } from './hard-break-spec'
|
|
3
|
+
import { defineHardBreakCommands, type HardBreakCommandsExtension } from './hard-break-commands.ts'
|
|
4
|
+
import { defineHardBreakKeymap } from './hard-break-keymap.ts'
|
|
5
|
+
import { defineHardBreakSpec, type HardBreakSpecExtension } from './hard-break-spec.ts'
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @internal
|
package/src/hard-break/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
1
|
+
export { defineHardBreakCommands, type HardBreakCommandsExtension } from './hard-break-commands.ts'
|
|
2
|
+
export { defineHardBreakKeymap } from './hard-break-keymap.ts'
|
|
3
|
+
export { defineHardBreakSpec, type HardBreakSpecExtension } from './hard-break-spec.ts'
|
|
4
|
+
export { defineHardBreak, type HardBreakExtension } from './hard-break.ts'
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { PlainExtension } from '@prosekit/core'
|
|
2
2
|
|
|
3
|
-
import { defineTextBlockInputRule } from '../input-rule'
|
|
3
|
+
import { defineTextBlockInputRule } from '../input-rule/index.ts'
|
|
4
4
|
|
|
5
|
-
import type { HeadingAttrs } from './heading-types'
|
|
5
|
+
import type { HeadingAttrs } from './heading-types.ts'
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Converts the text block to a heading when `#` is typed at the start of a new
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest'
|
|
2
2
|
import { keyboard } from 'vitest-browser-commands/playwright'
|
|
3
3
|
|
|
4
|
-
import { setupTest } from '../testing'
|
|
4
|
+
import { setupTest } from '../testing/index.ts'
|
|
5
5
|
|
|
6
6
|
describe('defineHeadingKeymap', () => {
|
|
7
7
|
it('should toggle heading', async () => {
|
package/src/heading/heading.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { union, type Union } from '@prosekit/core'
|
|
2
2
|
|
|
3
|
-
import { defineHeadingCommands, type HeadingCommandsExtension } from './heading-commands'
|
|
4
|
-
import { defineHeadingInputRule } from './heading-input-rule'
|
|
5
|
-
import { defineHeadingKeymap } from './heading-keymap'
|
|
6
|
-
import { defineHeadingSpec, type HeadingSpecExtension } from './heading-spec'
|
|
3
|
+
import { defineHeadingCommands, type HeadingCommandsExtension } from './heading-commands.ts'
|
|
4
|
+
import { defineHeadingInputRule } from './heading-input-rule.ts'
|
|
5
|
+
import { defineHeadingKeymap } from './heading-keymap.ts'
|
|
6
|
+
import { defineHeadingSpec, type HeadingSpecExtension } from './heading-spec.ts'
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* @internal
|
package/src/heading/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export type
|
|
1
|
+
export { defineHeadingCommands, type HeadingCommandsExtension } from './heading-commands.ts'
|
|
2
|
+
export { defineHeadingInputRule } from './heading-input-rule.ts'
|
|
3
|
+
export { defineHeadingKeymap } from './heading-keymap.ts'
|
|
4
|
+
export { defineHeadingSpec, type HeadingSpecExtension } from './heading-spec.ts'
|
|
5
|
+
export type { HeadingAttrs } from './heading-types.ts'
|
|
6
|
+
export { defineHeading, type HeadingExtension } from './heading.ts'
|
|
@@ -8,21 +8,23 @@ export type HorizontalRuleCommandsExtension = Extension<{
|
|
|
8
8
|
}
|
|
9
9
|
}>
|
|
10
10
|
|
|
11
|
+
const insertHorizontalRuleCommand: Command = (state, dispatch): boolean => {
|
|
12
|
+
if (!dispatch) return true
|
|
13
|
+
|
|
14
|
+
const { schema, tr } = state
|
|
15
|
+
const type = getNodeType(schema, 'horizontalRule')
|
|
16
|
+
const node = type.createChecked()
|
|
17
|
+
const pos = tr.selection.anchor
|
|
18
|
+
tr.replaceRange(pos, pos, new Slice(Fragment.from(node), 0, 0))
|
|
19
|
+
dispatch(tr)
|
|
20
|
+
return true
|
|
21
|
+
}
|
|
22
|
+
|
|
11
23
|
/**
|
|
12
24
|
* Returns a command that inserts a horizontal rule at the current selection.
|
|
13
25
|
*/
|
|
14
26
|
export function insertHorizontalRule(): Command {
|
|
15
|
-
return
|
|
16
|
-
if (!dispatch) return true
|
|
17
|
-
|
|
18
|
-
const { schema, tr } = state
|
|
19
|
-
const type = getNodeType(schema, 'horizontalRule')
|
|
20
|
-
const node = type.createChecked()
|
|
21
|
-
const pos = tr.selection.anchor
|
|
22
|
-
tr.replaceRange(pos, pos, new Slice(Fragment.from(node), 0, 0))
|
|
23
|
-
dispatch(tr)
|
|
24
|
-
return true
|
|
25
|
-
}
|
|
27
|
+
return insertHorizontalRuleCommand
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
export function defineHorizontalRuleCommands(): HorizontalRuleCommandsExtension {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest'
|
|
2
2
|
|
|
3
|
-
import { setupTest } from '../testing'
|
|
4
|
-
import { inputText } from '../testing/keyboard'
|
|
3
|
+
import { setupTest } from '../testing/index.ts'
|
|
4
|
+
import { inputText } from '../testing/keyboard.ts'
|
|
5
5
|
|
|
6
6
|
describe('defineHorizontalRuleInputRule', () => {
|
|
7
7
|
const { editor, n } = setupTest()
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { union, type Union } from '@prosekit/core'
|
|
2
2
|
|
|
3
|
-
import { defineHorizontalRuleCommands, type HorizontalRuleCommandsExtension } from './horizontal-rule-commands'
|
|
4
|
-
import { defineHorizontalRuleInputRule } from './horizontal-rule-input-rule'
|
|
5
|
-
import { defineHorizontalRuleSpec, type HorizontalRuleSpecExtension } from './horizontal-rule-spec'
|
|
3
|
+
import { defineHorizontalRuleCommands, type HorizontalRuleCommandsExtension } from './horizontal-rule-commands.ts'
|
|
4
|
+
import { defineHorizontalRuleInputRule } from './horizontal-rule-input-rule.ts'
|
|
5
|
+
import { defineHorizontalRuleSpec, type HorizontalRuleSpecExtension } from './horizontal-rule-spec.ts'
|
|
6
6
|
|
|
7
7
|
export type HorizontalRuleExtension = Union<
|
|
8
8
|
[HorizontalRuleSpecExtension, HorizontalRuleCommandsExtension]
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
1
|
+
export { defineHorizontalRuleCommands, insertHorizontalRule, type HorizontalRuleCommandsExtension } from './horizontal-rule-commands.ts'
|
|
2
|
+
export { defineHorizontalRuleInputRule } from './horizontal-rule-input-rule.ts'
|
|
3
|
+
export { defineHorizontalRuleSpec, type HorizontalRuleSpecExtension } from './horizontal-rule-spec.ts'
|
|
4
|
+
export { defineHorizontalRule, type HorizontalRuleExtension } from './horizontal-rule.ts'
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { insertNode } from '@prosekit/core'
|
|
2
2
|
import type { Command } from '@prosekit/pm/state'
|
|
3
3
|
|
|
4
|
-
import type { ImageAttrs } from '../image-spec'
|
|
4
|
+
import type { ImageAttrs } from '../image-spec.ts'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Returns a command that inserts an image node with the given attributes at the
|
|
@@ -3,11 +3,11 @@ import { findNode, findNodes } from '@prosekit/core'
|
|
|
3
3
|
import type { ProseMirrorNode } from '@prosekit/pm/model'
|
|
4
4
|
import { describe, expect, it, vi } from 'vitest'
|
|
5
5
|
|
|
6
|
-
import type { Uploader } from '../../file'
|
|
7
|
-
import { setupTest } from '../../testing'
|
|
8
|
-
import type { ImageAttrs } from '../image-spec'
|
|
6
|
+
import type { Uploader } from '../../file/index.ts'
|
|
7
|
+
import { setupTest } from '../../testing/index.ts'
|
|
8
|
+
import type { ImageAttrs } from '../image-spec.ts'
|
|
9
9
|
|
|
10
|
-
import { replaceImageURL, uploadImage, type ImageUploadErrorHandler } from './upload-image'
|
|
10
|
+
import { replaceImageURL, uploadImage, type ImageUploadErrorHandler } from './upload-image.ts'
|
|
11
11
|
|
|
12
12
|
describe('uploadImage', () => {
|
|
13
13
|
it('should insert image at current selection by default', async () => {
|
|
@@ -2,8 +2,8 @@ import { insertNode, ProseKitError } from '@prosekit/core'
|
|
|
2
2
|
import type { Command, EditorState, Transaction } from '@prosekit/pm/state'
|
|
3
3
|
import type { EditorView } from '@prosekit/pm/view'
|
|
4
4
|
|
|
5
|
-
import { UploadTask, type Uploader } from '../../file'
|
|
6
|
-
import type { ImageAttrs } from '../image-spec'
|
|
5
|
+
import { UploadTask, type Uploader } from '../../file/index.ts'
|
|
6
|
+
import type { ImageAttrs } from '../image-spec.ts'
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Options for {@link uploadImage}.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { defineCommands, type Extension } from '@prosekit/core'
|
|
2
2
|
|
|
3
|
-
import { insertImage } from './image-commands/insert-image'
|
|
4
|
-
import { uploadImage, type UploadImageOptions } from './image-commands/upload-image'
|
|
5
|
-
import type { ImageAttrs } from './image-spec'
|
|
3
|
+
import { insertImage } from './image-commands/insert-image.ts'
|
|
4
|
+
import { uploadImage, type UploadImageOptions } from './image-commands/upload-image.ts'
|
|
5
|
+
import type { ImageAttrs } from './image-spec.ts'
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @internal
|
|
@@ -8,9 +8,9 @@ import {
|
|
|
8
8
|
type FilePasteHandler,
|
|
9
9
|
type FilePasteHandlerOptions,
|
|
10
10
|
type Uploader,
|
|
11
|
-
} from '../file'
|
|
11
|
+
} from '../file/index.ts'
|
|
12
12
|
|
|
13
|
-
import { uploadImage, type ImageUploadErrorHandler } from './image-commands/upload-image'
|
|
13
|
+
import { uploadImage, type ImageUploadErrorHandler } from './image-commands/upload-image.ts'
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* A predicate to determine if the pasted file should be uploaded and inserted as an image.
|
package/src/image/image.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { union, type Union } from '@prosekit/core'
|
|
2
2
|
|
|
3
|
-
import { defineImageCommands, type ImageCommandsExtension } from './image-commands'
|
|
4
|
-
import { defineImageSpec, type ImageSpecExtension } from './image-spec'
|
|
3
|
+
import { defineImageCommands, type ImageCommandsExtension } from './image-commands.ts'
|
|
4
|
+
import { defineImageSpec, type ImageSpecExtension } from './image-spec.ts'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @internal
|
package/src/image/index.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export { insertImage } from './image-commands/insert-image'
|
|
1
|
+
export { defineImageCommands, type ImageCommandsExtension } from './image-commands.ts'
|
|
2
|
+
export { insertImage } from './image-commands/insert-image.ts'
|
|
4
3
|
export {
|
|
5
4
|
replaceImageURL,
|
|
6
5
|
uploadImage,
|
|
7
6
|
type ImageUploadErrorHandler,
|
|
8
7
|
type ImageUploadErrorHandlerOptions,
|
|
9
8
|
type UploadImageOptions,
|
|
10
|
-
} from './image-commands/upload-image'
|
|
11
|
-
export { defineImageSpec, type ImageAttrs, type ImageSpecExtension } from './image-spec'
|
|
9
|
+
} from './image-commands/upload-image.ts'
|
|
10
|
+
export { defineImageSpec, type ImageAttrs, type ImageSpecExtension } from './image-spec.ts'
|
|
12
11
|
export {
|
|
13
12
|
defineImageUploadHandler,
|
|
14
13
|
type ImageCanDropPredicate,
|
|
15
14
|
type ImageCanPastePredicate,
|
|
16
15
|
type ImageUploadHandlerOptions,
|
|
17
|
-
} from './image-upload-handler'
|
|
16
|
+
} from './image-upload-handler.ts'
|
|
17
|
+
export { defineImage, type ImageExtension } from './image.ts'
|
package/src/italic/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
1
|
+
export { defineItalicCommands, type ItalicCommandsExtension } from './italic-commands.ts'
|
|
2
|
+
export { defineItalicInputRule } from './italic-input-rule.ts'
|
|
3
|
+
export { defineItalicKeymap } from './italic-keymap.ts'
|
|
4
|
+
export { defineItalicSpec, type ItalicSpecExtension } from './italic-spec.ts'
|
|
5
|
+
export { defineItalic, type ItalicExtension } from './italic.ts'
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { createEditor, defineBaseCommands, union } from '@prosekit/core'
|
|
2
2
|
import { describe, expect, it } from 'vitest'
|
|
3
3
|
|
|
4
|
-
import { defineDoc } from '../doc'
|
|
5
|
-
import { defineParagraph } from '../paragraph'
|
|
6
|
-
import { defineText } from '../text'
|
|
4
|
+
import { defineDoc } from '../doc/index.ts'
|
|
5
|
+
import { defineParagraph } from '../paragraph/index.ts'
|
|
6
|
+
import { defineText } from '../text/index.ts'
|
|
7
7
|
|
|
8
|
-
import { defineItalic } from './index'
|
|
8
|
+
import { defineItalic } from './index.ts'
|
|
9
9
|
|
|
10
10
|
describe('command', () => {
|
|
11
11
|
const extension = union(
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest'
|
|
2
2
|
|
|
3
|
-
import { setupTest } from '../testing'
|
|
4
|
-
import { inputText } from '../testing/keyboard'
|
|
3
|
+
import { setupTest } from '../testing/index.ts'
|
|
4
|
+
import { inputText } from '../testing/keyboard.ts'
|
|
5
5
|
|
|
6
6
|
describe('defineItalicInputRule', () => {
|
|
7
7
|
const { editor, n, m } = setupTest()
|