@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/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
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.42.0](https://github.com/easyops-cn/next-core/compare/@next-core/editor-bricks-helper@0.41.1...@next-core/editor-bricks-helper@0.42.0) (2022-06-14)
7
+
8
+
9
+ ### Features
10
+
11
+ * **BuilderDataManager:** support preview snippet apply ([ef506d4](https://github.com/easyops-cn/next-core/commit/ef506d4ae83946665e1a30a125948ff5504ba4aa))
12
+
13
+
14
+
15
+
16
+
6
17
  ## [0.41.1](https://github.com/easyops-cn/next-core/compare/@next-core/editor-bricks-helper@0.41.0...@next-core/editor-bricks-helper@0.41.1) (2022-06-10)
7
18
 
8
19
  **Note:** Version bump only for package @next-core/editor-bricks-helper
@@ -1,17 +1,17 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('@babel/runtime/helpers/objectSpread2'), require('@babel/runtime/helpers/defineProperty'), require('lodash'), require('@next-core/brick-utils'), require('@babel/runtime/helpers/objectWithoutProperties'), require('react-dnd'), require('@babel/runtime/helpers/asyncToGenerator'), require('@next-core/brick-kit'), require('js-yaml'), require('@babel/runtime/helpers/decorate'), require('react-dom'), require('react-dnd-html5-backend')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'react', '@babel/runtime/helpers/objectSpread2', '@babel/runtime/helpers/defineProperty', 'lodash', '@next-core/brick-utils', '@babel/runtime/helpers/objectWithoutProperties', 'react-dnd', '@babel/runtime/helpers/asyncToGenerator', '@next-core/brick-kit', 'js-yaml', '@babel/runtime/helpers/decorate', 'react-dom', 'react-dnd-html5-backend'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.EditorBricksHelper = {}, global.React, global._objectSpread, global._defineProperty, global.lodash, global.brickUtils, global._objectWithoutProperties, global.reactDnd, global._asyncToGenerator, global.brickKit, global.yaml, global._decorate, global.ReactDOM, global.reactDndHtml5Backend));
5
- })(this, (function (exports, React, _objectSpread, _defineProperty, lodash, brickUtils, _objectWithoutProperties, reactDnd, _asyncToGenerator, brickKit, yaml, _decorate, ReactDOM, reactDndHtml5Backend) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('@babel/runtime/helpers/objectSpread2'), require('@babel/runtime/helpers/defineProperty'), require('lodash'), require('@next-core/brick-utils'), require('js-yaml'), require('@babel/runtime/helpers/objectWithoutProperties'), require('react-dnd'), require('@babel/runtime/helpers/asyncToGenerator'), require('@next-core/brick-kit'), require('@babel/runtime/helpers/decorate'), require('react-dom'), require('react-dnd-html5-backend')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'react', '@babel/runtime/helpers/objectSpread2', '@babel/runtime/helpers/defineProperty', 'lodash', '@next-core/brick-utils', 'js-yaml', '@babel/runtime/helpers/objectWithoutProperties', 'react-dnd', '@babel/runtime/helpers/asyncToGenerator', '@next-core/brick-kit', '@babel/runtime/helpers/decorate', 'react-dom', 'react-dnd-html5-backend'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.EditorBricksHelper = {}, global.React, global._objectSpread, global._defineProperty, global.lodash, global.brickUtils, global.yaml, global._objectWithoutProperties, global.reactDnd, global._asyncToGenerator, global.brickKit, global._decorate, global.ReactDOM, global.reactDndHtml5Backend));
5
+ })(this, (function (exports, React, _objectSpread, _defineProperty, lodash, brickUtils, yaml, _objectWithoutProperties, reactDnd, _asyncToGenerator, brickKit, _decorate, ReactDOM, reactDndHtml5Backend) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
9
9
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
10
10
  var _objectSpread__default = /*#__PURE__*/_interopDefaultLegacy(_objectSpread);
11
11
  var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
12
+ var yaml__default = /*#__PURE__*/_interopDefaultLegacy(yaml);
12
13
  var _objectWithoutProperties__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutProperties);
13
14
  var _asyncToGenerator__default = /*#__PURE__*/_interopDefaultLegacy(_asyncToGenerator);
14
- var yaml__default = /*#__PURE__*/_interopDefaultLegacy(yaml);
15
15
  var _decorate__default = /*#__PURE__*/_interopDefaultLegacy(_decorate);
16
16
  var ReactDOM__default = /*#__PURE__*/_interopDefaultLegacy(ReactDOM);
17
17
 
@@ -660,6 +660,63 @@
660
660
  return nodes.find(node => node.$$uid === parentUid).$$isExpandableTemplate;
661
661
  }
