@thetinkerinc/sprout 0.4.0 → 0.5.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/dist/forms/index.d.ts +20 -0
- package/dist/forms/index.js +27 -0
- package/package.json +10 -6
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { RemoteForm, RemoteFormInput } from '@sveltejs/kit';
|
|
2
|
+
type Form = RemoteForm<RemoteFormInput, Promise<unknown>>;
|
|
3
|
+
type EnhanceParams<T extends Form> = Parameters<Parameters<T['enhance']>[0]>[0];
|
|
4
|
+
type CallbackParams<T extends Form> = Pick<EnhanceParams<T>, 'form' | 'data'> & {
|
|
5
|
+
result: unknown;
|
|
6
|
+
};
|
|
7
|
+
type Callback<T extends Form> = (params: CallbackParams<T>) => Promise<void>;
|
|
8
|
+
type ErrorParams<T extends Form> = Pick<EnhanceParams<T>, 'form' | 'data'> & {
|
|
9
|
+
error: unknown;
|
|
10
|
+
};
|
|
11
|
+
type ErrorCallback<T extends Form> = (params: ErrorParams<T>) => Promise<void>;
|
|
12
|
+
type EnhanceOptions<T extends Form> = {
|
|
13
|
+
onInvalid?: Callback<T>;
|
|
14
|
+
onSuccess?: Callback<T>;
|
|
15
|
+
onSubmit?: Callback<T>;
|
|
16
|
+
onError?: ErrorCallback<T>;
|
|
17
|
+
reset?: boolean;
|
|
18
|
+
};
|
|
19
|
+
export declare function makeEnhance<T extends Form>(remoteForm: T, { onInvalid, onSuccess, onSubmit, onError, reset }: EnhanceOptions<T>): ({ submit, ...rest }: EnhanceParams<T>) => Promise<void>;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export function makeEnhance(remoteForm, { onInvalid, onSuccess, onSubmit, onError, reset = true }) {
|
|
2
|
+
return async ({ submit, ...rest }) => {
|
|
3
|
+
const params = {
|
|
4
|
+
...rest,
|
|
5
|
+
result: remoteForm.result
|
|
6
|
+
};
|
|
7
|
+
try {
|
|
8
|
+
await submit();
|
|
9
|
+
if (remoteForm.fields.allIssues()) {
|
|
10
|
+
await onInvalid?.(params);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
await onSuccess?.(params);
|
|
14
|
+
}
|
|
15
|
+
await onSubmit?.(params);
|
|
16
|
+
if (reset) {
|
|
17
|
+
params.form.reset();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
await onError?.({
|
|
22
|
+
...rest,
|
|
23
|
+
error
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thetinkerinc/sprout",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -52,7 +52,11 @@
|
|
|
52
52
|
},
|
|
53
53
|
"./events": {
|
|
54
54
|
"types": "./dist/events/index.d.ts",
|
|
55
|
-
"
|
|
55
|
+
"import": "./dist/events/index.js"
|
|
56
|
+
},
|
|
57
|
+
"./forms": {
|
|
58
|
+
"types": "./dist/forms/index.d.ts",
|
|
59
|
+
"import": "./dist/forms/index.js"
|
|
56
60
|
},
|
|
57
61
|
"./vite": {
|
|
58
62
|
"types": "./dist/vite/index.d.ts",
|
|
@@ -66,15 +70,15 @@
|
|
|
66
70
|
"devDependencies": {
|
|
67
71
|
"@eslint/compat": "^2.0.2",
|
|
68
72
|
"@eslint/js": "^10.0.1",
|
|
69
|
-
"@inlang/paraglide-js": "^2.
|
|
73
|
+
"@inlang/paraglide-js": "^2.13.0",
|
|
70
74
|
"@sveltejs/adapter-cloudflare": "^7.2.8",
|
|
71
|
-
"@sveltejs/kit": "^2.53.
|
|
75
|
+
"@sveltejs/kit": "^2.53.3",
|
|
72
76
|
"@sveltejs/package": "^2.5.7",
|
|
73
77
|
"@sveltejs/vite-plugin-svelte": "^6.2.4",
|
|
74
78
|
"@tailwindcss/forms": "^0.5.11",
|
|
75
79
|
"@tailwindcss/typography": "^0.5.19",
|
|
76
80
|
"@tailwindcss/vite": "^4.2.1",
|
|
77
|
-
"@types/node": "^25.3.
|
|
81
|
+
"@types/node": "^25.3.2",
|
|
78
82
|
"@types/pg": "^8.16.0",
|
|
79
83
|
"eslint": "^10.0.2",
|
|
80
84
|
"eslint-config-prettier": "^10.1.8",
|
|
@@ -86,7 +90,7 @@
|
|
|
86
90
|
"prettier-plugin-tailwindcss": "^0.7.2",
|
|
87
91
|
"publint": "^0.3.17",
|
|
88
92
|
"svelte": "^5.53.5",
|
|
89
|
-
"svelte-check": "^4.4.
|
|
93
|
+
"svelte-check": "^4.4.4",
|
|
90
94
|
"svelte-clerk": "^0.20.5",
|
|
91
95
|
"tailwindcss": "^4.2.1",
|
|
92
96
|
"typescript": "^5.9.3",
|