1 | function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
2 |
|
3 | function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
|
4 |
|
5 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
6 |
|
7 | var React = require('react');
|
8 |
|
9 | var PropTypes = require('prop-types');
|
10 |
|
11 | var uppyPropType = require('./propTypes').uppy;
|
12 |
|
13 | var h = React.createElement;
|
14 |
|
15 | var UppyWrapper = function (_React$Component) {
|
16 | _inheritsLoose(UppyWrapper, _React$Component);
|
17 |
|
18 | function UppyWrapper(props) {
|
19 | var _this;
|
20 |
|
21 | _this = _React$Component.call(this, props) || this;
|
22 | _this.refContainer = _this.refContainer.bind(_assertThisInitialized(_this));
|
23 | return _this;
|
24 | }
|
25 |
|
26 | var _proto = UppyWrapper.prototype;
|
27 |
|
28 | _proto.componentDidMount = function componentDidMount() {
|
29 | this.installPlugin();
|
30 | };
|
31 |
|
32 | _proto.componentDidUpdate = function componentDidUpdate(prevProps) {
|
33 | if (prevProps.uppy !== this.props.uppy) {
|
34 | this.uninstallPlugin(prevProps);
|
35 | this.installPlugin();
|
36 | }
|
37 | };
|
38 |
|
39 | _proto.componentWillUnmount = function componentWillUnmount() {
|
40 | this.uninstallPlugin();
|
41 | };
|
42 |
|
43 | _proto.installPlugin = function installPlugin() {
|
44 | var plugin = this.props.uppy.getPlugin(this.props.plugin);
|
45 | plugin.mount(this.container, plugin);
|
46 | };
|
47 |
|
48 | _proto.uninstallPlugin = function uninstallPlugin(props) {
|
49 | if (props === void 0) {
|
50 | props = this.props;
|
51 | }
|
52 |
|
53 | var plugin = props.uppy.getPlugin(this.props.plugin);
|
54 | plugin.unmount();
|
55 | };
|
56 |
|
57 | _proto.refContainer = function refContainer(container) {
|
58 | this.container = container;
|
59 | };
|
60 |
|
61 | _proto.render = function render() {
|
62 | return h('div', {
|
63 | ref: this.refContainer
|
64 | });
|
65 | };
|
66 |
|
67 | return UppyWrapper;
|
68 | }(React.Component);
|
69 |
|
70 | UppyWrapper.propTypes = {
|
71 | uppy: uppyPropType,
|
72 | plugin: PropTypes.string.isRequired
|
73 | };
|
74 | module.exports = UppyWrapper; |
\ | No newline at end of file |