@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
|
+
* What a navbar, a sidenav or a dropdown is made of, read from its markup.
|
|
3
|
+
*
|
|
4
|
+
* Nothing here keeps state, and nothing needs the editor: the build puts a
|
|
5
|
+
* copy of src/js/nav/ in each plugin that imports it, so what the two
|
|
6
|
+
* plugins share is only the markup they agree on.
|
|
7
|
+
*/
|
|
8
|
+
import * as dom from '../dom.js';
|
|
9
|
+
|
|
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';
|
|
18
|
+
|
|
19
|
+
var WRAPS = '.container, .container-fluid, .container-sm, .container-md, .container-lg, .container-xl, .container-xxl';
|
|
20
|
+
|
|
21
|
+
/** The kinds of piece, as the events call them. */
|
|
22
|
+
export var KINDS = ['nav-list', 'nav-link', 'nav-dropdown', 'nav-menu-item', 'nav-text', 'nav-zone', 'nav-brand'];
|
|
23
|
+
|
|
24
|
+
export function typeOf(container) {
|
|
25
|
+
return container ? container.getAttribute('data-ge-container') : null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function isZone(node) {
|
|
29
|
+
return dom.is(node, '[data-ge-nav="zone"]');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function isSubmenu(node) {
|
|
33
|
+
return dom.is(node, 'li[data-ge-nav="submenu"]');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The `nav` of a navbar. */
|
|
37
|
+
export function navOf(container) {
|
|
38
|
+
return dom.child(container, 'nav');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** What holds a navbar's brand: the `.container*`, or the `nav` when it has none. */
|
|
42
|
+
export function wrapOf(container) {
|
|
43
|
+
var nav = navOf(container);
|
|
44
|
+
|
|
45
|
+
return nav ? (dom.child(nav, WRAPS) || nav) : null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** The part of a navbar that folds, or the node the pieces are in when nothing folds. */
|
|
49
|
+
export function areaOf(container) {
|
|
50
|
+
var wrap = wrapOf(container);
|
|
51
|
+
if (!wrap) { return null; }
|
|
52
|
+
|
|
53
|
+
var collapse = dom.child(wrap, '.navbar-collapse');
|
|
54
|
+
if (collapse) { return collapse; }
|
|
55
|
+
|
|
56
|
+
var offcanvas = dom.child(wrap, '.offcanvas');
|
|
57
|
+
var body = offcanvas ? dom.child(offcanvas, '.offcanvas-body') : null;
|
|
58
|
+
|
|
59
|
+
return body || wrap;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** The `.offcanvas` a navbar folds into, or null. */
|
|
63
|
+
export function offcanvasOf(container) {
|
|
64
|
+
var wrap = wrapOf(container);
|
|
65
|
+
|
|
66
|
+
return wrap ? dom.child(wrap, '.offcanvas') : null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** The panel of a sidenav: what is not the editor's drawer or the button that opens it. */
|
|
70
|
+
export function panelOf(container) {
|
|
71
|
+
return dom.children(container).filter(function(node) {
|
|
72
|
+
return !dom.hasClass(node, 'ge-tools-drawer') && node.tagName !== 'BUTTON';
|
|
73
|
+
})[0] || null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** The button that opens a responsive sidenav, or null. */
|
|
77
|
+
export function triggerOf(container) {
|
|
78
|
+
return dom.child(container, 'button');
|
|
79
|
+
}
|
|
80
|
+
|
|
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. */
|
|
100
|
+
export function holderOf(container) {
|
|
101
|
+
var type = typeOf(container);
|
|
102
|
+
|
|
103
|
+
if (type === 'dropdown') { return dropdownOf(container); }
|
|
104
|
+
|
|
105
|
+
return type === 'sidenav' ? panelOf(container) : areaOf(container);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* The navbar or sidenav a node is a piece of: the nearest container above
|
|
110
|
+
* it, when that is one of these and a plugin the editor has. A free zone,
|
|
111
|
+
* or another container, is a scope of its own: what is in it is not a piece.
|
|
112
|
+
*/
|
|
113
|
+
export function ownerOf(node, loaded) {
|
|
114
|
+
var holder = node && node.parentElement ? node.parentElement.closest('[data-ge-container], [data-ge-nav="zone"]') : null;
|
|
115
|
+
|
|
116
|
+
if (!holder || isZone(holder)) { return null; }
|
|
117
|
+
|
|
118
|
+
return loaded(typeOf(holder)) ? holder : null;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function isMenu(node) {
|
|
122
|
+
return dom.is(node, '.dropdown-menu');
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** The menu of a dropdown or a submenu: what its items are children of. */
|
|
126
|
+
export function menuOf(dropdown) {
|
|
127
|
+
if (isSubmenu(dropdown)) { return dom.one(dropdown, ':scope > .collapse > ul'); }
|
|
128
|
+
|
|
129
|
+
return dom.child(dropdown, '.dropdown-menu');
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** What an item of a menu is, by what it holds. */
|
|
133
|
+
export function itemType(item) {
|
|
134
|
+
if (dom.child(item, 'hr')) { return 'divider'; }
|
|
135
|
+
if (dom.child(item, 'h6')) { return 'header'; }
|
|
136
|
+
if (dom.child(item, 'a')) { return 'link'; }
|
|
137
|
+
|
|
138
|
+
return 'text';
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** The link of a link, a dropdown's toggle, or a menu item that is a link. */
|
|
142
|
+
export function anchorOf(piece) {
|
|
143
|
+
return dom.child(piece, 'a');
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** What the markup of a node says it is, wherever it is. */
|
|
147
|
+
export function kindOf(node, loaded) {
|
|
148
|
+
var container = ownerOf(node, loaded);
|
|
149
|
+
if (!container) { return null; }
|
|
150
|
+
|
|
151
|
+
var type = typeOf(container);
|
|
152
|
+
var parent = node.parentElement;
|
|
153
|
+
var holder = holderOf(container);
|
|
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
|
+
|
|
160
|
+
if (parent === holder || (type === 'navbar' && parent === wrapOf(container) && dom.is(node, '.navbar-brand'))) {
|
|
161
|
+
if (isZone(node)) { return 'nav-zone'; }
|
|
162
|
+
|
|
163
|
+
if (type === 'navbar') {
|
|
164
|
+
if (dom.is(node, '.navbar-brand')) { return 'nav-brand'; }
|
|
165
|
+
if (dom.is(node, 'ul.navbar-nav')) { return 'nav-list'; }
|
|
166
|
+
if (dom.is(node, '.navbar-text')) { return 'nav-text'; }
|
|
167
|
+
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (dom.is(node, 'a[data-ge-nav="brand"]')) { return 'nav-brand'; }
|
|
172
|
+
if (dom.is(node, 'ul.nav')) { return 'nav-list'; }
|
|
173
|
+
if (dom.is(node, '[data-ge-nav="text"]')) { return 'nav-text'; }
|
|
174
|
+
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (!dom.is(node, 'li') || !parent) { return null; }
|
|
179
|
+
|
|
180
|
+
if (dom.is(parent, 'ul') && parent.parentElement && kindOf(parent, loaded) === 'nav-list') {
|
|
181
|
+
if (dom.is(node, '.nav-item.dropdown') || (type === 'sidenav' && isSubmenu(node))) { return 'nav-dropdown'; }
|
|
182
|
+
if (dom.is(node, '.nav-item') && dom.child(node, 'a.nav-link')) { return 'nav-link'; }
|
|
183
|
+
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (isMenu(parent) && dom.is(parent.parentElement, 'li.nav-item.dropdown') && kindOf(parent.parentElement, loaded) === 'nav-dropdown') {
|
|
188
|
+
return 'nav-menu-item';
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (type === 'sidenav' && dom.is(parent, 'ul') && dom.is(parent.parentElement, '.collapse') &&
|
|
192
|
+
isSubmenu(parent.parentElement.parentElement) && kindOf(parent.parentElement.parentElement, loaded) === 'nav-dropdown') {
|
|
193
|
+
return 'nav-menu-item';
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** Every piece of a container, in document order: { node, kind }. */
|
|
200
|
+
export function piecesOf(container, loaded) {
|
|
201
|
+
var found = [];
|
|
202
|
+
|
|
203
|
+
dom.all(container, '*').forEach(function(node) {
|
|
204
|
+
if (ownerOf(node, loaded) !== container) { return; }
|
|
205
|
+
|
|
206
|
+
var kind = kindOf(node, loaded);
|
|
207
|
+
if (kind) { found.push({ node: node, kind: kind }); }
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
return found;
|
|
211
|
+
}
|
|
212
|
+
|
|
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
|
+
*/
|
|
218
|
+
export function isOwn(container, node) {
|
|
219
|
+
var scope = node.parentElement ? node.parentElement.closest('[data-ge-container], [data-ge-nav="zone"]') : null;
|
|
220
|
+
|
|
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;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** The nodes of a container's own that Bootstrap's data api acts on. */
|
|
233
|
+
export function togglesOf(container) {
|
|
234
|
+
return dom.all(container, '[data-bs-toggle], [data-ge-bs-toggle], [data-bs-dismiss], [data-ge-bs-dismiss]').filter(function(node) {
|
|
235
|
+
return isOwn(container, node);
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** What a piece is called in the default text it gets when its label is emptied. */
|
|
240
|
+
export function defaultLabelKey(node, kind, container) {
|
|
241
|
+
var type = typeOf(container);
|
|
242
|
+
|
|
243
|
+
if (kind === 'nav-link') { return 'container.nav_link'; }
|
|
244
|
+
if (kind === 'nav-dropdown') { return isSubmenu(node) ? 'container.nav_submenu' : 'container.nav_dropdown'; }
|
|
245
|
+
if (kind === 'nav-text') { return 'container.nav_text'; }
|
|
246
|
+
if (kind === 'nav-brand') { return type === 'sidenav' ? 'container.sidenav_brand' : 'container.navbar_brand'; }
|
|
247
|
+
|
|
248
|
+
var itemKind = itemType(node);
|
|
249
|
+
if (itemKind === 'header') { return 'container.nav_menu_header'; }
|
|
250
|
+
if (itemKind === 'text') { return 'container.nav_text'; }
|
|
251
|
+
|
|
252
|
+
return 'container.nav_menu_link';
|
|
253
|
+
}
|
|
@@ -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
|
+
};
|