@quillmark/svelte 0.29.2 → 0.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/THEMING.md +8 -6
- package/dist/core/address.d.ts +3 -3
- package/dist/core/address.js +1 -1
- package/dist/core/bloom.d.ts +3 -2
- package/dist/core/bloom.js +6 -7
- package/dist/core/codec/decode.d.ts +1 -3
- package/dist/core/codec/decode.js +145 -206
- package/dist/core/codec/encode.d.ts +13 -35
- package/dist/core/codec/encode.js +127 -408
- package/dist/core/codec/field.d.ts +9 -9
- package/dist/core/codec/field.js +87 -80
- package/dist/core/codec/index.d.ts +2 -5
- package/dist/core/codec/index.js +4 -4
- package/dist/core/codec/inputrules.d.ts +0 -3
- package/dist/core/codec/inputrules.js +1 -1
- package/dist/core/codec/islands.d.ts +13 -19
- package/dist/core/codec/islands.js +55 -50
- package/dist/core/codec/list-move.d.ts +0 -3
- package/dist/core/codec/list-move.js +2 -2
- package/dist/core/codec/list-node.d.ts +2 -0
- package/dist/core/codec/list-node.js +1 -0
- package/dist/core/codec/list-paste.js +1 -1
- package/dist/core/codec/markdown-paste.d.ts +0 -9
- package/dist/core/codec/markdown-paste.js +1 -1
- package/dist/core/codec/marks.d.ts +12 -18
- package/dist/core/codec/marks.js +16 -26
- package/dist/core/codec/nesting.d.ts +0 -4
- package/dist/core/codec/nesting.js +1 -1
- package/dist/core/codec/positions.d.ts +14 -7
- package/dist/core/codec/positions.js +43 -50
- package/dist/core/codec/prose.css +1 -1
- package/dist/core/codec/reveal.d.ts +14 -0
- package/dist/core/codec/reveal.js +40 -0
- package/dist/core/codec/schema.d.ts +1 -1
- package/dist/core/codec/schema.js +26 -8
- package/dist/core/codec/slash.js +0 -0
- package/dist/core/codec/table-copy.d.ts +3 -3
- package/dist/core/codec/table-copy.js +6 -4
- package/dist/core/codec/table-paste.js +13 -9
- package/dist/core/codec/table-view.js +22 -15
- package/dist/core/codec/table.d.ts +77 -49
- package/dist/core/codec/table.js +158 -49
- package/dist/core/codec/touching.d.ts +0 -2
- package/dist/core/codec/touching.js +1 -11
- package/dist/preview/Preview.svelte +20 -1
- package/dist/preview/Preview.svelte.d.ts +1 -0
- package/dist/preview/controller.d.ts +5 -0
- package/dist/preview/controller.js +6 -0
- package/dist/preview/viewport.js +19 -1
- package/dist/preview/wash.d.ts +9 -0
- package/dist/preview/wash.js +38 -0
- package/dist/visual/ArrayField.svelte +18 -115
- package/dist/visual/FormatPopover.svelte +1 -1
- package/dist/visual/MatrixField.svelte +15 -19
- package/dist/visual/ObjectField.svelte +10 -13
- package/dist/visual/ProseValue.svelte +8 -8
- package/dist/visual/VisualEditorInner.svelte +17 -11
- package/dist/visual/guidance.d.ts +0 -12
- package/dist/visual/guidance.js +2 -2
- package/dist/visual/leaves.d.ts +1 -1
- package/dist/visual/leaves.js +1 -1
- package/dist/visual/props.d.ts +2 -2
- package/dist/visual/rowdrag.svelte.d.ts +21 -0
- package/dist/visual/rowdrag.svelte.js +118 -0
- package/dist/visual/structure.d.ts +6 -6
- package/dist/visual/structure.js +18 -21
- package/package.json +2 -2
- package/dist/visual/checklists.d.ts +0 -3
- package/dist/visual/checklists.js +0 -7
package/dist/core/codec/table.js
CHANGED
|
@@ -1,10 +1,113 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { contentEdit, pmToContent } from './encode.js';
|
|
1
|
+
import { pmToContent } from './encode.js';
|
|
2
|
+
import { HARD_BREAK, isTableProps } from './islands.js';
|
|
4
3
|
import { valueEqual } from './reconcile.js';
|
|
5
4
|
/** The alignments a column can take: the four the content declares, `none` first
|
|
6
5
|
* because it is what a column arrives at and what a set is cleared back to. */
|
|
7
6
|
export const ALIGNS = ['none', 'left', 'center', 'right'];
|
|
7
|
+
const TABLE_KEYS = new Set(['columns', 'rows', 'head', 'aligns', 'widths', 'align', 'cell_attrs']);
|
|
8
|
+
/** The grid a table island spells, each cell its slot's content and its ids. */
|
|
9
|
+
export function gridOf(props, slots) {
|
|
10
|
+
const attrs = props.cell_attrs ?? {};
|
|
11
|
+
const cells = props.rows.map((row) => props.columns.map((column) => {
|
|
12
|
+
const slot = row.cells[column] ?? '';
|
|
13
|
+
const content = slots?.[slot];
|
|
14
|
+
return {
|
|
15
|
+
...attrs[slot],
|
|
16
|
+
text: content?.text ?? '',
|
|
17
|
+
marks: content?.marks ?? [],
|
|
18
|
+
...(content?.anchors?.length && { anchors: content.anchors }),
|
|
19
|
+
ids: { row: row.id, column, slot, block: content?.blocks[0]?.id ?? 'b0' }
|
|
20
|
+
};
|
|
21
|
+
}));
|
|
22
|
+
const extra = Object.fromEntries(Object.entries(props).filter(([k]) => !TABLE_KEYS.has(k)));
|
|
23
|
+
const [header = [], ...rows] = cells;
|
|
24
|
+
return normalizeTable({
|
|
25
|
+
header,
|
|
26
|
+
rows,
|
|
27
|
+
aligns: props.columns.map((c) => props.aligns?.[c] ?? 'none'),
|
|
28
|
+
...(props.widths && {
|
|
29
|
+
widths: props.widths && props.columns.map((c) => props.widths?.[c] ?? null)
|
|
30
|
+
}),
|
|
31
|
+
...(props.align && { align: props.align }),
|
|
32
|
+
...(props.head !== undefined && { head: props.head }),
|
|
33
|
+
...(Object.keys(extra).length && { extra })
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/** A node's grid, or `undefined` for any other island and for a payload of the wrong shape. */
|
|
37
|
+
export function tableOfNode(node) {
|
|
38
|
+
const attrs = node.attrs;
|
|
39
|
+
return attrs.islandType === 'table' && isTableProps(attrs.props)
|
|
40
|
+
? gridOf(attrs.props, attrs.slots)
|
|
41
|
+
: undefined;
|
|
42
|
+
}
|
|
43
|
+
/** A minter for one id space: `{prefix}{n}` past the highest `held` names under `prefix`. */
|
|
44
|
+
function minter(held, prefix) {
|
|
45
|
+
const taken = new Set();
|
|
46
|
+
let next = 0;
|
|
47
|
+
for (const id of held) {
|
|
48
|
+
const m = new RegExp(`^${prefix}(\\d+)$`).exec(id);
|
|
49
|
+
if (m)
|
|
50
|
+
next = Math.max(next, Number(m[1]) + 1);
|
|
51
|
+
}
|
|
52
|
+
return (want) => {
|
|
53
|
+
if (want && !taken.has(want)) {
|
|
54
|
+
taken.add(want);
|
|
55
|
+
return want;
|
|
56
|
+
}
|
|
57
|
+
let id = `${prefix}${next++}`;
|
|
58
|
+
while (taken.has(id))
|
|
59
|
+
id = `${prefix}${next++}`;
|
|
60
|
+
taken.add(id);
|
|
61
|
+
return id;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/** The island a grid spells: its props and slots, each rank's id the first its cells carry. */
|
|
65
|
+
export function islandOf(grid) {
|
|
66
|
+
const g = normalizeTable(grid);
|
|
67
|
+
const rows = allRows(g);
|
|
68
|
+
const every = rows.flat().flatMap((cell) => (cell.ids ? [cell.ids] : []));
|
|
69
|
+
const rowId = minter(every.map((i) => i.row), 'r');
|
|
70
|
+
const columnId = minter(every.map((i) => i.column), 'k');
|
|
71
|
+
const slotId = minter(every.map((i) => i.slot), 's');
|
|
72
|
+
const columns = g.aligns.map((_, c) => columnId(rows.map((row) => row[c]?.ids?.column).find((id) => id !== undefined)));
|
|
73
|
+
const slots = {};
|
|
74
|
+
const cellAttrs = {};
|
|
75
|
+
const out = rows.map((row) => ({
|
|
76
|
+
id: rowId(row.map((cell) => cell.ids?.row).find((id) => id !== undefined)),
|
|
77
|
+
cells: Object.fromEntries(row.map((cell, c) => {
|
|
78
|
+
const slot = slotId(cell.ids?.slot);
|
|
79
|
+
slots[slot] = cellContent(cell);
|
|
80
|
+
const own = cellAttrsOf(cell);
|
|
81
|
+
if (Object.keys(own).length)
|
|
82
|
+
cellAttrs[slot] = own;
|
|
83
|
+
return [columns[c], slot];
|
|
84
|
+
}))
|
|
85
|
+
}));
|
|
86
|
+
const keyed = (xs, skip) => {
|
|
87
|
+
const entries = (xs ?? []).flatMap((x, c) => (skip(x) ? [] : [[columns[c], x]]));
|
|
88
|
+
return entries.length ? Object.fromEntries(entries) : undefined;
|
|
89
|
+
};
|
|
90
|
+
const aligns = keyed(g.aligns, (a) => a === 'none');
|
|
91
|
+
const widths = keyed(g.widths, (w) => w === null);
|
|
92
|
+
return {
|
|
93
|
+
props: {
|
|
94
|
+
...g.extra,
|
|
95
|
+
columns,
|
|
96
|
+
rows: out,
|
|
97
|
+
...(g.head !== undefined && g.head !== 1 && { head: g.head }),
|
|
98
|
+
...(aligns && { aligns }),
|
|
99
|
+
...(widths && { widths }),
|
|
100
|
+
...(g.align && { align: g.align }),
|
|
101
|
+
...(Object.keys(cellAttrs).length && { cell_attrs: cellAttrs })
|
|
102
|
+
},
|
|
103
|
+
slots
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/** A cell's own layout: every key beside its text, marks, anchors and ids. */
|
|
107
|
+
function cellAttrsOf(cell) {
|
|
108
|
+
const { text: _t, marks: _m, anchors: _a, ids: _i, ...layout } = cell;
|
|
109
|
+
return layout;
|
|
110
|
+
}
|
|
8
111
|
/** The zero cell: empty text, no marks. */
|
|
9
112
|
export function emptyCell() {
|
|
10
113
|
return { text: '', marks: [] };
|
|
@@ -52,7 +155,8 @@ export function normalizeTable(props) {
|
|
|
52
155
|
aligns: Array.from({ length: cols }, (_, c) => props.aligns[c] ?? 'none'),
|
|
53
156
|
...(widths.some((w) => w !== null) && { widths }),
|
|
54
157
|
...(props.align && { align: props.align }),
|
|
55
|
-
...(props.head !== undefined && props.head !== 1 && { head: props.head })
|
|
158
|
+
...(props.head !== undefined && props.head !== 1 && { head: props.head }),
|
|
159
|
+
...(props.extra && { extra: props.extra })
|
|
56
160
|
};
|
|
57
161
|
}
|
|
58
162
|
/** How many rows from the top draw as header rows, absent being one. */
|
|
@@ -163,7 +267,7 @@ function respan(rows, r, c, span) {
|
|
|
163
267
|
* row alike. `header` is a separate field because a table always has one; {@link fromRows} splits
|
|
164
268
|
* it back.
|
|
165
269
|
*/
|
|
166
|
-
|
|
270
|
+
function allRows(props) {
|
|
167
271
|
return [props.header, ...props.rows];
|
|
168
272
|
}
|
|
169
273
|
/**
|
|
@@ -432,8 +536,8 @@ export function mergeCells(props, block) {
|
|
|
432
536
|
if (!grid[r][c] || cell.text === '')
|
|
433
537
|
continue;
|
|
434
538
|
if (text)
|
|
435
|
-
text +=
|
|
436
|
-
const at =
|
|
539
|
+
text += HARD_BREAK;
|
|
540
|
+
const at = text.length;
|
|
437
541
|
text += cell.text;
|
|
438
542
|
for (const m of cell.marks)
|
|
439
543
|
marks.push({ ...m, start: m.start + at, end: m.end + at });
|
|
@@ -477,64 +581,69 @@ export function columnShares(props) {
|
|
|
477
581
|
return weights.map((w) => w / total);
|
|
478
582
|
}
|
|
479
583
|
// ── The cell codec ──────────────────────────────────────────────────────────
|
|
480
|
-
/**
|
|
481
|
-
* A cell as a one-paragraph `Content` for `decode` under `cellSchema`: each `\n` opens a
|
|
482
|
-
* `continues` line, the hard break it decodes to. The cell's marks are that content's marks.
|
|
483
|
-
*/
|
|
584
|
+
/** A cell as its slot: one paragraph, for `decode` under `cellSchema`. */
|
|
484
585
|
export function cellContent(cell) {
|
|
485
|
-
const breaks = cell.text.split('\n').length - 1;
|
|
486
586
|
return {
|
|
487
587
|
text: cell.text,
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
containers: [],
|
|
492
|
-
kind: 'para',
|
|
493
|
-
continues: true
|
|
494
|
-
}))
|
|
495
|
-
],
|
|
496
|
-
marks: cell.marks,
|
|
497
|
-
islands: []
|
|
588
|
+
blocks: [{ id: cell.ids?.block ?? 'b0', kind: 'para' }],
|
|
589
|
+
...(cell.marks.length && { marks: cell.marks }),
|
|
590
|
+
...(cell.anchors?.length && { anchors: cell.anchors })
|
|
498
591
|
};
|
|
499
592
|
}
|
|
500
593
|
/**
|
|
501
|
-
*
|
|
594
|
+
* Where `pos` in `before` lands in `after`, reading the edit between them as the one replaced run
|
|
595
|
+
* their common prefix and suffix leave: what a keystroke in a cell is. `assoc` says which side of
|
|
596
|
+
* the replaced run a position at its edge or inside it takes.
|
|
597
|
+
*/
|
|
598
|
+
function mapThrough(before, after, pos, assoc) {
|
|
599
|
+
const most = Math.min(before.length, after.length);
|
|
600
|
+
let head = 0;
|
|
601
|
+
while (head < most && before[head] === after[head])
|
|
602
|
+
head++;
|
|
603
|
+
let tail = 0;
|
|
604
|
+
while (tail < most - head && before[before.length - 1 - tail] === after[after.length - 1 - tail])
|
|
605
|
+
tail++;
|
|
606
|
+
const oldEnd = before.length - tail;
|
|
607
|
+
const newEnd = after.length - tail;
|
|
608
|
+
if (pos < head || (pos === head && assoc === 'before'))
|
|
609
|
+
return pos;
|
|
610
|
+
if (pos > oldEnd || (pos === oldEnd && assoc === 'after'))
|
|
611
|
+
return pos + newEnd - oldEnd;
|
|
612
|
+
return assoc === 'before' ? head : newEnd;
|
|
613
|
+
}
|
|
614
|
+
/**
|
|
615
|
+
* The cell a nested PM doc projects, carrying `prior`'s layout, ids and anchors through.
|
|
502
616
|
*
|
|
503
|
-
* Anchors inside a cell are preserved
|
|
504
|
-
*
|
|
505
|
-
*
|
|
506
|
-
*
|
|
507
|
-
*
|
|
617
|
+
* Anchors inside a cell are preserved, never minted: they are not in the field plugin's coordinate
|
|
618
|
+
* space (its position map holds one `atom` run for the whole table), so the popover withholds its
|
|
619
|
+
* `anchor` button in a cell. Preserving still means rebasing: each held anchor maps through the
|
|
620
|
+
* edit by the store's rule, a range's start after it and its end before, a point before, and a
|
|
621
|
+
* range the edit closes is dropped.
|
|
508
622
|
*/
|
|
509
623
|
export function cellFromDoc(doc, prior) {
|
|
510
624
|
const projected = pmToContent(doc);
|
|
511
|
-
const
|
|
512
|
-
const
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
const
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
};
|
|
526
|
-
}
|
|
527
|
-
/** A cell's keys beside its text and marks: what no edit of the text touches. */
|
|
528
|
-
function cellLayout(cell) {
|
|
529
|
-
const { text: _text, marks: _marks, ...layout } = cell;
|
|
530
|
-
return layout;
|
|
625
|
+
const { anchors: held, ...rest } = prior;
|
|
626
|
+
const next = { ...rest, text: projected.text, marks: projected.marks ?? [] };
|
|
627
|
+
if (!held?.length)
|
|
628
|
+
return next;
|
|
629
|
+
const at = (pos, assoc) => mapThrough(prior.text, next.text, pos, assoc);
|
|
630
|
+
const anchors = held.flatMap((a) => {
|
|
631
|
+
if (a.start === a.end) {
|
|
632
|
+
const p = at(a.start, 'before');
|
|
633
|
+
return [{ ...a, start: p, end: p }];
|
|
634
|
+
}
|
|
635
|
+
const start = at(a.start, 'after');
|
|
636
|
+
const end = at(a.end, 'before');
|
|
637
|
+
return start < end ? [{ ...a, start, end }] : [];
|
|
638
|
+
});
|
|
639
|
+
return anchors.length ? { ...next, anchors } : next;
|
|
531
640
|
}
|
|
532
641
|
/**
|
|
533
642
|
* Whether two cells are the same value, telling an own edit from an external one (an undo, a
|
|
534
643
|
* re-hydrate) without a flag. Marks compare structurally, as `reconcile.ts` states.
|
|
535
644
|
*/
|
|
536
645
|
export function cellEqual(a, b) {
|
|
537
|
-
return a.text === b.text && valueEqual(a.marks, b.marks);
|
|
646
|
+
return a.text === b.text && valueEqual(a.marks, b.marks) && valueEqual(a.anchors, b.anchors);
|
|
538
647
|
}
|
|
539
648
|
/** Whether two tables have the same rectangle, alignment, header and widths: the
|
|
540
649
|
* change that forces a rebuild rather than a per-cell reseed. */
|
|
@@ -5,8 +5,6 @@ export declare function touching(doc: PMNode, pos: number): boolean;
|
|
|
5
5
|
/** Join the two lists of one kind meeting at `pos`, the first's `start` counting for
|
|
6
6
|
* both. */
|
|
7
7
|
export declare function joinLists(tr: Transaction, pos: number): boolean;
|
|
8
|
-
/** Join the list at `pos` to a list of its kind touching it on either side. */
|
|
9
|
-
export declare function joinAround(tr: Transaction, pos: number): void;
|
|
10
8
|
/** Join at every seam of `seams` that two lists of one kind meet at, the last first so
|
|
11
9
|
* each join leaves the positions before it standing. */
|
|
12
10
|
export declare function joinAll(tr: Transaction, seams: Iterable<number>): void;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { canJoin } from 'prosemirror-transform';
|
|
2
|
-
|
|
3
|
-
return node.firstChild?.type === node.type.schema.nodes.list_item;
|
|
4
|
-
}
|
|
2
|
+
import { isList } from './list-node.js';
|
|
5
3
|
/** Whether two lists of one kind meet at `pos`. */
|
|
6
4
|
export function touching(doc, pos) {
|
|
7
5
|
const $pos = doc.resolve(pos);
|
|
@@ -17,14 +15,6 @@ export function joinLists(tr, pos) {
|
|
|
17
15
|
tr.join(pos);
|
|
18
16
|
return true;
|
|
19
17
|
}
|
|
20
|
-
/** Join the list at `pos` to a list of its kind touching it on either side. */
|
|
21
|
-
export function joinAround(tr, pos) {
|
|
22
|
-
const node = tr.doc.nodeAt(pos);
|
|
23
|
-
if (!node)
|
|
24
|
-
return;
|
|
25
|
-
joinLists(tr, pos + node.nodeSize);
|
|
26
|
-
joinLists(tr, pos);
|
|
27
|
-
}
|
|
28
18
|
/** Join at every seam of `seams` that two lists of one kind meet at, the last first so
|
|
29
19
|
* each join leaves the positions before it standing. */
|
|
30
20
|
export function joinAll(tr, seams) {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
container div on mount and tears it down on unmount. No logic beyond wiring;
|
|
4
4
|
paint.ts/bridge.ts/controller.ts own the behavior. Exposes the
|
|
5
5
|
`PreviewController` verbs as instance methods (`bind:this`) for a consumer
|
|
6
|
-
that drives `refresh`/`scrollToField`/`focusPosition`/`endFollow`/`setZoom`
|
|
6
|
+
that drives `refresh`/`scrollToField`/`focusPosition`/`washField`/`endFollow`/`setZoom`
|
|
7
7
|
imperatively (e.g. after `session.apply` elsewhere).
|
|
8
8
|
-->
|
|
9
9
|
<script lang="ts">
|
|
@@ -73,6 +73,10 @@
|
|
|
73
73
|
export function focusPosition(at: Place): void {
|
|
74
74
|
controller?.focusPosition(at);
|
|
75
75
|
}
|
|
76
|
+
/** `false` when this compile places nothing at `field` ({@link PreviewController}). */
|
|
77
|
+
export function washField(field: DocPath): boolean {
|
|
78
|
+
return controller?.washField(field) ?? false;
|
|
79
|
+
}
|
|
76
80
|
/** The follow ends on a focus change ({@link PreviewController}), and the editor's
|
|
77
81
|
* own signal is one: `onActiveLeafChange={preview.endFollow}`. */
|
|
78
82
|
export function endFollow(): void {
|
|
@@ -126,6 +130,21 @@
|
|
|
126
130
|
background: var(--_qm-surface-sunken);
|
|
127
131
|
}
|
|
128
132
|
|
|
133
|
+
/* The arrival wash on the page (`wash.ts`): a plane at a field's box, its tone the editor's,
|
|
134
|
+
reaching a hair past the ink's tight box and rounded, as a control's wash is a box's own. Over
|
|
135
|
+
the canvas by tree order, the canvas being a slot's first child. */
|
|
136
|
+
:global(:where(.qm-preview-wash)) {
|
|
137
|
+
pointer-events: none;
|
|
138
|
+
}
|
|
139
|
+
:global(:where(.qm-preview-wash))::after {
|
|
140
|
+
content: '';
|
|
141
|
+
position: absolute;
|
|
142
|
+
inset: calc(-1 * var(--_qm-space-half));
|
|
143
|
+
border-radius: var(--_qm-radius-inner);
|
|
144
|
+
background: var(--_qm-accent-wash);
|
|
145
|
+
opacity: 0;
|
|
146
|
+
}
|
|
147
|
+
|
|
129
148
|
/* Sticky to the pane's bottom edge and stretched across it, so the pill's corner is
|
|
130
149
|
the pane's however the pages scroll; zero height, so it displaces nothing. */
|
|
131
150
|
:global(:where(.qm-preview-dock)) {
|
|
@@ -32,6 +32,7 @@ declare const Preview: import("svelte").Component<Props, {
|
|
|
32
32
|
refresh: (change: ChangeSet) => void;
|
|
33
33
|
scrollToField: (field: DocPath) => boolean;
|
|
34
34
|
focusPosition: (at: Place) => void;
|
|
35
|
+
washField: (field: DocPath) => boolean;
|
|
35
36
|
endFollow: () => void;
|
|
36
37
|
setZoom: (zoom: number | undefined) => void;
|
|
37
38
|
}, "">;
|
|
@@ -36,6 +36,11 @@ export interface PreviewController {
|
|
|
36
36
|
* Takes the editor's `onCaretMove` payload, so `onCaretMove={preview.focusPosition}` wires it.
|
|
37
37
|
*/
|
|
38
38
|
focusPosition(at: Place): void;
|
|
39
|
+
/**
|
|
40
|
+
* Play the arrival wash over every box this compile places at `field`, and move nothing: no
|
|
41
|
+
* scroll, and the follow stands. `false` when this compile places nothing at that address.
|
|
42
|
+
*/
|
|
43
|
+
washField(field: DocPath): boolean;
|
|
39
44
|
/**
|
|
40
45
|
* End the follow: the pane stays where the user left it until the next `focusPosition`. Wire
|
|
41
46
|
* `onActiveLeafChange={preview.endFollow}`; a form control reports no caret, so unwired the
|
|
@@ -2,6 +2,7 @@ import { reportError, errorMessage } from '../core/errors.js';
|
|
|
2
2
|
import { createPaintLoop } from './paint.js';
|
|
3
3
|
import { createBridge } from './bridge.js';
|
|
4
4
|
import { createViewport } from './viewport.js';
|
|
5
|
+
import { cutWashes, washField } from './wash.js';
|
|
5
6
|
import { mergePreviewStrings } from './strings.js';
|
|
6
7
|
const CONTAINER_CLASS = 'qm-preview';
|
|
7
8
|
const MESSAGE_CLASS = 'qm-preview-message';
|
|
@@ -77,6 +78,8 @@ export function createPreview(session, opts) {
|
|
|
77
78
|
let followed;
|
|
78
79
|
return {
|
|
79
80
|
refresh(change) {
|
|
81
|
+
// A plane is laid at the layout it washed; a recompile may have moved the ink under it.
|
|
82
|
+
cutWashes(paintLoop.slots);
|
|
80
83
|
render(change.pageCount, change.dirtyPages);
|
|
81
84
|
viewport.update();
|
|
82
85
|
if (followed)
|
|
@@ -94,6 +97,9 @@ export function createPreview(session, opts) {
|
|
|
94
97
|
followed = at;
|
|
95
98
|
bridge?.focusPosition(at.field, at.pos);
|
|
96
99
|
},
|
|
100
|
+
washField(field) {
|
|
101
|
+
return washField(session, paintLoop.slots, field);
|
|
102
|
+
},
|
|
97
103
|
endFollow() {
|
|
98
104
|
followed = undefined;
|
|
99
105
|
},
|
package/dist/preview/viewport.js
CHANGED
|
@@ -155,12 +155,30 @@ export function createViewport(container, slots, setScale, resetLabel) {
|
|
|
155
155
|
// `deltaY = -100 ln(scale)`, in deltas smaller than a notch's: those track the fingers.
|
|
156
156
|
function onWheel(e) {
|
|
157
157
|
if (!(e.ctrlKey || e.metaKey))
|
|
158
|
-
return;
|
|
158
|
+
return pan(e);
|
|
159
159
|
e.preventDefault();
|
|
160
160
|
const pinched = e.deltaMode === 0 && Math.abs(e.deltaY) < PINCH_DELTA;
|
|
161
161
|
const factor = Math.exp(-e.deltaY * (pinched ? PINCH_RATE : WHEEL_RATE[e.deltaMode]));
|
|
162
162
|
glideTo((g) => g.raw * factor, e.clientX, e.clientY);
|
|
163
163
|
}
|
|
164
|
+
// A trackpad pan over pages that overflow both ways, scrolled here: on macOS the
|
|
165
|
+
// browser rails a scroll not near enough a diagonal to the axis it leans on, which
|
|
166
|
+
// over a zoomed page is the wrong axis as often as not. A delta on one axis is left
|
|
167
|
+
// to the browser, so a mouse wheel keeps its smooth notch, and one at an edge
|
|
168
|
+
// chains on.
|
|
169
|
+
function pan(e) {
|
|
170
|
+
if (e.deltaMode !== 0 || !e.deltaX || !e.deltaY)
|
|
171
|
+
return;
|
|
172
|
+
const { scrollWidth, scrollHeight, clientWidth, clientHeight } = container;
|
|
173
|
+
if (scrollWidth <= clientWidth || scrollHeight <= clientHeight)
|
|
174
|
+
return;
|
|
175
|
+
const { scrollLeft, scrollTop } = container;
|
|
176
|
+
container.scrollLeft += e.deltaX;
|
|
177
|
+
container.scrollTop += e.deltaY;
|
|
178
|
+
if (container.scrollLeft !== scrollLeft || container.scrollTop !== scrollTop) {
|
|
179
|
+
e.preventDefault();
|
|
180
|
+
}
|
|
181
|
+
}
|
|
164
182
|
// The keys are the focused pane's alone: elsewhere they are the browser's own zoom,
|
|
165
183
|
// the pointer over the pane notwithstanding. A key a host's own handler took is left
|
|
166
184
|
// to it.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { LiveSession } from '@quillmark/wasm';
|
|
2
|
+
import type { PageSlot } from './paint.js';
|
|
3
|
+
/** Cut every plane still playing on `field`, or on any field when `field` is unset. */
|
|
4
|
+
export declare function cutWashes(slots: readonly PageSlot[], field?: string): void;
|
|
5
|
+
/**
|
|
6
|
+
* Wash every box this compile places at `field`; `false` when it places none. A wash still playing
|
|
7
|
+
* on the same address is cut first, so two quick washes do not stack alphas.
|
|
8
|
+
*/
|
|
9
|
+
export declare function washField(session: LiveSession, slots: readonly PageSlot[], field: string): boolean;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { bloom } from '../core/bloom.js';
|
|
2
|
+
import { applyPercentRect, boxesForField, rectToPercent } from './geometry.js';
|
|
3
|
+
const WASH_CLASS = 'qm-preview-wash';
|
|
4
|
+
/** Cut every plane still playing on `field`, or on any field when `field` is unset. */
|
|
5
|
+
export function cutWashes(slots, field) {
|
|
6
|
+
for (const { el } of slots) {
|
|
7
|
+
for (const plane of el.querySelectorAll(`.${WASH_CLASS}`)) {
|
|
8
|
+
if (field === undefined || plane.dataset.field === field)
|
|
9
|
+
plane.remove();
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Wash every box this compile places at `field`; `false` when it places none. A wash still playing
|
|
15
|
+
* on the same address is cut first, so two quick washes do not stack alphas.
|
|
16
|
+
*/
|
|
17
|
+
export function washField(session, slots, field) {
|
|
18
|
+
const boxes = boxesForField(field, session.fieldBoxes(field), () => session.regions());
|
|
19
|
+
cutWashes(slots, field);
|
|
20
|
+
let placed = false;
|
|
21
|
+
for (const box of boxes) {
|
|
22
|
+
const slot = slots[box.page];
|
|
23
|
+
if (!slot)
|
|
24
|
+
continue;
|
|
25
|
+
placed = true;
|
|
26
|
+
const plane = document.createElement('div');
|
|
27
|
+
plane.className = WASH_CLASS;
|
|
28
|
+
plane.dataset.field = field;
|
|
29
|
+
applyPercentRect(plane, rectToPercent(box.rect, slot.size));
|
|
30
|
+
slot.el.appendChild(plane);
|
|
31
|
+
const run = bloom(plane);
|
|
32
|
+
if (run)
|
|
33
|
+
run.onfinish = run.oncancel = () => plane.remove();
|
|
34
|
+
else
|
|
35
|
+
plane.remove();
|
|
36
|
+
}
|
|
37
|
+
return placed;
|
|
38
|
+
}
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
baseType,
|
|
71
71
|
controlKind,
|
|
72
72
|
declaredContent,
|
|
73
|
-
|
|
73
|
+
fieldTitle,
|
|
74
74
|
literalText,
|
|
75
75
|
rowSummary,
|
|
76
76
|
schemaAt,
|
|
@@ -81,6 +81,7 @@
|
|
|
81
81
|
import { propertyDomIds } from './domid.js';
|
|
82
82
|
import type { LandingBox } from './leaves.js';
|
|
83
83
|
import { reorder, reorderArm } from './motion.js';
|
|
84
|
+
import { rowDrag } from './rowdrag.svelte.js';
|
|
84
85
|
import Icon from './icons/Icon.svelte';
|
|
85
86
|
import TextField from './TextField.svelte';
|
|
86
87
|
import ObjectField from './ObjectField.svelte';
|
|
@@ -266,7 +267,6 @@
|
|
|
266
267
|
// one, else this instance's own.
|
|
267
268
|
const uid = $props.id();
|
|
268
269
|
const countId = $derived(`${idBase ?? `qm-${uid}`}-count`);
|
|
269
|
-
const columnTitle = (key: string, sub: QuillFieldSchema): string => sub.title ?? humanize(key);
|
|
270
270
|
|
|
271
271
|
// The awaited flush below is the only work that outlives a gesture here, so the
|
|
272
272
|
// span carries the reorder's frame and nothing else: it is the liveness
|
|
@@ -393,7 +393,7 @@
|
|
|
393
393
|
}
|
|
394
394
|
/**
|
|
395
395
|
* Land at `steps`: element `steps[0]`, and the rest of the walk inside its subform,
|
|
396
|
-
* at
|
|
396
|
+
* at UTF-16 offset `pos` where the leaf the walk ends in can take one ({@link
|
|
397
397
|
* FieldControl.focusPath}). The index resolves to the element's session id here, at
|
|
398
398
|
* the call, never carried as one — an index is stale the moment anything above it
|
|
399
399
|
* splices. Past the live list it falls back to {@link focus}: the field is right and
|
|
@@ -536,7 +536,7 @@
|
|
|
536
536
|
* moves nothing, and never the record around it. A held drag owns the row until its
|
|
537
537
|
* release. */
|
|
538
538
|
function onRowKey(e: KeyboardEvent, k: number): void {
|
|
539
|
-
if (!e.altKey || e.shiftKey || e.ctrlKey || e.metaKey || e.isComposing || drag) return;
|
|
539
|
+
if (!e.altKey || e.shiftKey || e.ctrlKey || e.metaKey || e.isComposing || drag.held()) return;
|
|
540
540
|
// A cell that took the key — a select opening, a date segment stepping, a prose
|
|
541
541
|
// leaf joining — owns it.
|
|
542
542
|
if (e.defaultPrevented) return;
|
|
@@ -549,109 +549,12 @@
|
|
|
549
549
|
move(k, k + dir);
|
|
550
550
|
}
|
|
551
551
|
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
// reflows until the release (the lift is a tone and the drop rule is out of flow), and
|
|
559
|
-
// the release is the one splice `move` makes. A handle that loses the pointer, or
|
|
560
|
-
// leaves the DOM, ends the drag with no move.
|
|
561
|
-
const DEAD_ZONE = 3;
|
|
562
|
-
/** The band at a scrollport's top and bottom edges that scrolls it under a held drag,
|
|
563
|
-
* and the most one frame scrolls, reached at the edge itself. */
|
|
564
|
-
const EDGE = 48;
|
|
565
|
-
const STEP = 16;
|
|
566
|
-
type RowDrag = { k: number; origin: number; y: number; engaged: boolean; drop: number };
|
|
567
|
-
let drag = $state<RowDrag | undefined>();
|
|
568
|
-
let follow: { grip: Element; port: Element; armed: boolean; frame: number } | undefined;
|
|
569
|
-
function onHandleDown(e: PointerEvent, k: number): void {
|
|
570
|
-
if (e.button !== 0) return;
|
|
571
|
-
e.preventDefault();
|
|
572
|
-
release();
|
|
573
|
-
const grip = e.currentTarget as HTMLElement;
|
|
574
|
-
grip.setPointerCapture?.(e.pointerId);
|
|
575
|
-
drag = { k, origin: e.clientY, y: e.clientY, engaged: false, drop: k };
|
|
576
|
-
follow = { grip, port: scrollport(grip), armed: false, frame: 0 };
|
|
577
|
-
}
|
|
578
|
-
function onHandleMove(e: PointerEvent): void {
|
|
579
|
-
if (!drag) return;
|
|
580
|
-
drag.y = e.clientY;
|
|
581
|
-
if (!drag.engaged) {
|
|
582
|
-
if (Math.abs(e.clientY - drag.origin) < DEAD_ZONE) return;
|
|
583
|
-
drag.engaged = true;
|
|
584
|
-
addEventListener('scroll', repick, { capture: true, passive: true });
|
|
585
|
-
if (follow) follow.frame = requestAnimationFrame(edgeScroll);
|
|
586
|
-
}
|
|
587
|
-
repick();
|
|
588
|
-
}
|
|
589
|
-
function repick(): void {
|
|
590
|
-
if (drag?.engaged) drag.drop = dropIndex(drag.k, drag.y);
|
|
591
|
-
}
|
|
592
|
-
const rowBox = (i: number): DOMRect | undefined => rowEls[ids[i]]?.getBoundingClientRect();
|
|
593
|
-
/** The row the pointer is over, or the nearest one past either end. */
|
|
594
|
-
function dropIndex(k: number, y: number): number {
|
|
595
|
-
let best = k;
|
|
596
|
-
let nearest = Infinity;
|
|
597
|
-
ids.forEach((_, i) => {
|
|
598
|
-
const box = rowBox(i);
|
|
599
|
-
if (!box) return;
|
|
600
|
-
const gap = y < box.top ? box.top - y : y > box.bottom ? y - box.bottom : 0;
|
|
601
|
-
if (gap < nearest) {
|
|
602
|
-
nearest = gap;
|
|
603
|
-
best = i;
|
|
604
|
-
}
|
|
605
|
-
});
|
|
606
|
-
return best;
|
|
607
|
-
}
|
|
608
|
-
const page = (): Element => document.scrollingElement ?? document.documentElement;
|
|
609
|
-
/** The nearest ancestor that scrolls vertically, else the page. */
|
|
610
|
-
function scrollport(from: Element): Element {
|
|
611
|
-
for (let el = from.parentElement; el; el = el.parentElement) {
|
|
612
|
-
const { overflowY } = getComputedStyle(el);
|
|
613
|
-
if (/auto|scroll/.test(overflowY) && el.scrollHeight > el.clientHeight) return el;
|
|
614
|
-
}
|
|
615
|
-
return page();
|
|
616
|
-
}
|
|
617
|
-
function edgeScroll(): void {
|
|
618
|
-
if (!follow || !drag?.engaged) return;
|
|
619
|
-
if (!follow.grip.isConnected) {
|
|
620
|
-
drag = undefined;
|
|
621
|
-
release();
|
|
622
|
-
return;
|
|
623
|
-
}
|
|
624
|
-
const { port } = follow;
|
|
625
|
-
const box = port === page() ? undefined : port.getBoundingClientRect();
|
|
626
|
-
const top = Math.max(box?.top ?? 0, 0);
|
|
627
|
-
const bottom = Math.min(box?.bottom ?? innerHeight, innerHeight);
|
|
628
|
-
const into = Math.min(drag.y - top - EDGE, 0) + Math.max(drag.y - bottom + EDGE, 0);
|
|
629
|
-
if (!into) follow.armed = true;
|
|
630
|
-
// Only toward rows still out of view: past the list's end there is nothing to reach.
|
|
631
|
-
const beyond =
|
|
632
|
-
into < 0 ? (rowBox(0)?.top ?? top) < top : (rowBox(ids.length - 1)?.bottom ?? 0) > bottom;
|
|
633
|
-
if (into && follow.armed && beyond)
|
|
634
|
-
port.scrollBy({ top: STEP * Math.max(-1, Math.min(1, into / EDGE)), behavior: 'instant' });
|
|
635
|
-
follow.frame = requestAnimationFrame(edgeScroll);
|
|
636
|
-
}
|
|
637
|
-
function release(): void {
|
|
638
|
-
if (follow) cancelAnimationFrame(follow.frame);
|
|
639
|
-
follow = undefined;
|
|
640
|
-
removeEventListener('scroll', repick, { capture: true });
|
|
641
|
-
}
|
|
642
|
-
onDestroy(release);
|
|
643
|
-
function onHandleUp(e: PointerEvent): void {
|
|
644
|
-
const done = drag;
|
|
645
|
-
drag = undefined;
|
|
646
|
-
release();
|
|
647
|
-
if (!done?.engaged || e.type !== 'pointerup') return;
|
|
648
|
-
move(done.k, done.drop);
|
|
649
|
-
}
|
|
650
|
-
/** Where the drop rule draws on row `k`, while a drag would land the row there. */
|
|
651
|
-
function dropSide(k: number): 'before' | 'after' | undefined {
|
|
652
|
-
if (!drag?.engaged || drag.drop !== k || drag.drop === drag.k) return undefined;
|
|
653
|
-
return drag.drop > drag.k ? 'after' : 'before';
|
|
654
|
-
}
|
|
552
|
+
const drag = rowDrag({
|
|
553
|
+
count: () => ids.length,
|
|
554
|
+
box: (i) => rowEls[ids[i]]?.getBoundingClientRect(),
|
|
555
|
+
move
|
|
556
|
+
});
|
|
557
|
+
onDestroy(drag.release);
|
|
655
558
|
|
|
656
559
|
/** Whether cells stand past the table scroller's end edge, under the pinned remove,
|
|
657
560
|
* which is what the fade before the remove draws on. */
|
|
@@ -731,7 +634,7 @@
|
|
|
731
634
|
]}
|
|
732
635
|
>
|
|
733
636
|
<FieldLabel
|
|
734
|
-
label={
|
|
637
|
+
label={fieldTitle(key, sub)}
|
|
735
638
|
descriptionId={idBase != null ? propertyDomIds(idBase, key).description : undefined}
|
|
736
639
|
description={sub.description}
|
|
737
640
|
/>
|
|
@@ -775,9 +678,9 @@
|
|
|
775
678
|
<div
|
|
776
679
|
class={[
|
|
777
680
|
'qm-array-row qm-element qm-wash',
|
|
778
|
-
{ open: open.has(id), lifted: drag
|
|
681
|
+
{ open: open.has(id), lifted: drag.lifted(k) }
|
|
779
682
|
]}
|
|
780
|
-
data-drop={dropSide(k)}
|
|
683
|
+
data-drop={drag.dropSide(k)}
|
|
781
684
|
data-qm-index={k}
|
|
782
685
|
bind:this={rowEls[id]}
|
|
783
686
|
animate:reorder={arm.armed}
|
|
@@ -893,11 +796,11 @@
|
|
|
893
796
|
class="qm-row-handle"
|
|
894
797
|
aria-hidden="true"
|
|
895
798
|
title={t.strings.arrayDrag}
|
|
896
|
-
onpointerdown={(e) =>
|
|
897
|
-
onpointermove={
|
|
898
|
-
onpointerup={
|
|
899
|
-
onpointercancel={
|
|
900
|
-
onlostpointercapture={
|
|
799
|
+
onpointerdown={(e) => drag.down(e, k)}
|
|
800
|
+
onpointermove={drag.move}
|
|
801
|
+
onpointerup={drag.up}
|
|
802
|
+
onpointercancel={drag.up}
|
|
803
|
+
onlostpointercapture={drag.up}
|
|
901
804
|
><span class="qm-row-handle-bar"><Icon name="grip-vertical" /></span></span
|
|
902
805
|
>
|
|
903
806
|
{/snippet}
|