@widgetic/design-system 0.5.41 → 0.5.42
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/dist/components/EmptyState.svelte +6 -2
- package/dist/components/creator/CreatorBar.svelte +54 -1
- package/dist/components/creator/CreatorBar.svelte.d.ts +5 -0
- package/dist/components/modals/BaseModal.svelte +9 -0
- package/dist/components/modals/BaseModal.svelte.d.ts +5 -0
- package/dist/components/search-input/SearchInput.svelte +38 -3
- package/dist/components/search-input/recentSearches.d.ts +5 -1
- package/dist/components/search-input/recentSearches.js +18 -1
- package/dist/components/shell/NavRow.svelte +53 -10
- package/dist/components/shell/NavRow.svelte.d.ts +23 -2
- package/dist/components/shell/NotificationRow.svelte +3 -2
- package/dist/components/shell/ProfileRow.svelte +6 -4
- package/dist/components/shell/ProfileRow.svelte.d.ts +2 -2
- package/dist/components/shell/SettingsDialog.svelte +23 -1
- package/dist/components/shell/WidgetRow.svelte +4 -3
- package/dist/components/shell/WidgetRow.svelte.d.ts +2 -2
- package/dist/components/ui/accordion/accordion-trigger.svelte +19 -0
- package/dist/components/ui/button/button.svelte +4 -2
- package/dist/components/ui/dialog/dialog-content.svelte +24 -2
- package/dist/components/ui/dropdown-menu/dropdown-menu-content.svelte +2 -1
- package/dist/components/ui/dropdown-menu/dropdown-menu-sub-content.svelte +2 -1
- package/dist/components/ui/hover-card/hover-card-content.svelte +2 -1
- package/dist/components/ui/popover/popover-content.svelte +2 -1
- package/dist/components/ui/select/select-content.svelte +2 -1
- package/dist/components/ui/tooltip/tooltip-content.svelte +1 -1
- package/dist/styles/tokens.css +68 -1
- package/dist/utils/modalEnterKey.d.ts +139 -0
- package/dist/utils/modalEnterKey.js +276 -0
- package/dist/utils/modalFocusTrap.d.ts +7 -0
- package/dist/utils/modalFocusTrap.js +22 -0
- package/dist/utils/overlayMotion.d.ts +9 -0
- package/dist/utils/overlayMotion.js +9 -0
- package/dist/utils/revealOpeningSection.d.ts +51 -0
- package/dist/utils/revealOpeningSection.js +109 -0
- package/package.json +1 -1
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { Accordion as AccordionPrimitive, type WithoutChild } from "bits-ui";
|
|
3
3
|
import IconChevronDown from "@tabler/icons-svelte/icons/chevron-down";
|
|
4
4
|
import { cn } from "../../../utils.js";
|
|
5
|
+
import { followOpeningSection } from "../../../utils/revealOpeningSection.js";
|
|
5
6
|
|
|
6
7
|
let {
|
|
7
8
|
ref = $bindable(null),
|
|
@@ -37,14 +38,32 @@
|
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
40
|
|
|
41
|
+
/**
|
|
42
|
+
* A section that opens near the bottom of a scrolling box (the settings dialog, a page) grows below the edge of it. While it
|
|
43
|
+
* opens, its box is scrolled so the content comes into view, and the person does not have to scroll to read what they opened.
|
|
44
|
+
* At the time of the toggle the trigger still has the state it is leaving, so `closed` means this click opens the item.
|
|
45
|
+
*/
|
|
46
|
+
function keepOpeningItemInView(event: Event) {
|
|
47
|
+
try {
|
|
48
|
+
const trigger = event.currentTarget as HTMLElement | null;
|
|
49
|
+
if (trigger?.getAttribute("data-state") !== "closed") return;
|
|
50
|
+
const ownItem = trigger.closest<HTMLElement>("[data-accordion-item]");
|
|
51
|
+
if (ownItem) followOpeningSection(ownItem);
|
|
52
|
+
} catch (error) {
|
|
53
|
+
console.warn("[accordion] could not keep the opening item in view:", error);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
40
57
|
function handleTriggerClick(event: MouseEvent & { currentTarget: EventTarget & HTMLButtonElement }) {
|
|
41
58
|
markAccordionItemsAnimate(event);
|
|
59
|
+
keepOpeningItemInView(event);
|
|
42
60
|
onclick?.(event);
|
|
43
61
|
}
|
|
44
62
|
|
|
45
63
|
function handleTriggerKeydown(event: KeyboardEvent & { currentTarget: EventTarget & HTMLButtonElement }) {
|
|
46
64
|
if (event.key === "Enter" || event.key === " ") {
|
|
47
65
|
markAccordionItemsAnimate(event);
|
|
66
|
+
keepOpeningItemInView(event);
|
|
48
67
|
}
|
|
49
68
|
onkeydown?.(event);
|
|
50
69
|
}
|
|
@@ -118,12 +118,14 @@
|
|
|
118
118
|
);
|
|
119
119
|
</script>
|
|
120
120
|
|
|
121
|
+
<!-- `data-variant` says how the button is drawn. A modal reads it to find its main button: Enter presses the last filled one
|
|
122
|
+
(default, accent or destructive, see utils/modalEnterKey.ts). A caller can still set its own through `restProps`. -->
|
|
121
123
|
{#if href}
|
|
122
|
-
<a bind:this={ref} class={classes} {href} {...restProps}>
|
|
124
|
+
<a bind:this={ref} class={classes} {href} data-variant={variant} {...restProps}>
|
|
123
125
|
{@render children?.()}
|
|
124
126
|
</a>
|
|
125
127
|
{:else}
|
|
126
|
-
<button bind:this={ref} class={classes} {type} {...restProps}>
|
|
128
|
+
<button bind:this={ref} class={classes} {type} data-variant={variant} {...restProps}>
|
|
127
129
|
{@render children?.()}
|
|
128
130
|
</button>
|
|
129
131
|
{/if}
|
|
@@ -14,6 +14,9 @@
|
|
|
14
14
|
import { claimOverlayLayerPair, overlayLayerZIndexStyle } from "../../../utils/overlayLayerStack.js";
|
|
15
15
|
import { OVERLAY_LAYER_CONTEXT_KEY, type OverlayLayerContext } from "./overlay-layer-context.js";
|
|
16
16
|
import DialogLayerSync from "./DialogLayerSync.svelte";
|
|
17
|
+
// Enter inside the card presses the dialog's main button (see utils/modalEnterKey.ts).
|
|
18
|
+
import { modalEnterKey } from "../../../utils/modalEnterKey.js";
|
|
19
|
+
import { dialogInitialFocusTarget } from "../../../utils/modalFocusTrap.js";
|
|
17
20
|
|
|
18
21
|
let {
|
|
19
22
|
ref = $bindable(null),
|
|
@@ -49,11 +52,28 @@
|
|
|
49
52
|
onDestroy(() => overlayLayerContext.releaseLayer());
|
|
50
53
|
|
|
51
54
|
const panelFly = $derived(overlayPanelFlyTransition());
|
|
55
|
+
|
|
56
|
+
// By default bits-ui puts the focus on the first tabbable element when the dialog opens, and in a confirm dialog that is
|
|
57
|
+
// "Cancel": Enter would then cancel the dialog, where the person expects it to press the main button (owner, 18 Nov 2026).
|
|
58
|
+
// The focus goes to the first field to type in, else to the card, and never to a button; a caller that wants something else
|
|
59
|
+
// passes its own `onOpenAutoFocus` (it comes after this one in the props). The focus stays inside the dialog, so the focus
|
|
60
|
+
// trap is not weakened.
|
|
61
|
+
function handleOpenAutoFocus(event: Event): void {
|
|
62
|
+
event.preventDefault();
|
|
63
|
+
requestAnimationFrame(() => {
|
|
64
|
+
try {
|
|
65
|
+
if (!ref) return;
|
|
66
|
+
dialogInitialFocusTarget(ref).focus({ preventScroll: true });
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.warn("[dialog] Could not move the focus into the dialog", error);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
52
72
|
</script>
|
|
53
73
|
|
|
54
74
|
<Dialog.Portal {...portalProps}>
|
|
55
75
|
<Dialog.Overlay />
|
|
56
|
-
<DialogPrimitive.Content bind:ref forceMount {...restProps}>
|
|
76
|
+
<DialogPrimitive.Content bind:ref forceMount onOpenAutoFocus={handleOpenAutoFocus} {...restProps}>
|
|
57
77
|
{#snippet child({ props, open })}
|
|
58
78
|
<DialogLayerSync {open} {overlayLayerContext} />
|
|
59
79
|
{#if open}
|
|
@@ -68,8 +88,10 @@
|
|
|
68
88
|
>
|
|
69
89
|
<div
|
|
70
90
|
{...props}
|
|
91
|
+
use:modalEnterKey
|
|
71
92
|
class={cn(
|
|
72
|
-
|
|
93
|
+
// outline-hidden: the card holds the focus when the dialog opens with no field in it (see handleOpenAutoFocus)
|
|
94
|
+
"bg-background border-border pointer-events-auto grid w-dialog max-w-[calc(100vw-3rem)] gap-4 rounded-panel border p-6 outline-hidden",
|
|
73
95
|
overlayDialogPanelCardClasses,
|
|
74
96
|
className
|
|
75
97
|
)}
|
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
{sideOffset}
|
|
26
26
|
dir={$textDirection}
|
|
27
27
|
class={cn(
|
|
28
|
-
|
|
28
|
+
// floating-motion: fade + 8px slide from the trigger side in 150ms (tokens.css); the account and workspace menus of the sidebar use it too
|
|
29
|
+
'bg-popover text-popover-foreground border-border floating-motion w-max min-w-[8rem] max-w-[min(24rem,calc(100vw-1rem))] overflow-hidden rounded-xl border p-1 outline-hidden',
|
|
29
30
|
overlayFloatingContentZClass,
|
|
30
31
|
className
|
|
31
32
|
)}
|
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
bind:ref
|
|
24
24
|
dir={$textDirection}
|
|
25
25
|
class={cn(
|
|
26
|
-
|
|
26
|
+
// floating-motion: the sub-menu slides in like the menu it opens from (it had no motion before)
|
|
27
|
+
'bg-popover text-popover-foreground border-border floating-motion w-max min-w-[8rem] max-w-[min(24rem,calc(100vw-1rem))] rounded-xl border p-1 focus:outline-hidden',
|
|
27
28
|
overlayFloatingContentZClass,
|
|
28
29
|
className
|
|
29
30
|
)}
|
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
{sideOffset}
|
|
28
28
|
dir={$textDirection}
|
|
29
29
|
class={cn(
|
|
30
|
-
|
|
30
|
+
// floating-motion: fade + 8px slide from the trigger side in 150ms (tokens.css)
|
|
31
|
+
'bg-popover text-popover-foreground border-border floating-motion mt-3 w-64 rounded-xl border p-4 outline-hidden',
|
|
31
32
|
overlayFloatingContentZClass,
|
|
32
33
|
className
|
|
33
34
|
)}
|
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
{align}
|
|
28
28
|
dir={$textDirection}
|
|
29
29
|
class={cn(
|
|
30
|
-
|
|
30
|
+
// floating-motion: fade + 8px slide from the trigger side in 150ms (tokens.css)
|
|
31
|
+
'bg-popover text-popover-foreground border-border floating-motion w-72 rounded-xl border p-4 outline-hidden',
|
|
31
32
|
overlayFloatingContentZClass,
|
|
32
33
|
className
|
|
33
34
|
)}
|
|
@@ -128,7 +128,8 @@
|
|
|
128
128
|
{sideOffset}
|
|
129
129
|
dir={$textDirection}
|
|
130
130
|
class={cn(
|
|
131
|
-
|
|
131
|
+
// floating-motion: fade + 8px slide from the trigger side in 150ms (tokens.css); the translate-* classes are the 4px gap
|
|
132
|
+
'relative max-h-96 min-w-[8rem] overflow-hidden rounded-xl border border-border bg-popover text-popover-foreground floating-motion data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1',
|
|
132
133
|
overlayFloatingContentZClass,
|
|
133
134
|
className
|
|
134
135
|
)}
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
|
|
26
26
|
const variantClasses = {
|
|
27
27
|
default:
|
|
28
|
-
'bg-popover text-popover-foreground border border-border shadow-
|
|
28
|
+
'bg-popover text-popover-foreground border border-border shadow-floating',
|
|
29
29
|
inverse: 'bg-inverse text-inverse-foreground border-transparent'
|
|
30
30
|
};
|
|
31
31
|
</script>
|
package/dist/styles/tokens.css
CHANGED
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
--color-light-green: #e3f0db;
|
|
19
19
|
/*
|
|
20
20
|
* Success toast pill (round 5): the green of the reference toast, one step darker so that white 14px/500 text keeps 4.5:1 (4.54:1).
|
|
21
|
-
* Used by the toast only
|
|
21
|
+
* Used by the toast only. It is the Figma primitive status/toast-green (added to the Primitives collection on 18 Nov 2026, so
|
|
22
|
+
* that the Foundations list and the library hold every colour of this file); a second use asks for a semantic token first.
|
|
22
23
|
*/
|
|
23
24
|
--color-toast-green: #008932;
|
|
24
25
|
|
|
@@ -71,6 +72,8 @@
|
|
|
71
72
|
--brand-subtle: var(--color-light-green);
|
|
72
73
|
--border: var(--color-neutral-200);
|
|
73
74
|
--border-strong: var(--color-alpha-dark-30);
|
|
75
|
+
/* The quiet line (Figma border/subtle, 18 Nov 2026): neutral/100, for the divider between the header of a panel and its body, where `--border` is too loud. */
|
|
76
|
+
--border-subtle: var(--color-neutral-100);
|
|
74
77
|
--input: var(--color-neutral-200);
|
|
75
78
|
--ring: var(--color-deep-forest-green);
|
|
76
79
|
--sidebar: var(--color-neutral-100);
|
|
@@ -123,6 +126,9 @@
|
|
|
123
126
|
--duration-base: 160ms;
|
|
124
127
|
--duration-slow: 250ms;
|
|
125
128
|
--duration-enter: 500ms;
|
|
129
|
+
/* A floating surface (dropdown, sub-menu, popover, select list, hover card) opening from its trigger: see `floating-motion` */
|
|
130
|
+
--duration-floating: 150ms;
|
|
131
|
+
--floating-slide: 8px;
|
|
126
132
|
--stagger-item: 50ms;
|
|
127
133
|
--ease-standard: ease;
|
|
128
134
|
--ease-out: cubic-bezier(0.23, 1, 0.32, 1);
|
|
@@ -170,6 +176,7 @@
|
|
|
170
176
|
--brand-subtle: var(--color-alpha-sage-15);
|
|
171
177
|
--border: var(--color-alpha-sage-25);
|
|
172
178
|
--border-strong: var(--color-alpha-light-30);
|
|
179
|
+
--border-subtle: var(--color-alpha-light-10);
|
|
173
180
|
--input: var(--color-alpha-sage-25);
|
|
174
181
|
--ring: var(--color-sage-green);
|
|
175
182
|
--sidebar: var(--color-dark);
|
|
@@ -213,6 +220,7 @@
|
|
|
213
220
|
--color-brand-subtle: var(--brand-subtle);
|
|
214
221
|
--color-border: var(--border);
|
|
215
222
|
--color-border-strong: var(--border-strong);
|
|
223
|
+
--color-border-subtle: var(--border-subtle);
|
|
216
224
|
--color-input: var(--input);
|
|
217
225
|
--color-ring: var(--ring);
|
|
218
226
|
--color-sidebar: var(--sidebar);
|
|
@@ -341,6 +349,65 @@
|
|
|
341
349
|
}
|
|
342
350
|
}
|
|
343
351
|
|
|
352
|
+
/*
|
|
353
|
+
* The motion of a floating surface that opens from a trigger (the dropdown and its sub-menus, the popover, the select list, the
|
|
354
|
+
* hover card; the account and workspace menus of the sidebar are dropdowns): it fades in while it slides `--floating-slide` (8px)
|
|
355
|
+
* from the side it opens towards, in `--duration-floating` (150ms) on `--ease-out`, so it arrives quickly and almost at once, the
|
|
356
|
+
* way a dialog slides in (owner, 18 Nov 2026). On the way out it only fades, in `--duration-fast`. People who ask for less motion get
|
|
357
|
+
* no animation at all. It reads the `data-state` and `data-side` that bits-ui writes on the floating element, so put it on the
|
|
358
|
+
* element that carries them (the `Content`), and do not combine it with the `animate-in` / `slide-in-from-*` utilities.
|
|
359
|
+
*
|
|
360
|
+
* Why not those utilities: `tailwindcss-animate` writes the slide as `--tw-enter-translate-y` in a `data-[side=bottom]:` rule and
|
|
361
|
+
* `data-[state=open]:animate-in` resets that variable to `initial`. Tailwind 4 puts the `data-[side=...]` rules before the
|
|
362
|
+
* `data-[state=...]` ones, so the reset won and the menus only faded: no slide at all (measured with `getAnimations()`).
|
|
363
|
+
* An open surface is anything that is not `closed`, because a tooltip says `delayed-open` and `instant-open`.
|
|
364
|
+
*/
|
|
365
|
+
@keyframes floating-enter {
|
|
366
|
+
from {
|
|
367
|
+
opacity: 0;
|
|
368
|
+
transform: translate3d(var(--floating-slide-x, 0px), var(--floating-slide-y, 0px), 0);
|
|
369
|
+
}
|
|
370
|
+
to {
|
|
371
|
+
opacity: 1;
|
|
372
|
+
transform: none;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
@keyframes floating-exit {
|
|
376
|
+
from {
|
|
377
|
+
opacity: 1;
|
|
378
|
+
}
|
|
379
|
+
to {
|
|
380
|
+
opacity: 0;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
@utility floating-motion {
|
|
384
|
+
&[data-side='bottom'] {
|
|
385
|
+
--floating-slide-y: calc(var(--floating-slide) * -1);
|
|
386
|
+
}
|
|
387
|
+
&[data-side='top'] {
|
|
388
|
+
--floating-slide-y: var(--floating-slide);
|
|
389
|
+
}
|
|
390
|
+
&[data-side='right'] {
|
|
391
|
+
--floating-slide-x: calc(var(--floating-slide) * -1);
|
|
392
|
+
}
|
|
393
|
+
&[data-side='left'] {
|
|
394
|
+
--floating-slide-x: var(--floating-slide);
|
|
395
|
+
}
|
|
396
|
+
&:not([data-state='closed']) {
|
|
397
|
+
animation: floating-enter var(--duration-floating) var(--ease-out) backwards;
|
|
398
|
+
}
|
|
399
|
+
&[data-state='closed'] {
|
|
400
|
+
animation: floating-exit var(--duration-fast) ease-out forwards;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
@media (prefers-reduced-motion: reduce) {
|
|
404
|
+
&:not([data-state='closed']),
|
|
405
|
+
&[data-state='closed'] {
|
|
406
|
+
animation: none;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
344
411
|
/*
|
|
345
412
|
* Text that is being worked on: a soft band of a lighter colour keeps passing over it, the way "Planning" waits for the plan, the
|
|
346
413
|
* task that is being built is shown, or "thinking" is said. Put `shimmer` on an element that holds only text and is as wide as that text
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enter in an open modal presses the modal's main button (owner, 18 Nov 2026: "when I have a modal open, if I click Enter,
|
|
3
|
+
* take it as the main CTA").
|
|
4
|
+
*
|
|
5
|
+
* Both modal shells of the design system (`BaseModal` and the bits-ui `Dialog.Content`) put the `modalEnterKey` action on
|
|
6
|
+
* their card, so every dialog built on them gets it without writing anything. A key press is for a card when it was pressed
|
|
7
|
+
* inside that card and no other card is closer to the focus: a modal that is open over another one never presses the buttons
|
|
8
|
+
* of the one under it.
|
|
9
|
+
*
|
|
10
|
+
* Which button: the one the person sees as the main one.
|
|
11
|
+
* 1. a button marked `data-modal-primary` (the last one, when several are), else
|
|
12
|
+
* 2. the last filled button of the card (design system `Button` with `variant` default, accent or destructive; the Button
|
|
13
|
+
* writes it as `data-variant`). The footer comes last in every dialog, so a filled button inside the body does not win.
|
|
14
|
+
* The last filled button is the one that counts even while it is disabled ("Create" waiting for a name): Enter then does
|
|
15
|
+
* nothing, it does not fall back on another button.
|
|
16
|
+
*
|
|
17
|
+
* When Enter belongs to the control it is pressed on, it is left alone: a focused button or link does its own thing (Enter on
|
|
18
|
+
* "Cancel" cancels), a textarea gets a new line (Cmd or Ctrl + Enter submits), a combobox, a list option that is not chosen
|
|
19
|
+
* yet, a select and a rich text field keep their Enter, and so does everything that has already handled the key
|
|
20
|
+
* (`defaultPrevented`, or a handler that stopped it from travelling on), which is how a dialog that has its own Enter in a
|
|
21
|
+
* field (the rename dialog) keeps working unchanged. A control can say it itself: `data-modal-enter="own"` on it or on something
|
|
22
|
+
* around it keeps Enter for the control, and `data-modal-enter="primary"` on a button hands its Enter to the main button
|
|
23
|
+
* instead (a choice that is only a step towards the main action).
|
|
24
|
+
*
|
|
25
|
+
* The listener is on the window, in the bubble phase, on purpose: Svelte 5 handles `onkeydown="…"` of an element once, at the
|
|
26
|
+
* root of the app, after the key has passed the card. A listener on the card would see the key before the field's own handler
|
|
27
|
+
* and take it from it; on the window it comes last, and sees what the field did with it.
|
|
28
|
+
*/
|
|
29
|
+
/** Marks the button that Enter presses. Put it on a button that is not the last filled button of the card. */
|
|
30
|
+
export declare const modalPrimaryAttribute = "data-modal-primary";
|
|
31
|
+
/** `own` on a control (or around it) keeps Enter for the control, `primary` on a button hands its Enter to the main button. */
|
|
32
|
+
export declare const modalEnterAttribute = "data-modal-enter";
|
|
33
|
+
/** Written by the action on the card of every modal, so that a key press can tell which card is the closest to the focus. */
|
|
34
|
+
export declare const modalCardAttribute = "data-modal-card";
|
|
35
|
+
/** What the decision needs to know about the element that has the focus (every DOM `Element` has all of it). */
|
|
36
|
+
export interface EnterTargetLike {
|
|
37
|
+
tagName?: string;
|
|
38
|
+
type?: string;
|
|
39
|
+
isContentEditable?: boolean;
|
|
40
|
+
getAttribute(name: string): string | null;
|
|
41
|
+
closest(selector: string): EnterTargetLike | null;
|
|
42
|
+
}
|
|
43
|
+
/** What the decision needs to know about the key press (a `KeyboardEvent` has all of it). */
|
|
44
|
+
export interface EnterKeyFacts {
|
|
45
|
+
key: string;
|
|
46
|
+
defaultPrevented: boolean;
|
|
47
|
+
isComposing: boolean;
|
|
48
|
+
repeat: boolean;
|
|
49
|
+
shiftKey: boolean;
|
|
50
|
+
altKey: boolean;
|
|
51
|
+
metaKey: boolean;
|
|
52
|
+
ctrlKey: boolean;
|
|
53
|
+
keyCode?: number;
|
|
54
|
+
target: EnterTargetLike | null;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Whether Enter, pressed with the focus on `target`, belongs to `target` (it does something there) and so is not for the
|
|
58
|
+
* main button. `submitShortcut` is Cmd or Ctrl + Enter, which a textarea gives to the dialog.
|
|
59
|
+
*/
|
|
60
|
+
export declare function targetKeepsEnter(target: EnterTargetLike | null, submitShortcut?: boolean): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Whether this key press is an Enter that the modal takes as "the main button": Enter, not handled by anything yet, not part of
|
|
63
|
+
* typing in another script (an IME choosing a character), not a held key (the main button is pressed once), not a line break
|
|
64
|
+
* (Shift or Alt + Enter), and not an Enter that the control it is on keeps for itself.
|
|
65
|
+
*/
|
|
66
|
+
export declare function shouldTakeEnterAsPrimary(facts: EnterKeyFacts): boolean;
|
|
67
|
+
/** What the search for the main button needs from a button. */
|
|
68
|
+
export interface PrimaryActionElement extends EnterTargetLike {
|
|
69
|
+
hasAttribute?(name: string): boolean;
|
|
70
|
+
disabled?: boolean;
|
|
71
|
+
hidden?: boolean;
|
|
72
|
+
click(): void;
|
|
73
|
+
textContent?: string | null;
|
|
74
|
+
}
|
|
75
|
+
/** What the search for the main button needs from the card of the modal. */
|
|
76
|
+
export interface PrimaryActionContainer {
|
|
77
|
+
querySelectorAll(selector: string): ArrayLike<PrimaryActionElement>;
|
|
78
|
+
}
|
|
79
|
+
/** True when the button can be pressed right now: not `disabled`, not `aria-disabled`. */
|
|
80
|
+
export declare function isActionEnabled(element: PrimaryActionElement): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* The main button of a modal card (see the rules at the top of this file), whether it can be pressed or not, and `null` when
|
|
83
|
+
* the card has none. The caller checks `isActionEnabled`.
|
|
84
|
+
*
|
|
85
|
+
* @param isVisible - Whether an element is drawn (a button inside a closed section is not). The page default reads the layout.
|
|
86
|
+
*/
|
|
87
|
+
export declare function findModalPrimaryAction(card: PrimaryActionContainer, isVisible?: (element: PrimaryActionElement) => boolean): PrimaryActionElement | null;
|
|
88
|
+
/** What `activateModalPrimaryOnEnter` reads of the key press, and what it does to it (a `KeyboardEvent` has all of it). */
|
|
89
|
+
export interface EnterKeyEventLike {
|
|
90
|
+
key: string;
|
|
91
|
+
defaultPrevented: boolean;
|
|
92
|
+
isComposing: boolean;
|
|
93
|
+
repeat: boolean;
|
|
94
|
+
shiftKey: boolean;
|
|
95
|
+
altKey: boolean;
|
|
96
|
+
metaKey: boolean;
|
|
97
|
+
ctrlKey: boolean;
|
|
98
|
+
keyCode?: number;
|
|
99
|
+
target: unknown;
|
|
100
|
+
composedPath?(): ArrayLike<unknown>;
|
|
101
|
+
preventDefault(): void;
|
|
102
|
+
stopPropagation(): void;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* What the decision reads of a key press. The properties are read one by one on purpose: a `KeyboardEvent` keeps them on its
|
|
106
|
+
* prototype, so spreading it into an object copies none of them.
|
|
107
|
+
*/
|
|
108
|
+
export declare function enterKeyFactsOf(event: EnterKeyEventLike): EnterKeyFacts;
|
|
109
|
+
/** How long after the main button was pressed a second Enter is not taken for another press (a double tap, a closing dialog). */
|
|
110
|
+
export declare const primaryPressCooldownMs = 400;
|
|
111
|
+
/** Whether a press at `lastPressAtMs` still counts as "just now" at `nowMs`. */
|
|
112
|
+
export declare function isWithinPressCooldown(lastPressAtMs: number, nowMs: number, cooldownMs?: number): boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Presses the main button of `card` for an Enter key press, when the key press is one that the modal takes (see
|
|
115
|
+
* `shouldTakeEnterAsPrimary`) and the card has a main button that can be pressed.
|
|
116
|
+
*
|
|
117
|
+
* The key is then kept from everything else: `preventDefault` stops the browser from also submitting a form the focused field
|
|
118
|
+
* is in (the button's own press does that, once), `stopPropagation` stops the key from travelling on.
|
|
119
|
+
*
|
|
120
|
+
* @returns whether the main button was pressed
|
|
121
|
+
*/
|
|
122
|
+
export declare function activateModalPrimaryOnEnter(event: EnterKeyEventLike, card: PrimaryActionContainer, isVisible?: (element: PrimaryActionElement) => boolean): boolean;
|
|
123
|
+
/**
|
|
124
|
+
* Whether the key press belongs to `card`: it was pressed inside it, and no other modal card is closer to the focus (a modal
|
|
125
|
+
* drawn inside another one's markup is the closest one).
|
|
126
|
+
*/
|
|
127
|
+
export declare function keyPressBelongsToCard(path: ArrayLike<unknown>, card: unknown): boolean;
|
|
128
|
+
/**
|
|
129
|
+
* Svelte action for the card of a modal: Enter pressed inside the card presses its main button (see the top of this file).
|
|
130
|
+
* `enabled: false` switches it off for a modal that wants Enter for itself.
|
|
131
|
+
*/
|
|
132
|
+
export declare function modalEnterKey(card: HTMLElement, options?: {
|
|
133
|
+
enabled?: boolean;
|
|
134
|
+
}): {
|
|
135
|
+
update(nextOptions?: {
|
|
136
|
+
enabled?: boolean;
|
|
137
|
+
}): void;
|
|
138
|
+
destroy(): void;
|
|
139
|
+
};
|