viewerjs-react
Version:
Typescript supported react wrapper for viewerjs.
65 lines (48 loc) • 1.51 kB
JavaScript
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var React = require('react');
var ViewerJS = _interopDefault(require('viewerjs'));
require('viewerjs/dist/viewer.css');
function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
subClass.__proto__ = superClass;
}
var RViewerJS = /*#__PURE__*/function (_React$PureComponent) {
_inheritsLoose(RViewerJS, _React$PureComponent);
function RViewerJS() {
var _this;
_this = _React$PureComponent.apply(this, arguments) || this;
_this.viewer = null;
_this.onRef = function (el) {
if (!el) {
return;
}
if (_this.viewer) {
_this.viewer.destroy();
}
_this.viewer = new ViewerJS(el, _this.props.options);
};
return _this;
}
var _proto = RViewerJS.prototype;
_proto.componentDidUpdate = function componentDidUpdate() {
if (this.viewer) {
this.viewer.update();
}
};
_proto.componentWillUnmount = function componentWillUnmount() {
if (this.viewer) {
this.viewer.destroy();
}
this.viewer = null;
};
_proto.render = function render() {
return React.createElement("div", {
ref: this.onRef,
className: this.props.className
}, this.props.children);
};
return RViewerJS;
}(React.PureComponent);
module.exports = RViewerJS;
//# sourceMappingURL=index.js.map