react-split-pane 0.1.81 → 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 CHANGED
@@ -6,7 +6,6 @@ var React = _interopDefault(require('react'));
6
6
  var PropTypes = _interopDefault(require('prop-types'));
7
7
  var Prefixer = _interopDefault(require('inline-style-prefixer'));
8
8
  var stylePropType = _interopDefault(require('react-style-proptype'));
9
- var ReactDOM = _interopDefault(require('react-dom'));
10
9
 
11
10
  /**
12
11
  * Copyright (c) 2013-present, Facebook, Inc.
@@ -248,7 +247,8 @@ var Pane = function (_React$PureComponent) {
248
247
  prefixer = _props.prefixer,
249
248
  split = _props.split,
250
249
  styleProps = _props.style,
251
- size = _props.size;
250
+ size = _props.size,
251
+ eleRef = _props.eleRef;
252
252
 
253
253
 
254
254
  var classes = ['Pane', split, className];
@@ -271,7 +271,11 @@ var Pane = function (_React$PureComponent) {
271
271
 
272
272
  return React.createElement(
273
273
  'div',
274
- { className: classes.join(' '), style: prefixer.prefix(style) },
274
+ {
275
+ ref: eleRef,
276
+ className: classes.join(' '),
277
+ style: prefixer.prefix(style)
278
+ },
275
279
  children
276
280
  );
277
281
  }
@@ -285,7 +289,8 @@ Pane.propTypes = {
285
289
  prefixer: PropTypes.instanceOf(Prefixer).isRequired,
286
290
  size: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
287
291
  split: PropTypes.oneOf(['vertical', 'horizontal']),
288
- style: stylePropType
292
+ style: stylePropType,
293
+ eleRef: PropTypes.func
289
294
  };
290
295
 
291
296
  Pane.defaultProps = {
@@ -413,16 +418,16 @@ var SplitPane = function (_React$Component) {
413
418
 
414
419
  // order of setting panel sizes.
415
420
  // 1. size
416
- // 2. defaultSize
417
- // 3. minSize
421
+ // 2. getDefaultSize(defaultSize, minsize, maxSize)
418
422
 
419
423
  var size = props.size,
420
424
  defaultSize = props.defaultSize,
421
425
  minSize = props.minSize,
426
+ maxSize = props.maxSize,
422
427
  primary = props.primary;
423
428
 
424
429
 
425
- var initialSize = size !== undefined ? size : defaultSize !== undefined ? defaultSize : minSize;
430
+ var initialSize = size !== undefined ? size : getDefaultSize(defaultSize, minSize, maxSize, null);
426
431
 
427
432
  _this.state = {
428
433
  active: false,
@@ -432,7 +437,11 @@ var SplitPane = function (_React$Component) {
432
437
 
433
438
  // previous props that we need in static methods
434
439
  instanceProps: {
435
- primary: primary
440
+ primary: primary,
441
+ size: size,
442
+ defaultSize: defaultSize,
443
+ minSize: minSize,
444
+ maxSize: maxSize
436
445
  }
437
446
  };
438
447
  return _this;
@@ -441,10 +450,10 @@ var SplitPane = function (_React$Component) {
441
450
  createClass(SplitPane, [{
442
451
  key: 'componentDidMount',
443
452
  value: function componentDidMount() {
444
- this.setState(SplitPane.setSize(this.props, this.state));
445
453
  document.addEventListener('mouseup', this.onMouseUp);
446
454
  document.addEventListener('mousemove', this.onMouseMove);
447
455
  document.addEventListener('touchmove', this.onTouchMove);
456
+ this.setState(SplitPane.setSize(this.props, this.state));
448
457
  }
449
458
  }, {
450
459
  key: 'componentWillUnmount',
@@ -511,8 +520,8 @@ var SplitPane = function (_React$Component) {
511
520
  var ref = isPrimaryFirst ? this.pane1 : this.pane2;
512
521
  var ref2 = isPrimaryFirst ? this.pane2 : this.pane1;
513
522
  if (ref) {
514
- var node = ReactDOM.findDOMNode(ref);
515
- var node2 = ReactDOM.findDOMNode(ref2);
523
+ var node = ref;
524
+ var node2 = ref2;
516
525
 
517
526
  if (node.getBoundingClientRect) {
518
527
  var width = node.getBoundingClientRect().width;
@@ -538,11 +547,11 @@ var SplitPane = function (_React$Component) {
538
547
 
539
548
  var newMaxSize = maxSize;
540
549
  if (maxSize !== undefined && maxSize <= 0) {
541
- var splPane = this.splitPane;
550
+ var splitPane = this.splitPane;
542
551
  if (split === 'vertical') {
543
- newMaxSize = splPane.getBoundingClientRect().width + maxSize;
552
+ newMaxSize = splitPane.getBoundingClientRect().width + maxSize;
544
553
  } else {
545
- newMaxSize = splPane.getBoundingClientRect().height + maxSize;
554
+ newMaxSize = splitPane.getBoundingClientRect().height + maxSize;
546
555
  }
547
556
  }
548
557
 
@@ -586,6 +595,10 @@ var SplitPane = function (_React$Component) {
586
595
  this.setState({ active: false });
587
596
  }
588
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
+
589
602
  }, {
590
603
  key: 'render',
591
604
  value: function render() {
@@ -666,7 +679,7 @@ var SplitPane = function (_React$Component) {
666
679
  {
667
680
  className: pane1Classes,
668
681
  key: 'pane1',
669
- ref: function ref(node) {
682
+ eleRef: function eleRef(node) {
670
683
  _this2.pane1 = node;
671
684
  },
672
685
  size: pane1Size,
@@ -683,9 +696,6 @@ var SplitPane = function (_React$Component) {
683
696
  onTouchStart: this.onTouchStart,
684
697
  onTouchEnd: this.onMouseUp,
685
698
  key: 'resizer',
686
- ref: function ref(node) {
687
- _this2.resizer = node;
688
- },
689
699
  resizerClassName: resizerClassNamesIncludingDefault,
690
700
  split: split,
691
701
  style: resizerStyle || {}
@@ -695,7 +705,7 @@ var SplitPane = function (_React$Component) {
695
705
  {
696
706
  className: pane2Classes,
697
707
  key: 'pane2',
698
- ref: function ref(node) {
708
+ eleRef: function eleRef(node) {
699
709
  _this2.pane2 = node;
700
710
  },
701
711
  size: pane2Size,
@@ -714,22 +724,40 @@ var SplitPane = function (_React$Component) {
714
724
  }, {
715
725
  key: 'setSize',
716
726
  value: function setSize(props, state) {
727
+ var instanceProps = state.instanceProps;
728
+
717
729
  var newState = {};
718
- var isPanel1Primary = props.primary === 'first';
719
730
 
720
731
  var newSize = props.size !== undefined ? props.size : getDefaultSize(props.defaultSize, props.minSize, props.maxSize, state.draggedSize);
721
732
 
722
- newState[isPanel1Primary ? 'pane1Size' : 'pane2Size'] = newSize;
733
+ var defaultSizeChanged = props.defaultSize !== instanceProps.defaultSize || props.minSize !== instanceProps.minSize || props.maxSize !== instanceProps.maxSize;
723
734
 
724
- if (props.size !== undefined && props.size !== state.draggedSize) {
735
+ var shouldUpdateSize = props.size !== undefined ? props.size !== instanceProps.size : defaultSizeChanged;
736
+
737
+ if (props.size !== undefined && props.size !== state.draggedSize && shouldUpdateSize) {
725
738
  newState.draggedSize = newSize;
726
739
  }
727
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
728
748
  if (props.primary !== state.instanceProps.primary) {
729
749
  newState[isPanel1Primary ? 'pane2Size' : 'pane1Size'] = undefined;
730
- newState.instanceProps = { primary: props.primary };
731
750
  }
732
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
+
733
761
  return newState;
734
762
  }
735
763
  }]);
package/dist/index.esm.js CHANGED
@@ -2,7 +2,6 @@ import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import Prefixer from 'inline-style-prefixer';
4
4
  import stylePropType from 'react-style-proptype';
5
- import ReactDOM from 'react-dom';
6
5
 
7
6
  /**
8
7
  * Copyright (c) 2013-present, Facebook, Inc.
@@ -244,7 +243,8 @@ var Pane = function (_React$PureComponent) {
244
243
  prefixer = _props.prefixer,
245
244
  split = _props.split,
246
245
  styleProps = _props.style,
247
- size = _props.size;
246
+ size = _props.size,
247
+ eleRef = _props.eleRef;
248
248
 
249
249
 
250
250
  var classes = ['Pane', split, className];
@@ -267,7 +267,11 @@ var Pane = function (_React$PureComponent) {
267
267
 
268
268
  return React.createElement(
269
269
  'div',
270
- { className: classes.join(' '), style: prefixer.prefix(style) },
270
+ {
271
+ ref: eleRef,
272
+ className: classes.join(' '),
273
+ style: prefixer.prefix(style)
274
+ },
271
275
  children
272
276
  );
273
277
  }
@@ -281,7 +285,8 @@ Pane.propTypes = {
281
285
  prefixer: PropTypes.instanceOf(Prefixer).isRequired,
282
286
  size: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
283
287
  split: PropTypes.oneOf(['vertical', 'horizontal']),
284
- style: stylePropType
288
+ style: stylePropType,
289
+ eleRef: PropTypes.func
285
290
  };
286
291
 
287
292
  Pane.defaultProps = {
@@ -409,16 +414,16 @@ var SplitPane = function (_React$Component) {
409
414
 
410
415
  // order of setting panel sizes.
411
416
  // 1. size
412
- // 2. defaultSize
413
- // 3. minSize
417
+ // 2. getDefaultSize(defaultSize, minsize, maxSize)
414
418
 
415
419
  var size = props.size,
416
420
  defaultSize = props.defaultSize,
417
421
  minSize = props.minSize,
422
+ maxSize = props.maxSize,
418
423
  primary = props.primary;
419
424
 
420
425
 
421
- var initialSize = size !== undefined ? size : defaultSize !== undefined ? defaultSize : minSize;
426
+ var initialSize = size !== undefined ? size : getDefaultSize(defaultSize, minSize, maxSize, null);
422
427
 
423
428
  _this.state = {
424
429
  active: false,
@@ -428,7 +433,11 @@ var SplitPane = function (_React$Component) {
428
433
 
429
434
  // previous props that we need in static methods
430
435
  instanceProps: {
431
- primary: primary
436
+ primary: primary,
437
+ size: size,
438
+ defaultSize: defaultSize,
439
+ minSize: minSize,
440
+ maxSize: maxSize
432
441
  }
433
442
  };
434
443
  return _this;
@@ -437,10 +446,10 @@ var SplitPane = function (_React$Component) {
437
446
  createClass(SplitPane, [{
438
447
  key: 'componentDidMount',
439
448
  value: function componentDidMount() {
440
- this.setState(SplitPane.setSize(this.props, this.state));
441
449
  document.addEventListener('mouseup', this.onMouseUp);
442
450
  document.addEventListener('mousemove', this.onMouseMove);
443
451
  document.addEventListener('touchmove', this.onTouchMove);
452
+ this.setState(SplitPane.setSize(this.props, this.state));
444
453
  }
445
454
  }, {
446
455
  key: 'componentWillUnmount',
@@ -507,8 +516,8 @@ var SplitPane = function (_React$Component) {
507
516
  var ref = isPrimaryFirst ? this.pane1 : this.pane2;
508
517
  var ref2 = isPrimaryFirst ? this.pane2 : this.pane1;
509
518
  if (ref) {
510
- var node = ReactDOM.findDOMNode(ref);
511
- var node2 = ReactDOM.findDOMNode(ref2);
519
+ var node = ref;
520
+ var node2 = ref2;
512
521
 
513
522
  if (node.getBoundingClientRect) {
514
523
  var width = node.getBoundingClientRect().width;
@@ -534,11 +543,11 @@ var SplitPane = function (_React$Component) {
534
543
 
535
544
  var newMaxSize = maxSize;
536
545
  if (maxSize !== undefined && maxSize <= 0) {
537
- var splPane = this.splitPane;
546
+ var splitPane = this.splitPane;
538
547
  if (split === 'vertical') {
539
- newMaxSize = splPane.getBoundingClientRect().width + maxSize;
548
+ newMaxSize = splitPane.getBoundingClientRect().width + maxSize;
540
549
  } else {
541
- newMaxSize = splPane.getBoundingClientRect().height + maxSize;
550
+ newMaxSize = splitPane.getBoundingClientRect().height + maxSize;
542
551
  }
543
552
  }
544
553
 
@@ -582,6 +591,10 @@ var SplitPane = function (_React$Component) {
582
591
  this.setState({ active: false });
583
592
  }
584
593
  }
594
+
595
+ // TODO: find a more elegant way to fix this. memoize calls to setSize?
596
+ // we have to check values since gDSFP is called on every render
597
+
585
598
  }, {
586
599
  key: 'render',
587
600
  value: function render() {
@@ -662,7 +675,7 @@ var SplitPane = function (_React$Component) {
662
675
  {
663
676
  className: pane1Classes,
664
677
  key: 'pane1',
665
- ref: function ref(node) {
678
+ eleRef: function eleRef(node) {
666
679
  _this2.pane1 = node;
667
680
  },
668
681
  size: pane1Size,
@@ -679,9 +692,6 @@ var SplitPane = function (_React$Component) {
679
692
  onTouchStart: this.onTouchStart,
680
693
  onTouchEnd: this.onMouseUp,
681
694
  key: 'resizer',
682
- ref: function ref(node) {
683
- _this2.resizer = node;
684
- },
685
695
  resizerClassName: resizerClassNamesIncludingDefault,
686
696
  split: split,
687
697
  style: resizerStyle || {}
@@ -691,7 +701,7 @@ var SplitPane = function (_React$Component) {
691
701
  {
692
702
  className: pane2Classes,
693
703
  key: 'pane2',
694
- ref: function ref(node) {
704
+ eleRef: function eleRef(node) {
695
705
  _this2.pane2 = node;
696
706
  },
697
707
  size: pane2Size,
@@ -710,22 +720,40 @@ var SplitPane = function (_React$Component) {
710
720
  }, {
711
721
  key: 'setSize',
712
722
  value: function setSize(props, state) {
723
+ var instanceProps = state.instanceProps;
724
+
713
725
  var newState = {};
714
- var isPanel1Primary = props.primary === 'first';
715
726
 
716
727
  var newSize = props.size !== undefined ? props.size : getDefaultSize(props.defaultSize, props.minSize, props.maxSize, state.draggedSize);
717
728
 
718
- newState[isPanel1Primary ? 'pane1Size' : 'pane2Size'] = newSize;
729
+ var defaultSizeChanged = props.defaultSize !== instanceProps.defaultSize || props.minSize !== instanceProps.minSize || props.maxSize !== instanceProps.maxSize;
719
730
 
720
- if (props.size !== undefined && props.size !== state.draggedSize) {
731
+ var shouldUpdateSize = props.size !== undefined ? props.size !== instanceProps.size : defaultSizeChanged;
732
+
733
+ if (props.size !== undefined && props.size !== state.draggedSize && shouldUpdateSize) {
721
734
  newState.draggedSize = newSize;
722
735
  }
723
736
 
737
+ var isPanel1Primary = props.primary === 'first';
738
+
739
+ if (shouldUpdateSize || props.primary !== state.instanceProps.primary) {
740
+ newState[isPanel1Primary ? 'pane1Size' : 'pane2Size'] = newSize;
741
+ }
742
+
743
+ // unset the size on the non primary panel
724
744
  if (props.primary !== state.instanceProps.primary) {
725
745
  newState[isPanel1Primary ? 'pane2Size' : 'pane1Size'] = undefined;
726
- newState.instanceProps = { primary: props.primary };
727
746
  }
728
747
 
748
+ // update the values in instanceProps
749
+ instanceProps.primary = props.primary;
750
+ instanceProps.size = props.size;
751
+ instanceProps.defaultSize = props.defaultSize;
752
+ instanceProps.minSize = props.minSize;
753
+ instanceProps.maxSize = props.maxSize;
754
+
755
+ newState.instanceProps = instanceProps;
756
+
729
757
  return newState;
730
758
  }
731
759
  }]);
package/package.json CHANGED
@@ -3,12 +3,13 @@
3
3
  "description": "React split-pane component",
4
4
  "main": "dist/index.cjs.js",
5
5
  "module": "dist/index.esm.js",
6
+ "source": "src/index.js",
6
7
  "types": "index.d.ts",
7
8
  "files": [
8
9
  "dist",
9
10
  "index.d.ts"
10
11
  ],
11
- "version": "0.1.81",
12
+ "version": "0.1.82",
12
13
  "repository": {
13
14
  "type": "git",
14
15
  "url": "https://github.com/tomkp/react-split-pane"
@@ -42,7 +43,6 @@
42
43
  "babel-preset-react": "^6.24.1",
43
44
  "babel-preset-stage-0": "^6.24.1",
44
45
  "babelify": "^7.3.0",
45
- "browserify": "^14.4.0",
46
46
  "chai": "^4.0.2",
47
47
  "chai-spies": "^0.7.1",
48
48
  "coveralls": "^2.13.1",
@@ -57,7 +57,6 @@
57
57
  "eslint-plugin-prettier": "^2.6.0",
58
58
  "eslint-plugin-react": "^7.9.1",
59
59
  "eslint-plugin-relay": "^0.0.21",
60
- "express": "^4.15.3",
61
60
  "husky": "^0.14.3",
62
61
  "lint-staged": "^7.2.0",
63
62
  "mochify": "^5.8.0",
@@ -70,17 +69,15 @@
70
69
  "rollup-plugin-babel": "^3.0.4",
71
70
  "rollup-plugin-commonjs": "^9.1.3",
72
71
  "rollup-plugin-node-resolve": "^3.3.0",
73
- "surge": "^0.19.0",
74
- "typescript": "^2.5.3",
75
- "watchify": "^3.9.0"
72
+ "surge": "^0.19.0"
76
73
  },
77
74
  "scripts": {
78
75
  "build": "npm run clean && rollup -c",
79
76
  "build:watch": "rollup -c --watch",
80
77
  "clean": "rimraf dist",
81
- "test": "cross-env NODE_ENV=test mochify -R spec",
82
- "test:watch": "cross-env NODE_ENV=test mochify -R spec --watch",
83
- "test:coverage": "cross-env NODE_ENV=test mochify --plugin [ mochify-istanbul --exclude '**/test/**' --report lcovonly ] && cat lcov.info | coveralls && rm lcov.info",
78
+ "test": "cross-env NODE_ENV=test mochify -R spec --transform babelify",
79
+ "test:watch": "cross-env NODE_ENV=test mochify -R spec --watch --transform babelify",
80
+ "test:coverage": "cross-env NODE_ENV=test mochify --plugin [ mochify-istanbul --exclude '**/test/**' --report lcovonly ] --transform babelify && cat lcov.info | coveralls && rm lcov.info",
84
81
  "website:start": "npm run start --prefix website",
85
82
  "website:deploy": "npm run deploy --prefix website",
86
83
  "prettier": "prettier --write '{src,test}/**/*.js'",
@@ -94,13 +91,6 @@
94
91
  "git add"
95
92
  ]
96
93
  },
97
- "browserify": {
98
- "transform": [
99
- [
100
- "babelify"
101
- ]
102
- ]
103
- },
104
94
  "babel": {
105
95
  "presets": [
106
96
  "./.babelrc.js"