@quillmark/svelte 0.32.0 → 0.34.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.
Files changed (99) hide show
  1. package/README.md +73 -1
  2. package/THEMING.md +11 -10
  3. package/dist/core/codec/anchor.d.ts +12 -0
  4. package/dist/core/codec/anchor.js +39 -0
  5. package/dist/core/codec/drag-move.d.ts +11 -0
  6. package/dist/core/codec/drag-move.js +143 -0
  7. package/dist/core/codec/encode.d.ts +2 -1
  8. package/dist/core/codec/encode.js +16 -6
  9. package/dist/core/codec/field.d.ts +47 -1
  10. package/dist/core/codec/field.js +201 -37
  11. package/dist/core/codec/index.d.ts +8 -2
  12. package/dist/core/codec/index.js +9 -2
  13. package/dist/core/codec/islands.d.ts +4 -1
  14. package/dist/core/codec/islands.js +6 -0
  15. package/dist/core/codec/keymap.d.ts +3 -0
  16. package/dist/core/codec/keymap.js +13 -12
  17. package/dist/core/codec/leave.d.ts +17 -0
  18. package/dist/core/codec/leave.js +78 -0
  19. package/dist/core/codec/prose.css +217 -0
  20. package/dist/core/codec/review-diff.d.ts +12 -0
  21. package/dist/core/codec/review-diff.js +131 -0
  22. package/dist/core/codec/review.d.ts +131 -0
  23. package/dist/core/codec/review.js +1077 -0
  24. package/dist/core/codec/shortcuts.d.ts +20 -4
  25. package/dist/core/codec/shortcuts.js +27 -7
  26. package/dist/core/codec/slash.d.ts +3 -0
  27. package/dist/core/codec/slash.js +2 -1
  28. package/dist/core/codec/table-view.js +163 -25
  29. package/dist/core/codec/undo.d.ts +6 -0
  30. package/dist/core/codec/undo.js +25 -2
  31. package/dist/core/dragfollow.d.ts +18 -0
  32. package/dist/core/dragfollow.js +63 -0
  33. package/dist/core/theme.css +36 -7
  34. package/dist/preview/controller.js +16 -0
  35. package/dist/preview/strings.d.ts +4 -0
  36. package/dist/preview/strings.js +3 -1
  37. package/dist/visual/ArrayField.svelte +363 -57
  38. package/dist/visual/ArrayField.svelte.d.ts +5 -0
  39. package/dist/visual/BooleanField.svelte +60 -5
  40. package/dist/visual/BooleanField.svelte.d.ts +2 -1
  41. package/dist/visual/Card.svelte +27 -17
  42. package/dist/visual/CardControls.svelte +17 -7
  43. package/dist/visual/CardControls.svelte.d.ts +2 -0
  44. package/dist/visual/DateField.svelte +90 -39
  45. package/dist/visual/DateField.svelte.d.ts +2 -2
  46. package/dist/visual/Field.svelte +126 -6
  47. package/dist/visual/FieldHint.svelte +24 -9
  48. package/dist/visual/FieldLabel.svelte +128 -22
  49. package/dist/visual/FieldLabel.svelte.d.ts +9 -0
  50. package/dist/visual/FormatPopover.svelte +125 -20
  51. package/dist/visual/MatrixAdd.svelte +13 -6
  52. package/dist/visual/MatrixAdd.svelte.d.ts +3 -2
  53. package/dist/visual/MatrixField.svelte +36 -8
  54. package/dist/visual/NumberField.svelte +27 -6
  55. package/dist/visual/NumberField.svelte.d.ts +3 -0
  56. package/dist/visual/ObjectField.svelte +25 -1
  57. package/dist/visual/ObjectField.svelte.d.ts +6 -0
  58. package/dist/visual/ProseField.svelte +23 -0
  59. package/dist/visual/ProseField.svelte.d.ts +3 -0
  60. package/dist/visual/ProseValue.svelte +107 -17
  61. package/dist/visual/ProseValue.svelte.d.ts +18 -4
  62. package/dist/visual/ReviewPopover.svelte +179 -0
  63. package/dist/visual/ReviewPopover.svelte.d.ts +16 -0
  64. package/dist/visual/ReviewProposal.svelte +149 -0
  65. package/dist/visual/ReviewProposal.svelte.d.ts +15 -0
  66. package/dist/visual/ReviewRows.svelte +68 -0
  67. package/dist/visual/ReviewRows.svelte.d.ts +11 -0
  68. package/dist/visual/SlashMenu.svelte +13 -1
  69. package/dist/visual/SlashMenu.svelte.d.ts +2 -0
  70. package/dist/visual/VisualEditor.svelte +23 -0
  71. package/dist/visual/VisualEditor.svelte.d.ts +7 -0
  72. package/dist/visual/VisualEditorInner.svelte +671 -22
  73. package/dist/visual/VisualEditorInner.svelte.d.ts +7 -0
  74. package/dist/visual/controls.css +17 -2
  75. package/dist/visual/guidance.d.ts +12 -0
  76. package/dist/visual/guidance.js +37 -2
  77. package/dist/visual/icons/nodes.d.ts +14 -2
  78. package/dist/visual/icons/nodes.js +12 -1
  79. package/dist/visual/index.d.ts +6 -0
  80. package/dist/visual/index.js +2 -0
  81. package/dist/visual/listhistory.d.ts +36 -0
  82. package/dist/visual/listhistory.js +53 -0
  83. package/dist/visual/proposals.d.ts +40 -0
  84. package/dist/visual/proposals.js +219 -0
  85. package/dist/visual/props.d.ts +35 -0
  86. package/dist/visual/removed.d.ts +20 -0
  87. package/dist/visual/removed.js +30 -0
  88. package/dist/visual/review.d.ts +170 -0
  89. package/dist/visual/review.js +269 -0
  90. package/dist/visual/review.svelte.d.ts +106 -0
  91. package/dist/visual/review.svelte.js +356 -0
  92. package/dist/visual/rowdrag.svelte.js +44 -55
  93. package/dist/visual/strings.d.ts +48 -7
  94. package/dist/visual/strings.js +32 -7
  95. package/dist/visual/structure.d.ts +5 -0
  96. package/dist/visual/structure.js +1 -1
  97. package/dist/visual/undo.svelte.d.ts +40 -7
  98. package/dist/visual/undo.svelte.js +98 -25
  99. package/package.json +1 -1
