fuma 0.2.3 → 0.2.6
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/server/formAction.d.ts +14 -0
- package/dist/server/formAction.js +8 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +1 -0
- package/dist/server/parseFormData.d.ts +7 -17
- package/dist/server/parseFormData.js +4 -5
- package/dist/server/try.d.ts +5 -2
- package/dist/server/try.js +15 -4
- package/dist/ui/drawer/layers.js +0 -1
- package/dist/ui/form/Form.svelte +14 -4
- package/dist/ui/form/Form.svelte.d.ts +9 -7
- package/dist/ui/form/FormInput.svelte +4 -2
- package/dist/ui/form/FormInput.svelte.d.ts +116 -0
- package/dist/ui/form/form.d.ts +8 -3
- package/dist/ui/form/form.js +30 -0
- package/dist/ui/input/RelationAfter.svelte +7 -1
- package/dist/ui/menu/DropDownMenu.svelte +2 -1
- package/dist/ui/menu/DropDownMenu.svelte.d.ts +2 -0
- package/dist/ui/slot/Slot.svelte +3 -1
- package/dist/ui/slot/Slot.svelte.d.ts +22 -0
- package/dist/validation/zod.d.ts +2 -0
- package/dist/validation/zod.js +4 -4
- package/package.json +6 -6
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import type { RequestEvent } from '@sveltejs/kit';
|
|
3
|
+
export declare function formAction<E extends RequestEvent, Shape extends z.ZodRawShape = z.ZodRawShape, ReturnType extends unknown = unknown>(shapes: Shape | Shape[], func: (arg: E & {
|
|
4
|
+
event: E;
|
|
5
|
+
data: z.baseObjectOutputType<Shape>;
|
|
6
|
+
formData: FormData;
|
|
7
|
+
}) => Promise<ReturnType>, options?: {
|
|
8
|
+
validation?: z.SuperRefinement<z.objectOutputType<Shape, z.ZodTypeAny>>;
|
|
9
|
+
redirectTo?: string | ((res: ReturnType) => string);
|
|
10
|
+
}): (event: E) => Promise<import("@sveltejs/kit").ActionFailure<{
|
|
11
|
+
message: string;
|
|
12
|
+
} | {
|
|
13
|
+
issues: import("./parseFormData.js").Issue[];
|
|
14
|
+
}> | ReturnType>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { parseFormData } from './parseFormData.js';
|
|
2
|
+
import { tryOrFail } from './try.js';
|
|
3
|
+
export function formAction(shapes, func, options = {}) {
|
|
4
|
+
return (event) => tryOrFail(async () => {
|
|
5
|
+
const { data, formData } = await parseFormData(event.request, shapes, options.validation);
|
|
6
|
+
return func({ ...event, event, data, formData });
|
|
7
|
+
}, options.redirectTo);
|
|
8
|
+
}
|
package/dist/server/index.d.ts
CHANGED
package/dist/server/index.js
CHANGED
|
@@ -1,20 +1,10 @@
|
|
|
1
|
-
/// <reference types="@sveltejs/kit" />
|
|
2
1
|
import z from 'zod';
|
|
3
|
-
export
|
|
2
|
+
export type Issue = z.ZodIssue & {
|
|
3
|
+
received: string;
|
|
4
|
+
expected: string;
|
|
5
|
+
unionErrors?: z.ZodError[];
|
|
6
|
+
};
|
|
7
|
+
export declare function parseFormData<Shape extends z.ZodRawShape>(requestOrFormData: Request | FormData, shapes: Shape | Shape[], validation?: z.SuperRefinement<z.objectOutputType<Shape, z.ZodTypeAny>>): Promise<{
|
|
8
|
+
data: { [k_1 in keyof z.objectUtil.addQuestionMarks<z.baseObjectOutputType<Shape>, { [k in keyof z.baseObjectOutputType<Shape>]: undefined extends z.baseObjectOutputType<Shape>[k] ? never : k; }[keyof Shape]>]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<Shape>, { [k_2 in keyof z.baseObjectOutputType<Shape>]: undefined extends z.baseObjectOutputType<Shape>[k_2] ? never : k_2; }[keyof Shape]>[k_1]; };
|
|
4
9
|
formData: FormData;
|
|
5
|
-
err: import("@sveltejs/kit").ActionFailure<{
|
|
6
|
-
issues: {
|
|
7
|
-
message: string;
|
|
8
|
-
path: (string | number)[];
|
|
9
|
-
code: "invalid_type" | "invalid_literal" | "unrecognized_keys" | "invalid_union" | "invalid_union_discriminator" | "invalid_enum_value" | "invalid_arguments" | "invalid_return_type" | "invalid_date" | "invalid_string" | "too_small" | "too_big" | "invalid_intersection_types" | "not_multiple_of" | "not_finite" | "custom";
|
|
10
|
-
received: string;
|
|
11
|
-
expected: string;
|
|
12
|
-
unionErrors: z.typeToFlattenedError<any, string>[] | undefined;
|
|
13
|
-
}[];
|
|
14
|
-
}>;
|
|
15
|
-
data?: undefined;
|
|
16
|
-
} | {
|
|
17
|
-
data: { [k_1 in keyof z.objectUtil.addQuestionMarks<z.baseObjectOutputType<Type>, { [k in keyof z.baseObjectOutputType<Type>]: undefined extends z.baseObjectOutputType<Type>[k] ? never : k; }[keyof Type]>]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<Type>, { [k_2 in keyof z.baseObjectOutputType<Type>]: undefined extends z.baseObjectOutputType<Type>[k_2] ? never : k_2; }[keyof Type]>[k_1]; };
|
|
18
|
-
formData: FormData;
|
|
19
|
-
err?: undefined;
|
|
20
10
|
}>;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import z from 'zod';
|
|
2
|
-
|
|
3
|
-
export async function parseFormData(requestOrFormData, shaps, validation) {
|
|
2
|
+
export async function parseFormData(requestOrFormData, shapes, validation) {
|
|
4
3
|
const formData = requestOrFormData instanceof Request ? await requestOrFormData.formData() : requestOrFormData;
|
|
5
|
-
const [firstShap, ...unionShaps] = Array.isArray(
|
|
4
|
+
const [firstShap, ...unionShaps] = Array.isArray(shapes) ? shapes : [shapes];
|
|
6
5
|
const shema = z.object(firstShap).superRefine(validation || (() => { }));
|
|
7
6
|
unionShaps.forEach((shap) => shema.or(z.object(shap)));
|
|
8
7
|
const formDataFlateObject = Object.fromEntries(formData);
|
|
@@ -15,10 +14,10 @@ export async function parseFormData(requestOrFormData, shaps, validation) {
|
|
|
15
14
|
code: issue.code,
|
|
16
15
|
received: issue.received,
|
|
17
16
|
expected: issue.expected,
|
|
18
|
-
unionErrors: issue.unionErrors?.map((err) => err.flatten())
|
|
17
|
+
unionErrors: issue.unionErrors?.map((err) => err.flatten())
|
|
19
18
|
});
|
|
20
19
|
const issues = parsed.error.issues.map(issueToPOJO);
|
|
21
|
-
|
|
20
|
+
throw { issues };
|
|
22
21
|
}
|
|
23
22
|
return { data: parsed.data, formData };
|
|
24
23
|
}
|
package/dist/server/try.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { type ActionFailure } from '@sveltejs/kit';
|
|
2
|
-
|
|
2
|
+
import type { Issue } from './parseFormData.js';
|
|
3
|
+
export declare function tryOrFail<T = unknown>(func: () => Promise<T>,
|
|
3
4
|
/** You can redirect on success */
|
|
4
|
-
redirectTo?: string | ((res: T) => string)): Promise<T | ActionFailure<{
|
|
5
|
+
redirectTo?: string | ((res: T) => string | undefined)): Promise<T | ActionFailure<{
|
|
5
6
|
message: string;
|
|
7
|
+
} | {
|
|
8
|
+
issues: Issue[];
|
|
6
9
|
}>>;
|
package/dist/server/try.js
CHANGED
|
@@ -1,21 +1,28 @@
|
|
|
1
1
|
import { fail, redirect } from '@sveltejs/kit';
|
|
2
|
-
export async function tryOrFail(
|
|
2
|
+
export async function tryOrFail(func,
|
|
3
3
|
/** You can redirect on success */
|
|
4
4
|
redirectTo) {
|
|
5
5
|
let result = null;
|
|
6
6
|
let isSuccess = false;
|
|
7
7
|
try {
|
|
8
|
-
result = await
|
|
8
|
+
result = await func();
|
|
9
9
|
isSuccess = true;
|
|
10
10
|
return result;
|
|
11
11
|
}
|
|
12
12
|
catch (error) {
|
|
13
|
+
// Handle Classic error
|
|
13
14
|
if ('status' in error && 'body' in error && 'message' in error.body) {
|
|
14
15
|
return fail(error.status, { message: error.body.message });
|
|
15
16
|
}
|
|
17
|
+
// Handle Prisma error
|
|
16
18
|
if ('meta' in error && error.meta && 'cause' in error.meta) {
|
|
17
19
|
return fail(400, { message: error.meta.cause });
|
|
18
20
|
}
|
|
21
|
+
// Handle parseFormData error
|
|
22
|
+
if ('issues' in error) {
|
|
23
|
+
console.log(error.issues);
|
|
24
|
+
return fail(400, { issues: error.issues });
|
|
25
|
+
}
|
|
19
26
|
const { message } = error;
|
|
20
27
|
return fail(400, { message });
|
|
21
28
|
}
|
|
@@ -23,8 +30,12 @@ redirectTo) {
|
|
|
23
30
|
if (isSuccess && redirectTo) {
|
|
24
31
|
if (typeof redirectTo === 'string')
|
|
25
32
|
redirect(302, redirectTo);
|
|
26
|
-
else if (result)
|
|
27
|
-
|
|
33
|
+
else if (result) {
|
|
34
|
+
const url = redirectTo(result);
|
|
35
|
+
if (url)
|
|
36
|
+
redirect(302, url);
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
28
39
|
console.warn('No result can be provide in redirectTo() function. Please use a simple string.');
|
|
29
40
|
}
|
|
30
41
|
}
|
package/dist/ui/drawer/layers.js
CHANGED
|
@@ -6,7 +6,6 @@ const layersOffset = derived(layers, ($layers) => {
|
|
|
6
6
|
const nbDrawer = $layers.length;
|
|
7
7
|
return $layers.reduce((acc, layer, index) => {
|
|
8
8
|
const drawerOffset = nbDrawer - index - 1;
|
|
9
|
-
console.log({ drawerOffset });
|
|
10
9
|
return { ...acc, [layer]: drawerOffset };
|
|
11
10
|
}, {});
|
|
12
11
|
});
|
package/dist/ui/form/Form.svelte
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
<script
|
|
2
|
-
|
|
1
|
+
<script context="module"></script>
|
|
2
|
+
|
|
3
|
+
<script
|
|
4
|
+
|
|
5
|
+
generics="Shape extends z.ZodRawShape, ReturnData extends Record<string, unknown> = FormData<Shape>"
|
|
6
|
+
>import { createEventDispatcher, onMount } from "svelte";
|
|
3
7
|
import { fade } from "svelte/transition";
|
|
4
8
|
import { page } from "$app/stores";
|
|
9
|
+
import { contextContainer } from "../context.js";
|
|
5
10
|
import {
|
|
6
11
|
initData,
|
|
7
|
-
getFieldType
|
|
12
|
+
getFieldType,
|
|
13
|
+
useHandleInput
|
|
8
14
|
} from "./form.js";
|
|
9
15
|
import { useForm } from "../../validation/form.js";
|
|
10
16
|
import Input from "./FormInput.svelte";
|
|
@@ -13,6 +19,7 @@ let klass = "";
|
|
|
13
19
|
export { klass as class };
|
|
14
20
|
export let classSection = "";
|
|
15
21
|
export let classAction = "";
|
|
22
|
+
export let model = void 0;
|
|
16
23
|
export let fields = [];
|
|
17
24
|
export let sections = [{}];
|
|
18
25
|
export let data = initData(fields);
|
|
@@ -24,7 +31,7 @@ export function set(key, value) {
|
|
|
24
31
|
data[key] = value;
|
|
25
32
|
}
|
|
26
33
|
const dispatch = createEventDispatcher();
|
|
27
|
-
const { enhance } = useForm({
|
|
34
|
+
const { enhance, setError } = useForm({
|
|
28
35
|
...options,
|
|
29
36
|
onSuccess(action2, data2) {
|
|
30
37
|
dispatch("success", { action: action2, data: data2 });
|
|
@@ -32,6 +39,8 @@ const { enhance } = useForm({
|
|
|
32
39
|
options.onSuccess(action2, data2);
|
|
33
40
|
}
|
|
34
41
|
});
|
|
42
|
+
const handleInput = model ? useHandleInput(model, { setError }) : () => {
|
|
43
|
+
};
|
|
35
44
|
onMount(lookupValueFromParams);
|
|
36
45
|
function lookupValueFromParams() {
|
|
37
46
|
fields.flat().forEach(({ key }) => {
|
|
@@ -60,6 +69,7 @@ const getBoolean = (bool) => (_data) => typeof bool === "boolean" || bool === vo
|
|
|
60
69
|
enctype="multipart/form-data"
|
|
61
70
|
class="{klass} flex flex-col gap-4"
|
|
62
71
|
use:enhance
|
|
72
|
+
on:input={handleInput}
|
|
63
73
|
>
|
|
64
74
|
{#if data.id}
|
|
65
75
|
<input type="hidden" name="id" value={data.id} />
|
|
@@ -1,35 +1,37 @@
|
|
|
1
1
|
import { SvelteComponent } from "svelte";
|
|
2
2
|
import type { z } from 'zod';
|
|
3
|
+
import type { FormData } from './form.js';
|
|
3
4
|
import { type FormField, type FormSectionProps } from './form.js';
|
|
4
5
|
import { type UseFormOptions } from '../../validation/form.js';
|
|
5
|
-
declare class __sveltets_Render<Shape extends z.ZodRawShape> {
|
|
6
|
+
declare class __sveltets_Render<Shape extends z.ZodRawShape, ReturnData extends Record<string, unknown> = FormData<Shape>> {
|
|
6
7
|
props(): {
|
|
7
8
|
class?: string | undefined;
|
|
8
9
|
classSection?: string | undefined;
|
|
9
10
|
classAction?: string | undefined;
|
|
11
|
+
model?: Shape | undefined;
|
|
10
12
|
fields?: FormField<Shape>[][] | undefined;
|
|
11
13
|
sections?: FormSectionProps<Shape>[] | undefined;
|
|
12
14
|
data?: Partial<z.objectUtil.addQuestionMarks<z.baseObjectOutputType<Shape>, { [k_1 in keyof z.baseObjectOutputType<Shape>]: undefined extends z.baseObjectOutputType<Shape>[k_1] ? never : k_1; }[keyof Shape]> extends infer T ? { [k in keyof T]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<Shape>, { [k_1 in keyof z.baseObjectOutputType<Shape>]: undefined extends z.baseObjectOutputType<Shape>[k_1] ? never : k_1; }[keyof Shape]>[k]; } : never> | undefined;
|
|
13
15
|
action?: string | undefined;
|
|
14
16
|
actionDelete?: string | undefined;
|
|
15
17
|
actionPrefix?: string | undefined;
|
|
16
|
-
options?: UseFormOptions<
|
|
18
|
+
options?: UseFormOptions<ReturnData> | undefined;
|
|
17
19
|
set?: (<K extends keyof Shape>(key: K, value: Partial<z.objectUtil.addQuestionMarks<z.baseObjectOutputType<Shape>, { [k_1 in keyof z.baseObjectOutputType<Shape>]: undefined extends z.baseObjectOutputType<Shape>[k_1] ? never : k_1; }[keyof Shape]> extends infer T_1 ? { [k in keyof T_1]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<Shape>, { [k_1 in keyof z.baseObjectOutputType<Shape>]: undefined extends z.baseObjectOutputType<Shape>[k_1] ? never : k_1; }[keyof Shape]>[k]; } : never>[K]) => void) | undefined;
|
|
18
20
|
};
|
|
19
21
|
events(): {
|
|
20
22
|
success: CustomEvent<{
|
|
21
23
|
action: URL;
|
|
22
|
-
data?:
|
|
24
|
+
data?: ReturnData | undefined;
|
|
23
25
|
}>;
|
|
24
26
|
} & {
|
|
25
27
|
[evt: string]: CustomEvent<any>;
|
|
26
28
|
};
|
|
27
29
|
slots(): {};
|
|
28
30
|
}
|
|
29
|
-
export type FormProps<Shape extends z.ZodRawShape> = ReturnType<__sveltets_Render<Shape>['props']>;
|
|
30
|
-
export type FormEvents<Shape extends z.ZodRawShape> = ReturnType<__sveltets_Render<Shape>['events']>;
|
|
31
|
-
export type FormSlots<Shape extends z.ZodRawShape> = ReturnType<__sveltets_Render<Shape>['slots']>;
|
|
32
|
-
export default class Form<Shape extends z.ZodRawShape> extends SvelteComponent<FormProps<Shape>, FormEvents<Shape>, FormSlots<Shape>> {
|
|
31
|
+
export type FormProps<Shape extends z.ZodRawShape, ReturnData extends Record<string, unknown> = FormData<Shape>> = ReturnType<__sveltets_Render<Shape, ReturnData>['props']>;
|
|
32
|
+
export type FormEvents<Shape extends z.ZodRawShape, ReturnData extends Record<string, unknown> = FormData<Shape>> = ReturnType<__sveltets_Render<Shape, ReturnData>['events']>;
|
|
33
|
+
export type FormSlots<Shape extends z.ZodRawShape, ReturnData extends Record<string, unknown> = FormData<Shape>> = ReturnType<__sveltets_Render<Shape, ReturnData>['slots']>;
|
|
34
|
+
export default class Form<Shape extends z.ZodRawShape, ReturnData extends Record<string, unknown> = FormData<Shape>> extends SvelteComponent<FormProps<Shape, ReturnData>, FormEvents<Shape, ReturnData>, FormSlots<Shape, ReturnData>> {
|
|
33
35
|
get set(): <K extends keyof Shape>(key: K, value: Partial<z.objectUtil.addQuestionMarks<z.baseObjectOutputType<Shape>, { [k_1 in keyof z.baseObjectOutputType<Shape>]: undefined extends z.baseObjectOutputType<Shape>[k_1] ? never : k_1; }[keyof Shape]> extends infer T ? { [k in keyof T]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<Shape>, { [k_1 in keyof z.baseObjectOutputType<Shape>]: undefined extends z.baseObjectOutputType<Shape>[k_1] ? never : k_1; }[keyof Shape]>[k]; } : never>[K]) => void;
|
|
34
36
|
}
|
|
35
37
|
export {};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
<script>import { formInputs } from "./formInput.js";
|
|
1
|
+
<script generics="InputType extends FormInputsType">import { formInputs } from "./formInput.js";
|
|
2
2
|
let inputType;
|
|
3
3
|
export { inputType as type };
|
|
4
4
|
export let value;
|
|
5
|
+
$:
|
|
6
|
+
component = formInputs[inputType];
|
|
5
7
|
</script>
|
|
6
8
|
|
|
7
|
-
<svelte:component this={
|
|
9
|
+
<svelte:component this={component} bind:value {...$$restProps} />
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
import { type FormInputsType } from './formInput.js';
|
|
3
|
+
declare class __sveltets_Render<InputType extends FormInputsType> {
|
|
4
|
+
props(): import("svelte").ComponentProps<InstanceType<{
|
|
5
|
+
readonly text: typeof import("../index.js").InputText;
|
|
6
|
+
readonly textarea: typeof import("../index.js").InputTextarea;
|
|
7
|
+
readonly textrich: typeof import("../index.js").InputTextRich;
|
|
8
|
+
readonly boolean: typeof import("../index.js").InputBoolean;
|
|
9
|
+
readonly date: typeof import("../index.js").InputDate;
|
|
10
|
+
readonly datetime: typeof import("../index.js").InputDatetime;
|
|
11
|
+
readonly number: typeof import("../index.js").InputNumber;
|
|
12
|
+
readonly password: typeof import("../index.js").InputPassword;
|
|
13
|
+
readonly select: typeof import("../index.js").InputSelect;
|
|
14
|
+
readonly radio: typeof import("../index.js").InputRadio;
|
|
15
|
+
readonly relation: {
|
|
16
|
+
new (options: import("svelte").ComponentConstructorOptions<{
|
|
17
|
+
key?: string | undefined;
|
|
18
|
+
label?: string | undefined;
|
|
19
|
+
search: (q: string) => Promise<any[]>;
|
|
20
|
+
createUrl?: string | undefined;
|
|
21
|
+
createTitle?: string | undefined;
|
|
22
|
+
createIcon?: string | undefined;
|
|
23
|
+
value?: any;
|
|
24
|
+
error?: string | undefined;
|
|
25
|
+
placeholder?: string | undefined;
|
|
26
|
+
tippyProps?: Partial<import("tippy.js").Props> | undefined;
|
|
27
|
+
flatMode?: boolean | undefined;
|
|
28
|
+
slotItem?: ((item: any) => string | import("../../index.js").ComponentAndProps) | null | undefined;
|
|
29
|
+
slotSuggestion?: ((item: any) => string | import("../../index.js").ComponentAndProps) | null | undefined;
|
|
30
|
+
class?: string | undefined;
|
|
31
|
+
classList?: string | undefined;
|
|
32
|
+
clear?: (() => Promise<void>) | undefined;
|
|
33
|
+
}>): import("../index.js").InputRelation<any>;
|
|
34
|
+
};
|
|
35
|
+
readonly relations: {
|
|
36
|
+
new (options: import("svelte").ComponentConstructorOptions<{
|
|
37
|
+
key?: string | undefined;
|
|
38
|
+
label?: string | undefined;
|
|
39
|
+
search: (q: string) => Promise<any[]>;
|
|
40
|
+
createUrl?: string | undefined;
|
|
41
|
+
createTitle?: string | undefined;
|
|
42
|
+
createIcon?: string | undefined;
|
|
43
|
+
error?: string | undefined;
|
|
44
|
+
placeholder?: string | undefined;
|
|
45
|
+
flatMode?: boolean | undefined;
|
|
46
|
+
slotItem?: ((item: any) => string | import("../../index.js").ComponentAndProps) | null | undefined;
|
|
47
|
+
slotSuggestion?: ((item: any) => string | import("../../index.js").ComponentAndProps) | null | undefined;
|
|
48
|
+
class?: string | undefined;
|
|
49
|
+
classList?: string | undefined;
|
|
50
|
+
value?: any[] | null | undefined;
|
|
51
|
+
}>): import("../index.js").InputRelations<any>;
|
|
52
|
+
};
|
|
53
|
+
}[InputType]>> & {
|
|
54
|
+
type: InputType;
|
|
55
|
+
value: import("svelte").ComponentProps<InstanceType<{
|
|
56
|
+
readonly text: typeof import("../index.js").InputText;
|
|
57
|
+
readonly textarea: typeof import("../index.js").InputTextarea;
|
|
58
|
+
readonly textrich: typeof import("../index.js").InputTextRich;
|
|
59
|
+
readonly boolean: typeof import("../index.js").InputBoolean;
|
|
60
|
+
readonly date: typeof import("../index.js").InputDate;
|
|
61
|
+
readonly datetime: typeof import("../index.js").InputDatetime;
|
|
62
|
+
readonly number: typeof import("../index.js").InputNumber;
|
|
63
|
+
readonly password: typeof import("../index.js").InputPassword;
|
|
64
|
+
readonly select: typeof import("../index.js").InputSelect;
|
|
65
|
+
readonly radio: typeof import("../index.js").InputRadio;
|
|
66
|
+
readonly relation: {
|
|
67
|
+
new (options: import("svelte").ComponentConstructorOptions<{
|
|
68
|
+
key?: string | undefined;
|
|
69
|
+
label?: string | undefined;
|
|
70
|
+
search: (q: string) => Promise<any[]>;
|
|
71
|
+
createUrl?: string | undefined;
|
|
72
|
+
createTitle?: string | undefined;
|
|
73
|
+
createIcon?: string | undefined;
|
|
74
|
+
value?: any;
|
|
75
|
+
error?: string | undefined;
|
|
76
|
+
placeholder?: string | undefined;
|
|
77
|
+
tippyProps?: Partial<import("tippy.js").Props> | undefined;
|
|
78
|
+
flatMode?: boolean | undefined;
|
|
79
|
+
slotItem?: ((item: any) => string | import("../../index.js").ComponentAndProps) | null | undefined;
|
|
80
|
+
slotSuggestion?: ((item: any) => string | import("../../index.js").ComponentAndProps) | null | undefined;
|
|
81
|
+
class?: string | undefined;
|
|
82
|
+
classList?: string | undefined;
|
|
83
|
+
clear?: (() => Promise<void>) | undefined;
|
|
84
|
+
}>): import("../index.js").InputRelation<any>;
|
|
85
|
+
};
|
|
86
|
+
readonly relations: {
|
|
87
|
+
new (options: import("svelte").ComponentConstructorOptions<{
|
|
88
|
+
key?: string | undefined;
|
|
89
|
+
label?: string | undefined;
|
|
90
|
+
search: (q: string) => Promise<any[]>;
|
|
91
|
+
createUrl?: string | undefined;
|
|
92
|
+
createTitle?: string | undefined;
|
|
93
|
+
createIcon?: string | undefined;
|
|
94
|
+
error?: string | undefined;
|
|
95
|
+
placeholder?: string | undefined;
|
|
96
|
+
flatMode?: boolean | undefined;
|
|
97
|
+
slotItem?: ((item: any) => string | import("../../index.js").ComponentAndProps) | null | undefined;
|
|
98
|
+
slotSuggestion?: ((item: any) => string | import("../../index.js").ComponentAndProps) | null | undefined;
|
|
99
|
+
class?: string | undefined;
|
|
100
|
+
classList?: string | undefined;
|
|
101
|
+
value?: any[] | null | undefined;
|
|
102
|
+
}>): import("../index.js").InputRelations<any>;
|
|
103
|
+
};
|
|
104
|
+
}[InputType]>>["value"];
|
|
105
|
+
};
|
|
106
|
+
events(): {} & {
|
|
107
|
+
[evt: string]: CustomEvent<any>;
|
|
108
|
+
};
|
|
109
|
+
slots(): {};
|
|
110
|
+
}
|
|
111
|
+
export type FormInputProps_<InputType extends FormInputsType> = ReturnType<__sveltets_Render<InputType>['props']>;
|
|
112
|
+
export type FormInputEvents<InputType extends FormInputsType> = ReturnType<__sveltets_Render<InputType>['events']>;
|
|
113
|
+
export type FormInputSlots<InputType extends FormInputsType> = ReturnType<__sveltets_Render<InputType>['slots']>;
|
|
114
|
+
export default class FormInput<InputType extends FormInputsType> extends SvelteComponent<FormInputProps_<InputType>, FormInputEvents<InputType>, FormInputSlots<InputType>> {
|
|
115
|
+
}
|
|
116
|
+
export {};
|
package/dist/ui/form/form.d.ts
CHANGED
|
@@ -2,12 +2,13 @@ import type { z } from 'zod';
|
|
|
2
2
|
import type { ComponentProps } from 'svelte';
|
|
3
3
|
import { type FormInputsProps, type FormInputsType } from './formInput.js';
|
|
4
4
|
import type FormSection from './FormSection.svelte';
|
|
5
|
+
import type { FormEventHandler } from 'svelte/elements';
|
|
5
6
|
type Shape = z.ZodRawShape;
|
|
6
7
|
type PickOne<T> = {
|
|
7
8
|
[P in keyof T]: Record<P, T[P]> & Partial<Record<Exclude<keyof T, P>, undefined>>;
|
|
8
9
|
}[keyof T];
|
|
9
|
-
export type BoolOrFunction<M extends Shape> = boolean | ((data: FormData<M
|
|
10
|
-
export type FormData<M extends Shape> =
|
|
10
|
+
export type BoolOrFunction<M extends Shape> = boolean | ((data: Partial<FormData<M>>) => unknown);
|
|
11
|
+
export type FormData<M extends Shape> = z.infer<z.ZodObject<M>>;
|
|
11
12
|
export type FormField<M extends Shape> = {
|
|
12
13
|
key: string & keyof M;
|
|
13
14
|
/** number col used by field */
|
|
@@ -19,6 +20,10 @@ export type FormSectionProps<M extends Shape> = ComponentProps<FormSection> & {
|
|
|
19
20
|
/** hide group if true */
|
|
20
21
|
hide?: BoolOrFunction<M>;
|
|
21
22
|
};
|
|
22
|
-
export declare function initData<M extends Shape>(fields: FormField<M>[][]): FormData<M
|
|
23
|
+
export declare function initData<M extends Shape>(fields: FormField<M>[][]): Partial<FormData<M>>;
|
|
23
24
|
export declare function getFieldType<M extends Shape>(field: FormField<M>): FormInputsType;
|
|
25
|
+
type HandleInputOptions = {
|
|
26
|
+
setError: (key: string, value: string) => void;
|
|
27
|
+
};
|
|
28
|
+
export declare function useHandleInput(model: Shape, { setError }: HandleInputOptions): FormEventHandler<HTMLFormElement>;
|
|
24
29
|
export {};
|
package/dist/ui/form/form.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { formInputsType } from './formInput.js';
|
|
2
|
+
import debounce from 'debounce';
|
|
2
3
|
export function initData(fields) {
|
|
3
4
|
// @ts-ignore
|
|
4
5
|
return fields.flat().reduce((acc, cur) => {
|
|
@@ -13,3 +14,32 @@ export function getFieldType(field) {
|
|
|
13
14
|
return 'text';
|
|
14
15
|
return inputType;
|
|
15
16
|
}
|
|
17
|
+
export function useHandleInput(model, { setError }) {
|
|
18
|
+
const setErrorDebounced = debounce(setError, 1500);
|
|
19
|
+
return ({ target }) => {
|
|
20
|
+
if (!target)
|
|
21
|
+
return;
|
|
22
|
+
const { name, type, value, valueAsNumber, valueAsDate, checked } = target;
|
|
23
|
+
const typeMapValue = {
|
|
24
|
+
number: valueAsNumber,
|
|
25
|
+
date: valueAsDate,
|
|
26
|
+
text: value,
|
|
27
|
+
checkbox: checked
|
|
28
|
+
};
|
|
29
|
+
const v = typeMapValue[type] ?? value;
|
|
30
|
+
if (v === undefined || name === undefined)
|
|
31
|
+
return;
|
|
32
|
+
if (name === undefined)
|
|
33
|
+
return;
|
|
34
|
+
if (!model[name])
|
|
35
|
+
return;
|
|
36
|
+
const res = model[name].safeParse(v);
|
|
37
|
+
if (res.success) {
|
|
38
|
+
setErrorDebounced.clear();
|
|
39
|
+
setError(name, '');
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
setErrorDebounced(name, res.error.issues[0].message);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -18,7 +18,13 @@ const dispatch = createEventDispatcher();
|
|
|
18
18
|
/>
|
|
19
19
|
</div>
|
|
20
20
|
{:else if createUrl}
|
|
21
|
-
<a
|
|
21
|
+
<a
|
|
22
|
+
href={createUrl}
|
|
23
|
+
class="btn btn-square btn-sm"
|
|
24
|
+
in:fade|local={{ duration: 200 }}
|
|
25
|
+
data-sveltekit-noscroll
|
|
26
|
+
data-sveltekit-replacestate
|
|
27
|
+
>
|
|
22
28
|
<Icon path={createIcon} on:click={() => dispatch('create')} title={createTitle} />
|
|
23
29
|
</a>
|
|
24
30
|
{/if}
|
|
@@ -5,6 +5,7 @@ import { DropDown } from "./index.js";
|
|
|
5
5
|
import { SelectorList } from "../input/index.js";
|
|
6
6
|
import { parseOptions } from "../../utils/options.js";
|
|
7
7
|
export let options;
|
|
8
|
+
export let tippyProps = {};
|
|
8
9
|
$:
|
|
9
10
|
_options = parseOptions(options);
|
|
10
11
|
let trigger;
|
|
@@ -17,7 +18,7 @@ function onSelect(index) {
|
|
|
17
18
|
}
|
|
18
19
|
</script>
|
|
19
20
|
|
|
20
|
-
<DropDown bind:this={dropDown}>
|
|
21
|
+
<DropDown bind:this={dropDown} {tippyProps}>
|
|
21
22
|
<div class="contents" bind:this={trigger} slot="activator">
|
|
22
23
|
<slot>
|
|
23
24
|
<button type="button" class="flex h-12 items-center gap-2 rounded-lg border pl-4 pr-2">
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { SvelteComponent } from "svelte";
|
|
2
2
|
import { type Options } from '../../utils/options.js';
|
|
3
|
+
import type { TippyProps } from '../../utils/tippy.js';
|
|
3
4
|
declare const __propDef: {
|
|
4
5
|
props: {
|
|
5
6
|
options: Options;
|
|
7
|
+
tippyProps?: Partial<TippyProps> | undefined;
|
|
6
8
|
};
|
|
7
9
|
events: {
|
|
8
10
|
select: CustomEvent<string>;
|
package/dist/ui/slot/Slot.svelte
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
type _Slot = ((...args: any) => ComponentAndProps | ComponentType | string) | ComponentAndProps | ComponentType | string;
|
|
3
|
+
import { type ComponentType } from 'svelte';
|
|
4
|
+
import { type ComponentAndProps } from '../../utils/component.js';
|
|
5
|
+
declare class __sveltets_Render<Slot extends _Slot> {
|
|
6
|
+
props(): {
|
|
7
|
+
slot?: Slot | null | undefined;
|
|
8
|
+
args?: (Slot extends (...args: any) => any ? Parameters<Slot>[0] : undefined) | null | undefined;
|
|
9
|
+
};
|
|
10
|
+
events(): {} & {
|
|
11
|
+
[evt: string]: CustomEvent<any>;
|
|
12
|
+
};
|
|
13
|
+
slots(): {
|
|
14
|
+
default: {};
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export type SlotProps<Slot extends _Slot> = ReturnType<__sveltets_Render<Slot>['props']>;
|
|
18
|
+
export type SlotEvents<Slot extends _Slot> = ReturnType<__sveltets_Render<Slot>['events']>;
|
|
19
|
+
export type SlotSlots<Slot extends _Slot> = ReturnType<__sveltets_Render<Slot>['slots']>;
|
|
20
|
+
export default class Slot<Slot extends _Slot> extends SvelteComponent<SlotProps<Slot>, SlotEvents<Slot>, SlotSlots<Slot>> {
|
|
21
|
+
}
|
|
22
|
+
export {};
|
package/dist/validation/zod.d.ts
CHANGED
|
@@ -325,6 +325,8 @@ export declare const z: {
|
|
|
325
325
|
quotelessJson: (obj: any) => string;
|
|
326
326
|
ZodError: typeof zod.ZodError;
|
|
327
327
|
};
|
|
328
|
+
export type ZodInfer<T extends zod.ZodType<any, any, any>> = T['_output'];
|
|
329
|
+
export type SuperRefinement<T> = zod.SuperRefinement<T>;
|
|
328
330
|
/**
|
|
329
331
|
* @example type MyModel = {name: z.string()} satisfies ZodObj<{name: string}>
|
|
330
332
|
*/
|
package/dist/validation/zod.js
CHANGED
|
@@ -84,14 +84,14 @@ const filter = {
|
|
|
84
84
|
};
|
|
85
85
|
export const z = {
|
|
86
86
|
...zod,
|
|
87
|
-
json,
|
|
88
|
-
array,
|
|
89
|
-
arrayRaw: zod.array,
|
|
87
|
+
json, // TODO: rename stringAsObject
|
|
88
|
+
array, // TODO: rename stringAsArray
|
|
89
|
+
arrayRaw: zod.array, // TODO: remove
|
|
90
90
|
relation,
|
|
91
91
|
relations,
|
|
92
92
|
filter,
|
|
93
93
|
dateOptional,
|
|
94
|
-
booleanAsString,
|
|
94
|
+
booleanAsString, // TODO: rename stringAsBoolean
|
|
95
95
|
date: zod.coerce.date,
|
|
96
96
|
number: zod.coerce.number,
|
|
97
97
|
bigint: zod.coerce.bigint,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fuma",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"description": "My fullstack material build with sveltekit, daisyui, zod and more",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Jonas Voisard",
|
|
@@ -52,9 +52,9 @@
|
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@sveltejs/adapter-auto": "^3.0.0",
|
|
55
|
-
"@sveltejs/kit": "^2.5.
|
|
56
|
-
"@sveltejs/package": "^2.
|
|
57
|
-
"@sveltejs/vite-plugin-svelte": "^3.
|
|
55
|
+
"@sveltejs/kit": "^2.5.7",
|
|
56
|
+
"@sveltejs/package": "^2.3.1",
|
|
57
|
+
"@sveltejs/vite-plugin-svelte": "^3.1.0",
|
|
58
58
|
"@tailwindcss/typography": "^0.5.13",
|
|
59
59
|
"@types/debounce": "^1.2.4",
|
|
60
60
|
"@types/eslint": "^8.56.0",
|
|
@@ -73,12 +73,12 @@
|
|
|
73
73
|
"prettier-plugin-tailwindcss": "^0.5.9",
|
|
74
74
|
"prisma": "^5.13.0",
|
|
75
75
|
"publint": "^0.1.9",
|
|
76
|
-
"svelte": "^4.2.
|
|
76
|
+
"svelte": "^4.2.15",
|
|
77
77
|
"svelte-check": "^3.6.0",
|
|
78
78
|
"tailwindcss": "^3.3.6",
|
|
79
79
|
"tslib": "^2.4.1",
|
|
80
80
|
"typescript": "^5.0.0",
|
|
81
|
-
"vite": "^5.2.
|
|
81
|
+
"vite": "^5.2.11",
|
|
82
82
|
"vitest": "^1.2.0"
|
|
83
83
|
},
|
|
84
84
|
"dependencies": {
|