UNPKG

preact-island

Version:

🏝 Create your own slice of paradise on any website.

63 lines (62 loc) 3.01 kB
import { ComponentType } from 'preact'; import { InitialProps, Island } from './island'; declare type HostElement = HTMLElement | ShadowRoot; export declare const isInShadow: (node: HostElement | HTMLOrSVGScriptElement) => boolean; export declare const isShadowRoot: (x: unknown) => x is ShadowRoot; export declare const formatProp: (str: string) => string; export declare const getPropsFromElement: (element: HostElement | HTMLOrSVGScriptElement) => { [x: string]: any; } | undefined; export declare const isValidPropsScript: (element: Element) => boolean; export declare const getInteriorPropsScriptsForElement: (element: HostElement) => HTMLScriptElement[]; export declare const getPropsScriptsBySelector: (selector: string) => HTMLOrSVGScriptElement[]; export declare const getPropsFromScripts: (scripts: HTMLOrSVGScriptElement[]) => any; /** * Get the props from a host element's data attributes * @param {Element} The host element * @return {Object} props object to be passed to the component */ export declare const generateHostElementProps: <P extends InitialProps>(island: Island<P>, element: HostElement, initialProps: {} | undefined, propsSelector: string | undefined | null) => P; export declare const getHostElements: ({ selector, inline, elementName, }: { selector?: string | undefined; inline: boolean; /** * Passed if targeting web components so that mount in can create web components inside of the host elements */ elementName?: string | undefined; }) => HostElement[]; /** * A Preact 11+ implementation of the `replaceNode` parameter from Preact 10. * * This creates a "Persistent Fragment" (a fake DOM element) containing one or more * DOM nodes, which can then be passed as the `parent` argument to Preact's `render()` method. * * Lifted from: https://gist.github.com/developit/f4c67a2ede71dc2fab7f357f39cff28c */ export declare type RootFragment = any; export declare function createRootFragment(parent: HostElement, replaceNode: HostElement | HostElement[]): RootFragment; export declare const watchForPropChanges: <P extends InitialProps>({ island, hostElement, initialProps, onNewProps, propsSelector, }: { island: Island<P>; hostElement: HostElement; initialProps: any; onNewProps: (props: P) => void; propsSelector: string | undefined | null; }) => MutationObserver; export declare const renderIsland: <P extends InitialProps>({ island, widget, rootFragment, props, }: { island: Island<P>; widget: ComponentType<P>; rootFragment: RootFragment; props: P; }) => void; export declare const mount: <P extends InitialProps>({ island, widget, hostElements, clean, replace, initialProps, propsSelector, }: { island: Island<P>; widget: ComponentType<P>; hostElements: Array<HostElement>; clean: boolean; replace: boolean; initialProps: P; propsSelector?: string | undefined; }) => { rootFragments: any; }; export {};