@quillmark/svelte 0.29.3 → 0.31.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 +3 -3
- package/dist/core/address.d.ts +3 -3
- package/dist/core/address.js +1 -1
- package/dist/core/codec/decode.d.ts +4 -5
- package/dist/core/codec/decode.js +151 -208
- package/dist/core/codec/encode.d.ts +13 -35
- package/dist/core/codec/encode.js +127 -408
- package/dist/core/codec/field.d.ts +11 -10
- package/dist/core/codec/field.js +190 -92
- package/dist/core/codec/index.d.ts +2 -2
- package/dist/core/codec/index.js +4 -4
- package/dist/core/codec/islands.d.ts +13 -9
- package/dist/core/codec/islands.js +54 -49
- package/dist/core/codec/marks.d.ts +12 -18
- package/dist/core/codec/marks.js +16 -26
- package/dist/core/codec/positions.d.ts +25 -7
- package/dist/core/codec/positions.js +43 -50
- package/dist/core/codec/prose.css +0 -8
- package/dist/core/codec/schema.d.ts +3 -3
- package/dist/core/codec/schema.js +29 -11
- package/dist/core/codec/slash.d.ts +4 -2
- package/dist/core/codec/slash.js +13 -3
- 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 +19 -12
- package/dist/core/codec/table.d.ts +77 -43
- package/dist/core/codec/table.js +157 -48
- package/dist/core/index.d.ts +1 -0
- package/dist/core/theme.css +14 -6
- package/dist/visual/ArrayField.svelte +168 -83
- package/dist/visual/BooleanField.svelte +2 -2
- package/dist/visual/Card.svelte +65 -44
- package/dist/visual/DateField.svelte +16 -1
- package/dist/visual/DiagnosticList.svelte +34 -2
- package/dist/visual/EnumField.svelte +58 -44
- package/dist/visual/Field.svelte +13 -3
- package/dist/visual/Field.svelte.d.ts +3 -1
- package/dist/visual/FieldHint.svelte +10 -3
- package/dist/visual/FormatPopover.svelte +1 -1
- package/dist/visual/MatrixAdd.svelte +3 -18
- package/dist/visual/MatrixField.svelte +20 -12
- package/dist/visual/ObjectField.svelte +164 -145
- package/dist/visual/ProseField.svelte +6 -1
- package/dist/visual/ProseValue.svelte +8 -8
- package/dist/visual/SlashMenu.svelte +24 -12
- package/dist/visual/SlashMenu.svelte.d.ts +2 -0
- package/dist/visual/VisualEditor.svelte +1 -1
- package/dist/visual/VisualEditor.svelte.d.ts +1 -1
- package/dist/visual/VisualEditorInner.svelte +159 -18
- package/dist/visual/VisualEditorInner.svelte.d.ts +1 -1
- package/dist/visual/controls.css +42 -4
- package/dist/visual/leaves.d.ts +1 -1
- package/dist/visual/leaves.js +1 -1
- package/dist/visual/strings.d.ts +27 -10
- package/dist/visual/strings.js +40 -6
- package/dist/visual/structure.d.ts +17 -9
- package/dist/visual/structure.js +20 -26
- package/dist/visual/undo.svelte.d.ts +36 -0
- package/dist/visual/undo.svelte.js +119 -0
- package/package.json +2 -2
- package/dist/visual/hold.d.ts +0 -17
- package/dist/visual/hold.js +0 -39
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. */
|
|
@@ -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. */
|
package/dist/core/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { init } from './lifecycle.js';
|
|
2
2
|
export type { DocPath, Landing, Place } from './address.js';
|
|
3
3
|
export { fieldPathForAddr, addrForFieldPath } from './address.js';
|
|
4
|
+
export type { Delta } from './codec/positions.js';
|
|
4
5
|
export type { EditorError, EditorErrorCode, EditorErrorHandler } from './errors.js';
|
package/dist/core/theme.css
CHANGED
|
@@ -141,6 +141,11 @@
|
|
|
141
141
|
--_qm-surface: var(--_qm-bg);
|
|
142
142
|
--_qm-surface-well: oklab(from var(--_qm-bg) calc(l - (0.04 + 0.0202 * (1 - l))) a b);
|
|
143
143
|
--_qm-surface-sunken: var(--_qm-surface-well);
|
|
144
|
+
/* The well's own edge, drawn inside it: the fill alone stands about 1.1:1 off the
|
|
145
|
+
card, too faint to find a field by. A step toward the ink laid over the well,
|
|
146
|
+
translucent as `hover` is, so it darkens a light well and lightens a dark one by
|
|
147
|
+
the same measure. */
|
|
148
|
+
--_qm-well-edge: color-mix(in oklab, var(--_qm-fg) 10%, transparent);
|
|
144
149
|
/* `raised` is the same ramp spelled as a mix, its step 0.08 × (1 − l): the light
|
|
145
150
|
arm is zero, a white card having nowhere further to go, so a floating surface
|
|
146
151
|
separates on its hairline and `--_qm-lift` there and the step joins them in
|
|
@@ -244,9 +249,9 @@
|
|
|
244
249
|
/* ── Ratios and effects ──────────────────────────────────────────────────
|
|
245
250
|
No palette fixes these, so they are their own rungs. */
|
|
246
251
|
--_qm-blur: 8px;
|
|
247
|
-
/* The popover's
|
|
248
|
-
|
|
249
|
-
--_qm-surface-popover: color-mix(in oklab, var(--_qm-surface-raised)
|
|
252
|
+
/* The popover's surface: the raised rung all but opaque, so the blur softens what
|
|
253
|
+
is behind it and a line of text under a toolbar never reads through it. */
|
|
254
|
+
--_qm-surface-popover: color-mix(in oklab, var(--_qm-surface-raised) 96%, transparent);
|
|
250
255
|
/* What a surface with no plane under it lifts on. A tone rung cannot carry that at
|
|
251
256
|
both poles: `raised` is a no-op against a white card (§Colour), so in light the
|
|
252
257
|
hairline is otherwise the whole separation over the body prose these float on.
|
|
@@ -256,10 +261,13 @@
|
|
|
256
261
|
the cue means one thing whichever way the scale runs. Spent only on what floats,
|
|
257
262
|
and the one shadow any surface casts, which is review's to hold. */
|
|
258
263
|
--_qm-lift: 0 0 12px color-mix(in oklab, #000 16%, transparent);
|
|
259
|
-
/* The recede ladder: a
|
|
260
|
-
|
|
261
|
-
correctly given the element's own colour is a rung.
|
|
264
|
+
/* The recede ladder: a disabled affordance, a muted one, and a live one at rest
|
|
265
|
+
that comes up under the pointer. Opacity recedes toward whatever is behind, so
|
|
266
|
+
these invert correctly given the element's own colour is a rung. `rest` keeps a
|
|
267
|
+
label-ink control over 3:1 on the card and the well (WCAG 1.4.11), where `idle`
|
|
268
|
+
is a disabled control's, which owes no contrast. */
|
|
262
269
|
--_qm-opacity-idle: 0.35;
|
|
270
|
+
--_qm-opacity-rest: 0.75;
|
|
263
271
|
--_qm-opacity-muted: 0.5;
|
|
264
272
|
|
|
265
273
|
/* ── Focus ───────────────────────────────────────────────────────────────
|