@quillmark/svelte 0.35.0 → 0.36.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.
Files changed (60) hide show
  1. package/README.md +21 -13
  2. package/dist/core/address.d.ts +5 -0
  3. package/dist/core/address.js +14 -0
  4. package/dist/core/codec/field.d.ts +30 -7
  5. package/dist/core/codec/field.js +67 -4
  6. package/dist/core/codec/index.d.ts +6 -3
  7. package/dist/core/codec/index.js +2 -3
  8. package/dist/core/codec/prose.css +11 -77
  9. package/dist/core/codec/review.d.ts +27 -21
  10. package/dist/core/codec/review.js +87 -148
  11. package/dist/core/codec/shortcuts.d.ts +3 -3
  12. package/dist/core/codec/shortcuts.js +7 -7
  13. package/dist/core/codec/value-diff.d.ts +21 -0
  14. package/dist/core/codec/value-diff.js +83 -0
  15. package/dist/core/codec/value-plan.d.ts +29 -0
  16. package/dist/core/codec/value-plan.js +157 -0
  17. package/dist/core/theme.css +7 -2
  18. package/dist/visual/ArrayField.svelte +191 -17
  19. package/dist/visual/Card.svelte +12 -1
  20. package/dist/visual/Card.svelte.d.ts +3 -0
  21. package/dist/visual/EnumField.svelte +14 -4
  22. package/dist/visual/EnumField.svelte.d.ts +3 -0
  23. package/dist/visual/Field.svelte +56 -47
  24. package/dist/visual/FieldHint.svelte +9 -15
  25. package/dist/visual/FormatPopover.svelte +1 -0
  26. package/dist/visual/MatrixField.svelte +43 -5
  27. package/dist/visual/MatrixField.svelte.d.ts +5 -0
  28. package/dist/visual/NumberField.svelte +112 -3
  29. package/dist/visual/NumberField.svelte.d.ts +5 -0
  30. package/dist/visual/ObjectField.svelte +54 -16
  31. package/dist/visual/ProseField.svelte +16 -3
  32. package/dist/visual/ProseField.svelte.d.ts +3 -0
  33. package/dist/visual/ProseValue.svelte +38 -2
  34. package/dist/visual/ProseValue.svelte.d.ts +3 -0
  35. package/dist/visual/ReviewCard.svelte +347 -0
  36. package/dist/visual/ReviewCard.svelte.d.ts +19 -0
  37. package/dist/visual/ReviewProposal.svelte +104 -131
  38. package/dist/visual/ReviewProposal.svelte.d.ts +3 -6
  39. package/dist/visual/ReviewRows.svelte +6 -25
  40. package/dist/visual/ReviewRows.svelte.d.ts +1 -3
  41. package/dist/visual/SlashMenu.svelte +1 -0
  42. package/dist/visual/VariantField.svelte +44 -4
  43. package/dist/visual/VariantField.svelte.d.ts +5 -0
  44. package/dist/visual/VisualEditor.svelte +16 -7
  45. package/dist/visual/VisualEditor.svelte.d.ts +3 -0
  46. package/dist/visual/VisualEditorInner.svelte +840 -115
  47. package/dist/visual/VisualEditorInner.svelte.d.ts +3 -0
  48. package/dist/visual/index.d.ts +2 -2
  49. package/dist/visual/proposals.d.ts +13 -22
  50. package/dist/visual/proposals.js +69 -32
  51. package/dist/visual/props.d.ts +18 -18
  52. package/dist/visual/review.d.ts +68 -3
  53. package/dist/visual/review.js +36 -1
  54. package/dist/visual/review.svelte.d.ts +55 -15
  55. package/dist/visual/review.svelte.js +156 -42
  56. package/dist/visual/strings.d.ts +23 -6
  57. package/dist/visual/strings.js +10 -5
  58. package/dist/visual/undo.svelte.d.ts +3 -1
  59. package/dist/visual/undo.svelte.js +7 -3
  60. package/package.json +1 -1
package/README.md CHANGED
@@ -161,12 +161,13 @@ Hand it a different `doc` and the editor **re-keys itself**: every leaf remounts
161
161
  /* heard for each answer; the editor draws it, and the list stays as it was set */
162
162
  }}
163
163
  onReviewFocus={(id) => {
164
- /* the item under the reader's attention, or undefined */
164
+ /* the current item, which the answer card and the review keys answer, or undefined */
165
165
  }}
166
+ reviewInset={barHeight}
166
167
  />
167
168
  ```
168
169
 
169
- An item names its place by the **blocks** of a rich text field or a body, by the ids `doc.blocks(addr)` reads, or by a **field**'s path:
170
+ An item names its place by the **blocks** of a rich text field or a body, by the ids `doc.blocks(addr)` reads, by a **field**'s path, or by a **card** it adds or takes out:
170
171
 
171
172
  ```ts
172
173
  type ReviewItem =
@@ -183,19 +184,22 @@ type ReviewItem =
183
184
  insert: { after: string } | { before: string } | 'end';
184
185
  after: string;
185
186
  }
