@quillmark/svelte 0.39.1 → 0.41.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 +1 -1
- package/dist/core/codec/field.js +2 -3
- package/dist/core/codec/lists.d.ts +2 -2
- package/dist/core/codec/lists.js +32 -3
- package/dist/core/codec/shortcuts.d.ts +9 -6
- package/dist/core/codec/shortcuts.js +17 -9
- package/dist/core/codec/table-view.js +3 -3
- package/dist/core/codec/tasks.d.ts +2 -2
- package/dist/core/codec/tasks.js +3 -3
- package/dist/core/frame.d.ts +3 -0
- package/dist/core/frame.js +3 -2
- package/dist/visual/ArrayField.svelte +6 -4
- package/dist/visual/Card.svelte +1 -1
- package/dist/visual/ReviewCard.svelte +86 -14
- package/dist/visual/ReviewCard.svelte.d.ts +6 -0
- package/dist/visual/VisualEditorInner.svelte +238 -75
- package/dist/visual/hears.d.ts +14 -0
- package/dist/visual/hears.js +58 -0
- package/dist/visual/index.d.ts +2 -0
- package/dist/visual/index.js +1 -0
- package/dist/visual/proposals.js +1 -1
- package/dist/visual/review.svelte.d.ts +2 -0
- package/dist/visual/review.svelte.js +9 -2
- package/dist/visual/structure.d.ts +2 -2
- package/dist/visual/undo.svelte.js +6 -3
- package/package.json +2 -2
|
@@ -61,6 +61,7 @@
|
|
|
61
61
|
import type { Delta } from '../core/codec/positions.js';
|
|
62
62
|
import { diagnosticText, mergeStrings, setWording } from './strings.js';
|
|
63
63
|
import { createStructuralUndo, setStructuralUndo } from './undo.svelte.js';
|
|
64
|
+
import { reviewKeysHeard, type ReviewKeyName } from './hears.js';
|
|
64
65
|
import { undoChord } from './listhistory.js';
|
|
65
66
|
import { removedCards, type RemovedCard } from './removed.js';
|
|
66
67
|
import { createReview, setReview, type CardAdd } from './review.svelte.js';
|
|
@@ -214,7 +215,7 @@
|
|
|
214
215
|
// card reorder.
|
|
215
216
|
const commitErrors = new SvelteMap<string, RoutedDiagnostic>();
|
|
216
217
|
|
|
217
|
-
const kinds = $derived(Object.keys(quill.schema.
|
|
218
|
+
const kinds = $derived(Object.keys(quill.schema).filter((k) => k !== 'main'));
|
|
218
219
|
|
|
219
220
|
// The removal's step back (`undo.svelte.ts`), published so an array's row removal
|
|
220
221
|
// offers on the same toast a card's does.
|
|
@@ -278,7 +279,7 @@
|
|
|
278
279
|
if (!running || value === undefined || !shown || !Object.hasOwn(shown.values, name))
|
|
279
280
|
return rederive();
|
|
280
281
|
const fresh = fieldValues((isMain ? doc.main : doc.card(at)).payloadItems);
|
|
281
|
-
const cardSchema = isMain ? quill.schema.main : quill.schema
|
|
282
|
+
const cardSchema = isMain ? quill.schema.main : quill.schema[shown.kind];
|
|
282
283
|
patched = {
|
|
283
284
|
...patched,
|
|
284
285
|
[id]: {
|
|
@@ -565,7 +566,7 @@
|
|
|
565
566
|
text: string;
|
|
566
567
|
} {
|
|
567
568
|
const { add } = item;
|
|
568
|
-
const schema = quill.schema
|
|
569
|
+
const schema = quill.schema[add.kind];
|
|
569
570
|
const values = fieldValues(add.payloadItems);
|
|
570
571
|
const named = (add.ext?.editor as { title?: unknown } | undefined)?.title;
|
|
571
572
|
const title = cardTitle(
|
|
@@ -593,6 +594,12 @@
|
|
|
593
594
|
typing = false;
|
|
594
595
|
onReviewFocus?.(id);
|
|
595
596
|
});
|
|
597
|
+
// The caret landing on a change brings back the card typing put aside, the same change
|
|
598
|
+
// included once the caret has left it and come back.
|
|
599
|
+
$effect(() => {
|
|
600
|
+
void reviewing.landed;
|
|
601
|
+
typing = false;
|
|
602
|
+
});
|
|
596
603
|
// The report, to a host counting its own list: each change, read once the leaves the change
|
|
597
604
|
// mounted have drawn, so a list just handed over is not reported as anchored nowhere. A
|
|
598
605
|
// review starts on its first change, and goes on to the first open one wherever the current
|
|
@@ -659,31 +666,58 @@
|
|
|
659
666
|
/** Answer the current change, as its card would. False with none open. */
|
|
660
667
|
function answerCurrent(action: 'accept' | 'dismiss'): boolean {
|
|
661
668
|
const id = reviewing.lit;
|
|
662
|
-
|
|
669
|
+
if (id === undefined) return false;
|
|
670
|
+
const at = document.activeElement;
|
|
671
|
+
const held = at instanceof Element && reviewIds(at.closest(THING)).includes(id);
|
|
672
|
+
if (!answerReview([id], action).length) return false;
|
|
673
|
+
// A change that is a thing goes with its answer, and the focus it held with it: the focus
|
|
674
|
+
// goes on to the next change, as a step would take it.
|
|
675
|
+
if (held)
|
|
676
|
+
void tick().then(() => {
|
|
677
|
+
const next = reviewing.lit;
|
|
678
|
+
if (next !== undefined && !rootEl?.contains(document.activeElement))
|
|
679
|
+
void reveal(next, true, true);
|
|
680
|
+
});
|
|
681
|
+
return true;
|
|
663
682
|
}
|
|
664
|
-
/** An answer key: the card's, so it answers only a change whose card stands whole in view.
|
|
665
|
-
*
|
|
666
|
-
*
|
|
683
|
+
/** An answer key: the card's, so it answers only a change whose card stands whole in view. A
|
|
684
|
+
* press with the change or its card out of view, or the card out of the way of the reader's
|
|
685
|
+
* typing, brings both back, and the next answers. */
|
|
667
686
|
function answerByKey(action: 'accept' | 'dismiss'): boolean {
|
|
668
687
|
const id = reviewing.lit;
|
|
669
|
-
if (id === undefined
|
|
670
|
-
if (!typing && inView(id) && (answerCard?.standsInView() ?? true))
|
|
688
|
+
if (id === undefined) return false;
|
|
689
|
+
if (!typing && inView(id) && (answerCard?.standsInView() ?? true)) {
|
|
690
|
+
answerCurrent(action);
|
|
691
|
+
return true;
|
|
692
|
+
}
|
|
671
693
|
typing = false;
|
|
694
|
+
asked = action;
|
|
672
695
|
void reveal(id, false, false);
|
|
673
696
|
return true;
|
|
674
697
|
}
|
|
675
|
-
/**
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
698
|
+
/** The answer key whose press only brought the card, which the card's hint for it shows. */
|
|
699
|
+
let asked = $state<'accept' | 'dismiss' | undefined>();
|
|
700
|
+
$effect(() => {
|
|
701
|
+
void reviewing.lit;
|
|
702
|
+
asked = undefined;
|
|
703
|
+
});
|
|
704
|
+
/** An answer key's fresh press. Its repeats are never an answer: a held key answers once. */
|
|
705
|
+
function answerKey(action: 'accept' | 'dismiss'): boolean {
|
|
706
|
+
if (repeat) return false;
|
|
707
|
+
answered = answerByKey(action);
|
|
708
|
+
return answered;
|
|
709
|
+
}
|
|
710
|
+
/** The review took the press being matched as an answer key's. */
|
|
711
|
+
let answered = false;
|
|
712
|
+
/** The chord of the answer key the review took and the keyboard may still repeat, whose
|
|
713
|
+
* repeats it swallows even once no change is left, so none falls through to a leaf. */
|
|
714
|
+
let heldChord: string | undefined;
|
|
715
|
+
const chordOf = (e: KeyboardEvent): string =>
|
|
716
|
+
`${e.key}:${+e.metaKey}${+e.ctrlKey}${+e.altKey}${+e.shiftKey}`;
|
|
683
717
|
let answerCard = $state<ReviewCard | undefined>();
|
|
684
718
|
const reviewKeys = keydownHandler({
|
|
685
|
-
[REVIEW_KEYS.accept]: () =>
|
|
686
|
-
[REVIEW_KEYS.dismiss]: () =>
|
|
719
|
+
[REVIEW_KEYS.accept]: () => answerKey('accept'),
|
|
720
|
+
[REVIEW_KEYS.dismiss]: () => answerKey('dismiss'),
|
|
687
721
|
[REVIEW_KEYS.next]: () => {
|
|
688
722
|
void step(1, inside);
|
|
689
723
|
return true;
|
|
@@ -693,35 +727,82 @@
|
|
|
693
727
|
return true;
|
|
694
728
|
},
|
|
695
729
|
'Alt-F10': () => {
|
|
696
|
-
|
|
697
|
-
|
|
730
|
+
const id = reviewing.lit;
|
|
731
|
+
if (!answerCard || id === undefined || document.getSelection()?.isCollapsed === false)
|
|
732
|
+
return false;
|
|
733
|
+
void enterCard(id);
|
|
698
734
|
return true;
|
|
699
735
|
}
|
|
700
736
|
});
|
|
737
|
+
/** The review key being matched, by the name a host's text box hands it over by. */
|
|
738
|
+
let named: ReviewKeyName | undefined;
|
|
739
|
+
const reviewKeyName = keydownHandler(
|
|
740
|
+
Object.fromEntries(
|
|
741
|
+
(['accept', 'dismiss', 'next', 'previous'] as const).map((key) => [
|
|
742
|
+
REVIEW_KEYS[key],
|
|
743
|
+
() => {
|
|
744
|
+
named = key;
|
|
745
|
+
return true;
|
|
746
|
+
}
|
|
747
|
+
])
|
|
748
|
+
)
|
|
749
|
+
);
|
|
750
|
+
/** Alt-F10: the card brought back from wherever typing or a scroll put it, then entered. */
|
|
751
|
+
async function enterCard(id: string): Promise<void> {
|
|
752
|
+
typing = false;
|
|
753
|
+
if (!inView(id) || !(answerCard?.standsInView() ?? true)) await reveal(id, false, false);
|
|
754
|
+
await tick();
|
|
755
|
+
// A reveal glides, and the card is entered once it stands in the pane.
|
|
756
|
+
for (let frame = 0; frame < ENTER_FRAMES && reviewing.lit === id; frame++) {
|
|
757
|
+
if (await answerCard?.enter()) return;
|
|
758
|
+
await new Promise(requestAnimationFrame);
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
/** How many frames Alt-F10 waits for a reveal's scroll to bring the card into the pane. */
|
|
762
|
+
const ENTER_FRAMES = 90;
|
|
701
763
|
/** Whether the key being matched was pressed inside the editor, where a step takes the caret
|
|
702
764
|
* with it. */
|
|
703
765
|
let inside = false;
|
|
704
|
-
/**
|
|
705
|
-
|
|
766
|
+
/** Whether the key being matched is the keyboard's repeat of a held one. */
|
|
767
|
+
let repeat = false;
|
|
768
|
+
/** The review keys, captured on the document ahead of a leaf's arrows and a host's own keys. */
|
|
706
769
|
function onReviewKey(e: KeyboardEvent): void {
|
|
707
|
-
if (
|
|
708
|
-
|
|
770
|
+
if (!e.repeat) {
|
|
771
|
+
asked = undefined;
|
|
772
|
+
heldChord = undefined;
|
|
773
|
+
} else if (heldChord === chordOf(e)) {
|
|
774
|
+
e.preventDefault();
|
|
775
|
+
e.stopPropagation();
|
|
776
|
+
return;
|
|
777
|
+
}
|
|
778
|
+
if (e.defaultPrevented || e.isComposing || e.keyCode === 229) return;
|
|
779
|
+
if (reviewing.lit === undefined || !rootEl) return;
|
|
780
|
+
named = undefined;
|
|
781
|
+
reviewKeyName({} as never, e);
|
|
782
|
+
if (!reviewKeysHeard(e.target, rootEl, named)) return;
|
|
783
|
+
inside = rootEl.contains(e.target as Node);
|
|
784
|
+
repeat = e.repeat;
|
|
785
|
+
answered = false;
|
|
709
786
|
// The bindings read no view: this is `prosemirror-keymap`'s chord matcher alone.
|
|
710
787
|
if (!reviewKeys({} as never, e)) return;
|
|
788
|
+
if (answered) heldChord = chordOf(e);
|
|
711
789
|
e.preventDefault();
|
|
712
790
|
e.stopPropagation();
|
|
713
791
|
}
|
|
714
792
|
|
|
715
|
-
/** The reader is typing: the card keeps out of the way until the pointer moves
|
|
716
|
-
*
|
|
793
|
+
/** The reader is typing: the card keeps out of the way until the pointer moves, the caret
|
|
794
|
+
* lands on a change, the focus moves to another leaf or place, or an answer key or Alt-F10
|
|
795
|
+
* asks for it. */
|
|
717
796
|
let typing = $state(false);
|
|
718
797
|
let pointerAt = { x: NaN, y: NaN };
|
|
719
798
|
function onTyped(e: KeyboardEvent): void {
|
|
720
799
|
if (reviewing.lit === undefined || e.metaKey || e.ctrlKey || e.altKey) return;
|
|
800
|
+
if (e.target instanceof Element && e.target.closest('.qm-review-card')) return;
|
|
721
801
|
if (e.key.length === 1 || e.key === 'Backspace' || e.key === 'Delete' || e.key === 'Enter')
|
|
722
802
|
typing = true;
|
|
723
803
|
}
|
|
724
804
|
function onPointerMove(e: PointerEvent): void {
|
|
805
|
+
asked = undefined;
|
|
725
806
|
if (!typing) {
|
|
726
807
|
pointerAt = { x: e.clientX, y: e.clientY };
|
|
727
808
|
return;
|
|
@@ -738,42 +819,73 @@
|
|
|
738
819
|
function reviewIds(el: Element | null | undefined): string[] {
|
|
739
820
|
return el?.getAttribute('data-qm-review')?.split(' ').filter(Boolean) ?? [];
|
|
740
821
|
}
|
|
741
|
-
/** A press on a change makes it current at once, and a press elsewhere
|
|
742
|
-
*
|
|
822
|
+
/** A press on a change makes it current at once, and a press elsewhere the change nearest it
|
|
823
|
+
* in its place (`placeOf`). */
|
|
743
824
|
function onPick(e: PointerEvent): void {
|
|
744
825
|
const target = e.target instanceof Element ? e.target : null;
|
|
745
|
-
|
|
746
|
-
const id = ids.includes(reviewing.lit ?? '') ? reviewing.lit : ids[0];
|
|
747
|
-
if (id && reviewing.items.some((item) => item.id === id)) {
|
|
748
|
-
typing = false;
|
|
749
|
-
reviewing.reveal(id);
|
|
750
|
-
} else if (target) pickNear(target);
|
|
826
|
+
if (target && !nameAt(target)) pickNear(target);
|
|
751
827
|
}
|
|
752
|
-
/** The
|
|
753
|
-
*
|
|
828
|
+
/** The focus arriving from elsewhere on the page, not handed back from a surface floating over
|
|
829
|
+
* the editor, is a press by another hand: on a change it names it, and elsewhere the change
|
|
830
|
+
* nearest it in its place. Moving from one leaf or place to another ends the writing the
|
|
831
|
+
* card stood aside for. A leaf of words that draws changes of its own names them from its
|
|
832
|
+
* caret (`review-caret.ts`). */
|
|
754
833
|
function onArrive(e: FocusEvent): void {
|
|
755
834
|
const target = e.target instanceof Element ? e.target : null;
|
|
756
835
|
const from = e.relatedTarget instanceof Element ? e.relatedTarget : null;
|
|
757
836
|
if (!target || !from || from.closest('.qm-popover-surface')) return;
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
837
|
+
if (
|
|
838
|
+
from.closest('.ProseMirror') !== target.closest('.ProseMirror') ||
|
|
839
|
+
placeOf(from) !== placeOf(target)
|
|
840
|
+
)
|
|
841
|
+
typing = false;
|
|
842
|
+
if (target.closest('.ProseMirror')?.querySelector('[data-qm-review]')) return;
|
|
843
|
+
const marked = target.closest('[data-qm-review]');
|
|
844
|
+
if (marked && openIds(marked).length) {
|
|
845
|
+
if (!marked.contains(from)) nameAt(target);
|
|
846
|
+
return;
|
|
847
|
+
}
|
|
848
|
+
const place = placeOf(target);
|
|
849
|
+
if (place && !place.contains(from)) pickNear(target);
|
|
850
|
+
}
|
|
851
|
+
/** The focus left the editor: the reader is no longer writing in it. */
|
|
852
|
+
function onLeave(e: FocusEvent): void {
|
|
853
|
+
if (!(e.relatedTarget instanceof Node && rootEl?.contains(e.relatedTarget))) typing = false;
|
|
854
|
+
}
|
|
855
|
+
/** The open items `el` draws. */
|
|
856
|
+
function openIds(el: Element): string[] {
|
|
857
|
+
return reviewIds(el).filter((id) => reviewing.items.some((item) => item.id === id));
|
|
858
|
+
}
|
|
859
|
+
/** Make current the open change `el` stands in, the current one where it stands in several.
|
|
860
|
+
* False where it stands in none. */
|
|
861
|
+
function nameAt(el: Element): boolean {
|
|
862
|
+
const ids = openIds(el.closest('[data-qm-review]') ?? el);
|
|
863
|
+
if (!ids.length) return false;
|
|
864
|
+
typing = false;
|
|
865
|
+
reviewing.reveal(ids.includes(reviewing.lit ?? '') ? reviewing.lit! : ids[0]);
|
|
866
|
+
return true;
|
|
867
|
+
}
|
|
868
|
+
/** Where a reader arriving at `el` means to work: the list it is a row of, else the control it
|
|
869
|
+
* is in, a record's property as much as a field. A group or a record holding properties is
|
|
870
|
+
* no place, so its header and the gaps between its properties name nothing. */
|
|
871
|
+
function placeOf(el: Element): Element | undefined {
|
|
872
|
+
const row = el.closest('.qm-array-row');
|
|
873
|
+
if (row?.parentElement)
|
|
874
|
+
return row.parentElement.closest('.qm-object-prop, .qm-field') ?? undefined;
|
|
875
|
+
const place = el.closest('.qm-object-prop, .qm-field');
|
|
876
|
+
return place?.matches('.qm-field') && place.querySelector('.qm-object-prop')
|
|
877
|
+
? undefined
|
|
878
|
+
: (place ?? undefined);
|
|
879
|
+
}
|
|
880
|
+
/** Make the change in `target`'s place nearest it current, the fewest rows away and then the
|
|
881
|
+
* fewest pixels across, the current item being another place's. A leaf of words that draws
|
|
770
882
|
* changes of its own names them from its caret (`review-caret.ts`). */
|
|
771
883
|
function pickNear(target: Element): void {
|
|
772
884
|
if (target.closest('.ProseMirror')?.querySelector('[data-qm-review]')) return;
|
|
773
|
-
const
|
|
774
|
-
if (!
|
|
885
|
+
const place = placeOf(target);
|
|
886
|
+
if (!place) return;
|
|
775
887
|
const open = new Set(reviewing.order);
|
|
776
|
-
const marks = [...
|
|
888
|
+
const marks = [...place.querySelectorAll('[data-qm-review]')].filter((el) =>
|
|
777
889
|
reviewIds(el).some((id) => open.has(id))
|
|
778
890
|
);
|
|
779
891
|
if (!marks.length) return;
|
|
@@ -809,7 +921,7 @@
|
|
|
809
921
|
if (!key?.field) return '';
|
|
810
922
|
const isMain = key.card === undefined;
|
|
811
923
|
const card = isMain ? model.main : model.cards[cardIndexOf(key.card as CardId)];
|
|
812
|
-
const schema = isMain ? quill.schema.main : quill.schema
|
|
924
|
+
const schema = isMain ? quill.schema.main : quill.schema[card?.kind ?? ''];
|
|
813
925
|
const sub = schema?.fields[key.field];
|
|
814
926
|
return sub ? fieldTitle(key.field, sub) : humanize(key.field);
|
|
815
927
|
}
|
|
@@ -924,7 +1036,7 @@
|
|
|
924
1036
|
const { card: at, field } = addr;
|
|
925
1037
|
if (typeof at !== 'number' || field == null) return;
|
|
926
1038
|
const shown = model.cards[at];
|
|
927
|
-
const cardSchema = shown && quill.schema
|
|
1039
|
+
const cardSchema = shown && quill.schema[shown.kind];
|
|
928
1040
|
if (!cardSchema || cardSchema.title?.trim()) return;
|
|
929
1041
|
const sub = Object.hasOwn(cardSchema.fields, field) ? cardSchema.fields[field] : undefined;
|
|
930
1042
|
if (!sub || !shortCell(sub)) return;
|
|
@@ -1139,7 +1251,7 @@
|
|
|
1139
1251
|
const name =
|
|
1140
1252
|
shown?.titleOverride ||
|
|
1141
1253
|
shown?.titlePlaceholder ||
|
|
1142
|
-
kindTitle(quill.schema
|
|
1254
|
+
kindTitle(quill.schema[card.kind], card.kind);
|
|
1143
1255
|
const gone = removed.remove(id, card, cardIds, i);
|
|
1144
1256
|
doc.removeCard(i);
|
|
1145
1257
|
arm.arm();
|
|
@@ -1398,7 +1510,7 @@
|
|
|
1398
1510
|
false,
|
|
1399
1511
|
c.kind,
|
|
1400
1512
|
c,
|
|
1401
|
-
schema
|
|
1513
|
+
schema[c.kind],
|
|
1402
1514
|
byCard.get(i) ?? NO_RESOLVED_ROWS
|
|
1403
1515
|
)
|
|
1404
1516
|
)
|
|
@@ -1662,11 +1774,15 @@
|
|
|
1662
1774
|
}
|
|
1663
1775
|
if (!(await span.resumes(tick()))) return false;
|
|
1664
1776
|
reviewing.reveal(id);
|
|
1665
|
-
|
|
1777
|
+
const thing = focus ? reviewEls(id).find((el) => el.matches(THING)) : undefined;
|
|
1778
|
+
if (thing) thing.focus({ preventScroll: true });
|
|
1779
|
+
else if (focus && key !== undefined && !leaves.prose(key)?.enterReview(id)) {
|
|
1666
1780
|
const control = leaves.control(key);
|
|
1667
1781
|
const steps = reviewing.at(key).nested?.find((e) => e.item.id === id)?.steps;
|
|
1668
|
-
if (steps && control?.focusPath) control.focusPath(steps);
|
|
1782
|
+
if (steps && control?.focusPath) await control.focusPath(steps);
|
|
1669
1783
|
else control?.focus();
|
|
1784
|
+
if (!span.alive) return false;
|
|
1785
|
+
caretToEnd(id);
|
|
1670
1786
|
}
|
|
1671
1787
|
// The current item is drawn again, so its element is read once it has been.
|
|
1672
1788
|
if (!(await span.resumes(tick()))) return false;
|
|
@@ -1675,11 +1791,50 @@
|
|
|
1675
1791
|
(key !== undefined ? leaves.prose(key)?.reviewElements(id)[0] : undefined) ??
|
|
1676
1792
|
els[0] ??
|
|
1677
1793
|
(key !== undefined ? leaves.control(key)?.el : undefined);
|
|
1678
|
-
if (!at
|
|
1794
|
+
if (!at) return true;
|
|
1795
|
+
const extent = framing(answerCard?.extent());
|
|
1796
|
+
if (stepping && comfortable(els.length ? els : [at], extent)) return true;
|
|
1679
1797
|
const reduce = window.matchMedia?.('(prefers-reduced-motion: reduce)').matches;
|
|
1680
|
-
frame(at, {
|
|
1798
|
+
frame(at, {
|
|
1799
|
+
block: 'center',
|
|
1800
|
+
foot: reviewInset,
|
|
1801
|
+
behavior: reduce ? 'instant' : 'smooth',
|
|
1802
|
+
extent
|
|
1803
|
+
});
|
|
1681
1804
|
return true;
|
|
1682
1805
|
}
|
|
1806
|
+
/** What a reveal frames beside the change: `whole`, the change's blocks and its card, where
|
|
1807
|
+
* they fit in the pane together. Where they do not, the card pins at the pane's foot and the
|
|
1808
|
+
* change's own words are what to show, so nothing is framed beside them. */
|
|
1809
|
+
function framing(
|
|
1810
|
+
whole: { top: number; bottom: number } | undefined
|
|
1811
|
+
): { top: number; bottom: number } | undefined {
|
|
1812
|
+
if (!whole) return undefined;
|
|
1813
|
+
const { top, bottom } = pane();
|
|
1814
|
+
const room = bottom - reviewInset - top - 2 * (spacePx(rootEl, 1) ?? 0);
|
|
1815
|
+
return whole.bottom - whole.top <= room ? whole : undefined;
|
|
1816
|
+
}
|
|
1817
|
+
/** What a change that is a thing draws, which takes the focus as one stop: a row or a card
|
|
1818
|
+
* proposed new, and a card proposed for removal. */
|
|
1819
|
+
const THING = '.qm-review-added, .qm-review-card-add, .qm-review-card-remove.qm-review-on';
|
|
1820
|
+
/** Put the caret at the end of the words of `id` in the leaf holding the focus: past its last
|
|
1821
|
+
* run, or ahead of a piece it adds, which stands at the end of the line it follows. */
|
|
1822
|
+
function caretToEnd(id: string): void {
|
|
1823
|
+
const leaf = document.activeElement?.closest('.ProseMirror');
|
|
1824
|
+
const last = leaf
|
|
1825
|
+
? [...leaf.querySelectorAll('[data-qm-review]')]
|
|
1826
|
+
.filter((el) => reviewIds(el).includes(id))
|
|
1827
|
+
.at(-1)
|
|
1828
|
+
: undefined;
|
|
1829
|
+
const selection = document.getSelection();
|
|
1830
|
+
if (!last || !selection) return;
|
|
1831
|
+
const range = document.createRange();
|
|
1832
|
+
if (last.getAttribute('contenteditable') === 'false') range.setStartBefore(last);
|
|
1833
|
+
else range.selectNodeContents(last);
|
|
1834
|
+
range.collapse(last.getAttribute('contenteditable') === 'false');
|
|
1835
|
+
selection.removeAllRanges();
|
|
1836
|
+
selection.addRange(range);
|
|
1837
|
+
}
|
|
1683
1838
|
/** Whether the open card item `id` is drawn. */
|
|
1684
1839
|
function byCardId(id: string): boolean {
|
|
1685
1840
|
for (const list of reviewing.cards.adds.values())
|
|
@@ -1706,16 +1861,17 @@
|
|
|
1706
1861
|
const boxes = (els: readonly HTMLElement[]): DOMRect[] =>
|
|
1707
1862
|
els.map((el) => el.getBoundingClientRect()).filter((r) => r.width || r.height);
|
|
1708
1863
|
/** Whether `els` stand in the view the editor scrolls in, clear of the host's chrome at its
|
|
1709
|
-
* foot, with the answer card
|
|
1710
|
-
function comfortable(
|
|
1864
|
+
* foot, with `extent`, the change and its answer card as the card stands, inside it too. */
|
|
1865
|
+
function comfortable(
|
|
1866
|
+
els: readonly HTMLElement[],
|
|
1867
|
+
extent: { top: number; bottom: number } | undefined
|
|
1868
|
+
): boolean {
|
|
1711
1869
|
const rects = boxes(els);
|
|
1712
1870
|
if (!rects.length) return false;
|
|
1713
1871
|
const { top, bottom } = pane();
|
|
1714
|
-
const
|
|
1715
|
-
const
|
|
1716
|
-
return (
|
|
1717
|
-
(framedTop(els, band) ?? top) >= top && Math.max(...rects.map((r) => r.bottom)) <= band.bottom
|
|
1718
|
-
);
|
|
1872
|
+
const band = { top, bottom: bottom - reviewInset - (spacePx(rootEl, 1) ?? 0) };
|
|
1873
|
+
const lowest = Math.max(extent?.bottom ?? -Infinity, ...rects.map((r) => r.bottom));
|
|
1874
|
+
return (framedTop(els, band) ?? top) >= top && lowest <= band.bottom;
|
|
1719
1875
|
}
|
|
1720
1876
|
/** Whether any of the item `id` shows in that view, which is where its answer card stands.
|
|
1721
1877
|
* An editor with no box of its own measures nothing, and every item counts as shown. */
|
|
@@ -1724,8 +1880,6 @@
|
|
|
1724
1880
|
const { top, bottom } = pane();
|
|
1725
1881
|
return boxes(reviewEls(id)).some((r) => r.bottom > top && r.top < bottom - reviewInset);
|
|
1726
1882
|
}
|
|
1727
|
-
/** The room the answer card takes under a change, in `--_qm-space` rungs. */
|
|
1728
|
-
const CARD_ROOM = 7;
|
|
1729
1883
|
|
|
1730
1884
|
/** Whether the item `id` is listed in `group`. */
|
|
1731
1885
|
function inGroup(group: string): (id: string) => boolean {
|
|
@@ -2000,7 +2154,7 @@
|
|
|
2000
2154
|
if (addr.field == null) return undefined;
|
|
2001
2155
|
const kind = typeof addr.card === 'number' ? model.cards[addr.card]?.kind : undefined;
|
|
2002
2156
|
const schema = quill.schema;
|
|
2003
|
-
const card = addr.card == null ? schema.main : kind ? schema
|
|
2157
|
+
const card = addr.card == null ? schema.main : kind ? schema[kind] : undefined;
|
|
2004
2158
|
return card?.fields?.[addr.field];
|
|
2005
2159
|
}
|
|
2006
2160
|
|
|
@@ -2033,6 +2187,7 @@
|
|
|
2033
2187
|
onkeydowncapture={onTyped}
|
|
2034
2188
|
onpointerdowncapture={onPick}
|
|
2035
2189
|
onfocusin={onArrive}
|
|
2190
|
+
onfocusout={onLeave}
|
|
2036
2191
|
onkeydown={raiseGuidance}
|
|
2037
2192
|
ondragover={refuseFiles}
|
|
2038
2193
|
ondrop={refuseFiles}
|
|
@@ -2076,13 +2231,16 @@
|
|
|
2076
2231
|
{@const removal = reviewing.cards.removes.get(c.id)}
|
|
2077
2232
|
<div class="qm-card-slot" bind:this={slotEls[i]} animate:reorder={arm.armed} in:slot out:slot>
|
|
2078
2233
|
<!-- A removal's mark wraps the whole card it would take out, so the answer card
|
|
2079
|
-
stands under the card and not on it.
|
|
2234
|
+
stands under the card and not on it. A step lands the focus on it, out of the Tab
|
|
2235
|
+
walk. -->
|
|
2236
|
+
<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
|
|
2080
2237
|
<div
|
|
2081
2238
|
class={[
|
|
2082
|
-
'qm-review-card-remove',
|
|
2239
|
+
'qm-review-card-remove qm-focus-ring',
|
|
2083
2240
|
{ 'qm-review-on': !!removal, 'qm-review-lit': !!removal && reviewing.lit === removal.id }
|
|
2084
2241
|
]}
|
|
2085
2242
|
data-qm-review={removal?.id}
|
|
2243
|
+
tabindex={removal ? -1 : undefined}
|
|
2086
2244
|
role={removal ? 'group' : undefined}
|
|
2087
2245
|
aria-label={removal ? merged.reviewRemoveCard : undefined}
|
|
2088
2246
|
>
|
|
@@ -2115,6 +2273,7 @@
|
|
|
2115
2273
|
root={rootEl}
|
|
2116
2274
|
inset={reviewInset}
|
|
2117
2275
|
hidden={typing}
|
|
2276
|
+
{asked}
|
|
2118
2277
|
outdated={reviewing.lit !== undefined && drewOutdated.includes(reviewing.lit)}
|
|
2119
2278
|
note={reviewing.lit === undefined
|
|
2120
2279
|
? undefined
|
|
@@ -2163,7 +2322,7 @@
|
|
|
2163
2322
|
|
|
2164
2323
|
<FormatPopover {getActiveLeaf} families={fontFamilies} {fontLabels} />
|
|
2165
2324
|
|
|
2166
|
-
<!-- The add affordance is gated on the schema declaring
|
|
2325
|
+
<!-- The add affordance is gated on the schema declaring a card kind, there being
|
|
2167
2326
|
nothing to seed otherwise. Cards render regardless: a kind with no schema degrades to
|
|
2168
2327
|
a recovery shell inside <Card> (retype + delete), never gated away, so its content is
|
|
2169
2328
|
neither dropped nor trapped. The gate lives here rather than at each call site: the
|
|
@@ -2179,8 +2338,12 @@
|
|
|
2179
2338
|
{@const preview = previewOf(item)}
|
|
2180
2339
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
2181
2340
|
<div
|
|
2182
|
-
class={[
|
|
2341
|
+
class={[
|
|
2342
|
+
'qm-review-card-add qm-focus-ring',
|
|
2343
|
+
{ 'qm-review-lit': reviewing.lit === item.id }
|
|
2344
|
+
]}
|
|
2183
2345
|
data-qm-review={item.id}
|
|
2346
|
+
tabindex="-1"
|
|
2184
2347
|
role="group"
|
|
2185
2348
|
aria-label={`${merged.reviewNewCard}, ${preview.title}`}
|
|
2186
2349
|
>
|
|
@@ -2252,7 +2415,7 @@
|
|
|
2252
2415
|
<div class="qm-menu-surface" data-qm-root>
|
|
2253
2416
|
{#each kinds as k (k)}
|
|
2254
2417
|
<DropdownMenu.Item class="qm-menu-item" onSelect={() => addPicked(atIndex, k)}
|
|
2255
|
-
>{kindTitle(quill.schema
|
|
2418
|
+
>{kindTitle(quill.schema[k], k)}</DropdownMenu.Item
|
|
2256
2419
|
>
|
|
2257
2420
|
{/each}
|
|
2258
2421
|
</div>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** A control that keeps its own keys: a form control, or anything the reader types in under
|
|
2
|
+
* any spelling of `contenteditable` but `false`, which the nearest one holding it decides. */
|
|
3
|
+
export declare function textBox(target: Element): boolean;
|
|
4
|
+
/** A review key by name, as a host lists the ones a text box hands over. */
|
|
5
|
+
export type ReviewKeyName = 'accept' | 'dismiss' | 'next' | 'previous' | 'undo';
|
|
6
|
+
/**
|
|
7
|
+
* Whether review key `key` pressed at `target` is the review's: anywhere on the page but under
|
|
8
|
+
* a modal the editor stands outside, inside another editor, or in a text box outside the editor.
|
|
9
|
+
* A text box the host marks `data-qm-review-keys` hands over the keys it has no use for: all of
|
|
10
|
+
* them with the attribute empty, the ones it names otherwise, so a prompt holding a draft can
|
|
11
|
+
* hand over accept and keep dismiss for its own delete. With no `root`, every editor on the
|
|
12
|
+
* page counts as the one asking.
|
|
13
|
+
*/
|
|
14
|
+
export declare function reviewKeysHeard(target: EventTarget | null, root?: Element, key?: ReviewKeyName): boolean;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/** A control that keeps its own keys: a form control, or anything the reader types in under
|
|
2
|
+
* any spelling of `contenteditable` but `false`, which the nearest one holding it decides. */
|
|
3
|
+
export function textBox(target) {
|
|
4
|
+
if (target.closest('input, textarea, select'))
|
|
5
|
+
return true;
|
|
6
|
+
const editable = target.closest('[contenteditable]');
|
|
7
|
+
return !!editable && editable.getAttribute('contenteditable')?.toLowerCase() !== 'false';
|
|
8
|
+
}
|
|
9
|
+
const MODALS = '[aria-modal="true"], dialog[open]';
|
|
10
|
+
/** Whether `el` is a modal on show. A `<dialog>` is one only as `showModal` opens it, and
|
|
11
|
+
* counts as one where the engine has no `:modal` to ask. */
|
|
12
|
+
function modal(el) {
|
|
13
|
+
if (el.checkVisibility?.() === false)
|
|
14
|
+
return false;
|
|
15
|
+
if (!(el instanceof HTMLDialogElement))
|
|
16
|
+
return true;
|
|
17
|
+
try {
|
|
18
|
+
return el.matches(':modal');
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/** Whether a modal on show stands over the editor: one holding neither `root` nor, with no
|
|
25
|
+
* `root`, any editor. A key under it is the dialog's wherever the focus is, on the page behind
|
|
26
|
+
* it included. */
|
|
27
|
+
function underModal(root) {
|
|
28
|
+
for (const el of document.querySelectorAll(MODALS))
|
|
29
|
+
if (modal(el) && !(root ? el.contains(root) : el.querySelector('.qm-editor')))
|
|
30
|
+
return true;
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
/** Whether the text box holding `target` hands the review `key`: `data-qm-review-keys` empty
|
|
34
|
+
* hands every key over, and a list of names hands those alone. */
|
|
35
|
+
function handedOver(target, key) {
|
|
36
|
+
const box = target.closest('[data-qm-review-keys]');
|
|
37
|
+
if (!box)
|
|
38
|
+
return false;
|
|
39
|
+
const names = box.getAttribute('data-qm-review-keys').split(/\s+/).filter(Boolean);
|
|
40
|
+
return !names.length || (key !== undefined && names.includes(key));
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Whether review key `key` pressed at `target` is the review's: anywhere on the page but under
|
|
44
|
+
* a modal the editor stands outside, inside another editor, or in a text box outside the editor.
|
|
45
|
+
* A text box the host marks `data-qm-review-keys` hands over the keys it has no use for: all of
|
|
46
|
+
* them with the attribute empty, the ones it names otherwise, so a prompt holding a draft can
|
|
47
|
+
* hand over accept and keep dismiss for its own delete. With no `root`, every editor on the
|
|
48
|
+
* page counts as the one asking.
|
|
49
|
+
*/
|
|
50
|
+
export function reviewKeysHeard(target, root, key) {
|
|
51
|
+
if (!(target instanceof Element) || underModal(root))
|
|
52
|
+
return false;
|
|
53
|
+
if (root ? root.contains(target) : target.closest('.qm-editor'))
|
|
54
|
+
return true;
|
|
55
|
+
if (target.closest('.qm-editor'))
|
|
56
|
+
return false;
|
|
57
|
+
return !textBox(target) || handedOver(target, key);
|
|
58
|
+
}
|
package/dist/visual/index.d.ts
CHANGED
|
@@ -13,5 +13,7 @@ export { proposalsBetween, reviewRevised } from './proposals.js';
|
|
|
13
13
|
export type { Proposed, ProposalsOpts } from './proposals.js';
|
|
14
14
|
export type { ReviewAction } from '../core/codec/index.js';
|
|
15
15
|
export { REVIEW_KEYS } from '../core/codec/index.js';
|
|
16
|
+
export { reviewKeysHeard } from './hears.js';
|
|
17
|
+
export type { ReviewKeyName } from './hears.js';
|
|
16
18
|
export { patchEditorExt } from './ext.js';
|
|
17
19
|
export type { ActiveLeaf, CardId, CardOp, ChangeSource, EditorChange } from './signals.js';
|
package/dist/visual/index.js
CHANGED
|
@@ -27,6 +27,7 @@ export { DEFAULT_VISUAL_STRINGS } from './strings.js';
|
|
|
27
27
|
export { editorShortcuts } from '../core/codec/index.js';
|
|
28
28
|
export { proposalsBetween, reviewRevised } from './proposals.js';
|
|
29
29
|
export { REVIEW_KEYS } from '../core/codec/index.js';
|
|
30
|
+
export { reviewKeysHeard } from './hears.js';
|
|
30
31
|
// The `$ext.editor` write unit. A consumer seeding editor-side chrome
|
|
31
32
|
// state (a card title, the tips channel) goes through this rather than `storeExt`,
|
|
32
33
|
// which replaces the whole map and takes every sibling with it.
|
package/dist/visual/proposals.js
CHANGED
|
@@ -196,7 +196,7 @@ export function proposalsBetween(quill, base, answer, opts = {}) {
|
|
|
196
196
|
}
|
|
197
197
|
kept.set(answerAt, at);
|
|
198
198
|
const first = items.length;
|
|
199
|
-
diffCard(quill.schema
|
|
199
|
+
diffCard(quill.schema[was.kind], at, was, now, answerAt);
|
|
200
200
|
if (id)
|
|
201
201
|
for (const item of items.slice(first))
|
|
202
202
|
Object.assign(item, { card: id });
|
|
@@ -63,6 +63,8 @@ export interface Review {
|
|
|
63
63
|
/** The item the caret is in, `undefined` where it left one: arriving names it at once, and
|
|
64
64
|
* leaving names nothing. */
|
|
65
65
|
point(id: string | undefined): void;
|
|
66
|
+
/** A count that moves each time the caret lands on a change, the current one included. */
|
|
67
|
+
readonly landed: number;
|
|
66
68
|
/** A reader's answer. False where it could not be made. */
|
|
67
69
|
act(id: string, action: ReviewAction): boolean;
|
|
68
70
|
/** Answer items as the answer card would, in the page's order: `'all'` is every item drawn,
|