Skip to content

Commit 74e1ba9

Browse files
committed
add SchemaFormEvent type
1 parent 5092809 commit 74e1ba9

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

src/lib/SchemaForm.svelte

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import set from "lodash-es/set";
1010
import get from "lodash-es/get";
1111
import { validator } from "@exodus/schemasafe";
12-
import { FileNone, type CommonComponentParameters, type ValidationErrors } from './types/CommonComponentParameters';
12+
import { FileNone, type CommonComponentParameters, type ValidationErrors, type SchemaFormEvent } from './types/CommonComponentParameters';
1313
import Enum from './editors/Enum.svelte';
1414
import Array from './editors/Array.svelte';
1515
import { incr, nullOptionalsAllowed } from './utilities.js';
@@ -34,7 +34,9 @@
3434
export let components: Record<string, new (...args: any[]) => any> = {};
3535
export let componentContext: Record<string, unknown> = {};
3636
37-
const dispatch = createEventDispatcher();
37+
const dispatch = createEventDispatcher<{
38+
value: SchemaFormEvent
39+
}>();
3840
3941
let validationErrors = {} as ValidationErrors;
4042

src/lib/SubmitForm.svelte

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<script lang="ts">
44
import SchemaForm from "./SchemaForm.svelte";
55
import { createEventDispatcher, setContext } from "svelte";
6-
import { ProgressContext, type ValidationErrors } from "./types/CommonComponentParameters";
6+
import { ProgressContext, type SchemaFormEvent, type ValidationErrors } from "./types/CommonComponentParameters";
77
import { substituteProperties } from "./utilities.js";
88
import { writable } from "svelte/store";
99
import set from "lodash-es/set";
@@ -21,14 +21,14 @@
2121
export let submitRequiresDirty = true;
2222
export let componentContext = {} as Record<string, unknown>;
2323
24-
const dispatch = createEventDispatcher();
24+
const dispatch = createEventDispatcher<{value: SchemaFormEvent, submit: {value: any}}>();
2525
let pathProgress = writable({} as Record<string, Record<string, number>>);
2626
setContext(ProgressContext, pathProgress);
2727
2828
let currentErrors = {} as ValidationErrors;
2929
let showErrors = false;
3030
31-
const change = (e: CustomEvent) => {
31+
const change = (e: CustomEvent<SchemaFormEvent>) => {
3232
currentErrors = e.detail.errors;
3333
dispatch('value', e.detail);
3434
value = e.detail.value;

src/lib/types/CommonComponentParameters.ts

+8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ export interface CommonComponentParameters {
1818
idx: number
1919
}
2020

21+
export interface SchemaFormEvent {
22+
path: string[],
23+
value: any,
24+
errors: ValidationErrors,
25+
pathValue?: any,
26+
op?: string
27+
}
28+
2129
export const childComponentParameters = (params: CommonComponentParameters, propName: string) => {
2230
return {
2331
...params,

0 commit comments

Comments
 (0)