@themarioga/grid-editor 9.0.0-beta.6 → 9.0.0-beta.8

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 (103) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/README.md +54 -27
  3. package/UPGRADING.md +1 -1
  4. package/dist/grideditor.bundle.min.js +2 -2
  5. package/dist/grideditor.css +24 -3
  6. package/dist/grideditor.d.ts +27 -2
  7. package/dist/grideditor.esm.js +64 -7
  8. package/dist/grideditor.js +64 -7
  9. package/dist/grideditor.min.css +1 -1
  10. package/dist/grideditor.min.css.map +1 -1
  11. package/dist/grideditor.min.js +1 -1
  12. package/dist/grideditor.min.js.map +3 -3
  13. package/dist/locales/grideditor.es.esm.js +2 -0
  14. package/dist/locales/grideditor.es.js +2 -0
  15. package/dist/locales/grideditor.es.min.js +1 -1
  16. package/dist/locales/grideditor.es.min.js.map +2 -2
  17. package/dist/plugins/grideditor.accordion.esm.js +9 -0
  18. package/dist/plugins/grideditor.accordion.js +9 -0
  19. package/dist/plugins/grideditor.accordion.min.js +1 -1
  20. package/dist/plugins/grideditor.accordion.min.js.map +3 -3
  21. package/dist/plugins/grideditor.card.min.js +1 -1
  22. package/dist/plugins/grideditor.card.min.js.map +1 -1
  23. package/dist/plugins/grideditor.carousel.esm.js +3 -0
  24. package/dist/plugins/grideditor.carousel.js +3 -0
  25. package/dist/plugins/grideditor.carousel.min.js +1 -1
  26. package/dist/plugins/grideditor.carousel.min.js.map +3 -3
  27. package/dist/plugins/grideditor.ckeditor.esm.js +9 -0
  28. package/dist/plugins/grideditor.ckeditor.js +9 -0
  29. package/dist/plugins/grideditor.ckeditor.min.js +1 -1
  30. package/dist/plugins/grideditor.ckeditor.min.js.map +3 -3
  31. package/dist/plugins/grideditor.clipboard.esm.js +44 -7
  32. package/dist/plugins/grideditor.clipboard.js +44 -7
  33. package/dist/plugins/grideditor.clipboard.min.js +1 -1
  34. package/dist/plugins/grideditor.clipboard.min.js.map +3 -3
  35. package/dist/plugins/grideditor.codemirror-inline.min.js.map +1 -1
  36. package/dist/plugins/grideditor.codemirror.min.js.map +1 -1
  37. package/dist/plugins/grideditor.elements.esm.js +3 -0
  38. package/dist/plugins/grideditor.elements.js +3 -0
  39. package/dist/plugins/grideditor.elements.min.js +1 -1
  40. package/dist/plugins/grideditor.elements.min.js.map +3 -3
  41. package/dist/plugins/grideditor.gutters.min.js.map +1 -1
  42. package/dist/plugins/grideditor.history.esm.js +1 -1
  43. package/dist/plugins/grideditor.history.js +1 -1
  44. package/dist/plugins/grideditor.history.min.js +1 -1
  45. package/dist/plugins/grideditor.history.min.js.map +2 -2
  46. package/dist/plugins/grideditor.inline-style.esm.js +66 -3
  47. package/dist/plugins/grideditor.inline-style.js +66 -3
  48. package/dist/plugins/grideditor.inline-style.min.js +4 -4
  49. package/dist/plugins/grideditor.inline-style.min.js.map +3 -3
  50. package/dist/plugins/grideditor.offcanvas.min.js.map +1 -1
  51. package/dist/plugins/grideditor.order.min.js +1 -1
  52. package/dist/plugins/grideditor.order.min.js.map +1 -1
  53. package/dist/plugins/grideditor.popup.min.js.map +1 -1
  54. package/dist/plugins/grideditor.sections.esm.js +9 -0
  55. package/dist/plugins/grideditor.sections.js +9 -0
  56. package/dist/plugins/grideditor.sections.min.js +1 -1
  57. package/dist/plugins/grideditor.sections.min.js.map +3 -3
  58. package/dist/plugins/grideditor.summernote.esm.js +9 -0
  59. package/dist/plugins/grideditor.summernote.js +9 -0
  60. package/dist/plugins/grideditor.summernote.min.js +1 -1
  61. package/dist/plugins/grideditor.summernote.min.js.map +3 -3
  62. package/dist/plugins/grideditor.tabs.esm.js +3 -0
  63. package/dist/plugins/grideditor.tabs.js +3 -0
  64. package/dist/plugins/grideditor.tabs.min.js +1 -1
  65. package/dist/plugins/grideditor.tabs.min.js.map +3 -3
  66. package/dist/plugins/grideditor.tinymce.esm.js +9 -0
  67. package/dist/plugins/grideditor.tinymce.js +9 -0
  68. package/dist/plugins/grideditor.tinymce.min.js +1 -1
  69. package/dist/plugins/grideditor.tinymce.min.js.map +3 -3
  70. package/docs/events.md +6 -1
  71. package/docs/locale-keys.md +2 -0
  72. package/docs/plugins.md +9 -7
  73. package/example/adapter.html +11 -1
  74. package/example/clipboard.html +7 -4
  75. package/example/{autocols.html → columns.html} +61 -20
  76. package/example/containers.html +13 -2
  77. package/example/{attributes.html → custom-plugins.html} +130 -12
  78. package/example/elements.html +13 -2
  79. package/example/history.html +6 -3
  80. package/example/index.html +30 -81
  81. package/example/playground.html +840 -0
  82. package/example/style.html +291 -0
  83. package/example/text-editors.html +320 -0
  84. package/package.json +1 -1
  85. package/src/js/dom.js +6 -0
  86. package/src/js/grideditor.js +69 -7
  87. package/src/js/inline-style/accordion.js +4 -3
  88. package/src/js/inline-style/fields.js +56 -3
  89. package/src/js/inline-style/options.js +12 -0
  90. package/src/js/locales/grideditor.es.js +2 -0
  91. package/src/js/plugins/grideditor.clipboard.js +61 -11
  92. package/src/js/plugins/grideditor.history.js +3 -3
  93. package/src/js/plugins/grideditor.inline-style.js +10 -0
  94. package/src/js/text/grideditor.text.js +1 -1
  95. package/src/less/grideditor.less +26 -3
  96. package/types/grideditor.d.ts +27 -2
  97. package/example/breakpoints.html +0 -100
  98. package/example/ckeditor.html +0 -110
  99. package/example/custom_editor.html +0 -212
  100. package/example/inline-style.html +0 -163
  101. package/example/plugins.html +0 -251
  102. package/example/summernote.html +0 -114
  103. package/example/utilities.html +0 -200
