@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
package/src/facets/state.ts
CHANGED
|
@@ -1,25 +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 { toReversed } from '../utils/array'
|
|
13
4
|
import { assert } from '../utils/assert'
|
|
14
5
|
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
type Facet,
|
|
18
|
-
} from './facet'
|
|
19
|
-
import {
|
|
20
|
-
rootFacet,
|
|
21
|
-
type RootPayload,
|
|
22
|
-
} from './root'
|
|
6
|
+
import { defineFacet, type Facet } from './facet'
|
|
7
|
+
import { rootFacet, type RootPayload } from './root'
|
|
23
8
|
|
|
24
9
|
export type StatePayload = (ctx: { schema: Schema }) => EditorStateConfig
|
|
25
10
|
|
|
@@ -37,7 +22,7 @@ export const stateFacet: Facet<StatePayload, RootPayload> = defineFacet({
|
|
|
37
22
|
|
|
38
23
|
// An array of state payloads from higher to lower priority. This matches the
|
|
39
24
|
// order of plugins required by ProseMirror.
|
|
40
|
-
const reversedCallbacks =
|
|
25
|
+
const reversedCallbacks = [...callbacks].reverse()
|
|
41
26
|
|
|
42
27
|
for (const callback of reversedCallbacks) {
|
|
43
28
|
const config = callback(ctx)
|
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Extension,
|
|
3
|
-
ExtensionTyping,
|
|
4
|
-
} from '../types/extension'
|
|
1
|
+
import type { Extension, ExtensionTyping } from '../types/extension'
|
|
5
2
|
import type { Priority } from '../types/priority'
|
|
6
3
|
import { assert } from '../utils/assert'
|
|
7
4
|
|
|
8
5
|
import { BaseExtension } from './base-extension'
|
|
9
|
-
import {
|
|
10
|
-
unionFacetNode,
|
|
11
|
-
type FacetNode,
|
|
12
|
-
} from './facet-node'
|
|
6
|
+
import { unionFacetNode, type FacetNode } from './facet-node'
|
|
13
7
|
|
|
14
8
|
export class UnionExtensionImpl<T extends ExtensionTyping = ExtensionTyping> extends BaseExtension<T> implements Extension<T> {
|
|
15
9
|
/**
|
package/src/index.ts
CHANGED
|
@@ -1,102 +1,30 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from './commands/
|
|
5
|
-
export {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} from './commands/
|
|
9
|
-
export {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
} from './commands/
|
|
13
|
-
export {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
} from './commands/
|
|
17
|
-
export {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
} from './commands/remove-mark'
|
|
21
|
-
export {
|
|
22
|
-
removeNode,
|
|
23
|
-
type RemoveNodeOptions,
|
|
24
|
-
} from './commands/remove-node'
|
|
25
|
-
export {
|
|
26
|
-
setBlockType,
|
|
27
|
-
type SetBlockTypeOptions,
|
|
28
|
-
} from './commands/set-block-type'
|
|
29
|
-
export {
|
|
30
|
-
setNodeAttrs,
|
|
31
|
-
type SetNodeAttrsOptions,
|
|
32
|
-
} from './commands/set-node-attrs'
|
|
33
|
-
export {
|
|
34
|
-
toggleMark,
|
|
35
|
-
type ToggleMarkOptions,
|
|
36
|
-
} from './commands/toggle-mark'
|
|
37
|
-
export {
|
|
38
|
-
toggleNode,
|
|
39
|
-
type ToggleNodeOptions,
|
|
40
|
-
} from './commands/toggle-node'
|
|
41
|
-
export {
|
|
42
|
-
toggleWrap,
|
|
43
|
-
type ToggleWrapOptions,
|
|
44
|
-
} from './commands/toggle-wrap'
|
|
45
|
-
export {
|
|
46
|
-
unsetBlockType,
|
|
47
|
-
type UnsetBlockTypeOptions,
|
|
48
|
-
} from './commands/unset-block-type'
|
|
49
|
-
export {
|
|
50
|
-
unsetMark,
|
|
51
|
-
type UnsetMarkOptions,
|
|
52
|
-
} from './commands/unset-mark'
|
|
53
|
-
export {
|
|
54
|
-
wrap,
|
|
55
|
-
type WrapOptions,
|
|
56
|
-
} from './commands/wrap'
|
|
57
|
-
export type {
|
|
58
|
-
MarkAction,
|
|
59
|
-
MarkBuilder,
|
|
60
|
-
NodeAction,
|
|
61
|
-
NodeBuilder,
|
|
62
|
-
NodeChild,
|
|
63
|
-
} from './editor/action'
|
|
64
|
-
export {
|
|
65
|
-
createEditor,
|
|
66
|
-
Editor,
|
|
67
|
-
type EditorOptions,
|
|
68
|
-
} from './editor/editor'
|
|
1
|
+
export { addMark, type AddMarkOptions } from './commands/add-mark'
|
|
2
|
+
export { expandMark, type ExpandMarkOptions } from './commands/expand-mark'
|
|
3
|
+
export { insertDefaultBlock, type InsertDefaultBlockOptions } from './commands/insert-default-block'
|
|
4
|
+
export { insertNode, type InsertNodeOptions } from './commands/insert-node'
|
|
5
|
+
export { removeMark, type RemoveMarkOptions } from './commands/remove-mark'
|
|
6
|
+
export { removeNode, type RemoveNodeOptions } from './commands/remove-node'
|
|
7
|
+
export { selectAll } from './commands/select-all'
|
|
8
|
+
export { selectBlock } from './commands/select-block'
|
|
9
|
+
export { setBlockType, type SetBlockTypeOptions } from './commands/set-block-type'
|
|
10
|
+
export { setNodeAttrs, type SetNodeAttrsOptions } from './commands/set-node-attrs'
|
|
11
|
+
export { setNodeAttrsBetween, type SetNodeAttrsBetweenOptions } from './commands/set-node-attrs-between'
|
|
12
|
+
export { toggleMark, type ToggleMarkOptions } from './commands/toggle-mark'
|
|
13
|
+
export { toggleNode, type ToggleNodeOptions } from './commands/toggle-node'
|
|
14
|
+
export { toggleWrap, type ToggleWrapOptions } from './commands/toggle-wrap'
|
|
15
|
+
export { unsetBlockType, type UnsetBlockTypeOptions } from './commands/unset-block-type'
|
|
16
|
+
export { unsetMark, type UnsetMarkOptions } from './commands/unset-mark'
|
|
17
|
+
export { wrap, type WrapOptions } from './commands/wrap'
|
|
18
|
+
export type { MarkAction, NodeAction, NodeChild } from './editor/action'
|
|
19
|
+
export { createEditor, Editor, type EditorOptions } from './editor/editor'
|
|
69
20
|
export { union } from './editor/union'
|
|
70
21
|
export { withPriority } from './editor/with-priority'
|
|
71
|
-
export {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
} from './
|
|
75
|
-
export {
|
|
76
|
-
|
|
77
|
-
type ClipboardSerializerOptions,
|
|
78
|
-
} from './extensions/clipboard-serializer'
|
|
79
|
-
export {
|
|
80
|
-
defineBaseCommands,
|
|
81
|
-
defineCommands,
|
|
82
|
-
type BaseCommandsExtension,
|
|
83
|
-
} from './extensions/command'
|
|
84
|
-
export {
|
|
85
|
-
defineDefaultState,
|
|
86
|
-
type DefaultStateOptions,
|
|
87
|
-
} from './extensions/default-state'
|
|
88
|
-
export {
|
|
89
|
-
defineDoc,
|
|
90
|
-
type DocExtension,
|
|
91
|
-
} from './extensions/doc'
|
|
92
|
-
export {
|
|
93
|
-
defineDocChangeHandler,
|
|
94
|
-
type DocChangeHandler,
|
|
95
|
-
} from './extensions/events/doc-change'
|
|
96
|
-
export {
|
|
97
|
-
defineDOMEventHandler,
|
|
98
|
-
type DOMEventHandler,
|
|
99
|
-
} from './extensions/events/dom-event'
|
|
22
|
+
export { EditorNotFoundError, ProseKitError } from './error'
|
|
23
|
+
export { defineClipboardSerializer, type ClipboardSerializerOptions } from './extensions/clipboard-serializer'
|
|
24
|
+
export { defineBaseCommands, defineCommands, type BaseCommandsExtension } from './extensions/command'
|
|
25
|
+
export { defineDefaultState, type DefaultStateOptions } from './extensions/default-state'
|
|
26
|
+
export { defineDocChangeHandler, type DocChangeHandler } from './extensions/events/doc-change'
|
|
27
|
+
export { defineDOMEventHandler, type DOMEventHandler } from './extensions/events/dom-event'
|
|
100
28
|
export {
|
|
101
29
|
defineClickHandler,
|
|
102
30
|
defineClickOnHandler,
|
|
@@ -125,10 +53,7 @@ export {
|
|
|
125
53
|
type TripleClickHandler,
|
|
126
54
|
type TripleClickOnHandler,
|
|
127
55
|
} from './extensions/events/editor-event'
|
|
128
|
-
export {
|
|
129
|
-
defineFocusChangeHandler,
|
|
130
|
-
type FocusChangeHandler,
|
|
131
|
-
} from './extensions/events/focus'
|
|
56
|
+
export { defineFocusChangeHandler, type FocusChangeHandler } from './extensions/events/focus'
|
|
132
57
|
export {
|
|
133
58
|
defineMountHandler,
|
|
134
59
|
defineUnmountHandler,
|
|
@@ -137,82 +62,34 @@ export {
|
|
|
137
62
|
type UnmountHandler,
|
|
138
63
|
type UpdateHandler,
|
|
139
64
|
} from './extensions/events/plugin-view'
|
|
140
|
-
export {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
} from './extensions/
|
|
145
|
-
export {
|
|
146
|
-
defineKeymap,
|
|
147
|
-
keymapFacet,
|
|
148
|
-
type Keymap,
|
|
149
|
-
type KeymapPayload,
|
|
150
|
-
} from './extensions/keymap'
|
|
151
|
-
export {
|
|
152
|
-
defineBaseKeymap,
|
|
153
|
-
type BaseKeymapExtension,
|
|
154
|
-
} from './extensions/keymap-base'
|
|
155
|
-
export {
|
|
156
|
-
defineMarkAttr,
|
|
157
|
-
defineMarkSpec,
|
|
158
|
-
type MarkAttrOptions,
|
|
159
|
-
type MarkSpecOptions,
|
|
160
|
-
} from './extensions/mark-spec'
|
|
161
|
-
export {
|
|
162
|
-
defineMarkView,
|
|
163
|
-
type MarkViewOptions,
|
|
164
|
-
} from './extensions/mark-view'
|
|
65
|
+
export { defineHistory, type HistoryExtension, type HistoryOptions } from './extensions/history'
|
|
66
|
+
export { defineKeymap, keymapFacet, type Keymap, type KeymapPayload } from './extensions/keymap'
|
|
67
|
+
export { defineBaseKeymap, type BaseKeymapExtension, type BaseKeymapOptions } from './extensions/keymap-base'
|
|
68
|
+
export { defineMarkAttr, defineMarkSpec, type MarkAttrOptions, type MarkSpecOptions } from './extensions/mark-spec'
|
|
69
|
+
export { defineMarkView, type MarkViewOptions } from './extensions/mark-view'
|
|
165
70
|
export {
|
|
166
71
|
defineMarkViewComponent,
|
|
167
72
|
defineMarkViewFactory,
|
|
168
73
|
type MarkViewComponentOptions,
|
|
169
74
|
type MarkViewFactoryOptions,
|
|
170
75
|
} from './extensions/mark-view-effect'
|
|
171
|
-
export {
|
|
172
|
-
|
|
173
|
-
defineNodeSpec,
|
|
174
|
-
type NodeAttrOptions,
|
|
175
|
-
type NodeSpecOptions,
|
|
176
|
-
} from './extensions/node-spec'
|
|
177
|
-
export {
|
|
178
|
-
defineNodeView,
|
|
179
|
-
type NodeViewOptions,
|
|
180
|
-
} from './extensions/node-view'
|
|
76
|
+
export { defineNodeAttr, defineNodeSpec, type NodeAttrOptions, type NodeSpecOptions } from './extensions/node-spec'
|
|
77
|
+
export { defineNodeView, type NodeViewOptions } from './extensions/node-view'
|
|
181
78
|
export {
|
|
182
79
|
defineNodeViewComponent,
|
|
183
80
|
defineNodeViewFactory,
|
|
184
81
|
type NodeViewComponentOptions,
|
|
185
82
|
type NodeViewFactoryOptions,
|
|
186
83
|
} from './extensions/node-view-effect'
|
|
187
|
-
export {
|
|
188
|
-
|
|
189
|
-
type ParagraphExtension,
|
|
190
|
-
} from './extensions/paragraph'
|
|
191
|
-
export {
|
|
192
|
-
definePlugin,
|
|
193
|
-
pluginFacet,
|
|
194
|
-
type PluginPayload,
|
|
195
|
-
} from './extensions/plugin'
|
|
196
|
-
export {
|
|
197
|
-
defineText,
|
|
198
|
-
type TextExtension,
|
|
199
|
-
} from './extensions/text'
|
|
200
|
-
export {
|
|
201
|
-
defineFacet,
|
|
202
|
-
type Facet,
|
|
203
|
-
} from './facets/facet'
|
|
84
|
+
export { definePlugin, pluginFacet, type PluginPayload } from './extensions/plugin'
|
|
85
|
+
export { defineFacet, type Facet } from './facets/facet'
|
|
204
86
|
export { defineFacetPayload } from './facets/facet-extension'
|
|
205
87
|
export type { AnyFunction } from './types/any-function'
|
|
206
|
-
export type {
|
|
207
|
-
AnyAttrs,
|
|
208
|
-
AttrSpec,
|
|
209
|
-
} from './types/attrs'
|
|
210
|
-
export type { BaseNodeViewOptions } from './types/base-node-view-options'
|
|
88
|
+
export type { AnyAttrs, AttrSpec } from './types/attrs'
|
|
211
89
|
export type {
|
|
212
90
|
Extension,
|
|
213
91
|
ExtensionTyping,
|
|
214
92
|
ExtractCommandActions,
|
|
215
|
-
ExtractCommandAppliers,
|
|
216
93
|
ExtractCommandCreators,
|
|
217
94
|
ExtractCommands,
|
|
218
95
|
ExtractMarkActions,
|
|
@@ -222,26 +99,11 @@ export type {
|
|
|
222
99
|
ExtractTyping,
|
|
223
100
|
PlainExtension,
|
|
224
101
|
Union,
|
|
225
|
-
UnionExtension,
|
|
226
102
|
} from './types/extension'
|
|
227
|
-
export type {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
} from './types/
|
|
231
|
-
export type {
|
|
232
|
-
MarkTyping,
|
|
233
|
-
ToMarkAction,
|
|
234
|
-
} from './types/extension-mark'
|
|
235
|
-
export type {
|
|
236
|
-
NodeTyping,
|
|
237
|
-
ToNodeAction,
|
|
238
|
-
} from './types/extension-node'
|
|
239
|
-
export type {
|
|
240
|
-
NodeJSON,
|
|
241
|
-
SelectionJSON,
|
|
242
|
-
StateJSON,
|
|
243
|
-
StepJSON,
|
|
244
|
-
} from './types/model'
|
|
103
|
+
export type { CommandAction, CommandTyping } from './types/extension-command'
|
|
104
|
+
export type { MarkTyping, ToMarkAction } from './types/extension-mark'
|
|
105
|
+
export type { NodeTyping, ToNodeAction } from './types/extension-node'
|
|
106
|
+
export type { NodeJSON, SelectionJSON, StateJSON, StepJSON } from './types/model'
|
|
245
107
|
export type { PickSubType } from './types/pick-sub-type'
|
|
246
108
|
export { Priority } from './types/priority'
|
|
247
109
|
export type { SimplifyDeeper } from './types/simplify-deeper'
|
|
@@ -249,20 +111,12 @@ export type { SimplifyUnion } from './types/simplify-union'
|
|
|
249
111
|
export { assert } from './utils/assert'
|
|
250
112
|
export { canUseRegexLookbehind } from './utils/can-use-regex-lookbehind'
|
|
251
113
|
export { clsx } from './utils/clsx'
|
|
252
|
-
export { collectChildren } from './utils/collect-children'
|
|
253
|
-
export {
|
|
254
|
-
collectNodes,
|
|
255
|
-
type NodeContent,
|
|
256
|
-
} from './utils/collect-nodes'
|
|
257
114
|
export { containsInlineNode } from './utils/contains-inline-node'
|
|
258
115
|
export { defaultBlockAt } from './utils/default-block-at'
|
|
259
116
|
export { isApple } from './utils/env'
|
|
260
|
-
export {
|
|
261
|
-
|
|
262
|
-
type FindParentNodeResult,
|
|
263
|
-
} from './utils/find-parent-node'
|
|
117
|
+
export { findNode, findNodes, type FindNodeResult } from './utils/find-node'
|
|
118
|
+
export { findParentNode, type FindParentNodeResult } from './utils/find-parent-node'
|
|
264
119
|
export { findParentNodeOfType } from './utils/find-parent-node-of-type'
|
|
265
|
-
export { getId as _getId } from './utils/get-id'
|
|
266
120
|
export { getMarkType } from './utils/get-mark-type'
|
|
267
121
|
export { getNodeType } from './utils/get-node-type'
|
|
268
122
|
export { isAtBlockStart } from './utils/is-at-block-start'
|
package/src/test/index.ts
CHANGED
package/src/test/test-builder.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import type { ProseMirrorNode } from '@prosekit/pm/model'
|
|
2
2
|
|
|
3
|
-
import type {
|
|
4
|
-
ApplyMarkFunction,
|
|
5
|
-
CreateNodeFunction,
|
|
6
|
-
} from '../editor/action'
|
|
3
|
+
import type { ApplyMarkFunction, CreateNodeFunction } from '../editor/action'
|
|
7
4
|
import { assert } from '../utils/assert'
|
|
8
5
|
|
|
9
6
|
type Tags = Record<string, number>
|
package/src/test/test-editor.ts
CHANGED
|
@@ -1,32 +1,13 @@
|
|
|
1
1
|
import type { ProseMirrorNode } from '@prosekit/pm/model'
|
|
2
|
-
import {
|
|
3
|
-
NodeSelection,
|
|
4
|
-
TextSelection,
|
|
5
|
-
type Selection,
|
|
6
|
-
} from '@prosekit/pm/state'
|
|
2
|
+
import { NodeSelection, TextSelection, type Selection } from '@prosekit/pm/state'
|
|
7
3
|
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
createNodeActions,
|
|
11
|
-
} from '../editor/action'
|
|
12
|
-
import {
|
|
13
|
-
Editor,
|
|
14
|
-
EditorInstance,
|
|
15
|
-
setupEditorExtension,
|
|
16
|
-
type EditorOptions,
|
|
17
|
-
} from '../editor/editor'
|
|
4
|
+
import { createMarkActions, createNodeActions } from '../editor/action'
|
|
5
|
+
import { Editor, EditorInstance, setupEditorExtension, type EditorOptions } from '../editor/editor'
|
|
18
6
|
import type { Extension } from '../types/extension'
|
|
19
|
-
import type {
|
|
20
|
-
NodeJSON,
|
|
21
|
-
SelectionJSON,
|
|
22
|
-
} from '../types/model'
|
|
7
|
+
import type { NodeJSON, SelectionJSON } from '../types/model'
|
|
23
8
|
import { isProseMirrorNode } from '../utils/type-assertion'
|
|
24
9
|
|
|
25
|
-
import {
|
|
26
|
-
applyMarkForTest,
|
|
27
|
-
createNodeForTest,
|
|
28
|
-
type TaggedProseMirrorNode,
|
|
29
|
-
} from './test-builder'
|
|
10
|
+
import { applyMarkForTest, createNodeForTest, type TaggedProseMirrorNode } from './test-builder'
|
|
30
11
|
|
|
31
12
|
function maybeResolve(doc: ProseMirrorNode, pos?: number) {
|
|
32
13
|
if (pos != null) {
|
package/src/testing/index.ts
CHANGED
|
@@ -9,15 +9,8 @@ import { defineHistory } from '../extensions/history'
|
|
|
9
9
|
import { defineBaseKeymap } from '../extensions/keymap-base'
|
|
10
10
|
import { defineMarkSpec } from '../extensions/mark-spec'
|
|
11
11
|
import { defineNodeSpec } from '../extensions/node-spec'
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
type TestEditor,
|
|
15
|
-
} from '../test'
|
|
16
|
-
import type {
|
|
17
|
-
Extension,
|
|
18
|
-
ExtractMarkActions,
|
|
19
|
-
ExtractNodeActions,
|
|
20
|
-
} from '../types/extension'
|
|
12
|
+
import { createTestEditor, type TestEditor } from '../test'
|
|
13
|
+
import type { Extension, ExtractMarkActions, ExtractNodeActions } from '../types/extension'
|
|
21
14
|
import { Priority } from '../types/priority'
|
|
22
15
|
|
|
23
16
|
type DocExtension = Extension<{ Nodes: { doc: Attrs } }>
|
|
@@ -182,7 +175,7 @@ function defineHeading(): HeadingExtension {
|
|
|
182
175
|
|
|
183
176
|
type CodeBlockExtension = Extension<{
|
|
184
177
|
Nodes: {
|
|
185
|
-
codeBlock: { language: string }
|
|
178
|
+
codeBlock: { language: string; lineNumbers?: boolean }
|
|
186
179
|
}
|
|
187
180
|
}>
|
|
188
181
|
|
|
@@ -197,16 +190,23 @@ function defineCodeBlock(): CodeBlockExtension {
|
|
|
197
190
|
code: true,
|
|
198
191
|
defining: true,
|
|
199
192
|
marks: '',
|
|
200
|
-
attrs: {
|
|
193
|
+
attrs: {
|
|
194
|
+
language: { default: '', validate: 'string' },
|
|
195
|
+
lineNumbers: { default: false, validate: 'boolean' },
|
|
196
|
+
},
|
|
201
197
|
toDOM() {
|
|
202
198
|
return ['pre', ['code', 0]]
|
|
203
199
|
},
|
|
204
200
|
})
|
|
205
201
|
}
|
|
206
202
|
|
|
203
|
+
interface BlockquoteAttrs {
|
|
204
|
+
variant: string
|
|
205
|
+
}
|
|
206
|
+
|
|
207
207
|
type BlockquoteExtension = Extension<{
|
|
208
208
|
Nodes: {
|
|
209
|
-
blockquote:
|
|
209
|
+
blockquote: BlockquoteAttrs
|
|
210
210
|
}
|
|
211
211
|
}>
|
|
212
212
|
|
|
@@ -219,9 +219,13 @@ function defineBlockquote(): BlockquoteExtension {
|
|
|
219
219
|
content: 'block+',
|
|
220
220
|
group: 'block',
|
|
221
221
|
defining: true,
|
|
222
|
+
attrs: {
|
|
223
|
+
variant: { default: '', validate: 'string' },
|
|
224
|
+
},
|
|
222
225
|
parseDOM: [{ tag: 'blockquote' }],
|
|
223
|
-
toDOM() {
|
|
224
|
-
|
|
226
|
+
toDOM(node) {
|
|
227
|
+
const { variant } = node.attrs as BlockquoteAttrs
|
|
228
|
+
return ['blockquote', { 'data-variant': variant }, 0]
|
|
225
229
|
},
|
|
226
230
|
})
|
|
227
231
|
}
|
|
@@ -19,13 +19,6 @@ export interface CommandAction<Args extends any[] = any[]> {
|
|
|
19
19
|
* can be executed, otherwise `false`.
|
|
20
20
|
*/
|
|
21
21
|
canExec(...args: Args): boolean
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* An alias for `canExec`.
|
|
25
|
-
*
|
|
26
|
-
* @deprecated Use `canExec` instead.
|
|
27
|
-
*/
|
|
28
|
-
canApply(...args: Args): boolean
|
|
29
22
|
}
|
|
30
23
|
|
|
31
24
|
export type CommandCreator<Args extends any[] = any[]> = (
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { test } from 'vitest'
|
|
2
2
|
|
|
3
3
|
import { assertTypeEqual } from './assert-type-equal'
|
|
4
|
-
import type {
|
|
5
|
-
Extension,
|
|
6
|
-
Union,
|
|
7
|
-
} from './extension'
|
|
4
|
+
import type { Extension, Union } from './extension'
|
|
8
5
|
|
|
9
6
|
test('ExtractTyping', () => {
|
|
10
7
|
type E1 = Extension<{
|
package/src/types/extension.ts
CHANGED
|
@@ -1,18 +1,8 @@
|
|
|
1
1
|
import type { Schema } from '@prosekit/pm/model'
|
|
2
2
|
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
ToCommandCreators,
|
|
7
|
-
} from './extension-command'
|
|
8
|
-
import type {
|
|
9
|
-
MarkTyping,
|
|
10
|
-
ToMarkAction,
|
|
11
|
-
} from './extension-mark'
|
|
12
|
-
import type {
|
|
13
|
-
NodeTyping,
|
|
14
|
-
ToNodeAction,
|
|
15
|
-
} from './extension-node'
|
|
3
|
+
import type { CommandTyping, ToCommandAction, ToCommandCreators } from './extension-command'
|
|
4
|
+
import type { MarkTyping, ToMarkAction } from './extension-mark'
|
|
5
|
+
import type { NodeTyping, ToNodeAction } from './extension-node'
|
|
16
6
|
import type { PickStringLiteral } from './pick-string-literal'
|
|
17
7
|
import type { PickSubType } from './pick-sub-type'
|
|
18
8
|
import type { Priority } from './priority'
|
|
@@ -142,11 +132,6 @@ export type ExtractMarkActions<E extends Extension> = ToMarkAction<
|
|
|
142
132
|
ExtractMarks<E>
|
|
143
133
|
>
|
|
144
134
|
|
|
145
|
-
/**
|
|
146
|
-
* @deprecated Use `ExtractCommandActions` instead.
|
|
147
|
-
*/
|
|
148
|
-
export type ExtractCommandAppliers<E extends Extension> = ExtractCommandActions<E>
|
|
149
|
-
|
|
150
135
|
/**
|
|
151
136
|
* @internal
|
|
152
137
|
*/
|
|
@@ -155,14 +140,3 @@ export type Union<E extends readonly Extension[]> = Extension<{
|
|
|
155
140
|
Marks: ExtractMarks<E[number]>
|
|
156
141
|
Commands: ExtractCommands<E[number]>
|
|
157
142
|
}>
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* @deprecated Use `Union` instead.
|
|
161
|
-
* @internal
|
|
162
|
-
*/
|
|
163
|
-
export type UnionExtension<E extends Extension | readonly Extension[]> = E extends readonly Extension[] ? Extension<{
|
|
164
|
-
Nodes: ExtractNodes<E[number]>
|
|
165
|
-
Marks: ExtractMarks<E[number]>
|
|
166
|
-
Commands: ExtractCommands<E[number]>
|
|
167
|
-
}>
|
|
168
|
-
: E
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
expect,
|
|
3
|
-
test,
|
|
4
|
-
} from 'vitest'
|
|
1
|
+
import { expect, test } from 'vitest'
|
|
5
2
|
|
|
6
|
-
import {
|
|
7
|
-
groupBy,
|
|
8
|
-
groupEntries,
|
|
9
|
-
} from './array-grouping'
|
|
3
|
+
import { groupEntries } from './array-grouping'
|
|
10
4
|
|
|
11
5
|
test('groupEntries', () => {
|
|
12
6
|
expect(
|
|
@@ -20,10 +14,3 @@ test('groupEntries', () => {
|
|
|
20
14
|
b: [2],
|
|
21
15
|
})
|
|
22
16
|
})
|
|
23
|
-
|
|
24
|
-
test('groupBy', () => {
|
|
25
|
-
expect(groupBy([1, 2, 3, 4, 5], (n) => n % 2)).toEqual({
|
|
26
|
-
0: [2, 4],
|
|
27
|
-
1: [1, 3, 5],
|
|
28
|
-
})
|
|
29
|
-
})
|
|
@@ -1,17 +1,4 @@
|
|
|
1
|
-
import type { ObjectEntries } from '
|
|
2
|
-
|
|
3
|
-
export function groupBy<K extends PropertyKey, T>(
|
|
4
|
-
items: Iterable<T>,
|
|
5
|
-
keySelector: (item: T) => K,
|
|
6
|
-
): Partial<Record<K, T[]>> {
|
|
7
|
-
const result: Partial<Record<K, T[]>> = {}
|
|
8
|
-
for (const item of items) {
|
|
9
|
-
const key = keySelector(item)
|
|
10
|
-
const values = (result[key] ||= [])
|
|
11
|
-
values.push(item)
|
|
12
|
-
}
|
|
13
|
-
return result
|
|
14
|
-
}
|
|
1
|
+
import type { ObjectEntries } from '@ocavue/utils'
|
|
15
2
|
|
|
16
3
|
export function groupEntries<T extends Record<string, any>>(
|
|
17
4
|
entries: ObjectEntries<T>[],
|
package/src/utils/array.ts
CHANGED
|
@@ -15,7 +15,3 @@ export function uniqPush<T>(prev: readonly T[], next: readonly T[]): T[] {
|
|
|
15
15
|
export function arraySubtract<T>(a: T[], b: T[]): T[] {
|
|
16
16
|
return a.filter((x) => !b.includes(x))
|
|
17
17
|
}
|
|
18
|
-
|
|
19
|
-
export function toReversed<T>(arr: T[]): T[] {
|
|
20
|
-
return arr.toReversed?.() ?? [...arr].reverse()
|
|
21
|
-
}
|
package/src/utils/attrs-match.ts
CHANGED
package/src/utils/clsx.spec.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { toReversed } from './array'
|
|
2
|
-
|
|
3
1
|
export function combineEventHandlers<
|
|
4
2
|
Handler extends (...args: any[]) => boolean | void,
|
|
5
3
|
Args extends Parameters<Handler> = Parameters<Handler>,
|
|
@@ -10,13 +8,13 @@ export function combineEventHandlers<
|
|
|
10
8
|
let handlers: Handler[] = []
|
|
11
9
|
|
|
12
10
|
function setHandlers(eventHandlers: Handler[]): void {
|
|
13
|
-
|
|
14
|
-
handlers = toReversed(eventHandlers)
|
|
11
|
+
handlers = eventHandlers
|
|
15
12
|
}
|
|
16
13
|
|
|
17
14
|
function combinedEventHandler(...args: Args): boolean {
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
// The handlers at the end have a higher priority.
|
|
16
|
+
for (let i = handlers.length - 1; i >= 0; i--) {
|
|
17
|
+
if (handlers[i](...args)) {
|
|
20
18
|
return true
|
|
21
19
|
}
|
|
22
20
|
}
|