react-ui-basics 0.0.175 → 0.0.176

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 (137) hide show
  1. package/Animated.js.map +1 -1
  2. package/AutocompleteSelect.js.map +1 -1
  3. package/Button.js.map +1 -1
  4. package/Checkbox.js.map +1 -1
  5. package/CircleProgress.js.map +1 -1
  6. package/CommonFields.js.map +1 -1
  7. package/DNDContainer.js.map +1 -1
  8. package/DNDDraggable.js.map +1 -1
  9. package/DNDDroppable.js.map +1 -1
  10. package/Dialog.js.map +1 -1
  11. package/DropFileInput.js.map +1 -1
  12. package/DroppableHorizontalList.js.map +1 -1
  13. package/DroppableList.js.map +1 -1
  14. package/Dropzone.js.map +1 -1
  15. package/FilteredList.js.map +1 -1
  16. package/FloatingActionButton.js.map +1 -1
  17. package/FormUploadProgress.js.map +1 -1
  18. package/ImageGallery.js.map +1 -1
  19. package/MaterialIcon.js.map +1 -1
  20. package/Modal.js.map +1 -1
  21. package/ModalMenu.js.map +1 -1
  22. package/ReactConstants.js.map +1 -1
  23. package/ReactCreateElement.js.map +1 -1
  24. package/ReadyListener.js.map +1 -1
  25. package/Scrollable.js.map +1 -1
  26. package/ScrollableTable.js.map +1 -1
  27. package/Size.js.map +1 -1
  28. package/Snackbar.js.map +1 -1
  29. package/SpinningProgress.js.map +1 -1
  30. package/Switch.js.map +1 -1
  31. package/Table.js.map +1 -1
  32. package/TextField.js.map +1 -1
  33. package/Tools.d.ts +2 -2
  34. package/Tools.js.map +1 -1
  35. package/bundle.css +596 -596
  36. package/package.json +1 -1
  37. package/router/HistoryTools.js.map +1 -1
  38. package/router/Link.js.map +1 -1
  39. package/router/NavLink.js.map +1 -1
  40. package/router/Route.js.map +1 -1
  41. package/router/index.js.map +1 -1
  42. package/src/Animated.css +7 -0
  43. package/src/Animated.js +219 -0
  44. package/src/Animated.scss +8 -0
  45. package/src/AutocompleteSelect.css +256 -0
  46. package/src/AutocompleteSelect.js +473 -0
  47. package/src/AutocompleteSelect.scss +322 -0
  48. package/src/Button.css +138 -0
  49. package/src/Button.js +104 -0
  50. package/src/Button.scss +177 -0
  51. package/src/Checkbox.css +56 -0
  52. package/src/Checkbox.js +52 -0
  53. package/src/Checkbox.scss +87 -0
  54. package/src/CircleProgress.css +11 -0
  55. package/src/CircleProgress.js +38 -0
  56. package/src/CircleProgress.scss +13 -0
  57. package/src/CommonFields.js +21 -0
  58. package/src/DNDContainer.css +26 -0
  59. package/src/DNDContainer.js +263 -0
  60. package/src/DNDContainer.scss +33 -0
  61. package/src/DNDDraggable.js +55 -0
  62. package/src/DNDDroppable.js +58 -0
  63. package/src/Dialog.css +36 -0
  64. package/src/Dialog.js +160 -0
  65. package/src/Dialog.scss +42 -0
  66. package/src/DropFileInput.css +24 -0
  67. package/src/DropFileInput.js +45 -0
  68. package/src/DropFileInput.scss +28 -0
  69. package/src/DroppableHorizontalList.js +190 -0
  70. package/src/DroppableList.css +14 -0
  71. package/src/DroppableList.js +201 -0
  72. package/src/DroppableList.scss +27 -0
  73. package/src/Dropzone.css +54 -0
  74. package/src/Dropzone.js +140 -0
  75. package/src/Dropzone.scss +66 -0
  76. package/src/FilteredList.css +68 -0
  77. package/src/FilteredList.js +196 -0
  78. package/src/FilteredList.scss +86 -0
  79. package/src/FloatingActionButton.css +20 -0
  80. package/src/FloatingActionButton.js +35 -0
  81. package/src/FloatingActionButton.scss +25 -0
  82. package/src/FormUploadProgress.css +61 -0
  83. package/src/FormUploadProgress.js +87 -0
  84. package/src/FormUploadProgress.scss +78 -0
  85. package/src/ImageGallery.css +196 -0
  86. package/src/ImageGallery.js +935 -0
  87. package/src/ImageGallery.scss +256 -0
  88. package/src/MaterialIcon.js +1837 -0
  89. package/src/Modal.css +61 -0
  90. package/src/Modal.js +160 -0
  91. package/src/Modal.scss +73 -0
  92. package/src/ModalMenu.css +30 -0
  93. package/src/ModalMenu.js +59 -0
  94. package/src/ModalMenu.scss +36 -0
  95. package/src/ReactConstants.ts +42 -0
  96. package/src/ReactCreateElement.js +5 -0
  97. package/src/ReadyListener.js +53 -0
  98. package/src/ResizeObserver.ts +50 -0
  99. package/src/Scrollable.css +80 -0
  100. package/src/Scrollable.js +388 -0
  101. package/src/Scrollable.scss +100 -0
  102. package/src/ScrollableTable.css +6 -0
  103. package/src/ScrollableTable.scss +12 -0
  104. package/src/ScrollableTable.tsx +39 -0
  105. package/src/Size.js +56 -0
  106. package/src/Snackbar.css +40 -0
  107. package/src/Snackbar.js +71 -0
  108. package/src/Snackbar.scss +47 -0
  109. package/src/SpinningProgress.css +49 -0
  110. package/src/SpinningProgress.js +19 -0
  111. package/src/SpinningProgress.scss +57 -0
  112. package/src/Switch.css +69 -0
  113. package/src/Switch.js +54 -0
  114. package/src/Switch.scss +73 -0
  115. package/src/Table.css +94 -0
  116. package/src/Table.scss +121 -0
  117. package/src/Table.tsx +360 -0
  118. package/src/TextField.css +122 -0
  119. package/src/TextField.js +162 -0
  120. package/src/TextField.scss +160 -0
  121. package/src/Tools.test.js +105 -0
  122. package/src/Tools.ts +231 -0
  123. package/src/global.css +1 -0
  124. package/src/global.scss +6 -0
  125. package/src/index.js +78 -0
  126. package/src/router/HistoryTools.js +32 -0
  127. package/src/router/Link.js +27 -0
  128. package/src/router/NavLink.js +25 -0
  129. package/src/router/README.md +55 -0
  130. package/src/router/Route.js +209 -0
  131. package/src/router/Route.test.js +139 -0
  132. package/src/router/index.js +14 -0
  133. package/src/store/ProxyTools.js +91 -0
  134. package/src/store/ProxyTools.test.js +97 -0
  135. package/src/store/Store.ts +91 -0
  136. package/store/ProxyTools.js.map +1 -1
  137. package/store/Store.js.map +1 -1
