notform 2.0.0-alpha.1 → 2.0.0-alpha.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 +65 -8
- package/dist/index.js +71 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as _$vue from "vue";
|
|
1
2
|
import { ComputedRef, MaybeRefOrGetter, Ref } from "vue";
|
|
2
3
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
3
4
|
|
|
@@ -2793,11 +2794,13 @@ type UseNotFormConfig<TSchema extends ObjectSchema> = {
|
|
|
2793
2794
|
*/
|
|
2794
2795
|
onSubmit?: (values: StandardSchemaV1.InferOutput<TSchema>) => void | Promise<void>;
|
|
2795
2796
|
};
|
|
2797
|
+
//#endregion
|
|
2798
|
+
//#region src/types/not-form.d.ts
|
|
2796
2799
|
/**
|
|
2797
2800
|
* The core state and methods provided by a form instance.
|
|
2798
2801
|
* @template TSchema The validation schema type derived from ObjectSchema.
|
|
2799
2802
|
*/
|
|
2800
|
-
type
|
|
2803
|
+
type NotFormInstance<TSchema extends ObjectSchema> = Omit<UseNotFormConfig<TSchema>, 'schema' | 'onSubmit'> & {
|
|
2801
2804
|
/**
|
|
2802
2805
|
* A convenience self-reference to the form instance.
|
|
2803
2806
|
* Useful when you prefer to destructure the composable return value but still need
|
|
@@ -2806,7 +2809,7 @@ type UseNotFormInstance<TSchema extends ObjectSchema> = Omit<UseNotFormConfig<TS
|
|
|
2806
2809
|
* const { values, submit, instance } = useNotForm({ schema, onSubmit })
|
|
2807
2810
|
* // <NotForm :form="instance" />
|
|
2808
2811
|
*/
|
|
2809
|
-
instance:
|
|
2812
|
+
instance: NotFormInstance<TSchema>; /** Deeply reactive object of field values */
|
|
2810
2813
|
values: Ref<StandardSchemaV1.InferInput<TSchema>>;
|
|
2811
2814
|
/**
|
|
2812
2815
|
* Updates a specific field value by path.
|
|
@@ -2910,17 +2913,71 @@ type UseNotFormInstance<TSchema extends ObjectSchema> = Omit<UseNotFormConfig<TS
|
|
|
2910
2913
|
*/
|
|
2911
2914
|
reset: (values?: DeepPartial<StandardSchemaV1.InferInput<TSchema>>, errors?: StandardSchemaV1.Issue[]) => void;
|
|
2912
2915
|
};
|
|
2913
|
-
//#endregion
|
|
2914
|
-
//#region src/types/not-form.d.ts
|
|
2915
2916
|
/**
|
|
2916
2917
|
* Props for the NotForm component
|
|
2917
2918
|
* @template TSchema The validation schema type derived from ObjectSchema.
|
|
2918
2919
|
*/
|
|
2919
2920
|
type NotFormProps<TSchema extends ObjectSchema> = {
|
|
2920
|
-
/** The form instance to use */instance:
|
|
2921
|
+
/** The form instance to use */instance: NotFormInstance<TSchema>;
|
|
2922
|
+
};
|
|
2923
|
+
type NotFormSlots = {
|
|
2924
|
+
/** The default slot */default: [];
|
|
2921
2925
|
};
|
|
2922
|
-
|
|
2923
|
-
|
|
2926
|
+
//#endregion
|
|
2927
|
+
//#region src/components/not-form.vue.d.ts
|
|
2928
|
+
declare const __VLS_export$1: <TSchema extends ObjectSchema>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal$1<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_exposed?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
|
|
2929
|
+
props: _$vue.PublicProps & __VLS_PrettifyLocal$1<NotFormProps<TSchema>> & (typeof globalThis extends {
|
|
2930
|
+
__VLS_PROPS_FALLBACK: infer P;
|
|
2931
|
+
} ? P : {});
|
|
2932
|
+
expose: (exposed: {}) => void;
|
|
2933
|
+
attrs: any;
|
|
2934
|
+
slots: NotFormSlots;
|
|
2935
|
+
emit: {};
|
|
2936
|
+
}>) => _$vue.VNode & {
|
|
2937
|
+
__ctx?: Awaited<typeof __VLS_setup>;
|
|
2938
|
+
};
|
|
2939
|
+
declare const _default$1: typeof __VLS_export$1;
|
|
2940
|
+
type __VLS_PrettifyLocal$1<T> = (T extends any ? { [K in keyof T]: T[K] } : { [K in keyof T as K]: T[K] }) & {};
|
|
2941
|
+
//#endregion
|
|
2942
|
+
//#region src/types/not-field.d.ts
|
|
2943
|
+
/**
|
|
2944
|
+
* Props for the NotField component
|
|
2945
|
+
* @template TSchema The validation schema type derived from ObjectSchema.
|
|
2946
|
+
*/
|
|
2947
|
+
type NotFieldProps<TSchema extends ObjectSchema> = {
|
|
2948
|
+
/** The unique name/path identifying the field within the form state */path: string; /** The optional form instance to use - takes priority over injected context */
|
|
2949
|
+
form?: NotFormInstance<TSchema>;
|
|
2950
|
+
};
|
|
2951
|
+
/**
|
|
2952
|
+
* The core state and methods provided by a field instance.
|
|
2953
|
+
* @template TSchema The validation schema type derived from ObjectSchema.
|
|
2954
|
+
*/
|
|
2955
|
+
type NotFieldInstance<TSchema extends ObjectSchema> = {
|
|
2956
|
+
/** The unique name/path identifying the field within the form state */path: string; /** The errors of the field */
|
|
2957
|
+
errors: StandardSchemaV1.Issue[]; /** The validate method of the field */
|
|
2958
|
+
validate: () => ReturnType<NotFormInstance<TSchema>['validateField']>;
|
|
2959
|
+
};
|
|
2960
|
+
/**
|
|
2961
|
+
* Slots for the NotField component
|
|
2962
|
+
* @template TSchema The validation schema type derived from ObjectSchema.
|
|
2963
|
+
*/
|
|
2964
|
+
type NotFieldSlots<TSchema extends ObjectSchema> = {
|
|
2965
|
+
/** The default slot receives the field instance for use within templates */default: (props: NotFieldInstance<TSchema>) => [];
|
|
2966
|
+
};
|
|
2967
|
+
//#endregion
|
|
2968
|
+
//#region src/components/not-field.vue.d.ts
|
|
2969
|
+
declare const __VLS_export: <TSchema extends ObjectSchema>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_exposed?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
|
|
2970
|
+
props: _$vue.PublicProps & __VLS_PrettifyLocal<NotFieldProps<TSchema>> & (typeof globalThis extends {
|
|
2971
|
+
__VLS_PROPS_FALLBACK: infer P;
|
|
2972
|
+
} ? P : {});
|
|
2973
|
+
expose: (exposed: {}) => void;
|
|
2974
|
+
attrs: any;
|
|
2975
|
+
slots: NotFieldSlots<TSchema>;
|
|
2976
|
+
emit: {};
|
|
2977
|
+
}>) => _$vue.VNode & {
|
|
2978
|
+
__ctx?: Awaited<typeof __VLS_setup>;
|
|
2924
2979
|
};
|
|
2980
|
+
declare const _default: typeof __VLS_export;
|
|
2981
|
+
type __VLS_PrettifyLocal<T> = (T extends any ? { [K in keyof T]: T[K] } : { [K in keyof T as K]: T[K] }) & {};
|
|
2925
2982
|
//#endregion
|
|
2926
|
-
export { ArraySchema, DeepPartial, NotFormProps, NotFormSlots, ObjectSchema, Paths, UseNotFormConfig,
|
|
2983
|
+
export { ArraySchema, DeepPartial, _default as NotField, NotFieldInstance, NotFieldProps, NotFieldSlots, _default$1 as NotForm, NotFormInstance, NotFormProps, NotFormSlots, ObjectSchema, Paths, UseNotFormConfig, ValidationTrigger };
|
package/dist/index.js
CHANGED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { computed, createElementBlock, defineComponent, guardReactiveProps, inject, normalizeProps, openBlock, provide, reactive, renderSlot, unref, useAttrs } from "vue";
|
|
2
|
+
//#region src/utils/instance-utils.ts
|
|
3
|
+
/** Injection key for the current active form instance */
|
|
4
|
+
const NOT_FORM_INSTANCE_KEY = Symbol("notform:instance");
|
|
5
|
+
/**
|
|
6
|
+
* Provides a form instance to all descendant components.
|
|
7
|
+
* @param instance The form instance to provide.
|
|
8
|
+
*/
|
|
9
|
+
function provideNotFormInstance(instance) {
|
|
10
|
+
provide(NOT_FORM_INSTANCE_KEY, instance);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Resolves the active form instance from context or an explicit prop override.
|
|
14
|
+
* @param explicitInstance Optional instance passed directly via :form prop — takes priority over injected context.
|
|
15
|
+
* @throws If no instance is found from either source.
|
|
16
|
+
*/
|
|
17
|
+
function useNotFormInstance(explicitInstance) {
|
|
18
|
+
const injected = inject(NOT_FORM_INSTANCE_KEY);
|
|
19
|
+
const instance = explicitInstance ?? injected;
|
|
20
|
+
if (!instance) throw new Error("[NotForm] No form instance found. Add a <NotForm :form=\"...\"> ancestor or pass :form directly.");
|
|
21
|
+
return instance;
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/components/not-form.vue
|
|
25
|
+
var not_form_default = /* @__PURE__ */ defineComponent({
|
|
26
|
+
__name: "not-form",
|
|
27
|
+
props: { instance: {
|
|
28
|
+
type: Object,
|
|
29
|
+
required: true
|
|
30
|
+
} },
|
|
31
|
+
setup(__props) {
|
|
32
|
+
const attributes = useAttrs();
|
|
33
|
+
provideNotFormInstance(__props.instance);
|
|
34
|
+
return (_ctx, _cache) => {
|
|
35
|
+
return openBlock(), createElementBlock("form", normalizeProps(guardReactiveProps(unref(attributes))), [renderSlot(_ctx.$slots, "default")], 16);
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src/components/not-field.vue
|
|
41
|
+
var not_field_default = /* @__PURE__ */ defineComponent({
|
|
42
|
+
inheritAttrs: false,
|
|
43
|
+
__name: "not-field",
|
|
44
|
+
props: {
|
|
45
|
+
path: {
|
|
46
|
+
type: String,
|
|
47
|
+
required: true
|
|
48
|
+
},
|
|
49
|
+
form: {
|
|
50
|
+
type: Object,
|
|
51
|
+
required: false
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
setup(__props) {
|
|
55
|
+
const props = __props;
|
|
56
|
+
const formInstance = useNotFormInstance(props.form);
|
|
57
|
+
const path = computed(() => props.path);
|
|
58
|
+
const errors = formInstance.getFieldErrors(path.value);
|
|
59
|
+
const validate = () => formInstance.validateField(path.value);
|
|
60
|
+
const fieldInstance = reactive({
|
|
61
|
+
path: path.value,
|
|
62
|
+
errors,
|
|
63
|
+
validate
|
|
64
|
+
});
|
|
65
|
+
return (_ctx, _cache) => {
|
|
66
|
+
return renderSlot(_ctx.$slots, "default", normalizeProps(guardReactiveProps(fieldInstance)));
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
//#endregion
|
|
71
|
+
export { not_field_default as NotField, not_form_default as NotForm };
|