@swishapp/browser
Version:
JS library to integrate Swish into a browser environment.
52 lines (51 loc) • 2.15 kB
TypeScript
import type { SwishUiElementSpec, SwishUiManifest, SwishUiOptions } from "../types";
import type { Ref } from "./types";
import type { ShopBridge } from "../utils/shop-bridge";
import "../utils/shop-bridge";
export type * from "./types";
export declare const setConfig: (opts: SwishUiOptions) => void;
export declare const showSignIn: (options?: {
returnTo?: string;
}) => Promise<void>;
export declare const showNotification: (options: {
title?: string;
text: string;
image?: string;
action?: {
label: string;
url?: string;
onAction?: () => void;
};
}) => Promise<void>;
export declare const showVariantSelect: <TData = unknown>(options: {
productId?: string;
productHandle?: string;
variantId?: string;
displayType?: "rows" | "pills";
onSubmit: (data: TData) => void | Promise<void>;
}) => Promise<void>;
export declare const initShopBridge: ({ onShopModalOpen, }: {
onShopModalOpen: () => void;
}) => Promise<ShopBridge>;
export declare const loadManifest: () => Promise<SwishUiManifest>;
export declare const importElementSepc: (name: string) => Promise<SwishUiElementSpec>;
export interface RequireUiComponentOptions<TComponent> {
instance?: string;
listeners?: Record<string, (event: Event) => void | Promise<void>>;
onHydrated?: (ref: Ref<TComponent>) => void;
}
export declare const requireUiComponent: <TComponent = unknown>(name: string, options?: RequireUiComponentOptions<TComponent>) => Promise<SwishUiElement>;
export declare const insertComponent: <T extends HTMLElement = SwishUiElement>({ name, instance, template, position, refElement, }: {
name: string;
instance?: string;
template: string;
position: InsertPosition;
refElement: HTMLElement;
}) => Promise<T>;
export declare const queryComponent: <T extends HTMLElement = SwishUiElement>(name: string, instance?: string) => T;
export declare class SwishUiElement extends HTMLElement {
constructor();
private componentRef;
getComponentRef: <TComponent = unknown>() => Ref<TComponent>;
setComponentRef: <TComponent = unknown>(ref: Ref<TComponent>) => void;
}