-
-
Notifications
You must be signed in to change notification settings - Fork 970
Refactor React #1684
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
Draft
davidjbradshaw
wants to merge
4
commits into
dev
Choose a base branch
from
dev-react-refactore
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+93
−66
Draft
Refactor React #1684
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import type { IFrameComponent } from '@iframe-resizer/core' | ||
| import { type ForwardedRef, type RefObject, useImperativeHandle } from 'react' | ||
|
|
||
| import type { IFrameForwardRef } from './types' | ||
|
|
||
| export default function useForwardedRef( | ||
| ref: ForwardedRef<IFrameForwardRef>, | ||
| iframeRef: RefObject<IFrameComponent>, | ||
| ) { | ||
| useImperativeHandle( | ||
| ref, | ||
| () => ({ | ||
| getRef: () => iframeRef, | ||
| getElement: () => iframeRef.current, | ||
| getVersion: () => iframeRef.current.iframeResizer.getVersion(), | ||
| moveToAnchor: (anchor: string) => | ||
| iframeRef.current.iframeResizer.moveToAnchor(anchor), | ||
| sendMessage: (message: any, targetOrigin?: string) => { | ||
| iframeRef.current.iframeResizer.sendMessage(message, targetOrigin) | ||
| }, | ||
| }), | ||
| [iframeRef], | ||
|
|
||
| ) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import { esModuleInterop } from '@iframe-resizer/common' | ||
| import type { IFrameComponent } from '@iframe-resizer/core' | ||
| import connectResizer from '@iframe-resizer/core' | ||
| import acg from 'auto-console-group' | ||
| import { useEffect, useRef } from 'react' | ||
|
|
||
| import type { IFrameResizerProps } from './types' | ||
|
|
||
| // Deal with UMD not converting default exports to named exports | ||
| const createAutoConsoleGroup = esModuleInterop(acg) | ||
|
|
||
| export default function useResizer(props: IFrameResizerProps) { | ||
| const { log, logExpand } = props | ||
| const iframeRef = useRef<IFrameComponent>(null) | ||
| const consoleGroupRef = | ||
| useRef<ReturnType<typeof createAutoConsoleGroup>>(null) | ||
|
|
||
| if (!consoleGroupRef.current) { | ||
| consoleGroupRef.current = createAutoConsoleGroup() | ||
| } | ||
|
|
||
| const consoleGroup = consoleGroupRef.current | ||
|
|
||
| const onBeforeClose = (): boolean => { | ||
| consoleGroup.event('close') | ||
| consoleGroup.warn( | ||
| `Close event ignored, to remove the iframe update your React component.`, | ||
| ) | ||
|
|
||
| return false | ||
| } | ||
|
|
||
| // This hook is only run once, as once iframe-resizer is bound, it will | ||
| // deal with changes to the element and does not need recalling | ||
| useEffect(() => { | ||
| const iframe = iframeRef.current | ||
|
|
||
| consoleGroup.label(`react(${iframe.id})`) | ||
| consoleGroup.event('setup') | ||
|
|
||
| const resizer = connectResizer({ ...props, onBeforeClose })(iframe) | ||
|
|
||
|
Copilot marked this conversation as resolved.
Outdated
|
||
| consoleGroup.expand(logExpand) | ||
| if (log) consoleGroup.log('Created React component') | ||
|
|
||
| return () => { | ||
| consoleGroup.endAutoGroup() | ||
| resizer?.disconnect() | ||
| } | ||
| }, []) // eslint-disable-line react-hooks/exhaustive-deps | ||
|
davidjbradshaw marked this conversation as resolved.
Dismissed
|
||
|
|
||
| return iframeRef | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.