@profidev/pleiades 1.9.0 → 1.9.1

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,5 +1,5 @@
1
1
  <script lang="ts" generics="V extends ZodValidationSchema">
2
- import type { Snippet } from 'svelte';
2
+ import type { Component, Snippet } from 'svelte';
3
3
  import { get } from 'svelte/store';
4
4
  import {
5
5
  defaults,
@@ -14,16 +14,18 @@
14
14
  } from 'sveltekit-superforms/adapters';
15
15
  import { FormButton } from '../ui/form/index.js';
16
16
  import LoaderCircle from '@lucide/svelte/icons/loader-circle';
17
+ import RotateCCW from '@lucide/svelte/icons/rotate-ccw';
17
18
  import type { ButtonVariant } from '../ui/button/index.js';
18
19
  import { cn } from '../../utils.js';
19
20
  import type { Error, FormEnctype, FormValue } from './types.js';
21
+ import { toast } from 'svelte-sonner';
20
22
 
21
23
  interface Props {
22
24
  schema: V;
23
25
  initialValue?: Partial<FormValue<V>>;
24
26
  onsubmit: (
25
27
  form: FormValue<V>
26
- ) => Error | undefined | void | Promise<Error | undefined | void>;
28
+ ) => Error<V> | undefined | void | Promise<Error<V> | undefined | void>;
27
29
  children?: Snippet<
28
30
  [{ props: { formData: SuperForm<FormValue<V>>; disabled: boolean } }]
29
31
  >;
@@ -31,16 +33,27 @@
31
33
  [
32
34
  {
33
35
  defaultBtn: Snippet<
34
- [{ className?: string; variant?: ButtonVariant; content: string }?]
36
+ [
37
+ {
38
+ className?: string;
39
+ variant?: ButtonVariant;
40
+ content: string;
41
+ icon?: Component;
42
+ }
43
+ ]
35
44
  >;
36
45
  isLoading: boolean;
46
+ isError: boolean;
37
47
  }
38
48
  ]
39
49
  >;
40
50
  isLoading?: boolean;
41
- error?: string;
42
51
  class?: string;
43
52
  enctype?: FormEnctype;
53
+ noErrorToast?: boolean;
54
+ submitText?: string;
55
+ retryText?: string;
56
+ submitIcon?: Component;
44
57
  }
45
58
 
46
59
  let {
@@ -50,11 +63,16 @@
50
63
  children,
51
64
  footer = defaultFooter,
52
65
  isLoading = $bindable(false),
53
- error = $bindable(''),
54
66
  class: className,
55
- enctype
67
+ enctype,
68
+ noErrorToast,
69
+ submitText = 'Submit',
70
+ retryText = 'Retry',
71
+ submitIcon
56
72
  }: Props = $props();
57
73
 
74
+ let isError = $state(false);
75
+
58
76
  let form = superForm(
59
77
  defaults(
60
78
  initialValue,
@@ -66,7 +84,7 @@
66
84
  onUpdate: async ({ form, cancel }) => {
67
85
  if (!form.valid) return;
68
86
 
69
- error = '';
87
+ isError = false;
70
88
  isLoading = true;
71
89
 
72
90
  let ret = await onsubmit(form.data);
@@ -76,7 +94,12 @@
76
94
  if (ret.field) {
77
95
  setError(form, ret.field as '', ret.error, undefined);
78
96
  } else {
79
- if (ret.error !== '') error = ret.error;
97
+ if (ret.error !== '') {
98
+ isError = true;
99
+ if (!noErrorToast) {
100
+ toast.error(ret.error);
101
+ }
102
+ }
80
103
  cancel();
81
104
  }
82
105
  }
@@ -105,21 +128,36 @@
105
128
 
106
129
  <form method="POST" class={cn('grid gap-3', className)} use:enhance {enctype}>
107
130
  {@render children?.({ props: { formData: form, disabled: isLoading } })}
108
- {#if error}
109
- <span class="text-destructive truncate text-sm">{error}</span>
110
- {/if}
111
- {@render footer({ defaultBtn: formButton, isLoading })}
131
+ {@render footer({ defaultBtn: formButton, isLoading, isError })}
112
132
  </form>
113
133
 
114
- {#snippet defaultFooter({ defaultBtn }: { defaultBtn: Snippet })}
115
- {@render defaultBtn()}
134
+ {#snippet defaultFooter({
135
+ defaultBtn
136
+ }: {
137
+ defaultBtn: Snippet<
138
+ [
139
+ {
140
+ className?: string;
141
+ variant?: ButtonVariant;
142
+ content: string;
143
+ icon?: Component;
144
+ }
145
+ ]
146
+ >;
147
+ })}
148
+ {@render defaultBtn({
149
+ variant: isError ? 'destructive' : undefined,
150
+ content: isError ? retryText : submitText,
151
+ icon: submitIcon
152
+ })}
116
153
  {/snippet}
117
154
 
118
- {#snippet formButton(
119
- props:
120
- | { className?: string; variant?: ButtonVariant; content: string }
121
- | undefined
122
- )}
155
+ {#snippet formButton(props: {
156
+ className?: string;
157
+ variant?: ButtonVariant;
158
+ content: string;
159
+ icon?: Component;
160
+ })}
123
161
  {@const prop = { ...props }}
