UNPKG

blade

Version:
293 lines (292 loc) 10.4 kB
import { D as StoredObject, m as ModelField } from "./index-l2pJm30F.js"; import { p as TriggerError } from "./errors-BiF9KgM_.js"; import { n as ResultRecord } from "./types-BAUgmPHH.js"; import * as react0 from "react"; import { AnchorHTMLAttributes, FormHTMLAttributes, FunctionComponent, InputHTMLAttributes, ReactNode } from "react"; //#region private/client/components/link.d.ts interface LinkURL extends Omit<Partial<InstanceType<typeof URL>>, 'search'> { search?: string | Record<string, string | number | boolean | null>; } interface LinkProps extends Omit<AnchorHTMLAttributes<HTMLAnchorElement>, 'href'> { children: ReactNode; href: string | LinkURL; segments?: Record<string, string | Array<string>>; prefetch?: boolean; } declare const Link: FunctionComponent<LinkProps>; //#endregion //#region private/client/components/image.d.ts interface BaseImageProps { /** * Defines text that can replace the image in the page. */ alt?: string; /** * The quality level at which the image should be displayed. A lower quality ensures a * faster loading speed, but might also effect the visual appearance, so it is * essential to choose carefully. * * Must be an integer between `0` and `100`. * * @default 80 */ quality?: number; /** * The format of the image. * * @default "webp" */ format?: 'webp' | 'jpeg' | 'png' | 'original'; /** * The value of a RONIN blob field. */ src: string | StoredObject; /** * Specifies how the image should be resized to fit its container. * * @default "cover" */ fit?: React.CSSProperties['objectFit']; /** * The aspect ratio of the image. Can be "square", "video", or a custom string. */ aspect?: 'square' | 'video' | string; /** * Indicates how the browser should load the image. * * Providing the value "lazy" defers loading the image until it reaches a calculated * distance from the viewport, as defined by the browser. The intent is to avoid the * network and storage impact needed to handle the image until it's reasonably certain * that it will be needed. This generally improves the performance of the content in * most typical use cases. */ loading?: 'lazy'; /** * The class names for the image container (not the image itself). */ className?: string; /** * The inline style for the image container (not the image itself). */ style?: React.CSSProperties; } type ImageProps = BaseImageProps & ({ /** * The intrinsic size of the image in pixels, if its width and height are the same. * Must be an integer without a unit. */ size: number; /** * The intrinsic width of the image in pixels. Must be an integer without a unit. */ width?: never; /** * The intrinsic height of the image, in pixels. Must be an integer without a unit. */ height?: never; } | { /** * The intrinsic size of the image in pixels, if its width and height are the same. * Must be an integer without a unit. */ size?: never; /** * The intrinsic width of the image in pixels. Must be an integer without a unit. */ width?: number; /** * The intrinsic height of the image, in pixels. Must be an integer without a unit. */ height: number; } | { /** * The intrinsic size of the image in pixels, if its width and height are the same. * Must be an integer without a unit. */ size?: never; /** * The intrinsic width of the image in pixels. Must be an integer without a unit. */ width: number; /** * The intrinsic height of the image, in pixels. Must be an integer without a unit. */ height?: number; }); declare const Image: react0.ForwardRefExoticComponent<ImageProps & react0.RefAttributes<HTMLDivElement>>; //#endregion //#region private/client/components/form.d.ts type FieldType = 'BOOL' | 'STRING' | 'INT64' | 'FLOAT64' | 'DATE' | 'TIMESTAMP' | 'ARRAY' | 'JSON' | 'SUBQUERY' | 'READABLE'; interface RegisterFormProps { current: HTMLFormElement; } type FormContextValue = { /** * A key that lets React clear the inputs when the props of `Form` change. This is * needed when rendering a `Form` on different pages that have the same layout, since * React re-uses the exact same DOM elements between different pages if their hierarchy * is the same (React doesn't even have a concept of pages, just DOM updates). */ key: string; /** Method for submitting the form. */ submit: () => Promise<void>; /** Whether the form is currently being submitted. */ waiting: boolean; /** Whether the form should be cleared after its successful submission. */ clearOnSuccess: boolean; /** Allows for registering a virtual field. */ registerProperty: (name: string, type: RegisteredProperty['type'], getValue: RegisteredProperty['getValue']) => void; /** Allows for unregistering a virtual field. */ unregisterProperty: (name: string) => void; /** Allows for setting the `redirect` prop via context. */ registerRedirect: (destination: string) => void; /** Allows for unsetting the `redirect` prop via context. */ unregisterRedirect: () => void; /** The resulting record of the form submission. */ result: unknown | null; /** An error that occurred while submitting the form. */ error: TriggerError | null; /** * The time when the form was last submitted. Allows for understanding whether the form * was even ever submitted, and if so, when. */ updatedAt: Date | null; /** Allows for clearing all form fields. */ reset: (clearFields?: true) => void; /** Allows for registering a new `form` element. */ registerForm: ({ current }: RegisterFormProps) => string; /** Allows for unregistering a new `form` element. */ unregisterForm: (id: string) => void; /** Whether the form should be interactive, or not. */ disabled?: boolean; }; type RegisteredProperty = { type: FieldType; getValue: () => void; }; type CtxArg = FormContextValue | null; declare const FormContext: React.Context<CtxArg>; type TargetRecord = Record<string, unknown> & Partial<ResultRecord>; interface FormProps extends Omit<FormHTMLAttributes<HTMLFormElement>, 'onError'> { /** The slug (singular) of the affected Blade model. */ model: string; /** Called once the queries of the form have been executed successfully. */ onSuccess?: (result: NonNullable<Result['value']>) => void; /** Called if one of the queries of the form fails to execute. */ onError?: (error: Required<Result>['error']) => void; /** * Redirect to the given URL after the form was submitted successfully. * * Supports template syntax like "/{0.slug}" where {0} refers to the first object * in the array of returned results. * * @example ``` * // Redirects to `/home` on success. * <FormControls model="team" redirect="/home" /> * ``` * * @example ``` * // Redirects to `/teams/<slug>` on success. * <FormControls model="team" redirect="/teams/{0.slug}" /> * ``` * * Redirects can also be registered by invoking the `registerRedirect` method exposed * by the form context. */ redirect?: string; /** * Whether the form should be interactive, or not. * * @default false */ disabled?: boolean; /** * Whether the form should be disabled while waiting for the submission * of the data it contains. */ disabledWhileWaiting?: boolean; /** * If one of the fields submitted with the form is used in the URL, this prop * will ensure that the URL of the page automatically gets updated every time * the value of the field changes. */ recordSlug?: { param: string; field: string; formatAs?: 'dash-case'; }; /** * Certain forms in the dashboard are designed for being submitted several * times in a row, with different values being present every time. For this * kind of form, we want to immediately clear all input fields within the * form after it is submitted, to make it easy for people to fill them again * right after that. */ clearOnSuccess?: boolean; /** * Submits the query to a specific database. If this is not provided, the query will be * submitted to the default database. */ database?: string; /** * Allows for resolving the values of the specified Record fields when * returning updated or created records. This is done by setting the * `including` instruction of the resulting query. */ including?: Array<ModelField['slug']>; /** * If the fields associated with the provided field slugs are empty (`null`), * they will be excluded from the final query. * * This is useful in cases where certain fields should only be submitted if * they've received a value — such as when displaying the fields for changing * the password of an account. */ excludeEmptyFields?: Array<string>; /** * The slug that the page for creating a new record has in the URL. * * @default "new" */ newRecordSlug?: 'new'; /** Disable the automatic creation of a `<form>` element. */ noElement?: boolean; /** * Fields for matching a target record that should be modified. If not provided, a new * record will be created. */ set?: TargetRecord | boolean; /** * Fields for matching a target record that should be removed. If not provided, a new * record will be created. */ remove?: TargetRecord | boolean; } interface Result { value?: ResultRecord; error?: TriggerError; updatedAt: Date; } declare const Form: FunctionComponent<FormProps>; //#endregion //#region private/client/components/form-element.d.ts interface FormElementProps extends FormHTMLAttributes<HTMLFormElement> { allowGlobalSave?: boolean; } declare const FormElement: FunctionComponent<FormElementProps>; //#endregion //#region private/client/components/input.d.ts type InputValue = string | number | boolean | object | null | Date; interface InputProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'value'> { /** The value to be stored for the field in the Blade model. */ value?: InputValue; /** The type of the field in the Blade model. */ fieldType?: FieldType; /** Whether the input should be used to resolve the target record. */ target?: boolean; } declare const Input: FunctionComponent<InputProps>; //#endregion export { Image as a, FormContext as i, FormElement as n, Link as o, Form as r, Input as t };