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,123 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
import type { HTMLDialogAttributes } from "svelte/elements";
|
|
4
|
+
import { scale } from "svelte/transition";
|
|
5
|
+
import { twMerge } from "tailwind-merge";
|
|
6
|
+
import { events } from "..";
|
|
7
|
+
import { mergeProps } from "../merge-props";
|
|
8
|
+
import { Shortcut } from "../shortcut";
|
|
9
|
+
import { type ClassName } from "../utils";
|
|
10
|
+
|
|
11
|
+
export type ModalProps = {
|
|
12
|
+
ref?: HTMLDialogElement;
|
|
13
|
+
onCancel?: () => void;
|
|
14
|
+
children: Snippet;
|
|
15
|
+
} & ClassName &
|
|
16
|
+
HTMLDialogAttributes;
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<script lang="ts">
|
|
20
|
+
let {
|
|
21
|
+
ref = $bindable(),
|
|
22
|
+
open = $bindable(),
|
|
23
|
+
onCancel,
|
|
24
|
+
children,
|
|
25
|
+
class: className,
|
|
26
|
+
...restProps
|
|
27
|
+
}: ModalProps = $props();
|
|
28
|
+
|
|
29
|
+
function handleKeydown(event: KeyboardEvent) {
|
|
30
|
+
if (Shortcut.ESCAPE.matches(event)) {
|
|
31
|
+
open = false;
|
|
32
|
+
onCancel?.();
|
|
33
|
+
event.preventDefault();
|
|
34
|
+
}
|
|
35
|
+
event.stopImmediatePropagation();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function handleClickOutside(event: MouseEvent) {
|
|
39
|
+
if (ref && ref === event.target) {
|
|
40
|
+
const rect = ref.getBoundingClientRect();
|
|
41
|
+
if (
|
|
42
|
+
event.clientY < rect.top ||
|
|
43
|
+
event.clientY > rect.top + rect.height ||
|
|
44
|
+
event.clientX < rect.left ||
|
|
45
|
+
event.clientX > rect.left + rect.width
|
|
46
|
+
) {
|
|
47
|
+
open = false;
|
|
48
|
+
onCancel?.();
|
|
49
|
+
event.preventDefault();
|
|
50
|
+
event.stopImmediatePropagation();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
$effect(() => {
|
|
56
|
+
if (ref) {
|
|
57
|
+
ref.showModal();
|
|
58
|
+
events.on("keydown", handleKeydown);
|
|
59
|
+
events.on("mousedown", handleClickOutside);
|
|
60
|
+
|
|
61
|
+
return () => {
|
|
62
|
+
events.remove("keydown", handleKeydown);
|
|
63
|
+
events.remove("mousedown", handleClickOutside);
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
</script>
|
|
68
|
+
|
|
69
|
+
{#if open}
|
|
70
|
+
<dialog
|
|
71
|
+
bind:this={ref}
|
|
72
|
+
class={twMerge("m-auto rounded-lg p-5 shadow-lg", className)}
|
|
73
|
+
transition:scale={{ duration: 150, start: 0.95 }}
|
|
74
|
+
{...mergeProps(restProps, {
|
|
75
|
+
onintrostart: () => {
|
|
76
|
+
if (ref) {
|
|
77
|
+
ref.classList.remove("backdrop-out");
|
|
78
|
+
ref.classList.add("backdrop-in");
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
onoutrostart: () => {
|
|
82
|
+
if (ref) {
|
|
83
|
+
ref.classList.remove("backdrop-in");
|
|
84
|
+
ref.classList.add("backdrop-out");
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
})}
|
|
88
|
+
>
|
|
89
|
+
{@render children()}
|
|
90
|
+
</dialog>
|
|
91
|
+
{/if}
|
|
92
|
+
|
|
93
|
+
<style>
|
|
94
|
+
.backdrop-in::backdrop {
|
|
95
|
+
animation: backdrop-in 150ms forwards;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.backdrop-out::backdrop {
|
|
99
|
+
animation: backdrop-out 150ms forwards;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
@keyframes backdrop-in {
|
|
103
|
+
from {
|
|
104
|
+
background: rgba(0, 0, 0, 0);
|
|
105
|
+
backdrop-filter: blur(0px);
|
|
106
|
+
}
|
|
107
|
+
to {
|
|
108
|
+
background: rgba(0, 0, 0, 0.5);
|
|
109
|
+
backdrop-filter: blur(2px);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
@keyframes backdrop-out {
|
|
114
|
+
from {
|
|
115
|
+
background: rgba(0, 0, 0, 0.5);
|
|
116
|
+
backdrop-filter: blur(2px);
|
|
117
|
+
}
|
|
118
|
+
to {
|
|
119
|
+
background: rgba(0, 0, 0, 0);
|
|
120
|
+
backdrop-filter: blur(0px);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
</style>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Snippet } from "svelte";
|
|
2
|
+
import type { HTMLDialogAttributes } from "svelte/elements";
|
|
3
|
+
import { type ClassName } from "../utils";
|
|
4
|
+
export type ModalProps = {
|
|
5
|
+
ref?: HTMLDialogElement;
|
|
6
|
+
onCancel?: () => void;
|
|
7
|
+
children: Snippet;
|
|
8
|
+
} & ClassName & HTMLDialogAttributes;
|
|
9
|
+
declare const Modal: import("svelte").Component<ModalProps, {}, "open" | "ref">;
|
|
10
|
+
type Modal = ReturnType<typeof Modal>;
|
|
11
|
+
export default Modal;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export class OrderedHTMLElements {
|
|
2
|
+
#items = [];
|
|
3
|
+
get items() {
|
|
4
|
+
return this.#items;
|
|
5
|
+
}
|
|
6
|
+
getInsertionIndex(item) {
|
|
7
|
+
if (this.#items.includes(item)) {
|
|
8
|
+
throw new Error(`Ordered items already contains ${item}`);
|
|
9
|
+
}
|
|
10
|
+
for (let i = 0; i < this.#items.length; i++) {
|
|
11
|
+
const position = item.compareDocumentPosition(this.#items[i]);
|
|
12
|
+
if ((position & Node.DOCUMENT_POSITION_FOLLOWING) !== 0) {
|
|
13
|
+
return i;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return this.#items.length;
|
|
17
|
+
}
|
|
18
|
+
add(item) {
|
|
19
|
+
const index = this.getInsertionIndex(item);
|
|
20
|
+
this.#items.splice(index, 0, item);
|
|
21
|
+
}
|
|
22
|
+
delete(item) {
|
|
23
|
+
const index = this.#items.indexOf(item);
|
|
24
|
+
if (index === -1) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
this.items.splice(index, 1);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as Popover, type PopoverProps } from "./popover.svelte";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as Popover } from "./popover.svelte";
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import * as floatingUi from "@floating-ui/dom";
|
|
3
|
+
import { type Snippet } from "svelte";
|
|
4
|
+
import type { HTMLAttributes } from "svelte/elements";
|
|
5
|
+
import { scale } from "svelte/transition";
|
|
6
|
+
import { twMerge, type ClassNameValue } from "tailwind-merge";
|
|
7
|
+
import { events } from "..";
|
|
8
|
+
import { mergeProps } from "../merge-props";
|
|
9
|
+
import { Shortcut } from "../shortcut";
|
|
10
|
+
import {
|
|
11
|
+
noop,
|
|
12
|
+
type ClassName,
|
|
13
|
+
type ElementRef,
|
|
14
|
+
type ToggleEventWithTarget,
|
|
15
|
+
} from "../utils";
|
|
16
|
+
|
|
17
|
+
export type PopoverProps = {
|
|
18
|
+
arrow?: boolean;
|
|
19
|
+
arrowClass?: ClassNameValue;
|
|
20
|
+
placement?: floatingUi.Placement;
|
|
21
|
+
strategy?: floatingUi.Strategy;
|
|
22
|
+
open?: boolean;
|
|
23
|
+
anchorEl?: HTMLElement;
|
|
24
|
+
onKeydownWhileOpen?: (event: KeyboardEvent) => void;
|
|
25
|
+
children: Snippet;
|
|
26
|
+
} & ClassName &
|
|
27
|
+
ElementRef &
|
|
28
|
+
HTMLAttributes<HTMLDivElement>;
|
|
29
|
+
|
|
30
|
+
type Side = "top" | "bottom" | "left" | "right";
|
|
31
|
+
</script>
|
|
32
|
+
|
|
33
|
+
<script lang="ts">
|
|
34
|
+
let {
|
|
35
|
+
arrow = false,
|
|
36
|
+
placement = "top",
|
|
37
|
+
strategy = "fixed",
|
|
38
|
+
open = $bindable(false),
|
|
39
|
+
anchorEl,
|
|
40
|
+
children,
|
|
41
|
+
onKeydownWhileOpen,
|
|
42
|
+
el: popoverEl = $bindable(),
|
|
43
|
+
ref = noop,
|
|
44
|
+
arrowClass,
|
|
45
|
+
class: className,
|
|
46
|
+
...restProps
|
|
47
|
+
}: PopoverProps = $props();
|
|
48
|
+
|
|
49
|
+
let arrowEl: HTMLDivElement | undefined = $state();
|
|
50
|
+
|
|
51
|
+
function getArrowRotation(placement: Side) {
|
|
52
|
+
if (placement === "top") {
|
|
53
|
+
return "rotateZ(0deg)";
|
|
54
|
+
} else if (placement === "right") {
|
|
55
|
+
return "rotateZ(90deg)";
|
|
56
|
+
} else if (placement === "bottom") {
|
|
57
|
+
return "rotateZ(180deg)";
|
|
58
|
+
} else if (placement === "left") {
|
|
59
|
+
return "rotateZ(270deg)";
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function handleEscape(event: KeyboardEvent) {
|
|
64
|
+
if (popoverEl && Shortcut.ESCAPE.matches(event)) {
|
|
65
|
+
popoverEl.hidePopover();
|
|
66
|
+
anchorEl?.focus();
|
|
67
|
+
event.preventDefault();
|
|
68
|
+
event.stopImmediatePropagation();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function handleClickOutside(event: MouseEvent) {
|
|
73
|
+
if (
|
|
74
|
+
popoverEl &&
|
|
75
|
+
event.target instanceof Node &&
|
|
76
|
+
!popoverEl.contains(event.target) &&
|
|
77
|
+
(!anchorEl || !anchorEl.contains(event.target))
|
|
78
|
+
) {
|
|
79
|
+
popoverEl.hidePopover();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function handleClickInside(event: MouseEvent) {
|
|
84
|
+
event.stopImmediatePropagation();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function onbeforetoggle(event: ToggleEventWithTarget<HTMLDivElement>) {
|
|
88
|
+
if (event.newState === "closed") {
|
|
89
|
+
open = false;
|
|
90
|
+
} else {
|
|
91
|
+
open = true;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
$effect(() => {
|
|
96
|
+
if (popoverEl) {
|
|
97
|
+
popoverEl.showPopover();
|
|
98
|
+
events.on("keydown", handleEscape);
|
|
99
|
+
events.on("keydown", onKeydownWhileOpen);
|
|
100
|
+
events.on("mousedown", handleClickOutside);
|
|
101
|
+
|
|
102
|
+
return () => {
|
|
103
|
+
events.remove("keydown", handleEscape);
|
|
104
|
+
events.remove("keydown", onKeydownWhileOpen);
|
|
105
|
+
events.remove("mousedown", handleClickOutside);
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
$effect(() => {
|
|
111
|
+
if (anchorEl && popoverEl) {
|
|
112
|
+
return floatingUi.autoUpdate(anchorEl, popoverEl, updatePosition);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
async function updatePosition() {
|
|
117
|
+
if (anchorEl && popoverEl && arrowEl) {
|
|
118
|
+
const computedPosition = await floatingUi.computePosition(
|
|
119
|
+
anchorEl,
|
|
120
|
+
popoverEl,
|
|
121
|
+
{
|
|
122
|
+
placement,
|
|
123
|
+
middleware: [
|
|
124
|
+
floatingUi.offset(6),
|
|
125
|
+
floatingUi.flip(),
|
|
126
|
+
floatingUi.shift({ padding: 5 }),
|
|
127
|
+
floatingUi.arrow({ element: arrowEl }),
|
|
128
|
+
],
|
|
129
|
+
strategy,
|
|
130
|
+
},
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
Object.assign(popoverEl.style, {
|
|
134
|
+
left: `${computedPosition.x}px`,
|
|
135
|
+
top: `${computedPosition.y}px`,
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
if (computedPosition.middlewareData.arrow) {
|
|
139
|
+
const arrow = computedPosition.middlewareData.arrow;
|
|
140
|
+
|
|
141
|
+
const side = computedPosition.placement.split("-")[0] as Side;
|
|
142
|
+
|
|
143
|
+
const staticSide = {
|
|
144
|
+
top: "bottom",
|
|
145
|
+
right: "left",
|
|
146
|
+
bottom: "top",
|
|
147
|
+
left: "right",
|
|
148
|
+
}[side];
|
|
149
|
+
|
|
150
|
+
Object.assign(arrowEl.style, {
|
|
151
|
+
left: arrow.x != null ? `${arrow.x}px` : "",
|
|
152
|
+
top: arrow.y != null ? `${arrow.y}px` : "",
|
|
153
|
+
[staticSide]: "-4px",
|
|
154
|
+
transform: getArrowRotation(side),
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (!children) {
|
|
161
|
+
console.log(children);
|
|
162
|
+
}
|
|
163
|
+
</script>
|
|
164
|
+
|
|
165
|
+
{#if open}
|
|
166
|
+
<div
|
|
167
|
+
bind:this={popoverEl}
|
|
168
|
+
use:ref
|
|
169
|
+
popover="manual"
|
|
170
|
+
class={twMerge(className)}
|
|
171
|
+
transition:scale={{ duration: 150, start: 0.95 }}
|
|
172
|
+
{...mergeProps(restProps, { onbeforetoggle, onclick: handleClickInside })}
|
|
173
|
+
>
|
|
174
|
+
{@render children()}
|
|
175
|
+
<div
|
|
176
|
+
bind:this={arrowEl}
|
|
177
|
+
class={twMerge(
|
|
178
|
+
arrowClass,
|
|
179
|
+
"absolute size-2 rotate-45",
|
|
180
|
+
arrow ? "block" : "hidden",
|
|
181
|
+
)}
|
|
182
|
+
></div>
|
|
183
|
+
</div>
|
|
184
|
+
{/if}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as floatingUi from "@floating-ui/dom";
|
|
2
|
+
import { type Snippet } from "svelte";
|
|
3
|
+
import type { HTMLAttributes } from "svelte/elements";
|
|
4
|
+
import { type ClassNameValue } from "tailwind-merge";
|
|
5
|
+
import { type ClassName, type ElementRef } from "../utils";
|
|
6
|
+
export type PopoverProps = {
|
|
7
|
+
arrow?: boolean;
|
|
8
|
+
arrowClass?: ClassNameValue;
|
|
9
|
+
placement?: floatingUi.Placement;
|
|
10
|
+
strategy?: floatingUi.Strategy;
|
|
11
|
+
open?: boolean;
|
|
12
|
+
anchorEl?: HTMLElement;
|
|
13
|
+
onKeydownWhileOpen?: (event: KeyboardEvent) => void;
|
|
14
|
+
children: Snippet;
|
|
15
|
+
} & ClassName & ElementRef & HTMLAttributes<HTMLDivElement>;
|
|
16
|
+
declare const Popover: import("svelte").Component<PopoverProps, {}, "open" | "el">;
|
|
17
|
+
type Popover = ReturnType<typeof Popover>;
|
|
18
|
+
export default Popover;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as Portal } from "./portal.svelte";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as Portal } from "./portal.svelte";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { mount, unmount, type Snippet } from "svelte";
|
|
3
|
+
import Proxy from "./proxy.svelte";
|
|
4
|
+
|
|
5
|
+
type Props = { children?: Snippet; target?: HTMLElement };
|
|
6
|
+
const { children, target = document.body }: Props = $props();
|
|
7
|
+
|
|
8
|
+
$effect(() => {
|
|
9
|
+
const instance = mount(Proxy, { target, props: { children } });
|
|
10
|
+
return () => unmount(instance);
|
|
11
|
+
});
|
|
12
|
+
</script>
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
|
|
4
|
+
const DASH_ARRAY = 2 * 3.1415926535 * 10;
|
|
5
|
+
|
|
6
|
+
type Props = {
|
|
7
|
+
children?: Snippet;
|
|
8
|
+
progress?: number;
|
|
9
|
+
size?: string | number;
|
|
10
|
+
trackColor?: string;
|
|
11
|
+
textColor?: string;
|
|
12
|
+
color?: string;
|
|
13
|
+
class?: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const {
|
|
17
|
+
children,
|
|
18
|
+
progress,
|
|
19
|
+
size = 24,
|
|
20
|
+
trackColor = "color-mix(in srgb, currentColor 10%, transparent)",
|
|
21
|
+
textColor = "currentColor",
|
|
22
|
+
color = "currentColor",
|
|
23
|
+
class: className,
|
|
24
|
+
}: Props = $props();
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<svg
|
|
28
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
29
|
+
width={size}
|
|
30
|
+
height={size}
|
|
31
|
+
viewBox="0 0 24 24"
|
|
32
|
+
fill="transparent"
|
|
33
|
+
class={className}
|
|
34
|
+
class:circular={progress === undefined}
|
|
35
|
+
>
|
|
36
|
+
<circle cx="50%" cy="50%" r="10px" stroke={trackColor} stroke-width="2px" />
|
|
37
|
+
<circle
|
|
38
|
+
class:path={progress === undefined}
|
|
39
|
+
cx="50%"
|
|
40
|
+
cy="50%"
|
|
41
|
+
r="10px"
|
|
42
|
+
stroke={color}
|
|
43
|
+
stroke-width="2px"
|
|
44
|
+
stroke-linecap="round"
|
|
45
|
+
stroke-dasharray={DASH_ARRAY}
|
|
46
|
+
stroke-dashoffset={(1 - (progress ?? 1)) * DASH_ARRAY}
|
|
47
|
+
transform-origin="center"
|
|
48
|
+
transform="rotate(-90)"
|
|
49
|
+
/>
|
|
50
|
+
<text
|
|
51
|
+
x="12"
|
|
52
|
+
y="12"
|
|
53
|
+
font-size="7"
|
|
54
|
+
text-anchor="middle"
|
|
55
|
+
dominant-baseline="central"
|
|
56
|
+
fill={textColor}
|
|
57
|
+
>
|
|
58
|
+
{@render children?.()}
|
|
59
|
+
</text>
|
|
60
|
+
</svg>
|
|
61
|
+
|
|
62
|
+
<style>
|
|
63
|
+
.circular {
|
|
64
|
+
animation: rotate 2s linear infinite;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.path {
|
|
68
|
+
animation: dash 1.5s ease-in-out infinite;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
@keyframes rotate {
|
|
72
|
+
100% {
|
|
73
|
+
transform: rotate(360deg);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
@keyframes dash {
|
|
77
|
+
0% {
|
|
78
|
+
stroke-dasharray: 1, 200;
|
|
79
|
+
stroke-dashoffset: 0;
|
|
80
|
+
}
|
|
81
|
+
100% {
|
|
82
|
+
stroke-dasharray: 89, 200;
|
|
83
|
+
stroke-dashoffset: -62;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
</style>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Snippet } from "svelte";
|
|
2
|
+
type Props = {
|
|
3
|
+
children?: Snippet;
|
|
4
|
+
progress?: number;
|
|
5
|
+
size?: string | number;
|
|
6
|
+
trackColor?: string;
|
|
7
|
+
textColor?: string;
|
|
8
|
+
color?: string;
|
|
9
|
+
class?: string;
|
|
10
|
+
};
|
|
11
|
+
declare const CircularProgress: import("svelte").Component<Props, {}, "">;
|
|
12
|
+
type CircularProgress = ReturnType<typeof CircularProgress>;
|
|
13
|
+
export default CircularProgress;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as CircularProgress } from "./circular-progress.svelte";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as CircularProgress } from "./circular-progress.svelte";
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import type { HTMLInputAttributes } from "svelte/elements";
|
|
3
|
+
import { twMerge, type ClassNameValue } from "tailwind-merge";
|
|
4
|
+
import { Box } from "../box";
|
|
5
|
+
import { noop, type ClassName, type ElementRef } from "../utils";
|
|
6
|
+
import type { Shortcut } from "./shortcut";
|
|
7
|
+
|
|
8
|
+
export type ShortcutBadgeProps = {
|
|
9
|
+
shortcut: Shortcut;
|
|
10
|
+
badgeClass?: ClassNameValue;
|
|
11
|
+
} & ElementRef &
|
|
12
|
+
ClassName &
|
|
13
|
+
HTMLInputAttributes;
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<script lang="ts">
|
|
17
|
+
let {
|
|
18
|
+
shortcut,
|
|
19
|
+
el = $bindable(),
|
|
20
|
+
ref = noop,
|
|
21
|
+
class: className,
|
|
22
|
+
badgeClass,
|
|
23
|
+
}: ShortcutBadgeProps = $props();
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<div
|
|
27
|
+
bind:this={el}
|
|
28
|
+
use:ref
|
|
29
|
+
class={twMerge("flex gap-1 text-m3-on-surface", className)}
|
|
30
|
+
>
|
|
31
|
+
{#each shortcut as symbol, index (index)}
|
|
32
|
+
<Box
|
|
33
|
+
variant="elevated"
|
|
34
|
+
color="secondary"
|
|
35
|
+
centered
|
|
36
|
+
class={twMerge("h-5 min-w-5 rounded border p-1 text-xs", badgeClass)}
|
|
37
|
+
>
|
|
38
|
+
{symbol}
|
|
39
|
+
</Box>
|
|
40
|
+
{/each}
|
|
41
|
+
</div>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { HTMLInputAttributes } from "svelte/elements";
|
|
2
|
+
import { type ClassNameValue } from "tailwind-merge";
|
|
3
|
+
import { type ClassName, type ElementRef } from "../utils";
|
|
4
|
+
import type { Shortcut } from "./shortcut";
|
|
5
|
+
export type ShortcutBadgeProps = {
|
|
6
|
+
shortcut: Shortcut;
|
|
7
|
+
badgeClass?: ClassNameValue;
|
|
8
|
+
} & ElementRef & ClassName & HTMLInputAttributes;
|
|
9
|
+
declare const ShortcutBadge: import("svelte").Component<ShortcutBadgeProps, {}, "el">;
|
|
10
|
+
type ShortcutBadge = ReturnType<typeof ShortcutBadge>;
|
|
11
|
+
export default ShortcutBadge;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export declare class Shortcut {
|
|
2
|
+
key: string;
|
|
3
|
+
alt: boolean;
|
|
4
|
+
ctrl: boolean;
|
|
5
|
+
meta: boolean;
|
|
6
|
+
shift: boolean;
|
|
7
|
+
constructor(shortcut: {
|
|
8
|
+
key: string;
|
|
9
|
+
alt?: boolean;
|
|
10
|
+
ctrl?: boolean;
|
|
11
|
+
meta?: boolean;
|
|
12
|
+
shift?: boolean;
|
|
13
|
+
});
|
|
14
|
+
matches(event: KeyboardEvent): boolean;
|
|
15
|
+
toChar(): string;
|
|
16
|
+
toString(): string;
|
|
17
|
+
[Symbol.iterator](): Iterator<string>;
|
|
18
|
+
static isChar(event: KeyboardEvent): boolean;
|
|
19
|
+
static fromEvent(event: KeyboardEvent): Shortcut;
|
|
20
|
+
static ARROW_UP: Shortcut;
|
|
21
|
+
static ARROW_DOWN: Shortcut;
|
|
22
|
+
static END: Shortcut;
|
|
23
|
+
static ENTER: Shortcut;
|
|
24
|
+
static ESCAPE: Shortcut;
|
|
25
|
+
static HOME: Shortcut;
|
|
26
|
+
static SPACE: Shortcut;
|
|
27
|
+
static TAB_BACKWARD: Shortcut;
|
|
28
|
+
static TAB_FORWARD: Shortcut;
|
|
29
|
+
}
|