@oiij/naive-ui 0.0.1 → 0.0.2

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/index.d.ts CHANGED
@@ -1,178 +1,51 @@
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';
1
+ import { ComputedRef, Reactive, Ref } from "vue";
2
+ import { FormInst, FormItemRule, FormRules, GlobalThemeOverrides, NDateLocale, darkTheme, enUS, zhCN } from "naive-ui";
3
+ import { ValidateError } from "async-validator";
6
4
 
7
- interface NaiveFormOptions<T extends object = Record<string, any>> {
8
- value?: T;
9
- rules?: Partial<Record<keyof T, FormRules | FormItemRule | FormItemRule[]>>;
5
+ //#region src/composables/useNaiveForm.d.ts
6
+ type ExtendsType = Record<string, unknown>;
7
+ type NaiveFormRules<T extends ExtendsType> = Partial<Record<keyof T, FormRules | FormItemRule | FormItemRule[]>> | undefined;
8
+ interface NaiveFormOptions<T extends ExtendsType> {
9
+ value?: T;
10
+ rules?: NaiveFormRules<T>;
10
11
  }
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
- };
12
+ interface NaiveFormReturns<T extends ExtendsType> {
13
+ formRef: Ref<FormInst | undefined>;
14
+ formValue: Ref<T>;
15
+ rules: NaiveFormRules<T>;
16
+ formProps: {
17
+ ref: Ref<FormInst | undefined>;
18
+ model: Reactive<T>;
19
+ rules: NaiveFormRules<T>;
20
+ };
21
+ validate: () => Promise<{
22
+ warnings: ValidateError[][] | undefined;
23
+ }> | undefined;
24
+ resetValidation: () => void;
25
+ resetForm: () => void;
26
+ clear: () => void;
27
+ reset: () => void;
28
+ }
29
+ declare function useNaiveForm<T extends ExtendsType>(options?: NaiveFormOptions<T>): NaiveFormReturns<T>;
27
30
 
31
+ //#endregion
32
+ //#region src/composables/useNaiveTheme.d.ts
28
33
  interface Color {
29
- primary: string;
30
- info: string;
31
- success: string;
32
- warning: string;
33
- error: string;
34
+ primary: string;
35
+ info: string;
36
+ success: string;
37
+ warning: string;
38
+ error: string;
39
+ }
40
+ interface NaiveThemeReturns {
41
+ theme: ComputedRef<typeof darkTheme | undefined>;
42
+ themeOverrides: ComputedRef<GlobalThemeOverrides>;
43
+ locale: ComputedRef<typeof zhCN | typeof enUS>;
44
+ dateLocale: ComputedRef<NDateLocale>;
45
+ color: Ref<Color>;
46
+ setColor: (v: Color) => void;
34
47
  }
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
- };
48
+ declare function useNaiveTheme<T extends 'zh-CN' | 'en-US'>(darkMode?: ComputedRef<boolean> | Ref<boolean>, language?: ComputedRef<T> | Ref<T>, globalThemeOverrides?: GlobalThemeOverrides): NaiveThemeReturns;
177
49
 
178
- export { type NaiveFormOptions, useNaiveForm, useNaiveTheme };
50
+ //#endregion
51
+ export { NaiveFormOptions, NaiveFormReturns, NaiveFormRules, NaiveThemeReturns, useNaiveForm, useNaiveTheme };
package/dist/index.js CHANGED
@@ -1,151 +1,157 @@
1
- // src/useNaiveForm.ts
2
- import { deepClone, isObject } from "mixte";
3
- import { nextTick, reactive, ref, toValue } from "vue";
1
+ import { computed, reactive, ref, toValue } from "vue";
2
+ import { colord } from "colord";
3
+ import { darkTheme, dateEnUS, dateZhCN, enUS, zhCN } from "naive-ui";
4
+
5
+ //#region src/composables/useNaiveForm.ts
6
+ function clearObjectValues(obj) {
7
+ if (Array.isArray(obj)) {
8
+ obj.length = 0;
9
+ return obj;
10
+ }
11
+ if (typeof obj === "object" && obj !== null) {
12
+ for (const key in obj) if (Object.prototype.hasOwnProperty.call(obj, key)) obj[key] = clearObjectValues(obj[key]);
13
+ return obj;
14
+ }
15
+ if (typeof obj === "string") return "";
16
+ if (typeof obj === "number") return 0;
17
+ if (typeof obj === "boolean") return false;
18
+ return obj;
19
+ }
4
20
  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
