From 10737c82a34b872b3ea1ff0461dcff8a3d5aa196 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 11 Mar 2025 12:24:25 +0100 Subject: [PATCH] Move types around --- .../src/components/app/forms/Field.svelte | 3 +- .../app/forms/RelationshipField.svelte | 3 +- .../client/src/components/app/forms/index.ts | 13 ---- packages/client/src/context.d.ts | 5 +- packages/client/src/index.ts | 61 +------------------ packages/client/src/types/components.ts | 9 +++ packages/client/src/types/fields.ts | 3 + packages/client/src/types/forms.ts | 37 +++++++++++ packages/client/src/types/index.ts | 4 ++ packages/client/src/types/sdk.ts | 24 ++++++++ 10 files changed, 83 insertions(+), 79 deletions(-) create mode 100644 packages/client/src/types/components.ts create mode 100644 packages/client/src/types/fields.ts create mode 100644 packages/client/src/types/forms.ts create mode 100644 packages/client/src/types/index.ts create mode 100644 packages/client/src/types/sdk.ts diff --git a/packages/client/src/components/app/forms/Field.svelte b/packages/client/src/components/app/forms/Field.svelte index f200303c8a..03e88f7dbd 100644 --- a/packages/client/src/components/app/forms/Field.svelte +++ b/packages/client/src/components/app/forms/Field.svelte @@ -6,9 +6,8 @@ import { memo } from "@budibase/frontend-core" import Placeholder from "../Placeholder.svelte" import InnerForm from "./InnerForm.svelte" - import type { FieldApi, FieldState } from "." import type { FieldSchema, FieldType } from "@budibase/types" - import type { FieldValidation, FormField } from "@/index" + import { FieldApi, FieldState, FieldValidation, FormField } from "@/types" interface FieldInfo { field: string diff --git a/packages/client/src/components/app/forms/RelationshipField.svelte b/packages/client/src/components/app/forms/RelationshipField.svelte index 4a595e3094..b5906b72fa 100644 --- a/packages/client/src/components/app/forms/RelationshipField.svelte +++ b/packages/client/src/components/app/forms/RelationshipField.svelte @@ -9,8 +9,7 @@ RelationshipFieldMetadata, Row, } from "@budibase/types" - import type { FieldApi, FieldState } from "." - import type { FieldValidation } from "@/index" + import type { FieldApi, FieldState, FieldValidation } from "@/types" type ValueType = string | string[] diff --git a/packages/client/src/components/app/forms/index.ts b/packages/client/src/components/app/forms/index.ts index 10edb73859..391b5fa19f 100644 --- a/packages/client/src/components/app/forms/index.ts +++ b/packages/client/src/components/app/forms/index.ts @@ -19,16 +19,3 @@ export { default as codescanner } from "./CodeScannerField.svelte" export { default as signaturesinglefield } from "./SignatureField.svelte" export { default as bbreferencefield } from "./BBReferenceField.svelte" export { default as bbreferencesinglefield } from "./BBReferenceSingleField.svelte" - -export interface FieldApi { - setValue(value: any): boolean - deregister(): void -} - -export interface FieldState { - value: T - fieldId: string - disabled: boolean - readonly: boolean - error?: string -} diff --git a/packages/client/src/context.d.ts b/packages/client/src/context.d.ts index 6a8d0c2514..3aa2613eef 100644 --- a/packages/client/src/context.d.ts +++ b/packages/client/src/context.d.ts @@ -1,10 +1,11 @@ import { Writable } from "svelte" -import { Component, Context, FieldGroupContext, FormContext, SDK } from "." +import { Component, FieldGroupContext, FormContext, SDK } from "@/types" +import { Readable } from "svelte/store" declare module "svelte" { export function getContext(key: "sdk"): SDK export function getContext(key: "component"): Component - export function getContext(key: "context"): Context + export function getContext(key: "context"): Readable> export function getContext(key: "form"): FormContext | undefined export function getContext(key: "form-step"): Writable | undefined export function getContext(key: "field-group"): FieldGroupContext | undefined diff --git a/packages/client/src/index.ts b/packages/client/src/index.ts index 7f16222cdf..8e8ba53f00 100644 --- a/packages/client/src/index.ts +++ b/packages/client/src/index.ts @@ -14,8 +14,6 @@ import { } from "@/stores" import { get } from "svelte/store" import { initWebsocket } from "@/websocket" -import { APIClient } from "@budibase/frontend-core" -import type { ActionTypes } from "@/constants" import { Readable } from "svelte/store" import { Screen, @@ -27,8 +25,6 @@ import { Snippet, UIComponentError, CustomComponent, - FieldType, - FieldSchema, } from "@budibase/types" // Provide svelte and svelte/internal as globals for custom components @@ -41,7 +37,7 @@ window.svelte = svelte // Initialise spectrum icons // eslint-disable-next-line local-rules/no-budibase-imports import loadSpectrumIcons from "@budibase/bbui/spectrum-icons-vite.js" -import { FieldApi, FieldState } from "./components/app" + loadSpectrumIcons() // Extend global window scope @@ -76,63 +72,8 @@ declare global { } } -export interface SDK { - API: APIClient - styleable: any - Provider: any - ActionTypes: typeof ActionTypes - fetchDatasourceSchema: any - generateGoldenSample: any - builderStore: Readable<{ - inBuilder: boolean - }> & { - actions: { - highlightSetting: (key: string) => void - addParentComponent: ( - componentId: string, - fullAncestorType: string - ) => void - updateProp: (key: string, value: any) => void - } - } -} - -export type Component = Readable<{ - id: string - name: string - styles: any - editing: boolean - errorState: boolean -}> - export type Context = Readable> -export interface FormContext { - formApi?: { - registerField: ( - field: string, - type: FieldType, - defaultValue: string | undefined, - disabled: boolean, - readonly: boolean, - validation: FieldValidation | undefined, - formStep: number - ) => Readable - } -} - -export type FieldValidation = () => string | undefined - -export interface FormField { - fieldState: FieldState - fieldApi: FieldApi - fieldSchema: FieldSchema -} - -export interface FieldGroupContext { - labelPosition: string -} - let app: ClientApp const loadBudibase = async () => { diff --git a/packages/client/src/types/components.ts b/packages/client/src/types/components.ts new file mode 100644 index 0000000000..45496abee8 --- /dev/null +++ b/packages/client/src/types/components.ts @@ -0,0 +1,9 @@ +import { Readable } from "svelte/store" + +export type Component = Readable<{ + id: string + name: string + styles: any + editing: boolean + errorState: boolean +}> diff --git a/packages/client/src/types/fields.ts b/packages/client/src/types/fields.ts new file mode 100644 index 0000000000..e2dfba2b10 --- /dev/null +++ b/packages/client/src/types/fields.ts @@ -0,0 +1,3 @@ +export interface FieldGroupContext { + labelPosition: string +} diff --git a/packages/client/src/types/forms.ts b/packages/client/src/types/forms.ts new file mode 100644 index 0000000000..cc63326d06 --- /dev/null +++ b/packages/client/src/types/forms.ts @@ -0,0 +1,37 @@ +import { Readable } from "svelte/store" +import { FieldSchema, FieldType } from "@budibase/types" + +export interface FormContext { + formApi?: { + registerField: ( + field: string, + type: FieldType, + defaultValue: string | undefined, + disabled: boolean, + readonly: boolean, + validation: FieldValidation | undefined, + formStep: number + ) => Readable + } +} + +export type FieldValidation = () => string | undefined + +export interface FormField { + fieldState: FieldState + fieldApi: FieldApi + fieldSchema: FieldSchema +} + +export interface FieldApi { + setValue(value: any): boolean + deregister(): void +} + +export interface FieldState { + value: T + fieldId: string + disabled: boolean + readonly: boolean + error?: string +} diff --git a/packages/client/src/types/index.ts b/packages/client/src/types/index.ts new file mode 100644 index 0000000000..2ad1ccdd38 --- /dev/null +++ b/packages/client/src/types/index.ts @@ -0,0 +1,4 @@ +export * from "./components" +export * from "./fields" +export * from "./forms" +export * from "./sdk" diff --git a/packages/client/src/types/sdk.ts b/packages/client/src/types/sdk.ts new file mode 100644 index 0000000000..e3c536e80e --- /dev/null +++ b/packages/client/src/types/sdk.ts @@ -0,0 +1,24 @@ +import { ActionTypes } from "@/constants" +import { APIClient } from "@budibase/frontend-core" +import { Readable } from "svelte/store" + +export interface SDK { + API: APIClient + styleable: any + Provider: any + ActionTypes: typeof ActionTypes + fetchDatasourceSchema: any + generateGoldenSample: any + builderStore: Readable<{ + inBuilder: boolean + }> & { + actions: { + highlightSetting: (key: string) => void + addParentComponent: ( + componentId: string, + fullAncestorType: string + ) => void + updateProp: (key: string, value: any) => void + } + } +}