662
662
 
663
+ var jsonFieldsInBrick = ["properties", "events", "lifeCycle", "params", "if", "transform"];
664
+ var yamlFieldsInBrick = ["permissionsPreCheck", "transformFrom"];
665
+ var ignoredFieldsInBrick = ["brick", "template", "portal", "slots", "id", "children", "instanceId"];
666
+ // The reverse operation of *normalize*.
667
+ // https://github.com/easyops-cn/next-basics/blob/5a6710d567821bcb4a0c71e22d55212193d8b0cb/bricks/next-builder/src/shared/storyboard/buildStoryboard.ts#L394
668
+ function reverseNormalize(brickConf, ctx) {
669
+ return Object.fromEntries(Object.entries(brickConf).map(_ref => {
670
+ var [key, value] = _ref;
671
+ return value === undefined || ignoredFieldsInBrick.includes(key) ? undefined : jsonFieldsInBrick.includes(key) ? [key, JSON.stringify(value)] : yamlFieldsInBrick.includes(key) ? [key, yaml__default["default"].safeDump(value)] : [key, value];
672
+ }).filter(Boolean).concat(Object.entries(ctx.nodeData), [["brick", ctx.nodeData.type === "template" ? brickConf.template : brickConf.brick], ["portal", ctx.isPortalCanvas || brickConf.portal]]));
673
+ }
674
+
675
+ function getSnippetNodeDetail(_ref) {
676
+ var {
677
+ parent,
678
+ parentUid,
679
+ mountPoint,
680
+ nodeUid,
681
+ brickConf,
682
+ isPortalCanvas,
683
+ sort
684
+ } = _ref;
685
+ var type = brickConf.template ? "template" : brickConf.bg ? "provider" : "brick";
686
+ return {
687
+ nodeUid,
688
+ parentUid,
689
+ nodeData: reverseNormalize(brickConf, {
690
+ isPortalCanvas,
691
+ nodeData: {
692
+ type,
693
+ parent,
694
+ mountPoint,
695
+ sort
696
+ }
697
+ }),
698
+ children: brickConf.slots ? Object.entries(brickConf.slots).flatMap(_ref2 => {
699
+ var [mountPoint, slotConf] = _ref2;
700
+ return slotConf.bricks.map(childBrickConf => ({
701
+ childBrickConf,
702
+ mountPoint
703
+ }));
704
+ }).map((_ref3, index) => {
705
+ var {
706
+ childBrickConf,
707
+ mountPoint
708
+ } = _ref3;
709
+ return getSnippetNodeDetail({
710
+ parentUid: nodeUid,
711
+ mountPoint,
712
+ nodeUid: getUniqueNodeId(),
713
+ brickConf: childBrickConf,
714
+ sort: index
715
+ });
716
+ }) : []
717
+ };
718
+ }
719
+
663
720
  var BuilderInternalEventType;
664
721
 
