@themarioga/grid-editor 5.3.1 → 6.0.0-beta.2

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 (51) hide show
  1. package/BUILDING.md +2 -4
  2. package/CHANGELOG.md +59 -0
  3. package/README.md +34 -8
  4. package/UPGRADING.md +57 -12
  5. package/dist/grideditor.css +179 -100
  6. package/dist/grideditor.min.css +1 -1
  7. package/dist/grideditor.min.css.map +1 -1
  8. package/dist/jquery.grideditor.bundle.min.js +2 -2
  9. package/dist/jquery.grideditor.js +490 -432
  10. package/dist/jquery.grideditor.min.js +1 -1
  11. package/dist/jquery.grideditor.min.js.map +1 -1
  12. package/dist/locales/grideditor.es.js +12 -0
  13. package/dist/locales/grideditor.es.min.js +1 -1
  14. package/dist/locales/grideditor.es.min.js.map +1 -1
  15. package/dist/plugins/grideditor.ckeditor.js +2 -1
  16. package/dist/plugins/grideditor.ckeditor.min.js.map +1 -1
  17. package/dist/plugins/grideditor.clipboard.js +1 -11
  18. package/dist/plugins/grideditor.clipboard.min.js +1 -1
  19. package/dist/plugins/grideditor.clipboard.min.js.map +1 -1
  20. package/dist/plugins/grideditor.elements.js +66 -38
  21. package/dist/plugins/grideditor.elements.min.js +1 -1
  22. package/dist/plugins/grideditor.elements.min.js.map +1 -1
  23. package/dist/plugins/grideditor.sections.js +2 -2
  24. package/dist/plugins/grideditor.sections.min.js +1 -1
  25. package/dist/plugins/grideditor.sections.min.js.map +1 -1
  26. package/dist/plugins/grideditor.spacing.js +1 -1
  27. package/dist/plugins/grideditor.spacing.min.js +1 -1
  28. package/dist/plugins/grideditor.spacing.min.js.map +1 -1
  29. package/dist/plugins/grideditor.summernote.js +2 -1
  30. package/dist/plugins/grideditor.summernote.min.js.map +1 -1
  31. package/dist/plugins/grideditor.tinymce.js +2 -1
  32. package/dist/plugins/grideditor.tinymce.min.js.map +1 -1
  33. package/docs/events.md +4 -3
  34. package/docs/locale-keys.md +23 -0
  35. package/docs/plugins.md +18 -20
  36. package/example/attributes.html +21 -37
  37. package/example/elements.html +25 -20
  38. package/example/plugins.html +5 -5
  39. package/example/utilities.html +31 -8
  40. package/package.json +1 -1
  41. package/src/js/jquery.grideditor.js +489 -34
  42. package/src/js/locales/grideditor.es.js +12 -0
  43. package/src/js/plugins/grideditor.ckeditor.js +2 -1
  44. package/src/js/plugins/grideditor.clipboard.js +1 -11
  45. package/src/js/plugins/grideditor.elements.js +66 -38
  46. package/src/js/plugins/grideditor.sections.js +2 -2
  47. package/src/js/plugins/grideditor.spacing.js +1 -1
  48. package/src/js/plugins/grideditor.summernote.js +2 -1
  49. package/src/js/plugins/grideditor.tinymce.js +2 -1
  50. package/src/less/grideditor.less +203 -112
  51. package/src/js/compat/bundled-texts.js +0 -14
package/docs/plugins.md CHANGED
@@ -107,7 +107,8 @@ not change without a major version.
107
107
  | `ge.defaultRegion()` | A row with one full width column: what an empty pane starts as |
108
108
  | `ge.createTool(drawer, title, className, iconClass, handlers)` | A tool in a drawer |
109
109
  | `ge.createMoveTool(drawer)` | The drag handle, unless `drag_handle` says the whole drawer is one |
110
- | `ge.addSettingsTool(drawer, node, presets)` | The gear, and the id and class panel it opens |
110
+ | `ge.addSettingsTool(drawer, node, presets)` | The gear, and the id and class panel it opens. Returns the panel, to add fields to |
111
+ | `ge.detailsOf(node)` | A node's settings panel, wherever it is: in its drawer, or open in the offcanvas, popover or modal `settings_panel` names, outside the canvas. Find a panel's fields through it, never through the drawer |
111
112
  | `ge.deleteNode(kind, node, confirmText, animate)` | Remove a node: ask, animate, announce |
