vueless 0.0.478-beta.1 → 0.0.478-beta.10
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/assets/icons/sentiment_satisfied.svg +1 -0
- package/composables/useUI.js +1 -204
- package/composablesTs/useAutoPosition.ts +32 -43
- package/composablesTs/useBreakpoint.ts +36 -33
- package/composablesTs/useLocale.ts +6 -9
- package/composablesTs/useMutationObserver.ts +16 -13
- package/composablesTs/useUI.ts +12 -238
- package/constants.js +0 -1
- package/directivesTs/clickOutside/storybook/Docs.mdx +11 -0
- package/directivesTs/clickOutside/storybook/stories.ts +109 -0
- package/directivesTs/clickOutside/types.ts +22 -0
- package/directivesTs/clickOutside/vClickOutside.ts +96 -0
- package/directivesTs/index.ts +2 -0
- package/directivesTs/tooltip/storybook/Docs.mdx +11 -0
- package/directivesTs/tooltip/storybook/stories.ts +88 -0
- package/directivesTs/tooltip/types.ts +14 -0
- package/directivesTs/tooltip/vTooltip.ts +82 -0
- package/package.json +5 -5
- package/types.ts +17 -3
- package/ui.button/config.js +0 -12
- package/ui.button/storybook/stories.js +10 -5
- package/ui.button-link/config.js +0 -9
- package/ui.button-link/storybook/stories.js +1 -1
- package/ui.button-toggle/storybook/stories.js +1 -1
- package/ui.container-divider/storybook/stories.js +1 -1
- package/ui.container-modal/storybook/stories.js +1 -1
- package/ui.container-modal-confirm/storybook/stories.js +1 -1
- package/ui.container-row/storybook/stories.js +1 -1
- package/ui.data-table/UTable.vue +1 -1
- package/ui.dropdown-badge/config.js +0 -1
- package/ui.dropdown-badge/storybook/stories.js +1 -1
- package/ui.dropdown-button/config.js +0 -1
- package/ui.dropdown-button/storybook/stories.js +2 -2
- package/ui.dropdown-link/storybook/stories.js +1 -1
- package/ui.dropdown-list/storybook/stories.js +1 -1
- package/ui.form-checkbox/config.js +0 -9
- package/ui.form-checkbox/storybook/stories.js +1 -1
- package/ui.form-checkbox-group/storybook/stories.js +1 -1
- package/ui.form-checkbox-multi-state/storybook/stories.js +1 -1
- package/ui.form-color-picker/config.js +0 -7
- package/ui.form-color-picker/storybook/stories.js +1 -1
- package/ui.form-date-picker/storybook/stories.js +2 -2
- package/ui.form-date-picker-range/storybook/stories.js +1 -1
- package/ui.form-input/storybook/stories.js +1 -1
- package/ui.form-input-file/storybook/stories.js +1 -1
- package/ui.form-input-money/storybook/stories.js +1 -1
- package/ui.form-input-number/storybook/stories.js +1 -1
- package/ui.form-input-rating/storybook/stories.js +1 -1
- package/ui.form-input-search/storybook/stories.js +1 -1
- package/ui.form-label/storybook/stories.js +1 -1
- package/ui.form-radio/config.js +0 -6
- package/ui.form-radio-group/storybook/stories.js +1 -1
- package/ui.form-select/storybook/stories.js +1 -1
- package/ui.form-switch/config.js +0 -6
- package/ui.form-switch/storybook/stories.js +1 -1
- package/ui.form-textarea/storybook/stories.js +1 -1
- package/ui.image-avatar/config.js +0 -5
- package/ui.image-avatar/storybook/stories.js +1 -1
- package/ui.image-icon/UIcon.vue +20 -5
- package/ui.image-icon/config.js +0 -5
- package/ui.image-icon/storybook/stories.js +1 -1
- package/ui.loader/config.js +0 -1
- package/ui.loader/storybook/stories.js +1 -1
- package/ui.loader-overlay/config.js +0 -1
- package/ui.loader-progress/config.js +0 -1
- package/ui.loader-progress/storybook/stories.js +1 -1
- package/ui.navigation-progress/config.js +0 -9
- package/ui.navigation-progress/storybook/stories.js +1 -1
- package/ui.navigation-tabs/storybook/stories.js +1 -1
- package/ui.other-dot/config.js +0 -1
- package/ui.other-dot/storybook/stories.js +1 -1
- package/ui.text-alert/config.js +0 -7
- package/ui.text-alert/storybook/stories.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 +2 -2
- package/ui.text-badge/storybook/{stories.js → stories.ts} +25 -34
- package/ui.text-badge/types.ts +84 -0
- package/ui.text-badge/{useAttrs.js → useAttrs.ts} +10 -5
- package/ui.text-block/storybook/stories.ts +2 -2
- package/ui.text-empty/storybook/stories.js +1 -1
- package/ui.text-file/UFile.vue +0 -1
- package/ui.text-header/config.js +0 -1
- package/ui.text-header/storybook/stories.js +1 -1
- package/ui.text-money/config.js +0 -1
- package/ui.text-money/storybook/stories.js +1 -1
- package/utils/utilStorybook.js +17 -18
- package/utils/utilUI.js +205 -1
- package/utilsTs/utilStorybook.ts +19 -18
- package/utilsTs/utilTailwind.ts +3 -10
- package/utilsTs/utilTheme.ts +37 -13
- package/utilsTs/utilUI.ts +232 -1
- package/adatper.locale/vue-i18n.js +0 -11
- package/web-types.json +0 -9580
- /package/adatper.locale/locales/{en.js → en.ts} +0 -0
- /package/ui.text-badge/{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 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 -960 960 960"><path d="M624.57-531.57q22.97 0 39.2-16.22Q680-564.02 680-587t-16.23-39.21q-16.23-16.22-39.2-16.22-22.98 0-39.09 16.14-16.11 16.14-16.11 39.21 0 23.06 16.1 39.29 16.1 16.22 39.1 16.22Zm-289.14 0q22.98 0 39.09-16.14 16.11-16.14 16.11-39.21 0-23.06-16.1-39.29-16.1-16.22-39.1-16.22-22.97 0-39.2 16.22Q280-609.98 280-587t16.23 39.21q16.23 16.22 39.2 16.22ZM480-261q66 0 121.5-35.5T682-393h-55.11q-22.52 38.8-61.83 59.59-39.31 20.78-84.59 20.78-45.27 0-84.94-20.28-39.66-20.29-61.18-60.09H278q26 61 81 96.5T480-261Zm.01 186.98q-84.21 0-158.28-31.86-74.08-31.86-129.03-86.82-54.96-54.95-86.82-129.02-31.86-74.06-31.86-158.27 0-84.21 31.86-158.28 31.86-74.08 86.78-129.05 54.92-54.97 129-86.93 74.08-31.97 158.31-31.97t158.33 31.95q74.1 31.95 129.06 86.88 54.95 54.94 86.9 129.05 31.96 74.1 31.96 158.36 0 84.24-31.97 158.31-31.96 74.08-86.93 129-54.97 54.93-129.04 86.79-74.06 31.86-158.27 31.86ZM480-480Zm0 337.85q141.42 0 239.63-98.22 98.22-98.21 98.22-239.63 0-141.42-98.22-239.63-98.21-98.22-239.63-98.22-141.42 0-239.63 98.22-98.22 98.21-98.22 239.63 0 141.42 98.22 239.63 98.21 98.22 239.63 98.22Z"/></svg>
|
package/composables/useUI.js
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
computed,
|
|
12
12
|
} from "vue";
|
|
13
13
|
|
|
14
|
-
import { cx, cva, setColor, getColor, vuelessConfig } from "../utils/utilUI.js";
|
|
14
|
+
import { cx, cva, setColor, getColor, vuelessConfig, mergeConfigs } from "../utils/utilUI.js";
|
|
15
15
|
|
|
16
16
|
import { cloneDeep, isCSR } from "../utils/utilHelper.js";
|
|
17
17
|
import {
|
|
@@ -241,209 +241,6 @@ function getMergedConfig({ defaultConfig, globalConfig, propsConfig, vuelessStra
|
|
|
241
241
|
}
|
|
242
242
|
}
|
|
243
243
|
|
|
244
|
-
/**
|
|
245
|
-
* Recursively merge config objects with removing tailwind classes duplicates.
|
|
246
|
-
* @param {Object} defaultConfig
|
|
247
|
-
* @param {Object} globalConfig
|
|
248
|
-
* @param {Object} propsConfig
|
|
249
|
-
* @param {Object} config - final merged config.
|
|
250
|
-
* @param {boolean} isReplace - enables class replacement instead of merge.
|
|
251
|
-
* @param {boolean} isVarinants - if true, prevents adding a "base" key into nested objects.
|
|
252
|
-
*
|
|
253
|
-
* @returns {Object}
|
|
254
|
-
*/
|
|
255
|
-
function mergeConfigs({
|
|
256
|
-
defaultConfig,
|
|
257
|
-
globalConfig,
|
|
258
|
-
propsConfig,
|
|
259
|
-
config = {},
|
|
260
|
-
isReplace = false,
|
|
261
|
-
isVariants = false,
|
|
262
|
-
}) {
|
|
263
|
-
globalConfig = cloneDeep(globalConfig || {});
|
|
264
|
-
propsConfig = cloneDeep(propsConfig || {});
|
|
265
|
-
|
|
266
|
-
const isGlobalConfig = Object.keys(globalConfig).length;
|
|
267
|
-
const isPropsConfig = Object.keys(propsConfig).length;
|
|
268
|
-
|
|
269
|
-
// Add unique keys from defaultConfig to composedConfig
|
|
270
|
-
let composedConfig = cloneDeep(defaultConfig);
|
|
271
|
-
|
|
272
|
-
// Add unique keys from globalConfig to composedConfig
|
|
273
|
-
for (let key in globalConfig) {
|
|
274
|
-
if (!Object.keys(composedConfig).includes(key)) {
|
|
275
|
-
composedConfig[key] = globalConfig[key];
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
// Add unique keys from propsConfig to composedConfig
|
|
280
|
-
for (let key in propsConfig) {
|
|
281
|
-
if (!Object.keys(composedConfig).includes(key)) {
|
|
282
|
-
composedConfig[key] = propsConfig[key];
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
const {
|
|
287
|
-
i18n,
|
|
288
|
-
defaults,
|
|
289
|
-
strategy,
|
|
290
|
-
safelist,
|
|
291
|
-
component,
|
|
292
|
-
safelistColors,
|
|
293
|
-
defaultVariants,
|
|
294
|
-
compoundVariants,
|
|
295
|
-
} = SYSTEM_CONFIG_KEY;
|
|
296
|
-
|
|
297
|
-
for (let key in composedConfig) {
|
|
298
|
-
if (isGlobalConfig || isPropsConfig) {
|
|
299
|
-
if (key === safelist || key === safelistColors) {
|
|
300
|
-
if (propsConfig[key]) {
|
|
301
|
-
// eslint-disable-next-line no-console
|
|
302
|
-
console.warn(`Passing '${key}' key in 'config' prop is not allowed.`);
|
|
303
|
-
}
|
|
304
|
-
} else if (key === component) {
|
|
305
|
-
config[key] = propsConfig[key] || defaultConfig[key];
|
|
306
|
-
|
|
307
|
-
if (globalConfig[key]) {
|
|
308
|
-
// eslint-disable-next-line no-console
|
|
309
|
-
console.warn(`Passing '${key}' key in 'config' prop or by global config is not allowed.`);
|
|
310
|
-
}
|
|
311
|
-
} else if (key === strategy) {
|
|
312
|
-
config[key] = propsConfig[key] || globalConfig[key] || defaultConfig[key];
|
|
313
|
-
} else if (key === defaults || key === defaultVariants) {
|
|
314
|
-
config[key] = { ...defaultConfig[key], ...globalConfig[key], ...propsConfig[key] };
|
|
315
|
-
} else if (key === compoundVariants) {
|
|
316
|
-
config[key] = mergeCompoundVariants({
|
|
317
|
-
defaultConfig: composedConfig,
|
|
318
|
-
globalConfig,
|
|
319
|
-
propsConfig,
|
|
320
|
-
isReplace,
|
|
321
|
-
key,
|
|
322
|
-
});
|
|
323
|
-
} else {
|
|
324
|
-
const isObjectComposedConfig = typeof composedConfig[key] === "object";
|
|
325
|
-
const isObjectGlobalConfig = typeof globalConfig[key] === "object";
|
|
326
|
-
const isObjectPropsConfig = typeof propsConfig[key] === "object";
|
|
327
|
-
|
|
328
|
-
const isObject = isObjectComposedConfig || isObjectGlobalConfig || isObjectPropsConfig;
|
|
329
|
-
const isEmpty = composedConfig[key] === null;
|
|
330
|
-
const isI18n = key === i18n;
|
|
331
|
-
|
|
332
|
-
if (key === "variants" && !isVariants) {
|
|
333
|
-
isVariants = true;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
config[key] =
|
|
337
|
-
isObject && !isEmpty && !isI18n
|
|
338
|
-
? mergeConfigs({
|
|
339
|
-
defaultConfig: stringToObject(composedConfig[key], { addBase: !isVariants }),
|
|
340
|
-
globalConfig: stringToObject(globalConfig[key], { addBase: !isVariants }),
|
|
341
|
-
propsConfig: stringToObject(propsConfig[key], { addBase: !isVariants }),
|
|
342
|
-
config: stringToObject(composedConfig[key], { addBase: !isVariants }),
|
|
343
|
-
isReplace,
|
|
344
|
-
isVariants,
|
|
345
|
-
})
|
|
346
|
-
: isReplace || isI18n
|
|
347
|
-
? propsConfig[key] || globalConfig[key] || defaultConfig[key]
|
|
348
|
-
: cx([defaultConfig[key], globalConfig[key], propsConfig[key]]);
|
|
349
|
-
}
|
|
350
|
-
} else {
|
|
351
|
-
config[key] = composedConfig[key];
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
return config;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
/**
|
|
359
|
-
Turn simplified nested component config to regular config.
|
|
360
|
-
@param {Object | String} value
|
|
361
|
-
@param {Boolean} addBase
|
|
362
|
-
@returns {Object}
|
|
363
|
-
*/
|
|
364
|
-
function stringToObject(value, { addBase = false }) {
|
|
365
|
-
if (value === undefined) value = "";
|
|
366
|
-
|
|
367
|
-
return typeof value !== "object" ? addBase && { base: value } : value;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
/**
|
|
371
|
-
* Merge CVA compound variants arrays.
|
|
372
|
-
* @param {Object} defaultConfig
|
|
373
|
-
* @param {Object} globalConfig
|
|
374
|
-
* @param {Object} propsConfig
|
|
375
|
-
* @param {string} key
|
|
376
|
-
* @param {boolean} isReplace - enables class replacement instead of merge.
|
|
377
|
-
*
|
|
378
|
-
* @returns {Array}
|
|
379
|
-
*/
|
|
380
|
-
function mergeCompoundVariants({ defaultConfig, globalConfig, propsConfig, key, isReplace }) {
|
|
381
|
-
if (
|
|
382
|
-
(globalConfig[key] && !Array.isArray(globalConfig[key])) ||
|
|
383
|
-
(propsConfig[key] && !Array.isArray(propsConfig[key])) ||
|
|
384
|
-
(defaultConfig[key] && !Array.isArray(defaultConfig[key]))
|
|
385
|
-
) {
|
|
386
|
-
// eslint-disable-next-line no-console
|
|
387
|
-
console.error("CompoundVariants should be an array.");
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
let globalConfigUniqueItems = cloneDeep(globalConfig[key] || []);
|
|
391
|
-
let propsConfigUniqueItems = cloneDeep(propsConfig[key] || []);
|
|
392
|
-
|
|
393
|
-
const config = defaultConfig[key].map((defaultConfigItem) => {
|
|
394
|
-
/**
|
|
395
|
-
* Compare two objects by keys for match.
|
|
396
|
-
* @param {Object} configItem
|
|
397
|
-
* @returns {Boolean}
|
|
398
|
-
*/
|
|
399
|
-
function isSameItem(configItem) {
|
|
400
|
-
const hasConfigItemKeys = Object.keys(defaultConfigItem)
|
|
401
|
-
.map((key) => defaultConfigItem[key] === configItem[key] || key === "class")
|
|
402
|
-
.every((item) => !!item);
|
|
403
|
-
|
|
404
|
-
const hasDefaultConfigItemKeys = Object.keys(configItem)
|
|
405
|
-
.map((key) => defaultConfigItem[key] === configItem[key] || key === "class")
|
|
406
|
-
.every((item) => !!item);
|
|
407
|
-
|
|
408
|
-
return hasConfigItemKeys && hasDefaultConfigItemKeys;
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
/**
|
|
412
|
-
* Find the same compound variant item in custom config if exist.
|
|
413
|
-
* @param {Object} config
|
|
414
|
-
* @returns {Object|undefined}
|
|
415
|
-
*/
|
|
416
|
-
function findItem(config = []) {
|
|
417
|
-
const globalConfigUniqueItemIndex = globalConfigUniqueItems.findIndex(isSameItem);
|
|
418
|
-
const propsConfigUniqueItemIndex = propsConfigUniqueItems.findIndex(isSameItem);
|
|
419
|
-
|
|
420
|
-
if (~globalConfigUniqueItemIndex) {
|
|
421
|
-
globalConfigUniqueItems.splice(globalConfigUniqueItemIndex, 1);
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
if (~propsConfigUniqueItemIndex) {
|
|
425
|
-
propsConfigUniqueItems.splice(propsConfigUniqueItemIndex, 1);
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
return config.find(isSameItem);
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
const globalConfigItem = findItem(globalConfig[key]);
|
|
432
|
-
const propsConfigItem = findItem(propsConfig[key]);
|
|
433
|
-
|
|
434
|
-
return globalConfigItem || propsConfigItem
|
|
435
|
-
? {
|
|
436
|
-
...defaultConfigItem,
|
|
437
|
-
class: isReplace
|
|
438
|
-
? propsConfigItem?.class || globalConfigItem?.class || defaultConfigItem.class
|
|
439
|
-
: cx([defaultConfigItem.class, globalConfigItem?.class, propsConfigItem?.class]),
|
|
440
|
-
}
|
|
441
|
-
: defaultConfigItem;
|
|
442
|
-
});
|
|
443
|
-
|
|
444
|
-
return [...config, ...globalConfigUniqueItems, ...propsConfigUniqueItems];
|
|
445
|
-
}
|
|
446
|
-
|
|
447
244
|
/**
|
|
448
245
|
* Merge component classes from "class" attribute into final config.
|
|
449
246
|
* @param {Object} config
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
import { computed, toValue, ref } from "vue";
|
|
2
2
|
import { isSSR } from "../utilsTs/utilHelper.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,62 +11,56 @@ export enum Position {
|
|
|
16
11
|
Auto = "auto",
|
|
17
12
|
}
|
|
18
13
|
|
|
19
|
-
|
|
20
|
-
export
|
|
21
|
-
left: "left",
|
|
22
|
-
right: "right",
|
|
23
|
-
top: "top",
|
|
24
|
-
bottom: "bottom",
|
|
25
|
-
auto: "auto",
|
|
26
|
-
};
|
|
14
|
+
export type Align = `${Direction}`;
|
|
15
|
+
export type Position = { x: Align; y: Align };
|
|
27
16
|
|
|
28
17
|
export function useAutoPosition(
|
|
29
|
-
anchorElement:
|
|
30
|
-
targetElement:
|
|
31
|
-
position:
|
|
32
|
-
preferredPosition:
|
|
18
|
+
anchorElement: MaybeRef<HTMLElement | null>,
|
|
19
|
+
targetElement: MaybeRef<HTMLElement | null>,
|
|
20
|
+
position: Reactive<Position> | ComputedRef<Position>,
|
|
21
|
+
preferredPosition: Reactive<Position> | ComputedRef<Position>,
|
|
33
22
|
) {
|
|
34
23
|
const localAnchorElement = computed(() => toValue(anchorElement));
|
|
35
24
|
const localTargetElement = computed(() => toValue(targetElement));
|
|
36
25
|
const localPosition = computed(() => toValue(position));
|
|
37
26
|
const localPreferredPosition = computed(() => toValue(preferredPosition));
|
|
38
27
|
|
|
39
|
-
const preferredOpenDirectionY = ref(localPreferredPosition.value
|
|
40
|
-
const preferredOpenDirectionX = ref(localPreferredPosition.value
|
|
28
|
+
const preferredOpenDirectionY = ref(localPreferredPosition.value.y || Direction.Bottom);
|
|
29
|
+
const preferredOpenDirectionX = ref(localPreferredPosition.value.x || Direction.Left);
|
|
41
30
|
|
|
42
31
|
const isTop = computed(() => {
|
|
43
|
-
if (localPosition.value.y !==
|
|
44
|
-
return localPosition.value.y ===
|
|
32
|
+
if (localPosition.value.y !== Direction.Auto) {
|
|
33
|
+
return localPosition.value.y === Direction.Top;
|
|
45
34
|
}
|
|
46
35
|
|
|
47
|
-
return preferredOpenDirectionY.value ===
|
|
36
|
+
return preferredOpenDirectionY.value === Direction.Top;
|
|
48
37
|
});
|
|
49
38
|
|
|
50
39
|
const isLeft = computed(() => {
|
|
51
|
-
if (localPosition.value.x !==
|
|
52
|
-
return localPosition.value.x ===
|
|
40
|
+
if (localPosition.value.x !== Direction.Auto) {
|
|
41
|
+
return localPosition.value.x === Direction.Left;
|
|
53
42
|
}
|
|
54
43
|
|
|
55
|
-
return preferredOpenDirectionX.value ===
|
|
44
|
+
return preferredOpenDirectionX.value === Direction.Left;
|
|
56
45
|
});
|
|
57
46
|
|
|
58
47
|
const isBottom = computed(() => {
|
|
59
|
-
if (localPosition.value.y !==
|
|
60
|
-
return localPosition.value.y ===
|
|
48
|
+
if (localPosition.value.y !== Direction.Auto) {
|
|
49
|
+
return localPosition.value.y === Direction.Bottom;
|
|
61
50
|
}
|
|
62
51
|
|
|
63
|
-
return preferredOpenDirectionY.value ===
|
|
52
|
+
return preferredOpenDirectionY.value === Direction.Bottom;
|
|
64
53
|
});
|
|
65
54
|
|
|
66
55
|
const isRight = computed(() => {
|
|
67
|
-
if (localPosition.value.x !==
|
|
68
|
-
return localPosition.value.x ===
|
|
56
|
+
if (localPosition.value.x !== Direction.Auto) {
|
|
57
|
+
return localPosition.value.x === Direction.Right;
|
|
69
58
|
}
|
|
70
59
|
|
|
71
|
-
return preferredOpenDirectionX.value ===
|
|
60
|
+
return preferredOpenDirectionX.value === Direction.Right;
|
|
72
61
|
});
|
|
73
62
|
|
|
74
|
-
function adjustPositionY()
|
|
63
|
+
function adjustPositionY() {
|
|
75
64
|
if (isSSR || !localAnchorElement.value || !localTargetElement.value) return;
|
|
76
65
|
|
|
77
66
|
const spaceAbove = localAnchorElement.value.getBoundingClientRect().top;
|
|
@@ -81,18 +70,18 @@ export function useAutoPosition(
|
|
|
81
70
|
const hasEnoughSpaceAbove =
|
|
82
71
|
spaceAbove > localTargetElement.value.getBoundingClientRect().height;
|
|
83
72
|
|
|
84
|
-
if (localPreferredPosition.value.y ===
|
|
73
|
+
if (localPreferredPosition.value.y === Direction.Bottom) {
|
|
85
74
|
preferredOpenDirectionY.value =
|
|
86
|
-
hasEnoughSpaceBelow || spaceBelow > spaceAbove ?
|
|
75
|
+
hasEnoughSpaceBelow || spaceBelow > spaceAbove ? Direction.Bottom : Direction.Top;
|
|
87
76
|
}
|
|
88
77
|
|
|
89
|
-
if (localPreferredPosition.value.y ===
|
|
78
|
+
if (localPreferredPosition.value.y === Direction.Top) {
|
|
90
79
|
preferredOpenDirectionY.value =
|
|
91
|
-
hasEnoughSpaceAbove || spaceAbove > spaceBelow ?
|
|
80
|
+
hasEnoughSpaceAbove || spaceAbove > spaceBelow ? Direction.Top : Direction.Bottom;
|
|
92
81
|
}
|
|
93
82
|
}
|
|
94
83
|
|
|
95
|
-
function adjustPositionX()
|
|
84
|
+
function adjustPositionX() {
|
|
96
85
|
if (isSSR || !localAnchorElement.value || !localTargetElement.value) return;
|
|
97
86
|
|
|
98
87
|
const spaceRight = localAnchorElement.value.getBoundingClientRect().right;
|
|
@@ -100,14 +89,14 @@ export function useAutoPosition(
|
|
|
100
89
|
const hasEnoughSpaceLeft = spaceLeft > localTargetElement.value.getBoundingClientRect().width;
|
|
101
90
|
const hasEnoughSpaceRight = spaceRight > localTargetElement.value.getBoundingClientRect().width;
|
|
102
91
|
|
|
103
|
-
if (localPreferredPosition.value.x ===
|
|
92
|
+
if (localPreferredPosition.value.x === Direction.Right) {
|
|
104
93
|
preferredOpenDirectionX.value =
|
|
105
|
-
hasEnoughSpaceRight || spaceRight > spaceLeft ?
|
|
94
|
+
hasEnoughSpaceRight || spaceRight > spaceLeft ? Direction.Right : Direction.Left;
|
|
106
95
|
}
|
|
107
96
|
|
|
108
|
-
if (localPreferredPosition.value.x ===
|
|
97
|
+
if (localPreferredPosition.value.x === Direction.Left) {
|
|
109
98
|
preferredOpenDirectionX.value =
|
|
110
|
-
hasEnoughSpaceLeft || spaceLeft > spaceRight ?
|
|
99
|
+
hasEnoughSpaceLeft || spaceLeft > spaceRight ? Direction.Left : Direction.Right;
|
|
111
100
|
}
|
|
112
101
|
}
|
|
113
102
|
|
|
@@ -3,32 +3,34 @@ import { isSSR } from "../utilsTs/utilHelper.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
|
|
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
import { inject } from "vue";
|
|
2
|
-
import createVuelessAdapter from "../adatper.locale/vueless.
|
|
2
|
+
import createVuelessAdapter from "../adatper.locale/vueless.ts";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
import type { LocaleInstance, LocaleOptions } from "../adatper.locale/vueless.ts";
|
|
5
|
+
import type { InjectionKey } from "vue";
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
return obj.name !== null;
|
|
8
|
-
}
|
|
7
|
+
export const LocaleSymbol: InjectionKey<LocaleInstance> = Symbol.for("vueless:locale");
|
|
9
8
|
|
|
10
|
-
export function createLocale(options) {
|
|
9
|
+
export function createLocale(options: LocaleOptions) {
|
|
11
10
|
const i18n =
|
|
12
|
-
options?.adapter &&
|
|
13
|
-
? options?.adapter
|
|
14
|
-
: createVuelessAdapter(options);
|
|
11
|
+
options?.adapter && options?.adapter?.name ? options?.adapter : createVuelessAdapter(options);
|
|
15
12
|
|
|
16
13
|
return { ...i18n };
|
|
17
14
|
}
|