{"name":"react-frame-component","version":"5.3.0","keywords":["React","component","iFrame","browser"],"author":{"name":"Ryan Seddon"},"license":"MIT","_id":"react-frame-component@5.3.0","maintainers":[{"name":"ryanseddon","email":"seddon.ryan@gmail.com"}],"contributors":[{"name":"Chris Trevino","email":"darthtrevino@gmail.com"}],"homepage":"https://github.com/ryanseddon/react-frame-component","bugs":{"url":"https://github.com/ryanseddon/react-frame-component/issues"},"dist":{"shasum":"000dccdb8d27ceeac4f803f273998876da41d555","tarball":"http://registry-npm.ywwl.com/react-frame-component/download/react-frame-component-5.3.0.tgz","fileCount":8,"integrity":"sha512-FWu66kghyOBQZHlr32hVOfAm/PV3+jcDW1J8WMuw/EafyUcYoF3jsL4mMOwTnIVhiJZDxyivMNzKIdHR/n6aYw==","signatures":[{"sig":"MEUCIEWO262wrUrmsVpFGudfguw2SmRDDXCE96RZmMs5dgXIAiEA3Yx4giaKIiDkfLTou82tUkwvoMLBxn6C1C86BpPBeqI=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":220572,"size":62275,"noattachment":false,"key":"/react-frame-component/-/react-frame-component-5.3.0.tgz"},"main":"dist/react-frame-component.umd.js","type":"module","types":"index.d.ts","module":"dist/react-frame-component.esm.js","exports":{".":{"import":"./dist/react-frame-component.esm.js","require":"./dist/react-frame-component.umd.js"}},"gitHead":"c5953ebab7a5e6e6c87dd3fa77c739d7dec2c2bc","scripts":{"lint":"eslint src test","test":"vitest run","build":"vite build","clean":"rimraf dist","serve":"vite --root example","start":"npm run serve","deploy":"gh-pages -d dist","publish":"npm run deploy","release":"changeset version && npm run build","prepublish":"npm run build","test:watch":"vitest","build:example":"vite build --config vite.example.config.js","publish:changesets":"changeset publish"},"_npmUser":{"name":"ryanseddon","email":"seddon.ryan@gmail.com"},"prettier":{"singleQuote":true,"trailingComma":"none"},"repository":{"url":"git://github.com/ryanseddon/react-frame-component.git","type":"git"},"_npmVersion":"11.6.2","description":"React component to wrap your application or component in an iFrame for encapsulation purposes","directories":{},"_nodeVersion":"25.2.1","_hasShrinkwrap":false,"devDependencies":{"react":"^18.2.0","eslint":"^9.0.0","rimraf":"^5.0.5","vitest":"^4.0.18","globals":"^15.0.0","webpack":"^5.90.0","gh-pages":"^6.1.1","prettier":"^3.2.0","react-dom":"^18.2.0","@babel/cli":"^7.24.0","@eslint/js":"^9.0.0","prop-types":"^15.8.1","@babel/core":"^7.24.0","babel-loader":"^9.1.3","@babel/register":"^7.23.0","@changesets/cli":"^2.29.8","@vitest/browser":"^4.0.18","@playwright/test":"^1.58.2","@babel/preset-env":"^7.24.0","webpack-dev-server":"^5.0.0","@babel/preset-react":"^7.24.0","eslint-plugin-react":"^7.34.0","html-webpack-plugin":"^5.6.0","@testing-library/dom":"^10.4.1","@vitejs/plugin-react":"^5.1.4","@testing-library/react":"^16.3.2","eslint-plugin-react-hooks":"^5.0.0","@vitest/browser-playwright":"^4.0.18","eslint-plugin-react-refresh":"^0.4.5","@babel/plugin-proposal-class-properties":"^7.18.6"},"peerDependencies":{"react":">= 16.8 || ^17.0.0 || ^18.0.0 || ^19.0.0","react-dom":">= 16.8 || ^17.0.0 || ^18.0.0 || ^19.0.0","prop-types":"^15.8.1 || ^16.0.0 || ^17.0.0 || ^18.0.0"},"_npmOperationalInternal":{"tmp":"tmp/react-frame-component_5.3.0_1774153567117_0.6644685177734346","host":"s3://npm-registry-packages-npm-production"},"readme":"# React &lt;Frame /> component\n\n[![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][depstat-image]][depstat-url]\n\nThis component allows you to encapsulate your entire React application or per component in an iFrame.\n\n```bash\nnpm install --save react-frame-component\n```\n\n## How to use:\n\n```js\nimport Frame from 'react-frame-component';\n```\n\nGo check out the [demo][demo-url].\n\n```html\nconst Header = ({ children }) => (\n  <Frame>\n    <h1>{children}</h1>\n  </Frame>\n);\n\nReactDOM.render(<Header>Hello</Header>, document.body);\n```\n\nOr you can wrap it at the `render` call.\n\n```html\nReactDOM.render(\n  <Frame>\n    <Header>Hello</Header>\n  </Frame>,\n  document.body\n);\n```\n\n##### Props:\n\n###### head\n`head:  PropTypes.node`\n\nThe `head` prop is a dom node that gets inserted before the children of the frame. Note that this is injected into the body of frame (see the blog post for why). This has the benefit of being able to update and works for stylesheets.\n\n###### initialContent\n`initialContent:  PropTypes.string`\n\nDefaults to `'<!DOCTYPE html><html><head></head><body><div></div></body></html>'`\n\nThe `initialContent` props is the initial html injected into frame. It is only injected once, but allows you to insert any html into the frame (e.g. a head tag, script tags, etc). Note that it does *not* update if you change the prop. Also at least one div is required in the body of the html, which we use to render the react dom into.\n\n###### mountTarget\n`mountTarget:  PropTypes.string`\n\nThe `mountTarget` props is a css selector (#target/.target) that specifies where in the `initialContent` of the iframe, children will be mounted.\n\n```html\n<Frame\n  initialContent='<!DOCTYPE html><html><head></head><body><h1>i wont be changed</h1><div id=\"mountHere\"></div></body></html>'\n  mountTarget='#mountHere'\n  >\n</Frame>\n```\n\n###### dangerouslyUseDocWrite\n`dangerouslyUseDocWrite: PropTypes.bool`\n\nDefaults to `false`\n\nThe frame's initial content, as defined by the `initialContent` prop, is populated via the frame's `srcdoc` attribute by default. However, this can cause issues with some libraries such as Recaptcha and Google Maps that depend on the frame's location/origin. In these cases, setting this flag will cause `Frame` to use `document.write()` to populate the initial content. This is **unperformant and unrecommended**, but allows these libraries to be used inside a `Frame` instance.\n\n###### contentDidMount and contentDidUpdate\n`contentDidMount:  PropTypes.func`\n`contentDidUpdate:  PropTypes.func`\n\n`contentDidMount` and `contentDidUpdate` are conceptually equivalent to\n`componentDidMount` and `componentDidUpdate`, respectively. The reason these are\nneeded is because internally we call `ReactDOM.render` which starts a new set of\nlifecycle calls. This set of lifecycle calls are sometimes triggered after the\nlifecycle of the parent component, so these callbacks provide a hook to know\nwhen the frame contents are mounted and updated.\n\n###### ref\n`ref: PropTypes.oneOfType([ PropTypes.func, PropTypes.shape({ current: PropTypes.instanceOf(Element) }) ])`\n\nThe `ref` prop provides a way to access inner iframe DOM node. To utilitize this prop use, for example, one of the React's built-in methods to create a ref: [`React.createRef()`](https://reactjs.org/docs/refs-and-the-dom.html#creating-refs) or [`React.useRef()`](https://reactjs.org/docs/hooks-reference.html#useref).\n\n```js\nconst MyComponent = (props) => {\n  const iframeRef = React.useRef();\n\n  React.useEffect(() => {\n    // Use iframeRef for:\n    // - focus managing\n    // - triggering imperative animations\n    // - integrating with third-party DOM libraries\n    iframeRef.current.focus()\n  }, [])\n\n  return (\n    <Frame ref={iframeRef}>\n      <InnerComponent />\n    </Frame>\n  );\n}\n```\n\n##### Accessing the iframe's window and document\nThe iframe's `window` and `document` may be accessed via the `FrameContextConsumer` or the `useFrame` hook.\n\nThe example with `FrameContextConsumer`:\n\n```js\nimport Frame, { FrameContextConsumer } from 'react-frame-component'\n\nconst MyComponent = (props, context) => (\n  <Frame>\n    <FrameContextConsumer>\n      {\n        // Callback is invoked with iframe's window and document instances\n        ({document, window}) => {\n          // Render Children\n        }\n      }\n    </FrameContextConsumer>\n  </Frame>\n);\n\n```\n\nThe example with `useFrame` hook:\n\n```js\nimport Frame, { useFrame } from 'react-frame-component';\n\nconst InnerComponent = () => {\n  // Hook returns iframe's window and document instances from Frame context\n  const { document, window } = useFrame();\n\n  return null;\n};\n\nconst OuterComponent = () => (\n  <Frame>\n    <InnerComponent />\n  </Frame>\n);\n```\n\n## More info\n\nI wrote a [blog post][blog-url] about building this component.\n\n## License\n\nCopyright 2014, Ryan Seddon.\nThis content is released under the MIT license http://ryanseddon.mit-license.org\n\n[npm-url]: https://npmjs.org/package/react-frame-component\n[npm-image]: https://badge.fury.io/js/react-frame-component.png\n\n[travis-url]: http://travis-ci.org/ryanseddon/react-frame-component\n[travis-image]: https://secure.travis-ci.org/ryanseddon/react-frame-component.png?branch=master\n\n[depstat-url]: https://david-dm.org/ryanseddon/react-frame-component\n[depstat-image]: https://david-dm.org/ryanseddon/react-frame-component.png\n\n[demo-url]: http://ryanseddon.github.io/react-frame-component/\n[blog-url]: https://medium.com/@ryanseddon/rendering-to-iframes-in-react-d1cb92274f86\n","publish_time":1774153567276,"_cnpm_publish_time":1774153567276,"dist-tags":{"alpha":"5.2.3-alpha.0","canary":"0.0.0-canary-20260323223911","latest":"5.3.2"}}