@next-core/editor-bricks-helper 0.40.1 → 0.41.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/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
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.41.0](https://github.com/easyops-cn/next-core/compare/@next-core/editor-bricks-helper@0.40.1...@next-core/editor-bricks-helper@0.41.0) (2022-06-10)
7
+
8
+
9
+ ### Features
10
+
11
+ * **BuilderDataManager:** support preview addNode ([b5b0ee7](https://github.com/easyops-cn/next-core/commit/b5b0ee7e55466486a6d31656ec384d0114111ce7))
12
+
13
+
14
+
15
+
16
+
6
17
  ## [0.40.1](https://github.com/easyops-cn/next-core/compare/@next-core/editor-bricks-helper@0.40.0...@next-core/editor-bricks-helper@0.40.1) (2022-06-06)
7
18
 
8
19
  **Note:** Version bump only for package @next-core/editor-bricks-helper
@@ -816,7 +816,8 @@
816
816
  nodeUid,
817
817
  parentUid,
818
818
  nodeUids,
819
- nodeData
819
+ nodeData,
820
+ sort
820
821
  } = detail;
821
822
  var {
822
823
  nodes: addNodes,
@@ -827,7 +828,7 @@
827
828
  parent: parentUid,
828
829
  child: nodeUid,
829
830
  mountPoint: nodeData.mountPoint,
830
- sort: undefined,
831
+ sort: sort !== null && sort !== void 0 ? sort : undefined,
831
832
  $$isTemplateDelegated: isParentExpandableTemplate(nodes, parentUid)
832
833
  }).concat(addEdges);
833
834
  var newData = {
@@ -1065,30 +1066,35 @@
1065
1066
  this.reorder(parentUid, orderedEdges);
1066
1067
  }
1067
1068
 
1068
- workbenchTreeNodeMove(detail) {
1069
- var {
1070
- rootId,
1071
- nodes,
1072
- edges,
1073
- wrapperNode
1074
- } = this.data;
1069
+ getDragInfo(_ref3) {
1070
+ var _dragEdge$mountPoint;
1071
+
1075
1072
  var {
1073
+ nodeData,
1076
1074
  dragNodeUid,
1077
1075
  dragOverNodeUid,
1078
- dragParentNodeUid,
1079
1076
  dragStatus
1080
- } = detail;
1077
+ } = _ref3;
1078
+ var {
1079
+ rootId,
1080
+ nodes,
1081
+ edges
1082
+ } = this.data;
1081
1083
  var isDragRoot = dragOverNodeUid === rootId;
1082
- var nodeData = nodes.find(item => item.$$uid === dragNodeUid);
1083
- var dragEdge = edges.find(item => item.child === dragNodeUid);
1084
+ /*
1085
+ * 如果没有id, 则为新增状态, 没有edge, 否则为移动状态
1086
+ */
1087
+
1088
+ var isAdd = nodeData.id;
1089
+ var dragEdge = !isAdd ? edges.find(item => item.child === dragNodeUid) : null;
1084
1090
  var dragOverEdge = edges.find(item => item.child === dragOverNodeUid);
1085
1091
  /**
1086
1092
  * 如果是根节点, 则mountPoint强制等于 bricks
1087
- * 如果是属于拖动进某个节点中, 则使用原mountPoint
1093
+ * 如果是属于拖动进某个节点中, 则使用原mountPoint(新增节点为content)
1088
1094
  * 其他情况, 使用被拖拽节点的mountPoint
1089
1095
  */
1090
1096
 
1091
- var mountPoint = isDragRoot ? "bricks" : dragStatus === "inside" ? dragEdge.mountPoint : dragOverEdge.mountPoint;
1097
+ var mountPoint = isDragRoot ? "bricks" : dragStatus === "inside" ? (_dragEdge$mountPoint = dragEdge === null || dragEdge === void 0 ? void 0 : dragEdge.mountPoint) !== null && _dragEdge$mountPoint !== void 0 ? _dragEdge$mountPoint : "content" : dragOverEdge.mountPoint;
1092
1098
  var parentEdge = edges.find(item => item.child === dragOverNodeUid);
1093
1099
  /**
1094
1100
  * 如果是根节点, parentUid强制等于rootId
@@ -1111,31 +1117,121 @@
1111
1117
 
1112
1118
  sortNodeIds.push(nodeData.id);
1113
1119
  } else if (dragStatus === "top" || dragStatus === "bottom") {
1114
- var _dragEdge = edges.find(edge => edge.child === dragNodeUid);
1120
+ var _dragEdge$child;
1115
1121
 
1116
1122
  var overIndex = sortUids.findIndex(item => item === dragOverNodeUid);
1117
1123
  sortIndex = dragStatus === "top" ? overIndex : overIndex + 1; // 排序修正
1118
1124
 
1119
1125
  sortNodeIds.splice(sortIndex, 0, nodeData.id);
1120
- sortUids.splice(sortIndex, 0, _dragEdge.child);
1126
+ sortUids.splice(sortIndex, 0, (_dragEdge$child = dragEdge === null || dragEdge === void 0 ? void 0 : dragEdge.child) !== null && _dragEdge$child !== void 0 ? _dragEdge$child : null);
1127
+ }
1128
+
1129
+ return {
1130
+ parentUid,
1131
+ mountPoint,
1132
+ sortIndex,
1133
+ parnetNodeData,
1134
+ sortUids,
1135
+ sortNodeIds
1136
+ };
1137
+ }
1138
+
1139
+ workbenchNodeAdd(detail) {
1140
+ var {
1141
+ rootId,
1142
+ nodes
1143
+ } = this.data;
1144
+ var {
1145
+ nodeData,
1146
+ dragOverNodeInstanceId,
1147
+ dragStatus
1148
+ } = detail;
1149
+
1150
+ if (nodeData.instanceId) ; else {
1151
+ var _nodes$find;
1152
+
1153
+ // insert
1154
+ var newNodeUid = getUniqueNodeId();
1155
+ var isRoot = dragOverNodeInstanceId === "#main-mount-point";
1156
+ var dragOverNodeUid = (_nodes$find = nodes.find(item => isRoot ? item.$$uid === rootId : item.instanceId === dragOverNodeInstanceId)) === null || _nodes$find === void 0 ? void 0 : _nodes$find.$$uid;
1157
+ var {
1158
+ parentUid,
1159
+ mountPoint,
1160
+ sortIndex,
1161
+ sortUids: nodeUids,
1162
+ sortNodeIds: nodeIds
1163
+ } = this.getDragInfo({
1164
+ nodeData: {
1165
+ id: null
1166
+ },
1167
+ dragNodeUid: newNodeUid,
1168
+ dragOverNodeUid,
1169
+ dragStatus
1170
+ });
1171
+ nodeData.parent = nodes.find(item => item.$$uid === parentUid).instanceId;
1172
+ nodeData.mountPoint = mountPoint;
1173
+ this.runAddNodeAction({
1174
+ nodeUid: newNodeUid,
1175
+ parentUid,
1176
+ nodeUids,
1177
+ nodeIds,
1178
+ nodeData,
1179
+ sort: sortIndex
1180
+ });
1181
+ this.eventTarget.dispatchEvent(new CustomEvent(BuilderInternalEventType.NODE_ADD, {
1182
+ detail: {
1183
+ nodeUid: newNodeUid,
1184
+ parentUid,
1185
+ nodeUids,
1186
+ nodeIds,
1187
+ nodeData
1188
+ }
1189
+ }));
1121
1190
  }
1191
+ }
1122
1192
 
1193
+ workbenchTreeNodeMove(detail) {
1194
+ var {
1195
+ rootId,
1196
+ nodes,
1197
+ edges,
1198
+ wrapperNode
1199
+ } = this.data;
1200
+ var {
1201
+ dragNodeUid,
1202
+ dragOverNodeUid,
1203
+ dragStatus
1204
+ } = detail;
1205
+ var nodeData = nodes.find(item => item.$$uid === dragNodeUid);
1206
+ var {
1207
+ parentUid,
1208
+ parnetNodeData,
1209
+ mountPoint,
1210
+ sortIndex,
1211
+ sortUids: nodeUids,
1212
+ sortNodeIds: nodeIds
1213
+ } = this.getDragInfo({
1214
+ nodeData,
1215
+ dragNodeUid,
1216
+ dragOverNodeUid,
1217
+ dragStatus
1218
+ });
1123
1219
  var newData = {
1124
1220
  rootId,
1125
1221
  nodes,
1126
1222
  edges: edges.filter(edge => edge.child !== dragNodeUid).concat({
1127
- parent: dragParentNodeUid,
1223
+ parent: parentUid,
1128
1224
  child: dragNodeUid,
1129
1225
  mountPoint: mountPoint,
1130
1226
  sort: sortIndex,
1131
- $$isTemplateDelegated: isParentExpandableTemplate(nodes, dragParentNodeUid)
1227
+ $$isTemplateDelegated: isParentExpandableTemplate(nodes, parentUid)
1132
1228
  }),
1133
1229
  wrapperNode
1134
1230
  };
1135
1231
  this.data = _objectSpread__default["default"](_objectSpread__default["default"]({}, newData), {}, {
1136
1232
  edges: reorderBuilderEdges(newData, {
1137
1233
  parentUid,
1138
- nodeUids: sortUids
1234
+ nodeUids
1139
1235
  })
1140
1236
  });
1141
1237
  this.triggerDataChange();
@@ -1143,7 +1239,7 @@
1143
1239
  detail: {
1144
1240
  nodeUid: dragNodeUid,
1145
1241
  nodeInstanceId: nodeData.instanceId,
1146
- nodeIds: sortNodeIds,
1242
+ nodeIds,
1147
1243
  nodeData: {
1148
1244
  parent: parnetNodeData.instanceId,
1149
1245
  mountPoint: mountPoint
@@ -1156,10 +1252,10 @@
1156
1252
  */
1157
1253
 
1158
1254
 
1159
- moveMountPoint(_ref3, mountPoint, direction) {
1255
+ moveMountPoint(_ref4, mountPoint, direction) {
1160
1256
  var {
1161
1257
  $$uid: parentUid
1162
- } = _ref3;
1258
+ } = _ref4;
1163
1259
  var {
1164
1260
  relatedEdges,
1165
1261
  mountPoints