Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export typescript definitions #1279

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
239 changes: 117 additions & 122 deletions packages/child/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,130 +8,125 @@
* I'm not a TypeScript dev, so please feel free to submit PRs to improve this file.
*/

declare module '@iframe-resizer/child' {
namespace iframeResizer {
// eslint-disable-next-line @typescript-eslint/naming-convention
interface IFramePageOptions {
/**
* This option allows you to restrict the domain of the parent page,
* to prevent other sites mimicking your parent page.
*/
targetOrigin?: string | undefined

/**
* Receive message posted from the parent page with the iframe.iFrameResizer.sendMessage() method.
*/
onMessage?(message: any): void

/**
* This function is called once iFrame-Resizer has been initialized after receiving a call from the parent page.
*/
onReady?(): void
}

// eslint-disable-next-line @typescript-eslint/naming-convention
interface IFramePage {
/**
* Turn autoResizing of the iFrame on and off. Returns bool of current state.
*/
autoResize(resize?: boolean): boolean

/**
* Remove the iFrame from the parent page.
*/
close(): void

/**
* Returns the ID of the iFrame that the page is contained in.
*/
getId(): string

/**
* Ask the containing page for its positioning coordinates.
*
* Your callback function will be recalled when the parent page is scrolled or resized.
*
* Pass false to disable the callback.
*/
getParentProps(callback: (data: ParentProps) => void): void

/**
* Scroll the parent page by x and y
*/
scrollBy(x: number, y: number): void

/**
* Scroll the parent page to the coordinates x and y
*/
scrollTo(x: number, y: number): void

/**
* Scroll the parent page to the coordinates x and y relative to the position of the iFrame.
*/
scrollToOffset(x: number, y: number): void

/**
* Send data to the containing page, message can be any data type that can be serialized into JSON. The `targetOrigin`
* option is used to restrict where the message is sent to; to stop an attacker mimicking your parent page.
* See the MDN documentation on postMessage for more details.
*/
sendMessage(message: any, targetOrigin?: string): void

/**
* Set default target origin.
*/
setTargetOrigin(targetOrigin: string): void

/**
* Manually force iFrame to resize. To use passed arguments you need first to disable the `autoResize` option to
* prevent auto resizing and enable the `sizeWidth` option if you wish to set the width.
*/
size(customHeight?: string, customWidth?: string): void
}

interface ParentProps {
/**
* The values returned by iframe.getBoundingClientRect()
*/
iframe: {
x: number
y: number
width: number
height: number
top: number
right: number
bottom: number
left: number
}

/**
* The values returned by document.documentElement.scrollWidth and document.documentElement.scrollHeight
*/
document: {
scrollWidth: number
scrollHeight: number
}

/**
* The values returned by window.visualViewport
*/
viewport: {
width: number
height: number
offsetLeft: number
offsetTop: number
pageLeft: number
pageTop: number
scale: number
}
}
// eslint-disable-next-line @typescript-eslint/naming-convention
export interface IFramePageOptions {
/**
* This option allows you to restrict the domain of the parent page,
* to prevent other sites mimicking your parent page.
*/
targetOrigin?: string | undefined

/**
* Receive message posted from the parent page with the iframe.iFrameResizer.sendMessage() method.
*/
onMessage?(message: any): void

/**
* This function is called once iFrame-Resizer has been initialized after receiving a call from the parent page.
*/
onReady?(): void
}

// eslint-disable-next-line @typescript-eslint/naming-convention
export interface IFramePage {
/**
* Turn autoResizing of the iFrame on and off. Returns bool of current state.
*/
autoResize(resize?: boolean): boolean

/**
* Remove the iFrame from the parent page.
*/
close(): void

/**
* Returns the ID of the iFrame that the page is contained in.
*/
getId(): string

/**
* Ask the containing page for its positioning coordinates.
*
* Your callback function will be recalled when the parent page is scrolled or resized.
*
* Pass false to disable the callback.
*/
getParentProps(callback: (data: ParentProps) => void): void

/**
* Scroll the parent page by x and y
*/
scrollBy(x: number, y: number): void

/**
* Scroll the parent page to the coordinates x and y
*/
scrollTo(x: number, y: number): void

/**
* Scroll the parent page to the coordinates x and y relative to the position of the iFrame.
*/
scrollToOffset(x: number, y: number): void

/**
* Send data to the containing page, message can be any data type that can be serialized into JSON. The `targetOrigin`
* option is used to restrict where the message is sent to; to stop an attacker mimicking your parent page.
* See the MDN documentation on postMessage for more details.
*/
sendMessage(message: any, targetOrigin?: string): void

/**
* Set default target origin.
*/
setTargetOrigin(targetOrigin: string): void

/**
* Manually force iFrame to resize. To use passed arguments you need first to disable the `autoResize` option to
* prevent auto resizing and enable the `sizeWidth` option if you wish to set the width.
*/
size(customHeight?: string, customWidth?: string): void
}

export interface ParentProps {
/**
* The values returned by iframe.getBoundingClientRect()
*/
iframe: {
x: number
y: number
width: number
height: number
top: number
right: number
bottom: number
left: number
}

global {
interface Window {
iFrameResizer: iframeResizer.IFramePageOptions
parentIFrame: iframeResizer.IFramePage
}
/**
* The values returned by document.documentElement.scrollWidth and document.documentElement.scrollHeight
*/
document: {
scrollWidth: number
scrollHeight: number
}

/**
* The values returned by window.visualViewport
*/
viewport: {
width: number
height: number
offsetLeft: number
offsetTop: number
pageLeft: number
pageTop: number
scale: number
}
}

declare global {
interface Window {
iFrameResizer: IFramePageOptions
parentIFrame: IFramePage
}
}
Loading