@next-core/editor-bricks-helper 0.49.30 → 0.49.32

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