@themarioga/grid-editor 9.0.0-beta.5 → 9.0.0-beta.6

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.
Files changed (63) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/README.md +23 -17
  3. package/UPGRADING.md +24 -5
  4. package/dist/grideditor.bundle.min.js +3 -3
  5. package/dist/grideditor.css +5 -4
  6. package/dist/grideditor.d.ts +6 -18
  7. package/dist/grideditor.esm.js +122 -100
  8. package/dist/grideditor.jquery.js +1 -3
  9. package/dist/grideditor.jquery.min.js +1 -1
  10. package/dist/grideditor.jquery.min.js.map +2 -2
  11. package/dist/grideditor.js +122 -100
  12. package/dist/grideditor.min.css +1 -1
  13. package/dist/grideditor.min.css.map +1 -1
  14. package/dist/grideditor.min.js +2 -2
  15. package/dist/grideditor.min.js.map +3 -3
  16. package/dist/plugins/grideditor.accordion.esm.js +7 -0
  17. package/dist/plugins/grideditor.accordion.js +7 -0
  18. package/dist/plugins/grideditor.accordion.min.js +1 -1
  19. package/dist/plugins/grideditor.accordion.min.js.map +3 -3
  20. package/dist/plugins/grideditor.card.esm.js +4 -0
  21. package/dist/plugins/grideditor.card.js +4 -0
  22. package/dist/plugins/grideditor.card.min.js +1 -1
  23. package/dist/plugins/grideditor.card.min.js.map +3 -3
  24. package/dist/plugins/grideditor.carousel.esm.js +4 -0
  25. package/dist/plugins/grideditor.carousel.js +4 -0
  26. package/dist/plugins/grideditor.carousel.min.js +1 -1
  27. package/dist/plugins/grideditor.carousel.min.js.map +2 -2
  28. package/dist/plugins/grideditor.clipboard.esm.js +3 -18
  29. package/dist/plugins/grideditor.clipboard.js +3 -18
  30. package/dist/plugins/grideditor.clipboard.min.js +1 -1
  31. package/dist/plugins/grideditor.clipboard.min.js.map +3 -3
  32. package/dist/plugins/grideditor.history.esm.js +1 -6
  33. package/dist/plugins/grideditor.history.js +1 -6
  34. package/dist/plugins/grideditor.history.min.js +1 -1
  35. package/dist/plugins/grideditor.history.min.js.map +3 -3
  36. package/dist/plugins/grideditor.offcanvas.esm.js +4 -0
  37. package/dist/plugins/grideditor.offcanvas.js +4 -0
  38. package/dist/plugins/grideditor.offcanvas.min.js +1 -1
  39. package/dist/plugins/grideditor.offcanvas.min.js.map +3 -3
  40. package/dist/plugins/grideditor.popup.esm.js +4 -0
  41. package/dist/plugins/grideditor.popup.js +4 -0
  42. package/dist/plugins/grideditor.popup.min.js +1 -1
  43. package/dist/plugins/grideditor.popup.min.js.map +3 -3
  44. package/dist/plugins/grideditor.tabs.esm.js +4 -0
  45. package/dist/plugins/grideditor.tabs.js +4 -0
  46. package/dist/plugins/grideditor.tabs.min.js +1 -1
  47. package/dist/plugins/grideditor.tabs.min.js.map +2 -2
  48. package/docs/events.md +8 -11
  49. package/docs/plugins.md +10 -8
  50. package/example/clipboard.html +13 -10
  51. package/package.json +1 -1
  52. package/src/js/grideditor.jquery.js +0 -2
  53. package/src/js/grideditor.js +177 -110
  54. package/src/js/plugins/grideditor.accordion.js +9 -0
  55. package/src/js/plugins/grideditor.card.js +5 -0
  56. package/src/js/plugins/grideditor.carousel.js +5 -0
  57. package/src/js/plugins/grideditor.clipboard.js +11 -24
  58. package/src/js/plugins/grideditor.history.js +3 -6
  59. package/src/js/plugins/grideditor.offcanvas.js +5 -0
  60. package/src/js/plugins/grideditor.popup.js +5 -0
  61. package/src/js/plugins/grideditor.tabs.js +5 -0
  62. package/src/less/grideditor.less +5 -4
  63. package/types/grideditor.d.ts +6 -18
@@ -38,8 +38,6 @@ var METHODS = {
38
38
  setUtility: { value: true },
39
39
  getActiveTarget: { value: true },
40
40
  setActiveTarget: {},
41
- getSelected: { value: true },
42
- setSelected: {},
43
41
  };
44
42
 