@@ -1,7 +1,7 @@
1
1
  import type { Schema } from 'prosemirror-model';
2
2
  import type { Command } from 'prosemirror-state';
3
- /** Every prose leaf, a table cell included: history and the marks. `link` binds in the
4
- * formatting popover, which is the surface that prompts for the URL. */
3
+ /** Every prose leaf, a table cell included: history and the marks. `link` and `formatBar`
4
+ * bind in the formatting popover, the surface one prompts from and the other enters. */
5
5
  export declare const FIELD_KEYS: {
6
6
  readonly undo: "Mod-z";
7
7
  readonly redo: "Mod-Shift-z";
@@ -12,6 +12,7 @@ export declare const FIELD_KEYS: {
12
12
  readonly strike: "Mod-Shift-x";
13
13
  readonly code: "Mod-e";
14
14
  readonly link: "Mod-k";
15
+ readonly formatBar: "Alt-F10";
15
16
  };
16
17
  /** A multi-block body, outside any surface nested in it. */
17
18
  export declare const BODY_KEYS: {
@@ -44,10 +45,20 @@ export declare const TABLE_KEYS: {
44
45
  readonly erase: "Backspace";
45
46
  readonly eraseAlt: "Delete";
46
47
  };
48
+ /** An item of review under the caret (`review.ts`), ahead of every other binding of its keys,
49
+ * so `accept` takes a proposal over a task item's `LIST_KEYS.task`; `next` and `previous` step
50
+ * through the items from anywhere in the editor. */
51
+ export declare const REVIEW_KEYS: {
52
+ readonly accept: "Mod-Enter";
53
+ readonly dismiss: "Mod-.";
54
+ readonly next: "Mod-Alt-ArrowDown";
55
+ readonly previous: "Mod-Alt-ArrowUp";
56
+ };
47
57
  /** The mark toggles, each bound only where the schema declares its mark. */
48
58
  export declare function markKeymap(schema: Schema): Record<string, Command>;
49
- /** Where a shortcut answers: any prose field, a multi-block body, a list item, a table cell. */
50
- export type ShortcutScope = 'field' | 'body' | 'list' | 'table';
59
+ /** Where a shortcut answers: any prose field, a multi-block body, a list item, a table cell, an
60
+ * item of review. */
61
+ export type ShortcutScope = 'field' | 'body' | 'list' | 'table' | 'review';
51
62
  /** One shortcut as a host lists it. `keys` are the alternatives in `prosemirror-keymap`
52
63
  * notation (`Mod-Shift-7`, `Alt-ArrowUp`): `Mod` is ⌘ on Apple platforms and Ctrl
53
64
  * elsewhere, and the host prints them. */
@@ -66,6 +77,7 @@ export interface ShortcutStrings {
66
77
  shortcutStrikethrough: string;
67
78
  shortcutCode: string;
68
79
  shortcutLink: string;
80
+ shortcutFormatBar: string;
69
81
  shortcutLineBreak: string;
70
82
  shortcutLeave: string;
71
83
  shortcutNumberedList: string;
@@ -82,6 +94,10 @@ export interface ShortcutStrings {
82
94
  shortcutMoveLine: string;
83
95
  shortcutAlignColumn: string;
84
96
  shortcutDeleteCells: string;
97
+ shortcutReviewAccept: string;
98
+ shortcutReviewDismiss: string;
99
+ shortcutReviewNext: string;
100
+ shortcutReviewPrevious: string;
85
101
  }
86
102
  export declare const DEFAULT_SHORTCUT_STRINGS: ShortcutStrings;
87
103
  /**
@@ -6,8 +6,8 @@
6
6
  // body's Tab hold, a code fence's Tab) is not a shortcut a writer looks up, and stays a
7
7
  // literal in its keymap.
8
8
  import { toggleMark } from 'prosemirror-commands';
9
- /** Every prose leaf, a table cell included: history and the marks. `link` binds in the
10
- * formatting popover, which is the surface that prompts for the URL. */
9
+ /** Every prose leaf, a table cell included: history and the marks. `link` and `formatBar`
10
+ * bind in the formatting popover, the surface one prompts from and the other enters. */
11
11
  export const FIELD_KEYS = {
12
12
  undo: 'Mod-z',
13
13
  redo: 'Mod-Shift-z',
@@ -17,7 +17,8 @@ export const FIELD_KEYS = {
17
17
  underline: 'Mod-u',
18
18
  strike: 'Mod-Shift-x',
19
19
  code: 'Mod-e',
20
- link: 'Mod-k'
20
+ link: 'Mod-k',
21
+ formatBar: 'Alt-F10'
21
22
  };
22
23
  /** A multi-block body, outside any surface nested in it. */
23
24
  export const BODY_KEYS = {
@@ -50,6 +51,15 @@ export const TABLE_KEYS = {
50
51
  erase: 'Backspace',
51
52
  eraseAlt: 'Delete'
52
53
  };
54
+ /** An item of review under the caret (`review.ts`), ahead of every other binding of its keys,
55
+ * so `accept` takes a proposal over a task item's `LIST_KEYS.task`; `next` and `previous` step
56
+ * through the items from anywhere in the editor. */
57
+ export const REVIEW_KEYS = {
58
+ accept: 'Mod-Enter',
59
+ dismiss: 'Mod-.',
60
+ next: 'Mod-Alt-ArrowDown',
61
+ previous: 'Mod-Alt-ArrowUp'
62
+ };
53
63
  /** The mark toggles, each bound only where the schema declares its mark. */
54
64
  export function markKeymap(schema) {
55
65
  const map = {};
@@ -74,13 +84,14 @@ export const DEFAULT_SHORTCUT_STRINGS = {
74
84
  shortcutStrikethrough: 'Strikethrough',
75
85
  shortcutCode: 'Code',
76
86
  shortcutLink: 'Link',
87
+ shortcutFormatBar: 'Move to the format bar over a selection',
77
88
  shortcutLineBreak: 'Line break within a paragraph',
78
- shortcutLeave: 'Leave the editor',
89
+ shortcutLeave: 'Let Tab leave the editor',
79
90
  shortcutNumberedList: 'Numbered list',
80
91
  shortcutBulletedList: 'Bulleted list',
81
92
  shortcutIndent: 'Nest under the item above',
82
93
  shortcutOutdent: 'Move back up a level',
83
- shortcutTask: 'Check or uncheck a task',
94
+ shortcutTask: 'Check or uncheck a task, outside a proposal',
84
95
  shortcutMoveItem: 'Move the item up or down',
85
96
  shortcutNextCell: 'Next cell, adding a row past the last',
86
97
  shortcutPreviousCell: 'Previous cell',
@@ -89,7 +100,11 @@ export const DEFAULT_SHORTCUT_STRINGS = {
89
100
  shortcutSelectRow: 'Select the row, then the table',
90
101
  shortcutMoveLine: 'Move a selected row or column',
91
102
  shortcutAlignColumn: 'Align a selected column',
92
- shortcutDeleteCells: 'Delete the selected cells, rows or columns'
103
+ shortcutDeleteCells: 'Delete the selected cells, rows or columns',
104
+ shortcutReviewAccept: 'Accept the proposed change',
105
+ shortcutReviewDismiss: 'Dismiss the proposed change, or undo the change made',
106
+ shortcutReviewNext: 'Go to the next review item',
107
+ shortcutReviewPrevious: 'Go to the previous review item'
93
108
  };
94
109
  const F = FIELD_KEYS;
95
110
  const L = LIST_KEYS;
@@ -104,6 +119,7 @@ const SHORTCUTS = [
104
119
  { scope: 'field', label: 'shortcutStrikethrough', keys: [F.strike] },
105
120
  { scope: 'field', label: 'shortcutCode', keys: [F.code] },
106
121
  { scope: 'field', label: 'shortcutLink', keys: [F.link] },
122
+ { scope: 'field', label: 'shortcutFormatBar', keys: [F.formatBar] },
107
123
  { scope: 'body', label: 'shortcutLineBreak', keys: [BODY_KEYS.lineBreak] },
108
124
  { scope: 'body', label: 'shortcutLeave', keys: [BODY_KEYS.leave] },
109
125
  { scope: 'list', label: 'shortcutNumberedList', keys: [L.numbered] },
@@ -123,7 +139,11 @@ const SHORTCUTS = [
123
139
  keys: [T.moveUp, T.moveDown, T.moveLeft, T.moveRight]
124
140
  },
125
141
  { scope: 'table', label: 'shortcutAlignColumn', keys: [T.alignLeft, T.alignRight] },
126
- { scope: 'table', label: 'shortcutDeleteCells', keys: [T.erase, T.eraseAlt] }
142
+ { scope: 'table', label: 'shortcutDeleteCells', keys: [T.erase, T.eraseAlt] },
143
+ { scope: 'review', label: 'shortcutReviewAccept', keys: [REVIEW_KEYS.accept] },
144
+ { scope: 'review', label: 'shortcutReviewDismiss', keys: [REVIEW_KEYS.dismiss] },
145
+ { scope: 'review', label: 'shortcutReviewNext', keys: [REVIEW_KEYS.next] },
146
+ { scope: 'review', label: 'shortcutReviewPrevious', keys: [REVIEW_KEYS.previous] }
127
147
  ];
128
148
  /**
129
149
  * The rich editor's shortcuts, worded by `strings` (the package's English where a key is unset),
@@ -27,6 +27,9 @@ export interface SlashStrings {
27
27
  slashHint: string;
28
28
  /** A command's row name, by its token: `numbered-list` → `Numbered list`. */
29
29
  slashName: (command: string) => string;
30
+ /** What the menu announces as its highlight moves, the caret never leaving the text:
31
+ * the row's name and its 1-based place, `Table, 6 of 6`. */
32
+ slashPosition: (name: string, index: number, count: number) => string;
30
33
  }
31
34
  /** The package's English, beside the surface that draws it; the visual `strings` set extends it. */
32
35
  export declare const DEFAULT_SLASH_STRINGS: SlashStrings;
@@ -17,7 +17,8 @@ const SLASH_NAMES = {
17
17
  export const DEFAULT_SLASH_STRINGS = {
18
18
  slashLabel: 'Insert',
19
19
  slashHint: 'Type / to insert',
20
- slashName: (command) => SLASH_NAMES[command] ?? command.charAt(0).toUpperCase() + command.slice(1).replace(/-/g, ' ')
20
+ slashName: (command) => SLASH_NAMES[command] ?? command.charAt(0).toUpperCase() + command.slice(1).replace(/-/g, ' '),
21
+ slashPosition: (name, index, count) => `${name}, ${index} of ${count}`
21
22
  };
22
23
  /**
23
24
  * The vocabulary a caret can run, in menu order, each name asked whether it would fire here: a row
@@ -18,11 +18,14 @@ import { decode } from './decode.js';
18
18
  import { FIELD_KEYS, markKeymap, TABLE_KEYS as T } from './shortcuts.js';
19
19
  import { inputRulesPlugin, undoRuleKeymap } from './inputrules.js';
20
20
  import { linkPastePlugin } from './link-paste.js';
21
+ import { dragMovePlugin } from './drag-move.js';
22
+ import { TYPING } from './undo.js';
21
23
  import { tableOfNode } from './table.js';
22
24
  import { tableElement, tableText } from './table-copy.js';
23
25
  import { breakKeymap } from './breaks.js';
24
26
  import { cellSchema } from './schema.js';
25
27
  import { revealProps } from './reveal.js';
28
+ import { followDrag } from '../dragfollow.js';
26
29
  import { ALIGNS, canMerge, cellAt, closeBlock, cellContent, cellEqual, cellFromDoc, clearCells, columnCount, deleteColumn, deleteRow, insertColumn, insertRow, mergeCells, moveColumn, moveRow, normalizeTable, rowCells, rowCount, rowEmpty, setAlign, setHead, headRows, columnShares, setWidths, shapeEqual, spanGrid, splitCell, withCell, islandOf } from './table.js';
27
30
  /**
28
31
  * The package's English for the island chrome. It lives beside the surface that draws it so a
@@ -126,11 +129,12 @@ function chromeButton(className, label, run) {
126
129
  }
127
130
  /** A cell's plugin stack: marks, the markdown shorthands and a pasted URL's link, and
128
131
  * nothing that belongs to the field (history, anchors, the ghost). */
129
- function cellPlugins(keys) {
132
+ function cellPlugins(keys, outer) {
130
133
  return [
131
134
  inputRulesPlugin(cellSchema),
132
135
  undoRuleKeymap(),
133
136
  linkPastePlugin(cellSchema.marks.link),
137
+ dragMovePlugin(outer),
134
138
  keymap(keys),
135
139
  keymap(baseKeymap)
136
140
  ];
@@ -144,6 +148,8 @@ const CONTROLS = '.qm-table-grip, .qm-table-add, .qm-table-align, .qm-table-resi
144
148
  /** What the nested views and the band answer for themselves, which is what `stopEvent`
145
149
  * keeps from PM. */
146
150
  const OWNED = `.qm-table-cell-host, ${CONTROLS}`;
151
+ /** The drops a table dispatched again over a cell's text, which it lets through. */
152
+ const redropped = new WeakSet();
147
153
  /** How far a press travels before it is a drag rather than a click. */
148
154
  const DEAD_ZONE = 3;
149
155
  /** A line's key in the grip registry, spelled once. */
@@ -222,6 +228,9 @@ class TableIslandView {
222
228
  resize;
223
229
  /** A drag's trailing `click`, which would otherwise re-select the moved line. */
224
230
  suppressClick = false;
231
+ /** The seat the last cell edit was typed in, so the next keystroke there joins its undo
232
+ * step; any other write clears it. */
233
+ typedIn;
225
234
  /** The grips of the row and column under the pointer, drawn up. */
226
235
  near = [];
227
236
  constructor(node, outer, getPos, deps) {
@@ -236,6 +245,7 @@ class TableIslandView {
236
245
  this.dom.addEventListener('mouseover', this.onHover);
237
246
  this.dom.addEventListener('mouseleave', this.onLeave);
238
247
  this.dom.addEventListener('copy', this.onCopy, true);
248
+ this.dom.addEventListener('drop', this.onDrop, true);
239
249
  this.render();
240
250
  }
241
251
  // ── PM's NodeView contract ────────────────────────────────────────────────
@@ -263,7 +273,7 @@ class TableIslandView {
263
273
  const head = mounted.view.state.selection.head;
264
274
  const fresh = EditorState.create({
265
275
  doc: decode(cellContent(stored), cellSchema),
266
- plugins: cellPlugins(this.cellKeys(mounted.r, mounted.c))
276
+ plugins: cellPlugins(this.cellKeys(mounted.r, mounted.c), () => this.outer)
267
277
  });
268
278
  mounted.view.updateState(fresh);
269
279
  mounted.shown = stored;
@@ -299,6 +309,7 @@ class TableIslandView {
299
309
  this.dom.removeEventListener('mouseover', this.onHover);
300
310
  this.dom.removeEventListener('mouseleave', this.onLeave);
301
311
  this.dom.removeEventListener('copy', this.onCopy, true);
312
+ this.dom.removeEventListener('drop', this.onDrop, true);
302
313
  this.endDrag();
303
314
  this.endSweep();
304
315
  this.endResize();
@@ -346,8 +357,11 @@ class TableIslandView {
346
357
  event.preventDefault();
347
358
  event.stopPropagation();
348
359
  const grid = this.dom.querySelector('.qm-table');
349
- if (grid && within(grid.getBoundingClientRect(), point))
350
- this.focusNearestCell(point);
360
+ if (grid && within(grid.getBoundingClientRect(), point)) {
361
+ const nearest = this.nearestCell(point);
362
+ if (nearest)
363
+ this.focusCell(nearest.r, nearest.c);
364
+ }
351
365
  else
352
366
  this.caretBeside(point);
353
367
  };
@@ -390,11 +404,74 @@ class TableIslandView {
390
404
  event.stopPropagation();
391
405
  };
392
406
  /**
393
- * The cell a press inside the frame belongs to: the nearest by rect. Row cells share a vertical
407
+ * A drop anywhere in a cell's box lands in that cell, at the text nearest the pointer, as a
408
+ * press there does. The cell's padding is the table's, and the editor's own padding resolves
409
+ * to a place between blocks no text fits, so left alone the first drop lands in the field
410
+ * beside the table and the second nowhere. The drop is dispatched again over the cell's text, so the cell's view runs
411
+ * its whole drop, a move's delete in the leaf it came from included. Captured, ahead of both
412
+ * views.
413
+ */
414
+ onDrop = (event) => {
415
+ if (redropped.has(event) || !this.rendered)
416
+ return;
417
+ // A file is the editor root's to refuse.
418
+ if (event.dataTransfer?.types.includes('Files'))
419
+ return;
420
+ const target = event.target;
421
+ if (target?.closest?.(CONTROLS))
422
+ return;
423
+ const point = { x: event.clientX, y: event.clientY };
424
+ const box = target?.closest?.('.qm-table-cell');
425
+ const grid = this.dom.querySelector('.qm-table');
426
+ const cell = box
427
+ ? this.cells.find((m) => m.box === box)
428
+ : grid && within(grid.getBoundingClientRect(), point)
429
+ ? this.nearestCell(point)
430
+ : undefined;
431
+ if (!cell)
432
+ return;
433
+ const { view } = cell;
434
+ if (target && view.dom.contains(target)) {
435
+ const over = view.posAtCoords({ left: point.x, top: point.y });
436
+ if (over && view.state.doc.resolve(over.pos).parent.inlineContent)
437
+ return;
438
+ }
439
+ let line;
440
+ let nearest = Infinity;
441
+ for (const block of view.dom.children) {
442
+ const at = distance(block.getBoundingClientRect(), point);
443
+ if (at < nearest)
444
+ [line, nearest] = [block, at];
445
+ }
446
+ if (!line)
447
+ return;
448
+ const rect = line.getBoundingClientRect();
449
+ const x = Math.min(Math.max(point.x, rect.left + 1), rect.right - 1);
450
+ const y = Math.min(Math.max(point.y, rect.top + 1), rect.bottom - 1);
451
+ event.preventDefault();
452
+ event.stopPropagation();
453
+ const again = new DragEvent('drop', {
454
+ bubbles: true,
455
+ cancelable: true,
456
+ clientX: x,
457
+ clientY: y,
458
+ screenX: event.screenX + x - point.x,
459
+ screenY: event.screenY + y - point.y,
460
+ dataTransfer: event.dataTransfer,
461
+ altKey: event.altKey,
462
+ ctrlKey: event.ctrlKey,
463
+ metaKey: event.metaKey,
464
+ shiftKey: event.shiftKey
465
+ });
466
+ redropped.add(again);
467
+ line.dispatchEvent(again);
468
+ };
469
+ /**
470
+ * The cell a point inside the frame belongs to: the nearest by rect. Row cells share a vertical
394
471
  * extent and column cells a horizontal one, so the nearest cell is the nearest row crossed with
395
472
  * the nearest column: R+C rects rather than R×C (27 layouts a press at 20x8, not 160).
396
473
  */
397
- focusNearestCell(point) {
474
+ nearestCell(point) {
398
475
  let row;
399
476
  let column;
400
477
  let nearestRow = Infinity;
@@ -418,8 +495,9 @@ class TableIslandView {
418
495
  }
419
496
  }
420
497
  }
421
- if (row !== undefined && column !== undefined)
422
- this.focusCell(row, column);
498
+ if (row === undefined || column === undefined)
499
+ return undefined;
500
+ return this.cells.find((m) => covers(m, row, column));
423
501
  }
424
502
  /**
425
503
  * A caret beside the island, on the side the press landed: a gap cursor where the document
@@ -793,7 +871,9 @@ class TableIslandView {
793
871
  this.drag = {
794
872
  line,
795
873
  origin: { x: event.clientX, y: event.clientY },
874
+ at: line.axis === 'row' ? event.clientY : event.clientX,
796
875
  engaged: false,
876
+ cancelled: false,
797
877
  drop: line.index,
798
878
  painted: -1,
799
879
  pointerId: event.pointerId,
@@ -810,23 +890,47 @@ class TableIslandView {
810
890
  };
811
891
  onGripMove = (event) => {
812
892
  const drag = this.drag;
813
- if (!drag)
893
+ if (!drag || drag.cancelled)
814
894
  return;
815
895
  const travel = Math.hypot(event.clientX - drag.origin.x, event.clientY - drag.origin.y);
816
896
  if (!drag.engaged && travel < DEAD_ZONE)
817
897
  return;
898
+ drag.at = drag.line.axis === 'row' ? event.clientY : event.clientX;
818
899
  if (!drag.engaged)
819
900
  this.engage(drag);
820
- drag.drop = this.dropIndex(drag, drag.line.axis === 'row' ? event.clientY : event.clientX);
901
+ drag.drop = this.dropIndex(drag, drag.at);
821
902
  this.paintDrop(drag);
822
903
  };
823
- /** The drag becomes one: lift the line, and measure the table once. */
904
+ /** The drag becomes one: lift the line, measure the table, and follow what scrolls under it. */
824
905
  engage(drag) {
825
906
  drag.engaged = true;
907
+ addEventListener('keydown', this.onDragKey, true);
826
908
  this.dom.classList.add('qm-table-dragging');
827
909
  drag.grip.classList.add('qm-table-lifted');
828
910
  for (const cell of this.boxesOf(drag.line))
829
911
  cell.classList.add('qm-table-lifted');
912
+ this.measure(drag);
913
+ drag.unfollow = followDrag({
914
+ grip: drag.grip,
915
+ axis: drag.line.axis === 'row' ? 'y' : 'x',
916
+ at: () => drag.at,
917
+ extent: () => drag.lines.length
918
+ ? { start: drag.lines[0].start, end: drag.lines[drag.lines.length - 1].end }
919
+ : undefined,
920
+ moved: () => {
921
+ if (this.drag !== drag || drag.cancelled)
922
+ return;
923
+ this.measure(drag);
924
+ drag.drop = this.dropIndex(drag, drag.at);
925
+ drag.painted = -1;
926
+ this.paintDrop(drag);
927
+ },
928
+ lost: () => this.drag === drag && this.endDrag()
929
+ });
930
+ }
931
+ /** Each line's extent where it stands now. */
932
+ measure(drag) {
933
+ drag.lines = [];
830
934
  const frame = this.frame;
831
935
  if (!frame)
832
936
  return;
@@ -855,7 +959,7 @@ class TableIslandView {
855
959
  const drag = this.drag;
856
960
  if (!drag)
857
961
  return;
858
- const { line, drop, engaged } = drag;
962
+ const { line, drop, engaged, cancelled } = drag;
859
963
  this.endDrag();
860
964
  if (!engaged)
861
965
  return;
@@ -866,21 +970,41 @@ class TableIslandView {
866
970
  // The press that ends a drag must not re-select the line it just moved off, so the
867
971
  // following click is swallowed.
868
972
  this.suppressClick = true;
973
+ if (cancelled)
974
+ return;
869
975
  if (drop !== line.index)
870
976
  this.moveLine(line, drop - line.index);
871
977
  else
872
978
  this.selectLine(line);
873
979
  };
874
- endDrag() {
980
+ /**
981
+ * Escape over an engaged drag drops the lift and the drop rule. The grip keeps the pointer, so
982
+ * the release still arrives here and swallows its click.
983
+ */
984
+ onDragKey = (event) => {
875
985
  const drag = this.drag;
876
- if (!drag)
986
+ if (event.key !== 'Escape' || !drag?.engaged || drag.cancelled)
877
987
  return;
878
- this.drag = undefined;
988
+ event.preventDefault();
989
+ event.stopPropagation();
990
+ drag.cancelled = true;
991
+ this.unlift();
992
+ };
993
+ unlift() {
994
+ this.drag?.unfollow?.();
995
+ removeEventListener('keydown', this.onDragKey, true);
879
996
  this.dropMark?.remove();
880
997
  this.dropMark = undefined;
881
998
  this.dom.classList.remove('qm-table-dragging');
882
999
  for (const lifted of this.dom.querySelectorAll('.qm-table-lifted'))
883
1000
  lifted.classList.remove('qm-table-lifted');
1001
+ }
1002
+ endDrag() {
1003
+ const drag = this.drag;
1004
+ if (!drag)
1005
+ return;
1006
+ this.unlift();
1007
+ this.drag = undefined;
884
1008
  drag.grip.removeEventListener('pointermove', this.onGripMove);
885
1009
  drag.grip.removeEventListener('pointerup', this.onGripUp);
886
1010
  drag.grip.removeEventListener('pointercancel', this.onGripUp);
@@ -888,20 +1012,24 @@ class TableIslandView {
888
1012
  drag.grip.releasePointerCapture(drag.pointerId);
889
1013
  }
890
1014
  /**
891
- * Which line the pointer is over along the drag's axis: the nearest by the extents measured at
892
- * engage. One dimension suffices: the cross-axis term is identical across the candidates.
1015
+ * Which line the pointer is over along the drag's axis: the nearest by the extents last
1016
+ * measured, within that line's own extent past either end of the table, and the drag's own
1017
+ * line, so no move, further out than that. One dimension suffices: the cross-axis term is
1018
+ * identical across the candidates.
893
1019
  */
894
1020
  dropIndex(drag, at) {
895
1021
  let best = drag.line.index;
896
1022
  let nearest = Infinity;
1023
+ let reach = 0;
897
1024
  for (const line of drag.lines) {
898
1025
  const gap = at < line.start ? line.start - at : at > line.end ? at - line.end : 0;
899
1026
  if (gap >= nearest)
900
1027
  continue;
901
1028
  nearest = gap;
902
1029
  best = line.index;
1030
+ reach = line.end - line.start;
903
1031
  }
904
- return best;
1032
+ return nearest > reach ? drag.line.index : best;
905
1033
  }
906
1034
  boxesOf(line) {
907
1035
  const props = this.props();
@@ -909,11 +1037,17 @@ class TableIslandView {
909
1037
  }
910
1038
  /**
911
1039
  * The drop indicator: one rule on the boundary the line would land against, redrawn only when
912
- * the boundary changes.
1040
+ * the boundary changes, and none while the release would leave the line where it stands.
913
1041
  */
914
1042
  paintDrop(drag) {
915
1043
  if (drag.drop === drag.painted)
916
1044
  return;
1045
+ if (drag.drop === drag.line.index) {
1046
+ drag.painted = drag.drop;
1047
+ this.dropMark?.remove();
1048
+ this.dropMark = undefined;
1049
+ return;
1050
+ }
917
1051
  const line = drag.lines.find((l) => l.index === drag.drop);
918
1052
  const frame = this.frame;
919
1053
  if (!line || !frame)
@@ -1332,7 +1466,7 @@ class TableIslandView {
1332
1466
  const view = new EditorView(host, {
1333
1467
  state: EditorState.create({
1334
1468
  doc: decode(cellContent(seed), cellSchema),
1335
- plugins: cellPlugins(this.cellKeys(r, c))
1469
+ plugins: cellPlugins(this.cellKeys(r, c), () => this.outer)
1336
1470
  }),
1337
1471
  attributes: { 'aria-label': name, class: 'qm-table-cell-editor' },
1338
1472
  // A cell is one of the leaf's lines, so a reveal keeps the leaf's clearance, not PM's
@@ -1351,7 +1485,7 @@ class TableIslandView {
1351
1485
  const now = this.props();
1352
1486
  const cell = cellFromDoc(next.doc, cellAt(now, r, c));
1353
1487
  mounted.shown = cell;
1354
- this.write(withCell(now, r, c, cell), undefined, from);
1488
+ this.write(withCell(now, r, c, cell), undefined, from, `${r}:${c}`);
1355
1489
  },
1356
1490
  handleDOMEvents: {
1357
1491
  focus: () => {
@@ -1389,9 +1523,9 @@ class TableIslandView {
1389
1523
  /**
1390
1524
  * Commit a new rectangle onto the node. `setNodeMarkup` is an ordinary PM transaction, so the
1391
1525
  * field lowers it through the island channel: one commit, one undo step, which is why every op
1392
- * writes a whole table.
1526
+ * writes a whole table. A run of keystrokes in one cell (`typedIn` its seat) is one step.
1393
1527
  */
1394
- write(next, focus, from = this.focusedSeat()) {
1528
+ write(next, focus, from = this.focusedSeat(), typedIn) {
1395
1529
  const pos = this.getPos();
1396
1530
  if (pos == null)
1397
1531
  return;
@@ -1401,10 +1535,14 @@ class TableIslandView {
1401
1535
  const left = valueKey(node);
1402
1536
  if (left && from)
1403
1537
  departures.set(left, from);
1404
- this.outer.dispatch(this.outer.state.tr.setNodeMarkup(pos, undefined, {
1538
+ const tr = this.outer.state.tr.setNodeMarkup(pos, undefined, {
1405
1539
  ...node.attrs,
1406
1540
  ...islandOf(next)
1407
- }));
1541
+ });
1542
+ if (typedIn !== undefined && typedIn === this.typedIn)
1543
+ tr.setMeta(TYPING, true);
1544
+ this.typedIn = typedIn;
1545
+ this.outer.dispatch(tr);
1408
1546
  if (focus)
1409
1547
  this.focusCell(focus.r, focus.c);
1410
1548
  }
@@ -1,4 +1,10 @@
1
1
  import { Plugin } from 'prosemirror-state';
2
+ /** The meta on a transaction that goes on typing in the island cell the last one typed in. */
3
+ export declare const TYPING = "qmTyping";
4
+ /** Run `dispatch` with every transaction it lands in a leaf joined to that leaf's last
5
+ * undo step, as one a plugin appended to it is: neither history's delay nor the distance
6
+ * between the two edits opens a new one. */
7
+ export declare function joinStep(dispatch: () => void): void;
2
8
  /** Marks each block-moving transaction as the start of an undo step. `filterTransaction`
3
9
  * is the one hook that sees a transaction before history's `apply` does; it passes
4
10
  * every one. A transaction a plugin appended stays in its root's step. */
@@ -1,23 +1,46 @@
1
1
  // Undo steps. History groups a run of adjacent edits under its delay, so a burst of
2
2
  // typing with a list change in it would undo as one step. A transaction that moves a
3
3
  // block (`mayNest`: a split, a join, a wrap, a lift) opens a step of its own, the typing
4
- // after it joining that step.
4
+ // after it joining that step. A table cell's keystroke rewrites its island node, which reads
5
+ // as a block move, so it carries {@link TYPING} and joins the step the cell's typing is in.
6
+ // A gesture that lands as two transactions in one leaf, a drag between a table cell and the
7
+ // leaf its island stands in, runs its second under {@link joinStep} and undoes as one step.
5
8
  import { closeHistory, isHistoryTransaction } from 'prosemirror-history';
6
9
  import { Plugin } from 'prosemirror-state';
7
10
  import { mayNest } from './nesting.js';
8
11
  import { isRemote } from './remote.js';
12
+ /** The meta on a transaction that goes on typing in the island cell the last one typed in. */
13
+ export const TYPING = 'qmTyping';
14
+ let joining = false;
15
+ /** Run `dispatch` with every transaction it lands in a leaf joined to that leaf's last
16
+ * undo step, as one a plugin appended to it is: neither history's delay nor the distance
17
+ * between the two edits opens a new one. */
18
+ export function joinStep(dispatch) {
19
+ joining = true;
20
+ try {
21
+ dispatch();
22
+ }
23
+ finally {
24
+ joining = false;
25
+ }
26
+ }
9
27
  /** Marks each block-moving transaction as the start of an undo step. `filterTransaction`
10
28
  * is the one hook that sees a transaction before history's `apply` does; it passes
11
29
  * every one. A transaction a plugin appended stays in its root's step. */
12
30
  export function undoStepPlugin() {
13
31
  return new Plugin({
14
32
  filterTransaction: (tr) => {
33
+ // The meta history reads to keep a transaction in the step before it. It names the
34
+ // transaction appended to, of which history asks only whether it was a history
35
+ // step: this one is not.
36
+ if (joining && tr.docChanged && !isHistoryTransaction(tr))
37
+ tr.setMeta('appendedTransaction', tr);
15
38
  if (!tr.docChanged ||
16
39
  isHistoryTransaction(tr) ||
17
40
  isRemote(tr) ||
18
41
  tr.getMeta('appendedTransaction'))
19
42
  return true;
20
- if (mayNest(tr))
43
+ if (mayNest(tr) && !tr.getMeta(TYPING))
21
44
  closeHistory(tr);
22
45
  return true;
23
46
  }
@@ -0,0 +1,18 @@
1
+ export interface DragFollowOptions {
2
+ /** The handle the drag holds. One that leaves the DOM ends the follow as {@link lost}. */
3
+ grip: Element;
4
+ /** The axis the lines stack along: the one the drag scrolls. */
5
+ axis: 'x' | 'y';
6
+ /** The pointer along the axis, in client pixels. */
7
+ at(): number;
8
+ /** The lines' whole extent along the axis, where they stand now. */
9
+ extent(): {
10
+ start: number;
11
+ end: number;
12
+ } | undefined;
13
+ /** The lines moved under the pointer: pick the drop again. */
14
+ moved(): void;
15
+ lost(): void;
16
+ }
17
+ /** Follow an engaged drag until the returned stop is called. */
18
+ export declare function followDrag(o: DragFollowOptions): () => void;