@themarioga/grid-editor 6.0.0 → 7.0.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 (147) hide show
  1. package/AUTO_SAVE.md +2 -2
  2. package/BUILDING.md +45 -29
  3. package/CHANGELOG.md +47 -0
  4. package/README.md +137 -85
  5. package/UPGRADING.md +119 -0
  6. package/dist/grideditor.bundle.min.js +14 -0
  7. package/dist/grideditor.d.ts +335 -0
  8. package/dist/grideditor.esm.js +3977 -0
  9. package/dist/grideditor.jquery.js +253 -0
  10. package/dist/grideditor.jquery.min.js +1 -0
  11. package/dist/grideditor.jquery.min.js.map +7 -0
  12. package/dist/grideditor.js +3983 -0
  13. package/dist/grideditor.min.js +6 -0
  14. package/dist/grideditor.min.js.map +7 -0
  15. package/dist/locales/grideditor.es.esm.js +158 -0
  16. package/dist/locales/grideditor.es.js +164 -168
  17. package/dist/locales/grideditor.es.min.js +6 -2
  18. package/dist/locales/grideditor.es.min.js.map +7 -1
  19. package/dist/plugins/grideditor.accordion.esm.js +294 -0
  20. package/dist/plugins/grideditor.accordion.js +286 -180
  21. package/dist/plugins/grideditor.accordion.min.js +1 -2
  22. package/dist/plugins/grideditor.accordion.min.js.map +7 -1
  23. package/dist/plugins/grideditor.alignment.esm.js +55 -0
  24. package/dist/plugins/grideditor.alignment.js +58 -77
  25. package/dist/plugins/grideditor.alignment.min.js +1 -2
  26. package/dist/plugins/grideditor.alignment.min.js.map +7 -1
  27. package/dist/plugins/grideditor.card.esm.js +73 -0
  28. package/dist/plugins/grideditor.card.js +74 -64
  29. package/dist/plugins/grideditor.card.min.js +1 -2
  30. package/dist/plugins/grideditor.card.min.js.map +7 -1
  31. package/dist/plugins/grideditor.ckeditor.esm.js +500 -0
  32. package/dist/plugins/grideditor.ckeditor.js +484 -449
  33. package/dist/plugins/grideditor.ckeditor.min.js +1 -2
  34. package/dist/plugins/grideditor.ckeditor.min.js.map +7 -1
  35. package/dist/plugins/grideditor.clipboard.esm.js +326 -0
  36. package/dist/plugins/grideditor.clipboard.js +298 -235
  37. package/dist/plugins/grideditor.clipboard.min.js +1 -2
  38. package/dist/plugins/grideditor.clipboard.min.js.map +7 -1
  39. package/dist/plugins/grideditor.codemirror-inline.esm.js +205 -0
  40. package/dist/plugins/grideditor.codemirror-inline.js +188 -168
  41. package/dist/plugins/grideditor.codemirror-inline.min.js +1 -2
  42. package/dist/plugins/grideditor.codemirror-inline.min.js.map +7 -1
  43. package/dist/plugins/grideditor.codemirror.esm.js +63 -0
  44. package/dist/plugins/grideditor.codemirror.js +60 -71
  45. package/dist/plugins/grideditor.codemirror.min.js +1 -2
  46. package/dist/plugins/grideditor.codemirror.min.js.map +7 -1
  47. package/dist/plugins/grideditor.elements.esm.js +271 -0
  48. package/dist/plugins/grideditor.elements.js +256 -149
  49. package/dist/plugins/grideditor.elements.min.js +1 -2
  50. package/dist/plugins/grideditor.elements.min.js.map +7 -1
  51. package/dist/plugins/grideditor.float.esm.js +34 -0
  52. package/dist/plugins/grideditor.float.js +37 -52
  53. package/dist/plugins/grideditor.float.min.js +1 -2
  54. package/dist/plugins/grideditor.float.min.js.map +7 -1
  55. package/dist/plugins/grideditor.gutters.esm.js +143 -0
  56. package/dist/plugins/grideditor.gutters.js +134 -131
  57. package/dist/plugins/grideditor.gutters.min.js +1 -2
  58. package/dist/plugins/grideditor.gutters.min.js.map +7 -1
  59. package/dist/plugins/grideditor.order.esm.js +189 -0
  60. package/dist/plugins/grideditor.order.js +170 -182
  61. package/dist/plugins/grideditor.order.min.js +1 -2
  62. package/dist/plugins/grideditor.order.min.js.map +7 -1
  63. package/dist/plugins/grideditor.popup.esm.js +187 -0
  64. package/dist/plugins/grideditor.popup.js +183 -134
  65. package/dist/plugins/grideditor.popup.min.js +1 -2
  66. package/dist/plugins/grideditor.popup.min.js.map +7 -1
  67. package/dist/plugins/grideditor.sections.esm.js +271 -0
  68. package/dist/plugins/grideditor.sections.js +250 -173
  69. package/dist/plugins/grideditor.sections.min.js +1 -2
  70. package/dist/plugins/grideditor.sections.min.js.map +7 -1
  71. package/dist/plugins/grideditor.spacing.esm.js +318 -0
  72. package/dist/plugins/grideditor.spacing.js +296 -272
  73. package/dist/plugins/grideditor.spacing.min.js +1 -2
  74. package/dist/plugins/grideditor.spacing.min.js.map +7 -1
  75. package/dist/plugins/grideditor.summernote.esm.js +509 -0
  76. package/dist/plugins/grideditor.summernote.js +493 -427
  77. package/dist/plugins/grideditor.summernote.min.js +1 -2
  78. package/dist/plugins/grideditor.summernote.min.js.map +7 -1
  79. package/dist/plugins/grideditor.tabs.esm.js +237 -0
  80. package/dist/plugins/grideditor.tabs.js +233 -139
  81. package/dist/plugins/grideditor.tabs.min.js +1 -2
  82. package/dist/plugins/grideditor.tabs.min.js.map +7 -1
  83. package/dist/plugins/grideditor.textalign.esm.js +40 -0
  84. package/dist/plugins/grideditor.textalign.js +43 -56
  85. package/dist/plugins/grideditor.textalign.min.js +1 -2
  86. package/dist/plugins/grideditor.textalign.min.js.map +7 -1
  87. package/dist/plugins/grideditor.tinymce.esm.js +519 -0
  88. package/dist/plugins/grideditor.tinymce.js +502 -490
  89. package/dist/plugins/grideditor.tinymce.min.js +1 -2
  90. package/dist/plugins/grideditor.tinymce.min.js.map +7 -1
  91. package/dist/plugins/grideditor.visibility.esm.js +158 -0
  92. package/dist/plugins/grideditor.visibility.js +140 -149
  93. package/dist/plugins/grideditor.visibility.min.js +1 -2
  94. package/dist/plugins/grideditor.visibility.min.js.map +7 -1
  95. package/docs/events.md +47 -21
  96. package/docs/locale-keys.md +6 -0
  97. package/docs/plugins.md +47 -25
  98. package/example/adapter.html +112 -0
  99. package/example/attributes.html +85 -61
  100. package/example/autocols.html +9 -9
  101. package/example/autosave.html +13 -14
  102. package/example/basic.html +4 -5
  103. package/example/breakpoints.html +5 -6
  104. package/example/ckeditor.html +4 -5
  105. package/example/clipboard.html +11 -10
  106. package/example/codemirror.html +9 -7
  107. package/example/containers.html +7 -8
  108. package/example/custom_editor.html +53 -34
  109. package/example/elements.html +10 -11
  110. package/example/index.html +16 -2
  111. package/example/locale.html +6 -7
  112. package/example/plugins.html +44 -29
  113. package/example/summernote.html +6 -5
  114. package/example/utilities.html +17 -13
  115. package/example/wrap_content.html +9 -9
  116. package/package.json +43 -12
  117. package/src/js/dom.js +401 -0
  118. package/src/js/grideditor.classic.js +16 -0
  119. package/src/js/grideditor.jquery.js +325 -0
  120. package/src/js/{jquery.grideditor.js → grideditor.js} +1284 -1124
  121. package/src/js/locales/grideditor.es.js +163 -156
  122. package/src/js/plugins/grideditor.accordion.js +97 -77
  123. package/src/js/plugins/grideditor.alignment.js +5 -7
  124. package/src/js/plugins/grideditor.card.js +23 -23
  125. package/src/js/plugins/grideditor.ckeditor.js +107 -106
  126. package/src/js/plugins/grideditor.clipboard.js +49 -37
  127. package/src/js/plugins/grideditor.codemirror-inline.js +50 -37
  128. package/src/js/plugins/grideditor.codemirror.js +9 -10
  129. package/src/js/plugins/grideditor.elements.js +57 -33
  130. package/src/js/plugins/grideditor.float.js +4 -6
  131. package/src/js/plugins/grideditor.gutters.js +20 -15
  132. package/src/js/plugins/grideditor.order.js +28 -25
  133. package/src/js/plugins/grideditor.popup.js +63 -51
  134. package/src/js/plugins/grideditor.sections.js +39 -32
  135. package/src/js/plugins/grideditor.spacing.js +42 -45
  136. package/src/js/plugins/grideditor.summernote.js +112 -76
  137. package/src/js/plugins/grideditor.tabs.js +65 -57
  138. package/src/js/plugins/grideditor.textalign.js +4 -6
  139. package/src/js/plugins/grideditor.tinymce.js +147 -139
  140. package/src/js/plugins/grideditor.visibility.js +24 -25
  141. package/src/js/register.js +18 -0
  142. package/src/js/text/grideditor.text.js +77 -56
  143. package/types/grideditor.d.ts +335 -0
  144. package/dist/jquery.grideditor.bundle.min.js +0 -10
  145. package/dist/jquery.grideditor.js +0 -4927
  146. package/dist/jquery.grideditor.min.js +0 -2
  147. package/dist/jquery.grideditor.min.js.map +0 -1
