@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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest'
|
|
2
2
|
|
|
3
|
-
import { splitTextByRegex } from './split-text-by-regex'
|
|
3
|
+
import { splitTextByRegex } from './split-text-by-regex.ts'
|
|
4
4
|
|
|
5
5
|
describe('splitTextByRegex', () => {
|
|
6
6
|
it('should return undefined when no matches are found', () => {
|
package/src/placeholder/index.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { ProseMirrorNode } from '@prosekit/pm/model'
|
|
|
3
3
|
import { Plugin, PluginKey, type EditorState } from '@prosekit/pm/state'
|
|
4
4
|
import { Decoration, DecorationSet } from '@prosekit/pm/view'
|
|
5
5
|
|
|
6
|
-
import { findTable } from '../table'
|
|
6
|
+
import { findTable } from '../table/index.ts'
|
|
7
7
|
|
|
8
8
|
export interface PlaceholderOptions {
|
|
9
9
|
/**
|
package/src/strike/index.ts
CHANGED
package/src/table/index.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
10
|
-
export {
|
|
11
|
-
export {
|
|
12
|
-
export { defineTablePlugins } from './table-plugins'
|
|
1
|
+
export { defineTableCommands, type TableCommandsExtension } from './table-commands.ts'
|
|
2
|
+
export { exitTable } from './table-commands/exit-table.ts'
|
|
3
|
+
export { insertTable, type InsertTableOptions } from './table-commands/insert-table.ts'
|
|
4
|
+
export { moveTableColumn, type MoveTableColumnOptions } from './table-commands/move-table-column.ts'
|
|
5
|
+
export { moveTableRow, type MoveTableRowOptions } from './table-commands/move-table-row.ts'
|
|
6
|
+
export { selectTableCell, type SelectTableCellOptions } from './table-commands/select-table-cell.ts'
|
|
7
|
+
export { selectTableColumn, type SelectTableColumnOptions } from './table-commands/select-table-column.ts'
|
|
8
|
+
export { selectTableRow, type SelectTableRowOptions } from './table-commands/select-table-row.ts'
|
|
9
|
+
export { selectTable, type SelectTableOptions } from './table-commands/select-table.ts'
|
|
10
|
+
export { defineTableDropIndicator } from './table-drop-indicator.ts'
|
|
11
|
+
export { defineTablePlugins } from './table-plugins.ts'
|
|
13
12
|
export {
|
|
14
13
|
defineTableCellSpec,
|
|
15
14
|
defineTableHeaderCellSpec,
|
|
@@ -19,5 +18,6 @@ export {
|
|
|
19
18
|
type TableHeaderCellSpecExtension,
|
|
20
19
|
type TableRowSpecExtension,
|
|
21
20
|
type TableSpecExtension,
|
|
22
|
-
} from './table-spec'
|
|
23
|
-
export { findTable, isCellSelection } from './table-utils'
|
|
21
|
+
} from './table-spec.ts'
|
|
22
|
+
export { findTable, isCellSelection } from './table-utils.ts'
|
|
23
|
+
export { defineTable, type TableExtension } from './table.ts'
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest'
|
|
2
2
|
|
|
3
|
-
import { setupTest } from '../../testing'
|
|
4
|
-
import { isCellSelection } from '../table-utils'
|
|
5
|
-
import { setCellSelection } from '../test-utils'
|
|
3
|
+
import { setupTest } from '../../testing/index.ts'
|
|
4
|
+
import { isCellSelection } from '../table-utils.ts'
|
|
5
|
+
import { setCellSelection } from '../test-utils.ts'
|
|
6
6
|
|
|
7
7
|
describe('deleteCellSelection', () => {
|
|
8
8
|
it('can clear the content in the selected table cells', () => {
|
|
@@ -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('exitTable', () => {
|
|
7
7
|
it('can exist a table', async () => {
|
|
@@ -2,9 +2,9 @@ import type { Command } from '@prosekit/pm/state'
|
|
|
2
2
|
import { CellSelection } from 'prosemirror-tables'
|
|
3
3
|
import { describe, expect, it } from 'vitest'
|
|
4
4
|
|
|
5
|
-
import { setupTest } from '../../testing'
|
|
5
|
+
import { setupTest } from '../../testing/index.ts'
|
|
6
6
|
|
|
7
|
-
import { moveTableColumn } from './move-table-column'
|
|
7
|
+
import { moveTableColumn } from './move-table-column.ts'
|
|
8
8
|
|
|
9
9
|
function setup() {
|
|
10
10
|
const { editor, n } = setupTest()
|
|
@@ -2,9 +2,9 @@ import type { Command } from '@prosekit/pm/state'
|
|
|
2
2
|
import { CellSelection } from 'prosemirror-tables'
|
|
3
3
|
import { describe, expect, it } from 'vitest'
|
|
4
4
|
|
|
5
|
-
import { setupTest } from '../../testing'
|
|
5
|
+
import { setupTest } from '../../testing/index.ts'
|
|
6
6
|
|
|
7
|
-
import { moveTableRow } from './move-table-row'
|
|
7
|
+
import { moveTableRow } from './move-table-row.ts'
|
|
8
8
|
|
|
9
9
|
function setup() {
|
|
10
10
|
const { editor, n } = setupTest()
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest'
|
|
2
2
|
|
|
3
|
-
import { setupTest } from '../../testing'
|
|
4
|
-
import { isCellSelection } from '../table-utils'
|
|
5
|
-
import { inspectSelectedCells } from '../test-utils'
|
|
3
|
+
import { setupTest } from '../../testing/index.ts'
|
|
4
|
+
import { isCellSelection } from '../table-utils.ts'
|
|
5
|
+
import { inspectSelectedCells } from '../test-utils.ts'
|
|
6
6
|
|
|
7
7
|
describe('selectTableCell', () => {
|
|
8
8
|
it('can select a table cell', () => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest'
|
|
2
2
|
|
|
3
|
-
import { setupTest } from '../../testing'
|
|
4
|
-
import { inspectSelectedCells } from '../test-utils'
|
|
3
|
+
import { setupTest } from '../../testing/index.ts'
|
|
4
|
+
import { inspectSelectedCells } from '../test-utils.ts'
|
|
5
5
|
|
|
6
6
|
describe('selectTableColumn', () => {
|
|
7
7
|
it('can select the whole table column', () => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest'
|
|
2
2
|
|
|
3
|
-
import { setupTest } from '../../testing'
|
|
4
|
-
import { inspectSelectedCells } from '../test-utils'
|
|
3
|
+
import { setupTest } from '../../testing/index.ts'
|
|
4
|
+
import { inspectSelectedCells } from '../test-utils.ts'
|
|
5
5
|
|
|
6
6
|
describe('selectTableRow', () => {
|
|
7
7
|
it('can select the whole table row', () => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest'
|
|
2
2
|
|
|
3
|
-
import { setupTest } from '../../testing'
|
|
4
|
-
import { inspectSelectedCells } from '../test-utils'
|
|
3
|
+
import { setupTest } from '../../testing/index.ts'
|
|
4
|
+
import { inspectSelectedCells } from '../test-utils.ts'
|
|
5
5
|
|
|
6
6
|
describe('selectTable', () => {
|
|
7
7
|
it('can select the whole table', () => {
|
|
@@ -11,15 +11,15 @@ import {
|
|
|
11
11
|
splitCell,
|
|
12
12
|
} from 'prosemirror-tables'
|
|
13
13
|
|
|
14
|
-
import { deleteCellSelection } from './table-commands/delete-cell-selection'
|
|
15
|
-
import { exitTable } from './table-commands/exit-table'
|
|
16
|
-
import { insertTable, type InsertTableOptions } from './table-commands/insert-table'
|
|
17
|
-
import { moveTableColumn, type MoveTableColumnOptions } from './table-commands/move-table-column'
|
|
18
|
-
import { moveTableRow, type MoveTableRowOptions } from './table-commands/move-table-row'
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
14
|
+
import { deleteCellSelection } from './table-commands/delete-cell-selection.ts'
|
|
15
|
+
import { exitTable } from './table-commands/exit-table.ts'
|
|
16
|
+
import { insertTable, type InsertTableOptions } from './table-commands/insert-table.ts'
|
|
17
|
+
import { moveTableColumn, type MoveTableColumnOptions } from './table-commands/move-table-column.ts'
|
|
18
|
+
import { moveTableRow, type MoveTableRowOptions } from './table-commands/move-table-row.ts'
|
|
19
|
+
import { selectTableCell, type SelectTableCellOptions } from './table-commands/select-table-cell.ts'
|
|
20
|
+
import { selectTableColumn, type SelectTableColumnOptions } from './table-commands/select-table-column.ts'
|
|
21
|
+
import { selectTableRow, type SelectTableRowOptions } from './table-commands/select-table-row.ts'
|
|
22
|
+
import { selectTable, type SelectTableOptions } from './table-commands/select-table.ts'
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* @internal
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { PlainExtension } from '@prosekit/core'
|
|
2
2
|
|
|
3
|
-
import type { DragEventHandler } from '../drop-indicator'
|
|
4
|
-
import { defineDropIndicator } from '../drop-indicator'
|
|
3
|
+
import type { DragEventHandler } from '../drop-indicator/index.ts'
|
|
4
|
+
import { defineDropIndicator } from '../drop-indicator/index.ts'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Hides the drop indicator when dragging a table column or row by using the
|
|
@@ -2,11 +2,11 @@ import { union } from '@prosekit/core'
|
|
|
2
2
|
import pick from 'just-pick'
|
|
3
3
|
import { describe, expect, it } from 'vitest'
|
|
4
4
|
|
|
5
|
-
import { defineDoc } from '../doc'
|
|
6
|
-
import { defineParagraph } from '../paragraph'
|
|
7
|
-
import { defineText } from '../text'
|
|
5
|
+
import { defineDoc } from '../doc/index.ts'
|
|
6
|
+
import { defineParagraph } from '../paragraph/index.ts'
|
|
7
|
+
import { defineText } from '../text/index.ts'
|
|
8
8
|
|
|
9
|
-
import { defineTableCellSpec, defineTableHeaderCellSpec, defineTableRowSpec, defineTableSpec } from './table-spec'
|
|
9
|
+
import { defineTableCellSpec, defineTableHeaderCellSpec, defineTableRowSpec, defineTableSpec } from './table-spec.ts'
|
|
10
10
|
|
|
11
11
|
describe('table spec', () => {
|
|
12
12
|
it('should be defined', () => {
|
package/src/table/table.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { union, type Union } from '@prosekit/core'
|
|
2
2
|
|
|
3
|
-
import { defineTableCommands, type TableCommandsExtension } from './table-commands'
|
|
4
|
-
import { defineTableDropIndicator } from './table-drop-indicator'
|
|
5
|
-
import { defineTablePlugins } from './table-plugins'
|
|
3
|
+
import { defineTableCommands, type TableCommandsExtension } from './table-commands.ts'
|
|
4
|
+
import { defineTableDropIndicator } from './table-drop-indicator.ts'
|
|
5
|
+
import { defineTablePlugins } from './table-plugins.ts'
|
|
6
6
|
import {
|
|
7
7
|
defineTableCellSpec,
|
|
8
8
|
defineTableHeaderCellSpec,
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
type TableHeaderCellSpecExtension,
|
|
13
13
|
type TableRowSpecExtension,
|
|
14
14
|
type TableSpecExtension,
|
|
15
|
-
} from './table-spec'
|
|
15
|
+
} from './table-spec.ts'
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* @internal
|
package/src/table/test-utils.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Command, Selection } from '@prosekit/pm/state'
|
|
2
2
|
import { CellSelection } from 'prosemirror-tables'
|
|
3
3
|
|
|
4
|
-
import { isCellSelection } from './table-utils'
|
|
4
|
+
import { isCellSelection } from './table-utils.ts'
|
|
5
5
|
|
|
6
6
|
// Helper to create a cell selection between two positions
|
|
7
7
|
export function setCellSelection(from: number, to: number): Command {
|
package/src/testing/index.ts
CHANGED
|
@@ -13,28 +13,30 @@ import {
|
|
|
13
13
|
import { createTestEditor, type TestEditor } from '@prosekit/core/test'
|
|
14
14
|
import { keyboard } from 'vitest-browser-commands/playwright'
|
|
15
15
|
|
|
16
|
-
import { defineBackgroundColor } from '../background-color'
|
|
17
|
-
import { defineBlockquote } from '../blockquote'
|
|
18
|
-
import { defineBold } from '../bold'
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import { defineDoc } from '../doc'
|
|
22
|
-
import { defineHardBreak } from '../hard-break'
|
|
23
|
-
import { defineHeading } from '../heading'
|
|
24
|
-
import { defineHorizontalRule } from '../horizontal-rule'
|
|
25
|
-
import { defineImage } from '../image'
|
|
26
|
-
import { defineItalic } from '../italic'
|
|
27
|
-
import { defineLink } from '../link'
|
|
28
|
-
import { defineList, type ListAttrs } from '../list'
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
31
|
-
import {
|
|
32
|
-
import
|
|
33
|
-
import {
|
|
34
|
-
import { defineTextColor } from '../text-color'
|
|
35
|
-
import {
|
|
36
|
-
|
|
37
|
-
|
|
16
|
+
import { defineBackgroundColor } from '../background-color/index.ts'
|
|
17
|
+
import { defineBlockquote } from '../blockquote/index.ts'
|
|
18
|
+
import { defineBold } from '../bold/index.ts'
|
|
19
|
+
import { defineCodeBlock } from '../code-block/index.ts'
|
|
20
|
+
import { defineCode } from '../code/index.ts'
|
|
21
|
+
import { defineDoc } from '../doc/index.ts'
|
|
22
|
+
import { defineHardBreak } from '../hard-break/index.ts'
|
|
23
|
+
import { defineHeading } from '../heading/index.ts'
|
|
24
|
+
import { defineHorizontalRule } from '../horizontal-rule/index.ts'
|
|
25
|
+
import { defineImage } from '../image/index.ts'
|
|
26
|
+
import { defineItalic } from '../italic/index.ts'
|
|
27
|
+
import { defineLink } from '../link/index.ts'
|
|
28
|
+
import { defineList, type ListAttrs } from '../list/index.ts'
|
|
29
|
+
import { defineMath } from '../math/index.ts'
|
|
30
|
+
import { defineParagraph } from '../paragraph/index.ts'
|
|
31
|
+
import { defineStrike } from '../strike/index.ts'
|
|
32
|
+
import { defineTable } from '../table/index.ts'
|
|
33
|
+
import type { CellAttrs } from '../table/table-spec.ts'
|
|
34
|
+
import { defineTextColor } from '../text-color/index.ts'
|
|
35
|
+
import { defineText } from '../text/index.ts'
|
|
36
|
+
import { defineUnderline } from '../underline/index.ts'
|
|
37
|
+
|
|
38
|
+
import { readHtmlTextFromClipboard, readPlainTextFromClipboard } from './clipboard.ts'
|
|
39
|
+
import { renderMathBlock, renderMathInline } from './katex.ts'
|
|
38
40
|
|
|
39
41
|
/**
|
|
40
42
|
* @internal
|
|
@@ -63,6 +65,7 @@ export function defineTestExtension() {
|
|
|
63
65
|
defineHorizontalRule(),
|
|
64
66
|
defineHardBreak(),
|
|
65
67
|
defineCodeBlock(),
|
|
68
|
+
defineMath({ renderMathBlock, renderMathInline }),
|
|
66
69
|
)
|
|
67
70
|
}
|
|
68
71
|
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { render } from 'katex'
|
|
2
|
+
|
|
3
|
+
export function renderMathBlock(text: string, element: HTMLElement) {
|
|
4
|
+
render(text, element, { displayMode: true, throwOnError: false, output: 'mathml' })
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function renderMathInline(text: string, element: HTMLElement) {
|
|
8
|
+
render(text, element, { displayMode: false, throwOnError: false, output: 'mathml' })
|
|
9
|
+
}
|
package/src/text-color/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
1
|
+
export { addTextColor, defineTextColorCommands, removeTextColor, type TextColorCommandsExtension } from './text-color-commands.ts'
|
|
2
|
+
export { defineTextColorSpec, type TextColorAttrs, type TextColorSpecExtension } from './text-color-spec.ts'
|
|
3
|
+
export { defineTextColor, type TextColorExtension } from './text-color.ts'
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { addMark, defineCommands, removeMark, type Extension } from '@prosekit/core'
|
|
2
2
|
import type { Command } from '@prosekit/pm/state'
|
|
3
3
|
|
|
4
|
-
import type { TextColorAttrs } from './text-color-spec'
|
|
4
|
+
import type { TextColorAttrs } from './text-color-spec.ts'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @internal
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { formatHTML } from 'diffable-html-snapshot'
|
|
2
2
|
import { describe, expect, it } from 'vitest'
|
|
3
3
|
|
|
4
|
-
import { setupTest } from '../testing'
|
|
4
|
+
import { setupTest } from '../testing/index.ts'
|
|
5
5
|
|
|
6
6
|
describe('defineTextColorSpec', () => {
|
|
7
7
|
it('should render color as inline span with style attribute', () => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { union, type Union } from '@prosekit/core'
|
|
2
2
|
|
|
3
|
-
import { defineTextColorCommands, type TextColorCommandsExtension } from './text-color-commands'
|
|
4
|
-
import { defineTextColorSpec, type TextColorSpecExtension } from './text-color-spec'
|
|
3
|
+
import { defineTextColorCommands, type TextColorCommandsExtension } from './text-color-commands.ts'
|
|
4
|
+
import { defineTextColorSpec, type TextColorSpecExtension } from './text-color-spec.ts'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @internal
|
package/src/yjs/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export
|
|
6
|
-
export type
|
|
7
|
-
export {
|
|
1
|
+
export { defineYjsCommands } from './yjs-commands.ts'
|
|
2
|
+
export { defineYjsCursorPlugin, type YjsCursorOptions, type YjsCursorPluginOptions } from './yjs-cursor-plugin.ts'
|
|
3
|
+
export { defineYjsKeymap } from './yjs-keymap.ts'
|
|
4
|
+
export { defineYjsSyncPlugin, type YjsSyncOptions, type YjsSyncPluginOptions } from './yjs-sync-plugin.ts'
|
|
5
|
+
export type { Awareness } from './yjs-types.ts'
|
|
6
|
+
export { defineYjsUndoPlugin, type YjsUndoOptions, type YjsUndoPluginOptions } from './yjs-undo-plugin.ts'
|
|
7
|
+
export { defineYjs, type YjsExtension, type YjsOptions } from './yjs.ts'
|
|
@@ -2,7 +2,7 @@ import { definePlugin, type PlainExtension } from '@prosekit/core'
|
|
|
2
2
|
import type { Plugin } from '@prosekit/pm/state'
|
|
3
3
|
import { yCursorPlugin } from 'y-prosemirror'
|
|
4
4
|
|
|
5
|
-
import type { Awareness } from './yjs-types'
|
|
5
|
+
import type { Awareness } from './yjs-types.ts'
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Options for `y-prosemirror`'s `yCursorPlugin`.
|
package/src/yjs/yjs-types.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { definePlugin, type PlainExtension } from '@prosekit/core'
|
|
2
2
|
import type { ProseMirrorPlugin } from '@prosekit/pm/state'
|
|
3
3
|
import type { EditorView } from '@prosekit/pm/view'
|
|
4
|
-
import { yUndoPlugin as originalYUndoPlugin, yUndoPluginKey } from 'y-prosemirror'
|
|
4
|
+
import { yUndoPlugin as originalYUndoPlugin, yUndoPluginKey, type UndoPluginState } from 'y-prosemirror'
|
|
5
5
|
import type { UndoManager as YjsUndoManager } from 'yjs'
|
|
6
6
|
|
|
7
7
|
type UndoManager = YjsUndoManager & { restore: () => void }
|
|
@@ -12,7 +12,8 @@ type UndoManager = YjsUndoManager & { restore: () => void }
|
|
|
12
12
|
function fixYUndoPlugin(yUndoPluginInstance: ProseMirrorPlugin) {
|
|
13
13
|
const originalUndoPluginView = yUndoPluginInstance.spec.view
|
|
14
14
|
yUndoPluginInstance.spec.view = (view: EditorView) => {
|
|
15
|
-
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- The type definition in y-prosemirror is not correct. An explicit file extension should be added to this line: https://npmx.dev/package-code/y-prosemirror/v/1.3.7/dist%2Fsrc%2Fplugins%2Fkeys.d.ts#L13
|
|
16
|
+
const pluginState: UndoPluginState | undefined = yUndoPluginKey.getState(view.state)
|
|
16
17
|
if (!pluginState) {
|
|
17
18
|
return {}
|
|
18
19
|
}
|
package/src/yjs/yjs.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Priority, union, withPriority, type PlainExtension, type Union } from '@prosekit/core'
|
|
2
2
|
import type * as Y from 'yjs'
|
|
3
3
|
|
|
4
|
-
import { defineYjsCommands, type YjsCommandsExtension } from './yjs-commands'
|
|
5
|
-
import { defineYjsCursorPlugin, type YjsCursorPluginOptions } from './yjs-cursor-plugin'
|
|
6
|
-
import { defineYjsKeymap } from './yjs-keymap'
|
|
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'
|
|
4
|
+
import { defineYjsCommands, type YjsCommandsExtension } from './yjs-commands.ts'
|
|
5
|
+
import { defineYjsCursorPlugin, type YjsCursorPluginOptions } from './yjs-cursor-plugin.ts'
|
|
6
|
+
import { defineYjsKeymap } from './yjs-keymap.ts'
|
|
7
|
+
import { defineYjsSyncPlugin, type YjsSyncPluginOptions } from './yjs-sync-plugin.ts'
|
|
8
|
+
import type { Awareness } from './yjs-types.ts'
|
|
9
|
+
import { defineYjsUndoPlugin, type YjsUndoPluginOptions } from './yjs-undo-plugin.ts'
|
|
10
10
|
|
|
11
11
|
export interface YjsOptions {
|
|
12
12
|
/**
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { OBJECT_REPLACEMENT_CHARACTER, defineFacet, defineFacetPayload, getNodeType, isTextSelection, maybeRun, pluginFacet } from "@prosekit/core";
|
|
2
|
-
import { PluginKey, ProseMirrorPlugin } from "@prosekit/pm/state";
|
|
3
|
-
import { keydownHandler } from "@prosekit/pm/keymap";
|
|
4
|
-
|
|
5
|
-
//#region src/enter-rule/index.ts
|
|
6
|
-
/**
|
|
7
|
-
* Defines an enter rule. An enter rule applies when the text directly in front of
|
|
8
|
-
* the cursor matches `regex` and user presses Enter. The `regex` should end
|
|
9
|
-
* with `$`.
|
|
10
|
-
*
|
|
11
|
-
* @param options
|
|
12
|
-
*
|
|
13
|
-
* @public
|
|
14
|
-
*/
|
|
15
|
-
function defineEnterRule({ regex, handler, stop = false }) {
|
|
16
|
-
return defineFacetPayload(enterRule, [new EnterRule(regex, handler, stop)]);
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Defines an enter rule that replaces the matched text with a block node.
|
|
20
|
-
*
|
|
21
|
-
* See also {@link defineEnterRule}.
|
|
22
|
-
*
|
|
23
|
-
* @param options
|
|
24
|
-
*
|
|
25
|
-
* @public
|
|
26
|
-
*/
|
|
27
|
-
function defineTextBlockEnterRule({ regex, type, attrs, stop = true }) {
|
|
28
|
-
return defineEnterRule({
|
|
29
|
-
regex,
|
|
30
|
-
handler: ({ state, from, to, match }) => {
|
|
31
|
-
const nodeType = getNodeType(state.schema, type);
|
|
32
|
-
const $start = state.doc.resolve(from);
|
|
33
|
-
if (!$start.node(-1).canReplaceWith($start.index(-1), $start.indexAfter(-1), nodeType)) return null;
|
|
34
|
-
const nodeAttrs = maybeRun(attrs, match);
|
|
35
|
-
return state.tr.delete(from, to).setBlockType(from, from, nodeType, nodeAttrs);
|
|
36
|
-
},
|
|
37
|
-
stop
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* @internal
|
|
42
|
-
*/
|
|
43
|
-
var EnterRule = class {
|
|
44
|
-
constructor(regex, handler, stop) {
|
|
45
|
-
this.regex = regex;
|
|
46
|
-
this.handler = handler;
|
|
47
|
-
this.stop = stop;
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
const enterRule = defineFacet({
|
|
51
|
-
reduce: () => {
|
|
52
|
-
let rules = [];
|
|
53
|
-
const command = (state, dispatch, view) => {
|
|
54
|
-
if (!view) return false;
|
|
55
|
-
return execRules(view, rules, dispatch);
|
|
56
|
-
};
|
|
57
|
-
const handler = keydownHandler({ Enter: command });
|
|
58
|
-
const plugin = new ProseMirrorPlugin({
|
|
59
|
-
key: new PluginKey("prosekit-enter-rule"),
|
|
60
|
-
props: { handleKeyDown: handler }
|
|
61
|
-
});
|
|
62
|
-
return function reducer(inputs) {
|
|
63
|
-
rules = inputs;
|
|
64
|
-
return plugin;
|
|
65
|
-
};
|
|
66
|
-
},
|
|
67
|
-
parent: pluginFacet
|
|
68
|
-
});
|
|
69
|
-
function execRules(view, rules, dispatch) {
|
|
70
|
-
if (view.composing) return false;
|
|
71
|
-
const state = view.state;
|
|
72
|
-
const selection = state.selection;
|
|
73
|
-
if (!isTextSelection(selection)) return false;
|
|
74
|
-
const $cursor = selection.$cursor;
|
|
75
|
-
if (!$cursor || $cursor.parent.type.spec.code) return false;
|
|
76
|
-
const textBefore = $cursor.parent.textBetween(Math.max(0, $cursor.parentOffset - MAX_MATCH), $cursor.parentOffset, null, OBJECT_REPLACEMENT_CHARACTER);
|
|
77
|
-
for (const rule of rules) {
|
|
78
|
-
rule.regex.lastIndex = 0;
|
|
79
|
-
const match = rule.regex.exec(textBefore);
|
|
80
|
-
const tr = match && rule.handler({
|
|
81
|
-
state,
|
|
82
|
-
from: $cursor.pos - match[0].length,
|
|
83
|
-
to: $cursor.pos,
|
|
84
|
-
match
|
|
85
|
-
});
|
|
86
|
-
if (!tr) continue;
|
|
87
|
-
dispatch?.(tr);
|
|
88
|
-
if (rule.stop) return true;
|
|
89
|
-
}
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
92
|
-
const MAX_MATCH = 200;
|
|
93
|
-
|
|
94
|
-
//#endregion
|
|
95
|
-
export { defineTextBlockEnterRule as n, defineEnterRule as t };
|
|
96
|
-
//# sourceMappingURL=enter-rule-D-p4ykfv.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"enter-rule-D-p4ykfv.js","names":[],"sources":["../src/enter-rule/index.ts"],"sourcesContent":["import {\n defineFacet,\n defineFacetPayload,\n getNodeType,\n isTextSelection,\n maybeRun,\n OBJECT_REPLACEMENT_CHARACTER,\n pluginFacet,\n type PlainExtension,\n type PluginPayload,\n} from '@prosekit/core'\nimport { keydownHandler } from '@prosekit/pm/keymap'\nimport type { Attrs, NodeType } from '@prosekit/pm/model'\nimport { PluginKey, ProseMirrorPlugin, type Command, type EditorState, type Transaction } from '@prosekit/pm/state'\nimport type { EditorView } from '@prosekit/pm/view'\n\n/**\n * @public\n *\n * Options for {@link EnterRuleHandler}.\n */\nexport interface EnterRuleHandlerOptions {\n /**\n * The current editor state.\n */\n state: EditorState\n\n /**\n * The start position of the matched text.\n */\n from: number\n\n /**\n * The end position of the matched text.\n */\n to: number\n\n /**\n * The matched result from the regular expression.\n */\n match: RegExpExecArray\n}\n\n/**\n * @public\n */\nexport type EnterRuleHandler = (options: EnterRuleHandlerOptions) => Transaction | null\n\n/**\n * Options for {@link defineEnterRule}.\n *\n * @public\n */\nexport type EnterRuleOptions = {\n /**\n * The regular expression to match against. It should end with `$`.\n */\n regex: RegExp\n\n /**\n * A function to be called when an enter rule is triggered.\n */\n handler: EnterRuleHandler\n\n /**\n * Whether to stop further handlers from being called if this rule is triggered.\n *\n * @default false\n */\n stop?: boolean\n}\n\n/**\n * Options for {@link defineTextBlockEnterRule}.\n *\n * @public\n */\nexport interface TextBlockEnterRuleOptions {\n /**\n * The regular expression to match against. It should end with `$`.\n */\n regex: RegExp\n\n /**\n * The node type to replace the matched text with.\n */\n type: string | NodeType\n\n /**\n * Attributes to set on the node. If a function is provided, it will be called\n * with the matched result from the regular expression.\n */\n attrs?: Attrs | null | ((match: RegExpMatchArray) => Attrs | null)\n\n /**\n * Whether to stop further handlers from being called if this rule is triggered.\n *\n * @default true\n */\n stop?: boolean\n}\n\n/**\n * Defines an enter rule. An enter rule applies when the text directly in front of\n * the cursor matches `regex` and user presses Enter. The `regex` should end\n * with `$`.\n *\n * @param options\n *\n * @public\n */\nexport function defineEnterRule({\n regex,\n handler,\n stop = false,\n}: EnterRuleOptions): PlainExtension {\n const rule: EnterRule = new EnterRule(regex, handler, stop)\n return defineFacetPayload(enterRule, [rule]) as PlainExtension\n}\n\n/**\n * Defines an enter rule that replaces the matched text with a block node.\n *\n * See also {@link defineEnterRule}.\n *\n * @param options\n *\n * @public\n */\nexport function defineTextBlockEnterRule({\n regex,\n type,\n attrs,\n stop = true,\n}: TextBlockEnterRuleOptions): PlainExtension {\n return defineEnterRule({\n regex,\n handler: ({ state, from, to, match }) => {\n const nodeType = getNodeType(state.schema, type)\n const $start = state.doc.resolve(from)\n\n if (\n !$start\n .node(-1)\n .canReplaceWith($start.index(-1), $start.indexAfter(-1), nodeType)\n ) {\n return null\n }\n\n const nodeAttrs = maybeRun(attrs, match)\n return state.tr\n .delete(from, to)\n .setBlockType(from, from, nodeType, nodeAttrs)\n },\n stop,\n })\n}\n\n/**\n * @internal\n */\nclass EnterRule {\n constructor(\n readonly regex: RegExp,\n readonly handler: EnterRuleHandler,\n readonly stop: boolean,\n ) {}\n}\n\nconst enterRule = defineFacet<EnterRule, PluginPayload>({\n reduce: () => {\n let rules: EnterRule[] = []\n\n const command: Command = (state, dispatch, view) => {\n if (!view) return false\n return execRules(view, rules, dispatch)\n }\n const handler = keydownHandler({ Enter: command })\n const plugin = new ProseMirrorPlugin({\n key: new PluginKey('prosekit-enter-rule'),\n props: { handleKeyDown: handler },\n })\n\n return function reducer(inputs) {\n rules = inputs\n return plugin\n }\n },\n\n parent: pluginFacet,\n})\n\nfunction execRules(\n view: EditorView,\n rules: readonly EnterRule[],\n dispatch?: (tr: Transaction) => void,\n): boolean {\n if (view.composing) return false\n const state = view.state\n const selection = state.selection\n if (!isTextSelection(selection)) return false\n const $cursor = selection.$cursor\n if (!$cursor || $cursor.parent.type.spec.code) return false\n\n const textBefore = $cursor.parent.textBetween(\n Math.max(0, $cursor.parentOffset - MAX_MATCH),\n $cursor.parentOffset,\n null,\n OBJECT_REPLACEMENT_CHARACTER,\n )\n\n for (const rule of rules) {\n rule.regex.lastIndex = 0\n const match = rule.regex.exec(textBefore)\n const tr = match\n && rule.handler({\n state,\n from: $cursor.pos - match[0].length,\n to: $cursor.pos,\n match,\n })\n if (!tr) continue\n dispatch?.(tr)\n\n if (rule.stop) {\n return true\n }\n }\n return false\n}\n\nconst MAX_MATCH = 200\n"],"mappings":";;;;;;;;;;;;;;AA+GA,SAAgB,gBAAgB,EAC9B,OACA,SACA,OAAO,SAC4B;AAEnC,QAAO,mBAAmB,WAAW,CADb,IAAI,UAAU,OAAO,SAAS,KAAK,CAChB,CAAC;;;;;;;;;;;AAY9C,SAAgB,yBAAyB,EACvC,OACA,MACA,OACA,OAAO,QACqC;AAC5C,QAAO,gBAAgB;EACrB;EACA,UAAU,EAAE,OAAO,MAAM,IAAI,YAAY;GACvC,MAAM,WAAW,YAAY,MAAM,QAAQ,KAAK;GAChD,MAAM,SAAS,MAAM,IAAI,QAAQ,KAAK;AAEtC,OACE,CAAC,OACE,KAAK,GAAG,CACR,eAAe,OAAO,MAAM,GAAG,EAAE,OAAO,WAAW,GAAG,EAAE,SAAS,CAEpE,QAAO;GAGT,MAAM,YAAY,SAAS,OAAO,MAAM;AACxC,UAAO,MAAM,GACV,OAAO,MAAM,GAAG,CAChB,aAAa,MAAM,MAAM,UAAU,UAAU;;EAElD;EACD,CAAC;;;;;AAMJ,IAAM,YAAN,MAAgB;CACd,YACE,AAAS,OACT,AAAS,SACT,AAAS,MACT;EAHS;EACA;EACA;;;AAIb,MAAM,YAAY,YAAsC;CACtD,cAAc;EACZ,IAAI,QAAqB,EAAE;EAE3B,MAAM,WAAoB,OAAO,UAAU,SAAS;AAClD,OAAI,CAAC,KAAM,QAAO;AAClB,UAAO,UAAU,MAAM,OAAO,SAAS;;EAEzC,MAAM,UAAU,eAAe,EAAE,OAAO,SAAS,CAAC;EAClD,MAAM,SAAS,IAAI,kBAAkB;GACnC,KAAK,IAAI,UAAU,sBAAsB;GACzC,OAAO,EAAE,eAAe,SAAS;GAClC,CAAC;AAEF,SAAO,SAAS,QAAQ,QAAQ;AAC9B,WAAQ;AACR,UAAO;;;CAIX,QAAQ;CACT,CAAC;AAEF,SAAS,UACP,MACA,OACA,UACS;AACT,KAAI,KAAK,UAAW,QAAO;CAC3B,MAAM,QAAQ,KAAK;CACnB,MAAM,YAAY,MAAM;AACxB,KAAI,CAAC,gBAAgB,UAAU,CAAE,QAAO;CACxC,MAAM,UAAU,UAAU;AAC1B,KAAI,CAAC,WAAW,QAAQ,OAAO,KAAK,KAAK,KAAM,QAAO;CAEtD,MAAM,aAAa,QAAQ,OAAO,YAChC,KAAK,IAAI,GAAG,QAAQ,eAAe,UAAU,EAC7C,QAAQ,cACR,MACA,6BACD;AAED,MAAK,MAAM,QAAQ,OAAO;AACxB,OAAK,MAAM,YAAY;EACvB,MAAM,QAAQ,KAAK,MAAM,KAAK,WAAW;EACzC,MAAM,KAAK,SACN,KAAK,QAAQ;GACd;GACA,MAAM,QAAQ,MAAM,MAAM,GAAG;GAC7B,IAAI,QAAQ;GACZ;GACD,CAAC;AACJ,MAAI,CAAC,GAAI;AACT,aAAW,GAAG;AAEd,MAAI,KAAK,KACP,QAAO;;AAGX,QAAO;;AAGT,MAAM,YAAY"}
|