import type { AsyncComponentAttributes, BaseAttributes, ComponentType, MaybeGetter } from "./jsx.d.ts"; export type WithParams = T & { params?: Record }; export interface Elements { /** * A built-in element of mono-jsx that is used to load components lazily, * which can improve performance by reducing the initial load time of the application. * @mono-jsx */ component: BaseAttributes & AsyncComponentAttributes & { /** * The name of the component to render. */ name?: string; /** * The component to render. */ is?: ComponentType; /** * The element to render. */ as?: JSX.Element; /** * The props of the component to render. */ props?: Record; /** * The ref of the component. */ ref?: ComponentElement | ((el: ComponentElement) => void); /** * Enables view transition for the children. */ viewTransition?: string | boolean; }; /** * A built-in element of mono-jsx that provides SPA routing. * @mono-jsx */ router: BaseAttributes & AsyncComponentAttributes & { /** * The base URL for the router. */ base?: string; /** * The ref of the router. */ ref?: RouterElement | ((el: RouterElement) => void); /** * Enables view transition for the children. * @mono-jsx */ viewTransition?: string | boolean; }; /** * A built-in element of mono-jsx that caches the rendered content of the child nodes * with the given key and TTL. * @mono-jsx */ cache: BaseAttributes & { /** * The key of the cache. */ key?: string; /** * The maximum age of the cache in seconds. */ maxAge?: number; }; /** * A built-in element of mono-jsx that treats the child nodes as static content, * When the child nodes are rendered once, they will be cached in memory and reused on subsequent renders. * @mono-jsx */ static: BaseAttributes; /** * A built-in element of mono-jsx that redirects to the given URL in the client side. * @mono-jsx */ redirect: { /** * The redirect URL. */ to?: string | URL; /** * The replace behavior of the redirect. * Only works when the `router` element is used. */ replace?: boolean; }; /** * A built-in element of mono-jsx that sets custom validation * state for the form elements. * @mono-jsx */ invalid: BaseAttributes & { /** * Which form elements to set the custom validation state for. */ for?: string; }; /** * A built-in element of mono-jsx that is used to display the content of the route form * in the `form` element. * @mono-jsx */ formslot: BaseAttributes & { /** * The name of the formslot element. */ name?: string; /** * The insert mode of the formslot. * - "insertbefore": Insert HTML before the formslot element. * - "insertafter": Insert HTML after the formslot element. * - "replaceChildren": Replace the formslot element's children with the HTML. * @default "replaceChildren" */ mode?: "insertbefore" | "insertafter" | "replaceChildren"; /** * If true, the formslot element will be hidden. */ hidden?: boolean; /** * The callback function to be called when the formslot element is updated. */ onUpdate?: (evt: { type: "update"; target: HTMLElement }) => void | Promise; }; } /** * The `` element. */ export type ComponentElement = { name: string; props: Record | undefined; refresh: () => Promise; }; /** * The `` element. */ export type RouterElement = { navigate: (url: string | URL, options?: { replace?: boolean }) => Promise; }; /** * The session storage API. */ export interface Session { /** * The session ID. */ readonly sessionId: string; /** * If true, update the session cookie to the client. */ readonly isDirty: boolean; /** * Gets a value from the session. */ get(key: string): T | undefined; /** * Gets all the entries from the session. */ all(): Record; /** * Sets a value in the session. */ set(key: string, value: string | number | boolean | any[] | Record): void; /** * Deletes a value from the session. */ delete(key: string): void; /** * Destroys the session. */ destroy(): void; } declare global { interface FCExtension { /** * The global signals shared across the application. */ readonly app: { /** * The `app.refs` object stores variables in the application scope. * It is similar to `refs`, but it is shared across all components in the application. * * **⚠ This is a client-side only API.** */ readonly refs: Record; /** * The `app.url` object contains the current URL. */ readonly url: WithParams; }; /** * The `request` object contains the current request. * * **⚠ This is a server-side only API.** */ readonly request: WithParams< Request & { /** * Returns the URL of the request as a URL object. */ URL: URL; } >; /** * The `session` object contains the current session. * * **⚠ This is a server-side only API.** */ readonly session: Session; } /** * Defines the `this.app` type. */ type WithAppSignals> = T extends FC ? FC & { /** * The global signals shared across the application. */ readonly app: { /** * The `app.refs` object stores variables in the application scope. * It is similar to `refs`, but it is shared across all components in the application. * * **⚠ This is a client-side only API.** */ readonly refs: AppRefs; /** * The `app.url` object contains the current URL. */ readonly url: WithParams; } & Omit; } : never; /** * Defines the `this.context` type. */ type WithContext = T extends FC ? FC & { /** * The rendering context object. * * **⚠ This is a server-side only API.** */ readonly context: Context; } : never; } export type { AsyncComponentAttributes, BaseAttributes, MaybeGetter };