highmark-cli 0.0.133 → 0.0.138

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/src/view.js CHANGED
@@ -1,10 +1,494 @@
1
1
  "use strict";
2
2
 
3
- import { Element } from "easy";
3
+ import withStyle from "easy-with-style";
4
+
5
+ import { keyCodes } from "necessary";
6
+ import { Element, window } from "easy";
7
+
8
+ import LeafDiv from "./view/div/leaf";
9
+ import MenuDiv from "./view/div/menu";
10
+ import touchMixins from "./mixins/touch";
11
+
12
+ import { leafNodesFromNodeList } from "./utilities/tree";
13
+ import { elementsFromDOMElements } from "./utilities/element";
14
+ import { VIEW_CHILD_DIVS_SELECTOR } from "./selectors";
15
+ import { SHOW_DELAY, ZOOM_RATIO, SCROLL_DELAY, UP_DIRECTION, DECELERATION, DOWN_DIRECTION, MENU_DIV_SWIPE_BOTTOM } from "./constants";
16
+
17
+ const { ENTER_KEY_CODE,
18
+ ESCAPE_KEY_CODE,
19
+ BACKSPACE_KEY_CODE,
20
+ ARROW_UP_KEY_CODE,
21
+ ARROW_DOWN_KEY_CODE,
22
+ ARROW_LEFT_KEY_CODE,
23
+ ARROW_RIGHT_KEY_CODE } = keyCodes;
24
+
25
+ class View extends Element {
26
+ doubleTapCustomHandler = (event, element) => {
27
+ this.enableNativeGestures();
28
+ }
29
+
30
+ pinchStartCustomHandler = (event, element) => {
31
+ const nativeGesturesEnabled = this.areNativeGesturesEnabled();
32
+
33
+ if (nativeGesturesEnabled) {
34
+ return;
35
+ }
36
+
37
+ const zoom = this.getZoom(),
38
+ startZoom = zoom; ///
39
+
40
+ this.setStartZoom(startZoom);
41
+ }
42
+
43
+ pinchMoveCustomHandler = (event, element, ratio) => {
44
+ const nativeGesturesEnabled = this.areNativeGesturesEnabled();
45
+
46
+ if (nativeGesturesEnabled) {
47
+ return;
48
+ }
49
+
50
+ const startZoom = this.getStartZoom(),
51
+ zoom = startZoom * Math.sqrt(ratio);
52
+
53
+ this.setZoom(zoom);
54
+
55
+ this.zoom(zoom);
56
+ }
57
+
58
+ swipeRightCustomHandler = (event, element) => {
59
+ const nativeGesturesEnabled = this.areNativeGesturesEnabled();
60
+
61
+ if (nativeGesturesEnabled) {
62
+ return;
63
+ }
64
+
65
+ this.showLeftLeafDiv();
66
+ }
67
+
68
+ swipeLeftCustomHandler = (event, element) => {
69
+ const nativeGesturesEnabled = this.areNativeGesturesEnabled();
70
+
71
+ if (nativeGesturesEnabled) {
72
+ return;
73
+ }
74
+
75
+ this.showRightLeftDiv();
76
+ }
77
+
78
+ swipeDownCustomHandler = (event, element, top, left, speed) => {
79
+ const nativeGesturesEnabled = this.areNativeGesturesEnabled();
80
+
81
+ if (nativeGesturesEnabled) {
82
+ return;
83
+ }
84
+
85
+ const direction = DOWN_DIRECTION;
86
+
87
+ this.scroll(speed, direction);
88
+ }
89
+
90
+ swipeUpCustomHandler = (event, element, top, left, speed) => {
91
+ const nativeGesturesEnabled = this.areNativeGesturesEnabled();
92
+
93
+ if (nativeGesturesEnabled) {
94
+ return;
95
+ }
96
+
97
+ const height = this.getHeight(),
98
+ bottom = height - top;
99
+
100
+ if (bottom < MENU_DIV_SWIPE_BOTTOM) {
101
+ this.showMenuDiv();
102
+
103
+ return;
104
+ }
105
+
106
+ const direction = UP_DIRECTION;
107
+
108
+ this.scroll(speed, direction);
109
+ }
110
+
111
+ dragStartCustomHandler = (event, element) => {
112
+ const nativeGesturesEnabled = this.areNativeGesturesEnabled();
113
+
114
+ if (nativeGesturesEnabled) {
115
+ return;
116
+ }
117
+
118
+ const scrollTop = this.getScrollTop(),
119
+ startScrollTop = scrollTop; ///
120
+
121
+ this.setStartScrollTop(startScrollTop);
122
+ }
123
+
124
+ dragDownCustomHandler = (event, element, top, left) => {
125
+ const nativeGesturesEnabled = this.areNativeGesturesEnabled();
126
+
127
+ if (nativeGesturesEnabled) {
128
+ return;
129
+ }
130
+
131
+ const startScrollTop = this.getStartScrollTop(),
132
+ scrollTop = startScrollTop - top;
133
+
134
+ this.setScrollTop(scrollTop);
135
+ }
136
+
137
+ dragUpCustomHandler = (event, element, top, left) => {
138
+ const nativeGesturesEnabled = this.areNativeGesturesEnabled();
139
+
140
+ if (nativeGesturesEnabled) {
141
+ return;
142
+ }
143
+
144
+ const startScrollTop = this.getStartScrollTop(),
145
+ scrollTop = startScrollTop - top;
146
+
147
+ this.setScrollTop(scrollTop);
148
+ }
149
+
150
+ tapCustomHandler = (event, element) => {
151
+
152
+ alert("view tap...")
153
+
154
+ this.disableNativeGestures();
155
+ }
156
+
157
+ keyDownHandler = (event, element) => {
158
+ const { keyCode } = event;
159
+
160
+ switch (keyCode) {
161
+ case ENTER_KEY_CODE:
162
+ case ARROW_RIGHT_KEY_CODE: {
163
+ this.showRightLeftDiv();
164
+
165
+ break;
166
+ }
167
+
168
+ case BACKSPACE_KEY_CODE:
169
+ case ARROW_LEFT_KEY_CODE: {
170
+ this.showLeftLeafDiv();
171
+
172
+ break;
173
+ }
174
+
175
+ case ESCAPE_KEY_CODE: {
176
+ ///
177
+
178
+ break;
179
+ }
180
+
181
+ case ARROW_UP_KEY_CODE: {
182
+ this.showFirstLeftDiv();
183
+
184
+ break;
185
+ }
186
+
187
+ case ARROW_DOWN_KEY_CODE: {
188
+ this.showLastLeafDiv();
189
+
190
+ break;
191
+ }
192
+ }
193
+ }
194
+
195
+ zoomOut() {
196
+ let zoom = this.getZoom();
197
+
198
+ zoom /= ZOOM_RATIO;
199
+
200
+ this.setZoom(zoom);
201
+
202
+ this.zoom(zoom);
203
+ }
204
+
205
+ zoomIn() {
206
+ let zoom = this.getZoom();
207
+
208
+ zoom *= ZOOM_RATIO;
209
+
210
+ this.setZoom(zoom);
211
+
212
+ this.zoom(zoom);
213
+ }
214
+
215
+ zoom(zoom) {
216
+ const displayedLeafDiv = this.findDisplayedLeafDiv();
217
+
218
+ displayedLeafDiv.zoom(zoom);
219
+ }
220
+
221
+ scroll(speed, direction) {
222
+ let scrollTop = this.getScrollTop();
223
+
224
+ scrollTop += speed * SCROLL_DELAY;
225
+
226
+ this.setScrollTop(scrollTop);
227
+
228
+ let interval = this.getInterval();
229
+
230
+ if (interval !== null) {
231
+ clearInterval(interval);
232
+ }
233
+
234
+ interval = setInterval(() => {
235
+ speed = speed - direction * DECELERATION;
236
+
237
+ if ((speed * direction) < 0) {
238
+ clearInterval(interval);
239
+
240
+ interval = null;
241
+
242
+ this.setInterval(interval);
243
+ }
244
+
245
+ let scrollTop = this.getScrollTop();
246
+
247
+ scrollTop += speed * SCROLL_DELAY;
248
+
249
+ this.setScrollTop(scrollTop);
250
+ }, SCROLL_DELAY);
251
+
252
+ this.setInterval(interval);
253
+ }
254
+
255
+ showFirstLeftDiv() {
256
+ const displayedLeafDiv = this.findDisplayedLeafDiv(),
257
+ leafDivs = this.getLeafDivs(),
258
+ index = leafDivs.indexOf(displayedLeafDiv),
259
+ nextIndex = 0,
260
+ previousIndex = index; ///
261
+
262
+ this.showNextLeafDiv(nextIndex, previousIndex);
263
+ }
264
+
265
+ showLeftLeafDiv() {
266
+ const displayedLeafDiv = this.findDisplayedLeafDiv(),
267
+ leafDivs = this.getLeafDivs(),
268
+ index = leafDivs.indexOf(displayedLeafDiv),
269
+ nextIndex = index - 1,
270
+ previousIndex = index; ///
271
+
272
+ this.showNextLeafDiv(nextIndex, previousIndex);
273
+ }
274
+
275
+ showRightLeftDiv() {
276
+ const displayedLeafDiv = this.findDisplayedLeafDiv(),
277
+ leafDivs = this.getLeafDivs(),
278
+ index = leafDivs.indexOf(displayedLeafDiv),
279
+ nextIndex = index + 1,
280
+ previousIndex = index; ///
281
+
282
+ this.showNextLeafDiv(nextIndex, previousIndex);
283
+ }
284
+
285
+ showLastLeafDiv() {
286
+ const displayedLeafDiv = this.findDisplayedLeafDiv(),
287
+ leafDivs = this.getLeafDivs(),
288
+ index = leafDivs.indexOf(displayedLeafDiv),
289
+ leafDivsLength = leafDivs.length,
290
+ nextIndex = leafDivsLength - 1,
291
+ previousIndex = index; ///
292
+
293
+ this.showNextLeafDiv(nextIndex, previousIndex);
294
+ }
295
+
296
+ showNextLeafDiv(nextIndex, previousIndex) {
297
+ const leafDivs = this.getLeafDivs(),
298
+ leafDivsLength = leafDivs.length,
299
+ previousLeafDiv = leafDivs[previousIndex];
300
+
301
+ if ((nextIndex === -1) || (nextIndex === previousIndex) || (nextIndex === leafDivsLength)) {
302
+ return;
303
+ }
304
+
305
+ previousLeafDiv.hide();
306
+
307
+ const nextLeafDiv = leafDivs[nextIndex],
308
+ zoom = this.getZoom();
309
+
310
+ nextLeafDiv.zoom(zoom);
311
+
312
+ setTimeout(() => {
313
+ const scrollTop = 0;
314
+
315
+ nextLeafDiv.setScrollTop(scrollTop);
316
+
317
+ nextLeafDiv.show();
318
+ }, SHOW_DELAY);
319
+ }
320
+
321
+ enableNativeGestures() {
322
+ this.addClass("native-gestures");
323
+ }
324
+
325
+ disableNativeGestures() {
326
+ this.removeClass("native-gestures");
327
+ }
328
+
329
+ forEachLeafDiv(callback) {
330
+ const leafDivs = this.getLeafDivs();
331
+
332
+ leafDivs.forEach(callback);
333
+ }
334
+
335
+ findDisplayedLeafDiv() {
336
+ const leafDivs = this.getLeafDivs(),
337
+ displayedLeafDiv = leafDivs.find((leafDiv) => {
338
+ const displayed = leafDiv.isDisplayed();
339
+
340
+ if (displayed) {
341
+ return true;
342
+ }
343
+ });
344
+
345
+ return displayedLeafDiv;
346
+ }
347
+
348
+ retrieveLeafDivs() {
349
+ const viewChildDivDOMElementNodeList = document.querySelectorAll(VIEW_CHILD_DIVS_SELECTOR),
350
+ viewChildDivDOMElements = leafNodesFromNodeList(viewChildDivDOMElementNodeList), ///
351
+ leafDivs = elementsFromDOMElements(viewChildDivDOMElements, LeafDiv);
352
+
353
+ return leafDivs;
354
+ }
355
+
356
+ getZoom() {
357
+ const { zoom } = this.getState();
358
+
359
+ return zoom;
360
+ }
361
+
362
+ setZoom(zoom) {
363
+ this.updateState({
364
+ zoom
365
+ });
366
+ }
367
+
368
+ getLeafDivs() {
369
+ const { leafDivs } = this.getState();
370
+
371
+ return leafDivs;
372
+ }
373
+
374
+ setLeftDivs(leafDivs) {
375
+ this.updateState({
376
+ leafDivs
377
+ });
378
+ }
379
+
380
+ getInterval() {
381
+ const { interval } = this.getState();
382
+
383
+ return interval;
384
+ }
385
+
386
+ setInterval(interval) {
387
+ this.updateState({
388
+ interval
389
+ });
390
+ }
391
+
392
+ getStartZoom() {
393
+ const { startZoom } = this.getState();
394
+
395
+ return startZoom;
396
+ }
397
+
398
+ setStartZoom(startZoom) {
399
+ this.updateState({
400
+ startZoom
401
+ });
402
+ }
403
+
404
+ getStartScrollTop() {
405
+ const { startScrollTop } = this.getState();
406
+
407
+ return startScrollTop;
408
+ }
409
+
410
+ setStartScrollTop(startScrollTop) {
411
+ this.updateState({
412
+ startScrollTop
413
+ });
414
+ }
415
+
416
+ areNativeGesturesEnabled() {
417
+ const nativeGesturesEnabled = this.hasClass("native-gestures");
418
+
419
+ return nativeGesturesEnabled;
420
+ }
421
+
422
+ setInitialState() {
423
+ const zoom = 1,
424
+ leafDivs = this.retrieveLeafDivs(),
425
+ interval = null,
426
+ startZoom = null,
427
+ startScrollTop = null;
428
+
429
+ this.setState({
430
+ zoom,
431
+ leafDivs,
432
+ interval,
433
+ startZoom,
434
+ startScrollTop
435
+ });
436
+ }
437
+
438
+ didMount() {
439
+ this.enableTouch();
440
+
441
+ this.onCustomTap(this.tapCustomHandler);
442
+ this.onCustomDragUp(this.dragUpCustomHandler);
443
+ this.onCustomDragDown(this.dragDownCustomHandler);
444
+ this.onCustomDragStart(this.dragStartCustomHandler);
445
+ this.onCustomSwipeUp(this.swipeUpCustomHandler);
446
+ this.onCustomSwipeDown(this.swipeDownCustomHandler);
447
+ this.onCustomSwipeLeft(this.swipeLeftCustomHandler);
448
+ this.onCustomSwipeRight(this.swipeRightCustomHandler);
449
+ this.onCustomPinchMove(this.pinchMoveCustomHandler);
450
+ this.onCustomPinchStart(this.pinchStartCustomHandler);
451
+ this.onCustomDoubleTap(this.doubleTapCustomHandler);
452
+
453
+ window.onKeyDown(this.keyDownHandler);
454
+ }
455
+
456
+ willUnmount() {
457
+ this.offCustomTap(this.tapCustomHandler);
458
+ this.offCustomDragUp(this.dragUpCustomHandler);
459
+ this.offCustomDragDown(this.dragDownCustomHandler);
460
+ this.offCustomDragStart(this.dragStartCustomHandler);
461
+ this.offCustomSwipeUp(this.swipeUpCustomHandler);
462
+ this.offCustomSwipeDown(this.swipeDownCustomHandler);
463
+ this.offCustomSwipeLeft(this.swipeLeftCustomHandler);
464
+ this.offCustomSwipeRight(this.swipeRightCustomHandler);
465
+ this.offCustomPinchMove(this.pinchMoveCustomHandler);
466
+ this.offCustomPinchStart(this.pinchStartCustomHandler);
467
+ this.offCustomDoubleTap(this.doubleTapCustomHandler);
468
+
469
+ this.disableTouch();
470
+
471
+ window.offKeyDown(this.keyDownHandler);
472
+ }
473
+
474
+ childElements() {
475
+ return (
476
+
477
+ <MenuDiv/>
478
+
479
+ );
480
+ }
4
481
 
5
- export default class View extends Element {
6
482
  initialise() {
7
483
  this.assignContext();
484
+
485
+ this.setInitialState();
486
+
487
+ this.forEachLeafDiv((leafDiv, index) => {
488
+ (index === 0) ?
489
+ leafDiv.show() :
490
+ leafDiv.hide();
491
+ });
8
492
  }
9
493
 
10
494
  static tagName = "div";
@@ -13,3 +497,18 @@ export default class View extends Element {
13
497
  className: "view"
14
498
  };
15
499
  }
500
+
501
+ Object.assign(View.prototype, touchMixins);
502
+
503
+ export default withStyle(View)`
504
+
505
+ width: 100%;
506
+ height: 100%;
507
+ overflow: hidden;
508
+ touch-action: none;
509
+
510
+ .native-gestures {
511
+ touch-action: auto;
512
+ }
513
+
514
+ `;
@@ -30,10 +30,16 @@
30
30
  *,
31
31
  *::after,
32
32
  *::before {
33
- border: 0;
34
- margin: 0;
35
- padding: 0;
36
- box-sizing: border-box;
33
+ border: 0;
34
+ margin: 0;
35
+ padding: 0;
36
+ box-sizing: border-box;
37
+ }
38
+
39
+ html,
40
+ html > body {
41
+ width: 100%;
42
+ height: 100%;
37
43
  }
38
44
 
39
45
  </style>
@@ -47,9 +53,16 @@
47
53
  ${markdownStylesCSS}
48
54
 
49
55
  </style>
56
+ <style>
57
+
58
+ ${loadingCSS}
59
+
60
+ </style>
50
61
  </head>
51
62
  <body>
52
63
 
64
+ ${loadingHTML}
65
+
53
66
  ${markdownHTML}
54
67
 
55
68
  ${clientHTML}
@@ -0,0 +1,17 @@
1
+
2
+ <div class="loading">
3
+ <div class="spinner">
4
+ <div></div>
5
+ <div></div>
6
+ <div></div>
7
+ <div></div>
8
+ <div></div>
9
+ <div></div>
10
+ <div></div>
11
+ <div></div>
12
+ <div></div>
13
+ <div></div>
14
+ <div></div>
15
+ <div></div>
16
+ </div>
17
+ </div>