@prosekit/core 0.8.7 → 0.10.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 (139) hide show
  1. package/dist/{editor-M9OimMiI.d.ts → editor-BULC1zqX.d.ts} +31 -71
  2. package/dist/editor-BULC1zqX.d.ts.map +1 -0
  3. package/dist/{editor-B0L9BgMi.js → editor-g-Rqn-ZE.js} +119 -136
  4. package/dist/editor-g-Rqn-ZE.js.map +1 -0
  5. package/dist/prosekit-core-test.d.ts +1 -2
  6. package/dist/prosekit-core-test.d.ts.map +1 -1
  7. package/dist/prosekit-core-test.js +1 -1
  8. package/dist/prosekit-core-test.js.map +1 -1
  9. package/dist/prosekit-core.d.ts +182 -202
  10. package/dist/prosekit-core.d.ts.map +1 -1
  11. package/dist/prosekit-core.js +543 -549
  12. package/dist/prosekit-core.js.map +1 -1
  13. package/package.json +9 -12
  14. package/src/commands/add-mark.ts +1 -4
  15. package/src/commands/expand-mark.ts +2 -9
  16. package/src/commands/insert-default-block.spec.ts +1 -5
  17. package/src/commands/insert-default-block.ts +1 -4
  18. package/src/commands/insert-node.ts +4 -8
  19. package/src/commands/remove-mark.ts +1 -4
  20. package/src/commands/remove-node.ts +2 -2
  21. package/src/commands/select-all.ts +3 -8
  22. package/src/commands/select-block.spec.ts +81 -0
  23. package/src/commands/select-block.ts +56 -0
  24. package/src/commands/set-block-type.ts +1 -4
  25. package/src/commands/set-node-attrs-between.spec.ts +221 -0
  26. package/src/commands/set-node-attrs-between.ts +77 -0
  27. package/src/commands/set-node-attrs.spec.ts +129 -0
  28. package/src/commands/set-node-attrs.ts +25 -26
  29. package/src/commands/toggle-mark.ts +1 -4
  30. package/src/commands/toggle-node.ts +2 -5
  31. package/src/commands/toggle-wrap.spec.ts +1 -5
  32. package/src/commands/toggle-wrap.ts +1 -4
  33. package/src/commands/unset-block-type.spec.ts +1 -5
  34. package/src/commands/unset-block-type.ts +2 -8
  35. package/src/commands/unset-mark.spec.ts +1 -5
  36. package/src/commands/wrap.ts +2 -10
  37. package/src/editor/action.spec.ts +2 -6
  38. package/src/editor/action.ts +2 -19
  39. package/src/editor/editor.spec.ts +2 -9
  40. package/src/editor/editor.ts +31 -77
  41. package/src/editor/union.spec.ts +1 -5
  42. package/src/editor/union.ts +1 -4
  43. package/src/extensions/clipboard-serializer.ts +4 -16
  44. package/src/extensions/command.ts +20 -48
  45. package/src/extensions/default-state.spec.ts +1 -9
  46. package/src/extensions/default-state.ts +6 -32
  47. package/src/extensions/events/dom-event.spec.ts +1 -6
  48. package/src/extensions/events/dom-event.ts +5 -20
  49. package/src/extensions/events/editor-event.ts +5 -17
  50. package/src/extensions/events/focus.spec.ts +1 -6
  51. package/src/extensions/events/plugin-view.ts +2 -9
  52. package/src/extensions/history.ts +3 -10
  53. package/src/extensions/keymap-base.spec.ts +89 -0
  54. package/src/extensions/keymap-base.ts +34 -13
  55. package/src/extensions/keymap.spec.ts +12 -22
  56. package/src/extensions/keymap.ts +16 -69
  57. package/src/extensions/mark-spec.spec.ts +5 -20
  58. package/src/extensions/mark-spec.ts +33 -41
  59. package/src/extensions/mark-view-effect.ts +3 -9
  60. package/src/extensions/mark-view.ts +2 -8
  61. package/src/extensions/node-spec.spec.ts +5 -21
  62. package/src/extensions/node-spec.ts +31 -33
  63. package/src/extensions/node-view-effect.ts +3 -9
  64. package/src/extensions/node-view.ts +2 -8
  65. package/src/extensions/plugin.spec.ts +3 -16
  66. package/src/extensions/plugin.ts +4 -14
  67. package/src/facets/base-extension.ts +1 -4
  68. package/src/facets/command.ts +10 -10
  69. package/src/facets/facet-extension.spec.ts +4 -15
  70. package/src/facets/facet-node.spec.ts +2 -9
  71. package/src/facets/facet-node.ts +4 -9
  72. package/src/facets/facet.spec.ts +1 -4
  73. package/src/facets/schema-spec.ts +2 -9
  74. package/src/facets/schema.ts +3 -12
  75. package/src/facets/state.spec.ts +8 -15
  76. package/src/facets/state.ts +5 -20
  77. package/src/facets/union-extension.ts +2 -8
  78. package/src/index.ts +42 -188
  79. package/src/test/index.ts +1 -4
  80. package/src/test/test-builder.ts +1 -4
  81. package/src/test/test-editor.spec.ts +1 -5
  82. package/src/test/test-editor.ts +5 -24
  83. package/src/testing/index.ts +18 -14
  84. package/src/types/extension-command.ts +0 -7
  85. package/src/types/extension.spec.ts +1 -4
  86. package/src/types/extension.ts +3 -29
  87. package/src/types/simplify-union.ts +1 -4
  88. package/src/utils/array-grouping.spec.ts +2 -15
  89. package/src/utils/array-grouping.ts +1 -14
  90. package/src/utils/array.ts +0 -4
  91. package/src/utils/attrs-match.ts +1 -5
  92. package/src/utils/clsx.spec.ts +1 -4
  93. package/src/utils/combine-event-handlers.spec.ts +1 -5
  94. package/src/utils/combine-event-handlers.ts +4 -6
  95. package/src/utils/default-block-at.ts +1 -4
  96. package/src/utils/editor-content.spec.ts +1 -4
  97. package/src/utils/editor-content.ts +7 -19
  98. package/src/utils/find-node.ts +65 -0
  99. package/src/utils/find-parent-node-of-type.ts +6 -12
  100. package/src/utils/find-parent-node.spec.ts +1 -5
  101. package/src/utils/find-parent-node.ts +1 -4
  102. package/src/utils/get-custom-selection.ts +1 -5
  103. package/src/utils/get-mark-type.ts +1 -4
  104. package/src/utils/get-node-type.ts +1 -4
  105. package/src/utils/get-node-types.ts +1 -4
  106. package/src/utils/includes-mark.ts +1 -5
  107. package/src/utils/is-at-block-start.ts +1 -4
  108. package/src/utils/is-mark-absent.spec.ts +1 -4
  109. package/src/utils/is-mark-absent.ts +1 -5
  110. package/src/utils/is-mark-active.ts +1 -4
  111. package/src/utils/is-node-active.spec.ts +109 -0
  112. package/src/utils/is-node-active.ts +17 -8
  113. package/src/utils/is-subset.spec.ts +1 -4
  114. package/src/utils/maybe-run.spec.ts +1 -5
  115. package/src/utils/merge-objects.spec.ts +1 -4
  116. package/src/utils/merge-objects.ts +2 -1
  117. package/src/utils/merge-specs.ts +1 -4
  118. package/src/utils/object-equal.spec.ts +1 -4
  119. package/src/utils/output-spec.test.ts +1 -5
  120. package/src/utils/output-spec.ts +12 -9
  121. package/src/utils/parse.spec.ts +2 -11
  122. package/src/utils/parse.ts +12 -24
  123. package/src/utils/remove-undefined-values.spec.ts +1 -4
  124. package/src/utils/set-selection-around.ts +1 -4
  125. package/src/utils/type-assertion.ts +2 -21
  126. package/src/utils/unicode.spec.ts +1 -4
  127. package/dist/editor-B0L9BgMi.js.map +0 -1
  128. package/dist/editor-M9OimMiI.d.ts.map +0 -1
  129. package/src/extensions/doc.ts +0 -31
  130. package/src/extensions/paragraph.ts +0 -61
  131. package/src/extensions/text.ts +0 -34
  132. package/src/types/base-node-view-options.ts +0 -33
  133. package/src/types/object-entries.ts +0 -13
  134. package/src/utils/collect-children.ts +0 -21
  135. package/src/utils/collect-nodes.ts +0 -37
  136. package/src/utils/deep-equals.spec.ts +0 -26
  137. package/src/utils/deep-equals.ts +0 -29
  138. package/src/utils/get-id.spec.ts +0 -14
  139. package/src/utils/get-id.ts +0 -13
