-
-
Notifications
You must be signed in to change notification settings - Fork 982
Refactor core #1548
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
Open
davidjbradshaw
wants to merge
42
commits into
master
Choose a base branch
from
parent_refactor2
base: master
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.
Open
Refactor core #1548
Changes from 34 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
c7764af
Add `both` to Angular directive type
davidjbradshaw 8951821
Refactor
davidjbradshaw a279ffa
Move file
davidjbradshaw 371a19e
Extract title functions from core
davidjbradshaw 3375f5c
Extract createOutgoingMessage()
davidjbradshaw 7416b44
Extract iframeReady()
davidjbradshaw 1ea7486
Extract trigger
davidjbradshaw 4985b98
Extract setOffsetSize()
davidjbradshaw 55e7a37
Extract parent-props
davidjbradshaw 9646eb2
Extract checkEvent
davidjbradshaw c6ffe8c
Extract page-position
davidjbradshaw f2ad2e2
Create `core/page`
davidjbradshaw 61f506e
Fix move of title
davidjbradshaw 807917c
Extract scroll functions
davidjbradshaw 0b6a371
Extract sizing functions from core
davidjbradshaw f909df3
Extract receiver functions
davidjbradshaw 93c4901
Extract mouse events from core
davidjbradshaw d786945
Reorder router
davidjbradshaw 64a62d0
rename function
davidjbradshaw 586bef2
Revert git stash pop
davidjbradshaw d223da5
Extract checks
davidjbradshaw 019c0e6
Extract more checks
davidjbradshaw fe2b8e9
Yet more extracted checks
davidjbradshaw 03b7473
Extract firstRun()
davidjbradshaw dbd48af
Extract inPageLink and fix scrollTo
davidjbradshaw ed7a602
Extract methods from core
davidjbradshaw 9c8d07a
Extract setup props
davidjbradshaw c76b508
Extract setup logging
davidjbradshaw 33a7227
Extract init
davidjbradshaw b8214f2
Extract processOption()
davidjbradshaw 17a873d
Extract getMessageBody()
davidjbradshaw d163e72
Extract message router from core
davidjbradshaw 8d03c4c
receive -> received
davidjbradshaw 2917bae
move on
davidjbradshaw 3874353
Split message.js
davidjbradshaw aa61312
Extract iframe setup from core
davidjbradshaw e3ac761
Extract tabVisible
davidjbradshaw 1eab6bb
Update banner
davidjbradshaw feecf77
isObject()
davidjbradshaw 83a20c4
tidy
davidjbradshaw 713dffe
Tidy
davidjbradshaw 3d679cd
Code Review
davidjbradshaw 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
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
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,32 @@ | ||
| import { isString } from '../../common/utils' | ||
| import { event as consoleEvent, log } from '../console' | ||
| import defaults from '../values/defaults' | ||
|
|
||
| let count = 0 | ||
|
|
||
| function newId(options) { | ||
| let id = options?.id || defaults.id + count++ | ||
|
|
||
| if (document.getElementById(id) !== null) { | ||
| id += count++ | ||
| } | ||
|
|
||
| return id | ||
| } | ||
|
|
||
| export default function ensureHasId(iframe, options) { | ||
| let { id } = iframe | ||
|
|
||
| if (id && !isString(id)) { | ||
| throw new TypeError('Invalid id for iFrame. Expected String') | ||
| } | ||
|
|
||
| if (!id || id === '') { | ||
| id = newId(options) | ||
| iframe.id = id | ||
| consoleEvent(id, 'assignId') | ||
| log(id, `Added missing iframe ID: ${id} (${iframe.src})`) | ||
| } | ||
|
|
||
| return id | ||
| } |
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,10 @@ | ||
| import { COLLAPSE } from '../../common/consts' | ||
|
|
||
| export default function (options) { | ||
| const { search } = window.location | ||
|
|
||
| if (search.includes('ifrlog')) { | ||
| options.log = COLLAPSE | ||
| options.logExpand = search.includes('ifrlog=expanded') | ||
| } | ||
| } |
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,38 @@ | ||
| import { VERSION } from '../../common/consts' | ||
| import { getModeData, getModeLabel } from '../../common/mode' | ||
| import { advise, purge as consoleClear, vInfo } from '../console' | ||
| import settings from '../values/settings' | ||
|
|
||
| let vAdvised = false | ||
| let vInfoDisable = false | ||
|
|
||
| export default function checkMode(id, childMode = -3) { | ||
| if (vAdvised) return | ||
| const mode = Math.max(settings[id].mode, childMode) | ||
| if (mode > settings[id].mode) settings[id].mode = mode | ||
| if (mode < 0) { | ||
| consoleClear(id) | ||
| if (!settings[id].vAdvised) | ||
| advise(id || 'Parent', `${getModeData(mode + 2)}${getModeData(2)}`) | ||
| settings[id].vAdvised = true | ||
| throw getModeData(mode + 2).replace(/<\/?[a-z][^>]*>|<\/>/gi, '') | ||
| } | ||
| if (!(mode > 0 && vInfoDisable)) { | ||
| vInfo(`v${VERSION} (${getModeLabel(mode)})`, mode) | ||
| } | ||
| if (mode < 1) advise('Parent', getModeData(3)) | ||
| vAdvised = true | ||
| } | ||
|
|
||
| export function preModeCheck(id) { | ||
| if (vAdvised) return | ||
| const { mode } = settings[id] | ||
| if (mode !== -1) checkMode(id, mode) | ||
| } | ||
|
|
||
| export function enableVInfo(options) { | ||
| if (options?.log === -1) { | ||
| options.log = false | ||
| vInfoDisable = true | ||
| } | ||
| } | ||
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,28 @@ | ||
| import { | ||
| AUTO_RESIZE, | ||
| BOTH, | ||
| HORIZONTAL, | ||
| NONE, | ||
| VERTICAL, | ||
| } from '../../common/consts' | ||
| import { advise } from '../console' | ||
|
|
||
| export default function checkOptions(id, options) { | ||
| if (!options) return {} | ||
|
|
||
| if ( | ||
| 'sizeWidth' in options || | ||
| 'sizeHeight' in options || | ||
| AUTO_RESIZE in options | ||
| ) { | ||
| advise( | ||
| id, | ||
| `<rb>Deprecated Option</> | ||
|
|
||
| The <b>sizeWidth</>, <b>sizeHeight</> and <b>autoResize</> options have been replaced with new <b>direction</> option which expects values of <bb>${VERTICAL}</>, <bb>${HORIZONTAL}</>, <bb>${BOTH}</> or <bb>${NONE}</>. | ||
| `, | ||
| ) | ||
| } | ||
|
|
||
| return options | ||
| } |
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,15 @@ | ||
| import { HIGHLIGHT } from 'auto-console-group' | ||
|
|
||
| import { log } from '../console' | ||
| import settings from '../values/settings' | ||
|
|
||
| export default function checkSameDomain(id) { | ||
| try { | ||
| settings[id].sameOrigin = | ||
| !!settings[id]?.iframe?.contentWindow?.iframeChildListener | ||
| } catch (error) { | ||
| settings[id].sameOrigin = false | ||
| } | ||
|
|
||
| log(id, `sameOrigin: %c${settings[id].sameOrigin}`, HIGHLIGHT) | ||
| } |
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,27 @@ | ||
| import { FOREGROUND, HIGHLIGHT } from 'auto-console-group' | ||
|
|
||
| import { VERSION } from '../../common/consts' | ||
| import { advise, log } from '../console' | ||
|
|
||
| export default function checkVersion(id, version) { | ||
| if (version === VERSION) return | ||
| if (version === undefined) { | ||
| advise( | ||
| id, | ||
| `<rb>Legacy version detected in iframe</> | ||
|
|
||
| Detected legacy version of child page script. It is recommended to update the page in the iframe to use <b>@iframe-resizer/child</>. | ||
|
|
||
| See <u>https://iframe-resizer.com/setup/#child-page-setup</> for more details. | ||
| `, | ||
| ) | ||
| return | ||
| } | ||
| log( | ||
| id, | ||
| `Version mismatch (Child: %c${version}%c !== Parent: %c${VERSION})`, | ||
| HIGHLIGHT, | ||
| FOREGROUND, | ||
| HIGHLIGHT, | ||
| ) | ||
| } |
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,10 @@ | ||
| import { HIGHLIGHT } from 'auto-console-group' | ||
|
|
||
| import { info } from '../console' | ||
| import settings from '../values/settings' | ||
|
|
||
| export default function checkWarningTimeout(id) { | ||
| if (!settings[id].warningTimeout) { | ||
| info(id, 'warningTimeout:%c disabled', HIGHLIGHT) | ||
| } | ||
| } |
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,28 @@ | ||
| import { SEPARATOR } from '../../common/consts' | ||
| import { getMessageBody } from '../received/message' | ||
| import on from './wrapper' | ||
|
|
||
| export default function onMouse(event, messageData) { | ||
| const { id, iframe, height, type, width } = messageData | ||
| let mousePos = {} | ||
|
|
||
| if (width === 0 && height === 0) { | ||
| const coords = getMessageBody(id, 9).split(SEPARATOR) | ||
| mousePos = { | ||
| x: coords[1], | ||
| y: coords[0], | ||
| } | ||
| } else { | ||
| mousePos = { | ||
| x: width, | ||
| y: height, | ||
| } | ||
| } | ||
|
|
||
| on(id, event, { | ||
| iframe, | ||
| screenX: Number(mousePos.x), | ||
| screenY: Number(mousePos.y), | ||
| type, | ||
| }) | ||
| } |
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,28 @@ | ||
| import { HIGHLIGHT } from 'auto-console-group' | ||
|
|
||
| import { HEIGHT, WIDTH } from '../../common/consts' | ||
| import { info } from '../console' | ||
| import { setPagePosition } from '../page/position' | ||
| import settings from '../values/settings' | ||
| import checkEvent from './wrapper' | ||
|
|
||
| export function setSize(messageData) { | ||
| function setDimension(dimension) { | ||
| const size = `${messageData[dimension]}px` | ||
| messageData.iframe.style[dimension] = size | ||
| info(id, `Set ${dimension}: %c${size}`, HIGHLIGHT) | ||
| } | ||
|
|
||
| const { id } = messageData | ||
| const { sizeHeight, sizeWidth } = settings[id] | ||
|
|
||
| if (sizeHeight) setDimension(HEIGHT) | ||
| if (sizeWidth) setDimension(WIDTH) | ||
| } | ||
|
|
||
| export function resizeIframe(messageData) { | ||
| const { id } = messageData | ||
| setSize(messageData) | ||
| setPagePosition(id) | ||
| checkEvent(id, 'onResized', messageData) | ||
| } |
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,27 @@ | ||
| import { FUNCTION } from '../../common/consts' | ||
| import { isolateUserCode } from '../../common/utils' | ||
| import { warn } from '../console' | ||
| import settings from '../values/settings' | ||
|
|
||
| function on(iframeId, funcName, val) { | ||
| if (!settings[iframeId]) return null | ||
|
|
||
| const func = settings[iframeId][funcName] | ||
|
|
||
| if (typeof func !== FUNCTION) | ||
| throw new TypeError(`${funcName} on iframe[${iframeId}] is not a function`) | ||
|
|
||
| if (funcName !== 'onBeforeClose' && funcName !== 'onScroll') | ||
| return isolateUserCode(func, val) | ||
|
|
||
| try { | ||
| return func(val) | ||
| } catch (error) { | ||
| // eslint-disable-next-line no-console | ||
| console.error(error) | ||
|
||
| warn(iframeId, `Error in ${funcName} callback`) | ||
| return null | ||
| } | ||
| } | ||
|
|
||
| export default on | ||
Oops, something went wrong.
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.