@quillmark/svelte 0.30.0 → 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.
Files changed (42) hide show
  1. package/README.md +2 -2
  2. package/dist/core/codec/decode.d.ts +3 -2
  3. package/dist/core/codec/decode.js +15 -11
  4. package/dist/core/codec/field.d.ts +2 -1
  5. package/dist/core/codec/field.js +119 -30
  6. package/dist/core/codec/positions.d.ts +12 -1
  7. package/dist/core/codec/prose.css +0 -8
  8. package/dist/core/codec/schema.d.ts +2 -2
  9. package/dist/core/codec/schema.js +3 -3
  10. package/dist/core/codec/slash.d.ts +4 -2
  11. package/dist/core/codec/slash.js +11 -1
  12. package/dist/core/index.d.ts +1 -0
  13. package/dist/core/theme.css +14 -6
  14. package/dist/visual/ArrayField.svelte +167 -82
  15. package/dist/visual/BooleanField.svelte +2 -2
  16. package/dist/visual/Card.svelte +65 -44
  17. package/dist/visual/DateField.svelte +16 -1
  18. package/dist/visual/DiagnosticList.svelte +34 -2
  19. package/dist/visual/EnumField.svelte +58 -44
  20. package/dist/visual/Field.svelte +13 -3
  21. package/dist/visual/Field.svelte.d.ts +3 -1
  22. package/dist/visual/FieldHint.svelte +10 -3
  23. package/dist/visual/MatrixAdd.svelte +3 -18
  24. package/dist/visual/MatrixField.svelte +20 -12
  25. package/dist/visual/ObjectField.svelte +164 -145
  26. package/dist/visual/ProseField.svelte +6 -1
  27. package/dist/visual/SlashMenu.svelte +24 -12
  28. package/dist/visual/SlashMenu.svelte.d.ts +2 -0
  29. package/dist/visual/VisualEditor.svelte +1 -1
  30. package/dist/visual/VisualEditor.svelte.d.ts +1 -1
  31. package/dist/visual/VisualEditorInner.svelte +144 -9
  32. package/dist/visual/VisualEditorInner.svelte.d.ts +1 -1
  33. package/dist/visual/controls.css +42 -4
  34. package/dist/visual/strings.d.ts +27 -10
  35. package/dist/visual/strings.js +40 -6
  36. package/dist/visual/structure.d.ts +17 -9
  37. package/dist/visual/structure.js +19 -16
  38. package/dist/visual/undo.svelte.d.ts +36 -0
  39. package/dist/visual/undo.svelte.js +119 -0
  40. package/package.json +2 -2
  41. package/dist/visual/hold.d.ts +0 -17
  42. package/dist/visual/hold.js +0 -39
@@ -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.30.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.134.1-0 <0.135.0-0",
72
+ "@quillmark/wasm": ">=0.135.0-0",
73
73
  "svelte": "^5.33.0"
74
74
  },
75
75
  "dependencies": {
@@ -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;
@@ -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
- }