@themarioga/grid-editor 9.2.6 → 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 +57 -0
- package/README.md +109 -5
- package/dist/grideditor.bundle.min.js +2 -2
- package/dist/grideditor.css +329 -0
- package/dist/grideditor.d.ts +125 -0
- package/dist/grideditor.esm.js +27 -5
- package/dist/grideditor.js +27 -5
- package/dist/grideditor.min.css +1 -1
- package/dist/grideditor.min.css.map +1 -1
- package/dist/grideditor.min.js +1 -1
- package/dist/grideditor.min.js.map +3 -3
- package/dist/locales/grideditor.es.esm.js +125 -0
- package/dist/locales/grideditor.es.js +125 -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 +2188 -0
- package/dist/plugins/grideditor.navbar.js +2189 -0
- package/dist/plugins/grideditor.navbar.min.js +1 -0
- package/dist/plugins/grideditor.navbar.min.js.map +7 -0
- package/dist/plugins/grideditor.sidenav.esm.js +2082 -0
- package/dist/plugins/grideditor.sidenav.js +2083 -0
- package/dist/plugins/grideditor.sidenav.min.js +1 -0
- package/dist/plugins/grideditor.sidenav.min.js.map +7 -0
- package/docs/events.md +5 -1
- package/docs/locale-keys.md +126 -1
- package/docs/plugins.md +24 -4
- package/example/containers.html +93 -2
- package/example/index.html +1 -1
- package/example/playground.html +3 -0
- package/package.json +1 -1
- package/src/js/grideditor.js +36 -4
- package/src/js/locales/grideditor.es.js +125 -0
- package/src/js/nav/browse.js +51 -0
- package/src/js/nav/canvas.js +170 -0
- package/src/js/nav/convert.js +179 -0
- package/src/js/nav/drawers.js +290 -0
- package/src/js/nav/dropdown.js +253 -0
- package/src/js/nav/feature.js +113 -0
- package/src/js/nav/locale.js +128 -0
- package/src/js/nav/markup.js +121 -0
- package/src/js/nav/panels.js +454 -0
- package/src/js/nav/pieces.js +253 -0
- package/src/js/plugins/grideditor.dropdown.js +335 -0
- package/src/js/plugins/grideditor.navbar.js +454 -0
- package/src/js/plugins/grideditor.sidenav.js +349 -0
- package/src/less/grideditor.less +231 -0
- package/types/grideditor.d.ts +125 -0
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The feature plugin the navbar and the sidenav share: what the editor
|
|
3
|
+
* asks of a plugin that makes up kinds of its own. It is registered by the
|
|
4
|
+
* first of the two plugins the page loads, and does not depend on the other.
|
|
5
|
+
*/
|
|
6
|
+
import { GridEditor } from '../grideditor.js';
|
|
7
|
+
import * as dom from '../dom.js';
|
|
8
|
+
import * as pieces from './pieces.js';
|
|
9
|
+
import { createPanels, SECTION_KEYS } from './panels.js';
|
|
10
|
+
import { loadedFor, guardLinks } from './canvas.js';
|
|
11
|
+
|
|
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
|
+
|
|
16
|
+
return dom.is(node, selector) || !!dom.one(node, selector);
|
|
17
|
+
}
|
|
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
|
+
|
|
22
|
+
export function registerNav() {
|
|
23
|
+
if (GridEditor.features.nav) { return; }
|
|
24
|
+
|
|
25
|
+
var factory = function(ge) {
|
|
26
|
+
var loaded = loadedFor(ge);
|
|
27
|
+
var panels = createPanels(ge, loaded);
|
|
28
|
+
var guard = guardLinks(ge, loaded);
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
kindOf: function(node) { return pieces.kindOf(node, loaded); },
|
|
32
|
+
|
|
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,
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* A zone takes rows and nothing else, and no navbar or sidenav
|
|
38
|
+
* at any depth: not in it, not in a column of it, and not in a
|
|
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.
|
|
42
|
+
*/
|
|
43
|
+
accepts: function(region, node) {
|
|
44
|
+
if (pieces.isZone(region) && !dom.is(node, '.row')) { return false; }
|
|
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
|
+
}
|
|
51
|
+
|
|
52
|
+
return true;
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
panelSection: function(node, kind) { return panels.pieceSection(node, kind); },
|
|
56
|
+
|
|
57
|
+
kindLabel: function(kind) {
|
|
58
|
+
return SECTION_KEYS[kind] ? ge.t(SECTION_KEYS[kind].labelKey) : null;
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
// What moves: the lists, texts and zones of an area, the links and
|
|
62
|
+
// dropdowns of a list, and the items of a menu, each among its own
|
|
63
|
+
onSortable: function(sortable) {
|
|
64
|
+
var holders = [];
|
|
65
|
+
var lists = [];
|
|
66
|
+
var menus = [];
|
|
67
|
+
|
|
68
|
+
dom.all(ge.canvas, '[data-ge-container]').forEach(function(container) {
|
|
69
|
+
if (!loaded(pieces.typeOf(container))) { return; }
|
|
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
|
+
|
|
80
|
+
var holder = pieces.holderOf(container);
|
|
81
|
+
if (holder) { holders.push(holder); }
|
|
82
|
+
|
|
83
|
+
pieces.piecesOf(container, loaded).forEach(function(each) {
|
|
84
|
+
if (each.kind === 'nav-list') { lists.push(each.node); }
|
|
85
|
+
if (each.kind === 'nav-dropdown') { menus.push(pieces.menuOf(each.node)); }
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
sortable(holders, { draggable: '.ge-nav-list, .ge-nav-text, .ge-nav-zone', group: 'nav-block' });
|
|
90
|
+
sortable(lists, { draggable: '.ge-nav-link, .ge-nav-dropdown', group: 'nav-item' });
|
|
91
|
+
sortable(menus.filter(Boolean), { draggable: '.ge-nav-menu-item', group: 'nav-menu-item' });
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
onInit: function() { guard.start(); },
|
|
95
|
+
|
|
96
|
+
onDeinit: function() {
|
|
97
|
+
guard.stop();
|
|
98
|
+
panels.onDeinit();
|
|
99
|
+
},
|
|
100
|
+
|
|
101
|
+
// Nothing of the feature's is in the markup
|
|
102
|
+
cleanMarkup: function() {},
|
|
103
|
+
|
|
104
|
+
onRefresh: function(scope) { panels.onRefresh(scope); },
|
|
105
|
+
|
|
106
|
+
onDestroy: function() { panels.onDestroy(); },
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
// The pieces are markup of the plugins' own, whatever `plugins` names
|
|
111
|
+
factory.always = true;
|
|
112
|
+
GridEditor.features.nav = factory;
|
|
113
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The texts the navbar and sidenav plugins share, in English. Each plugin
|
|
3
|
+
* puts them in the editor's locale itself, and adds its own toolbar label.
|
|
4
|
+
*/
|
|
5
|
+
export var EN = {
|
|
6
|
+
'container.navbar_brand': 'Brand',
|
|
7
|
+
'container.sidenav_brand': 'Brand',
|
|
8
|
+
'container.nav_link': 'Link',
|
|
9
|
+
'container.nav_dropdown': 'Dropdown',
|
|
10
|
+
'container.nav_submenu': 'Submenu',
|
|
11
|
+
'container.nav_menu_link': 'Action',
|
|
12
|
+
'container.nav_menu_header': 'Header',
|
|
13
|
+
'container.nav_text': 'Text',
|
|
14
|
+
'container.navbar_toggle': 'Toggle navigation',
|
|
15
|
+
'container.navbar_offcanvas_title': 'Menu',
|
|
16
|
+
'container.sidenav_trigger': 'Menu',
|
|
17
|
+
'tool.add_nav_piece': 'Add…',
|
|
18
|
+
'tool.add_nav_link': 'Add link or dropdown',
|
|
19
|
+
'tool.add_nav_menu_item': 'Add item',
|
|
20
|
+
'tool.fold_nav_menu': 'Fold this menu while editing',
|
|
21
|
+
'confirm.delete_nav_piece': 'Delete this and everything in it?',
|
|
22
|
+
'container.navbar_section': 'Navbar',
|
|
23
|
+
'container.sidenav_section': 'Sidebar',
|
|
24
|
+
'container.nav_brand_show': 'Brand',
|
|
25
|
+
'container.nav_brand_image': 'Image',
|
|
26
|
+
'container.nav_brand_alt': 'Alt text',
|
|
27
|
+
'container.nav_brand_height': 'Height (px)',
|
|
28
|
+
'container.navbar_expand': 'Expand',
|
|
29
|
+
'container.navbar_expand_never': 'Never',
|
|
30
|
+
'container.navbar_expand_always': 'Always',
|
|
31
|
+
'container.navbar_expand_from': 'From {breakpoint}',
|
|
32
|
+
'container.navbar_collapse': 'Collapse',
|
|
33
|
+
'container.navbar_collapse_collapse': 'Collapse',
|
|
34
|
+
'container.navbar_collapse_offcanvas': 'Offcanvas',
|
|
35
|
+
'container.navbar_collapse_none': 'Not collapsed',
|
|
36
|
+
'container.navbar_offcanvas_placement': 'Side',
|
|
37
|
+
'container.nav_start': 'Start',
|
|
38
|
+
'container.nav_end': 'End',
|
|
39
|
+
'container.nav_bg': 'Background',
|
|
40
|
+
'container.nav_bg_none': 'None',
|
|
41
|
+
'container.nav_bg_body_tertiary': 'Light grey',
|
|
42
|
+
'container.nav_bg_body': 'Page',
|
|
43
|
+
'container.nav_bg_primary': 'Primary',
|
|
44
|
+
'container.nav_bg_secondary': 'Secondary',
|
|
45
|
+
'container.nav_bg_success': 'Success',
|
|
46
|
+
'container.nav_bg_danger': 'Danger',
|
|
47
|
+
'container.nav_bg_warning': 'Warning',
|
|
48
|
+
'container.nav_bg_info': 'Info',
|
|
49
|
+
'container.nav_bg_light': 'Light',
|
|
50
|
+
'container.nav_bg_dark': 'Dark',
|
|
51
|
+
'container.nav_theme': 'Theme',
|
|
52
|
+
'container.nav_theme_auto': 'Auto',
|
|
53
|
+
'container.nav_theme_light': 'Light',
|
|
54
|
+
'container.nav_theme_dark': 'Dark',
|
|
55
|
+
'container.navbar_position': 'Position',
|
|
56
|
+
'container.navbar_position_none': 'In the flow',
|
|
57
|
+
'container.navbar_position_fixed_top': 'Fixed top',
|
|
58
|
+
'container.navbar_position_fixed_bottom': 'Fixed bottom',
|
|
59
|
+
'container.navbar_position_sticky_top': 'Sticky top',
|
|
60
|
+
'container.navbar_position_sticky_bottom': 'Sticky bottom',
|
|
61
|
+
'container.navbar_width': 'Inner width',
|
|
62
|
+
'container.navbar_width_fluid': 'Full',
|
|
63
|
+
'container.navbar_width_fixed': 'Fixed',
|
|
64
|
+
'container.navbar_width_from': 'Full up to {breakpoint}',
|
|
65
|
+
'container.sidenav_width': 'Width',
|
|
66
|
+
'container.sidenav_style': 'Link style',
|
|
67
|
+
'container.sidenav_style_pills': 'Pills',
|
|
68
|
+
'container.sidenav_style_plain': 'Plain',
|
|
69
|
+
'container.sidenav_full_height': 'Full height',
|
|
70
|
+
'container.sidenav_responsive': 'Responsive',
|
|
71
|
+
'container.sidenav_responsive_never': 'Always visible',
|
|
72
|
+
'container.sidenav_responsive_from': 'Offcanvas below {breakpoint}',
|
|
73
|
+
'container.sidenav_offcanvas_title': 'Menu',
|
|
74
|
+
'container.nav_close': 'Close',
|
|
75
|
+
'container.nav_list_section': 'List',
|
|
76
|
+
'container.nav_link_section': 'Link',
|
|
77
|
+
'container.nav_dropdown_section': 'Dropdown',
|
|
78
|
+
'container.nav_menu_item_section': 'Item',
|
|
79
|
+
'container.nav_text_section': 'Text',
|
|
80
|
+
'container.nav_zone_section': 'Free zone',
|
|
81
|
+
'container.nav_brand_section': 'Brand',
|
|
82
|
+
'container.nav_align': 'Alignment',
|
|
83
|
+
'container.nav_align_after': 'After the previous',
|
|
84
|
+
'container.nav_align_end': 'At the end',
|
|
85
|
+
'container.nav_align_center': 'Centered',
|
|
86
|
+
'container.nav_scroll': 'Scroll',
|
|
87
|
+
'container.nav_scroll_height': 'Height',
|
|
88
|
+
'container.nav_bottom': 'At the bottom',
|
|
89
|
+
'container.nav_href': 'URL',
|
|
90
|
+
'container.nav_active': 'Active',
|
|
91
|
+
'container.nav_disabled': 'Disabled',
|
|
92
|
+
'container.nav_new_tab': 'New tab',
|
|
93
|
+
'container.nav_menu_end': 'Menu on the right',
|
|
94
|
+
'container.nav_submenu_type': 'Type',
|
|
95
|
+
'container.nav_submenu_type_collapse': 'Collapsible',
|
|
96
|
+
'container.nav_submenu_type_dropdown': 'Dropdown',
|
|
97
|
+
'container.nav_submenu_open': 'Open on load',
|
|
98
|
+
'container.nav_menu_divider': 'Divider',
|
|
99
|
+
'container.nav_zone': 'Free zone',
|
|
100
|
+
'tool.add_nav_list': 'Add list',
|
|
101
|
+
'tool.add_nav_text': 'Add text',
|
|
102
|
+
'tool.add_nav_zone': 'Add free zone',
|
|
103
|
+
'tool.unfold_nav_menu': 'Unfold this menu',
|
|
104
|
+
'container.nav_browse': 'Browse…',
|
|
105
|
+
'tool.delete_nav_piece': 'Delete',
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/** The backgrounds a navbar and a sidenav offer, and the text each is called. */
|
|
109
|
+
export var BACKGROUND_CHOICES = [
|
|
110
|
+
{ value: 'body-tertiary', labelKey: 'container.nav_bg_body_tertiary' },
|
|
111
|
+
{ value: 'body', labelKey: 'container.nav_bg_body' },
|
|
112
|
+
{ value: 'primary', labelKey: 'container.nav_bg_primary' },
|
|
113
|
+
{ value: 'secondary', labelKey: 'container.nav_bg_secondary' },
|
|
114
|
+
{ value: 'success', labelKey: 'container.nav_bg_success' },
|
|
115
|
+
{ value: 'danger', labelKey: 'container.nav_bg_danger' },
|
|
116
|
+
{ value: 'warning', labelKey: 'container.nav_bg_warning' },
|
|
117
|
+
{ value: 'info', labelKey: 'container.nav_bg_info' },
|
|
118
|
+
{ value: 'light', labelKey: 'container.nav_bg_light' },
|
|
119
|
+
{ value: 'dark', labelKey: 'container.nav_bg_dark' },
|
|
120
|
+
];
|
|
121
|
+
|
|
122
|
+
/** The positions a navbar takes, and the text each is called. */
|
|
123
|
+
export var POSITION_CHOICES = [
|
|
124
|
+
{ value: 'fixed-top', labelKey: 'container.navbar_position_fixed_top' },
|
|
125
|
+
{ value: 'fixed-bottom', labelKey: 'container.navbar_position_fixed_bottom' },
|
|
126
|
+
{ value: 'sticky-top', labelKey: 'container.navbar_position_sticky_top' },
|
|
127
|
+
{ value: 'sticky-bottom', labelKey: 'container.navbar_position_sticky_bottom' },
|
|
128
|
+
];
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The markup of the pieces a navbar and a sidenav are made of. Every text
|
|
3
|
+
* goes in as text, never as html.
|
|
4
|
+
*/
|
|
5
|
+
import * as dom from '../dom.js';
|
|
6
|
+
|
|
7
|
+
/** The classes an item of a menu has, by what it is: in a dropdown's menu, and in a collapsible submenu. */
|
|
8
|
+
export var MENU_CLASSES = {
|
|
9
|
+
link: 'dropdown-item',
|
|
10
|
+
divider: 'dropdown-divider',
|
|
11
|
+
header: 'dropdown-header',
|
|
12
|
+
text: 'dropdown-item-text',
|
|
13
|
+
};
|
|
14
|
+
export var SUBMENU_CLASSES = {
|
|
15
|
+
link: 'nav-link',
|
|
16
|
+
divider: 'my-1',
|
|
17
|
+
header: 'small text-body-secondary px-3 pt-2 mb-1',
|
|
18
|
+
text: 'd-block small px-3 py-1',
|
|
19
|
+
};
|
|
20
|
+
export var ITEM_TAGS = { link: 'a', divider: 'hr', header: 'h6', text: 'span' };
|
|
21
|
+
|
|
22
|
+
/** An item of a menu: `context` is 'menu' for a dropdown's and 'submenu' for a collapsible one's. */
|
|
23
|
+
export function menuItem(ge, type, context) {
|
|
24
|
+
var classes = context === 'submenu' ? SUBMENU_CLASSES : MENU_CLASSES;
|
|
25
|
+
var item = dom.element('li', type === 'link' && context === 'submenu' ? { 'class': 'nav-item' } : {});
|
|
26
|
+
var inner = dom.element(ITEM_TAGS[type], { 'class': classes[type] });
|
|
27
|
+
|
|
28
|
+
if (type === 'link') {
|
|
29
|
+
inner.setAttribute('href', '#');
|
|
30
|
+
inner.textContent = ge.t('container.nav_menu_link');
|
|
31
|
+
} else if (type === 'header') {
|
|
32
|
+
inner.textContent = ge.t('container.nav_menu_header');
|
|
33
|
+
} else if (type === 'text') {
|
|
34
|
+
inner.textContent = ge.t('container.nav_text');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
item.appendChild(inner);
|
|
38
|
+
|
|
39
|
+
return item;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** A link of a list: `li.nav-item > a.nav-link`. */
|
|
43
|
+
export function link(ge) {
|
|
44
|
+
var item = dom.element('li', { 'class': 'nav-item' });
|
|
45
|
+
|
|
46
|
+
item.appendChild(dom.element('a', { 'class': 'nav-link', href: '#' }, ge.t('container.nav_link')));
|
|
47
|
+
|
|
48
|
+
return item;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** A navbar's dropdown, with two items. */
|
|
52
|
+
export function dropdown(ge) {
|
|
53
|
+
var item = dom.element('li', { 'class': 'nav-item dropdown' });
|
|
54
|
+
|
|
55
|
+
item.appendChild(dom.element('a', {
|
|
56
|
+
'class': 'nav-link dropdown-toggle',
|
|
57
|
+
href: '#',
|
|
58
|
+
role: 'button',
|
|
59
|
+
'data-bs-toggle': 'dropdown',
|
|
60
|
+
'aria-expanded': 'false',
|
|
61
|
+
}, ge.t('container.nav_dropdown')));
|
|
62
|
+
|
|
63
|
+
var menu = item.appendChild(dom.element('ul', { 'class': 'dropdown-menu' }));
|
|
64
|
+
menu.appendChild(menuItem(ge, 'link', 'menu'));
|
|
65
|
+
menu.appendChild(menuItem(ge, 'link', 'menu'));
|
|
66
|
+
|
|
67
|
+
return item;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** A sidenav's collapsible submenu, with two items. */
|
|
71
|
+
export function submenu(ge) {
|
|
72
|
+
var id = ge.containerId('nav');
|
|
73
|
+
var item = dom.element('li', { 'class': 'nav-item', 'data-ge-nav': 'submenu' });
|
|
74
|
+
|
|
75
|
+
item.appendChild(dom.element('a', {
|
|
76
|
+
'class': 'nav-link dropdown-toggle',
|
|
77
|
+
href: '#' + id,
|
|
78
|
+
'data-bs-toggle': 'collapse',
|
|
79
|
+
role: 'button',
|
|
80
|
+
'aria-expanded': 'false',
|
|
81
|
+
'aria-controls': id,
|
|
82
|
+
}, ge.t('container.nav_submenu')));
|
|
83
|
+
|
|
84
|
+
var menu = item.appendChild(dom.element('div', { 'class': 'collapse', id: id }))
|
|
85
|
+
.appendChild(dom.element('ul', { 'class': 'nav flex-column ms-3' }));
|
|
86
|
+
menu.appendChild(menuItem(ge, 'link', 'submenu'));
|
|
87
|
+
menu.appendChild(menuItem(ge, 'link', 'submenu'));
|
|
88
|
+
|
|
89
|
+
return item;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** The class of a list: a navbar's, or a sidenav's with or without pills. */
|
|
93
|
+
export function listClass(type, pills) {
|
|
94
|
+
return type === 'sidenav' ? 'nav' + (pills ? ' nav-pills' : '') + ' flex-column' : 'navbar-nav';
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** A list with `count` links. */
|
|
98
|
+
export function list(ge, type, pills, count) {
|
|
99
|
+
var ul = dom.element('ul', { 'class': listClass(type, pills) });
|
|
100
|
+
|
|
101
|
+
for (var i = 0; i < count; i++) { ul.appendChild(link(ge)); }
|
|
102
|
+
|
|
103
|
+
return ul;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function text(ge, type) {
|
|
107
|
+
var label = ge.t('container.nav_text');
|
|
108
|
+
|
|
109
|
+
return type === 'sidenav'
|
|
110
|
+
? dom.element('div', { 'class': 'px-3 py-2', 'data-ge-nav': 'text' }, label)
|
|
111
|
+
: dom.element('span', { 'class': 'navbar-text' }, label);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** A free zone: a node that holds rows and columns, as a section does. */
|
|
115
|
+
export function zone(ge) {
|
|
116
|
+
var node = dom.element('div', { 'class': 'd-block', 'data-ge-nav': 'zone' });
|
|
117
|
+
|
|
118
|
+
node.appendChild(ge.defaultRegion());
|
|
119
|
+
|
|
120
|
+
return node;
|
|
121
|
+
}
|