@@ -1,26 +1,11 @@
1
- import type {
2
- DOMOutputSpec,
3
- TagParseRule,
4
- } from '@prosekit/pm/model'
5
- import formatHTML from 'diffable-html'
6
- import {
7
- describe,
8
- expect,
9
- it,
10
- } from 'vitest'
1
+ import type { DOMOutputSpec, TagParseRule } from '@prosekit/pm/model'
2
+ import { formatHTML } from 'diffable-html-snapshot'
3
+ import { describe, expect, it } from 'vitest'
11
4
 
12
5
  import { union } from '../editor/union'
13
- import {
14
- defineDoc,
15
- defineParagraph,
16
- defineText,
17
- setupTestFromExtension,
18
- } from '../testing'
6
+ import { defineDoc, defineParagraph, defineText, setupTestFromExtension } from '../testing'
19
7
 
20
- import {
21
- defineMarkAttr,
22
- defineMarkSpec,
23
- } from './mark-spec'
8
+ import { defineMarkAttr, defineMarkSpec } from './mark-spec'
24
9
 
25
10
  describe('defineMarkSpec', () => {
26
11
  it('can merge mark specs', () => {
@@ -1,27 +1,15 @@
1
- import type {
2
- MarkSpec,
3
- ParseRule,
4
- SchemaSpec,
5
- } from '@prosekit/pm/model'
6
- import clone from 'just-clone'
1
+ import { isNotNullish, mapGroupBy } from '@ocavue/utils'
2
+ import type { AttributeSpec, MarkSpec, SchemaSpec } from '@prosekit/pm/model'
7
3
  import OrderedMap from 'orderedmap'
8
4
 
9
5
  import { defineFacet } from '../facets/facet'
10
6
  import { defineFacetPayload } from '../facets/facet-extension'
11
7
  import { schemaSpecFacet } from '../facets/schema-spec'
12
- import type {
13
- AnyAttrs,
14
- AttrSpec,
15
- } from '../types/attrs'
8
+ import type { AnyAttrs, AttrSpec } from '../types/attrs'
16
9
  import type { Extension } from '../types/extension'
17
- import { groupBy } from '../utils/array-grouping'
18
10
  import { assert } from '../utils/assert'
19
11
  import { mergeSpecs } from '../utils/merge-specs'
20
- import {
21
- wrapOutputSpecAttrs,
22
- wrapTagParseRuleAttrs,
23
- } from '../utils/output-spec'
24
- import { isNotNullish } from '../utils/type-assertion'
12
+ import { wrapOutputSpecAttrs, wrapParseRuleAttrs } from '../utils/output-spec'
25
13
 
26
14
  /**
27
15
  * @public
@@ -76,7 +64,24 @@ export interface MarkAttrOptions<
76
64
  }
77
65
 
78
66
  /**
67
+ * Defines a mark type into the editor schema.
68
+ *
79
69
  * @public
70
+ *
71
+ * @example
72
+ *
73
+ * ```ts
74
+ * const extension = defineMarkSpec({
75
+ * name: 'bold',
76
+ * parseDOM: [
77
+ * { tag: 'strong' },
78
+ * { tag: 'b' },
79
+ * ],
80
+ * toDOM() {
81
+ * return ['strong', 0]
82
+ * },
83
+ * })
84
+ * ```
80
85
  */
81
86
  export function defineMarkSpec<
82
87
  Mark extends string,
@@ -133,35 +138,32 @@ const markSpecFacet = defineFacet<MarkSpecPayload, SchemaSpec>({
133
138
  }
134
139
  }
135
140
 
136
- const groupedAttrs = groupBy(attrPayloads, (payload) => payload.type)
141
+ const groupedAttrs = mapGroupBy(attrPayloads, (payload) => payload.type)
137
142
 
138
- for (const [type, attrs] of Object.entries(groupedAttrs)) {
143
+ for (const [type, attrs] of groupedAttrs.entries()) {
139
144
  if (!attrs) continue
140
145
 
141
- const maybeSpec = specs.get(type)
142
- assert(maybeSpec, `Mark type ${type} must be defined`)
143
- const spec = clone(maybeSpec)
146
+ const oldSpec = specs.get(type)
147
+ assert(oldSpec, `Mark type ${type} must be defined`)
144
148
 
145
- if (!spec.attrs) {
146
- spec.attrs = {}
147
- }
149
+ const newSpec = { ...oldSpec, attrs: { ...oldSpec.attrs } } satisfies MarkSpec
148
150
 
149
151
  for (const attr of attrs) {
150
- spec.attrs[attr.attr] = {
152
+ newSpec.attrs[attr.attr] = {
151
153
  default: attr.default as unknown,
152
154
  validate: attr.validate,
153
- }
155
+ } satisfies AttributeSpec
154
156
  }
155
157
 
156
- if (spec.toDOM) {
157
- spec.toDOM = wrapOutputSpecAttrs(spec.toDOM, attrs)
158
+ if (oldSpec.toDOM) {
159
+ newSpec.toDOM = wrapOutputSpecAttrs(oldSpec.toDOM, attrs)
158
160
  }
159
161
 
160
- if (spec.parseDOM) {
161
- spec.parseDOM = spec.parseDOM.map((rule) => wrapParseRuleAttrs(rule, attrs))
162
+ if (oldSpec.parseDOM) {
163
+ newSpec.parseDOM = oldSpec.parseDOM.map((rule) => wrapParseRuleAttrs(rule, attrs))
162
164
  }
163
165
 
164
- specs = specs.update(type, spec)
166
+ specs = specs.update(type, newSpec)
165
167
  }
166
168
 
167
169
  return { marks: specs, nodes: {} }
@@ -169,13 +171,3 @@ const markSpecFacet = defineFacet<MarkSpecPayload, SchemaSpec>({
169
171
  parent: schemaSpecFacet,
170
172
  singleton: true,
171
173
  })
172
-
173
- function wrapParseRuleAttrs(
174
- rule: ParseRule,
175
- attrs: MarkAttrOptions[],
176
- ): ParseRule {
177
- if (rule.tag) {
178
- return wrapTagParseRuleAttrs(rule, attrs)
179
- }
180
- return rule
181
- }
@@ -1,18 +1,12 @@
1
- import {
2
- PluginKey,
3
- ProseMirrorPlugin,
4
- } from '@prosekit/pm/state'
1
+ import { isNotNullish } from '@ocavue/utils'
2
+ import { PluginKey, ProseMirrorPlugin } from '@prosekit/pm/state'
5
3
  import type { MarkViewConstructor } from '@prosekit/pm/view'
6
4
 
7
5
  import { defineFacet } from '../facets/facet'
8
6
  import { defineFacetPayload } from '../facets/facet-extension'
9
7
  import type { Extension } from '../types/extension'
10
- import { isNotNullish } from '../utils/type-assertion'
11
8
 
12
- import {
13
- pluginFacet,
14
- type PluginPayload,
15
- } from './plugin'
9
+ import { pluginFacet, type PluginPayload } from './plugin'
16
10
 
17
11
  /**
18
12
  * @internal
@@ -1,17 +1,11 @@
1
- import {
2
- PluginKey,
3
- ProseMirrorPlugin,
4
- } from '@prosekit/pm/state'
1
+ import { PluginKey, ProseMirrorPlugin } from '@prosekit/pm/state'
5
2
  import type { MarkViewConstructor } from '@prosekit/pm/view'
6
3
 
7
4
  import { defineFacet } from '../facets/facet'
8
5
  import { defineFacetPayload } from '../facets/facet-extension'
9
6
  import type { Extension } from '../types/extension'
10
7
 
11
- import {
12
- pluginFacet,
13
- type PluginPayload,
14
- } from './plugin'
8
+ import { pluginFacet, type PluginPayload } from './plugin'
15
9
 
16
10
  export interface MarkViewOptions {
17
11
  name: string
@@ -1,29 +1,13 @@
1
- import type {
2
- DOMOutputSpec,
3
- Schema,
4
- TagParseRule,
5
- } from '@prosekit/pm/model'
6
- import formatHTML from 'diffable-html'
7
- import {
8
- describe,
9
- expect,
10
- it,
11
- } from 'vitest'
1
+ import type { DOMOutputSpec, Schema, TagParseRule } from '@prosekit/pm/model'
2
+ import { formatHTML } from 'diffable-html-snapshot'
3
+ import { describe, expect, it } from 'vitest'
12
4
 
13
5
  import { union } from '../editor/union'
14
- import {
15
- defineDoc,
16
- defineParagraph,
17
- defineText,
18
- setupTestFromExtension,
19
- } from '../testing'
6
+ import { defineDoc, defineParagraph, defineText, setupTestFromExtension } from '../testing'
20
7
 
21
8
  import { defineHistory } from './history'
22
9
  import { defineBaseKeymap } from './keymap-base'
23
- import {
24
- defineNodeAttr,
25
- defineNodeSpec,
26
- } from './node-spec'
10
+ import { defineNodeAttr, defineNodeSpec } from './node-spec'
27
11
 
28
12
  describe('defineNodeSpec', () => {
29
13
  it('can merge node specs', () => {
@@ -1,27 +1,15 @@
1
- import type {
2
- AttributeSpec,
3
- NodeSpec,
4
- SchemaSpec,
5
- } from '@prosekit/pm/model'
6
- import clone from 'just-clone'
1
+ import { isNotNullish, mapGroupBy } from '@ocavue/utils'
2
+ import type { AttributeSpec, NodeSpec, SchemaSpec } from '@prosekit/pm/model'
7
3
  import OrderedMap from 'orderedmap'
8
4
 
9
5
  import { defineFacet } from '../facets/facet'
10
6
  import { defineFacetPayload } from '../facets/facet-extension'
11
7
  import { schemaSpecFacet } from '../facets/schema-spec'
12
- import type {
13
- AnyAttrs,
14
- AttrSpec,
15
- } from '../types/attrs'
8
+ import type { AnyAttrs, AttrSpec } from '../types/attrs'
16
9
  import type { Extension } from '../types/extension'
17
- import { groupBy } from '../utils/array-grouping'
18
10
  import { assert } from '../utils/assert'
19
11
  import { mergeSpecs } from '../utils/merge-specs'
20
- import {
21
- wrapOutputSpecAttrs,
22
- wrapTagParseRuleAttrs,
23
- } from '../utils/output-spec'
24
- import { isNotNullish } from '../utils/type-assertion'
12
+ import { wrapOutputSpecAttrs, wrapTagParseRuleAttrs } from '../utils/output-spec'
25
13
 
26
14
  /**
27
15
  * @public
@@ -93,9 +81,23 @@ export interface NodeAttrOptions<
93
81
  }
94
82
 
95
83
  /**
96
- * Defines a node type.
84
+ * Defines a node type into the editor schema.
97
85
  *
98
86
  * @public
87
+ *
88
+ * @example
89
+ *
90
+ * ```ts
91
+ * const extension = defineNodeSpec({
92
+ * name: 'fancyParagraph',
93
+ * content: 'inline*',
94
+ * group: 'block',
95
+ * parseDOM: [{ tag: 'p.fancy' }],
96
+ * toDOM() {
97
+ * return ['p', { 'class': 'fancy' }, 0]
98
+ * },
99
+ * })
100
+ * ```
99
101
  */
100
102
  export function defineNodeSpec<
101
103
  Node extends string,
@@ -159,37 +161,33 @@ const nodeSpecFacet = defineFacet<NodeSpecPayload, SchemaSpec>({
159
161
  }
160
162
  }
161
163
 
162
- const groupedAttrs = groupBy(attrPayloads, (payload) => payload.type)
164
+ const groupedAttrs = mapGroupBy(attrPayloads, (payload) => payload.type)
163
165
 
164
- for (const [type, attrs] of Object.entries(groupedAttrs)) {
166
+ for (const [type, attrs] of groupedAttrs.entries()) {
165
167
  if (!attrs) continue
166
168
 
167
- const maybeSpec = specs.get(type)
168
- assert(maybeSpec, `Node type ${type} must be defined`)
169
+ const oldSpec = specs.get(type)
170
+ assert(oldSpec, `Node type ${type} must be defined`)
169
171
 
170
- const spec = clone(maybeSpec)
171
-
172
- if (!spec.attrs) {
173
- spec.attrs = {}
174
- }
172
+ const newSpec = { ...oldSpec, attrs: { ...oldSpec.attrs } } satisfies NodeSpec
175
173
 
176
174
  for (const attr of attrs) {
177
- spec.attrs[attr.attr] = {
175
+ newSpec.attrs[attr.attr] = {
178
176
  default: attr.default as unknown,
179
177
  validate: attr.validate,
180
178
  splittable: attr.splittable,
181
- } as AttributeSpec
179
+ } satisfies AttributeSpec
182
180
  }
183
181
 
184
- if (spec.toDOM) {
185
- spec.toDOM = wrapOutputSpecAttrs(spec.toDOM, attrs)
182
+ if (oldSpec.toDOM) {
183
+ newSpec.toDOM = wrapOutputSpecAttrs(oldSpec.toDOM, attrs)
186
184
  }
187
185
 
188
- if (spec.parseDOM) {
189
- spec.parseDOM = spec.parseDOM.map((rule) => wrapTagParseRuleAttrs(rule, attrs))
186
+ if (oldSpec.parseDOM) {
187
+ newSpec.parseDOM = oldSpec.parseDOM.map((rule) => wrapTagParseRuleAttrs(rule, attrs))
190
188
  }
191
189
 
192
- specs = specs.update(type, spec)
190
+ specs = specs.update(type, newSpec)
193
191
  }
194
192
 
195
193
  return { nodes: specs, topNode: topNodeName }
@@ -1,18 +1,12 @@
1
- import {
2
- PluginKey,
3
- ProseMirrorPlugin,
4
- } from '@prosekit/pm/state'
1
+ import { isNotNullish } from '@ocavue/utils'
2
+ import { PluginKey, ProseMirrorPlugin } from '@prosekit/pm/state'
5
3
  import type { NodeViewConstructor } from '@prosekit/pm/view'
6
4
 
7
5
  import { defineFacet } from '../facets/facet'
8
6
  import { defineFacetPayload } from '../facets/facet-extension'
9
7
  import type { Extension } from '../types/extension'
10
- import { isNotNullish } from '../utils/type-assertion'
11
8
 
12
- import {
13
- pluginFacet,
14
- type PluginPayload,
15
- } from './plugin'
9
+ import { pluginFacet, type PluginPayload } from './plugin'
16
10
 
17
11
  /**
18
12
  * @internal
@@ -1,17 +1,11 @@
1
- import {
2
- PluginKey,
3
- ProseMirrorPlugin,
4
- } from '@prosekit/pm/state'
1
+ import { PluginKey, ProseMirrorPlugin } from '@prosekit/pm/state'
5
2
  import type { NodeViewConstructor } from '@prosekit/pm/view'
6
3
 
7
4
  import { defineFacet } from '../facets/facet'
8
5
  import { defineFacetPayload } from '../facets/facet-extension'
9
6
  import type { Extension } from '../types/extension'
10
7
 
11
- import {
12
- pluginFacet,
13
- type PluginPayload,
14
- } from './plugin'
8
+ import { pluginFacet, type PluginPayload } from './plugin'
15
9
 
16
10
  export interface NodeViewOptions {
17
11
  name: string
@@ -1,22 +1,9 @@
1
- import {
2
- Plugin,
3
- PluginKey,
4
- } from '@prosekit/pm/state'
5
- import {
6
- describe,
7
- expect,
8
- it,
9
- vi,
10
- } from 'vitest'
1
+ import { Plugin, PluginKey } from '@prosekit/pm/state'
2
+ import { describe, expect, it, vi } from 'vitest'
11
3
 
12
4
  import { union } from '../editor/union'
13
5
  import { withPriority } from '../editor/with-priority'
14
- import {
15
- defineDoc,
16
- defineParagraph,
17
- defineText,
18
- setupTestFromExtension,
19
- } from '../testing'
6
+ import { defineDoc, defineParagraph, defineText, setupTestFromExtension } from '../testing'
20
7
  import { Priority } from '../types/priority'
21
8
 
22
9
  import { definePlugin } from './plugin'
@@ -1,21 +1,11 @@
1
1
  import type { Schema } from '@prosekit/pm/model'
2
- import {
3
- Plugin,
4
- type ProseMirrorPlugin,
5
- } from '@prosekit/pm/state'
2
+ import { Plugin, type ProseMirrorPlugin } from '@prosekit/pm/state'
6
3
 
7
4
  import { ProseKitError } from '../error'
8
- import {
9
- defineFacet,
10
- type Facet,
11
- } from '../facets/facet'
5
+ import { defineFacet, type Facet } from '../facets/facet'
12
6
  import { defineFacetPayload } from '../facets/facet-extension'
13
- import {
14
- stateFacet,
15
- type StatePayload,
16
- } from '../facets/state'
7
+ import { stateFacet, type StatePayload } from '../facets/state'
17
8
  import type { PlainExtension } from '../types/extension'
18
- import { toReversed } from '../utils/array'
19
9
 
20
10
  /**
21
11
  * Adds a ProseMirror plugin to the editor.
@@ -72,7 +62,7 @@ export const pluginFacet: Facet<PluginPayload, StatePayload> = defineFacet({
72
62
 
73
63
  // An array of plugins from higher to lower priority. This matches the
74
64
  // order of plugins required by ProseMirror.
75
- const reversedPlugins = toReversed(plugins)
65
+ const reversedPlugins = [...plugins].reverse()
76
66
 
77
67
  return { plugins: reversedPlugins }
78
68
  }
@@ -1,9 +1,6 @@
1
1
  import type { Schema } from '@prosekit/pm/model'
2
2
 
3
- import type {
4
- Extension,
5
- ExtensionTyping,
6
- } from '../types/extension'
3
+ import type { Extension, ExtensionTyping } from '../types/extension'
7
4
  import { Priority } from '../types/priority'
8
5
 
9
6
  import type { Facet } from './facet'
@@ -1,20 +1,20 @@
1
1
  import type { CommandCreators } from '../types/extension-command'
2
2
 
3
- import {
4
- defineFacet,
5
- type Facet,
6
- } from './facet'
7
- import {
8
- rootFacet,
9
- type RootPayload,
10
- } from './root'
3
+ import { defineFacet, type Facet } from './facet'
4
+ import { rootFacet, type RootPayload } from './root'
11
5
 
12
6
  type CommandPayload = CommandCreators
13
7
 
14
8
  export const commandFacet: Facet<CommandPayload, RootPayload> = defineFacet({
15
9
  reducer: (inputs) => {
16
- const commands = Object.assign({}, ...inputs) as CommandPayload
17
- return { commands }
10
+ switch (inputs.length) {
11
+ case 0:
12
+ return { commands: {} }
13
+ case 1:
14
+ return { commands: inputs[0] }
15
+ default:
16
+ return { commands: Object.assign({}, ...inputs) as CommandCreators }
17
+ }
18
18
  },
19
19
  parent: rootFacet,
20
20
  singleton: true,
@@ -1,22 +1,11 @@
1
- import {
2
- describe,
3
- expect,
4
- it,
5
- vi,
6
- } from 'vitest'
1
+ import { isNotNullish } from '@ocavue/utils'
2
+ import { describe, expect, it, vi } from 'vitest'
7
3
 
8
4
  import { Priority } from '../types/priority'
9
- import { isNotNullish } from '../utils/type-assertion'
10
5
 
11
- import {
12
- defineFacet,
13
- Facet,
14
- } from './facet'
6
+ import { defineFacet, Facet } from './facet'
15
7
  import { FacetExtensionImpl } from './facet-extension'
16
- import {
17
- subtractFacetNode,
18
- unionFacetNode,
19
- } from './facet-node'
8
+ import { subtractFacetNode, unionFacetNode } from './facet-node'
20
9
  import type { FacetReducer } from './facet-types'
21
10
  import { UnionExtensionImpl } from './union-extension'
22
11
 
@@ -1,16 +1,9 @@
1
- import {
2
- expect,
3
- test,
4
- } from 'vitest'
1
+ import { expect, test } from 'vitest'
5
2
 
6
3
  import { Priority } from '../types/priority'
7
4
 
8
5
  import { Facet } from './facet'
9
- import {
10
- FacetNode,
11
- subtractFacetNode,
12
- unionFacetNode,
13
- } from './facet-node'
6
+ import { FacetNode, subtractFacetNode, unionFacetNode } from './facet-node'
14
7
 
15
8
  const sum = (input: number[]) => input.reduce((acc, cur) => acc + cur, 0)
16
9
 
@@ -1,16 +1,11 @@
1
+ import { isNotNullish } from '@ocavue/utils'
2
+
1
3
  import { Priority } from '../types/priority'
2
- import {
3
- arraySubtract,
4
- uniqPush,
5
- } from '../utils/array'
4
+ import { arraySubtract, uniqPush } from '../utils/array'
6
5
  import { assert } from '../utils/assert'
7
- import { isNotNullish } from '../utils/type-assertion'
8
6
 
9
7
  import type { Facet } from './facet'
10
- import type {
11
- FacetReducer,
12
- Tuple5,
13
- } from './facet-types'
8
+ import type { FacetReducer, Tuple5 } from './facet-types'
14
9
  import type { RootOutput } from './root'
15
10
 
16
11
  function zip5<T>(
@@ -1,7 +1,4 @@
1
- import {
2
- expect,
3
- test,
4
- } from 'vitest'
1
+ import { expect, test } from 'vitest'
5
2
 
6
3
  import { Facet } from './facet'
7
4
 
@@ -1,14 +1,7 @@
1
- import type {
2
- MarkSpec,
3
- NodeSpec,
4
- SchemaSpec,
5
- } from '@prosekit/pm/model'
1
+ import type { MarkSpec, NodeSpec, SchemaSpec } from '@prosekit/pm/model'
6
2
  import OrderedMap from 'orderedmap'
7
3
 
8
- import {
9
- defineFacet,
10
- type Facet,
11
- } from './facet'
4
+ import { defineFacet, type Facet } from './facet'
12
5
  import { schemaFacet } from './schema'
13
6
 
14
7
  export const schemaSpecFacet: Facet<SchemaSpec, SchemaSpec> = defineFacet({
@@ -1,18 +1,9 @@
1
- import {
2
- Schema,
3
- type SchemaSpec,
4
- } from '@prosekit/pm/model'
1
+ import { Schema, type SchemaSpec } from '@prosekit/pm/model'
5
2
 
6
3
  import { assert } from '../utils/assert'
7
4
 
8
- import {
9
- defineFacet,
10
- type Facet,
11
- } from './facet'
12
- import {
13
- rootFacet,
14
- type RootPayload,
15
- } from './root'
5
+ import { defineFacet, type Facet } from './facet'
6
+ import { rootFacet, type RootPayload } from './root'
16
7
 
17
8
  export const schemaFacet: Facet<SchemaSpec, RootPayload> = defineFacet({
18
9
  reducer: (specs) => {
@@ -1,16 +1,9 @@
1
- import {
2
- describe,
3
- expect,
4
- it,
5
- } from 'vitest'
1
+ import { describe, expect, it } from 'vitest'
6
2
 
7
3
  import { union } from '../editor/union'
8
4
  import { withPriority } from '../editor/with-priority'
9
5
  import { defineDefaultState } from '../extensions/default-state'
10
- import {
11
- defineTestExtension,
12
- setupTestFromExtension,
13
- } from '../testing'
6
+ import { defineTestExtension, setupTestFromExtension } from '../testing'
14
7
  import type { NodeJSON } from '../types/model'
15
8
  import { Priority } from '../types/priority'
16
9
 
@@ -20,9 +13,9 @@ describe('state', () => {
20
13
  const doc2: NodeJSON = { type: 'doc', content: [{ type: 'paragraph', content: [{ type: 'text', text: 'highest priority' }] }] }
21
14
  const doc3: NodeJSON = { type: 'doc', content: [{ type: 'paragraph', content: [{ type: 'text', text: 'lowest priority' }] }] }
22
15
 
23
- const extension1 = defineDefaultState({ defaultDoc: doc1 }) // default priority
24
- const extension2 = withPriority(defineDefaultState({ defaultDoc: doc2 }), Priority.highest)
25
- const extension3 = withPriority(defineDefaultState({ defaultDoc: doc3 }), Priority.lowest)
16
+ const extension1 = defineDefaultState({ defaultContent: doc1 }) // default priority
17
+ const extension2 = withPriority(defineDefaultState({ defaultContent: doc2 }), Priority.highest)
18
+ const extension3 = withPriority(defineDefaultState({ defaultContent: doc3 }), Priority.lowest)
26
19
 
27
20
  const combinedExtension = union(defineTestExtension(), extension1, extension2, extension3)
28
21
  const { editor } = setupTestFromExtension(combinedExtension)
@@ -38,9 +31,9 @@ describe('state', () => {
38
31
  const doc2 = { type: 'doc', content: [{ type: 'paragraph', content: [{ type: 'text', text: 'second' }] }] }
39
32
  const doc3 = { type: 'doc', content: [{ type: 'paragraph', content: [{ type: 'text', text: 'third' }] }] }
40
33
 
41
- const extension1 = defineDefaultState({ defaultDoc: doc1 })
42
- const extension2 = defineDefaultState({ defaultDoc: doc2 })
43
- const extension3 = defineDefaultState({ defaultDoc: doc3 })
34
+ const extension1 = defineDefaultState({ defaultContent: doc1 })
35
+ const extension2 = defineDefaultState({ defaultContent: doc2 })
36
+ const extension3 = defineDefaultState({ defaultContent: doc3 })
44
37
 
45
38
  const combinedExtension = union(defineTestExtension(), extension1, extension2, extension3)
46
39
  const { editor } = setupTestFromExtension(combinedExtension)