lutra 0.0.12 → 0.0.15

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 (117) hide show
  1. package/dist/data/Stat.svelte +1 -1
  2. package/dist/display/Avatar.svelte +1 -1
  3. package/dist/display/Badge.svelte +1 -1
  4. package/dist/display/Callout.svelte +3 -3
  5. package/dist/display/Code.svelte +1 -1
  6. package/dist/display/ContextTip.svelte +12 -8
  7. package/dist/display/Details.svelte +1 -1
  8. package/dist/display/Hero.svelte +1 -1
  9. package/dist/display/Icon.svelte +13 -6
  10. package/dist/display/IconButton.svelte +9 -9
  11. package/dist/display/IconButton.svelte.d.ts +0 -2
  12. package/dist/display/Image.svelte +41 -0
  13. package/dist/display/Image.svelte.d.ts +24 -0
  14. package/dist/display/Indicator.svelte +1 -1
  15. package/dist/display/Inset.svelte +18 -0
  16. package/dist/display/Inset.svelte.d.ts +17 -0
  17. package/dist/display/Popup.svelte +1 -1
  18. package/dist/display/Popup.svelte.d.ts +1 -3
  19. package/dist/display/Table.svelte +21 -0
  20. package/dist/display/Table.svelte.d.ts +23 -0
  21. package/dist/display/Tag.svelte +2 -2
  22. package/dist/display/Tooltip.svelte +8 -5
  23. package/dist/display/index.d.ts +1 -0
  24. package/dist/display/index.js +1 -0
  25. package/dist/form/Button.svelte +1 -1
  26. package/dist/form/FieldActions.svelte +27 -6
  27. package/dist/form/FieldActions.svelte.d.ts +1 -0
  28. package/dist/form/FieldContainer.svelte +4 -3
  29. package/dist/form/FieldContent.svelte +54 -16
  30. package/dist/form/FieldError.svelte +1 -1
  31. package/dist/form/FieldSection.svelte +21 -46
  32. package/dist/form/Fieldset.svelte +10 -5
  33. package/dist/form/Fieldset.svelte.d.ts +2 -0
  34. package/dist/form/Form.svelte +30 -25
  35. package/dist/form/Form.svelte.d.ts +1 -1
  36. package/dist/form/Input.svelte +23 -42
  37. package/dist/form/Input.svelte.d.ts +5 -1
  38. package/dist/form/InputLength.svelte +1 -1
  39. package/dist/form/Label.svelte +2 -1
  40. package/dist/form/Select.svelte +7 -26
  41. package/dist/form/Select.svelte.d.ts +2 -26
  42. package/dist/form/client.svelte.js +13 -9
  43. package/dist/form/form.d.ts +1 -1
  44. package/dist/form/form.js +4 -0
  45. package/dist/grid/Column.svelte +1 -1
  46. package/dist/grid/Grid.svelte +1 -1
  47. package/dist/grid/Row.svelte +1 -1
  48. package/dist/icons/Alert.svelte +2 -2
  49. package/dist/icons/Copy.svelte +2 -2
  50. package/dist/icons/Done.svelte +2 -2
  51. package/dist/icons/Error.svelte +2 -2
  52. package/dist/icons/Help.svelte +2 -2
  53. package/dist/icons/Hide.svelte +2 -2
  54. package/dist/icons/Info.svelte +2 -2
  55. package/dist/icons/Link.svelte +2 -2
  56. package/dist/icons/MenuBurger.svelte +3 -0
  57. package/dist/icons/MenuBurger.svelte.d.ts +23 -0
  58. package/dist/icons/MenuDots.svelte +3 -0
  59. package/dist/icons/MenuDots.svelte.d.ts +23 -0
  60. package/dist/icons/Show.svelte +2 -2
  61. package/dist/icons/Success.svelte +2 -2
  62. package/dist/icons/Warning.svelte +2 -2
  63. package/dist/layout/Layout.svelte +1 -1
  64. package/dist/layout/LayoutFooter.svelte +1 -1
  65. package/dist/layout/LayoutGrid.svelte +1 -1
  66. package/dist/layout/LayoutHeader.svelte +1 -1
  67. package/dist/layout/PageContent.svelte +1 -1
  68. package/dist/layout/Theme.svelte +7 -7
  69. package/dist/layout/UIContent.svelte +1 -1
  70. package/dist/nav/Breadcrumb.svelte +1 -1
  71. package/dist/nav/Menu.svelte +177 -161
  72. package/dist/nav/Menu.svelte.d.ts +11 -3
  73. package/dist/nav/MenuItem.svelte +122 -0
  74. package/dist/nav/MenuItem.svelte.d.ts +17 -0
  75. package/dist/nav/MenuTypes.d.ts +24 -3
  76. package/dist/nav/NavMenu.svelte +183 -0
  77. package/dist/nav/NavMenu.svelte.d.ts +18 -0
  78. package/dist/nav/TabbedContent.svelte +1 -1
  79. package/dist/nav/Tabs.svelte +8 -8
  80. package/dist/nav/index.d.ts +2 -0
  81. package/dist/nav/index.js +1 -0
  82. package/dist/style.css +36 -24
  83. package/dist/typo/Clamp.svelte +1 -1
  84. package/dist/typo/H.svelte +3 -2
  85. package/dist/typo/H.svelte.d.ts +2 -0
  86. package/dist/typo/H1.svelte +3 -3
  87. package/dist/typo/H1.svelte.d.ts +2 -0
  88. package/dist/typo/H2.svelte +3 -2
  89. package/dist/typo/H2.svelte.d.ts +2 -0
  90. package/dist/typo/H3.svelte +3 -2
  91. package/dist/typo/H3.svelte.d.ts +2 -0
  92. package/dist/typo/H4.svelte +3 -2
  93. package/dist/typo/H4.svelte.d.ts +2 -0
  94. package/dist/typo/H5.svelte +3 -2
  95. package/dist/typo/H5.svelte.d.ts +2 -0
  96. package/dist/typo/H6.svelte +3 -2
  97. package/dist/typo/H6.svelte.d.ts +2 -0
  98. package/dist/typo/P.svelte +3 -1
  99. package/dist/typo/P.svelte.d.ts +2 -0
  100. package/dist/utils/StringOrComponentOrSnippet.svelte +13 -0
  101. package/dist/utils/StringOrComponentOrSnippet.svelte.d.ts +17 -0
  102. package/dist/utils/index.d.ts +8 -0
  103. package/dist/utils/index.js +5 -0
  104. package/dist/utils/keyboard.svelte.d.ts +3 -0
  105. package/dist/utils/keyboard.svelte.js +142 -0
  106. package/dist/utils/transitions.js +14 -7
  107. package/package.json +9 -13
  108. package/dist/datatable/DataTable.svelte +0 -30
  109. package/dist/datatable/DataTable.svelte.d.ts +0 -20
  110. package/dist/datatable/DataTableColumn.svelte +0 -20
  111. package/dist/datatable/DataTableColumn.svelte.d.ts +0 -18
  112. package/dist/datatable/DataTableRow.svelte +0 -60
  113. package/dist/datatable/DataTableRow.svelte.d.ts +0 -21
  114. package/dist/datatable/index.d.ts +0 -3
  115. package/dist/datatable/index.js +0 -3
  116. package/dist/form/server.d.ts +0 -21
  117. package/dist/form/server.js +0 -48
