@byyuurin/ui 0.0.11 → 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 +170 -58
- package/dist/module.d.mts +4 -13
- package/dist/module.json +4 -4
- package/dist/module.mjs +54 -20
- package/dist/runtime/components/Accordion.vue +28 -23
- package/dist/runtime/components/Accordion.vue.d.ts +51 -29
- package/dist/runtime/components/Alert.vue +47 -27
- package/dist/runtime/components/Alert.vue.d.ts +37 -25
- package/dist/runtime/components/App.vue +9 -8
- package/dist/runtime/components/App.vue.d.ts +22 -20
- package/dist/runtime/components/Avatar.vue +65 -21
- package/dist/runtime/components/Avatar.vue.d.ts +27 -13
- package/dist/runtime/components/AvatarGroup.vue +14 -10
- package/dist/runtime/components/AvatarGroup.vue.d.ts +12 -9
- package/dist/runtime/components/Badge.vue +64 -32
- package/dist/runtime/components/Badge.vue.d.ts +30 -29
- package/dist/runtime/components/Breadcrumb.vue +40 -22
- package/dist/runtime/components/Breadcrumb.vue.d.ts +48 -21
- package/dist/runtime/components/Button.vue +113 -52
- package/dist/runtime/components/Button.vue.d.ts +36 -20
- package/dist/runtime/components/Calendar.vue +50 -43
- package/dist/runtime/components/Calendar.vue.d.ts +58 -31
- package/dist/runtime/components/Card.vue +18 -14
- package/dist/runtime/components/Card.vue.d.ts +18 -14
- package/dist/runtime/components/Carousel.vue +99 -46
- package/dist/runtime/components/Carousel.vue.d.ts +46 -25
- package/dist/runtime/components/Checkbox.vue +60 -35
- package/dist/runtime/components/Checkbox.vue.d.ts +35 -28
- package/dist/runtime/components/CheckboxGroup.vue +131 -0
- package/dist/runtime/components/CheckboxGroup.vue.d.ts +89 -0
- package/dist/runtime/components/Chip.vue +35 -32
- package/dist/runtime/components/Chip.vue.d.ts +33 -15
- package/dist/runtime/components/Collapsible.vue +13 -9
- package/dist/runtime/components/Collapsible.vue.d.ts +16 -8
- package/dist/runtime/components/Drawer.vue +80 -70
- package/dist/runtime/components/Drawer.vue.d.ts +51 -28
- package/dist/runtime/components/DropdownMenu.vue +23 -16
- package/dist/runtime/components/DropdownMenu.vue.d.ts +77 -36
- package/dist/runtime/components/DropdownMenuContent.vue +136 -106
- package/dist/runtime/components/DropdownMenuContent.vue.d.ts +38 -26
- package/dist/runtime/components/FieldGroup.vue +33 -0
- package/dist/runtime/components/FieldGroup.vue.d.ts +33 -0
- package/dist/runtime/components/Form.vue +172 -88
- package/dist/runtime/components/Form.vue.d.ts +69 -44
- package/dist/runtime/components/FormField.vue +108 -0
- package/dist/runtime/components/FormField.vue.d.ts +63 -0
- package/dist/runtime/components/Icon.vue +20 -0
- package/dist/runtime/components/Icon.vue.d.ts +9 -0
- package/dist/runtime/components/Input.vue +84 -79
- package/dist/runtime/components/Input.vue.d.ts +55 -43
- package/dist/runtime/components/InputNumber.vue +66 -52
- package/dist/runtime/components/InputNumber.vue.d.ts +50 -109
- package/dist/runtime/components/InputTags.vue +155 -0
- package/dist/runtime/components/InputTags.vue.d.ts +85 -0
- package/dist/runtime/components/Kbd.vue +11 -5
- package/dist/runtime/components/Kbd.vue.d.ts +17 -11
- package/dist/runtime/components/Link.vue +54 -197
- package/dist/runtime/components/Link.vue.d.ts +17 -17
- package/dist/runtime/components/LinkBase.vue +11 -33
- package/dist/runtime/components/LinkBase.vue.d.ts +8 -3
- package/dist/runtime/components/Marquee.vue +38 -0
- package/dist/runtime/components/Marquee.vue.d.ts +54 -0
- package/dist/runtime/components/Modal.vue +53 -39
- package/dist/runtime/components/Modal.vue.d.ts +64 -34
- package/dist/runtime/components/NavigationMenu.vue +345 -0
- package/dist/runtime/components/NavigationMenu.vue.d.ts +216 -0
- package/dist/runtime/components/OverlayProvider.vue +3 -3
- package/dist/runtime/components/OverlayProvider.vue.d.ts +2 -1
- package/dist/runtime/components/Pagination.vue +39 -47
- package/dist/runtime/components/Pagination.vue.d.ts +54 -31
- package/dist/runtime/components/PinInput.vue +46 -32
- package/dist/runtime/components/PinInput.vue.d.ts +40 -21
- package/dist/runtime/components/Popover.vue +33 -19
- package/dist/runtime/components/Popover.vue.d.ts +57 -32
- package/dist/runtime/components/Progress.vue +31 -26
- package/dist/runtime/components/Progress.vue.d.ts +32 -23
- package/dist/runtime/components/RadioGroup.vue +75 -48
- package/dist/runtime/components/RadioGroup.vue.d.ts +58 -36
- package/dist/runtime/components/ScrollArea.vue +33 -31
- package/dist/runtime/components/ScrollArea.vue.d.ts +9 -5
- package/dist/runtime/components/Select.vue +166 -76
- package/dist/runtime/components/Select.vue.d.ts +206 -65
- package/dist/runtime/components/Separator.vue +42 -16
- package/dist/runtime/components/Separator.vue.d.ts +35 -14
- package/dist/runtime/components/Skeleton.vue +18 -6
- package/dist/runtime/components/Skeleton.vue.d.ts +4 -4
- package/dist/runtime/components/Slider.vue +42 -24
- package/dist/runtime/components/Slider.vue.d.ts +43 -27
- package/dist/runtime/components/Switch.vue +40 -31
- package/dist/runtime/components/Switch.vue.d.ts +36 -27
- package/dist/runtime/components/Table.vue +329 -79
- package/dist/runtime/components/Table.vue.d.ts +152 -66
- package/dist/runtime/components/Tabs.vue +70 -23
- package/dist/runtime/components/Tabs.vue.d.ts +61 -29
- package/dist/runtime/components/Textarea.vue +102 -54
- package/dist/runtime/components/Textarea.vue.d.ts +57 -41
- package/dist/runtime/components/Timeline.vue +102 -0
- package/dist/runtime/components/Timeline.vue.d.ts +74 -0
- package/dist/runtime/components/Toast.vue +84 -38
- package/dist/runtime/components/Toast.vue.d.ts +48 -27
- package/dist/runtime/components/ToastProvider.vue +31 -22
- package/dist/runtime/components/ToastProvider.vue.d.ts +30 -17
- package/dist/runtime/components/Tooltip.vue +33 -21
- package/dist/runtime/components/Tooltip.vue.d.ts +37 -15
- package/dist/runtime/composables/defineShortcuts.d.ts +16 -0
- package/dist/runtime/composables/defineShortcuts.js +129 -0
- package/dist/runtime/composables/useAvatarGroup.d.ts +8 -3
- package/dist/runtime/composables/useAvatarGroup.js +10 -3
- package/dist/runtime/composables/useComponentIcons.d.ts +9 -6
- package/dist/runtime/composables/useComponentIcons.js +4 -4
- package/dist/runtime/composables/useFieldGroup.d.ts +8 -0
- package/dist/runtime/composables/useFieldGroup.js +14 -0
- package/dist/runtime/composables/useFormField.d.ts +62 -0
- package/dist/runtime/composables/useFormField.js +99 -0
- package/dist/runtime/composables/useKbd.d.ts +3 -2
- package/dist/runtime/composables/useKbd.js +3 -2
- package/dist/runtime/composables/useLocale.d.ts +68 -5
- package/dist/runtime/composables/useLocale.js +11 -11
- package/dist/runtime/composables/useOverlay.d.ts +51 -15
- package/dist/runtime/composables/useOverlay.js +44 -30
- package/dist/runtime/composables/usePortal.d.ts +6 -0
- package/dist/runtime/composables/usePortal.js +17 -0
- package/dist/runtime/composables/useToast.d.ts +12 -5
- package/dist/runtime/composables/useToast.js +12 -7
- package/dist/runtime/locale/en.d.ts +30 -1
- package/dist/runtime/locale/en.js +2 -1
- package/dist/runtime/locale/index.d.ts +2 -2
- package/dist/runtime/locale/index.js +1 -1
- package/dist/runtime/locale/zh_tw.d.ts +31 -0
- package/dist/runtime/locale/{zh-tw.js → zh_tw.js} +2 -1
- package/dist/runtime/plugins/colors.d.ts +2 -0
- package/dist/runtime/plugins/colors.js +50 -0
- package/dist/runtime/types/app.config.d.ts +6 -0
- package/dist/runtime/types/form.d.ts +58 -17
- package/dist/runtime/types/form.js +11 -0
- package/dist/runtime/types/index.d.ts +56 -8
- package/dist/runtime/types/index.js +49 -1
- package/dist/runtime/types/input.d.ts +8 -0
- package/dist/runtime/types/locale.d.ts +5 -0
- package/dist/runtime/types/style.d.ts +33 -0
- package/dist/runtime/types/style.js +0 -0
- package/dist/runtime/types/unocss.d.ts +4 -0
- package/dist/runtime/types/utils.d.ts +41 -37
- package/dist/runtime/utils/form.d.ts +5 -1
- package/dist/runtime/utils/form.js +49 -0
- package/dist/runtime/utils/index.d.ts +10 -13
- package/dist/runtime/utils/index.js +41 -48
- package/dist/runtime/utils/link.d.ts +3 -2
- package/dist/runtime/utils/link.js +16 -2
- package/dist/runtime/utils/locale.d.ts +5 -0
- package/dist/runtime/utils/locale.js +10 -0
- package/dist/runtime/utils/style.d.ts +94 -0
- package/dist/runtime/utils/style.js +37 -0
- package/dist/runtime/vue/components/Icon.vue +15 -0
- package/dist/runtime/vue/components/Icon.vue.d.ts +7 -0
- package/dist/runtime/vue/components/Link.vue +163 -0
- package/dist/runtime/vue/components/Link.vue.d.ts +95 -0
- package/dist/runtime/vue/composables/useAppConfig.d.ts +1 -0
- package/dist/runtime/vue/composables/useAppConfig.js +4 -0
- package/dist/runtime/vue/plugins/color-mode.d.ts +4 -0
- package/dist/runtime/vue/plugins/color-mode.js +6 -0
- package/dist/runtime/vue/plugins/head.d.ts +4 -0
- package/dist/runtime/vue/plugins/head.js +9 -0
- package/dist/runtime/vue/stubs.d.ts +16 -1
- package/dist/runtime/vue/stubs.js +32 -1
- package/dist/setup.d.mts +13 -0
- package/dist/setup.mjs +12 -0
- package/dist/shared/ui.CzIlLITK.mjs +51 -0
- package/dist/shared/ui.DLOxhmP0.mjs +4242 -0
- package/dist/shared/ui.DpbffTXs.d.mts +84 -0
- package/dist/shared/ui.IulR-OYx.d.mts +64 -0
- package/dist/types.d.mts +3 -1
- package/dist/unocss.d.mts +12 -52
- package/dist/unocss.mjs +144 -254
- package/dist/unplugin.d.mts +13 -26
- package/dist/unplugin.mjs +193 -18
- package/dist/vite.d.mts +10 -1
- package/dist/vite.mjs +12 -3
- package/package.json +154 -87
- package/vue-plugin.d.ts +5 -0
- package/dist/module.d.ts +0 -13
- package/dist/module.mjs.map +0 -1
- package/dist/runtime/app/injections.d.ts +0 -9331
- package/dist/runtime/app/injections.js +0 -61
- package/dist/runtime/components/ButtonGroup.vue +0 -26
- package/dist/runtime/components/ButtonGroup.vue.d.ts +0 -26
- package/dist/runtime/components/FormItem.vue +0 -90
- package/dist/runtime/components/FormItem.vue.d.ts +0 -60
- package/dist/runtime/composables/useButtonGroup.d.ts +0 -5
- package/dist/runtime/composables/useButtonGroup.js +0 -9
- package/dist/runtime/composables/useFormItem.d.ts +0 -27
- package/dist/runtime/composables/useFormItem.js +0 -64
- package/dist/runtime/composables/useTheme.d.ts +0 -9
- package/dist/runtime/composables/useTheme.js +0 -23
- package/dist/runtime/index.d.ts +0 -44
- package/dist/runtime/index.js +0 -44
- package/dist/runtime/locale/zh-tw.d.ts +0 -2
- package/dist/runtime/theme/accordion.d.ts +0 -50
- package/dist/runtime/theme/accordion.js +0 -28
- package/dist/runtime/theme/alert.d.ts +0 -119
- package/dist/runtime/theme/alert.js +0 -47
- package/dist/runtime/theme/app.d.ts +0 -19
- package/dist/runtime/theme/app.js +0 -19
- package/dist/runtime/theme/avatar-group.d.ts +0 -46
- package/dist/runtime/theme/avatar-group.js +0 -32
- package/dist/runtime/theme/avatar.d.ts +0 -50
- package/dist/runtime/theme/avatar.js +0 -34
- package/dist/runtime/theme/badge.d.ts +0 -76
- package/dist/runtime/theme/badge.js +0 -92
- package/dist/runtime/theme/breadcrumb.d.ts +0 -61
- package/dist/runtime/theme/breadcrumb.js +0 -44
- package/dist/runtime/theme/button-group.d.ts +0 -60
- package/dist/runtime/theme/button-group.js +0 -42
- package/dist/runtime/theme/button.d.ts +0 -184
- package/dist/runtime/theme/button.js +0 -164
- package/dist/runtime/theme/calendar.d.ts +0 -58
- package/dist/runtime/theme/calendar.js +0 -86
- package/dist/runtime/theme/card.d.ts +0 -56
- package/dist/runtime/theme/card.js +0 -37
- package/dist/runtime/theme/carousel.d.ts +0 -107
- package/dist/runtime/theme/carousel.js +0 -43
- package/dist/runtime/theme/checkbox.d.ts +0 -82
- package/dist/runtime/theme/checkbox.js +0 -54
- package/dist/runtime/theme/chip.d.ts +0 -61
- package/dist/runtime/theme/chip.js +0 -66
- package/dist/runtime/theme/collapsible.d.ts +0 -32
- package/dist/runtime/theme/collapsible.js +0 -10
- package/dist/runtime/theme/drawer.d.ts +0 -142
- package/dist/runtime/theme/drawer.js +0 -113
- package/dist/runtime/theme/dropdown-menu.d.ts +0 -65
- package/dist/runtime/theme/dropdown-menu.js +0 -83
- package/dist/runtime/theme/form-item.d.ts +0 -70
- package/dist/runtime/theme/form-item.js +0 -34
- package/dist/runtime/theme/form.d.ts +0 -2
- package/dist/runtime/theme/form.js +0 -7
- package/dist/runtime/theme/index.d.ts +0 -41
- package/dist/runtime/theme/index.js +0 -41
- package/dist/runtime/theme/input-number.d.ts +0 -115
- package/dist/runtime/theme/input-number.js +0 -95
- package/dist/runtime/theme/input.d.ts +0 -172
- package/dist/runtime/theme/input.js +0 -151
- package/dist/runtime/theme/kbd.d.ts +0 -33
- package/dist/runtime/theme/kbd.js +0 -26
- package/dist/runtime/theme/link.d.ts +0 -38
- package/dist/runtime/theme/link.js +0 -26
- package/dist/runtime/theme/modal.d.ts +0 -42
- package/dist/runtime/theme/modal.js +0 -55
- package/dist/runtime/theme/pagination.d.ts +0 -74
- package/dist/runtime/theme/pagination.js +0 -17
- package/dist/runtime/theme/pinInput.d.ts +0 -94
- package/dist/runtime/theme/pinInput.js +0 -111
- package/dist/runtime/theme/popover.d.ts +0 -32
- package/dist/runtime/theme/popover.js +0 -13
- package/dist/runtime/theme/progress.d.ts +0 -180
- package/dist/runtime/theme/progress.js +0 -95
- package/dist/runtime/theme/radio-group.d.ts +0 -104
- package/dist/runtime/theme/radio-group.js +0 -61
- package/dist/runtime/theme/scroll-area.d.ts +0 -67
- package/dist/runtime/theme/scroll-area.js +0 -33
- package/dist/runtime/theme/select.d.ts +0 -186
- package/dist/runtime/theme/select.js +0 -173
- package/dist/runtime/theme/separator.d.ts +0 -74
- package/dist/runtime/theme/separator.js +0 -53
- package/dist/runtime/theme/skeleton.d.ts +0 -2
- package/dist/runtime/theme/skeleton.js +0 -7
- package/dist/runtime/theme/slider.d.ts +0 -70
- package/dist/runtime/theme/slider.js +0 -52
- package/dist/runtime/theme/switch.d.ts +0 -116
- package/dist/runtime/theme/switch.js +0 -78
- package/dist/runtime/theme/table.d.ts +0 -86
- package/dist/runtime/theme/table.js +0 -36
- package/dist/runtime/theme/tabs.d.ts +0 -129
- package/dist/runtime/theme/tabs.js +0 -146
- package/dist/runtime/theme/textarea.d.ts +0 -90
- package/dist/runtime/theme/textarea.js +0 -116
- package/dist/runtime/theme/toast-provider.d.ts +0 -116
- package/dist/runtime/theme/toast-provider.js +0 -97
- package/dist/runtime/theme/toast.d.ts +0 -83
- package/dist/runtime/theme/toast.js +0 -35
- package/dist/runtime/theme/tooltip.d.ts +0 -38
- package/dist/runtime/theme/tooltip.js +0 -11
- package/dist/runtime/types/components.d.ts +0 -42
- package/dist/runtime/utils/extend-theme.d.ts +0 -9
- package/dist/runtime/utils/extend-theme.js +0 -27
- package/dist/runtime/utils/styler.d.ts +0 -4
- package/dist/runtime/utils/styler.js +0 -10
- package/dist/runtime/utils/translator.d.ts +0 -18
- package/dist/runtime/utils/translator.js +0 -8
- package/dist/shared/ui.D1BTWZFB.mjs +0 -5
- package/dist/shared/ui.D1BTWZFB.mjs.map +0 -1
- package/dist/unocss.d.ts +0 -52
- package/dist/unocss.mjs.map +0 -1
- package/dist/unplugin.d.ts +0 -26
- package/dist/unplugin.mjs.map +0 -1
- package/dist/vite.d.ts +0 -9
- package/dist/vite.mjs.map +0 -1
- /package/dist/runtime/types/{components.js → input.js} +0 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { MaybeRef } from 'vue';
|
|
2
|
+
import type { Nullable } from '../types/utils';
|
|
3
|
+
type Handler = (e?: any) => void;
|
|
4
|
+
export interface ShortcutConfig {
|
|
5
|
+
handler: Handler;
|
|
6
|
+
usingInput?: string | boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface ShortcutsConfig {
|
|
9
|
+
[key: string]: Nullable<ShortcutConfig | Handler | false>;
|
|
10
|
+
}
|
|
11
|
+
export interface ShortcutsOptions {
|
|
12
|
+
chainDelay?: number;
|
|
13
|
+
}
|
|
14
|
+
export declare function extractShortcuts(items: any[] | any[][]): Record<string, Handler>;
|
|
15
|
+
export declare function defineShortcuts(config: MaybeRef<ShortcutsConfig>, options?: ShortcutsOptions): import("@vueuse/core").Fn;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { useActiveElement, useDebounceFn, useEventListener } from "@vueuse/core";
|
|
2
|
+
import { computed, ref, toValue } from "vue";
|
|
3
|
+
import { useKbd } from "./useKbd.js";
|
|
4
|
+
const chainedShortcutRegex = /^[^-]+.*-.*[^-]+$/;
|
|
5
|
+
const combinedShortcutRegex = /^[^_]+.*_.*[^_]+$/;
|
|
6
|
+
const shiftableKeys = /* @__PURE__ */ new Set(["arrowleft", "arrowright", "arrowup", "arrowright", "tab", "escape", "enter", "backspace"]);
|
|
7
|
+
export function extractShortcuts(items) {
|
|
8
|
+
const shortcuts = {};
|
|
9
|
+
function traverse(items2) {
|
|
10
|
+
items2.forEach((item) => {
|
|
11
|
+
if (item.kbds?.length && (item.onSelect || item.onClick)) {
|
|
12
|
+
const shortcutKey = item.kbds.join("_");
|
|
13
|
+
shortcuts[shortcutKey] = item.onSelect || item.onClick;
|
|
14
|
+
}
|
|
15
|
+
if (item.children)
|
|
16
|
+
traverse(item.children.flat());
|
|
17
|
+
if (item.items)
|
|
18
|
+
traverse(item.items.flat());
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
traverse(items.flat());
|
|
22
|
+
return shortcuts;
|
|
23
|
+
}
|
|
24
|
+
export function defineShortcuts(config, options = {}) {
|
|
25
|
+
const chainedInputs = ref([]);
|
|
26
|
+
const clearChainedInput = () => {
|
|
27
|
+
chainedInputs.value.splice(0, chainedInputs.value.length);
|
|
28
|
+
};
|
|
29
|
+
const debouncedClearChainedInput = useDebounceFn(clearChainedInput, options.chainDelay ?? 800);
|
|
30
|
+
const { macOS } = useKbd();
|
|
31
|
+
const activeElement = useActiveElement();
|
|
32
|
+
const usingInput = computed(() => {
|
|
33
|
+
const tagName = activeElement.value?.tagName;
|
|
34
|
+
const contentEditable = activeElement.value?.contentEditable;
|
|
35
|
+
const usingInput2 = !!(tagName === "INPUT" || tagName === "TEXTAREA" || contentEditable === "true" || contentEditable === "plaintext-only");
|
|
36
|
+
if (usingInput2)
|
|
37
|
+
return activeElement.value?.name || true;
|
|
38
|
+
return false;
|
|
39
|
+
});
|
|
40
|
+
const shortcuts = computed(() => {
|
|
41
|
+
return Object.entries(toValue(config)).map(([key, shortcutConfig]) => {
|
|
42
|
+
if (!shortcutConfig)
|
|
43
|
+
return null;
|
|
44
|
+
let shortcut;
|
|
45
|
+
if (key.includes("-") && key !== "-" && !key.includes("_") && !key.match(chainedShortcutRegex)?.length)
|
|
46
|
+
console.trace(`[Shortcut] Invalid key: "${key}"`);
|
|
47
|
+
if (key.includes("_") && key !== "_" && !key.match(combinedShortcutRegex)?.length)
|
|
48
|
+
console.trace(`[Shortcut] Invalid key: "${key}"`);
|
|
49
|
+
const chained = key.includes("-") && key !== "-" && !key.includes("_");
|
|
50
|
+
if (chained) {
|
|
51
|
+
shortcut = {
|
|
52
|
+
key: key.toLowerCase(),
|
|
53
|
+
metaKey: false,
|
|
54
|
+
ctrlKey: false,
|
|
55
|
+
shiftKey: false,
|
|
56
|
+
altKey: false
|
|
57
|
+
};
|
|
58
|
+
} else {
|
|
59
|
+
const keySplit = key.toLowerCase().split("_").map((k) => k);
|
|
60
|
+
shortcut = {
|
|
61
|
+
key: keySplit.filter((k) => !["meta", "command", "ctrl", "shift", "alt", "option"].includes(k)).join("_"),
|
|
62
|
+
metaKey: keySplit.includes("meta") || keySplit.includes("command"),
|
|
63
|
+
ctrlKey: keySplit.includes("ctrl"),
|
|
64
|
+
shiftKey: keySplit.includes("shift"),
|
|
65
|
+
altKey: keySplit.includes("alt") || keySplit.includes("option")
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
shortcut.chained = chained;
|
|
69
|
+
if (!macOS.value && shortcut.metaKey && !shortcut.ctrlKey) {
|
|
70
|
+
shortcut.metaKey = false;
|
|
71
|
+
shortcut.ctrlKey = true;
|
|
72
|
+
}
|
|
73
|
+
if (typeof shortcutConfig === "function")
|
|
74
|
+
shortcut.handler = shortcutConfig;
|
|
75
|
+
else if (typeof shortcutConfig === "object")
|
|
76
|
+
shortcut = { ...shortcut, handler: shortcutConfig.handler };
|
|
77
|
+
if (!shortcut.handler) {
|
|
78
|
+
console.trace("[Shortcut] Invalid value");
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
let enabled = true;
|
|
82
|
+
if (!shortcutConfig.usingInput)
|
|
83
|
+
enabled = !usingInput.value;
|
|
84
|
+
else if (typeof shortcutConfig.usingInput === "string")
|
|
85
|
+
enabled = usingInput.value === shortcutConfig.usingInput;
|
|
86
|
+
shortcut.enabled = enabled;
|
|
87
|
+
return shortcut;
|
|
88
|
+
}).filter(Boolean);
|
|
89
|
+
});
|
|
90
|
+
const onKeyDown = (e) => {
|
|
91
|
+
if (!e.key)
|
|
92
|
+
return;
|
|
93
|
+
const alphabetKey = /^[a-z]{1}$/i.test(e.key);
|
|
94
|
+
const shiftableKey = shiftableKeys.has(e.key.toLowerCase());
|
|
95
|
+
let chainedKey;
|
|
96
|
+
chainedInputs.value.push(e.key);
|
|
97
|
+
if (chainedInputs.value.length >= 2) {
|
|
98
|
+
chainedKey = chainedInputs.value.slice(-2).join("-");
|
|
99
|
+
for (const shortcut of shortcuts.value.filter((s) => s.chained)) {
|
|
100
|
+
if (shortcut.key !== chainedKey)
|
|
101
|
+
continue;
|
|
102
|
+
if (shortcut.enabled) {
|
|
103
|
+
e.preventDefault();
|
|
104
|
+
shortcut.handler(e);
|
|
105
|
+
}
|
|
106
|
+
clearChainedInput();
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
for (const shortcut of shortcuts.value.filter((s) => !s.chained)) {
|
|
111
|
+
if (e.key.toLowerCase() !== shortcut.key)
|
|
112
|
+
continue;
|
|
113
|
+
if (e.metaKey !== shortcut.metaKey)
|
|
114
|
+
continue;
|
|
115
|
+
if (e.ctrlKey !== shortcut.ctrlKey)
|
|
116
|
+
continue;
|
|
117
|
+
if ((alphabetKey || shiftableKey) && e.shiftKey !== shortcut.shiftKey)
|
|
118
|
+
continue;
|
|
119
|
+
if (shortcut.enabled) {
|
|
120
|
+
e.preventDefault();
|
|
121
|
+
shortcut.handler(e);
|
|
122
|
+
}
|
|
123
|
+
clearChainedInput();
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
debouncedClearChainedInput();
|
|
127
|
+
};
|
|
128
|
+
return useEventListener("keydown", onKeyDown);
|
|
129
|
+
}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type { ComputedRef } from 'vue';
|
|
2
|
+
import type { AvatarGroupProps } from '../types';
|
|
3
|
+
export type AvatarGroupProvideValue = Pick<AvatarGroupProps, 'size'>;
|
|
4
|
+
export declare const InjectionKeyAvatarGroup: import("vue").InjectionKey<ComputedRef<AvatarGroupProvideValue>>, injectAvatarGroup: () => ComputedRef<AvatarGroupProvideValue> | undefined, provideAvatarGroup: (value: ComputedRef<AvatarGroupProvideValue>) => void;
|
|
5
|
+
export declare function useAvatarGroup(props: {
|
|
6
|
+
size: AvatarGroupProps['size'];
|
|
7
|
+
}): {
|
|
8
|
+
size: ComputedRef<"2xl" | "3xs" | "2xs" | "xs" | "sm" | "md" | "lg" | "xl" | "3xl" | undefined>;
|
|
4
9
|
};
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import { computed } from "vue";
|
|
2
|
-
import {
|
|
3
|
-
export
|
|
2
|
+
import { defineInjection } from "../utils/index.js";
|
|
3
|
+
export const {
|
|
4
|
+
InjectionKey: InjectionKeyAvatarGroup,
|
|
5
|
+
inject: injectAvatarGroup,
|
|
6
|
+
provide: provideAvatarGroup
|
|
7
|
+
} = defineInjection("ui.avatar-group");
|
|
8
|
+
export function useAvatarGroup(props) {
|
|
4
9
|
const avatarGroup = injectAvatarGroup();
|
|
10
|
+
const size = computed(() => props.size ?? avatarGroup?.value.size);
|
|
11
|
+
provideAvatarGroup(computed(() => ({ size: size.value })));
|
|
5
12
|
return {
|
|
6
|
-
size
|
|
13
|
+
size
|
|
7
14
|
};
|
|
8
15
|
}
|
|
@@ -1,26 +1,29 @@
|
|
|
1
1
|
import { type MaybeRefOrGetter } from 'vue';
|
|
2
|
+
import type { AvatarProps, IconProps } from '../types';
|
|
2
3
|
export interface UseComponentIconsProps {
|
|
3
4
|
/** Display an icon based on the `leading` and `trailing` props. */
|
|
4
|
-
icon?:
|
|
5
|
+
icon?: IconProps['name'];
|
|
6
|
+
/** Display an avatar on the left side. */
|
|
7
|
+
avatar?: AvatarProps;
|
|
5
8
|
/** When `true`, the icon will be displayed on the left side. */
|
|
6
9
|
leading?: boolean;
|
|
7
10
|
/** Display an icon on the left side. */
|
|
8
|
-
leadingIcon?:
|
|
11
|
+
leadingIcon?: IconProps['name'];
|
|
9
12
|
/** When `true`, the icon will be displayed on the right side. */
|
|
10
13
|
trailing?: boolean;
|
|
11
14
|
/** Display an icon on the right side. */
|
|
12
|
-
trailingIcon?:
|
|
15
|
+
trailingIcon?: IconProps['name'];
|
|
13
16
|
/** When `true`, the loading icon will be displayed. */
|
|
14
17
|
loading?: boolean;
|
|
15
18
|
/**
|
|
16
19
|
* The icon when the `loading` prop is `true`.
|
|
17
20
|
* @default app.icons.loading
|
|
18
21
|
*/
|
|
19
|
-
loadingIcon?:
|
|
22
|
+
loadingIcon?: IconProps['name'];
|
|
20
23
|
}
|
|
21
24
|
export declare function useComponentIcons(componentProps: MaybeRefOrGetter<UseComponentIconsProps>): {
|
|
22
25
|
isLeading: import("vue").ComputedRef<boolean>;
|
|
23
26
|
isTrailing: import("vue").ComputedRef<boolean>;
|
|
24
|
-
leadingIconName: import("vue").ComputedRef<
|
|
25
|
-
trailingIconName: import("vue").ComputedRef<
|
|
27
|
+
leadingIconName: import("vue").ComputedRef<any>;
|
|
28
|
+
trailingIconName: import("vue").ComputedRef<any>;
|
|
26
29
|
};
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { computed, toValue } from "vue";
|
|
2
|
-
import {
|
|
2
|
+
import { useAppConfig } from "#imports";
|
|
3
3
|
export function useComponentIcons(componentProps) {
|
|
4
|
-
const
|
|
4
|
+
const appConfig = useAppConfig();
|
|
5
5
|
const props = computed(() => toValue(componentProps));
|
|
6
6
|
const isLeading = computed(() => props.value.icon && props.value.leading || props.value.icon && !props.value.trailing || props.value.loading && !props.value.trailing || !!props.value.leadingIcon);
|
|
7
7
|
const isTrailing = computed(() => props.value.icon && props.value.trailing || props.value.loading && props.value.trailing || !!props.value.trailingIcon);
|
|
8
8
|
const leadingIconName = computed(() => {
|
|
9
9
|
if (props.value.loading)
|
|
10
|
-
return props.value.loadingIcon ||
|
|
10
|
+
return props.value.loadingIcon || appConfig.ui.icons.loading;
|
|
11
11
|
return props.value.leadingIcon || props.value.icon;
|
|
12
12
|
});
|
|
13
13
|
const trailingIconName = computed(() => {
|
|
14
14
|
if (props.value.loading && !isLeading.value)
|
|
15
|
-
return props.value.loadingIcon ||
|
|
15
|
+
return props.value.loadingIcon || appConfig.ui.icons.loading;
|
|
16
16
|
return props.value.trailingIcon || props.value.icon;
|
|
17
17
|
});
|
|
18
18
|
return {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ComputedRef } from 'vue';
|
|
2
|
+
import type { ButtonProps, FieldGroupProps } from '../types';
|
|
3
|
+
export type FieldGroupProvideValue = Pick<FieldGroupProps, 'size' | 'orientation'>;
|
|
4
|
+
export declare const InjectionKeyFieldGroup: import("vue").InjectionKey<ComputedRef<FieldGroupProvideValue>>, injectFieldGroup: () => ComputedRef<FieldGroupProvideValue> | undefined, provideFieldGroup: (value: ComputedRef<FieldGroupProvideValue>) => void;
|
|
5
|
+
export declare function useFieldGroup(props?: Pick<ButtonProps, 'size'>): {
|
|
6
|
+
size: ComputedRef<"xs" | "sm" | "md" | "lg" | "xl" | undefined>;
|
|
7
|
+
orientation: ComputedRef<"horizontal" | "vertical" | undefined>;
|
|
8
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { computed } from "vue";
|
|
2
|
+
import { defineInjection } from "../utils/index.js";
|
|
3
|
+
export const {
|
|
4
|
+
InjectionKey: InjectionKeyFieldGroup,
|
|
5
|
+
inject: injectFieldGroup,
|
|
6
|
+
provide: provideFieldGroup
|
|
7
|
+
} = defineInjection("ui.field-group");
|
|
8
|
+
export function useFieldGroup(props = {}) {
|
|
9
|
+
const fieldGroup = injectFieldGroup();
|
|
10
|
+
return {
|
|
11
|
+
size: computed(() => props.size ?? fieldGroup?.value.size),
|
|
12
|
+
orientation: computed(() => fieldGroup?.value.orientation)
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { UseEventBusReturn } from '@vueuse/core';
|
|
2
|
+
import type { ComputedRef, Ref } from 'vue';
|
|
3
|
+
import type { FormErrorWithId, FormEvent, FormFieldProps } from '../types';
|
|
4
|
+
import type { GetObjectField, MaybeNull } from '../types/utils';
|
|
5
|
+
export interface FormOptionsProvideValue {
|
|
6
|
+
disabled: boolean;
|
|
7
|
+
validateOnInputDelay: number;
|
|
8
|
+
}
|
|
9
|
+
export declare const InjectionKeyFormOptions: import("vue").InjectionKey<ComputedRef<FormOptionsProvideValue>>, injectFormOptions: () => ComputedRef<FormOptionsProvideValue> | undefined, provideFormOptions: (value: ComputedRef<FormOptionsProvideValue>) => void;
|
|
10
|
+
export type FormBusProvideValue = UseEventBusReturn<FormEvent<any>, string>;
|
|
11
|
+
export declare const InjectionKeyFormBus: import("vue").InjectionKey<FormBusProvideValue>, injectFormBus: () => FormBusProvideValue | undefined, provideFormBus: (value: FormBusProvideValue) => void;
|
|
12
|
+
export type FormStateProvideValue = Record<string, any>;
|
|
13
|
+
export declare const InjectionKeyFormState: import("vue").InjectionKey<ComputedRef<FormStateProvideValue>>, injectFormState: () => ComputedRef<FormStateProvideValue> | undefined, provideFormState: (value: ComputedRef<FormStateProvideValue>) => void;
|
|
14
|
+
export interface FormFieldProvideValue<T> {
|
|
15
|
+
name?: string;
|
|
16
|
+
size?: GetObjectField<T, 'size'>;
|
|
17
|
+
error?: string | boolean;
|
|
18
|
+
eagerValidation?: boolean;
|
|
19
|
+
validateOnInputDelay?: number;
|
|
20
|
+
errorPattern?: RegExp;
|
|
21
|
+
hint?: string;
|
|
22
|
+
help?: string;
|
|
23
|
+
description?: string;
|
|
24
|
+
ariaId: string;
|
|
25
|
+
}
|
|
26
|
+
export declare const InjectionKeyFormField: import("vue").InjectionKey<ComputedRef<FormFieldProvideValue<FormFieldProps>>>, injectFormField: () => ComputedRef<FormFieldProvideValue<FormFieldProps>> | undefined, provideFormField: (value: ComputedRef<FormFieldProvideValue<FormFieldProps>>) => void;
|
|
27
|
+
export declare const InjectionKeyFormInputId: import("vue").InjectionKey<Ref<string | undefined, string | undefined>>, injectFormInputId: () => Ref<string | undefined, string | undefined> | undefined, provideFormInputId: (value: Ref<string | undefined, string | undefined>) => void;
|
|
28
|
+
export type FormInputsProvideValue = Record<string, {
|
|
29
|
+
id?: string;
|
|
30
|
+
pattern?: RegExp;
|
|
31
|
+
}>;
|
|
32
|
+
export declare const InjectionKeyFormInputs: import("vue").InjectionKey<Ref<FormInputsProvideValue, FormInputsProvideValue>>, injectFormInputs: () => Ref<FormInputsProvideValue, FormInputsProvideValue> | undefined, provideFormInputs: (value: Ref<FormInputsProvideValue, FormInputsProvideValue>) => void;
|
|
33
|
+
export declare const InjectionKeyFormLoading: import("vue").InjectionKey<Readonly<Ref<boolean, boolean>>>, injectFormLoading: () => Readonly<Ref<boolean, boolean>> | undefined, provideFormLoading: (value: Readonly<Ref<boolean, boolean>>) => void;
|
|
34
|
+
export declare const InjectionKeyFormErrors: import("vue").InjectionKey<MaybeNull<Ref<FormErrorWithId[], FormErrorWithId[]>>>, injectFormErrors: () => MaybeNull<Ref<FormErrorWithId[], FormErrorWithId[]>>, provideFormErrors: (value: MaybeNull<Ref<FormErrorWithId[], FormErrorWithId[]>>) => void;
|
|
35
|
+
interface Props<T> {
|
|
36
|
+
id?: string;
|
|
37
|
+
name?: string;
|
|
38
|
+
size?: GetObjectField<T, 'size'>;
|
|
39
|
+
color?: GetObjectField<T, 'color'>;
|
|
40
|
+
highlight?: boolean;
|
|
41
|
+
disabled?: boolean;
|
|
42
|
+
}
|
|
43
|
+
export declare function useFormField<T>(props?: Props<T>, options?: {
|
|
44
|
+
bind?: boolean;
|
|
45
|
+
deferInputValidation?: boolean;
|
|
46
|
+
}): {
|
|
47
|
+
id: ComputedRef<string | undefined>;
|
|
48
|
+
name: ComputedRef<string | undefined>;
|
|
49
|
+
size: ComputedRef<"xs" | "sm" | "md" | "lg" | "xl" | NonNullable<GetObjectField<T, "size">> | undefined>;
|
|
50
|
+
color: ComputedRef<"error" | GetObjectField<T, "color"> | undefined>;
|
|
51
|
+
highlight: ComputedRef<boolean | undefined>;
|
|
52
|
+
disabled: ComputedRef<boolean | undefined>;
|
|
53
|
+
emitFormBlur: () => void;
|
|
54
|
+
emitFormInput: import("@vueuse/core").UseDebounceFnReturn<() => void>;
|
|
55
|
+
emitFormChange: () => void;
|
|
56
|
+
emitFormFocus: () => void;
|
|
57
|
+
ariaAttrs: ComputedRef<{
|
|
58
|
+
'aria-describedby': string;
|
|
59
|
+
'aria-invalid': boolean;
|
|
60
|
+
} | undefined>;
|
|
61
|
+
};
|
|
62
|
+
export {};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { useDebounceFn } from "@vueuse/core";
|
|
2
|
+
import { computed } from "vue";
|
|
3
|
+
import { defineInjection } from "../utils/index.js";
|
|
4
|
+
export const {
|
|
5
|
+
InjectionKey: InjectionKeyFormOptions,
|
|
6
|
+
inject: injectFormOptions,
|
|
7
|
+
provide: provideFormOptions
|
|
8
|
+
} = defineInjection("ui.form-options");
|
|
9
|
+
export const {
|
|
10
|
+
InjectionKey: InjectionKeyFormBus,
|
|
11
|
+
inject: injectFormBus,
|
|
12
|
+
provide: provideFormBus
|
|
13
|
+
} = defineInjection("ui.form-bus");
|
|
14
|
+
export const {
|
|
15
|
+
InjectionKey: InjectionKeyFormState,
|
|
16
|
+
inject: injectFormState,
|
|
17
|
+
provide: provideFormState
|
|
18
|
+
} = defineInjection("ui.form-state");
|
|
19
|
+
export const {
|
|
20
|
+
InjectionKey: InjectionKeyFormField,
|
|
21
|
+
inject: injectFormField,
|
|
22
|
+
provide: provideFormField
|
|
23
|
+
} = defineInjection("ui.form-field");
|
|
24
|
+
export const {
|
|
25
|
+
InjectionKey: InjectionKeyFormInputId,
|
|
26
|
+
inject: injectFormInputId,
|
|
27
|
+
provide: provideFormInputId
|
|
28
|
+
} = defineInjection("ui.form-input-id");
|
|
29
|
+
export const {
|
|
30
|
+
InjectionKey: InjectionKeyFormInputs,
|
|
31
|
+
inject: injectFormInputs,
|
|
32
|
+
provide: provideFormInputs
|
|
33
|
+
} = defineInjection("ui.form-inputs");
|
|
34
|
+
export const {
|
|
35
|
+
InjectionKey: InjectionKeyFormLoading,
|
|
36
|
+
inject: injectFormLoading,
|
|
37
|
+
provide: provideFormLoading
|
|
38
|
+
} = defineInjection("ui.form-loading");
|
|
39
|
+
export const {
|
|
40
|
+
InjectionKey: InjectionKeyFormErrors,
|
|
41
|
+
inject: injectFormErrors,
|
|
42
|
+
provide: provideFormErrors
|
|
43
|
+
} = defineInjection("ui.form-errors", null);
|
|
44
|
+
export function useFormField(props, options) {
|
|
45
|
+
const formOptions = injectFormOptions();
|
|
46
|
+
const formBus = injectFormBus();
|
|
47
|
+
const formField = injectFormField();
|
|
48
|
+
const formInputs = injectFormInputs();
|
|
49
|
+
const inputId = injectFormInputId();
|
|
50
|
+
if (formField && inputId) {
|
|
51
|
+
if (options?.bind === false) {
|
|
52
|
+
inputId.value = void 0;
|
|
53
|
+
} else if (props?.id) {
|
|
54
|
+
inputId.value = props?.id;
|
|
55
|
+
}
|
|
56
|
+
if (formInputs && formField.value.name && inputId.value)
|
|
57
|
+
formInputs.value[formField.value.name] = { id: inputId.value, pattern: formField.value.errorPattern };
|
|
58
|
+
}
|
|
59
|
+
function emitFormEvent(type, name, eager) {
|
|
60
|
+
if (formBus && formField && name)
|
|
61
|
+
formBus.emit({ type, name, eager });
|
|
62
|
+
}
|
|
63
|
+
function emitFormBlur() {
|
|
64
|
+
emitFormEvent("blur", formField?.value.name);
|
|
65
|
+
}
|
|
66
|
+
function emitFormFocus() {
|
|
67
|
+
emitFormEvent("focus", formField?.value.name);
|
|
68
|
+
}
|
|
69
|
+
function emitFormChange() {
|
|
70
|
+
emitFormEvent("change", formField?.value.name);
|
|
71
|
+
}
|
|
72
|
+
const emitFormInput = useDebounceFn(
|
|
73
|
+
() => {
|
|
74
|
+
emitFormEvent("input", formField?.value.name, !options?.deferInputValidation || formField?.value.eagerValidation);
|
|
75
|
+
},
|
|
76
|
+
formField?.value.validateOnInputDelay ?? formOptions?.value.validateOnInputDelay ?? 0
|
|
77
|
+
);
|
|
78
|
+
return {
|
|
79
|
+
id: computed(() => props?.id ?? inputId?.value),
|
|
80
|
+
name: computed(() => props?.name ?? formField?.value.name),
|
|
81
|
+
size: computed(() => props?.size ?? formField?.value.size),
|
|
82
|
+
color: computed(() => formField?.value.error ? "error" : props?.color),
|
|
83
|
+
highlight: computed(() => formField?.value.error ? true : props?.highlight),
|
|
84
|
+
disabled: computed(() => formOptions?.value.disabled || props?.disabled),
|
|
85
|
+
emitFormBlur,
|
|
86
|
+
emitFormInput,
|
|
87
|
+
emitFormChange,
|
|
88
|
+
emitFormFocus,
|
|
89
|
+
ariaAttrs: computed(() => {
|
|
90
|
+
if (!formField?.value)
|
|
91
|
+
return;
|
|
92
|
+
const descriptiveAttrs = ["error", "hint", "help", "description"].filter((type) => formField?.value?.[type]).map((type) => `${formField?.value.ariaId}-${type}`) || [];
|
|
93
|
+
return {
|
|
94
|
+
"aria-describedby": descriptiveAttrs.join(" "),
|
|
95
|
+
"aria-invalid": !!formField?.value.error
|
|
96
|
+
};
|
|
97
|
+
})
|
|
98
|
+
};
|
|
99
|
+
}
|
|
@@ -28,8 +28,9 @@ export declare const kbdKeysMap: {
|
|
|
28
28
|
};
|
|
29
29
|
export type KbdKey = keyof typeof kbdKeysMap;
|
|
30
30
|
export type KbdKeySpecific = keyof KbdKeysSpecificMap;
|
|
31
|
-
|
|
32
|
-
macOS: import("vue").ComputedRef<
|
|
31
|
+
declare function _useKbd(): {
|
|
32
|
+
macOS: import("vue").ComputedRef<false | "" | RegExpMatchArray | null>;
|
|
33
33
|
getKbdKey: (value?: KbdKey | (string & {})) => string | undefined;
|
|
34
34
|
};
|
|
35
|
+
export declare const useKbd: typeof _useKbd;
|
|
35
36
|
export {};
|
|
@@ -23,7 +23,7 @@ export const kbdKeysMap = {
|
|
|
23
23
|
home: "\u2196",
|
|
24
24
|
end: "\u2198"
|
|
25
25
|
};
|
|
26
|
-
|
|
26
|
+
function _useKbd() {
|
|
27
27
|
const macOS = computed(() => import.meta.client && navigator && navigator.userAgent && navigator.userAgent.match(/Macintosh;/));
|
|
28
28
|
const kbdKeysSpecificMap = reactive({
|
|
29
29
|
meta: " ",
|
|
@@ -46,4 +46,5 @@ export const useKbd = createSharedComposable(() => {
|
|
|
46
46
|
macOS,
|
|
47
47
|
getKbdKey
|
|
48
48
|
};
|
|
49
|
-
}
|
|
49
|
+
}
|
|
50
|
+
export const useKbd = /* @__PURE__ */ createSharedComposable(_useKbd);
|
|
@@ -1,8 +1,71 @@
|
|
|
1
|
-
import type { Translator } from '
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type { Translator } from '@byyuurin/ui-kit';
|
|
2
|
+
import type { MaybeRefOrGetter } from 'vue';
|
|
3
|
+
import type { Messages } from '../types';
|
|
4
|
+
export declare const InjectionKeyLocaleContext: import("vue").InjectionKey<MaybeRefOrGetter<Required<import("@byyuurin/ui-kit").Locale<Messages>> | undefined>>, injectLocaleContext: () => MaybeRefOrGetter<Required<import("@byyuurin/ui-kit").Locale<Messages>> | undefined>, provideLocaleContext: (value: MaybeRefOrGetter<Required<import("@byyuurin/ui-kit").Locale<Messages>> | undefined>) => void;
|
|
5
|
+
declare function _useLocale(): {
|
|
6
|
+
locale: import("vue").ComputedRef<Required<import("@byyuurin/ui-kit").Locale<{
|
|
7
|
+
alert: {
|
|
8
|
+
close: string;
|
|
9
|
+
};
|
|
10
|
+
calendar: {
|
|
11
|
+
prevYear: string;
|
|
12
|
+
nextYear: string;
|
|
13
|
+
prevMonth: string;
|
|
14
|
+
nextMonth: string;
|
|
15
|
+
};
|
|
16
|
+
carousel: {
|
|
17
|
+
dots: string;
|
|
18
|
+
prev: string;
|
|
19
|
+
next: string;
|
|
20
|
+
goto: string;
|
|
21
|
+
};
|
|
22
|
+
inputNumber: {
|
|
23
|
+
increment: string;
|
|
24
|
+
decrement: string;
|
|
25
|
+
};
|
|
26
|
+
modal: {
|
|
27
|
+
close: string;
|
|
28
|
+
};
|
|
29
|
+
table: {
|
|
30
|
+
noData: string;
|
|
31
|
+
};
|
|
32
|
+
toast: {
|
|
33
|
+
close: string;
|
|
34
|
+
};
|
|
35
|
+
}>>>;
|
|
4
36
|
lang: import("vue").ComputedRef<string>;
|
|
5
37
|
code: import("vue").ComputedRef<string>;
|
|
6
|
-
dir: import("vue").ComputedRef<import("
|
|
7
|
-
t: Translator<
|
|
38
|
+
dir: import("vue").ComputedRef<import("@byyuurin/ui-kit").LocaleDirection>;
|
|
39
|
+
t: Translator<{
|
|
40
|
+
alert: {
|
|
41
|
+
close: string;
|
|
42
|
+
};
|
|
43
|
+
calendar: {
|
|
44
|
+
prevYear: string;
|
|
45
|
+
nextYear: string;
|
|
46
|
+
prevMonth: string;
|
|
47
|
+
nextMonth: string;
|
|
48
|
+
};
|
|
49
|
+
carousel: {
|
|
50
|
+
dots: string;
|
|
51
|
+
prev: string;
|
|
52
|
+
next: string;
|
|
53
|
+
goto: string;
|
|
54
|
+
};
|
|
55
|
+
inputNumber: {
|
|
56
|
+
increment: string;
|
|
57
|
+
decrement: string;
|
|
58
|
+
};
|
|
59
|
+
modal: {
|
|
60
|
+
close: string;
|
|
61
|
+
};
|
|
62
|
+
table: {
|
|
63
|
+
noData: string;
|
|
64
|
+
};
|
|
65
|
+
toast: {
|
|
66
|
+
close: string;
|
|
67
|
+
};
|
|
68
|
+
}>;
|
|
8
69
|
};
|
|
70
|
+
export declare const useLocale: typeof _useLocale;
|
|
71
|
+
export {};
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { createSharedComposable } from "@vueuse/core";
|
|
2
2
|
import { computed, toValue } from "vue";
|
|
3
|
-
import { injectLocaleContext } from "../app/injections.js";
|
|
4
3
|
import localeDefault from "../locale/en.js";
|
|
5
|
-
import {
|
|
6
|
-
|
|
4
|
+
import { defineInjection } from "../utils/index.js";
|
|
5
|
+
import { createTranslator } from "../utils/locale.js";
|
|
6
|
+
export const {
|
|
7
|
+
InjectionKey: InjectionKeyLocaleContext,
|
|
8
|
+
inject: injectLocaleContext,
|
|
9
|
+
provide: provideLocaleContext
|
|
10
|
+
} = defineInjection("ui.locale-context");
|
|
11
|
+
function _useLocale() {
|
|
7
12
|
const _locale = injectLocaleContext();
|
|
8
13
|
const locale = computed(() => toValue(_locale) ?? localeDefault);
|
|
9
14
|
const lang = computed(() => locale.value.name);
|
|
@@ -12,11 +17,6 @@ export const useLocale = createSharedComposable(() => {
|
|
|
12
17
|
const t = (path, options) => {
|
|
13
18
|
return createTranslator(toValue(locale))(path, options);
|
|
14
19
|
};
|
|
15
|
-
return {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
code,
|
|
19
|
-
dir,
|
|
20
|
-
t
|
|
21
|
-
};
|
|
22
|
-
});
|
|
20
|
+
return { locale, lang, code, dir, t };
|
|
21
|
+
}
|
|
22
|
+
export const useLocale = import.meta.client ? createSharedComposable(_useLocale) : _useLocale;
|
|
@@ -1,29 +1,65 @@
|
|
|
1
1
|
import type { Component } from 'vue';
|
|
2
|
-
import type { ComponentProps } from 'vue-component-type-helpers';
|
|
2
|
+
import type { ComponentEmit, ComponentProps } from 'vue-component-type-helpers';
|
|
3
|
+
/**
|
|
4
|
+
* This is a workaround for a design limitation in TypeScript.
|
|
5
|
+
*
|
|
6
|
+
* Conditional types only match the last function overload, not a union of all possible
|
|
7
|
+
* parameter types. This workaround forces TypeScript to properly extract the 'close'
|
|
8
|
+
* event argument type from component emits with multiple event signatures.
|
|
9
|
+
*
|
|
10
|
+
* @see https://github.com/microsoft/TypeScript/issues/32164
|
|
11
|
+
*/
|
|
12
|
+
type CloseEventArgType<T> = T extends {
|
|
13
|
+
(event: 'close', arg_0: infer Arg, ...args: any[]): void;
|
|
14
|
+
(...args: any[]): void;
|
|
15
|
+
(...args: any[]): void;
|
|
16
|
+
(...args: any[]): void;
|
|
17
|
+
(...args: any[]): void;
|
|
18
|
+
(...args: any[]): void;
|
|
19
|
+
(...args: any[]): void;
|
|
20
|
+
(...args: any[]): void;
|
|
21
|
+
(...args: any[]): void;
|
|
22
|
+
(...args: any[]): void;
|
|
23
|
+
(...args: any[]): void;
|
|
24
|
+
(...args: any[]): void;
|
|
25
|
+
(...args: any[]): void;
|
|
26
|
+
(...args: any[]): void;
|
|
27
|
+
(...args: any[]): void;
|
|
28
|
+
(...args: any[]): void;
|
|
29
|
+
(...args: any[]): void;
|
|
30
|
+
} ? Arg : never;
|
|
3
31
|
export interface OverlayOptions<ComponentProps = Record<string, any>> {
|
|
4
32
|
defaultOpen?: boolean;
|
|
5
33
|
props?: ComponentProps;
|
|
6
34
|
unmountOnHide?: boolean;
|
|
7
35
|
}
|
|
8
|
-
interface
|
|
36
|
+
interface OverlayOptionsPrivate<T extends Component> {
|
|
9
37
|
component?: T;
|
|
10
|
-
id:
|
|
38
|
+
id: symbol;
|
|
11
39
|
isMounted: boolean;
|
|
12
|
-
|
|
13
|
-
|
|
40
|
+
isOpen: boolean;
|
|
41
|
+
originalProps?: ComponentProps<T>;
|
|
42
|
+
resolvePromise?: (value: unknown) => void;
|
|
14
43
|
}
|
|
15
|
-
export type
|
|
16
|
-
|
|
17
|
-
|
|
44
|
+
export type Overlay = OverlayOptions<Component> & OverlayOptionsPrivate<Component>;
|
|
45
|
+
type OpenedOverlay<T extends Component> = Omit<OverlayInstance<T>, 'open' | 'close' | 'patch' | 'modelValue' | 'resolvePromise'> & {
|
|
46
|
+
result: Promise<CloseEventArgType<ComponentEmit<T>>>;
|
|
47
|
+
} & Promise<CloseEventArgType<ComponentEmit<T>>>;
|
|
48
|
+
export interface OverlayInstance<T extends Component> {
|
|
49
|
+
id: symbol;
|
|
50
|
+
open: (props?: ComponentProps<T>) => OpenedOverlay<T>;
|
|
18
51
|
close: (value?: any) => void;
|
|
19
52
|
patch: (props: Partial<ComponentProps<T>>) => void;
|
|
20
53
|
}
|
|
21
|
-
|
|
22
|
-
overlays: import("vue").ShallowReactive<
|
|
23
|
-
open: <T extends Component>(id:
|
|
24
|
-
close: (id:
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
54
|
+
declare function _useOverlay(): {
|
|
55
|
+
overlays: import("vue").ShallowReactive<Overlay[]>;
|
|
56
|
+
open: <T extends Component>(id: Overlay["id"], props?: ComponentProps<T>) => OpenedOverlay<T>;
|
|
57
|
+
close: (id: symbol, value?: any) => void;
|
|
58
|
+
closeAll: () => void;
|
|
59
|
+
create: <T extends Component>(component: T, options?: OverlayOptions<ComponentProps<T>>) => OverlayInstance<T>;
|
|
60
|
+
patch: <T extends Component>(id: symbol, props: Partial<ComponentProps<T>>) => void;
|
|
61
|
+
unmount: (id: symbol) => void;
|
|
62
|
+
isOpen: (id: symbol) => boolean;
|
|
28
63
|
};
|
|
64
|
+
export declare const useOverlay: typeof _useOverlay;
|
|
29
65
|
export {};
|