package/README.md CHANGED
@@ -1,14 +1,12 @@
1
1
  Grid Editor
2
2
  ===========
3
3
 
4
- Grid Editor is a visual javascript editor for the [bootstrap 5 grid system](https://getbootstrap.com/docs/5.3/layout/grid/), written as a [jQuery](http://jquery.com/) plugin. You can create, drag, resize and delete rows and columns — sized in units, equal (`col`) or to their content (`col-auto`), or shared out by their row (`row-cols-*`) — indent them, group them in sections (`.container`), copy and paste them, and give each of bootstrap's six breakpoints its own layout — or edit them all at once, with a mouse or with a finger. Bootstrap's responsive utilities — visibility, order, alignment, gutters, spacing, text alignment and float — are edited per breakpoint too. It also edits tabs, accordions, popups and cards, and any markup you mark as an element, and it tells your application about every change it makes.
4
+ Grid Editor is a visual javascript editor for the [bootstrap 5 grid system](https://getbootstrap.com/docs/5.3/layout/grid/), in plain DOM: no jQuery needed. You can create, drag, resize and delete rows and columns — sized in units, equal (`col`) or to their content (`col-auto`), or shared out by their row (`row-cols-*`) — indent them, group them in sections (`.container`), copy and paste them, and give each of bootstrap's six breakpoints its own layout — or edit them all at once, with a mouse or with a finger. Bootstrap's responsive utilities — visibility, order, alignment, gutters, spacing, text alignment and float — are edited per breakpoint too. It also edits tabs, accordions, popups and cards, and any markup you mark as an element, and it tells your application about every change it makes.
5
5
 
6
6
  This is a fork of [Friendly-Pixel/grid-editor](https://github.com/Friendly-Pixel/grid-editor)
7
7
  by Simon Epskamp, carrying it on from 2.x. It is published as
8
8
  `@themarioga/grid-editor`.
9
9
 
10
- (Looking for the __bootstrap 3 support__? Use version 0 in the [bootstrap_3 branch](https://github.com/Friendly-Pixel/grid-editor/tree/bootstrap_3))
11
-
12
10
  It provides integration plugins for the following rich text editors to edit column content: TinyMCE, summernote and CKEditor.
13
11
 
14
12
  ![Preview](http://i.imgur.com/UF9CCzk.png)
@@ -39,13 +37,14 @@ from any web server, or from GitHub Pages, with no build step.
39
37
  | [example/clipboard.html](example/clipboard.html) | Copy and paste, within an editor, between two, and between tabs | [live](https://themarioga.github.io/grid-editor/example/clipboard.html) |
40
38
  | [example/wrap_content.html](example/wrap_content.html) | Non-bootstrap markup wrapped into the grid | [live](https://themarioga.github.io/grid-editor/example/wrap_content.html) |
41
39
  | [example/autosave.html](example/autosave.html) | Saving the html as the user edits | [live](https://themarioga.github.io/grid-editor/example/autosave.html) |
40
+ | [example/adapter.html](example/adapter.html) | A page written for 6.x, with jQuery, running unchanged through the adapter | [live](https://themarioga.github.io/grid-editor/example/adapter.html) |
42
41
 
43
42
  Installation
44
43
  ------------
45
44
 
46
- * __Dependencies:__ Grid Editor depends on jQuery, [SortableJS](https://sortablejs.github.io/Sortable/), Bootstrap Icons, and Bootstrap 5, so make sure you have included those in the page.
47
- * If you want to use the tinyMCE integration, include tinyMCE 6 as well, and `dist/plugins/grideditor.tinymce.min.js` after the editor. The tinyMCE jQuery plugin is no longer needed, and no longer exists as of tinyMCE 6.
48
- * If you want to use the summernote integration, include summernote and `dist/plugins/grideditor.summernote.min.js`.
45
+ * __Dependencies:__ Grid Editor depends on [SortableJS](https://sortablejs.github.io/Sortable/), Bootstrap Icons, and Bootstrap 5, so make sure you have included those in the page. It does not need jQuery since 7.0.
46
+ * If you want to use the tinyMCE integration, include tinyMCE 6 as well, and `dist/plugins/grideditor.tinymce.min.js` after the editor.
47
+ * If you want to use the summernote integration, include summernote and `dist/plugins/grideditor.summernote.min.js`. Summernote needs jQuery itself, so that page loads jQuery too; nothing else does.
49
48
  * If you want to use the CKEditor integration... you get the point: CKEditor and `dist/plugins/grideditor.ckeditor.min.js`.
50
49
  * Up to 5.x the main bundle carried a copy of the three; since 6.0 the plugin of the editor you use has to be loaded, as above. See [UPGRADING.md](UPGRADING.md).
51
50
  * From npm:
@@ -57,10 +56,10 @@ npm install @themarioga/grid-editor
57
56
  * Or [download the latest version of Grid Editor](https://github.com/themarioga/grid-editor/archive/master.zip) and include it in your page:
58
57
 
59
58
  ```html
60
- <!-- Make sure jQuery, SortableJS, bootstrap icons, and bootstrap 5 are included. TinyMCE is optional. -->
59
+ <!-- Make sure SortableJS, bootstrap icons, and bootstrap 5 are included. TinyMCE is optional. -->
61
60
  <link rel="stylesheet" type="text/css" href="grid-editor/dist/grideditor.min.css" />
62
61
  <script src="https://cdn.jsdelivr.net/npm/sortablejs@1.15.6/Sortable.min.js"></script>
63
- <script src="grid-editor/dist/jquery.grideditor.min.js"></script>
62
+ <script src="grid-editor/dist/grideditor.min.js"></script>
64
63
  <!-- The text editor you use, as a plugin -->
65
64
  <script src="grid-editor/dist/plugins/grideditor.tinymce.min.js"></script>
66
65
  ```
@@ -70,20 +69,64 @@ inside it &mdash; one or the other, never both:
70
69
 
71
70
  ```html
72
71
  <link rel="stylesheet" type="text/css" href="grid-editor/dist/grideditor.min.css" />
73
- <script src="grid-editor/dist/jquery.grideditor.bundle.min.js"></script>
72
+ <script src="grid-editor/dist/grideditor.bundle.min.js"></script>
73
+ ```
74
+
75
+ ### As an ES module
76
+
77
+ An app built with a bundler - Angular, React, Vue, Vite - imports the editor
78
+ and the plugins it wants. A plugin registers as it is imported:
79
+
80
+ ```javascript
81
+ import GridEditor from '@themarioga/grid-editor';
82
+ import '@themarioga/grid-editor/plugins/tabs';
83
+ import '@themarioga/grid-editor/plugins/tinymce';
84
+ import '@themarioga/grid-editor/locales/es';
85
+ import '@themarioga/grid-editor/css';
86
+ import Sortable from 'sortablejs';
87
+ import * as bootstrap from 'bootstrap';
88
+
89
+ // What a module app has as imports, not as window.Sortable and window.bootstrap
90
+ GridEditor.Sortable = Sortable;
91
+ GridEditor.bootstrap = bootstrap;
92
+
93
+ const ge = new GridEditor(element, { content_types: ['tinymce'] });
94
+ ```
95
+
96
+ The module build imports nothing itself. Without `GridEditor.Sortable` or a
97
+ `window.Sortable`, dragging is off; without Bootstrap's javascript, a delete is
98
+ confirmed with the browser's `confirm()` and the modal settings panel opens
99
+ with a backdrop of the editor's own. Types for the public API come with the
100
+ package (`dist/grideditor.d.ts`).
101
+
102
+ Load the classic script *or* the module build on a page, never both.
103
+
104
+ ### A page written for 6.x
105
+
106
+ A page that uses the jQuery API of 6.x - `$(el).gridEditor(...)`, jQuery
107
+ events, jQuery objects in the payloads - keeps it by loading jQuery 4 and the
108
+ adapter after the editor, and the 7.x plugins after that:
109
+
110
+ ```html
111
+ <script src="https://code.jquery.com/jquery-4.0.0.min.js"></script>
112
+ <script src="grid-editor/dist/grideditor.min.js"></script>
113
+ <script src="grid-editor/dist/grideditor.jquery.min.js"></script>
114
+ <script src="grid-editor/dist/plugins/grideditor.tabs.min.js"></script>
74
115
  ```
75
116
 
117
+ Plugins written for 6.x are not kept working: see [UPGRADING.md](UPGRADING.md).
118
+
76
119
  Usage
77
120
  -----
78
121
  ```javascript
79
- $('#myGrid').gridEditor({
122
+ var ge = new GridEditor('#myGrid', {
80
123
  new_row_layouts: [[12], [6,6], [9,3]],
81
124
  });
82
125
  // Call this to get the result after the user has done some editing:
83
- var html = $('#myGrid').gridEditor('getHtml');
126
+ var html = ge.getHtml();
84
127
 
85
128
  // Or, for a page that only publishes the result and never edits it again:
86
- var published = $('#myGrid').gridEditor('getPlainHtml');
129
+ var published = ge.getPlainHtml();
87
130
  ```
88
131
 
89
132
  `getHtml` keeps a little of the editor's own marking: the `column` class, the
@@ -104,9 +147,17 @@ Methods
104
147
  -------
105
148
 
106
149
  ```javascript
107
- $('#myGrid').gridEditor('method', argument);
150
+ var ge = new GridEditor('#myGrid', options); // or GridEditor.create('#myGrid', options)
151
+ ge.method(argument);
152
+
153
+ GridEditor.get('#myGrid'); // the editor on an element, or null
108
154
  ```
109
155
 
156
+ The element is an element or a selector, which takes the first element it
157
+ matches; one that matches nothing throws a `TypeError`. An element has one
158
+ editor at most: asked for a second, `new GridEditor` hands back the one it
159
+ has, with the options it was made with, and warns once.
160
+
110
161
  | Method | Arguments | Returns | What it does |
111
162
  | --- | --- | --- | --- |
112
163
  | `getHtml` | — | `String` | The clean html: no drawers, no editor classes, no inline styles |
@@ -115,62 +166,64 @@ $('#myGrid').gridEditor('method', argument);
115
166
  | `deinit` | — | `this` | Strip the editing furniture, leave the markup |
116
167
  | `reset` | — | `this` | `deinit()` then `init()` |
117
168
  | `destroy` | — | `this` | Deinit, drop the controls, unbind, forget the instance |
118
- | `remove` | — | `this` | Deprecated alias of `destroy` |
119
169
  | `changeView` | `breakpoint` | `this` | `'xs'`…`'xxl'`, or `'all'` to edit every breakpoint at once, with one class |
120
170
  | `getView` | — | `String` | The view the editor is in |
121
171
  | `setLocale` | `code` | `this` | Switch language and re-render the controls |
122
- | `createRow` | `layout?`, `options?` | `jQuery` | A row, optionally with columns: `createRow([8, 4])`, `createRow(['auto', 'equal'])`, `createRow({ row_cols: { xs: 1, md: 3 }, columns: 6 })` |
123
- | `createColumn` | `size`, `options?` | `jQuery` | An empty column: units, `'equal'` or `'auto'`; no size into a row with row-cols takes the row's share. `options`: `offset`, `content` - a text of the first editor offered, or plain content with none |
124
- | `createSection` | `options?` | `jQuery` | A section, with the sections plugin. `options`: `width` (`'fixed'`, `'fluid'` or a breakpoint), `rows` (layouts), and a placement |
125
- | `createElement` | `content`, `options?` | `jQuery` | Host markup wrapped as an element. `options`: `type`, `label` |
126
- | `createText` | `type?`, `options?` | `jQuery` | A content area for a text editor, the first one offered by default. `options`: `content`, and a placement. `null` if the editor is not loaded, or no text editor is |
127
- | `createContainer` | `type`, `options?` | `jQuery` | `'tabs'`, `'accordion'` or `'popup'` |
128
- | `addTab` | `container`, `options?` | `jQuery` | Appends a tab, returns its pane |
129
- | `addAccordionItem` | `container`, `options?` | `jQuery` | Appends an item, returns its body |
172
+ | `createRow` | `layout?`, `options?` | `Element` | A row, optionally with columns: `createRow([8, 4])`, `createRow(['auto', 'equal'])`, `createRow({ row_cols: { xs: 1, md: 3 }, columns: 6 })` |
173
+ | `createColumn` | `size`, `options?` | `Element` | An empty column: units, `'equal'` or `'auto'`; no size into a row with row-cols takes the row's share. `options`: `offset`, `content` - a text of the first editor offered, or plain content with none |
174
+ | `createSection` | `options?` | `Element` | A section, with the sections plugin. `options`: `width` (`'fixed'`, `'fluid'` or a breakpoint), `rows` (layouts), and a placement |
175
+ | `createElement` | `content`, `options?` | `Element` | Host markup wrapped as an element. `options`: `type`, `label` |
176
+ | `createText` | `type?`, `options?` | `Element` | A content area for a text editor, the first one offered by default. `options`: `content`, and a placement. `null` if the editor is not loaded, or no text editor is |
177
+ | `createContainer` | `type`, `options?` | `Element` | `'tabs'`, `'accordion'` or `'popup'` |
178
+ | `addTab` | `container`, `options?` | `Element` | Appends a tab, returns its pane |
179
+ | `addAccordionItem` | `container`, `options?` | `Element` | Appends an item, returns its body |
130
180
  | `getUtility` | `node`, `family`, `view?` | `String` | A utility plugin's value on a node in a view (the current one by default), or `null` |
131
181
  | `setUtility` | `node`, `family`, `value`, `view?` | `Boolean` | Write it through the events; `null` is inherit. `false` if canceled or nothing changed |
132
182
 
133
- A method called on an element with no editor on it is a no-op that returns the
134
- set, so host code does not have to check first. `getHtml` and `getPlainHtml`
135
- are the exception: they return the element's html either way, and
136
- `getPlainHtml` cleans it.
183
+ The methods that do something hand back the editor, so they chain. After
184
+ `destroy()` every method is a no-op that says so once, but for `getHtml` and
185
+ `getPlainHtml`, which read the element as it is.
137
186
 
138
- The `create*` methods hand back the node they made rather than the jQuery set,
139
- because you need the node. It comes back **detached**: place it and call
140
- `reset()`, or pass a parent and let grid-editor do both.
187
+ The `create*` methods hand back the element they made, or `null` when a handler
188
+ canceled the add. It comes back **detached**: place it and call `reset()`, or
189
+ pass a parent - an element or a selector - and let grid-editor do both.
141
190
 
142
191
  ```javascript
143
192
  // place it yourself
144
- var row = $('#myGrid').gridEditor('createRow', [8, 4]);
145
- row.appendTo('#myGrid');
146
- $('#myGrid').gridEditor('reset');
193
+ var row = ge.createRow([8, 4]);
194
+ document.querySelector('#myGrid').appendChild(row);
195
+ ge.reset();
147
196
 
148
197
  // or say where it goes: appendTo, prependTo, insertAfter, insertBefore
149
- $('#myGrid').gridEditor('createRow', [8, 4], { appendTo: '#myGrid' });
198
+ ge.createRow([8, 4], { appendTo: '#myGrid' });
150
199
  ```
151
200
 
152
- If you are calling several methods in a row, take the instance handle instead
153
- of dispatching each one. It exposes the same methods, plus the canvas and a
154
- read-only copy of the settings:
201
+ Besides the methods, the editor has its canvas and a read-only copy of the
202
+ settings:
155
203
 
156
204
  ```javascript
157
- var ge = $('#myGrid').data('grideditor');
158
205
  ge.createRow([12], { appendTo: ge.canvas });
159
- ge.changeView('lg');
206
+ ge.settings.locale; // 'en'
160
207
  ```
161
208
 
209
+ A html string written into the canvas - through the source view,
210
+ `source_textarea`, `createElement` or a paste - is parsed as `innerHTML`
211
+ parses: a `<script>` in it is kept in the markup and does not run in the
212
+ editor. Up to 6.x it did.
213
+
162
214
  Events
163
215
  ------
164
216
 
165
- Every operation is announced before and after it happens, as a jQuery event on
166
- the canvas and as a callback. A `before-*` can be canceled.
217
+ Every operation is announced before and after it happens, as a DOM event on
218
+ the canvas - a `CustomEvent` with the payload as its `detail` - and as a
219
+ callback. A `before-*` can be canceled.
167
220
 
168
221
  ```javascript
169
- $('#myGrid').on('grideditor:before-delete', function(e, payload) {
170
- if (payload.node.hasClass('locked')) { e.preventDefault(); }
222
+ ge.canvas.addEventListener('grideditor:before-delete', function(e) {
223
+ if (e.detail.node.classList.contains('locked')) { e.preventDefault(); }
171
224
  });
172
225
 
173
- $('#myGrid').gridEditor({
226
+ new GridEditor('#myGrid', {
174
227
  callbacks: {
175
228
  after_move: function(payload) { console.log(payload.from, payload.to); },
176
229
  },
@@ -183,7 +236,7 @@ The full catalogue, the payload and what canceling each operation does is in
183
236
  Languages
184
237
  ---------
185
238
 
186
- The interface ships in English and Spanish. English is built into the plugin;
239
+ The interface ships in English and Spanish. English is built into the editor;
187
240
  every other language is a file you load after it.
188
241
 
189
242
  | Code | Language | File |
@@ -192,9 +245,9 @@ every other language is a file you load after it.
192
245
  | `es` | Spanish | `dist/locales/grideditor.es.js` |
193
246
 
194
247
  ```html
195
- <script src="grid-editor/dist/jquery.grideditor.min.js"></script>
248
+ <script src="grid-editor/dist/grideditor.min.js"></script>
196
249
  <script src="grid-editor/dist/locales/grideditor.es.js"></script>
197
- <script>$('#myGrid').gridEditor({ locale: 'es' });</script>
250
+ <script>new GridEditor('#myGrid', { locale: 'es' });</script>
198
251
  ```
199
252
 
200
253
  Override single strings without a locale file with `locale_strings`, and switch
@@ -214,7 +267,7 @@ Options
214
267
  __`new_row_layouts`:__ Set the column layouts that appear in the "new row" buttons at the top of the editor. A size is a number of units, `'equal'` (Bootstrap's `col`, sharing what the row has left) or `'auto'` (`col-auto`, as wide as its content).
215
268
 
216
269
  ```javascript
217
- $('#myGrid').gridEditor({
270
+ new GridEditor('#myGrid', {
218
271
  new_row_layouts: [[12], [6,6], [9,3], ['auto', 'equal'], { row_cols: { xs: 1, md: 3 }, columns: 6 }],
219
272
  });
220
273
  ```
@@ -260,7 +313,7 @@ buttons beside the two fields. Empty by default; the classes field covers the
260
313
  general case, and this is for the handful a host wants one click away.
261
314
 
262
315
  ```javascript
263
- $('#myGrid').gridEditor({
316
+ new GridEditor('#myGrid', {
264
317
  row_classes: [{ label: 'Dark', cssClass: 'my-app-dark' }],
265
318
  });
266
319
  ```
@@ -270,7 +323,7 @@ __`col_classes`:__ The same as `row_classes`, but for columns. `container_classe
270
323
  __`row_tools`:__ Add extra tool buttons to the row toolbar.
271
324
 
272
325
  ```javascript
273
- $('#myGrid').gridEditor({
326
+ new GridEditor('#myGrid', {
274
327
  row_tools: [{
275
328
  title: 'Set background image',
276
329
  iconClass: 'glyphicon-picture',
@@ -288,7 +341,7 @@ __`col_tools`:__ The same as row_tools, but for columns.
288
341
  __`drag_handle`:__ What a drag starts from. `'tool'`, the default, gives every drawer a move tool and only that tool drags. `'drawer'` makes the whole drawer the handle and drops the move tool, since it would then only say "drag from here". The tools inside a draggable drawer still answer to a click, and dragging from one starts no move.
289
342
 
290
343
  ```javascript
291
- $('#myGrid').gridEditor({
344
+ new GridEditor('#myGrid', {
292
345
  drag_handle: 'drawer',
293
346
  });
294
347
  ```
@@ -296,7 +349,7 @@ $('#myGrid').gridEditor({
296
349
  __`toolbar_drag`:__ Whether the toolbar's buttons are a palette: drag one onto the canvas and the row or container it stands for is created where you drop it, with a line showing where that is. `'auto'`, the default, turns it on when `drag_handle` is `'drawer'`, since that is the same idea applied to the toolbar; `true` and `false` decide it outright. Clicking a button still adds at the end either way.
297
350
 
298
351
  ```javascript
299
- $('#myGrid').gridEditor({
352
+ new GridEditor('#myGrid', {
300
353
  drag_handle: 'drawer',
301
354
  toolbar_drag: 'auto',
302
355
  });
@@ -306,7 +359,7 @@ __`custom_filter`:__ Allows the execution of a custom function before initializa
306
359
  Gives the `canvas` element and `isInit` (true/false) as parameter.
307
360
 
308
361
  ```javascript
309
- $('#myGrid').gridEditor({
362
+ new GridEditor('#myGrid', {
310
363
  'custom_filter': 'functionname',
311
364
  });
312
365
 
@@ -322,7 +375,7 @@ function functionname(canvas, isInit) {
322
375
  or
323
376
 
324
377
  ```javascript
325
- $('#myGrid').gridEditor({
378
+ new GridEditor('#myGrid', {
326
379
  'custom_filter': function(canvas, isInit) {
327
380
  //...
328
381
  },
@@ -332,7 +385,7 @@ $('#myGrid').gridEditor({
332
385
  __`valid_col_sizes`:__ The column sizes the +/- buttons step through, and that the add column picker and the width field offer. Default `[1, 2, … 12, 'equal', 'auto']`; leave `'equal'` and `'auto'` out and they are not offered, though a column that has one still shows it.
333
386
 
334
387
  ```javascript
335
- $('#myGrid').gridEditor({
388
+ new GridEditor('#myGrid', {
336
389
  'valid_col_sizes': [2, 5, 8, 10],
337
390
  });
338
391
  ```
@@ -342,7 +395,7 @@ __`valid_col_offsets`:__ The same, for the indent buttons. Default `[0, 1, … 1
342
395
  __`add_column`:__ What the add column tool in a row's drawer does. A click adds a column of `size`; holding the tool for `delay` milliseconds — with the pointer or with a finger — offers the widths in `valid_col_sizes` instead, marking the ones that no longer fit the row. Defaults:
343
396
 
344
397
  ```javascript
345
- $('#myGrid').gridEditor({
398
+ new GridEditor('#myGrid', {
346
399
  add_column: {
347
400
  size: 12, // what a click adds
348
401
  picker: true, // false turns the hold gesture off
@@ -354,9 +407,9 @@ $('#myGrid').gridEditor({
354
407
  __`callbacks`:__ A `before_*`/`after_*` function per operation, the same notifications as the events. Returning `false` from a `before_*` cancels it. See [docs/events.md](docs/events.md).
355
408
 
356
409
  ```javascript
357
- $('#myGrid').gridEditor({
410
+ new GridEditor('#myGrid', {
358
411
  callbacks: {
359
- before_delete: function(payload) { return !payload.node.hasClass('locked'); },
412
+ before_delete: function(payload) { return !payload.node.classList.contains('locked'); },
360
413
  after_add_row: function(payload) { console.log('row added', payload.node); },
361
414
  },
362
415
  });
@@ -374,7 +427,7 @@ __`settings_panel`:__ Where the settings a gear opens are shown - a node's id, i
374
427
  Each is titled after its node ("Column settings"), the node is outlined while its settings are open, and Escape closes them. The editor opens and places them itself, with Bootstrap's markup and css: a page needs neither Popper nor Bootstrap's javascript, and the modal is Bootstrap's own when Bootstrap is there. [example/utilities.html](example/utilities.html) switches between the four.
375
428
 
376
429
  ```javascript
377
- $('#myGrid').gridEditor({ settings_panel: 'popover' });
430
+ new GridEditor('#myGrid', { settings_panel: 'popover' });
378
431
  ```
379
432
 
380
433
  __`confirm_delete`:__ Whether to ask before deleting a row, column, element or container. Default `true`. The question is asked in a Bootstrap modal the editor builds outside your canvas, in the interface language; a page that loaded Bootstrap's css but not its javascript gets the browser's own confirm instead. Set it to `false` if you cancel `before-delete` and ask in your own way.
@@ -382,7 +435,7 @@ __`confirm_delete`:__ Whether to ask before deleting a row, column, element or c
382
435
  __`drag`:__ How a drag behaves, wherever the editor drags something. Named for the gesture rather than for the library underneath, so it survives a change of library. Every gesture works from a touchscreen, which is what `touch_delay` is for: a touch drag that started instantly would take the page's scrolling with it, so a finger has to rest for a moment before it moves anything. Setting `delay` makes both gestures wait that long.
383
436
 
384
437
  ```javascript
385
- $('#myGrid').gridEditor({
438
+ new GridEditor('#myGrid', {
386
439
  drag: {
387
440
  delay: 0, // ms to hold before a drag starts
388
441
  touch_delay: 100, // the same for touch, where 0 eats the page's scrolling
@@ -398,7 +451,7 @@ $('#myGrid').gridEditor({
398
451
  __`layout_modes`:__ Which views the toolbar dropdown offers. Default `['all', 'xs', 'sm', 'md', 'lg', 'xl', 'xxl']`. Offer fewer to keep the feel of 2.x:
399
452
 
400
453
  ```javascript
401
- $('#myGrid').gridEditor({
454
+ new GridEditor('#myGrid', {
402
455
  layout_modes: ['all', 'lg', 'sm', 'xs'],
403
456
  });
404
457
  ```
@@ -408,7 +461,7 @@ __`default_view`:__ The view the editor starts in. Default `'all'`, which writes
408
461
  __`resize`:__ Resizing a column by dragging its edge. Defaults:
409
462
 
410
463
  ```javascript
411
- $('#myGrid').gridEditor({
464
+ new GridEditor('#myGrid', {
412
465
  resize: {
413
466
  enabled: true,
414
467
  handles: 'e', // 'w' for a right to left page, 'e, w' for both
@@ -437,7 +490,7 @@ several (*Text (tinyMCE)*, *Text (CKEditor)*...). The button adds a row with
437
490
  the text in it, or, dragged into a column, puts the text where it is dropped.
438
491
 
439
492
  ```javascript
440
- $('#myGrid').gridEditor('createText', { content: '<p>Hello</p>', appendTo: '#myColumn' });
493
+ ge.createText({ content: '<p>Hello</p>', appendTo: '#myColumn' });
441
494
  ```
442
495
 
443
496
  A text whose editor's plugin is not loaded is still a block, to move and
@@ -487,7 +540,7 @@ beside it instead, with a warning.
487
540
  __`elements`:__ Defaults:
488
541
 
489
542
  ```javascript
490
- $('#myGrid').gridEditor({
543
+ new GridEditor('#myGrid', {
491
544
  elements: {
492
545
  enabled: 'auto', // on when the page has any; true or false to decide yourself
493
546
  selector: '[data-ge-element]', // what counts as an element
@@ -534,14 +587,14 @@ replaces what the breakpoints said. While you edit, the canvas shows what the
534
587
  classes mean in the view you are in; `getHtml` returns only the classes.
535
588
 
536
589
  ```javascript
537
- $('#myGrid').gridEditor('setUtility', column, 'visibility', 'none', 'md'); // d-md-none
538
- $('#myGrid').gridEditor('getUtility', column, 'visibility', 'lg'); // 'none', inherited
590
+ ge.setUtility(column, 'visibility', 'none', 'md'); // d-md-none
591
+ ge.getUtility(column, 'visibility', 'lg'); // 'none', inherited
539
592
  ```
540
593
 
541
594
  __`utilities`:__ Options for each plugin, under its name.
542
595
 
543
596
  ```javascript
544
- $('#myGrid').gridEditor({
597
+ new GridEditor('#myGrid', {
545
598
  utilities: {
546
599
  visibility: { drawer: false }, // no eye in the drawers, the field only
547
600
  order: { drawer: false }, // no arrows in the column drawers
@@ -573,7 +626,7 @@ breakpoint. They are called sections, not containers, because a container is
573
626
  what the tabs, accordion, popup and card plugins make.
574
627
 
575
628
  ```javascript
576
- $('#myGrid').gridEditor('createSection', { width: 'md', rows: [[6, 6]], appendTo: '#myGrid' });
629
+ ge.createSection({ width: 'md', rows: [[6, 6]], appendTo: '#myGrid' });
577
630
  ```
578
631
 
579
632
  __`sections`:__ `{ widths: ['fixed', 'sm', 'md', 'lg', 'xl', 'xxl', 'fluid'] }`, the widths the field offers.
@@ -633,7 +686,7 @@ Each type is a plugin, in a file of its own, and loading the file is what makes
633
686
  it available:
634
687
 
635
688
  ```html
636
- <script src="grid-editor/dist/jquery.grideditor.min.js"></script>
689
+ <script src="grid-editor/dist/grideditor.min.js"></script>
637
690
  <script src="grid-editor/dist/plugins/grideditor.tabs.min.js"></script>
638
691
  <script src="grid-editor/dist/plugins/grideditor.accordion.min.js"></script>
639
692
  <script src="grid-editor/dist/plugins/grideditor.popup.min.js"></script>
@@ -646,21 +699,21 @@ for the contract, and for writing one of your own.
646
699
  __`plugins`:__ Which of the loaded plugins to use, containers, features and utilities alike. Every one by default; name them to use fewer than the page loaded.
647
700
 
648
701
  ```javascript
649
- $('#myGrid').gridEditor({ plugins: ['tabs', 'elements'] });
702
+ new GridEditor('#myGrid', { plugins: ['tabs', 'elements'] });
650
703
  ```
651
704
 
652
705
  __`container_tools`, `tab_tools`, `accordion_tools`:__ Extra tools on the container drawer and on each pane's drawer, same shape as `row_tools`.
653
706
 
654
707
  ```javascript
655
- var tabs = $('#myGrid').gridEditor('createContainer', 'tabs', {
708
+ var tabs = ge.createContainer('tabs', {
656
709
  tabs: 2,
657
710
  labels: ['Overview', 'Details'],
658
711
  appendTo: $('#myGrid .column').first(),
659
712
  });
660
- $('#myGrid').gridEditor('addTab', tabs, { label: 'Third', activate: true });
713
+ ge.addTab(tabs, { label: 'Third', activate: true });
661
714
 
662
- $('#myGrid').gridEditor('createContainer', 'accordion', { items: 3, stay_open: true });
663
- $('#myGrid').gridEditor('createContainer', 'popup', { title: 'Terms', trigger_label: 'Read them', size: 'lg' });
715
+ ge.createContainer('accordion', { items: 3, stay_open: true });
716
+ ge.createContainer('popup', { title: 'Terms', trigger_label: 'Read them', size: 'lg' });
664
717
  ```
665
718
 
666
719
  An accordion opens and closes from its headers while editing, and what you
@@ -684,16 +737,16 @@ __`locale`:__ The code of a locale in `$.fn.gridEditor.locales`. Default `'en'`.
684
737
  __`locale_strings`:__ Overrides for individual keys, without a locale file.
685
738
 
686
739
  ```javascript
687
- $('#myGrid').gridEditor({
740
+ new GridEditor('#myGrid', {
688
741
  locale: 'es',
689
742
  locale_strings: { 'tool.move': 'Arrastrar' },
690
743
  });
691
744
  ```
692
745
 
693
- __`source_textarea`:__ Allows to set an already existing textarea as input for grid editor.
746
+ __`source_textarea`:__ Allows to set an already existing textarea as input for grid editor: an element, or a selector.
694
747
 
695
748
  ```javascript
696
- $('#myGrid').gridEditor({
749
+ new GridEditor('#myGrid', {
697
750
  source_textarea: 'textarea.myTextarea',
698
751
  });
699
752
  ```
@@ -701,9 +754,8 @@ $('#myGrid').gridEditor({
701
754
  You will have write back the content to the textarea before saving, for example in this way:
702
755
 
703
756
  ```javascript
704
- $('form.myForm').on('submit', function() {
705
- var html = $('#myGrid').gridEditor('getHtml');
706
- $('textarea.myTextarea').val(html);
757
+ document.querySelector('form.myForm').addEventListener('submit', function() {
758
+ document.querySelector('textarea.myTextarea').value = ge.getHtml();
707
759
  });
708
760
  ```
709
761
 
@@ -715,7 +767,7 @@ hand, and back again with what was written.
715
767
  __`edit_source`:__ Whether the toolbar has that button. Default value: `true`.
716
768
 
717
769
  ```javascript
718
- $('#myGrid').gridEditor({
770
+ new GridEditor('#myGrid', {
719
771
  edit_source: false,
720
772
  });
721
773
  ```
@@ -740,7 +792,7 @@ plugin's defaults: `mode: 'htmlmixed'`, `lineNumbers`, `lineWrapping`, a tab
740
792
  of 2.
741
793
 
742
794
  ```javascript
743
- $('#myGrid').gridEditor({
795
+ new GridEditor('#myGrid', {
744
796
  codemirror: { config: { theme: 'monokai' } },
745
797
  });
746
798
  ```
@@ -779,7 +831,7 @@ it is missing. Another editor is a plugin of your own:
779
831
  __`content_types`:__ Specify the RTEs to offer, in order. Valid values: any of `'tinymce'`, `'summernote'`, `'ckeditor'` whose plugin is loaded. Default value: every text editor loaded, in the order the page loaded them.
780
832
 
781
833
  ```javascript
782
- $('#myGrid').gridEditor({
834
+ new GridEditor('#myGrid', {
783
835
  content_types: ['summernote'],
784
836
  });
785
837
  ```
@@ -789,7 +841,7 @@ See the [CKEditor documentation](http://docs.ckeditor.com/).
789
841
  Also check out the [ckeditor example](example/ckeditor.html).
790
842
 
791
843
  ```javascript
792
- $('#myGrid').gridEditor({
844
+ new GridEditor('#myGrid', {
793
845
  ckeditor: {
794
846
  config: { language: 'fr' }
795
847
  }
@@ -801,7 +853,7 @@ See the [summernote documentation](http://summernote.org/deep-dive/).
801
853
  Also check out the [summernote example](example/summernote.html).
802
854
 
803
855
  ```javascript
804
- $('#myGrid').gridEditor({
856
+ new GridEditor('#myGrid', {
805
857
  summernote: {
806
858
  config: { shortcuts: false }
807
859
  }
@@ -813,7 +865,7 @@ See the [tinyMCE documentation](https://www.tiny.cloud/docs/tinymce/6/).
813
865
  Also check out the [tinymce example](example/basic.html).
814
866
 
815
867
  ```javascript
816
- $('#myGrid').gridEditor({
868
+ new GridEditor('#myGrid', {
817
869
  tinymce: {
818
870
  config: { paste_as_text: true }
819
871
  }