easy-layout 5.0.101 → 5.0.106

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 (38) hide show
  1. package/example.js +2682 -1278
  2. package/lib/constants.js +2 -4
  3. package/lib/cursor.js +1 -1
  4. package/lib/div/column.js +1 -1
  5. package/lib/div/columns.js +1 -1
  6. package/lib/div/row.js +1 -1
  7. package/lib/div/rows.js +1 -1
  8. package/lib/div/sizeable.js +1 -1
  9. package/lib/div/splitter/horizontal.js +21 -51
  10. package/lib/div/splitter/vertical.js +21 -51
  11. package/lib/div/splitter.js +57 -223
  12. package/lib/example/div/bottomLeft.js +1 -1
  13. package/lib/example/div/row/blue.js +1 -1
  14. package/lib/example/div/row/yellow.js +1 -1
  15. package/lib/example/div/sizeable/bottom.js +2 -2
  16. package/lib/example/div/sizeable/left.js +1 -1
  17. package/lib/example/div/sizeable/right.js +1 -1
  18. package/lib/example/div/splitter/horizontal/main.js +1 -61
  19. package/lib/example/div/splitter/pseudo.js +1 -1
  20. package/lib/example/div/splitter/vertical/left.js +1 -1
  21. package/lib/example/div/splitter/vertical/right.js +1 -1
  22. package/lib/example/preamble.js +1 -1
  23. package/lib/example/view.js +12 -13
  24. package/lib/example.js +1 -1
  25. package/lib/index.js +9 -9
  26. package/lib/section/sizeable.js +189 -0
  27. package/package.json +3 -2
  28. package/src/constants.js +0 -1
  29. package/src/div/splitter/horizontal.js +22 -67
  30. package/src/div/splitter/vertical.js +22 -67
  31. package/src/div/splitter.js +64 -201
  32. package/src/example/div/sizeable/bottom.js +0 -1
  33. package/src/example/div/splitter/horizontal/main.js +0 -19
  34. package/src/example/view.js +24 -10
  35. package/src/index.js +1 -2
  36. package/src/section/sizeable.js +19 -0
  37. package/lib/options.js +0 -13
  38. package/src/options.js +0 -7
@@ -2,254 +2,111 @@
2
2
 
3
3
  import withStyle from "easy-with-style"; ///
4
4
 
5
- import { window, Element, eventTypes } from "easy";
5
+ import { Element } from "easy";
6
+ import { dragMixins } from "easy-drag-and-drop";
6
7
 
7
8
  import SizeableDiv from "../div/sizeable";
9
+ import SizeableSection from "../section/sizeable";
8
10
 
9
11
  import { resetCursor } from "../cursor";
10
- import { ESCAPE_KEY_CODE } from "../constants";
11
- import { ESCAPE_KEY_STOPS_DRAGGING_OPTION } from "../options";
12
-
13
- const { BLUR_EVENT_TYPE, DRAG_EVENT_TYPE, MOUSEUP_EVENT_TYPE, STOP_DRAG_EVENT_TYPE, START_DRAG_EVENT_TYPE } = eventTypes;
14
12
 
