@teselagen/ove 0.7.28 → 0.7.29

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.
Files changed (285) hide show
  1. package/index.cjs.js +1055 -996
  2. package/index.es.js +1055 -996
  3. package/index.umd.js +189036 -0
  4. package/ove.css +1 -1
  5. package/package.json +2 -6
  6. package/src/helperComponents/PropertiesDialog/TranslationProperties.js +1 -1
  7. package/AASliver.js +0 -187
  8. package/AddLaddersDialog.js +0 -82
  9. package/AdditionalCutsiteInfoDialog.js +0 -599
  10. package/AlignmentVisibilityTool.js +0 -105
  11. package/AnnotationContainerHolder.js +0 -20
  12. package/AnnotationPositioner.js +0 -27
  13. package/AutoAnnotate.js +0 -501
  14. package/AutoAnnotateBpMatchingDialog.js +0 -208
  15. package/Axis.js +0 -151
  16. package/AxisNumbers.js +0 -35
  17. package/Browser.js +0 -106
  18. package/Caret.js +0 -63
  19. package/Chromatogram.js +0 -293
  20. package/CircularDnaSequence.js +0 -73
  21. package/CircularZoomMinimap.js +0 -16
  22. package/ColorPicker.js +0 -30
  23. package/CommandHotkeyHandler.js +0 -44
  24. package/CreateAnnotationsPage.js +0 -98
  25. package/Cutsite.js +0 -18
  26. package/CutsiteProperties.js +0 -176
  27. package/CutsiteSelectionLayers.js +0 -47
  28. package/Cutsites.js +0 -271
  29. package/DeletionLayer.js +0 -28
  30. package/DropHandler.css +0 -21
  31. package/DropHandler.js +0 -64
  32. package/EditCaretPosition.js +0 -234
  33. package/EditTrackNameDialog.js +0 -30
  34. package/Feature.js +0 -83
  35. package/FeatureProperties.js +0 -6
  36. package/FillWindow.js +0 -47
  37. package/GenbankView.js +0 -74
  38. package/GeneralProperties.js +0 -117
  39. package/GenericAnnotationProperties.js +0 -406
  40. package/GlobalDialog.js +0 -73
  41. package/GlobalDialogUtils.js +0 -110
  42. package/GoToDialog.js +0 -25
  43. package/HorizontalPanelDragHandle.js +0 -35
  44. package/Keyboard.js +0 -85
  45. package/Labels.js +0 -327
  46. package/Ladder.css +0 -20
  47. package/Ladder.js +0 -303
  48. package/MeltingTemp.js +0 -85
  49. package/Menlo.ttf +0 -0
  50. package/Minimap.js +0 -515
  51. package/Mismatches.js +0 -134
  52. package/Monaco.ttf +0 -0
  53. package/MultipleSeqsDetectedOnImportDialog.js +0 -74
  54. package/Orf.js +0 -109
  55. package/OrfProperties.js +0 -117
  56. package/Orfs.js +0 -35
  57. package/PCRTool.js +0 -179
  58. package/PairwiseAlignmentView.js +0 -68
  59. package/Part.js +0 -34
  60. package/PartProperties.js +0 -9
  61. package/PassThrough.js +0 -3
  62. package/PerformantSelectionLayer.js +0 -32
  63. package/PinchHelper.js +0 -24
  64. package/PointedAnnotation.js +0 -347
  65. package/PositionAnnotationOnCircle.js +0 -26
  66. package/Primer.js +0 -41
  67. package/PrimerProperties.js +0 -19
  68. package/ReflexContainer.js +0 -802
  69. package/ReflexElement.js +0 -160
  70. package/ReflexEvents.js +0 -77
  71. package/ReflexSplitter.js +0 -205
  72. package/RenameSequenceDialog.js +0 -7
  73. package/RotateCircularViewSlider.js +0 -93
  74. package/SelectDialog.js +0 -150
  75. package/SequenceName.js +0 -15
  76. package/SimpleCircularOrLinearView.js +0 -381
  77. package/SimpleOligoPreview.js +0 -39
  78. package/SingleEnzymeCutsiteInfo.js +0 -139
  79. package/ToolbarItem.js +0 -192
  80. package/Translation.js +0 -198
  81. package/TranslationProperties.js +0 -149
  82. package/UncontrolledSliderWithPlusMinusBtns.css +0 -5
  83. package/UncontrolledSliderWithPlusMinusBtns.js +0 -134
  84. package/VeTopRightContainer.js +0 -12
  85. package/ZoomCircularViewSlider.js +0 -62
  86. package/ZoomLinearView.js +0 -47
  87. package/addAlignment.js +0 -6
  88. package/addMetaToActionCreators.js +0 -12
  89. package/addWrappedAddons.js +0 -20
  90. package/alignmentTool.js +0 -503
  91. package/alignments.js +0 -379
  92. package/annotationLabelVisibility.js +0 -2
  93. package/annotationSearchSelector.js +0 -24
  94. package/annotationTypes.js +0 -35
  95. package/annotationVisibility.js +0 -196
  96. package/annotationsToSupport.js +0 -104
  97. package/arrayToObjWithIds.js +0 -17
  98. package/arrayUtils.js +0 -19
  99. package/array_move.js +0 -10
  100. package/calculateTickMarkPositionsForGivenRange.js +0 -47
  101. package/caretPosition.js +0 -27
  102. package/cdsFeaturesSelector.js +0 -9
  103. package/charWidth.js +0 -22
  104. package/circular.js +0 -19
  105. package/circularSelector.js +0 -4
  106. package/clickAndDragUtils.js +0 -576
  107. package/coerceInitialValue.js +0 -7
  108. package/combineReducersDontIgnoreKeys.js +0 -12
  109. package/commandUtils.js +0 -20
  110. package/constants.js +0 -2
  111. package/copyOptions.js +0 -34
  112. package/createFragmentLines.js +0 -120
  113. package/createMergedDefaultStateReducer.js +0 -30
  114. package/createMetaAction.js +0 -12
  115. package/createSequenceInputPopup.js +0 -290
  116. package/createSequenceInputPopupStyle.css +0 -87
  117. package/createSimpleDialog.js +0 -89
  118. package/createYourOwnEnzyme.js +0 -39
  119. package/cutsiteLabelColorSelector.js +0 -6
  120. package/cutsiteTool.js +0 -88
  121. package/cutsitesByRangeSelector.js +0 -5
  122. package/cutsitesSelector.js +0 -61
  123. package/darkmode.css +0 -98
  124. package/defaultConfig.js +0 -150
  125. package/deletionLayers.js +0 -36
  126. package/description.js +0 -21
  127. package/digestTool.js +0 -34
  128. package/dnaToColor.js +0 -17
  129. package/downloadTool.js +0 -39
  130. package/draggableClassnames.js +0 -5
  131. package/drawAnnotations.js +0 -440
  132. package/drawDirectedPiePiece.js +0 -142
  133. package/editTool.js +0 -49
  134. package/editorSelector.js +0 -2
  135. package/editorUtils.js +0 -205
  136. package/estimateRowHeight.js +0 -184
  137. package/featureLengthsToHide.js +0 -27
  138. package/featureTool.js +0 -34
  139. package/features.js +0 -19
  140. package/featuresSelector.js +0 -8
  141. package/filteredCutsitesSelector.js +0 -136
  142. package/filteredFeaturesSelector.js +0 -32
  143. package/filteredPartsSelector.js +0 -57
  144. package/filteredPrimersSelector.js +0 -27
  145. package/filteredRestrictionEnzymesSelector.js +0 -1
  146. package/find.png +0 -0
  147. package/findTool.js +0 -79
  148. package/findToolConstants.js +0 -1
  149. package/frameTranslations.js +0 -52
  150. package/fullscreen.png +0 -0
  151. package/getAdditionalEnzymesSelector.js +0 -46
  152. package/getAngleForPositionMidpoint.js +0 -3
  153. package/getAnnotationClassnames.js +0 -12
  154. package/getAnnotationNameAndStartStopString.js +0 -61
  155. package/getBpsPerRow.js +0 -19
  156. package/getCutsiteLabelHeights.js +0 -56
  157. package/getGapMap.js +0 -12
  158. package/getGaps.js +0 -27
  159. package/getInternalLabel.js +0 -40
  160. package/getOveHotkeyDefs.js +0 -12
  161. package/getPairwiseOverviewLinearViewOptions.js +0 -38
  162. package/getRangeAnglesSpecial.js +0 -12
  163. package/getStructuredBases.js +0 -97
  164. package/getTrackFromEvent.js +0 -25
  165. package/getVisibleStartEnd.js +0 -7
  166. package/getXStartAndWidthFromNonCircularRange.js +0 -12
  167. package/getXStartAndWidthOfRangeWrtRow.js +0 -27
  168. package/getXStartAndWidthOfRowAnnotation.js +0 -19
  169. package/getYOffset.js +0 -15
  170. package/hoveredAnnotation.js +0 -24
  171. package/importTool.js +0 -27
  172. package/index.js +0 -71
  173. package/inlineFindTool.js +0 -38
  174. package/isElementInViewport.js +0 -29
  175. package/isEnzymeFilterAndSelector.js +0 -1
  176. package/isTargetWithinEl.js +0 -6
  177. package/labelLineIntensity.js +0 -25
  178. package/labelSize.js +0 -23
  179. package/ladderDefaults.js +0 -25
  180. package/lastSavedId.js +0 -20
  181. package/lineageLines.js +0 -11
  182. package/linear.png +0 -0
  183. package/makeStore.js +0 -34
  184. package/massageTickSpacing.js +0 -19
  185. package/materiallyAvailable.js +0 -19
  186. package/middleware.js +0 -112
  187. package/minimumOrfSize.js +0 -24
  188. package/minimumOrfSizeSelector.js +0 -2
  189. package/modalActions.js +0 -3
  190. package/moveCaret.js +0 -58
  191. package/name.js +0 -19
  192. package/normalizeAngle.js +0 -3
  193. package/normalizeAngleRange.js +0 -9
  194. package/oligoTool.js +0 -30
  195. package/onlyUpdateForKeysDeep.js +0 -31
  196. package/orfFrameToColorMap.js +0 -10
  197. package/orfTool.js +0 -136
  198. package/orfsSelector.js +0 -15
  199. package/panelsShown.js +0 -294
  200. package/partLengthsToHide.js +0 -23
  201. package/partOverhangs.js +0 -6
  202. package/partTagSearch.js +0 -69
  203. package/partTool.js +0 -45
  204. package/parts.js +0 -19
  205. package/partsSelector.js +0 -8
  206. package/pie.png +0 -0
  207. package/polarToSpecialCartesian.js +0 -7
  208. package/positionCutsites.js +0 -6
  209. package/prepareRowData.js +0 -64
  210. package/primerBases.js +0 -221
  211. package/primerLengthsToHide.js +0 -27
  212. package/primers.js +0 -19
  213. package/primersSelector.js +0 -8
  214. package/print.png +0 -0
  215. package/printTool.js +0 -31
  216. package/propertiesTool.js +0 -40
  217. package/proteinUtils.js +0 -3
  218. package/pureNoFunc.js +0 -18
  219. package/readOnly.js +0 -25
  220. package/redoTool.js +0 -30
  221. package/reflex-styles.css +0 -128
  222. package/reflex-styles.css.map +0 -9
  223. package/relaxLabelAngles.js +0 -157
  224. package/relaxLabels_DEPRECATED.js +0 -105
  225. package/replacementLayers.js +0 -36
  226. package/restrictionEnzymes.js +0 -52
  227. package/restrictionEnzymesSelector.js +0 -34
  228. package/rowviewContants.js +0 -3
  229. package/ruler.css +0 -89
  230. package/save.png +0 -0
  231. package/saveTool.js +0 -44
  232. package/searchLayersSelector.js +0 -71
  233. package/selectedAnnotations.js +0 -89
  234. package/selectedAnnotationsSelector.js +0 -1
  235. package/selectedCutsitesSelector.js +0 -21
  236. package/selectedPartTags.js +0 -21
  237. package/selectionLayer.js +0 -25
  238. package/sequence.js +0 -12
  239. package/sequenceDataHistory.js +0 -43
  240. package/sequenceDataSelector.js +0 -2
  241. package/sequenceLengthSelector.js +0 -5
  242. package/sequenceSelector.js +0 -4
  243. package/sharedActionCreators.js +0 -0
  244. package/shouldFlipText.js +0 -4
  245. package/shouldRerender.js +0 -27
  246. package/showFileDialog.js +0 -25
  247. package/showGCContent.js +0 -23
  248. package/show_cut_sites.png +0 -0
  249. package/show_features.png +0 -0
  250. package/show_orfs.png +0 -0
  251. package/show_primers.png +0 -0
  252. package/simpleDialog.css +0 -13
  253. package/specialCutsiteFilterOptions.js +0 -22
  254. package/style.css +0 -10
  255. package/tagsToBoldSelector.js +0 -2
  256. package/toggle_views.svg +0 -1
  257. package/toolBar.js +0 -23
  258. package/translationSearchMatchesSelector.js +0 -14
  259. package/translations.js +0 -20
  260. package/translationsRawSelector.js +0 -8
  261. package/translationsSelector.js +0 -137
  262. package/typeField.js +0 -24
  263. package/undoTool.js +0 -30
  264. package/updateEditor.js +0 -200
  265. package/updateLabelsForInViewFeatures.js +0 -55
  266. package/updateLabelsForInViewFeaturesCircView.js +0 -41
  267. package/updateTrackHelper.js +0 -58
  268. package/uppercaseSequenceMapFont.js +0 -25
  269. package/upsertDeleteActionGenerator.js +0 -31
  270. package/useAAColorType.js +0 -8
  271. package/useAdditionalOrfStartCodons.js +0 -24
  272. package/useAnnotationLimits.js +0 -42
  273. package/useChromatogramPrefs.js +0 -31
  274. package/useFormValue.js +0 -7
  275. package/useLadders.js +0 -6
  276. package/useMeltingTemp.js +0 -7
  277. package/useTmType.js +0 -10
  278. package/userDefinedHandlersAndOpts.js +0 -61
  279. package/utils.js +0 -37
  280. package/versionHistory.js +0 -26
  281. package/versionHistoryTool.js +0 -21
  282. package/viewSubmenu.js +0 -479
  283. package/visibilityTool.js +0 -39
  284. package/withHover.js +0 -113
  285. package/withRestrictionEnzymes.js +0 -15
@@ -1,802 +0,0 @@
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;