rax-image
Advanced tools
Comparing version 2.3.0 to 2.3.1
# Changelog | ||
## 2.3.1 | ||
- Keep miniapp native code in older dir | ||
- Add `sideEffects: false` in package.json | ||
- Remove `quickappConfig` in package.json | ||
## 2.3.0 | ||
@@ -4,0 +10,0 @@ |
import { isWeb, isWeex, isMiniApp, isWeChatMiniProgram, isByteDanceMicroApp, isBaiduSmartProgram, isKuaiShouMiniProgram } from 'universal-env'; | ||
import ImageWeb from './web'; | ||
import ImageMiniApp from './miniapp'; | ||
import ImageMiniApp from './miniapp-runtime'; | ||
import ImageWeex from './weex'; | ||
@@ -5,0 +5,0 @@ var Image = null; |
@@ -1,4 +0,1 @@ | ||
import { ForwardRefExoticComponent } from 'rax'; | ||
import { ImageProps } from '../types'; | ||
declare const Image: ForwardRefExoticComponent<ImageProps>; | ||
export default Image; | ||
export {}; |
@@ -1,74 +0,67 @@ | ||
var _excluded = ["source", "fallbackSource", "onLoad", "onError", "style", "resizeMode", "loading"]; | ||
import fmtEvent from './fmtEvent'; | ||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
var noop = function () {}; | ||
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } | ||
console.warn('组件所依赖的 rax-image 版本较旧,请尽快重新构建发布该组件'); | ||
Component({ | ||
data: { | ||
styleSheet: '' | ||
}, | ||
props: { | ||
className: '', | ||
style: '', | ||
source: { | ||
uri: '' | ||
}, | ||
mode: 'scaleToFill', | ||
loading: 'eager', | ||
lazyLoad: false, | ||
onClick: noop, | ||
onLoad: noop, | ||
onError: noop | ||
}, | ||
deriveDataFromProps: function deriveDataFromProps(nextProps) { | ||
this.initImage(nextProps); | ||
}, | ||
didMount: function didMount() { | ||
if (!my.canIUse('component2')) { | ||
this.initImage(); | ||
} | ||
}, | ||
didUpdate: function didUpdate() { | ||
if (!my.canIUse('component2')) { | ||
this.initImage(); | ||
} | ||
}, | ||
methods: { | ||
onClick: function onClick(e) { | ||
var event = fmtEvent(this.props, e); | ||
this.props.onClick(event); | ||
}, | ||
onLoad: function onLoad(e) { | ||
var event = fmtEvent(this.props, e); | ||
this.props.onLoad(event); | ||
}, | ||
onError: function onError(e) { | ||
var event = fmtEvent(this.props, e); | ||
this.props.onError(event); | ||
}, | ||
initImage: function initImage(nextProps) { | ||
var props = nextProps || this.props; | ||
import { createElement, useState, useCallback, forwardRef } from 'rax'; | ||
import EMPTY_SOURCE from '../utils/emptySource'; | ||
var Image = forwardRef(function (_ref, ref) { | ||
var source = _ref.source, | ||
fallbackSource = _ref.fallbackSource, | ||
onLoad = _ref.onLoad, | ||
onError = _ref.onError, | ||
style = _ref.style, | ||
resizeMode = _ref.resizeMode, | ||
loading = _ref.loading, | ||
rest = _objectWithoutPropertiesLoose(_ref, _excluded); | ||
var _ref = props.source || {}, | ||
_ref$width = _ref.width, | ||
width = _ref$width === void 0 ? null : _ref$width, | ||
_ref$height = _ref.height, | ||
height = _ref$height === void 0 ? null : _ref$height; | ||
source = source || EMPTY_SOURCE; | ||
fallbackSource = fallbackSource || EMPTY_SOURCE; | ||
var nativeProps = rest; | ||
var _useState = useState({}), | ||
errorState = _useState[0], | ||
setErrorState = _useState[1]; | ||
nativeProps.onError = useCallback(function (e) { | ||
if (errorState.uri === undefined) { | ||
setErrorState({ | ||
uri: source.uri | ||
var style = props.style || ''; | ||
if (width) style += 'width:' + width + 'rpx;'; | ||
if (height) style += 'height:' + height + 'rpx;'; | ||
if (style === this.data.styleSheet) return; | ||
this.setData({ | ||
styleSheet: style | ||
}); | ||
} | ||
onError && onError(e); | ||
}, [source.uri, onError, errorState]); | ||
nativeProps.onLoad = useCallback(function (e) { | ||
// onLoad is triggered by native, so no need to judge | ||
onLoad && onLoad(e); | ||
}, [onLoad, onError]); | ||
if (errorState.uri !== undefined) { | ||
if (errorState.uri !== source.uri) { | ||
errorState.uri = undefined; | ||
} else if (fallbackSource.uri != null) { | ||
source = fallbackSource; | ||
} | ||
} | ||
var _source = source, | ||
width = _source.width, | ||
height = _source.height, | ||
uri = _source.uri; | ||
nativeProps.src = uri; | ||
nativeProps.style = _extends({ | ||
width: width, | ||
height: height | ||
}, style); | ||
if (loading) { | ||
nativeProps['lazy-load'] = loading === 'lazy'; | ||
} // for cover and contain | ||
resizeMode = resizeMode || nativeProps.style.resizeMode; | ||
if (resizeMode) { | ||
nativeProps.style.objectFit = resizeMode; | ||
} | ||
return createElement("img", _extends({}, nativeProps, { | ||
ref: ref | ||
})); | ||
}); | ||
export default Image; | ||
}); |
@@ -11,3 +11,3 @@ "use strict"; | ||
var _miniapp = _interopRequireDefault(require("./miniapp")); | ||
var _miniappRuntime = _interopRequireDefault(require("./miniapp-runtime")); | ||
@@ -32,3 +32,3 @@ var _weex = _interopRequireDefault(require("./weex")); | ||
} else if (_universalEnv.isMiniApp || _universalEnv.isWeChatMiniProgram || _universalEnv.isByteDanceMicroApp || _universalEnv.isBaiduSmartProgram || _universalEnv.isKuaiShouMiniProgram) { | ||
Image = _miniapp.default; | ||
Image = _miniappRuntime.default; | ||
} else if (_universalEnv.isWeex) { | ||
@@ -35,0 +35,0 @@ Image = _weex.default; |
@@ -1,4 +0,1 @@ | ||
import { ForwardRefExoticComponent } from 'rax'; | ||
import { ImageProps } from '../types'; | ||
declare const Image: ForwardRefExoticComponent<ImageProps>; | ||
export default Image; | ||
export {}; |
"use strict"; | ||
exports.__esModule = true; | ||
exports.default = void 0; | ||
var _fmtEvent = _interopRequireDefault(require("./fmtEvent")); | ||
var _rax = require("rax"); | ||
var _emptySource = _interopRequireDefault(require("../utils/emptySource")); | ||
var _excluded = ["source", "fallbackSource", "onLoad", "onError", "style", "resizeMode", "loading"]; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
var noop = function () {}; | ||
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } | ||
console.warn('组件所依赖的 rax-image 版本较旧,请尽快重新构建发布该组件'); | ||
Component({ | ||
data: { | ||
styleSheet: '' | ||
}, | ||
props: { | ||
className: '', | ||
style: '', | ||
source: { | ||
uri: '' | ||
}, | ||
mode: 'scaleToFill', | ||
loading: 'eager', | ||
lazyLoad: false, | ||
onClick: noop, | ||
onLoad: noop, | ||
onError: noop | ||
}, | ||
deriveDataFromProps: function deriveDataFromProps(nextProps) { | ||
this.initImage(nextProps); | ||
}, | ||
didMount: function didMount() { | ||
if (!my.canIUse('component2')) { | ||
this.initImage(); | ||
} | ||
}, | ||
didUpdate: function didUpdate() { | ||
if (!my.canIUse('component2')) { | ||
this.initImage(); | ||
} | ||
}, | ||
methods: { | ||
onClick: function onClick(e) { | ||
var event = (0, _fmtEvent.default)(this.props, e); | ||
this.props.onClick(event); | ||
}, | ||
onLoad: function onLoad(e) { | ||
var event = (0, _fmtEvent.default)(this.props, e); | ||
this.props.onLoad(event); | ||
}, | ||
onError: function onError(e) { | ||
var event = (0, _fmtEvent.default)(this.props, e); | ||
this.props.onError(event); | ||
}, | ||
initImage: function initImage(nextProps) { | ||
var props = nextProps || this.props; | ||
var Image = (0, _rax.forwardRef)(function (_ref, ref) { | ||
var source = _ref.source, | ||
fallbackSource = _ref.fallbackSource, | ||
onLoad = _ref.onLoad, | ||
onError = _ref.onError, | ||
style = _ref.style, | ||
resizeMode = _ref.resizeMode, | ||
loading = _ref.loading, | ||
rest = _objectWithoutPropertiesLoose(_ref, _excluded); | ||
var _ref = props.source || {}, | ||
_ref$width = _ref.width, | ||
width = _ref$width === void 0 ? null : _ref$width, | ||
_ref$height = _ref.height, | ||
height = _ref$height === void 0 ? null : _ref$height; | ||
source = source || _emptySource.default; | ||
fallbackSource = fallbackSource || _emptySource.default; | ||
var nativeProps = rest; | ||
var _useState = (0, _rax.useState)({}), | ||
errorState = _useState[0], | ||
setErrorState = _useState[1]; | ||
nativeProps.onError = (0, _rax.useCallback)(function (e) { | ||
if (errorState.uri === undefined) { | ||
setErrorState({ | ||
uri: source.uri | ||
var style = props.style || ''; | ||
if (width) style += 'width:' + width + 'rpx;'; | ||
if (height) style += 'height:' + height + 'rpx;'; | ||
if (style === this.data.styleSheet) return; | ||
this.setData({ | ||
styleSheet: style | ||
}); | ||
} | ||
onError && onError(e); | ||
}, [source.uri, onError, errorState]); | ||
nativeProps.onLoad = (0, _rax.useCallback)(function (e) { | ||
// onLoad is triggered by native, so no need to judge | ||
onLoad && onLoad(e); | ||
}, [onLoad, onError]); | ||
if (errorState.uri !== undefined) { | ||
if (errorState.uri !== source.uri) { | ||
errorState.uri = undefined; | ||
} else if (fallbackSource.uri != null) { | ||
source = fallbackSource; | ||
} | ||
} | ||
var _source = source, | ||
width = _source.width, | ||
height = _source.height, | ||
uri = _source.uri; | ||
nativeProps.src = uri; | ||
nativeProps.style = _extends({ | ||
width: width, | ||
height: height | ||
}, style); | ||
if (loading) { | ||
nativeProps['lazy-load'] = loading === 'lazy'; | ||
} // for cover and contain | ||
resizeMode = resizeMode || nativeProps.style.resizeMode; | ||
if (resizeMode) { | ||
nativeProps.style.objectFit = resizeMode; | ||
} | ||
return (0, _rax.createElement)("img", _extends({}, nativeProps, { | ||
ref: ref | ||
})); | ||
}); | ||
var _default = Image; | ||
exports.default = _default; | ||
}); |
{ | ||
"name": "rax-image", | ||
"version": "2.3.0", | ||
"version": "2.3.1", | ||
"description": "Image component for Rax.", | ||
@@ -14,2 +14,3 @@ "license": "BSD-3-Clause", | ||
], | ||
"sideEffects": false, | ||
"exports": { | ||
@@ -19,7 +20,7 @@ ".": { | ||
"weex": "./es/weex/index.js", | ||
"miniapp": "./es/miniapp/index.js", | ||
"wechat-miniprogram": "./es/miniapp/index.js", | ||
"bytedance-microapp": "./es/miniapp/index.js", | ||
"baidu-smartprogram": "./es/miniapp/index.js", | ||
"kuaishou-miniprogram": "./es/miniapp/index.js", | ||
"miniapp": "./es/miniapp-runtime/index.js", | ||
"wechat-miniprogram": "./es/miniapp-runtime/index.js", | ||
"bytedance-microapp": "./es/miniapp-runtime/index.js", | ||
"baidu-smartprogram": "./es/miniapp-runtime/index.js", | ||
"kuaishou-miniprogram": "./es/miniapp-runtime/index.js", | ||
"default": "./es/index.js" | ||
@@ -36,5 +37,2 @@ }, | ||
}, | ||
"quickappConfig": { | ||
"main": "lib/quickapp/index" | ||
}, | ||
"scripts": { | ||
@@ -41,0 +39,0 @@ "build": "../../node_modules/.bin/build-scripts build --config ../../build.json --skip-demo", |
87269
89
1398