@next-core/editor-bricks-helper 0.39.32 → 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/dist/index.esm.js CHANGED
@@ -676,6 +676,7 @@ var BuilderInternalEventType;
676
676
  BuilderInternalEventType["HIGHLIGHT_NODES_CHANGE"] = "builder.highlightNodes.change";
677
677
  BuilderInternalEventType["OUTLINE_DISABLED_NODES_CHANGE"] = "builder.outlineDisabledNodes.change";
678
678
  BuilderInternalEventType["DROPPING_STATUS_CHANGE"] = "builder.droppingStatus.change";
679
+ BuilderInternalEventType["WORKBENCH_TREE_NODE_MOVE"] = "workbench.tree.node.move";
679
680
  })(BuilderInternalEventType || (BuilderInternalEventType = {}));
680
681
 
681
682
  var storageKeyOfOutlineDisabledNodes = "builder-outline-disabled-nodes";
@@ -813,7 +814,8 @@ class BuilderDataManager {
813
814
  nodeUid,
814
815
  parentUid,
815
816
  nodeUids,
816
- nodeData
817
+ nodeData,
818
+ sort
817
819
  } = detail;
818
820
  var {
819
821
  nodes: addNodes,
@@ -824,7 +826,7 @@ class BuilderDataManager {
824
826
  parent: parentUid,
825
827
  child: nodeUid,
826
828
  mountPoint: nodeData.mountPoint,
827
- sort: undefined,
829
+ sort: sort !== null && sort !== void 0 ? sort : undefined,
828
830
  $$isTemplateDelegated: isParentExpandableTemplate(nodes, parentUid)
829
831
  }).concat(addEdges);
830
832
  var newData = {
@@ -1061,15 +1063,197 @@ class BuilderDataManager {
1061
1063
  var orderedEdges = sortBy(relatedEdges, edge => mountPoints.indexOf(edge.mountPoint), edge => orderedSiblingEdges.indexOf(edge));
1062
1064
  this.reorder(parentUid, orderedEdges);
1063
1065
  }
1066
+
1067
+ getDragInfo(_ref3) {
1068
+ var _dragEdge$mountPoint;
1069
+
1070
+ var {
1071
+ nodeData,
1072
+ dragNodeUid,
1073
+ dragOverNodeUid,
1074
+ dragStatus
1075
+ } = _ref3;
1076
+ var {
1077
+ rootId,
1078
+ nodes,
1079
+ edges
1080
+ } = this.data;
1081
+ var isDragRoot = dragOverNodeUid === rootId;
1082
+ /*
1083
+ * 如果没有id, 则为新增状态, 没有edge, 否则为移动状态
1084
+ */
1085
+
1086
+ var isAdd = nodeData.id;
1087
+ var dragEdge = !isAdd ? edges.find(item => item.child === dragNodeUid) : null;
1088
+ var dragOverEdge = edges.find(item => item.child === dragOverNodeUid);
1089
+ /**
1090
+ * 如果是根节点, 则mountPoint强制等于 bricks
1091
+ * 如果是属于拖动进某个节点中, 则使用原mountPoint(新增节点为content)
1092
+ * 其他情况, 使用被拖拽节点的mountPoint
1093
+ */
1094
+
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;
1096
+ var parentEdge = edges.find(item => item.child === dragOverNodeUid);
1097
+ /**
1098
+ * 如果是根节点, parentUid强制等于rootId
1099
+ * 如果是拖动进某个节点, 则当前节点为该节点parent
1100
+ * 否则, 等于该节点的父节点
1101
+ */
1102
+
1103
+ var parentUid = isDragRoot ? rootId : dragStatus === "inside" ? parentEdge.child : parentEdge.parent;
1104
+ var parnetNodeData = nodes.find(item => item.$$uid === parentUid); // 找到节点父亲等于拖动节点的父节点(寻找兄弟节点)
1105
+
1106
+ var siblingEdge = edges.filter(edge => edge.child !== dragNodeUid && edge.parent === parentUid);
1107
+ var sortUids = sortBy(siblingEdge, "sort").map(item => item.child);
1108
+ var sortNodeIds = sortUids.map(item => {
1109
+ return nodes.find(node => node.$$uid === item).id;
1110
+ });
1111
+ var sortIndex;
1112
+
1113
+ if (dragStatus === "inside") {
1114
+ sortIndex = siblingEdge.length ? Math.max(...siblingEdge.map(item => item.sort)) + 1 : 0; // 插入默认插最后
1115
+
1116
+ sortNodeIds.push(nodeData.id);
1117
+ } else if (dragStatus === "top" || dragStatus === "bottom") {
1118
+ var _dragEdge$child;
1119
+
1120
+ var overIndex = sortUids.findIndex(item => item === dragOverNodeUid);
1121
+ sortIndex = dragStatus === "top" ? overIndex : overIndex + 1; // 排序修正
1122
+
1123
+ sortNodeIds.splice(sortIndex, 0, nodeData.id);
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
+ }));
1188
+ }
1189
+ }
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
+ });
1217
+ var newData = {
1218
+ rootId,
1219
+ nodes,
1220
+ edges: edges.filter(edge => edge.child !== dragNodeUid).concat({
1221
+ parent: parentUid,
1222
+ child: dragNodeUid,
1223
+ mountPoint: mountPoint,
1224
+ sort: sortIndex,
1225
+ $$isTemplateDelegated: isParentExpandableTemplate(nodes, parentUid)
1226
+ }),
1227
+ wrapperNode
1228
+ };
1229
+ this.data = _objectSpread(_objectSpread({}, newData), {}, {
1230
+ edges: reorderBuilderEdges(newData, {
1231
+ parentUid,
1232
+ nodeUids
1233
+ })
1234
+ });
1235
+ this.triggerDataChange();
1236
+ this.eventTarget.dispatchEvent(new CustomEvent(BuilderInternalEventType.WORKBENCH_TREE_NODE_MOVE, {
1237
+ detail: {
1238
+ nodeUid: dragNodeUid,
1239
+ nodeInstanceId: nodeData.instanceId,
1240
+ nodeIds,
1241
+ nodeData: {
1242
+ parent: parnetNodeData.instanceId,
1243
+ mountPoint: mountPoint
1244
+ }
1245
+ }
1246
+ }));
1247
+ }
1064
1248
  /**
1065
1249
  * Move mount-point up or down.
1066
1250
  */
1067
1251
 
1068
1252
 
1069
- moveMountPoint(_ref3, mountPoint, direction) {
1253
+ moveMountPoint(_ref4, mountPoint, direction) {
1070
1254
  var {
1071
1255
  $$uid: parentUid
1072
- } = _ref3;
1256
+ } = _ref4;
1073
1257
  var {
1074
1258
  relatedEdges,
1075
1259
  mountPoints
@@ -1194,6 +1378,13 @@ class BuilderDataManager {
1194
1378
  };
1195
1379
  }
1196
1380
 
1381
+ onWorkbenchTreeNodeMove(fn) {
1382
+ this.eventTarget.addEventListener(BuilderInternalEventType.WORKBENCH_TREE_NODE_MOVE, fn);
1383
+ return () => {
1384
+ this.eventTarget.removeEventListener(BuilderInternalEventType.WORKBENCH_TREE_NODE_MOVE, fn);
1385
+ };
1386
+ }
1387
+
1197
1388
  onNodeClick(fn) {
1198
1389
  this.eventTarget.addEventListener(BuilderInternalEventType.NODE_CLICK, fn);
1199
1390
  return () => {