@themarioga/grid-editor 9.2.2 → 9.2.4

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/docs/plugins.md CHANGED
@@ -189,6 +189,7 @@ element, and where there may be several, an array.
189
189
  | `ge.nodeHtml(node)` | One node's markup as `getHtml` would give it. The canvas leaves editing to read it and comes back, as it does for `getHtml` |
190
190
  | `ge.snapshotHtml()` | The canvas's markup as `getHtml` gives it, read on a copy so the canvas never leaves editing: what `getHtml({ keepEditing: true })` is. See [Reading on a copy](#reading-on-a-copy) |
191
191
  | `ge.setHtml(html)` | The canvas made of other markup, and edited again: the source view closed if it is open, `deinit`, the markup in, `init`. No add or delete events: it is replaced as a whole. A `<script>` in it does not run in the editor |
192
+ | `ge.reinit()` | The canvas out of editing and back in - `deinit` then `init`, as `getHtml` does around its read - for a plugin that shows the same markup another way and wants it painted again. Does nothing with the source view open, and after `destroy` |
192
193
  | `ge.confirm(message, options, answer)` | A question in the editor's confirm modal, the one deleting asks in. `options`: `title`, `ok`, `cancel` - the texts, the locale's by default - and `danger`, a red ok button. `answer(true)` for ok, `answer(false)` for cancel, the close button or Escape, `answer(null)` when the modal is taken away unanswered: `setLocale`, `destroy`, or another question. The browser's `confirm` without Bootstrap's javascript |
193
194
  | `ge.refreshToolbar()` | The toolbar built again, from what the feature plugins' `toolbar`s hold now: for a plugin whose buttons come and go. The category shown with `toolbar_groups`, the preview and the source view stay as they are. Does nothing before the toolbar is first built, and after `destroy` |
194
195
  | `ge.getActiveTarget()` | The node the toolbar adds to and the sidebar shows - any node with settings - as the public method gives it: `null` without `active_target` |
