@quillmark/svelte 0.29.2 → 0.29.3
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 +1 -0
- package/THEMING.md +8 -6
- package/dist/core/bloom.d.ts +3 -2
- package/dist/core/bloom.js +6 -7
- package/dist/core/codec/field.js +2 -4
- package/dist/core/codec/index.d.ts +0 -3
- package/dist/core/codec/inputrules.d.ts +0 -3
- package/dist/core/codec/inputrules.js +1 -1
- package/dist/core/codec/islands.d.ts +0 -10
- package/dist/core/codec/islands.js +1 -1
- package/dist/core/codec/list-move.d.ts +0 -3
- package/dist/core/codec/list-move.js +2 -2
- package/dist/core/codec/list-node.d.ts +2 -0
- package/dist/core/codec/list-node.js +1 -0
- package/dist/core/codec/list-paste.js +1 -1
- package/dist/core/codec/markdown-paste.d.ts +0 -9
- package/dist/core/codec/markdown-paste.js +1 -1
- package/dist/core/codec/nesting.d.ts +0 -4
- package/dist/core/codec/nesting.js +1 -1
- package/dist/core/codec/prose.css +1 -1
- package/dist/core/codec/reveal.d.ts +14 -0
- package/dist/core/codec/reveal.js +40 -0
- package/dist/core/codec/slash.js +0 -0
- package/dist/core/codec/table-view.js +3 -3
- package/dist/core/codec/table.d.ts +0 -6
- package/dist/core/codec/table.js +1 -1
- package/dist/core/codec/touching.d.ts +0 -2
- package/dist/core/codec/touching.js +1 -11
- package/dist/preview/Preview.svelte +20 -1
- package/dist/preview/Preview.svelte.d.ts +1 -0
- package/dist/preview/controller.d.ts +5 -0
- package/dist/preview/controller.js +6 -0
- package/dist/preview/viewport.js +19 -1
- package/dist/preview/wash.d.ts +9 -0
- package/dist/preview/wash.js +38 -0
- package/dist/visual/ArrayField.svelte +17 -114
- package/dist/visual/MatrixField.svelte +15 -19
- package/dist/visual/ObjectField.svelte +10 -13
- package/dist/visual/guidance.d.ts +0 -12
- package/dist/visual/guidance.js +2 -2
- package/dist/visual/props.d.ts +2 -2
- package/dist/visual/rowdrag.svelte.d.ts +21 -0
- package/dist/visual/rowdrag.svelte.js +118 -0
- package/dist/visual/structure.d.ts +6 -6
- package/dist/visual/structure.js +17 -11
- package/package.json +2 -2
- package/dist/visual/checklists.d.ts +0 -3
- package/dist/visual/checklists.js +0 -7
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
baseType,
|
|
71
71
|
controlKind,
|
|
72
72
|
declaredContent,
|
|
73
|
-
|
|
73
|
+
fieldTitle,
|
|
74
74
|
literalText,
|
|
75
75
|
rowSummary,
|
|
76
76
|
schemaAt,
|
|
@@ -81,6 +81,7 @@
|
|
|
81
81
|
import { propertyDomIds } from './domid.js';
|
|
82
82
|
import type { LandingBox } from './leaves.js';
|
|
83
83
|
import { reorder, reorderArm } from './motion.js';
|
|
84
|
+
import { rowDrag } from './rowdrag.svelte.js';
|
|
84
85
|
import Icon from './icons/Icon.svelte';
|
|
85
86
|
import TextField from './TextField.svelte';
|
|
86
87
|
import ObjectField from './ObjectField.svelte';
|
|
@@ -266,7 +267,6 @@
|
|
|
266
267
|
// one, else this instance's own.
|
|
267
268
|
const uid = $props.id();
|
|
268
269
|
const countId = $derived(`${idBase ?? `qm-${uid}`}-count`);
|
|
269
|
-
const columnTitle = (key: string, sub: QuillFieldSchema): string => sub.title ?? humanize(key);
|
|
270
270
|
|
|
271
271
|
// The awaited flush below is the only work that outlives a gesture here, so the
|
|
272
272
|
// span carries the reorder's frame and nothing else: it is the liveness
|
|
@@ -536,7 +536,7 @@
|
|
|
536
536
|
* moves nothing, and never the record around it. A held drag owns the row until its
|
|
537
537
|
* release. */
|
|
538
538
|
function onRowKey(e: KeyboardEvent, k: number): void {
|
|
539
|
-
if (!e.altKey || e.shiftKey || e.ctrlKey || e.metaKey || e.isComposing || drag) return;
|
|
539
|
+
if (!e.altKey || e.shiftKey || e.ctrlKey || e.metaKey || e.isComposing || drag.held()) return;
|
|
540
540
|
// A cell that took the key — a select opening, a date segment stepping, a prose
|
|
541
541
|
// leaf joining — owns it.
|
|
542
542
|
if (e.defaultPrevented) return;
|
|
@@ -549,109 +549,12 @@
|
|
|
549
549
|
move(k, k + dir);
|
|
550
550
|
}
|
|
551
551
|
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
// reflows until the release (the lift is a tone and the drop rule is out of flow), and
|
|
559
|
-
// the release is the one splice `move` makes. A handle that loses the pointer, or
|
|
560
|
-
// leaves the DOM, ends the drag with no move.
|
|
561
|
-
const DEAD_ZONE = 3;
|
|
562
|
-
/** The band at a scrollport's top and bottom edges that scrolls it under a held drag,
|
|
563
|
-
* and the most one frame scrolls, reached at the edge itself. */
|
|
564
|
-
const EDGE = 48;
|
|
565
|
-
const STEP = 16;
|
|
566
|
-
type RowDrag = { k: number; origin: number; y: number; engaged: boolean; drop: number };
|
|
567
|
-
let drag = $state<RowDrag | undefined>();
|
|
568
|
-
let follow: { grip: Element; port: Element; armed: boolean; frame: number } | undefined;
|
|
569
|
-
function onHandleDown(e: PointerEvent, k: number): void {
|
|
570
|
-
if (e.button !== 0) return;
|
|
571
|
-
e.preventDefault();
|
|
572
|
-
release();
|
|
573
|
-
const grip = e.currentTarget as HTMLElement;
|
|
574
|
-
grip.setPointerCapture?.(e.pointerId);
|
|
575
|
-
drag = { k, origin: e.clientY, y: e.clientY, engaged: false, drop: k };
|
|
576
|
-
follow = { grip, port: scrollport(grip), armed: false, frame: 0 };
|
|
577
|
-
}
|
|
578
|
-
function onHandleMove(e: PointerEvent): void {
|
|
579
|
-
if (!drag) return;
|
|
580
|
-
drag.y = e.clientY;
|
|
581
|
-
if (!drag.engaged) {
|
|
582
|
-
if (Math.abs(e.clientY - drag.origin) < DEAD_ZONE) return;
|
|
583
|
-
drag.engaged = true;
|
|
584
|
-
addEventListener('scroll', repick, { capture: true, passive: true });
|
|
585
|
-
if (follow) follow.frame = requestAnimationFrame(edgeScroll);
|
|
586
|
-
}
|
|
587
|
-
repick();
|
|
588
|
-
}
|
|
589
|
-
function repick(): void {
|
|
590
|
-
if (drag?.engaged) drag.drop = dropIndex(drag.k, drag.y);
|
|
591
|
-
}
|
|
592
|
-
const rowBox = (i: number): DOMRect | undefined => rowEls[ids[i]]?.getBoundingClientRect();
|
|
593
|
-
/** The row the pointer is over, or the nearest one past either end. */
|
|
594
|
-
function dropIndex(k: number, y: number): number {
|
|
595
|
-
let best = k;
|
|
596
|
-
let nearest = Infinity;
|
|
597
|
-
ids.forEach((_, i) => {
|
|
598
|
-
const box = rowBox(i);
|
|
599
|
-
if (!box) return;
|
|
600
|
-
const gap = y < box.top ? box.top - y : y > box.bottom ? y - box.bottom : 0;
|
|
601
|
-
if (gap < nearest) {
|
|
602
|
-
nearest = gap;
|
|
603
|
-
best = i;
|
|
604
|
-
}
|
|
605
|
-
});
|
|
606
|
-
return best;
|
|
607
|
-
}
|
|
608
|
-
const page = (): Element => document.scrollingElement ?? document.documentElement;
|
|
609
|
-
/** The nearest ancestor that scrolls vertically, else the page. */
|
|
610
|
-
function scrollport(from: Element): Element {
|
|
611
|
-
for (let el = from.parentElement; el; el = el.parentElement) {
|
|
612
|
-
const { overflowY } = getComputedStyle(el);
|
|
613
|
-
if (/auto|scroll/.test(overflowY) && el.scrollHeight > el.clientHeight) return el;
|
|
614
|
-
}
|
|
615
|
-
return page();
|
|
616
|
-
}
|
|
617
|
-
function edgeScroll(): void {
|
|
618
|
-
if (!follow || !drag?.engaged) return;
|
|
619
|
-
if (!follow.grip.isConnected) {
|
|
620
|
-
drag = undefined;
|
|
621
|
-
release();
|
|
622
|
-
return;
|
|
623
|
-
}
|
|
624
|
-
const { port } = follow;
|
|
625
|
-
const box = port === page() ? undefined : port.getBoundingClientRect();
|
|
626
|
-
const top = Math.max(box?.top ?? 0, 0);
|
|
627
|
-
const bottom = Math.min(box?.bottom ?? innerHeight, innerHeight);
|
|
628
|
-
const into = Math.min(drag.y - top - EDGE, 0) + Math.max(drag.y - bottom + EDGE, 0);
|
|
629
|
-
if (!into) follow.armed = true;
|
|
630
|
-
// Only toward rows still out of view: past the list's end there is nothing to reach.
|
|
631
|
-
const beyond =
|
|
632
|
-
into < 0 ? (rowBox(0)?.top ?? top) < top : (rowBox(ids.length - 1)?.bottom ?? 0) > bottom;
|
|
633
|
-
if (into && follow.armed && beyond)
|
|
634
|
-
port.scrollBy({ top: STEP * Math.max(-1, Math.min(1, into / EDGE)), behavior: 'instant' });
|
|
635
|
-
follow.frame = requestAnimationFrame(edgeScroll);
|
|
636
|
-
}
|
|
637
|
-
function release(): void {
|
|
638
|
-
if (follow) cancelAnimationFrame(follow.frame);
|
|
639
|
-
follow = undefined;
|
|
640
|
-
removeEventListener('scroll', repick, { capture: true });
|
|
641
|
-
}
|
|
642
|
-
onDestroy(release);
|
|
643
|
-
function onHandleUp(e: PointerEvent): void {
|
|
644
|
-
const done = drag;
|
|
645
|
-
drag = undefined;
|
|
646
|
-
release();
|
|
647
|
-
if (!done?.engaged || e.type !== 'pointerup') return;
|
|
648
|
-
move(done.k, done.drop);
|
|
649
|
-
}
|
|
650
|
-
/** Where the drop rule draws on row `k`, while a drag would land the row there. */
|
|
651
|
-
function dropSide(k: number): 'before' | 'after' | undefined {
|
|
652
|
-
if (!drag?.engaged || drag.drop !== k || drag.drop === drag.k) return undefined;
|
|
653
|
-
return drag.drop > drag.k ? 'after' : 'before';
|
|
654
|
-
}
|
|
552
|
+
const drag = rowDrag({
|
|
553
|
+
count: () => ids.length,
|
|
554
|
+
box: (i) => rowEls[ids[i]]?.getBoundingClientRect(),
|
|
555
|
+
move
|
|
556
|
+
});
|
|
557
|
+
onDestroy(drag.release);
|
|
655
558
|
|
|
656
559
|
/** Whether cells stand past the table scroller's end edge, under the pinned remove,
|
|
657
560
|
* which is what the fade before the remove draws on. */
|
|
@@ -731,7 +634,7 @@
|
|
|
731
634
|
]}
|
|
732
635
|
>
|
|
733
636
|
<FieldLabel
|
|
734
|
-
label={
|
|
637
|
+
label={fieldTitle(key, sub)}
|
|
735
638
|
descriptionId={idBase != null ? propertyDomIds(idBase, key).description : undefined}
|
|
736
639
|
description={sub.description}
|
|
737
640
|
/>
|
|
@@ -775,9 +678,9 @@
|
|
|
775
678
|
<div
|
|
776
679
|
class={[
|
|
777
680
|
'qm-array-row qm-element qm-wash',
|
|
778
|
-
{ open: open.has(id), lifted: drag
|
|
681
|
+
{ open: open.has(id), lifted: drag.lifted(k) }
|
|
779
682
|
]}
|
|
780
|
-
data-drop={dropSide(k)}
|
|
683
|
+
data-drop={drag.dropSide(k)}
|
|
781
684
|
data-qm-index={k}
|
|
782
685
|
bind:this={rowEls[id]}
|
|
783
686
|
animate:reorder={arm.armed}
|
|
@@ -893,11 +796,11 @@
|
|
|
893
796
|
class="qm-row-handle"
|
|
894
797
|
aria-hidden="true"
|
|
895
798
|
title={t.strings.arrayDrag}
|
|
896
|
-
onpointerdown={(e) =>
|
|
897
|
-
onpointermove={
|
|
898
|
-
onpointerup={
|
|
899
|
-
onpointercancel={
|
|
900
|
-
onlostpointercapture={
|
|
799
|
+
onpointerdown={(e) => drag.down(e, k)}
|
|
800
|
+
onpointermove={drag.move}
|
|
801
|
+
onpointerup={drag.up}
|
|
802
|
+
onpointercancel={drag.up}
|
|
803
|
+
onlostpointercapture={drag.up}
|
|
901
804
|
><span class="qm-row-handle-bar"><Icon name="grip-vertical" /></span></span
|
|
902
805
|
>
|
|
903
806
|
{/snippet}
|
|
@@ -44,12 +44,12 @@
|
|
|
44
44
|
matrixEmpty,
|
|
45
45
|
matrixHeld,
|
|
46
46
|
matrixMembers,
|
|
47
|
-
|
|
47
|
+
matrixPrinted,
|
|
48
|
+
own,
|
|
48
49
|
memberWrite,
|
|
49
50
|
onRoster,
|
|
50
51
|
schemaAt
|
|
51
52
|
} from './structure.js';
|
|
52
|
-
import { matrixPrinted } from './checklists.js';
|
|
53
53
|
import { splitDeep, unrouted, type DeepDiagnostic } from './diagnostics.js';
|
|
54
54
|
import type { LandingBox } from './leaves.js';
|
|
55
55
|
import { propertyDomIds } from './domid.js';
|
|
@@ -106,7 +106,7 @@
|
|
|
106
106
|
const map = $derived(matrixPrinted(value, schema));
|
|
107
107
|
const defaulted = $derived(value == null && map != null && Object.keys(map).length > 0);
|
|
108
108
|
const added = $derived(addedItems(schema, map));
|
|
109
|
-
const held = (id: string): boolean => matrixHeld(
|
|
109
|
+
const held = (id: string): boolean => matrixHeld(own(map, id));
|
|
110
110
|
const heldCount = $derived(members.filter((m) => held(m.id)).length + added.length);
|
|
111
111
|
/** Whether `id` is an item this control draws: a roster member or a held added item. */
|
|
112
112
|
const drawn = (id: string): boolean =>
|
|
@@ -145,10 +145,6 @@
|
|
|
145
145
|
const colEls: Record<string, Subform | undefined> = $state({});
|
|
146
146
|
let rosterEl = $state<HTMLElement | undefined>();
|
|
147
147
|
let addEl = $state<{ focus: () => void } | undefined>();
|
|
148
|
-
/** A ref by member id, own keys only: an id can be spelled `constructor`. */
|
|
149
|
-
const ref = <T,>(refs: Record<string, T | undefined>, id: string): T | undefined =>
|
|
150
|
-
Object.hasOwn(refs, id) ? refs[id] : undefined;
|
|
151
|
-
|
|
152
148
|
/** The rows' content read: the boundary's, or, while the set is the default, the
|
|
153
149
|
* literal's own leaf at the codec its declared type names. */
|
|
154
150
|
function readAt(path: PathStep[]): Content | undefined {
|
|
@@ -167,7 +163,7 @@
|
|
|
167
163
|
}
|
|
168
164
|
/** The map with `id` unticked, its columns stashed for a retick. */
|
|
169
165
|
function unticked(id: string): Record<string, unknown> | undefined {
|
|
170
|
-
const columns = matrixColumns(
|
|
166
|
+
const columns = matrixColumns(own(map, id));
|
|
171
167
|
if (Object.keys(columns).length) stash.set(id, columns);
|
|
172
168
|
else stash.delete(id);
|
|
173
169
|
return commitMember(map, id, undefined);
|
|
@@ -188,11 +184,11 @@
|
|
|
188
184
|
commit(commitMember(map, id, memberWrite(columns, title)));
|
|
189
185
|
}
|
|
190
186
|
function itemTitle(id: string): string {
|
|
191
|
-
const stored =
|
|
187
|
+
const stored = own(map, id) as Record<string, unknown> | undefined;
|
|
192
188
|
return String(stored?.[MATRIX_TITLE] ?? '');
|
|
193
189
|
}
|
|
194
190
|
function retitle(id: string, title: string): void {
|
|
195
|
-
commit(commitMember(map, id, memberWrite(matrixColumns(
|
|
191
|
+
commit(commitMember(map, id, memberWrite(matrixColumns(own(map, id)), title)));
|
|
196
192
|
}
|
|
197
193
|
async function removeItem(id: string): Promise<void> {
|
|
198
194
|
const at = added.findIndex((item) => item.id === id);
|
|
@@ -200,7 +196,7 @@
|
|
|
200
196
|
await flush();
|
|
201
197
|
// The caret goes where the row was: the next added item, else the add box.
|
|
202
198
|
const next = added[at] ?? added[at - 1];
|
|
203
|
-
if (next)
|
|
199
|
+
if (next) own(titleEls, next.id)?.focus();
|
|
204
200
|
else addEl?.focus();
|
|
205
201
|
}
|
|
206
202
|
|
|
@@ -210,20 +206,20 @@
|
|
|
210
206
|
const id = addedId(title, taken);
|
|
211
207
|
commit(commitMember(map, id, memberWrite({}, title)));
|
|
212
208
|
await flush();
|
|
213
|
-
const box =
|
|
209
|
+
const box = own(memberEls, id);
|
|
214
210
|
// The item's columns are what the author came to fill; a checklist has none, and
|
|
215
211
|
// the box stays where the next item is typed.
|
|
216
212
|
const first = Object.keys(schema.properties ?? {})[0];
|
|
217
|
-
if (first !== undefined)
|
|
213
|
+
if (first !== undefined) own(colEls, id)?.focusPath([first]);
|
|
218
214
|
if (box) bloom(box);
|
|
219
215
|
}
|
|
220
216
|
|
|
221
217
|
/** Take the caret: the first item's control, else the add box. */
|
|
222
218
|
export function focus(): void {
|
|
223
219
|
const first = members[0];
|
|
224
|
-
if (first) return
|
|
220
|
+
if (first) return own(tickEls, first.id)?.focus();
|
|
225
221
|
const item = added[0];
|
|
226
|
-
if (item) return
|
|
222
|
+
if (item) return own(titleEls, item.id)?.focus();
|
|
227
223
|
addEl?.focus();
|
|
228
224
|
}
|
|
229
225
|
/** The box an arrival wash blooms in: the roster, not the label row above it, this
|
|
@@ -248,13 +244,13 @@
|
|
|
248
244
|
return undefined;
|
|
249
245
|
}
|
|
250
246
|
const column = rest[0];
|
|
251
|
-
const cells =
|
|
252
|
-
const member =
|
|
247
|
+
const cells = own(colEls, id);
|
|
248
|
+
const member = own(memberEls, id);
|
|
253
249
|
if (column !== undefined && column !== MATRIX_TITLE && cells) {
|
|
254
250
|
const inner = cells.focusPath(rest, pos);
|
|
255
251
|
return inner instanceof Promise ? inner.then((box) => box ?? member) : (inner ?? member);
|
|
256
252
|
}
|
|
257
|
-
(
|
|
253
|
+
(own(tickEls, id) ?? own(titleEls, id))?.focus();
|
|
258
254
|
return member;
|
|
259
255
|
}
|
|
260
256
|
</script>
|
|
@@ -363,7 +359,7 @@
|
|
|
363
359
|
{#if on && hasColumns}
|
|
364
360
|
<ObjectField
|
|
365
361
|
bind:this={colEls[id]}
|
|
366
|
-
value={matrixColumns(
|
|
362
|
+
value={matrixColumns(own(map, id))}
|
|
367
363
|
properties={schema.properties}
|
|
368
364
|
label={`${label ?? ''} ${title}`.trim()}
|
|
369
365
|
idBase={memberBase(id)}
|
|
@@ -41,11 +41,12 @@
|
|
|
41
41
|
controlKind,
|
|
42
42
|
declaredContent,
|
|
43
43
|
fieldModels,
|
|
44
|
-
|
|
44
|
+
fieldTitle,
|
|
45
45
|
isContainer,
|
|
46
46
|
literalText,
|
|
47
47
|
mountKey,
|
|
48
48
|
optionalCell,
|
|
49
|
+
own,
|
|
49
50
|
placeFields,
|
|
50
51
|
printedText,
|
|
51
52
|
renderedBoolean,
|
|
@@ -150,7 +151,6 @@
|
|
|
150
151
|
const routed = $derived(splitDeep(diagnostics));
|
|
151
152
|
const foot = $derived(unrouted(routed, (step) => typeof step === 'string' && has(step)));
|
|
152
153
|
|
|
153
|
-
const title = (key: string, sub: QuillFieldSchema): string => sub.title ?? humanize(key);
|
|
154
154
|
/** What an unset optional cell ghosts, which is what it prints: `none`. An answered
|
|
155
155
|
* cell ghosts nothing, an empty answer printing empty. */
|
|
156
156
|
const noneOf = (key: string, sub: QuillFieldSchema): string | undefined =>
|
|
@@ -163,7 +163,7 @@
|
|
|
163
163
|
/** The `aria-label` fallback, for a subform mounted without a field's id space:
|
|
164
164
|
* the field's name and the property's, since nothing else names the control. */
|
|
165
165
|
const fallbackName = (key: string, sub: QuillFieldSchema): string =>
|
|
166
|
-
`${label != null ? `${label} ` : ''}${
|
|
166
|
+
`${label != null ? `${label} ` : ''}${fieldTitle(key, sub)}`;
|
|
167
167
|
|
|
168
168
|
/** The handles of the cells the DOM cannot answer for, keyed by property name —
|
|
169
169
|
* which is stable, a subform drawing its properties by declaration and never by
|
|
@@ -186,9 +186,6 @@
|
|
|
186
186
|
| undefined
|
|
187
187
|
> = $state({});
|
|
188
188
|
let rootEl = $state<HTMLElement | undefined>();
|
|
189
|
-
/** A handle by property name, own keys only: a property can be named `constructor`. */
|
|
190
|
-
const ref = <T,>(map: Record<string, T | undefined>, key: string): T | undefined =>
|
|
191
|
-
Object.hasOwn(map, key) ? map[key] : undefined;
|
|
192
189
|
const FOCUSABLE = 'input, select, button, [tabindex]:not([tabindex="-1"])';
|
|
193
190
|
/** Take the caret: the first property that has somewhere to put it, in document
|
|
194
191
|
* order — a subform has no single control of its own to land on. An empty subform
|
|
@@ -210,9 +207,9 @@
|
|
|
210
207
|
focus();
|
|
211
208
|
return undefined;
|
|
212
209
|
}
|
|
213
|
-
const nested =
|
|
210
|
+
const nested = own(nestedEls, key);
|
|
214
211
|
if (nested) return nested.focusPath(rest, pos);
|
|
215
|
-
const prose =
|
|
212
|
+
const prose = own(proseEls, key);
|
|
216
213
|
if (prose) {
|
|
217
214
|
if (pos != null) prose.setCaret(pos);
|
|
218
215
|
else prose.focus();
|
|
@@ -239,7 +236,7 @@
|
|
|
239
236
|
/** Land in one property's cell, answering whether it took the caret. */
|
|
240
237
|
function landOn(cell: HTMLElement): boolean {
|
|
241
238
|
const key = cell.dataset.qmProp ?? '';
|
|
242
|
-
const owned =
|
|
239
|
+
const owned = own(nestedEls, key) ?? own(proseEls, key);
|
|
243
240
|
if (owned) {
|
|
244
241
|
owned.focus();
|
|
245
242
|
return true;
|
|
@@ -313,7 +310,7 @@
|
|
|
313
310
|
>
|
|
314
311
|
{#if ids && kind !== 'array' && kind !== 'matrix'}
|
|
315
312
|
<FieldLabel
|
|
316
|
-
label={
|
|
313
|
+
label={fieldTitle(key, sub)}
|
|
317
314
|
controlId={labelable ? ids.control : undefined}
|
|
318
315
|
id={ids.label}
|
|
319
316
|
descriptionId={describes}
|
|
@@ -410,7 +407,7 @@
|
|
|
410
407
|
items={sub.items}
|
|
411
408
|
layout={arrayLayout(sub)}
|
|
412
409
|
max={sub.max}
|
|
413
|
-
label={
|
|
410
|
+
label={fieldTitle(key, sub)}
|
|
414
411
|
description={sub.description}
|
|
415
412
|
labelId={ids?.label}
|
|
416
413
|
descriptionId={describes}
|
|
@@ -438,7 +435,7 @@
|
|
|
438
435
|
bind:this={nestedEls[key]}
|
|
439
436
|
value={obj[key] as Record<string, unknown> | undefined}
|
|
440
437
|
schema={sub}
|
|
441
|
-
label={
|
|
438
|
+
label={fieldTitle(key, sub)}
|
|
442
439
|
description={sub.description}
|
|
443
440
|
labelId={ids?.label}
|
|
444
441
|
descriptionId={describes}
|
|
@@ -453,7 +450,7 @@
|
|
|
453
450
|
value={obj[key] as Record<string, unknown> | undefined}
|
|
454
451
|
schema={sub}
|
|
455
452
|
ghostMember={sub.default as string | undefined}
|
|
456
|
-
label={
|
|
453
|
+
label={fieldTitle(key, sub)}
|
|
457
454
|
id={ids?.control}
|
|
458
455
|
labelledBy={ids?.label}
|
|
459
456
|
describedBy={describes}
|
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
/** `Mod-/`, read off `key` so a layout that shifts to reach `/` still matches; either
|
|
2
|
-
* modifier stands for `Mod`. */
|
|
3
|
-
export declare function isGuidanceKey(e: KeyboardEvent): boolean;
|
|
4
|
-
/**
|
|
5
|
-
* The guidance trigger for the description nearest `from`: the innermost element
|
|
6
|
-
* carrying `aria-describedby` whose ids name a parked description with a trigger
|
|
7
|
-
* beside it. A trigger points at its own parked node through that same attribute,
|
|
8
|
-
* which is the relation read here; ids that are not a description (an array's count,
|
|
9
|
-
* a prose leaf's note) are skipped, and an undescribed property falls through to the
|
|
10
|
-
* group around it.
|
|
11
|
-
*/
|
|
12
|
-
export declare function guidanceTrigger(from: Element, root: Element): HTMLElement | undefined;
|
|
13
1
|
/** Root keydown: the key raises (or lowers) the nearest guidance. A trigger's `click()`
|
|
14
2
|
* is an activation with no pointer behind it, which `FieldHint` toggles on. */
|
|
15
3
|
export declare function raiseGuidance(e: KeyboardEvent): void;
|
package/dist/visual/guidance.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// the keyboard's way in to a `FieldHint` whose glyph is out of the tab order.
|
|
3
3
|
/** `Mod-/`, read off `key` so a layout that shifts to reach `/` still matches; either
|
|
4
4
|
* modifier stands for `Mod`. */
|
|
5
|
-
|
|
5
|
+
function isGuidanceKey(e) {
|
|
6
6
|
return e.key === '/' && (e.ctrlKey || e.metaKey) && !e.altKey && !e.isComposing;
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
@@ -13,7 +13,7 @@ export function isGuidanceKey(e) {
|
|
|
13
13
|
* a prose leaf's note) are skipped, and an undescribed property falls through to the
|
|
14
14
|
* group around it.
|
|
15
15
|
*/
|
|
16
|
-
|
|
16
|
+
function guidanceTrigger(from, root) {
|
|
17
17
|
for (let el = from.closest('[aria-describedby]'); el;) {
|
|
18
18
|
for (const id of el.getAttribute('aria-describedby').split(/\s+/)) {
|
|
19
19
|
const trigger = root.querySelector(`.qm-field-hint[aria-describedby="${id}"]`);
|
package/dist/visual/props.d.ts
CHANGED
|
@@ -110,7 +110,7 @@ export interface VisualEditorProps {
|
|
|
110
110
|
/** Appended to the root's own class: the surface is a mounted element the
|
|
111
111
|
* consumer positions, so it needs a handle for layout it owns. */
|
|
112
112
|
class?: string;
|
|
113
|
-
/** Merged onto the root.
|
|
114
|
-
*
|
|
113
|
+
/** Merged onto the root. The theme derivation hangs off `data-qm-root`
|
|
114
|
+
* (core/theme.css), not this attribute. */
|
|
115
115
|
style?: string;
|
|
116
116
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** The list a drag reads and moves: its row count, row `i`'s box where it stands, and the
|
|
2
|
+
* splice a release makes. */
|
|
3
|
+
export interface DragRows {
|
|
4
|
+
count(): number;
|
|
5
|
+
box(i: number): DOMRect | undefined;
|
|
6
|
+
move(k: number, to: number): void;
|
|
7
|
+
}
|
|
8
|
+
export interface RowDrag {
|
|
9
|
+
/** Whether a press on a handle is held, engaged or not. */
|
|
10
|
+
held(): boolean;
|
|
11
|
+
/** Whether row `k` is the one an engaged drag carries. */
|
|
12
|
+
lifted(k: number): boolean;
|
|
13
|
+
/** Where the drop rule draws on row `k`, while a drag would land the row there. */
|
|
14
|
+
dropSide(k: number): 'before' | 'after' | undefined;
|
|
15
|
+
down(e: PointerEvent, k: number): void;
|
|
16
|
+
move(e: PointerEvent): void;
|
|
17
|
+
up(e: PointerEvent): void;
|
|
18
|
+
/** Stop following the pointer, for the list's teardown. */
|
|
19
|
+
release(): void;
|
|
20
|
+
}
|
|
21
|
+
export declare function rowDrag(rows: DragRows): RowDrag;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// A record list's drag handle. Press-and-drag the handle moves its row; a press that does
|
|
2
|
+
// not travel past the dead zone does nothing. The drop is the row under the pointer, read
|
|
3
|
+
// off the rows where they stand, so a scroll by any hand re-picks it. Held in an edge band
|
|
4
|
+
// of its scrollport, the drag scrolls it toward the rows out of view, once the pointer has
|
|
5
|
+
// been outside the band: a press on a row already in the band does not scroll. Nothing
|
|
6
|
+
// reflows until the release (the lift is a tone and the drop rule is out of flow), and the
|
|
7
|
+
// release is the one splice `move` makes. A handle that loses the pointer, or leaves the
|
|
8
|
+
// DOM, ends the drag with no move.
|
|
9
|
+
const DEAD_ZONE = 3;
|
|
10
|
+
/** The band at a scrollport's top and bottom edges that scrolls it under a held drag, and
|
|
11
|
+
* the most one frame scrolls, reached at the edge itself. */
|
|
12
|
+
const EDGE = 48;
|
|
13
|
+
const STEP = 16;
|
|
14
|
+
const page = () => document.scrollingElement ?? document.documentElement;
|
|
15
|
+
/** The nearest ancestor that scrolls vertically, else the page. */
|
|
16
|
+
function scrollport(from) {
|
|
17
|
+
for (let el = from.parentElement; el; el = el.parentElement) {
|
|
18
|
+
const { overflowY } = getComputedStyle(el);
|
|
19
|
+
if (/auto|scroll/.test(overflowY) && el.scrollHeight > el.clientHeight)
|
|
20
|
+
return el;
|
|
21
|
+
}
|
|
22
|
+
return page();
|
|
23
|
+
}
|
|
24
|
+
export function rowDrag(rows) {
|
|
25
|
+
let drag = $state();
|
|
26
|
+
let follow;
|
|
27
|
+
/** The row the pointer is over, or the nearest one past either end. */
|
|
28
|
+
function dropIndex(k, y) {
|
|
29
|
+
let best = k;
|
|
30
|
+
let nearest = Infinity;
|
|
31
|
+
for (let i = 0; i < rows.count(); i++) {
|
|
32
|
+
const box = rows.box(i);
|
|
33
|
+
if (!box)
|
|
34
|
+
continue;
|
|
35
|
+
const gap = y < box.top ? box.top - y : y > box.bottom ? y - box.bottom : 0;
|
|
36
|
+
if (gap < nearest) {
|
|
37
|
+
nearest = gap;
|
|
38
|
+
best = i;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return best;
|
|
42
|
+
}
|
|
43
|
+
function repick() {
|
|
44
|
+
if (drag?.engaged)
|
|
45
|
+
drag.drop = dropIndex(drag.k, drag.y);
|
|
46
|
+
}
|
|
47
|
+
function edgeScroll() {
|
|
48
|
+
if (!follow || !drag?.engaged)
|
|
49
|
+
return;
|
|
50
|
+
if (!follow.grip.isConnected) {
|
|
51
|
+
drag = undefined;
|
|
52
|
+
release();
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const { port } = follow;
|
|
56
|
+
const box = port === page() ? undefined : port.getBoundingClientRect();
|
|
57
|
+
const top = Math.max(box?.top ?? 0, 0);
|
|
58
|
+
const bottom = Math.min(box?.bottom ?? innerHeight, innerHeight);
|
|
59
|
+
const into = Math.min(drag.y - top - EDGE, 0) + Math.max(drag.y - bottom + EDGE, 0);
|
|
60
|
+
if (!into)
|
|
61
|
+
follow.armed = true;
|
|
62
|
+
// Only toward rows still out of view: past the list's end there is nothing to reach.
|
|
63
|
+
const beyond = into < 0
|
|
64
|
+
? (rows.box(0)?.top ?? top) < top
|
|
65
|
+
: (rows.box(rows.count() - 1)?.bottom ?? 0) > bottom;
|
|
66
|
+
if (into && follow.armed && beyond)
|
|
67
|
+
port.scrollBy({ top: STEP * Math.max(-1, Math.min(1, into / EDGE)), behavior: 'instant' });
|
|
68
|
+
follow.frame = requestAnimationFrame(edgeScroll);
|
|
69
|
+
}
|
|
70
|
+
function release() {
|
|
71
|
+
if (follow)
|
|
72
|
+
cancelAnimationFrame(follow.frame);
|
|
73
|
+
follow = undefined;
|
|
74
|
+
removeEventListener('scroll', repick, { capture: true });
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
held: () => drag !== undefined,
|
|
78
|
+
lifted: (k) => !!drag?.engaged && drag.k === k,
|
|
79
|
+
dropSide(k) {
|
|
80
|
+
if (!drag?.engaged || drag.drop !== k || drag.drop === drag.k)
|
|
81
|
+
return undefined;
|
|
82
|
+
return drag.drop > drag.k ? 'after' : 'before';
|
|
83
|
+
},
|
|
84
|
+
down(e, k) {
|
|
85
|
+
if (e.button !== 0)
|
|
86
|
+
return;
|
|
87
|
+
e.preventDefault();
|
|
88
|
+
release();
|
|
89
|
+
const grip = e.currentTarget;
|
|
90
|
+
grip.setPointerCapture?.(e.pointerId);
|
|
91
|
+
drag = { k, origin: e.clientY, y: e.clientY, engaged: false, drop: k };
|
|
92
|
+
follow = { grip, port: scrollport(grip), armed: false, frame: 0 };
|
|
93
|
+
},
|
|
94
|
+
move(e) {
|
|
95
|
+
if (!drag)
|
|
96
|
+
return;
|
|
97
|
+
drag.y = e.clientY;
|
|
98
|
+
if (!drag.engaged) {
|
|
99
|
+
if (Math.abs(e.clientY - drag.origin) < DEAD_ZONE)
|
|
100
|
+
return;
|
|
101
|
+
drag.engaged = true;
|
|
102
|
+
addEventListener('scroll', repick, { capture: true, passive: true });
|
|
103
|
+
if (follow)
|
|
104
|
+
follow.frame = requestAnimationFrame(edgeScroll);
|
|
105
|
+
}
|
|
106
|
+
repick();
|
|
107
|
+
},
|
|
108
|
+
up(e) {
|
|
109
|
+
const done = drag;
|
|
110
|
+
drag = undefined;
|
|
111
|
+
release();
|
|
112
|
+
if (!done?.engaged || e.type !== 'pointerup')
|
|
113
|
+
return;
|
|
114
|
+
rows.move(done.k, done.drop);
|
|
115
|
+
},
|
|
116
|
+
release
|
|
117
|
+
};
|
|
118
|
+
}
|
|
@@ -183,9 +183,10 @@ export interface MatrixMember {
|
|
|
183
183
|
/** The roster's members, in declaration order. Own keys only: a schema map is indexed
|
|
184
184
|
* by a document-supplied id, and `'toString' in members` is true of every roster. */
|
|
185
185
|
export declare function matrixMembers(roster: Record<string, string> | undefined): MatrixMember[];
|
|
186
|
-
/** A
|
|
187
|
-
|
|
188
|
-
|
|
186
|
+
/** A value by own key: a document key or a declared id can be spelled `constructor`. */
|
|
187
|
+
export declare function own<T>(map: Record<string, T> | undefined, key: string): T | undefined;
|
|
188
|
+
/** The value a matrix prints: the stored map, else a mapping `default:`. */
|
|
189
|
+
export declare function matrixPrinted(value: unknown, schema: QuillFieldSchema): Record<string, unknown> | undefined;
|
|
189
190
|
/**
|
|
190
191
|
* Whether a stored member is held: by being present. A mapping is held whatever it
|
|
191
192
|
* carries, `{}` included, and a bare scalar is the tick itself, read as Quillmark's
|
|
@@ -212,9 +213,6 @@ export declare function commitMember(map: Record<string, unknown> | undefined, i
|
|
|
212
213
|
* ({@link commitMember} with `undefined`), never a write.
|
|
213
214
|
*/
|
|
214
215
|
export declare function memberWrite(columns: Record<string, unknown>, title?: string): unknown;
|
|
215
|
-
/** Whether `id` is spelled as a matrix id: snake_case, the rule the roster's ids and
|
|
216
|
-
* an added item's key share. */
|
|
217
|
-
export declare function matrixId(id: string): boolean;
|
|
218
216
|
export declare function onRoster(matrix: QuillFieldSchema, id: string): boolean;
|
|
219
217
|
/**
|
|
220
218
|
* Whether a step under the matrix names a member, judged on the schema alone as an
|
|
@@ -285,6 +283,8 @@ export declare function variantCells(schema: QuillFieldSchema, member: string |
|
|
|
285
283
|
export declare function commitDiscriminant(value: Record<string, unknown> | undefined, member: string | undefined): Record<string, unknown> | undefined;
|
|
286
284
|
/** `foo_bar` → `Foo bar`. */
|
|
287
285
|
export declare function humanize(name: string): string;
|
|
286
|
+
/** What a field or property is called: its `title:`, else its key humanized. */
|
|
287
|
+
export declare function fieldTitle(key: string, schema: QuillFieldSchema): string;
|
|
288
288
|
/** Project a card schema's `fields` map (declaration = key order) into models. A
|
|
289
289
|
* card-level object's `properties` project the same way. */
|
|
290
290
|
export declare function fieldModels(cardSchema: Pick<QuillCardSchema, 'fields'>): FieldModel[];
|