@prosekit/core 0.10.0 → 0.12.0-beta.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.
Files changed (132) hide show
  1. package/dist/{editor-BULC1zqX.d.ts → editor.d.ts} +48 -8
  2. package/dist/editor.d.ts.map +1 -0
  3. package/dist/{editor-g-Rqn-ZE.js → editor.js} +19 -60
  4. package/dist/editor.js.map +1 -0
  5. package/dist/prosekit-core-test.d.ts +1 -1
  6. package/dist/prosekit-core-test.js +2 -4
  7. package/dist/prosekit-core-test.js.map +1 -1
  8. package/dist/prosekit-core.d.ts +69 -68
  9. package/dist/prosekit-core.d.ts.map +1 -1
  10. package/dist/prosekit-core.js +100 -135
  11. package/dist/prosekit-core.js.map +1 -1
  12. package/package.json +6 -5
  13. package/src/commands/add-mark.ts +2 -2
  14. package/src/commands/expand-mark.ts +1 -1
  15. package/src/commands/insert-default-block.spec.ts +3 -3
  16. package/src/commands/insert-default-block.ts +1 -1
  17. package/src/commands/insert-node.ts +3 -3
  18. package/src/commands/remove-mark.ts +2 -2
  19. package/src/commands/remove-node.ts +2 -2
  20. package/src/commands/select-block.spec.ts +2 -2
  21. package/src/commands/select-block.ts +1 -1
  22. package/src/commands/set-block-type.ts +2 -2
  23. package/src/commands/set-node-attrs-between.spec.ts +2 -2
  24. package/src/commands/set-node-attrs-between.ts +1 -1
  25. package/src/commands/set-node-attrs.spec.ts +2 -2
  26. package/src/commands/set-node-attrs.ts +2 -2
  27. package/src/commands/toggle-mark.ts +2 -2
  28. package/src/commands/toggle-node.ts +2 -2
  29. package/src/commands/toggle-wrap.spec.ts +1 -1
  30. package/src/commands/toggle-wrap.ts +2 -2
  31. package/src/commands/unset-block-type.spec.ts +1 -1
  32. package/src/commands/unset-block-type.ts +1 -1
  33. package/src/commands/unset-mark.spec.ts +1 -1
  34. package/src/commands/unset-mark.ts +1 -1
  35. package/src/commands/wrap.ts +1 -1
  36. package/src/editor/action.spec.ts +3 -3
  37. package/src/editor/action.ts +6 -6
  38. package/src/editor/editor.spec.ts +5 -5
  39. package/src/editor/editor.ts +13 -13
  40. package/src/editor/union.spec.ts +7 -7
  41. package/src/editor/union.ts +4 -4
  42. package/src/editor/with-priority.ts +3 -3
  43. package/src/error.ts +8 -1
  44. package/src/extensions/clipboard-serializer.ts +17 -9
  45. package/src/extensions/command.ts +19 -19
  46. package/src/extensions/default-state.spec.ts +3 -3
  47. package/src/extensions/default-state.ts +5 -5
  48. package/src/extensions/events/doc-change.ts +2 -2
  49. package/src/extensions/events/dom-event.spec.ts +3 -3
  50. package/src/extensions/events/dom-event.ts +7 -7
  51. package/src/extensions/events/editor-event.ts +6 -6
  52. package/src/extensions/events/focus.spec.ts +4 -4
  53. package/src/extensions/events/focus.ts +2 -2
  54. package/src/extensions/events/plugin-view.ts +4 -4
  55. package/src/extensions/history.ts +6 -6
  56. package/src/extensions/keymap-base.spec.ts +5 -5
  57. package/src/extensions/keymap-base.ts +6 -6
  58. package/src/extensions/keymap.spec.ts +5 -5
  59. package/src/extensions/keymap.ts +4 -4
  60. package/src/extensions/mark-spec.spec.ts +3 -3
  61. package/src/extensions/mark-spec.ts +8 -8
  62. package/src/extensions/mark-view-effect.ts +4 -4
  63. package/src/extensions/mark-view.ts +4 -4
  64. package/src/extensions/node-spec.spec.ts +5 -5
  65. package/src/extensions/node-spec.ts +8 -8
  66. package/src/extensions/node-view-effect.ts +4 -4
  67. package/src/extensions/node-view.ts +4 -4
  68. package/src/extensions/plugin.spec.ts +5 -5
  69. package/src/extensions/plugin.ts +5 -5
  70. package/src/facets/base-extension.ts +7 -7
  71. package/src/facets/command.ts +3 -3
  72. package/src/facets/facet-extension.spec.ts +6 -6
  73. package/src/facets/facet-extension.ts +12 -8
  74. package/src/facets/facet-node.spec.ts +3 -3
  75. package/src/facets/facet-node.ts +24 -14
  76. package/src/facets/facet.spec.ts +1 -1
  77. package/src/facets/facet.ts +14 -7
  78. package/src/facets/root.ts +2 -2
  79. package/src/facets/schema-spec.ts +2 -2
  80. package/src/facets/schema.ts +3 -3
  81. package/src/facets/state.spec.ts +6 -6
  82. package/src/facets/state.ts +3 -3
  83. package/src/facets/union-extension.ts +9 -6
  84. package/src/index.ts +74 -74
  85. package/src/test/index.ts +1 -1
  86. package/src/test/test-builder.ts +2 -2
  87. package/src/test/test-editor.spec.ts +1 -1
  88. package/src/test/test-editor.ts +6 -6
  89. package/src/testing/index.ts +10 -10
  90. package/src/types/extension-mark.ts +1 -1
  91. package/src/types/extension-node.ts +1 -1
  92. package/src/types/extension.spec.ts +2 -2
  93. package/src/types/extension.ts +8 -8
  94. package/src/types/pick-string-literal.spec.ts +2 -2
  95. package/src/types/pick-string-literal.ts +1 -1
  96. package/src/types/pick-sub-type.spec.ts +2 -2
  97. package/src/types/priority.ts +50 -7
  98. package/src/types/simplify-deeper.spec.ts +2 -2
  99. package/src/types/simplify-union.spec.ts +2 -2
  100. package/src/utils/array-grouping.spec.ts +1 -1
  101. package/src/utils/assert.ts +1 -1
  102. package/src/utils/can-use-regex-lookbehind.ts +2 -8
  103. package/src/utils/clsx.spec.ts +1 -1
  104. package/src/utils/combine-event-handlers.spec.ts +1 -1
  105. package/src/utils/editor-content.spec.ts +2 -2
  106. package/src/utils/editor-content.ts +4 -4
  107. package/src/utils/find-parent-node-of-type.ts +2 -2
  108. package/src/utils/find-parent-node.spec.ts +2 -2
  109. package/src/utils/get-dom-api.ts +1 -1
  110. package/src/utils/get-mark-type.ts +1 -1
  111. package/src/utils/get-node-type.ts +1 -1
  112. package/src/utils/get-node-types.ts +1 -1
  113. package/src/utils/includes-mark.ts +1 -1
  114. package/src/utils/is-mark-absent.spec.ts +2 -2
  115. package/src/utils/is-mark-absent.ts +1 -1
  116. package/src/utils/is-mark-active.ts +3 -3
  117. package/src/utils/is-node-active.spec.ts +2 -2
  118. package/src/utils/is-node-active.ts +3 -3
  119. package/src/utils/is-subset.spec.ts +1 -1
  120. package/src/utils/maybe-run.spec.ts +1 -1
  121. package/src/utils/merge-objects.spec.ts +1 -1
  122. package/src/utils/merge-objects.ts +1 -1
  123. package/src/utils/merge-specs.ts +1 -1
  124. package/src/utils/object-equal.spec.ts +1 -1
  125. package/src/utils/output-spec.test.ts +1 -1
  126. package/src/utils/parse.spec.ts +3 -3
  127. package/src/utils/parse.ts +3 -3
  128. package/src/utils/remove-undefined-values.spec.ts +1 -1
  129. package/src/utils/unicode.spec.ts +1 -1
  130. package/src/utils/with-skip-code-block.ts +1 -1
  131. package/dist/editor-BULC1zqX.d.ts.map +0 -1
  132. 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.10.0",
