@next-core/editor-bricks-helper 0.37.8 → 0.38.0

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/dist/index.esm.js CHANGED
@@ -713,46 +713,6 @@ class BuilderDataManager {
713
713
  _defineProperty(this, "localJsonStorage", new JsonStorage(localStorage));
714
714
 
715
715
  _defineProperty(this, "outlineDisabledNodes", new Set((_this$localJsonStorag = this.localJsonStorage.getItem(storageKeyOfOutlineDisabledNodes)) !== null && _this$localJsonStorag !== void 0 ? _this$localJsonStorag : []));
716
-
717
- _defineProperty(this, "runAddNodeAction", detail => {
718
- var {
719
- rootId,
720
- nodes,
721
- edges,
722
- wrapperNode
723
- } = this.data;
724
- var {
725
- nodeUid,
726
- parentUid,
727
- nodeUids,
728
- nodeData
729
- } = detail;
730
- var {
731
- nodes: addNodes,
732
- edges: addEdges
733
- } = getAppendingNodesAndEdges(omit(nodeData, ["parent"]), nodeUid, this.templateSourceMap, this.getStoryList());
734
- var newNodes = nodes.concat(addNodes);
735
- var newEdges = edges.concat({
736
- parent: parentUid,
737
- child: nodeUid,
738
- mountPoint: nodeData.mountPoint,
739
- sort: undefined,
740
- $$isTemplateDelegated: isParentExpandableTemplate(nodes, parentUid)
741
- }).concat(addEdges);
742
- var newData = {
743
- rootId,
744
- nodes: newNodes,
745
- edges: newEdges,
746
- wrapperNode
747
- };
748
- this.data = _objectSpread(_objectSpread({}, newData), {}, {
749
- edges: reorderBuilderEdges(newData, {
750
- parentUid,
751
- nodeUids
752
- })
753
- });
754
- this.triggerDataChange();
755
- });
756
716
  }
757
717
 
758
718
  getData() {
@@ -836,6 +796,46 @@ class BuilderDataManager {
836
796
  this.eventTarget.dispatchEvent(new CustomEvent(BuilderInternalEventType.DATA_CHANGE));
837
797
  }
838
798
 
799
+ runAddNodeAction(detail) {
800
+ var {
801
+ rootId,
802
+ nodes,
803
+ edges,
804
+ wrapperNode
805
+ } = this.data;
806
+ var {
807
+ nodeUid,
808
+ parentUid,
809
+ nodeUids,
810
+ nodeData
811
+ } = detail;
812
+ var {
813
+ nodes: addNodes,
814
+ edges: addEdges
815
+ } = getAppendingNodesAndEdges(omit(nodeData, ["parent"]), nodeUid, this.templateSourceMap, this.getStoryList());
816
+ var newNodes = nodes.concat(addNodes);
817
+ var newEdges = edges.concat({
818
+ parent: parentUid,
819
+ child: nodeUid,
820
+ mountPoint: nodeData.mountPoint,
821
+ sort: undefined,
822
+ $$isTemplateDelegated: isParentExpandableTemplate(nodes, parentUid)
823
+ }).concat(addEdges);
824
+ var newData = {
825
+ rootId,
826
+ nodes: newNodes,
827
+ edges: newEdges,
828
+ wrapperNode
829
+ };
830
+ this.data = _objectSpread(_objectSpread({}, newData), {}, {
831
+ edges: reorderBuilderEdges(newData, {
832
+ parentUid,
833
+ nodeUids
834
+ })
835
+ });
836
+ this.triggerDataChange();
837
+ }
838
+
839
839
  updateBrick(detail) {
840
840
  this.data = deleteNodeFromTree(detail.nodeUid, this.data);
841
841
  this.runAddNodeAction(detail);
@@ -982,6 +982,11 @@ class BuilderDataManager {
982
982
  };
983
983
  this.triggerDataChange();
984
984
  }
985
+ /**
986
+ * Move node anywhere by drag-n-drop.
987
+ * @deprecated use `moveNode` instead.
988
+ */
989
+
985
990
 
986
991
  nodeMove(detail) {
987
992
  var {
@@ -1020,6 +1025,81 @@ class BuilderDataManager {
1020
1025
  detail
1021
1026
  }));
1022
1027
  }
