@quillmark/svelte 0.33.0 → 0.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +73 -1
- package/THEMING.md +11 -10
- package/dist/core/codec/anchor.d.ts +12 -0
- package/dist/core/codec/anchor.js +39 -0
- package/dist/core/codec/drag-move.d.ts +11 -0
- package/dist/core/codec/drag-move.js +143 -0
- package/dist/core/codec/encode.js +14 -5
- package/dist/core/codec/field.d.ts +47 -1
- package/dist/core/codec/field.js +147 -38
- package/dist/core/codec/index.d.ts +8 -2
- package/dist/core/codec/index.js +9 -2
- package/dist/core/codec/islands.d.ts +4 -1
- package/dist/core/codec/islands.js +6 -0
- package/dist/core/codec/keymap.d.ts +3 -0
- package/dist/core/codec/keymap.js +13 -12
- package/dist/core/codec/leave.d.ts +17 -0
- package/dist/core/codec/leave.js +78 -0
- package/dist/core/codec/prose.css +217 -0
- package/dist/core/codec/review-diff.d.ts +12 -0
- package/dist/core/codec/review-diff.js +131 -0
- package/dist/core/codec/review.d.ts +131 -0
- package/dist/core/codec/review.js +1077 -0
- package/dist/core/codec/shortcuts.d.ts +20 -4
- package/dist/core/codec/shortcuts.js +27 -7
- package/dist/core/codec/slash.d.ts +3 -0
- package/dist/core/codec/slash.js +2 -1
- package/dist/core/codec/table-view.js +163 -25
- package/dist/core/codec/undo.d.ts +6 -0
- package/dist/core/codec/undo.js +25 -2
- package/dist/core/dragfollow.d.ts +18 -0
- package/dist/core/dragfollow.js +63 -0
- package/dist/core/theme.css +36 -7
- package/dist/preview/controller.js +16 -0
- package/dist/preview/strings.d.ts +4 -0
- package/dist/preview/strings.js +3 -1
- package/dist/visual/ArrayField.svelte +363 -57
- package/dist/visual/ArrayField.svelte.d.ts +5 -0
- package/dist/visual/BooleanField.svelte +60 -5
- package/dist/visual/BooleanField.svelte.d.ts +2 -1
- package/dist/visual/Card.svelte +27 -17
- package/dist/visual/CardControls.svelte +17 -7
- package/dist/visual/CardControls.svelte.d.ts +2 -0
- package/dist/visual/DateField.svelte +90 -39
- package/dist/visual/DateField.svelte.d.ts +2 -2
- package/dist/visual/Field.svelte +126 -6
- package/dist/visual/FieldHint.svelte +24 -9
- package/dist/visual/FieldLabel.svelte +128 -22
- package/dist/visual/FieldLabel.svelte.d.ts +9 -0
- package/dist/visual/FormatPopover.svelte +125 -20
- package/dist/visual/MatrixAdd.svelte +13 -6
- package/dist/visual/MatrixAdd.svelte.d.ts +3 -2
- package/dist/visual/MatrixField.svelte +36 -8
- package/dist/visual/NumberField.svelte +27 -6
- package/dist/visual/NumberField.svelte.d.ts +3 -0
- package/dist/visual/ObjectField.svelte +25 -1
- package/dist/visual/ObjectField.svelte.d.ts +6 -0
- package/dist/visual/ProseField.svelte +23 -0
- package/dist/visual/ProseField.svelte.d.ts +3 -0
- package/dist/visual/ProseValue.svelte +107 -17
- package/dist/visual/ProseValue.svelte.d.ts +18 -4
- package/dist/visual/ReviewPopover.svelte +179 -0
- package/dist/visual/ReviewPopover.svelte.d.ts +16 -0
- package/dist/visual/ReviewProposal.svelte +149 -0
- package/dist/visual/ReviewProposal.svelte.d.ts +15 -0
- package/dist/visual/ReviewRows.svelte +68 -0
- package/dist/visual/ReviewRows.svelte.d.ts +11 -0
- package/dist/visual/SlashMenu.svelte +13 -1
- package/dist/visual/SlashMenu.svelte.d.ts +2 -0
- package/dist/visual/VisualEditor.svelte +23 -0
- package/dist/visual/VisualEditor.svelte.d.ts +7 -0
- package/dist/visual/VisualEditorInner.svelte +671 -22
- package/dist/visual/VisualEditorInner.svelte.d.ts +7 -0
- package/dist/visual/controls.css +17 -2
- package/dist/visual/guidance.d.ts +12 -0
- package/dist/visual/guidance.js +37 -2
- package/dist/visual/icons/nodes.d.ts +14 -2
- package/dist/visual/icons/nodes.js +12 -1
- package/dist/visual/index.d.ts +6 -0
- package/dist/visual/index.js +2 -0
- package/dist/visual/listhistory.d.ts +36 -0
- package/dist/visual/listhistory.js +53 -0
- package/dist/visual/proposals.d.ts +40 -0
- package/dist/visual/proposals.js +219 -0
- package/dist/visual/props.d.ts +35 -0
- package/dist/visual/removed.d.ts +20 -0
- package/dist/visual/removed.js +30 -0
- package/dist/visual/review.d.ts +170 -0
- package/dist/visual/review.js +269 -0
- package/dist/visual/review.svelte.d.ts +106 -0
- package/dist/visual/review.svelte.js +356 -0
- package/dist/visual/rowdrag.svelte.js +44 -55
- package/dist/visual/strings.d.ts +48 -7
- package/dist/visual/strings.js +32 -7
- package/dist/visual/structure.d.ts +5 -0
- package/dist/visual/structure.js +1 -1
- package/dist/visual/undo.svelte.d.ts +40 -7
- package/dist/visual/undo.svelte.js +98 -25
- package/package.json +1 -1
package/dist/core/codec/field.js
CHANGED
|
@@ -26,11 +26,14 @@ import { anchorsFromContent } from './marks.js';
|
|
|
26
26
|
import { contentEqual, createReconciler } from './reconcile.js';
|
|
27
27
|
import { inputRulesPlugin, undoRuleKeymap } from './inputrules.js';
|
|
28
28
|
import { linebreakPlugin } from './breaks.js';
|
|
29
|
-
import { bodyKeymap } from './keymap.js';
|
|
29
|
+
import { bodyKeymap, holdsTab } from './keymap.js';
|
|
30
|
+
import { DEFAULT_LEAVE_STRINGS, leavePlugin } from './leave.js';
|
|
30
31
|
import { FIELD_KEYS, markKeymap } from './shortcuts.js';
|
|
31
32
|
import { remoteKey } from './remote.js';
|
|
33
|
+
import { DEFAULT_REVIEW_STRINGS, renameBlocks, reviewLayer } from './review.js';
|
|
32
34
|
import { blockSchema, isBlockSchema, isInlineSchema, leafSchema, plainSchema } from './schema.js';
|
|
33
35
|
import { linkPastePlugin } from './link-paste.js';
|
|
36
|
+
import { dragMovePlugin } from './drag-move.js';
|
|
34
37
|
import { linePastePlugin } from './line-paste.js';
|
|
35
38
|
import { listPastePlugin } from './list-paste.js';
|
|
36
39
|
import { markdownPastePlugin } from './markdown-paste.js';
|
|
@@ -43,6 +46,7 @@ import { taskPlugin } from './tasks.js';
|
|
|
43
46
|
import { DEFAULT_TABLE_STRINGS, tableNodeView } from './table-view.js';
|
|
44
47
|
import { DEFAULT_SLASH_STRINGS, focusSlashItem, runSlashItem, slashPlugin } from './slash.js';
|
|
45
48
|
const anchorKey = new PluginKey('quill-anchors');
|
|
49
|
+
const NO_ANCHORS = [];
|
|
46
50
|
const GHOSTS = 100;
|
|
47
51
|
/**
|
|
48
52
|
* Plugin-held anchors (PM coords), mapped through every edit's `StepMap` and mutated by an {@link
|
|
@@ -73,6 +77,11 @@ function anchorPlugin(seed) {
|
|
|
73
77
|
}
|
|
74
78
|
else if (edit?.op === 'reset')
|
|
75
79
|
anchors = edit.anchors;
|
|
80
|
+
else if (edit?.op === 'restore') {
|
|
81
|
+
const back = new Set(edit.anchors.map((a) => a.id));
|
|
82
|
+
anchors = [...anchors.filter((a) => !back.has(a.id)), ...edit.anchors];
|
|
83
|
+
ghosts = ghosts.filter((g) => !back.has(g.id));
|
|
84
|
+
}
|
|
76
85
|
return { anchors, ghosts: ghosts.slice(-GHOSTS) };
|
|
77
86
|
}
|
|
78
87
|
},
|
|
@@ -239,6 +248,8 @@ export function createField(opts) {
|
|
|
239
248
|
/** Whether the leaf holds a default nobody has written: the `data-default` mark. */
|
|
240
249
|
const unwritten = () => !!fallback && doc.getStored(addr) == null;
|
|
241
250
|
let defaulted = unwritten();
|
|
251
|
+
/** The document the leaf last held as its unwritten default, which an undo can return to. */
|
|
252
|
+
let unwrittenDoc;
|
|
242
253
|
// `known` is the codec's view of what the leaf holds: kept in sync after every
|
|
243
254
|
// own-edit so `reconcile` can tell an external change from the field's own.
|
|
244
255
|
const reconciler = createReconciler(shown());
|
|
@@ -250,6 +261,38 @@ export function createField(opts) {
|
|
|
250
261
|
// The views nested inside this leaf, one per table cell (`table-view.ts`): chrome asks the leaf
|
|
251
262
|
// which view holds the caret.
|
|
252
263
|
const nested = new Set();
|
|
264
|
+
// The review layer's live cells: the items and the lit one move by assignment and a re-render.
|
|
265
|
+
let reviewItems = [];
|
|
266
|
+
let reviewLit;
|
|
267
|
+
const parsed = new Map();
|
|
268
|
+
const review = plaintext
|
|
269
|
+
? undefined
|
|
270
|
+
: reviewLayer({
|
|
271
|
+
items: () => reviewItems,
|
|
272
|
+
lit: () => reviewLit,
|
|
273
|
+
strings: () => opts.reviewStrings?.() ?? DEFAULT_REVIEW_STRINGS,
|
|
274
|
+
anchors: (state) => anchorKey.getState(state)?.anchors ?? NO_ANCHORS,
|
|
275
|
+
restore: (tr, anchors) => tr.setMeta(anchorKey, { op: 'restore', anchors }),
|
|
276
|
+
parse: (markdown) => {
|
|
277
|
+
if (!parsed.has(markdown)) {
|
|
278
|
+
let node;
|
|
279
|
+
try {
|
|
280
|
+
node = decode(core().importMarkdown(markdown).content, schema);
|
|
281
|
+
}
|
|
282
|
+
catch {
|
|
283
|
+
node = undefined;
|
|
284
|
+
}
|
|
285
|
+
parsed.set(markdown, node);
|
|
286
|
+
}
|
|
287
|
+
return parsed.get(markdown);
|
|
288
|
+
},
|
|
289
|
+
shown: () => opts.reviewShown?.(),
|
|
290
|
+
dismiss: () => opts.onReviewDismiss?.(),
|
|
291
|
+
act: (id, action, chord) => opts.onReview?.(id, action, chord),
|
|
292
|
+
writing: (on) => opts.onReviewWriting?.(on),
|
|
293
|
+
point: (id, via) => opts.onReviewPoint?.(id, via),
|
|
294
|
+
drew: (report) => opts.onReviewDrawn?.(report)
|
|
295
|
+
});
|
|
253
296
|
// The menu's report channel; the vocabulary is the codec's own constant (`slash.ts`).
|
|
254
297
|
const slash = block ? opts.onSlash : undefined;
|
|
255
298
|
// Judged of the value being mounted rather than read off a diagnostic: a routed set
|
|
@@ -258,11 +301,19 @@ export function createField(opts) {
|
|
|
258
301
|
const holds = (rt) => !fitsLeaf(rt, { inline, plaintext, islands: true });
|
|
259
302
|
let held = holds(reconciler.last);
|
|
260
303
|
const named = proseAttributes(opts) ?? {};
|
|
261
|
-
const defaultNamed = {
|
|
304
|
+
const defaultNamed = {
|
|
305
|
+
...proseAttributes({
|
|
306
|
+
...opts,
|
|
307
|
+
describedBy: [opts.describedBy, opts.defaultNoteId].filter(Boolean).join(' ') || undefined
|
|
308
|
+
}),
|
|
309
|
+
'data-default': ''
|
|
310
|
+
};
|
|
262
311
|
const heldNamed = heldAttributes(opts, opts.heldNoteId);
|
|
263
312
|
const seeded = buildState(reconciler.last);
|
|
264
313
|
const state = seeded.state;
|
|
265
314
|
index = seeded.index;
|
|
315
|
+
if (defaulted)
|
|
316
|
+
unwrittenDoc = state.doc;
|
|
266
317
|
// The clearance PM's reveal keeps around the caret, in this leaf's own line box: PM's 5px
|
|
267
318
|
// default leaves the next typed line past the fold. Measured off the mounted box and dropped
|
|
268
319
|
// where the derivation is out of reach (jsdom).
|
|
@@ -313,8 +364,14 @@ export function createField(opts) {
|
|
|
313
364
|
// (d) the change signal, only for what actually landed.
|
|
314
365
|
const anchors = plaintext ? [] : readAnchors();
|
|
315
366
|
const newRt = scan ? scanContent(scan, anchors) : pmToContent(next.doc, anchors);
|
|
316
|
-
|
|
367
|
+
// An undo back to the default the leaf held unwritten takes the write back too.
|
|
368
|
+
const unwrite = !!unwrittenDoc && isHistoryTransaction(tr) && next.doc.eq(unwrittenDoc);
|
|
369
|
+
if (unwrite ? commitUnset() : commitEdit(oldRt, newRt))
|
|
317
370
|
opts.onChange?.(addr);
|
|
371
|
+
if (unwrite) {
|
|
372
|
+
defaulted = unwritten();
|
|
373
|
+
view.setProps({});
|
|
374
|
+
}
|
|
318
375
|
}
|
|
319
376
|
// The caret, for structural and selection-only changes, reported after the commit.
|
|
320
377
|
opts.onCaretMove?.(addr, pmToOffset(index, next.selection.head));
|
|
@@ -349,17 +406,50 @@ export function createField(opts) {
|
|
|
349
406
|
inline,
|
|
350
407
|
slash,
|
|
351
408
|
slashHint: () => (opts.slashStrings?.() ?? DEFAULT_SLASH_STRINGS).slashHint,
|
|
409
|
+
leaveStrings: opts.leaveStrings,
|
|
352
410
|
noInputRules: opts.noInputRules,
|
|
353
411
|
// Always installed, so a leaf that mounts without a ghost can still be
|
|
354
412
|
// given one later; the plugin draws nothing while the text is empty.
|
|
355
413
|
placeholder: () => placeholderText,
|
|
356
414
|
placeholderUntilEdit: opts.placeholderUntilEdit,
|
|
357
415
|
cap: opts.cap,
|
|
358
|
-
afterHistory: [anchorPlugin(seededAnchors)]
|
|
416
|
+
afterHistory: [anchorPlugin(seededAnchors), ...(review ? [review.plugin] : [])]
|
|
359
417
|
})
|
|
360
418
|
});
|
|
361
419
|
return { state: built, index: seedIndex };
|
|
362
420
|
}
|
|
421
|
+
/** Re-read the leaf from the document: the reconciler's own edit, a landed remote replace, or
|
|
422
|
+
* a rebuild. */
|
|
423
|
+
function reread(delta) {
|
|
424
|
+
const current = shown();
|
|
425
|
+
const flipped = holds(current) !== held;
|
|
426
|
+
const wasDefaulted = defaulted;
|
|
427
|
+
defaulted = unwritten();
|
|
428
|
+
if (!flipped && !reconciler.shouldRehydrate(current)) {
|
|
429
|
+
// Own edit / no change; a default written as itself changes the mark alone.
|
|
430
|
+
if (defaulted !== wasDefaulted)
|
|
431
|
+
view.setProps({});
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
if (!flipped && !held && landRemote(current, delta)) {
|
|
435
|
+
reconciler.commit(current);
|
|
436
|
+
if (defaulted !== wasDefaulted)
|
|
437
|
+
view.setProps({});
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
if (flipped)
|
|
441
|
+
held = !held;
|
|
442
|
+
const caret = pmToOffset(index, view.state.selection.head);
|
|
443
|
+
const fresh = buildState(current);
|
|
444
|
+
index = fresh.index;
|
|
445
|
+
// Best-effort caret continuity across an external change: keep the offset. Set
|
|
446
|
+
// rather than dispatched, so a leaf the caret is not in reports no caret move.
|
|
447
|
+
const sel = Selection.near(fresh.state.doc.resolve(offsetToPM(index, caret)));
|
|
448
|
+
view.updateState(fresh.state.apply(fresh.state.tr.setSelection(sel)));
|
|
449
|
+
reconciler.commit(current);
|
|
450
|
+
if (flipped)
|
|
451
|
+
opts.onHold?.(held);
|
|
452
|
+
}
|
|
363
453
|
// (b)+(c): lower the edit to a change and commit, or `replace` a field not yet at content rest.
|
|
364
454
|
// Keeps the optimistic PM on throw. Returns whether anything landed, independent of which
|
|
365
455
|
// branch ran.
|
|
@@ -457,10 +547,16 @@ export function createField(opts) {
|
|
|
457
547
|
if (nodes.length !== stored.length)
|
|
458
548
|
return;
|
|
459
549
|
const tr = view.state.tr;
|
|
550
|
+
const renamed = [];
|
|
460
551
|
nodes.forEach((n, i) => {
|
|
461
|
-
if (n.id
|
|
462
|
-
|
|
552
|
+
if (n.id === stored[i])
|
|
553
|
+
return;
|
|
554
|
+
tr.setNodeAttribute(n.pos, n.key, stored[i]);
|
|
555
|
+
// A split's copy of an id the first half keeps is no rename.
|
|
556
|
+
if (typeof n.id === 'string' && !stored.includes(n.id))
|
|
557
|
+
renamed.push([n.id, stored[i]]);
|
|
463
558
|
});
|
|
559
|
+
renameBlocks(tr, renamed);
|
|
464
560
|
if (tr.docChanged)
|
|
465
561
|
view.updateState(view.state.apply(tr.setMeta('addToHistory', false)));
|
|
466
562
|
}
|
|
@@ -518,6 +614,7 @@ export function createField(opts) {
|
|
|
518
614
|
const next = decode(rt, schema);
|
|
519
615
|
const tr = before.tr.setMeta('addToHistory', false).setMeta(remoteKey, true);
|
|
520
616
|
const start = before.doc.content.findDiffStart(next.content);
|
|
617
|
+
let span;
|
|
521
618
|
try {
|
|
522
619
|
if (start != null) {
|
|
523
620
|
let { a: endA, b: endB } = before.doc.content.findDiffEnd(next.content);
|
|
@@ -527,13 +624,22 @@ export function createField(opts) {
|
|
|
527
624
|
endB += overlap;
|
|
528
625
|
}
|
|
529
626
|
tr.replace(start, endA, next.slice(start, endB));
|
|
627
|
+
span = [start, endA];
|
|
530
628
|
}
|
|
531
629
|
if (!tr.doc.eq(next))
|
|
532
630
|
return false;
|
|
533
631
|
const after = buildLineIndex(tr.doc);
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
632
|
+
const { selection } = before;
|
|
633
|
+
// With no delta to map through, a caret inside the replaced span keeps its offset, as a
|
|
634
|
+
// rebuild keeps it: mapped, it would leave the span, and a span can be wider than what
|
|
635
|
+
// changed where a block's container ids differ from the store's.
|
|
636
|
+
const replaced = !!span && span[0] <= selection.from && selection.to <= span[1];
|
|
637
|
+
if (selection instanceof TextSelection && (delta || replaced)) {
|
|
638
|
+
const at = (pm) => {
|
|
639
|
+
const offset = pmToOffset(index, pm);
|
|
640
|
+
return offsetToPM(after, delta ? mapThroughDelta(delta, offset) : offset);
|
|
641
|
+
};
|
|
642
|
+
tr.setSelection(TextSelection.between(tr.doc.resolve(at(selection.anchor)), tr.doc.resolve(at(selection.head))));
|
|
537
643
|
}
|
|
538
644
|
if (!plaintext)
|
|
539
645
|
tr.setMeta(anchorKey, {
|
|
@@ -573,34 +679,8 @@ export function createField(opts) {
|
|
|
573
679
|
view.dispatch(view.state.tr.setSelection(sel).scrollIntoView());
|
|
574
680
|
},
|
|
575
681
|
applyExternal(delta) {
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
const wasDefaulted = defaulted;
|
|
579
|
-
defaulted = unwritten();
|
|
580
|
-
if (!flipped && !reconciler.shouldRehydrate(current)) {
|
|
581
|
-
// Own edit / no change; a default written as itself changes the mark alone.
|
|
582
|
-
if (defaulted !== wasDefaulted)
|
|
583
|
-
view.setProps({});
|
|
584
|
-
return;
|
|
585
|
-
}
|
|
586
|
-
if (!flipped && !held && landRemote(current, delta)) {
|
|
587
|
-
reconciler.commit(current);
|
|
588
|
-
if (defaulted !== wasDefaulted)
|
|
589
|
-
view.setProps({});
|
|
590
|
-
return;
|
|
591
|
-
}
|
|
592
|
-
if (flipped)
|
|
593
|
-
held = !held;
|
|
594
|
-
const caret = pmToOffset(index, view.state.selection.head);
|
|
595
|
-
const fresh = buildState(current);
|
|
596
|
-
index = fresh.index;
|
|
597
|
-
// Best-effort caret continuity across an external change: keep the offset. Set
|
|
598
|
-
// rather than dispatched, so a leaf the caret is not in reports no caret move.
|
|
599
|
-
const sel = Selection.near(fresh.state.doc.resolve(offsetToPM(index, caret)));
|
|
600
|
-
view.updateState(fresh.state.apply(fresh.state.tr.setSelection(sel)));
|
|
601
|
-
reconciler.commit(current);
|
|
602
|
-
if (flipped)
|
|
603
|
-
opts.onHold?.(held);
|
|
682
|
+
reread(delta);
|
|
683
|
+
unwrittenDoc = defaulted ? view.state.doc : undefined;
|
|
604
684
|
},
|
|
605
685
|
setPlaceholder(text) {
|
|
606
686
|
if (text === placeholderText)
|
|
@@ -641,6 +721,31 @@ export function createField(opts) {
|
|
|
641
721
|
return; // absent: nothing to commit
|
|
642
722
|
view.dispatch(view.state.tr.setMeta(anchorKey, { op: 'remove', id }));
|
|
643
723
|
},
|
|
724
|
+
setReview(items, lit) {
|
|
725
|
+
if (!review || (items === reviewItems && lit === reviewLit))
|
|
726
|
+
return;
|
|
727
|
+
reviewItems = items;
|
|
728
|
+
reviewLit = lit;
|
|
729
|
+
for (const markdown of parsed.keys())
|
|
730
|
+
if (!items.some((item) => item.after === markdown))
|
|
731
|
+
parsed.delete(markdown);
|
|
732
|
+
review.refresh(view);
|
|
733
|
+
},
|
|
734
|
+
reviewElements(id) {
|
|
735
|
+
return review?.elements(view, id) ?? [];
|
|
736
|
+
},
|
|
737
|
+
answerReview(id, action) {
|
|
738
|
+
return review?.answer(id, action) ?? false;
|
|
739
|
+
},
|
|
740
|
+
reopenReview(id) {
|
|
741
|
+
review?.reopen(view, id);
|
|
742
|
+
},
|
|
743
|
+
undoReview() {
|
|
744
|
+
return review?.undo(view) ?? false;
|
|
745
|
+
},
|
|
746
|
+
enterReview(id) {
|
|
747
|
+
return review?.enter(view, id) ?? false;
|
|
748
|
+
},
|
|
644
749
|
anchorsInRange(from, to) {
|
|
645
750
|
return heldAnchors()
|
|
646
751
|
.filter((a) => pmToOffset(index, a.end) >= from && pmToOffset(index, a.start) <= to)
|
|
@@ -684,7 +789,8 @@ export function createField(opts) {
|
|
|
684
789
|
* `ProseValue` so the two never fork the plugin ordering. History first with the step-splitting
|
|
685
790
|
* plugin (`undo.ts`), then `afterHistory` plugins (the addressed leaf's anchor plugin), {@link
|
|
686
791
|
* linebreakPlugin}, the markdown-shorthand input rules and their Backspace, the field keymap over
|
|
687
|
-
* the base keymap, the URL paste that links a selection (`link-paste.ts`),
|
|
792
|
+
* the base keymap, the URL paste that links a selection (`link-paste.ts`), the drag that moves
|
|
793
|
+
* between leaves (`drag-move.ts`), and last the block
|
|
688
794
|
* leaf's own shapes: the gap cursor, {@link pastAtomPlugin}, the island paste (`islands.ts`), table
|
|
689
795
|
* paste (`table-paste.ts`), markdown paste (`markdown-paste.ts`) and the task checkbox
|
|
690
796
|
* (`tasks.ts`). A one-line leaf's paste joins its lines (`line-paste.ts`).
|
|
@@ -702,12 +808,15 @@ export function proseLeafPlugins(schema, opts) {
|
|
|
702
808
|
];
|
|
703
809
|
if (opts.slash)
|
|
704
810
|
list.push(slashPlugin(opts.slash, opts.slashHint));
|
|
811
|
+
if (!opts.inline && holdsTab(schema))
|
|
812
|
+
list.push(leavePlugin(opts.leaveStrings ?? (() => DEFAULT_LEAVE_STRINGS)));
|
|
705
813
|
if (!opts.noInputRules)
|
|
706
814
|
list.push(inputRulesPlugin(schema), undoRuleKeymap());
|
|
707
815
|
list.push(keymap(editorKeymap(schema, opts.inline, !!opts.slash)));
|
|
708
816
|
list.push(keymap(baseKeymap));
|
|
709
817
|
if (schema.marks.link)
|
|
710
818
|
list.push(linkPastePlugin(schema.marks.link));
|
|
819
|
+
list.push(dragMovePlugin());
|
|
711
820
|
// Each answers to something only the block schema holds.
|
|
712
821
|
if (isBlockSchema(schema))
|
|
713
822
|
list.push(gapCursor(), pastAtomPlugin(), islandPastePlugin(), tablePastePlugin(), tableCopyPlugin(), markdownPastePlugin(), wordPastePlugin(), listPastePlugin(), taskPlugin(), nestingPlugin());
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { rangeAnchor } from './anchor.js';
|
|
1
|
+
export { markAnchor, rangeAnchor } from './anchor.js';
|
|
2
2
|
export type { RangeAnchor } from './anchor.js';
|
|
3
3
|
export { createField, emptyContent, heldAttributes, isEmptyContent, proseAttributes, proseLeafPlugins } from './field.js';
|
|
4
4
|
export type { CreateFieldOpts, FieldController, LeafViews } from './field.js';
|
|
@@ -9,7 +9,13 @@ export { DEFAULT_TABLE_STRINGS } from './table-view.js';
|
|
|
9
9
|
export type { TableChromeStrings } from './table-view.js';
|
|
10
10
|
export { DEFAULT_SLASH_STRINGS } from './slash.js';
|
|
11
11
|
export type { SlashState, SlashStrings } from './slash.js';
|
|
12
|
-
export {
|
|
12
|
+
export { DEFAULT_LEAVE_STRINGS } from './leave.js';
|
|
13
|
+
export type { LeaveStrings } from './leave.js';
|
|
14
|
+
export { DEFAULT_REVIEW_STRINGS } from './review.js';
|
|
15
|
+
export type { BlockPlace, LeafUndrawn, ReviewAction, ReviewReport, ReviewStrings, ReviewVia, TextReview } from './review.js';
|
|
16
|
+
export { wordDiff } from './review-diff.js';
|
|
17
|
+
export type { DiffHunk } from './review-diff.js';
|
|
18
|
+
export { DEFAULT_SHORTCUT_STRINGS, FIELD_KEYS, REVIEW_KEYS, editorShortcuts } from './shortcuts.js';
|
|
13
19
|
export type { EditorShortcut, ShortcutScope, ShortcutStrings } from './shortcuts.js';
|
|
14
20
|
export { blockSchema, inlineSchema, plaintextSchema, plainSchema, leafSchema, hasMarks } from './schema.js';
|
|
15
21
|
export { rendersHref, storableUrl } from './urls.js';
|
package/dist/core/codec/index.js
CHANGED
|
@@ -11,7 +11,7 @@ import 'prosemirror-gapcursor/style/gapcursor.css';
|
|
|
11
11
|
import './prose.css';
|
|
12
12
|
// What a floating surface anchors to. The visual tier's own surfaces mint one over a
|
|
13
13
|
// selection (`visual/FormatPopover.svelte`), so it is reached off-barrel.
|
|
14
|
-
export { rangeAnchor } from './anchor.js';
|
|
14
|
+
export { markAnchor, rangeAnchor } from './anchor.js';
|
|
15
15
|
// The prose leaf.
|
|
16
16
|
export { createField, emptyContent, heldAttributes, isEmptyContent, proseAttributes, proseLeafPlugins } from './field.js';
|
|
17
17
|
export { capCount } from './cap.js';
|
|
@@ -22,10 +22,17 @@ export { DEFAULT_TABLE_STRINGS } from './table-view.js';
|
|
|
22
22
|
// The slash menu: the codec owns the model and the picks, the chrome the words and
|
|
23
23
|
// the pixels (`visual/SlashMenu.svelte` is the only off-barrel caller).
|
|
24
24
|
export { DEFAULT_SLASH_STRINGS } from './slash.js';
|
|
25
|
+
// The body's way out by the keyboard: the codec owns the keys and the hint's element,
|
|
26
|
+
// the visual tier's `strings` set its wording.
|
|
27
|
+
export { DEFAULT_LEAVE_STRINGS } from './leave.js';
|
|
28
|
+
// The review layer a leaf draws over its blocks: the visual tier's `strings` set extends its
|
|
29
|
+
// wording and its `ReviewItem` narrows to the leaf's own.
|
|
30
|
+
export { DEFAULT_REVIEW_STRINGS } from './review.js';
|
|
31
|
+
export { wordDiff } from './review-diff.js';
|
|
25
32
|
// The rich editor's shortcuts as a host lists them, read off the tables the keymaps bind from;
|
|
26
33
|
// the visual tier's `strings` set extends their wording, and the formatting popover binds its
|
|
27
34
|
// link chord from `FIELD_KEYS`.
|
|
28
|
-
export { DEFAULT_SHORTCUT_STRINGS, FIELD_KEYS, editorShortcuts } from './shortcuts.js';
|
|
35
|
+
export { DEFAULT_SHORTCUT_STRINGS, FIELD_KEYS, REVIEW_KEYS, editorShortcuts } from './shortcuts.js';
|
|
29
36
|
// Schemas (the decode/encode target; the VisualEditor mounts them). `hasMarks` is
|
|
30
37
|
// what a mark surface asks before offering itself over a leaf.
|
|
31
38
|
export { blockSchema, inlineSchema, plaintextSchema, plainSchema, leafSchema, hasMarks } from './schema.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Node as PMNode, type NodeSpec } from 'prosemirror-model';
|
|
1
|
+
import { Fragment, type Node as PMNode, type NodeSpec } from 'prosemirror-model';
|
|
2
2
|
import { Plugin } from 'prosemirror-state';
|
|
3
3
|
import type { Content, ContentIsland, TableProps } from '@quillmark/wasm';
|
|
4
4
|
/** The `U+2028` line separator that is a break inside a block's text. */
|
|
@@ -39,6 +39,9 @@ export declare function islandEntryFromNode(attrs: IslandNodeAttrs): ContentIsla
|
|
|
39
39
|
export declare function isTableProps(props: unknown): props is TableProps;
|
|
40
40
|
/** The next island id for a field: one draw from {@link islandMinter}. */
|
|
41
41
|
export declare function mintIslandId(doc: PMNode): string;
|
|
42
|
+
/** `fragment` as it lands in `doc` from outside it: an island whose id the document holds, or
|
|
43
|
+
* that carries none, takes a fresh one. */
|
|
44
|
+
export declare function arriving(doc: PMNode, fragment: Fragment): Fragment;
|
|
42
45
|
/**
|
|
43
46
|
* The paste's island pass: an id the field already holds is re-minted on the way in, and an island
|
|
44
47
|
* arriving with none (a table read off foreign markup, `table-paste.ts`) takes its first.
|
|
@@ -222,6 +222,12 @@ function remintIslands(fragment, taken, mint) {
|
|
|
222
222
|
});
|
|
223
223
|
return changed ? Fragment.fromArray(out) : null;
|
|
224
224
|
}
|
|
225
|
+
/** `fragment` as it lands in `doc` from outside it: an island whose id the document holds, or
|
|
226
|
+
* that carries none, takes a fresh one. */
|
|
227
|
+
export function arriving(doc, fragment) {
|
|
228
|
+
const { held, mint } = islandState(doc);
|
|
229
|
+
return remintIslands(fragment, held, mint) ?? fragment;
|
|
230
|
+
}
|
|
225
231
|
/**
|
|
226
232
|
* The paste's island pass: an id the field already holds is re-minted on the way in, and an island
|
|
227
233
|
* arriving with none (a table read off foreign markup, `table-paste.ts`) takes its first.
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type { Schema } from 'prosemirror-model';
|
|
2
2
|
import type { Command } from 'prosemirror-state';
|
|
3
|
+
/** Whether a body over `schema` holds Tab: `false` over `plainSchema`, a form field whose
|
|
4
|
+
* Tab is field navigation. */
|
|
5
|
+
export declare function holdsTab(schema: Schema): boolean;
|
|
3
6
|
/** A multi-block leaf's structural keys, each link binding only what its schema
|
|
4
7
|
* declares: over `plainSchema`, which holds neither lists nor code blocks nor islands,
|
|
5
8
|
* the block link and the break link alone. The argument list is the precedence order
|
|
@@ -5,6 +5,7 @@ import { breakKeymap } from './breaks.js';
|
|
|
5
5
|
import { codeKeymap } from './code.js';
|
|
6
6
|
import { listKeymap } from './lists.js';
|
|
7
7
|
import { listMoveKeymap } from './list-move.js';
|
|
8
|
+
import { armLeave, teachLeave } from './leave.js';
|
|
8
9
|
import { slashKeymap } from './slash.js';
|
|
9
10
|
import { BODY_KEYS } from './shortcuts.js';
|
|
10
11
|
/** One chain per key, the maps taken in precedence order: on a key several bind, an
|
|
@@ -19,22 +20,22 @@ function chainKeymaps(...maps) {
|
|
|
19
20
|
}
|
|
20
21
|
return out;
|
|
21
22
|
}
|
|
23
|
+
/** Whether a body over `schema` holds Tab: `false` over `plainSchema`, a form field whose
|
|
24
|
+
* Tab is field navigation. */
|
|
25
|
+
export function holdsTab(schema) {
|
|
26
|
+
return !!schema.nodes.list_item;
|
|
27
|
+
}
|
|
22
28
|
/** The last link of a document body: Tab and Shift-Tab held wherever no surface took
|
|
23
|
-
* them,
|
|
24
|
-
* `{}`
|
|
29
|
+
* them, each naming the way out, and Escape handing the next one to the browser
|
|
30
|
+
* (`leave.ts`). `{}` where the body does not hold Tab. */
|
|
25
31
|
function exitKeymap(schema) {
|
|
26
|
-
if (!schema
|
|
32
|
+
if (!holdsTab(schema))
|
|
27
33
|
return {};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
[BODY_KEYS.leave]: (_state, _dispatch, view) => {
|
|
32
|
-
if (!view)
|
|
33
|
-
return false;
|
|
34
|
-
view.dom.blur();
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
34
|
+
const held = (state, dispatch) => {
|
|
35
|
+
teachLeave(state, dispatch);
|
|
36
|
+
return true;
|
|
37
37
|
};
|
|
38
|
+
return { Tab: held, 'Shift-Tab': held, [BODY_KEYS.leave]: armLeave };
|
|
38
39
|
}
|
|
39
40
|
/** A multi-block leaf's structural keys, each link binding only what its schema
|
|
40
41
|
* declares: over `plainSchema`, which holds neither lists nor code blocks nor islands,
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Plugin, type Command } from 'prosemirror-state';
|
|
2
|
+
/** The hint's wording, in each of its two states. */
|
|
3
|
+
export interface LeaveStrings {
|
|
4
|
+
/** After a Tab the body held to no effect: the way out, in keys. */
|
|
5
|
+
leaveTaught: string;
|
|
6
|
+
/** After Escape, while the next Tab leaves. */
|
|
7
|
+
leaveArmed: string;
|
|
8
|
+
}
|
|
9
|
+
/** The package's English, beside the surface that draws it; the visual `strings` set extends it. */
|
|
10
|
+
export declare const DEFAULT_LEAVE_STRINGS: LeaveStrings;
|
|
11
|
+
type Leave = 'idle' | 'taught' | 'armed';
|
|
12
|
+
/** Hand the next Tab to the browser. Declines in a state without {@link leavePlugin}. */
|
|
13
|
+
export declare const armLeave: Command;
|
|
14
|
+
/** Name the way out, after a Tab the body held. Declines as {@link armLeave}. */
|
|
15
|
+
export declare const teachLeave: Command;
|
|
16
|
+
export declare function leavePlugin(strings: () => LeaveStrings): Plugin<Leave>;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// The body's way out by the keyboard.
|
|
2
|
+
//
|
|
3
|
+
// A body holds Tab (`keymap.ts`), so a keyboard that walked into one cannot walk out by
|
|
4
|
+
// the key that brought it. Escape opens the way: the next Tab or Shift-Tab is the
|
|
5
|
+
// browser's, which moves the focus on from the leaf in either direction, and any other
|
|
6
|
+
// key, a press or an edit hands Tab back to the body. The focus stays in the leaf between
|
|
7
|
+
// the two keys, so the place is drawn and announced throughout, and Shift-Tab leaves
|
|
8
|
+
// backwards as Tab leaves forwards.
|
|
9
|
+
//
|
|
10
|
+
// The leaf says so at the point of need. A Tab the body held and did nothing with names
|
|
11
|
+
// the way out, and Escape names the key it now waits for. The words stand in a status
|
|
12
|
+
// region beside the editable, empty at rest, so a reader hears them as they arrive.
|
|
13
|
+
import { Plugin, PluginKey } from 'prosemirror-state';
|
|
14
|
+
/** The package's English, beside the surface that draws it; the visual `strings` set extends it. */
|
|
15
|
+
export const DEFAULT_LEAVE_STRINGS = {
|
|
16
|
+
leaveTaught: 'Esc, then Tab, to move on',
|
|
17
|
+
leaveArmed: 'Tab to move on'
|
|
18
|
+
};
|
|
19
|
+
const leaveKey = new PluginKey('qm.leave');
|
|
20
|
+
/** Keys that are part of the chord still being pressed, or the key that arms. */
|
|
21
|
+
const KEPT = new Set(['Shift', 'Control', 'Alt', 'Meta', 'Escape']);
|
|
22
|
+
const enter = (to) => (state, dispatch) => {
|
|
23
|
+
if (leaveKey.getState(state) === undefined)
|
|
24
|
+
return false;
|
|
25
|
+
dispatch?.(state.tr.setMeta(leaveKey, to));
|
|
26
|
+
return true;
|
|
27
|
+
};
|
|
28
|
+
/** Hand the next Tab to the browser. Declines in a state without {@link leavePlugin}. */
|
|
29
|
+
export const armLeave = enter('armed');
|
|
30
|
+
/** Name the way out, after a Tab the body held. Declines as {@link armLeave}. */
|
|
31
|
+
export const teachLeave = enter('taught');
|
|
32
|
+
export function leavePlugin(strings) {
|
|
33
|
+
const rest = (view) => {
|
|
34
|
+
if (leaveKey.getState(view.state) !== 'idle')
|
|
35
|
+
view.dispatch(view.state.tr.setMeta(leaveKey, 'idle'));
|
|
36
|
+
return false;
|
|
37
|
+
};
|
|
38
|
+
return new Plugin({
|
|
39
|
+
key: leaveKey,
|
|
40
|
+
state: {
|
|
41
|
+
init: () => 'idle',
|
|
42
|
+
apply: (tr, prev) => tr.getMeta(leaveKey) ??
|
|
43
|
+
(tr.docChanged || tr.selectionSet ? 'idle' : prev)
|
|
44
|
+
},
|
|
45
|
+
props: {
|
|
46
|
+
handleDOMEvents: {
|
|
47
|
+
// Ahead of every keymap, and answering `true` without preventing the default:
|
|
48
|
+
// the view then runs no binding for the key, a list's indent included, and the
|
|
49
|
+
// browser moves the focus.
|
|
50
|
+
keydown: (view, e) => {
|
|
51
|
+
const at = leaveKey.getState(view.state);
|
|
52
|
+
if (at === 'idle' || KEPT.has(e.key))
|
|
53
|
+
return false;
|
|
54
|
+
if (e.key === 'Tab')
|
|
55
|
+
return at === 'armed' && !e.ctrlKey && !e.altKey && !e.metaKey;
|
|
56
|
+
return rest(view);
|
|
57
|
+
},
|
|
58
|
+
blur: rest,
|
|
59
|
+
mousedown: rest
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
view: (view) => {
|
|
63
|
+
const note = document.createElement('span');
|
|
64
|
+
note.className = 'qm-leave-hint';
|
|
65
|
+
note.setAttribute('role', 'status');
|
|
66
|
+
view.dom.after(note);
|
|
67
|
+
const draw = () => {
|
|
68
|
+
const at = leaveKey.getState(view.state);
|
|
69
|
+
const words = strings();
|
|
70
|
+
const text = at === 'armed' ? words.leaveArmed : at === 'taught' ? words.leaveTaught : '';
|
|
71
|
+
if (note.textContent !== text)
|
|
72
|
+
note.textContent = text;
|
|
73
|
+
};
|
|
74
|
+
draw();
|
|
75
|
+
return { update: draw, destroy: () => note.remove() };
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|