@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
|
@@ -15,6 +15,13 @@ declare const VisualEditorInner: import("svelte").Component<VisualEditorProps, {
|
|
|
15
15
|
applyExternal: (field: DocPath, delta?: Delta) => void;
|
|
16
16
|
refresh: () => void;
|
|
17
17
|
applyCardOps: (ops: readonly CardOp[]) => void;
|
|
18
|
+
revealReview: (id: string, opts?: {
|
|
19
|
+
focus?: boolean;
|
|
20
|
+
}) => Promise<boolean>;
|
|
21
|
+
answerReview: (ids: readonly string[] | "all", action: "accept" | "dismiss") => string[];
|
|
22
|
+
stepReview: (dir: 1 | -1, opts?: {
|
|
23
|
+
focus?: boolean;
|
|
24
|
+
}) => Promise<string | undefined>;
|
|
18
25
|
}, "">;
|
|
19
26
|
type VisualEditorInner = ReturnType<typeof VisualEditorInner>;
|
|
20
27
|
export default VisualEditorInner;
|
package/dist/visual/controls.css
CHANGED
|
@@ -180,12 +180,13 @@
|
|
|
180
180
|
}
|
|
181
181
|
:where(.qm-icon-btn:hover:not(:disabled)),
|
|
182
182
|
:where(.qm-add-affordance:hover:not(:disabled)),
|
|
183
|
-
:where(.qm-chip:hover:not(:disabled)) {
|
|
183
|
+
:where(.qm-chip:hover:not(:disabled, [aria-disabled='true'])) {
|
|
184
184
|
background: var(--_qm-surface-hover);
|
|
185
185
|
}
|
|
186
186
|
:where(.qm-icon-btn:disabled),
|
|
187
187
|
:where(.qm-add-affordance:disabled),
|
|
188
|
-
:where(.qm-chip:disabled)
|
|
188
|
+
:where(.qm-chip:disabled),
|
|
189
|
+
:where(.qm-chip[aria-disabled='true']) {
|
|
189
190
|
opacity: var(--_qm-opacity-idle);
|
|
190
191
|
cursor: default;
|
|
191
192
|
}
|
|
@@ -440,6 +441,20 @@
|
|
|
440
441
|
}
|
|
441
442
|
}
|
|
442
443
|
|
|
444
|
+
/* Heard and not drawn: a parked description, a status a screen reader follows. In the
|
|
445
|
+
accessibility tree, out of the layout, and never a focus stop. Clipped rather than
|
|
446
|
+
`display: none` / `hidden`, which take a node out of the tree entirely and would make
|
|
447
|
+
an `aria-describedby` dangle. Out of flow, so the classic recipe's `margin: -1px` has
|
|
448
|
+
nothing left to counteract: and it would mint a literal off every rung. */
|
|
449
|
+
:where(.qm-visually-hidden) {
|
|
450
|
+
position: absolute;
|
|
451
|
+
width: 1px;
|
|
452
|
+
height: 1px;
|
|
453
|
+
overflow: hidden;
|
|
454
|
+
clip-path: inset(50%);
|
|
455
|
+
white-space: nowrap;
|
|
456
|
+
}
|
|
457
|
+
|
|
443
458
|
/* Forced colours drop every fill and shadow, which is every edge a field and a chip
|
|
444
459
|
draw here, and keep opacity, which would leave a resting control a ghost against a
|
|
445
460
|
system palette. The system's own strokes stand in for both. */
|
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A description's markdown as DOM, by the path a tip takes (`renderTip`): the body's
|
|
3
|
+
* mark vocabulary under the inline schema, so any string is one paragraph and a
|
|
4
|
+
* description is spelled as its quill's bodies are. A link is drawn as its words: the
|
|
5
|
+
* surface is one a pointer cannot stay on and no reader lands in. A throw degrades to
|
|
6
|
+
* the literal text.
|
|
7
|
+
*/
|
|
8
|
+
export declare function renderGuidance(markdown: string): Node;
|
|
9
|
+
/** Whether a description stands in flow under its label, with no marker to raise. */
|
|
10
|
+
export declare const isBrief: (description: string) => boolean;
|
|
11
|
+
/** A description as the words alone, for the node that describes its control. */
|
|
12
|
+
export declare const guidanceText: (markdown: string) => string;
|
|
1
13
|
/** Root keydown: the key raises (or lowers) the nearest guidance. A trigger's `click()`
|
|
2
14
|
* is an activation with no pointer behind it, which `FieldHint` toggles on. */
|
|
3
15
|
export declare function raiseGuidance(e: KeyboardEvent): void;
|
package/dist/visual/guidance.js
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
|
-
//
|
|
2
|
-
// the
|
|
1
|
+
// A field's guidance: its schema `description`, as the DOM the label draws it from, and
|
|
2
|
+
// the key that raises it. `Mod-/` on a control raises the description that control
|
|
3
|
+
// carries, the keyboard's way in to a `FieldHint` whose glyph is out of the tab order.
|
|
4
|
+
import { core } from '../core/lifecycle.js';
|
|
5
|
+
import { renderContent, inlineSchema } from '../core/codec/index.js';
|
|
6
|
+
/**
|
|
7
|
+
* A description's markdown as DOM, by the path a tip takes (`renderTip`): the body's
|
|
8
|
+
* mark vocabulary under the inline schema, so any string is one paragraph and a
|
|
9
|
+
* description is spelled as its quill's bodies are. A link is drawn as its words: the
|
|
10
|
+
* surface is one a pointer cannot stay on and no reader lands in. A throw degrades to
|
|
11
|
+
* the literal text.
|
|
12
|
+
*/
|
|
13
|
+
export function renderGuidance(markdown) {
|
|
14
|
+
const { importMarkdown } = core();
|
|
15
|
+
try {
|
|
16
|
+
const dom = renderContent(importMarkdown(markdown).content, inlineSchema);
|
|
17
|
+
if (dom instanceof DocumentFragment || dom instanceof Element)
|
|
18
|
+
for (const a of dom.querySelectorAll('a'))
|
|
19
|
+
a.replaceWith(...a.childNodes);
|
|
20
|
+
return dom;
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return document.createTextNode(markdown);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/** The longest description that stands under its label: about a line at the label rung
|
|
27
|
+
* across a card, two in a half-width field. Past it the text goes behind the marker,
|
|
28
|
+
* in flow under every field being the density a card avoids (`FieldHint`). */
|
|
29
|
+
const BRIEF_MAX = 72;
|
|
30
|
+
/** Whether a description stands in flow under its label, with no marker to raise. */
|
|
31
|
+
export const isBrief = (description) => description.length <= BRIEF_MAX;
|
|
32
|
+
/** A description as the words alone, for the node that describes its control. */
|
|
33
|
+
export const guidanceText = (markdown) => renderGuidance(markdown).textContent ?? markdown;
|
|
3
34
|
/** `Mod-/`, read off `key` so a layout that shifts to reach `/` still matches; either
|
|
4
35
|
* modifier stands for `Mod`. */
|
|
5
36
|
function isGuidanceKey(e) {
|
|
@@ -19,6 +50,10 @@ function guidanceTrigger(from, root) {
|
|
|
19
50
|
const trigger = root.querySelector(`.qm-field-hint[aria-describedby="${id}"]`);
|
|
20
51
|
if (trigger)
|
|
21
52
|
return trigger;
|
|
53
|
+
// A description under its label is on screen already, and the key is not the
|
|
54
|
+
// container's to answer for it.
|
|
55
|
+
if (document.getElementById(id)?.matches('.qm-field-brief'))
|
|
56
|
+
return undefined;
|
|
22
57
|
}
|
|
23
58
|
el = el.parentElement?.closest('[aria-describedby]') ?? null;
|
|
24
59
|
}
|
|
@@ -15,6 +15,16 @@ export declare const ICONS: {
|
|
|
15
15
|
readonly 'chevron-up': readonly [readonly ["path", {
|
|
16
16
|
readonly d: "m18 15-6-6-6 6";
|
|
17
17
|
}]];
|
|
18
|
+
readonly 'arrow-up': readonly [readonly ["path", {
|
|
19
|
+
readonly d: "m5 12 7-7 7 7";
|
|
20
|
+
}], readonly ["path", {
|
|
21
|
+
readonly d: "M12 19V5";
|
|
22
|
+
}]];
|
|
23
|
+
readonly 'arrow-down': readonly [readonly ["path", {
|
|
24
|
+
readonly d: "M12 5v14";
|
|
25
|
+
}], readonly ["path", {
|
|
26
|
+
readonly d: "m19 12-7 7-7-7";
|
|
27
|
+
}]];
|
|
18
28
|
readonly 'grip-vertical': readonly [readonly ["circle", {
|
|
19
29
|
readonly cx: "9";
|
|
20
30
|
readonly cy: "12";
|
|
@@ -138,8 +148,10 @@ export declare const ICONS: {
|
|
|
138
148
|
}], readonly ["path", {
|
|
139
149
|
readonly d: "M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2";
|
|
140
150
|
}]];
|
|
141
|
-
readonly
|
|
142
|
-
readonly d: "
|
|
151
|
+
readonly x: readonly [readonly ["path", {
|
|
152
|
+
readonly d: "M18 6 6 18";
|
|
153
|
+
}], readonly ["path", {
|
|
154
|
+
readonly d: "m6 6 12 12";
|
|
143
155
|
}]];
|
|
144
156
|
readonly check: readonly [readonly ["path", {
|
|
145
157
|
readonly d: "M20 6 9 17l-5-5";
|
|
@@ -14,6 +14,14 @@ export const ICONS = {
|
|
|
14
14
|
],
|
|
15
15
|
'chevron-down': [['path', { d: 'm6 9 6 6 6-6' }]],
|
|
16
16
|
'chevron-up': [['path', { d: 'm18 15-6-6-6 6' }]],
|
|
17
|
+
'arrow-up': [
|
|
18
|
+
['path', { d: 'm5 12 7-7 7 7' }],
|
|
19
|
+
['path', { d: 'M12 19V5' }]
|
|
20
|
+
],
|
|
21
|
+
'arrow-down': [
|
|
22
|
+
['path', { d: 'M12 5v14' }],
|
|
23
|
+
['path', { d: 'm19 12-7 7-7-7' }]
|
|
24
|
+
],
|
|
17
25
|
'grip-vertical': [
|
|
18
26
|
['circle', { cx: '9', cy: '12', r: '1' }],
|
|
19
27
|
['circle', { cx: '9', cy: '5', r: '1' }],
|
|
@@ -77,7 +85,10 @@ export const ICONS = {
|
|
|
77
85
|
['path', { d: 'M3 6h18' }],
|
|
78
86
|
['path', { d: 'M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2' }]
|
|
79
87
|
],
|
|
80
|
-
|
|
88
|
+
x: [
|
|
89
|
+
['path', { d: 'M18 6 6 18' }],
|
|
90
|
+
['path', { d: 'm6 6 12 12' }]
|
|
91
|
+
],
|
|
81
92
|
check: [['path', { d: 'M20 6 9 17l-5-5' }]],
|
|
82
93
|
calendar: [
|
|
83
94
|
['path', { d: 'M8 2v3' }],
|
package/dist/visual/index.d.ts
CHANGED
|
@@ -7,5 +7,11 @@ export type { VisualStrings, VisualStringsInput, FormatDiagnostic } from './stri
|
|
|
7
7
|
export type { BodyPlaceholder, BodyPlaceholderContext } from './structure.js';
|
|
8
8
|
export { editorShortcuts } from '../core/codec/index.js';
|
|
9
9
|
export type { EditorShortcut, ShortcutScope } from '../core/codec/index.js';
|
|
10
|
+
export type { BlockProposal, ReviewDrawn, ReviewEvent, ReviewItem, ReviewUndrawn } from './review.js';
|
|
11
|
+
export type { BlockPlace } from '../core/codec/index.js';
|
|
12
|
+
export { proposalsBetween } from './proposals.js';
|
|
13
|
+
export type { CardProposal, Proposed } from './proposals.js';
|
|
14
|
+
export type { ReviewAction } from '../core/codec/index.js';
|
|
15
|
+
export { REVIEW_KEYS } from '../core/codec/index.js';
|
|
10
16
|
export { patchEditorExt } from './ext.js';
|
|
11
17
|
export type { ActiveLeaf, CardId, CardOp, ChangeSource, EditorChange } from './signals.js';
|
package/dist/visual/index.js
CHANGED
|
@@ -25,6 +25,8 @@ export { DEFAULT_VISUAL_STRINGS } from './strings.js';
|
|
|
25
25
|
// The prose leaf's shortcuts, for a host's shortcut list: read off the keymaps' own tables and
|
|
26
26
|
// worded by the same `strings` (pass the editor's, or none for the package's English).
|
|
27
27
|
export { editorShortcuts } from '../core/codec/index.js';
|
|
28
|
+
export { proposalsBetween } from './proposals.js';
|
|
29
|
+
export { REVIEW_KEYS } from '../core/codec/index.js';
|
|
28
30
|
// The `$ext.editor` write unit. A consumer seeding editor-side chrome
|
|
29
31
|
// state (a card title, the tips channel) goes through this rather than `storeExt`,
|
|
30
32
|
// which replaces the whole map and takes every sibling with it.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** Where the focus was in the list: the row holding it, and a prose row's caret. */
|
|
2
|
+
export interface ListFocus {
|
|
3
|
+
id: string;
|
|
4
|
+
caret?: number;
|
|
5
|
+
}
|
|
6
|
+
/** The rows at one end of a step: their ids, their values and the focus among them. */
|
|
7
|
+
export interface ListRows {
|
|
8
|
+
ids: string[];
|
|
9
|
+
values: unknown[];
|
|
10
|
+
focus?: ListFocus;
|
|
11
|
+
}
|
|
12
|
+
/** One change to the rows, from `before` to `after`. */
|
|
13
|
+
export interface ListStep {
|
|
14
|
+
before: ListRows;
|
|
15
|
+
after: ListRows;
|
|
16
|
+
}
|
|
17
|
+
export interface ListHistory {
|
|
18
|
+
/** Record a step, dropping every step undone before it. */
|
|
19
|
+
record(step: ListStep): void;
|
|
20
|
+
/** The latest step that can be undone. */
|
|
21
|
+
latest(): ListStep | undefined;
|
|
22
|
+
/** Take the latest step back (`redo` false) or forward again, where `values` still stand
|
|
23
|
+
* where it would start from. The rows it leaves, or `undefined` where nothing moved. */
|
|
24
|
+
take(redo: boolean, values: unknown[]): ListRows | undefined;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* A list's history. `same` says whether two value lists are one: a record's blank cells read
|
|
28
|
+
* as absent to it, since a cell typed in and undone back to empty commits its empty answer
|
|
29
|
+
* where the step's row had no key.
|
|
30
|
+
*/
|
|
31
|
+
export declare function listHistory(same: (a: unknown[], b: unknown[]) => boolean): ListHistory;
|
|
32
|
+
/** Whether two value lists are one, compared by JSON after `norm` reads each element. */
|
|
33
|
+
export declare function sameValues(a: unknown[], b: unknown[], norm?: (value: unknown) => unknown): boolean;
|
|
34
|
+
/** The chord a keydown is, of the two a list answers: ⌘/Ctrl+Z, and ⌘/Ctrl+Shift+Z or
|
|
35
|
+
* Ctrl+Y. */
|
|
36
|
+
export declare function undoChord(e: KeyboardEvent): 'undo' | 'redo' | undefined;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// A list's own undo (`ArrayField`). A change to the rows (an insert, a remove, a split, a
|
|
2
|
+
// join, a spill, a move) lives in no leaf's history, so the list keeps its steps itself. A
|
|
3
|
+
// step is taken back only while the rows stand as the step left them: an edit in a row since
|
|
4
|
+
// is the row's to undo first, and once its own undo brings the rows back, the step is next.
|
|
5
|
+
/** How many steps a list keeps each way. */
|
|
6
|
+
const DEPTH = 100;
|
|
7
|
+
/**
|
|
8
|
+
* A list's history. `same` says whether two value lists are one: a record's blank cells read
|
|
9
|
+
* as absent to it, since a cell typed in and undone back to empty commits its empty answer
|
|
10
|
+
* where the step's row had no key.
|
|
11
|
+
*/
|
|
12
|
+
export function listHistory(same) {
|
|
13
|
+
let done = [];
|
|
14
|
+
let undone = [];
|
|
15
|
+
return {
|
|
16
|
+
record(step) {
|
|
17
|
+
done = [...done.slice(1 - DEPTH), step];
|
|
18
|
+
undone = [];
|
|
19
|
+
},
|
|
20
|
+
latest: () => done.at(-1),
|
|
21
|
+
take(redo, values) {
|
|
22
|
+
const step = (redo ? undone : done).at(-1);
|
|
23
|
+
if (!step)
|
|
24
|
+
return undefined;
|
|
25
|
+
const [from, to] = redo ? [step.before, step.after] : [step.after, step.before];
|
|
26
|
+
if (!same(values, from.values))
|
|
27
|
+
return undefined;
|
|
28
|
+
if (redo) {
|
|
29
|
+
undone = undone.slice(0, -1);
|
|
30
|
+
done = [...done, step];
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
done = done.slice(0, -1);
|
|
34
|
+
undone = [...undone, step];
|
|
35
|
+
}
|
|
36
|
+
return to;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/** Whether two value lists are one, compared by JSON after `norm` reads each element. */
|
|
41
|
+
export function sameValues(a, b, norm = (value) => value) {
|
|
42
|
+
return a === b || JSON.stringify(a.map(norm)) === JSON.stringify(b.map(norm));
|
|
43
|
+
}
|
|
44
|
+
/** The chord a keydown is, of the two a list answers: ⌘/Ctrl+Z, and ⌘/Ctrl+Shift+Z or
|
|
45
|
+
* Ctrl+Y. */
|
|
46
|
+
export function undoChord(e) {
|
|
47
|
+
if (e.defaultPrevented || e.isComposing || e.altKey || !(e.metaKey || e.ctrlKey))
|
|
48
|
+
return;
|
|
49
|
+
const key = e.key.toLowerCase();
|
|
50
|
+
if ((key === 'z' && e.shiftKey) || (key === 'y' && !e.shiftKey && e.ctrlKey))
|
|
51
|
+
return 'redo';
|
|
52
|
+
return key === 'z' && !e.shiftKey ? 'undo' : undefined;
|
|
53
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Card, Document, Quill } from '@quillmark/wasm';
|
|
2
|
+
import { type ReviewItem } from './review.js';
|
|
3
|
+
/** A card the answer adds or takes out, which no item draws: a row the host answers itself. */
|
|
4
|
+
export type CardProposal =
|
|
5
|
+
/** `card` as the answer holds it. `after` is the id of the card it follows in the answer,
|
|
6
|
+
* absent at the head; it can be a card added before it, so a host adds them in list order. */
|
|
7
|
+
{
|
|
8
|
+
type: 'add';
|
|
9
|
+
card: Card;
|
|
10
|
+
after?: string;
|
|
11
|
+
}
|
|
12
|
+
/** The base's card `id`, of `kind`. */
|
|
13
|
+
| {
|
|
14
|
+
type: 'remove';
|
|
15
|
+
id: string;
|
|
16
|
+
kind: string;
|
|
17
|
+
};
|
|
18
|
+
/** The review an answer makes: the items the editor draws, and the cards it adds or removes. */
|
|
19
|
+
export interface Proposed {
|
|
20
|
+
items: ReviewItem[];
|
|
21
|
+
cards: CardProposal[];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The review list from `base`, the document as the answer's writer read it, to `answer`, the
|
|
25
|
+
* document as the writer left it: a copy of `base` the writer edited, so the two share card and
|
|
26
|
+
* block ids. Each item carries `before`, what the writer read, so the editor keeps what the
|
|
27
|
+
* reader has written since and reports a place both changed as outdated.
|
|
28
|
+
*
|
|
29
|
+
* Cards pair by id. Each paired card's body and block rich text fields take one `replace` item
|
|
30
|
+
* per block the answer rewrote or took out, and one `insert` item per run of blocks it added.
|
|
31
|
+
* Every other field takes an item per place that changed: a record's cell, and a list's member,
|
|
32
|
+
* changed, taken out, or appended past the end, two appends to one list at successive indices.
|
|
33
|
+
* A one-line rich text field, a list that gains members anywhere but its end, a value of a type
|
|
34
|
+
* nothing nests in, and a rich text value inside a record or a list are proposed whole. Values
|
|
35
|
+
* are in the form the editor's controls are handed, a text cell as its `Content`.
|
|
36
|
+
*
|
|
37
|
+
* Paths are `base`'s. A card the answer retypes is listed as taken out and added; one it moves
|
|
38
|
+
* is not listed. `mint` names each item, and by default names it uniquely for the page.
|
|
39
|
+
*/
|
|
40
|
+
export declare function proposalsBetween(quill: Quill, base: Document, answer: Document, mint?: () => string): Proposed;
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { fieldPathForAddr } from '../core/address.js';
|
|
2
|
+
import { sameValue } from './review.js';
|
|
3
|
+
import { baseType, fieldValues, oneLine } from './structure.js';
|
|
4
|
+
let minted = 0;
|
|
5
|
+
/**
|
|
6
|
+
* The review list from `base`, the document as the answer's writer read it, to `answer`, the
|
|
7
|
+
* document as the writer left it: a copy of `base` the writer edited, so the two share card and
|
|
8
|
+
* block ids. Each item carries `before`, what the writer read, so the editor keeps what the
|
|
9
|
+
* reader has written since and reports a place both changed as outdated.
|
|
10
|
+
*
|
|
11
|
+
* Cards pair by id. Each paired card's body and block rich text fields take one `replace` item
|
|
12
|
+
* per block the answer rewrote or took out, and one `insert` item per run of blocks it added.
|
|
13
|
+
* Every other field takes an item per place that changed: a record's cell, and a list's member,
|
|
14
|
+
* changed, taken out, or appended past the end, two appends to one list at successive indices.
|
|
15
|
+
* A one-line rich text field, a list that gains members anywhere but its end, a value of a type
|
|
16
|
+
* nothing nests in, and a rich text value inside a record or a list are proposed whole. Values
|
|
17
|
+
* are in the form the editor's controls are handed, a text cell as its `Content`.
|
|
18
|
+
*
|
|
19
|
+
* Paths are `base`'s. A card the answer retypes is listed as taken out and added; one it moves
|
|
20
|
+
* is not listed. `mint` names each item, and by default names it uniquely for the page.
|
|
21
|
+
*/
|
|
22
|
+
export function proposalsBetween(quill, base, answer, mint = () => `review-${minted++}`) {
|
|
23
|
+
const items = [];
|
|
24
|
+
const cards = [];
|
|
25
|
+
const kinds = Array.from({ length: base.cardCount }, (_, i) => base.card(i).kind);
|
|
26
|
+
const baseIds = Array.from({ length: base.cardCount }, (_, i) => base.card(i).id ?? '');
|
|
27
|
+
const answerIds = Array.from({ length: answer.cardCount }, (_, i) => answer.card(i).id ?? '');
|
|
28
|
+
const pathOf = (at, field, steps = []) => fieldPathForAddr(addrOf(at, field), kinds, steps);
|
|
29
|
+
const diffCard = (schema, at, was, now, answerAt) => {
|
|
30
|
+
const before = fieldValues(was.payloadItems);
|
|
31
|
+
const after = fieldValues(now.payloadItems);
|
|
32
|
+
const fields = schema?.fields ?? {};
|
|
33
|
+
for (const name of keysOf(fields, before, after)) {
|
|
34
|
+
const f = fields[name];
|
|
35
|
+
if (f && baseType(f) === 'richtext' && !oneLine(f)) {
|
|
36
|
+
blocks(pathOf(at, name), base, addrOf(at, name), answer, addrOf(answerAt, name));
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
value((steps) => pathOf(at, name, steps), f, [], before[name] ?? undefined, after[name] ?? undefined);
|
|
40
|
+
}
|
|
41
|
+
if (schema?.body?.enabled !== false)
|
|
42
|
+
blocks(pathOf(at, undefined), base, addrOf(at), answer, addrOf(answerAt));
|
|
43
|
+
};
|
|
44
|
+
const blocks = (field, from, fromAddr, to, toAddr) => {
|
|
45
|
+
const was = blocksOf(from, fromAddr);
|
|
46
|
+
const now = blocksOf(to, toAddr);
|
|
47
|
+
const nowById = new Map(now.map((b) => [b.id, b]));
|
|
48
|
+
for (const b of was) {
|
|
49
|
+
const next = nowById.get(b.id);
|
|
50
|
+
if (next?.markdown === b.markdown)
|
|
51
|
+
continue;
|
|
52
|
+
items.push({
|
|
53
|
+
id: mint(),
|
|
54
|
+
field,
|
|
55
|
+
replace: [b.id],
|
|
56
|
+
before: b.markdown,
|
|
57
|
+
after: next?.markdown ?? ''
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
const kept = new Set(was.map((b) => b.id));
|
|
61
|
+
let lead;
|
|
62
|
+
let run = [];
|
|
63
|
+
const flush = (next) => {
|
|
64
|
+
if (!run.length)
|
|
65
|
+
return;
|
|
66
|
+
items.push({
|
|
67
|
+
id: mint(),
|
|
68
|
+
field,
|
|
69
|
+
insert: lead ? { after: lead } : next ? { before: next } : 'end',
|
|
70
|
+
after: run.map((b) => b.markdown).join('\n\n')
|
|
71
|
+
});
|
|
72
|
+
run = [];
|
|
73
|
+
};
|
|
74
|
+
for (const b of now) {
|
|
75
|
+
if (!kept.has(b.id)) {
|
|
76
|
+
run.push(b);
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
flush(b.id);
|
|
80
|
+
lead = b.id;
|
|
81
|
+
}
|
|
82
|
+
flush(undefined);
|
|
83
|
+
};
|
|
84
|
+
const value = (pathAt, f, steps, was, now) => {
|
|
85
|
+
if (sameValue(was, now))
|
|
86
|
+
return;
|
|
87
|
+
const whole = () => void items.push({
|
|
88
|
+
id: mint(),
|
|
89
|
+
field: pathAt(steps),
|
|
90
|
+
...(was !== undefined && { before: was }),
|
|
91
|
+
...(now !== undefined && { after: now })
|
|
92
|
+
});
|
|
93
|
+
const kind = f && baseType(f);
|
|
94
|
+
if (kind === 'object' && f?.properties && isRecord(was) && isRecord(now)) {
|
|
95
|
+
for (const key of keysOf(f.properties, was, now))
|
|
96
|
+
value(pathAt, f.properties[key], [...steps, key], was[key], now[key]);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (kind !== 'array' || !Array.isArray(was) || !Array.isArray(now))
|
|
100
|
+
return whole();
|
|
101
|
+
const runs = aligned(was, now);
|
|
102
|
+
if (!runs)
|
|
103
|
+
return whole();
|
|
104
|
+
let appended = was.length;
|
|
105
|
+
for (const { from, to, removed, added } of runs) {
|
|
106
|
+
const paired = Math.min(removed, added);
|
|
107
|
+
for (let k = 0; k < paired; k++)
|
|
108
|
+
value(pathAt, f?.items, [...steps, from + k], was[from + k], now[to + k]);
|
|
109
|
+
for (let k = paired; k < removed; k++)
|
|
110
|
+
items.push({
|
|
111
|
+
id: mint(),
|
|
112
|
+
field: pathAt([...steps, from + k]),
|
|
113
|
+
before: was[from + k]
|
|
114
|
+
});
|
|
115
|
+
for (let k = paired; k < added; k++)
|
|
116
|
+
items.push({
|
|
117
|
+
id: mint(),
|
|
118
|
+
field: pathAt([...steps, appended++]),
|
|
119
|
+
after: now[to + k]
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
diffCard(quill.schema.main, undefined, base.main, answer.main, undefined);
|
|
124
|
+
for (const [at, id] of baseIds.entries()) {
|
|
125
|
+
const answerAt = answerIds.indexOf(id);
|
|
126
|
+
const was = base.card(at);
|
|
127
|
+
if (answerAt < 0) {
|
|
128
|
+
cards.push({ type: 'remove', id, kind: was.kind });
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
const now = answer.card(answerAt);
|
|
132
|
+
if (now.kind !== was.kind) {
|
|
133
|
+
cards.push({ type: 'remove', id, kind: was.kind });
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
diffCard(quill.schema.card_kinds?.[was.kind], at, was, now, answerAt);
|
|
137
|
+
}
|
|
138
|
+
for (const [at, id] of answerIds.entries()) {
|
|
139
|
+
const at0 = baseIds.indexOf(id);
|
|
140
|
+
if (at0 >= 0 && base.card(at0).kind === answer.card(at).kind)
|
|
141
|
+
continue;
|
|
142
|
+
cards.push({
|
|
143
|
+
type: 'add',
|
|
144
|
+
card: answer.card(at),
|
|
145
|
+
...(at > 0 && { after: answerIds[at - 1] })
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
return { items, cards };
|
|
149
|
+
}
|
|
150
|
+
const addrOf = (card, field) => ({
|
|
151
|
+
...(card !== undefined && { card }),
|
|
152
|
+
...(field !== undefined && { field })
|
|
153
|
+
});
|
|
154
|
+
/** The blocks of the value at `addr`, none where it holds none. */
|
|
155
|
+
function blocksOf(doc, addr) {
|
|
156
|
+
try {
|
|
157
|
+
return doc.blocks(addr);
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
return [];
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
const isRecord = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
164
|
+
/** The keys a schema declares, then any either value holds beyond them. */
|
|
165
|
+
function keysOf(declared, ...values) {
|
|
166
|
+
const keys = new Set(Object.keys(declared));
|
|
167
|
+
for (const v of values)
|
|
168
|
+
if (isRecord(v))
|
|
169
|
+
for (const key of Object.keys(v))
|
|
170
|
+
keys.add(key);
|
|
171
|
+
return [...keys];
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* The runs where two lists differ, members matched by value along their longest common run:
|
|
175
|
+
* at each, `removed` members of `was` from `from` and `added` members of `now` from `to`. A run
|
|
176
|
+
* pairs its members as changes, and takes out or appends the rest. `undefined` where a run adds
|
|
177
|
+
* more members than it takes out anywhere but the end, which no index names.
|
|
178
|
+
*/
|
|
179
|
+
function aligned(was, now) {
|
|
180
|
+
const m = was.length;
|
|
181
|
+
const n = now.length;
|
|
182
|
+
const lcs = Array.from({ length: m + 1 }, () => new Array(n + 1).fill(0));
|
|
183
|
+
for (let i = m - 1; i >= 0; i--)
|
|
184
|
+
for (let j = n - 1; j >= 0; j--)
|
|
185
|
+
lcs[i][j] = sameValue(was[i], now[j])
|
|
186
|
+
? lcs[i + 1][j + 1] + 1
|
|
187
|
+
: Math.max(lcs[i + 1][j], lcs[i][j + 1]);
|
|
188
|
+
const runs = [];
|
|
189
|
+
let i = 0;
|
|
190
|
+
let j = 0;
|
|
191
|
+
let from = 0;
|
|
192
|
+
let to = 0;
|
|
193
|
+
const close = () => {
|
|
194
|
+
const removed = i - from;
|
|
195
|
+
const added = j - to;
|
|
196
|
+
if (added > removed && i < m)
|
|
197
|
+
return false;
|
|
198
|
+
if (removed || added)
|
|
199
|
+
runs.push({ from, to, removed, added });
|
|
200
|
+
return true;
|
|
201
|
+
};
|
|
202
|
+
while (i < m && j < n) {
|
|
203
|
+
if (sameValue(was[i], now[j])) {
|
|
204
|
+
if (!close())
|
|
205
|
+
return undefined;
|
|
206
|
+
i++;
|
|
207
|
+
j++;
|
|
208
|
+
from = i;
|
|
209
|
+
to = j;
|
|
210
|
+
}
|
|
211
|
+
else if (lcs[i + 1][j] >= lcs[i][j + 1])
|
|
212
|
+
i++;
|
|
213
|
+
else
|
|
214
|
+
j++;
|
|
215
|
+
}
|
|
216
|
+
i = m;
|
|
217
|
+
j = n;
|
|
218
|
+
return close() ? runs : undefined;
|
|
219
|
+
}
|
package/dist/visual/props.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { Place } from '../core/address.js';
|
|
|
3
3
|
import type { EditorErrorHandler } from '../core/errors.js';
|
|
4
4
|
import type { ActiveLeaf, EditorChange } from './signals.js';
|
|
5
5
|
import type { FormatDiagnostic, VisualStringsInput } from './strings.js';
|
|
6
|
+
import type { ReviewDrawn, ReviewEvent, ReviewItem } from './review.js';
|
|
6
7
|
export interface VisualEditorProps {
|
|
7
8
|
doc: Document;
|
|
8
9
|
/**
|
|
@@ -107,6 +108,41 @@ export interface VisualEditorProps {
|
|
|
107
108
|
* render lanes need: their parameters exist only inside that English string.
|
|
108
109
|
*/
|
|
109
110
|
formatDiagnostic?: FormatDiagnostic;
|
|
111
|
+
/**
|
|
112
|
+
* What someone other than the reader proposes, for the editor to draw where each item sits
|
|
113
|
+
* ({@link ReviewItem}): a proposal as a word-level edit of its own blocks with Accept and
|
|
114
|
+
* Dismiss at its end, and a field's proposed value under its control. Declarative: the host
|
|
115
|
+
* sets the list once and clears it once, and the editor draws every answer while the list
|
|
116
|
+
* holds the item: an answered item is drawn no more, and an accepted one is plain text. A
|
|
117
|
+
* card an item names by index is read against the cards as they stood when the list was
|
|
118
|
+
* set, so the item stays on its card through `applyCardOps` and the reader's own card
|
|
119
|
+
* edits; an item whose card is gone draws nothing.
|
|
120
|
+
*/
|
|
121
|
+
review?: readonly ReviewItem[];
|
|
122
|
+
/**
|
|
123
|
+
* A reader answered an item: a button on it, `Mod-Enter` / `Mod-.` with the caret or the
|
|
124
|
+
* focus in it, or a host's `answerReview`; or undid an answer with ⌘Z, `reopen`. The editor has made every write an answer asks for and draws it,
|
|
125
|
+
* so the host leaves `review` as it set it.
|
|
126
|
+
*/
|
|
127
|
+
onReview?: (event: ReviewEvent) => void;
|
|
128
|
+
/**
|
|
129
|
+
* What the editor draws of `review`, on each change once the leaves have drawn: the open
|
|
130
|
+
* items in document order, the proposals the reader has written past since, and every
|
|
131
|
+
* listed item it does not draw with why. What a
|
|
132
|
+
* host counts and steps its own list by.
|
|
133
|
+
*/
|
|
134
|
+
onReviewDrawn?: (drawn: ReviewDrawn) => void;
|
|
135
|
+
/**
|
|
136
|
+
* Whether an answer given by a chord goes on to the next item, the caret in it, so a held
|
|
137
|
+
* walk down a batch answers each in turn. An answer by pointer stays where it was given.
|
|
138
|
+
* Default `true`.
|
|
139
|
+
*/
|
|
140
|
+
reviewAdvance?: boolean;
|
|
141
|
+
/**
|
|
142
|
+
* The item under attention, `undefined` once nothing is: the pointer over one, the caret
|
|
143
|
+
* in one, or one a `revealReview` named. What a host lights its own list by.
|
|
144
|
+
*/
|
|
145
|
+
onReviewFocus?: (id: string | undefined) => void;
|
|
110
146
|
/** Appended to the root's own class: the surface is a mounted element the
|
|
111
147
|
* consumer positions, so it needs a handle for layout it owns. */
|
|
112
148
|
class?: string;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** A removed card and the place it left. */
|
|
2
|
+
export interface RemovedCard<Card> {
|
|
3
|
+
readonly id: string;
|
|
4
|
+
readonly card: Card;
|
|
5
|
+
above: string | undefined;
|
|
6
|
+
below: string | undefined;
|
|
7
|
+
/** The index it left, for a card both of whose neighbours are gone. */
|
|
8
|
+
readonly at: number;
|
|
9
|
+
}
|
|
10
|
+
export interface RemovedCards<Card> {
|
|
11
|
+
/** A card just removed from `at` in `ids`, the stack as it stood. */
|
|
12
|
+
remove(id: string, card: Card, ids: readonly string[], at: number): RemovedCard<Card>;
|
|
13
|
+
/** Where `gone` goes back in the stack `ids`: under the card it stood below, else over
|
|
14
|
+
* the one it stood above, else the index it left, held to the stack's length. */
|
|
15
|
+
place(gone: RemovedCard<Card>, ids: readonly string[]): number;
|
|
16
|
+
/** `gone` went back under the session key `id`: a removal that named it as its
|
|
17
|
+
* neighbour names the restored card. */
|
|
18
|
+
restored(gone: RemovedCard<Card>, id: string): void;
|
|
19
|
+
}
|
|
20
|
+
export declare function removedCards<Card>(): RemovedCards<Card>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// The cards removed this session and not yet restored, each named by the place it left
|
|
2
|
+
// (INVARIANTS §"Card operations"): the cards either side of it, since an index names
|
|
3
|
+
// whatever stands there after the next insert, move or removal, and a session key names
|
|
4
|
+
// one card for the surface's life.
|
|
5
|
+
export function removedCards() {
|
|
6
|
+
const held = [];
|
|
7
|
+
return {
|
|
8
|
+
remove(id, card, ids, at) {
|
|
9
|
+
const gone = { id, card, above: ids[at - 1], below: ids[at + 1], at };
|
|
10
|
+
held.push(gone);
|
|
11
|
+
return gone;
|
|
12
|
+
},
|
|
13
|
+
place(gone, ids) {
|
|
14
|
+
const above = gone.above === undefined ? -1 : ids.indexOf(gone.above);
|
|
15
|
+
if (above >= 0)
|
|
16
|
+
return above + 1;
|
|
17
|
+
const below = gone.below === undefined ? -1 : ids.indexOf(gone.below);
|
|
18
|
+
return below >= 0 ? below : Math.min(gone.at, ids.length);
|
|
19
|
+
},
|
|
20
|
+
restored(gone, id) {
|
|
21
|
+
held.splice(held.indexOf(gone), 1);
|
|
22
|
+
for (const other of held) {
|
|
23
|
+
if (other.above === gone.id)
|
|
24
|
+
other.above = id;
|
|
25
|
+
if (other.below === gone.id)
|
|
26
|
+
other.below = id;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|