4
+ "version": "0.12.0-beta.0",
5
5
  "private": false,
6
6
  "description": "Core features for ProseKit",
7
7
  "author": {
@@ -40,19 +40,20 @@
40
40
  "src"
41
41
  ],
42
42
  "dependencies": {
43
- "@ocavue/utils": "^1.4.0",
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.4.3",
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.20.1",
52
+ "tsdown": "^0.21.4",
53
53
  "typescript": "~5.9.3",
54
- "vitest": "^4.0.18",
54
+ "vitest": "^4.1.1",
55
55
  "vitest-browser-commands": "^0.2.0",
56
+ "@prosekit/config-ts": "0.0.0",
56
57
  "@prosekit/config-vitest": "0.0.0",
57
58
  "@prosekit/config-tsdown": "0.0.0"
58
59
  },
@@ -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()
@@ -1,6 +1,6 @@
1
1
  import { TextSelection, type Command } from '@prosekit/pm/state'
2
2
 
3
- import { defaultBlockAt } from '../utils/default-block-at'
3
+ import { defaultBlockAt } from '../utils/default-block-at.ts'
4
4
 
5
5
  /**
6
6
  * @public
@@ -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,7 +1,7 @@
1
1
  import type { Attrs, NodeType } from '@prosekit/pm/model'
2
2
  import type { Command } from '@prosekit/pm/state'
3
3
 
4
- import { getNodeTypes } from '../utils/get-node-types'
4
+ import { getNodeTypes } from '../utils/get-node-types.ts'
5
5
 
6
6
  /**
7
7
  * @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 { 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
@@ -1,6 +1,6 @@
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
5
  describe('toggle-wrap', () => {
6
6
  it('adds the node wrapping the selection', () => {
@@ -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
  /**
@@ -1,6 +1,6 @@
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
5
  describe('unsetBlockType', () => {
6
6
  it('can unset a single block', () => {
@@ -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
@@ -1,6 +1,6 @@
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
5
  describe('unsetMark', () => {
6
6
  it('can unset marks', () => {
@@ -1,6 +1,6 @@
1
1
  import type { Command } from '@prosekit/pm/state'
2
2
 
3
- import type { CommandCreator } from '../types/extension-command'
3
+ import type { CommandCreator } from '../types/extension-command.ts'
4
4
 
5
5
  /**
6
6
  * @public
@@ -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()
@@ -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', () => {
@@ -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 { CommandAction, CommandCreator } from '../types/extension-command'
19
- import type { NodeJSON, SelectionJSON } from '../types/model'
20
- import { assert } from '../utils/assert'
21
- import { getEditorContentDoc, getEditorSelection } from '../utils/editor-content'
22
- import { htmlFromNode, jsonFromNode, type DOMDocumentOptions } from '../utils/parse'
23
-
24
- import { createMarkActions, createNodeActions, type MarkAction, type NodeAction } from './action'
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
@@ -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 { Extension } from '../types/extension'
10
- import type { CommandCreator } from '../types/extension-command'
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', () => {
@@ -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 { defineFacet } from '../facets/facet'
6
- import { defineFacetPayload } from '../facets/facet-extension'
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
- private serializeFragmentWrapper?: FunctionWrapper<SerializeFragmentFunction>,
42
- private serializeNodeWrapper?: FunctionWrapper<SerializeNodeFunction>,
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 { setNodeAttrs, type SetNodeAttrsOptions } from '../commands/set-node-attrs'
11
- import { setNodeAttrsBetween, type SetNodeAttrsBetweenOptions } from '../commands/set-node-attrs-between'
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 { Extension } from '../types/extension'
19
- 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'
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', () => {