@teselagen/ove 0.7.28 → 0.7.30-beta.1

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