@next-core/editor-bricks-helper 0.41.0 → 0.42.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/CHANGELOG.md +27 -0
- package/dist/index.bundle.js +107 -73
- package/dist/index.bundle.js.map +1 -1
- package/dist/index.esm.js +103 -69
- package/dist/index.esm.js.map +1 -1
- package/dist/types/interfaces.d.ts +6 -2
- package/package.json +3 -3
package/dist/index.esm.js
CHANGED
|
@@ -4,11 +4,11 @@ import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
|
4
4
|
import { sortBy, clamp, isEmpty, cloneDeep, upperFirst, omit } from 'lodash';
|
|
5
5
|
import { hasOwnProperty, isBrickNode, normalizeBuilderNode, JsonStorage, isRouteNode } from '@next-core/brick-utils';
|
|
6
6
|
export { isBrickNode, isCustomTemplateNode, isRouteNode, isSnippetNode } from '@next-core/brick-utils';
|
|
7
|
+
import yaml from 'js-yaml';
|
|
7
8
|
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
8
9
|
import { useDrag, useDrop, DndProvider } from 'react-dnd';
|
|
9
10
|
import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
|
|
10
11
|
import { developHelper, getRuntime, BrickAsComponent, property, BrickWrapper, UpdatingElement } from '@next-core/brick-kit';
|
|
11
|
-
import yaml from 'js-yaml';
|
|
12
12
|
import _decorate from '@babel/runtime/helpers/decorate';
|
|
13
13
|
import ReactDOM from 'react-dom';
|
|
14
14
|
import { HTML5Backend } from 'react-dnd-html5-backend';
|
|
@@ -658,6 +658,63 @@ function isParentExpandableTemplate(nodes, parentUid) {
|
|
|
658
658
|
return nodes.find(node => node.$$uid === parentUid).$$isExpandableTemplate;
|
|
659
659
|
}
|
|
660
660
|
|
|
661
|
+
var jsonFieldsInBrick = ["properties", "events", "lifeCycle", "params", "if", "transform"];
|
|
662
|
+
var yamlFieldsInBrick = ["permissionsPreCheck", "transformFrom"];
|
|
663
|
+
var ignoredFieldsInBrick = ["brick", "template", "portal", "slots", "id", "children", "instanceId"];
|
|
664
|
+
// The reverse operation of *normalize*.
|
|
665
|
+
// https://github.com/easyops-cn/next-basics/blob/5a6710d567821bcb4a0c71e22d55212193d8b0cb/bricks/next-builder/src/shared/storyboard/buildStoryboard.ts#L394
|
|
666
|
+
function reverseNormalize(brickConf, ctx) {
|
|
667
|
+
return Object.fromEntries(Object.entries(brickConf).map(_ref => {
|
|
668
|
+
var [key, value] = _ref;
|
|
669
|
+
return value === undefined || ignoredFieldsInBrick.includes(key) ? undefined : jsonFieldsInBrick.includes(key) ? [key, JSON.stringify(value)] : yamlFieldsInBrick.includes(key) ? [key, yaml.safeDump(value)] : [key, value];
|
|
670
|
+
}).filter(Boolean).concat(Object.entries(ctx.nodeData), [["brick", ctx.nodeData.type === "template" ? brickConf.template : brickConf.brick], ["portal", ctx.isPortalCanvas || brickConf.portal]]));
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
function getSnippetNodeDetail(_ref) {
|
|
674
|
+
var {
|
|
675
|
+
parent,
|
|
676
|
+
parentUid,
|
|
677
|
+
mountPoint,
|
|
678
|
+
nodeUid,
|
|
679
|
+
brickConf,
|
|
680
|
+
isPortalCanvas,
|
|
681
|
+
sort
|
|
682
|
+
} = _ref;
|
|
683
|
+
var type = brickConf.template ? "template" : brickConf.bg ? "provider" : "brick";
|
|
684
|
+
return {
|
|
685
|
+
nodeUid,
|
|
686
|
+
parentUid,
|
|
687
|
+
nodeData: reverseNormalize(brickConf, {
|
|
688
|
+
isPortalCanvas,
|
|
689
|
+
nodeData: {
|
|
690
|
+
type,
|
|
691
|
+
parent,
|
|
692
|
+
mountPoint,
|
|
693
|
+
sort
|
|
694
|
+
}
|
|
695
|
+
}),
|
|
696
|
+
children: brickConf.slots ? Object.entries(brickConf.slots).flatMap(_ref2 => {
|
|
697
|
+
var [mountPoint, slotConf] = _ref2;
|
|
698
|
+
return slotConf.bricks.map(childBrickConf => ({
|
|
699
|
+
childBrickConf,
|
|
700
|
+
mountPoint
|
|
701
|
+
}));
|
|
702
|
+
}).map((_ref3, index) => {
|
|
703
|
+
var {
|
|
704
|
+
childBrickConf,
|
|
705
|
+
mountPoint
|
|
706
|
+
} = _ref3;
|
|
707
|
+
return getSnippetNodeDetail({
|
|
708
|
+
parentUid: nodeUid,
|
|
709
|
+
mountPoint,
|
|
710
|
+
nodeUid: getUniqueNodeId(),
|
|
711
|
+
brickConf: childBrickConf,
|
|
712
|
+
sort: index
|
|
713
|
+
});
|
|
714
|
+
}) : []
|
|
715
|
+
};
|
|
716
|
+
}
|
|
717
|
+
|
|
661
718
|
var BuilderInternalEventType;
|
|
662
719
|
|
|
663
720
|
(function (BuilderInternalEventType) {
|
|
@@ -1136,25 +1193,40 @@ class BuilderDataManager {
|
|
|
1136
1193
|
|
|
1137
1194
|
workbenchNodeAdd(detail) {
|
|
1138
1195
|
var {
|
|
1139
|
-
|
|
1140
|
-
|
|
1196
|
+
nodes,
|
|
1197
|
+
edges,
|
|
1198
|
+
rootId
|
|
1141
1199
|
} = this.data;
|
|
1142
1200
|
var {
|
|
1143
1201
|
nodeData,
|
|
1144
|
-
|
|
1145
|
-
|
|
1202
|
+
dragOverInstanceId,
|
|
1203
|
+
parentInstanceId,
|
|
1204
|
+
dragStatus,
|
|
1205
|
+
mountPoint
|
|
1146
1206
|
} = detail;
|
|
1147
1207
|
|
|
1148
1208
|
if (nodeData.instanceId) ; else {
|
|
1149
|
-
var _nodes$find;
|
|
1150
|
-
|
|
1151
1209
|
// insert
|
|
1152
1210
|
var newNodeUid = getUniqueNodeId();
|
|
1153
|
-
var
|
|
1154
|
-
var dragOverNodeUid =
|
|
1211
|
+
var overNode = nodes.find(item => item.instanceId === dragOverInstanceId);
|
|
1212
|
+
var dragOverNodeUid = overNode.$$uid;
|
|
1213
|
+
var realDragStatus = dragStatus;
|
|
1214
|
+
|
|
1215
|
+
if (dragOverNodeUid === rootId) {
|
|
1216
|
+
realDragStatus = "inside";
|
|
1217
|
+
} else {
|
|
1218
|
+
var overEdge = edges.find(item => item.child === dragOverNodeUid);
|
|
1219
|
+
var overParentNode = nodes.find(item => item.$$uid === overEdge.parent);
|
|
1220
|
+
|
|
1221
|
+
if (overParentNode.instanceId !== parentInstanceId) {
|
|
1222
|
+
// 如果instanceId不相同, 说明父元素被修改, dragStatus强制等于inside, uid也需要切换成实际父元素的uid
|
|
1223
|
+
realDragStatus = "inside";
|
|
1224
|
+
dragOverNodeUid = nodes.find(item => item.instanceId === parentInstanceId).$$uid;
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
|
|
1155
1228
|
var {
|
|
1156
1229
|
parentUid,
|
|
1157
|
-
mountPoint,
|
|
1158
1230
|
sortIndex,
|
|
1159
1231
|
sortUids: nodeUids,
|
|
1160
1232
|
sortNodeIds: nodeIds
|
|
@@ -1164,10 +1236,29 @@ class BuilderDataManager {
|
|
|
1164
1236
|
},
|
|
1165
1237
|
dragNodeUid: newNodeUid,
|
|
1166
1238
|
dragOverNodeUid,
|
|
1167
|
-
dragStatus
|
|
1239
|
+
dragStatus: realDragStatus
|
|
1168
1240
|
});
|
|
1169
|
-
nodeData.parent =
|
|
1241
|
+
nodeData.parent = parentInstanceId;
|
|
1170
1242
|
nodeData.mountPoint = mountPoint;
|
|
1243
|
+
|
|
1244
|
+
if (nodeData.bricks) {
|
|
1245
|
+
// snippet
|
|
1246
|
+
this.snippetApply({
|
|
1247
|
+
parentUid,
|
|
1248
|
+
nodeDetails: nodeData.bricks.map(brickConf => getSnippetNodeDetail({
|
|
1249
|
+
parent: parentInstanceId,
|
|
1250
|
+
parentUid: parentUid,
|
|
1251
|
+
mountPoint: mountPoint,
|
|
1252
|
+
nodeUid: newNodeUid,
|
|
1253
|
+
brickConf: brickConf,
|
|
1254
|
+
isPortalCanvas: false
|
|
1255
|
+
})),
|
|
1256
|
+
nodeIds,
|
|
1257
|
+
nodeUids
|
|
1258
|
+
});
|
|
1259
|
+
return;
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1171
1262
|
this.runAddNodeAction({
|
|
1172
1263
|
nodeUid: newNodeUid,
|
|
1173
1264
|
parentUid,
|
|
@@ -2348,63 +2439,6 @@ function getSortedIdsAfterDropped(droppingInfo) {
|
|
|
2348
2439
|
};
|
|
2349
2440
|
}
|
|
2350
2441
|
|
|
2351
|
-
var jsonFieldsInBrick = ["properties", "events", "lifeCycle", "params", "if", "transform"];
|
|
2352
|
-
var yamlFieldsInBrick = ["permissionsPreCheck", "transformFrom"];
|
|
2353
|
-
var ignoredFieldsInBrick = ["brick", "template", "portal", "slots", "id", "children", "instanceId"];
|
|
2354
|
-
// The reverse operation of *normalize*.
|
|
2355
|
-
// https://github.com/easyops-cn/next-basics/blob/5a6710d567821bcb4a0c71e22d55212193d8b0cb/bricks/next-builder/src/shared/storyboard/buildStoryboard.ts#L394
|
|
2356
|
-
function reverseNormalize(brickConf, ctx) {
|
|
2357
|
-
return Object.fromEntries(Object.entries(brickConf).map(_ref => {
|
|
2358
|
-
var [key, value] = _ref;
|
|
2359
|
-
return value === undefined || ignoredFieldsInBrick.includes(key) ? undefined : jsonFieldsInBrick.includes(key) ? [key, JSON.stringify(value)] : yamlFieldsInBrick.includes(key) ? [key, yaml.safeDump(value)] : [key, value];
|
|
2360
|
-
}).filter(Boolean).concat(Object.entries(ctx.nodeData), [["brick", ctx.nodeData.type === "template" ? brickConf.template : brickConf.brick], ["portal", ctx.isPortalCanvas || brickConf.portal]]));
|
|
2361
|
-
}
|
|
2362
|
-
|
|
2363
|
-
function getSnippetNodeDetail(_ref) {
|
|
2364
|
-
var {
|
|
2365
|
-
parent,
|
|
2366
|
-
parentUid,
|
|
2367
|
-
mountPoint,
|
|
2368
|
-
nodeUid,
|
|
2369
|
-
brickConf,
|
|
2370
|
-
isPortalCanvas,
|
|
2371
|
-
sort
|
|
2372
|
-
} = _ref;
|
|
2373
|
-
var type = brickConf.template ? "template" : brickConf.bg ? "provider" : "brick";
|
|
2374
|
-
return {
|
|
2375
|
-
nodeUid,
|
|
2376
|
-
parentUid,
|
|
2377
|
-
nodeData: reverseNormalize(brickConf, {
|
|
2378
|
-
isPortalCanvas,
|
|
2379
|
-
nodeData: {
|
|
2380
|
-
type,
|
|
2381
|
-
parent,
|
|
2382
|
-
mountPoint,
|
|
2383
|
-
sort
|
|
2384
|
-
}
|
|
2385
|
-
}),
|
|
2386
|
-
children: brickConf.slots ? Object.entries(brickConf.slots).flatMap(_ref2 => {
|
|
2387
|
-
var [mountPoint, slotConf] = _ref2;
|
|
2388
|
-
return slotConf.bricks.map(childBrickConf => ({
|
|
2389
|
-
childBrickConf,
|
|
2390
|
-
mountPoint
|
|
2391
|
-
}));
|
|
2392
|
-
}).map((_ref3, index) => {
|
|
2393
|
-
var {
|
|
2394
|
-
childBrickConf,
|
|
2395
|
-
mountPoint
|
|
2396
|
-
} = _ref3;
|
|
2397
|
-
return getSnippetNodeDetail({
|
|
2398
|
-
parentUid: nodeUid,
|
|
2399
|
-
mountPoint,
|
|
2400
|
-
nodeUid: getUniqueNodeId(),
|
|
2401
|
-
brickConf: childBrickConf,
|
|
2402
|
-
sort: index
|
|
2403
|
-
});
|
|
2404
|
-
}) : []
|
|
2405
|
-
};
|
|
2406
|
-
}
|
|
2407
|
-
|
|
2408
2442
|
function processDrop(_ref) {
|
|
2409
2443
|
var {
|
|
2410
2444
|
manager,
|