@quillmark/svelte 0.29.3 → 0.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/core/address.d.ts +3 -3
- package/dist/core/address.js +1 -1
- package/dist/core/codec/decode.d.ts +4 -5
- package/dist/core/codec/decode.js +151 -208
- package/dist/core/codec/encode.d.ts +13 -35
- package/dist/core/codec/encode.js +127 -408
- package/dist/core/codec/field.d.ts +11 -10
- package/dist/core/codec/field.js +190 -92
- package/dist/core/codec/index.d.ts +2 -2
- package/dist/core/codec/index.js +4 -4
- package/dist/core/codec/islands.d.ts +13 -9
- package/dist/core/codec/islands.js +54 -49
- package/dist/core/codec/marks.d.ts +12 -18
- package/dist/core/codec/marks.js +16 -26
- package/dist/core/codec/positions.d.ts +25 -7
- package/dist/core/codec/positions.js +43 -50
- package/dist/core/codec/prose.css +0 -8
- package/dist/core/codec/schema.d.ts +3 -3
- package/dist/core/codec/schema.js +29 -11
- package/dist/core/codec/slash.d.ts +4 -2
- package/dist/core/codec/slash.js +13 -3
- package/dist/core/codec/table-copy.d.ts +3 -3
- package/dist/core/codec/table-copy.js +6 -4
- package/dist/core/codec/table-paste.js +13 -9
- package/dist/core/codec/table-view.js +19 -12
- package/dist/core/codec/table.d.ts +77 -43
- package/dist/core/codec/table.js +157 -48
- package/dist/core/index.d.ts +1 -0
- package/dist/core/theme.css +14 -6
- package/dist/visual/ArrayField.svelte +168 -83
- package/dist/visual/BooleanField.svelte +2 -2
- package/dist/visual/Card.svelte +65 -44
- package/dist/visual/DateField.svelte +16 -1
- package/dist/visual/DiagnosticList.svelte +34 -2
- package/dist/visual/EnumField.svelte +58 -44
- package/dist/visual/Field.svelte +13 -3
- package/dist/visual/Field.svelte.d.ts +3 -1
- package/dist/visual/FieldHint.svelte +10 -3
- package/dist/visual/FormatPopover.svelte +1 -1
- package/dist/visual/MatrixAdd.svelte +3 -18
- package/dist/visual/MatrixField.svelte +20 -12
- package/dist/visual/ObjectField.svelte +164 -145
- package/dist/visual/ProseField.svelte +6 -1
- package/dist/visual/ProseValue.svelte +8 -8
- package/dist/visual/SlashMenu.svelte +24 -12
- package/dist/visual/SlashMenu.svelte.d.ts +2 -0
- package/dist/visual/VisualEditor.svelte +1 -1
- package/dist/visual/VisualEditor.svelte.d.ts +1 -1
- package/dist/visual/VisualEditorInner.svelte +159 -18
- package/dist/visual/VisualEditorInner.svelte.d.ts +1 -1
- package/dist/visual/controls.css +42 -4
- package/dist/visual/leaves.d.ts +1 -1
- package/dist/visual/leaves.js +1 -1
- package/dist/visual/strings.d.ts +27 -10
- package/dist/visual/strings.js +40 -6
- package/dist/visual/structure.d.ts +17 -9
- package/dist/visual/structure.js +20 -26
- package/dist/visual/undo.svelte.d.ts +36 -0
- package/dist/visual/undo.svelte.js +119 -0
- package/package.json +2 -2
- package/dist/visual/hold.d.ts +0 -17
- package/dist/visual/hold.js +0 -39
package/dist/visual/structure.js
CHANGED
|
@@ -105,16 +105,7 @@ export function declaredContent(v, markdown) {
|
|
|
105
105
|
return undefined;
|
|
106
106
|
if (markdown)
|
|
107
107
|
return core().importMarkdown(text).content;
|
|
108
|
-
return {
|
|
109
|
-
text,
|
|
110
|
-
lines: text
|
|
111
|
-
.split('\n')
|
|
112
|
-
.map((_, i) => i === 0
|
|
113
|
-
? { containers: [], kind: 'para' }
|
|
114
|
-
: { containers: [], kind: 'para', continues: true }),
|
|
115
|
-
marks: [],
|
|
116
|
-
islands: []
|
|
117
|
-
};
|
|
108
|
+
return { text: text.replaceAll('\n', '\u2028'), blocks: [{ id: 'b0', kind: 'para' }] };
|
|
118
109
|
}
|
|
119
110
|
/** A field's `{#each}` key: its name and what a mounted leaf reads once, its type,
|
|
120
111
|
* {@link oneLine} and `max:`, and its elements'. A retype or a quill swap that changes
|
|
@@ -284,7 +275,7 @@ export function addedItems(matrix, map) {
|
|
|
284
275
|
const title = stored[MATRIX_TITLE];
|
|
285
276
|
if (title == null)
|
|
286
277
|
continue;
|
|
287
|
-
out.push({ id, title:
|
|
278
|
+
out.push({ id, title: titleText(title) });
|
|
288
279
|
}
|
|
289
280
|
return out.sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
|
|
290
281
|
}
|
|
@@ -369,9 +360,9 @@ function stepInto(schema, step) {
|
|
|
369
360
|
return undefined;
|
|
370
361
|
}
|
|
371
362
|
}
|
|
372
|
-
// ──
|
|
363
|
+
// ── Short cells and layouts ──────────────────────────────────────────────────
|
|
373
364
|
/**
|
|
374
|
-
* Whether a cell is one line tall by declaration: what a table column
|
|
365
|
+
* Whether a cell is one line tall by declaration: what a table column can hold.
|
|
375
366
|
*/
|
|
376
367
|
export function shortCell(sub) {
|
|
377
368
|
const kind = controlKind(sub);
|
|
@@ -392,10 +383,6 @@ function firstShortText(cells, values) {
|
|
|
392
383
|
return undefined;
|
|
393
384
|
return titleText(own(values, named[0])).trim() || undefined;
|
|
394
385
|
}
|
|
395
|
-
/** A collapsed row's own words ({@link firstShortText}). */
|
|
396
|
-
export function rowSummary(items, row) {
|
|
397
|
-
return firstShortText(items?.properties, (row ?? {}));
|
|
398
|
-
}
|
|
399
386
|
/**
|
|
400
387
|
* The layout an array takes: `'table'` where the array's own `ui.layout` asks for it
|
|
401
388
|
* and every cell of the row is short (a block prose cell declines it, at load width and
|
|
@@ -553,7 +540,7 @@ export function cardSections(cardSchema) {
|
|
|
553
540
|
return [...panels, ...groupSections(grouped, order, (g) => groupLabel(cardSchema, g))];
|
|
554
541
|
}
|
|
555
542
|
/**
|
|
556
|
-
* The group section a card
|
|
543
|
+
* The group section a card opens on first mount, or `null` when the card declares none.
|
|
557
544
|
* All-collapsed would disclose nothing of what is behind the chevrons, and a rule keyed on document
|
|
558
545
|
* state would move the opening under a user as they fill.
|
|
559
546
|
*/
|
|
@@ -589,18 +576,25 @@ function packable(f) {
|
|
|
589
576
|
return f.control !== 'prose' || f.inline;
|
|
590
577
|
}
|
|
591
578
|
/**
|
|
592
|
-
* Consecutive packable fields are `cell`s the grid auto-places
|
|
593
|
-
*
|
|
594
|
-
* empty.
|
|
579
|
+
* Consecutive packable fields are `cell`s the grid auto-places, and a run of one is `full`:
|
|
580
|
+
* alone, a field would stand in a narrow track that reads as truncated against the width it
|
|
581
|
+
* leaves empty. A longer run's last cell carries its `tail`, which the grid spends at the
|
|
582
|
+
* capacity it stands at, so the last of three spans the row at two tracks and shares it at
|
|
583
|
+
* four. Everything else is `full`. No width is measured.
|
|
595
584
|
*/
|
|
596
585
|
export function placeFields(fields) {
|
|
597
586
|
const out = [];
|
|
598
587
|
let run = 0;
|
|
599
|
-
// A run
|
|
600
|
-
// field already placed.
|
|
588
|
+
// A run's length is only knowable at its end, so the span or tail is patched back onto
|
|
589
|
+
// the field already placed.
|
|
601
590
|
const flush = () => {
|
|
591
|
+
const last = out[out.length - 1];
|
|
602
592
|
if (run === 1)
|
|
603
|
-
|
|
593
|
+
last.span = 'full';
|
|
594
|
+
else if (run % 4 === 1)
|
|
595
|
+
last.tail = 'lone';
|
|
596
|
+
else if (run % 2 === 1)
|
|
597
|
+
last.tail = 'odd';
|
|
604
598
|
run = 0;
|
|
605
599
|
};
|
|
606
600
|
for (const f of fields) {
|
|
@@ -624,8 +618,8 @@ export function fieldValues(items) {
|
|
|
624
618
|
values[p.key] = p.value;
|
|
625
619
|
return values;
|
|
626
620
|
}
|
|
627
|
-
/** A field value as title text. A
|
|
628
|
-
*
|
|
621
|
+
/** A field value as title text. A text field rests as the authored string or as
|
|
622
|
+
* `Content`, whose `text` is the same words; a scalar reads as
|
|
629
623
|
* itself; a variant container reads as its discriminant member, the one cell of it
|
|
630
624
|
* that names the world; any other container as nothing. */
|
|
631
625
|
export function titleText(v) {
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** How long an offer stands, in ms. Long enough to read the toast and reach its button;
|
|
2
|
+
* short enough that the toast is gone before the user has moved on to something else. */
|
|
3
|
+
export declare const OFFER_MS = 6000;
|
|
4
|
+
export interface UndoOffer {
|
|
5
|
+
/** What the toast says, already worded: `Item 2 removed`. */
|
|
6
|
+
readonly notice: string;
|
|
7
|
+
/** Put back what the removal took. Runs at most once. */
|
|
8
|
+
readonly restore: () => void;
|
|
9
|
+
}
|
|
10
|
+
export interface StructuralUndo {
|
|
11
|
+
/** The offer on show, if any. */
|
|
12
|
+
readonly current: UndoOffer | undefined;
|
|
13
|
+
/** Offer `restore` as the undo of the removal just made, replacing any standing offer. */
|
|
14
|
+
offer(notice: string, restore: () => void): void;
|
|
15
|
+
/** Name the control the removal handed the focus to. ⌘Z there is the offer's until the
|
|
16
|
+
* control takes an edit or the focus leaves it: the key that removed is the key that
|
|
17
|
+
* asks for it back, and the control has nothing of its own to undo yet. */
|
|
18
|
+
hand(el: Element | null): void;
|
|
19
|
+
/** Whether ⌘Z pressed at `target` is the offer's: the page's body, where a removal under
|
|
20
|
+
* the pointer leaves the focus, when this offer is the page's latest; the handed control; or a control under `root` that keeps
|
|
21
|
+
* no history of its own. A text control that is not the handed one keeps its key. */
|
|
22
|
+
accepts(target: EventTarget | null, root: Element | undefined): boolean;
|
|
23
|
+
/** Hold the lapse while the toast is under the pointer or the focus, and let it run again. */
|
|
24
|
+
pause(): void;
|
|
25
|
+
resume(): void;
|
|
26
|
+
/** Run the standing offer and clear it. False when there was none to run. */
|
|
27
|
+
take(): boolean;
|
|
28
|
+
/** Drop the standing offer without running it. */
|
|
29
|
+
withdraw(): void;
|
|
30
|
+
}
|
|
31
|
+
export declare function createStructuralUndo(): StructuralUndo & {
|
|
32
|
+
dispose(): void;
|
|
33
|
+
};
|
|
34
|
+
export declare function setStructuralUndo(undo: StructuralUndo): void;
|
|
35
|
+
/** The editor's undo, or {@link NO_UNDO} off-tree. */
|
|
36
|
+
export declare function structuralUndo(): StructuralUndo;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// The structural undo: one step back for a removal, offered on a toast.
|
|
2
|
+
//
|
|
3
|
+
// A leaf's text has its own history (`core/codec/field.ts`), so a keystroke is undone where
|
|
4
|
+
// it was typed. A removal has no leaf left to hold one: the card or the row it took is gone
|
|
5
|
+
// from the tree, and with it every history that could have restored it. So the surface keeps
|
|
6
|
+
// the step itself, one deep, and offers it where the removal happened.
|
|
7
|
+
//
|
|
8
|
+
// One deep, and only the latest: a second removal replaces the first offer, and any other
|
|
9
|
+
// structural edit withdraws it, because the restore reinserts at the index the removal left
|
|
10
|
+
// and an edit between the two moves what that index names. The offer lapses on its own after
|
|
11
|
+
// a while, so an Undo pressed long after the removal is not a surprise; the while holds as
|
|
12
|
+
// long as the toast is under the pointer or the focus.
|
|
13
|
+
//
|
|
14
|
+
// The key listens on the document while an offer stands, not on the surface: a removal by
|
|
15
|
+
// the pointer takes the pressed button with it and leaves the focus on the page's body,
|
|
16
|
+
// which no keydown on the surface hears.
|
|
17
|
+
import { getContext, setContext } from 'svelte';
|
|
18
|
+
/** How long an offer stands, in ms. Long enough to read the toast and reach its button;
|
|
19
|
+
* short enough that the toast is gone before the user has moved on to something else. */
|
|
20
|
+
export const OFFER_MS = 6000;
|
|
21
|
+
const EDITABLE = 'input, textarea, select, [contenteditable="true"]';
|
|
22
|
+
/** The editor whose offer is the page's latest: the body belongs to no surface, so of two
|
|
23
|
+
* editors with an offer standing, the key at the body is the one that offered last's. */
|
|
24
|
+
let latest;
|
|
25
|
+
export function createStructuralUndo() {
|
|
26
|
+
let current = $state();
|
|
27
|
+
let handed;
|
|
28
|
+
let timer;
|
|
29
|
+
let paused = false;
|
|
30
|
+
const stop = () => {
|
|
31
|
+
if (timer !== undefined)
|
|
32
|
+
clearTimeout(timer);
|
|
33
|
+
timer = undefined;
|
|
34
|
+
};
|
|
35
|
+
const lapse = () => {
|
|
36
|
+
timer = setTimeout(clear, OFFER_MS);
|
|
37
|
+
};
|
|
38
|
+
const clear = () => {
|
|
39
|
+
stop();
|
|
40
|
+
paused = false;
|
|
41
|
+
handed = undefined;
|
|
42
|
+
current = undefined;
|
|
43
|
+
};
|
|
44
|
+
const self = {
|
|
45
|
+
get current() {
|
|
46
|
+
return current;
|
|
47
|
+
},
|
|
48
|
+
offer(notice, restore) {
|
|
49
|
+
clear();
|
|
50
|
+
current = { notice, restore };
|
|
51
|
+
latest = self;
|
|
52
|
+
lapse();
|
|
53
|
+
},
|
|
54
|
+
hand(el) {
|
|
55
|
+
if (!current || !el)
|
|
56
|
+
return;
|
|
57
|
+
handed = el;
|
|
58
|
+
const release = () => {
|
|
59
|
+
if (handed === el)
|
|
60
|
+
handed = undefined;
|
|
61
|
+
el.removeEventListener('input', release);
|
|
62
|
+
el.removeEventListener('focusout', release);
|
|
63
|
+
};
|
|
64
|
+
el.addEventListener('input', release);
|
|
65
|
+
el.addEventListener('focusout', release);
|
|
66
|
+
},
|
|
67
|
+
accepts(target, root) {
|
|
68
|
+
if (!current || !(target instanceof Element))
|
|
69
|
+
return false;
|
|
70
|
+
if (target === document.body)
|
|
71
|
+
return latest === self;
|
|
72
|
+
if (target === handed)
|
|
73
|
+
return true;
|
|
74
|
+
return !!root?.contains(target) && !target.closest(EDITABLE);
|
|
75
|
+
},
|
|
76
|
+
pause() {
|
|
77
|
+
if (!current || paused)
|
|
78
|
+
return;
|
|
79
|
+
paused = true;
|
|
80
|
+
stop();
|
|
81
|
+
},
|
|
82
|
+
resume() {
|
|
83
|
+
if (!current || !paused)
|
|
84
|
+
return;
|
|
85
|
+
paused = false;
|
|
86
|
+
lapse();
|
|
87
|
+
},
|
|
88
|
+
take() {
|
|
89
|
+
const offer = current;
|
|
90
|
+
clear();
|
|
91
|
+
if (!offer)
|
|
92
|
+
return false;
|
|
93
|
+
offer.restore();
|
|
94
|
+
return true;
|
|
95
|
+
},
|
|
96
|
+
withdraw: clear,
|
|
97
|
+
dispose: clear
|
|
98
|
+
};
|
|
99
|
+
return self;
|
|
100
|
+
}
|
|
101
|
+
const KEY = Symbol('qm.undo');
|
|
102
|
+
export function setStructuralUndo(undo) {
|
|
103
|
+
setContext(KEY, undo);
|
|
104
|
+
}
|
|
105
|
+
/** What a component rendered outside the editor gets: no offer, so it removes as it always did. */
|
|
106
|
+
const NO_UNDO = {
|
|
107
|
+
current: undefined,
|
|
108
|
+
offer() { },
|
|
109
|
+
hand() { },
|
|
110
|
+
accepts: () => false,
|
|
111
|
+
pause() { },
|
|
112
|
+
resume() { },
|
|
113
|
+
take: () => false,
|
|
114
|
+
withdraw() { }
|
|
115
|
+
};
|
|
116
|
+
/** The editor's undo, or {@link NO_UNDO} off-tree. */
|
|
117
|
+
export function structuralUndo() {
|
|
118
|
+
return getContext(KEY) ?? NO_UNDO;
|
|
119
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quillmark/svelte",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.0",
|
|
4
4
|
"description": "Editor, live-preview and source surfaces over a Quillmark WASM session.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"check": "svelte-check --tsconfig ./tsconfig.json --fail-on-warnings"
|
|
70
70
|
},
|
|
71
71
|
"peerDependencies": {
|
|
72
|
-
"@quillmark/wasm": ">=0.
|
|
72
|
+
"@quillmark/wasm": ">=0.135.0-0",
|
|
73
73
|
"svelte": "^5.33.0"
|
|
74
74
|
},
|
|
75
75
|
"dependencies": {
|
package/dist/visual/hold.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Run `change` and keep `anchor` inside the fold for the length of the move.
|
|
3
|
-
*
|
|
4
|
-
* A section closing above the pressed control carries that control off the fold with it,
|
|
5
|
-
* and what answers that is the trip every landing here already takes: the minimum, to the
|
|
6
|
-
* nearest edge, never a centring (VISUAL_EDITOR §"Focus and the preview bridge"). So a
|
|
7
|
-
* control the collapse never carries out of view costs no scroll at all, and one it would
|
|
8
|
-
* rides up and parks at the edge, which is where a section just opened wants its header:
|
|
9
|
-
* the fold below it is the room its fields unfold into, where a control held on the line
|
|
10
|
-
* it was pressed on opens its section into the screen it sits on the edge of.
|
|
11
|
-
*
|
|
12
|
-
* Per frame, because both panels move over the motion rung: a trip taken once is taken
|
|
13
|
-
* against a track that has not moved yet, the same flush a reveal's landing measures in
|
|
14
|
-
* (`Card.revealLeaf`). `instant`, because a host's `scroll-behavior: smooth` would
|
|
15
|
-
* otherwise animate each frame's correction toward the one before it.
|
|
16
|
-
*/
|
|
17
|
-
export declare function holdInView(anchor: HTMLElement | undefined, change: () => void): void;
|
package/dist/visual/hold.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
// The gesture's anchor, which scroll anchoring is not: the platform picks its anchor off
|
|
2
|
-
// the layout, and what fills the viewport as a section collapses is that section's own
|
|
3
|
-
// content, whose top never moves.
|
|
4
|
-
import { flushSync } from 'svelte';
|
|
5
|
-
import { rungMs, rungStyle } from '../core/rungs.js';
|
|
6
|
-
/**
|
|
7
|
-
* Run `change` and keep `anchor` inside the fold for the length of the move.
|
|
8
|
-
*
|
|
9
|
-
* A section closing above the pressed control carries that control off the fold with it,
|
|
10
|
-
* and what answers that is the trip every landing here already takes: the minimum, to the
|
|
11
|
-
* nearest edge, never a centring (VISUAL_EDITOR §"Focus and the preview bridge"). So a
|
|
12
|
-
* control the collapse never carries out of view costs no scroll at all, and one it would
|
|
13
|
-
* rides up and parks at the edge, which is where a section just opened wants its header:
|
|
14
|
-
* the fold below it is the room its fields unfold into, where a control held on the line
|
|
15
|
-
* it was pressed on opens its section into the screen it sits on the edge of.
|
|
16
|
-
*
|
|
17
|
-
* Per frame, because both panels move over the motion rung: a trip taken once is taken
|
|
18
|
-
* against a track that has not moved yet, the same flush a reveal's landing measures in
|
|
19
|
-
* (`Card.revealLeaf`). `instant`, because a host's `scroll-behavior: smooth` would
|
|
20
|
-
* otherwise animate each frame's correction toward the one before it.
|
|
21
|
-
*/
|
|
22
|
-
export function holdInView(anchor, change) {
|
|
23
|
-
if (!anchor)
|
|
24
|
-
return void change();
|
|
25
|
-
change();
|
|
26
|
-
flushSync();
|
|
27
|
-
const reveal = () => anchor.scrollIntoView({ block: 'nearest', behavior: 'instant' });
|
|
28
|
-
reveal();
|
|
29
|
-
const rung = rungMs(rungStyle(anchor), '--_qm-duration-slow');
|
|
30
|
-
if (rung === undefined)
|
|
31
|
-
return;
|
|
32
|
-
const until = performance.now() + rung;
|
|
33
|
-
const step = (now) => {
|
|
34
|
-
reveal();
|
|
35
|
-
if (now < until)
|
|
36
|
-
requestAnimationFrame(step);
|
|
37
|
-
};
|
|
38
|
-
requestAnimationFrame(step);
|
|
39
|
-
}
|