vueless 0.0.478-beta.5 → 0.0.478-beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/adatper.locale/vue-i18n.ts +14 -0
- package/adatper.locale/{vueless.js → vueless.ts} +67 -19
- 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/package.json +2 -1
- package/types.ts +4 -1
- package/ui.button/storybook/stories.js +8 -3
- package/ui.text-badge/config.ts +1 -1
- package/ui.text-badge/types.ts +3 -3
- package/utils/utilStorybook.js +17 -18
- package/utilsTs/utilStorybook.ts +19 -18
- package/adatper.locale/vue-i18n.js +0 -11
- /package/adatper.locale/locales/{en.js → en.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
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
|
}
|
|
@@ -1,41 +1,44 @@
|
|
|
1
|
-
import { onBeforeUnmount, onMounted, toValue, watch } from "vue";
|
|
1
|
+
import { computed, onBeforeUnmount, onMounted, toValue, watch } from "vue";
|
|
2
2
|
import { isSSR } from "../utilsTs/utilHelper.ts";
|
|
3
3
|
|
|
4
|
-
import type {
|
|
4
|
+
import type { TemplateRefElement } from "../types.ts";
|
|
5
5
|
|
|
6
6
|
export function useMutationObserver(
|
|
7
|
-
target:
|
|
8
|
-
|
|
7
|
+
target: TemplateRefElement,
|
|
8
|
+
callback: MutationCallback,
|
|
9
9
|
config = { childList: true, attributes: true, characterData: true },
|
|
10
10
|
) {
|
|
11
11
|
if (isSSR) return;
|
|
12
12
|
|
|
13
|
-
const observer = new MutationObserver(
|
|
13
|
+
const observer = new MutationObserver(callback);
|
|
14
|
+
const targetValue = computed(() => toValue(target));
|
|
14
15
|
|
|
15
16
|
onMounted(() => {
|
|
16
|
-
if (!
|
|
17
|
+
if (!targetValue.value) return;
|
|
17
18
|
|
|
18
|
-
if (Array.isArray(
|
|
19
|
-
|
|
19
|
+
if (Array.isArray(targetValue.value)) {
|
|
20
|
+
targetValue.value.forEach((element) => {
|
|
20
21
|
observer.observe(element, config);
|
|
21
22
|
});
|
|
22
23
|
} else {
|
|
23
|
-
observer.observe(
|
|
24
|
+
observer.observe(targetValue.value, config);
|
|
24
25
|
}
|
|
25
26
|
});
|
|
26
27
|
|
|
27
28
|
watch(
|
|
28
|
-
|
|
29
|
+
targetValue,
|
|
29
30
|
() => {
|
|
30
|
-
if (
|
|
31
|
-
|
|
31
|
+
if (!targetValue.value) return;
|
|
32
|
+
|
|
33
|
+
if (Array.isArray(targetValue.value)) {
|
|
34
|
+
targetValue.value.forEach((element) => {
|
|
32
35
|
observer.observe(element, config);
|
|
33
36
|
});
|
|
34
37
|
|
|
35
38
|
return;
|
|
36
39
|
}
|
|
37
40
|
|
|
38
|
-
observer.observe(
|
|
41
|
+
observer.observe(targetValue.value, config);
|
|
39
42
|
},
|
|
40
43
|
{
|
|
41
44
|
deep: true,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vueless",
|
|
3
|
-
"version": "0.0.478-beta.
|
|
3
|
+
"version": "0.0.478-beta.7",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Vue Styleless UI Component Library, powered by Tailwind CSS.",
|
|
6
6
|
"keywords": [
|
|
@@ -81,6 +81,7 @@
|
|
|
81
81
|
"vite": "^5.4.9",
|
|
82
82
|
"vite-plugin-compression": "^0.5.1",
|
|
83
83
|
"vue": "^3.5.4",
|
|
84
|
+
"vue-i18n": "^10.0.4",
|
|
84
85
|
"vue-router": "^4.3.2",
|
|
85
86
|
"vue-tsc": "^2.1.6"
|
|
86
87
|
},
|
package/types.ts
CHANGED
|
@@ -4,7 +4,10 @@ import { hasSlotContent } from "./composablesTs/useUI.ts";
|
|
|
4
4
|
import UTextDefaultConfig from "./ui.text-block/config.ts";
|
|
5
5
|
import UButtonDefaultConfig from "./ui.button/config.ts";
|
|
6
6
|
import UBadgeDefaultConfig from "./ui.text-badge/config.ts";
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
import type { ComputedRef, MaybeRef } from "vue";
|
|
9
|
+
|
|
10
|
+
export type TemplateRefElement = MaybeRef<HTMLElement | HTMLElement[] | null>;
|
|
8
11
|
|
|
9
12
|
export interface ThemeConfig {
|
|
10
13
|
/**
|
|
@@ -5,9 +5,6 @@ import UIcon from "../../ui.image-icon/UIcon.vue";
|
|
|
5
5
|
import URow from "../../ui.container-row/URow.vue";
|
|
6
6
|
import UCol from "../../ui.container-col/UCol.vue";
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* The `UButton` component. | [View on GitHub](https://github.com/vuelessjs/vueless/tree/main/src/ui.button)
|
|
10
|
-
*/
|
|
11
8
|
export default {
|
|
12
9
|
id: "1010",
|
|
13
10
|
title: "Buttons & Links / Button",
|
|
@@ -18,6 +15,14 @@ export default {
|
|
|
18
15
|
argTypes: {
|
|
19
16
|
...getArgTypes(UButton.__name),
|
|
20
17
|
},
|
|
18
|
+
// TODO: Generate by function same like `getArgTypes(UButton.__name)`
|
|
19
|
+
parameters: {
|
|
20
|
+
docs: {
|
|
21
|
+
description: {
|
|
22
|
+
component: `The \`${UButton.__name}\` component. | [View on GitHub](https://github.com/vuelessjs/vueless/tree/main/src/ui.button)`,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
},
|
|
21
26
|
};
|
|
22
27
|
|
|
23
28
|
const DefaultTemplate = (args) => ({
|
package/ui.text-badge/config.ts
CHANGED
package/ui.text-badge/types.ts
CHANGED
|
@@ -14,7 +14,7 @@ export interface UBadgeProps {
|
|
|
14
14
|
/**
|
|
15
15
|
* Add border to the `thirdary` variant.
|
|
16
16
|
*/
|
|
17
|
-
bordered
|
|
17
|
+
bordered?: boolean;
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* Badge size.
|
|
@@ -65,12 +65,12 @@ export interface UBadgeProps {
|
|
|
65
65
|
/**
|
|
66
66
|
* Set badge corners rounded.
|
|
67
67
|
*/
|
|
68
|
-
round
|
|
68
|
+
round?: boolean;
|
|
69
69
|
|
|
70
70
|
/**
|
|
71
71
|
* Controls the keyboard “Tab” focus order of elements.
|
|
72
72
|
*/
|
|
73
|
-
tabindex
|
|
73
|
+
tabindex?: string;
|
|
74
74
|
|
|
75
75
|
/**
|
|
76
76
|
* Component config object.
|
package/utils/utilStorybook.js
CHANGED
|
@@ -63,24 +63,12 @@ export function getArgTypes(componentName) {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
if (type.includes("|")) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
table: {
|
|
73
|
-
defaultValue: { summary: attribute.default || "" },
|
|
74
|
-
},
|
|
75
|
-
};
|
|
76
|
-
} else {
|
|
77
|
-
types[attribute.name] = {
|
|
78
|
-
control: type.split("|")[0],
|
|
79
|
-
table: {
|
|
80
|
-
defaultValue: { summary: attribute.default || "" },
|
|
81
|
-
},
|
|
82
|
-
};
|
|
83
|
-
}
|
|
66
|
+
types[attribute.name] = {
|
|
67
|
+
control: type.split("|")[0],
|
|
68
|
+
table: {
|
|
69
|
+
defaultValue: { summary: attribute.default || "" },
|
|
70
|
+
},
|
|
71
|
+
};
|
|
84
72
|
}
|
|
85
73
|
|
|
86
74
|
if (attribute.description?.includes("@ignore")) {
|
|
@@ -90,6 +78,17 @@ export function getArgTypes(componentName) {
|
|
|
90
78
|
},
|
|
91
79
|
};
|
|
92
80
|
}
|
|
81
|
+
|
|
82
|
+
if (attribute.enum) {
|
|
83
|
+
types[attribute.name] = {
|
|
84
|
+
options: attribute.enum,
|
|
85
|
+
control: "select",
|
|
86
|
+
table: {
|
|
87
|
+
defaultValue: { summary: attribute.default || "" },
|
|
88
|
+
type: { summary: attribute.enum.join(" | ") },
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
}
|
|
93
92
|
});
|
|
94
93
|
|
|
95
94
|
component.slots?.forEach((slot) => {
|
package/utilsTs/utilStorybook.ts
CHANGED
|
@@ -27,6 +27,7 @@ interface Tag {
|
|
|
27
27
|
|
|
28
28
|
interface Attribute {
|
|
29
29
|
name: string;
|
|
30
|
+
enum: string[];
|
|
30
31
|
required?: boolean;
|
|
31
32
|
description?: string;
|
|
32
33
|
value: AttributeValue;
|
|
@@ -97,6 +98,7 @@ interface TableConfig {
|
|
|
97
98
|
disable?: boolean;
|
|
98
99
|
defaultValue?: { summary: unknown };
|
|
99
100
|
category?: "slots" | "expose" | "Storybook Events";
|
|
101
|
+
type?: Record<string, string | string[]>;
|
|
100
102
|
}
|
|
101
103
|
|
|
102
104
|
/* Load Web-Types from the project root. */
|
|
@@ -168,24 +170,23 @@ export function getArgTypes(componentName: string | undefined) {
|
|
|
168
170
|
}
|
|
169
171
|
|
|
170
172
|
if (type.includes("|")) {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
}
|
|
173
|
+
types[attribute.name] = {
|
|
174
|
+
control: type.split("|")[0] as ArgType["control"],
|
|
175
|
+
table: {
|
|
176
|
+
defaultValue: { summary: attribute.default || "" },
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (attribute.enum) {
|
|
182
|
+
types[attribute.name] = {
|
|
183
|
+
options: attribute.enum,
|
|
184
|
+
control: "select",
|
|
185
|
+
table: {
|
|
186
|
+
defaultValue: { summary: attribute.default || "" },
|
|
187
|
+
type: { summary: attribute.enum.join(" | ") },
|
|
188
|
+
},
|
|
189
|
+
};
|
|
189
190
|
}
|
|
190
191
|
|
|
191
192
|
if (attribute.description?.includes("@ignore")) {
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export default function createVueI18nAdapter(i18n) {
|
|
2
|
-
return {
|
|
3
|
-
name: "vue-i18n",
|
|
4
|
-
locale: i18n.global.locale,
|
|
5
|
-
fallback: i18n.global.fallbackLocale,
|
|
6
|
-
messages: i18n.global.messages,
|
|
7
|
-
t: (key, ...params) => i18n.global.t(key, params),
|
|
8
|
-
tm: i18n.global.tm,
|
|
9
|
-
n: i18n.global.n,
|
|
10
|
-
};
|
|
11
|
-
}
|
|
File without changes
|