@next-core/editor-bricks-helper 0.33.34 → 0.35.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 +21 -36
- package/README.md +2 -2
- package/dist/index.bundle.js +112 -37
- package/dist/index.bundle.js.map +1 -1
- package/dist/index.esm.js +112 -37
- package/dist/index.esm.js.map +1 -1
- package/dist/types/DropZone/DropZone.d.ts +2 -1
- package/dist/types/hooks/useBuilderGroupedChildNodes.d.ts +4 -2
- package/dist/types/hooks/useBuilderNode.d.ts +2 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/interfaces.d.ts +2 -24
- package/dist/types/internal/BuilderDataManager.d.ts +3 -2
- package/dist/types/internal/deleteNodeFromTree.d.ts +1 -1
- package/dist/types/internal/getAppendingNodesAndEdges.d.ts +2 -1
- package/package.json +5 -5
package/dist/index.esm.js
CHANGED
|
@@ -294,14 +294,16 @@ function deleteNodeFromTree(nodeUid, _ref) {
|
|
|
294
294
|
var {
|
|
295
295
|
rootId,
|
|
296
296
|
nodes,
|
|
297
|
-
edges
|
|
297
|
+
edges,
|
|
298
|
+
wrapperNode
|
|
298
299
|
} = _ref;
|
|
299
300
|
var idsToDelete = new Set();
|
|
300
301
|
collectIdsToDelete(nodeUid, edges, idsToDelete);
|
|
301
302
|
return {
|
|
302
303
|
rootId,
|
|
303
304
|
nodes: nodes.filter(node => !idsToDelete.has(node.$$uid)),
|
|
304
|
-
edges: edges.filter(edge => !idsToDelete.has(edge.parent) && !idsToDelete.has(edge.child))
|
|
305
|
+
edges: edges.filter(edge => !idsToDelete.has(edge.parent) && !idsToDelete.has(edge.child)),
|
|
306
|
+
wrapperNode: (wrapperNode === null || wrapperNode === void 0 ? void 0 : wrapperNode.$$uid) === nodeUid ? null : wrapperNode
|
|
305
307
|
};
|
|
306
308
|
}
|
|
307
309
|
|
|
@@ -453,10 +455,12 @@ function getBuilderNode(nodeData, nodeUid, isTemplateInternalNode) {
|
|
|
453
455
|
|
|
454
456
|
function getAppendingNodesAndEdges(nodeData, nodeUid, templateSourceMap) {
|
|
455
457
|
var storyList = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
|
|
458
|
+
var isRoot = arguments.length > 4 ? arguments[4] : undefined;
|
|
456
459
|
var nodes = [];
|
|
457
460
|
var edges = [];
|
|
461
|
+
var wrapperNode;
|
|
458
462
|
|
|
459
|
-
var walk = (nodeData, currentUid, processedTemplateSet, isTemplateInternalNode, inheritedTemplateRefToUid) => {
|
|
463
|
+
var walk = (nodeData, currentUid, processedTemplateSet, isTemplateInternalNode, inheritedTemplateRefToUid, layoutType) => {
|
|
460
464
|
var _templateSource$child, _storyList$find, _templateSource$child2;
|
|
461
465
|
|
|
462
466
|
var builderNode = getBuilderNode(nodeData, currentUid, isTemplateInternalNode);
|
|
@@ -469,7 +473,11 @@ function getAppendingNodesAndEdges(nodeData, nodeUid, templateSourceMap) {
|
|
|
469
473
|
var templateSource;
|
|
470
474
|
|
|
471
475
|
if (isBrickNode(builderNode) && (!builderNode.brick.includes(".") && builderNode.brick.startsWith("tpl-") && !processedTemplateSet.has(builderNode.brick) && (templateSource = templateSourceMap === null || templateSourceMap === void 0 ? void 0 : templateSourceMap.get(builderNode.brick)) && ((_templateSource$child = templateSource.children) === null || _templateSource$child === void 0 ? void 0 : _templateSource$child.length) > 0 || builderNode.brick.includes(".tpl-") && (templateSource = storyList === null || storyList === void 0 ? void 0 : (_storyList$find = storyList.find(item => item.storyId === builderNode.brick)) === null || _storyList$find === void 0 ? void 0 : _storyList$find.originData) && ((_templateSource$child2 = templateSource.children) === null || _templateSource$child2 === void 0 ? void 0 : _templateSource$child2.length) > 0)) {
|
|
472
|
-
|
|
476
|
+
if (templateSource.layoutType === "wrapper") {
|
|
477
|
+
builderNode.layoutType = "wrapper";
|
|
478
|
+
} // Avoid nesting the same templates.
|
|
479
|
+
|
|
480
|
+
|
|
473
481
|
processedTemplateSet.add(builderNode.brick);
|
|
474
482
|
builderNode.$$isExpandableTemplate = true;
|
|
475
483
|
builderNode.$$templateProxy = templateSource.proxy && JSON.parse(templateSource.proxy);
|
|
@@ -613,9 +621,30 @@ function getAppendingNodesAndEdges(nodeData, nodeUid, templateSourceMap) {
|
|
|
613
621
|
};
|
|
614
622
|
|
|
615
623
|
walk(nodeData, nodeUid, new Set());
|
|
624
|
+
|
|
625
|
+
var _loop2 = function (i) {
|
|
626
|
+
// 布局模板属于第一层
|
|
627
|
+
var item = nodes[i];
|
|
628
|
+
|
|
629
|
+
if (item.layoutType === "wrapper" && isRoot && edges.find(edge => edge.child === item.$$uid).parent === nodeUid) {
|
|
630
|
+
if (!wrapperNode) {
|
|
631
|
+
wrapperNode = item;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
return "break";
|
|
635
|
+
}
|
|
636
|
+
};
|
|
637
|
+
|
|
638
|
+
for (var i = 0; i < nodes.length; i++) {
|
|
639
|
+
var _ret = _loop2(i);
|
|
640
|
+
|
|
641
|
+
if (_ret === "break") break;
|
|
642
|
+
}
|
|
643
|
+
|
|
616
644
|
return {
|
|
617
645
|
nodes,
|
|
618
|
-
edges
|
|
646
|
+
edges,
|
|
647
|
+
wrapperNode
|
|
619
648
|
};
|
|
620
649
|
}
|
|
621
650
|
function isBasicRefProperty(propRef) {
|
|
@@ -653,7 +682,8 @@ class BuilderDataManager {
|
|
|
653
682
|
_defineProperty(this, "data", {
|
|
654
683
|
rootId: null,
|
|
655
684
|
nodes: [],
|
|
656
|
-
edges: []
|
|
685
|
+
edges: [],
|
|
686
|
+
wrapperNode: null
|
|
657
687
|
});
|
|
658
688
|
|
|
659
689
|
_defineProperty(this, "hoverNodeUid", void 0);
|
|
@@ -688,7 +718,8 @@ class BuilderDataManager {
|
|
|
688
718
|
var {
|
|
689
719
|
rootId,
|
|
690
720
|
nodes,
|
|
691
|
-
edges
|
|
721
|
+
edges,
|
|
722
|
+
wrapperNode
|
|
692
723
|
} = this.data;
|
|
693
724
|
var {
|
|
694
725
|
nodeUid,
|
|
@@ -711,7 +742,8 @@ class BuilderDataManager {
|
|
|
711
742
|
var newData = {
|
|
712
743
|
rootId,
|
|
713
744
|
nodes: newNodes,
|
|
714
|
-
edges: newEdges
|
|
745
|
+
edges: newEdges,
|
|
746
|
+
wrapperNode
|
|
715
747
|
};
|
|
716
748
|
this.data = _objectSpread(_objectSpread({}, newData), {}, {
|
|
717
749
|
edges: reorderBuilderEdges(newData, {
|
|
@@ -785,7 +817,7 @@ class BuilderDataManager {
|
|
|
785
817
|
|
|
786
818
|
var newData = _objectSpread({
|
|
787
819
|
rootId
|
|
788
|
-
}, getAppendingNodesAndEdges(root, rootId, templateSourceMap, this.storyList));
|
|
820
|
+
}, getAppendingNodesAndEdges(root, rootId, templateSourceMap, this.storyList, true));
|
|
789
821
|
|
|
790
822
|
this.data = _objectSpread(_objectSpread({}, newData), {}, {
|
|
791
823
|
edges: expandTemplateEdges(newData)
|
|
@@ -809,7 +841,23 @@ class BuilderDataManager {
|
|
|
809
841
|
this.runAddNodeAction(detail);
|
|
810
842
|
}
|
|
811
843
|
|
|
844
|
+
redirectMountPoint(detail) {
|
|
845
|
+
var {
|
|
846
|
+
rootId,
|
|
847
|
+
wrapperNode
|
|
848
|
+
} = this.data;
|
|
849
|
+
|
|
850
|
+
if (detail.parentUid === rootId) {
|
|
851
|
+
detail.nodeData.mountPoint = "bricks";
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
if (wrapperNode && wrapperNode.instanceId === detail.nodeData.parent) {
|
|
855
|
+
detail.nodeData.mountPoint = "content";
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
|
|
812
859
|
nodeAdd(detail) {
|
|
860
|
+
this.redirectMountPoint(detail);
|
|
813
861
|
this.runAddNodeAction(detail);
|
|
814
862
|
this.eventTarget.dispatchEvent(new CustomEvent(BuilderInternalEventType.NODE_ADD, {
|
|
815
863
|
detail
|
|
@@ -820,7 +868,8 @@ class BuilderDataManager {
|
|
|
820
868
|
var {
|
|
821
869
|
rootId,
|
|
822
870
|
nodes,
|
|
823
|
-
edges
|
|
871
|
+
edges,
|
|
872
|
+
wrapperNode
|
|
824
873
|
} = this.data;
|
|
825
874
|
var {
|
|
826
875
|
nodeUid,
|
|
@@ -832,7 +881,8 @@ class BuilderDataManager {
|
|
|
832
881
|
id: nodeData.id,
|
|
833
882
|
instanceId: nodeData.instanceId
|
|
834
883
|
}) : node),
|
|
835
|
-
edges
|
|
884
|
+
edges,
|
|
885
|
+
wrapperNode
|
|
836
886
|
};
|
|
837
887
|
this.triggerDataChange();
|
|
838
888
|
}
|
|
@@ -841,7 +891,8 @@ class BuilderDataManager {
|
|
|
841
891
|
var {
|
|
842
892
|
rootId,
|
|
843
893
|
nodes,
|
|
844
|
-
edges
|
|
894
|
+
edges,
|
|
895
|
+
wrapperNode
|
|
845
896
|
} = this.data;
|
|
846
897
|
var {
|
|
847
898
|
nodeDetails,
|
|
@@ -883,7 +934,8 @@ class BuilderDataManager {
|
|
|
883
934
|
var newData = {
|
|
884
935
|
rootId,
|
|
885
936
|
nodes: newNodes,
|
|
886
|
-
edges: newEdges
|
|
937
|
+
edges: newEdges,
|
|
938
|
+
wrapperNode
|
|
887
939
|
};
|
|
888
940
|
this.data = _objectSpread(_objectSpread({}, newData), {}, {
|
|
889
941
|
edges: reorderBuilderEdges(newData, {
|
|
@@ -924,8 +976,10 @@ class BuilderDataManager {
|
|
|
924
976
|
var {
|
|
925
977
|
rootId,
|
|
926
978
|
nodes,
|
|
927
|
-
edges
|
|
979
|
+
edges,
|
|
980
|
+
wrapperNode
|
|
928
981
|
} = this.data;
|
|
982
|
+
this.redirectMountPoint(detail);
|
|
929
983
|
var {
|
|
930
984
|
nodeUid,
|
|
931
985
|
parentUid,
|
|
@@ -941,7 +995,8 @@ class BuilderDataManager {
|
|
|
941
995
|
mountPoint: nodeData.mountPoint,
|
|
942
996
|
sort: undefined,
|
|
943
997
|
$$isTemplateDelegated: isParentExpandableTemplate(nodes, parentUid)
|
|
944
|
-
})
|
|
998
|
+
}),
|
|
999
|
+
wrapperNode
|
|
945
1000
|
};
|
|
946
1001
|
this.data = _objectSpread(_objectSpread({}, newData), {}, {
|
|
947
1002
|
edges: reorderBuilderEdges(newData, {
|
|
@@ -959,14 +1014,16 @@ class BuilderDataManager {
|
|
|
959
1014
|
var {
|
|
960
1015
|
rootId,
|
|
961
1016
|
nodes,
|
|
962
|
-
edges
|
|
1017
|
+
edges,
|
|
1018
|
+
wrapperNode
|
|
963
1019
|
} = this.data;
|
|
964
1020
|
this.data = {
|
|
965
1021
|
rootId,
|
|
966
1022
|
edges,
|
|
967
1023
|
nodes: nodes.map(node => node.$$uid === rootId ? _objectSpread(_objectSpread({}, node), {}, {
|
|
968
1024
|
context: detail.context
|
|
969
|
-
}) : node)
|
|
1025
|
+
}) : node),
|
|
1026
|
+
wrapperNode
|
|
970
1027
|
};
|
|
971
1028
|
this.triggerDataChange();
|
|
972
1029
|
}
|
|
@@ -1181,14 +1238,22 @@ function useBuilderData() {
|
|
|
1181
1238
|
function useBuilderNode(_ref) {
|
|
1182
1239
|
var {
|
|
1183
1240
|
nodeUid,
|
|
1184
|
-
isRoot
|
|
1241
|
+
isRoot,
|
|
1242
|
+
isWrapper
|
|
1185
1243
|
} = _ref;
|
|
1186
1244
|
var {
|
|
1187
1245
|
rootId,
|
|
1188
|
-
nodes
|
|
1246
|
+
nodes,
|
|
1247
|
+
wrapperNode
|
|
1189
1248
|
} = useBuilderData();
|
|
1190
1249
|
var currentUid = isRoot ? rootId : nodeUid;
|
|
1191
|
-
return useMemo(() =>
|
|
1250
|
+
return useMemo(() => {
|
|
1251
|
+
if (isWrapper) {
|
|
1252
|
+
return wrapperNode;
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
return nodes.find(node => node.$$uid === currentUid);
|
|
1256
|
+
}, [nodes, currentUid, isWrapper, wrapperNode]);
|
|
1192
1257
|
}
|
|
1193
1258
|
|
|
1194
1259
|
function useBuilderContextMenuStatus() {
|
|
@@ -1600,26 +1665,30 @@ function useBuilderGroupedChildNodes(_ref) {
|
|
|
1600
1665
|
var {
|
|
1601
1666
|
nodeUid,
|
|
1602
1667
|
isRoot,
|
|
1603
|
-
doNotExpandTemplates
|
|
1668
|
+
doNotExpandTemplates,
|
|
1669
|
+
isWrapper
|
|
1604
1670
|
} = _ref;
|
|
1605
1671
|
var {
|
|
1606
1672
|
rootId,
|
|
1607
1673
|
nodes,
|
|
1608
|
-
edges
|
|
1674
|
+
edges,
|
|
1675
|
+
wrapperNode
|
|
1609
1676
|
} = useBuilderData();
|
|
1610
1677
|
return useMemo(() => getBuilderGroupedChildNodes({
|
|
1611
1678
|
nodes,
|
|
1612
1679
|
edges,
|
|
1613
|
-
nodeUid: isRoot ? rootId : nodeUid,
|
|
1614
|
-
doNotExpandTemplates
|
|
1615
|
-
|
|
1680
|
+
nodeUid: isRoot ? isWrapper ? wrapperNode.$$uid : rootId : nodeUid,
|
|
1681
|
+
doNotExpandTemplates,
|
|
1682
|
+
isWrapper: isWrapper
|
|
1683
|
+
}), [doNotExpandTemplates, edges, isRoot, nodeUid, nodes, rootId, isWrapper, wrapperNode]);
|
|
1616
1684
|
}
|
|
1617
1685
|
function getBuilderGroupedChildNodes(_ref2) {
|
|
1618
1686
|
var {
|
|
1619
1687
|
nodeUid,
|
|
1620
1688
|
nodes,
|
|
1621
1689
|
edges,
|
|
1622
|
-
doNotExpandTemplates
|
|
1690
|
+
doNotExpandTemplates,
|
|
1691
|
+
isWrapper
|
|
1623
1692
|
} = _ref2;
|
|
1624
1693
|
var groups = new Map();
|
|
1625
1694
|
var relatedEdges = sortBy(edges.filter(edge => edge.parent === nodeUid && (doNotExpandTemplates ? !edge.$$isTemplateInternal : !edge.$$isTemplateDelegated)), [edge => edge.sort]);
|
|
@@ -1641,7 +1710,7 @@ function getBuilderGroupedChildNodes(_ref2) {
|
|
|
1641
1710
|
return Array.from(groups.entries()).map(_ref3 => {
|
|
1642
1711
|
var [mountPoint, childNodes] = _ref3;
|
|
1643
1712
|
return {
|
|
1644
|
-
mountPoint,
|
|
1713
|
+
mountPoint: isWrapper ? "bricks" : mountPoint,
|
|
1645
1714
|
childNodes
|
|
1646
1715
|
};
|
|
1647
1716
|
});
|
|
@@ -2131,20 +2200,30 @@ function DropZone(_ref) {
|
|
|
2131
2200
|
dropZoneStyle,
|
|
2132
2201
|
dropZoneBodyStyle,
|
|
2133
2202
|
slotContentLayout,
|
|
2134
|
-
showOutlineIfEmpty
|
|
2203
|
+
showOutlineIfEmpty,
|
|
2204
|
+
hiddenWrapper = true
|
|
2135
2205
|
} = _ref;
|
|
2136
2206
|
var dropZoneBody = React.useRef();
|
|
2137
2207
|
var [dropPositionCursor, setDropPositionCursor] = React.useState(null);
|
|
2138
2208
|
var dropPositionCursorRef = React.useRef();
|
|
2139
2209
|
var contextMenuStatus = useBuilderContextMenuStatus();
|
|
2140
2210
|
var manager = useBuilderDataManager();
|
|
2211
|
+
var {
|
|
2212
|
+
nodes,
|
|
2213
|
+
edges,
|
|
2214
|
+
wrapperNode
|
|
2215
|
+
} = useBuilderData();
|
|
2216
|
+
var isWrapper = hiddenWrapper && isRoot && !isEmpty(wrapperNode);
|
|
2141
2217
|
var node = useBuilderNode({
|
|
2142
2218
|
nodeUid,
|
|
2143
|
-
isRoot
|
|
2219
|
+
isRoot,
|
|
2220
|
+
isWrapper
|
|
2144
2221
|
});
|
|
2145
2222
|
var groupedChildNodes = useBuilderGroupedChildNodes({
|
|
2146
2223
|
nodeUid,
|
|
2147
|
-
isRoot
|
|
2224
|
+
isRoot,
|
|
2225
|
+
doNotExpandTemplates: isWrapper,
|
|
2226
|
+
isWrapper
|
|
2148
2227
|
});
|
|
2149
2228
|
var isGeneralizedPortalCanvas = independentPortalCanvas ? canvasIndex > 0 : isPortalCanvas;
|
|
2150
2229
|
var hasTabs = separateCanvas || independentPortalCanvas;
|
|
@@ -2174,10 +2253,6 @@ function DropZone(_ref) {
|
|
|
2174
2253
|
|
|
2175
2254
|
return isGeneralizedPortalCanvas ? selfChildNodes.length : 0;
|
|
2176
2255
|
}, [hasTabs, selfChildNodesInCurrentCanvas, isGeneralizedPortalCanvas, selfChildNodes]);
|
|
2177
|
-
var {
|
|
2178
|
-
nodes,
|
|
2179
|
-
edges
|
|
2180
|
-
} = useBuilderData();
|
|
2181
2256
|
var getDroppingContext = React.useCallback(() => {
|
|
2182
2257
|
if (delegatedContext) {
|
|
2183
2258
|
var _siblingGroups$find$c, _siblingGroups$find;
|
|
@@ -2199,12 +2274,12 @@ function DropZone(_ref) {
|
|
|
2199
2274
|
|
|
2200
2275
|
return {
|
|
2201
2276
|
droppingParentUid: node.$$uid,
|
|
2202
|
-
droppingParentInstanceId: node.instanceId,
|
|
2277
|
+
droppingParentInstanceId: isWrapper ? wrapperNode.instanceId : node.instanceId,
|
|
2203
2278
|
droppingMountPoint: mountPoint,
|
|
2204
2279
|
droppingChildNodes: selfChildNodes,
|
|
2205
2280
|
droppingSiblingGroups: groupedChildNodes
|
|
2206
2281
|
};
|
|
2207
|
-
}, [delegatedContext, edges, groupedChildNodes, mountPoint, node, nodes, selfChildNodes]);
|
|
2282
|
+
}, [delegatedContext, edges, groupedChildNodes, mountPoint, node, nodes, selfChildNodes, isWrapper, wrapperNode]);
|
|
2208
2283
|
var [{
|
|
2209
2284
|
isDraggingOverCurrent
|
|
2210
2285
|
}, dropRef] = useDrop({
|
|
@@ -2247,7 +2322,7 @@ function DropZone(_ref) {
|
|
|
2247
2322
|
React.useEffect(() => {
|
|
2248
2323
|
manager.updateDroppingStatus(delegatedContext ? delegatedContext.templateUid : node.$$uid, delegatedContext ? delegatedContext.templateMountPoint : mountPoint, isDraggingOverCurrent);
|
|
2249
2324
|
}, [isDraggingOverCurrent, mountPoint, manager, delegatedContext, node]);
|
|
2250
|
-
var droppable = !!delegatedContext || !(node.$$isExpandableTemplate || node.$$isTemplateInternalNode);
|
|
2325
|
+
var droppable = !!delegatedContext || isWrapper || !(node.$$isExpandableTemplate || node.$$isTemplateInternalNode);
|
|
2251
2326
|
var dropZoneRef = React.useRef();
|
|
2252
2327
|
var dropZoneRefCallback = React.useCallback(element => {
|
|
2253
2328
|
dropZoneRef.current = element;
|