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

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 (96) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/README.md +43 -24
  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 +13 -20
  7. package/dist/grideditor.esm.js +174 -104
  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 +174 -104
  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/locales/grideditor.es.esm.js +1 -0
  17. package/dist/locales/grideditor.es.js +1 -0
  18. package/dist/locales/grideditor.es.min.js +1 -1
  19. package/dist/locales/grideditor.es.min.js.map +2 -2
  20. package/dist/plugins/grideditor.accordion.esm.js +16 -0
  21. package/dist/plugins/grideditor.accordion.js +16 -0
  22. package/dist/plugins/grideditor.accordion.min.js +1 -1
  23. package/dist/plugins/grideditor.accordion.min.js.map +3 -3
  24. package/dist/plugins/grideditor.card.esm.js +4 -0
  25. package/dist/plugins/grideditor.card.js +4 -0
  26. package/dist/plugins/grideditor.card.min.js +1 -1
  27. package/dist/plugins/grideditor.card.min.js.map +3 -3
  28. package/dist/plugins/grideditor.carousel.esm.js +7 -0
  29. package/dist/plugins/grideditor.carousel.js +7 -0
  30. package/dist/plugins/grideditor.carousel.min.js +1 -1
  31. package/dist/plugins/grideditor.carousel.min.js.map +3 -3
  32. package/dist/plugins/grideditor.ckeditor.esm.js +9 -0
  33. package/dist/plugins/grideditor.ckeditor.js +9 -0
  34. package/dist/plugins/grideditor.ckeditor.min.js +1 -1
  35. package/dist/plugins/grideditor.ckeditor.min.js.map +3 -3
  36. package/dist/plugins/grideditor.clipboard.esm.js +47 -25
  37. package/dist/plugins/grideditor.clipboard.js +47 -25
  38. package/dist/plugins/grideditor.clipboard.min.js +1 -1
  39. package/dist/plugins/grideditor.clipboard.min.js.map +3 -3
  40. package/dist/plugins/grideditor.codemirror-inline.min.js.map +1 -1
  41. package/dist/plugins/grideditor.codemirror.min.js.map +1 -1
  42. package/dist/plugins/grideditor.elements.esm.js +3 -0
  43. package/dist/plugins/grideditor.elements.js +3 -0
  44. package/dist/plugins/grideditor.elements.min.js +1 -1
  45. package/dist/plugins/grideditor.elements.min.js.map +3 -3
  46. package/dist/plugins/grideditor.gutters.min.js.map +1 -1
  47. package/dist/plugins/grideditor.history.esm.js +2 -7
  48. package/dist/plugins/grideditor.history.js +2 -7
  49. package/dist/plugins/grideditor.history.min.js +1 -1
  50. package/dist/plugins/grideditor.history.min.js.map +3 -3
  51. package/dist/plugins/grideditor.inline-style.min.js.map +1 -1
  52. package/dist/plugins/grideditor.offcanvas.esm.js +4 -0
  53. package/dist/plugins/grideditor.offcanvas.js +4 -0
  54. package/dist/plugins/grideditor.offcanvas.min.js +1 -1
  55. package/dist/plugins/grideditor.offcanvas.min.js.map +3 -3
  56. package/dist/plugins/grideditor.order.min.js +1 -1
  57. package/dist/plugins/grideditor.order.min.js.map +1 -1
  58. package/dist/plugins/grideditor.popup.esm.js +4 -0
  59. package/dist/plugins/grideditor.popup.js +4 -0
  60. package/dist/plugins/grideditor.popup.min.js +1 -1
  61. package/dist/plugins/grideditor.popup.min.js.map +3 -3
  62. package/dist/plugins/grideditor.sections.esm.js +9 -0
  63. package/dist/plugins/grideditor.sections.js +9 -0
  64. package/dist/plugins/grideditor.sections.min.js +1 -1
  65. package/dist/plugins/grideditor.sections.min.js.map +3 -3
  66. package/dist/plugins/grideditor.summernote.esm.js +9 -0
  67. package/dist/plugins/grideditor.summernote.js +9 -0
  68. package/dist/plugins/grideditor.summernote.min.js +1 -1
  69. package/dist/plugins/grideditor.summernote.min.js.map +3 -3
  70. package/dist/plugins/grideditor.tabs.esm.js +7 -0
  71. package/dist/plugins/grideditor.tabs.js +7 -0
  72. package/dist/plugins/grideditor.tabs.min.js +1 -1
  73. package/dist/plugins/grideditor.tabs.min.js.map +3 -3
  74. package/dist/plugins/grideditor.tinymce.esm.js +9 -0
  75. package/dist/plugins/grideditor.tinymce.js +9 -0
  76. package/dist/plugins/grideditor.tinymce.min.js +1 -1
  77. package/dist/plugins/grideditor.tinymce.min.js.map +3 -3
  78. package/docs/events.md +14 -12
  79. package/docs/locale-keys.md +1 -0
  80. package/docs/plugins.md +11 -8
  81. package/example/clipboard.html +20 -14
  82. package/package.json +1 -1
  83. package/src/js/dom.js +6 -0
  84. package/src/js/grideditor.jquery.js +0 -2
  85. package/src/js/grideditor.js +233 -114
  86. package/src/js/locales/grideditor.es.js +1 -0
  87. package/src/js/plugins/grideditor.accordion.js +9 -0
  88. package/src/js/plugins/grideditor.card.js +5 -0
  89. package/src/js/plugins/grideditor.carousel.js +5 -0
  90. package/src/js/plugins/grideditor.clipboard.js +70 -33
  91. package/src/js/plugins/grideditor.history.js +6 -9
  92. package/src/js/plugins/grideditor.offcanvas.js +5 -0
  93. package/src/js/plugins/grideditor.popup.js +5 -0
  94. package/src/js/plugins/grideditor.tabs.js +5 -0
  95. package/src/less/grideditor.less +5 -4
  96. package/types/grideditor.d.ts +13 -20
