/** Represents a currently active live page. Live pages are open in the client and either in the process of being served for the first time, connecting via WebSocket, or connected via WebSocket. All live pages belong to a session. Usage: When authoring, you can export your page route as a subclass of KittenPage using the global reference to it at `kitten.Page`. Helpers: page.send(): Sends message to connected page (calls page.socket.send()). page.everyoneElse.send(): Sends message to everyone connected to this page but the current person. page.everyone.send(): Send message to everyone connected to this page, including the current person. @example See the KittenComponent class for an example of usage. */ import type { JavaScriptFunction, KittenHtml } from './KittenComponent.ts'; import type WebSocket from '../../third-party-libraries-with-missing-type-information/ws/index.d.ts'; export type KittenPageEvent = { page: KittenPage; name: string; handler: string; id: string; target: string; data: { [s: string]: any; }; headers: any; event: any; }; type WebSocketWithIsAlive = WebSocket & { isAlive: boolean; id?: string; }; type KittenRequest = import('../types/index.ts').KittenRequest & { ws?: Function; }; type KittenResponse = import('../types/index.ts').KittenResponse; type SwapTarget = { before?: string; } | { after?: string; } | { asFirstChildOf?: string; } | { asLastChildOf?: string; }; type BufferLike = string | Buffer | DataView | number | ArrayBufferView | Uint8Array | ArrayBuffer | SharedArrayBuffer | ReadonlyArray | ReadonlyArray | { valueOf(): ArrayBuffer; } | { valueOf(): SharedArrayBuffer; } | { valueOf(): Uint8Array; } | { valueOf(): ReadonlyArray; } | { valueOf(): string; } | { [Symbol.toPrimitive](hint: string): string; }; import KittenComponent, { eventNameToEventHandlerName } from './KittenComponent.ts'; export { eventNameToEventHandlerName }; import { type Session } from '../Sessions.ts'; /** Converts any key paths found in the keys of passed data into an actual object structure. This enables you to specify object structure in the names of your connected elements and makes it easier to persist them on the server. */ export declare function convertKeypathsToObjects(data: { [s: string]: any; }): { [s: string]: any; }; /** Add message envelope used when inserting elements into the DOM relative to another element using htmx’s out-of-band swaps (oob-swaps). If a swap target is not provided, the message is returned unchanged. */ export declare function addMessageEnvelopeIfNecessary(message: any, swapTarget: SwapTarget): any; export default class KittenPage extends KittenComponent { _isPage: boolean; session: Session | undefined; _request: KittenRequest | undefined; _response: KittenResponse | undefined; _isAuthoredPage: boolean; _socket: WebSocketWithIsAlive | undefined; _sockets: Array | undefined; timeout: ReturnType | undefined; socketMessageHandler: ((event: any) => void) | undefined; everyone: MessageSender; everyoneElse: MessageSender; /** Every page has a unique ID (inherited from KittenComponent) and can hold ephemeral page-level data. e.g., the states of components when using the Streaming HTML workfow. (Page storage is ephemeral is that it only lasts for the lifetime of a page in the browser and is destroyed when the page is closed or reloaded.) If you need greater persistence, use session storage (request.session) or the built-in JSDB database (kitten.db). A page is an authored page if the author of the Kitten app/site wrote and exported a KittenPage subclass in the route (as opposed to exporting a simple function and function-based event handlers that then resulted in a generic page being created by Kitten’s PageRoute class). Keeping track of this is an optimisation that enabled the PageSocketRoute to not have to import the source file again if the page was authored as a page instance and thus already contains its event handlers (as opposed to the event handlers being exported as separate functions that have be read in and mixed into the generic KittenPage instance by the PageSocketRoute). */ constructor(); get request(): KittenRequest | undefined; set request(request: KittenRequest | undefined); get response(): import("../types/types.js").KittenResponse | undefined; set response(response: import("../types/types.js").KittenResponse | undefined); /** The page has connected to its WebSocket. The list of sockets and the specific socket for this page are passed for storage on the page and the list of event handlers imported from the page (when using function-based page routes), if any, to be mixed into this instance as methods. */ connect(socket: WebSocketWithIsAlive, sockets: WebSocketWithIsAlive[], eventHandlers?: { [s: string]: JavaScriptFunction; }): void; /** Remove the socket event listener on disconnect. */ _onDisconnect(): void; /** Send specified message to just this page’s socket, awaiting promise if message is a promise (which can happen if this.component is accessed in a kitten.html tagged template string). You can specify an optional swap target that intelligently wraps what you’re sending with the necessary envelope tag. This is normally rather confusing with htmx’s oob swaps, especially when inserting table rows. See: https://htmx.org/attributes/hx-swap-oob/#using-alternate-swap-strategies */ send(message: BufferLike | Promise, swapTarget?: SwapTarget): void; /** Sends message. Expects it not to be a promise. */ sendImmediately(message: BufferLike, swapTarget: SwapTarget): void; /** Displays a toast message on the client. You can find the toast component itself at `kitten.components.toast` and you can change its styles using the #kitten-toast and #kitten-toast.settling selectors. */ toast(html: KittenHtml): void; /** The convention for page sockets is to map the name of the DOM element that triggered the HTMX request to the name of the event handler so that maps to onEventName() on the page. */ _messageHandler(event: { data: any; }): Promise; } /** Provides a namespaced send() method for use in Page instances. */ export declare class MessageSender { socket: WebSocketWithIsAlive; sockets: WebSocketWithIsAlive[]; includeSelf: boolean; constructor({ socket, sockets, includeSelf }: { socket: WebSocketWithIsAlive; sockets: WebSocketWithIsAlive[]; includeSelf: boolean; }); /** Sends message either to all connections or to all connections excluding the current one. You can specify an optional swap target that intelligently wraps what you’re sending with the necessary envelope tag. This is normally rather confusing with htmx’s oob swaps, especially when inserting table rows. See: https://htmx.org/attributes/hx-swap-oob/#using-alternate-swap-strategies */ send(message: BufferLike, swapTarget?: SwapTarget): number; }