@prosekit/core 0.8.4 → 0.8.6
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-CizSwUN8.js → editor-D2iEkgO8.js} +32 -34
- package/dist/editor-D2iEkgO8.js.map +1 -0
- package/dist/{editor-CfkZ4TNU.d.ts → editor-M9OimMiI.d.ts} +12 -38
- package/dist/editor-M9OimMiI.d.ts.map +1 -0
- package/dist/prosekit-core-test.d.ts +1 -1
- package/dist/prosekit-core-test.d.ts.map +1 -1
- package/dist/prosekit-core-test.js +2 -4
- package/dist/prosekit-core-test.js.map +1 -1
- package/dist/prosekit-core.d.ts +48 -66
- package/dist/prosekit-core.d.ts.map +1 -1
- package/dist/prosekit-core.js +17 -37
- package/dist/prosekit-core.js.map +1 -1
- package/package.json +9 -10
- package/src/extensions/keymap.spec.ts +46 -10
- package/src/extensions/plugin.spec.ts +153 -0
- package/src/extensions/plugin.ts +8 -18
- package/src/facets/facet-node.spec.ts +1 -1
- package/src/facets/state.spec.ts +53 -0
- package/src/facets/state.ts +46 -18
- package/src/testing/keyboard.ts +1 -1
- package/src/utils/clsx.ts +2 -0
- package/dist/editor-CfkZ4TNU.d.ts.map +0 -1
- package/dist/editor-CizSwUN8.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.8.
|
|
4
|
+
"version": "0.8.6",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Core features for ProseKit",
|
|
7
7
|
"author": {
|
|
@@ -40,24 +40,23 @@
|
|
|
40
40
|
"src"
|
|
41
41
|
],
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@ocavue/utils": "^0.
|
|
43
|
+
"@ocavue/utils": "^0.8.1",
|
|
44
44
|
"clsx": "^2.1.1",
|
|
45
45
|
"just-clone": "^6.2.0",
|
|
46
46
|
"just-map-values": "^3.2.0",
|
|
47
47
|
"orderedmap": "^2.1.1",
|
|
48
48
|
"prosemirror-splittable": "^0.1.1",
|
|
49
|
-
"type-fest": "^
|
|
50
|
-
"@prosekit/pm": "^0.1.
|
|
49
|
+
"type-fest": "^5.2.0",
|
|
50
|
+
"@prosekit/pm": "^0.1.14"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@types/diffable-html": "^5.0.2",
|
|
54
|
-
"@vitest/browser": "^3.2.4",
|
|
55
54
|
"diffable-html": "^6.0.1",
|
|
56
|
-
"tsdown": "^0.
|
|
57
|
-
"typescript": "~5.9.
|
|
58
|
-
"vitest": "^
|
|
59
|
-
"@prosekit/config-
|
|
60
|
-
"@prosekit/config-
|
|
55
|
+
"tsdown": "^0.16.2",
|
|
56
|
+
"typescript": "~5.9.3",
|
|
57
|
+
"vitest": "^4.0.8",
|
|
58
|
+
"@prosekit/config-vitest": "0.0.0",
|
|
59
|
+
"@prosekit/config-tsdown": "0.0.0"
|
|
61
60
|
},
|
|
62
61
|
"publishConfig": {
|
|
63
62
|
"dev": {}
|
|
@@ -6,8 +6,10 @@ import {
|
|
|
6
6
|
vi,
|
|
7
7
|
} from 'vitest'
|
|
8
8
|
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
9
|
+
import { union } from '../editor/union'
|
|
10
|
+
import { withPriority } from '../editor/with-priority'
|
|
11
|
+
import { setupTest } from '../testing'
|
|
12
|
+
import { Priority } from '../types/priority'
|
|
11
13
|
|
|
12
14
|
import {
|
|
13
15
|
defineKeymap,
|
|
@@ -16,10 +18,7 @@ import {
|
|
|
16
18
|
|
|
17
19
|
describe('keymap', () => {
|
|
18
20
|
it('can register and unregister keymap', () => {
|
|
19
|
-
const
|
|
20
|
-
const extension = defineTestExtension()
|
|
21
|
-
const editor = createEditor({ extension })
|
|
22
|
-
editor.mount(div)
|
|
21
|
+
const { editor } = setupTest()
|
|
23
22
|
|
|
24
23
|
const command1: Command = vi.fn(() => false)
|
|
25
24
|
const command2: Command = vi.fn(() => false)
|
|
@@ -56,10 +55,7 @@ describe('keymap', () => {
|
|
|
56
55
|
})
|
|
57
56
|
|
|
58
57
|
it('can skip unnecessary plugin update', () => {
|
|
59
|
-
const
|
|
60
|
-
const extension = defineTestExtension()
|
|
61
|
-
const editor = createEditor({ extension })
|
|
62
|
-
editor.mount(div)
|
|
58
|
+
const { editor } = setupTest()
|
|
63
59
|
|
|
64
60
|
const command1: Command = vi.fn(() => false)
|
|
65
61
|
const command2: Command = vi.fn(() => false)
|
|
@@ -86,4 +82,44 @@ describe('keymap', () => {
|
|
|
86
82
|
expect(plugins2).toEqual(plugins3)
|
|
87
83
|
expect(plugins3).toEqual(plugins4)
|
|
88
84
|
})
|
|
85
|
+
|
|
86
|
+
it('respects priority and calls highest priority first', () => {
|
|
87
|
+
const { editor } = setupTest()
|
|
88
|
+
|
|
89
|
+
const callOrder: string[] = []
|
|
90
|
+
|
|
91
|
+
const command1: Command = vi.fn(() => {
|
|
92
|
+
callOrder.push('default')
|
|
93
|
+
return false
|
|
94
|
+
})
|
|
95
|
+
const command2: Command = vi.fn(() => {
|
|
96
|
+
callOrder.push('highest')
|
|
97
|
+
return false
|
|
98
|
+
})
|
|
99
|
+
const command3: Command = vi.fn(() => {
|
|
100
|
+
callOrder.push('lowest')
|
|
101
|
+
return false
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
const keymap1: Keymap = { ArrowUp: command1 }
|
|
105
|
+
const keymap2: Keymap = { ArrowUp: command2 }
|
|
106
|
+
const keymap3: Keymap = { ArrowUp: command3 }
|
|
107
|
+
|
|
108
|
+
const extension1 = defineKeymap(keymap1)
|
|
109
|
+
const extension2 = withPriority(defineKeymap(keymap2), Priority.highest)
|
|
110
|
+
const extension3 = withPriority(defineKeymap(keymap3), Priority.lowest)
|
|
111
|
+
|
|
112
|
+
const combinedExtension = union(extension1, extension2, extension3)
|
|
113
|
+
editor.use(combinedExtension)
|
|
114
|
+
|
|
115
|
+
editor.view.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowUp' }))
|
|
116
|
+
|
|
117
|
+
// All commands should be called since none returns true
|
|
118
|
+
expect(command1).toHaveBeenCalledTimes(1)
|
|
119
|
+
expect(command2).toHaveBeenCalledTimes(1)
|
|
120
|
+
expect(command3).toHaveBeenCalledTimes(1)
|
|
121
|
+
|
|
122
|
+
// Highest priority should be called first
|
|
123
|
+
expect(callOrder).toEqual(['highest', 'default', 'lowest'])
|
|
124
|
+
})
|
|
89
125
|
})
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Plugin,
|
|
3
|
+
PluginKey,
|
|
4
|
+
} from '@prosekit/pm/state'
|
|
5
|
+
import {
|
|
6
|
+
describe,
|
|
7
|
+
expect,
|
|
8
|
+
it,
|
|
9
|
+
vi,
|
|
10
|
+
} from 'vitest'
|
|
11
|
+
|
|
12
|
+
import { union } from '../editor/union'
|
|
13
|
+
import { withPriority } from '../editor/with-priority'
|
|
14
|
+
import {
|
|
15
|
+
defineDoc,
|
|
16
|
+
defineParagraph,
|
|
17
|
+
defineText,
|
|
18
|
+
setupTestFromExtension,
|
|
19
|
+
} from '../testing'
|
|
20
|
+
import { Priority } from '../types/priority'
|
|
21
|
+
|
|
22
|
+
import { definePlugin } from './plugin'
|
|
23
|
+
|
|
24
|
+
describe('plugin', () => {
|
|
25
|
+
it('maintains plugin order in state based on priority', () => {
|
|
26
|
+
const plugins = {
|
|
27
|
+
a: new Plugin({ key: new PluginKey('a') }),
|
|
28
|
+
b: new Plugin({ key: new PluginKey('b') }),
|
|
29
|
+
c: new Plugin({ key: new PluginKey('c') }),
|
|
30
|
+
d: new Plugin({ key: new PluginKey('d') }),
|
|
31
|
+
e: new Plugin({ key: new PluginKey('e') }),
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const extension1 = definePlugin(() => [plugins.a, plugins.d]) // default priority
|
|
35
|
+
const extension2 = withPriority(definePlugin(plugins.b), Priority.highest)
|
|
36
|
+
const extension3 = withPriority(definePlugin([plugins.c]), Priority.lowest)
|
|
37
|
+
const extension4 = definePlugin(plugins.e) // default priority
|
|
38
|
+
|
|
39
|
+
const { editor } = setupTestFromExtension(union(
|
|
40
|
+
defineDoc(),
|
|
41
|
+
defineParagraph(),
|
|
42
|
+
defineText(),
|
|
43
|
+
extension1,
|
|
44
|
+
extension2,
|
|
45
|
+
extension3,
|
|
46
|
+
extension4,
|
|
47
|
+
))
|
|
48
|
+
|
|
49
|
+
const pluginKeys = editor.state.plugins.map((plugin) => {
|
|
50
|
+
for (const [key, value] of Object.entries(plugins)) {
|
|
51
|
+
if (plugin === value) {
|
|
52
|
+
return key
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return undefined
|
|
56
|
+
}).filter(Boolean)
|
|
57
|
+
|
|
58
|
+
// The plugins with the highest priority should be listed
|
|
59
|
+
// first in state. The plugins with the same priority should be listed in
|
|
60
|
+
// the order of the extensions.
|
|
61
|
+
expect(pluginKeys).toEqual([
|
|
62
|
+
// Highest priority
|
|
63
|
+
'b',
|
|
64
|
+
|
|
65
|
+
// Default priority, added in the last extension
|
|
66
|
+
'e',
|
|
67
|
+
|
|
68
|
+
// Default priority, added as the second plugin in the first extension
|
|
69
|
+
'd',
|
|
70
|
+
|
|
71
|
+
// Default priority, added as the first plugin in the first extension
|
|
72
|
+
'a',
|
|
73
|
+
|
|
74
|
+
// Lowest priority
|
|
75
|
+
'c',
|
|
76
|
+
])
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
it('calls handlers in priority order with highest priority first', () => {
|
|
80
|
+
const callOrder: string[] = []
|
|
81
|
+
|
|
82
|
+
const handleKeyDownA = vi.fn(() => {
|
|
83
|
+
callOrder.push('a')
|
|
84
|
+
return false
|
|
85
|
+
})
|
|
86
|
+
const handleKeyDownB = vi.fn(() => {
|
|
87
|
+
callOrder.push('b')
|
|
88
|
+
return false
|
|
89
|
+
})
|
|
90
|
+
const handleKeyDownC = vi.fn(() => {
|
|
91
|
+
callOrder.push('c')
|
|
92
|
+
return false
|
|
93
|
+
})
|
|
94
|
+
const handleKeyDownD = vi.fn(() => {
|
|
95
|
+
callOrder.push('d')
|
|
96
|
+
return false
|
|
97
|
+
})
|
|
98
|
+
const handleKeyDownE = vi.fn(() => {
|
|
99
|
+
callOrder.push('e')
|
|
100
|
+
return false
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
const plugins = {
|
|
104
|
+
a: new Plugin({ props: { handleKeyDown: handleKeyDownA } }),
|
|
105
|
+
b: new Plugin({ props: { handleKeyDown: handleKeyDownB } }),
|
|
106
|
+
c: new Plugin({ props: { handleKeyDown: handleKeyDownC } }),
|
|
107
|
+
d: new Plugin({ props: { handleKeyDown: handleKeyDownD } }),
|
|
108
|
+
e: new Plugin({ props: { handleKeyDown: handleKeyDownE } }),
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const extension1 = definePlugin(() => [plugins.a, plugins.d]) // default priority
|
|
112
|
+
const extension2 = withPriority(definePlugin(plugins.b), Priority.highest)
|
|
113
|
+
const extension3 = withPriority(definePlugin([plugins.c]), Priority.lowest)
|
|
114
|
+
const extension4 = definePlugin(plugins.e) // default priority
|
|
115
|
+
|
|
116
|
+
const { editor } = setupTestFromExtension(union(
|
|
117
|
+
defineDoc(),
|
|
118
|
+
defineParagraph(),
|
|
119
|
+
defineText(),
|
|
120
|
+
extension1,
|
|
121
|
+
extension2,
|
|
122
|
+
extension3,
|
|
123
|
+
extension4,
|
|
124
|
+
))
|
|
125
|
+
|
|
126
|
+
editor.view.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowUp' }))
|
|
127
|
+
|
|
128
|
+
// All handlers should be called since none returns true
|
|
129
|
+
expect(handleKeyDownA).toHaveBeenCalledTimes(1)
|
|
130
|
+
expect(handleKeyDownB).toHaveBeenCalledTimes(1)
|
|
131
|
+
expect(handleKeyDownC).toHaveBeenCalledTimes(1)
|
|
132
|
+
expect(handleKeyDownD).toHaveBeenCalledTimes(1)
|
|
133
|
+
expect(handleKeyDownE).toHaveBeenCalledTimes(1)
|
|
134
|
+
|
|
135
|
+
// The event handlers of the plugins with the highest priority should be called first
|
|
136
|
+
expect(callOrder).toEqual([
|
|
137
|
+
// Highest priority
|
|
138
|
+
'b',
|
|
139
|
+
|
|
140
|
+
// Default priority, added in the last extension
|
|
141
|
+
'e',
|
|
142
|
+
|
|
143
|
+
// Default priority, added as the second plugin in the first extension
|
|
144
|
+
'd',
|
|
145
|
+
|
|
146
|
+
// Default priority, added as the first plugin in the first extension
|
|
147
|
+
'a',
|
|
148
|
+
|
|
149
|
+
// Lowest priority
|
|
150
|
+
'c',
|
|
151
|
+
])
|
|
152
|
+
})
|
|
153
|
+
})
|
package/src/extensions/plugin.ts
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
type StatePayload,
|
|
16
16
|
} from '../facets/state'
|
|
17
17
|
import type { PlainExtension } from '../types/extension'
|
|
18
|
+
import { toReversed } from '../utils/array'
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
21
|
* Adds a ProseMirror plugin to the editor.
|
|
@@ -30,18 +31,7 @@ export function definePlugin(
|
|
|
30
31
|
| Plugin[]
|
|
31
32
|
| ((context: { schema: Schema }) => Plugin | Plugin[]),
|
|
32
33
|
): PlainExtension {
|
|
33
|
-
|
|
34
|
-
plugin instanceof Plugin
|
|
35
|
-
|| (Array.isArray(plugin) && plugin.every((p) => p instanceof Plugin))
|
|
36
|
-
) {
|
|
37
|
-
return definePluginPayload(() => plugin)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (typeof plugin === 'function') {
|
|
41
|
-
return definePluginPayload(plugin)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
throw new TypeError('Invalid plugin')
|
|
34
|
+
return definePluginPayload(plugin)
|
|
45
35
|
}
|
|
46
36
|
|
|
47
37
|
function definePluginPayload(payload: PluginPayload): PlainExtension {
|
|
@@ -62,6 +52,7 @@ export type PluginPayload =
|
|
|
62
52
|
export const pluginFacet: Facet<PluginPayload, StatePayload> = defineFacet({
|
|
63
53
|
reducer: (payloads): StatePayload => {
|
|
64
54
|
return ({ schema }) => {
|
|
55
|
+
// An array of plugins from lower to higher priority.
|
|
65
56
|
const plugins: ProseMirrorPlugin[] = []
|
|
66
57
|
|
|
67
58
|
for (const payload of payloads) {
|
|
@@ -79,12 +70,11 @@ export const pluginFacet: Facet<PluginPayload, StatePayload> = defineFacet({
|
|
|
79
70
|
}
|
|
80
71
|
}
|
|
81
72
|
|
|
82
|
-
//
|
|
83
|
-
//
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
plugins
|
|
87
|
-
return { plugins }
|
|
73
|
+
// An array of plugins from higher to lower priority. This matches the
|
|
74
|
+
// order of plugins required by ProseMirror.
|
|
75
|
+
const reversedPlugins = toReversed(plugins)
|
|
76
|
+
|
|
77
|
+
return { plugins: reversedPlugins }
|
|
88
78
|
}
|
|
89
79
|
},
|
|
90
80
|
parent: stateFacet,
|
|
@@ -105,7 +105,7 @@ test('Singleton Root Facet Node', () => {
|
|
|
105
105
|
expect(singletonRootNode.getOutput()).toEqual([
|
|
106
106
|
null,
|
|
107
107
|
null,
|
|
108
|
-
sum([...value1, sum(value2), sum(value3),
|
|
108
|
+
sum([...value1, sum(value2), sum(value3), sum(value2), sum(value3)]),
|
|
109
109
|
null,
|
|
110
110
|
null,
|
|
111
111
|
])
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {
|
|
2
|
+
describe,
|
|
3
|
+
expect,
|
|
4
|
+
it,
|
|
5
|
+
} from 'vitest'
|
|
6
|
+
|
|
7
|
+
import { union } from '../editor/union'
|
|
8
|
+
import { withPriority } from '../editor/with-priority'
|
|
9
|
+
import { defineDefaultState } from '../extensions/default-state'
|
|
10
|
+
import {
|
|
11
|
+
defineTestExtension,
|
|
12
|
+
setupTestFromExtension,
|
|
13
|
+
} from '../testing'
|
|
14
|
+
import type { NodeJSON } from '../types/model'
|
|
15
|
+
import { Priority } from '../types/priority'
|
|
16
|
+
|
|
17
|
+
describe('state', () => {
|
|
18
|
+
it('uses doc from extension with highest priority', () => {
|
|
19
|
+
const doc1: NodeJSON = { type: 'doc', content: [{ type: 'paragraph', content: [{ type: 'text', text: 'default priority' }] }] }
|
|
20
|
+
const doc2: NodeJSON = { type: 'doc', content: [{ type: 'paragraph', content: [{ type: 'text', text: 'highest priority' }] }] }
|
|
21
|
+
const doc3: NodeJSON = { type: 'doc', content: [{ type: 'paragraph', content: [{ type: 'text', text: 'lowest priority' }] }] }
|
|
22
|
+
|
|
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)
|
|
26
|
+
|
|
27
|
+
const combinedExtension = union(defineTestExtension(), extension1, extension2, extension3)
|
|
28
|
+
const { editor } = setupTestFromExtension(combinedExtension)
|
|
29
|
+
|
|
30
|
+
const docText = editor.state.doc.textContent
|
|
31
|
+
|
|
32
|
+
// The extension with the highest priority should set the doc
|
|
33
|
+
expect(docText).toEqual('highest priority')
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
it('uses doc from last extension when all have same priority', () => {
|
|
37
|
+
const doc1 = { type: 'doc', content: [{ type: 'paragraph', content: [{ type: 'text', text: 'first' }] }] }
|
|
38
|
+
const doc2 = { type: 'doc', content: [{ type: 'paragraph', content: [{ type: 'text', text: 'second' }] }] }
|
|
39
|
+
const doc3 = { type: 'doc', content: [{ type: 'paragraph', content: [{ type: 'text', text: 'third' }] }] }
|
|
40
|
+
|
|
41
|
+
const extension1 = defineDefaultState({ defaultDoc: doc1 })
|
|
42
|
+
const extension2 = defineDefaultState({ defaultDoc: doc2 })
|
|
43
|
+
const extension3 = defineDefaultState({ defaultDoc: doc3 })
|
|
44
|
+
|
|
45
|
+
const combinedExtension = union(defineTestExtension(), extension1, extension2, extension3)
|
|
46
|
+
const { editor } = setupTestFromExtension(combinedExtension)
|
|
47
|
+
|
|
48
|
+
const docText = editor.state.doc.textContent
|
|
49
|
+
|
|
50
|
+
// When all have same priority, later extensions override earlier ones
|
|
51
|
+
expect(docText).toEqual('third')
|
|
52
|
+
})
|
|
53
|
+
})
|
package/src/facets/state.ts
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
Mark,
|
|
3
|
+
ProseMirrorNode,
|
|
4
|
+
Schema,
|
|
5
|
+
} from '@prosekit/pm/model'
|
|
2
6
|
import type { EditorStateConfig } from '@prosekit/pm/state'
|
|
7
|
+
import type {
|
|
8
|
+
Plugin,
|
|
9
|
+
Selection,
|
|
10
|
+
} from '@prosekit/pm/state'
|
|
3
11
|
|
|
4
|
-
import {
|
|
12
|
+
import { toReversed } from '../utils/array'
|
|
5
13
|
import { assert } from '../utils/assert'
|
|
6
14
|
|
|
7
15
|
import {
|
|
@@ -17,34 +25,54 @@ export type StatePayload = (ctx: { schema: Schema }) => EditorStateConfig
|
|
|
17
25
|
|
|
18
26
|
export const stateFacet: Facet<StatePayload, RootPayload> = defineFacet({
|
|
19
27
|
reduce: () => {
|
|
28
|
+
// An array of state payloads from lower to higher priority.
|
|
20
29
|
let callbacks: StatePayload[] = []
|
|
21
30
|
|
|
22
31
|
const state: StatePayload = (ctx) => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
32
|
+
let doc: ProseMirrorNode | undefined
|
|
33
|
+
let selection: Selection | undefined
|
|
34
|
+
let schema: Schema | undefined = ctx.schema
|
|
35
|
+
const markSet = new Set<Mark>()
|
|
36
|
+
const pluginSet = new Set<Plugin>()
|
|
37
|
+
|
|
38
|
+
// An array of state payloads from higher to lower priority. This matches the
|
|
39
|
+
// order of plugins required by ProseMirror.
|
|
40
|
+
const reversedCallbacks = toReversed(callbacks)
|
|
41
|
+
|
|
42
|
+
for (const callback of reversedCallbacks) {
|
|
43
|
+
const config = callback(ctx)
|
|
44
|
+
|
|
45
|
+
doc ||= config.doc
|
|
46
|
+
selection ||= config.selection
|
|
47
|
+
schema ||= config.schema
|
|
48
|
+
|
|
49
|
+
for (const mark of (config.storedMarks ?? [])) {
|
|
50
|
+
markSet.add(mark)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
for (const plugin of (config.plugins ?? [])) {
|
|
54
|
+
// `config.plugins` is an array of plugins from higher to lower priority.
|
|
55
|
+
pluginSet.add(plugin)
|
|
56
|
+
}
|
|
28
57
|
}
|
|
29
58
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
config.selection = config.selection ?? c.selection
|
|
34
|
-
config.storedMarks = [...config.storedMarks!, ...(c.storedMarks ?? [])]
|
|
35
|
-
config.plugins = uniqPush(config.plugins ?? [], c.plugins ?? [])
|
|
59
|
+
// If both doc and schema are provided, the schema is not needed.
|
|
60
|
+
if (doc && schema) {
|
|
61
|
+
schema = undefined
|
|
36
62
|
}
|
|
37
63
|
|
|
38
64
|
assert(
|
|
39
|
-
|
|
65
|
+
doc || schema,
|
|
40
66
|
"Can't create state without a schema nor a document",
|
|
41
67
|
)
|
|
42
68
|
|
|
43
|
-
|
|
44
|
-
|
|
69
|
+
return {
|
|
70
|
+
doc,
|
|
71
|
+
selection,
|
|
72
|
+
schema,
|
|
73
|
+
storedMarks: Array.from(markSet),
|
|
74
|
+
plugins: Array.from(pluginSet),
|
|
45
75
|
}
|
|
46
|
-
|
|
47
|
-
return config
|
|
48
76
|
}
|
|
49
77
|
|
|
50
78
|
return function reducer(inputs) {
|
package/src/testing/keyboard.ts
CHANGED
package/src/utils/clsx.ts
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"editor-CfkZ4TNU.d.ts","names":[],"sources":["../src/types/attrs.ts","../src/editor/action.ts","../src/types/extension-command.ts","../src/types/extension-mark.ts","../src/types/extension-node.ts","../src/types/pick-sub-type.ts","../src/types/pick-string-literal.ts","../src/types/priority.ts","../src/types/simplify-deeper.ts","../src/types/simplify-union.ts","../src/types/extension.ts","../src/types/model.ts","../src/types/dom-node.ts","../src/utils/parse.ts","../src/editor/editor.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;AAOY,KAAA,QAAA,GAAW,KAAA;AAKvB;;;KAAY;ECWA;;;;;EAWK,OAAA,CAAA,EDhBL,QCgBe;EAAA;;;;;;;;;;EA4BV,QAAA,CAAA,EAAA,MAAU,GAAA,CAAA,CAAA,KAAA,EAAA,OAAA,EAAA,GAAA,IAAA,CAAA;CAAA;;;;;;ADvD3B;AAKA;KCWY,SAAA,GAAY,2BAA2B;;;AAAnD;;;;;AAWA;;AAA0C,UAAzB,UAAyB,CAAA,cAAA,QAAA,GAAW,QAAX,CAAA,CAAA;;;;QAIS,EAAzC,KAAyC,GAAA,IAAA,EAAA,GAAA,QAAA,EAAd,SAAc,EAAA,CAAA,EAAA,eAAA;;;;EAYzB,CAAA,GAAA,QAAA,EAPV,SAOU,EAAA,CAAA,EAPI,eAOJ;EAYT;;;;;UAIoB,EAAA,CAAA,KAAA,CAAA,EAhBhB,KAgBgB,EAAA,GAAA,OAAA;;;;;;AAkBrC;AAKA;;;;AChFiB,UDqDA,UCrDa,CAAA,cDqDY,QCrDZ,GDqDuB,QCrDvB,CAAA,CAAA;EAAA;;;QAkBV,EDuCV,KCvCU,GAAA,IAAA,EAAA,GAAA,QAAA,EDuCiB,SCvCjB,EAAA,CAAA,EDuC+B,eCvC/B,EAAA;EAAI;AAGxB;;MACU,QAAA,EDwCM,SCxCN,EAAA,CAAA,EDwCoB,eCxCpB,EAAA;;;AAMV;AAQA;;UAAwC,EAAA,CAAA,KAAA,CAAA,EDiCnB,KCjCmB,EAAA,GAAA,OAAA;;;;;AACR,KDsCpB,WAAA,GAAc,UCtCM;AAGhC;;;AACc,KDuCF,WAAA,GAAc,UCvCZ;;;;;;;;;;;AF3Cd;AAKA;UEHiB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