@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
package/README.md
CHANGED
|
@@ -147,9 +147,81 @@ Hand it a different `doc` and the editor **re-keys itself**: every leaf remounts
|
|
|
147
147
|
|
|
148
148
|
`insertCard` hands back the new card's `cardId`; `removeCard`, `moveCard` and `setKind` take one. `focusField` reaches any mounted field: a prose leaf takes its view's focus, a form control the same handoff a click on its label takes, and either way the group holding it is revealed first. `washField` plays the same arrival wash over a field and nothing else, for a change the host wrote: focus, scroll and closed groups stay as they are, and a field in a closed group washes nothing. A card key or a path the surface does not hold is a no-op that reports `target-unknown` through `onError` at `dev` severity.
|
|
149
149
|
|
|
150
|
+
### Review
|
|
151
|
+
|
|
152
|
+
`review` is a list of what someone other than the reader, an assistant or a collaborator, proposes to change in the document. The editor draws each item where it is, in its own flow, and reports the reader's answers. The list is plain data, the host's to set: an item is drawn while it is on the list.
|
|
153
|
+
|
|
154
|
+
```svelte
|
|
155
|
+
<VisualEditor
|
|
156
|
+
bind:this={editor}
|
|
157
|
+
{doc}
|
|
158
|
+
{quill}
|
|
159
|
+
review={items}
|
|
160
|
+
onReview={({ id, action }) => {
|
|
161
|
+
/* heard for each answer; the editor draws it, and the list stays as it was set */
|
|
162
|
+
}}
|
|
163
|
+
onReviewFocus={(id) => {
|
|
164
|
+
/* the item under the reader's attention, or undefined */
|
|
165
|
+
}}
|
|
166
|
+
/>
|
|
167
|
+
```
|
|
168
|
+
|
|
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
|
+
|
|
171
|
+
```ts
|
|
172
|
+
type ReviewItem =
|
|
173
|
+
| {
|
|
174
|
+
id: string;
|
|
175
|
+
field: DocPath;
|
|
176
|
+
replace: string[];
|
|
177
|
+
before?: string;
|
|
178
|
+
after: string;
|
|
179
|
+
}
|
|
180
|
+
| {
|
|
181
|
+
id: string;
|
|
182
|
+
field: DocPath;
|
|
183
|
+
insert: { after: string } | { before: string } | 'end';
|
|
184
|
+
after: string;
|
|
185
|
+
}
|
|
186
|
+
| { id: string; field: DocPath; before?: unknown; after?: unknown };
|
|
187
|
+
```
|
|
188
|
+
|
|
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, and its Undo writes that place alone back, so another place taken since keeps its change. 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
|
+
|
|
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, so a card added, removed or moved between the snapshot and the answer, or while the review is open, puts an item's path on another card: a block item then names no block there and goes `undrawn` as `block`, and a field item with `before` mostly goes `outdated`, but one can land on the wrong card where that card's field holds the same value. A host either holds adding, removing and moving cards while an answer is pending and its review is open, or clears the review when the card list changes.
|
|
194
|
+
|
|
195
|
+
```ts
|
|
196
|
+
const base = doc.clone(); // when the assistant is asked
|
|
197
|
+
const answer = base.clone(); // the assistant edits this copy
|
|
198
|
+
const { items, cards } = proposalsBetween(quill, base, answer);
|
|
199
|
+
review = items;
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
The editor makes every write an answer asks for:
|
|
203
|
+
|
|
204
|
+
| `action` | What the reader did | What is written |
|
|
205
|
+
| --------- | ------------------------------- | --------------------------------------------------------------------------------------------------------- |
|
|
206
|
+
| `accept` | Took a proposal. | Before the event, the proposal as it was drawn, as an edit of the reader's. `onChange` reports it. |
|
|
207
|
+
| `dismiss` | Turned a proposal down. | Nothing. |
|
|
208
|
+
| `reopen` | Undid an accept or a dismissal. | Before the event, what an accept wrote is taken back, as an edit of the reader's. The item is open again. |
|
|
209
|
+
|
|
210
|
+
An accepted proposal the list still holds is drawn as the change it made: the words it wrote underlined, a wedge where it only removed words, and a field's control marked along its foot, each with the card that shows what stood there and **Undo**, raised by the pointer or the caret resting on it and lowered by Escape. Undo takes back what the accept wrote, the old words with their formatting or the old value, as an edit of the reader's, out of order and past whatever the reader has typed beside it, and reports `reopen`: the item is a proposal again. Words the reader typed inside the accepted ones go with them, and a mark whose words are all gone, or a field set to another value since, drops without a report. With the caret in the mark, ⌘/Ctrl+. does what Undo does. The marks are the mounted editor's and are not stored: a leaf that mounts again shows the text as it stands, and the item reports as `applied`.
|
|
211
|
+
|
|
212
|
+
A dismissed item is drawn no more from the moment of the answer. ⌘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.
|
|
213
|
+
|
|
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: a dismissed item goes, an accepted proposal is drawn as its change, and an item reopened by Undo or ⌘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 `order` that are in neither `outdated` nor `undrawn`, so a proposal the reader's writing meets stays open; an item the reader then reopens it turns down with `answerReview([id], 'dismiss')`, so Undo is the one press. Clearing the list keeps the accepted changes unmarked. A field's proposal the schema refuses stays, unanswered, and the field says why as it does for any refused value.
|
|
215
|
+
|
|
216
|
+
`onReviewDrawn` reports what the editor draws of the list, on each change once the leaves have drawn: `order`, the items drawn in document order; `accepted`, those of them drawn as accepted changes; `open`, the rest of `order`, 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 `order`, so they agree with the page.
|
|
217
|
+
|
|
218
|
+
The verbs complete it. `answerReview(ids | 'all', 'accept' | 'dismiss' | 'reopen')` answers items as their buttons would, in document order, and returns the ids answered: `onReview` hears each, an accept and a dismissal pass over a proposal already accepted, `'reopen'` takes back each accepted one as its Undo does, 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, lights it and raises its card, and resolves `false` for an item the editor does not draw; `{ focus: true }` also puts the caret in it.
|
|
219
|
+
|
|
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 or takes an accepted one back. 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. The caret is in the item that holds it closest, so in an accepted change inside another proposal's paragraph ⌘/Ctrl+. takes the change back, and ⌘/Ctrl+Enter takes the proposal still. 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)).
|
|
221
|
+
|
|
150
222
|
### Wording
|
|
151
223
|
|
|
152
|
-
The package ships English and a seam to replace it. `strings` is keyed and **partial**: set what you have translations for, and the rest stay the package's. Several keys are **accessible names** rather than decoration (the card controls, the add trigger), so an untranslated surface reads the wrong language to a screen reader. `DEFAULT_VISUAL_STRINGS` is the English, exported so you can compose against it. `<Preview>` takes its own
|
|
224
|
+
The package ships English and a seam to replace it. `strings` is keyed and **partial**: set what you have translations for, and the rest stay the package's. Several keys are **accessible names** rather than decoration (the card controls, the add trigger), so an untranslated surface reads the wrong language to a screen reader. `DEFAULT_VISUAL_STRINGS` is the English, exported so you can compose against it. `<Preview>` takes its own `strings`: the states it shows when there is nothing to paint, the zoom pill's action, and the names a screen reader hears for the pane and each page.
|
|
153
225
|
|
|
154
226
|
```svelte
|
|
155
227
|
<VisualEditor
|
package/THEMING.md
CHANGED
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
|
|
5
5
|
There are three depths to that. An app mounting into an unstyled page stops at the first; an app with a plate of its own starts at the second:
|
|
6
6
|
|
|
7
|
-
| | You write
|
|
8
|
-
| ----------------- |
|
|
9
|
-
| **Drop it in** | nothing
|
|
10
|
-
| **Make it yours** |
|
|
11
|
-
| **Match ours** | one CSS import
|
|
7
|
+
| | You write | You get |
|
|
8
|
+
| ----------------- | --------------------- | ------------------------------------------------------- |
|
|
9
|
+
| **Drop it in** | nothing | a mounted surface that looks right in a bare `<div>` |
|
|
10
|
+
| **Make it yours** | ten custom properties | the whole surface rescaled and recolored to your brand |
|
|
11
|
+
| **Match ours** | one CSS import | the page around the surface, drawn the way we draw ours |
|
|
12
12
|
|
|
13
13
|
## Drop it in
|
|
14
14
|
|
|
@@ -32,7 +32,7 @@ A surface's width is the one you give it. Each contains its own inline size, so
|
|
|
32
32
|
|
|
33
33
|
## Make it yours
|
|
34
34
|
|
|
35
|
-
The whole contract is **
|
|
35
|
+
The whole contract is **ten CSS custom properties**. They are dials, not a palette: each derives a closed private scale that every component reads, so one override rescales or recolors the whole surface. Set them on any ancestor of a mounted surface (the app, or one pane):
|
|
36
36
|
|
|
37
37
|
```css
|
|
38
38
|
.my-editor {
|
|
@@ -57,8 +57,9 @@ The poles take a colour, not `transparent` or `inherit`: the raised surfaces, th
|
|
|
57
57
|
| ---------------- | -------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
58
58
|
| `--qm-bg` | `#fff` / `#272729` | Base surface: a card, and the preview's sheet. Fields, the popover and the column behind the cards each step off it. |
|
|
59
59
|
| `--qm-fg` | `#1c1c1c` / `#d7dadc` | Base ink. Body text, labels, and borders step off it. |
|
|
60
|
-
| `--qm-accent` | `#71717a` / `#a1a1aa` | Focus rings, active marks, the preview's active field box.
|
|
60
|
+
| `--qm-accent` | `#71717a` / `#a1a1aa` | Focus rings, active marks, the preview's active field box. Outside error and review the surface spends no hue of its own, so this is the one it wears. |
|
|
61
61
|
| `--qm-danger` | `#9e1518` / `#f9786c` | Error diagnostics and the delete glyph. |
|
|
62
|
+
| `--qm-review` | `#4f46e5` / `#a5b4fc` | Review: the line under a change someone else made, and the tint under the words a proposal would add. Give it the hue your app gives its reviewer. |
|
|
62
63
|
| `--qm-font` | `ui-sans-serif, system-ui, sans-serif` | The editor surface's font family. Controls and buttons take it too, in place of the UA face. |
|
|
63
64
|
| `--qm-font-mono` | `ui-monospace, monospace` | The monospace face: the JSON array control, the tips card. |
|
|
64
65
|
| `--qm-font-size` | `0.875rem` | Chrome text: every control's size, the anchor the ramp derives up (title) and down (label/meta) from, and the anchor a document body sits one small step over. |
|
|
@@ -106,7 +107,7 @@ Setting the poles yourself wins over the default in both schemes, so a fixed pal
|
|
|
106
107
|
}
|
|
107
108
|
```
|
|
108
109
|
|
|
109
|
-
That cuts both ways for the status hue: `--qm-danger` defaults to a pair calibrated against the card at both poles, and one pinned value replaces both arms, so a red measured against white carries into the dark scheme unmeasured. Pin it under your own scheme rule (`.dark { --qm-danger: … }`) where the colour your app means by error is itself scheme-aware.
|
|
110
|
+
That cuts both ways for the status hue: `--qm-danger` defaults to a pair calibrated against the card at both poles, and one pinned value replaces both arms, so a red measured against white carries into the dark scheme unmeasured. Pin it under your own scheme rule (`.dark { --qm-danger: … }`) where the colour your app means by error is itself scheme-aware. `--qm-review` is a pair the same way.
|
|
110
111
|
|
|
111
112
|
A palette **pinned against** your own scheme still wants a second line, for a smaller reason than it used to be: the planes read your card's lightness, so the surface itself lands right either way, but the poles' own defaults, the status hue and native chrome all still read `color-scheme`. Pin it with them (`.my-editor { color-scheme: dark }`). Skip that line and what the browser paints — the selection highlight, the scrollbar, the spinner — stays on whichever scheme the host inherits, and a status hue you left to us is measured against the wrong card.
|
|
112
113
|
|
|
@@ -131,7 +132,7 @@ import '@quillmark/svelte/preset';
|
|
|
131
132
|
|
|
132
133
|
This is the stylesheet our own apps import: the playground, studio and quillkit's app client draw with these rules and nothing else, so what you get is what we ship, not a reduction of it.
|
|
133
134
|
|
|
134
|
-
It carries a `--qmh-*` scale for the page, derived from the same
|
|
135
|
+
It carries a `--qmh-*` scale for the page, derived from the same ten dials and calibrated against the surfaces' own steps, so a plate of yours and a card of ours agree about which way "raised" goes. Turning a dial moves both.
|
|
135
136
|
|
|
136
137
|
| Class | What it is |
|
|
137
138
|
| ------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
|
|
@@ -212,7 +213,7 @@ They compute at specificity zero, as the shell does, so `.qm-app-header { backgr
|
|
|
212
213
|
|
|
213
214
|
A stylesheet you write against a mounted surface, or one an author writes over an app someone else built, may aim at these and nothing else:
|
|
214
215
|
|
|
215
|
-
- the
|
|
216
|
+
- the ten dials (§"The dials");
|
|
216
217
|
- the surface roots, `.qm-editor` and `.qm-preview`, and `.qm-pane`;
|
|
217
218
|
- `data-qm-card="<kind>"`, on the box of every card the editor draws, its value the card's kind and `main` for the main card;
|
|
218
219
|
- the preset's classes, on your own DOM, if you import it (§"Match ours").
|
|
@@ -17,3 +17,15 @@ export interface RangeAnchor {
|
|
|
17
17
|
* `from === to` is a caret, which is what the slash menu hangs off.
|
|
18
18
|
*/
|
|
19
19
|
export declare function rangeAnchor(view: EditorView, from: number, to: number): RangeAnchor;
|
|
20
|
+
/**
|
|
21
|
+
* `anchor`'s horizontal extent over the vertical extent of `boxes`: a surface hung off it
|
|
22
|
+
* clears every one, as a surface over a selection in a table cell clears the cell's row.
|
|
23
|
+
*/
|
|
24
|
+
export declare function across(anchor: RangeAnchor, boxes: readonly Element[]): RangeAnchor;
|
|
25
|
+
/**
|
|
26
|
+
* A virtual anchor over the first line box of the element `find` returns when asked: a mark a
|
|
27
|
+
* view redraws under every edit, so no element outlives the surface hung off it. `context` is
|
|
28
|
+
* the view's own element, which does. Total as {@link rangeAnchor} is: with nothing to measure
|
|
29
|
+
* it returns the last rect that measured.
|
|
30
|
+
*/
|
|
31
|
+
export declare function markAnchor(context: Element, find: () => Element | undefined): RangeAnchor;
|
|
@@ -58,3 +58,42 @@ export function rangeAnchor(view, from, to) {
|
|
|
58
58
|
}
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* `anchor`'s horizontal extent over the vertical extent of `boxes`: a surface hung off it
|
|
63
|
+
* clears every one, as a surface over a selection in a table cell clears the cell's row.
|
|
64
|
+
*/
|
|
65
|
+
export function across(anchor, boxes) {
|
|
66
|
+
return {
|
|
67
|
+
contextElement: anchor.contextElement,
|
|
68
|
+
getBoundingClientRect: () => {
|
|
69
|
+
const { left, width } = anchor.getBoundingClientRect();
|
|
70
|
+
let top = Infinity;
|
|
71
|
+
let bottom = -Infinity;
|
|
72
|
+
for (const box of boxes) {
|
|
73
|
+
const rect = box.getBoundingClientRect();
|
|
74
|
+
top = Math.min(top, rect.top);
|
|
75
|
+
bottom = Math.max(bottom, rect.bottom);
|
|
76
|
+
}
|
|
77
|
+
return new DOMRect(left, top, width, bottom - top);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* A virtual anchor over the first line box of the element `find` returns when asked: a mark a
|
|
83
|
+
* view redraws under every edit, so no element outlives the surface hung off it. `context` is
|
|
84
|
+
* the view's own element, which does. Total as {@link rangeAnchor} is: with nothing to measure
|
|
85
|
+
* it returns the last rect that measured.
|
|
86
|
+
*/
|
|
87
|
+
export function markAnchor(context, find) {
|
|
88
|
+
let last;
|
|
89
|
+
return {
|
|
90
|
+
contextElement: context,
|
|
91
|
+
getBoundingClientRect: () => {
|
|
92
|
+
const el = find();
|
|
93
|
+
const rect = el?.getClientRects()[0] ?? el?.getBoundingClientRect();
|
|
94
|
+
if (rect)
|
|
95
|
+
last = rect;
|
|
96
|
+
return last ?? new DOMRect();
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Plugin } from 'prosemirror-state';
|
|
2
|
+
import type { EditorView } from 'prosemirror-view';
|
|
3
|
+
/**
|
|
4
|
+
* Deletes what a drag took from its own leaf when a different leaf accepts the drop. The
|
|
5
|
+
* receiving view parses the drop through its own schema, as it does a paste, and the
|
|
6
|
+
* delete follows only a drop that changed it, so text a leaf refused stays where it was.
|
|
7
|
+
* The copy modifier keeps the source, as it does inside one view, and a read-only source
|
|
8
|
+
* keeps it always. `owner` is the view whose history holds this view's edits, where that
|
|
9
|
+
* is not the view itself.
|
|
10
|
+
*/
|
|
11
|
+
export declare function dragMovePlugin(owner?: () => EditorView): Plugin;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { Plugin, PluginKey } from 'prosemirror-state';
|
|
2
|
+
import { isHistoryTransaction, redo, undo } from 'prosemirror-history';
|
|
3
|
+
import { joinStep } from './undo.js';
|
|
4
|
+
/** The history owner of a view that keeps none, named by the view's own plugin. */
|
|
5
|
+
const owners = new WeakMap();
|
|
6
|
+
/** The view the drag in flight started in. One drag runs at a time, across every editor
|
|
7
|
+
* on the page. */
|
|
8
|
+
let source;
|
|
9
|
+
/** The latest move: the two leaves whose histories hold its halves, each at the document
|
|
10
|
+
* its half left or, once undone, restored. Any other edit to either leaf moves it off that
|
|
11
|
+
* document and the pairing lapses. */
|
|
12
|
+
let pair;
|
|
13
|
+
/** Whether the transaction that produced a state was a history step. */
|
|
14
|
+
const stepped = new PluginKey('qmDragMove');
|
|
15
|
+
/** The other half follows a history step over one half. */
|
|
16
|
+
function follow(view, prev) {
|
|
17
|
+
const held = pair;
|
|
18
|
+
if (!held || !stepped.getState(view.state) || view.state.doc === prev.doc)
|
|
19
|
+
return;
|
|
20
|
+
const other = view === held.a && prev.doc === held.aDoc
|
|
21
|
+
? { view: held.b, doc: held.bDoc }
|
|
22
|
+
: view === held.b && prev.doc === held.bDoc
|
|
23
|
+
? { view: held.a, doc: held.aDoc }
|
|
24
|
+
: undefined;
|
|
25
|
+
if (!other)
|
|
26
|
+
return;
|
|
27
|
+
// Cleared first: the step below lands in this function again, on the other leaf.
|
|
28
|
+
pair = undefined;
|
|
29
|
+
if (other.view.isDestroyed || other.view.state.doc !== other.doc)
|
|
30
|
+
return;
|
|
31
|
+
if (!(held.undone ? redo : undo)(other.view.state, other.view.dispatch))
|
|
32
|
+
return;
|
|
33
|
+
pair = {
|
|
34
|
+
a: held.a,
|
|
35
|
+
aDoc: held.a.state.doc,
|
|
36
|
+
b: held.b,
|
|
37
|
+
bDoc: held.b.state.doc,
|
|
38
|
+
undone: !held.undone
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/** One character of a line, an inline node reading as none of the characters below. */
|
|
42
|
+
const charAt = (doc, from, to) => from < to ? doc.textBetween(from, to, '', '\ufffc') : '';
|
|
43
|
+
/** What may follow a word with no space between: the end of the line, a space, or
|
|
44
|
+
* punctuation that closes. */
|
|
45
|
+
const closesWord = (c) => c === '' || c === ' ' || /[.,;:!?)\]}'"”’]/.test(c);
|
|
46
|
+
/**
|
|
47
|
+
* Whether the text from `from` to `to` is whole words standing between spaces or a line's
|
|
48
|
+
* ends, which a word processor's smart cut closes the gap behind.
|
|
49
|
+
*/
|
|
50
|
+
function wholeWords(doc, from, to) {
|
|
51
|
+
const $from = doc.resolve(from);
|
|
52
|
+
const $to = doc.resolve(to);
|
|
53
|
+
if (!$from.sameParent($to) || !$from.parent.inlineContent || from === to)
|
|
54
|
+
return false;
|
|
55
|
+
const text = charAt(doc, from, to);
|
|
56
|
+
if (text.startsWith(' ') || text.endsWith(' '))
|
|
57
|
+
return false;
|
|
58
|
+
const before = charAt(doc, Math.max($from.start(), from - 1), from);
|
|
59
|
+
return ((before === '' || before === ' ') && closesWord(charAt(doc, to, Math.min($to.end(), to + 1))));
|
|
60
|
+
}
|
|
61
|
+
/** Close the gap whole words left at `pos`: the space before it goes where another space,
|
|
62
|
+
* closing punctuation or the line's end follows, and the space after it where the line
|
|
63
|
+
* starts there. */
|
|
64
|
+
function closeGap(tr, pos) {
|
|
65
|
+
const $pos = tr.doc.resolve(pos);
|
|
66
|
+
const before = charAt(tr.doc, Math.max($pos.start(), pos - 1), pos);
|
|
67
|
+
const after = charAt(tr.doc, pos, Math.min($pos.end(), pos + 1));
|
|
68
|
+
if (before === ' ' && closesWord(after))
|
|
69
|
+
tr.delete(pos - 1, pos);
|
|
70
|
+
else if (before === '' && after === ' ')
|
|
71
|
+
tr.delete(pos, pos + 1);
|
|
72
|
+
}
|
|
73
|
+
/** ProseMirror's own modifier for a drag that copies. */
|
|
74
|
+
const copies = (event) => /Mac|iP(hone|[oa]d)/.test(typeof navigator === 'undefined' ? '' : navigator.platform)
|
|
75
|
+
? event.altKey
|
|
76
|
+
: event.ctrlKey;
|
|
77
|
+
/**
|
|
78
|
+
* Deletes what a drag took from its own leaf when a different leaf accepts the drop. The
|
|
79
|
+
* receiving view parses the drop through its own schema, as it does a paste, and the
|
|
80
|
+
* delete follows only a drop that changed it, so text a leaf refused stays where it was.
|
|
81
|
+
* The copy modifier keeps the source, as it does inside one view, and a read-only source
|
|
82
|
+
* keeps it always. `owner` is the view whose history holds this view's edits, where that
|
|
83
|
+
* is not the view itself.
|
|
84
|
+
*/
|
|
85
|
+
export function dragMovePlugin(owner) {
|
|
86
|
+
return new Plugin({
|
|
87
|
+
key: owner ? undefined : stepped,
|
|
88
|
+
state: {
|
|
89
|
+
init: () => false,
|
|
90
|
+
apply: (tr) => isHistoryTransaction(tr)
|
|
91
|
+
},
|
|
92
|
+
view: () => ({ update: follow }),
|
|
93
|
+
props: {
|
|
94
|
+
handleDOMEvents: {
|
|
95
|
+
dragstart(view) {
|
|
96
|
+
if (owner)
|
|
97
|
+
owners.set(view, owner);
|
|
98
|
+
source = view;
|
|
99
|
+
return false;
|
|
100
|
+
},
|
|
101
|
+
dragend(view) {
|
|
102
|
+
if (source === view)
|
|
103
|
+
source = undefined;
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
handleDrop(view, event, _slice, moved) {
|
|
108
|
+
const from = source;
|
|
109
|
+
const dragging = from?.dragging;
|
|
110
|
+
if (moved || !from || from === view || !dragging || !from.editable || copies(event))
|
|
111
|
+
return false;
|
|
112
|
+
const before = view.state.doc;
|
|
113
|
+
// After the drop this handler is part of: the default inserts synchronously.
|
|
114
|
+
queueMicrotask(() => {
|
|
115
|
+
if (from.isDestroyed || view.isDestroyed || view.state.doc === before)
|
|
116
|
+
return;
|
|
117
|
+
const tr = from.state.tr;
|
|
118
|
+
const { from: start, to: end } = from.state.selection;
|
|
119
|
+
if (dragging.node)
|
|
120
|
+
dragging.node.replace(tr);
|
|
121
|
+
else {
|
|
122
|
+
const words = wholeWords(tr.doc, start, end);
|
|
123
|
+
tr.deleteSelection();
|
|
124
|
+
if (words)
|
|
125
|
+
closeGap(tr, tr.mapping.map(start));
|
|
126
|
+
}
|
|
127
|
+
if (!tr.docChanged)
|
|
128
|
+
return;
|
|
129
|
+
const a = owners.get(from)?.() ?? from;
|
|
130
|
+
const b = owner?.() ?? view;
|
|
131
|
+
// One history holds both halves: the delete joins the drop's step.
|
|
132
|
+
if (a === b)
|
|
133
|
+
joinStep(() => from.dispatch(tr));
|
|
134
|
+
else
|
|
135
|
+
from.dispatch(tr);
|
|
136
|
+
pair =
|
|
137
|
+
a === b ? undefined : { a, aDoc: a.state.doc, b, bDoc: b.state.doc, undone: false };
|
|
138
|
+
});
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
@@ -196,7 +196,12 @@ function emitText(acc, s, pmStart, marks) {
|
|
|
196
196
|
for (const mark of marks)
|
|
197
197
|
acc.rawMarks.push({ start: at, end: acc.text.length, ...contentDescriptorFromPM(mark) });
|
|
198
198
|
}
|
|
199
|
-
/**
|
|
199
|
+
/**
|
|
200
|
+
* Merge adjacent/overlapping same-descriptor marks into maximal ranges, in the store's
|
|
201
|
+
* canonical order: by range, then by descriptor. A write takes a `Content` in that order
|
|
202
|
+
* alone, and PM hands a character's marks in its schema's, so two marks over one range
|
|
203
|
+
* leave here ordered by what they are rather than by which the schema ranks first.
|
|
204
|
+
*/
|
|
200
205
|
function mergeMarks(raw) {
|
|
201
206
|
const groups = new Map();
|
|
202
207
|
for (const m of raw) {
|
|
@@ -208,7 +213,7 @@ function mergeMarks(raw) {
|
|
|
208
213
|
g.intervals.push({ start, end });
|
|
209
214
|
}
|
|
210
215
|
const out = [];
|
|
211
|
-
for (const g of groups
|
|
216
|
+
for (const [key, g] of groups) {
|
|
212
217
|
const sorted = [...g.intervals].sort((a, b) => a.start - b.start);
|
|
213
218
|
let cur = null;
|
|
214
219
|
for (const iv of sorted) {
|
|
@@ -216,14 +221,18 @@ function mergeMarks(raw) {
|
|
|
216
221
|
cur.end = Math.max(cur.end, iv.end);
|
|
217
222
|
else {
|
|
218
223
|
if (cur)
|
|
219
|
-
out.push({ ...cur, ...g.descriptor });
|
|
224
|
+
out.push({ key, mark: { ...cur, ...g.descriptor } });
|
|
220
225
|
cur = { ...iv };
|
|
221
226
|
}
|
|
222
227
|
}
|
|
223
228
|
if (cur)
|
|
224
|
-
out.push({ ...cur, ...g.descriptor });
|
|
229
|
+
out.push({ key, mark: { ...cur, ...g.descriptor } });
|
|
225
230
|
}
|
|
226
|
-
return out
|
|
231
|
+
return out
|
|
232
|
+
.sort((a, b) => a.mark.start - b.mark.start ||
|
|
233
|
+
a.mark.end - b.mark.end ||
|
|
234
|
+
(a.key < b.key ? -1 : a.key > b.key ? 1 : 0))
|
|
235
|
+
.map((o) => o.mark);
|
|
227
236
|
}
|
|
228
237
|
// ── Lowering ────────────────────────────────────────────────────────────────
|
|
229
238
|
/**
|
|
@@ -5,6 +5,8 @@ import type { Document, Content, Addr, Quill } from '@quillmark/wasm';
|
|
|
5
5
|
import type { EditorErrorHandler } from '../errors.js';
|
|
6
6
|
import { type Delta } from './positions.js';
|
|
7
7
|
import { type TextCap } from './cap.js';
|
|
8
|
+
import { type LeaveStrings } from './leave.js';
|
|
9
|
+
import { type ReviewAction, type ReviewReport, type ReviewStrings, type ReviewVia, type TextReview } from './review.js';
|
|
8
10
|
import { type TableChromeStrings } from './table-view.js';
|
|
9
11
|
import { type SlashState, type SlashStrings } from './slash.js';
|
|
10
12
|
/** Options for {@link createField}. */
|
|
@@ -25,6 +27,9 @@ export interface CreateFieldOpts {
|
|
|
25
27
|
/** The id of the note the caller draws inside `container` for a held leaf →
|
|
26
28
|
* `aria-describedby` while it holds. */
|
|
27
29
|
heldNoteId?: string;
|
|
30
|
+
/** The id of the tag the caller draws for a leaf holding its unwritten default →
|
|
31
|
+
* `aria-describedby` while it does. */
|
|
32
|
+
defaultNoteId?: string;
|
|
28
33
|
/**
|
|
29
34
|
* Fired when the leaf holds or releases, and at mount when it mounts held. A one-line or `text`
|
|
30
35
|
* leaf is held over a value its schema cannot hold (`fitsLeaf`): the decode would join lines
|
|
@@ -50,6 +55,8 @@ export interface CreateFieldOpts {
|
|
|
50
55
|
onSlash?(state: SlashState | undefined): void;
|
|
51
56
|
/** The slash surface's wording, read per decoration pass; read only beside {@link onSlash}. */
|
|
52
57
|
slashStrings?: () => SlashStrings;
|
|
58
|
+
/** The way out's wording, read as it is drawn (`leave.ts`). Absent leaves the package's English. */
|
|
59
|
+
leaveStrings?: () => LeaveStrings;
|
|
53
60
|
/**
|
|
54
61
|
* Accessible name → `aria-label` on the `contenteditable`, for a leaf nothing else names (an
|
|
55
62
|
* array element, the card body). A leaf with a field label takes `labelledBy` instead: `for`
|
|
@@ -80,6 +87,24 @@ export interface CreateFieldOpts {
|
|
|
80
87
|
/** An edit leaving the leaf empty removes the field: an optional cell (`t?`), whose
|
|
81
88
|
* unanswered `none` is what the empty leaf draws and an empty answer would hide. */
|
|
82
89
|
emptyUnsets?: boolean;
|
|
90
|
+
/** The review layer's wording, read per decoration pass (`review.ts`). */
|
|
91
|
+
reviewStrings?: () => ReviewStrings;
|
|
92
|
+
/** The review item whose card is up, and the reader's Escape lowering it. */
|
|
93
|
+
reviewShown?: () => string | undefined;
|
|
94
|
+
onReviewDismiss?(): void;
|
|
95
|
+
/** A reader answered the review item `id`: a proposal's button or its chord, or the chord
|
|
96
|
+
* that takes a change back, `chord` where a key gave it. A proposal taken is written by
|
|
97
|
+
* then. */
|
|
98
|
+
onReview?(id: string, action: ReviewAction, chord?: boolean): void;
|
|
99
|
+
/** The leaf is writing a taken proposal, and is done: the commit between is the answer's. */
|
|
100
|
+
onReviewWriting?(on: boolean): void;
|
|
101
|
+
/** The review item under the pointer or holding the caret, `undefined` once it has left.
|
|
102
|
+
* The caret's report holds off while the reader types inside the item. */
|
|
103
|
+
onReviewPoint?(id: string | undefined, via: ReviewVia): void;
|
|
104
|
+
/** What the leaf draws of the review items, on each change: the ids drawn, and the items
|
|
105
|
+
* whose anchor the leaf holds that it does not draw, each with why. An item whose anchor
|
|
106
|
+
* the leaf does not hold is in neither. */
|
|
107
|
+
onReviewDrawn?(report: ReviewReport): void;
|
|
83
108
|
onFocus?(addr: Addr): void;
|
|
84
109
|
/** Fired with the new caret offset after an edit or a selection move. */
|
|
85
110
|
onCaretMove?(addr: Addr, pos: number): void;
|
|
@@ -127,6 +152,24 @@ export interface FieldController {
|
|
|
127
152
|
insertAnchor(id: string, pos: number, end?: number): void;
|
|
128
153
|
/** Remove the identity anchor `id` (the inverse of {@link insertAnchor}); a no-op if absent. */
|
|
129
154
|
removeAnchor(id: string): void;
|
|
155
|
+
/**
|
|
156
|
+
* Draw `items` over the leaf, the one named `lit` a step stronger (`review.ts`): each by an
|
|
157
|
+
* anchor the leaf holds, in the leaf's own flow, with nothing written to the document. A
|
|
158
|
+
* `text` leaf holds no anchors and draws none.
|
|
159
|
+
*/
|
|
160
|
+
setReview(items: readonly TextReview[], lit?: string): void;
|
|
161
|
+
/** The elements the review item `id` draws, in document order; `[]` for one not drawn. */
|
|
162
|
+
reviewElements(id: string): HTMLElement[];
|
|
163
|
+
/** Put the caret in the review item `id` and focus the leaf; false for one not drawn. */
|
|
164
|
+
enterReview(id: string): boolean;
|
|
165
|
+
/** Answer the review item `id` as its button would, moving neither the caret nor the
|
|
166
|
+
* focus; false for one not drawn, or a proposal that can no longer be written. */
|
|
167
|
+
answerReview(id: string, action: ReviewAction): boolean;
|
|
168
|
+
/** Open the review item `id` this leaf dismissed again, reported as `reopen`, whether or
|
|
169
|
+
* not the host still lists it. */
|
|
170
|
+
reopenReview(id: string): void;
|
|
171
|
+
/** Undo the leaf's newest step, a taken proposal's, reported as `reopen`. */
|
|
172
|
+
undoReview(): boolean;
|
|
130
173
|
/** Ids of the anchors touching content range `[from, to]`: a selection's anchor state. */
|
|
131
174
|
anchorsInRange(from: number, to: number): string[];
|
|
132
175
|
/**
|
|
@@ -184,7 +227,8 @@ export declare function createField(opts: CreateFieldOpts): FieldController;
|
|
|
184
227
|
* `ProseValue` so the two never fork the plugin ordering. History first with the step-splitting
|
|
185
228
|
* plugin (`undo.ts`), then `afterHistory` plugins (the addressed leaf's anchor plugin), {@link
|
|
186
229
|
* linebreakPlugin}, the markdown-shorthand input rules and their Backspace, the field keymap over
|
|
187
|
-
* the base keymap, the URL paste that links a selection (`link-paste.ts`),
|
|
230
|
+
* the base keymap, the URL paste that links a selection (`link-paste.ts`), the drag that moves
|
|
231
|
+
* between leaves (`drag-move.ts`), and last the block
|
|
188
232
|
* leaf's own shapes: the gap cursor, {@link pastAtomPlugin}, the island paste (`islands.ts`), table
|
|
189
233
|
* paste (`table-paste.ts`), markdown paste (`markdown-paste.ts`) and the task checkbox
|
|
190
234
|
* (`tasks.ts`). A one-line leaf's paste joins its lines (`line-paste.ts`).
|
|
@@ -198,6 +242,8 @@ export declare function proseLeafPlugins(schema: Schema, opts: {
|
|
|
198
242
|
slash?: (state: SlashState | undefined) => void;
|
|
199
243
|
/** The empty line's hint, read live; drawn only beside `slash`. */
|
|
200
244
|
slashHint?: () => string | undefined;
|
|
245
|
+
/** The way out's wording, read live (`leave.ts`); the package's English without it. */
|
|
246
|
+
leaveStrings?: () => LeaveStrings;
|
|
201
247
|
noInputRules?: boolean;
|
|
202
248
|
/** Read live: the ghost can move after mount and a re-hydration rebuilds this stack. */
|
|
203
249
|
placeholder?: () => string | undefined;
|