@themarioga/grid-editor 9.2.6 → 9.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/README.md +68 -5
  3. package/dist/grideditor.bundle.min.js +2 -2
  4. package/dist/grideditor.css +267 -0
  5. package/dist/grideditor.d.ts +88 -0
  6. package/dist/grideditor.esm.js +27 -5
  7. package/dist/grideditor.js +27 -5
  8. package/dist/grideditor.min.css +1 -1
  9. package/dist/grideditor.min.css.map +1 -1
  10. package/dist/grideditor.min.js +1 -1
  11. package/dist/grideditor.min.js.map +3 -3
  12. package/dist/locales/grideditor.es.esm.js +102 -0
  13. package/dist/locales/grideditor.es.js +102 -0
  14. package/dist/locales/grideditor.es.min.js +1 -1
  15. package/dist/locales/grideditor.es.min.js.map +2 -2
  16. package/dist/plugins/grideditor.navbar.esm.js +2084 -0
  17. package/dist/plugins/grideditor.navbar.js +2085 -0
  18. package/dist/plugins/grideditor.navbar.min.js +1 -0
  19. package/dist/plugins/grideditor.navbar.min.js.map +7 -0
  20. package/dist/plugins/grideditor.sidenav.esm.js +1978 -0
  21. package/dist/plugins/grideditor.sidenav.js +1979 -0
  22. package/dist/plugins/grideditor.sidenav.min.js +1 -0
  23. package/dist/plugins/grideditor.sidenav.min.js.map +7 -0
  24. package/docs/events.md +5 -1
  25. package/docs/locale-keys.md +103 -1
  26. package/docs/plugins.md +23 -4
  27. package/example/containers.html +59 -2
  28. package/example/index.html +1 -1
  29. package/example/playground.html +2 -0
  30. package/package.json +1 -1
  31. package/src/js/grideditor.js +36 -4
  32. package/src/js/locales/grideditor.es.js +102 -0
  33. package/src/js/nav/browse.js +51 -0
  34. package/src/js/nav/canvas.js +170 -0
  35. package/src/js/nav/convert.js +175 -0
  36. package/src/js/nav/drawers.js +258 -0
  37. package/src/js/nav/feature.js +94 -0
  38. package/src/js/nav/locale.js +128 -0
  39. package/src/js/nav/markup.js +121 -0
  40. package/src/js/nav/panels.js +443 -0
  41. package/src/js/nav/pieces.js +207 -0
  42. package/src/js/plugins/grideditor.navbar.js +454 -0
  43. package/src/js/plugins/grideditor.sidenav.js +349 -0
  44. package/src/less/grideditor.less +199 -0
  45. package/types/grideditor.d.ts +88 -0
