@themarioga/grid-editor 9.0.0-beta.4 → 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.
- package/CHANGELOG.md +49 -0
- package/README.md +29 -17
- package/UPGRADING.md +24 -5
- package/dist/grideditor.bundle.min.js +3 -3
- package/dist/grideditor.css +5 -4
- package/dist/grideditor.d.ts +10 -15
- package/dist/grideditor.esm.js +151 -113
- package/dist/grideditor.jquery.js +1 -3
- package/dist/grideditor.jquery.min.js +1 -1
- package/dist/grideditor.jquery.min.js.map +2 -2
- package/dist/grideditor.js +151 -113
- package/dist/grideditor.min.css +1 -1
- package/dist/grideditor.min.css.map +1 -1
- package/dist/grideditor.min.js +2 -2
- package/dist/grideditor.min.js.map +3 -3
- package/dist/plugins/grideditor.accordion.esm.js +7 -0
- package/dist/plugins/grideditor.accordion.js +7 -0
- package/dist/plugins/grideditor.accordion.min.js +1 -1
- package/dist/plugins/grideditor.accordion.min.js.map +3 -3
- package/dist/plugins/grideditor.card.esm.js +4 -0
- package/dist/plugins/grideditor.card.js +4 -0
- package/dist/plugins/grideditor.card.min.js +1 -1
- package/dist/plugins/grideditor.card.min.js.map +3 -3
- package/dist/plugins/grideditor.carousel.esm.js +4 -0
- package/dist/plugins/grideditor.carousel.js +4 -0
- package/dist/plugins/grideditor.carousel.min.js +1 -1
- package/dist/plugins/grideditor.carousel.min.js.map +2 -2
- package/dist/plugins/grideditor.clipboard.esm.js +3 -18
- package/dist/plugins/grideditor.clipboard.js +3 -18
- package/dist/plugins/grideditor.clipboard.min.js +1 -1
- package/dist/plugins/grideditor.clipboard.min.js.map +3 -3
- package/dist/plugins/grideditor.history.esm.js +1 -6
- package/dist/plugins/grideditor.history.js +1 -6
- package/dist/plugins/grideditor.history.min.js +1 -1
- package/dist/plugins/grideditor.history.min.js.map +3 -3
- package/dist/plugins/grideditor.offcanvas.esm.js +185 -4
- package/dist/plugins/grideditor.offcanvas.js +185 -4
- package/dist/plugins/grideditor.offcanvas.min.js +1 -1
- package/dist/plugins/grideditor.offcanvas.min.js.map +3 -3
- package/dist/plugins/grideditor.popup.esm.js +185 -4
- package/dist/plugins/grideditor.popup.js +185 -4
- package/dist/plugins/grideditor.popup.min.js +1 -1
- package/dist/plugins/grideditor.popup.min.js.map +3 -3
- package/dist/plugins/grideditor.tabs.esm.js +4 -0
- package/dist/plugins/grideditor.tabs.js +4 -0
- package/dist/plugins/grideditor.tabs.min.js +1 -1
- package/dist/plugins/grideditor.tabs.min.js.map +2 -2
- package/docs/events.md +14 -11
- package/docs/plugins.md +20 -8
- package/example/clipboard.html +13 -10
- package/package.json +1 -1
- package/src/js/grideditor.jquery.js +0 -2
- package/src/js/grideditor.js +211 -125
- package/src/js/plugins/grideditor.accordion.js +9 -0
- package/src/js/plugins/grideditor.card.js +5 -0
- package/src/js/plugins/grideditor.carousel.js +5 -0
- package/src/js/plugins/grideditor.clipboard.js +11 -24
- package/src/js/plugins/grideditor.history.js +3 -6
- package/src/js/plugins/grideditor.offcanvas.js +8 -0
- package/src/js/plugins/grideditor.popup.js +7 -0
- package/src/js/plugins/grideditor.tabs.js +5 -0
- package/src/js/triggers/triggers.js +211 -11
- package/src/less/grideditor.less +5 -4
- package/types/grideditor.d.ts +10 -15
package/src/js/grideditor.js
CHANGED
|
@@ -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
|
|
447
|
-
//
|
|
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) {
|
|
@@ -467,8 +465,9 @@ function build(instance, baseElem, optionsOrMethod) {
|
|
|
467
465
|
var confirmDialog = null; // The delete confirmation, built when first needed
|
|
468
466
|
var sizePicker = null; // The open column size picker, if there is one
|
|
469
467
|
var sourceOpen = false; // Whether the canvas is being edited as html
|
|
468
|
+
var previewing = false; // Whether the preview button is pressed: not while the mouse is only over it
|
|
470
469
|
var dropMarker = null; // The line showing where a dragged toolbar button would land
|
|
471
|
-
var activeTarget = null; // The
|
|
470
|
+
var activeTarget = null; // The node the toolbar adds to, and the sidebar shows, with active_target
|
|
472
471
|
var toolbarLifetime = null; // Aborted when the toolbar is rebuilt or taken away
|
|
473
472
|
var closeOverflowMenu = function() {}; // Folds the toolbar's overflow menu away, when it has one
|
|
474
473
|
var refitToolbar = function() {}; // Works out again what the toolbar's overflow menu holds, when it has one
|
|
@@ -479,7 +478,6 @@ function build(instance, baseElem, optionsOrMethod) {
|
|
|
479
478
|
var sortables = []; // Every list made sortable, so deinit destroys exactly those
|
|
480
479
|
var instanceId = ++editorCounter; // Scopes the sortable groups to this editor
|
|
481
480
|
var destroyed = false;
|
|
482
|
-
var selected = null; // The node whose settings the sidebar shows, with settings_panel 'sidebar'
|
|
483
481
|
var sidebarCollapsed = null; // Folded away, once the sidebar has been shown: the window's width decides the first time
|
|
484
482
|
var pluginHandle = null; // What the plugins were handed, for the hooks that call them back
|
|
485
483
|
|
|
@@ -1097,9 +1095,7 @@ function build(instance, baseElem, optionsOrMethod) {
|
|
|
1097
1095
|
/* A click on the host's plain content offers to make it a text */
|
|
1098
1096
|
dom.delegate(canvas, 'click', '.ge-content', onContentClick, signal);
|
|
1099
1097
|
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
if (settings.active_target || sidebarMode) {
|
|
1098
|
+
if (settings.active_target) {
|
|
1103
1099
|
// The click a drag ends in - a resize, a move - is not one:
|
|
1104
1100
|
// it comes where the pointer let go, not where it pressed
|
|
1105
1101
|
var pressed = null;
|
|
@@ -1112,66 +1108,73 @@ function build(instance, baseElem, optionsOrMethod) {
|
|
|
1112
1108
|
if (!dom.hasClass(canvas, 'ge-editing')) { return; }
|
|
1113
1109
|
if (from && Math.abs(e.clientX - from.x) + Math.abs(e.clientY - from.y) > settings.drag.threshold) { return; }
|
|
1114
1110
|
|
|
1115
|
-
|
|
1116
|
-
// A tool that took its node off the canvas says nothing of where the click was
|
|
1117
|
-
if (sidebarMode && canvas.contains(e.target)) { changeSelection(settingsNodeAt(e.target)); }
|
|
1111
|
+
clickTarget(e);
|
|
1118
1112
|
}, signal);
|
|
1119
1113
|
|
|
1120
1114
|
// Escape is the panel's, the dialog's, and a field's or a
|
|
1121
1115
|
// text's while one has the focus; after those, it is the
|
|
1122
|
-
//
|
|
1116
|
+
// target's
|
|
1123
1117
|
document.addEventListener('keydown', function(e) {
|
|
1124
1118
|
if (e.key !== 'Escape' || openSettingsState || dialogState) { return; }
|
|
1125
1119
|
if (confirmDialog && dom.hasClass(confirmDialog, 'show')) { return; }
|
|
1126
1120
|
var focus = document.activeElement;
|
|
1127
1121
|
if (focus && (dom.is(focus, 'input, textarea, select') || focus.isContentEditable)) { return; }
|
|
1128
1122
|
|
|
1129
|
-
if (
|
|
1130
|
-
changeSelection(null);
|
|
1131
|
-
} else if (activeTarget) {
|
|
1132
|
-
changeTarget(null);
|
|
1133
|
-
}
|
|
1123
|
+
if (activeTarget) { changeTarget(null); }
|
|
1134
1124
|
}, signal);
|
|
1135
|
-
}
|
|
1136
1125
|
|
|
1137
|
-
|
|
1138
|
-
// 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
|
|
1139
1127
|
canvas.addEventListener('focusin', function(e) {
|
|
1140
1128
|
var node = isEditing() ? settingsNodeAt(e.target) : null;
|
|
1141
|
-
if (node) {
|
|
1129
|
+
if (node) { changeTarget(node); }
|
|
1142
1130
|
}, signal);
|
|
1143
1131
|
|
|
1144
1132
|
// A click on the page, away from the canvas and the editor's own
|
|
1145
|
-
// controls, puts the
|
|
1146
|
-
// 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 });
|
|
1147
1139
|
document.addEventListener('click', function(e) {
|
|
1148
1140
|
var target = e.target;
|
|
1149
|
-
|
|
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; }
|
|
1150
1145
|
if (!dom.attached(target) || canvas.contains(target)) { return; }
|
|
1151
1146
|
if (dom.closest(target, EDITOR_CONTROLS) || canvas.querySelector('.ge-rte-active')) { return; }
|
|
1152
1147
|
|
|
1153
|
-
|
|
1148
|
+
changeTarget(null);
|
|
1154
1149
|
}, signal);
|
|
1150
|
+
}
|
|
1155
1151
|
|
|
1152
|
+
if (panelMode() === 'sidebar') {
|
|
1156
1153
|
window.addEventListener('resize', reserveSidebarRoom, signal);
|
|
1157
1154
|
}
|
|
1158
1155
|
|
|
1159
1156
|
/* Whatever the click was for - a text, a tool - it also says
|
|
1160
|
-
where the toolbar adds next
|
|
1161
|
-
says nowhere, and the toolbar adds
|
|
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. */
|
|
1162
1160
|
function clickTarget(e) {
|
|
1163
|
-
|
|
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);
|
|
1164
1165
|
|
|
1165
1166
|
// The target's own background, or its drawer's, clicked
|
|
1166
1167
|
// again takes it back. What is in it - a text, a tool, a
|
|
1167
|
-
// nested column - keeps it, or makes that the target
|
|
1168
|
-
|
|
1169
|
-
|
|
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')))) {
|
|
1170
1173
|
changeTarget(null);
|
|
1171
1174
|
return;
|
|
1172
1175
|
}
|
|
1173
1176
|
|
|
1174
|
-
changeTarget(
|
|
1177
|
+
changeTarget(node);
|
|
1175
1178
|
}
|
|
1176
1179
|
}
|
|
1177
1180
|
|
|
@@ -1338,21 +1341,20 @@ function build(instance, baseElem, optionsOrMethod) {
|
|
|
1338
1341
|
btnGroup.appendChild(htmlButton);
|
|
1339
1342
|
}
|
|
1340
1343
|
|
|
1344
|
+
// Over it, the canvas looks as the page will; pressed, it stays
|
|
1345
|
+
// that way and the page's own controls work
|
|
1341
1346
|
var previewButton = dom.create('<button type="button" class="btn btn-sm btn-primary gm-preview"><i class="bi bi-eye-fill"></i></button>');
|
|
1342
|
-
var endPreview = function() {
|
|
1343
|
-
if (!dom.hasClass(previewButton, 'active')) {
|
|
1344
|
-
dom.addClass(canvas, 'ge-editing');
|
|
1345
|
-
}
|
|
1346
|
-
};
|
|
1347
1347
|
previewButton.setAttribute('title', t('tool.preview'));
|
|
1348
|
+
dom.toggleClass(previewButton, 'active btn-danger', previewing);
|
|
1348
1349
|
previewButton.addEventListener('mouseenter', function() {
|
|
1349
1350
|
dom.removeClass(canvas, 'ge-editing');
|
|
1350
1351
|
});
|
|
1351
1352
|
previewButton.addEventListener('click', function() {
|
|
1352
|
-
|
|
1353
|
-
|
|
1353
|
+
setPreview(!previewing);
|
|
1354
|
+
});
|
|
1355
|
+
previewButton.addEventListener('mouseleave', function() {
|
|
1356
|
+
if (!previewing) { dom.addClass(canvas, 'ge-editing'); }
|
|
1354
1357
|
});
|
|
1355
|
-
previewButton.addEventListener('mouseleave', endPreview);
|
|
1356
1358
|
btnGroup.appendChild(previewButton);
|
|
1357
1359
|
|
|
1358
1360
|
// Floated right after the source and preview buttons, so it
|
|
@@ -1467,14 +1469,8 @@ function build(instance, baseElem, optionsOrMethod) {
|
|
|
1467
1469
|
// then - or taken away for good
|
|
1468
1470
|
if (!mainControls || destroyed) { return; }
|
|
1469
1471
|
|
|
1470
|
-
var previewing = !!dom.one(mainControls, '.gm-preview.active');
|
|
1471
|
-
|
|
1472
1472
|
removeMainControls();
|
|
1473
1473
|
createMainControls();
|
|
1474
|
-
|
|
1475
|
-
if (previewing) {
|
|
1476
|
-
dom.addClass(dom.one(mainControls, '.gm-preview'), 'active btn-danger');
|
|
1477
|
-
}
|
|
1478
1474
|
onScroll();
|
|
1479
1475
|
}
|
|
1480
1476
|
|
|
@@ -1806,13 +1802,13 @@ function build(instance, baseElem, optionsOrMethod) {
|
|
|
1806
1802
|
var placed = made;
|
|
1807
1803
|
|
|
1808
1804
|
if (item.inColumn) {
|
|
1809
|
-
// Where it lands in a column,
|
|
1810
|
-
// own anywhere else
|
|
1811
|
-
|
|
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);
|
|
1812
1808
|
} else if (!acceptsBlock(where.region, made)) {
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1809
|
+
where = canvasAfterTopOf(where.region);
|
|
1810
|
+
} else if (dom.is(where.region, '.row')) {
|
|
1811
|
+
placed = wrapFor(where.region, made);
|
|
1816
1812
|
}
|
|
1817
1813
|
|
|
1818
1814
|
return addNode(item.kind, made, function() {
|
|
@@ -1824,12 +1820,45 @@ function build(instance, baseElem, optionsOrMethod) {
|
|
|
1824
1820
|
}, { parent: where.region, source: item.source || source || 'dragdrop' });
|
|
1825
1821
|
}
|
|
1826
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
|
+
|
|
1827
1859
|
/** A detached row with one full width column holding `node`. */
|
|
1828
1860
|
function inRowOfItsOwn(node) {
|
|
1829
|
-
|
|
1830
|
-
row.appendChild(createColumn(MAX_COL_SIZE)).appendChild(node);
|
|
1831
|
-
|
|
1832
|
-
return row;
|
|
1861
|
+
return rowHolding(createColumn(MAX_COL_SIZE), node);
|
|
1833
1862
|
}
|
|
1834
1863
|
|
|
1835
1864
|
/** A line where the block would go, following the pointer. */
|
|
@@ -1869,9 +1898,9 @@ function build(instance, baseElem, optionsOrMethod) {
|
|
|
1869
1898
|
: rowFromLayout(button.getAttribute('data-ge-layout'));
|
|
1870
1899
|
|
|
1871
1900
|
// A container belongs in a column: dropped straight onto the
|
|
1872
|
-
// canvas it brings a row and a column of its own
|
|
1873
|
-
|
|
1874
|
-
|
|
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);
|
|
1875
1904
|
|
|
1876
1905
|
return addNode(container ? type : 'row', made, function() {
|
|
1877
1906
|
if (where.before) {
|
|
@@ -2163,6 +2192,25 @@ function build(instance, baseElem, optionsOrMethod) {
|
|
|
2163
2192
|
init();
|
|
2164
2193
|
}
|
|
2165
2194
|
|
|
2195
|
+
/**
|
|
2196
|
+
* The preview button pressed, or let go: the one way the preview
|
|
2197
|
+
* changes, told only when it does. Pressed, the canvas stops looking
|
|
2198
|
+
* edited and a plugin lets the page's own controls work - a popup's
|
|
2199
|
+
* trigger opens it - until it is let go. Only hovering the button
|
|
2200
|
+
* previews the look alone, and tells no one.
|
|
2201
|
+
*/
|
|
2202
|
+
function setPreview(on) {
|
|
2203
|
+
on = !!on;
|
|
2204
|
+
if (on === previewing) { return; }
|
|
2205
|
+
|
|
2206
|
+
previewing = on;
|
|
2207
|
+
var button = mainControls ? dom.one(mainControls, '.gm-preview') : null;
|
|
2208
|
+
if (button) { dom.toggleClass(button, 'active btn-danger', on); }
|
|
2209
|
+
dom.toggleClass(canvas, 'ge-editing', !on);
|
|
2210
|
+
plugins('onPreviewChange', on);
|
|
2211
|
+
emit('preview-change', { canvas: canvas, previewing: on });
|
|
2212
|
+
}
|
|
2213
|
+
|
|
2166
2214
|
/**
|
|
2167
2215
|
* The canvas as html, in the textarea in its place, to edit by hand.
|
|
2168
2216
|
* A feature plugin's onSourceOpen may put a code editor over the
|
|
@@ -2170,10 +2218,10 @@ function build(instance, baseElem, optionsOrMethod) {
|
|
|
2170
2218
|
* what the canvas is made of again.
|
|
2171
2219
|
*/
|
|
2172
2220
|
function openSource() {
|
|
2221
|
+
setPreview(false);
|
|
2173
2222
|
deinit();
|
|
2174
2223
|
// The canvas is made again from the html when it comes back
|
|
2175
2224
|
changeTarget(null);
|
|
2176
|
-
changeSelection(null);
|
|
2177
2225
|
htmlTextArea.style.height = (0.8 * document.documentElement.clientHeight) + 'px';
|
|
2178
2226
|
htmlTextArea.value = canvas.innerHTML;
|
|
2179
2227
|
dom.show(htmlTextArea);
|
|
@@ -2197,15 +2245,13 @@ function build(instance, baseElem, optionsOrMethod) {
|
|
|
2197
2245
|
}
|
|
2198
2246
|
|
|
2199
2247
|
/**
|
|
2200
|
-
* What can be the active target: a
|
|
2201
|
-
*
|
|
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.
|
|
2202
2252
|
*/
|
|
2203
|
-
function targetSelector() {
|
|
2204
|
-
return ['.column'].concat(pluginHooks('regions')).join(', ');
|
|
2205
|
-
}
|
|
2206
|
-
|
|
2207
2253
|
function isTarget(node) {
|
|
2208
|
-
return !!node && node !== canvas && canvas.contains(node) &&
|
|
2254
|
+
return !!node && node !== canvas && canvas.contains(node) && detailsFor.has(node);
|
|
2209
2255
|
}
|
|
2210
2256
|
|
|
2211
2257
|
/** The one way the active target changes, told only when it does. */
|
|
@@ -2213,19 +2259,89 @@ function build(instance, baseElem, optionsOrMethod) {
|
|
|
2213
2259
|
if (node === activeTarget) { return; }
|
|
2214
2260
|
|
|
2215
2261
|
var from = activeTarget;
|
|
2216
|
-
if (from) { dom.removeClass(from, 'ge-
|
|
2262
|
+
if (from) { dom.removeClass(from, 'ge-selected'); }
|
|
2217
2263
|
activeTarget = node;
|
|
2218
|
-
if (node && dom.hasClass(canvas, 'ge-editing')) { dom.addClass(node, 'ge-
|
|
2264
|
+
if (node && dom.hasClass(canvas, 'ge-editing')) { dom.addClass(node, 'ge-selected'); }
|
|
2265
|
+
renderSidebar();
|
|
2219
2266
|
|
|
2220
2267
|
emit('target-change', { canvas: canvas, target: node, from: from });
|
|
2221
2268
|
}
|
|
2222
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
|
+
|
|
2223
2338
|
/**
|
|
2224
2339
|
* A toolbar button's click with an active target: what it makes goes
|
|
2225
|
-
* where a drop at the target's
|
|
2340
|
+
* where a drop at the end of the target's region would put it, in
|
|
2341
|
+
* whatever it lacks to be there.
|
|
2226
2342
|
*/
|
|
2227
2343
|
function addToTarget(button, source) {
|
|
2228
|
-
var made = insertFromToolbar(button, { region: activeTarget, before: null }, source);
|
|
2344
|
+
var made = insertFromToolbar(button, { region: effectiveRegion(activeTarget), before: null }, source);
|
|
2229
2345
|
if (made && made.scrollIntoView) { made.scrollIntoView({ behavior: 'smooth' }); }
|
|
2230
2346
|
}
|
|
2231
2347
|
|
|
@@ -2235,9 +2351,9 @@ function build(instance, baseElem, optionsOrMethod) {
|
|
|
2235
2351
|
if (openSettingsState && !dom.attached(openSettingsState.node)) {
|
|
2236
2352
|
closeSettings();
|
|
2237
2353
|
}
|
|
2238
|
-
// The same for the
|
|
2239
|
-
if (
|
|
2240
|
-
|
|
2354
|
+
// The same for the target, which the sidebar stops showing
|
|
2355
|
+
if (activeTarget && !canvas.contains(activeTarget)) {
|
|
2356
|
+
changeTarget(null);
|
|
2241
2357
|
}
|
|
2242
2358
|
// And a dialog showing part of a panel that is gone
|
|
2243
2359
|
if (dialogState && dialogState.home && !dom.attached(dialogState.home)) {
|
|
@@ -2245,7 +2361,8 @@ function build(instance, baseElem, optionsOrMethod) {
|
|
|
2245
2361
|
}
|
|
2246
2362
|
|
|
2247
2363
|
runFilter(true);
|
|
2248
|
-
|
|
2364
|
+
// A getHtml in the middle of a preview comes back to it
|
|
2365
|
+
dom.toggleClass(canvas, 'ge-editing', !previewing);
|
|
2249
2366
|
dom.toggleClass(canvas, 'ge-drag-drawer', settings.drag_handle === 'drawer');
|
|
2250
2367
|
addAllColClasses();
|
|
2251
2368
|
var cutter = textCutter();
|
|
@@ -2265,7 +2382,7 @@ function build(instance, baseElem, optionsOrMethod) {
|
|
|
2265
2382
|
if (activeTarget && !canvas.contains(activeTarget)) {
|
|
2266
2383
|
changeTarget(null);
|
|
2267
2384
|
} else if (activeTarget) {
|
|
2268
|
-
dom.addClass(activeTarget, 'ge-
|
|
2385
|
+
dom.addClass(activeTarget, 'ge-selected');
|
|
2269
2386
|
}
|
|
2270
2387
|
|
|
2271
2388
|
showSidebar();
|
|
@@ -2277,7 +2394,7 @@ function build(instance, baseElem, optionsOrMethod) {
|
|
|
2277
2394
|
hideSidebar();
|
|
2278
2395
|
dom.removeClass(canvas, 'ge-editing ge-drag-drawer ge-dropping');
|
|
2279
2396
|
// The mark goes, the target stays: getHtml comes straight back
|
|
2280
|
-
if (activeTarget) { dom.removeClass(activeTarget, 'ge-
|
|
2397
|
+
if (activeTarget) { dom.removeClass(activeTarget, 'ge-selected'); }
|
|
2281
2398
|
// Before the drawers and the text blocks come off: an editor
|
|
2282
2399
|
// plugin closes its editors here, and finds them where it left them
|
|
2283
2400
|
plugins('onBeforeDeinit');
|
|
@@ -2379,8 +2496,8 @@ function build(instance, baseElem, optionsOrMethod) {
|
|
|
2379
2496
|
var copy = copyCanvas();
|
|
2380
2497
|
var root = copy.root;
|
|
2381
2498
|
|
|
2382
|
-
[root].concat(dom.all(root, '.ge-
|
|
2383
|
-
dom.removeClass(node, 'ge-
|
|
2499
|
+
[root].concat(dom.all(root, '.ge-selected, .ge-settings-target')).forEach(function(node) {
|
|
2500
|
+
dom.removeClass(node, 'ge-selected ge-settings-target');
|
|
2384
2501
|
dom.dropEmptyClass(node);
|
|
2385
2502
|
});
|
|
2386
2503
|
dom.all(root, '.ge-drop-marker').forEach(function(marker) { marker.remove(); });
|
|
@@ -2465,6 +2582,8 @@ function build(instance, baseElem, optionsOrMethod) {
|
|
|
2465
2582
|
}
|
|
2466
2583
|
}
|
|
2467
2584
|
|
|
2585
|
+
// What a preview opened goes with the markup it was in
|
|
2586
|
+
setPreview(false);
|
|
2468
2587
|
deinit();
|
|
2469
2588
|
dom.setHtml(canvas, html);
|
|
2470
2589
|
init();
|
|
@@ -2481,9 +2600,9 @@ function build(instance, baseElem, optionsOrMethod) {
|
|
|
2481
2600
|
plugins('onDestroy');
|
|
2482
2601
|
// The html being edited is what the canvas is left with
|
|
2483
2602
|
if (sourceOpen) { closeSource(); }
|
|
2603
|
+
setPreview(false);
|
|
2484
2604
|
deinit();
|
|
2485
2605
|
activeTarget = null;
|
|
2486
|
-
selected = null;
|
|
2487
2606
|
if (sidebarHolder === instance) { sidebarHolder = null; }
|
|
2488
2607
|
removeConfirmModal();
|
|
2489
2608
|
removeSettingsPanels();
|
|
@@ -2582,6 +2701,9 @@ function build(instance, baseElem, optionsOrMethod) {
|
|
|
2582
2701
|
addSettingsTool: addSettingsTool,
|
|
2583
2702
|
deleteNode: deleteNode,
|
|
2584
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,
|
|
2585
2707
|
createPaneControls: createPaneControls,
|
|
2586
2708
|
makeLabelEditable: makeLabelEditable,
|
|
2587
2709
|
labelIn: labelIn,
|
|
@@ -2593,6 +2715,7 @@ function build(instance, baseElem, optionsOrMethod) {
|
|
|
2593
2715
|
operate: operate,
|
|
2594
2716
|
kindOf: kindOf,
|
|
2595
2717
|
view: getView,
|
|
2718
|
+
previewing: function() { return previewing; },
|
|
2596
2719
|
viewTiers: function() {
|
|
2597
2720
|
return tiersFor(curView).map(function(tier) { return tier.key; });
|
|
2598
2721
|
},
|
|
@@ -2633,22 +2756,16 @@ function build(instance, baseElem, optionsOrMethod) {
|
|
|
2633
2756
|
? dom.all(mainControls, '[data-ge-toolbar="feature"][data-ge-feature="' + name + '"]')
|
|
2634
2757
|
: [];
|
|
2635
2758
|
},
|
|
2636
|
-
getSelected: function() { return panelMode() === 'sidebar' ? selected : null; },
|
|
2637
2759
|
getActiveTarget: function() { return settings.active_target ? activeTarget : null; },
|
|
2638
2760
|
// True when it took: a node that cannot be, or no setting
|
|
2639
2761
|
// for it, says nothing, since a plugin putting back what it
|
|
2640
2762
|
// remembers cannot know the node is still one
|
|
2641
|
-
setSelected: function(node) {
|
|
2642
|
-
var chosen = panelMode() === 'sidebar' && !!node && node !== canvas && canvas.contains(node) && detailsFor.has(node);
|
|
2643
|
-
if (chosen) { changeSelection(node); }
|
|
2644
|
-
return chosen;
|
|
2645
|
-
},
|
|
2646
2763
|
setActiveTarget: function(node) {
|
|
2647
2764
|
var chosen = !!settings.active_target && isTarget(node);
|
|
2648
2765
|
if (chosen) { changeTarget(node); }
|
|
2649
2766
|
return chosen;
|
|
2650
2767
|
},
|
|
2651
|
-
// What keeps Escape from the
|
|
2768
|
+
// What keeps Escape from the target, and an
|
|
2652
2769
|
// inline panel unfolded in a drawer, which Escape leaves alone
|
|
2653
2770
|
panelOpen: function() {
|
|
2654
2771
|
if (openSettingsState || dialogState) { return true; }
|
|
@@ -4447,7 +4564,7 @@ function build(instance, baseElem, optionsOrMethod) {
|
|
|
4447
4564
|
|
|
4448
4565
|
dom.delegate(panel, 'click', '.ge-settings-close', function(e) {
|
|
4449
4566
|
e.preventDefault();
|
|
4450
|
-
if (mode === 'sidebar') {
|
|
4567
|
+
if (mode === 'sidebar') { changeTarget(null); } else { closeSettings(); }
|
|
4451
4568
|
});
|
|
4452
4569
|
|
|
4453
4570
|
settingsPanels[mode] = document.body.appendChild(panel);
|
|
@@ -4548,7 +4665,7 @@ function build(instance, baseElem, optionsOrMethod) {
|
|
|
4548
4665
|
applySidebar();
|
|
4549
4666
|
}
|
|
4550
4667
|
|
|
4551
|
-
/** Editing stops: out of sight, with the
|
|
4668
|
+
/** Editing stops: out of sight, with the target's panel back in its drawer. The target stays. */
|
|
4552
4669
|
function hideSidebar() {
|
|
4553
4670
|
unshowDetails();
|
|
4554
4671
|
|
|
@@ -4587,7 +4704,7 @@ function build(instance, baseElem, optionsOrMethod) {
|
|
|
4587
4704
|
var panel = settingsPanels.sidebar;
|
|
4588
4705
|
if (!panel || !isEditing()) { return; }
|
|
4589
4706
|
|
|
4590
|
-
var details =
|
|
4707
|
+
var details = activeTarget ? detailsOf(activeTarget) : null;
|
|
4591
4708
|
if (details ? sidebarShown && sidebarShown.details === details : !sidebarShown && sidebarEmpty) { return; }
|
|
4592
4709
|
|
|
4593
4710
|
unshowSidebar();
|
|
@@ -4603,11 +4720,10 @@ function build(instance, baseElem, optionsOrMethod) {
|
|
|
4603
4720
|
return;
|
|
4604
4721
|
}
|
|
4605
4722
|
|
|
4606
|
-
sidebarShown = { node:
|
|
4607
|
-
setSidebarTitle(t('panel.title', { kind: kindLabel(
|
|
4723
|
+
sidebarShown = { node: activeTarget, details: details, home: details.parentElement, next: details.nextElementSibling };
|
|
4724
|
+
setSidebarTitle(t('panel.title', { kind: kindLabel(activeTarget) }));
|
|
4608
4725
|
holder.appendChild(details);
|
|
4609
4726
|
dom.show(details);
|
|
4610
|
-
dom.addClass(selected, 'ge-settings-target');
|
|
4611
4727
|
}
|
|
4612
4728
|
|
|
4613
4729
|
/**
|
|
@@ -4671,17 +4787,6 @@ function build(instance, baseElem, optionsOrMethod) {
|
|
|
4671
4787
|
return null;
|
|
4672
4788
|
}
|
|
4673
4789
|
|
|
4674
|
-
/** The one way the selection changes, told only when it does. */
|
|
4675
|
-
function changeSelection(node) {
|
|
4676
|
-
if (node === selected) { return; }
|
|
4677
|
-
|
|
4678
|
-
var from = selected;
|
|
4679
|
-
selected = node;
|
|
4680
|
-
renderSidebar();
|
|
4681
|
-
|
|
4682
|
-
emit('selection-change', { canvas: canvas, node: node, from: from });
|
|
4683
|
-
}
|
|
4684
|
-
|
|
4685
4790
|
/**
|
|
4686
4791
|
* Under the gear, or over it when there is more room there, inside
|
|
4687
4792
|
* the window, and no taller than the room it has: past that its body
|
|
@@ -6317,30 +6422,13 @@ function build(instance, baseElem, optionsOrMethod) {
|
|
|
6317
6422
|
var node = nodeFrom(value);
|
|
6318
6423
|
if (!isTarget(node)) {
|
|
6319
6424
|
var named = typeof value === 'string' ? value : (node ? '<' + node.tagName.toLowerCase() + '>' : String(value));
|
|
6320
|
-
warn('setActiveTarget: ' + named + ' is not a
|
|
6425
|
+
warn('setActiveTarget: ' + named + ' is not a node of the canvas with settings');
|
|
6321
6426
|
return;
|
|
6322
6427
|
}
|
|
6323
6428
|
|
|
6324
6429
|
changeTarget(node);
|
|
6325
6430
|
}
|
|
6326
6431
|
|
|
6327
|
-
function apiSetSelected(value) {
|
|
6328
|
-
if (panelMode() !== 'sidebar') {
|
|
6329
|
-
warnOnceHere('sidebar-api', 'setSelected needs settings_panel "sidebar": without it, it does nothing');
|
|
6330
|
-
return;
|
|
6331
|
-
}
|
|
6332
|
-
if (value === null || value === undefined) { changeSelection(null); return; }
|
|
6333
|
-
|
|
6334
|
-
var node = nodeFrom(value);
|
|
6335
|
-
if (!node || node === canvas || !canvas.contains(node) || !detailsFor.has(node)) {
|
|
6336
|
-
var named = typeof value === 'string' ? value : (node ? '<' + node.tagName.toLowerCase() + '>' : String(value));
|
|
6337
|
-
warn('setSelected: ' + named + ' is not a node of the canvas with settings');
|
|
6338
|
-
return;
|
|
6339
|
-
}
|
|
6340
|
-
|
|
6341
|
-
changeSelection(node);
|
|
6342
|
-
}
|
|
6343
|
-
|
|
6344
6432
|
var own = {
|
|
6345
6433
|
getHtml: getHtml,
|
|
6346
6434
|
getPlainHtml: getPlainHtml,
|
|
@@ -6374,8 +6462,6 @@ function build(instance, baseElem, optionsOrMethod) {
|
|
|
6374
6462
|
setUtility: setUtility,
|
|
6375
6463
|
getActiveTarget: function() { return settings.active_target ? activeTarget : null; },
|
|
6376
6464
|
setActiveTarget: apiSetActiveTarget,
|
|
6377
|
-
getSelected: function() { return panelMode() === 'sidebar' ? selected : null; },
|
|
6378
|
-
setSelected: apiSetSelected,
|
|
6379
6465
|
};
|
|
6380
6466
|
|
|
6381
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
|