1028
+ /**
1029
+ * Move node up or down.
1030
+ */
1031
+
1032
+
1033
+ moveNode(_ref2, direction) {
1034
+ var {
1035
+ $$uid: nodeUid
1036
+ } = _ref2;
1037
+ var {
1038
+ parent: parentUid,
1039
+ mountPoint
1040
+ } = this.data.edges.find(edge => edge.child === nodeUid);
1041
+ var {
1042
+ relatedEdges,
1043
+ mountPoints
1044
+ } = getRelatedEdgesAndMountPoint(this.data.edges, parentUid);
1045
+ /** Edges of the same mount-point */
1046
+
1047
+ var siblingEdges = relatedEdges.filter(edge => edge.mountPoint === mountPoint);
1048
+ var index = siblingEdges.findIndex(edge => edge.child === nodeUid);
1049
+ var orderedSiblingEdges = moveItemInList(siblingEdges, index, direction);
1050
+
1051
+ if (!orderedSiblingEdges) {
1052
+ return;
1053
+ }
1054
+
1055
+ var orderedEdges = sortBy(relatedEdges, edge => mountPoints.indexOf(edge.mountPoint), edge => orderedSiblingEdges.indexOf(edge));
1056
+ this.reorder(parentUid, orderedEdges);
1057
+ }
1058
+ /**
1059
+ * Move mount-point up or down.
1060
+ */
1061
+
1062
+
1063
+ moveMountPoint(_ref3, mountPoint, direction) {
1064
+ var {
1065
+ $$uid: parentUid
1066
+ } = _ref3;
1067
+ var {
1068
+ relatedEdges,
1069
+ mountPoints
1070
+ } = getRelatedEdgesAndMountPoint(this.data.edges, parentUid);
1071
+ var index = mountPoints.indexOf(mountPoint);
1072
+ var orderedMountPoints = moveItemInList(mountPoints, index, direction);
1073
+
1074
+ if (!orderedMountPoints) {
1075
+ return;
1076
+ }
1077
+
1078
+ var orderedEdges = sortBy(relatedEdges, edge => orderedMountPoints.indexOf(edge.mountPoint), "sort");
1079
+ this.reorder(parentUid, orderedEdges);
1080
+ }
1081
+
1082
+ reorder(parentUid, orderedEdges) {
1083
+ var {
1084
+ nodes
1085
+ } = this.data;
1086
+ var childUids = orderedEdges.map(edge => edge.child);
1087
+ this.data = _objectSpread(_objectSpread({}, this.data), {}, {
1088
+ edges: reorderBuilderEdges(this.data, {
1089
+ parentUid,
1090
+ nodeUids: childUids
1091
+ })
1092
+ });
1093
+ this.triggerDataChange();
1094
+ var childIds = childUids.map(uid => nodes.find(node => node.$$uid === uid)).map(node => node.id);
1095
+ this.eventTarget.dispatchEvent(new CustomEvent(BuilderInternalEventType.NODE_REORDER, {
1096
+ detail: {
1097
+ nodeUids: childUids,
1098
+ parentUid,
1099
+ nodeIds: childIds
1100
+ }
1101
+ }));
1102
+ }
1023
1103
 
1024
1104
  contextUpdated(detail) {
1025
1105
  var {
@@ -1218,6 +1298,41 @@ class BuilderDataManager {
1218
1298
 
1219
1299
  }
1220
1300
 
1301
+ function getRelatedEdgesAndMountPoint(edges, parentUid) {
1302
+ var relatedEdges = sortBy(edges.filter(edge => edge.parent === parentUid && !edge.$$isTemplateExpanded), "sort");
1303
+ var mountPointSet = new Set();
1304
+
1305
+ for (var edge of relatedEdges) {
1306
+ mountPointSet.add(edge.mountPoint);
1307
+ }
1308
+
1309
+ var mountPoints = Array.from(mountPointSet);
1310
+ return {
1311
+ relatedEdges,
1312
+ mountPoints
1313
+ };
1314
+ }
1315
+
1316
+ function moveItemInList(list, index, direction) {
1317
+ var upperIndex;
1318
+
1319
+ if (direction === "up") {
1320
+ if (index <= 0) {
1321
+ return;
1322
+ }
1323
+
1324
+ upperIndex = index - 1;
1325
+ } else {
1326
+ if (index === -1 || index >= list.length - 1) {
1327
+ return;
1328
+ }
1329
+
1330
+ upperIndex = index;
1331
+ }
1332
+
1333
+ return [...list.slice(0, upperIndex), list[upperIndex + 1], list[upperIndex], ...list.slice(upperIndex + 2)];
1334
+ }
1335
+
1221
1336
  var BuilderContext = /*#__PURE__*/React.createContext({});
1222
1337
  function createBuilderContext() {
1223
1338
  return {