@next-core/editor-bricks-helper 0.40.0 → 0.41.1

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