45
43
  /**
@@ -443,8 +441,8 @@ function build(instance, baseElem, optionsOrMethod) {
443
441
  settings[name] = Object.assign({}, NESTED_SETTINGS[name], settings[name]);
444
442
  });
445
443
 
446
- // The sidebar shows what is selected and the toolbar adds to the
447
- // target: both follow the node last clicked, so one asks for the other.
444
+ // The sidebar shows the target and the toolbar adds to it: both
445
+ // follow the node last clicked, so one asks for the other.
448
446
  // Read from what the host gave, as the default is already in settings
449
447
  if (settings.settings_panel === 'sidebar') {
450
448
  if (optionsOrMethod && optionsOrMethod.active_target === false) {
@@ -469,7 +467,7 @@ function build(instance, baseElem, optionsOrMethod) {
469
467
  var sourceOpen = false; // Whether the canvas is being edited as html
470
468
  var previewing = false; // Whether the preview button is pressed: not while the mouse is only over it
471
469
  var dropMarker = null; // The line showing where a dragged toolbar button would land
472
- var activeTarget = null; // The column or region the toolbar adds to, with active_target
470
+ var activeTarget = null; // The node the toolbar adds to, and the sidebar shows, with active_target
473
471
  var toolbarLifetime = null; // Aborted when the toolbar is rebuilt or taken away
474
472
  var closeOverflowMenu = function() {}; // Folds the toolbar's overflow menu away, when it has one
475
473
  var refitToolbar = function() {}; // Works out again what the toolbar's overflow menu holds, when it has one
@@ -480,7 +478,6 @@ function build(instance, baseElem, optionsOrMethod) {
480
478
  var sortables = []; // Every list made sortable, so deinit destroys exactly those
481
479
  var instanceId = ++editorCounter; // Scopes the sortable groups to this editor
482
480
  var destroyed = false;
483
- var selected = null; // The node whose settings the sidebar shows, with settings_panel 'sidebar'
484
481
  var sidebarCollapsed = null; // Folded away, once the sidebar has been shown: the window's width decides the first time
485
482
  var pluginHandle = null; // What the plugins were handed, for the hooks that call them back
486
483
 
@@ -1098,9 +1095,7 @@ function build(instance, baseElem, optionsOrMethod) {
1098
1095
  /* A click on the host's plain content offers to make it a text */
1099
1096
  dom.delegate(canvas, 'click', '.ge-content', onContentClick, signal);
1100
1097
 
1101
- var sidebarMode = panelMode() === 'sidebar';
1102
-
1103
- if (settings.active_target || sidebarMode) {
1098
+ if (settings.active_target) {
1104
1099
  // The click a drag ends in - a resize, a move - is not one:
1105
1100
  // it comes where the pointer let go, not where it pressed
1106
1101
  var pressed = null;
@@ -1113,66 +1108,73 @@ function build(instance, baseElem, optionsOrMethod) {
1113
1108
  if (!dom.hasClass(canvas, 'ge-editing')) { return; }
1114
1109
  if (from && Math.abs(e.clientX - from.x) + Math.abs(e.clientY - from.y) > settings.drag.threshold) { return; }
1115
1110
 
1116
- if (settings.active_target) { clickTarget(e); }
1117
- // A tool that took its node off the canvas says nothing of where the click was
1118
- if (sidebarMode && canvas.contains(e.target)) { changeSelection(settingsNodeAt(e.target)); }
1111
+ clickTarget(e);
1119
1112
  }, signal);
1120
1113
 
1121
1114
  // Escape is the panel's, the dialog's, and a field's or a
1122
1115
  // text's while one has the focus; after those, it is the
1123
- // selection's, and then the target's
1116
+ // target's
1124
1117
  document.addEventListener('keydown', function(e) {
1125
1118
  if (e.key !== 'Escape' || openSettingsState || dialogState) { return; }
1126
1119
  if (confirmDialog && dom.hasClass(confirmDialog, 'show')) { return; }
1127
1120
  var focus = document.activeElement;
1128
1121
  if (focus && (dom.is(focus, 'input, textarea, select') || focus.isContentEditable)) { return; }
1129
1122
 
1130
- if (selected && isEditing()) {
1131
- changeSelection(null);
1132
- } else if (activeTarget) {
1133
- changeTarget(null);
1134
- }
1123
+ if (activeTarget) { changeTarget(null); }
1135
1124
  }, signal);
1136
- }
1137
1125
 
