@themarioga/grid-editor 4.0.0 → 5.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 (65) hide show
  1. package/CHANGELOG.md +95 -0
  2. package/README.md +121 -9
  3. package/UPGRADING.md +55 -0
  4. package/dist/grideditor.css +609 -0
  5. package/dist/grideditor.min.css +1 -1
  6. package/dist/grideditor.min.css.map +1 -1
  7. package/dist/jquery.grideditor.bundle.min.js +2 -2
  8. package/dist/jquery.grideditor.js +1189 -118
  9. package/dist/jquery.grideditor.min.js +1 -1
  10. package/dist/jquery.grideditor.min.js.map +1 -1
  11. package/dist/locales/grideditor.es.js +58 -0
  12. package/dist/locales/grideditor.es.min.js +1 -1
  13. package/dist/locales/grideditor.es.min.js.map +1 -1
  14. package/dist/plugins/grideditor.alignment.js +81 -0
  15. package/dist/plugins/grideditor.alignment.min.js +2 -0
  16. package/dist/plugins/grideditor.alignment.min.js.map +1 -0
  17. package/dist/plugins/grideditor.float.js +56 -0
  18. package/dist/plugins/grideditor.float.min.js +2 -0
  19. package/dist/plugins/grideditor.float.min.js.map +1 -0
  20. package/dist/plugins/grideditor.gutters.js +145 -0
  21. package/dist/plugins/grideditor.gutters.min.js +2 -0
  22. package/dist/plugins/grideditor.gutters.min.js.map +1 -0
  23. package/dist/plugins/grideditor.order.js +206 -0
  24. package/dist/plugins/grideditor.order.min.js +2 -0
  25. package/dist/plugins/grideditor.order.min.js.map +1 -0
  26. package/dist/plugins/grideditor.sections.js +199 -0
  27. package/dist/plugins/grideditor.sections.min.js +2 -0
  28. package/dist/plugins/grideditor.sections.min.js.map +1 -0
  29. package/dist/plugins/grideditor.spacing.js +299 -0
  30. package/dist/plugins/grideditor.spacing.min.js +2 -0
  31. package/dist/plugins/grideditor.spacing.min.js.map +1 -0
  32. package/dist/plugins/grideditor.textalign.js +60 -0
  33. package/dist/plugins/grideditor.textalign.min.js +2 -0
  34. package/dist/plugins/grideditor.textalign.min.js.map +1 -0
  35. package/dist/plugins/grideditor.visibility.js +172 -0
  36. package/dist/plugins/grideditor.visibility.min.js +2 -0
  37. package/dist/plugins/grideditor.visibility.min.js.map +1 -0
  38. package/docs/events.md +32 -2
  39. package/docs/locale-keys.md +88 -1
  40. package/docs/plugins.md +141 -3
  41. package/example/autocols.html +137 -0
  42. package/example/autosave.html +5 -0
  43. package/example/basic.html +5 -0
  44. package/example/breakpoints.html +12 -5
  45. package/example/ckeditor.html +5 -0
  46. package/example/containers.html +4 -0
  47. package/example/elements.html +5 -0
  48. package/example/index.html +38 -1
  49. package/example/locale.html +5 -0
  50. package/example/plugins.html +5 -0
  51. package/example/summernote.html +5 -0
  52. package/example/utilities.html +166 -0
  53. package/example/wrap_content.html +5 -0
  54. package/package.json +1 -1
  55. package/src/js/jquery.grideditor.js +1190 -119
  56. package/src/js/locales/grideditor.es.js +58 -0
  57. package/src/js/plugins/grideditor.alignment.js +81 -0
  58. package/src/js/plugins/grideditor.float.js +56 -0
  59. package/src/js/plugins/grideditor.gutters.js +145 -0
  60. package/src/js/plugins/grideditor.order.js +206 -0
  61. package/src/js/plugins/grideditor.sections.js +199 -0
  62. package/src/js/plugins/grideditor.spacing.js +299 -0
  63. package/src/js/plugins/grideditor.textalign.js +60 -0
  64. package/src/js/plugins/grideditor.visibility.js +172 -0
  65. package/src/less/grideditor.less +299 -0
package/docs/events.md CHANGED
@@ -56,6 +56,9 @@ about every insertion can bind `grideditor:before-add` and switch on
56
56
  | `grideditor:before-indent` | — | yes | before a column's offset changes |
57
57
  | `grideditor:after-indent` | — | no | after the offset class is written |
58
58
  | `grideditor:popup-orphan` | — | no | on `init`, once per trigger whose popup is missing and cannot be re-pointed |
59
+ | `grideditor:before-utility` | — | yes | before a utility class is written, from the panel, a plugin's tool or `setUtility` |
60
+ | `grideditor:after-utility` | — | no | after the class is written and the preview redrawn, only if something changed |
61
+ | `grideditor:view-change` | — | no | after the view changes, only if it actually changed |
59
62
 
