vueless 0.0.479 → 0.0.480
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/adatper.locale/vue-i18n.ts +14 -0
- package/adatper.locale/{vueless.js → vueless.ts} +67 -19
- package/composables/useAutoPosition.ts +113 -0
- package/composables/useBreakpoint.ts +109 -0
- package/composables/useLocale.ts +22 -0
- package/composables/useMutationObserver.ts +53 -0
- package/composables/{useUI.js → useUI.ts} +109 -105
- package/constants.js +124 -2
- package/directives/clickOutside/storybook/Docs.mdx +1 -1
- package/directives/clickOutside/storybook/{stories.js → stories.ts} +7 -9
- package/directives/clickOutside/types.ts +22 -0
- package/directives/clickOutside/vClickOutside.ts +96 -0
- package/directives/index.js +7 -2
- package/directives/tooltip/storybook/Docs.mdx +1 -1
- package/directives/tooltip/storybook/{stories.js → stories.ts} +22 -10
- package/directives/tooltip/types.ts +14 -0
- package/directives/tooltip/vTooltip.ts +82 -0
- package/{index.js → index.ts} +12 -9
- package/package.json +38 -25
- package/plugin-vite.d.ts +10 -0
- package/plugin-vite.js +97 -0
- package/{preset.tailwind.js → preset-tailwind.js} +21 -7
- package/types.ts +322 -0
- package/ui.button/UButton.vue +1 -1
- package/ui.button/storybook/Docs.mdx +1 -1
- package/ui.button/storybook/stories.js +11 -6
- package/ui.button/useAttrs.js +1 -1
- package/ui.button-link/ULink.vue +2 -2
- package/ui.button-link/storybook/Docs.mdx +1 -1
- package/ui.button-link/storybook/stories.js +2 -2
- package/ui.button-link/useAttrs.js +1 -1
- package/ui.button-toggle/UToggle.vue +1 -1
- package/ui.button-toggle/storybook/Docs.mdx +1 -1
- package/ui.button-toggle/storybook/stories.js +2 -2
- package/ui.button-toggle/useAttrs.js +1 -1
- package/ui.button-toggle-item/UToggleItem.vue +1 -1
- package/ui.button-toggle-item/storybook/Docs.mdx +1 -1
- package/ui.button-toggle-item/storybook/stories.js +1 -1
- package/ui.button-toggle-item/useAttrs.js +1 -1
- package/ui.container-accordion/UAccordion.vue +1 -1
- package/ui.container-accordion/storybook/Docs.mdx +1 -1
- package/ui.container-accordion/storybook/stories.js +1 -1
- package/ui.container-accordion/useAttrs.js +1 -1
- package/ui.container-card/storybook/Docs.mdx +1 -1
- package/ui.container-card/storybook/stories.js +1 -1
- package/ui.container-card/useAttrs.js +1 -1
- package/ui.container-col/UCol.vue +1 -1
- package/ui.container-col/storybook/Docs.mdx +1 -1
- package/ui.container-col/storybook/stories.js +1 -1
- package/ui.container-col/useAttrs.js +1 -1
- package/ui.container-divider/UDivider.vue +1 -1
- package/ui.container-divider/storybook/Docs.mdx +1 -1
- package/ui.container-divider/storybook/stories.js +2 -2
- package/ui.container-divider/useAttrs.js +1 -1
- package/ui.container-group/UGroup.vue +1 -1
- package/ui.container-group/storybook/Docs.mdx +1 -1
- package/ui.container-group/storybook/stories.js +1 -1
- package/ui.container-group/useAttrs.js +1 -1
- package/ui.container-modal/UModal.vue +1 -1
- package/ui.container-modal/storybook/Docs.mdx +1 -1
- package/ui.container-modal/storybook/stories.js +2 -2
- package/ui.container-modal/useAttrs.js +1 -1
- package/ui.container-modal-confirm/UModalConfirm.vue +2 -2
- package/ui.container-modal-confirm/storybook/Docs.mdx +1 -1
- package/ui.container-modal-confirm/storybook/stories.js +2 -2
- package/ui.container-modal-confirm/useAttrs.js +1 -1
- package/ui.container-page/UPage.vue +2 -2
- package/ui.container-page/storybook/Docs.mdx +1 -1
- package/ui.container-page/storybook/stories.js +1 -1
- package/ui.container-page/useAttrs.js +2 -2
- package/ui.container-row/URow.vue +1 -1
- package/ui.container-row/storybook/Docs.mdx +1 -1
- package/ui.container-row/storybook/stories.js +2 -2
- package/ui.container-row/useAttrs.js +1 -1
- package/ui.data-list/UDataList.vue +6 -6
- package/ui.data-list/storybook/Docs.mdx +1 -1
- package/ui.data-list/storybook/stories.js +1 -1
- package/ui.data-list/useAttrs.js +1 -1
- package/ui.data-table/UTable.vue +3 -3
- package/ui.data-table/UTableRow.vue +7 -6
- package/ui.data-table/config.js +10 -3
- package/ui.data-table/storybook/Docs.mdx +1 -1
- package/ui.data-table/storybook/stories.js +5 -3
- package/ui.data-table/useAttrs.js +1 -1
- package/ui.data-table/utilTable.js +1 -1
- package/ui.dropdown-badge/UDropdownBadge.vue +1 -1
- package/ui.dropdown-badge/storybook/Docs.mdx +1 -1
- package/ui.dropdown-badge/storybook/stories.js +2 -2
- package/ui.dropdown-badge/useAttrs.js +1 -1
- package/ui.dropdown-button/UDropdownButton.vue +1 -1
- package/ui.dropdown-button/storybook/Docs.mdx +1 -1
- package/ui.dropdown-button/storybook/stories.js +3 -3
- package/ui.dropdown-button/useAttrs.js +1 -1
- package/ui.dropdown-link/UDropdownLink.vue +1 -1
- package/ui.dropdown-link/config.js +1 -1
- package/ui.dropdown-link/storybook/Docs.mdx +1 -1
- package/ui.dropdown-link/storybook/stories.js +2 -2
- package/ui.dropdown-link/useAttrs.js +4 -6
- package/ui.dropdown-list/UDropdownList.vue +3 -3
- package/ui.dropdown-list/storybook/Docs.mdx +1 -1
- package/ui.dropdown-list/storybook/stories.js +2 -2
- package/ui.dropdown-list/useAttrs.js +1 -1
- package/ui.form-calendar/UCalendar.vue +2 -2
- package/ui.form-calendar/storybook/Docs.mdx +1 -1
- package/ui.form-calendar/storybook/stories.js +1 -1
- package/ui.form-calendar/useAttrs.js +1 -1
- package/ui.form-checkbox/UCheckbox.vue +1 -1
- package/ui.form-checkbox/storybook/Docs.mdx +1 -1
- package/ui.form-checkbox/storybook/stories.js +2 -2
- package/ui.form-checkbox/useAttrs.js +1 -1
- package/ui.form-checkbox-group/UCheckboxGroup.vue +1 -1
- package/ui.form-checkbox-group/storybook/Docs.mdx +1 -1
- package/ui.form-checkbox-group/storybook/stories.js +2 -2
- package/ui.form-checkbox-group/useAttrs.js +1 -1
- package/ui.form-checkbox-multi-state/UCheckboxMultiState.vue +1 -1
- package/ui.form-checkbox-multi-state/storybook/Docs.mdx +1 -1
- package/ui.form-checkbox-multi-state/storybook/stories.js +2 -2
- package/ui.form-checkbox-multi-state/useAttrs.js +1 -1
- package/ui.form-color-picker/UColorPicker.vue +1 -1
- package/ui.form-color-picker/storybook/Docs.mdx +1 -1
- package/ui.form-color-picker/storybook/stories.js +2 -2
- package/ui.form-color-picker/useAttrs.js +1 -1
- package/ui.form-date-picker/UDatePicker.vue +4 -7
- package/ui.form-date-picker/storybook/Docs.mdx +1 -1
- package/ui.form-date-picker/storybook/stories.js +3 -3
- package/ui.form-date-picker/useAttrs.js +2 -2
- package/ui.form-date-picker-range/UDatePickerRange.vue +2 -2
- package/ui.form-date-picker-range/storybook/Docs.mdx +1 -1
- package/ui.form-date-picker-range/storybook/stories.js +2 -2
- package/ui.form-date-picker-range/useAttrs.js +2 -2
- package/ui.form-date-picker-range/useLocale.js +1 -1
- package/ui.form-input/UInput.vue +3 -3
- package/ui.form-input/storybook/Docs.mdx +1 -1
- package/ui.form-input/storybook/stories.js +2 -2
- package/ui.form-input/useAttrs.js +1 -1
- package/ui.form-input-file/UInputFile.vue +2 -2
- package/ui.form-input-file/storybook/Docs.mdx +1 -1
- package/ui.form-input-file/storybook/stories.js +2 -2
- package/ui.form-input-file/useAttrs.js +1 -1
- package/ui.form-input-money/UInputMoney.vue +1 -1
- package/ui.form-input-money/storybook/Docs.mdx +1 -1
- package/ui.form-input-money/storybook/stories.js +2 -2
- package/ui.form-input-money/useAttrs.js +1 -1
- package/ui.form-input-money/useFormatCurrency.js +1 -1
- package/ui.form-input-number/UInputNumber.vue +5 -4
- package/ui.form-input-number/storybook/Docs.mdx +1 -1
- package/ui.form-input-number/storybook/stories.js +2 -2
- package/ui.form-input-number/useAttrs.js +1 -1
- package/ui.form-input-rating/UInputRating.vue +1 -1
- package/ui.form-input-rating/storybook/Docs.mdx +1 -1
- package/ui.form-input-rating/storybook/stories.js +2 -2
- package/ui.form-input-rating/useAttrs.js +1 -1
- package/ui.form-input-search/UInputSearch.vue +2 -2
- package/ui.form-input-search/storybook/Docs.mdx +1 -1
- package/ui.form-input-search/storybook/stories.js +2 -2
- package/ui.form-input-search/useAttrs.js +1 -1
- package/ui.form-label/ULabel.vue +1 -1
- package/ui.form-label/config.js +2 -2
- package/ui.form-label/storybook/Docs.mdx +1 -1
- package/ui.form-label/storybook/stories.js +2 -2
- package/ui.form-label/useAttrs.js +1 -1
- package/ui.form-radio/URadio.vue +1 -1
- package/ui.form-radio/storybook/Docs.mdx +1 -1
- package/ui.form-radio/storybook/stories.js +1 -1
- package/ui.form-radio/useAttrs.js +1 -1
- package/ui.form-radio-group/URadioGroup.vue +1 -1
- package/ui.form-radio-group/storybook/Docs.mdx +1 -1
- package/ui.form-radio-group/storybook/stories.js +2 -2
- package/ui.form-radio-group/useAttrs.js +1 -1
- package/ui.form-select/USelect.vue +4 -4
- package/ui.form-select/storybook/Docs.mdx +1 -1
- package/ui.form-select/storybook/stories.js +2 -2
- package/ui.form-select/useAttrs.js +1 -1
- package/ui.form-switch/USwitch.vue +2 -2
- package/ui.form-switch/storybook/Docs.mdx +1 -1
- package/ui.form-switch/storybook/stories.js +2 -2
- package/ui.form-switch/useAttrs.js +1 -1
- package/ui.form-switch/utilVariant.js +1 -1
- package/ui.form-textarea/UTextarea.vue +1 -1
- package/ui.form-textarea/storybook/Docs.mdx +1 -1
- package/ui.form-textarea/storybook/stories.js +2 -2
- package/ui.form-textarea/useAttrs.js +1 -1
- package/ui.image-avatar/UAvatar.vue +1 -1
- package/ui.image-avatar/storybook/Docs.mdx +1 -1
- package/ui.image-avatar/storybook/stories.js +2 -2
- package/ui.image-avatar/useAttrs.js +1 -1
- package/ui.image-icon/UIcon.vue +14 -8
- package/ui.image-icon/storybook/Docs.mdx +2 -2
- package/ui.image-icon/storybook/stories.js +2 -2
- package/ui.image-icon/useAttrs.js +2 -2
- package/ui.loader/ULoader.vue +1 -1
- package/ui.loader/storybook/Docs.mdx +1 -1
- package/ui.loader/storybook/stories.js +2 -2
- package/ui.loader/useAttrs.js +1 -1
- package/ui.loader-overlay/ULoaderOverlay.vue +1 -1
- package/ui.loader-overlay/storybook/Docs.mdx +1 -1
- package/ui.loader-overlay/storybook/stories.js +1 -1
- package/ui.loader-overlay/useAttrs.js +1 -1
- package/ui.loader-progress/ULoaderProgress.vue +33 -48
- package/ui.loader-progress/constants.js +1 -0
- package/ui.loader-progress/storybook/Docs.mdx +1 -1
- package/ui.loader-progress/storybook/stories.js +3 -4
- package/ui.loader-progress/useAttrs.js +1 -1
- package/ui.loader-progress/useLoaderProgress.js +13 -8
- package/ui.loader-progress/utilLoaderProgress.js +1 -1
- package/ui.navigation-pagination/UPagination.vue +1 -1
- package/ui.navigation-pagination/storybook/Docs.mdx +1 -1
- package/ui.navigation-pagination/storybook/stories.js +1 -1
- package/ui.navigation-pagination/useAttrs.js +1 -1
- package/ui.navigation-progress/UProgress.vue +1 -1
- package/ui.navigation-progress/storybook/Docs.mdx +1 -1
- package/ui.navigation-progress/storybook/stories.js +2 -2
- package/ui.navigation-progress/useAttrs.js +1 -1
- package/ui.navigation-tab/UTab.vue +1 -1
- package/ui.navigation-tab/storybook/Docs.mdx +1 -1
- package/ui.navigation-tab/storybook/stories.js +1 -1
- package/ui.navigation-tab/useAttrs.js +1 -1
- package/ui.navigation-tabs/UTabs.vue +1 -1
- package/ui.navigation-tabs/storybook/Docs.mdx +1 -1
- package/ui.navigation-tabs/storybook/stories.js +2 -2
- package/ui.navigation-tabs/useAttrs.js +1 -1
- package/ui.other-dot/UDot.vue +1 -1
- package/ui.other-dot/storybook/Docs.mdx +1 -1
- package/ui.other-dot/storybook/stories.js +2 -2
- package/ui.other-dot/useAttrs.js +1 -1
- package/ui.text-alert/UAlert.vue +1 -1
- package/ui.text-alert/storybook/Docs.mdx +1 -1
- package/ui.text-alert/storybook/stories.js +2 -2
- package/ui.text-alert/useAttrs.js +1 -1
- package/ui.text-badge/UBadge.vue +89 -179
- package/ui.text-badge/storybook/Docs.mdx +3 -3
- package/ui.text-badge/storybook/{stories.js → stories.ts} +33 -37
- package/ui.text-badge/types.ts +84 -0
- package/ui.text-badge/useAttrs.ts +28 -0
- package/ui.text-block/UText.vue +18 -62
- package/ui.text-block/storybook/Docs.mdx +3 -3
- package/ui.text-block/storybook/{stories.js → stories.ts} +13 -8
- package/ui.text-block/types.ts +33 -0
- package/ui.text-block/useAttrs.ts +20 -0
- package/ui.text-empty/UEmpty.vue +1 -1
- package/ui.text-empty/storybook/Docs.mdx +1 -1
- package/ui.text-empty/storybook/stories.js +2 -2
- package/ui.text-empty/useAttrs.js +1 -1
- package/ui.text-file/UFile.vue +13 -16
- package/ui.text-file/config.js +12 -2
- package/ui.text-file/storybook/Docs.mdx +1 -1
- package/ui.text-file/storybook/stories.js +1 -1
- package/ui.text-file/useAttrs.js +1 -1
- package/ui.text-files/UFiles.vue +1 -1
- package/ui.text-files/config.js +1 -1
- package/ui.text-files/storybook/Docs.mdx +1 -1
- package/ui.text-files/storybook/stories.js +1 -1
- package/ui.text-files/useAttrs.js +1 -1
- package/ui.text-header/UHeader.vue +1 -1
- package/ui.text-header/storybook/Docs.mdx +1 -1
- package/ui.text-header/storybook/stories.js +2 -2
- package/ui.text-header/useAttrs.js +1 -1
- package/ui.text-money/UMoney.vue +1 -1
- package/ui.text-money/storybook/Docs.mdx +1 -1
- package/ui.text-money/storybook/stories.js +2 -2
- package/ui.text-money/useAttrs.js +1 -1
- package/ui.text-money/utilMoney.js +2 -2
- package/ui.text-notify/UNotify.vue +2 -2
- package/ui.text-notify/storybook/Docs.mdx +1 -1
- package/ui.text-notify/storybook/stories.js +1 -1
- package/ui.text-notify/useAttrs.js +1 -1
- package/ui.text-notify/utilNotify.js +1 -1
- package/utils/{utilHelper.js → helper.ts} +14 -27
- package/utils/node/helper.js +78 -0
- package/utils/node/loaderIcon.js +232 -0
- package/utils/node/loaderSvg.js +71 -0
- package/utils/node/mergeConfigs.js +199 -0
- package/utils/node/tailwindSafelist.js +366 -0
- package/utils/node/vuelessConfig.js +42 -0
- package/utils/node/vuelessResolver.js +28 -0
- package/utils/{utilPlatform.js → platform.ts} +10 -3
- package/utils/{utilStorybook.js → storybook.ts} +102 -36
- package/utils/tailwindConfig.ts +33 -0
- package/utils/{utilTheme.js → theme.ts} +65 -30
- package/utils/ui.ts +129 -0
- package/web-types.json +1362 -157
- package/adatper.locale/vue-i18n.js +0 -11
- package/composables/useAutoPosition.js +0 -94
- package/composables/useBreakpoint.js +0 -104
- package/composables/useLocale.js +0 -25
- package/composables/useMutationObserver.js +0 -48
- package/directives/clickOutside/vClickOutside.js +0 -64
- package/directives/tooltip/vTooltip.js +0 -56
- package/ui.text-badge/useAttrs.js +0 -23
- package/ui.text-block/useAttrs.js +0 -15
- package/utils/utilUI.js +0 -360
- /package/adatper.locale/locales/{en.js → en.ts} +0 -0
- /package/ui.image-icon/{config.js → config.ts} +0 -0
- /package/ui.text-badge/{config.js → config.ts} +0 -0
- /package/ui.text-badge/{constants.js → constants.ts} +0 -0
- /package/ui.text-block/{config.js → config.ts} +0 -0
- /package/ui.text-block/{constants.js → constants.ts} +0 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { I18n } from "vue-i18n";
|
|
2
|
+
|
|
3
|
+
export default function createVueI18nAdapter(i18n: I18n) {
|
|
4
|
+
return {
|
|
5
|
+
name: "vue-i18n",
|
|
6
|
+
locale: i18n.global.locale,
|
|
7
|
+
fallback: i18n.global.fallbackLocale,
|
|
8
|
+
messages: i18n.global.messages,
|
|
9
|
+
// @ts-expect-error Type instantiation is excessively deep and possibly infinite
|
|
10
|
+
t: (key: string, ...params: unknown[]) => i18n.global.t(key, params),
|
|
11
|
+
tm: i18n.global.tm,
|
|
12
|
+
n: i18n.global.n,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -1,11 +1,35 @@
|
|
|
1
1
|
import { shallowRef, ref } from "vue";
|
|
2
2
|
import { merge } from "lodash-es";
|
|
3
3
|
|
|
4
|
-
import en from "./locales/en.
|
|
4
|
+
import en from "./locales/en.ts";
|
|
5
|
+
|
|
6
|
+
import type { Ref } from "vue";
|
|
7
|
+
import type { UnknownObject } from "../types.ts";
|
|
8
|
+
|
|
9
|
+
export interface LocaleMessages {
|
|
10
|
+
[key: string]: LocaleMessages | string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface LocaleOptions {
|
|
14
|
+
messages?: LocaleMessages;
|
|
15
|
+
locale?: string;
|
|
16
|
+
fallback?: string;
|
|
17
|
+
adapter?: LocaleInstance;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface LocaleInstance {
|
|
21
|
+
name: string;
|
|
22
|
+
messages: Ref<LocaleMessages>;
|
|
23
|
+
locale: Ref<string>;
|
|
24
|
+
fallback: Ref<string>;
|
|
25
|
+
t: (key: string, ...params: unknown[]) => string;
|
|
26
|
+
n: (value: number) => string;
|
|
27
|
+
tm: (key: string, ...params: unknown[]) => string;
|
|
28
|
+
}
|
|
5
29
|
|
|
6
30
|
const FALLBACK_LOCALE_CODE = "en";
|
|
7
31
|
|
|
8
|
-
export default function createVuelessAdapter(options) {
|
|
32
|
+
export default function createVuelessAdapter(options?: LocaleOptions): LocaleInstance {
|
|
9
33
|
const current = shallowRef(options?.locale ?? FALLBACK_LOCALE_CODE);
|
|
10
34
|
const fallback = shallowRef(options?.fallback ?? FALLBACK_LOCALE_CODE);
|
|
11
35
|
|
|
@@ -22,12 +46,16 @@ export default function createVuelessAdapter(options) {
|
|
|
22
46
|
};
|
|
23
47
|
}
|
|
24
48
|
|
|
25
|
-
function createTranslateFunction(
|
|
26
|
-
|
|
49
|
+
function createTranslateFunction(
|
|
50
|
+
current: Ref<string>,
|
|
51
|
+
fallback: Ref<string>,
|
|
52
|
+
messages: Ref<LocaleMessages>,
|
|
53
|
+
) {
|
|
54
|
+
return (key: string, ...params: unknown[]) => {
|
|
27
55
|
const currentLocale = current.value && messages.value[current.value];
|
|
28
56
|
const fallbackLocale = fallback.value && messages.value[fallback.value];
|
|
29
57
|
|
|
30
|
-
let str = getObjectValueByPath(currentLocale, key, null);
|
|
58
|
+
let str = getObjectValueByPath<LocaleMessages | string, unknown>(currentLocale, key, null);
|
|
31
59
|
|
|
32
60
|
if (!str) {
|
|
33
61
|
// eslint-disable-next-line no-console
|
|
@@ -49,16 +77,20 @@ function createTranslateFunction(current, fallback, messages) {
|
|
|
49
77
|
str = key;
|
|
50
78
|
}
|
|
51
79
|
|
|
52
|
-
return replace(str, params);
|
|
80
|
+
return replace(String(str), params);
|
|
53
81
|
};
|
|
54
82
|
}
|
|
55
83
|
|
|
56
|
-
function createTranslateMessageFunction(
|
|
57
|
-
|
|
84
|
+
function createTranslateMessageFunction(
|
|
85
|
+
current: Ref<string>,
|
|
86
|
+
fallback: Ref<string>,
|
|
87
|
+
messages: Ref<LocaleMessages>,
|
|
88
|
+
) {
|
|
89
|
+
return (key: string) => {
|
|
58
90
|
const currentLocale = current.value && messages.value[current.value];
|
|
59
91
|
const fallbackLocale = fallback.value && messages.value[fallback.value];
|
|
60
92
|
|
|
61
|
-
let str = getObjectValueByPath(currentLocale, key, null);
|
|
93
|
+
let str = getObjectValueByPath<LocaleMessages | string, unknown>(currentLocale, key, null);
|
|
62
94
|
|
|
63
95
|
if (str === undefined) {
|
|
64
96
|
// eslint-disable-next-line no-console
|
|
@@ -68,51 +100,67 @@ function createTranslateMessageFunction(current, fallback, messages) {
|
|
|
68
100
|
str = getObjectValueByPath(fallbackLocale, key, null);
|
|
69
101
|
}
|
|
70
102
|
|
|
71
|
-
return str;
|
|
103
|
+
return String(str);
|
|
72
104
|
};
|
|
73
105
|
}
|
|
74
106
|
|
|
75
|
-
const replace = (str, params) => {
|
|
107
|
+
const replace = (str: string, params: unknown[]) => {
|
|
76
108
|
return str.replace(/\{(\d+)\}/g, (match, index) => {
|
|
77
109
|
return String(params[+index]);
|
|
78
110
|
});
|
|
79
111
|
};
|
|
80
112
|
|
|
81
|
-
function createNumberFunction(current
|
|
82
|
-
return (value, options) => {
|
|
113
|
+
function createNumberFunction(current: Ref<string>, fallback: Ref<string>) {
|
|
114
|
+
return (value: number, options?: Intl.NumberFormatOptions) => {
|
|
83
115
|
const numberFormat = new Intl.NumberFormat([current.value, fallback.value], options);
|
|
84
116
|
|
|
85
117
|
return numberFormat.format(value);
|
|
86
118
|
};
|
|
87
119
|
}
|
|
88
120
|
|
|
89
|
-
export function getObjectValueByPath
|
|
121
|
+
export function getObjectValueByPath<T, K = unknown>(
|
|
122
|
+
obj: T,
|
|
123
|
+
path?: string,
|
|
124
|
+
fallback?: K,
|
|
125
|
+
): K | undefined {
|
|
90
126
|
if (obj == null || !path || typeof path !== "string") return fallback;
|
|
91
|
-
|
|
127
|
+
|
|
128
|
+
const unknownObject = obj as UnknownObject;
|
|
129
|
+
|
|
130
|
+
if (unknownObject[path] !== undefined) {
|
|
131
|
+
return unknownObject[path] as K;
|
|
132
|
+
}
|
|
133
|
+
|
|
92
134
|
path = path.replace(/\[(\w+)\]/g, ".$1"); // convert indexes to properties
|
|
93
135
|
path = path.replace(/^\./, ""); // strip a leading dot
|
|
94
136
|
|
|
95
137
|
return getNestedValue(obj, path.split("."), fallback);
|
|
96
138
|
}
|
|
97
139
|
|
|
98
|
-
export function getNestedValue
|
|
140
|
+
export function getNestedValue<T, K = unknown>(
|
|
141
|
+
obj: T | null | undefined,
|
|
142
|
+
path: (string | number)[],
|
|
143
|
+
fallback?: K,
|
|
144
|
+
): K | undefined {
|
|
99
145
|
const last = path.length - 1;
|
|
100
146
|
|
|
101
147
|
if (last < 0) {
|
|
102
|
-
return obj === undefined ? fallback : obj;
|
|
148
|
+
return obj === undefined ? fallback : (obj as unknown as K);
|
|
103
149
|
}
|
|
104
150
|
|
|
151
|
+
const unknownObject = obj as Record<string | number, unknown>;
|
|
152
|
+
|
|
105
153
|
for (let i = 0; i < last; i++) {
|
|
106
154
|
if (obj == null) {
|
|
107
155
|
return fallback;
|
|
108
156
|
}
|
|
109
157
|
|
|
110
|
-
obj =
|
|
158
|
+
obj = unknownObject[path[i]] as T;
|
|
111
159
|
}
|
|
112
160
|
|
|
113
161
|
if (obj == null) {
|
|
114
162
|
return fallback;
|
|
115
163
|
}
|
|
116
164
|
|
|
117
|
-
return
|
|
165
|
+
return (unknownObject[path[last]] === undefined ? fallback : unknownObject[path[last]]) as K;
|
|
118
166
|
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { computed, toValue, ref } from "vue";
|
|
2
|
+
import { isSSR } from "../utils/helper.ts";
|
|
3
|
+
|
|
4
|
+
import type { ComputedRef, MaybeRef, Reactive } from "vue";
|
|
5
|
+
|
|
6
|
+
export enum Direction {
|
|
7
|
+
Left = "left",
|
|
8
|
+
Right = "right",
|
|
9
|
+
Top = "top",
|
|
10
|
+
Bottom = "bottom",
|
|
11
|
+
Auto = "auto",
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type Align = `${Direction}`;
|
|
15
|
+
export type Position = { x: Align; y: Align };
|
|
16
|
+
|
|
17
|
+
// TODO: Remove it after ui.form-date-picker-range and ui.form-date-picker ts migration (use enum there instead).
|
|
18
|
+
export const POSITION = {
|
|
19
|
+
left: "left",
|
|
20
|
+
right: "right",
|
|
21
|
+
top: "top",
|
|
22
|
+
bottom: "bottom",
|
|
23
|
+
auto: "auto",
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export function useAutoPosition(
|
|
27
|
+
anchorElement: MaybeRef<HTMLElement | null>,
|
|
28
|
+
targetElement: MaybeRef<HTMLElement | null>,
|
|
29
|
+
position: Reactive<Position> | ComputedRef<Position>,
|
|
30
|
+
preferredPosition: Reactive<Position> | ComputedRef<Position>,
|
|
31
|
+
) {
|
|
32
|
+
const localAnchorElement = computed(() => toValue(anchorElement));
|
|
33
|
+
const localTargetElement = computed(() => toValue(targetElement));
|
|
34
|
+
const localPosition = computed(() => toValue(position));
|
|
35
|
+
const localPreferredPosition = computed(() => toValue(preferredPosition));
|
|
36
|
+
|
|
37
|
+
const preferredOpenDirectionY = ref(localPreferredPosition.value.y || Direction.Bottom);
|
|
38
|
+
const preferredOpenDirectionX = ref(localPreferredPosition.value.x || Direction.Left);
|
|
39
|
+
|
|
40
|
+
const isTop = computed(() => {
|
|
41
|
+
if (localPosition.value.y !== Direction.Auto) {
|
|
42
|
+
return localPosition.value.y === Direction.Top;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return preferredOpenDirectionY.value === Direction.Top;
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const isLeft = computed(() => {
|
|
49
|
+
if (localPosition.value.x !== Direction.Auto) {
|
|
50
|
+
return localPosition.value.x === Direction.Left;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return preferredOpenDirectionX.value === Direction.Left;
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const isBottom = computed(() => {
|
|
57
|
+
if (localPosition.value.y !== Direction.Auto) {
|
|
58
|
+
return localPosition.value.y === Direction.Bottom;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return preferredOpenDirectionY.value === Direction.Bottom;
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const isRight = computed(() => {
|
|
65
|
+
if (localPosition.value.x !== Direction.Auto) {
|
|
66
|
+
return localPosition.value.x === Direction.Right;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return preferredOpenDirectionX.value === Direction.Right;
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
function adjustPositionY() {
|
|
73
|
+
if (isSSR || !localAnchorElement.value || !localTargetElement.value) return;
|
|
74
|
+
|
|
75
|
+
const spaceAbove = localAnchorElement.value.getBoundingClientRect().top;
|
|
76
|
+
const spaceBelow = window.innerHeight - localAnchorElement.value.getBoundingClientRect().bottom;
|
|
77
|
+
const hasEnoughSpaceBelow =
|
|
78
|
+
spaceBelow > localTargetElement.value.getBoundingClientRect().height;
|
|
79
|
+
const hasEnoughSpaceAbove =
|
|
80
|
+
spaceAbove > localTargetElement.value.getBoundingClientRect().height;
|
|
81
|
+
|
|
82
|
+
if (localPreferredPosition.value.y === Direction.Bottom) {
|
|
83
|
+
preferredOpenDirectionY.value =
|
|
84
|
+
hasEnoughSpaceBelow || spaceBelow > spaceAbove ? Direction.Bottom : Direction.Top;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (localPreferredPosition.value.y === Direction.Top) {
|
|
88
|
+
preferredOpenDirectionY.value =
|
|
89
|
+
hasEnoughSpaceAbove || spaceAbove > spaceBelow ? Direction.Top : Direction.Bottom;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function adjustPositionX() {
|
|
94
|
+
if (isSSR || !localAnchorElement.value || !localTargetElement.value) return;
|
|
95
|
+
|
|
96
|
+
const spaceRight = localAnchorElement.value.getBoundingClientRect().right;
|
|
97
|
+
const spaceLeft = window.innerWidth - localAnchorElement.value.getBoundingClientRect().left;
|
|
98
|
+
const hasEnoughSpaceLeft = spaceLeft > localTargetElement.value.getBoundingClientRect().width;
|
|
99
|
+
const hasEnoughSpaceRight = spaceRight > localTargetElement.value.getBoundingClientRect().width;
|
|
100
|
+
|
|
101
|
+
if (localPreferredPosition.value.x === Direction.Right) {
|
|
102
|
+
preferredOpenDirectionX.value =
|
|
103
|
+
hasEnoughSpaceRight || spaceRight > spaceLeft ? Direction.Right : Direction.Left;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (localPreferredPosition.value.x === Direction.Left) {
|
|
107
|
+
preferredOpenDirectionX.value =
|
|
108
|
+
hasEnoughSpaceLeft || spaceLeft > spaceRight ? Direction.Left : Direction.Right;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return { isTop, isRight, isBottom, isLeft, adjustPositionY, adjustPositionX };
|
|
113
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { onMounted, ref, watch, computed, onBeforeUnmount } from "vue";
|
|
2
|
+
import { isSSR } from "../utils/helper.ts";
|
|
3
|
+
|
|
4
|
+
import type { Ref } from "vue";
|
|
5
|
+
|
|
6
|
+
enum BreakpointName {
|
|
7
|
+
Xs = "xs",
|
|
8
|
+
Sm = "sm",
|
|
9
|
+
Md = "md",
|
|
10
|
+
Lg = "lg",
|
|
11
|
+
Xl = "xl",
|
|
12
|
+
"2xl" = "2xl",
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
enum BreakpointWidth {
|
|
16
|
+
Xs = 0,
|
|
17
|
+
Sm = 640,
|
|
18
|
+
Md = 768,
|
|
19
|
+
Lg = 1024,
|
|
20
|
+
Xl = 1280,
|
|
21
|
+
"2xl" = 1536,
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type Breakpoint = `${BreakpointName}`;
|
|
25
|
+
|
|
26
|
+
const mobileDevices = ["xs", "sm"];
|
|
27
|
+
const portableDevices = ["xs", "sm", "md"];
|
|
28
|
+
|
|
29
|
+
export default function useBreakpoint() {
|
|
30
|
+
let timeout: number | undefined;
|
|
31
|
+
|
|
32
|
+
const windowWidth = ref(0);
|
|
33
|
+
const currentBreakpoint: Ref<Breakpoint> = ref(BreakpointName.Xs);
|
|
34
|
+
|
|
35
|
+
const isMobileBreakpoint = computed(() => {
|
|
36
|
+
return mobileDevices.includes(currentBreakpoint.value);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const isTabletBreakpoint = computed(() => {
|
|
40
|
+
return mobileDevices.includes(currentBreakpoint.value);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const isLaptopBreakpoint = computed(() => {
|
|
44
|
+
return currentBreakpoint.value === BreakpointName.Lg;
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const isPortableBreakpoint = computed(() => {
|
|
48
|
+
return portableDevices.includes(currentBreakpoint.value);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// TODO: Why do we need this? Maybe we should rename it.
|
|
52
|
+
const elementSize = computed(() => {
|
|
53
|
+
return isMobileBreakpoint.value ? BreakpointName.Md : BreakpointName.Lg;
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
onMounted(() => {
|
|
57
|
+
if (isSSR) return;
|
|
58
|
+
|
|
59
|
+
windowWidth.value = window.innerWidth;
|
|
60
|
+
|
|
61
|
+
window.addEventListener("resize", resizeListener, { passive: true });
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
onBeforeUnmount(() => {
|
|
65
|
+
if (isSSR) return;
|
|
66
|
+
|
|
67
|
+
window.removeEventListener("resize", resizeListener);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
watch(windowWidth, setBreakpoint, { immediate: true });
|
|
71
|
+
|
|
72
|
+
function resizeListener() {
|
|
73
|
+
if (isSSR) return;
|
|
74
|
+
|
|
75
|
+
if (timeout) {
|
|
76
|
+
window.cancelAnimationFrame(timeout);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
timeout = window.requestAnimationFrame(() => {
|
|
80
|
+
windowWidth.value = window.innerWidth;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function setBreakpoint(newWindowWidth: number) {
|
|
85
|
+
if (newWindowWidth === undefined) return;
|
|
86
|
+
|
|
87
|
+
currentBreakpoint.value = "xs";
|
|
88
|
+
|
|
89
|
+
if (newWindowWidth >= BreakpointWidth.Sm && newWindowWidth < BreakpointWidth.Sm) {
|
|
90
|
+
currentBreakpoint.value = BreakpointName.Sm;
|
|
91
|
+
} else if (newWindowWidth >= BreakpointWidth.Md && newWindowWidth < BreakpointWidth.Lg) {
|
|
92
|
+
currentBreakpoint.value = BreakpointName.Md;
|
|
93
|
+
} else if (newWindowWidth >= BreakpointWidth.Lg && newWindowWidth < BreakpointWidth.Xl) {
|
|
94
|
+
currentBreakpoint.value = BreakpointName.Lg;
|
|
95
|
+
} else if (newWindowWidth >= BreakpointWidth.Xl && newWindowWidth < BreakpointWidth["2xl"]) {
|
|
96
|
+
currentBreakpoint.value = BreakpointName.Xl;
|
|
97
|
+
} else if (newWindowWidth >= BreakpointWidth["2xl"]) {
|
|
98
|
+
currentBreakpoint.value = BreakpointName["2xl"];
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return {
|
|
103
|
+
isLaptopBreakpoint,
|
|
104
|
+
isTabletBreakpoint,
|
|
105
|
+
isMobileBreakpoint,
|
|
106
|
+
isPortableBreakpoint,
|
|
107
|
+
elementSize,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { inject } from "vue";
|
|
2
|
+
import createVuelessAdapter from "../adatper.locale/vueless.ts";
|
|
3
|
+
|
|
4
|
+
import type { LocaleInstance, LocaleOptions } from "../adatper.locale/vueless.ts";
|
|
5
|
+
import type { InjectionKey } from "vue";
|
|
6
|
+
|
|
7
|
+
export const LocaleSymbol: InjectionKey<LocaleInstance> = Symbol.for("vueless:locale");
|
|
8
|
+
|
|
9
|
+
export function createLocale(options?: LocaleOptions) {
|
|
10
|
+
const i18n =
|
|
11
|
+
options?.adapter && options?.adapter?.name ? options?.adapter : createVuelessAdapter(options);
|
|
12
|
+
|
|
13
|
+
return { ...i18n };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function useLocale() {
|
|
17
|
+
const locale = inject(LocaleSymbol);
|
|
18
|
+
|
|
19
|
+
if (!locale) throw new Error("[vueless] Could not find injected locale instance");
|
|
20
|
+
|
|
21
|
+
return locale;
|
|
22
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { computed, onBeforeUnmount, onMounted, toValue, watch } from "vue";
|
|
2
|
+
import { isSSR } from "../utils/helper.ts";
|
|
3
|
+
|
|
4
|
+
import type { TemplateRefElement } from "../types.ts";
|
|
5
|
+
|
|
6
|
+
export function useMutationObserver(
|
|
7
|
+
target: TemplateRefElement,
|
|
8
|
+
callback: MutationCallback,
|
|
9
|
+
config = { childList: true, attributes: true, characterData: true },
|
|
10
|
+
) {
|
|
11
|
+
if (isSSR) return;
|
|
12
|
+
|
|
13
|
+
const observer = new MutationObserver(callback);
|
|
14
|
+
const targetValue = computed(() => toValue(target));
|
|
15
|
+
|
|
16
|
+
onMounted(() => {
|
|
17
|
+
if (!targetValue.value) return;
|
|
18
|
+
|
|
19
|
+
if (Array.isArray(targetValue.value)) {
|
|
20
|
+
targetValue.value.forEach((element) => {
|
|
21
|
+
observer.observe(element, config);
|
|
22
|
+
});
|
|
23
|
+
} else {
|
|
24
|
+
observer.observe(targetValue.value, config);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
watch(
|
|
29
|
+
targetValue,
|
|
30
|
+
() => {
|
|
31
|
+
if (!targetValue.value) return;
|
|
32
|
+
|
|
33
|
+
if (Array.isArray(targetValue.value)) {
|
|
34
|
+
targetValue.value.forEach((element) => {
|
|
35
|
+
observer.observe(element, config);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
observer.observe(targetValue.value, config);
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
deep: true,
|
|
45
|
+
},
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
onBeforeUnmount(() => {
|
|
49
|
+
observer.disconnect();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
return { observer };
|
|
53
|
+
}
|