@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
|
@@ -320,6 +320,32 @@ li.ProseMirror-selectednode::after {
|
|
|
320
320
|
}
|
|
321
321
|
}
|
|
322
322
|
|
|
323
|
+
/* The way out's hint (`leave.ts`): a status region beside the editable, in the corner of
|
|
324
|
+
the box the leaf stands in, over the text's last line rather than under it, so its
|
|
325
|
+
coming and going moves nothing. Empty at rest and still in the tree, which is what
|
|
326
|
+
lets a reader hear the words arrive. */
|
|
327
|
+
:where(:has(> .qm-leave-hint)) {
|
|
328
|
+
position: relative;
|
|
329
|
+
}
|
|
330
|
+
.qm-leave-hint {
|
|
331
|
+
position: absolute;
|
|
332
|
+
inset-block-end: var(--_qm-space);
|
|
333
|
+
inset-inline-end: var(--_qm-space);
|
|
334
|
+
padding: var(--_qm-space-half) var(--_qm-space-2);
|
|
335
|
+
border-radius: var(--_qm-radius-pill);
|
|
336
|
+
background: var(--_qm-surface-raised);
|
|
337
|
+
box-shadow: var(--_qm-lift);
|
|
338
|
+
font-size: var(--_qm-text-label);
|
|
339
|
+
font-style: normal;
|
|
340
|
+
line-height: 1;
|
|
341
|
+
white-space: nowrap;
|
|
342
|
+
color: var(--_qm-ink-label);
|
|
343
|
+
pointer-events: none;
|
|
344
|
+
}
|
|
345
|
+
.qm-leave-hint:empty {
|
|
346
|
+
opacity: 0;
|
|
347
|
+
}
|
|
348
|
+
|
|
323
349
|
/* ── The table island ────────────────────────────────────────────────────────
|
|
324
350
|
|
|
325
351
|
The one construct in this file with chrome in it. The rest of the stylesheet
|
|
@@ -759,3 +785,194 @@ li.ProseMirror-selectednode::after {
|
|
|
759
785
|
.qm-table-drop[data-axis='column'] {
|
|
760
786
|
width: var(--_qm-ring-width);
|
|
761
787
|
}
|
|
788
|
+
|
|
789
|
+
/* ── Review (`review.ts`) ────────────────────────────────────────────────────
|
|
790
|
+
Drawn in the leaf's own flow and at the leaf's own type, so a reviewed paragraph still
|
|
791
|
+
reads as the paragraph. One hue throughout (`--_qm-review`), and three strengths of it.
|
|
792
|
+
|
|
793
|
+
A change someone else made is a line under the words that were written: quieter than a
|
|
794
|
+
link's, which is the ink's, and absent from the page the document prints. The tint
|
|
795
|
+
arrives with attention. */
|
|
796
|
+
.ProseMirror .qm-review-changed {
|
|
797
|
+
text-decoration: underline;
|
|
798
|
+
text-decoration-color: var(--_qm-review-line);
|
|
799
|
+
text-decoration-thickness: var(--_qm-vertical-width);
|
|
800
|
+
text-underline-offset: 0.2em;
|
|
801
|
+
border-radius: var(--_qm-radius-inner);
|
|
802
|
+
transition: background-color var(--_qm-duration-fast) var(--_qm-ease-reverse);
|
|
803
|
+
}
|
|
804
|
+
.ProseMirror .qm-review-changed.qm-review-lit {
|
|
805
|
+
background: var(--_qm-review-tint);
|
|
806
|
+
}
|
|
807
|
+
/* Where text was only taken out there are no words to underline, so a wedge stands at the
|
|
808
|
+
join, under the baseline the way a proofreader's caret does. It takes no width: the
|
|
809
|
+
line reads as the document has it. What the pointer and a finger find is the join's
|
|
810
|
+
whole line, a letter to either side, since the wedge alone is too small to hit. */
|
|
811
|
+
.ProseMirror .qm-review-gone {
|
|
812
|
+
position: relative;
|
|
813
|
+
display: inline-block;
|
|
814
|
+
width: 0;
|
|
815
|
+
height: 1em;
|
|
816
|
+
vertical-align: text-bottom;
|
|
817
|
+
}
|
|
818
|
+
.ProseMirror .qm-review-gone::before {
|
|
819
|
+
content: '';
|
|
820
|
+
position: absolute;
|
|
821
|
+
inset: -0.15em -0.45em -0.4em;
|
|
822
|
+
}
|
|
823
|
+
.ProseMirror .qm-review-gone::after {
|
|
824
|
+
content: '';
|
|
825
|
+
position: absolute;
|
|
826
|
+
left: -0.35em;
|
|
827
|
+
bottom: -0.3em;
|
|
828
|
+
width: 0.7em;
|
|
829
|
+
height: 0.45em;
|
|
830
|
+
background: var(--_qm-review-line);
|
|
831
|
+
clip-path: polygon(50% 0, 100% 100%, 0 100%);
|
|
832
|
+
transition: background-color var(--_qm-duration-fast) var(--_qm-ease-reverse);
|
|
833
|
+
}
|
|
834
|
+
.ProseMirror .qm-review-gone.qm-review-lit::after {
|
|
835
|
+
background: var(--_qm-review);
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
/* A proposal is its paragraph read as an edit of itself. The words that would go step back
|
|
839
|
+
to the label ink under a line; the words that would come stand at the ink on the tint,
|
|
840
|
+
since they are what the reader is being asked to read. A struck word and the word
|
|
841
|
+
replacing it stand a space apart, having none of the paragraph's own between them. */
|
|
842
|
+
.ProseMirror .qm-review-del {
|
|
843
|
+
color: var(--_qm-ink-label);
|
|
844
|
+
text-decoration: line-through;
|
|
845
|
+
text-decoration-color: var(--_qm-review-line);
|
|
846
|
+
}
|
|
847
|
+
/* The tint runs a hair past the words on either side, as a highlighter does, without moving
|
|
848
|
+
them: a shadow in the tint's own colour beside the fill, so the line sets as it would
|
|
849
|
+
without the proposal. */
|
|
850
|
+
.ProseMirror .qm-review-ins {
|
|
851
|
+
text-decoration: none;
|
|
852
|
+
background: var(--_qm-review-tint);
|
|
853
|
+
box-shadow:
|
|
854
|
+
calc(-1 * var(--_qm-space-half)) 0 0 var(--_qm-review-tint),
|
|
855
|
+
var(--_qm-space-half) 0 0 var(--_qm-review-tint);
|
|
856
|
+
border-radius: var(--_qm-radius-inner);
|
|
857
|
+
-webkit-box-decoration-break: clone;
|
|
858
|
+
box-decoration-break: clone;
|
|
859
|
+
transition:
|
|
860
|
+
background-color var(--_qm-duration-fast) var(--_qm-ease-reverse),
|
|
861
|
+
box-shadow var(--_qm-duration-fast) var(--_qm-ease-reverse);
|
|
862
|
+
}
|
|
863
|
+
.ProseMirror .qm-review-del + .qm-review-ins {
|
|
864
|
+
margin-inline-start: calc(var(--_qm-space) + var(--_qm-space-half));
|
|
865
|
+
}
|
|
866
|
+
/* A block the proposal adds whole, in flow where it would stand. */
|
|
867
|
+
.ProseMirror .qm-review-add {
|
|
868
|
+
background: var(--_qm-review-tint);
|
|
869
|
+
box-shadow:
|
|
870
|
+
calc(-1 * var(--_qm-space)) 0 0 var(--_qm-review-tint),
|
|
871
|
+
var(--_qm-space) 0 0 var(--_qm-review-tint);
|
|
872
|
+
border-radius: var(--_qm-radius-inner);
|
|
873
|
+
transition:
|
|
874
|
+
background-color var(--_qm-duration-fast) var(--_qm-ease-reverse),
|
|
875
|
+
box-shadow var(--_qm-duration-fast) var(--_qm-ease-reverse);
|
|
876
|
+
}
|
|
877
|
+
.ProseMirror .qm-review-lit .qm-review-ins {
|
|
878
|
+
background: var(--_qm-review-lit);
|
|
879
|
+
box-shadow:
|
|
880
|
+
calc(-1 * var(--_qm-space-half)) 0 0 var(--_qm-review-lit),
|
|
881
|
+
var(--_qm-space-half) 0 0 var(--_qm-review-lit);
|
|
882
|
+
}
|
|
883
|
+
.ProseMirror .qm-review-add.qm-review-lit {
|
|
884
|
+
background: var(--_qm-review-lit);
|
|
885
|
+
box-shadow:
|
|
886
|
+
calc(-1 * var(--_qm-space)) 0 0 var(--_qm-review-lit),
|
|
887
|
+
var(--_qm-space) 0 0 var(--_qm-review-lit);
|
|
888
|
+
}
|
|
889
|
+
/* A block the proposal takes whole that has no words to strike: a rule, an island. */
|
|
890
|
+
.ProseMirror .qm-review-out:is(hr, div) {
|
|
891
|
+
opacity: var(--_qm-opacity-muted);
|
|
892
|
+
}
|
|
893
|
+
/* The empty paragraph a proposal writes into shows the proposal, not the leaf's ghost. */
|
|
894
|
+
.ProseMirror .qm-review-held.qm-prose-placeholder[data-placeholder]::after {
|
|
895
|
+
content: none;
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
/* A proposal's two answers, at the end of its last line: chrome set in the paragraph, so
|
|
899
|
+
at the chrome's face and the label rung whatever the block around it is set in. A run
|
|
900
|
+
rather than a row, so a proposal takes no line the paragraph did not have; the row is
|
|
901
|
+
for a block with no line to end. The run stands a space off the words, and the space is
|
|
902
|
+
a real one, widened: it hangs at the end of a line the answers wrap from, where a margin
|
|
903
|
+
would indent them. Accept is the one outlined thing in the pair, on the card's own
|
|
904
|
+
ground so it reads as a button over a tinted block too, and Dismiss rests as a word. */
|
|
905
|
+
.ProseMirror .qm-review-chip {
|
|
906
|
+
font-family: var(--_qm-font);
|
|
907
|
+
font-size: var(--_qm-text-label);
|
|
908
|
+
font-style: normal;
|
|
909
|
+
font-weight: var(--_qm-weight-mid);
|
|
910
|
+
line-height: var(--_qm-leading-tight);
|
|
911
|
+
word-spacing: var(--_qm-space);
|
|
912
|
+
user-select: none;
|
|
913
|
+
}
|
|
914
|
+
.qm-review-acts {
|
|
915
|
+
display: inline-flex;
|
|
916
|
+
gap: var(--_qm-space-half);
|
|
917
|
+
vertical-align: baseline;
|
|
918
|
+
word-spacing: normal;
|
|
919
|
+
white-space: nowrap;
|
|
920
|
+
}
|
|
921
|
+
.ProseMirror .qm-review-chip-row {
|
|
922
|
+
display: block;
|
|
923
|
+
margin-block-start: var(--_qm-space);
|
|
924
|
+
}
|
|
925
|
+
.qm-review-act {
|
|
926
|
+
padding: var(--_qm-space-half) var(--_qm-space-2);
|
|
927
|
+
border: none;
|
|
928
|
+
border-radius: var(--_qm-radius-inner);
|
|
929
|
+
background: transparent;
|
|
930
|
+
font: inherit;
|
|
931
|
+
color: var(--_qm-ink-label);
|
|
932
|
+
cursor: pointer;
|
|
933
|
+
transition:
|
|
934
|
+
background-color var(--_qm-duration-fast) var(--_qm-ease-reverse),
|
|
935
|
+
color var(--_qm-duration-fast) var(--_qm-ease-reverse);
|
|
936
|
+
}
|
|
937
|
+
.qm-review-act:hover {
|
|
938
|
+
background: var(--_qm-surface-hover);
|
|
939
|
+
color: var(--_qm-ink);
|
|
940
|
+
}
|
|
941
|
+
.qm-review-act.qm-review-accept {
|
|
942
|
+
background: var(--_qm-bg);
|
|
943
|
+
box-shadow: inset 0 0 0 var(--_qm-vertical-width) var(--_qm-review-line);
|
|
944
|
+
color: var(--_qm-ink);
|
|
945
|
+
}
|
|
946
|
+
.qm-review-act.qm-review-accept:hover {
|
|
947
|
+
background: linear-gradient(var(--_qm-review-tint), var(--_qm-review-tint)) var(--_qm-bg);
|
|
948
|
+
}
|
|
949
|
+
/* Under a finger the two answers are a tap target each, and stand apart. */
|
|
950
|
+
@media (pointer: coarse) {
|
|
951
|
+
.qm-review-act {
|
|
952
|
+
padding-block: var(--_qm-space);
|
|
953
|
+
}
|
|
954
|
+
.qm-review-acts {
|
|
955
|
+
gap: var(--_qm-space-2);
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
/* A proposal the reader's own writing meets says so before its answers, in the label's ink:
|
|
959
|
+
taking it writes over what the reader wrote. */
|
|
960
|
+
.qm-review-outdated-label {
|
|
961
|
+
align-self: center;
|
|
962
|
+
color: var(--_qm-ink-label);
|
|
963
|
+
}
|
|
964
|
+
/* Forced colours drop the tint, which is all that tells a proposed word from the document's
|
|
965
|
+
and Accept from a word beside it. A line under the proposed words, an outline round an
|
|
966
|
+
added block and the system's button stroke round each answer stand in. */
|
|
967
|
+
@media (forced-colors: active) {
|
|
968
|
+
.ProseMirror .qm-review-ins {
|
|
969
|
+
text-decoration: underline;
|
|
970
|
+
}
|
|
971
|
+
.ProseMirror .qm-review-add {
|
|
972
|
+
outline: var(--_qm-border-width) solid CanvasText;
|
|
973
|
+
}
|
|
974
|
+
.qm-review-act.qm-review-accept,
|
|
975
|
+
.qm-review-act.qm-review-dismiss {
|
|
976
|
+
border: var(--_qm-border-width) solid ButtonText;
|
|
977
|
+
}
|
|
978
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** One change to `before`: its `[at, end)` gives way to `insert`. Either half may be empty. */
|
|
2
|
+
export interface DiffHunk {
|
|
3
|
+
at: number;
|
|
4
|
+
end: number;
|
|
5
|
+
insert: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* The hunks that take `before` to `after`, in order and apart. Two changes with only space between
|
|
9
|
+
* them are one, so a rewritten phrase reads as a phrase. Lines that share too few words to be an
|
|
10
|
+
* edit of one another differ whole.
|
|
11
|
+
*/
|
|
12
|
+
export declare function wordDiff(before: string, after: string): DiffHunk[];
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// The word diff a proposal draws: what a reader would strike from a line and what they would
|
|
2
|
+
// write in its place. Compared a word at a time, since a reader sees a word change and a
|
|
3
|
+
// character diff keeps the letters two words happen to share.
|
|
4
|
+
import { HARD_BREAK, ISLAND_SLOT } from './islands.js';
|
|
5
|
+
const WORD = /[\p{L}\p{N}\p{M}_'’]/u;
|
|
6
|
+
const SPACE = /\s/u;
|
|
7
|
+
/** `text` as tokens, each `[start, end)` in UTF-16: a run of word characters, a run of spaces, or
|
|
8
|
+
* any other one character. A break and an island are each a token of their own. */
|
|
9
|
+
function tokens(text) {
|
|
10
|
+
const out = [];
|
|
11
|
+
let run;
|
|
12
|
+
let at = 0;
|
|
13
|
+
for (const ch of text) {
|
|
14
|
+
const kind = ch === HARD_BREAK || ch === ISLAND_SLOT || ch === '\n'
|
|
15
|
+
? undefined
|
|
16
|
+
: WORD.test(ch)
|
|
17
|
+
? 'word'
|
|
18
|
+
: SPACE.test(ch)
|
|
19
|
+
? 'space'
|
|
20
|
+
: undefined;
|
|
21
|
+
if (kind && kind === run)
|
|
22
|
+
out[out.length - 1][1] = at + ch.length;
|
|
23
|
+
else
|
|
24
|
+
out.push([at, at + ch.length]);
|
|
25
|
+
run = kind;
|
|
26
|
+
at += ch.length;
|
|
27
|
+
}
|
|
28
|
+
return out;
|
|
29
|
+
}
|
|
30
|
+
/** Past this many cells the table is not built, and the lines differ whole between what they
|
|
31
|
+
* share at either end. */
|
|
32
|
+
const CELLS = 4_000_000;
|
|
33
|
+
/** The share of the longer line's words two lines have to hold in common to be drawn as an edit
|
|
34
|
+
* of one another. Under it the words they share are chance, and the diff is the whole line. */
|
|
35
|
+
const KIN = 0.34;
|
|
36
|
+
/**
|
|
37
|
+
* The hunks that take `before` to `after`, in order and apart. Two changes with only space between
|
|
38
|
+
* them are one, so a rewritten phrase reads as a phrase. Lines that share too few words to be an
|
|
39
|
+
* edit of one another differ whole.
|
|
40
|
+
*/
|
|
41
|
+
export function wordDiff(before, after) {
|
|
42
|
+
if (before === after)
|
|
43
|
+
return [];
|
|
44
|
+
const a = tokens(before);
|
|
45
|
+
const b = tokens(after);
|
|
46
|
+
const ka = a.map(([s, e]) => before.slice(s, e));
|
|
47
|
+
const kb = b.map(([s, e]) => after.slice(s, e));
|
|
48
|
+
let head = 0;
|
|
49
|
+
while (head < ka.length && head < kb.length && ka[head] === kb[head])
|
|
50
|
+
head++;
|
|
51
|
+
let tail = 0;
|
|
52
|
+
while (tail < ka.length - head &&
|
|
53
|
+
tail < kb.length - head &&
|
|
54
|
+
ka[ka.length - 1 - tail] === kb[kb.length - 1 - tail])
|
|
55
|
+
tail++;
|
|
56
|
+
const n = ka.length - head - tail;
|
|
57
|
+
const m = kb.length - head - tail;
|
|
58
|
+
const startA = (k) => (k < a.length ? a[k][0] : before.length);
|
|
59
|
+
const startB = (k) => (k < b.length ? b[k][0] : after.length);
|
|
60
|
+
const hunk = (a0, a1, b0, b1) => ({
|
|
61
|
+
at: startA(a0),
|
|
62
|
+
end: startA(a1),
|
|
63
|
+
insert: after.slice(startB(b0), startB(b1))
|
|
64
|
+
});
|
|
65
|
+
const whole = [hunk(head, head + n, head, head + m)];
|
|
66
|
+
if (!n || !m || n * m > CELLS)
|
|
67
|
+
return whole;
|
|
68
|
+
// Longest common subsequence over the middle, read back from the end so a run of matches
|
|
69
|
+
// sits as far left as the lines allow.
|
|
70
|
+
const width = m + 1;
|
|
71
|
+
const table = new Uint32Array((n + 1) * width);
|
|
72
|
+
for (let i = n - 1; i >= 0; i--)
|
|
73
|
+
for (let j = m - 1; j >= 0; j--)
|
|
74
|
+
table[i * width + j] =
|
|
75
|
+
ka[head + i] === kb[head + j]
|
|
76
|
+
? table[(i + 1) * width + j + 1] + 1
|
|
77
|
+
: Math.max(table[(i + 1) * width + j], table[i * width + j + 1]);
|
|
78
|
+
const isWord = (t) => !SPACE.test(t[0]);
|
|
79
|
+
const words = (list) => list.reduce((count, t) => count + (isWord(t) ? 1 : 0), 0);
|
|
80
|
+
let kept = words(ka.slice(0, head)) + words(ka.slice(ka.length - tail));
|
|
81
|
+
/** A run both lines hold, by its place in each, then the next. */
|
|
82
|
+
const runs = [];
|
|
83
|
+
let i = 0;
|
|
84
|
+
let j = 0;
|
|
85
|
+
let open;
|
|
86
|
+
const close = () => {
|
|
87
|
+
if (open)
|
|
88
|
+
runs.push([open[0], i, open[1], j]);
|
|
89
|
+
open = undefined;
|
|
90
|
+
};
|
|
91
|
+
while (i < n && j < m) {
|
|
92
|
+
if (ka[head + i] === kb[head + j]) {
|
|
93
|
+
open ??= [i, j];
|
|
94
|
+
if (isWord(ka[head + i]))
|
|
95
|
+
kept++;
|
|
96
|
+
i++;
|
|
97
|
+
j++;
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
close();
|
|
101
|
+
if (table[(i + 1) * width + j] >= table[i * width + j + 1])
|
|
102
|
+
i++;
|
|
103
|
+
else
|
|
104
|
+
j++;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
close();
|
|
108
|
+
const most = Math.max(words(ka), words(kb));
|
|
109
|
+
if (most >= 4 && kept / most < KIN)
|
|
110
|
+
return [hunk(0, ka.length, 0, kb.length)];
|
|
111
|
+
const out = [];
|
|
112
|
+
let ai = 0;
|
|
113
|
+
let bi = 0;
|
|
114
|
+
let pending;
|
|
115
|
+
for (const [a0, a1, b0, b1] of [...runs, [n, n, m, m]]) {
|
|
116
|
+
const spaces = a1 > a0 && a1 < n && ka.slice(head + a0, head + a1).every((t) => SPACE.test(t[0]));
|
|
117
|
+
if (spaces && (pending || a0 > ai || b0 > bi)) {
|
|
118
|
+
pending ??= [ai, bi];
|
|
119
|
+
ai = a1;
|
|
120
|
+
bi = b1;
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
const [fromA, fromB] = pending ?? [ai, bi];
|
|
124
|
+
if (a0 > fromA || b0 > fromB)
|
|
125
|
+
out.push(hunk(head + fromA, head + a0, head + fromB, head + b0));
|
|
126
|
+
pending = undefined;
|
|
127
|
+
ai = a1;
|
|
128
|
+
bi = b1;
|
|
129
|
+
}
|
|
130
|
+
return out;
|
|
131
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { type Node as PMNode } from 'prosemirror-model';
|
|
2
|
+
import { Plugin, type EditorState, type Transaction } from 'prosemirror-state';
|
|
3
|
+
import { type EditorView } from 'prosemirror-view';
|
|
4
|
+
import type { AnchorPos } from './marks.js';
|
|
5
|
+
/**
|
|
6
|
+
* One proposal over a prose leaf, by the blocks that place it.
|
|
7
|
+
*
|
|
8
|
+
* It reads the blocks `replace` names by id as rewritten to `after`, Markdown, where `''`
|
|
9
|
+
* proposes their removal. Its blocks pair with the paragraphs in order, each drawn as an edit of the one
|
|
10
|
+
* it pairs with while the two are one kind of block; past the first that is not, the paragraphs
|
|
11
|
+
* left are struck whole and the blocks left are added after the outermost block holding the last
|
|
12
|
+
* paragraph, or as the next items of its list. One that names where it adds, by `insert`, proposes new blocks the same way after the block it names, or before the leaf's
|
|
13
|
+
* first; in a leaf that holds one empty paragraph it proposes that paragraph's text. A paragraph
|
|
14
|
+
* takes one proposal that rewrites it and one that adds after it, and a later item of either kind
|
|
15
|
+
* naming it draws nothing.
|
|
16
|
+
*
|
|
17
|
+
* `before` is the blocks `replace` names as the proposal's writer read them, Markdown: the
|
|
18
|
+
* proposal is an edit of those, carried onto the blocks as they stand. Without it the proposal is
|
|
19
|
+
* an edit of the blocks as they stood when the leaf first drew it.
|
|
20
|
+
*/
|
|
21
|
+
export type TextReview = {
|
|
22
|
+
id: string;
|
|
23
|
+
replace: readonly string[];
|
|
24
|
+
before?: string;
|
|
25
|
+
after: string;
|
|
26
|
+
} | {
|
|
27
|
+
id: string;
|
|
28
|
+
insert: BlockPlace;
|
|
29
|
+
after: string;
|
|
30
|
+
};
|
|
31
|
+
/** Where a proposal adds blocks: after or before the block with the id, or at the leaf's end. */
|
|
32
|
+
export type BlockPlace = {
|
|
33
|
+
after: string;
|
|
34
|
+
} | {
|
|
35
|
+
before: string;
|
|
36
|
+
} | 'end';
|
|
37
|
+
/** What a reader did with a proposal: took it, which the leaf has written by the time it says
|
|
38
|
+
* so, turned it down, or undid an answer, so the item is open again with whatever was written
|
|
39
|
+
* for it taken back. */
|
|
40
|
+
export type ReviewAction = 'accept' | 'dismiss' | 'reopen';
|
|
41
|
+
/** What brought an item under attention: the pointer over it, or the caret in it. */
|
|
42
|
+
export type ReviewVia = 'pointer' | 'caret';
|
|
43
|
+
/** The words the leaf draws on a proposal's two buttons, and the names of what has no words. */
|
|
44
|
+
export interface ReviewStrings {
|
|
45
|
+
reviewAccept: string;
|
|
46
|
+
reviewDismiss: string;
|
|
47
|
+
/** The two buttons' tooltips, which name their chords (`REVIEW_KEYS`). */
|
|
48
|
+
reviewAcceptTitle: string;
|
|
49
|
+
reviewDismissTitle: string;
|
|
50
|
+
/** The accessible name of a proposal's two buttons as a group. */
|
|
51
|
+
reviewProposal: string;
|
|
52
|
+
/** The accessible name of the wedge standing where text was removed. */
|
|
53
|
+
reviewGone: string;
|
|
54
|
+
/** The label before the buttons of a proposal whose paragraph the reader rewrote since. */
|
|
55
|
+
reviewOutdated: string;
|
|
56
|
+
}
|
|
57
|
+
export declare const DEFAULT_REVIEW_STRINGS: ReviewStrings;
|
|
58
|
+
/** What the plugin reads and reports through; every reader is live. */
|
|
59
|
+
export interface ReviewChannel {
|
|
60
|
+
items(): readonly TextReview[];
|
|
61
|
+
/** The item under attention, drawn a step stronger. */
|
|
62
|
+
lit(): string | undefined;
|
|
63
|
+
strings(): ReviewStrings;
|
|
64
|
+
anchors(state: EditorState): readonly AnchorPos[];
|
|
65
|
+
/** Lay `anchors` again in the transaction that puts their text back. */
|
|
66
|
+
restore?(tr: Transaction, anchors: readonly AnchorPos[]): void;
|
|
67
|
+
/** `after` as a document under the leaf's schema; `undefined` where it does not parse. */
|
|
68
|
+
parse(markdown: string): PMNode | undefined;
|
|
69
|
+
/** The item whose card is up, and the way to lower it. */
|
|
70
|
+
shown(): string | undefined;
|
|
71
|
+
dismiss(): void;
|
|
72
|
+
/** A reader's answer, `chord` where a key gave it. */
|
|
73
|
+
act(id: string, action: ReviewAction, chord?: boolean): void;
|
|
74
|
+
/** The leaf is writing a taken proposal, and is done. */
|
|
75
|
+
writing?(on: boolean): void;
|
|
76
|
+
/** The item the pointer or the caret is in, `undefined` once it has left. */
|
|
77
|
+
point(id: string | undefined, via: ReviewVia): void;
|
|
78
|
+
/** What the leaf draws and what it holds and does not draw, on each change of either. */
|
|
79
|
+
drew(report: ReviewReport): void;
|
|
80
|
+
}
|
|
81
|
+
/** Why a listed item the leaf holds draws nothing: `after` is not Markdown the leaf's schema
|
|
82
|
+
* holds, an earlier item has the paragraph, the text already reads as proposed, or no block it
|
|
83
|
+
* names by id stands in the leaf. */
|
|
84
|
+
export type LeafUndrawn = 'parse' | 'taken' | 'applied' | 'block';
|
|
85
|
+
/** What a leaf draws of the items it was handed. */
|
|
86
|
+
export interface ReviewReport {
|
|
87
|
+
/** The ids drawn, in the order the items were listed. */
|
|
88
|
+
ids: readonly string[];
|
|
89
|
+
/** The drawn proposals the reader's own writing meets: words both changed, or a block one
|
|
90
|
+
* names gone or no longer the block it read. */
|
|
91
|
+
outdated: readonly string[];
|
|
92
|
+
/** The items the leaf holds and does not draw, each with why: by the blocks it names,
|
|
93
|
+
* which only the leaf holding its field is handed. */
|
|
94
|
+
undrawn: readonly {
|
|
95
|
+
id: string;
|
|
96
|
+
reason: LeafUndrawn;
|
|
97
|
+
}[];
|
|
98
|
+
/** The drawn proposals taken here and still listed, drawn as changes, each with the text
|
|
99
|
+
* that stood where it wrote. */
|
|
100
|
+
accepted: readonly {
|
|
101
|
+
id: string;
|
|
102
|
+
before: string;
|
|
103
|
+
}[];
|
|
104
|
+
}
|
|
105
|
+
/** Tell the review layer the store took blocks under new ids, each `[was, now]`. */
|
|
106
|
+
export declare function renameBlocks(tr: Transaction, renamed: readonly (readonly [string, string])[]): void;
|
|
107
|
+
/** The handle the leaf keeps on its review layer. */
|
|
108
|
+
export interface ReviewLayer {
|
|
109
|
+
plugin: Plugin;
|
|
110
|
+
/** Draw again from the channel: the items or the lit one moved. */
|
|
111
|
+
refresh(view: EditorView): void;
|
|
112
|
+
/** The elements item `id` draws, in document order. */
|
|
113
|
+
elements(view: EditorView, id: string): HTMLElement[];
|
|
114
|
+
/** Put the caret in item `id` and take the focus, so the item's chords answer. False for
|
|
115
|
+
* an item the leaf does not draw. */
|
|
116
|
+
enter(view: EditorView, id: string): boolean;
|
|
117
|
+
/** Answer item `id` as its button would, moving neither the caret nor the focus. False
|
|
118
|
+
* where the leaf does not draw it or cannot write it. */
|
|
119
|
+
answer(id: string, action: ReviewAction): boolean;
|
|
120
|
+
/** Open a dismissal of item `id` again and say so, the dismissal still held here or
|
|
121
|
+
* already pruned by the host taking the item off its list. */
|
|
122
|
+
reopen(view: EditorView, id: string): void;
|
|
123
|
+
/** Undo the leaf's newest history step: an accept's, which reopens its item. */
|
|
124
|
+
undo(view: EditorView): boolean;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* The leaf's review layer. The decorations are a function of the document, the anchors and the
|
|
128
|
+
* channel's items, kept until one of them moves. The caret's report holds off while the reader
|
|
129
|
+
* types inside an item: an item is news on arriving in it, and noise under every keystroke.
|
|
130
|
+
*/
|
|
131
|
+
export declare function reviewLayer(channel: ReviewChannel): ReviewLayer;
|