@micromag/screen-game-sort 0.3.737 → 0.3.739

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 +36 -20
  2. package/package.json +2 -2
package/es/index.js CHANGED
@@ -1,15 +1,15 @@
1
1
  import { useIntl, FormattedMessage, defineMessage } from 'react-intl';
2
- import _objectSpread from '@babel/runtime/helpers/objectSpread2';
3
2
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
4
3
  import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
5
4
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
5
+ import _objectSpread from '@babel/runtime/helpers/objectSpread2';
6
6
  import { useSprings, animated } from '@react-spring/web';
7
7
  import { useDrag } from '@use-gesture/react';
8
8
  import classNames from 'classnames';
9
9
  import isString from 'lodash/isString';
10
10
  import shuffle from 'lodash/shuffle';
11
11
  import PropTypes from 'prop-types';
12
- import React, { useState, useRef, useEffect, useCallback } from 'react';
12
+ import React, { useMemo, useState, useRef, useEffect, useCallback } from 'react';
13
13
  import { PropTypes as PropTypes$1 } from '@micromag/core';
14
14
  import { ScreenElement } from '@micromag/core/components';
15
15
  import { useScreenSize, useScreenRenderContext, useViewerContext, useViewerWebView, usePlaybackContext, usePlaybackMediaRef } from '@micromag/core/contexts';
@@ -74,10 +74,10 @@ var defaultProps = {
74
74
  active: true,
75
75
  className: null
76
76
  };
77
- var zzzz = function zzzz(_ref) {
77
+ var GameSort = function GameSort(_ref) {
78
78
  var layout = _ref.layout,
79
79
  heading = _ref.heading,
80
- items = _ref.items,
80
+ initialItems = _ref.items,
81
81
  spacing = _ref.spacing,
82
82
  itemsLayout = _ref.itemsLayout,
83
83
  itemsBoxStyle = _ref.itemsBoxStyle,
@@ -135,6 +135,13 @@ var zzzz = function zzzz(_ref) {
135
135
  footerHeight = _useDimensionObserver4 === void 0 ? 0 : _useDimensionObserver4;
136
136
  var trackingEnabled = isView;
137
137
  var trackEvent = useTrackScreenEvent('game-sort');
138
+ var items = useMemo(function () {
139
+ return (initialItems || []).map(function (item, itemIndex) {
140
+ return _objectSpread({
141
+ id: itemIndex
142
+ }, item);
143
+ });
144
+ }, [initialItems]);
138
145
  var _useState = useState(isView ? shuffle(items || []) : items || []),
139
146
  _useState2 = _slicedToArray(_useState, 2),
140
147
  sortedItems = _useState2[0],
@@ -197,18 +204,25 @@ var zzzz = function zzzz(_ref) {
197
204
  var refs = currentItems.map(function (it) {
198
205
  return elementsRef.current[it.id] || null;
199
206
  });
200
- var heights = refs.map(function (it) {
207
+ var initialRefs = (items || []).map(function (it) {
208
+ return elementsRef.current[it.id] || null;
209
+ });
210
+ var initialHeights = initialRefs.map(function (it) {
201
211
  var _it$getBoundingClient;
202
212
  return (it === null || it === void 0 || (_it$getBoundingClient = it.getBoundingClientRect()) === null || _it$getBoundingClient === void 0 ? void 0 : _it$getBoundingClient.height) || 0;
203
213
  });
214
+ var heights = refs.map(function (it) {
215
+ var _it$getBoundingClient2;
216
+ return (it === null || it === void 0 || (_it$getBoundingClient2 = it.getBoundingClientRect()) === null || _it$getBoundingClient2 === void 0 ? void 0 : _it$getBoundingClient2.height) || 0;
217
+ });
204
218
  // console.log('heights', heights);
205
219
  api.start(function (itemIndex) {
206
220
  var item = (items || [])[itemIndex] || null;
207
221
  var sortedIndex = currentItems.findIndex(function (it) {
208
222
  return it.id === item.id;
209
223
  });
210
- var currentHeight = heights[itemIndex] || 0;
211
- var currentY = heights.slice(0, itemIndex).reduce(function (acc, itemHeight) {
224
+ var currentHeight = initialHeights[itemIndex] || 0;
225
+ var currentY = initialHeights.slice(0, itemIndex).reduce(function (acc, itemHeight) {
212
226
  return acc + itemHeight;
213
227
  }, 0);
214
228
 
@@ -221,13 +235,15 @@ var zzzz = function zzzz(_ref) {
221
235
  immediate: true
222
236
  };
223
237
  }
224
- if (itemIndex === sortedIndex) {
225
- return {
226
- y: "0%",
227
- scale: 1,
228
- immediate: initial
229
- };
230
- }
238
+
239
+ // if (itemIndex === sortedIndex) {
240
+ // return {
241
+ // y: `0%`,
242
+ // scale: 1,
243
+ // immediate: initial,
244
+ // };
245
+ // }
246
+
231
247
  var newY = heights.slice(0, sortedIndex).reduce(function (acc, itemHeight) {
232
248
  return acc + itemHeight;
233
249
  }, 0);
@@ -282,8 +298,8 @@ var zzzz = function zzzz(_ref) {
282
298
  return elementsRef.current[it.id] || null;
283
299
  });
284
300
  var heights = refs.map(function (it) {
285
- var _it$getBoundingClient2;
286
- return (it === null || it === void 0 || (_it$getBoundingClient2 = it.getBoundingClientRect()) === null || _it$getBoundingClient2 === void 0 ? void 0 : _it$getBoundingClient2.height) || 0;
301
+ var _it$getBoundingClient3;
302
+ return (it === null || it === void 0 || (_it$getBoundingClient3 = it.getBoundingClientRect()) === null || _it$getBoundingClient3 === void 0 ? void 0 : _it$getBoundingClient3.height) || 0;
287
303
  });
288
304
  var ys = heights.map(function (itemHeight, heightIndex) {
289
305
  var endY = itemHeight + heights.slice(0, heightIndex).reduce(function (acc, h) {
@@ -505,8 +521,8 @@ var zzzz = function zzzz(_ref) {
505
521
  className: styles.background
506
522
  }) : null);
507
523
  };
508
- zzzz.propTypes = propTypes;
509
- zzzz.defaultProps = defaultProps;
524
+ GameSort.propTypes = propTypes;
525
+ GameSort.defaultProps = defaultProps;
510
526
 
511
527
  // import * as transforms from './transforms/index';
512
528
 
@@ -530,7 +546,7 @@ var definition = {
530
546
  "value": "Sort game"
531
547
  }]
532
548
  }),
533
- component: zzzz,
549
+ component: GameSort,
534
550
  layouts: ['top', 'middle', 'bottom'],
535
551
  // transforms,
536
552
  fields: [{
@@ -763,4 +779,4 @@ var definition = {
763
779
  }]
764
780
  };
765
781
 
766
- export { zzzz as GameSortScreen, definition as default };
782
+ export { GameSort as GameSortScreen, definition as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@micromag/screen-game-sort",
3
- "version": "0.3.737",
3
+ "version": "0.3.739",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [
@@ -87,5 +87,5 @@
87
87
  "access": "public",
88
88
  "registry": "https://registry.npmjs.org/"
89
89
  },
90
- "gitHead": "357ff7c95c7a25f250304c26a5d8a611a717d341"
90
+ "gitHead": "3808fe7b593aaed071a4cf42039c17e5a90cc596"
91
91
  }