1138
- if (sidebarMode) {
1139
- // The focus coming into a node selects it, as a click does
1126
+ // The focus coming into a node makes it the target, as a click does
1140
1127
  canvas.addEventListener('focusin', function(e) {
1141
1128
  var node = isEditing() ? settingsNodeAt(e.target) : null;
1142
- if (node) { changeSelection(node); }
1129
+ if (node) { changeTarget(node); }
1143
1130
  }, signal);
1144
1131
 
1145
1132
  // A click on the page, away from the canvas and the editor's own
1146
- // controls, puts the selection away - not while a text is open,
1147
- // whose editor has controls of its own out there
1133
+ // controls, puts the target away - not while a text is open,
1134
+ // whose editor has controls of its own out there. Nor the
1135
+ // click a drag from the toolbar ends in, which the browser
1136
+ // gives to what holds both the toolbar and the canvas
1137
+ var pressedOn = null;
1138
+ document.addEventListener('pointerdown', function(e) { pressedOn = e.target; }, { capture: true, signal: signal.signal });
1148
1139
  document.addEventListener('click', function(e) {
1149
1140
  var target = e.target;
1150
- if (!selected || !isEditing() || !target || target.nodeType !== 1) { return; }
1141
+ var from = pressedOn;
1142
+ pressedOn = null;
1143
+ if (!activeTarget || !isEditing() || !target || target.nodeType !== 1) { return; }
1144
+ if (from && from.nodeType === 1 && (canvas.contains(from) || dom.closest(from, EDITOR_CONTROLS))) { return; }
1151
1145
  if (!dom.attached(target) || canvas.contains(target)) { return; }
1152
1146
  if (dom.closest(target, EDITOR_CONTROLS) || canvas.querySelector('.ge-rte-active')) { return; }
1153
1147
 
1154
- changeSelection(null);
1148
+ changeTarget(null);
1155
1149
  }, signal);
1150
+ }
1156
1151
 
1152
+ if (panelMode() === 'sidebar') {
1157
1153
  window.addEventListener('resize', reserveSidebarRoom, signal);
1158
1154
  }
1159
1155
 
1160
1156
  /* Whatever the click was for - a text, a tool - it also says
1161
- where the toolbar adds next. A click on no column or region
1162
- says nowhere, and the toolbar adds to the canvas again. */
1157
+ where the toolbar adds next: the innermost node with settings
1158
+ under it. A click on none says nowhere, and the toolbar adds
1159
+ to the canvas again. */
1163
1160
  function clickTarget(e) {
1164
- var region = dom.closest(e.target, targetSelector());
1161
+ // A tool that took its node off the canvas says nothing of where the click was
1162
+ if (!canvas.contains(e.target)) { return; }
1163
+
1164
+ var node = settingsNodeAt(e.target);
1165
1165
 
1166
1166
  // The target's own background, or its drawer's, clicked
1167
1167
  // again takes it back. What is in it - a text, a tool, a
1168
- // nested column - keeps it, or makes that the target
1169
- if (region && region === activeTarget &&
1170
- (e.target === region || e.target === dom.child(region, '.ge-tools-drawer'))) {
1168
+ // nested column - keeps it, or makes that the target. A
1169
+ // text has no background of its own: where it is clicked
1170
+ // is where it opens
1171
+ if (node && node === activeTarget &&
1172
+ (e.target === drawerOf(node) || (e.target === node && !dom.hasClass(node, 'ge-content')))) {
1171
1173
  changeTarget(null);
1172
1174
  return;
1173
1175
  }
1174
1176
 
1175
- changeTarget(region && region !== canvas && canvas.contains(region) ? region : null);
1177
+ changeTarget(node);
1176
1178
  }
1177
1179
  }
1178
1180
 