@@ -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
 
@@ -498,6 +495,8 @@ function build(instance, baseElem, optionsOrMethod) {
498
495
  // be jQuery data: a node's settings panel, a drag or a resize in
499
496
  // progress. Kept off the markup, and gone with the node.
500
497
  var detailsFor = new WeakMap(); // node -> its settings panel
498
+ var toolActions = new WeakMap(); // A tool -> what its click does, to do it without one
499
+ var pendingDelete = null; // What removeNode asks of the delete the tool it runs makes, for that call only
501
500
  var moves = new WeakMap(); // dragged node -> { from, canceled }
502
501
  var resizes = new WeakMap(); // column -> { from, units }
503
502
  var sectionNodes = new WeakMap(); // Responsive section -> the node it edits
@@ -847,12 +846,16 @@ function build(instance, baseElem, optionsOrMethod) {
847
846
  * question to have been asked already.
848
847
  */
849
848
  function deleteNode(kind, node, message, animate) {
849
+ var asked = pendingDelete || {};
850
+ pendingDelete = null;
851
+
850
852
  operate(function() {
851
- var payload = payloadFor(kind, node, { source: 'tool' });
853
+ var payload = payloadFor(kind, node, { source: asked.source || 'tool' });
852
854
 
853
855
  if (!emit('before-delete', payload)) { return; }
856
+ if (asked.before) { asked.before(); }
854
857
 
855
- askToDelete(message, function() {
858
+ var remove = function() {
856
859
  operate(function() {
857
860
  animate(function() {
858
861
  node.remove();
@@ -862,10 +865,51 @@ function build(instance, baseElem, optionsOrMethod) {
862
865
  });
863
866
  });
864
867
  });
865
- });
868
+ };
869
+
870
+ if (asked.confirm === false) {
871
+ remove();
872
+ } else {
873
+ askToDelete(message, remove);
874
+ }
866
875
  });
867
876
  }
868
877
 
878
+ /**
879
+ * A node removed as its own delete tool removes it - the text's
880
+ * editor closes first, say - but as the caller asks: without the
881
+ * question, from a `source` of its own, and with `before()` called
882
+ * once the host's before-delete has let it through, which is also
883
+ * what the answer says. False for a node with no delete tool, or
884
+ * one a before-delete turned away.
885
+ */
886
+ function removeNode(node, options) {
887
+ options = options || {};
888
+
889
+ var drawer = node ? drawerOf(node) : null;
890
+ var tool = drawer ? dom.child(drawer, '[class*="ge-delete-"]') : null;
891
+ var action = tool ? toolActions.get(tool) : null;
892
+ if (!action) { return false; }
893
+
894
+ var went = false;
895
+ pendingDelete = {
896
+ source: options.source,
897
+ confirm: options.confirm,
898
+ before: function() {
899
+ went = true;
900
+ if (options.before) { options.before(); }
901
+ },
902
+ };
903
+
904
+ try {
905
+ action.call(tool);
906
+ } finally {
907
+ pendingDelete = null;
908
+ }
909
+
910
+ return went;
911
+ }
912
+
869
913
  /**
870
914
  * What resizing this column to `size` in `view` would write, or null
871
915
  * when the budget refuses it or there is nothing to change.
@@ -1098,9 +1142,7 @@ function build(instance, baseElem, optionsOrMethod) {
1098
1142
  /* A click on the host's plain content offers to make it a text */
1099
1143
  dom.delegate(canvas, 'click', '.ge-content', onContentClick, signal);
1100
1144
 
1101
- var sidebarMode = panelMode() === 'sidebar';
1102
-
1103
- if (settings.active_target || sidebarMode) {
1145
+ if (settings.active_target) {
1104
1146
  // The click a drag ends in - a resize, a move - is not one:
1105
1147
  // it comes where the pointer let go, not where it pressed
1106
1148
  var pressed = null;
@@ -1113,66 +1155,73 @@ function build(instance, baseElem, optionsOrMethod) {
1113
1155
  if (!dom.hasClass(canvas, 'ge-editing')) { return; }
1114
1156
  if (from && Math.abs(e.clientX - from.x) + Math.abs(e.clientY - from.y) > settings.drag.threshold) { return; }
1115
1157
 
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)); }
1158
+ clickTarget(e);
1119
1159
  }, signal);
