@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.
- package/CHANGELOG.md +19 -0
- package/README.md +45 -4
- package/dist/grideditor.bundle.min.js +2 -2
- package/dist/grideditor.css +73 -11
- package/dist/grideditor.d.ts +37 -0
- package/dist/grideditor.esm.js +1 -1
- package/dist/grideditor.js +1 -1
- package/dist/grideditor.min.css +1 -1
- package/dist/grideditor.min.css.map +1 -1
- package/dist/grideditor.min.js +1 -1
- package/dist/locales/grideditor.es.esm.js +23 -0
- package/dist/locales/grideditor.es.js +23 -0
- package/dist/locales/grideditor.es.min.js +1 -1
- package/dist/locales/grideditor.es.min.js.map +2 -2
- package/dist/plugins/grideditor.dropdown.esm.js +2231 -0
- package/dist/plugins/grideditor.dropdown.js +2232 -0
- package/dist/plugins/grideditor.dropdown.min.js +1 -0
- package/dist/plugins/grideditor.dropdown.min.js.map +7 -0
- package/dist/plugins/grideditor.navbar.esm.js +199 -95
- package/dist/plugins/grideditor.navbar.js +199 -95
- package/dist/plugins/grideditor.navbar.min.js +1 -1
- package/dist/plugins/grideditor.navbar.min.js.map +4 -4
- package/dist/plugins/grideditor.sidenav.esm.js +199 -95
- package/dist/plugins/grideditor.sidenav.js +199 -95
- package/dist/plugins/grideditor.sidenav.min.js +1 -1
- package/dist/plugins/grideditor.sidenav.min.js.map +4 -4
- package/docs/events.md +4 -4
- package/docs/locale-keys.md +24 -1
- package/docs/plugins.md +3 -2
- package/example/containers.html +35 -1
- package/example/playground.html +1 -0
- package/package.json +1 -1
- package/src/js/locales/grideditor.es.js +23 -0
- package/src/js/nav/convert.js +6 -2
- package/src/js/nav/drawers.js +46 -14
- package/src/js/nav/dropdown.js +253 -0
- package/src/js/nav/feature.js +26 -7
- package/src/js/nav/panels.js +65 -54
- package/src/js/nav/pieces.js +52 -6
- package/src/js/plugins/grideditor.dropdown.js +335 -0
- package/src/less/grideditor.less +33 -1
- package/types/grideditor.d.ts +37 -0
package/docs/events.md
CHANGED
|
@@ -63,9 +63,9 @@ about every insertion can bind `grideditor:before-add` and switch on
|
|
|
63
63
|
| `grideditor:after-add-row` | `grideditor:after-add` | no | after insertion, once the canvas is up to date |
|
|
64
64
|
| `grideditor:before-add-column` | `grideditor:before-add` | yes | before a column is inserted |
|
|
65
65
|
| `grideditor:after-add-column` | `grideditor:after-add` | no | |
|
|
66
|
-
| `grideditor:before-add-container` | `grideditor:before-add` | yes | before a container is inserted; `payload.kind` is `tabs`, `accordion`, `popup`, `offcanvas`, `carousel`, `card`, `navbar` or `
|
|
66
|
+
| `grideditor:before-add-container` | `grideditor:before-add` | yes | before a container is inserted; `payload.kind` is `tabs`, `accordion`, `popup`, `offcanvas`, `carousel`, `card`, `navbar`, `sidenav` or `dropdown` |
|
|
67
67
|
| `grideditor:after-add-container` | `grideditor:after-add` | no | |
|
|
68
|
-
| `grideditor:before-add-nav-list`, `-nav-link`, `-nav-dropdown`, `-nav-menu-item`, `-nav-text`, `-nav-zone` | `grideditor:before-add` | yes | before a piece is added to a navbar or a sidenav: a list, a link, a dropdown, an item of a menu, a text, a free zone |
|
|
68
|
+
| `grideditor:before-add-nav-list`, `-nav-link`, `-nav-dropdown`, `-nav-menu-item`, `-nav-text`, `-nav-zone` | `grideditor:before-add` | yes | before a piece is added to a navbar or a sidenav: a list, a link, a dropdown, an item of a menu, a text, a free zone. The items of a dropdown on its own are `-nav-menu-item` too |
|
|
69
69
|
| `grideditor:after-add-nav-list`, `-nav-link`… | `grideditor:after-add` | no | |
|
|
70
70
|
| `grideditor:before-add-tab` | `grideditor:before-add` | yes | before a tab is added to a tabs container |
|
|
71
71
|
| `grideditor:after-add-tab` | `grideditor:after-add` | no | |
|
|
@@ -117,8 +117,8 @@ The payload
|
|
|
117
117
|
{
|
|
118
118
|
kind: 'row', // row | column | text | plain | element
|
|
119
119
|
// tabs | accordion | popup | offcanvas | carousel | card | tab | accordion-item | carousel-item
|
|
120
|
-
// navbar | sidenav | nav-list | nav-link | nav-dropdown | nav-menu-item | nav-text | nav-zone | nav-brand,
|
|
121
|
-
// with the navbar and
|
|
120
|
+
// navbar | sidenav | dropdown | nav-list | nav-link | nav-dropdown | nav-menu-item | nav-text | nav-zone | nav-brand,
|
|
121
|
+
// with the navbar, sidenav and dropdown plugins
|
|
122
122
|
// section, with the sections plugin
|
|
123
123
|
node: Element, // the node added, deleted, moved or resized
|
|
124
124
|
parent: Element, // where it is going, or where it came from on a delete;
|
package/docs/locale-keys.md
CHANGED
|
@@ -105,7 +105,7 @@ title. `{kind}` is one of the `panel.kind_*` keys, or a container's own label.
|
|
|
105
105
|
container.*
|
|
106
106
|
-----------
|
|
107
107
|
|
|
108
|
-
The containers: tabs, accordions, popups, offcanvases, carousels, cards, navbars and
|
|
108
|
+
The containers: tabs, accordions, popups, offcanvases, carousels, cards, navbars, sidebars and dropdowns, and the panes and pieces inside them.
|
|
109
109
|
|
|
110
110
|
| Key | English | Where |
|
|
111
111
|
| --- | --- | --- |
|
|
@@ -280,6 +280,29 @@ The containers: tabs, accordions, popups, offcanvases, carousels, cards, navbars
|
|
|
280
280
|
| `tool.unfold_nav_menu` | Unfold this menu | Dropdown drawer, the same tool once the menu is folded away |
|
|
281
281
|
| `container.nav_browse` | Browse… | Title of the button that opens the host's file browser |
|
|
282
282
|
| `tool.delete_nav_piece` | Delete | Delete tool of a piece of a navbar or a sidebar |
|
|
283
|
+
| `container.add_dropdown` | Dropdown | Toolbar button that adds a dropdown on its own |
|
|
284
|
+
| `container.dropdown_label` | Dropdown | Text of the button of a new dropdown, and what an emptied one goes back to |
|
|
285
|
+
| `container.dropdown_toggle` | Toggle Dropdown | Hidden text of the caret of a split dropdown, for screen readers, written in the interface's language when the button is made |
|
|
286
|
+
| `container.dropdown_section` | Dropdown | Heading of a dropdown's section of its settings panel |
|
|
287
|
+
| `container.dropdown_menu` | Menu | Its select: what the menu holds |
|
|
288
|
+
| `container.dropdown_menu_items` | Items | Its choice for a menu of links, dividers, headers and texts |
|
|
289
|
+
| `container.dropdown_menu_content` | Free content | Its choice for a menu of rows and columns |
|
|
290
|
+
| `container.dropdown_style` | Style | Its select for the button's Bootstrap style |
|
|
291
|
+
| `container.dropdown_outline` | Outline | Its checkbox for the outline version of the style |
|
|
292
|
+
| `container.dropdown_size` | Size | Its select for the button's size |
|
|
293
|
+
| `container.dropdown_size_sm` | Small | Its choice for `btn-sm` |
|
|
294
|
+
| `container.dropdown_size_default` | Normal | Its choice for no size class |
|
|
295
|
+
| `container.dropdown_size_lg` | Large | Its choice for `btn-lg` |
|
|
296
|
+
| `container.dropdown_direction` | Direction | Its select for the side the menu opens to |
|
|
297
|
+
| `container.dropdown_down` | Down | Its choice for `dropdown` |
|
|
298
|
+
| `container.dropdown_up` | Up | Its choice for `dropup` |
|
|
299
|
+
| `container.dropdown_end` | Right | Its choice for `dropend` |
|
|
300
|
+
| `container.dropdown_start` | Left | Its choice for `dropstart` |
|
|
301
|
+
| `container.dropdown_menu_end` | Menu on the right | Its checkbox for `dropdown-menu-end` |
|
|
302
|
+
| `container.dropdown_split` | Split button | Its checkbox for a button with an action and a caret |
|
|
303
|
+
| `container.dropdown_split_href` | Main button link | Its field for the address of the action of a split button |
|
|
304
|
+
| `container.dropdown_split_new_tab` | Open in a new tab | Its checkbox for the action of a split button |
|
|
305
|
+
| `confirm.dropdown_change_menu` | Change the menu? What it has now is removed. | Asked before a dropdown's menu is changed from items to free content, or back |
|
|
283
306
|
|
|
284
307
|
|
|
285
308
|
section.*
|
package/docs/plugins.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Writing a plugin
|
|
2
2
|
================
|
|
3
3
|
|
|
4
|
-
Tabs, accordions, popups, offcanvases, carousels, cards, navbars, sidebars and the element level controls are not built
|
|
4
|
+
Tabs, accordions, popups, offcanvases, carousels, cards, navbars, sidebars, dropdowns and the element level controls are not built
|
|
5
5
|
into grid-editor: each is a file you load beside it, and loading the file is
|
|
6
6
|
what turns the feature on. `grideditor.card.js` is the shortest of them, and
|
|
7
7
|
the one to read first if you are about to write your own.
|
|
@@ -14,6 +14,7 @@ the one to read first if you are about to write your own.
|
|
|
14
14
|
<script src="dist/plugins/grideditor.card.min.js"></script>
|
|
15
15
|
<script src="dist/plugins/grideditor.navbar.min.js"></script>
|
|
16
16
|
<script src="dist/plugins/grideditor.sidenav.min.js"></script>
|
|
17
|
+
<script src="dist/plugins/grideditor.dropdown.min.js"></script>
|
|
17
18
|
<script src="dist/plugins/grideditor.elements.min.js"></script>
|
|
18
19
|
```
|
|
19
20
|
|
|
@@ -509,7 +510,7 @@ rather than remembering anything about it.
|
|
|
509
510
|
kind the plugin made up with, or null. It is asked where the panel would
|
|
510
511
|
otherwise show the kind as it is - after a container's `labelKey` and its
|
|
511
512
|
panes' `paneLabelKey`, and the core's own kinds - and the first plugin that
|
|
512
|
-
answers wins. The navbar and
|
|
513
|
+
answers wins. The `nav` feature the navbar, sidenav and dropdown plugins share uses it for
|
|
513
514
|
the kinds of their pieces.
|
|
514
515
|
|
|
515
516
|
The core's own lists and the plugins' are taken down together: every list made
|
package/example/containers.html
CHANGED
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
<script src="../dist/plugins/grideditor.carousel.min.js"></script>
|
|
28
28
|
<script src="../dist/plugins/grideditor.navbar.min.js"></script>
|
|
29
29
|
<script src="../dist/plugins/grideditor.sidenav.min.js"></script>
|
|
30
|
+
<script src="../dist/plugins/grideditor.dropdown.min.js"></script>
|
|
30
31
|
|
|
31
32
|
<script>
|
|
32
33
|
document.addEventListener('DOMContentLoaded', function() {
|
|
@@ -126,7 +127,9 @@
|
|
|
126
127
|
between them, and the gear has a Carousel section for
|
|
127
128
|
fade, autoplay and the rest of Bootstrap's options, and a
|
|
128
129
|
slide’s own gear has its interval. The navbar and the
|
|
129
|
-
sidebar after it are edited piece by piece, each with a drawer
|
|
130
|
+
sidebar after it are edited piece by piece, each with a drawer,
|
|
131
|
+
and so are the two dropdowns at the end: one with a menu of
|
|
132
|
+
items, and a split one whose menu holds rows and columns.
|
|
130
133
|
</p>
|
|
131
134
|
<button class="btn btn-sm btn-secondary" id="output" type="button">Show the html this produces</button>
|
|
132
135
|
<button class="btn btn-sm btn-primary" id="authored" type="button">Open that html as a real page</button>
|
|
@@ -427,6 +430,37 @@
|
|
|
427
430
|
</div>
|
|
428
431
|
</div>
|
|
429
432
|
|
|
433
|
+
<div class="row">
|
|
434
|
+
<div class="col-lg-4">
|
|
435
|
+
<div data-ge-container="dropdown">
|
|
436
|
+
<div class="dropdown">
|
|
437
|
+
<button class="btn btn-primary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">Actions</button>
|
|
438
|
+
<ul class="dropdown-menu">
|
|
439
|
+
<li><a class="dropdown-item" href="#">Edit</a></li>
|
|
440
|
+
<li><a class="dropdown-item" href="#">Duplicate</a></li>
|
|
441
|
+
<li><hr class="dropdown-divider"></li>
|
|
442
|
+
<li><h6 class="dropdown-header">Danger</h6></li>
|
|
443
|
+
<li><a class="dropdown-item" href="#">Delete</a></li>
|
|
444
|
+
</ul>
|
|
445
|
+
</div>
|
|
446
|
+
</div>
|
|
447
|
+
</div>
|
|
448
|
+
<div class="col-lg-8">
|
|
449
|
+
<div data-ge-container="dropdown">
|
|
450
|
+
<div class="btn-group">
|
|
451
|
+
<a class="btn btn-outline-success" href="#">Filters</a>
|
|
452
|
+
<button class="btn btn-outline-success dropdown-toggle dropdown-toggle-split" type="button" data-bs-toggle="dropdown" aria-expanded="false"><span class="visually-hidden">Toggle Dropdown</span></button>
|
|
453
|
+
<div class="dropdown-menu p-3">
|
|
454
|
+
<div class="row">
|
|
455
|
+
<div class="col-md-6"><div class="ge-content" data-ge-content-type="tinymce"><p>A menu can hold rows and columns.</p></div></div>
|
|
456
|
+
<div class="col-md-6"><div class="ge-content" data-ge-content-type="tinymce"><p>Each one is an ordinary region.</p></div></div>
|
|
457
|
+
</div>
|
|
458
|
+
</div>
|
|
459
|
+
</div>
|
|
460
|
+
</div>
|
|
461
|
+
</div>
|
|
462
|
+
</div>
|
|
463
|
+
|
|
430
464
|
</div> <!-- /#myGrid -->
|
|
431
465
|
</div> <!-- /.container -->
|
|
432
466
|
|
package/example/playground.html
CHANGED
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
<script src="../dist/plugins/grideditor.card.min.js"></script>
|
|
49
49
|
<script src="../dist/plugins/grideditor.navbar.min.js"></script>
|
|
50
50
|
<script src="../dist/plugins/grideditor.sidenav.min.js"></script>
|
|
51
|
+
<script src="../dist/plugins/grideditor.dropdown.min.js"></script>
|
|
51
52
|
<script src="../dist/plugins/grideditor.order.min.js"></script>
|
|
52
53
|
<script src="../dist/plugins/grideditor.alignment.min.js"></script>
|
|
53
54
|
<script src="../dist/plugins/grideditor.gutters.min.js"></script>
|
package/package.json
CHANGED
|
@@ -234,6 +234,29 @@ GridEditor.locales.es = {
|
|
|
234
234
|
'tool.unfold_nav_menu': 'Desplegar este menú',
|
|
235
235
|
'container.nav_browse': 'Examinar…',
|
|
236
236
|
'tool.delete_nav_piece': 'Borrar',
|
|
237
|
+
'container.add_dropdown': 'Desplegable',
|
|
238
|
+
'container.dropdown_label': 'Desplegable',
|
|
239
|
+
'container.dropdown_toggle': 'Alternar desplegable',
|
|
240
|
+
'container.dropdown_section': 'Desplegable',
|
|
241
|
+
'container.dropdown_menu': 'Menú',
|
|
242
|
+
'container.dropdown_menu_items': 'Ítems',
|
|
243
|
+
'container.dropdown_menu_content': 'Contenido libre',
|
|
244
|
+
'container.dropdown_style': 'Estilo',
|
|
245
|
+
'container.dropdown_outline': 'Contorno',
|
|
246
|
+
'container.dropdown_size': 'Tamaño',
|
|
247
|
+
'container.dropdown_size_sm': 'Pequeño',
|
|
248
|
+
'container.dropdown_size_default': 'Normal',
|
|
249
|
+
'container.dropdown_size_lg': 'Grande',
|
|
250
|
+
'container.dropdown_direction': 'Dirección',
|
|
251
|
+
'container.dropdown_down': 'Abajo',
|
|
252
|
+
'container.dropdown_up': 'Arriba',
|
|
253
|
+
'container.dropdown_end': 'Derecha',
|
|
254
|
+
'container.dropdown_start': 'Izquierda',
|
|
255
|
+
'container.dropdown_menu_end': 'Menú a la derecha',
|
|
256
|
+
'container.dropdown_split': 'Botón dividido',
|
|
257
|
+
'container.dropdown_split_href': 'Enlace del botón principal',
|
|
258
|
+
'container.dropdown_split_new_tab': 'Abrir en pestaña nueva',
|
|
259
|
+
'confirm.dropdown_change_menu': '¿Cambiar el menú? Lo que tiene ahora se quita.',
|
|
237
260
|
'container.add_popup': 'Ventana emergente',
|
|
238
261
|
'container.popup_title': 'Título',
|
|
239
262
|
'container.popup_trigger': 'Abrir',
|
package/src/js/nav/convert.js
CHANGED
|
@@ -16,9 +16,13 @@ export function setItemContext(item, context) {
|
|
|
16
16
|
|
|
17
17
|
if (!inner) { return; }
|
|
18
18
|
|
|
19
|
-
// The kind's own classes first, as they are written when it is made new
|
|
19
|
+
// The kind's own classes first, as they are written when it is made new. Those of the
|
|
20
|
+
// place it is going to are not repeated: an item moved between two menus has them already
|
|
20
21
|
var own = String(from[type]).split(' ');
|
|
21
|
-
var
|
|
22
|
+
var target = String(to[type]).split(' ');
|
|
23
|
+
var rest = Array.prototype.filter.call(inner.classList, function(name) {
|
|
24
|
+
return own.indexOf(name) === -1 && target.indexOf(name) === -1;
|
|
25
|
+
});
|
|
22
26
|
|
|
23
27
|
inner.className = [to[type]].concat(rest).join(' ');
|
|
24
28
|
|
package/src/js/nav/drawers.js
CHANGED
|
@@ -7,6 +7,7 @@ import * as dom from '../dom.js';
|
|
|
7
7
|
import * as pieces from './pieces.js';
|
|
8
8
|
import * as markup from './markup.js';
|
|
9
9
|
import * as convert from './convert.js';
|
|
10
|
+
import * as dropdown from './dropdown.js';
|
|
10
11
|
|
|
11
12
|
var wired = new WeakSet();
|
|
12
13
|
|
|
@@ -100,10 +101,40 @@ function add(ge, node, kind, holder) {
|
|
|
100
101
|
return ge.place(node, kind, { appendTo: holder, source: 'tool' });
|
|
101
102
|
}
|
|
102
103
|
|
|
103
|
-
/**
|
|
104
|
+
/** What a menu takes: a link, a divider, a header and a text, each made for the kind of menu it is in. */
|
|
105
|
+
function itemChoices(ge, holder, context) {
|
|
106
|
+
var addItem = function(itemType) {
|
|
107
|
+
add(ge, markup.menuItem(ge, itemType, context), 'nav-menu-item', holder);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
return [
|
|
111
|
+
choice(ge.t('container.nav_menu_link'), function() { addItem('link'); }),
|
|
112
|
+
choice(ge.t('container.nav_menu_divider'), function() { addItem('divider'); }),
|
|
113
|
+
choice(ge.t('container.nav_menu_header'), function() { addItem('header'); }),
|
|
114
|
+
choice(ge.t('container.nav_text'), function() { addItem('text'); }),
|
|
115
|
+
];
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** The tool of the container's drawer: add a list, a text or a free zone; to a dropdown, an item. */
|
|
104
119
|
export function containerTools(ge, drawer, container) {
|
|
105
120
|
var type = pieces.typeOf(container);
|
|
106
121
|
|
|
122
|
+
if (type === 'dropdown') {
|
|
123
|
+
var addButton = pickerTool(ge, drawer, ge.t('tool.add_nav_menu_item'), function() {
|
|
124
|
+
var menu = pieces.dropdownMenuOf(container);
|
|
125
|
+
|
|
126
|
+
return menu && !pieces.isContentMenu(menu) ? itemChoices(ge, menu, 'menu') : [];
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
// The core marks a container before it makes its drawer, so this is where a menu of free content is first known
|
|
130
|
+
var held = pieces.dropdownMenuOf(container);
|
|
131
|
+
if (held && pieces.isContentMenu(held)) { addButton.style.display = 'none'; }
|
|
132
|
+
|
|
133
|
+
foldTool(ge, drawer, function() { return pieces.dropdownOf(container); });
|
|
134
|
+
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
107
138
|
pickerTool(ge, drawer, ge.t('tool.add_nav_piece'), function() {
|
|
108
139
|
var holder = pieces.holderOf(container);
|
|
109
140
|
|
|
@@ -141,28 +172,21 @@ function addsOf(ge, node, kind, container) {
|
|
|
141
172
|
|
|
142
173
|
if (kind !== 'nav-dropdown') { return null; }
|
|
143
174
|
|
|
144
|
-
var addItem = function(itemType) {
|
|
145
|
-
add(ge, markup.menuItem(ge, itemType, pieces.isSubmenu(node) ? 'submenu' : 'menu'), 'nav-menu-item', pieces.menuOf(node));
|
|
146
|
-
};
|
|
147
|
-
|
|
148
175
|
return {
|
|
149
176
|
title: ge.t('tool.add_nav_menu_item'),
|
|
150
|
-
choices: function() {
|
|
151
|
-
return [
|
|
152
|
-
choice(ge.t('container.nav_menu_link'), function() { addItem('link'); }),
|
|
153
|
-
choice(ge.t('container.nav_menu_divider'), function() { addItem('divider'); }),
|
|
154
|
-
choice(ge.t('container.nav_menu_header'), function() { addItem('header'); }),
|
|
155
|
-
choice(ge.t('container.nav_text'), function() { addItem('text'); }),
|
|
156
|
-
];
|
|
157
|
-
},
|
|
177
|
+
choices: function() { return itemChoices(ge, pieces.menuOf(node), pieces.isSubmenu(node) ? 'submenu' : 'menu'); },
|
|
158
178
|
};
|
|
159
179
|
}
|
|
160
180
|
|
|
181
|
+
/** Fold a menu away while editing: `node` is the node that folds, or a function that says which when asked. */
|
|
161
182
|
function foldTool(ge, drawer, node) {
|
|
162
183
|
var tool = ge.createTool(drawer, ge.t('tool.fold_nav_menu'), 'ge-nav-fold', 'bi bi-chevron-bar-contract', function(e) {
|
|
163
184
|
if (e) { e.preventDefault(); }
|
|
164
185
|
|
|
165
|
-
var
|
|
186
|
+
var target = typeof node === 'function' ? node() : node;
|
|
187
|
+
if (!target) { return; }
|
|
188
|
+
|
|
189
|
+
var folded = dom.toggleClass(target, 'ge-nav-folded').classList.contains('ge-nav-folded');
|
|
166
190
|
tool.setAttribute('title', folded ? ge.t('tool.unfold_nav_menu') : ge.t('tool.fold_nav_menu'));
|
|
167
191
|
});
|
|
168
192
|
|
|
@@ -213,6 +237,14 @@ export function markContainer(ge, container, loaded) {
|
|
|
213
237
|
if (kind === 'nav-dropdown') { foldTool(ge, drawer, node); }
|
|
214
238
|
});
|
|
215
239
|
|
|
240
|
+
if (type === 'dropdown') {
|
|
241
|
+
var button = dropdown.mainOf(container) || dropdown.toggleOf(container);
|
|
242
|
+
|
|
243
|
+
if (button) { editInPlace(ge, button, function() { return ge.t('container.dropdown_label'); }); }
|
|
244
|
+
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
|
|
216
248
|
// The titles of the offcanvas a container has, and the sidenav's button
|
|
217
249
|
var offcanvas = type === 'navbar' ? pieces.offcanvasOf(container) : pieces.panelOf(container);
|
|
218
250
|
var title = offcanvas ? dom.one(offcanvas, ':scope > .offcanvas-header .offcanvas-title') : null;
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The markup of a dropdown that stands on its own, and what the settings
|
|
3
|
+
* panel does to it. Nothing here keeps state: a dropdown is read from its
|
|
4
|
+
* markup, and written back to it.
|
|
5
|
+
*
|
|
6
|
+
* Bootstrap shapes a button group by its direction, so the wrapper of the
|
|
7
|
+
* buttons is rebuilt when the direction or the split changes, around the
|
|
8
|
+
* same nodes: the menu, with what is in it, and the buttons.
|
|
9
|
+
*/
|
|
10
|
+
import * as dom from '../dom.js';
|
|
11
|
+
import * as pieces from './pieces.js';
|
|
12
|
+
import * as markup from './markup.js';
|
|
13
|
+
|
|
14
|
+
export var STYLES = ['primary', 'secondary', 'success', 'danger', 'warning', 'info', 'light', 'dark', 'link'];
|
|
15
|
+
export var DIRECTIONS = ['down', 'up', 'end', 'start'];
|
|
16
|
+
export var SIZES = [null, 'sm', 'lg'];
|
|
17
|
+
export var MENUS = ['items', 'content'];
|
|
18
|
+
|
|
19
|
+
var DIRECTION_CLASS = { down: 'dropdown', up: 'dropup', end: 'dropend', start: 'dropstart' };
|
|
20
|
+
var WRAP_CLASSES = ['dropdown', 'dropup', 'dropend', 'dropstart', 'btn-group'];
|
|
21
|
+
var STYLE_CLASS = new RegExp('^btn-(outline-)?(' + STYLES.join('|') + ')$');
|
|
22
|
+
|
|
23
|
+
// Bootstrap has no sizes beyond these two, but a page may have its own
|
|
24
|
+
var SIZE_CLASS = /^btn-(sm|lg|xs|xl|xxl)$/;
|
|
25
|
+
|
|
26
|
+
function ownAll(container, selector) {
|
|
27
|
+
return dom.all(container, selector).filter(function(node) { return pieces.isOwn(container, node); });
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** The button that opens the menu: the whole button, or the caret of a split one. */
|
|
31
|
+
export function toggleOf(container) {
|
|
32
|
+
return ownAll(container, '.dropdown-toggle')[0] || null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** The action of a split button, or null for one that is not split. */
|
|
36
|
+
export function mainOf(container) {
|
|
37
|
+
return ownAll(container, '.btn').filter(function(node) { return !dom.hasClass(node, 'dropdown-toggle'); })[0] || null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function classOf(node, pattern) {
|
|
41
|
+
return Array.prototype.filter.call(node.classList, function(name) { return pattern.test(name); });
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** The text of a button, not what is only there for a screen reader. */
|
|
45
|
+
function textOf(node) {
|
|
46
|
+
return Array.prototype.filter.call(node.childNodes, function(each) {
|
|
47
|
+
return each.nodeType === 3 || !dom.hasClass(each, 'visually-hidden');
|
|
48
|
+
}).map(function(each) { return each.textContent; }).join('').trim();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* What a dropdown is, from its markup. `style` is null for a button that
|
|
53
|
+
* has none of Bootstrap's, and `size` is undefined for one with a size that
|
|
54
|
+
* is not in the list: the panel shows neither, and neither is touched
|
|
55
|
+
* until another is chosen.
|
|
56
|
+
*/
|
|
57
|
+
export function read(container) {
|
|
58
|
+
var menu = pieces.dropdownMenuOf(container);
|
|
59
|
+
var toggle = toggleOf(container);
|
|
60
|
+
var main = mainOf(container);
|
|
61
|
+
var split = !!(toggle && dom.hasClass(toggle, 'dropdown-toggle-split'));
|
|
62
|
+
var look = (split && main) || toggle;
|
|
63
|
+
var direction = ownAll(container, '.dropup, .dropend, .dropstart')[0];
|
|
64
|
+
var style = look ? classOf(look, STYLE_CLASS)[0] : null;
|
|
65
|
+
var foreignSize = look ? classOf(look, SIZE_CLASS).filter(function(name) { return name !== 'btn-sm' && name !== 'btn-lg'; }).length : 0;
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
label: look ? textOf(look) : '',
|
|
69
|
+
menu: menu && pieces.isContentMenu(menu) ? 'content' : 'items',
|
|
70
|
+
style: style ? style.replace(/^btn-(outline-)?/, '') : null,
|
|
71
|
+
outline: !!style && /^btn-outline-/.test(style),
|
|
72
|
+
size: !look ? null : foreignSize ? undefined : dom.hasClass(look, 'btn-sm') ? 'sm' : dom.hasClass(look, 'btn-lg') ? 'lg' : null,
|
|
73
|
+
direction: !direction ? 'down' : dom.hasClass(direction, 'dropup') ? 'up' : dom.hasClass(direction, 'dropend') ? 'end' : 'start',
|
|
74
|
+
menu_end: !!menu && dom.hasClass(menu, 'dropdown-menu-end'),
|
|
75
|
+
split: split,
|
|
76
|
+
href: split && main ? main.getAttribute('href') || '' : null,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function removeMatching(node, pattern) {
|
|
81
|
+
classOf(node, pattern).forEach(function(name) { node.classList.remove(name); });
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Bootstrap's style on the buttons. A style Bootstrap has no outline for, `link`, is not outlined. */
|
|
85
|
+
export function setStyle(container, style, outline) {
|
|
86
|
+
[toggleOf(container), mainOf(container)].filter(Boolean).forEach(function(button) {
|
|
87
|
+
removeMatching(button, STYLE_CLASS);
|
|
88
|
+
dom.addClass(button, 'btn-' + (outline && style !== 'link' ? 'outline-' : '') + style);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function setSize(container, size) {
|
|
93
|
+
[toggleOf(container), mainOf(container)].filter(Boolean).forEach(function(button) {
|
|
94
|
+
removeMatching(button, SIZE_CLASS);
|
|
95
|
+
if (size) { dom.addClass(button, 'btn-' + size); }
|
|
96
|
+
dom.dropEmptyClass(button);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function setMenuEnd(container, on) {
|
|
101
|
+
var menu = pieces.dropdownMenuOf(container);
|
|
102
|
+
if (!menu) { return; }
|
|
103
|
+
|
|
104
|
+
dom.toggleClass(menu, 'dropdown-menu-end', on);
|
|
105
|
+
dom.dropEmptyClass(menu);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function itemsMenu(ge) {
|
|
109
|
+
var menu = dom.element('ul', { 'class': 'dropdown-menu' });
|
|
110
|
+
|
|
111
|
+
menu.appendChild(markup.menuItem(ge, 'link', 'menu'));
|
|
112
|
+
menu.appendChild(markup.menuItem(ge, 'link', 'menu'));
|
|
113
|
+
|
|
114
|
+
return menu;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** The padding is for the rows: they have negative margins of their own. */
|
|
118
|
+
function contentMenu(ge, withRow) {
|
|
119
|
+
var menu = dom.element('div', { 'class': 'dropdown-menu p-3' });
|
|
120
|
+
|
|
121
|
+
if (withRow) { menu.appendChild(ge.defaultRegion()); }
|
|
122
|
+
|
|
123
|
+
return menu;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** What the old menu had that the plugin does not manage, on the new one. */
|
|
127
|
+
function carryOver(from, to, managed) {
|
|
128
|
+
Array.prototype.forEach.call(from.attributes, function(attribute) {
|
|
129
|
+
if (attribute.name !== 'class' && !to.hasAttribute(attribute.name)) { to.setAttribute(attribute.name, attribute.value); }
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
Array.prototype.filter.call(from.classList, function(name) {
|
|
133
|
+
return managed.indexOf(name) === -1 && !/^ge-/.test(name);
|
|
134
|
+
}).forEach(function(name) { dom.addClass(to, name); });
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** A menu of the other kind, in place of this one: what it holds is dropped. */
|
|
138
|
+
function swapMenu(ge, menu, to) {
|
|
139
|
+
var made = to === 'content' ? contentMenu(ge, false) : itemsMenu(ge);
|
|
140
|
+
|
|
141
|
+
carryOver(menu, made, ['dropdown-menu', 'p-3', 'show']);
|
|
142
|
+
menu.parentNode.replaceChild(made, menu);
|
|
143
|
+
|
|
144
|
+
return made;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function newToggle() {
|
|
148
|
+
return dom.element('button', {
|
|
149
|
+
'class': 'btn dropdown-toggle',
|
|
150
|
+
type: 'button',
|
|
151
|
+
'data-bs-toggle': 'dropdown',
|
|
152
|
+
'aria-expanded': 'false',
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** The buttons, and the wrapper Bootstrap's direction and split call for. */
|
|
157
|
+
function compose(ge, container, parts, want, was, wrapper) {
|
|
158
|
+
var toggle = parts.toggle;
|
|
159
|
+
var main = parts.main;
|
|
160
|
+
|
|
161
|
+
if (want.split) {
|
|
162
|
+
if (!main) {
|
|
163
|
+
main = dom.element('a', { 'class': 'btn', href: '#' });
|
|
164
|
+
Array.prototype.filter.call(toggle.classList, function(name) {
|
|
165
|
+
return name !== 'dropdown-toggle' && name !== 'dropdown-toggle-split';
|
|
166
|
+
}).forEach(function(name) { dom.addClass(main, name); });
|
|
167
|
+
main.textContent = was.label;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
dom.addClass(toggle, 'dropdown-toggle-split');
|
|
171
|
+
|
|
172
|
+
if (!dom.child(toggle, '.visually-hidden')) {
|
|
173
|
+
toggle.textContent = '';
|
|
174
|
+
toggle.appendChild(dom.element('span', { 'class': 'visually-hidden' }, ge.t('container.dropdown_toggle')));
|
|
175
|
+
}
|
|
176
|
+
} else {
|
|
177
|
+
dom.removeClass(toggle, 'dropdown-toggle-split');
|
|
178
|
+
dom.dropEmptyClass(toggle);
|
|
179
|
+
|
|
180
|
+
if (was.split) { toggle.textContent = was.label; }
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
var made;
|
|
184
|
+
|
|
185
|
+
if (!want.split) {
|
|
186
|
+
made = dom.element('div', { 'class': DIRECTION_CLASS[want.direction] });
|
|
187
|
+
made.appendChild(toggle);
|
|
188
|
+
made.appendChild(parts.menu);
|
|
189
|
+
} else if (want.direction === 'start') {
|
|
190
|
+
// Bootstrap puts the caret of a split button before its action on the left
|
|
191
|
+
var inner = dom.element('div', { 'class': 'btn-group dropstart' });
|
|
192
|
+
|
|
193
|
+
inner.appendChild(toggle);
|
|
194
|
+
inner.appendChild(parts.menu);
|
|
195
|
+
made = dom.element('div', { 'class': 'btn-group' });
|
|
196
|
+
made.appendChild(inner);
|
|
197
|
+
made.appendChild(main);
|
|
198
|
+
} else {
|
|
199
|
+
made = dom.element('div', { 'class': 'btn-group' + (want.direction === 'down' ? '' : ' ' + DIRECTION_CLASS[want.direction]) });
|
|
200
|
+
made.appendChild(main);
|
|
201
|
+
made.appendChild(toggle);
|
|
202
|
+
made.appendChild(parts.menu);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (wrapper) {
|
|
206
|
+
carryOver(wrapper, made, WRAP_CLASSES);
|
|
207
|
+
container.replaceChild(made, wrapper);
|
|
208
|
+
} else {
|
|
209
|
+
container.appendChild(made);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* A dropdown made new, from options that are valid: `label`, `menu`,
|
|
215
|
+
* `style`, `outline`, `size`, `direction`, `menu_end` and `split`.
|
|
216
|
+
*/
|
|
217
|
+
export function create(ge, options) {
|
|
218
|
+
var container = dom.element('div', { 'data-ge-container': 'dropdown' });
|
|
219
|
+
var toggle = newToggle();
|
|
220
|
+
var menu = options.menu === 'content' ? contentMenu(ge, true) : itemsMenu(ge);
|
|
221
|
+
|
|
222
|
+
toggle.textContent = options.label;
|
|
223
|
+
container.appendChild(toggle);
|
|
224
|
+
container.appendChild(menu);
|
|
225
|
+
|
|
226
|
+
// The buttons and the menu, in their wrapper
|
|
227
|
+
compose(ge, container, { toggle: toggle, main: null, menu: menu },
|
|
228
|
+
{ split: options.split, direction: options.direction }, { split: false, label: options.label }, null);
|
|
229
|
+
|
|
230
|
+
setStyle(container, options.style, options.outline);
|
|
231
|
+
setSize(container, options.size);
|
|
232
|
+
setMenuEnd(container, options.menu_end);
|
|
233
|
+
|
|
234
|
+
return container;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Change what the wrapper depends on - `direction`, `split` - or the kind of
|
|
239
|
+
* menu, keeping the rest. Gives the menu: a new one when its kind changed.
|
|
240
|
+
*/
|
|
241
|
+
export function arrange(ge, container, change) {
|
|
242
|
+
var now = read(container);
|
|
243
|
+
var want = Object.assign({}, now, change);
|
|
244
|
+
var parts = { toggle: toggleOf(container), main: mainOf(container), menu: pieces.dropdownMenuOf(container) };
|
|
245
|
+
|
|
246
|
+
if (!parts.toggle || !parts.menu) { return parts.menu; }
|
|
247
|
+
|
|
248
|
+
if (want.menu !== now.menu) { parts.menu = swapMenu(ge, parts.menu, want.menu); }
|
|
249
|
+
|
|
250
|
+
compose(ge, container, parts, want, now, pieces.dropdownOf(container));
|
|
251
|
+
|
|
252
|
+
return parts.menu;
|
|
253
|
+
}
|
package/src/js/nav/feature.js
CHANGED
|
@@ -9,13 +9,16 @@ import * as pieces from './pieces.js';
|
|
|
9
9
|
import { createPanels, SECTION_KEYS } from './panels.js';
|
|
10
10
|
import { loadedFor, guardLinks } from './canvas.js';
|
|
11
11
|
|
|
12
|
-
/** Whether a node is, or has in it, a
|
|
13
|
-
function
|
|
14
|
-
var selector =
|
|
12
|
+
/** Whether a node is, or has in it, a container of one of these types. */
|
|
13
|
+
function holds(node, types) {
|
|
14
|
+
var selector = types.map(function(type) { return '[data-ge-container="' + type + '"]'; }).join(', ');
|
|
15
15
|
|
|
16
16
|
return dom.is(node, selector) || !!dom.one(node, selector);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
/** The free content of a dropdown's menu: a region of rows. */
|
|
20
|
+
var CONTENT_MENU = '[data-ge-container="dropdown"] div.dropdown-menu';
|
|
21
|
+
|
|
19
22
|
export function registerNav() {
|
|
20
23
|
if (GridEditor.features.nav) { return; }
|
|
21
24
|
|
|
@@ -27,17 +30,24 @@ export function registerNav() {
|
|
|
27
30
|
return {
|
|
28
31
|
kindOf: function(node) { return pieces.kindOf(node, loaded); },
|
|
29
32
|
|
|
30
|
-
// A free zone
|
|
31
|
-
regions: '[data-ge-nav="zone"]',
|
|
33
|
+
// A free zone, and the free content of a dropdown's menu, are lists rows go in, as a section is
|
|
34
|
+
regions: '[data-ge-nav="zone"], ' + CONTENT_MENU,
|
|
32
35
|
|
|
33
36
|
/**
|
|
34
37
|
* A zone takes rows and nothing else, and no navbar or sidenav
|
|
35
38
|
* at any depth: not in it, not in a column of it, and not in a
|
|
36
|
-
* row that holds one.
|
|
39
|
+
* row that holds one. The free content of a dropdown's menu takes
|
|
40
|
+
* rows too, and none that holds a dropdown as well: Bootstrap has
|
|
41
|
+
* no menus inside menus.
|
|
37
42
|
*/
|
|
38
43
|
accepts: function(region, node) {
|
|
39
44
|
if (pieces.isZone(region) && !dom.is(node, '.row')) { return false; }
|
|
40
|
-
if (region.closest && region.closest('[data-ge-nav="zone"]') &&
|
|
45
|
+
if (region.closest && region.closest('[data-ge-nav="zone"]') && holds(node, pieces.NAV_TYPES)) { return false; }
|
|
46
|
+
|
|
47
|
+
if (loaded('dropdown') && region.closest && region.closest(CONTENT_MENU)) {
|
|
48
|
+
if (dom.is(region, CONTENT_MENU) && !dom.is(node, '.row')) { return false; }
|
|
49
|
+
if (holds(node, pieces.TYPES)) { return false; }
|
|
50
|
+
}
|
|
41
51
|
|
|
42
52
|
return true;
|
|
43
53
|
},
|
|
@@ -58,6 +68,15 @@ export function registerNav() {
|
|
|
58
68
|
dom.all(ge.canvas, '[data-ge-container]').forEach(function(container) {
|
|
59
69
|
if (!loaded(pieces.typeOf(container))) { return; }
|
|
60
70
|
|
|
71
|
+
// A dropdown on its own has only the items of its menu to move
|
|
72
|
+
if (pieces.typeOf(container) === 'dropdown') {
|
|
73
|
+
var own = pieces.dropdownMenuOf(container);
|
|
74
|
+
|
|
75
|
+
if (own && !pieces.isContentMenu(own)) { menus.push(own); }
|
|
76
|
+
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
61
80
|
var holder = pieces.holderOf(container);
|
|
62
81
|
if (holder) { holders.push(holder); }
|
|
63
82
|
|