@next-core/editor-bricks-helper 0.41.1 → 0.42.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
@@ -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) {
@@ -1151,6 +1208,7 @@ class BuilderDataManager {
1151
1208
  // insert
1152
1209
  var newNodeUid = getUniqueNodeId();
1153
1210
  var isRoot = dragOverNodeInstanceId === "#main-mount-point";
1211
+ var parentInstanceId = isRoot ? nodes.find(item => item.$$uid === rootId).instanceId : dragOverNodeInstanceId;
1154
1212
  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
1213
  var {
1156
1214
  parentUid,
@@ -1168,6 +1226,25 @@ class BuilderDataManager {
1168
1226
  });
1169
1227
  nodeData.parent = nodes.find(item => item.$$uid === parentUid).instanceId;
1170
1228
  nodeData.mountPoint = mountPoint;
1229
+
1230
+ if (nodeData.bricks) {
1231
+ // snippet
1232
+ this.snippetApply({
1233
+ parentUid,
1234
+ nodeDetails: nodeData.bricks.map(brickConf => getSnippetNodeDetail({
1235
+ parent: parentInstanceId,
1236
+ parentUid: parentUid,
1237
+ mountPoint: mountPoint,
1238
+ nodeUid: newNodeUid,
1239
+ brickConf: brickConf,
1240
+ isPortalCanvas: false
1241
+ })),
1242
+ nodeIds,
1243
+ nodeUids
1244
+ });
1245
+ return;
1246
+ }
1247
+
1171
1248
  this.runAddNodeAction({
1172
1249
  nodeUid: newNodeUid,
1173
1250
  parentUid,
@@ -2348,63 +2425,6 @@ function getSortedIdsAfterDropped(droppingInfo) {
2348
2425
  };
2349
2426
  }
2350
2427
 
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
2428
  function processDrop(_ref) {
2409
2429
  var {
2410
2430
  manager,