665
722
  (function (BuilderInternalEventType) {
@@ -1153,6 +1210,7 @@
1153
1210
  // insert
1154
1211
  var newNodeUid = getUniqueNodeId();
1155
1212
  var isRoot = dragOverNodeInstanceId === "#main-mount-point";
1213
+ var parentInstanceId = isRoot ? nodes.find(item => item.$$uid === rootId).instanceId : dragOverNodeInstanceId;
1156
1214
  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
1215
  var {
1158
1216
  parentUid,
@@ -1170,6 +1228,25 @@
1170
1228
  });
1171
1229
  nodeData.parent = nodes.find(item => item.$$uid === parentUid).instanceId;
1172
1230
  nodeData.mountPoint = mountPoint;
1231
+
1232
+ if (nodeData.bricks) {
1233
+ // snippet
1234
+ this.snippetApply({
1235
+ parentUid,
1236
+ nodeDetails: nodeData.bricks.map(brickConf => getSnippetNodeDetail({
1237
+ parent: parentInstanceId,
1238
+ parentUid: parentUid,
1239
+ mountPoint: mountPoint,
1240
+ nodeUid: newNodeUid,
1241
+ brickConf: brickConf,
1242
+ isPortalCanvas: false
1243
+ })),
1244
+ nodeIds,
1245
+ nodeUids
1246
+ });
1247
+ return;
1248
+ }
1249
+
1173
1250
  this.runAddNodeAction({
1174
1251
  nodeUid: newNodeUid,
1175
1252
  parentUid,
@@ -2350,63 +2427,6 @@
2350
2427
  };
2351
2428
  }
2352
2429
 
2353
- var jsonFieldsInBrick = ["properties", "events", "lifeCycle", "params", "if", "transform"];
2354
- var yamlFieldsInBrick = ["permissionsPreCheck", "transformFrom"];
2355
- var ignoredFieldsInBrick = ["brick", "template", "portal", "slots", "id", "children", "instanceId"];
2356
- // The reverse operation of *normalize*.
2357
- // https://github.com/easyops-cn/next-basics/blob/5a6710d567821bcb4a0c71e22d55212193d8b0cb/bricks/next-builder/src/shared/storyboard/buildStoryboard.ts#L394
2358
- function reverseNormalize(brickConf, ctx) {
2359
- return Object.fromEntries(Object.entries(brickConf).map(_ref => {
2360
- var [key, value] = _ref;
2361
- return value === undefined || ignoredFieldsInBrick.includes(key) ? undefined : jsonFieldsInBrick.includes(key) ? [key, JSON.stringify(value)] : yamlFieldsInBrick.includes(key) ? [key, yaml__default["default"].safeDump(value)] : [key, value];
2362
- }).filter(Boolean).concat(Object.entries(ctx.nodeData), [["brick", ctx.nodeData.type === "template" ? brickConf.template : brickConf.brick], ["portal", ctx.isPortalCanvas || brickConf.portal]]));
2363
- }
2364
-
2365
- function getSnippetNodeDetail(_ref) {
2366
- var {
2367
- parent,
2368
- parentUid,
2369
- mountPoint,
2370
- nodeUid,
2371
- brickConf,
2372
- isPortalCanvas,
2373
- sort
2374
- } = _ref;
2375
- var type = brickConf.template ? "template" : brickConf.bg ? "provider" : "brick";
2376
- return {
2377
- nodeUid,
2378
- parentUid,
2379
- nodeData: reverseNormalize(brickConf, {
2380
- isPortalCanvas,
2381
- nodeData: {
2382
- type,
2383
- parent,
2384
- mountPoint,
2385
- sort
2386
- }
2387
- }),
2388
- children: brickConf.slots ? Object.entries(brickConf.slots).flatMap(_ref2 => {
2389
- var [mountPoint, slotConf] = _ref2;
2390
- return slotConf.bricks.map(childBrickConf => ({
2391
- childBrickConf,
2392
- mountPoint
2393
- }));
2394
- }).map((_ref3, index) => {
2395
- var {
2396
- childBrickConf,
2397
- mountPoint
2398
- } = _ref3;
2399
- return getSnippetNodeDetail({
2400
- parentUid: nodeUid,
2401
- mountPoint,
2402
- nodeUid: getUniqueNodeId(),
2403
- brickConf: childBrickConf,
2404
- sort: index
2405
- });
2406
- }) : []
2407
- };
2408
- }
2409
-
2410
2430
  function processDrop(_ref) {
2411
2431
  var {
2412
2432
  manager,