@handlewithcare/react-prosemirror 2.8.0-tiptap.10 → 2.8.0-tiptap.11
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/cjs/tiptap/tiptapNodeView.js +26 -13
- package/dist/esm/tiptap/tiptapNodeView.js +27 -14
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/constants.d.ts +1 -1
- package/dist/types/props.d.ts +26 -26
- package/package.json +1 -1
- package/dist/esm/@jest/pattern/src/__tests__/TestPathPatterns.test.js +0 -241
- package/dist/esm/@swc/cli/lib/swc/__tests__/compile.test.js +0 -19
- package/dist/esm/@swc/cli/lib/swc/__tests__/options.test.js +0 -315
- package/dist/esm/@swc/cli/lib/swc/__tests__/sources.test.js +0 -161
- package/dist/esm/@uiw/react-codemirror/src/__tests__/index.test.js +0 -111
- package/dist/esm/cheerio/src/__tests__/deprecated.spec.js +0 -249
- package/dist/esm/cheerio/src/__tests__/xml.spec.js +0 -55
- package/dist/esm/components/__tests__/ProseMirror.composition.test.js +0 -395
- package/dist/esm/components/__tests__/ProseMirror.domchange.test.js +0 -266
- package/dist/esm/components/__tests__/ProseMirror.draw-decoration.test.js +0 -968
- package/dist/esm/components/__tests__/ProseMirror.draw.test.js +0 -335
- package/dist/esm/components/__tests__/ProseMirror.mobile.test.js +0 -54
- package/dist/esm/components/__tests__/ProseMirror.node-view.test.js +0 -553
- package/dist/esm/components/__tests__/ProseMirror.selection.test.js +0 -440
- package/dist/esm/components/__tests__/ProseMirror.test.js +0 -324
- package/dist/esm/contexts/__tests__/DeferredLayoutEffects.test.js +0 -98
- package/dist/esm/hooks/__tests__/useEditorEffect.test.js +0 -134
- package/dist/esm/jsx-ast-utils/__tests__/helper.js +0 -83
- package/dist/esm/jsx-ast-utils/__tests__/src/elementType-test.js +0 -76
- package/dist/esm/jsx-ast-utils/__tests__/src/eventHandlers-test.js +0 -98
- package/dist/esm/jsx-ast-utils/__tests__/src/getProp-parser-test.js +0 -188
- package/dist/esm/jsx-ast-utils/__tests__/src/getProp-test.js +0 -119
- package/dist/esm/jsx-ast-utils/__tests__/src/getPropLiteralValue-babelparser-test.js +0 -393
- package/dist/esm/jsx-ast-utils/__tests__/src/getPropLiteralValue-flowparser-test.js +0 -379
- package/dist/esm/jsx-ast-utils/__tests__/src/getPropValue-babelparser-test.js +0 -925
- package/dist/esm/jsx-ast-utils/__tests__/src/getPropValue-flowparser-test.js +0 -700
- package/dist/esm/jsx-ast-utils/__tests__/src/hasProp-test.js +0 -350
- package/dist/esm/jsx-ast-utils/__tests__/src/index-test.js +0 -24
- package/dist/esm/jsx-ast-utils/__tests__/src/propName-test.js +0 -37
- package/dist/esm/plugins/__tests__/reactKeys.test.js +0 -77
- package/dist/esm/tsconfig-paths/lib/__tests__/config-loader.test.d.js +0 -1
- package/dist/esm/tsconfig-paths/lib/__tests__/config-loader.test.js +0 -97
- package/dist/esm/tsconfig-paths/lib/__tests__/data/match-path-data.d.js +0 -1
- package/dist/esm/tsconfig-paths/lib/__tests__/data/match-path-data.js +0 -319
- package/dist/esm/tsconfig-paths/lib/__tests__/filesystem.test.d.js +0 -1
- package/dist/esm/tsconfig-paths/lib/__tests__/filesystem.test.js +0 -62
- package/dist/esm/tsconfig-paths/lib/__tests__/mapping-entry.test.d.js +0 -1
- package/dist/esm/tsconfig-paths/lib/__tests__/mapping-entry.test.js +0 -80
- package/dist/esm/tsconfig-paths/lib/__tests__/match-path-async.test.d.js +0 -1
- package/dist/esm/tsconfig-paths/lib/__tests__/match-path-async.test.js +0 -22
- package/dist/esm/tsconfig-paths/lib/__tests__/match-path-sync.test.d.js +0 -1
- package/dist/esm/tsconfig-paths/lib/__tests__/match-path-sync.test.js +0 -20
- package/dist/esm/tsconfig-paths/lib/__tests__/try-path.test.d.js +0 -1
- package/dist/esm/tsconfig-paths/lib/__tests__/try-path.test.js +0 -219
- package/dist/esm/tsconfig-paths/lib/__tests__/tsconfig-loader.test.d.js +0 -1
- package/dist/esm/tsconfig-paths/lib/__tests__/tsconfig-loader.test.js +0 -323
- package/dist/esm/tsconfig-paths/src/__tests__/config-loader.test.js +0 -89
- package/dist/esm/tsconfig-paths/src/__tests__/data/match-path-data.js +0 -314
- package/dist/esm/tsconfig-paths/src/__tests__/filesystem.test.js +0 -58
- package/dist/esm/tsconfig-paths/src/__tests__/mapping-entry.test.js +0 -76
- package/dist/esm/tsconfig-paths/src/__tests__/match-path-async.test.js +0 -12
- package/dist/esm/tsconfig-paths/src/__tests__/match-path-sync.test.js +0 -10
- package/dist/esm/tsconfig-paths/src/__tests__/try-path.test.js +0 -214
- package/dist/esm/tsconfig-paths/src/__tests__/tsconfig-loader.test.js +0 -296
|
@@ -1,395 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-non-null-assertion */ import { doc, em, p, strong } from "prosemirror-test-builder";
|
|
2
|
-
// @ts-expect-error This is an internal export
|
|
3
|
-
import { __endComposition } from "prosemirror-view";
|
|
4
|
-
import { findTextNode, tempEditor } from "../../testing/editorViewTestHelpers.js";
|
|
5
|
-
function endComposition(view, forceUpdate) {
|
|
6
|
-
__endComposition(view, forceUpdate);
|
|
7
|
-
}
|
|
8
|
-
function event(pm, type) {
|
|
9
|
-
pm.dom.dispatchEvent(new CompositionEvent(type));
|
|
10
|
-
}
|
|
11
|
-
function edit(node) {
|
|
12
|
-
let text = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "", from = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : node.nodeValue.length, to = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : from;
|
|
13
|
-
const val = node.nodeValue;
|
|
14
|
-
node.nodeValue = val.slice(0, from) + text + val.slice(to);
|
|
15
|
-
document.getSelection().collapse(node, from + text.length);
|
|
16
|
-
return node;
|
|
17
|
-
}
|
|
18
|
-
function hasCompositionNode(_pm) {
|
|
19
|
-
let { focusNode } = document.getSelection();
|
|
20
|
-
while(focusNode && !focusNode.pmViewDesc)focusNode = focusNode.parentNode;
|
|
21
|
-
return focusNode && focusNode.pmViewDesc.constructor.name == "CompositionViewDesc";
|
|
22
|
-
}
|
|
23
|
-
function compose(pm, start, update) {
|
|
24
|
-
let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
|
|
25
|
-
event(pm, "compositionstart");
|
|
26
|
-
expect(pm.composing).toBeTruthy();
|
|
27
|
-
let node;
|
|
28
|
-
const sel = document.getSelection();
|
|
29
|
-
for(let i = -1; i < update.length; i++){
|
|
30
|
-
if (i < 0) node = start();
|
|
31
|
-
else update[i](node);
|
|
32
|
-
const { focusNode, focusOffset } = sel;
|
|
33
|
-
// @ts-expect-error Internal property
|
|
34
|
-
pm.domObserver.flush();
|
|
35
|
-
if (options.cancel && i == update.length - 1) {
|
|
36
|
-
expect(hasCompositionNode(pm)).toBeFalsy();
|
|
37
|
-
} else {
|
|
38
|
-
expect(node.parentNode && pm.dom.contains(node.parentNode)).toBeTruthy();
|
|
39
|
-
expect(sel.focusNode === focusNode).toBeTruthy();
|
|
40
|
-
expect(sel.focusOffset === focusOffset).toBeTruthy();
|
|
41
|
-
if (options.node) expect(hasCompositionNode(pm)).toBeTruthy();
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
event(pm, "compositionend");
|
|
45
|
-
if (options.end) {
|
|
46
|
-
options.end(node);
|
|
47
|
-
// @ts-expect-error Internal property
|
|
48
|
-
pm.domObserver.flush();
|
|
49
|
-
}
|
|
50
|
-
endComposition(pm);
|
|
51
|
-
expect(pm.composing).toBeFalsy();
|
|
52
|
-
expect(hasCompositionNode(pm)).toBeFalsy();
|
|
53
|
-
}
|
|
54
|
-
// function wordDeco(state: EditorState) {
|
|
55
|
-
// const re = /\w+/g,
|
|
56
|
-
// deco: Decoration[] = [];
|
|
57
|
-
// state.doc.descendants((node, pos) => {
|
|
58
|
-
// if (node.isText)
|
|
59
|
-
// for (let m; (m = re.exec(node.text!)); )
|
|
60
|
-
// deco.push(
|
|
61
|
-
// Decoration.inline(pos + m.index, pos + m.index + m[0].length, {
|
|
62
|
-
// class: "word",
|
|
63
|
-
// })
|
|
64
|
-
// );
|
|
65
|
-
// });
|
|
66
|
-
// return DecorationSet.create(state.doc, deco);
|
|
67
|
-
// }
|
|
68
|
-
// const wordHighlighter = new Plugin({
|
|
69
|
-
// props: { decorations: wordDeco },
|
|
70
|
-
// });
|
|
71
|
-
// const Widget = forwardRef(function Widget(
|
|
72
|
-
// { widget, pos, ...props }: WidgetViewComponentProps,
|
|
73
|
-
// ref: Ref<HTMLElement>
|
|
74
|
-
// ) {
|
|
75
|
-
// return (
|
|
76
|
-
// <var ref={ref} {...props}>
|
|
77
|
-
// ×
|
|
78
|
-
// </var>
|
|
79
|
-
// );
|
|
80
|
-
// });
|
|
81
|
-
// function widgets(positions: number[], sides: number[]) {
|
|
82
|
-
// return new Plugin({
|
|
83
|
-
// state: {
|
|
84
|
-
// init(state) {
|
|
85
|
-
// const deco = positions.map((p, i) =>
|
|
86
|
-
// widget(p, Widget, { side: sides[i] })
|
|
87
|
-
// );
|
|
88
|
-
// return DecorationSet.create(state.doc!, deco);
|
|
89
|
-
// },
|
|
90
|
-
// apply(tr, deco) {
|
|
91
|
-
// return deco.map(tr.mapping, tr.doc);
|
|
92
|
-
// },
|
|
93
|
-
// },
|
|
94
|
-
// props: {
|
|
95
|
-
// decorations(this: Plugin, state) {
|
|
96
|
-
// return this.getState(state);
|
|
97
|
-
// },
|
|
98
|
-
// },
|
|
99
|
-
// });
|
|
100
|
-
// }
|
|
101
|
-
// These unfortunately aren't working at the moment, though
|
|
102
|
-
// composition seems to be working generally.
|
|
103
|
-
describe.skip("EditorView composition", ()=>{
|
|
104
|
-
it("supports composition in an empty block", ()=>{
|
|
105
|
-
const { view: pm } = tempEditor({
|
|
106
|
-
doc: doc(p("<a>"))
|
|
107
|
-
});
|
|
108
|
-
compose(pm, ()=>edit(pm.dom.firstChild.appendChild(document.createTextNode("a"))), [
|
|
109
|
-
(n)=>edit(n, "b"),
|
|
110
|
-
(n)=>edit(n, "c")
|
|
111
|
-
], {
|
|
112
|
-
node: true
|
|
113
|
-
});
|
|
114
|
-
expect(pm.state.doc).toEqualNode(doc(p("abc")));
|
|
115
|
-
});
|
|
116
|
-
it("supports composition at end of block", ()=>{
|
|
117
|
-
const { view: pm } = tempEditor({
|
|
118
|
-
doc: doc(p("foo"))
|
|
119
|
-
});
|
|
120
|
-
compose(pm, ()=>edit(findTextNode(pm.dom, "foo")), [
|
|
121
|
-
(n)=>edit(n, "!"),
|
|
122
|
-
(n)=>edit(n, "?")
|
|
123
|
-
]);
|
|
124
|
-
expect(pm.state.doc).toEqualNode(doc(p("foo!?")));
|
|
125
|
-
});
|
|
126
|
-
it("supports composition at end of block in a new node", ()=>{
|
|
127
|
-
const { view: pm } = tempEditor({
|
|
128
|
-
doc: doc(p("foo"))
|
|
129
|
-
});
|
|
130
|
-
compose(pm, ()=>edit(pm.dom.firstChild.appendChild(document.createTextNode("!"))), [
|
|
131
|
-
(n)=>edit(n, "?")
|
|
132
|
-
], // $$FORK: We don't use composition view descriptors except for in initially empty nodes
|
|
133
|
-
{
|
|
134
|
-
node: false
|
|
135
|
-
});
|
|
136
|
-
expect(pm.state.doc).toEqualNode(doc(p("foo!?")));
|
|
137
|
-
});
|
|
138
|
-
it("supports composition at start of block in a new node", ()=>{
|
|
139
|
-
const { view: pm } = tempEditor({
|
|
140
|
-
doc: doc(p("foo"))
|
|
141
|
-
});
|
|
142
|
-
compose(pm, ()=>{
|
|
143
|
-
const p = pm.dom.firstChild;
|
|
144
|
-
return edit(p.insertBefore(document.createTextNode("!"), p.firstChild));
|
|
145
|
-
}, [
|
|
146
|
-
(n)=>edit(n, "?")
|
|
147
|
-
], // $$FORK: We don't use composition view descriptors except for in initially empty nodes
|
|
148
|
-
{
|
|
149
|
-
node: false
|
|
150
|
-
});
|
|
151
|
-
expect(pm.state.doc).toEqualNode(doc(p("!?foo")));
|
|
152
|
-
});
|
|
153
|
-
it("supports composition inside existing text", ()=>{
|
|
154
|
-
const { view: pm } = tempEditor({
|
|
155
|
-
doc: doc(p("foo"))
|
|
156
|
-
});
|
|
157
|
-
compose(pm, ()=>edit(findTextNode(pm.dom, "foo")), [
|
|
158
|
-
(n)=>edit(n, "x", 1),
|
|
159
|
-
(n)=>edit(n, "y", 2),
|
|
160
|
-
(n)=>edit(n, "z", 3)
|
|
161
|
-
]);
|
|
162
|
-
expect(pm.state.doc).toEqualNode(doc(p("fxyzoo")));
|
|
163
|
-
});
|
|
164
|
-
// TODO: Offset out of bound
|
|
165
|
-
// eslint-disable-next-line jest/no-disabled-tests
|
|
166
|
-
it.skip("can deal with Android-style newline-after-composition", ()=>{
|
|
167
|
-
const { view: pm } = tempEditor({
|
|
168
|
-
doc: doc(p("abcdef"))
|
|
169
|
-
});
|
|
170
|
-
compose(pm, ()=>edit(findTextNode(pm.dom, "abcdef")), [
|
|
171
|
-
(n)=>edit(n, "x", 3),
|
|
172
|
-
(n)=>edit(n, "y", 4)
|
|
173
|
-
], {
|
|
174
|
-
end: (n)=>{
|
|
175
|
-
const line = pm.dom.appendChild(document.createElement("div"));
|
|
176
|
-
line.textContent = "def";
|
|
177
|
-
n.nodeValue = "abcxy";
|
|
178
|
-
document.getSelection().collapse(line, 0);
|
|
179
|
-
}
|
|
180
|
-
});
|
|
181
|
-
expect(pm.state.doc).toEqualNode(doc(p("abcxy"), p("def")));
|
|
182
|
-
});
|
|
183
|
-
it("handles replacement of existing words", ()=>{
|
|
184
|
-
const { view: pm } = tempEditor({
|
|
185
|
-
doc: doc(p("one two three"))
|
|
186
|
-
});
|
|
187
|
-
compose(pm, ()=>edit(findTextNode(pm.dom, "one two three"), "five", 4, 7), [
|
|
188
|
-
(n)=>edit(n, "seven", 4, 8),
|
|
189
|
-
(n)=>edit(n, "zero", 4, 9)
|
|
190
|
-
]);
|
|
191
|
-
expect(pm.state.doc).toEqualNode(doc(p("one zero three")));
|
|
192
|
-
});
|
|
193
|
-
it("handles composition inside marks", ()=>{
|
|
194
|
-
const { view: pm } = tempEditor({
|
|
195
|
-
doc: doc(p("one ", em("two")))
|
|
196
|
-
});
|
|
197
|
-
compose(pm, ()=>edit(findTextNode(pm.dom, "two"), "o"), [
|
|
198
|
-
(n)=>edit(n, "o"),
|
|
199
|
-
(n)=>edit(n, "w")
|
|
200
|
-
]);
|
|
201
|
-
expect(pm.state.doc).toEqualNode(doc(p("one ", em("twooow"))));
|
|
202
|
-
});
|
|
203
|
-
it.skip("handles composition in a mark that has multiple children", ()=>{
|
|
204
|
-
const { view: pm } = tempEditor({
|
|
205
|
-
doc: doc(p("one ", em("two", strong(" three"))))
|
|
206
|
-
});
|
|
207
|
-
compose(pm, ()=>edit(findTextNode(pm.dom, "two"), "o"), [
|
|
208
|
-
(n)=>edit(n, "o"),
|
|
209
|
-
(n)=>edit(n, "w")
|
|
210
|
-
]);
|
|
211
|
-
expect(pm.state.doc).toEqualNode(doc(p("one ", em("twooow", strong(" three")))));
|
|
212
|
-
});
|
|
213
|
-
// it("supports composition in a cursor wrapper", () => {
|
|
214
|
-
// const { view: pm } = tempEditor({ doc: doc(p("<a>")) });
|
|
215
|
-
// pm.dispatch(pm.state.tr.addStoredMark(schema.marks.em.create()));
|
|
216
|
-
// compose(
|
|
217
|
-
// pm,
|
|
218
|
-
// () =>
|
|
219
|
-
// edit(pm.dom.firstChild!.appendChild(document.createTextNode("")), "a"),
|
|
220
|
-
// [(n) => edit(n, "b"), (n) => edit(n, "c")],
|
|
221
|
-
// { node: true }
|
|
222
|
-
// );
|
|
223
|
-
// ist(pm.state.doc, doc(p(em("abc"))), eq);
|
|
224
|
-
// });
|
|
225
|
-
// it("handles composition in a multi-child mark with a cursor wrapper", () => {
|
|
226
|
-
// const { view: pm } = requireFocus(
|
|
227
|
-
// tempEditor({ doc: doc(p("one ", em("two<a>", strong(" three")))) })
|
|
228
|
-
// );
|
|
229
|
-
// pm.dispatch(pm.state.tr.addStoredMark(schema.marks.code.create()));
|
|
230
|
-
// const emNode = pm.dom.querySelector("em")!;
|
|
231
|
-
// compose(
|
|
232
|
-
// pm,
|
|
233
|
-
// () =>
|
|
234
|
-
// edit(
|
|
235
|
-
// emNode.insertBefore(
|
|
236
|
-
// document.createTextNode(""),
|
|
237
|
-
// emNode.querySelector("strong")
|
|
238
|
-
// ),
|
|
239
|
-
// "o"
|
|
240
|
-
// ),
|
|
241
|
-
// [(n) => edit(n, "o"), (n) => edit(n, "w")],
|
|
242
|
-
// { node: true }
|
|
243
|
-
// );
|
|
244
|
-
// ist(
|
|
245
|
-
// pm.state.doc,
|
|
246
|
-
// doc(p("one ", em("two", code("oow"), strong(" three")))),
|
|
247
|
-
// eq
|
|
248
|
-
// );
|
|
249
|
-
// });
|
|
250
|
-
// it("doesn't get interrupted by changes in decorations", () => {
|
|
251
|
-
// const { view: pm } = requireFocus(
|
|
252
|
-
// tempEditor({ doc: doc(p("foo ...")), plugins: [wordHighlighter] })
|
|
253
|
-
// );
|
|
254
|
-
// compose(pm, () => edit(findTextNode(pm.dom, " ...")!), [
|
|
255
|
-
// (n) => edit(n, "hi", 1, 4),
|
|
256
|
-
// ]);
|
|
257
|
-
// ist(pm.state.doc, doc(p("foo hi")), eq);
|
|
258
|
-
// });
|
|
259
|
-
// it("works inside highlighted text", () => {
|
|
260
|
-
// const { view: pm } = requireFocus(
|
|
261
|
-
// tempEditor({ doc: doc(p("one two")), plugins: [wordHighlighter] })
|
|
262
|
-
// );
|
|
263
|
-
// compose(pm, () => edit(findTextNode(pm.dom, "one")!, "x"), [
|
|
264
|
-
// (n) => edit(n, "y"),
|
|
265
|
-
// (n) => edit(n, "."),
|
|
266
|
-
// ]);
|
|
267
|
-
// ist(pm.state.doc, doc(p("onexy. two")), eq);
|
|
268
|
-
// });
|
|
269
|
-
// it("can handle compositions spanning multiple nodes", () => {
|
|
270
|
-
// const { view: pm } = requireFocus(
|
|
271
|
-
// tempEditor({ doc: doc(p("one two")), plugins: [wordHighlighter] })
|
|
272
|
-
// );
|
|
273
|
-
// compose(
|
|
274
|
-
// pm,
|
|
275
|
-
// () => edit(findTextNode(pm.dom, "two")!, "a"),
|
|
276
|
-
// [(n) => edit(n, "b"), (n) => edit(n, "c")],
|
|
277
|
-
// {
|
|
278
|
-
// end: (n: Text) => {
|
|
279
|
-
// n.parentNode!.previousSibling!.remove();
|
|
280
|
-
// n.parentNode!.previousSibling!.remove();
|
|
281
|
-
// return edit(n, "xyzone ", 0);
|
|
282
|
-
// },
|
|
283
|
-
// }
|
|
284
|
-
// );
|
|
285
|
-
// ist(pm.state.doc, doc(p("xyzone twoabc")), eq);
|
|
286
|
-
// });
|
|
287
|
-
// it("doesn't overwrite widgets next to the composition", () => {
|
|
288
|
-
// const { view: pm } = requireFocus(
|
|
289
|
-
// tempEditor({ doc: doc(p("")), plugins: [widgets([1, 1], [-1, 1])] })
|
|
290
|
-
// );
|
|
291
|
-
// compose(
|
|
292
|
-
// pm,
|
|
293
|
-
// () => {
|
|
294
|
-
// const p = pm.dom.firstChild!;
|
|
295
|
-
// return edit(p.insertBefore(document.createTextNode("a"), p.lastChild));
|
|
296
|
-
// },
|
|
297
|
-
// [(n) => edit(n, "b", 0, 1)],
|
|
298
|
-
// {
|
|
299
|
-
// end: () => {
|
|
300
|
-
// ist(pm.dom.querySelectorAll("var").length, 2);
|
|
301
|
-
// },
|
|
302
|
-
// }
|
|
303
|
-
// );
|
|
304
|
-
// ist(pm.state.doc, doc(p("b")), eq);
|
|
305
|
-
// });
|
|
306
|
-
// it("cancels composition when a change fully overlaps with it", () => {
|
|
307
|
-
// const { view: pm } = requireFocus(
|
|
308
|
-
// tempEditor({ doc: doc(p("one"), p("two"), p("three")) })
|
|
309
|
-
// );
|
|
310
|
-
// compose(
|
|
311
|
-
// pm,
|
|
312
|
-
// () => edit(findTextNode(pm.dom, "two")!, "x"),
|
|
313
|
-
// [() => pm.dispatch(pm.state.tr.insertText("---", 3, 13))],
|
|
314
|
-
// { cancel: true }
|
|
315
|
-
// );
|
|
316
|
-
// ist(pm.state.doc, doc(p("on---hree")), eq);
|
|
317
|
-
// });
|
|
318
|
-
// it("cancels composition when a change partially overlaps with it", () => {
|
|
319
|
-
// const { view: pm } = requireFocus(
|
|
320
|
-
// tempEditor({ doc: doc(p("one"), p("two"), p("three")) })
|
|
321
|
-
// );
|
|
322
|
-
// compose(
|
|
323
|
-
// pm,
|
|
324
|
-
// () => edit(findTextNode(pm.dom, "two")!, "x", 0),
|
|
325
|
-
// [() => pm.dispatch(pm.state.tr.insertText("---", 7, 15))],
|
|
326
|
-
// { cancel: true }
|
|
327
|
-
// );
|
|
328
|
-
// ist(pm.state.doc, doc(p("one"), p("x---ee")), eq);
|
|
329
|
-
// });
|
|
330
|
-
// it("cancels composition when a change happens inside of it", () => {
|
|
331
|
-
// const { view: pm } = requireFocus(
|
|
332
|
-
// tempEditor({ doc: doc(p("one"), p("two"), p("three")) })
|
|
333
|
-
// );
|
|
334
|
-
// compose(
|
|
335
|
-
// pm,
|
|
336
|
-
// () => edit(findTextNode(pm.dom, "two")!, "x", 0),
|
|
337
|
-
// [() => pm.dispatch(pm.state.tr.insertText("!", 7, 8))],
|
|
338
|
-
// { cancel: true }
|
|
339
|
-
// );
|
|
340
|
-
// ist(pm.state.doc, doc(p("one"), p("x!wo"), p("three")), eq);
|
|
341
|
-
// });
|
|
342
|
-
// it("doesn't cancel composition when a change happens elsewhere", () => {
|
|
343
|
-
// const { view: pm } = requireFocus(
|
|
344
|
-
// tempEditor({ doc: doc(p("one"), p("two"), p("three")) })
|
|
345
|
-
// );
|
|
346
|
-
// compose(pm, () => edit(findTextNode(pm.dom, "two")!, "x", 0), [
|
|
347
|
-
// (n) => edit(n, "y", 1),
|
|
348
|
-
// () => pm.dispatch(pm.state.tr.insertText("!", 2, 3)),
|
|
349
|
-
// (n) => edit(n, "z", 2),
|
|
350
|
-
// ]);
|
|
351
|
-
// ist(pm.state.doc, doc(p("o!e"), p("xyztwo"), p("three")), eq);
|
|
352
|
-
// });
|
|
353
|
-
// it("handles compositions rapidly following each other", () => {
|
|
354
|
-
// const { view: pm } = tempEditor({ doc: doc(p("one"), p("two")) });
|
|
355
|
-
// event(pm, "compositionstart");
|
|
356
|
-
// const one = findTextNode(pm.dom, "one")!;
|
|
357
|
-
// edit(one, "!");
|
|
358
|
-
// pm.domObserver.flush();
|
|
359
|
-
// event(pm, "compositionend");
|
|
360
|
-
// one.nodeValue = "one!!";
|
|
361
|
-
// const L2 = pm.dom.lastChild;
|
|
362
|
-
// event(pm, "compositionstart");
|
|
363
|
-
// const two = findTextNode(pm.dom, "two")!;
|
|
364
|
-
// ist(pm.dom.lastChild, L2);
|
|
365
|
-
// edit(two, ".");
|
|
366
|
-
// pm.domObserver.flush();
|
|
367
|
-
// ist(document.getSelection()!.focusNode, two);
|
|
368
|
-
// ist(document.getSelection()!.focusOffset, 4);
|
|
369
|
-
// ist(pm.composing);
|
|
370
|
-
// event(pm, "compositionend");
|
|
371
|
-
// pm.domObserver.flush();
|
|
372
|
-
// ist(pm.state.doc, doc(p("one!!"), p("two.")), eq);
|
|
373
|
-
// });
|
|
374
|
-
// function crossParagraph(first = false) {
|
|
375
|
-
// const { view: pm } = requireFocus(
|
|
376
|
-
// tempEditor({ doc: doc(p("one <a>two"), p("three"), p("four<b> five")) })
|
|
377
|
-
// );
|
|
378
|
-
// compose(
|
|
379
|
-
// pm,
|
|
380
|
-
// () => {
|
|
381
|
-
// for (let i = 0; i < 2; i++)
|
|
382
|
-
// pm.dom.removeChild(first ? pm.dom.lastChild! : pm.dom.firstChild!);
|
|
383
|
-
// const target = pm.dom.firstChild!.firstChild as Text;
|
|
384
|
-
// target.nodeValue = "one A five";
|
|
385
|
-
// document.getSelection()!.collapse(target, 4);
|
|
386
|
-
// return target;
|
|
387
|
-
// },
|
|
388
|
-
// [(n) => edit(n, "B", 4, 5), (n) => edit(n, "C", 4, 5)]
|
|
389
|
-
// );
|
|
390
|
-
// ist(pm.state.doc, doc(p("one C five")), eq);
|
|
391
|
-
// }
|
|
392
|
-
// it("can handle cross-paragraph compositions", () => crossParagraph(true));
|
|
393
|
-
// it("can handle cross-paragraph compositions (keeping the last paragraph)", () =>
|
|
394
|
-
// crossParagraph(false));
|
|
395
|
-
});
|
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-non-null-assertion */ import { screen } from "@testing-library/react";
|
|
2
|
-
import { EditorState, TextSelection } from "prosemirror-state";
|
|
3
|
-
import { a, blockquote, doc, em, p, pre, strong } from "prosemirror-test-builder";
|
|
4
|
-
import { Key } from "webdriverio";
|
|
5
|
-
import { tempEditor } from "../../testing/editorViewTestHelpers.js";
|
|
6
|
-
describe("DOM change", ()=>{
|
|
7
|
-
it("notices when text is added", async ()=>{
|
|
8
|
-
const { view } = tempEditor({
|
|
9
|
-
doc: doc(p("he<a>llo"))
|
|
10
|
-
});
|
|
11
|
-
view.focus();
|
|
12
|
-
await browser.keys([
|
|
13
|
-
Key.Shift,
|
|
14
|
-
"l"
|
|
15
|
-
]);
|
|
16
|
-
expect(view.state.doc).toEqualNode(doc(p("heLllo")));
|
|
17
|
-
});
|
|
18
|
-
it("notices when text is removed", async ()=>{
|
|
19
|
-
const { view } = tempEditor({
|
|
20
|
-
doc: doc(p("hell<a>o"))
|
|
21
|
-
});
|
|
22
|
-
view.focus();
|
|
23
|
-
await browser.keys(Key.Backspace);
|
|
24
|
-
await browser.keys(Key.Backspace);
|
|
25
|
-
expect(view.state.doc).toEqualNode(doc(p("heo")));
|
|
26
|
-
});
|
|
27
|
-
it("respects stored marks", async ()=>{
|
|
28
|
-
const { view } = tempEditor({
|
|
29
|
-
doc: doc(p("hello<a>"))
|
|
30
|
-
});
|
|
31
|
-
view.dispatch(view.state.tr.addStoredMark(view.state.schema.marks.em.create()));
|
|
32
|
-
view.focus();
|
|
33
|
-
await browser.keys("o");
|
|
34
|
-
expect(view.state.doc).toEqualNode(doc(p("hello", em("o"))));
|
|
35
|
-
});
|
|
36
|
-
it("support inserting repeated text", async ()=>{
|
|
37
|
-
const { view } = tempEditor({
|
|
38
|
-
doc: doc(p("hello"))
|
|
39
|
-
});
|
|
40
|
-
view.focus();
|
|
41
|
-
await browser.keys("h");
|
|
42
|
-
await browser.keys("e");
|
|
43
|
-
await browser.keys("l");
|
|
44
|
-
expect(view.state.doc).toEqualNode(doc(p("helhello")));
|
|
45
|
-
});
|
|
46
|
-
it("detects an enter press", async ()=>{
|
|
47
|
-
let enterPressed = false;
|
|
48
|
-
const { view } = tempEditor({
|
|
49
|
-
doc: doc(blockquote(p("foo"), p("<a>"))),
|
|
50
|
-
handleKeyDown: (_, event)=>{
|
|
51
|
-
if (event.key === "Enter") return enterPressed = true;
|
|
52
|
-
return false;
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
view.focus();
|
|
56
|
-
await browser.keys(Key.Enter);
|
|
57
|
-
expect(enterPressed).toBeTruthy();
|
|
58
|
-
});
|
|
59
|
-
it("detects a simple backspace press", async ()=>{
|
|
60
|
-
let backspacePressed = false;
|
|
61
|
-
const { view } = tempEditor({
|
|
62
|
-
doc: doc(blockquote(p("foo"), p("<a>"))),
|
|
63
|
-
handleKeyDown: (_, event)=>{
|
|
64
|
-
if (event.key === "Backspace") return backspacePressed = true;
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
view.focus();
|
|
69
|
-
await browser.keys(Key.Backspace);
|
|
70
|
-
expect(backspacePressed).toBeTruthy();
|
|
71
|
-
});
|
|
72
|
-
it("correctly adjusts the selection", async ()=>{
|
|
73
|
-
const { view } = tempEditor({
|
|
74
|
-
doc: doc(p("abc<a>"))
|
|
75
|
-
});
|
|
76
|
-
view.focus();
|
|
77
|
-
await browser.keys("d");
|
|
78
|
-
expect(view.state.doc).toEqualNode(doc(p("abcd")));
|
|
79
|
-
expect(view.state.selection.anchor).toBe(5);
|
|
80
|
-
expect(view.state.selection.head).toBe(5);
|
|
81
|
-
});
|
|
82
|
-
// todoit("can read a simple composition", () => {
|
|
83
|
-
// let view = tempEditor({ doc: doc(p("hello")) });
|
|
84
|
-
// findTextNode(view.dom, "hello")!.nodeValue = "hellox";
|
|
85
|
-
// flush(view);
|
|
86
|
-
// ist(view.state.doc, doc(p("hellox")), eq);
|
|
87
|
-
// });
|
|
88
|
-
// $$FORK: We _do_ repaint text nodes when they're typed into.
|
|
89
|
-
// Unlike prosemirror-view, we prevent user inputs from modifying
|
|
90
|
-
// the dom until after we've turned them into transactions.
|
|
91
|
-
// This test instead ensures that we only modify the character data,
|
|
92
|
-
// rather than replacing entire nodes.
|
|
93
|
-
it("does not replace a text node when it's typed into", async ()=>{
|
|
94
|
-
const { view } = tempEditor({
|
|
95
|
-
doc: doc(p("fo<a>o"))
|
|
96
|
-
});
|
|
97
|
-
let mutated = false;
|
|
98
|
-
const observer = new MutationObserver(()=>mutated = true);
|
|
99
|
-
observer.observe(view.dom, {
|
|
100
|
-
subtree: true,
|
|
101
|
-
characterData: false,
|
|
102
|
-
childList: true
|
|
103
|
-
});
|
|
104
|
-
view.focus();
|
|
105
|
-
await browser.keys("j");
|
|
106
|
-
expect(view.state.doc).toEqualNode(doc(p("fojo")));
|
|
107
|
-
expect(mutated).toBeFalsy();
|
|
108
|
-
observer.disconnect();
|
|
109
|
-
});
|
|
110
|
-
it("understands text typed into an empty paragraph", async ()=>{
|
|
111
|
-
const { view } = tempEditor({
|
|
112
|
-
doc: doc(p("<a>"))
|
|
113
|
-
});
|
|
114
|
-
view.focus();
|
|
115
|
-
await browser.keys("i");
|
|
116
|
-
expect(view.state.doc).toEqualNode(doc(p("i")));
|
|
117
|
-
});
|
|
118
|
-
it("fixes text changes when input is ignored", async ()=>{
|
|
119
|
-
const { view } = tempEditor({
|
|
120
|
-
doc: doc(p("foo<a>")),
|
|
121
|
-
controlled: true,
|
|
122
|
-
dispatchTransaction () {
|
|
123
|
-
// intentionally do nothing
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
view.focus();
|
|
127
|
-
await browser.keys("i");
|
|
128
|
-
expect(view.dom.textContent).toBe("foo");
|
|
129
|
-
});
|
|
130
|
-
it("aborts when an incompatible state is set", async ()=>{
|
|
131
|
-
const { view } = tempEditor({
|
|
132
|
-
doc: doc(p("<a>abcde"))
|
|
133
|
-
});
|
|
134
|
-
view.dispatchEvent({
|
|
135
|
-
type: "input"
|
|
136
|
-
});
|
|
137
|
-
view.focus();
|
|
138
|
-
await browser.keys("x");
|
|
139
|
-
view.updateState(EditorState.create({
|
|
140
|
-
doc: doc(p("uvw"))
|
|
141
|
-
}));
|
|
142
|
-
expect(view.state.doc).toEqualNode(doc(p("uvw")));
|
|
143
|
-
});
|
|
144
|
-
it("preserves marks on deletion", async ()=>{
|
|
145
|
-
const { view } = tempEditor({
|
|
146
|
-
doc: doc(p("one", em("x<a>")))
|
|
147
|
-
});
|
|
148
|
-
view.focus();
|
|
149
|
-
await browser.keys(Key.Backspace);
|
|
150
|
-
view.dispatchEvent({
|
|
151
|
-
type: "input"
|
|
152
|
-
});
|
|
153
|
-
view.dispatch(view.state.tr.insertText("y"));
|
|
154
|
-
expect(view.state.doc).toEqualNode(doc(p("one", em("y"))));
|
|
155
|
-
});
|
|
156
|
-
it("works when a node's contentDOM is deleted", async ()=>{
|
|
157
|
-
const { view } = tempEditor({
|
|
158
|
-
doc: doc(p("one"), pre("two<a>"))
|
|
159
|
-
});
|
|
160
|
-
view.focus();
|
|
161
|
-
await browser.keys(Key.Backspace);
|
|
162
|
-
await browser.keys(Key.Backspace);
|
|
163
|
-
await browser.keys(Key.Backspace);
|
|
164
|
-
view.dispatchEvent({
|
|
165
|
-
type: "input"
|
|
166
|
-
});
|
|
167
|
-
expect(view.state.doc).toEqualNode(doc(p("one"), pre()));
|
|
168
|
-
expect(view.state.selection.head).toBe(6);
|
|
169
|
-
});
|
|
170
|
-
it("doesn't redraw content with marks when typing in front", async ()=>{
|
|
171
|
-
const { view } = tempEditor({
|
|
172
|
-
doc: doc(p("f<a>oo", em("bar"), strong("baz")))
|
|
173
|
-
});
|
|
174
|
-
const bar = await screen.findByText("bar");
|
|
175
|
-
const foo = await screen.findByText("foo");
|
|
176
|
-
view.focus();
|
|
177
|
-
await browser.keys("r");
|
|
178
|
-
expect(view.state.doc).toEqualNode(doc(p("froo", em("bar"), strong("baz"))));
|
|
179
|
-
expect(bar.parentNode).toBeTruthy();
|
|
180
|
-
expect(view.dom.contains(bar.parentNode)).toBeTruthy();
|
|
181
|
-
expect(foo.parentNode).toBeTruthy();
|
|
182
|
-
expect(view.dom.contains(foo.parentNode)).toBeTruthy();
|
|
183
|
-
});
|
|
184
|
-
it("doesn't redraw content with marks when typing inside mark", async ()=>{
|
|
185
|
-
const { view } = tempEditor({
|
|
186
|
-
doc: doc(p("foo", em("b<a>ar"), strong("baz")))
|
|
187
|
-
});
|
|
188
|
-
const bar = await screen.findByText("bar");
|
|
189
|
-
const foo = await screen.findByText("foo");
|
|
190
|
-
view.focus();
|
|
191
|
-
await browser.keys("a");
|
|
192
|
-
expect(view.state.doc).toEqualNode(doc(p("foo", em("baar"), strong("baz"))));
|
|
193
|
-
expect(bar.parentNode).toBeTruthy();
|
|
194
|
-
expect(view.dom.contains(bar.parentNode)).toBeTruthy();
|
|
195
|
-
expect(foo.parentNode).toBeTruthy();
|
|
196
|
-
expect(view.dom.contains(foo.parentNode)).toBeTruthy();
|
|
197
|
-
});
|
|
198
|
-
it("maps input to coordsAtPos through pending changes", async ()=>{
|
|
199
|
-
const { view } = tempEditor({
|
|
200
|
-
doc: doc(p("foo"))
|
|
201
|
-
});
|
|
202
|
-
view.dispatchEvent({
|
|
203
|
-
type: "input"
|
|
204
|
-
});
|
|
205
|
-
view.dispatch(view.state.tr.insertText("more text"));
|
|
206
|
-
expect(view.coordsAtPos(13)).toBeTruthy();
|
|
207
|
-
});
|
|
208
|
-
it("notices text added to a cursor wrapper at the start of a mark", async ()=>{
|
|
209
|
-
const { view } = tempEditor({
|
|
210
|
-
doc: doc(p(strong(a("foo<a>"), "bar")))
|
|
211
|
-
});
|
|
212
|
-
view.focus();
|
|
213
|
-
await browser.keys("xy");
|
|
214
|
-
expect(view.state.doc).toEqualNode(doc(p(strong(a("foo"), "xybar"))));
|
|
215
|
-
});
|
|
216
|
-
it("removes cursor wrapper text when the wrapper otherwise remains valid", async ()=>{
|
|
217
|
-
const { view } = tempEditor({
|
|
218
|
-
doc: doc(p(a(strong("foo<a>"), "bar")))
|
|
219
|
-
});
|
|
220
|
-
view.focus();
|
|
221
|
-
await browser.keys("q");
|
|
222
|
-
expect(view.state.doc).toEqualNode(doc(p(a(strong("fooq"), "bar"))));
|
|
223
|
-
const found = screen.queryByText("\ufeffq");
|
|
224
|
-
expect(found).toBeNull();
|
|
225
|
-
});
|
|
226
|
-
it("creates a correct step for an ambiguous selection-deletion", async ()=>{
|
|
227
|
-
let steps;
|
|
228
|
-
const { view } = tempEditor({
|
|
229
|
-
doc: doc(p("la<a>la<b>la")),
|
|
230
|
-
dispatchTransaction (tr) {
|
|
231
|
-
steps = tr.steps;
|
|
232
|
-
view.updateState(view.state.apply(tr));
|
|
233
|
-
}
|
|
234
|
-
});
|
|
235
|
-
view.input.lastKeyCode = 8;
|
|
236
|
-
view.input.lastKeyCodeTime = Date.now();
|
|
237
|
-
view.focus();
|
|
238
|
-
await browser.keys(Key.Backspace);
|
|
239
|
-
expect(steps).toHaveLength(1);
|
|
240
|
-
expect(steps[0].from).toBe(3);
|
|
241
|
-
expect(steps[0].to).toBe(5);
|
|
242
|
-
});
|
|
243
|
-
it("creates a step that covers the entire selection for partially-matching replacement", async ()=>{
|
|
244
|
-
let steps;
|
|
245
|
-
const { view } = tempEditor({
|
|
246
|
-
doc: doc(p("one <a>two<b> three")),
|
|
247
|
-
dispatchTransaction (tr) {
|
|
248
|
-
steps = tr.steps;
|
|
249
|
-
view.updateState(view.state.apply(tr));
|
|
250
|
-
}
|
|
251
|
-
});
|
|
252
|
-
view.focus();
|
|
253
|
-
await browser.keys("t");
|
|
254
|
-
expect(steps).toHaveLength(1);
|
|
255
|
-
expect(steps[0].from).toBe(5);
|
|
256
|
-
expect(steps[0].to).toBe(8);
|
|
257
|
-
expect(steps[0].slice.content.toString()).toBe('<"t">');
|
|
258
|
-
view.dispatch(view.state.tr.setSelection(TextSelection.create(view.state.doc, 7, 12)));
|
|
259
|
-
view.focus();
|
|
260
|
-
await browser.keys("e");
|
|
261
|
-
expect(steps).toHaveLength(1);
|
|
262
|
-
expect(steps[0].from).toBe(7);
|
|
263
|
-
expect(steps[0].to).toBe(12);
|
|
264
|
-
expect(steps[0].slice.content.toString()).toBe('<"e">');
|
|
265
|
-
});
|
|
266
|
-
});
|