@@ -0,0 +1,935 @@
1
+ import ReactConstants from "./../ReactConstants";
2
+ import {clientHeight as __clientHeight, clientWidth as __clientWidth, createAccessor as __createAccessor, data as __data, height as __height, left as __left, length as __length, pageX as __pageX, pageY as __pageY, props as __props, scrollLeft as __scrollLeft, scrollTop as __scrollTop, state as __state, style as __style, target as __target, top as __top, value as __value, width as __width} from "./../CommonFields";
3
+ import React from 'react';
4
+ import {toConsumableArray as __toConsumableArray} from "./../_virtual/_rollupPluginBabelHelpers";
5
+ import {extends as __extends} from "./../_virtual/_rollupPluginBabelHelpers";
6
+ import {inherits as __inherits} from "./../_virtual/_rollupPluginBabelHelpers";
7
+ import './ImageGallery.css';
8
+ import ReactCreateElement from './ReactCreateElement';
9
+ import './ImageGallery.css'
10
+ import Animated from "./Animated";
11
+ import Button from "./Button";
12
+ import SpinningProgress from "./SpinningProgress";
13
+ import {
14
+ UNDEFINED,
15
+ preventDefault,
16
+ stopPropagation,
17
+ classNames,
18
+ DOCUMENT,
19
+ WINDOW,
20
+ addEventListener,
21
+ removeEventListener,
22
+ setTimeout,
23
+ orNoop,
24
+ createRef,
25
+ debounce,
26
+ isDifferent
27
+ } from "./Tools";
28
+ import MaterialIcon from "./MaterialIcon";
29
+ import {componentDidUpdate, componentWillUnmount, componentDidMount, render, propsGetter, stateGSs} from "./ReactConstants";
30
+
31
+ const min = Math.min;
32
+ const abs = Math.abs;
33
+
34
+ const toPx = (value) => value + 'px';
35
+
36
+ const previewRatio = 4 / 3;
37
+ const previewHeight = 80;
38
+ const previewWidth = previewRatio * previewHeight;
39
+ const previewPadding = 8;
40
+ const previewsHeight = previewHeight + 15;
41
+
42
+ const calculatePosition = (it, ratio, width, height, previewsHeight, embedded, container) => {
43
+ const windowWidth = embedded ? __clientWidth(container) : min(DOCUMENT.body.clientWidth, WINDOW.innerWidth);
44
+ const windowHeight = embedded ? __clientHeight(container) : min(DOCUMENT.body.clientHeight, WINDOW.innerHeight);
45
+
46
+ let offset = it.offset;
47
+ if (offset == null)
48
+ offset = (embedded ? 0 : windowHeight * 0.03);
49
+
50
+ let offsetTop = it.offsetTop
51
+ offsetTop = offsetTop == null ? offset : offsetTop
52
+ let offsetBottom = it.offsetBottom
53
+ offsetBottom = offsetBottom == null ? offset : offsetBottom
54
+ let offsetLeft = it.offsetLeft
55
+ offsetLeft = offsetLeft == null ? offset : offsetLeft
56
+ let offsetRight = it.offsetRight
57
+ offsetRight = offsetRight == null ? offset : offsetRight
58
+
59
+ if (Number.isNaN(ratio))
60
+ ratio = 0;
61
+ if (embedded) {
62
+ if (ratio > 1) {
63
+ it.toHeight = windowHeight - previewsHeight - -offsetTop - offsetBottom;
64
+ it.toWidth = it.toHeight * ratio;
65
+ } else {
66
+ it.toWidth = windowWidth - offsetLeft - offsetRight;
67
+ it.toHeight = it.toWidth / ratio;
68
+ }
69
+ } else if (ratio > 1) {
70
+ it.toWidth = windowWidth - offsetLeft - offsetRight;
71
+ it.toHeight = it.toWidth / ratio;
72
+ if (it.toHeight > windowHeight - previewsHeight - offsetTop - offsetBottom) {
73
+ it.toHeight = windowHeight - previewsHeight - offsetTop - offsetBottom;
74
+ it.toWidth = it.toHeight * ratio;
75
+ }
76
+ } else {
77
+ it.toHeight = windowHeight - previewsHeight - offsetTop - offsetBottom;
78
+ it.toWidth = it.toHeight * ratio;
79
+ if (it.toWidth > windowWidth - offsetLeft - offsetRight) {
80
+ it.toWidth = windowWidth - offsetLeft - offsetRight;
81
+ it.toHeight = it.toWidth / ratio;
82
+ }
83
+ }
84
+
85
+ // if (width && it.toWidth > width) {
86
+ // it.toWidth = width;
87
+ // it.toHeight = height;
88
+ // }
89
+
90
+ it.toTop = offsetTop + (windowHeight - previewsHeight - offsetTop - offsetBottom - it.toHeight) / 2;
91
+ it.toLeft = (windowWidth - it.toWidth) / 2;
92
+
93
+ it.toWidthPx = toPx(it.toWidth);
94
+ // it.toHeightPx = toPx(it.toHeight);
95
+ it.toTopPx = toPx(it.toTop);
96
+ it.toLeftPx = toPx(it.toLeft);
97
+ };
98
+
99
+ const calculatePreviewsScroll = (index, length, width) => {
100
+ if (length <= 5)
101
+ return 0;
102
+
103
+ if (index < 3)
104
+ return 0;
105
+
106
+ if (index > length - 3)
107
+ return -(length - 5) * (previewWidth + previewPadding);
108
+
109
+ return -(index * (previewWidth + previewPadding) + (previewWidth) / 2 - width / 2);
110
+ };
111
+
112
+ function calculatePreview(width, height, url) {
113
+ let top = 0;
114
+ let left = 0;
115
+
116
+ let ratio = width / height;
117
+
118
+ if (width !== previewWidth || height !== previewHeight) {
119
+ if (ratio < previewRatio) {
120
+ width = previewWidth;
121
+ height = width / ratio;
122
+ top = -(height - previewHeight) / 2;
123
+ } else {
124
+ height = previewHeight;
125
+ width = height * ratio;
126
+ left = -(width - previewWidth) / 2;
127
+ }
128
+ }
129
+
130
+ return {
131
+ url,
132
+ position: 'absolute',
133
+ width: toPx(width),
134
+ height: toPx(height),
135
+ top: toPx(top),
136
+ left: toPx(left),
137
+ };
138
+ }
139
+
140
+ const loadImage = (src, cb) => {
141
+ const image = new Image();
142
+ image.onload = () => {
143
+ cb(image)
144
+ };
145
+ image.src = src;
146
+ }
147
+
148
+ const ACTION_PREFIX = 'IMAGE_GALLERY_';
149
+ const ACTION_IMAGE_GALLERY_SHOW = ACTION_PREFIX + 'SHOW';
150
+ const ACTION_IMAGE_GALLERY_CLOSE = ACTION_PREFIX + 'CLOSE';
151
+ const ACTION_IMAGE_GALLERY_RECALCULATE = ACTION_PREFIX + 'RECALCULATE';
152
+ const ACTION_IMAGE_GALLERY_FULL_IMAGE_LOADED = ACTION_PREFIX + 'FULL_IMAGE_LOADED';
153
+ const ACTION_IMAGE_GALLERY_PREVIEW_LOADED = ACTION_PREFIX + 'PREVIEW_LOADED';
154
+
155
+ export class Actions {
156
+ static replaceImages = images => (dispatch, getState) => {
157
+ const state = getState();
158
+ const length = __length(images);
159
+ const nextState = {...state}
160
+ nextState.images = images.map(item => {
161
+ const image = state.images.find(it => it.url === item.url)
162
+ if (image)
163
+ return image
164
+
165
+ const it = {...item}
166
+ const el = it.el;
167
+ if (el) {
168
+ const rect = el.getBoundingClientRect();
169
+ const fromWidth = __clientWidth(el);
170
+ const fromHeight = __clientHeight(el);
171
+
172
+ it.fromLeftPx = toPx(__left(rect));
173
+ it.fromTopPx = toPx(__top(rect));
174
+ it.fromWidthPx = toPx(fromWidth);
175
+
176
+ let ratio = fromWidth / fromHeight;
177
+ calculatePosition(it, ratio, el.naturalWidth || __width(el), el.naturalHeight || __height(el), withPreviews ? previewsHeight : 0, embedded, container);
178
+ } else {
179
+ it.toLeft = 100;
180
+ it.toTop = 100;
181
+ }
182
+ if (!it.toWidth || !it.toHeight || !el)
183
+ Actions.loadPreview(it)(dispatch);
184
+ return it;
185
+ })
186
+ nextState.previews.width = min(length, 5) * previewWidth + min(length - 1, 4) * previewPadding;
187
+ nextState.previews.totalWidth = toPx(length * previewWidth + (length - 1) * previewPadding);
188
+ nextState.previews.images = nextState.images.map(item => {
189
+ const preview = state.previews.images.find(it => it.url === item.previewUrl)
190
+ if (preview)
191
+ return preview
192
+
193
+ const el = item.el;
194
+ if (!el)
195
+ return {};
196
+
197
+ let width = __clientWidth(el);
198
+ let height = __clientHeight(el);
199
+ return calculatePreview(width, height, el.src);
200
+ });
201
+
202
+ dispatch({type: ACTION_IMAGE_GALLERY_SHOW, data: nextState});
203
+ };
204
+
205
+ static show = (gallery) => (dispatch) => {
206
+ const images = gallery.images;
207
+ const length = __length(images);
208
+ const withPreviews = length > 1 && (gallery.withPreviews === UNDEFINED || !!gallery.withPreviews);
209
+ const container = gallery.container;
210
+ const embedded = gallery.embedded;
211
+ const index = gallery.index;
212
+ const data = {
213
+ index,
214
+ container,
215
+ embedded,
216
+ withPreviews,
217
+ images: images.map(item => {
218
+ const it = {...item}
219
+ const el = it.el;
220
+ if (el) {
221
+ const rect = el.getBoundingClientRect();
222
+ const fromWidth = __clientWidth(el);
223
+ const fromHeight = __clientHeight(el);
224
+
225
+ it.fromLeftPx = toPx(__left(rect));
226
+ it.fromTopPx = toPx(__top(rect));
227
+ it.fromWidthPx = toPx(fromWidth);
228
+
229
+ let ratio = fromWidth / fromHeight;
230
+ calculatePosition(it, ratio, el.naturalWidth || __width(el), el.naturalHeight || __height(el), withPreviews ? previewsHeight : 0, embedded, container);
231
+ } else {
232
+ it.toLeft = 100;
233
+ it.toTop = 100;
234
+ }
235
+ if (!it.toWidth || !it.toHeight || !el)
236
+ Actions.loadPreview(it)(dispatch);
237
+ return it;
238
+ }),
239
+ previews: {
240
+ show: withPreviews,
241
+ width: min(length, 5) * previewWidth + min(length - 1, 4) * previewPadding,
242
+ totalWidth: toPx(length * previewWidth + (length - 1) * previewPadding),
243
+ scroll: UNDEFINED,
244
+ images: images.map(it => {
245
+ const el = it.el;
246
+ if (!el)
247
+ return {};
248
+
249
+ let width = __clientWidth(el);
250
+ let height = __clientHeight(el);
251
+ return calculatePreview(width, height, el.src);
252
+ })
253
+ },
254
+ };
255
+
256
+ data.images.forEach(it => {
257
+ if (!it.fromLeftPx) {
258
+ const imageWithFromData = data.images.find(it => !!it.fromLeftPx);
259
+ if (imageWithFromData) {
260
+ it.fromLeftPx = imageWithFromData.fromLeftPx;
261
+ it.fromTopPx = imageWithFromData.fromTopPx;
262
+ it.fromWidthPx = imageWithFromData.fromWidthPx;
263
+ }
264
+ }
265
+ });
266
+ data.previews.scroll = calculatePreviewsScroll(index, length, data.previews.width);
267
+
268
+ dispatch({type: ACTION_IMAGE_GALLERY_SHOW, data});
269
+ Actions.load(data.images[index])(dispatch)
270
+ };
271
+ static close = () => (dispatch) => {
272
+ dispatch({type: ACTION_IMAGE_GALLERY_CLOSE});
273
+ };
274
+ static recalculate = () => (dispatch) => {
275
+ dispatch({type: ACTION_IMAGE_GALLERY_RECALCULATE});
276
+ };
277
+ static loaded = (item, image) => (dispatch) => {
278
+ dispatch({type: ACTION_IMAGE_GALLERY_FULL_IMAGE_LOADED, item, image});
279
+ };
280
+ static loadedPreview = (item, image) => (dispatch) => {
281
+ dispatch({type: ACTION_IMAGE_GALLERY_PREVIEW_LOADED, item, image});
282
+ };
283
+ static load = (item) => (dispatch) => {
284
+ loadImage(item.url, (image) => {
285
+ Actions.loaded(item, image)(dispatch);
286
+ })
287
+ };
288
+
289
+ static loadPreview = (item) => (dispatch) => {
290
+ loadImage(item.previewUrl, (image) => {
291
+ Actions.loadedPreview(item, image)(dispatch);
292
+ })
293
+ };
294
+ }
295
+
296
+ const reducers = {
297
+ [ACTION_IMAGE_GALLERY_SHOW]: (state, action) => ({...__data(action), open: true}),
298
+ [ACTION_IMAGE_GALLERY_CLOSE]: (state, action) => ({...state, open: false}),
299
+ [ACTION_IMAGE_GALLERY_RECALCULATE]: (state, action) => {
300
+ const images = [...state.images];
301
+ const result = {...state, images};
302
+ for (let i = 0; i < __length(images); i++) {
303
+ if (!__width(images[i]) && !images[i].fromWidthPx)
304
+ continue
305
+
306
+ const it = {...images[i]};
307
+ const width = __width(it) || Number.parseInt(it.fromWidthPx);
308
+ const height = __height(it) || Number.parseInt(it.fromHeightPx);
309
+ calculatePosition(it, width / height, width, height, result.previews.show ? previewsHeight : 0, state.embedded, state.container);
310
+ images[i] = it;
311
+ }
312
+
313
+ return result;
314
+ },
315
+ [ACTION_IMAGE_GALLERY_FULL_IMAGE_LOADED]: (state, action) => {
316
+ const item = action.item;
317
+ const image = action.image;
318
+ const images = [...state.images];
319
+ const result = {...state, images};
320
+ const index = images.findIndex(it => it.id === item.id);
321
+
322
+ const width = __width(image)
323
+ const height = __height(image)
324
+ const it = {...images[index], loaded: true, width, height};
325
+ // debugger
326
+ // if (it.toWidth > __width(image))
327
+ calculatePosition(it, width / height, width, height, result.previews.show ? previewsHeight : 0, state.embedded, state.container);
328
+ images[index] = it;
329
+ return result;
330
+ },
331
+ [ACTION_IMAGE_GALLERY_PREVIEW_LOADED]: (state, action) => {
332
+ const item = action.item;
333
+ const image = action.image;
334
+ const images = [...state.images];
335
+ const result = {...state, images};
336
+ const index = images.findIndex(it => it.id === item.id);
337
+ const it = {...images[index]};
338
+
339
+ if (!it.toWidth || !it.toHeight)
340
+ calculatePosition(it, __width(image) / __height(image), __width(image), __height(image), result.previews.show ? previewsHeight : 0, state.embedded, state.container);
341
+ images[index] = it;
342
+
343
+ const previewImages = [...state.previews.images];
344
+ result.previews.images = previewImages;
345
+ const preview = calculatePreview(__width(image), __height(image), image.src);
346
+ previewImages[index] = preview;
347
+
348
+ return result;
349
+ },
350
+ };
351
+
352
+ const small = (it, index, i, length) => {
353
+ if (index !== i)
354
+ return big(it, index, i, 0, length);
355
+
356
+ return {
357
+ position: 'absolute',
358
+ top: it.fromTopPx,
359
+ left: it.fromLeftPx,
360
+ width: it.fromWidthPx,
361
+ // height: it.fromHeightPx,
362
+ opacity: 0,
363
+ };
364
+ };
365
+
366
+ const big = (it, index, i, shift, length, previous) => {
367
+ const styles = {
368
+ position: 'absolute',
369
+ top: it.toTopPx,
370
+ left: toPx(it.toLeft + shift),
371
+ width: it.toWidthPx,
372
+ // height: it.toHeightPx,
373
+ };
374
+
375
+
376
+ // if (previous !== UNDEFINED && abs(index - previous) > 1) {
377
+ // styles.transitionDelay = 100 * abs(previous - i) + 'ms';
378
+ // }
379
+
380
+ if (index !== i) {
381
+ const width = WINDOW.innerWidth;
382
+ const additionalOffset = it.toLeft < 0 ? -it.toLeft : 0;
383
+
384
+ if (i < index)
385
+ styles.left = toPx(it.toLeft - width - additionalOffset + (i + 1 === index ? shift : 0));
386
+ else
387
+ styles.left = toPx(it.toLeft + width + additionalOffset + (i - 1 === index ? shift : 0));
388
+ }
389
+ return styles;
390
+ };
391
+
392
+ class ImageGallery extends React.Component {
393
+ constructor(properties) {
394
+ super(properties);
395
+ const that = this;
396
+ that.state = {};
397
+
398
+ const [
399
+ shift,
400
+ index,
401
+ previous,
402
+ zoomed,
403
+ previewScroll,
404
+ ] = stateGSs(that, 5);
405
+
406
+
407
+ const props = propsGetter(that);
408
+
409
+ that[ReactConstants[2]] = (prevProps, prevState, snapshot) => {
410
+ if (props().open !== prevProps.open && !props().open) {
411
+ setTimeout(() => {
412
+ shift(0)
413
+ index(UNDEFINED)
414
+ previous(UNDEFINED)
415
+ }, 250 + 100); // 250ms transition + 100ms to be sure it ended
416
+ }
417
+
418
+ const images = props().images;
419
+ if (!images)
420
+ return
421
+
422
+ const indexValue = index() !== UNDEFINED ? index() : props().index;
423
+ const image = images[indexValue];
424
+ if (!image) {
425
+ const i = __length(images) - 1
426
+ if (i === -1) {
427
+ if (prevProps.images !== images) {
428
+ onClose()
429
+ }
430
+ } else {
431
+ scrollTo(i, UNDEFINED)
432
+ }
433
+ } else if (!image.loaded) {
434
+ props().load(image)
435
+ }
436
+ }
437
+
438
+ const resizeListener = debounce(() => {
439
+ props().open && props().recalculate()
440
+ }, 100)
441
+ that[ReactConstants[0]] = () => {
442
+ addEventListener(WINDOW, 'resize', resizeListener)
443
+ }
444
+ that[ReactConstants[1]] = () => {
445
+ removeEventListener(WINDOW, 'resize', resizeListener)
446
+ }
447
+ const onClose = () => {
448
+ resetZoom()
449
+ moveListenerAdded = false;
450
+ __props(this).close();
451
+ }
452
+
453
+ const onKeyDown = e => {
454
+ const keyCode = e.keyCode;
455
+ if (keyCode === 37/*left*/) {
456
+ left();
457
+ preventDefault(e);
458
+ }
459
+ if (keyCode === 39/*right*/) {
460
+ right();
461
+ preventDefault(e);
462
+ }
463
+ if (keyCode === 27/*escape*/ && !props().embedded) {
464
+ onClose();
465
+ preventDefault(e);
466
+ }
467
+ };
468
+
469
+ let touchesStart;
470
+ let zoomValue = 1;
471
+ let zoomValueStarted;
472
+ let zoomedImage;
473
+ let oldLeft;
474
+ let oldTop;
475
+
476
+ let defaultWidth;
477
+ let defaultLeft;
478
+ let defaultTop;
479
+ let touchpadStarted = null;
480
+
481
+ const onKeyUp = e => {
482
+ const keyCode = e.keyCode;
483
+ if (touchpadStarted && keyCode === 17/*ctrl*/ && zoomed() && zoomValue < 1) {
484
+ resetZoom()
485
+ }
486
+ };
487
+
488
+ const resetZoom = () => {
489
+ if (!zoomed()) return
490
+ zoomed(false)
491
+ __style(zoomedImage).width = defaultWidth;
492
+ __style(zoomedImage).left = defaultLeft;
493
+ __style(zoomedImage).top = defaultTop;
494
+ __style(zoomedImage).transition = null
495
+ touchpadStarted = null
496
+ }
497
+ const initZoom = () => {
498
+ zoomed(true)
499
+ defaultWidth = __style(zoomedImage).width;
500
+ defaultLeft = __style(zoomedImage).left;
501
+ defaultTop = __style(zoomedImage).top;
502
+ }
503
+
504
+ const initTouchpadDragging = () => {
505
+ oldLeft = Number.parseFloat(__style(zoomedImage).left);
506
+ oldTop = Number.parseFloat(__style(zoomedImage).top);
507
+ __style(zoomedImage).transition = 'none'
508
+ touchpadStarted = true;
509
+ }
510
+
511
+ const onWheel = (e) => {
512
+ if (!zoomed()) return;
513
+
514
+ preventDefault(e)
515
+ if (!touchpadStarted) {
516
+ initTouchpadDragging()
517
+ }
518
+
519
+ if (e.ctrlKey) {
520
+ let diff = e.deltaY * 0.005;
521
+
522
+ let newZoom = Math.min(Math.max(zoomValue + diff, 0.5), 10)
523
+ let zoomX = __pageX(e);
524
+ oldLeft = zoomX - (zoomX - oldLeft) * newZoom / zoomValue;
525
+
526
+ let zoomY = __pageY(e);
527
+ oldTop = zoomY - (zoomY - oldTop) * newZoom / zoomValue;
528
+ zoomValue = newZoom
529
+
530
+ __style(zoomedImage).width = (zoomValue * 100) + '%';
531
+ } else {
532
+ oldLeft += e.deltaX * 0.5;
533
+ oldTop += e.deltaY * 0.5;
534
+ }
535
+ __style(zoomedImage).left = oldLeft + 'px'
536
+ __style(zoomedImage).top = oldTop + 'px'
537
+ }
538
+
539
+ let moveListenerAdded
540
+
541
+ const onTouchStart = e => {
542
+ e.swipeProcessed = false;
543
+ if (e.button === 2) return;
544
+ const touches = e.touches || [{pageX: __pageX(e), pageY: __pageY(e)}];
545
+ // console.log('onTouchStart', e.touches, __target(e));
546
+
547
+ zoomedImage = __target(e);
548
+ zoomedImage = zoomedImage.tagName.toLowerCase() === 'img' ? zoomedImage.parentElement : zoomedImage;
549
+ oldLeft = Number.parseFloat(__style(zoomedImage).left);
550
+ oldTop = Number.parseFloat(__style(zoomedImage).top);
551
+ if (zoomed()) {
552
+ __style(zoomedImage).transition = 'none'
553
+ }
554
+ if (!moveListenerAdded) {
555
+ //need to add it like this to be able to call preventDefault
556
+ addEventListener(this.gallery, 'touchmove', onTouchMove, false)
557
+ moveListenerAdded = true;
558
+ }
559
+
560
+ if (__length(touches) === 2) {
561
+ if (zoomed())
562
+ zoomValueStarted = zoomValue;
563
+ else if (!props().embedded) {
564
+ initZoom()
565
+ __style(zoomedImage).transition = 'none'
566
+ zoomValueStarted = zoomValue = Number.parseFloat(__style(zoomedImage).width) / WINDOW.innerWidth;
567
+ }
568
+ }
569
+ touchesStart = (touches)
570
+ };
571
+
572
+ const power2 = x => x * x;
573
+
574
+ const distance = touches => {
575
+ const a = touches[0]
576
+ const b = touches[1]
577
+ return Math.sqrt(power2(__pageX(a) - __pageX(b)) + power2(__pageY(a) - __pageY(b)))
578
+ }
579
+ const center = touches => {
580
+ const a = touches[0]
581
+ const b = touches[1]
582
+ return {x: (__pageX(a) + __pageX(b)) / 2, y: (__pageY(a) + __pageY(b)) / 2}
583
+ }
584
+
585
+ const onTouchMove = e => {
586
+ if (!touchesStart)
587
+ return;
588
+
589
+ const touches = e.touches || [{pageX: __pageX(e), pageY: __pageY(e)}];
590
+ // console.log('onTouchMove', touches, e)
591
+
592
+ if (zoomed()) {
593
+ preventDefault(e)
594
+ if (__length(touches) === 2) {
595
+ const diff = distance(touches) / distance(touchesStart);
596
+
597
+ zoomValue = Math.min(Math.max(zoomValueStarted * diff, 0.5), 10)
598
+
599
+ let zoomedAt = center(touchesStart)
600
+ let zoomX = zoomedAt.x;
601
+ let newLeft = zoomX - (zoomX - oldLeft) * zoomValue / zoomValueStarted;
602
+
603
+ let zoomY = zoomedAt.y;
604
+ let newTop = zoomY - (zoomY - oldTop) * zoomValue / zoomValueStarted;
605
+
606
+ __style(zoomedImage).left = newLeft + 'px'
607
+ __style(zoomedImage).top = newTop + 'px'
608
+ __style(zoomedImage).width = (zoomValue * 100) + '%';
609
+
610
+ return;
611
+ } else {
612
+ let touch = touches[0];
613
+ let touchStart = touchesStart[0];
614
+ let newLeft = oldLeft + __pageX(touch) - __pageX(touchStart)
615
+ let newTop = oldTop + __pageY(touch) - __pageY(touchStart)
616
+ __style(zoomedImage).left = newLeft + 'px'
617
+ __style(zoomedImage).top = newTop + 'px'
618
+ return;
619
+ }
620
+ }
621
+
622
+ if (__length(touches) > 1 || zoomed())
623
+ return;
624
+
625
+ let touch = touches[0];
626
+ let touchStart = touchesStart[0];
627
+ shift(__pageX(touch) - __pageX(touchStart))
628
+ };
629
+
630
+ const onTouchEnd = e => {
631
+ if (!touchesStart)
632
+ return;
633
+
634
+ if (zoomed()) {
635
+ touchesStart = (UNDEFINED)
636
+ if (zoomValue < 1) {
637
+ resetZoom()
638
+ }
639
+ return;
640
+ }
641
+
642
+ const touches = e.changedTouches || [{pageX: __pageX(e), pageY: __pageY(e)}];
643
+ // console.log('onTouchEnd', touches, e)
644
+
645
+ let touchEnd = touches[0];
646
+ let touchStart = touchesStart[0];
647
+ let distX = __pageX(touchEnd) - __pageX(touchStart);
648
+ let distY = __pageY(touchEnd) - __pageY(touchStart);
649
+
650
+ touchesStart = (UNDEFINED)
651
+ shift(0)
652
+ const minDistance = 20;
653
+
654
+ if (abs(distX / distY) > 2 && abs(distX) > minDistance) {
655
+ distX < 0 ? right() : left();
656
+ e.swipeProcessed = true
657
+ } else if (abs(distY / distX) > 2 && abs(distY) > minDistance) {
658
+ !props().embedded && onClose();
659
+ e.swipeProcessed = true
660
+ }
661
+ };
662
+
663
+ const scrollTo = (i, prev) => {
664
+ const {previews} = props();
665
+ index(i)
666
+ previous(prev)
667
+ previewScroll(calculatePreviewsScroll(i, previews.images.length, __width(previews)))
668
+ };
669
+
670
+ const left = (e) => {
671
+ if (zoomed())
672
+ return;
673
+ preventDefault(e);
674
+ stopPropagation(e);
675
+ const indexValue = index() !== UNDEFINED ? index() : props().index;
676
+ if (indexValue > 0)
677
+ scrollTo(indexValue - 1, indexValue)
678
+ else if (props().loop)
679
+ scrollTo(props().images.length - 1, indexValue)
680
+ };
681
+
682
+ const right = (e) => {
683
+ if (zoomed())
684
+ return;
685
+ preventDefault(e);
686
+ stopPropagation(e);
687
+ const {images} = props();
688
+ const indexValue = index() !== UNDEFINED ? index() : props().index;
689
+ if (indexValue < __length(images) - 1)
690
+ scrollTo(indexValue + 1, indexValue)
691
+ else if (props().loop)
692
+ scrollTo(0, indexValue)
693
+ };
694
+
695
+ that.scrollTo = scrollTo;
696
+ that.left = left;
697
+ that.right = right;
698
+
699
+ const animatedRoundButton = (show, className, onClick, icon) => (
700
+ <Animated value={show}>
701
+ <Button className={className} onClick={onClick} round={true}>
702
+ <MaterialIcon icon={icon}/>
703
+ </Button>
704
+ </Animated>);
705
+
706
+ that[ReactConstants[3]] = () => {
707
+ const {open} = props();
708
+ const {images = [], previews = {}, indicator, embedded, loop, onClick, children} = props();
709
+
710
+ const indexValue = index() !== UNDEFINED ? index() : props().index;
711
+ const length = __length(images);
712
+ const isZoomed = zoomed();
713
+ const shiftValue = shift() || 0;
714
+ const previousValue = previous();
715
+ return (
716
+ <Animated value={open}>
717
+ <div className={classNames('ImageGallery', embedded && 'embedded', isZoomed && 'zoomed')}
718
+ tabIndex={0}
719
+ ref={it => (that.gallery = it) && !embedded && it.focus()}
720
+ onKeyDown={onKeyDown}
721
+ onKeyUp={onKeyUp}
722
+ // onClick={e => __target(e) === that.gallery && !e.swipeProcessed && !embedded && onClose()}
723
+ onTouchStart={onTouchStart}
724
+ onTouchEnd={onTouchEnd}
725
+ onMouseDown={onTouchStart}
726
+ onMouseUp={onTouchEnd}
727
+ onMouseMove={onTouchMove}
728
+ onMouseLeave={onTouchEnd}
729
+ onWheel={onWheel}
730
+ >
731
+ {images.map((it, i) => {
732
+ const isZoomedCurrent = isZoomed && i === indexValue;
733
+ const loaded = it.loaded;
734
+ return <Animated key={it.id} value={open} styles={{
735
+ default: small(it, indexValue, i, length),
736
+ mounting: big(it, indexValue, i, shiftValue, length, previousValue),
737
+ mountend: big(it, indexValue, i, shiftValue, length, previousValue),
738
+ unmounting: small(it, indexValue, i, length),
739
+ }}>
740
+ <div
741
+ draggable={false}
742
+ onDoubleClick={e => {
743
+ const img = __target(e);
744
+ if (img.naturalWidth === __clientWidth(img) && img.naturalHeight === __clientHeight(img))
745
+ return;
746
+
747
+ if (!isZoomed) {
748
+ zoomedImage = img.tagName.toLowerCase() === 'img' ? img.parentElement : img;
749
+ initZoom()
750
+ zoomValue = 2;
751
+ let newWidth = WINDOW.innerWidth * 2;
752
+ let oldWidth = Number.parseFloat(__style(zoomedImage).width);
753
+ let oldLeft = Number.parseFloat(__style(zoomedImage).left);
754
+ let zoomX = __pageX(e);
755
+ let diff = newWidth / oldWidth;
756
+ let newLeft = zoomX - (zoomX - oldLeft) * diff;
757
+
758
+ let oldTop = Number.parseFloat(__style(zoomedImage).top);
759
+ let zoomY = __pageY(e);
760
+ let newTop = zoomY - (zoomY - oldTop) * diff;
761
+
762
+ __style(zoomedImage).width = '200%'
763
+ __style(zoomedImage).left = newLeft + 'px'
764
+ __style(zoomedImage).top = newTop + 'px'
765
+ } else {
766
+ resetZoom()
767
+ }
768
+ }}
769
+ onClick={(e) => {
770
+ !e.swipeProcessed && orNoop(onClick)(e, it, i)
771
+ }}
772
+ key={i} className={classNames('image', touchesStart && 'dragging', isZoomedCurrent && 'zoomed', i === indexValue && 'current')}
773
+ >
774
+ <img draggable={false} src={loaded ? it.url : it.previewUrl} onDragStart={preventDefault}/>
775
+
776
+ <Animated value={!loaded && Math.abs(indexValue - i) <= 1}>
777
+ <div className={'spinner'}><SpinningProgress/></div>
778
+ </Animated>
779
+
780
+ {!embedded && animatedRoundButton(open && !isZoomedCurrent,
781
+ 'close',
782
+ onClose,
783
+ 'close'
784
+ )}
785
+
786
+
787
+ <Animated value={loaded && !isZoomedCurrent}>
788
+ <div className="counter">
789
+ {indexValue + 1} / {length}
790
+ </div>
791
+ </Animated>
792
+
793
+ {!isZoomedCurrent && loaded && it.overlay}
794
+ </div>
795
+ </Animated>;
796
+ })}
797
+
798
+ {animatedRoundButton(open && length > 1 && (indexValue > 0 || loop) && !isZoomed,
799
+ 'arrow left',
800
+ left,
801
+ 'chevron_left'
802
+ )}
803
+
804
+ {animatedRoundButton(open && length > 1 && (indexValue !== length - 1 || loop) && !isZoomed,
805
+ 'arrow right',
806
+ right,
807
+ 'chevron_right'
808
+ )}
809
+
810
+ <Animated value={open && length > 1 && !isZoomed}>
811
+ <div className="counter">
812
+ {indexValue + 1} / {length}
813
+ </div>
814
+ </Animated>
815
+
816
+ {indicator && <Animated value={open && length > 1 && !isZoomed}>
817
+ {indicator(indexValue, length)}
818
+ </Animated>}
819
+
820
+ <Animated value={open && previews.show && !isZoomed}>
821
+ <div className="previews" style={{width: __width(previews)}}>
822
+ <div className="viewport">
823
+ <div className="container" style={{width: previews.totalWidth, left: toPx(previewScroll() || previews.scroll)}}>
824
+ {(previews.images || []).map((it, i) =>
825
+ <div key={i}
826
+ className={classNames('preview', indexValue === i && 'selected')}
827
+ onClick={() => scrollTo(i, indexValue)}
828
+ >
829
+ <img src={it.url} style={it}/>
830
+
831
+ <div className="border">
832
+ <div className="line"/>
833
+ </div>
834
+ </div>)}
835
+ </div>
836
+ </div>
837
+
838
+ {animatedRoundButton(indexValue > 0 || loop,
839
+ 'arrow left',
840
+ left,
841
+ 'keyboard_arrow_left'
842
+ )}
843
+ {animatedRoundButton(indexValue !== length - 1 || loop,
844
+ 'arrow right',
845
+ right,
846
+ 'keyboard_arrow_right'
847
+ )}
848
+ </div>
849
+ </Animated>
850
+
851
+ {children}
852
+ </div>
853
+ </Animated>
854
+ )
855
+ }
856
+
857
+ }
858
+ }
859
+
860
+ export const IMAGE_GALLERY_REDUCER_NAME = 'gallery';
861
+ export const IMAGE_GALLERY_REDUCER = (state, action) => {
862
+ state = state || {};
863
+ const reducer = reducers[action.type];
864
+ return reducer ? reducer(state, action) : state;
865
+ };
866
+
867
+ export const mapStateToProps = (state, ownProps) => state[IMAGE_GALLERY_REDUCER_NAME];
868
+
869
+ export default ImageGallery;
870
+
871
+ export class ImageGalleryContainer extends React.Component {
872
+ constructor(properties) {
873
+ super(properties);
874
+ const that = this;
875
+
876
+ that.state = IMAGE_GALLERY_REDUCER(null, {})
877
+ const getState = () => __state(that);
878
+
879
+ const dispatch = (action) => setTimeout(() => {
880
+ that.setState(state => {
881
+ // console.log('before action', action, state)
882
+ state = IMAGE_GALLERY_REDUCER(state, action);
883
+ // console.log('after action', action, state)
884
+ return state;
885
+ })
886
+ }, 0)
887
+
888
+ const props = propsGetter(that)
889
+
890
+ const embedded = 'embedded'
891
+ const galleryRef = createRef()
892
+
893
+ const show = that.show = (gallery) => {
894
+ if (!!props()[embedded]) {
895
+ if (props().containerRef()) {
896
+ Actions.show({
897
+ ...gallery,
898
+ [embedded]: !!props()[embedded],
899
+ container: props().containerRef(),
900
+ })(dispatch)
901
+ } else {
902
+ setTimeout(show, 1, gallery)
903
+ }
904
+ } else {
905
+ Actions.show(gallery)(dispatch)
906
+ }
907
+ };
908
+ const close = that.close = () => {
909
+ Actions.close()(dispatch)
910
+ };
911
+ const load = that.load = (item) => {
912
+ Actions.load(item)(dispatch)
913
+ };
914
+ const recalculate = that.recalculate = () => {
915
+ Actions.recalculate()(dispatch)
916
+ };
917
+ that.replaceImages = (images) => {
918
+ Actions.replaceImages(images)(dispatch, getState)
919
+ };
920
+
921
+ that[ReactConstants[3]] = () => <ImageGallery ref={galleryRef} {...__props(that)} {...__state(that)} show={show} load={load} close={close} recalculate={recalculate}>
922
+ {__props(that)[ReactConstants[4]]}
923
+ </ImageGallery>
924
+
925
+ that[ReactConstants[0]] = () => {
926
+ props()[embedded] && show(props()[embedded])
927
+ that.scrollTo = galleryRef().scrollTo;
928
+ that.left = __left(galleryRef());
929
+ that.right = galleryRef().right;
930
+ }
931
+ that[ReactConstants[2]] = (prevProps, prevState) => {
932
+ isDifferent(prevProps[embedded], props()[embedded]) && props()[embedded] && show(props()[embedded])
933
+ }
934
+ }
935
+ }