@@ -0,0 +1,443 @@
1
+ /**
2
+ * The fields of the settings panel: the builders the two plugins share, and
3
+ * the section each piece has.
4
+ */
5
+ import * as dom from '../dom.js';
6
+ import * as pieces from './pieces.js';
7
+ import * as convert from './convert.js';
8
+ import { browseButton } from './browse.js';
9
+ import { editInPlace } from './drawers.js';
10
+
11
+ var counter = 0;
12
+
13
+ /** The title of a piece's section, which is also what the panel calls the piece. */
14
+ export var SECTION_KEYS = {
15
+ 'nav-list': { labelKey: 'container.nav_list_section' },
16
+ 'nav-link': { labelKey: 'container.nav_link_section' },
17
+ 'nav-dropdown': { labelKey: 'container.nav_dropdown_section' },
18
+ 'nav-menu-item': { labelKey: 'container.nav_menu_item_section' },
19
+ 'nav-text': { labelKey: 'container.nav_text_section' },
20
+ 'nav-zone': { labelKey: 'container.nav_zone_section' },
21
+ 'nav-brand': { labelKey: 'container.nav_brand_section' },
22
+ };
23
+
24
+ function nextId() {
25
+ return 'ge-nav-option-' + (++counter);
26
+ }
27
+
28
+ /** A field: its label, its control and a name tests and styles can find it by. */
29
+ export function fieldRow(name, label, control, id) {
30
+ var box = dom.element('div', { 'class': 'ge-nav-option mb-2', 'data-ge-nav-option': name });
31
+
32
+ if (label) { box.appendChild(dom.element('label', { 'class': 'form-label', 'for': id }, label)); }
33
+ box.appendChild(control);
34
+
35
+ return box;
36
+ }
37
+
38
+ /** A select over `choices`, each { value, label }. */
39
+ export function selectControl(choices, onChange) {
40
+ var id = nextId();
41
+ var control = dom.element('select', { 'class': 'form-select form-select-sm', id: id });
42
+
43
+ choices.forEach(function(each) { control.appendChild(dom.element('option', { value: each.value }, each.label)); });
44
+ control.addEventListener('change', function() { onChange(control.value); });
45
+
46
+ return { id: id, control: control };
47
+ }
48
+
49
+ /** A checkbox; `box` is what goes in the panel. */
50
+ export function checkControl(label, onChange) {
51
+ var id = nextId();
52
+ var box = dom.element('div', { 'class': 'form-check ge-nav-option mb-2' });
53
+ var input = box.appendChild(dom.element('input', { 'class': 'form-check-input', type: 'checkbox', id: id }));
54
+
55
+ box.appendChild(dom.element('label', { 'class': 'form-check-label', 'for': id }, label));
56
+ input.addEventListener('change', function() { onChange(input.checked); });
57
+
58
+ return { box: box, input: input };
59
+ }
60
+
61
+ /** A text field that writes as it is typed in and when it is left. */
62
+ export function textControl(onChange) {
63
+ var id = nextId();
64
+ var control = dom.element('input', { 'class': 'form-control form-control-sm', type: 'text', id: id });
65
+
66
+ ['input', 'change'].forEach(function(name) {
67
+ control.addEventListener(name, function() { onChange(control.value); });
68
+ });
69
+
70
+ return { id: id, control: control };
71
+ }
72
+
73
+ /** A field marked as wrong, or not. */
74
+ export function markInvalid(control, invalid) {
75
+ dom.toggleClass(control, 'is-invalid', invalid);
76
+ }
77
+
78
+ /** A list of the sections open, to fill again when the markup changes. */
79
+ export function sectionsOf() {
80
+ var kept = [];
81
+
82
+ return {
83
+ add: function(entry) {
84
+ kept = kept.filter(function(each) { return each.element.isConnected; });
85
+ kept.push(entry);
86
+ },
87
+ render: function(scope) {
88
+ kept = kept.filter(function(each) { return each.element.isConnected; });
89
+ kept.forEach(function(each) {
90
+ if (!scope || each.node === scope || scope.contains(each.node)) { each.render(); }
91
+ });
92
+ },
93
+ clear: function() { kept = []; },
94
+ };
95
+ }
96
+
97
+ /** Clear what marks a link active, and give it to one. */
98
+ export function setActive(container, anchor, on) {
99
+ var clear = function(each) {
100
+ dom.removeClass(each, 'active');
101
+ each.removeAttribute('aria-current');
102
+ dom.dropEmptyClass(each);
103
+ };
104
+
105
+ if (!on) {
106
+ clear(anchor);
107
+ return;
108
+ }
109
+
110
+ dom.all(container, 'a.nav-link, a.dropdown-item').filter(function(each) {
111
+ return pieces.isOwn(container, each);
112
+ }).forEach(clear);
113
+
114
+ dom.addClass(anchor, 'active');
115
+ anchor.setAttribute('aria-current', 'page');
116
+ }
117
+
118
+ function alignOf(node) {
119
+ return dom.hasClass(node, 'ms-auto') ? 'end' : dom.hasClass(node, 'mx-auto') ? 'center' : 'after';
120
+ }
121
+
122
+ /** The panels of the pieces of a navbar and a sidenav, for one editor. */
123
+ export function createPanels(ge, loaded) {
124
+ var kept = sectionsOf();
125
+ var context = { destroyed: false };
126
+
127
+ function settingsOf(container) {
128
+ return ge.settings[pieces.typeOf(container)] || {};
129
+ }
130
+
131
+ /** A URL field, with the host's file browser beside it when it gave one. */
132
+ function urlField(container, node, property, name, label, read, write, browseNode) {
133
+ var field = textControl(write);
134
+ var holder = dom.element('div', { 'class': 'input-group input-group-sm' });
135
+
136
+ holder.appendChild(field.control);
137
+
138
+ var button = browseButton(ge, context, settingsOf(container).browse, browseNode || node, property, read, function(url) {
139
+ write(url);
140
+ kept.render();
141
+ });
142
+ if (button) { holder.appendChild(button); }
143
+
144
+ return {
145
+ row: fieldRow(name, label, holder, field.id),
146
+ render: function() { field.control.value = read(); },
147
+ };
148
+ }
149
+
150
+ function linkFields(container, node, anchor, fields) {
151
+ fields.push(urlField(container, node, 'href', 'href', ge.t('container.nav_href'),
152
+ function() { return anchor.getAttribute('href') || ''; },
153
+ function(value) { anchor.setAttribute('href', value); }, anchor));
154
+
155
+ var active = checkControl(ge.t('container.nav_active'), function(on) {
156
+ setActive(container, anchor, on);
157
+ kept.render();
158
+ });
159
+ var disabled = checkControl(ge.t('container.nav_disabled'), function(on) {
160
+ dom.toggleClass(anchor, 'disabled', on);
161
+ if (on) {
162
+ anchor.setAttribute('aria-disabled', 'true');
163
+ } else {
164
+ anchor.removeAttribute('aria-disabled');
165
+ dom.dropEmptyClass(anchor);
166
+ }
167
+ });
168
+ var tab = checkControl(ge.t('container.nav_new_tab'), function(on) {
169
+ if (on) {
170
+ anchor.setAttribute('target', '_blank');
171
+ anchor.setAttribute('rel', 'noopener');
172
+ } else {
173
+ anchor.removeAttribute('target');
174
+ anchor.removeAttribute('rel');
175
+ }
176
+ });
177
+
178
+ active.box.setAttribute('data-ge-nav-option', 'active');
179
+ disabled.box.setAttribute('data-ge-nav-option', 'disabled');
180
+ tab.box.setAttribute('data-ge-nav-option', 'new_tab');
181
+
182
+ fields.push({ row: active.box, render: function() { active.input.checked = dom.hasClass(anchor, 'active'); } });
183
+ fields.push({ row: disabled.box, render: function() { disabled.input.checked = dom.hasClass(anchor, 'disabled'); } });
184
+ fields.push({ row: tab.box, render: function() { tab.input.checked = anchor.getAttribute('target') === '_blank'; } });
185
+ }
186
+
187
+ function dropdownFields(container, node, fields) {
188
+ var type = pieces.typeOf(container);
189
+
190
+ if (type === 'sidenav') {
191
+ var kind = selectControl([
192
+ { value: 'collapse', label: ge.t('container.nav_submenu_type_collapse') },
193
+ { value: 'dropdown', label: ge.t('container.nav_submenu_type_dropdown') },
194
+ ], function(value) {
195
+ if (value === 'collapse') { convert.toSubmenu(ge, node); } else { convert.toDropdown(ge, node); }
196
+ kept.render();
197
+ });
198
+
199
+ fields.push({
200
+ row: fieldRow('submenu_type', ge.t('container.nav_submenu_type'), kind.control, kind.id),
201
+ render: function() { kind.control.value = pieces.isSubmenu(node) ? 'collapse' : 'dropdown'; },
202
+ });
203
+ }
204
+
205
+ var end = checkControl(ge.t('container.nav_menu_end'), function(on) {
206
+ var menu = pieces.menuOf(node);
207
+ if (!menu) { return; }
208
+
209
+ dom.toggleClass(menu, 'dropdown-menu-end', on);
210
+ dom.dropEmptyClass(menu);
211
+ });
212
+ end.box.setAttribute('data-ge-nav-option', 'menu_end');
213
+ fields.push({
214
+ row: end.box,
215
+ render: function() {
216
+ var menu = pieces.menuOf(node);
217
+
218
+ end.input.checked = dom.hasClass(menu, 'dropdown-menu-end');
219
+ end.input.disabled = pieces.isSubmenu(node);
220
+ },
221
+ });
222
+
223
+ if (type !== 'sidenav') { return; }
224
+
225
+ var open = checkControl(ge.t('container.nav_submenu_open'), function(on) {
226
+ var collapse = dom.child(node, '.collapse');
227
+ var toggle = dom.child(node, 'a');
228
+ if (!collapse) { return; }
229
+
230
+ dom.toggleClass(collapse, 'show', on);
231
+ toggle.setAttribute('aria-expanded', on ? 'true' : 'false');
232
+ });
233
+ open.box.setAttribute('data-ge-nav-option', 'submenu_open');
234
+ fields.push({
235
+ row: open.box,
236
+ render: function() {
237
+ var collapse = dom.child(node, '.collapse');
238
+
239
+ open.input.checked = dom.hasClass(collapse, 'show');
240
+ open.input.disabled = !pieces.isSubmenu(node);
241
+ },
242
+ });
243
+ }
244
+
245
+ function alignmentField(node, fields) {
246
+ var align = selectControl([
247
+ { value: 'after', label: ge.t('container.nav_align_after') },
248
+ { value: 'end', label: ge.t('container.nav_align_end') },
249
+ { value: 'center', label: ge.t('container.nav_align_center') },
250
+ ], function(value) {
251
+ dom.removeClass(node, 'ms-auto mx-auto');
252
+ if (value === 'end') { dom.addClass(node, 'ms-auto'); }
253
+ if (value === 'center') { dom.addClass(node, 'mx-auto'); }
254
+ dom.dropEmptyClass(node);
255
+ });
256
+
257
+ fields.push({
258
+ row: fieldRow('align', ge.t('container.nav_align'), align.control, align.id),
259
+ render: function() { align.control.value = alignOf(node); },
260
+ });
261
+ }
262
+
263
+ function scrollFields(node, fields) {
264
+ var height = textControl(function(value) {
265
+ if (!dom.hasClass(node, 'navbar-nav-scroll')) { return; }
266
+
267
+ var valid = value.trim() !== '' && window.CSS && CSS.supports('height', value.trim());
268
+
269
+ markInvalid(height.control, !valid);
270
+ if (valid) { ge.setHostStyle(node, '--bs-scroll-height', value.trim()); }
271
+ });
272
+ var scroll = checkControl(ge.t('container.nav_scroll'), function(on) {
273
+ if (on) {
274
+ var typed = height.control.value.trim();
275
+ var wanted = typed && CSS.supports('height', typed) ? typed : '75vh';
276
+
277
+ dom.addClass(node, 'navbar-nav-scroll');
278
+ ge.setHostStyle(node, '--bs-scroll-height', wanted);
279
+ } else {
280
+ dom.removeClass(node, 'navbar-nav-scroll');
281
+ dom.dropEmptyClass(node);
282
+ ge.setHostStyle(node, '--bs-scroll-height', '');
283
+ }
284
+
285
+ markInvalid(height.control, false);
286
+ });
287
+
288
+ scroll.box.setAttribute('data-ge-nav-option', 'scroll');
289
+ fields.push({ row: scroll.box, render: function() { scroll.input.checked = dom.hasClass(node, 'navbar-nav-scroll'); } });
290
+ fields.push({
291
+ row: fieldRow('scroll_height', ge.t('container.nav_scroll_height'), height.control, height.id),
292
+ render: function() {
293
+ var shown = ge.hostStyle(node, '--bs-scroll-height').value;
294
+
295
+ height.control.value = shown || '75vh';
296
+ height.control.disabled = !dom.hasClass(node, 'navbar-nav-scroll');
297
+ markInvalid(height.control, false);
298
+ },
299
+ });
300
+ }
301
+
302
+ function bottomField(node, fields) {
303
+ var bottom = checkControl(ge.t('container.nav_bottom'), function(on) {
304
+ dom.toggleClass(node, 'mt-auto', on);
305
+ dom.dropEmptyClass(node);
306
+ });
307
+
308
+ bottom.box.setAttribute('data-ge-nav-option', 'bottom');
309
+ fields.push({ row: bottom.box, render: function() { bottom.input.checked = dom.hasClass(node, 'mt-auto'); } });
310
+ }
311
+
312
+ function brandFields(container, node, fields) {
313
+ var imageOf = function() { return dom.child(node, 'img'); };
314
+
315
+ fields.push(urlField(container, node, 'href', 'href', ge.t('container.nav_href'),
316
+ function() { return node.getAttribute('href') || ''; },
317
+ function(value) { node.setAttribute('href', value); }));
318
+
319
+ fields.push(urlField(container, node, 'src', 'image', ge.t('container.nav_brand_image'),
320
+ function() { var img = imageOf(); return img ? img.getAttribute('src') || '' : ''; },
321
+ function(value) { setImage(value); },
322
+ function() { return imageOf() || node; }));
323
+
324
+ var alt = textControl(function(value) {
325
+ var img = imageOf();
326
+ if (img) { img.setAttribute('alt', value); }
327
+ });
328
+ fields.push({
329
+ row: fieldRow('alt', ge.t('container.nav_brand_alt'), alt.control, alt.id),
330
+ render: function() {
331
+ var img = imageOf();
332
+
333
+ alt.control.value = img ? img.getAttribute('alt') || '' : '';
334
+ alt.control.disabled = !img;
335
+ },
336
+ });
337
+
338
+ var height = textControl(function(value) {
339
+ var img = imageOf();
340
+ var valid = /^\d+$/.test(value.trim()) && parseInt(value, 10) >= 1;
341
+
342
+ markInvalid(height.control, !valid);
343
+ if (valid && img) { img.setAttribute('height', String(parseInt(value, 10))); }
344
+ });
345
+ fields.push({
346
+ row: fieldRow('image_height', ge.t('container.nav_brand_height'), height.control, height.id),
347
+ render: function() {
348
+ var img = imageOf();
349
+
350
+ height.control.value = img ? img.getAttribute('height') || '30' : '30';
351
+ height.control.disabled = !img;
352
+ markInvalid(height.control, false);
353
+ },
354
+ });
355
+
356
+ function setImage(url) {
357
+ var img = imageOf();
358
+
359
+ if (url === '') {
360
+ if (img) { img.remove(); }
361
+ if (!node.textContent.trim().replace(/\s+/g, '')) {
362
+ node.appendChild(document.createTextNode(ge.t(pieces.defaultLabelKey(node, 'nav-brand', container))));
363
+ editInPlace(ge, node, function() { return ge.t(pieces.defaultLabelKey(node, 'nav-brand', container)); });
364
+ }
365
+ return;
366
+ }
367
+
368
+ if (img) {
369
+ img.setAttribute('src', url);
370
+ return;
371
+ }
372
+
373
+ var first = dom.children(node).filter(function(each) { return !dom.hasClass(each, 'ge-tools-drawer'); })[0] || null;
374
+
375
+ node.insertBefore(dom.element('img', { src: url, alt: '', height: '30' }), first || node.firstChild);
376
+ }
377
+ }
378
+
379
+ /** The fields of a piece, or an empty list for a piece with none. */
380
+ function fieldsOf(container, node, kind) {
381
+ var type = pieces.typeOf(container);
382
+ var fields = [];
383
+
384
+ if (kind === 'nav-link') { linkFields(container, node, pieces.anchorOf(node), fields); }
385
+ if (kind === 'nav-dropdown') { dropdownFields(container, node, fields); }
386
+
387
+ if (kind === 'nav-menu-item' && pieces.itemType(node) === 'link') {
388
+ linkFields(container, node, pieces.anchorOf(node), fields);
389
+ }
390
+
391
+ if (kind === 'nav-list') {
392
+ if (type === 'navbar') {
393
+ alignmentField(node, fields);
394
+ scrollFields(node, fields);
395
+ } else {
396
+ bottomField(node, fields);
397
+ }
398
+ }
399
+
400
+ if (kind === 'nav-text' || kind === 'nav-zone') {
401
+ if (type === 'navbar') { alignmentField(node, fields); } else { bottomField(node, fields); }
402
+ }
403
+
404
+ if (kind === 'nav-brand') { brandFields(container, node, fields); }
405
+
406
+ return fields;
407
+ }
408
+
409
+ return {
410
+ context: context,
411
+
412
+ /** The section of a piece's settings panel, or null for a piece with nothing to set. */
413
+ pieceSection: function(node, kind) {
414
+ if (pieces.KINDS.indexOf(kind) === -1) { return null; }
415
+
416
+ var container = pieces.ownerOf(node, loaded);
417
+ if (!container) { return null; }
418
+
419
+ var fields = fieldsOf(container, node, kind);
420
+ if (!fields.length) { return null; }
421
+
422
+ var body = dom.element('div', { 'class': 'ge-nav-options' });
423
+
424
+ fields.forEach(function(each) { body.appendChild(each.row); });
425
+
426
+ var render = function() { fields.forEach(function(each) { each.render(); }); };
427
+
428
+ render();
429
+ kept.add({ node: node, element: body, render: render });
430
+
431
+ return { labelKey: SECTION_KEYS[kind].labelKey, body: body };
432
+ },
433
+
434
+ /** Every section open, filled again from the markup. */
435
+ refresh: function() { kept.render(); },
436
+
437
+ onRefresh: function(scope) { kept.render(scope); },
438
+
439
+ onDeinit: function() { kept.clear(); },
440
+
441
+ onDestroy: function() { context.destroyed = true; },
442
+ };
443
+ }
@@ -0,0 +1,207 @@
1
+ /**
2
+ * What a navbar or a sidenav 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
+ export var TYPES = ['navbar', 'sidenav'];
11
+
12
+ var WRAPS = '.container, .container-fluid, .container-sm, .container-md, .container-lg, .container-xl, .container-xxl';
13
+
14
+ /** The kinds of piece, as the events call them. */
15
+ export var KINDS = ['nav-list', 'nav-link', 'nav-dropdown', 'nav-menu-item', 'nav-text', 'nav-zone', 'nav-brand'];
16
+
17
+ export function typeOf(container) {
18
+ return container ? container.getAttribute('data-ge-container') : null;
19
+ }
20
+
21
+ export function isZone(node) {
22
+ return dom.is(node, '[data-ge-nav="zone"]');
23
+ }
24
+
25
+ export function isSubmenu(node) {
26
+ return dom.is(node, 'li[data-ge-nav="submenu"]');
27
+ }
28
+
29
+ /** The `nav` of a navbar. */
30
+ export function navOf(container) {
31
+ return dom.child(container, 'nav');
32
+ }
33
+
34
+ /** What holds a navbar's brand: the `.container*`, or the `nav` when it has none. */
35
+ export function wrapOf(container) {
36
+ var nav = navOf(container);
37
+
38
+ return nav ? (dom.child(nav, WRAPS) || nav) : null;
39
+ }
40
+
41
+ /** The part of a navbar that folds, or the node the pieces are in when nothing folds. */
42
+ export function areaOf(container) {
43
+ var wrap = wrapOf(container);
44
+ if (!wrap) { return null; }
45
+
46
+ var collapse = dom.child(wrap, '.navbar-collapse');
47
+ if (collapse) { return collapse; }
48
+
49
+ var offcanvas = dom.child(wrap, '.offcanvas');
50
+ var body = offcanvas ? dom.child(offcanvas, '.offcanvas-body') : null;
51
+
52
+ return body || wrap;
53
+ }
54
+
55
+ /** The `.offcanvas` a navbar folds into, or null. */
56
+ export function offcanvasOf(container) {
57
+ var wrap = wrapOf(container);
58
+
59
+ return wrap ? dom.child(wrap, '.offcanvas') : null;
60
+ }
61
+
62
+ /** The panel of a sidenav: what is not the editor's drawer or the button that opens it. */
63
+ export function panelOf(container) {
64
+ return dom.children(container).filter(function(node) {
65
+ return !dom.hasClass(node, 'ge-tools-drawer') && node.tagName !== 'BUTTON';
66
+ })[0] || null;
67
+ }
68
+
69
+ /** The button that opens a responsive sidenav, or null. */
70
+ export function triggerOf(container) {
71
+ return dom.child(container, 'button');
72
+ }
73
+
74
+ /** Where the pieces of a container are: the area of a navbar, the panel of a sidenav. */
75
+ export function holderOf(container) {
76
+ return typeOf(container) === 'sidenav' ? panelOf(container) : areaOf(container);
77
+ }
78
+
79
+ /**
80
+ * The navbar or sidenav a node is a piece of: the nearest container above
81
+ * it, when that is one of these and a plugin the editor has. A free zone,
82
+ * or another container, is a scope of its own: what is in it is not a piece.
83
+ */
84
+ export function ownerOf(node, loaded) {
85
+ var holder = node && node.parentElement ? node.parentElement.closest('[data-ge-container], [data-ge-nav="zone"]') : null;
86
+
87
+ if (!holder || isZone(holder)) { return null; }
88
+
89
+ return loaded(typeOf(holder)) ? holder : null;
90
+ }
91
+
92
+ function isMenu(node) {
93
+ return dom.is(node, '.dropdown-menu');
94
+ }
95
+
96
+ /** The menu of a dropdown or a submenu: what its items are children of. */
97
+ export function menuOf(dropdown) {
98
+ if (isSubmenu(dropdown)) { return dom.one(dropdown, ':scope > .collapse > ul'); }
99
+
100
+ return dom.child(dropdown, '.dropdown-menu');
101
+ }
102
+
103
+ /** What an item of a menu is, by what it holds. */
104
+ export function itemType(item) {
105
+ if (dom.child(item, 'hr')) { return 'divider'; }
106
+ if (dom.child(item, 'h6')) { return 'header'; }
107
+ if (dom.child(item, 'a')) { return 'link'; }
108
+
109
+ return 'text';
110
+ }
111
+
112
+ /** The link of a link, a dropdown's toggle, or a menu item that is a link. */
113
+ export function anchorOf(piece) {
114
+ return dom.child(piece, 'a');
115
+ }
116
+
117
+ /** What the markup of a node says it is, wherever it is. */
118
+ export function kindOf(node, loaded) {
119
+ var container = ownerOf(node, loaded);
120
+ if (!container) { return null; }
121
+
122
+ var type = typeOf(container);
123
+ var parent = node.parentElement;
124
+ var holder = holderOf(container);
125
+
126
+ if (parent === holder || (type === 'navbar' && parent === wrapOf(container) && dom.is(node, '.navbar-brand'))) {
127
+ if (isZone(node)) { return 'nav-zone'; }
128
+
129
+ if (type === 'navbar') {
130
+ if (dom.is(node, '.navbar-brand')) { return 'nav-brand'; }
131
+ if (dom.is(node, 'ul.navbar-nav')) { return 'nav-list'; }
132
+ if (dom.is(node, '.navbar-text')) { return 'nav-text'; }
133
+
134
+ return null;
135
+ }
136
+
137
+ if (dom.is(node, 'a[data-ge-nav="brand"]')) { return 'nav-brand'; }
138
+ if (dom.is(node, 'ul.nav')) { return 'nav-list'; }
139
+ if (dom.is(node, '[data-ge-nav="text"]')) { return 'nav-text'; }
140
+
141
+ return null;
142
+ }
143
+
144
+ if (!dom.is(node, 'li') || !parent) { return null; }
145
+
146
+ if (dom.is(parent, 'ul') && parent.parentElement && kindOf(parent, loaded) === 'nav-list') {
147
+ if (dom.is(node, '.nav-item.dropdown') || (type === 'sidenav' && isSubmenu(node))) { return 'nav-dropdown'; }
148
+ if (dom.is(node, '.nav-item') && dom.child(node, 'a.nav-link')) { return 'nav-link'; }
149
+
150
+ return null;
151
+ }
152
+
153
+ if (isMenu(parent) && dom.is(parent.parentElement, 'li.nav-item.dropdown') && kindOf(parent.parentElement, loaded) === 'nav-dropdown') {
154
+ return 'nav-menu-item';
155
+ }
156
+
157
+ if (type === 'sidenav' && dom.is(parent, 'ul') && dom.is(parent.parentElement, '.collapse') &&
158
+ isSubmenu(parent.parentElement.parentElement) && kindOf(parent.parentElement.parentElement, loaded) === 'nav-dropdown') {
159
+ return 'nav-menu-item';
160
+ }
161
+
162
+ return null;
163
+ }
164
+
165
+ /** Every piece of a container, in document order: { node, kind }. */
166
+ export function piecesOf(container, loaded) {
167
+ var found = [];
168
+
169
+ dom.all(container, '*').forEach(function(node) {
170
+ if (ownerOf(node, loaded) !== container) { return; }
171
+
172
+ var kind = kindOf(node, loaded);
173
+ if (kind) { found.push({ node: node, kind: kind }); }
174
+ });
175
+
176
+ return found;
177
+ }
178
+
179
+ /** Whether a node is the container's own: not in a free zone of it, and not in another container. */
180
+ export function isOwn(container, node) {
181
+ var scope = node.parentElement ? node.parentElement.closest('[data-ge-container], [data-ge-nav="zone"]') : null;
182
+
183
+ return scope === container;
184
+ }
185
+
186
+ /** The nodes of a container's own that Bootstrap's data api acts on. */
187
+ export function togglesOf(container) {
188
+ return dom.all(container, '[data-bs-toggle], [data-ge-bs-toggle], [data-bs-dismiss], [data-ge-bs-dismiss]').filter(function(node) {
189
+ return isOwn(container, node);
190
+ });
191
+ }
192
+
193
+ /** What a piece is called in the default text it gets when its label is emptied. */
194
+ export function defaultLabelKey(node, kind, container) {
195
+ var type = typeOf(container);
196
+
197
+ if (kind === 'nav-link') { return 'container.nav_link'; }
198
+ if (kind === 'nav-dropdown') { return isSubmenu(node) ? 'container.nav_submenu' : 'container.nav_dropdown'; }
199
+ if (kind === 'nav-text') { return 'container.nav_text'; }
200
+ if (kind === 'nav-brand') { return type === 'sidenav' ? 'container.sidenav_brand' : 'container.navbar_brand'; }
201
+
202
+ var itemKind = itemType(node);
203
+ if (itemKind === 'header') { return 'container.nav_menu_header'; }
204
+ if (itemKind === 'text') { return 'container.nav_text'; }
205
+
206
+ return 'container.nav_menu_link';
207
+ }