1120
1160
 
1121
1161
  // Escape is the panel's, the dialog's, and a field's or a
1122
1162
  // text's while one has the focus; after those, it is the
1123
- // selection's, and then the target's
1163
+ // target's
1124
1164
  document.addEventListener('keydown', function(e) {
1125
1165
  if (e.key !== 'Escape' || openSettingsState || dialogState) { return; }
1126
1166
  if (confirmDialog && dom.hasClass(confirmDialog, 'show')) { return; }
1127
1167
  var focus = document.activeElement;
1128
1168
  if (focus && (dom.is(focus, 'input, textarea, select') || focus.isContentEditable)) { return; }
1129
1169
 
1130
- if (selected && isEditing()) {
1131
- changeSelection(null);
1132
- } else if (activeTarget) {
1133
- changeTarget(null);
1134
- }
1170
+ if (activeTarget) { changeTarget(null); }
1135
1171
  }, signal);
1136
- }
1137
1172
 
1138
- if (sidebarMode) {
1139
- // The focus coming into a node selects it, as a click does
1173
+ // The focus coming into a node makes it the target, as a click does
1140
1174
  canvas.addEventListener('focusin', function(e) {
1141
1175
  var node = isEditing() ? settingsNodeAt(e.target) : null;
1142
- if (node) { changeSelection(node); }
1176
+ if (node) { changeTarget(node); }
1143
1177
  }, signal);
1144
1178
 
1145
1179
  // 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
1180
+ // controls, puts the target away - not while a text is open,
1181
+ // whose editor has controls of its own out there. Nor the
1182
+ // click a drag from the toolbar ends in, which the browser
1183
+ // gives to what holds both the toolbar and the canvas
1184
+ var pressedOn = null;
1185
+ document.addEventListener('pointerdown', function(e) { pressedOn = e.target; }, { capture: true, signal: signal.signal });
1148
1186
  document.addEventListener('click', function(e) {
1149
1187
  var target = e.target;
1150
- if (!selected || !isEditing() || !target || target.nodeType !== 1) { return; }
1188
+ var from = pressedOn;
1189
+ pressedOn = null;
1190
+ if (!activeTarget || !isEditing() || !target || target.nodeType !== 1) { return; }
1191
+ if (from && from.nodeType === 1 && (canvas.contains(from) || dom.closest(from, EDITOR_CONTROLS))) { return; }
1151
1192
  if (!dom.attached(target) || canvas.contains(target)) { return; }
1152
1193
  if (dom.closest(target, EDITOR_CONTROLS) || canvas.querySelector('.ge-rte-active')) { return; }
1153
1194
 
1154
- changeSelection(null);
1195
+ changeTarget(null);
1155
1196
  }, signal);
1197
+ }
1156
1198
 
