@overgaming/valiform 0.2.1 → 0.3.0
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/README.md +41 -55
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +347 -346
- package/dist/src/components/Field.vue.d.ts +0 -1
- package/dist/src/components/__tests__/components/ExampleField.vue.d.ts +0 -1
- package/dist/src/context/useFieldContext.d.ts +37 -1
- package/dist/src/types.d.ts +1 -1
- package/package.json +1 -1
|
@@ -2,4 +2,40 @@ import type { InjectionKey } from 'vue';
|
|
|
2
2
|
import type { FieldContext } from '../types';
|
|
3
3
|
export declare const fieldContextKey: InjectionKey<FieldContext>;
|
|
4
4
|
export declare const useFieldContextProvider: (data: FieldContext) => void;
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Retrieves the `FieldContext` provided by the nearest `Field` component ancestor.
|
|
7
|
+
*
|
|
8
|
+
* **Three call signatures:**
|
|
9
|
+
*
|
|
10
|
+
* - `useFieldContext()` — no args. Returns `FieldContext` directly (no `!` needed).
|
|
11
|
+
* Throws at runtime if called outside a `Field`. Use this for components that
|
|
12
|
+
* must always be nested inside a `Field` (e.g. `FieldLabel`, `FieldError`).
|
|
13
|
+
*
|
|
14
|
+
* - `useFieldContext(fallback: FieldContext)` — with a fallback object. Returns
|
|
15
|
+
* `FieldContext` directly (no `!` needed). Use this for components that can work
|
|
16
|
+
* both inside and outside a `Field` (e.g. standalone inputs with `v-model`).
|
|
17
|
+
*
|
|
18
|
+
* - `useFieldContext(null)` — explicit null. Returns `FieldContext | null`.
|
|
19
|
+
* Use when you want to handle the absence of context manually.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* // Always inside a Field — throws at runtime if misused:
|
|
23
|
+
* const { labelProps } = useFieldContext();
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* // Standalone-capable input — works inside or outside a Field:
|
|
27
|
+
* const model = defineModel<string>({ default: '' });
|
|
28
|
+
* const { inputValue, inputProps } = useFieldContext({ inputValue: model });
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* // Manual null-handling:
|
|
32
|
+
* const ctx = useFieldContext(null);
|
|
33
|
+
* if (ctx) { ... }
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* // ❌ Wrong — `{}` does not satisfy FieldContext and will cause a type error:
|
|
37
|
+
* const { labelProps } = useFieldContext({});
|
|
38
|
+
*/
|
|
39
|
+
export declare function useFieldContext(): FieldContext;
|
|
40
|
+
export declare function useFieldContext(defaultData: null): FieldContext | null;
|
|
41
|
+
export declare function useFieldContext(defaultData: FieldContext): FieldContext;
|
package/dist/src/types.d.ts
CHANGED
|
@@ -33,7 +33,7 @@ export type InputProps = {
|
|
|
33
33
|
onBlur: () => void;
|
|
34
34
|
};
|
|
35
35
|
export interface FieldContext {
|
|
36
|
-
inputValue: WritableComputedRef<unknown>;
|
|
36
|
+
inputValue: WritableComputedRef<unknown> | Ref<unknown>;
|
|
37
37
|
inputProps: ComputedRef<InputProps>;
|
|
38
38
|
labelProps: {
|
|
39
39
|
for: string;
|