@oiij/naive-ui 0.0.31 → 0.0.33
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/data-table-plus/index.d.ts +2 -1
- package/dist/components/preset-form/index.d.ts +2 -1
- package/dist/components/preset-input/_utils.d.ts +2 -2
- package/dist/components.cjs +17 -17
- package/dist/components.js +1812 -1802
- package/dist/components.umd.cjs +21 -21
- package/dist/composables/useNaiveForm.cjs +18 -4
- package/dist/composables/useNaiveForm.d.cts +5 -6
- package/dist/composables/useNaiveForm.d.ts +4 -5
- package/dist/composables/useNaiveForm.js +19 -5
- package/dist/composables/useNaiveTheme.d.cts +1 -1
- package/dist/composables/useNaiveTheme.d.ts +2 -2
- package/package.json +2 -2
|
@@ -3,6 +3,9 @@ const __vueuse_core = require_rolldown_runtime.__toESM(require("@vueuse/core"));
|
|
|
3
3
|
const vue = require_rolldown_runtime.__toESM(require("vue"));
|
|
4
4
|
|
|
5
5
|
//#region src/composables/useNaiveForm.ts
|
|
6
|
+
function isObject(value) {
|
|
7
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8
|
+
}
|
|
6
9
|
function clearObjectValues(obj, rules) {
|
|
7
10
|
const { string: _string = "", number: _number = null, boolean: _boolean = false } = rules ?? {};
|
|
8
11
|
if (Array.isArray(obj)) {
|
|
@@ -18,9 +21,19 @@ function clearObjectValues(obj, rules) {
|
|
|
18
21
|
if (typeof obj === "boolean") return _boolean;
|
|
19
22
|
return obj;
|
|
20
23
|
}
|
|
24
|
+
function deepMerge(target = {}, source = {}) {
|
|
25
|
+
for (const key in source) if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
26
|
+
const sourceValue = source[key];
|
|
27
|
+
const targetValue = target[key];
|
|
28
|
+
if (isObject(sourceValue) && isObject(targetValue)) deepMerge(targetValue, sourceValue);
|
|
29
|
+
else target[key] = sourceValue;
|
|
30
|
+
}
|
|
31
|
+
return target;
|
|
32
|
+
}
|
|
21
33
|
function useNaiveForm(value, options) {
|
|
22
34
|
const { rules, clearRules } = options ?? {};
|
|
23
|
-
const
|
|
35
|
+
const cacheValue = structuredClone((0, vue.toRaw)((0, vue.toValue)(value)));
|
|
36
|
+
const formValue = (0, vue.ref)((0, vue.toValue)(value ?? {}));
|
|
24
37
|
const formRules = rules;
|
|
25
38
|
const formRef = (0, vue.ref)();
|
|
26
39
|
const formProps = {
|
|
@@ -31,7 +44,7 @@ function useNaiveForm(value, options) {
|
|
|
31
44
|
const onValidatedEvent = (0, __vueuse_core.createEventHook)();
|
|
32
45
|
function validate() {
|
|
33
46
|
return new Promise((resolve, reject) => {
|
|
34
|
-
if (!formRef.value) return reject(/* @__PURE__ */ new Error("formRef
|
|
47
|
+
if (!formRef.value) return reject(/* @__PURE__ */ new Error("useNaiveForm: formRef is not found."));
|
|
35
48
|
formRef.value.validate().then((res) => {
|
|
36
49
|
onValidatedEvent.trigger((0, vue.toRaw)((0, vue.toValue)(formValue)));
|
|
37
50
|
return resolve(res);
|
|
@@ -42,11 +55,12 @@ function useNaiveForm(value, options) {
|
|
|
42
55
|
formRef.value?.restoreValidation();
|
|
43
56
|
}
|
|
44
57
|
function clear() {
|
|
45
|
-
clearObjectValues(formValue, clearRules);
|
|
58
|
+
clearObjectValues(formValue.value, clearRules);
|
|
46
59
|
}
|
|
47
60
|
function resetForm() {
|
|
48
61
|
clear();
|
|
49
|
-
|
|
62
|
+
const _cacheValue = structuredClone(cacheValue);
|
|
63
|
+
deepMerge(formValue.value, _cacheValue);
|
|
50
64
|
}
|
|
51
65
|
function reset() {
|
|
52
66
|
resetValidation();
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import { Ref } from "vue";
|
|
3
|
-
import * as _vueuse_core2 from "@vueuse/core";
|
|
1
|
+
import * as _vueuse_core1 from "@vueuse/core";
|
|
4
2
|
import { ValidateError } from "async-validator";
|
|
5
3
|
import { FormInst, FormItemRule, FormRules } from "naive-ui";
|
|
4
|
+
import { Ref } from "vue";
|
|
6
5
|
|
|
7
6
|
//#region src/composables/useNaiveForm.d.ts
|
|
8
7
|
interface NaiveFormClearRules {
|
|
@@ -15,13 +14,13 @@ interface NaiveFormOptions<T extends Record<string, any>> {
|
|
|
15
14
|
rules?: NaiveFormRules<T>;
|
|
16
15
|
clearRules?: NaiveFormClearRules;
|
|
17
16
|
}
|
|
18
|
-
declare function useNaiveForm<T extends Record<string, any> = Record<string, any>>(value?: T
|
|
17
|
+
declare function useNaiveForm<T extends Record<string, any> = Record<string, any>>(value?: T | Ref<T>, options?: NaiveFormOptions<T>): {
|
|
19
18
|
formRef: Ref<FormInst | undefined, FormInst | undefined>;
|
|
20
19
|
formValue: Ref<T>;
|
|
21
20
|
formRules: Partial<Record<keyof T, FormRules | FormItemRule | FormItemRule[]>> | undefined;
|
|
22
21
|
formProps: {
|
|
23
22
|
ref: Ref<FormInst | undefined, FormInst | undefined>;
|
|
24
|
-
model:
|
|
23
|
+
model: Ref<T, T>;
|
|
25
24
|
rules: Partial<Record<keyof T, FormRules | FormItemRule | FormItemRule[]>> | undefined;
|
|
26
25
|
};
|
|
27
26
|
validate: () => Promise<{
|
|
@@ -31,7 +30,7 @@ declare function useNaiveForm<T extends Record<string, any> = Record<string, any
|
|
|
31
30
|
resetForm: () => void;
|
|
32
31
|
reset: () => void;
|
|
33
32
|
clear: () => void;
|
|
34
|
-
onValidated:
|
|
33
|
+
onValidated: _vueuse_core1.EventHookOn<[T]>;
|
|
35
34
|
};
|
|
36
35
|
type NaiveFormReturns<T extends Record<string, any> = Record<string, any>> = ReturnType<typeof useNaiveForm<T>>;
|
|
37
36
|
//#endregion
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import * as vue1 from "vue";
|
|
1
|
+
import * as _vueuse_core0 from "@vueuse/core";
|
|
3
2
|
import { Ref } from "vue";
|
|
4
3
|
import { FormInst, FormItemRule, FormRules } from "naive-ui";
|
|
5
4
|
import { ValidateError } from "async-validator";
|
|
@@ -15,13 +14,13 @@ interface NaiveFormOptions<T extends Record<string, any>> {
|
|
|
15
14
|
rules?: NaiveFormRules<T>;
|
|
16
15
|
clearRules?: NaiveFormClearRules;
|
|
17
16
|
}
|
|
18
|
-
declare function useNaiveForm<T extends Record<string, any> = Record<string, any>>(value?: T
|
|
17
|
+
declare function useNaiveForm<T extends Record<string, any> = Record<string, any>>(value?: T | Ref<T>, options?: NaiveFormOptions<T>): {
|
|
19
18
|
formRef: Ref<FormInst | undefined, FormInst | undefined>;
|
|
20
19
|
formValue: Ref<T>;
|
|
21
20
|
formRules: Partial<Record<keyof T, FormRules | FormItemRule | FormItemRule[]>> | undefined;
|
|
22
21
|
formProps: {
|
|
23
22
|
ref: Ref<FormInst | undefined, FormInst | undefined>;
|
|
24
|
-
model:
|
|
23
|
+
model: Ref<T, T>;
|
|
25
24
|
rules: Partial<Record<keyof T, FormRules | FormItemRule | FormItemRule[]>> | undefined;
|
|
26
25
|
};
|
|
27
26
|
validate: () => Promise<{
|
|
@@ -31,7 +30,7 @@ declare function useNaiveForm<T extends Record<string, any> = Record<string, any
|
|
|
31
30
|
resetForm: () => void;
|
|
32
31
|
reset: () => void;
|
|
33
32
|
clear: () => void;
|
|
34
|
-
onValidated:
|
|
33
|
+
onValidated: _vueuse_core0.EventHookOn<[T]>;
|
|
35
34
|
};
|
|
36
35
|
type NaiveFormReturns<T extends Record<string, any> = Record<string, any>> = ReturnType<typeof useNaiveForm<T>>;
|
|
37
36
|
//#endregion
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { createEventHook } from "@vueuse/core";
|
|
2
|
-
import {
|
|
2
|
+
import { ref, toRaw, toRef, toValue } from "vue";
|
|
3
3
|
|
|
4
4
|
//#region src/composables/useNaiveForm.ts
|
|
5
|
+
function isObject(value) {
|
|
6
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
7
|
+
}
|
|
5
8
|
function clearObjectValues(obj, rules) {
|
|
6
9
|
const { string: _string = "", number: _number = null, boolean: _boolean = false } = rules ?? {};
|
|
7
10
|
if (Array.isArray(obj)) {
|
|
@@ -17,9 +20,19 @@ function clearObjectValues(obj, rules) {
|
|
|
17
20
|
if (typeof obj === "boolean") return _boolean;
|
|
18
21
|
return obj;
|
|
19
22
|
}
|
|
23
|
+
function deepMerge(target = {}, source = {}) {
|
|
24
|
+
for (const key in source) if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
25
|
+
const sourceValue = source[key];
|
|
26
|
+
const targetValue = target[key];
|
|
27
|
+
if (isObject(sourceValue) && isObject(targetValue)) deepMerge(targetValue, sourceValue);
|
|
28
|
+
else target[key] = sourceValue;
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
}
|
|
20
32
|
function useNaiveForm(value, options) {
|
|
21
33
|
const { rules, clearRules } = options ?? {};
|
|
22
|
-
const
|
|
34
|
+
const cacheValue = structuredClone(toRaw(toValue(value)));
|
|
35
|
+
const formValue = ref(toValue(value ?? {}));
|
|
23
36
|
const formRules = rules;
|
|
24
37
|
const formRef = ref();
|
|
25
38
|
const formProps = {
|
|
@@ -30,7 +43,7 @@ function useNaiveForm(value, options) {
|
|
|
30
43
|
const onValidatedEvent = createEventHook();
|
|
31
44
|
function validate() {
|
|
32
45
|
return new Promise((resolve, reject) => {
|
|
33
|
-
if (!formRef.value) return reject(/* @__PURE__ */ new Error("formRef
|
|
46
|
+
if (!formRef.value) return reject(/* @__PURE__ */ new Error("useNaiveForm: formRef is not found."));
|
|
34
47
|
formRef.value.validate().then((res) => {
|
|
35
48
|
onValidatedEvent.trigger(toRaw(toValue(formValue)));
|
|
36
49
|
return resolve(res);
|
|
@@ -41,11 +54,12 @@ function useNaiveForm(value, options) {
|
|
|
41
54
|
formRef.value?.restoreValidation();
|
|
42
55
|
}
|
|
43
56
|
function clear() {
|
|
44
|
-
clearObjectValues(formValue, clearRules);
|
|
57
|
+
clearObjectValues(formValue.value, clearRules);
|
|
45
58
|
}
|
|
46
59
|
function resetForm() {
|
|
47
60
|
clear();
|
|
48
|
-
|
|
61
|
+
const _cacheValue = structuredClone(cacheValue);
|
|
62
|
+
deepMerge(formValue.value, _cacheValue);
|
|
49
63
|
}
|
|
50
64
|
function reset() {
|
|
51
65
|
resetValidation();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ComputedRef, Ref } from "vue";
|
|
2
1
|
import { GlobalThemeOverrides, NDateLocale } from "naive-ui";
|
|
2
|
+
import { ComputedRef, Ref } from "vue";
|
|
3
3
|
import * as naive_ui_es_themes_interface0 from "naive-ui/es/themes/interface";
|
|
4
4
|
|
|
5
5
|
//#region src/composables/useNaiveTheme.d.ts
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ComputedRef, Ref } from "vue";
|
|
2
2
|
import { GlobalThemeOverrides, NDateLocale } from "naive-ui";
|
|
3
|
-
import * as
|
|
3
|
+
import * as naive_ui_es_themes_interface1 from "naive-ui/es/themes/interface";
|
|
4
4
|
|
|
5
5
|
//#region src/composables/useNaiveTheme.d.ts
|
|
6
6
|
interface Color {
|
|
@@ -19,7 +19,7 @@ interface NaiveThemeOptions {
|
|
|
19
19
|
declare function useNaiveTheme(options?: NaiveThemeOptions): {
|
|
20
20
|
language: Ref<string | undefined, string | undefined>;
|
|
21
21
|
darkMode: Ref<boolean | undefined, boolean | undefined>;
|
|
22
|
-
theme: ComputedRef<
|
|
22
|
+
theme: ComputedRef<naive_ui_es_themes_interface1.BuiltInGlobalTheme | undefined>;
|
|
23
23
|
themeOverrides: ComputedRef<GlobalThemeOverrides>;
|
|
24
24
|
locale: ComputedRef<{
|
|
25
25
|
name: string;
|
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.33",
|
|
5
5
|
"description": "Som Composable Functions And Components for Vue 3",
|
|
6
6
|
"author": "oiij",
|
|
7
7
|
"license": "MIT",
|
|
@@ -59,8 +59,8 @@
|
|
|
59
59
|
"vue": "^3.5.17",
|
|
60
60
|
"vue-component-type-helpers": "^2.2.10",
|
|
61
61
|
"vue-hooks-plus": "^2.4.0",
|
|
62
|
-
"@oiij/css-render": "0.0.2",
|
|
63
62
|
"@oiij/markdown-it": "0.0.3",
|
|
63
|
+
"@oiij/css-render": "0.0.2",
|
|
64
64
|
"@oiij/use": "0.0.18"
|
|
65
65
|
},
|
|
66
66
|
"publishConfig": {
|