@webamoki/web-svelte 0.5.27 → 0.5.28

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.
@@ -42,7 +42,12 @@
42
42
  {#if label || description}
43
43
  <div>
44
44
  {#if label}
45
- <Label class="text-sm font-medium">{label}</Label>
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-[180px] cursor-pointer truncate', className)}>
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, type Day } from '../../../utils/index.js';
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 { type Day } from '../../../utils/index.js';
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 { type Day } from '../../../utils/index.js';
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
- 'flex h-9 w-full min-w-0 rounded-md border border-input bg-transparent px-3 pt-1.5 text-sm font-medium shadow-xs ring-offset-background transition-[color,box-shadow] outline-none selection:bg-primary selection:text-primary-foreground placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50 md:text-sm dark:bg-input/30',
27
- 'focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50',
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
- 'flex h-9 w-full min-w-0 rounded-md border border-input bg-background px-3 py-1 text-base shadow-xs ring-offset-background transition-[color,box-shadow] outline-none selection:bg-primary selection:text-primary-foreground placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50 md:text-sm dark:bg-input/30',
42
- 'focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50',
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-fit items-center justify-between gap-2 rounded-md border border-input bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none select-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[placeholder]:text-muted-foreground data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 dark:bg-input/30 dark:hover:bg-input/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground",
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
- import { dateTransport } from './index.js';
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),
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.5.27",
6
+ "version": "0.5.28",
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",
@@ -1,6 +0,0 @@
1
- export * from './datetime/index.js';
2
- export * from './types/arktype.js';
3
- export * from './types/db.js';
4
- export * from './types/consts.js';
5
- export * from './string.js';
6
- export * from './form.js';
@@ -1,6 +0,0 @@
1
- export * from './datetime/index.js';
2
- export * from './types/arktype.js';
3
- export * from './types/db.js';
4
- export * from './types/consts.js';
5
- export * from './string.js';
6
- export * from './form.js';