@micromag/editor 0.2.409 → 0.2.410

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 CHANGED
@@ -791,6 +791,8 @@ var useThemeValue = function useThemeValue(value) {
791
791
  return valueWithTheme;
792
792
  };
793
793
 
794
+ var styles$a = {"container":"micromag-editor-menus-devices-container","button":"micromag-editor-menus-devices-button"};
795
+
794
796
  /* eslint-disable react/button-has-type, react/jsx-props-no-spreading */
795
797
  var propTypes$h = {
796
798
  color: PropTypes.string,
@@ -863,7 +865,7 @@ var DeviceIcons = /*#__PURE__*/Object.freeze({
863
865
  Mobile: MobileIcon
864
866
  });
865
867
 
866
- var styles$a = {"container":"micromag-editor-buttons-device-container","icon":"micromag-editor-buttons-device-icon"};
868
+ var styles$9 = {"container":"micromag-editor-buttons-device-container","icon":"micromag-editor-buttons-device-icon"};
867
869
 
868
870
  var _excluded$6 = ["device", "className", "iconComponents"];
869
871
  var propTypes$f = {
@@ -884,17 +886,15 @@ var DeviceButton = function DeviceButton(_ref) {
884
886
 
885
887
  var DeviceIcon = getComponentFromName(device, iconComponents, DesktopIcon);
886
888
  return /*#__PURE__*/React.createElement(Button, Object.assign({
887
- className: classNames([styles$a.container, _defineProperty({}, className, className !== null)])
889
+ className: classNames([styles$9.container, _defineProperty({}, className, className !== null)])
888
890
  }, props), /*#__PURE__*/React.createElement(DeviceIcon, {
889
- className: styles$a.icon
891
+ className: styles$9.icon
890
892
  }));
891
893
  };
892
894
 
893
895
  DeviceButton.propTypes = propTypes$f;
894
896
  DeviceButton.defaultProps = defaultProps$f;
895
897
 
896
- var styles$9 = {"container":"micromag-editor-menus-devices-container","button":"micromag-editor-menus-devices-button"};
897
-
898
898
  var _excluded$5 = ["id"];
899
899
  var propTypes$e = {
900
900
  items: PropTypes$1.menuItems,
@@ -914,7 +914,7 @@ var DevicesMenu = function DevicesMenu(_ref) {
914
914
  return /*#__PURE__*/React.createElement(Tabs, {
915
915
  items: items,
916
916
  theme: "outline-secondary",
917
- className: classNames([styles$9.container, _defineProperty({}, className, className !== null)]),
917
+ className: classNames([styles$a.container, _defineProperty({}, className, className !== null)]),
918
918
  renderItemButton: function renderItemButton(item, index, props) {
919
919
  var id = item.id,
920
920
  itemProps = _objectWithoutProperties(item, _excluded$5);
@@ -922,7 +922,7 @@ var DevicesMenu = function DevicesMenu(_ref) {
922
922
  return /*#__PURE__*/React.createElement(DeviceButton, Object.assign({
923
923
  device: id
924
924
  }, props, itemProps, {
925
- className: styles$9.button,
925
+ className: styles$a.button,
926
926
  onClick: function onClick(e) {
927
927
  return onClickItem !== null ? onClickItem(e, item, index) : null;
928
928
  }
@@ -1245,11 +1245,9 @@ ScreenWithPreview.propTypes = propTypes$b;
1245
1245
  ScreenWithPreview.defaultProps = defaultProps$b;
1246
1246
 
1247
1247
  var iOS = /iPad|iPhone|iPod/.test(navigator.platform);
1248
-
1249
1248
  function getDragDepth(offset, indentationWidth) {
1250
1249
  return Math.round(offset / indentationWidth);
1251
1250
  }
1252
-
1253
1251
  function getMaxDepth(_ref) {
1254
1252
  var previousItem = _ref.previousItem;
1255
1253
 
@@ -1260,7 +1258,6 @@ function getMaxDepth(_ref) {
1260
1258
 
1261
1259
  return 0;
1262
1260
  }
1263
-
1264
1261
  function getMinDepth(_ref2) {
1265
1262
  var nextItem = _ref2.nextItem;
1266
1263
 
@@ -1271,7 +1268,6 @@ function getMinDepth(_ref2) {
1271
1268
 
1272
1269
  return 0;
1273
1270
  }
1274
-
1275
1271
  function getProjection(items, activeId, overId, dragOffset, indentationWidth) {
1276
1272
  var overItemIndex = items.findIndex(function (_ref3) {
1277
1273
  var id = _ref3.id;
@@ -1345,49 +1341,54 @@ function flatten(items) {
1345
1341
  function flattenTree(items) {
1346
1342
  return flatten(items);
1347
1343
  }
1344
+ function findItem(items, itemId) {
1345
+ return items.find(function (_ref5) {
1346
+ var id = _ref5.id;
1347
+ return id === itemId;
1348
+ });
1349
+ }
1348
1350
  function buildTree(flattenedItems) {
1351
+ var root = {
1352
+ id: 'root',
1353
+ children: []
1354
+ };
1355
+
1356
+ var nodes = _defineProperty({}, root.id, root);
1357
+
1349
1358
  var items = flattenedItems.map(function (item) {
1350
1359
  return _objectSpread(_objectSpread({}, item), {}, {
1351
1360
  children: []
1352
1361
  });
1353
- });
1354
- var nodeList = items.reduce(function (acc, item) {
1355
- var _item$parentId = item.parentId,
1356
- parentId = _item$parentId === void 0 ? null : _item$parentId;
1357
-
1358
- if (parentId) {
1359
- var found = false;
1360
- var newList = acc.map(function (it) {
1361
- if (it.id === parentId) {
1362
- found = true;
1363
- return _objectSpread(_objectSpread({}, it), {}, {
1364
- children: [].concat(_toConsumableArray(it.children), [_objectSpread({}, item)])
1365
- });
1366
- }
1362
+ }); // eslint-disable-next-line no-restricted-syntax
1367
1363
 
1368
- return it;
1369
- });
1364
+ var _iterator = _createForOfIteratorHelper(items),
1365
+ _step;
1370
1366
 
1371
- if (found) {
1372
- return newList;
1373
- }
1367
+ try {
1368
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
1369
+ var _item$parentId, _nodes$parentId;
1374
1370
 
1375
- acc.push(_objectSpread(_objectSpread({}, items.find(function (_ref5) {
1376
- var id = _ref5.id;
1377
- return id === parentId;
1378
- }) || null), {}, {
1379
- children: [item]
1380
- }));
1381
- return acc;
1371
+ var item = _step.value;
1372
+ var id = item.id,
1373
+ children = item.children;
1374
+ var parentId = (_item$parentId = item.parentId) !== null && _item$parentId !== void 0 ? _item$parentId : root.id;
1375
+ var parent = (_nodes$parentId = nodes[parentId]) !== null && _nodes$parentId !== void 0 ? _nodes$parentId : findItem(items, parentId);
1376
+ nodes[id] = {
1377
+ id: id,
1378
+ children: children
1379
+ };
1380
+ parent.children.push(item);
1382
1381
  }
1382
+ } catch (err) {
1383
+ _iterator.e(err);
1384
+ } finally {
1385
+ _iterator.f();
1386
+ }
1383
1387
 
1384
- acc.push(item);
1385
- return acc;
1386
- }, []);
1387
- return nodeList;
1388
+ return root.children;
1388
1389
  }
1389
1390
  function findItemDeep(items, itemId) {
1390
- for (var i = 0; i < items.length - 1; i += 1) {
1391
+ for (var i = 0; i < items.length; i += 1) {
1391
1392
  var item = items[i] || {};
1392
1393
  var id = item.id,
1393
1394
  _item$children = item.children,
@@ -1397,7 +1398,7 @@ function findItemDeep(items, itemId) {
1397
1398
  return item;
1398
1399
  }
1399
1400
 
1400
- if (children.length) {
1401
+ if (children.length > 0) {
1401
1402
  var child = findItemDeep(children, itemId);
1402
1403
 
1403
1404
  if (child) {
@@ -1409,65 +1410,57 @@ function findItemDeep(items, itemId) {
1409
1410
  return undefined;
1410
1411
  }
1411
1412
  function removeItem(items, id) {
1412
- var newItems = [];
1413
+ var newItems = []; // eslint-disable-next-line no-restricted-syntax
1413
1414
 
1414
- for (var i = 0; i < items.length - 1; i += 1) {
1415
- var item = items[i] || {};
1415
+ var _iterator2 = _createForOfIteratorHelper(items),
1416
+ _step2;
1416
1417
 
1417
- if (item.id === id) {
1418
- // eslint-disable-next-line no-continue
1419
- continue;
1420
- }
1418
+ try {
1419
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
1420
+ var item = _step2.value;
1421
1421
 
1422
- if (item.children.length) {
1423
- item.children = removeItem(item.children || [], id);
1424
- }
1422
+ if (item.id === id) {
1423
+ // eslint-disable-next-line no-continue
1424
+ continue;
1425
+ }
1425
1426
 
1426
- newItems.push(item);
1427
+ if (item.children.length) {
1428
+ item.children = removeItem(item.children, id);
1429
+ }
1430
+
1431
+ newItems.push(item);
1432
+ }
1433
+ } catch (err) {
1434
+ _iterator2.e(err);
1435
+ } finally {
1436
+ _iterator2.f();
1427
1437
  }
1428
1438
 
1429
1439
  return newItems;
1430
1440
  }
1431
1441
  function setProperty(items, id, property, setter) {
1432
- // const item = items[i];
1433
- // if (item.id === id) {
1434
- // item[property] = setter(item[property]);
1435
- // newItems.push({ ...item });
1436
- // } else {
1437
- // const { children = [] } = item;
1438
- // let newChildren = [];
1439
- // if (children.length > 0) {
1440
- // newChildren = setProperty(children, id, property, setter);
1441
- // }
1442
- // newItems.push({ ...item, children: newChildren });
1443
- // }
1444
- // }
1445
-
1446
- var _iterator = _createForOfIteratorHelper(items),
1447
- _step;
1442
+ // eslint-disable-next-line no-restricted-syntax
1443
+ var _iterator3 = _createForOfIteratorHelper(items),
1444
+ _step3;
1448
1445
 
1449
1446
  try {
1450
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
1451
- var item = _step.value;
1447
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
1448
+ var item = _step3.value;
1452
1449
 
1453
1450
  if (item.id === id) {
1454
- item[property] = setter(item[property]);
1451
+ item[property] = setter(item[property]); // eslint-disable-next-line no-continue
1452
+
1455
1453
  continue;
1456
1454
  }
1457
1455
 
1458
- var _item$children2 = item.children,
1459
- children = _item$children2 === void 0 ? [] : _item$children2;
1460
-
1461
- if (children.length) {
1462
- children = setProperty(children, id, property, setter);
1456
+ if (item.children.length) {
1457
+ item.children = setProperty(item.children, id, property, setter);
1463
1458
  }
1464
- } // console.log('fubar', items, newItems);
1465
- // return newItems;
1466
-
1459
+ }
1467
1460
  } catch (err) {
1468
- _iterator.e(err);
1461
+ _iterator3.e(err);
1469
1462
  } finally {
1470
- _iterator.f();
1463
+ _iterator3.f();
1471
1464
  }
1472
1465
 
1473
1466
  return _toConsumableArray(items);
@@ -1475,9 +1468,9 @@ function setProperty(items, id, property, setter) {
1475
1468
 
1476
1469
  function countChildren(items) {
1477
1470
  var count = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
1478
- return items.reduce(function (acc, _ref7) {
1479
- var _ref7$children = _ref7.children,
1480
- children = _ref7$children === void 0 ? [] : _ref7$children;
1471
+ return items.reduce(function (acc, _ref6) {
1472
+ var _ref6$children = _ref6.children,
1473
+ children = _ref6$children === void 0 ? [] : _ref6$children;
1481
1474
 
1482
1475
  if (children.length) {
1483
1476
  return countChildren(children, acc + 1);
@@ -1500,8 +1493,8 @@ function removeChildrenOf(items, ids) {
1500
1493
 
1501
1494
  return items.filter(function (item) {
1502
1495
  if (item.parentId && excludeParentIds.includes(item.parentId)) {
1503
- var _item$children3 = item.children,
1504
- children = _item$children3 === void 0 ? [] : _item$children3;
1496
+ var _item$children2 = item.children,
1497
+ children = _item$children2 === void 0 ? [] : _item$children2;
1505
1498
 
1506
1499
  if (children.length) {
1507
1500
  excludeParentIds.push(item.id);
@@ -1649,7 +1642,7 @@ var sortableTreeKeyboardCoordinates = function sortableTreeKeyboardCoordinates(c
1649
1642
  };
1650
1643
  };
1651
1644
 
1652
- var styles$3 = {"wrapper":"micromag-editor-sortable-tree-item-actions-wrapper","inner":"micromag-editor-sortable-tree-item-actions-inner","button":"micromag-editor-sortable-tree-item-actions-button","withChildren":"micromag-editor-sortable-tree-item-actions-withChildren","clone":"micromag-editor-sortable-tree-item-actions-clone","ghost":"micromag-editor-sortable-tree-item-actions-ghost","indicator":"micromag-editor-sortable-tree-item-actions-indicator","handle":"micromag-editor-sortable-tree-item-actions-handle","text":"micromag-editor-sortable-tree-item-actions-text","collapsedCount":"micromag-editor-sortable-tree-item-actions-collapsedCount","count":"micromag-editor-sortable-tree-item-actions-count","disableInteraction":"micromag-editor-sortable-tree-item-actions-disableInteraction","Count":"micromag-editor-sortable-tree-item-actions-Count","Text":"micromag-editor-sortable-tree-item-actions-Text","disableSelection":"micromag-editor-sortable-tree-item-actions-disableSelection","collapse":"micromag-editor-sortable-tree-item-actions-collapse","collapsed":"micromag-editor-sortable-tree-item-actions-collapsed","children":"micromag-editor-sortable-tree-item-actions-children"};
1645
+ var styles$3 = {"wrapper":"micromag-editor-sortable-sortable-tree-item-actions-wrapper","inner":"micromag-editor-sortable-sortable-tree-item-actions-inner","button":"micromag-editor-sortable-sortable-tree-item-actions-button","handle":"micromag-editor-sortable-sortable-tree-item-actions-handle","icon":"micromag-editor-sortable-sortable-tree-item-actions-icon","withChildren":"micromag-editor-sortable-sortable-tree-item-actions-withChildren","clone":"micromag-editor-sortable-sortable-tree-item-actions-clone","ghost":"micromag-editor-sortable-sortable-tree-item-actions-ghost","indicator":"micromag-editor-sortable-sortable-tree-item-actions-indicator","text":"micromag-editor-sortable-sortable-tree-item-actions-text","collapsedCount":"micromag-editor-sortable-sortable-tree-item-actions-collapsedCount","count":"micromag-editor-sortable-sortable-tree-item-actions-count","disableInteraction":"micromag-editor-sortable-sortable-tree-item-actions-disableInteraction","Count":"micromag-editor-sortable-sortable-tree-item-actions-Count","Text":"micromag-editor-sortable-sortable-tree-item-actions-Text","disableSelection":"micromag-editor-sortable-sortable-tree-item-actions-disableSelection","collapse":"micromag-editor-sortable-sortable-tree-item-actions-collapse","collapsed":"micromag-editor-sortable-sortable-tree-item-actions-collapsed","children":"micromag-editor-sortable-sortable-tree-item-actions-children"};
1653
1646
 
1654
1647
  var _excluded$4 = ["childCount", "clone", "depth", "disableSelection", "disableInteraction", "ghost", "handleProps", "indentationWidth", "indicator", "collapsed", "onCollapse", "onRemove", "onClick", "style", "value", "wrapperRef", "showId", "children"];
1655
1648
  var propTypes$a = {
@@ -1710,13 +1703,13 @@ var SortableTreeItemActions = /*#__PURE__*/forwardRef(function (_ref, ref) {
1710
1703
  indicator = _ref.indicator,
1711
1704
  collapsed = _ref.collapsed,
1712
1705
  onCollapse = _ref.onCollapse,
1713
- onRemove = _ref.onRemove,
1714
- onClick = _ref.onClick,
1715
- style = _ref.style,
1716
- value = _ref.value,
1717
- wrapperRef = _ref.wrapperRef,
1718
- showId = _ref.showId,
1719
- children = _ref.children,
1706
+ onRemove = _ref.onRemove;
1707
+ _ref.onClick;
1708
+ var style = _ref.style;
1709
+ _ref.value;
1710
+ var wrapperRef = _ref.wrapperRef;
1711
+ _ref.showId;
1712
+ var children = _ref.children,
1720
1713
  props = _objectWithoutProperties(_ref, _excluded$4);
1721
1714
 
1722
1715
  return /*#__PURE__*/React.createElement("li", Object.assign({
@@ -1736,18 +1729,9 @@ var SortableTreeItemActions = /*#__PURE__*/forwardRef(function (_ref, ref) {
1736
1729
  className: classNames([styles$3.button, styles$3.handle]),
1737
1730
  type: "button"
1738
1731
  }, handleProps), /*#__PURE__*/React.createElement(FontAwesomeIcon, {
1732
+ className: styles$3.icon,
1739
1733
  icon: faGripLines
1740
- })), /*#__PURE__*/React.createElement("button", {
1741
- className: classNames([styles$3.button, styles$3.full]),
1742
- type: "button",
1743
- onClick: onClick,
1744
- style: {
1745
- width: style.width,
1746
- height: style.height
1747
- }
1748
- }), showId ? /*#__PURE__*/React.createElement("span", {
1749
- className: styles$3.text
1750
- }, value) : null, !clone && onRemove ? /*#__PURE__*/React.createElement("button", {
1734
+ })), !clone && onRemove ? /*#__PURE__*/React.createElement("button", {
1751
1735
  type: "button",
1752
1736
  onClick: onRemove
1753
1737
  }, /*#__PURE__*/React.createElement(FontAwesomeIcon, {
@@ -1772,13 +1756,14 @@ var SortableTreeItemActions = /*#__PURE__*/forwardRef(function (_ref, ref) {
1772
1756
  SortableTreeItemActions.propTypes = propTypes$a;
1773
1757
  SortableTreeItemActions.defaultProps = defaultProps$a;
1774
1758
 
1775
- var _excluded$3 = ["id", "depth", "component", "screenValue", "style", "onCollapse", "onClick"];
1759
+ var _excluded$3 = ["id", "index", "depth", "component", "value", "style", "smallScale", "onCollapse", "onClickItem"];
1776
1760
  var propTypes$9 = {
1777
1761
  id: PropTypes.string.isRequired,
1762
+ index: PropTypes.number.isRequired,
1778
1763
  depth: PropTypes.number.isRequired,
1779
1764
  component: PropTypes.func,
1780
1765
  // eslint-disable-next-line react/forbid-prop-types
1781
- screenValue: PropTypes.object,
1766
+ value: PropTypes.object,
1782
1767
  style: PropTypes.shape({
1783
1768
  width: PropTypes.number.isRequired,
1784
1769
  height: PropTypes.number.isRequired,
@@ -1787,15 +1772,17 @@ var propTypes$9 = {
1787
1772
  transform: PropTypes.string.isRequired,
1788
1773
  scale: PropTypes.number.isRequired
1789
1774
  }),
1775
+ smallScale: PropTypes.number,
1790
1776
  onCollapse: PropTypes.func,
1791
- onClick: PropTypes.func
1777
+ onClickItem: PropTypes.func
1792
1778
  };
1793
1779
  var defaultProps$9 = {
1794
1780
  component: null,
1795
- screenValue: null,
1781
+ value: null,
1796
1782
  style: null,
1783
+ smallScale: 0.75,
1797
1784
  onCollapse: null,
1798
- onClick: null
1785
+ onClickItem: null
1799
1786
  };
1800
1787
 
1801
1788
  var animateLayoutChanges = function animateLayoutChanges(_ref) {
@@ -1806,12 +1793,14 @@ var animateLayoutChanges = function animateLayoutChanges(_ref) {
1806
1793
 
1807
1794
  var SortableTreeItem = function SortableTreeItem(_ref2) {
1808
1795
  var id = _ref2.id,
1796
+ index = _ref2.index,
1809
1797
  depth = _ref2.depth,
1810
1798
  Component = _ref2.component,
1811
- screenValue = _ref2.screenValue,
1799
+ value = _ref2.value,
1812
1800
  itemStyle = _ref2.style,
1801
+ smallScale = _ref2.smallScale,
1813
1802
  onCollapse = _ref2.onCollapse,
1814
- onClick = _ref2.onClick,
1803
+ onClickItem = _ref2.onClickItem,
1815
1804
  props = _objectWithoutProperties(_ref2, _excluded$3);
1816
1805
 
1817
1806
  var _useSortable = useSortable({
@@ -1836,17 +1825,29 @@ var SortableTreeItem = function SortableTreeItem(_ref2) {
1836
1825
  scale = _itemStyle$scale === void 0 ? 1 : _itemStyle$scale;
1837
1826
  var extraHeight = hasCollapse ? 30 : 0;
1838
1827
  var actionsStyle = {
1839
- width: depth === 0 ? scaledWidth : scaledWidth * 0.75,
1840
- height: depth === 0 ? scaledHeight + extraHeight : scaledHeight * 0.75,
1828
+ width: depth === 0 ? scaledWidth : scaledWidth * smallScale,
1829
+ height: depth === 0 ? scaledHeight + extraHeight : scaledHeight * smallScale,
1841
1830
  transform: CSS.Translate.toString(transform),
1842
1831
  transition: transition
1843
1832
  };
1844
1833
  var previewStyle = {
1845
1834
  width: itemStyle.width,
1846
1835
  height: itemStyle.height,
1847
- transform: depth === 0 ? itemStyle.transform : "scale(".concat(scale * 0.75, ", ").concat(scale * 0.75, ")"),
1848
- transformOrigin: 'top left'
1836
+ transform: depth === 0 ? itemStyle.transform : "scale(".concat(scale * smallScale, ", ").concat(scale * smallScale, ")")
1849
1837
  };
1838
+
1839
+ var _ref3 = listeners || {},
1840
+ onPointerDown = _ref3.onPointerDown;
1841
+
1842
+ var onClickAction = useCallback(function (e) {
1843
+ if (onClickItem !== null) {
1844
+ onClickItem(value, index);
1845
+ }
1846
+
1847
+ if (onPointerDown !== null) {
1848
+ onPointerDown(e);
1849
+ }
1850
+ }, [value, index, onClickItem, onPointerDown]);
1850
1851
  return /*#__PURE__*/React.createElement(SortableTreeItemActions, Object.assign({
1851
1852
  ref: setDraggableNodeRef,
1852
1853
  wrapperRef: setDroppableNodeRef,
@@ -1855,10 +1856,11 @@ var SortableTreeItem = function SortableTreeItem(_ref2) {
1855
1856
  ghost: isDragging,
1856
1857
  disableSelection: iOS,
1857
1858
  disableInteraction: isSorting,
1858
- handleProps: _objectSpread(_objectSpread({}, attributes), listeners),
1859
- onCollapse: onCollapse,
1860
- onClick: onClick
1861
- }, props), Component !== null ? /*#__PURE__*/React.createElement(Component, Object.assign({}, screenValue, {
1859
+ handleProps: _objectSpread(_objectSpread(_objectSpread({}, attributes), listeners), {}, {
1860
+ onPointerDown: onClickAction
1861
+ }),
1862
+ onCollapse: onCollapse
1863
+ }, props), Component !== null ? /*#__PURE__*/React.createElement(Component, Object.assign({}, value, {
1862
1864
  previewStyle: previewStyle
1863
1865
  })) : null);
1864
1866
  };
@@ -1978,7 +1980,8 @@ var SortableTree = function SortableTree(_ref2) {
1978
1980
  var flattenedTree = flattenTree(items); // console.log('yo', items, flattenedTree);
1979
1981
 
1980
1982
  var collapsedItems = flattenedTree.reduce(function (acc, _ref3) {
1981
- var children = _ref3.children,
1983
+ var _ref3$children = _ref3.children,
1984
+ children = _ref3$children === void 0 ? [] : _ref3$children,
1982
1985
  collapsed = _ref3.collapsed,
1983
1986
  id = _ref3.id;
1984
1987
  return collapsed && children.length ? [].concat(_toConsumableArray(acc), [id]) : acc;
@@ -2035,11 +2038,14 @@ var SortableTree = function SortableTree(_ref2) {
2035
2038
  _ref6$children = _ref6.children,
2036
2039
  children = _ref6$children === void 0 ? [] : _ref6$children,
2037
2040
  _ref6$parentId = _ref6.parentId,
2038
- parentId = _ref6$parentId === void 0 ? null : _ref6$parentId;
2041
+ parentId = _ref6$parentId === void 0 ? null : _ref6$parentId,
2042
+ _ref6$collapsed = _ref6.collapsed,
2043
+ collapsed = _ref6$collapsed === void 0 ? false : _ref6$collapsed;
2039
2044
  return {
2040
2045
  id: itemId,
2041
2046
  props: _objectSpread(_objectSpread({}, (children || []).length > 0 ? {
2042
2047
  group: {
2048
+ collapsed: collapsed,
2043
2049
  mergeNavItems: true
2044
2050
  }
2045
2051
  } : {
@@ -2059,11 +2065,12 @@ var SortableTree = function SortableTree(_ref2) {
2059
2065
  return "Moving was cancelled. ".concat(id, " was dropped in its original position.");
2060
2066
  }
2061
2067
  };
2062
- }, [flattenedItems, onChange]); // Note: this is quite brutal for perf
2063
-
2064
- useEffect(function () {// setItems(defaultItems);
2065
- }, [defaultItems, setItems]); // console.log('render: current id', activeId);
2068
+ }, [flattenedItems, onChange]); // Initial tree setup from list
2066
2069
 
2070
+ useEffect(function () {
2071
+ // console.log('fuck off');
2072
+ setItems(buildTree(defaultItems));
2073
+ }, []);
2067
2074
  return /*#__PURE__*/React.createElement(DndContext, {
2068
2075
  announcements: announcements,
2069
2076
  sensors: sensors,
@@ -2083,12 +2090,11 @@ var SortableTree = function SortableTree(_ref2) {
2083
2090
  children = _ref7$children === void 0 ? [] : _ref7$children,
2084
2091
  collapsed = _ref7.collapsed,
2085
2092
  depth = _ref7.depth,
2086
- _ref7$screenValue = _ref7.screenValue,
2087
- screenValue = _ref7$screenValue === void 0 ? null : _ref7$screenValue;
2093
+ _ref7$value = _ref7.value,
2094
+ value = _ref7$value === void 0 ? null : _ref7$value;
2088
2095
  return /*#__PURE__*/React.createElement(SortableTreeItem, {
2089
2096
  key: id,
2090
2097
  id: id,
2091
- value: id,
2092
2098
  depth: id === activeId && projected ? projected.depth : depth,
2093
2099
  indentationWidth: indentationWidth,
2094
2100
  indicator: indicator,
@@ -2101,15 +2107,10 @@ var SortableTree = function SortableTree(_ref2) {
2101
2107
  } : undefined,
2102
2108
  childCount: getChildCount(items, id),
2103
2109
  component: component,
2104
- screenValue: screenValue,
2110
+ value: value,
2105
2111
  style: itemStyle,
2106
- onClick: function onClick() {
2107
- if (onClickItem !== null) {
2108
- onClickItem({
2109
- id: id
2110
- }, idx);
2111
- }
2112
- }
2112
+ onClickItem: onClickItem,
2113
+ index: idx
2113
2114
  });
2114
2115
  }), /*#__PURE__*/createPortal( /*#__PURE__*/React.createElement(DragOverlay, {
2115
2116
  dropAnimation: dropAnimation,
@@ -2119,19 +2120,23 @@ var SortableTree = function SortableTree(_ref2) {
2119
2120
  depth: activeItem.depth,
2120
2121
  clone: true,
2121
2122
  childCount: getChildCount(items, activeId) + 1,
2122
- value: activeId,
2123
2123
  indentationWidth: indentationWidth,
2124
2124
  component: component,
2125
- screenValue: activeItem === null || activeItem === void 0 ? void 0 : activeItem.screenValue,
2125
+ value: activeItem === null || activeItem === void 0 ? void 0 : activeItem.value,
2126
+ onClickItem: onClickItem,
2127
+ index: flattenedItems.findIndex(function (_ref8) {
2128
+ var id = _ref8.id;
2129
+ return activeId === id;
2130
+ }),
2126
2131
  style: itemStyle
2127
2132
  }) : null), document.body)));
2128
2133
 
2129
- function handleDragStart(_ref8) {
2130
- var newActiveId = _ref8.active.id;
2134
+ function handleDragStart(_ref9) {
2135
+ var newActiveId = _ref9.active.id;
2131
2136
  setActiveId(newActiveId);
2132
2137
  setOverId(newActiveId);
2133
- var newActiveItem = flattenedItems.find(function (_ref9) {
2134
- var id = _ref9.id;
2138
+ var newActiveItem = flattenedItems.find(function (_ref10) {
2139
+ var id = _ref10.id;
2135
2140
  return id === newActiveId;
2136
2141
  });
2137
2142
 
@@ -2145,15 +2150,15 @@ var SortableTree = function SortableTree(_ref2) {
2145
2150
  document.body.style.setProperty('cursor', 'grabbing');
2146
2151
  }
2147
2152
 
2148
- function handleDragMove(_ref10) {
2149
- var delta = _ref10.delta;
2153
+ function handleDragMove(_ref11) {
2154
+ var delta = _ref11.delta;
2150
2155
  setOffsetLeft(delta.x);
2151
2156
  }
2152
2157
 
2153
- function handleDragOver(_ref11) {
2158
+ function handleDragOver(_ref12) {
2154
2159
  var _over$id;
2155
2160
 
2156
- var over = _ref11.over;
2161
+ var over = _ref12.over;
2157
2162
  setOverId((_over$id = over === null || over === void 0 ? void 0 : over.id) !== null && _over$id !== void 0 ? _over$id : null);
2158
2163
  }
2159
2164
 
@@ -2165,24 +2170,44 @@ var SortableTree = function SortableTree(_ref2) {
2165
2170
  document.body.style.setProperty('cursor', '');
2166
2171
  }
2167
2172
 
2168
- function handleDragEnd(_ref12) {
2169
- var active = _ref12.active,
2170
- over = _ref12.over;
2173
+ function handleDragEnd(_ref13) {
2174
+ var active = _ref13.active,
2175
+ over = _ref13.over;
2171
2176
  resetState();
2172
2177
 
2173
2178
  if (projected && over) {
2174
2179
  var depth = projected.depth,
2175
2180
  parentId = projected.parentId;
2176
2181
  var clonedItems = JSON.parse(JSON.stringify(flattenTree(items)));
2177
- var overIndex = clonedItems.findIndex(function (_ref13) {
2178
- var id = _ref13.id;
2182
+ var overIndex = clonedItems.findIndex(function (_ref14) {
2183
+ var id = _ref14.id;
2179
2184
  return id === over.id;
2180
2185
  });
2181
- var activeIndex = clonedItems.findIndex(function (_ref14) {
2182
- var id = _ref14.id;
2186
+ var activeIndex = clonedItems.findIndex(function (_ref15) {
2187
+ var id = _ref15.id;
2183
2188
  return id === active.id;
2184
2189
  });
2185
2190
  var activeTreeItem = clonedItems[activeIndex];
2191
+ var maxDepth = getMaxDepth(activeTreeItem); // Un-merge and flatten
2192
+
2193
+ if (depth > 0 && depth >= maxDepth && (activeTreeItem === null || activeTreeItem === void 0 ? void 0 : activeTreeItem.children) !== null && activeTreeItem.children.length > 0) {
2194
+ var _loop = function _loop(i) {
2195
+ var childId = activeTreeItem.children[i].id;
2196
+ var childIndex = clonedItems.findIndex(function (_ref16) {
2197
+ var id = _ref16.id;
2198
+ return id === childId;
2199
+ });
2200
+ clonedItems[childIndex].parentId = parentId;
2201
+ clonedItems[childIndex].depth = depth;
2202
+ };
2203
+
2204
+ for (var i = 0; i < activeTreeItem.children.length; i += 1) {
2205
+ _loop(i);
2206
+ }
2207
+
2208
+ activeTreeItem.children = [];
2209
+ }
2210
+
2186
2211
  clonedItems[activeIndex] = _objectSpread(_objectSpread({}, activeTreeItem), {}, {
2187
2212
  depth: depth,
2188
2213
  parentId: parentId
@@ -2225,12 +2250,12 @@ var SortableTree = function SortableTree(_ref2) {
2225
2250
  }
2226
2251
 
2227
2252
  var clonedItems = JSON.parse(JSON.stringify(flattenTree(items)));
2228
- var overIndex = clonedItems.findIndex(function (_ref15) {
2229
- var id = _ref15.id;
2253
+ var overIndex = clonedItems.findIndex(function (_ref17) {
2254
+ var id = _ref17.id;
2230
2255
  return id === currentOverId;
2231
2256
  });
2232
- var activeIndex = clonedItems.findIndex(function (_ref16) {
2233
- var id = _ref16.id;
2257
+ var activeIndex = clonedItems.findIndex(function (_ref18) {
2258
+ var id = _ref18.id;
2234
2259
  return id === currentActiveId;
2235
2260
  });
2236
2261
  var sortedItems = arrayMove(clonedItems, activeIndex, overIndex);
@@ -2247,17 +2272,17 @@ var SortableTree = function SortableTree(_ref2) {
2247
2272
  } else {
2248
2273
  var previousSibling = previousItem;
2249
2274
 
2250
- var _loop = function _loop() {
2275
+ var _loop2 = function _loop2() {
2251
2276
  var _previousSibling = previousSibling,
2252
2277
  parentId = _previousSibling.parentId;
2253
- previousSibling = sortedItems.find(function (_ref17) {
2254
- var id = _ref17.id;
2278
+ previousSibling = sortedItems.find(function (_ref19) {
2279
+ var id = _ref19.id;
2255
2280
  return id === parentId;
2256
2281
  });
2257
2282
  };
2258
2283
 
2259
2284
  while (previousSibling && projected.depth < previousSibling.depth) {
2260
- _loop();
2285
+ _loop2();
2261
2286
  }
2262
2287
 
2263
2288
  if (previousSibling) {
@@ -2273,7 +2298,7 @@ var SortableTree = function SortableTree(_ref2) {
2273
2298
  SortableTree.propTypes = propTypes$8;
2274
2299
  SortableTree.defaultProps = defaultProps$8;
2275
2300
 
2276
- var _excluded$2 = ["className", "screen", "type"],
2301
+ var _excluded$2 = ["className", "screen", "type", "onClick"],
2277
2302
  _excluded2 = ["id", "screen"];
2278
2303
  var propTypes$7 = {
2279
2304
  items: PropTypes$1.menuItems,
@@ -2311,7 +2336,7 @@ var defaultProps$7 = {
2311
2336
  };
2312
2337
 
2313
2338
  var ScreensMenu = function ScreensMenu(_ref) {
2314
- var _ref9;
2339
+ var _ref10;
2315
2340
 
2316
2341
  var items = _ref.items,
2317
2342
  withPreview = _ref.withPreview,
@@ -2384,6 +2409,8 @@ var ScreensMenu = function ScreensMenu(_ref) {
2384
2409
  itemCustomClassName = _ref4$className === void 0 ? null : _ref4$className,
2385
2410
  screen = _ref4.screen,
2386
2411
  type = _ref4.type,
2412
+ _ref4$onClick = _ref4.onClick,
2413
+ onClick = _ref4$onClick === void 0 ? null : _ref4$onClick,
2387
2414
  item = _objectWithoutProperties(_ref4, _excluded$2);
2388
2415
 
2389
2416
  return /*#__PURE__*/React.createElement("li", {
@@ -2400,44 +2427,46 @@ var ScreensMenu = function ScreensMenu(_ref) {
2400
2427
  previewStyle: previewStyle,
2401
2428
  withPreview: withPreview,
2402
2429
  withPlaceholder: withPlaceholder,
2403
- onClick: onClickItem
2430
+ onClick: onClick,
2431
+ onClickItem: onClickItem
2404
2432
  }), settings !== null ? /*#__PURE__*/React.createElement("div", {
2405
2433
  className: classNames([_defineProperty({}, settingsClassName, settingsClassName !== null), styles$6.settings, 'p-2'])
2406
2434
  }, isFunction(settings) ? settings(index) : settings) : null);
2407
2435
  }) : [];
2408
2436
  var sortableItems = useMemo(function () {
2409
- return isTree ? items.reduce(function (acc, _ref7) {
2437
+ return isTree ? items.map(function (_ref7) {
2410
2438
  var id = _ref7.id,
2411
2439
  _ref7$screen = _ref7.screen,
2412
2440
  screen = _ref7$screen === void 0 ? {} : _ref7$screen,
2413
2441
  props = _objectWithoutProperties(_ref7, _excluded2);
2414
2442
 
2415
2443
  var _screen$parentId = screen.parentId,
2416
- parentId = _screen$parentId === void 0 ? null : _screen$parentId; // console.log('hey', id, screen, parentId, props);
2417
- // const children =
2418
- // items.filter(({ screen: { parentId: cpid = null } }) => cpid === id) ||
2419
- // [];
2420
- // console.log('children', children);
2444
+ parentId = _screen$parentId === void 0 ? null : _screen$parentId,
2445
+ _screen$group = screen.group,
2446
+ group = _screen$group === void 0 ? {} : _screen$group;
2447
+
2448
+ var _ref8 = group || {},
2449
+ _ref8$collapsed = _ref8.collapsed,
2450
+ collapsed = _ref8$collapsed === void 0 ? true : _ref8$collapsed;
2421
2451
 
2422
- acc.push(_objectSpread({
2452
+ return _objectSpread({
2423
2453
  id: id,
2424
2454
  parentId: parentId,
2425
- screenValue: {
2455
+ collapsed: collapsed,
2456
+ value: {
2426
2457
  id: id,
2427
2458
  screen: screen
2428
2459
  }
2429
- }, props));
2430
- return acc;
2431
- }, []) : items.map(function (_ref8) {
2432
- var id = _ref8.id;
2460
+ }, props);
2461
+ }, []) : items.map(function (_ref9) {
2462
+ var id = _ref9.id;
2433
2463
  return {
2434
2464
  id: id
2435
2465
  };
2436
2466
  });
2437
- }, [items, isTree]); // console.log('screens menu items/sitems', items, sortableItems);
2438
-
2467
+ }, [items, isTree]);
2439
2468
  return /*#__PURE__*/React.createElement("div", {
2440
- className: classNames([styles$6.container, (_ref9 = {}, _defineProperty(_ref9, styles$6.noWrap, noWrap), _defineProperty(_ref9, styles$6.isVertical, isVertical), _defineProperty(_ref9, styles$6.isTree, isTree), _defineProperty(_ref9, styles$6.withPlaceholder, withPlaceholder), _defineProperty(_ref9, className, className), _ref9)]),
2469
+ className: classNames([styles$6.container, (_ref10 = {}, _defineProperty(_ref10, styles$6.noWrap, noWrap), _defineProperty(_ref10, styles$6.isVertical, isVertical), _defineProperty(_ref10, styles$6.isTree, isTree), _defineProperty(_ref10, styles$6.withPlaceholder, withPlaceholder), _defineProperty(_ref10, className, className), _ref10)]),
2441
2470
  ref: columnRef
2442
2471
  }, isTree && !sortable ? /*#__PURE__*/React.createElement(SortableTree, {
2443
2472
  items: sortableItems,
@@ -3055,7 +3084,8 @@ var Editor = function Editor(_ref) {
3055
3084
  onChange: onStoryChange,
3056
3085
  onClickScreen: onClickScreen,
3057
3086
  isVertical: !isMobile,
3058
- className: styles$f.inner
3087
+ className: styles$f.inner,
3088
+ isTree: true
3059
3089
  })), /*#__PURE__*/React.createElement("div", {
3060
3090
  className: classNames([styles$f.center, _defineProperty({}, styles$f.visible, !isMobile || mobileView === 'preview')])
3061
3091
  }, /*#__PURE__*/React.createElement(EditorPreview, {