@next-core/editor-bricks-helper 0.49.31 → 0.49.33

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.
@@ -16,31 +16,24 @@
16
16
  var ReactDOM__default = /*#__PURE__*/_interopDefaultLegacy(ReactDOM);
17
17
 
18
18
  exports.BuilderDataTransferType = void 0;
19
-
20
19
  (function (BuilderDataTransferType) {
21
20
  BuilderDataTransferType["NODE_TO_ADD"] = "builder/node-to-add";
22
21
  BuilderDataTransferType["NODE_TO_MOVE"] = "builder/node-to-move";
23
22
  BuilderDataTransferType["SNIPPET_TO_APPLY"] = "builder/snippet-to-apply";
24
23
  })(exports.BuilderDataTransferType || (exports.BuilderDataTransferType = {}));
25
-
26
24
  exports.EditorBrickType = void 0;
27
-
28
25
  (function (EditorBrickType) {
29
26
  EditorBrickType["DEFAULT"] = "editorOfDefault";
30
27
  EditorBrickType["CONTAINER"] = "editorOfContainer";
31
28
  EditorBrickType["TRANSPARENT_CONTAINER"] = "editorOfTransparentContainer";
32
29
  })(exports.EditorBrickType || (exports.EditorBrickType = {}));
33
-
34
30
  exports.EditorSelfLayout = void 0;
35
-
36
31
  (function (EditorSelfLayout) {
37
32
  EditorSelfLayout["BLOCK"] = "block";
38
33
  EditorSelfLayout["INLINE"] = "inline";
39
34
  EditorSelfLayout["CONTAINER"] = "container";
40
35
  })(exports.EditorSelfLayout || (exports.EditorSelfLayout = {}));
41
-
42
36
  exports.EditorSlotContentLayout = void 0;
43
-
44
37
  (function (EditorSlotContentLayout) {
45
38
  EditorSlotContentLayout["BLOCK"] = "block";
46
39
  EditorSlotContentLayout["INLINE"] = "inline";
@@ -54,27 +47,23 @@
54
47
  Licensed under the MIT License (MIT), see
55
48
  http://jedwatson.github.io/classnames
56
49
  */
57
-
58
50
  (function (module) {
59
51
  /* global define */
52
+
60
53
  (function () {
61
54
 
62
55
  var hasOwn = {}.hasOwnProperty;
63
-
64
56
  function classNames() {
65
57
  var classes = [];
66
-
67
58
  for (var i = 0; i < arguments.length; i++) {
68
59
  var arg = arguments[i];
69
60
  if (!arg) continue;
70
61
  var argType = typeof arg;
71
-
72
62
  if (argType === 'string' || argType === 'number') {
73
63
  classes.push(arg);
74
64
  } else if (Array.isArray(arg)) {
75
65
  if (arg.length) {
76
66
  var inner = classNames.apply(null, arg);
77
-
78
67
  if (inner) {
79
68
  classes.push(inner);
80
69
  }
@@ -91,10 +80,8 @@
91
80
  }
92
81
  }
93
82
  }
94
-
95
83
  return classes.join(' ');
96
84
  }
97
-
98
85
  if (module.exports) {
99
86
  classNames.default = classNames;
100
87
  module.exports = classNames;
@@ -103,12 +90,10 @@
103
90
  }
104
91
  })();
105
92
  })(classnames);
106
-
107
93
  var classNames = classnames.exports;
108
94
 
109
95
  /*! (c) Andrea Giammarchi - ISC */
110
96
  var self = {};
111
-
112
97
  try {
113
98
  self.EventTarget = new EventTarget().constructor;
114
99
  } catch (EventTarget) {
@@ -120,7 +105,6 @@
120
105
  for (var secret = wm.get(this), listeners = secret[type] || (secret[type] = []), i = 0, length = listeners.length; i < length; i++) {
121
106
  if (listeners[i].listener === listener) return;
122
107
  }
123
-
124
108
  listeners.push({
125
109
  target: this,
126
110
  listener: listener,
@@ -130,7 +114,6 @@
130
114
  define(proto, 'dispatchEvent', function (event) {
131
115
  var secret = wm.get(this);
132
116
  var listeners = secret[event.type];
133
-
134
117
  if (listeners) {
135
118
  define(event, 'target', this);
136
119
  define(event, 'currentTarget', this);
@@ -138,13 +121,11 @@
138
121
  delete event.currentTarget;
139
122
  delete event.target;
140
123
  }
141
-
142
124
  return true;
143
125
  });
144
126
  define(proto, 'removeEventListener', function (type, listener) {
145
- for (var secret = wm.get(this),
146
- /* istanbul ignore next */
147
- listeners = secret[type] || (secret[type] = []), i = 0, length = listeners.length; i < length; i++) {
127
+ for (var secret = wm.get(this), /* istanbul ignore next */
128
+ listeners = secret[type] || (secret[type] = []), i = 0, length = listeners.length; i < length; i++) {
148
129
  if (listeners[i].listener === listener) {
149
130
  listeners.splice(i, 1);
150
131
  return;
@@ -152,12 +133,10 @@
152
133
  }
153
134
  });
154
135
  self.EventTarget = EventTarget;
155
-
156
136
  function EventTarget() {
157
137
 
158
138
  wm.set(this, create(null));
159
139
  }
160
-
161
140
  function define(target, name, value) {
162
141
  defineProperty(target, name, {
163
142
  configurable: true,
@@ -165,7 +144,6 @@
165
144
  value: value
166
145
  });
167
146
  }
168
-
169
147
  function dispatch(info) {
170
148
  var options = info.options;
171
149
  if (options && options.once) info.target.removeEventListener(this.type, info.listener);
@@ -174,7 +152,6 @@
174
152
  }
175
153
  })(Object, new WeakMap());
176
154
  }
177
-
178
155
  var EventTarget$1 = self.EventTarget;
179
156
 
180
157
  var uniqueIdCursor = 0;
@@ -191,32 +168,25 @@
191
168
  } = _ref;
192
169
  var newEdges = edges.slice();
193
170
  var reorderedEdgesMap = new WeakMap();
194
-
195
171
  var walk = (uid, callback) => {
196
172
  var node = nodes.find(item => item.$$uid === uid);
197
173
  var childEdges = lodash.sortBy(edges.filter(edge => edge.parent === node.$$uid), edge => edge.sort);
198
174
  callback(node, childEdges);
199
-
200
175
  for (var edge of childEdges) {
201
176
  walk(edge.child, callback);
202
177
  }
203
178
  };
204
-
205
179
  var expandEdgesThroughTemplateChain = (node, mountPoint, childUid) => {
206
180
  var _node$$$templateProxy;
207
-
208
181
  var proxySlotConf;
209
182
  var delegateToParentUid;
210
-
211
183
  if (node.$$isExpandableTemplate && (_node$$$templateProxy = node.$$templateProxy) !== null && _node$$$templateProxy !== void 0 && _node$$$templateProxy.slots && brickUtils.hasOwnProperty(node.$$templateProxy.slots, mountPoint) && (proxySlotConf = node.$$templateProxy.slots[mountPoint]) && (delegateToParentUid = node.$$templateRefToUid.get(proxySlotConf.ref))) {
212
184
  var nextNode = nodes.find(n => n.$$uid === delegateToParentUid);
213
185
  var nextMountPoint = proxySlotConf.refSlot;
214
-
215
186
  if (nextNode.$$isExpandableTemplate) {
216
187
  expandEdgesThroughTemplateChain(nextNode, nextMountPoint, childUid);
217
188
  } else {
218
189
  var _proxySlotConf$refPos;
219
-
220
190
  var expandedEdge = {
221
191
  child: childUid,
222
192
  parent: delegateToParentUid,
@@ -226,12 +196,11 @@
226
196
  };
227
197
  var siblingEdges = lodash.sortBy(newEdges.filter(edge => edge.parent === delegateToParentUid), edge => {
228
198
  var _reorderedEdgesMap$ge;
229
-
230
199
  return (_reorderedEdgesMap$ge = reorderedEdgesMap.get(edge)) !== null && _reorderedEdgesMap$ge !== void 0 ? _reorderedEdgesMap$ge : edge.sort;
231
200
  });
232
- var internalEdges = siblingEdges.filter(edge => edge.$$isTemplateInternal); // For more details about refPosition implementation detail,
201
+ var internalEdges = siblingEdges.filter(edge => edge.$$isTemplateInternal);
202
+ // For more details about refPosition implementation detail,
233
203
  // see `packages/brick-kit/src/core/CustomTemplates/expandCustomTemplate.ts`.
234
-
235
204
  var refPosition = (_proxySlotConf$refPos = proxySlotConf.refPosition) !== null && _proxySlotConf$refPos !== void 0 ? _proxySlotConf$refPos : -1;
236
205
  var clampedRefPosition = lodash.clamp(refPosition < 0 ? internalEdges.length + 1 + refPosition : refPosition, 0, internalEdges.length);
237
206
  siblingEdges.splice(clampedRefPosition < internalEdges.length ? siblingEdges.findIndex(edge => edge === internalEdges[clampedRefPosition]) : siblingEdges.length, 0, expandedEdge);
@@ -242,18 +211,15 @@
242
211
  }
243
212
  }
244
213
  };
245
-
246
214
  walk(rootId, (node, childEdges) => {
247
215
  if (!node.$$isExpandableTemplate) {
248
216
  return;
249
217
  }
250
-
251
218
  for (var childEdge of childEdges) {
252
219
  // Recursively expand templates.
253
220
  expandEdgesThroughTemplateChain(node, childEdge.mountPoint, childEdge.child);
254
221
  }
255
222
  });
256
-
257
223
  if (newEdges.length > edges.length) {
258
224
  return newEdges.map(edge => {
259
225
  var sort = reorderedEdgesMap.get(edge);
@@ -262,7 +228,6 @@
262
228
  });
263
229
  });
264
230
  }
265
-
266
231
  return edges;
267
232
  }
268
233
 
@@ -308,17 +273,14 @@
308
273
  wrapperNode: (wrapperNode === null || wrapperNode === void 0 ? void 0 : wrapperNode.$$uid) === nodeUid ? null : wrapperNode
309
274
  };
310
275
  }
