diff --git a/package.json b/package.json index e91239b..8c09a7d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@finsweet/ts-utils", - "version": "0.24.2", + "version": "0.24.3", "description": "Typescript utils for custom Webflow projects.", "main": "index.ts", "module": "index.ts", diff --git a/types/Webflow.ts b/types/Webflow.ts index d4b2627..3dae7e8 100644 --- a/types/Webflow.ts +++ b/types/Webflow.ts @@ -5,6 +5,46 @@ type Callback = () => unknown; export type WebflowModule = 'ix2' | 'commerce' | 'lottie' | 'lightbox'; +interface WebflowCommerce { + destroy: () => void; + init: (params: { siteId: string; apiUrl: string }) => void; +} + +interface WebflowIx2 { + destroy: () => void; + init: () => void; + actions: { + [key: string]: (...params: unknown[]) => unknown; + }; + store: { + dispatch: (param: unknown) => void; + getState: () => { + ixData: { + actionLists: unknown; + eventTypeMap: unknown; + events: unknown; + mediaQueries: unknown; + mediaQueryKeys: unknown; + }; + ixElements: { + [key: string]: unknown; + }; + ixInstances: { + [key: string]: unknown; + }; + ixRequest: { + [key: string]: unknown; + }; + ixSession: { + eventState: { + [key: string]: unknown; + }; + [key: string]: unknown; + }; + }; + }; +} + /** * Includes methods of the Webflow.js object */ @@ -12,14 +52,7 @@ export interface Webflow extends Pick { destroy: () => void; ready: () => void; env: () => boolean; - require: ( - key: Key - ) => - | { - destroy: () => void; - init: Key extends 'commerce' ? (params: { siteId: string; apiUrl: string }) => void : () => void; - } - | undefined; + require: (key: Key) => (Key extends 'commerce' ? WebflowCommerce : WebflowIx2) | undefined; } /** diff --git a/webflow/restartWebflow.ts b/webflow/restartWebflow.ts index 88b43e6..cdbbfd9 100644 --- a/webflow/restartWebflow.ts +++ b/webflow/restartWebflow.ts @@ -26,8 +26,14 @@ export const restartWebflow = async (modules?: WebflowModule[]): Promise