1199
+ if (panelMode() === 'sidebar') {
1157
1200
  window.addEventListener('resize', reserveSidebarRoom, signal);
1158
1201
  }
1159
1202
 
1160
1203
  /* 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. */
1204
+ where the toolbar adds next: the innermost node with settings
1205
+ under it. A click on none says nowhere, and the toolbar adds
1206
+ to the canvas again. */
1163
1207
  function clickTarget(e) {
1164
- var region = dom.closest(e.target, targetSelector());
1208
+ // A tool that took its node off the canvas says nothing of where the click was
1209
+ if (!canvas.contains(e.target)) { return; }
1210
+
1211
+ var node = settingsNodeAt(e.target);
1165
1212
 
1166
1213
  // The target's own background, or its drawer's, clicked
1167
1214
  // 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'))) {
1215
+ // nested column - keeps it, or makes that the target. A
1216
+ // text has no background of its own: where it is clicked
1217
+ // is where it opens
1218
+ if (node && node === activeTarget &&
1219
+ (e.target === drawerOf(node) || (e.target === node && !dom.hasClass(node, 'ge-content')))) {
1171
1220
  changeTarget(null);
1172
1221
  return;
1173
1222
  }
1174
1223
 
1175
- changeTarget(region && region !== canvas && canvas.contains(region) ? region : null);
1224
+ changeTarget(node);
1176
1225
  }
1177
1226
  }
1178
1227
 
@@ -1800,13 +1849,13 @@ function build(instance, baseElem, optionsOrMethod) {
1800
1849
  var placed = made;
1801
1850
 
1802
1851
  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); }
1852
+ // Where it lands in a column, in a column of a row, or in a
1853
+ // row and a column of its own anywhere else
1854
+ placed = wrapFor(where.region, made);
1806
1855
  } 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 };
1856
+ where = canvasAfterTopOf(where.region);
1857
+ } else if (dom.is(where.region, '.row')) {
1858
+ placed = wrapFor(where.region, made);
1810
1859
  }
1811
1860
 
1812
1861
  return addNode(item.kind, made, function() {
@@ -1818,12 +1867,45 @@ function build(instance, baseElem, optionsOrMethod) {
1818
1867
  }, { parent: where.region, source: item.source || source || 'dragdrop' });
1819
1868
  }
1820
1869
 
1870
+ /** The canvas, just after the top level block `region` is in: where a block goes that the region will not have. */
1871
+ function canvasAfterTopOf(region) {
1872
+ var ancestors = region === canvas ? [] : dom.parentsUntil(region, canvas).reverse().concat([region]);
1873
+ var top = ancestors[0] || null;
1874
+
1875
+ return { region: canvas, before: top ? top.nextElementSibling : null };
1876
+ }
1877
+
1878
+ /**
1879
+ * A node already made - a paste, say - added to the active target,
1880
+ * as the toolbar's buttons add what they make. Null with no target,
1881
+ * or when a handler canceled the add.
1882
+ */
1883
+ function placeInTarget(node, kind, source) {
1884
+ if (!activeTarget) { return null; }
1885
+
1886
+ var where = { region: effectiveRegion(activeTarget), before: null };
1887
+ var placed = wrapFor(where.region, node);
1888
+
1889
+ // Wrapped in a column, a block still has to be one the column
1890
+ // will have: a section is not, however it is wrapped
1891
+ var holder = placed === node ? null : node.parentElement;
1892
+ if (!acceptsBlock(where.region, placed) || (holder && !acceptsBlock(holder, node))) {
1893
+ where = canvasAfterTopOf(where.region);
1894
+ placed = node;
1895
+ }
1896
+
1897
+ return addNode(kind, node, function() {
1898
+ if (where.before) {
1899
+ where.before.parentNode.insertBefore(placed, where.before);
1900
+ } else {
1901
+ where.region.appendChild(placed);
1902
+ }
1903
+ }, { parent: where.region, source: source || 'api' });
1904
+ }
1905
+
1821
1906
  /** A detached row with one full width column holding `node`. */
