@prosekit/core 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{editor-4lgGc3CY.d.ts → editor.d.ts} +58 -18
- package/dist/editor.d.ts.map +1 -0
- package/dist/{editor-DGNUXn-u.js → editor.js} +40 -81
- package/dist/editor.js.map +1 -0
- package/dist/prosekit-core-test.d.ts +1 -2
- package/dist/prosekit-core-test.d.ts.map +1 -1
- package/dist/prosekit-core-test.js +2 -4
- package/dist/prosekit-core-test.js.map +1 -1
- package/dist/prosekit-core.d.ts +148 -68
- package/dist/prosekit-core.d.ts.map +1 -1
- package/dist/prosekit-core.js +184 -138
- package/dist/prosekit-core.js.map +1 -1
- package/package.json +9 -9
- package/src/commands/add-mark.ts +3 -6
- package/src/commands/expand-mark.ts +4 -11
- package/src/commands/insert-default-block.spec.ts +4 -8
- package/src/commands/insert-default-block.ts +2 -5
- package/src/commands/insert-node.ts +7 -11
- package/src/commands/remove-mark.ts +3 -6
- package/src/commands/remove-node.ts +4 -4
- package/src/commands/select-block.spec.ts +6 -8
- package/src/commands/select-block.ts +2 -5
- package/src/commands/set-block-type.ts +3 -6
- package/src/commands/set-node-attrs-between.spec.ts +221 -0
- package/src/commands/set-node-attrs-between.ts +77 -0
- package/src/commands/set-node-attrs.spec.ts +129 -0
- package/src/commands/set-node-attrs.ts +26 -27
- package/src/commands/toggle-mark.ts +3 -6
- package/src/commands/toggle-node.ts +4 -7
- package/src/commands/toggle-wrap.spec.ts +2 -6
- package/src/commands/toggle-wrap.ts +3 -6
- package/src/commands/unset-block-type.spec.ts +2 -6
- package/src/commands/unset-block-type.ts +3 -9
- package/src/commands/unset-mark.spec.ts +2 -6
- package/src/commands/unset-mark.ts +1 -1
- package/src/commands/wrap.ts +2 -5
- package/src/editor/action.spec.ts +5 -9
- package/src/editor/action.ts +7 -14
- package/src/editor/editor.spec.ts +8 -15
- package/src/editor/editor.ts +18 -52
- package/src/editor/union.spec.ts +8 -12
- package/src/editor/union.ts +4 -7
- package/src/editor/with-priority.ts +3 -3
- package/src/error.ts +8 -1
- package/src/extensions/clipboard-serializer.ts +22 -26
- package/src/extensions/command.ts +22 -54
- package/src/extensions/default-state.spec.ts +4 -8
- package/src/extensions/default-state.ts +6 -12
- package/src/extensions/events/doc-change.ts +2 -2
- package/src/extensions/events/dom-event.spec.ts +4 -9
- package/src/extensions/events/dom-event.ts +9 -21
- package/src/extensions/events/editor-event.ts +8 -20
- package/src/extensions/events/focus.spec.ts +7 -12
- package/src/extensions/events/focus.ts +2 -2
- package/src/extensions/events/plugin-view.ts +5 -12
- package/src/extensions/history.ts +7 -14
- package/src/extensions/keymap-base.spec.ts +6 -15
- package/src/extensions/keymap-base.ts +6 -9
- package/src/extensions/keymap.spec.ts +10 -24
- package/src/extensions/keymap.ts +5 -15
- package/src/extensions/mark-spec.spec.ts +6 -21
- package/src/extensions/mark-spec.ts +10 -21
- package/src/extensions/mark-view-effect.ts +6 -12
- package/src/extensions/mark-view.ts +5 -11
- package/src/extensions/node-spec.spec.ts +10 -26
- package/src/extensions/node-spec.ts +10 -21
- package/src/extensions/node-view-effect.ts +6 -12
- package/src/extensions/node-view.ts +5 -11
- package/src/extensions/plugin.spec.ts +9 -22
- package/src/extensions/plugin.ts +6 -15
- package/src/facets/base-extension.ts +7 -10
- package/src/facets/command.ts +3 -9
- package/src/facets/facet-extension.spec.ts +10 -21
- package/src/facets/facet-extension.ts +12 -8
- package/src/facets/facet-node.spec.ts +4 -11
- package/src/facets/facet-node.ts +27 -22
- package/src/facets/facet.spec.ts +2 -5
- package/src/facets/facet.ts +14 -7
- package/src/facets/root.ts +2 -2
- package/src/facets/schema-spec.ts +3 -10
- package/src/facets/schema.ts +4 -13
- package/src/facets/state.spec.ts +8 -15
- package/src/facets/state.ts +5 -19
- package/src/facets/union-extension.ts +10 -13
- package/src/index.ts +74 -200
- package/src/test/index.ts +1 -4
- package/src/test/test-builder.ts +2 -5
- package/src/test/test-editor.spec.ts +2 -6
- package/src/test/test-editor.ts +7 -26
- package/src/testing/index.ts +26 -22
- package/src/types/extension-mark.ts +1 -1
- package/src/types/extension-node.ts +1 -1
- package/src/types/extension.spec.ts +2 -5
- package/src/types/extension.ts +8 -18
- package/src/types/pick-string-literal.spec.ts +2 -2
- package/src/types/pick-string-literal.ts +1 -1
- package/src/types/pick-sub-type.spec.ts +2 -2
- package/src/types/priority.ts +50 -7
- package/src/types/simplify-deeper.spec.ts +2 -2
- package/src/types/simplify-union.spec.ts +2 -2
- package/src/types/simplify-union.ts +1 -4
- package/src/utils/array-grouping.spec.ts +2 -5
- package/src/utils/assert.ts +1 -1
- package/src/utils/attrs-match.ts +1 -5
- package/src/utils/can-use-regex-lookbehind.ts +2 -8
- package/src/utils/clsx.spec.ts +2 -5
- package/src/utils/combine-event-handlers.spec.ts +2 -6
- package/src/utils/default-block-at.ts +1 -4
- package/src/utils/editor-content.spec.ts +3 -6
- package/src/utils/editor-content.ts +5 -17
- package/src/utils/find-node.ts +65 -0
- package/src/utils/find-parent-node-of-type.ts +6 -12
- package/src/utils/find-parent-node.spec.ts +3 -7
- package/src/utils/find-parent-node.ts +1 -4
- package/src/utils/get-custom-selection.ts +1 -5
- package/src/utils/get-dom-api.ts +1 -1
- package/src/utils/get-mark-type.ts +2 -5
- package/src/utils/get-node-type.ts +2 -5
- package/src/utils/get-node-types.ts +2 -5
- package/src/utils/includes-mark.ts +2 -6
- package/src/utils/is-at-block-start.ts +1 -4
- package/src/utils/is-mark-absent.spec.ts +3 -6
- package/src/utils/is-mark-absent.ts +2 -6
- package/src/utils/is-mark-active.ts +4 -7
- package/src/utils/is-node-active.spec.ts +109 -0
- package/src/utils/is-node-active.ts +19 -10
- package/src/utils/is-subset.spec.ts +2 -5
- package/src/utils/maybe-run.spec.ts +2 -6
- package/src/utils/merge-objects.spec.ts +2 -5
- package/src/utils/merge-objects.ts +3 -2
- package/src/utils/merge-specs.ts +2 -5
- package/src/utils/object-equal.spec.ts +2 -5
- package/src/utils/output-spec.test.ts +2 -6
- package/src/utils/output-spec.ts +2 -10
- package/src/utils/parse.spec.ts +6 -15
- package/src/utils/parse.ts +4 -16
- package/src/utils/remove-undefined-values.spec.ts +2 -5
- package/src/utils/set-selection-around.ts +1 -4
- package/src/utils/type-assertion.ts +2 -21
- package/src/utils/unicode.spec.ts +2 -5
- package/src/utils/with-skip-code-block.ts +1 -1
- package/dist/editor-4lgGc3CY.d.ts.map +0 -1
- package/dist/editor-DGNUXn-u.js.map +0 -1
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Attrs,
|
|
3
|
-
NodeType,
|
|
4
|
-
} from '@prosekit/pm/model'
|
|
1
|
+
import type { Attrs, NodeType } from '@prosekit/pm/model'
|
|
5
2
|
import type { Command } from '@prosekit/pm/state'
|
|
6
3
|
|
|
7
|
-
import {
|
|
4
|
+
import { findParentNodeOfType } from '../utils/find-parent-node-of-type.ts'
|
|
5
|
+
import { getNodeTypes } from '../utils/get-node-types.ts'
|
|
8
6
|
|
|
9
7
|
/**
|
|
10
8
|
* @public
|
|
@@ -12,8 +10,6 @@ import { getNodeTypes } from '../utils/get-node-types'
|
|
|
12
10
|
export interface SetNodeAttrsOptions {
|
|
13
11
|
/**
|
|
14
12
|
* The type of node to set the attributes of.
|
|
15
|
-
*
|
|
16
|
-
* If current node is not of this type, the command will do nothing.
|
|
17
13
|
*/
|
|
18
14
|
type: string | NodeType | string[] | NodeType[]
|
|
19
15
|
|
|
@@ -23,43 +19,46 @@ export interface SetNodeAttrsOptions {
|
|
|
23
19
|
attrs: Attrs
|
|
24
20
|
|
|
25
21
|
/**
|
|
26
|
-
* The position of the node
|
|
27
|
-
*
|
|
22
|
+
* The document position of the node to update. If not provided, the command
|
|
23
|
+
* will find the closest ancestor node that matches the type based on the
|
|
24
|
+
* anchor position of the selection.
|
|
28
25
|
*/
|
|
29
26
|
pos?: number
|
|
30
27
|
}
|
|
31
28
|
|
|
32
29
|
/**
|
|
33
|
-
* Returns a command that
|
|
30
|
+
* Returns a command that sets the attributes of the current node.
|
|
31
|
+
*
|
|
32
|
+
* @param options
|
|
34
33
|
*
|
|
35
34
|
* @public
|
|
36
35
|
*/
|
|
37
|
-
export function setNodeAttrs(
|
|
36
|
+
export function setNodeAttrs({ type, attrs, pos }: SetNodeAttrsOptions): Command {
|
|
38
37
|
return (state, dispatch) => {
|
|
39
|
-
|
|
40
|
-
const from = options.pos ?? state.selection.from
|
|
41
|
-
const to = options.pos ?? state.selection.to
|
|
42
|
-
const positions: number[] = []
|
|
38
|
+
let updatePos: number
|
|
43
39
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
40
|
+
if (pos == null) {
|
|
41
|
+
const found = findParentNodeOfType(type, state.selection.$anchor)
|
|
42
|
+
if (!found) {
|
|
43
|
+
return false
|
|
47
44
|
}
|
|
48
|
-
|
|
45
|
+
updatePos = found.pos
|
|
46
|
+
} else {
|
|
47
|
+
const found = state.doc.nodeAt(pos)
|
|
48
|
+
if (!found) {
|
|
49
49
|
return false
|
|
50
50
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
51
|
+
const nodeTypes = getNodeTypes(state.schema, type)
|
|
52
|
+
if (!nodeTypes.includes(found.type)) {
|
|
53
|
+
return false
|
|
54
|
+
}
|
|
55
|
+
updatePos = pos
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
if (dispatch) {
|
|
58
59
|
const { tr } = state
|
|
59
|
-
for (const
|
|
60
|
-
|
|
61
|
-
tr.setNodeAttribute(pos, key, value)
|
|
62
|
-
}
|
|
60
|
+
for (const [key, value] of Object.entries(attrs)) {
|
|
61
|
+
tr.setNodeAttribute(updatePos, key, value)
|
|
63
62
|
}
|
|
64
63
|
dispatch(tr)
|
|
65
64
|
}
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { toggleMark as baseToggleMark } from '@prosekit/pm/commands'
|
|
2
|
-
import type {
|
|
3
|
-
Attrs,
|
|
4
|
-
MarkType,
|
|
5
|
-
} from '@prosekit/pm/model'
|
|
2
|
+
import type { Attrs, MarkType } from '@prosekit/pm/model'
|
|
6
3
|
import type { Command } from '@prosekit/pm/state'
|
|
7
4
|
|
|
8
|
-
import type { CommandCreator } from '../types/extension-command'
|
|
9
|
-
import { getMarkType } from '../utils/get-mark-type'
|
|
5
|
+
import type { CommandCreator } from '../types/extension-command.ts'
|
|
6
|
+
import { getMarkType } from '../utils/get-mark-type.ts'
|
|
10
7
|
|
|
11
8
|
/**
|
|
12
9
|
* @public
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { setBlockType } from '@prosekit/pm/commands'
|
|
2
|
-
import type {
|
|
3
|
-
Attrs,
|
|
4
|
-
NodeType,
|
|
5
|
-
} from '@prosekit/pm/model'
|
|
2
|
+
import type { Attrs, NodeType } from '@prosekit/pm/model'
|
|
6
3
|
import type { Command } from '@prosekit/pm/state'
|
|
7
4
|
|
|
8
|
-
import { getNodeType } from '../utils/get-node-type'
|
|
9
|
-
import { isNodeActive } from '../utils/is-node-active'
|
|
5
|
+
import { getNodeType } from '../utils/get-node-type.ts'
|
|
6
|
+
import { isNodeActive } from '../utils/is-node-active.ts'
|
|
10
7
|
|
|
11
8
|
/**
|
|
12
9
|
* @public
|
|
@@ -24,7 +21,7 @@ export interface ToggleNodeOptions {
|
|
|
24
21
|
}
|
|
25
22
|
|
|
26
23
|
/**
|
|
27
|
-
* Returns a command that
|
|
24
|
+
* Returns a command that sets the selected textblocks to the given node type
|
|
28
25
|
* with the given attributes.
|
|
29
26
|
*
|
|
30
27
|
* @param options
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
describe,
|
|
3
|
-
expect,
|
|
4
|
-
it,
|
|
5
|
-
} from 'vitest'
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
6
2
|
|
|
7
|
-
import { setupTest } from '../testing'
|
|
3
|
+
import { setupTest } from '../testing/index.ts'
|
|
8
4
|
|
|
9
5
|
describe('toggle-wrap', () => {
|
|
10
6
|
it('adds the node wrapping the selection', () => {
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import { lift } from '@prosekit/pm/commands'
|
|
2
|
-
import type {
|
|
3
|
-
Attrs,
|
|
4
|
-
NodeType,
|
|
5
|
-
} from '@prosekit/pm/model'
|
|
2
|
+
import type { Attrs, NodeType } from '@prosekit/pm/model'
|
|
6
3
|
import type { Command } from '@prosekit/pm/state'
|
|
7
4
|
|
|
8
|
-
import { isNodeActive } from '../utils/is-node-active'
|
|
5
|
+
import { isNodeActive } from '../utils/is-node-active.ts'
|
|
9
6
|
|
|
10
|
-
import { wrap } from './wrap'
|
|
7
|
+
import { wrap } from './wrap.ts'
|
|
11
8
|
|
|
12
9
|
export interface ToggleWrapOptions {
|
|
13
10
|
/**
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
describe,
|
|
3
|
-
expect,
|
|
4
|
-
it,
|
|
5
|
-
} from 'vitest'
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
6
2
|
|
|
7
|
-
import { setupTest } from '../testing'
|
|
3
|
+
import { setupTest } from '../testing/index.ts'
|
|
8
4
|
|
|
9
5
|
describe('unsetBlockType', () => {
|
|
10
6
|
it('can unset a single block', () => {
|
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
Slice,
|
|
4
|
-
} from '@prosekit/pm/model'
|
|
5
|
-
import type {
|
|
6
|
-
Command,
|
|
7
|
-
Transaction,
|
|
8
|
-
} from '@prosekit/pm/state'
|
|
1
|
+
import { Fragment, Slice } from '@prosekit/pm/model'
|
|
2
|
+
import type { Command, Transaction } from '@prosekit/pm/state'
|
|
9
3
|
import { ReplaceAroundStep } from '@prosekit/pm/transform'
|
|
10
4
|
|
|
11
|
-
import type { CommandCreator } from '../types/extension-command'
|
|
5
|
+
import type { CommandCreator } from '../types/extension-command.ts'
|
|
12
6
|
|
|
13
7
|
/**
|
|
14
8
|
* @public
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
describe,
|
|
3
|
-
expect,
|
|
4
|
-
it,
|
|
5
|
-
} from 'vitest'
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
6
2
|
|
|
7
|
-
import { setupTest } from '../testing'
|
|
3
|
+
import { setupTest } from '../testing/index.ts'
|
|
8
4
|
|
|
9
5
|
describe('unsetMark', () => {
|
|
10
6
|
it('can unset marks', () => {
|
package/src/commands/wrap.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Attrs,
|
|
3
|
-
NodeType,
|
|
4
|
-
} from '@prosekit/pm/model'
|
|
1
|
+
import type { Attrs, NodeType } from '@prosekit/pm/model'
|
|
5
2
|
import type { Command } from '@prosekit/pm/state'
|
|
6
3
|
import { findWrapping } from '@prosekit/pm/transform'
|
|
7
4
|
|
|
8
|
-
import { getNodeType } from '../utils/get-node-type'
|
|
5
|
+
import { getNodeType } from '../utils/get-node-type.ts'
|
|
9
6
|
|
|
10
7
|
/**
|
|
11
8
|
* @public
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
describe,
|
|
3
|
-
expect,
|
|
4
|
-
it,
|
|
5
|
-
} from 'vitest'
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
6
2
|
|
|
7
|
-
import { setupTest } from '../testing'
|
|
8
|
-
import { jsonFromNode } from '../utils/parse'
|
|
3
|
+
import { setupTest } from '../testing/index.ts'
|
|
4
|
+
import { jsonFromNode } from '../utils/parse.ts'
|
|
9
5
|
|
|
10
|
-
import type { NodeChild } from './action'
|
|
6
|
+
import type { NodeChild } from './action.ts'
|
|
11
7
|
|
|
12
8
|
describe('NodeAction', () => {
|
|
13
9
|
const { editor, n } = setupTest()
|
|
@@ -22,7 +18,7 @@ describe('NodeAction', () => {
|
|
|
22
18
|
it('can apply node with attrs', () => {
|
|
23
19
|
expect(n.codeBlock({ language: 'javascript' }, 'foo').toJSON()).toEqual({
|
|
24
20
|
type: 'codeBlock',
|
|
25
|
-
attrs: { language: 'javascript' },
|
|
21
|
+
attrs: { language: 'javascript', lineNumbers: false },
|
|
26
22
|
content: [{ text: 'foo', type: 'text' }],
|
|
27
23
|
})
|
|
28
24
|
})
|
package/src/editor/action.ts
CHANGED
|
@@ -1,20 +1,13 @@
|
|
|
1
1
|
import { mapValues } from '@ocavue/utils'
|
|
2
|
-
import type {
|
|
3
|
-
Attrs,
|
|
4
|
-
Mark,
|
|
5
|
-
MarkType,
|
|
6
|
-
NodeType,
|
|
7
|
-
ProseMirrorNode,
|
|
8
|
-
Schema,
|
|
9
|
-
} from '@prosekit/pm/model'
|
|
2
|
+
import type { Attrs, Mark, MarkType, NodeType, ProseMirrorNode, Schema } from '@prosekit/pm/model'
|
|
10
3
|
import type { EditorState } from '@prosekit/pm/state'
|
|
11
4
|
|
|
12
|
-
import { ProseKitError } from '../error'
|
|
13
|
-
import type { AnyAttrs } from '../types/attrs'
|
|
14
|
-
import { assert } from '../utils/assert'
|
|
15
|
-
import { isMarkActive } from '../utils/is-mark-active'
|
|
16
|
-
import { isNodeActive } from '../utils/is-node-active'
|
|
17
|
-
import { isProseMirrorNode } from '../utils/type-assertion'
|
|
5
|
+
import { ProseKitError } from '../error.ts'
|
|
6
|
+
import type { AnyAttrs } from '../types/attrs.ts'
|
|
7
|
+
import { assert } from '../utils/assert.ts'
|
|
8
|
+
import { isMarkActive } from '../utils/is-mark-active.ts'
|
|
9
|
+
import { isNodeActive } from '../utils/is-node-active.ts'
|
|
10
|
+
import { isProseMirrorNode } from '../utils/type-assertion.ts'
|
|
18
11
|
|
|
19
12
|
/**
|
|
20
13
|
* Available children parameters for {@link NodeAction} and {@link MarkAction}.
|
|
@@ -1,18 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
} from '
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
defineTestExtension,
|
|
11
|
-
setupTest,
|
|
12
|
-
} from '../testing'
|
|
13
|
-
import type { NodeJSON } from '../types/model'
|
|
14
|
-
|
|
15
|
-
import { createEditor } from './editor'
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import { insertText } from '../commands/insert-text.ts'
|
|
4
|
+
import { wrap } from '../commands/wrap.ts'
|
|
5
|
+
import { defineTestExtension, setupTest } from '../testing/index.ts'
|
|
6
|
+
import type { NodeJSON } from '../types/model.ts'
|
|
7
|
+
|
|
8
|
+
import { createEditor } from './editor.ts'
|
|
16
9
|
|
|
17
10
|
describe('createEditor', () => {
|
|
18
11
|
it('can mount the editor', () => {
|
package/src/editor/editor.ts
CHANGED
|
@@ -1,29 +1,13 @@
|
|
|
1
1
|
import { isDeepEqual } from '@ocavue/utils'
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
type Transaction,
|
|
12
|
-
} from '@prosekit/pm/state'
|
|
13
|
-
import {
|
|
14
|
-
EditorView,
|
|
15
|
-
type DirectEditorProps,
|
|
16
|
-
type EditorProps,
|
|
17
|
-
} from '@prosekit/pm/view'
|
|
18
|
-
|
|
19
|
-
import { ProseKitError } from '../error'
|
|
20
|
-
import { defineDefaultState } from '../extensions/default-state'
|
|
21
|
-
import type { BaseExtension } from '../facets/base-extension'
|
|
22
|
-
import {
|
|
23
|
-
subtractFacetNode,
|
|
24
|
-
unionFacetNode,
|
|
25
|
-
type FacetNode,
|
|
26
|
-
} from '../facets/facet-node'
|
|
2
|
+
import type { ProseMirrorNode, Schema } from '@prosekit/pm/model'
|
|
3
|
+
import { EditorState, type Command, type Plugin, type Selection, type Transaction } from '@prosekit/pm/state'
|
|
4
|
+
import { EditorView, type DirectEditorProps, type EditorProps } from '@prosekit/pm/view'
|
|
5
|
+
|
|
6
|
+
import { ProseKitError } from '../error.ts'
|
|
7
|
+
import { defineDefaultState } from '../extensions/default-state.ts'
|
|
8
|
+
import type { BaseExtension } from '../facets/base-extension.ts'
|
|
9
|
+
import { subtractFacetNode, unionFacetNode, type FacetNode } from '../facets/facet-node.ts'
|
|
10
|
+
import type { CommandAction, CommandCreator } from '../types/extension-command.ts'
|
|
27
11
|
import type {
|
|
28
12
|
Extension,
|
|
29
13
|
ExtractCommandActions,
|
|
@@ -31,33 +15,14 @@ import type {
|
|
|
31
15
|
ExtractMarkNames,
|
|
32
16
|
ExtractNodeActions,
|
|
33
17
|
ExtractNodeNames,
|
|
34
|
-
} from '../types/extension'
|
|
35
|
-
import type {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
} from '../
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
} from '../types/model'
|
|
43
|
-
import { assert } from '../utils/assert'
|
|
44
|
-
import {
|
|
45
|
-
getEditorContentDoc,
|
|
46
|
-
getEditorSelection,
|
|
47
|
-
} from '../utils/editor-content'
|
|
48
|
-
import {
|
|
49
|
-
htmlFromNode,
|
|
50
|
-
jsonFromNode,
|
|
51
|
-
type DOMDocumentOptions,
|
|
52
|
-
} from '../utils/parse'
|
|
53
|
-
|
|
54
|
-
import {
|
|
55
|
-
createMarkActions,
|
|
56
|
-
createNodeActions,
|
|
57
|
-
type MarkAction,
|
|
58
|
-
type NodeAction,
|
|
59
|
-
} from './action'
|
|
60
|
-
import { union } from './union'
|
|
18
|
+
} from '../types/extension.ts'
|
|
19
|
+
import type { NodeJSON, SelectionJSON } from '../types/model.ts'
|
|
20
|
+
import { assert } from '../utils/assert.ts'
|
|
21
|
+
import { getEditorContentDoc, getEditorSelection } from '../utils/editor-content.ts'
|
|
22
|
+
import { htmlFromNode, jsonFromNode, type DOMDocumentOptions } from '../utils/parse.ts'
|
|
23
|
+
|
|
24
|
+
import { createMarkActions, createNodeActions, type MarkAction, type NodeAction } from './action.ts'
|
|
25
|
+
import { union } from './union.ts'
|
|
61
26
|
|
|
62
27
|
/**
|
|
63
28
|
* @public
|
|
@@ -297,6 +262,7 @@ export class EditorInstance {
|
|
|
297
262
|
}
|
|
298
263
|
this.view = new EditorView({ mount: place }, this.directEditorProps)
|
|
299
264
|
this.afterMounted.forEach((callback) => callback())
|
|
265
|
+
this.afterMounted.length = 0
|
|
300
266
|
}
|
|
301
267
|
|
|
302
268
|
public unmount(): void {
|
package/src/editor/union.spec.ts
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
import type { Attrs } from '@prosekit/pm/model'
|
|
2
2
|
import type { Command } from '@prosekit/pm/state'
|
|
3
|
-
import {
|
|
4
|
-
describe,
|
|
5
|
-
expectTypeOf,
|
|
6
|
-
it,
|
|
7
|
-
} from 'vitest'
|
|
3
|
+
import { describe, expectTypeOf, it } from 'vitest'
|
|
8
4
|
|
|
9
|
-
import { defineCommands } from '../extensions/command'
|
|
10
|
-
import { defineMarkSpec } from '../extensions/mark-spec'
|
|
11
|
-
import { defineNodeSpec } from '../extensions/node-spec'
|
|
12
|
-
import { assertTypeEqual } from '../types/assert-type-equal'
|
|
13
|
-
import type {
|
|
14
|
-
import type {
|
|
5
|
+
import { defineCommands } from '../extensions/command.ts'
|
|
6
|
+
import { defineMarkSpec } from '../extensions/mark-spec.ts'
|
|
7
|
+
import { defineNodeSpec } from '../extensions/node-spec.ts'
|
|
8
|
+
import { assertTypeEqual } from '../types/assert-type-equal.ts'
|
|
9
|
+
import type { CommandCreator } from '../types/extension-command.ts'
|
|
10
|
+
import type { Extension } from '../types/extension.ts'
|
|
15
11
|
|
|
16
|
-
import { union } from './union'
|
|
12
|
+
import { union } from './union.ts'
|
|
17
13
|
|
|
18
14
|
describe('union', () => {
|
|
19
15
|
it('can merge one extension types', () => {
|
package/src/editor/union.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import type { BaseExtension } from '../facets/base-extension'
|
|
2
|
-
import { UnionExtensionImpl } from '../facets/union-extension'
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
Union,
|
|
6
|
-
} from '../types/extension'
|
|
7
|
-
import { assert } from '../utils/assert'
|
|
1
|
+
import type { BaseExtension } from '../facets/base-extension.ts'
|
|
2
|
+
import { UnionExtensionImpl } from '../facets/union-extension.ts'
|
|
3
|
+
import type { Extension, Union } from '../types/extension.ts'
|
|
4
|
+
import { assert } from '../utils/assert.ts'
|
|
8
5
|
|
|
9
6
|
/**
|
|
10
7
|
* Merges multiple extensions into one. You can pass multiple extensions as
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { Extension } from '../types/extension'
|
|
2
|
-
import type { Priority } from '../types/priority'
|
|
1
|
+
import type { Extension } from '../types/extension.ts'
|
|
2
|
+
import type { Priority } from '../types/priority.ts'
|
|
3
3
|
|
|
4
|
-
import { union } from './union'
|
|
4
|
+
import { union } from './union.ts'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Return an new extension with the given priority.
|
package/src/error.ts
CHANGED
|
@@ -3,7 +3,14 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @internal
|
|
5
5
|
*/
|
|
6
|
-
export class ProseKitError extends Error {
|
|
6
|
+
export class ProseKitError extends Error {
|
|
7
|
+
constructor(message?: string, options?: ErrorOptions) {
|
|
8
|
+
if (typeof message === 'string' && !message.startsWith('[')) {
|
|
9
|
+
message = `[prosekit] ${message}`
|
|
10
|
+
}
|
|
11
|
+
super(message, options)
|
|
12
|
+
}
|
|
13
|
+
}
|
|
7
14
|
|
|
8
15
|
/**
|
|
9
16
|
* @internal
|
|
@@ -1,25 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from '
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
} from '@prosekit/pm/state'
|
|
12
|
-
|
|
13
|
-
import { defineFacet } from '../facets/facet'
|
|
14
|
-
import { defineFacetPayload } from '../facets/facet-extension'
|
|
15
|
-
import type { AnyFunction } from '../types/any-function'
|
|
16
|
-
import type { PlainExtension } from '../types/extension'
|
|
17
|
-
import { isNotNullish } from '../utils/type-assertion'
|
|
18
|
-
|
|
19
|
-
import {
|
|
20
|
-
pluginFacet,
|
|
21
|
-
type PluginPayload,
|
|
22
|
-
} from './plugin'
|
|
1
|
+
import { isNotNullish } from '@ocavue/utils'
|
|
2
|
+
import { DOMSerializer, type DOMOutputSpec, type Mark, type ProseMirrorNode, type Schema } from '@prosekit/pm/model'
|
|
3
|
+
import { PluginKey, ProseMirrorPlugin } from '@prosekit/pm/state'
|
|
4
|
+
|
|
5
|
+
import { defineFacetPayload } from '../facets/facet-extension.ts'
|
|
6
|
+
import { defineFacet } from '../facets/facet.ts'
|
|
7
|
+
import type { AnyFunction } from '../types/any-function.ts'
|
|
8
|
+
import type { PlainExtension } from '../types/extension.ts'
|
|
9
|
+
|
|
10
|
+
import { pluginFacet, type PluginPayload } from './plugin.ts'
|
|
23
11
|
|
|
24
12
|
type SerializeFragmentFunction = typeof DOMSerializer.prototype.serializeFragment
|
|
25
13
|
type SerializeNodeFunction = typeof DOMSerializer.prototype.serializeNode
|
|
@@ -47,29 +35,37 @@ function wrapFunction<T extends AnyFunction>(fn: T, wrapper?: FunctionWrapper<T>
|
|
|
47
35
|
}
|
|
48
36
|
|
|
49
37
|
class CustomDOMSerializer extends DOMSerializer {
|
|
38
|
+
private serializeFragmentWrapper?: FunctionWrapper<SerializeFragmentFunction>
|
|
39
|
+
private serializeNodeWrapper?: FunctionWrapper<SerializeNodeFunction>
|
|
40
|
+
|
|
50
41
|
constructor(
|
|
51
42
|
nodes: Record<string, (node: ProseMirrorNode) => DOMOutputSpec>,
|
|
52
43
|
marks: Record<string, (mark: Mark, inline: boolean) => DOMOutputSpec>,
|
|
53
|
-
|
|
54
|
-
|
|
44
|
+
serializeFragmentWrapper?: FunctionWrapper<SerializeFragmentFunction>,
|
|
45
|
+
serializeNodeWrapper?: FunctionWrapper<SerializeNodeFunction>,
|
|
55
46
|
) {
|
|
56
47
|
super(nodes, marks)
|
|
48
|
+
this.serializeFragmentWrapper = serializeFragmentWrapper
|
|
49
|
+
this.serializeNodeWrapper = serializeNodeWrapper
|
|
57
50
|
}
|
|
58
51
|
|
|
59
52
|
override serializeFragment(...args: Parameters<SerializeFragmentFunction>): ReturnType<SerializeFragmentFunction> {
|
|
53
|
+
// eslint-disable-next-line unicorn/consistent-function-scoping -- See https://github.com/sindresorhus/eslint-plugin-unicorn/issues/2088
|
|
60
54
|
const fn: SerializeFragmentFunction = (...args) => super.serializeFragment(...args)
|
|
61
55
|
return wrapFunction(fn, this.serializeFragmentWrapper)(...args)
|
|
62
56
|
}
|
|
63
57
|
|
|
64
58
|
override serializeNode(...args: Parameters<SerializeNodeFunction>): ReturnType<SerializeNodeFunction> {
|
|
59
|
+
// eslint-disable-next-line unicorn/consistent-function-scoping -- See https://github.com/sindresorhus/eslint-plugin-unicorn/issues/2088
|
|
65
60
|
const fn: SerializeNodeFunction = (...args) => super.serializeNode(...args)
|
|
66
61
|
return wrapFunction(fn, this.serializeNodeWrapper)(...args)
|
|
67
62
|
}
|
|
68
63
|
}
|
|
69
64
|
|
|
65
|
+
const nodesFromSchema = /* @__PURE__ */ DOMSerializer.nodesFromSchema.bind(DOMSerializer)
|
|
66
|
+
const marksFromSchema = /* @__PURE__ */ DOMSerializer.marksFromSchema.bind(DOMSerializer)
|
|
67
|
+
|
|
70
68
|
function createCustomDOMSerializer(schema: Schema, options: ClipboardSerializerOptions) {
|
|
71
|
-
const nodesFromSchema: NodesFromSchemaFunction = (...args) => DOMSerializer.nodesFromSchema(...args)
|
|
72
|
-
const marksFromSchema: MarksFromSchemaFunction = (...args) => DOMSerializer.marksFromSchema(...args)
|
|
73
69
|
const nodes = wrapFunction(nodesFromSchema, options.nodesFromSchemaWrapper)(schema)
|
|
74
70
|
const marks = wrapFunction(marksFromSchema, options.marksFromSchemaWrapper)(schema)
|
|
75
71
|
return new CustomDOMSerializer(nodes, marks, options.serializeFragmentWrapper, options.serializeNodeWrapper)
|
|
@@ -1,57 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from '../commands/
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} from '../commands/
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
} from '../commands/
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
} from '../
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
} from '../commands/remove-mark'
|
|
21
|
-
import {
|
|
22
|
-
removeNode,
|
|
23
|
-
type RemoveNodeOptions,
|
|
24
|
-
} from '../commands/remove-node'
|
|
25
|
-
import { selectAll } from '../commands/select-all'
|
|
26
|
-
import { selectBlock } from '../commands/select-block'
|
|
27
|
-
import {
|
|
28
|
-
setBlockType,
|
|
29
|
-
type SetBlockTypeOptions,
|
|
30
|
-
} from '../commands/set-block-type'
|
|
31
|
-
import {
|
|
32
|
-
setNodeAttrs,
|
|
33
|
-
type SetNodeAttrsOptions,
|
|
34
|
-
} from '../commands/set-node-attrs'
|
|
35
|
-
import {
|
|
36
|
-
toggleWrap,
|
|
37
|
-
type ToggleWrapOptions,
|
|
38
|
-
} from '../commands/toggle-wrap'
|
|
39
|
-
import {
|
|
40
|
-
unsetBlockType,
|
|
41
|
-
type UnsetBlockTypeOptions,
|
|
42
|
-
} from '../commands/unset-block-type'
|
|
43
|
-
import {
|
|
44
|
-
unsetMark,
|
|
45
|
-
type UnsetMarkOptions,
|
|
46
|
-
} from '../commands/unset-mark'
|
|
47
|
-
import {
|
|
48
|
-
wrap,
|
|
49
|
-
type WrapOptions,
|
|
50
|
-
} from '../commands/wrap'
|
|
51
|
-
import { commandFacet } from '../facets/command'
|
|
52
|
-
import { defineFacetPayload } from '../facets/facet-extension'
|
|
53
|
-
import type { Extension } from '../types/extension'
|
|
54
|
-
import type { CommandCreator } from '../types/extension-command'
|
|
1
|
+
import { addMark, type AddMarkOptions } from '../commands/add-mark.ts'
|
|
2
|
+
import { insertDefaultBlock, type InsertDefaultBlockOptions } from '../commands/insert-default-block.ts'
|
|
3
|
+
import { insertNode, type InsertNodeOptions } from '../commands/insert-node.ts'
|
|
4
|
+
import { insertText, type InsertTextOptions } from '../commands/insert-text.ts'
|
|
5
|
+
import { removeMark, type RemoveMarkOptions } from '../commands/remove-mark.ts'
|
|
6
|
+
import { removeNode, type RemoveNodeOptions } from '../commands/remove-node.ts'
|
|
7
|
+
import { selectAll } from '../commands/select-all.ts'
|
|
8
|
+
import { selectBlock } from '../commands/select-block.ts'
|
|
9
|
+
import { setBlockType, type SetBlockTypeOptions } from '../commands/set-block-type.ts'
|
|
10
|
+
import { setNodeAttrsBetween, type SetNodeAttrsBetweenOptions } from '../commands/set-node-attrs-between.ts'
|
|
11
|
+
import { setNodeAttrs, type SetNodeAttrsOptions } from '../commands/set-node-attrs.ts'
|
|
12
|
+
import { toggleWrap, type ToggleWrapOptions } from '../commands/toggle-wrap.ts'
|
|
13
|
+
import { unsetBlockType, type UnsetBlockTypeOptions } from '../commands/unset-block-type.ts'
|
|
14
|
+
import { unsetMark, type UnsetMarkOptions } from '../commands/unset-mark.ts'
|
|
15
|
+
import { wrap, type WrapOptions } from '../commands/wrap.ts'
|
|
16
|
+
import { commandFacet } from '../facets/command.ts'
|
|
17
|
+
import { defineFacetPayload } from '../facets/facet-extension.ts'
|
|
18
|
+
import type { CommandCreator } from '../types/extension-command.ts'
|
|
19
|
+
import type { Extension } from '../types/extension.ts'
|
|
55
20
|
|
|
56
21
|
export function defineCommands<
|
|
57
22
|
T extends Record<string, CommandCreator> = Record<string, CommandCreator>,
|
|
@@ -77,6 +42,7 @@ export type BaseCommandsExtension = Extension<{
|
|
|
77
42
|
toggleWrap: [options: ToggleWrapOptions]
|
|
78
43
|
setBlockType: [options: SetBlockTypeOptions]
|
|
79
44
|
setNodeAttrs: [options: SetNodeAttrsOptions]
|
|
45
|
+
setNodeAttrsBetween: [options: SetNodeAttrsBetweenOptions]
|
|
80
46
|
insertDefaultBlock: [options?: InsertDefaultBlockOptions]
|
|
81
47
|
selectAll: []
|
|
82
48
|
selectBlock: []
|
|
@@ -108,6 +74,8 @@ export function defineBaseCommands(): BaseCommandsExtension {
|
|
|
108
74
|
|
|
109
75
|
setNodeAttrs,
|
|
110
76
|
|
|
77
|
+
setNodeAttrsBetween,
|
|
78
|
+
|
|
111
79
|
insertDefaultBlock,
|
|
112
80
|
|
|
113
81
|
selectAll,
|