@axium/client 0.12.0 → 0.12.2
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/lib/Popover.svelte +4 -1
- package/lib/ZodInput.svelte +66 -29
- package/package.json +1 -1
package/lib/Popover.svelte
CHANGED
package/lib/ZodInput.svelte
CHANGED
|
@@ -14,13 +14,23 @@
|
|
|
14
14
|
schema: ZodPref;
|
|
15
15
|
defaultValue?: any;
|
|
16
16
|
optional?: boolean;
|
|
17
|
+
noLabel?: boolean;
|
|
17
18
|
updateValue(value: any): void;
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
let {
|
|
21
|
+
let {
|
|
22
|
+
rootValue = $bindable(),
|
|
23
|
+
label,
|
|
24
|
+
path,
|
|
25
|
+
schema,
|
|
26
|
+
optional = false,
|
|
27
|
+
defaultValue,
|
|
28
|
+
idPrefix,
|
|
29
|
+
updateValue,
|
|
30
|
+
noLabel = false,
|
|
31
|
+
}: Props = $props();
|
|
21
32
|
const id = (idPrefix ? idPrefix + ':' : '') + path.replaceAll(' ', '_');
|
|
22
33
|
|
|
23
|
-
let input = $state<HTMLInputElement | HTMLSelectElement>()!;
|
|
24
34
|
let value = $state<any>(getByString(rootValue, path));
|
|
25
35
|
|
|
26
36
|
let error = $state();
|
|
@@ -82,19 +92,9 @@
|
|
|
82
92
|
|
|
83
93
|
{#snippet _in(rest: HTMLInputAttributes)}
|
|
84
94
|
<div class="ZodInput">
|
|
85
|
-
<label for={id}>{label || path}</label>
|
|
95
|
+
{#if !noLabel}<label for={id}>{label || path}</label>{/if}
|
|
86
96
|
{#if error}<span class="ZodInput-error error-text">{error}</span>{/if}
|
|
87
|
-
<input
|
|
88
|
-
bind:this={input}
|
|
89
|
-
{id}
|
|
90
|
-
{...rest}
|
|
91
|
-
bind:value
|
|
92
|
-
{onchange}
|
|
93
|
-
{onkeyup}
|
|
94
|
-
required={!optional}
|
|
95
|
-
{defaultValue}
|
|
96
|
-
class={[error && 'error']}
|
|
97
|
-
/>
|
|
97
|
+
<input {id} {...rest} bind:value {onchange} {onkeyup} required={!optional} {defaultValue} class={[error && 'error']} />
|
|
98
98
|
</div>
|
|
99
99
|
{/snippet}
|
|
100
100
|
|
|
@@ -106,8 +106,8 @@
|
|
|
106
106
|
{@render _in({ type: 'number', min: Number(schema.minValue), max: Number(schema.maxValue), step: 1 })}
|
|
107
107
|
{:else if schema.type == 'boolean'}
|
|
108
108
|
<div class="ZodInput">
|
|
109
|
-
<label for="{id}:checkbox">{label || path}</label>
|
|
110
|
-
<input bind:checked={value}
|
|
109
|
+
{#if !noLabel}<label for="{id}:checkbox">{label || path}</label>{/if}
|
|
110
|
+
<input bind:checked={value} id="{id}:checkbox" type="checkbox" {onchange} {onkeyup} required={!optional} />
|
|
111
111
|
<label for="{id}:checkbox" {id} class="checkbox">
|
|
112
112
|
{#if value}<Icon i="check" --size="1.3em" />{/if}
|
|
113
113
|
</label>
|
|
@@ -123,7 +123,7 @@
|
|
|
123
123
|
{:else if schema.type == 'literal'}
|
|
124
124
|
<div class="ZodInput">
|
|
125
125
|
<label for={id}>{label || path}</label>
|
|
126
|
-
<select bind:
|
|
126
|
+
<select bind:value {id} {onchange} {onkeyup} required={!optional}>
|
|
127
127
|
{#each schema.values as value}
|
|
128
128
|
<option {value} selected={value === value}>{value}</option>
|
|
129
129
|
{/each}
|
|
@@ -138,20 +138,40 @@
|
|
|
138
138
|
<ZodInput bind:rootValue {updateValue} {idPrefix} {path} {defaultValue} schema={schema.def.innerType} optional={true} />
|
|
139
139
|
{:else if schema.type == 'array'}
|
|
140
140
|
<div class="ZodInput">
|
|
141
|
-
<label for={id}>{label || path}</label>
|
|
142
|
-
{#
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
141
|
+
{#if !noLabel}<label for={id}>{label || path}</label>{/if}
|
|
142
|
+
{#if error}<span class="ZodInput-error error-text">{error}</span>{/if}
|
|
143
|
+
<div class="ZodInput-array">
|
|
144
|
+
{#each value, i}
|
|
145
|
+
<div class="ZodInput-element">
|
|
146
|
+
<input
|
|
147
|
+
id="{id}.{i}"
|
|
148
|
+
bind:value={value[i]}
|
|
149
|
+
{onchange}
|
|
150
|
+
{onkeyup}
|
|
151
|
+
required={!optional}
|
|
152
|
+
{defaultValue}
|
|
153
|
+
class={[error && 'error']}
|
|
154
|
+
/>
|
|
155
|
+
<button
|
|
156
|
+
onclick={e => {
|
|
157
|
+
value.splice(i, 1);
|
|
158
|
+
onchange(e);
|
|
159
|
+
}}
|
|
160
|
+
>
|
|
161
|
+
<Icon i="trash" --size="16px" />
|
|
162
|
+
</button>
|
|
163
|
+
</div>
|
|
164
|
+
{/each}
|
|
165
|
+
<button onclick={() => value.push('')}>
|
|
166
|
+
<Icon i="plus" --size="16px" />
|
|
167
|
+
</button>
|
|
168
|
+
</div>
|
|
149
169
|
</div>
|
|
150
170
|
{:else if schema.type == 'record'}
|
|
151
171
|
<div class="ZodInput-record">
|
|
152
172
|
{#each Object.keys(value) as key}
|
|
153
173
|
<div class="ZodInput-record-entry">
|
|
154
|
-
<label for={id}>{key}</label>
|
|
174
|
+
{#if !noLabel}<label for={id}>{key}</label>{/if}
|
|
155
175
|
<ZodInput bind:rootValue {updateValue} {idPrefix} {defaultValue} path="{path}.{key}" schema={schema.valueType} />
|
|
156
176
|
</div>
|
|
157
177
|
{/each}
|
|
@@ -170,8 +190,9 @@
|
|
|
170
190
|
</div>
|
|
171
191
|
{:else if schema.type == 'enum'}
|
|
172
192
|
<div class="ZodInput">
|
|
173
|
-
<label for={id}>{label || path}</label>
|
|
174
|
-
|
|
193
|
+
{#if !noLabel}<label for={id}>{label || path}</label>{/if}
|
|
194
|
+
{#if error}<span class="ZodInput-error error-text">{error}</span>{/if}
|
|
195
|
+
<select {id} {onchange} {onkeyup} bind:value required={!optional}>
|
|
175
196
|
{#each Object.entries(schema.enum) as [key, value]}
|
|
176
197
|
<option {value} selected={value === value}>{key}</option>
|
|
177
198
|
{/each}
|
|
@@ -216,9 +237,25 @@
|
|
|
216
237
|
}
|
|
217
238
|
}
|
|
218
239
|
|
|
240
|
+
.ZodInput-element {
|
|
241
|
+
display: flex;
|
|
242
|
+
gap: 0.5em;
|
|
243
|
+
align-items: center;
|
|
244
|
+
|
|
245
|
+
button {
|
|
246
|
+
position: relative;
|
|
247
|
+
right: 1em;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
.ZodInput-array {
|
|
252
|
+
display: flex;
|
|
253
|
+
gap: 0.5em;
|
|
254
|
+
align-items: center;
|
|
255
|
+
}
|
|
256
|
+
|
|
219
257
|
.ZodInput-object,
|
|
220
258
|
.ZodInput-record,
|
|
221
|
-
.ZodInput-array,
|
|
222
259
|
.ZodInput-tuple {
|
|
223
260
|
display: flex;
|
|
224
261
|
flex-direction: column;
|