export interface ContentSavedEvent { contentLink: string; editUrl?: string; previewUrl: string; previewToken: string; /** Where the edit happened: one or the other, only on the editor's token message. */ sectionId?: string; nodeIds?: string[]; } /** * Callback for handling navigation/refresh when content is saved. * @param url - Target URL to navigate to * @param isSameUrl - True if URL matches current location (refresh), false if different (navigate) */ export type NavigateCallback = (url: string, isSameUrl: boolean) => void | Promise; export type ContentSavedListenerOptions = { /** Called with the target URL. Without one, the page hard-reloads. */ onNavigate?: NavigateCallback; /** * Delay in ms between the CMS reporting a save as ready and navigating. False to * disable. Merges back-to-back saves into one refresh. * @default 50 */ refreshTimeout?: number | false; /** Called when a refresh starts and again when it settles. */ onBusyChange?: (busy: boolean) => void; /** * Retries media that fails to load with the preview token. See `startMediaTokenRetry`. * Read when the listener starts. * @default true */ mediaTokenRetry?: boolean; /** The CMS URL for the media retry. See `MediaTokenRetryOptions.cmsUrl`. */ cmsUrl?: string; }; export type ContentSavedListener = { /** Subscribes to the event. Returns the unsubscribe. */ start(): () => void; /** * Merges into the current options without resubscribing. * * Callers pass an inline arrow for `onNavigate`, and tearing the listener down * would `clearTimeout` a refresh that is already pending. */ update(options: Partial): void; }; /** * Creates a listener for the CMS content-saved event. * * The CMS sends two messages per save: one with the editor's preview token, and one * when the change is ready. It navigates once both have arrived, in either order, to * the token message's URL. * * Nothing is subscribed until {@linkcode ContentSavedListener.start} is called, so * importing this module is safe on the server. */ export declare function createContentSavedListener(initialOptions?: ContentSavedListenerOptions): ContentSavedListener;