@webamoki/web-svelte 0.6.3 → 0.7.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.
|
@@ -1,74 +1,3 @@
|
|
|
1
|
-
<!-- <script lang="ts" generics="S extends type.Any<Record<string, unknown>>">
|
|
2
|
-
import { toast } from 'svelte-sonner';
|
|
3
|
-
import { dateTransport } from '../../utils/index.js';
|
|
4
|
-
import { type } from 'arktype';
|
|
5
|
-
import type { Snippet } from 'svelte';
|
|
6
|
-
import type { Readable } from 'svelte/store';
|
|
7
|
-
import { defaults, superForm, type SuperForm, type SuperValidated } from 'sveltekit-superforms';
|
|
8
|
-
import { arktype, arktypeClient } from 'sveltekit-superforms/adapters';
|
|
9
|
-
import type { SuperFormData, SuperFormErrors } from 'sveltekit-superforms/client';
|
|
10
|
-
|
|
11
|
-
interface Props {
|
|
12
|
-
validated?: SuperValidated<S['infer']> | S['infer'];
|
|
13
|
-
schema: S;
|
|
14
|
-
onSuccess?: (
|
|
15
|
-
form: Readonly<SuperValidated<S['infer'], App.Superforms.Message, S['infer']>>
|
|
16
|
-
) => void;
|
|
17
|
-
invalidateAll?: boolean;
|
|
18
|
-
children: Snippet<
|
|
19
|
-
[
|
|
20
|
-
{
|
|
21
|
-
form: SuperForm<S['infer'], App.Superforms.Message>;
|
|
22
|
-
data: SuperFormData<S['infer']>;
|
|
23
|
-
delayed: Readable<boolean>;
|
|
24
|
-
errors: SuperFormErrors<S['infer']>;
|
|
25
|
-
}
|
|
26
|
-
]
|
|
27
|
-
>;
|
|
28
|
-
// TODO: Enforce use of resolve
|
|
29
|
-
action: string;
|
|
30
|
-
actionName?: string;
|
|
31
|
-
class?: string;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
let {
|
|
35
|
-
validated: _validated,
|
|
36
|
-
schema,
|
|
37
|
-
onSuccess,
|
|
38
|
-
invalidateAll = false,
|
|
39
|
-
children,
|
|
40
|
-
action: _action,
|
|
41
|
-
actionName,
|
|
42
|
-
class: className
|
|
43
|
-
}: Props = $props();
|
|
44
|
-
|
|
45
|
-
let validated = _validated ?? defaults(arktype(schema));
|
|
46
|
-
const form = superForm(validated, {
|
|
47
|
-
validators: arktypeClient(schema),
|
|
48
|
-
dataType: 'json',
|
|
49
|
-
invalidateAll,
|
|
50
|
-
transport: dateTransport,
|
|
51
|
-
onUpdated({ form }) {
|
|
52
|
-
const text = form.message?.text;
|
|
53
|
-
if (text === undefined) return;
|
|
54
|
-
|
|
55
|
-
if (form.message?.success) {
|
|
56
|
-
toast.success(text);
|
|
57
|
-
} else {
|
|
58
|
-
toast.error(text);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (form.valid) {
|
|
62
|
-
onSuccess?.(form);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
const { form: data, delayed, errors } = form;
|
|
67
|
-
</script>
|
|
68
|
-
|
|
69
|
-
<form class={className} action="{_action}?/{actionName}" method="POST" use:form.enhance>
|
|
70
|
-
{@render children({ form, data, delayed, errors })}
|
|
71
|
-
</form> -->
|
|
72
1
|
<script lang="ts" generics="T extends Record<string, unknown>, M">
|
|
73
2
|
import type { FsSuperForm } from 'formsnap';
|
|
74
3
|
import type { Snippet } from 'svelte';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type } from 'arktype';
|
|
2
2
|
import { type SuperValidated } from 'sveltekit-superforms';
|
|
3
3
|
export * from './virtual-form.js';
|
|
4
|
-
export declare function prepareForm<S extends type.Any<Record<string, unknown>>>(validated: SuperValidated<S['infer']> | S['infer'],
|
|
4
|
+
export declare function prepareForm<S extends type.Any<Record<string, unknown>>>(schema: S, validated: SuperValidated<S['infer']> | S['infer'], options?: Partial<{
|
|
5
5
|
invalidateAll: boolean;
|
|
6
6
|
resetForm: boolean;
|
|
7
7
|
onSuccess: (form: Readonly<SuperValidated<S['infer'], App.Superforms.Message, S['infer']>>) => void;
|
|
@@ -9,7 +9,7 @@ export declare function prepareForm<S extends type.Any<Record<string, unknown>>>
|
|
|
9
9
|
}>): {
|
|
10
10
|
form: import("sveltekit-superforms").SuperForm<S["infer"], any>;
|
|
11
11
|
data: import("sveltekit-superforms/client").SuperFormData<S["infer"]>;
|
|
12
|
-
|
|
12
|
+
isProcessing: import("svelte/store").Readable<boolean>;
|
|
13
13
|
errors: import("sveltekit-superforms/client").SuperFormErrors<S["infer"]>;
|
|
14
14
|
};
|
|
15
15
|
export declare function prepareEmptyForm<S extends type.Any<Record<string, unknown>>>(schema: S, options?: Partial<{
|
|
@@ -20,6 +20,6 @@ export declare function prepareEmptyForm<S extends type.Any<Record<string, unkno
|
|
|
20
20
|
}>): {
|
|
21
21
|
form: import("sveltekit-superforms").SuperForm<S["infer"], any>;
|
|
22
22
|
data: import("sveltekit-superforms/client").SuperFormData<S["infer"]>;
|
|
23
|
-
|
|
23
|
+
isProcessing: import("svelte/store").Readable<boolean>;
|
|
24
24
|
errors: import("sveltekit-superforms/client").SuperFormErrors<S["infer"]>;
|
|
25
25
|
};
|
package/dist/utils/form/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { defaults, superForm } from 'sveltekit-superforms';
|
|
|
4
4
|
import { arktype, arktypeClient } from 'sveltekit-superforms/adapters';
|
|
5
5
|
import { dateTransport } from '../datetime/index.js';
|
|
6
6
|
export * from './virtual-form.js';
|
|
7
|
-
export function prepareForm(
|
|
7
|
+
export function prepareForm(schema, validated, options) {
|
|
8
8
|
const form = superForm(validated, {
|
|
9
9
|
validators: arktypeClient(schema),
|
|
10
10
|
dataType: 'json',
|
|
@@ -31,9 +31,9 @@ export function prepareForm(validated, schema, options) {
|
|
|
31
31
|
toast.error(`${status} - ${message}`);
|
|
32
32
|
}
|
|
33
33
|
});
|
|
34
|
-
const
|
|
34
|
+
const isProcessing = form.delayed;
|
|
35
35
|
const errors = form.errors;
|
|
36
|
-
return { form, data: form.form,
|
|
36
|
+
return { form, data: form.form, isProcessing, errors };
|
|
37
37
|
}
|
|
38
38
|
export function prepareEmptyForm(schema, options) {
|
|
39
39
|
const form = superForm(defaults(arktype(schema)), {
|
|
@@ -62,7 +62,7 @@ export function prepareEmptyForm(schema, options) {
|
|
|
62
62
|
toast.error(`${status} - ${message}`);
|
|
63
63
|
}
|
|
64
64
|
});
|
|
65
|
-
const
|
|
65
|
+
const isProcessing = form.delayed;
|
|
66
66
|
const errors = form.errors;
|
|
67
|
-
return { form, data: form.form,
|
|
67
|
+
return { form, data: form.form, isProcessing, errors };
|
|
68
68
|
}
|
|
@@ -5,7 +5,7 @@ import { parse, stringify } from 'devalue';
|
|
|
5
5
|
import { dateTransport } from '../datetime/index.js';
|
|
6
6
|
export class VirtualForm {
|
|
7
7
|
// state storage
|
|
8
|
-
#
|
|
8
|
+
#isProcessing = false;
|
|
9
9
|
#url = '';
|
|
10
10
|
#schema;
|
|
11
11
|
#transport;
|
|
@@ -70,7 +70,7 @@ export class VirtualForm {
|
|
|
70
70
|
return result;
|
|
71
71
|
}
|
|
72
72
|
async submit(data) {
|
|
73
|
-
this.#
|
|
73
|
+
this.#isProcessing = true;
|
|
74
74
|
this.#update();
|
|
75
75
|
// Validate data against schema
|
|
76
76
|
const validated = this.#schema(data);
|
|
@@ -99,7 +99,7 @@ export class VirtualForm {
|
|
|
99
99
|
if (!res.ok || result.status === 400) {
|
|
100
100
|
console.error('Request failed:', result);
|
|
101
101
|
this.#onError?.(result);
|
|
102
|
-
this.#
|
|
102
|
+
this.#isProcessing = false;
|
|
103
103
|
this.#update();
|
|
104
104
|
return;
|
|
105
105
|
}
|
|
@@ -124,11 +124,11 @@ export class VirtualForm {
|
|
|
124
124
|
console.error(err);
|
|
125
125
|
this.#onError?.({ text: 'Network error', data: err, success: false, showToast: false });
|
|
126
126
|
}
|
|
127
|
-
this.#
|
|
127
|
+
this.#isProcessing = false;
|
|
128
128
|
this.#update();
|
|
129
129
|
}
|
|
130
|
-
get
|
|
130
|
+
get isProcessing() {
|
|
131
131
|
this.#subscribe();
|
|
132
|
-
return this.#
|
|
132
|
+
return this.#isProcessing;
|
|
133
133
|
}
|
|
134
134
|
}
|