vueless 0.0.478-beta.2 → 0.0.478-beta.20
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/{composablesTs → composables}/useAutoPosition.ts +35 -37
- package/{composablesTs → composables}/useBreakpoint.ts +37 -34
- package/composables/useLocale.ts +22 -0
- package/composables/useMutationObserver.ts +53 -0
- package/{composablesTs → composables}/useUI.ts +5 -226
- package/constants.js +123 -1
- 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} +17 -5
- package/directives/tooltip/types.ts +14 -0
- package/directives/tooltip/vTooltip.ts +82 -0
- package/index.ts +5 -5
- package/package.json +12 -10
- package/preset.tailwind.js +5 -0
- package/types.ts +20 -5
- package/ui.button/UButton.vue +1 -1
- package/ui.button/config.js +0 -12
- package/ui.button/storybook/Docs.mdx +1 -1
- package/ui.button/storybook/stories.js +9 -4
- package/ui.button/useAttrs.js +1 -1
- package/ui.button-link/ULink.vue +1 -1
- package/ui.button-link/config.js +0 -9
- package/ui.button-link/storybook/Docs.mdx +1 -1
- package/ui.button-link/storybook/stories.js +1 -1
- 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 +1 -1
- 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 +1 -1
- 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 +1 -1
- 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 +1 -1
- 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 +1 -1
- package/ui.container-row/useAttrs.js +1 -1
- package/ui.data-list/UDataList.vue +2 -2
- 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/config.js +0 -1
- package/ui.dropdown-badge/storybook/Docs.mdx +1 -1
- package/ui.dropdown-badge/storybook/stories.js +1 -1
- package/ui.dropdown-badge/useAttrs.js +1 -1
- package/ui.dropdown-button/UDropdownButton.vue +1 -1
- package/ui.dropdown-button/config.js +0 -1
- package/ui.dropdown-button/storybook/Docs.mdx +1 -1
- package/ui.dropdown-button/storybook/stories.js +1 -1
- 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 +1 -1
- 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 +1 -1
- 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/config.js +0 -9
- package/ui.form-checkbox/storybook/Docs.mdx +1 -1
- package/ui.form-checkbox/storybook/stories.js +1 -1
- 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 +1 -1
- 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 +1 -1
- package/ui.form-checkbox-multi-state/useAttrs.js +1 -1
- package/ui.form-color-picker/UColorPicker.vue +1 -1
- package/ui.form-color-picker/config.js +0 -7
- package/ui.form-color-picker/storybook/Docs.mdx +1 -1
- package/ui.form-color-picker/storybook/stories.js +1 -1
- 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 +1 -1
- 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 +1 -1
- 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 +2 -2
- package/ui.form-input/storybook/Docs.mdx +1 -1
- package/ui.form-input/storybook/stories.js +1 -1
- 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 +1 -1
- 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 +1 -1
- package/ui.form-input-money/useAttrs.js +1 -1
- package/ui.form-input-number/UInputNumber.vue +1 -1
- package/ui.form-input-number/storybook/Docs.mdx +1 -1
- package/ui.form-input-number/storybook/stories.js +1 -1
- 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 +1 -1
- 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 +1 -1
- package/ui.form-input-search/useAttrs.js +1 -1
- package/ui.form-label/ULabel.vue +1 -1
- package/ui.form-label/storybook/Docs.mdx +1 -1
- package/ui.form-label/storybook/stories.js +1 -1
- package/ui.form-label/useAttrs.js +1 -1
- package/ui.form-radio/URadio.vue +1 -1
- package/ui.form-radio/config.js +0 -6
- 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 +1 -1
- 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 +1 -1
- package/ui.form-select/useAttrs.js +1 -1
- package/ui.form-switch/USwitch.vue +2 -2
- package/ui.form-switch/config.js +0 -6
- package/ui.form-switch/storybook/Docs.mdx +1 -1
- package/ui.form-switch/storybook/stories.js +1 -1
- 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 +1 -1
- package/ui.form-textarea/useAttrs.js +1 -1
- package/ui.image-avatar/UAvatar.vue +1 -1
- package/ui.image-avatar/config.js +0 -5
- package/ui.image-avatar/storybook/Docs.mdx +1 -1
- package/ui.image-avatar/storybook/stories.js +1 -1
- package/ui.image-avatar/useAttrs.js +1 -1
- package/ui.image-icon/UIcon.vue +23 -8
- package/ui.image-icon/{config.js → config.ts} +0 -5
- package/ui.image-icon/storybook/Docs.mdx +2 -2
- package/ui.image-icon/storybook/stories.js +1 -1
- package/ui.image-icon/useAttrs.js +2 -2
- package/ui.loader/ULoader.vue +1 -1
- package/ui.loader/config.js +0 -1
- package/ui.loader/storybook/Docs.mdx +1 -1
- package/ui.loader/storybook/stories.js +1 -1
- package/ui.loader/useAttrs.js +1 -1
- package/ui.loader-overlay/ULoaderOverlay.vue +1 -1
- package/ui.loader-overlay/config.js +0 -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/config.js +0 -1
- package/ui.loader-progress/constants.js +1 -0
- package/ui.loader-progress/storybook/Docs.mdx +1 -1
- package/ui.loader-progress/storybook/stories.js +2 -3
- 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/config.js +0 -9
- package/ui.navigation-progress/storybook/Docs.mdx +1 -1
- package/ui.navigation-progress/storybook/stories.js +1 -1
- 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 +1 -1
- package/ui.navigation-tabs/useAttrs.js +1 -1
- package/ui.other-dot/UDot.vue +1 -1
- package/ui.other-dot/config.js +0 -1
- package/ui.other-dot/storybook/Docs.mdx +1 -1
- package/ui.other-dot/storybook/stories.js +1 -1
- package/ui.other-dot/useAttrs.js +1 -1
- package/ui.text-alert/UAlert.vue +1 -1
- package/ui.text-alert/config.js +0 -7
- package/ui.text-alert/storybook/Docs.mdx +1 -1
- package/ui.text-alert/storybook/stories.js +1 -1
- package/ui.text-alert/useAttrs.js +1 -1
- package/ui.text-badge/UBadge.vue +89 -179
- package/ui.text-badge/{config.js → config.ts} +0 -8
- package/ui.text-badge/storybook/Docs.mdx +3 -3
- package/ui.text-badge/storybook/{stories.js → stories.ts} +26 -35
- package/ui.text-badge/types.ts +84 -0
- package/ui.text-badge/useAttrs.ts +28 -0
- package/ui.text-block/UText.vue +1 -1
- package/ui.text-block/storybook/Docs.mdx +1 -1
- package/ui.text-block/storybook/stories.ts +1 -1
- package/ui.text-block/useAttrs.ts +1 -1
- package/ui.text-empty/UEmpty.vue +1 -1
- package/ui.text-empty/storybook/Docs.mdx +1 -1
- package/ui.text-empty/storybook/stories.js +1 -1
- package/ui.text-empty/useAttrs.js +1 -1
- package/ui.text-file/UFile.vue +1 -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/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/config.js +0 -1
- package/ui.text-header/storybook/Docs.mdx +1 -1
- package/ui.text-header/storybook/stories.js +1 -1
- package/ui.text-header/useAttrs.js +1 -1
- package/ui.text-money/UMoney.vue +1 -1
- package/ui.text-money/config.js +0 -1
- package/ui.text-money/storybook/Docs.mdx +1 -1
- package/ui.text-money/storybook/stories.js +1 -1
- package/ui.text-money/useAttrs.js +1 -1
- 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/node/helper.js +107 -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 +362 -0
- package/utils/node/vuelessConfig.js +40 -0
- package/utils/node/vuelessResolver.js +28 -0
- package/{utilsTs/utilPlatform.ts → utils/platform.ts} +1 -1
- package/{utilsTs/utilStorybook.ts → utils/storybook.ts} +48 -25
- package/{utilsTs/utilTailwind.ts → utils/tailwindConfig.ts} +7 -12
- package/{utilsTs/utilTheme.ts → utils/theme.ts} +40 -16
- package/{utilsTs/utilUI.ts → utils/ui.ts} +7 -21
- package/vite.d.ts +10 -0
- package/vite.js +100 -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/composables/useUI.js +0 -535
- package/composablesTs/useLocale.ts +0 -25
- package/composablesTs/useMutationObserver.ts +0 -50
- package/constants.ts +0 -73
- package/directives/clickOutside/vClickOutside.js +0 -64
- package/directives/tooltip/vTooltip.js +0 -56
- package/ui.text-badge/useAttrs.js +0 -23
- package/utils/utilHelper.js +0 -81
- package/utils/utilPlatform.js +0 -46
- package/utils/utilStorybook.js +0 -191
- package/utils/utilUI.js +0 -156
- /package/adatper.locale/locales/{en.js → en.ts} +0 -0
- /package/ui.text-badge/{constants.js → constants.ts} +0 -0
- /package/{utilsTs/utilHelper.ts → utils/helper.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
|
}
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
import { computed, toValue, ref } from "vue";
|
|
2
|
-
import { isSSR } from "../
|
|
2
|
+
import { isSSR } from "../utils/helper.ts";
|
|
3
3
|
|
|
4
|
-
import type {
|
|
4
|
+
import type { ComputedRef, MaybeRef, Reactive } from "vue";
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
x: Position;
|
|
8
|
-
y: Position;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export enum Position {
|
|
6
|
+
export enum Direction {
|
|
12
7
|
Left = "left",
|
|
13
8
|
Right = "right",
|
|
14
9
|
Top = "top",
|
|
@@ -16,7 +11,10 @@ export enum Position {
|
|
|
16
11
|
Auto = "auto",
|
|
17
12
|
}
|
|
18
13
|
|
|
19
|
-
|
|
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).
|
|
20
18
|
export const POSITION = {
|
|
21
19
|
left: "left",
|
|
22
20
|
right: "right",
|
|
@@ -26,52 +24,52 @@ export const POSITION = {
|
|
|
26
24
|
};
|
|
27
25
|
|
|
28
26
|
export function useAutoPosition(
|
|
29
|
-
anchorElement:
|
|
30
|
-
targetElement:
|
|
31
|
-
position:
|
|
32
|
-
preferredPosition:
|
|
27
|
+
anchorElement: MaybeRef<HTMLElement | null>,
|
|
28
|
+
targetElement: MaybeRef<HTMLElement | null>,
|
|
29
|
+
position: Reactive<Position> | ComputedRef<Position>,
|
|
30
|
+
preferredPosition: Reactive<Position> | ComputedRef<Position>,
|
|
33
31
|
) {
|
|
34
32
|
const localAnchorElement = computed(() => toValue(anchorElement));
|
|
35
33
|
const localTargetElement = computed(() => toValue(targetElement));
|
|
36
34
|
const localPosition = computed(() => toValue(position));
|
|
37
35
|
const localPreferredPosition = computed(() => toValue(preferredPosition));
|
|
38
36
|
|
|
39
|
-
const preferredOpenDirectionY = ref(localPreferredPosition.value
|
|
40
|
-
const preferredOpenDirectionX = ref(localPreferredPosition.value
|
|
37
|
+
const preferredOpenDirectionY = ref(localPreferredPosition.value.y || Direction.Bottom);
|
|
38
|
+
const preferredOpenDirectionX = ref(localPreferredPosition.value.x || Direction.Left);
|
|
41
39
|
|
|
42
40
|
const isTop = computed(() => {
|
|
43
|
-
if (localPosition.value.y !==
|
|
44
|
-
return localPosition.value.y ===
|
|
41
|
+
if (localPosition.value.y !== Direction.Auto) {
|
|
42
|
+
return localPosition.value.y === Direction.Top;
|
|
45
43
|
}
|
|
46
44
|
|
|
47
|
-
return preferredOpenDirectionY.value ===
|
|
45
|
+
return preferredOpenDirectionY.value === Direction.Top;
|
|
48
46
|
});
|
|
49
47
|
|
|
50
48
|
const isLeft = computed(() => {
|
|
51
|
-
if (localPosition.value.x !==
|
|
52
|
-
return localPosition.value.x ===
|
|
49
|
+
if (localPosition.value.x !== Direction.Auto) {
|
|
50
|
+
return localPosition.value.x === Direction.Left;
|
|
53
51
|
}
|
|
54
52
|
|
|
55
|
-
return preferredOpenDirectionX.value ===
|
|
53
|
+
return preferredOpenDirectionX.value === Direction.Left;
|
|
56
54
|
});
|
|
57
55
|
|
|
58
56
|
const isBottom = computed(() => {
|
|
59
|
-
if (localPosition.value.y !==
|
|
60
|
-
return localPosition.value.y ===
|
|
57
|
+
if (localPosition.value.y !== Direction.Auto) {
|
|
58
|
+
return localPosition.value.y === Direction.Bottom;
|
|
61
59
|
}
|
|
62
60
|
|
|
63
|
-
return preferredOpenDirectionY.value ===
|
|
61
|
+
return preferredOpenDirectionY.value === Direction.Bottom;
|
|
64
62
|
});
|
|
65
63
|
|
|
66
64
|
const isRight = computed(() => {
|
|
67
|
-
if (localPosition.value.x !==
|
|
68
|
-
return localPosition.value.x ===
|
|
65
|
+
if (localPosition.value.x !== Direction.Auto) {
|
|
66
|
+
return localPosition.value.x === Direction.Right;
|
|
69
67
|
}
|
|
70
68
|
|
|
71
|
-
return preferredOpenDirectionX.value ===
|
|
69
|
+
return preferredOpenDirectionX.value === Direction.Right;
|
|
72
70
|
});
|
|
73
71
|
|
|
74
|
-
function adjustPositionY()
|
|
72
|
+
function adjustPositionY() {
|
|
75
73
|
if (isSSR || !localAnchorElement.value || !localTargetElement.value) return;
|
|
76
74
|
|
|
77
75
|
const spaceAbove = localAnchorElement.value.getBoundingClientRect().top;
|
|
@@ -81,18 +79,18 @@ export function useAutoPosition(
|
|
|
81
79
|
const hasEnoughSpaceAbove =
|
|
82
80
|
spaceAbove > localTargetElement.value.getBoundingClientRect().height;
|
|
83
81
|
|
|
84
|
-
if (localPreferredPosition.value.y ===
|
|
82
|
+
if (localPreferredPosition.value.y === Direction.Bottom) {
|
|
85
83
|
preferredOpenDirectionY.value =
|
|
86
|
-
hasEnoughSpaceBelow || spaceBelow > spaceAbove ?
|
|
84
|
+
hasEnoughSpaceBelow || spaceBelow > spaceAbove ? Direction.Bottom : Direction.Top;
|
|
87
85
|
}
|
|
88
86
|
|
|
89
|
-
if (localPreferredPosition.value.y ===
|
|
87
|
+
if (localPreferredPosition.value.y === Direction.Top) {
|
|
90
88
|
preferredOpenDirectionY.value =
|
|
91
|
-
hasEnoughSpaceAbove || spaceAbove > spaceBelow ?
|
|
89
|
+
hasEnoughSpaceAbove || spaceAbove > spaceBelow ? Direction.Top : Direction.Bottom;
|
|
92
90
|
}
|
|
93
91
|
}
|
|
94
92
|
|
|
95
|
-
function adjustPositionX()
|
|
93
|
+
function adjustPositionX() {
|
|
96
94
|
if (isSSR || !localAnchorElement.value || !localTargetElement.value) return;
|
|
97
95
|
|
|
98
96
|
const spaceRight = localAnchorElement.value.getBoundingClientRect().right;
|
|
@@ -100,14 +98,14 @@ export function useAutoPosition(
|
|
|
100
98
|
const hasEnoughSpaceLeft = spaceLeft > localTargetElement.value.getBoundingClientRect().width;
|
|
101
99
|
const hasEnoughSpaceRight = spaceRight > localTargetElement.value.getBoundingClientRect().width;
|
|
102
100
|
|
|
103
|
-
if (localPreferredPosition.value.x ===
|
|
101
|
+
if (localPreferredPosition.value.x === Direction.Right) {
|
|
104
102
|
preferredOpenDirectionX.value =
|
|
105
|
-
hasEnoughSpaceRight || spaceRight > spaceLeft ?
|
|
103
|
+
hasEnoughSpaceRight || spaceRight > spaceLeft ? Direction.Right : Direction.Left;
|
|
106
104
|
}
|
|
107
105
|
|
|
108
|
-
if (localPreferredPosition.value.x ===
|
|
106
|
+
if (localPreferredPosition.value.x === Direction.Left) {
|
|
109
107
|
preferredOpenDirectionX.value =
|
|
110
|
-
hasEnoughSpaceLeft || spaceLeft > spaceRight ?
|
|
108
|
+
hasEnoughSpaceLeft || spaceLeft > spaceRight ? Direction.Left : Direction.Right;
|
|
111
109
|
}
|
|
112
110
|
}
|
|
113
111
|
|
|
@@ -1,34 +1,36 @@
|
|
|
1
1
|
import { onMounted, ref, watch, computed, onBeforeUnmount } from "vue";
|
|
2
|
-
import { isSSR } from "../
|
|
2
|
+
import { isSSR } from "../utils/helper.ts";
|
|
3
3
|
|
|
4
4
|
import type { Ref } from "vue";
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"2xl"
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"2xl"
|
|
22
|
-
}
|
|
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}`;
|
|
23
25
|
|
|
24
26
|
const mobileDevices = ["xs", "sm"];
|
|
25
27
|
const portableDevices = ["xs", "sm", "md"];
|
|
26
28
|
|
|
27
29
|
export default function useBreakpoint() {
|
|
28
|
-
let timeout: number;
|
|
30
|
+
let timeout: number | undefined;
|
|
29
31
|
|
|
30
|
-
const windowWidth
|
|
31
|
-
const currentBreakpoint = ref(
|
|
32
|
+
const windowWidth = ref(0);
|
|
33
|
+
const currentBreakpoint: Ref<Breakpoint> = ref(BreakpointName.Xs);
|
|
32
34
|
|
|
33
35
|
const isMobileBreakpoint = computed(() => {
|
|
34
36
|
return mobileDevices.includes(currentBreakpoint.value);
|
|
@@ -39,15 +41,16 @@ export default function useBreakpoint() {
|
|
|
39
41
|
});
|
|
40
42
|
|
|
41
43
|
const isLaptopBreakpoint = computed(() => {
|
|
42
|
-
return currentBreakpoint.value ===
|
|
44
|
+
return currentBreakpoint.value === BreakpointName.Lg;
|
|
43
45
|
});
|
|
44
46
|
|
|
45
47
|
const isPortableBreakpoint = computed(() => {
|
|
46
48
|
return portableDevices.includes(currentBreakpoint.value);
|
|
47
49
|
});
|
|
48
50
|
|
|
51
|
+
// TODO: Why do we need this? Maybe we should rename it.
|
|
49
52
|
const elementSize = computed(() => {
|
|
50
|
-
return isMobileBreakpoint.value ?
|
|
53
|
+
return isMobileBreakpoint.value ? BreakpointName.Md : BreakpointName.Lg;
|
|
51
54
|
});
|
|
52
55
|
|
|
53
56
|
onMounted(() => {
|
|
@@ -78,21 +81,21 @@ export default function useBreakpoint() {
|
|
|
78
81
|
});
|
|
79
82
|
}
|
|
80
83
|
|
|
81
|
-
function setBreakpoint(newWindowWidth: number
|
|
84
|
+
function setBreakpoint(newWindowWidth: number) {
|
|
82
85
|
if (newWindowWidth === undefined) return;
|
|
83
86
|
|
|
84
87
|
currentBreakpoint.value = "xs";
|
|
85
88
|
|
|
86
|
-
if (newWindowWidth >=
|
|
87
|
-
currentBreakpoint.value =
|
|
88
|
-
} else if (newWindowWidth >=
|
|
89
|
-
currentBreakpoint.value =
|
|
90
|
-
} else if (newWindowWidth >=
|
|
91
|
-
currentBreakpoint.value =
|
|
92
|
-
} else if (newWindowWidth >=
|
|
93
|
-
currentBreakpoint.value =
|
|
94
|
-
} else if (newWindowWidth >=
|
|
95
|
-
currentBreakpoint.value = "2xl";
|
|
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"];
|
|
96
99
|
}
|
|
97
100
|
}
|
|
98
101
|
|
|
@@ -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
|
+
}
|