@quillmark/svelte 0.2.0 → 0.3.1
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/NOTICE +6 -6
- package/README.md +3 -3
- package/THEMING.md +12 -8
- package/dist/core/address.d.ts +7 -7
- package/dist/core/address.js +6 -6
- package/dist/core/bloom.d.ts +3 -32
- package/dist/core/bloom.js +19 -51
- package/dist/core/codec/anchor.d.ts +1 -1
- package/dist/core/codec/anchor.js +1 -1
- package/dist/core/codec/atoms.d.ts +10 -0
- package/dist/core/codec/atoms.js +78 -0
- package/dist/core/codec/clipboard.d.ts +59 -0
- package/dist/core/codec/clipboard.js +202 -0
- package/dist/core/codec/code.d.ts +1 -1
- package/dist/core/codec/code.js +4 -4
- package/dist/core/codec/decode.d.ts +1 -1
- package/dist/core/codec/decode.js +8 -8
- package/dist/core/codec/encode.d.ts +4 -4
- package/dist/core/codec/encode.js +10 -10
- package/dist/core/codec/field.d.ts +21 -26
- package/dist/core/codec/field.js +33 -32
- package/dist/core/codec/index.js +5 -8
- package/dist/core/codec/inputrules.js +56 -18
- package/dist/core/codec/islands.d.ts +11 -7
- package/dist/core/codec/islands.js +16 -10
- package/dist/core/codec/keymap.d.ts +5 -6
- package/dist/core/codec/keymap.js +8 -7
- package/dist/core/codec/lists.d.ts +3 -3
- package/dist/core/codec/lists.js +32 -13
- package/dist/core/codec/marks.d.ts +1 -1
- package/dist/core/codec/marks.js +1 -1
- package/dist/core/codec/positions.js +1 -1
- package/dist/core/codec/prose.css +235 -221
- package/dist/core/codec/schema.js +4 -4
- package/dist/core/codec/slash.d.ts +39 -41
- package/dist/core/codec/slash.js +0 -0
- package/dist/core/codec/table-view.d.ts +12 -16
- package/dist/core/codec/table-view.js +488 -292
- package/dist/core/codec/table.d.ts +42 -15
- package/dist/core/codec/table.js +70 -26
- package/dist/core/errors.d.ts +5 -5
- package/dist/core/index.js +2 -2
- package/dist/core/lifecycle.js +1 -1
- package/dist/core/rebind.svelte.d.ts +2 -2
- package/dist/core/rebind.svelte.js +4 -4
- package/dist/core/teardown.d.ts +1 -1
- package/dist/core/teardown.js +1 -1
- package/dist/core/theme.css +170 -64
- package/dist/preset/index.css +1 -1
- package/dist/preset/recipes.css +31 -29
- package/dist/preset/scale.css +37 -26
- package/dist/preview/Preview.svelte +17 -27
- package/dist/preview/Preview.svelte.d.ts +4 -5
- package/dist/preview/bridge.js +6 -6
- package/dist/preview/controller.d.ts +8 -10
- package/dist/preview/controller.js +19 -44
- package/dist/preview/geometry.d.ts +8 -10
- package/dist/preview/geometry.js +8 -10
- package/dist/preview/index.js +4 -4
- package/dist/preview/paint.d.ts +1 -1
- package/dist/preview/paint.js +17 -19
- package/dist/visual/ArrayField.svelte +80 -66
- package/dist/visual/ArrayField.svelte.d.ts +1 -1
- package/dist/visual/BooleanField.svelte +8 -6
- package/dist/visual/BooleanField.svelte.d.ts +2 -2
- package/dist/visual/Card.svelte +160 -329
- package/dist/visual/Card.svelte.d.ts +2 -7
- package/dist/visual/CardControls.svelte +1 -1
- package/dist/visual/DateField.svelte +19 -19
- package/dist/visual/DateField.svelte.d.ts +3 -3
- package/dist/visual/DiagnosticList.svelte +1 -1
- package/dist/visual/EnumField.svelte +16 -16
- package/dist/visual/EnumField.svelte.d.ts +2 -2
- package/dist/visual/Field.svelte +128 -115
- package/dist/visual/Field.svelte.d.ts +1 -1
- package/dist/visual/FieldHint.svelte +24 -42
- package/dist/visual/FieldHint.svelte.d.ts +1 -1
- package/dist/visual/FieldLabel.svelte +8 -8
- package/dist/visual/FormatPopover.svelte +80 -35
- package/dist/visual/NumberField.svelte +5 -5
- package/dist/visual/NumberField.svelte.d.ts +1 -1
- package/dist/visual/ObjectField.svelte +9 -9
- package/dist/visual/ObjectField.svelte.d.ts +1 -1
- package/dist/visual/ProseArrayElement.svelte +11 -13
- package/dist/visual/ProseArrayElement.svelte.d.ts +1 -1
- package/dist/visual/ProseField.svelte +53 -87
- package/dist/visual/ProseField.svelte.d.ts +13 -19
- package/dist/visual/SlashMenu.svelte +42 -16
- package/dist/visual/TextField.svelte +5 -5
- package/dist/visual/TextField.svelte.d.ts +1 -1
- package/dist/visual/TipsCard.svelte +68 -56
- package/dist/visual/VisualEditor.svelte +6 -6
- package/dist/visual/VisualEditorInner.svelte +203 -290
- package/dist/visual/controls.css +74 -30
- package/dist/visual/diagnostics.d.ts +5 -5
- package/dist/visual/diagnostics.js +3 -3
- package/dist/visual/domid.js +3 -3
- package/dist/visual/ext.d.ts +1 -1
- package/dist/visual/ext.js +1 -1
- package/dist/visual/icons/nodes.d.ts +19 -0
- package/dist/visual/icons/nodes.js +13 -1
- package/dist/visual/index.js +4 -4
- package/dist/visual/leaves.d.ts +3 -3
- package/dist/visual/leaves.js +1 -1
- package/dist/visual/links.d.ts +24 -0
- package/dist/visual/links.js +67 -0
- package/dist/visual/props.d.ts +8 -8
- package/dist/visual/signals.d.ts +6 -6
- package/dist/visual/strings.d.ts +14 -19
- package/dist/visual/strings.js +5 -7
- package/dist/visual/structure.d.ts +24 -17
- package/dist/visual/structure.js +8 -8
- package/dist/visual/synced.svelte.d.ts +1 -1
- package/dist/visual/synced.svelte.js +4 -4
- package/dist/visual/tips.d.ts +2 -2
- package/dist/visual/tips.js +3 -3
- package/package.json +2 -2
- package/dist/preview/overlay.d.ts +0 -11
- package/dist/preview/overlay.js +0 -97
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
<!--
|
|
2
2
|
One element of an array-of-`richtext` field (fixture `references`). Array
|
|
3
|
-
elements are
|
|
3
|
+
elements are not `applyChange`-addressable: `Addr.field` is a flat name, so
|
|
4
4
|
`references.0` has no op address. So
|
|
5
|
-
this is
|
|
5
|
+
this is not a `createField` leaf: it mounts a minimal PM view over the codec's
|
|
6
6
|
decode/encode + inline schema, and on every edit hands the re-encoded
|
|
7
|
-
`Content`
|
|
7
|
+
`Content` up to the parent {@link ArrayField}, which commits the whole array
|
|
8
8
|
by value (`writer.set(field, arrayWithElementReplaced)`). Anchors within an
|
|
9
9
|
element are dropped on that value write: acceptable for inline refs. Mounts
|
|
10
|
-
|
|
10
|
+
once per stable element id (no reset on the parent's re-derive).
|
|
11
11
|
-->
|
|
12
12
|
<script lang="ts">
|
|
13
13
|
import { onMount } from 'svelte';
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
label?: string;
|
|
25
25
|
onChange: (rt: Content) => void;
|
|
26
26
|
/** Raw keydown, for a container whose own keys run through this element: the
|
|
27
|
-
* array repeater's Enter/Backspace (`ArrayField`). Fires
|
|
27
|
+
* array repeater's Enter/Backspace (`ArrayField`). Fires before the view's own
|
|
28
28
|
* keymap, so the state it reads is the one this keystroke has yet to change. */
|
|
29
29
|
onKey?: (e: KeyboardEvent) => void;
|
|
30
30
|
}
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
|
|
33
33
|
let containerEl: HTMLDivElement | undefined = $state();
|
|
34
34
|
let view: EditorView | undefined;
|
|
35
|
-
/** Take the caret: what a parent placing focus on this element calls. The
|
|
35
|
+
/** Take the caret: what a parent placing focus on this element calls. The view's
|
|
36
36
|
* focus, not the element's: a PM view restores its selection, where a bare DOM
|
|
37
37
|
* focus on a contenteditable leaves the caret unplaced. */
|
|
38
38
|
export function focus(): void {
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
|
|
42
42
|
onMount(() => {
|
|
43
43
|
if (!containerEl) return;
|
|
44
|
-
// An array element is an inline, value-by-value leaf: the
|
|
44
|
+
// An array element is an inline, value-by-value leaf: the same keymap and
|
|
45
45
|
// plugin stack a `createField` leaf mounts (shared `proseLeafPlugins`), minus
|
|
46
46
|
// the anchor-position plugin (element anchors are dropped on the array's value
|
|
47
47
|
// write, per the header). Its own `dispatchTransaction` hands `Content` up.
|
|
@@ -79,15 +79,13 @@
|
|
|
79
79
|
an array of `string` render rows of equal height. No floor: the reset in
|
|
80
80
|
`core/codec/prose.css` makes one line of prose measure one line. Width is the
|
|
81
81
|
row's to give: the element fills the track it is placed in (`ArrayField`). -->
|
|
82
|
-
<div bind:this={containerEl} class="qm-array-prose qm-control-box"></div>
|
|
82
|
+
<div bind:this={containerEl} class="qm-array-prose qm-control-box qm-focus-ring-within"></div>
|
|
83
83
|
|
|
84
84
|
<style>
|
|
85
|
-
/* Caret-primary, matching ProseField: the contenteditable outline is
|
|
86
|
-
and the
|
|
85
|
+
/* Caret-primary, matching ProseField: the contenteditable's own outline is
|
|
86
|
+
dropped and the ring rides the wrapper (`qm-focus-ring-within`,
|
|
87
|
+
controls.css), which is where the box is. */
|
|
87
88
|
.qm-array-prose :global(.ProseMirror) {
|
|
88
89
|
outline: none;
|
|
89
90
|
}
|
|
90
|
-
.qm-array-prose:focus-within {
|
|
91
|
-
border-color: var(--_qm-accent);
|
|
92
|
-
}
|
|
93
91
|
</style>
|
|
@@ -7,7 +7,7 @@ interface Props {
|
|
|
7
7
|
label?: string;
|
|
8
8
|
onChange: (rt: Content) => void;
|
|
9
9
|
/** Raw keydown, for a container whose own keys run through this element: the
|
|
10
|
-
* array repeater's Enter/Backspace (`ArrayField`). Fires
|
|
10
|
+
* array repeater's Enter/Backspace (`ArrayField`). Fires before the view's own
|
|
11
11
|
* keymap, so the state it reads is the one this keystroke has yet to change. */
|
|
12
12
|
onKey?: (e: KeyboardEvent) => void;
|
|
13
13
|
}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
<!--
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
`addr` is supplied by the parent as a LIVE object (its `card` a getter over the
|
|
7
|
-
stable-id→index map), so a card reorder re-targets this leaf's commits without
|
|
8
|
-
a remount: the caret rides the untouched PM view.
|
|
2
|
+
A Svelte mount of the codec's `createField` (VISUAL_EDITOR §Surface), which owns the
|
|
3
|
+
PM state, the history and the per-keystroke commit, leaving this wrapper wiring and
|
|
4
|
+
registration. `addr` is a live object the parent builds, so a card reorder re-targets
|
|
5
|
+
this leaf's commits with the caret riding the untouched view.
|
|
9
6
|
-->
|
|
10
7
|
<script lang="ts">
|
|
11
8
|
import { onMount } from 'svelte';
|
|
@@ -20,44 +17,38 @@
|
|
|
20
17
|
interface Props {
|
|
21
18
|
doc: Document;
|
|
22
19
|
/** The schema this leaf reads its content through: `createField` binds a reader
|
|
23
|
-
* off it, so a stored string decodes by declared type
|
|
20
|
+
* off it, so a stored string decodes by its declared type. */
|
|
24
21
|
quill: Quill;
|
|
25
22
|
addr: Addr;
|
|
26
23
|
inline?: boolean;
|
|
27
24
|
plaintext?: boolean;
|
|
28
25
|
/**
|
|
29
|
-
* Draw no box: the card body's leaf, and nothing else.
|
|
30
|
-
*
|
|
31
|
-
* a
|
|
32
|
-
* row of controls. Only the body is paper, and only its caller knows it is.
|
|
26
|
+
* Draw no box: the card body's leaf, and nothing else. Not `block`, which is a
|
|
27
|
+
* different predicate: a `richtext` field without `inline` is block prose and
|
|
28
|
+
* still a control in a row of controls, so only the caller knows what is paper.
|
|
33
29
|
*/
|
|
34
30
|
unframed?: boolean;
|
|
35
|
-
/** Accessible name for a leaf
|
|
36
|
-
* card body. A leaf with a field label takes `labelledBy
|
|
31
|
+
/** Accessible name for a leaf nothing else names: an array element, or the
|
|
32
|
+
* card body. A leaf with a field label takes `labelledBy`. */
|
|
37
33
|
label?: string;
|
|
38
34
|
/** The field label's own id → `aria-labelledby` on the editable region. `for`
|
|
39
|
-
* cannot reach a `contenteditable
|
|
40
|
-
*
|
|
41
|
-
* the controller's `focus`. */
|
|
35
|
+
* cannot reach a `contenteditable`, so the association runs the other way and
|
|
36
|
+
* the label's click comes back through the controller's `focus`. */
|
|
42
37
|
labelledBy?: string;
|
|
43
38
|
/** The parked `description` (FieldLabel) → `aria-describedby`. */
|
|
44
39
|
describedBy?: string;
|
|
45
|
-
/** Ghost shown on the empty leaf
|
|
46
|
-
*
|
|
47
|
-
* (`resolveBodyGhost`). Reactive: a change is pushed into the mounted view,
|
|
48
|
-
* never a remount. */
|
|
40
|
+
/** Ghost shown on the empty leaf: an inline leaf's resolved `default:` or
|
|
41
|
+
* nothing, a body's always text (`resolveBodyGhost`). */
|
|
49
42
|
placeholder?: string;
|
|
50
|
-
/**
|
|
51
|
-
* visible as one. */
|
|
43
|
+
/** Registry identity, stamped on the DOM node so a remount is visible as one. */
|
|
52
44
|
leafKey: string;
|
|
53
45
|
onFocus?: (addr: Addr) => void;
|
|
54
46
|
onCaretMove?: (addr: Addr, pos: number) => void;
|
|
55
47
|
/** A commit landed on this leaf: the prose change lane. */
|
|
56
48
|
onChange?: (addr: Addr) => void;
|
|
57
49
|
onError?: EditorErrorHandler;
|
|
58
|
-
/** The editor's leaf registry (`leaves.ts`).
|
|
59
|
-
*
|
|
60
|
-
* of, which is what makes this leaf a caret target and not merely a focus one. */
|
|
50
|
+
/** The editor's leaf registry (`leaves.ts`). Registering the controller is what
|
|
51
|
+
* makes this leaf a caret target and not merely a focus one. */
|
|
61
52
|
leaves?: LeafRegistry;
|
|
62
53
|
}
|
|
63
54
|
|
|
@@ -82,33 +73,24 @@
|
|
|
82
73
|
|
|
83
74
|
let containerEl: HTMLDivElement | undefined = $state();
|
|
84
75
|
|
|
85
|
-
//
|
|
86
|
-
//
|
|
87
|
-
// mounted table without remounting the leaf and losing the caret.
|
|
76
|
+
// Handed to the codec as a getter: the island chrome redraws on each render, so a
|
|
77
|
+
// locale swap reaches a mounted table without remounting the leaf and losing the caret.
|
|
88
78
|
const t = wording();
|
|
89
79
|
|
|
90
|
-
/**
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
* leaf is active. A constrained leaf never receives one (`createField` mounts the
|
|
94
|
-
* trigger on the block schema alone). */
|
|
80
|
+
/** Pushed by the leaf's trigger plugin: the menu is the leaf's surface rather than
|
|
81
|
+
* the shell's (VISUAL_EDITOR §Chrome). A constrained leaf never receives one, the
|
|
82
|
+
* trigger mounting on the block schema alone. */
|
|
95
83
|
let slash: SlashState | undefined = $state();
|
|
96
84
|
|
|
97
|
-
//
|
|
98
|
-
//
|
|
99
|
-
//
|
|
100
|
-
// `plaintext`-only field would take the body's floor while holding one paragraph.
|
|
85
|
+
// The codec's own schema predicate (`createField`: `plaintext` implies `inline`), so
|
|
86
|
+
// the box a leaf draws and the schema it holds cannot disagree. On `inline` alone a
|
|
87
|
+
// `plaintext` field would take the block floor while holding one paragraph.
|
|
101
88
|
const block = $derived(!(inline || plaintext));
|
|
102
89
|
|
|
103
|
-
// An absent richtext field (a `default:`-only field like `tag_line`) is handled
|
|
104
|
-
// by the codec itself: `createField` decodes an empty content and overwrites on
|
|
105
|
-
// the first edit; so this wrapper adds no pre-seeding, and an untouched field
|
|
106
|
-
// stays absent (its default rendering intact) until actually edited.
|
|
107
90
|
let controller: FieldController | undefined;
|
|
108
91
|
|
|
109
|
-
/**
|
|
110
|
-
*
|
|
111
|
-
* the wrapper leaves unplaced. */
|
|
92
|
+
/** What the label's click calls. The controller's focus, not the container's, which
|
|
93
|
+
* leaves the PM selection unplaced. */
|
|
112
94
|
export function focus(): void {
|
|
113
95
|
controller?.focus();
|
|
114
96
|
}
|
|
@@ -127,7 +109,6 @@
|
|
|
127
109
|
describedBy,
|
|
128
110
|
placeholder,
|
|
129
111
|
tableStrings: () => t.strings,
|
|
130
|
-
slashStrings: () => t.strings,
|
|
131
112
|
onSlash: (next) => {
|
|
132
113
|
slash = next;
|
|
133
114
|
},
|
|
@@ -144,10 +125,8 @@
|
|
|
144
125
|
};
|
|
145
126
|
});
|
|
146
127
|
|
|
147
|
-
//
|
|
148
|
-
//
|
|
149
|
-
// the old kind's wording. Push it instead: the caret is worth more than the
|
|
150
|
-
// simplicity of rebuilding.
|
|
128
|
+
// A retype does not remount the leaf (its key is the card's session id), so the new
|
|
129
|
+
// kind's ghost is pushed into the live view rather than paid for with the caret.
|
|
151
130
|
$effect(() => {
|
|
152
131
|
controller?.setPlaceholder(placeholder);
|
|
153
132
|
});
|
|
@@ -157,59 +136,46 @@
|
|
|
157
136
|
bind:this={containerEl}
|
|
158
137
|
class="qm-prose"
|
|
159
138
|
class:qm-control-box={!unframed}
|
|
139
|
+
class:qm-focus-ring-within={!unframed}
|
|
160
140
|
class:qm-prose-block={block}
|
|
161
141
|
data-leaf-key={leafKey}
|
|
162
142
|
></div>
|
|
163
143
|
<SlashMenu menu={slash} leaf={() => controller} label={t.strings.slashLabel} />
|
|
164
144
|
|
|
165
145
|
<style>
|
|
166
|
-
/* The box is `.qm-control-box` (controls.css)
|
|
167
|
-
draws, so the two agree on height by construction
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
prose in this box measures one line of text in that one. */
|
|
146
|
+
/* The box is `.qm-control-box` (controls.css), the same rule the input beside it
|
|
147
|
+
draws, so the two agree on height by construction. No `min-height` with it:
|
|
148
|
+
`core/codec/prose.css` resets the paragraph box, so one line of prose in this box
|
|
149
|
+
measures one line of text in that one. */
|
|
171
150
|
.qm-prose {
|
|
172
|
-
/*
|
|
173
|
-
inset child, so it covers the text without fading it or tinting the leaf's
|
|
174
|
-
own surface. */
|
|
151
|
+
/* Containing block for the arrival wash's inset child (`core/bloom.ts`). */
|
|
175
152
|
position: relative;
|
|
176
153
|
}
|
|
177
|
-
/* A leaf the inline schema does
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
.qm-prose-block {
|
|
185
|
-
min-height: calc(1em * var(--_qm-leading-body)
|
|
154
|
+
/* A leaf the inline schema does not constrain grows, and opens at one line box: the
|
|
155
|
+
empty leaf is the height its first line will take, so the first keystroke displaces
|
|
156
|
+
nothing below it. `1em`, not a size rung, which is the rule below's to name.
|
|
157
|
+
|
|
158
|
+
On the editable rather than on the wrapper, which is what makes that line part of the
|
|
159
|
+
body: height the wrapper holds is height outside the `contenteditable`, where a press
|
|
160
|
+
lands no caret. */
|
|
161
|
+
.qm-prose-block :global(.ProseMirror) {
|
|
162
|
+
min-height: calc(1em * var(--_qm-leading-body));
|
|
186
163
|
}
|
|
187
|
-
/*
|
|
188
|
-
declare, so a schema omitting it on a richtext field puts a block leaf in
|
|
189
|
-
row, where
|
|
190
|
-
construction. */
|
|
164
|
+
/* Paper, and the withheld box is what says so. Not `block` alone: `inline` is the
|
|
165
|
+
quill's to declare, so a schema omitting it on a richtext field puts a block leaf in
|
|
166
|
+
a field row, where this rung would break the height agreement above. */
|
|
191
167
|
.qm-prose-block:not(.qm-control-box) {
|
|
192
168
|
font-size: var(--_qm-text-paper);
|
|
193
169
|
}
|
|
194
|
-
/* The caret is the
|
|
195
|
-
|
|
196
|
-
|
|
170
|
+
/* The caret is the body's focus indicator: a ring around the one surface in a card
|
|
171
|
+
that is paper reads as form chrome. So the contenteditable's own outline is dropped
|
|
172
|
+
everywhere, and a boxed leaf takes the shared ring on its wrapper instead
|
|
173
|
+
(`qm-focus-ring-within`, controls.css). */
|
|
197
174
|
.qm-prose :global(.ProseMirror) {
|
|
198
175
|
outline: none;
|
|
199
176
|
}
|
|
200
|
-
/*
|
|
201
|
-
|
|
202
|
-
Scoped to the leaves that HAVE a hairline: the body has none, and the caret is
|
|
203
|
-
the whole indicator there: one surface per card, and the largest in it, so
|
|
204
|
-
"which leaf am I in" is not a question it raises. A rule drawn to answer it
|
|
205
|
-
would be a stroke bought back to replace the one unframing removed. */
|
|
206
|
-
.qm-prose.qm-control-box:focus-within {
|
|
207
|
-
border-color: var(--_qm-accent);
|
|
208
|
-
}
|
|
209
|
-
/* Empty-leaf ghost: the resolved `default:` as dim/italic ghost,
|
|
210
|
-
matching the scalar ghost rung. Rendered from a node decoration's data attr so
|
|
211
|
-
it stays out of the
|
|
212
|
-
document; `float`/`height:0` keep it from displacing the caret. */
|
|
177
|
+
/* Empty-leaf ghost, at the scalar ghost rung: a node decoration's data attr, so it
|
|
178
|
+
stays out of the document; `float`/`height: 0` keep it from displacing the caret. */
|
|
213
179
|
.qm-prose :global(.ProseMirror .qm-prose-placeholder::before) {
|
|
214
180
|
content: attr(data-placeholder);
|
|
215
181
|
color: var(--_qm-ink-ghost);
|
|
@@ -5,44 +5,38 @@ import type { EditorErrorHandler } from '../core/errors.js';
|
|
|
5
5
|
interface Props {
|
|
6
6
|
doc: Document;
|
|
7
7
|
/** The schema this leaf reads its content through: `createField` binds a reader
|
|
8
|
-
* off it, so a stored string decodes by declared type
|
|
8
|
+
* off it, so a stored string decodes by its declared type. */
|
|
9
9
|
quill: Quill;
|
|
10
10
|
addr: Addr;
|
|
11
11
|
inline?: boolean;
|
|
12
12
|
plaintext?: boolean;
|
|
13
13
|
/**
|
|
14
|
-
* Draw no box: the card body's leaf, and nothing else.
|
|
15
|
-
*
|
|
16
|
-
* a
|
|
17
|
-
* row of controls. Only the body is paper, and only its caller knows it is.
|
|
14
|
+
* Draw no box: the card body's leaf, and nothing else. Not `block`, which is a
|
|
15
|
+
* different predicate: a `richtext` field without `inline` is block prose and
|
|
16
|
+
* still a control in a row of controls, so only the caller knows what is paper.
|
|
18
17
|
*/
|
|
19
18
|
unframed?: boolean;
|
|
20
|
-
/** Accessible name for a leaf
|
|
21
|
-
* card body. A leaf with a field label takes `labelledBy
|
|
19
|
+
/** Accessible name for a leaf nothing else names: an array element, or the
|
|
20
|
+
* card body. A leaf with a field label takes `labelledBy`. */
|
|
22
21
|
label?: string;
|
|
23
22
|
/** The field label's own id → `aria-labelledby` on the editable region. `for`
|
|
24
|
-
* cannot reach a `contenteditable
|
|
25
|
-
*
|
|
26
|
-
* the controller's `focus`. */
|
|
23
|
+
* cannot reach a `contenteditable`, so the association runs the other way and
|
|
24
|
+
* the label's click comes back through the controller's `focus`. */
|
|
27
25
|
labelledBy?: string;
|
|
28
26
|
/** The parked `description` (FieldLabel) → `aria-describedby`. */
|
|
29
27
|
describedBy?: string;
|
|
30
|
-
/** Ghost shown on the empty leaf
|
|
31
|
-
*
|
|
32
|
-
* (`resolveBodyGhost`). Reactive: a change is pushed into the mounted view,
|
|
33
|
-
* never a remount. */
|
|
28
|
+
/** Ghost shown on the empty leaf: an inline leaf's resolved `default:` or
|
|
29
|
+
* nothing, a body's always text (`resolveBodyGhost`). */
|
|
34
30
|
placeholder?: string;
|
|
35
|
-
/**
|
|
36
|
-
* visible as one. */
|
|
31
|
+
/** Registry identity, stamped on the DOM node so a remount is visible as one. */
|
|
37
32
|
leafKey: string;
|
|
38
33
|
onFocus?: (addr: Addr) => void;
|
|
39
34
|
onCaretMove?: (addr: Addr, pos: number) => void;
|
|
40
35
|
/** A commit landed on this leaf: the prose change lane. */
|
|
41
36
|
onChange?: (addr: Addr) => void;
|
|
42
37
|
onError?: EditorErrorHandler;
|
|
43
|
-
/** The editor's leaf registry (`leaves.ts`).
|
|
44
|
-
*
|
|
45
|
-
* of, which is what makes this leaf a caret target and not merely a focus one. */
|
|
38
|
+
/** The editor's leaf registry (`leaves.ts`). Registering the controller is what
|
|
39
|
+
* makes this leaf a caret target and not merely a focus one. */
|
|
46
40
|
leaves?: LeafRegistry;
|
|
47
41
|
}
|
|
48
42
|
declare const ProseField: import("svelte").Component<Props, {
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
<!--
|
|
2
2
|
The slash menu. The leaf's own surface, not the
|
|
3
3
|
shell's: the trigger belongs to one caret in one leaf, so it is mounted by
|
|
4
|
-
`ProseField` beside the view it reads from, unlike the
|
|
4
|
+
`ProseField` beside the view it reads from, unlike the one shell-owned format
|
|
5
5
|
popover that follows whichever leaf is active.
|
|
6
6
|
|
|
7
|
-
The
|
|
7
|
+
The model is the codec's (`codec/slash.ts`: the trigger run, the query, the
|
|
8
8
|
highlighted index, and what each pick does). This component draws it and nothing
|
|
9
9
|
else. The keys are the leaf's keymap for the same reason: the caret stays in the
|
|
10
10
|
contenteditable while the menu is open, so a focus-taking listbox would move the
|
|
11
|
-
selection the insert is measured against. What is left here is the
|
|
12
|
-
buttons that pick, and that swallow their own mousedown so the caret stays put.
|
|
11
|
+
selection the insert is measured against. What is left here is mostly the pointer's
|
|
12
|
+
half: buttons that pick, and that swallow their own mousedown so the caret stays put.
|
|
13
13
|
|
|
14
|
-
The highlight has
|
|
15
|
-
index names, and a pointer entering an item
|
|
14
|
+
The highlight has one lane: `data-highlighted` marks whichever item the codec's
|
|
15
|
+
index names, and a pointer entering an item moves that index rather than painting a
|
|
16
16
|
second highlight the keyboard cannot reach (controls.css, the shared menu recipe).
|
|
17
|
+
The keyboard's one claim here is the scroll: the arrows move an index, and only the
|
|
18
|
+
chrome knows the port that index has to stay inside.
|
|
17
19
|
-->
|
|
18
20
|
<script lang="ts">
|
|
19
21
|
import { Popover } from 'bits-ui';
|
|
@@ -32,7 +34,7 @@
|
|
|
32
34
|
let { menu, leaf, label }: Props = $props();
|
|
33
35
|
|
|
34
36
|
/** Raised whenever the codec reports offers. Mirrored into local state rather than
|
|
35
|
-
* derived, because the primitive
|
|
37
|
+
* derived, because the primitive owns this prop: its own dismissal layer (an
|
|
36
38
|
* outside press) writes it, and a derived it cannot write to is an error rather
|
|
37
39
|
* than a dismissal. The next report re-syncs, so the codec stays the authority on
|
|
38
40
|
* whether a run is live. */
|
|
@@ -41,11 +43,21 @@
|
|
|
41
43
|
open = !!menu && menu.items.length > 0;
|
|
42
44
|
});
|
|
43
45
|
|
|
44
|
-
/** The root to portal
|
|
46
|
+
/** The root to portal into, resolved from the leaf's own DOM so the menu lands
|
|
45
47
|
* inside whichever `[data-qm-root]` raised it and inherits the consumer's dials;
|
|
46
48
|
* `undefined` falls back to bits-ui's `document.body`. */
|
|
47
49
|
const portalTarget = $derived(leaf()?.el.closest<HTMLElement>('[data-qm-root]') ?? undefined);
|
|
48
50
|
|
|
51
|
+
let surface = $state<HTMLElement | undefined>();
|
|
52
|
+
|
|
53
|
+
/** Keep the keyboard's cursor in the port: the arrows move an index rather than a
|
|
54
|
+
* focus, so a row the list scrolled past has nothing bringing it back. `nearest`
|
|
55
|
+
* scrolls the least that works, and no ancestor the row is already visible in. */
|
|
56
|
+
$effect(() => {
|
|
57
|
+
void menu?.index;
|
|
58
|
+
surface?.querySelector('[data-highlighted]')?.scrollIntoView({ block: 'nearest' });
|
|
59
|
+
});
|
|
60
|
+
|
|
49
61
|
/** Swallow the item's own mousedown: without it the browser focuses the item and
|
|
50
62
|
* blurs the leaf, taking the trigger run's caret with it. */
|
|
51
63
|
function keepFocus(e: MouseEvent): void {
|
|
@@ -55,12 +67,17 @@
|
|
|
55
67
|
|
|
56
68
|
<Popover.Root bind:open>
|
|
57
69
|
<Popover.Portal to={portalTarget}>
|
|
70
|
+
<!-- Hung off the trigger and flush against it: the anchor is the `/` itself
|
|
71
|
+
(`codec/slash.ts`), so the surface's top left corner sits at the line's bottom
|
|
72
|
+
edge under the character that opened the menu, and stays there as the query is
|
|
73
|
+
typed. Zero offset, because a gap reads as a surface floating near the caret
|
|
74
|
+
rather than one growing out of it. -->
|
|
58
75
|
<Popover.Content
|
|
59
76
|
customAnchor={menu?.anchor ?? null}
|
|
60
77
|
side="bottom"
|
|
61
78
|
align="start"
|
|
62
79
|
trapFocus={false}
|
|
63
|
-
sideOffset={
|
|
80
|
+
sideOffset={0}
|
|
64
81
|
onOpenAutoFocus={(e: Event) => e.preventDefault()}
|
|
65
82
|
onCloseAutoFocus={(e: Event) => e.preventDefault()}
|
|
66
83
|
>
|
|
@@ -74,22 +91,26 @@
|
|
|
74
91
|
a thing to click, tab into, or read. -->
|
|
75
92
|
<div
|
|
76
93
|
{...props}
|
|
94
|
+
bind:this={surface}
|
|
77
95
|
class="qm-slash-menu qm-menu-surface"
|
|
78
96
|
data-qm-root
|
|
79
97
|
role="group"
|
|
80
98
|
aria-label={label}
|
|
81
99
|
inert={!raised}
|
|
82
100
|
>
|
|
83
|
-
|
|
101
|
+
<!-- The row is the command as typed, leading `/` and all: the menu is a
|
|
102
|
+
completion of the run in the text, so the row and the run read the
|
|
103
|
+
same. -->
|
|
104
|
+
{#each menu?.items ?? [] as name, i (name)}
|
|
84
105
|
<button
|
|
85
106
|
type="button"
|
|
86
107
|
class="qm-menu-item qm-slash-item"
|
|
87
108
|
data-highlighted={i === menu?.index ? '' : undefined}
|
|
88
109
|
onmousedown={keepFocus}
|
|
89
|
-
onclick={() => leaf()?.slashPick(
|
|
90
|
-
onpointerenter={() => leaf()?.slashFocus(
|
|
110
|
+
onclick={() => leaf()?.slashPick(name)}
|
|
111
|
+
onpointerenter={() => leaf()?.slashFocus(name)}
|
|
91
112
|
>
|
|
92
|
-
{
|
|
113
|
+
/{name}
|
|
93
114
|
</button>
|
|
94
115
|
{/each}
|
|
95
116
|
</div>
|
|
@@ -104,20 +125,25 @@
|
|
|
104
125
|
`.qm-menu-surface` / `.qm-menu-item` (controls.css): the same recipe the enum
|
|
105
126
|
listbox and the card stack's kind menu draw, because all three are lists picked
|
|
106
127
|
from. What is here is this menu's own: a measure, so a long label does not stretch
|
|
107
|
-
the surface across the card,
|
|
128
|
+
the surface across the card, a scroll for a filtered list that stays long, and the
|
|
129
|
+
face. Monospace, where the sibling menus are not: they offer values of the document
|
|
130
|
+
and read as the prose around them, where these are commands, and the surface
|
|
131
|
+
already spells a literal in that face (the `code` mark, `codec/prose.css`). */
|
|
108
132
|
.qm-slash-menu {
|
|
109
133
|
min-width: 12rem;
|
|
110
134
|
max-height: 16rem;
|
|
111
135
|
overflow-y: auto;
|
|
136
|
+
font-family: var(--_qm-font-mono);
|
|
112
137
|
}
|
|
113
138
|
/* An item is a row of text, not a glyph: the whole row is the target, and the label
|
|
114
139
|
is the accessible name with nothing beside it. A button is a button, so the UA's
|
|
115
|
-
own box is taken back; what is left is the shared item recipe.
|
|
140
|
+
own box is taken back; what is left is the shared item recipe. The fill is not
|
|
141
|
+
taken back here: a scoped block is unlayered, so a reset would outrank the recipe's
|
|
142
|
+
highlight; the resting transparent is the recipe's own (controls.css). */
|
|
116
143
|
.qm-slash-item {
|
|
117
144
|
display: block;
|
|
118
145
|
width: 100%;
|
|
119
146
|
border: none;
|
|
120
|
-
background: none;
|
|
121
147
|
font: inherit;
|
|
122
148
|
color: inherit;
|
|
123
149
|
text-align: left;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
<!--
|
|
2
|
-
A `string` field → text input. Commits a non-empty edit
|
|
2
|
+
A `string` field → text input. Commits a non-empty edit live (on input) via the
|
|
3
3
|
parent's typed `writer.set`, so the preview tracks typing. A cleared field is the
|
|
4
|
-
|
|
4
|
+
unset rung of the commitment ladder (VISUAL_EDITOR §"Structure mirrors the schema"): it
|
|
5
5
|
commits `undefined` (the parent removes the field, ghosted `default:` renders):
|
|
6
|
-
but at `change` (blur),
|
|
6
|
+
but at `change` (blur), not per keystroke, so select-all-and-retype doesn't flash
|
|
7
7
|
the field through its default between the delete and the first typed char.
|
|
8
|
-
Trade-off (recorded in VISUAL_EDITOR): an explicit empty string
|
|
8
|
+
Trade-off (recorded in VISUAL_EDITOR): an explicit empty string over a non-empty
|
|
9
9
|
default is inexpressible from the UI: clear and unset collapse to one gesture.
|
|
10
10
|
-->
|
|
11
11
|
<script lang="ts">
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
interface Props {
|
|
16
16
|
value: string | undefined;
|
|
17
17
|
placeholder?: string;
|
|
18
|
-
/** Accessible name for an input
|
|
18
|
+
/** Accessible name for an input nothing else names: an array element, whose
|
|
19
19
|
* name is the field label plus its 1-based index. A field's own input takes
|
|
20
20
|
* `id` instead and is named by the `<label for>` beside it. */
|
|
21
21
|
label?: string;
|
|
@@ -2,7 +2,7 @@ import './controls.css';
|
|
|
2
2
|
interface Props {
|
|
3
3
|
value: string | undefined;
|
|
4
4
|
placeholder?: string;
|
|
5
|
-
/** Accessible name for an input
|
|
5
|
+
/** Accessible name for an input nothing else names: an array element, whose
|
|
6
6
|
* name is the field label plus its 1-based index. A field's own input takes
|
|
7
7
|
* `id` instead and is named by the `<label for>` beside it. */
|
|
8
8
|
label?: string;
|