@axium/client 0.23.2 → 0.23.4

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,7 +1,7 @@
1
1
  <script lang="ts">
2
- import { text } from '@axium/client';
2
+ import { text, type ReplacementOptions } from '@axium/client';
3
3
  import type { ZodPref } from '@axium/core';
4
- import { zKeys } from '@axium/core/locales';
4
+ import { zKeys, type ZodLocaleInfo } from '@axium/core/locales';
5
5
  import type { HTMLInputAttributes } from 'svelte/elements';
6
6
  import { getByString, pick, setByString } from 'utilium';
7
7
  import { prettifyError } from 'zod';
@@ -10,6 +10,7 @@
10
10
 
11
11
  interface Props {
12
12
  idPrefix?: string;
13
+ localeInfo?: ZodLocaleInfo;
13
14
  rootValue: any;
14
15
  path: string;
15
16
  label?: string;
@@ -24,7 +25,19 @@
24
25
 
25
26
  let { rootValue = $bindable(), ...props }: Props = $props();
26
27
 
27
- let { label, path, schema, _parseSchema = schema, optional, readonly, defaultValue, idPrefix, updateValue, noLabel } = props;
28
+ let {
29
+ label,
30
+ path,
31
+ schema,
32
+ _parseSchema = schema,
33
+ optional,
34
+ readonly,
35
+ defaultValue,
36
+ idPrefix,
37
+ updateValue,
38
+ noLabel,
39
+ localeInfo = zKeys.get(schema),
40
+ } = props;
28
41
 
29
42
  const id = (idPrefix ? idPrefix + ':' : '') + path.replaceAll(' ', '_');
30
43
 
@@ -86,7 +99,13 @@
86
99
 
87
100
  const oninput = onchange;
88
101
 
89
- const labelText = $derived(zKeys.has(props.schema) ? text(zKeys.get(props.schema)!.key) : label || path);
102
+ /** Localize text for a given field in the current schema */
103
+ function subText(name: string, replacements?: ReplacementOptions & Record<string, any>) {
104
+ if (!localeInfo?.prefix) return;
105
+ return text(`${localeInfo.prefix}.${name}`, replacements);
106
+ }
107
+
108
+ const labelText = $derived(localeInfo?.key ? text(localeInfo.key) : label || path);
90
109
  const placeholder = noLabel == 'placeholder' ? labelText : undefined;
91
110
 
92
111
  /** Array element types that indicate the array should put elements on their own lines */
@@ -138,22 +157,29 @@
138
157
  <div class="ZodInput">
139
158
  <label for={id}>{labelText}</label>
140
159
  <select bind:value {id} {oninput} required={!optional}>
141
- {#each schema.values as value}
142
- <option {value} selected={value === value}>{value}</option>
160
+ {#each schema.values as literal}
161
+ <option value={literal} selected={value === literal}>{subText(String(literal), { $default: String(literal) })}</option>
143
162
  {/each}
144
163
  </select>
145
164
  </div>
146
165
  {:else if schema.type == 'template_literal'}
147
166
  <!-- todo -->
148
167
  {:else if schema.type == 'readonly'}
149
- <ZodInput bind:rootValue {...props} label={labelText} schema={schema.def.innerType} readonly />
168
+ <ZodInput bind:rootValue {...props} {localeInfo} label={labelText} schema={schema.def.innerType} readonly />
150
169
  {:else if schema.type == 'default'}
151
- <ZodInput bind:rootValue {...props} label={labelText} schema={schema.def.innerType} defaultValue={schema.def.defaultValue} />
170
+ <ZodInput
171
+ bind:rootValue
172
+ {...props}
173
+ {localeInfo}
174
+ label={labelText}
175
+ schema={schema.def.innerType}
176
+ defaultValue={schema.def.defaultValue}
177
+ />
152
178
  {:else if schema.type == 'nullable' || schema.type == 'optional'}
153
179
  <!-- defaults are handled differently -->
154
- <ZodInput bind:rootValue {...props} label={labelText} schema={schema.def.innerType} optional={true} />
180
+ <ZodInput bind:rootValue {...props} {localeInfo} label={labelText} schema={schema.def.innerType} optional={true} />
155
181
  {:else if schema.type == 'nonoptional'}
156
- <ZodInput bind:rootValue {...props} label={labelText} schema={schema.def.innerType} optional={false} />
182
+ <ZodInput bind:rootValue {...props} {localeInfo} label={labelText} schema={schema.def.innerType} optional={false} />
157
183
  {:else if schema.type == 'array'}
158
184
  <div class="ZodInput">
159
185
  {#if !noLabel}<label for={id}>{labelText}</label>{/if}
@@ -191,7 +217,7 @@
191
217
  {:else if schema.type == 'object'}
192
218
  <!-- <div class="ZodInput-object"> -->
193
219
  {#each Object.entries(schema.shape) as [key, value]}
194
- <ZodInput bind:rootValue {updateValue} {idPrefix} {noLabel} path="{path}.{key}" schema={value} />
220
+ <ZodInput bind:rootValue {updateValue} {idPrefix} {noLabel} path="{path}.{key}" schema={value} label={subText(key)} />
195
221
  {/each}
196
222
  <!-- </div> -->
197
223
  {:else if schema.type == 'tuple'}
@@ -205,8 +231,8 @@
205
231
  {#if !noLabel}<label for={id}>{labelText}</label>{/if}
206
232
  {#if error}<span class="ZodInput-error">{error}</span>{/if}
207
233
  <select {id} {onchange} bind:value required={!optional}>
208
- {#each Object.entries(schema.enum) as [key, value]}
209
- <option {value} selected={value === value}>{key}</option>
234
+ {#each Object.entries(schema.enum) as [name, enumValue]}
235
+ <option value={enumValue} selected={value === enumValue}>{subText(name, { $default: name })}</option>
210
236
  {/each}
211
237
  </select>
212
238
  </div>
@@ -102,7 +102,6 @@ export function contextMenu(...menuItems: (ContextMenuItem | false | null | unde
102
102
  export function dynamicRows(max: number = 40, min: number = 3): Attachment<HTMLTextAreaElement> {
103
103
  return function _attachDynamicRows(element: HTMLTextAreaElement) {
104
104
  element.style.resize = 'none';
105
- // @ts-expect-error field-sizing is not yet in the types
106
105
  element.style.fieldSizing = 'content';
107
106
  element.style.height = 'max-content';
108
107
  element.style.overflowY = 'scroll';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axium/client",
3
- "version": "0.23.2",
3
+ "version": "0.23.4",
4
4
  "author": "James Prevett <jp@jamespre.dev>",
5
5
  "funding": {
6
6
  "type": "individual",
@@ -45,7 +45,7 @@
45
45
  "build": "tsc"
46
46
  },
47
47
  "peerDependencies": {
48
- "@axium/core": ">=0.26.0",
48
+ "@axium/core": ">=0.27.1",
49
49
  "svelte": "^5.36.0",
50
50
  "utilium": "^3.0.0",
51
51
  "zod": "^4.0.5"