1822
1907
  function inRowOfItsOwn(node) {
1823
- var row = createRow();
1824
- row.appendChild(createColumn(MAX_COL_SIZE)).appendChild(node);
1825
-
1826
- return row;
1908
+ return rowHolding(createColumn(MAX_COL_SIZE), node);
1827
1909
  }
1828
1910
 
1829
1911
  /** A line where the block would go, following the pointer. */
@@ -1863,9 +1945,9 @@ function build(instance, baseElem, optionsOrMethod) {
1863
1945
  : rowFromLayout(button.getAttribute('data-ge-layout'));
1864
1946
 
1865
1947
  // 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); }
1948
+ // canvas it brings a row and a column of its own, and in a row
1949
+ // a column. A row in a row brings a column too
1950
+ var placed = wrapFor(where.region, made);
1869
1951
 
1870
1952
  return addNode(container ? type : 'row', made, function() {
1871
1953
  if (where.before) {
@@ -2187,7 +2269,6 @@ function build(instance, baseElem, optionsOrMethod) {
2187
2269
  deinit();
2188
2270
  // The canvas is made again from the html when it comes back
2189
2271
  changeTarget(null);
2190
- changeSelection(null);
2191
2272
  htmlTextArea.style.height = (0.8 * document.documentElement.clientHeight) + 'px';
2192
2273
  htmlTextArea.value = canvas.innerHTML;
2193
2274
  dom.show(htmlTextArea);
@@ -2211,15 +2292,13 @@ function build(instance, baseElem, optionsOrMethod) {
2211
2292
  }
2212
2293
 
2213
2294
  /**
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.
2295
+ * What can be the active target: a node of the canvas with settings -
2296
+ * a row, a column, a section, a container or one of its panes, a
2297
+ * text, an element. Not the canvas, which is where the toolbar adds
2298
+ * without one.
2216
2299
  */
2217
- function targetSelector() {
2218
- return ['.column'].concat(pluginHooks('regions')).join(', ');
2219
- }
2220
-
2221
2300
  function isTarget(node) {
2222
- return !!node && node !== canvas && canvas.contains(node) && dom.is(node, targetSelector());
2301
+ return !!node && node !== canvas && canvas.contains(node) && detailsFor.has(node);
2223
2302
  }
2224
2303
 
2225
2304
  /** The one way the active target changes, told only when it does. */
@@ -2227,19 +2306,89 @@ function build(instance, baseElem, optionsOrMethod) {
2227
2306
  if (node === activeTarget) { return; }
2228
2307
 
2229
2308
  var from = activeTarget;
2230
- if (from) { dom.removeClass(from, 'ge-active-target'); }
2309
+ if (from) { dom.removeClass(from, 'ge-selected'); }
2231
2310
  activeTarget = node;
2232
- if (node && dom.hasClass(canvas, 'ge-editing')) { dom.addClass(node, 'ge-active-target'); }
2311
+ if (node && dom.hasClass(canvas, 'ge-editing')) { dom.addClass(node, 'ge-selected'); }
2312
+ renderSidebar();
2233
2313
 
2234
2314
  emit('target-change', { canvas: canvas, target: node, from: from });
2235
2315
  }
2236
2316
 
2317
+ /** The regions a block can be added to: a column, and a plugin's region such as a section. */
2318
+ function regionSelector() {
2319
+ return ['.column'].concat(pluginHooks('regions')).join(', ');
2320
+ }
2321
+
2322
+ /**
2323
+ * Where what is added to `target` goes in: the node itself when it
2324
+ * holds blocks, the pane showing when it is a container or one of
2325
+ * its panes, and the column around it when it holds nothing - a text,
2326
+ * an element, a container with no pane showing.
2327
+ */
2328
+ function effectiveRegion(target) {
2329
+ if (dom.is(target, '.row, ' + regionSelector())) { return target; }
2330
+
2331
+ var inside = isContainerOrPane(target) ? paneRegionOf(target) : null;
2332
+
2333
+ return inside || dom.closest(target.parentElement, regionSelector()) || canvas;
2334
+ }
2335
+
2336
+ function isContainerOrPane(node) {
2337
+ if (node.getAttribute('data-ge-container')) { return true; }
2338
+
2339
+ var container = dom.closest(node.parentElement, '[data-ge-container]', canvas);
2340
+ var definition = container && CONTAINERS[containerTypeOf(container)];
2341
+
2342
+ return !!definition && !!definition.paneKind && kindOf(node) === definition.paneKind;
2343
+ }
2344
+
2345
+ /** What a container plugin says: where the rows of a container's visible pane, or of one of its panes, go. */
2346
+ function paneRegionOf(node) {
2347
+ var isContainer = !!node.getAttribute('data-ge-container');
2348
+ var container = isContainer ? node : dom.closest(node.parentElement, '[data-ge-container]', canvas);
2349
+ var definition = CONTAINERS[containerTypeOf(container)];
2350
+
2351
+ return definition && definition.regionOf ? definition.regionOf(container, isContainer ? null : node) || null : null;
2352
+ }
2353
+
2354
+ /**
2355
+ * What is put in `region` for `node`: the node itself when it fits
2356
+ * there, or the level it lacks around it. A row in a row is a row in
2357
+ * a new column of it, and a column in a column or in a section is a
2358
+ * column in a new row; anything else goes in a column of a row, and
2359
+ * a row of a column.
2360
+ */
2361
+ function wrapFor(region, node) {
2362
+ if (dom.is(node, '.column')) {
2363
+ return dom.is(region, '.row') ? node : rowHolding(node);
2364
+ }
2365
+ if (dom.is(region, '.row')) {
2366
+ // The width a column added to the row with its own tool has
2367
+ var column = createColumn(rowColsSource(region, leadingTier()) ? null : settings.add_column.size);
2368
+ column.appendChild(node);
2369
+ return column;
2370
+ }
2371
+ if (dom.is(region, '.column') || dom.is(node, '.row')) { return node; }
2372
+
2373
+ return rowHolding(createColumn(MAX_COL_SIZE), node);
2374
+ }
2375
+
2376
+ /** A detached row holding `column`, or a new full width column holding `node`. */
2377
+ function rowHolding(column, node) {
2378
+ var row = createRow();
2379
+ if (node) { column.appendChild(node); }
2380
+ row.appendChild(column);
2381
+
2382
+ return row;
2383
+ }
2384
+
2237
2385
  /**
2238
2386
  * 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.
2387
+ * where a drop at the end of the target's region would put it, in
2388
+ * whatever it lacks to be there.
2240
2389
  */
2241
2390
  function addToTarget(button, source) {
2242
- var made = insertFromToolbar(button, { region: activeTarget, before: null }, source);
2391
+ var made = insertFromToolbar(button, { region: effectiveRegion(activeTarget), before: null }, source);
2243
2392
  if (made && made.scrollIntoView) { made.scrollIntoView({ behavior: 'smooth' }); }
2244
2393
  }
2245
2394
 
@@ -2249,9 +2398,9 @@ function build(instance, baseElem, optionsOrMethod) {
2249
2398
  if (openSettingsState && !dom.attached(openSettingsState.node)) {
2250
2399
  closeSettings();
2251
2400
  }
2252
- // The same for the selected node, which the sidebar stops showing
2253
- if (selected && !canvas.contains(selected)) {
2254
- changeSelection(null);
2401
+ // The same for the target, which the sidebar stops showing
2402
+ if (activeTarget && !canvas.contains(activeTarget)) {
2403
+ changeTarget(null);
2255
2404
  }
2256
2405
  // And a dialog showing part of a panel that is gone
2257
2406
  if (dialogState && dialogState.home && !dom.attached(dialogState.home)) {
@@ -2280,7 +2429,7 @@ function build(instance, baseElem, optionsOrMethod) {
2280
2429
  if (activeTarget && !canvas.contains(activeTarget)) {
2281
2430
  changeTarget(null);
2282
2431
  } else if (activeTarget) {
2283
- dom.addClass(activeTarget, 'ge-active-target');
2432
+ dom.addClass(activeTarget, 'ge-selected');
2284
2433
  }
2285
2434
 
2286
2435
  showSidebar();
@@ -2292,7 +2441,7 @@ function build(instance, baseElem, optionsOrMethod) {
2292
2441
  hideSidebar();
2293
2442
  dom.removeClass(canvas, 'ge-editing ge-drag-drawer ge-dropping');
2294
2443
  // The mark goes, the target stays: getHtml comes straight back
2295
- if (activeTarget) { dom.removeClass(activeTarget, 'ge-active-target'); }
2444
+ if (activeTarget) { dom.removeClass(activeTarget, 'ge-selected'); }
2296
2445
  // Before the drawers and the text blocks come off: an editor
2297
2446
  // plugin closes its editors here, and finds them where it left them
2298
2447
  plugins('onBeforeDeinit');
@@ -2394,8 +2543,8 @@ function build(instance, baseElem, optionsOrMethod) {
2394
2543
  var copy = copyCanvas();
2395
2544
  var root = copy.root;
2396
2545
 
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');
2546
+ [root].concat(dom.all(root, '.ge-selected, .ge-settings-target, .ge-leaving')).forEach(function(node) {
2547
+ dom.removeClass(node, 'ge-selected ge-settings-target ge-leaving');
2399
2548
  dom.dropEmptyClass(node);
2400
2549
  });
2401
2550
  dom.all(root, '.ge-drop-marker').forEach(function(marker) { marker.remove(); });
@@ -2501,7 +2650,6 @@ function build(instance, baseElem, optionsOrMethod) {
2501
2650
  setPreview(false);
2502
2651
  deinit();
2503
2652
  activeTarget = null;
2504
- selected = null;
2505
2653
  if (sidebarHolder === instance) { sidebarHolder = null; }
2506
2654
  removeConfirmModal();
2507
2655
  removeSettingsPanels();
@@ -2600,6 +2748,9 @@ function build(instance, baseElem, optionsOrMethod) {
2600
2748
  addSettingsTool: addSettingsTool,
2601
2749
  deleteNode: deleteNode,
2602
2750
  place: place,
2751
+ // A node made, added to the active target as the toolbar adds
2752
+ // what it makes: null with no target, or when it was canceled
2753
+ placeInTarget: placeInTarget,
2603
2754
  createPaneControls: createPaneControls,
2604
2755
  makeLabelEditable: makeLabelEditable,
2605
2756
  labelIn: labelIn,
@@ -2652,22 +2803,19 @@ function build(instance, baseElem, optionsOrMethod) {
2652
2803
  ? dom.all(mainControls, '[data-ge-toolbar="feature"][data-ge-feature="' + name + '"]')
2653
2804
  : [];
2654
2805
  },
2655
- getSelected: function() { return panelMode() === 'sidebar' ? selected : null; },
2656
2806
  getActiveTarget: function() { return settings.active_target ? activeTarget : null; },
2657
2807
  // True when it took: a node that cannot be, or no setting
2658
2808
  // for it, says nothing, since a plugin putting back what it
2659
2809
  // 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
- },
2810
+ // null takes it away
2665
2811
  setActiveTarget: function(node) {
2666
- var chosen = !!settings.active_target && isTarget(node);
2812
+ var chosen = !!settings.active_target && (node === null || isTarget(node));
2667
2813
  if (chosen) { changeTarget(node); }
2668
2814
  return chosen;
2669
2815
  },
2670
- // What keeps Escape from the selection and the target, and an
2816
+ // A node removed as its delete tool does, as asked
2817
+ removeNode: removeNode,
2818
+ // What keeps Escape from the target, and an
2671
2819
  // inline panel unfolded in a drawer, which Escape leaves alone
2672
2820
  panelOpen: function() {
2673
2821
  if (openSettingsState || dialogState) { return true; }
@@ -4063,11 +4211,13 @@ function build(instance, baseElem, optionsOrMethod) {
4063
4211
 
4064
4212
  if (typeof eventHandlers == 'function') {
4065
4213
  tool.addEventListener('click', eventHandlers);
4214
+ toolActions.set(tool, eventHandlers);
4066
4215
  }
4067
4216
  if (eventHandlers && typeof eventHandlers == 'object') {
4068
4217
  Object.keys(eventHandlers).forEach(function(name) {
4069
4218
  dom.on(tool, name, eventHandlers[name]);
4070
4219
  });
4220
+ if (typeof eventHandlers.click == 'function') { toolActions.set(tool, eventHandlers.click); }
4071
4221
  }
4072
4222
 
4073
4223
  return tool;
@@ -4466,7 +4616,7 @@ function build(instance, baseElem, optionsOrMethod) {
4466
4616
 
4467
4617
  dom.delegate(panel, 'click', '.ge-settings-close', function(e) {
4468
4618
  e.preventDefault();
4469
- if (mode === 'sidebar') { changeSelection(null); } else { closeSettings(); }
4619
+ if (mode === 'sidebar') { changeTarget(null); } else { closeSettings(); }
4470
4620
  });
4471
4621
 
4472
4622
  settingsPanels[mode] = document.body.appendChild(panel);
@@ -4567,7 +4717,7 @@ function build(instance, baseElem, optionsOrMethod) {
4567
4717
  applySidebar();
4568
4718
  }
4569
4719
 
4570
- /** Editing stops: out of sight, with the selected node's panel back in its drawer. The selection stays. */
4720
+ /** Editing stops: out of sight, with the target's panel back in its drawer. The target stays. */
4571
4721
  function hideSidebar() {
4572
4722
  unshowDetails();
4573
4723
 
@@ -4606,7 +4756,7 @@ function build(instance, baseElem, optionsOrMethod) {
4606
4756
  var panel = settingsPanels.sidebar;
4607
4757
  if (!panel || !isEditing()) { return; }
4608
4758
 
4609
- var details = selected ? detailsOf(selected) : null;
4759
+ var details = activeTarget ? detailsOf(activeTarget) : null;
4610
4760
  if (details ? sidebarShown && sidebarShown.details === details : !sidebarShown && sidebarEmpty) { return; }
4611
4761
 
4612
4762
  unshowSidebar();
@@ -4622,11 +4772,10 @@ function build(instance, baseElem, optionsOrMethod) {
4622
4772
  return;
4623
4773
  }
4624
4774
 
4625
- sidebarShown = { node: selected, details: details, home: details.parentElement, next: details.nextElementSibling };
4626
- setSidebarTitle(t('panel.title', { kind: kindLabel(selected) }));
4775
+ sidebarShown = { node: activeTarget, details: details, home: details.parentElement, next: details.nextElementSibling };
4776
+ setSidebarTitle(t('panel.title', { kind: kindLabel(activeTarget) }));
4627
4777
  holder.appendChild(details);
4628
4778
  dom.show(details);
4629
- dom.addClass(selected, 'ge-settings-target');
4630
4779
  }
4631
4780
 
4632
4781
  /**
@@ -4690,17 +4839,6 @@ function build(instance, baseElem, optionsOrMethod) {
4690
4839
  return null;
4691
4840
  }
4692
4841
 
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
4842
  /**
4705
4843
  * Under the gear, or over it when there is more room there, inside
4706
4844
  * the window, and no taller than the room it has: past that its body
@@ -6336,30 +6474,13 @@ function build(instance, baseElem, optionsOrMethod) {
6336
6474
  var node = nodeFrom(value);
6337
6475
  if (!isTarget(node)) {
6338
6476
  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');
6477
+ warn('setActiveTarget: ' + named + ' is not a node of the canvas with settings');
6340
6478
  return;
6341
6479
  }
6342
6480
 
6343
6481
  changeTarget(node);
6344
6482
  }
6345
6483
 
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
6484
  var own = {
6364
6485
  getHtml: getHtml,
6365
6486
  getPlainHtml: getPlainHtml,
@@ -6393,8 +6514,6 @@ function build(instance, baseElem, optionsOrMethod) {
6393
6514
  setUtility: setUtility,
6394
6515
  getActiveTarget: function() { return settings.active_target ? activeTarget : null; },
6395
6516
  setActiveTarget: apiSetActiveTarget,
6396
- getSelected: function() { return panelMode() === 'sidebar' ? selected : null; },
6397
- setSelected: apiSetSelected,
6398
6517
  };
6399
6518
 
6400
6519
  Object.keys(own).forEach(function(name) {
@@ -188,6 +188,7 @@ GridEditor.locales.es = {
188
188
  'tool.delete_section': 'Quitar sección',
189
189
  'confirm.delete_section': '¿Seguro que quieres borrar esta sección y todo su contenido?',
190
190
  'tool.copy': 'Copiar',
191
+ 'tool.cut': 'Cortar',
191
192
  'tool.paste': 'Pegar',
192
193
  'clipboard.paste_row': 'Pegar fila',
193
194
  'clipboard.paste_section': 'Pegar sección',
@@ -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 || [];