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

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 (73) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +25 -12
  3. package/dist/grideditor.bundle.min.js +2 -2
  4. package/dist/grideditor.d.ts +7 -2
  5. package/dist/grideditor.esm.js +55 -7
  6. package/dist/grideditor.js +55 -7
  7. package/dist/grideditor.min.js +1 -1
  8. package/dist/grideditor.min.js.map +3 -3
  9. package/dist/locales/grideditor.es.esm.js +1 -0
  10. package/dist/locales/grideditor.es.js +1 -0
  11. package/dist/locales/grideditor.es.min.js +1 -1
  12. package/dist/locales/grideditor.es.min.js.map +2 -2
  13. package/dist/plugins/grideditor.accordion.esm.js +9 -0
  14. package/dist/plugins/grideditor.accordion.js +9 -0
  15. package/dist/plugins/grideditor.accordion.min.js +1 -1
  16. package/dist/plugins/grideditor.accordion.min.js.map +3 -3
  17. package/dist/plugins/grideditor.card.min.js +1 -1
  18. package/dist/plugins/grideditor.card.min.js.map +1 -1
  19. package/dist/plugins/grideditor.carousel.esm.js +3 -0
  20. package/dist/plugins/grideditor.carousel.js +3 -0
  21. package/dist/plugins/grideditor.carousel.min.js +1 -1
  22. package/dist/plugins/grideditor.carousel.min.js.map +3 -3
  23. package/dist/plugins/grideditor.ckeditor.esm.js +9 -0
  24. package/dist/plugins/grideditor.ckeditor.js +9 -0
  25. package/dist/plugins/grideditor.ckeditor.min.js +1 -1
  26. package/dist/plugins/grideditor.ckeditor.min.js.map +3 -3
  27. package/dist/plugins/grideditor.clipboard.esm.js +44 -7
  28. package/dist/plugins/grideditor.clipboard.js +44 -7
  29. package/dist/plugins/grideditor.clipboard.min.js +1 -1
  30. package/dist/plugins/grideditor.clipboard.min.js.map +3 -3
  31. package/dist/plugins/grideditor.codemirror-inline.min.js.map +1 -1
  32. package/dist/plugins/grideditor.codemirror.min.js.map +1 -1
  33. package/dist/plugins/grideditor.elements.esm.js +3 -0
  34. package/dist/plugins/grideditor.elements.js +3 -0
  35. package/dist/plugins/grideditor.elements.min.js +1 -1
  36. package/dist/plugins/grideditor.elements.min.js.map +3 -3
  37. package/dist/plugins/grideditor.gutters.min.js.map +1 -1
  38. package/dist/plugins/grideditor.history.esm.js +1 -1
  39. package/dist/plugins/grideditor.history.js +1 -1
  40. package/dist/plugins/grideditor.history.min.js +1 -1
  41. package/dist/plugins/grideditor.history.min.js.map +2 -2
  42. package/dist/plugins/grideditor.inline-style.min.js.map +1 -1
  43. package/dist/plugins/grideditor.offcanvas.min.js.map +1 -1
  44. package/dist/plugins/grideditor.order.min.js +1 -1
  45. package/dist/plugins/grideditor.order.min.js.map +1 -1
  46. package/dist/plugins/grideditor.popup.min.js.map +1 -1
  47. package/dist/plugins/grideditor.sections.esm.js +9 -0
  48. package/dist/plugins/grideditor.sections.js +9 -0
  49. package/dist/plugins/grideditor.sections.min.js +1 -1
  50. package/dist/plugins/grideditor.sections.min.js.map +3 -3
  51. package/dist/plugins/grideditor.summernote.esm.js +9 -0
  52. package/dist/plugins/grideditor.summernote.js +9 -0
  53. package/dist/plugins/grideditor.summernote.min.js +1 -1
  54. package/dist/plugins/grideditor.summernote.min.js.map +3 -3
  55. package/dist/plugins/grideditor.tabs.esm.js +3 -0
  56. package/dist/plugins/grideditor.tabs.js +3 -0
  57. package/dist/plugins/grideditor.tabs.min.js +1 -1
  58. package/dist/plugins/grideditor.tabs.min.js.map +3 -3
  59. package/dist/plugins/grideditor.tinymce.esm.js +9 -0
  60. package/dist/plugins/grideditor.tinymce.js +9 -0
  61. package/dist/plugins/grideditor.tinymce.min.js +1 -1
  62. package/dist/plugins/grideditor.tinymce.min.js.map +3 -3
  63. package/docs/events.md +6 -1
  64. package/docs/locale-keys.md +1 -0
  65. package/docs/plugins.md +2 -1
  66. package/example/clipboard.html +7 -4
  67. package/package.json +1 -1
  68. package/src/js/dom.js +6 -0
  69. package/src/js/grideditor.js +58 -6
  70. package/src/js/locales/grideditor.es.js +1 -0
  71. package/src/js/plugins/grideditor.clipboard.js +61 -11
  72. package/src/js/plugins/grideditor.history.js +3 -3
  73. package/types/grideditor.d.ts +7 -2
@@ -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
  }
@@ -331,11 +331,16 @@ export interface Payload {
331
331
  parent: HTMLElement | null;
332
332
  canvas: HTMLElement;
333
333
  breakpoint: View;
334
- source: 'api' | 'tool' | 'dragdrop' | 'paste' | 'panel' | 'shortcut' | string;
334
+ source: 'api' | 'tool' | 'dragdrop' | 'paste' | 'cut' | 'panel' | 'shortcut' | string;
335
335
  /** A pane inside a container. */
336
336
  container?: HTMLElement;
337
337
  }
338
338
 
339
+ /** A node was copied, or cut: with the clipboard plugin, `source` is 'tool' or 'shortcut', and `cut` says whether the node is leaving. */
340
+ export interface CopyPayload extends Payload {
341
+ cut: boolean;
342
+ }
343
+
339
344
  export interface MovePayload extends Payload {
340
345
  from: Position;
341
346
  to?: Position;
@@ -438,7 +443,7 @@ export interface GridEditorEventMap {
438
443
  'grideditor:after-convert': ConvertPayload;
439
444
  'grideditor:before-edit-html': EditHtmlPayload;
440
445
  'grideditor:after-edit-html': EditHtmlPayload;
441
- 'grideditor:after-copy': Payload;
446
+ 'grideditor:after-copy': CopyPayload;
442
447
  'grideditor:popup-orphan': PopupOrphanPayload;
443
448
  'grideditor:offcanvas-orphan': OffcanvasOrphanPayload;
444
449
  'grideditor:view-change': ViewChangePayload;