Move types around
This commit is contained in:
parent
482bc98715
commit
10737c82a3
|
@ -6,9 +6,8 @@
|
||||||
import { memo } from "@budibase/frontend-core"
|
import { memo } from "@budibase/frontend-core"
|
||||||
import Placeholder from "../Placeholder.svelte"
|
import Placeholder from "../Placeholder.svelte"
|
||||||
import InnerForm from "./InnerForm.svelte"
|
import InnerForm from "./InnerForm.svelte"
|
||||||
import type { FieldApi, FieldState } from "."
|
|
||||||
import type { FieldSchema, FieldType } from "@budibase/types"
|
import type { FieldSchema, FieldType } from "@budibase/types"
|
||||||
import type { FieldValidation, FormField } from "@/index"
|
import { FieldApi, FieldState, FieldValidation, FormField } from "@/types"
|
||||||
|
|
||||||
interface FieldInfo {
|
interface FieldInfo {
|
||||||
field: string
|
field: string
|
||||||
|
|
|
@ -9,8 +9,7 @@
|
||||||
RelationshipFieldMetadata,
|
RelationshipFieldMetadata,
|
||||||
Row,
|
Row,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import type { FieldApi, FieldState } from "."
|
import type { FieldApi, FieldState, FieldValidation } from "@/types"
|
||||||
import type { FieldValidation } from "@/index"
|
|
||||||
|
|
||||||
type ValueType = string | string[]
|
type ValueType = string | string[]
|
||||||
|
|
||||||
|
|
|
@ -19,16 +19,3 @@ export { default as codescanner } from "./CodeScannerField.svelte"
|
||||||
export { default as signaturesinglefield } from "./SignatureField.svelte"
|
export { default as signaturesinglefield } from "./SignatureField.svelte"
|
||||||
export { default as bbreferencefield } from "./BBReferenceField.svelte"
|
export { default as bbreferencefield } from "./BBReferenceField.svelte"
|
||||||
export { default as bbreferencesinglefield } from "./BBReferenceSingleField.svelte"
|
export { default as bbreferencesinglefield } from "./BBReferenceSingleField.svelte"
|
||||||
|
|
||||||
export interface FieldApi {
|
|
||||||
setValue(value: any): boolean
|
|
||||||
deregister(): void
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface FieldState<T = any> {
|
|
||||||
value: T
|
|
||||||
fieldId: string
|
|
||||||
disabled: boolean
|
|
||||||
readonly: boolean
|
|
||||||
error?: string
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
import { Writable } from "svelte"
|
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" {
|
declare module "svelte" {
|
||||||
export function getContext(key: "sdk"): SDK
|
export function getContext(key: "sdk"): SDK
|
||||||
export function getContext(key: "component"): Component
|
export function getContext(key: "component"): Component
|
||||||
export function getContext(key: "context"): Context
|
export function getContext(key: "context"): Readable<Record<string, any>>
|
||||||
export function getContext(key: "form"): FormContext | undefined
|
export function getContext(key: "form"): FormContext | undefined
|
||||||
export function getContext(key: "form-step"): Writable<number> | undefined
|
export function getContext(key: "form-step"): Writable<number> | undefined
|
||||||
export function getContext(key: "field-group"): FieldGroupContext | undefined
|
export function getContext(key: "field-group"): FieldGroupContext | undefined
|
||||||
|
|
|
@ -14,8 +14,6 @@ import {
|
||||||
} from "@/stores"
|
} from "@/stores"
|
||||||
import { get } from "svelte/store"
|
import { get } from "svelte/store"
|
||||||
import { initWebsocket } from "@/websocket"
|
import { initWebsocket } from "@/websocket"
|
||||||
import { APIClient } from "@budibase/frontend-core"
|
|
||||||
import type { ActionTypes } from "@/constants"
|
|
||||||
import { Readable } from "svelte/store"
|
import { Readable } from "svelte/store"
|
||||||
import {
|
import {
|
||||||
Screen,
|
Screen,
|
||||||
|
@ -27,8 +25,6 @@ import {
|
||||||
Snippet,
|
Snippet,
|
||||||
UIComponentError,
|
UIComponentError,
|
||||||
CustomComponent,
|
CustomComponent,
|
||||||
FieldType,
|
|
||||||
FieldSchema,
|
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
|
|
||||||
// Provide svelte and svelte/internal as globals for custom components
|
// Provide svelte and svelte/internal as globals for custom components
|
||||||
|
@ -41,7 +37,7 @@ window.svelte = svelte
|
||||||
// Initialise spectrum icons
|
// Initialise spectrum icons
|
||||||
// eslint-disable-next-line local-rules/no-budibase-imports
|
// eslint-disable-next-line local-rules/no-budibase-imports
|
||||||
import loadSpectrumIcons from "@budibase/bbui/spectrum-icons-vite.js"
|
import loadSpectrumIcons from "@budibase/bbui/spectrum-icons-vite.js"
|
||||||
import { FieldApi, FieldState } from "./components/app"
|
|
||||||
loadSpectrumIcons()
|
loadSpectrumIcons()
|
||||||
|
|
||||||
// Extend global window scope
|
// 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<Record<string, any>>
|
export type Context = Readable<Record<string, any>>
|
||||||
|
|
||||||
export interface FormContext {
|
|
||||||
formApi?: {
|
|
||||||
registerField: (
|
|
||||||
field: string,
|
|
||||||
type: FieldType,
|
|
||||||
defaultValue: string | undefined,
|
|
||||||
disabled: boolean,
|
|
||||||
readonly: boolean,
|
|
||||||
validation: FieldValidation | undefined,
|
|
||||||
formStep: number
|
|
||||||
) => Readable<FormField>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export type FieldValidation = () => string | undefined
|
|
||||||
|
|
||||||
export interface FormField {
|
|
||||||
fieldState: FieldState
|
|
||||||
fieldApi: FieldApi
|
|
||||||
fieldSchema: FieldSchema
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface FieldGroupContext {
|
|
||||||
labelPosition: string
|
|
||||||
}
|
|
||||||
|
|
||||||
let app: ClientApp
|
let app: ClientApp
|
||||||
|
|
||||||
const loadBudibase = async () => {
|
const loadBudibase = async () => {
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
import { Readable } from "svelte/store"
|
||||||
|
|
||||||
|
export type Component = Readable<{
|
||||||
|
id: string
|
||||||
|
name: string
|
||||||
|
styles: any
|
||||||
|
editing: boolean
|
||||||
|
errorState: boolean
|
||||||
|
}>
|
|
@ -0,0 +1,3 @@
|
||||||
|
export interface FieldGroupContext {
|
||||||
|
labelPosition: string
|
||||||
|
}
|
|
@ -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<FormField>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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<T = any> {
|
||||||
|
value: T
|
||||||
|
fieldId: string
|
||||||
|
disabled: boolean
|
||||||
|
readonly: boolean
|
||||||
|
error?: string
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
export * from "./components"
|
||||||
|
export * from "./fields"
|
||||||
|
export * from "./forms"
|
||||||
|
export * from "./sdk"
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue