@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.cjs CHANGED
@@ -1,173 +1,182 @@
1
1
  "use strict";
2
+ //#region rolldown:runtime
3
+ var __create = Object.create;
2
4
  var __defProp = Object.defineProperty;
3
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
5
8
  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
9
  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;
10
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
+ get: ((k) => from[k]).bind(null, key),
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
16
+ }
17
+ return to;
17
18
  };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
20
+ value: mod,
21
+ enumerable: true
22
+ }) : target, mod));
19
23
 
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);
24
+ //#endregion
25
+ const vue = __toESM(require("vue"));
26
+ const colord = __toESM(require("colord"));
27
+ const naive_ui = __toESM(require("naive-ui"));
27
28
 
28
- // src/useNaiveForm.ts
29
- var import_mixte = require("mixte");
30
- var import_vue = require("vue");
29
+ //#region src/composables/useNaiveForm.ts
30
+ function clearObjectValues(obj) {
31
+ if (Array.isArray(obj)) {
32
+ obj.length = 0;
33
+ return obj;
34
+ }
35
+ if (typeof obj === "object" && obj !== null) {
36
+ for (const key in obj) if (Object.prototype.hasOwnProperty.call(obj, key)) obj[key] = clearObjectValues(obj[key]);
37
+ return obj;
38
+ }
39
+ if (typeof obj === "string") return "";
40
+ if (typeof obj === "number") return 0;
41
+ if (typeof obj === "boolean") return false;
42
+ return obj;
43
+ }
31
44
  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
- };
45
+ const { value, rules } = options ?? {};
46
+ const formValue = (0, vue.ref)(structuredClone(value));
47
+ const formRules = rules;
48
+ const formRef = (0, vue.ref)();
49
+ const formProps = {
50
+ ref: formRef,
51
+ model: (0, vue.reactive)((0, vue.toValue)(formValue)),
52
+ rules: formRules
53
+ };
54
+ function validate() {
55
+ return formRef.value?.validate();
56
+ }
57
+ function resetValidation() {
58
+ formRef.value?.restoreValidation();
59
+ }
60
+ function clear() {
61
+ clearObjectValues(formValue.value);
62
+ }
63
+ function resetForm() {
64
+ clear();
65
+ Object.assign(formValue.value, structuredClone(value));
66
+ }
67
+ function reset() {
68
+ resetValidation();
69
+ resetForm();
70
+ }
71
+ return {
72
+ formRef,
73
+ formValue,
74
+ rules: formRules,
75
+ formProps,
76
+ validate,
77
+ resetValidation,
78
+ resetForm,
79
+ reset,
80
+ clear
81
+ };
73
82
  }
74
83
 
75
- // src/useNaiveTheme.ts
76
- var import_colord = require("colord");
77
- var import_naive_ui = require("naive-ui");
78
- var import_vue2 = require("vue");
84
+ //#endregion
85
+ //#region src/composables/useNaiveTheme.ts
79
86
  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
- };
87
+ return {
88
+ color,
89
+ hover: (0, colord.colord)(color).lighten(.1).toHex(),
90
+ pressed: (0, colord.colord)(color).darken(.1).toHex(),
91
+ suppl: (0, colord.colord)(color).lighten(.1).toHex()
92
+ };
86
93
  }
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
- }
94
+ const naiveLocaleMap = {
95
+ "zh-CN": {
96
+ name: "简体中文",
97
+ dateLocale: naive_ui.dateZhCN,
98
+ locale: naive_ui.zhCN
99
+ },
100
+ "en-US": {
101
+ name: "English",
102
+ dateLocale: naive_ui.dateEnUS,
103
+ locale: naive_ui.enUS
104
+ }
98
105
  };
99
106
  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
- };
107
+ const { common, Dialog,...extra } = globalThemeOverrides || {};
108
+ const color = (0, vue.ref)({
109
+ primary: "#64748B",
110
+ info: "#06b6d4",
111
+ success: "#10b981",
112
+ warning: "#fbbf24",
113
+ error: "#f43f5e"
114
+ });
115
+ function setColor(v) {
116
+ color.value = v;
117
+ }
118
+ const theme = (0, vue.computed)(() => {
119
+ return darkMode?.value ? naive_ui.darkTheme : void 0;
120
+ });
121
+ const themeOverrides = (0, vue.computed)(() => {
122
+ const primary = getStatusColor(color.value.primary);
123
+ const info = getStatusColor(color.value.info);
124
+ const success = getStatusColor(color.value.success);
125
+ const warning = getStatusColor(color.value.warning);
126
+ const error = getStatusColor(color.value.error);
127
+ return {
128
+ common: {
129
+ bodyColor: darkMode?.value ? "#1f1f1f" : "#f5f5f5",
130
+ primaryColor: primary.color,
131
+ primaryColorHover: primary.hover,
132
+ primaryColorPressed: primary.pressed,
133
+ primaryColorSuppl: primary.suppl,
134
+ infoColor: info.color,
135
+ infoColorHover: info.hover,
136
+ infoColorPressed: info.pressed,
137
+ infoColorSuppl: info.suppl,
138
+ successColor: success.color,
139
+ successColorHover: success.hover,
140
+ successColorPressed: success.pressed,
141
+ successColorSuppl: success.suppl,
142
+ warningColor: warning.color,
143
+ warningColorHover: warning.hover,
144
+ warningColorPressed: warning.pressed,
145
+ warningColorSuppl: warning.suppl,
146
+ errorColor: error.color,
147
+ errorColorHover: error.hover,
148
+ errorColorPressed: error.pressed,
149
+ errorColorSuppl: error.suppl,
150
+ borderRadius: "6px",
151
+ ...common
152
+ },
153
+ Dialog: {
154
+ borderRadius: "12px",
155
+ padding: "20px",
156
+ closeMargin: "20px 20px 0 0",
157
+ ...Dialog
158
+ },
159
+ ...extra
160
+ };
161
+ });
162
+ const locale = (0, vue.computed)(() => {
163
+ if (!language?.value || !naiveLocaleMap[language.value]) return naiveLocaleMap["zh-CN"].locale;
164
+ return naiveLocaleMap[language.value].locale;
165
+ });
166
+ const dateLocale = (0, vue.computed)(() => {
167
+ if (!language?.value || !naiveLocaleMap[language.value]) return naiveLocaleMap["zh-CN"].dateLocale;
168
+ return naiveLocaleMap[language.value].dateLocale;
169
+ });
170
+ return {
171
+ theme,
172
+ themeOverrides,
173
+ locale,
174
+ dateLocale,
175
+ color,
176
+ setColor
177
+ };
168
178
  }
169
- // Annotate the CommonJS export names for ESM import in node:
170
- 0 && (module.exports = {
171
- useNaiveForm,
172
- useNaiveTheme
173
- });
179
+
180
+ //#endregion
181
+ exports.useNaiveForm = useNaiveForm
182
+ exports.useNaiveTheme = useNaiveTheme
package/dist/index.d.cts 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 { ValidateError } from "async-validator";
2
+ import { FormInst, FormItemRule, FormRules, GlobalThemeOverrides, NDateLocale, darkTheme, enUS, zhCN } from "naive-ui";
3
+ import { ComputedRef, Reactive, Ref } from "vue";
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 };