@azure-net/kit 1.0.0 → 1.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.
@@ -1,7 +1,6 @@
1
1
  import type { RequestErrors } from '../../delivery/schema/index.js';
2
2
  import type { AsyncActionResponse } from '../../index.js';
3
- export interface FormConfig<FormData, Response> {
4
- onSubmit: (formData: Partial<FormData>) => Promise<AsyncActionResponse<Response, FormData>>;
3
+ export interface FormConfig<FormData> {
5
4
  initialData?: FormData;
6
5
  }
7
6
  export interface ActiveForm<FormData, Response> {
@@ -12,4 +11,4 @@ export interface ActiveForm<FormData, Response> {
12
11
  pending: boolean;
13
12
  dirty: boolean;
14
13
  }
15
- export declare const createActiveForm: <FormData, Response = unknown>(config: FormConfig<FormData, Response>) => ActiveForm<FormData, Response>;
14
+ export declare const createActiveForm: <FormData, Response = unknown>(onSubmit: (formData: Partial<FormData>) => Promise<AsyncActionResponse<Response, FormData>>, config?: FormConfig<FormData>) => ActiveForm<FormData, Response>;
@@ -1,13 +1,13 @@
1
1
  import { ObjectUtil } from 'azure-net-tools';
2
- export const createActiveForm = (config) => {
3
- const initial = config.initialData ?? {};
2
+ export const createActiveForm = (onSubmit, config) => {
3
+ const initial = config?.initialData ?? {};
4
4
  let formData = $state(ObjectUtil.deepClone(initial));
5
5
  let formErrors = $state({});
6
6
  let pending = $state(false);
7
7
  const dirty = $derived(JSON.stringify(formData) !== JSON.stringify(initial));
8
8
  const submit = async () => {
9
9
  pending = true;
10
- const result = await config.onSubmit(formData);
10
+ const result = await onSubmit(formData);
11
11
  if (result.error?.fields) {
12
12
  formErrors = result.error?.fields;
13
13
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azure-net/kit",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "files": [
5
5
  "dist",
6
6
  "!dist/**/*.test.*",