60
63
  Two things here are not in the 3.0 specification's catalogue. The indent pair,
61
64
  because the indent tools are an operation like any other and announce
@@ -70,28 +73,53 @@ The payload
70
73
  {
71
74
  kind: 'row', // row | column | content | element
72
75
  // tabs | accordion | popup | tab | accordion-item
76
+ // section, with the sections plugin
73
77
  node: jQuery, // the node added, deleted, moved or resized
74
78
  parent: jQuery, // where it is going, or where it came from on a delete
75
79
  canvas: jQuery,
76
80
  breakpoint: 'lg', // the view at the time: a breakpoint key, or 'all'
77
- source: 'tool', // tool | api | dragdrop
81
+ source: 'tool', // tool | api | dragdrop | panel (a width chosen in the panel)
78
82
 
79
83
  // move only
80
84
  from: { parent: jQuery, index: 2 },
81
85
  to: { parent: jQuery, index: 0 },
82
86
 
83
- // resize and indent only: units, not pixels
87
+ // resize and indent only: units, not pixels. A size can also be
88
+ // 'equal' or 'auto', and null when the width field chose "inherit"
84
89
  from: 6,
85
90
  to: 7,
91
+ cleared: [ // the all view only: the breakpoints' own sizes or
92
+ { breakpoint: 'md', value: 4 }, // offsets, which the write took off
93
+ ],
86
94
 
87
95
  // a pane inside a container
88
96
  container: jQuery,
89
97
 
90
98
  // popup-orphan only
91
99
  missing: 'ge-popup-3-a91', // the id the trigger pointed at
100
+
101
+ // utility only
102
+ family: 'order', // the utility, as its plugin names it
103
+ from: '1', // what applied in the view before, or null
104
+ to: '2', // what was asked for; null is "inherit"
105
+ tiers: ['md'], // the breakpoints whose class was written
106
+ cleared: [ // the all view only: what the breakpoints said,
107
+ { breakpoint: 'lg', value: '3' }, // and the write took away
108
+ ],
92
109
  }
