@quillmark/svelte 0.33.0 → 0.34.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 +73 -1
- package/THEMING.md +11 -10
- package/dist/core/codec/anchor.d.ts +12 -0
- package/dist/core/codec/anchor.js +39 -0
- package/dist/core/codec/drag-move.d.ts +11 -0
- package/dist/core/codec/drag-move.js +143 -0
- package/dist/core/codec/encode.js +14 -5
- package/dist/core/codec/field.d.ts +47 -1
- package/dist/core/codec/field.js +147 -38
- package/dist/core/codec/index.d.ts +8 -2
- package/dist/core/codec/index.js +9 -2
- package/dist/core/codec/islands.d.ts +4 -1
- package/dist/core/codec/islands.js +6 -0
- package/dist/core/codec/keymap.d.ts +3 -0
- package/dist/core/codec/keymap.js +13 -12
- package/dist/core/codec/leave.d.ts +17 -0
- package/dist/core/codec/leave.js +78 -0
- package/dist/core/codec/prose.css +217 -0
- package/dist/core/codec/review-diff.d.ts +12 -0
- package/dist/core/codec/review-diff.js +131 -0
- package/dist/core/codec/review.d.ts +131 -0
- package/dist/core/codec/review.js +1077 -0
- package/dist/core/codec/shortcuts.d.ts +20 -4
- package/dist/core/codec/shortcuts.js +27 -7
- package/dist/core/codec/slash.d.ts +3 -0
- package/dist/core/codec/slash.js +2 -1
- package/dist/core/codec/table-view.js +163 -25
- package/dist/core/codec/undo.d.ts +6 -0
- package/dist/core/codec/undo.js +25 -2
- package/dist/core/dragfollow.d.ts +18 -0
- package/dist/core/dragfollow.js +63 -0
- package/dist/core/theme.css +36 -7
- package/dist/preview/controller.js +16 -0
- package/dist/preview/strings.d.ts +4 -0
- package/dist/preview/strings.js +3 -1
- package/dist/visual/ArrayField.svelte +363 -57
- package/dist/visual/ArrayField.svelte.d.ts +5 -0
- package/dist/visual/BooleanField.svelte +60 -5
- package/dist/visual/BooleanField.svelte.d.ts +2 -1
- package/dist/visual/Card.svelte +27 -17
- package/dist/visual/CardControls.svelte +17 -7
- package/dist/visual/CardControls.svelte.d.ts +2 -0
- package/dist/visual/DateField.svelte +90 -39
- package/dist/visual/DateField.svelte.d.ts +2 -2
- package/dist/visual/Field.svelte +126 -6
- package/dist/visual/FieldHint.svelte +24 -9
- package/dist/visual/FieldLabel.svelte +128 -22
- package/dist/visual/FieldLabel.svelte.d.ts +9 -0
- package/dist/visual/FormatPopover.svelte +125 -20
- package/dist/visual/MatrixAdd.svelte +13 -6
- package/dist/visual/MatrixAdd.svelte.d.ts +3 -2
- package/dist/visual/MatrixField.svelte +36 -8
- package/dist/visual/NumberField.svelte +27 -6
- package/dist/visual/NumberField.svelte.d.ts +3 -0
- package/dist/visual/ObjectField.svelte +25 -1
- package/dist/visual/ObjectField.svelte.d.ts +6 -0
- package/dist/visual/ProseField.svelte +23 -0
- package/dist/visual/ProseField.svelte.d.ts +3 -0
- package/dist/visual/ProseValue.svelte +107 -17
- package/dist/visual/ProseValue.svelte.d.ts +18 -4
- package/dist/visual/ReviewPopover.svelte +179 -0
- package/dist/visual/ReviewPopover.svelte.d.ts +16 -0
- package/dist/visual/ReviewProposal.svelte +149 -0
- package/dist/visual/ReviewProposal.svelte.d.ts +15 -0
- package/dist/visual/ReviewRows.svelte +68 -0
- package/dist/visual/ReviewRows.svelte.d.ts +11 -0
- package/dist/visual/SlashMenu.svelte +13 -1
- package/dist/visual/SlashMenu.svelte.d.ts +2 -0
- package/dist/visual/VisualEditor.svelte +23 -0
- package/dist/visual/VisualEditor.svelte.d.ts +7 -0
- package/dist/visual/VisualEditorInner.svelte +671 -22
- package/dist/visual/VisualEditorInner.svelte.d.ts +7 -0
- package/dist/visual/controls.css +17 -2
- package/dist/visual/guidance.d.ts +12 -0
- package/dist/visual/guidance.js +37 -2
- package/dist/visual/icons/nodes.d.ts +14 -2
- package/dist/visual/icons/nodes.js +12 -1
- package/dist/visual/index.d.ts +6 -0
- package/dist/visual/index.js +2 -0
- package/dist/visual/listhistory.d.ts +36 -0
- package/dist/visual/listhistory.js +53 -0
- package/dist/visual/proposals.d.ts +40 -0
- package/dist/visual/proposals.js +219 -0
- package/dist/visual/props.d.ts +35 -0
- package/dist/visual/removed.d.ts +20 -0
- package/dist/visual/removed.js +30 -0
- package/dist/visual/review.d.ts +170 -0
- package/dist/visual/review.js +269 -0
- package/dist/visual/review.svelte.d.ts +106 -0
- package/dist/visual/review.svelte.js +356 -0
- package/dist/visual/rowdrag.svelte.js +44 -55
- package/dist/visual/strings.d.ts +48 -7
- package/dist/visual/strings.js +32 -7
- package/dist/visual/structure.d.ts +5 -0
- package/dist/visual/structure.js +1 -1
- package/dist/visual/undo.svelte.d.ts +40 -7
- package/dist/visual/undo.svelte.js +98 -25
- package/package.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Content, PathStep, QuillFieldSchema } from '@quillmark/wasm';
|
|
2
2
|
import { type ArrayLayout } from './structure.js';
|
|
3
|
+
import { type DeepReview } from './review.js';
|
|
3
4
|
import { type DeepDiagnostic } from './diagnostics.js';
|
|
4
5
|
import type { LandingBox } from './leaves.js';
|
|
5
6
|
interface Props {
|
|
@@ -40,6 +41,10 @@ interface Props {
|
|
|
40
41
|
* naming a row draws under that row — under its head while it is collapsed, under
|
|
41
42
|
* the cell once it is open — and one naming no row draws at the list's foot. */
|
|
42
43
|
diagnostics?: readonly DeepDiagnostic[];
|
|
44
|
+
/** The review items naming a place inside this list, each with its steps still to
|
|
45
|
+
* walk from it: a member's under its row, a record's cell handed to the open row
|
|
46
|
+
* that draws it, and a member past the last at the list's foot (`ReviewRows`). */
|
|
47
|
+
review?: readonly DeepReview[];
|
|
43
48
|
}
|
|
44
49
|
declare const ArrayField: import("svelte").Component<Props, {
|
|
45
50
|
focus: () => void;
|
|
@@ -9,13 +9,16 @@
|
|
|
9
9
|
third: the thumb at the track's centre. `role="switch"` admits no third state (a
|
|
10
10
|
`mixed` there reads as false), so an optional boolean's control is a `checkbox`, the
|
|
11
11
|
toggle role that does, announcing `mixed` while unset. A press from unset writes
|
|
12
|
-
`true
|
|
12
|
+
`true`, and a press only ever answers. Delete or Backspace on an answered optional cell
|
|
13
|
+
unsets it: the answer taken back is a key's, as emptying any other control is, and no
|
|
14
|
+
control is drawn for it.
|
|
13
15
|
|
|
14
16
|
An unset switch draws its `default:` at the default rung, as every control draws a
|
|
15
17
|
printed default: a checked track takes the accent's default rung.
|
|
16
18
|
-->
|
|
17
19
|
<script lang="ts">
|
|
18
20
|
import { Switch } from 'bits-ui';
|
|
21
|
+
import { wording } from './strings.js';
|
|
19
22
|
import './controls.css';
|
|
20
23
|
|
|
21
24
|
interface Props {
|
|
@@ -34,10 +37,13 @@
|
|
|
34
37
|
id?: string;
|
|
35
38
|
/** The parked `description` (FieldLabel): announced after the name. */
|
|
36
39
|
describedBy?: string;
|
|
37
|
-
|
|
40
|
+
/** The answer, or `undefined` where an optional cell's was taken back. */
|
|
41
|
+
onCommit: (v: boolean | undefined) => void;
|
|
38
42
|
}
|
|
39
43
|
let { value, fallback, optional = false, label, id, describedBy, onCommit }: Props = $props();
|
|
40
44
|
|
|
45
|
+
const t = wording();
|
|
46
|
+
|
|
41
47
|
// The primitive is driven controlled (`checked` + `onCheckedChange`, never `bind:`)
|
|
42
48
|
// so reconciliation stays the package's: a two-way bind hands the primitive a lane
|
|
43
49
|
// around it, which repeats the reconciliation hazard in miniature. `undefined` is
|
|
@@ -46,8 +52,22 @@
|
|
|
46
52
|
const unset = $derived(local === undefined);
|
|
47
53
|
const defaulted = $derived(value === undefined && fallback !== undefined);
|
|
48
54
|
const tristate = $derived(
|
|
49
|
-
optional
|
|
55
|
+
optional
|
|
56
|
+
? {
|
|
57
|
+
role: 'checkbox',
|
|
58
|
+
'aria-checked': unset ? ('mixed' as const) : !!local,
|
|
59
|
+
'aria-keyshortcuts': 'Delete Backspace'
|
|
60
|
+
}
|
|
61
|
+
: {}
|
|
50
62
|
);
|
|
63
|
+
function unsetKey(e: KeyboardEvent): void {
|
|
64
|
+
if (!optional || value === undefined) return;
|
|
65
|
+
if (e.key !== 'Delete' && e.key !== 'Backspace') return;
|
|
66
|
+
if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) return;
|
|
67
|
+
e.preventDefault();
|
|
68
|
+
e.stopPropagation();
|
|
69
|
+
onCommit(undefined);
|
|
70
|
+
}
|
|
51
71
|
</script>
|
|
52
72
|
|
|
53
73
|
<!-- Not `.qm-switch`: that name is the preset's pane band, whose narrow-viewport rule
|
|
@@ -71,9 +91,18 @@
|
|
|
71
91
|
}}
|
|
72
92
|
>
|
|
73
93
|
{#snippet child({ props })}
|
|
74
|
-
<button
|
|
94
|
+
<button
|
|
95
|
+
{...props}
|
|
96
|
+
{...tristate}
|
|
97
|
+
onkeydown={(e) => {
|
|
98
|
+
unsetKey(e);
|
|
99
|
+
if (!e.defaultPrevented)
|
|
100
|
+
(props.onkeydown as ((e: KeyboardEvent) => void) | undefined)?.(e);
|
|
101
|
+
}}><Switch.Thumb class="qm-toggle-thumb" /></button
|
|
102
|
+
>
|
|
75
103
|
{/snippet}
|
|
76
104
|
</Switch.Root>
|
|
105
|
+
{#if unset}<span class="qm-toggle-none" aria-hidden="true">{t.strings.optionalGhost}</span>{/if}
|
|
77
106
|
</span>
|
|
78
107
|
|
|
79
108
|
<style>
|
|
@@ -139,8 +168,34 @@
|
|
|
139
168
|
translate: var(--thumb);
|
|
140
169
|
background: var(--_qm-surface);
|
|
141
170
|
}
|
|
142
|
-
/* Unset, the thumb stands at neither end: halfway along its travel
|
|
171
|
+
/* Unset, the thumb stands at neither end: halfway along its travel, with the word every
|
|
172
|
+
other unset optional control ghosts beside it. The word is the eye's; the tristate's
|
|
173
|
+
`mixed` is what a screen reader hears. */
|
|
143
174
|
.qm-toggle-wrap[data-unset] :global(.qm-toggle-thumb) {
|
|
144
175
|
translate: calc(var(--thumb) / 2);
|
|
145
176
|
}
|
|
177
|
+
.qm-toggle-none {
|
|
178
|
+
margin-inline-start: var(--_qm-space-2);
|
|
179
|
+
font-size: var(--_qm-text-body);
|
|
180
|
+
color: var(--_qm-ink-label);
|
|
181
|
+
}
|
|
182
|
+
/* Forced colours drop the track's fill and the thumb's with it, so the switch would
|
|
183
|
+
draw nothing: the system's stroke draws the track, and its text and highlight colours
|
|
184
|
+
the thumb at each end. */
|
|
185
|
+
@media (forced-colors: active) {
|
|
186
|
+
.qm-toggle-wrap :global(.qm-toggle) {
|
|
187
|
+
forced-color-adjust: none;
|
|
188
|
+
border: var(--_qm-border-width) solid ButtonText;
|
|
189
|
+
background: Canvas;
|
|
190
|
+
}
|
|
191
|
+
.qm-toggle-wrap :global(.qm-toggle[data-state='checked']) {
|
|
192
|
+
background: Highlight;
|
|
193
|
+
}
|
|
194
|
+
.qm-toggle-wrap :global(.qm-toggle-thumb) {
|
|
195
|
+
background: ButtonText;
|
|
196
|
+
}
|
|
197
|
+
.qm-toggle-wrap :global(.qm-toggle-thumb[data-state='checked']) {
|
|
198
|
+
background: HighlightText;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
146
201
|
</style>
|
|
@@ -14,7 +14,8 @@ interface Props {
|
|
|
14
14
|
id?: string;
|
|
15
15
|
/** The parked `description` (FieldLabel): announced after the name. */
|
|
16
16
|
describedBy?: string;
|
|
17
|
-
|
|
17
|
+
/** The answer, or `undefined` where an optional cell's was taken back. */
|
|
18
|
+
onCommit: (v: boolean | undefined) => void;
|
|
18
19
|
}
|
|
19
20
|
declare const BooleanField: import("svelte").Component<Props, {}, "">;
|
|
20
21
|
type BooleanField = ReturnType<typeof BooleanField>;
|
package/dist/visual/Card.svelte
CHANGED
|
@@ -20,9 +20,11 @@
|
|
|
20
20
|
import type { FieldDomIds } from './domid.js';
|
|
21
21
|
import Field from './Field.svelte';
|
|
22
22
|
import FieldHint from './FieldHint.svelte';
|
|
23
|
+
import { guidanceText } from './guidance.js';
|
|
23
24
|
import ProseField from './ProseField.svelte';
|
|
24
25
|
import CardControls from './CardControls.svelte';
|
|
25
26
|
import DiagnosticList from './DiagnosticList.svelte';
|
|
27
|
+
import { review } from './review.svelte.js';
|
|
26
28
|
|
|
27
29
|
/** The per-card operation bundle the VisualEditor builds (all resolve id→index lazily). */
|
|
28
30
|
interface CardOps {
|
|
@@ -73,6 +75,8 @@
|
|
|
73
75
|
leaves
|
|
74
76
|
}: Props = $props();
|
|
75
77
|
|
|
78
|
+
const reviewing = review();
|
|
79
|
+
|
|
76
80
|
// The rename in flight, written once on blur or Enter. Held apart from the stored
|
|
77
81
|
// title because a re-derive mid-edit hands `card` back with the title it stored.
|
|
78
82
|
let draft = $state<string | undefined>(undefined);
|
|
@@ -202,7 +206,9 @@
|
|
|
202
206
|
* recovery shell, which has no title to focus. */
|
|
203
207
|
export function focusHeader(): void {
|
|
204
208
|
handed = true;
|
|
205
|
-
el?.querySelector<HTMLElement>(
|
|
209
|
+
el?.querySelector<HTMLElement>(
|
|
210
|
+
".qm-card-header :is(input, button:not(:disabled, [aria-disabled='true']))"
|
|
211
|
+
)?.focus();
|
|
206
212
|
handed = false;
|
|
207
213
|
}
|
|
208
214
|
</script>
|
|
@@ -243,6 +249,7 @@
|
|
|
243
249
|
<CardControls
|
|
244
250
|
{isFirst}
|
|
245
251
|
{isLast}
|
|
252
|
+
name={shownTitle || card.titlePlaceholder}
|
|
246
253
|
onMoveUp={() => ops.move(-1)}
|
|
247
254
|
onMoveDown={() => ops.move(1)}
|
|
248
255
|
onDelete={() => ops.remove()}
|
|
@@ -271,6 +278,8 @@
|
|
|
271
278
|
{@const isOpen = open.has(group)}
|
|
272
279
|
{@const flagged =
|
|
273
280
|
!isOpen && section.fields.some((f) => ops.diagFor(f.name)?.length)}
|
|
281
|
+
{@const reviewed =
|
|
282
|
+
!isOpen && section.fields.some((f) => reviewing.marks(ops.leafKey(f.name)))}
|
|
274
283
|
{@const panelId = ops.panelId(group)}
|
|
275
284
|
{@const headIds = section.head ? ops.domIds(section.head.name) : undefined}
|
|
276
285
|
{@const headHint = section.head?.description}
|
|
@@ -299,6 +308,10 @@
|
|
|
299
308
|
<span class="qm-group-flag" aria-hidden="true"></span>
|
|
300
309
|
<span class="qm-visually-hidden">{t.strings.groupFlagged}</span>
|
|
301
310
|
{/if}
|
|
311
|
+
{#if reviewed}
|
|
312
|
+
<span class="qm-group-flag qm-group-reviewed" aria-hidden="true"></span>
|
|
313
|
+
<span class="qm-visually-hidden">{t.strings.groupReviewed}</span>
|
|
314
|
+
{/if}
|
|
302
315
|
</button>
|
|
303
316
|
{#if headIds && headHint}
|
|
304
317
|
<FieldHint
|
|
@@ -306,7 +319,9 @@
|
|
|
306
319
|
label={section.label}
|
|
307
320
|
describedBy={headIds.description}
|
|
308
321
|
/>
|
|
309
|
-
<span class="qm-visually-hidden" id={headIds.description}
|
|
322
|
+
<span class="qm-visually-hidden" id={headIds.description}
|
|
323
|
+
>{guidanceText(headHint)}</span
|
|
324
|
+
>
|
|
310
325
|
{/if}
|
|
311
326
|
</div>
|
|
312
327
|
<!-- The panel is clipped, not unmounted, so without `inert` every field
|
|
@@ -396,6 +411,7 @@
|
|
|
396
411
|
<CardControls
|
|
397
412
|
{isFirst}
|
|
398
413
|
{isLast}
|
|
414
|
+
name={humanize(card.kind)}
|
|
399
415
|
onMoveUp={() => ops.move(-1)}
|
|
400
416
|
onMoveDown={() => ops.move(1)}
|
|
401
417
|
onDelete={() => ops.remove()}
|
|
@@ -517,15 +533,15 @@
|
|
|
517
533
|
overlaid input tracks its content width. Both carry the same nothing for a box model
|
|
518
534
|
and inherit the same type tokens, which is what makes the two measure alike.
|
|
519
535
|
|
|
520
|
-
The type is
|
|
521
|
-
ranks above theirs, at the
|
|
522
|
-
|
|
536
|
+
The type is the title rung, over the group header's: the card holds its sections, so
|
|
537
|
+
its name ranks above theirs, at the header's weight: the size ramp ranks, and the
|
|
538
|
+
weight stays the chrome's one (INVARIANTS §Styling). */
|
|
523
539
|
.qm-card-title-sizer {
|
|
524
540
|
display: inline-grid;
|
|
525
541
|
align-items: center;
|
|
526
542
|
min-width: 0;
|
|
527
543
|
max-width: 100%;
|
|
528
|
-
font-size: var(--_qm-text-
|
|
544
|
+
font-size: var(--_qm-text-title);
|
|
529
545
|
font-weight: var(--_qm-weight-mid);
|
|
530
546
|
line-height: var(--_qm-leading-tight);
|
|
531
547
|
font-family: inherit;
|
|
@@ -577,6 +593,10 @@
|
|
|
577
593
|
border-radius: var(--_qm-radius-pill);
|
|
578
594
|
background: var(--_qm-danger);
|
|
579
595
|
}
|
|
596
|
+
/* The same mark in the review hue: something under here is someone else's to look at. */
|
|
597
|
+
.qm-group-reviewed {
|
|
598
|
+
background: var(--_qm-review);
|
|
599
|
+
}
|
|
580
600
|
/* One rung between the payload's two kinds of section, and none inside the panel stack:
|
|
581
601
|
what stands one disclosure row off the next is the two headers' own block padding and
|
|
582
602
|
nothing else, so the rows tile and their targets with them. A run of one-line rows
|
|
@@ -745,16 +765,6 @@
|
|
|
745
765
|
position: absolute;
|
|
746
766
|
inset: 0;
|
|
747
767
|
}
|
|
748
|
-
/* The parked description: `FieldLabel`'s recipe, for the one description a
|
|
749
|
-
header rather than a label parks. */
|
|
750
|
-
.qm-visually-hidden {
|
|
751
|
-
position: absolute;
|
|
752
|
-
width: 1px;
|
|
753
|
-
height: 1px;
|
|
754
|
-
overflow: hidden;
|
|
755
|
-
clip-path: inset(50%);
|
|
756
|
-
white-space: nowrap;
|
|
757
|
-
}
|
|
758
768
|
.qm-group-header :global(.qm-group-chevron) {
|
|
759
769
|
flex-shrink: 0;
|
|
760
770
|
display: block;
|
|
@@ -833,7 +843,7 @@
|
|
|
833
843
|
}
|
|
834
844
|
/* One typographic role with the editable title above. */
|
|
835
845
|
.qm-card-title-static {
|
|
836
|
-
font-size: var(--_qm-text-
|
|
846
|
+
font-size: var(--_qm-text-title);
|
|
837
847
|
font-weight: var(--_qm-weight-mid);
|
|
838
848
|
line-height: var(--_qm-leading-tight);
|
|
839
849
|
color: var(--_qm-ink-label);
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
<!--
|
|
2
2
|
Card controls, composable cards only.
|
|
3
|
-
Right-aligned in the header: a move-up/move-down
|
|
4
|
-
|
|
3
|
+
Right-aligned in the header: a move-up/move-down arrow pair (each inert at its edge),
|
|
4
|
+
then delete, each named for the card it acts on, the row revealed while the pointer or
|
|
5
|
+
the caret is in the card. A move button at its edge is inert by `aria-disabled` and out
|
|
6
|
+
of the tab order, not `disabled`: a move that reaches the edge under the focus then keeps
|
|
7
|
+
the focus on the button pressed, where a disabled one drops it to the page.
|
|
5
8
|
Reorder is buttons, not drag. All three are chips (controls.css): fill arrives
|
|
6
9
|
on hover, and delete rests at the label ink beside them. The card scopes
|
|
7
10
|
that reveal, so its condition lives in the parent's CSS; the row keeps the narrower
|
|
@@ -19,11 +22,13 @@
|
|
|
19
22
|
interface Props {
|
|
20
23
|
isFirst: boolean;
|
|
21
24
|
isLast: boolean;
|
|
25
|
+
/** The title the card's header shows, which the controls' names carry. */
|
|
26
|
+
name: string;
|
|
22
27
|
onMoveUp: () => void;
|
|
23
28
|
onMoveDown: () => void;
|
|
24
29
|
onDelete: () => void;
|
|
25
30
|
}
|
|
26
|
-
let { isFirst, isLast, onMoveUp, onMoveDown, onDelete }: Props = $props();
|
|
31
|
+
let { isFirst, isLast, name, onMoveUp, onMoveDown, onDelete }: Props = $props();
|
|
27
32
|
</script>
|
|
28
33
|
|
|
29
34
|
<div class="qm-card-controls">
|
|
@@ -32,21 +37,26 @@
|
|
|
32
37
|
type="button"
|
|
33
38
|
class="qm-chip qm-focus-ring"
|
|
34
39
|
title={t.strings.cardMoveUp}
|
|
35
|
-
|
|
36
|
-
|
|
40
|
+
aria-label={t.strings.cardAction(t.strings.cardMoveUp, name)}
|
|
41
|
+
aria-disabled={isFirst || undefined}
|
|
42
|
+
tabindex={isFirst ? -1 : undefined}
|
|
43
|
+
onclick={() => isFirst || onMoveUp()}><Icon name="arrow-up" /></button
|
|
37
44
|
>
|
|
38
45
|
<button
|
|
39
46
|
type="button"
|
|
40
47
|
class="qm-chip qm-focus-ring"
|
|
41
48
|
title={t.strings.cardMoveDown}
|
|
42
|
-
|
|
43
|
-
|
|
49
|
+
aria-label={t.strings.cardAction(t.strings.cardMoveDown, name)}
|
|
50
|
+
aria-disabled={isLast || undefined}
|
|
51
|
+
tabindex={isLast ? -1 : undefined}
|
|
52
|
+
onclick={() => isLast || onMoveDown()}><Icon name="arrow-down" /></button
|
|
44
53
|
>
|
|
45
54
|
</div>
|
|
46
55
|
<button
|
|
47
56
|
type="button"
|
|
48
57
|
class="qm-chip qm-card-delete qm-focus-ring"
|
|
49
58
|
title={t.strings.cardDelete}
|
|
59
|
+
aria-label={t.strings.cardAction(t.strings.cardDelete, name)}
|
|
50
60
|
onclick={onDelete}><Icon name="trash-2" /></button
|
|
51
61
|
>
|
|
52
62
|
</div>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<!--
|
|
2
|
-
A `date`
|
|
2
|
+
A `date` or `datetime` field → a styled segmented date field on bits-ui. The
|
|
3
3
|
stored value is a string, `YYYY-MM-DD` or `today`; a cleared control commits as its
|
|
4
4
|
last segment empties, the blank `""` over a `default:`, which stays blank, and `undefined`
|
|
5
5
|
(the unset rung) where nothing is declared, the parent removing the field. The value-object a date field lowers to is a render-time
|
|
@@ -18,12 +18,20 @@
|
|
|
18
18
|
calendar) rather than `DatePicker`: the segments are the entry affordance, and a
|
|
19
19
|
calendar is a second surface this field does not need.
|
|
20
20
|
|
|
21
|
+
A `datetime` is the same control with the time's segments after the date's, to the
|
|
22
|
+
minute. It stores `YYYY-MM-DDThh:mm`, and `:ss` after it where the stored value
|
|
23
|
+
carried seconds, which no segment shows and an edit keeps. `today` is no value of its
|
|
24
|
+
type, so it draws no toggle and takes no `T`. The value is whole only with every
|
|
25
|
+
segment filled, the time's too, so a date typed with no time is held and, on
|
|
26
|
+
leaving, put back as any half-typed date is.
|
|
27
|
+
|
|
21
28
|
The boundary is a string, and the local is too. The primitive speaks
|
|
22
|
-
`CalendarDate
|
|
23
|
-
and
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
29
|
+
`CalendarDate`, or `CalendarDateTime` for a `datetime`; the document speaks
|
|
30
|
+
`YYYY-MM-DD` and `YYYY-MM-DDThh:mm`. Neither carries a zone, so the round-trip is
|
|
31
|
+
lossless and no local-midnight shift can occur: the hazard that makes
|
|
32
|
+
`new Date('2026-07-25')` the wrong tool here. Authored values are data, not input:
|
|
33
|
+
the parse throws on anything malformed, so a bad string degrades to an empty field
|
|
34
|
+
rather than taking the editor down with it.
|
|
27
35
|
|
|
28
36
|
The local is a `$derived`, which compares by identity, so it holds the string, not
|
|
29
37
|
the parsed value: a fresh `CalendarDate` is never `===` the last one, so the
|
|
@@ -57,14 +65,22 @@
|
|
|
57
65
|
<script lang="ts">
|
|
58
66
|
import { flushSync } from 'svelte';
|
|
59
67
|
import { DateField as BitsDateField } from 'bits-ui';
|
|
60
|
-
import {
|
|
68
|
+
import {
|
|
69
|
+
getLocalTimeZone,
|
|
70
|
+
parseDate,
|
|
71
|
+
parseDateTime,
|
|
72
|
+
toCalendarDateTime,
|
|
73
|
+
today,
|
|
74
|
+
type DateValue
|
|
75
|
+
} from '@internationalized/date';
|
|
61
76
|
import Icon from './icons/Icon.svelte';
|
|
62
77
|
import { wording } from './strings.js';
|
|
63
78
|
import './controls.css';
|
|
64
79
|
|
|
65
80
|
const t = wording();
|
|
66
81
|
const TODAY = 'today';
|
|
67
|
-
|
|
82
|
+
/** Read at each use: a session left open past midnight renders the new day. */
|
|
83
|
+
const renderDate = (): DateValue => today(getLocalTimeZone());
|
|
68
84
|
|
|
69
85
|
interface Props {
|
|
70
86
|
value: string | undefined;
|
|
@@ -86,8 +102,8 @@
|
|
|
86
102
|
labelledBy?: string;
|
|
87
103
|
/** The parked `description` (FieldLabel): announced after the name. */
|
|
88
104
|
describedBy?: string;
|
|
89
|
-
/** A `datetime`:
|
|
90
|
-
* takes no `T`. */
|
|
105
|
+
/** A `datetime`: the time's segments stand after the date's, and `today` is no
|
|
106
|
+
* value of its type, so it draws no toggle and takes no `T`. */
|
|
91
107
|
datetime?: boolean;
|
|
92
108
|
onCommit: (v: string | undefined) => void;
|
|
93
109
|
}
|
|
@@ -102,24 +118,36 @@
|
|
|
102
118
|
wrapEl?.querySelector<HTMLElement>('[data-segment]:not([data-segment="literal"])')?.focus();
|
|
103
119
|
}
|
|
104
120
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
//
|
|
121
|
+
/** The part of a stored string this control edits: all of a `datetime`, and the date
|
|
122
|
+
* half of a `date`, anything past `YYYY-MM-DD` being no part of its type. */
|
|
123
|
+
const span = (s: string | undefined): string | undefined => (datetime ? s : s?.slice(0, 10));
|
|
124
|
+
// The parse throws on a malformed authored value: the segments stand empty and the
|
|
125
|
+
// stored string draws beside them (`unread`), so the value an error names is on
|
|
126
|
+
// screen.
|
|
109
127
|
function toDateValue(s: string): DateValue | undefined {
|
|
110
128
|
if (!s) return undefined;
|
|
111
|
-
if (s === TODAY) return renderDate;
|
|
112
129
|
try {
|
|
113
|
-
return
|
|
130
|
+
if (datetime) return parseDateTime(s);
|
|
131
|
+
return s === TODAY ? renderDate() : parseDate(s);
|
|
114
132
|
} catch {
|
|
115
133
|
return undefined;
|
|
116
134
|
}
|
|
117
135
|
}
|
|
136
|
+
/** A value as the document spells it. A `datetime` to the minute, its seconds
|
|
137
|
+
* written only where it holds some. */
|
|
138
|
+
const spell = (d: DateValue | undefined): string =>
|
|
139
|
+
d ? (datetime ? d.toString().replace(/:00$/, '') : d.toString()) : '';
|
|
118
140
|
|
|
119
141
|
const unread = $derived(
|
|
120
|
-
value && value !== TODAY && !toDateValue(value
|
|
142
|
+
value && value !== TODAY && !toDateValue(span(value)!) ? value : undefined
|
|
143
|
+
);
|
|
144
|
+
const fallbackDate = $derived(toDateValue(span(fallback) ?? ''));
|
|
145
|
+
/** Where an empty segment counts from: the default, else, for a `datetime`, the
|
|
146
|
+
* render date's midnight, a placeholder with a time being what stands the time's
|
|
147
|
+
* segments. */
|
|
148
|
+
const placeholder = $derived(
|
|
149
|
+
fallbackDate ?? (datetime ? toCalendarDateTime(renderDate()) : undefined)
|
|
121
150
|
);
|
|
122
|
-
const fallbackDate = $derived(toDateValue(fallback?.slice(0, 10) ?? ''));
|
|
123
151
|
/** The default is the primitive's value: from entering an unset field until an
|
|
124
152
|
* edit or leaving. Part of the projection, so a re-derivation keeps it. */
|
|
125
153
|
let seat = $state(false);
|
|
@@ -132,7 +160,7 @@
|
|
|
132
160
|
// Driven controlled (`value` + `onValueChange`, never `bind:`) so reconciliation
|
|
133
161
|
// stays the package's.
|
|
134
162
|
let local = $derived(
|
|
135
|
-
held ? '' : (value
|
|
163
|
+
held ? '' : (span(value) ?? (seat && fallbackDate ? spell(fallbackDate) : ''))
|
|
136
164
|
);
|
|
137
165
|
const parsed = $derived(toDateValue(local));
|
|
138
166
|
// The date the empty segments ghost, or undefined when there is nothing to ghost:
|
|
@@ -154,7 +182,7 @@
|
|
|
154
182
|
onCommit(next);
|
|
155
183
|
}
|
|
156
184
|
function toggle(): void {
|
|
157
|
-
write(follows ? renderDate.toString() : TODAY);
|
|
185
|
+
write(follows ? renderDate().toString() : TODAY);
|
|
158
186
|
}
|
|
159
187
|
function shortcut(e: KeyboardEvent): void {
|
|
160
188
|
if (datetime || e.key.toLowerCase() !== 't' || e.ctrlKey || e.metaKey || e.altKey) return;
|
|
@@ -181,11 +209,12 @@
|
|
|
181
209
|
}
|
|
182
210
|
function leave(e: FocusEvent): void {
|
|
183
211
|
if (within(e)) return;
|
|
212
|
+
const seated = seat;
|
|
184
213
|
seat = false;
|
|
185
|
-
|
|
214
|
+
const emptied = held;
|
|
186
215
|
held = false;
|
|
187
|
-
if (!filled()) clear();
|
|
188
|
-
else if (!value) generation++;
|
|
216
|
+
if (emptied && !filled()) clear();
|
|
217
|
+
else if (!value && (emptied || (!seated && filled()))) generation++;
|
|
189
218
|
}
|
|
190
219
|
/** The keystroke that empties the last segment, after the primitive has drawn it. */
|
|
191
220
|
function settle(): void {
|
|
@@ -206,20 +235,39 @@
|
|
|
206
235
|
// alphabetic in every locale bits ships (`mm`/`yyyy`, `аа`, `年`), a filled one
|
|
207
236
|
// is digits.
|
|
208
237
|
//
|
|
209
|
-
// The separators are `literal` parts, never unfilled
|
|
210
|
-
//
|
|
211
|
-
//
|
|
238
|
+
// The separators are `literal` parts, never unfilled. Digits are zero-padded to
|
|
239
|
+
// the segment widths the field displays. A day period holds letters filled or not,
|
|
240
|
+
// so it is filled where its hour is: `hour` is the hour segment's own text, and
|
|
241
|
+
// `twelve` whether the field draws a day period, and so counts its hours to twelve.
|
|
212
242
|
type Rung = 'default' | 'hint' | undefined;
|
|
213
|
-
function segmentText(
|
|
214
|
-
|
|
243
|
+
function segmentText(
|
|
244
|
+
part: string,
|
|
245
|
+
text: string,
|
|
246
|
+
hour = '',
|
|
247
|
+
twelve = false
|
|
248
|
+
): { text: string; ghosted: Rung } {
|
|
249
|
+
const filled = /\d/.test(part === 'dayPeriod' ? hour : text);
|
|
250
|
+
if (part === 'literal' || filled) return { text, ghosted: undefined };
|
|
215
251
|
if (!ghost) return { text, ghosted: 'hint' };
|
|
252
|
+
const pad = (n: number, width = 2) => String(n).padStart(width, '0');
|
|
253
|
+
const clock = 'hour' in ghost ? ghost : undefined;
|
|
216
254
|
switch (part) {
|
|
217
255
|
case 'year':
|
|
218
|
-
return { text:
|
|
256
|
+
return { text: pad(ghost.year, 4), ghosted: 'default' };
|
|
219
257
|
case 'month':
|
|
220
|
-
return { text:
|
|
258
|
+
return { text: pad(ghost.month), ghosted: 'default' };
|
|
221
259
|
case 'day':
|
|
222
|
-
return { text:
|
|
260
|
+
return { text: pad(ghost.day), ghosted: 'default' };
|
|
261
|
+
case 'hour':
|
|
262
|
+
return clock
|
|
263
|
+
? { text: pad(twelve ? ((clock.hour + 11) % 12) + 1 : clock.hour), ghosted: 'default' }
|
|
264
|
+
: { text, ghosted: 'hint' };
|
|
265
|
+
case 'minute':
|
|
266
|
+
return clock ? { text: pad(clock.minute), ghosted: 'default' } : { text, ghosted: 'hint' };
|
|
267
|
+
case 'dayPeriod':
|
|
268
|
+
return clock
|
|
269
|
+
? { text: clock.hour < 12 ? 'AM' : 'PM', ghosted: 'default' }
|
|
270
|
+
: { text, ghosted: 'hint' };
|
|
223
271
|
default:
|
|
224
272
|
return { text, ghosted: 'hint' };
|
|
225
273
|
}
|
|
@@ -236,14 +284,15 @@
|
|
|
236
284
|
{#key generation}
|
|
237
285
|
<BitsDateField.Root
|
|
238
286
|
value={parsed}
|
|
239
|
-
placeholder
|
|
287
|
+
{placeholder}
|
|
288
|
+
granularity={datetime ? 'minute' : 'day'}
|
|
240
289
|
onValueChange={(d) => {
|
|
241
|
-
//
|
|
242
|
-
//
|
|
243
|
-
//
|
|
244
|
-
//
|
|
245
|
-
const next = d
|
|
246
|
-
if (next === (parsed
|
|
290
|
+
// A cleared or half-typed field yields undefined, held until the focus
|
|
291
|
+
// leaves. The primitive reports its own value again as a segment loses
|
|
292
|
+
// focus, which is no edit, and over a seated default or `today` would
|
|
293
|
+
// write it.
|
|
294
|
+
const next = spell(d);
|
|
295
|
+
if (next === spell(parsed)) return;
|
|
247
296
|
if (!d) {
|
|
248
297
|
held = true;
|
|
249
298
|
return;
|
|
@@ -270,8 +319,10 @@
|
|
|
270
319
|
{#snippet children({ segments })}
|
|
271
320
|
<!-- Keyed by index: `part` repeats (the `literal` separators between
|
|
272
321
|
segments all carry it) so a part-keyed block collides. -->
|
|
322
|
+
{@const hour = segments.find((seg) => seg.part === 'hour')?.value}
|
|
323
|
+
{@const twelve = segments.some((seg) => seg.part === 'dayPeriod')}
|
|
273
324
|
{#each segments as seg, i (i)}
|
|
274
|
-
{@const shown = segmentText(seg.part, seg.value)}
|
|
325
|
+
{@const shown = segmentText(seg.part, seg.value, hour, twelve)}
|
|
275
326
|
<BitsDateField.Segment
|
|
276
327
|
class="qm-date-segment"
|
|
277
328
|
part={seg.part}
|
|
@@ -18,8 +18,8 @@ interface Props {
|
|
|
18
18
|
labelledBy?: string;
|
|
19
19
|
/** The parked `description` (FieldLabel): announced after the name. */
|
|
20
20
|
describedBy?: string;
|
|
21
|
-
/** A `datetime`:
|
|
22
|
-
* takes no `T`. */
|
|
21
|
+
/** A `datetime`: the time's segments stand after the date's, and `today` is no
|
|
22
|
+
* value of its type, so it draws no toggle and takes no `T`. */
|
|
23
23
|
datetime?: boolean;
|
|
24
24
|
onCommit: (v: string | undefined) => void;
|
|
25
25
|
}
|