@themarioga/grid-editor 9.3.0 → 9.4.0

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 (42) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +45 -4
  3. package/dist/grideditor.bundle.min.js +2 -2
  4. package/dist/grideditor.css +73 -11
  5. package/dist/grideditor.d.ts +37 -0
  6. package/dist/grideditor.esm.js +1 -1
  7. package/dist/grideditor.js +1 -1
  8. package/dist/grideditor.min.css +1 -1
  9. package/dist/grideditor.min.css.map +1 -1
  10. package/dist/grideditor.min.js +1 -1
  11. package/dist/locales/grideditor.es.esm.js +23 -0
  12. package/dist/locales/grideditor.es.js +23 -0
  13. package/dist/locales/grideditor.es.min.js +1 -1
  14. package/dist/locales/grideditor.es.min.js.map +2 -2
  15. package/dist/plugins/grideditor.dropdown.esm.js +2231 -0
  16. package/dist/plugins/grideditor.dropdown.js +2232 -0
  17. package/dist/plugins/grideditor.dropdown.min.js +1 -0
  18. package/dist/plugins/grideditor.dropdown.min.js.map +7 -0
  19. package/dist/plugins/grideditor.navbar.esm.js +199 -95
  20. package/dist/plugins/grideditor.navbar.js +199 -95
  21. package/dist/plugins/grideditor.navbar.min.js +1 -1
  22. package/dist/plugins/grideditor.navbar.min.js.map +4 -4
  23. package/dist/plugins/grideditor.sidenav.esm.js +199 -95
  24. package/dist/plugins/grideditor.sidenav.js +199 -95
  25. package/dist/plugins/grideditor.sidenav.min.js +1 -1
  26. package/dist/plugins/grideditor.sidenav.min.js.map +4 -4
  27. package/docs/events.md +4 -4
  28. package/docs/locale-keys.md +24 -1
  29. package/docs/plugins.md +3 -2
  30. package/example/containers.html +35 -1
  31. package/example/playground.html +1 -0
  32. package/package.json +1 -1
  33. package/src/js/locales/grideditor.es.js +23 -0
  34. package/src/js/nav/convert.js +6 -2
  35. package/src/js/nav/drawers.js +46 -14
  36. package/src/js/nav/dropdown.js +253 -0
  37. package/src/js/nav/feature.js +26 -7
  38. package/src/js/nav/panels.js +65 -54
  39. package/src/js/nav/pieces.js +52 -6
  40. package/src/js/plugins/grideditor.dropdown.js +335 -0
  41. package/src/less/grideditor.less +33 -1
  42. package/types/grideditor.d.ts +37 -0
@@ -119,69 +119,80 @@ function alignOf(node) {
119
119
  return dom.hasClass(node, 'ms-auto') ? 'end' : dom.hasClass(node, 'mx-auto') ? 'center' : 'after';
120
120
  }
121
121
 