93
110
  ```
94
111
 
112
+ A section's width change is announced as a utility change too, with
113
+ `family: 'section'`, `breakpoint: 'all'` and the widths - `'fixed'`, `'fluid'`,
114
+ `'md'` - as `from` and `to`: a section has one container class, whatever the
115
+ breakpoint. Adding a section fires `before-add-section` and `after-add-section`,
116
+ with the generic pair.
117
+
118
+ `view-change` carries no node: its payload is `canvas`, `breakpoint` (the new
119
+ view), `from` and `to`. A utility's `breakpoint` is the view it was written
120
+ in, which `setUtility` can be asked to make a different one from the view on
121
+ screen, and its `source` is `panel`, `tool` or `api`.
122
+
95
123
  `source` matters to a host that both drives the editor from its own palette and
96
124
  listens for what the user does: `api` is your own call coming back to you,
97
125
  `tool` is a click in the editor, `dragdrop` is a gesture.
@@ -121,6 +149,8 @@ cancels a `before-*`. What that means depends on the operation:
121
149
  - **Resize.** From a tool, nothing is written. From a drag, the gesture never
122
150
  starts: the column does not move and nothing is written.
123
151
  - **Indent.** Nothing is written.
152
+ - **Utility.** Nothing is written, `setUtility` returns `false`, and the panel
153
+ field goes back to the value that stands.
124
154
 
125
155
  `after-move` is suppressed when the drop leaves the node in the same parent at
126
156
  the same index, and `after-resize` when the snapped size equals the old one, so
@@ -30,6 +30,8 @@ The tools in a drawer, and the buttons in the toolbar above the canvas.
30
30
  | `tool.add_row` | Add row | Column drawer, adds a nested row |
31
31
  | `tool.add_column` | Add column\n(hold to choose the width) | Row drawer. A click adds a column, holding the tool offers the widths. Two lines |
32
32
  | `tool.column_size` | {size} of 12 | Tooltip of a width in that picker |
33
+ | `tool.column_equal` | Equal: shares what the row has left | The `equal` choice in that picker, which adds a `col` |
34
+ | `tool.column_auto` | Auto: as wide as its content | The `auto` choice in that picker, which adds a `col-auto` |
33
35
  | `tool.delete_row` | Remove row | Row drawer |
34
36
  | `tool.delete_column` | Remove col | Column drawer |
35
37
  | `tool.delete_element` | Remove element | Element drawer |
@@ -57,6 +59,7 @@ row.*
57
59
  | Key | English | Where |
58
60
  | --- | --- | --- |
59
61
  | `row.add` | Add row {layout} | Tooltip of each toolbar add-row button. `{layout}` is the column layout, as in `6-6` |
62
+ | `row.add_row_cols` | Add a row of {columns} columns, {counts} per row | Tooltip of a toolbar button for a `{ row_cols, columns }` layout. `{counts}` reads like `1, md: 3` |
60
63
 
61
64
 
62
65
  container.*
@@ -80,6 +83,23 @@ The containers: tabs, accordions and popups, and the panes inside them.
80
83
  | `container.card_footer` | Card footer | Text of a new card's footer, when it has one |
81
84
 
82
85
 
86
+ section.*
87
+ ---------
88
+
89
+ The sections plugin: Bootstrap's `.container` and its kin, on the canvas.
90
+
91
+ | Key | English | Where |
92
+ | --- | --- | --- |
93
+ | `section.add` | Section | Toolbar button that adds a section |
94
+ | `section.width` | Width | Label of a section's width field, in its settings panel |
95
+ | `section.fixed` | Fixed | Its choice for `container` |
96
+ | `section.fluid` | Full width | Its choice for `container-fluid` |
97
+ | `section.from` | Fixed from {breakpoint} | Its choice for `container-{bp}`. `{breakpoint}` is the key |
98
+ | `tool.add_row_to_section` | Add row | Section drawer, adds a row to the section |
99
+ | `tool.delete_section` | Remove section | Section drawer |
100
+ | `confirm.delete_section` | Delete this section and everything in it? | Asked before a section is deleted |
101
+
102
+
83
103
  confirm.*
84
104
  ---------
85
105
 
@@ -113,7 +133,7 @@ key, so a locale covers a new breakpoint by adding `view.<key>`. Short strings
113
133
 
114
134
  | Key | English | Where |
115
135
  | --- | --- | --- |
116
- | `view.all` | All sizes | The default view, which writes every breakpoint at once |
136
+ | `view.all` | All sizes | The default view, which writes one class for every breakpoint |
117
137
  | `view.xs` | Phone | Layout mode writing `col-*` and `offset-*` |
118
138
  | `view.sm` | Tablet | Layout mode writing `col-sm-*` and `offset-sm-*` |
119
139
  | `view.md` | Small desktop | Layout mode writing `col-md-*` and `offset-md-*` |
@@ -122,6 +142,73 @@ key, so a locale covers a new breakpoint by adding `view.<key>`. Short strings
122
142
  | `view.xxl` | Widescreen | Layout mode writing `col-xxl-*` and `offset-xxl-*` |
123
143
 
124
144
 
145
+ utility.*
146
+ ---------
147
+
148
+ The Responsive section of a settings panel, which the utility plugins fill.
149
+ The labels of each utility and its values are the plugins' own keys.
150
+
151
+ | Key | English | Where |
152
+ | --- | --- | --- |
153
+ | `utility.section` | Responsive: {view} | The section's fold toggle. `{view}` is the label of the view being edited |
154
+ | `utility.col_width` | Width | The column width field, in a column's Responsive section |
155
+ | `utility.col_equal` | Equal | Its choice for `col` / `col-{bp}` |
156
+ | `utility.col_auto` | Auto | Its choice for `col-auto` / `col-{bp}-auto` |
157
+ | `utility.col_from_row` | From the row: {count} | The width field's empty choice when the row's row-cols sizes the column. `{count}` is `badge.row_cols` |
158
+ | `utility.row_cols` | Columns per row | The row-cols field, in a row's Responsive section |
159
+ | `utility.default` | Default | The empty choice of a field when nothing below the view sets the utility, and always in the all view |
160
+ | `utility.inherit` | Inherit: {value} (from {breakpoint}) | The empty choice in a breakpoint view when a smaller breakpoint sets the utility. `{breakpoint}` is its key, `sm` |
161
+ | `utility.varies` | Changes at {breakpoints}; choosing here replaces that | Note under a field in the all view when breakpoints set their own value. `{breakpoints}` is a list of keys |
162
+ | `utility.visibility` | Visibility | Label of the visibility plugin's field |
163
+ | `utility.visibility_hidden` | Hidden | Its choice for `d-*-none` |
164
+ | `utility.visibility_shown` | Shown | Its choice for `d-*-block`, or `d-*-flex` on a row |
165
+ | `tool.hide_in_view` | Hide in this view | The visibility plugin's eye, on a node shown in the view being edited |
166
+ | `tool.show_in_view` | Show in this view | The same eye, on a node hidden there |
167
+ | `utility.order` | Order | Label of the order plugin's field |
168
+ | `utility.order_first` | First | Its choice for `order-*-first` |
169
+ | `utility.order_last` | Last | Its choice for `order-*-last` |
170
+ | `tool.order_earlier` | Earlier in this view | The order plugin's left arrow in a column drawer |
171
+ | `tool.order_later` | Later in this view | Its right arrow |
172
+ | `utility.justify_content` | Justify columns | The alignment plugin's `justify-content-*` field, on a row |
173
+ | `utility.align_items` | Align columns | Its `align-items-*` field, on a row |
174
+ | `utility.align_self` | Align self | Its `align-self-*` field, on a column |
175
+ | `utility.gutters` | Gutters | The gutters plugin's `g-*` field, on a row |
176
+ | `utility.gutters_x` | Horizontal gutters | Its `gx-*` field |
177
+ | `utility.gutters_y` | Vertical gutters | Its `gy-*` field |
178
+ | `utility.padding` | Padding | The spacing plugin's padding group |
179
+ | `utility.margin` | Margin | Its margin group |
180
+ | `utility.side_all` | All sides | The side of `p-*` and `m-*` in a group's side choice |
181
+ | `utility.side_x` | Left and right | The side of `px-*` and `mx-*` |
182
+ | `utility.side_y` | Top and bottom | The side of `py-*` and `my-*` |
183
+ | `utility.side_t` | Top | The side of `pt-*` and `mt-*` |
184
+ | `utility.side_b` | Bottom | The side of `pb-*` and `mb-*` |
185
+ | `utility.side_s` | Start | The side of `ps-*` and `ms-*` |
186
+ | `utility.side_e` | End | The side of `pe-*` and `me-*` |
187
+ | `utility.text_align` | Text alignment | Label of the textalign plugin's field |
188
+ | `utility.text_start` | Start | Its choice for `text-*-start` |
189
+ | `utility.text_center` | Center | Its choice for `text-*-center` |
190
+ | `utility.text_end` | End | Its choice for `text-*-end` |
191
+ | `utility.float` | Float | Label of the float plugin's field, on an element |
192
+ | `utility.float_start` | Start | Its choice for `float-*-start` |
193
+ | `utility.float_end` | End | Its choice for `float-*-end` |
194
+ | `utility.float_none` | None | Its choice for `float-*-none` |
195
+ | `utility.spacing_gutter` | A column's side padding is its gutter: changing it changes the gutter | Note in a column's spacing group while it carries side padding |
196
+
197
+
198
+ badge.*
199
+ -------
200
+
201
+ Text the utility plugins show on the canvas while editing. Never in the
202
+ markup `getHtml` returns.
203
+
204
+ | Key | English | Where |
205
+ | --- | --- | --- |
206
+ | `badge.hidden_in` | Hidden at {breakpoints} | Corner of a node hidden at some breakpoints, in the all view. `{breakpoints}` is a list of keys |
207
+ | `badge.row_cols` | {count} per row | Corner of a row whose row-cols sizes its columns in the view being edited |
208
+ | `badge.row_cols_auto` | As wide as their content | The same, for `row-cols-auto` |
209
+ | `badge.order` | Order: {value} | Corner of a column ordered by class in the view being edited |
210
+
211
+
125
212
  error.*
126
213
  -------
127
214
 
package/docs/plugins.md CHANGED
@@ -14,11 +14,13 @@ the one to read first if you are about to write your own.
14
14
  <script src="dist/plugins/grideditor.elements.min.js"></script>
15
15
  ```
