@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/CHANGELOG.md +31 -0
- package/dist/index.bundle.js +195 -4
- package/dist/index.bundle.js.map +1 -1
- package/dist/index.esm.js +195 -4
- package/dist/index.esm.js.map +1 -1
- package/dist/types/interfaces.d.ts +26 -0
- package/dist/types/internal/BuilderDataManager.d.ts +5 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,37 @@
|
|
|
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
|
+
|
|
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)
|
|
18
|
+
|
|
19
|
+
**Note:** Version bump only for package @next-core/editor-bricks-helper
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# [0.40.0](https://github.com/easyops-cn/next-core/compare/@next-core/editor-bricks-helper@0.39.32...@next-core/editor-bricks-helper@0.40.0) (2022-06-02)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Features
|
|
29
|
+
|
|
30
|
+
* **BuilderDataManager:** support workbench move ([d6f892e](https://github.com/easyops-cn/next-core/commit/d6f892e684586873098fa1790001b4c8c8d690db))
|
|
31
|
+
* **BuilderDataManager:** support workbench move ([e37f490](https://github.com/easyops-cn/next-core/commit/e37f490c5580182da3638ad9ffa81267b51638aa))
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
6
37
|
## [0.39.32](https://github.com/easyops-cn/next-core/compare/@next-core/editor-bricks-helper@0.39.31...@next-core/editor-bricks-helper@0.39.32) (2022-06-01)
|
|
7
38
|
|
|
8
39
|
**Note:** Version bump only for package @next-core/editor-bricks-helper
|
package/dist/index.bundle.js
CHANGED
|
@@ -678,6 +678,7 @@
|
|
|
678
678
|
BuilderInternalEventType["HIGHLIGHT_NODES_CHANGE"] = "builder.highlightNodes.change";
|
|
679
679
|
BuilderInternalEventType["OUTLINE_DISABLED_NODES_CHANGE"] = "builder.outlineDisabledNodes.change";
|
|
680
680
|
BuilderInternalEventType["DROPPING_STATUS_CHANGE"] = "builder.droppingStatus.change";
|
|
681
|
+
BuilderInternalEventType["WORKBENCH_TREE_NODE_MOVE"] = "workbench.tree.node.move";
|
|
681
682
|
})(BuilderInternalEventType || (BuilderInternalEventType = {}));
|
|
682
683
|
|
|
683
684
|
var storageKeyOfOutlineDisabledNodes = "builder-outline-disabled-nodes";
|
|
@@ -815,7 +816,8 @@
|
|
|
815
816
|
nodeUid,
|
|
816
817
|
parentUid,
|
|
817
818
|
nodeUids,
|
|
818
|
-
nodeData
|
|
819
|
+
nodeData,
|
|
820
|
+
sort
|
|
819
821
|
} = detail;
|
|
820
822
|
var {
|
|
821
823
|
nodes: addNodes,
|
|
@@ -826,7 +828,7 @@
|
|
|
826
828
|
parent: parentUid,
|
|
827
829
|
child: nodeUid,
|
|
828
830
|
mountPoint: nodeData.mountPoint,
|
|
829
|
-
sort: undefined,
|
|
831
|
+
sort: sort !== null && sort !== void 0 ? sort : undefined,
|
|
830
832
|
$$isTemplateDelegated: isParentExpandableTemplate(nodes, parentUid)
|
|
831
833
|
}).concat(addEdges);
|
|
832
834
|
var newData = {
|
|
@@ -1063,15 +1065,197 @@
|
|
|
1063
1065
|
var orderedEdges = lodash.sortBy(relatedEdges, edge => mountPoints.indexOf(edge.mountPoint), edge => orderedSiblingEdges.indexOf(edge));
|
|
1064
1066
|
this.reorder(parentUid, orderedEdges);
|
|
1065
1067
|
}
|
|
1068
|
+
|
|
1069
|
+
getDragInfo(_ref3) {
|
|
1070
|
+
var _dragEdge$mountPoint;
|
|
1071
|
+
|
|
1072
|
+
var {
|
|
1073
|
+
nodeData,
|
|
1074
|
+
dragNodeUid,
|
|
1075
|
+
dragOverNodeUid,
|
|
1076
|
+
dragStatus
|
|
1077
|
+
} = _ref3;
|
|
1078
|
+
var {
|
|
1079
|
+
rootId,
|
|
1080
|
+
nodes,
|
|
1081
|
+
edges
|
|
1082
|
+
} = this.data;
|
|
1083
|
+
var isDragRoot = dragOverNodeUid === rootId;
|
|
1084
|
+
/*
|
|
1085
|
+
* 如果没有id, 则为新增状态, 没有edge, 否则为移动状态
|
|
1086
|
+
*/
|
|
1087
|
+
|
|
1088
|
+
var isAdd = nodeData.id;
|
|
1089
|
+
var dragEdge = !isAdd ? edges.find(item => item.child === dragNodeUid) : null;
|
|
1090
|
+
var dragOverEdge = edges.find(item => item.child === dragOverNodeUid);
|
|
1091
|
+
/**
|
|
1092
|
+
* 如果是根节点, 则mountPoint强制等于 bricks
|
|
1093
|
+
* 如果是属于拖动进某个节点中, 则使用原mountPoint(新增节点为content)
|
|
1094
|
+
* 其他情况, 使用被拖拽节点的mountPoint
|
|
1095
|
+
*/
|
|
1096
|
+
|
|
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;
|
|
1098
|
+
var parentEdge = edges.find(item => item.child === dragOverNodeUid);
|
|
1099
|
+
/**
|
|
1100
|
+
* 如果是根节点, parentUid强制等于rootId
|
|
1101
|
+
* 如果是拖动进某个节点, 则当前节点为该节点parent
|
|
1102
|
+
* 否则, 等于该节点的父节点
|
|
1103
|
+
*/
|
|
1104
|
+
|
|
1105
|
+
var parentUid = isDragRoot ? rootId : dragStatus === "inside" ? parentEdge.child : parentEdge.parent;
|
|
1106
|
+
var parnetNodeData = nodes.find(item => item.$$uid === parentUid); // 找到节点父亲等于拖动节点的父节点(寻找兄弟节点)
|
|
1107
|
+
|
|
1108
|
+
var siblingEdge = edges.filter(edge => edge.child !== dragNodeUid && edge.parent === parentUid);
|
|
1109
|
+
var sortUids = lodash.sortBy(siblingEdge, "sort").map(item => item.child);
|
|
1110
|
+
var sortNodeIds = sortUids.map(item => {
|
|
1111
|
+
return nodes.find(node => node.$$uid === item).id;
|
|
1112
|
+
});
|
|
1113
|
+
var sortIndex;
|
|
1114
|
+
|
|
1115
|
+
if (dragStatus === "inside") {
|
|
1116
|
+
sortIndex = siblingEdge.length ? Math.max(...siblingEdge.map(item => item.sort)) + 1 : 0; // 插入默认插最后
|
|
1117
|
+
|
|
1118
|
+
sortNodeIds.push(nodeData.id);
|
|
1119
|
+
} else if (dragStatus === "top" || dragStatus === "bottom") {
|
|
1120
|
+
var _dragEdge$child;
|
|
1121
|
+
|
|
1122
|
+
var overIndex = sortUids.findIndex(item => item === dragOverNodeUid);
|
|
1123
|
+
sortIndex = dragStatus === "top" ? overIndex : overIndex + 1; // 排序修正
|
|
1124
|
+
|
|
1125
|
+
sortNodeIds.splice(sortIndex, 0, nodeData.id);
|
|
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
|
+
}));
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
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
|
+
});
|
|
1219
|
+
var newData = {
|
|
1220
|
+
rootId,
|
|
1221
|
+
nodes,
|
|
1222
|
+
edges: edges.filter(edge => edge.child !== dragNodeUid).concat({
|
|
1223
|
+
parent: parentUid,
|
|
1224
|
+
child: dragNodeUid,
|
|
1225
|
+
mountPoint: mountPoint,
|
|
1226
|
+
sort: sortIndex,
|
|
1227
|
+
$$isTemplateDelegated: isParentExpandableTemplate(nodes, parentUid)
|
|
1228
|
+
}),
|
|
1229
|
+
wrapperNode
|
|
1230
|
+
};
|
|
1231
|
+
this.data = _objectSpread__default["default"](_objectSpread__default["default"]({}, newData), {}, {
|
|
1232
|
+
edges: reorderBuilderEdges(newData, {
|
|
1233
|
+
parentUid,
|
|
1234
|
+
nodeUids
|
|
1235
|
+
})
|
|
1236
|
+
});
|
|
1237
|
+
this.triggerDataChange();
|
|
1238
|
+
this.eventTarget.dispatchEvent(new CustomEvent(BuilderInternalEventType.WORKBENCH_TREE_NODE_MOVE, {
|
|
1239
|
+
detail: {
|
|
1240
|
+
nodeUid: dragNodeUid,
|
|
1241
|
+
nodeInstanceId: nodeData.instanceId,
|
|
1242
|
+
nodeIds,
|
|
1243
|
+
nodeData: {
|
|
1244
|
+
parent: parnetNodeData.instanceId,
|
|
1245
|
+
mountPoint: mountPoint
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
}));
|
|
1249
|
+
}
|
|
1066
1250
|
/**
|
|
1067
1251
|
* Move mount-point up or down.
|
|
1068
1252
|
*/
|
|
1069
1253
|
|
|
1070
1254
|
|
|
1071
|
-
moveMountPoint(
|
|
1255
|
+
moveMountPoint(_ref4, mountPoint, direction) {
|
|
1072
1256
|
var {
|
|
1073
1257
|
$$uid: parentUid
|
|
1074
|
-
} =
|
|
1258
|
+
} = _ref4;
|
|
1075
1259
|
var {
|
|
1076
1260
|
relatedEdges,
|
|
1077
1261
|
mountPoints
|
|
@@ -1196,6 +1380,13 @@
|
|
|
1196
1380
|
};
|
|
1197
1381
|
}
|
|
1198
1382
|
|
|
1383
|
+
onWorkbenchTreeNodeMove(fn) {
|
|
1384
|
+
this.eventTarget.addEventListener(BuilderInternalEventType.WORKBENCH_TREE_NODE_MOVE, fn);
|
|
1385
|
+
return () => {
|
|
1386
|
+
this.eventTarget.removeEventListener(BuilderInternalEventType.WORKBENCH_TREE_NODE_MOVE, fn);
|
|
1387
|
+
};
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1199
1390
|
onNodeClick(fn) {
|
|
1200
1391
|
this.eventTarget.addEventListener(BuilderInternalEventType.NODE_CLICK, fn);
|
|
1201
1392
|
return () => {
|