| 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 |
1×
1×
1×
1×
1×
1×
11×
1×
1×
1×
1×
3×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1× | 'use strict';
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
Object.defineProperty(exports, '__esModule', {
value: true
});
var _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;
};
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;Eif ('value' in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor);
}
}return function (Constructor, protoProps, staticProps) {
Eif (protoProps) defineProperties(Constructor.prototype, protoProps);Iif (staticProps) defineProperties(Constructor, staticProps);return Constructor;
};
}();
var _get = function get(_x, _x2, _x3) {
var _again = true;_function: while (_again) {
var object = _x,
property = _x2,
receiver = _x3;_again = false;if (object === null) object = Function.prototype;var desc = Object.getOwnPropertyDescriptor(object, property);if (desc === undefined) {
var parent = Object.getPrototypeOf(object);if (parent === null) {
return undefined;
} else {
_x = parent;_x2 = property;_x3 = receiver;_again = true;desc = parent = undefined;continue _function;
}
} else if ('value' in desc) {
return desc.value;
} else {
var getter = desc.get;if (getter === undefined) {
return undefined;
}return getter.call(receiver);
}
}
};
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : { 'default': obj };
}
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError('Cannot call a class as a function');
}
}
function _inherits(subClass, superClass) {
Iif (typeof superClass !== 'function' && superClass !== null) {
throw new TypeError('Super expression must either be null or a function, not ' + (typeof superClass === 'undefined' ? 'undefined' : _typeof(superClass)));
}subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } });Eif (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
}
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _reactDom = require('react-dom');
var _reactDom2 = _interopRequireDefault(_reactDom);
var _Dialog = require('./Dialog');
var _Dialog2 = _interopRequireDefault(_Dialog);
function noop() {}
function copy(obj, fields) {
var ret = {};
fields.forEach(function (f) {
if (obj[f] !== undefined) {
ret[f] = obj[f];
}
});
return ret;
}
var DialogWrap = function (_React$Component) {
_inherits(DialogWrap, _React$Component);
function DialogWrap(props) {
var _this = this;
_classCallCheck(this, DialogWrap);
_get(Object.getPrototypeOf(DialogWrap.prototype), 'constructor', this).call(this, props);
this.state = {
visible: props.visible
};
['onClose', 'cleanDialogContainer'].forEach(function (m) {
_this[m] = _this[m].bind(_this);
});
}
_createClass(DialogWrap, [{
key: 'componentDidMount',
value: function componentDidMount() {
this.componentDidUpdate();
}
}, {
key: 'componentWillReceiveProps',
value: function componentWillReceiveProps(props) {
if ('visible' in props) {
this.setState({
visible: props.visible
});
}
}
}, {
key: 'shouldComponentUpdate',
value: function shouldComponentUpdate(nextProps, nextState) {
return !!(this.state.visible || nextState.visible);
}
}, {
key: 'componentDidUpdate',
value: function componentDidUpdate() {
if (this.dialogRendered) {
this.dialogInstance = _reactDom2['default'].unstable_renderSubtreeIntoContainer(this, this.getDialogElement(), this.getDialogContainer());
}
}
}, {
key: 'componentWillUnmount',
value: function componentWillUnmount() {
if (this.dialogContainer) {
if (this.state.visible) {
_reactDom2['default'].unstable_renderSubtreeIntoContainer(this, this.getDialogElement({
onAfterClose: this.cleanDialogContainer,
onClose: noop,
visible: false
}), this.dialogContainer);
} else {
this.cleanDialogContainer();
}
}
}
}, {
key: 'onClose',
value: function onClose(e) {
this.props.onClose(e);
}
}, {
key: 'getDialogContainer',
value: function getDialogContainer() {
if (!this.dialogContainer) {
this.dialogContainer = document.createElement('div');
this.dialogContainer.className = this.props.prefixCls + '-container';
document.body.appendChild(this.dialogContainer);
}
return this.dialogContainer;
}
}, {
key: 'getDialogElement',
value: function getDialogElement(extra) {
var props = this.props;
var dialogProps = copy(props, ['className', 'closable', 'maskClosable', 'align', 'title', 'footer', 'mask', 'animation', 'transitionName', 'maskAnimation', 'maskTransitionName', 'mousePosition', 'prefixCls', 'style', 'width', 'height', 'zIndex', 'bodyStyle']);
dialogProps = _extends({}, dialogProps, {
onClose: this.onClose,
visible: this.state.visible
}, extra);
return _react2['default'].createElement(_Dialog2['default'], _extends({}, dialogProps, { key: 'dialog' }), props.children);
}
}, {
key: 'getElement',
value: function getElement(part) {
return this.dialogInstance.getElement(part);
}
}, {
key: 'cleanDialogContainer',
value: function cleanDialogContainer() {
_reactDom2['default'].unmountComponentAtNode(this.getDialogContainer());
document.body.removeChild(this.dialogContainer);
this.dialogContainer = null;
}
}, {
key: 'render',
value: function render() {
this.dialogRendered = this.dialogRendered || this.state.visible;
return null;
}
}]);
return DialogWrap;
}(_react2['default'].Component);
DialogWrap.defaultProps = {
className: '',
align: {
points: ['tc', 'tc'],
offset: [0, 100]
},
mask: true,
closable: true,
maskClosable: true,
prefixCls: 'rc-dialog',
onClose: noop
};
DialogWrap.propTypes = {
className: _react2['default'].PropTypes.string,
align: _react2['default'].PropTypes.shape({
align: _react2['default'].PropTypes.array,
offset: _react2['default'].PropTypes.arrayOf(_react2['default'].PropTypes.number)
}),
mask: _react2['default'].PropTypes.bool,
closable: _react2['default'].PropTypes.bool,
maskClosable: _react2['default'].PropTypes.bool,
prefixCls: _react2['default'].PropTypes.string,
visible: _react2['default'].PropTypes.bool,
onClose: _react2['default'].PropTypes.func
};
exports['default'] = DialogWrap;
module.exports = exports['default']; |