112
113
  | `ge.place(node, kind, options)` | Put a created node where `appendTo` and friends say, through the add events. `options.source` is the payload's `source`, `api` by default |
113
114
  | `ge.createPaneControls(pane, kind, hostTools, confirmText, remove)` | The drawer a pane gets: move, the host's tools, delete |
@@ -149,7 +150,8 @@ $.fn.gridEditor.features.elements = function(ge) {
149
150
  kindOf: function(node) { … }, // what an event calls this node
150
151
  onInit: function() { … }, // every init: put the furniture in
151
152
  onDeinit: function() { … }, // every deinit: take it out again
152
- onContentReady: function(area) { … }, // a rich text editor just took over
153
+ onContentReady: function(area) { … }, // a rich text editor just took over, or rewrote a text
154
+ cuts: '[data-my-block]', // what cuts a text: a block of the column, never part of a text
153
155
  onSortable: function(sortable) { … }, // declare your own sortable lists
154
156
  blocks: '.ge-section', // more blocks the canvas and the columns move
155
157
  regions: '.ge-section', // more lists those blocks move in
@@ -167,6 +169,12 @@ needs to put a new kind of block on the canvas:
167
169
  rows, content areas and containers, the editor's own blocks.
168
170
  - **`regions`** is a selector for more lists those blocks move in, in the same
169
171
  group, so a row dragged from the canvas can land in one.
172
+ - **`cuts`** is a selector, or a function returning one, for nodes that are
173
+ never part of a text: blocks of the column. The editor cuts a content area
174
+ at each of its own children that matches - the text before it stays, the
175
+ node goes into the column, the text after goes into a new content area -
176
+ which is how the elements plugin takes 5.x's elements out of their text. Rows
177
+ and containers always cut.
170
178
  - **`accepts(region, node)`** can turn a block away from a list: `false` and the
171
179
  drag will not drop it there, whoever's block and whoever's list. With none of
172
180
  these hooks, every block goes everywhere, as before.
@@ -194,21 +202,12 @@ animation for rows, columns, containers and elements, kept in a
194
202
  takes off. `getHtml` keeps every attribute that is not the editor's.
195
203
  - **The dialog lives outside the canvas**, appended to `body`, so it is never
196
204
  part of the markup.
197
- - **An element sits inside text a rich text editor may be editing.** Written
198
- behind its back, the attribute is lost the next time the user undoes
199
- something: undo restores a snapshot from before it. With tinyMCE, write it
200
- through the editor's undo manager, and it becomes a step of its own:
201
-
202
- ```javascript
203
- var area = node.closest('.ge-content')[0];
204
- var editor = window.tinymce && tinymce.get().filter(function(e) { return e.getBody() === area; })[0];
205
- var apply = function() { node.attr('data-animation', JSON.stringify(value)); };
206
-
207
- if (editor) { editor.undoManager.transact(apply); } else { apply(); }
208
- ```
209
-
210
- Rows, columns, sections and containers are outside any content area, and a
211
- plain `attr()` is all they need.
205
+ - **Nothing else.** A plain `attr()` on any node. An element is never inside a
206
+ text editor since 6.0, and a text's own attributes, given while its editor
207
+ is open, are kept by grid-editor when the editor closes - tinyMCE would put
208
+ back the ones it found when it opened. Up to 5.x an element sat inside the
209
+ text, and an attribute written behind the editor's back was lost to its
210
+ undo.
212
211
 
213
212
  A node's drawer is built again on every `init`, so a tool reads the node
214
213
  rather than remembering anything about it.
@@ -298,9 +297,8 @@ $.fn.gridEditor.texts.mytext = function(ge) {
298
297
  A text editor is chosen by `content_types`, never by the `plugins` setting: a
299
298
  page that names its containers there has named no editor.
300
299
 
301
- Up to 6.0 the main bundle carries a copy of the three shipped ones, marked
302
- `bundled`; editing with a copy warns once that 6.0 leaves them out. A plugin's
303
- own file, loaded after, registers itself again and is the one used.
300
+ Up to 5.x the main bundle carried a copy of the three shipped ones; since 6.0
301
+ a page loads the plugin of the editor it uses, as it loads any other.
304
302
 
305
303
  5.x's `$.fn.gridEditor.RTEs.mytext = { init, deinit, initialContent }` still
306
304
  works: `init(settings, contentAreas)` and `deinit(settings, contentAreas)` are
@@ -69,40 +69,19 @@
69
69
  }
70
70
 
71
71
  /**
72
- * An element lives inside a content area, and while a rich
73
- * text editor is open there, a change it does not know about
74
- * is one its undo would take back: undoing the next thing the
75
- * user types restores a snapshot from before the attribute.
76
- * Made through tinyMCE's undo manager, it is a step of its
77
- * own, which undo and redo treat like any other.
72
+ * A plain attr() on any node: an element is never inside a
73
+ * text editor since 6.0, and a text's own attributes, given
74
+ * while its editor is open, are kept by grid-editor when the
75
+ * editor closes.
78
76
  */
79
77
  function write(node, value) {
80
- var apply = function() {
81
- if (value) {
82
- node.attr(ATTRIBUTE, JSON.stringify(value));
83
- } else {
84
- node.removeAttr(ATTRIBUTE);
85
- }
86
- };
87
- var editor = editorAround(node);
88
-
89
- if (editor) {
90
- editor.undoManager.transact(apply);
78
+ if (value) {
79
+ node.attr(ATTRIBUTE, JSON.stringify(value));
91
80
  } else {
92
- apply();
81
+ node.removeAttr(ATTRIBUTE);
93
82
  }
94
83
  }
95
84
 
96
- /** The tinyMCE editor open on the content area around node, if there is one. */
97
- function editorAround(node) {
98
- var area = node.closest('.ge-content');
99
- if (!area.length || !window.tinymce) { return null; }
100
-
101
- return window.tinymce.get().filter(function(editor) {
102
- return editor.getBody && editor.getBody() === area[0];
103
- })[0] || null;
104
- }
105
-
106
85
  /** Built once, outside the canvas, so it is never part of getHtml. */
107
86
  function dialog() {
108
87
  if (modal) { return modal; }
@@ -297,12 +276,13 @@
297
276
  an animation has its tool highlighted.
298
277
  </p>
299
278
  <p class="form-text">
300
- The quote is an element, inside text tinyMCE edits. Open the
301
- editor there, set an animation on the quote, keep typing
302
- and press <kbd>Ctrl</kbd>+<kbd>Z</kbd>: the text goes, the
303
- animation stays, because the plugin wrote it through
304
- tinyMCE&rsquo;s undo manager. Written behind its back,
305
- undoing the typing would undo the attribute with it.
279
+ Open tinyMCE on a text and set an animation on that same
280
+ text, from its drawer, while you are typing: the attribute
281
+ is kept when the editor closes, although tinyMCE puts back
282
+ the attributes it found when it opened. The plugin does
283
+ nothing special for that - a plain <code>attr()</code> -
284
+ and nothing special for the quote either, which is an
285
+ element: a block beside the texts, never inside one.
306
286
  </p>
307
287
  <p class="form-text">
308
288
  <em>Open as a published page</em> puts the plain html in a
@@ -325,11 +305,15 @@
325
305
  </div>
326
306
  <div class="row">
327
307
  <div class="col-lg-6">
328
- <p>Ordinary text, edited by tinyMCE.</p>
308
+ <div class="ge-content" data-ge-content-type="tinymce">
309
+ <p>Ordinary text, edited by tinyMCE.</p>
310
+ </div>
329
311
  <blockquote class="blockquote" data-ge-element="quote" data-ge-label="Quote">
330
- <p>An element: give it an animation while you edit the text around it.</p>
312
+ <p>An element, beside the texts: give it an animation.</p>
331
313
  </blockquote>
332
- <p>More text, after the element.</p>
314
+ <div class="ge-content" data-ge-content-type="tinymce">
315
+ <p>More text, after the element.</p>
316
+ </div>
333
317
  </div>
334
318
  <div class="col-lg-6">
335
319
  <div data-ge-container="card">
@@ -49,8 +49,8 @@
49
49
  selector: '[data-ge-element]',
50
50
 
51
51
  // Turn this on for a page that configures no rich text
52
- // editor and injects its own markup: every child of a
53
- // content area is then an element.
52
+ // editor and injects its own markup: every loose node of
53
+ // a column is then an element.
54
54
  auto: false,
55
55
  },
56
56
 
@@ -74,11 +74,11 @@
74
74
  // own save step. Grid editor needs no feature for this - the
75
75
  // element level controls already apply (spec 4.4).
76
76
  $('#addTag').on('click', function() {
77
- var contentArea = $('#myGrid .ge-content').first();
77
+ var column = $('#myGrid .column').first();
78
78
 
79
79
  $('#myGrid').gridEditor('createElement',
80
80
  '<span class="my-app-tag-placeholder">Analytics tag</span>',
81
- { type: 'analytics-tag', label: 'Analytics', appendTo: contentArea }
81
+ { type: 'analytics-tag', label: 'Analytics', appendTo: column }
82
82
  );
83
83
  });
84
84
 
@@ -103,17 +103,20 @@
103
103
  <div class="col-lg-8">
104
104
  <h1 class="h4">Element level controls</h1>
105
105
  <p class="form-text">
106
- An element is a node inside a content area that the editor
107
- treats as one movable, deletable thing instead of as rich
108
- text. The host marks them with
109
- <code>data-ge-element</code>, optionally naming them with
110
- <code>data-ge-label</code>. Each one gets a drawer of its
111
- own: move, an info tool, the host's own tools, and delete.
112
- They drag between content areas as well as within one.
106
+ An element is a node the editor treats as one movable,
107
+ deletable block instead of as rich text: a block of the
108
+ column, beside its texts, its rows and its containers. The
109
+ host marks them with <code>data-ge-element</code>,
110
+ optionally naming them with <code>data-ge-label</code>.
111
+ Each one gets a drawer of its own: move, an info tool, the
112
+ host's own tools, and delete. They drag within a column and
113
+ between columns.
113
114
  </p>
114
115
  <p class="form-text">
115
- Click the text around an element to edit it as text; the
116
- element itself stays atomic while the editor is open.
116
+ Click a text to edit it; an element is never part of the
117
+ text an editor edits. Markup that 5.x saved, with elements
118
+ inside a content area's text, still loads: they come out of
119
+ it, into the column.
117
120
  </p>
118
121
  <button class="btn btn-sm btn-secondary" id="addTag" type="button">Add an analytics tag</button>
119
122
  <button class="btn btn-sm btn-secondary" id="output" type="button">Show the html this produces</button>
@@ -127,22 +130,24 @@
127
130
  <div class="col-lg-6">
128
131
  <div class="ge-content" data-ge-content-type="tinymce">
129
132
  <p>Ordinary text, edited in place by tinyMCE.</p>
133
+ </div>
130
134
 
131
- <blockquote class="my-app-quote" data-ge-element="quote" data-ge-label="Pull quote">
132
- <p>An element the host owns and styles.</p>
133
- </blockquote>
135
+ <blockquote class="my-app-quote" data-ge-element="quote" data-ge-label="Pull quote">
136
+ <p>An element the host owns and styles.</p>
137
+ </blockquote>
134
138
 
139
+ <div class="ge-content" data-ge-content-type="tinymce">
135
140
  <p>More ordinary text, after the element.</p>
136
141
  </div>
137
142
  </div>
138
143
  <div class="col-lg-6">
139
144
  <div class="ge-content" data-ge-content-type="tinymce">
140
- <p>A second content area. Drag an element's drawer from
145
+ <p>A second column. Drag an element's drawer from
141
146
  the left column into this one.</p>
147
+ </div>
142
148
 
143
- <div data-ge-element="figure" data-ge-label="Figure">
144
- <p><strong>Figure 1.</strong> Another element, of a different type.</p>
145
- </div>
149
+ <div data-ge-element="figure" data-ge-label="Figure">
150
+ <p><strong>Figure 1.</strong> Another element, of a different type.</p>
146
151
  </div>
147
152
  </div>
148
153
  </div>
@@ -180,12 +180,12 @@
180
180
  <div class="col-lg-12">
181
181
  <div class="ge-content">
182
182
  <p>Ordinary text in a content area.</p>
183
-
184
- <blockquote data-ge-element="quote" data-ge-label="Pull quote">
185
- <p>A node the host marked: an element when the elements plugin is on,
186
- ordinary markup when it is off.</p>
187
- </blockquote>
188
183
  </div>
184
+
185
+ <blockquote data-ge-element="quote" data-ge-label="Pull quote">
186
+ <p>A node the host marked: an element when the elements plugin is on,
187
+ ordinary markup - text - when it is off.</p>
188
+ </blockquote>
189
189
  </div>
190
190
  </div>
191
191
 
@@ -30,13 +30,27 @@
30
30
 
31
31
  <script>
32
32
  $(function() {
33
- $('#myGrid').gridEditor({
34
- new_row_layouts: [[12], [6,6], [4,4,4], [8,4]],
35
- content_types: [],
36
-
37
- // Utilities are edited per breakpoint, so this page starts in
38
- // one. Switch to "All sizes" to see the page as it will render.
39
- default_view: 'xs',
33
+ function start(panel) {
34
+ $('#myGrid').gridEditor({
35
+ new_row_layouts: [[12], [6,6], [4,4,4], [8,4]],
36
+ content_types: [],
37
+
38
+ // Utilities are edited per breakpoint, so this page starts in
39
+ // one. Switch to "All sizes" to see the page as it will render.
40
+ default_view: 'xs',
41
+
42
+ // Where a node's settings open: 'offcanvas', the default,
43
+ // 'popover', 'modal', or 'inline' in its drawer
44
+ settings_panel: panel,
45
+ });
46
+ }
47
+ start($('#panel').val());
48
+
49
+ // The same canvas, started again with its settings elsewhere
50
+ $('#panel').on('change', function() {
51
+ var html = $('#myGrid').gridEditor('getHtml');
52
+ $('#myGrid').gridEditor('destroy').html(html);
53
+ start(this.value);
40
54
  });
41
55
 
42
56
  // Every change to a utility is announced, like any other operation
@@ -75,6 +89,15 @@
75
89
  section with a field per utility, which says what the
76
90
  breakpoint inherits and from where.
77
91
  </p>
92
+ <div class="d-flex align-items-center gap-2 mb-3">
93
+ <label class="form-label mb-0" for="panel">A gear opens its settings in</label>
94
+ <select class="form-select form-select-sm w-auto" id="panel">
95
+ <option value="offcanvas">a side panel (offcanvas)</option>
96
+ <option value="popover">a popover</option>
97
+ <option value="modal">a modal</option>
98
+ <option value="inline">the drawer itself (inline)</option>
99
+ </select>
100
+ </div>
78
101
  <p class="form-text">
79
102
  <strong>Visibility:</strong> the eye in a drawer hides the
80
103
  node in the view being edited. It stays on the canvas,
@@ -154,7 +177,7 @@
154
177
  <blockquote data-ge-element="quote" data-ge-label="Pull quote" class="float-sm-end ms-sm-3 p-3 border-start border-4">
155
178
  A floated element, <code>float-sm-end</code>.
156
179
  </blockquote>
157
- <p>The text of the content area flows round the quote from tablet up, and runs under it on phones, where it does not float. Switch between Phone and Tablet in the dropdown to see it move, or choose another float in the element's panel.</p>
180
+ <p>The text after it flows round the quote from tablet up, and runs under it on phones, where it does not float. Switch between Phone and Tablet in the dropdown to see it move, or choose another float in the element's panel.</p>
158
181
  <p>A second paragraph, so there is enough text to flow.</p>
159
182
  </div>
160
183
  </div>
package/package.json CHANGED
@@ -34,7 +34,7 @@
34
34
  "comment": "A scoped package publishes restricted unless it is told otherwise.",
35
35
  "access": "public"
36
36
  },
37
- "version": "5.3.1",
37
+ "version": "6.0.0-beta.2",
38
38
  "main": "dist/jquery.grideditor.js",
39
39
  "files": [
40
40
  "dist",