16
16
 
17
- There are two kinds. A **container plugin** builds a type of container — it
17
+ There are three kinds. A **container plugin** builds a type of container — it
18
18
  registers under `$.fn.gridEditor.containers`, and the toolbar offers a button
19
- for it. A **feature plugin** is anything else the editor can do —
19
+ for it. A **utility plugin** declares families of Bootstrap's responsive
20
+ utility classes — `$.fn.gridEditor.utilities` — and the editor edits them per
21
+ breakpoint. A **feature plugin** is anything else the editor can do —
20
22
  `$.fn.gridEditor.features`, hooks into the canvas, and may contribute methods.
21
- Both are factories called once per editor with the same handle.
23
+ All three are factories called once per editor with the same handle.
22
24
 
23
25
  The `plugins` setting names which of the loaded ones to use:
24
26
 
@@ -114,6 +116,15 @@ not change without a major version.
114
116
  | `ge.emit(name, payload)` | Fire an event and its callbacks; false means a handler canceled |
115
117
  | `ge.payloadFor(kind, node, extra)` | Build a payload the documented way |
116
118
  | `ge.operate(body)` | Run `body` as one operation, so a handler calling back in is queued |
119
+ | `ge.kindOf(node)` | What an event calls a node: `row`, `column`, `element`, a container's type… |
120
+ | `ge.view()` | The view being edited: a breakpoint key, or `'all'` |
121
+ | `ge.viewTiers()` | The breakpoint key that view writes: the one being edited, or `xs` - the class with no breakpoint - in the all view |
122
+ | `ge.breakpoints` | Every breakpoint key, smallest first |
123
+ | `ge.getUtility(node, family, view?)` | A utility's value, as in the public method |
124
+ | `ge.setUtility(node, family, value, options?)` | Write one through the events. `options` is a view key or `{ view, source }` |
125
+ | `ge.utilityField(node, family)` | A panel field for one family, for a plugin that builds its own panel |
126
+ | `ge.rowFromLayout(layout)` | A detached row from a layout: `[8, 4]`, `['auto', 'equal']` or `{ row_cols, columns }` |
127
+ | `ge.bareStyle(node, family, property)` | A css property's value on the node with none of the family's classes: what a preview shows when no class applies and that is not a constant |
117
128
 