@@ -222,6 +223,7 @@ GridEditor.features.elements = function(ge) {
222
223
  onDeinit: function() { … }, // every deinit: take it out again
223
224
  onBeforeDeinit: function() { … }, // every deinit, before the drawers come off: close what you opened
224
225
  cleanMarkup: function(root, liveOf) { … }, // what onDeinit and onBeforeDeinit take off, off a copy
226
+ plainMarkup: function(root, options) { … }, // the markup getPlainHtml is about to clean, to change first
225
227
  onDestroy: function() { … }, // destroy, first, while the editor is whole
226
228
  onSourceOpen: function(textarea) { … }, // the source view opened: the canvas's html is in the textarea
227
229
  onSourceClose: function(textarea) { … }, // and is closing: put what you edited back in the textarea
@@ -465,6 +467,17 @@ rather than remembering anything about it.
465
467
  goes over the textarea on open and puts its value back in it on close, which
466
468
  is all the codemirror plugin does; `destroy` with the source open closes it
467
469
  first.
470
+ - **`plainMarkup(root, options)`** is called by `getPlainHtml(options)`, for
471
+ every kind of plugin in the order `deinit` calls them, with the markup
472
+ `getHtml` read, parsed in a document of its own that does not run scripts
473
+ or load images, and still carrying grid-editor's marking: the `data-ge-*`
474
+ attributes and `ge-*` classes come off after every plugin has had its turn.
475
+ Change `root` as the published page should be. `options` is what
476
+ `getPlainHtml` was given, which a plugin may read its own keys from. Return
477
+ `false` to make `getPlainHtml` answer `null` - for a request the plugin
478
+ cannot serve - and the plugins after it are not called. An error it throws
479
+ reaches the caller of `getPlainHtml`. Not called for the jQuery adapter's
480
+ html that is not on a canvas, nor after `destroy`.
468
481
  - **`plainTools(drawer, block)`** puts tools in the drawer of the host's plain
469
482
  content, between move and delete. That drawer has no gear, so
470
483
  `drawerTools` never runs for it: plain content gets no utility, no copy and
package/package.json CHANGED
@@ -32,7 +32,7 @@
32
32
  "publishConfig": {
33
33
  "access": "public"
34
34
  },
35
- "version": "9.2.2",
35
+ "version": "9.2.4",
36
36
  "main": "dist/grideditor.js",
37
37
  "module": "dist/grideditor.esm.js",
38
38
  "types": "dist/grideditor.d.ts",
@@ -294,12 +294,16 @@ function modalLibrary() {
294
294
  *
295
295
  * The marking is what lets the editor read its markup back, so this is for
296
296
  * publishing, not for saving something to edit again.
297
+ *
298
+ * `prepare(root)` sees the markup in the inert document before the marking
299
+ * comes off, and can change it; false from it gives null instead of the html.
297
300
  */
298
- function plainHtml(html) {
301
+ function plainHtml(html, prepare) {
299
302
  // Parsed in a document of its own, which is inert: no script in the
300
303
  // markup runs and no image starts loading while it is being cleaned
301
304
  var root = document.implementation.createHTMLDocument('').body;
302
305
  root.innerHTML = html;
306
+ if (prepare && prepare(root) === false) { return null; }
303
307
  var emptied = [];
304
308
 
305
309
  dom.all(root, '*').forEach(function(node) {
@@ -2668,9 +2672,15 @@ function build(instance, baseElem, optionsOrMethod) {
2668
2672
  return html;
2669
2673
  }
2670
2674
 
2671
- /** getHtml with grid-editor's own classes and attributes taken off. */
2675
+ /**
2676
+ * getHtml with grid-editor's own classes and attributes taken off.
2677
+ * A plugin's plainMarkup(root, options) may change the markup first,
2678
+ * while the marking is still on it; false from one makes this null.
2679
+ */
2672
2680
  function getPlainHtml(options) {
2673
- return plainHtml(getHtml(options));
2681
+ return plainHtml(getHtml(options), function(root) {
2682
+ return pluginsAccept('plainMarkup', root, options);
2683
+ });
2674
2684
  }
2675
2685
 
2676
2686
  /**
@@ -2795,6 +2805,18 @@ function build(instance, baseElem, optionsOrMethod) {
2795
2805
  });
2796
2806
  }
2797
2807
 
2808
+ /**
2809
+ * plugins(), for a hook that can refuse: false as soon as one says
2810
+ * false, the rest not asked.
2811
+ */
2812
+ function pluginsAccept(hook, argument, extra) {
2813
+ return [CONTAINERS, FEATURES, UTILITIES].every(function(registry) {
2814
+ return Object.keys(registry).every(function(name) {
2815
+ return !registry[name][hook] || registry[name][hook](argument, extra) !== false;
2816
+ });
2817
+ });
2818
+ }
2819
+
2798
2820
  /** What a plugin is handed. See docs/plugins.md. */
2799
2821
  function pluginApi() {
2800
2822
  return {
@@ -2844,6 +2866,14 @@ function build(instance, baseElem, optionsOrMethod) {
2844
2866
  // The markup as getHtml gives it, with the canvas left editing
2845
2867
  snapshotHtml: snapshotHtml,
2846
2868
  setHtml: setHtml,
2869
+ // The canvas out of editing and back in, as getHtml does it,
2870
+ // for a plugin that shows the same markup another way. Not
2871
+ // with the source view open, or after destroy
2872
+ reinit: function() {
2873
+ if (sourceOpen || destroyed) { return; }
2874
+ deinit();
2875
+ init();
2876
+ },
2847
2877
  // A question in the editor's confirm modal
2848
2878
  confirm: confirmWith,
2849
2879
  // A text editor has rewritten a content area, so whatever the
@@ -41,7 +41,7 @@ export function drawerflowPart(ge) {
41
41
  var node = '.ge-canvas.ge-editing [' + OUT_ATTR + '="' + room + '"]';
42
42
  sheet.appendChild(document.createTextNode(
43
43
  node + ' { border-top-width: ' + room + 'px !important; }\n' +
44
- node + ' > .ge-tools-drawer { top: -' + room + 'px; }\n'
44
+ node + ' > .ge-tools-drawer:not(.ge-code-inline) { top: -' + room + 'px; }\n'
45
45
  ));
46
46
  }
47
47
 
@@ -1555,7 +1555,9 @@ html.ge-sidebar-open {
1555
1555
  border-top-style: solid !important;
1556
1556
  border-top-color: transparent !important;
1557
1557
 
1558
- > .ge-tools-drawer {
1558
+ /* Not a block's html being edited, with the codemirror-inline plugin:
1559
+ a drawer only in name, it stands where the block was, in the flow */
1560
+ > .ge-tools-drawer:not(.ge-code-inline) {
1559
1561
  position: absolute;
1560
1562
  left: 0;
1561
1563
  right: 0;