122
- /** The panels of the pieces of a navbar and a sidenav, for one editor. */
123
- export function createPanels(ge, loaded) {
124
- var kept = sectionsOf();
125
- var context = { destroyed: false };
122
+ function settingsOf(ge, container) {
123
+ return ge.settings[pieces.typeOf(container)] || {};
124
+ }
126
125
 
127
- function settingsOf(container) {
128
- return ge.settings[pieces.typeOf(container)] || {};
129
- }
126
+ /**
127
+ * A URL field, with the host's file browser beside it when it gave one. `context`
128
+ * says the editor is gone, and `kept` is the list of sections to fill again.
129
+ */
130
+ export function urlFieldFor(ge, context, kept, container, node, property, name, label, read, write, browseNode) {
131
+ var field = textControl(write);
132
+ var holder = dom.element('div', { 'class': 'input-group input-group-sm' });
130
133
 
131
- /** A URL field, with the host's file browser beside it when it gave one. */
132
- function urlField(container, node, property, name, label, read, write, browseNode) {
133
- var field = textControl(write);
134
- var holder = dom.element('div', { 'class': 'input-group input-group-sm' });
134
+ holder.appendChild(field.control);
135
135
 
136
- holder.appendChild(field.control);
136
+ var button = browseButton(ge, context, settingsOf(ge, container).browse, browseNode || node, property, read, function(url) {
137
+ write(url);
138
+ kept.render();
139
+ });
140
+ if (button) { holder.appendChild(button); }
137
141
 
138
- var button = browseButton(ge, context, settingsOf(container).browse, browseNode || node, property, read, function(url) {
139
- write(url);
140
- kept.render();
141
- });
142
- if (button) { holder.appendChild(button); }
142
+ return {
143
+ row: fieldRow(name, label, holder, field.id),
144
+ render: function() { field.control.value = read(); },
145
+ };
146
+ }
143
147
 
144
- return {
145
- row: fieldRow(name, label, holder, field.id),
146
- render: function() { field.control.value = read(); },
147
- };
148
- }
148
+ export function linkFieldsFor(ge, context, kept, container, node, anchor, fields) {
149
+ fields.push(urlFieldFor(ge, context, kept, container, node, 'href', 'href', ge.t('container.nav_href'),
150
+ function() { return anchor.getAttribute('href') || ''; },
151
+ function(value) { anchor.setAttribute('href', value); }, anchor));
149
152
 
150
- function linkFields(container, node, anchor, fields) {
151
- fields.push(urlField(container, node, 'href', 'href', ge.t('container.nav_href'),
152
- function() { return anchor.getAttribute('href') || ''; },
153
- function(value) { anchor.setAttribute('href', value); }, anchor));
153
+ var active = checkControl(ge.t('container.nav_active'), function(on) {
154
+ setActive(container, anchor, on);
155
+ kept.render();
156
+ });
157
+ var disabled = checkControl(ge.t('container.nav_disabled'), function(on) {
158
+ dom.toggleClass(anchor, 'disabled', on);
159
+ if (on) {
160
+ anchor.setAttribute('aria-disabled', 'true');
161
+ } else {
162
+ anchor.removeAttribute('aria-disabled');
163
+ dom.dropEmptyClass(anchor);
164
+ }
165
+ });
166
+ var tab = checkControl(ge.t('container.nav_new_tab'), function(on) {
167
+ if (on) {
168
+ anchor.setAttribute('target', '_blank');
169
+ anchor.setAttribute('rel', 'noopener');
170
+ } else {
171
+ anchor.removeAttribute('target');
172
+ anchor.removeAttribute('rel');
173
+ }
174
+ });
154
175
 
155
- var active = checkControl(ge.t('container.nav_active'), function(on) {
156
- setActive(container, anchor, on);
157
- kept.render();
158
- });
159
- var disabled = checkControl(ge.t('container.nav_disabled'), function(on) {
160
- dom.toggleClass(anchor, 'disabled', on);
161
- if (on) {
162
- anchor.setAttribute('aria-disabled', 'true');
163
- } else {
164
- anchor.removeAttribute('aria-disabled');
165
- dom.dropEmptyClass(anchor);
166
- }
167
- });
168
- var tab = checkControl(ge.t('container.nav_new_tab'), function(on) {
169
- if (on) {
170
- anchor.setAttribute('target', '_blank');
171
- anchor.setAttribute('rel', 'noopener');
172
- } else {
173
- anchor.removeAttribute('target');
174
- anchor.removeAttribute('rel');
175
- }
176
- });
176
+ active.box.setAttribute('data-ge-nav-option', 'active');
177
+ disabled.box.setAttribute('data-ge-nav-option', 'disabled');
178
+ tab.box.setAttribute('data-ge-nav-option', 'new_tab');
177
179
 
178
- active.box.setAttribute('data-ge-nav-option', 'active');
179
- disabled.box.setAttribute('data-ge-nav-option', 'disabled');
180
- tab.box.setAttribute('data-ge-nav-option', 'new_tab');
180
+ fields.push({ row: active.box, render: function() { active.input.checked = dom.hasClass(anchor, 'active'); } });
181
+ fields.push({ row: disabled.box, render: function() { disabled.input.checked = dom.hasClass(anchor, 'disabled'); } });
182
+ fields.push({ row: tab.box, render: function() { tab.input.checked = anchor.getAttribute('target') === '_blank'; } });
183
+ }
184
+
185
+ /** The panels of the pieces of a navbar and a sidenav, for one editor. */
186
+ export function createPanels(ge, loaded) {
187
+ var kept = sectionsOf();
188
+ var context = { destroyed: false };
181
189
 
182
- fields.push({ row: active.box, render: function() { active.input.checked = dom.hasClass(anchor, 'active'); } });
183
- fields.push({ row: disabled.box, render: function() { disabled.input.checked = dom.hasClass(anchor, 'disabled'); } });
184
- fields.push({ row: tab.box, render: function() { tab.input.checked = anchor.getAttribute('target') === '_blank'; } });
190
+ function urlField(container, node, property, name, label, read, write, browseNode) {
191
+ return urlFieldFor(ge, context, kept, container, node, property, name, label, read, write, browseNode);
192
+ }
193
+
194
+ function linkFields(container, node, anchor, fields) {
195
+ linkFieldsFor(ge, context, kept, container, node, anchor, fields);
185
196
  }
186
197
 
187
198
  function dropdownFields(container, node, fields) {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * What a navbar or a sidenav is made of, read from its markup.
2
+ * What a navbar, a sidenav or a dropdown is made of, read from its markup.
3
3
  *
4
4
  * Nothing here keeps state, and nothing needs the editor: the build puts a
5
5
  * copy of src/js/nav/ in each plugin that imports it, so what the two
@@ -7,7 +7,14 @@
7
7
  */
8
8
  import * as dom from '../dom.js';
9
9
 
10
- export var TYPES = ['navbar', 'sidenav'];
10
+ /** The containers that hold lists, texts and free zones, and so may not hold one another. */
11
+ export var NAV_TYPES = ['navbar', 'sidenav'];
12
+
13
+ /** Every container whose pieces these modules know. */
14
+ export var TYPES = NAV_TYPES.concat(['dropdown']);
15
+
16
+ /** What a dropdown's button or buttons are in: a plain group, or one of the four directions. */
17
+ var DROPDOWN_WRAPS = '.dropdown, .dropup, .dropend, .dropstart, .btn-group';
11
18
 
12
19
  var WRAPS = '.container, .container-fluid, .container-sm, .container-md, .container-lg, .container-xl, .container-xxl';
13
20
 
@@ -71,9 +78,31 @@ export function triggerOf(container) {
71
78
  return dom.child(container, 'button');
72
79
  }
73
80
 
74
- /** Where the pieces of a container are: the area of a navbar, the panel of a sidenav. */
81
+ /** What holds a dropdown's button or buttons and its menu. */
82
+ export function dropdownOf(container) {
83
+ return dom.children(container).filter(function(node) { return dom.is(node, DROPDOWN_WRAPS); })[0] || null;
84
+ }
85
+
86
+ /**
87
+ * Whether a node is the menu of a dropdown that holds rows and columns, not
88
+ * a list of items.
89
+ */
90
+ export function isContentMenu(node) {
91
+ return dom.is(node, 'div.dropdown-menu');
92
+ }
93
+
94
+ /** The menu of a dropdown container, whichever it holds, or null. */
95
+ export function dropdownMenuOf(container) {
96
+ return dom.all(container, '.dropdown-menu').filter(function(node) { return isOwn(container, node); })[0] || null;
97
+ }
98
+
99
+ /** Where the pieces of a container are: the area of a navbar, the panel of a sidenav, the wrapper of a dropdown. */
75
100
  export function holderOf(container) {
76
- return typeOf(container) === 'sidenav' ? panelOf(container) : areaOf(container);
101
+ var type = typeOf(container);
102
+
103
+ if (type === 'dropdown') { return dropdownOf(container); }
104
+
105
+ return type === 'sidenav' ? panelOf(container) : areaOf(container);
77
106
  }
78
107
 
79
108
  /**
@@ -123,6 +152,11 @@ export function kindOf(node, loaded) {
123
152
  var parent = node.parentElement;
124
153
  var holder = holderOf(container);
125
154
 
155
+ // The only pieces of a dropdown are the items of its menu
156
+ if (type === 'dropdown') {
157
+ return dom.is(node, 'li') && dom.is(parent, 'ul.dropdown-menu') ? 'nav-menu-item' : null;
158
+ }
159
+
126
160
  if (parent === holder || (type === 'navbar' && parent === wrapOf(container) && dom.is(node, '.navbar-brand'))) {
127
161
  if (isZone(node)) { return 'nav-zone'; }
128
162
 
@@ -176,11 +210,23 @@ export function piecesOf(container, loaded) {
176
210
  return found;
177
211
  }
178
212
 
179
- /** Whether a node is the container's own: not in a free zone of it, and not in another container. */
213
+ /**
214
+ * Whether a node is the container's own: not in a free zone of it, not in
215
+ * another container, and not in the free content of a dropdown's menu, which
216
+ * is the page's.
217
+ */
180
218
  export function isOwn(container, node) {
181
219
  var scope = node.parentElement ? node.parentElement.closest('[data-ge-container], [data-ge-nav="zone"]') : null;
182
220
 
183
- return scope === container;
221
+ if (scope !== container) { return false; }
222
+
223
+ if (typeOf(container) === 'dropdown') {
224
+ var content = node.parentElement.closest('div.dropdown-menu');
225
+
226
+ return !content || !container.contains(content);
227
+ }
228
+
229
+ return true;
184
230
  }
185
231
 
186
232
  /** The nodes of a container's own that Bootstrap's data api acts on. */
@@ -0,0 +1,335 @@
1
+ /**
2
+ * Dropdowns for grid-editor: a button that opens a menu, on its own.
3
+ *
4
+ * A container plugin: load this file after the editor and the toolbar offers
5
+ * a dropdown. Its menu is a list of items - links, dividers, headers and
6
+ * texts, as in the navbar plugin's dropdowns - or free content: rows and
7
+ * columns. The button can be split, open in any direction, take the menu to
8
+ * the right and have a Bootstrap style and size. What it can ask the editor
9
+ * for is the handle its factory is called with, described in docs/plugins.md.
10
+ *
11
+ * <script src="dist/grideditor.min.js"></script>
12
+ * <script src="dist/plugins/grideditor.dropdown.min.js"></script>
13
+ *
14
+ * It is edited as the navbar plugin's dropdowns are: its items have a drawer
15
+ * each, the text of the buttons is renamed where it stands, and its options
16
+ * are in the settings panel. It shares its code with the navbar and sidenav
17
+ * plugins, which are of the same version.
18
+ *
19
+ * new GridEditor('#myGrid', { dropdown: { style: 'primary', size: 'sm' } });
20
+ * ge.createContainer('dropdown', { label: 'Actions', menu: 'content', split: true });
21
+ */
22
+ import { GridEditor } from '../grideditor.js';
23
+ import * as dom from '../dom.js';
24
+ import { EN } from '../nav/locale.js';
25
+ import * as pieces from '../nav/pieces.js';
26
+ import * as dropdown from '../nav/dropdown.js';
27
+ import { registerNav } from '../nav/feature.js';
28
+ import { containerBase } from '../nav/canvas.js';
29
+ import { fieldRow, selectControl, checkControl, sectionsOf, urlFieldFor } from '../nav/panels.js';
30
+
31
+ Object.assign(GridEditor.locales.en, EN, {
32
+ 'container.add_dropdown': 'Dropdown',
33
+ 'container.dropdown_label': 'Dropdown',
34
+ 'container.dropdown_toggle': 'Toggle Dropdown',
35
+ 'container.dropdown_section': 'Dropdown',
36
+ 'container.dropdown_menu': 'Menu',
37
+ 'container.dropdown_menu_items': 'Items',
38
+ 'container.dropdown_menu_content': 'Free content',
39
+ 'container.dropdown_style': 'Style',
40
+ 'container.dropdown_outline': 'Outline',
41
+ 'container.dropdown_size': 'Size',
42
+ 'container.dropdown_size_sm': 'Small',
43
+ 'container.dropdown_size_default': 'Normal',
44
+ 'container.dropdown_size_lg': 'Large',
45
+ 'container.dropdown_direction': 'Direction',
46
+ 'container.dropdown_down': 'Down',
47
+ 'container.dropdown_up': 'Up',
48
+ 'container.dropdown_end': 'Right',
49
+ 'container.dropdown_start': 'Left',
50
+ 'container.dropdown_menu_end': 'Menu on the right',
51
+ 'container.dropdown_split': 'Split button',
52
+ 'container.dropdown_split_href': 'Main button link',
53
+ 'container.dropdown_split_new_tab': 'Open in a new tab',
54
+ 'confirm.dropdown_change_menu': 'Change the menu? What it has now is removed.',
55
+ });
56
+
57
+ registerNav();
58
+
59
+ /** What a dropdown made new has when neither the call nor the setting says. */
60
+ var DEFAULTS = {
61
+ menu: 'items',
62
+ style: 'secondary',
63
+ outline: false,
64
+ size: null,
65
+ direction: 'down',
66
+ menu_end: false,
67
+ split: false,
68
+ };
69
+
70
+ var VALUES = {
71
+ menu: dropdown.MENUS,
72
+ style: dropdown.STYLES,
73
+ size: dropdown.SIZES,
74
+ direction: dropdown.DIRECTIONS,
75
+ };
76
+ var BOOLEANS = ['outline', 'menu_end', 'split'];
77
+
78
+ /** The text each style is called: the backgrounds' have the same names. */
79
+ var STYLE_LABELS = {
80
+ primary: 'container.nav_bg_primary',
81
+ secondary: 'container.nav_bg_secondary',
82
+ success: 'container.nav_bg_success',
83
+ danger: 'container.nav_bg_danger',
84
+ warning: 'container.nav_bg_warning',
85
+ info: 'container.nav_bg_info',
86
+ light: 'container.nav_bg_light',
87
+ dark: 'container.nav_bg_dark',
88
+ link: 'container.nav_link',
89
+ };
90
+
91
+ var DIRECTION_CHOICES = [
92
+ { value: 'down', labelKey: 'container.dropdown_down' },
93
+ { value: 'up', labelKey: 'container.dropdown_up' },
94
+ { value: 'end', labelKey: 'container.dropdown_end' },
95
+ { value: 'start', labelKey: 'container.dropdown_start' },
96
+ ];
97
+
98
+ GridEditor.containers.dropdown = function(ge) {
99
+ var base = containerBase(ge, 'dropdown');
100
+ var baseMark = base.mark;
101
+ var context = { destroyed: false };
102
+ var sections = sectionsOf();
103
+
104
+ function warnInvalid(key, value, taken, fallback) {
105
+ ge.warn('dropdown: ' + JSON.stringify(value) + ' is not a ' + key + ', which takes ' + JSON.stringify(taken) +
106
+ ': ' + JSON.stringify(fallback) + ' is used');
107
+ }
108
+
109
+ /**
110
+ * A value for a new dropdown: the option, or the dropdown setting, or the
111
+ * default. One the option does not take is warned about and the default
112
+ * used.
113
+ */
114
+ function chosen(options, key) {
115
+ var setting = ge.settings.dropdown || {};
116
+ var value = options[key] !== undefined ? options[key] : setting[key];
117
+
118
+ if (value === undefined) { return DEFAULTS[key]; }
119
+
120
+ var isBoolean = BOOLEANS.indexOf(key) !== -1;
121
+
122
+ if (isBoolean ? typeof value === 'boolean' : VALUES[key].indexOf(value) !== -1) { return value; }
123
+
124
+ warnInvalid(key, value, isBoolean ? [true, false] : VALUES[key], DEFAULTS[key]);
125
+ return DEFAULTS[key];
126
+ }
127
+
128
+ function labelOf(options) {
129
+ var setting = ge.settings.dropdown || {};
130
+ var value = options.label !== undefined ? options.label : setting.label;
131
+ var fallback = ge.t('container.dropdown_label');
132
+
133
+ if (value === undefined) { return fallback; }
134
+ if (typeof value === 'string' && value.trim() !== '') { return value; }
135
+
136
+ warnInvalid('label', value, 'a text', fallback);
137
+ return fallback;
138
+ }
139
+
140
+ /** The tool that adds an item has nothing to add to a menu of free content. */
141
+ function syncTools(container) {
142
+ var tool = dom.one(container, ':scope > .ge-container-drawer .ge-nav-add');
143
+ var menu = pieces.dropdownMenuOf(container);
144
+
145
+ if (tool) { tool.style.display = menu && pieces.isContentMenu(menu) ? 'none' : ''; }
146
+ }
147
+
148
+ /**
149
+ * The wrapper of the buttons, or the kind of menu, made over: the editor's
150
+ * furniture comes off first, so the labels and toggles are plain while the
151
+ * markup is rebuilt, and goes on again after.
152
+ */
153
+ function rebuild(container, change) {
154
+ base.unmark(container);
155
+
156
+ var menu = dropdown.arrange(ge, container, change);
157
+
158
+ baseMark(container);
159
+ syncTools(container);
160
+
161
+ if (change.menu === 'content' && menu) {
162
+ ge.place(ge.defaultRegion(), 'row', { appendTo: menu, source: 'tool' });
163
+ }
164
+
165
+ sections.render();
166
+ }
167
+
168
+ function changeMenu(container, to) {
169
+ ge.confirm(ge.t('confirm.dropdown_change_menu'), { danger: true }, function(confirmed) {
170
+ if (confirmed === true) {
171
+ rebuild(container, { menu: to });
172
+ } else {
173
+ sections.render();
174
+ }
175
+ });
176
+ }
177
+
178
+ /** The Dropdown section of a dropdown's settings panel. */
179
+ function createSection(container) {
180
+ var body = dom.element('div', { 'class': 'ge-nav-options' });
181
+ var fields = {};
182
+ var optional = [];
183
+
184
+ function select(name, label, choices, onChange) {
185
+ var field = selectControl(choices, onChange);
186
+
187
+ fields[name] = field.control;
188
+ body.appendChild(fieldRow(name, label, field.control, field.id));
189
+ }
190
+
191
+ function check(name, label, onChange) {
192
+ var field = checkControl(label, onChange);
193
+
194
+ field.box.setAttribute('data-ge-nav-option', name);
195
+ fields[name] = field.input;
196
+ body.appendChild(field.box);
197
+
198
+ return field;
199
+ }
200
+
201
+ function write(change) {
202
+ var values = dropdown.read(container);
203
+ var style = change.style !== undefined ? change.style : values.style;
204
+ var outline = change.outline !== undefined ? change.outline : values.outline;
205
+
206
+ if (change.style !== undefined || (change.outline !== undefined && style !== null)) {
207
+ dropdown.setStyle(container, style, outline);
208
+ }
209
+ if (change.size !== undefined) { dropdown.setSize(container, change.size); }
210
+ if (change.menu_end !== undefined) { dropdown.setMenuEnd(container, change.menu_end); }
211
+
212
+ sections.render();
213
+ }
214
+
215
+ select('menu', ge.t('container.dropdown_menu'), [
216
+ { value: 'items', label: ge.t('container.dropdown_menu_items') },
217
+ { value: 'content', label: ge.t('container.dropdown_menu_content') },
218
+ ], function(value) { changeMenu(container, value); });
219
+
220
+ select('style', ge.t('container.dropdown_style'), dropdown.STYLES.map(function(name) {
221
+ return { value: name, label: ge.t(STYLE_LABELS[name]) };
222
+ }), function(value) { write({ style: value }); });
223
+
224
+ check('outline', ge.t('container.dropdown_outline'), function(on) { write({ outline: on }); });
225
+
226
+ select('size', ge.t('container.dropdown_size'), [
227
+ { value: 'sm', label: ge.t('container.dropdown_size_sm') },
228
+ { value: 'normal', label: ge.t('container.dropdown_size_default') },
229
+ { value: 'lg', label: ge.t('container.dropdown_size_lg') },
230
+ ], function(value) { write({ size: value === 'normal' ? null : value }); });
231
+
232
+ select('direction', ge.t('container.dropdown_direction'), DIRECTION_CHOICES.map(function(each) {
233
+ return { value: each.value, label: ge.t(each.labelKey) };
234
+ }), function(value) { rebuild(container, { direction: value }); });
235
+
236
+ check('menu_end', ge.t('container.dropdown_menu_end'), function(on) { write({ menu_end: on }); });
237
+ check('split', ge.t('container.dropdown_split'), function(on) { rebuild(container, { split: on }); });
238
+
239
+ // The action of a split button: where it goes, and whether in a tab of its own
240
+ var href = urlFieldFor(ge, context, sections, container, container, 'href', 'split_href',
241
+ ge.t('container.dropdown_split_href'),
242
+ function() { var main = dropdown.mainOf(container); return main ? main.getAttribute('href') || '' : ''; },
243
+ function(value) { var main = dropdown.mainOf(container); if (main) { main.setAttribute('href', value); } },
244
+ function() { return dropdown.mainOf(container) || container; });
245
+
246
+ body.appendChild(href.row);
247
+ optional.push(href.row);
248
+
249
+ var tab = check('split_new_tab', ge.t('container.dropdown_split_new_tab'), function(on) {
250
+ var main = dropdown.mainOf(container);
251
+ if (!main) { return; }
252
+
253
+ if (on) {
254
+ main.setAttribute('target', '_blank');
255
+ main.setAttribute('rel', 'noopener');
256
+ } else {
257
+ main.removeAttribute('target');
258
+ main.removeAttribute('rel');
259
+ }
260
+ });
261
+
262
+ optional.push(tab.box);
263
+
264
+ function render() {
265
+ var values = dropdown.read(container);
266
+ var main = dropdown.mainOf(container);
267
+
268
+ fields.menu.value = values.menu;
269
+ fields.style.value = values.style === null ? '' : values.style;
270
+ fields.outline.checked = values.outline;
271
+ fields.outline.disabled = values.style === 'link';
272
+ fields.size.value = values.size === undefined ? '' : values.size === null ? 'normal' : values.size;
273
+ fields.direction.value = values.direction;
274
+ fields.menu_end.checked = values.menu_end;
275
+ fields.split.checked = values.split;
276
+ fields.split_new_tab.checked = !!main && main.getAttribute('target') === '_blank';
277
+
278
+ href.render();
279
+ optional.forEach(function(row) { row.hidden = !values.split; });
280
+ }
281
+
282
+ render();
283
+ sections.add({ node: container, element: body, render: render });
284
+
285
+ return body;
286
+ }
287
+
288
+ return Object.assign(base, {
289
+ labelKey: 'container.add_dropdown',
290
+
291
+ // Where rows go when it is the target: the menu, when it holds free content
292
+ regionOf: function(container) {
293
+ var menu = pieces.dropdownMenuOf(container);
294
+
295
+ return menu && pieces.isContentMenu(menu) ? menu : null;
296
+ },
297
+
298
+ create: function(options) {
299
+ options = options || {};
300
+
301
+ return dropdown.create(ge, {
302
+ label: labelOf(options),
303
+ menu: chosen(options, 'menu'),
304
+ style: chosen(options, 'style'),
305
+ outline: chosen(options, 'outline'),
306
+ size: chosen(options, 'size'),
307
+ direction: chosen(options, 'direction'),
308
+ menu_end: chosen(options, 'menu_end'),
309
+ split: chosen(options, 'split'),
310
+ });
311
+ },
312
+
313
+ // What is not a dropdown's own markup - nothing of it is read - is left as it is
314
+ mark: function(container) {
315
+ baseMark(container);
316
+ syncTools(container);
317
+ },
318
+
319
+ panelSection: function(node, kind) {
320
+ if (kind !== 'dropdown' || !pieces.dropdownOf(node)) { return null; }
321
+
322
+ return { labelKey: 'container.dropdown_section', body: createSection(node) };
323
+ },
324
+
325
+ onInit: function() { context.destroyed = false; },
326
+
327
+ onRefresh: function(scope) { sections.render(scope); },
328
+
329
+ // An answer of the host's file browser that comes after is for a canvas that is gone
330
+ onDeinit: function() {
331
+ context.destroyed = true;
332
+ sections.clear();
333
+ },
334
+ });
335
+ };
@@ -1331,7 +1331,8 @@ html.ge-sidebar-open {
1331
1331
  Bootstrap's javascript is involved: what it would open on a click is
1332
1332
  rendered open here. */
1333
1333
  [data-ge-container="navbar"],
1334
- [data-ge-container="sidenav"] {
1334
+ [data-ge-container="sidenav"],
1335
+ [data-ge-container="dropdown"] {
1335
1336
  .ge-nav-link,
1336
1337
  .ge-nav-dropdown,
1337
1338
  .ge-nav-menu-item {
@@ -1389,6 +1390,37 @@ html.ge-sidebar-open {
1389
1390
  }
1390
1391
  }
1391
1392
 
1393
+ /* A dropdown on its own: its menu is open, in its place and below the
1394
+ buttons whichever the direction, since a menu beside them would cover
1395
+ what is next to it. The free content of a menu is a region of rows. */
1396
+ [data-ge-container="dropdown"] {
1397
+ /* The buttons side by side and the menu under both, as wide as they are or as it needs */
1398
+ .btn-group {
1399
+ display: inline-grid;
1400
+ grid-template-columns: repeat(2, auto);
1401
+ justify-content: start;
1402
+ }
1403
+ .btn-group > .dropdown-menu {
1404
+ grid-column: 1 / -1;
1405
+ grid-row: 2;
1406
+ }
1407
+ .dropdown-menu {
1408
+ display: block;
1409
+ position: static;
1410
+ float: none;
1411
+ transform: none;
1412
+ margin: 2px 0 0;
1413
+ }
1414
+ div.dropdown-menu {
1415
+ min-width: 10rem;
1416
+ outline: 1px dashed @containerColor;
1417
+ outline-offset: -2px;
1418
+ }
1419
+ .ge-nav-folded .dropdown-menu {
1420
+ display: none;
1421
+ }
1422
+ }
1423
+
1392
1424
  /* The part of a navbar that folds is shown open, whichever the window.
1393
1425
  Expanded, Bootstrap's own rules, which are !important, win */
1394
1426
  [data-ge-container="navbar"] {
@@ -222,6 +222,40 @@ export interface CreateSidenavOptions extends Placement, SidenavOptions {
222
222
  trigger_label?: string;
223
223
  }
224
224
 
225
+ /** The Bootstrap styles of the button of a dropdown. */
226
+ export type DropdownStyle = 'primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'info' | 'light' | 'dark' | 'link';
227
+
228
+ /**
229
+ * The dropdown plugin's options, the ones a dropdown made new has, as the
230
+ * dropdown setting gives them and createContainer overrides them.
231
+ */
232
+ export interface DropdownOptions {
233
+ /** The text of the button, or of the action of a split one. Default `'Dropdown'`, in the interface's language. */
234
+ label?: string;
235
+ /** What the menu holds: items - links, dividers, headers, texts - or free content, rows and columns. Default `'items'`. */
236
+ menu?: 'items' | 'content';
237
+ /** `btn-*`. Default `'secondary'`. */
238
+ style?: DropdownStyle;
239
+ /** `btn-outline-*`; `link` has none. Default false. */
240
+ outline?: boolean;
241
+ /** `btn-sm` or `btn-lg`; null for neither. Default null. */
242
+ size?: 'sm' | 'lg' | null;
243
+ /** `dropdown`, `dropup`, `dropend` or `dropstart`. Default `'down'`. */
244
+ direction?: 'down' | 'up' | 'end' | 'start';
245
+ /** `dropdown-menu-end`. Default false. */
246
+ menu_end?: boolean;
247
+ /** An action and a caret, as two buttons. Default false. */
248
+ split?: boolean;
249
+ }
250
+
251
+ /** The dropdown setting: the options of the dropdowns made new, and the host's file browser. */
252
+ export interface DropdownSetting extends DropdownOptions {
253
+ browse?: NavBrowse;
254
+ }
255
+
256
+ /** createContainer('dropdown', …) */
257
+ export interface CreateDropdownOptions extends Placement, DropdownOptions {}
258
+
225
259
  /** What a file browser is told about the field it was opened from. */
226
260
  export interface InlineStyleBrowseContext {
227
261
  node: HTMLElement;
@@ -312,6 +346,8 @@ export interface GridEditorOptions {
312
346
  navbar?: NavbarSetting;
313
347
  /** The sidenav plugin: the options of the sidebars made new, and `browse`. */
314
348
  sidenav?: SidenavSetting;
349
+ /** The dropdown plugin: the options of the dropdowns made new, and `browse`. */
350
+ dropdown?: DropdownSetting;
315
351
  elements?: { enabled?: boolean | 'auto'; selector?: string; auto?: boolean; types?: ElementType[] };
316
352
  /** The autosave plugin: what is edited, kept in the browser's storage as it changes. */
317
353
  autosave?: AutosaveOptions;
@@ -682,6 +718,7 @@ export declare class GridEditor {
682
718
  createContainer(type: 'offcanvas', options?: CreateOffcanvasOptions): HTMLElement | null;
683
719
  createContainer(type: 'navbar', options?: CreateNavbarOptions): HTMLElement | null;
684
720
  createContainer(type: 'sidenav', options?: CreateSidenavOptions): HTMLElement | null;
721
+ createContainer(type: 'dropdown', options?: CreateDropdownOptions): HTMLElement | null;
685
722
  createContainer(type: string, options?: Placement & Record<string, unknown>): HTMLElement | null;
686
723
  addTab(container: Target, options?: PaneOptions): HTMLElement | null;
687
724
  addAccordionItem(container: Target, options?: PaneOptions): HTMLElement | null;