- };
21
+ const { value, rules } = options ?? {};
22
+ const formValue = ref(structuredClone(value));
23
+ const formRules = rules;
24
+ const formRef = ref();
25
+ const formProps = {
26
+ ref: formRef,
27
+ model: reactive(toValue(formValue)),
28
+ rules: formRules
29
+ };
30
+ function validate() {
31
+ return formRef.value?.validate();
32
+ }
33
+ function resetValidation() {
34
+ formRef.value?.restoreValidation();
35
+ }
36
+ function clear() {
37
+ clearObjectValues(formValue.value);
38
+ }
39
+ function resetForm() {
40
+ clear();
41
+ Object.assign(formValue.value, structuredClone(value));
42
+ }
43
+ function reset() {
44
+ resetValidation();
45
+ resetForm();
46
+ }
47
+ return {
48
+ formRef,
49
+ formValue,
50
+ rules: formRules,
51
+ formProps,
52
+ validate,
53
+ resetValidation,
54
+ resetForm,
55
+ reset,
56
+ clear
57
+ };
46
58
  }
47
59
 
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";
60
+ //#endregion
61
+ //#region src/composables/useNaiveTheme.ts
58
62
  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
- };
63
+ return {
64
+ color,
65
+ hover: colord(color).lighten(.1).toHex(),
66
+ pressed: colord(color).darken(.1).toHex(),
67
+ suppl: colord(color).lighten(.1).toHex()
68
+ };
65
69
  }
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
- }
70
+ const naiveLocaleMap = {
71
+ "zh-CN": {
72
+ name: "简体中文",
73
+ dateLocale: dateZhCN,
74
+ locale: zhCN
75
+ },
76
+ "en-US": {
77
+ name: "English",
78
+ dateLocale: dateEnUS,
79
+ locale: enUS
80
+ }
77
81
  };
78
82
  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
- };
83
+ const { common, Dialog,...extra } = globalThemeOverrides || {};
84
+ const color = ref({
85
+ primary: "#64748B",
86
+ info: "#06b6d4",
87
+ success: "#10b981",
88
+ warning: "#fbbf24",
89
+ error: "#f43f5e"
90
+ });
91
+ function setColor(v) {
92
+ color.value = v;
93
+ }
94
+ const theme = computed(() => {
95
+ return darkMode?.value ? darkTheme : void 0;
96
+ });
97
+ const themeOverrides = computed(() => {
98
+ const primary = getStatusColor(color.value.primary);
99
+ const info = getStatusColor(color.value.info);
100
+ const success = getStatusColor(color.value.success);
101
+ const warning = getStatusColor(color.value.warning);
102
+ const error = getStatusColor(color.value.error);
103
+ return {
104
+ common: {
105
+ bodyColor: darkMode?.value ? "#1f1f1f" : "#f5f5f5",
106
+ primaryColor: primary.color,
107
+ primaryColorHover: primary.hover,
108
+ primaryColorPressed: primary.pressed,
109
+ primaryColorSuppl: primary.suppl,
110
+ infoColor: info.color,
111
+ infoColorHover: info.hover,
112
+ infoColorPressed: info.pressed,
113
+ infoColorSuppl: info.suppl,
114
+ successColor: success.color,
115
+ successColorHover: success.hover,
116
+ successColorPressed: success.pressed,
117
+ successColorSuppl: success.suppl,
118
+ warningColor: warning.color,
119
+ warningColorHover: warning.hover,
120
+ warningColorPressed: warning.pressed,
121
+ warningColorSuppl: warning.suppl,
122
+ errorColor: error.color,
123
+ errorColorHover: error.hover,
124
+ errorColorPressed: error.pressed,
125
+ errorColorSuppl: error.suppl,
126
+ borderRadius: "6px",
127
+ ...common
128
+ },
129
+ Dialog: {
130
+ borderRadius: "12px",
131
+ padding: "20px",
132
+ closeMargin: "20px 20px 0 0",
133
+ ...Dialog
134
+ },
135
+ ...extra
136
+ };
137
+ });
138
+ const locale = computed(() => {
139
+ if (!language?.value || !naiveLocaleMap[language.value]) return naiveLocaleMap["zh-CN"].locale;
140
+ return naiveLocaleMap[language.value].locale;
141
+ });
142
+ const dateLocale = computed(() => {
143
+ if (!language?.value || !naiveLocaleMap[language.value]) return naiveLocaleMap["zh-CN"].dateLocale;
144
+ return naiveLocaleMap[language.value].dateLocale;
145
+ });
146
+ return {
147
+ theme,
148
+ themeOverrides,
149
+ locale,
150
+ dateLocale,
151
+ color,
152
+ setColor
153
+ };
147
154
  }
148
- export {
149
- useNaiveForm,
150
- useNaiveTheme
151
- };
155
+
156
+ //#endregion
157
+ export { useNaiveForm, useNaiveTheme };