@nqmcreative/ui 0.1.1 → 0.2.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 +89 -34
- package/cli/index.mjs +67 -30
- package/dist/core/calendar.d.ts +3 -0
- package/dist/core/calendar.js +36 -0
- package/dist/core/dialog.svelte.d.ts +14 -0
- package/dist/core/dialog.svelte.js +23 -0
- package/dist/core/files.d.ts +35 -0
- package/dist/core/files.js +62 -0
- package/dist/core/index.d.ts +37 -0
- package/dist/core/index.js +35 -0
- package/dist/core/list.svelte.d.ts +41 -0
- package/dist/core/list.svelte.js +77 -0
- package/dist/core/number.d.ts +7 -0
- package/dist/core/number.js +17 -0
- package/dist/core/pagination.d.ts +6 -0
- package/dist/core/pagination.js +21 -0
- package/dist/core/password.d.ts +8 -0
- package/dist/core/password.js +23 -0
- package/dist/core/table.d.ts +22 -0
- package/dist/core/table.js +41 -0
- package/dist/core/theme.svelte.d.ts +16 -0
- package/dist/core/theme.svelte.js +34 -0
- package/dist/core/trigger.d.ts +35 -0
- package/dist/core/trigger.js +77 -0
- package/dist/index.d.ts +11 -103
- package/dist/index.js +11 -75
- package/dist/{components → styles/matte}/AccordionItem.svelte +1 -1
- package/dist/{components → styles/matte}/AccordionItem.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/Alert.svelte +8 -2
- package/dist/{components → styles/matte}/Alert.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/Avatar.svelte +1 -1
- package/dist/{components → styles/matte}/Avatar.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/Badge.svelte +8 -3
- package/dist/{components → styles/matte}/Badge.svelte.d.ts +1 -3
- package/dist/{components → styles/matte}/Breadcrumb.svelte +2 -2
- package/dist/{components → styles/matte}/Breadcrumb.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/Button.svelte +1 -1
- package/dist/{components → styles/matte}/Button.svelte.d.ts +1 -1
- package/dist/styles/matte/CTASection.svelte +76 -0
- package/dist/styles/matte/CTASection.svelte.d.ts +18 -0
- package/dist/{components → styles/matte}/Calendar.svelte +7 -17
- package/dist/{components → styles/matte}/Calendar.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/Card.svelte +1 -1
- package/dist/{components → styles/matte}/Card.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/Checkbox.svelte +1 -1
- package/dist/{components → styles/matte}/Checkbox.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/CheckboxGroup.svelte +1 -1
- package/dist/{components → styles/matte}/CheckboxGroup.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/Combobox.svelte +31 -42
- package/dist/{components → styles/matte}/Combobox.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/CommandPalette.svelte +26 -41
- package/dist/{components → styles/matte}/CommandPalette.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/ConfirmDialog.svelte +2 -2
- package/dist/{components → styles/matte}/ConfirmDialog.svelte.d.ts +2 -2
- package/dist/{components → styles/matte}/ContextMenu.svelte +5 -7
- package/dist/{components → styles/matte}/DatePicker.svelte +7 -11
- package/dist/{components → styles/matte}/DatePicker.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/Drawer.svelte +4 -7
- package/dist/{components → styles/matte}/Dropdown.svelte +18 -36
- package/dist/{components → styles/matte}/Dropdown.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/Dropzone.svelte +11 -43
- package/dist/{components → styles/matte}/Dropzone.svelte.d.ts +2 -5
- package/dist/{components → styles/matte}/EmptyState.svelte +1 -1
- package/dist/{components → styles/matte}/EmptyState.svelte.d.ts +1 -1
- package/dist/styles/matte/FeatureCard.svelte +58 -0
- package/dist/styles/matte/FeatureCard.svelte.d.ts +16 -0
- package/dist/styles/matte/FeatureGrid.svelte +62 -0
- package/dist/styles/matte/FeatureGrid.svelte.d.ts +16 -0
- package/dist/{components → styles/matte}/Footer.svelte +1 -1
- package/dist/{components → styles/matte}/Footer.svelte.d.ts +1 -1
- package/dist/styles/matte/HeroSection.svelte +80 -0
- package/dist/styles/matte/HeroSection.svelte.d.ts +21 -0
- package/dist/{components → styles/matte}/Input.svelte +1 -1
- package/dist/{components → styles/matte}/Input.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/Link.svelte +1 -1
- package/dist/{components → styles/matte}/Link.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/LocaleProvider.svelte +1 -1
- package/dist/{components → styles/matte}/LocaleProvider.svelte.d.ts +1 -1
- package/dist/styles/matte/LogoCloud.svelte +61 -0
- package/dist/styles/matte/LogoCloud.svelte.d.ts +19 -0
- package/dist/{components → styles/matte}/MenuItem.svelte +1 -1
- package/dist/{components → styles/matte}/MenuItem.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/Modal.svelte +4 -7
- package/dist/{components → styles/matte}/MultiSelect.svelte +18 -37
- package/dist/{components → styles/matte}/MultiSelect.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/Navbar.svelte +2 -2
- package/dist/{components → styles/matte}/Navbar.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/NumberInput.svelte +4 -8
- package/dist/{components → styles/matte}/NumberInput.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/Pagination.svelte +4 -15
- package/dist/{components → styles/matte}/Pagination.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/PasswordInput.svelte +4 -13
- package/dist/{components → styles/matte}/PasswordInput.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/Popover.svelte +16 -41
- package/dist/{components → styles/matte}/Popover.svelte.d.ts +1 -1
- package/dist/styles/matte/PricingCard.svelte +107 -0
- package/dist/styles/matte/PricingCard.svelte.d.ts +25 -0
- package/dist/{components → styles/matte}/Progress.svelte +3 -2
- package/dist/{components → styles/matte}/Progress.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/Radio.svelte +1 -1
- package/dist/{components → styles/matte}/Radio.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/RadioGroup.svelte +1 -1
- package/dist/{components → styles/matte}/RadioGroup.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/SegmentedControl.svelte +1 -1
- package/dist/{components → styles/matte}/SegmentedControl.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/Select.svelte +1 -1
- package/dist/{components → styles/matte}/Select.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/Sidebar.svelte +2 -2
- package/dist/{components → styles/matte}/Sidebar.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/Slider.svelte +3 -2
- package/dist/{components → styles/matte}/Slider.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/Spinner.svelte +2 -2
- package/dist/{components → styles/matte}/Spinner.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/Stat.svelte +1 -1
- package/dist/{components → styles/matte}/Stat.svelte.d.ts +1 -1
- package/dist/styles/matte/StatsBand.svelte +57 -0
- package/dist/styles/matte/StatsBand.svelte.d.ts +20 -0
- package/dist/{components → styles/matte}/Steps.svelte +1 -1
- package/dist/{components → styles/matte}/Steps.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/Switch.svelte +1 -1
- package/dist/{components → styles/matte}/Switch.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/Table.svelte +6 -28
- package/dist/{components → styles/matte}/Table.svelte.d.ts +2 -6
- package/dist/{components → styles/matte}/Tabs.svelte +8 -1
- package/dist/{components → styles/matte}/Tabs.svelte.d.ts +1 -1
- package/dist/styles/matte/Testimonial.svelte +67 -0
- package/dist/styles/matte/Testimonial.svelte.d.ts +19 -0
- package/dist/{components → styles/matte}/Textarea.svelte +1 -1
- package/dist/{components → styles/matte}/Textarea.svelte.d.ts +1 -1
- package/dist/{components → styles/matte}/ThemeToggle.svelte +14 -27
- package/dist/{components → styles/matte}/ThemeToggle.svelte.d.ts +2 -6
- package/dist/{components → styles/matte}/Toaster.svelte +4 -4
- package/dist/styles/matte/index.d.ts +109 -0
- package/dist/styles/matte/index.js +83 -0
- package/dist/styles/paper/Accordion.svelte +17 -0
- package/dist/styles/paper/Accordion.svelte.d.ts +8 -0
- package/dist/styles/paper/AccordionItem.svelte +46 -0
- package/dist/styles/paper/AccordionItem.svelte.d.ts +14 -0
- package/dist/styles/paper/Alert.svelte +99 -0
- package/dist/styles/paper/Alert.svelte.d.ts +18 -0
- package/dist/styles/paper/Avatar.svelte +60 -0
- package/dist/styles/paper/Avatar.svelte.d.ts +16 -0
- package/dist/styles/paper/AvatarGroup.svelte +17 -0
- package/dist/styles/paper/AvatarGroup.svelte.d.ts +8 -0
- package/dist/styles/paper/Badge.svelte +58 -0
- package/dist/styles/paper/Badge.svelte.d.ts +16 -0
- package/dist/styles/paper/Breadcrumb.svelte +49 -0
- package/dist/styles/paper/Breadcrumb.svelte.d.ts +14 -0
- package/dist/styles/paper/Button.svelte +96 -0
- package/dist/styles/paper/Button.svelte.d.ts +21 -0
- package/dist/styles/paper/CTASection.svelte +76 -0
- package/dist/styles/paper/CTASection.svelte.d.ts +18 -0
- package/dist/styles/paper/Calendar.svelte +202 -0
- package/dist/styles/paper/Calendar.svelte.d.ts +22 -0
- package/dist/styles/paper/Card.svelte +78 -0
- package/dist/styles/paper/Card.svelte.d.ts +21 -0
- package/dist/styles/paper/Checkbox.svelte +75 -0
- package/dist/styles/paper/Checkbox.svelte.d.ts +15 -0
- package/dist/styles/paper/CheckboxGroup.svelte +111 -0
- package/dist/styles/paper/CheckboxGroup.svelte.d.ts +30 -0
- package/dist/styles/paper/Combobox.svelte +266 -0
- package/dist/styles/paper/Combobox.svelte.d.ts +29 -0
- package/dist/styles/paper/CommandPalette.svelte +209 -0
- package/dist/styles/paper/CommandPalette.svelte.d.ts +32 -0
- package/dist/styles/paper/ConfirmDialog.svelte +97 -0
- package/dist/styles/paper/ConfirmDialog.svelte.d.ts +22 -0
- package/dist/styles/paper/ContextMenu.svelte +88 -0
- package/dist/styles/paper/ContextMenu.svelte.d.ts +15 -0
- package/dist/styles/paper/DatePicker.svelte +192 -0
- package/dist/styles/paper/DatePicker.svelte.d.ts +23 -0
- package/dist/styles/paper/Divider.svelte +30 -0
- package/dist/styles/paper/Divider.svelte.d.ts +10 -0
- package/dist/styles/paper/Drawer.svelte +165 -0
- package/dist/styles/paper/Drawer.svelte.d.ts +20 -0
- package/dist/styles/paper/Dropdown.svelte +94 -0
- package/dist/styles/paper/Dropdown.svelte.d.ts +23 -0
- package/dist/styles/paper/Dropzone.svelte +210 -0
- package/dist/styles/paper/Dropzone.svelte.d.ts +29 -0
- package/dist/styles/paper/EmptyState.svelte +71 -0
- package/dist/styles/paper/EmptyState.svelte.d.ts +18 -0
- package/dist/styles/paper/FeatureCard.svelte +58 -0
- package/dist/styles/paper/FeatureCard.svelte.d.ts +16 -0
- package/dist/styles/paper/FeatureGrid.svelte +62 -0
- package/dist/styles/paper/FeatureGrid.svelte.d.ts +16 -0
- package/dist/styles/paper/Field.svelte +42 -0
- package/dist/styles/paper/Field.svelte.d.ts +16 -0
- package/dist/styles/paper/Footer.svelte +91 -0
- package/dist/styles/paper/Footer.svelte.d.ts +25 -0
- package/dist/styles/paper/HeroSection.svelte +86 -0
- package/dist/styles/paper/HeroSection.svelte.d.ts +21 -0
- package/dist/styles/paper/Input.svelte +60 -0
- package/dist/styles/paper/Input.svelte.d.ts +18 -0
- package/dist/styles/paper/InputGroup.svelte +20 -0
- package/dist/styles/paper/InputGroup.svelte.d.ts +11 -0
- package/dist/styles/paper/Kbd.svelte +17 -0
- package/dist/styles/paper/Kbd.svelte.d.ts +8 -0
- package/dist/styles/paper/Label.svelte +16 -0
- package/dist/styles/paper/Label.svelte.d.ts +9 -0
- package/dist/styles/paper/Link.svelte +44 -0
- package/dist/styles/paper/Link.svelte.d.ts +16 -0
- package/dist/styles/paper/LocaleProvider.svelte +24 -0
- package/dist/styles/paper/LocaleProvider.svelte.d.ts +10 -0
- package/dist/styles/paper/LogoCloud.svelte +61 -0
- package/dist/styles/paper/LogoCloud.svelte.d.ts +19 -0
- package/dist/styles/paper/MenuItem.svelte +64 -0
- package/dist/styles/paper/MenuItem.svelte.d.ts +18 -0
- package/dist/styles/paper/MenuSeparator.svelte +22 -0
- package/dist/styles/paper/MenuSeparator.svelte.d.ts +8 -0
- package/dist/styles/paper/Modal.svelte +118 -0
- package/dist/styles/paper/Modal.svelte.d.ts +21 -0
- package/dist/styles/paper/MultiSelect.svelte +287 -0
- package/dist/styles/paper/MultiSelect.svelte.d.ts +31 -0
- package/dist/styles/paper/Navbar.svelte +201 -0
- package/dist/styles/paper/Navbar.svelte.d.ts +33 -0
- package/dist/styles/paper/NumberInput.svelte +96 -0
- package/dist/styles/paper/NumberInput.svelte.d.ts +15 -0
- package/dist/styles/paper/Pagination.svelte +83 -0
- package/dist/styles/paper/Pagination.svelte.d.ts +15 -0
- package/dist/styles/paper/PasswordInput.svelte +100 -0
- package/dist/styles/paper/PasswordInput.svelte.d.ts +12 -0
- package/dist/styles/paper/Popover.svelte +89 -0
- package/dist/styles/paper/Popover.svelte.d.ts +19 -0
- package/dist/styles/paper/PricingCard.svelte +108 -0
- package/dist/styles/paper/PricingCard.svelte.d.ts +25 -0
- package/dist/styles/paper/Progress.svelte +59 -0
- package/dist/styles/paper/Progress.svelte.d.ts +17 -0
- package/dist/styles/paper/Radio.svelte +55 -0
- package/dist/styles/paper/Radio.svelte.d.ts +15 -0
- package/dist/styles/paper/RadioGroup.svelte +95 -0
- package/dist/styles/paper/RadioGroup.svelte.d.ts +27 -0
- package/dist/styles/paper/SegmentedControl.svelte +88 -0
- package/dist/styles/paper/SegmentedControl.svelte.d.ts +25 -0
- package/dist/styles/paper/Select.svelte +61 -0
- package/dist/styles/paper/Select.svelte.d.ts +20 -0
- package/dist/styles/paper/Sidebar.svelte +206 -0
- package/dist/styles/paper/Sidebar.svelte.d.ts +36 -0
- package/dist/styles/paper/Skeleton.svelte +46 -0
- package/dist/styles/paper/Skeleton.svelte.d.ts +13 -0
- package/dist/styles/paper/Slider.svelte +80 -0
- package/dist/styles/paper/Slider.svelte.d.ts +19 -0
- package/dist/styles/paper/Spinner.svelte +34 -0
- package/dist/styles/paper/Spinner.svelte.d.ts +13 -0
- package/dist/styles/paper/Stat.svelte +51 -0
- package/dist/styles/paper/Stat.svelte.d.ts +16 -0
- package/dist/styles/paper/StatsBand.svelte +63 -0
- package/dist/styles/paper/StatsBand.svelte.d.ts +20 -0
- package/dist/styles/paper/Steps.svelte +141 -0
- package/dist/styles/paper/Steps.svelte.d.ts +24 -0
- package/dist/styles/paper/Switch.svelte +64 -0
- package/dist/styles/paper/Switch.svelte.d.ts +14 -0
- package/dist/styles/paper/Table.svelte +217 -0
- package/dist/styles/paper/Table.svelte.d.ts +66 -0
- package/dist/styles/paper/Tabs.svelte +102 -0
- package/dist/styles/paper/Tabs.svelte.d.ts +23 -0
- package/dist/styles/paper/Testimonial.svelte +64 -0
- package/dist/styles/paper/Testimonial.svelte.d.ts +19 -0
- package/dist/styles/paper/Textarea.svelte +54 -0
- package/dist/styles/paper/Textarea.svelte.d.ts +12 -0
- package/dist/styles/paper/ThemeToggle.svelte +130 -0
- package/dist/styles/paper/ThemeToggle.svelte.d.ts +16 -0
- package/dist/styles/paper/Toaster.svelte +132 -0
- package/dist/styles/paper/Toaster.svelte.d.ts +8 -0
- package/dist/styles/paper/Tooltip.svelte +33 -0
- package/dist/styles/paper/Tooltip.svelte.d.ts +12 -0
- package/dist/styles/paper/fonts.css +46 -0
- package/dist/styles/paper/index.d.ts +109 -0
- package/dist/styles/paper/index.js +83 -0
- package/dist/styles/paper/theme.css +222 -0
- package/package.json +531 -201
- package/registry.json +658 -339
- /package/dist/{actions → core/actions}/anchor.d.ts +0 -0
- /package/dist/{actions → core/actions}/anchor.js +0 -0
- /package/dist/{actions → core/actions}/dismissable.d.ts +0 -0
- /package/dist/{actions → core/actions}/dismissable.js +0 -0
- /package/dist/{date.d.ts → core/date.d.ts} +0 -0
- /package/dist/{date.js → core/date.js} +0 -0
- /package/dist/{locale.svelte.d.ts → core/locale.svelte.d.ts} +0 -0
- /package/dist/{locale.svelte.js → core/locale.svelte.js} +0 -0
- /package/dist/{toast.svelte.d.ts → core/toast.svelte.d.ts} +0 -0
- /package/dist/{toast.svelte.js → core/toast.svelte.js} +0 -0
- /package/dist/{tones.d.ts → core/tones.d.ts} +0 -0
- /package/dist/{tones.js → core/tones.js} +0 -0
- /package/dist/{components → styles/matte}/Accordion.svelte +0 -0
- /package/dist/{components → styles/matte}/Accordion.svelte.d.ts +0 -0
- /package/dist/{components → styles/matte}/AvatarGroup.svelte +0 -0
- /package/dist/{components → styles/matte}/AvatarGroup.svelte.d.ts +0 -0
- /package/dist/{components → styles/matte}/ContextMenu.svelte.d.ts +0 -0
- /package/dist/{components → styles/matte}/Divider.svelte +0 -0
- /package/dist/{components → styles/matte}/Divider.svelte.d.ts +0 -0
- /package/dist/{components → styles/matte}/Drawer.svelte.d.ts +0 -0
- /package/dist/{components → styles/matte}/Field.svelte +0 -0
- /package/dist/{components → styles/matte}/Field.svelte.d.ts +0 -0
- /package/dist/{components → styles/matte}/InputGroup.svelte +0 -0
- /package/dist/{components → styles/matte}/InputGroup.svelte.d.ts +0 -0
- /package/dist/{components → styles/matte}/Kbd.svelte +0 -0
- /package/dist/{components → styles/matte}/Kbd.svelte.d.ts +0 -0
- /package/dist/{components → styles/matte}/Label.svelte +0 -0
- /package/dist/{components → styles/matte}/Label.svelte.d.ts +0 -0
- /package/dist/{components → styles/matte}/MenuSeparator.svelte +0 -0
- /package/dist/{components → styles/matte}/MenuSeparator.svelte.d.ts +0 -0
- /package/dist/{components → styles/matte}/Modal.svelte.d.ts +0 -0
- /package/dist/{components → styles/matte}/Skeleton.svelte +0 -0
- /package/dist/{components → styles/matte}/Skeleton.svelte.d.ts +0 -0
- /package/dist/{components → styles/matte}/Toaster.svelte.d.ts +0 -0
- /package/dist/{components → styles/matte}/Tooltip.svelte +0 -0
- /package/dist/{components → styles/matte}/Tooltip.svelte.d.ts +0 -0
- /package/dist/{fonts.css → styles/matte/fonts.css} +0 -0
- /package/dist/{theme.css → styles/matte/theme.css} +0 -0
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
export interface CommandItem {
|
|
3
|
+
id: string;
|
|
4
|
+
label: string;
|
|
5
|
+
/** Second line under the label. */
|
|
6
|
+
description?: string;
|
|
7
|
+
/** Items sharing a group are rendered under one heading. */
|
|
8
|
+
group?: string;
|
|
9
|
+
/** Right-aligned hint, e.g. `'⌘K'`. */
|
|
10
|
+
shortcut?: string;
|
|
11
|
+
/** Extra words to match on that aren't in the label. */
|
|
12
|
+
keywords?: string;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
onselect?: () => void;
|
|
15
|
+
}
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<script lang="ts">
|
|
19
|
+
import { focusTrap } from '../../core/actions/dismissable.js';
|
|
20
|
+
import { syncDialog } from '../../core/dialog.svelte.js';
|
|
21
|
+
import { ListCursor, groupItems, matchQuery, revealIndex } from '../../core/list.svelte.js';
|
|
22
|
+
import { useLocale } from '../../core/locale.svelte.js';
|
|
23
|
+
import { toneSoft, type Tone } from '../../core/tones.js';
|
|
24
|
+
import Kbd from './Kbd.svelte';
|
|
25
|
+
|
|
26
|
+
interface Props {
|
|
27
|
+
open?: boolean;
|
|
28
|
+
items: CommandItem[];
|
|
29
|
+
placeholder?: string;
|
|
30
|
+
emptyText?: string;
|
|
31
|
+
tone?: Tone;
|
|
32
|
+
/**
|
|
33
|
+
* Key that opens the palette with Cmd/Ctrl held. Default `'k'`.
|
|
34
|
+
* Pass `null` to wire your own trigger only.
|
|
35
|
+
*/
|
|
36
|
+
hotkey?: string | null;
|
|
37
|
+
onselect?: (item: CommandItem) => void;
|
|
38
|
+
class?: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
let {
|
|
42
|
+
open = $bindable(false),
|
|
43
|
+
items,
|
|
44
|
+
placeholder,
|
|
45
|
+
emptyText,
|
|
46
|
+
tone = 'brand',
|
|
47
|
+
hotkey = 'k',
|
|
48
|
+
onselect,
|
|
49
|
+
class: className = ''
|
|
50
|
+
}: Props = $props();
|
|
51
|
+
|
|
52
|
+
const t = useLocale();
|
|
53
|
+
|
|
54
|
+
let dialog: HTMLDialogElement | null = $state(null);
|
|
55
|
+
let inputEl: HTMLInputElement | null = $state(null);
|
|
56
|
+
let listEl: HTMLElement | null = $state(null);
|
|
57
|
+
let query = $state('');
|
|
58
|
+
|
|
59
|
+
const matches = $derived(
|
|
60
|
+
matchQuery(
|
|
61
|
+
items,
|
|
62
|
+
query,
|
|
63
|
+
(item) => `${item.label} ${item.description ?? ''} ${item.keywords ?? ''} ${item.group ?? ''}`
|
|
64
|
+
)
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
const groups = $derived(groupItems(matches));
|
|
68
|
+
const flat = $derived(groups.flatMap(([, group]) => group));
|
|
69
|
+
|
|
70
|
+
const cursor = new ListCursor(() => flat);
|
|
71
|
+
const active = $derived(cursor.index);
|
|
72
|
+
|
|
73
|
+
$effect(() => {
|
|
74
|
+
if (!dialog) return;
|
|
75
|
+
const wasOpen = dialog.open;
|
|
76
|
+
syncDialog(dialog, open);
|
|
77
|
+
if (open && !wasOpen) {
|
|
78
|
+
query = '';
|
|
79
|
+
cursor.reset();
|
|
80
|
+
queueMicrotask(() => inputEl?.focus());
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
$effect(() => {
|
|
85
|
+
if (!hotkey) return;
|
|
86
|
+
const onKeydown = (event: KeyboardEvent) => {
|
|
87
|
+
if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === hotkey.toLowerCase()) {
|
|
88
|
+
event.preventDefault();
|
|
89
|
+
open = !open;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
window.addEventListener('keydown', onKeydown);
|
|
93
|
+
return () => window.removeEventListener('keydown', onKeydown);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
function run(item: CommandItem) {
|
|
97
|
+
if (item.disabled) return;
|
|
98
|
+
open = false;
|
|
99
|
+
item.onselect?.();
|
|
100
|
+
onselect?.(item);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function move(step: number) {
|
|
104
|
+
cursor.move(step);
|
|
105
|
+
revealIndex(listEl, cursor.index);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function onKeydown(event: KeyboardEvent) {
|
|
109
|
+
switch (event.key) {
|
|
110
|
+
case 'ArrowDown':
|
|
111
|
+
event.preventDefault();
|
|
112
|
+
move(1);
|
|
113
|
+
break;
|
|
114
|
+
case 'ArrowUp':
|
|
115
|
+
event.preventDefault();
|
|
116
|
+
move(-1);
|
|
117
|
+
break;
|
|
118
|
+
case 'Enter':
|
|
119
|
+
if (cursor.current) {
|
|
120
|
+
event.preventDefault();
|
|
121
|
+
run(cursor.current);
|
|
122
|
+
}
|
|
123
|
+
break;
|
|
124
|
+
case 'Escape':
|
|
125
|
+
event.preventDefault();
|
|
126
|
+
open = false;
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
</script>
|
|
131
|
+
|
|
132
|
+
<dialog
|
|
133
|
+
bind:this={dialog}
|
|
134
|
+
onclose={() => (open = false)}
|
|
135
|
+
onclick={(event) => {
|
|
136
|
+
if (event.target === dialog) open = false;
|
|
137
|
+
}}
|
|
138
|
+
class="mx-auto mt-[12vh] mb-auto w-[min(36rem,calc(100vw-2rem))] max-w-none rounded-xl border border-hairline bg-bg p-0 text-text shadow-2xl backdrop:bg-text/30 backdrop:backdrop-blur-[1px] {className}"
|
|
139
|
+
>
|
|
140
|
+
<div use:focusTrap={{ autofocus: false }} onkeydown={onKeydown} role="none" class="flex flex-col">
|
|
141
|
+
<div class="flex items-center gap-3 border-b border-hairline px-4">
|
|
142
|
+
<svg
|
|
143
|
+
class="size-4 shrink-0 text-text-muted"
|
|
144
|
+
viewBox="0 0 16 16"
|
|
145
|
+
fill="none"
|
|
146
|
+
aria-hidden="true"
|
|
147
|
+
>
|
|
148
|
+
<circle cx="7" cy="7" r="4.5" stroke="currentColor" stroke-width="1.5" />
|
|
149
|
+
<path d="m10.5 10.5 3 3" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" />
|
|
150
|
+
</svg>
|
|
151
|
+
<input
|
|
152
|
+
bind:this={inputEl}
|
|
153
|
+
bind:value={query}
|
|
154
|
+
oninput={() => cursor.reset()}
|
|
155
|
+
type="text"
|
|
156
|
+
autocomplete="off"
|
|
157
|
+
aria-label={placeholder ?? t.current.commandPlaceholder}
|
|
158
|
+
placeholder={placeholder ?? t.current.commandPlaceholder}
|
|
159
|
+
class="h-12 w-full min-w-0 bg-transparent font-sans text-sm text-text placeholder:text-text-muted focus:outline-none"
|
|
160
|
+
/>
|
|
161
|
+
<Kbd>esc</Kbd>
|
|
162
|
+
</div>
|
|
163
|
+
|
|
164
|
+
<div
|
|
165
|
+
bind:this={listEl}
|
|
166
|
+
role="listbox"
|
|
167
|
+
aria-label="Commands"
|
|
168
|
+
class="max-h-80 overflow-y-auto py-1"
|
|
169
|
+
>
|
|
170
|
+
{#if flat.length === 0}
|
|
171
|
+
<p class="px-4 py-10 text-center font-sans text-sm text-text-muted">
|
|
172
|
+
{emptyText ?? t.current.noResults}
|
|
173
|
+
</p>
|
|
174
|
+
{:else}
|
|
175
|
+
{#each groups as [group, groupItems] (group)}
|
|
176
|
+
{#if group}
|
|
177
|
+
<p class="px-4 pt-3 pb-1 text-[11px] font-semibold text-text-muted">{group}</p>
|
|
178
|
+
{/if}
|
|
179
|
+
{#each groupItems as item (item.id)}
|
|
180
|
+
{@const index = flat.indexOf(item)}
|
|
181
|
+
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
182
|
+
<div
|
|
183
|
+
data-index={index}
|
|
184
|
+
role="option"
|
|
185
|
+
tabindex="-1"
|
|
186
|
+
aria-selected={index === active}
|
|
187
|
+
aria-disabled={item.disabled}
|
|
188
|
+
onclick={() => run(item)}
|
|
189
|
+
onpointermove={() => (cursor.index = index)}
|
|
190
|
+
class="mx-2 flex cursor-pointer items-center gap-3 rounded-md px-2.5 py-2 font-sans text-sm transition-colors duration-100
|
|
191
|
+
{item.disabled ? 'pointer-events-none opacity-40' : ''}
|
|
192
|
+
{index === active ? toneSoft[tone] : 'text-text-secondary'}"
|
|
193
|
+
>
|
|
194
|
+
<span class="flex min-w-0 flex-1 flex-col gap-0.5">
|
|
195
|
+
<span class="truncate">{item.label}</span>
|
|
196
|
+
{#if item.description}
|
|
197
|
+
<span class="truncate text-xs text-text-muted">{item.description}</span>
|
|
198
|
+
{/if}
|
|
199
|
+
</span>
|
|
200
|
+
{#if item.shortcut}
|
|
201
|
+
<span class="shrink-0 text-[11px] text-text-muted">{item.shortcut}</span>
|
|
202
|
+
{/if}
|
|
203
|
+
</div>
|
|
204
|
+
{/each}
|
|
205
|
+
{/each}
|
|
206
|
+
{/if}
|
|
207
|
+
</div>
|
|
208
|
+
</div>
|
|
209
|
+
</dialog>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export interface CommandItem {
|
|
2
|
+
id: string;
|
|
3
|
+
label: string;
|
|
4
|
+
/** Second line under the label. */
|
|
5
|
+
description?: string;
|
|
6
|
+
/** Items sharing a group are rendered under one heading. */
|
|
7
|
+
group?: string;
|
|
8
|
+
/** Right-aligned hint, e.g. `'⌘K'`. */
|
|
9
|
+
shortcut?: string;
|
|
10
|
+
/** Extra words to match on that aren't in the label. */
|
|
11
|
+
keywords?: string;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
onselect?: () => void;
|
|
14
|
+
}
|
|
15
|
+
import { type Tone } from '../../core/tones.js';
|
|
16
|
+
interface Props {
|
|
17
|
+
open?: boolean;
|
|
18
|
+
items: CommandItem[];
|
|
19
|
+
placeholder?: string;
|
|
20
|
+
emptyText?: string;
|
|
21
|
+
tone?: Tone;
|
|
22
|
+
/**
|
|
23
|
+
* Key that opens the palette with Cmd/Ctrl held. Default `'k'`.
|
|
24
|
+
* Pass `null` to wire your own trigger only.
|
|
25
|
+
*/
|
|
26
|
+
hotkey?: string | null;
|
|
27
|
+
onselect?: (item: CommandItem) => void;
|
|
28
|
+
class?: string;
|
|
29
|
+
}
|
|
30
|
+
declare const CommandPalette: import("svelte").Component<Props, {}, "open">;
|
|
31
|
+
type CommandPalette = ReturnType<typeof CommandPalette>;
|
|
32
|
+
export default CommandPalette;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import Button from './Button.svelte';
|
|
4
|
+
import Modal from './Modal.svelte';
|
|
5
|
+
import { useLocale } from '../../core/locale.svelte.js';
|
|
6
|
+
import { toneSoft, type Tone } from '../../core/tones.js';
|
|
7
|
+
|
|
8
|
+
interface Props {
|
|
9
|
+
open?: boolean;
|
|
10
|
+
title: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
/** Drives the confirm button and the glyph. `danger` for destructive acts. */
|
|
13
|
+
tone?: Tone;
|
|
14
|
+
confirmLabel?: string;
|
|
15
|
+
cancelLabel?: string;
|
|
16
|
+
/** Spins the confirm button and blocks dismissal while the action runs. */
|
|
17
|
+
loading?: boolean;
|
|
18
|
+
/** Awaited — the dialog stays open and busy until it settles. */
|
|
19
|
+
onconfirm?: () => void | Promise<void>;
|
|
20
|
+
oncancel?: () => void;
|
|
21
|
+
icon?: Snippet;
|
|
22
|
+
/** Extra content between the description and the buttons. */
|
|
23
|
+
children?: Snippet;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let {
|
|
27
|
+
open = $bindable(false),
|
|
28
|
+
title,
|
|
29
|
+
description,
|
|
30
|
+
tone = 'danger',
|
|
31
|
+
confirmLabel,
|
|
32
|
+
cancelLabel,
|
|
33
|
+
loading = $bindable(false),
|
|
34
|
+
onconfirm,
|
|
35
|
+
oncancel,
|
|
36
|
+
icon,
|
|
37
|
+
children
|
|
38
|
+
}: Props = $props();
|
|
39
|
+
|
|
40
|
+
const t = useLocale();
|
|
41
|
+
|
|
42
|
+
async function confirm() {
|
|
43
|
+
try {
|
|
44
|
+
loading = true;
|
|
45
|
+
await onconfirm?.();
|
|
46
|
+
open = false;
|
|
47
|
+
} finally {
|
|
48
|
+
loading = false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function cancel() {
|
|
53
|
+
if (loading) return;
|
|
54
|
+
open = false;
|
|
55
|
+
oncancel?.();
|
|
56
|
+
}
|
|
57
|
+
</script>
|
|
58
|
+
|
|
59
|
+
<Modal
|
|
60
|
+
bind:open
|
|
61
|
+
size="sm"
|
|
62
|
+
dismissible={!loading}
|
|
63
|
+
showClose={false}
|
|
64
|
+
onclose={() => (loading = false)}
|
|
65
|
+
>
|
|
66
|
+
<div class="flex items-start gap-4">
|
|
67
|
+
<span class="flex size-10 shrink-0 items-center justify-center rounded-full {toneSoft[tone]}">
|
|
68
|
+
{#if icon}
|
|
69
|
+
{@render icon()}
|
|
70
|
+
{:else}
|
|
71
|
+
<svg class="size-5" viewBox="0 0 20 20" fill="none" aria-hidden="true">
|
|
72
|
+
<circle cx="10" cy="10" r="7.5" stroke="currentColor" stroke-width="1.5" />
|
|
73
|
+
<path d="M10 5.75v5" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" />
|
|
74
|
+
<circle cx="10" cy="14" r="1" fill="currentColor" />
|
|
75
|
+
</svg>
|
|
76
|
+
{/if}
|
|
77
|
+
</span>
|
|
78
|
+
<div class="flex min-w-0 flex-1 flex-col gap-1.5">
|
|
79
|
+
<h2 class="font-heading text-base font-semibold text-text">{title}</h2>
|
|
80
|
+
{#if description}
|
|
81
|
+
<p class="text-[13px] leading-relaxed text-text-secondary">{description}</p>
|
|
82
|
+
{/if}
|
|
83
|
+
{#if children}
|
|
84
|
+
{@render children()}
|
|
85
|
+
{/if}
|
|
86
|
+
</div>
|
|
87
|
+
</div>
|
|
88
|
+
|
|
89
|
+
{#snippet footer()}
|
|
90
|
+
<Button variant="outline" tone="neutral" onclick={cancel} disabled={loading}>
|
|
91
|
+
{cancelLabel ?? t.current.cancel}
|
|
92
|
+
</Button>
|
|
93
|
+
<Button {tone} onclick={confirm} {loading}>
|
|
94
|
+
{confirmLabel ?? t.current.confirm}
|
|
95
|
+
</Button>
|
|
96
|
+
{/snippet}
|
|
97
|
+
</Modal>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import { type Tone } from '../../core/tones.js';
|
|
3
|
+
interface Props {
|
|
4
|
+
open?: boolean;
|
|
5
|
+
title: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
/** Drives the confirm button and the glyph. `danger` for destructive acts. */
|
|
8
|
+
tone?: Tone;
|
|
9
|
+
confirmLabel?: string;
|
|
10
|
+
cancelLabel?: string;
|
|
11
|
+
/** Spins the confirm button and blocks dismissal while the action runs. */
|
|
12
|
+
loading?: boolean;
|
|
13
|
+
/** Awaited — the dialog stays open and busy until it settles. */
|
|
14
|
+
onconfirm?: () => void | Promise<void>;
|
|
15
|
+
oncancel?: () => void;
|
|
16
|
+
icon?: Snippet;
|
|
17
|
+
/** Extra content between the description and the buttons. */
|
|
18
|
+
children?: Snippet;
|
|
19
|
+
}
|
|
20
|
+
declare const ConfirmDialog: import("svelte").Component<Props, {}, "open" | "loading">;
|
|
21
|
+
type ConfirmDialog = ReturnType<typeof ConfirmDialog>;
|
|
22
|
+
export default ConfirmDialog;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import { anchored } from '../../core/actions/anchor.js';
|
|
4
|
+
import { clickOutside, focusTrap, navigateList, portal } from '../../core/actions/dismissable.js';
|
|
5
|
+
import { menuItems } from '../../core/trigger.js';
|
|
6
|
+
import { useLocale } from '../../core/locale.svelte.js';
|
|
7
|
+
|
|
8
|
+
interface Props {
|
|
9
|
+
/** The region that responds to a right-click. */
|
|
10
|
+
children: Snippet;
|
|
11
|
+
/** Menu contents: `MenuItem`, `MenuSeparator`, anything. */
|
|
12
|
+
menu: Snippet;
|
|
13
|
+
open?: boolean;
|
|
14
|
+
label?: string;
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
class?: string;
|
|
17
|
+
menuClass?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
let {
|
|
21
|
+
children,
|
|
22
|
+
menu,
|
|
23
|
+
open = $bindable(false),
|
|
24
|
+
label,
|
|
25
|
+
disabled = false,
|
|
26
|
+
class: className = '',
|
|
27
|
+
menuClass = ''
|
|
28
|
+
}: Props = $props();
|
|
29
|
+
|
|
30
|
+
const t = useLocale();
|
|
31
|
+
|
|
32
|
+
let menuEl: HTMLElement | null = $state(null);
|
|
33
|
+
/**
|
|
34
|
+
* A 0×0 element parked at the pointer, so the same `anchored` action that
|
|
35
|
+
* positions dropdowns can flip and clamp this menu too.
|
|
36
|
+
*/
|
|
37
|
+
let cursor: HTMLElement | null = $state(null);
|
|
38
|
+
|
|
39
|
+
function onContextMenu(event: MouseEvent) {
|
|
40
|
+
if (disabled) return;
|
|
41
|
+
event.preventDefault();
|
|
42
|
+
if (!cursor) {
|
|
43
|
+
cursor = document.createElement('div');
|
|
44
|
+
cursor.style.cssText = 'position:fixed;width:0;height:0;pointer-events:none';
|
|
45
|
+
document.body.appendChild(cursor);
|
|
46
|
+
}
|
|
47
|
+
cursor.style.left = `${event.clientX}px`;
|
|
48
|
+
cursor.style.top = `${event.clientY}px`;
|
|
49
|
+
open = true;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
$effect(() => () => cursor?.remove());
|
|
53
|
+
|
|
54
|
+
function onMenuKeydown(event: KeyboardEvent) {
|
|
55
|
+
if (event.key === 'Escape' || event.key === 'Tab') {
|
|
56
|
+
if (event.key === 'Escape') event.preventDefault();
|
|
57
|
+
event.stopPropagation();
|
|
58
|
+
open = false;
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
navigateList(event, menuItems(menuEl));
|
|
62
|
+
}
|
|
63
|
+
</script>
|
|
64
|
+
|
|
65
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
66
|
+
<div oncontextmenu={onContextMenu} class={className}>
|
|
67
|
+
{@render children()}
|
|
68
|
+
</div>
|
|
69
|
+
|
|
70
|
+
{#if open}
|
|
71
|
+
<div
|
|
72
|
+
bind:this={menuEl}
|
|
73
|
+
use:portal
|
|
74
|
+
use:anchored={{ anchor: cursor, placement: 'bottom-start', offset: 2 }}
|
|
75
|
+
use:clickOutside={{ onoutside: () => (open = false) }}
|
|
76
|
+
use:focusTrap={{ restore: true }}
|
|
77
|
+
onkeydown={onMenuKeydown}
|
|
78
|
+
onclick={(event) => {
|
|
79
|
+
if ((event.target as HTMLElement).closest('[role="menuitem"]:not([disabled])')) open = false;
|
|
80
|
+
}}
|
|
81
|
+
role="menu"
|
|
82
|
+
aria-label={label ?? t.current.menu}
|
|
83
|
+
tabindex="-1"
|
|
84
|
+
class="z-50 flex max-h-[min(24rem,80vh)] min-w-48 flex-col overflow-y-auto rounded-lg border border-hairline bg-bg py-1 font-sans shadow-lg {menuClass}"
|
|
85
|
+
>
|
|
86
|
+
{@render menu()}
|
|
87
|
+
</div>
|
|
88
|
+
{/if}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
interface Props {
|
|
3
|
+
/** The region that responds to a right-click. */
|
|
4
|
+
children: Snippet;
|
|
5
|
+
/** Menu contents: `MenuItem`, `MenuSeparator`, anything. */
|
|
6
|
+
menu: Snippet;
|
|
7
|
+
open?: boolean;
|
|
8
|
+
label?: string;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
class?: string;
|
|
11
|
+
menuClass?: string;
|
|
12
|
+
}
|
|
13
|
+
declare const ContextMenu: import("svelte").Component<Props, {}, "open">;
|
|
14
|
+
type ContextMenu = ReturnType<typeof ContextMenu>;
|
|
15
|
+
export default ContextMenu;
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { anchored } from '../../core/actions/anchor.js';
|
|
3
|
+
import { clickOutside, portal } from '../../core/actions/dismissable.js';
|
|
4
|
+
import { dateHint } from '../../core/calendar.js';
|
|
5
|
+
import { formatISO, parseFormatted } from '../../core/date.js';
|
|
6
|
+
import { useLocale } from '../../core/locale.svelte.js';
|
|
7
|
+
import { toneFocusWithinBorder, type Tone } from '../../core/tones.js';
|
|
8
|
+
import Calendar from './Calendar.svelte';
|
|
9
|
+
|
|
10
|
+
interface Props {
|
|
11
|
+
/** Bindable `YYYY-MM-DD` — the same shape as `<input type="date">`. */
|
|
12
|
+
value?: string;
|
|
13
|
+
/** Inclusive bounds, `YYYY-MM-DD`. */
|
|
14
|
+
min?: string;
|
|
15
|
+
max?: string;
|
|
16
|
+
isDisabled?: (date: Date) => boolean;
|
|
17
|
+
weekStart?: 0 | 1;
|
|
18
|
+
tone?: Tone;
|
|
19
|
+
invalid?: boolean;
|
|
20
|
+
disabled?: boolean;
|
|
21
|
+
clearable?: boolean;
|
|
22
|
+
placeholder?: string;
|
|
23
|
+
id?: string;
|
|
24
|
+
/** Submits the ISO value with a form. */
|
|
25
|
+
name?: string;
|
|
26
|
+
onchange?: (value: string) => void;
|
|
27
|
+
class?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
let {
|
|
31
|
+
value = $bindable(''),
|
|
32
|
+
min,
|
|
33
|
+
max,
|
|
34
|
+
isDisabled,
|
|
35
|
+
weekStart = 1,
|
|
36
|
+
tone = 'brand',
|
|
37
|
+
invalid = false,
|
|
38
|
+
disabled = false,
|
|
39
|
+
clearable = true,
|
|
40
|
+
placeholder,
|
|
41
|
+
id,
|
|
42
|
+
name,
|
|
43
|
+
onchange,
|
|
44
|
+
class: className = ''
|
|
45
|
+
}: Props = $props();
|
|
46
|
+
|
|
47
|
+
const t = useLocale();
|
|
48
|
+
|
|
49
|
+
let open = $state(false);
|
|
50
|
+
let text = $state('');
|
|
51
|
+
let editing = $state(false);
|
|
52
|
+
let wrapper: HTMLElement | null = $state(null);
|
|
53
|
+
let inputEl: HTMLInputElement | null = $state(null);
|
|
54
|
+
|
|
55
|
+
/** While typing the field shows the raw text; otherwise the formatted value. */
|
|
56
|
+
const display = $derived(editing ? text : formatISO(value, t.current.dateFormat));
|
|
57
|
+
const hint = $derived(placeholder ?? dateHint(t.current.dateFormat));
|
|
58
|
+
|
|
59
|
+
function commit() {
|
|
60
|
+
editing = false;
|
|
61
|
+
if (!text.trim()) {
|
|
62
|
+
if (value) {
|
|
63
|
+
value = '';
|
|
64
|
+
onchange?.('');
|
|
65
|
+
}
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const parsed = parseFormatted(text, t.current.dateFormat);
|
|
69
|
+
if (parsed && parsed !== value) {
|
|
70
|
+
value = parsed;
|
|
71
|
+
onchange?.(parsed);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function onKeydown(event: KeyboardEvent) {
|
|
76
|
+
if (event.key === 'Escape' && open) {
|
|
77
|
+
event.preventDefault();
|
|
78
|
+
event.stopPropagation();
|
|
79
|
+
open = false;
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (event.key === 'Enter') {
|
|
83
|
+
event.preventDefault();
|
|
84
|
+
commit();
|
|
85
|
+
open = false;
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (event.key === 'ArrowDown' && !open) {
|
|
89
|
+
event.preventDefault();
|
|
90
|
+
open = true;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
</script>
|
|
94
|
+
|
|
95
|
+
<div
|
|
96
|
+
bind:this={wrapper}
|
|
97
|
+
class="inline-flex w-full items-center gap-1 rounded-md border bg-bg pr-1 pl-3 shadow-xs transition-colors duration-150 ease-brand-out
|
|
98
|
+
{invalid ? 'border-danger' : `border-hairline-strong ${toneFocusWithinBorder[tone]}`}
|
|
99
|
+
{disabled ? 'pointer-events-none opacity-50' : ''} {className}"
|
|
100
|
+
>
|
|
101
|
+
<input
|
|
102
|
+
bind:this={inputEl}
|
|
103
|
+
{id}
|
|
104
|
+
{disabled}
|
|
105
|
+
type="text"
|
|
106
|
+
inputmode="numeric"
|
|
107
|
+
autocomplete="off"
|
|
108
|
+
role="combobox"
|
|
109
|
+
aria-haspopup="dialog"
|
|
110
|
+
aria-controls="{id ?? 'datepicker'}-calendar"
|
|
111
|
+
aria-invalid={invalid ? 'true' : undefined}
|
|
112
|
+
aria-expanded={open}
|
|
113
|
+
placeholder={hint}
|
|
114
|
+
value={display}
|
|
115
|
+
oninput={(event) => {
|
|
116
|
+
editing = true;
|
|
117
|
+
text = event.currentTarget.value;
|
|
118
|
+
}}
|
|
119
|
+
onblur={commit}
|
|
120
|
+
onkeydown={onKeydown}
|
|
121
|
+
class="h-10 w-full min-w-0 bg-transparent font-sans text-sm text-text tabular-nums placeholder:text-text-muted focus:outline-none"
|
|
122
|
+
/>
|
|
123
|
+
|
|
124
|
+
{#if name}<input type="hidden" {name} {value} />{/if}
|
|
125
|
+
|
|
126
|
+
{#if clearable && value && !disabled}
|
|
127
|
+
<button
|
|
128
|
+
type="button"
|
|
129
|
+
onclick={() => {
|
|
130
|
+
value = '';
|
|
131
|
+
text = '';
|
|
132
|
+
onchange?.('');
|
|
133
|
+
inputEl?.focus();
|
|
134
|
+
}}
|
|
135
|
+
aria-label={t.current.clear}
|
|
136
|
+
class="shrink-0 rounded p-1 text-text-muted transition-colors duration-150 hover:bg-bg-inset hover:text-text focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-current"
|
|
137
|
+
>
|
|
138
|
+
<svg class="size-3.5" viewBox="0 0 14 14" fill="none" aria-hidden="true">
|
|
139
|
+
<path
|
|
140
|
+
d="m2 2 10 10M12 2 2 12"
|
|
141
|
+
stroke="currentColor"
|
|
142
|
+
stroke-width="1.6"
|
|
143
|
+
stroke-linecap="round"
|
|
144
|
+
/>
|
|
145
|
+
</svg>
|
|
146
|
+
</button>
|
|
147
|
+
{/if}
|
|
148
|
+
|
|
149
|
+
<button
|
|
150
|
+
type="button"
|
|
151
|
+
{disabled}
|
|
152
|
+
onclick={() => (open = !open)}
|
|
153
|
+
aria-label={t.current.selectDate}
|
|
154
|
+
aria-expanded={open}
|
|
155
|
+
class="shrink-0 rounded p-1.5 text-text-muted transition-colors duration-150 hover:bg-bg-inset hover:text-text focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-current"
|
|
156
|
+
>
|
|
157
|
+
<svg class="size-4" viewBox="0 0 20 20" fill="none" aria-hidden="true">
|
|
158
|
+
<rect x="3" y="4.5" width="14" height="12" rx="2" stroke="currentColor" stroke-width="1.4" />
|
|
159
|
+
<path
|
|
160
|
+
d="M3 8.5h14M7 3v3M13 3v3"
|
|
161
|
+
stroke="currentColor"
|
|
162
|
+
stroke-width="1.4"
|
|
163
|
+
stroke-linecap="round"
|
|
164
|
+
/>
|
|
165
|
+
</svg>
|
|
166
|
+
</button>
|
|
167
|
+
</div>
|
|
168
|
+
|
|
169
|
+
{#if open}
|
|
170
|
+
<div
|
|
171
|
+
use:portal
|
|
172
|
+
use:anchored={{ anchor: wrapper, placement: 'bottom-start', offset: 4 }}
|
|
173
|
+
use:clickOutside={{ onoutside: () => (open = false), ignore: [wrapper] }}
|
|
174
|
+
id="{id ?? 'datepicker'}-calendar"
|
|
175
|
+
class="z-50 rounded-lg border border-hairline bg-bg shadow-lg"
|
|
176
|
+
>
|
|
177
|
+
<Calendar
|
|
178
|
+
bind:value
|
|
179
|
+
{min}
|
|
180
|
+
{max}
|
|
181
|
+
{isDisabled}
|
|
182
|
+
{weekStart}
|
|
183
|
+
{tone}
|
|
184
|
+
onselect={(next) => {
|
|
185
|
+
editing = false;
|
|
186
|
+
open = false;
|
|
187
|
+
onchange?.(next);
|
|
188
|
+
inputEl?.focus();
|
|
189
|
+
}}
|
|
190
|
+
/>
|
|
191
|
+
</div>
|
|
192
|
+
{/if}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type Tone } from '../../core/tones.js';
|
|
2
|
+
interface Props {
|
|
3
|
+
/** Bindable `YYYY-MM-DD` — the same shape as `<input type="date">`. */
|
|
4
|
+
value?: string;
|
|
5
|
+
/** Inclusive bounds, `YYYY-MM-DD`. */
|
|
6
|
+
min?: string;
|
|
7
|
+
max?: string;
|
|
8
|
+
isDisabled?: (date: Date) => boolean;
|
|
9
|
+
weekStart?: 0 | 1;
|
|
10
|
+
tone?: Tone;
|
|
11
|
+
invalid?: boolean;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
clearable?: boolean;
|
|
14
|
+
placeholder?: string;
|
|
15
|
+
id?: string;
|
|
16
|
+
/** Submits the ISO value with a form. */
|
|
17
|
+
name?: string;
|
|
18
|
+
onchange?: (value: string) => void;
|
|
19
|
+
class?: string;
|
|
20
|
+
}
|
|
21
|
+
declare const DatePicker: import("svelte").Component<Props, {}, "value">;
|
|
22
|
+
type DatePicker = ReturnType<typeof DatePicker>;
|
|
23
|
+
export default DatePicker;
|