@teselagen/ove 0.7.27 → 0.7.28
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/AASliver.js +187 -0
- package/AddLaddersDialog.js +82 -0
- package/AdditionalCutsiteInfoDialog.js +599 -0
- package/AlignmentView/Mismatches.d.ts +3 -3
- package/AlignmentVisibilityTool.js +105 -0
- package/AnnotationContainerHolder.js +20 -0
- package/AnnotationPositioner.js +27 -0
- package/AutoAnnotate.js +501 -0
- package/AutoAnnotateBpMatchingDialog.js +208 -0
- package/Axis.js +151 -0
- package/AxisNumbers.js +35 -0
- package/Browser.js +106 -0
- package/Caret.js +63 -0
- package/Chromatogram.js +293 -0
- package/CircularDnaSequence.js +73 -0
- package/CircularView/Labels/index.d.ts +1 -1
- package/CircularView/index.d.ts +0 -1
- package/CircularZoomMinimap.js +16 -0
- package/ColorPicker.js +30 -0
- package/CommandHotkeyHandler.js +44 -0
- package/CreateAnnotationsPage.d.ts +4 -4
- package/CreateAnnotationsPage.js +98 -0
- package/Cutsite.js +18 -0
- package/CutsiteProperties.js +176 -0
- package/CutsiteSelectionLayers.js +47 -0
- package/Cutsites.js +271 -0
- package/DeletionLayer.js +28 -0
- package/DigestTool/Ladder.d.ts +1 -1
- package/DropHandler.css +21 -0
- package/DropHandler.js +64 -0
- package/EditCaretPosition.js +234 -0
- package/EditTrackNameDialog.js +30 -0
- package/Feature.js +83 -0
- package/FeatureProperties.js +6 -0
- package/FillWindow.js +47 -0
- package/GenbankView.js +74 -0
- package/GeneralProperties.js +117 -0
- package/GenericAnnotationProperties.js +406 -0
- package/GlobalDialog.js +73 -0
- package/GlobalDialogUtils.js +110 -0
- package/GoToDialog.js +25 -0
- package/HorizontalPanelDragHandle.js +35 -0
- package/Keyboard.js +85 -0
- package/Labels.js +327 -0
- package/Ladder.css +20 -0
- package/Ladder.js +303 -0
- package/MeltingTemp.js +85 -0
- package/Menlo.ttf +0 -0
- package/Minimap.js +515 -0
- package/Mismatches.js +134 -0
- package/Monaco.ttf +0 -0
- package/MultipleSeqsDetectedOnImportDialog.js +74 -0
- package/Orf.js +109 -0
- package/OrfProperties.js +117 -0
- package/Orfs.js +35 -0
- package/PCRTool.js +179 -0
- package/PairwiseAlignmentView.js +68 -0
- package/Part.js +34 -0
- package/PartProperties.js +9 -0
- package/PassThrough.js +3 -0
- package/PerformantSelectionLayer.js +32 -0
- package/PinchHelper.js +24 -0
- package/PointedAnnotation.js +347 -0
- package/PositionAnnotationOnCircle.js +26 -0
- package/Primer.js +41 -0
- package/PrimerProperties.js +19 -0
- package/Reflex/index.d.ts +0 -1
- package/ReflexContainer.js +802 -0
- package/ReflexElement.js +160 -0
- package/ReflexEvents.js +77 -0
- package/ReflexSplitter.js +205 -0
- package/RenameSequenceDialog.js +7 -0
- package/RotateCircularViewSlider.js +93 -0
- package/RowView/index.d.ts +0 -1
- package/SelectDialog.js +150 -0
- package/SequenceName.js +15 -0
- package/SimpleCircularOrLinearView.js +381 -0
- package/SimpleOligoPreview.js +39 -0
- package/SingleEnzymeCutsiteInfo.js +139 -0
- package/ToolBar/ToolbarItem.d.ts +1 -3
- package/ToolbarItem.js +192 -0
- package/Translation.js +198 -0
- package/TranslationProperties.js +149 -0
- package/UncontrolledSliderWithPlusMinusBtns.css +5 -0
- package/UncontrolledSliderWithPlusMinusBtns.js +134 -0
- package/VeTopRightContainer.js +12 -0
- package/ZoomCircularViewSlider.js +62 -0
- package/ZoomLinearView.js +47 -0
- package/addAlignment.js +6 -0
- package/addMetaToActionCreators.js +12 -0
- package/addWrappedAddons.js +20 -0
- package/alignmentTool.js +503 -0
- package/alignments.js +379 -0
- package/annotationLabelVisibility.js +2 -0
- package/annotationSearchSelector.js +24 -0
- package/annotationTypes.js +35 -0
- package/annotationVisibility.js +196 -0
- package/annotationsToSupport.js +104 -0
- package/arrayToObjWithIds.js +17 -0
- package/arrayUtils.js +19 -0
- package/array_move.js +10 -0
- package/calculateTickMarkPositionsForGivenRange.js +47 -0
- package/caretPosition.js +27 -0
- package/cdsFeaturesSelector.js +9 -0
- package/charWidth.js +22 -0
- package/circular.js +19 -0
- package/circularSelector.js +4 -0
- package/clickAndDragUtils.js +576 -0
- package/coerceInitialValue.js +7 -0
- package/combineReducersDontIgnoreKeys.js +12 -0
- package/commandUtils.js +20 -0
- package/constants.js +2 -0
- package/copyOptions.js +34 -0
- package/createFragmentLines.js +120 -0
- package/createMergedDefaultStateReducer.js +30 -0
- package/createMetaAction.js +12 -0
- package/createSequenceInputPopup.js +290 -0
- package/createSequenceInputPopupStyle.css +87 -0
- package/createSimpleDialog.js +89 -0
- package/createYourOwnEnzyme.js +39 -0
- package/cutsiteLabelColorSelector.js +6 -0
- package/cutsiteTool.js +88 -0
- package/cutsitesByRangeSelector.js +5 -0
- package/cutsitesSelector.js +61 -0
- package/darkmode.css +98 -0
- package/defaultConfig.js +150 -0
- package/deletionLayers.js +36 -0
- package/description.js +21 -0
- package/digestTool.js +34 -0
- package/dnaToColor.js +17 -0
- package/downloadTool.js +39 -0
- package/draggableClassnames.js +5 -0
- package/drawAnnotations.js +440 -0
- package/drawDirectedPiePiece.js +142 -0
- package/editTool.js +49 -0
- package/editorSelector.js +2 -0
- package/editorUtils.js +205 -0
- package/estimateRowHeight.js +184 -0
- package/featureLengthsToHide.js +27 -0
- package/featureTool.js +34 -0
- package/features.js +19 -0
- package/featuresSelector.js +8 -0
- package/filteredCutsitesSelector.js +136 -0
- package/filteredFeaturesSelector.js +32 -0
- package/filteredPartsSelector.js +57 -0
- package/filteredPrimersSelector.js +27 -0
- package/filteredRestrictionEnzymesSelector.js +1 -0
- package/find.png +0 -0
- package/findTool.js +79 -0
- package/findToolConstants.js +1 -0
- package/frameTranslations.js +52 -0
- package/fullscreen.png +0 -0
- package/getAdditionalEnzymesSelector.js +46 -0
- package/getAngleForPositionMidpoint.js +3 -0
- package/getAnnotationClassnames.js +12 -0
- package/getAnnotationNameAndStartStopString.js +61 -0
- package/getBpsPerRow.js +19 -0
- package/getCutsiteLabelHeights.js +56 -0
- package/getGapMap.js +12 -0
- package/getGaps.js +27 -0
- package/getInternalLabel.js +40 -0
- package/getOveHotkeyDefs.js +12 -0
- package/getPairwiseOverviewLinearViewOptions.js +38 -0
- package/getRangeAnglesSpecial.js +12 -0
- package/getStructuredBases.js +97 -0
- package/getTrackFromEvent.js +25 -0
- package/getVisibleStartEnd.js +7 -0
- package/getXStartAndWidthFromNonCircularRange.js +12 -0
- package/getXStartAndWidthOfRangeWrtRow.js +27 -0
- package/getXStartAndWidthOfRowAnnotation.js +19 -0
- package/getYOffset.js +15 -0
- package/hoveredAnnotation.js +24 -0
- package/{html2canvas.esm--JN4fLQL.js → html2canvas.esm-DiGWN1gP.js} +187 -229
- package/{html2canvas.esm-B7d7VJmQ.cjs → html2canvas.esm-J1esNpMJ.cjs} +187 -229
- package/importTool.js +27 -0
- package/index.cjs.js +48165 -47142
- package/index.es.js +47699 -46676
- package/index.js +71 -0
- package/inlineFindTool.js +38 -0
- package/isElementInViewport.js +29 -0
- package/isEnzymeFilterAndSelector.js +1 -0
- package/isTargetWithinEl.js +6 -0
- package/labelLineIntensity.js +25 -0
- package/labelSize.js +23 -0
- package/ladderDefaults.js +25 -0
- package/lastSavedId.js +20 -0
- package/lineageLines.js +11 -0
- package/linear.png +0 -0
- package/makeStore.js +34 -0
- package/massageTickSpacing.js +19 -0
- package/materiallyAvailable.js +19 -0
- package/middleware.js +112 -0
- package/minimumOrfSize.js +24 -0
- package/minimumOrfSizeSelector.js +2 -0
- package/modalActions.js +3 -0
- package/moveCaret.js +58 -0
- package/name.js +19 -0
- package/normalizeAngle.js +3 -0
- package/normalizeAngleRange.js +9 -0
- package/oligoTool.js +30 -0
- package/onlyUpdateForKeysDeep.js +31 -0
- package/orfFrameToColorMap.js +10 -0
- package/orfTool.js +136 -0
- package/orfsSelector.js +15 -0
- package/ove.css +12107 -0
- package/package.json +6 -5
- package/panelsShown.js +294 -0
- package/partLengthsToHide.js +23 -0
- package/partOverhangs.js +6 -0
- package/partTagSearch.js +69 -0
- package/partTool.js +45 -0
- package/parts.js +19 -0
- package/partsSelector.js +8 -0
- package/pie.png +0 -0
- package/polarToSpecialCartesian.js +7 -0
- package/positionCutsites.js +6 -0
- package/prepareRowData.js +64 -0
- package/primerBases.js +221 -0
- package/primerLengthsToHide.js +27 -0
- package/primers.js +19 -0
- package/primersSelector.js +8 -0
- package/print.png +0 -0
- package/printTool.js +31 -0
- package/propertiesTool.js +40 -0
- package/proteinUtils.js +3 -0
- package/pureNoFunc.js +18 -0
- package/readOnly.js +25 -0
- package/redoTool.js +30 -0
- package/reflex-styles.css +128 -0
- package/reflex-styles.css.map +9 -0
- package/relaxLabelAngles.js +157 -0
- package/relaxLabels_DEPRECATED.js +105 -0
- package/replacementLayers.js +36 -0
- package/restrictionEnzymes.js +52 -0
- package/restrictionEnzymesSelector.js +34 -0
- package/rowviewContants.js +3 -0
- package/ruler.css +89 -0
- package/save.png +0 -0
- package/saveTool.js +44 -0
- package/searchLayersSelector.js +71 -0
- package/selectedAnnotations.js +89 -0
- package/selectedAnnotationsSelector.js +1 -0
- package/selectedCutsitesSelector.js +21 -0
- package/selectedPartTags.js +21 -0
- package/selectionLayer.js +25 -0
- package/selectors/annotationSearchSelector.d.ts +1 -1
- package/sequence.js +12 -0
- package/sequenceDataHistory.js +43 -0
- package/sequenceDataSelector.js +2 -0
- package/sequenceLengthSelector.js +5 -0
- package/sequenceSelector.js +4 -0
- package/sharedActionCreators.js +0 -0
- package/shouldFlipText.js +4 -0
- package/shouldRerender.js +27 -0
- package/showFileDialog.js +25 -0
- package/showGCContent.js +23 -0
- package/show_cut_sites.png +0 -0
- package/show_features.png +0 -0
- package/show_orfs.png +0 -0
- package/show_primers.png +0 -0
- package/simpleDialog.css +13 -0
- package/specialCutsiteFilterOptions.js +22 -0
- package/src/Editor/DropHandler.js +2 -1
- package/src/Editor/index.js +0 -2
- package/src/RowItem/StackedAnnotations/getStructuredBases.js +20 -6
- package/src/ToolBar/cutsiteTool.js +1 -1
- package/src/helperComponents/PropertiesDialog/TranslationProperties.js +2 -1
- package/style.css +3 -12100
- package/tagsToBoldSelector.js +2 -0
- package/toggle_views.svg +1 -0
- package/toolBar.js +23 -0
- package/translationSearchMatchesSelector.js +14 -0
- package/translations.js +20 -0
- package/translationsRawSelector.js +8 -0
- package/translationsSelector.js +137 -0
- package/typeField.js +24 -0
- package/undoTool.js +30 -0
- package/updateEditor.d.ts +1 -3
- package/updateEditor.js +200 -0
- package/updateLabelsForInViewFeatures.js +55 -0
- package/updateLabelsForInViewFeaturesCircView.js +41 -0
- package/updateTrackHelper.js +58 -0
- package/uppercaseSequenceMapFont.js +25 -0
- package/upsertDeleteActionGenerator.js +31 -0
- package/useAAColorType.js +8 -0
- package/useAdditionalOrfStartCodons.js +24 -0
- package/useAnnotationLimits.js +42 -0
- package/useChromatogramPrefs.js +31 -0
- package/useFormValue.js +7 -0
- package/useLadders.js +6 -0
- package/useMeltingTemp.js +7 -0
- package/useTmType.js +10 -0
- package/userDefinedHandlersAndOpts.js +61 -0
- package/utils/getAnnotationNameAndStartStopString.d.ts +1 -5
- package/utils/selectionLayer.d.ts +2 -2
- package/utils.js +37 -0
- package/versionHistory.js +26 -0
- package/versionHistoryTool.js +21 -0
- package/viewSubmenu.js +479 -0
- package/visibilityTool.js +39 -0
- package/withEditorInteractions/getBpsPerRow.d.ts +1 -3
- package/withHover.js +113 -0
- package/withRestrictionEnzymes.js +15 -0
- package/index.umd.js +0 -188322
|
@@ -0,0 +1,802 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////
|
|
2
|
+
// ReflexContainer
|
|
3
|
+
// By Philippe Leefsma
|
|
4
|
+
// December 2016
|
|
5
|
+
//
|
|
6
|
+
///////////////////////////////////////////////////////////
|
|
7
|
+
import ReflexSplitter from "./ReflexSplitter";
|
|
8
|
+
import ReflexEvents from "./ReflexEvents";
|
|
9
|
+
import PropTypes from "prop-types";
|
|
10
|
+
import ReactDOM from "react-dom";
|
|
11
|
+
import React from "react";
|
|
12
|
+
import { cloneDeep, round } from "lodash-es";
|
|
13
|
+
|
|
14
|
+
class ReflexContainer extends React.Component {
|
|
15
|
+
/////////////////////////////////////////////////////////
|
|
16
|
+
//
|
|
17
|
+
//
|
|
18
|
+
/////////////////////////////////////////////////////////
|
|
19
|
+
constructor(props) {
|
|
20
|
+
super(props);
|
|
21
|
+
|
|
22
|
+
this.state = {
|
|
23
|
+
flexData: []
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
this.events = new ReflexEvents();
|
|
27
|
+
|
|
28
|
+
this.onSplitterStartResize = this.onSplitterStartResize.bind(this);
|
|
29
|
+
|
|
30
|
+
this.onSplitterStopResize = this.onSplitterStopResize.bind(this);
|
|
31
|
+
|
|
32
|
+
this.onSplitterResize = this.onSplitterResize.bind(this);
|
|
33
|
+
|
|
34
|
+
this.onElementSize = this.onElementSize.bind(this);
|
|
35
|
+
|
|
36
|
+
this.children = [];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/////////////////////////////////////////////////////////
|
|
40
|
+
//
|
|
41
|
+
//
|
|
42
|
+
/////////////////////////////////////////////////////////
|
|
43
|
+
setPartialState(partialState) {
|
|
44
|
+
return new Promise(resolve => {
|
|
45
|
+
this.setState(Object.assign({}, this.state, partialState), () => {
|
|
46
|
+
resolve();
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/////////////////////////////////////////////////////////
|
|
52
|
+
//
|
|
53
|
+
//
|
|
54
|
+
/////////////////////////////////////////////////////////
|
|
55
|
+
componentDidMount() {
|
|
56
|
+
const flexData = this.computeFlexData();
|
|
57
|
+
|
|
58
|
+
this.setPartialState({
|
|
59
|
+
flexData
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
this.events.on("splitter.startResize", this.onSplitterStartResize);
|
|
63
|
+
|
|
64
|
+
this.events.on("splitter.stopResize", this.onSplitterStopResize);
|
|
65
|
+
|
|
66
|
+
this.events.on("splitter.resize", this.onSplitterResize);
|
|
67
|
+
|
|
68
|
+
this.events.on("element.size", this.onElementSize);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/////////////////////////////////////////////////////////
|
|
72
|
+
//
|
|
73
|
+
//
|
|
74
|
+
/////////////////////////////////////////////////////////
|
|
75
|
+
componentWillUnmount() {
|
|
76
|
+
this.events.off();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/////////////////////////////////////////////////////////
|
|
80
|
+
//
|
|
81
|
+
//
|
|
82
|
+
/////////////////////////////////////////////////////////
|
|
83
|
+
getValidChildren(props = this.props) {
|
|
84
|
+
return this.toArray(props.children).filter(child => {
|
|
85
|
+
return !!child;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/////////////////////////////////////////////////////////////
|
|
90
|
+
//
|
|
91
|
+
//
|
|
92
|
+
/////////////////////////////////////////////////////////////
|
|
93
|
+
UNSAFE_componentWillReceiveProps(props) {
|
|
94
|
+
const children = this.getValidChildren(props);
|
|
95
|
+
|
|
96
|
+
if (
|
|
97
|
+
children.length !== this.state.flexData.length ||
|
|
98
|
+
this.flexHasChanged(props)
|
|
99
|
+
) {
|
|
100
|
+
const flexData = this.computeFlexData(children);
|
|
101
|
+
|
|
102
|
+
this.setPartialState({
|
|
103
|
+
flexData
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/////////////////////////////////////////////////////////
|
|
109
|
+
// Check if flex has changed: this allows updating the
|
|
110
|
+
// component when different flex is passed as property
|
|
111
|
+
// to one or several children
|
|
112
|
+
//
|
|
113
|
+
/////////////////////////////////////////////////////////
|
|
114
|
+
flexHasChanged(props) {
|
|
115
|
+
const nextChildrenFlex = this.getValidChildren(props).map(child => {
|
|
116
|
+
return child.props.flex || 0;
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const childrenFlex = this.getValidChildren().map(child => {
|
|
120
|
+
return child.props.flex || 0;
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
return !childrenFlex.every((flex, idx) => {
|
|
124
|
+
return flex === nextChildrenFlex[idx];
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/////////////////////////////////////////////////////////
|
|
129
|
+
// Returns size of a ReflexElement
|
|
130
|
+
//
|
|
131
|
+
/////////////////////////////////////////////////////////
|
|
132
|
+
getSize(element) {
|
|
133
|
+
const ref = element.ref ? this.refs[element.ref] : element;
|
|
134
|
+
|
|
135
|
+
const domElement = ReactDOM.findDOMNode(ref);
|
|
136
|
+
|
|
137
|
+
switch (this.props.orientation) {
|
|
138
|
+
case "horizontal":
|
|
139
|
+
return domElement.offsetHeight;
|
|
140
|
+
|
|
141
|
+
case "vertical":
|
|
142
|
+
default:
|
|
143
|
+
return domElement.offsetWidth;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/////////////////////////////////////////////////////////
|
|
148
|
+
// Computes offset from pointer position
|
|
149
|
+
//
|
|
150
|
+
/////////////////////////////////////////////////////////
|
|
151
|
+
getOffset(event) {
|
|
152
|
+
const pos = event.changedTouches ? event.changedTouches[0] : event;
|
|
153
|
+
|
|
154
|
+
switch (this.props.orientation) {
|
|
155
|
+
case "horizontal":
|
|
156
|
+
return pos.pageY - this.previousPos;
|
|
157
|
+
|
|
158
|
+
case "vertical":
|
|
159
|
+
default:
|
|
160
|
+
return pos.pageX - this.previousPos;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/////////////////////////////////////////////////////////
|
|
165
|
+
// Handles splitter startResize event
|
|
166
|
+
//
|
|
167
|
+
/////////////////////////////////////////////////////////
|
|
168
|
+
onSplitterStartResize(data) {
|
|
169
|
+
const pos = data.event.changedTouches
|
|
170
|
+
? data.event.changedTouches[0]
|
|
171
|
+
: data.event;
|
|
172
|
+
|
|
173
|
+
switch (this.props.orientation) {
|
|
174
|
+
case "horizontal":
|
|
175
|
+
document.body.style.cursor = "row-resize";
|
|
176
|
+
this.previousPos = pos.pageY;
|
|
177
|
+
break;
|
|
178
|
+
|
|
179
|
+
case "vertical":
|
|
180
|
+
default:
|
|
181
|
+
document.body.style.cursor = "col-resize";
|
|
182
|
+
this.previousPos = pos.pageX;
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const idx = data.splitter.props.index;
|
|
187
|
+
|
|
188
|
+
this.elements = [this.children[idx - 1], this.children[idx + 1]];
|
|
189
|
+
|
|
190
|
+
this.emitElementsEvent(this.elements, "onStartResize");
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/////////////////////////////////////////////////////////
|
|
194
|
+
// Handles splitter resize event
|
|
195
|
+
//
|
|
196
|
+
/////////////////////////////////////////////////////////
|
|
197
|
+
onSplitterResize(data) {
|
|
198
|
+
const idx = data.splitter.props.index;
|
|
199
|
+
|
|
200
|
+
const offset = this.getOffset(data.event);
|
|
201
|
+
|
|
202
|
+
let availableOffset = this.computeAvailableOffset(idx, offset);
|
|
203
|
+
|
|
204
|
+
if (this.hasCollapsed) {
|
|
205
|
+
if (this.isNegativeWhenCollapsing ? offset > 0 : offset < 0) {
|
|
206
|
+
this.hasCollapsed = false;
|
|
207
|
+
this.setPartialState(this.stateBeforeCollapse).then(() => {
|
|
208
|
+
this.emitElementsEvent(this.elements, "onResize");
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (!availableOffset) {
|
|
215
|
+
this.closeThreshold = 40;
|
|
216
|
+
const shrink = this.computeAvailableShrink(idx, offset);
|
|
217
|
+
|
|
218
|
+
if (shrink === 0 && Math.abs(offset) > this.closeThreshold) {
|
|
219
|
+
const childIdx = offset > 0 ? idx + 1 : idx - 1;
|
|
220
|
+
|
|
221
|
+
const child = this.children[childIdx];
|
|
222
|
+
const size = this.getSize(child);
|
|
223
|
+
this.stateBeforeCollapse = cloneDeep(this.state);
|
|
224
|
+
this.isNegativeWhenCollapsing = offset < 0;
|
|
225
|
+
availableOffset = size * (offset > 0 ? 1 : -1);
|
|
226
|
+
this.hasCollapsed = child.props;
|
|
227
|
+
this.elements = this.dispatchOffset(idx, availableOffset);
|
|
228
|
+
this.adjustFlex(this.elements);
|
|
229
|
+
this.setPartialState(this.state).then(() => {
|
|
230
|
+
this.emitElementsEvent(this.elements, "onResize");
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
} else if (availableOffset) {
|
|
234
|
+
const pos = data.event.changedTouches
|
|
235
|
+
? data.event.changedTouches[0]
|
|
236
|
+
: data.event;
|
|
237
|
+
|
|
238
|
+
switch (this.props.orientation) {
|
|
239
|
+
case "horizontal":
|
|
240
|
+
this.previousPos = pos.pageY;
|
|
241
|
+
break;
|
|
242
|
+
|
|
243
|
+
case "vertical":
|
|
244
|
+
default:
|
|
245
|
+
this.previousPos = pos.pageX;
|
|
246
|
+
break;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
this.elements = this.dispatchOffset(idx, availableOffset);
|
|
250
|
+
|
|
251
|
+
this.adjustFlex(this.elements);
|
|
252
|
+
this.setPartialState(this.state).then(() => {
|
|
253
|
+
this.emitElementsEvent(this.elements, "onResize");
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/////////////////////////////////////////////////////////
|
|
259
|
+
// Determines if element is a splitter
|
|
260
|
+
// or wraps a splitter
|
|
261
|
+
//
|
|
262
|
+
/////////////////////////////////////////////////////////
|
|
263
|
+
isSplitterElement(element) {
|
|
264
|
+
//https://github.com/leefsmp/Re-Flex/issues/49
|
|
265
|
+
return process.env.NODE_ENV === "development"
|
|
266
|
+
? element.type === React.createElement(ReflexSplitter).type
|
|
267
|
+
: element.type === ReflexSplitter;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/////////////////////////////////////////////////////////
|
|
271
|
+
// Handles splitter stopResize event
|
|
272
|
+
//
|
|
273
|
+
/////////////////////////////////////////////////////////
|
|
274
|
+
onSplitterStopResize() {
|
|
275
|
+
if (this.hasCollapsed) {
|
|
276
|
+
this.props.onPanelCollapse &&
|
|
277
|
+
this.props.onPanelCollapse(this.hasCollapsed);
|
|
278
|
+
this.hasCollapsed = false;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
document.body.style.cursor = "auto";
|
|
282
|
+
|
|
283
|
+
const resizedRefs = this.elements.map(element => {
|
|
284
|
+
return element.ref;
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
const elements = this.children.filter(child => {
|
|
288
|
+
return !this.isSplitterElement(child) && resizedRefs.includes(child.ref);
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
this.emitElementsEvent(elements, "onStopResize");
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/////////////////////////////////////////////////////////
|
|
295
|
+
// Handles element size modified event
|
|
296
|
+
//
|
|
297
|
+
/////////////////////////////////////////////////////////
|
|
298
|
+
onElementSize(data) {
|
|
299
|
+
return new Promise(resolve => {
|
|
300
|
+
try {
|
|
301
|
+
const idx = data.element.props.index;
|
|
302
|
+
|
|
303
|
+
const size = this.getSize(this.children[idx]);
|
|
304
|
+
|
|
305
|
+
const offset = data.size - size;
|
|
306
|
+
|
|
307
|
+
const dir = data.direction;
|
|
308
|
+
|
|
309
|
+
const splitterIdx = idx + dir;
|
|
310
|
+
|
|
311
|
+
const availableOffset = this.computeAvailableOffset(
|
|
312
|
+
splitterIdx,
|
|
313
|
+
dir * offset
|
|
314
|
+
);
|
|
315
|
+
|
|
316
|
+
this.elements = null;
|
|
317
|
+
|
|
318
|
+
if (availableOffset) {
|
|
319
|
+
this.elements = this.dispatchOffset(splitterIdx, availableOffset);
|
|
320
|
+
|
|
321
|
+
this.adjustFlex(this.elements);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
this.setPartialState(this.state).then(() => {
|
|
325
|
+
this.emitElementsEvent(this.elements, "onResize");
|
|
326
|
+
|
|
327
|
+
resolve();
|
|
328
|
+
});
|
|
329
|
+
} catch (ex) {
|
|
330
|
+
// TODO handle exception ...
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/////////////////////////////////////////////////////////
|
|
336
|
+
// Adjusts flex after a dispatch to make sure
|
|
337
|
+
// total flex of modified elements remains the same
|
|
338
|
+
//
|
|
339
|
+
/////////////////////////////////////////////////////////
|
|
340
|
+
adjustFlex(elements) {
|
|
341
|
+
const diffFlex = elements.reduce((sum, element) => {
|
|
342
|
+
const idx = element.props.index;
|
|
343
|
+
|
|
344
|
+
const previousFlex = element.props.flex;
|
|
345
|
+
|
|
346
|
+
const nextFlex = this.state.flexData[idx].flex;
|
|
347
|
+
|
|
348
|
+
return sum + (previousFlex - nextFlex) / elements.length;
|
|
349
|
+
}, 0);
|
|
350
|
+
|
|
351
|
+
elements.forEach(element => {
|
|
352
|
+
// eslint-disable-next-line react/no-direct-mutation-state
|
|
353
|
+
this.state.flexData[element.props.index].flex += diffFlex;
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/////////////////////////////////////////////////////////
|
|
358
|
+
// Returns available offset for a given raw offset value
|
|
359
|
+
// This checks how much the panes can be stretched and
|
|
360
|
+
// shrink, then returns the min
|
|
361
|
+
//
|
|
362
|
+
/////////////////////////////////////////////////////////
|
|
363
|
+
computeAvailableOffset(idx, offset) {
|
|
364
|
+
const stretch = this.computeAvailableStretch(idx, offset);
|
|
365
|
+
|
|
366
|
+
const shrink = this.computeAvailableShrink(idx, offset);
|
|
367
|
+
|
|
368
|
+
const availableOffset = Math.min(stretch, shrink) * Math.sign(offset);
|
|
369
|
+
|
|
370
|
+
return availableOffset;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/////////////////////////////////////////////////////////
|
|
374
|
+
// Returns true if the next splitter than the one at idx
|
|
375
|
+
// can propagate the drag. This can happen if that
|
|
376
|
+
// next element is actually a splitter and it has
|
|
377
|
+
// propagate=true property set
|
|
378
|
+
//
|
|
379
|
+
/////////////////////////////////////////////////////////
|
|
380
|
+
checkPropagate(idx, direction) {
|
|
381
|
+
if (direction > 0) {
|
|
382
|
+
if (idx < this.children.length - 2) {
|
|
383
|
+
const child = this.children[idx + 2];
|
|
384
|
+
|
|
385
|
+
const typeCheck = this.isSplitterElement(child);
|
|
386
|
+
|
|
387
|
+
return typeCheck && child.props.propagate;
|
|
388
|
+
}
|
|
389
|
+
} else {
|
|
390
|
+
if (idx > 2) {
|
|
391
|
+
const child = this.children[idx - 2];
|
|
392
|
+
|
|
393
|
+
const typeCheck = this.isSplitterElement(child);
|
|
394
|
+
|
|
395
|
+
return typeCheck && child.props.propagate;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
return false;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/////////////////////////////////////////////////////////
|
|
403
|
+
// Recursively computes available stretch at splitter
|
|
404
|
+
// idx for given raw offset
|
|
405
|
+
//
|
|
406
|
+
/////////////////////////////////////////////////////////
|
|
407
|
+
computeAvailableStretch(idx, offset) {
|
|
408
|
+
const childIdx = offset < 0 ? idx + 1 : idx - 1;
|
|
409
|
+
|
|
410
|
+
const child = this.children[childIdx];
|
|
411
|
+
|
|
412
|
+
const size = this.getSize(child);
|
|
413
|
+
|
|
414
|
+
const maxSize = child.props.maxSize;
|
|
415
|
+
|
|
416
|
+
const availableStretch = maxSize - size;
|
|
417
|
+
|
|
418
|
+
if (availableStretch < Math.abs(offset)) {
|
|
419
|
+
if (this.checkPropagate(idx, -1 * offset)) {
|
|
420
|
+
const nextOffset =
|
|
421
|
+
Math.sign(offset) * (Math.abs(offset) - availableStretch);
|
|
422
|
+
|
|
423
|
+
return (
|
|
424
|
+
availableStretch +
|
|
425
|
+
this.computeAvailableStretch(
|
|
426
|
+
offset < 0 ? idx + 2 : idx - 2,
|
|
427
|
+
nextOffset
|
|
428
|
+
)
|
|
429
|
+
);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
return Math.min(availableStretch, Math.abs(offset));
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/////////////////////////////////////////////////////////
|
|
437
|
+
// Recursively computes available shrink at splitter
|
|
438
|
+
// idx for given raw offset
|
|
439
|
+
//
|
|
440
|
+
/////////////////////////////////////////////////////////
|
|
441
|
+
computeAvailableShrink(idx, offset) {
|
|
442
|
+
const childIdx = offset > 0 ? idx + 1 : idx - 1;
|
|
443
|
+
|
|
444
|
+
const child = this.children[childIdx];
|
|
445
|
+
|
|
446
|
+
const size = this.getSize(child);
|
|
447
|
+
|
|
448
|
+
const minSize = Math.max(child.props.minSize, 0);
|
|
449
|
+
|
|
450
|
+
const availableShrink = size - minSize;
|
|
451
|
+
|
|
452
|
+
if (availableShrink < Math.abs(offset)) {
|
|
453
|
+
if (this.checkPropagate(idx, offset)) {
|
|
454
|
+
const nextOffset =
|
|
455
|
+
Math.sign(offset) * (Math.abs(offset) - availableShrink);
|
|
456
|
+
|
|
457
|
+
return (
|
|
458
|
+
availableShrink +
|
|
459
|
+
this.computeAvailableShrink(
|
|
460
|
+
offset > 0 ? idx + 2 : idx - 2,
|
|
461
|
+
nextOffset
|
|
462
|
+
)
|
|
463
|
+
);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
return Math.min(availableShrink, Math.abs(offset));
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/////////////////////////////////////////////////////////
|
|
471
|
+
// Returns flex value for unit pixel
|
|
472
|
+
//
|
|
473
|
+
/////////////////////////////////////////////////////////
|
|
474
|
+
computePixelFlex() {
|
|
475
|
+
const domElement = ReactDOM.findDOMNode(this);
|
|
476
|
+
|
|
477
|
+
switch (this.props.orientation) {
|
|
478
|
+
case "horizontal":
|
|
479
|
+
if (domElement.offsetHeight === 0.0) {
|
|
480
|
+
console.warn(
|
|
481
|
+
"Found ReflexContainer with height=0, " +
|
|
482
|
+
"this will cause invalid behavior..."
|
|
483
|
+
);
|
|
484
|
+
console.warn(domElement);
|
|
485
|
+
return 0.0;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
return 1.0 / domElement.offsetHeight;
|
|
489
|
+
|
|
490
|
+
case "vertical":
|
|
491
|
+
default:
|
|
492
|
+
if (domElement.offsetWidth === 0.0) {
|
|
493
|
+
console.warn(
|
|
494
|
+
"Found ReflexContainer with width=0, " +
|
|
495
|
+
"this will cause invalid behavior..."
|
|
496
|
+
);
|
|
497
|
+
console.warn(domElement);
|
|
498
|
+
return 0.0;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
return 1.0 / domElement.offsetWidth;
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/////////////////////////////////////////////////////////
|
|
506
|
+
// Adds offset to a given ReflexElement
|
|
507
|
+
//
|
|
508
|
+
/////////////////////////////////////////////////////////
|
|
509
|
+
addOffset(element, offset) {
|
|
510
|
+
const size = this.getSize(element);
|
|
511
|
+
|
|
512
|
+
const idx = element.props.index;
|
|
513
|
+
|
|
514
|
+
const newSize = Math.max(size + offset, 0);
|
|
515
|
+
|
|
516
|
+
const currentFlex = this.state.flexData[idx].flex;
|
|
517
|
+
|
|
518
|
+
const newFlex =
|
|
519
|
+
currentFlex > 0
|
|
520
|
+
? (currentFlex * newSize) / size
|
|
521
|
+
: this.computePixelFlex() * newSize;
|
|
522
|
+
|
|
523
|
+
// eslint-disable-next-line react/no-direct-mutation-state
|
|
524
|
+
this.state.flexData[idx].flex =
|
|
525
|
+
!isFinite(newFlex) || isNaN(newFlex) ? 0 : newFlex;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
/////////////////////////////////////////////////////////
|
|
529
|
+
// Recursively dispatches stretch offset across
|
|
530
|
+
// children elements starting at splitter idx
|
|
531
|
+
//
|
|
532
|
+
/////////////////////////////////////////////////////////
|
|
533
|
+
dispatchStretch(idx, offset) {
|
|
534
|
+
const childIdx = offset < 0 ? idx + 1 : idx - 1;
|
|
535
|
+
|
|
536
|
+
if (childIdx < 0 || childIdx > this.children.length - 1) {
|
|
537
|
+
return [];
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
const child = this.children[childIdx];
|
|
541
|
+
|
|
542
|
+
const size = this.getSize(child);
|
|
543
|
+
|
|
544
|
+
const newSize = Math.min(child.props.maxSize, size + Math.abs(offset));
|
|
545
|
+
|
|
546
|
+
const dispatchedStretch = newSize - size;
|
|
547
|
+
|
|
548
|
+
this.addOffset(child, dispatchedStretch);
|
|
549
|
+
|
|
550
|
+
if (dispatchedStretch < Math.abs(offset)) {
|
|
551
|
+
const nextIdx = idx - Math.sign(offset) * 2;
|
|
552
|
+
|
|
553
|
+
const nextOffset =
|
|
554
|
+
Math.sign(offset) * (Math.abs(offset) - dispatchedStretch);
|
|
555
|
+
|
|
556
|
+
return [child, ...this.dispatchStretch(nextIdx, nextOffset)];
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
return [child];
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
/////////////////////////////////////////////////////////
|
|
563
|
+
// Recursively dispatches shrink offset across
|
|
564
|
+
// children elements starting at splitter idx
|
|
565
|
+
//
|
|
566
|
+
/////////////////////////////////////////////////////////
|
|
567
|
+
dispatchShrink(idx, offset) {
|
|
568
|
+
const childIdx = offset > 0 ? idx + 1 : idx - 1;
|
|
569
|
+
|
|
570
|
+
if (childIdx < 0 || childIdx > this.children.length - 1) {
|
|
571
|
+
return [];
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
const child = this.children[childIdx];
|
|
575
|
+
|
|
576
|
+
const size = this.getSize(child);
|
|
577
|
+
|
|
578
|
+
const newSize = Math.max(
|
|
579
|
+
// child.props.minSize, //tnr: not sure what to do about this.. I had to comment this out to make the collapsing work
|
|
580
|
+
size - Math.abs(offset)
|
|
581
|
+
);
|
|
582
|
+
|
|
583
|
+
const dispatchedShrink = newSize - size;
|
|
584
|
+
|
|
585
|
+
this.addOffset(child, dispatchedShrink);
|
|
586
|
+
|
|
587
|
+
if (Math.abs(dispatchedShrink) < Math.abs(offset)) {
|
|
588
|
+
const nextIdx = idx + Math.sign(offset) * 2;
|
|
589
|
+
|
|
590
|
+
const nextOffset =
|
|
591
|
+
Math.sign(offset) * (Math.abs(offset) + dispatchedShrink);
|
|
592
|
+
|
|
593
|
+
return [child, ...this.dispatchShrink(nextIdx, nextOffset)];
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
return [child];
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
/////////////////////////////////////////////////////////
|
|
600
|
+
// Dispatch offset at splitter idx
|
|
601
|
+
//
|
|
602
|
+
/////////////////////////////////////////////////////////
|
|
603
|
+
dispatchOffset(idx, offset) {
|
|
604
|
+
return [
|
|
605
|
+
...this.dispatchStretch(idx, offset),
|
|
606
|
+
...this.dispatchShrink(idx, offset)
|
|
607
|
+
];
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
/////////////////////////////////////////////////////////
|
|
611
|
+
// Emits given if event for each given element
|
|
612
|
+
// if present in the component props
|
|
613
|
+
//
|
|
614
|
+
/////////////////////////////////////////////////////////
|
|
615
|
+
emitElementsEvent(elements, event) {
|
|
616
|
+
this.toArray(elements).forEach(element => {
|
|
617
|
+
if (element.props[event]) {
|
|
618
|
+
const ref = this.refs[element.ref];
|
|
619
|
+
|
|
620
|
+
element.props[event]({
|
|
621
|
+
domElement: ReactDOM.findDOMNode(ref),
|
|
622
|
+
component: element
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
/////////////////////////////////////////////////////////
|
|
629
|
+
// Computes initial flex data based on provided flex
|
|
630
|
+
// properties. By default each ReflexElement gets
|
|
631
|
+
// evenly arranged within its container
|
|
632
|
+
//
|
|
633
|
+
/////////////////////////////////////////////////////////
|
|
634
|
+
computeFlexData(children = this.getValidChildren()) {
|
|
635
|
+
const pixelFlex = this.computePixelFlex();
|
|
636
|
+
|
|
637
|
+
const computeFreeFlex = flexData => {
|
|
638
|
+
return flexData.reduce((sum, entry) => {
|
|
639
|
+
if (!this.isSplitterElement(entry) && entry.constrained) {
|
|
640
|
+
return sum - entry.flex;
|
|
641
|
+
}
|
|
642
|
+
return sum;
|
|
643
|
+
}, 1);
|
|
644
|
+
};
|
|
645
|
+
|
|
646
|
+
const computeFreeElements = flexData => {
|
|
647
|
+
return flexData.reduce((sum, entry) => {
|
|
648
|
+
if (!this.isSplitterElement(entry) && !entry.constrained) {
|
|
649
|
+
return sum + 1;
|
|
650
|
+
}
|
|
651
|
+
return sum;
|
|
652
|
+
}, 0);
|
|
653
|
+
};
|
|
654
|
+
|
|
655
|
+
const flexDataInit = children.map(child => {
|
|
656
|
+
const props = child.props;
|
|
657
|
+
|
|
658
|
+
return {
|
|
659
|
+
maxFlex: (props.maxSize || Number.MAX_VALUE) * pixelFlex,
|
|
660
|
+
sizeFlex: (props.size || Number.MAX_VALUE) * pixelFlex,
|
|
661
|
+
minFlex: (props.minSize || 1) * pixelFlex,
|
|
662
|
+
constrained: props.flex !== undefined,
|
|
663
|
+
guid: props.ref || this.guid(),
|
|
664
|
+
flex: props.flex || 0,
|
|
665
|
+
type: child.type
|
|
666
|
+
};
|
|
667
|
+
});
|
|
668
|
+
|
|
669
|
+
const computeFlexDataRec = flexDataIn => {
|
|
670
|
+
let hasContrain = false;
|
|
671
|
+
|
|
672
|
+
const freeElements = computeFreeElements(flexDataIn);
|
|
673
|
+
|
|
674
|
+
const freeFlex = computeFreeFlex(flexDataIn);
|
|
675
|
+
|
|
676
|
+
const flexDataOut = flexDataIn.map(entry => {
|
|
677
|
+
if (this.isSplitterElement(entry)) {
|
|
678
|
+
return entry;
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
const proposedFlex = !entry.constrained
|
|
682
|
+
? freeFlex / freeElements
|
|
683
|
+
: entry.flex;
|
|
684
|
+
|
|
685
|
+
const constrainedFlex = Math.min(
|
|
686
|
+
entry.sizeFlex,
|
|
687
|
+
Math.min(entry.maxFlex, Math.max(entry.minFlex, proposedFlex))
|
|
688
|
+
);
|
|
689
|
+
|
|
690
|
+
const constrained = constrainedFlex !== proposedFlex;
|
|
691
|
+
|
|
692
|
+
hasContrain = hasContrain || constrained;
|
|
693
|
+
|
|
694
|
+
return Object.assign({}, entry, {
|
|
695
|
+
flex: constrainedFlex,
|
|
696
|
+
constrained
|
|
697
|
+
});
|
|
698
|
+
});
|
|
699
|
+
|
|
700
|
+
return hasContrain ? computeFlexDataRec(flexDataOut) : flexDataOut;
|
|
701
|
+
};
|
|
702
|
+
|
|
703
|
+
const flexData = computeFlexDataRec(flexDataInit);
|
|
704
|
+
|
|
705
|
+
return flexData.map(entry => {
|
|
706
|
+
return {
|
|
707
|
+
flex: !this.isSplitterElement(entry) ? entry.flex : 0.0,
|
|
708
|
+
guid: entry.guid
|
|
709
|
+
};
|
|
710
|
+
});
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
/////////////////////////////////////////////////////////
|
|
714
|
+
// Utility method that generates a new unique GUID
|
|
715
|
+
//
|
|
716
|
+
/////////////////////////////////////////////////////////
|
|
717
|
+
guid(format = "xxxx-xxxx") {
|
|
718
|
+
let d = new Date().getTime();
|
|
719
|
+
|
|
720
|
+
return format.replace(/[xy]/g, function (c) {
|
|
721
|
+
const r = (d + Math.random() * 16) % 16 | 0;
|
|
722
|
+
d = Math.floor(d / 16);
|
|
723
|
+
// eslint-disable-next-line eqeqeq
|
|
724
|
+
return (c == "x" ? r : (r & 0x7) | 0x8).toString(16);
|
|
725
|
+
});
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
/////////////////////////////////////////////////////////
|
|
729
|
+
// Utility method to ensure given argument is
|
|
730
|
+
// returned as an array
|
|
731
|
+
//
|
|
732
|
+
/////////////////////////////////////////////////////////
|
|
733
|
+
toArray(obj) {
|
|
734
|
+
return obj ? (Array.isArray(obj) ? obj : [obj]) : [];
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
/////////////////////////////////////////////////////////
|
|
738
|
+
// Render container. This will clone all original child
|
|
739
|
+
// components in order to pass some internal properties
|
|
740
|
+
// used to handle resizing logic
|
|
741
|
+
//
|
|
742
|
+
/////////////////////////////////////////////////////////
|
|
743
|
+
render() {
|
|
744
|
+
const classNames = [
|
|
745
|
+
"reflex-layout",
|
|
746
|
+
"reflex-container",
|
|
747
|
+
this.props.orientation,
|
|
748
|
+
...this.props.className.split(" ")
|
|
749
|
+
];
|
|
750
|
+
|
|
751
|
+
this.children = React.Children.map(
|
|
752
|
+
this.getValidChildren(),
|
|
753
|
+
(child, idx) => {
|
|
754
|
+
if (idx > this.state.flexData.length - 1) {
|
|
755
|
+
return <div />;
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
const flexData = this.state.flexData[idx];
|
|
759
|
+
|
|
760
|
+
const newProps = Object.assign({}, child.props, {
|
|
761
|
+
maxSize: child.props.maxSize || Number.MAX_VALUE,
|
|
762
|
+
orientation: this.props.orientation,
|
|
763
|
+
minSize: child.props.minSize || 1,
|
|
764
|
+
events: this.events,
|
|
765
|
+
flex: round(flexData.flex, 5), //tnr: this rounding is necessary because flex was getting computed very slightly off (eg -1.423432e-17). This corrects for that
|
|
766
|
+
ref: flexData.guid,
|
|
767
|
+
index: idx
|
|
768
|
+
});
|
|
769
|
+
|
|
770
|
+
return React.cloneElement(child, newProps);
|
|
771
|
+
}
|
|
772
|
+
);
|
|
773
|
+
|
|
774
|
+
return (
|
|
775
|
+
<div className={classNames.join(" ")} style={this.props.style}>
|
|
776
|
+
{this.children}
|
|
777
|
+
</div>
|
|
778
|
+
);
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
/////////////////////////////////////////////////////////
|
|
783
|
+
//
|
|
784
|
+
//
|
|
785
|
+
/////////////////////////////////////////////////////////
|
|
786
|
+
ReflexContainer.propTypes = {
|
|
787
|
+
orientation: PropTypes.oneOf(["horizontal", "vertical"]),
|
|
788
|
+
className: PropTypes.string,
|
|
789
|
+
style: PropTypes.object
|
|
790
|
+
};
|
|
791
|
+
|
|
792
|
+
/////////////////////////////////////////////////////////
|
|
793
|
+
//
|
|
794
|
+
//
|
|
795
|
+
/////////////////////////////////////////////////////////
|
|
796
|
+
ReflexContainer.defaultProps = {
|
|
797
|
+
orientation: "horizontal",
|
|
798
|
+
className: "",
|
|
799
|
+
style: {}
|
|
800
|
+
};
|
|
801
|
+
|
|
802
|
+
export default ReflexContainer;
|