UNPKG

@softr/sdk

Version:

The SDK for building Softr apps on TanStack Start. It lets an app interact with Softr: auth, datasources, workflows and integrations.

125 lines (124 loc) • 5.34 kB
import { z } from "zod"; import * as react0 from "react"; import { ReactNode } from "react"; //#region src/formatting.d.ts type FixedDateFormat = "FRIENDLY" | "DD-MM-YYYY" | "MM-DD-YYYY" | "YYYY-MM-DD"; type DateSeparator = "-" | "/" | "."; /** ISO week day: 1 is Monday, 7 is Sunday. */ type WeekDay = 1 | 2 | 3 | 4 | 5 | 6 | 7; /** How this request formats dates and numbers. Read it with `useFormatting()`. */ type Formatting = { /** The locale for dates when the app uses the visitor's format. */ dateLocale: string; /** The locale for numbers. */ numberLocale: string; /** * The IANA time zone for timestamps. `null` when the app uses the visitor's * zone and the browser has not reported it yet, which is the first visit. */ timeZone: string | null; /** The app's fixed date format, or `null` to format in `dateLocale`. */ fixedDate: { format: FixedDateFormat; separator: DateSeparator; hour12: boolean; } | null; /** The first day of the week, or `null` to use the locale's own. */ weekStart: WeekDay | null; /** The app's language, for `<html lang>`. */ language: string; /** Whether the app's language reads right to left, for `<html dir>`. */ rtl: boolean; }; /** A date as a record field holds it: a `Date`, epoch milliseconds, or an ISO string. */ type DateValue = Date | number | string; type DateOptions = { /** How long the date reads when the app uses the visitor's format. A fixed format ignores it. */ dateStyle?: "short" | "medium" | "long" | "full"; /** * The parts to show, such as `{ month: 'long', year: 'numeric' }` or `{ hour: 'numeric', minute: * 'numeric', timeZoneName: 'short' }`. Wins over `dateStyle` and the app's fixed format. */ parts?: DateParts; /** * The IANA zone for this value, such as `America/New_York`, when the builder names one. Wins over * a `FormattingScope` and the app's settings. An unknown zone is ignored. */ timeZone?: string; }; type DateParts = Pick<Intl.DateTimeFormatOptions, "weekday" | "year" | "month" | "day" | "hour" | "minute" | "timeZoneName">; /** * The day of a date, in the app's format. A timestamp reads in * `formatting.timeZone`, or in UTC while that is unknown. Returns `""` for * `null`, `undefined` or a value that is not a date, so a record's nullable * date field needs no guard. */ declare function formatDate(value: DateValue | null | undefined, formatting: Formatting, options?: DateOptions): string; /** * The day and the time of a timestamp, in the app's format and zone. Returns * `""` for `null`, `undefined` or a value that is not a date. In JSX, prefer * `<FormattedDate time />`: on a first visit it waits for the visitor's zone * instead of showing UTC. */ declare function formatDateTime(value: DateValue | null | undefined, formatting: Formatting, options?: DateOptions): string; /** A number in the app's number locale. Returns `""` for a value that is not finite. */ declare function formatNumber(value: number, formatting: Formatting, options?: Intl.NumberFormatOptions): string; /** * The formatting of this request. On the server and during hydration it is * the one the server resolved. After hydration, a zone the server did not know * yet is filled in from the browser. * * Requires the root route to resolve `getSoftrContext`. */ declare function useFormatting(): Formatting; type Scope = { timeZone?: string; locale?: string; }; /** * Formats every date and number inside it in a zone or a locale the builder names, such as "show * this page in New York time". A known zone renders on the server at once. An inner scope wins over * an outer one. An unknown zone or locale is ignored, because it can come from a record. * * @example * <FormattingScope timeZone="America/New_York"> * <FormattedDate value={event.fields.starts} time /> * </FormattingScope> */ declare function FormattingScope({ timeZone, locale, children }: { /** An IANA zone, such as `America/New_York`. */ timeZone?: string; /** A BCP 47 locale, such as `de-DE`. It drops the app's fixed date format inside the scope. */ locale?: string; children?: ReactNode; }): react0.FunctionComponentElement<react0.ProviderProps<Scope>>; /** * A date in the app's format, in a `<span>`, safe to render on the server. A * timestamp whose zone is not known yet renders `fallback` until the browser * supplies it, so the visitor never sees a UTC time. A `null` or `undefined` * value renders nothing, so a record's nullable date field needs no guard. * * @example * <FormattedDate value={bug.fields.created} /> * <FormattedDate value={event.fields.starts} time /> */ declare function FormattedDate({ value, time, fallback, ...options }: DateOptions & { value: DateValue | null | undefined; /** Shows the time as well as the day. A calendar day such as `2026-10-06` has no time to show. */ time?: boolean; /** What renders while the visitor's zone is unknown. */ fallback?: ReactNode; }): react0.FunctionComponentElement<react0.FragmentProps> | react0.DetailedReactHTMLElement<{ suppressHydrationWarning: true; }, HTMLElement> | null; //#endregion export { DateOptions, DateParts, DateSeparator, DateValue, FixedDateFormat, FormattedDate, Formatting, FormattingScope, WeekDay, formatDate, formatDateTime, formatNumber, useFormatting };