@texaryn/svelte 0.2.0 → 0.4.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # @texaryn/svelte
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 0ad9d1f: Moves optional integrations to the stable internal dependency lines while
8
+ keeping existing pre-stable dependent ranges on their previous minor versions.
9
+
10
+ ### Patch Changes
11
+
12
+ - Updated dependencies [aa0bc46]
13
+ - @texaryn/core@1.0.0
14
+
15
+ ## 0.3.0
16
+
17
+ ### Minor Changes
18
+
19
+ - 3e79b3e: FormRoot now renders the UI tree without creating a native form. Consumers own
20
+ the form element and connect its submit event to the runtime.
21
+ - 3e79b3e: Give every renderer one localized validation message contract and normalize
22
+ adapter parameters so built-in widgets do not display evaluator diagnostics.
23
+ - 3e79b3e: Make the form root error summary opt in, matching the other renderer bindings.
24
+
25
+ ### Patch Changes
26
+
27
+ - Updated dependencies [35cb55f]
28
+ - Updated dependencies [3e79b3e]
29
+ - @texaryn/core@0.16.0
30
+
3
31
  ## 0.2.0
4
32
 
5
33
  ### Minor Changes
package/README.md CHANGED
@@ -50,14 +50,26 @@ mount(App, {
50
50
  const form = createForm(adapter, { initialData: { name: '', age: 18 } })
51
51
  const data = form.data
52
52
  const registry = createDefaultRegistry()
53
+
54
+ function submit(event: SubmitEvent) {
55
+ event.preventDefault()
56
+ form.dispatch({ type: 'Submit' })
57
+ }
53
58
  </script>
54
59
 
55
- <FormRoot {form} {registry}>
56
- <h2>Data</h2>
57
- <pre>{JSON.stringify($data, null, 2)}</pre>
58
- </FormRoot>
60
+ <form novalidate onsubmit={submit}>
61
+ <FormRoot {form} {registry} showErrorSummary>
62
+ <h2>Data</h2>
63
+ <pre>{JSON.stringify($data, null, 2)}</pre>
64
+ </FormRoot>
65
+ <button type="submit">Submit</button>
66
+ </form>
59
67
  ```
60
68
 
69
+ `FormRoot` renders the tree only. The application owns the native `<form>` and
70
+ connects its submit event to the runtime, so the tree can also be composed
71
+ inside a larger form.
72
+
61
73
  `FormRoot` creates a server rendering safe id prefix with Svelte's component id
62
74
  unless `idPrefix` is provided. The prefix must be unique among forms rendered
63
75
  by the same component tree. `FormRoot` destroys the runtime when it unmounts by
@@ -22,7 +22,7 @@
22
22
  }
23
23
 
24
24
  function details(entry: VisibleError): string {
25
- return $messages.errorSummaryDetail({ messages: visibleErrorMessages(entry) })
25
+ return $messages.errorSummaryDetail({ messages: visibleErrorMessages(entry, $messages) })
26
26
  }
27
27
  </script>
28
28
 
@@ -32,7 +32,7 @@
32
32
  <ul>
33
33
  {#each $visibleErrors as entry (entry.nodeId)}
34
34
  <li>
35
- <a href={`#${makeId(context.idPrefix, entry.nodeId, 'input')}`}>{visibleErrorLabel(entry)}</a>
35
+ <a href={`#${makeId(context.idPrefix, entry.nodeId, 'input')}`}>{visibleErrorLabel(entry, $messages)}</a>
36
36
  {details(entry)}
37
37
  </li>
38
38
  {/each}
@@ -1,12 +1,14 @@
1
1
  <script lang="ts">
2
2
  import type { ValidationError } from '@texaryn/core'
3
+ import { useFormContext } from '../context.js'
3
4
 
4
5
  export let id: string
5
6
  export let errors: readonly ValidationError[] = []
7
+ const { messages } = useFormContext()
6
8
  </script>
7
9
 
8
10
  <div {id} aria-live="polite" aria-atomic="true">
9
11
  {#each errors as error, index (`${error.instancePointer}:${error.keyword}:${index}`)}
10
- <div>{error.message ?? error.keyword}</div>
12
+ <div>{$messages.validationMessage(error)}</div>
11
13
  {/each}
12
14
  </div>
@@ -1 +1 @@
1
- {"version":3,"file":"FieldErrors.svelte.d.ts","sourceRoot":"","sources":["../../src/lib/components/FieldErrors.svelte.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAiBrD,UAAU,kCAAkC,CAAC,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GA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AG,EAAE,EAAE,QAAQ,GAAG,MAAM;IACpM,KAAK,OAAO,EAAE,OAAO,QAAQ,EAAE,2BAA2B,CAAC,KAAK,CAAC,GAAG,OAAO,QAAQ,EAAE,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,GAAG;QAAE,UAAU,CAAC,EAAE,QAAQ,CAAA;KAAE,GAAG,OAAO,CAAC;IACjK,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,GAAG;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,KAAK,CAAA;KAAC,GAAG,OAAO,GAAG;QAAE,IAAI,CAAC,EAAE,GAAG,CAAC;QAAC,GAAG,CAAC,EAAE,GAAG,CAAA;KAAE,CAAC;IAC9G,YAAY,CAAC,EAAE,QAAQ,CAAC;CAC3B;AAKD,QAAA,MAAM,WAAW;QAViC,MAAM;aAAW,SAAS,eAAe,EAAE;;;kBAUG,CAAC;AAC/E,KAAK,WAAW,GAAG,YAAY,CAAC,OAAO,WAAW,CAAC,CAAC;AACtD,eAAe,WAAW,CAAC"}
@@ -17,6 +17,7 @@
17
17
  messages?: FormMessages
18
18
  idPrefix?: string
19
19
  destroyOnUnmount?: boolean
20
+ showErrorSummary?: boolean
20
21
  children?: Snippet
21
22
  }
22
23
 
@@ -26,6 +27,7 @@
26
27
  messages = englishMessages,
27
28
  idPrefix,
28
29
  destroyOnUnmount = true,
30
+ showErrorSummary = false,
29
31
  children,
30
32
  }: Props = $props()
31
33
 
@@ -81,18 +83,14 @@
81
83
  if (destroyOnUnmount) get(formStore).runtime.destroy()
82
84
  })