124
162
  <FormButton
125
163
  class={cn('cursor-pointer', prop.className)}
@@ -129,6 +167,10 @@
129
167
  >
130
168
  {#if isLoading}
131
169
  <LoaderCircle class="mr-2 h-4 w-4 animate-spin" />
170
+ {:else if isError}
171
+ <RotateCCW class="mr-2 h-4 w-4" />
172
+ {:else if prop.icon}
173
+ <prop.icon class="mr-2 h-4 w-4" />
132
174
  {/if}
133
175
  {prop.content}
134
176
  </FormButton>
@@ -1,4 +1,4 @@
1
- import type { Snippet } from 'svelte';
1
+ import type { Component, Snippet } from 'svelte';
2
2
  import { type SuperForm } from 'sveltekit-superforms';
3
3
  import { type ZodValidationSchema } from 'sveltekit-superforms/adapters';
4
4
  import type { ButtonVariant } from '../ui/button/index.js';
@@ -7,7 +7,7 @@ declare function $$render<V extends ZodValidationSchema>(): {
7
7
  props: {
8
8
  schema: V;
9
9
  initialValue?: Partial<FormValue<V>>;
10
- onsubmit: (form: FormValue<V>) => Error | undefined | void | Promise<Error | undefined | void>;
10
+ onsubmit: (form: FormValue<V>) => Error<V> | undefined | void | Promise<Error<V> | undefined | void>;
11
11
  children?: Snippet<[{
12
12
  props: {
13
13
  formData: SuperForm<FormValue<V>>;
@@ -19,19 +19,24 @@ declare function $$render<V extends ZodValidationSchema>(): {
19
19
  className?: string;
20
20
  variant?: ButtonVariant;
21
21
  content: string;
22
- }?]>;
22
+ icon?: Component;
23
+ }]>;
23
24
  isLoading: boolean;
25
+ isError: boolean;
24
26
  }]>;
25
27
  isLoading?: boolean;
26
- error?: string;
27
28
  class?: string;
28
29
  enctype?: FormEnctype;
30
+ noErrorToast?: boolean;
31
+ submitText?: string;
32
+ retryText?: string;
33
+ submitIcon?: Component;
29
34
  };
30
35
  exports: {
31
36
  setValue: (value: FormValue<V>) => void;
32
37
  getValue: () => FormValue<V>;
33
38
  };
34
- bindings: "error" | "isLoading";
39
+ bindings: "isLoading";
35
40
  slots: {};
36
41
  events: {};
37
42
  };