186
- | { id: string; field: DocPath; before?: unknown; after?: unknown };
187
+ | { id: string; field: DocPath; before?: unknown; after?: unknown }
188
+ | { id: string; add: Card; after?: number }
189
+ | { id: string; remove: number };
187
190
  ```
188
191
 
189
- - **A proposal in text** reads the blocks `replace` names as rewritten to `after`, Markdown: the words that would go are struck, the words that would come are tinted, and blocks it adds stand in flow where they would land, with **Accept** and **Dismiss** at the end of its last line. `''` proposes the blocks' removal. `insert` proposes new blocks after or before the block it names, or at the field's end; in a field holding one empty paragraph it proposes that paragraph's text. A paragraph takes one proposal that rewrites it and one that adds after it, the first of each, whole. A word the proposal keeps and formats anew is drawn as a word it changes. The proposal is an edit of `before`, the blocks as its writer read them, or without one of the paragraph as it stood when the item arrived: what the reader writes in the paragraph meanwhile and while it stands is theirs, neither struck nor lost when the proposal is taken. Where the reader's writing meets the proposal's own words, the chip says **Edited since** and `onReviewDrawn` names the item `outdated`; where it reaches past them, the proposal reads as the whole paragraph as it now stands giving way to the whole of `after`. A block `replace` names that is gone, or that `before` does not read as, makes the proposal outdated too; a block an undo puts back under a new id is still the block it named. A proposal that would write nothing, its paragraph already reading as proposed, draws nothing.
190
- - **A proposal for a field** stands under the control as the value that would go and the value that would come, with the same two answers, and is outdated where the field no longer holds its `before`. Two lines of words differ by their words. Two lists differ by their members: a member both hold is kept, one that goes is struck, one that comes is tinted. A record differs by the keys that change, each as `key:` with its old and new value, and in a list of records only the records that differ show, each named by its first value when that stays. Accept writes the whole value.
191
- - **A proposal for a place inside a field** names it by its path, `main.contact.email` or `main.signature_block[2]`, and stands under the control of that place: a record's cell, a list's row, or for a member past the last, the list's foot, led by its number. Where no control of its own is drawn, inside a closed row or a matrix, it stands under the nearest one, led by where it is. Accept writes the field's whole value with that place alone changed, down the lane an edit of the place takes. In a list, `after` absent takes the member out, and an index past the last appends one. A member's `before` finds it: where the member at the index no longer holds it, the nearest that does and that no other open proposal of the list has found, so taking one member out does not move the next proposal onto the wrong row. One whose `before` nothing holds is outdated. An item in a closed group marks the group's header, and stepping to it opens the group.
192
+ - **A proposal in text** reads the blocks `replace` names as rewritten to `after`, Markdown: the words that would go are struck, the words that would come are tinted, and blocks it adds stand in flow where they would land. `''` proposes the blocks' removal. `insert` proposes new blocks after or before the block it names, or at the field's end; in a field holding one empty paragraph it proposes that paragraph's text. A paragraph takes one proposal that rewrites it and one that adds after it, the first of each, whole. A word the proposal keeps and formats anew is drawn as a word it changes. The proposal is an edit of `before`, the blocks as its writer read them, or without one of the paragraph as it stood when the item arrived: what the reader writes in the paragraph meanwhile and while it stands is theirs, neither struck nor lost when the proposal is taken. Where the reader's writing meets the proposal's own words, the answer card says **Changed since proposed** and `onReviewDrawn` names the item `outdated`; where it reaches past them, the proposal reads as the whole paragraph as it now stands giving way to the whole of `after`. A block `replace` names that is gone, or that `before` does not read as, makes the proposal outdated too; a block an undo puts back under a new id is still the block it named. A proposal that would write nothing, its paragraph already reading as proposed, draws nothing.
193
+ - **A proposal for a field** is drawn in its control as what Accept would write, and is outdated where the field no longer holds its `before`. A one-line or multi-line text field is drawn as a word diff in the field, the words that would go struck and the words that would come tinted in their own formatting; the diff is carried from `before`, as a paragraph's is, so what the reader types beside it is theirs and kept by Accept, and the proposal is outdated only where that typing meets its words. A number strikes its figures and tints the proposed ones. A choice, a date, a switch, or a record or list proposed whole shows in its control as the value that would come under the review tint, a cleared one as the default it would print or the empty control, and a field on its default drops its Default tag meanwhile. A commit on a choice, a date or a switch answers its proposal: the proposed value accepts it, any other value is written and dismisses it, and ⌘Z takes either back. Accept writes the whole value.
194
+ - **A proposal for a place inside a field** names it by its path, `main.contact.email` or `main.signature_block[2]`, and is drawn in the control of that place as a field's is: a record's cell, a list's row, ringed and struck where the member goes, or for a member past the last, a row after the list's last in the controls it would have, holding the proposed value under the review tint and taking no input. A choice with variants takes its discriminant at `main.distribution.value` and each cell of its world beside it, and a checklist each member at `main.checks.figures`, drawn on its tick, and each cell inside one. Where no control of its own is drawn, inside a closed row, it marks the nearest one. Accept writes the field's whole value with that place alone changed, down the lane an edit of the place takes. In a list, `after` absent takes the member out, and an index past the last appends one. A member's `before` finds it: where the member at the index no longer holds it, the nearest that does and that no other open proposal of the list has found, so taking one member out does not move the next proposal onto the wrong row. One whose `before` nothing holds is outdated. An item in a closed group marks the group's header, and stepping to it opens the group.
195
+ - **A proposed card** is drawn where it would stand: `add` as a preview of the card, its title, each field it fills by name and the start of its body, after the card at index `after` (before the first card without one), and `remove` as a ring round the card at that index, its values dimmed and _Proposed removal_ in its header. Accept writes it as the reader's own card operation, the added card under the `$id` it carries, and `onChange` reports it as a `structure` change; ⌘Z takes it back. Cards added after the same card stand in the list's order.
192
196
 
193
- `proposalsBetween(quill, base, answer)`, from `@quillmark/svelte/visual`, makes the list from an assistant's answer. `base` is the document as the assistant read it, a snapshot taken when it was asked, and `answer` a copy of it the assistant edited; neither is the live document, which the editor compares each item with as it draws, so what the reader typed meanwhile is theirs and a place both changed is `outdated`. It returns `{ items, cards }`: `items` with `before` filled in, one `replace` per block the answer rewrote or took out and one `insert` per run of blocks it added, and an item per record cell and list member that changed elsewhere, at the paths of `base`; `cards`, the cards it added (`{ type: 'add', card, after }`, `after` the id of the card it follows) and took out (`{ type: 'remove', id, kind }`), which no item draws and the host lists and answers itself. A path names its card by index, read against the cards as they stood when the list was set: the editor carries each item through every card added, removed or moved since, by `applyCardOps` or by the reader, so it stays on its card, and an item whose card is gone goes `undrawn` as `field`. A host accepting a card the answer added writes it and calls `applyCardOps` at once, with the review still open. A card added, removed or moved between the snapshot and the answer is not carried: a block item then names no block where its path lands and goes `undrawn` as `block`, and a field item with `before` mostly goes `outdated`, so a host sets the list over the cards the snapshot held, or clears it when they move before the answer lands.
197
+ `proposalsBetween(quill, base, answer)`, from `@quillmark/svelte/visual`, makes the list from an assistant's answer. `base` is the document as the assistant read it, a snapshot taken when it was asked, and `answer` a copy of it the assistant edited; neither is the live document, which the editor compares each item with as it draws, so what the reader typed meanwhile is theirs and a place both changed is `outdated`. It returns `{ items }`, with `before` filled in: one `replace` per block the answer rewrote or took out and one `insert` per run of blocks it added, an item per record cell and list member that changed elsewhere, at the paths of `base`, and an item per card it added, after the card of `base` it follows, and per card it took out. A path and a card item name their card by index, read against the cards as they stood when the list was set: the editor carries each item through every card added, removed or moved since, by `applyCardOps`, by the reader or by an accepted card item, so it stays on its card, and an item whose card is gone goes `undrawn` as `field`, a removal whose card is gone as `applied`. A card added, removed or moved between the snapshot and the answer is not carried: a block item then names no block where its path lands and goes `undrawn` as `block`, and a field item with `before` mostly goes `outdated`, so a host sets the list over the cards the snapshot held, or clears it when they move before the answer lands.
194
198
 
195
199
  ```ts