311
-
312
276
  function collectIdsToDelete(nodeUid, edges, idsToDelete) {
313
277
  idsToDelete.add(nodeUid);
314
278
  var ids = new Set();
315
-
316
279
  for (var edge of edges) {
317
280
  if (edge.parent === nodeUid) {
318
281
  ids.add(edge.child);
319
282
  }
320
283
  }
321
-
322
284
  for (var id of ids) {
323
285
  collectIdsToDelete(id, edges, idsToDelete);
324
286
  }
@@ -328,37 +290,30 @@
328
290
  var nodesMap = new Map();
329
291
  var targetMap = new Map();
330
292
  var targetRefMap = new Map();
331
-
332
293
  for (var n of nodes) {
333
294
  nodesMap.set(n.$$uid, {
334
295
  upstreamNodes: new Set(),
335
296
  downstreamNodes: new Set()
336
297
  });
337
-
338
298
  for (var selector of n.$$matchedSelectors) {
339
299
  if (!targetMap.get(selector)) {
340
300
  targetMap.set(selector, n.$$uid);
341
301
  }
342
302
  }
343
-
344
303
  if (rootNodeIsCustomTemplate) {
345
304
  if (n.ref) {
346
305
  targetRefMap.set(n.ref, n.$$uid);
347
306
  }
348
307
  }
349
308
  }
350
-
351
309
  for (var node of nodes) {
352
310
  var handlers = [];
353
-
354
311
  if (!lodash.isEmpty(node.$$parsedEvents)) {
355
312
  handlers = Object.values(node.$$parsedEvents).flat();
356
313
  }
357
-
358
314
  if (!lodash.isEmpty(node.$$parsedLifeCycle)) {
359
315
  handlers = handlers.concat(Object.entries(node.$$parsedLifeCycle).flatMap(_ref => {
360
316
  var [lifeCycleName, lifeCycleConf] = _ref;
361
-
362
317
  switch (lifeCycleName) {
363
318
  case "onBeforePageLoad":
364
319
  case "onPageLoad":
@@ -368,10 +323,8 @@
368
323
  case "onAnchorUnload":
369
324
  case "onMessageClose":
370
325
  return lifeCycleConf;
371
-
372
326
  case "onMessage":
373
327
  return [].concat(lifeCycleConf).flatMap(messageConf => [].concat(messageConf.handlers));
374
-
375
328
  default:
376
329
  // eslint-disable-next-line no-console
377
330
  console.warn("unknown lifeCycle: ".concat(lifeCycleName));
@@ -379,21 +332,17 @@
379
332
  }
380
333
  }));
381
334
  }
382
-
383
335
  if (handlers.length > 0) {
384
336
  collectRelatedNodes(node, handlers, nodesMap, targetMap, targetRefMap);
385
337
  }
386
338
  }
387
-
388
339
  return nodesMap;
389
340
  }
