// Tipos de justAlerts 3.0 · https://www.dnmjustme.x10.mx/justAlerts/ // La librería se exporta con module.exports, por eso se declara con `export =` // (con esModuleInterop también funciona `import justAlerts from "justalerts"`). declare namespace justAlerts { // ------------------------------------------------------------------ // Toasts // ------------------------------------------------------------------ type ToastType = "success" | "danger" | "warning" | "info" | "loading"; type AlertType = "success" | "danger" | "warning" | "info"; type Position = | "top-left" | "top-center" | "top-right" | "bottom-left" | "bottom-center" | "bottom-right"; type Theme = "light" | "dark" | "auto"; type Lang = "es" | "en" | "auto"; interface ToastAction { /** Button text, e.g. "Undo". */ label: string; /** Runs on click. Return `false` to keep the toast open. */ onClick?: (toast: ToastHandle) => unknown; } interface ToastOptions { /** Default: "info". "loading" shows a spinner and never auto-closes. */ type?: ToastType; /** Optional bold title (plain text). */ title?: string; /** Toast text. Escaped unless `html` is true. A DOM node is also accepted. */ message?: string | Node; /** Default: "top-right". */ position?: Position; /** Visible milliseconds; 0 = never closes on its own. Default: 5000. */ duration?: number; /** Extra pixels from the screen edge. Default: 0. */ offset?: number; /** Treat `message` as HTML. Only for trusted content. Default: false. */ html?: boolean; /** Pause the timer on hover or focus. Default: true. */ pauseOnHover?: boolean; /** Show the time-left bar. Default: true. */ progress?: boolean; /** Action button inside the toast. */ action?: ToastAction | null; /** Default: "light". */ theme?: Theme; /** Language of the built-in texts. Default: "auto" (from ). */ lang?: Lang; } /** v2 name of ToastOptions. */ type Options = ToastOptions; interface ToastHandle { id: string | null; element: HTMLElement | null; close(): void; /** Change the open toast (type, title, message, duration, action...). */ update(next: ToastOptions | string): ToastHandle; } /** v2 name of ToastHandle. */ type Handle = ToastHandle; interface PromiseMessages { loading?: string; success?: string | ((value: T) => string); error?: string | ((error: any) => string); loadingTitle?: string; successTitle?: string; errorTitle?: string; } // ------------------------------------------------------------------ // Modals // ------------------------------------------------------------------ type ModalType = "success" | "danger" | "warning" | "info" | "question"; type ButtonStyle = "primary" | "secondary" | "danger" | "success" | "ghost"; type ModalAction = "confirm" | "deny" | "cancel" | "close" | "esc" | "backdrop" | "timer"; interface ButtonOptions { text?: string; style?: ButtonStyle; className?: string; } /** `true` = default text, `false` = hidden, a string = custom text. */ type Button = boolean | string | ButtonOptions; type FieldType = | "text" | "email" | "password" | "number" | "tel" | "url" | "search" | "date" | "time" | "datetime-local" | "month" | "week" | "color" | "textarea" | "select" | "radio" | "checkboxes" | "checkbox" | "range" | "file"; type FieldOptions = | Array | Record; type ValidationResult = true | string | void | null; interface Field { /** Key in the resulting values object. */ name: string; /** Default: "text". */ type?: FieldType; label?: string; placeholder?: string; /** Initial value (array for checkboxes / multiple select). */ value?: any; /** Initial state of a single checkbox. */ checked?: boolean; required?: boolean; min?: number | string; max?: number | string; step?: number | string; minLength?: number; maxLength?: number; pattern?: string; /** For select, radio and checkboxes. */ options?: FieldOptions; /** Small help text under the field. */ hint?: string; /** "half" puts two fields per row. */ width?: "full" | "half"; /** Textarea rows. Default: 4. */ rows?: number; multiple?: boolean; /** File types for type "file", e.g. "image/*". */ accept?: string; /** Image previews for type "file". Default: true. */ preview?: boolean; /** Suffix shown next to a range value, e.g. "%". */ unit?: string; autocomplete?: string; inputmode?: string; disabled?: boolean; readonly?: boolean; className?: string; /** Extra attributes for the control. */ attrs?: Record; /** Custom validation after the native one: true/undefined if valid, or an error message. May be async. */ validate?: (value: any, values: Record) => ValidationResult | Promise; } interface ModalImage { src: string; alt?: string; width?: number | string; height?: number | string; } interface CloseOptions { /** Close with the Escape key. Default: true. */ esc?: boolean; /** Close by clicking outside. Default: true. */ backdrop?: boolean; /** Show the × button. Default: true. */ button?: boolean; } type FormValidationResult = ValidationResult | Record; interface ModalOptions { /** Animated icon. */ type?: ModalType | null; /** false hides the icon. Default: true. */ icon?: boolean; title?: string; /** Plain text (escaped). */ text?: string; /** Trusted HTML or a DOM node; replaces `text`. */ html?: string | Node | null; image?: string | ModalImage | null; /** Default: true. */ confirm?: Button; /** Third button ("No"). Default: false. */ deny?: Button; /** Default: false (true in confirm, prompt and form). */ cancel?: Button; reverseButtons?: boolean; /** A single field: its value is the result. */ input?: FieldType | Partial | null; /** A whole form: field list,
/