@quillmark/svelte 0.35.1 → 0.37.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 +30 -18
- package/THEMING.md +1 -1
- package/dist/core/address.d.ts +5 -0
- package/dist/core/address.js +14 -0
- package/dist/core/codec/decode.d.ts +4 -2
- package/dist/core/codec/decode.js +5 -2
- package/dist/core/codec/field.d.ts +42 -16
- package/dist/core/codec/field.js +97 -28
- package/dist/core/codec/index.d.ts +8 -5
- package/dist/core/codec/index.js +4 -5
- package/dist/core/codec/prose.css +25 -81
- package/dist/core/codec/review.d.ts +31 -26
- package/dist/core/codec/review.js +93 -169
- package/dist/core/codec/schema.d.ts +12 -2
- package/dist/core/codec/schema.js +27 -5
- package/dist/core/codec/shortcuts.d.ts +5 -4
- package/dist/core/codec/shortcuts.js +9 -8
- package/dist/core/codec/table-view.js +15 -3
- package/dist/core/codec/value-diff.d.ts +21 -0
- package/dist/core/codec/value-diff.js +83 -0
- package/dist/core/codec/value-plan.d.ts +29 -0
- package/dist/core/codec/value-plan.js +157 -0
- package/dist/core/theme.css +46 -15
- package/dist/core/tooltip.css +49 -0
- package/dist/core/tooltip.d.ts +6 -0
- package/dist/core/tooltip.js +176 -0
- package/dist/preview/Preview.svelte +22 -1
- package/dist/preview/controller.js +38 -0
- package/dist/preview/strings.d.ts +2 -0
- package/dist/preview/strings.js +1 -0
- package/dist/visual/ArrayField.svelte +374 -96
- package/dist/visual/Card.svelte +33 -12
- package/dist/visual/Card.svelte.d.ts +3 -0
- package/dist/visual/CardControls.svelte +3 -3
- package/dist/visual/DateField.svelte +47 -5
- package/dist/visual/DiagnosticList.svelte +3 -2
- package/dist/visual/EnumField.svelte +20 -5
- package/dist/visual/EnumField.svelte.d.ts +5 -0
- package/dist/visual/Field.svelte +56 -47
- package/dist/visual/FieldHint.svelte +20 -8
- package/dist/visual/FormatPopover.svelte +54 -20
- package/dist/visual/MatrixField.svelte +48 -6
- package/dist/visual/MatrixField.svelte.d.ts +5 -0
- package/dist/visual/NumberField.svelte +131 -6
- package/dist/visual/NumberField.svelte.d.ts +5 -0
- package/dist/visual/ObjectField.svelte +60 -18
- package/dist/visual/ProseField.svelte +21 -5
- package/dist/visual/ProseField.svelte.d.ts +5 -1
- package/dist/visual/ProseValue.svelte +49 -8
- package/dist/visual/ProseValue.svelte.d.ts +7 -1
- package/dist/visual/ReviewCard.svelte +400 -0
- package/dist/visual/ReviewCard.svelte.d.ts +20 -0
- package/dist/visual/ReviewProposal.svelte +98 -138
- package/dist/visual/ReviewProposal.svelte.d.ts +3 -6
- package/dist/visual/ReviewRows.svelte +6 -25
- package/dist/visual/ReviewRows.svelte.d.ts +1 -3
- package/dist/visual/SlashMenu.svelte +1 -0
- package/dist/visual/TipsCard.svelte +1 -1
- package/dist/visual/VariantField.svelte +45 -4
- package/dist/visual/VariantField.svelte.d.ts +5 -0
- package/dist/visual/VisualEditor.svelte +24 -9
- package/dist/visual/VisualEditor.svelte.d.ts +8 -1
- package/dist/visual/VisualEditorInner.svelte +917 -280
- package/dist/visual/VisualEditorInner.svelte.d.ts +8 -1
- package/dist/visual/controls.css +2 -2
- package/dist/visual/index.d.ts +2 -2
- package/dist/visual/proposals.d.ts +25 -24
- package/dist/visual/proposals.js +92 -32
- package/dist/visual/props.d.ts +18 -18
- package/dist/visual/review-order.d.ts +51 -0
- package/dist/visual/review-order.js +87 -0
- package/dist/visual/review.d.ts +94 -3
- package/dist/visual/review.js +37 -2
- package/dist/visual/review.svelte.d.ts +77 -20
- package/dist/visual/review.svelte.js +306 -49
- package/dist/visual/strings.d.ts +59 -25
- package/dist/visual/strings.js +90 -29
- package/dist/visual/structure.d.ts +17 -3
- package/dist/visual/structure.js +71 -5
- package/dist/visual/undo.svelte.d.ts +3 -1
- package/dist/visual/undo.svelte.js +7 -3
- package/package.json +2 -2
|
@@ -17,22 +17,12 @@
|
|
|
17
17
|
// transaction, one undo step, one commit.
|
|
18
18
|
import { closeHistory, isHistoryTransaction, undo } from 'prosemirror-history';
|
|
19
19
|
import { DOMSerializer, Fragment, Mark } from 'prosemirror-model';
|
|
20
|
-
import { keydownHandler } from 'prosemirror-keymap';
|
|
21
20
|
import { Plugin, PluginKey, Selection } from 'prosemirror-state';
|
|
22
|
-
import { Step, StepResult } from 'prosemirror-transform';
|
|
21
|
+
import { Mapping, Step, StepResult } from 'prosemirror-transform';
|
|
23
22
|
import { Decoration, DecorationSet } from 'prosemirror-view';
|
|
24
23
|
import { arriving, HARD_BREAK, ISLAND_SLOT } from './islands.js';
|
|
25
24
|
import { remoteKey } from './remote.js';
|
|
26
25
|
import { wordDiff } from './review-diff.js';
|
|
27
|
-
import { REVIEW_KEYS } from './shortcuts.js';
|
|
28
|
-
export const DEFAULT_REVIEW_STRINGS = {
|
|
29
|
-
reviewAccept: 'Accept',
|
|
30
|
-
reviewDismiss: 'Dismiss',
|
|
31
|
-
reviewAcceptTitle: 'Accept',
|
|
32
|
-
reviewDismissTitle: 'Dismiss',
|
|
33
|
-
reviewProposal: 'Proposed change',
|
|
34
|
-
reviewOutdated: 'Edited since'
|
|
35
|
-
};
|
|
36
26
|
const reviewKey = new PluginKey('quill-review');
|
|
37
27
|
/** Tell the review layer the store took blocks under new ids, each `[was, now]`. */
|
|
38
28
|
export function renameBlocks(tr, renamed) {
|
|
@@ -182,22 +172,8 @@ function tail(doc, from) {
|
|
|
182
172
|
function taking(state, plan) {
|
|
183
173
|
const tr = state.tr;
|
|
184
174
|
try {
|
|
185
|
-
for (const piece of [...plan].sort((a, b) => b.from - a.from))
|
|
186
|
-
|
|
187
|
-
if (piece.lift) {
|
|
188
|
-
const $at = tr.doc.resolve(from);
|
|
189
|
-
for (let d = $at.depth; d > 0 && $at.node(d).childCount === 1; d--) {
|
|
190
|
-
from = $at.before(d);
|
|
191
|
-
to = $at.after(d);
|
|
192
|
-
}
|
|
193
|
-
// A leaf holds a block at the least: its last one is emptied where it stands.
|
|
194
|
-
if (from === 0 && to === tr.doc.content.size) {
|
|
195
|
-
tr.replaceWith(from, to, tr.doc.type.createAndFill().content);
|
|
196
|
-
continue;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
tr.replaceWith(from, to, arriving(tr.doc, piece.content));
|
|
200
|
-
}
|
|
175
|
+
for (const piece of [...plan].sort((a, b) => b.from - a.from))
|
|
176
|
+
writePiece(tr, piece);
|
|
201
177
|
tr.doc.check();
|
|
202
178
|
}
|
|
203
179
|
catch {
|
|
@@ -205,6 +181,78 @@ function taking(state, plan) {
|
|
|
205
181
|
}
|
|
206
182
|
return tr.docChanged ? closeHistory(tr) : undefined;
|
|
207
183
|
}
|
|
184
|
+
/** One piece of a plan written into `tr`, at its place in the document the plan was read over. */
|
|
185
|
+
function writePiece(tr, piece) {
|
|
186
|
+
let { from, to } = piece;
|
|
187
|
+
if (piece.lift) {
|
|
188
|
+
const $at = tr.doc.resolve(from);
|
|
189
|
+
for (let d = $at.depth; d > 0 && $at.node(d).childCount === 1; d--) {
|
|
190
|
+
from = $at.before(d);
|
|
191
|
+
to = $at.after(d);
|
|
192
|
+
}
|
|
193
|
+
// A leaf holds a block at the least: its last one is emptied where it stands.
|
|
194
|
+
if (from === 0 && to === tr.doc.content.size) {
|
|
195
|
+
tr.replaceWith(from, to, tr.doc.type.createAndFill().content);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
tr.replaceWith(from, to, arriving(tr.doc, piece.content));
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Every proposal the leaf draws, taken from the plans it draws them from. The pieces of every
|
|
203
|
+
* plan are written in one pass, last first, which is what taking them one at a time writes,
|
|
204
|
+
* since no two proposals the leaf draws share a stretch; where the pieces of two do not make a
|
|
205
|
+
* document together, each is planned again over what the one before it left, as a batch of
|
|
206
|
+
* accepts plans it.
|
|
207
|
+
*/
|
|
208
|
+
function projecting(state, now, redraw) {
|
|
209
|
+
const ids = now.spans.map((span) => span.id);
|
|
210
|
+
if (!ids.length)
|
|
211
|
+
return undefined;
|
|
212
|
+
const pieces = ids.flatMap((id) => (now.plans.get(id) ?? []).map((piece) => ({ id, piece })));
|
|
213
|
+
pieces.sort((a, b) => b.piece.from - a.piece.from);
|
|
214
|
+
const tr = state.tr;
|
|
215
|
+
const adds = [];
|
|
216
|
+
try {
|
|
217
|
+
for (const { id, piece } of pieces) {
|
|
218
|
+
const step = tr.steps.length;
|
|
219
|
+
writePiece(tr, piece);
|
|
220
|
+
if (piece.from === piece.to && piece.content.firstChild?.isBlock)
|
|
221
|
+
adds.push({ id, at: piece.from, step });
|
|
222
|
+
}
|
|
223
|
+
tr.doc.check();
|
|
224
|
+
}
|
|
225
|
+
catch {
|
|
226
|
+
return oneByOne(state, ids, redraw);
|
|
227
|
+
}
|
|
228
|
+
const next = state.apply(tr);
|
|
229
|
+
if (next === state)
|
|
230
|
+
return undefined;
|
|
231
|
+
const added = adds.map(({ id, at, step }) => {
|
|
232
|
+
const after = tr.mapping.slice(step);
|
|
233
|
+
return { id, from: after.map(at, -1), to: after.map(at, 1) };
|
|
234
|
+
});
|
|
235
|
+
return { state: next, ids, mapping: tr.mapping, added };
|
|
236
|
+
}
|
|
237
|
+
/** {@link projecting}, each proposal planned over what the one before it left. */
|
|
238
|
+
function oneByOne(state, ids, redraw) {
|
|
239
|
+
const mapping = new Mapping();
|
|
240
|
+
const taken = [];
|
|
241
|
+
let at = state;
|
|
242
|
+
for (const id of ids) {
|
|
243
|
+
const plan = redraw(at).plans.get(id);
|
|
244
|
+
const tr = plan && taking(at, plan);
|
|
245
|
+
if (!tr)
|
|
246
|
+
continue;
|
|
247
|
+
const next = at.apply(tr);
|
|
248
|
+
if (next === at)
|
|
249
|
+
continue;
|
|
250
|
+
mapping.appendMapping(tr.mapping);
|
|
251
|
+
taken.push(id);
|
|
252
|
+
at = next;
|
|
253
|
+
}
|
|
254
|
+
return taken.length ? { state: at, ids: taken, mapping, added: [] } : undefined;
|
|
255
|
+
}
|
|
208
256
|
/** The marks on each offset of a textblock's content. */
|
|
209
257
|
function marksOf(block) {
|
|
210
258
|
const out = [];
|
|
@@ -335,60 +383,6 @@ const rewritten = (() => {
|
|
|
335
383
|
return out;
|
|
336
384
|
};
|
|
337
385
|
})();
|
|
338
|
-
/** A chord as `aria-keyshortcuts` spells it, `Mod` as either platform's. */
|
|
339
|
-
const ariaKeys = (chord) => ['Meta', 'Control'].map((mod) => chord.replace('Mod', mod).replaceAll('-', '+')).join(' ');
|
|
340
|
-
function button(act, id, action, label, title, keys) {
|
|
341
|
-
const el = document.createElement('button');
|
|
342
|
-
el.type = 'button';
|
|
343
|
-
el.tabIndex = -1;
|
|
344
|
-
el.className = `qm-review-act qm-review-${action}`;
|
|
345
|
-
el.textContent = label;
|
|
346
|
-
el.title = title;
|
|
347
|
-
el.setAttribute('aria-keyshortcuts', ariaKeys(keys));
|
|
348
|
-
// The press keeps the caret where it is: the answer is about the text, not a move off it.
|
|
349
|
-
el.addEventListener('mousedown', (e) => e.preventDefault());
|
|
350
|
-
el.addEventListener('click', (e) => {
|
|
351
|
-
e.preventDefault();
|
|
352
|
-
act(id, action);
|
|
353
|
-
});
|
|
354
|
-
return el;
|
|
355
|
-
}
|
|
356
|
-
/** A proposal's two buttons: a run at the end of its last line, or a row of their own under a
|
|
357
|
-
* block that has no line to end. */
|
|
358
|
-
function chip(strings, act, id, row, outdated) {
|
|
359
|
-
const el = document.createElement(row ? 'div' : 'span');
|
|
360
|
-
el.className = ['qm-review-chip', row && 'qm-review-chip-row', outdated && 'qm-review-outdated']
|
|
361
|
-
.filter(Boolean)
|
|
362
|
-
.join(' ');
|
|
363
|
-
el.contentEditable = 'false';
|
|
364
|
-
el.setAttribute('data-qm-review', id);
|
|
365
|
-
el.setAttribute('role', 'group');
|
|
366
|
-
el.setAttribute('aria-label', strings.reviewProposal);
|
|
367
|
-
const acts = document.createElement('span');
|
|
368
|
-
acts.className = 'qm-review-acts';
|
|
369
|
-
if (outdated) {
|
|
370
|
-
const label = document.createElement('span');
|
|
371
|
-
label.className = 'qm-review-outdated-label';
|
|
372
|
-
label.textContent = strings.reviewOutdated;
|
|
373
|
-
acts.append(label);
|
|
374
|
-
}
|
|
375
|
-
acts.append(button(act, id, 'accept', strings.reviewAccept, strings.reviewAcceptTitle, REVIEW_KEYS.accept), button(act, id, 'dismiss', strings.reviewDismiss, strings.reviewDismissTitle, REVIEW_KEYS.dismiss));
|
|
376
|
-
// The space a run of answers stands off its line by, which a wrapped run leaves behind.
|
|
377
|
-
el.append(row ? '' : ' ', acts);
|
|
378
|
-
return el;
|
|
379
|
-
}
|
|
380
|
-
/** The last textblock's element under `el`, where a run can be appended to its last line. */
|
|
381
|
-
function lastLine(el) {
|
|
382
|
-
let at = el;
|
|
383
|
-
for (;;) {
|
|
384
|
-
if (/^(P|H[1-6]|CODE)$/.test(at.tagName))
|
|
385
|
-
return at;
|
|
386
|
-
const last = at.lastElementChild;
|
|
387
|
-
if (!(last instanceof HTMLElement))
|
|
388
|
-
return undefined;
|
|
389
|
-
at = last;
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
386
|
/** The id of the stored block a leaf decodes from: a block island's own, any other's `id`. */
|
|
393
387
|
function blockOf(node) {
|
|
394
388
|
return String((node.type.name === 'island_block' ? node.attrs.block : node.attrs.id) ?? '');
|
|
@@ -440,7 +434,7 @@ function readOf(ids, before, channel) {
|
|
|
440
434
|
row.set(before, out);
|
|
441
435
|
return out;
|
|
442
436
|
}
|
|
443
|
-
function draw(state, channel,
|
|
437
|
+
function draw(state, channel, bases) {
|
|
444
438
|
const { answered, renamed } = reviewKey.getState(state);
|
|
445
439
|
const now = (id) => nowOf(renamed, id);
|
|
446
440
|
const listed = channel.items();
|
|
@@ -466,7 +460,6 @@ function draw(state, channel, act, bases) {
|
|
|
466
460
|
if (!items.length)
|
|
467
461
|
return { decos, lighting, spans: [], plans, outdated, undrawn };
|
|
468
462
|
const { doc } = state;
|
|
469
|
-
const strings = channel.strings();
|
|
470
463
|
const serializer = DOMSerializer.fromSchema(state.schema);
|
|
471
464
|
const lights = (id, make) => {
|
|
472
465
|
lighting.add(id);
|
|
@@ -594,13 +587,6 @@ function draw(state, channel, act, bases) {
|
|
|
594
587
|
const $last = doc.resolve(last.pos);
|
|
595
588
|
/** Past the outermost block holding the last one, or the head of the leaf. */
|
|
596
589
|
const outer = ahead ? 0 : $last.depth ? $last.after(1) : last.pos + last.node.nodeSize;
|
|
597
|
-
const row = () => {
|
|
598
|
-
decos.push(Decoration.widget(outer, () => chip(strings, act, item.id, true, stale), {
|
|
599
|
-
side: ahead ? -1 : 9999,
|
|
600
|
-
key: `chip:${item.id}:row:${stale}`,
|
|
601
|
-
stopEvent: () => true
|
|
602
|
-
}));
|
|
603
|
-
};
|
|
604
590
|
if (added.length) {
|
|
605
591
|
// A proposal that continues the list its paragraph is in adds items to that list.
|
|
606
592
|
const listed = !ahead &&
|
|
@@ -620,10 +606,7 @@ function draw(state, channel, act, bases) {
|
|
|
620
606
|
else
|
|
621
607
|
plan.push({ from: piece.at, to: piece.at, content: Fragment.from(piece.node) });
|
|
622
608
|
}
|
|
623
|
-
const closing = pieces.length - 1;
|
|
624
|
-
const chipped = endsInLine(pieces[closing].node);
|
|
625
609
|
pieces.forEach((piece, n) => {
|
|
626
|
-
const holds = chipped && n === closing;
|
|
627
610
|
lights(item.id, (on) => Decoration.widget(piece.at, () => {
|
|
628
611
|
const el = serializer.serializeNode(piece.node);
|
|
629
612
|
el.classList.add('qm-review-add');
|
|
@@ -631,44 +614,24 @@ function draw(state, channel, act, bases) {
|
|
|
631
614
|
el.classList.add('qm-review-lit');
|
|
632
615
|
el.contentEditable = 'false';
|
|
633
616
|
el.setAttribute('data-qm-review', item.id);
|
|
634
|
-
if (holds)
|
|
635
|
-
lastLine(el)?.append(chip(strings, act, item.id, false, stale));
|
|
636
617
|
return el;
|
|
637
618
|
}, {
|
|
638
619
|
side: ahead ? -1000 + n : 1 + n,
|
|
639
|
-
key: `add:${item.id}:${n}:${on}:${piece.node.toString()}
|
|
640
|
-
stopEvent: (e) => e.target?.closest?.('.qm-review-chip') != null
|
|
620
|
+
key: `add:${item.id}:${n}:${on}:${piece.node.toString()}`
|
|
641
621
|
}));
|
|
642
622
|
});
|
|
643
|
-
if (!chipped)
|
|
644
|
-
row();
|
|
645
623
|
}
|
|
646
|
-
else if (last.node.isTextblock) {
|
|
647
|
-
decos.push(Decoration.widget(reach(last)[1], () => chip(strings, act, item.id, false, stale), {
|
|
648
|
-
side: 1,
|
|
649
|
-
key: `chip:${item.id}:${stale}`,
|
|
650
|
-
stopEvent: () => true
|
|
651
|
-
}));
|
|
652
|
-
}
|
|
653
|
-
else
|
|
654
|
-
row();
|
|
655
624
|
// What a proposal only adds to has the caret anywhere in the block it adds from.
|
|
656
625
|
spans.push({
|
|
657
626
|
id: item.id,
|
|
658
627
|
adds: !covered.length,
|
|
628
|
+
ahead,
|
|
659
629
|
from: reach(covered[0] ?? last)[0],
|
|
660
630
|
to: reach(last)[1]
|
|
661
631
|
});
|
|
662
632
|
}
|
|
663
633
|
return { decos, lighting, spans, plans, outdated, undrawn };
|
|
664
634
|
}
|
|
665
|
-
/** Whether a block's last leaf is a textblock, so its last line can carry a run. */
|
|
666
|
-
function endsInLine(node) {
|
|
667
|
-
let at = node;
|
|
668
|
-
while (!at.isTextblock && !at.isAtom && at.lastChild)
|
|
669
|
-
at = at.lastChild;
|
|
670
|
-
return at.isTextblock;
|
|
671
|
-
}
|
|
672
635
|
/** The item the caret is in: the one it was put into by its id while it holds the caret, else
|
|
673
636
|
* the one that holds it closest, so of a proposal that rewrites a paragraph and one that adds
|
|
674
637
|
* after it, the one that rewrites. */
|
|
@@ -699,10 +662,9 @@ export function reviewLayer(channel) {
|
|
|
699
662
|
let reported = NOTHING;
|
|
700
663
|
let host;
|
|
701
664
|
const bases = new Map();
|
|
702
|
-
/** Answer an item
|
|
703
|
-
*
|
|
704
|
-
|
|
705
|
-
const act = (id, action, how = {}) => {
|
|
665
|
+
/** Answer an item, moving neither the caret nor the focus. Taking a proposal writes it
|
|
666
|
+
* first, and one that can no longer be written stays as it is. */
|
|
667
|
+
const act = (id, action) => {
|
|
706
668
|
const view = host;
|
|
707
669
|
if (!view || !drawn(view.state).spans.some((span) => span.id === id))
|
|
708
670
|
return false;
|
|
@@ -711,11 +673,6 @@ export function reviewLayer(channel) {
|
|
|
711
673
|
const tr = plan && taking(view.state, plan);
|
|
712
674
|
if (!tr || !plan)
|
|
713
675
|
return false;
|
|
714
|
-
const away = !how.quiet && !view.hasFocus();
|
|
715
|
-
if (away) {
|
|
716
|
-
const end = tr.mapping.map(Math.max(...plan.map((piece) => piece.to)), 1);
|
|
717
|
-
tr.setSelection(Selection.near(tr.doc.resolve(Math.min(end, tr.doc.content.size)), -1));
|
|
718
|
-
}
|
|
719
676
|
channel.writing?.(true);
|
|
720
677
|
try {
|
|
721
678
|
view.dispatch(tr.step(new ReviewAnswer(id, 'accept')));
|
|
@@ -723,29 +680,22 @@ export function reviewLayer(channel) {
|
|
|
723
680
|
finally {
|
|
724
681
|
channel.writing?.(false);
|
|
725
682
|
}
|
|
726
|
-
if (away)
|
|
727
|
-
view.focus();
|
|
728
683
|
}
|
|
729
684
|
else {
|
|
730
685
|
view.dispatch(view.state.tr
|
|
731
686
|
.setMeta(reviewKey, { answer: { id, to: 'dismiss' } })
|
|
732
687
|
.setMeta('addToHistory', false));
|
|
733
688
|
}
|
|
734
|
-
channel.act(id, action
|
|
689
|
+
channel.act(id, action);
|
|
735
690
|
return true;
|
|
736
691
|
};
|
|
737
692
|
const drawn = (state) => {
|
|
738
693
|
const review = reviewKey.getState(state);
|
|
739
694
|
const items = channel.items();
|
|
740
|
-
|
|
741
|
-
if (memo &&
|
|
742
|
-
memo.doc === state.doc &&
|
|
743
|
-
memo.review === review &&
|
|
744
|
-
memo.items === items &&
|
|
745
|
-
memo.strings === strings)
|
|
695
|
+
if (memo && memo.doc === state.doc && memo.review === review && memo.items === items)
|
|
746
696
|
return memo.drawn;
|
|
747
|
-
const next = draw(state, channel,
|
|
748
|
-
memo = { doc: state.doc, review, items,
|
|
697
|
+
const next = draw(state, channel, bases);
|
|
698
|
+
memo = { doc: state.doc, review, items, drawn: next };
|
|
749
699
|
return next;
|
|
750
700
|
};
|
|
751
701
|
/** Whether the lit item moving to `lit` changes how anything here reads. */
|
|
@@ -767,21 +717,15 @@ export function reviewLayer(channel) {
|
|
|
767
717
|
/** Tell the channel what the leaf draws, where that moved. */
|
|
768
718
|
const report = (state) => {
|
|
769
719
|
const { spans, outdated, undrawn } = drawn(state);
|
|
770
|
-
const
|
|
720
|
+
const turn = (s) => (s.ahead ? 0 : s.adds ? 2 : 1);
|
|
721
|
+
const placed = [...spans].sort((a, b) => a.from - b.from || turn(a) - turn(b));
|
|
722
|
+
const next = { ids: placed.map((s) => s.id), outdated, undrawn };
|
|
771
723
|
const joined = JSON.stringify(next);
|
|
772
724
|
if (joined === reported)
|
|
773
725
|
return;
|
|
774
726
|
reported = joined;
|
|
775
727
|
channel.drew(next);
|
|
776
728
|
};
|
|
777
|
-
let hovered;
|
|
778
|
-
const hover = (id) => {
|
|
779
|
-
if (id === hovered)
|
|
780
|
-
return;
|
|
781
|
-
hovered = id;
|
|
782
|
-
channel.point(id, 'pointer');
|
|
783
|
-
};
|
|
784
|
-
const idAt = (target) => (target instanceof Element ? target.closest('[data-qm-review]') : null)?.getAttribute('data-qm-review') ?? undefined;
|
|
785
729
|
let caret;
|
|
786
730
|
/** The item the reader typed in, quiet until the caret has left it. */
|
|
787
731
|
let muted;
|
|
@@ -799,14 +743,7 @@ export function reviewLayer(channel) {
|
|
|
799
743
|
if (next === caret)
|
|
800
744
|
return;
|
|
801
745
|
caret = next;
|
|
802
|
-
channel.point(next
|
|
803
|
-
};
|
|
804
|
-
const answer = (action) => (state) => {
|
|
805
|
-
const span = spanAt(drawn(state).spans, state.selection.head, reviewKey.getState(state)?.entered);
|
|
806
|
-
if (!span)
|
|
807
|
-
return false;
|
|
808
|
-
act(span.id, action, { chord: true });
|
|
809
|
-
return true;
|
|
746
|
+
channel.point(next);
|
|
810
747
|
};
|
|
811
748
|
const plugin = new Plugin({
|
|
812
749
|
key: reviewKey,
|
|
@@ -822,19 +759,7 @@ export function reviewLayer(channel) {
|
|
|
822
759
|
},
|
|
823
760
|
props: {
|
|
824
761
|
decorations,
|
|
825
|
-
handleKeyDown: keydownHandler({
|
|
826
|
-
[REVIEW_KEYS.accept]: answer('accept'),
|
|
827
|
-
[REVIEW_KEYS.dismiss]: answer('dismiss')
|
|
828
|
-
}),
|
|
829
762
|
handleDOMEvents: {
|
|
830
|
-
mouseover: (_view, e) => {
|
|
831
|
-
hover(idAt(e.target));
|
|
832
|
-
return false;
|
|
833
|
-
},
|
|
834
|
-
mouseleave: () => {
|
|
835
|
-
hover(undefined);
|
|
836
|
-
return false;
|
|
837
|
-
},
|
|
838
763
|
focus: (view) => {
|
|
839
764
|
follow(view, false);
|
|
840
765
|
return false;
|
|
@@ -862,10 +787,8 @@ export function reviewLayer(channel) {
|
|
|
862
787
|
follow(view, reviewKey.getState(prev)?.edits !== reviewKey.getState(view.state)?.edits);
|
|
863
788
|
},
|
|
864
789
|
destroy() {
|
|
865
|
-
if (hovered !== undefined)
|
|
866
|
-
channel.point(undefined, 'pointer');
|
|
867
790
|
if (caret !== undefined)
|
|
868
|
-
channel.point(undefined
|
|
791
|
+
channel.point(undefined);
|
|
869
792
|
if (reported !== NOTHING)
|
|
870
793
|
channel.drew({ ids: [], outdated: [], undrawn: [] });
|
|
871
794
|
host = undefined;
|
|
@@ -878,7 +801,7 @@ export function reviewLayer(channel) {
|
|
|
878
801
|
refresh(view) {
|
|
879
802
|
// Only the lit item moved, and nothing here reads it: the leaf is left alone.
|
|
880
803
|
const lit = channel.lit();
|
|
881
|
-
if (memo?.items === channel.items() &&
|
|
804
|
+
if (memo?.items === channel.items() && !relit(lit)) {
|
|
882
805
|
if (shown)
|
|
883
806
|
shown.lit = lit;
|
|
884
807
|
return;
|
|
@@ -896,7 +819,7 @@ export function reviewLayer(channel) {
|
|
|
896
819
|
elements(view, id) {
|
|
897
820
|
return [...view.dom.querySelectorAll('[data-qm-review]')].filter((el) => el.getAttribute('data-qm-review') === id);
|
|
898
821
|
},
|
|
899
|
-
answer:
|
|
822
|
+
answer: act,
|
|
900
823
|
reopen(view, id) {
|
|
901
824
|
if (reviewKey.getState(view.state)?.answered.get(id) === 'dismiss')
|
|
902
825
|
view.dispatch(view.state.tr
|
|
@@ -905,6 +828,7 @@ export function reviewLayer(channel) {
|
|
|
905
828
|
channel.act(id, 'reopen');
|
|
906
829
|
},
|
|
907
830
|
undo: (view) => undo(view.state, view.dispatch),
|
|
831
|
+
project: (state) => projecting(state, drawn(state), (at) => at === state ? drawn(state) : draw(at, channel, new Map(bases))),
|
|
908
832
|
enter(view, id) {
|
|
909
833
|
const span = drawn(view.state).spans.find((s) => s.id === id);
|
|
910
834
|
if (!span)
|
|
@@ -21,17 +21,27 @@ export declare const plaintextSchema: Schema<string, never>;
|
|
|
21
21
|
*/
|
|
22
22
|
export declare const cellSchema: Schema<"hard_break", string>;
|
|
23
23
|
/**
|
|
24
|
-
* A `text` field declaring `
|
|
24
|
+
* A `text` field declaring `shape: lines`: paragraphs and hard breaks, no marks, islands or
|
|
25
25
|
* containers, the shape `Content::is_plain` admits. Its literal text spells a break as a `\n` and a
|
|
26
26
|
* paragraph boundary as a blank line.
|
|
27
27
|
*/
|
|
28
28
|
export declare const plainSchema: Schema<"text" | "paragraph" | "hard_break" | "doc", never>;
|
|
29
|
+
/**
|
|
30
|
+
* A `richtext` field declaring `shape: lines`: the plain schema with the full mark set, the shape
|
|
31
|
+
* `Content::is_lines` admits. Formatted lines with no list, heading, quote, code block or island.
|
|
32
|
+
*/
|
|
33
|
+
export declare const linesSchema: Schema<"text" | "paragraph" | "hard_break" | "doc", string>;
|
|
29
34
|
/** The schema a leaf of the declared type mounts: `inline` narrows either type to one
|
|
30
|
-
* textblock,
|
|
35
|
+
* textblock, `plaintext` takes its marks away, and `paragraphs` holds a `richtext` to
|
|
36
|
+
* paragraphs and hard breaks. */
|
|
31
37
|
export declare function leafSchema(opts: {
|
|
32
38
|
plaintext?: boolean;
|
|
33
39
|
inline?: boolean;
|
|
40
|
+
paragraphs?: boolean;
|
|
34
41
|
}): Schema;
|
|
42
|
+
/** True for the two schemas of paragraphs and hard breaks alone, {@link plainSchema} and
|
|
43
|
+
* {@link linesSchema}: what a leaf's literal clipboard mounts on. */
|
|
44
|
+
export declare function isParagraphsSchema(schema: Schema): boolean;
|
|
35
45
|
/** Whether `schema` can carry formatting at all: false for the two mark-free schemas.
|
|
36
46
|
* What a mark command asks before it offers itself. */
|
|
37
47
|
export declare function hasMarks(schema: Schema): boolean;
|
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
// formatting set. Each set is closed upstream, so the schema names its whole vocabulary.
|
|
4
4
|
// `blockSchema` is the full field; `inlineSchema` the single-textblock form for a one-line
|
|
5
5
|
// `richtext`; `plaintextSchema` that without marks, for a one-line `text`; `plainSchema` a `text`
|
|
6
|
-
// field declaring `
|
|
7
|
-
//
|
|
6
|
+
// field declaring `shape: lines` (paragraphs and hard breaks only); `linesSchema` that with marks,
|
|
7
|
+
// for a `richtext` field declaring `shape: lines`; `cellSchema` the inline form with hard breaks,
|
|
8
|
+
// for a table cell. Anchors are not marks here (decorations).
|
|
8
9
|
//
|
|
9
10
|
// `toDOM` and `parseDOM` are one tier: a copy and a paste inside one body run the whole document
|
|
10
11
|
// through them (INVARIANTS §"Markdown at the edges"), so every attribute written here is read back here.
|
|
@@ -292,7 +293,7 @@ export const cellSchema = new Schema({
|
|
|
292
293
|
marks
|
|
293
294
|
});
|
|
294
295
|
/**
|
|
295
|
-
* A `text` field declaring `
|
|
296
|
+
* A `text` field declaring `shape: lines`: paragraphs and hard breaks, no marks, islands or
|
|
296
297
|
* containers, the shape `Content::is_plain` admits. Its literal text spells a break as a `\n` and a
|
|
297
298
|
* paragraph boundary as a blank line.
|
|
298
299
|
*/
|
|
@@ -305,12 +306,33 @@ export const plainSchema = new Schema({
|
|
|
305
306
|
},
|
|
306
307
|
marks: {}
|
|
307
308
|
});
|
|
309
|
+
/**
|
|
310
|
+
* A `richtext` field declaring `shape: lines`: the plain schema with the full mark set, the shape
|
|
311
|
+
* `Content::is_lines` admits. Formatted lines with no list, heading, quote, code block or island.
|
|
312
|
+
*/
|
|
313
|
+
export const linesSchema = new Schema({
|
|
314
|
+
nodes: {
|
|
315
|
+
doc: { content: 'paragraph+' },
|
|
316
|
+
paragraph: blockNodes.paragraph,
|
|
317
|
+
text: inlineLeafNodes.text,
|
|
318
|
+
hard_break: inlineLeafNodes.hard_break
|
|
319
|
+
},
|
|
320
|
+
marks
|
|
321
|
+
});
|
|
308
322
|
/** The schema a leaf of the declared type mounts: `inline` narrows either type to one
|
|
309
|
-
* textblock,
|
|
323
|
+
* textblock, `plaintext` takes its marks away, and `paragraphs` holds a `richtext` to
|
|
324
|
+
* paragraphs and hard breaks. */
|
|
310
325
|
export function leafSchema(opts) {
|
|
311
326
|
if (opts.plaintext)
|
|
312
327
|
return opts.inline ? plaintextSchema : plainSchema;
|
|
313
|
-
|
|
328
|
+
if (opts.inline)
|
|
329
|
+
return inlineSchema;
|
|
330
|
+
return opts.paragraphs ? linesSchema : blockSchema;
|
|
331
|
+
}
|
|
332
|
+
/** True for the two schemas of paragraphs and hard breaks alone, {@link plainSchema} and
|
|
333
|
+
* {@link linesSchema}: what a leaf's literal clipboard mounts on. */
|
|
334
|
+
export function isParagraphsSchema(schema) {
|
|
335
|
+
return schema === plainSchema || schema === linesSchema;
|
|
314
336
|
}
|
|
315
337
|
/** Whether `schema` can carry formatting at all: false for the two mark-free schemas.
|
|
316
338
|
* What a mark command asks before it offers itself. */
|
|
@@ -45,12 +45,13 @@ export declare const TABLE_KEYS: {
|
|
|
45
45
|
readonly erase: "Backspace";
|
|
46
46
|
readonly eraseAlt: "Delete";
|
|
47
47
|
};
|
|
48
|
-
/**
|
|
49
|
-
* so `accept` takes
|
|
50
|
-
*
|
|
48
|
+
/** The review's keys, the editor's wherever the focus is while a review is open and ahead of
|
|
49
|
+
* every other binding of them, so `accept` takes the current change over a task item's
|
|
50
|
+
* `LIST_KEYS.task` and `dismiss` over a text leaf's own delete; `next` and `previous` step
|
|
51
|
+
* through the changes. */
|
|
51
52
|
export declare const REVIEW_KEYS: {
|
|
52
53
|
readonly accept: "Mod-Enter";
|
|
53
|
-
readonly dismiss: "Mod
|
|
54
|
+
readonly dismiss: "Mod-Backspace";
|
|
54
55
|
readonly next: "Mod-Alt-ArrowDown";
|
|
55
56
|
readonly previous: "Mod-Alt-ArrowUp";
|
|
56
57
|
};
|
|
@@ -51,12 +51,13 @@ export const TABLE_KEYS = {
|
|
|
51
51
|
erase: 'Backspace',
|
|
52
52
|
eraseAlt: 'Delete'
|
|
53
53
|
};
|
|
54
|
-
/**
|
|
55
|
-
* so `accept` takes
|
|
56
|
-
*
|
|
54
|
+
/** The review's keys, the editor's wherever the focus is while a review is open and ahead of
|
|
55
|
+
* every other binding of them, so `accept` takes the current change over a task item's
|
|
56
|
+
* `LIST_KEYS.task` and `dismiss` over a text leaf's own delete; `next` and `previous` step
|
|
57
|
+
* through the changes. */
|
|
57
58
|
export const REVIEW_KEYS = {
|
|
58
59
|
accept: 'Mod-Enter',
|
|
59
|
-
dismiss: 'Mod
|
|
60
|
+
dismiss: 'Mod-Backspace',
|
|
60
61
|
next: 'Mod-Alt-ArrowDown',
|
|
61
62
|
previous: 'Mod-Alt-ArrowUp'
|
|
62
63
|
};
|
|
@@ -91,7 +92,7 @@ export const DEFAULT_SHORTCUT_STRINGS = {
|
|
|
91
92
|
shortcutBulletedList: 'Bulleted list',
|
|
92
93
|
shortcutIndent: 'Nest under the item above',
|
|
93
94
|
shortcutOutdent: 'Move back up a level',
|
|
94
|
-
shortcutTask: 'Check or uncheck a task, outside a
|
|
95
|
+
shortcutTask: 'Check or uncheck a task, outside a review',
|
|
95
96
|
shortcutMoveItem: 'Move the item up or down',
|
|
96
97
|
shortcutNextCell: 'Next cell, adding a row past the last',
|
|
97
98
|
shortcutPreviousCell: 'Previous cell',
|
|
@@ -102,9 +103,9 @@ export const DEFAULT_SHORTCUT_STRINGS = {
|
|
|
102
103
|
shortcutAlignColumn: 'Align a selected column',
|
|
103
104
|
shortcutDeleteCells: 'Delete the selected cells, rows or columns',
|
|
104
105
|
shortcutReviewAccept: 'Accept the proposed change',
|
|
105
|
-
shortcutReviewDismiss: 'Dismiss the proposed change
|
|
106
|
-
shortcutReviewNext: 'Go to the next
|
|
107
|
-
shortcutReviewPrevious: 'Go to the previous
|
|
106
|
+
shortcutReviewDismiss: 'Dismiss the proposed change',
|
|
107
|
+
shortcutReviewNext: 'Go to the next proposed change',
|
|
108
|
+
shortcutReviewPrevious: 'Go to the previous proposed change'
|
|
108
109
|
};
|
|
109
110
|
const F = FIELD_KEYS;
|
|
110
111
|
const L = LIST_KEYS;
|
|
@@ -113,12 +113,13 @@ function el(tag, className) {
|
|
|
113
113
|
}
|
|
114
114
|
/**
|
|
115
115
|
* A band button. It swallows its own `mousedown` (prosemirror-menu's trick) so the browser does not
|
|
116
|
-
* focus it and blur the cell whose caret the op is measured against.
|
|
116
|
+
* focus it and blur the cell whose caret the op is measured against. Its label is its accessible
|
|
117
|
+
* name and, the button drawing a glyph or nothing, its tip (`core/tooltip.ts`).
|
|
117
118
|
*/
|
|
118
119
|
function chromeButton(className, label, run) {
|
|
119
120
|
const btn = el('button', className);
|
|
120
121
|
btn.type = 'button';
|
|
121
|
-
btn.
|
|
122
|
+
btn.setAttribute('data-qm-tip', label);
|
|
122
123
|
btn.setAttribute('aria-label', label);
|
|
123
124
|
btn.addEventListener('mousedown', (e) => e.preventDefault());
|
|
124
125
|
btn.addEventListener('click', (e) => {
|
|
@@ -1376,6 +1377,7 @@ class TableIslandView {
|
|
|
1376
1377
|
const cluster = el('div', 'qm-table-align');
|
|
1377
1378
|
cluster.setAttribute('role', 'group');
|
|
1378
1379
|
cluster.setAttribute('aria-label', s.tableColumn(c + 1));
|
|
1380
|
+
cluster.setAttribute('data-qm-tip-side', 'bottom');
|
|
1379
1381
|
cluster.hidden = true;
|
|
1380
1382
|
// The cluster's own edge is no button, and a press on it would otherwise take the
|
|
1381
1383
|
// focus off the caret the write lands back on.
|
|
@@ -1403,6 +1405,7 @@ class TableIslandView {
|
|
|
1403
1405
|
headerToggle(header, s) {
|
|
1404
1406
|
const cluster = el('div', 'qm-table-align');
|
|
1405
1407
|
cluster.setAttribute('data-header', '');
|
|
1408
|
+
cluster.setAttribute('data-qm-tip-side', 'bottom');
|
|
1406
1409
|
cluster.hidden = true;
|
|
1407
1410
|
cluster.addEventListener('mousedown', (e) => e.preventDefault());
|
|
1408
1411
|
const btn = chromeButton('qm-table-align-option', s.tableHeaderToggle, () => {
|
|
@@ -1433,6 +1436,8 @@ class TableIslandView {
|
|
|
1433
1436
|
const btn = chromeButton('qm-table-cells-option', label, run);
|
|
1434
1437
|
btn.tabIndex = -1;
|
|
1435
1438
|
btn.textContent = label;
|
|
1439
|
+
// The label is drawn, and a tip would say it twice.
|
|
1440
|
+
btn.removeAttribute('data-qm-tip');
|
|
1436
1441
|
cluster.appendChild(btn);
|
|
1437
1442
|
}
|
|
1438
1443
|
return cluster;
|
|
@@ -1453,6 +1458,8 @@ class TableIslandView {
|
|
|
1453
1458
|
this.write(insertColumn(props, columnCount(props) - 1), { r: 0, c: columnCount(props) });
|
|
1454
1459
|
});
|
|
1455
1460
|
btn.setAttribute('data-axis', axis);
|
|
1461
|
+
if (axis === 'row')
|
|
1462
|
+
btn.setAttribute('data-qm-tip-side', 'bottom');
|
|
1456
1463
|
btn.tabIndex = -1;
|
|
1457
1464
|
btn.appendChild(el('span', 'qm-table-add-bar'));
|
|
1458
1465
|
return btn;
|
|
@@ -1468,7 +1475,12 @@ class TableIslandView {
|
|
|
1468
1475
|
doc: decode(cellContent(seed), cellSchema),
|
|
1469
1476
|
plugins: cellPlugins(this.cellKeys(r, c), () => this.outer)
|
|
1470
1477
|
}),
|
|
1471
|
-
attributes: {
|
|
1478
|
+
attributes: {
|
|
1479
|
+
role: 'textbox',
|
|
1480
|
+
'aria-multiline': 'true',
|
|
1481
|
+
'aria-label': name,
|
|
1482
|
+
class: 'qm-table-cell-editor'
|
|
1483
|
+
},
|
|
1472
1484
|
// A cell is one of the leaf's lines, so a reveal keeps the leaf's clearance, not PM's
|
|
1473
1485
|
// 5px default, and the same scroll padding (`reveal.ts`).
|
|
1474
1486
|
...revealProps(this.deps.clearance),
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Plugin, PluginKey } from 'prosemirror-state';
|
|
2
|
+
import type { Content } from '@quillmark/wasm';
|
|
3
|
+
/** A field's proposed value as the leaf draws it. */
|
|
4
|
+
export interface ValueProposal {
|
|
5
|
+
id: string;
|
|
6
|
+
/** The value the field would hold. */
|
|
7
|
+
after: Content;
|
|
8
|
+
/** The value as the proposal's writer read it, where it says. */
|
|
9
|
+
before?: Content;
|
|
10
|
+
/** It is the current item, drawn a step stronger. */
|
|
11
|
+
lit: boolean;
|
|
12
|
+
}
|
|
13
|
+
/** How a proposal stands against what the leaf holds: drawn and open, drawn and met by the
|
|
14
|
+
* reader's writing, or already read as proposed, so its Accept would write nothing. */
|
|
15
|
+
export type ValueState = 'open' | 'outdated' | 'applied';
|
|
16
|
+
export declare const valueDiffKey: PluginKey<void>;
|
|
17
|
+
/**
|
|
18
|
+
* The plugin, reading the proposal live: a caller that moves it redraws with `setProps`.
|
|
19
|
+
* `planned` hears, on each draw, how the proposal stands against what the leaf holds.
|
|
20
|
+
*/
|
|
21
|
+
export declare function valueDiffPlugin(read: () => ValueProposal | undefined, planned?: (id: string, state: ValueState) => void): Plugin;
|