@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.
- package/dist/{editor-M9OimMiI.d.ts → editor-BULC1zqX.d.ts} +31 -71
- package/dist/editor-BULC1zqX.d.ts.map +1 -0
- package/dist/{editor-B0L9BgMi.js → editor-g-Rqn-ZE.js} +119 -136
- package/dist/editor-g-Rqn-ZE.js.map +1 -0
- package/dist/prosekit-core-test.d.ts +1 -2
- package/dist/prosekit-core-test.d.ts.map +1 -1
- package/dist/prosekit-core-test.js +1 -1
- package/dist/prosekit-core-test.js.map +1 -1
- package/dist/prosekit-core.d.ts +182 -202
- package/dist/prosekit-core.d.ts.map +1 -1
- package/dist/prosekit-core.js +543 -549
- package/dist/prosekit-core.js.map +1 -1
- package/package.json +9 -12
- package/src/commands/add-mark.ts +1 -4
- package/src/commands/expand-mark.ts +2 -9
- package/src/commands/insert-default-block.spec.ts +1 -5
- package/src/commands/insert-default-block.ts +1 -4
- package/src/commands/insert-node.ts +4 -8
- package/src/commands/remove-mark.ts +1 -4
- package/src/commands/remove-node.ts +2 -2
- package/src/commands/select-all.ts +3 -8
- package/src/commands/select-block.spec.ts +81 -0
- package/src/commands/select-block.ts +56 -0
- package/src/commands/set-block-type.ts +1 -4
- package/src/commands/set-node-attrs-between.spec.ts +221 -0
- package/src/commands/set-node-attrs-between.ts +77 -0
- package/src/commands/set-node-attrs.spec.ts +129 -0
- package/src/commands/set-node-attrs.ts +25 -26
- package/src/commands/toggle-mark.ts +1 -4
- package/src/commands/toggle-node.ts +2 -5
- package/src/commands/toggle-wrap.spec.ts +1 -5
- package/src/commands/toggle-wrap.ts +1 -4
- package/src/commands/unset-block-type.spec.ts +1 -5
- package/src/commands/unset-block-type.ts +2 -8
- package/src/commands/unset-mark.spec.ts +1 -5
- package/src/commands/wrap.ts +2 -10
- package/src/editor/action.spec.ts +2 -6
- package/src/editor/action.ts +2 -19
- package/src/editor/editor.spec.ts +2 -9
- package/src/editor/editor.ts +31 -77
- package/src/editor/union.spec.ts +1 -5
- package/src/editor/union.ts +1 -4
- package/src/extensions/clipboard-serializer.ts +4 -16
- package/src/extensions/command.ts +20 -48
- package/src/extensions/default-state.spec.ts +1 -9
- package/src/extensions/default-state.ts +6 -32
- package/src/extensions/events/dom-event.spec.ts +1 -6
- package/src/extensions/events/dom-event.ts +5 -20
- package/src/extensions/events/editor-event.ts +5 -17
- package/src/extensions/events/focus.spec.ts +1 -6
- package/src/extensions/events/plugin-view.ts +2 -9
- package/src/extensions/history.ts +3 -10
- package/src/extensions/keymap-base.spec.ts +89 -0
- package/src/extensions/keymap-base.ts +34 -13
- package/src/extensions/keymap.spec.ts +12 -22
- package/src/extensions/keymap.ts +16 -69
- package/src/extensions/mark-spec.spec.ts +5 -20
- package/src/extensions/mark-spec.ts +33 -41
- package/src/extensions/mark-view-effect.ts +3 -9
- package/src/extensions/mark-view.ts +2 -8
- package/src/extensions/node-spec.spec.ts +5 -21
- package/src/extensions/node-spec.ts +31 -33
- package/src/extensions/node-view-effect.ts +3 -9
- package/src/extensions/node-view.ts +2 -8
- package/src/extensions/plugin.spec.ts +3 -16
- package/src/extensions/plugin.ts +4 -14
- package/src/facets/base-extension.ts +1 -4
- package/src/facets/command.ts +10 -10
- package/src/facets/facet-extension.spec.ts +4 -15
- package/src/facets/facet-node.spec.ts +2 -9
- package/src/facets/facet-node.ts +4 -9
- package/src/facets/facet.spec.ts +1 -4
- package/src/facets/schema-spec.ts +2 -9
- package/src/facets/schema.ts +3 -12
- package/src/facets/state.spec.ts +8 -15
- package/src/facets/state.ts +5 -20
- package/src/facets/union-extension.ts +2 -8
- package/src/index.ts +42 -188
- package/src/test/index.ts +1 -4
- package/src/test/test-builder.ts +1 -4
- package/src/test/test-editor.spec.ts +1 -5
- package/src/test/test-editor.ts +5 -24
- package/src/testing/index.ts +18 -14
- package/src/types/extension-command.ts +0 -7
- package/src/types/extension.spec.ts +1 -4
- package/src/types/extension.ts +3 -29
- package/src/types/simplify-union.ts +1 -4
- package/src/utils/array-grouping.spec.ts +2 -15
- package/src/utils/array-grouping.ts +1 -14
- package/src/utils/array.ts +0 -4
- package/src/utils/attrs-match.ts +1 -5
- package/src/utils/clsx.spec.ts +1 -4
- package/src/utils/combine-event-handlers.spec.ts +1 -5
- package/src/utils/combine-event-handlers.ts +4 -6
- package/src/utils/default-block-at.ts +1 -4
- package/src/utils/editor-content.spec.ts +1 -4
- package/src/utils/editor-content.ts +7 -19
- package/src/utils/find-node.ts +65 -0
- package/src/utils/find-parent-node-of-type.ts +6 -12
- package/src/utils/find-parent-node.spec.ts +1 -5
- package/src/utils/find-parent-node.ts +1 -4
- package/src/utils/get-custom-selection.ts +1 -5
- package/src/utils/get-mark-type.ts +1 -4
- package/src/utils/get-node-type.ts +1 -4
- package/src/utils/get-node-types.ts +1 -4
- package/src/utils/includes-mark.ts +1 -5
- package/src/utils/is-at-block-start.ts +1 -4
- package/src/utils/is-mark-absent.spec.ts +1 -4
- package/src/utils/is-mark-absent.ts +1 -5
- package/src/utils/is-mark-active.ts +1 -4
- package/src/utils/is-node-active.spec.ts +109 -0
- package/src/utils/is-node-active.ts +17 -8
- package/src/utils/is-subset.spec.ts +1 -4
- package/src/utils/maybe-run.spec.ts +1 -5
- package/src/utils/merge-objects.spec.ts +1 -4
- package/src/utils/merge-objects.ts +2 -1
- package/src/utils/merge-specs.ts +1 -4
- package/src/utils/object-equal.spec.ts +1 -4
- package/src/utils/output-spec.test.ts +1 -5
- package/src/utils/output-spec.ts +12 -9
- package/src/utils/parse.spec.ts +2 -11
- package/src/utils/parse.ts +12 -24
- package/src/utils/remove-undefined-values.spec.ts +1 -4
- package/src/utils/set-selection-around.ts +1 -4
- package/src/utils/type-assertion.ts +2 -21
- package/src/utils/unicode.spec.ts +1 -4
- package/dist/editor-B0L9BgMi.js.map +0 -1
- package/dist/editor-M9OimMiI.d.ts.map +0 -1
- package/src/extensions/doc.ts +0 -31
- package/src/extensions/paragraph.ts +0 -61
- package/src/extensions/text.ts +0 -34
- package/src/types/base-node-view-options.ts +0 -33
- package/src/types/object-entries.ts +0 -13
- package/src/utils/collect-children.ts +0 -21
- package/src/utils/collect-nodes.ts +0 -37
- package/src/utils/deep-equals.spec.ts +0 -26
- package/src/utils/deep-equals.ts +0 -29
- package/src/utils/get-id.spec.ts +0 -14
- package/src/utils/get-id.ts +0 -13
|
@@ -1,26 +1,11 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
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
|
|
2
|
-
|
|
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 =
|
|
141
|
+
const groupedAttrs = mapGroupBy(attrPayloads, (payload) => payload.type)
|
|
137
142
|
|
|
138
|
-
for (const [type, attrs] of
|
|
143
|
+
for (const [type, attrs] of groupedAttrs.entries()) {
|
|
139
144
|
if (!attrs) continue
|
|
140
145
|
|
|
141
|
-
const
|
|
142
|
-
assert(
|
|
143
|
-
const spec = clone(maybeSpec)
|
|
146
|
+
const oldSpec = specs.get(type)
|
|
147
|
+
assert(oldSpec, `Mark type ${type} must be defined`)
|
|
144
148
|
|
|
145
|
-
|
|
146
|
-
spec.attrs = {}
|
|
147
|
-
}
|
|
149
|
+
const newSpec = { ...oldSpec, attrs: { ...oldSpec.attrs } } satisfies MarkSpec
|
|
148
150
|
|
|
149
151
|
for (const attr of attrs) {
|
|
150
|
-
|
|
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 (
|
|
157
|
-
|
|
158
|
+
if (oldSpec.toDOM) {
|
|
159
|
+
newSpec.toDOM = wrapOutputSpecAttrs(oldSpec.toDOM, attrs)
|
|
158
160
|
}
|
|
159
161
|
|
|
160
|
-
if (
|
|
161
|
-
|
|
162
|
+
if (oldSpec.parseDOM) {
|
|
163
|
+
newSpec.parseDOM = oldSpec.parseDOM.map((rule) => wrapParseRuleAttrs(rule, attrs))
|
|
162
164
|
}
|
|
163
165
|
|
|
164
|
-
specs = specs.update(type,
|
|
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
|
-
|
|
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
|
-
|
|
3
|
-
|
|
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
|
|
2
|
-
|
|
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 =
|
|
164
|
+
const groupedAttrs = mapGroupBy(attrPayloads, (payload) => payload.type)
|
|
163
165
|
|
|
164
|
-
for (const [type, attrs] of
|
|
166
|
+
for (const [type, attrs] of groupedAttrs.entries()) {
|
|
165
167
|
if (!attrs) continue
|
|
166
168
|
|
|
167
|
-
const
|
|
168
|
-
assert(
|
|
169
|
+
const oldSpec = specs.get(type)
|
|
170
|
+
assert(oldSpec, `Node type ${type} must be defined`)
|
|
169
171
|
|
|
170
|
-
const
|
|
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
|
-
|
|
175
|
+
newSpec.attrs[attr.attr] = {
|
|
178
176
|
default: attr.default as unknown,
|
|
179
177
|
validate: attr.validate,
|
|
180
178
|
splittable: attr.splittable,
|
|
181
|
-
}
|
|
179
|
+
} satisfies AttributeSpec
|
|
182
180
|
}
|
|
183
181
|
|
|
184
|
-
if (
|
|
185
|
-
|
|
182
|
+
if (oldSpec.toDOM) {
|
|
183
|
+
newSpec.toDOM = wrapOutputSpecAttrs(oldSpec.toDOM, attrs)
|
|
186
184
|
}
|
|
187
185
|
|
|
188
|
-
if (
|
|
189
|
-
|
|
186
|
+
if (oldSpec.parseDOM) {
|
|
187
|
+
newSpec.parseDOM = oldSpec.parseDOM.map((rule) => wrapTagParseRuleAttrs(rule, attrs))
|
|
190
188
|
}
|
|
191
189
|
|
|
192
|
-
specs = specs.update(type,
|
|
190
|
+
specs = specs.update(type, newSpec)
|
|
193
191
|
}
|
|
194
192
|
|
|
195
193
|
return { nodes: specs, topNode: topNodeName }
|
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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
|
-
|
|
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'
|
package/src/extensions/plugin.ts
CHANGED
|
@@ -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 =
|
|
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'
|
package/src/facets/command.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import type { CommandCreators } from '../types/extension-command'
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
|
|
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
|
-
|
|
17
|
-
|
|
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
|
-
|
|
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
|
|
package/src/facets/facet-node.ts
CHANGED
|
@@ -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>(
|
package/src/facets/facet.spec.ts
CHANGED
|
@@ -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({
|
package/src/facets/schema.ts
CHANGED
|
@@ -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
|
-
|
|
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) => {
|
package/src/facets/state.spec.ts
CHANGED
|
@@ -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({
|
|
24
|
-
const extension2 = withPriority(defineDefaultState({
|
|
25
|
-
const extension3 = withPriority(defineDefaultState({
|
|
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({
|
|
42
|
-
const extension2 = defineDefaultState({
|
|
43
|
-
const extension3 = defineDefaultState({
|
|
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)
|