390
-
391
341
  function collectRelatedNodes(node, handlers, nodesMap, targetMap, targetRefMap) {
392
342
  for (var handler of handlers) {
393
343
  if (handler) {
394
344
  if (handler.target) {
395
345
  var targetNodeUid = targetMap.get(handler.target);
396
-
397
346
  if (targetNodeUid) {
398
347
  nodesMap.get(node.$$uid).downstreamNodes.add(targetNodeUid);
399
348
  nodesMap.get(targetNodeUid).upstreamNodes.add(node.$$uid);
@@ -401,14 +350,12 @@
401
350
  } else if (handler.targetRef) {
402
351
  for (var ref of [].concat(handler.targetRef)) {
403
352
  var targetRefNodeUid = targetRefMap.get(ref);
404
-
405
353
  if (targetRefNodeUid) {
406
354
  nodesMap.get(node.$$uid).downstreamNodes.add(targetRefNodeUid);
407
355
  nodesMap.get(targetRefNodeUid).upstreamNodes.add(node.$$uid);
408
356
  }
409
357
  }
410
358
  }
411
-
412
359
  if (handler.callback) {
413
360
  for (var callbackHandlers of Object.values(handler.callback)) {
414
361
  collectRelatedNodes(node, [].concat(callbackHandlers), nodesMap, targetMap, targetRefMap);
@@ -418,33 +365,28 @@
418
365
  }
419
366
  }
420
367
 
421
- var nodeIgnoreFields = ["parent", "children", "graphInfo", "mountPoint"]; // Match evaluations and placeholders,
422
- // E.g.: `<% QUERY.x %>` or `${QUERY.x}`.
368
+ var nodeIgnoreFields = ["parent", "children", "graphInfo", "mountPoint"];
423
369
 
370
+ // Match evaluations and placeholders,
371
+ // E.g.: `<% QUERY.x %>` or `${QUERY.x}`.
424
372
  var computationRegExp = /[<{]/;
425
373
  function getBuilderNode(nodeData, nodeUid, isTemplateInternalNode) {
426
374
  var matchedSelectors = [];
427
-
428
375
  if (nodeData.brick) {
429
376
  matchedSelectors.push(nodeData.brick.replace(/\./g, "\\."));
430
377
  }
431
-
432
378
  var normalized = brickUtils.normalizeBuilderNode(nodeData);
433
379
  var jsonFieldsInBrick = ["properties", "events", "lifeCycle"];
434
380
  var parsedFields = [];
435
381
  var parsedId;
436
382
  var parsedTestId;
437
-
438
383
  for (var field of jsonFieldsInBrick) {
439
384
  var parsed = lodash.cloneDeep(normalized === null || normalized === void 0 ? void 0 : normalized[field]);
440
385
  parsedFields.push(["$$parsed".concat(lodash.upperFirst(field)), parsed !== null && parsed !== void 0 ? parsed : {}]);
441
-
442
386
  if (field === "properties") {
443
387
  var _parsed$dataset;
444
-
445
388
  var tempParsedId = void 0;
446
389
  var tempParsedTestId = void 0;
447
-
448
390
  if ((tempParsedTestId = parsed === null || parsed === void 0 ? void 0 : (_parsed$dataset = parsed.dataset) === null || _parsed$dataset === void 0 ? void 0 : _parsed$dataset.testid, typeof tempParsedTestId === "string") && !computationRegExp.test(tempParsedTestId)) {
449
391
  parsedTestId = tempParsedTestId;
450
392
  } else if ((tempParsedId = parsed === null || parsed === void 0 ? void 0 : parsed.id, typeof tempParsedId === "string") && !computationRegExp.test(tempParsedId)) {
@@ -453,23 +395,20 @@
453
395
  }
454
396
  }
455
397
  }
456
-
457
398
  var isBrick = brickUtils.isBrickNode(nodeData);
458
399
  var brickName = isBrick ? nodeData.brick.split(".").pop() : null;
459
400
  var unreachable = false;
460
-
461
401
  if ((normalized === null || normalized === void 0 ? void 0 : normalized.if) !== undefined && (isBrick || brickUtils.isRouteNode(nodeData))) {
462
402
  var check = {
463
403
  if: normalized.if
464
404
  };
465
405
  brickUtils.computeConstantCondition(check);
466
-
467
406
  if (check.if === false) {
468
407
  unreachable = true;
469
408
  }
470
409
  }
471
-
472
- return Object.fromEntries(Object.entries(nodeData).filter(entry => !nodeIgnoreFields.includes(entry[0])).concat([["displayName", // Ignore alias which equals to brick name.
410
+ return Object.fromEntries(Object.entries(nodeData).filter(entry => !nodeIgnoreFields.includes(entry[0])).concat([["displayName",
411
+ // Ignore alias which equals to brick name.
473
412
  !(isBrick && nodeData.alias === brickName) && nodeData.alias || (isBrick ? nodeData.ref || parsedTestId || parsedId || brickName : undefined)], ["$$uid", nodeUid], ["$$matchedSelectors", matchedSelectors], ["$$isTemplateInternalNode", isTemplateInternalNode], ["$$normalized", normalized], ["$$unreachable", unreachable]]).concat(parsedFields));
474
413
  }
475
414
 
@@ -478,25 +417,19 @@
478
417
  var nodes = [];
479
418
  var edges = [];
480
419
  var wrapperNode;
481
-
482
420
  var walk = (nodeData, currentUid, processedTemplateSet, isTemplateInternalNode, inheritedTemplateRefToUid, layoutType) => {
483
421
  var _templateSource$child;
484
-
485
422
  var builderNode = getBuilderNode(nodeData, currentUid, isTemplateInternalNode);
486
423
  nodes.push(builderNode);
487
-
488
424
  if (inheritedTemplateRefToUid && builderNode.ref) {
489
425
  inheritedTemplateRefToUid.set(builderNode.ref, currentUid);
490
426
  }
491
-
492
427
  var templateSource;
493
-
494
428
  if (brickUtils.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) {
495
429
  if (templateSource.layoutType === "wrapper") {
496
430
  builderNode.layoutType = "wrapper";
497
- } // Avoid nesting the same templates.
498
-
499
-
431
+ }
432
+ // Avoid nesting the same templates.
500
433
  processedTemplateSet.add(builderNode.brick);
501
434
  builderNode.$$isExpandableTemplate = true;
502
435
  builderNode.$$templateProxy = templateSource.proxy && JSON.parse(templateSource.proxy);
@@ -504,12 +437,12 @@
504
437
  builderNode.$$templateRefToUid = templateRefToUid;
505
438
  var sortedChildren = lodash.sortBy(templateSource.children, [item => {
506
439
  var _item$sort;
507
-
508
440
  return (_item$sort = item.sort) !== null && _item$sort !== void 0 ? _item$sort : -Infinity;
509
441
  }]);
510
442
  sortedChildren.forEach((child, index) => {
511
443
  var childUid = getUniqueNodeId();
512
- walk(child, childUid, // Each child should be a branch.
444
+ walk(child, childUid,
445
+ // Each child should be a branch.
513
446
  new Set(processedTemplateSet), true, templateRefToUid);
514
447
  edges.push({
515
448
  child: childUid,
@@ -519,37 +452,28 @@
519
452
  $$isTemplateInternal: true
520
453
  });
521
454
  });
522
-
523
455
  if (!builderNode.$$isTemplateInternalNode) {
524
456
  // Here all internal nodes of the template including nested templates are ready.
525
457
  var processDelegatingSlots = (cursorNode, mountPoint, rootMountPoint) => {
526
458
  var _cursorNode$$$templat;
527
-
528
459
  if ((_cursorNode$$$templat = cursorNode.$$templateProxy) !== null && _cursorNode$$$templat !== void 0 && _cursorNode$$$templat.slots) {
529
460
  var _cursorNode$$$templat2;
530
-
531
461
  var slotEntries = Object.entries((_cursorNode$$$templat2 = cursorNode.$$templateProxy) === null || _cursorNode$$$templat2 === void 0 ? void 0 : _cursorNode$$$templat2.slots).filter(entry => mountPoint === undefined || entry[0] === mountPoint);
532
-
533
462
  var _loop = function (slotName, slotConf) {
534
463
  var refUid = cursorNode.$$templateRefToUid.get(slotConf.ref);
535
-
536
464
  if (refUid) {
537
465
  var refNode = nodes.find(node => node.$$uid === refUid);
538
-
539
466
  if (refNode.$$isExpandableTemplate) {
540
467
  processDelegatingSlots(refNode, slotConf.refSlot, slotName);
541
468
  } else {
542
469
  if (!refNode.$$delegatedSlots) {
543
470
  refNode.$$delegatedSlots = new Map();
544
471
  }
545
-
546
472
  var delegatedSlotsByRefSlot = refNode.$$delegatedSlots.get(slotConf.refSlot);
547
-
548
473
  if (!delegatedSlotsByRefSlot) {
549
474
  delegatedSlotsByRefSlot = [];
550
475
  refNode.$$delegatedSlots.set(slotConf.refSlot, delegatedSlotsByRefSlot);
551
476
  }
552
-
553
477
  delegatedSlotsByRefSlot.push({
554
478
  templateUid: builderNode.$$uid,
555
479
  templateMountPoint: rootMountPoint || slotName
@@ -557,33 +481,25 @@
557
481
  }
558
482
  }
559
483
  };
560
-
561
484
  for (var [slotName, slotConf] of slotEntries) {
562
485
  _loop(slotName, slotConf);
563
486
  }
564
487
  }
565
488
  };
566
-
567
489
  processDelegatingSlots(builderNode);
568
-
569
490
  var processDelegatingProperties = (cursorNode, previousPropertyName) => {
570
491
  var _cursorNode$$$templat3;
571
-
572
492
  if ((_cursorNode$$$templat3 = cursorNode.$$templateProxy) !== null && _cursorNode$$$templat3 !== void 0 && _cursorNode$$$templat3.properties) {
573
493
  var _cursorNode$$$templat4;
574
-
575
494
  var propertyEntries = Object.entries((_cursorNode$$$templat4 = cursorNode.$$templateProxy) === null || _cursorNode$$$templat4 === void 0 ? void 0 : _cursorNode$$$templat4.properties).filter(entry => previousPropertyName === undefined || entry[0] === previousPropertyName);
576
-
577
495
  for (var [propertyName, propertyConf] of propertyEntries) {
578
496
  if (brickUtils.hasOwnProperty(cursorNode.$$parsedProperties, propertyName) && isBasicRefProperty(propertyConf)) {
579
497
  (function () {
580
498
  var refUid = cursorNode.$$templateRefToUid.get(propertyConf.ref);
581
499
  var propertyValue = cursorNode.$$parsedProperties[propertyName];
582
-
583
500
  if (refUid) {
584
501
  var refNode = nodes.find(node => node.$$uid === refUid);
585
502
  refNode.$$parsedProperties[propertyConf.refProperty] = propertyValue;
586
-
587
503
  if (refNode.$$isExpandableTemplate) {
588
504
  processDelegatingProperties(refNode, propertyConf.refProperty);
589
505
  }
@@ -593,40 +509,33 @@
593
509
  }
594
510
  }
595
511
  };
596
-
597
512
  processDelegatingProperties(builderNode);
598
513
  }
599
514
  }
600
-
601
515
  if (Array.isArray(nodeData.children)) {
602
516
  // For routes and custom-templates, their children are fixed
603
517
  // and mount points should be ignored. To unify tree edge
604
518
  // data structure, just override their mount points.
605
519
  var overrideChildrenMountPoint;
606
-
607
520
  switch (builderNode.type) {
608
521
  case "bricks":
609
522
  case "custom-template":
610
523
  case "snippet":
611
524
  overrideChildrenMountPoint = "bricks";
612
525
  break;
613
-
614
526
  case "routes":
615
527
  overrideChildrenMountPoint = "routes";
616
528
  break;
617
529
  }
618
-
619
530
  var _sortedChildren = lodash.sortBy(nodeData.children, [item => {
620
531
  var _item$sort2;
621
-
622
532
  return (_item$sort2 = item.sort) !== null && _item$sort2 !== void 0 ? _item$sort2 : -Infinity;
623
533
  }]);
624
-
625
534
  _sortedChildren.forEach((child, index) => {
626
535
  var _overrideChildrenMoun;
627
-
628
536
  var childUid = getUniqueNodeId();
629
- walk(child, childUid, // Each child should be a branch.
537
+ walk(child, childUid,
538
+ // Each child should be a branch.
630
539
  new Set(processedTemplateSet), isTemplateInternalNode, inheritedTemplateRefToUid);
631
540
  edges.push({
632
541
  child: childUid,
@@ -639,28 +548,21 @@
639
548
  });
640
549
  }
641
550
  };
642
-
643
551
  walk(nodeData, nodeUid, new Set());
644
-
645
552
  var _loop2 = function (i) {
646
553
  // 布局模板属于第一层
647
554
  var item = nodes[i];
648
-
649
555
  if (item.layoutType === "wrapper" && isRoot && edges.find(edge => edge.child === item.$$uid).parent === nodeUid) {
650
556
  if (!wrapperNode) {
651
557
  wrapperNode = item;
652
558
  }
653
-
654
559
  return "break";
655
560
  }
656
561
  };
657
-
658
562
  for (var i = 0; i < nodes.length; i++) {
659
563
  var _ret = _loop2(i);
660
-
661
564
  if (_ret === "break") break;
662
565
  }
663
-
664
566
  return {
665
567
  nodes,
666
568
  edges,
@@ -740,7 +642,6 @@
740
642
  };
741
643
 
742
644
  var BuilderInternalEventType;
743
-
744
645
  (function (BuilderInternalEventType) {
745
646
  BuilderInternalEventType["NODE_ADD"] = "builder.node.add";
746
647
  BuilderInternalEventType["NODE_MOVE"] = "builder.node.move";
@@ -760,120 +661,87 @@
760
661
  BuilderInternalEventType["DROPPING_STATUS_CHANGE"] = "builder.droppingStatus.change";
761
662
  BuilderInternalEventType["WORKBENCH_TREE_NODE_MOVE"] = "workbench.tree.node.move";
762
663
  })(BuilderInternalEventType || (BuilderInternalEventType = {}));
763
-
764
664
  var storageKeyOfOutlineDisabledNodes = "builder-outline-disabled-nodes";
765
665
  class BuilderDataManager {
766
666
  constructor() {
767
667
  var _this$localJsonStorag;
768
-
769
668
  _defineProperty__default["default"](this, "data", {
770
669
  rootId: null,
771
670
  nodes: [],
772
671
  edges: [],
773
672
  wrapperNode: null
774
673
  });
775
-
776
674
  _defineProperty__default["default"](this, "hoverNodeUid", void 0);
777
-
778
675
  _defineProperty__default["default"](this, "activeNodeUid", void 0);
779
-
780
676
  _defineProperty__default["default"](this, "sharedEditorList", void 0);
781
-
782
677
  _defineProperty__default["default"](this, "routeList", void 0);
783
-
784
678
  _defineProperty__default["default"](this, "storyList", void 0);
785
-
786
679
  _defineProperty__default["default"](this, "eventTarget", new EventTarget$1());
787
-
788
680
  _defineProperty__default["default"](this, "contextMenuStatus", {
789
681
  active: false
790
682
  });
791
-
792
683
  _defineProperty__default["default"](this, "showRelatedNodesBasedOnEvents", void 0);
793
-
794
684
  _defineProperty__default["default"](this, "relatedNodesBasedOnEventsMap", void 0);
795
-
796
685
  _defineProperty__default["default"](this, "highlightNodes", new Set());
797
-
798
686
  _defineProperty__default["default"](this, "templateSourceMap", void 0);
799
-
800
687
  _defineProperty__default["default"](this, "droppingStatus", new Map());
801
-
802
688
  _defineProperty__default["default"](this, "localJsonStorage", new brickUtils.JsonStorage(localStorage));
803
-
804
689
  _defineProperty__default["default"](this, "outlineDisabledNodes", new Set((_this$localJsonStorag = this.localJsonStorage.getItem(storageKeyOfOutlineDisabledNodes)) !== null && _this$localJsonStorag !== void 0 ? _this$localJsonStorag : []));
805
690
  }
806
-
807
691
  getData() {
808
692
  return this.data;
809
693
  }
810
-
811
694
  getContextMenuStatus() {
812
695
  return this.contextMenuStatus;
813
696
  }
814
-
815
697
  getRelatedNodesBasedOnEventsMap() {
816
698
  return this.relatedNodesBasedOnEventsMap;
817
699
  }
818
-
819
700
  sharedEditorListInit(data) {
820
701
  this.sharedEditorList = data;
821
702
  this.eventTarget.dispatchEvent(new CustomEvent(BuilderInternalEventType.SHARED_EDITOR_LIST_CHANGE));
822
703
  }
823
-
824
704
  getSharedEditorList() {
825
705
  var _this$sharedEditorLis;
826
-
827
706
  return (_this$sharedEditorLis = this.sharedEditorList) !== null && _this$sharedEditorLis !== void 0 ? _this$sharedEditorLis : [];
828
707
  }
829
-
830
708
  onSharedEditorListChange(fn) {
831
709
  this.eventTarget.addEventListener(BuilderInternalEventType.SHARED_EDITOR_LIST_CHANGE, fn);
832
710
  return () => {
833
711
  this.eventTarget.removeEventListener(BuilderInternalEventType.SHARED_EDITOR_LIST_CHANGE, fn);
834
712
  };
835
713
  }
836
-
837
714
  routeListInit(data) {
838
715
  this.routeList = data;
839
716
  this.eventTarget.dispatchEvent(new CustomEvent(BuilderInternalEventType.ROUTE_LIST_CHANGE));
840
717
  }
841
-
842
718
  getRouteList() {
843
719
  var _this$routeList;
844
-
845
720
  return (_this$routeList = this.routeList) !== null && _this$routeList !== void 0 ? _this$routeList : [];
846
721
  }
847
-
848
722
  storyListInit(data) {
849
723
  this.storyList = data;
850
724
  }
851
-
852
725
  getStoryList() {
853
726
  return this.storyList;
854
727
  }
855
-
856
728
  onRouteListChange(fn) {
857
729
  this.eventTarget.addEventListener(BuilderInternalEventType.ROUTE_LIST_CHANGE, fn);
858
730
  return () => {
859
731
  this.eventTarget.removeEventListener(BuilderInternalEventType.ROUTE_LIST_CHANGE, fn);
860
732
  };
861
733
  }
862
-
863
734
  dataInit(root, templateSourceMap) {
864
735
  this.templateSourceMap = templateSourceMap;
865
736
  var rootId = getUniqueNodeId();
866
-
867
737
  var newData = _objectSpread__default["default"]({
868
738
  rootId
869
739
  }, getAppendingNodesAndEdges(root, rootId, templateSourceMap, this.storyList, true));
870
-
871
740
  this.data = _objectSpread__default["default"](_objectSpread__default["default"]({}, newData), {}, {
872
741
  edges: expandTemplateEdges(newData)
873
742
  });
874
743
  this.triggerDataChange();
875
744
  }
876
-
877
745
  triggerDataChange() {
878
746
  var {
879
747
  rootId,
@@ -886,7 +754,6 @@
886
754
  detail: this.data
887
755
  }));
888
756
  }
889
-
890
757
  runAddNodeAction(detail) {
891
758
  var {
892
759
  rootId,
@@ -927,12 +794,10 @@
927
794
  });
928
795
  this.triggerDataChange();
929
796
  }
930
-
931
797
  updateBrick(detail) {
932
798
  this.data = deleteNodeFromTree(detail.nodeUid, this.data);
933
799
  this.runAddNodeAction(detail);
934
800
  }
935
-
936
801
  updateNode(instanceId, detail) {
937
802
  var {
938
803
  rootId,
@@ -945,23 +810,19 @@
945
810
  if (item.instanceId === instanceId) {
946
811
  var unreachable = false;
947
812
  var normalized = detail.$$normalized;
948
-
949
813
  if ((normalized === null || normalized === void 0 ? void 0 : normalized.if) !== undefined && (brickUtils.isBrickNode(item) || brickUtils.isRouteNode(item))) {
950
814
  var check = {
951
815
  if: normalized.if
952
816
  };
953
817
  brickUtils.computeConstantCondition(check);
954
-
955
818
  if (check.if === false) {
956
819
  unreachable = true;
957
820
  }
958
821
  }
959
-
960
822
  return _objectSpread__default["default"](_objectSpread__default["default"](_objectSpread__default["default"]({}, item), detail), {}, {
961
823
  $$unreachable: unreachable
962
824
  });
963
825
  }
964
-
965
826
  return item;
966
827
  });
967
828
  var newEdges = detail.mountPoint === undefined || detail.mountPoint === null ? edges : edges.map(item => {
@@ -970,7 +831,6 @@
970
831
  mountPoint: detail.mountPoint
971
832
  });
972
833
  }
973
-
974
834
  return item;
975
835
  });
976
836
  this.data = {
@@ -983,30 +843,24 @@
983
843
  detail: this.data
984
844
  }));
985
845
  }
986
-
987
846
  redirectMountPoint(detail) {
988
847
  var {
989
848
  rootId,
990
849
  wrapperNode
991
850
  } = this.data;
992
-
993
851
  if (detail.parentUid === rootId) {
994
852
  detail.nodeData.mountPoint = "bricks";
995
853
  }
996
-
997
854
  if (wrapperNode && wrapperNode.instanceId === detail.nodeData.parent) {
998
855
  detail.nodeData.mountPoint = "content";
999
856
  }
1000
857
  }
1001
-
1002
858
  redirectSnippetMountPoint(detail) {
1003
859
  var _detail$nodeDetails;
1004
-
1005
860
  (_detail$nodeDetails = detail.nodeDetails) === null || _detail$nodeDetails === void 0 ? void 0 : _detail$nodeDetails.forEach(item => {
1006
861
  this.redirectMountPoint(item);
1007
862
  });
1008
863
  }
1009
-
1010
864
  nodeAdd(detail) {
1011
865
  this.redirectMountPoint(detail);
1012
866
  this.runAddNodeAction(detail);
@@ -1014,7 +868,6 @@
1014
868
  detail
1015
869
  }));
1016
870
  }
1017
-
1018
871
  nodeAddStored(detail) {
1019
872
  var {
1020
873
  rootId,
@@ -1037,7 +890,6 @@
1037
890
  };
1038
891
  this.triggerDataChange();
1039
892
  }
1040
-
1041
893
  snippetApply(detail) {
1042
894
  this.redirectSnippetMountPoint(detail);
1043
895
  var {
@@ -1053,7 +905,6 @@
1053
905
  } = detail;
1054
906
  var newNodes = nodes.slice();
1055
907
  var newEdges = edges.slice();
1056
-
1057
908
  var walk = _ref => {
1058
909
  var {
1059
910
  parentUid,
@@ -1073,16 +924,13 @@
1073
924
  sort: nodeData.sort,
1074
925
  $$isTemplateDelegated: isParentExpandableTemplate(newNodes, parentUid)
1075
926
  }, ...appendingEdges);
1076
-
1077
927
  for (var item of children) {
1078
928
  walk(item);
1079
929
  }
1080
930
  };
1081
-
1082
931
  for (var item of nodeDetails) {
1083
932
  walk(item);
1084
933
  }
1085
-
1086
934
  var newData = {
1087
935
  rootId,
1088
936
  nodes: newNodes,
@@ -1100,7 +948,6 @@
1100
948
  detail
1101
949
  }));
1102
950
  }
1103
-
1104
951
  snippetApplyStored(detail) {
1105
952
  var {
1106
953
  rootId,
@@ -1125,12 +972,11 @@
1125
972
  };
1126
973
  this.triggerDataChange();
1127
974
  }
975
+
1128
976
  /**
1129
977
  * Move node anywhere by drag-n-drop.
1130
978
  * @deprecated use `moveNode` instead.
1131
979
  */
1132
-
1133
-
1134
980
  nodeMove(detail) {
1135
981
  var {
1136
982
  rootId,
@@ -1168,11 +1014,10 @@
1168
1014
  detail
1169
1015
  }));
1170
1016
  }
1017
+
1171
1018
  /**
1172
1019
  * Move node up or down.
1173
1020
  */
1174
-
1175
-
1176
1021
  moveNode(_ref2, direction) {
1177
1022
  var {
1178
1023
  $$uid: nodeUid
@@ -1186,22 +1031,18 @@
1186
1031
  mountPoints
1187
1032
  } = getRelatedEdgesAndMountPoint(this.data.edges, parentUid);
1188
1033
  /** Edges of the same mount-point */
1189
-
1190
1034
  var siblingEdges = relatedEdges.filter(edge => edge.mountPoint === mountPoint);
1191
1035
  var index = siblingEdges.findIndex(edge => edge.child === nodeUid);
1192
1036
  var orderedSiblingEdges = moveItemInList(siblingEdges, index, direction);
1193
-
1194
1037
  if (!orderedSiblingEdges) {
1195
1038
  return;
1196
1039
  }
1197
-
1198
1040
  var orderedEdges = lodash.sortBy(relatedEdges, edge => mountPoints.indexOf(edge.mountPoint), edge => orderedSiblingEdges.indexOf(edge));
1199
1041
  this.reorder(parentUid, orderedEdges);
1200
1042
  this.eventTarget.dispatchEvent(new CustomEvent(BuilderInternalEventType.NODE_UPDATE, {
1201
1043
  detail: this.data
1202
1044
  }));
1203
1045
  }
1204
-
1205
1046
  getDragInfo(_ref3) {
1206
1047
  var {
1207
1048
  nodeData,
@@ -1218,7 +1059,6 @@
1218
1059
  /*
1219
1060
  * 如果找不到edge, 则为新增状态, 否则为移动状态
1220
1061
  */
1221
-
1222
1062
  var dragEdge = edges.find(item => item.child === dragNodeUid);
1223
1063
  var dragOverEdge = edges.find(item => item.child === dragOverNodeUid);
1224
1064
  /**
@@ -1226,7 +1066,6 @@
1226
1066
  * 如果是属于拖动进某个节点中, 默认使用 content
1227
1067
  * 其他情况, 使用被拖拽节点的mountPoint
1228
1068
  */
1229
-
1230
1069
  var mountPoint = isDragRoot ? "bricks" : dragStatus === "inside" ? "content" : dragOverEdge.mountPoint;
1231
1070
  var parentEdge = edges.find(item => item.child === dragOverNodeUid);
1232
1071
  /**
@@ -1234,10 +1073,9 @@
1234
1073
  * 如果是拖动进某个节点, 则当前节点为该节点parent
1235
1074
  * 否则, 等于该节点的父节点
1236
1075
  */
1237
-
1238
1076
  var parentUid = isDragRoot ? rootId : dragStatus === "inside" ? parentEdge.child : parentEdge.parent;
1239
- var parnetNodeData = nodes.find(item => item.$$uid === parentUid); // 找到节点父亲等于拖动节点的父节点(寻找兄弟节点)
1240
-
1077
+ var parnetNodeData = nodes.find(item => item.$$uid === parentUid);
1078
+ // 找到节点父亲等于拖动节点的父节点(寻找兄弟节点)
1241
1079
  var siblingEdge = edges.filter(edge => edge.child !== dragNodeUid && edge.parent === parentUid);
1242
1080
  var sortUids = lodash.sortBy(siblingEdge, "sort").map(item => item.child);
1243
1081
  var sortNodeIds = [];
@@ -1248,24 +1086,21 @@
1248
1086
  sortNodeInstanceIds.push(node.instanceId);
1249
1087
  });
1250
1088
  var sortIndex;
1251
-
1252
1089
  if (dragStatus === "inside") {
1253
- sortIndex = siblingEdge.length ? Math.max(...siblingEdge.map(item => item.sort)) + 1 : 0; // 插入默认插最后
1254
-
1090
+ sortIndex = siblingEdge.length ? Math.max(...siblingEdge.map(item => item.sort)) + 1 : 0;
1091
+ // 插入默认插最后
1255
1092
  sortNodeIds.push(nodeData.id);
1256
1093
  sortNodeInstanceIds.push(nodeData.instanceId);
1257
1094
  } else if (dragStatus === "top" || dragStatus === "bottom") {
1258
1095
  var _dragEdge$child;
1259
-
1260
1096
  var overIndex = sortUids.findIndex(item => item === dragOverNodeUid);
1261
- sortIndex = dragStatus === "top" ? overIndex : overIndex + 1; // 排序修正
1262
-
1263
- sortNodeIds.splice(sortIndex, 0, nodeData.id); // 如果是新增的情况下, 没有edge, 则取dragNodeUid(新创建的uid)
1264
-
1097
+ sortIndex = dragStatus === "top" ? overIndex : overIndex + 1;
1098
+ // 排序修正
1099
+ sortNodeIds.splice(sortIndex, 0, nodeData.id);
1100
+ // 如果是新增的情况下, 没有edge, 则取dragNodeUid(新创建的uid)
1265
1101
  sortUids.splice(sortIndex, 0, (_dragEdge$child = dragEdge === null || dragEdge === void 0 ? void 0 : dragEdge.child) !== null && _dragEdge$child !== void 0 ? _dragEdge$child : dragNodeUid);
1266
1102
  sortNodeInstanceIds.splice(sortIndex, 0, nodeData.instanceId);
1267
1103
  }
1268
-
1269
1104
  return {
1270
1105
  parentUid,
1271
1106
  mountPoint,
@@ -1276,7 +1111,6 @@
1276
1111
  sortNodeInstanceIds
1277
1112
  };
1278
1113
  }
1279
-
1280
1114
  workbenchNodeAdd(detail) {
1281
1115
  var isNeedUpdateSnippet = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
1282
1116
  var {
@@ -1290,30 +1124,25 @@
1290
1124
  dragStatus,
1291
1125
  mountPoint
1292
1126
  } = detail;
1293
-
1294
1127
  if (nodeData.instanceId && !nodeData.instanceId.startsWith("mock")) ; else {
1295
1128
  var _nodeData$id, _nodeData$instanceId;
1296
-
1297
1129
  // insert
1298
1130
  var parentInstanceId = detail.parent || detail.parentInstanceId;
1299
1131
  var newNodeUid = nodeData.$$uid || getUniqueNodeId();
1300
1132
  var overNode = nodes.find(item => item.instanceId === dragOverInstanceId);
1301
1133
  var dragOverNodeUid = overNode.$$uid;
1302
1134
  var realDragStatus = dragStatus;
1303
-
1304
1135
  if (dragOverNodeUid === rootId) {
1305
1136
  realDragStatus = "inside";
1306
1137
  } else {
1307
1138
  var overEdge = edges.find(item => item.child === dragOverNodeUid);
1308
1139
  var overParentNode = nodes.find(item => dragStatus === "inside" ? item.$$uid === overEdge.child : item.$$uid === overEdge.parent);
1309
-
1310
1140
  if (overParentNode.instanceId !== parentInstanceId) {
1311
1141
  // 如果instanceId不相同, 说明父元素被修改, dragStatus强制等于inside, uid也需要切换成实际父元素的uid
1312
1142
  realDragStatus = "inside";
1313
1143
  dragOverNodeUid = nodes.find(item => item.instanceId === parentInstanceId).$$uid;
1314
1144
  }
1315
1145
  }
1316
-
1317
1146
  var {
1318
1147
  parentUid,
1319
1148
  sortIndex,
@@ -1332,7 +1161,6 @@
1332
1161
  nodeData.parent = parentInstanceId;
1333
1162
  nodeData.mountPoint = mountPoint;
1334
1163
  nodeData.sort = sortIndex;
1335
-
1336
1164
  if (nodeData.bricks) {
1337
1165
  // snippet
1338
1166
  var snippetData = {
@@ -1348,14 +1176,12 @@
1348
1176
  nodeIds,
1349
1177
  nodeUids
1350
1178
  };
1351
-
1352
1179
  if (isNeedUpdateSnippet) {
1353
1180
  this.snippetApply(snippetData);
1354
1181
  } else {
1355
1182
  return snippetData;
1356
1183
  }
1357
1184
  }
1358
-
1359
1185
  this.runAddNodeAction({
1360
1186
  nodeUid: newNodeUid,
1361
1187
  parentUid,
@@ -1382,7 +1208,6 @@
1382
1208
  }));
1383
1209
  }
1384
1210
  }
1385
-
1386
1211
  workbenchTreeNodeMove(detail) {
1387
1212
  var {
1388
1213
  rootId,
@@ -1449,11 +1274,10 @@
1449
1274
  detail: this.data
1450
1275
  }));