@@ -495,6 +495,8 @@ function build(instance, baseElem, optionsOrMethod) {
495
495
  // be jQuery data: a node's settings panel, a drag or a resize in
496
496
  // progress. Kept off the markup, and gone with the node.
497
497
  var detailsFor = new WeakMap(); // node -> its settings panel
498
+ var toolActions = new WeakMap(); // A tool -> what its click does, to do it without one
499
+ var pendingDelete = null; // What removeNode asks of the delete the tool it runs makes, for that call only
498
500
  var moves = new WeakMap(); // dragged node -> { from, canceled }
499
501
  var resizes = new WeakMap(); // column -> { from, units }
500
502
  var sectionNodes = new WeakMap(); // Responsive section -> the node it edits
@@ -844,12 +846,16 @@ function build(instance, baseElem, optionsOrMethod) {
844
846
  * question to have been asked already.
845
847
  */
846
848
  function deleteNode(kind, node, message, animate) {
849
+ var asked = pendingDelete || {};
850
+ pendingDelete = null;
851
+
847
852
  operate(function() {
848
- var payload = payloadFor(kind, node, { source: 'tool' });
853
+ var payload = payloadFor(kind, node, { source: asked.source || 'tool' });
849
854
 
850
855
  if (!emit('before-delete', payload)) { return; }
856
+ if (asked.before) { asked.before(); }
851
857
 
852
- askToDelete(message, function() {
858
+ var remove = function() {
853
859
  operate(function() {
854
860
  animate(function() {
855
861
  node.remove();
@@ -859,10 +865,51 @@ function build(instance, baseElem, optionsOrMethod) {
859
865
  });
860
866
  });
861
867
  });
862
- });
868
+ };
869
+
870
+ if (asked.confirm === false) {
871
+ remove();
872
+ } else {
873
+ askToDelete(message, remove);
874
+ }
863
875
  });
864
876
  }
865
877
 
878
+ /**
879
+ * A node removed as its own delete tool removes it - the text's
880
+ * editor closes first, say - but as the caller asks: without the
881
+ * question, from a `source` of its own, and with `before()` called
882
+ * once the host's before-delete has let it through, which is also
883
+ * what the answer says. False for a node with no delete tool, or
884
+ * one a before-delete turned away.
885
+ */
886
+ function removeNode(node, options) {
887
+ options = options || {};
888
+
889
+ var drawer = node ? drawerOf(node) : null;
890
+ var tool = drawer ? dom.child(drawer, '[class*="ge-delete-"]') : null;
891
+ var action = tool ? toolActions.get(tool) : null;
892
+ if (!action) { return false; }
893
+
894
+ var went = false;
895
+ pendingDelete = {
896
+ source: options.source,
897
+ confirm: options.confirm,
898
+ before: function() {
899
+ went = true;
900
+ if (options.before) { options.before(); }
901
+ },
902
+ };
903
+
904
+ try {
905
+ action.call(tool);
906
+ } finally {
907
+ pendingDelete = null;
908
+ }
909
+
910
+ return went;
911
+ }
912
+
866
913
  /**
867
914
  * What resizing this column to `size` in `view` would write, or null
868
915
  * when the budget refuses it or there is nothing to change.
@@ -1561,8 +1608,12 @@ function build(instance, baseElem, optionsOrMethod) {
1561
1608
  // Only the chosen category's, with toolbar_groups: the others
1562
1609
  // wait in their stash
1563
1610
  var homes = shownAddButtons();
1564
- homes.forEach(function(entry) { entry.home.appendChild(entry.button); });
1611
+ homes.forEach(function(entry) {
1612
+ entry.home.appendChild(entry.button);
1613
+ dom.removeClass(entry.button, 'ge-before-more');
1614
+ });
1565
1615
  dom.removeClass(more, 'ge-needed');
1616
+ dom.removeClass(wrapper, 'ge-toolbar-overflowing');
1566
1617
 
1567
1618
  if (start.scrollWidth <= start.clientWidth) {
1568
1619
  openOverflow(false);
@@ -1570,10 +1621,16 @@ function build(instance, baseElem, optionsOrMethod) {
1570
1621
  }
1571
1622
 
1572
1623
  dom.addClass(more, 'ge-needed');
1624
+ dom.addClass(wrapper, 'ge-toolbar-overflowing');
1573
1625
  for (var i = homes.length - 1; i >= 0 && start.scrollWidth > start.clientWidth; i--) {
1574
1626
  var into = spareOf(homes[i].home);
1575
1627
  into.insertBefore(homes[i].button, into.firstChild);
1576
1628
  }
1629
+
1630
+ // The more button joins the last button left on the line, as
1631
+ // one more button of its group
1632
+ var onLine = homes.filter(function(entry) { return entry.button.parentNode === entry.home; });
1633
+ if (onLine.length) { dom.addClass(onLine[onLine.length - 1].button, 'ge-before-more'); }
1577
1634
  }
1578
1635
  }
1579
1636
 
@@ -2496,8 +2553,8 @@ function build(instance, baseElem, optionsOrMethod) {
2496
2553
  var copy = copyCanvas();
2497
2554
  var root = copy.root;
2498
2555
 
2499
- [root].concat(dom.all(root, '.ge-selected, .ge-settings-target')).forEach(function(node) {
2500
- dom.removeClass(node, 'ge-selected ge-settings-target');
2556
+ [root].concat(dom.all(root, '.ge-selected, .ge-settings-target, .ge-leaving')).forEach(function(node) {
2557
+ dom.removeClass(node, 'ge-selected ge-settings-target ge-leaving');
2501
2558
  dom.dropEmptyClass(node);
2502
2559
  });
2503
2560
  dom.all(root, '.ge-drop-marker').forEach(function(marker) { marker.remove(); });
@@ -2760,11 +2817,14 @@ function build(instance, baseElem, optionsOrMethod) {
2760
2817
  // True when it took: a node that cannot be, or no setting
2761
2818
  // for it, says nothing, since a plugin putting back what it
2762
2819
  // remembers cannot know the node is still one
2820
+ // null takes it away
2763
2821
  setActiveTarget: function(node) {
2764
- var chosen = !!settings.active_target && isTarget(node);
2822
+ var chosen = !!settings.active_target && (node === null || isTarget(node));
2765
2823
  if (chosen) { changeTarget(node); }
2766
2824
  return chosen;
2767
2825
  },
2826
+ // A node removed as its delete tool does, as asked
2827
+ removeNode: removeNode,
2768
2828
  // What keeps Escape from the target, and an
2769
2829
  // inline panel unfolded in a drawer, which Escape leaves alone
2770
2830
  panelOpen: function() {
@@ -4161,11 +4221,13 @@ function build(instance, baseElem, optionsOrMethod) {
4161
4221
 
4162
4222
  if (typeof eventHandlers == 'function') {
4163
4223
  tool.addEventListener('click', eventHandlers);
4224
+ toolActions.set(tool, eventHandlers);
4164
4225
  }
4165
4226
  if (eventHandlers && typeof eventHandlers == 'object') {
4166
4227
  Object.keys(eventHandlers).forEach(function(name) {
4167
4228
  dom.on(tool, name, eventHandlers[name]);
4168
4229
  });
4230
+ if (typeof eventHandlers.click == 'function') { toolActions.set(tool, eventHandlers.click); }
4169
4231
  }
4170
4232
 
4171
4233
  return tool;
@@ -54,8 +54,9 @@ function partContent(ge, part, node, kind) {
54
54
 
55
55
  /**
56
56
  * `context` is the plugin's: its resolved sections, its parts by name, the
57
- * state it keeps for the editor ({ open }) and `opened(key)`, called when
58
- * the user opens or closes a section.
57
+ * state it keeps for the editor ({ open }), `opened(key)`, called when
58
+ * the user opens or closes a section, the host's `browse` and whether the
59
+ * editor was `destroyed`.
59
60
  */
60
61
  export function createAccordion(ge, node, kind, context) {
61
62
  var inline = takesInlineStyle(node, kind);
@@ -122,7 +123,7 @@ export function createAccordion(ge, node, kind, context) {
122
123
 
123
124
  var grid = body.appendChild(dom.element('div', { 'class': 'ge-inline-style-fields' }));
124
125
  properties.forEach(function(property) {
125
- var field = createStyleField(ge, node, property, changed);
126
+ var field = createStyleField(ge, node, property, changed, context);
126
127
  fields.push(field);
127
128
  grid.appendChild(field);
128
129
  });
@@ -312,12 +312,53 @@ function shadowControl(ge, node, property, changed) {
312
312
  return { element: holder, render: render, value: function() { return ge.hostStyle(node, property).value; } };
313
313
  }
314
314
 
315
+ /**
316
+ * The button that opens the host's file browser: `browse(done, { node,
317
+ * property, value })`, answered by `done(url)` or by the promise it
318
+ * returns, whichever comes first. Nothing, an empty text or a value that is
319
+ * not a text leaves the field as it was, and so does an answer that comes
320
+ * when the node or the editor is gone. Errors are the host's: not caught.
321
+ */
322
+ function browseButton(ge, node, property, context, current, apply) {
323
+ var button = dom.element('button', {
324
+ type: 'button',
325
+ 'class': 'btn btn-outline-secondary ge-inline-style-browse',
326
+ title: ge.t('inline_style.browse'),
327
+ 'aria-label': ge.t('inline_style.browse'),
328
+ });
329
+ button.appendChild(dom.element('i', { 'class': 'bi bi-folder2-open', 'aria-hidden': 'true' }));
330
+
331
+ button.addEventListener('click', function() {
332
+ var answered = false; // Each press takes one answer, the first
333
+
334
+ function answer(url) {
335
+ if (answered) { return; }
336
+ answered = true;
337
+
338
+ if (url === null || url === undefined) { return; }
339
+ if (typeof url !== 'string') {
340
+ ge.warn('inline_style.browse gave ' + typeof url + ', not a text: ignored');
341
+ return;
342
+ }
343
+ if (url.trim() === '' || context.destroyed || !ge.canvas.contains(node)) { return; }
344
+
345
+ apply(url.trim());
346
+ }
347
+
348
+ var result = context.browse(answer, { node: node, property: property.name, value: shownUrl(current()) });
349
+ if (result && typeof result.then === 'function') { result.then(answer); }
350
+ });
351
+
352
+ return button;
353
+ }
354
+
315
355
  /**
316
356
  * The field for one property of a node. `changed` is called after every
317
357
  * write that went through, so the plugin can bring the rest of its
318
- * sections up to date.
358
+ * sections up to date. `context` is the plugin's, where the host's
359
+ * file browser is.
319
360
  */
320
- export function createStyleField(ge, node, property, changed) {
361
+ export function createStyleField(ge, node, property, changed, context) {
321
362
  var field = dom.element('div', { 'class': 'ge-inline-style-field', 'data-ge-inline-style-property': property.name });
322
363
  var label = field.appendChild(dom.element('label', { 'class': 'ge-inline-style-label' }, ge.t(property.labelKey)));
323
364
  var render;
@@ -350,8 +391,20 @@ export function createStyleField(ge, node, property, changed) {
350
391
  field.appendChild(color.element);
351
392
  render = function() { color.set(current()); };
352
393
  } else if (property.type === 'url') {
353
- var url = field.appendChild(textInput());
394
+ var url = textInput();
354
395
  url.addEventListener('change', function() { commit(urlValue(url.value), url); });
396
+
397
+ if (context && context.browse) {
398
+ var group = field.appendChild(dom.element('div', { 'class': 'input-group input-group-sm ge-inline-style-url' }));
399
+ group.appendChild(url);
400
+ group.appendChild(browseButton(ge, node, property, context, current, function(text) {
401
+ dom.removeClass(url, 'is-invalid');
402
+ url.value = text;
403
+ commit(urlValue(text), url);
404
+ }));
405
+ } else {
406
+ field.appendChild(url);
407
+ }
355
408
  render = function() { fill(url, shownUrl(current())); };
356
409
  } else if (property.type === 'shadow') {
357
410
  var shadow = shadowControl(ge, node, property.name, changed);
@@ -5,6 +5,7 @@
5
5
  * sections: { border: { properties: [...], catalog: false }, position: false, … },
6
6
  * spacing: { values, scale }, // the values offered, and what 0 to 5 come to
7
7
  * visibility: { drawer }, // false leaves the eye out of the drawers
8
+ * browse: function(done, ctx), // a file browser for the url fields: see fields.js
8
9
  * }
9
10
  *
10
11
  * Every section is on unless it is turned off.
@@ -49,10 +50,21 @@ function resolveSections(ge, given) {
49
50
  return resolved;
50
51
  }
51
52
 
53
+ /** The host's file browser, or null: anything but a function is ignored. */
54
+ function resolveBrowse(ge, given) {
55
+ if (given === undefined || given === null) { return null; }
56
+ if (typeof given === 'function') { return given; }
57
+
58
+ ge.warn('inline_style.browse must be a function: ignored');
59
+
60
+ return null;
61
+ }
62
+
52
63
  export function resolveOptions(ge) {
53
64
  var style = ge.settings.inline_style || {};
54
65
 
55
66
  return {
67
+ browse: resolveBrowse(ge, style.browse),
56
68
  sections: resolveSections(ge, style.sections),
57
69
  spacing: style.spacing,
58
70
  visibility: style.visibility,
@@ -188,6 +188,7 @@ GridEditor.locales.es = {
188
188
  'tool.delete_section': 'Quitar sección',
189
189
  'confirm.delete_section': '¿Seguro que quieres borrar esta sección y todo su contenido?',
190
190
  'tool.copy': 'Copiar',
191
+ 'tool.cut': 'Cortar',
191
192
  'tool.paste': 'Pegar',
192
193
  'clipboard.paste_row': 'Pegar fila',
193
194
  'clipboard.paste_section': 'Pegar sección',
@@ -265,6 +266,7 @@ GridEditor.locales.es = {
265
266
  'inline_style.overridden': 'La clase {class} tiene prioridad sobre este valor',
266
267
  'inline_style.invalid': 'Esta propiedad no acepta ese valor',
267
268
  'inline_style.catalog': 'Clases de Bootstrap',
269
+ 'inline_style.browse': 'Examinar…',
268
270
  'inline_style.shadow_x': 'X',
269
271
  'inline_style.shadow_y': 'Y',
270
272
  'inline_style.shadow_blur': 'Desenfoque',
@@ -15,11 +15,16 @@
15
15
  * pasted in another tab or another editor of the same site. A browser that
16
16
  * will not give the page its storage keeps it in memory, for this page only.
17
17
  *
18
+ * Cut is a copy and a removal in one: its tool in the same drawers, and Ctrl+X.
19
+ * It never asks, and is all or nothing: a before-delete that turns the
20
+ * removal away leaves the clipboard as it was. The target goes to what held
21
+ * the node, so a paste right after puts it back.
22
+ *
18
23
  * A paste is an add like any other - before-add-* and after-add-*, with
19
24
  * `source: 'paste'` - so a host can turn one away.
20
25
  *
21
- * With active_target (which the sidebar turns on), Ctrl+C copies the target
22
- * and Ctrl+V pastes into it, as the toolbar adds to it.
26
+ * With active_target (which the sidebar turns on), Ctrl+C copies the target,
27
+ * Ctrl+X cuts it and Ctrl+V pastes into it, as the toolbar adds to it.
23
28
  * `clipboard: { shortcuts: false }` turns them off. They go through the same
24
29
  * store as the tools, never the system clipboard.
25
30
  */
@@ -28,6 +33,7 @@ import * as dom from '../dom.js';
28
33
 
29
34
  Object.assign(GridEditor.locales.en, {
30
35
  'tool.copy': 'Copy',
36
+ 'tool.cut': 'Cut',
31
37
  'tool.paste': 'Paste',
32
38
  'clipboard.paste_row': 'Paste row',
33
39
  'clipboard.paste_section': 'Paste section',
@@ -102,12 +108,12 @@ function track(e) {
102
108
  document.addEventListener('pointerdown', track, true);
103
109
  document.addEventListener('focusin', track, true);
104
110
 
105
- /** 'c', 'v' or null, from the letter typed or, on a layout without Latin letters, the key's place. */
111
+ /** 'c', 'x', 'v' or null, from the letter typed or, on a layout without Latin letters, the key's place. */
106
112
  function shortcutKey(e) {
107
113
  var key = (e.key || '').toLowerCase();
108
- if (!/^[a-z]$/.test(key)) { key = { KeyC: 'c', KeyV: 'v' }[e.code] || ''; }
114
+ if (!/^[a-z]$/.test(key)) { key = { KeyC: 'c', KeyX: 'x', KeyV: 'v' }[e.code] || ''; }
109
115
 
110
- return key === 'c' || key === 'v' ? key : null;
116
+ return key === 'c' || key === 'x' || key === 'v' ? key : null;
111
117
  }
112
118
 
113
119
  function typing() {
@@ -162,18 +168,21 @@ GridEditor.features.clipboard = function(ge) {
162
168
  }
163
169
  if (wanted === undefined) { return target; }
164
170
  if (wanted && !target) {
165
- ge.warn('clipboard.shortcuts needs active_target, or settings_panel "sidebar": without it, Ctrl+C and Ctrl+V do nothing');
171
+ ge.warn('clipboard.shortcuts needs active_target, or settings_panel "sidebar": without it, Ctrl+C, Ctrl+X and Ctrl+V do nothing');
166
172
  return false;
167
173
  }
168
174
 
169
175
  return wanted;
170
176
  }
171
177
 
172
- function copy(node, kind, source) {
173
- var html = ge.nodeHtml(node);
178
+ /** What is copied, kept, and said: by a copy, or by a cut on its way to removing the node. */
179
+ function keep(node, kind, source, removing) {
180
+ write({ version: VERSION, category: categoryOf(kind), kind: kind, html: ge.nodeHtml(node) });
181
+ ge.emit('after-copy', ge.payloadFor(kind, node, { source: source || 'tool', cut: removing }));
182
+ }
174
183
 
175
- write({ version: VERSION, category: categoryOf(kind), kind: kind, html: html });
176
- ge.emit('after-copy', ge.payloadFor(kind, node, { source: source || 'tool' }));
184
+ function copy(node, kind, source) {
185
+ keep(node, kind, source, false);
177
186
 
178
187
  // The canvas came back with new drawers: the one to flash is the
179
188
  // node's new copy tool
@@ -189,6 +198,30 @@ GridEditor.features.clipboard = function(ge) {
189
198
  }, 1200);
190
199
  }
191
200
 
201
+ /**
202
+ * Copy the node and remove it, as its delete tool does but without the
203
+ * question: all or nothing, so a before-delete that turns it away leaves
204
+ * the clipboard as it was. The target, if it was this node or in it, goes
205
+ * to what held it before the node leaves, so a paste right after goes
206
+ * there.
207
+ */
208
+ function cut(node, kind, source) {
209
+ return ge.removeNode(node, {
210
+ source: 'cut',
211
+ confirm: false,
212
+ before: function() {
213
+ keep(node, kind, source, true);
214
+
215
+ var target = ge.getActiveTarget();
216
+ if (source !== 'tool' && !(target && node.contains(target))) { return; }
217
+
218
+ var parent = node.parentElement;
219
+ while (parent && parent !== ge.canvas && !ge.detailsOf(parent)) { parent = parent.parentElement; }
220
+ ge.setActiveTarget(parent && parent !== ge.canvas ? parent : null);
221
+ },
222
+ });
223
+ }
224
+
192
225
  function paste(target, categories) {
193
226
  var clip = read();
194
227
  if (!fits(clip, categories)) { return; }
@@ -223,13 +256,24 @@ GridEditor.features.clipboard = function(ge) {
223
256
  return true;
224
257
  }
225
258
 
259
+ function cutByShortcut() {
260
+ if (textSelected()) { return false; }
261
+
262
+ var node = ge.getActiveTarget();
263
+ var kind = node && ge.kindOf(node);
264
+ if (!kind || !categoryOf(kind)) { return false; }
265
+
266
+ return cut(node, kind, 'shortcut');
267
+ }
268
+
226
269
  function onKeydown(e) {
227
270
  if (lastEditor !== ge || e.repeat || e.shiftKey || e.altKey || !(e.ctrlKey || e.metaKey)) { return; }
228
271
  var key = shortcutKey(e);
229
272
  if (!key || !dom.hasClass(ge.canvas, 'ge-editing') || typing() || ge.panelOpen()) { return; }
230
273
 
231
274
  // Left alone, it is the browser's: a copy of the text, a paste in a field
232
- if (key === 'c' ? copyByShortcut() : pasteByShortcut()) { e.preventDefault(); }
275
+ var acted = { c: copyByShortcut, x: cutByShortcut, v: pasteByShortcut }[key]();
276
+ if (acted) { e.preventDefault(); }
233
277
  }
234
278
 
235
279
  function listenForShortcuts(on) {
@@ -285,6 +329,12 @@ GridEditor.features.clipboard = function(ge) {
285
329
  ge.createTool(drawer, ge.t('tool.copy'), 'ge-copy', 'bi bi-copy', function() {
286
330
  copy(node, kind);
287
331
  });
332
+ ge.createTool(drawer, ge.t('tool.cut'), 'ge-cut', 'bi bi-scissors', function(e) {
333
+ // The click that picks the node it is in would pick it as
334
+ // the target again, after it has gone to what held it
335
+ e.stopPropagation();
336
+ cut(node, kind, 'tool');
337
+ });
288
338
  }
289
339
 
290
340
  var categories = TARGETS[kind];
@@ -35,8 +35,8 @@ var DEFAULT_DELAY = 500;
35
35
  /** What the editor puts in a node that is not the node's own: a position counts without it. */
36
36
  var FURNITURE = '.ge-tools-drawer, .ge-drop-marker';
37
37
 
38
- /** What a drag or a resize leaves on the canvas while it lasts. */
39
- var BUSY = '.ge-drag-chosen, .ge-drag-placeholder, .ge-drag-helper, .ge-resizing';
38
+ /** What a drag, a resize or a node animating out leaves on the canvas while it lasts. */
39
+ var BUSY = '.ge-drag-chosen, .ge-drag-placeholder, .ge-drag-helper, .ge-resizing, .ge-leaving';
40
40
 
41
41
  /** The editors listening for the keys, and the one used last, which a key press goes to. */
42
42
  var listeningEditors = [];
@@ -133,7 +133,7 @@ GridEditor.features.history = function(ge) {
133
133
  return dom.hasClass(ge.canvas, 'ge-editing');
134
134
  }
135
135
 
136
- /** A drag or a resize is going on: the canvas is not at a step but between two. */
136
+ /** A drag, a resize or a removal is going on: the canvas is not at a step but between two. */
137
137
  function busy() {
138
138
  return dom.hasClass(ge.canvas, 'ge-dropping') || !!dom.one(ge.canvas, BUSY);
139
139
  }
@@ -23,6 +23,8 @@
23
23
  * inline_style.sections chooses the sections, and in each the properties and
24
24
  * whether it has a catalog; inline_style.spacing is the options of spacing, whose
25
25
  * scale the gaps share, and inline_style.visibility those of the eye.
26
+ * inline_style.browse is the host's file browser: with it, a url field - the
27
+ * background image - has a button that opens it, and takes the url it gives.
26
28
  */
27
29
  import { GridEditor } from '../grideditor.js';
28
30
  import { spacingPart } from '../inline-style/spacing.js';
@@ -52,6 +54,7 @@ Object.assign(GridEditor.locales.en, {
52
54
  'inline_style.overridden': 'The class {class} takes priority over this value',
53
55
  'inline_style.invalid': 'Not a value this property takes',
54
56
  'inline_style.catalog': 'Bootstrap classes',
57
+ 'inline_style.browse': 'Browse…',
55
58
  'inline_style.shadow_x': 'X',
56
59
  'inline_style.shadow_y': 'Y',
57
60
  'inline_style.shadow_blur': 'Blur',
@@ -127,6 +130,8 @@ GridEditor.utilities['inline-style'] = function(ge) {
127
130
  sections: options.sections,
128
131
  parts: parts,
129
132
  state: { open: null },
133
+ browse: options.browse,
134
+ destroyed: false,
130
135
  opened: function(key) {
131
136
  accordions.forEach(function(entry) { entry.accordion.open(key); });
132
137
  },
@@ -178,6 +183,11 @@ GridEditor.utilities['inline-style'] = function(ge) {
178
183
 
179
184
  drawerTools: each('drawerTools'),
180
185
 
186
+ // An answer from the host's browser can come after the editor is gone
187
+ onDestroy: function() {
188
+ context.destroyed = true;
189
+ },
190
+
181
191
  onDeinit: function() {
182
192
  each('onDeinit')();
183
193
  accordions = [];
@@ -15,7 +15,7 @@
15
15
  *
16
16
  * Each editor registers under GridEditor.texts, which is this file's own
17
17
  * registry and not a contract: an editor of a host's own is a feature plugin
18
- * of its own, as example/custom_editor.html shows.
18
+ * of its own, as example/text-editors.html shows.
19
19
  */
20
20
  import { GridEditor } from '../grideditor.js';
21
21
  import * as dom from '../dom.js';
@@ -109,31 +109,54 @@
109
109
  }
110
110
  }
111
111
 
112
+ /* As wide as its buttons, so the more button comes right after them;
113
+ the room left over pushes the right-hand buttons to the end, from
114
+ the line or, while it shows, from the more button */
112
115
  .ge-toolbar-start {
113
116
  display: flex;
114
- flex: 1 1 auto;
117
+ flex: 0 1 auto;
115
118
  min-width: 0;
119
+ margin-right: auto;
116
120
  overflow: hidden;
117
121
 
118
122
  /* A group as wide as its buttons and a button as wide as its label:
119
123
  squeezed, they would wrap their labels rather than overflow */
120
124
  > .btn-group {
121
125
  flex: none;
126
+
127
+ /* All its buttons behind the more button: no margin left over */
128
+ &:empty {
129
+ display: none;
130
+ }
122
131
  }
123
132
  .btn {
124
133
  white-space: nowrap;
125
134
  }
135
+ .btn.ge-before-more {
136
+ border-top-right-radius: 0;
137
+ border-bottom-right-radius: 0;
138
+ }
139
+ }
140
+ .ge-toolbar-overflowing > .ge-toolbar-start {
141
+ margin-right: 0;
126
142
  }
127
143
 
128
144
  .ge-toolbar-more {
129
145
  display: none;
130
146
  position: relative;
131
147
  flex: none;
132
- margin: 0 5px 0 4px;
148
+ margin: 0 auto 0 -1px;
149
+ padding-right: 5px;
133
150
 
134
151
  &.ge-needed {
135
152
  display: block;
136
153
  }
154
+
155
+ /* Joined to the last button on the line, as in a btn-group */
156
+ > .btn {
157
+ border-top-left-radius: 0;
158
+ border-bottom-left-radius: 0;
159
+ }
137
160
  }
138
161
 
139
162
  .ge-toolbar-overflow {
@@ -141,7 +164,7 @@
141
164
  position: absolute;
142
165
  z-index: 30;
143
166
  top: ~"calc(100% + 4px)";
144
- right: 0;
167
+ right: 5px;
145
168
  flex-direction: column;
146
169
  gap: 6px;
147
170
  width: max-content;
@@ -140,6 +140,24 @@ export interface CreateOffcanvasOptions extends Placement, OffcanvasOptions {
140
140
  trigger_label?: string;
141
141
  }
142
142
 
143
+ /** What a file browser is told about the field it was opened from. */
144
+ export interface InlineStyleBrowseContext {
145
+ node: HTMLElement;
146
+ property: string;
147
+ /** What the field shows: the url, or the value as it is when it is not one. */
148
+ value: string;
149
+ }
150
+
151
+ /**
152
+ * The host's file browser. It answers with `done(url)`, or with a promise of
153
+ * the url: the first answer counts. Nothing, `null` or an empty text leaves
154
+ * the field as it was.
155
+ */
156
+ export type InlineStyleBrowse = (
157
+ done: (url?: string | null) => void,
158
+ context: InlineStyleBrowseContext,
159
+ ) => void | Promise<string | null | undefined>;
160
+
143
161
  /** The inline-style plugin's settings. */
144
162
  export interface InlineStyleOptions {
145
163
  /** Every section is on unless it is turned off here. */
@@ -148,6 +166,8 @@ export interface InlineStyleOptions {
148
166
  spacing?: { values?: string[]; scale?: string[] };
149
167
  /** The eye that hides and shows a node, the display family's: false leaves it out of the drawers. */
150
168
  visibility?: { drawer?: boolean };
169
+ /** A file browser for the url fields: with it they have a button that opens it. */
170
+ browse?: InlineStyleBrowse;
151
171
  }
152
172
 
153
173
  /** What the sidebar shows while nothing is selected, instead of its message. */
@@ -331,11 +351,16 @@ export interface Payload {
331
351
  parent: HTMLElement | null;
332
352
  canvas: HTMLElement;
333
353
  breakpoint: View;
334
- source: 'api' | 'tool' | 'dragdrop' | 'paste' | 'panel' | 'shortcut' | string;
354
+ source: 'api' | 'tool' | 'dragdrop' | 'paste' | 'cut' | 'panel' | 'shortcut' | string;
335
355
  /** A pane inside a container. */
336
356
  container?: HTMLElement;
337
357
  }
338
358
 
359
+ /** A node was copied, or cut: with the clipboard plugin, `source` is 'tool' or 'shortcut', and `cut` says whether the node is leaving. */
360
+ export interface CopyPayload extends Payload {
361
+ cut: boolean;
362
+ }
363
+
339
364
  export interface MovePayload extends Payload {
340
365
  from: Position;
341
366
  to?: Position;
@@ -438,7 +463,7 @@ export interface GridEditorEventMap {
438
463
  'grideditor:after-convert': ConvertPayload;
439
464
  'grideditor:before-edit-html': EditHtmlPayload;
440
465
  'grideditor:after-edit-html': EditHtmlPayload;
441
- 'grideditor:after-copy': Payload;
466
+ 'grideditor:after-copy': CopyPayload;
442
467
  'grideditor:popup-orphan': PopupOrphanPayload;
443
468
  'grideditor:offcanvas-orphan': OffcanvasOrphanPayload;
444
469
  'grideditor:view-change': ViewChangePayload;