@next-core/editor-bricks-helper 0.37.8 → 0.38.2
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/CHANGELOG.md +27 -0
- package/dist/index.bundle.js +155 -40
- package/dist/index.bundle.js.map +1 -1
- package/dist/index.esm.js +155 -40
- package/dist/index.esm.js.map +1 -1
- package/dist/types/internal/BuilderDataManager.d.ts +14 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,33 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [0.38.2](https://github.com/easyops-cn/next-core/compare/@next-core/editor-bricks-helper@0.38.1...@next-core/editor-bricks-helper@0.38.2) (2022-03-29)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @next-core/editor-bricks-helper
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [0.38.1](https://github.com/easyops-cn/next-core/compare/@next-core/editor-bricks-helper@0.38.0...@next-core/editor-bricks-helper@0.38.1) (2022-03-28)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @next-core/editor-bricks-helper
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# [0.38.0](https://github.com/easyops-cn/next-core/compare/@next-core/editor-bricks-helper@0.37.8...@next-core/editor-bricks-helper@0.38.0) (2022-03-25)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Features
|
|
26
|
+
|
|
27
|
+
* move node up or down ([bf45965](https://github.com/easyops-cn/next-core/commit/bf45965d3a59a7b952e956cc3b84e9502fba76e5))
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
6
33
|
## [0.37.8](https://github.com/easyops-cn/next-core/compare/@next-core/editor-bricks-helper@0.37.7...@next-core/editor-bricks-helper@0.37.8) (2022-03-24)
|
|
7
34
|
|
|
8
35
|
**Note:** Version bump only for package @next-core/editor-bricks-helper
|
package/dist/index.bundle.js
CHANGED
|
@@ -715,46 +715,6 @@
|
|
|
715
715
|
_defineProperty__default["default"](this, "localJsonStorage", new brickUtils.JsonStorage(localStorage));
|
|
716
716
|
|
|
717
717
|
_defineProperty__default["default"](this, "outlineDisabledNodes", new Set((_this$localJsonStorag = this.localJsonStorage.getItem(storageKeyOfOutlineDisabledNodes)) !== null && _this$localJsonStorag !== void 0 ? _this$localJsonStorag : []));
|
|
718
|
-
|
|
719
|
-
_defineProperty__default["default"](this, "runAddNodeAction", detail => {
|
|
720
|
-
var {
|
|
721
|
-
rootId,
|
|
722
|
-
nodes,
|
|
723
|
-
edges,
|
|
724
|
-
wrapperNode
|
|
725
|
-
} = this.data;
|
|
726
|
-
var {
|
|
727
|
-
nodeUid,
|
|
728
|
-
parentUid,
|
|
729
|
-
nodeUids,
|
|
730
|
-
nodeData
|
|
731
|
-
} = detail;
|
|
732
|
-
var {
|
|
733
|
-
nodes: addNodes,
|
|
734
|
-
edges: addEdges
|
|
735
|
-
} = getAppendingNodesAndEdges(lodash.omit(nodeData, ["parent"]), nodeUid, this.templateSourceMap, this.getStoryList());
|
|
736
|
-
var newNodes = nodes.concat(addNodes);
|
|
737
|
-
var newEdges = edges.concat({
|
|
738
|
-
parent: parentUid,
|
|
739
|
-
child: nodeUid,
|
|
740
|
-
mountPoint: nodeData.mountPoint,
|
|
741
|
-
sort: undefined,
|
|
742
|
-
$$isTemplateDelegated: isParentExpandableTemplate(nodes, parentUid)
|
|
743
|
-
}).concat(addEdges);
|
|
744
|
-
var newData = {
|
|
745
|
-
rootId,
|
|
746
|
-
nodes: newNodes,
|
|
747
|
-
edges: newEdges,
|
|
748
|
-
wrapperNode
|
|
749
|
-
};
|
|
750
|
-
this.data = _objectSpread__default["default"](_objectSpread__default["default"]({}, newData), {}, {
|
|
751
|
-
edges: reorderBuilderEdges(newData, {
|
|
752
|
-
parentUid,
|
|
753
|
-
nodeUids
|
|
754
|
-
})
|
|
755
|
-
});
|
|
756
|
-
this.triggerDataChange();
|
|
757
|
-
});
|
|
758
718
|
}
|
|
759
719
|
|
|
760
720
|
getData() {
|
|
@@ -838,6 +798,46 @@
|
|
|
838
798
|
this.eventTarget.dispatchEvent(new CustomEvent(BuilderInternalEventType.DATA_CHANGE));
|
|
839
799
|
}
|
|
840
800
|
|
|
801
|
+
runAddNodeAction(detail) {
|
|
802
|
+
var {
|
|
803
|
+
rootId,
|
|
804
|
+
nodes,
|
|
805
|
+
edges,
|
|
806
|
+
wrapperNode
|
|
807
|
+
} = this.data;
|
|
808
|
+
var {
|
|
809
|
+
nodeUid,
|
|
810
|
+
parentUid,
|
|
811
|
+
nodeUids,
|
|
812
|
+
nodeData
|
|
813
|
+
} = detail;
|
|
814
|
+
var {
|
|
815
|
+
nodes: addNodes,
|
|
816
|
+
edges: addEdges
|
|
817
|
+
} = getAppendingNodesAndEdges(lodash.omit(nodeData, ["parent"]), nodeUid, this.templateSourceMap, this.getStoryList());
|
|
818
|
+
var newNodes = nodes.concat(addNodes);
|
|
819
|
+
var newEdges = edges.concat({
|
|
820
|
+
parent: parentUid,
|
|
821
|
+
child: nodeUid,
|
|
822
|
+
mountPoint: nodeData.mountPoint,
|
|
823
|
+
sort: undefined,
|
|
824
|
+
$$isTemplateDelegated: isParentExpandableTemplate(nodes, parentUid)
|
|
825
|
+
}).concat(addEdges);
|
|
826
|
+
var newData = {
|
|
827
|
+
rootId,
|
|
828
|
+
nodes: newNodes,
|
|
829
|
+
edges: newEdges,
|
|
830
|
+
wrapperNode
|
|
831
|
+
};
|
|
832
|
+
this.data = _objectSpread__default["default"](_objectSpread__default["default"]({}, newData), {}, {
|
|
833
|
+
edges: reorderBuilderEdges(newData, {
|
|
834
|
+
parentUid,
|
|
835
|
+
nodeUids
|
|
836
|
+
})
|
|
837
|
+
});
|
|
838
|
+
this.triggerDataChange();
|
|
839
|
+
}
|
|
840
|
+
|
|
841
841
|
updateBrick(detail) {
|
|
842
842
|
this.data = deleteNodeFromTree(detail.nodeUid, this.data);
|
|
843
843
|
this.runAddNodeAction(detail);
|
|
@@ -984,6 +984,11 @@
|
|
|
984
984
|
};
|
|
985
985
|
this.triggerDataChange();
|
|
986
986
|
}
|
|
987
|
+
/**
|
|
988
|
+
* Move node anywhere by drag-n-drop.
|
|
989
|
+
* @deprecated use `moveNode` instead.
|
|
990
|
+
*/
|
|
991
|
+
|
|
987
992
|
|
|
988
993
|
nodeMove(detail) {
|
|
989
994
|
var {
|
|
@@ -1022,6 +1027,81 @@
|
|
|
1022
1027
|
detail
|
|
1023
1028
|
}));
|
|
1024
1029
|
}
|
|
1030
|
+
/**
|
|
1031
|
+
* Move node up or down.
|
|
1032
|
+
*/
|
|
1033
|
+
|
|
1034
|
+
|
|
1035
|
+
moveNode(_ref2, direction) {
|
|
1036
|
+
var {
|
|
1037
|
+
$$uid: nodeUid
|
|
1038
|
+
} = _ref2;
|
|
1039
|
+
var {
|
|
1040
|
+
parent: parentUid,
|
|
1041
|
+
mountPoint
|
|
1042
|
+
} = this.data.edges.find(edge => edge.child === nodeUid);
|
|
1043
|
+
var {
|
|
1044
|
+
relatedEdges,
|
|
1045
|
+
mountPoints
|
|
1046
|
+
} = getRelatedEdgesAndMountPoint(this.data.edges, parentUid);
|
|
1047
|
+
/** Edges of the same mount-point */
|
|
1048
|
+
|
|
1049
|
+
var siblingEdges = relatedEdges.filter(edge => edge.mountPoint === mountPoint);
|
|
1050
|
+
var index = siblingEdges.findIndex(edge => edge.child === nodeUid);
|
|
1051
|
+
var orderedSiblingEdges = moveItemInList(siblingEdges, index, direction);
|
|
1052
|
+
|
|
1053
|
+
if (!orderedSiblingEdges) {
|
|
1054
|
+
return;
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
var orderedEdges = lodash.sortBy(relatedEdges, edge => mountPoints.indexOf(edge.mountPoint), edge => orderedSiblingEdges.indexOf(edge));
|
|
1058
|
+
this.reorder(parentUid, orderedEdges);
|
|
1059
|
+
}
|
|
1060
|
+
/**
|
|
1061
|
+
* Move mount-point up or down.
|
|
1062
|
+
*/
|
|
1063
|
+
|
|
1064
|
+
|
|
1065
|
+
moveMountPoint(_ref3, mountPoint, direction) {
|
|
1066
|
+
var {
|
|
1067
|
+
$$uid: parentUid
|
|
1068
|
+
} = _ref3;
|
|
1069
|
+
var {
|
|
1070
|
+
relatedEdges,
|
|
1071
|
+
mountPoints
|
|
1072
|
+
} = getRelatedEdgesAndMountPoint(this.data.edges, parentUid);
|
|
1073
|
+
var index = mountPoints.indexOf(mountPoint);
|
|
1074
|
+
var orderedMountPoints = moveItemInList(mountPoints, index, direction);
|
|
1075
|
+
|
|
1076
|
+
if (!orderedMountPoints) {
|
|
1077
|
+
return;
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
var orderedEdges = lodash.sortBy(relatedEdges, edge => orderedMountPoints.indexOf(edge.mountPoint), "sort");
|
|
1081
|
+
this.reorder(parentUid, orderedEdges);
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
reorder(parentUid, orderedEdges) {
|
|
1085
|
+
var {
|
|
1086
|
+
nodes
|
|
1087
|
+
} = this.data;
|
|
1088
|
+
var childUids = orderedEdges.map(edge => edge.child);
|
|
1089
|
+
this.data = _objectSpread__default["default"](_objectSpread__default["default"]({}, this.data), {}, {
|
|
1090
|
+
edges: reorderBuilderEdges(this.data, {
|
|
1091
|
+
parentUid,
|
|
1092
|
+
nodeUids: childUids
|
|
1093
|
+
})
|
|
1094
|
+
});
|
|
1095
|
+
this.triggerDataChange();
|
|
1096
|
+
var childIds = childUids.map(uid => nodes.find(node => node.$$uid === uid)).map(node => node.id);
|
|
1097
|
+
this.eventTarget.dispatchEvent(new CustomEvent(BuilderInternalEventType.NODE_REORDER, {
|
|
1098
|
+
detail: {
|
|
1099
|
+
nodeUids: childUids,
|
|
1100
|
+
parentUid,
|
|
1101
|
+
nodeIds: childIds
|
|
1102
|
+
}
|
|
1103
|
+
}));
|
|
1104
|
+
}
|
|
1025
1105
|
|
|
1026
1106
|
contextUpdated(detail) {
|
|
1027
1107
|
var {
|
|
@@ -1220,6 +1300,41 @@
|
|
|
1220
1300
|
|
|
1221
1301
|
}
|
|
1222
1302
|
|
|
1303
|
+
function getRelatedEdgesAndMountPoint(edges, parentUid) {
|
|
1304
|
+
var relatedEdges = lodash.sortBy(edges.filter(edge => edge.parent === parentUid && !edge.$$isTemplateExpanded), "sort");
|
|
1305
|
+
var mountPointSet = new Set();
|
|
1306
|
+
|
|
1307
|
+
for (var edge of relatedEdges) {
|
|
1308
|
+
mountPointSet.add(edge.mountPoint);
|
|
1309
|
+
}
|
|
1310
|
+
|
|
1311
|
+
var mountPoints = Array.from(mountPointSet);
|
|
1312
|
+
return {
|
|
1313
|
+
relatedEdges,
|
|
1314
|
+
mountPoints
|
|
1315
|
+
};
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
function moveItemInList(list, index, direction) {
|
|
1319
|
+
var upperIndex;
|
|
1320
|
+
|
|
1321
|
+
if (direction === "up") {
|
|
1322
|
+
if (index <= 0) {
|
|
1323
|
+
return;
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
upperIndex = index - 1;
|
|
1327
|
+
} else {
|
|
1328
|
+
if (index === -1 || index >= list.length - 1) {
|
|
1329
|
+
return;
|
|
1330
|
+
}
|
|
1331
|
+
|
|
1332
|
+
upperIndex = index;
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
return [...list.slice(0, upperIndex), list[upperIndex + 1], list[upperIndex], ...list.slice(upperIndex + 2)];
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1223
1338
|
var BuilderContext = /*#__PURE__*/React__default["default"].createContext({});
|
|
1224
1339
|
function createBuilderContext() {
|
|
1225
1340
|
return {
|