|
6 | 6 | import Button, { Label as BtnLabel } from "@smui/button"
|
7 | 7 | import Textfield from '@smui/textfield';
|
8 | 8 | import Snackbar, { Label as SBLabel, Actions } from '@smui/snackbar';
|
9 |
| - import SchemaForm, { type ValidationError } from "$lib"; |
| 9 | + import SchemaForm, { ValidationError } from "$lib"; |
10 | 10 | import schemas, { type TestSchema } from "../schemas";
|
11 | 11 |
|
12 | 12 | import type UISchema from "$lib/UISchema";
|
|
18 | 18 | let schemaString = "";
|
19 | 19 | let uischemaString = "";
|
20 | 20 | let dataString = "";
|
21 |
| - let validationError: ValidationError | null = null; |
| 21 | + let schemaError: Error | ValidationError | null = null; |
22 | 22 |
|
23 | 23 | let schemaForm: SchemaForm;
|
24 | 24 | let errorSnackbar: Snackbar;
|
|
27 | 27 | $: setSchemaString(schema);
|
28 | 28 | $: setUISchemaString(uischema);
|
29 | 29 | $: setDataString(data);
|
30 |
| - $: if (validationError != null) errorSnackbar.open(); |
| 30 | + $: if (schemaError != null) errorSnackbar.open(); |
31 | 31 |
|
32 | 32 | async function setSchemaString(schema: TestSchema["schema"]) {
|
33 | 33 | await tick();
|
|
87 | 87 | try {
|
88 | 88 | schemaForm.download();
|
89 | 89 | } catch (error) {
|
90 |
| - validationError = error as ValidationError; |
| 90 | + schemaError = error as Error; |
91 | 91 | }
|
92 | 92 | }
|
93 | 93 | </script>
|
|
98 | 98 | <Label>{tab.name}</Label>
|
99 | 99 | </Tab>
|
100 | 100 | </TabBar>
|
101 |
| - <SchemaForm {schema} {uischema} bind:data bind:this={schemaForm}> |
| 101 | + <SchemaForm {schema} {uischema} bind:data bind:this={schemaForm} on:error={(event) => schemaError = event.detail}> |
102 | 102 | <Button on:click={download} type="button" variant="raised">
|
103 | 103 | <BtnLabel>Download</BtnLabel>
|
104 | 104 | </Button>
|
105 | 105 | </SchemaForm>
|
106 | 106 |
|
107 | 107 | <Snackbar class="schema-error" bind:this={errorSnackbar}>
|
108 | 108 | <SBLabel>
|
109 |
| - {#if validationError} |
110 |
| - {validationError.message} |
111 |
| - <ul> |
112 |
| - {#each validationError.errors as error} |
113 |
| - <li>{error.message}</li> |
114 |
| - {/each} |
115 |
| - </ul> |
| 109 | + {#if schemaError} |
| 110 | + {schemaError.message} |
| 111 | + {#if schemaError instanceof ValidationError} |
| 112 | + <ul> |
| 113 | + {#each schemaError.errors as error} |
| 114 | + <li>{error.message}</li> |
| 115 | + {/each} |
| 116 | + </ul> |
| 117 | + {/if} |
116 | 118 | {:else}
|
117 | 119 | Unknown error
|
118 | 120 | {/if}
|
|
0 commit comments