@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.
Files changed (60) hide show
  1. package/dist/cjs/tiptap/tiptapNodeView.js +26 -13
  2. package/dist/esm/tiptap/tiptapNodeView.js +27 -14
  3. package/dist/tsconfig.tsbuildinfo +1 -1
  4. package/dist/types/constants.d.ts +1 -1
  5. package/dist/types/props.d.ts +26 -26
  6. package/package.json +1 -1
  7. package/dist/esm/@jest/pattern/src/__tests__/TestPathPatterns.test.js +0 -241
  8. package/dist/esm/@swc/cli/lib/swc/__tests__/compile.test.js +0 -19
  9. package/dist/esm/@swc/cli/lib/swc/__tests__/options.test.js +0 -315
  10. package/dist/esm/@swc/cli/lib/swc/__tests__/sources.test.js +0 -161
  11. package/dist/esm/@uiw/react-codemirror/src/__tests__/index.test.js +0 -111
  12. package/dist/esm/cheerio/src/__tests__/deprecated.spec.js +0 -249
  13. package/dist/esm/cheerio/src/__tests__/xml.spec.js +0 -55
  14. package/dist/esm/components/__tests__/ProseMirror.composition.test.js +0 -395
  15. package/dist/esm/components/__tests__/ProseMirror.domchange.test.js +0 -266
  16. package/dist/esm/components/__tests__/ProseMirror.draw-decoration.test.js +0 -968
  17. package/dist/esm/components/__tests__/ProseMirror.draw.test.js +0 -335
  18. package/dist/esm/components/__tests__/ProseMirror.mobile.test.js +0 -54
  19. package/dist/esm/components/__tests__/ProseMirror.node-view.test.js +0 -553
  20. package/dist/esm/components/__tests__/ProseMirror.selection.test.js +0 -440
  21. package/dist/esm/components/__tests__/ProseMirror.test.js +0 -324
  22. package/dist/esm/contexts/__tests__/DeferredLayoutEffects.test.js +0 -98
  23. package/dist/esm/hooks/__tests__/useEditorEffect.test.js +0 -134
  24. package/dist/esm/jsx-ast-utils/__tests__/helper.js +0 -83
  25. package/dist/esm/jsx-ast-utils/__tests__/src/elementType-test.js +0 -76
  26. package/dist/esm/jsx-ast-utils/__tests__/src/eventHandlers-test.js +0 -98
  27. package/dist/esm/jsx-ast-utils/__tests__/src/getProp-parser-test.js +0 -188
  28. package/dist/esm/jsx-ast-utils/__tests__/src/getProp-test.js +0 -119
  29. package/dist/esm/jsx-ast-utils/__tests__/src/getPropLiteralValue-babelparser-test.js +0 -393
  30. package/dist/esm/jsx-ast-utils/__tests__/src/getPropLiteralValue-flowparser-test.js +0 -379
  31. package/dist/esm/jsx-ast-utils/__tests__/src/getPropValue-babelparser-test.js +0 -925
  32. package/dist/esm/jsx-ast-utils/__tests__/src/getPropValue-flowparser-test.js +0 -700
  33. package/dist/esm/jsx-ast-utils/__tests__/src/hasProp-test.js +0 -350
  34. package/dist/esm/jsx-ast-utils/__tests__/src/index-test.js +0 -24
  35. package/dist/esm/jsx-ast-utils/__tests__/src/propName-test.js +0 -37
  36. package/dist/esm/plugins/__tests__/reactKeys.test.js +0 -77
  37. package/dist/esm/tsconfig-paths/lib/__tests__/config-loader.test.d.js +0 -1
  38. package/dist/esm/tsconfig-paths/lib/__tests__/config-loader.test.js +0 -97
  39. package/dist/esm/tsconfig-paths/lib/__tests__/data/match-path-data.d.js +0 -1
  40. package/dist/esm/tsconfig-paths/lib/__tests__/data/match-path-data.js +0 -319
  41. package/dist/esm/tsconfig-paths/lib/__tests__/filesystem.test.d.js +0 -1
  42. package/dist/esm/tsconfig-paths/lib/__tests__/filesystem.test.js +0 -62
  43. package/dist/esm/tsconfig-paths/lib/__tests__/mapping-entry.test.d.js +0 -1
  44. package/dist/esm/tsconfig-paths/lib/__tests__/mapping-entry.test.js +0 -80
  45. package/dist/esm/tsconfig-paths/lib/__tests__/match-path-async.test.d.js +0 -1
  46. package/dist/esm/tsconfig-paths/lib/__tests__/match-path-async.test.js +0 -22
  47. package/dist/esm/tsconfig-paths/lib/__tests__/match-path-sync.test.d.js +0 -1
  48. package/dist/esm/tsconfig-paths/lib/__tests__/match-path-sync.test.js +0 -20
  49. package/dist/esm/tsconfig-paths/lib/__tests__/try-path.test.d.js +0 -1
  50. package/dist/esm/tsconfig-paths/lib/__tests__/try-path.test.js +0 -219
  51. package/dist/esm/tsconfig-paths/lib/__tests__/tsconfig-loader.test.d.js +0 -1
  52. package/dist/esm/tsconfig-paths/lib/__tests__/tsconfig-loader.test.js +0 -323
  53. package/dist/esm/tsconfig-paths/src/__tests__/config-loader.test.js +0 -89
  54. package/dist/esm/tsconfig-paths/src/__tests__/data/match-path-data.js +0 -314
  55. package/dist/esm/tsconfig-paths/src/__tests__/filesystem.test.js +0 -58
  56. package/dist/esm/tsconfig-paths/src/__tests__/mapping-entry.test.js +0 -76
  57. package/dist/esm/tsconfig-paths/src/__tests__/match-path-async.test.js +0 -12
  58. package/dist/esm/tsconfig-paths/src/__tests__/match-path-sync.test.js +0 -10
  59. package/dist/esm/tsconfig-paths/src/__tests__/try-path.test.js +0 -214
  60. package/dist/esm/tsconfig-paths/src/__tests__/tsconfig-loader.test.js +0 -296