@@ -39,7 +44,7 @@ declare class __sveltets_Render<V extends ZodValidationSchema> {
39
44
  props(): ReturnType<typeof $$render<V>>['props'];
40
45
  events(): ReturnType<typeof $$render<V>>['events'];
41
46
  slots(): ReturnType<typeof $$render<V>>['slots'];
42
- bindings(): "error" | "isLoading";
47
+ bindings(): "isLoading";
43
48
  exports(): {
44
49
  setValue: (value: import("zod/v4").infer<V>) => void;
45
50
  getValue: () => import("zod/v4").infer<V>;
@@ -1,6 +1,6 @@
1
1
  <script lang="ts" generics="V extends ZodValidationSchema">
2
2
  import * as Dialog from '../ui/dialog/index.js';
3
- import type { Snippet } from 'svelte';
3
+ import type { Component, Snippet } from 'svelte';
4
4
  import {
5
5
  Button,
6
6
  type ButtonSize,
@@ -18,7 +18,9 @@
18
18
  title: string;
19
19
  description?: string;
20
20
  confirm: string;
21
+ retryText?: string;
21
22
  confirmVariant?: ButtonVariant;
23
+ confirmIcon?: Component;
22
24
  open?: boolean;
23
25
  class?: string;
24
26
  isLoading?: boolean;
@@ -33,7 +35,7 @@
33
35
  onopen?: () => boolean | Promise<boolean>;
34
36
  onsubmit: (
35
37
  form: FormValue<V>
36
- ) => Error | undefined | void | Promise<Error | undefined | void>;
38
+ ) => Error<V> | undefined | void | Promise<Error<V> | undefined | void>;
37
39
  children?: Snippet<
38
40
  [{ props: { formData: SuperForm<FormValue<V>>; disabled: boolean } }]
39
41
  >;
@@ -41,6 +43,7 @@
41
43
  schema: V;
42
44
  initialValue?: FormValue<V>;
43
45
  enctype?: FormEnctype;
46
+ noErrorToast?: boolean;
44
47
  }
45
48
 
46
49
  let {
@@ -58,11 +61,13 @@
58
61
  triggerInner,
59
62
  schema,
60
63
  initialValue,
61
- enctype
64
+ enctype,
65
+ retryText = 'Retry',
66
+ confirmIcon,
67
+ noErrorToast
62
68
  }: Props = $props();
63
69
 
64
70
  let formComp: BaseForm<V> | undefined = $state();
65
- let error = $state('');
66
71
  let formSetValue = $derived(formComp?.setValue);
67
72
  let formGetValue = $derived(formComp?.getValue);
68
73
 
@@ -78,7 +83,6 @@
78
83
  isLoading = true;
79
84
  if (await onopen()) {
80
85
  open = true;
81
- error = '';
82
86
  }
83
87
  isLoading = false;
84
88
  };
@@ -120,16 +124,20 @@
120
124
  <Form
121
125
  bind:this={formComp}
122
126
  bind:isLoading
123
- bind:error
124
127
  {schema}
125
128
  {initialValue}
126
129
  {enctype}
127
130
  onsubmit={submit}
128
131
  {children}
132
+ {noErrorToast}
129
133
  >
