@micromag/screen-game-sort 0.3.736 → 0.3.737

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 +35 -24
  2. package/package.json +2 -2
package/es/index.js CHANGED
@@ -74,7 +74,7 @@ var defaultProps = {
74
74
  active: true,
75
75
  className: null
76
76
  };
77
- var ShareScreen = function ShareScreen(_ref) {
77
+ var zzzz = function zzzz(_ref) {
78
78
  var layout = _ref.layout,
79
79
  heading = _ref.heading,
80
80
  items = _ref.items,
@@ -141,7 +141,7 @@ var ShareScreen = function ShareScreen(_ref) {
141
141
  setSortedItems = _useState2[1];
142
142
  var sortedItemsRef = useRef(sortedItems);
143
143
  var currentItemsRef = useRef(items);
144
- var elementsRef = useRef([]);
144
+ var elementsRef = useRef({});
145
145
  var _useState3 = useState(false),
146
146
  _useState4 = _slicedToArray(_useState3, 2),
147
147
  initialSorted = _useState4[0],
@@ -194,21 +194,27 @@ var ShareScreen = function ShareScreen(_ref) {
194
194
  dragY = _ref2.dragY,
195
195
  _ref2$initial = _ref2.initial,
196
196
  initial = _ref2$initial === void 0 ? false : _ref2$initial;
197
- var heights = elementsRef.current.map(function (item) {
198
- var _item$getBoundingClie;
199
- return (item === null || item === void 0 || (_item$getBoundingClie = item.getBoundingClientRect()) === null || _item$getBoundingClie === void 0 ? void 0 : _item$getBoundingClie.height) || 0;
197
+ var refs = currentItems.map(function (it) {
198
+ return elementsRef.current[it.id] || null;
200
199
  });
200
+ var heights = refs.map(function (it) {
201
+ var _it$getBoundingClient;
202
+ return (it === null || it === void 0 || (_it$getBoundingClient = it.getBoundingClientRect()) === null || _it$getBoundingClient === void 0 ? void 0 : _it$getBoundingClient.height) || 0;
203
+ });
204
+ // console.log('heights', heights);
201
205
  api.start(function (itemIndex) {
202
206
  var item = (items || [])[itemIndex] || null;
203
207
  var sortedIndex = currentItems.findIndex(function (it) {
204
- return it === item;
208
+ return it.id === item.id;
205
209
  });
206
210
  var currentHeight = heights[itemIndex] || 0;
211
+ var currentY = heights.slice(0, itemIndex).reduce(function (acc, itemHeight) {
212
+ return acc + itemHeight;
213
+ }, 0);
214
+
215
+ // This works
207
216
  if (item === dragItem) {
208
- var _currentY = heights.slice(0, itemIndex).reduce(function (acc, itemHeight) {
209
- return acc + itemHeight;
210
- }, 0);
211
- var _deltaY = dragY - _currentY;
217
+ var _deltaY = dragY - currentY;
212
218
  return {
213
219
  y: "".concat(_deltaY / currentHeight * 100, "%"),
214
220
  scale: 1.02,
@@ -222,9 +228,6 @@ var ShareScreen = function ShareScreen(_ref) {
222
228
  immediate: initial
223
229
  };
224
230
  }
225
- var currentY = heights.slice(0, itemIndex).reduce(function (acc, itemHeight) {
226
- return acc + itemHeight;
227
- }, 0);
228
231
  var newY = heights.slice(0, sortedIndex).reduce(function (acc, itemHeight) {
229
232
  return acc + itemHeight;
230
233
  }, 0);
@@ -269,12 +272,18 @@ var ShareScreen = function ShareScreen(_ref) {
269
272
  var sortedIndex = sortedItems.findIndex(function (it) {
270
273
  return it === item;
271
274
  });
272
- var heights = sortedItems.map(function (sortedItem) {
273
- var _elementsRef$current$;
274
- var elementIndex = items.findIndex(function (it) {
275
- return it === sortedItem;
276
- });
277
- return ((_elementsRef$current$ = elementsRef.current[elementIndex]) === null || _elementsRef$current$ === void 0 || (_elementsRef$current$ = _elementsRef$current$.getBoundingClientRect()) === null || _elementsRef$current$ === void 0 ? void 0 : _elementsRef$current$.height) || 0;
275
+
276
+ // const heights = sortedItems.map((sortedItem) => {
277
+ // const elementIndex = items.findIndex((it) => it === sortedItem);
278
+ // return elementsRef.current[elementIndex]?.getBoundingClientRect()?.height || 0;
279
+ // });
280
+
281
+ var refs = sortedItems.map(function (it) {
282
+ return elementsRef.current[it.id] || null;
283
+ });
284
+ 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;
278
287
  });
279
288
  var ys = heights.map(function (itemHeight, heightIndex) {
280
289
  var endY = itemHeight + heights.slice(0, heightIndex).reduce(function (acc, h) {
@@ -406,6 +415,8 @@ var ShareScreen = function ShareScreen(_ref) {
406
415
  scale = _ref6.scale;
407
416
  var item = items[itemIndex] || {};
408
417
  var _ref7 = item || {},
418
+ _ref7$id = _ref7.id,
419
+ id = _ref7$id === void 0 ? null : _ref7$id,
409
420
  _ref7$visual = _ref7.visual,
410
421
  visual = _ref7$visual === void 0 ? null : _ref7$visual,
411
422
  itemLabel = _ref7.label,
@@ -428,7 +439,7 @@ var ShareScreen = function ShareScreen(_ref) {
428
439
  clickable: dragEnabled
429
440
  }, styles.isEmpty, isEmpty), styles.valid, validated !== null && isValid), styles.invalid, validated !== null && !isValid)]),
430
441
  ref: function ref(_ref1) {
431
- elementsRef.current[itemIndex] = _ref1;
442
+ elementsRef.current[id] = _ref1;
432
443
  },
433
444
  style: _objectSpread(_objectSpread({
434
445
  transform: y.to(function (yValue) {
@@ -494,8 +505,8 @@ var ShareScreen = function ShareScreen(_ref) {
494
505
  className: styles.background
495
506
  }) : null);
496
507
  };
497
- ShareScreen.propTypes = propTypes;
498
- ShareScreen.defaultProps = defaultProps;
508
+ zzzz.propTypes = propTypes;
509
+ zzzz.defaultProps = defaultProps;
499
510
 
500
511
  // import * as transforms from './transforms/index';
501
512
 
@@ -519,7 +530,7 @@ var definition = {
519
530
  "value": "Sort game"
520
531
  }]
521
532
  }),
522
- component: ShareScreen,
533
+ component: zzzz,
523
534
  layouts: ['top', 'middle', 'bottom'],
524
535
  // transforms,
525
536
  fields: [{
@@ -752,4 +763,4 @@ var definition = {
752
763
  }]
753
764
  };
754
765
 
755
- export { ShareScreen as GameSortScreen, definition as default };
766
+ export { zzzz 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.736",
3
+ "version": "0.3.737",
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": "77bd0bf6941418463c0f7bbb68bf9b20379c5c55"
90
+ "gitHead": "357ff7c95c7a25f250304c26a5d8a611a717d341"
91
91
  }