@prosekit/core 0.10.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-BULC1zqX.d.ts → editor.d.ts} +48 -8
- package/dist/editor.d.ts.map +1 -0
- package/dist/{editor-g-Rqn-ZE.js → editor.js} +19 -60
- package/dist/editor.js.map +1 -0
- package/dist/prosekit-core-test.d.ts +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 +69 -68
- package/dist/prosekit-core.d.ts.map +1 -1
- package/dist/prosekit-core.js +100 -135
- package/dist/prosekit-core.js.map +1 -1
- package/package.json +8 -7
- package/src/commands/add-mark.ts +2 -2
- package/src/commands/expand-mark.ts +1 -1
- package/src/commands/insert-default-block.spec.ts +3 -3
- package/src/commands/insert-default-block.ts +1 -1
- package/src/commands/insert-node.ts +3 -3
- package/src/commands/remove-mark.ts +2 -2
- package/src/commands/remove-node.ts +2 -2
- package/src/commands/select-block.spec.ts +2 -2
- package/src/commands/select-block.ts +1 -1
- package/src/commands/set-block-type.ts +2 -2
- package/src/commands/set-node-attrs-between.spec.ts +2 -2
- package/src/commands/set-node-attrs-between.ts +1 -1
- package/src/commands/set-node-attrs.spec.ts +2 -2
- package/src/commands/set-node-attrs.ts +2 -2
- package/src/commands/toggle-mark.ts +2 -2
- package/src/commands/toggle-node.ts +2 -2
- package/src/commands/toggle-wrap.spec.ts +1 -1
- package/src/commands/toggle-wrap.ts +2 -2
- package/src/commands/unset-block-type.spec.ts +1 -1
- package/src/commands/unset-block-type.ts +1 -1
- package/src/commands/unset-mark.spec.ts +1 -1
- package/src/commands/unset-mark.ts +1 -1
- package/src/commands/wrap.ts +1 -1
- package/src/editor/action.spec.ts +3 -3
- package/src/editor/action.ts +6 -6
- package/src/editor/editor.spec.ts +5 -5
- package/src/editor/editor.ts +13 -13
- package/src/editor/union.spec.ts +7 -7
- package/src/editor/union.ts +4 -4
- package/src/editor/with-priority.ts +3 -3
- package/src/error.ts +8 -1
- package/src/extensions/clipboard-serializer.ts +17 -9
- package/src/extensions/command.ts +19 -19
- package/src/extensions/default-state.spec.ts +3 -3
- package/src/extensions/default-state.ts +5 -5
- package/src/extensions/events/doc-change.ts +2 -2
- package/src/extensions/events/dom-event.spec.ts +3 -3
- package/src/extensions/events/dom-event.ts +7 -7
- package/src/extensions/events/editor-event.ts +6 -6
- package/src/extensions/events/focus.spec.ts +4 -4
- package/src/extensions/events/focus.ts +2 -2
- package/src/extensions/events/plugin-view.ts +4 -4
- package/src/extensions/history.ts +6 -6
- package/src/extensions/keymap-base.spec.ts +5 -5
- package/src/extensions/keymap-base.ts +6 -6
- package/src/extensions/keymap.spec.ts +5 -5
- package/src/extensions/keymap.ts +4 -4
- package/src/extensions/mark-spec.spec.ts +3 -3
- package/src/extensions/mark-spec.ts +8 -8
- package/src/extensions/mark-view-effect.ts +4 -4
- package/src/extensions/mark-view.ts +4 -4
- package/src/extensions/node-spec.spec.ts +5 -5
- package/src/extensions/node-spec.ts +8 -8
- package/src/extensions/node-view-effect.ts +4 -4
- package/src/extensions/node-view.ts +4 -4
- package/src/extensions/plugin.spec.ts +5 -5
- package/src/extensions/plugin.ts +5 -5
- package/src/facets/base-extension.ts +7 -7
- package/src/facets/command.ts +3 -3
- package/src/facets/facet-extension.spec.ts +6 -6
- package/src/facets/facet-extension.ts +12 -8
- package/src/facets/facet-node.spec.ts +3 -3
- package/src/facets/facet-node.ts +24 -14
- package/src/facets/facet.spec.ts +1 -1
- package/src/facets/facet.ts +14 -7
- package/src/facets/root.ts +2 -2
- package/src/facets/schema-spec.ts +2 -2
- package/src/facets/schema.ts +3 -3
- package/src/facets/state.spec.ts +6 -6
- package/src/facets/state.ts +3 -3
- package/src/facets/union-extension.ts +9 -6
- package/src/index.ts +74 -74
- package/src/test/index.ts +1 -1
- package/src/test/test-builder.ts +2 -2
- package/src/test/test-editor.spec.ts +1 -1
- package/src/test/test-editor.ts +6 -6
- package/src/testing/index.ts +10 -10
- package/src/types/extension-mark.ts +1 -1
- package/src/types/extension-node.ts +1 -1
- package/src/types/extension.spec.ts +2 -2
- package/src/types/extension.ts +8 -8
- 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/utils/array-grouping.spec.ts +1 -1
- package/src/utils/assert.ts +1 -1
- package/src/utils/can-use-regex-lookbehind.ts +2 -8
- package/src/utils/clsx.spec.ts +1 -1
- package/src/utils/combine-event-handlers.spec.ts +1 -1
- package/src/utils/editor-content.spec.ts +2 -2
- package/src/utils/editor-content.ts +4 -4
- package/src/utils/find-parent-node-of-type.ts +2 -2
- package/src/utils/find-parent-node.spec.ts +2 -2
- package/src/utils/get-dom-api.ts +1 -1
- package/src/utils/get-mark-type.ts +1 -1
- package/src/utils/get-node-type.ts +1 -1
- package/src/utils/get-node-types.ts +1 -1
- package/src/utils/includes-mark.ts +1 -1
- package/src/utils/is-mark-absent.spec.ts +2 -2
- package/src/utils/is-mark-absent.ts +1 -1
- package/src/utils/is-mark-active.ts +3 -3
- package/src/utils/is-node-active.spec.ts +2 -2
- package/src/utils/is-node-active.ts +3 -3
- package/src/utils/is-subset.spec.ts +1 -1
- package/src/utils/maybe-run.spec.ts +1 -1
- package/src/utils/merge-objects.spec.ts +1 -1
- package/src/utils/merge-objects.ts +1 -1
- package/src/utils/merge-specs.ts +1 -1
- package/src/utils/object-equal.spec.ts +1 -1
- package/src/utils/output-spec.test.ts +1 -1
- package/src/utils/parse.spec.ts +3 -3
- package/src/utils/parse.ts +3 -3
- package/src/utils/remove-undefined-values.spec.ts +1 -1
- package/src/utils/unicode.spec.ts +1 -1
- package/src/utils/with-skip-code-block.ts +1 -1
- package/dist/editor-BULC1zqX.d.ts.map +0 -1
- package/dist/editor-g-Rqn-ZE.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prosekit/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.11.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Core features for ProseKit",
|
|
7
7
|
"author": {
|
|
@@ -40,21 +40,22 @@
|
|
|
40
40
|
"src"
|
|
41
41
|
],
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@ocavue/utils": "^1.
|
|
43
|
+
"@ocavue/utils": "^1.6.0",
|
|
44
44
|
"clsx": "^2.1.1",
|
|
45
45
|
"orderedmap": "^2.1.1",
|
|
46
46
|
"prosemirror-splittable": "^0.1.1",
|
|
47
|
-
"type-fest": "^5.
|
|
47
|
+
"type-fest": "^5.5.0",
|
|
48
48
|
"@prosekit/pm": "^0.1.15"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"diffable-html-snapshot": "^0.2.0",
|
|
52
|
-
"tsdown": "^0.
|
|
52
|
+
"tsdown": "^0.21.4",
|
|
53
53
|
"typescript": "~5.9.3",
|
|
54
|
-
"vitest": "^4.
|
|
54
|
+
"vitest": "^4.1.1",
|
|
55
55
|
"vitest-browser-commands": "^0.2.0",
|
|
56
|
-
"@prosekit/config-
|
|
57
|
-
"@prosekit/config-
|
|
56
|
+
"@prosekit/config-tsdown": "0.0.0",
|
|
57
|
+
"@prosekit/config-ts": "0.0.0",
|
|
58
|
+
"@prosekit/config-vitest": "0.0.0"
|
|
58
59
|
},
|
|
59
60
|
"publishConfig": {
|
|
60
61
|
"dev": {}
|
package/src/commands/add-mark.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Attrs, MarkType } from '@prosekit/pm/model'
|
|
2
2
|
import type { Command } from '@prosekit/pm/state'
|
|
3
3
|
|
|
4
|
-
import type { CommandCreator } from '../types/extension-command'
|
|
5
|
-
import { getMarkType } from '../utils/get-mark-type'
|
|
4
|
+
import type { CommandCreator } from '../types/extension-command.ts'
|
|
5
|
+
import { getMarkType } from '../utils/get-mark-type.ts'
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @public
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Mark, MarkType, ResolvedPos } from '@prosekit/pm/model'
|
|
2
2
|
import { TextSelection, type Command } from '@prosekit/pm/state'
|
|
3
3
|
|
|
4
|
-
import { getMarkType } from '../utils/get-mark-type'
|
|
4
|
+
import { getMarkType } from '../utils/get-mark-type.ts'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @public
|
|
@@ -1,9 +1,9 @@
|
|
|
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
|
-
import { insertDefaultBlock } from './insert-default-block'
|
|
6
|
+
import { insertDefaultBlock } from './insert-default-block.ts'
|
|
7
7
|
|
|
8
8
|
describe('insertDefaultBlock', () => {
|
|
9
9
|
const { editor, n } = setupTest()
|
|
@@ -2,9 +2,9 @@ import { Fragment, Slice, type Attrs, type NodeType, type ProseMirrorNode } from
|
|
|
2
2
|
import type { Command } from '@prosekit/pm/state'
|
|
3
3
|
import { dropPoint } from '@prosekit/pm/transform'
|
|
4
4
|
|
|
5
|
-
import { assert } from '../utils/assert'
|
|
6
|
-
import { getNodeType } from '../utils/get-node-type'
|
|
7
|
-
import { setSelectionAround } from '../utils/set-selection-around'
|
|
5
|
+
import { assert } from '../utils/assert.ts'
|
|
6
|
+
import { getNodeType } from '../utils/get-node-type.ts'
|
|
7
|
+
import { setSelectionAround } from '../utils/set-selection-around.ts'
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* @public
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Attrs, MarkType } from '@prosekit/pm/model'
|
|
2
2
|
import type { Command } from '@prosekit/pm/state'
|
|
3
3
|
|
|
4
|
-
import type { CommandCreator } from '../types/extension-command'
|
|
5
|
-
import { getMarkType } from '../utils/get-mark-type'
|
|
4
|
+
import type { CommandCreator } from '../types/extension-command.ts'
|
|
5
|
+
import { getMarkType } from '../utils/get-mark-type.ts'
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @public
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { NodeType } from '@prosekit/pm/model'
|
|
2
2
|
import type { Command } from '@prosekit/pm/state'
|
|
3
3
|
|
|
4
|
-
import type { CommandCreator } from '../types/extension-command'
|
|
5
|
-
import { findParentNodeOfType } from '../utils/find-parent-node-of-type'
|
|
4
|
+
import type { CommandCreator } from '../types/extension-command.ts'
|
|
5
|
+
import { findParentNodeOfType } from '../utils/find-parent-node-of-type.ts'
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @public
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest'
|
|
2
2
|
|
|
3
|
-
import { setupTest } from '../testing'
|
|
3
|
+
import { setupTest } from '../testing/index.ts'
|
|
4
4
|
|
|
5
|
-
import { selectBlock } from './select-block'
|
|
5
|
+
import { selectBlock } from './select-block.ts'
|
|
6
6
|
|
|
7
7
|
describe('selectBlock', () => {
|
|
8
8
|
it('should expand the text selection to cover the start of the paragraph', () => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TextSelection, type Command } from '@prosekit/pm/state'
|
|
2
2
|
|
|
3
|
-
import { isTextSelection } from '../utils/type-assertion'
|
|
3
|
+
import { isTextSelection } from '../utils/type-assertion.ts'
|
|
4
4
|
|
|
5
5
|
// Based on https://github.com/ProseMirror/prosemirror-commands/blob/1.7.1/src/commands.ts#L507-L521
|
|
6
6
|
function getTextblockEndpoint(selection: TextSelection, side: number): number | undefined {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Attrs, NodeType } from '@prosekit/pm/model'
|
|
2
2
|
import type { Command } from '@prosekit/pm/state'
|
|
3
3
|
|
|
4
|
-
import { getCustomSelection } from '../utils/get-custom-selection'
|
|
5
|
-
import { getNodeType } from '../utils/get-node-type'
|
|
4
|
+
import { getCustomSelection } from '../utils/get-custom-selection.ts'
|
|
5
|
+
import { getNodeType } from '../utils/get-node-type.ts'
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @public
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest'
|
|
2
2
|
|
|
3
|
-
import { setupTest } from '../testing'
|
|
3
|
+
import { setupTest } from '../testing/index.ts'
|
|
4
4
|
|
|
5
|
-
import { setNodeAttrsBetween } from './set-node-attrs-between'
|
|
5
|
+
import { setNodeAttrsBetween } from './set-node-attrs-between.ts'
|
|
6
6
|
|
|
7
7
|
describe('setNodeAttrsBetween', () => {
|
|
8
8
|
it('should set attributes on multiple nodes in selection range', () => {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest'
|
|
2
2
|
|
|
3
|
-
import { setupTest } from '../testing'
|
|
3
|
+
import { setupTest } from '../testing/index.ts'
|
|
4
4
|
|
|
5
|
-
import { setNodeAttrs } from './set-node-attrs'
|
|
5
|
+
import { setNodeAttrs } from './set-node-attrs.ts'
|
|
6
6
|
|
|
7
7
|
describe('setNodeAttrs', () => {
|
|
8
8
|
it('should set attributes on a code block node', () => {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Attrs, NodeType } from '@prosekit/pm/model'
|
|
2
2
|
import type { Command } from '@prosekit/pm/state'
|
|
3
3
|
|
|
4
|
-
import { findParentNodeOfType } from '../utils/find-parent-node-of-type'
|
|
5
|
-
import { getNodeTypes } from '../utils/get-node-types'
|
|
4
|
+
import { findParentNodeOfType } from '../utils/find-parent-node-of-type.ts'
|
|
5
|
+
import { getNodeTypes } from '../utils/get-node-types.ts'
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @public
|
|
@@ -2,8 +2,8 @@ import { toggleMark as baseToggleMark } from '@prosekit/pm/commands'
|
|
|
2
2
|
import type { Attrs, MarkType } from '@prosekit/pm/model'
|
|
3
3
|
import type { Command } from '@prosekit/pm/state'
|
|
4
4
|
|
|
5
|
-
import type { CommandCreator } from '../types/extension-command'
|
|
6
|
-
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'
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* @public
|
|
@@ -2,8 +2,8 @@ import { setBlockType } from '@prosekit/pm/commands'
|
|
|
2
2
|
import type { Attrs, NodeType } from '@prosekit/pm/model'
|
|
3
3
|
import type { Command } from '@prosekit/pm/state'
|
|
4
4
|
|
|
5
|
-
import { getNodeType } from '../utils/get-node-type'
|
|
6
|
-
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'
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* @public
|
|
@@ -2,9 +2,9 @@ import { lift } from '@prosekit/pm/commands'
|
|
|
2
2
|
import type { Attrs, NodeType } from '@prosekit/pm/model'
|
|
3
3
|
import type { Command } from '@prosekit/pm/state'
|
|
4
4
|
|
|
5
|
-
import { isNodeActive } from '../utils/is-node-active'
|
|
5
|
+
import { isNodeActive } from '../utils/is-node-active.ts'
|
|
6
6
|
|
|
7
|
-
import { wrap } from './wrap'
|
|
7
|
+
import { wrap } from './wrap.ts'
|
|
8
8
|
|
|
9
9
|
export interface ToggleWrapOptions {
|
|
10
10
|
/**
|
|
@@ -2,7 +2,7 @@ import { Fragment, Slice } from '@prosekit/pm/model'
|
|
|
2
2
|
import type { Command, Transaction } from '@prosekit/pm/state'
|
|
3
3
|
import { ReplaceAroundStep } from '@prosekit/pm/transform'
|
|
4
4
|
|
|
5
|
-
import type { CommandCreator } from '../types/extension-command'
|
|
5
|
+
import type { CommandCreator } from '../types/extension-command.ts'
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @public
|
package/src/commands/wrap.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { Attrs, NodeType } from '@prosekit/pm/model'
|
|
|
2
2
|
import type { Command } from '@prosekit/pm/state'
|
|
3
3
|
import { findWrapping } from '@prosekit/pm/transform'
|
|
4
4
|
|
|
5
|
-
import { getNodeType } from '../utils/get-node-type'
|
|
5
|
+
import { getNodeType } from '../utils/get-node-type.ts'
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @public
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest'
|
|
2
2
|
|
|
3
|
-
import { setupTest } from '../testing'
|
|
4
|
-
import { jsonFromNode } from '../utils/parse'
|
|
3
|
+
import { setupTest } from '../testing/index.ts'
|
|
4
|
+
import { jsonFromNode } from '../utils/parse.ts'
|
|
5
5
|
|
|
6
|
-
import type { NodeChild } from './action'
|
|
6
|
+
import type { NodeChild } from './action.ts'
|
|
7
7
|
|
|
8
8
|
describe('NodeAction', () => {
|
|
9
9
|
const { editor, n } = setupTest()
|
package/src/editor/action.ts
CHANGED
|
@@ -2,12 +2,12 @@ import { mapValues } from '@ocavue/utils'
|
|
|
2
2
|
import type { Attrs, Mark, MarkType, NodeType, ProseMirrorNode, Schema } from '@prosekit/pm/model'
|
|
3
3
|
import type { EditorState } from '@prosekit/pm/state'
|
|
4
4
|
|
|
5
|
-
import { ProseKitError } from '../error'
|
|
6
|
-
import type { AnyAttrs } from '../types/attrs'
|
|
7
|
-
import { assert } from '../utils/assert'
|
|
8
|
-
import { isMarkActive } from '../utils/is-mark-active'
|
|
9
|
-
import { isNodeActive } from '../utils/is-node-active'
|
|
10
|
-
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'
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Available children parameters for {@link NodeAction} and {@link MarkAction}.
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest'
|
|
2
2
|
|
|
3
|
-
import { insertText } from '../commands/insert-text'
|
|
4
|
-
import { wrap } from '../commands/wrap'
|
|
5
|
-
import { defineTestExtension, setupTest } from '../testing'
|
|
6
|
-
import type { NodeJSON } from '../types/model'
|
|
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
7
|
|
|
8
|
-
import { createEditor } from './editor'
|
|
8
|
+
import { createEditor } from './editor.ts'
|
|
9
9
|
|
|
10
10
|
describe('createEditor', () => {
|
|
11
11
|
it('can mount the editor', () => {
|
package/src/editor/editor.ts
CHANGED
|
@@ -3,10 +3,11 @@ import type { ProseMirrorNode, Schema } from '@prosekit/pm/model'
|
|
|
3
3
|
import { EditorState, type Command, type Plugin, type Selection, type Transaction } from '@prosekit/pm/state'
|
|
4
4
|
import { EditorView, type DirectEditorProps, type EditorProps } from '@prosekit/pm/view'
|
|
5
5
|
|
|
6
|
-
import { ProseKitError } from '../error'
|
|
7
|
-
import { defineDefaultState } from '../extensions/default-state'
|
|
8
|
-
import type { BaseExtension } from '../facets/base-extension'
|
|
9
|
-
import { subtractFacetNode, unionFacetNode, type FacetNode } from '../facets/facet-node'
|
|
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'
|
|
10
11
|
import type {
|
|
11
12
|
Extension,
|
|
12
13
|
ExtractCommandActions,
|
|
@@ -14,15 +15,14 @@ import type {
|
|
|
14
15
|
ExtractMarkNames,
|
|
15
16
|
ExtractNodeActions,
|
|
16
17
|
ExtractNodeNames,
|
|
17
|
-
} from '../types/extension'
|
|
18
|
-
import type {
|
|
19
|
-
import
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
import {
|
|
25
|
-
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'
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* @public
|
package/src/editor/union.spec.ts
CHANGED
|
@@ -2,14 +2,14 @@ import type { Attrs } from '@prosekit/pm/model'
|
|
|
2
2
|
import type { Command } from '@prosekit/pm/state'
|
|
3
3
|
import { describe, expectTypeOf, it } from 'vitest'
|
|
4
4
|
|
|
5
|
-
import { defineCommands } from '../extensions/command'
|
|
6
|
-
import { defineMarkSpec } from '../extensions/mark-spec'
|
|
7
|
-
import { defineNodeSpec } from '../extensions/node-spec'
|
|
8
|
-
import { assertTypeEqual } from '../types/assert-type-equal'
|
|
9
|
-
import type {
|
|
10
|
-
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'
|
|
11
11
|
|
|
12
|
-
import { union } from './union'
|
|
12
|
+
import { union } from './union.ts'
|
|
13
13
|
|
|
14
14
|
describe('union', () => {
|
|
15
15
|
it('can merge one extension types', () => {
|
package/src/editor/union.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { BaseExtension } from '../facets/base-extension'
|
|
2
|
-
import { UnionExtensionImpl } from '../facets/union-extension'
|
|
3
|
-
import type { Extension, Union } from '../types/extension'
|
|
4
|
-
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'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
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
|
|
@@ -2,12 +2,12 @@ import { isNotNullish } from '@ocavue/utils'
|
|
|
2
2
|
import { DOMSerializer, type DOMOutputSpec, type Mark, type ProseMirrorNode, type Schema } from '@prosekit/pm/model'
|
|
3
3
|
import { PluginKey, ProseMirrorPlugin } from '@prosekit/pm/state'
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import type { AnyFunction } from '../types/any-function'
|
|
8
|
-
import type { PlainExtension } from '../types/extension'
|
|
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
9
|
|
|
10
|
-
import { pluginFacet, type PluginPayload } from './plugin'
|
|
10
|
+
import { pluginFacet, type PluginPayload } from './plugin.ts'
|
|
11
11
|
|
|
12
12
|
type SerializeFragmentFunction = typeof DOMSerializer.prototype.serializeFragment
|
|
13
13
|
type SerializeNodeFunction = typeof DOMSerializer.prototype.serializeNode
|
|
@@ -35,29 +35,37 @@ function wrapFunction<T extends AnyFunction>(fn: T, wrapper?: FunctionWrapper<T>
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
class CustomDOMSerializer extends DOMSerializer {
|
|
38
|
+
private serializeFragmentWrapper?: FunctionWrapper<SerializeFragmentFunction>
|
|
39
|
+
private serializeNodeWrapper?: FunctionWrapper<SerializeNodeFunction>
|
|
40
|
+
|
|
38
41
|
constructor(
|
|
39
42
|
nodes: Record<string, (node: ProseMirrorNode) => DOMOutputSpec>,
|
|
40
43
|
marks: Record<string, (mark: Mark, inline: boolean) => DOMOutputSpec>,
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
serializeFragmentWrapper?: FunctionWrapper<SerializeFragmentFunction>,
|
|
45
|
+
serializeNodeWrapper?: FunctionWrapper<SerializeNodeFunction>,
|
|
43
46
|
) {
|
|
44
47
|
super(nodes, marks)
|
|
48
|
+
this.serializeFragmentWrapper = serializeFragmentWrapper
|
|
49
|
+
this.serializeNodeWrapper = serializeNodeWrapper
|
|
45
50
|
}
|
|
46
51
|
|
|
47
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
|
|
48
54
|
const fn: SerializeFragmentFunction = (...args) => super.serializeFragment(...args)
|
|
49
55
|
return wrapFunction(fn, this.serializeFragmentWrapper)(...args)
|
|
50
56
|
}
|
|
51
57
|
|
|
52
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
|
|
53
60
|
const fn: SerializeNodeFunction = (...args) => super.serializeNode(...args)
|
|
54
61
|
return wrapFunction(fn, this.serializeNodeWrapper)(...args)
|
|
55
62
|
}
|
|
56
63
|
}
|
|
57
64
|
|
|
65
|
+
const nodesFromSchema = /* @__PURE__ */ DOMSerializer.nodesFromSchema.bind(DOMSerializer)
|
|
66
|
+
const marksFromSchema = /* @__PURE__ */ DOMSerializer.marksFromSchema.bind(DOMSerializer)
|
|
67
|
+
|
|
58
68
|
function createCustomDOMSerializer(schema: Schema, options: ClipboardSerializerOptions) {
|
|
59
|
-
const nodesFromSchema: NodesFromSchemaFunction = (...args) => DOMSerializer.nodesFromSchema(...args)
|
|
60
|
-
const marksFromSchema: MarksFromSchemaFunction = (...args) => DOMSerializer.marksFromSchema(...args)
|
|
61
69
|
const nodes = wrapFunction(nodesFromSchema, options.nodesFromSchemaWrapper)(schema)
|
|
62
70
|
const marks = wrapFunction(marksFromSchema, options.marksFromSchemaWrapper)(schema)
|
|
63
71
|
return new CustomDOMSerializer(nodes, marks, options.serializeFragmentWrapper, options.serializeNodeWrapper)
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { addMark, type AddMarkOptions } from '../commands/add-mark'
|
|
2
|
-
import { insertDefaultBlock, type InsertDefaultBlockOptions } from '../commands/insert-default-block'
|
|
3
|
-
import { insertNode, type InsertNodeOptions } from '../commands/insert-node'
|
|
4
|
-
import { insertText, type InsertTextOptions } from '../commands/insert-text'
|
|
5
|
-
import { removeMark, type RemoveMarkOptions } from '../commands/remove-mark'
|
|
6
|
-
import { removeNode, type RemoveNodeOptions } from '../commands/remove-node'
|
|
7
|
-
import { selectAll } from '../commands/select-all'
|
|
8
|
-
import { selectBlock } from '../commands/select-block'
|
|
9
|
-
import { setBlockType, type SetBlockTypeOptions } from '../commands/set-block-type'
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import { toggleWrap, type ToggleWrapOptions } from '../commands/toggle-wrap'
|
|
13
|
-
import { unsetBlockType, type UnsetBlockTypeOptions } from '../commands/unset-block-type'
|
|
14
|
-
import { unsetMark, type UnsetMarkOptions } from '../commands/unset-mark'
|
|
15
|
-
import { wrap, type WrapOptions } from '../commands/wrap'
|
|
16
|
-
import { commandFacet } from '../facets/command'
|
|
17
|
-
import { defineFacetPayload } from '../facets/facet-extension'
|
|
18
|
-
import type {
|
|
19
|
-
import type {
|
|
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'
|
|
20
20
|
|
|
21
21
|
export function defineCommands<
|
|
22
22
|
T extends Record<string, CommandCreator> = Record<string, CommandCreator>,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest'
|
|
2
2
|
|
|
3
|
-
import { createEditor } from '../editor/editor'
|
|
4
|
-
import { defineTestExtension } from '../testing'
|
|
3
|
+
import { createEditor } from '../editor/editor.ts'
|
|
4
|
+
import { defineTestExtension } from '../testing/index.ts'
|
|
5
5
|
|
|
6
|
-
import type { DefaultStateOptions } from './default-state'
|
|
6
|
+
import type { DefaultStateOptions } from './default-state.ts'
|
|
7
7
|
|
|
8
8
|
describe('defineDefaultState', () => {
|
|
9
9
|
const docJSON = {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Selection, type EditorStateConfig } from '@prosekit/pm/state'
|
|
2
2
|
|
|
3
|
-
import { defineFacetPayload } from '../facets/facet-extension'
|
|
4
|
-
import { stateFacet } from '../facets/state'
|
|
5
|
-
import type { PlainExtension } from '../types/extension'
|
|
6
|
-
import type { NodeJSON, SelectionJSON } from '../types/model'
|
|
7
|
-
import { getEditorContentJSON } from '../utils/editor-content'
|
|
3
|
+
import { defineFacetPayload } from '../facets/facet-extension.ts'
|
|
4
|
+
import { stateFacet } from '../facets/state.ts'
|
|
5
|
+
import type { PlainExtension } from '../types/extension.ts'
|
|
6
|
+
import type { NodeJSON, SelectionJSON } from '../types/model.ts'
|
|
7
|
+
import { getEditorContentJSON } from '../utils/editor-content.ts'
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* @public
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { EditorState } from '@prosekit/pm/state'
|
|
2
2
|
import type { EditorView } from '@prosekit/pm/view'
|
|
3
3
|
|
|
4
|
-
import type { PlainExtension } from '../../types/extension'
|
|
4
|
+
import type { PlainExtension } from '../../types/extension.ts'
|
|
5
5
|
|
|
6
|
-
import { defineUpdateHandler } from './plugin-view'
|
|
6
|
+
import { defineUpdateHandler } from './plugin-view.ts'
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* A function that is called when the editor document is changed.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { describe, expect, it, vi } from 'vitest'
|
|
2
2
|
|
|
3
|
-
import { createEditor } from '../../editor/editor'
|
|
4
|
-
import { defineTestExtension } from '../../testing'
|
|
3
|
+
import { createEditor } from '../../editor/editor.ts'
|
|
4
|
+
import { defineTestExtension } from '../../testing/index.ts'
|
|
5
5
|
|
|
6
|
-
import { defineDOMEventHandler } from './dom-event'
|
|
6
|
+
import { defineDOMEventHandler } from './dom-event.ts'
|
|
7
7
|
|
|
8
8
|
describe('defineDOMEventHandler', () => {
|
|
9
9
|
it('should register and unregister event handlers dynamically', () => {
|