@@ -1,4 +1,4 @@
1
- <script>import H5 from "../typo/H5.svelte";
1
+ <script lang="ts">import H5 from "../typo/H5.svelte";
2
2
  import P from "../typo/P.svelte";
3
3
  let {
4
4
  title,
@@ -7,7 +7,7 @@ let {
7
7
  } = $props();
8
8
  </script>
9
9
 
10
- <div class="FieldSection">
10
+ <div class="FieldSection" class:noTitle={!!title && !!description}>
11
11
  {#if title || description}
12
12
  <div class="FieldSectionTitle">
13
13
  {#if title}
@@ -35,63 +35,38 @@ let {
35
35
  .FieldSection {
36
36
  padding: 0;
37
37
  display: grid;
38
- gap: 0rem;
39
- grid-template-columns: 1fr;
38
+ grid-template-columns: subgrid;
39
+ grid-column: 1 / -1;
40
+ padding: calc(var(--fcc) * 3em);
40
41
  }
41
- .FieldSection .FieldSectionTitle {
42
+ .FieldSectionTitle {
42
43
  display: flex;
43
44
  flex-direction: column;
44
45
  background-color: var(--base);
45
- gap: 0.25rem;
46
- padding: 1em 1.5em;
47
- border-bottom: var(--border);
46
+ gap: 1.25em;
47
+ text-wrap: balance;
48
48
  }
49
49
  .FieldSection:not(:first-child) {
50
50
  border-top: calc(var(--fcc) * var(--border-size)) var(--border-style) var(--border-color);
51
51
  }
52
- .FieldSection .FieldSectionFields {
53
- padding: calc(var(--padding, 1.5em) * var(--fcc));
52
+ .FieldSectionFields {
54
53
  display: grid;
55
- gap: 1.5rem;
54
+ gap: var(--gap, 1.5em);
56
55
  }
57
- @container (min-width: 600px) {
58
- .FieldSection {
59
- gap: 3rem;
60
- padding: 2rem;
61
- grid-template-columns: 1fr;
62
- border-bottom: 1px dotted var(--border-light);
63
- margin-bottom: 3rem;
64
- border-radius: 0;
65
- }
66
- .FieldSection:has(.FieldSectionTitle) {
67
- grid-template-columns: minmax(180px, 1fr) 3fr;
68
- }
69
- .FieldSection:last-child {
70
- border-bottom: none;
71
- margin-bottom: 0;
72
- }
73
- .FieldSection:not(:first-child) {
74
- border-top: 0;
75
- padding-top: 0;
76
- }
77
- .FieldSection .FieldSectionTitle {
78
- gap: 1rem;
79
- padding: 0;
80
- background-color: transparent;
81
- border-bottom: none;
82
- }
83
- .FieldSection .FieldSectionFields {
84
- padding: 0;
85
- }
56
+ .FieldSection.noTitle .FieldSectionFields {
57
+ grid-column: 1 / -1;
86
58
  }
87
- @container (min-width: 1024px) {
59
+ @container (max-width: 640px) {
88
60
  .FieldSection {
89
- grid-template-columns: minmax(300px, 1fr) 3fr;
90
- padding: 3rem;
61
+ padding: 2em;
62
+ }
63
+ .FieldSectionTitle {
64
+ gap: 0.5em;
65
+ padding-block-end: 1.5em;
91
66
  }
92
- .FieldSection:not(:first-child) {
93
- border-top: 0;
94
- padding-top: 0;
67
+ .FieldSectionTitle,
68
+ .FieldSectionFields {
69
+ grid-column: 1 / -1;
95
70
  }
96
71
  }
97
72
  </style>
@@ -1,4 +1,5 @@
1
- <script>let {
1
+ <script lang="ts">let {
2
+ fullWidth,
2
3
  description,
3
4
  contained,
4
5
  rounded,
@@ -13,7 +14,7 @@ let smColumns = columnsArray[2] || mdColumns;
13
14
  </script>
14
15
 
15
16
  <div class="FieldsetContainer">
16
- <fieldset class:rounded class:contained class="cols-{columns}" style="--lg-cols: {lgColumns}; --md-cols: {mdColumns}; --sm-cols: {smColumns}">
17
+ <fieldset class:fullWidth class:rounded class:contained class="cols-{columns}" style="--lg-cols: {lgColumns}; --md-cols: {mdColumns}; --sm-cols: {smColumns}">
17
18
  {#if legend}
18
19
  <legend>
19
20
  {#if typeof legend === 'string'}
@@ -40,15 +41,19 @@ let smColumns = columnsArray[2] || mdColumns;
40
41
  }
41
42
  fieldset {
42
43
  display: grid;
44
+ width: var(--width, fit-content);
43
45
  grid-template-columns: repeat(var(--lg-cols), 1fr);
44
- gap: 1rem;
46
+ gap: var(--gap, 1.5em);
45
47
  }
46
48
  legend {
47
- margin-bottom: 1.5rem;
49
+ font-weight: 500;
48
50
  font-size: var(--font-size, 1em);
49
51
  }
50
52
  fieldset.contained {
51
- padding: 2rem;
53
+ padding: 1.5em;
54
+ }
55
+ fieldset.fullWidth {
56
+ width: 100%;
52
57
  }
53
58
  @container(max-width: 960px) {
54
59
  fieldset {
@@ -2,6 +2,8 @@ import { SvelteComponent } from "svelte";
2
2
  import type { Snippet } from "svelte";
3
3
  declare const __propDef: {
4
4
  props: {
5
+ /** Whether the fieldset should be full width. */
6
+ fullWidth?: boolean | undefined;
5
7
  /** The description of the fieldset. */
6
8
  description?: string | ((this: void) => typeof import("svelte").SnippetReturn & {
7
9
  _: "functions passed to {@render ...} tags must use the `Snippet` type imported from \"svelte\"";
@@ -1,4 +1,4 @@
1
- <script>import { enhance } from "$app/forms";
1
+ <script lang="ts">import { enhance } from "$app/forms";
2
2
  import UiContent from "../layout/UIContent.svelte";
3
3
  import { Bodyguard } from "@auth70/bodyguard";
4
4
  import { onMount, setContext } from "svelte";
@@ -16,26 +16,30 @@ let {
16
16
  } = $props();
17
17
  setContext("form", form);
18
18
  setContext("form.validators", getIndividualValidators(form));
19
- const schema = dezerialize(form.schema);
19
+ const schema = form?.schema ? dezerialize(form?.schema) : null;
20
20
  const bodyguard = new Bodyguard();
21
21
  let formEl;
22
22
  function setFormIssuesAndFields(issues, fields) {
23
- form.issues = issues;
24
- form.fields = fields;
23
+ if (form) {
24
+ form.issues = issues;
25
+ form.fields = fields;
26
+ }
25
27
  }
26
28
  async function validate() {
27
- form.tainted = true;
28
- const req = new Request("localhost", {
29
- method: "POST",
30
- body: new FormData(formEl)
31
- });
32
- const result = await bodyguard.softForm(req, schema.parse);
33
- if (result.success === true) {
34
- form.valid = true;
35
- form.issues = [];
36
- } else {
37
- form.valid = false;
38
- form.issues = parseFormIssues(result.error.issues);
29
+ if (form && schema) {
30
+ form.tainted = true;
31
+ const req = new Request("localhost", {
32
+ method: "POST",
33
+ body: new FormData(formEl)
34
+ });
35
+ const result = await bodyguard.softForm(req, schema.parse);
36
+ if (result.success === true) {
37
+ form.valid = true;
38
+ form.issues = [];
39
+ } else {
40
+ form.valid = false;
41
+ form.issues = parseFormIssues(result.error.issues);
42
+ }
39
43
  }
40
44
  }
41
45
  onMount(() => {
@@ -61,19 +65,20 @@ onMount(() => {
61
65
  // `result` is an `ActionResult` object
62
66
  // `update` is a function which triggers the default logic that would be triggered if this callback wasn't set
63
67
  console.log('result', result);
64
- const resultForm = result?.data?.form;
68
+ const resultForm = result.type !== "redirect" && result.type !== "error" ? result?.data?.form : null;
65
69
  if(result.type === "success") {
66
- if(resultForm) {
67
- form.valid = resultForm.valid;
68
- }
69
- } else if(result.type === "error") {
70
- if(resultForm) {
71
- setFormIssuesAndFields(resultForm.issues, resultForm.fields);
70
+ if(resultForm && form) {
71
+ form.valid = Object.assign({ valid: false }, resultForm).valid ?? false;
72
72
  }
73
73
  } else if(result.type === "failure") {
74
- if(resultForm) {
75
- setFormIssuesAndFields(resultForm.issues, resultForm.fields);
74
+ if(resultForm && form) {
75
+ setFormIssuesAndFields(
76
+ Object.assign({ issues: [] }, resultForm).issues, // Have to assign to avoid type error as we cant use `as` here
77
+ Object.assign({ fields: [] }, resultForm).fields,
78
+ );
76
79
  }
80
+ } else if(result.type === "error") {
81
+ console.error('[lutra] Error from form enhance call', result.error);
77
82
  } else if(result.type === "redirect") {
78
83
  window.location.href = result.location;
79
84
  }
@@ -3,7 +3,7 @@ import type { Snippet } from "svelte";
3
3
  import type { Form } from "./types.js";
4
4
  declare const __propDef: {
5
5
  props: {
6
- form: Form<any>;
6
+ form?: Form<any> | undefined;
7
7
  action?: string | undefined;
8
8
  enctype?: "application/x-www-form-urlencoded" | "multipart/form-data" | "text/plain" | undefined;
9
9
  method?: "GET" | "POST" | undefined;
@@ -1,4 +1,4 @@
1
- <script>import { getContext } from "svelte";
1
+ <script lang="ts">import { getContext } from "svelte";
2
2
  import { createId } from "../utils/id.js";
3
3
  import Copy from "../icons/Copy.svelte";
4
4
  import Done from "../icons/Done.svelte";
@@ -13,6 +13,7 @@ import { ZodType } from "zod";
13
13
  import FieldContent from "./FieldContent.svelte";
14
14
  let {
15
15
  alt,
16
+ attrs,
16
17
  autocapitalize,
17
18
  autocomplete,
18
19
  autocorrect,
@@ -53,6 +54,7 @@ let {
53
54
  required,
54
55
  results,
55
56
  shape = "rounded",
57
+ size,
56
58
  src,
57
59
  step,
58
60
  tabindex,
@@ -69,7 +71,7 @@ let copyTooltipOpen = $state(false);
69
71
  let copyBtnIcon = $state(Copy);
70
72
  let viewBtnIcon = $state(Show);
71
73
  const form = getContext("form");
72
- const field = $derived(form.fields[name]);
74
+ const field = $derived(form?.fields[name]);
73
75
  const issue = $derived(form?.issues?.find((issue2) => issue2.name === name));
74
76
  const validator = getContext("form.validators")?.[name];
75
77
  const data = form?.data;
@@ -115,6 +117,7 @@ function copy(e) {
115
117
  <input
116
118
  bind:this={el}
117
119
  {alt}
120
+ {...attrs}
118
121
  autocapitalize={typeof autocapitalize === 'string' ? autocapitalize : (typeof autocapitalize === 'boolean' ? (autocapitalize ? 'on' : 'off') : undefined)}
119
122
  {autocomplete}
120
123
  autocorrect={typeof autocorrect === 'boolean' ? (autocorrect ? 'on' : 'off') : undefined}
@@ -146,12 +149,13 @@ function copy(e) {
146
149
  {readonly}
147
150
  required={required || field?.required}
148
151
  {results}
152
+ {size}
149
153
  {src}
150
154
  {step}
151
155
  {tabindex}
152
156
  {title}
153
157
  {type}
154
- value={value || getFromObjWithStringPath(Object.assign(originalData, data), name) || form?.fields?.[name]?.defaultValue || ''}
158
+ value={value || getFromObjWithStringPath(Object.assign(originalData ?? {}, data ?? {}), name) || form?.fields?.[name]?.defaultValue || ''}
155
159
  {webkitdirectory}
156
160
  />
157
161
  {/snippet}
@@ -160,55 +164,32 @@ function copy(e) {
160
164
  {id}
161
165
  {label}
162
166
  {labelTip}
167
+ contained={type === "checkbox" || type === "radio" ? false : true}
163
168
  direction={(type === "checkbox" || type === "radio") ? 'row' : 'column'}
164
169
  {field}
165
170
  {issue}
171
+ {prefix}
172
+ {suffix}
166
173
  >
167
174
 
168
175
  {#if type === "checkbox" || type === "radio"}
169
176
  {@render input()}
170
177
  {:else}
171
178
 
172
- <div
173
- class="Field {type}"
174
- class:hasPrefix={!!prefix}
175
- class:hasSuffix={!!suffix}
176
- class:invalid={field?.tainted && issue?.code}
177
- >
178
- {#if prefix}
179
- <div class="Fix Prefix">
180
- {#if typeof prefix === 'string'}
181
- {prefix}
182
- {:else}
183
- {@render prefix()}
184
- {/if}
185
- </div>
186
- {/if}
187
-
188
- {@render input()}
179
+ {@render input()}
189
180
 
190
- {#if copyable}
191
- <Tooltip tip={copyTitle} open={copyTooltipOpen}>
192
- <IconButton icon={copyBtnIcon} onclick={copy} disabled={copyTooltipOpen} />
193
- </Tooltip>
194
- {/if}
195
-
196
- {#if type === "password" && viewable}
197
- <Tooltip tip={viewTitle}>
198
- <IconButton icon={viewBtnIcon} onclick={view} />
199
- </Tooltip>
200
- {/if}
181
+ {#if copyable}
182
+ <Tooltip tip={copyTitle} open={copyTooltipOpen}>
183
+ <IconButton icon={copyBtnIcon} onclick={copy} disabled={copyTooltipOpen} />
184
+ </Tooltip>
185
+ {/if}
186
+
187
+ {#if type === "password" && viewable}
188
+ <Tooltip tip={viewTitle}>
189
+ <IconButton icon={viewBtnIcon} onclick={view} />
190
+ </Tooltip>
191
+ {/if}
201
192
 
202
- {#if suffix}
203
- <div class="Fix Suffix">
204
- {#if typeof suffix === 'string'}
205
- {suffix}
206
- {:else}
207
- {@render suffix()}
208
- {/if}
209
- </div>
210
- {/if}
211
- </div>
212
193
  {/if}
213
194
  </FieldContent>
214
195
 
@@ -237,7 +218,7 @@ function copy(e) {
237
218
  .Fix {
238
219
  display: flex;
239
220
  align-items: center;
240
- padding-inline: 0.75em;
221
+ padding-inline: 0.65em;
241
222
  font-size: 1em;
242
223
  line-height: 1.5;
243
224
  color: var(--text-subtle);
@@ -4,6 +4,8 @@ declare const __propDef: {
4
4
  props: {
5
5
  /** alt attribute for the image type. Required for accessibility */
6
6
  alt?: string | undefined;
7
+ /** Additional attributes to add to the input element. */
8
+ attrs?: Record<string, string> | undefined;
7
9
  /** Whether the input should be autocapitalized. */
8
10
  autocapitalize?: boolean | "none" | "off" | "on" | "sentences" | "words" | "characters" | undefined;
9
11
  /** Specifies whether autocomplete is enabled for the input. */
@@ -95,6 +97,8 @@ declare const __propDef: {
95
97
  results?: number | undefined;
96
98
  /** The shape of the input element. */
97
99
  shape?: "default" | "circle" | "rounded" | "pill" | undefined;
100
+ /** The size of the input element. */
101
+ size?: number | undefined;
98
102
  /** Source URL for the image type. */
99
103
  src?: string | undefined;
100
104
  /** Spellcheck the input. */
@@ -117,7 +121,7 @@ declare const __propDef: {
117
121
  events: {
118
122
  [evt: string]: CustomEvent<any>;
119
123
  };
120
- slots: {}; /** Onclick event handler */
124
+ slots: {};
121
125
  };
122
126
  export type InputProps = typeof __propDef.props;
123
127
  export type InputEvents = typeof __propDef.events;
@@ -1,4 +1,4 @@
1
- <script>let {
1
+ <script lang="ts">let {
2
2
  value,
3
3
  maxlength
4
4
  } = $props();
@@ -1,4 +1,4 @@
1
- <script>import ContextTip from "../display/ContextTip.svelte";
1
+ <script lang="ts">import ContextTip from "../display/ContextTip.svelte";
2
2
  let {
3
3
  id,
4
4
  label,
@@ -22,5 +22,6 @@ let {
22
22
  <style>
23
23
  label {
24
24
  cursor: var(--cursor, default);
25
+ text-wrap: balance;
25
26
  }
26
27
  </style>
@@ -1,4 +1,4 @@
1
- <script>import { getContext } from "svelte";
1
+ <script lang="ts">import { getContext } from "svelte";
2
2
  import Label from "./Label.svelte";
3
3
  import { createId } from "../utils/id.js";
4
4
  import Copy from "../icons/Copy.svelte";
@@ -13,27 +13,14 @@ import { getFromObjWithStringPath } from "./form.js";
13
13
  import { ZodType } from "zod";
14
14
  import FieldContent from "./FieldContent.svelte";
15
15
  let {
16
- alt,
17
- checked,
16
+ attrs,
18
17
  children,
19
- contained,
20
- defaultValue,
21
- dirname,
22
18
  disabled,
23
19
  help,
24
20
  id = $bindable(createId()),
25
21
  label,
26
22
  labelTip,
27
- list,
28
- maxlength,
29
- minlength,
30
- max,
31
- min,
32
- multiple,
33
23
  name,
34
- pattern,
35
- placeholder,
36
- suffix,
37
24
  onblur,
38
25
  onchange,
39
26
  onclick,
@@ -42,23 +29,16 @@ let {
42
29
  onkeyup,
43
30
  onkeypress,
44
31
  options,
45
- prefix,
46
- readonly,
32
+ placeholder,
47
33
  required,
48
34
  results,
49
- shape = "rounded",
50
- src,
35
+ shape = "default",
51
36
  tabindex,
52
37
  value = $bindable()
53
38
  } = $props();
54
39
  let el = $state();
55
- let copyTitle = $state("Copy");
56
- let viewTitle = $state("Show");
57
- let copyTooltipOpen = $state(false);
58
- let copyBtnIcon = $state(Copy);
59
- let viewBtnIcon = $state(Show);
60
40
  const form = getContext("form");
61
- const field = $derived(form.fields[name]);
41
+ const field = $derived(form?.fields[name]);
62
42
  const issue = $derived(form?.issues?.find((issue2) => issue2.name === name));
63
43
  const validator = getContext("form.validators")?.[name];
64
44
  const data = form?.data;
@@ -74,6 +54,7 @@ const originalData = form?.originalData;
74
54
  >
75
55
  <select
76
56
  bind:this={el}
57
+ {...attrs}
77
58
  {disabled}
78
59
  {id}
79
60
  {name}
@@ -88,7 +69,7 @@ const originalData = form?.originalData;
88
69
  required={required || field?.required}
89
70
  {results}
90
71
  {tabindex}
91
- value={value || getFromObjWithStringPath(Object.assign(originalData, data), name) || form?.fields?.[name]?.defaultValue || ''}
72
+ value={value || getFromObjWithStringPath(Object.assign(originalData ?? {}, data ?? {}), name) || form?.fields?.[name]?.defaultValue || ''}
92
73
  >
93
74
  {#if children}
94
75
  {@render children()}
@@ -1,20 +1,12 @@
1
1
  import { SvelteComponent } from "svelte";
2
2
  declare const __propDef: {
3
3
  props: {
4
- /** alt attribute for the image type. Required for accessibility */
5
- alt?: string | undefined;
6
- /** Whether the input should be checked. */
7
- checked?: boolean | undefined;
4
+ /** Additional attributes to add to the input element. */
5
+ attrs?: Record<string, string> | undefined;
8
6
  /** Options for the select element. */
9
7
  children?: ((this: void) => typeof import("svelte").SnippetReturn & {
10
8
  _: "functions passed to {@render ...} tags must use the `Snippet` type imported from \"svelte\"";
11
9
  }) | undefined;
12
- /** Whether the input should be contained. */
13
- contained?: boolean | undefined;
14
- /** The default value of the input element. */
15
- defaultValue?: string | undefined;
16
- /** Form field name for the directionality of the element's text content during form submission */
17
- dirname?: string | undefined;
18
10
  /** Whether the input should be disabled. */
19
11
  disabled?: boolean | undefined;
20
12
  /** Help text to display below the input. */
@@ -31,18 +23,6 @@ declare const __propDef: {
31
23
  labelTip?: string | ((this: void) => typeof import("svelte").SnippetReturn & {
32
24
  _: "functions passed to {@render ...} tags must use the `Snippet` type imported from \"svelte\"";
33
25
  }) | undefined;
34
- /** The id of a datalist element that contains pre-defined options for the input element. */
35
- list?: string | undefined;
36
- /** The maximum number of characters (as UTF-16 code units) the user can enter into the input. Valid for text, search, url, tel, email, and password. */
37
- maxlength?: number | undefined;
38
- /** The minimum number of characters (as UTF-16 code units) the user can enter into the input. Valid for text, search, url, tel, email, and password. */
39
- minlength?: number | undefined;
40
- /** The maximum value of the input element. Valid for date, month, week, time, datetime-local, number, and range. */
41
- max?: number | undefined;
42
- /** The minimum value of the input element. Valid for date, month, week, time, datetime-local, number, and range. */
43
- min?: number | undefined;
44
- /** Whether the input should allow multiple values. Valid for email and file inputs. */
45
- multiple?: boolean | undefined;
46
26
  /** The name of the input element. */
47
27
  name: string;
48
28
  /** The onblur event handler */
@@ -64,8 +44,6 @@ declare const __propDef: {
64
44
  value: string;
65
45
  label: string;
66
46
  }[] | undefined;
67
- /** A regular expression that the input's value is checked against. Valid for text, search, url, tel, email, and password. */
68
- pattern?: string | undefined;
69
47
  /** Placeholder text to display when the input is empty. */
70
48
  placeholder?: string | undefined;
71
49
  /** Suffix content, to display after the input. */
@@ -76,8 +54,6 @@ declare const __propDef: {
76
54
  prefix?: string | ((this: void) => typeof import("svelte").SnippetReturn & {
77
55
  _: "functions passed to {@render ...} tags must use the `Snippet` type imported from \"svelte\"";
78
56
  }) | undefined;
79
- /** Whether the input should be read-only. */
80
- readonly?: boolean | undefined;
81
57
  /** Whether the input should be required. */
82
58
  required?: boolean | undefined;
83
59
  /** The maximum number of items that should be displayed in the drop-down list of previous search queries. Safari only. */
@@ -51,11 +51,13 @@ export function fieldValidate(form, name, el, validator) {
51
51
  export function fieldKeydown(form, name, el, validator, onkeydown) {
52
52
  return async function (e) {
53
53
  setTimeout(() => {
54
- const possibleKey = e?.key;
55
- if (ignoreKeys.includes(possibleKey))
56
- return;
57
- form.data[name] = el()?.value || '';
58
- fieldValidate(form, name, el(), validator);
54
+ if (form) {
55
+ const possibleKey = e?.key;
56
+ if (ignoreKeys.includes(possibleKey))
57
+ return;
58
+ form.data[name] = el()?.value || '';
59
+ fieldValidate(form, name, el(), validator);
60
+ }
59
61
  }, 0); // Wait for the key to be updated in the input.
60
62
  if (onkeydown)
61
63
  return onkeydown(e);
@@ -72,10 +74,12 @@ export function fieldKeydown(form, name, el, validator, onkeydown) {
72
74
  */
73
75
  export function fieldChange(form, name, el, validator, onchange) {
74
76
  return async function (e) {
75
- console.log('fieldChange', name, el()?.value, validator);
76
- form.data[name] = el()?.value || '';
77
- form.fields[name].tainted = true;
78
- fieldValidate(form, name, el(), validator);
77
+ if (form) {
78
+ console.log('fieldChange', name, el()?.value, validator);
79
+ form.data[name] = el()?.value || '';
80
+ form.fields[name].tainted = true;
81
+ fieldValidate(form, name, el(), validator);
82
+ }
79
83
  if (onchange)
80
84
  return onchange(e);
81
85
  };
@@ -49,4 +49,4 @@ export declare function getFromObjWithStringPath(obj: any, path: string): string
49
49
  * @param {Form} form - The form to get the validators from.
50
50
  * @returns {Record<keyof Infer<T>, (value: any) => boolean>} - The validators for each field.
51
51
  */
52
- export declare function getIndividualValidators<T extends ZodTypes>(form: Form<T>): Record<keyof Infer<T>, (value: any) => boolean>;
52
+ export declare function getIndividualValidators<T extends ZodTypes>(form?: Form<T>): Record<keyof Infer<T>, (value: any) => boolean>;
package/dist/form/form.js CHANGED
@@ -246,6 +246,8 @@ export function arrayPathToStringPath(path) {
246
246
  * @returns {string | number | Date | boolean | object | undefined} - The value from the object.
247
247
  */
248
248
  export function getFromObjWithStringPath(obj, path) {
249
+ if (!obj)
250
+ return undefined;
249
251
  const parts = path.split('.');
250
252
  let current = obj;
251
253
  for (let i = 0; i < parts.length; i++) {
@@ -301,6 +303,8 @@ export function getFromObjWithStringPath(obj, path) {
301
303
  * @returns {Record<keyof Infer<T>, (value: any) => boolean>} - The validators for each field.
302
304
  */
303
305
  export function getIndividualValidators(form) {
306
+ if (!form)
307
+ return {};
304
308
  const schema = form.schema;
305
309
  const fields = form.fields;
306
310
  if (!schema || !fields) {
@@ -1,4 +1,4 @@
1
- <script>import { setContext } from "svelte";
1
+ <script lang="ts">import { setContext } from "svelte";
2
2
  let { children } = $props();
3
3
  </script>
4
4
 
@@ -1,4 +1,4 @@
1
- <script>import { setContext } from "svelte";
1
+ <script lang="ts">import { setContext } from "svelte";
2
2
  let {
3
3
  children,
4
4
  fullWidth = false
@@ -1,4 +1,4 @@
1
- <script>import { setContext } from "svelte";
1
+ <script lang="ts">import { setContext } from "svelte";
2
2
  let {
3
3
  children,
4
4
  span = 12
@@ -1,3 +1,3 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" width="16" height="16" viewBox="0,0,256,256">
2
- <g fill="currentColor" transform="translate(7.98665,7.9375) scale(16,16)"><path d="M7.5,1.00781c-0.54297,0 -1.08594,0.25781 -1.39453,0.77344l-5.87891,9.82422c-0.625,1.03906 0.17578,2.39453 1.39063,2.39453h11.76172c1.21875,0 2.01953,-1.35547 1.39844,-2.39453l-5.88281,-9.82422c-0.30859,-0.51562 -0.85156,-0.77344 -1.39453,-0.77344zM7.5,1.99219c0.20703,0 0.41406,0.10156 0.53906,0.30469l5.87891,9.82031c0.24609,0.41016 -0.02734,0.88281 -0.53906,0.88281h-11.76172c-0.50781,0 -0.78125,-0.47266 -0.53516,-0.88281l5.87891,-9.82031c0.125,-0.20312 0.33203,-0.30469 0.53906,-0.30469zM6.99219,5v5h1v-5zM6.99219,11v1h1v-1z"></path></g>
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 16 16">
2
+ <path fill="currentColor" d="M7.999,1.063C7.419,1.063 6.84,1.339 6.51,1.889L0.232,12.38C-0.435,13.489 0.42,14.937 1.717,14.937L14.277,14.937C15.578,14.937 16.433,13.489 15.77,12.38L9.488,1.889C9.159,1.339 8.579,1.063 7.999,1.063ZM7.999,2.114C8.22,2.114 8.441,2.223 8.575,2.44L14.852,12.926C15.115,13.364 14.823,13.869 14.277,13.869L1.717,13.869C1.175,13.869 0.883,13.364 1.146,12.926L7.423,2.44C7.557,2.223 7.778,2.114 7.999,2.114ZM7.457,11.733L7.457,12.801L8.525,12.801L8.525,11.733L7.457,11.733ZM7.457,5.326L7.457,10.665L8.525,10.665L8.525,5.326L7.457,5.326Z" />
3
3
  </svg>