15
13
  class SplitterDiv extends Element {
16
- constructor(selector, options) {
17
- super(selector);
18
-
19
- this.options = options;
20
- }
21
-
22
- isOptionPresent(option) {
23
- const optionPresent = !!this.options[option];
24
-
25
- return optionPresent;
26
- }
27
-
28
- setOptions(options) {
29
- this.options = options;
30
- }
31
-
32
- setOption(option) {
33
- this.options[option] = true;
34
- }
35
-
36
- unsetOption(option) {
37
- delete(this.options[option]);
38
- }
39
-
40
- onDrag(dragHandler, element) {
41
- const eventType = DRAG_EVENT_TYPE,
42
- handler = dragHandler; ///
43
-
44
- this.addEventListener(eventType, handler, element);
45
- }
46
-
47
- offDrag(dragHandler, element) {
48
- const eventType = DRAG_EVENT_TYPE,
49
- handler = dragHandler; ///
50
-
51
- this.removeEventListener(eventType, handler, element);
52
- }
53
-
54
- onStopDrag(stopDragHandler, element) {
55
- const eventType = STOP_DRAG_EVENT_TYPE,
56
- handler = stopDragHandler; ///
57
-
58
- this.addEventListener(eventType, handler, element);
59
- }
60
-
61
- offStopDrag(stopDragHandler, element) {
62
- const eventType = STOP_DRAG_EVENT_TYPE,
63
- handler = stopDragHandler; ///
14
+ mouseOutHandler(event, element) {
15
+ const disabled = this.isDisabled();
64
16
 
65
- this.removeEventListener(eventType, handler, element);
17
+ if (!disabled) {
18
+ resetCursor();
19
+ }
66
20
  }
67
21
 
68
- onStartDrag(stopDragHandler, element) {
69
- const eventType = START_DRAG_EVENT_TYPE,
70
- handler = stopDragHandler; ///
71
-
72
- this.addEventListener(eventType, handler, element);
73
- }
22
+ stopDragHandler(dropElement, aborted, element, done) {
23
+ const disabled = this.isDisabled();
74
24
 
75
- offStartDrag(stopDragHandler, element) {
76
- const eventType = START_DRAG_EVENT_TYPE,
77
- handler = stopDragHandler; ///
25
+ if (!disabled) {
26
+ resetCursor();
27
+ }
78
28
 
79
- this.removeEventListener(eventType, handler, element);
29
+ done();
80
30
  }
81
31
 
82
- callHandlers(eventType, ...remainingArguments) {
83
- const eventListeners = this.findEventListeners(eventType);
84
-
85
- eventListeners.forEach((eventListener) => {
86
- const { handler, element: handlerElement } = eventListener,
87
- element = this; ///
32
+ getSizeableElement() {
33
+ let sizeableElement;
88
34
 
89
- handler.call(handlerElement, ...remainingArguments, element);
90
- });
91
- }
35
+ const nextSiblingElement = this.getNextSiblingElement(),
36
+ previousSiblingElement = this.getPreviousSiblingElement(),
37
+ nextSiblingElementSizeableElement = isElementSizeableElement(nextSiblingElement),
38
+ previousSiblingElementSizeableElement = isElementSizeableElement(previousSiblingElement);
92
39
 
93
- enable() {
94
- this.removeClass("disabled");
95
- }
40
+ if (nextSiblingElementSizeableElement) {
41
+ sizeableElement = nextSiblingElement; ///
42
+ }
96
43
 
97
- disable() {
98
- this.addClass("disabled");
99
- }
44
+ if (previousSiblingElementSizeableElement) {
45
+ sizeableElement = previousSiblingElement; ///
46
+ }
100
47
 
101
- isDisabled() {
102
- const disabled = this.hasClass("disabled");
103
-
104
- return disabled;
48
+ return sizeableElement;
105
49
  }
106
50
 
107
- isDragging() {
108
- const dragging = this.hasClass("dragging");
109
-
110
- return dragging;
111
- }
112
-
113
51
  getDirection() {
114
52
  let direction;
115
53
 
116
54
  const nextSiblingElement = this.getNextSiblingElement(),
117
- previousSiblingElement = this.getPreviousSiblingElement();
55
+ previousSiblingElement = this.getPreviousSiblingElement(),
56
+ nextSiblingElementSizeableElement = isElementSizeableElement(nextSiblingElement),
57
+ previousSiblingElementSizeableElement = isElementSizeableElement(previousSiblingElement);
118
58
 
119
- if (nextSiblingElement instanceof SizeableDiv) {
59
+ if (nextSiblingElementSizeableElement) {
120
60
  direction = +1;
121
61
  }
122
62
 
123
- if (previousSiblingElement instanceof SizeableDiv) {
63
+ if (previousSiblingElementSizeableElement) {
124
64
  direction = -1;
125
65
  }
126
66
 
127
67
  return direction;
128
68
  }
129
69
 
130
- getSizeableDiv() {
131
- let sizeableDiv;
132
-
133
- const nextSiblingElement = this.getNextSiblingElement(),
134
- previousSiblingElement = this.getPreviousSiblingElement();
135
-
136
- if (nextSiblingElement instanceof SizeableDiv) {
137
- sizeableDiv = nextSiblingElement; ///
138
- }
139
-
140
- if (previousSiblingElement instanceof SizeableDiv) {
141
- sizeableDiv = previousSiblingElement; ///
142
- }
143
-
144
- return sizeableDiv;
145
- }
146
-
147
- startDrag() {
148
- const eventType = START_DRAG_EVENT_TYPE,
149
- escapeKeyStopsDraggingOptionPresent = this.isOptionPresent(ESCAPE_KEY_STOPS_DRAGGING_OPTION);
150
-
151
- if (escapeKeyStopsDraggingOptionPresent) {
152
- window.onKeyDown(this.keyDownHandler, this);
153
- }
154
-
155
- this.addClass("dragging");
156
-
157
- this.callHandlers(eventType)
158
- }
159
-
160
- stopDrag() {
161
- const eventType = STOP_DRAG_EVENT_TYPE,
162
- escapeKeyStopsDraggingOptionPresent = this.isOptionPresent(ESCAPE_KEY_STOPS_DRAGGING_OPTION);
163
-
164
- if (escapeKeyStopsDraggingOptionPresent) {
165
- window.offKeyDown(this.keyDownHandler, this);
166
- }
167
-
168
- this.removeClass("dragging");
169
-
170
- this.callHandlers(eventType);
171
- }
172
-
173
- mouseUpHandler(event, element) {
174
- const disabled = this.isDisabled();
175
-
176
- if (!disabled) {
177
- const dragging = this.isDragging();
178
-
179
- if (dragging) {
180
- this.stopDrag();
181
- }
182
-
183
- resetCursor();
184
- }
70
+ enable() {
71
+ this.removeClass("disabled");
185
72
  }
186
73
 
187
- mouseOutHandler(event, element) {
188
- const disabled = this.isDisabled();
189
-
190
- if (!disabled) {
191
- const dragging = this.isDragging();
192
-
193
- if (!dragging) {
194
- resetCursor();
195
- }
196
- }
74
+ disable() {
75
+ this.addClass("disabled");
197
76
  }
198
77
 
199
- keyDownHandler(event, element) {
200
- const { keyCode } = event;
201
-
202
- if (keyCode === ESCAPE_KEY_CODE) {
203
- const dragging = this.isDragging();
204
-
205
- if (dragging) {
206
- this.stopDrag();
207
- }
78
+ isDisabled() {
79
+ const disabled = this.hasClass("disabled");
208
80
 
209
- resetCursor();
210
- }
81
+ return disabled;
211
82
  }
212
83
 
213
84
  didMount() {
214
- const { onDrag, onStopDrag, onStartDrag, disabled } = this.properties,
215
- dragHandler = onDrag, ///
216
- stopDragHandler = onStopDrag, ///
217
- startDragHandler = onStartDrag; ///
85
+ this.enableDrag();
218
86
 
219
- (disabled === true) ? ///
220
- this.disable() :
221
- this.enable();
87
+ this.onDrag(this.dragHandler, this);
222
88
 
223
- dragHandler && this.onDrag(dragHandler);
224
- stopDragHandler && this.onStopDrag(stopDragHandler);
225
- startDragHandler && this.onStartDrag(startDragHandler);
89
+ this.onStopDrag(this.stopDragHandler, this);
226
90
 
227
- window.on(`${BLUR_EVENT_TYPE} ${MOUSEUP_EVENT_TYPE}`, this.mouseUpHandler, this); ///
91
+ this.onStartDrag(this.startDragHandler, this);
228
92
 
229
- window.onMouseMove(this.mouseMoveHandler, this);
230
-
231
- this.onMouseDown(this.mouseDownHandler, this);
232
93
  this.onMouseOver(this.mouseOverHandler, this);
94
+
233
95
  this.onMouseOut(this.mouseOutHandler, this);
234
96
  }
235
97
 
236
98
  willUnmount() {
237
- const { onDrag, onStopDrag, onStartDrag } = this.properties,
238
- dragHandler = onDrag, ///
239
- stopDragHandler = onStopDrag, ///
240
- startDragHandler = onStartDrag; ///
99
+ this.offMouseOut(this.mouseOutHandler, this);
241
100
 
242
- dragHandler && this.offDrag(dragHandler);
243
- stopDragHandler && this.offStopDrag(stopDragHandler);
244
- startDragHandler && this.offStartDrag(startDragHandler);
101
+ this.offMouseOver(this.mouseOverHandler, this);
245
102
 
246
- window.off(`${BLUR_EVENT_TYPE} ${MOUSEUP_EVENT_TYPE}`, this.mouseUpHandler, this); ///
103
+ this.offStartDrag(this.startDragHandler, this);
247
104
 
248
- window.offMouseMove(this.mouseMoveHandler, this);
105
+ this.offStopDrag(this.stopDragHandler, this);
249
106
 
250
- this.offMouseDown(this.mouseDownHandler, this);
251
- this.offMouseOver(this.mouseOverHandler, this);
252
- this.offMouseOut(this.mouseOutHandler, this);
107
+ this.offDrag(this.dragHandler, this);
108
+
109
+ this.disableDrag();
253
110
  }
254
111
 
255
112
  initialise() {
@@ -258,28 +115,34 @@ class SplitterDiv extends Element {
258
115
 
259
116
  static tagName = "div";
260
117
 
261
- static defaultProperties = {
262
- className: "splitter"
263
- };
264
-
265
118
  static ignoredProperties = [
266
119
  "onDrag",
267
- "options",
268
120
  "disabled",
269
121
  "onStopDrag",
270
122
  "onStartDrag"
271
123
  ];
272
124
 
125
+ static defaultProperties = {
126
+ className: "splitter"
127
+ };
128
+
273
129
  static fromClass(Class, properties) {
274
- const { options = {} } = properties,
275
- splitterDiv = Element.fromClass(Class, properties, options);
130
+ const splitterDiv = Element.fromClass(Class, properties);
276
131
 
277
132
  return splitterDiv;
278
133
  }
279
134
  }
280
135
 
136
+ Object.assign(SplitterDiv.prototype, dragMixins);
137
+
281
138
  export default withStyle(SplitterDiv)`
282
139
 
283
140
  flex-shrink: 0;
284
141
 
285
142
  `;
143
+
144
+ function isElementSizeableElement(element) {
145
+ const elementSizeableElement = (element instanceof SizeableDiv) || (element instanceof SizeableSection);
146
+
147
+ return elementSizeableElement;
148
+ }
@@ -13,6 +13,5 @@ class BottomSizeableDiv extends SizeableDiv {
13
13
  export default withStyle(BottomSizeableDiv)`
14
14
 
15
15
  height: 24rem;
16
- max-height: 40rem;
17
16
 
18
17
  `;
@@ -5,25 +5,6 @@ import withStyle from "easy-with-style"; ///
5
5
  import { HorizontalSplitterDiv } from "../../../../index"; ///
6
6
 
7
7
  class MainHorizontalSplitterDiv extends HorizontalSplitterDiv {
8
- dragHandler(sizeableDivHeight) {
9
- const { bottomLeftDiv } = this.properties,
10
- height = sizeableDivHeight; ///
11
-
12
- bottomLeftDiv.setHeight(height);
13
- }
14
-
15
- didMount() {
16
- super.didMount();
17
-
18
- this.onDrag(this.dragHandler, this);
19
- }
20
-
21
- willUnmount() {
22
- this.offDrag(this.dragHandler, this);
23
-
24
- super.willUnmount();
25
- }
26
-
27
8
  static defaultProperties = {
28
9
  className: "main"
29
10
  };
@@ -2,7 +2,7 @@
2
2
 
3
3
  import withStyle from "easy-with-style"; ///
4
4
 
5
- import { RowDiv, RowsDiv, ColumnDiv, ColumnsDiv, options } from "../index"; ///
5
+ import { RowDiv, RowsDiv, ColumnDiv, ColumnsDiv } from "../index"; ///
6
6
 
7
7
  import BlueRowDiv from "./div/row/blue";
8
8
  import YellowRowDiv from "./div/row/yellow";
@@ -15,8 +15,6 @@ import LeftVerticalSplitterDiv from "./div/splitter/vertical/left";
15
15
  import RightVerticalSplitterDiv from "./div/splitter/vertical/right";
16
16
  import MainHorizontalSplitterDiv from "./div/splitter/horizontal/main";
17
17
 
18
- const { ESCAPE_KEY_STOPS_DRAGGING_OPTION } = options;
19
-
20
18
  const View = (properties) => {
21
19
  const { className } = properties,
22
20
  bottomLeftDiv =
@@ -24,9 +22,13 @@ const View = (properties) => {
24
22
  <BottomLeftDiv/>
25
23
 
26
24
  ,
27
- options = {
28
- ESCAPE_KEY_STOPS_DRAGGING_OPTION
29
- };
25
+ bottomSizeableDiv =
26
+
27
+ <BottomSizeableDiv/>
28
+
29
+ ;
30
+
31
+ let bottomSizeableDivHeight;
30
32
 
31
33
  return (
32
34
 
@@ -39,13 +41,13 @@ const View = (properties) => {
39
41
  {bottomLeftDiv}
40
42
  </RowsDiv>
41
43
  </LeftSizeableDiv>
42
- <LeftVerticalSplitterDiv options={options} />
44
+ <LeftVerticalSplitterDiv/>
43
45
  <ColumnDiv>
44
46
  <RowsDiv>
45
47
  <RowDiv>
46
48
  <ColumnsDiv>
47
49
  <ColumnDiv/>
48
- <RightVerticalSplitterDiv options={options} />
50
+ <RightVerticalSplitterDiv/>
49
51
  <RightSizeableDiv>
50
52
  <RowsDiv>
51
53
  <BlueRowDiv/>
@@ -53,8 +55,20 @@ const View = (properties) => {
53
55
  </RightSizeableDiv>
54
56
  </ColumnsDiv>
55
57
  </RowDiv>
56
- <MainHorizontalSplitterDiv bottomLeftDiv={bottomLeftDiv} options={options} />
57
- <BottomSizeableDiv/>
58
+ <MainHorizontalSplitterDiv onStartDrag={(element) => {
59
+
60
+ bottomSizeableDivHeight = bottomSizeableDiv.getHeight();
61
+
62
+ }}
63
+ onDrag={(relativeMouseTop, relativeMouseLeft) => {
64
+
65
+ const height = bottomSizeableDivHeight - relativeMouseTop;
66
+
67
+ bottomLeftDiv.setHeight(height);
68
+
69
+ }}
70
+ />
71
+ {bottomSizeableDiv}
58
72
  </RowsDiv>
59
73
  </ColumnDiv>
60
74
  </ColumnsDiv>
package/src/index.js CHANGED
@@ -1,12 +1,11 @@
1
1
  'use strict';
2
2
 
3
- export { default as options } from "./options";
4
-
5
3
  export { default as RowDiv } from "./div/row";
6
4
  export { default as RowsDiv } from "./div/rows";
7
5
  export { default as ColumnDiv } from "./div/column";
8
6
  export { default as ColumnsDiv } from "./div/columns";
9
7
  export { default as SplitterDiv } from "./div/splitter";
10
8
  export { default as SizeableDiv } from "./div/sizeable";
9
+ export { default as SizeableSection } from "./section/sizeable";
11
10
  export { default as VerticalSplitterDiv } from "./div/splitter/vertical";
12
11
  export { default as HorizontalSplitterDiv } from "./div/splitter/horizontal";
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ import withStyle from "easy-with-style"; ///
4
+
5
+ import { Element } from "easy";
6
+
7
+ class SizeableSection extends Element {
8
+ static tagName = "section";
9
+
10
+ static defaultProperties = {
11
+ className: "sizeable"
12
+ };
13
+ }
14
+
15
+ export default withStyle(SizeableSection)`
16
+
17
+ display: flex;
18
+
19
+ `;
package/lib/options.js DELETED
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- exports.default = exports.ESCAPE_KEY_STOPS_DRAGGING_OPTION = void 0;
6
- var ESCAPE_KEY_STOPS_DRAGGING_OPTION = "ESCAPE_KEY_STOPS_DRAGGING";
7
- exports.ESCAPE_KEY_STOPS_DRAGGING_OPTION = ESCAPE_KEY_STOPS_DRAGGING_OPTION;
8
- var _default = {
9
- ESCAPE_KEY_STOPS_DRAGGING_OPTION: ESCAPE_KEY_STOPS_DRAGGING_OPTION
10
- };
11
- exports.default = _default;
12
-
13
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9vcHRpb25zLmpzIl0sInNvdXJjZXNDb250ZW50IjpbIlwidXNlIHN0cmljdFwiO1xuXG5leHBvcnQgY29uc3QgRVNDQVBFX0tFWV9TVE9QU19EUkFHR0lOR19PUFRJT04gPSBcIkVTQ0FQRV9LRVlfU1RPUFNfRFJBR0dJTkdcIjtcblxuZXhwb3J0IGRlZmF1bHQge1xuICBFU0NBUEVfS0VZX1NUT1BTX0RSQUdHSU5HX09QVElPTlxufTtcbiJdLCJuYW1lcyI6WyJFU0NBUEVfS0VZX1NUT1BTX0RSQUdHSU5HX09QVElPTiJdLCJtYXBwaW5ncyI6IkFBQUEsQ0FBWSxXQUFBLENBQUM7OztFQUFiO21FQUFBO0FBRU8sR0FBSyxDQUFDQSxnQ0FBZ0MsR0FBRyxDQUEyQjtRQUE5REEsZ0NBQWdDLEdBQWhDQSxnQ0FBZ0MsQUFGN0M7ZUFJZSxDQUFDO0lBQ2RBLGdDQUFnQyxFQUFoQ0EsZ0NBQWdDO0FBQ2xDLENBQUM7MEJBTkQifQ==
package/src/options.js DELETED
@@ -1,7 +0,0 @@
1
- "use strict";
2
-
3
- export const ESCAPE_KEY_STOPS_DRAGGING_OPTION = "ESCAPE_KEY_STOPS_DRAGGING";
4
-
5
- export default {
6
- ESCAPE_KEY_STOPS_DRAGGING_OPTION
7
- };