118
129
  The add, delete and move events for a container and its panes are fired by the
119
130
  editor, not by the plugin: `createPaneControls` handles a pane's delete, and
@@ -134,10 +145,29 @@ $.fn.gridEditor.features.elements = function(ge) {
134
145
  onDeinit: function() { … }, // every deinit: take it out again
135
146
  onContentReady: function(area) { … }, // a rich text editor just took over
136
147
  onSortable: function(sortable) { … }, // declare your own sortable lists
148
+ blocks: '.ge-section', // more blocks the canvas and the columns move
149
+ regions: '.ge-section', // more lists those blocks move in
150
+ accepts: function(region, node) { … }, // false turns a block away from a region
151
+ toolbar: [{ labelKey: …, kind: …, create: function() { … } }], // buttons beside the containers'
137
152
  };
138
153
  };
139
154
  ```
140
155
 
156
+ The last four are what the sections plugin is made of, and what a plugin
157
+ needs to put a new kind of block on the canvas:
158
+
159
+ - **`blocks`** is a selector added to what the canvas and every column move -
160
+ rows, content areas and containers, the editor's own blocks.
161
+ - **`regions`** is a selector for more lists those blocks move in, in the same
162
+ group, so a row dragged from the canvas can land in one.
163
+ - **`accepts(region, node)`** can turn a block away from a list: `false` and the
164
+ drag will not drop it there, whoever's block and whoever's list. With none of
165
+ these hooks, every block goes everywhere, as before.
166
+ - **`toolbar`** adds buttons beside the containers'. A click appends what
167
+ `create()` returns to the canvas, announced as `kind`; a drop puts it where it
168
+ was dropped, or, when that region will not have it, on the canvas just after
169
+ the block it was dropped in.
170
+
141
171
  - **`onSortable(sortable)`** is handed the function the editor makes all of its
142
172
  own lists with. A plugin describes a list; it never touches the drag toolkit
143
173
  itself, which is what keeps `drag_handle`, the cancel selector and the move
@@ -177,3 +207,111 @@ the plugin.
177
207
  Sorting is the one thing a plugin sets up itself, in `mark`, because only the
178
208
  plugin knows which of its parts move: the tabs plugin makes its strip sortable
179
209
  and puts the panes back in strip order in `afterPaneMove`.
210
+
211
+
212
+ Utility plugins
213
+ ---------------
214
+
215
+ A utility plugin edits one of Bootstrap's responsive utility classes — the
216
+ ones spelled `{property}-{breakpoint}-{value}`, like `order-md-2` or
217
+ `d-lg-none` — and hardly has to do anything to do it. It declares **families**,
218
+ and the editor reads, writes, previews and announces them:
219
+
220
+ ```javascript
221
+ $.fn.gridEditor.utilities.order = function(ge) {
222
+ return {
223
+ families: [{
224
+ name: 'order', // what events and setUtility call it
225
+ prefix: 'order', // order-2, order-md-2, order-xxl-2
226
+ values: ['first', 0, 1, 2, 3, 4, 5, 'last'],
227
+ appliesTo: ['column'], // row | column | element | container | a container type
228
+ labelKey: 'utility.order', // the field's label, optional
229
+ label: function(value) { … }, // an option's text, optional: the value itself otherwise
230
+ choices: function(node, kind) { … }, // what to offer this node, optional: every value otherwise
231
+ panel: false, // optional: no field of its own, see "A panel of your own"
232
+ className: function(breakpoint, value) { … }, // optional, for classes not spelled {prefix}-{bp}-{value}
233
+ write: function(node, value, view, source) { … }, // optional, a write that is some other operation
234
+ preview: function(value, node, kind) { // what the value looks like, see below
235
+ return { order: value === null ? 0 : value };
236
+ },
237
+ }],
238
+ drawerTools: function(drawer, node, kind) { … }, // optional, tools beside the gear
239
+ onRefresh: function(scope) { … }, // optional, see below
240
+ panel: function(node, kind) { … }, // optional, see "A panel of your own"
241
+ preview: function(node, kind, breakpoint) { … }, // optional, the same
242
+ onViewChange: function(view) { … }, // optional
243
+ };
244
+ };
245
+ ```
246
+
247
+ What the editor does with a family:
248
+
249
+ - **Reading follows the cascade.** A breakpoint's value is its own class or the
250
+ nearest smaller breakpoint's. The all view reads the class with no infix.
251
+ - **Writing depends on the view.** A breakpoint view writes its own tier and
252
+ nothing else. The all view writes the class with no infix and takes the
253
+ family off every other breakpoint, because choosing one value for every size
254
+ is choosing it over what the sizes said; the event says what it took off.
255
+ `null` is inherit: the tier's class comes off.
256
+ - **The panel.** Every node with a gear gets a folded *Responsive* section in
257
+ its settings panel, with a field per family that applies to it. A field shows
258
+ the view being edited, says what it inherits and from which breakpoint, and
259
+ follows the classes field when the user types there.
260
+ - **The preview.** A breakpoint view narrows the canvas, not the window, and
261
+ Bootstrap's utilities answer to the window with `!important`. So in a
262
+ breakpoint view each node that carries a family's class gets
263
+ `preview(value)` — the value that applies there, or `null` — as inline
264
+ `!important` styles. Return what `null` looks like too: a wider breakpoint's
265
+ class is still live in a wide window and has to be overruled. When what
266
+ `null` looks like depends on the page — `text-align` inherits, the host's
267
+ css may float an element — `ge.bareStyle(node, family, property)` asks the
268
+ browser. Parents are previewed before their children. The all view
269
+ previews nothing, since every breakpoint there is live and what Bootstrap
270
+ shows is the truth. The styles come off on `deinit`, leaving the host's own
271
+ `style` as it was, so `getHtml` never sees them.
272
+ - **The events.** Every write goes through `before-utility`, which can cancel
273
+ it, and `after-utility`. See [events.md](events.md).
274
+
275
+ `drawerTools` runs for every drawer that has a gear — rows, columns, elements,
276
+ containers and panes — so a plugin checks `kind` and adds nothing where its
277
+ tool does not belong. A tool writes with `ge.setUtility(node, family, value,
278
+ { source: 'tool' })`, and the panel, the classes field and the preview follow.
279
+
280
+ `onRefresh(scope)` runs whenever the preview is redrawn — on `init`, on a view
281
+ change, after a write, after the user types in a classes field — with the node
282
+ whose utilities changed, or the canvas. It is for what a plugin marks the canvas
283
+ with beyond inline styles: the visibility plugin keeps hidden nodes on the
284
+ canvas and fades them there. Whatever it adds, `onDeinit` takes away.
285
+
286
+ ### A panel of your own
287
+
288
+ A field per family is the right panel for most plugins and the wrong one for
289
+ some: spacing has fourteen families, and fourteen fields. Such a plugin marks
290
+ its families `panel: false` and returns its own element from
291
+ `panel(node, kind)` — or null where it does not apply — and the editor puts it
292
+ in the Responsive section. Inside it, `ge.utilityField(node, family)` makes the
293
+ same field the editor would, and the editor keeps every such field up to date
294
+ with the view and the classes; swapping one field for another is the plugin's
295
+ business. The spacing plugin's panel is a side and one field, and choosing a
296
+ side swaps the field for that side's family.
297
+
298
+ The same plugins tend to need the node as a whole for the preview, because
299
+ their families settle one property between them — `p-3` and `pt-md-1` both
300
+ set the top padding. A plugin-level `preview(node, kind, breakpoint)` is called
301
+ for every node in a breakpoint view, after the families' own, and returns the
302
+ styles for the node or an empty object.
303
+
304
+ Two escape hatches, which the column width uses: `className(breakpoint,
305
+ value)` spells the classes of a family that does not follow the pattern
306
+ (`col`, `col-md`, `col-md-auto`), and `write(node, value, view, source)` does a
307
+ write some other way than a utility change - the width field's writes are
308
+ resizes, through the resize events. The editor still checks the value and the
309
+ node before it calls `write`.
310
+
311
+ Two plugins cannot declare the same family name: the second one is ignored,
312
+ with a warning.
313
+
314
+ Plugin options live in the `utilities` setting, under the plugin's name:
315
+ `utilities: { spacing: { values: ['0', '2', '4'] } }`. The editor passes the
316
+ setting through as it is; each plugin fills in its own defaults.
317
+
@@ -0,0 +1,137 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
5
+
6
+ <!-- CSS dependencies -->
7
+ <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-sRIl4kxILFvY47J16cr9ZwB07vP4J8+LH7qKQnuqkuIAvNWLzeN8tE5YBujZqJLB" crossorigin="anonymous">
8
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.13.1/font/bootstrap-icons.css">
9
+
10
+ <!-- Javascript dependencies -->
11
+ <script src="https://code.jquery.com/jquery-4.0.0.min.js"></script>
12
+ <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/js/bootstrap.bundle.min.js" integrity="sha384-FKyoEForCGlyvwx9Hj09JcYn3nv7wiPVlz7YYwJrWVcXK/BmnVDxM+D2scQbITxI" crossorigin="anonymous"></script>
13
+
14
+ <!-- Grid editor CSS -->
15
+ <link rel="stylesheet" type="text/css" href="../dist/grideditor.css" />
16
+
17
+ <!-- The editor, and the sections plugin: equal and auto sizes and
18
+ columns per row are the editor's own, sections are a plugin -->
19
+ <script src="https://cdn.jsdelivr.net/npm/sortablejs@1.15.6/Sortable.min.js"></script>
20
+ <script src="../dist/jquery.grideditor.min.js"></script>
21
+ <script src="../dist/plugins/grideditor.sections.min.js"></script>
22
+
23
+ <script>
24
+ $(function() {
25
+ $('#myGrid').gridEditor({
26
+ content_types: [],
27
+
28
+ // Sizes are numbers, 'equal' (col) or 'auto' (col-auto), and a
29
+ // layout can be a row with columns per row
30
+ new_row_layouts: [
31
+ [12], [6, 6], ['auto', 'equal'], ['equal', 'equal', 'equal'],
32
+ { row_cols: { xs: 1, sm: 2, lg: 4 }, columns: 4 },
33
+ ],
34
+
35
+ default_view: 'lg',
36
+ });
37
+
38
+ // A width chosen anywhere - tools, edge, panel - is a resize
39
+ $('#myGrid').on('grideditor:after-resize', function(e, payload) {
40
+ $('#last').text('width at ' + payload.breakpoint + ': ' +
41
+ (payload.from === null ? 'from the row' : payload.from) + ' → ' +
42
+ (payload.to === null ? 'inherit' : payload.to) +
43
+ (payload.cleared && payload.cleared.length ? ' (took off ' + payload.cleared.map(function(entry) {
44
+ return entry.breakpoint;
45
+ }).join(', ') + ')' : ''));
46
+ });
47
+
48
+ $('#output').on('click', function() {
49
+ $('#html').text($('#myGrid').gridEditor('getHtml'));
50
+ });
51
+ });
52
+ </script>
53
+
54
+ <title>Grid Editor column sizes and sections example</title>
55
+ </head>
56
+ <body>
57
+ <!-- Back to the demo index -->
58
+ <div class="container pt-3">
59
+ <a class="link-secondary" href="index.html"><i class="bi bi-arrow-left"></i> All demos</a>
60
+ </div>
61
+
62
+
63
+ <div class="container-fluid px-4">
64
+
65
+ <div class="row my-3">
66
+ <div class="col-lg-8">
67
+ <h1 class="h4">Column sizes, columns per row, and sections</h1>
68
+ <p class="form-text">
69
+ <strong>Equal and auto.</strong> A column is a number of
70
+ twelfths, <em>equal</em> (<code>col</code>: an equal share
71
+ of what the row has left) or <em>auto</em>
72
+ (<code>col-auto</code>: as wide as its content), at each
73
+ breakpoint. Every size is in the <em>Width</em> field of a
74
+ column's settings, under Responsive; the width tools and
75
+ dragging an edge turn an equal or auto column into a
76
+ number, starting from the width it has.
77
+ </p>
78
+ <p class="form-text">
79
+ <strong>Columns per row.</strong> A row's
80
+ <em>Columns per row</em> field shares the line out among
81
+ the columns that have no size of their own. The second
82
+ section's cards are one per line on phones, two on
83
+ tablets, four on desktops.
84
+ </p>
85
+ <p class="form-text">
86
+ <strong>Sections.</strong> Bootstrap's containers, grouping
87
+ rows. Drag rows in and out of them, choose their width in
88
+ their settings, and switch views to see each one as wide
89
+ as its container would be. <strong>All sizes</strong>
90
+ writes one class for every size.
91
+ </p>
92
+ <p class="form-text">Last width change: <span id="last">none yet</span></p>
93
+ <button class="btn btn-sm btn-secondary" id="output" type="button">Show the html this produces</button>
94
+ <pre id="html" class="form-text"></pre>
95
+ </div>
96
+ </div>
97
+
98
+ <div id="myGrid">
99
+
100
+ <div class="container">
101
+ <div class="row">
102
+ <div class="col-auto">
103
+ <h2 class="h5">Auto</h2>
104
+ <p>As wide as this.</p>
105
+ </div>
106
+ <div class="col">
107
+ <h2 class="h5">Equal</h2>
108
+ <p>Takes what the auto column leaves.</p>
109
+ </div>
110
+ <div class="col-3">
111
+ <h2 class="h5">Three</h2>
112
+ <p>A fixed quarter.</p>
113
+ </div>
114
+ </div>
115
+ </div>
116
+
117
+ <div class="container-lg">
118
+ <div class="row row-cols-1 row-cols-sm-2 row-cols-lg-4">
119
+ <div class="col"><h2 class="h6">Card one</h2><p>Shared out by the row.</p></div>
120
+ <div class="col"><h2 class="h6">Card two</h2><p>Shared out by the row.</p></div>
121
+ <div class="col"><h2 class="h6">Card three</h2><p>Shared out by the row.</p></div>
122
+ <div class="col"><h2 class="h6">Card four</h2><p>Shared out by the row.</p></div>
123
+ </div>
124
+ </div>
125
+
126
+ <div class="row">
127
+ <div class="col-12">
128
+ <h2 class="h5">A row outside any section</h2>
129
+ <p>Full width of the canvas. Drag it into one of the sections above.</p>
130
+ </div>
131
+ </div>
132
+
133
+ </div> <!-- /#myGrid -->
134
+ </div> <!-- /.container-fluid -->
135
+
136
+ </body>
137
+ </html>
@@ -20,6 +20,11 @@
20
20
  <script src="../dist/jquery.grideditor.min.js"></script>
21
21
  </head>
22
22
  <body>
23
+ <!-- Back to the demo index -->
24
+ <div class="container pt-3">
25
+ <a class="link-secondary" href="index.html"><i class="bi bi-arrow-left"></i> All demos</a>
26
+ </div>
27
+
23
28
  <div class="container py-3">
24
29
  <h2>Grid Editor example - auto save and import/export</h2>
25
30
  <div class="mb-3">
@@ -37,6 +37,11 @@
37
37
  <title>Grid Editor example</title>
38
38
  </head>
39
39
  <body>
40
+ <!-- Back to the demo index -->
41
+ <div class="container pt-3">
42
+ <a class="link-secondary" href="index.html"><i class="bi bi-arrow-left"></i> All demos</a>
43
+ </div>
44
+
40
45
 
41
46
  <div class="container">
42
47
  <div id="myGrid">
@@ -23,9 +23,10 @@
23
23
  new_row_layouts: [[12], [6,6], [4,4,4], [8,4]],
24
24
  content_types: [],
25
25
 
26
- // The default: every size and offset change is written to all
27
- // six breakpoints at once. Switch the dropdown to a single
28
- // breakpoint to tune that one on its own.
26
+ // The default: a size or offset change is written once, as the
27
+ // class with no breakpoint, and replaces what the breakpoints
28
+ // said. Switch the dropdown to a single breakpoint to tune
29
+ // that one on its own.
29
30
  default_view: 'all',
30
31
 
31
32
  // A host that wants the old three-mode feel can offer three
@@ -41,6 +42,11 @@
41
42
  <title>Grid Editor breakpoints example</title>
42
43
  </head>
43
44
  <body>
45
+ <!-- Back to the demo index -->
46
+ <div class="container pt-3">
47
+ <a class="link-secondary" href="index.html"><i class="bi bi-arrow-left"></i> All demos</a>
48
+ </div>
49
+
44
50
 
45
51
  <div class="container">
46
52
 
@@ -50,8 +56,9 @@
50
56
  <p class="form-text">
51
57
  The dropdown on the right of the toolbar picks the layout
52
58
  mode. In <strong>All sizes</strong> the canvas renders as
53
- the browser would, and the width and indent tools write
54
- every breakpoint at once. Pick a single breakpoint and the
59
+ the browser would, and the width and indent tools write one
60
+ class for every size (<code>col-4</code>), replacing what
61
+ the breakpoints had. Pick a single breakpoint and the
55
62
  canvas narrows to that tier's width, that tier's classes
56
63
  become the effective ones whatever your window is doing,
57
64
  and the tools write only that tier.
@@ -47,6 +47,11 @@
47
47
  <title>Grid Editor example</title>
48
48
  </head>
49
49
  <body>
50
+ <!-- Back to the demo index -->
51
+ <div class="container pt-3">
52
+ <a class="link-secondary" href="index.html"><i class="bi bi-arrow-left"></i> All demos</a>
53
+ </div>
54
+
50
55
 
51
56
  <div class="container">
52
57
  <div id="myGrid">
@@ -70,6 +70,10 @@
70
70
  <title>Grid Editor containers example</title>
71
71
  </head>
72
72
  <body>
73
+ <!-- Back to the demo index -->
74
+ <div class="container pt-3">
75
+ <a class="link-secondary" href="index.html"><i class="bi bi-arrow-left"></i> All demos</a>
76
+ </div>
73
77
 
74
78
  <div class="container">
75
79
 
@@ -89,6 +89,11 @@
89
89
  <title>Grid Editor elements example</title>
90
90
  </head>
91
91
  <body>
92
+ <!-- Back to the demo index -->
93
+ <div class="container pt-3">
94
+ <a class="link-secondary" href="index.html"><i class="bi bi-arrow-left"></i> All demos</a>
95
+ </div>
96
+
92
97
 
93
98
  <div class="container">
94
99