react-split-pane 0.1.75 → 0.1.82
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +809 -0
- package/dist/index.esm.js +805 -0
- package/index.d.ts +1 -1
- package/package.json +57 -31
- package/.editorconfig +0 -6
- package/.idea/jsLibraryMappings.xml +0 -6
- package/.idea/misc.xml +0 -7
- package/.idea/modules.xml +0 -8
- package/.idea/react-split-pane.iml +0 -9
- package/.idea/shelf/Get_Resizer_dimensions/shelved.patch +0 -206
- package/.idea/shelf/Get_Resizer_dimensions.xml +0 -4
- package/.idea/vcs.xml +0 -6
- package/.idea/workspace.xml +0 -1449
- package/.npmignore +0 -4
- package/.travis.yml +0 -10
- package/index.js +0 -3
- package/lib/Pane.js +0 -104
- package/lib/Resizer.js +0 -115
- package/lib/SplitPane.js +0 -417
- package/tsconfig.json +0 -11
- package/yarn.lock +0 -3983
|
@@ -0,0 +1,809 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
4
|
+
|
|
5
|
+
var React = _interopDefault(require('react'));
|
|
6
|
+
var PropTypes = _interopDefault(require('prop-types'));
|
|
7
|
+
var Prefixer = _interopDefault(require('inline-style-prefixer'));
|
|
8
|
+
var stylePropType = _interopDefault(require('react-style-proptype'));
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Copyright (c) 2013-present, Facebook, Inc.
|
|
12
|
+
*
|
|
13
|
+
* This source code is licensed under the MIT license found in the
|
|
14
|
+
* LICENSE file in the root directory of this source tree.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
function componentWillMount() {
|
|
18
|
+
// Call this.constructor.gDSFP to support sub-classes.
|
|
19
|
+
var state = this.constructor.getDerivedStateFromProps(this.props, this.state);
|
|
20
|
+
if (state !== null && state !== undefined) {
|
|
21
|
+
this.setState(state);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function componentWillReceiveProps(nextProps) {
|
|
26
|
+
// Call this.constructor.gDSFP to support sub-classes.
|
|
27
|
+
// Use the setState() updater to ensure state isn't stale in certain edge cases.
|
|
28
|
+
function updater(prevState) {
|
|
29
|
+
var state = this.constructor.getDerivedStateFromProps(nextProps, prevState);
|
|
30
|
+
return state !== null && state !== undefined ? state : null;
|
|
31
|
+
}
|
|
32
|
+
// Binding "this" is important for shallow renderer support.
|
|
33
|
+
this.setState(updater.bind(this));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function componentWillUpdate(nextProps, nextState) {
|
|
37
|
+
try {
|
|
38
|
+
var prevProps = this.props;
|
|
39
|
+
var prevState = this.state;
|
|
40
|
+
this.props = nextProps;
|
|
41
|
+
this.state = nextState;
|
|
42
|
+
this.__reactInternalSnapshotFlag = true;
|
|
43
|
+
this.__reactInternalSnapshot = this.getSnapshotBeforeUpdate(
|
|
44
|
+
prevProps,
|
|
45
|
+
prevState
|
|
46
|
+
);
|
|
47
|
+
} finally {
|
|
48
|
+
this.props = prevProps;
|
|
49
|
+
this.state = prevState;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// React may warn about cWM/cWRP/cWU methods being deprecated.
|
|
54
|
+
// Add a flag to suppress these warnings for this special case.
|
|
55
|
+
componentWillMount.__suppressDeprecationWarning = true;
|
|
56
|
+
componentWillReceiveProps.__suppressDeprecationWarning = true;
|
|
57
|
+
componentWillUpdate.__suppressDeprecationWarning = true;
|
|
58
|
+
|
|
59
|
+
function polyfill(Component) {
|
|
60
|
+
var prototype = Component.prototype;
|
|
61
|
+
|
|
62
|
+
if (!prototype || !prototype.isReactComponent) {
|
|
63
|
+
throw new Error('Can only polyfill class components');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (
|
|
67
|
+
typeof Component.getDerivedStateFromProps !== 'function' &&
|
|
68
|
+
typeof prototype.getSnapshotBeforeUpdate !== 'function'
|
|
69
|
+
) {
|
|
70
|
+
return Component;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// If new component APIs are defined, "unsafe" lifecycles won't be called.
|
|
74
|
+
// Error if any of these lifecycles are present,
|
|
75
|
+
// Because they would work differently between older and newer (16.3+) versions of React.
|
|
76
|
+
var foundWillMountName = null;
|
|
77
|
+
var foundWillReceivePropsName = null;
|
|
78
|
+
var foundWillUpdateName = null;
|
|
79
|
+
if (typeof prototype.componentWillMount === 'function') {
|
|
80
|
+
foundWillMountName = 'componentWillMount';
|
|
81
|
+
} else if (typeof prototype.UNSAFE_componentWillMount === 'function') {
|
|
82
|
+
foundWillMountName = 'UNSAFE_componentWillMount';
|
|
83
|
+
}
|
|
84
|
+
if (typeof prototype.componentWillReceiveProps === 'function') {
|
|
85
|
+
foundWillReceivePropsName = 'componentWillReceiveProps';
|
|
86
|
+
} else if (typeof prototype.UNSAFE_componentWillReceiveProps === 'function') {
|
|
87
|
+
foundWillReceivePropsName = 'UNSAFE_componentWillReceiveProps';
|
|
88
|
+
}
|
|
89
|
+
if (typeof prototype.componentWillUpdate === 'function') {
|
|
90
|
+
foundWillUpdateName = 'componentWillUpdate';
|
|
91
|
+
} else if (typeof prototype.UNSAFE_componentWillUpdate === 'function') {
|
|
92
|
+
foundWillUpdateName = 'UNSAFE_componentWillUpdate';
|
|
93
|
+
}
|
|
94
|
+
if (
|
|
95
|
+
foundWillMountName !== null ||
|
|
96
|
+
foundWillReceivePropsName !== null ||
|
|
97
|
+
foundWillUpdateName !== null
|
|
98
|
+
) {
|
|
99
|
+
var componentName = Component.displayName || Component.name;
|
|
100
|
+
var newApiName =
|
|
101
|
+
typeof Component.getDerivedStateFromProps === 'function'
|
|
102
|
+
? 'getDerivedStateFromProps()'
|
|
103
|
+
: 'getSnapshotBeforeUpdate()';
|
|
104
|
+
|
|
105
|
+
throw Error(
|
|
106
|
+
'Unsafe legacy lifecycles will not be called for components using new component APIs.\n\n' +
|
|
107
|
+
componentName +
|
|
108
|
+
' uses ' +
|
|
109
|
+
newApiName +
|
|
110
|
+
' but also contains the following legacy lifecycles:' +
|
|
111
|
+
(foundWillMountName !== null ? '\n ' + foundWillMountName : '') +
|
|
112
|
+
(foundWillReceivePropsName !== null
|
|
113
|
+
? '\n ' + foundWillReceivePropsName
|
|
114
|
+
: '') +
|
|
115
|
+
(foundWillUpdateName !== null ? '\n ' + foundWillUpdateName : '') +
|
|
116
|
+
'\n\nThe above lifecycles should be removed. Learn more about this warning here:\n' +
|
|
117
|
+
'https://fb.me/react-async-component-lifecycle-hooks'
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// React <= 16.2 does not support static getDerivedStateFromProps.
|
|
122
|
+
// As a workaround, use cWM and cWRP to invoke the new static lifecycle.
|
|
123
|
+
// Newer versions of React will ignore these lifecycles if gDSFP exists.
|
|
124
|
+
if (typeof Component.getDerivedStateFromProps === 'function') {
|
|
125
|
+
prototype.componentWillMount = componentWillMount;
|
|
126
|
+
prototype.componentWillReceiveProps = componentWillReceiveProps;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// React <= 16.2 does not support getSnapshotBeforeUpdate.
|
|
130
|
+
// As a workaround, use cWU to invoke the new lifecycle.
|
|
131
|
+
// Newer versions of React will ignore that lifecycle if gSBU exists.
|
|
132
|
+
if (typeof prototype.getSnapshotBeforeUpdate === 'function') {
|
|
133
|
+
if (typeof prototype.componentDidUpdate !== 'function') {
|
|
134
|
+
throw new Error(
|
|
135
|
+
'Cannot polyfill getSnapshotBeforeUpdate() for components that do not define componentDidUpdate() on the prototype'
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
prototype.componentWillUpdate = componentWillUpdate;
|
|
140
|
+
|
|
141
|
+
var componentDidUpdate = prototype.componentDidUpdate;
|
|
142
|
+
|
|
143
|
+
prototype.componentDidUpdate = function componentDidUpdatePolyfill(
|
|
144
|
+
prevProps,
|
|
145
|
+
prevState,
|
|
146
|
+
maybeSnapshot
|
|
147
|
+
) {
|
|
148
|
+
// 16.3+ will not execute our will-update method;
|
|
149
|
+
// It will pass a snapshot value to did-update though.
|
|
150
|
+
// Older versions will require our polyfilled will-update value.
|
|
151
|
+
// We need to handle both cases, but can't just check for the presence of "maybeSnapshot",
|
|
152
|
+
// Because for <= 15.x versions this might be a "prevContext" object.
|
|
153
|
+
// We also can't just check "__reactInternalSnapshot",
|
|
154
|
+
// Because get-snapshot might return a falsy value.
|
|
155
|
+
// So check for the explicit __reactInternalSnapshotFlag flag to determine behavior.
|
|
156
|
+
var snapshot = this.__reactInternalSnapshotFlag
|
|
157
|
+
? this.__reactInternalSnapshot
|
|
158
|
+
: maybeSnapshot;
|
|
159
|
+
|
|
160
|
+
componentDidUpdate.call(this, prevProps, prevState, snapshot);
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return Component;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
var classCallCheck = function (instance, Constructor) {
|
|
168
|
+
if (!(instance instanceof Constructor)) {
|
|
169
|
+
throw new TypeError("Cannot call a class as a function");
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
var createClass = function () {
|
|
174
|
+
function defineProperties(target, props) {
|
|
175
|
+
for (var i = 0; i < props.length; i++) {
|
|
176
|
+
var descriptor = props[i];
|
|
177
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
178
|
+
descriptor.configurable = true;
|
|
179
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
180
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return function (Constructor, protoProps, staticProps) {
|
|
185
|
+
if (protoProps) defineProperties(Constructor.prototype, protoProps);
|
|
186
|
+
if (staticProps) defineProperties(Constructor, staticProps);
|
|
187
|
+
return Constructor;
|
|
188
|
+
};
|
|
189
|
+
}();
|
|
190
|
+
|
|
191
|
+
var defineProperty = function (obj, key, value) {
|
|
192
|
+
if (key in obj) {
|
|
193
|
+
Object.defineProperty(obj, key, {
|
|
194
|
+
value: value,
|
|
195
|
+
enumerable: true,
|
|
196
|
+
configurable: true,
|
|
197
|
+
writable: true
|
|
198
|
+
});
|
|
199
|
+
} else {
|
|
200
|
+
obj[key] = value;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return obj;
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
var inherits = function (subClass, superClass) {
|
|
207
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
208
|
+
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
212
|
+
constructor: {
|
|
213
|
+
value: subClass,
|
|
214
|
+
enumerable: false,
|
|
215
|
+
writable: true,
|
|
216
|
+
configurable: true
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
var possibleConstructorReturn = function (self, call) {
|
|
223
|
+
if (!self) {
|
|
224
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return call && (typeof call === "object" || typeof call === "function") ? call : self;
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
var DEFAULT_USER_AGENT = 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.2 (KHTML, like Gecko) Safari/537.2';
|
|
231
|
+
var USER_AGENT = typeof navigator !== 'undefined' ? navigator.userAgent : DEFAULT_USER_AGENT;
|
|
232
|
+
|
|
233
|
+
var Pane = function (_React$PureComponent) {
|
|
234
|
+
inherits(Pane, _React$PureComponent);
|
|
235
|
+
|
|
236
|
+
function Pane() {
|
|
237
|
+
classCallCheck(this, Pane);
|
|
238
|
+
return possibleConstructorReturn(this, (Pane.__proto__ || Object.getPrototypeOf(Pane)).apply(this, arguments));
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
createClass(Pane, [{
|
|
242
|
+
key: 'render',
|
|
243
|
+
value: function render() {
|
|
244
|
+
var _props = this.props,
|
|
245
|
+
children = _props.children,
|
|
246
|
+
className = _props.className,
|
|
247
|
+
prefixer = _props.prefixer,
|
|
248
|
+
split = _props.split,
|
|
249
|
+
styleProps = _props.style,
|
|
250
|
+
size = _props.size,
|
|
251
|
+
eleRef = _props.eleRef;
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
var classes = ['Pane', split, className];
|
|
255
|
+
|
|
256
|
+
var style = Object.assign({}, styleProps || {}, {
|
|
257
|
+
flex: 1,
|
|
258
|
+
position: 'relative',
|
|
259
|
+
outline: 'none'
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
if (size !== undefined) {
|
|
263
|
+
if (split === 'vertical') {
|
|
264
|
+
style.width = size;
|
|
265
|
+
} else {
|
|
266
|
+
style.height = size;
|
|
267
|
+
style.display = 'flex';
|
|
268
|
+
}
|
|
269
|
+
style.flex = 'none';
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
return React.createElement(
|
|
273
|
+
'div',
|
|
274
|
+
{
|
|
275
|
+
ref: eleRef,
|
|
276
|
+
className: classes.join(' '),
|
|
277
|
+
style: prefixer.prefix(style)
|
|
278
|
+
},
|
|
279
|
+
children
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
}]);
|
|
283
|
+
return Pane;
|
|
284
|
+
}(React.PureComponent);
|
|
285
|
+
|
|
286
|
+
Pane.propTypes = {
|
|
287
|
+
className: PropTypes.string.isRequired,
|
|
288
|
+
children: PropTypes.node.isRequired,
|
|
289
|
+
prefixer: PropTypes.instanceOf(Prefixer).isRequired,
|
|
290
|
+
size: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
291
|
+
split: PropTypes.oneOf(['vertical', 'horizontal']),
|
|
292
|
+
style: stylePropType,
|
|
293
|
+
eleRef: PropTypes.func
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
Pane.defaultProps = {
|
|
297
|
+
prefixer: new Prefixer({ userAgent: USER_AGENT })
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
var DEFAULT_USER_AGENT$1 = 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.2 (KHTML, like Gecko) Safari/537.2';
|
|
301
|
+
var USER_AGENT$1 = typeof navigator !== 'undefined' ? navigator.userAgent : DEFAULT_USER_AGENT$1;
|
|
302
|
+
var RESIZER_DEFAULT_CLASSNAME = 'Resizer';
|
|
303
|
+
|
|
304
|
+
var Resizer = function (_React$Component) {
|
|
305
|
+
inherits(Resizer, _React$Component);
|
|
306
|
+
|
|
307
|
+
function Resizer() {
|
|
308
|
+
classCallCheck(this, Resizer);
|
|
309
|
+
return possibleConstructorReturn(this, (Resizer.__proto__ || Object.getPrototypeOf(Resizer)).apply(this, arguments));
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
createClass(Resizer, [{
|
|
313
|
+
key: 'render',
|
|
314
|
+
value: function render() {
|
|
315
|
+
var _props = this.props,
|
|
316
|
+
className = _props.className,
|
|
317
|
+
_onClick = _props.onClick,
|
|
318
|
+
_onDoubleClick = _props.onDoubleClick,
|
|
319
|
+
_onMouseDown = _props.onMouseDown,
|
|
320
|
+
_onTouchEnd = _props.onTouchEnd,
|
|
321
|
+
_onTouchStart = _props.onTouchStart,
|
|
322
|
+
prefixer = _props.prefixer,
|
|
323
|
+
resizerClassName = _props.resizerClassName,
|
|
324
|
+
split = _props.split,
|
|
325
|
+
style = _props.style;
|
|
326
|
+
|
|
327
|
+
var classes = [resizerClassName, split, className];
|
|
328
|
+
|
|
329
|
+
return React.createElement('span', {
|
|
330
|
+
className: classes.join(' '),
|
|
331
|
+
style: prefixer.prefix(style) || {},
|
|
332
|
+
onMouseDown: function onMouseDown(event) {
|
|
333
|
+
return _onMouseDown(event);
|
|
334
|
+
},
|
|
335
|
+
onTouchStart: function onTouchStart(event) {
|
|
336
|
+
event.preventDefault();
|
|
337
|
+
_onTouchStart(event);
|
|
338
|
+
},
|
|
339
|
+
onTouchEnd: function onTouchEnd(event) {
|
|
340
|
+
event.preventDefault();
|
|
341
|
+
_onTouchEnd(event);
|
|
342
|
+
},
|
|
343
|
+
onClick: function onClick(event) {
|
|
344
|
+
if (_onClick) {
|
|
345
|
+
event.preventDefault();
|
|
346
|
+
_onClick(event);
|
|
347
|
+
}
|
|
348
|
+
},
|
|
349
|
+
onDoubleClick: function onDoubleClick(event) {
|
|
350
|
+
if (_onDoubleClick) {
|
|
351
|
+
event.preventDefault();
|
|
352
|
+
_onDoubleClick(event);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
}]);
|
|
358
|
+
return Resizer;
|
|
359
|
+
}(React.Component);
|
|
360
|
+
|
|
361
|
+
Resizer.propTypes = {
|
|
362
|
+
className: PropTypes.string.isRequired,
|
|
363
|
+
onClick: PropTypes.func,
|
|
364
|
+
onDoubleClick: PropTypes.func,
|
|
365
|
+
onMouseDown: PropTypes.func.isRequired,
|
|
366
|
+
onTouchStart: PropTypes.func.isRequired,
|
|
367
|
+
onTouchEnd: PropTypes.func.isRequired,
|
|
368
|
+
prefixer: PropTypes.instanceOf(Prefixer).isRequired,
|
|
369
|
+
split: PropTypes.oneOf(['vertical', 'horizontal']),
|
|
370
|
+
style: stylePropType,
|
|
371
|
+
resizerClassName: PropTypes.string.isRequired
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
Resizer.defaultProps = {
|
|
375
|
+
prefixer: new Prefixer({ userAgent: USER_AGENT$1 }),
|
|
376
|
+
resizerClassName: RESIZER_DEFAULT_CLASSNAME
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
var DEFAULT_USER_AGENT$2 = 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.2 (KHTML, like Gecko) Safari/537.2';
|
|
380
|
+
var USER_AGENT$2 = typeof navigator !== 'undefined' ? navigator.userAgent : DEFAULT_USER_AGENT$2;
|
|
381
|
+
|
|
382
|
+
function unFocus(document, window) {
|
|
383
|
+
if (document.selection) {
|
|
384
|
+
document.selection.empty();
|
|
385
|
+
} else {
|
|
386
|
+
try {
|
|
387
|
+
window.getSelection().removeAllRanges();
|
|
388
|
+
// eslint-disable-next-line no-empty
|
|
389
|
+
} catch (e) {}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
function getDefaultSize(defaultSize, minSize, maxSize, draggedSize) {
|
|
394
|
+
if (typeof draggedSize === 'number') {
|
|
395
|
+
var min = typeof minSize === 'number' ? minSize : 0;
|
|
396
|
+
var max = typeof maxSize === 'number' && maxSize >= 0 ? maxSize : Infinity;
|
|
397
|
+
return Math.max(min, Math.min(max, draggedSize));
|
|
398
|
+
}
|
|
399
|
+
if (defaultSize !== undefined) {
|
|
400
|
+
return defaultSize;
|
|
401
|
+
}
|
|
402
|
+
return minSize;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
var SplitPane = function (_React$Component) {
|
|
406
|
+
inherits(SplitPane, _React$Component);
|
|
407
|
+
|
|
408
|
+
function SplitPane(props) {
|
|
409
|
+
classCallCheck(this, SplitPane);
|
|
410
|
+
|
|
411
|
+
var _this = possibleConstructorReturn(this, (SplitPane.__proto__ || Object.getPrototypeOf(SplitPane)).call(this, props));
|
|
412
|
+
|
|
413
|
+
_this.onMouseDown = _this.onMouseDown.bind(_this);
|
|
414
|
+
_this.onTouchStart = _this.onTouchStart.bind(_this);
|
|
415
|
+
_this.onMouseMove = _this.onMouseMove.bind(_this);
|
|
416
|
+
_this.onTouchMove = _this.onTouchMove.bind(_this);
|
|
417
|
+
_this.onMouseUp = _this.onMouseUp.bind(_this);
|
|
418
|
+
|
|
419
|
+
// order of setting panel sizes.
|
|
420
|
+
// 1. size
|
|
421
|
+
// 2. getDefaultSize(defaultSize, minsize, maxSize)
|
|
422
|
+
|
|
423
|
+
var size = props.size,
|
|
424
|
+
defaultSize = props.defaultSize,
|
|
425
|
+
minSize = props.minSize,
|
|
426
|
+
maxSize = props.maxSize,
|
|
427
|
+
primary = props.primary;
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
var initialSize = size !== undefined ? size : getDefaultSize(defaultSize, minSize, maxSize, null);
|
|
431
|
+
|
|
432
|
+
_this.state = {
|
|
433
|
+
active: false,
|
|
434
|
+
resized: false,
|
|
435
|
+
pane1Size: primary === 'first' ? initialSize : undefined,
|
|
436
|
+
pane2Size: primary === 'second' ? initialSize : undefined,
|
|
437
|
+
|
|
438
|
+
// previous props that we need in static methods
|
|
439
|
+
instanceProps: {
|
|
440
|
+
primary: primary,
|
|
441
|
+
size: size,
|
|
442
|
+
defaultSize: defaultSize,
|
|
443
|
+
minSize: minSize,
|
|
444
|
+
maxSize: maxSize
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
return _this;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
createClass(SplitPane, [{
|
|
451
|
+
key: 'componentDidMount',
|
|
452
|
+
value: function componentDidMount() {
|
|
453
|
+
document.addEventListener('mouseup', this.onMouseUp);
|
|
454
|
+
document.addEventListener('mousemove', this.onMouseMove);
|
|
455
|
+
document.addEventListener('touchmove', this.onTouchMove);
|
|
456
|
+
this.setState(SplitPane.setSize(this.props, this.state));
|
|
457
|
+
}
|
|
458
|
+
}, {
|
|
459
|
+
key: 'componentWillUnmount',
|
|
460
|
+
value: function componentWillUnmount() {
|
|
461
|
+
document.removeEventListener('mouseup', this.onMouseUp);
|
|
462
|
+
document.removeEventListener('mousemove', this.onMouseMove);
|
|
463
|
+
document.removeEventListener('touchmove', this.onTouchMove);
|
|
464
|
+
}
|
|
465
|
+
}, {
|
|
466
|
+
key: 'onMouseDown',
|
|
467
|
+
value: function onMouseDown(event) {
|
|
468
|
+
var eventWithTouches = Object.assign({}, event, {
|
|
469
|
+
touches: [{ clientX: event.clientX, clientY: event.clientY }]
|
|
470
|
+
});
|
|
471
|
+
this.onTouchStart(eventWithTouches);
|
|
472
|
+
}
|
|
473
|
+
}, {
|
|
474
|
+
key: 'onTouchStart',
|
|
475
|
+
value: function onTouchStart(event) {
|
|
476
|
+
var _props = this.props,
|
|
477
|
+
allowResize = _props.allowResize,
|
|
478
|
+
onDragStarted = _props.onDragStarted,
|
|
479
|
+
split = _props.split;
|
|
480
|
+
|
|
481
|
+
if (allowResize) {
|
|
482
|
+
unFocus(document, window);
|
|
483
|
+
var position = split === 'vertical' ? event.touches[0].clientX : event.touches[0].clientY;
|
|
484
|
+
|
|
485
|
+
if (typeof onDragStarted === 'function') {
|
|
486
|
+
onDragStarted();
|
|
487
|
+
}
|
|
488
|
+
this.setState({
|
|
489
|
+
active: true,
|
|
490
|
+
position: position
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
}, {
|
|
495
|
+
key: 'onMouseMove',
|
|
496
|
+
value: function onMouseMove(event) {
|
|
497
|
+
var eventWithTouches = Object.assign({}, event, {
|
|
498
|
+
touches: [{ clientX: event.clientX, clientY: event.clientY }]
|
|
499
|
+
});
|
|
500
|
+
this.onTouchMove(eventWithTouches);
|
|
501
|
+
}
|
|
502
|
+
}, {
|
|
503
|
+
key: 'onTouchMove',
|
|
504
|
+
value: function onTouchMove(event) {
|
|
505
|
+
var _props2 = this.props,
|
|
506
|
+
allowResize = _props2.allowResize,
|
|
507
|
+
maxSize = _props2.maxSize,
|
|
508
|
+
minSize = _props2.minSize,
|
|
509
|
+
onChange = _props2.onChange,
|
|
510
|
+
split = _props2.split,
|
|
511
|
+
step = _props2.step;
|
|
512
|
+
var _state = this.state,
|
|
513
|
+
active = _state.active,
|
|
514
|
+
position = _state.position;
|
|
515
|
+
|
|
516
|
+
|
|
517
|
+
if (allowResize && active) {
|
|
518
|
+
unFocus(document, window);
|
|
519
|
+
var isPrimaryFirst = this.props.primary === 'first';
|
|
520
|
+
var ref = isPrimaryFirst ? this.pane1 : this.pane2;
|
|
521
|
+
var ref2 = isPrimaryFirst ? this.pane2 : this.pane1;
|
|
522
|
+
if (ref) {
|
|
523
|
+
var node = ref;
|
|
524
|
+
var node2 = ref2;
|
|
525
|
+
|
|
526
|
+
if (node.getBoundingClientRect) {
|
|
527
|
+
var width = node.getBoundingClientRect().width;
|
|
528
|
+
var height = node.getBoundingClientRect().height;
|
|
529
|
+
var current = split === 'vertical' ? event.touches[0].clientX : event.touches[0].clientY;
|
|
530
|
+
var size = split === 'vertical' ? width : height;
|
|
531
|
+
var positionDelta = position - current;
|
|
532
|
+
if (step) {
|
|
533
|
+
if (Math.abs(positionDelta) < step) {
|
|
534
|
+
return;
|
|
535
|
+
}
|
|
536
|
+
// Integer division
|
|
537
|
+
// eslint-disable-next-line no-bitwise
|
|
538
|
+
positionDelta = ~~(positionDelta / step) * step;
|
|
539
|
+
}
|
|
540
|
+
var sizeDelta = isPrimaryFirst ? positionDelta : -positionDelta;
|
|
541
|
+
|
|
542
|
+
var pane1Order = parseInt(window.getComputedStyle(node).order);
|
|
543
|
+
var pane2Order = parseInt(window.getComputedStyle(node2).order);
|
|
544
|
+
if (pane1Order > pane2Order) {
|
|
545
|
+
sizeDelta = -sizeDelta;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
var newMaxSize = maxSize;
|
|
549
|
+
if (maxSize !== undefined && maxSize <= 0) {
|
|
550
|
+
var splitPane = this.splitPane;
|
|
551
|
+
if (split === 'vertical') {
|
|
552
|
+
newMaxSize = splitPane.getBoundingClientRect().width + maxSize;
|
|
553
|
+
} else {
|
|
554
|
+
newMaxSize = splitPane.getBoundingClientRect().height + maxSize;
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
var newSize = size - sizeDelta;
|
|
559
|
+
var newPosition = position - positionDelta;
|
|
560
|
+
|
|
561
|
+
if (newSize < minSize) {
|
|
562
|
+
newSize = minSize;
|
|
563
|
+
} else if (maxSize !== undefined && newSize > newMaxSize) {
|
|
564
|
+
newSize = newMaxSize;
|
|
565
|
+
} else {
|
|
566
|
+
this.setState({
|
|
567
|
+
position: newPosition,
|
|
568
|
+
resized: true
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
if (onChange) onChange(newSize);
|
|
573
|
+
|
|
574
|
+
this.setState(defineProperty({
|
|
575
|
+
draggedSize: newSize
|
|
576
|
+
}, isPrimaryFirst ? 'pane1Size' : 'pane2Size', newSize));
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
}, {
|
|
582
|
+
key: 'onMouseUp',
|
|
583
|
+
value: function onMouseUp() {
|
|
584
|
+
var _props3 = this.props,
|
|
585
|
+
allowResize = _props3.allowResize,
|
|
586
|
+
onDragFinished = _props3.onDragFinished;
|
|
587
|
+
var _state2 = this.state,
|
|
588
|
+
active = _state2.active,
|
|
589
|
+
draggedSize = _state2.draggedSize;
|
|
590
|
+
|
|
591
|
+
if (allowResize && active) {
|
|
592
|
+
if (typeof onDragFinished === 'function') {
|
|
593
|
+
onDragFinished(draggedSize);
|
|
594
|
+
}
|
|
595
|
+
this.setState({ active: false });
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
// TODO: find a more elegant way to fix this. memoize calls to setSize?
|
|
600
|
+
// we have to check values since gDSFP is called on every render
|
|
601
|
+
|
|
602
|
+
}, {
|
|
603
|
+
key: 'render',
|
|
604
|
+
value: function render() {
|
|
605
|
+
var _this2 = this;
|
|
606
|
+
|
|
607
|
+
var _props4 = this.props,
|
|
608
|
+
allowResize = _props4.allowResize,
|
|
609
|
+
children = _props4.children,
|
|
610
|
+
className = _props4.className,
|
|
611
|
+
onResizerClick = _props4.onResizerClick,
|
|
612
|
+
onResizerDoubleClick = _props4.onResizerDoubleClick,
|
|
613
|
+
paneClassName = _props4.paneClassName,
|
|
614
|
+
pane1ClassName = _props4.pane1ClassName,
|
|
615
|
+
pane2ClassName = _props4.pane2ClassName,
|
|
616
|
+
paneStyle = _props4.paneStyle,
|
|
617
|
+
pane1StyleProps = _props4.pane1Style,
|
|
618
|
+
pane2StyleProps = _props4.pane2Style,
|
|
619
|
+
prefixer = _props4.prefixer,
|
|
620
|
+
resizerClassName = _props4.resizerClassName,
|
|
621
|
+
resizerStyle = _props4.resizerStyle,
|
|
622
|
+
split = _props4.split,
|
|
623
|
+
styleProps = _props4.style;
|
|
624
|
+
var _state3 = this.state,
|
|
625
|
+
pane1Size = _state3.pane1Size,
|
|
626
|
+
pane2Size = _state3.pane2Size;
|
|
627
|
+
|
|
628
|
+
|
|
629
|
+
var disabledClass = allowResize ? '' : 'disabled';
|
|
630
|
+
var resizerClassNamesIncludingDefault = resizerClassName ? resizerClassName + ' ' + RESIZER_DEFAULT_CLASSNAME : resizerClassName;
|
|
631
|
+
|
|
632
|
+
var style = Object.assign({}, {
|
|
633
|
+
display: 'flex',
|
|
634
|
+
flex: 1,
|
|
635
|
+
height: '100%',
|
|
636
|
+
position: 'absolute',
|
|
637
|
+
outline: 'none',
|
|
638
|
+
overflow: 'hidden',
|
|
639
|
+
MozUserSelect: 'text',
|
|
640
|
+
WebkitUserSelect: 'text',
|
|
641
|
+
msUserSelect: 'text',
|
|
642
|
+
userSelect: 'text'
|
|
643
|
+
}, styleProps || {});
|
|
644
|
+
|
|
645
|
+
if (split === 'vertical') {
|
|
646
|
+
Object.assign(style, {
|
|
647
|
+
flexDirection: 'row',
|
|
648
|
+
left: 0,
|
|
649
|
+
right: 0
|
|
650
|
+
});
|
|
651
|
+
} else {
|
|
652
|
+
Object.assign(style, {
|
|
653
|
+
bottom: 0,
|
|
654
|
+
flexDirection: 'column',
|
|
655
|
+
minHeight: '100%',
|
|
656
|
+
top: 0,
|
|
657
|
+
width: '100%'
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
var classes = ['SplitPane', className, split, disabledClass];
|
|
662
|
+
var pane1Style = prefixer.prefix(Object.assign({}, paneStyle || {}, pane1StyleProps || {}));
|
|
663
|
+
var pane2Style = prefixer.prefix(Object.assign({}, paneStyle || {}, pane2StyleProps || {}));
|
|
664
|
+
|
|
665
|
+
var pane1Classes = ['Pane1', paneClassName, pane1ClassName].join(' ');
|
|
666
|
+
var pane2Classes = ['Pane2', paneClassName, pane2ClassName].join(' ');
|
|
667
|
+
|
|
668
|
+
return React.createElement(
|
|
669
|
+
'div',
|
|
670
|
+
{
|
|
671
|
+
className: classes.join(' '),
|
|
672
|
+
ref: function ref(node) {
|
|
673
|
+
_this2.splitPane = node;
|
|
674
|
+
},
|
|
675
|
+
style: prefixer.prefix(style)
|
|
676
|
+
},
|
|
677
|
+
React.createElement(
|
|
678
|
+
Pane,
|
|
679
|
+
{
|
|
680
|
+
className: pane1Classes,
|
|
681
|
+
key: 'pane1',
|
|
682
|
+
eleRef: function eleRef(node) {
|
|
683
|
+
_this2.pane1 = node;
|
|
684
|
+
},
|
|
685
|
+
size: pane1Size,
|
|
686
|
+
split: split,
|
|
687
|
+
style: pane1Style
|
|
688
|
+
},
|
|
689
|
+
children[0]
|
|
690
|
+
),
|
|
691
|
+
React.createElement(Resizer, {
|
|
692
|
+
className: disabledClass,
|
|
693
|
+
onClick: onResizerClick,
|
|
694
|
+
onDoubleClick: onResizerDoubleClick,
|
|
695
|
+
onMouseDown: this.onMouseDown,
|
|
696
|
+
onTouchStart: this.onTouchStart,
|
|
697
|
+
onTouchEnd: this.onMouseUp,
|
|
698
|
+
key: 'resizer',
|
|
699
|
+
resizerClassName: resizerClassNamesIncludingDefault,
|
|
700
|
+
split: split,
|
|
701
|
+
style: resizerStyle || {}
|
|
702
|
+
}),
|
|
703
|
+
React.createElement(
|
|
704
|
+
Pane,
|
|
705
|
+
{
|
|
706
|
+
className: pane2Classes,
|
|
707
|
+
key: 'pane2',
|
|
708
|
+
eleRef: function eleRef(node) {
|
|
709
|
+
_this2.pane2 = node;
|
|
710
|
+
},
|
|
711
|
+
size: pane2Size,
|
|
712
|
+
split: split,
|
|
713
|
+
style: pane2Style
|
|
714
|
+
},
|
|
715
|
+
children[1]
|
|
716
|
+
)
|
|
717
|
+
);
|
|
718
|
+
}
|
|
719
|
+
}], [{
|
|
720
|
+
key: 'getDerivedStateFromProps',
|
|
721
|
+
value: function getDerivedStateFromProps(nextProps, prevState) {
|
|
722
|
+
return SplitPane.setSize(nextProps, prevState);
|
|
723
|
+
}
|
|
724
|
+
}, {
|
|
725
|
+
key: 'setSize',
|
|
726
|
+
value: function setSize(props, state) {
|
|
727
|
+
var instanceProps = state.instanceProps;
|
|
728
|
+
|
|
729
|
+
var newState = {};
|
|
730
|
+
|
|
731
|
+
var newSize = props.size !== undefined ? props.size : getDefaultSize(props.defaultSize, props.minSize, props.maxSize, state.draggedSize);
|
|
732
|
+
|
|
733
|
+
var defaultSizeChanged = props.defaultSize !== instanceProps.defaultSize || props.minSize !== instanceProps.minSize || props.maxSize !== instanceProps.maxSize;
|
|
734
|
+
|
|
735
|
+
var shouldUpdateSize = props.size !== undefined ? props.size !== instanceProps.size : defaultSizeChanged;
|
|
736
|
+
|
|
737
|
+
if (props.size !== undefined && props.size !== state.draggedSize && shouldUpdateSize) {
|
|
738
|
+
newState.draggedSize = newSize;
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
var isPanel1Primary = props.primary === 'first';
|
|
742
|
+
|
|
743
|
+
if (shouldUpdateSize || props.primary !== state.instanceProps.primary) {
|
|
744
|
+
newState[isPanel1Primary ? 'pane1Size' : 'pane2Size'] = newSize;
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
// unset the size on the non primary panel
|
|
748
|
+
if (props.primary !== state.instanceProps.primary) {
|
|
749
|
+
newState[isPanel1Primary ? 'pane2Size' : 'pane1Size'] = undefined;
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
// update the values in instanceProps
|
|
753
|
+
instanceProps.primary = props.primary;
|
|
754
|
+
instanceProps.size = props.size;
|
|
755
|
+
instanceProps.defaultSize = props.defaultSize;
|
|
756
|
+
instanceProps.minSize = props.minSize;
|
|
757
|
+
instanceProps.maxSize = props.maxSize;
|
|
758
|
+
|
|
759
|
+
newState.instanceProps = instanceProps;
|
|
760
|
+
|
|
761
|
+
return newState;
|
|
762
|
+
}
|
|
763
|
+
}]);
|
|
764
|
+
return SplitPane;
|
|
765
|
+
}(React.Component);
|
|
766
|
+
|
|
767
|
+
SplitPane.propTypes = {
|
|
768
|
+
allowResize: PropTypes.bool,
|
|
769
|
+
children: PropTypes.arrayOf(PropTypes.node).isRequired,
|
|
770
|
+
className: PropTypes.string,
|
|
771
|
+
primary: PropTypes.oneOf(['first', 'second']),
|
|
772
|
+
minSize: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
773
|
+
maxSize: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
774
|
+
// eslint-disable-next-line react/no-unused-prop-types
|
|
775
|
+
defaultSize: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
776
|
+
size: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
777
|
+
split: PropTypes.oneOf(['vertical', 'horizontal']),
|
|
778
|
+
onDragStarted: PropTypes.func,
|
|
779
|
+
onDragFinished: PropTypes.func,
|
|
780
|
+
onChange: PropTypes.func,
|
|
781
|
+
onResizerClick: PropTypes.func,
|
|
782
|
+
onResizerDoubleClick: PropTypes.func,
|
|
783
|
+
prefixer: PropTypes.instanceOf(Prefixer).isRequired,
|
|
784
|
+
style: stylePropType,
|
|
785
|
+
resizerStyle: stylePropType,
|
|
786
|
+
paneClassName: PropTypes.string,
|
|
787
|
+
pane1ClassName: PropTypes.string,
|
|
788
|
+
pane2ClassName: PropTypes.string,
|
|
789
|
+
paneStyle: stylePropType,
|
|
790
|
+
pane1Style: stylePropType,
|
|
791
|
+
pane2Style: stylePropType,
|
|
792
|
+
resizerClassName: PropTypes.string,
|
|
793
|
+
step: PropTypes.number
|
|
794
|
+
};
|
|
795
|
+
|
|
796
|
+
SplitPane.defaultProps = {
|
|
797
|
+
allowResize: true,
|
|
798
|
+
minSize: 50,
|
|
799
|
+
prefixer: new Prefixer({ userAgent: USER_AGENT$2 }),
|
|
800
|
+
primary: 'first',
|
|
801
|
+
split: 'vertical',
|
|
802
|
+
paneClassName: '',
|
|
803
|
+
pane1ClassName: '',
|
|
804
|
+
pane2ClassName: ''
|
|
805
|
+
};
|
|
806
|
+
|
|
807
|
+
polyfill(SplitPane);
|
|
808
|
+
|
|
809
|
+
module.exports = SplitPane;
|