rax-image
Advanced tools
Comparing version 1.0.3 to 1.0.4-beta.1
@@ -1,3 +0,3 @@ | ||
import { Props } from './types'; | ||
declare const _default: import("@rax-types/rax").ForwardRefExoticComponent<Props & import("@rax-types/rax").RefAttributes<unknown>>; | ||
import { ImageProps } from './types'; | ||
declare const _default: import("@rax-types/rax").ForwardRefExoticComponent<Pick<ImageProps, string | number> & import("@rax-types/rax").RefAttributes<HTMLDivElement>>; | ||
export default _default; |
@@ -16,11 +16,20 @@ "use strict"; | ||
var __rest = void 0 && (void 0).__rest || function (s, e) { | ||
var t = {}; | ||
for (var p in s) { | ||
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; | ||
} | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
}; | ||
var Image = function Image(props, ref) { | ||
var _useState = (0, _rax.useState)({}), | ||
var _useState = (0, _rax.useState)(props.source), | ||
source = _useState[0], | ||
setSource = _useState[1]; | ||
var _useState2 = (0, _rax.useState)(false), | ||
isError = _useState2[0], | ||
setIsError = _useState2[1]; | ||
var imgRef = (0, _rax.useRef)(null); | ||
@@ -36,3 +45,2 @@ | ||
setSource(fallbackSource); | ||
setIsError(true); | ||
} | ||
@@ -48,3 +56,7 @@ | ||
if (typeof e.success !== 'undefined') { | ||
if (e.success) onLoad(e);else onError(e); | ||
if (e.success) { | ||
onLoad(e); | ||
} else { | ||
onError(e); | ||
} | ||
} else if (typeof e.currentTarget !== 'undefined') { | ||
@@ -60,17 +72,13 @@ if (e.currentTarget.naturalWidth > 1 && e.currentTarget.naturalHeight > 1) { | ||
(0, _rax.useImperativeHandle)(ref, function () { | ||
return { | ||
_nativeNode: imgRef.current | ||
}; | ||
return imgRef.current; | ||
}); | ||
var nativeProps = Object.assign({}, props); | ||
source = isError ? source : nativeProps.source; // Source must a object | ||
var nativeProps = Object.assign({}, props); // Source must a object | ||
if (source && source.uri) { | ||
var style = nativeProps.style; | ||
var _source = source, | ||
width = _source.width, | ||
height = _source.height, | ||
uri = _source.uri; // Default is 0 | ||
var width = source.width, | ||
height = source.height, | ||
uri = source.uri; // Default is 0 | ||
if (width == null && height == null && style.height == null && style.width == null) { | ||
if (!width && !height && !style.height && !style.width) { | ||
width = 0; | ||
@@ -80,3 +88,3 @@ height = 0; | ||
nativeProps.style = Object.assign({}, Object.assign({ | ||
nativeProps.style = Object.assign(Object.assign({}, Object.assign({ | ||
display: 'flex' | ||
@@ -86,8 +94,7 @@ }, { | ||
height: height | ||
}), style); | ||
})), style); | ||
nativeProps.src = uri; | ||
nativeProps.onLoad = onLoad; | ||
nativeProps.onError = onError; | ||
delete nativeProps.source; | ||
var NativeImage = _universalEnv.isWeex ? 'image' : 'img'; // for cover and contain | ||
delete nativeProps.source; // for cover and contain | ||
@@ -105,9 +112,15 @@ var resizeMode = nativeProps.resizeMode || nativeProps.style.resizeMode; | ||
var children = nativeProps.children, | ||
otherProps = __rest(nativeProps, ["children"]); | ||
var nativeImage = _universalEnv.isWeex ? (0, _rax.createElement)("image", _extends({ | ||
ref: imgRef | ||
}, otherProps)) : (0, _rax.createElement)("img", _extends({ | ||
ref: imgRef | ||
}, otherProps)); | ||
if (props.children) { | ||
nativeProps.children = null; | ||
return (0, _rax.createElement)(_raxView.default, { | ||
style: nativeProps.style | ||
}, (0, _rax.createElement)(NativeImage, _extends({ | ||
ref: imgRef | ||
}, nativeProps)), (0, _rax.createElement)(_raxView.default, { | ||
}, nativeImage, (0, _rax.createElement)(_raxView.default, { | ||
style: { | ||
@@ -118,7 +131,5 @@ left: 0, | ||
} | ||
}, props.children)); | ||
}, children)); | ||
} else { | ||
return (0, _rax.createElement)(NativeImage, _extends({ | ||
ref: imgRef | ||
}, nativeProps)); | ||
return nativeImage; | ||
} | ||
@@ -125,0 +136,0 @@ } |
@@ -1,7 +0,11 @@ | ||
import * as Rax from 'rax'; | ||
import { HTMLAttributes, RefAttributes, CSSProperties, SyntheticEvent } from 'rax'; | ||
export interface Source { | ||
uri?: string; | ||
width?: string | number; | ||
height?: string | number; | ||
} | ||
/** | ||
* props of components | ||
*/ | ||
export interface Props extends Rax.Attributes { | ||
children?: any; | ||
export interface ImageProps extends HTMLAttributes<HTMLImageElement>, RefAttributes<HTMLDivElement> { | ||
/** | ||
@@ -16,3 +20,3 @@ * source: set image uri | ||
*/ | ||
width?: Source; | ||
width?: string | number; | ||
/** | ||
@@ -22,3 +26,3 @@ * height: must for weex | ||
*/ | ||
height?: Source; | ||
height?: string | number; | ||
/** | ||
@@ -28,3 +32,3 @@ * style: style of image | ||
*/ | ||
style?: Rax.CSSProperties; | ||
style?: CSSProperties; | ||
/** | ||
@@ -48,15 +52,10 @@ * fallbackSource: load fallback image when source image load failed | ||
*/ | ||
onLoad?: (e: Event) => void; | ||
onLoad?: (e: ImageLoadEvent) => void; | ||
/** | ||
* callback of failure | ||
*/ | ||
onError?: (e: Event) => void; | ||
onError?: (e: ImageLoadEvent) => void; | ||
} | ||
export interface Event { | ||
[propName: string]: any; | ||
export interface ImageLoadEvent extends SyntheticEvent<HTMLImageElement> { | ||
success?: string; | ||
} | ||
export interface Source { | ||
uri?: string; | ||
width?: string | number; | ||
height?: string | number; | ||
} |
{ | ||
"name": "rax-image", | ||
"version": "1.0.3", | ||
"version": "1.0.4-beta.1", | ||
"description": "Image component for Rax.", | ||
@@ -5,0 +5,0 @@ "license": "BSD-3-Clause", |
@@ -1,8 +0,14 @@ | ||
import * as Rax from 'rax'; | ||
import { HTMLAttributes, RefAttributes, CSSProperties, SyntheticEvent } from 'rax'; | ||
export interface Source { | ||
uri?: string; | ||
width?: string|number; | ||
height?: string|number; | ||
} | ||
/** | ||
* props of components | ||
*/ | ||
export interface Props extends Rax.Attributes { | ||
children?: any; | ||
export interface ImageProps extends HTMLAttributes<HTMLImageElement>, RefAttributes<HTMLDivElement> { | ||
/** | ||
@@ -17,3 +23,3 @@ * source: set image uri | ||
*/ | ||
width?: Source; | ||
width?: string | number; | ||
/** | ||
@@ -23,3 +29,3 @@ * height: must for weex | ||
*/ | ||
height?: Source; | ||
height?: string | number; | ||
/** | ||
@@ -29,3 +35,3 @@ * style: style of image | ||
*/ | ||
style?: Rax.CSSProperties; | ||
style?: CSSProperties; | ||
/** | ||
@@ -49,17 +55,11 @@ * fallbackSource: load fallback image when source image load failed | ||
*/ | ||
onLoad?: (e: Event) => void; | ||
onLoad?: (e: ImageLoadEvent) => void; | ||
/** | ||
* callback of failure | ||
*/ | ||
onError?: (e: Event) => void; | ||
onError?: (e: ImageLoadEvent) => void; | ||
} | ||
export interface Event { | ||
[propName: string]: any; | ||
export interface ImageLoadEvent extends SyntheticEvent<HTMLImageElement>{ | ||
success?: string; | ||
} | ||
export interface Source { | ||
uri?: string; | ||
width?: string|number; | ||
height?: string|number; | ||
} |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
21748
560
1
1