Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/lib/SchemaForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import set from "lodash-es/set";
import get from "lodash-es/get";
import { validator } from "@exodus/schemasafe";
import { FileNone, type CommonComponentParameters, type ValidationErrors } from './types/CommonComponentParameters';
import { FileNone, type CommonComponentParameters, type ValidationErrors, type SchemaFormEvent } from './types/CommonComponentParameters';
import Enum from './editors/Enum.svelte';
import Array from './editors/Array.svelte';
import { incr, nullOptionalsAllowed } from './utilities.js';
Expand All @@ -34,7 +34,9 @@
export let components: Record<string, new (...args: any[]) => any> = {};
export let componentContext: Record<string, unknown> = {};

const dispatch = createEventDispatcher();
const dispatch = createEventDispatcher<{
value: SchemaFormEvent
}>();

let validationErrors = {} as ValidationErrors;

Expand Down
6 changes: 3 additions & 3 deletions src/lib/SubmitForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<script lang="ts">
import SchemaForm from "./SchemaForm.svelte";
import { createEventDispatcher, setContext } from "svelte";
import { ProgressContext, type ValidationErrors } from "./types/CommonComponentParameters";
import { ProgressContext, type SchemaFormEvent, type ValidationErrors } from "./types/CommonComponentParameters";
import { substituteProperties } from "./utilities.js";
import { writable } from "svelte/store";
import set from "lodash-es/set";
Expand All @@ -21,14 +21,14 @@
export let submitRequiresDirty = true;
export let componentContext = {} as Record<string, unknown>;

const dispatch = createEventDispatcher();
const dispatch = createEventDispatcher<{value: SchemaFormEvent, submit: {value: any}}>();
let pathProgress = writable({} as Record<string, Record<string, number>>);
setContext(ProgressContext, pathProgress);

let currentErrors = {} as ValidationErrors;
let showErrors = false;

const change = (e: CustomEvent) => {
const change = (e: CustomEvent<SchemaFormEvent>) => {
currentErrors = e.detail.errors;
dispatch('value', e.detail);
value = e.detail.value;
Expand Down
8 changes: 8 additions & 0 deletions src/lib/types/CommonComponentParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ export interface CommonComponentParameters {
idx: number
}

export interface SchemaFormEvent {
path: string[],
value: any,
errors: ValidationErrors,
pathValue?: any,
op?: string
}

export const childComponentParameters = (params: CommonComponentParameters, propName: string) => {
return {
...params,
Expand Down