@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
|
@@ -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
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
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
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
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
|
-
|
|
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.
|
|
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.
|
|
218
|
+
var node = ge.getActiveTarget();
|
|
232
219
|
var kind = node && ge.kindOf(node);
|
|
233
220
|
if (!kind || !categoryOf(kind)) { return false; }
|
|
234
221
|
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
*
|
|
13
13
|
* A step is the canvas's markup as ge.snapshotHtml() gives it, kept `delay`
|
|
14
14
|
* ms after the last change: a drag or a burst of typing is one step. Going
|
|
15
|
-
* to one puts its markup back with ge.setHtml(), and the
|
|
16
|
-
*
|
|
15
|
+
* to one puts its markup back with ge.setHtml(), and the target is chosen
|
|
16
|
+
* again by where it was.
|
|
17
17
|
*
|
|
18
18
|
* Typing in a text is the text editor's own to undo while it has the focus:
|
|
19
19
|
* the keys are left alone then, and what was typed becomes a step when it
|
|
@@ -227,7 +227,6 @@ GridEditor.features.history = function(ge) {
|
|
|
227
227
|
var to = index + step;
|
|
228
228
|
if (to < 0 || to >= stack.length) { return false; }
|
|
229
229
|
|
|
230
|
-
var selected = pathOf(ge.getSelected());
|
|
231
230
|
var target = pathOf(ge.getActiveTarget());
|
|
232
231
|
|
|
233
232
|
stopObserving();
|
|
@@ -236,9 +235,7 @@ GridEditor.features.history = function(ge) {
|
|
|
236
235
|
// The step as the canvas reads it back, so that is what is compared with
|
|
237
236
|
stack[index] = ge.snapshotHtml();
|
|
238
237
|
|
|
239
|
-
var node = resolve(
|
|
240
|
-
if (node) { ge.setSelected(node); }
|
|
241
|
-
node = resolve(target);
|
|
238
|
+
var node = resolve(target);
|
|
242
239
|
if (node) { ge.setActiveTarget(node); }
|
|
243
240
|
|
|
244
241
|
observe();
|
|
@@ -317,6 +317,11 @@ GridEditor.containers.offcanvas = function(ge) {
|
|
|
317
317
|
labelKey: 'container.add_offcanvas',
|
|
318
318
|
paneKind: 'offcanvas',
|
|
319
319
|
|
|
320
|
+
// Where rows go: the offcanvas's body
|
|
321
|
+
regionOf: function(container) {
|
|
322
|
+
return dom.one(container, '.offcanvas-body');
|
|
323
|
+
},
|
|
324
|
+
|
|
320
325
|
// The ids a copy of an offcanvas has to rename together
|
|
321
326
|
references: ['data-ge-offcanvas-id', 'data-ge-offcanvas-target'],
|
|
322
327
|
|
|
@@ -328,6 +333,9 @@ GridEditor.containers.offcanvas = function(ge) {
|
|
|
328
333
|
dropTriggerMarks(ge.canvas);
|
|
329
334
|
},
|
|
330
335
|
|
|
336
|
+
// The preview pressed, the triggers open the real thing; let go, it closes
|
|
337
|
+
onPreviewChange: triggers.onPreviewChange,
|
|
338
|
+
|
|
331
339
|
// What onDeinit and unmark do, on a copy of the canvas
|
|
332
340
|
cleanMarkup: function(root) {
|
|
333
341
|
var definition = this;
|
|
@@ -27,11 +27,18 @@ GridEditor.containers.popup = function(ge) {
|
|
|
27
27
|
labelKey: 'container.add_popup',
|
|
28
28
|
paneKind: 'popup',
|
|
29
29
|
|
|
30
|
+
// Where rows go: the popup's body
|
|
31
|
+
regionOf: function(container) {
|
|
32
|
+
return dom.one(container, '.modal-body');
|
|
33
|
+
},
|
|
34
|
+
|
|
30
35
|
// The ids a copy of a popup has to rename together
|
|
31
36
|
references: ['data-ge-popup-id', 'data-ge-popup-target'],
|
|
32
37
|
|
|
33
38
|
onInit: triggers.onInit,
|
|
34
39
|
onDeinit: triggers.onDeinit,
|
|
40
|
+
// The preview pressed, the triggers open the real thing; let go, it closes
|
|
41
|
+
onPreviewChange: triggers.onPreviewChange,
|
|
35
42
|
|
|
36
43
|
// What onDeinit and unmark do, on a copy of the canvas
|
|
37
44
|
cleanMarkup: function(root) {
|
|
@@ -368,6 +368,11 @@ GridEditor.containers.tabs = function(ge) {
|
|
|
368
368
|
addPaneKey: 'container.add_tab',
|
|
369
369
|
paneKind: 'tab',
|
|
370
370
|
|
|
371
|
+
// Where rows go: the pane showing, or the pane of the tab
|
|
372
|
+
regionOf: function(container, tab) {
|
|
373
|
+
return tab ? paneOf(container, tab) : dom.one(container, ':scope > .tab-content > .tab-pane.active');
|
|
374
|
+
},
|
|
375
|
+
|
|
371
376
|
create: function(options) {
|
|
372
377
|
var container = dom.element('div', { 'data-ge-container': 'tabs' });
|
|
373
378
|
var labels = options.labels || [];
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
* A trigger is markup the host owns - a button, a link - anywhere in the
|
|
5
5
|
* canvas, that points at a container by id. While editing it must not reach
|
|
6
|
-
* Bootstrap, and one that points at nothing is warned about.
|
|
6
|
+
* Bootstrap, and one that points at nothing is warned about. With the
|
|
7
|
+
* preview button pressed it does reach it, and opens the container as the
|
|
8
|
+
* page will, until the button is let go. Not a public
|
|
7
9
|
* API: the build puts a copy of this file in each plugin that imports it,
|
|
8
10
|
* so it keeps nothing of its own between plugins.
|
|
9
11
|
*/
|
|
@@ -18,19 +20,47 @@ import * as dom from '../dom.js';
|
|
|
18
20
|
* `targetAttribute` the one a trigger names it with, and `toggle` is
|
|
19
21
|
* Bootstrap's `data-bs-toggle` for it, written on the way out.
|
|
20
22
|
*
|
|
21
|
-
* Gives back `onInit` and `
|
|
22
|
-
* its own, and `write(root)`, what onDeinit does to the
|
|
23
|
-
* cleanMarkup to do to a copy.
|
|
23
|
+
* Gives back `onInit`, `onDeinit` and `onPreviewChange`, for the plugin to
|
|
24
|
+
* hand the editor as its own, and `write(root)`, what onDeinit does to the
|
|
25
|
+
* canvas, for cleanMarkup to do to a copy.
|
|
24
26
|
*/
|
|
25
27
|
export function triggersFor(ge, kind, idAttribute, targetAttribute, toggle) {
|
|
26
28
|
var triggerClass = 'ge-' + kind + '-trigger';
|
|
27
29
|
var orphanClass = 'ge-' + kind + '-orphan';
|
|
28
30
|
var listening = null;
|
|
29
31
|
|
|
32
|
+
// What Bootstrap changes on a container as it opens and closes it
|
|
33
|
+
var STATE_ATTRIBUTES = ['style', 'aria-hidden', 'aria-modal', 'role'];
|
|
34
|
+
var STATE_CLASSES = ['show', 'showing', 'hiding'];
|
|
35
|
+
// Each container's element as the preview found it: what it goes back to
|
|
36
|
+
var before = new Map();
|
|
37
|
+
// The dismisses the preview gave back to Bootstrap, to take away again
|
|
38
|
+
var dismisses = [];
|
|
39
|
+
// What a getHtml in the middle of a preview took off, for onInit to put back
|
|
40
|
+
var saved = new Map();
|
|
41
|
+
// Where Bootstrap is with each container it has been asked to open:
|
|
42
|
+
// opening, open or closing, as its events tell. Not there once closed
|
|
43
|
+
var phases = new Map();
|
|
44
|
+
var watching = null;
|
|
45
|
+
// Let go of while Bootstrap was still closing them: what they go back to once it is done
|
|
46
|
+
var pending = new Map();
|
|
47
|
+
var PHASES = { show: 'opening', shown: 'open', hide: 'closing' };
|
|
48
|
+
|
|
30
49
|
function idOf(container) {
|
|
31
50
|
return container.getAttribute(idAttribute);
|
|
32
51
|
}
|
|
33
52
|
|
|
53
|
+
/** The modal, the panel: the element in a container with the container's id. */
|
|
54
|
+
function targetOf(container) {
|
|
55
|
+
var id = idOf(container);
|
|
56
|
+
|
|
57
|
+
return dom.all(container, '[id]').filter(function(node) { return node.id === id; })[0] || null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function targets() {
|
|
61
|
+
return dom.all(ge.canvas, '[' + idAttribute + ']').map(targetOf).filter(Boolean);
|
|
62
|
+
}
|
|
63
|
+
|
|
34
64
|
/** Whether a container with this id is on the canvas. */
|
|
35
65
|
function exists(id, root) {
|
|
36
66
|
return dom.all(root || ge.canvas, '[' + idAttribute + ']').some(function(container) {
|
|
@@ -74,24 +104,170 @@ export function triggersFor(ge, kind, idAttribute, targetAttribute, toggle) {
|
|
|
74
104
|
});
|
|
75
105
|
}
|
|
76
106
|
|
|
107
|
+
/** Bootstrap's own attributes on the triggers that point at something. */
|
|
108
|
+
function arm(root) {
|
|
109
|
+
dom.all(root, '[' + targetAttribute + ']').forEach(function(trigger) {
|
|
110
|
+
var wanted = trigger.getAttribute(targetAttribute);
|
|
111
|
+
if (!exists(wanted, root)) { return; }
|
|
112
|
+
|
|
113
|
+
trigger.setAttribute('data-bs-toggle', toggle);
|
|
114
|
+
trigger.setAttribute('data-bs-target', '#' + wanted);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function disarm() {
|
|
119
|
+
dom.all(ge.canvas, '[' + targetAttribute + ']').forEach(function(trigger) {
|
|
120
|
+
trigger.removeAttribute('data-bs-toggle');
|
|
121
|
+
trigger.removeAttribute('data-bs-target');
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
77
125
|
function write(root) {
|
|
78
126
|
root = root || ge.canvas;
|
|
79
127
|
|
|
128
|
+
// The warning marking is editing furniture, whether or not
|
|
129
|
+
// the trigger can be wired up
|
|
80
130
|
dom.all(root, '[' + targetAttribute + ']').forEach(function(trigger) {
|
|
81
|
-
var wanted = trigger.getAttribute(targetAttribute);
|
|
82
|
-
|
|
83
|
-
// The warning marking is editing furniture, whether or not
|
|
84
|
-
// the trigger can be wired up
|
|
85
131
|
dom.removeClass(trigger, orphanClass);
|
|
86
132
|
dom.dropEmptyClass(trigger);
|
|
133
|
+
});
|
|
87
134
|
|
|
88
|
-
|
|
135
|
+
arm(root);
|
|
89
136
|
|
|
90
|
-
|
|
91
|
-
|
|
137
|
+
// A container the preview opened is read as the preview found it,
|
|
138
|
+
// whether the preview goes on or Bootstrap is still closing it
|
|
139
|
+
var quiet = new Map();
|
|
140
|
+
before.forEach(function(state, target) { quiet.set(target.id, state); });
|
|
141
|
+
pending.forEach(function(state, target) { quiet.set(target.id, state); });
|
|
142
|
+
if (!quiet.size) { return; }
|
|
143
|
+
|
|
144
|
+
dom.all(root, '[id]').forEach(function(node) {
|
|
145
|
+
if (quiet.has(node.id)) { putState(node, quiet.get(node.id)); }
|
|
92
146
|
});
|
|
93
147
|
}
|
|
94
148
|
|
|
149
|
+
/** What Bootstrap may change on a container, as it is now. */
|
|
150
|
+
function stateOf(target) {
|
|
151
|
+
var state = { classes: STATE_CLASSES.filter(function(name) { return dom.hasClass(target, name); }) };
|
|
152
|
+
STATE_ATTRIBUTES.forEach(function(name) { state[name] = target.getAttribute(name); });
|
|
153
|
+
return state;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function putState(target, state) {
|
|
157
|
+
STATE_CLASSES.forEach(function(name) { dom.toggleClass(target, name, state.classes.indexOf(name) !== -1); });
|
|
158
|
+
STATE_ATTRIBUTES.forEach(function(name) {
|
|
159
|
+
// Read first: a style Bootstrap last wrote through the element's
|
|
160
|
+
// style object is only written to the attribute when it is read,
|
|
161
|
+
// and would otherwise come back, empty, after it is taken off
|
|
162
|
+
target.getAttribute(name);
|
|
163
|
+
|
|
164
|
+
if (state[name] === null) {
|
|
165
|
+
target.removeAttribute(name);
|
|
166
|
+
} else {
|
|
167
|
+
target.setAttribute(name, state[name]);
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* The preview pressed: the triggers reach Bootstrap, and so do the
|
|
174
|
+
* container's own close buttons, which editing keeps from it.
|
|
175
|
+
*/
|
|
176
|
+
function startPreview() {
|
|
177
|
+
// Again after a getHtml, whose init took them away once more
|
|
178
|
+
dismisses = [];
|
|
179
|
+
targets().forEach(function(target) {
|
|
180
|
+
if (!before.has(target)) { before.set(target, stateOf(target)); }
|
|
181
|
+
|
|
182
|
+
dom.all(target, '[data-ge-bs-dismiss="' + toggle + '"]').forEach(function(dismiss) {
|
|
183
|
+
ge.resumeToggles(dismiss);
|
|
184
|
+
dismisses.push(dismiss);
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
arm(ge.canvas);
|
|
188
|
+
|
|
189
|
+
if (watching) { watching.abort(); }
|
|
190
|
+
watching = new AbortController();
|
|
191
|
+
['show', 'shown', 'hide', 'hidden'].forEach(function(name) {
|
|
192
|
+
ge.canvas.addEventListener(name + '.bs.' + toggle, function(e) {
|
|
193
|
+
if (!before.has(e.target)) { return; }
|
|
194
|
+
|
|
195
|
+
if (name === 'hidden') {
|
|
196
|
+
phases.delete(e.target);
|
|
197
|
+
} else {
|
|
198
|
+
phases.set(e.target, PHASES[name]);
|
|
199
|
+
}
|
|
200
|
+
}, { signal: watching.signal });
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** Bootstrap's component for this kind, when the page has it on window. */
|
|
205
|
+
function component() {
|
|
206
|
+
var bootstrap = window.bootstrap;
|
|
207
|
+
var name = toggle.charAt(0).toUpperCase() + toggle.slice(1);
|
|
208
|
+
|
|
209
|
+
return bootstrap && bootstrap[name] && bootstrap[name].getInstance ? bootstrap[name] : null;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Ask Bootstrap to close a container: through its instance, or, for a
|
|
214
|
+
* page with no window.bootstrap - an app that imports it - through its
|
|
215
|
+
* own close button, which its data api still listens for.
|
|
216
|
+
*/
|
|
217
|
+
function closer(target) {
|
|
218
|
+
var Component = component();
|
|
219
|
+
var instance = Component ? Component.getInstance(target) : null;
|
|
220
|
+
if (instance) { return function() { instance.hide(); }; }
|
|
221
|
+
|
|
222
|
+
var dismiss = dom.one(target, '[data-bs-dismiss="' + toggle + '"], [data-ge-bs-dismiss="' + toggle + '"]');
|
|
223
|
+
if (!dismiss) { return null; }
|
|
224
|
+
|
|
225
|
+
return function() {
|
|
226
|
+
ge.resumeToggles(dismiss);
|
|
227
|
+
dismiss.click();
|
|
228
|
+
ge.suspendToggles(dismiss);
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* The preview let go: an open container is closed, by Bootstrap so its
|
|
234
|
+
* backdrop and the page's scroll go back too, and each is left as the
|
|
235
|
+
* preview found it once Bootstrap is done with it. One still opening is
|
|
236
|
+
* closed when it has opened, as Bootstrap will not close it before.
|
|
237
|
+
*/
|
|
238
|
+
function endPreview() {
|
|
239
|
+
if (watching) { watching.abort(); }
|
|
240
|
+
watching = null;
|
|
241
|
+
|
|
242
|
+
before.forEach(function(state, target) {
|
|
243
|
+
var phase = phases.get(target);
|
|
244
|
+
var close = phase && phase !== 'closing' ? closer(target) : null;
|
|
245
|
+
var restore = function() {
|
|
246
|
+
pending.delete(target);
|
|
247
|
+
putState(target, state);
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
if (!phase || (phase !== 'closing' && !close)) {
|
|
251
|
+
restore();
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
pending.set(target, state);
|
|
256
|
+
target.addEventListener('hidden.bs.' + toggle, restore, { once: true });
|
|
257
|
+
if (phase === 'opening') {
|
|
258
|
+
target.addEventListener('shown.bs.' + toggle, close, { once: true });
|
|
259
|
+
} else if (phase === 'open') {
|
|
260
|
+
close();
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
before = new Map();
|
|
264
|
+
phases = new Map();
|
|
265
|
+
|
|
266
|
+
dismisses.forEach(function(dismiss) { ge.suspendToggles(dismiss); });
|
|
267
|
+
dismisses = [];
|
|
268
|
+
disarm();
|
|
269
|
+
}
|
|
270
|
+
|
|
95
271
|
return {
|
|
96
272
|
write: write,
|
|
97
273
|
|
|
@@ -109,13 +285,37 @@ export function triggersFor(ge, kind, idAttribute, targetAttribute, toggle) {
|
|
|
109
285
|
dom.delegate(ge.canvas, 'click', '.' + triggerClass + ', [' + targetAttribute + ']', function(e) {
|
|
110
286
|
if (dom.hasClass(ge.canvas, 'ge-editing')) { e.preventDefault(); }
|
|
111
287
|
}, { signal: listening.signal });
|
|
288
|
+
|
|
289
|
+
// A getHtml in the middle of a preview: back to what it was
|
|
290
|
+
if (ge.previewing()) {
|
|
291
|
+
var live = new Map(saved);
|
|
292
|
+
saved = new Map();
|
|
293
|
+
startPreview();
|
|
294
|
+
live.forEach(function(state, target) {
|
|
295
|
+
if (ge.canvas.contains(target)) { putState(target, state); }
|
|
296
|
+
});
|
|
297
|
+
}
|
|
112
298
|
},
|
|
113
299
|
|
|
114
300
|
onDeinit: function() {
|
|
115
301
|
if (listening) { listening.abort(); }
|
|
116
302
|
listening = null;
|
|
117
303
|
|
|
304
|
+
// In the middle of a preview, write reads the markup as the
|
|
305
|
+
// preview found it, not with a container open: onInit puts it back
|
|
306
|
+
if (ge.previewing()) {
|
|
307
|
+
before.forEach(function(state, target) { saved.set(target, stateOf(target)); });
|
|
308
|
+
}
|
|
309
|
+
|
|
118
310
|
write();
|
|
119
311
|
},
|
|
312
|
+
|
|
313
|
+
onPreviewChange: function(previewing) {
|
|
314
|
+
if (previewing) {
|
|
315
|
+
startPreview();
|
|
316
|
+
} else {
|
|
317
|
+
endPreview();
|
|
318
|
+
}
|
|
319
|
+
},
|
|
120
320
|
};
|
|
121
321
|
}
|
package/src/less/grideditor.less
CHANGED
|
@@ -680,13 +680,14 @@ html.ge-sidebar-open {
|
|
|
680
680
|
outline-offset: 1px;
|
|
681
681
|
}
|
|
682
682
|
|
|
683
|
-
/*
|
|
684
|
-
shows
|
|
685
|
-
|
|
683
|
+
/* The target, with active_target: where the toolbar's buttons add and what
|
|
684
|
+
the sidebar shows. A node that also has its panel open shows both: this
|
|
685
|
+
one a little further out */
|
|
686
|
+
.ge-canvas.ge-editing .ge-selected {
|
|
686
687
|
outline: 2px dashed var(--bs-success, #198754);
|
|
687
688
|
outline-offset: -2px;
|
|
688
689
|
}
|
|
689
|
-
.ge-canvas.ge-editing .ge-
|
|
690
|
+
.ge-canvas.ge-editing .ge-selected.ge-settings-target {
|
|
690
691
|
box-shadow: 0 0 0 4px var(--bs-success, #198754);
|
|
691
692
|
}
|
|
692
693
|
|
package/types/grideditor.d.ts
CHANGED
|
@@ -190,7 +190,7 @@ export interface GridEditorOptions {
|
|
|
190
190
|
drawer_overflow?: 'menu' | 'wrap';
|
|
191
191
|
/** The add buttons in categories - rows, content, and a plugin's own - one shown at a time, chosen with tabs. Default false. */
|
|
192
192
|
toolbar_groups?: boolean;
|
|
193
|
-
/** A click
|
|
193
|
+
/** A click on any node with settings - a row, a column, a container, a text - makes it the target: where the toolbar's buttons add, and what the sidebar shows. Default false, and true with settings_panel 'sidebar', which throws if it is given false. */
|
|
194
194
|
active_target?: boolean;
|
|
195
195
|
/** The plugins to use, of any kind; null is every one loaded. */
|
|
196
196
|
plugins?: string[] | null;
|
|
@@ -209,7 +209,7 @@ export interface GridEditorOptions {
|
|
|
209
209
|
elements?: { enabled?: boolean | 'auto'; selector?: string; auto?: boolean; types?: ElementType[] };
|
|
210
210
|
/** The autosave plugin: what is edited, kept in the browser's storage as it changes. */
|
|
211
211
|
autosave?: AutosaveOptions;
|
|
212
|
-
/** The clipboard plugin. `shortcuts`: Ctrl+C and Ctrl+V on the
|
|
212
|
+
/** The clipboard plugin. `shortcuts`: Ctrl+C and Ctrl+V on the active target; default active_target. */
|
|
213
213
|
clipboard?: { shortcuts?: boolean };
|
|
214
214
|
/** The history plugin: undo and redo. */
|
|
215
215
|
history?: HistoryOptions;
|
|
@@ -230,7 +230,7 @@ export interface GridEditorOptions {
|
|
|
230
230
|
locale_strings?: Record<string, string>;
|
|
231
231
|
callbacks?: Partial<GridEditorCallbacks>;
|
|
232
232
|
confirm_delete?: boolean;
|
|
233
|
-
/** Where a node's settings open. 'sidebar' is a panel that stays on the right while editing, showing the
|
|
233
|
+
/** Where a node's settings open. 'sidebar' is a panel that stays on the right while editing, showing the active target's; one editor per page has it. It turns active_target on, and the constructor throws a TypeError if active_target is false. */
|
|
234
234
|
settings_panel?: 'offcanvas' | 'popover' | 'modal' | 'inline' | 'sidebar';
|
|
235
235
|
/** The 'sidebar' panel. */
|
|
236
236
|
sidebar?: SidebarSettings;
|
|
@@ -389,18 +389,17 @@ export interface ViewChangePayload {
|
|
|
389
389
|
to: View;
|
|
390
390
|
}
|
|
391
391
|
|
|
392
|
-
/** The active target changed: the
|
|
392
|
+
/** The active target changed: the node the toolbar adds to and the sidebar shows - any with settings - or null for the canvas. */
|
|
393
393
|
export interface TargetChangePayload {
|
|
394
394
|
canvas: HTMLElement;
|
|
395
395
|
target: HTMLElement | null;
|
|
396
396
|
from: HTMLElement | null;
|
|
397
397
|
}
|
|
398
398
|
|
|
399
|
-
/** The
|
|
400
|
-
export interface
|
|
399
|
+
/** The preview button was pressed (true) or let go (false). */
|
|
400
|
+
export interface PreviewChangePayload {
|
|
401
401
|
canvas: HTMLElement;
|
|
402
|
-
|
|
403
|
-
from: HTMLElement | null;
|
|
402
|
+
previewing: boolean;
|
|
404
403
|
}
|
|
405
404
|
|
|
406
405
|
/** The events, by name, with their payloads. Adding fires a specific name and the generic one. */
|
|
@@ -443,8 +442,8 @@ export interface GridEditorEventMap {
|
|
|
443
442
|
'grideditor:popup-orphan': PopupOrphanPayload;
|
|
444
443
|
'grideditor:offcanvas-orphan': OffcanvasOrphanPayload;
|
|
445
444
|
'grideditor:view-change': ViewChangePayload;
|
|
445
|
+
'grideditor:preview-change': PreviewChangePayload;
|
|
446
446
|
'grideditor:target-change': TargetChangePayload;
|
|
447
|
-
'grideditor:selection-change': SelectionChangePayload;
|
|
448
447
|
'grideditor:after-autosave': AutosavePayload;
|
|
449
448
|
'grideditor:after-restore-draft': RestoreDraftPayload;
|
|
450
449
|
'grideditor:autosave-error': AutosaveErrorPayload;
|
|
@@ -555,14 +554,10 @@ export declare class GridEditor {
|
|
|
555
554
|
/** Take the editor off: the markup stays, everything else goes. */
|
|
556
555
|
destroy(): this;
|
|
557
556
|
changeView(view: View): this;
|
|
558
|
-
/** The
|
|
557
|
+
/** The node the toolbar adds to, and the sidebar shows, or null: any node with settings, a row, a column, a container, a text. Null without active_target, which settings_panel 'sidebar' turns on. */
|
|
559
558
|
getActiveTarget(): HTMLElement | null;
|
|
560
|
-
/** Make a
|
|
559
|
+
/** Make a node with settings, or the first a selector matches, the one the toolbar adds to; null for none. */
|
|
561
560
|
setActiveTarget(target: HTMLElement | string | null): this;
|
|
562
|
-
/** The node whose settings the sidebar shows, or null. Null unless settings_panel is 'sidebar'. */
|
|
563
|
-
getSelected(): HTMLElement | null;
|
|
564
|
-
/** Select a node with settings, or the first a selector matches, or null for none. Does nothing unless settings_panel is 'sidebar'. */
|
|
565
|
-
setSelected(node: HTMLElement | string | null): this;
|
|
566
561
|
getView(): View;
|
|
567
562
|
setLocale(code: string): this;
|
|
568
563
|
createRow(layout?: RowLayout, options?: Placement): HTMLElement | null;
|