@prosekit/core 0.8.3 → 0.8.5
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-KZlceNQ1.d.ts +722 -0
- package/dist/editor-KZlceNQ1.d.ts.map +1 -0
- package/dist/{editor-DlGlYOp-.js → editor-TvRTsFdO.js} +102 -196
- package/dist/editor-TvRTsFdO.js.map +1 -0
- package/dist/prosekit-core-test.d.ts +20 -19
- package/dist/prosekit-core-test.d.ts.map +1 -0
- package/dist/prosekit-core-test.js +5 -8
- package/dist/prosekit-core-test.js.map +1 -0
- package/dist/prosekit-core.d.ts +797 -792
- package/dist/prosekit-core.d.ts.map +1 -0
- package/dist/prosekit-core.js +42 -79
- package/dist/prosekit-core.js.map +1 -0
- package/package.json +14 -12
- package/src/commands/add-mark.ts +53 -0
- package/src/commands/expand-mark.ts +96 -0
- package/src/commands/insert-default-block.spec.ts +102 -0
- package/src/commands/insert-default-block.ts +49 -0
- package/src/commands/insert-node.ts +71 -0
- package/src/commands/insert-text.ts +24 -0
- package/src/commands/remove-mark.ts +54 -0
- package/src/commands/remove-node.ts +43 -0
- package/src/commands/select-all.ts +16 -0
- package/src/commands/set-block-type.ts +64 -0
- package/src/commands/set-node-attrs.ts +68 -0
- package/src/commands/toggle-mark.ts +65 -0
- package/src/commands/toggle-node.ts +47 -0
- package/src/commands/toggle-wrap.spec.ts +35 -0
- package/src/commands/toggle-wrap.ts +42 -0
- package/src/commands/unset-block-type.spec.ts +49 -0
- package/src/commands/unset-block-type.ts +84 -0
- package/src/commands/unset-mark.spec.ts +35 -0
- package/src/commands/unset-mark.ts +38 -0
- package/src/commands/wrap.ts +50 -0
- package/src/editor/action.spec.ts +143 -0
- package/src/editor/action.ts +248 -0
- package/src/editor/editor.spec.ts +186 -0
- package/src/editor/editor.ts +563 -0
- package/src/editor/union.spec.ts +108 -0
- package/src/editor/union.ts +47 -0
- package/src/editor/with-priority.ts +25 -0
- package/src/error.ts +28 -0
- package/src/extensions/clipboard-serializer.ts +107 -0
- package/src/extensions/command.ts +121 -0
- package/src/extensions/default-state.spec.ts +60 -0
- package/src/extensions/default-state.ts +76 -0
- package/src/extensions/doc.ts +31 -0
- package/src/extensions/events/doc-change.ts +34 -0
- package/src/extensions/events/dom-event.spec.ts +70 -0
- package/src/extensions/events/dom-event.ts +117 -0
- package/src/extensions/events/editor-event.ts +293 -0
- package/src/extensions/events/focus.spec.ts +50 -0
- package/src/extensions/events/focus.ts +28 -0
- package/src/extensions/events/plugin-view.ts +132 -0
- package/src/extensions/history.ts +81 -0
- package/src/extensions/keymap-base.ts +60 -0
- package/src/extensions/keymap.spec.ts +125 -0
- package/src/extensions/keymap.ts +96 -0
- package/src/extensions/mark-spec.spec.ts +177 -0
- package/src/extensions/mark-spec.ts +181 -0
- package/src/extensions/mark-view-effect.ts +85 -0
- package/src/extensions/mark-view.ts +43 -0
- package/src/extensions/node-spec.spec.ts +224 -0
- package/src/extensions/node-spec.ts +199 -0
- package/src/extensions/node-view-effect.ts +85 -0
- package/src/extensions/node-view.ts +43 -0
- package/src/extensions/paragraph.ts +61 -0
- package/src/extensions/plugin.spec.ts +153 -0
- package/src/extensions/plugin.ts +81 -0
- package/src/extensions/text.ts +34 -0
- package/src/facets/base-extension.ts +54 -0
- package/src/facets/command.ts +21 -0
- package/src/facets/facet-extension.spec.ts +173 -0
- package/src/facets/facet-extension.ts +53 -0
- package/src/facets/facet-node.spec.ts +265 -0
- package/src/facets/facet-node.ts +185 -0
- package/src/facets/facet-types.ts +9 -0
- package/src/facets/facet.spec.ts +76 -0
- package/src/facets/facet.ts +84 -0
- package/src/facets/root.ts +44 -0
- package/src/facets/schema-spec.ts +30 -0
- package/src/facets/schema.ts +26 -0
- package/src/facets/state.spec.ts +53 -0
- package/src/facets/state.ts +85 -0
- package/src/facets/union-extension.ts +41 -0
- package/src/index.ts +302 -0
- package/src/test/index.ts +4 -0
- package/src/test/test-builder.ts +68 -0
- package/src/test/test-editor.spec.ts +104 -0
- package/src/test/test-editor.ts +113 -0
- package/src/testing/index.ts +283 -0
- package/src/testing/keyboard.ts +5 -0
- package/src/types/any-function.ts +4 -0
- package/src/types/assert-type-equal.ts +8 -0
- package/src/types/attrs.ts +32 -0
- package/src/types/base-node-view-options.ts +33 -0
- package/src/types/dom-node.ts +1 -0
- package/src/types/extension-command.ts +52 -0
- package/src/types/extension-mark.ts +15 -0
- package/src/types/extension-node.ts +15 -0
- package/src/types/extension.spec.ts +56 -0
- package/src/types/extension.ts +168 -0
- package/src/types/model.ts +54 -0
- package/src/types/object-entries.ts +13 -0
- package/src/types/pick-string-literal.spec.ts +10 -0
- package/src/types/pick-string-literal.ts +6 -0
- package/src/types/pick-sub-type.spec.ts +20 -0
- package/src/types/pick-sub-type.ts +6 -0
- package/src/types/priority.ts +12 -0
- package/src/types/setter.ts +4 -0
- package/src/types/simplify-deeper.spec.ts +40 -0
- package/src/types/simplify-deeper.ts +6 -0
- package/src/types/simplify-union.spec.ts +21 -0
- package/src/types/simplify-union.ts +11 -0
- package/src/utils/array-grouping.spec.ts +29 -0
- package/src/utils/array-grouping.ts +25 -0
- package/src/utils/array.ts +21 -0
- package/src/utils/assert.ts +13 -0
- package/src/utils/attrs-match.ts +20 -0
- package/src/utils/can-use-regex-lookbehind.ts +12 -0
- package/src/utils/clsx.spec.ts +14 -0
- package/src/utils/clsx.ts +14 -0
- package/src/utils/collect-children.ts +21 -0
- package/src/utils/collect-nodes.ts +37 -0
- package/src/utils/combine-event-handlers.spec.ts +27 -0
- package/src/utils/combine-event-handlers.ts +27 -0
- package/src/utils/contains-inline-node.ts +17 -0
- package/src/utils/deep-equals.spec.ts +26 -0
- package/src/utils/deep-equals.ts +29 -0
- package/src/utils/default-block-at.ts +15 -0
- package/src/utils/editor-content.spec.ts +47 -0
- package/src/utils/editor-content.ts +77 -0
- package/src/utils/env.ts +6 -0
- package/src/utils/find-parent-node-of-type.ts +29 -0
- package/src/utils/find-parent-node.spec.ts +68 -0
- package/src/utils/find-parent-node.ts +55 -0
- package/src/utils/get-custom-selection.ts +19 -0
- package/src/utils/get-dom-api.ts +56 -0
- package/src/utils/get-id.spec.ts +14 -0
- package/src/utils/get-id.ts +13 -0
- package/src/utils/get-mark-type.ts +20 -0
- package/src/utils/get-node-type.ts +20 -0
- package/src/utils/get-node-types.ts +19 -0
- package/src/utils/includes-mark.ts +18 -0
- package/src/utils/is-at-block-start.ts +26 -0
- package/src/utils/is-in-code-block.ts +18 -0
- package/src/utils/is-mark-absent.spec.ts +53 -0
- package/src/utils/is-mark-absent.ts +42 -0
- package/src/utils/is-mark-active.ts +27 -0
- package/src/utils/is-node-active.ts +25 -0
- package/src/utils/is-subset.spec.ts +12 -0
- package/src/utils/is-subset.ts +11 -0
- package/src/utils/maybe-run.spec.ts +39 -0
- package/src/utils/maybe-run.ts +11 -0
- package/src/utils/merge-objects.spec.ts +30 -0
- package/src/utils/merge-objects.ts +11 -0
- package/src/utils/merge-specs.ts +35 -0
- package/src/utils/object-equal.spec.ts +26 -0
- package/src/utils/object-equal.ts +28 -0
- package/src/utils/output-spec.test.ts +95 -0
- package/src/utils/output-spec.ts +130 -0
- package/src/utils/parse.spec.ts +46 -0
- package/src/utils/parse.ts +321 -0
- package/src/utils/remove-undefined-values.spec.ts +15 -0
- package/src/utils/remove-undefined-values.ts +9 -0
- package/src/utils/set-selection-around.ts +11 -0
- package/src/utils/type-assertion.ts +91 -0
- package/src/utils/unicode.spec.ts +10 -0
- package/src/utils/unicode.ts +4 -0
- package/src/utils/with-skip-code-block.ts +15 -0
- package/dist/editor-OUH5V8BA.d.ts +0 -754
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import {
|
|
2
|
+
describe,
|
|
3
|
+
expect,
|
|
4
|
+
it,
|
|
5
|
+
} from 'vitest'
|
|
6
|
+
|
|
7
|
+
import { insertText } from '../commands/insert-text'
|
|
8
|
+
import { wrap } from '../commands/wrap'
|
|
9
|
+
import {
|
|
10
|
+
defineTestExtension,
|
|
11
|
+
setupTest,
|
|
12
|
+
} from '../testing'
|
|
13
|
+
import type { NodeJSON } from '../types/model'
|
|
14
|
+
|
|
15
|
+
import { createEditor } from './editor'
|
|
16
|
+
|
|
17
|
+
describe('createEditor', () => {
|
|
18
|
+
it('can mount the editor', () => {
|
|
19
|
+
const div = document.body.appendChild(document.createElement('div'))
|
|
20
|
+
const extension = defineTestExtension()
|
|
21
|
+
const editor = createEditor({ extension })
|
|
22
|
+
editor.mount(div)
|
|
23
|
+
expect(div.outerHTML).toMatchInlineSnapshot(
|
|
24
|
+
`"<div contenteditable="true" translate="no" class="ProseMirror"><p><br class="ProseMirror-trailingBreak"></p></div>"`,
|
|
25
|
+
)
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('can get and update state', () => {
|
|
29
|
+
const extension = defineTestExtension()
|
|
30
|
+
const editor = createEditor({ extension })
|
|
31
|
+
|
|
32
|
+
const update = (text: string) => {
|
|
33
|
+
const s1 = editor.state
|
|
34
|
+
const s2 = s1.apply(s1.tr.insertText(text, 1))
|
|
35
|
+
editor.updateState(s2)
|
|
36
|
+
const s3 = editor.state
|
|
37
|
+
|
|
38
|
+
expect(s3).toBe(s2)
|
|
39
|
+
expect(s2).not.toEqual(s1)
|
|
40
|
+
|
|
41
|
+
return s3
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const expectStateEqual = (fn: VoidFunction) => {
|
|
45
|
+
const s1 = editor.state
|
|
46
|
+
fn()
|
|
47
|
+
const s2 = editor.state
|
|
48
|
+
expect(s1).toBe(s2)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const expectStateNotEqual = (fn: VoidFunction) => {
|
|
52
|
+
const s1 = editor.state
|
|
53
|
+
fn()
|
|
54
|
+
const s2 = editor.state
|
|
55
|
+
expect(s1).not.toEqual(s2)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Initial state
|
|
59
|
+
expect(editor.state).toBeDefined()
|
|
60
|
+
expect(editor.state.doc.textContent).toMatchInlineSnapshot(`""`)
|
|
61
|
+
|
|
62
|
+
// Update state before mounting
|
|
63
|
+
expectStateNotEqual(() => update('1'))
|
|
64
|
+
expect(editor.state.doc.textContent).toMatchInlineSnapshot(`"1"`)
|
|
65
|
+
|
|
66
|
+
// Mount editor
|
|
67
|
+
const div = document.body.appendChild(document.createElement('div'))
|
|
68
|
+
expectStateEqual(() => editor.mount(div))
|
|
69
|
+
expect(editor.state.doc.textContent).toMatchInlineSnapshot(`"1"`)
|
|
70
|
+
|
|
71
|
+
// Update state after mounting
|
|
72
|
+
expectStateNotEqual(() => update('2'))
|
|
73
|
+
expect(editor.state.doc.textContent).toMatchInlineSnapshot(`"21"`)
|
|
74
|
+
|
|
75
|
+
// Unmount editor
|
|
76
|
+
expectStateEqual(() => editor.unmount())
|
|
77
|
+
expect(editor.state.doc.textContent).toMatchInlineSnapshot(`"21"`)
|
|
78
|
+
|
|
79
|
+
// Update state after unmounting
|
|
80
|
+
expectStateNotEqual(() => update('3'))
|
|
81
|
+
expect(editor.state.doc.textContent).toMatchInlineSnapshot(`"321"`)
|
|
82
|
+
|
|
83
|
+
// Re-mount editor
|
|
84
|
+
expectStateEqual(() => editor.mount(div))
|
|
85
|
+
expect(editor.state.doc.textContent).toMatchInlineSnapshot(`"321"`)
|
|
86
|
+
|
|
87
|
+
// Update state after re-mounting
|
|
88
|
+
expectStateNotEqual(() => update('4'))
|
|
89
|
+
expect(editor.state.doc.textContent).toMatchInlineSnapshot(`"4321"`)
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
it('can update document and selection', () => {
|
|
93
|
+
const extension = defineTestExtension()
|
|
94
|
+
const editor = createEditor({ extension })
|
|
95
|
+
|
|
96
|
+
expect(editor.state.doc.textContent).toMatchInlineSnapshot(`""`)
|
|
97
|
+
|
|
98
|
+
editor.setContent('foo')
|
|
99
|
+
expect(editor.state.toJSON()).toMatchInlineSnapshot(`
|
|
100
|
+
{
|
|
101
|
+
"doc": {
|
|
102
|
+
"content": [
|
|
103
|
+
{
|
|
104
|
+
"content": [
|
|
105
|
+
{
|
|
106
|
+
"text": "foo",
|
|
107
|
+
"type": "text",
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
"type": "paragraph",
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
"type": "doc",
|
|
114
|
+
},
|
|
115
|
+
"selection": {
|
|
116
|
+
"anchor": 1,
|
|
117
|
+
"head": 1,
|
|
118
|
+
"type": "text",
|
|
119
|
+
},
|
|
120
|
+
}
|
|
121
|
+
`)
|
|
122
|
+
|
|
123
|
+
editor.setContent(
|
|
124
|
+
{
|
|
125
|
+
type: 'doc',
|
|
126
|
+
content: [
|
|
127
|
+
{
|
|
128
|
+
type: 'paragraph',
|
|
129
|
+
content: [{ type: 'text', text: 'bar' }],
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
},
|
|
133
|
+
'end',
|
|
134
|
+
)
|
|
135
|
+
expect(editor.state.toJSON()).toMatchInlineSnapshot(`
|
|
136
|
+
{
|
|
137
|
+
"doc": {
|
|
138
|
+
"content": [
|
|
139
|
+
{
|
|
140
|
+
"content": [
|
|
141
|
+
{
|
|
142
|
+
"text": "bar",
|
|
143
|
+
"type": "text",
|
|
144
|
+
},
|
|
145
|
+
],
|
|
146
|
+
"type": "paragraph",
|
|
147
|
+
},
|
|
148
|
+
],
|
|
149
|
+
"type": "doc",
|
|
150
|
+
},
|
|
151
|
+
"selection": {
|
|
152
|
+
"anchor": 4,
|
|
153
|
+
"head": 4,
|
|
154
|
+
"type": "text",
|
|
155
|
+
},
|
|
156
|
+
}
|
|
157
|
+
`)
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
it('can refuse invalid document', () => {
|
|
161
|
+
const extension = defineTestExtension()
|
|
162
|
+
const editor = createEditor({ extension })
|
|
163
|
+
|
|
164
|
+
const invalidDoc: NodeJSON = {
|
|
165
|
+
type: 'doc',
|
|
166
|
+
content: [{ type: 'text', text: 'bar aaa aa' }],
|
|
167
|
+
}
|
|
168
|
+
expect(() => editor.setContent(invalidDoc)).toThrow()
|
|
169
|
+
})
|
|
170
|
+
|
|
171
|
+
it('can execute commands', () => {
|
|
172
|
+
const { editor } = setupTest()
|
|
173
|
+
|
|
174
|
+
expect(editor.exec(insertText({ text: 'foo' }))).toBe(true)
|
|
175
|
+
expect(editor.state.doc.textContent).toBe('foo')
|
|
176
|
+
|
|
177
|
+
expect(editor.commands.insertText({ text: 'bar' })).toBe(true)
|
|
178
|
+
expect(editor.state.doc.textContent).toBe('foobar')
|
|
179
|
+
|
|
180
|
+
expect(editor.exec(wrap({ type: 'paragraph' }))).toBe(false)
|
|
181
|
+
expect(editor.commands.wrap({ type: 'paragraph' })).toBe(false)
|
|
182
|
+
|
|
183
|
+
expect(editor.canExec(wrap({ type: 'paragraph' }))).toBe(false)
|
|
184
|
+
expect(editor.commands.wrap.canExec({ type: 'paragraph' })).toBe(false)
|
|
185
|
+
})
|
|
186
|
+
})
|