1451
1276
  }
1277
+
1452
1278
  /**
1453
1279
  * Move mount-point up or down.
1454
1280
  */
1455
-
1456
-
1457
1281
  moveMountPoint(_ref4, mountPoint, direction) {
1458
1282
  var {
1459
1283
  $$uid: parentUid
@@ -1464,15 +1288,12 @@
1464
1288
  } = getRelatedEdgesAndMountPoint(this.data.edges, parentUid);
1465
1289
  var index = mountPoints.indexOf(mountPoint);
1466
1290
  var orderedMountPoints = moveItemInList(mountPoints, index, direction);
1467
-
1468
1291
  if (!orderedMountPoints) {
1469
1292
  return;
1470
1293
  }
1471
-
1472
1294
  var orderedEdges = lodash.sortBy(relatedEdges, edge => orderedMountPoints.indexOf(edge.mountPoint), "sort");
1473
1295
  this.reorder(parentUid, orderedEdges);
1474
1296
  }
1475
-
1476
1297
  reorder(parentUid, orderedEdges) {
1477
1298
  var {
1478
1299
  nodes
@@ -1495,7 +1316,6 @@
1495
1316
  }
1496
1317
  }));
1497
1318
  }
1498
-
1499
1319
  contextUpdated(detail) {
1500
1320
  var {
1501
1321
  rootId,
@@ -1513,7 +1333,6 @@
1513
1333
  };
1514
1334
  this.triggerDataChange();
1515
1335
  }
