kosui 0.0.7
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/LICENSE +7 -0
- package/README.md +3 -0
- package/dist/alert/alert.svelte +28 -0
- package/dist/alert/alert.svelte.d.ts +5 -0
- package/dist/alert/index.d.ts +1 -0
- package/dist/alert/index.js +1 -0
- package/dist/autocomplete/autocomplete-content.svelte +47 -0
- package/dist/autocomplete/autocomplete-content.svelte.d.ts +10 -0
- package/dist/autocomplete/autocomplete-context.svelte.d.ts +12 -0
- package/dist/autocomplete/autocomplete-context.svelte.js +34 -0
- package/dist/autocomplete/autocomplete-input.svelte +43 -0
- package/dist/autocomplete/autocomplete-input.svelte.d.ts +7 -0
- package/dist/autocomplete/autocomplete-item.svelte +68 -0
- package/dist/autocomplete/autocomplete-item.svelte.d.ts +11 -0
- package/dist/autocomplete/autocomplete.svelte +20 -0
- package/dist/autocomplete/autocomplete.svelte.d.ts +8 -0
- package/dist/autocomplete/index.d.ts +4 -0
- package/dist/autocomplete/index.js +4 -0
- package/dist/avatar/avatar.svelte +47 -0
- package/dist/avatar/avatar.svelte.d.ts +8 -0
- package/dist/avatar/index.d.ts +1 -0
- package/dist/avatar/index.js +1 -0
- package/dist/badge/badge.svelte +43 -0
- package/dist/badge/badge.svelte.d.ts +9 -0
- package/dist/badge/index.d.ts +1 -0
- package/dist/badge/index.js +1 -0
- package/dist/base.d.ts +21 -0
- package/dist/base.js +70 -0
- package/dist/bindable.svelte.d.ts +7 -0
- package/dist/bindable.svelte.js +25 -0
- package/dist/box/box.svelte +42 -0
- package/dist/box/box.svelte.d.ts +12 -0
- package/dist/box/index.d.ts +1 -0
- package/dist/box/index.js +1 -0
- package/dist/breadcrumbs/breadcrumbs.svelte +39 -0
- package/dist/breadcrumbs/breadcrumbs.svelte.d.ts +13 -0
- package/dist/breadcrumbs/index.d.ts +1 -0
- package/dist/breadcrumbs/index.js +1 -0
- package/dist/button/button.svelte +70 -0
- package/dist/button/button.svelte.d.ts +13 -0
- package/dist/button/index.d.ts +1 -0
- package/dist/button/index.js +1 -0
- package/dist/chip/chip.svelte +57 -0
- package/dist/chip/chip.svelte.d.ts +11 -0
- package/dist/chip/index.d.ts +1 -0
- package/dist/chip/index.js +1 -0
- package/dist/command/action.svelte.d.ts +35 -0
- package/dist/command/action.svelte.js +76 -0
- package/dist/command/command-content.svelte +15 -0
- package/dist/command/command-content.svelte.d.ts +8 -0
- package/dist/command/command-context.svelte.d.ts +5 -0
- package/dist/command/command-context.svelte.js +13 -0
- package/dist/command/command-input.svelte +44 -0
- package/dist/command/command-input.svelte.d.ts +7 -0
- package/dist/command/command-item.svelte +66 -0
- package/dist/command/command-item.svelte.d.ts +11 -0
- package/dist/command/command-search.svelte +29 -0
- package/dist/command/command-search.svelte.d.ts +5 -0
- package/dist/command/command.svelte +19 -0
- package/dist/command/command.svelte.d.ts +8 -0
- package/dist/command/commander.svelte +107 -0
- package/dist/command/commander.svelte.d.ts +9 -0
- package/dist/command/index.d.ts +8 -0
- package/dist/command/index.js +8 -0
- package/dist/common/divider.svelte +13 -0
- package/dist/common/divider.svelte.d.ts +6 -0
- package/dist/common/header.svelte +35 -0
- package/dist/common/header.svelte.d.ts +10 -0
- package/dist/common/index.d.ts +3 -0
- package/dist/common/index.js +3 -0
- package/dist/common/item-context.svelte.d.ts +12 -0
- package/dist/common/item-context.svelte.js +77 -0
- package/dist/dialog/dialog-button.svelte +25 -0
- package/dist/dialog/dialog-button.svelte.d.ts +32 -0
- package/dist/dialog/dialog.svelte +69 -0
- package/dist/dialog/dialog.svelte.d.ts +37 -0
- package/dist/dialog/dialoguer-context.svelte.d.ts +53 -0
- package/dist/dialog/dialoguer-context.svelte.js +85 -0
- package/dist/dialog/dialoguer.svelte +65 -0
- package/dist/dialog/dialoguer.svelte.d.ts +7 -0
- package/dist/dialog/index.d.ts +4 -0
- package/dist/dialog/index.js +4 -0
- package/dist/event-manager.d.ts +15 -0
- package/dist/event-manager.js +47 -0
- package/dist/fab/fab.svelte +28 -0
- package/dist/fab/fab.svelte.d.ts +6 -0
- package/dist/fab/index.d.ts +1 -0
- package/dist/fab/index.js +1 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.js +39 -0
- package/dist/input/index.d.ts +1 -0
- package/dist/input/index.js +1 -0
- package/dist/input/input.svelte +41 -0
- package/dist/input/input.svelte.d.ts +7 -0
- package/dist/link/index.d.ts +1 -0
- package/dist/link/index.js +1 -0
- package/dist/link/link.svelte +51 -0
- package/dist/link/link.svelte.d.ts +10 -0
- package/dist/markdown/index.d.ts +25 -0
- package/dist/markdown/index.js +25 -0
- package/dist/markdown/markdown-blockquote.svelte +14 -0
- package/dist/markdown/markdown-blockquote.svelte.d.ts +7 -0
- package/dist/markdown/markdown-br.svelte +12 -0
- package/dist/markdown/markdown-br.svelte.d.ts +7 -0
- package/dist/markdown/markdown-code.svelte +14 -0
- package/dist/markdown/markdown-code.svelte.d.ts +7 -0
- package/dist/markdown/markdown-codespan.svelte +15 -0
- package/dist/markdown/markdown-codespan.svelte.d.ts +7 -0
- package/dist/markdown/markdown-context.svelte.d.ts +26 -0
- package/dist/markdown/markdown-context.svelte.js +30 -0
- package/dist/markdown/markdown-def.svelte +15 -0
- package/dist/markdown/markdown-def.svelte.d.ts +7 -0
- package/dist/markdown/markdown-del.svelte +14 -0
- package/dist/markdown/markdown-del.svelte.d.ts +7 -0
- package/dist/markdown/markdown-em.svelte +14 -0
- package/dist/markdown/markdown-em.svelte.d.ts +7 -0
- package/dist/markdown/markdown-escape.svelte +8 -0
- package/dist/markdown/markdown-escape.svelte.d.ts +5 -0
- package/dist/markdown/markdown-heading.svelte +16 -0
- package/dist/markdown/markdown-heading.svelte.d.ts +7 -0
- package/dist/markdown/markdown-hr.svelte +12 -0
- package/dist/markdown/markdown-hr.svelte.d.ts +7 -0
- package/dist/markdown/markdown-html.svelte +9 -0
- package/dist/markdown/markdown-html.svelte.d.ts +5 -0
- package/dist/markdown/markdown-image.svelte +12 -0
- package/dist/markdown/markdown-image.svelte.d.ts +7 -0
- package/dist/markdown/markdown-link.svelte +15 -0
- package/dist/markdown/markdown-link.svelte.d.ts +7 -0
- package/dist/markdown/markdown-list-item.svelte +14 -0
- package/dist/markdown/markdown-list-item.svelte.d.ts +7 -0
- package/dist/markdown/markdown-list.svelte +19 -0
- package/dist/markdown/markdown-list.svelte.d.ts +7 -0
- package/dist/markdown/markdown-paragraph.svelte +16 -0
- package/dist/markdown/markdown-paragraph.svelte.d.ts +7 -0
- package/dist/markdown/markdown-space.svelte +8 -0
- package/dist/markdown/markdown-space.svelte.d.ts +5 -0
- package/dist/markdown/markdown-strong.svelte +15 -0
- package/dist/markdown/markdown-strong.svelte.d.ts +7 -0
- package/dist/markdown/markdown-table-cell.svelte +16 -0
- package/dist/markdown/markdown-table-cell.svelte.d.ts +7 -0
- package/dist/markdown/markdown-table.svelte +34 -0
- package/dist/markdown/markdown-table.svelte.d.ts +7 -0
- package/dist/markdown/markdown-text.svelte +8 -0
- package/dist/markdown/markdown-text.svelte.d.ts +5 -0
- package/dist/markdown/markdown-token.svelte +25 -0
- package/dist/markdown/markdown-token.svelte.d.ts +7 -0
- package/dist/markdown/markdown-tokens.svelte +13 -0
- package/dist/markdown/markdown-tokens.svelte.d.ts +7 -0
- package/dist/markdown/markdown.svelte +186 -0
- package/dist/markdown/markdown.svelte.d.ts +31 -0
- package/dist/menu/index.d.ts +7 -0
- package/dist/menu/index.js +7 -0
- package/dist/menu/menu-actions.svelte +51 -0
- package/dist/menu/menu-actions.svelte.d.ts +7 -0
- package/dist/menu/menu-content.svelte +47 -0
- package/dist/menu/menu-content.svelte.d.ts +10 -0
- package/dist/menu/menu-context.svelte.d.ts +18 -0
- package/dist/menu/menu-context.svelte.js +118 -0
- package/dist/menu/menu-item.svelte +85 -0
- package/dist/menu/menu-item.svelte.d.ts +11 -0
- package/dist/menu/menu-trigger-button.svelte +31 -0
- package/dist/menu/menu-trigger-button.svelte.d.ts +5 -0
- package/dist/menu/menu-trigger.svelte +42 -0
- package/dist/menu/menu-trigger.svelte.d.ts +10 -0
- package/dist/menu/menu.svelte +29 -0
- package/dist/menu/menu.svelte.d.ts +9 -0
- package/dist/merge-props.d.ts +13 -0
- package/dist/merge-props.js +84 -0
- package/dist/modal/index.d.ts +1 -0
- package/dist/modal/index.js +1 -0
- package/dist/modal/modal.svelte +123 -0
- package/dist/modal/modal.svelte.d.ts +11 -0
- package/dist/ordered-html-elements.d.ts +7 -0
- package/dist/ordered-html-elements.js +29 -0
- package/dist/popover/index.d.ts +1 -0
- package/dist/popover/index.js +1 -0
- package/dist/popover/popover.svelte +184 -0
- package/dist/popover/popover.svelte.d.ts +18 -0
- package/dist/portal/index.d.ts +1 -0
- package/dist/portal/index.js +1 -0
- package/dist/portal/portal.svelte +12 -0
- package/dist/portal/portal.svelte.d.ts +8 -0
- package/dist/portal/proxy.svelte +10 -0
- package/dist/portal/proxy.svelte.d.ts +7 -0
- package/dist/progress/circular-progress.svelte +86 -0
- package/dist/progress/circular-progress.svelte.d.ts +13 -0
- package/dist/progress/index.d.ts +1 -0
- package/dist/progress/index.js +1 -0
- package/dist/shortcut/index.d.ts +2 -0
- package/dist/shortcut/index.js +2 -0
- package/dist/shortcut/shortcut-badge.svelte +41 -0
- package/dist/shortcut/shortcut-badge.svelte.d.ts +11 -0
- package/dist/shortcut/shortcut.d.ts +29 -0
- package/dist/shortcut/shortcut.js +95 -0
- package/dist/toggle/index.d.ts +2 -0
- package/dist/toggle/index.js +2 -0
- package/dist/toggle/toggle-button.svelte +60 -0
- package/dist/toggle/toggle-button.svelte.d.ts +32 -0
- package/dist/toggle/toggle-context.svelte.d.ts +9 -0
- package/dist/toggle/toggle-context.svelte.js +32 -0
- package/dist/toggle/toggle-group.svelte +41 -0
- package/dist/toggle/toggle-group.svelte.d.ts +32 -0
- package/dist/tooltip/index.d.ts +1 -0
- package/dist/tooltip/index.js +1 -0
- package/dist/tooltip/tooltip.svelte +94 -0
- package/dist/tooltip/tooltip.svelte.d.ts +25 -0
- package/dist/utils.d.ts +43 -0
- package/dist/utils.js +72 -0
- package/package.json +76 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import { Link, type LinkProps } from "..";
|
|
3
|
+
import type { Snippet } from "svelte";
|
|
4
|
+
import { twMerge } from "tailwind-merge";
|
|
5
|
+
|
|
6
|
+
type Crumb = {
|
|
7
|
+
title: string;
|
|
8
|
+
href: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type BreadcrumbsProps = {
|
|
12
|
+
path: Crumb[];
|
|
13
|
+
separator?: Snippet | string;
|
|
14
|
+
} & Omit<LinkProps, "children">;
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<script lang="ts">
|
|
18
|
+
const {
|
|
19
|
+
path,
|
|
20
|
+
separator = "›",
|
|
21
|
+
class: className,
|
|
22
|
+
...restProps
|
|
23
|
+
}: BreadcrumbsProps = $props();
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<div class={twMerge("flex gap-2", className)}>
|
|
27
|
+
{#each path as { title, href }, index (title)}
|
|
28
|
+
{#if index !== 0}
|
|
29
|
+
<div>
|
|
30
|
+
{#if typeof separator === "function"}
|
|
31
|
+
{@render separator()}
|
|
32
|
+
{:else}
|
|
33
|
+
{separator}
|
|
34
|
+
{/if}
|
|
35
|
+
</div>
|
|
36
|
+
{/if}
|
|
37
|
+
<Link {href} {...restProps}>{title}</Link>
|
|
38
|
+
{/each}
|
|
39
|
+
</div>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type LinkProps } from "..";
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
type Crumb = {
|
|
4
|
+
title: string;
|
|
5
|
+
href: string;
|
|
6
|
+
};
|
|
7
|
+
export type BreadcrumbsProps = {
|
|
8
|
+
path: Crumb[];
|
|
9
|
+
separator?: Snippet | string;
|
|
10
|
+
} & Omit<LinkProps, "children">;
|
|
11
|
+
declare const Breadcrumbs: import("svelte").Component<BreadcrumbsProps, {}, "">;
|
|
12
|
+
type Breadcrumbs = ReturnType<typeof Breadcrumbs>;
|
|
13
|
+
export default Breadcrumbs;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as Breadcrumbs } from "./breadcrumbs.svelte";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as Breadcrumbs } from "./breadcrumbs.svelte";
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { Icon } from "@lucide/svelte";
|
|
3
|
+
import type { Snippet } from "svelte";
|
|
4
|
+
import type { HTMLButtonAttributes } from "svelte/elements";
|
|
5
|
+
import { twMerge } from "tailwind-merge";
|
|
6
|
+
import { baseClasses, type Variants } from "../base";
|
|
7
|
+
import { mergeProps } from "../merge-props";
|
|
8
|
+
import { Tooltip, type TooltipTriggerProps } from "../tooltip";
|
|
9
|
+
import { noop, type ClassName, type ElementRef } from "../utils";
|
|
10
|
+
|
|
11
|
+
export type ButtonProps = {
|
|
12
|
+
icon?: typeof Icon;
|
|
13
|
+
size?: number;
|
|
14
|
+
tooltip?: Snippet | string;
|
|
15
|
+
} & ElementRef &
|
|
16
|
+
ClassName &
|
|
17
|
+
Variants &
|
|
18
|
+
HTMLButtonAttributes;
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<script lang="ts">
|
|
22
|
+
let {
|
|
23
|
+
icon: IconComponent,
|
|
24
|
+
size = 16,
|
|
25
|
+
tooltip,
|
|
26
|
+
children,
|
|
27
|
+
el = $bindable(),
|
|
28
|
+
ref = noop,
|
|
29
|
+
class: className,
|
|
30
|
+
variant = "outlined",
|
|
31
|
+
color = "primary",
|
|
32
|
+
shape = "rounded",
|
|
33
|
+
...restProps
|
|
34
|
+
}: ButtonProps = $props();
|
|
35
|
+
</script>
|
|
36
|
+
|
|
37
|
+
{#snippet button({ ref: anchorRef, ...triggerProps }: TooltipTriggerProps)}
|
|
38
|
+
<button
|
|
39
|
+
bind:this={el}
|
|
40
|
+
use:ref
|
|
41
|
+
use:anchorRef
|
|
42
|
+
class={twMerge(
|
|
43
|
+
baseClasses({ variant, color, shape, hover: true, focus: true }),
|
|
44
|
+
"flex items-center justify-center gap-2 text-sm text-nowrap transition-all select-none enabled:active:scale-95",
|
|
45
|
+
children ? "px-4 py-2" : "p-2",
|
|
46
|
+
className,
|
|
47
|
+
)}
|
|
48
|
+
{...mergeProps(restProps, triggerProps)}
|
|
49
|
+
>
|
|
50
|
+
{#if IconComponent}
|
|
51
|
+
<IconComponent {size} />
|
|
52
|
+
{/if}
|
|
53
|
+
{@render children?.()}
|
|
54
|
+
</button>
|
|
55
|
+
{/snippet}
|
|
56
|
+
|
|
57
|
+
{#if tooltip}
|
|
58
|
+
<Tooltip arrow>
|
|
59
|
+
{#snippet trigger(props)}
|
|
60
|
+
{@render button(props)}
|
|
61
|
+
{/snippet}
|
|
62
|
+
{#if typeof tooltip === "function"}
|
|
63
|
+
{@render tooltip()}
|
|
64
|
+
{:else}
|
|
65
|
+
{tooltip}
|
|
66
|
+
{/if}
|
|
67
|
+
</Tooltip>
|
|
68
|
+
{:else}
|
|
69
|
+
{@render button({ ref: noop })}
|
|
70
|
+
{/if}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Icon } from "@lucide/svelte";
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
import type { HTMLButtonAttributes } from "svelte/elements";
|
|
4
|
+
import { type Variants } from "../base";
|
|
5
|
+
import { type ClassName, type ElementRef } from "../utils";
|
|
6
|
+
export type ButtonProps = {
|
|
7
|
+
icon?: typeof Icon;
|
|
8
|
+
size?: number;
|
|
9
|
+
tooltip?: Snippet | string;
|
|
10
|
+
} & ElementRef & ClassName & Variants & HTMLButtonAttributes;
|
|
11
|
+
declare const Button: import("svelte").Component<ButtonProps, {}, "el">;
|
|
12
|
+
type Button = ReturnType<typeof Button>;
|
|
13
|
+
export default Button;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as Button, type ButtonProps } from "./button.svelte";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as Button } from "./button.svelte";
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import { X } from "@lucide/svelte";
|
|
3
|
+
import type { Snippet } from "svelte";
|
|
4
|
+
import { twMerge } from "tailwind-merge";
|
|
5
|
+
|
|
6
|
+
export type ChipProps = {
|
|
7
|
+
title?: string;
|
|
8
|
+
onClick?: (event: MouseEvent | KeyboardEvent) => void;
|
|
9
|
+
onDelete?: (event: MouseEvent | KeyboardEvent) => void;
|
|
10
|
+
children: Snippet;
|
|
11
|
+
} & BoxProps;
|
|
12
|
+
</script>
|
|
13
|
+
|
|
14
|
+
<script lang="ts">
|
|
15
|
+
import { Box, type BoxProps } from "../box";
|
|
16
|
+
|
|
17
|
+
let {
|
|
18
|
+
title,
|
|
19
|
+
onClick,
|
|
20
|
+
onDelete,
|
|
21
|
+
children,
|
|
22
|
+
el = $bindable(),
|
|
23
|
+
class: className,
|
|
24
|
+
variant = "filled",
|
|
25
|
+
color = "primary",
|
|
26
|
+
shape = "rounded",
|
|
27
|
+
...restProps
|
|
28
|
+
}: ChipProps = $props();
|
|
29
|
+
</script>
|
|
30
|
+
|
|
31
|
+
<Box
|
|
32
|
+
bind:el
|
|
33
|
+
role="option"
|
|
34
|
+
{variant}
|
|
35
|
+
{color}
|
|
36
|
+
{shape}
|
|
37
|
+
class={twMerge("inline-flex gap-1 px-1 py-0 text-xs", className)}
|
|
38
|
+
{...restProps}
|
|
39
|
+
>
|
|
40
|
+
<button onclick={onClick} {title}>
|
|
41
|
+
{@render children()}
|
|
42
|
+
</button>
|
|
43
|
+
|
|
44
|
+
{#if onDelete}
|
|
45
|
+
<button
|
|
46
|
+
aria-label="Delete chip"
|
|
47
|
+
class={twMerge(
|
|
48
|
+
"transition-all hover:ring-1 active:scale-95",
|
|
49
|
+
shape === "rounded" && "rounded",
|
|
50
|
+
shape === "circle" && "rounded-full",
|
|
51
|
+
)}
|
|
52
|
+
onclick={onDelete}
|
|
53
|
+
>
|
|
54
|
+
<X size={12} />
|
|
55
|
+
</button>
|
|
56
|
+
{/if}
|
|
57
|
+
</Box>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Snippet } from "svelte";
|
|
2
|
+
export type ChipProps = {
|
|
3
|
+
title?: string;
|
|
4
|
+
onClick?: (event: MouseEvent | KeyboardEvent) => void;
|
|
5
|
+
onDelete?: (event: MouseEvent | KeyboardEvent) => void;
|
|
6
|
+
children: Snippet;
|
|
7
|
+
} & BoxProps;
|
|
8
|
+
import { type BoxProps } from "../box";
|
|
9
|
+
declare const Chip: import("svelte").Component<ChipProps, {}, "el">;
|
|
10
|
+
type Chip = ReturnType<typeof Chip>;
|
|
11
|
+
export default Chip;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as Chip, type ChipProps } from "./chip.svelte";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as Chip } from "./chip.svelte";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type Icon } from "@lucide/svelte";
|
|
2
|
+
import type { Shortcut } from "../shortcut";
|
|
3
|
+
type ActionProps = {
|
|
4
|
+
id: string;
|
|
5
|
+
callback: () => void;
|
|
6
|
+
category?: string;
|
|
7
|
+
name?: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
icon?: typeof Icon;
|
|
10
|
+
enabled?: () => boolean;
|
|
11
|
+
selected?: () => boolean;
|
|
12
|
+
shortcut?: Shortcut;
|
|
13
|
+
};
|
|
14
|
+
export declare class Action {
|
|
15
|
+
id: string;
|
|
16
|
+
callback: () => void;
|
|
17
|
+
category: string;
|
|
18
|
+
name: string;
|
|
19
|
+
description: string;
|
|
20
|
+
icon: typeof Icon;
|
|
21
|
+
enabled: () => boolean;
|
|
22
|
+
selected?: () => boolean;
|
|
23
|
+
shortcut?: Shortcut;
|
|
24
|
+
constructor({ id, callback, category, name, description, icon, enabled, selected, shortcut, }: ActionProps);
|
|
25
|
+
}
|
|
26
|
+
export declare class Registry {
|
|
27
|
+
#private;
|
|
28
|
+
get actions(): Action[];
|
|
29
|
+
get(id: string): Action | undefined;
|
|
30
|
+
getByShortcut(shortcut: Shortcut): Action | undefined;
|
|
31
|
+
call(id: string): void;
|
|
32
|
+
register(...actions: Action[]): () => void;
|
|
33
|
+
unregister(...actions: Action[]): void;
|
|
34
|
+
}
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { CircleSlash } from "@lucide/svelte";
|
|
2
|
+
import { untrack } from "svelte";
|
|
3
|
+
export class Action {
|
|
4
|
+
id;
|
|
5
|
+
callback;
|
|
6
|
+
category;
|
|
7
|
+
name;
|
|
8
|
+
description;
|
|
9
|
+
icon;
|
|
10
|
+
enabled;
|
|
11
|
+
selected;
|
|
12
|
+
shortcut;
|
|
13
|
+
constructor({ id, callback, category, name, description, icon = CircleSlash, enabled = () => true, selected, shortcut, }) {
|
|
14
|
+
this.id = id;
|
|
15
|
+
this.callback = callback;
|
|
16
|
+
this.category = category ?? "";
|
|
17
|
+
this.name = name ?? id;
|
|
18
|
+
this.description = description ?? name ?? id;
|
|
19
|
+
this.icon = icon;
|
|
20
|
+
this.enabled = enabled;
|
|
21
|
+
this.selected = selected;
|
|
22
|
+
this.shortcut = shortcut;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export class Registry {
|
|
26
|
+
#actions = $state([]);
|
|
27
|
+
#shortcuts = {};
|
|
28
|
+
get actions() {
|
|
29
|
+
return this.#actions;
|
|
30
|
+
}
|
|
31
|
+
get(id) {
|
|
32
|
+
for (const action of this.#actions) {
|
|
33
|
+
if (action.id === id) {
|
|
34
|
+
return action;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
getByShortcut(shortcut) {
|
|
39
|
+
return this.#shortcuts[shortcut.toString()];
|
|
40
|
+
}
|
|
41
|
+
call(id) {
|
|
42
|
+
const action = this.get(id);
|
|
43
|
+
if (!action) {
|
|
44
|
+
throw new Error(`No action named "${id}" is registered`);
|
|
45
|
+
}
|
|
46
|
+
action.callback();
|
|
47
|
+
}
|
|
48
|
+
register(...actions) {
|
|
49
|
+
for (const action of actions) {
|
|
50
|
+
untrack(() => {
|
|
51
|
+
if (this.#actions.find((existing) => existing.id === action.id)) {
|
|
52
|
+
throw new Error(`${action.id} is already registered`);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
if (action.shortcut) {
|
|
56
|
+
if (action.shortcut.toString() in this.#shortcuts) {
|
|
57
|
+
throw new Error(`${action.shortcut} is already registered`);
|
|
58
|
+
}
|
|
59
|
+
this.#shortcuts[action.shortcut.toString()] = action;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
this.#actions.unshift(...actions);
|
|
63
|
+
return () => this.unregister(...actions);
|
|
64
|
+
}
|
|
65
|
+
unregister(...actions) {
|
|
66
|
+
for (const action of actions) {
|
|
67
|
+
const index = this.#actions.indexOf(action);
|
|
68
|
+
if (index !== -1) {
|
|
69
|
+
this.#actions.splice(index, 1);
|
|
70
|
+
if (action.shortcut) {
|
|
71
|
+
delete this.#shortcuts[action.shortcut.toString()];
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
import { twMerge } from "tailwind-merge";
|
|
4
|
+
import type { ClassName } from "../utils";
|
|
5
|
+
|
|
6
|
+
export type CommandContentProps = { children: Snippet } & ClassName;
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<script lang="ts">
|
|
10
|
+
let { class: className, children }: CommandContentProps = $props();
|
|
11
|
+
</script>
|
|
12
|
+
|
|
13
|
+
<div class={twMerge("h-full overflow-scroll", className)}>
|
|
14
|
+
{@render children()}
|
|
15
|
+
</div>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Snippet } from "svelte";
|
|
2
|
+
import type { ClassName } from "../utils";
|
|
3
|
+
export type CommandContentProps = {
|
|
4
|
+
children: Snippet;
|
|
5
|
+
} & ClassName;
|
|
6
|
+
declare const CommandContent: import("svelte").Component<CommandContentProps, {}, "">;
|
|
7
|
+
type CommandContent = ReturnType<typeof CommandContent>;
|
|
8
|
+
export default CommandContent;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { getContext, setContext } from "svelte";
|
|
2
|
+
import { ItemContext } from "../common";
|
|
3
|
+
export class CommandContext extends ItemContext {
|
|
4
|
+
}
|
|
5
|
+
export function setCommandContext(state) {
|
|
6
|
+
return setContext(CommandContext, state);
|
|
7
|
+
}
|
|
8
|
+
export function getCommandContext() {
|
|
9
|
+
const ctx = getContext(CommandContext);
|
|
10
|
+
if (!ctx)
|
|
11
|
+
throw new Error("CommandContext is undefined");
|
|
12
|
+
return ctx;
|
|
13
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import type { HTMLInputAttributes } from "svelte/elements";
|
|
3
|
+
import { twMerge } from "tailwind-merge";
|
|
4
|
+
import { baseClasses, type Variants } from "../base";
|
|
5
|
+
import { mergeProps } from "../merge-props";
|
|
6
|
+
import type { ClassName, ElementRef } from "../utils";
|
|
7
|
+
import { getCommandContext } from "./command-context.svelte";
|
|
8
|
+
|
|
9
|
+
export type CommandInputProps = {} & ElementRef &
|
|
10
|
+
ClassName &
|
|
11
|
+
Variants &
|
|
12
|
+
HTMLInputAttributes;
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<script lang="ts">
|
|
16
|
+
let {
|
|
17
|
+
value = $bindable(""),
|
|
18
|
+
class: className,
|
|
19
|
+
variant = "plain",
|
|
20
|
+
color = "secondary",
|
|
21
|
+
shape = "rounded",
|
|
22
|
+
...restProps
|
|
23
|
+
}: CommandInputProps = $props();
|
|
24
|
+
|
|
25
|
+
const ctx = getCommandContext();
|
|
26
|
+
ctx.bindInput(
|
|
27
|
+
() => value,
|
|
28
|
+
(newValue) => (value = newValue),
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
function handleKeyDown(event: KeyboardEvent) {
|
|
32
|
+
ctx.handleKeyDown(event);
|
|
33
|
+
}
|
|
34
|
+
</script>
|
|
35
|
+
|
|
36
|
+
<input
|
|
37
|
+
bind:value={ctx.input}
|
|
38
|
+
class={twMerge(
|
|
39
|
+
baseClasses({ variant, color, shape }),
|
|
40
|
+
"w-full p-1 focus-visible:outline-hidden",
|
|
41
|
+
className,
|
|
42
|
+
)}
|
|
43
|
+
{...mergeProps({ onkeydown: handleKeyDown }, restProps)}
|
|
44
|
+
/>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { HTMLInputAttributes } from "svelte/elements";
|
|
2
|
+
import { type Variants } from "../base";
|
|
3
|
+
import type { ClassName, ElementRef } from "../utils";
|
|
4
|
+
export type CommandInputProps = {} & ElementRef & ClassName & Variants & HTMLInputAttributes;
|
|
5
|
+
declare const CommandInput: import("svelte").Component<CommandInputProps, {}, "value">;
|
|
6
|
+
type CommandInput = ReturnType<typeof CommandInput>;
|
|
7
|
+
export default CommandInput;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import { type Snippet } from "svelte";
|
|
3
|
+
import type { HTMLAttributes } from "svelte/elements";
|
|
4
|
+
import { twMerge } from "tailwind-merge";
|
|
5
|
+
import { baseClasses, type Variants } from "../base";
|
|
6
|
+
import { mergeProps } from "../merge-props";
|
|
7
|
+
import { type ClassName, type ElementRef } from "../utils";
|
|
8
|
+
import { getCommandContext } from "./command-context.svelte";
|
|
9
|
+
|
|
10
|
+
export type CommandItemProps = {
|
|
11
|
+
onSelect?: (el: HTMLElement) => void;
|
|
12
|
+
children: Snippet<[]>;
|
|
13
|
+
} & ElementRef &
|
|
14
|
+
ClassName &
|
|
15
|
+
Variants &
|
|
16
|
+
HTMLAttributes<HTMLDivElement>;
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<script lang="ts">
|
|
20
|
+
let {
|
|
21
|
+
onSelect,
|
|
22
|
+
children,
|
|
23
|
+
el = $bindable(),
|
|
24
|
+
class: className,
|
|
25
|
+
variant = "plain",
|
|
26
|
+
color = "secondary",
|
|
27
|
+
shape = "rounded",
|
|
28
|
+
...restProps
|
|
29
|
+
}: CommandItemProps = $props();
|
|
30
|
+
|
|
31
|
+
const ctx = getCommandContext();
|
|
32
|
+
|
|
33
|
+
function handleClick() {
|
|
34
|
+
if (el) {
|
|
35
|
+
onSelect?.(el);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function handleMouseEnter() {
|
|
40
|
+
ctx.focused = el;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
$effect(() => {
|
|
44
|
+
if (el) {
|
|
45
|
+
return ctx.add(el);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
</script>
|
|
49
|
+
|
|
50
|
+
<div
|
|
51
|
+
bind:this={el}
|
|
52
|
+
role="option"
|
|
53
|
+
tabindex="-1"
|
|
54
|
+
aria-selected={ctx.focused === el}
|
|
55
|
+
class={twMerge(
|
|
56
|
+
baseClasses({ variant, color, shape }),
|
|
57
|
+
"flex w-full cursor-pointer items-center gap-1 px-2 py-1 text-left text-sm focus:ring-0 disabled:bg-transparent aria-selected:bg-m3-secondary/15",
|
|
58
|
+
className,
|
|
59
|
+
)}
|
|
60
|
+
{...mergeProps(restProps, {
|
|
61
|
+
onclick: handleClick,
|
|
62
|
+
onmouseenter: handleMouseEnter,
|
|
63
|
+
})}
|
|
64
|
+
>
|
|
65
|
+
{@render children()}
|
|
66
|
+
</div>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Snippet } from "svelte";
|
|
2
|
+
import type { HTMLAttributes } from "svelte/elements";
|
|
3
|
+
import { type Variants } from "../base";
|
|
4
|
+
import { type ClassName, type ElementRef } from "../utils";
|
|
5
|
+
export type CommandItemProps = {
|
|
6
|
+
onSelect?: (el: HTMLElement) => void;
|
|
7
|
+
children: Snippet<[]>;
|
|
8
|
+
} & ElementRef & ClassName & Variants & HTMLAttributes<HTMLDivElement>;
|
|
9
|
+
declare const CommandItem: import("svelte").Component<CommandItemProps, {}, "el">;
|
|
10
|
+
type CommandItem = ReturnType<typeof CommandItem>;
|
|
11
|
+
export default CommandItem;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import { SearchIcon } from "@lucide/svelte";
|
|
3
|
+
import { CommandInput } from ".";
|
|
4
|
+
import type { CommandInputProps } from "./command-input.svelte";
|
|
5
|
+
|
|
6
|
+
export type CommandSearchProps = {} & CommandInputProps;
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<script lang="ts">
|
|
10
|
+
import { twMerge } from "tailwind-merge";
|
|
11
|
+
|
|
12
|
+
let {
|
|
13
|
+
value = $bindable(""),
|
|
14
|
+
placeholder = "Search...",
|
|
15
|
+
class: className,
|
|
16
|
+
...restProps
|
|
17
|
+
}: CommandSearchProps = $props();
|
|
18
|
+
</script>
|
|
19
|
+
|
|
20
|
+
<div class={twMerge("flex items-center gap-2 px-2", className)}>
|
|
21
|
+
<SearchIcon size={16} />
|
|
22
|
+
<CommandInput
|
|
23
|
+
autofocus
|
|
24
|
+
bind:value
|
|
25
|
+
{placeholder}
|
|
26
|
+
class="h-10"
|
|
27
|
+
{...restProps}
|
|
28
|
+
/>
|
|
29
|
+
</div>
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { CommandInputProps } from "./command-input.svelte";
|
|
2
|
+
export type CommandSearchProps = {} & CommandInputProps;
|
|
3
|
+
declare const CommandSearch: import("svelte").Component<CommandSearchProps, {}, "value">;
|
|
4
|
+
type CommandSearch = ReturnType<typeof CommandSearch>;
|
|
5
|
+
export default CommandSearch;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
import { twMerge } from "tailwind-merge";
|
|
4
|
+
import type { ClassName } from "../utils";
|
|
5
|
+
import { CommandContext, setCommandContext } from "./command-context.svelte";
|
|
6
|
+
|
|
7
|
+
export type CommandProps = {
|
|
8
|
+
children: Snippet<[]>;
|
|
9
|
+
} & ClassName;
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<script lang="ts">
|
|
13
|
+
let { children, class: className }: CommandProps = $props();
|
|
14
|
+
setCommandContext(new CommandContext());
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<div class={twMerge("flex h-full flex-col p-1", className)}>
|
|
18
|
+
{@render children()}
|
|
19
|
+
</div>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Snippet } from "svelte";
|
|
2
|
+
import type { ClassName } from "../utils";
|
|
3
|
+
export type CommandProps = {
|
|
4
|
+
children: Snippet<[]>;
|
|
5
|
+
} & ClassName;
|
|
6
|
+
declare const Command: import("svelte").Component<CommandProps, {}, "">;
|
|
7
|
+
type Command = ReturnType<typeof Command>;
|
|
8
|
+
export default Command;
|