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

React: Remove npm dependency for Warning package #1327

Merged
merged 5 commits into from
Sep 2, 2024
Merged
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
43 changes: 16 additions & 27 deletions example/react/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions example/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
"version": "0.0.1",
"type": "module",
"scripts": {
"dev": "vite",
"dev": "vite --force",
"build": "vite build",
"lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"dependencies": {
"@iframe-resizer/child": "^5.2.3",
"@iframe-resizer/core": "^5.2.3",
"@iframe-resizer/react": "^5.2.3",
"@iframe-resizer/child": "^5.3.0-beta.1",
"@iframe-resizer/react": "^5.3.0-beta.1",
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
Expand All @@ -26,4 +25,4 @@
"eslint-plugin-react-refresh": "^0.4.9",
"vite": "^5.3.5"
}
}
}
29 changes: 18 additions & 11 deletions example/react/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import './App.css'
function App() {
const iframeRef = useRef(null)
const [messageData, setMessageData] = useState()
const [show, setShow] = useState(true)

const onResized = (data) => setMessageData(data)

Expand All @@ -20,17 +21,23 @@ function App() {
return (
<>
<h2>@iframe-resizer/react example</h2>
<IframeResizer
license="GPLv3"
log
forwardRef={iframeRef}
inPageLinks
onMessage={onMessage}
onResized={onResized}
src="child/frame.content.html"
style={{ width: '100%', height: '100vh'}}
/>
<MessageData data={messageData} />
<button onClick={() => setShow(!show)}>{show ? 'Hide' : 'Show'}</button>
{show &&
<>
<IframeResizer
license="GPLv3"
log
forwardRef={iframeRef}
inPageLinks
onMessage={onMessage}
onResized={onResized}
src="child/frame.content.html"
style={{ width: '100%', height: '100vh' }}
/>

<MessageData data={messageData} />
</>
}
</>
)
}
Expand Down
5 changes: 3 additions & 2 deletions packages/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -689,8 +689,9 @@ function chkEvent(iframeId, funcName, val) {
}

function removeIframeListeners(iframe) {
const iframeId = iframe.id
delete settings[iframeId]
const { id } = iframe
delete settings[id]
log(id, 'Disconnected from iframe')
}

function closeIFrame(iframe) {
Expand Down
13 changes: 7 additions & 6 deletions packages/react/index.jsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import connectResizer from '@iframe-resizer/core'
import React, { useEffect, useImperativeHandle, useRef } from 'react'
import warning from 'warning'

import filterIframeAttribs from '../common/filter-iframe-attribs'

// TODO: Add support for React.forwardRef() in next major version (Breaking change)
function IframeResizer(props) {
// eslint-disable-next-line react/prop-types
const { title, forwardRef, ...rest } = props
const { forwardRef, ...rest } = props
const filteredProps = filterIframeAttribs(rest)
const iframeRef = useRef(null)

const onClose = () => {
warning(
!iframeRef.current,
console.warn(
`[iframe-resizer/react][${iframeRef?.current?.id}] Close event ignored, to remove the iframe update your React component.`,
)
return !iframeRef.current // Allow React to close this

return false
}

// This hook is only run once, as once iframe-resizer is bound, it will
Expand All @@ -37,7 +37,8 @@ function IframeResizer(props) {
},
}))

return <iframe title={title} {...filteredProps} ref={iframeRef} />
// eslint-disable-next-line jsx-a11y/iframe-has-title
return <iframe {...filteredProps} ref={iframeRef} />
}

export default IframeResizer
2 changes: 1 addition & 1 deletion rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ const npm = [
{
input: 'packages/react/index.jsx',
output: [output('react')('esm'), output('react')('cjs')],
external: ['@iframe-resizer/core', 'react', 'warning', /@babel\/runtime/],
external: ['@iframe-resizer/core', 'react', /@babel\/runtime/],
plugins: [
...pluginsProd('react'),
copy({
Expand Down
Loading