/
index.cjs.js
236 lines (192 loc) · 6.75 KB
/
index.cjs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var Marionette = _interopDefault(require('backbone.marionette'));
var React = require('react');
var React__default = _interopDefault(React);
var PropTypes = _interopDefault(require('prop-types'));
var ReactDOM = _interopDefault(require('react-dom'));
var classCallCheck = function (instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
};
var createClass = function () {
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
return function (Constructor, protoProps, staticProps) {
if (protoProps) defineProperties(Constructor.prototype, protoProps);
if (staticProps) defineProperties(Constructor, staticProps);
return Constructor;
};
}();
var inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
};
var possibleConstructorReturn = function (self, call) {
if (!self) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return call && (typeof call === "object" || typeof call === "function") ? call : self;
};
/**
* Developer: Stepan Burguchev
* Date: 2/5/2017
* Copyright: 2015-2017 ApprovalMax
* All Rights Reserved
*
* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF ApprovalMax
* The copyright notice above does not evidence any
* actual or intended publication of such source code.
*/
var MarionetteComponent = function (_Component) {
inherits(MarionetteComponent, _Component);
function MarionetteComponent(props) {
classCallCheck(this, MarionetteComponent);
var _this = possibleConstructorReturn(this, (MarionetteComponent.__proto__ || Object.getPrototypeOf(MarionetteComponent)).call(this, props));
_this._el = React.createRef();
_this._view = null;
_this._hostRegion = null;
_this._regionManager = null;
return _this;
}
createClass(MarionetteComponent, [{
key: 'componentDidMount',
value: function componentDidMount() {
this._regionManager = new Marionette.View();
this._hostRegion = this._regionManager.addRegion('hostRegion', {
el: this._el.current
});
this._rebuildView();
}
}, {
key: 'componentWillReceiveProps',
value: function componentWillReceiveProps(nextProps) {
if (this.props.view !== nextProps.view) {
throw new Error('[MarionetteComponent] error: `props.view` cannot be changed after the initial render.');
}
}
}, {
key: 'componentDidUpdate',
value: function componentDidUpdate(prevProps) {
if (this.props.onUpdateOptions) {
this.props.onUpdateOptions(this._view, prevProps.viewOptions, this.props.viewOptions);
}
if (this._view.shouldViewRebuild && this._view.shouldViewRebuild(this.props.viewOptions)) {
this._rebuildView();
}
}
}, {
key: 'componentWillUnmount',
value: function componentWillUnmount() {
this._regionManager.destroy();
}
}, {
key: 'getRegion',
value: function getRegion() {
return this._hostRegion;
}
}, {
key: '_rebuildView',
value: function _rebuildView() {
if (!this.props.view) {
return;
}
var View = this.props.view;
this._view = new View(this.props.viewOptions);
this._hostRegion.show(this._view);
}
}, {
key: 'render',
value: function render() {
return React__default.createElement('div', { className: this.props.className, ref: this._el });
}
}]);
return MarionetteComponent;
}(React.Component);
MarionetteComponent.propTypes = {
view: PropTypes.func.isRequired,
viewOptions: PropTypes.object,
onUpdateOptions: PropTypes.func,
className: PropTypes.string
};
/**
* Developer: Stepan Burguchev
* Date: 2/5/2017
* Copyright: 2015-2017 ApprovalMax
* All Rights Reserved
*
* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF ApprovalMax
* The copyright notice above does not evidence any
* actual or intended publication of such source code.
*/
var ReactBehavior = Marionette.Behavior.extend({
initialize: function initialize(options) {
if (!options.render) {
throw new Error('Missing options: render');
}
},
onRender: function onRender() {
this._mountReactComponent();
},
onDestroy: function onDestroy() {
if (this._mounted) {
ReactDOM.unmountComponentAtNode(this._getContainerEl());
}
},
_mountReactComponent: function _mountReactComponent() {
ReactDOM.render(this.options.render(), this._getContainerEl());
this._mounted = true;
},
_getContainerEl: function _getContainerEl() {
if (this.options.containerEl) {
return this.$(this.options.containerEl)[0];
}
return this.el;
}
});
/**
* Developer: Stepan Burguchev
* Date: 2/5/2017
* Copyright: 2015-2017 ApprovalMax
* All Rights Reserved
*
* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF ApprovalMax
* The copyright notice above does not evidence any
* actual or intended publication of such source code.
*/
var ReactView = Marionette.View.extend({
initialize: function initialize(options) {},
template: false,
behaviors: function behaviors() {
return {
ReactBehavior: {
behaviorClass: ReactBehavior,
containerEl: null,
render: this.options.render
}
};
}
});
exports.MarionetteComponent = MarionetteComponent;
exports.ReactBehavior = ReactBehavior;
exports.ReactView = ReactView;
//# sourceMappingURL=index.cjs.js.map