@micromag/screen-keypad 0.4.52 → 0.4.55
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/es/index.js +116 -92
- package/package.json +18 -18
package/es/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import { animated } from '@react-spring/web';
|
|
|
6
6
|
import classNames from 'classnames';
|
|
7
7
|
import isEmpty from 'lodash/isEmpty';
|
|
8
8
|
import isString from 'lodash/isString';
|
|
9
|
-
import { useRef,
|
|
9
|
+
import { useRef, useState, useMemo, useCallback, useEffect } from 'react';
|
|
10
10
|
import { Close, ScreenElement } from '@micromag/core/components';
|
|
11
11
|
import { usePlaybackContext, usePlaybackMediaRef, useScreenState, useScreenSize, useViewerContext, useViewerWebView, useViewerInteraction, useScreenRenderContext } from '@micromag/core/contexts';
|
|
12
12
|
import { useTrackScreenEvent, useDimensionObserver, useDragProgress } from '@micromag/core/hooks';
|
|
@@ -134,6 +134,10 @@ function KeypadScreen(_ref) {
|
|
|
134
134
|
footerRef = _useDimensionObserver3.ref,
|
|
135
135
|
_useDimensionObserver4 = _useDimensionObserver3.height,
|
|
136
136
|
footerHeight = _useDimensionObserver4 === void 0 ? 0 : _useDimensionObserver4;
|
|
137
|
+
var _useState = useState(false),
|
|
138
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
139
|
+
popupDragDisabled = _useState2[0],
|
|
140
|
+
setPopupDragDisabled = _useState2[1];
|
|
137
141
|
var backgroundPlaying = current && (isView || isEdit) && (isCurrentMedia || !isView);
|
|
138
142
|
var mediaShouldLoad = !isPlaceholder && (current || preload);
|
|
139
143
|
var isInteractivePreview = isEdit && screenState === null;
|
|
@@ -177,14 +181,15 @@ function KeypadScreen(_ref) {
|
|
|
177
181
|
var popupLayoutClassName = useMemo(function () {
|
|
178
182
|
return popupLayout !== null ? camelCase(popupLayout) : '';
|
|
179
183
|
}, [popupLayout]);
|
|
180
|
-
var
|
|
181
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
182
|
-
showPopup = _useState2[0],
|
|
183
|
-
setShowPopup = _useState2[1];
|
|
184
|
-
var _useState3 = useState(null),
|
|
184
|
+
var _useState3 = useState(false),
|
|
185
185
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
186
|
-
|
|
187
|
-
|
|
186
|
+
showPopup = _useState4[0],
|
|
187
|
+
setShowPopup = _useState4[1];
|
|
188
|
+
var _useState5 = useState(null),
|
|
189
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
190
|
+
popup = _useState6[0],
|
|
191
|
+
setPopup = _useState6[1];
|
|
192
|
+
var prevShowPopupRef = useRef(showPopup);
|
|
188
193
|
var _ref7 = popup || {},
|
|
189
194
|
_ref7$heading = _ref7.heading,
|
|
190
195
|
popupHeading = _ref7$heading === void 0 ? null : _ref7$heading,
|
|
@@ -196,37 +201,46 @@ function KeypadScreen(_ref) {
|
|
|
196
201
|
popupButton = _ref7$button === void 0 ? null : _ref7$button,
|
|
197
202
|
_ref7$popupBoxStyle = _ref7.popupBoxStyle,
|
|
198
203
|
singlePopupBoxStyle = _ref7$popupBoxStyle === void 0 ? null : _ref7$popupBoxStyle;
|
|
204
|
+
var _ref8 = largeVisual || {},
|
|
205
|
+
_ref8$metadata = _ref8.metadata,
|
|
206
|
+
metadata = _ref8$metadata === void 0 ? null : _ref8$metadata;
|
|
207
|
+
var _ref9 = metadata || {},
|
|
208
|
+
_ref9$width = _ref9.width,
|
|
209
|
+
largeVisualWidth = _ref9$width === void 0 ? 0 : _ref9$width,
|
|
210
|
+
_ref9$height = _ref9.height,
|
|
211
|
+
largeVisualHeight = _ref9$height === void 0 ? 0 : _ref9$height;
|
|
212
|
+
var largeVisualRatio = largeVisualWidth > 0 && largeVisualHeight > 0 ? largeVisualWidth / largeVisualHeight : null;
|
|
199
213
|
var hasPopupHeading = isTextFilled(popupHeading);
|
|
200
|
-
var
|
|
201
|
-
|
|
202
|
-
popupHeadingTextStyle =
|
|
214
|
+
var _ref0 = popupHeading || {},
|
|
215
|
+
_ref0$textStyle = _ref0.textStyle,
|
|
216
|
+
popupHeadingTextStyle = _ref0$textStyle === void 0 ? null : _ref0$textStyle;
|
|
203
217
|
var hasPopupContent = isTextFilled(popupContent);
|
|
204
|
-
var
|
|
205
|
-
|
|
206
|
-
popupContentTextStyle =
|
|
207
|
-
var
|
|
208
|
-
|
|
209
|
-
buttonLabel =
|
|
210
|
-
|
|
211
|
-
buttonUrl =
|
|
212
|
-
|
|
213
|
-
popupInWebView =
|
|
214
|
-
|
|
215
|
-
popupButtonBoxStyle =
|
|
218
|
+
var _ref1 = popupContent || {},
|
|
219
|
+
_ref1$textStyle = _ref1.textStyle,
|
|
220
|
+
popupContentTextStyle = _ref1$textStyle === void 0 ? null : _ref1$textStyle;
|
|
221
|
+
var _ref10 = popupButton || {},
|
|
222
|
+
_ref10$label = _ref10.label,
|
|
223
|
+
buttonLabel = _ref10$label === void 0 ? null : _ref10$label,
|
|
224
|
+
_ref10$url = _ref10.url,
|
|
225
|
+
buttonUrl = _ref10$url === void 0 ? null : _ref10$url,
|
|
226
|
+
_ref10$inWebView = _ref10.inWebView,
|
|
227
|
+
popupInWebView = _ref10$inWebView === void 0 ? false : _ref10$inWebView,
|
|
228
|
+
_ref10$boxStyle = _ref10.boxStyle,
|
|
229
|
+
popupButtonBoxStyle = _ref10$boxStyle === void 0 ? null : _ref10$boxStyle;
|
|
216
230
|
var onItemClick = useCallback(function (e, item, index) {
|
|
217
231
|
e.stopPropagation();
|
|
218
232
|
if (isNotInteractive) {
|
|
219
233
|
return;
|
|
220
234
|
}
|
|
221
|
-
var
|
|
222
|
-
|
|
223
|
-
itemLabel =
|
|
224
|
-
|
|
225
|
-
heading =
|
|
226
|
-
|
|
227
|
-
inWebView =
|
|
228
|
-
|
|
229
|
-
url =
|
|
235
|
+
var _ref11 = item || {},
|
|
236
|
+
_ref11$label = _ref11.label,
|
|
237
|
+
itemLabel = _ref11$label === void 0 ? null : _ref11$label,
|
|
238
|
+
_ref11$heading = _ref11.heading,
|
|
239
|
+
heading = _ref11$heading === void 0 ? null : _ref11$heading,
|
|
240
|
+
_ref11$inWebView = _ref11.inWebView,
|
|
241
|
+
inWebView = _ref11$inWebView === void 0 ? false : _ref11$inWebView,
|
|
242
|
+
_ref11$url = _ref11.url,
|
|
243
|
+
url = _ref11$url === void 0 ? null : _ref11$url;
|
|
230
244
|
if (inWebView && url !== null) {
|
|
231
245
|
openWebView({
|
|
232
246
|
url: url
|
|
@@ -235,9 +249,9 @@ function KeypadScreen(_ref) {
|
|
|
235
249
|
setPopup(item);
|
|
236
250
|
setShowPopup(true);
|
|
237
251
|
}
|
|
238
|
-
var
|
|
239
|
-
|
|
240
|
-
headingBody =
|
|
252
|
+
var _ref12 = heading || {},
|
|
253
|
+
_ref12$body = _ref12.body,
|
|
254
|
+
headingBody = _ref12$body === void 0 ? null : _ref12$body;
|
|
241
255
|
var finalLabel = isString(itemLabel) ? itemLabel : (itemLabel || {}).body || null;
|
|
242
256
|
trackScreenEvent('click_item', ["#".concat(index + 1), finalLabel || headingBody || ''].filter(function (it) {
|
|
243
257
|
return !isEmpty(it);
|
|
@@ -271,25 +285,25 @@ function KeypadScreen(_ref) {
|
|
|
271
285
|
e.stopPropagation();
|
|
272
286
|
}
|
|
273
287
|
}, []);
|
|
274
|
-
var
|
|
275
|
-
|
|
276
|
-
popupDragDirection =
|
|
277
|
-
setPopupDragDirection =
|
|
278
|
-
var onPopupScrollHeightChange = useCallback(function (
|
|
279
|
-
var
|
|
280
|
-
scrolleeHeight =
|
|
288
|
+
var _useState7 = useState(null),
|
|
289
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
290
|
+
popupDragDirection = _useState8[0],
|
|
291
|
+
setPopupDragDirection = _useState8[1];
|
|
292
|
+
var onPopupScrollHeightChange = useCallback(function (_ref13) {
|
|
293
|
+
var _ref13$scrolleeHeight = _ref13.scrolleeHeight,
|
|
294
|
+
scrolleeHeight = _ref13$scrolleeHeight === void 0 ? 0 : _ref13$scrolleeHeight;
|
|
281
295
|
if (Math.floor(scrolleeHeight) >= Math.floor(height)) {
|
|
282
296
|
setPopupDragDirection('top');
|
|
283
297
|
} else {
|
|
284
298
|
setPopupDragDirection('bottom');
|
|
285
299
|
}
|
|
286
300
|
}, [height]);
|
|
287
|
-
var computePopupProgress = useCallback(function (
|
|
288
|
-
var dragActive =
|
|
289
|
-
|
|
290
|
-
my =
|
|
291
|
-
|
|
292
|
-
vy =
|
|
301
|
+
var computePopupProgress = useCallback(function (_ref14) {
|
|
302
|
+
var dragActive = _ref14.active,
|
|
303
|
+
_ref14$movement = _slicedToArray(_ref14.movement, 2),
|
|
304
|
+
my = _ref14$movement[1],
|
|
305
|
+
_ref14$velocity = _slicedToArray(_ref14.velocity, 2),
|
|
306
|
+
vy = _ref14$velocity[1];
|
|
293
307
|
var damper = 0.5;
|
|
294
308
|
var windowHeight = typeof window !== 'undefined' ? window.innerHeight : 0;
|
|
295
309
|
var delta = windowHeight > 0 ? Math.abs(my) / windowHeight : 0;
|
|
@@ -329,10 +343,6 @@ function KeypadScreen(_ref) {
|
|
|
329
343
|
document.removeEventListener('mouseup', handleClickOutside);
|
|
330
344
|
};
|
|
331
345
|
}, [current, popupInnerRef, containerRef, isInteractivePreview, isEdit, showPopup]);
|
|
332
|
-
var _useState7 = useState(false),
|
|
333
|
-
_useState8 = _slicedToArray(_useState7, 2),
|
|
334
|
-
popupDragDisabled = _useState8[0],
|
|
335
|
-
setPopupDragDisabled = _useState8[1];
|
|
336
346
|
var onPopupScrollBottom = useCallback(function () {
|
|
337
347
|
setPopupDragDisabled(false);
|
|
338
348
|
}, [setPopupDragDisabled]);
|
|
@@ -351,10 +361,12 @@ function KeypadScreen(_ref) {
|
|
|
351
361
|
var onTap = useCallback(function () {
|
|
352
362
|
onCloseModal(showPopup);
|
|
353
363
|
}, [onCloseModal, showPopup]);
|
|
364
|
+
var onResolve = useCallback(function () {}, []);
|
|
354
365
|
var _useDragProgress = useDragProgress({
|
|
355
366
|
disabled: !isView || popupDragDisabled,
|
|
356
367
|
progress: showPopup ? 0 : 1,
|
|
357
368
|
computeProgress: computePopupProgress,
|
|
369
|
+
onResolve: onResolve,
|
|
358
370
|
springParams: {
|
|
359
371
|
config: {
|
|
360
372
|
tension: 300,
|
|
@@ -369,7 +381,16 @@ function KeypadScreen(_ref) {
|
|
|
369
381
|
onTap: onTap
|
|
370
382
|
}),
|
|
371
383
|
bindPopupDrag = _useDragProgress.bind,
|
|
372
|
-
popupSpring = _useDragProgress.progress
|
|
384
|
+
popupSpring = _useDragProgress.progress,
|
|
385
|
+
popupTransitioning = _useDragProgress.transitioning;
|
|
386
|
+
|
|
387
|
+
// Clear popup contents after close transition completes
|
|
388
|
+
useEffect(function () {
|
|
389
|
+
if (prevShowPopupRef.current && !showPopup && !popupTransitioning) {
|
|
390
|
+
setPopup(null);
|
|
391
|
+
}
|
|
392
|
+
prevShowPopupRef.current = showPopup;
|
|
393
|
+
}, [showPopup, popupTransitioning]);
|
|
373
394
|
useEffect(function () {
|
|
374
395
|
var keyup = function keyup(e) {
|
|
375
396
|
if (e.key === 'Escape') {
|
|
@@ -385,43 +406,43 @@ function KeypadScreen(_ref) {
|
|
|
385
406
|
}, [showPopup, onCloseModal]);
|
|
386
407
|
var gridItems = useMemo(function () {
|
|
387
408
|
return (items === null || items.length === 0 ? placeholders : items).map(function (item, index) {
|
|
388
|
-
var
|
|
389
|
-
|
|
390
|
-
id =
|
|
391
|
-
|
|
392
|
-
itemLabel =
|
|
393
|
-
|
|
394
|
-
visual =
|
|
395
|
-
|
|
396
|
-
boxStyle =
|
|
397
|
-
|
|
398
|
-
heading =
|
|
399
|
-
|
|
400
|
-
content =
|
|
401
|
-
|
|
402
|
-
url =
|
|
403
|
-
|
|
404
|
-
inWebView =
|
|
405
|
-
|
|
406
|
-
popupLargeVisual =
|
|
407
|
-
var
|
|
408
|
-
|
|
409
|
-
visualUrl =
|
|
410
|
-
var
|
|
411
|
-
|
|
412
|
-
headingBody =
|
|
413
|
-
var
|
|
414
|
-
|
|
415
|
-
contentBody =
|
|
409
|
+
var _ref15 = item || {},
|
|
410
|
+
_ref15$id = _ref15.id,
|
|
411
|
+
id = _ref15$id === void 0 ? null : _ref15$id,
|
|
412
|
+
_ref15$label = _ref15.label,
|
|
413
|
+
itemLabel = _ref15$label === void 0 ? null : _ref15$label,
|
|
414
|
+
_ref15$visual = _ref15.visual,
|
|
415
|
+
visual = _ref15$visual === void 0 ? null : _ref15$visual,
|
|
416
|
+
_ref15$boxStyle = _ref15.boxStyle,
|
|
417
|
+
boxStyle = _ref15$boxStyle === void 0 ? null : _ref15$boxStyle,
|
|
418
|
+
_ref15$heading = _ref15.heading,
|
|
419
|
+
heading = _ref15$heading === void 0 ? null : _ref15$heading,
|
|
420
|
+
_ref15$content = _ref15.content,
|
|
421
|
+
content = _ref15$content === void 0 ? null : _ref15$content,
|
|
422
|
+
_ref15$url = _ref15.url,
|
|
423
|
+
url = _ref15$url === void 0 ? null : _ref15$url,
|
|
424
|
+
_ref15$inWebView = _ref15.inWebView,
|
|
425
|
+
inWebView = _ref15$inWebView === void 0 ? false : _ref15$inWebView,
|
|
426
|
+
_ref15$largeVisual = _ref15.largeVisual,
|
|
427
|
+
popupLargeVisual = _ref15$largeVisual === void 0 ? null : _ref15$largeVisual;
|
|
428
|
+
var _ref16 = visual || {},
|
|
429
|
+
_ref16$url = _ref16.url,
|
|
430
|
+
visualUrl = _ref16$url === void 0 ? null : _ref16$url;
|
|
431
|
+
var _ref17 = heading || {},
|
|
432
|
+
_ref17$body = _ref17.body,
|
|
433
|
+
headingBody = _ref17$body === void 0 ? null : _ref17$body;
|
|
434
|
+
var _ref18 = content || {},
|
|
435
|
+
_ref18$body = _ref18.body,
|
|
436
|
+
contentBody = _ref18$body === void 0 ? null : _ref18$body;
|
|
416
437
|
var finalLabel = isString(itemLabel) ? {
|
|
417
438
|
body: itemLabel
|
|
418
439
|
} : itemLabel || {};
|
|
419
|
-
var
|
|
420
|
-
|
|
421
|
-
finalLabelTextStyle =
|
|
422
|
-
var
|
|
423
|
-
|
|
424
|
-
finalBody =
|
|
440
|
+
var _ref19 = finalLabel || {},
|
|
441
|
+
_ref19$textStyle = _ref19.textStyle,
|
|
442
|
+
finalLabelTextStyle = _ref19$textStyle === void 0 ? null : _ref19$textStyle;
|
|
443
|
+
var _ref20 = finalLabel || {},
|
|
444
|
+
_ref20$body = _ref20.body,
|
|
445
|
+
finalBody = _ref20$body === void 0 ? null : _ref20$body;
|
|
425
446
|
var key = finalBody || visualUrl || id;
|
|
426
447
|
var itemIsEmpty = finalBody === null && visual === null;
|
|
427
448
|
var isExternalLink = url !== null && !inWebView;
|
|
@@ -462,17 +483,17 @@ function KeypadScreen(_ref) {
|
|
|
462
483
|
setPopup(null);
|
|
463
484
|
setShowPopup(false);
|
|
464
485
|
}
|
|
465
|
-
if (screenState
|
|
486
|
+
if (screenState != null && screenState.includes('popup')) {
|
|
466
487
|
var index = screenState.split('.').pop();
|
|
467
488
|
var found = items[index];
|
|
468
489
|
setPopup(found);
|
|
469
490
|
setShowPopup(true);
|
|
470
491
|
}
|
|
471
|
-
if (screenState
|
|
492
|
+
if (screenState == null && !isView) {
|
|
472
493
|
setPopup(null);
|
|
473
494
|
setShowPopup(false);
|
|
474
495
|
}
|
|
475
|
-
}, [screenState, items, isView
|
|
496
|
+
}, [screenState, items, isView]);
|
|
476
497
|
return /*#__PURE__*/jsxs("div", {
|
|
477
498
|
ref: containerRef,
|
|
478
499
|
className: classNames([styles.container, className, _defineProperty(_defineProperty({}, styles.isPlaceholder, isPlaceholder), styles.withSquareItems, withSquareItems)]),
|
|
@@ -519,7 +540,8 @@ function KeypadScreen(_ref) {
|
|
|
519
540
|
verticalAlign: layout,
|
|
520
541
|
width: width,
|
|
521
542
|
style: !isPlaceholder ? {
|
|
522
|
-
|
|
543
|
+
paddingLeft: spacing,
|
|
544
|
+
paddingRight: spacing,
|
|
523
545
|
paddingTop: (hasHeader ? headerHeight : spacing) + (current && !isPreview ? viewerTopHeight : 0),
|
|
524
546
|
paddingBottom: (hasFooter ? footerHeight : spacing) + (current && !isPreview ? viewerBottomHeight : 0)
|
|
525
547
|
} : null,
|
|
@@ -652,7 +674,9 @@ function KeypadScreen(_ref) {
|
|
|
652
674
|
videoClassName: styles.popupVisualVideo,
|
|
653
675
|
media: largeVisual,
|
|
654
676
|
resolution: resolution,
|
|
655
|
-
|
|
677
|
+
ratio: largeVisualRatio,
|
|
678
|
+
width: "100%",
|
|
679
|
+
height: "auto"
|
|
656
680
|
}) : null
|
|
657
681
|
}), /*#__PURE__*/jsx(ScreenElement, {
|
|
658
682
|
placeholder: "button",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@micromag/screen-keypad",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.55",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"keywords": [
|
|
@@ -66,22 +66,22 @@
|
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
68
|
"@babel/runtime": "^7.28.6",
|
|
69
|
-
"@micromag/core": "^0.4.
|
|
70
|
-
"@micromag/element-background": "^0.4.
|
|
71
|
-
"@micromag/element-button": "^0.4.
|
|
72
|
-
"@micromag/element-call-to-action": "^0.4.
|
|
73
|
-
"@micromag/element-container": "^0.4.
|
|
74
|
-
"@micromag/element-footer": "^0.4.
|
|
75
|
-
"@micromag/element-grid": "^0.4.
|
|
76
|
-
"@micromag/element-header": "^0.4.
|
|
77
|
-
"@micromag/element-heading": "^0.4.
|
|
78
|
-
"@micromag/element-keypad": "^0.4.
|
|
79
|
-
"@micromag/element-layout": "^0.4.
|
|
80
|
-
"@micromag/element-scroll": "^0.4.
|
|
81
|
-
"@micromag/element-text": "^0.4.
|
|
82
|
-
"@micromag/element-urbania-author": "^0.4.
|
|
83
|
-
"@micromag/element-visual": "^0.4.
|
|
84
|
-
"@micromag/transforms": "^0.4.
|
|
69
|
+
"@micromag/core": "^0.4.55",
|
|
70
|
+
"@micromag/element-background": "^0.4.55",
|
|
71
|
+
"@micromag/element-button": "^0.4.55",
|
|
72
|
+
"@micromag/element-call-to-action": "^0.4.55",
|
|
73
|
+
"@micromag/element-container": "^0.4.55",
|
|
74
|
+
"@micromag/element-footer": "^0.4.55",
|
|
75
|
+
"@micromag/element-grid": "^0.4.55",
|
|
76
|
+
"@micromag/element-header": "^0.4.55",
|
|
77
|
+
"@micromag/element-heading": "^0.4.55",
|
|
78
|
+
"@micromag/element-keypad": "^0.4.55",
|
|
79
|
+
"@micromag/element-layout": "^0.4.55",
|
|
80
|
+
"@micromag/element-scroll": "^0.4.55",
|
|
81
|
+
"@micromag/element-text": "^0.4.55",
|
|
82
|
+
"@micromag/element-urbania-author": "^0.4.55",
|
|
83
|
+
"@micromag/element-visual": "^0.4.55",
|
|
84
|
+
"@micromag/transforms": "^0.4.55",
|
|
85
85
|
"@react-spring/core": "^10.0.3",
|
|
86
86
|
"@react-spring/web": "^10.0.3",
|
|
87
87
|
"@use-gesture/react": "^10.3.0",
|
|
@@ -94,6 +94,6 @@
|
|
|
94
94
|
"access": "public",
|
|
95
95
|
"registry": "https://registry.npmjs.org/"
|
|
96
96
|
},
|
|
97
|
-
"gitHead": "
|
|
97
|
+
"gitHead": "9708f0016de0cf18dcd6a6aa5bc70d7f00b86d9f",
|
|
98
98
|
"types": "es/index.d.ts"
|
|
99
99
|
}
|