1516
-
1517
1336
  nodeReorder(detail) {
1518
1337
  var {
1519
1338
  nodeUids,
@@ -1530,234 +1349,195 @@
1530
1349
  detail
1531
1350
  }));
1532
1351
  }
1533
-
1534
1352
  nodeDelete(detail) {
1535
1353
  this.data = deleteNodeFromTree(detail.$$uid, this.data);
1536
1354
  this.triggerDataChange();
1537
1355
  }
1538
-
1539
1356
  nodeClick(detail) {
1540
1357
  this.setActiveNodeUid(detail.$$uid);
1541
1358
  this.eventTarget.dispatchEvent(new CustomEvent(BuilderInternalEventType.NODE_CLICK, {
1542
1359
  detail
1543
1360
  }));
1544
1361
  }
1545
-
1546
1362
  contextMenuChange(detail) {
1547
1363
  this.contextMenuStatus = detail;
1548
1364
  this.eventTarget.dispatchEvent(new CustomEvent(BuilderInternalEventType.CONTEXT_MENU_CHANGE));
1549
1365
  }
1550
-
1551
1366
  onDataChange(fn) {
1552
1367
  this.eventTarget.addEventListener(BuilderInternalEventType.DATA_CHANGE, fn);
1553
1368
  return () => {
1554
1369
  this.eventTarget.removeEventListener(BuilderInternalEventType.DATA_CHANGE, fn);
1555
1370
  };
1556
1371
  }
1557
-
1558
1372
  onNodeAdd(fn) {
1559
1373
  this.eventTarget.addEventListener(BuilderInternalEventType.NODE_ADD, fn);
1560
1374
  return () => {
1561
1375
  this.eventTarget.removeEventListener(BuilderInternalEventType.NODE_ADD, fn);
1562
1376
  };
1563
1377
  }
1564
-
1565
1378
  onSnippetApply(fn) {
1566
1379
  this.eventTarget.addEventListener(BuilderInternalEventType.SNIPPET_APPLY, fn);
1567
1380
  return () => {
1568
1381
  this.eventTarget.removeEventListener(BuilderInternalEventType.SNIPPET_APPLY, fn);
1569
1382
  };
1570
1383
  }
1571
-
1572
1384
  onNodeReorder(fn) {
1573
1385
  this.eventTarget.addEventListener(BuilderInternalEventType.NODE_REORDER, fn);
1574
1386
  return () => {
1575
1387
  this.eventTarget.removeEventListener(BuilderInternalEventType.NODE_REORDER, fn);
1576
1388
  };
1577
1389
  }
1578
-
1579
1390
  onNodeMove(fn) {
1580
1391
  this.eventTarget.addEventListener(BuilderInternalEventType.NODE_MOVE, fn);
1581
1392
  return () => {
1582
1393
  this.eventTarget.removeEventListener(BuilderInternalEventType.NODE_MOVE, fn);
1583
1394
  };
1584
1395
  }
1585
-
1586
1396
  onWorkbenchTreeNodeMove(fn) {
1587
1397
  this.eventTarget.addEventListener(BuilderInternalEventType.WORKBENCH_TREE_NODE_MOVE, fn);
1588
1398
  return () => {
1589
1399
  this.eventTarget.removeEventListener(BuilderInternalEventType.WORKBENCH_TREE_NODE_MOVE, fn);
1590
1400
  };
1591
1401
  }
1592
-
1593
1402
  onNodeClick(fn) {
1594
1403
  this.eventTarget.addEventListener(BuilderInternalEventType.NODE_CLICK, fn);
1595
1404
  return () => {
1596
1405
  this.eventTarget.removeEventListener(BuilderInternalEventType.NODE_CLICK, fn);
1597
1406
  };
1598
1407
  }
1599
-
1600
1408
  onNodeUpdate(fn) {
1601
1409
  this.eventTarget.addEventListener(BuilderInternalEventType.NODE_UPDATE, fn);
1602
1410
  return () => {
1603
1411
  this.eventTarget.removeEventListener(BuilderInternalEventType.NODE_UPDATE, fn);
1604
1412
  };
1605
1413
  }
1606
-
1607
1414
  onContextMenuChange(fn) {
1608
1415
  this.eventTarget.addEventListener(BuilderInternalEventType.CONTEXT_MENU_CHANGE, fn);
1609
1416
  return () => {
1610
1417
  this.eventTarget.removeEventListener(BuilderInternalEventType.CONTEXT_MENU_CHANGE, fn);
1611
1418
  };
1612
1419
  }
1613
-
1614
1420
  setShowRelatedNodesBasedOnEvents(show) {
1615
1421
  this.showRelatedNodesBasedOnEvents = show;
1616
1422
  this.eventTarget.dispatchEvent(new CustomEvent(BuilderInternalEventType.SHOW_RELATED_NODES_BASED_ON_EVENTS));
1617
1423
  }
1618
-
1619
1424
  getShowRelatedNodesBasedOnEvents() {
1620
1425
  return this.showRelatedNodesBasedOnEvents;
1621
1426
  }
1622
-
1623
1427
  onShowRelatedNodesBasedOnEventsChange(fn) {
1624
1428
  this.eventTarget.addEventListener(BuilderInternalEventType.SHOW_RELATED_NODES_BASED_ON_EVENTS, fn);
1625
1429
  return () => {
1626
1430
  this.eventTarget.removeEventListener(BuilderInternalEventType.SHOW_RELATED_NODES_BASED_ON_EVENTS, fn);
1627
1431
  };
1628
1432
  }
1629
-
1630
1433
  setHoverNodeUid(uid) {
1631
1434
  if (this.hoverNodeUid !== uid) {
1632
1435
  this.hoverNodeUid = uid;
1633
1436
  this.eventTarget.dispatchEvent(new CustomEvent(BuilderInternalEventType.HOVER_NODE_CHANGE));
1634
1437
  }
1635
1438
  }
1636
-
1637
1439
  getHoverNodeUid() {
1638
1440
  return this.hoverNodeUid;
1639
1441
  }
1640
-
1641
1442
  onHoverNodeChange(fn) {
1642
1443
  this.eventTarget.addEventListener(BuilderInternalEventType.HOVER_NODE_CHANGE, fn);
1643
1444
  return () => {
1644
1445
  this.eventTarget.removeEventListener(BuilderInternalEventType.HOVER_NODE_CHANGE, fn);
1645
1446
  };
1646
1447
  }
1647
-
1648
1448
  setActiveNodeUid(uid) {
1649
1449
  if (this.activeNodeUid !== uid) {
1650
1450
  this.activeNodeUid = uid;
1651
1451
  this.eventTarget.dispatchEvent(new CustomEvent(BuilderInternalEventType.ACTIVE_NODE_CHANGE));
1652
1452
  }
1653
1453
  }
1654
-
1655
1454
  getActiveNodeUid() {
1656
1455
  return this.activeNodeUid;
1657
1456
  }
1658
-
1659
1457
  onActiveNodeChange(fn) {
1660
1458
  this.eventTarget.addEventListener(BuilderInternalEventType.ACTIVE_NODE_CHANGE, fn);
1661
1459
  return () => {
1662
1460
  this.eventTarget.removeEventListener(BuilderInternalEventType.ACTIVE_NODE_CHANGE, fn);
1663
1461
  };
1664
1462
  }
1665
-
1666
1463
  toggleOutline(nodeInstanceId) {
1667
1464
  if (this.outlineDisabledNodes.has(nodeInstanceId)) {
1668
1465
  this.outlineDisabledNodes.delete(nodeInstanceId);
1669
1466
  } else {
1670
1467
  this.outlineDisabledNodes.add(nodeInstanceId);
1671
1468
  }
1672
-
1673
1469
  this.localJsonStorage.setItem(storageKeyOfOutlineDisabledNodes, Array.from(this.outlineDisabledNodes));
1674
1470
  this.eventTarget.dispatchEvent(new CustomEvent(BuilderInternalEventType.OUTLINE_DISABLED_NODES_CHANGE));
1675
1471
  }
1676
-
1677
1472
  isOutlineEnabled(nodeInstanceId) {
1678
1473
  return !this.outlineDisabledNodes.has(nodeInstanceId);
1679
1474
  }
1680
-
1681
1475
  onOutlineEnabledNodesChange(fn) {
1682
1476
  this.eventTarget.addEventListener(BuilderInternalEventType.OUTLINE_DISABLED_NODES_CHANGE, fn);
1683
1477
  return () => {
1684
1478
  this.eventTarget.removeEventListener(BuilderInternalEventType.OUTLINE_DISABLED_NODES_CHANGE, fn);
1685
1479
  };
1686
1480
  }
1687
-
1688
1481
  setHighlightNodes(nodeUids) {
1689
1482
  this.highlightNodes = nodeUids;
1690
1483
  this.eventTarget.dispatchEvent(new CustomEvent(BuilderInternalEventType.HIGHLIGHT_NODES_CHANGE));
1691
1484
  }
