@iframe-resizer/react 6.0.0-beta.0 → 6.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/filter-iframe-attribs.d.ts +1 -3
- package/index.cjs.js +1 -1
- package/index.cjs.js.map +1 -1
- package/index.d.ts +8 -10
- package/index.esm.js +39 -38
- package/index.esm.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
declare const _default: ({ license, bodyBackground, bodyMargin, bodyPadding, checkOrigin, direction, inPageLinks, log, offset, offsetHeight, offsetWidth, scrolling, tolerance, warningTimeout, waitForLoad, onAfterClose, onReady, onMessage, onResized, ...iframeProps }: Record<string, unknown>) =>
|
|
2
|
-
[x: string]: unknown;
|
|
3
|
-
};
|
|
1
|
+
declare const _default: ({ license, bodyBackground, bodyMargin, bodyPadding, checkOrigin, direction, inPageLinks, log, offset, offsetHeight, offsetWidth, scrolling, tolerance, warningTimeout, waitForLoad, onAfterClose, onReady, onMessage, onResized, ...iframeProps }: Record<string, unknown>) => Record<string, unknown>;
|
|
4
2
|
export default _default;
|
package/index.cjs.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const g=require("@iframe-resizer/core"),m=require("auto-console-group"),t=require("react"),R=e=>e?.__esModule?e.default:e,p=({license:e,bodyBackground:c,bodyMargin:i,bodyPadding:a,checkOrigin:f,direction:r,inPageLinks:n,log:u,offset:o,offsetHeight:s,offsetWidth:l,scrolling:A,tolerance:M,warningTimeout:b,waitForLoad:y,onAfterClose:C,onReady:w,onMessage:x,onResized:E,...d})=>d,z=R(m);function v(e,c){const{log:i,logExpand:a}=e,f=p(e),r=t.useRef(null),n=z(),u=()=>(n.event("close"),n.warn("Close event ignored, to remove the iframe update your React component."),!1);return t.useEffect(()=>{const o=r.current,s={...e,onBeforeClose:u};n.label(`react(${o.id})`),n.event("setup");const l=g(s)(o);return n.expand(a),i&&n.log("Created React component"),()=>{n.endAutoGroup(),l?.disconnect()}},[]),t.useImperativeHandle(c,()=>({getRef:()=>r,getElement:()=>r.current,resize:()=>r.current.iframeResizer.resize(),moveToAnchor:o=>r.current.iframeResizer.moveToAnchor(o),sendMessage:(o,s)=>{r.current.iframeResizer.sendMessage(o,s)}})),t.createElement("iframe",{...f,ref:r})}const h=t.forwardRef(v);module.exports=h;
|
|
2
2
|
//# sourceMappingURL=index.cjs.js.map
|
package/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":["../../packages/common/utils.ts","../../packages/react/filter-iframe-attribs.ts","../../packages/react/index.tsx"],"sourcesContent":["import { OBJECT, STRING } from './consts'\n\nexport const isElement = (node: Node): boolean
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../../packages/common/utils.ts","../../packages/react/filter-iframe-attribs.ts","../../packages/react/index.tsx"],"sourcesContent":["import { OBJECT, STRING } from './consts'\n\nexport const isElement = (node: Node): boolean =>\n node.nodeType === Node.ELEMENT_NODE\nexport const isNumber = (value: unknown): value is number =>\n typeof value === 'number' && !Number.isNaN(value)\nexport const isObject = (value: unknown): value is Record<string, unknown> =>\n typeof value === OBJECT && value !== null\nexport const isString = (value: unknown): value is string =>\n typeof value === STRING\n\nexport const isSafari: boolean = /^((?!chrome|android).)*safari/i.test(\n navigator.userAgent,\n)\n\nexport function isIframe(element: unknown): element is HTMLIFrameElement {\n if (!isObject(element)) return false\n\n try {\n return (\n (element as unknown as HTMLElement).tagName === 'IFRAME' ||\n element instanceof HTMLIFrameElement\n )\n } catch (error) {\n return false\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype AnyFunction = (...args: any[]) => any\n\nexport const isolateUserCode = (\n func: AnyFunction,\n ...val: unknown[]\n): ReturnType<typeof setTimeout> => setTimeout(() => func(...val), 0)\n\nexport const once = <T extends AnyFunction>(fn: T): T => {\n let done = false\n\n return function (this: unknown, ...args: unknown[]) {\n return done ? undefined : ((done = true), fn.apply(this, args))\n } as unknown as T\n}\n\nconst hasOwnFallback = (o: object, k: PropertyKey): boolean =>\n Object.prototype.hasOwnProperty.call(o, k)\n\nexport const hasOwn = (o: object, k: PropertyKey): boolean =>\n Object.hasOwn ? Object.hasOwn(o, k) : hasOwnFallback(o, k)\n\nexport const isDarkModeEnabled = (): boolean =>\n window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches\n\nexport const id = <T>(x: T): T => x\n\nconst ROUNDING = 1000\n\nexport const round = (value: number): number =>\n Math.round(value * ROUNDING) / ROUNDING\n\nexport const capitalizeFirstLetter = (string: string): string =>\n string.charAt(0).toUpperCase() + string.slice(1)\n\nexport const isDef = (value: unknown): boolean =>\n `${value}` !== '' && value !== undefined\n\nexport const invoke = <T>(fn: () => T): T => fn()\n\nexport const lower = (str: string): string => str.toLowerCase()\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function getElementName(el: any): string {\n switch (true) {\n case !isDef(el):\n return ''\n\n case isDef(el.id):\n return `${el.nodeName}#${el.id}`\n\n case isDef(el.name):\n return `${el.nodeName} (${el.name}`\n\n case isDef(el.className):\n return `${el.nodeName}.${el.className}`\n\n default:\n return el.nodeName\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const esModuleInterop = <T = any>(mod: any): T =>\n // eslint-disable-next-line no-underscore-dangle\n mod?.__esModule ? mod.default : mod\n\nexport const typeAssert = (\n value: unknown,\n type: string,\n error: string,\n): void => {\n // eslint-disable-next-line valid-typeof\n if (typeof value !== type) {\n throw new TypeError(`${error} is not a ${capitalizeFirstLetter(type)}`)\n }\n}\n","export default ({\n license,\n bodyBackground,\n bodyMargin,\n bodyPadding,\n checkOrigin,\n direction,\n inPageLinks,\n log,\n offset,\n offsetHeight,\n offsetWidth,\n scrolling,\n tolerance,\n warningTimeout,\n waitForLoad,\n onAfterClose,\n onReady,\n onMessage,\n onResized,\n ...iframeProps\n}: Record<string, unknown>): Record<string, unknown> => iframeProps\n","// eslint-disable-next-line eslint-comments/disable-enable-pair\n/* eslint-disable react/require-default-props */\nimport type {\n Direction,\n IFrameComponent,\n IFrameMessageData,\n IFrameMouseData,\n IFrameObject,\n IFrameResizedData,\n IFrameScrollData,\n LogOption,\n ScrollOption,\n} from '@iframe-resizer/core'\nimport connectResizer from '@iframe-resizer/core'\nimport acg from 'auto-console-group'\nimport React, {\n forwardRef,\n type ReactElement,\n type RefObject,\n useEffect,\n useImperativeHandle,\n useRef,\n} from 'react'\n\nimport { esModuleInterop } from '../common/utils'\nimport filterIframeAttribs from './filter-iframe-attribs'\n\nexport type IFrameForwardRef = Omit<IFrameObject, 'close' | 'disconnect'> & {\n getElement: () => IFrameComponent\n getRef: () => RefObject<HTMLIFrameElement | null>\n}\n\ntype IframeProps = React.DetailedHTMLProps<\n React.IframeHTMLAttributes<HTMLIFrameElement>,\n HTMLIFrameElement\n>\n\nexport type ResizerOptions = {\n bodyBackground?: string | null\n bodyMargin?: string | number | null\n bodyPadding?: string | number | null\n checkOrigin?: boolean | string[]\n direction?: Direction\n inPageLinks?: boolean\n license: string\n log?: LogOption\n logExpand?: boolean\n offsetSize?: number\n scrolling?: ScrollOption\n tolerance?: number\n waitForLoad?: boolean\n warningTimeout?: number\n}\n\nexport type ResizerEvents = {\n onAfterClose?: (iframeId: string) => void\n onMessage?: (ev: IFrameMessageData) => void\n onMouseEnter?: (ev: IFrameMouseData) => void\n onMouseLeave?: (ev: IFrameMouseData) => void\n onReady?: (iframe: IFrameComponent) => void\n onResized?: (ev: IFrameResizedData) => void\n onScroll?: (ev: IFrameScrollData) => boolean\n}\n\nexport type IframeResizerProps = Omit<IframeProps, 'scrolling'> &\n ResizerOptions &\n ResizerEvents\n\n// Deal with UMD not converting default exports to named exports\nconst createAutoConsoleGroup = esModuleInterop(acg)\n\nfunction IframeResizer(\n props: IframeResizerProps,\n ref: React.ForwardedRef<IFrameForwardRef>,\n): ReactElement {\n const { log, logExpand } = props\n const filteredProps = filterIframeAttribs(props)\n const iframeRef = useRef<IFrameComponent>(null)\n const consoleGroup = createAutoConsoleGroup()\n\n const onBeforeClose = (): boolean => {\n consoleGroup.event('close')\n consoleGroup.warn(\n `Close event ignored, to remove the iframe update your React component.`,\n )\n\n return false\n }\n\n // This hook is only run once, as once iframe-resizer is bound, it will\n // deal with changes to the element and does not need recalling\n useEffect(() => {\n const iframe = iframeRef.current\n const resizerOptions = { ...props, onBeforeClose }\n\n consoleGroup.label(`react(${iframe.id})`)\n consoleGroup.event('setup')\n\n const resizer = connectResizer(resizerOptions)(iframe)\n\n consoleGroup.expand(logExpand)\n if (log) consoleGroup.log('Created React component')\n\n return () => {\n consoleGroup.endAutoGroup()\n resizer?.disconnect()\n }\n }, []) // eslint-disable-line react-hooks/exhaustive-deps\n\n useImperativeHandle(ref, () => ({\n getRef: () => iframeRef,\n getElement: () => iframeRef.current,\n resize: () => iframeRef.current.iframeResizer.resize(),\n moveToAnchor: (anchor: string) =>\n iframeRef.current.iframeResizer.moveToAnchor(anchor),\n sendMessage: (message: string, targetOrigin?: string) => {\n iframeRef.current.iframeResizer.sendMessage(message, targetOrigin)\n },\n }))\n\n // eslint-disable-next-line jsx-a11y/iframe-has-title\n return <iframe {...filteredProps} ref={iframeRef} />\n}\n\nexport default forwardRef<IFrameForwardRef, IframeResizerProps>(IframeResizer)\n\nexport { type IFrameComponent, type IFrameObject } from '@iframe-resizer/core'\n"],"names":["esModuleInterop","mod","filterIframeAttribs","license","bodyBackground","bodyMargin","bodyPadding","checkOrigin","direction","inPageLinks","log","offset","offsetHeight","offsetWidth","scrolling","tolerance","warningTimeout","waitForLoad","onAfterClose","onReady","onMessage","onResized","iframeProps","createAutoConsoleGroup","acg","IframeResizer","props","ref","logExpand","filteredProps","iframeRef","useRef","consoleGroup","onBeforeClose","useEffect","iframe","resizerOptions","resizer","connectResizer","useImperativeHandle","anchor","message","targetOrigin","React","index","forwardRef"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,EAASC,CAAY,CACnE,CAAA,EACA,EAGKC,EAAA,cAAC,SAAA,CAAQ,GAAGd,EAAe,IAAKC,EAAW,CACpD,CAEA,MAAAc,EAAeC,EAAAA,WAAiDpB,CAAa"}
|
package/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { default as React,
|
|
3
|
-
export type { IFrameObject, IFrameComponent };
|
|
1
|
+
import { Direction, IFrameComponent, IFrameMessageData, IFrameMouseData, IFrameObject, IFrameResizedData, IFrameScrollData, LogOption, ScrollOption } from '@iframe-resizer/core';
|
|
2
|
+
import { default as React, RefObject } from 'react';
|
|
4
3
|
export type IFrameForwardRef = Omit<IFrameObject, 'close' | 'disconnect'> & {
|
|
5
4
|
getElement: () => IFrameComponent;
|
|
6
5
|
getRef: () => RefObject<HTMLIFrameElement | null>;
|
|
@@ -11,20 +10,18 @@ export type ResizerOptions = {
|
|
|
11
10
|
bodyMargin?: string | number | null;
|
|
12
11
|
bodyPadding?: string | number | null;
|
|
13
12
|
checkOrigin?: boolean | string[];
|
|
14
|
-
direction?:
|
|
15
|
-
forwardRef?: any;
|
|
13
|
+
direction?: Direction;
|
|
16
14
|
inPageLinks?: boolean;
|
|
17
15
|
license: string;
|
|
18
|
-
log?:
|
|
16
|
+
log?: LogOption;
|
|
19
17
|
logExpand?: boolean;
|
|
20
18
|
offsetSize?: number;
|
|
21
|
-
scrolling?:
|
|
19
|
+
scrolling?: ScrollOption;
|
|
22
20
|
tolerance?: number;
|
|
23
21
|
waitForLoad?: boolean;
|
|
24
22
|
warningTimeout?: number;
|
|
25
23
|
};
|
|
26
24
|
export type ResizerEvents = {
|
|
27
|
-
onCLosed?: (iframeId: string) => void;
|
|
28
25
|
onAfterClose?: (iframeId: string) => void;
|
|
29
26
|
onMessage?: (ev: IFrameMessageData) => void;
|
|
30
27
|
onMouseEnter?: (ev: IFrameMouseData) => void;
|
|
@@ -34,5 +31,6 @@ export type ResizerEvents = {
|
|
|
34
31
|
onScroll?: (ev: IFrameScrollData) => boolean;
|
|
35
32
|
};
|
|
36
33
|
export type IframeResizerProps = Omit<IframeProps, 'scrolling'> & ResizerOptions & ResizerEvents;
|
|
37
|
-
declare
|
|
38
|
-
export default
|
|
34
|
+
declare const _default: any;
|
|
35
|
+
export default _default;
|
|
36
|
+
export { type IFrameComponent, type IFrameObject } from '@iframe-resizer/core';
|
package/index.esm.js
CHANGED
|
@@ -1,53 +1,54 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
const
|
|
1
|
+
import u from "@iframe-resizer/core";
|
|
2
|
+
import m from "auto-console-group";
|
|
3
|
+
import g, { forwardRef as R, useRef as p, useEffect as z, useImperativeHandle as v } from "react";
|
|
4
|
+
const h = (e) => (
|
|
5
5
|
// eslint-disable-next-line no-underscore-dangle
|
|
6
|
-
|
|
7
|
-
),
|
|
8
|
-
license:
|
|
6
|
+
e?.__esModule ? e.default : e
|
|
7
|
+
), A = ({
|
|
8
|
+
license: e,
|
|
9
9
|
bodyBackground: s,
|
|
10
10
|
bodyMargin: i,
|
|
11
|
-
bodyPadding:
|
|
12
|
-
checkOrigin:
|
|
13
|
-
direction:
|
|
11
|
+
bodyPadding: c,
|
|
12
|
+
checkOrigin: a,
|
|
13
|
+
direction: o,
|
|
14
14
|
inPageLinks: r,
|
|
15
|
-
log:
|
|
16
|
-
offset:
|
|
17
|
-
offsetHeight:
|
|
18
|
-
offsetWidth:
|
|
19
|
-
scrolling:
|
|
20
|
-
tolerance:
|
|
21
|
-
warningTimeout:
|
|
22
|
-
waitForLoad:
|
|
15
|
+
log: f,
|
|
16
|
+
offset: t,
|
|
17
|
+
offsetHeight: n,
|
|
18
|
+
offsetWidth: l,
|
|
19
|
+
scrolling: y,
|
|
20
|
+
tolerance: C,
|
|
21
|
+
warningTimeout: w,
|
|
22
|
+
waitForLoad: x,
|
|
23
23
|
onAfterClose: E,
|
|
24
24
|
onReady: I,
|
|
25
25
|
onMessage: k,
|
|
26
|
-
onResized:
|
|
27
|
-
...
|
|
28
|
-
}) =>
|
|
29
|
-
function
|
|
30
|
-
const i =
|
|
26
|
+
onResized: G,
|
|
27
|
+
...d
|
|
28
|
+
}) => d, M = h(m);
|
|
29
|
+
function b(e, s) {
|
|
30
|
+
const { log: i, logExpand: c } = e, a = A(e), o = p(null), r = M(), f = () => (r.event("close"), r.warn(
|
|
31
31
|
"Close event ignored, to remove the iframe update your React component."
|
|
32
32
|
), !1);
|
|
33
|
-
return
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
return
|
|
38
|
-
|
|
33
|
+
return z(() => {
|
|
34
|
+
const t = o.current, n = { ...e, onBeforeClose: f };
|
|
35
|
+
r.label(`react(${t.id})`), r.event("setup");
|
|
36
|
+
const l = u(n)(t);
|
|
37
|
+
return r.expand(c), i && r.log("Created React component"), () => {
|
|
38
|
+
r.endAutoGroup(), l?.disconnect();
|
|
39
39
|
};
|
|
40
|
-
}, []),
|
|
41
|
-
getRef: () =>
|
|
42
|
-
getElement: () =>
|
|
43
|
-
resize: () =>
|
|
44
|
-
moveToAnchor: (
|
|
45
|
-
sendMessage: (
|
|
46
|
-
|
|
40
|
+
}, []), v(s, () => ({
|
|
41
|
+
getRef: () => o,
|
|
42
|
+
getElement: () => o.current,
|
|
43
|
+
resize: () => o.current.iframeResizer.resize(),
|
|
44
|
+
moveToAnchor: (t) => o.current.iframeResizer.moveToAnchor(t),
|
|
45
|
+
sendMessage: (t, n) => {
|
|
46
|
+
o.current.iframeResizer.sendMessage(t, n);
|
|
47
47
|
}
|
|
48
|
-
})), /* @__PURE__ */
|
|
48
|
+
})), /* @__PURE__ */ g.createElement("iframe", { ...a, ref: o });
|
|
49
49
|
}
|
|
50
|
+
const H = R(b);
|
|
50
51
|
export {
|
|
51
|
-
|
|
52
|
+
H as default
|
|
52
53
|
};
|
|
53
54
|
//# sourceMappingURL=index.esm.js.map
|
package/index.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":["../../packages/common/utils.ts","../../packages/react/filter-iframe-attribs.ts","../../packages/react/index.tsx"],"sourcesContent":["import { OBJECT, STRING } from './consts'\n\nexport const isElement = (node: Node): boolean
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["../../packages/common/utils.ts","../../packages/react/filter-iframe-attribs.ts","../../packages/react/index.tsx"],"sourcesContent":["import { OBJECT, STRING } from './consts'\n\nexport const isElement = (node: Node): boolean =>\n node.nodeType === Node.ELEMENT_NODE\nexport const isNumber = (value: unknown): value is number =>\n typeof value === 'number' && !Number.isNaN(value)\nexport const isObject = (value: unknown): value is Record<string, unknown> =>\n typeof value === OBJECT && value !== null\nexport const isString = (value: unknown): value is string =>\n typeof value === STRING\n\nexport const isSafari: boolean = /^((?!chrome|android).)*safari/i.test(\n navigator.userAgent,\n)\n\nexport function isIframe(element: unknown): element is HTMLIFrameElement {\n if (!isObject(element)) return false\n\n try {\n return (\n (element as unknown as HTMLElement).tagName === 'IFRAME' ||\n element instanceof HTMLIFrameElement\n )\n } catch (error) {\n return false\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype AnyFunction = (...args: any[]) => any\n\nexport const isolateUserCode = (\n func: AnyFunction,\n ...val: unknown[]\n): ReturnType<typeof setTimeout> => setTimeout(() => func(...val), 0)\n\nexport const once = <T extends AnyFunction>(fn: T): T => {\n let done = false\n\n return function (this: unknown, ...args: unknown[]) {\n return done ? undefined : ((done = true), fn.apply(this, args))\n } as unknown as T\n}\n\nconst hasOwnFallback = (o: object, k: PropertyKey): boolean =>\n Object.prototype.hasOwnProperty.call(o, k)\n\nexport const hasOwn = (o: object, k: PropertyKey): boolean =>\n Object.hasOwn ? Object.hasOwn(o, k) : hasOwnFallback(o, k)\n\nexport const isDarkModeEnabled = (): boolean =>\n window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches\n\nexport const id = <T>(x: T): T => x\n\nconst ROUNDING = 1000\n\nexport const round = (value: number): number =>\n Math.round(value * ROUNDING) / ROUNDING\n\nexport const capitalizeFirstLetter = (string: string): string =>\n string.charAt(0).toUpperCase() + string.slice(1)\n\nexport const isDef = (value: unknown): boolean =>\n `${value}` !== '' && value !== undefined\n\nexport const invoke = <T>(fn: () => T): T => fn()\n\nexport const lower = (str: string): string => str.toLowerCase()\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function getElementName(el: any): string {\n switch (true) {\n case !isDef(el):\n return ''\n\n case isDef(el.id):\n return `${el.nodeName}#${el.id}`\n\n case isDef(el.name):\n return `${el.nodeName} (${el.name}`\n\n case isDef(el.className):\n return `${el.nodeName}.${el.className}`\n\n default:\n return el.nodeName\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const esModuleInterop = <T = any>(mod: any): T =>\n // eslint-disable-next-line no-underscore-dangle\n mod?.__esModule ? mod.default : mod\n\nexport const typeAssert = (\n value: unknown,\n type: string,\n error: string,\n): void => {\n // eslint-disable-next-line valid-typeof\n if (typeof value !== type) {\n throw new TypeError(`${error} is not a ${capitalizeFirstLetter(type)}`)\n }\n}\n","export default ({\n license,\n bodyBackground,\n bodyMargin,\n bodyPadding,\n checkOrigin,\n direction,\n inPageLinks,\n log,\n offset,\n offsetHeight,\n offsetWidth,\n scrolling,\n tolerance,\n warningTimeout,\n waitForLoad,\n onAfterClose,\n onReady,\n onMessage,\n onResized,\n ...iframeProps\n}: Record<string, unknown>): Record<string, unknown> => iframeProps\n","// eslint-disable-next-line eslint-comments/disable-enable-pair\n/* eslint-disable react/require-default-props */\nimport type {\n Direction,\n IFrameComponent,\n IFrameMessageData,\n IFrameMouseData,\n IFrameObject,\n IFrameResizedData,\n IFrameScrollData,\n LogOption,\n ScrollOption,\n} from '@iframe-resizer/core'\nimport connectResizer from '@iframe-resizer/core'\nimport acg from 'auto-console-group'\nimport React, {\n forwardRef,\n type ReactElement,\n type RefObject,\n useEffect,\n useImperativeHandle,\n useRef,\n} from 'react'\n\nimport { esModuleInterop } from '../common/utils'\nimport filterIframeAttribs from './filter-iframe-attribs'\n\nexport type IFrameForwardRef = Omit<IFrameObject, 'close' | 'disconnect'> & {\n getElement: () => IFrameComponent\n getRef: () => RefObject<HTMLIFrameElement | null>\n}\n\ntype IframeProps = React.DetailedHTMLProps<\n React.IframeHTMLAttributes<HTMLIFrameElement>,\n HTMLIFrameElement\n>\n\nexport type ResizerOptions = {\n bodyBackground?: string | null\n bodyMargin?: string | number | null\n bodyPadding?: string | number | null\n checkOrigin?: boolean | string[]\n direction?: Direction\n inPageLinks?: boolean\n license: string\n log?: LogOption\n logExpand?: boolean\n offsetSize?: number\n scrolling?: ScrollOption\n tolerance?: number\n waitForLoad?: boolean\n warningTimeout?: number\n}\n\nexport type ResizerEvents = {\n onAfterClose?: (iframeId: string) => void\n onMessage?: (ev: IFrameMessageData) => void\n onMouseEnter?: (ev: IFrameMouseData) => void\n onMouseLeave?: (ev: IFrameMouseData) => void\n onReady?: (iframe: IFrameComponent) => void\n onResized?: (ev: IFrameResizedData) => void\n onScroll?: (ev: IFrameScrollData) => boolean\n}\n\nexport type IframeResizerProps = Omit<IframeProps, 'scrolling'> &\n ResizerOptions &\n ResizerEvents\n\n// Deal with UMD not converting default exports to named exports\nconst createAutoConsoleGroup = esModuleInterop(acg)\n\nfunction IframeResizer(\n props: IframeResizerProps,\n ref: React.ForwardedRef<IFrameForwardRef>,\n): ReactElement {\n const { log, logExpand } = props\n const filteredProps = filterIframeAttribs(props)\n const iframeRef = useRef<IFrameComponent>(null)\n const consoleGroup = createAutoConsoleGroup()\n\n const onBeforeClose = (): boolean => {\n consoleGroup.event('close')\n consoleGroup.warn(\n `Close event ignored, to remove the iframe update your React component.`,\n )\n\n return false\n }\n\n // This hook is only run once, as once iframe-resizer is bound, it will\n // deal with changes to the element and does not need recalling\n useEffect(() => {\n const iframe = iframeRef.current\n const resizerOptions = { ...props, onBeforeClose }\n\n consoleGroup.label(`react(${iframe.id})`)\n consoleGroup.event('setup')\n\n const resizer = connectResizer(resizerOptions)(iframe)\n\n consoleGroup.expand(logExpand)\n if (log) consoleGroup.log('Created React component')\n\n return () => {\n consoleGroup.endAutoGroup()\n resizer?.disconnect()\n }\n }, []) // eslint-disable-line react-hooks/exhaustive-deps\n\n useImperativeHandle(ref, () => ({\n getRef: () => iframeRef,\n getElement: () => iframeRef.current,\n resize: () => iframeRef.current.iframeResizer.resize(),\n moveToAnchor: (anchor: string) =>\n iframeRef.current.iframeResizer.moveToAnchor(anchor),\n sendMessage: (message: string, targetOrigin?: string) => {\n iframeRef.current.iframeResizer.sendMessage(message, targetOrigin)\n },\n }))\n\n // eslint-disable-next-line jsx-a11y/iframe-has-title\n return <iframe {...filteredProps} ref={iframeRef} />\n}\n\nexport default forwardRef<IFrameForwardRef, IframeResizerProps>(IframeResizer)\n\nexport { type IFrameComponent, type IFrameObject } from '@iframe-resizer/core'\n"],"names":["esModuleInterop","mod","filterIframeAttribs","license","bodyBackground","bodyMargin","bodyPadding","checkOrigin","direction","inPageLinks","log","offset","offsetHeight","offsetWidth","scrolling","tolerance","warningTimeout","waitForLoad","onAfterClose","onReady","onMessage","onResized","iframeProps","createAutoConsoleGroup","acg","IframeResizer","props","ref","logExpand","filteredProps","iframeRef","useRef","consoleGroup","onBeforeClose","useEffect","iframe","resizerOptions","resizer","connectResizer","useImperativeHandle","anchor","message","targetOrigin","React","index","forwardRef"],"mappings":";;;AA2FO,MAAMA,IAAkB,CAAUC;AAAA;AAAA,EAEvCA,GAAK,aAAaA,EAAI,UAAUA;AAAA,GC7FlCC,IAAe,CAAC;AAAA,EACd,SAAAC;AAAA,EACA,gBAAAC;AAAA,EACA,YAAAC;AAAA,EACA,aAAAC;AAAA,EACA,aAAAC;AAAA,EACA,WAAAC;AAAA,EACA,aAAAC;AAAA,EACA,KAAAC;AAAA,EACA,QAAAC;AAAA,EACA,cAAAC;AAAA,EACA,aAAAC;AAAA,EACA,WAAAC;AAAA,EACA,WAAAC;AAAA,EACA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|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iframe-resizer/react",
|
|
3
|
-
"version": "6.0.0-beta.
|
|
3
|
+
"version": "6.0.0-beta.1",
|
|
4
4
|
"license": "GPL-3.0",
|
|
5
5
|
"homepage": "https://iframe-resizer.com",
|
|
6
6
|
"author": {
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"react"
|
|
39
39
|
],
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@iframe-resizer/core": "6.0.0-beta.
|
|
41
|
+
"@iframe-resizer/core": "6.0.0-beta.1",
|
|
42
42
|
"auto-console-group": "1.3.0",
|
|
43
43
|
"react": "^19.2.4"
|
|
44
44
|
}
|