@quillmark/svelte 0.42.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/anchor.d.ts +0 -7
- package/dist/core/codec/anchor.js +0 -19
- package/dist/core/codec/field.js +1 -1
- package/dist/core/codec/index.d.ts +4 -7
- package/dist/core/codec/index.js +3 -4
- 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/core/schema.d.ts +6 -0
- package/dist/core/schema.js +9 -0
- 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/ArrayField.svelte +1 -6
- package/dist/visual/Card.svelte +2 -1
- package/dist/visual/MatrixField.svelte +1 -6
- package/dist/visual/ProseField.svelte +3 -13
- package/dist/visual/ProseValue.svelte +3 -13
- package/dist/visual/VariantField.svelte +1 -6
- package/dist/visual/VisualEditorInner.svelte +25 -14
- package/dist/visual/diagnostics.d.ts +1 -1
- package/dist/visual/index.js +4 -5
- package/dist/visual/leaves.d.ts +6 -0
- package/dist/visual/proposals.js +12 -8
- package/dist/visual/review.d.ts +0 -13
- package/dist/visual/review.js +1 -105
- package/dist/visual/review.svelte.d.ts +6 -0
- package/dist/visual/review.svelte.js +18 -1
- package/dist/visual/structure.js +1 -1
- 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 +3 -12
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
this leaf's commits with the caret riding the untouched view.
|
|
6
6
|
-->
|
|
7
7
|
<script lang="ts">
|
|
8
|
-
import {
|
|
8
|
+
import { untrack } from 'svelte';
|
|
9
9
|
import {
|
|
10
10
|
createField,
|
|
11
11
|
type FieldController,
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
import type { LeafRegistry } from './leaves.js';
|
|
16
16
|
import SlashMenu from './SlashMenu.svelte';
|
|
17
17
|
import { wording } from './strings.js';
|
|
18
|
-
import { review } from './review.svelte.js';
|
|
18
|
+
import { dropPlansOnLeave, review } from './review.svelte.js';
|
|
19
19
|
import type { TextProposal } from './review.js';
|
|
20
20
|
import './controls.css';
|
|
21
21
|
import type { Document, Quill, Addr, Content, Diagnostic } from '@quillmark/wasm';
|
|
@@ -202,17 +202,7 @@
|
|
|
202
202
|
(proposed ?? []).map((p) => ({ ...p, lit: reviewing.lit === p.id }))
|
|
203
203
|
);
|
|
204
204
|
});
|
|
205
|
-
|
|
206
|
-
* list is answered, which would leave its own Accept writing its value whole. */
|
|
207
|
-
let plannedIds: readonly string[] = [];
|
|
208
|
-
$effect(() => {
|
|
209
|
-
const ids = (proposed ?? []).map((p) => p.id);
|
|
210
|
-
for (const id of plannedIds) if (!ids.includes(id)) reviewing.planned(id, undefined);
|
|
211
|
-
plannedIds = ids;
|
|
212
|
-
});
|
|
213
|
-
onDestroy(() => {
|
|
214
|
-
for (const id of plannedIds) reviewing.planned(id, undefined);
|
|
215
|
-
});
|
|
205
|
+
dropPlansOnLeave(reviewing, () => proposed);
|
|
216
206
|
|
|
217
207
|
// Only a narrowed or a plain leaf holds by what a re-validation says, so only one of them asks.
|
|
218
208
|
$effect(() => {
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
replacement reads, so a write moving the value takes it or releases it.
|
|
46
46
|
-->
|
|
47
47
|
<script lang="ts">
|
|
48
|
-
import {
|
|
48
|
+
import { untrack } from 'svelte';
|
|
49
49
|
import { Fragment, Slice, type Node as PMNode } from 'prosemirror-model';
|
|
50
50
|
import { EditorState, Selection } from 'prosemirror-state';
|
|
51
51
|
import { EditorView } from 'prosemirror-view';
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
type TextCap
|
|
77
77
|
} from '../core/codec/index.js';
|
|
78
78
|
import { valueLeafSeat } from './leaves.js';
|
|
79
|
-
import { review } from './review.svelte.js';
|
|
79
|
+
import { dropPlansOnLeave, review } from './review.svelte.js';
|
|
80
80
|
import type { TextProposal } from './review.js';
|
|
81
81
|
import { wording } from './strings.js';
|
|
82
82
|
import './controls.css';
|
|
@@ -176,17 +176,7 @@
|
|
|
176
176
|
litHere: () => drawnProposals.some((p) => p.lit),
|
|
177
177
|
point: (id) => reviewing.point(id)
|
|
178
178
|
});
|
|
179
|
-
|
|
180
|
-
* list is answered, which would leave its own Accept writing its value whole. */
|
|
181
|
-
let plannedIds: readonly string[] = [];
|
|
182
|
-
$effect(() => {
|
|
183
|
-
const ids = (proposed ?? []).map((p) => p.id);
|
|
184
|
-
for (const id of plannedIds) if (!ids.includes(id)) reviewing.planned(id, undefined);
|
|
185
|
-
plannedIds = ids;
|
|
186
|
-
});
|
|
187
|
-
onDestroy(() => {
|
|
188
|
-
for (const id of plannedIds) reviewing.planned(id, undefined);
|
|
189
|
-
});
|
|
179
|
+
dropPlansOnLeave(reviewing, () => proposed);
|
|
190
180
|
|
|
191
181
|
const t = wording();
|
|
192
182
|
const seat = valueLeafSeat();
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
import type { DeepDiagnostic } from './diagnostics.js';
|
|
23
23
|
import { shownValue, splitReview, type DeepReview } from './review.js';
|
|
24
24
|
import { review as reviewState } from './review.svelte.js';
|
|
25
|
-
import type { LandingBox } from './leaves.js';
|
|
25
|
+
import type { LandingBox, Subform } from './leaves.js';
|
|
26
26
|
import {
|
|
27
27
|
VARIANT_DISCRIMINANT,
|
|
28
28
|
commitDiscriminant,
|
|
@@ -107,11 +107,6 @@
|
|
|
107
107
|
onCommit(next);
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
type Subform = {
|
|
111
|
-
focus: () => void;
|
|
112
|
-
focusPath: (steps: readonly PathStep[], pos?: number) => LandingBox;
|
|
113
|
-
openPath: (steps: readonly PathStep[]) => Promise<void>;
|
|
114
|
-
};
|
|
115
110
|
let cellsEl = $state<Subform | undefined>();
|
|
116
111
|
|
|
117
112
|
/** Whether a step names a cell the live world draws. The one test the landing and
|
|
@@ -46,16 +46,15 @@
|
|
|
46
46
|
import { createLifespan } from '../core/teardown.js';
|
|
47
47
|
import { spacePx } from '../core/rungs.js';
|
|
48
48
|
import { tooltips } from '../core/tooltip.js';
|
|
49
|
+
import { schemaOf } from '../core/schema.js';
|
|
49
50
|
import type {
|
|
50
51
|
Addr,
|
|
51
|
-
CardAddr,
|
|
52
52
|
Diagnostic,
|
|
53
53
|
Document,
|
|
54
54
|
PathStep,
|
|
55
55
|
PayloadItem,
|
|
56
56
|
QuillFieldSchema,
|
|
57
|
-
Resolved
|
|
58
|
-
ResolvedField
|
|
57
|
+
Resolved
|
|
59
58
|
} from '@quillmark/wasm';
|
|
60
59
|
import type { VisualEditorProps } from './props.js';
|
|
61
60
|
import type { Delta } from '../core/codec/positions.js';
|
|
@@ -215,7 +214,7 @@
|
|
|
215
214
|
// card reorder.
|
|
216
215
|
const commitErrors = new SvelteMap<string, RoutedDiagnostic>();
|
|
217
216
|
|
|
218
|
-
const kinds = $derived(Object.keys(quill
|
|
217
|
+
const kinds = $derived(Object.keys(schemaOf(quill)).filter((k) => k !== 'main'));
|
|
219
218
|
|
|
220
219
|
// The removal's step back (`undo.svelte.ts`), published so an array's row removal
|
|
221
220
|
// offers on the same toast a card's does.
|
|
@@ -279,7 +278,7 @@
|
|
|
279
278
|
if (!running || value === undefined || !shown || !Object.hasOwn(shown.values, name))
|
|
280
279
|
return rederive();
|
|
281
280
|
const fresh = fieldValues((isMain ? doc.main : doc.card(at)).payloadItems);
|
|
282
|
-
const cardSchema = isMain ?
|
|
281
|
+
const cardSchema = schemaOf(quill)[isMain ? 'main' : shown.kind];
|
|
283
282
|
patched = {
|
|
284
283
|
...patched,
|
|
285
284
|
[id]: {
|
|
@@ -366,7 +365,7 @@
|
|
|
366
365
|
};
|
|
367
366
|
/** The session key of the card holding `$id` `id`. */
|
|
368
367
|
function cardKeyFor(id: string): string | undefined {
|
|
369
|
-
return cardIds.find((_, k) => doc.
|
|
368
|
+
return cardIds.find((_, k) => doc.cardId(k) === id);
|
|
370
369
|
}
|
|
371
370
|
/** The host's list with each card a path names moved to where that card stands now: the card
|
|
372
371
|
* holding the item's `card`, else the one at the path's index when the list was set. */
|
|
@@ -376,12 +375,24 @@
|
|
|
376
375
|
if (!review?.length) return review;
|
|
377
376
|
if (was === now && !review.some((item) => 'card' in item && item.card !== undefined))
|
|
378
377
|
return review;
|
|
378
|
+
let keys: Map<string, string> | undefined;
|
|
379
|
+
const keyOf = (id: string): string | undefined => {
|
|
380
|
+
if (!keys) {
|
|
381
|
+
keys = new Map();
|
|
382
|
+
const cards = doc.cards;
|
|
383
|
+
for (const [k, key] of now.entries()) {
|
|
384
|
+
const at = cards[k]?.id;
|
|
385
|
+
if (at != null && !keys.has(at)) keys.set(at, key);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
return keys.get(id);
|
|
389
|
+
};
|
|
379
390
|
return review.map((item) => {
|
|
380
391
|
if (byCard(item)) return item;
|
|
381
392
|
let field: DocPath;
|
|
382
393
|
if (item.card === undefined) field = cardMoved(item.field, was, now);
|
|
383
394
|
else {
|
|
384
|
-
const key =
|
|
395
|
+
const key = keyOf(item.card);
|
|
385
396
|
field = pathOnCard(item.field, key === undefined ? now.length : now.indexOf(key));
|
|
386
397
|
}
|
|
387
398
|
return field === item.field ? item : { ...item, field };
|
|
@@ -566,7 +577,7 @@
|
|
|
566
577
|
text: string;
|
|
567
578
|
} {
|
|
568
579
|
const { add } = item;
|
|
569
|
-
const schema = quill
|
|
580
|
+
const schema = schemaOf(quill)[add.kind];
|
|
570
581
|
const values = fieldValues(add.payloadItems);
|
|
571
582
|
const named = (add.ext?.editor as { title?: unknown } | undefined)?.title;
|
|
572
583
|
const title = cardTitle(
|
|
@@ -921,7 +932,7 @@
|
|
|
921
932
|
if (!key?.field) return '';
|
|
922
933
|
const isMain = key.card === undefined;
|
|
923
934
|
const card = isMain ? model.main : model.cards[cardIndexOf(key.card as CardId)];
|
|
924
|
-
const schema = isMain ?
|
|
935
|
+
const schema = schemaOf(quill)[isMain ? 'main' : (card?.kind ?? '')];
|
|
925
936
|
const sub = schema?.fields[key.field];
|
|
926
937
|
return sub ? fieldTitle(key.field, sub) : humanize(key.field);
|
|
927
938
|
}
|
|
@@ -1036,7 +1047,7 @@
|
|
|
1036
1047
|
const { card: at, field } = addr;
|
|
1037
1048
|
if (typeof at !== 'number' || field == null) return;
|
|
1038
1049
|
const shown = model.cards[at];
|
|
1039
|
-
const cardSchema = shown && quill
|
|
1050
|
+
const cardSchema = shown && schemaOf(quill)[shown.kind];
|
|
1040
1051
|
if (!cardSchema || cardSchema.title?.trim()) return;
|
|
1041
1052
|
const sub = Object.hasOwn(cardSchema.fields, field) ? cardSchema.fields[field] : undefined;
|
|
1042
1053
|
if (!sub || !shortCell(sub)) return;
|
|
@@ -1251,7 +1262,7 @@
|
|
|
1251
1262
|
const name =
|
|
1252
1263
|
shown?.titleOverride ||
|
|
1253
1264
|
shown?.titlePlaceholder ||
|
|
1254
|
-
kindTitle(quill
|
|
1265
|
+
kindTitle(schemaOf(quill)[card.kind], card.kind);
|
|
1255
1266
|
const gone = removed.remove(id, card, cardIds, i);
|
|
1256
1267
|
doc.removeCard(i);
|
|
1257
1268
|
arm.arm();
|
|
@@ -1476,7 +1487,7 @@
|
|
|
1476
1487
|
|
|
1477
1488
|
const tree = $derived.by(() => {
|
|
1478
1489
|
revision; // re-derive on every mutation
|
|
1479
|
-
const schema = quill
|
|
1490
|
+
const schema = schemaOf(quill);
|
|
1480
1491
|
const main = doc.main;
|
|
1481
1492
|
const cards = doc.cards;
|
|
1482
1493
|
// The provenance channel (FIELD_PROVENANCE): one whole-doc resolve per
|
|
@@ -2158,7 +2169,7 @@
|
|
|
2158
2169
|
function declaredField(addr: Addr): QuillFieldSchema | undefined {
|
|
2159
2170
|
if (addr.field == null) return undefined;
|
|
2160
2171
|
const kind = typeof addr.card === 'number' ? model.cards[addr.card]?.kind : undefined;
|
|
2161
|
-
const schema = quill
|
|
2172
|
+
const schema = schemaOf(quill);
|
|
2162
2173
|
const card = addr.card == null ? schema.main : kind ? schema[kind] : undefined;
|
|
2163
2174
|
return card?.fields?.[addr.field];
|
|
2164
2175
|
}
|
|
@@ -2420,7 +2431,7 @@
|
|
|
2420
2431
|
<div class="qm-menu-surface" data-qm-root>
|
|
2421
2432
|
{#each kinds as k (k)}
|
|
2422
2433
|
<DropdownMenu.Item class="qm-menu-item" onSelect={() => addPicked(atIndex, k)}
|
|
2423
|
-
>{kindTitle(quill
|
|
2434
|
+
>{kindTitle(schemaOf(quill)[k], k)}</DropdownMenu.Item
|
|
2424
2435
|
>
|
|
2425
2436
|
{/each}
|
|
2426
2437
|
</div>
|
|
@@ -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
|
package/dist/visual/leaves.d.ts
CHANGED
|
@@ -7,6 +7,12 @@ import type { FieldController, LeafViews } from '../core/codec/index.js';
|
|
|
7
7
|
* the walk had to open something on the way.
|
|
8
8
|
*/
|
|
9
9
|
export type LandingBox = HTMLElement | undefined | Promise<HTMLElement | undefined>;
|
|
10
|
+
/** A nested form's handle, as a container field holds one per row, column or variant. */
|
|
11
|
+
export type Subform = {
|
|
12
|
+
focus: () => void;
|
|
13
|
+
focusPath: (steps: readonly PathStep[], pos?: number) => LandingBox;
|
|
14
|
+
openPath: (steps: readonly PathStep[]) => Promise<void>;
|
|
15
|
+
};
|
|
10
16
|
/**
|
|
11
17
|
* A mounted field's landing handle: focus it, and the `.qm-wash` box the arrival wash
|
|
12
18
|
* plays over ({@link import('../core/bloom.js').bloom}).
|
package/dist/visual/proposals.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { addrForFieldPath, fieldPathForAddr } from '../core/address.js';
|
|
2
|
+
import { schemaOf } from '../core/schema.js';
|
|
2
3
|
import { asContent, lineRuns } from '../core/codec/value-plan.js';
|
|
3
4
|
import { byBlocks, sameValue } from './review.js';
|
|
4
5
|
import { VARIANT_DISCRIMINANT, baseType, fieldValues, textKind } from './structure.js';
|
|
@@ -37,9 +38,12 @@ let minted = 0;
|
|
|
37
38
|
export function proposalsBetween(quill, base, answer, opts = {}) {
|
|
38
39
|
const { mint = () => `review-${minted++}`, label } = typeof opts === 'function' ? { mint: opts } : opts;
|
|
39
40
|
const items = [];
|
|
40
|
-
const
|
|
41
|
-
const
|
|
42
|
-
const
|
|
41
|
+
const schemas = schemaOf(quill);
|
|
42
|
+
const baseCards = base.cards;
|
|
43
|
+
const answerCards = answer.cards;
|
|
44
|
+
const kinds = baseCards.map((c) => c.kind);
|
|
45
|
+
const baseIds = baseCards.map((c) => c.id ?? '');
|
|
46
|
+
const answerIds = answerCards.map((c) => c.id ?? '');
|
|
43
47
|
const pathOf = (at, field, steps = []) => fieldPathForAddr(addrOf(at, field), kinds, steps);
|
|
44
48
|
const diffCard = (schema, at, was, now, answerAt) => {
|
|
45
49
|
const before = fieldValues(was.payloadItems);
|
|
@@ -182,21 +186,21 @@ export function proposalsBetween(quill, base, answer, opts = {}) {
|
|
|
182
186
|
});
|
|
183
187
|
}
|
|
184
188
|
};
|
|
185
|
-
diffCard(
|
|
189
|
+
diffCard(schemas.main, undefined, base.main, answer.main, undefined);
|
|
186
190
|
/** The base's index of each card the answer keeps as it was, by its answer index. */
|
|
187
191
|
const kept = new Map();
|
|
188
192
|
const removed = [];
|
|
189
193
|
for (const [at, id] of baseIds.entries()) {
|
|
190
194
|
const answerAt = answerIds.indexOf(id);
|
|
191
|
-
const was =
|
|
192
|
-
const now = answerAt < 0 ? undefined :
|
|
195
|
+
const was = baseCards[at];
|
|
196
|
+
const now = answerAt < 0 ? undefined : answerCards[answerAt];
|
|
193
197
|
if (!now || now.kind !== was.kind) {
|
|
194
198
|
removed.push(at);
|
|
195
199
|
continue;
|
|
196
200
|
}
|
|
197
201
|
kept.set(answerAt, at);
|
|
198
202
|
const first = items.length;
|
|
199
|
-
diffCard(
|
|
203
|
+
diffCard(schemas[was.kind], at, was, now, answerAt);
|
|
200
204
|
if (id)
|
|
201
205
|
for (const item of items.slice(first))
|
|
202
206
|
Object.assign(item, { card: id });
|
|
@@ -210,7 +214,7 @@ export function proposalsBetween(quill, base, answer, opts = {}) {
|
|
|
210
214
|
const after = kept.get(lead);
|
|
211
215
|
items.push({
|
|
212
216
|
id: mint(),
|
|
213
|
-
add:
|
|
217
|
+
add: answerCards[at],
|
|
214
218
|
...(after !== undefined && { after }),
|
|
215
219
|
...(after !== undefined && baseIds[after] && { afterCard: baseIds[after] })
|
|
216
220
|
});
|
package/dist/visual/review.d.ts
CHANGED
|
@@ -208,18 +208,6 @@ export declare function reviewText(value: unknown, words: {
|
|
|
208
208
|
on: string;
|
|
209
209
|
off: string;
|
|
210
210
|
}): string;
|
|
211
|
-
/** A stretch of a proposal as a reader is shown it: kept, struck, or tinted. */
|
|
212
|
-
export interface ReviewRun {
|
|
213
|
-
text: string;
|
|
214
|
-
kind?: 'del' | 'ins';
|
|
215
|
-
}
|
|
216
|
-
type Words = {
|
|
217
|
-
on: string;
|
|
218
|
-
off: string;
|
|
219
|
-
};
|
|
220
|
-
/** A proposal as runs, what it keeps, strikes and tints. Two lines of words differ by their words,
|
|
221
|
-
* two lists by their members, two records by their keys; any other pair differs whole. */
|
|
222
|
-
export declare function reviewRuns(before: unknown, after: unknown, words: Words): ReviewRun[];
|
|
223
211
|
/** A proposal a leaf of words draws over its own value: what it would write, and the value its
|
|
224
212
|
* writer read where it says, each as the leaf's content. */
|
|
225
213
|
export interface TextProposal {
|
|
@@ -245,4 +233,3 @@ export declare function shownValue(item: FieldProposal | undefined, stored: unkn
|
|
|
245
233
|
/** Whether a value a reader commits is the one a proposal would write: a blank and an unset value
|
|
246
234
|
* are one, since a control cleared over a default commits `''`. */
|
|
247
235
|
export declare function writesProposed(value: unknown, after: unknown): boolean;
|
|
248
|
-
export {};
|
package/dist/visual/review.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { asContent
|
|
1
|
+
import { asContent } from '../core/codec/index.js';
|
|
2
2
|
/** Whether an item proposes a whole card. */
|
|
3
3
|
export const byCard = (item) => 'add' in item || 'remove' in item;
|
|
4
4
|
/** Whether an item names blocks of a rich text field, which its prose leaf draws. */
|
|
@@ -167,110 +167,6 @@ export function reviewText(value, words) {
|
|
|
167
167
|
.map(([key, v]) => `${key}: ${v}`)
|
|
168
168
|
.join('; ');
|
|
169
169
|
}
|
|
170
|
-
const prose = (v) => typeof v === 'string' || (typeof v === 'object' && v !== null && 'text' in v);
|
|
171
|
-
const record = (v) => typeof v === 'object' && v !== null && !Array.isArray(v) && !prose(v);
|
|
172
|
-
const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
173
|
-
function whole(before, after) {
|
|
174
|
-
return [
|
|
175
|
-
...(before ? [{ text: before, kind: 'del' }] : []),
|
|
176
|
-
...(after ? [{ text: after, kind: 'ins' }] : [])
|
|
177
|
-
];
|
|
178
|
-
}
|
|
179
|
-
function joined(parts, by) {
|
|
180
|
-
return parts.filter((p) => p.length).flatMap((p, i) => (i ? [{ text: by }, ...p] : p));
|
|
181
|
-
}
|
|
182
|
-
/** The keys of two records that differ, each as `key: ` with what goes struck and what comes
|
|
183
|
-
* tinted. */
|
|
184
|
-
function recordRuns(before, after, words) {
|
|
185
|
-
const keys = [...new Set([...Object.keys(after), ...Object.keys(before)])];
|
|
186
|
-
return joined(keys
|
|
187
|
-
.filter((key) => !same(before[key], after[key]))
|
|
188
|
-
.map((key) => {
|
|
189
|
-
const runs = whole(reviewText(before[key], words), reviewText(after[key], words));
|
|
190
|
-
return runs.length ? [{ text: `${key}: ` }, ...runs] : [];
|
|
191
|
-
}), '; ');
|
|
192
|
-
}
|
|
193
|
-
/** Two lists by their members, in order: a member both hold is kept, one only `before` holds is
|
|
194
|
-
* struck, one only `after` holds is tinted. In a list of records a kept record is left out, and a
|
|
195
|
-
* record struck where one is tinted reads as the keys the two differ in. */
|
|
196
|
-
function listRuns(before, after, words) {
|
|
197
|
-
const n = before.length;
|
|
198
|
-
const m = after.length;
|
|
199
|
-
const common = Array.from({ length: n + 1 }, () => new Array(m + 1).fill(0));
|
|
200
|
-
for (let i = n - 1; i >= 0; i--)
|
|
201
|
-
for (let j = m - 1; j >= 0; j--)
|
|
202
|
-
common[i][j] = same(before[i], after[j])
|
|
203
|
-
? common[i + 1][j + 1] + 1
|
|
204
|
-
: Math.max(common[i + 1][j], common[i][j + 1]);
|
|
205
|
-
const records = [...before, ...after].some(record);
|
|
206
|
-
/** A record edited in place, named by its first value where that stays, so a reader can tell
|
|
207
|
-
* which of the list it is with the records kept left out. */
|
|
208
|
-
const edited = (was, now) => {
|
|
209
|
-
const first = Object.keys(now)[0];
|
|
210
|
-
const name = first !== undefined && same(was[first], now[first]) && reviewText(now[first], words);
|
|
211
|
-
const runs = recordRuns(was, now, words);
|
|
212
|
-
return name ? [{ text: `${name} (` }, ...runs, { text: ')' }] : runs;
|
|
213
|
-
};
|
|
214
|
-
const parts = [];
|
|
215
|
-
let gone = [];
|
|
216
|
-
let come = [];
|
|
217
|
-
const flush = () => {
|
|
218
|
-
const pairs = records ? Math.min(gone.length, come.length) : 0;
|
|
219
|
-
for (let k = 0; k < pairs; k++)
|
|
220
|
-
parts.push(record(gone[k]) && record(come[k])
|
|
221
|
-
? edited(gone[k], come[k])
|
|
222
|
-
: whole(reviewText(gone[k], words), reviewText(come[k], words)));
|
|
223
|
-
for (const v of gone.slice(pairs))
|
|
224
|
-
parts.push(whole(reviewText(v, words), ''));
|
|
225
|
-
for (const v of come.slice(pairs))
|
|
226
|
-
parts.push(whole('', reviewText(v, words)));
|
|
227
|
-
gone = [];
|
|
228
|
-
come = [];
|
|
229
|
-
};
|
|
230
|
-
let i = 0;
|
|
231
|
-
let j = 0;
|
|
232
|
-
while (i < n || j < m) {
|
|
233
|
-
if (i < n && j < m && same(before[i], after[j])) {
|
|
234
|
-
flush();
|
|
235
|
-
if (!records)
|
|
236
|
-
parts.push([{ text: reviewText(before[i], words) }]);
|
|
237
|
-
i++;
|
|
238
|
-
j++;
|
|
239
|
-
}
|
|
240
|
-
else if (j < m && (i === n || common[i][j + 1] >= common[i + 1][j]))
|
|
241
|
-
come.push(after[j++]);
|
|
242
|
-
else
|
|
243
|
-
gone.push(before[i++]);
|
|
244
|
-
}
|
|
245
|
-
flush();
|
|
246
|
-
return joined(parts, ', ');
|
|
247
|
-
}
|
|
248
|
-
/** A proposal as runs, what it keeps, strikes and tints. Two lines of words differ by their words,
|
|
249
|
-
* two lists by their members, two records by their keys; any other pair differs whole. */
|
|
250
|
-
export function reviewRuns(before, after, words) {
|
|
251
|
-
if (Array.isArray(before) && Array.isArray(after) && before.length && after.length)
|
|
252
|
-
return listRuns(before, after, words);
|
|
253
|
-
if (record(before) && record(after))
|
|
254
|
-
return recordRuns(before, after, words);
|
|
255
|
-
const was = reviewText(before, words);
|
|
256
|
-
const now = reviewText(after, words);
|
|
257
|
-
if (!prose(before) || !prose(after) || !was || !now)
|
|
258
|
-
return whole(was, now);
|
|
259
|
-
const out = [];
|
|
260
|
-
let at = 0;
|
|
261
|
-
for (const hunk of wordDiff(was, now)) {
|
|
262
|
-
if (hunk.at > at)
|
|
263
|
-
out.push({ text: was.slice(at, hunk.at) });
|
|
264
|
-
if (hunk.end > hunk.at)
|
|
265
|
-
out.push({ text: was.slice(hunk.at, hunk.end), kind: 'del' });
|
|
266
|
-
if (hunk.insert)
|
|
267
|
-
out.push({ text: hunk.insert, kind: 'ins' });
|
|
268
|
-
at = hunk.end;
|
|
269
|
-
}
|
|
270
|
-
if (at < was.length)
|
|
271
|
-
out.push({ text: was.slice(at) });
|
|
272
|
-
return out;
|
|
273
|
-
}
|
|
274
170
|
/** A proposal over a leaf of words, `undefined` where its values are not words. A cleared value
|
|
275
171
|
* is drawn as what Accept leaves: `cleared`, the default that would print, else nothing. */
|
|
276
172
|
export function textProposal(item, cleared) {
|
|
@@ -143,3 +143,9 @@ export declare function createReview(source: ReviewSource): Review;
|
|
|
143
143
|
export declare function setReview(review: Review): void;
|
|
144
144
|
/** The editor's review state, or {@link NO_REVIEW} off-tree. */
|
|
145
145
|
export declare function review(): Review;
|
|
146
|
+
/** A proposal's plan goes when it leaves the list or the leaf goes, not when another in the
|
|
147
|
+
* list is answered, which would leave its own Accept writing its value whole. Called during
|
|
148
|
+
* a leaf's init. */
|
|
149
|
+
export declare function dropPlansOnLeave(reviewing: Review, proposed: () => readonly {
|
|
150
|
+
id: string;
|
|
151
|
+
}[] | undefined): void;
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
// empties it: an inverse is good against the document it was recorded over. An answer's own
|
|
14
14
|
// writes, and an inverse's, go down the lanes an edit does, so they are flagged while they are
|
|
15
15
|
// made.
|
|
16
|
-
import { getContext, setContext } from 'svelte';
|
|
16
|
+
import { getContext, onDestroy, setContext } from 'svelte';
|
|
17
17
|
import { SvelteMap } from 'svelte/reactivity';
|
|
18
18
|
import { asContent, planValue } from '../core/codec/index.js';
|
|
19
19
|
import { byBlocks, byCard, locate, onField, putsIn, sameValue, textProposal, valueIn, writesProposed } from './review.js';
|
|
@@ -541,3 +541,20 @@ const NO_REVIEW = {
|
|
|
541
541
|
export function review() {
|
|
542
542
|
return getContext(KEY) ?? NO_REVIEW;
|
|
543
543
|
}
|
|
544
|
+
/** A proposal's plan goes when it leaves the list or the leaf goes, not when another in the
|
|
545
|
+
* list is answered, which would leave its own Accept writing its value whole. Called during
|
|
546
|
+
* a leaf's init. */
|
|
547
|
+
export function dropPlansOnLeave(reviewing, proposed) {
|
|
548
|
+
let plannedIds = [];
|
|
549
|
+
$effect(() => {
|
|
550
|
+
const ids = (proposed() ?? []).map((p) => p.id);
|
|
551
|
+
for (const id of plannedIds)
|
|
552
|
+
if (!ids.includes(id))
|
|
553
|
+
reviewing.planned(id, undefined);
|
|
554
|
+
plannedIds = ids;
|
|
555
|
+
});
|
|
556
|
+
onDestroy(() => {
|
|
557
|
+
for (const id of plannedIds)
|
|
558
|
+
reviewing.planned(id, undefined);
|
|
559
|
+
});
|
|
560
|
+
}
|
package/dist/visual/structure.js
CHANGED
|
@@ -735,7 +735,7 @@ export class IdSeq {
|
|
|
735
735
|
export function placeCardInto(target, card, at) {
|
|
736
736
|
const { id, ...bare } = card;
|
|
737
737
|
const free = id !== undefined &&
|
|
738
|
-
!Array.from({ length: target.cardCount }, (_, k) => target.
|
|
738
|
+
!Array.from({ length: target.cardCount }, (_, k) => target.cardId(k)).includes(id);
|
|
739
739
|
try {
|
|
740
740
|
target.unchecked.insertCard(free ? card : bare, at);
|
|
741
741
|
}
|
|
@@ -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
|
+
}
|