130
- {#snippet footer({ defaultBtn })}
134
+ {#snippet footer({ defaultBtn, isError })}
131
135
  <Dialog.Footer>
132
- {@render defaultBtn({ variant: confirmVariant, content: confirm })}
136
+ {@render defaultBtn({
137
+ variant: isError ? 'destructive' : confirmVariant,
138
+ content: isError ? retryText : confirm,
139
+ icon: confirmIcon
140
+ })}
133
141
  </Dialog.Footer>
134
142
  {/snippet}
135
143
  </Form>
@@ -1,4 +1,4 @@
1
- import type { Snippet } from 'svelte';
1
+ import type { Component, Snippet } from 'svelte';
2
2
  import { type ButtonSize, type ButtonVariant } from '../ui/button/index.js';
3
3
  import { type SuperForm } from 'sveltekit-superforms';
4
4
  import type { Error, FormEnctype, FormValue } from './types.js';
@@ -8,7 +8,9 @@ declare function $$render<V extends ZodValidationSchema>(): {
8
8
  title: string;
9
9
  description?: string;
10
10
  confirm: string;
11
+ retryText?: string;
11
12
  confirmVariant?: ButtonVariant;
13
+ confirmIcon?: Component;
12
14
  open?: boolean;
13
15
  class?: string;
14
16
  isLoading?: boolean;
@@ -21,7 +23,7 @@ declare function $$render<V extends ZodValidationSchema>(): {
21
23
  disabled?: boolean;
22
24
  };
23
25
  onopen?: () => boolean | Promise<boolean>;
24
- onsubmit: (form: FormValue<V>) => Error | undefined | void | Promise<Error | undefined | void>;
26
+ onsubmit: (form: FormValue<V>) => Error<V> | undefined | void | Promise<Error<V> | undefined | void>;
25
27
  children?: Snippet<[{
26
28
  props: {
27
29
  formData: SuperForm<FormValue<V>>;
@@ -32,6 +34,7 @@ declare function $$render<V extends ZodValidationSchema>(): {
32
34
  schema: V;
33
35
  initialValue?: FormValue<V>;
34
36
  enctype?: FormEnctype;
37
+ noErrorToast?: boolean;
35
38
  };
36
39
  exports: {
37
40
  openFn: () => Promise<void>;
@@ -17,9 +17,7 @@
17
17
  <span class="w-full border-t"></span>
18
18
  </div>
19
19
  <div class="relative flex justify-center text-xs uppercase">
20
- <span class="bg-background text-muted-foreground px-2"
21
- >Or continue with
22
- </span>
20
+ <span class="text-muted-foreground px-2">Or continue with </span>
23
21
  </div>
24
22
  </div>
25
23
  {#if passkeyError !== ''}
@@ -19,7 +19,7 @@
19
19
  stages: Stage<T>[];
20
20
  onsubmit: (
21
21
  data: object
22
- ) => Error | undefined | void | Promise<Error | undefined | void>;
22
+ ) => Error<any> | undefined | void | Promise<Error<any> | undefined | void>;
23
23
  data?: T;
24
24
  submitLabel?: string;
25
25
  submitIcon?: Component;
@@ -2,7 +2,7 @@ import { type Error, type Stage } from './types';
2
2
  import type { Component } from 'svelte';
3
3
  interface Props<T> {
4
4
  stages: Stage<T>[];
5
- onsubmit: (data: object) => Error | undefined | void | Promise<Error | undefined | void>;
5
+ onsubmit: (data: object) => Error<any> | undefined | void | Promise<Error<any> | undefined | void>;
6
6
  data?: T;
7
7
  submitLabel?: string;
8
8
  submitIcon?: Component;
@@ -6,8 +6,8 @@ export type { SuperForm, FormPath, FormPathLeaves } from 'sveltekit-superforms';
6
6
  export type { ZodValidationSchema };
7
7
  export type FormRecord = Record<string, unknown>;
8
8
  export type FormValue<V extends ZodValidationSchema> = z.infer<V>;
9
- export interface Error {
10
- field?: string;
9
+ export interface Error<V extends ZodValidationSchema> {
10
+ field?: keyof FormValue<V>;
11
11
  error: string;
12
12
  }
13
13
  export type FormEnctype = 'application/x-www-form-urlencoded' | 'multipart/form-data' | 'text/plain' | undefined | null;
@@ -8,10 +8,10 @@
8
8
 
9
9
  interface Props {
10
10
  items: NavGroup[];
11
- user: SidebarUserInfo | Promise<SidebarUserInfo>;
11
+ user?: SidebarUserInfo;
12
12
  }
13
13
 
14
- const { items, user: userPromise }: Props = $props();
14
+ const { items, user }: Props = $props();
15
15
 
16
16
  const filteredItems = (items: NavGroup[], user: SidebarUserInfo) =>
17
17
  items
@@ -33,7 +33,7 @@
33
33
  .sort((a, b) => b.href.length - a.href.length)[0] ?? undefined;
34
34
  </script>
35
35
 
36
- {#await userPromise}
36
+ {#if !user}
37
37
  <Sidebar.Group>
38
38
  <Sidebar.GroupLabel>Loading...</Sidebar.GroupLabel>
39
39
  <Sidebar.Menu>
@@ -44,7 +44,7 @@
44
44
  {/each}
45
45
  </Sidebar.Menu>
46
46
  </Sidebar.Group>
47
- {:then user}
47
+ {:else}
48
48
  {@const filtered = filteredItems(items, user)}
49
49
  {#each filtered as group}
50
50
  <Sidebar.Group>
@@ -70,4 +70,4 @@
70
70
  </Sidebar.Menu>
71
71
  </Sidebar.Group>
72
72
  {/each}
73
- {/await}
73
+ {/if}
@@ -1,7 +1,7 @@
1
1
  import type { NavGroup, SidebarUserInfo } from './types';
2
2
  interface Props {
3
3
  items: NavGroup[];
4
- user: SidebarUserInfo | Promise<SidebarUserInfo>;
4
+ user?: SidebarUserInfo;
5
5
  }
6
6
  declare const SidebarContent: import("svelte").Component<Props, {}, "">;
7
7
  type SidebarContent = ReturnType<typeof SidebarContent>;
@@ -11,12 +11,12 @@
11
11
  import { Skeleton } from '../../ui/skeleton';
12
12
 
13
13
  interface Props {
14
- user: SidebarUserInfo | Promise<SidebarUserInfo>;
14
+ user?: SidebarUserInfo;
15
15
  avatar?: string;
16
16
  logout: () => Promise<{ error?: any }>;
17
17
  }
18
18
 
19
- let { logout, user: userPromise, avatar }: Props = $props();
19
+ let { logout, user, avatar }: Props = $props();
20
20
 
21
21
  const sidebar = Sidebar.useSidebar();
22
22
  </script>
@@ -32,19 +32,17 @@
32
32
  {...props}
33
33
  >
34
34
  <Avatar.Root class="size-8 rounded-lg">
35
- {#await userPromise then user}
36
- <Avatar.Image src={avatar} alt={user.name} />
37
- {/await}
35
+ <Avatar.Image src={avatar} alt={user?.name} />
38
36
  <Avatar.Fallback class="rounded-full">?</Avatar.Fallback>
39
37
  </Avatar.Root>
40
38
  <div class="grid flex-1 text-start text-sm leading-tight">
41
- {#await userPromise}
39
+ {#if !user}
42
40
  <Skeleton class="mb-1 h-4" />
43
41
  <Skeleton class="h-3" />
44
- {:then user}
42
+ {:else}
45
43
  <span class="truncate font-medium">{user.name}</span>
46
44
  <span class="truncate text-xs">{user.email}</span>
47
- {/await}
45
+ {/if}
48
46
  </div>
49
47
  <ChevronsUpDownIcon class="ms-auto size-4" />
50
48
  </Sidebar.MenuButton>
@@ -59,19 +57,17 @@
59
57
  <DropdownMenu.Label class="p-0 font-normal">
60
58
  <div class="flex items-center gap-2 px-1 py-1.5 text-start text-sm">
61
59
  <Avatar.Root class="size-8 rounded-lg">
62
- {#await userPromise then user}
63
- <Avatar.Image src={avatar} alt={user.name} />
64
- {/await}
60
+ <Avatar.Image src={avatar} alt={user?.name} />
65
61
  <Avatar.Fallback class="rounded-full">?</Avatar.Fallback>
66
62
  </Avatar.Root>
67
63
  <div class="grid flex-1 text-start text-sm leading-tight">
68
- {#await userPromise}
64
+ {#if !user}
69
65
  <Skeleton class="mb-1 h-4" />
70
66
  <Skeleton class="h-3" />
71
- {:then user}
67
+ {:else}
72
68
  <span class="truncate font-medium">{user.name}</span>
73
69
  <span class="truncate text-xs">{user.email}</span>
74
- {/await}
70
+ {/if}
75
71
  </div>
76
72
  </div>
77
73
  </DropdownMenu.Label>
@@ -1,6 +1,6 @@
1
1
  import type { SidebarUserInfo } from './types';
2
2
  interface Props {
3
- user: SidebarUserInfo | Promise<SidebarUserInfo>;
3
+ user?: SidebarUserInfo;
4
4
  avatar?: string;
5
5
  logout: () => Promise<{
6
6
  error?: any;
@@ -7,7 +7,7 @@
7
7
  import type { NavGroup, SidebarUserInfo } from './types';
8
8
 
9
9
  interface Props {
10
- user: SidebarUserInfo | Promise<SidebarUserInfo>;
10
+ user?: SidebarUserInfo;
11
11
  avatar?: string;
12
12
  children: Snippet;
13
13
  version: string;
@@ -2,7 +2,7 @@ import * as Sidebar from '../../ui/sidebar';
2
2
  import type { Component, Snippet } from 'svelte';
3
3
  import type { NavGroup, SidebarUserInfo } from './types';
4
4
  interface Props {
5
- user: SidebarUserInfo | Promise<SidebarUserInfo>;
5
+ user?: SidebarUserInfo;
6
6
  avatar?: string;
7
7
  children: Snippet;
8
8
  version: string;
@@ -59,7 +59,7 @@
59
59
  createClass?: string;
60
60
  editClass?: string;
61
61
  errorMappings?: {
62
- [key in RequestError]?: Error;
62
+ [key in RequestError]?: Error<any>;
63
63
  };
64
64
  columnData: CD;
65
65
  }
@@ -38,7 +38,7 @@ declare function $$render<CV extends ZodValidationSchema, EV extends ZodValidati
38
38
  startEdit?: (item: T) => void | Promise<void>;
39
39
  createClass?: string;
40
40
  editClass?: string;
41
- errorMappings?: { [key in RequestError]?: Error; };
41
+ errorMappings?: { [key in RequestError]?: Error<any>; };
42
42
  columnData: CD;
43
43
  };
44
44
  exports: {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@profidev/pleiades",
3
- "version": "1.9.0",
3
+ "version": "1.9.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/Profiidev/pleiades"