@oiij/naive-ui 0.0.76 → 0.0.78
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/dist/components/config-providers/ConfigProviders.vue.d.ts +2 -2
- package/dist/components/config-providers/index.d.ts +16 -7
- package/dist/components/copy-button/CopyButton.js +2 -2
- package/dist/components/copy-button/CopyButton.vue.d.ts +4 -4
- package/dist/components/copy-button/index.d.ts +6 -3
- package/dist/components/data-table-plus/DataTablePlus.js +74 -125
- package/dist/components/data-table-plus/DataTablePlus.vue.d.ts +46 -111
- package/dist/components/data-table-plus/index.d.ts +52 -32
- package/dist/components/index.d.ts +2 -4
- package/dist/components/loading-provider/LoadingProvider.js +2 -2
- package/dist/components/loading-provider/LoadingProvider.vue.d.ts +2 -2
- package/dist/components/loading-provider/index.d.ts +19 -10
- package/dist/components/loading-provider/index.js +5 -2
- package/dist/components/preset-form/PresetForm.js +42 -21
- package/dist/components/preset-form/PresetForm.vue.d.ts +21 -21
- package/dist/components/preset-form/_utils.js +23 -8
- package/dist/components/preset-form/index.d.ts +32 -13
- package/dist/components/preset-input/PresetInput.vue.d.ts +3 -3
- package/dist/components/preset-input/index.d.ts +30 -20
- package/dist/components/preset-picker/PresetPicker.js +31 -34
- package/dist/components/preset-picker/PresetPicker.vue.d.ts +5 -10
- package/dist/components/preset-picker/index.d.ts +45 -31
- package/dist/components/preset-select/PresetSelect.js +23 -59
- package/dist/components/preset-select/PresetSelect.vue.d.ts +35 -39
- package/dist/components/preset-select/index.d.ts +56 -22
- package/dist/components/remote-request/RemoteRequest.js +7 -7
- package/dist/components/remote-request/RemoteRequest.vue.d.ts +13 -13
- package/dist/components/remote-request/index.d.ts +30 -8
- package/dist/components/search-input/SearchInput.vue.d.ts +4 -4
- package/dist/components/search-input/index.d.ts +10 -7
- package/dist/components/toggle-input/ToggleInput.vue.d.ts +4 -4
- package/dist/components/tooltip-button/TooltipButton.vue.d.ts +4 -4
- package/dist/components/tooltip-button/index.d.ts +5 -2
- package/dist/components/transition/BaseTransition.vue.d.ts +2 -2
- package/dist/components/transition/index.d.ts +4 -1
- package/dist/components.d.ts +2 -4
- package/dist/components.js +2 -3
- package/dist/composables/_helper.d.ts +7 -4
- package/dist/composables/_helper.js +47 -0
- package/dist/composables/index.d.ts +1 -1
- package/dist/composables/use-data-request.d.ts +25 -18
- package/dist/composables/use-data-request.js +22 -3
- package/dist/composables/use-loading.d.ts +6 -0
- package/dist/composables/use-loading.js +8 -2
- package/dist/composables/use-naive-form.d.ts +21 -13
- package/dist/composables/use-naive-form.js +48 -39
- package/dist/composables/use-naive-menu.d.ts +20 -5
- package/dist/composables/use-naive-menu.js +19 -61
- package/dist/composables/use-naive-theme.d.ts +27 -14
- package/dist/composables/use-naive-theme.js +22 -4
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/package.json +5 -7
- package/dist/components/_utils/prismjs.js +0 -16
- package/dist/components/icons/MageArrowUp.js +0 -29
- package/dist/components/type-writer/TypeWriter.js +0 -75
- package/dist/components/type-writer/TypeWriter.vue.d.ts +0 -22
- package/dist/components/type-writer/index.d.ts +0 -13
- package/dist/components/type-writer/type-writer.cssr.js +0 -27
|
@@ -1,29 +1,16 @@
|
|
|
1
1
|
import { createEventHook } from "@vueuse/core";
|
|
2
2
|
import { reactive, ref, toRaw, toValue, watchEffect } from "vue";
|
|
3
3
|
import { cloneDeep } from "es-toolkit/object";
|
|
4
|
+
import { isPlainObject } from "es-toolkit/predicate";
|
|
4
5
|
|
|
5
6
|
//#region src/composables/use-naive-form.ts
|
|
6
|
-
/**
|
|
7
|
-
* 检查值是否为对象类型
|
|
8
|
-
* @param value 要检查的值
|
|
9
|
-
* @returns 是否为对象类型
|
|
10
|
-
*/
|
|
11
|
-
function isObject(value) {
|
|
12
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* 清空对象值
|
|
16
|
-
* @param obj 要清空的对象
|
|
17
|
-
* @param rules 清空规则
|
|
18
|
-
* @returns 清空后的对象
|
|
19
|
-
*/
|
|
20
7
|
function clearObjectValues(obj, rules) {
|
|
21
8
|
const { string: _string = "", number: _number = null, boolean: _boolean = false } = rules ?? {};
|
|
22
9
|
if (Array.isArray(obj)) {
|
|
23
10
|
obj.length = 0;
|
|
24
11
|
return obj;
|
|
25
12
|
}
|
|
26
|
-
if (
|
|
13
|
+
if (isPlainObject(obj)) {
|
|
27
14
|
for (const key in obj) if (Object.prototype.hasOwnProperty.call(obj, key)) obj[key] = clearObjectValues(obj[key], rules);
|
|
28
15
|
return obj;
|
|
29
16
|
}
|
|
@@ -33,26 +20,19 @@ function clearObjectValues(obj, rules) {
|
|
|
33
20
|
return obj;
|
|
34
21
|
}
|
|
35
22
|
/**
|
|
36
|
-
* 深度合并对象
|
|
37
|
-
* @param target 目标对象
|
|
38
|
-
* @param source 源对象
|
|
39
|
-
* @returns 合并后的对象
|
|
40
|
-
*/
|
|
41
|
-
function deepMerge(target = {}, source = {}) {
|
|
42
|
-
for (const key in source) if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
43
|
-
const sourceValue = source[key];
|
|
44
|
-
const targetValue = target[key];
|
|
45
|
-
if (isObject(sourceValue) && isObject(targetValue)) deepMerge(targetValue, sourceValue);
|
|
46
|
-
else target[key] = sourceValue;
|
|
47
|
-
}
|
|
48
|
-
return target;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
23
|
* 用于处理 Naive UI 表单的组合式 API
|
|
52
24
|
* @template T 表单值类型
|
|
53
25
|
* @param formInstRef 表单实例引用
|
|
54
26
|
* @param options 配置选项
|
|
55
27
|
* @returns 表单操作对象
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* const formRef = ref<FormInst>()
|
|
31
|
+
* const { formValue, formRules, formProps, validate, reset, clear } = useNaiveForm(formRef, {
|
|
32
|
+
* value: { name: '', age: 0 },
|
|
33
|
+
* rules: { name: { required: true, message: '请输入姓名' } }
|
|
34
|
+
* })
|
|
35
|
+
* ```
|
|
56
36
|
*/
|
|
57
37
|
function useNaiveForm(formInstRef, options) {
|
|
58
38
|
const { value, rules, clearRules } = options ?? {};
|
|
@@ -62,7 +42,9 @@ function useNaiveForm(formInstRef, options) {
|
|
|
62
42
|
formValueRef.value = toValue(value) ?? {};
|
|
63
43
|
});
|
|
64
44
|
const formRulesRef = ref(toValue(rules));
|
|
65
|
-
watchEffect(() =>
|
|
45
|
+
watchEffect(() => {
|
|
46
|
+
formRulesRef.value = toValue(rules) ?? {};
|
|
47
|
+
});
|
|
66
48
|
const formProps = {
|
|
67
49
|
model: reactive(formValueRef.value),
|
|
68
50
|
rules: reactive(formRulesRef.value)
|
|
@@ -70,19 +52,31 @@ function useNaiveForm(formInstRef, options) {
|
|
|
70
52
|
const onValidatedEvent = createEventHook();
|
|
71
53
|
/**
|
|
72
54
|
* 设置表单值
|
|
73
|
-
* @param
|
|
55
|
+
* @param value - 要设置的值
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* setValue({ name: '张三' })
|
|
59
|
+
* ```
|
|
74
60
|
*/
|
|
75
|
-
function setValue(
|
|
76
|
-
Object.assign(formValueRef.value,
|
|
61
|
+
function setValue(value) {
|
|
62
|
+
Object.assign(formValueRef.value, value);
|
|
77
63
|
}
|
|
78
64
|
/**
|
|
79
65
|
* 验证表单
|
|
80
|
-
* @returns 验证结果Promise
|
|
66
|
+
* @returns 验证结果 Promise
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* try {
|
|
70
|
+
* await validate()
|
|
71
|
+
* } catch (errors) {
|
|
72
|
+
* console.log(errors)
|
|
73
|
+
* }
|
|
74
|
+
* ```
|
|
81
75
|
*/
|
|
82
76
|
function validate() {
|
|
77
|
+
if (!formInstRef.value) throw new Error("useNaiveForm: formInstRef is not found.");
|
|
83
78
|
return new Promise((resolve, reject) => {
|
|
84
|
-
|
|
85
|
-
formInstRef.value.validate().then((res) => {
|
|
79
|
+
formInstRef.value?.validate().then((res) => {
|
|
86
80
|
onValidatedEvent.trigger(toRaw(toValue(formValueRef)));
|
|
87
81
|
return resolve(res);
|
|
88
82
|
}).catch(reject);
|
|
@@ -90,26 +84,41 @@ function useNaiveForm(formInstRef, options) {
|
|
|
90
84
|
}
|
|
91
85
|
/**
|
|
92
86
|
* 重置表单验证状态
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* resetValidation()
|
|
90
|
+
* ```
|
|
93
91
|
*/
|
|
94
92
|
function resetValidation() {
|
|
95
93
|
formInstRef.value?.restoreValidation();
|
|
96
94
|
}
|
|
97
95
|
/**
|
|
98
96
|
* 清空表单值
|
|
97
|
+
* @example
|
|
98
|
+
* ```ts
|
|
99
|
+
* clear()
|
|
100
|
+
* ```
|
|
99
101
|
*/
|
|
100
102
|
function clear() {
|
|
101
103
|
clearObjectValues(formValueRef.value, clearRules);
|
|
102
104
|
}
|
|
103
105
|
/**
|
|
104
106
|
* 重置表单值到初始状态
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* resetForm()
|
|
110
|
+
* ```
|
|
105
111
|
*/
|
|
106
112
|
function resetForm() {
|
|
107
113
|
clear();
|
|
108
|
-
|
|
109
|
-
deepMerge(formValueRef.value, _cacheValue);
|
|
114
|
+
Object.assign(formValueRef.value, cloneDeep(cacheValue));
|
|
110
115
|
}
|
|
111
116
|
/**
|
|
112
117
|
* 重置表单验证状态和值
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* reset()
|
|
121
|
+
* ```
|
|
113
122
|
*/
|
|
114
123
|
function reset() {
|
|
115
124
|
resetValidation();
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as vue8 from "vue";
|
|
2
2
|
import { MaybeRefOrGetter, VNodeChild } from "vue";
|
|
3
|
+
import * as naive_ui0 from "naive-ui";
|
|
3
4
|
import { MenuOption } from "naive-ui";
|
|
4
5
|
import { RouteRecordRaw } from "vue-router";
|
|
5
6
|
|
|
@@ -61,14 +62,27 @@ type UseNaiveMenuOptions = {
|
|
|
61
62
|
*/
|
|
62
63
|
createMenuOption?: (route: RouteRecordRaw) => MenuOption;
|
|
63
64
|
};
|
|
65
|
+
/**
|
|
66
|
+
* 定义带有可选 children 属性的树形节点类型
|
|
67
|
+
*/
|
|
68
|
+
type TreeNode<T> = T & {
|
|
69
|
+
children?: TreeNode<T>[];
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* 将树形结构扁平化为一维数组
|
|
73
|
+
* @param array 原始树形节点数组
|
|
74
|
+
* @param childrenKey children 属性名,默认为 'children'
|
|
75
|
+
* @returns 扁平化后的数组
|
|
76
|
+
*/
|
|
77
|
+
declare function flattenDeep<T extends Record<string, any>>(array: TreeNode<T>[], childrenKey?: keyof TreeNode<T>): T[];
|
|
64
78
|
/**
|
|
65
79
|
* 自动菜单组合函数
|
|
66
80
|
* 将路由配置转换为菜单配置,并提供扁平化的菜单选项
|
|
67
81
|
* @param routes 路由配置数组,可以是响应式或普通数组
|
|
68
82
|
* @param options 配置选项
|
|
69
83
|
* @returns 包含菜单选项和扁平化菜单选项的对象
|
|
70
|
-
*
|
|
71
84
|
* @example
|
|
85
|
+
* ```ts
|
|
72
86
|
* // 基本使用
|
|
73
87
|
* const { menuOptions, flattenedMenuOptions } = useNaiveMenu(routes)
|
|
74
88
|
*
|
|
@@ -90,14 +104,15 @@ type UseNaiveMenuOptions = {
|
|
|
90
104
|
* keyField: 'name',
|
|
91
105
|
* iconField: 'icon'
|
|
92
106
|
* })
|
|
107
|
+
* ```
|
|
93
108
|
*/
|
|
94
109
|
declare function useNaiveMenu(routes: MaybeRefOrGetter<RouteRecordRaw[]>, options?: UseNaiveMenuOptions): {
|
|
95
|
-
menuOptions:
|
|
96
|
-
flattenedMenuOptions:
|
|
110
|
+
menuOptions: vue8.ComputedRef<MenuOption[]>;
|
|
111
|
+
flattenedMenuOptions: vue8.ComputedRef<(MenuOption | naive_ui0.MenuGroupOption | naive_ui0.MenuDividerOption)[]>;
|
|
97
112
|
};
|
|
98
113
|
/**
|
|
99
114
|
* useNaiveMenu 返回类型
|
|
100
115
|
*/
|
|
101
116
|
type UseNaiveMenuReturn = ReturnType<typeof useNaiveMenu>;
|
|
102
117
|
//#endregion
|
|
103
|
-
export { UseNaiveMenuOptions, UseNaiveMenuReturn, useNaiveMenu };
|
|
118
|
+
export { UseNaiveMenuOptions, UseNaiveMenuReturn, flattenDeep, useNaiveMenu };
|
|
@@ -1,26 +1,12 @@
|
|
|
1
1
|
import { computed, toValue } from "vue";
|
|
2
2
|
|
|
3
3
|
//#region src/composables/use-naive-menu.ts
|
|
4
|
-
/**
|
|
5
|
-
* 获取配置值
|
|
6
|
-
* @param route 路由配置
|
|
7
|
-
* @param config 配置项,可以是函数或字符串
|
|
8
|
-
* @param returnType 返回类型,'meta' 从 meta 中获取,'route' 从路由本身获取
|
|
9
|
-
* @param defaultValue 默认值
|
|
10
|
-
* @returns 配置值或默认值
|
|
11
|
-
*/
|
|
12
4
|
function getConfigValue(route, config, returnType, defaultValue) {
|
|
13
5
|
if (!config) return defaultValue;
|
|
14
6
|
if (typeof config === "function") return config(route);
|
|
15
7
|
if (returnType === "meta") return route.meta?.[config] ?? defaultValue;
|
|
16
8
|
return route?.[config] ?? defaultValue;
|
|
17
9
|
}
|
|
18
|
-
/**
|
|
19
|
-
* 创建单个菜单选项
|
|
20
|
-
* @param route 路由配置
|
|
21
|
-
* @param options 配置选项
|
|
22
|
-
* @returns 菜单选项
|
|
23
|
-
*/
|
|
24
10
|
function createConfigMenuOption(route, options) {
|
|
25
11
|
const { labelField, keyField, iconField, renderIcon } = options ?? {};
|
|
26
12
|
const labelValue = getConfigValue(route, labelField, "meta");
|
|
@@ -33,34 +19,16 @@ function createConfigMenuOption(route, options) {
|
|
|
33
19
|
meta: route.meta
|
|
34
20
|
};
|
|
35
21
|
}
|
|
36
|
-
/**
|
|
37
|
-
* 判断路由是否应该隐藏
|
|
38
|
-
* @param route 路由配置
|
|
39
|
-
* @param hidden 隐藏条件
|
|
40
|
-
* @returns 是否隐藏
|
|
41
|
-
*/
|
|
42
22
|
function shouldHide(route, hidden) {
|
|
43
23
|
if (!hidden) return false;
|
|
44
24
|
const result = getConfigValue(route, hidden, "meta");
|
|
45
25
|
return typeof result === "boolean" ? result : !!result;
|
|
46
26
|
}
|
|
47
|
-
/**
|
|
48
|
-
* 判断路由是否为根路由
|
|
49
|
-
* @param route 路由配置
|
|
50
|
-
* @param root 根路由判断
|
|
51
|
-
* @returns 是否为根路由
|
|
52
|
-
*/
|
|
53
27
|
function isRoot(route, root) {
|
|
54
28
|
if (!root) return false;
|
|
55
29
|
const result = getConfigValue(route, root, "meta");
|
|
56
30
|
return typeof result === "boolean" ? result : !!result;
|
|
57
31
|
}
|
|
58
|
-
/**
|
|
59
|
-
* 将路由配置转换为菜单配置的递归函数
|
|
60
|
-
* @param routes 路由配置数组
|
|
61
|
-
* @param options 配置选项
|
|
62
|
-
* @returns 菜单配置数组
|
|
63
|
-
*/
|
|
64
32
|
function routes2menu(routes, options) {
|
|
65
33
|
const { hidden, root, createMenuOption } = options ?? {};
|
|
66
34
|
const menuOptions = [];
|
|
@@ -80,26 +48,6 @@ function routes2menu(routes, options) {
|
|
|
80
48
|
}
|
|
81
49
|
return menuOptions;
|
|
82
50
|
}
|
|
83
|
-
/**
|
|
84
|
-
* 深度扁平化菜单选项
|
|
85
|
-
* @param menuOptions 菜单选项数组
|
|
86
|
-
* @returns 扁平化的菜单选项数组
|
|
87
|
-
*/
|
|
88
|
-
function flattenDeepMenuOptions(menuOptions) {
|
|
89
|
-
return menuOptions.reduce((flattened, menu) => {
|
|
90
|
-
flattened.push(menu);
|
|
91
|
-
if (menu.children?.length) flattened.push(...flattenDeepMenuOptions(menu.children));
|
|
92
|
-
return flattened;
|
|
93
|
-
}, []);
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* 深度向上合并父路由元信息
|
|
97
|
-
* @param routes 路由配置数组
|
|
98
|
-
* @param parentField 父路由元信息字段名
|
|
99
|
-
* @param parentFilePath 父路由文件路径
|
|
100
|
-
* @param parent 父路由元信息生成函数
|
|
101
|
-
* @returns 处理后的路由配置数组
|
|
102
|
-
*/
|
|
103
51
|
function deepUpRouteParentMeta(routes, parentField, parentFilePath, parent) {
|
|
104
52
|
return routes.map((route) => {
|
|
105
53
|
const emptyPathChild = route.children?.find((f) => f.path === parentFilePath);
|
|
@@ -123,13 +71,28 @@ function deepUpRouteParentMeta(routes, parentField, parentFilePath, parent) {
|
|
|
123
71
|
});
|
|
124
72
|
}
|
|
125
73
|
/**
|
|
74
|
+
* 将树形结构扁平化为一维数组
|
|
75
|
+
* @param array 原始树形节点数组
|
|
76
|
+
* @param childrenKey children 属性名,默认为 'children'
|
|
77
|
+
* @returns 扁平化后的数组
|
|
78
|
+
*/
|
|
79
|
+
function flattenDeep(array, childrenKey = "children") {
|
|
80
|
+
return array.reduce((result, item) => {
|
|
81
|
+
const { [childrenKey]: _, ...currentItem } = item;
|
|
82
|
+
result.push(currentItem);
|
|
83
|
+
const children = item[childrenKey];
|
|
84
|
+
if (children && Array.isArray(children)) result.push(...flattenDeep(children, childrenKey));
|
|
85
|
+
return result;
|
|
86
|
+
}, []);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
126
89
|
* 自动菜单组合函数
|
|
127
90
|
* 将路由配置转换为菜单配置,并提供扁平化的菜单选项
|
|
128
91
|
* @param routes 路由配置数组,可以是响应式或普通数组
|
|
129
92
|
* @param options 配置选项
|
|
130
93
|
* @returns 包含菜单选项和扁平化菜单选项的对象
|
|
131
|
-
*
|
|
132
94
|
* @example
|
|
95
|
+
* ```ts
|
|
133
96
|
* // 基本使用
|
|
134
97
|
* const { menuOptions, flattenedMenuOptions } = useNaiveMenu(routes)
|
|
135
98
|
*
|
|
@@ -151,13 +114,10 @@ function deepUpRouteParentMeta(routes, parentField, parentFilePath, parent) {
|
|
|
151
114
|
* keyField: 'name',
|
|
152
115
|
* iconField: 'icon'
|
|
153
116
|
* })
|
|
117
|
+
* ```
|
|
154
118
|
*/
|
|
155
119
|
function useNaiveMenu(routes, options) {
|
|
156
120
|
const { hidden = "hidden", root = "root", labelField = "title", keyField = "name", iconField = "icon", renderIcon, createMenuOption, parentField = "parent", parentFilePath = "", parent } = options ?? {};
|
|
157
|
-
/**
|
|
158
|
-
* 菜单选项
|
|
159
|
-
* 响应式计算属性,当路由或配置变化时自动更新
|
|
160
|
-
*/
|
|
161
121
|
const menuOptions = computed(() => {
|
|
162
122
|
return routes2menu(deepUpRouteParentMeta(toValue(routes), parentField, parentFilePath, parent), {
|
|
163
123
|
hidden,
|
|
@@ -171,11 +131,9 @@ function useNaiveMenu(routes, options) {
|
|
|
171
131
|
});
|
|
172
132
|
return {
|
|
173
133
|
menuOptions,
|
|
174
|
-
flattenedMenuOptions: computed(() =>
|
|
175
|
-
return flattenDeepMenuOptions(menuOptions.value);
|
|
176
|
-
})
|
|
134
|
+
flattenedMenuOptions: computed(() => flattenDeep(menuOptions.value))
|
|
177
135
|
};
|
|
178
136
|
}
|
|
179
137
|
|
|
180
138
|
//#endregion
|
|
181
|
-
export { useNaiveMenu };
|
|
139
|
+
export { flattenDeep, useNaiveMenu };
|
|
@@ -4,13 +4,9 @@ import { GlobalThemeOverrides, NDateLocale, zhCN } from "naive-ui";
|
|
|
4
4
|
import * as naive_ui_es_themes_interface0 from "naive-ui/es/themes/interface";
|
|
5
5
|
|
|
6
6
|
//#region src/composables/use-naive-theme.d.ts
|
|
7
|
-
/**
|
|
8
|
-
* 语言包类型
|
|
9
|
-
* @template T 语言代码类型
|
|
10
|
-
*/
|
|
11
7
|
type Locales<T extends string = string> = Record<T, {
|
|
12
|
-
|
|
13
|
-
dateLocale: NDateLocale;
|
|
8
|
+
name: string;
|
|
9
|
+
dateLocale: NDateLocale;
|
|
14
10
|
locale: typeof zhCN;
|
|
15
11
|
}>;
|
|
16
12
|
/**
|
|
@@ -30,11 +26,28 @@ type UseNaiveThemeOptions<T extends string> = {
|
|
|
30
26
|
* @template T 语言代码类型
|
|
31
27
|
* @param options 配置选项
|
|
32
28
|
* @returns 主题管理对象
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* const {
|
|
32
|
+
* language,
|
|
33
|
+
* darkMode,
|
|
34
|
+
* theme,
|
|
35
|
+
* themeColors,
|
|
36
|
+
* themeOverrides,
|
|
37
|
+
* locale,
|
|
38
|
+
* setColor
|
|
39
|
+
* } = useNaiveTheme({
|
|
40
|
+
* language: 'zh-CN',
|
|
41
|
+
* darkMode: false,
|
|
42
|
+
* colors: { primary: '#1890ff' },
|
|
43
|
+
* globalThemeOverrides: { common: { fontSize: '14px' } }
|
|
44
|
+
* })
|
|
45
|
+
* ```
|
|
33
46
|
*/
|
|
34
47
|
declare function useNaiveTheme<T extends string>(options?: UseNaiveThemeOptions<T>): {
|
|
35
|
-
|
|
36
|
-
darkMode: Ref<boolean | undefined, boolean | undefined>;
|
|
37
|
-
theme: ComputedRef<naive_ui_es_themes_interface0.BuiltInGlobalTheme | undefined>;
|
|
48
|
+
language: Ref<T | undefined, T | undefined>;
|
|
49
|
+
darkMode: Ref<boolean | undefined, boolean | undefined>;
|
|
50
|
+
theme: ComputedRef<naive_ui_es_themes_interface0.BuiltInGlobalTheme | undefined>;
|
|
38
51
|
colors: Ref<{
|
|
39
52
|
primary?: string | undefined;
|
|
40
53
|
info?: string | undefined;
|
|
@@ -47,17 +60,17 @@ declare function useNaiveTheme<T extends string>(options?: UseNaiveThemeOptions<
|
|
|
47
60
|
success?: string | undefined;
|
|
48
61
|
warning?: string | undefined;
|
|
49
62
|
error?: string | undefined;
|
|
50
|
-
}>;
|
|
63
|
+
}>;
|
|
51
64
|
themeColors: ComputedRef<{
|
|
52
65
|
primary?: string | undefined;
|
|
53
66
|
info?: string | undefined;
|
|
54
67
|
success?: string | undefined;
|
|
55
68
|
warning?: string | undefined;
|
|
56
69
|
error?: string | undefined;
|
|
57
|
-
}>;
|
|
58
|
-
themeOverrides: ComputedRef<GlobalThemeOverrides>;
|
|
59
|
-
locales: Locales<T>;
|
|
60
|
-
locale: ComputedRef<Locales<T>[T]>;
|
|
70
|
+
}>;
|
|
71
|
+
themeOverrides: ComputedRef<GlobalThemeOverrides>;
|
|
72
|
+
locales: Locales<T>;
|
|
73
|
+
locale: ComputedRef<Locales<T>[T]>;
|
|
61
74
|
setColor: (v: Partial<Colors>) => void;
|
|
62
75
|
};
|
|
63
76
|
/**
|
|
@@ -3,9 +3,6 @@ import { computed, ref, toValue, watchEffect } from "vue";
|
|
|
3
3
|
import { darkTheme, dateEnUS, dateZhCN, enUS, zhCN } from "naive-ui";
|
|
4
4
|
|
|
5
5
|
//#region src/composables/use-naive-theme.ts
|
|
6
|
-
/**
|
|
7
|
-
* 默认语言包映射
|
|
8
|
-
*/
|
|
9
6
|
const naiveLocaleMap = {
|
|
10
7
|
"zh-CN": {
|
|
11
8
|
name: "简体中文",
|
|
@@ -23,6 +20,23 @@ const naiveLocaleMap = {
|
|
|
23
20
|
* @template T 语言代码类型
|
|
24
21
|
* @param options 配置选项
|
|
25
22
|
* @returns 主题管理对象
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* const {
|
|
26
|
+
* language,
|
|
27
|
+
* darkMode,
|
|
28
|
+
* theme,
|
|
29
|
+
* themeColors,
|
|
30
|
+
* themeOverrides,
|
|
31
|
+
* locale,
|
|
32
|
+
* setColor
|
|
33
|
+
* } = useNaiveTheme({
|
|
34
|
+
* language: 'zh-CN',
|
|
35
|
+
* darkMode: false,
|
|
36
|
+
* colors: { primary: '#1890ff' },
|
|
37
|
+
* globalThemeOverrides: { common: { fontSize: '14px' } }
|
|
38
|
+
* })
|
|
39
|
+
* ```
|
|
26
40
|
*/
|
|
27
41
|
function useNaiveTheme(options) {
|
|
28
42
|
const { language, darkMode, colors, globalThemeOverrides, locales, darkColors } = options ?? {};
|
|
@@ -51,7 +65,11 @@ function useNaiveTheme(options) {
|
|
|
51
65
|
});
|
|
52
66
|
/**
|
|
53
67
|
* 设置主题颜色
|
|
54
|
-
* @param v 颜色配置
|
|
68
|
+
* @param v - 颜色配置
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* setColor({ primary: '#1890ff' })
|
|
72
|
+
* ```
|
|
55
73
|
*/
|
|
56
74
|
function setColor(v) {
|
|
57
75
|
colorsRef.value = {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DataObject, DataRequestFields, UseDataRequestOptions, UseDataRequestPagination, UseDataRequestReturns, useDataRequest } from "./composables/use-data-request.js";
|
|
2
2
|
import { useLoading } from "./composables/use-loading.js";
|
|
3
3
|
import { UseNaiveFormClearRules, UseNaiveFormOptions, UseNaiveFormReturns, UseNaiveFormRules, useNaiveForm } from "./composables/use-naive-form.js";
|
|
4
|
-
import { UseNaiveMenuOptions, UseNaiveMenuReturn, useNaiveMenu } from "./composables/use-naive-menu.js";
|
|
4
|
+
import { UseNaiveMenuOptions, UseNaiveMenuReturn, flattenDeep, useNaiveMenu } from "./composables/use-naive-menu.js";
|
|
5
5
|
import { UseNaiveThemeOptions, UseNaiveThemeReturns, useNaiveTheme } from "./composables/use-naive-theme.js";
|
|
6
6
|
import "./composables/index.js";
|
|
7
|
-
export { DataObject, DataRequestFields, UseDataRequestOptions, UseDataRequestPagination, UseDataRequestReturns, UseNaiveFormClearRules, UseNaiveFormOptions, UseNaiveFormReturns, UseNaiveFormRules, UseNaiveMenuOptions, UseNaiveMenuReturn, UseNaiveThemeOptions, UseNaiveThemeReturns, useDataRequest, useLoading, useNaiveForm, useNaiveMenu, useNaiveTheme };
|
|
7
|
+
export { DataObject, DataRequestFields, UseDataRequestOptions, UseDataRequestPagination, UseDataRequestReturns, UseNaiveFormClearRules, UseNaiveFormOptions, UseNaiveFormReturns, UseNaiveFormRules, UseNaiveMenuOptions, UseNaiveMenuReturn, UseNaiveThemeOptions, UseNaiveThemeReturns, flattenDeep, useDataRequest, useLoading, useNaiveForm, useNaiveMenu, useNaiveTheme };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useDataRequest } from "./composables/use-data-request.js";
|
|
2
2
|
import { useLoading } from "./composables/use-loading.js";
|
|
3
3
|
import { useNaiveForm } from "./composables/use-naive-form.js";
|
|
4
|
-
import { useNaiveMenu } from "./composables/use-naive-menu.js";
|
|
4
|
+
import { flattenDeep, useNaiveMenu } from "./composables/use-naive-menu.js";
|
|
5
5
|
import { useNaiveTheme } from "./composables/use-naive-theme.js";
|
|
6
6
|
|
|
7
|
-
export { useDataRequest, useLoading, useNaiveForm, useNaiveMenu, useNaiveTheme };
|
|
7
|
+
export { flattenDeep, useDataRequest, useLoading, useNaiveForm, useNaiveMenu, useNaiveTheme };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oiij/naive-ui",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.78",
|
|
5
5
|
"description": "Some Composable Functions And Components for Vue 3",
|
|
6
6
|
"author": "oiij",
|
|
7
7
|
"license": "MIT",
|
|
@@ -46,9 +46,8 @@
|
|
|
46
46
|
"vue-component-type-helpers": "^3.2.4",
|
|
47
47
|
"vue-hooks-plus": "^2.4.1",
|
|
48
48
|
"vue-router": "^5.0.2",
|
|
49
|
-
"@oiij/
|
|
50
|
-
"@oiij/
|
|
51
|
-
"@oiij/use": "0.0.44"
|
|
49
|
+
"@oiij/use": "0.0.48",
|
|
50
|
+
"@oiij/css-render": "0.0.11"
|
|
52
51
|
},
|
|
53
52
|
"devDependencies": {
|
|
54
53
|
"@types/prismjs": "^1.26.5",
|
|
@@ -62,9 +61,8 @@
|
|
|
62
61
|
"vue-component-type-helpers": "^3.2.4",
|
|
63
62
|
"vue-hooks-plus": "^2.4.1",
|
|
64
63
|
"vue-router": "^5.0.2",
|
|
65
|
-
"@oiij/css-render": "0.0.
|
|
66
|
-
"@oiij/use": "0.0.
|
|
67
|
-
"@oiij/markdown-it": "0.0.12"
|
|
64
|
+
"@oiij/css-render": "0.0.11",
|
|
65
|
+
"@oiij/use": "0.0.48"
|
|
68
66
|
},
|
|
69
67
|
"publishConfig": {
|
|
70
68
|
"access": "public"
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import Prism from "prismjs";
|
|
2
|
-
|
|
3
|
-
//#region src/components/_utils/prismjs.ts
|
|
4
|
-
if (typeof document !== "undefined") Prism.highlightAll();
|
|
5
|
-
function highlight(code, lang) {
|
|
6
|
-
try {
|
|
7
|
-
const grammar = Prism.languages[lang];
|
|
8
|
-
if (grammar) return `<pre class="language-${lang}"><code class="language-${lang}">${Prism.highlight(code, grammar || Prism.languages.text, lang)}</code></pre>`;
|
|
9
|
-
return code;
|
|
10
|
-
} catch {
|
|
11
|
-
return code;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
//#endregion
|
|
16
|
-
export { highlight };
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import export_helper_default from "../../_virtual/_/plugin-vue/export-helper.js";
|
|
2
|
-
import { createCommentVNode, createElementBlock, createElementVNode, openBlock } from "vue";
|
|
3
|
-
|
|
4
|
-
//#region src/components/icons/MageArrowUp.vue
|
|
5
|
-
const _sfc_main = { name: "MageArrowUp" };
|
|
6
|
-
const _hoisted_1 = {
|
|
7
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
8
|
-
width: "1em",
|
|
9
|
-
height: "1em",
|
|
10
|
-
viewBox: "0 0 24 24"
|
|
11
|
-
};
|
|
12
|
-
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
13
|
-
return openBlock(), createElementBlock("svg", _hoisted_1, [createCommentVNode(" Icon from Mage Icons by MageIcons - https://github.com/Mage-Icons/mage-icons/blob/main/License.txt "), _cache[0] || (_cache[0] = createElementVNode("g", {
|
|
14
|
-
fill: "none",
|
|
15
|
-
stroke: "#757575",
|
|
16
|
-
"stroke-linecap": "round",
|
|
17
|
-
"stroke-width": "1.5"
|
|
18
|
-
}, [createElementVNode("path", {
|
|
19
|
-
"stroke-miterlimit": "10",
|
|
20
|
-
d: "M12 4v16"
|
|
21
|
-
}), createElementVNode("path", {
|
|
22
|
-
"stroke-linejoin": "round",
|
|
23
|
-
d: "M19.66 11.033L13.089 4.46a1.53 1.53 0 0 0-2.176 0L4.34 11.033"
|
|
24
|
-
})], -1))]);
|
|
25
|
-
}
|
|
26
|
-
var MageArrowUp_default = /* @__PURE__ */ export_helper_default(_sfc_main, [["render", _sfc_render]]);
|
|
27
|
-
|
|
28
|
-
//#endregion
|
|
29
|
-
export { MageArrowUp_default as default };
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { highlight } from "../_utils/prismjs.js";
|
|
2
|
-
import { cName, typeWriterCssr } from "./type-writer.cssr.js";
|
|
3
|
-
import { computed, createBlock, createElementVNode, defineComponent, normalizeClass, normalizeStyle, openBlock, unref, withCtx } from "vue";
|
|
4
|
-
import { useStyle } from "@oiij/css-render";
|
|
5
|
-
import { NEl } from "naive-ui";
|
|
6
|
-
import { useMarkdownIt } from "@oiij/markdown-it";
|
|
7
|
-
import { useTypeWriter } from "@oiij/use";
|
|
8
|
-
|
|
9
|
-
//#region src/components/type-writer/TypeWriter.vue
|
|
10
|
-
const _hoisted_1 = ["innerHTML"];
|
|
11
|
-
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
12
|
-
__name: "TypeWriter",
|
|
13
|
-
props: {
|
|
14
|
-
value: {},
|
|
15
|
-
typing: {
|
|
16
|
-
type: Boolean,
|
|
17
|
-
default: true
|
|
18
|
-
},
|
|
19
|
-
markdown: { type: Boolean },
|
|
20
|
-
step: {},
|
|
21
|
-
interval: {},
|
|
22
|
-
suffix: { default: "|" }
|
|
23
|
-
},
|
|
24
|
-
emits: [
|
|
25
|
-
"start",
|
|
26
|
-
"update",
|
|
27
|
-
"stop"
|
|
28
|
-
],
|
|
29
|
-
setup(__props, { emit: __emit }) {
|
|
30
|
-
const emit = __emit;
|
|
31
|
-
useStyle(cName, typeWriterCssr());
|
|
32
|
-
const { typedValue, isTyping, onStat, onUpdate, onStop } = useTypeWriter(computed(() => __props.value ?? ""), {
|
|
33
|
-
step: __props.step,
|
|
34
|
-
interval: __props.interval,
|
|
35
|
-
enabled: __props.typing
|
|
36
|
-
});
|
|
37
|
-
onStat(() => {
|
|
38
|
-
emit("start");
|
|
39
|
-
});
|
|
40
|
-
onUpdate((v) => {
|
|
41
|
-
emit("update", v);
|
|
42
|
-
});
|
|
43
|
-
onStop((v) => {
|
|
44
|
-
emit("stop", v);
|
|
45
|
-
});
|
|
46
|
-
const { html } = useMarkdownIt(void 0, {
|
|
47
|
-
value: typedValue,
|
|
48
|
-
markdownItOptions: {
|
|
49
|
-
html: true,
|
|
50
|
-
linkify: true,
|
|
51
|
-
typographer: true,
|
|
52
|
-
breaks: true,
|
|
53
|
-
highlight
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
const renderValue = computed(() => __props.markdown ? html.value : typedValue.value);
|
|
57
|
-
return (_ctx, _cache) => {
|
|
58
|
-
return openBlock(), createBlock(unref(NEl), {
|
|
59
|
-
tag: "div",
|
|
60
|
-
class: normalizeClass([unref(cName)])
|
|
61
|
-
}, {
|
|
62
|
-
default: withCtx(() => [createElementVNode("div", {
|
|
63
|
-
class: normalizeClass([unref(isTyping) && !__props.markdown ? `${unref(cName)}__cursor` : void 0, __props.markdown ? `${unref(cName)}__markdown` : void 0]),
|
|
64
|
-
style: normalizeStyle([!__props.markdown ? { "--cursor-content": `'${__props.suffix}'` } : void 0]),
|
|
65
|
-
innerHTML: renderValue.value
|
|
66
|
-
}, null, 14, _hoisted_1)]),
|
|
67
|
-
_: 1
|
|
68
|
-
}, 8, ["class"]);
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
var TypeWriter_default = _sfc_main;
|
|
73
|
-
|
|
74
|
-
//#endregion
|
|
75
|
-
export { TypeWriter_default as default };
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { TypeWriterProps } from "./index.js";
|
|
2
|
-
import * as vue65 from "vue";
|
|
3
|
-
|
|
4
|
-
//#region src/components/type-writer/TypeWriter.vue.d.ts
|
|
5
|
-
declare const __VLS_export: vue65.DefineComponent<TypeWriterProps, {}, {}, {}, {}, vue65.ComponentOptionsMixin, vue65.ComponentOptionsMixin, {} & {
|
|
6
|
-
start: () => any;
|
|
7
|
-
update: (v: {
|
|
8
|
-
index: number;
|
|
9
|
-
value: string;
|
|
10
|
-
}) => any;
|
|
11
|
-
stop: (v: string) => any;
|
|
12
|
-
}, string, vue65.PublicProps, Readonly<TypeWriterProps> & Readonly<{
|
|
13
|
-
onStart?: (() => any) | undefined;
|
|
14
|
-
onUpdate?: ((v: {
|
|
15
|
-
index: number;
|
|
16
|
-
value: string;
|
|
17
|
-
}) => any) | undefined;
|
|
18
|
-
onStop?: ((v: string) => any) | undefined;
|
|
19
|
-
}>, {}, {}, {}, {}, string, vue65.ComponentProvideOptions, false, {}, any>;
|
|
20
|
-
declare const _default: typeof __VLS_export;
|
|
21
|
-
//#endregion
|
|
22
|
-
export { _default };
|