@oiij/naive-ui 0.0.1
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/LICENSE +21 -0
- package/README.md +31 -0
- package/dist/index.cjs +173 -0
- package/dist/index.d.cts +178 -0
- package/dist/index.d.ts +178 -0
- package/dist/index.js +151 -0
- package/package.json +93 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 oiij <https://github.com/oiij>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# library-starter
|
|
2
|
+
|
|
3
|
+
Features:
|
|
4
|
+
|
|
5
|
+
- Bundle with [tsup](https://github.com/egoist/tsup)
|
|
6
|
+
- Test with [vitest](https://vitest.dev)
|
|
7
|
+
|
|
8
|
+
## Usage
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
pnpm add @oiij/naive-ui
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { useNaiveForm, useNaiveTheme } from '@oiij/naive-ui'
|
|
16
|
+
const { theme, themeOverrides, locale, dateLocale, color, setColor, } = useNaiveTheme()
|
|
17
|
+
const { formRef, formProps, formValue, rules, validate, resetValidation, resetForm, reset, clear, } = useNaiveForm({
|
|
18
|
+
value: {
|
|
19
|
+
foo: ''
|
|
20
|
+
},
|
|
21
|
+
rules: {
|
|
22
|
+
foo: {
|
|
23
|
+
required: true
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## License
|
|
30
|
+
|
|
31
|
+
MIT
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
useNaiveForm: () => useNaiveForm,
|
|
24
|
+
useNaiveTheme: () => useNaiveTheme
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
|
|
28
|
+
// src/useNaiveForm.ts
|
|
29
|
+
var import_mixte = require("mixte");
|
|
30
|
+
var import_vue = require("vue");
|
|
31
|
+
function useNaiveForm(options) {
|
|
32
|
+
const { value, rules } = options ?? {};
|
|
33
|
+
const userFormValue = (0, import_vue.ref)(value);
|
|
34
|
+
const userFormRules = rules;
|
|
35
|
+
const formRef = (0, import_vue.ref)();
|
|
36
|
+
const formProps = {
|
|
37
|
+
model: (0, import_vue.reactive)((0, import_vue.toValue)(userFormValue)),
|
|
38
|
+
rules: userFormRules
|
|
39
|
+
};
|
|
40
|
+
const formInitialValues = (0, import_mixte.deepClone)(value);
|
|
41
|
+
function validate() {
|
|
42
|
+
return formRef.value?.validate();
|
|
43
|
+
}
|
|
44
|
+
function resetValidation() {
|
|
45
|
+
formRef.value?.restoreValidation();
|
|
46
|
+
}
|
|
47
|
+
function clear() {
|
|
48
|
+
Object.keys(userFormValue.value).forEach((key) => {
|
|
49
|
+
userFormValue.value[key] = Array.isArray(userFormValue.value[key]) ? [] : (0, import_mixte.isObject)(userFormValue.value[key]) ? {} : null;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function resetForm() {
|
|
53
|
+
clear();
|
|
54
|
+
(0, import_vue.nextTick)(() => {
|
|
55
|
+
Object.assign(userFormValue.value, formInitialValues);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function reset() {
|
|
59
|
+
resetValidation();
|
|
60
|
+
resetForm();
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
formRef,
|
|
64
|
+
formProps,
|
|
65
|
+
formValue: userFormValue,
|
|
66
|
+
rules: userFormRules,
|
|
67
|
+
validate,
|
|
68
|
+
resetValidation,
|
|
69
|
+
resetForm,
|
|
70
|
+
reset,
|
|
71
|
+
clear
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// src/useNaiveTheme.ts
|
|
76
|
+
var import_colord = require("colord");
|
|
77
|
+
var import_naive_ui = require("naive-ui");
|
|
78
|
+
var import_vue2 = require("vue");
|
|
79
|
+
function getStatusColor(color = "#ff461f") {
|
|
80
|
+
return {
|
|
81
|
+
color,
|
|
82
|
+
hover: (0, import_colord.colord)(color).lighten(0.1).toHex(),
|
|
83
|
+
pressed: (0, import_colord.colord)(color).darken(0.1).toHex(),
|
|
84
|
+
suppl: (0, import_colord.colord)(color).lighten(0.1).toHex()
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
var naiveLocaleMap = {
|
|
88
|
+
"zh-CN": {
|
|
89
|
+
name: "\u7B80\u4F53\u4E2D\u6587",
|
|
90
|
+
dateLocale: import_naive_ui.dateZhCN,
|
|
91
|
+
locale: import_naive_ui.zhCN
|
|
92
|
+
},
|
|
93
|
+
"en-US": {
|
|
94
|
+
name: "English",
|
|
95
|
+
dateLocale: import_naive_ui.dateEnUS,
|
|
96
|
+
locale: import_naive_ui.enUS
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
function useNaiveTheme(darkMode, language, globalThemeOverrides) {
|
|
100
|
+
const { common, Dialog, ...extra } = globalThemeOverrides || {};
|
|
101
|
+
const color = (0, import_vue2.ref)({
|
|
102
|
+
primary: "#64748B",
|
|
103
|
+
info: "#06b6d4",
|
|
104
|
+
success: "#10b981",
|
|
105
|
+
warning: "#fbbf24",
|
|
106
|
+
error: "#f43f5e"
|
|
107
|
+
});
|
|
108
|
+
function setColor(v) {
|
|
109
|
+
color.value = v;
|
|
110
|
+
}
|
|
111
|
+
const theme = (0, import_vue2.computed)(() => {
|
|
112
|
+
return darkMode?.value ? import_naive_ui.darkTheme : void 0;
|
|
113
|
+
});
|
|
114
|
+
const themeOverrides = (0, import_vue2.computed)(() => {
|
|
115
|
+
return {
|
|
116
|
+
common: {
|
|
117
|
+
bodyColor: darkMode?.value ? "#1f1f1f" : "#f5f5f5",
|
|
118
|
+
primaryColor: color.value.primary,
|
|
119
|
+
primaryColorHover: getStatusColor(color.value.primary).hover,
|
|
120
|
+
primaryColorPressed: getStatusColor(color.value.primary).pressed,
|
|
121
|
+
primaryColorSuppl: getStatusColor(color.value.primary).suppl,
|
|
122
|
+
infoColor: color.value.info,
|
|
123
|
+
infoColorHover: getStatusColor(color.value.info).hover,
|
|
124
|
+
infoColorPressed: getStatusColor(color.value.info).pressed,
|
|
125
|
+
infoColorSuppl: getStatusColor(color.value.info).suppl,
|
|
126
|
+
successColor: color.value.success,
|
|
127
|
+
successColorHover: getStatusColor(color.value.success).hover,
|
|
128
|
+
successColorPressed: getStatusColor(color.value.success).pressed,
|
|
129
|
+
successColorSuppl: getStatusColor(color.value.success).suppl,
|
|
130
|
+
warningColor: color.value.warning,
|
|
131
|
+
warningColorHover: getStatusColor(color.value.warning).hover,
|
|
132
|
+
warningColorPressed: getStatusColor(color.value.warning).pressed,
|
|
133
|
+
warningColorSuppl: getStatusColor(color.value.warning).suppl,
|
|
134
|
+
errorColor: color.value.error,
|
|
135
|
+
errorColorHover: getStatusColor(color.value.error).hover,
|
|
136
|
+
errorColorPressed: getStatusColor(color.value.error).pressed,
|
|
137
|
+
errorColorSuppl: getStatusColor(color.value.error).suppl,
|
|
138
|
+
borderRadius: "6px",
|
|
139
|
+
...common
|
|
140
|
+
},
|
|
141
|
+
Dialog: {
|
|
142
|
+
borderRadius: "12px",
|
|
143
|
+
padding: "20px",
|
|
144
|
+
closeMargin: "20px 20px 0 0",
|
|
145
|
+
...Dialog
|
|
146
|
+
},
|
|
147
|
+
...extra
|
|
148
|
+
};
|
|
149
|
+
});
|
|
150
|
+
const locale = (0, import_vue2.computed)(() => {
|
|
151
|
+
if (!language?.value || !naiveLocaleMap[language.value])
|
|
152
|
+
return naiveLocaleMap["zh-CN"].locale;
|
|
153
|
+
return naiveLocaleMap[language.value].locale;
|
|
154
|
+
});
|
|
155
|
+
const dateLocale = (0, import_vue2.computed)(() => {
|
|
156
|
+
if (!language?.value || !naiveLocaleMap[language.value])
|
|
157
|
+
return naiveLocaleMap["zh-CN"].dateLocale;
|
|
158
|
+
return naiveLocaleMap[language.value].dateLocale;
|
|
159
|
+
});
|
|
160
|
+
return {
|
|
161
|
+
theme,
|
|
162
|
+
themeOverrides,
|
|
163
|
+
locale,
|
|
164
|
+
dateLocale,
|
|
165
|
+
color,
|
|
166
|
+
setColor
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
170
|
+
0 && (module.exports = {
|
|
171
|
+
useNaiveForm,
|
|
172
|
+
useNaiveTheme
|
|
173
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import * as async_validator from 'async-validator';
|
|
2
|
+
import * as vue from 'vue';
|
|
3
|
+
import { Ref, ComputedRef } from 'vue';
|
|
4
|
+
import { FormRules, FormItemRule, FormInst, GlobalThemeOverrides, NDateLocale } from 'naive-ui';
|
|
5
|
+
import * as naive_ui_es_themes_interface from 'naive-ui/es/themes/interface';
|
|
6
|
+
|
|
7
|
+
interface NaiveFormOptions<T extends object = Record<string, any>> {
|
|
8
|
+
value?: T;
|
|
9
|
+
rules?: Partial<Record<keyof T, FormRules | FormItemRule | FormItemRule[]>>;
|
|
10
|
+
}
|
|
11
|
+
declare function useNaiveForm<T extends Record<string, any>>(options?: NaiveFormOptions<T>): {
|
|
12
|
+
formRef: Ref<FormInst | undefined, FormInst | undefined>;
|
|
13
|
+
formProps: {
|
|
14
|
+
model: vue.Reactive<T>;
|
|
15
|
+
rules: Partial<Record<keyof T, FormRules | FormItemRule | FormItemRule[]>> | undefined;
|
|
16
|
+
};
|
|
17
|
+
formValue: Ref<T>;
|
|
18
|
+
rules: Partial<Record<keyof T, FormRules | FormItemRule | FormItemRule[]>> | undefined;
|
|
19
|
+
validate: () => Promise<{
|
|
20
|
+
warnings: async_validator.ValidateError[][] | undefined;
|
|
21
|
+
}> | undefined;
|
|
22
|
+
resetValidation: () => void;
|
|
23
|
+
resetForm: () => void;
|
|
24
|
+
reset: () => void;
|
|
25
|
+
clear: () => void;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
interface Color {
|
|
29
|
+
primary: string;
|
|
30
|
+
info: string;
|
|
31
|
+
success: string;
|
|
32
|
+
warning: string;
|
|
33
|
+
error: string;
|
|
34
|
+
}
|
|
35
|
+
declare function useNaiveTheme(darkMode?: ComputedRef<boolean>, language?: ComputedRef<'zh-CN' | 'en-US'>, globalThemeOverrides?: GlobalThemeOverrides): {
|
|
36
|
+
theme: ComputedRef<naive_ui_es_themes_interface.BuiltInGlobalTheme | undefined>;
|
|
37
|
+
themeOverrides: ComputedRef<GlobalThemeOverrides>;
|
|
38
|
+
locale: ComputedRef<{
|
|
39
|
+
name: string;
|
|
40
|
+
global: {
|
|
41
|
+
undo: string;
|
|
42
|
+
redo: string;
|
|
43
|
+
confirm: string;
|
|
44
|
+
clear: string;
|
|
45
|
+
};
|
|
46
|
+
Popconfirm: {
|
|
47
|
+
positiveText: string;
|
|
48
|
+
negativeText: string;
|
|
49
|
+
};
|
|
50
|
+
Cascader: {
|
|
51
|
+
placeholder: string;
|
|
52
|
+
loading: string;
|
|
53
|
+
loadingRequiredMessage: (label: string) => string;
|
|
54
|
+
};
|
|
55
|
+
Time: {
|
|
56
|
+
dateFormat: string;
|
|
57
|
+
dateTimeFormat: string;
|
|
58
|
+
};
|
|
59
|
+
DatePicker: {
|
|
60
|
+
yearFormat: string;
|
|
61
|
+
monthFormat: string;
|
|
62
|
+
dayFormat: string;
|
|
63
|
+
yearTypeFormat: string;
|
|
64
|
+
monthTypeFormat: string;
|
|
65
|
+
dateFormat: string;
|
|
66
|
+
dateTimeFormat: string;
|
|
67
|
+
quarterFormat: string;
|
|
68
|
+
weekFormat: string;
|
|
69
|
+
clear: string;
|
|
70
|
+
now: string;
|
|
71
|
+
confirm: string;
|
|
72
|
+
selectTime: string;
|
|
73
|
+
selectDate: string;
|
|
74
|
+
datePlaceholder: string;
|
|
75
|
+
datetimePlaceholder: string;
|
|
76
|
+
monthPlaceholder: string;
|
|
77
|
+
yearPlaceholder: string;
|
|
78
|
+
quarterPlaceholder: string;
|
|
79
|
+
weekPlaceholder: string;
|
|
80
|
+
startDatePlaceholder: string;
|
|
81
|
+
endDatePlaceholder: string;
|
|
82
|
+
startDatetimePlaceholder: string;
|
|
83
|
+
endDatetimePlaceholder: string;
|
|
84
|
+
startMonthPlaceholder: string;
|
|
85
|
+
endMonthPlaceholder: string;
|
|
86
|
+
monthBeforeYear: boolean;
|
|
87
|
+
firstDayOfWeek: 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
88
|
+
today: string;
|
|
89
|
+
};
|
|
90
|
+
DataTable: {
|
|
91
|
+
checkTableAll: string;
|
|
92
|
+
uncheckTableAll: string;
|
|
93
|
+
confirm: string;
|
|
94
|
+
clear: string;
|
|
95
|
+
};
|
|
96
|
+
LegacyTransfer: {
|
|
97
|
+
sourceTitle: string;
|
|
98
|
+
targetTitle: string;
|
|
99
|
+
};
|
|
100
|
+
Transfer: {
|
|
101
|
+
selectAll: string;
|
|
102
|
+
unselectAll: string;
|
|
103
|
+
clearAll: string;
|
|
104
|
+
total: (num: number) => string;
|
|
105
|
+
selected: (num: number) => string;
|
|
106
|
+
};
|
|
107
|
+
Empty: {
|
|
108
|
+
description: string;
|
|
109
|
+
};
|
|
110
|
+
Select: {
|
|
111
|
+
placeholder: string;
|
|
112
|
+
};
|
|
113
|
+
TimePicker: {
|
|
114
|
+
placeholder: string;
|
|
115
|
+
positiveText: string;
|
|
116
|
+
negativeText: string;
|
|
117
|
+
now: string;
|
|
118
|
+
clear: string;
|
|
119
|
+
};
|
|
120
|
+
Pagination: {
|
|
121
|
+
goto: string;
|
|
122
|
+
selectionSuffix: string;
|
|
123
|
+
};
|
|
124
|
+
DynamicTags: {
|
|
125
|
+
add: string;
|
|
126
|
+
};
|
|
127
|
+
Log: {
|
|
128
|
+
loading: string;
|
|
129
|
+
};
|
|
130
|
+
Input: {
|
|
131
|
+
placeholder: string;
|
|
132
|
+
};
|
|
133
|
+
InputNumber: {
|
|
134
|
+
placeholder: string;
|
|
135
|
+
};
|
|
136
|
+
DynamicInput: {
|
|
137
|
+
create: string;
|
|
138
|
+
};
|
|
139
|
+
ThemeEditor: {
|
|
140
|
+
title: string;
|
|
141
|
+
clearAllVars: string;
|
|
142
|
+
clearSearch: string;
|
|
143
|
+
filterCompName: string;
|
|
144
|
+
filterVarName: string;
|
|
145
|
+
import: string;
|
|
146
|
+
export: string;
|
|
147
|
+
restore: string;
|
|
148
|
+
};
|
|
149
|
+
Image: {
|
|
150
|
+
tipPrevious: string;
|
|
151
|
+
tipNext: string;
|
|
152
|
+
tipCounterclockwise: string;
|
|
153
|
+
tipClockwise: string;
|
|
154
|
+
tipZoomOut: string;
|
|
155
|
+
tipZoomIn: string;
|
|
156
|
+
tipDownload: string;
|
|
157
|
+
tipClose: string;
|
|
158
|
+
tipOriginalSize: string;
|
|
159
|
+
};
|
|
160
|
+
}>;
|
|
161
|
+
dateLocale: ComputedRef<NDateLocale>;
|
|
162
|
+
color: vue.Ref<{
|
|
163
|
+
primary: string;
|
|
164
|
+
info: string;
|
|
165
|
+
success: string;
|
|
166
|
+
warning: string;
|
|
167
|
+
error: string;
|
|
168
|
+
}, Color | {
|
|
169
|
+
primary: string;
|
|
170
|
+
info: string;
|
|
171
|
+
success: string;
|
|
172
|
+
warning: string;
|
|
173
|
+
error: string;
|
|
174
|
+
}>;
|
|
175
|
+
setColor: (v: Color) => void;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
export { type NaiveFormOptions, useNaiveForm, useNaiveTheme };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import * as async_validator from 'async-validator';
|
|
2
|
+
import * as vue from 'vue';
|
|
3
|
+
import { Ref, ComputedRef } from 'vue';
|
|
4
|
+
import { FormRules, FormItemRule, FormInst, GlobalThemeOverrides, NDateLocale } from 'naive-ui';
|
|
5
|
+
import * as naive_ui_es_themes_interface from 'naive-ui/es/themes/interface';
|
|
6
|
+
|
|
7
|
+
interface NaiveFormOptions<T extends object = Record<string, any>> {
|
|
8
|
+
value?: T;
|
|
9
|
+
rules?: Partial<Record<keyof T, FormRules | FormItemRule | FormItemRule[]>>;
|
|
10
|
+
}
|
|
11
|
+
declare function useNaiveForm<T extends Record<string, any>>(options?: NaiveFormOptions<T>): {
|
|
12
|
+
formRef: Ref<FormInst | undefined, FormInst | undefined>;
|
|
13
|
+
formProps: {
|
|
14
|
+
model: vue.Reactive<T>;
|
|
15
|
+
rules: Partial<Record<keyof T, FormRules | FormItemRule | FormItemRule[]>> | undefined;
|
|
16
|
+
};
|
|
17
|
+
formValue: Ref<T>;
|
|
18
|
+
rules: Partial<Record<keyof T, FormRules | FormItemRule | FormItemRule[]>> | undefined;
|
|
19
|
+
validate: () => Promise<{
|
|
20
|
+
warnings: async_validator.ValidateError[][] | undefined;
|
|
21
|
+
}> | undefined;
|
|
22
|
+
resetValidation: () => void;
|
|
23
|
+
resetForm: () => void;
|
|
24
|
+
reset: () => void;
|
|
25
|
+
clear: () => void;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
interface Color {
|
|
29
|
+
primary: string;
|
|
30
|
+
info: string;
|
|
31
|
+
success: string;
|
|
32
|
+
warning: string;
|
|
33
|
+
error: string;
|
|
34
|
+
}
|
|
35
|
+
declare function useNaiveTheme(darkMode?: ComputedRef<boolean>, language?: ComputedRef<'zh-CN' | 'en-US'>, globalThemeOverrides?: GlobalThemeOverrides): {
|
|
36
|
+
theme: ComputedRef<naive_ui_es_themes_interface.BuiltInGlobalTheme | undefined>;
|
|
37
|
+
themeOverrides: ComputedRef<GlobalThemeOverrides>;
|
|
38
|
+
locale: ComputedRef<{
|
|
39
|
+
name: string;
|
|
40
|
+
global: {
|
|
41
|
+
undo: string;
|
|
42
|
+
redo: string;
|
|
43
|
+
confirm: string;
|
|
44
|
+
clear: string;
|
|
45
|
+
};
|
|
46
|
+
Popconfirm: {
|
|
47
|
+
positiveText: string;
|
|
48
|
+
negativeText: string;
|
|
49
|
+
};
|
|
50
|
+
Cascader: {
|
|
51
|
+
placeholder: string;
|
|
52
|
+
loading: string;
|
|
53
|
+
loadingRequiredMessage: (label: string) => string;
|
|
54
|
+
};
|
|
55
|
+
Time: {
|
|
56
|
+
dateFormat: string;
|
|
57
|
+
dateTimeFormat: string;
|
|
58
|
+
};
|
|
59
|
+
DatePicker: {
|
|
60
|
+
yearFormat: string;
|
|
61
|
+
monthFormat: string;
|
|
62
|
+
dayFormat: string;
|
|
63
|
+
yearTypeFormat: string;
|
|
64
|
+
monthTypeFormat: string;
|
|
65
|
+
dateFormat: string;
|
|
66
|
+
dateTimeFormat: string;
|
|
67
|
+
quarterFormat: string;
|
|
68
|
+
weekFormat: string;
|
|
69
|
+
clear: string;
|
|
70
|
+
now: string;
|
|
71
|
+
confirm: string;
|
|
72
|
+
selectTime: string;
|
|
73
|
+
selectDate: string;
|
|
74
|
+
datePlaceholder: string;
|
|
75
|
+
datetimePlaceholder: string;
|
|
76
|
+
monthPlaceholder: string;
|
|
77
|
+
yearPlaceholder: string;
|
|
78
|
+
quarterPlaceholder: string;
|
|
79
|
+
weekPlaceholder: string;
|
|
80
|
+
startDatePlaceholder: string;
|
|
81
|
+
endDatePlaceholder: string;
|
|
82
|
+
startDatetimePlaceholder: string;
|
|
83
|
+
endDatetimePlaceholder: string;
|
|
84
|
+
startMonthPlaceholder: string;
|
|
85
|
+
endMonthPlaceholder: string;
|
|
86
|
+
monthBeforeYear: boolean;
|
|
87
|
+
firstDayOfWeek: 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
88
|
+
today: string;
|
|
89
|
+
};
|
|
90
|
+
DataTable: {
|
|
91
|
+
checkTableAll: string;
|
|
92
|
+
uncheckTableAll: string;
|
|
93
|
+
confirm: string;
|
|
94
|
+
clear: string;
|
|
95
|
+
};
|
|
96
|
+
LegacyTransfer: {
|
|
97
|
+
sourceTitle: string;
|
|
98
|
+
targetTitle: string;
|
|
99
|
+
};
|
|
100
|
+
Transfer: {
|
|
101
|
+
selectAll: string;
|
|
102
|
+
unselectAll: string;
|
|
103
|
+
clearAll: string;
|
|
104
|
+
total: (num: number) => string;
|
|
105
|
+
selected: (num: number) => string;
|
|
106
|
+
};
|
|
107
|
+
Empty: {
|
|
108
|
+
description: string;
|
|
109
|
+
};
|
|
110
|
+
Select: {
|
|
111
|
+
placeholder: string;
|
|
112
|
+
};
|
|
113
|
+
TimePicker: {
|
|
114
|
+
placeholder: string;
|
|
115
|
+
positiveText: string;
|
|
116
|
+
negativeText: string;
|
|
117
|
+
now: string;
|
|
118
|
+
clear: string;
|
|
119
|
+
};
|
|
120
|
+
Pagination: {
|
|
121
|
+
goto: string;
|
|
122
|
+
selectionSuffix: string;
|
|
123
|
+
};
|
|
124
|
+
DynamicTags: {
|
|
125
|
+
add: string;
|
|
126
|
+
};
|
|
127
|
+
Log: {
|
|
128
|
+
loading: string;
|
|
129
|
+
};
|
|
130
|
+
Input: {
|
|
131
|
+
placeholder: string;
|
|
132
|
+
};
|
|
133
|
+
InputNumber: {
|
|
134
|
+
placeholder: string;
|
|
135
|
+
};
|
|
136
|
+
DynamicInput: {
|
|
137
|
+
create: string;
|
|
138
|
+
};
|
|
139
|
+
ThemeEditor: {
|
|
140
|
+
title: string;
|
|
141
|
+
clearAllVars: string;
|
|
142
|
+
clearSearch: string;
|
|
143
|
+
filterCompName: string;
|
|
144
|
+
filterVarName: string;
|
|
145
|
+
import: string;
|
|
146
|
+
export: string;
|
|
147
|
+
restore: string;
|
|
148
|
+
};
|
|
149
|
+
Image: {
|
|
150
|
+
tipPrevious: string;
|
|
151
|
+
tipNext: string;
|
|
152
|
+
tipCounterclockwise: string;
|
|
153
|
+
tipClockwise: string;
|
|
154
|
+
tipZoomOut: string;
|
|
155
|
+
tipZoomIn: string;
|
|
156
|
+
tipDownload: string;
|
|
157
|
+
tipClose: string;
|
|
158
|
+
tipOriginalSize: string;
|
|
159
|
+
};
|
|
160
|
+
}>;
|
|
161
|
+
dateLocale: ComputedRef<NDateLocale>;
|
|
162
|
+
color: vue.Ref<{
|
|
163
|
+
primary: string;
|
|
164
|
+
info: string;
|
|
165
|
+
success: string;
|
|
166
|
+
warning: string;
|
|
167
|
+
error: string;
|
|
168
|
+
}, Color | {
|
|
169
|
+
primary: string;
|
|
170
|
+
info: string;
|
|
171
|
+
success: string;
|
|
172
|
+
warning: string;
|
|
173
|
+
error: string;
|
|
174
|
+
}>;
|
|
175
|
+
setColor: (v: Color) => void;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
export { type NaiveFormOptions, useNaiveForm, useNaiveTheme };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
// src/useNaiveForm.ts
|
|
2
|
+
import { deepClone, isObject } from "mixte";
|
|
3
|
+
import { nextTick, reactive, ref, toValue } from "vue";
|
|
4
|
+
function useNaiveForm(options) {
|
|
5
|
+
const { value, rules } = options ?? {};
|
|
6
|
+
const userFormValue = ref(value);
|
|
7
|
+
const userFormRules = rules;
|
|
8
|
+
const formRef = ref();
|
|
9
|
+
const formProps = {
|
|
10
|
+
model: reactive(toValue(userFormValue)),
|
|
11
|
+
rules: userFormRules
|
|
12
|
+
};
|
|
13
|
+
const formInitialValues = deepClone(value);
|
|
14
|
+
function validate() {
|
|
15
|
+
return formRef.value?.validate();
|
|
16
|
+
}
|
|
17
|
+
function resetValidation() {
|
|
18
|
+
formRef.value?.restoreValidation();
|
|
19
|
+
}
|
|
20
|
+
function clear() {
|
|
21
|
+
Object.keys(userFormValue.value).forEach((key) => {
|
|
22
|
+
userFormValue.value[key] = Array.isArray(userFormValue.value[key]) ? [] : isObject(userFormValue.value[key]) ? {} : null;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
function resetForm() {
|
|
26
|
+
clear();
|
|
27
|
+
nextTick(() => {
|
|
28
|
+
Object.assign(userFormValue.value, formInitialValues);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
function reset() {
|
|
32
|
+
resetValidation();
|
|
33
|
+
resetForm();
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
formRef,
|
|
37
|
+
formProps,
|
|
38
|
+
formValue: userFormValue,
|
|
39
|
+
rules: userFormRules,
|
|
40
|
+
validate,
|
|
41
|
+
resetValidation,
|
|
42
|
+
resetForm,
|
|
43
|
+
reset,
|
|
44
|
+
clear
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// src/useNaiveTheme.ts
|
|
49
|
+
import { colord } from "colord";
|
|
50
|
+
import {
|
|
51
|
+
darkTheme,
|
|
52
|
+
dateEnUS,
|
|
53
|
+
dateZhCN,
|
|
54
|
+
enUS,
|
|
55
|
+
zhCN
|
|
56
|
+
} from "naive-ui";
|
|
57
|
+
import { computed, ref as ref2 } from "vue";
|
|
58
|
+
function getStatusColor(color = "#ff461f") {
|
|
59
|
+
return {
|
|
60
|
+
color,
|
|
61
|
+
hover: colord(color).lighten(0.1).toHex(),
|
|
62
|
+
pressed: colord(color).darken(0.1).toHex(),
|
|
63
|
+
suppl: colord(color).lighten(0.1).toHex()
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
var naiveLocaleMap = {
|
|
67
|
+
"zh-CN": {
|
|
68
|
+
name: "\u7B80\u4F53\u4E2D\u6587",
|
|
69
|
+
dateLocale: dateZhCN,
|
|
70
|
+
locale: zhCN
|
|
71
|
+
},
|
|
72
|
+
"en-US": {
|
|
73
|
+
name: "English",
|
|
74
|
+
dateLocale: dateEnUS,
|
|
75
|
+
locale: enUS
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
function useNaiveTheme(darkMode, language, globalThemeOverrides) {
|
|
79
|
+
const { common, Dialog, ...extra } = globalThemeOverrides || {};
|
|
80
|
+
const color = ref2({
|
|
81
|
+
primary: "#64748B",
|
|
82
|
+
info: "#06b6d4",
|
|
83
|
+
success: "#10b981",
|
|
84
|
+
warning: "#fbbf24",
|
|
85
|
+
error: "#f43f5e"
|
|
86
|
+
});
|
|
87
|
+
function setColor(v) {
|
|
88
|
+
color.value = v;
|
|
89
|
+
}
|
|
90
|
+
const theme = computed(() => {
|
|
91
|
+
return darkMode?.value ? darkTheme : void 0;
|
|
92
|
+
});
|
|
93
|
+
const themeOverrides = computed(() => {
|
|
94
|
+
return {
|
|
95
|
+
common: {
|
|
96
|
+
bodyColor: darkMode?.value ? "#1f1f1f" : "#f5f5f5",
|
|
97
|
+
primaryColor: color.value.primary,
|
|
98
|
+
primaryColorHover: getStatusColor(color.value.primary).hover,
|
|
99
|
+
primaryColorPressed: getStatusColor(color.value.primary).pressed,
|
|
100
|
+
primaryColorSuppl: getStatusColor(color.value.primary).suppl,
|
|
101
|
+
infoColor: color.value.info,
|
|
102
|
+
infoColorHover: getStatusColor(color.value.info).hover,
|
|
103
|
+
infoColorPressed: getStatusColor(color.value.info).pressed,
|
|
104
|
+
infoColorSuppl: getStatusColor(color.value.info).suppl,
|
|
105
|
+
successColor: color.value.success,
|
|
106
|
+
successColorHover: getStatusColor(color.value.success).hover,
|
|
107
|
+
successColorPressed: getStatusColor(color.value.success).pressed,
|
|
108
|
+
successColorSuppl: getStatusColor(color.value.success).suppl,
|
|
109
|
+
warningColor: color.value.warning,
|
|
110
|
+
warningColorHover: getStatusColor(color.value.warning).hover,
|
|
111
|
+
warningColorPressed: getStatusColor(color.value.warning).pressed,
|
|
112
|
+
warningColorSuppl: getStatusColor(color.value.warning).suppl,
|
|
113
|
+
errorColor: color.value.error,
|
|
114
|
+
errorColorHover: getStatusColor(color.value.error).hover,
|
|
115
|
+
errorColorPressed: getStatusColor(color.value.error).pressed,
|
|
116
|
+
errorColorSuppl: getStatusColor(color.value.error).suppl,
|
|
117
|
+
borderRadius: "6px",
|
|
118
|
+
...common
|
|
119
|
+
},
|
|
120
|
+
Dialog: {
|
|
121
|
+
borderRadius: "12px",
|
|
122
|
+
padding: "20px",
|
|
123
|
+
closeMargin: "20px 20px 0 0",
|
|
124
|
+
...Dialog
|
|
125
|
+
},
|
|
126
|
+
...extra
|
|
127
|
+
};
|
|
128
|
+
});
|
|
129
|
+
const locale = computed(() => {
|
|
130
|
+
if (!language?.value || !naiveLocaleMap[language.value])
|
|
131
|
+
return naiveLocaleMap["zh-CN"].locale;
|
|
132
|
+
return naiveLocaleMap[language.value].locale;
|
|
133
|
+
});
|
|
134
|
+
const dateLocale = computed(() => {
|
|
135
|
+
if (!language?.value || !naiveLocaleMap[language.value])
|
|
136
|
+
return naiveLocaleMap["zh-CN"].dateLocale;
|
|
137
|
+
return naiveLocaleMap[language.value].dateLocale;
|
|
138
|
+
});
|
|
139
|
+
return {
|
|
140
|
+
theme,
|
|
141
|
+
themeOverrides,
|
|
142
|
+
locale,
|
|
143
|
+
dateLocale,
|
|
144
|
+
color,
|
|
145
|
+
setColor
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
export {
|
|
149
|
+
useNaiveForm,
|
|
150
|
+
useNaiveTheme
|
|
151
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@oiij/naive-ui",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"description": "",
|
|
6
|
+
"author": "oiij",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"homepage": "https://github.com/oiij/naive-ui",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git@github.com:oiij/naive-ui.git"
|
|
12
|
+
},
|
|
13
|
+
"bugs": "https://github.com/oiij/naive-ui/issues",
|
|
14
|
+
"keywords": [
|
|
15
|
+
"@oiij,naive-ui",
|
|
16
|
+
"naive-ui extra"
|
|
17
|
+
],
|
|
18
|
+
"sideEffects": false,
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"import": "./dist/index.js",
|
|
23
|
+
"require": "./dist/index.cjs"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"main": "./dist/index.js",
|
|
27
|
+
"module": "./dist/index.js",
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"files": [
|
|
30
|
+
"LICENSE",
|
|
31
|
+
"README.md",
|
|
32
|
+
"dist",
|
|
33
|
+
"package.json"
|
|
34
|
+
],
|
|
35
|
+
"scripts": {
|
|
36
|
+
"dev": "tsup --watch",
|
|
37
|
+
"dev:unbuild": "unbuild --stub",
|
|
38
|
+
"build": "tsc --noEmit && tsup",
|
|
39
|
+
"build:unbuild": "tsc --noEmit && unbuild",
|
|
40
|
+
"lint": "eslint .",
|
|
41
|
+
"lint:fix": "eslint . --fix",
|
|
42
|
+
"prepublishOnly": "pnpm build",
|
|
43
|
+
"release": "bumpp -r && npm publish --access public",
|
|
44
|
+
"awe": "pnpx are-we-esm",
|
|
45
|
+
"nmi": "pnpx node-modules-inspector",
|
|
46
|
+
"start": "esno src/index.ts",
|
|
47
|
+
"test": "vitest",
|
|
48
|
+
"update:deps": "taze -w && pnpm i",
|
|
49
|
+
"type:check": "tsc --noEmit",
|
|
50
|
+
"cz": "czg",
|
|
51
|
+
"commit": "git pull && git add -A && pnpm cz && git push",
|
|
52
|
+
"link": "pnpm link --global",
|
|
53
|
+
"preinstall": "npx only-allow pnpm"
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"async-validator": "^4.2.5",
|
|
57
|
+
"colord": "^2.9.3",
|
|
58
|
+
"mixte": "3.0.0-beta.3"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"@antfu/eslint-config": "^4.2.0",
|
|
62
|
+
"@oiij/tsconfig": "^0.0.1",
|
|
63
|
+
"@types/node": "^22.13.1",
|
|
64
|
+
"@vitest/ui": "^3.0.5",
|
|
65
|
+
"bumpp": "^10.0.3",
|
|
66
|
+
"commitlint": "^19.7.1",
|
|
67
|
+
"cz-git": "^1.11.0",
|
|
68
|
+
"czg": "^1.11.0",
|
|
69
|
+
"eslint": "^9.20.1",
|
|
70
|
+
"eslint-plugin-format": "^1.0.1",
|
|
71
|
+
"esno": "^4.8.0",
|
|
72
|
+
"lint-staged": "^15.4.3",
|
|
73
|
+
"naive-ui": "^2.40.3",
|
|
74
|
+
"simple-git-hooks": "^2.11.1",
|
|
75
|
+
"taze": "^18.5.0",
|
|
76
|
+
"tsup": "8.3.6",
|
|
77
|
+
"typescript": "^5.7.3",
|
|
78
|
+
"unbuild": "^3.3.1",
|
|
79
|
+
"vitest": "^3.0.5",
|
|
80
|
+
"vue": "^3.5.13"
|
|
81
|
+
},
|
|
82
|
+
"simple-git-hooks": {
|
|
83
|
+
"pre-commit": "pnpm lint-staged && pnpm type:check"
|
|
84
|
+
},
|
|
85
|
+
"lint-staged": {
|
|
86
|
+
"*.{js,jsx,ts,tsx}": [
|
|
87
|
+
"pnpm lint:fix"
|
|
88
|
+
]
|
|
89
|
+
},
|
|
90
|
+
"publishConfig": {
|
|
91
|
+
"access": "public"
|
|
92
|
+
}
|
|
93
|
+
}
|