@quillmark/svelte 0.33.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 +73 -1
- package/THEMING.md +11 -10
- package/dist/core/address.d.ts +6 -0
- package/dist/core/address.js +16 -0
- 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 +44 -1
- package/dist/core/codec/field.js +137 -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 +172 -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 +116 -0
- package/dist/core/codec/review.js +920 -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 +34 -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 +98 -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 +21 -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/ReviewProposal.svelte +149 -0
- package/dist/visual/ReviewProposal.svelte.d.ts +15 -0
- package/dist/visual/ReviewRows.svelte +43 -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 +22 -0
- package/dist/visual/VisualEditor.svelte.d.ts +7 -0
- package/dist/visual/VisualEditorInner.svelte +591 -27
- 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 +36 -0
- package/dist/visual/removed.d.ts +20 -0
- package/dist/visual/removed.js +30 -0
- package/dist/visual/review.d.ts +135 -0
- package/dist/visual/review.js +227 -0
- package/dist/visual/review.svelte.d.ts +79 -0
- package/dist/visual/review.svelte.js +226 -0
- package/dist/visual/rowdrag.svelte.js +44 -55
- package/dist/visual/strings.d.ts +36 -7
- package/dist/visual/strings.js +26 -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';
|
|
@@ -239,6 +242,8 @@ export function createField(opts) {
|
|
|
239
242
|
/** Whether the leaf holds a default nobody has written: the `data-default` mark. */
|
|
240
243
|
const unwritten = () => !!fallback && doc.getStored(addr) == null;
|
|
241
244
|
let defaulted = unwritten();
|
|
245
|
+
/** The document the leaf last held as its unwritten default, which an undo can return to. */
|
|
246
|
+
let unwrittenDoc;
|
|
242
247
|
// `known` is the codec's view of what the leaf holds: kept in sync after every
|
|
243
248
|
// own-edit so `reconcile` can tell an external change from the field's own.
|
|
244
249
|
const reconciler = createReconciler(shown());
|
|
@@ -250,6 +255,34 @@ export function createField(opts) {
|
|
|
250
255
|
// The views nested inside this leaf, one per table cell (`table-view.ts`): chrome asks the leaf
|
|
251
256
|
// which view holds the caret.
|
|
252
257
|
const nested = new Set();
|
|
258
|
+
// The review layer's live cells: the items and the lit one move by assignment and a re-render.
|
|
259
|
+
let reviewItems = [];
|
|
260
|
+
let reviewLit;
|
|
261
|
+
const parsed = new Map();
|
|
262
|
+
const review = plaintext
|
|
263
|
+
? undefined
|
|
264
|
+
: reviewLayer({
|
|
265
|
+
items: () => reviewItems,
|
|
266
|
+
lit: () => reviewLit,
|
|
267
|
+
strings: () => opts.reviewStrings?.() ?? DEFAULT_REVIEW_STRINGS,
|
|
268
|
+
parse: (markdown) => {
|
|
269
|
+
if (!parsed.has(markdown)) {
|
|
270
|
+
let node;
|
|
271
|
+
try {
|
|
272
|
+
node = decode(core().importMarkdown(markdown).content, schema);
|
|
273
|
+
}
|
|
274
|
+
catch {
|
|
275
|
+
node = undefined;
|
|
276
|
+
}
|
|
277
|
+
parsed.set(markdown, node);
|
|
278
|
+
}
|
|
279
|
+
return parsed.get(markdown);
|
|
280
|
+
},
|
|
281
|
+
act: (id, action, chord) => opts.onReview?.(id, action, chord),
|
|
282
|
+
writing: (on) => opts.onReviewWriting?.(on),
|
|
283
|
+
point: (id, via) => opts.onReviewPoint?.(id, via),
|
|
284
|
+
drew: (report) => opts.onReviewDrawn?.(report)
|
|
285
|
+
});
|
|
253
286
|
// The menu's report channel; the vocabulary is the codec's own constant (`slash.ts`).
|
|
254
287
|
const slash = block ? opts.onSlash : undefined;
|
|
255
288
|
// Judged of the value being mounted rather than read off a diagnostic: a routed set
|
|
@@ -258,11 +291,19 @@ export function createField(opts) {
|
|
|
258
291
|
const holds = (rt) => !fitsLeaf(rt, { inline, plaintext, islands: true });
|
|
259
292
|
let held = holds(reconciler.last);
|
|
260
293
|
const named = proseAttributes(opts) ?? {};
|
|
261
|
-
const defaultNamed = {
|
|
294
|
+
const defaultNamed = {
|
|
295
|
+
...proseAttributes({
|
|
296
|
+
...opts,
|
|
297
|
+
describedBy: [opts.describedBy, opts.defaultNoteId].filter(Boolean).join(' ') || undefined
|
|
298
|
+
}),
|
|
299
|
+
'data-default': ''
|
|
300
|
+
};
|
|
262
301
|
const heldNamed = heldAttributes(opts, opts.heldNoteId);
|
|
263
302
|
const seeded = buildState(reconciler.last);
|
|
264
303
|
const state = seeded.state;
|
|
265
304
|
index = seeded.index;
|
|
305
|
+
if (defaulted)
|
|
306
|
+
unwrittenDoc = state.doc;
|
|
266
307
|
// The clearance PM's reveal keeps around the caret, in this leaf's own line box: PM's 5px
|
|
267
308
|
// default leaves the next typed line past the fold. Measured off the mounted box and dropped
|
|
268
309
|
// where the derivation is out of reach (jsdom).
|
|
@@ -313,8 +354,14 @@ export function createField(opts) {
|
|
|
313
354
|
// (d) the change signal, only for what actually landed.
|
|
314
355
|
const anchors = plaintext ? [] : readAnchors();
|
|
315
356
|
const newRt = scan ? scanContent(scan, anchors) : pmToContent(next.doc, anchors);
|
|
316
|
-
|
|
357
|
+
// An undo back to the default the leaf held unwritten takes the write back too.
|
|
358
|
+
const unwrite = !!unwrittenDoc && isHistoryTransaction(tr) && next.doc.eq(unwrittenDoc);
|
|
359
|
+
if (unwrite ? commitUnset() : commitEdit(oldRt, newRt))
|
|
317
360
|
opts.onChange?.(addr);
|
|
361
|
+
if (unwrite) {
|
|
362
|
+
defaulted = unwritten();
|
|
363
|
+
view.setProps({});
|
|
364
|
+
}
|
|
318
365
|
}
|
|
319
366
|
// The caret, for structural and selection-only changes, reported after the commit.
|
|
320
367
|
opts.onCaretMove?.(addr, pmToOffset(index, next.selection.head));
|
|
@@ -349,17 +396,50 @@ export function createField(opts) {
|
|
|
349
396
|
inline,
|
|
350
397
|
slash,
|
|
351
398
|
slashHint: () => (opts.slashStrings?.() ?? DEFAULT_SLASH_STRINGS).slashHint,
|
|
399
|
+
leaveStrings: opts.leaveStrings,
|
|
352
400
|
noInputRules: opts.noInputRules,
|
|
353
401
|
// Always installed, so a leaf that mounts without a ghost can still be
|
|
354
402
|
// given one later; the plugin draws nothing while the text is empty.
|
|
355
403
|
placeholder: () => placeholderText,
|
|
356
404
|
placeholderUntilEdit: opts.placeholderUntilEdit,
|
|
357
405
|
cap: opts.cap,
|
|
358
|
-
afterHistory: [anchorPlugin(seededAnchors)]
|
|
406
|
+
afterHistory: [anchorPlugin(seededAnchors), ...(review ? [review.plugin] : [])]
|
|
359
407
|
})
|
|
360
408
|
});
|
|
361
409
|
return { state: built, index: seedIndex };
|
|
362
410
|
}
|
|
411
|
+
/** Re-read the leaf from the document: the reconciler's own edit, a landed remote replace, or
|
|
412
|
+
* a rebuild. */
|
|
413
|
+
function reread(delta) {
|
|
414
|
+
const current = shown();
|
|
415
|
+
const flipped = holds(current) !== held;
|
|
416
|
+
const wasDefaulted = defaulted;
|
|
417
|
+
defaulted = unwritten();
|
|
418
|
+
if (!flipped && !reconciler.shouldRehydrate(current)) {
|
|
419
|
+
// Own edit / no change; a default written as itself changes the mark alone.
|
|
420
|
+
if (defaulted !== wasDefaulted)
|
|
421
|
+
view.setProps({});
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
if (!flipped && !held && landRemote(current, delta)) {
|
|
425
|
+
reconciler.commit(current);
|
|
426
|
+
if (defaulted !== wasDefaulted)
|
|
427
|
+
view.setProps({});
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
if (flipped)
|
|
431
|
+
held = !held;
|
|
432
|
+
const caret = pmToOffset(index, view.state.selection.head);
|
|
433
|
+
const fresh = buildState(current);
|
|
434
|
+
index = fresh.index;
|
|
435
|
+
// Best-effort caret continuity across an external change: keep the offset. Set
|
|
436
|
+
// rather than dispatched, so a leaf the caret is not in reports no caret move.
|
|
437
|
+
const sel = Selection.near(fresh.state.doc.resolve(offsetToPM(index, caret)));
|
|
438
|
+
view.updateState(fresh.state.apply(fresh.state.tr.setSelection(sel)));
|
|
439
|
+
reconciler.commit(current);
|
|
440
|
+
if (flipped)
|
|
441
|
+
opts.onHold?.(held);
|
|
442
|
+
}
|
|
363
443
|
// (b)+(c): lower the edit to a change and commit, or `replace` a field not yet at content rest.
|
|
364
444
|
// Keeps the optimistic PM on throw. Returns whether anything landed, independent of which
|
|
365
445
|
// branch ran.
|
|
@@ -457,10 +537,16 @@ export function createField(opts) {
|
|
|
457
537
|
if (nodes.length !== stored.length)
|
|
458
538
|
return;
|
|
459
539
|
const tr = view.state.tr;
|
|
540
|
+
const renamed = [];
|
|
460
541
|
nodes.forEach((n, i) => {
|
|
461
|
-
if (n.id
|
|
462
|
-
|
|
542
|
+
if (n.id === stored[i])
|
|
543
|
+
return;
|
|
544
|
+
tr.setNodeAttribute(n.pos, n.key, stored[i]);
|
|
545
|
+
// A split's copy of an id the first half keeps is no rename.
|
|
546
|
+
if (typeof n.id === 'string' && !stored.includes(n.id))
|
|
547
|
+
renamed.push([n.id, stored[i]]);
|
|
463
548
|
});
|
|
549
|
+
renameBlocks(tr, renamed);
|
|
464
550
|
if (tr.docChanged)
|
|
465
551
|
view.updateState(view.state.apply(tr.setMeta('addToHistory', false)));
|
|
466
552
|
}
|
|
@@ -518,6 +604,7 @@ export function createField(opts) {
|
|
|
518
604
|
const next = decode(rt, schema);
|
|
519
605
|
const tr = before.tr.setMeta('addToHistory', false).setMeta(remoteKey, true);
|
|
520
606
|
const start = before.doc.content.findDiffStart(next.content);
|
|
607
|
+
let span;
|
|
521
608
|
try {
|
|
522
609
|
if (start != null) {
|
|
523
610
|
let { a: endA, b: endB } = before.doc.content.findDiffEnd(next.content);
|
|
@@ -527,13 +614,22 @@ export function createField(opts) {
|
|
|
527
614
|
endB += overlap;
|
|
528
615
|
}
|
|
529
616
|
tr.replace(start, endA, next.slice(start, endB));
|
|
617
|
+
span = [start, endA];
|
|
530
618
|
}
|
|
531
619
|
if (!tr.doc.eq(next))
|
|
532
620
|
return false;
|
|
533
621
|
const after = buildLineIndex(tr.doc);
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
622
|
+
const { selection } = before;
|
|
623
|
+
// With no delta to map through, a caret inside the replaced span keeps its offset, as a
|
|
624
|
+
// rebuild keeps it: mapped, it would leave the span, and a span can be wider than what
|
|
625
|
+
// changed where a block's container ids differ from the store's.
|
|
626
|
+
const replaced = !!span && span[0] <= selection.from && selection.to <= span[1];
|
|
627
|
+
if (selection instanceof TextSelection && (delta || replaced)) {
|
|
628
|
+
const at = (pm) => {
|
|
629
|
+
const offset = pmToOffset(index, pm);
|
|
630
|
+
return offsetToPM(after, delta ? mapThroughDelta(delta, offset) : offset);
|
|
631
|
+
};
|
|
632
|
+
tr.setSelection(TextSelection.between(tr.doc.resolve(at(selection.anchor)), tr.doc.resolve(at(selection.head))));
|
|
537
633
|
}
|
|
538
634
|
if (!plaintext)
|
|
539
635
|
tr.setMeta(anchorKey, {
|
|
@@ -573,34 +669,8 @@ export function createField(opts) {
|
|
|
573
669
|
view.dispatch(view.state.tr.setSelection(sel).scrollIntoView());
|
|
574
670
|
},
|
|
575
671
|
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);
|
|
672
|
+
reread(delta);
|
|
673
|
+
unwrittenDoc = defaulted ? view.state.doc : undefined;
|
|
604
674
|
},
|
|
605
675
|
setPlaceholder(text) {
|
|
606
676
|
if (text === placeholderText)
|
|
@@ -641,6 +711,31 @@ export function createField(opts) {
|
|
|
641
711
|
return; // absent: nothing to commit
|
|
642
712
|
view.dispatch(view.state.tr.setMeta(anchorKey, { op: 'remove', id }));
|
|
643
713
|
},
|
|
714
|
+
setReview(items, lit) {
|
|
715
|
+
if (!review || (items === reviewItems && lit === reviewLit))
|
|
716
|
+
return;
|
|
717
|
+
reviewItems = items;
|
|
718
|
+
reviewLit = lit;
|
|
719
|
+
for (const markdown of parsed.keys())
|
|
720
|
+
if (!items.some((item) => item.after === markdown))
|
|
721
|
+
parsed.delete(markdown);
|
|
722
|
+
review.refresh(view);
|
|
723
|
+
},
|
|
724
|
+
reviewElements(id) {
|
|
725
|
+
return review?.elements(view, id) ?? [];
|
|
726
|
+
},
|
|
727
|
+
answerReview(id, action) {
|
|
728
|
+
return review?.answer(id, action) ?? false;
|
|
729
|
+
},
|
|
730
|
+
reopenReview(id) {
|
|
731
|
+
review?.reopen(view, id);
|
|
732
|
+
},
|
|
733
|
+
undoReview() {
|
|
734
|
+
return review?.undo(view) ?? false;
|
|
735
|
+
},
|
|
736
|
+
enterReview(id) {
|
|
737
|
+
return review?.enter(view, id) ?? false;
|
|
738
|
+
},
|
|
644
739
|
anchorsInRange(from, to) {
|
|
645
740
|
return heldAnchors()
|
|
646
741
|
.filter((a) => pmToOffset(index, a.end) >= from && pmToOffset(index, a.start) <= to)
|
|
@@ -684,7 +779,8 @@ export function createField(opts) {
|
|
|
684
779
|
* `ProseValue` so the two never fork the plugin ordering. History first with the step-splitting
|
|
685
780
|
* plugin (`undo.ts`), then `afterHistory` plugins (the addressed leaf's anchor plugin), {@link
|
|
686
781
|
* 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`),
|
|
782
|
+
* the base keymap, the URL paste that links a selection (`link-paste.ts`), the drag that moves
|
|
783
|
+
* between leaves (`drag-move.ts`), and last the block
|
|
688
784
|
* leaf's own shapes: the gap cursor, {@link pastAtomPlugin}, the island paste (`islands.ts`), table
|
|
689
785
|
* paste (`table-paste.ts`), markdown paste (`markdown-paste.ts`) and the task checkbox
|
|
690
786
|
* (`tasks.ts`). A one-line leaf's paste joins its lines (`line-paste.ts`).
|
|
@@ -702,12 +798,15 @@ export function proseLeafPlugins(schema, opts) {
|
|
|
702
798
|
];
|
|
703
799
|
if (opts.slash)
|
|
704
800
|
list.push(slashPlugin(opts.slash, opts.slashHint));
|
|
801
|
+
if (!opts.inline && holdsTab(schema))
|
|
802
|
+
list.push(leavePlugin(opts.leaveStrings ?? (() => DEFAULT_LEAVE_STRINGS)));
|
|
705
803
|
if (!opts.noInputRules)
|
|
706
804
|
list.push(inputRulesPlugin(schema), undoRuleKeymap());
|
|
707
805
|
list.push(keymap(editorKeymap(schema, opts.inline, !!opts.slash)));
|
|
708
806
|
list.push(keymap(baseKeymap));
|
|
709
807
|
if (schema.marks.link)
|
|
710
808
|
list.push(linkPastePlugin(schema.marks.link));
|
|
809
|
+
list.push(dragMovePlugin());
|
|
711
810
|
// Each answers to something only the block schema holds.
|
|
712
811
|
if (isBlockSchema(schema))
|
|
713
812
|
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
|
+
}
|