import { ComponentClass } from 'react'; import { ComponentType } from 'react'; import * as React_2 from 'react'; /** * A feature with its options, ready to be consumed by {@link makeWebshell}. * * @public */ export declare interface AssembledFeature { /** * The string containing valid ECMAScript 5 to be run in the WebView. * * @remarks * The script must define a single function which only argument is of the * type {@link WebjsContext}. * * It is recommended that you use eslint to validate this script syntax, and * event better, unit-test the script. See our repository home page for more * information. */ readonly script: string; /** * A unique identifier of the feature. The convention is to use a reverse * namespace domain ending with the event name. * * @example * com.archriss.linkPress */ readonly identifier: string; /** * The name of the event handler. The convention is to name it `on` + * PascalCase event name. * * @example * onLinkPress */ readonly eventHandlerName: E; /** * Any value that can be serialized to JSON and deserialized back. * This value will be passed to the top level function declared in the DOM * script. */ readonly options?: Partial; /** * Placeholder value to infer P. * * @remarks This is not required, but can help with typescript so that it * infers payload type P. */ readonly payloadType?: P; } /** * A lookup type to infer the assembled feature from a feature. * * @public */ export declare type AssembledFeatureOf = F extends Feature ? AssembledFeature : never; /** * This feature enables receiving the full width and height of an element * identified by `tagName` in the WebView pixels unit, including border widths, * but excluding margins. The first element matching the provided tagName is * retained. A new event will be triggered on every resize. * * @public */ export declare const dimensionsFeature: Feature; /** * @public */ export declare interface DimensionsObject { width: number; height: number; } /** * An object describing customization for the dimensions feature. * * @public */ export declare interface DimensionsOptions { /** * The element to target when the DOM is loaded. */ tagName: string; /** * When no elements are found matching the providing tag, should the script * raise an error? * * @defaultValue false */ errorWhenNotFound?: boolean; } /** * A lookup type to find the event name from an assembled feature. * * @public */ export declare type EventNameOf = T extends AssembledFeature<{}, infer E, unknown> ? E : never; /** * A feature adds new behaviors to the `WebView` DOM and offers handlers on React * Native's side. * * @public */ export declare interface Feature { /** {@inheritDoc AssembledFeature.identifier} */ readonly identifier: string; /** {@inheritDoc AssembledFeature.eventHandlerName} */ readonly eventHandlerName: E; /** * Assemble the feature source from options. The feature source object can * thereafter be passed to {@link makeWebshell} utility. */ readonly assemble: (options?: O) => AssembledFeature; } /** * This feature allows to intercept clicks on anchors (``). By default, it * will prevent the click from propagating. But you can disable this option. * * @public */ export declare const linkPressFeature: Feature; /** * An object describing customization for the linkPress feature. * * @public */ export declare interface LinkPressOptions { /** * Prevent click events on anchors to propagate. * * @defaultValue true */ preventDefault?: boolean; } /** * Create a feature. * * @param params - An object to specify attributes of the feature. * * @public */ export declare function makeFeature({ script, identifier, eventHandlerName, payloadType }: MakeFeatureParams): Feature; /** * An object to specify attributes of the feature. * * @public */ export declare interface MakeFeatureParams { /** {@inheritDoc AssembledFeature.script} */ readonly script: string; /** {@inheritDoc AssembledFeature.identifier} */ readonly identifier: string; /** {@inheritDoc AssembledFeature.eventHandlerName} */ readonly eventHandlerName: E; /** {@inheritDoc AssembledFeature.payloadType} */ readonly payloadType?: P; } /** * Creates a React component which decorates WebView component with additionnal * props to handle events from the DOM. * * @param WebView - A WebView component, typically exported from `react-native-webview`. * @param assembledFeatures - Assembled features ready to be loaded in the WebView DOM. * * @public */ declare function makeWebshell(WebView: ComponentType, ...assembledFeatures: F): React_2.ComponentClass, unknown>; export default makeWebshell; export { makeWebshell } /** * @public */ export declare interface MinimalWebViewProps { onMessage?: unknown; onError?: unknown; injectedJavaScript?: unknown; javaScriptEnabled?: unknown; source?: unknown; } /** * A lookup type to find the payload type from an assembled feature. * * @public */ export declare type PayloadOf = T extends AssembledFeature<{}, E, infer P> ? P : never; /** * This type specifies the shape of the object passed to DOM features scripts. * * @public */ export declare interface WebjsContext { /** * The options to customize the script behavior. See {@link AssembledFeature.options}. */ readonly options: O; /** * When invoked, the webshell will call the handler associated with this script. * * @param payload - The value which will be passed to the handler. */ readonly postMessage: (payload: P) => void; /** * Safely post a warn message to the console. */ readonly warn: (message: string) => void; /** * Safely post an error message to the console. */ readonly error: (message: string) => void; } /** * A utility type to infer WebshellComponent type from a list of features. * * @example * ``` * const Webshell: WebshellComponentOf< * WebViewProps, * [typeof featureA, typeof featureB] * >; * ``` * * @public */ export declare type WebshellComponentOf[]> = ComponentClass[]>, unknown>; /** * @public */ export declare type WebshellComponentProps[]> = WebshellHandlerProps & WebshellStaticProps; /** * A smart type which infers the prop type associated with a feature. * * @public */ export declare type WebshellHandlerProps> = { [E in EventNameOf]?: (p: PayloadOf) => void; }; /** * @public */ export declare interface WebshellStaticProps { onShellError?: (featureIdentifier: string, error: string) => void; webViewProps?: W; } export { }