import { AirtableInterface } from './types/airtable_interface'; import { RecordActionData, RecordActionDataCallback } from './types/record_action_data'; import AbstractModelWithAsyncData from './models/abstract_model_with_async_data'; import Sdk from './sdk'; import { ObjectValues } from './private_utils'; /** @hidden */ export declare const WatchablePerformRecordActionKeys: Readonly<{ isDataLoaded: "isDataLoaded"; recordActionData: "recordActionData"; }>; /** @hidden */ declare type WatchablePerformRecordActionKey = ObjectValues; /** * Returned by {@link registerRecordActionDataCallback}. Call it to unregister the previously * registered function. Do this before registering another function or unmounting the component. * */ declare type UnsubscribeFunction = () => void; /** * This class exists to manage registering a callback to receive "Open block" / "Perform record * action" messages. * This is different to other message handlers (_registerHandlers) since the callback is specified * by the block: it registers it during first render (vs the SDK registering during initialisation). * * On the liveapp side, we ensure that pending messages are held until the block registers the * callback (or another message is sent). If there's a pending message, it is returned at * registration. * * This class implements AbstractModelWithAsyncData in order to take advantage of useLoadable's * suspense handling. "Loading" the model means registering the handler with liveapp. This allows us * to suspend the block and return the initial pending message on first render. * * One difference is that _unloadData will not unregister the airtableInterface handler. We don't * support unregistering it at this time for simplicity. * * This class is internal: users should use registerRecordActionDataCallback or useRecordActionData. * * @internal * */ export declare class PerformRecordAction extends AbstractModelWithAsyncData { /** @internal */ _airtableInterface: AirtableInterface; /** @internal */ _hasRegisteredHandler: boolean; /** @internal */ _hasCompletedInitialDataLoad: boolean; /** * The data from the latest record action, or null if none have occurred yet. * * @internal */ recordActionData: RecordActionData | null; /** @hidden */ constructor(sdk: Sdk, airtableInterface: AirtableInterface); /** @internal */ static _isWatchableKey(key: string): boolean; /** @hidden */ _handlePerformRecordAction(data: RecordActionData): void; /** * This accessor method is defined solely to satisfy the contract of the * AbstractModel class. * * @internal */ get _dataOrNullIfDeleted(): never; /** * This accessor method is defined because the parent implementation uses _dataOrNullIfDeleted * * @inheritdoc */ get isDeleted(): boolean; /** * AbstractModelWithAsyncData implementation */ /** @internal */ _onChangeIsDataLoaded(): void; /** @internal */ _loadDataAsync(): Promise<[]>; /** @internal */ _unloadData(): void; /** @internal */ static _shouldLoadDataForKey(key: WatchablePerformRecordActionKey): boolean; } /** * Registers a callback to handle "open block" / "perform record action" events (from button field). * * Returns a unsubscribe function that should be used to unregister the callback for cleanup on * component unmount, or if you wish to register a different function. * * Also see {@link useRecordActionData}, which subscribes to the same events in a synchronous way. * * Your block will not receive "perform record action" events until a callback is registered - * they're held until registration to ensure the block is ready to handle the event (e.g. has * finished loading). * * Because of this, we recommend only registering a callback once, in your top level component - * otherwise, messages could be received while not all callbacks have been successfully registered. * Similarly, using both `registerRecordActionDataCallback` and `useRecordActionData` is not * supported. * * You can test your block in development by sending "perform record action" events to your block * in the "Advanced" panel of the block developer tools. * * After releasing your block, you can use it with a button field by choosing the "Open custom * block" action and selecting your block. * * @example * ```js * import React, {useEffect, useState} from 'react'; * import {registerRecordActionDataCallback} from '@airtable/blocks/ui'; * * function LatestRecordAction() { * const [recordActionData, setRecordActionData] = useState(null); * * const callback = (data) => { * console.log('Record action received', data); * setRecordActionData(data); * } * * useEffect(() => { * // Return the unsubscribe function so it's run on cleanup. * return registerRecordActionDataCallback(callback); * }, [callback]); * * if (recordActionData === null) { * return No events yet; * } * * return ( * * ); * } * ``` * */ export declare function registerRecordActionDataCallback(callback: RecordActionDataCallback): UnsubscribeFunction; export declare function __injectSdkIntoPerformRecordAction(_sdk: Sdk): void; export {};