1692
-
1693
1485
  getHighlightNodes() {
1694
1486
  return this.highlightNodes;
1695
1487
  }
1696
-
1697
1488
  onHighlightNodesChange(fn) {
1698
1489
  this.eventTarget.addEventListener(BuilderInternalEventType.HIGHLIGHT_NODES_CHANGE, fn);
1699
1490
  return () => {
1700
1491
  this.eventTarget.removeEventListener(BuilderInternalEventType.HIGHLIGHT_NODES_CHANGE, fn);
1701
1492
  };
1702
1493
  }
1703
-
1704
1494
  updateDroppingStatus(nodeUid, mountPoint, isDraggingOver) {
1705
1495
  var nodeStatus = this.droppingStatus.get(nodeUid);
1706
1496
  this.droppingStatus = new Map(Array.from(this.droppingStatus.entries()).concat([[nodeUid, new Map((nodeStatus ? Array.from(nodeStatus) : []).concat([[mountPoint, isDraggingOver]]))]]));
1707
- this.eventTarget.dispatchEvent(new CustomEvent(BuilderInternalEventType.DROPPING_STATUS_CHANGE)); // When dragging nodes over `EditorContainer`, the `mouseout` events
1497
+ this.eventTarget.dispatchEvent(new CustomEvent(BuilderInternalEventType.DROPPING_STATUS_CHANGE));
1498
+
1499
+ // When dragging nodes over `EditorContainer`, the `mouseout` events
1708
1500
  // are not triggered, which causes hover status does not get cleared.
1709
1501
  // So we manually reset hover status once dragging starts.
1710
-
1711
1502
  if (this.hoverNodeUid && Array.from(this.droppingStatus.values()).flatMap(nodeStatus => Array.from(nodeStatus.values())).some(Boolean)) {
1712
1503
  this.setHoverNodeUid(undefined);
1713
1504
  }
1714
1505
  }
1715
-
1716
1506
  getDroppingStatus() {
1717
1507
  return this.droppingStatus;
1718
1508
  }
1719
-
1720
1509
  onDroppingStatusChange(fn) {
1721
1510
  this.eventTarget.addEventListener(BuilderInternalEventType.DROPPING_STATUS_CHANGE, fn);
1722
1511
  return () => {
1723
1512
  this.eventTarget.removeEventListener(BuilderInternalEventType.DROPPING_STATUS_CHANGE, fn);
1724
1513
  };
1725
1514
  }
1726
-
1727
1515
  }
1728
-
1729
1516
  function getRelatedEdgesAndMountPoint(edges, parentUid) {
1730
1517
  var relatedEdges = lodash.sortBy(edges.filter(edge => edge.parent === parentUid && !edge.$$isTemplateExpanded), "sort");
1731
1518
  var mountPointSet = new Set();
1732
-
1733
1519
  for (var edge of relatedEdges) {
1734
1520
  mountPointSet.add(edge.mountPoint);
1735
1521
  }
1736
-
1737
1522
  var mountPoints = Array.from(mountPointSet);
1738
1523
  return {
1739
1524
  relatedEdges,
1740
1525
  mountPoints
1741
1526
  };
1742
1527
  }
1743
-
1744
1528
  function moveItemInList(list, index, direction) {
1745
1529
  var upperIndex;
1746
-
1747
1530
  if (direction === "up") {
1748
1531
  if (index <= 0) {
1749
1532
  return;
1750
1533
  }
1751
-
1752
1534
  upperIndex = index - 1;
1753
1535
  } else {
1754
1536
  if (index === -1 || index >= list.length - 1) {
1755
1537
  return;
1756
1538
  }
1757
-
1758
1539
  upperIndex = index;
1759
1540
  }
1760
-
1761
1541
  return [...list.slice(0, upperIndex), list[upperIndex + 1], list[upperIndex], ...list.slice(upperIndex + 2)];
1762
1542
  }
1763
1543
 
@@ -1772,11 +1552,9 @@
1772
1552
  var {
1773
1553
  manager
1774
1554
  } = React__default["default"].useContext(BuilderContext);
1775
-
1776
1555
  if (!manager) {
1777
1556
  throw new Error("Expected builder data context");
1778
1557
  }
1779
-
1780
1558
  return manager;
1781
1559
  }
1782
1560
 
@@ -1805,7 +1583,6 @@
1805
1583
  if (isWrapper) {
1806
1584
  return wrapperNode;
1807
1585
  }
1808
-
1809
1586
  return nodes.find(node => node.$$uid === currentUid);
1810
1587
  }, [nodes, currentUid, isWrapper, wrapperNode]);
1811
1588
  }
@@ -1831,15 +1608,12 @@
1831
1608
  function styleInject(css, ref) {
1832
1609
  if (ref === void 0) ref = {};
1833
1610
  var insertAt = ref.insertAt;
1834
-
1835
1611
  if (!css || typeof document === 'undefined') {
1836
1612
  return;
1837
1613
  }
1838
-
1839
1614
  var head = document.head || document.getElementsByTagName('head')[0];
1840
1615
  var style = document.createElement('style');
1841
1616
  style.type = 'text/css';
1842
-
1843
1617
  if (insertAt === 'top') {
1844
1618
  if (head.firstChild) {
1845
1619
  head.insertBefore(style, head.firstChild);
@@ -1849,7 +1623,6 @@
1849
1623
  } else {
1850
1624
  head.appendChild(style);
1851
1625
  }
1852
-
1853
1626
  if (style.styleSheet) {
1854
1627
  style.styleSheet.cssText = css;
1855
1628
  } else {
@@ -1864,21 +1637,17 @@
1864
1637
  function isCurrentTargetByClassName(targetElement, currentElement) {
1865
1638
  // Traverse DOM from bottom to top.
1866
1639
  var element = targetElement;
1867
-
1868
1640
  while (element) {
1869
1641
  if (element === currentElement) {
1870
1642
  return true;
1871
1643
  }
1872
-
1873
1644
  if (element.classList.contains(styles$3.editorContainer) && !element.classList.contains(styles$3.isTemplateInternalNode)) {
1874
1645
  // It's not the current target if
1875
1646
  // matches another editor container first.
1876
1647
  return false;
1877
1648
  }
1878
-
1879
1649
  element = element.parentElement;
1880
1650
  }
1881
-
1882
1651
  return false;
1883
1652
  }
1884
1653
 
@@ -1911,7 +1680,6 @@
1911
1680
 
1912
1681
  function EditorContainer(_ref) {
1913
1682
  var _droppingStatus$get$v, _droppingStatus$get;
1914
-
1915
1683
  var {
1916
1684
  nodeUid,
1917
1685
  type,
@@ -1941,7 +1709,6 @@
1941
1709
  var handleMouseOver = React.useCallback(event => {
1942
1710
  event.stopPropagation();
1943
1711
  setHover(true);
1944
-
1945
1712
  if (hoverNodeUidRef.current !== nodeUid) {
1946
1713
  manager.setHoverNodeUid(nodeUid);
1947
1714
  }
@@ -1949,7 +1716,6 @@
1949
1716
  var handleMouseOut = React.useCallback(event => {
1950
1717
  event.stopPropagation();
1951
1718
  setHover(false);
1952
-
1953
1719
  if (hoverNodeUidRef.current === nodeUid) {
1954
1720
  manager.setHoverNodeUid(undefined);
1955
1721
  }
@@ -1957,10 +1723,9 @@
1957
1723
  React.useEffect(() => {
1958
1724
  if (node.$$isTemplateInternalNode) {
1959
1725
  return;
1960
- } // Manually bind listeners since events which cross custom-elements
1726
+ }
1727
+ // Manually bind listeners since events which cross custom-elements
1961
1728
  // seem not working in React v16.
1962
-
1963
-
1964
1729
  var editorContainer = editorContainerRef.current;
1965
1730
  editorContainer.addEventListener("mouseover", handleMouseOver);
1966
1731
  editorContainer.addEventListener("mouseout", handleMouseOut);
@@ -1973,20 +1738,13 @@
1973
1738
  if (node.$$isTemplateInternalNode) {
1974
1739
  return;
1975
1740
  }
1976
-
1977
1741
  setHover(hoverNodeUid === nodeUid);
1978
-
1979
1742
  if (showRelatedEvents) {
1980
1743
  var _relatedNodes$get, _relatedNodes$get2;
1981
-
1982
1744
  var relatedNodes = manager.getRelatedNodesBasedOnEventsMap();
1983
-
1984
1745
  var _isUpstreamNode = (_relatedNodes$get = relatedNodes.get(hoverNodeUid)) === null || _relatedNodes$get === void 0 ? void 0 : _relatedNodes$get.upstreamNodes.has(nodeUid);
1985
-
1986
1746
  setIsUpstreamNode(_isUpstreamNode);
1987
-
1988
1747
  var _isDownstreamNode = (_relatedNodes$get2 = relatedNodes.get(hoverNodeUid)) === null || _relatedNodes$get2 === void 0 ? void 0 : _relatedNodes$get2.downstreamNodes.has(nodeUid);
1989
-
1990
1748
  setIsDownstreamNode(_isDownstreamNode);
1991
1749
  }
1992
1750
  }, [hoverNodeUid, node, nodeUid, showRelatedEvents, manager]);
@@ -2038,6 +1796,7 @@
2038
1796
 
2039
1797
  var ANY_BRICK_EDITOR = "basic-bricks.any-brick--editor";
2040
1798
  var ANY_ROUTE_EDITOR = "basic-bricks.any-route--editor";
1799
+
2041
1800
  /**
2042
1801
  * Get editor brick name by node.
2043
1802
  *
@@ -2053,44 +1812,36 @@
2053
1812
  *
2054
1813
  * And returns undefined if load failed.
2055
1814
  */
2056
-
2057
1815
  function getEditorBrick(_x, _x2) {
2058
1816
  return _getEditorBrick.apply(this, arguments);
2059
1817
  }
2060
-
2061
1818
  function _getEditorBrick() {
2062
1819
  _getEditorBrick = _asyncToGenerator__default["default"](function* (node, editor) {
2063
1820
  var tryEditorBricks = [];
2064
-
2065
1821
  if (brickUtils.isRouteNode(node)) {
2066
1822
  tryEditorBricks.push(ANY_ROUTE_EDITOR);
2067
1823
  } else if (brickUtils.isBrickNode(node)) {
2068
1824
  if (node.brick.includes("-")) {
2069
1825
  tryEditorBricks.push("".concat(node.brick, "--editor"));
2070
1826
  }
2071
-
2072
1827
  if (editor) {
2073
1828
  tryEditorBricks.push(editor);
2074
1829
  }
2075
-
2076
1830
  tryEditorBricks.push(ANY_BRICK_EDITOR);
2077
1831
  } else {
2078
1832
  // Currently there should be no custom-template nodes to be rendered as editor.
2079
1833
  throw new Error("Unsupported node type: ".concat(node.type));
2080
1834
  }
2081
-
2082
1835
  for (var editorBrick of tryEditorBricks) {
2083
1836
  try {
2084
1837
  yield brickKit.developHelper.loadEditorBricks([editorBrick]);
2085
1838
  } catch (error) {
2086
1839
  throw new Error("Load editor brick \"".concat(editorBrick, "\" failed"));
2087
1840
  }
2088
-
2089
1841
  if (customElements.get(editorBrick)) {
2090
1842
  return editorBrick;
2091
1843
  }
2092
1844
  }
2093
-
2094
1845
  throw new Error("Editor brick \"".concat(tryEditorBricks.join(", "), "\" not found"));
2095
1846
  });
2096
1847
  return _getEditorBrick.apply(this, arguments);
@@ -2143,7 +1894,6 @@
2143
1894
  setInitialized(false);
2144
1895
  var editorName;
2145
1896
  var editorError;
2146
-
2147
1897
  try {
2148
1898
  editorName = yield getEditorBrick(node, installedBricksEnabled ? editorConf === null || editorConf === void 0 ? void 0 : editorConf.editor : brickDoc === null || brickDoc === void 0 ? void 0 : brickDoc.editor);
2149
1899
  } catch (error) {
@@ -2151,7 +1901,6 @@
2151
1901
  console.error(error);
2152
1902
  editorError = error.message;
2153
1903
  }
2154
-
2155
1904
  setEditorBrick(editorName);
2156
1905
  setLoadEditorError(editorError);
2157
1906
  setInitialized(true);
@@ -2166,15 +1915,12 @@
2166
1915
  }), [brickDoc, editorBrick, editorConf, installedBricksEnabled, node.$$uid]);
2167
1916
  var selfLayout = React__default["default"].useMemo(() => {
2168
1917
  var _layout;
2169
-
2170
1918
  var layout;
2171
-
2172
1919
  if (initialized && editorBrick) {
2173
1920
  var editorConstructor = customElements.get(editorBrick);
2174
1921
  layout = editorConstructor.selfLayout;
2175
- } // For bricks with no editors, display as a container if it has children.
2176
-
2177
-
1922
+ }
1923
+ // For bricks with no editors, display as a container if it has children.
2178
1924
  return (_layout = layout) !== null && _layout !== void 0 ? _layout : hasChildren ? exports.EditorSelfLayout.CONTAINER : exports.EditorSelfLayout.INLINE;
2179
1925
  }, [initialized, editorBrick, hasChildren]);
2180
1926
  var [{
@@ -2246,21 +1992,17 @@
2246
1992
  } = _ref2;
2247
1993
  var groups = new Map();
2248
1994
  var relatedEdges = lodash.sortBy(edges.filter(edge => edge.parent === nodeUid && (doNotExpandTemplates ? !edge.$$isTemplateInternal : !edge.$$isTemplateDelegated)), [edge => edge.sort]);
2249
-
2250
1995
  var _loop = function (edge) {
2251
1996
  var childNode = nodes.find(node => node.$$uid === edge.child);
2252
-
2253
1997
  if (groups.has(edge.mountPoint)) {
2254
1998
  groups.get(edge.mountPoint).push(childNode);
2255
1999
  } else {
2256
2000
  groups.set(edge.mountPoint, [childNode]);
2257
2001
  }
2258
2002
  };
2259
-
2260
2003
  for (var edge of relatedEdges) {
2261
2004
  _loop(edge);
2262
2005
  }
2263
-
2264
2006
  return Array.from(groups.entries()).map(_ref3 => {
2265
2007
  var [mountPoint, childNodes] = _ref3;
2266
2008
  return {
@@ -2286,29 +2028,26 @@
2286
2028
  if (parentId === nodeUid) {
2287
2029
  return false;
2288
2030
  }
2289
-
2290
2031
  return !edges.some(edge => {
2291
2032
  if (edge.parent === parentId) {
2292
2033
  return !traverse(edge.child);
2293
2034
  }
2294
-
2295
2035
  return false;
2296
2036
  });
2297
2037
  };
2298
-
2299
2038
  return traverse(draggingUid);
2300
2039
  }, [edges]);
2301
2040
  }
2302
2041
 
2303
2042
  /* istanbul-ignore-file */
2304
2043
  // Todo(steve): Ignore tests temporarily for potential breaking change in the future.
2044
+
2305
2045
  var defaultGapHalf = 6;
2306
2046
  function getDropPositions(dropZone, dropZoneGrid) {
2307
- var zoneRect = dropZone.getBoundingClientRect(); // const gridRect = dropZoneGrid.getBoundingClientRect();
2308
-
2047
+ var zoneRect = dropZone.getBoundingClientRect();
2048
+ // const gridRect = dropZoneGrid.getBoundingClientRect();
2309
2049
  var positions = [];
2310
2050
  var gridItemList = Array.from(dropZoneGrid.children).filter(item => !item.classList.contains("__isTemplateInternalNode"));
2311
-
2312
2051
  if (gridItemList.length > 0) {
2313
2052
  var currentRow = {
2314
2053
  cells: []
@@ -2324,10 +2063,8 @@
2324
2063
  right: rect.right
2325
2064
  };
2326
2065
  var prevCell = currentRow.cells.length > 0 && currentRow.cells[currentRow.cells.length - 1];
2327
-
2328
2066
  if (!prevCell || compareApproximately(rect.left, prevCell.right) > 0 && compareApproximately(rect.top, prevCell.bottom) < 0) {
2329
2067
  var _currentRow$top, _currentRow$bottom;
2330
-
2331
2068
  currentRow.cells.push(cell);
2332
2069
  currentRow.top = Math.min((_currentRow$top = currentRow.top) !== null && _currentRow$top !== void 0 ? _currentRow$top : Infinity, rect.top);
2333
2070
  currentRow.bottom = Math.max((_currentRow$bottom = currentRow.bottom) !== null && _currentRow$bottom !== void 0 ? _currentRow$bottom : -Infinity, rect.bottom);
@@ -2339,7 +2076,8 @@
2339
2076
  };
2340
2077
  rows.push(currentRow);
2341
2078
  }
2342
- }); // console.log(rows);
2079
+ });
2080
+ // console.log(rows);
2343
2081
 
2344
2082
  var lastRectBottom = zoneRect.top;
2345
2083
  var nextCursorTop = zoneRect.top;
@@ -2360,8 +2098,9 @@
2360
2098
  }
2361
2099
  });
