@quillmark/svelte 0.43.0 → 0.44.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/CUSTOMIZING.md +78 -0
- package/README.md +96 -17
- package/THEMING.md +2 -0
- package/dist/core/codec/table-view.js +1 -1
- package/dist/core/index.js +1 -5
- package/dist/core/lifecycle.js +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +5 -3
- package/dist/preview/index.d.ts +3 -0
- package/dist/preview/index.js +4 -2
- package/dist/preview/strings.js +1 -1
- package/dist/visual/diagnostics.d.ts +1 -1
- package/dist/visual/index.js +4 -5
- package/dist/workspace/index.d.ts +5 -0
- package/dist/workspace/index.js +7 -0
- package/dist/workspace/print.d.ts +13 -0
- package/dist/workspace/print.js +67 -0
- package/dist/workspace/trap.d.ts +8 -0
- package/dist/workspace/trap.js +20 -0
- package/dist/workspace/workspace.d.ts +107 -0
- package/dist/workspace/workspace.js +346 -0
- package/package.json +2 -11
package/CUSTOMIZING.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# Customizing
|
|
2
|
+
|
|
3
|
+
What you can change about Quillmark's editor, preview and the quillkit app without forking any of it, and what is closed on purpose. The CSS detail is [THEMING.md](THEMING.md); this page says which depth a change belongs to and where each depth stops.
|
|
4
|
+
|
|
5
|
+
## The three depths
|
|
6
|
+
|
|
7
|
+
Start at the shallowest one that holds your change.
|
|
8
|
+
|
|
9
|
+
| | You write | You can change |
|
|
10
|
+
| ------------------------------- | ---------------------------------- | ----------------------------------------------------------------------- |
|
|
11
|
+
| **Configure the quillkit app** | files beside your quiver, no code | the app's name, icon and look |
|
|
12
|
+
| **Theme and word the surfaces** | props and CSS in your own page | how `<VisualEditor>` and `<Preview>` look and what they say |
|
|
13
|
+
| **Write your own shell** | a Svelte file on `createWorkspace` | what the page does: its actions, its storage, where documents come from |
|
|
14
|
+
|
|
15
|
+
### Configure the quillkit app
|
|
16
|
+
|
|
17
|
+
`quillkit build app` turns a quiver into a standalone app for the people filling its forms in. You configure it with files found by name beside `Quiver.yaml`, all optional ([quillkit's README](../quillkit/README.md#the-app)):
|
|
18
|
+
|
|
19
|
+
| File | What it sets |
|
|
20
|
+
| ------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------- |
|
|
21
|
+
| `App.yaml` | `title` and `description` |
|
|
22
|
+
| `icon.svg` or `icon.png` | the icon in the header and on the tab |
|
|
23
|
+
| `app.css` | the look: the `--qm-*` dials, the surface roots, the app chrome classes and `[data-qm-card="<kind>"]`, linked after the app's own styles |
|
|
24
|
+
|
|
25
|
+
Which forms appear is whatever the quiver holds: every quill in it, at its latest version, drafts only under `--drafts`. A different set of forms is a different quiver.
|
|
26
|
+
|
|
27
|
+
`check` and `build app` refuse an `App.yaml` key the app does not have and warn on an `app.css` selector the theming contract does not promise, so a key or a selector a release moves fails or warns where you build rather than going quiet.
|
|
28
|
+
|
|
29
|
+
### Theme and word the surfaces
|
|
30
|
+
|
|
31
|
+
In a page of your own you mount `<VisualEditor>` and `<Preview>` yourself and reach everything below.
|
|
32
|
+
|
|
33
|
+
| Handle | What it changes |
|
|
34
|
+
| --------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
35
|
+
| the ten `--qm-*` dials | colour, type, corner and spacing across both surfaces ([THEMING §"The dials"](THEMING.md#the-dials)) |
|
|
36
|
+
| `color-scheme` | light or dark, read off your page or set on one mount with `style` ([THEMING §"The surface follows your colour scheme"](THEMING.md#the-surface-follows-your-colour-scheme)) |
|
|
37
|
+
| `.qm-editor`, `.qm-preview`, `.qm-pane` | placing and sizing each surface from your own stylesheet; `class` and `style` props land on the same root |
|
|
38
|
+
| `[data-qm-card="<kind>"]` | the cards of one kind, `main` for the main card ([THEMING §"What a stylesheet may aim at"](THEMING.md#what-a-stylesheet-may-aim-at)) |
|
|
39
|
+
| `strings`, on each surface | every word it says, keyed and partial, the value-inserting ones included ([README §Wording](README.md#wording)) |
|
|
40
|
+
| `formatDiagnostic` | the text of a validation or edit diagnostic under its field |
|
|
41
|
+
| `enumOptionAllowed`, `enumDisallowed` | which options of an enum a deployment offers, and whether a refused one is hidden or greyed |
|
|
42
|
+
| `fonts`, `fontLabels` | the font families the format popover offers, and the names it shows them by ([README §Fonts](README.md#fonts)) |
|
|
43
|
+
| the quill's `ui` hints | layout from the schema: `ui.compact` to share a row, `ui.layout: table` for an array, `ui.blank_title` for an enum's blank |
|
|
44
|
+
| `review` | another writer's proposals, drawn where each sits and answered on the page ([README §Review](README.md#review)) |
|
|
45
|
+
|
|
46
|
+
### Write your own shell
|
|
47
|
+
|
|
48
|
+
Any change of behaviour, rather than of look or wording, is a shell of your own: a submit button, saving to your server, sign-in, a document opened prefilled. `createWorkspace` is the glue between the two surfaces packaged, so the shell is a short file of your wiring that takes each npm release as it comes rather than a copy of ours that drifts ([README §"A shell on the workspace"](README.md#a-shell-on-the-workspace)). The quillkit app is one such shell.
|
|
49
|
+
|
|
50
|
+
The shell holds the `Document`, so where it comes from and where it goes is yours: parse it from markdown your server sends, seed it from the quill, write it back on every `onChange` or on a press. Storage, choosing the quill, switching documents, the review list and collaboration are the shell's.
|
|
51
|
+
|
|
52
|
+
## What is closed, and why
|
|
53
|
+
|
|
54
|
+
Closed means no prop, promised class or file reaches it. Each is closed for the reason beside it.
|
|
55
|
+
|
|
56
|
+
| Closed | Why |
|
|
57
|
+
| -------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
58
|
+
| the DOM and classes inside a surface | a class contract over the interior would freeze the DOM the surfaces are free to re-cut; the dials and the root classes already reach what a restyle wants |
|
|
59
|
+
| the control drawn for each field type | per-control render slots are declined: they would hand reconciliation to your code |
|
|
60
|
+
| what the slash menu and the format popover offer | the slash menu offers the constructs the caret can make, each asked whether it would fire there, and its pointer door is declined; the format popover's buttons are fixed and the fonts it offers are yours (`fonts`) |
|
|
61
|
+
| the icons | a closed set drawn against one frame, so no glyph strokes differently from its neighbours; a glyph takes its control's colour, which the dials reach |
|
|
62
|
+
| keyboard shortcuts | each binding and the shortcut list are read off one table, so a list and a key cannot drift; `editorShortcuts()` and `REVIEW_KEYS` read them, and nothing rebinds them |
|
|
63
|
+
| the undo model | undo is per prose field and per list, never one stack for the document, and a removed card has its own step back |
|
|
64
|
+
| image authoring | declined: there is no asset story |
|
|
65
|
+
| touch-first editing | declined: touch is not a target, and neither is an accessory bar |
|
|
66
|
+
| in the quillkit app: where documents are stored | in this browser only, one database per app, and the app says so; a server is a shell's |
|
|
67
|
+
| in the quillkit app: the actions offered | `App.yaml` holds what the app says, not what it does: keys that compose into behaviour are a program, and a program belongs in a real language, the custom shell |
|
|
68
|
+
| in the quillkit app: the layout | where the app puts its parts is its client's; `app.css` restyles the chrome through the promised classes, and anything past them is warned, since a release may re-cut it |
|
|
69
|
+
| in the quillkit app: the version a new document opens on | the latest the quiver holds, at `0.1.0` or above unless built with `--drafts`; a document reopens on the version it was made on and offers an update, so a release never moves a half-filled form under its reader |
|
|
70
|
+
| in the quillkit app: the wording and the language | English and fixed: plain text in `App.yaml` cannot set a string that inserts a value, so a translation there stays part English; a shell sets every string through `strings` |
|
|
71
|
+
|
|
72
|
+
The reasons are recorded with the designs they rejected in [this package's INVARIANTS](prose/INVARIANTS.md) and [quillkit's](../quillkit/prose/INVARIANTS.md). Each package's exported names are held against a committed snapshot, `api.json`, which `check:api` compares on every build of this repository, so nothing becomes open or closed by an export appearing, vanishing or moving between entries without a reviewed diff.
|
|
73
|
+
|
|
74
|
+
## When something you need is missing
|
|
75
|
+
|
|
76
|
+
A dial appears when a real consumer needs one, and every dial is one more thing a reader has to hold. So before forking, [open an issue](https://github.com/birdorbs/quillmark-js/issues) describing what you are building and what stopped you: the need, not the patch.
|
|
77
|
+
|
|
78
|
+
Meanwhile the supported escape route is a custom shell on the published packages, not a fork: a shell takes each release as an npm update, where a fork takes one only by a merge.
|
package/README.md
CHANGED
|
@@ -12,17 +12,17 @@ npm install @quillmark/svelte
|
|
|
12
12
|
|
|
13
13
|
`svelte@^5.33` and `@quillmark/wasm` are peer dependencies: the session's handles cross the package boundary, so the consumer supplies the one copy both sides mint them from.
|
|
14
14
|
|
|
15
|
-
##
|
|
15
|
+
## Entries
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
A page imports from the root. `/preview` imports less where less is the point, and the preset is a stylesheet.
|
|
18
18
|
|
|
19
|
-
| Import |
|
|
20
|
-
| --------------------------- |
|
|
21
|
-
| `@quillmark/svelte
|
|
22
|
-
| `@quillmark/svelte/preview` |
|
|
23
|
-
| `@quillmark/svelte/
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
| Import | What it is |
|
|
20
|
+
| --------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
21
|
+
| `@quillmark/svelte` | Everything a page mounts: `<VisualEditor>`, `<Preview>` and `createPreview`, review and wording, `init`, the `DocPath`/`Place` address vocabulary and `EditorError` channel the surfaces share, and `createWorkspace` with `beginPrint` for a shell. |
|
|
22
|
+
| `@quillmark/svelte/preview` | `createPreview` and `<Preview>`, with `init` and the shared address and error types, for a page that only displays a document. It reaches nothing editor-side, so the page ships no ProseMirror. |
|
|
23
|
+
| `@quillmark/svelte/preset` | The opt-in stylesheet for the page around a surface ([THEMING.md](THEMING.md)). |
|
|
24
|
+
|
|
25
|
+
Code with no page, a worker or a plain Node server, mounts no surface, so it imports `init` from `@quillmark/wasm` directly: this package's entries reach the surfaces' stylesheets. Tree-shaking the root is no substitute for `/preview`: the package is `sideEffects: true`, since its components import stylesheets, so a bundler keeps what the root reaches.
|
|
26
26
|
|
|
27
27
|
## Open a session
|
|
28
28
|
|
|
@@ -30,7 +30,7 @@ The **consumer** owns the session and the handles, and drives every edit; the su
|
|
|
30
30
|
|
|
31
31
|
```ts
|
|
32
32
|
import { Engine } from '@quillmark/wasm';
|
|
33
|
-
import { init } from '@quillmark/svelte
|
|
33
|
+
import { init } from '@quillmark/svelte';
|
|
34
34
|
|
|
35
35
|
// Quill and Document are exported only through init().
|
|
36
36
|
const { Quill, Document } = await init();
|
|
@@ -50,6 +50,81 @@ const session = await new Engine().open(quill, doc);
|
|
|
50
50
|
|
|
51
51
|
`<VisualEditor>` needs no session, and the first `open` loads the render build, so a host that mounts the editor over `doc` and `quill` first shows it without waiting on that load. The session opens behind it: `await engine.load(quill)`, then `engine.open(quill, doc)`, so its first compile reads what was typed meanwhile ([INVARIANTS.md](prose/INVARIANTS.md#hosting)).
|
|
52
52
|
|
|
53
|
+
## A shell on the workspace
|
|
54
|
+
|
|
55
|
+
`createWorkspace` is the glue a shell over the two surfaces writes, packaged as one opt-in policy: it opens the session behind the editor, compiles each edit (a structure op at once, prose and field edits once 120 ms pass without another), merges the diagnostics for the editor, compiles an open review's projection for the preview ([Review](#review)), bridges the caret both ways, latches a backend trap, and tears down in order. The surfaces keep their own contracts under it, and a shell that wants another policy wires them itself ([Recompiling](#recompiling), [The caret bridge](#the-caret-bridge)). One workspace is one document, and it frees only the session it opened. This is the whole of a shell:
|
|
56
|
+
|
|
57
|
+
```svelte
|
|
58
|
+
<script lang="ts">
|
|
59
|
+
import { onDestroy, tick, untrack } from 'svelte';
|
|
60
|
+
import type { Document, Engine, Quill } from '@quillmark/wasm';
|
|
61
|
+
import { createWorkspace, Preview, VisualEditor } from '@quillmark/svelte';
|
|
62
|
+
|
|
63
|
+
interface Props {
|
|
64
|
+
engine: Engine | Promise<Engine>;
|
|
65
|
+
quill: Quill;
|
|
66
|
+
/** Handed over: the shell frees it once the workspace has freed its session. */
|
|
67
|
+
doc: Document;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const { engine, quill, doc }: Props = $props();
|
|
71
|
+
|
|
72
|
+
let editor = $state.raw<ReturnType<typeof VisualEditor>>();
|
|
73
|
+
let preview = $state.raw<ReturnType<typeof Preview>>();
|
|
74
|
+
|
|
75
|
+
// One workspace per document: a parent swaps documents with `{#key doc}`.
|
|
76
|
+
const ws = untrack(() =>
|
|
77
|
+
createWorkspace({
|
|
78
|
+
engine,
|
|
79
|
+
quill,
|
|
80
|
+
doc,
|
|
81
|
+
editor: () => editor,
|
|
82
|
+
preview: () => preview,
|
|
83
|
+
onState: (next) => (now = next)
|
|
84
|
+
})
|
|
85
|
+
);
|
|
86
|
+
let now = $state.raw(ws.state);
|
|
87
|
+
|
|
88
|
+
onDestroy(() => void ws.dispose(tick).then(() => doc.free()));
|
|
89
|
+
|
|
90
|
+
async function download(): Promise<void> {
|
|
91
|
+
const file = await ws.render('pdf');
|
|
92
|
+
if (!file) return;
|
|
93
|
+
const a = document.createElement('a');
|
|
94
|
+
a.href = URL.createObjectURL(new Blob([file.bytes as BlobPart], { type: file.mimeType }));
|
|
95
|
+
a.download = 'document.pdf';
|
|
96
|
+
a.click();
|
|
97
|
+
URL.revokeObjectURL(a.href);
|
|
98
|
+
}
|
|
99
|
+
</script>
|
|
100
|
+
|
|
101
|
+
<button type="button" onclick={download}>Download PDF</button>
|
|
102
|
+
{#if now.status === 'refused'}
|
|
103
|
+
<p role="alert">{now.refused[0]?.message}</p>
|
|
104
|
+
{/if}
|
|
105
|
+
<VisualEditor bind:this={editor} {doc} {quill} diagnostics={now.diagnostics} {...ws.editor} />
|
|
106
|
+
{#if now.session}
|
|
107
|
+
<Preview bind:this={preview} session={now.session} {...ws.preview} />
|
|
108
|
+
{/if}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
A host that opens several documents keys this shell on the document and guards its own open with a counter, so a load that lands after a later one frees its document rather than mounting it.
|
|
112
|
+
|
|
113
|
+
`ws.editor` and `ws.preview` are handler objects: spread them, or call one from a handler of the shell's own, as one that also saves each edit does with `onChange={(change) => { save(); ws.editor.onChange(change); }}`. The surfaces are read through getters because a preview mounts only once a session stands, so its ref arrives late. `onState` hands over a new `state` on every change: the `session` to mount the preview over, `diagnostics` for the editor, `formats` the backend emits, `review`, which is `none`, `shown` (the preview compiles the open review's projection) or `failed` (the projection did not compile, so the preview shows the document), and `status`, which is `opening`, `ready`, `refused` (the engine refused the last open or compile with `refused`; a session that stands still paints its last good compile, and the next edit after a refused open opens again), `paint-failed` (until the next edit) or `trapped`. `diagnostics` takes the shell's own as a getter, merged once each at every compile.
|
|
114
|
+
|
|
115
|
+
`trapped` is terminal: the render build trapped (`runtime::backend_trapped`), so its state is undefined, the session is dropped for the preview to unmount and then freed, and nothing compiles or opens again until the page reloads; editing continues, on the core build. The render build is one per process, so a workspace created after a trap starts `trapped`, and `backendTrapped()` says whether one has happened.
|
|
116
|
+
|
|
117
|
+
`ws.wrote(structural)` is the door for a write the shell made to the document itself: `true` compiles at once, as a card operation does, and otherwise the compile debounces as a keystroke's. `ws.flush()` runs a pending compile now and resolves once the page is current, for a shell that marks the page. `ws.render(format)` compiles a pending edit, waits on the open, and resolves `undefined` where the document does not compile, so a download is the document in hand, never a proposal the reader has not accepted, even while the preview shows one. `ws.doc` and `ws.quill` are the handles the editor mounts over. `ws.dispose(unmounted)` hands `onState` a state with no session, awaits `unmounted` so the surfaces go first, then frees the session. `beginPrint()`, called on the press itself so a fallback tab is not a blocked popup, prints the PDF once it is rendered:
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
const printing = beginPrint();
|
|
121
|
+
const pdf = await ws.render('pdf');
|
|
122
|
+
if (!pdf) printing.cancel();
|
|
123
|
+
else if (!printing.print(pdf.bytes)) refusal = 'This browser blocked printing.';
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Storage, choosing the quill, switching documents, the review list and collaboration stay the shell's.
|
|
127
|
+
|
|
53
128
|
## The quill resolves from the document
|
|
54
129
|
|
|
55
130
|
A stored document carries none of its quill's bytes, only a reference: `doc.quillRef` is `name@version`, persisted in the markdown itself. Resolution is **host code**: read the ref, map it to a `Quill`, open. No surface resolves, so one resolution per document holds by construction.
|
|
@@ -75,7 +150,7 @@ What stays yours is the text edge and the ref. The markdown is the host's at bot
|
|
|
75
150
|
`createPreview` supplies the layer the session omits: viewport, DOM, DPR, click mapping. It is a pure view: it never calls `session.apply`; you drive the edit and hand it the resulting `ChangeSet`.
|
|
76
151
|
|
|
77
152
|
```ts
|
|
78
|
-
import { createPreview } from '@quillmark/svelte
|
|
153
|
+
import { createPreview } from '@quillmark/svelte';
|
|
79
154
|
|
|
80
155
|
const preview = createPreview(session, {
|
|
81
156
|
container: document.querySelector('#preview')!,
|
|
@@ -101,7 +176,7 @@ In Svelte, `<Preview {session} onPick={…} />` exposes the same verbs (`refresh
|
|
|
101
176
|
|
|
102
177
|
```svelte
|
|
103
178
|
<script lang="ts">
|
|
104
|
-
import { VisualEditor } from '@quillmark/svelte
|
|
179
|
+
import { VisualEditor } from '@quillmark/svelte';
|
|
105
180
|
</script>
|
|
106
181
|
|
|
107
182
|
<VisualEditor
|
|
@@ -198,7 +273,7 @@ type ReviewItem =
|
|
|
198
273
|
- **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.
|
|
199
274
|
- **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 struck 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.
|
|
200
275
|
|
|
201
|
-
`proposalsBetween(quill, base, answer)`, from `@quillmark/svelte
|
|
276
|
+
`proposalsBetween(quill, base, answer)`, from `@quillmark/svelte`, 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. An item names its card one of two ways. `card` beside a `field`, `card` on a removal and `afterCard` on an added card name it by its `$id`, wherever it stands when the item is drawn, and `proposalsBetween` fills them in for every card of `base` that has one: the list holds over a live document whose cards were added, removed or moved since the snapshot. Without one, the path's index, `remove` and `after` name the card by index, read against the cards as they stood when the list was set, and a card added, removed or moved between the snapshot and then is not carried. Either way the editor keeps each item on its card through every card added, removed or moved while the list stands, by `applyCardOps`, by the reader or by an accepted card item. An item whose card is gone goes `undrawn` as `field`, a removal whose card is gone as `applied`, and a card added after one that is gone stands last.
|
|
202
277
|
|
|
203
278
|
```ts
|
|
204
279
|
const base = doc.clone(); // when the assistant is asked
|
|
@@ -229,6 +304,8 @@ The host sets the list once and clears it once. It sets it when an answer arrive
|
|
|
229
304
|
|
|
230
305
|
The verbs complete it. `answerReview(ids | 'all' | { group }, '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'` or `{ group }` 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 `{ group }` passes over every item of another group), 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.
|
|
231
306
|
|
|
307
|
+
While items are open, a preview shows the page as it would read with every open proposal taken, compiled from a copy and never from the document: `projectReview(copy)` writes each one into a clone the host hands in, as its Accept would, and returns `{ ids, toProjection, toLive }`, the proposals written and the map between the document's places and the copy's. The host compiles the copy for its preview alone and frees it, falls back to the document where the copy does not compile, compiles again on each `onReviewDrawn` whose `open` changed, and routes both bridge hops through the map, a pick on a card or paragraph only the copy holds naming the item that adds it for `revealReview`. Everything that saves, shares or prints reads the document. [The workspace](#a-shell-on-the-workspace) does all of this for a shell built on it.
|
|
308
|
+
|
|
232
309
|
The **answer card** floats on the current item, below the paragraph or block it stands in, beside that paragraph's last line where the line ends short of it, centred on the line of a one-line field so it stands inside the field rather than over the next field's label, or above it where there is no room, so it covers none of the item's own paragraph, with **Dismiss** and **Accept** and their keys, and the item's `note` above them on one line. 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, or on a screen with no hover, it drops the key hints and its buttons are tap-sized.
|
|
233
310
|
|
|
234
311
|
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+⌥/Alt+Backspace dismisses it, and ⌘/Ctrl+⌥/Alt+↓ and ↑ step to the next and previous item, moving the caret along when pressed in the editor. The two answer keys are the card's, so they answer an item the card stands on in view: with the item scrolled out of the pane, or the card aside while the reader types, the first press brings it back and the next answers it. No leaf binds a review key: ⌘/Ctrl+Enter is the review's alone, and Alt+Enter ticks a task item, takes a sibling from a list element of several lines and leaves a code block. 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)).
|
|
@@ -274,7 +351,7 @@ const engine = new Engine({ fonts: [carlito] });
|
|
|
274
351
|
|
|
275
352
|
### Recompiling
|
|
276
353
|
|
|
277
|
-
`onChange` is the signal to recompile, and it covers **all three lanes**: a prose keystroke, a scalar write, a card operation. `onCaretMove` is a _selection_ signal, not a change signal: it fires on a bare arrow key, so a recompile hung off it recompiles on every one.
|
|
354
|
+
`createWorkspace` is the packaged form of what follows ([A shell on the workspace](#a-shell-on-the-workspace)). `onChange` is the signal to recompile, and it covers **all three lanes**: a prose keystroke, a scalar write, a card operation. `onCaretMove` is a _selection_ signal, not a change signal: it fires on a bare arrow key, so a recompile hung off it recompiles on every one.
|
|
278
355
|
|
|
279
356
|
```ts
|
|
280
357
|
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
@@ -300,11 +377,11 @@ function recompileNow() {
|
|
|
300
377
|
|
|
301
378
|
`session.warnings` is a **getter on a handle Svelte does not track**: pull it per apply, or the editor shows the previous compile's errors.
|
|
302
379
|
|
|
303
|
-
The schedule is host policy,
|
|
380
|
+
The surfaces ship no scheduler: the schedule is host policy, and [the workspace](#a-shell-on-the-workspace) is one such policy, packaged. A host wiring the surfaces itself keeps three obligations: an edit of your own (an import, an undo, a direct `doc` write) recompiles by the same calls, since nothing polls the document; a compile re-reads the diagnostics; and teardown clears the timer **before** freeing the handles.
|
|
304
381
|
|
|
305
382
|
## The caret bridge
|
|
306
383
|
|
|
307
|
-
The bridge lives at the **consumer** layer and is opt-in; the editor is unaware of the preview, the preview unaware of the editor.
|
|
384
|
+
`createWorkspace` wires both directions as `ws.editor` and `ws.preview`, through the review projection's map while one is shown ([A shell on the workspace](#a-shell-on-the-workspace), [Review](#review)). The bridge lives at the **consumer** layer and is opt-in; the editor is unaware of the preview, the preview unaware of the editor. With no review projection shown, both hops are pass-throughs: the two surfaces already speak one address grammar, the canonical `DocPath`.
|
|
308
385
|
|
|
309
386
|
```ts
|
|
310
387
|
// preview → editor: a click resolved to an address lands in the field it names.
|
|
@@ -320,7 +397,7 @@ Both editor→preview hops or neither. A control reports its focus and no caret
|
|
|
320
397
|
|
|
321
398
|
A pick carries a caret where the compile tracks the content under the point, and the field alone where it tracks only the placement — a scalar the plate prints without tracking. `setCaret` takes both: an absent `pos` reveals and focuses the field, which is the whole of what a click on plate-placed ink can mean. The address may name an array element (`main.keywords[0]`), which lands on that row.
|
|
322
399
|
|
|
323
|
-
A consumer holding an `Addr` of its own maps it with the Document's `pathFor`. The playground
|
|
400
|
+
A consumer holding an `Addr` of its own maps it with the Document's `pathFor`. The playground's split-pane route takes both directions from the workspace, through a review projection and under a collaboration room; its landing page mounts the surfaces on their own verbs, with no workspace under them.
|
|
324
401
|
|
|
325
402
|
## Errors
|
|
326
403
|
|
|
@@ -349,6 +426,8 @@ el.textContent = doc.toMarkdown();
|
|
|
349
426
|
|
|
350
427
|
The surfaces carry the behavior against a neutral, overridable visual baseline: a set of `--qm-*` CSS custom properties you override on any ancestor. See [`THEMING.md`](THEMING.md).
|
|
351
428
|
|
|
429
|
+
What you can change without forking, at each depth from configuring the quillkit app to a shell of your own, and what is closed and why: [`CUSTOMIZING.md`](CUSTOMIZING.md).
|
|
430
|
+
|
|
352
431
|
## Development
|
|
353
432
|
|
|
354
433
|
This package is one workspace of [`quillmark-js`](../..); the gates are the root's, and the rules a change must keep live in [`prose/INVARIANTS.md`](prose/INVARIANTS.md).
|
package/THEMING.md
CHANGED
|
@@ -10,6 +10,8 @@ There are three depths to that. An app mounting into an unstyled page stops at t
|
|
|
10
10
|
| **Make it yours** | ten custom properties | the whole surface rescaled and recolored to your brand |
|
|
11
11
|
| **Match ours** | one CSS import | the page around the surface, drawn the way we draw ours |
|
|
12
12
|
|
|
13
|
+
Theming is one part of what you can change without forking: [CUSTOMIZING.md](CUSTOMIZING.md) maps the rest, and what is closed.
|
|
14
|
+
|
|
13
15
|
## Drop it in
|
|
14
16
|
|
|
15
17
|
```svelte
|
|
@@ -51,7 +51,7 @@ export const DEFAULT_TABLE_STRINGS = {
|
|
|
51
51
|
};
|
|
52
52
|
/**
|
|
53
53
|
* The grip's glyph as path data: this chrome's own set, since it is built without Svelte and
|
|
54
|
-
*
|
|
54
|
+
* `core/` reaches no surface module. Same 24×24 frame as `visual/icons/nodes.ts`, off an earlier
|
|
55
55
|
* release; `NOTICE` carries both notices. The dots are zero-length strokes under a round cap.
|
|
56
56
|
*/
|
|
57
57
|
const GRIP = {
|
package/dist/core/index.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
//
|
|
1
|
+
// What this package owns at the substrate seam, which the root re-exports.
|
|
2
2
|
//
|
|
3
3
|
// The `@quillmark/wasm` API is not re-exported: import it from the peer dependency. What earns a
|
|
4
4
|
// line here is what more than one surface speaks and no other package declares: the address
|
|
5
5
|
// vocabulary, the error channel, and the WASM init gate.
|
|
6
|
-
//
|
|
7
|
-
// No stylesheet: a host reaches this entry where there is no document (a worker, a server), and a
|
|
8
|
-
// dev server serves a side-effect sheet as a module that writes a `<style>` into one. The surface
|
|
9
|
-
// barrels carry the theme; `check:deps` holds it.
|
|
10
6
|
export { init } from './lifecycle.js';
|
package/dist/core/lifecycle.js
CHANGED
|
@@ -30,7 +30,7 @@ export function init() {
|
|
|
30
30
|
*/
|
|
31
31
|
export function core() {
|
|
32
32
|
if (!latched) {
|
|
33
|
-
throw new Error('@quillmark/svelte: the WASM core is not initialized. Await `init()` from `@quillmark/svelte
|
|
33
|
+
throw new Error('@quillmark/svelte: the WASM core is not initialized. Await `init()` from `@quillmark/svelte` before mounting a surface or calling a boundary verb.');
|
|
34
34
|
}
|
|
35
35
|
return latched;
|
|
36
36
|
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
// `@quillmark/svelte
|
|
2
|
-
//
|
|
3
|
-
// wants one import for the substrate.
|
|
1
|
+
// `@quillmark/svelte`: everything a page mounts. `init` here latches the surface for the
|
|
2
|
+
// package's synchronous internals; code that mounts no surface calls `@quillmark/wasm`'s directly.
|
|
4
3
|
export * from './core/index.js';
|
|
4
|
+
export * from './visual/index.js';
|
|
5
|
+
export * from './preview/index.js';
|
|
6
|
+
export * from './workspace/index.js';
|
package/dist/preview/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
export { init } from '../core/lifecycle.js';
|
|
2
|
+
export type { DocPath, Landing, Place } from '../core/address.js';
|
|
3
|
+
export type { EditorError, EditorErrorCode, EditorErrorHandler } from '../core/errors.js';
|
|
1
4
|
export { createPreview } from './controller.js';
|
|
2
5
|
export type { PreviewOptions, PreviewController } from './controller.js';
|
|
3
6
|
export { default as Preview } from './Preview.svelte';
|
package/dist/preview/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// `@quillmark/svelte/preview`: the live-preview surface. Imports no editor-side code; it may reach
|
|
2
|
-
//
|
|
2
|
+
// modules in `core/` and nothing else (`check:deps`).
|
|
3
3
|
// The theme derivation the page slots read through `var()`; a subpath import reaches `core/`
|
|
4
|
-
// modules, never its
|
|
4
|
+
// modules, never its barrel, which carries no sheet.
|
|
5
5
|
import '../core/theme.css';
|
|
6
|
+
// What a preview-only page needs beside the surface, so it opens a session without the root.
|
|
7
|
+
export { init } from '../core/lifecycle.js';
|
|
6
8
|
export { createPreview } from './controller.js';
|
|
7
9
|
export { default as Preview } from './Preview.svelte';
|
package/dist/preview/strings.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Separate from the visual surface's strings: `/preview` reaches
|
|
1
|
+
// Separate from the visual surface's strings: `/preview` reaches `core/` and nothing editor-side.
|
|
2
2
|
/** The package's English. */
|
|
3
3
|
export const DEFAULT_PREVIEW_STRINGS = {
|
|
4
4
|
renderFailed: 'Preview failed to render.',
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Diagnostic, PathStep } from '@quillmark/wasm';
|
|
2
|
-
/** A field's routing address, and
|
|
2
|
+
/** A field's routing address, and `core/`'s `Addr` structurally: an `Addr` is a
|
|
3
3
|
* positional `FieldKey`, so `nearestAddrForFieldPath` is the path→key walk and
|
|
4
4
|
* routing carries no second copy of the grammar. `card` is `undefined` for the main
|
|
5
5
|
* card; a composable card slot is a stable session id (the editor's own bookkeeping)
|
package/dist/visual/index.js
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
//
|
|
1
|
+
// The WYSIWYG surface, which the root entry re-exports.
|
|
2
2
|
//
|
|
3
3
|
// The federated VisualEditor: a thin Svelte composition over many small editors.
|
|
4
4
|
// Each content leaf is the codec's prose leaf; scalar fields are form controls;
|
|
5
|
-
// structure/cards are the editor's own. Depends on
|
|
5
|
+
// structure/cards are the editor's own. Depends on `core/` and the
|
|
6
6
|
// codec. Relative imports (not `$lib`): svelte-package ships this as-is.
|
|
7
7
|
//
|
|
8
8
|
// The barrel carries what a consumer story wants, and nothing else: a symbol
|
|
9
9
|
// earns its line when a caller outside the package needs it, and grows one when
|
|
10
10
|
// that caller arrives, not before.
|
|
11
11
|
// The theme derivation, which every control on this surface reads through `var()`.
|
|
12
|
-
// Imported at the barrel because
|
|
13
|
-
// reaches modules inside `core/` and never its
|
|
14
|
-
// `check:deps` holds the reach.
|
|
12
|
+
// Imported at the barrel because an entry is what a consumer gets: this surface
|
|
13
|
+
// reaches modules inside `core/` and never its barrel, which carries no sheet.
|
|
15
14
|
import '../core/theme.css';
|
|
16
15
|
export { default as VisualEditor } from './VisualEditor.svelte';
|
|
17
16
|
// The prose leaf's shortcuts, for a host's shortcut list: read off the keymaps' own tables and
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { createWorkspace } from './workspace.js';
|
|
2
|
+
export { backendTrapped } from './trap.js';
|
|
3
|
+
export type { Workspace, WorkspaceEditor, WorkspaceOptions, WorkspacePreview, WorkspaceState, WorkspaceStatus } from './workspace.js';
|
|
4
|
+
export { beginPrint } from './print.js';
|
|
5
|
+
export type { Printing } from './print.js';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// The workspace: one document's session, recompile, diagnostics, review projection and caret
|
|
2
|
+
// bridge over the two surfaces, an opt-in layer the root re-exports. Neither surface imports it
|
|
3
|
+
// (`check:deps`).
|
|
4
|
+
export { createWorkspace } from './workspace.js';
|
|
5
|
+
export { backendTrapped } from './trap.js';
|
|
6
|
+
// The browser door a shell prints a file through.
|
|
7
|
+
export { beginPrint } from './print.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** A print begun on a press, finished once the PDF is in hand. */
|
|
2
|
+
export interface Printing {
|
|
3
|
+
/** Print `pdf`. Returns false where the browser refused every way in. */
|
|
4
|
+
print(pdf: Uint8Array): boolean;
|
|
5
|
+
/** Drop a print that has nothing to print. */
|
|
6
|
+
cancel(): void;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Begin a print on the press itself, then hand the PDF to `print` once it is rendered, or call
|
|
10
|
+
* `cancel` where there is none. The tab a fallback prints from is opened here, while the press
|
|
11
|
+
* still counts as one, since a tab opened after the render's await is a popup the browser blocks.
|
|
12
|
+
*/
|
|
13
|
+
export declare function beginPrint(): Printing;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether this browser prints a PDF from a hidden frame. A browser without an inline PDF
|
|
3
|
+
* viewer (every phone) has nothing to print there, and Safari's frame prints blank or the
|
|
4
|
+
* page around it, so both are handed a tab of the PDF instead, printed from its viewer.
|
|
5
|
+
*/
|
|
6
|
+
function framePrints() {
|
|
7
|
+
if (navigator.pdfViewerEnabled === false)
|
|
8
|
+
return false;
|
|
9
|
+
const ua = navigator.userAgent;
|
|
10
|
+
return !(/AppleWebKit\//.test(ua) && !/(Chrome|Chromium)\//.test(ua));
|
|
11
|
+
}
|
|
12
|
+
/** The frame the last print loaded. A frame's print returns before its viewer is done
|
|
13
|
+
* with the PDF, so a frame stands until the next print replaces it. */
|
|
14
|
+
let frame;
|
|
15
|
+
function blobOf(pdf) {
|
|
16
|
+
// `BlobPart` takes an `ArrayBuffer`-backed view; wasm output is one.
|
|
17
|
+
return URL.createObjectURL(new Blob([pdf], { type: 'application/pdf' }));
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Begin a print on the press itself, then hand the PDF to `print` once it is rendered, or call
|
|
21
|
+
* `cancel` where there is none. The tab a fallback prints from is opened here, while the press
|
|
22
|
+
* still counts as one, since a tab opened after the render's await is a popup the browser blocks.
|
|
23
|
+
*/
|
|
24
|
+
export function beginPrint() {
|
|
25
|
+
const tab = framePrints() ? null : window.open('', '_blank');
|
|
26
|
+
const viaTab = (pdf) => {
|
|
27
|
+
const target = tab ?? window.open('', '_blank');
|
|
28
|
+
if (!target)
|
|
29
|
+
return false;
|
|
30
|
+
// Not revoked: the tab's viewer can read the URL again for as long as it stands.
|
|
31
|
+
target.location.href = blobOf(pdf);
|
|
32
|
+
return true;
|
|
33
|
+
};
|
|
34
|
+
return {
|
|
35
|
+
print(pdf) {
|
|
36
|
+
if (!framePrints())
|
|
37
|
+
return viaTab(pdf);
|
|
38
|
+
if (frame) {
|
|
39
|
+
frame.el.remove();
|
|
40
|
+
URL.revokeObjectURL(frame.url);
|
|
41
|
+
}
|
|
42
|
+
const url = blobOf(pdf);
|
|
43
|
+
const el = document.createElement('iframe');
|
|
44
|
+
el.setAttribute('aria-hidden', 'true');
|
|
45
|
+
el.tabIndex = -1;
|
|
46
|
+
// Laid out and off screen: a frame under `display: none` loads no viewer to print.
|
|
47
|
+
el.style.cssText =
|
|
48
|
+
'position:fixed;inset-inline-start:-10000px;top:0;width:1px;height:1px;border:0';
|
|
49
|
+
el.addEventListener('load', () => {
|
|
50
|
+
try {
|
|
51
|
+
el.contentWindow?.focus();
|
|
52
|
+
el.contentWindow?.print();
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
viaTab(pdf);
|
|
56
|
+
}
|
|
57
|
+
}, { once: true });
|
|
58
|
+
el.src = url;
|
|
59
|
+
document.body.append(el);
|
|
60
|
+
frame = { el, url };
|
|
61
|
+
return true;
|
|
62
|
+
},
|
|
63
|
+
cancel() {
|
|
64
|
+
tab?.close();
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const TRAPPED = "runtime::backend_trapped";
|
|
2
|
+
/** Whether the render build has trapped in this process: its state is undefined from then, so
|
|
3
|
+
* nothing compiles, opens or paints on it again until the page reloads. */
|
|
4
|
+
export declare function backendTrapped(): boolean;
|
|
5
|
+
/** Whether `err` is the engine's trap. */
|
|
6
|
+
export declare function isBackendTrap(err: unknown): boolean;
|
|
7
|
+
export declare function latch(): void;
|
|
8
|
+
export declare function unlatch(): void;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// The render build is one instance per process, so a trap in it is one latch for every
|
|
2
|
+
// workspace in the process. `unlatch` is the tests' door and is not exported from the root.
|
|
3
|
+
import { isQuillmarkError } from '@quillmark/wasm';
|
|
4
|
+
export const TRAPPED = 'runtime::backend_trapped';
|
|
5
|
+
let latched = false;
|
|
6
|
+
/** Whether the render build has trapped in this process: its state is undefined from then, so
|
|
7
|
+
* nothing compiles, opens or paints on it again until the page reloads. */
|
|
8
|
+
export function backendTrapped() {
|
|
9
|
+
return latched;
|
|
10
|
+
}
|
|
11
|
+
/** Whether `err` is the engine's trap. */
|
|
12
|
+
export function isBackendTrap(err) {
|
|
13
|
+
return isQuillmarkError(err) && err.diagnostics.some((d) => d.code === TRAPPED);
|
|
14
|
+
}
|
|
15
|
+
export function latch() {
|
|
16
|
+
latched = true;
|
|
17
|
+
}
|
|
18
|
+
export function unlatch() {
|
|
19
|
+
latched = false;
|
|
20
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { type Artifact, type ChangeSet, type Diagnostic, type Document, type Engine, type LiveSession, type OutputFormat, type Quill } from '@quillmark/wasm';
|
|
2
|
+
import type { Landing, Place } from '../core/address.js';
|
|
3
|
+
import { type EditorError } from '../core/errors.js';
|
|
4
|
+
import type { ReviewDrawn, ReviewProjection } from '../visual/review.js';
|
|
5
|
+
import type { ActiveLeaf, EditorChange } from '../visual/signals.js';
|
|
6
|
+
/** The editor verbs the workspace calls: a mounted `<VisualEditor>` carries them. */
|
|
7
|
+
export interface WorkspaceEditor {
|
|
8
|
+
setCaret(at: Landing): unknown;
|
|
9
|
+
/** Writes the open review into a copy for the preview to compile. Without it, the preview
|
|
10
|
+
* compiles the document whatever the review holds. */
|
|
11
|
+
projectReview?(target: Document): ReviewProjection;
|
|
12
|
+
/** Brings a review item to the reader, for a pick on what only the projection holds. */
|
|
13
|
+
revealReview?(id: string): unknown;
|
|
14
|
+
}
|
|
15
|
+
/** The preview verbs the workspace calls: a mounted `<Preview>` and a `PreviewController` carry
|
|
16
|
+
* them. */
|
|
17
|
+
export interface WorkspacePreview {
|
|
18
|
+
refresh(change: ChangeSet): void;
|
|
19
|
+
focusPosition(at: Place): void;
|
|
20
|
+
endFollow(): void;
|
|
21
|
+
}
|
|
22
|
+
export interface WorkspaceOptions {
|
|
23
|
+
/** The engine the session opens on. A promise is awaited by the open, so the editor need not
|
|
24
|
+
* wait on it. */
|
|
25
|
+
engine: Engine | Promise<Engine>;
|
|
26
|
+
/** Borrowed: the workspace frees neither the quill nor the document. */
|
|
27
|
+
quill: Quill;
|
|
28
|
+
doc: Document;
|
|
29
|
+
/** The mounted editor, or `undefined` while none is. */
|
|
30
|
+
editor: () => WorkspaceEditor | undefined;
|
|
31
|
+
/** The mounted preview, or `undefined` while none is: a preview mounts once a session
|
|
32
|
+
* stands. */
|
|
33
|
+
preview: () => WorkspacePreview | undefined;
|
|
34
|
+
/** The host's own diagnostics, merged into {@link WorkspaceState.diagnostics} at each state
|
|
35
|
+
* change. Re-read on the next one, so a host whose list changes outside an edit calls
|
|
36
|
+
* `wrote(true)`. */
|
|
37
|
+
diagnostics?: () => readonly Diagnostic[];
|
|
38
|
+
/** Called with the new state on every change. Not called at creation: read `state` then. */
|
|
39
|
+
onState?: (state: WorkspaceState) => void;
|
|
40
|
+
}
|
|
41
|
+
export type WorkspaceStatus =
|
|
42
|
+
/** No session yet: the open is in flight. */
|
|
43
|
+
'opening'
|
|
44
|
+
/** The session stands and the last compile took the document. */
|
|
45
|
+
| 'ready'
|
|
46
|
+
/** The engine refused the last open or compile; `refused` says with what. A session that
|
|
47
|
+
* stands still paints its last good compile. */
|
|
48
|
+
| 'refused'
|
|
49
|
+
/** The preview could not paint a page, until the next edit. */
|
|
50
|
+
| 'paint-failed'
|
|
51
|
+
/** The render build trapped, in this workspace or another in the process: there is no session
|
|
52
|
+
* and nothing compiles again until the page reloads. Editing continues. */
|
|
53
|
+
| 'trapped';
|
|
54
|
+
export interface WorkspaceState {
|
|
55
|
+
/** The session this workspace opened, until it is disposed. Mount the preview over it. */
|
|
56
|
+
session: LiveSession | undefined;
|
|
57
|
+
status: WorkspaceStatus;
|
|
58
|
+
/** Every producer's diagnostics, deduplicated, for the editor's `diagnostics` prop: what was
|
|
59
|
+
* refused, the schema's verdict, the compile's warnings, then the host's own. */
|
|
60
|
+
diagnostics: Diagnostic[];
|
|
61
|
+
/** What the engine refused the last open or compile with; empty while it compiles. */
|
|
62
|
+
refused: Diagnostic[];
|
|
63
|
+
/** What the quill's backend emits, once the engine is in hand. */
|
|
64
|
+
formats: OutputFormat[];
|
|
65
|
+
/** What the preview shows of the editor's open review: `none` open, the projection with every
|
|
66
|
+
* open proposal taken (`shown`), or the document because the projection did not compile
|
|
67
|
+
* (`failed`). */
|
|
68
|
+
review: 'none' | 'shown' | 'failed';
|
|
69
|
+
}
|
|
70
|
+
export interface Workspace {
|
|
71
|
+
readonly state: WorkspaceState;
|
|
72
|
+
/** What the editor mounts over: the options' own handles. */
|
|
73
|
+
readonly quill: Quill;
|
|
74
|
+
readonly doc: Document;
|
|
75
|
+
/** Handlers for `<VisualEditor>`, to spread onto it or call from the host's own. */
|
|
76
|
+
readonly editor: {
|
|
77
|
+
readonly onChange: (change: EditorChange) => void;
|
|
78
|
+
readonly onCaretMove: (at: Place) => void;
|
|
79
|
+
readonly onActiveLeafChange: (active?: ActiveLeaf) => void;
|
|
80
|
+
readonly onReviewDrawn: (drawn: ReviewDrawn) => void;
|
|
81
|
+
};
|
|
82
|
+
/** Handlers for `<Preview>`, to spread onto it or call from the host's own. */
|
|
83
|
+
readonly preview: {
|
|
84
|
+
readonly onPick: (at: Landing) => void;
|
|
85
|
+
readonly onError: (err: EditorError) => void;
|
|
86
|
+
};
|
|
87
|
+
/** The host wrote to the document itself: `structural` compiles at once, as a card operation
|
|
88
|
+
* does, and otherwise the compile debounces as a keystroke's. */
|
|
89
|
+
wrote(structural?: boolean): void;
|
|
90
|
+
/** Run the pending compile now; with none pending, nothing. Resolves once the page is
|
|
91
|
+
* current, the open in flight included. */
|
|
92
|
+
flush(): Promise<void>;
|
|
93
|
+
/**
|
|
94
|
+
* The document in hand as a file, never an unaccepted proposal, once the pending compile has
|
|
95
|
+
* run and the open in flight landed. `undefined` where the document does not compile, which
|
|
96
|
+
* `state` says why, or the workspace is disposed or trapped. A render the engine refuses
|
|
97
|
+
* throws.
|
|
98
|
+
*/
|
|
99
|
+
render(format: OutputFormat): Promise<Artifact | undefined>;
|
|
100
|
+
/**
|
|
101
|
+
* Cancel the pending compile, hand `onState` a state with no session, await `unmounted` so the
|
|
102
|
+
* host's surfaces go first, then free the session this workspace opened. Every call after is a
|
|
103
|
+
* no-op.
|
|
104
|
+
*/
|
|
105
|
+
dispose(unmounted?: () => Promise<void>): Promise<void>;
|
|
106
|
+
}
|
|
107
|
+
export declare function createWorkspace(opts: WorkspaceOptions): Workspace;
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
// The glue every shell over the two surfaces writes, packaged as one opt-in policy over one
|
|
2
|
+
// document. Framework-free: the surfaces are reached through getters, and the host renders
|
|
3
|
+
// from the state it is handed.
|
|
4
|
+
import { isQuillmarkError } from '@quillmark/wasm';
|
|
5
|
+
import { errorMessage, reportError } from '../core/errors.js';
|
|
6
|
+
import { backendTrapped, isBackendTrap, latch } from './trap.js';
|
|
7
|
+
const SETTLE_MS = 120;
|
|
8
|
+
/** What makes two diagnostics the same one: one message at two lines of a plate is two. */
|
|
9
|
+
const keyOf = (d) => [
|
|
10
|
+
d.severity,
|
|
11
|
+
d.code ?? '',
|
|
12
|
+
d.path ?? '',
|
|
13
|
+
d.location ? `${d.location.file}:${d.location.line}:${d.location.column}` : '',
|
|
14
|
+
d.message
|
|
15
|
+
].join(' ');
|
|
16
|
+
function merge(sources) {
|
|
17
|
+
const seen = new Map();
|
|
18
|
+
for (const diags of sources)
|
|
19
|
+
for (const diag of diags) {
|
|
20
|
+
const k = keyOf(diag);
|
|
21
|
+
if (!seen.has(k))
|
|
22
|
+
seen.set(k, diag);
|
|
23
|
+
}
|
|
24
|
+
return [...seen.values()];
|
|
25
|
+
}
|
|
26
|
+
function diagnosticsOf(err) {
|
|
27
|
+
if (isQuillmarkError(err) && err.diagnostics.length > 0)
|
|
28
|
+
return err.diagnostics;
|
|
29
|
+
return [{ severity: 'error', message: errorMessage(err) }];
|
|
30
|
+
}
|
|
31
|
+
function freeQuietly(session) {
|
|
32
|
+
try {
|
|
33
|
+
session?.free();
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
// A trapped build may refuse the free; the reload reclaims it.
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const SAME = { ids: [], toProjection: (at) => at, toLive: (at) => at };
|
|
40
|
+
export function createWorkspace(opts) {
|
|
41
|
+
const { quill, doc } = opts;
|
|
42
|
+
let session;
|
|
43
|
+
let refused = [];
|
|
44
|
+
let formats = [];
|
|
45
|
+
let paintFailed = false;
|
|
46
|
+
let trapped = backendTrapped();
|
|
47
|
+
let disposed = false;
|
|
48
|
+
let timer;
|
|
49
|
+
let opening;
|
|
50
|
+
/** Whether an edit landed after the open in flight read the document. */
|
|
51
|
+
let behind = false;
|
|
52
|
+
/** The open review items as one key, so a report that changes none compiles nothing. */
|
|
53
|
+
let reviewing = '';
|
|
54
|
+
/** The map between the document's places and those of what the session last compiled. */
|
|
55
|
+
let projection = SAME;
|
|
56
|
+
let review = 'none';
|
|
57
|
+
const warnings = () => (session?.warnings ?? []).flatMap((d) => {
|
|
58
|
+
if (!d.path)
|
|
59
|
+
return [d];
|
|
60
|
+
const path = projection.toLive(d.path);
|
|
61
|
+
return typeof path === 'string' ? [{ ...d, path }] : [];
|
|
62
|
+
});
|
|
63
|
+
const snapshot = () => ({
|
|
64
|
+
session,
|
|
65
|
+
status: trapped
|
|
66
|
+
? 'trapped'
|
|
67
|
+
: refused.length
|
|
68
|
+
? 'refused'
|
|
69
|
+
: paintFailed
|
|
70
|
+
? 'paint-failed'
|
|
71
|
+
: session
|
|
72
|
+
? 'ready'
|
|
73
|
+
: 'opening',
|
|
74
|
+
diagnostics: merge([refused, quill.validate(doc), warnings(), opts.diagnostics?.() ?? []]),
|
|
75
|
+
refused,
|
|
76
|
+
formats,
|
|
77
|
+
review
|
|
78
|
+
});
|
|
79
|
+
let state = snapshot();
|
|
80
|
+
function emit() {
|
|
81
|
+
state = snapshot();
|
|
82
|
+
opts.onState?.(state);
|
|
83
|
+
}
|
|
84
|
+
function stop() {
|
|
85
|
+
clearTimeout(timer);
|
|
86
|
+
timer = undefined;
|
|
87
|
+
}
|
|
88
|
+
/** The render build is gone: drop the session for the surfaces to unmount, then free it. */
|
|
89
|
+
function trap(err) {
|
|
90
|
+
if (trapped)
|
|
91
|
+
return;
|
|
92
|
+
latch();
|
|
93
|
+
trapped = true;
|
|
94
|
+
stop();
|
|
95
|
+
if (err !== undefined)
|
|
96
|
+
console.error('[quillmark/ui] the render build trapped', err);
|
|
97
|
+
const lost = session;
|
|
98
|
+
session = undefined;
|
|
99
|
+
refused = [];
|
|
100
|
+
paintFailed = false;
|
|
101
|
+
projection = SAME;
|
|
102
|
+
review = 'none';
|
|
103
|
+
if (!disposed)
|
|
104
|
+
emit();
|
|
105
|
+
setTimeout(() => freeQuietly(lost), 0);
|
|
106
|
+
}
|
|
107
|
+
/** Whether this workspace is trapped, taking up a trap another one in the process latched. */
|
|
108
|
+
function struck() {
|
|
109
|
+
if (!trapped && backendTrapped())
|
|
110
|
+
trap();
|
|
111
|
+
return trapped;
|
|
112
|
+
}
|
|
113
|
+
function open() {
|
|
114
|
+
behind = false;
|
|
115
|
+
const run = (async () => {
|
|
116
|
+
try {
|
|
117
|
+
const engine = await opts.engine;
|
|
118
|
+
formats = await engine.supportedFormats(quill);
|
|
119
|
+
if (struck())
|
|
120
|
+
return;
|
|
121
|
+
const opened = await engine.open(quill, doc);
|
|
122
|
+
if (disposed || struck())
|
|
123
|
+
return freeQuietly(opened);
|
|
124
|
+
session = opened;
|
|
125
|
+
refused = [];
|
|
126
|
+
}
|
|
127
|
+
catch (err) {
|
|
128
|
+
if (disposed)
|
|
129
|
+
return;
|
|
130
|
+
if (isBackendTrap(err))
|
|
131
|
+
return trap(err);
|
|
132
|
+
refused = diagnosticsOf(err);
|
|
133
|
+
}
|
|
134
|
+
finally {
|
|
135
|
+
opening = undefined;
|
|
136
|
+
}
|
|
137
|
+
if (behind || (reviewing && opts.editor()?.projectReview))
|
|
138
|
+
return compile();
|
|
139
|
+
emit();
|
|
140
|
+
})();
|
|
141
|
+
opening = run;
|
|
142
|
+
return run;
|
|
143
|
+
}
|
|
144
|
+
/** Compile the open review into a copy of the document, freed in every path. */
|
|
145
|
+
function project(live) {
|
|
146
|
+
const editor = opts.editor();
|
|
147
|
+
if (!editor?.projectReview)
|
|
148
|
+
return 'none';
|
|
149
|
+
const copy = doc.clone();
|
|
150
|
+
let change;
|
|
151
|
+
try {
|
|
152
|
+
const projected = editor.projectReview(copy);
|
|
153
|
+
if (!projected.ids.length)
|
|
154
|
+
return 'none';
|
|
155
|
+
change = live.update(copy);
|
|
156
|
+
projection = projected;
|
|
157
|
+
}
|
|
158
|
+
catch (err) {
|
|
159
|
+
if (!isBackendTrap(err))
|
|
160
|
+
return 'failed';
|
|
161
|
+
trap(err);
|
|
162
|
+
return 'trapped';
|
|
163
|
+
}
|
|
164
|
+
finally {
|
|
165
|
+
copy.free();
|
|
166
|
+
}
|
|
167
|
+
review = 'shown';
|
|
168
|
+
refused = [];
|
|
169
|
+
opts.preview()?.refresh(change);
|
|
170
|
+
emit();
|
|
171
|
+
return 'shown';
|
|
172
|
+
}
|
|
173
|
+
function compile() {
|
|
174
|
+
stop();
|
|
175
|
+
if (disposed || struck())
|
|
176
|
+
return Promise.resolve();
|
|
177
|
+
if (!session) {
|
|
178
|
+
if (!opening)
|
|
179
|
+
return open();
|
|
180
|
+
behind = true;
|
|
181
|
+
return opening;
|
|
182
|
+
}
|
|
183
|
+
const projected = reviewing ? project(session) : 'none';
|
|
184
|
+
if (projected === 'shown' || projected === 'trapped')
|
|
185
|
+
return Promise.resolve();
|
|
186
|
+
projection = SAME;
|
|
187
|
+
review = projected;
|
|
188
|
+
let change;
|
|
189
|
+
try {
|
|
190
|
+
change = session.update(doc);
|
|
191
|
+
refused = [];
|
|
192
|
+
}
|
|
193
|
+
catch (err) {
|
|
194
|
+
if (isBackendTrap(err)) {
|
|
195
|
+
trap(err);
|
|
196
|
+
return Promise.resolve();
|
|
197
|
+
}
|
|
198
|
+
refused = diagnosticsOf(err);
|
|
199
|
+
}
|
|
200
|
+
if (change)
|
|
201
|
+
opts.preview()?.refresh(change);
|
|
202
|
+
emit();
|
|
203
|
+
return Promise.resolve();
|
|
204
|
+
}
|
|
205
|
+
function wrote(structural = false) {
|
|
206
|
+
if (disposed || trapped)
|
|
207
|
+
return;
|
|
208
|
+
if (paintFailed) {
|
|
209
|
+
paintFailed = false;
|
|
210
|
+
emit();
|
|
211
|
+
}
|
|
212
|
+
if (structural)
|
|
213
|
+
void compile();
|
|
214
|
+
else {
|
|
215
|
+
clearTimeout(timer);
|
|
216
|
+
timer = setTimeout(() => void compile(), SETTLE_MS);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
async function flush() {
|
|
220
|
+
if (timer !== undefined)
|
|
221
|
+
await compile();
|
|
222
|
+
await opening;
|
|
223
|
+
}
|
|
224
|
+
function renderOf(live, format) {
|
|
225
|
+
let artifact;
|
|
226
|
+
try {
|
|
227
|
+
[artifact] = live.render({ format }).artifacts;
|
|
228
|
+
}
|
|
229
|
+
catch (err) {
|
|
230
|
+
if (!isBackendTrap(err))
|
|
231
|
+
throw err;
|
|
232
|
+
trap(err);
|
|
233
|
+
return undefined;
|
|
234
|
+
}
|
|
235
|
+
if (!artifact)
|
|
236
|
+
throw new Error(`the ${quill.backendId} backend emitted no ${format}`);
|
|
237
|
+
return artifact;
|
|
238
|
+
}
|
|
239
|
+
/** The session holds the projection: compile the document for the file, then the projection
|
|
240
|
+
* again for the preview. A document that does not compile leaves the projection painted. */
|
|
241
|
+
function renderDocument(live, format) {
|
|
242
|
+
try {
|
|
243
|
+
live.update(doc);
|
|
244
|
+
}
|
|
245
|
+
catch (err) {
|
|
246
|
+
if (isBackendTrap(err))
|
|
247
|
+
trap(err);
|
|
248
|
+
else {
|
|
249
|
+
refused = diagnosticsOf(err);
|
|
250
|
+
emit();
|
|
251
|
+
}
|
|
252
|
+
return undefined;
|
|
253
|
+
}
|
|
254
|
+
try {
|
|
255
|
+
return renderOf(live, format);
|
|
256
|
+
}
|
|
257
|
+
finally {
|
|
258
|
+
void compile();
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
if (!trapped)
|
|
262
|
+
void open();
|
|
263
|
+
return {
|
|
264
|
+
get state() {
|
|
265
|
+
return state;
|
|
266
|
+
},
|
|
267
|
+
quill,
|
|
268
|
+
doc,
|
|
269
|
+
editor: {
|
|
270
|
+
onChange(change) {
|
|
271
|
+
wrote(change.source === 'structure');
|
|
272
|
+
},
|
|
273
|
+
onCaretMove(at) {
|
|
274
|
+
if (disposed)
|
|
275
|
+
return;
|
|
276
|
+
const shown = projection.toProjection(at);
|
|
277
|
+
if (shown)
|
|
278
|
+
opts.preview()?.focusPosition(shown);
|
|
279
|
+
},
|
|
280
|
+
onActiveLeafChange() {
|
|
281
|
+
if (!disposed)
|
|
282
|
+
opts.preview()?.endFollow();
|
|
283
|
+
},
|
|
284
|
+
onReviewDrawn(drawn) {
|
|
285
|
+
const key = drawn.open.join('\n');
|
|
286
|
+
if (disposed || key === reviewing)
|
|
287
|
+
return;
|
|
288
|
+
reviewing = key;
|
|
289
|
+
if (opts.editor()?.projectReview || review !== 'none')
|
|
290
|
+
void compile();
|
|
291
|
+
}
|
|
292
|
+
},
|
|
293
|
+
preview: {
|
|
294
|
+
onPick(at) {
|
|
295
|
+
if (disposed)
|
|
296
|
+
return;
|
|
297
|
+
const editor = opts.editor();
|
|
298
|
+
const live = projection.toLive(at);
|
|
299
|
+
if (!editor || !live)
|
|
300
|
+
return;
|
|
301
|
+
if ('review' in live)
|
|
302
|
+
void editor.revealReview?.(live.review);
|
|
303
|
+
else
|
|
304
|
+
void editor.setCaret(live);
|
|
305
|
+
},
|
|
306
|
+
onError(err) {
|
|
307
|
+
if (err.code !== 'paint-failed')
|
|
308
|
+
return reportError(undefined, err);
|
|
309
|
+
if (disposed || trapped)
|
|
310
|
+
return;
|
|
311
|
+
if (isBackendTrap(err.cause))
|
|
312
|
+
return trap(err.cause);
|
|
313
|
+
if (paintFailed)
|
|
314
|
+
return;
|
|
315
|
+
paintFailed = true;
|
|
316
|
+
emit();
|
|
317
|
+
}
|
|
318
|
+
},
|
|
319
|
+
wrote,
|
|
320
|
+
flush,
|
|
321
|
+
async render(format) {
|
|
322
|
+
if (disposed)
|
|
323
|
+
return undefined;
|
|
324
|
+
await flush();
|
|
325
|
+
if (disposed || struck() || !session)
|
|
326
|
+
return undefined;
|
|
327
|
+
if (review === 'shown')
|
|
328
|
+
return renderDocument(session, format);
|
|
329
|
+
if (refused.length)
|
|
330
|
+
return undefined;
|
|
331
|
+
return renderOf(session, format);
|
|
332
|
+
},
|
|
333
|
+
async dispose(unmounted) {
|
|
334
|
+
if (disposed)
|
|
335
|
+
return;
|
|
336
|
+
disposed = true;
|
|
337
|
+
stop();
|
|
338
|
+
const opened = session;
|
|
339
|
+
session = undefined;
|
|
340
|
+
state = { ...state, session: undefined };
|
|
341
|
+
opts.onState?.(state);
|
|
342
|
+
await unmounted?.();
|
|
343
|
+
opened?.free();
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quillmark/svelte",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.44.0",
|
|
4
4
|
"description": "Editor, live-preview and source surfaces over a Quillmark WASM session.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -33,21 +33,11 @@
|
|
|
33
33
|
"svelte": "./dist/index.js",
|
|
34
34
|
"default": "./dist/index.js"
|
|
35
35
|
},
|
|
36
|
-
"./core": {
|
|
37
|
-
"types": "./dist/core/index.d.ts",
|
|
38
|
-
"svelte": "./dist/core/index.js",
|
|
39
|
-
"default": "./dist/core/index.js"
|
|
40
|
-
},
|
|
41
36
|
"./preview": {
|
|
42
37
|
"types": "./dist/preview/index.d.ts",
|
|
43
38
|
"svelte": "./dist/preview/index.js",
|
|
44
39
|
"default": "./dist/preview/index.js"
|
|
45
40
|
},
|
|
46
|
-
"./visual": {
|
|
47
|
-
"types": "./dist/visual/index.d.ts",
|
|
48
|
-
"svelte": "./dist/visual/index.js",
|
|
49
|
-
"default": "./dist/visual/index.js"
|
|
50
|
-
},
|
|
51
41
|
"./preset": {
|
|
52
42
|
"types": "./dist/preset/index.d.ts",
|
|
53
43
|
"default": "./dist/preset/index.css"
|
|
@@ -56,6 +46,7 @@
|
|
|
56
46
|
"files": [
|
|
57
47
|
"dist",
|
|
58
48
|
"THEMING.md",
|
|
49
|
+
"CUSTOMIZING.md",
|
|
59
50
|
"NOTICE"
|
|
60
51
|
],
|
|
61
52
|
"sideEffects": true,
|