Comparing version 9.0.81 to 9.0.82
{ | ||
"name": "zoid", | ||
"version": "9.0.81", | ||
"version": "9.0.82", | ||
"description": "Cross domain components.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -14,3 +14,3 @@ /* @flow */ | ||
import { getGlobal, destroyGlobal, getInitialParentPayload, isChildComponentWindow } from '../lib'; | ||
import type { CssDimensionsType, StringMatcherType, ContainerReferenceType } from '../types'; | ||
import type { CssDimensionsType, StringMatcherType } from '../types'; | ||
@@ -139,4 +139,4 @@ import { validateOptions } from './validate'; | ||
clone : () => ZoidComponentInstance<P, X, C>, | ||
render : (container? : ContainerReferenceType, context? : $Values<typeof CONTEXT>) => ZalgoPromise<void>, | ||
renderTo : (target : CrossDomainWindowType, container? : ContainerReferenceType, context? : $Values<typeof CONTEXT>) => ZalgoPromise<void> | ||
render : (container? : string | HTMLElement, context? : $Values<typeof CONTEXT>) => ZalgoPromise<void>, | ||
renderTo : (target : CrossDomainWindowType, container? : string | HTMLElement, context? : $Values<typeof CONTEXT>) => ZalgoPromise<void> | ||
|}; | ||
@@ -340,3 +340,3 @@ | ||
const getDefaultContainer = (context : $Values<typeof CONTEXT>, container? : ContainerReferenceType) : ContainerReferenceType => { | ||
const getDefaultContainer = (context : $Values<typeof CONTEXT>, container? : string | HTMLElement) : string | HTMLElement => { | ||
if (container) { | ||
@@ -343,0 +343,0 @@ if (typeof container !== 'string' && !isElement(container)) { |
@@ -118,3 +118,2 @@ /* @flow */ | ||
onError : (mixed) => ZalgoPromise<void>, | ||
container : HTMLElement | void, | ||
event : EventEmitterType | ||
@@ -128,3 +127,2 @@ |}) => ?T, | ||
onError : (mixed) => ZalgoPromise<void>, | ||
container : HTMLElement | void, | ||
event : EventEmitterType | ||
@@ -139,3 +137,2 @@ |}) => ?T, | ||
onError : (mixed) => ZalgoPromise<void>, | ||
container : HTMLElement | void, | ||
event : EventEmitterType | ||
@@ -433,15 +430,18 @@ |}) => T, | ||
type PropCallback<P, X, R> = | ||
((string, BooleanPropDefinitionType<boolean, P, X> | void, boolean) => R) & | ||
((string, StringPropDefinitionType<string, P, X> | void, string) => R) & | ||
((string, NumberPropDefinitionType<number, P, X> | void, number) => R) & | ||
((string, FunctionPropDefinitionType<Function, P, X> | void, Function) => R) & | ||
((string, ArrayPropDefinitionType<$ReadOnlyArray<*> | $ReadOnlyArray<*>, P, X> | void, $ReadOnlyArray<*> | $ReadOnlyArray<*>) => R) & | ||
((string, ObjectPropDefinitionType<Object, P, X> | void, Object) => R); | ||
((string, BooleanPropDefinitionType<boolean, P, X>, boolean) => R) & | ||
((string, StringPropDefinitionType<string, P, X>, string) => R) & | ||
((string, NumberPropDefinitionType<number, P, X>, number) => R) & | ||
((string, FunctionPropDefinitionType<Function, P, X>, Function) => R) & | ||
((string, ArrayPropDefinitionType<$ReadOnlyArray<*> | $ReadOnlyArray<*>, P, X>, $ReadOnlyArray<*> | $ReadOnlyArray<*>) => R) & | ||
((string, ObjectPropDefinitionType<Object, P, X>, Object) => R); | ||
export function eachProp<P, X>(props : PropsType<P>, propsDef : PropsDefinitionType<P, X>, handler : PropCallback<P, X, void>) { | ||
// $FlowFixMe[cannot-spread-indexer] | ||
for (const key of Object.keys({ ...props, ...propsDef })) { | ||
for (const key of Object.keys(props)) { | ||
const propDef = propsDef[key]; | ||
const value = props[key]; | ||
if (!propDef) { | ||
continue; | ||
} | ||
// $FlowFixMe[incompatible-call] | ||
@@ -448,0 +448,0 @@ handler(key, propDef, value); |
@@ -19,3 +19,3 @@ /* @flow */ | ||
import type { ChildExportsType } from '../child'; | ||
import type { CssDimensionsType, ContainerReferenceType } from '../types'; | ||
import type { CssDimensionsType } from '../types'; | ||
import type { NormalizedComponentOptionsType, AttributesType } from '../component'; | ||
@@ -106,3 +106,3 @@ | ||
type RejectInitPromise = (mixed) => ZalgoPromise<void>; | ||
type GetProxyContainer = (container : ContainerReferenceType) => ZalgoPromise<ProxyObject<HTMLElement>>; | ||
type GetProxyContainer = (container : string | HTMLElement) => ZalgoPromise<ProxyObject<HTMLElement>>; | ||
type Show = () => ZalgoPromise<void>; | ||
@@ -164,3 +164,3 @@ type Hide = () => ZalgoPromise<void>; | ||
target : CrossDomainWindowType, | ||
container : ContainerReferenceType, | ||
container : string | HTMLElement, | ||
context : $Values<typeof CONTEXT>, | ||
@@ -211,3 +211,2 @@ rerender : Rerender | ||
let currentChildDomain : ?string; | ||
let currentContainer : HTMLElement | void; | ||
@@ -342,2 +341,18 @@ const onErrorOverride : ?OnError = overrides.onError; | ||
const getProxyContainer : GetProxyContainer = (container : string | HTMLElement) : ZalgoPromise<ProxyObject<HTMLElement>> => { | ||
if (getProxyContainerOverride) { | ||
return getProxyContainerOverride(container); | ||
} | ||
return ZalgoPromise.try(() => { | ||
return elementReady(container); | ||
}).then(containerElement => { | ||
if (isShadowElement(containerElement)) { | ||
containerElement = insertShadowSlot(containerElement); | ||
} | ||
return getProxyObject(containerElement); | ||
}); | ||
}; | ||
const setProxyWin = (proxyWin : ProxyWindow) : ZalgoPromise<void> => { | ||
@@ -919,8 +934,3 @@ if (setProxyWinOverride) { | ||
const getDefaultPropsInput = () : PropsInputType<P> => { | ||
// $FlowFixMe | ||
return {}; | ||
}; | ||
const setProps = (newProps : PropsInputType<P> = getDefaultPropsInput()) => { | ||
const setProps = (newProps : PropsInputType<P>, isUpdate? : boolean = false) => { | ||
if (__DEBUG__ && validate) { | ||
@@ -930,9 +940,8 @@ validate({ props: newProps }); | ||
const container = currentContainer; | ||
const helpers = getHelpers(); | ||
extendProps(propsDef, props, newProps, helpers, container); | ||
extendProps(propsDef, props, newProps, helpers, isUpdate); | ||
}; | ||
const updateProps = (newProps : PropsInputType<P>) : ZalgoPromise<void> => { | ||
setProps(newProps); | ||
setProps(newProps, true); | ||
@@ -960,19 +969,2 @@ return initPromise.then(() => { | ||
const getProxyContainer : GetProxyContainer = (container : ContainerReferenceType) : ZalgoPromise<ProxyObject<HTMLElement>> => { | ||
if (getProxyContainerOverride) { | ||
return getProxyContainerOverride(container); | ||
} | ||
return ZalgoPromise.try(() => { | ||
return elementReady(container); | ||
}).then(containerElement => { | ||
if (isShadowElement(containerElement)) { | ||
containerElement = insertShadowSlot(containerElement); | ||
} | ||
currentContainer = containerElement; | ||
return getProxyObject(containerElement); | ||
}); | ||
}; | ||
const delegate = (context : $Values<typeof CONTEXT>, target : CrossDomainWindowType) : ZalgoPromise<DelegateOverrides> => { | ||
@@ -1036,3 +1028,3 @@ const delegateProps = {}; | ||
const checkAllowRender = (target : CrossDomainWindowType, childDomainMatch : DomainMatcher, container : ContainerReferenceType) => { | ||
const checkAllowRender = (target : CrossDomainWindowType, childDomainMatch : DomainMatcher, container : string | HTMLElement) => { | ||
if (target === window) { | ||
@@ -1078,2 +1070,3 @@ return; | ||
const buildUrlPromise = buildUrl(); | ||
const buildBodyPromise = buildBody(); | ||
@@ -1085,10 +1078,2 @@ const onRenderPromise = event.trigger(EVENT.RENDER); | ||
const finalSetPropsPromise = getProxyContainerPromise.then(() => { | ||
return setProps(); | ||
}); | ||
const buildUrlPromise = finalSetPropsPromise.then(() => { | ||
return buildUrl(); | ||
}); | ||
const buildWindowNamePromise = getProxyWindowPromise.then(proxyWin => { | ||
@@ -1172,3 +1157,3 @@ return buildWindowName({ proxyWin, initialChildDomain, childDomainMatch, target, context }); | ||
openPrerenderPromise, setStatePromise, prerenderPromise, loadUrlPromise, buildWindowNamePromise, setWindowNamePromise, watchForClosePromise, onDisplayPromise, | ||
openBridgePromise, runTimeoutPromise, onRenderedPromise, delegatePromise, watchForUnloadPromise, finalSetPropsPromise | ||
openBridgePromise, runTimeoutPromise, onRenderedPromise, delegatePromise, watchForUnloadPromise | ||
}); | ||
@@ -1175,0 +1160,0 @@ |
/* @flow */ | ||
import { ZalgoPromise } from 'zalgo-promise/src'; | ||
import { dotify, isDefined, base64encode, extend } from 'belter/src'; | ||
import { dotify, isDefined, extend, base64encode } from 'belter/src'; | ||
import { eachProp, mapProps, type PropsInputType, type PropsType, type PropsDefinitionType } from '../component/props'; | ||
import { PROP_SERIALIZATION, METHOD, PROP_TYPE } from '../constants'; | ||
import { PROP_SERIALIZATION, METHOD } from '../constants'; | ||
import type { ParentHelpers } from './index'; | ||
export function extendProps<P, X>(propsDef : PropsDefinitionType<P, X>, existingProps : PropsType<P>, inputProps : PropsInputType<P>, helpers : ParentHelpers<P>, container : HTMLElement | void) { | ||
function getDefaultInputProps<P>() : P { | ||
// $FlowFixMe[incompatible-type] | ||
const defaultInputProps : P = {}; | ||
return defaultInputProps; | ||
} | ||
export function extendProps<P, X>(propsDef : PropsDefinitionType<P, X>, props : PropsType<P>, inputProps : PropsInputType<P>, helpers : ParentHelpers<P>, isUpdate : boolean = false) { | ||
inputProps = inputProps || getDefaultInputProps(); | ||
extend(props, inputProps); | ||
const propNames = isUpdate ? [] : [ ...Object.keys(propsDef) ]; | ||
for (const key of Object.keys(inputProps)) { | ||
if (propNames.indexOf(key) === -1) { | ||
propNames.push(key); | ||
} | ||
} | ||
const aliases = []; | ||
const { state, close, focus, event, onError } = helpers; | ||
const newProps = { ...existingProps }; | ||
for (const key of propNames) { | ||
const propDef = propsDef[key]; | ||
// $FlowFixMe | ||
eachProp(inputProps, propsDef, (key, propDef, value) => { | ||
// $FlowFixMe | ||
let value = inputProps[key]; | ||
if (!propDef) { | ||
// $FlowFixMe | ||
newProps[key] = value; | ||
return; | ||
continue; | ||
} | ||
const alias = propDef.alias; | ||
if (alias && !isDefined(value) && isDefined(inputProps[alias])) { | ||
value = inputProps[alias]; | ||
if (alias) { | ||
if (!isDefined(value) && isDefined(inputProps[alias])) { | ||
value = inputProps[alias]; | ||
} | ||
aliases.push(alias); | ||
} | ||
if (propDef.value) { | ||
value = propDef.value({ props: newProps, state, close, focus, event, onError, container }); | ||
value = propDef.value({ props, state, close, focus, event, onError }); | ||
} | ||
if (propDef.default && !isDefined(value) && !isDefined(newProps[key])) { | ||
value = propDef.default({ props: newProps, state, close, focus, event, onError, container }); | ||
if (!isDefined(value) && propDef.default) { | ||
value = propDef.default({ props, state, close, focus, event, onError }); | ||
} | ||
if (isDefined(value)) { | ||
// $FlowFixMe | ||
newProps[key] = value; | ||
if (propDef.type === 'array' ? !Array.isArray(value) : (typeof value !== propDef.type)) { | ||
throw new TypeError(`Prop is not of type ${ propDef.type }: ${ key }`); | ||
} | ||
} | ||
}); | ||
// $FlowFixMe | ||
props[key] = value; | ||
} | ||
eachProp(newProps, propsDef, (key, propDef, value) => { | ||
for (const alias of aliases) { | ||
delete props[alias]; | ||
} | ||
eachProp(props, propsDef, (key, propDef, value) => { | ||
if (!propDef) { | ||
@@ -49,16 +79,6 @@ return; | ||
if (isDefined(value)) { | ||
if (propDef.type === PROP_TYPE.ARRAY ? !Array.isArray(value) : (typeof value !== propDef.type)) { | ||
throw new TypeError(`Prop is not of type ${ propDef.type }: ${ key }`); | ||
} | ||
} else { | ||
if (propDef.required !== false) { | ||
throw new Error(`Expected prop "${ key }" to be defined`); | ||
} | ||
} | ||
if (__DEBUG__ && isDefined(value) && propDef.validate) { | ||
// $FlowFixMe[incompatible-call] | ||
// $FlowFixMe[incompatible-exact] | ||
propDef.validate({ value, props: newProps }); | ||
propDef.validate({ value, props }); | ||
} | ||
@@ -68,12 +88,16 @@ | ||
// $FlowFixMe[incompatible-call] | ||
const decoratedValue = propDef.decorate({ value, props: newProps, state, close, focus, event, onError, container }); | ||
if (isDefined(decoratedValue)) { | ||
// $FlowFixMe[incompatible-type] | ||
newProps[key] = decoratedValue; | ||
} | ||
const decoratedValue = propDef.decorate({ value, props, state, close, focus, event, onError }); | ||
// $FlowFixMe[incompatible-type] | ||
props[key] = decoratedValue; | ||
} | ||
}); | ||
extend(existingProps, newProps); | ||
for (const key of Object.keys(propsDef)) { | ||
const propDef = propsDef[key]; | ||
// $FlowFixMe | ||
const propVal = props[key]; | ||
if (propDef.required !== false && !isDefined(propVal)) { | ||
throw new Error(`Expected prop "${ key }" to be defined`); | ||
} | ||
} | ||
} | ||
@@ -88,3 +112,3 @@ | ||
if (value === null || typeof value === 'undefined' || !propDef) { | ||
if (value === null || typeof value === 'undefined') { | ||
return; | ||
@@ -91,0 +115,0 @@ } |
@@ -21,3 +21,1 @@ /* @flow */ | ||
export type StringMatcherType = string | $ReadOnlyArray<string> | RegExp; | ||
export type ContainerReferenceType = string | HTMLElement; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
25082
0
3433209