lutra 0.0.19 → 0.0.33

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.
Files changed (192) hide show
  1. package/dist/color.css +0 -0
  2. package/dist/display/Avatar.svelte +1 -1
  3. package/dist/display/Avatar.svelte.d.ts +18 -22
  4. package/dist/display/Badge.svelte +2 -4
  5. package/dist/display/Badge.svelte.d.ts +28 -32
  6. package/dist/display/Callout.svelte +8 -8
  7. package/dist/display/Callout.svelte.d.ts +27 -35
  8. package/dist/display/Close.svelte.d.ts +17 -20
  9. package/dist/display/Code.svelte +26 -31
  10. package/dist/display/Code.svelte.d.ts +31 -30
  11. package/dist/display/ContextTip.svelte +2 -5
  12. package/dist/display/ContextTip.svelte.d.ts +16 -20
  13. package/dist/display/DataList.svelte +16 -0
  14. package/dist/display/DataList.svelte.d.ts +21 -0
  15. package/dist/display/Details.svelte.d.ts +25 -30
  16. package/dist/display/Hero.svelte.d.ts +24 -28
  17. package/dist/display/Icon.svelte +3 -4
  18. package/dist/display/Icon.svelte.d.ts +18 -23
  19. package/dist/display/IconButton.svelte +12 -5
  20. package/dist/display/IconButton.svelte.d.ts +26 -29
  21. package/dist/display/Image.svelte.d.ts +25 -36
  22. package/dist/display/Indicator.svelte.d.ts +21 -22
  23. package/dist/display/Inset.svelte.d.ts +16 -20
  24. package/dist/display/LineChart.svelte +385 -0
  25. package/dist/display/LineChart.svelte.d.ts +24 -0
  26. package/dist/display/LoadingIndicator.svelte +33 -0
  27. package/dist/display/LoadingIndicator.svelte.d.ts +15 -0
  28. package/dist/display/Modal.svelte +116 -0
  29. package/dist/display/Modal.svelte.d.ts +27 -0
  30. package/dist/display/Notification.svelte.d.ts +22 -41
  31. package/dist/display/Panel.svelte +23 -0
  32. package/dist/display/Panel.svelte.d.ts +19 -0
  33. package/dist/display/Popup.svelte.d.ts +23 -28
  34. package/dist/{data → display}/Stat.svelte +9 -17
  35. package/dist/display/Stat.svelte.d.ts +30 -0
  36. package/dist/display/Table.svelte +14 -10
  37. package/dist/display/Table.svelte.d.ts +22 -32
  38. package/dist/display/TablePaginator.svelte +51 -0
  39. package/dist/display/TablePaginator.svelte.d.ts +21 -0
  40. package/dist/display/Tag.svelte.d.ts +29 -32
  41. package/dist/display/Tooltip.svelte +5 -4
  42. package/dist/display/Tooltip.svelte.d.ts +21 -26
  43. package/dist/display/chart.d.ts +78 -0
  44. package/dist/display/chart.js +212 -0
  45. package/dist/display/index.d.ts +11 -1
  46. package/dist/display/index.js +11 -1
  47. package/dist/display/notifications.svelte.d.ts +3 -3
  48. package/dist/display/notifications.svelte.js +2 -2
  49. package/dist/form/Button.svelte +7 -2
  50. package/dist/form/Button.svelte.d.ts +25 -35
  51. package/dist/form/FieldActions.svelte +25 -3
  52. package/dist/form/FieldActions.svelte.d.ts +18 -22
  53. package/dist/form/FieldContainer.svelte +1 -1
  54. package/dist/form/FieldContainer.svelte.d.ts +17 -22
  55. package/dist/form/FieldContent.svelte +52 -33
  56. package/dist/form/FieldContent.svelte.d.ts +28 -56
  57. package/dist/form/FieldError.svelte.d.ts +17 -20
  58. package/dist/form/FieldSection.svelte.d.ts +18 -32
  59. package/dist/form/Fieldset.svelte.d.ts +29 -40
  60. package/dist/form/Form.svelte +55 -16
  61. package/dist/form/Form.svelte.d.ts +36 -31
  62. package/dist/form/ImageUpload.svelte +259 -0
  63. package/dist/form/ImageUpload.svelte.d.ts +31 -0
  64. package/dist/form/Input.svelte +192 -153
  65. package/dist/form/Input.svelte.d.ts +115 -140
  66. package/dist/form/InputLength.svelte.d.ts +19 -20
  67. package/dist/form/Label.svelte +21 -4
  68. package/dist/form/Label.svelte.d.ts +24 -30
  69. package/dist/form/LogoUpload.svelte +100 -0
  70. package/dist/form/LogoUpload.svelte.d.ts +29 -0
  71. package/dist/form/Select.svelte +84 -36
  72. package/dist/form/Select.svelte.d.ts +69 -96
  73. package/dist/form/Textarea.svelte +163 -0
  74. package/dist/form/Textarea.svelte.d.ts +108 -0
  75. package/dist/form/Toggle.svelte +2 -0
  76. package/dist/form/Toggle.svelte.d.ts +15 -0
  77. package/dist/form/client.svelte.d.ts +8 -9
  78. package/dist/form/client.svelte.js +18 -10
  79. package/dist/form/form.d.ts +6 -4
  80. package/dist/form/form.js +23 -9
  81. package/dist/form/index.d.ts +6 -3
  82. package/dist/form/index.js +6 -3
  83. package/dist/form/types.d.ts +11 -1
  84. package/dist/icons/IconAlert.svelte.d.ts +23 -0
  85. package/dist/icons/{Copy.svelte → IconCopy.svelte} +1 -1
  86. package/dist/icons/IconCopy.svelte.d.ts +23 -0
  87. package/dist/icons/IconDone.svelte.d.ts +23 -0
  88. package/dist/icons/IconError.svelte.d.ts +23 -0
  89. package/dist/icons/IconHelp.svelte.d.ts +23 -0
  90. package/dist/icons/IconHide.svelte.d.ts +23 -0
  91. package/dist/icons/IconInfo.svelte.d.ts +23 -0
  92. package/dist/icons/IconLink.svelte.d.ts +23 -0
  93. package/dist/icons/IconMenuBurger.svelte.d.ts +23 -0
  94. package/dist/icons/IconMenuDots.svelte.d.ts +23 -0
  95. package/dist/icons/IconSearch.svelte +3 -0
  96. package/dist/icons/IconSearch.svelte.d.ts +23 -0
  97. package/dist/icons/IconShow.svelte.d.ts +23 -0
  98. package/dist/icons/IconSuccess.svelte.d.ts +23 -0
  99. package/dist/icons/IconWarning.svelte.d.ts +23 -0
  100. package/dist/icons/index.d.ts +14 -11
  101. package/dist/icons/index.js +14 -11
  102. package/dist/layout/Layout.svelte +7 -5
  103. package/dist/layout/Layout.svelte.d.ts +19 -22
  104. package/dist/layout/LayoutFooter.svelte.d.ts +17 -18
  105. package/dist/layout/LayoutGrid.svelte.d.ts +25 -36
  106. package/dist/layout/LayoutHeader.svelte +3 -0
  107. package/dist/layout/LayoutHeader.svelte.d.ts +33 -38
  108. package/dist/layout/LayoutSideMenu.svelte +18 -17
  109. package/dist/layout/LayoutSideMenu.svelte.d.ts +18 -22
  110. package/dist/layout/Overlay.svelte.d.ts +22 -32
  111. package/dist/layout/OverlayContainer.svelte.d.ts +14 -15
  112. package/dist/layout/OverlayLayer.svelte +6 -11
  113. package/dist/layout/OverlayLayer.svelte.d.ts +17 -20
  114. package/dist/layout/PageContent.svelte +9 -24
  115. package/dist/layout/PageContent.svelte.d.ts +23 -26
  116. package/dist/layout/Theme.svelte +19 -4
  117. package/dist/layout/Theme.svelte.d.ts +17 -22
  118. package/dist/layout/UIContent.svelte.d.ts +16 -20
  119. package/dist/layout/index.d.ts +5 -1
  120. package/dist/layout/index.js +5 -1
  121. package/dist/layout/overlays.svelte.d.ts +2 -2
  122. package/dist/nav/Breadcrumb.svelte +1 -1
  123. package/dist/nav/Breadcrumb.svelte.d.ts +26 -31
  124. package/dist/nav/Menu.svelte +6 -13
  125. package/dist/nav/Menu.svelte.d.ts +25 -31
  126. package/dist/nav/MenuItem.svelte +15 -8
  127. package/dist/nav/MenuItem.svelte.d.ts +20 -24
  128. package/dist/nav/MenuTypes.d.ts +7 -7
  129. package/dist/nav/NavMenu.svelte +7 -9
  130. package/dist/nav/NavMenu.svelte.d.ts +17 -18
  131. package/dist/nav/TabbedContent.svelte +1 -1
  132. package/dist/nav/TabbedContent.svelte.d.ts +21 -22
  133. package/dist/nav/Tabs.svelte +53 -13
  134. package/dist/nav/Tabs.svelte.d.ts +24 -25
  135. package/dist/nav/index.d.ts +2 -1
  136. package/dist/nav/index.js +2 -1
  137. package/dist/style.css +176 -79
  138. package/dist/typo/Clamp.svelte.d.ts +22 -26
  139. package/dist/typo/H.svelte.d.ts +26 -30
  140. package/dist/typo/H1.svelte.d.ts +24 -28
  141. package/dist/typo/H2.svelte.d.ts +24 -28
  142. package/dist/typo/H3.svelte.d.ts +24 -28
  143. package/dist/typo/H4.svelte.d.ts +24 -28
  144. package/dist/typo/H5.svelte.d.ts +24 -28
  145. package/dist/typo/H6.svelte.d.ts +24 -28
  146. package/dist/typo/P.svelte.d.ts +24 -28
  147. package/dist/utils/StringOrComponent.svelte +14 -0
  148. package/dist/utils/StringOrComponent.svelte.d.ts +19 -0
  149. package/dist/utils/StringOrSnippet.svelte +11 -0
  150. package/dist/utils/StringOrSnippet.svelte.d.ts +19 -0
  151. package/dist/utils/color.d.ts +1 -1
  152. package/dist/utils/index.d.ts +2 -1
  153. package/dist/utils/index.js +2 -1
  154. package/dist/utils/isSnippet.d.ts +3 -5
  155. package/dist/utils/isSnippet.js +9 -4
  156. package/package.json +32 -25
  157. package/dist/data/Stat.svelte.d.ts +0 -39
  158. package/dist/data/index.d.ts +0 -1
  159. package/dist/data/index.js +0 -1
  160. package/dist/grid/Column.svelte +0 -11
  161. package/dist/grid/Column.svelte.d.ts +0 -22
  162. package/dist/grid/Grid.svelte +0 -19
  163. package/dist/grid/Grid.svelte.d.ts +0 -24
  164. package/dist/grid/Row.svelte +0 -44
  165. package/dist/grid/Row.svelte.d.ts +0 -24
  166. package/dist/icons/Alert.svelte.d.ts +0 -23
  167. package/dist/icons/Copy.svelte.d.ts +0 -23
  168. package/dist/icons/Done.svelte.d.ts +0 -23
  169. package/dist/icons/Error.svelte.d.ts +0 -23
  170. package/dist/icons/Help.svelte.d.ts +0 -23
  171. package/dist/icons/Hide.svelte.d.ts +0 -23
  172. package/dist/icons/Info.svelte.d.ts +0 -23
  173. package/dist/icons/Link.svelte.d.ts +0 -23
  174. package/dist/icons/MenuBurger.svelte.d.ts +0 -23
  175. package/dist/icons/MenuDots.svelte.d.ts +0 -23
  176. package/dist/icons/Show.svelte.d.ts +0 -23
  177. package/dist/icons/Success.svelte.d.ts +0 -23
  178. package/dist/icons/Warning.svelte.d.ts +0 -23
  179. package/dist/utils/StringOrComponentOrSnippet.svelte +0 -14
  180. package/dist/utils/StringOrComponentOrSnippet.svelte.d.ts +0 -24
  181. /package/dist/icons/{Alert.svelte → IconAlert.svelte} +0 -0
  182. /package/dist/icons/{Done.svelte → IconDone.svelte} +0 -0
  183. /package/dist/icons/{Error.svelte → IconError.svelte} +0 -0
  184. /package/dist/icons/{Help.svelte → IconHelp.svelte} +0 -0
  185. /package/dist/icons/{Hide.svelte → IconHide.svelte} +0 -0
  186. /package/dist/icons/{Info.svelte → IconInfo.svelte} +0 -0
  187. /package/dist/icons/{Link.svelte → IconLink.svelte} +0 -0
  188. /package/dist/icons/{MenuBurger.svelte → IconMenuBurger.svelte} +0 -0
  189. /package/dist/icons/{MenuDots.svelte → IconMenuDots.svelte} +0 -0
  190. /package/dist/icons/{Show.svelte → IconShow.svelte} +0 -0
  191. /package/dist/icons/{Success.svelte → IconSuccess.svelte} +0 -0
  192. /package/dist/icons/{Warning.svelte → IconWarning.svelte} +0 -0
