@webamoki/web-svelte 0.5.27 → 0.5.29
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/components/form/FieldWrapper.svelte +6 -1
- package/dist/components/form/fields/SelectField.svelte +1 -1
- package/dist/components/ui/choice/WeekdayChoice.svelte +2 -1
- package/dist/components/ui/choice/WeekdayChoice.svelte.d.ts +1 -1
- package/dist/components/ui/choice/WeekdayChoiceMulti.svelte +2 -1
- package/dist/components/ui/choice/WeekdayChoiceMulti.svelte.d.ts +1 -1
- package/dist/shadcn/components/ui/input/input.svelte +4 -6
- package/dist/shadcn/components/ui/select/select-trigger.svelte +1 -1
- package/dist/utils/form/handler.d.ts +29 -0
- package/dist/utils/form/handler.js +34 -0
- package/dist/utils/{form.d.ts → form/index.d.ts} +1 -0
- package/dist/utils/{form.js → form/index.js} +2 -1
- package/dist/utils/types/arktype.d.ts +1 -0
- package/dist/utils/types/arktype.js +9 -0
- package/package.json +4 -3
- package/dist/utils/index.d.ts +0 -6
- package/dist/utils/index.js +0 -6
|
@@ -42,7 +42,12 @@
|
|
|
42
42
|
{#if label || description}
|
|
43
43
|
<div>
|
|
44
44
|
{#if label}
|
|
45
|
-
<Label class="text-sm font-medium">
|
|
45
|
+
<Label class="text-sm font-medium">
|
|
46
|
+
{label}
|
|
47
|
+
{#if props['aria-required'] === 'true'}
|
|
48
|
+
<span class="text-red-500">*</span>
|
|
49
|
+
{/if}
|
|
50
|
+
</Label>
|
|
46
51
|
{/if}
|
|
47
52
|
{#if description}
|
|
48
53
|
<Description class="text-sm font-medium">{description}</Description>
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
<FieldWrapper {...fieldProps}>
|
|
64
64
|
{#snippet formElem(props)}
|
|
65
65
|
<Select type="single" {...props} bind:value={getKeyFromValue, setValueFromKey}>
|
|
66
|
-
<SelectTrigger class={cn('w-
|
|
66
|
+
<SelectTrigger class={cn('w-full cursor-pointer truncate', className)}>
|
|
67
67
|
<span class="block truncate">
|
|
68
68
|
{value ? getLabel(valueToItem.get(value)!) : placeholder}
|
|
69
69
|
</span>
|
|
@@ -12,10 +12,11 @@
|
|
|
12
12
|
</script>
|
|
13
13
|
|
|
14
14
|
<script lang="ts">
|
|
15
|
-
import { Days, formatDayLetter, formatDayShort
|
|
15
|
+
import { Days, formatDayLetter, formatDayShort } from '../../../utils/datetime/index.js';
|
|
16
16
|
import { identity } from 'ramda';
|
|
17
17
|
|
|
18
18
|
import Choice from './Choice.svelte';
|
|
19
|
+
import type { Day } from '../../../utils/types/arktype.js';
|
|
19
20
|
|
|
20
21
|
let { value = $bindable(undefined), ...props }: WeekdayChoiceProps = $props();
|
|
21
22
|
|
|
@@ -8,7 +8,7 @@ export interface WeekdayChoiceProps {
|
|
|
8
8
|
readonly?: boolean | null;
|
|
9
9
|
class?: string;
|
|
10
10
|
}
|
|
11
|
-
import {
|
|
11
|
+
import type { Day } from '../../../utils/types/arktype.js';
|
|
12
12
|
declare const WeekdayChoice: import("svelte").Component<WeekdayChoiceProps, {}, "value">;
|
|
13
13
|
type WeekdayChoice = ReturnType<typeof WeekdayChoice>;
|
|
14
14
|
export default WeekdayChoice;
|
|
@@ -15,8 +15,9 @@
|
|
|
15
15
|
</script>
|
|
16
16
|
|
|
17
17
|
<script lang="ts">
|
|
18
|
-
import { Days, formatDayLetter, formatDayShort, type Day } from '../../../utils/index.js';
|
|
19
18
|
import ChoiceMulti from './ChoiceMulti.svelte';
|
|
19
|
+
import { Days, formatDayLetter, formatDayShort } from '../../../utils/datetime/index.js';
|
|
20
|
+
import type { Day } from '../../../utils/types/arktype.js';
|
|
20
21
|
|
|
21
22
|
let { value = $bindable([]), ...props }: WeekdayChoiceMultiProps = $props();
|
|
22
23
|
|
|
@@ -9,7 +9,7 @@ export interface WeekdayChoiceMultiProps {
|
|
|
9
9
|
readonly?: boolean | null;
|
|
10
10
|
class?: string;
|
|
11
11
|
}
|
|
12
|
-
import {
|
|
12
|
+
import type { Day } from '../../../utils/types/arktype.js';
|
|
13
13
|
declare const WeekdayChoiceMulti: import("svelte").Component<WeekdayChoiceMultiProps, {}, "value">;
|
|
14
14
|
type WeekdayChoiceMulti = ReturnType<typeof WeekdayChoiceMulti>;
|
|
15
15
|
export default WeekdayChoiceMulti;
|
|
@@ -23,9 +23,8 @@
|
|
|
23
23
|
bind:this={ref}
|
|
24
24
|
data-slot="input"
|
|
25
25
|
class={cn(
|
|
26
|
-
'
|
|
27
|
-
'
|
|
28
|
-
'aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40',
|
|
26
|
+
'w-full rounded-lg border border-gray-300 px-4 py-3 transition-all outline-none focus:border-transparent focus:ring-2 focus:ring-primary disabled:cursor-not-allowed disabled:opacity-50',
|
|
27
|
+
'aria-invalid:border-red-500',
|
|
29
28
|
className
|
|
30
29
|
)}
|
|
31
30
|
type="file"
|
|
@@ -38,9 +37,8 @@
|
|
|
38
37
|
bind:this={ref}
|
|
39
38
|
data-slot="input"
|
|
40
39
|
class={cn(
|
|
41
|
-
'
|
|
42
|
-
'
|
|
43
|
-
'aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40',
|
|
40
|
+
'w-full rounded-lg border border-gray-300 px-4 py-3 transition-all outline-none focus:border-transparent focus:ring-2 focus:ring-primary disabled:cursor-not-allowed disabled:opacity-50',
|
|
41
|
+
'aria-invalid:border-red-500',
|
|
44
42
|
className
|
|
45
43
|
)}
|
|
46
44
|
{type}
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
data-slot="select-trigger"
|
|
20
20
|
data-size={size}
|
|
21
21
|
class={cn(
|
|
22
|
-
"flex w-
|
|
22
|
+
"flex w-full items-center justify-between gap-2 rounded-lg border border-gray-300 px-4 py-3 transition-all outline-none select-none focus:border-transparent focus:ring-2 focus:ring-primary disabled:opacity-50 aria-invalid:border-red-500 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
23
23
|
className
|
|
24
24
|
)}
|
|
25
25
|
{...restProps}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type SuperValidated } from 'sveltekit-superforms';
|
|
2
|
+
/**
|
|
3
|
+
* automatically handle database errors from catch.
|
|
4
|
+
* used in form/action handling in page.server.ts
|
|
5
|
+
*/
|
|
6
|
+
export declare function handleDbErrorForm<T extends Record<string, unknown>>(form: SuperValidated<T>, message: string, err: unknown): import("@sveltejs/kit").ActionFailure<{
|
|
7
|
+
form: SuperValidated<T>;
|
|
8
|
+
}>;
|
|
9
|
+
/**
|
|
10
|
+
* check if an error returned by a try catch is a duplicate value error in postgre
|
|
11
|
+
*/
|
|
12
|
+
export declare function isDuplicateDbError(err: unknown): boolean;
|
|
13
|
+
export declare function successMessage<T extends Record<string, unknown>>(form: SuperValidated<T>): {
|
|
14
|
+
form: SuperValidated<T, any, T>;
|
|
15
|
+
} | import("@sveltejs/kit").ActionFailure<{
|
|
16
|
+
form: SuperValidated<T, any, T>;
|
|
17
|
+
}>;
|
|
18
|
+
export declare function errorMessage<T extends Record<string, unknown>>(form: SuperValidated<T>, options?: {
|
|
19
|
+
showToast?: boolean;
|
|
20
|
+
text?: string;
|
|
21
|
+
data?: unknown;
|
|
22
|
+
}): {
|
|
23
|
+
form: SuperValidated<T, any, T>;
|
|
24
|
+
} | import("@sveltejs/kit").ActionFailure<{
|
|
25
|
+
form: SuperValidated<T, any, T>;
|
|
26
|
+
}>;
|
|
27
|
+
export declare function failFormValidation<T extends Record<string, unknown>>(form: SuperValidated<T>): import("@sveltejs/kit").ActionFailure<{
|
|
28
|
+
form: SuperValidated<T>;
|
|
29
|
+
}>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { DatabaseError } from 'pg';
|
|
2
|
+
import { fail, message as superFormMessage } from 'sveltekit-superforms';
|
|
3
|
+
/**
|
|
4
|
+
* automatically handle database errors from catch.
|
|
5
|
+
* used in form/action handling in page.server.ts
|
|
6
|
+
*/
|
|
7
|
+
export function handleDbErrorForm(form, message, err) {
|
|
8
|
+
if (err instanceof DatabaseError) {
|
|
9
|
+
console.error(`Database Error ${message}:`, err);
|
|
10
|
+
return fail(500, { form });
|
|
11
|
+
}
|
|
12
|
+
console.error(`Unexpected Error ${message}:`, err);
|
|
13
|
+
return fail(500, { form });
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* check if an error returned by a try catch is a duplicate value error in postgre
|
|
17
|
+
*/
|
|
18
|
+
export function isDuplicateDbError(err) {
|
|
19
|
+
return err instanceof DatabaseError && err.code === '23505';
|
|
20
|
+
}
|
|
21
|
+
export function successMessage(form) {
|
|
22
|
+
return superFormMessage(form, { success: true, showToast: true, text: 'Success' });
|
|
23
|
+
}
|
|
24
|
+
export function errorMessage(form, options) {
|
|
25
|
+
return superFormMessage(form, {
|
|
26
|
+
success: false,
|
|
27
|
+
showToast: options?.showToast ?? false,
|
|
28
|
+
text: options?.text,
|
|
29
|
+
data: options?.data
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
export function failFormValidation(form) {
|
|
33
|
+
return fail(400, { form });
|
|
34
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export * from './handler.js';
|
|
1
2
|
import { type } from 'arktype';
|
|
2
3
|
import { type SuperValidated } from 'sveltekit-superforms';
|
|
3
4
|
export declare function prepareForm<S extends type.Any<Record<string, unknown>>>(validated: SuperValidated<S['infer']> | S['infer'], schema: S, options?: Partial<{
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
export * from './handler.js';
|
|
2
2
|
import { type } from 'arktype';
|
|
3
3
|
import { toast } from 'svelte-sonner';
|
|
4
4
|
import { defaults, superForm, superValidate } from 'sveltekit-superforms';
|
|
5
5
|
import { arktype, arktypeClient } from 'sveltekit-superforms/adapters';
|
|
6
|
+
import { dateTransport } from '../datetime/index.js';
|
|
6
7
|
export function prepareForm(validated, schema, options) {
|
|
7
8
|
const form = superForm(validated, {
|
|
8
9
|
validators: arktypeClient(schema),
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Type } from 'arktype';
|
|
2
2
|
import { Days } from '../datetime/index.js';
|
|
3
3
|
import { Time as timeImport, CalendarDate as calendarImport } from '@internationalized/date';
|
|
4
|
+
export declare const Phone: import("arktype/internal/variants/string.ts").StringType<string, {}>;
|
|
4
5
|
/** Type string which is trimmed before narrowing the type checking */
|
|
5
6
|
export declare function trimTo(typeTo: Type<string>): import("arktype/internal/variants/object.ts").ObjectType<(In: string) => import("arktype/internal/attributes.ts").To<string>, {}>;
|
|
6
7
|
export declare const Day: import("arktype/internal/variants/string.ts").StringType<"Monday" | "Tuesday" | "Wednesday" | "Thursday" | "Friday" | "Saturday" | "Sunday", {}>;
|
|
@@ -3,6 +3,15 @@ import { Days } from '../datetime/index.js';
|
|
|
3
3
|
import { Time as timeImport, CalendarDate as calendarImport } from '@internationalized/date';
|
|
4
4
|
import { EMAIL_MAX, FIRST_NAME_MAX, LAST_NAME_MAX, NAME_MAX } from './consts.js';
|
|
5
5
|
import { toTitleCase } from '../string.js';
|
|
6
|
+
// Phone arktype: allows "+", digits, and spaces only
|
|
7
|
+
export const Phone = type('string').narrow((value, ctx) => {
|
|
8
|
+
if (!/^[+0-9 ]+$/.test(value)) {
|
|
9
|
+
return ctx.reject({
|
|
10
|
+
problem: 'invalid phone number. Only +, digits, and spaces are allowed.'
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
return true;
|
|
14
|
+
});
|
|
6
15
|
/** Type string which is trimmed before narrowing the type checking */
|
|
7
16
|
export function trimTo(typeTo) {
|
|
8
17
|
return type('string.trim').to(typeTo);
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.5.
|
|
6
|
+
"version": "0.5.29",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"files": [
|
|
9
9
|
"dist",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"import": "./dist/utils/types/db.js"
|
|
41
41
|
},
|
|
42
42
|
"./utils/form": {
|
|
43
|
-
"types": "./dist/utils/form.d.ts",
|
|
44
|
-
"import": "./dist/utils/form.js"
|
|
43
|
+
"types": "./dist/utils/form/index.d.ts",
|
|
44
|
+
"import": "./dist/utils/form/index.js"
|
|
45
45
|
},
|
|
46
46
|
"./utils/search": {
|
|
47
47
|
"types": "./dist/utils/search.d.ts",
|
|
@@ -72,6 +72,7 @@
|
|
|
72
72
|
"@tailwindcss/typography": "^0.5.19",
|
|
73
73
|
"@tailwindcss/vite": "^4.1.17",
|
|
74
74
|
"@types/node": "^22.19.0",
|
|
75
|
+
"@types/pg": "^8.15.6",
|
|
75
76
|
"@types/ramda": "^0.31.1",
|
|
76
77
|
"@types/sorted-array-functions": "^1.3.3",
|
|
77
78
|
"arktype": "^2.1.25",
|
package/dist/utils/index.d.ts
DELETED