2362
2100
  lastRectBottom = rectBottom;
2363
- nextCursorTop = cell.bottom; // Append one more insert position after reached the end.
2101
+ nextCursorTop = cell.bottom;
2364
2102
 
2103
+ // Append one more insert position after reached the end.
2365
2104
  if (rowIndex === rows.length - 1) {
2366
2105
  positions.push({
2367
2106
  rect: {
@@ -2377,9 +2116,7 @@
2377
2116
  });
2378
2117
  } else if (rows[rowIndex + 1].cells.length > 1) {
2379
2118
  var nextRow = rows[rowIndex + 1];
2380
-
2381
2119
  var _rectBottom = (cell.bottom + nextRow.top) / 2;
2382
-
2383
2120
  positions.push({
2384
2121
  rect: {
2385
2122
  top: lastRectBottom,
@@ -2397,9 +2134,7 @@
2397
2134
  } else {
2398
2135
  var lastRectRight = zoneRect.left;
2399
2136
  var nextCursorLeft = zoneRect.left;
2400
-
2401
2137
  var _rectBottom2 = rowIndex < rows.length - 1 ? (rows[rowIndex + 1].top + row.bottom) / 2 : zoneRect.bottom;
2402
-
2403
2138
  var cursorDefault = {
2404
2139
  isVertical: true,
2405
2140
  y: row.top - zoneRect.top,
@@ -2420,8 +2155,9 @@
2420
2155
  })
2421
2156
  });
2422
2157
  lastRectRight = rectRight;
2423
- nextCursorLeft = cell.right; // Append one more insert position after reached the row end.
2158
+ nextCursorLeft = cell.right;
2424
2159
 
2160
+ // Append one more insert position after reached the row end.
2425
2161
  if (cellIndex === row.cells.length - 1) {
2426
2162
  if (rowIndex === rows.length - 1) {
2427
2163
  positions.push({
@@ -2457,12 +2193,10 @@
2457
2193
  }
2458
2194
  });
2459
2195
  }
2460
-
2461
2196
  return positions;
2462
2197
  }
2463
2198
  function getDropPosition(x, y, dropZone, dropZoneGrid) {
2464
2199
  var positions = getDropPositions(dropZone, dropZoneGrid);
2465
-
2466
2200
  for (var {
2467
2201
  rect,
2468
2202
  cursor
@@ -2472,13 +2206,11 @@
2472
2206
  return cursor;
2473
2207
  }
2474
2208
  }
2475
-
2476
2209
  return {
2477
2210
  index: 0,
2478
2211
  y: 5
2479
2212
  };
2480
2213
  }
2481
-
2482
2214
  function compareApproximately(a, b) {
2483
2215
  var diff = a - b;
2484
2216
  return Math.abs(diff) < 1 ? 0 : diff;
@@ -2536,17 +2268,15 @@
2536
2268
  droppingMountPoint,
2537
2269
  droppingSiblingGroups,
2538
2270
  droppingIndex
2539
- } = droppingInfo; // When applying a snippet, the dragging nodes will be an array.
2540
-
2271
+ } = droppingInfo;
2272
+ // When applying a snippet, the dragging nodes will be an array.
2541
2273
  var draggingNodeUids = Array.isArray(draggingNodeUid) ? draggingNodeUid : [draggingNodeUid];
2542
2274
  var fullChildNodes = droppingSiblingGroups.flatMap(group => group.childNodes);
2543
2275
  var nodeUids = droppingSiblingGroups.flatMap(group => {
2544
2276
  var uids = group.childNodes.map(item => item.$$uid).filter(uid => !draggingNodeUids.includes(uid));
2545
-
2546
2277
  if (group.mountPoint === droppingMountPoint) {
2547
2278
  uids.splice((draggingIndex !== null && draggingIndex !== void 0 ? draggingIndex : -1) >= 0 && droppingIndex > draggingIndex ? droppingIndex - 1 : droppingIndex, 0, ...draggingNodeUids);
2548
2279
  }
2549
-
2550
2280
  return uids;
2551
2281
  });
2552
2282
  var nodeIds = nodeUids.map(uid => draggingNodeUids.includes(uid) ? draggingNodeId : fullChildNodes.find(item => item.$$uid === uid).id);
@@ -2569,7 +2299,6 @@
2569
2299
  droppingSiblingGroups,
2570
2300
  isPortalCanvas
2571
2301
  } = _ref;