@@ -1800,13 +1802,13 @@ function build(instance, baseElem, optionsOrMethod) {
1800
1802
  var placed = made;
1801
1803
 
1802
1804
  if (item.inColumn) {
1803
- // Where it lands in a column, or in a row and a column of its
1804
- // own anywhere else
1805
- if (!dom.is(where.region, '.column')) { placed = inRowOfItsOwn(made); }
1805
+ // Where it lands in a column, in a column of a row, or in a
1806
+ // row and a column of its own anywhere else
1807
+ placed = wrapFor(where.region, made);
1806
1808
  } else if (!acceptsBlock(where.region, made)) {
1807
- var ancestors = where.region === canvas ? [] : dom.parentsUntil(where.region, canvas).reverse().concat([where.region]);
1808
- var top = ancestors[0] || null;
1809
- where = { region: canvas, before: top ? top.nextElementSibling : null };
1809
+ where = canvasAfterTopOf(where.region);
1810
+ } else if (dom.is(where.region, '.row')) {
1811
+ placed = wrapFor(where.region, made);
1810
1812
  }
1811
1813
 
1812
1814
  return addNode(item.kind, made, function() {
@@ -1818,12 +1820,45 @@ function build(instance, baseElem, optionsOrMethod) {
1818
1820
  }, { parent: where.region, source: item.source || source || 'dragdrop' });
1819
1821
  }
1820
1822
 
1823
+ /** The canvas, just after the top level block `region` is in: where a block goes that the region will not have. */
1824
+ function canvasAfterTopOf(region) {
1825
+ var ancestors = region === canvas ? [] : dom.parentsUntil(region, canvas).reverse().concat([region]);
1826
+ var top = ancestors[0] || null;
1827
+
1828
+ return { region: canvas, before: top ? top.nextElementSibling : null };
1829
+ }
1830
+
1831
+ /**
1832
+ * A node already made - a paste, say - added to the active target,
1833
+ * as the toolbar's buttons add what they make. Null with no target,
1834
+ * or when a handler canceled the add.
1835
+ */
1836
+ function placeInTarget(node, kind, source) {
1837
+ if (!activeTarget) { return null; }
1838
+
1839
+ var where = { region: effectiveRegion(activeTarget), before: null };
1840
+ var placed = wrapFor(where.region, node);
1841
+
1842
+ // Wrapped in a column, a block still has to be one the column
1843
+ // will have: a section is not, however it is wrapped
1844
+ var holder = placed === node ? null : node.parentElement;
1845
+ if (!acceptsBlock(where.region, placed) || (holder && !acceptsBlock(holder, node))) {
1846
+ where = canvasAfterTopOf(where.region);
1847
+ placed = node;
1848
+ }
1849
+
1850
+ return addNode(kind, node, function() {
1851
+ if (where.before) {
1852
+ where.before.parentNode.insertBefore(placed, where.before);
1853
+ } else {
1854
+ where.region.appendChild(placed);
1855
+ }
1856
+ }, { parent: where.region, source: source || 'api' });
1857
+ }
1858
+
1821
1859
  /** A detached row with one full width column holding `node`. */
1822
1860
  function inRowOfItsOwn(node) {
1823
- var row = createRow();
1824
- row.appendChild(createColumn(MAX_COL_SIZE)).appendChild(node);
1825
-
1826
- return row;
1861
+ return rowHolding(createColumn(MAX_COL_SIZE), node);
1827
1862
  }
1828
1863
 
1829
1864
  /** A line where the block would go, following the pointer. */
@@ -1863,9 +1898,9 @@ function build(instance, baseElem, optionsOrMethod) {
1863
1898
  : rowFromLayout(button.getAttribute('data-ge-layout'));
1864
1899
 
1865
1900
  // A container belongs in a column: dropped straight onto the
1866
- // canvas it brings a row and a column of its own
1867
- var placed = made;
1868
- if (container && !dom.is(where.region, '.column')) { placed = inRowOfItsOwn(made); }
1901
+ // canvas it brings a row and a column of its own, and in a row
1902
+ // a column. A row in a row brings a column too
1903
+ var placed = wrapFor(where.region, made);
1869
1904
 
1870
1905
  return addNode(container ? type : 'row', made, function() {
1871
1906
  if (where.before) {
@@ -2187,7 +2222,6 @@ function build(instance, baseElem, optionsOrMethod) {
2187
2222
  deinit();
2188
2223
  // The canvas is made again from the html when it comes back
2189
2224
  changeTarget(null);
2190
- changeSelection(null);
2191
2225
  htmlTextArea.style.height = (0.8 * document.documentElement.clientHeight) + 'px';
2192
2226
  htmlTextArea.value = canvas.innerHTML;
2193
2227
  dom.show(htmlTextArea);
@@ -2211,15 +2245,13 @@ function build(instance, baseElem, optionsOrMethod) {
2211
2245
  }
2212
2246
 
2213
2247
  /**
2214
- * What can be the active target: a column, or a plugin's region - a
2215
- * section. Not the canvas, which is where the toolbar adds without one.
2248
+ * What can be the active target: a node of the canvas with settings -
2249
+ * a row, a column, a section, a container or one of its panes, a
2250
+ * text, an element. Not the canvas, which is where the toolbar adds
2251
+ * without one.
2216
2252
  */
2217
- function targetSelector() {
2218
- return ['.column'].concat(pluginHooks('regions')).join(', ');
2219
- }
2220
-
2221
2253
  function isTarget(node) {
2222
- return !!node && node !== canvas && canvas.contains(node) && dom.is(node, targetSelector());
2254
+ return !!node && node !== canvas && canvas.contains(node) && detailsFor.has(node);
2223
2255
  }
2224
2256
 
2225
2257
  /** The one way the active target changes, told only when it does. */
@@ -2227,19 +2259,89 @@ function build(instance, baseElem, optionsOrMethod) {
2227
2259
  if (node === activeTarget) { return; }
2228
2260
 
2229
2261
  var from = activeTarget;
2230
- if (from) { dom.removeClass(from, 'ge-active-target'); }
2262
+ if (from) { dom.removeClass(from, 'ge-selected'); }
2231
2263
  activeTarget = node;
2232
- if (node && dom.hasClass(canvas, 'ge-editing')) { dom.addClass(node, 'ge-active-target'); }
2264
+ if (node && dom.hasClass(canvas, 'ge-editing')) { dom.addClass(node, 'ge-selected'); }
2265
+ renderSidebar();
2233
2266
 
2234
2267
  emit('target-change', { canvas: canvas, target: node, from: from });
2235
2268
  }
2236
2269
 
2270
+ /** The regions a block can be added to: a column, and a plugin's region such as a section. */
2271
+ function regionSelector() {
2272
+ return ['.column'].concat(pluginHooks('regions')).join(', ');
2273
+ }
2274
+
2275
+ /**
2276
+ * Where what is added to `target` goes in: the node itself when it
2277
+ * holds blocks, the pane showing when it is a container or one of
2278
+ * its panes, and the column around it when it holds nothing - a text,
2279
+ * an element, a container with no pane showing.
2280
+ */
2281
+ function effectiveRegion(target) {
2282
+ if (dom.is(target, '.row, ' + regionSelector())) { return target; }
2283
+
2284
+ var inside = isContainerOrPane(target) ? paneRegionOf(target) : null;
2285
+
2286
+ return inside || dom.closest(target.parentElement, regionSelector()) || canvas;
2287
+ }
2288
+
2289
+ function isContainerOrPane(node) {
2290
+ if (node.getAttribute('data-ge-container')) { return true; }
2291
+
2292
+ var container = dom.closest(node.parentElement, '[data-ge-container]', canvas);
2293
+ var definition = container && CONTAINERS[containerTypeOf(container)];
2294
+
2295
+ return !!definition && !!definition.paneKind && kindOf(node) === definition.paneKind;
2296
+ }
2297
+
2298
+ /** What a container plugin says: where the rows of a container's visible pane, or of one of its panes, go. */
2299
+ function paneRegionOf(node) {
2300
+ var isContainer = !!node.getAttribute('data-ge-container');
2301
+ var container = isContainer ? node : dom.closest(node.parentElement, '[data-ge-container]', canvas);
2302
+ var definition = CONTAINERS[containerTypeOf(container)];
2303
+
2304
+ return definition && definition.regionOf ? definition.regionOf(container, isContainer ? null : node) || null : null;
2305
+ }
2306
+
2307
+ /**
2308
+ * What is put in `region` for `node`: the node itself when it fits
2309
+ * there, or the level it lacks around it. A row in a row is a row in
2310
+ * a new column of it, and a column in a column or in a section is a
2311
+ * column in a new row; anything else goes in a column of a row, and
2312
+ * a row of a column.
2313
+ */
2314
+ function wrapFor(region, node) {
2315
+ if (dom.is(node, '.column')) {
2316
+ return dom.is(region, '.row') ? node : rowHolding(node);
2317
+ }
2318
+ if (dom.is(region, '.row')) {
2319
+ // The width a column added to the row with its own tool has
2320
+ var column = createColumn(rowColsSource(region, leadingTier()) ? null : settings.add_column.size);
2321
+ column.appendChild(node);
2322
+ return column;
2323
+ }
2324
+ if (dom.is(region, '.column') || dom.is(node, '.row')) { return node; }
2325
+
2326
+ return rowHolding(createColumn(MAX_COL_SIZE), node);
2327
+ }
2328
+
2329
+ /** A detached row holding `column`, or a new full width column holding `node`. */
2330
+ function rowHolding(column, node) {
2331
+ var row = createRow();
2332
+ if (node) { column.appendChild(node); }
2333
+ row.appendChild(column);
2334
+
2335
+ return row;
2336
+ }
2337
+
2237
2338
  /**
2238
2339
  * A toolbar button's click with an active target: what it makes goes
2239
- * where a drop at the target's end would put it.
2340
+ * where a drop at the end of the target's region would put it, in
2341
+ * whatever it lacks to be there.
2240
2342
  */
2241
2343
  function addToTarget(button, source) {
2242
- var made = insertFromToolbar(button, { region: activeTarget, before: null }, source);
2344
+ var made = insertFromToolbar(button, { region: effectiveRegion(activeTarget), before: null }, source);
2243
2345
  if (made && made.scrollIntoView) { made.scrollIntoView({ behavior: 'smooth' }); }
2244
2346
  }
2245
2347
 
@@ -2249,9 +2351,9 @@ function build(instance, baseElem, optionsOrMethod) {
2249
2351
  if (openSettingsState && !dom.attached(openSettingsState.node)) {
2250
2352
  closeSettings();
2251
2353
  }
2252
- // The same for the selected node, which the sidebar stops showing
2253
- if (selected && !canvas.contains(selected)) {
2254
- changeSelection(null);
2354
+ // The same for the target, which the sidebar stops showing
2355
+ if (activeTarget && !canvas.contains(activeTarget)) {
2356
+ changeTarget(null);
2255
2357
  }
2256
2358
  // And a dialog showing part of a panel that is gone
2257
2359
  if (dialogState && dialogState.home && !dom.attached(dialogState.home)) {
@@ -2280,7 +2382,7 @@ function build(instance, baseElem, optionsOrMethod) {
2280
2382
  if (activeTarget && !canvas.contains(activeTarget)) {
2281
2383
  changeTarget(null);
2282
2384
  } else if (activeTarget) {
2283
- dom.addClass(activeTarget, 'ge-active-target');
2385
+ dom.addClass(activeTarget, 'ge-selected');
2284
2386
  }
2285
2387
 
2286
2388
  showSidebar();
@@ -2292,7 +2394,7 @@ function build(instance, baseElem, optionsOrMethod) {
2292
2394
  hideSidebar();
2293
2395
  dom.removeClass(canvas, 'ge-editing ge-drag-drawer ge-dropping');
2294
2396
  // The mark goes, the target stays: getHtml comes straight back
2295
- if (activeTarget) { dom.removeClass(activeTarget, 'ge-active-target'); }
2397
+ if (activeTarget) { dom.removeClass(activeTarget, 'ge-selected'); }
2296
2398
  // Before the drawers and the text blocks come off: an editor
2297
2399
  // plugin closes its editors here, and finds them where it left them
2298
2400
  plugins('onBeforeDeinit');
@@ -2394,8 +2496,8 @@ function build(instance, baseElem, optionsOrMethod) {
2394
2496
  var copy = copyCanvas();
2395
2497
  var root = copy.root;
2396
2498
 
2397
- [root].concat(dom.all(root, '.ge-active-target, .ge-settings-target')).forEach(function(node) {
2398
- dom.removeClass(node, 'ge-active-target ge-settings-target');
2499
+ [root].concat(dom.all(root, '.ge-selected, .ge-settings-target')).forEach(function(node) {
2500
+ dom.removeClass(node, 'ge-selected ge-settings-target');
2399
2501
  dom.dropEmptyClass(node);
2400
2502
  });
2401
2503
  dom.all(root, '.ge-drop-marker').forEach(function(marker) { marker.remove(); });
@@ -2501,7 +2603,6 @@ function build(instance, baseElem, optionsOrMethod) {
2501
2603
  setPreview(false);
2502
2604
  deinit();
2503
2605
  activeTarget = null;
2504
- selected = null;
2505
2606
  if (sidebarHolder === instance) { sidebarHolder = null; }
2506
2607
  removeConfirmModal();
2507
2608
  removeSettingsPanels();
@@ -2600,6 +2701,9 @@ function build(instance, baseElem, optionsOrMethod) {
2600
2701
  addSettingsTool: addSettingsTool,
2601
2702
  deleteNode: deleteNode,
2602
2703
  place: place,
2704
+ // A node made, added to the active target as the toolbar adds
2705
+ // what it makes: null with no target, or when it was canceled
2706
+ placeInTarget: placeInTarget,
2603
2707
  createPaneControls: createPaneControls,
2604
2708
  makeLabelEditable: makeLabelEditable,
2605
2709
  labelIn: labelIn,
@@ -2652,22 +2756,16 @@ function build(instance, baseElem, optionsOrMethod) {
2652
2756
  ? dom.all(mainControls, '[data-ge-toolbar="feature"][data-ge-feature="' + name + '"]')
2653
2757
  : [];
2654
2758
  },
2655
- getSelected: function() { return panelMode() === 'sidebar' ? selected : null; },
2656
2759
  getActiveTarget: function() { return settings.active_target ? activeTarget : null; },
2657
2760
  // True when it took: a node that cannot be, or no setting
2658
2761
  // for it, says nothing, since a plugin putting back what it
2659
2762
  // remembers cannot know the node is still one
2660
- setSelected: function(node) {
2661
- var chosen = panelMode() === 'sidebar' && !!node && node !== canvas && canvas.contains(node) && detailsFor.has(node);
2662
- if (chosen) { changeSelection(node); }
2663
- return chosen;
2664
- },
2665
2763
  setActiveTarget: function(node) {
2666
2764
  var chosen = !!settings.active_target && isTarget(node);
2667
2765
  if (chosen) { changeTarget(node); }
2668
2766
  return chosen;
2669
2767
  },
2670
- // What keeps Escape from the selection and the target, and an
2768
+ // What keeps Escape from the target, and an
2671
2769
  // inline panel unfolded in a drawer, which Escape leaves alone
2672
2770
  panelOpen: function() {
2673
2771
  if (openSettingsState || dialogState) { return true; }
@@ -4466,7 +4564,7 @@ function build(instance, baseElem, optionsOrMethod) {
4466
4564
 
4467
4565
  dom.delegate(panel, 'click', '.ge-settings-close', function(e) {
4468
4566
  e.preventDefault();
4469
- if (mode === 'sidebar') { changeSelection(null); } else { closeSettings(); }
4567
+ if (mode === 'sidebar') { changeTarget(null); } else { closeSettings(); }
4470
4568
  });
4471
4569
 
4472
4570
  settingsPanels[mode] = document.body.appendChild(panel);
@@ -4567,7 +4665,7 @@ function build(instance, baseElem, optionsOrMethod) {
4567
4665
  applySidebar();
4568
4666
  }
4569
4667
 
4570
- /** Editing stops: out of sight, with the selected node's panel back in its drawer. The selection stays. */
4668
+ /** Editing stops: out of sight, with the target's panel back in its drawer. The target stays. */
4571
4669
  function hideSidebar() {
4572
4670
  unshowDetails();
4573
4671
 
@@ -4606,7 +4704,7 @@ function build(instance, baseElem, optionsOrMethod) {
4606
4704
  var panel = settingsPanels.sidebar;
4607
4705
  if (!panel || !isEditing()) { return; }
4608
4706
 
4609
- var details = selected ? detailsOf(selected) : null;
4707
+ var details = activeTarget ? detailsOf(activeTarget) : null;
4610
4708
  if (details ? sidebarShown && sidebarShown.details === details : !sidebarShown && sidebarEmpty) { return; }
4611
4709
 
4612
4710
  unshowSidebar();
@@ -4622,11 +4720,10 @@ function build(instance, baseElem, optionsOrMethod) {
4622
4720
  return;
4623
4721
  }
4624
4722
 
4625
- sidebarShown = { node: selected, details: details, home: details.parentElement, next: details.nextElementSibling };
4626
- setSidebarTitle(t('panel.title', { kind: kindLabel(selected) }));
4723
+ sidebarShown = { node: activeTarget, details: details, home: details.parentElement, next: details.nextElementSibling };
4724
+ setSidebarTitle(t('panel.title', { kind: kindLabel(activeTarget) }));
4627
4725
  holder.appendChild(details);
4628
4726
  dom.show(details);
4629
- dom.addClass(selected, 'ge-settings-target');
4630
4727
  }
4631
4728
 
4632
4729
  /**
@@ -4690,17 +4787,6 @@ function build(instance, baseElem, optionsOrMethod) {
4690
4787
  return null;
4691
4788
  }
4692
4789
 
4693
- /** The one way the selection changes, told only when it does. */
4694
- function changeSelection(node) {
4695
- if (node === selected) { return; }
4696
-
4697
- var from = selected;
4698
- selected = node;
4699
- renderSidebar();
4700
-
4701
- emit('selection-change', { canvas: canvas, node: node, from: from });
4702
- }
4703
-
4704
4790
  /**
4705
4791
  * Under the gear, or over it when there is more room there, inside
4706
4792
  * the window, and no taller than the room it has: past that its body
@@ -6336,30 +6422,13 @@ function build(instance, baseElem, optionsOrMethod) {
6336
6422
  var node = nodeFrom(value);
6337
6423
  if (!isTarget(node)) {
6338
6424
  var named = typeof value === 'string' ? value : (node ? '<' + node.tagName.toLowerCase() + '>' : String(value));
6339
- warn('setActiveTarget: ' + named + ' is not a column or a region of the canvas');
6425
+ warn('setActiveTarget: ' + named + ' is not a node of the canvas with settings');
6340
6426
  return;
6341
6427
  }
6342
6428
 
6343
6429
  changeTarget(node);
6344
6430
  }
6345
6431
 
6346
- function apiSetSelected(value) {
6347
- if (panelMode() !== 'sidebar') {
6348
- warnOnceHere('sidebar-api', 'setSelected needs settings_panel "sidebar": without it, it does nothing');
6349
- return;
6350
- }
6351
- if (value === null || value === undefined) { changeSelection(null); return; }
6352
-
6353
- var node = nodeFrom(value);
6354
- if (!node || node === canvas || !canvas.contains(node) || !detailsFor.has(node)) {
6355
- var named = typeof value === 'string' ? value : (node ? '<' + node.tagName.toLowerCase() + '>' : String(value));
6356
- warn('setSelected: ' + named + ' is not a node of the canvas with settings');
6357
- return;
6358
- }
6359
-
6360
- changeSelection(node);
6361
- }
6362
-
6363
6432
  var own = {
6364
6433
  getHtml: getHtml,
6365
6434
  getPlainHtml: getPlainHtml,
@@ -6393,8 +6462,6 @@ function build(instance, baseElem, optionsOrMethod) {
6393
6462
  setUtility: setUtility,
6394
6463
  getActiveTarget: function() { return settings.active_target ? activeTarget : null; },
6395
6464
  setActiveTarget: apiSetActiveTarget,
6396
- getSelected: function() { return panelMode() === 'sidebar' ? selected : null; },
6397
- setSelected: apiSetSelected,
6398
6465
  };
6399
6466
 
6400
6467
  Object.keys(own).forEach(function(name) {
@@ -130,6 +130,15 @@ GridEditor.containers.accordion = function(ge) {
130
130
  addPaneKey: 'container.add_accordion_item',
131
131
  paneKind: 'accordion-item',
132
132
 
133
+ // Where rows go: the body of the item that is open, or of the item
134
+ regionOf: function(container, item) {
135
+ var open = item || dom.all(container, ':scope > .accordion > .accordion-item').filter(function(each) {
136
+ return dom.hasClass(collapseOf(each), 'show');
137
+ })[0];
138
+
139
+ return open ? dom.one(open, '.accordion-body') : null;
140
+ },
141
+
133
142
  create: function(options) {
134
143
  var container = dom.element('div', { 'data-ge-container': 'accordion' });
135
144
  var labels = options.labels || [];
@@ -28,6 +28,11 @@ GridEditor.containers.card = function(ge) {
28
28
  return {
29
29
  labelKey: 'container.add_card',
30
30
 
31
+ // Where rows go: the card's body
32
+ regionOf: function(container) {
33
+ return dom.one(container, '.card-body');
34
+ },
35
+
31
36
  /**
32
37
  * A card is a header, a body and an optional footer. `header: false`
33
38
  * leaves the title out, `footer: true` or a string adds one; both are
@@ -665,6 +665,11 @@ GridEditor.containers.carousel = function(ge) {
665
665
  labelKey: 'container.add_carousel',
666
666
  addPaneKey: 'container.add_carousel_item',
667
667
  paneKind: 'carousel-item',
668
+
669
+ // Where rows go: the slide showing, or the slide itself
670
+ regionOf: function(container, item) {
671
+ return item || currentOf(container);
672
+ },
668
673
  paneClass: 'ge-carousel-item',
669
674
  paneLabelKey: 'panel.kind_carousel_item',
670
675
 
@@ -18,10 +18,10 @@
18
18
  * A paste is an add like any other - before-add-* and after-add-*, with
19
19
  * `source: 'paste'` - so a host can turn one away.
20
20
  *
21
- * With active_target (which the sidebar turns on), Ctrl+C copies the node
22
- * selected, or the target, and Ctrl+V pastes into the target, or the node
23
- * selected. `clipboard: { shortcuts: false }` turns them off. They go through
24
- * the same store as the tools, never the system clipboard.
21
+ * With active_target (which the sidebar turns on), Ctrl+C copies the target
22
+ * and Ctrl+V pastes into it, as the toolbar adds to it.
23
+ * `clipboard: { shortcuts: false }` turns them off. They go through the same
24
+ * store as the tools, never the system clipboard.
25
25
  */
26
26
  import { GridEditor } from '../grideditor.js';
27
27
  import * as dom from '../dom.js';
@@ -197,29 +197,16 @@ GridEditor.features.clipboard = function(ge) {
197
197
  }
198
198
 
199
199
  /**
200
- * Ctrl+V: into the target as the toolbar's paste button would - a
201
- * section, which only the canvas takes, after the block the target is in
202
- * - and what that button has none for as the target's paste tool would.
203
- * With no target, as the selected node's paste tool. What does not fit
204
- * is not pasted anywhere else.
200
+ * Ctrl+V: into the target, where the toolbar would add it - at the end
201
+ * of what the target holds, in the row or column it lacks, a section on
202
+ * the canvas after the block the target is in. What the target cannot
203
+ * take is not pasted anywhere else.
205
204
  */
206
205
  function pasteByShortcut() {
207
206
  var clip = read();
208
- var target = ge.getActiveTarget();
209
- var node = target || ge.getSelected();
210
- if (!clip || !node) { return false; }
211
-
212
- var placement = { appendTo: node, source: 'paste' };
213
- if (target && clip.category === 'section') {
214
- if (!available(clip)) { return false; }
215
- var top = target;
216
- while (top.parentElement && top.parentElement !== ge.canvas) { top = top.parentElement; }
217
- placement = { insertAfter: top, source: 'paste' };
218
- } else if (!fits(clip, TARGETS[ge.kindOf(node)] || [])) {
219
- return false;
220
- }
207
+ if (!clip || !ge.getActiveTarget() || !available(clip)) { return false; }
221
208
 
222
- var made = ge.place(ge.freshNode(clip.html), clip.kind, placement);
209
+ var made = ge.placeInTarget(ge.freshNode(clip.html), clip.kind, 'paste');
223
210
  if (made && made.scrollIntoView) { made.scrollIntoView({ behavior: 'smooth' }); }
224
211
 
225
212
  return true;
@@ -228,7 +215,7 @@ GridEditor.features.clipboard = function(ge) {
228
215
  function copyByShortcut() {
229
216
  if (textSelected()) { return false; }
230
217
 
231
- var node = ge.getSelected() || ge.getActiveTarget();
218
+ var node = ge.getActiveTarget();
232
219
  var kind = node && ge.kindOf(node);
233
220
  if (!kind || !categoryOf(kind)) { return false; }
234
221