@quillmark/svelte 0.34.0 → 0.35.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 +13 -13
- package/THEMING.md +1 -1
- package/dist/core/address.d.ts +6 -0
- package/dist/core/address.js +16 -0
- package/dist/core/codec/field.d.ts +3 -6
- package/dist/core/codec/field.js +0 -10
- package/dist/core/codec/prose.css +1 -46
- package/dist/core/codec/review.d.ts +5 -20
- package/dist/core/codec/review.js +42 -199
- package/dist/core/theme.css +5 -7
- package/dist/visual/Field.svelte +10 -38
- package/dist/visual/ProseField.svelte +0 -2
- package/dist/visual/ReviewRows.svelte +11 -36
- package/dist/visual/VisualEditor.svelte +3 -4
- package/dist/visual/VisualEditor.svelte.d.ts +1 -1
- package/dist/visual/VisualEditorInner.svelte +61 -146
- package/dist/visual/VisualEditorInner.svelte.d.ts +1 -1
- package/dist/visual/props.d.ts +10 -9
- package/dist/visual/review.d.ts +10 -45
- package/dist/visual/review.js +2 -44
- package/dist/visual/review.svelte.d.ts +3 -30
- package/dist/visual/review.svelte.js +27 -157
- package/dist/visual/strings.d.ts +2 -14
- package/dist/visual/strings.js +0 -6
- package/package.json +1 -1
- package/dist/visual/ReviewPopover.svelte +0 -179
- package/dist/visual/ReviewPopover.svelte.d.ts +0 -16
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// Review, drawn in the leaf's own flow: what a writer other than the reader proposes to change
|
|
2
|
-
// here
|
|
3
|
-
//
|
|
2
|
+
// here. An item names blocks by the ids the leaf's nodes carry, so its place is the document's and
|
|
3
|
+
// rides every edit; nothing is measured from outside the view.
|
|
4
4
|
//
|
|
5
5
|
// A proposal is the paragraph it would rewrite, read as an edit of itself: the words that would go
|
|
6
6
|
// struck, the words that would come tinted in their place, and what it adds beyond the paragraph
|
|
7
7
|
// set in flow under it. None of it enters the document while it is proposed: the struck words are
|
|
8
|
-
// the leaf's own text under a decoration, and every added word is a widget. A proposal taken is
|
|
9
|
-
//
|
|
8
|
+
// the leaf's own text under a decoration, and every added word is a widget. A proposal taken is
|
|
9
|
+
// plain text, the leaf's like any other.
|
|
10
10
|
//
|
|
11
11
|
// A proposal is an edit of the paragraph as its writer read it, or as it stood when it arrived. What the reader
|
|
12
12
|
// writes in the paragraph since is theirs: the proposal's stretches ride past it, and only the
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
// words that land are the words that were drawn. It goes down the lane a keystroke takes: one
|
|
17
17
|
// transaction, one undo step, one commit.
|
|
18
18
|
import { closeHistory, isHistoryTransaction, undo } from 'prosemirror-history';
|
|
19
|
-
import { DOMSerializer, Fragment, Mark
|
|
19
|
+
import { DOMSerializer, Fragment, Mark } from 'prosemirror-model';
|
|
20
20
|
import { keydownHandler } from 'prosemirror-keymap';
|
|
21
21
|
import { Plugin, PluginKey, Selection } from 'prosemirror-state';
|
|
22
22
|
import { Step, StepResult } from 'prosemirror-transform';
|
|
@@ -31,23 +31,8 @@ export const DEFAULT_REVIEW_STRINGS = {
|
|
|
31
31
|
reviewAcceptTitle: 'Accept',
|
|
32
32
|
reviewDismissTitle: 'Dismiss',
|
|
33
33
|
reviewProposal: 'Proposed change',
|
|
34
|
-
reviewGone: 'Text removed here',
|
|
35
34
|
reviewOutdated: 'Edited since'
|
|
36
35
|
};
|
|
37
|
-
/** Each stretch through `mapping`. Words typed at a stretch's edge stay outside it, and one inside
|
|
38
|
-
* it grows it; `fresh` stretches were just written, so they reach over what the mapping wrote.
|
|
39
|
-
* `undefined` where nothing the proposal wrote or took out is left. */
|
|
40
|
-
function mapWritten(written, mapping, fresh = false) {
|
|
41
|
-
const out = [];
|
|
42
|
-
for (const w of written) {
|
|
43
|
-
const a = mapping.mapResult(w.from, fresh ? -1 : 1);
|
|
44
|
-
const b = mapping.mapResult(w.to, fresh ? 1 : -1);
|
|
45
|
-
if (w.from === w.to ? a.deleted : b.pos <= a.pos)
|
|
46
|
-
continue;
|
|
47
|
-
out.push({ ...w, from: a.pos, to: Math.max(a.pos, b.pos) });
|
|
48
|
-
}
|
|
49
|
-
return out.length ? out : undefined;
|
|
50
|
-
}
|
|
51
36
|
const reviewKey = new PluginKey('quill-review');
|
|
52
37
|
/** Tell the review layer the store took blocks under new ids, each `[was, now]`. */
|
|
53
38
|
export function renameBlocks(tr, renamed) {
|
|
@@ -69,76 +54,47 @@ function nowOf(renamed, id) {
|
|
|
69
54
|
class ReviewAnswer extends Step {
|
|
70
55
|
id;
|
|
71
56
|
to;
|
|
72
|
-
|
|
73
|
-
/** `written` stands in the document as it is after the steps that write it: an accept's
|
|
74
|
-
* stretches, and on an undo of an accept the stretches it puts back, which an undo of that
|
|
75
|
-
* undo writes over again. */
|
|
76
|
-
constructor(id, to, written = []) {
|
|
57
|
+
constructor(id, to) {
|
|
77
58
|
super();
|
|
78
59
|
this.id = id;
|
|
79
60
|
this.to = to;
|
|
80
|
-
this.written = written;
|
|
81
61
|
}
|
|
82
62
|
apply(doc) {
|
|
83
63
|
return StepResult.ok(doc);
|
|
84
64
|
}
|
|
85
65
|
invert() {
|
|
86
|
-
return new ReviewAnswer(this.id, this.to ? undefined : 'accept'
|
|
66
|
+
return new ReviewAnswer(this.id, this.to ? undefined : 'accept');
|
|
87
67
|
}
|
|
88
|
-
map(
|
|
89
|
-
return
|
|
68
|
+
map() {
|
|
69
|
+
return this;
|
|
90
70
|
}
|
|
91
71
|
toJSON() {
|
|
92
|
-
return {
|
|
93
|
-
stepType: 'quillReviewAnswer',
|
|
94
|
-
id: this.id,
|
|
95
|
-
to: this.to ?? null,
|
|
96
|
-
written: this.written.map((w) => ({ ...w, before: w.before.toJSON() }))
|
|
97
|
-
};
|
|
72
|
+
return { stepType: 'quillReviewAnswer', id: this.id, to: this.to ?? null };
|
|
98
73
|
}
|
|
99
|
-
static fromJSON(
|
|
100
|
-
return new ReviewAnswer(json.id, json.to ?? undefined
|
|
74
|
+
static fromJSON(_schema, json) {
|
|
75
|
+
return new ReviewAnswer(json.id, json.to ?? undefined);
|
|
101
76
|
}
|
|
102
77
|
}
|
|
103
78
|
Step.jsonID('quillReviewAnswer', ReviewAnswer);
|
|
104
|
-
function answering(state, id, to
|
|
105
|
-
let next = state;
|
|
106
|
-
if (state.written.has(id) || written) {
|
|
107
|
-
const all = new Map(state.written);
|
|
108
|
-
if (written)
|
|
109
|
-
all.set(id, written);
|
|
110
|
-
else
|
|
111
|
-
all.delete(id);
|
|
112
|
-
next = { ...next, written: all };
|
|
113
|
-
}
|
|
79
|
+
function answering(state, id, to) {
|
|
114
80
|
if (state.answered.get(id) === to)
|
|
115
|
-
return
|
|
81
|
+
return state;
|
|
116
82
|
const answered = new Map(state.answered);
|
|
117
83
|
if (to)
|
|
118
84
|
answered.set(id, to);
|
|
119
85
|
else
|
|
120
86
|
answered.delete(id);
|
|
121
|
-
return { ...
|
|
87
|
+
return { ...state, answered };
|
|
122
88
|
}
|
|
123
89
|
function applyReview(tr, state) {
|
|
124
90
|
let next = state.replayed.length ? { ...state, replayed: [] } : state;
|
|
125
91
|
if (tr.docChanged && !tr.getMeta(remoteKey))
|
|
126
92
|
next = { ...next, edits: next.edits + 1 };
|
|
127
|
-
if (tr.docChanged && next.written.size) {
|
|
128
|
-
const all = new Map();
|
|
129
|
-
for (const [id, written] of next.written) {
|
|
130
|
-
const moved = mapWritten(written, tr.mapping);
|
|
131
|
-
if (moved)
|
|
132
|
-
all.set(id, moved);
|
|
133
|
-
}
|
|
134
|
-
next = { ...next, written: all };
|
|
135
|
-
}
|
|
136
93
|
const history = isHistoryTransaction(tr);
|
|
137
|
-
tr.steps.forEach((step
|
|
94
|
+
tr.steps.forEach((step) => {
|
|
138
95
|
if (!(step instanceof ReviewAnswer))
|
|
139
96
|
return;
|
|
140
|
-
|
|
141
|
-
next = answering(next, step.id, step.to, written || undefined);
|
|
97
|
+
next = answering(next, step.id, step.to);
|
|
142
98
|
// Reported whether or not the answer is still held: the host's list may have dropped it.
|
|
143
99
|
if (history)
|
|
144
100
|
next = { ...next, replayed: [...next.replayed, { id: step.id, to: step.to }] };
|
|
@@ -221,14 +177,10 @@ function tail(doc, from) {
|
|
|
221
177
|
});
|
|
222
178
|
return out;
|
|
223
179
|
}
|
|
224
|
-
/**
|
|
225
|
-
*
|
|
226
|
-
|
|
227
|
-
* schema holds.
|
|
228
|
-
*/
|
|
229
|
-
function taking(state, plan, anchors) {
|
|
180
|
+
/** The edit that takes a proposal: its pieces, last first, so each still stands where it was
|
|
181
|
+
* read. `undefined` where the pieces no longer make a document the schema holds. */
|
|
182
|
+
function taking(state, plan) {
|
|
230
183
|
const tr = state.tr;
|
|
231
|
-
const made = [];
|
|
232
184
|
try {
|
|
233
185
|
for (const piece of [...plan].sort((a, b) => b.from - a.from)) {
|
|
234
186
|
let { from, to } = piece;
|
|
@@ -240,12 +192,10 @@ function taking(state, plan, anchors) {
|
|
|
240
192
|
}
|
|
241
193
|
// A leaf holds a block at the least: its last one is emptied where it stands.
|
|
242
194
|
if (from === 0 && to === tr.doc.content.size) {
|
|
243
|
-
made.push({ from, to, before: tr.doc.slice(from, to), step: tr.steps.length });
|
|
244
195
|
tr.replaceWith(from, to, tr.doc.type.createAndFill().content);
|
|
245
196
|
continue;
|
|
246
197
|
}
|
|
247
198
|
}
|
|
248
|
-
made.push({ from, to, before: tr.doc.slice(from, to), step: tr.steps.length });
|
|
249
199
|
tr.replaceWith(from, to, arriving(tr.doc, piece.content));
|
|
250
200
|
}
|
|
251
201
|
tr.doc.check();
|
|
@@ -253,34 +203,7 @@ function taking(state, plan, anchors) {
|
|
|
253
203
|
catch {
|
|
254
204
|
return undefined;
|
|
255
205
|
}
|
|
256
|
-
|
|
257
|
-
return undefined;
|
|
258
|
-
const written = made.map(({ from, to, before, step }) => {
|
|
259
|
-
const after = tr.mapping.slice(step);
|
|
260
|
-
const swallowed = anchors
|
|
261
|
-
.filter((a) => a.end > a.start && from <= a.start && a.end <= to)
|
|
262
|
-
.map((a) => ({ id: a.id, start: a.start - from, end: a.end - from }));
|
|
263
|
-
return { from: after.map(from, -1), to: after.map(to, 1), before, anchors: swallowed };
|
|
264
|
-
});
|
|
265
|
-
return { tr: closeHistory(tr), written };
|
|
266
|
-
}
|
|
267
|
-
/** The reader's edit that takes back what proposal `id` wrote, wherever the stretches have
|
|
268
|
-
* moved to and whatever was typed inside them, so the proposal is open again. */
|
|
269
|
-
function putBack(state, id, written, channel) {
|
|
270
|
-
const tr = state.tr;
|
|
271
|
-
const made = [];
|
|
272
|
-
for (const w of [...written].sort((a, b) => b.from - a.from)) {
|
|
273
|
-
made.push({ w, step: tr.steps.length });
|
|
274
|
-
tr.replace(w.from, w.to, w.before);
|
|
275
|
-
}
|
|
276
|
-
const back = made.map(({ w, step }) => {
|
|
277
|
-
const after = tr.mapping.slice(step);
|
|
278
|
-
return { ...w, from: after.map(w.from, -1), to: after.map(w.to, 1) };
|
|
279
|
-
});
|
|
280
|
-
const anchors = back.flatMap((w) => (w.anchors ?? []).map((a) => ({ id: a.id, start: w.from + a.start, end: w.from + a.end })));
|
|
281
|
-
if (anchors.length)
|
|
282
|
-
channel.restore?.(tr, anchors);
|
|
283
|
-
return closeHistory(tr.step(new ReviewAnswer(id, undefined, back)));
|
|
206
|
+
return tr.docChanged ? closeHistory(tr) : undefined;
|
|
284
207
|
}
|
|
285
208
|
/** The marks on each offset of a textblock's content. */
|
|
286
209
|
function marksOf(block) {
|
|
@@ -518,7 +441,7 @@ function readOf(ids, before, channel) {
|
|
|
518
441
|
return out;
|
|
519
442
|
}
|
|
520
443
|
function draw(state, channel, act, bases) {
|
|
521
|
-
const { answered,
|
|
444
|
+
const { answered, renamed } = reviewKey.getState(state);
|
|
522
445
|
const now = (id) => nowOf(renamed, id);
|
|
523
446
|
const listed = channel.items();
|
|
524
447
|
// A base outlives its item's answer and its leaving the list while a block it covered
|
|
@@ -534,17 +457,14 @@ function draw(state, channel, act, bases) {
|
|
|
534
457
|
if (!ids.has(id) && !stands(base.place))
|
|
535
458
|
bases.delete(id);
|
|
536
459
|
}
|
|
537
|
-
const items = answered.size
|
|
538
|
-
? listed.filter((item) => !answered.has(item.id) || written.has(item.id))
|
|
539
|
-
: listed;
|
|
460
|
+
const items = answered.size ? listed.filter((item) => !answered.has(item.id)) : listed;
|
|
540
461
|
const plans = new Map();
|
|
541
462
|
const undrawn = [];
|
|
542
463
|
const outdated = [];
|
|
543
|
-
const accepted = [];
|
|
544
464
|
const decos = [];
|
|
545
465
|
const lighting = new Set();
|
|
546
466
|
if (!items.length)
|
|
547
|
-
return { decos, lighting, spans: [], plans, outdated, undrawn
|
|
467
|
+
return { decos, lighting, spans: [], plans, outdated, undrawn };
|
|
548
468
|
const { doc } = state;
|
|
549
469
|
const strings = channel.strings();
|
|
550
470
|
const serializer = DOMSerializer.fromSchema(state.schema);
|
|
@@ -558,56 +478,7 @@ function draw(state, channel, act, bases) {
|
|
|
558
478
|
* a paragraph's end, or `-1` for the head of the leaf. */
|
|
559
479
|
const taken = new Set();
|
|
560
480
|
const adding = new Set();
|
|
561
|
-
/** A taken proposal's mark over `[from, to)`, or its wedge where text was only taken out. */
|
|
562
|
-
const changed = (id, from, to) => {
|
|
563
|
-
if (to > from) {
|
|
564
|
-
lights(id, (on) => Decoration.inline(from, to, {
|
|
565
|
-
class: on ? 'qm-review-changed qm-review-lit' : 'qm-review-changed',
|
|
566
|
-
'data-qm-review': id
|
|
567
|
-
}));
|
|
568
|
-
return;
|
|
569
|
-
}
|
|
570
|
-
lights(id, (on) => Decoration.widget(from, () => {
|
|
571
|
-
const el = document.createElement('span');
|
|
572
|
-
el.className = on ? 'qm-review-gone qm-review-lit' : 'qm-review-gone';
|
|
573
|
-
el.contentEditable = 'false';
|
|
574
|
-
el.setAttribute('data-qm-review', id);
|
|
575
|
-
el.setAttribute('role', 'img');
|
|
576
|
-
el.setAttribute('aria-label', strings.reviewGone);
|
|
577
|
-
return el;
|
|
578
|
-
}, { side: -1, key: `gone:${id}:${on}` }));
|
|
579
|
-
};
|
|
580
481
|
for (const item of items) {
|
|
581
|
-
// A proposal taken here is drawn as the change it made, while the host lists it.
|
|
582
|
-
const wrote = written.get(item.id);
|
|
583
|
-
if (wrote) {
|
|
584
|
-
for (const w of wrote) {
|
|
585
|
-
// A wedge stands in a line: one where whole blocks went stands at the end of the
|
|
586
|
-
// line before, or the start of the one after.
|
|
587
|
-
const $at = doc.resolve(w.from);
|
|
588
|
-
if (w.to > w.from || $at.parent.inlineContent)
|
|
589
|
-
changed(item.id, w.from, w.to);
|
|
590
|
-
else {
|
|
591
|
-
const at = Selection.findFrom($at, -1, true) ?? Selection.findFrom($at, 1, true);
|
|
592
|
-
if (at)
|
|
593
|
-
changed(item.id, at.from, at.from);
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
spans.push({
|
|
597
|
-
id: item.id,
|
|
598
|
-
proposed: false,
|
|
599
|
-
from: Math.min(...wrote.map((w) => w.from)),
|
|
600
|
-
to: Math.max(...wrote.map((w) => w.to))
|
|
601
|
-
});
|
|
602
|
-
accepted.push({
|
|
603
|
-
id: item.id,
|
|
604
|
-
before: wrote
|
|
605
|
-
.map((w) => w.before.content.textBetween(0, w.before.content.size, '\n'))
|
|
606
|
-
.filter(Boolean)
|
|
607
|
-
.join('\n')
|
|
608
|
-
});
|
|
609
|
-
continue;
|
|
610
|
-
}
|
|
611
482
|
const name = { 'data-qm-review': item.id };
|
|
612
483
|
leaves ??= leavesOf(doc);
|
|
613
484
|
const at = placeOf(item, leaves, now);
|
|
@@ -784,13 +655,12 @@ function draw(state, channel, act, bases) {
|
|
|
784
655
|
// What a proposal only adds to has the caret anywhere in the block it adds from.
|
|
785
656
|
spans.push({
|
|
786
657
|
id: item.id,
|
|
787
|
-
proposed: true,
|
|
788
658
|
adds: !covered.length,
|
|
789
659
|
from: reach(covered[0] ?? last)[0],
|
|
790
660
|
to: reach(last)[1]
|
|
791
661
|
});
|
|
792
662
|
}
|
|
793
|
-
return { decos, lighting, spans, plans, outdated, undrawn
|
|
663
|
+
return { decos, lighting, spans, plans, outdated, undrawn };
|
|
794
664
|
}
|
|
795
665
|
/** Whether a block's last leaf is a textblock, so its last line can carry a run. */
|
|
796
666
|
function endsInLine(node) {
|
|
@@ -800,13 +670,12 @@ function endsInLine(node) {
|
|
|
800
670
|
return at.isTextblock;
|
|
801
671
|
}
|
|
802
672
|
/** The item the caret is in: the one it was put into by its id while it holds the caret, else
|
|
803
|
-
* the one that holds it closest, so a
|
|
804
|
-
*
|
|
805
|
-
|
|
806
|
-
function spanAt(spans, pos, entered, proposed = false) {
|
|
673
|
+
* the one that holds it closest, so of a proposal that rewrites a paragraph and one that adds
|
|
674
|
+
* after it, the one that rewrites. */
|
|
675
|
+
function spanAt(spans, pos, entered) {
|
|
807
676
|
let best;
|
|
808
677
|
for (const s of spans) {
|
|
809
|
-
if (s.from > pos || pos > s.to
|
|
678
|
+
if (s.from > pos || pos > s.to)
|
|
810
679
|
continue;
|
|
811
680
|
if (s.id === entered)
|
|
812
681
|
return s;
|
|
@@ -818,20 +687,15 @@ function spanAt(spans, pos, entered, proposed = false) {
|
|
|
818
687
|
return best;
|
|
819
688
|
}
|
|
820
689
|
/**
|
|
821
|
-
* The leaf's review layer. The decorations are a function of the document
|
|
822
|
-
*
|
|
690
|
+
* The leaf's review layer. The decorations are a function of the document and the channel's
|
|
691
|
+
* items, kept until one of them moves. The caret's report holds off while the reader
|
|
823
692
|
* types inside an item: an item is news on arriving in it, and noise under every keystroke.
|
|
824
693
|
*/
|
|
825
694
|
export function reviewLayer(channel) {
|
|
826
695
|
let memo;
|
|
827
696
|
/** The decorations of what is drawn, with the lit item they were made for. */
|
|
828
697
|
let shown;
|
|
829
|
-
const NOTHING = JSON.stringify({
|
|
830
|
-
ids: [],
|
|
831
|
-
outdated: [],
|
|
832
|
-
undrawn: [],
|
|
833
|
-
accepted: []
|
|
834
|
-
});
|
|
698
|
+
const NOTHING = JSON.stringify({ ids: [], outdated: [], undrawn: [] });
|
|
835
699
|
let reported = NOTHING;
|
|
836
700
|
let host;
|
|
837
701
|
const bases = new Map();
|
|
@@ -842,20 +706,11 @@ export function reviewLayer(channel) {
|
|
|
842
706
|
const view = host;
|
|
843
707
|
if (!view || !drawn(view.state).spans.some((span) => span.id === id))
|
|
844
708
|
return false;
|
|
845
|
-
const wrote = reviewKey.getState(view.state).written.get(id);
|
|
846
|
-
if (wrote) {
|
|
847
|
-
if (action === 'accept' || action === 'dismiss')
|
|
848
|
-
return false;
|
|
849
|
-
view.dispatch(putBack(view.state, id, wrote, channel));
|
|
850
|
-
channel.act(id, 'reopen', how.chord);
|
|
851
|
-
return true;
|
|
852
|
-
}
|
|
853
709
|
if (action === 'accept') {
|
|
854
710
|
const plan = drawn(view.state).plans.get(id);
|
|
855
|
-
const
|
|
856
|
-
if (!
|
|
711
|
+
const tr = plan && taking(view.state, plan);
|
|
712
|
+
if (!tr || !plan)
|
|
857
713
|
return false;
|
|
858
|
-
const { tr } = took;
|
|
859
714
|
const away = !how.quiet && !view.hasFocus();
|
|
860
715
|
if (away) {
|
|
861
716
|
const end = tr.mapping.map(Math.max(...plan.map((piece) => piece.to)), 1);
|
|
@@ -863,7 +718,7 @@ export function reviewLayer(channel) {
|
|
|
863
718
|
}
|
|
864
719
|
channel.writing?.(true);
|
|
865
720
|
try {
|
|
866
|
-
view.dispatch(tr.step(new ReviewAnswer(id, 'accept'
|
|
721
|
+
view.dispatch(tr.step(new ReviewAnswer(id, 'accept')));
|
|
867
722
|
}
|
|
868
723
|
finally {
|
|
869
724
|
channel.writing?.(false);
|
|
@@ -881,18 +736,16 @@ export function reviewLayer(channel) {
|
|
|
881
736
|
};
|
|
882
737
|
const drawn = (state) => {
|
|
883
738
|
const review = reviewKey.getState(state);
|
|
884
|
-
const anchors = channel.anchors(state);
|
|
885
739
|
const items = channel.items();
|
|
886
740
|
const strings = channel.strings();
|
|
887
741
|
if (memo &&
|
|
888
742
|
memo.doc === state.doc &&
|
|
889
743
|
memo.review === review &&
|
|
890
|
-
memo.anchors === anchors &&
|
|
891
744
|
memo.items === items &&
|
|
892
745
|
memo.strings === strings)
|
|
893
746
|
return memo.drawn;
|
|
894
747
|
const next = draw(state, channel, act, bases);
|
|
895
|
-
memo = { doc: state.doc, review,
|
|
748
|
+
memo = { doc: state.doc, review, items, strings, drawn: next };
|
|
896
749
|
return next;
|
|
897
750
|
};
|
|
898
751
|
/** Whether the lit item moving to `lit` changes how anything here reads. */
|
|
@@ -913,8 +766,8 @@ export function reviewLayer(channel) {
|
|
|
913
766
|
};
|
|
914
767
|
/** Tell the channel what the leaf draws, where that moved. */
|
|
915
768
|
const report = (state) => {
|
|
916
|
-
const { spans, outdated, undrawn
|
|
917
|
-
const next = { ids: spans.map((s) => s.id), outdated, undrawn
|
|
769
|
+
const { spans, outdated, undrawn } = drawn(state);
|
|
770
|
+
const next = { ids: spans.map((s) => s.id), outdated, undrawn };
|
|
918
771
|
const joined = JSON.stringify(next);
|
|
919
772
|
if (joined === reported)
|
|
920
773
|
return;
|
|
@@ -949,18 +802,10 @@ export function reviewLayer(channel) {
|
|
|
949
802
|
channel.point(next, 'caret');
|
|
950
803
|
};
|
|
951
804
|
const answer = (action) => (state) => {
|
|
952
|
-
const span = spanAt(drawn(state).spans, state.selection.head, reviewKey.getState(state)?.entered
|
|
805
|
+
const span = spanAt(drawn(state).spans, state.selection.head, reviewKey.getState(state)?.entered);
|
|
953
806
|
if (!span)
|
|
954
807
|
return false;
|
|
955
|
-
act(span.id,
|
|
956
|
-
return true;
|
|
957
|
-
};
|
|
958
|
-
/** Escape lowers the card over the item the caret is in, before it is anything else's. */
|
|
959
|
-
const lower = (state) => {
|
|
960
|
-
const id = channel.shown();
|
|
961
|
-
if (id === undefined || !drawn(state).spans.some((span) => span.id === id))
|
|
962
|
-
return false;
|
|
963
|
-
channel.dismiss();
|
|
808
|
+
act(span.id, action, { chord: true });
|
|
964
809
|
return true;
|
|
965
810
|
};
|
|
966
811
|
const plugin = new Plugin({
|
|
@@ -969,7 +814,6 @@ export function reviewLayer(channel) {
|
|
|
969
814
|
init: () => ({
|
|
970
815
|
edits: 0,
|
|
971
816
|
answered: new Map(),
|
|
972
|
-
written: new Map(),
|
|
973
817
|
entered: undefined,
|
|
974
818
|
replayed: [],
|
|
975
819
|
renamed: new Map()
|
|
@@ -980,8 +824,7 @@ export function reviewLayer(channel) {
|
|
|
980
824
|
decorations,
|
|
981
825
|
handleKeyDown: keydownHandler({
|
|
982
826
|
[REVIEW_KEYS.accept]: answer('accept'),
|
|
983
|
-
[REVIEW_KEYS.dismiss]: answer('dismiss')
|
|
984
|
-
Escape: lower
|
|
827
|
+
[REVIEW_KEYS.dismiss]: answer('dismiss')
|
|
985
828
|
}),
|
|
986
829
|
handleDOMEvents: {
|
|
987
830
|
mouseover: (_view, e) => {
|
|
@@ -1024,7 +867,7 @@ export function reviewLayer(channel) {
|
|
|
1024
867
|
if (caret !== undefined)
|
|
1025
868
|
channel.point(undefined, 'caret');
|
|
1026
869
|
if (reported !== NOTHING)
|
|
1027
|
-
channel.drew({ ids: [], outdated: [], undrawn: []
|
|
870
|
+
channel.drew({ ids: [], outdated: [], undrawn: [] });
|
|
1028
871
|
host = undefined;
|
|
1029
872
|
}
|
|
1030
873
|
};
|
package/dist/core/theme.css
CHANGED
|
@@ -215,13 +215,11 @@
|
|
|
215
215
|
ratio `default` steps the ink. What is drawn over it in the card's colour, the
|
|
216
216
|
thumb and the check, holds 3:1 at both poles, at 3.3:1 and 4.2:1. */
|
|
217
217
|
--_qm-accent-default: color-mix(in oklab, var(--_qm-accent), var(--_qm-bg) 20%);
|
|
218
|
-
/* The review hue, three ways. `tint` is held under the words a proposal would add
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
would take, and a changed field's edge, held back so it sits under a link's
|
|
224
|
-
underline rather than beside it. */
|
|
218
|
+
/* The review hue, three ways. `tint` is held under the words a proposal would add, at
|
|
219
|
+
the strength the accent's own tint is held under body text plus what a state resting
|
|
220
|
+
on a well has to clear. `lit` is that tint under attention: the pointer over the
|
|
221
|
+
item, the caret in it, a host revealing it. `line` is the stroke through the words a
|
|
222
|
+
proposal would take, held back so it reads under the ink rather than as it. */
|
|
225
223
|
--_qm-review-tint: color-mix(in oklab, var(--_qm-review) 20%, transparent);
|
|
226
224
|
--_qm-review-lit: color-mix(in oklab, var(--_qm-review) 34%, transparent);
|
|
227
225
|
--_qm-review-line: color-mix(in oklab, var(--_qm-review) 60%, transparent);
|
package/dist/visual/Field.svelte
CHANGED
|
@@ -318,22 +318,16 @@
|
|
|
318
318
|
* rather than counted twice.
|
|
319
319
|
*/
|
|
320
320
|
// ── Review: this field's own items (`review.svelte.ts`) ──────────────────────
|
|
321
|
-
// A
|
|
322
|
-
//
|
|
323
|
-
// to, as the pointer and the caret are a mark's.
|
|
321
|
+
// A proposal rests as a row under the control. The focus in the control attends to it, as
|
|
322
|
+
// the caret in a leaf's words attends to theirs.
|
|
324
323
|
const reviewing = review();
|
|
325
324
|
const reviewed = $derived(reviewing.at(leafKey));
|
|
326
|
-
const changed = $derived(reviewed.changed);
|
|
327
325
|
const proposed = $derived(reviewed.proposed);
|
|
328
326
|
/** The items naming a place inside this field: a record's and a list's own controls draw
|
|
329
327
|
* them where they are, any other's under this one. */
|
|
330
328
|
const nestedReview = $derived(reviewed.nested);
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
* proposal. */
|
|
334
|
-
const attended = $derived(changed ?? proposed);
|
|
335
|
-
/** The chords, with the focus anywhere in the field: a proposal's answers, else an accepted
|
|
336
|
-
* one taken back. A prose leaf's own items answer first, in the leaf. */
|
|
329
|
+
/** The chords, with the focus anywhere in the field: the proposal's answers. A prose leaf's
|
|
330
|
+
* own items answer first, in the leaf. */
|
|
337
331
|
const reviewKeys = keydownHandler({
|
|
338
332
|
[REVIEW_KEYS.accept]: () => {
|
|
339
333
|
if (!proposed) return false;
|
|
@@ -341,14 +335,13 @@
|
|
|
341
335
|
return true;
|
|
342
336
|
},
|
|
343
337
|
[REVIEW_KEYS.dismiss]: () => {
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
reviewing.act(item.id, proposed ? 'dismiss' : 'reopen', true);
|
|
338
|
+
if (!proposed) return false;
|
|
339
|
+
reviewing.act(proposed.id, 'dismiss', true);
|
|
347
340
|
return true;
|
|
348
341
|
}
|
|
349
342
|
});
|
|
350
343
|
function onReviewKey(e: KeyboardEvent): void {
|
|
351
|
-
if (e.defaultPrevented ||
|
|
344
|
+
if (e.defaultPrevented || !proposed) return;
|
|
352
345
|
// The bindings read no view: this is `prosemirror-keymap`'s chord matcher alone.
|
|
353
346
|
if (reviewKeys({} as never, e)) e.preventDefault();
|
|
354
347
|
}
|
|
@@ -385,17 +378,13 @@
|
|
|
385
378
|
level and measures the same. -->
|
|
386
379
|
<div class="qm-field-stack">
|
|
387
380
|
<div
|
|
388
|
-
class=
|
|
389
|
-
data-qm-review={changed?.id}
|
|
381
|
+
class="qm-field-control qm-wash"
|
|
390
382
|
{@attach registerControl}
|
|
391
383
|
onfocusin={(e) => {
|
|
392
384
|
reportFocus?.(e);
|
|
393
|
-
if (
|
|
385
|
+
if (proposed) reviewing.point(proposed.id, 'caret', leafKey);
|
|
394
386
|
}}
|
|
395
|
-
onfocusout={() =>
|
|
396
|
-
oninput={() => changed && reviewing.point(undefined, 'caret')}
|
|
397
|
-
onpointerenter={() => changed && reviewing.point(changed.id, 'pointer')}
|
|
398
|
-
onpointerleave={() => changed && reviewing.point(undefined, 'pointer')}
|
|
387
|
+
onfocusout={() => proposed && reviewing.point(undefined, 'caret', leafKey)}
|
|
399
388
|
>
|
|
400
389
|
{#if field.control === 'prose'}
|
|
401
390
|
<ProseField
|
|
@@ -614,21 +603,4 @@
|
|
|
614
603
|
.qm-field-control {
|
|
615
604
|
border-radius: var(--_qm-radius-inner);
|
|
616
605
|
}
|
|
617
|
-
/* A value someone else set is underlined as a changed word is: the same stroke along the
|
|
618
|
-
control's foot, and under attention the tint a lit word takes. A plane over the
|
|
619
|
-
control, as the wash is, so it reads the same over a well, a switch and a subform, and
|
|
620
|
-
lifted over the control's own positioned box. */
|
|
621
|
-
.qm-field-control.qm-review-set::before {
|
|
622
|
-
content: '';
|
|
623
|
-
position: absolute;
|
|
624
|
-
inset: 0;
|
|
625
|
-
border-radius: inherit;
|
|
626
|
-
box-shadow: inset 0 calc(-1 * var(--_qm-vertical-width)) 0 var(--_qm-review-line);
|
|
627
|
-
z-index: 1;
|
|
628
|
-
pointer-events: none;
|
|
629
|
-
transition: background-color var(--_qm-duration-fast) var(--_qm-ease-reverse);
|
|
630
|
-
}
|
|
631
|
-
.qm-field-control.qm-review-set.qm-review-lit::before {
|
|
632
|
-
background: var(--_qm-review-tint);
|
|
633
|
-
}
|
|
634
606
|
</style>
|
|
@@ -153,8 +153,6 @@
|
|
|
153
153
|
slash = next;
|
|
154
154
|
},
|
|
155
155
|
reviewStrings: () => t.strings,
|
|
156
|
-
reviewShown: () => reviewing.shown?.item.id,
|
|
157
|
-
onReviewDismiss: () => reviewing.dismiss(),
|
|
158
156
|
onReview: (id, action, chord) => reviewing.heard(id, action, leafKey, chord),
|
|
159
157
|
onReviewPoint: (id, via) => reviewing.point(id, via, leafKey),
|
|
160
158
|
onReviewWriting: (on) => reviewing.writing(on),
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
<!--
|
|
2
2
|
The review items a container hands to one of its places, drawn under that place's control:
|
|
3
|
-
a proposal as the value that would go and the value that would come with its two
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
each a proposal, as the value that would go and the value that would come with its two
|
|
4
|
+
answers. An item naming a place deeper than the control under which it is drawn, which no
|
|
5
|
+
control of its own draws, leads with where it is: the cells and members between, by name and
|
|
6
|
+
number.
|
|
7
7
|
-->
|
|
8
8
|
<script lang="ts">
|
|
9
9
|
import type { PathStep } from '@quillmark/wasm';
|
|
10
10
|
import ReviewProposal from './ReviewProposal.svelte';
|
|
11
|
-
import {
|
|
12
|
-
import { review } from './review.svelte.js';
|
|
11
|
+
import { valueIn, type DeepReview } from './review.js';
|
|
13
12
|
import { wording } from './strings.js';
|
|
14
13
|
import { humanize } from './structure.js';
|
|
15
14
|
|
|
@@ -23,7 +22,6 @@
|
|
|
23
22
|
let { entries, value, member = false }: Props = $props();
|
|
24
23
|
|
|
25
24
|
const t = wording();
|
|
26
|
-
const reviewing = review();
|
|
27
25
|
|
|
28
26
|
const where = (steps: readonly PathStep[]): string | undefined =>
|
|
29
27
|
steps.length
|
|
@@ -36,33 +34,10 @@
|
|
|
36
34
|
</script>
|
|
37
35
|
|
|
38
36
|
{#each entries ?? [] as { steps, item } (item.id)}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
(steps.length ? typeof steps.at(-1) === 'number' : member)}
|
|
46
|
-
/>
|
|
47
|
-
{:else}
|
|
48
|
-
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
49
|
-
<div
|
|
50
|
-
class={['qm-review-line', { 'qm-review-lit': reviewing.lit === item.id }]}
|
|
51
|
-
data-qm-review={item.id}
|
|
52
|
-
onpointerenter={() => reviewing.point(item.id, 'pointer')}
|
|
53
|
-
onpointerleave={() => reviewing.point(undefined, 'pointer')}
|
|
54
|
-
></div>
|
|
55
|
-
{/if}
|
|
37
|
+
<ReviewProposal
|
|
38
|
+
{item}
|
|
39
|
+
value={valueIn(value, steps)}
|
|
40
|
+
label={where(steps)}
|
|
41
|
+
removes={item.after === undefined && (steps.length ? typeof steps.at(-1) === 'number' : member)}
|
|
42
|
+
/>
|
|
56
43
|
{/each}
|
|
57
|
-
|
|
58
|
-
<style>
|
|
59
|
-
/* The line a changed control carries along its foot (`Field.svelte`), under the place it
|
|
60
|
-
changed, at the vertical width the surface draws a stroke at. */
|
|
61
|
-
.qm-review-line {
|
|
62
|
-
height: var(--_qm-vertical-width);
|
|
63
|
-
background: var(--_qm-review-line);
|
|
64
|
-
}
|
|
65
|
-
.qm-review-line.qm-review-lit {
|
|
66
|
-
box-shadow: 0 0 0 var(--_qm-vertical-width) var(--_qm-review-tint);
|
|
67
|
-
}
|
|
68
|
-
</style>
|
|
@@ -107,17 +107,16 @@
|
|
|
107
107
|
inner?.applyCardOps(ops);
|
|
108
108
|
}
|
|
109
109
|
/** Bring the review item `id` to the reader: its panel opened, scrolled to the middle of
|
|
110
|
-
* the view, lit
|
|
110
|
+
* the view, lit. The focus stays put unless `focus` sends the caret into
|
|
111
111
|
* the item, where its chords answer. False for an item not drawn. */
|
|
112
112
|
export async function revealReview(id: string, opts?: { focus?: boolean }): Promise<boolean> {
|
|
113
113
|
return (await inner?.revealReview(id, opts)) ?? false;
|
|
114
114
|
}
|
|
115
115
|
/** Answer items as their buttons would, in document order (`'all'`: every item drawn),
|
|
116
|
-
* moving neither the focus nor the caret and raising no toast
|
|
117
|
-
* accepted proposals. Returns the ids answered. */
|
|
116
|
+
* moving neither the focus nor the caret and raising no toast. Returns the ids answered. */
|
|
118
117
|
export function answerReview(
|
|
119
118
|
ids: readonly string[] | 'all',
|
|
120
|
-
action: 'accept' | 'dismiss'
|
|
119
|
+
action: 'accept' | 'dismiss'
|
|
121
120
|
): string[] {
|
|
122
121
|
return inner?.answerReview(ids, action) ?? [];
|
|
123
122
|
}
|