2572
-
2573
2302
  if (type === exports.BuilderDataTransferType.NODE_TO_ADD) {
2574
2303
  // Drag a new node into canvas.
2575
2304
  var {
@@ -2598,8 +2327,8 @@
2598
2327
  } else if (type === exports.BuilderDataTransferType.SNIPPET_TO_APPLY) {
2599
2328
  var {
2600
2329
  bricks
2601
- } = data; // https://stackoverflow.com/questions/5501581/javascript-new-arrayn-and-array-prototype-map-weirdness
2602
-
2330
+ } = data;
2331
+ // https://stackoverflow.com/questions/5501581/javascript-new-arrayn-and-array-prototype-map-weirdness
2603
2332
  var draggingNodeUids = [...new Array(bricks.length)].map(() => getUniqueNodeId());
2604
2333
  manager.snippetApply(_objectSpread__default["default"](_objectSpread__default["default"]({}, getSortedIdsAfterDropped({
2605
2334
  draggingNodeUid: draggingNodeUids,
@@ -2624,9 +2353,9 @@
2624
2353
  nodeId: draggingNodeId,
2625
2354
  nodeInstanceId: draggingNodeInstanceId
2626
2355
  } = data;
2627
- var draggingIndex = droppingChildNodes.findIndex(item => item.$$uid === _draggingNodeUid); // If found dragging node in the same drop zone,
2356
+ var draggingIndex = droppingChildNodes.findIndex(item => item.$$uid === _draggingNodeUid);
2357
+ // If found dragging node in the same drop zone,
2628
2358
  // then apply a node reorder, otherwise apply a node move.
2629
-
2630
2359
  if (draggingIndex >= 0) {
2631
2360
  // If the index is not changed, then there is nothing to do.
2632
2361
  if (droppingIndex !== draggingIndex && droppingIndex !== draggingIndex + 1) {
@@ -2665,7 +2394,6 @@
2665
2394
  return React.useMemo(() => {
2666
2395
  var mainCanvas = [];
2667
2396
  var portalCanvasList = [];
2668
-
2669
2397
  for (var child of rootChildNodes) {
2670
2398
  if (child.portal) {
2671
2399
  portalCanvasList.push([child]);
@@ -2673,7 +2401,6 @@
2673
2401
  mainCanvas.push(child);
2674
2402
  }
2675
2403
  }
2676
-
2677
2404
  return [mainCanvas, ...portalCanvasList, []];
2678
2405
  }, [rootChildNodes]);
2679
2406
  }
@@ -2729,32 +2456,27 @@
2729
2456
  var refinedSlotContentLayout = slotContentLayout !== null && slotContentLayout !== void 0 ? slotContentLayout : exports.EditorSlotContentLayout.BLOCK;
2730
2457
  var selfChildNodes = React__default["default"].useMemo(() => {
2731
2458
  var _groupedChildNodes$fi, _groupedChildNodes$fi2;
2732
-
2733
2459
  return (_groupedChildNodes$fi = (_groupedChildNodes$fi2 = groupedChildNodes.find(group => group.mountPoint === mountPoint)) === null || _groupedChildNodes$fi2 === void 0 ? void 0 : _groupedChildNodes$fi2.childNodes) !== null && _groupedChildNodes$fi !== void 0 ? _groupedChildNodes$fi : [];
2734
2460
  }, [groupedChildNodes, mountPoint]);
2735
2461
  var canvasList = useCanvasList(selfChildNodes);
2736
2462
  var selfChildNodesInCurrentCanvas = React__default["default"].useMemo(() => separateCanvas ? selfChildNodes.filter(child => Boolean(Number(Boolean(isPortalCanvas)) ^ Number(!child.portal))) : independentPortalCanvas ? canvasList[lodash.clamp(canvasIndex !== null && canvasIndex !== void 0 ? canvasIndex : 0, 0, canvasList.length - 1)] : selfChildNodes, [canvasIndex, independentPortalCanvas, isPortalCanvas, selfChildNodes, canvasList, separateCanvas]);
2737
2463
  var canvasSettings = React__default["default"].useMemo(() => {
2738
2464
  var _selfChildNodesInCurr;
2739
-
2740
2465
  return (_selfChildNodesInCurr = selfChildNodesInCurrentCanvas[0]) === null || _selfChildNodesInCurr === void 0 ? void 0 : _selfChildNodesInCurr.$$parsedProperties._canvas_;
2741
2466
  }, [selfChildNodesInCurrentCanvas]);
2742
2467
  var getDroppingIndexInFullCanvas = React__default["default"].useCallback(droppingIndexInCurrentCanvas => {
2743
2468
  if (!hasTabs) {
2744
2469
  return droppingIndexInCurrentCanvas;
2745
2470
  }
2746
-
2747
2471
  if (selfChildNodesInCurrentCanvas.length > 0) {
2748
2472
  var cursorNode = selfChildNodesInCurrentCanvas[droppingIndexInCurrentCanvas === 0 ? 0 : droppingIndexInCurrentCanvas - 1];
2749
2473
  return selfChildNodes.findIndex(child => child === cursorNode) + (droppingIndexInCurrentCanvas === 0 ? 0 : 1);
2750
2474
  }
2751
-
2752
2475
  return isGeneralizedPortalCanvas ? selfChildNodes.length : 0;
2753
2476
  }, [hasTabs, selfChildNodesInCurrentCanvas, isGeneralizedPortalCanvas, selfChildNodes]);
2754
2477
  var getDroppingContext = React__default["default"].useCallback(() => {
2755
2478
  if (delegatedContext) {
2756
2479
  var _siblingGroups$find$c, _siblingGroups$find;
2757
-
2758
2480
  var siblingGroups = getBuilderGroupedChildNodes({
2759
2481
  nodeUid: delegatedContext.templateUid,
2760
2482
  nodes,
@@ -2769,7 +2491,6 @@
2769
2491
  droppingSiblingGroups: siblingGroups
2770
2492
  };
2771
2493
  }
2772
-
2773
2494
  return {
2774
2495
  droppingParentUid: node.$$uid,
2775
2496
  droppingParentInstanceId: isWrapper ? wrapperNode.instanceId : node.instanceId,
@@ -2803,10 +2524,9 @@
2803
2524
  drop: (item, monitor) => {
2804
2525
  if (!monitor.didDrop()) {
2805
2526
  var {
2806
- type
2807
- } = item,
2808
- data = _objectWithoutProperties__default["default"](item, _excluded);
2809
-
2527
+ type
2528
+ } = item,
2529
+ data = _objectWithoutProperties__default["default"](item, _excluded);
2810
2530
  processDrop(_objectSpread__default["default"]({
2811
2531
  type: type,
2812
2532
  data,
@@ -2824,7 +2544,6 @@
2824
2544
  var dropZoneRef = React__default["default"].useRef();
2825
2545
  var dropZoneRefCallback = React__default["default"].useCallback(element => {
2826
2546
  dropZoneRef.current = element;
2827
-
2828
2547
  if (droppable) {
2829
2548
  dropRef(element);
2830
2549
  }
@@ -2883,7 +2602,6 @@
2883
2602
  /* istanbul-ignore-file */
2884
2603
  function SlotContainer(_ref) {
2885
2604
  var _droppingStatus$get;
2886
-
2887
2605
  var {
2888
2606
  nodeUid,
2889
2607
  slotName,
@@ -2900,9 +2618,8 @@
2900
2618
  var droppingStatus = useDroppingStatus();
2901
2619
  var delegatedContext = React.useMemo(() => {
2902
2620
  var _node$$$delegatedSlot;
2903
-
2904
- var delegatedSlots = (_node$$$delegatedSlot = node.$$delegatedSlots) === null || _node$$$delegatedSlot === void 0 ? void 0 : _node$$$delegatedSlot.get(slotName); // Ignore when there are more than one delegated slots on a single slot.
2905
-
2621
+ var delegatedSlots = (_node$$$delegatedSlot = node.$$delegatedSlots) === null || _node$$$delegatedSlot === void 0 ? void 0 : _node$$$delegatedSlot.get(slotName);
2622
+ // Ignore when there are more than one delegated slots on a single slot.
2906
2623
  return (delegatedSlots === null || delegatedSlots === void 0 ? void 0 : delegatedSlots.length) === 1 ? delegatedSlots[0] : null;
2907
2624
  }, [node, slotName]);
2908
2625
  return /*#__PURE__*/React__default["default"].createElement("div", {
@@ -2927,35 +2644,29 @@
2927
2644
  // See https://github.com/react-dnd/react-dnd/blob/main/packages/react-dnd/src/common/DndProvider.tsx
2928
2645
  var BuilderProvider = /*#__PURE__*/React__default["default"].memo(LegacyBuilderProvider);
2929
2646
  var instanceSymbol = Symbol.for("__BRICK_NEXT_BUILDER_CONTEXT_INSTANCE__");
2930
-
2931
2647
  function createSingletonBuilderContext() {
2932
2648
  var ctx = window;
2933
-
2934
2649
  if (!ctx[instanceSymbol]) {
2935
2650
  ctx[instanceSymbol] = createBuilderContext();
2936
2651
  }
2937
-
2938
2652
  return ctx[instanceSymbol];
2939
2653
  }
2940
-
2941
2654
  var refCount = 0;
2942
-
2943
2655
  function LegacyBuilderProvider(_ref) {
2944
2656
  var {
2945
2657
  children
2946
2658
  } = _ref;
2947
2659
  var context = createSingletonBuilderContext();
2660
+
2948
2661
  /**
2949
2662
  * If the global context was used to store the DND context
2950
2663
  * then where theres no more references to it we should
2951
2664
  * clean it up to avoid memory leaks
2952
2665
  */
2953
-
2954
2666
  React__default["default"].useEffect(() => {
2955
2667
  refCount++;
2956
2668
  return () => {
2957
2669
  refCount--;
2958
-
2959
2670
  if (refCount === 0) {
2960
2671
  window[instanceSymbol] = null;
2961
2672
  }
@@ -2971,12 +2682,9 @@
2971
2682
  class NewEditorElement extends _UpdatingElement {
2972
2683
  constructor() {
2973
2684
  super(...arguments);
2974
-
2975
2685
  _initialize(this);
2976
2686
  }
2977
-
2978
2687
  }
2979
-
2980
2688
  return {
2981
2689
  F: NewEditorElement,
2982
2690
  d: [{
@@ -3009,13 +2717,11 @@
3009
2717
  if (!this.style.display) {
3010
2718
  this.style.display = "block";
3011
2719
  }
3012
-
3013
2720
  if (options !== null && options !== void 0 && options.brickStyle) {
3014
2721
  for (var [key, value] of Object.entries(options.brickStyle)) {
3015
2722
  this.style[key] = value;
3016
2723
  }
3017
2724
  }
3018
-
3019
2725
  this._render();
3020
2726
  }
3021
2727
  }, {
@@ -3041,12 +2747,12 @@
3041
2747
  }]
3042
2748
  };
3043
2749
  }, brickKit.UpdatingElement);
3044
-
3045
2750
  return NewEditorElement;
3046
2751
  }
3047
2752
 
3048
- // Todo(steve): remove this file.
2753
+ // It indicates which mount point of a container is active dropping zone.
3049
2754
 
2755
+ // Todo(steve): remove this file.
3050
2756
  /** @deprecated no more usage but for compatibility only. */
3051
2757
  var DroppingStatusContext = /*#__PURE__*/React.createContext({});
3052
2758
 
@@ -3064,11 +2770,9 @@
3064
2770
  return React.useMemo(() => {
3065
2771
  var mountPoints = new Set();
3066
2772
  var relatedEdges = lodash.sortBy(edges.filter(edge => edge.parent === currentUid && (doNotExpandTemplates ? !edge.$$isTemplateInternal : !edge.$$isTemplateDelegated)), [edge => edge.sort]);
3067
-
3068
2773
  for (var edge of relatedEdges) {
3069
2774
  mountPoints.add(edge.mountPoint);
3070
2775
  }
3071
-
3072
2776
  return Array.from(mountPoints);
3073
2777
  }, [currentUid, edges, doNotExpandTemplates]);
3074
2778
  }