@@ -1,440 +0,0 @@
1
- /* eslint-disable jest/no-disabled-tests */ /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-non-null-assertion */ import { act, screen } from "@testing-library/react";
2
- import { NodeSelection, Selection } from "prosemirror-state";
3
- import { blockquote, br, code, code_block, doc, em, hr, img as img_, li, p, strong, ul } from "prosemirror-test-builder";
4
- import { Decoration, DecorationSet } from "prosemirror-view";
5
- import { tempEditor } from "../../testing/editorViewTestHelpers.js";
6
- const img = img_({
7
- src: "data:image/gif;base64,R0lGODlhBQAFAIABAAAAAP///yH5BAEKAAEALAAAAAAFAAUAAAIEjI+pWAA7"
8
- });
9
- async function findTextNode(_, text) {
10
- const parent = await screen.findByText(text);
11
- return parent.firstChild;
12
- }
13
- function allPositions(doc) {
14
- const found = [];
15
- function scan(node, start) {
16
- if (node.isTextblock) {
17
- for(let i = 0; i <= node.content.size; i++)found.push(start + i);
18
- } else {
19
- node.forEach((child, offset)=>scan(child, start + offset + 1));
20
- }
21
- }
22
- scan(doc, 0);
23
- return found;
24
- }
25
- function setDOMSel(node, offset) {
26
- const range = document.createRange();
27
- range.setEnd(node, offset);
28
- range.setStart(node, offset);
29
- const sel = window.getSelection();
30
- sel.removeAllRanges();
31
- sel.addRange(range);
32
- }
33
- function getSel() {
34
- const sel = window.getSelection();
35
- let node = sel.focusNode, offset = sel.focusOffset;
36
- while(node && node.nodeType != 3){
37
- const after = offset < node.childNodes.length && node.childNodes[offset];
38
- const before = offset > 0 && node.childNodes[offset - 1];
39
- if (after) {
40
- node = after;
41
- offset = 0;
42
- } else if (before) {
43
- node = before;
44
- offset = node.nodeType == 3 ? node.nodeValue.length : node.childNodes.length;
45
- } else break;
46
- }
47
- return {
48
- node: node,
49
- offset: offset
50
- };
51
- }
52
- function setSel(view, sel) {
53
- const selection = typeof sel == "number" ? Selection.near(view.state.doc.resolve(sel)) : sel;
54
- act(()=>{
55
- view.dispatch(view.state.tr.setSelection(selection));
56
- });
57
- }
58
- function event(code) {
59
- const event = document.createEvent("Event");
60
- event.initEvent("keydown", true, true);
61
- event.keyCode = code;
62
- return event;
63
- }
64
- const LEFT = 37, RIGHT = 39, UP = 38, DOWN = 40;
65
- describe("ProseMirror", ()=>{
66
- it("can read the DOM selection", async ()=>{
67
- const { view } = tempEditor({
68
- doc: doc(p("one"), hr(), blockquote(p("two")))
69
- });
70
- function test(node, offset, expected) {
71
- setDOMSel(node, offset);
72
- view.dom.focus();
73
- act(()=>{
74
- view.domObserver.flush();
75
- });
76
- const sel = view.state.selection;
77
- expect(sel.head == null ? sel.from : sel.head).toBe(expected);
78
- }
79
- const one = await findTextNode(view.dom, "one");
80
- const two = await findTextNode(view.dom, "two");
81
- test(one, 0, 1);
82
- test(one, 1, 2);
83
- test(one, 3, 4);
84
- test(one.parentNode, 0, 1);
85
- test(one.parentNode, 1, 4);
86
- test(two, 0, 8);
87
- test(two, 3, 11);
88
- test(two.parentNode, 1, 11);
89
- test(view.dom, 1, 4);
90
- test(view.dom, 2, 8);
91
- test(view.dom, 3, 11);
92
- });
93
- it("syncs the DOM selection with the editor selection", async ()=>{
94
- const { view } = tempEditor({
95
- doc: doc(p("one"), hr(), blockquote(p("two")))
96
- });
97
- function test(pos, node, offset) {
98
- setSel(view, pos);
99
- const sel = getSel();
100
- expect(sel.node).toBe(node);
101
- expect(sel.offset).toBe(offset);
102
- }
103
- const one = await findTextNode(view.dom, "one");
104
- const two = await findTextNode(view.dom, "two");
105
- view.focus();
106
- test(1, one, 0);
107
- test(2, one, 1);
108
- test(4, one, 3);
109
- test(8, two, 0);
110
- test(10, two, 2);
111
- });
112
- it("returns sensible screen coordinates", async ()=>{
113
- const { view } = tempEditor({
114
- doc: doc(p("one"), p("two"))
115
- });
116
- const p00 = view.coordsAtPos(1);
117
- const p01 = view.coordsAtPos(2);
118
- const p03 = view.coordsAtPos(4);
119
- const p10 = view.coordsAtPos(6);
120
- const p13 = view.coordsAtPos(9);
121
- expect(p00.bottom).toBeGreaterThan(p00.top);
122
- expect(p13.bottom).toBeGreaterThan(p13.top);
123
- expect(p00.top).toEqual(p01.top);
124
- expect(p01.top).toEqual(p03.top);
125
- expect(p00.bottom).toEqual(p03.bottom);
126
- expect(p10.top).toEqual(p13.top);
127
- expect(p01.left).toBeGreaterThan(p00.left);
128
- expect(p03.left).toBeGreaterThan(p01.left);
129
- expect(p10.top).toBeGreaterThan(p00.top);
130
- expect(p13.left).toBeGreaterThan(p10.left);
131
- });
132
- it("returns proper coordinates in code blocks", async ()=>{
133
- const { view } = tempEditor({
134
- doc: doc(code_block("a\nb\n"))
135
- }), p = [];
136
- for(let i = 1; i <= 5; i++)p.push(view.coordsAtPos(i));
137
- const [p0, p1, p2, p3, p4] = p;
138
- expect(p0.top).toBe(p1.top);
139
- expect(p0.left).toBeLessThan(p1.left);
140
- expect(p2.top).toBeGreaterThan(p1.top);
141
- expect(p2.top).toBe(p3.top);
142
- expect(p2.left).toBeLessThan(p3.left);
143
- expect(p2.left).toBe(p0.left);
144
- expect(p4.top).toBeGreaterThan(p3.top);
145
- // This one shows a small (0.01 pixel) difference in Firefox for
146
- // some reason.
147
- expect(Math.round(p4.left)).toBe(Math.round(p2.left));
148
- });
149
- // TODO: This test fails on the position between the img and the br (it returns
150
- // the position before the img, instead of after).
151
- it.skip("produces sensible screen coordinates in corner cases", async ()=>{
152
- const { view } = tempEditor({
153
- doc: doc(p("one", em("two", strong("three"), img), br(), code("foo")), p())
154
- });
155
- return new Promise((ok)=>{
156
- setTimeout(()=>{
157
- allPositions(view.state.doc).forEach((pos)=>{
158
- const coords = view.coordsAtPos(pos);
159
- const found = view.posAtCoords({
160
- top: coords.top + 1,
161
- left: coords.left
162
- }).pos;
163
- expect(found).toBe(pos);
164
- setSel(view, pos);
165
- });
166
- ok(null);
167
- }, 20);
168
- });
169
- });
170
- it("doesn't return zero-height rectangles after leaves", async ()=>{
171
- const { view } = tempEditor({
172
- doc: doc(p(img))
173
- });
174
- const coords = view.coordsAtPos(2, 1);
175
- expect(coords.bottom - coords.top).toBeGreaterThan(5);
176
- });
177
- it("produces horizontal rectangles for positions between blocks", async ()=>{
178
- const { view } = tempEditor({
179
- doc: doc(p("ha"), hr(), blockquote(p("ba")))
180
- });
181
- const a = view.coordsAtPos(0);
182
- expect(a.top).toBe(a.bottom);
183
- expect(a.top).toBe(view.dom.firstChild.getBoundingClientRect().top);
184
- expect(a.left).toBeLessThan(a.right);
185
- const b = view.coordsAtPos(4);
186
- expect(b.top).toBe(b.bottom);
187
- expect(b.top).toBeGreaterThan(a.top);
188
- expect(b.left).toBeLessThan(b.right);
189
- const c = view.coordsAtPos(5);
190
- expect(c.top).toBe(c.bottom);
191
- expect(c.top).toBeGreaterThan(b.top);
192
- const d = view.coordsAtPos(6);
193
- expect(d.top).toBe(d.bottom);
194
- expect(d.left).toBeLessThan(d.right);
195
- expect(d.top).toBeLessThan(view.dom.getBoundingClientRect().bottom);
196
- });
197
- it("produces sensible screen coordinates around line breaks", async ()=>{
198
- const { view } = tempEditor({
199
- doc: doc(p("one two three four five-six-seven-eight"))
200
- });
201
- function afterSpace(pos) {
202
- return pos > 0 && view.state.doc.textBetween(pos - 1, pos) == " ";
203
- }
204
- view.dom.style.width = "4em";
205
- let prevBefore;
206
- let prevAfter;
207
- allPositions(view.state.doc).forEach((pos)=>{
208
- const coords = view.coordsAtPos(pos, 1);
209
- if (prevAfter) // eslint-disable-next-line jest/no-conditional-expect
210
- expect(prevAfter.top < coords.top || prevAfter.top == coords.top && prevAfter.left < coords.left).toBeTruthy();
211
- prevAfter = coords;
212
- const found = view.posAtCoords({
213
- top: coords.top + 1,
214
- left: coords.left
215
- }).pos;
216
- expect(found).toBe(pos);
217
- const coordsBefore = view.coordsAtPos(pos, -1);
218
- if (prevBefore) // eslint-disable-next-line jest/no-conditional-expect
219
- expect(prevBefore.top < coordsBefore.top || prevBefore.top == coordsBefore.top && (prevBefore.left < coordsBefore.left || afterSpace(pos) && prevBefore.left == coordsBefore.left)).toBeTruthy();
220
- prevBefore = coordsBefore;
221
- });
222
- });
223
- it("can find coordinates on node boundaries", async ()=>{
224
- const { view } = tempEditor({
225
- doc: doc(p("one ", em("two"), " ", em(strong("three"))))
226
- });
227
- let prev;
228
- allPositions(view.state.doc).forEach((pos)=>{
229
- const coords = view.coordsAtPos(pos, 1);
230
- if (prev) // eslint-disable-next-line jest/no-conditional-expect
231
- expect(prev.top < coords.top || Math.abs(prev.top - coords.top) < 4 && prev.left < coords.left).toBeTruthy();
232
- prev = coords;
233
- });
234
- });
235
- it("finds proper coordinates in RTL text", async ()=>{
236
- const { view } = tempEditor({
237
- doc: doc(p("مرآة نثرية"))
238
- });
239
- view.dom.style.direction = "rtl";
240
- let prev;
241
- allPositions(view.state.doc).forEach((pos)=>{
242
- const coords = view.coordsAtPos(pos, 1);
243
- if (prev) // eslint-disable-next-line jest/no-conditional-expect
244
- expect(prev.top < coords.top || Math.abs(prev.top - coords.top) < 4 && prev.left > coords.left).toBeTruthy();
245
- prev = coords;
246
- });
247
- });
248
- it("can go back and forth between screen coordsa and document positions", async ()=>{
249
- const { view } = tempEditor({
250
- doc: doc(p("one"), blockquote(p("two"), p("three")))
251
- });
252
- [
253
- 1,
254
- 2,
255
- 4,
256
- 7,
257
- 14,
258
- 15
259
- ].forEach((pos)=>{
260
- const coords = view.coordsAtPos(pos);
261
- const found = view.posAtCoords({
262
- top: coords.top + 1,
263
- left: coords.left
264
- }).pos;
265
- expect(found).toBe(pos);
266
- });
267
- });
268
- it("returns correct screen coordinates for wrapped lines", async ()=>{
269
- const { view } = tempEditor({});
270
- const top = view.coordsAtPos(1);
271
- let pos = 1, end;
272
- for(let i = 0; i < 100; i++){
273
- view.dispatch(view.state.tr.insertText("a bc de fg h"));
274
- pos += 12;
275
- end = view.coordsAtPos(pos);
276
- if (end.bottom > top.bottom + 4) break;
277
- }
278
- expect(view.posAtCoords({
279
- left: end.left + 50,
280
- top: end.top + 5
281
- }).pos).toBe(pos);
282
- });
283
- it("makes arrow motion go through selectable inline nodes", async ()=>{
284
- const { view } = tempEditor({
285
- doc: doc(p("foo<a>", img, "bar"))
286
- });
287
- act(()=>{
288
- view.dispatchEvent(event(RIGHT));
289
- });
290
- expect(view.state.selection.from).toBe(4);
291
- act(()=>{
292
- view.dispatchEvent(event(RIGHT));
293
- });
294
- expect(view.state.selection.head).toBe(5);
295
- expect(view.state.selection.anchor).toBe(5);
296
- act(()=>{
297
- view.dispatchEvent(event(LEFT));
298
- });
299
- expect(view.state.selection.from).toBe(4);
300
- act(()=>{
301
- view.dispatchEvent(event(LEFT));
302
- });
303
- expect(view.state.selection.head).toBe(4);
304
- expect(view.state.selection.anchor).toBe(4);
305
- });
306
- it("makes arrow motion go through selectable block nodes", async ()=>{
307
- const { view } = tempEditor({
308
- doc: doc(p("hello<a>"), hr(), ul(li(p("there"))))
309
- });
310
- act(()=>{
311
- view.dispatchEvent(event(DOWN));
312
- });
313
- expect(view.state.selection.from).toBe(7);
314
- setSel(view, 11);
315
- act(()=>{
316
- view.dispatchEvent(event(UP));
317
- });
318
- expect(view.state.selection.from).toBe(7);
319
- });
320
- it("supports arrow motion through adjacent blocks", async ()=>{
321
- const { view } = tempEditor({
322
- doc: doc(blockquote(p("hello<a>")), hr(), hr(), p("there"))
323
- });
324
- act(()=>{
325
- view.dispatchEvent(event(DOWN));
326
- });
327
- expect(view.state.selection.from).toBe(9);
328
- act(()=>{
329
- view.dispatchEvent(event(DOWN));
330
- });
331
- expect(view.state.selection.from).toBe(10);
332
- setSel(view, 14);
333
- act(()=>{
334
- view.dispatchEvent(event(UP));
335
- });
336
- expect(view.state.selection.from).toBe(10);
337
- act(()=>{
338
- view.dispatchEvent(event(UP));
339
- });
340
- expect(view.state.selection.from).toBe(9);
341
- });
342
- it("support horizontal motion through blocks", async ()=>{
343
- const { view } = tempEditor({
344
- doc: doc(p("foo<a>"), hr(), hr(), p("bar"))
345
- });
346
- act(()=>{
347
- view.dispatchEvent(event(RIGHT));
348
- });
349
- expect(view.state.selection.from).toBe(5);
350
- act(()=>{
351
- view.dispatchEvent(event(RIGHT));
352
- });
353
- expect(view.state.selection.from).toBe(6);
354
- act(()=>{
355
- view.dispatchEvent(event(RIGHT));
356
- });
357
- expect(view.state.selection.head).toBe(8);
358
- act(()=>{
359
- view.dispatchEvent(event(LEFT));
360
- });
361
- expect(view.state.selection.from).toBe(6);
362
- act(()=>{
363
- view.dispatchEvent(event(LEFT));
364
- });
365
- expect(view.state.selection.from).toBe(5);
366
- act(()=>{
367
- view.dispatchEvent(event(LEFT));
368
- });
369
- expect(view.state.selection.head).toBe(4);
370
- });
371
- it("allows moving directly from an inline node to a block node", async ()=>{
372
- const { view } = tempEditor({
373
- doc: doc(p("foo", img), hr(), p(img, "bar"))
374
- });
375
- setSel(view, NodeSelection.create(view.state.doc, 4));
376
- act(()=>{
377
- view.dispatchEvent(event(DOWN));
378
- });
379
- expect(view.state.selection.from).toBe(6);
380
- setSel(view, NodeSelection.create(view.state.doc, 8));
381
- act(()=>{
382
- view.dispatchEvent(event(UP));
383
- });
384
- expect(view.state.selection.from).toBe(6);
385
- });
386
- it("updates the selection even if the DOM parameters look unchanged", async ()=>{
387
- const { view, rerender } = tempEditor({
388
- doc: doc(p("foobar<a>"))
389
- });
390
- view.focus();
391
- const decos = DecorationSet.create(view.state.doc, [
392
- Decoration.inline(1, 4, {
393
- color: "green"
394
- })
395
- ]);
396
- rerender({
397
- decorations () {
398
- return decos;
399
- }
400
- });
401
- rerender({
402
- decorations: undefined
403
- });
404
- rerender({
405
- decorations () {
406
- return decos;
407
- }
408
- });
409
- const range = document.createRange();
410
- range.setEnd(document.getSelection().anchorNode, document.getSelection().anchorOffset);
411
- range.setStart(view.dom, 0);
412
- expect(range.toString()).toBe("foobar");
413
- });
414
- it("sets selection even if Selection.extend throws DOMException", async ()=>{
415
- const originalExtend = window.Selection.prototype.extend;
416
- window.Selection.prototype.extend = ()=>{
417
- // declare global: DOMException
418
- throw new DOMException("failed");
419
- };
420
- try {
421
- const { view } = tempEditor({
422
- doc: doc(p("foo", img), hr(), p(img, "bar"))
423
- });
424
- setSel(view, NodeSelection.create(view.state.doc, 4));
425
- act(()=>{
426
- view.dispatchEvent(event(DOWN));
427
- });
428
- expect(view.state.selection.from).toBe(6);
429
- } finally{
430
- window.Selection.prototype.extend = originalExtend;
431
- }
432
- });
433
- it("doesn't put the cursor after BR hack nodes", async ()=>{
434
- const { view } = tempEditor({
435
- doc: doc(p())
436
- });
437
- view.focus();
438
- expect(getSelection().focusOffset).toBe(0);
439
- });
440
- });