react-split-pane 0.1.86 → 0.1.92
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/CHANGELOG.md +50 -0
- package/README.md +139 -94
- package/dist/index.cjs.js +707 -0
- package/dist/index.esm.js +701 -0
- package/index.d.ts +26 -8
- package/package.json +52 -39
|
@@ -0,0 +1,707 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
6
|
+
|
|
7
|
+
var React = _interopDefault(require('react'));
|
|
8
|
+
var PropTypes = _interopDefault(require('prop-types'));
|
|
9
|
+
var stylePropType = _interopDefault(require('react-style-proptype'));
|
|
10
|
+
var reactLifecyclesCompat = require('react-lifecycles-compat');
|
|
11
|
+
|
|
12
|
+
function _classCallCheck(instance, Constructor) {
|
|
13
|
+
if (!(instance instanceof Constructor)) {
|
|
14
|
+
throw new TypeError("Cannot call a class as a function");
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function _defineProperties(target, props) {
|
|
19
|
+
for (var i = 0; i < props.length; i++) {
|
|
20
|
+
var descriptor = props[i];
|
|
21
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
22
|
+
descriptor.configurable = true;
|
|
23
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
24
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
29
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
30
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
31
|
+
return Constructor;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function _defineProperty(obj, key, value) {
|
|
35
|
+
if (key in obj) {
|
|
36
|
+
Object.defineProperty(obj, key, {
|
|
37
|
+
value: value,
|
|
38
|
+
enumerable: true,
|
|
39
|
+
configurable: true,
|
|
40
|
+
writable: true
|
|
41
|
+
});
|
|
42
|
+
} else {
|
|
43
|
+
obj[key] = value;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return obj;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function ownKeys(object, enumerableOnly) {
|
|
50
|
+
var keys = Object.keys(object);
|
|
51
|
+
|
|
52
|
+
if (Object.getOwnPropertySymbols) {
|
|
53
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
54
|
+
if (enumerableOnly) symbols = symbols.filter(function (sym) {
|
|
55
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
56
|
+
});
|
|
57
|
+
keys.push.apply(keys, symbols);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return keys;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function _objectSpread2(target) {
|
|
64
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
65
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
66
|
+
|
|
67
|
+
if (i % 2) {
|
|
68
|
+
ownKeys(Object(source), true).forEach(function (key) {
|
|
69
|
+
_defineProperty(target, key, source[key]);
|
|
70
|
+
});
|
|
71
|
+
} else if (Object.getOwnPropertyDescriptors) {
|
|
72
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
73
|
+
} else {
|
|
74
|
+
ownKeys(Object(source)).forEach(function (key) {
|
|
75
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return target;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function _inherits(subClass, superClass) {
|
|
84
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
85
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
89
|
+
constructor: {
|
|
90
|
+
value: subClass,
|
|
91
|
+
writable: true,
|
|
92
|
+
configurable: true
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
if (superClass) _setPrototypeOf(subClass, superClass);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function _getPrototypeOf(o) {
|
|
99
|
+
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
|
|
100
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
101
|
+
};
|
|
102
|
+
return _getPrototypeOf(o);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function _setPrototypeOf(o, p) {
|
|
106
|
+
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
|
|
107
|
+
o.__proto__ = p;
|
|
108
|
+
return o;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
return _setPrototypeOf(o, p);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function _isNativeReflectConstruct() {
|
|
115
|
+
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
116
|
+
if (Reflect.construct.sham) return false;
|
|
117
|
+
if (typeof Proxy === "function") return true;
|
|
118
|
+
|
|
119
|
+
try {
|
|
120
|
+
Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
|
|
121
|
+
return true;
|
|
122
|
+
} catch (e) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function _assertThisInitialized(self) {
|
|
128
|
+
if (self === void 0) {
|
|
129
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return self;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function _possibleConstructorReturn(self, call) {
|
|
136
|
+
if (call && (typeof call === "object" || typeof call === "function")) {
|
|
137
|
+
return call;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return _assertThisInitialized(self);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function _createSuper(Derived) {
|
|
144
|
+
return function () {
|
|
145
|
+
var Super = _getPrototypeOf(Derived),
|
|
146
|
+
result;
|
|
147
|
+
|
|
148
|
+
if (_isNativeReflectConstruct()) {
|
|
149
|
+
var NewTarget = _getPrototypeOf(this).constructor;
|
|
150
|
+
|
|
151
|
+
result = Reflect.construct(Super, arguments, NewTarget);
|
|
152
|
+
} else {
|
|
153
|
+
result = Super.apply(this, arguments);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return _possibleConstructorReturn(this, result);
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
var Pane = /*#__PURE__*/function (_React$PureComponent) {
|
|
161
|
+
_inherits(Pane, _React$PureComponent);
|
|
162
|
+
|
|
163
|
+
var _super = _createSuper(Pane);
|
|
164
|
+
|
|
165
|
+
function Pane() {
|
|
166
|
+
_classCallCheck(this, Pane);
|
|
167
|
+
|
|
168
|
+
return _super.apply(this, arguments);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
_createClass(Pane, [{
|
|
172
|
+
key: "render",
|
|
173
|
+
value: function render() {
|
|
174
|
+
var _this$props = this.props,
|
|
175
|
+
children = _this$props.children,
|
|
176
|
+
className = _this$props.className,
|
|
177
|
+
split = _this$props.split,
|
|
178
|
+
styleProps = _this$props.style,
|
|
179
|
+
size = _this$props.size,
|
|
180
|
+
eleRef = _this$props.eleRef;
|
|
181
|
+
var classes = ['Pane', split, className];
|
|
182
|
+
var style = {
|
|
183
|
+
flex: 1,
|
|
184
|
+
position: 'relative',
|
|
185
|
+
outline: 'none'
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
if (size !== undefined) {
|
|
189
|
+
if (split === 'vertical') {
|
|
190
|
+
style.width = size;
|
|
191
|
+
} else {
|
|
192
|
+
style.height = size;
|
|
193
|
+
style.display = 'flex';
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
style.flex = 'none';
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
style = Object.assign({}, style, styleProps || {});
|
|
200
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
201
|
+
ref: eleRef,
|
|
202
|
+
className: classes.join(' '),
|
|
203
|
+
style: style
|
|
204
|
+
}, children);
|
|
205
|
+
}
|
|
206
|
+
}]);
|
|
207
|
+
|
|
208
|
+
return Pane;
|
|
209
|
+
}(React.PureComponent);
|
|
210
|
+
|
|
211
|
+
Pane.propTypes = {
|
|
212
|
+
className: PropTypes.string.isRequired,
|
|
213
|
+
children: PropTypes.node.isRequired,
|
|
214
|
+
size: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
215
|
+
split: PropTypes.oneOf(['vertical', 'horizontal']),
|
|
216
|
+
style: stylePropType,
|
|
217
|
+
eleRef: PropTypes.func
|
|
218
|
+
};
|
|
219
|
+
Pane.defaultProps = {};
|
|
220
|
+
|
|
221
|
+
var RESIZER_DEFAULT_CLASSNAME = 'Resizer';
|
|
222
|
+
|
|
223
|
+
var Resizer = /*#__PURE__*/function (_React$Component) {
|
|
224
|
+
_inherits(Resizer, _React$Component);
|
|
225
|
+
|
|
226
|
+
var _super = _createSuper(Resizer);
|
|
227
|
+
|
|
228
|
+
function Resizer() {
|
|
229
|
+
_classCallCheck(this, Resizer);
|
|
230
|
+
|
|
231
|
+
return _super.apply(this, arguments);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
_createClass(Resizer, [{
|
|
235
|
+
key: "render",
|
|
236
|
+
value: function render() {
|
|
237
|
+
var _this$props = this.props,
|
|
238
|
+
className = _this$props.className,
|
|
239
|
+
_onClick = _this$props.onClick,
|
|
240
|
+
_onDoubleClick = _this$props.onDoubleClick,
|
|
241
|
+
_onMouseDown = _this$props.onMouseDown,
|
|
242
|
+
_onTouchEnd = _this$props.onTouchEnd,
|
|
243
|
+
_onTouchStart = _this$props.onTouchStart,
|
|
244
|
+
resizerClassName = _this$props.resizerClassName,
|
|
245
|
+
split = _this$props.split,
|
|
246
|
+
style = _this$props.style;
|
|
247
|
+
var classes = [resizerClassName, split, className];
|
|
248
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
249
|
+
role: "presentation",
|
|
250
|
+
className: classes.join(' '),
|
|
251
|
+
style: style,
|
|
252
|
+
onMouseDown: function onMouseDown(event) {
|
|
253
|
+
return _onMouseDown(event);
|
|
254
|
+
},
|
|
255
|
+
onTouchStart: function onTouchStart(event) {
|
|
256
|
+
event.preventDefault();
|
|
257
|
+
|
|
258
|
+
_onTouchStart(event);
|
|
259
|
+
},
|
|
260
|
+
onTouchEnd: function onTouchEnd(event) {
|
|
261
|
+
event.preventDefault();
|
|
262
|
+
|
|
263
|
+
_onTouchEnd(event);
|
|
264
|
+
},
|
|
265
|
+
onClick: function onClick(event) {
|
|
266
|
+
if (_onClick) {
|
|
267
|
+
event.preventDefault();
|
|
268
|
+
|
|
269
|
+
_onClick(event);
|
|
270
|
+
}
|
|
271
|
+
},
|
|
272
|
+
onDoubleClick: function onDoubleClick(event) {
|
|
273
|
+
if (_onDoubleClick) {
|
|
274
|
+
event.preventDefault();
|
|
275
|
+
|
|
276
|
+
_onDoubleClick(event);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
}]);
|
|
282
|
+
|
|
283
|
+
return Resizer;
|
|
284
|
+
}(React.Component);
|
|
285
|
+
|
|
286
|
+
Resizer.propTypes = {
|
|
287
|
+
className: PropTypes.string.isRequired,
|
|
288
|
+
onClick: PropTypes.func,
|
|
289
|
+
onDoubleClick: PropTypes.func,
|
|
290
|
+
onMouseDown: PropTypes.func.isRequired,
|
|
291
|
+
onTouchStart: PropTypes.func.isRequired,
|
|
292
|
+
onTouchEnd: PropTypes.func.isRequired,
|
|
293
|
+
split: PropTypes.oneOf(['vertical', 'horizontal']),
|
|
294
|
+
style: stylePropType,
|
|
295
|
+
resizerClassName: PropTypes.string.isRequired
|
|
296
|
+
};
|
|
297
|
+
Resizer.defaultProps = {
|
|
298
|
+
resizerClassName: RESIZER_DEFAULT_CLASSNAME
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
function unFocus(document, window) {
|
|
302
|
+
if (document.selection) {
|
|
303
|
+
document.selection.empty();
|
|
304
|
+
} else {
|
|
305
|
+
try {
|
|
306
|
+
window.getSelection().removeAllRanges(); // eslint-disable-next-line no-empty
|
|
307
|
+
} catch (e) {}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function getDefaultSize(defaultSize, minSize, maxSize, draggedSize) {
|
|
312
|
+
if (typeof draggedSize === 'number') {
|
|
313
|
+
var min = typeof minSize === 'number' ? minSize : 0;
|
|
314
|
+
var max = typeof maxSize === 'number' && maxSize >= 0 ? maxSize : Infinity;
|
|
315
|
+
return Math.max(min, Math.min(max, draggedSize));
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
if (defaultSize !== undefined) {
|
|
319
|
+
return defaultSize;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
return minSize;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
function removeNullChildren(children) {
|
|
326
|
+
return React.Children.toArray(children).filter(function (c) {
|
|
327
|
+
return c;
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
var SplitPane = /*#__PURE__*/function (_React$Component) {
|
|
332
|
+
_inherits(SplitPane, _React$Component);
|
|
333
|
+
|
|
334
|
+
var _super = _createSuper(SplitPane);
|
|
335
|
+
|
|
336
|
+
function SplitPane(props) {
|
|
337
|
+
var _this;
|
|
338
|
+
|
|
339
|
+
_classCallCheck(this, SplitPane);
|
|
340
|
+
|
|
341
|
+
_this = _super.call(this, props);
|
|
342
|
+
_this.onMouseDown = _this.onMouseDown.bind(_assertThisInitialized(_this));
|
|
343
|
+
_this.onTouchStart = _this.onTouchStart.bind(_assertThisInitialized(_this));
|
|
344
|
+
_this.onMouseMove = _this.onMouseMove.bind(_assertThisInitialized(_this));
|
|
345
|
+
_this.onTouchMove = _this.onTouchMove.bind(_assertThisInitialized(_this));
|
|
346
|
+
_this.onMouseUp = _this.onMouseUp.bind(_assertThisInitialized(_this)); // order of setting panel sizes.
|
|
347
|
+
// 1. size
|
|
348
|
+
// 2. getDefaultSize(defaultSize, minsize, maxSize)
|
|
349
|
+
|
|
350
|
+
var size = props.size,
|
|
351
|
+
defaultSize = props.defaultSize,
|
|
352
|
+
minSize = props.minSize,
|
|
353
|
+
maxSize = props.maxSize,
|
|
354
|
+
primary = props.primary;
|
|
355
|
+
var initialSize = size !== undefined ? size : getDefaultSize(defaultSize, minSize, maxSize, null);
|
|
356
|
+
_this.state = {
|
|
357
|
+
active: false,
|
|
358
|
+
resized: false,
|
|
359
|
+
pane1Size: primary === 'first' ? initialSize : undefined,
|
|
360
|
+
pane2Size: primary === 'second' ? initialSize : undefined,
|
|
361
|
+
// these are props that are needed in static functions. ie: gDSFP
|
|
362
|
+
instanceProps: {
|
|
363
|
+
size: size
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
return _this;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
_createClass(SplitPane, [{
|
|
370
|
+
key: "componentDidMount",
|
|
371
|
+
value: function componentDidMount() {
|
|
372
|
+
document.addEventListener('mouseup', this.onMouseUp);
|
|
373
|
+
document.addEventListener('mousemove', this.onMouseMove);
|
|
374
|
+
document.addEventListener('touchmove', this.onTouchMove);
|
|
375
|
+
this.setState(SplitPane.getSizeUpdate(this.props, this.state));
|
|
376
|
+
}
|
|
377
|
+
}, {
|
|
378
|
+
key: "componentWillUnmount",
|
|
379
|
+
value: function componentWillUnmount() {
|
|
380
|
+
document.removeEventListener('mouseup', this.onMouseUp);
|
|
381
|
+
document.removeEventListener('mousemove', this.onMouseMove);
|
|
382
|
+
document.removeEventListener('touchmove', this.onTouchMove);
|
|
383
|
+
}
|
|
384
|
+
}, {
|
|
385
|
+
key: "onMouseDown",
|
|
386
|
+
value: function onMouseDown(event) {
|
|
387
|
+
var eventWithTouches = Object.assign({}, event, {
|
|
388
|
+
touches: [{
|
|
389
|
+
clientX: event.clientX,
|
|
390
|
+
clientY: event.clientY
|
|
391
|
+
}]
|
|
392
|
+
});
|
|
393
|
+
this.onTouchStart(eventWithTouches);
|
|
394
|
+
}
|
|
395
|
+
}, {
|
|
396
|
+
key: "onTouchStart",
|
|
397
|
+
value: function onTouchStart(event) {
|
|
398
|
+
var _this$props = this.props,
|
|
399
|
+
allowResize = _this$props.allowResize,
|
|
400
|
+
onDragStarted = _this$props.onDragStarted,
|
|
401
|
+
split = _this$props.split;
|
|
402
|
+
|
|
403
|
+
if (allowResize) {
|
|
404
|
+
unFocus(document, window);
|
|
405
|
+
var position = split === 'vertical' ? event.touches[0].clientX : event.touches[0].clientY;
|
|
406
|
+
|
|
407
|
+
if (typeof onDragStarted === 'function') {
|
|
408
|
+
onDragStarted();
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
this.setState({
|
|
412
|
+
active: true,
|
|
413
|
+
position: position
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}, {
|
|
418
|
+
key: "onMouseMove",
|
|
419
|
+
value: function onMouseMove(event) {
|
|
420
|
+
var eventWithTouches = Object.assign({}, event, {
|
|
421
|
+
touches: [{
|
|
422
|
+
clientX: event.clientX,
|
|
423
|
+
clientY: event.clientY
|
|
424
|
+
}]
|
|
425
|
+
});
|
|
426
|
+
this.onTouchMove(eventWithTouches);
|
|
427
|
+
}
|
|
428
|
+
}, {
|
|
429
|
+
key: "onTouchMove",
|
|
430
|
+
value: function onTouchMove(event) {
|
|
431
|
+
var _this$props2 = this.props,
|
|
432
|
+
allowResize = _this$props2.allowResize,
|
|
433
|
+
maxSize = _this$props2.maxSize,
|
|
434
|
+
minSize = _this$props2.minSize,
|
|
435
|
+
onChange = _this$props2.onChange,
|
|
436
|
+
split = _this$props2.split,
|
|
437
|
+
step = _this$props2.step;
|
|
438
|
+
var _this$state = this.state,
|
|
439
|
+
active = _this$state.active,
|
|
440
|
+
position = _this$state.position;
|
|
441
|
+
|
|
442
|
+
if (allowResize && active) {
|
|
443
|
+
unFocus(document, window);
|
|
444
|
+
var isPrimaryFirst = this.props.primary === 'first';
|
|
445
|
+
var ref = isPrimaryFirst ? this.pane1 : this.pane2;
|
|
446
|
+
var ref2 = isPrimaryFirst ? this.pane2 : this.pane1;
|
|
447
|
+
|
|
448
|
+
if (ref) {
|
|
449
|
+
var node = ref;
|
|
450
|
+
var node2 = ref2;
|
|
451
|
+
|
|
452
|
+
if (node.getBoundingClientRect) {
|
|
453
|
+
var width = node.getBoundingClientRect().width;
|
|
454
|
+
var height = node.getBoundingClientRect().height;
|
|
455
|
+
var current = split === 'vertical' ? event.touches[0].clientX : event.touches[0].clientY;
|
|
456
|
+
var size = split === 'vertical' ? width : height;
|
|
457
|
+
var positionDelta = position - current;
|
|
458
|
+
|
|
459
|
+
if (step) {
|
|
460
|
+
if (Math.abs(positionDelta) < step) {
|
|
461
|
+
return;
|
|
462
|
+
} // Integer division
|
|
463
|
+
// eslint-disable-next-line no-bitwise
|
|
464
|
+
|
|
465
|
+
|
|
466
|
+
positionDelta = ~~(positionDelta / step) * step;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
var sizeDelta = isPrimaryFirst ? positionDelta : -positionDelta;
|
|
470
|
+
var pane1Order = parseInt(window.getComputedStyle(node).order);
|
|
471
|
+
var pane2Order = parseInt(window.getComputedStyle(node2).order);
|
|
472
|
+
|
|
473
|
+
if (pane1Order > pane2Order) {
|
|
474
|
+
sizeDelta = -sizeDelta;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
var newMaxSize = maxSize;
|
|
478
|
+
|
|
479
|
+
if (maxSize !== undefined && maxSize <= 0) {
|
|
480
|
+
var splitPane = this.splitPane;
|
|
481
|
+
|
|
482
|
+
if (split === 'vertical') {
|
|
483
|
+
newMaxSize = splitPane.getBoundingClientRect().width + maxSize;
|
|
484
|
+
} else {
|
|
485
|
+
newMaxSize = splitPane.getBoundingClientRect().height + maxSize;
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
var newSize = size - sizeDelta;
|
|
490
|
+
var newPosition = position - positionDelta;
|
|
491
|
+
|
|
492
|
+
if (newSize < minSize) {
|
|
493
|
+
newSize = minSize;
|
|
494
|
+
} else if (maxSize !== undefined && newSize > newMaxSize) {
|
|
495
|
+
newSize = newMaxSize;
|
|
496
|
+
} else {
|
|
497
|
+
this.setState({
|
|
498
|
+
position: newPosition,
|
|
499
|
+
resized: true
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
if (onChange) onChange(newSize);
|
|
504
|
+
this.setState(_defineProperty({
|
|
505
|
+
draggedSize: newSize
|
|
506
|
+
}, isPrimaryFirst ? 'pane1Size' : 'pane2Size', newSize));
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
}, {
|
|
512
|
+
key: "onMouseUp",
|
|
513
|
+
value: function onMouseUp() {
|
|
514
|
+
var _this$props3 = this.props,
|
|
515
|
+
allowResize = _this$props3.allowResize,
|
|
516
|
+
onDragFinished = _this$props3.onDragFinished;
|
|
517
|
+
var _this$state2 = this.state,
|
|
518
|
+
active = _this$state2.active,
|
|
519
|
+
draggedSize = _this$state2.draggedSize;
|
|
520
|
+
|
|
521
|
+
if (allowResize && active) {
|
|
522
|
+
if (typeof onDragFinished === 'function') {
|
|
523
|
+
onDragFinished(draggedSize);
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
this.setState({
|
|
527
|
+
active: false
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
} // we have to check values since gDSFP is called on every render and more in StrictMode
|
|
531
|
+
|
|
532
|
+
}, {
|
|
533
|
+
key: "render",
|
|
534
|
+
value: function render() {
|
|
535
|
+
var _this2 = this;
|
|
536
|
+
|
|
537
|
+
var _this$props4 = this.props,
|
|
538
|
+
allowResize = _this$props4.allowResize,
|
|
539
|
+
children = _this$props4.children,
|
|
540
|
+
className = _this$props4.className,
|
|
541
|
+
onResizerClick = _this$props4.onResizerClick,
|
|
542
|
+
onResizerDoubleClick = _this$props4.onResizerDoubleClick,
|
|
543
|
+
paneClassName = _this$props4.paneClassName,
|
|
544
|
+
pane1ClassName = _this$props4.pane1ClassName,
|
|
545
|
+
pane2ClassName = _this$props4.pane2ClassName,
|
|
546
|
+
paneStyle = _this$props4.paneStyle,
|
|
547
|
+
pane1StyleProps = _this$props4.pane1Style,
|
|
548
|
+
pane2StyleProps = _this$props4.pane2Style,
|
|
549
|
+
resizerClassName = _this$props4.resizerClassName,
|
|
550
|
+
resizerStyle = _this$props4.resizerStyle,
|
|
551
|
+
split = _this$props4.split,
|
|
552
|
+
styleProps = _this$props4.style;
|
|
553
|
+
var _this$state3 = this.state,
|
|
554
|
+
pane1Size = _this$state3.pane1Size,
|
|
555
|
+
pane2Size = _this$state3.pane2Size;
|
|
556
|
+
var disabledClass = allowResize ? '' : 'disabled';
|
|
557
|
+
var resizerClassNamesIncludingDefault = resizerClassName ? "".concat(resizerClassName, " ").concat(RESIZER_DEFAULT_CLASSNAME) : resizerClassName;
|
|
558
|
+
var notNullChildren = removeNullChildren(children);
|
|
559
|
+
|
|
560
|
+
var style = _objectSpread2({
|
|
561
|
+
display: 'flex',
|
|
562
|
+
flex: 1,
|
|
563
|
+
height: '100%',
|
|
564
|
+
position: 'absolute',
|
|
565
|
+
outline: 'none',
|
|
566
|
+
overflow: 'hidden',
|
|
567
|
+
MozUserSelect: 'text',
|
|
568
|
+
WebkitUserSelect: 'text',
|
|
569
|
+
msUserSelect: 'text',
|
|
570
|
+
userSelect: 'text'
|
|
571
|
+
}, styleProps);
|
|
572
|
+
|
|
573
|
+
if (split === 'vertical') {
|
|
574
|
+
Object.assign(style, {
|
|
575
|
+
flexDirection: 'row',
|
|
576
|
+
left: 0,
|
|
577
|
+
right: 0
|
|
578
|
+
});
|
|
579
|
+
} else {
|
|
580
|
+
Object.assign(style, {
|
|
581
|
+
bottom: 0,
|
|
582
|
+
flexDirection: 'column',
|
|
583
|
+
minHeight: '100%',
|
|
584
|
+
top: 0,
|
|
585
|
+
width: '100%'
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
var classes = ['SplitPane', className, split, disabledClass];
|
|
590
|
+
|
|
591
|
+
var pane1Style = _objectSpread2({}, paneStyle, {}, pane1StyleProps);
|
|
592
|
+
|
|
593
|
+
var pane2Style = _objectSpread2({}, paneStyle, {}, pane2StyleProps);
|
|
594
|
+
|
|
595
|
+
var pane1Classes = ['Pane1', paneClassName, pane1ClassName].join(' ');
|
|
596
|
+
var pane2Classes = ['Pane2', paneClassName, pane2ClassName].join(' ');
|
|
597
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
598
|
+
className: classes.join(' '),
|
|
599
|
+
ref: function ref(node) {
|
|
600
|
+
_this2.splitPane = node;
|
|
601
|
+
},
|
|
602
|
+
style: style
|
|
603
|
+
}, /*#__PURE__*/React.createElement(Pane, {
|
|
604
|
+
className: pane1Classes,
|
|
605
|
+
key: "pane1",
|
|
606
|
+
eleRef: function eleRef(node) {
|
|
607
|
+
_this2.pane1 = node;
|
|
608
|
+
},
|
|
609
|
+
size: pane1Size,
|
|
610
|
+
split: split,
|
|
611
|
+
style: pane1Style
|
|
612
|
+
}, notNullChildren[0]), /*#__PURE__*/React.createElement(Resizer, {
|
|
613
|
+
className: disabledClass,
|
|
614
|
+
onClick: onResizerClick,
|
|
615
|
+
onDoubleClick: onResizerDoubleClick,
|
|
616
|
+
onMouseDown: this.onMouseDown,
|
|
617
|
+
onTouchStart: this.onTouchStart,
|
|
618
|
+
onTouchEnd: this.onMouseUp,
|
|
619
|
+
key: "resizer",
|
|
620
|
+
resizerClassName: resizerClassNamesIncludingDefault,
|
|
621
|
+
split: split,
|
|
622
|
+
style: resizerStyle || {}
|
|
623
|
+
}), /*#__PURE__*/React.createElement(Pane, {
|
|
624
|
+
className: pane2Classes,
|
|
625
|
+
key: "pane2",
|
|
626
|
+
eleRef: function eleRef(node) {
|
|
627
|
+
_this2.pane2 = node;
|
|
628
|
+
},
|
|
629
|
+
size: pane2Size,
|
|
630
|
+
split: split,
|
|
631
|
+
style: pane2Style
|
|
632
|
+
}, notNullChildren[1]));
|
|
633
|
+
}
|
|
634
|
+
}], [{
|
|
635
|
+
key: "getDerivedStateFromProps",
|
|
636
|
+
value: function getDerivedStateFromProps(nextProps, prevState) {
|
|
637
|
+
return SplitPane.getSizeUpdate(nextProps, prevState);
|
|
638
|
+
}
|
|
639
|
+
}, {
|
|
640
|
+
key: "getSizeUpdate",
|
|
641
|
+
value: function getSizeUpdate(props, state) {
|
|
642
|
+
var newState = {};
|
|
643
|
+
var instanceProps = state.instanceProps;
|
|
644
|
+
|
|
645
|
+
if (instanceProps.size === props.size && props.size !== undefined) {
|
|
646
|
+
return {};
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
var newSize = props.size !== undefined ? props.size : getDefaultSize(props.defaultSize, props.minSize, props.maxSize, state.draggedSize);
|
|
650
|
+
|
|
651
|
+
if (props.size !== undefined) {
|
|
652
|
+
newState.draggedSize = newSize;
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
var isPanel1Primary = props.primary === 'first';
|
|
656
|
+
newState[isPanel1Primary ? 'pane1Size' : 'pane2Size'] = newSize;
|
|
657
|
+
newState[isPanel1Primary ? 'pane2Size' : 'pane1Size'] = undefined;
|
|
658
|
+
newState.instanceProps = {
|
|
659
|
+
size: props.size
|
|
660
|
+
};
|
|
661
|
+
return newState;
|
|
662
|
+
}
|
|
663
|
+
}]);
|
|
664
|
+
|
|
665
|
+
return SplitPane;
|
|
666
|
+
}(React.Component);
|
|
667
|
+
|
|
668
|
+
SplitPane.propTypes = {
|
|
669
|
+
allowResize: PropTypes.bool,
|
|
670
|
+
children: PropTypes.arrayOf(PropTypes.node).isRequired,
|
|
671
|
+
className: PropTypes.string,
|
|
672
|
+
primary: PropTypes.oneOf(['first', 'second']),
|
|
673
|
+
minSize: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
674
|
+
maxSize: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
675
|
+
// eslint-disable-next-line react/no-unused-prop-types
|
|
676
|
+
defaultSize: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
677
|
+
size: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
678
|
+
split: PropTypes.oneOf(['vertical', 'horizontal']),
|
|
679
|
+
onDragStarted: PropTypes.func,
|
|
680
|
+
onDragFinished: PropTypes.func,
|
|
681
|
+
onChange: PropTypes.func,
|
|
682
|
+
onResizerClick: PropTypes.func,
|
|
683
|
+
onResizerDoubleClick: PropTypes.func,
|
|
684
|
+
style: stylePropType,
|
|
685
|
+
resizerStyle: stylePropType,
|
|
686
|
+
paneClassName: PropTypes.string,
|
|
687
|
+
pane1ClassName: PropTypes.string,
|
|
688
|
+
pane2ClassName: PropTypes.string,
|
|
689
|
+
paneStyle: stylePropType,
|
|
690
|
+
pane1Style: stylePropType,
|
|
691
|
+
pane2Style: stylePropType,
|
|
692
|
+
resizerClassName: PropTypes.string,
|
|
693
|
+
step: PropTypes.number
|
|
694
|
+
};
|
|
695
|
+
SplitPane.defaultProps = {
|
|
696
|
+
allowResize: true,
|
|
697
|
+
minSize: 50,
|
|
698
|
+
primary: 'first',
|
|
699
|
+
split: 'vertical',
|
|
700
|
+
paneClassName: '',
|
|
701
|
+
pane1ClassName: '',
|
|
702
|
+
pane2ClassName: ''
|
|
703
|
+
};
|
|
704
|
+
reactLifecyclesCompat.polyfill(SplitPane);
|
|
705
|
+
|
|
706
|
+
exports.Pane = Pane;
|
|
707
|
+
exports.default = SplitPane;
|