@@ -1,5 +1,6 @@
1
1
  <script lang="ts">import Label from "./Label.svelte";
2
2
  import FieldError from "./FieldError.svelte";
3
+ import StringOrSnippet from "../utils/StringOrSnippet.svelte";
3
4
  let {
4
5
  id,
5
6
  contained,
@@ -7,9 +8,11 @@ let {
7
8
  suffix,
8
9
  label,
9
10
  labelTip,
11
+ help,
10
12
  type = "text",
11
13
  direction = "column",
12
14
  // 'row' | 'column'
15
+ required,
13
16
  children,
14
17
  field,
15
18
  issue
@@ -18,61 +21,67 @@ let {
18
21
 
19
22
  {#snippet _prefix()}
20
23
  <div class="Fix Prefix">
21
- {#if typeof prefix === 'string'}
22
- {prefix}
23
- {:else}
24
- {@render prefix()}
25
- {/if}
24
+ <StringOrSnippet content={prefix} />
26
25
  </div>
27
26
  {/snippet}
28
27
 
29
28
  {#snippet _suffix()}
30
29
  <div class="Fix Suffix">
31
- {#if typeof suffix === 'string'}
32
- {suffix}
33
- {:else}
34
- {@render suffix()}
35
- {/if}
30
+ <StringOrSnippet content={suffix} />
36
31
  </div>
37
32
  {/snippet}
38
33
 
39
- <div class="FieldContent {type} {direction}" class:contained>
40
- <Label {label} tip={labelTip} {id} />
41
- {#if contained}
42
- <div
43
- class="Field"
44
- class:hasPrefix={prefix}
45
- class:hasSuffix={suffix}
46
- class:invalid={field?.tainted && issue?.code}
47
- >
34
+ <div class="FieldContentContainer">
35
+ <div class="FieldContent {type} {direction}" class:contained>
36
+ <Label {label} tip={labelTip} {id} {required} />
37
+ {#if contained}
38
+ <div
39
+ class="Field"
40
+ class:hasPrefix={prefix}
41
+ class:hasSuffix={suffix}
42
+ class:invalid={field?.tainted && issue?.code}
43
+ >
44
+ {#if prefix}
45
+ {@render _prefix()}
46
+ {/if}
47
+
48
+ {@render children()}
49
+
50
+ {#if suffix}
51
+ {@render _suffix()}
52
+ {/if}
53
+ </div>
54
+ {:else}
48
55
  {#if prefix}
49
56
  {@render _prefix()}
50
57
  {/if}
51
-
58
+
52
59
  {@render children()}
53
-
60
+
54
61
  {#if suffix}
55
62
  {@render _suffix()}
56
63
  {/if}
57
- </div>
58
- {:else}
59
- {#if prefix}
60
- {@render _prefix()}
61
- {/if}
62
-
63
- {@render children()}
64
-
65
- {#if suffix}
66
- {@render _suffix()}
67
64
  {/if}
65
+
66
+ </div>
67
+
68
+ {#if help}
69
+ <div class="Help">
70
+ <StringOrSnippet content={help} />
71
+ </div>
68
72
  {/if}
69
-
73
+
70
74
  {#if field?.tainted && issue?.code}
71
75
  <FieldError code={issue.code} message={issue.message} />
72
76
  {/if}
73
77
  </div>
74
78
 
75
79
  <style>
80
+ .FieldContentContainer {
81
+ display: flex;
82
+ flex-direction: column;
83
+ gap: 0.75em;
84
+ }
76
85
  .FieldContent {
77
86
  display: flex;
78
87
  gap: 0.75em;
@@ -113,10 +122,14 @@ let {
113
122
  .Prefix {
114
123
  padding-inline-end: 0;
115
124
  }
116
- .Field:has(input:focus-visible) {
125
+ .Field:has(input:focus-visible),
126
+ .Field:has(select:focus-visible),
127
+ .Field:has(textarea:focus-visible) {
117
128
  outline: var(--focus-outline);
118
129
  }
119
130
  .Field:has(input:focus-visible:user-invalid),
131
+ .Field:has(select:focus-visible:user-invalid),
132
+ .Field:has(textarea:focus-visible:user-invalid),
120
133
  .Field.invalid:has(input:focus-visible) {
121
134
  outline-color: var(--focus-color-error);
122
135
  }
@@ -131,4 +144,10 @@ let {
131
144
  outline-offset: 3px;
132
145
  border-radius: calc(var(--field-radius) - 2px);
133
146
  }
147
+ .Help {
148
+ font-size: 0.85em;
149
+ color: var(--text-subtle);
150
+ line-height: 1.4;
151
+ font-weight: 400;
152
+ }
134
153
  </style>
@@ -1,59 +1,31 @@
1
- import { SvelteComponent } from "svelte";
2
1
  import type { Snippet } from "svelte";
3
2
  import type { FormField, FormIssue } from "./types.js";
4
- declare const __propDef: {
5
- props: {
6
- id: string;
7
- contained?: boolean | undefined;
8
- prefix?: string | ((this: void) => typeof import("svelte").SnippetReturn & {
9
- _: "functions passed to {@render ...} tags must use the `Snippet` type imported from \"svelte\"";
10
- }) | undefined;
11
- suffix?: string | ((this: void) => typeof import("svelte").SnippetReturn & {
12
- _: "functions passed to {@render ...} tags must use the `Snippet` type imported from \"svelte\"";
13
- }) | undefined;
14
- type?: string | undefined;
15
- label?: string | ((this: void) => typeof import("svelte").SnippetReturn & {
16
- _: "functions passed to {@render ...} tags must use the `Snippet` type imported from \"svelte\"";
17
- }) | undefined;
18
- labelTip?: string | ((this: void) => typeof import("svelte").SnippetReturn & {
19
- _: "functions passed to {@render ...} tags must use the `Snippet` type imported from \"svelte\"";
20
- }) | undefined;
21
- direction?: "row" | "column" | undefined;
22
- children: Snippet;
23
- field?: FormField | undefined;
24
- issue?: FormIssue | undefined;
25
- };
26
- events: {
27
- [evt: string]: CustomEvent<any>;
28
- };
29
- slots: {};
30
- };
31
- export type FieldContentProps = typeof __propDef.props;
32
- export type FieldContentEvents = typeof __propDef.events;
33
- export type FieldContentSlots = typeof __propDef.slots;
34
- export default class FieldContent extends SvelteComponent<FieldContentProps, FieldContentEvents, FieldContentSlots> {
35
- constructor(options?: import("svelte").ComponentConstructorOptions<{
36
- id: string;
37
- contained?: boolean | undefined;
38
- prefix?: string | ((this: void) => typeof import("svelte").SnippetReturn & {
39
- _: "functions passed to {@render ...} tags must use the `Snippet` type imported from \"svelte\"";
40
- }) | undefined;
41
- suffix?: string | ((this: void) => typeof import("svelte").SnippetReturn & {
42
- _: "functions passed to {@render ...} tags must use the `Snippet` type imported from \"svelte\"";
43
- }) | undefined;
44
- type?: string | undefined;
45
- label?: string | ((this: void) => typeof import("svelte").SnippetReturn & {
46
- _: "functions passed to {@render ...} tags must use the `Snippet` type imported from \"svelte\"";
47
- }) | undefined;
48
- labelTip?: string | ((this: void) => typeof import("svelte").SnippetReturn & {
49
- _: "functions passed to {@render ...} tags must use the `Snippet` type imported from \"svelte\"";
50
- }) | undefined;
51
- direction?: "row" | "column" | undefined;
52
- children: (this: void) => typeof import("svelte").SnippetReturn & {
53
- _: "functions passed to {@render ...} tags must use the `Snippet` type imported from \"svelte\"";
54
- };
55
- field?: FormField | undefined;
56
- issue?: FormIssue | undefined;
57
- }>);
3
+ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
4
+ new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
5
+ $$bindings?: Bindings;
6
+ } & Exports;
7
+ (internal: unknown, props: Props & {
8
+ $$events?: Events;
9
+ $$slots?: Slots;
10
+ }): Exports;
11
+ z_$$bindings?: Bindings;
58
12
  }
59
- export {};
13
+ declare const FieldContent: $$__sveltets_2_IsomorphicComponent<{
14
+ id: string;
15
+ contained?: boolean;
16
+ prefix?: string | Snippet;
17
+ suffix?: string | Snippet;
18
+ help?: string | Snippet;
19
+ type?: string;
20
+ label?: string | Snippet;
21
+ labelTip?: string | Snippet;
22
+ direction?: "row" | "column";
23
+ required?: boolean;
24
+ children: Snippet;
25
+ field?: FormField;
26
+ issue?: FormIssue;
27
+ }, {
28
+ [evt: string]: CustomEvent<any>;
29
+ }, {}, {}, "">;
30
+ type FieldContent = InstanceType<typeof FieldContent>;
31
+ export default FieldContent;
@@ -1,21 +1,18 @@
1
- import { SvelteComponent } from "svelte";
2
- declare const __propDef: {
3
- props: {
4
- code: string;
5
- message?: string | undefined;
6
- };
7
- events: {
8
- [evt: string]: CustomEvent<any>;
9
- };
10
- slots: {};
11
- };
12
- export type FieldErrorProps = typeof __propDef.props;
13
- export type FieldErrorEvents = typeof __propDef.events;
14
- export type FieldErrorSlots = typeof __propDef.slots;
15
- export default class FieldError extends SvelteComponent<FieldErrorProps, FieldErrorEvents, FieldErrorSlots> {
16
- constructor(options?: import("svelte").ComponentConstructorOptions<{
17
- code: string;
18
- message?: string | undefined;
19
- }>);
1
+ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
2
+ new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
3
+ $$bindings?: Bindings;
4
+ } & Exports;
5
+ (internal: unknown, props: Props & {
6
+ $$events?: Events;
7
+ $$slots?: Slots;
8
+ }): Exports;
9
+ z_$$bindings?: Bindings;
20
10
  }
21
- export {};
11
+ declare const FieldError: $$__sveltets_2_IsomorphicComponent<{
12
+ code: string;
13
+ message?: string;
14
+ }, {
15
+ [evt: string]: CustomEvent<any>;
16
+ }, {}, {}, "">;
17
+ type FieldError = InstanceType<typeof FieldError>;
18
+ export default FieldError;
@@ -1,34 +1,20 @@
1
- import { SvelteComponent } from "svelte";
2
1
  import type { Snippet } from "svelte";
3
- declare const __propDef: {
4
- props: {
5
- title?: string | ((this: void) => typeof import("svelte").SnippetReturn & {
6
- _: "functions passed to {@render ...} tags must use the `Snippet` type imported from \"svelte\"";
7
- }) | undefined;
8
- description?: string | ((this: void) => typeof import("svelte").SnippetReturn & {
9
- _: "functions passed to {@render ...} tags must use the `Snippet` type imported from \"svelte\"";
10
- }) | undefined;
11
- children: Snippet;
12
- };
13
- events: {
14
- [evt: string]: CustomEvent<any>;
15
- };
16
- slots: {};
17
- };
18
- export type FieldSectionProps = typeof __propDef.props;
19
- export type FieldSectionEvents = typeof __propDef.events;
20
- export type FieldSectionSlots = typeof __propDef.slots;
21
- export default class FieldSection extends SvelteComponent<FieldSectionProps, FieldSectionEvents, FieldSectionSlots> {
22
- constructor(options?: import("svelte").ComponentConstructorOptions<{
23
- title?: string | ((this: void) => typeof import("svelte").SnippetReturn & {
24
- _: "functions passed to {@render ...} tags must use the `Snippet` type imported from \"svelte\"";
25
- }) | undefined;
26
- description?: string | ((this: void) => typeof import("svelte").SnippetReturn & {
27
- _: "functions passed to {@render ...} tags must use the `Snippet` type imported from \"svelte\"";
28
- }) | undefined;
29
- children: (this: void) => typeof import("svelte").SnippetReturn & {
30
- _: "functions passed to {@render ...} tags must use the `Snippet` type imported from \"svelte\"";
31
- };
32
- }>);
2
+ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
3
+ new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
4
+ $$bindings?: Bindings;
5
+ } & Exports;
6
+ (internal: unknown, props: Props & {
7
+ $$events?: Events;
8
+ $$slots?: Slots;
9
+ }): Exports;
10
+ z_$$bindings?: Bindings;
33
11
  }
34
- export {};
12
+ declare const FieldSection: $$__sveltets_2_IsomorphicComponent<{
13
+ title?: string | Snippet;
14
+ description?: string | Snippet;
15
+ children: Snippet;
16
+ }, {
17
+ [evt: string]: CustomEvent<any>;
18
+ }, {}, {}, "">;
19
+ type FieldSection = InstanceType<typeof FieldSection>;
20
+ export default FieldSection;
@@ -1,42 +1,31 @@
1
- import { SvelteComponent } from "svelte";
2
1
  import type { Snippet } from "svelte";
3
- declare const __propDef: {
4
- props: {
5
- fullWidth?: boolean | undefined;
6
- description?: string | ((this: void) => typeof import("svelte").SnippetReturn & {
7
- _: "functions passed to {@render ...} tags must use the `Snippet` type imported from \"svelte\"";
8
- }) | undefined;
9
- contained?: boolean | undefined;
10
- rounded?: boolean | undefined;
11
- legend?: string | ((this: void) => typeof import("svelte").SnippetReturn & {
12
- _: "functions passed to {@render ...} tags must use the `Snippet` type imported from \"svelte\"";
13
- }) | undefined;
14
- columns?: number | [number] | [number, number] | [number, number, number] | undefined;
15
- children: Snippet;
16
- };
17
- events: {
18
- [evt: string]: CustomEvent<any>;
19
- };
20
- slots: {};
21
- };
22
- export type FieldsetProps = typeof __propDef.props;
23
- export type FieldsetEvents = typeof __propDef.events;
24
- export type FieldsetSlots = typeof __propDef.slots;
25
- export default class Fieldset extends SvelteComponent<FieldsetProps, FieldsetEvents, FieldsetSlots> {
26
- constructor(options?: import("svelte").ComponentConstructorOptions<{
27
- fullWidth?: boolean | undefined;
28
- description?: string | ((this: void) => typeof import("svelte").SnippetReturn & {
29
- _: "functions passed to {@render ...} tags must use the `Snippet` type imported from \"svelte\"";
30
- }) | undefined;
31
- contained?: boolean | undefined;
32
- rounded?: boolean | undefined;
33
- legend?: string | ((this: void) => typeof import("svelte").SnippetReturn & {
34
- _: "functions passed to {@render ...} tags must use the `Snippet` type imported from \"svelte\"";
35
- }) | undefined;
36
- columns?: number | [number] | [number, number] | [number, number, number] | undefined;
37
- children: (this: void) => typeof import("svelte").SnippetReturn & {
38
- _: "functions passed to {@render ...} tags must use the `Snippet` type imported from \"svelte\"";
39
- };
40
- }>);
2
+ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
3
+ new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
4
+ $$bindings?: Bindings;
5
+ } & Exports;
6
+ (internal: unknown, props: Props & {
7
+ $$events?: Events;
8
+ $$slots?: Slots;
9
+ }): Exports;
10
+ z_$$bindings?: Bindings;
41
11
  }
42
- export {};
12
+ declare const Fieldset: $$__sveltets_2_IsomorphicComponent<{
13
+ /** Whether the fieldset should be full width. */
14
+ fullWidth?: boolean;
15
+ /** The description of the fieldset. */
16
+ description?: string | Snippet;
17
+ /** Whether the fieldset should be contained. */
18
+ contained?: boolean;
19
+ /** Whether the fieldset should be rounded. */
20
+ rounded?: boolean;
21
+ /** The legend of the fieldset. */
22
+ legend?: string | Snippet;
23
+ /** The number of columns to display the fieldset in. You can pass a single number or an array of numbers. The array will be used to set the number of columns at different breakpoints (lg, md, sm). */
24
+ columns?: number | [number] | [number, number] | [number, number, number];
25
+ /** Content to be rendered inside the fieldset. */
26
+ children: Snippet;
27
+ }, {
28
+ [evt: string]: CustomEvent<any>;
29
+ }, {}, {}, "">;
30
+ type Fieldset = InstanceType<typeof Fieldset>;
31
+ export default Fieldset;
@@ -8,39 +8,52 @@ import { array } from "zod";
8
8
  import { arrayPathToStringPath, getIndividualValidators, parseFormIssues } from "./form.js";
9
9
  import { useForm } from "./client.svelte.js";
10
10
  let {
11
+ name = "form",
11
12
  form: _form,
12
13
  action,
13
14
  enctype = "multipart/form-data",
14
15
  method = "POST",
16
+ beforeSubmit,
15
17
  fullWidth = false,
18
+ onResult,
19
+ resetOnUpdate,
16
20
  children
17
21
  } = $props();
18
22
  let form = $state(_form ? useForm(_form) : null);
19
- setContext("form", form?.form);
20
- setContext("form.validators", getIndividualValidators(form?.form));
21
- const schema = form?.form.schema ? dezerialize(form?.form.schema) : null;
23
+ setContext("form", form);
24
+ setContext("form.validators", form ? getIndividualValidators(form) : null);
25
+ const beforeSubmitFunctions = [];
26
+ const addBeforeSubmit = (id, fn) => {
27
+ if (beforeSubmitFunctions.find((f) => f.id === id)) {
28
+ return;
29
+ }
30
+ beforeSubmitFunctions.push({ id, fn });
31
+ };
32
+ setContext("form.beforeSubmit", addBeforeSubmit);
33
+ const schema = form?.schema ? dezerialize(form?.schema) : null;
22
34
  const bodyguard = new Bodyguard();
23
35
  let formEl;
24
36
  function setFormIssuesAndFields(issues, fields) {
37
+ console.log("setFormIssuesAndFields", issues, fields);
25
38
  if (form) {
26
- form.form.issues = issues;
27
- form.form.fields = fields;
39
+ form.issues = issues;
40
+ form.fields = fields;
28
41
  }
29
42
  }
30
43
  async function validate() {
31
44
  if (form && schema) {
32
- form.form.tainted = true;
45
+ form.tainted = true;
33
46
  const req = new Request("localhost", {
34
47
  method: "POST",
35
48
  body: new FormData(formEl)
36
49
  });
37
50
  const result = await bodyguard.softForm(req, schema.parse);
38
51
  if (result.success === true) {
39
- form.form.valid = true;
40
- form.form.issues = [];
52
+ form.valid = true;
53
+ form.issues = [];
41
54
  } else {
42
- form.form.valid = false;
43
- form.form.issues = parseFormIssues(result.error.issues);
55
+ form.valid = false;
56
+ form.issues = parseFormIssues(result.error.issues);
44
57
  }
45
58
  }
46
59
  }
@@ -56,33 +69,59 @@ onMount(() => {
56
69
  {enctype}
57
70
  bind:this={formEl}
58
71
  onchange={validate}
59
- use:enhance={({ formElement, formData, action, cancel, submitter }) => {
72
+ use:enhance={async ({ formElement, formData, action, cancel, submitter }) => {
60
73
  // `formElement` is this `<form>` element
61
74
  // `formData` is its `FormData` object that's about to be submitted
62
75
  // `action` is the URL to which the form is posted
63
76
  // calling `cancel()` will prevent the submission
64
77
  // `submitter` is the `HTMLElement` that caused the form to be submitted
65
-
66
- return async ({ result, update }) => {
78
+ if(form) form.state = 'loading';
79
+ //await Promise.resolve(beforeSubmit(form));
80
+ if(beforeSubmit) await Promise.resolve(beforeSubmit({ form: formElement, data: formData, cancel: () => {
81
+ if(form) form.state = 'error';
82
+ cancel();
83
+ }}));
84
+ for(const { id, fn } of beforeSubmitFunctions) {
85
+ await Promise.resolve(fn({ form: formElement, data: formData, cancel: () => {
86
+ if(form) form.state = 'error';
87
+ cancel();
88
+ }}));
89
+ }
90
+ console.log('form state', form?.state);
91
+ return async (opts) => {
92
+ const { result, update } = opts;
67
93
  // `result` is an `ActionResult` object
68
94
  // `update` is a function which triggers the default logic that would be triggered if this callback wasn't set
69
- console.log('result', result);
70
- const resultForm = result.type !== "redirect" && result.type !== "error" ? result?.data?.form : null;
95
+ console.log('form result', opts);
96
+ if(onResult) {
97
+ console.log('calling onResult')
98
+ onResult(opts);
99
+ }
100
+ const resultForm = result.type !== "redirect" && result.type !== "error" ? result?.data![name] : null;
101
+ console.log('resultForm', resultForm, form)
71
102
  if(result.type === "success") {
72
103
  if(resultForm && form) {
73
- form.form.valid = Object.assign({ valid: false }, resultForm).valid ?? false;
104
+ form.valid = Object.assign({ valid: false }, resultForm).valid ?? false;
74
105
  }
106
+ if(form) form.state = 'success';
107
+ console.log('form state', form?.state);
108
+ update({ reset: !!resetOnUpdate });
75
109
  } else if(result.type === "failure") {
110
+ console.log('FAILURE')
76
111
  if(resultForm && form) {
112
+ console.log('setting form issues and fields')
77
113
  setFormIssuesAndFields(
78
114
  Object.assign({ issues: [] }, resultForm).issues, // Have to assign to avoid type error as we cant use `as` here
79
115
  Object.assign({ fields: [] }, resultForm).fields,
80
116
  );
81
117
  }
118
+ if(form) form.state = 'error';
82
119
  } else if(result.type === "error") {
83
120
  console.error('[lutra] Error from form enhance call', result.error);
121
+ if(form) form.state = 'error';
84
122
  } else if(result.type === "redirect") {
85
123
  window.location.href = result.location;
124
+ if(form) form.state = 'success';
86
125
  }
87
126
  };
88
127
  }}
@@ -1,33 +1,38 @@
1
- import { SvelteComponent } from "svelte";
1
+ import type { ActionResult } from "@sveltejs/kit";
2
2
  import type { Snippet } from "svelte";
3
- import type { Form } from "./types.js";
4
- declare const __propDef: {
5
- props: {
6
- form?: Form<any> | undefined;
7
- action?: string | undefined;
8
- enctype?: "application/x-www-form-urlencoded" | "multipart/form-data" | "text/plain" | undefined;
9
- method?: "GET" | "POST" | undefined;
10
- fullWidth?: boolean | undefined;
11
- children: Snippet;
12
- };
13
- events: {
14
- [evt: string]: CustomEvent<any>;
15
- };
16
- slots: {};
17
- };
18
- export type FormProps = typeof __propDef.props;
19
- export type FormEvents = typeof __propDef.events;
20
- export type FormSlots = typeof __propDef.slots;
21
- export default class Form extends SvelteComponent<FormProps, FormEvents, FormSlots> {
22
- constructor(options?: import("svelte").ComponentConstructorOptions<{
23
- form?: Form<any> | undefined;
24
- action?: string | undefined;
25
- enctype?: "application/x-www-form-urlencoded" | "multipart/form-data" | "text/plain" | undefined;
26
- method?: "GET" | "POST" | undefined;
27
- fullWidth?: boolean | undefined;
28
- children: (this: void) => typeof import("svelte").SnippetReturn & {
29
- _: "functions passed to {@render ...} tags must use the `Snippet` type imported from \"svelte\"";
30
- };
31
- }>);
3
+ import type { BeforeSubmitFn, LutraForm } from "./types.js";
4
+ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
5
+ new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
6
+ $$bindings?: Bindings;
7
+ } & Exports;
8
+ (internal: unknown, props: Props & {
9
+ $$events?: Events;
10
+ $$slots?: Slots;
11
+ }): Exports;
12
+ z_$$bindings?: Bindings;
32
13
  }
33
- export {};
14
+ declare const Form: $$__sveltets_2_IsomorphicComponent<{
15
+ name?: string;
16
+ form?: LutraForm<any>;
17
+ action?: string;
18
+ enctype?: "application/x-www-form-urlencoded" | "multipart/form-data" | "text/plain";
19
+ method?: "GET" | "POST";
20
+ beforeSubmit?: BeforeSubmitFn;
21
+ fullWidth?: boolean;
22
+ resetOnUpdate?: boolean;
23
+ onResult?: (args: {
24
+ formData: FormData;
25
+ formElement: HTMLFormElement;
26
+ action: URL;
27
+ result: ActionResult<Record<string, unknown> | undefined, Record<string, unknown> | undefined>;
28
+ update: (options?: {
29
+ reset?: boolean | undefined;
30
+ invalidateAll?: boolean | undefined;
31
+ } | undefined) => void;
32
+ }) => void;
33
+ children: Snippet;
34
+ }, {
35
+ [evt: string]: CustomEvent<any>;
36
+ }, {}, {}, "">;
37
+ type Form = InstanceType<typeof Form>;
38
+ export default Form;