196
200
  const base = doc.clone(); // when the assistant is asked
197
201
  const answer = base.clone(); // the assistant edits this copy
198
- const { items, cards } = proposalsBetween(quill, base, answer);
202
+ const { items } = proposalsBetween(quill, base, answer);
199
203
  review = items;
200
204
  ```
201
205
 
@@ -207,17 +211,21 @@ The editor makes every write an answer asks for:
207
211
  | `dismiss` | Turned a proposal down. | Nothing. |
208
212
  | `reopen` | Undid an accept or a dismissal with ⌘Z. | Before the event, what an accept wrote is taken back by its own undo. The item is open again. |
209
213
 
214
+ Every answer to the current item moves on to the next open one, in the page's order and round from the end, without moving the caret or the focus, so a review is a run of answers. A review starts on its first item. The caret entering an item or a press on one makes it current at once, and the pointer resting on one makes it current after a short dwell; leaving an item keeps it current.
215
+
210
216
  An answered item is drawn no more from the moment of the answer: a dismissed one wrote nothing, and an accepted one is plain text in the document, the reader's like any other. The editor keeps no record of what an accept replaced; a host that offers to take a whole answer back keeps its own snapshot of the document from before it.
211
217
 
212
- ⌘Z/Ctrl+Z from anywhere in the editor takes back the answers given since the reader's last edit, newest first, one answer or one `answerReview` call at a time, and each comes back as `reopen`; past that edit a taken proposal is still undone in its own text field, with its `reopen`, and a field's value and a dismissal are final. A field's accept stands on the toast with its way back; a host's `answerReview` batch raises no toast, and ⌘Z takes it back whole.
218
+ ⌘Z/Ctrl+Z from anywhere in the editor, or from the host's chrome outside a text box, takes back the answers given since the reader's last edit, newest first, one answer or one `answerReview` call at a time, and each comes back as `reopen`; past that edit a taken proposal is still undone in its own text field, with its `reopen`, and a field's value, a card and a dismissal are final. No answer raises a toast; a host's `answerReview` batch is taken back whole.
219
+
220
+ The host sets the list once and clears it once. It sets it when an answer arrives, and clears it when the reader keeps the result or asks again, or the document closes; between the two it does not touch the list. The editor draws every answer while the list holds the item: an answered item goes, and an item reopened by ⌘Z is drawn open again. A field's proposal the schema refuses stays, unanswered, and the field says why as it does for any refused value.
213
221
 
214
- The host sets the list once and clears it once. It sets it when an answer arrives, and clears it when the reader keeps the result or asks again, or the document closes; between the two it does not touch the list. The editor draws every answer while the list holds the item: an answered item goes, and an item reopened by ⌘Z is drawn open again. A host that accepts on arrival waits for the first `onReviewDrawn` that lists the new ids, which arrives before the browser paints them, and accepts the ids of `open` that are in neither `outdated` nor `undrawn`, so a proposal the reader's writing meets stays open; an item the reader then reopens with ⌘Z it turns down with `answerReview([id], 'dismiss')`, so ⌘Z is the one press. A field's proposal the schema refuses stays, unanswered, and the field says why as it does for any refused value.
222
+ `onReviewDrawn` reports what the editor draws of the list, on each change once the leaves have drawn: `open`, the items drawn in document order, each still waiting for an answer, so a host's bar shows Keep once it is empty; `outdated`, the open proposals the reader's own writing meets; and `undrawn`, every listed item it does not draw, each with why: `block` (no block it names stands in its field, or no leaf of the field is mounted), `field` (the path names no field the editor holds, or a place inside one its schema does not declare), `parse` (`after` is not Markdown the leaf reads), `taken` (an earlier item has the paragraph or the field) or `applied` (the text already reads as proposed). A host's count and its next and previous read `open`, so they agree with the page.
215
223
 
216
- `onReviewDrawn` reports what the editor draws of the list, on each change once the leaves have drawn: `open`, the items drawn in document order, each still waiting for an answer, so a host's bar shows Keep once it is empty; `outdated`, the open proposals the reader's own writing meets, which a host accepting on arrival leaves open; and `undrawn`, every listed item it does not draw, each with why: `block` (no block it names stands in its field, or no leaf of the field is mounted), `field` (the path names no field the editor holds, or a place inside one its schema does not declare), `parse` (`after` is not Markdown the leaf reads), `taken` (an earlier item has the paragraph or the field) or `applied` (the text already reads as proposed). A host's count and its next and previous read `open`, so they agree with the page.
224
+ The verbs complete it. `answerReview(ids | 'all', 'accept' | 'dismiss')` answers items as the answer card would, in document order, and returns the ids answered: `onReview` hears each, an item that cannot be answered stands, `'all'` with `'accept'` leaves every outdated item open, and neither the focus nor the caret moves; answering the current item moves on as the card does. `stepReview(1 | -1)` brings the next or previous drawn item to the reader, round from either end, with the caret in it or the focus in its field (`{ focus: false }` only lights it), and resolves its id; it scrolls the item's own scroller only as far as it must to show it, so an editor in a pane that scrolls on its own steps within that pane. `revealReview(id)` brings one item to the reader: it opens the group holding the item, scrolls it to the middle of the pane and lights it, and resolves `false` for an item the editor does not draw; `{ focus: true }` also puts the caret in it.
217
225
 
218
- The verbs complete it. `answerReview(ids | 'all', 'accept' | 'dismiss')` answers items as their buttons would, in document order, and returns the ids answered: `onReview` hears each, an item that cannot be answered stands, neither the focus nor the caret moves, and no toast is raised. `stepReview(1 | -1)` brings the next or previous drawn item to the reader, round from either end, with the caret in it or the focus in its field (`{ focus: false }` only lights it), and resolves its id; it scrolls the item's own scroller only as far as it must to show it, so an editor in a pane that scrolls on its own steps within that pane. `revealReview(id)` brings one item to the reader: it opens the group holding the item, scrolls it to the middle of the pane and lights it, and resolves `false` for an item the editor does not draw; `{ focus: true }` also puts the caret in it.
226
+ The **answer card** floats on the current item, below it or above it where there is no room, with **Dismiss** and **Accept** and their keys. It scrolls with the item and is clipped at the pane's edge as the text is. It keeps clear of `reviewInset`, the px the host's chrome takes at the foot of the pane, while the item shows, steps aside while the reader types, and never takes the focus: a press on it leaves the focus where it was, and Alt+F10 puts the keyboard on it, Escape handing the focus back. Under a finger it drops the key hints and its buttons are tap-sized.
219
227
 
220
- With the caret in an item, or the focus in its field, `REVIEW_KEYS` answer it: ⌘/Ctrl+Enter accepts a proposal, and ⌘/Ctrl+. dismisses one. From anywhere in the editor ⌘/Ctrl+⌥/Alt+↓ and ↑ step to the next and previous item, as `stepReview` does. An answer given by a chord goes on to the next item, so ⌘/Ctrl+Enter pressed down a batch walks it; `reviewAdvance={false}` keeps the caret where the answer was given, and an answer by pointer never moves it. A proposal that only adds blocks answers from anywhere in the paragraph it adds after; where a proposal also rewrites that paragraph, the caret answers the rewrite, and `revealReview(id, { focus: true })` puts it in the one asked for. Every word the review draws is a `strings` key, and its one hue is `--qm-review` ([THEMING.md](THEMING.md)).
228
+ While a review is open, `REVIEW_KEYS` answer the current item from anywhere on the page but another editor or a text box outside this one: ⌘/Ctrl+Enter accepts it, ⌘/Ctrl+. dismisses it, and ⌘/Ctrl+⌥/Alt+↓ and ↑ step to the next and previous item, moving the caret along when pressed in the editor. A proposal that only adds blocks is current from anywhere in the paragraph it adds after; where a proposal also rewrites that paragraph, the caret names the rewrite, and `revealReview(id, { focus: true })` puts it in the one asked for. Every word the review draws is a `strings` key, and its one hue is `--qm-review` ([THEMING.md](THEMING.md)).
221
229
 
222
230
  ### Wording
223
231
 
@@ -86,3 +86,8 @@ export interface NestedAddr {
86
86
  * the path resolves to nothing. `path` itself where it names no card, or a card past `was`.
87
87
  */
88
88
  export declare function cardMoved(path: DocPath, was: readonly string[], now: readonly string[]): DocPath;
89
+ /** The index of the card `path` names, `undefined` where it names none. */
90
+ export declare function cardOfPath(path: DocPath): number | undefined;
91
+ /** `path` naming the card at `index` in place of the card it names; `path` itself where it
92
+ * names none. */
93
+ export declare function pathOnCard(path: DocPath, index: number): DocPath;
@@ -99,6 +99,20 @@ export function cardMoved(path, was, now) {
99
99
  return path;
100
100
  return core().formatDocPath([{ ...head, index }, ...segs.slice(1)]);
101
101
  }
102
+ /** The index of the card `path` names, `undefined` where it names none. */
103
+ export function cardOfPath(path) {
104
+ const head = segsOf(path)?.[0];
105
+ return head?.seg === 'card' ? head.index : undefined;
106
+ }
107
+ /** `path` naming the card at `index` in place of the card it names; `path` itself where it
108
+ * names none. */
109
+ export function pathOnCard(path, index) {
110
+ const segs = segsOf(path);
111
+ const head = segs?.[0];
112
+ if (!segs || head?.seg !== 'card' || head.index === index)
113
+ return path;
114
+ return core().formatDocPath([{ ...head, index }, ...segs.slice(1)]);
115
+ }
102
116
  /**
103
117
  * `parseDocPath`, with a malformed path as `undefined` rather than a throw. The gate is read
104
118
  * outside the try: an uninitialized core is not a malformed path.
@@ -6,7 +6,8 @@ import type { EditorErrorHandler } from '../errors.js';
6
6
  import { type Delta } from './positions.js';
7
7
  import { type TextCap } from './cap.js';
8
8
  import { type LeaveStrings } from './leave.js';
9
- import { type ReviewAction, type ReviewReport, type ReviewStrings, type ReviewVia, type TextReview } from './review.js';
9
+ import { type ReviewAction, type ReviewReport, type ReviewVia, type TextReview } from './review.js';
10
+ import { type ValueProposal, type ValueState } from './value-diff.js';
10
11
  import { type TableChromeStrings } from './table-view.js';
11
12
  import { type SlashState, type SlashStrings } from './slash.js';
12
13
  /** Options for {@link createField}. */
@@ -87,12 +88,9 @@ export interface CreateFieldOpts {
87
88
  /** An edit leaving the leaf empty removes the field: an optional cell (`t?`), whose
88
89
  * unanswered `none` is what the empty leaf draws and an empty answer would hide. */
89
90
  emptyUnsets?: boolean;
90
- /** The review layer's wording, read per decoration pass (`review.ts`). */
91
- reviewStrings?: () => ReviewStrings;
92
- /** A reader answered the review item `id`: a proposal's button or its chord, or an undo
93
- * that took the answer back, `chord` where a key gave it. A proposal taken is written by
94
- * then. */
95
- onReview?(id: string, action: ReviewAction, chord?: boolean): void;
91
+ /** The leaf answered the review item `id`, or an undo took the answer back. A proposal
92
+ * taken is written by then. */
93
+ onReview?(id: string, action: ReviewAction): void;
96
94
  /** The leaf is writing a taken proposal, and is done: the commit between is the answer's. */
97
95
  onReviewWriting?(on: boolean): void;
98
96
  /** The review item under the pointer or holding the caret, `undefined` once it has left.
@@ -102,6 +100,9 @@ export interface CreateFieldOpts {
102
100
  * whose anchor the leaf holds that it does not draw, each with why. An item whose anchor
103
101
  * the leaf does not hold is in neither. */
104
102
  onReviewDrawn?(report: ReviewReport): void;
103
+ /** On each draw of a whole proposed value, how it stands against what the leaf holds
104
+ * (`value-diff.ts`). */
105
+ onValuePlanned?(id: string, state: ValueState): void;
105
106
  onFocus?(addr: Addr): void;
106
107
  /** Fired with the new caret offset after an edit or a selection move. */
107
108
  onCaretMove?(addr: Addr, pos: number): void;
@@ -116,6 +117,19 @@ export interface CreateFieldOpts {
116
117
  onError?: EditorErrorHandler;
117
118
  }
118
119
  /** The prose-leaf handle (INVARIANTS §Surface). */
120
+ /** A leaf's open proposals written into a copy of its document, and the way between the two. */
121
+ export interface LeafProjection {
122
+ /** The proposals written, in the order the leaf was handed them. */
123
+ ids: readonly string[];
124
+ /** A content offset in the leaf as it stands, as an offset in the projection. */
125
+ toProjection(pos: number): number;
126
+ /** A content offset in the projection, as one in the leaf as it stands, or the proposal
127
+ * that adds the block holding it. Inside a stretch a proposal rewrites, the offset is the
128
+ * nearest the leaf holds. */
129
+ toLive(pos: number): number | {
130
+ review: string;
131
+ };
132
+ }
119
133
  export interface FieldController {
120
134
  /** The mounted `container`: the leaf's element, for a caller that has to reach the
121
135
  * DOM the view sits in (the arrival wash, `core/bloom.ts`) rather than re-find it. */
@@ -155,6 +169,9 @@ export interface FieldController {
155
169
  * `text` leaf holds no anchors and draws none.
156
170
  */
157
171
  setReview(items: readonly TextReview[], lit?: string): void;
172
+ /** Draw a whole proposed value over a one-line leaf as a word diff, or none
173
+ * (`value-diff.ts`). A leaf that holds blocks draws none. */
174
+ setValueProposal(p: ValueProposal | undefined): void;
158
175
  /** The elements the review item `id` draws, in document order; `[]` for one not drawn. */
159
176
  reviewElements(id: string): HTMLElement[];
160
177
  /** Put the caret in the review item `id` and focus the leaf; false for one not drawn. */
@@ -167,6 +184,12 @@ export interface FieldController {
167
184
  reopenReview(id: string): void;
168
185
  /** Undo the leaf's newest step, a taken proposal's, reported as `reopen`. */
169
186
  undoReview(): boolean;
187
+ /**
188
+ * Write every proposal the leaf draws into `target`, a copy of the document the leaf edits,
189
+ * as their accepts would commit them, dispatching nothing: the leaf, its history and its
190
+ * document are as they were. `undefined` where the leaf draws none.
191
+ */
192
+ projectReview(target: Document): LeafProjection | undefined;
170
193
  /** Ids of the anchors touching content range `[from, to]`: a selection's anchor state. */
171
194
  anchorsInRange(from: number, to: number): string[];
172
195
  /**
@@ -30,7 +30,8 @@ import { bodyKeymap, holdsTab } from './keymap.js';
30
30
  import { DEFAULT_LEAVE_STRINGS, leavePlugin } from './leave.js';
31
31
  import { FIELD_KEYS, markKeymap } from './shortcuts.js';
32
32
  import { remoteKey } from './remote.js';
33
- import { DEFAULT_REVIEW_STRINGS, renameBlocks, reviewLayer } from './review.js';
33
+ import { renameBlocks, reviewLayer } from './review.js';
34
+ import { valueDiffPlugin } from './value-diff.js';
34
35
  import { blockSchema, isBlockSchema, isInlineSchema, leafSchema, plainSchema } from './schema.js';
35
36
  import { linkPastePlugin } from './link-paste.js';
36
37
  import { dragMovePlugin } from './drag-move.js';
@@ -264,7 +265,6 @@ export function createField(opts) {
264
265
  : reviewLayer({
265
266
  items: () => reviewItems,
266
267
  lit: () => reviewLit,
267
- strings: () => opts.reviewStrings?.() ?? DEFAULT_REVIEW_STRINGS,
268
268
  parse: (markdown) => {
269
269
  if (!parsed.has(markdown)) {
270
270
  let node;
@@ -278,11 +278,15 @@ export function createField(opts) {
278
278
  }
279
279
  return parsed.get(markdown);
280
280
  },
281
- act: (id, action, chord) => opts.onReview?.(id, action, chord),
281
+ act: (id, action) => opts.onReview?.(id, action),
282
282
  writing: (on) => opts.onReviewWriting?.(on),
283
283
  point: (id, via) => opts.onReviewPoint?.(id, via),
284
284
  drew: (report) => opts.onReviewDrawn?.(report)
285
285
  });
286
+ let valueProposal;
287
+ const valueDiff = inline || plaintext
288
+ ? valueDiffPlugin(() => valueProposal, (id, state) => opts.onValuePlanned?.(id, state))
289
+ : undefined;
286
290
  // The menu's report channel; the vocabulary is the codec's own constant (`slash.ts`).
287
291
  const slash = block ? opts.onSlash : undefined;
288
292
  // Judged of the value being mounted rather than read off a diagnostic: a routed set
@@ -403,7 +407,11 @@ export function createField(opts) {
403
407
  placeholder: () => placeholderText,
404
408
  placeholderUntilEdit: opts.placeholderUntilEdit,
405
409
  cap: opts.cap,
406
- afterHistory: [anchorPlugin(seededAnchors), ...(review ? [review.plugin] : [])]
410
+ afterHistory: [
411
+ anchorPlugin(seededAnchors),
412
+ ...(review ? [review.plugin] : []),
413
+ ...(valueDiff ? [valueDiff] : [])
414
+ ]
407
415
  })
408
416
  });
409
417
  return { state: built, index: seedIndex };
@@ -721,6 +729,17 @@ export function createField(opts) {
721
729
  parsed.delete(markdown);
722
730
  review.refresh(view);
723
731
  },
732
+ setValueProposal(p) {
733
+ if (!valueDiff)
734
+ return;
735
+ if (p?.id === valueProposal?.id &&
736
+ p?.lit === valueProposal?.lit &&
737
+ JSON.stringify([p?.after, p?.before]) ===
738
+ JSON.stringify([valueProposal?.after, valueProposal?.before]))
739
+ return;
740
+ valueProposal = p;
741
+ view.setProps({});
742
+ },
724
743
  reviewElements(id) {
725
744
  return review?.elements(view, id) ?? [];
726
745
  },
@@ -733,6 +752,50 @@ export function createField(opts) {
733
752
  undoReview() {
734
753
  return review?.undo(view) ?? false;
735
754
  },
755
+ projectReview(target) {
756
+ if (!review || held || plaintext)
757
+ return undefined;
758
+ const projected = review.project(view.state);
759
+ if (!projected)
760
+ return undefined;
761
+ const { state: next, mapping, added, ids } = projected;
762
+ const scan = scanDoc(next.doc);
763
+ const after = lineIndexOf(scan);
764
+ const anchors = (anchorKey.getState(next)?.anchors ?? []).map((a) => ({
765
+ id: a.id,
766
+ start: pmToOffset(after, a.start),
767
+ end: pmToOffset(after, a.end)
768
+ }));
769
+ const newRt = scanContent(scan, anchors);
770
+ const at = writeAddr(target, addr);
771
+ try {
772
+ if (opts.emptyUnsets && !anchors.length && isEmptyContent(newRt))
773
+ target.removeField(addr);
774
+ else if (!changeCommittable(target, addr))
775
+ target.replace(at, newRt);
776
+ else {
777
+ const change = lower(reconciler.last, newRt);
778
+ if (change) {
779
+ askCore(reconciler.last, change);
780
+ target.apply(at, change);
781
+ }
782
+ }
783
+ }
784
+ catch {
785
+ target.replace(at, newRt);
786
+ }
787
+ const back = mapping.invert();
788
+ const live = index;
789
+ return {
790
+ ids,
791
+ toProjection: (pos) => pmToOffset(after, mapping.map(offsetToPM(live, pos))),
792
+ toLive(pos) {
793
+ const pm = offsetToPM(after, pos);
794
+ const adds = added.find((a) => a.from <= pm && pm < a.to);
795
+ return adds ? { review: adds.id } : pmToOffset(live, back.map(pm));
796
+ }
797
+ };
798
+ },
736
799
  enterReview(id) {
737
800
  return review?.enter(view, id) ?? false;
738
801
  },
@@ -1,7 +1,7 @@
1
1
  export { markAnchor, rangeAnchor } from './anchor.js';
2
2
  export type { RangeAnchor } from './anchor.js';
3
3
  export { createField, emptyContent, heldAttributes, isEmptyContent, proseAttributes, proseLeafPlugins } from './field.js';
4
- export type { CreateFieldOpts, FieldController, LeafViews } from './field.js';
4
+ export type { CreateFieldOpts, FieldController, LeafProjection, LeafViews } from './field.js';
5
5
  export { capCount } from './cap.js';
6
6
  export { joinLines, pastedLines } from './line-paste.js';
7
7
  export type { TextCap } from './cap.js';
@@ -11,9 +11,12 @@ export { DEFAULT_SLASH_STRINGS } from './slash.js';
11
11
  export type { SlashState, SlashStrings } from './slash.js';
12
12
  export { DEFAULT_LEAVE_STRINGS } from './leave.js';
13
13
  export type { LeaveStrings } from './leave.js';
14
- export { DEFAULT_REVIEW_STRINGS } from './review.js';
15
- export type { BlockPlace, LeafUndrawn, ReviewAction, ReviewReport, ReviewStrings, ReviewVia, TextReview } from './review.js';
14
+ export type { BlockPlace, LeafUndrawn, ReviewAction, ReviewReport, ReviewVia, TextReview } from './review.js';
16
15
  export { wordDiff } from './review-diff.js';
16
+ export { valueDiffPlugin } from './value-diff.js';
17
+ export type { ValueProposal, ValueState } from './value-diff.js';
18
+ export { asContent, planValue, valueChanges } from './value-plan.js';
19
+ export type { ValuePlan, ValueChange } from './value-plan.js';
17
20
  export type { DiffHunk } from './review-diff.js';
18
21
  export { DEFAULT_SHORTCUT_STRINGS, FIELD_KEYS, REVIEW_KEYS, editorShortcuts } from './shortcuts.js';
19
22
  export type { EditorShortcut, ShortcutScope, ShortcutStrings } from './shortcuts.js';
@@ -25,10 +25,9 @@ export { DEFAULT_SLASH_STRINGS } from './slash.js';
25
25
  // The body's way out by the keyboard: the codec owns the keys and the hint's element,
26
26
  // the visual tier's `strings` set its wording.
27
27
  export { DEFAULT_LEAVE_STRINGS } from './leave.js';
28
- // The review layer a leaf draws over its blocks: the visual tier's `strings` set extends its
29
- // wording and its `ReviewItem` narrows to the leaf's own.
30
- export { DEFAULT_REVIEW_STRINGS } from './review.js';
31
28
  export { wordDiff } from './review-diff.js';
29
+ export { valueDiffPlugin } from './value-diff.js';
30
+ export { asContent, planValue, valueChanges } from './value-plan.js';
32
31
  // The rich editor's shortcuts as a host lists them, read off the tables the keymaps bind from;
33
32
  // the visual tier's `strings` set extends their wording, and the formatting popover binds its
34
33
  // link chord from `FIELD_KEYS`.
@@ -801,9 +801,13 @@ li.ProseMirror-selectednode::after {
801
801
  }
802
802
  /* The tint runs a hair past the words on either side, as a highlighter does, without moving
803
803
  them: a shadow in the tint's own colour beside the fill, so the line sets as it would
804
- without the proposal. */
804
+ without the proposal. A thin line in the review line under them says it in more than colour,
805
+ as the strike does for the words that would go. */
805
806
  .ProseMirror .qm-review-ins {
806
- text-decoration: none;
807
+ text-decoration: underline;
808
+ text-decoration-color: var(--_qm-review-line);
809
+ text-decoration-thickness: var(--_qm-border-width);
810
+ text-underline-offset: 0.2em;
807
811
  background: var(--_qm-review-tint);
808
812
  box-shadow:
809
813
  calc(-1 * var(--_qm-space-half)) 0 0 var(--_qm-review-tint),
@@ -829,7 +833,8 @@ li.ProseMirror-selectednode::after {
829
833
  background-color var(--_qm-duration-fast) var(--_qm-ease-reverse),
830
834
  box-shadow var(--_qm-duration-fast) var(--_qm-ease-reverse);
831
835
  }
832
- .ProseMirror .qm-review-lit .qm-review-ins {
836
+ .ProseMirror .qm-review-lit .qm-review-ins,
837
+ .ProseMirror .qm-review-ins.qm-review-lit {
833
838
  background: var(--_qm-review-lit);
834
839
  box-shadow:
835
840
  calc(-1 * var(--_qm-space-half)) 0 0 var(--_qm-review-lit),
@@ -850,84 +855,13 @@ li.ProseMirror-selectednode::after {
850
855
  content: none;
851
856
  }
852
857
 
853
- /* A proposal's two answers, at the end of its last line: chrome set in the paragraph, so
854
- at the chrome's face and the label rung whatever the block around it is set in. A run
855
- rather than a row, so a proposal takes no line the paragraph did not have; the row is
856
- for a block with no line to end. The run stands a space off the words, and the space is
857
- a real one, widened: it hangs at the end of a line the answers wrap from, where a margin
858
- would indent them. Accept is the one outlined thing in the pair, on the card's own
859
- ground so it reads as a button over a tinted block too, and Dismiss rests as a word. */
860
- .ProseMirror .qm-review-chip {
861
- font-family: var(--_qm-font);
862
- font-size: var(--_qm-text-label);
863
- font-style: normal;
864
- font-weight: var(--_qm-weight-mid);
865
- line-height: var(--_qm-leading-tight);
866
- word-spacing: var(--_qm-space);
867
- user-select: none;
868
- }
869
- .qm-review-acts {
870
- display: inline-flex;
871
- gap: var(--_qm-space-half);
872
- vertical-align: baseline;
873
- word-spacing: normal;
874
- white-space: nowrap;
875
- }
876
- .ProseMirror .qm-review-chip-row {
877
- display: block;
878
- margin-block-start: var(--_qm-space);
879
- }
880
- .qm-review-act {
881
- padding: var(--_qm-space-half) var(--_qm-space-2);
882
- border: none;
883
- border-radius: var(--_qm-radius-inner);
884
- background: transparent;
885
- font: inherit;
886
- color: var(--_qm-ink-label);
887
- cursor: pointer;
888
- transition:
889
- background-color var(--_qm-duration-fast) var(--_qm-ease-reverse),
890
- color var(--_qm-duration-fast) var(--_qm-ease-reverse);
891
- }
892
- .qm-review-act:hover {
893
- background: var(--_qm-surface-hover);
894
- color: var(--_qm-ink);
895
- }
896
- .qm-review-act.qm-review-accept {
897
- background: var(--_qm-bg);
898
- box-shadow: inset 0 0 0 var(--_qm-vertical-width) var(--_qm-review-line);
899
- color: var(--_qm-ink);
900
- }
901
- .qm-review-act.qm-review-accept:hover {
902
- background: linear-gradient(var(--_qm-review-tint), var(--_qm-review-tint)) var(--_qm-bg);
903
- }
904
- /* Under a finger the two answers are a tap target each, and stand apart. */
905
- @media (pointer: coarse) {
906
- .qm-review-act {
907
- padding-block: var(--_qm-space);
908
- }
909
- .qm-review-acts {
910
- gap: var(--_qm-space-2);
911
- }
912
- }
913
- /* A proposal the reader's own writing meets says so before its answers, in the label's ink:
914
- taking it writes over what the reader wrote. */
915
- .qm-review-outdated-label {
916
- align-self: center;
917
- color: var(--_qm-ink-label);
918
- }
919
- /* Forced colours drop the tint, which is all that tells a proposed word from the document's
920
- and Accept from a word beside it. A line under the proposed words, an outline round an
921
- added block and the system's button stroke round each answer stand in. */
858
+ /* Forced colours drop the tint and the line's colour. The line under the proposed words stays,
859
+ in the text's own colour, and an outline round an added block stands in for its tint. */
922
860
  @media (forced-colors: active) {
923
861
  .ProseMirror .qm-review-ins {
924
- text-decoration: underline;
862
+ text-decoration-color: currentColor;
925
863
  }
926
864
  .ProseMirror .qm-review-add {
927
865
  outline: var(--_qm-border-width) solid CanvasText;
928
866
  }
929
- .qm-review-act.qm-review-accept,
930
- .qm-review-act.qm-review-dismiss {
931
- border: var(--_qm-border-width) solid ButtonText;
932
- }
933
867
  }
@@ -1,5 +1,6 @@
1
1
  import { type Node as PMNode } from 'prosemirror-model';
2
- import { Plugin, type Transaction } from 'prosemirror-state';
2
+ import { Plugin, type EditorState, type Transaction } from 'prosemirror-state';
3
+ import { Mapping } from 'prosemirror-transform';
3
4
  import { type EditorView } from 'prosemirror-view';
4
5
  /**
5
6
  * One proposal over a prose leaf, by the blocks that place it.
@@ -39,29 +40,15 @@ export type BlockPlace = {
39
40
  export type ReviewAction = 'accept' | 'dismiss' | 'reopen';
40
41
  /** What brought an item under attention: the pointer over it, or the caret in it. */
41
42
  export type ReviewVia = 'pointer' | 'caret';
42
- /** The words the leaf draws on a proposal's two buttons, and the names of what has no words. */
43
- export interface ReviewStrings {
44
- reviewAccept: string;
45
- reviewDismiss: string;
46
- /** The two buttons' tooltips, which name their chords (`REVIEW_KEYS`). */
47
- reviewAcceptTitle: string;
48
- reviewDismissTitle: string;
49
- /** The accessible name of a proposal's two buttons as a group. */
50
- reviewProposal: string;
51
- /** The label before the buttons of a proposal whose paragraph the reader rewrote since. */
52
- reviewOutdated: string;
53
- }
54
- export declare const DEFAULT_REVIEW_STRINGS: ReviewStrings;
55
43
  /** What the plugin reads and reports through; every reader is live. */
56
44
  export interface ReviewChannel {
57
45
  items(): readonly TextReview[];
58
46
  /** The item under attention, drawn a step stronger. */
59
47
  lit(): string | undefined;
60
- strings(): ReviewStrings;
61
48
  /** `after` as a document under the leaf's schema; `undefined` where it does not parse. */
62
49
  parse(markdown: string): PMNode | undefined;
63
- /** A reader's answer, `chord` where a key gave it. */
64
- act(id: string, action: ReviewAction, chord?: boolean): void;
50
+ /** An answer the leaf gave or took back. */
51
+ act(id: string, action: ReviewAction): void;
65
52
  /** The leaf is writing a taken proposal, and is done. */
66
53
  writing?(on: boolean): void;
67
54
  /** The item the pointer or the caret is in, `undefined` once it has left. */
@@ -89,6 +76,22 @@ export interface ReviewReport {
89
76
  }
90
77
  /** Tell the review layer the store took blocks under new ids, each `[was, now]`. */
91
78
  export declare function renameBlocks(tr: Transaction, renamed: readonly (readonly [string, string])[]): void;
79
+ /** A leaf with every proposal it draws taken: the state the accepts leave it in, without one of
80
+ * them dispatched. */
81
+ export interface Projected {
82
+ /** The leaf's state as its accepts would leave it. */
83
+ state: EditorState;
84
+ /** The ids taken, in the order the leaf was handed them. */
85
+ ids: string[];
86
+ /** From the leaf as it stands to the projected one. */
87
+ mapping: Mapping;
88
+ /** The blocks a proposal adds, as ranges of the projected document, by its id. */
89
+ added: {
90
+ id: string;
91
+ from: number;
92
+ to: number;
93
+ }[];
94
+ }
92
95
  /** The handle the leaf keeps on its review layer. */
93
96
  export interface ReviewLayer {
94
97
  plugin: Plugin;
@@ -96,17 +99,20 @@ export interface ReviewLayer {
96
99
  refresh(view: EditorView): void;
97
100
  /** The elements item `id` draws, in document order. */
98
101
  elements(view: EditorView, id: string): HTMLElement[];
99
- /** Put the caret in item `id` and take the focus, so the item's chords answer. False for
100
- * an item the leaf does not draw. */
102
+ /** Put the caret in item `id` and take the focus. False for an item the leaf does not
103
+ * draw. */
101
104
  enter(view: EditorView, id: string): boolean;
102
- /** Answer item `id` as its button would, moving neither the caret nor the focus. False
103
- * where the leaf does not draw it or cannot write it. */
105
+ /** Answer item `id`, moving neither the caret nor the focus. False where the leaf does not
106
+ * draw it or cannot write it. */
104
107
  answer(id: string, action: 'accept' | 'dismiss'): boolean;
105
108
  /** Open a dismissal of item `id` again and say so, the dismissal still held here or
106
109
  * already pruned by the host taking the item off its list. */
107
110
  reopen(view: EditorView, id: string): void;
108
111
  /** Undo the leaf's newest history step: an accept's, which reopens its item. */
109
112
  undo(view: EditorView): boolean;
113
+ /** The leaf with every proposal it draws taken, nothing dispatched; `undefined` where it
114
+ * draws none, or taking them writes nothing. */
115
+ project(state: EditorState): Projected | undefined;
110
116
  }
111
117
  /**
112
118
  * The leaf's review layer. The decorations are a function of the document and the channel's