highmark-cli 0.0.133 → 0.0.135

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,270 @@
1
1
  "use strict";
2
2
 
3
- import { Element } from "easy";
3
+ import { keyCodes } from "necessary";
4
+ import { Element, window } from "easy";
5
+
6
+ import LeafDiv from "./view/div/leaf";
7
+
8
+ import { leafNodesFromNodeList } from "./utilities/tree";
9
+ import { elementsFromDOMElements } from "./utilities/element";
10
+ import { ENABLE_SWIPES_DELAY, MAXIMUM_CLICK_WIDTH_RATIO, VIEW_CHILD_DIVS_SELECTOR } from "./constants";
11
+
12
+ const { ENTER_KEY_CODE,
13
+ ESCAPE_KEY_CODE,
14
+ BACKSPACE_KEY_CODE,
15
+ ARROW_UP_KEY_CODE,
16
+ ARROW_DOWN_KEY_CODE,
17
+ ARROW_LEFT_KEY_CODE,
18
+ ARROW_RIGHT_KEY_CODE } = keyCodes;
4
19
 
5
20
  export default class View extends Element {
21
+ swipeRightCustomHandler = (event, element) => {
22
+ const swipesDisabled = this.areSwipesDisabled();
23
+
24
+ if (swipesDisabled) {
25
+ return;
26
+ }
27
+
28
+ this.disableSwipes();
29
+ this.showLeftLeafDiv();
30
+ this.waitToEnableSwipes();
31
+ }
32
+
33
+ swipeLeftCustomHandler = (event, element) => {
34
+ const swipesDisabled = this.areSwipesDisabled();
35
+
36
+ if (swipesDisabled) {
37
+ return;
38
+ }
39
+
40
+ this.disableSwipes();
41
+ this.showRightLeftDiv();
42
+ this.waitToEnableSwipes();
43
+ }
44
+
45
+ tapCustomHandler = (event, element) => {
46
+ ///
47
+ }
48
+
49
+ clickHandler = (event, element) => {
50
+ const { pageX } = event,
51
+ width = this.getWidth(),
52
+ clickWidthRatio = pageX / width;
53
+
54
+ if (clickWidthRatio < MAXIMUM_CLICK_WIDTH_RATIO) {
55
+ this.showLeftLeafDiv();
56
+ }
57
+
58
+ if ((1 - clickWidthRatio) < MAXIMUM_CLICK_WIDTH_RATIO) {
59
+ this.showRightLeftDiv();
60
+ }
61
+ }
62
+
63
+ keyDownHandler = (event, element) => {
64
+ const { keyCode } = event;
65
+
66
+ switch (keyCode) {
67
+ case ENTER_KEY_CODE:
68
+ case ARROW_RIGHT_KEY_CODE: {
69
+ this.showRightLeftDiv();
70
+
71
+ event.preventDefault();
72
+
73
+ break;
74
+ }
75
+
76
+ case BACKSPACE_KEY_CODE:
77
+ case ARROW_LEFT_KEY_CODE: {
78
+ this.showLeftLeafDiv();
79
+
80
+ event.preventDefault();
81
+
82
+ break;
83
+ }
84
+
85
+ case ESCAPE_KEY_CODE: {
86
+ ///
87
+
88
+ break;
89
+ }
90
+
91
+ case ARROW_UP_KEY_CODE: {
92
+ this.showFirstLeftDiv();
93
+
94
+ event.preventDefault();
95
+
96
+ break;
97
+ }
98
+
99
+ case ARROW_DOWN_KEY_CODE: {
100
+ this.showLastLeafDiv();
101
+
102
+ event.preventDefault();
103
+
104
+ break;
105
+ }
106
+ }
107
+ }
108
+
109
+ showFirstLeftDiv() {
110
+ const showingLeafDiv = this.findShowingLeafDiv(),
111
+ leafDivs = this.getLeafDivs(),
112
+ index = leafDivs.indexOf(showingLeafDiv),
113
+ nextIndex = 0,
114
+ previousIndex = index; ///
115
+
116
+ this.showNextLeafDiv(nextIndex, previousIndex);
117
+ }
118
+
119
+ showLeftLeafDiv() {
120
+ const showingLeafDiv = this.findShowingLeafDiv(),
121
+ leafDivs = this.getLeafDivs(),
122
+ index = leafDivs.indexOf(showingLeafDiv),
123
+ nextIndex = index - 1,
124
+ previousIndex = index; ///
125
+
126
+ this.showNextLeafDiv(nextIndex, previousIndex);
127
+ }
128
+
129
+ showRightLeftDiv() {
130
+ const showingLeafDiv = this.findShowingLeafDiv(),
131
+ leafDivs = this.getLeafDivs(),
132
+ index = leafDivs.indexOf(showingLeafDiv),
133
+ nextIndex = index + 1,
134
+ previousIndex = index; ///
135
+
136
+ this.showNextLeafDiv(nextIndex, previousIndex);
137
+ }
138
+
139
+ showLastLeafDiv() {
140
+ const showingLeafDiv = this.findShowingLeafDiv(),
141
+ leafDivs = this.getLeafDivs(),
142
+ index = leafDivs.indexOf(showingLeafDiv),
143
+ nextIndex = leafDivs.length - 1,
144
+ previousIndex = index; ///
145
+
146
+ this.showNextLeafDiv(nextIndex, previousIndex);
147
+ }
148
+
149
+ showNextLeafDiv(nextIndex, previousIndex) {
150
+ const leafDivs = this.getLeafDivs(),
151
+ leafDivsLength = leafDivs.length,
152
+ previousLeafDiv = leafDivs[previousIndex];
153
+
154
+ if ((nextIndex === -1) || (nextIndex === previousIndex) || (nextIndex === leafDivsLength)) {
155
+ previousLeafDiv.wiggle();
156
+
157
+ return;
158
+ }
159
+
160
+ const nextLeafDiv = leafDivs[nextIndex];
161
+
162
+ nextLeafDiv.show();
163
+
164
+ previousLeafDiv.hide();
165
+ }
166
+
167
+ forEachLeafDiv(callback) {
168
+ const leafDivs = this.getLeafDivs();
169
+
170
+ leafDivs.forEach(callback);
171
+ }
172
+
173
+ findShowingLeafDiv() {
174
+ const leafDivs = this.getLeafDivs(),
175
+ showingLeafDiv = leafDivs.find((leafDiv) => {
176
+ const showing = leafDiv.isShowing();
177
+
178
+ if (showing) {
179
+ return true;
180
+ }
181
+ });
182
+
183
+ return showingLeafDiv;
184
+ }
185
+
186
+ disableSwipes() {
187
+ const swipesDisabled = true;
188
+
189
+ this.setSwipesDisabled(swipesDisabled);
190
+ }
191
+
192
+ enableSwipes() {
193
+ const swipesDisabled = false;
194
+
195
+ this.setSwipesDisabled(swipesDisabled);
196
+ }
197
+
198
+ waitToEnableSwipes() {
199
+ const delay = ENABLE_SWIPES_DELAY;
200
+
201
+ setTimeout(() => {
202
+ this.enableSwipes();
203
+ }, delay);
204
+ }
205
+
206
+ getLeafDivs() {
207
+ const { leafDivs } = this.getState();
208
+
209
+ return leafDivs;
210
+ }
211
+
212
+ setLeftDivs(leafDivs) {
213
+ this.updateState({
214
+ leafDivs
215
+ });
216
+ }
217
+
218
+ areSwipesDisabled() {
219
+ const { swipesDisabled } = this.getState();
220
+
221
+ return swipesDisabled;
222
+ }
223
+
224
+ setSwipesDisabled(swipesDisabled) {
225
+ this.updateState({
226
+ swipesDisabled
227
+ });
228
+ }
229
+
230
+ setInitialState() {
231
+ const viewChildDivDOMElementNodeList = document.querySelectorAll(VIEW_CHILD_DIVS_SELECTOR),
232
+ viewChildDivDOMElements = leafNodesFromNodeList(viewChildDivDOMElementNodeList), ///
233
+ leafDivs = elementsFromDOMElements(viewChildDivDOMElements, () =>
234
+
235
+ <LeafDiv onCustomTap={this.tapCustomHandler}
236
+ onCustomSwipeLeft={this.swipeLeftCustomHandler}
237
+ onCustomSwipeRight={this.swipeRightCustomHandler} />
238
+
239
+ ),
240
+ swipesDisabled = false;
241
+
242
+ this.setState({
243
+ leafDivs,
244
+ swipesDisabled
245
+ });
246
+ }
247
+
248
+ didMount() {
249
+ this.onClick(this.clickHandler);
250
+
251
+ window.onKeyDown(this.keyDownHandler);
252
+ }
253
+
254
+ willUnmount() {
255
+ this.offClick(this.clickHandler);
256
+
257
+ window.offKeyDown(this.keyDownHandler);
258
+ }
259
+
6
260
  initialise() {
7
- this.assignContext();
261
+ this.setInitialState();
262
+
263
+ this.forEachLeafDiv((leafDiv, index) => {
264
+ (index === 0) ?
265
+ leafDiv.show() :
266
+ leafDiv.hide();
267
+ });
8
268
  }
9
269
 
10
270
  static tagName = "div";
@@ -47,9 +47,16 @@
47
47
  ${markdownStylesCSS}
48
48
 
49
49
  </style>
50
+ <style>
51
+
52
+ ${loadingCSS}
53
+
54
+ </style>
50
55
  </head>
51
56
  <body>
52
57
 
58
+ ${loadingHTML}
59
+
53
60
  ${markdownHTML}
54
61
 
55
62
  ${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>