@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/enter-rule/index.ts
CHANGED
|
@@ -1,113 +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 {
|
|
14
|
-
Attrs,
|
|
15
|
-
NodeType,
|
|
16
|
-
} from '@prosekit/pm/model'
|
|
17
|
-
import {
|
|
18
|
-
PluginKey,
|
|
19
|
-
ProseMirrorPlugin,
|
|
20
|
-
type Command,
|
|
21
|
-
type EditorState,
|
|
22
|
-
type Transaction,
|
|
23
|
-
} from '@prosekit/pm/state'
|
|
24
|
-
import type { EditorView } from '@prosekit/pm/view'
|
|
3
|
+
createEnterRulePlugin,
|
|
4
|
+
createTextBlockEnterRule,
|
|
5
|
+
type EnterRule,
|
|
6
|
+
type EnterRuleHandler,
|
|
7
|
+
type EnterRuleHandlerOptions,
|
|
8
|
+
type TextBlockEnterRuleOptions as _TextBlockEnterRuleOptions,
|
|
9
|
+
} from 'prosemirror-enter-rules'
|
|
25
10
|
|
|
26
|
-
|
|
27
|
-
* @public
|
|
28
|
-
*
|
|
29
|
-
* Options for {@link EnterRuleHandler}.
|
|
30
|
-
*/
|
|
31
|
-
export interface EnterRuleHandlerOptions {
|
|
32
|
-
/**
|
|
33
|
-
* The current editor state.
|
|
34
|
-
*/
|
|
35
|
-
state: EditorState
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* The start position of the matched text.
|
|
39
|
-
*/
|
|
40
|
-
from: number
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* The end position of the matched text.
|
|
44
|
-
*/
|
|
45
|
-
to: number
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* The matched result from the regular expression.
|
|
49
|
-
*/
|
|
50
|
-
match: RegExpExecArray
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* @public
|
|
55
|
-
*/
|
|
56
|
-
export type EnterRuleHandler = (options: EnterRuleHandlerOptions) => Transaction | null
|
|
11
|
+
export type { EnterRuleHandler, EnterRuleHandlerOptions }
|
|
57
12
|
|
|
58
13
|
/**
|
|
59
14
|
* Options for {@link defineEnterRule}.
|
|
60
15
|
*
|
|
61
16
|
* @public
|
|
62
17
|
*/
|
|
63
|
-
export type EnterRuleOptions =
|
|
64
|
-
/**
|
|
65
|
-
* The regular expression to match against. It should end with `$`.
|
|
66
|
-
*/
|
|
67
|
-
regex: RegExp
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* A function to be called when an enter rule is triggered.
|
|
71
|
-
*/
|
|
72
|
-
handler: EnterRuleHandler
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Whether to stop further handlers from being called if this rule is triggered.
|
|
76
|
-
*
|
|
77
|
-
* @default false
|
|
78
|
-
*/
|
|
79
|
-
stop?: boolean
|
|
80
|
-
}
|
|
18
|
+
export type EnterRuleOptions = EnterRule
|
|
81
19
|
|
|
82
20
|
/**
|
|
83
21
|
* Options for {@link defineTextBlockEnterRule}.
|
|
84
22
|
*
|
|
85
23
|
* @public
|
|
86
24
|
*/
|
|
87
|
-
export
|
|
88
|
-
/**
|
|
89
|
-
* The regular expression to match against. It should end with `$`.
|
|
90
|
-
*/
|
|
91
|
-
regex: RegExp
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* The node type to replace the matched text with.
|
|
95
|
-
*/
|
|
96
|
-
type: string | NodeType
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Attributes to set on the node. If a function is provided, it will be called
|
|
100
|
-
* with the matched result from the regular expression.
|
|
101
|
-
*/
|
|
102
|
-
attrs?: Attrs | null | ((match: RegExpMatchArray) => Attrs | null)
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Whether to stop further handlers from being called if this rule is triggered.
|
|
106
|
-
*
|
|
107
|
-
* @default true
|
|
108
|
-
*/
|
|
109
|
-
stop?: boolean
|
|
110
|
-
}
|
|
25
|
+
export type TextBlockEnterRuleOptions = _TextBlockEnterRuleOptions
|
|
111
26
|
|
|
112
27
|
/**
|
|
113
28
|
* Defines an enter rule. An enter rule applies when the text directly in front of
|
|
@@ -118,13 +33,8 @@ export interface TextBlockEnterRuleOptions {
|
|
|
118
33
|
*
|
|
119
34
|
* @public
|
|
120
35
|
*/
|
|
121
|
-
export function defineEnterRule({
|
|
122
|
-
|
|
123
|
-
handler,
|
|
124
|
-
stop = false,
|
|
125
|
-
}: EnterRuleOptions): PlainExtension {
|
|
126
|
-
const rule: EnterRule = new EnterRule(regex, handler, stop)
|
|
127
|
-
return defineFacetPayload(enterRule, [rule]) as PlainExtension
|
|
36
|
+
export function defineEnterRule(options: EnterRuleOptions): PlainExtension {
|
|
37
|
+
return defineFacetPayload(enterRuleFacet, [options]) as PlainExtension
|
|
128
38
|
}
|
|
129
39
|
|
|
130
40
|
/**
|
|
@@ -136,106 +46,14 @@ export function defineEnterRule({
|
|
|
136
46
|
*
|
|
137
47
|
* @public
|
|
138
48
|
*/
|
|
139
|
-
export function defineTextBlockEnterRule({
|
|
140
|
-
|
|
141
|
-
type,
|
|
142
|
-
attrs,
|
|
143
|
-
stop = true,
|
|
144
|
-
}: TextBlockEnterRuleOptions): PlainExtension {
|
|
145
|
-
return defineEnterRule({
|
|
146
|
-
regex,
|
|
147
|
-
handler: ({ state, from, to, match }) => {
|
|
148
|
-
const nodeType = getNodeType(state.schema, type)
|
|
149
|
-
const $start = state.doc.resolve(from)
|
|
150
|
-
|
|
151
|
-
if (
|
|
152
|
-
!$start
|
|
153
|
-
.node(-1)
|
|
154
|
-
.canReplaceWith($start.index(-1), $start.indexAfter(-1), nodeType)
|
|
155
|
-
) {
|
|
156
|
-
return null
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
const nodeAttrs = maybeRun(attrs, match)
|
|
160
|
-
return state.tr
|
|
161
|
-
.delete(from, to)
|
|
162
|
-
.setBlockType(from, from, nodeType, nodeAttrs)
|
|
163
|
-
},
|
|
164
|
-
stop,
|
|
165
|
-
})
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* @internal
|
|
170
|
-
*/
|
|
171
|
-
class EnterRule {
|
|
172
|
-
constructor(
|
|
173
|
-
readonly regex: RegExp,
|
|
174
|
-
readonly handler: EnterRuleHandler,
|
|
175
|
-
readonly stop: boolean,
|
|
176
|
-
) {}
|
|
49
|
+
export function defineTextBlockEnterRule(options: TextBlockEnterRuleOptions): PlainExtension {
|
|
50
|
+
return defineEnterRule(createTextBlockEnterRule(options))
|
|
177
51
|
}
|
|
178
52
|
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
const command: Command = (state, dispatch, view) => {
|
|
184
|
-
if (!view) return false
|
|
185
|
-
return execRules(view, rules, dispatch)
|
|
186
|
-
}
|
|
187
|
-
const handler = keydownHandler({ Enter: command })
|
|
188
|
-
const plugin = new ProseMirrorPlugin({
|
|
189
|
-
key: new PluginKey('prosekit-enter-rule'),
|
|
190
|
-
props: { handleKeyDown: handler },
|
|
191
|
-
})
|
|
192
|
-
|
|
193
|
-
return function reducer(inputs) {
|
|
194
|
-
rules = inputs
|
|
195
|
-
return plugin
|
|
196
|
-
}
|
|
53
|
+
const enterRuleFacet = defineFacet<EnterRule, PluginPayload>({
|
|
54
|
+
reducer: (rules: EnterRule[]): PluginPayload => {
|
|
55
|
+
return createEnterRulePlugin({ rules })
|
|
197
56
|
},
|
|
198
57
|
|
|
199
58
|
parent: pluginFacet,
|
|
200
59
|
})
|
|
201
|
-
|
|
202
|
-
function execRules(
|
|
203
|
-
view: EditorView,
|
|
204
|
-
rules: readonly EnterRule[],
|
|
205
|
-
dispatch?: (tr: Transaction) => void,
|
|
206
|
-
): boolean {
|
|
207
|
-
if (view.composing) return false
|
|
208
|
-
const state = view.state
|
|
209
|
-
const selection = state.selection
|
|
210
|
-
if (!isTextSelection(selection)) return false
|
|
211
|
-
const $cursor = selection.$cursor
|
|
212
|
-
if (!$cursor || $cursor.parent.type.spec.code) return false
|
|
213
|
-
|
|
214
|
-
const textBefore = $cursor.parent.textBetween(
|
|
215
|
-
Math.max(0, $cursor.parentOffset - MAX_MATCH),
|
|
216
|
-
$cursor.parentOffset,
|
|
217
|
-
null,
|
|
218
|
-
OBJECT_REPLACEMENT_CHARACTER,
|
|
219
|
-
)
|
|
220
|
-
|
|
221
|
-
for (const rule of rules) {
|
|
222
|
-
rule.regex.lastIndex = 0
|
|
223
|
-
const match = rule.regex.exec(textBefore)
|
|
224
|
-
const tr = match
|
|
225
|
-
&& rule.handler({
|
|
226
|
-
state,
|
|
227
|
-
from: $cursor.pos - match[0].length,
|
|
228
|
-
to: $cursor.pos,
|
|
229
|
-
match,
|
|
230
|
-
})
|
|
231
|
-
if (!tr) continue
|
|
232
|
-
dispatch?.(tr)
|
|
233
|
-
|
|
234
|
-
if (rule.stop) {
|
|
235
|
-
return true
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
return false
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
const MAX_MATCH = 200
|
|
@@ -1,20 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
union,
|
|
4
|
-
withPriority,
|
|
5
|
-
} from '@prosekit/core'
|
|
6
|
-
import {
|
|
7
|
-
beforeEach,
|
|
8
|
-
describe,
|
|
9
|
-
expect,
|
|
10
|
-
it,
|
|
11
|
-
vi,
|
|
12
|
-
} from 'vitest'
|
|
1
|
+
import { Priority, union, withPriority } from '@prosekit/core'
|
|
2
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
13
3
|
|
|
14
|
-
import {
|
|
15
|
-
defineTestExtension,
|
|
16
|
-
setupTestFromExtension,
|
|
17
|
-
} from '../testing'
|
|
4
|
+
import { defineTestExtension, setupTestFromExtension } from '../testing'
|
|
18
5
|
import { pasteFiles } from '../testing/clipboard'
|
|
19
6
|
|
|
20
7
|
import { defineFilePasteHandler } from './file-paste-handler'
|
package/src/file/index.ts
CHANGED
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
type FileDropHandlerOptions,
|
|
5
|
-
} from './file-drop-handler'
|
|
6
|
-
export {
|
|
7
|
-
defineFilePasteHandler,
|
|
8
|
-
type FilePasteHandler,
|
|
9
|
-
type FilePasteHandlerOptions,
|
|
10
|
-
} from './file-paste-handler'
|
|
11
|
-
export {
|
|
12
|
-
UploadTask,
|
|
13
|
-
type Uploader,
|
|
14
|
-
type UploaderOptions,
|
|
15
|
-
type UploadProgress,
|
|
16
|
-
} from './file-upload'
|
|
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'
|
package/src/gap-cursor/index.ts
CHANGED
|
@@ -1,17 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
union,
|
|
3
|
-
type Union,
|
|
4
|
-
} from '@prosekit/core'
|
|
1
|
+
import { union, type Union } from '@prosekit/core'
|
|
5
2
|
|
|
6
|
-
import {
|
|
7
|
-
defineHardBreakCommands,
|
|
8
|
-
type HardBreakCommandsExtension,
|
|
9
|
-
} from './hard-break-commands'
|
|
3
|
+
import { defineHardBreakCommands, type HardBreakCommandsExtension } from './hard-break-commands'
|
|
10
4
|
import { defineHardBreakKeymap } from './hard-break-keymap'
|
|
11
|
-
import {
|
|
12
|
-
defineHardBreakSpec,
|
|
13
|
-
type HardBreakSpecExtension,
|
|
14
|
-
} from './hard-break-spec'
|
|
5
|
+
import { defineHardBreakSpec, type HardBreakSpecExtension } from './hard-break-spec'
|
|
15
6
|
|
|
16
7
|
/**
|
|
17
8
|
* @internal
|
package/src/hard-break/index.ts
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
3
|
-
type HardBreakExtension,
|
|
4
|
-
} from './hard-break'
|
|
5
|
-
export {
|
|
6
|
-
defineHardBreakCommands,
|
|
7
|
-
type HardBreakCommandsExtension,
|
|
8
|
-
} from './hard-break-commands'
|
|
1
|
+
export { defineHardBreak, type HardBreakExtension } from './hard-break'
|
|
2
|
+
export { defineHardBreakCommands, type HardBreakCommandsExtension } from './hard-break-commands'
|
|
9
3
|
export { defineHardBreakKeymap } from './hard-break-keymap'
|
|
10
|
-
export {
|
|
11
|
-
defineHardBreakSpec,
|
|
12
|
-
type HardBreakSpecExtension,
|
|
13
|
-
} from './hard-break-spec'
|
|
4
|
+
export { defineHardBreakSpec, type HardBreakSpecExtension } from './hard-break-spec'
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
defineCommands,
|
|
3
|
-
insertNode,
|
|
4
|
-
setBlockType,
|
|
5
|
-
toggleNode,
|
|
6
|
-
type Extension,
|
|
7
|
-
} from '@prosekit/core'
|
|
1
|
+
import { defineCommands, insertNode, setBlockType, toggleNode, type Extension } from '@prosekit/core'
|
|
8
2
|
|
|
9
3
|
import type { HeadingAttrs } from './heading-types'
|
|
10
4
|
|
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
defineKeymap,
|
|
3
|
-
isAtBlockStart,
|
|
4
|
-
toggleNode,
|
|
5
|
-
unsetBlockType,
|
|
6
|
-
withSkipCodeBlock,
|
|
7
|
-
type PlainExtension,
|
|
8
|
-
} from '@prosekit/core'
|
|
1
|
+
import { defineKeymap, isAtBlockStart, toggleNode, unsetBlockType, withSkipCodeBlock, type PlainExtension } from '@prosekit/core'
|
|
9
2
|
import type { Command } from '@prosekit/pm/state'
|
|
10
3
|
|
|
11
4
|
function toggleHeadingKeybinding(level: number): Command {
|
package/src/heading/heading.ts
CHANGED
|
@@ -1,18 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
union,
|
|
3
|
-
type Union,
|
|
4
|
-
} from '@prosekit/core'
|
|
1
|
+
import { union, type Union } from '@prosekit/core'
|
|
5
2
|
|
|
6
|
-
import {
|
|
7
|
-
defineHeadingCommands,
|
|
8
|
-
type HeadingCommandsExtension,
|
|
9
|
-
} from './heading-commands'
|
|
3
|
+
import { defineHeadingCommands, type HeadingCommandsExtension } from './heading-commands'
|
|
10
4
|
import { defineHeadingInputRule } from './heading-input-rule'
|
|
11
5
|
import { defineHeadingKeymap } from './heading-keymap'
|
|
12
|
-
import {
|
|
13
|
-
defineHeadingSpec,
|
|
14
|
-
type HeadingSpecExtension,
|
|
15
|
-
} from './heading-spec'
|
|
6
|
+
import { defineHeadingSpec, type HeadingSpecExtension } from './heading-spec'
|
|
16
7
|
|
|
17
8
|
/**
|
|
18
9
|
* @internal
|
package/src/heading/index.ts
CHANGED
|
@@ -1,15 +1,6 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
3
|
-
type HeadingExtension,
|
|
4
|
-
} from './heading'
|
|
5
|
-
export {
|
|
6
|
-
defineHeadingCommands,
|
|
7
|
-
type HeadingCommandsExtension,
|
|
8
|
-
} from './heading-commands'
|
|
1
|
+
export { defineHeading, type HeadingExtension } from './heading'
|
|
2
|
+
export { defineHeadingCommands, type HeadingCommandsExtension } from './heading-commands'
|
|
9
3
|
export { defineHeadingInputRule } from './heading-input-rule'
|
|
10
4
|
export { defineHeadingKeymap } from './heading-keymap'
|
|
11
|
-
export {
|
|
12
|
-
defineHeadingSpec,
|
|
13
|
-
type HeadingSpecExtension,
|
|
14
|
-
} from './heading-spec'
|
|
5
|
+
export { defineHeadingSpec, type HeadingSpecExtension } from './heading-spec'
|
|
15
6
|
export type { HeadingAttrs } from './heading-types'
|
|
@@ -1,12 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
getNodeType,
|
|
4
|
-
type Extension,
|
|
5
|
-
} from '@prosekit/core'
|
|
6
|
-
import {
|
|
7
|
-
Fragment,
|
|
8
|
-
Slice,
|
|
9
|
-
} from '@prosekit/pm/model'
|
|
1
|
+
import { defineCommands, getNodeType, type Extension } from '@prosekit/core'
|
|
2
|
+
import { Fragment, Slice } from '@prosekit/pm/model'
|
|
10
3
|
import type { Command } from '@prosekit/pm/state'
|
|
11
4
|
|
|
12
5
|
export type HorizontalRuleCommandsExtension = Extension<{
|
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
describe,
|
|
3
|
-
expect,
|
|
4
|
-
it,
|
|
5
|
-
} from 'vitest'
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
6
2
|
|
|
7
3
|
import { setupTest } from '../testing'
|
|
8
4
|
import { inputText } from '../testing/keyboard'
|
|
9
5
|
|
|
10
6
|
describe('defineHorizontalRuleInputRule', () => {
|
|
11
7
|
const { editor, n } = setupTest()
|
|
12
|
-
it('should insert
|
|
8
|
+
it('should insert when typing "---" in an empty paragraph', async () => {
|
|
13
9
|
const doc = n.doc(n.p('<a>'))
|
|
14
10
|
editor.set(doc)
|
|
15
11
|
|
|
@@ -24,7 +20,7 @@ describe('defineHorizontalRuleInputRule', () => {
|
|
|
24
20
|
)
|
|
25
21
|
})
|
|
26
22
|
|
|
27
|
-
it('should insert
|
|
23
|
+
it('should insert when typing "---" before some text', async () => {
|
|
28
24
|
const doc = n.doc(n.p('<a>123'))
|
|
29
25
|
editor.set(doc)
|
|
30
26
|
|
|
@@ -39,7 +35,7 @@ describe('defineHorizontalRuleInputRule', () => {
|
|
|
39
35
|
)
|
|
40
36
|
})
|
|
41
37
|
|
|
42
|
-
it('should not insert
|
|
38
|
+
it('should not insert when typing "---" after some text', async () => {
|
|
43
39
|
const doc = n.doc(n.p('123<a>'))
|
|
44
40
|
editor.set(doc)
|
|
45
41
|
|
|
@@ -49,7 +45,7 @@ describe('defineHorizontalRuleInputRule', () => {
|
|
|
49
45
|
)
|
|
50
46
|
})
|
|
51
47
|
|
|
52
|
-
it('should not insert
|
|
48
|
+
it('should not insert inside a code block', async () => {
|
|
53
49
|
const doc = n.doc(n.codeBlock('<a>'))
|
|
54
50
|
editor.set(doc)
|
|
55
51
|
|
|
@@ -1,17 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
union,
|
|
3
|
-
type Union,
|
|
4
|
-
} from '@prosekit/core'
|
|
1
|
+
import { union, type Union } from '@prosekit/core'
|
|
5
2
|
|
|
6
|
-
import {
|
|
7
|
-
defineHorizontalRuleCommands,
|
|
8
|
-
type HorizontalRuleCommandsExtension,
|
|
9
|
-
} from './horizontal-rule-commands'
|
|
3
|
+
import { defineHorizontalRuleCommands, type HorizontalRuleCommandsExtension } from './horizontal-rule-commands'
|
|
10
4
|
import { defineHorizontalRuleInputRule } from './horizontal-rule-input-rule'
|
|
11
|
-
import {
|
|
12
|
-
defineHorizontalRuleSpec,
|
|
13
|
-
type HorizontalRuleSpecExtension,
|
|
14
|
-
} from './horizontal-rule-spec'
|
|
5
|
+
import { defineHorizontalRuleSpec, type HorizontalRuleSpecExtension } from './horizontal-rule-spec'
|
|
15
6
|
|
|
16
7
|
export type HorizontalRuleExtension = Union<
|
|
17
8
|
[HorizontalRuleSpecExtension, HorizontalRuleCommandsExtension]
|
|
@@ -1,14 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
3
|
-
type HorizontalRuleExtension,
|
|
4
|
-
} from './horizontal-rule'
|
|
5
|
-
export {
|
|
6
|
-
defineHorizontalRuleCommands,
|
|
7
|
-
insertHorizontalRule,
|
|
8
|
-
type HorizontalRuleCommandsExtension,
|
|
9
|
-
} from './horizontal-rule-commands'
|
|
1
|
+
export { defineHorizontalRule, type HorizontalRuleExtension } from './horizontal-rule'
|
|
2
|
+
export { defineHorizontalRuleCommands, insertHorizontalRule, type HorizontalRuleCommandsExtension } from './horizontal-rule-commands'
|
|
10
3
|
export { defineHorizontalRuleInputRule } from './horizontal-rule-input-rule'
|
|
11
|
-
export {
|
|
12
|
-
defineHorizontalRuleSpec,
|
|
13
|
-
type HorizontalRuleSpecExtension,
|
|
14
|
-
} from './horizontal-rule-spec'
|
|
4
|
+
export { defineHorizontalRuleSpec, type HorizontalRuleSpecExtension } from './horizontal-rule-spec'
|