Skip to content

Commit

Permalink
Add consts
Browse files Browse the repository at this point in the history
  • Loading branch information
davidjbradshaw committed Jul 11, 2024
1 parent 9f072db commit 6e5a7b7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
19 changes: 13 additions & 6 deletions packages/child/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { BASE, SINGLE, SIZE_ATTR, VERSION } from '../common/consts'
import {
BASE,
HEIGHT_EDGE,
SINGLE,
SIZE_ATTR,
VERSION,
WIDTH_EDGE,
} from '../common/consts'
import formatAdvise from '../common/format-advise'
import { addEventListener, removeEventListener } from '../common/listeners'
import { getModeData } from '../common/mode'
Expand Down Expand Up @@ -205,7 +212,7 @@ function setupObserveOverflow() {
if (calculateHeight === calculateWidth) return
observeOverflow = overflowObserver({
onChange: once(initContinue),
side: calculateHeight ? 'bottom' : 'right',
side: calculateHeight ? HEIGHT_EDGE : WIDTH_EDGE,
})
}

Expand Down Expand Up @@ -1071,8 +1078,8 @@ const getHeight = {
max: () => Math.max(...getAllMeasurements(getHeight)),
min: () => Math.min(...getAllMeasurements(getHeight)),
grow: () => getHeight.max(),
lowestElement: () => getMaxElement('bottom'),
taggedElement: () => getMaxElement('bottom'),
lowestElement: () => getMaxElement(HEIGHT_EDGE),
taggedElement: () => getMaxElement(HEIGHT_EDGE),
}

const getWidth = {
Expand All @@ -1088,10 +1095,10 @@ const getWidth = {
document.documentElement.getBoundingClientRect().right,
max: () => Math.max(...getAllMeasurements(getWidth)),
min: () => Math.min(...getAllMeasurements(getWidth)),
rightMostElement: () => getMaxElement('right'),
rightMostElement: () => getMaxElement(WIDTH_EDGE),
scroll: () =>
Math.max(getWidth.bodyScroll(), getWidth.documentElementScroll()),
taggedElement: () => getMaxElement('right'),
taggedElement: () => getMaxElement(WIDTH_EDGE),
}

function sizeIFrame(
Expand Down
8 changes: 4 additions & 4 deletions packages/child/overflow.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HEIGHT_EDGE, OVERFLOW_ATTR } from '../common/consts'
import { id } from '../common/utils'

const OVERFLOW = 'data-iframe-overflow'
let side = 'bottom'
let side = HEIGHT_EDGE

let onChange = id

Expand All @@ -20,10 +20,10 @@ const isTarget = (entry) =>

const callback = (entries) => {
entries.forEach((entry) => {
entry.target.toggleAttribute(OVERFLOW, isTarget(entry))
entry.target.toggleAttribute(OVERFLOW_ATTR, isTarget(entry))
})

overflowedElements = document.querySelectorAll(`[${OVERFLOW}]`)
overflowedElements = document.querySelectorAll(`[${OVERFLOW_ATTR}]`)
onChange()
}

Expand Down
5 changes: 5 additions & 0 deletions packages/common/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ export const VERSION = '[VI]{version}[/VI]'

export const BASE = 10
export const SINGLE = 1

export const SIZE_ATTR = 'data-iframe-size'
export const OVERFLOW_ATTR = 'data-iframe-overflow'

export const HEIGHT_EDGE = 'bottom'
export const WIDTH_EDGE = 'right'

export const msgHeader = 'message'
export const msgHeaderLen = msgHeader.length
Expand Down

0 comments on commit 6e5a7b7

Please sign in to comment.