@prosekit/core 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{editor-4lgGc3CY.d.ts → editor.d.ts} +58 -18
- package/dist/editor.d.ts.map +1 -0
- package/dist/{editor-DGNUXn-u.js → editor.js} +40 -81
- package/dist/editor.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 +2 -4
- package/dist/prosekit-core-test.js.map +1 -1
- package/dist/prosekit-core.d.ts +148 -68
- package/dist/prosekit-core.d.ts.map +1 -1
- package/dist/prosekit-core.js +184 -138
- package/dist/prosekit-core.js.map +1 -1
- package/package.json +9 -9
- package/src/commands/add-mark.ts +3 -6
- package/src/commands/expand-mark.ts +4 -11
- package/src/commands/insert-default-block.spec.ts +4 -8
- package/src/commands/insert-default-block.ts +2 -5
- package/src/commands/insert-node.ts +7 -11
- package/src/commands/remove-mark.ts +3 -6
- package/src/commands/remove-node.ts +4 -4
- package/src/commands/select-block.spec.ts +6 -8
- package/src/commands/select-block.ts +2 -5
- package/src/commands/set-block-type.ts +3 -6
- 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 +26 -27
- package/src/commands/toggle-mark.ts +3 -6
- package/src/commands/toggle-node.ts +4 -7
- package/src/commands/toggle-wrap.spec.ts +2 -6
- package/src/commands/toggle-wrap.ts +3 -6
- package/src/commands/unset-block-type.spec.ts +2 -6
- package/src/commands/unset-block-type.ts +3 -9
- package/src/commands/unset-mark.spec.ts +2 -6
- package/src/commands/unset-mark.ts +1 -1
- package/src/commands/wrap.ts +2 -5
- package/src/editor/action.spec.ts +5 -9
- package/src/editor/action.ts +7 -14
- package/src/editor/editor.spec.ts +8 -15
- package/src/editor/editor.ts +18 -52
- package/src/editor/union.spec.ts +8 -12
- package/src/editor/union.ts +4 -7
- package/src/editor/with-priority.ts +3 -3
- package/src/error.ts +8 -1
- package/src/extensions/clipboard-serializer.ts +22 -26
- package/src/extensions/command.ts +22 -54
- package/src/extensions/default-state.spec.ts +4 -8
- package/src/extensions/default-state.ts +6 -12
- package/src/extensions/events/doc-change.ts +2 -2
- package/src/extensions/events/dom-event.spec.ts +4 -9
- package/src/extensions/events/dom-event.ts +9 -21
- package/src/extensions/events/editor-event.ts +8 -20
- package/src/extensions/events/focus.spec.ts +7 -12
- package/src/extensions/events/focus.ts +2 -2
- package/src/extensions/events/plugin-view.ts +5 -12
- package/src/extensions/history.ts +7 -14
- package/src/extensions/keymap-base.spec.ts +6 -15
- package/src/extensions/keymap-base.ts +6 -9
- package/src/extensions/keymap.spec.ts +10 -24
- package/src/extensions/keymap.ts +5 -15
- package/src/extensions/mark-spec.spec.ts +6 -21
- package/src/extensions/mark-spec.ts +10 -21
- package/src/extensions/mark-view-effect.ts +6 -12
- package/src/extensions/mark-view.ts +5 -11
- package/src/extensions/node-spec.spec.ts +10 -26
- package/src/extensions/node-spec.ts +10 -21
- package/src/extensions/node-view-effect.ts +6 -12
- package/src/extensions/node-view.ts +5 -11
- package/src/extensions/plugin.spec.ts +9 -22
- package/src/extensions/plugin.ts +6 -15
- package/src/facets/base-extension.ts +7 -10
- package/src/facets/command.ts +3 -9
- package/src/facets/facet-extension.spec.ts +10 -21
- package/src/facets/facet-extension.ts +12 -8
- package/src/facets/facet-node.spec.ts +4 -11
- package/src/facets/facet-node.ts +27 -22
- package/src/facets/facet.spec.ts +2 -5
- package/src/facets/facet.ts +14 -7
- package/src/facets/root.ts +2 -2
- package/src/facets/schema-spec.ts +3 -10
- package/src/facets/schema.ts +4 -13
- package/src/facets/state.spec.ts +8 -15
- package/src/facets/state.ts +5 -19
- package/src/facets/union-extension.ts +10 -13
- package/src/index.ts +74 -200
- package/src/test/index.ts +1 -4
- package/src/test/test-builder.ts +2 -5
- package/src/test/test-editor.spec.ts +2 -6
- package/src/test/test-editor.ts +7 -26
- package/src/testing/index.ts +26 -22
- package/src/types/extension-mark.ts +1 -1
- package/src/types/extension-node.ts +1 -1
- package/src/types/extension.spec.ts +2 -5
- package/src/types/extension.ts +8 -18
- package/src/types/pick-string-literal.spec.ts +2 -2
- package/src/types/pick-string-literal.ts +1 -1
- package/src/types/pick-sub-type.spec.ts +2 -2
- package/src/types/priority.ts +50 -7
- package/src/types/simplify-deeper.spec.ts +2 -2
- package/src/types/simplify-union.spec.ts +2 -2
- package/src/types/simplify-union.ts +1 -4
- package/src/utils/array-grouping.spec.ts +2 -5
- package/src/utils/assert.ts +1 -1
- package/src/utils/attrs-match.ts +1 -5
- package/src/utils/can-use-regex-lookbehind.ts +2 -8
- package/src/utils/clsx.spec.ts +2 -5
- package/src/utils/combine-event-handlers.spec.ts +2 -6
- package/src/utils/default-block-at.ts +1 -4
- package/src/utils/editor-content.spec.ts +3 -6
- package/src/utils/editor-content.ts +5 -17
- 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 +3 -7
- package/src/utils/find-parent-node.ts +1 -4
- package/src/utils/get-custom-selection.ts +1 -5
- package/src/utils/get-dom-api.ts +1 -1
- package/src/utils/get-mark-type.ts +2 -5
- package/src/utils/get-node-type.ts +2 -5
- package/src/utils/get-node-types.ts +2 -5
- package/src/utils/includes-mark.ts +2 -6
- package/src/utils/is-at-block-start.ts +1 -4
- package/src/utils/is-mark-absent.spec.ts +3 -6
- package/src/utils/is-mark-absent.ts +2 -6
- package/src/utils/is-mark-active.ts +4 -7
- package/src/utils/is-node-active.spec.ts +109 -0
- package/src/utils/is-node-active.ts +19 -10
- package/src/utils/is-subset.spec.ts +2 -5
- package/src/utils/maybe-run.spec.ts +2 -6
- package/src/utils/merge-objects.spec.ts +2 -5
- package/src/utils/merge-objects.ts +3 -2
- package/src/utils/merge-specs.ts +2 -5
- package/src/utils/object-equal.spec.ts +2 -5
- package/src/utils/output-spec.test.ts +2 -6
- package/src/utils/output-spec.ts +2 -10
- package/src/utils/parse.spec.ts +6 -15
- package/src/utils/parse.ts +4 -16
- package/src/utils/remove-undefined-values.spec.ts +2 -5
- package/src/utils/set-selection-around.ts +1 -4
- package/src/utils/type-assertion.ts +2 -21
- package/src/utils/unicode.spec.ts +2 -5
- package/src/utils/with-skip-code-block.ts +1 -1
- package/dist/editor-4lgGc3CY.d.ts.map +0 -1
- package/dist/editor-DGNUXn-u.js.map +0 -1
|
@@ -1,25 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from '
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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'
|
|
1
|
+
import { Plugin, PluginKey } from '@prosekit/pm/state'
|
|
2
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
3
|
+
|
|
4
|
+
import { union } from '../editor/union.ts'
|
|
5
|
+
import { withPriority } from '../editor/with-priority.ts'
|
|
6
|
+
import { defineDoc, defineParagraph, defineText, setupTestFromExtension } from '../testing/index.ts'
|
|
7
|
+
import { Priority } from '../types/priority.ts'
|
|
8
|
+
|
|
9
|
+
import { definePlugin } from './plugin.ts'
|
|
23
10
|
|
|
24
11
|
describe('plugin', () => {
|
|
25
12
|
it('maintains plugin order in state based on priority', () => {
|
package/src/extensions/plugin.ts
CHANGED
|
@@ -1,20 +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
|
-
import { ProseKitError } from '../error'
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
} from '../
|
|
12
|
-
import { defineFacetPayload } from '../facets/facet-extension'
|
|
13
|
-
import {
|
|
14
|
-
stateFacet,
|
|
15
|
-
type StatePayload,
|
|
16
|
-
} from '../facets/state'
|
|
17
|
-
import type { PlainExtension } from '../types/extension'
|
|
4
|
+
import { ProseKitError } from '../error.ts'
|
|
5
|
+
import { defineFacetPayload } from '../facets/facet-extension.ts'
|
|
6
|
+
import { defineFacet, type Facet } from '../facets/facet.ts'
|
|
7
|
+
import { stateFacet, type StatePayload } from '../facets/state.ts'
|
|
8
|
+
import type { PlainExtension } from '../types/extension.ts'
|
|
18
9
|
|
|
19
10
|
/**
|
|
20
11
|
* Adds a ProseMirror plugin to the editor.
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import type { Schema } from '@prosekit/pm/model'
|
|
2
2
|
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
ExtensionTyping,
|
|
6
|
-
} from '../types/extension'
|
|
7
|
-
import { Priority } from '../types/priority'
|
|
3
|
+
import type { Extension, ExtensionTyping } from '../types/extension.ts'
|
|
4
|
+
import type { Priority } from '../types/priority.ts'
|
|
8
5
|
|
|
9
|
-
import type {
|
|
10
|
-
import type {
|
|
11
|
-
import type {
|
|
12
|
-
import { schemaFacet } from './schema'
|
|
6
|
+
import type { FacetNode } from './facet-node.ts'
|
|
7
|
+
import type { Tuple5 } from './facet-types.ts'
|
|
8
|
+
import type { Facet } from './facet.ts'
|
|
9
|
+
import { schemaFacet } from './schema.ts'
|
|
13
10
|
|
|
14
11
|
/**
|
|
15
12
|
* @internal
|
|
@@ -30,7 +27,7 @@ export abstract class BaseExtension<T extends ExtensionTyping = ExtensionTyping>
|
|
|
30
27
|
* @internal
|
|
31
28
|
*/
|
|
32
29
|
getTree(priority?: Priority): FacetNode {
|
|
33
|
-
const pri = priority ?? this.priority ?? Priority.default
|
|
30
|
+
const pri = priority ?? this.priority ?? (2 satisfies typeof Priority.default)
|
|
34
31
|
return (this.trees[pri] ||= this.createTree(pri))
|
|
35
32
|
}
|
|
36
33
|
|
package/src/facets/command.ts
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
import type { CommandCreators } from '../types/extension-command'
|
|
1
|
+
import type { CommandCreators } from '../types/extension-command.ts'
|
|
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.ts'
|
|
4
|
+
import { rootFacet, type RootPayload } from './root.ts'
|
|
11
5
|
|
|
12
6
|
type CommandPayload = CommandCreators
|
|
13
7
|
|
|
@@ -1,24 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from '
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
defineFacet,
|
|
13
|
-
Facet,
|
|
14
|
-
} from './facet'
|
|
15
|
-
import { FacetExtensionImpl } from './facet-extension'
|
|
16
|
-
import {
|
|
17
|
-
subtractFacetNode,
|
|
18
|
-
unionFacetNode,
|
|
19
|
-
} from './facet-node'
|
|
20
|
-
import type { FacetReducer } from './facet-types'
|
|
21
|
-
import { UnionExtensionImpl } from './union-extension'
|
|
1
|
+
import { isNotNullish } from '@ocavue/utils'
|
|
2
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
3
|
+
|
|
4
|
+
import { Priority } from '../types/priority.ts'
|
|
5
|
+
|
|
6
|
+
import { FacetExtensionImpl } from './facet-extension.ts'
|
|
7
|
+
import { subtractFacetNode, unionFacetNode } from './facet-node.ts'
|
|
8
|
+
import type { FacetReducer } from './facet-types.ts'
|
|
9
|
+
import { defineFacet, Facet } from './facet.ts'
|
|
10
|
+
import { UnionExtensionImpl } from './union-extension.ts'
|
|
22
11
|
|
|
23
12
|
describe('facet extension', () => {
|
|
24
13
|
type FooHandler = (foo: string) => void
|
|
@@ -1,25 +1,29 @@
|
|
|
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 { BaseExtension } from './base-extension'
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import type {
|
|
4
|
+
import { BaseExtension } from './base-extension.ts'
|
|
5
|
+
import { FacetNode } from './facet-node.ts'
|
|
6
|
+
import type { Tuple5 } from './facet-types.ts'
|
|
7
|
+
import type { Facet } from './facet.ts'
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* @internal
|
|
11
11
|
*/
|
|
12
12
|
export class FacetExtensionImpl<Input, Output> extends BaseExtension {
|
|
13
13
|
declare extension: Extension
|
|
14
|
+
readonly facet: Facet<Input, Output>
|
|
15
|
+
readonly payloads: Input[]
|
|
14
16
|
|
|
15
17
|
/**
|
|
16
18
|
* @internal
|
|
17
19
|
*/
|
|
18
20
|
constructor(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
facet: Facet<Input, Output>,
|
|
22
|
+
payloads: Input[],
|
|
21
23
|
) {
|
|
22
24
|
super()
|
|
25
|
+
this.facet = facet
|
|
26
|
+
this.payloads = payloads
|
|
23
27
|
}
|
|
24
28
|
|
|
25
29
|
/**
|
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
expect,
|
|
3
|
-
test,
|
|
4
|
-
} from 'vitest'
|
|
1
|
+
import { expect, test } from 'vitest'
|
|
5
2
|
|
|
6
|
-
import { Priority } from '../types/priority'
|
|
3
|
+
import { Priority } from '../types/priority.ts'
|
|
7
4
|
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
FacetNode,
|
|
11
|
-
subtractFacetNode,
|
|
12
|
-
unionFacetNode,
|
|
13
|
-
} from './facet-node'
|
|
5
|
+
import { FacetNode, subtractFacetNode, unionFacetNode } from './facet-node.ts'
|
|
6
|
+
import { Facet } from './facet.ts'
|
|
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,17 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
} from '../utils/
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
import type {
|
|
10
|
-
import type {
|
|
11
|
-
FacetReducer,
|
|
12
|
-
Tuple5,
|
|
13
|
-
} from './facet-types'
|
|
14
|
-
import type { RootOutput } from './root'
|
|
1
|
+
import { isNotNullish } from '@ocavue/utils'
|
|
2
|
+
|
|
3
|
+
import type { Priority } from '../types/priority.ts'
|
|
4
|
+
import { arraySubtract, uniqPush } from '../utils/array.ts'
|
|
5
|
+
import { assert } from '../utils/assert.ts'
|
|
6
|
+
|
|
7
|
+
import type { FacetReducer, Tuple5 } from './facet-types.ts'
|
|
8
|
+
import type { Facet } from './facet.ts'
|
|
9
|
+
import type { RootOutput } from './root.ts'
|
|
15
10
|
|
|
16
11
|
function zip5<T>(
|
|
17
12
|
a: Tuple5<T>,
|
|
@@ -109,18 +104,28 @@ export function subtractFacetNode<I, O>(
|
|
|
109
104
|
export class FacetNode<I = any, O = any> {
|
|
110
105
|
output: Tuple5<O | null> | null = null
|
|
111
106
|
|
|
107
|
+
readonly facet: Facet<I, O>
|
|
108
|
+
readonly inputs: Tuple5<I[] | null>
|
|
109
|
+
readonly children: Map<number, FacetNode>
|
|
110
|
+
readonly reducers: Tuple5<FacetReducer<I, O> | null>
|
|
111
|
+
|
|
112
112
|
constructor(
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
113
|
+
facet: Facet<I, O>,
|
|
114
|
+
inputs: Tuple5<I[] | null> = [null, null, null, null, null],
|
|
115
|
+
children: Map<number, FacetNode> = new Map<number, FacetNode>(),
|
|
116
|
+
reducers: Tuple5<FacetReducer<I, O> | null> = [
|
|
117
117
|
null,
|
|
118
118
|
null,
|
|
119
119
|
null,
|
|
120
120
|
null,
|
|
121
121
|
null,
|
|
122
122
|
],
|
|
123
|
-
) {
|
|
123
|
+
) {
|
|
124
|
+
this.facet = facet
|
|
125
|
+
this.inputs = inputs
|
|
126
|
+
this.children = children
|
|
127
|
+
this.reducers = reducers
|
|
128
|
+
}
|
|
124
129
|
|
|
125
130
|
private calcOutput(): Tuple5<O | null> {
|
|
126
131
|
const inputs: Tuple5<I[] | null> = [null, null, null, null, null]
|
|
@@ -144,9 +149,9 @@ export class FacetNode<I = any, O = any> {
|
|
|
144
149
|
}
|
|
145
150
|
|
|
146
151
|
if (this.facet.singleton) {
|
|
147
|
-
const reducer = (this.reducers[Priority.default] ||= this.facet.reducer)
|
|
152
|
+
const reducer = (this.reducers[2 satisfies typeof Priority.default] ||= this.facet.reducer)
|
|
148
153
|
const input: I[] = inputs.filter(isNotNullish).flat()
|
|
149
|
-
output[Priority.default] = reducer(input)
|
|
154
|
+
output[2 satisfies typeof Priority.default] = reducer(input)
|
|
150
155
|
} else {
|
|
151
156
|
for (let pri = 0; pri < 5; pri++) {
|
|
152
157
|
const input = inputs[pri]
|
|
@@ -169,7 +174,7 @@ export class FacetNode<I = any, O = any> {
|
|
|
169
174
|
|
|
170
175
|
getSingletonOutput(): O | null {
|
|
171
176
|
assert(this.facet.singleton)
|
|
172
|
-
return this.getOutput()[Priority.default]
|
|
177
|
+
return this.getOutput()[2 satisfies typeof Priority.default]
|
|
173
178
|
}
|
|
174
179
|
|
|
175
180
|
getRootOutput(): RootOutput {
|
package/src/facets/facet.spec.ts
CHANGED
package/src/facets/facet.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ProseKitError } from '../error.ts'
|
|
2
2
|
|
|
3
|
-
import type { FacetReducer } from './facet-types'
|
|
3
|
+
import type { FacetReducer } from './facet-types.ts'
|
|
4
4
|
|
|
5
5
|
let facetCount = 0
|
|
6
6
|
|
|
@@ -27,17 +27,24 @@ export class Facet<Input, Output> {
|
|
|
27
27
|
*/
|
|
28
28
|
readonly path: number[]
|
|
29
29
|
|
|
30
|
+
private reduce: () => FacetReducer<Input, Output>
|
|
31
|
+
|
|
30
32
|
/**
|
|
31
33
|
* @internal
|
|
32
34
|
*/
|
|
33
35
|
constructor(
|
|
34
36
|
parent: Facet<Output, any> | null,
|
|
35
37
|
singleton: boolean,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
reducer?: FacetReducer<Input, Output>,
|
|
39
|
+
reduce?: () => FacetReducer<Input, Output>,
|
|
38
40
|
) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
if (reduce && !reducer) {
|
|
42
|
+
this.reduce = reduce
|
|
43
|
+
} else if (reducer && !reduce) {
|
|
44
|
+
this.reduce = () => reducer
|
|
45
|
+
} else {
|
|
46
|
+
throw new ProseKitError('Incorrect reducer')
|
|
47
|
+
}
|
|
41
48
|
|
|
42
49
|
this.parent = parent
|
|
43
50
|
this.singleton = singleton
|
|
@@ -45,7 +52,7 @@ export class Facet<Input, Output> {
|
|
|
45
52
|
}
|
|
46
53
|
|
|
47
54
|
get reducer(): FacetReducer<Input, Output> {
|
|
48
|
-
return
|
|
55
|
+
return this.reduce()
|
|
49
56
|
}
|
|
50
57
|
}
|
|
51
58
|
|
package/src/facets/root.ts
CHANGED
|
@@ -2,9 +2,9 @@ import type { Schema } from '@prosekit/pm/model'
|
|
|
2
2
|
import type { EditorStateConfig } from '@prosekit/pm/state'
|
|
3
3
|
import type { DirectEditorProps } from '@prosekit/pm/view'
|
|
4
4
|
|
|
5
|
-
import type { CommandCreators } from '../types/extension-command'
|
|
5
|
+
import type { CommandCreators } from '../types/extension-command.ts'
|
|
6
6
|
|
|
7
|
-
import { Facet } from './facet'
|
|
7
|
+
import { Facet } from './facet.ts'
|
|
8
8
|
|
|
9
9
|
export type RootPayload = {
|
|
10
10
|
schema?: Schema | null
|
|
@@ -1,15 +1,8 @@
|
|
|
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
|
-
|
|
10
|
-
type Facet,
|
|
11
|
-
} from './facet'
|
|
12
|
-
import { schemaFacet } from './schema'
|
|
4
|
+
import { defineFacet, type Facet } from './facet.ts'
|
|
5
|
+
import { schemaFacet } from './schema.ts'
|
|
13
6
|
|
|
14
7
|
export const schemaSpecFacet: Facet<SchemaSpec, SchemaSpec> = defineFacet({
|
|
15
8
|
reducer: (specs): SchemaSpec => {
|
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
|
-
import { assert } from '../utils/assert'
|
|
3
|
+
import { assert } from '../utils/assert.ts'
|
|
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.ts'
|
|
6
|
+
import { rootFacet, type RootPayload } from './root.ts'
|
|
16
7
|
|
|
17
8
|
export const schemaFacet: Facet<SchemaSpec, RootPayload> = defineFacet({
|
|
18
9
|
reducer: (specs) => {
|
package/src/facets/state.spec.ts
CHANGED
|
@@ -1,18 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
} from '
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
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'
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import { union } from '../editor/union.ts'
|
|
4
|
+
import { withPriority } from '../editor/with-priority.ts'
|
|
5
|
+
import { defineDefaultState } from '../extensions/default-state.ts'
|
|
6
|
+
import { defineTestExtension, setupTestFromExtension } from '../testing/index.ts'
|
|
7
|
+
import type { NodeJSON } from '../types/model.ts'
|
|
8
|
+
import { Priority } from '../types/priority.ts'
|
|
16
9
|
|
|
17
10
|
describe('state', () => {
|
|
18
11
|
it('uses doc from extension with highest priority', () => {
|
package/src/facets/state.ts
CHANGED
|
@@ -1,24 +1,10 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
ProseMirrorNode,
|
|
4
|
-
Schema,
|
|
5
|
-
} from '@prosekit/pm/model'
|
|
6
|
-
import type { EditorStateConfig } from '@prosekit/pm/state'
|
|
7
|
-
import type {
|
|
8
|
-
Plugin,
|
|
9
|
-
Selection,
|
|
10
|
-
} from '@prosekit/pm/state'
|
|
1
|
+
import type { Mark, ProseMirrorNode, Schema } from '@prosekit/pm/model'
|
|
2
|
+
import type { EditorStateConfig, Plugin, Selection } from '@prosekit/pm/state'
|
|
11
3
|
|
|
12
|
-
import { assert } from '../utils/assert'
|
|
4
|
+
import { assert } from '../utils/assert.ts'
|
|
13
5
|
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
type Facet,
|
|
17
|
-
} from './facet'
|
|
18
|
-
import {
|
|
19
|
-
rootFacet,
|
|
20
|
-
type RootPayload,
|
|
21
|
-
} from './root'
|
|
6
|
+
import { defineFacet, type Facet } from './facet.ts'
|
|
7
|
+
import { rootFacet, type RootPayload } from './root.ts'
|
|
22
8
|
|
|
23
9
|
export type StatePayload = (ctx: { schema: Schema }) => EditorStateConfig
|
|
24
10
|
|
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
import { BaseExtension } from './base-extension'
|
|
9
|
-
import {
|
|
10
|
-
unionFacetNode,
|
|
11
|
-
type FacetNode,
|
|
12
|
-
} from './facet-node'
|
|
1
|
+
import type { Extension, ExtensionTyping } from '../types/extension.ts'
|
|
2
|
+
import type { Priority } from '../types/priority.ts'
|
|
3
|
+
import { assert } from '../utils/assert.ts'
|
|
4
|
+
|
|
5
|
+
import { BaseExtension } from './base-extension.ts'
|
|
6
|
+
import { unionFacetNode, type FacetNode } from './facet-node.ts'
|
|
13
7
|
|
|
14
8
|
export class UnionExtensionImpl<T extends ExtensionTyping = ExtensionTyping> extends BaseExtension<T> implements Extension<T> {
|
|
9
|
+
readonly extension: BaseExtension[]
|
|
10
|
+
|
|
15
11
|
/**
|
|
16
12
|
* @internal
|
|
17
13
|
*/
|
|
18
|
-
constructor(
|
|
14
|
+
constructor(extension: BaseExtension[] = []) {
|
|
19
15
|
super()
|
|
16
|
+
this.extension = extension
|
|
20
17
|
}
|
|
21
18
|
|
|
22
19
|
/**
|