83
85
 
84
- function handleSubmit(event: SubmitEvent): void {
85
- event.preventDefault()
86
- currentForm.dispatch({ type: 'Submit' })
87
- }
88
86
  </script>
89
87
 
90
- <form onsubmit={handleSubmit}>
88
+ {#if showErrorSummary}
91
89
  {#key $runtime}
92
90
  <ErrorSummary />
93
91
  {/key}
94
- {#if rootNode}
95
- <NodeRenderer node={rootNode} />
96
- {/if}
97
- {@render children?.()}
98
- </form>
92
+ {/if}
93
+ {#if rootNode}
94
+ <NodeRenderer node={rootNode} />
95
+ {/if}
96
+ {@render children?.()}
@@ -8,6 +8,7 @@ interface Props {
8
8
  messages?: FormMessages;
9
9
  idPrefix?: string;
10
10
  destroyOnUnmount?: boolean;
11
+ showErrorSummary?: boolean;
11
12
  children?: Snippet;
12
13
  }
13
14
  declare const FormRoot: import("svelte").Component<Props, {}, "">;
@@ -1 +1 @@
1
- {"version":3,"file":"FormRoot.svelte.d.ts","sourceRoot":"","sources":["../../src/lib/components/FormRoot.svelte.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAErC,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAU,MAAM,eAAe,CAAA;AAE3E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAOjD,UAAU,KAAK;IACb,IAAI,EAAE,iBAAiB,CAAA;IACvB,QAAQ,CAAC,EAAE,gBAAgB,CAAC,eAAe,CAAC,CAAA;IAC5C,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AA8FH,QAAA,MAAM,QAAQ,2CAAwC,CAAC;AACvD,KAAK,QAAQ,GAAG,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC;AAC5C,eAAe,QAAQ,CAAC"}
1
+ {"version":3,"file":"FormRoot.svelte.d.ts","sourceRoot":"","sources":["../../src/lib/components/FormRoot.svelte.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAErC,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAU,MAAM,eAAe,CAAA;AAE3E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAOjD,UAAU,KAAK;IACb,IAAI,EAAE,iBAAiB,CAAA;IACvB,QAAQ,CAAC,EAAE,gBAAgB,CAAC,eAAe,CAAC,CAAA;IAC5C,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AA2FH,QAAA,MAAM,QAAQ,2CAAwC,CAAC;AACvD,KAAK,QAAQ,GAAG,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC;AAC5C,eAAe,QAAQ,CAAC"}
@@ -1,4 +1,4 @@
1
- import type { FieldNode, ValidationError } from '@texaryn/core';
1
+ import type { FieldNode, FormMessages, ValidationError } from '@texaryn/core';
2
2
  export interface FieldAria {
3
3
  id: string;
4
4
  name: string;
@@ -16,5 +16,5 @@ export declare function fieldAria(node: FieldNode, state: {
16
16
  showErrors: boolean;
17
17
  errors: readonly ValidationError[];
18
18
  }, idPrefix: string, nativeReadOnly?: boolean): FieldAria;
19
- export declare function fieldLabel(node: FieldNode): string;
19
+ export declare function fieldLabel(node: FieldNode, messages?: FormMessages): string;
20
20
  //# sourceMappingURL=field-props.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"field-props.d.ts","sourceRoot":"","sources":["../src/lib/field-props.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAE/D,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,OAAO,CAAA;IACjB,QA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,SAAS,CACvB,IAAI,EAAE,SAAS,EACf,KAAK,EAAE;IAAE,QAAQ,EAAE,OAAO,CAAC;IAAC,UAAU,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,SAAS,eAAe,EAAE,CAAA;CAAE,EACrF,QAAQ,EAAE,MAAM,EAChB,cAAc,UAAO,GACpB,SAAS,CAyBX;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,GAAE,YAA8B,GAAG,MAAM,CAE5F"}
@@ -1,3 +1,4 @@
1
+ import { englishMessages, visibleFieldLabel } from '@texaryn/core';
1
2
  export function makeId(idPrefix, nodeId, suffix) {
2
3
  return `${idPrefix}-${nodeId}-${suffix}`;
3
4
  }
@@ -25,6 +26,6 @@ export function fieldAria(node, state, idPrefix, nativeReadOnly = true) {
25
26
  placeholder: node.placeholder ?? undefined,
26
27
  };
27
28
  }
28
- export function fieldLabel(node) {
29
- return node.annotations.title ?? node.dataPointer ?? node.id;
29
+ export function fieldLabel(node, messages = englishMessages) {
30
+ return visibleFieldLabel(node.annotations.title, node.dataPointer, messages);
30
31
  }
package/dist/field.js CHANGED
@@ -25,7 +25,7 @@ export function createFieldBinding(form, nodeId, idPrefix, messages) {
25
25
  const kind = derived(node, ($node) => fieldKind($node));
26
26
  const visibleErrors = derived([showErrors, errors], ([$showErrors, $errors]) => $showErrors ? $errors : NO_ERRORS);
27
27
  const display = derived([kind, value], ([$kind, $value]) => displayValue($kind, $value));
28
- const label = derived(node, ($node) => $node ? fieldLabel($node) : '');
28
+ const label = derived([node, messages], ([$node, $messages]) => $node ? fieldLabel($node, $messages) : '');
29
29
  const description = derived(node, ($node) => $node?.helpText ?? $node?.annotations.description);
30
30
  const labelFor = derived(node, ($node) => makeId(idPrefix, $node?.id ?? get(nodeId), 'input'));
31
31
  const descriptionId = derived(node, ($node) => makeId(idPrefix, $node?.id ?? get(nodeId), 'description'));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@texaryn/svelte",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "Svelte 5 bindings, renderer, and default widgets for Texaryn",
5
5
  "keywords": [
6
6
  "svelte",
@@ -46,7 +46,7 @@
46
46
  "LICENSE"
47
47
  ],
48
48
  "dependencies": {
49
- "@texaryn/core": "^0.15.0"
49
+ "@texaryn/core": "^1.0.0"
50
50
  },
51
51
  "peerDependencies": {
52
52
  "svelte": ">=5.20.0"