@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.
Files changed (2) hide show
  1. package/es/index.js +116 -92
  2. 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, useMemo, useState, useCallback, useEffect } from 'react';
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 _useState = useState(false),
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
- popup = _useState4[0],
187
- setPopup = _useState4[1];
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 _ref8 = popupHeading || {},
201
- _ref8$textStyle = _ref8.textStyle,
202
- popupHeadingTextStyle = _ref8$textStyle === void 0 ? null : _ref8$textStyle;
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 _ref9 = popupContent || {},
205
- _ref9$textStyle = _ref9.textStyle,
206
- popupContentTextStyle = _ref9$textStyle === void 0 ? null : _ref9$textStyle;
207
- var _ref0 = popupButton || {},
208
- _ref0$label = _ref0.label,
209
- buttonLabel = _ref0$label === void 0 ? null : _ref0$label,
210
- _ref0$url = _ref0.url,
211
- buttonUrl = _ref0$url === void 0 ? null : _ref0$url,
212
- _ref0$inWebView = _ref0.inWebView,
213
- popupInWebView = _ref0$inWebView === void 0 ? false : _ref0$inWebView,
214
- _ref0$boxStyle = _ref0.boxStyle,
215
- popupButtonBoxStyle = _ref0$boxStyle === void 0 ? null : _ref0$boxStyle;
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 _ref1 = item || {},
222
- _ref1$label = _ref1.label,
223
- itemLabel = _ref1$label === void 0 ? null : _ref1$label,
224
- _ref1$heading = _ref1.heading,
225
- heading = _ref1$heading === void 0 ? null : _ref1$heading,
226
- _ref1$inWebView = _ref1.inWebView,
227
- inWebView = _ref1$inWebView === void 0 ? false : _ref1$inWebView,
228
- _ref1$url = _ref1.url,
229
- url = _ref1$url === void 0 ? null : _ref1$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 _ref10 = heading || {},
239
- _ref10$body = _ref10.body,
240
- headingBody = _ref10$body === void 0 ? null : _ref10$body;
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 _useState5 = useState(0),
275
- _useState6 = _slicedToArray(_useState5, 2),
276
- popupDragDirection = _useState6[0],
277
- setPopupDragDirection = _useState6[1];
278
- var onPopupScrollHeightChange = useCallback(function (_ref11) {
279
- var _ref11$scrolleeHeight = _ref11.scrolleeHeight,
280
- scrolleeHeight = _ref11$scrolleeHeight === void 0 ? 0 : _ref11$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 (_ref12) {
288
- var dragActive = _ref12.active,
289
- _ref12$movement = _slicedToArray(_ref12.movement, 2),
290
- my = _ref12$movement[1],
291
- _ref12$velocity = _slicedToArray(_ref12.velocity, 2),
292
- vy = _ref12$velocity[1];
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 _ref13 = item || {},
389
- _ref13$id = _ref13.id,
390
- id = _ref13$id === void 0 ? null : _ref13$id,
391
- _ref13$label = _ref13.label,
392
- itemLabel = _ref13$label === void 0 ? null : _ref13$label,
393
- _ref13$visual = _ref13.visual,
394
- visual = _ref13$visual === void 0 ? null : _ref13$visual,
395
- _ref13$boxStyle = _ref13.boxStyle,
396
- boxStyle = _ref13$boxStyle === void 0 ? null : _ref13$boxStyle,
397
- _ref13$heading = _ref13.heading,
398
- heading = _ref13$heading === void 0 ? null : _ref13$heading,
399
- _ref13$content = _ref13.content,
400
- content = _ref13$content === void 0 ? null : _ref13$content,
401
- _ref13$url = _ref13.url,
402
- url = _ref13$url === void 0 ? null : _ref13$url,
403
- _ref13$inWebView = _ref13.inWebView,
404
- inWebView = _ref13$inWebView === void 0 ? false : _ref13$inWebView,
405
- _ref13$largeVisual = _ref13.largeVisual,
406
- popupLargeVisual = _ref13$largeVisual === void 0 ? null : _ref13$largeVisual;
407
- var _ref14 = visual || {},
408
- _ref14$url = _ref14.url,
409
- visualUrl = _ref14$url === void 0 ? null : _ref14$url;
410
- var _ref15 = heading || {},
411
- _ref15$body = _ref15.body,
412
- headingBody = _ref15$body === void 0 ? null : _ref15$body;
413
- var _ref16 = content || {},
414
- _ref16$body = _ref16.body,
415
- contentBody = _ref16$body === void 0 ? null : _ref16$body;
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 _ref17 = finalLabel || {},
420
- _ref17$textStyle = _ref17.textStyle,
421
- finalLabelTextStyle = _ref17$textStyle === void 0 ? null : _ref17$textStyle;
422
- var _ref18 = finalLabel || {},
423
- _ref18$body = _ref18.body,
424
- finalBody = _ref18$body === void 0 ? null : _ref18$body;
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 !== null && screenState.includes('popup')) {
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 === null && !isView) {
492
+ if (screenState == null && !isView) {
472
493
  setPopup(null);
473
494
  setShowPopup(false);
474
495
  }
475
- }, [screenState, items, isView, showPopup, setPopup, setShowPopup]);
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
- padding: spacing,
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
- width: "100%"
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.52",
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.52",
70
- "@micromag/element-background": "^0.4.52",
71
- "@micromag/element-button": "^0.4.52",
72
- "@micromag/element-call-to-action": "^0.4.52",
73
- "@micromag/element-container": "^0.4.52",
74
- "@micromag/element-footer": "^0.4.52",
75
- "@micromag/element-grid": "^0.4.52",
76
- "@micromag/element-header": "^0.4.52",
77
- "@micromag/element-heading": "^0.4.52",
78
- "@micromag/element-keypad": "^0.4.52",
79
- "@micromag/element-layout": "^0.4.52",
80
- "@micromag/element-scroll": "^0.4.52",
81
- "@micromag/element-text": "^0.4.52",
82
- "@micromag/element-urbania-author": "^0.4.52",
83
- "@micromag/element-visual": "^0.4.52",
84
- "@micromag/transforms": "^0.4.52",
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": "7e9283049e6904a73ed2c8ac47b2e45465823656",
97
+ "gitHead": "9708f0016de0cf18dcd6a6aa5bc70d7f00b86d9f",
98
98
  "types": "es/index.d.ts"
99
99
  }