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

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 (103) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/README.md +54 -27
  3. package/UPGRADING.md +1 -1
  4. package/dist/grideditor.bundle.min.js +2 -2
  5. package/dist/grideditor.css +24 -3
  6. package/dist/grideditor.d.ts +27 -2
  7. package/dist/grideditor.esm.js +64 -7
  8. package/dist/grideditor.js +64 -7
  9. package/dist/grideditor.min.css +1 -1
  10. package/dist/grideditor.min.css.map +1 -1
  11. package/dist/grideditor.min.js +1 -1
  12. package/dist/grideditor.min.js.map +3 -3
  13. package/dist/locales/grideditor.es.esm.js +2 -0
  14. package/dist/locales/grideditor.es.js +2 -0
  15. package/dist/locales/grideditor.es.min.js +1 -1
  16. package/dist/locales/grideditor.es.min.js.map +2 -2
  17. package/dist/plugins/grideditor.accordion.esm.js +9 -0
  18. package/dist/plugins/grideditor.accordion.js +9 -0
  19. package/dist/plugins/grideditor.accordion.min.js +1 -1
  20. package/dist/plugins/grideditor.accordion.min.js.map +3 -3
  21. package/dist/plugins/grideditor.card.min.js +1 -1
  22. package/dist/plugins/grideditor.card.min.js.map +1 -1
  23. package/dist/plugins/grideditor.carousel.esm.js +3 -0
  24. package/dist/plugins/grideditor.carousel.js +3 -0
  25. package/dist/plugins/grideditor.carousel.min.js +1 -1
  26. package/dist/plugins/grideditor.carousel.min.js.map +3 -3
  27. package/dist/plugins/grideditor.ckeditor.esm.js +9 -0
  28. package/dist/plugins/grideditor.ckeditor.js +9 -0
  29. package/dist/plugins/grideditor.ckeditor.min.js +1 -1
  30. package/dist/plugins/grideditor.ckeditor.min.js.map +3 -3
  31. package/dist/plugins/grideditor.clipboard.esm.js +44 -7
  32. package/dist/plugins/grideditor.clipboard.js +44 -7
  33. package/dist/plugins/grideditor.clipboard.min.js +1 -1
  34. package/dist/plugins/grideditor.clipboard.min.js.map +3 -3
  35. package/dist/plugins/grideditor.codemirror-inline.min.js.map +1 -1
  36. package/dist/plugins/grideditor.codemirror.min.js.map +1 -1
  37. package/dist/plugins/grideditor.elements.esm.js +3 -0
  38. package/dist/plugins/grideditor.elements.js +3 -0
  39. package/dist/plugins/grideditor.elements.min.js +1 -1
  40. package/dist/plugins/grideditor.elements.min.js.map +3 -3
  41. package/dist/plugins/grideditor.gutters.min.js.map +1 -1
  42. package/dist/plugins/grideditor.history.esm.js +1 -1
  43. package/dist/plugins/grideditor.history.js +1 -1
  44. package/dist/plugins/grideditor.history.min.js +1 -1
  45. package/dist/plugins/grideditor.history.min.js.map +2 -2
  46. package/dist/plugins/grideditor.inline-style.esm.js +66 -3
  47. package/dist/plugins/grideditor.inline-style.js +66 -3
  48. package/dist/plugins/grideditor.inline-style.min.js +4 -4
  49. package/dist/plugins/grideditor.inline-style.min.js.map +3 -3
  50. package/dist/plugins/grideditor.offcanvas.min.js.map +1 -1
  51. package/dist/plugins/grideditor.order.min.js +1 -1
  52. package/dist/plugins/grideditor.order.min.js.map +1 -1
  53. package/dist/plugins/grideditor.popup.min.js.map +1 -1
  54. package/dist/plugins/grideditor.sections.esm.js +9 -0
  55. package/dist/plugins/grideditor.sections.js +9 -0
  56. package/dist/plugins/grideditor.sections.min.js +1 -1
  57. package/dist/plugins/grideditor.sections.min.js.map +3 -3
  58. package/dist/plugins/grideditor.summernote.esm.js +9 -0
  59. package/dist/plugins/grideditor.summernote.js +9 -0
  60. package/dist/plugins/grideditor.summernote.min.js +1 -1
  61. package/dist/plugins/grideditor.summernote.min.js.map +3 -3
  62. package/dist/plugins/grideditor.tabs.esm.js +3 -0
  63. package/dist/plugins/grideditor.tabs.js +3 -0
  64. package/dist/plugins/grideditor.tabs.min.js +1 -1
  65. package/dist/plugins/grideditor.tabs.min.js.map +3 -3
  66. package/dist/plugins/grideditor.tinymce.esm.js +9 -0
  67. package/dist/plugins/grideditor.tinymce.js +9 -0
  68. package/dist/plugins/grideditor.tinymce.min.js +1 -1
  69. package/dist/plugins/grideditor.tinymce.min.js.map +3 -3
  70. package/docs/events.md +6 -1
  71. package/docs/locale-keys.md +2 -0
  72. package/docs/plugins.md +9 -7
  73. package/example/adapter.html +11 -1
  74. package/example/clipboard.html +7 -4
  75. package/example/{autocols.html → columns.html} +61 -20
  76. package/example/containers.html +13 -2
  77. package/example/{attributes.html → custom-plugins.html} +130 -12
  78. package/example/elements.html +13 -2
  79. package/example/history.html +6 -3
  80. package/example/index.html +30 -81
  81. package/example/playground.html +840 -0
  82. package/example/style.html +291 -0
  83. package/example/text-editors.html +320 -0
  84. package/package.json +1 -1
  85. package/src/js/dom.js +6 -0
  86. package/src/js/grideditor.js +69 -7
  87. package/src/js/inline-style/accordion.js +4 -3
  88. package/src/js/inline-style/fields.js +56 -3
  89. package/src/js/inline-style/options.js +12 -0
  90. package/src/js/locales/grideditor.es.js +2 -0
  91. package/src/js/plugins/grideditor.clipboard.js +61 -11
  92. package/src/js/plugins/grideditor.history.js +3 -3
  93. package/src/js/plugins/grideditor.inline-style.js +10 -0
  94. package/src/js/text/grideditor.text.js +1 -1
  95. package/src/less/grideditor.less +26 -3
  96. package/types/grideditor.d.ts +27 -2
  97. package/example/breakpoints.html +0 -100
  98. package/example/ckeditor.html +0 -110
  99. package/example/custom_editor.html +0 -212
  100. package/example/inline-style.html +0 -163
  101. package/example/plugins.html +0 -251
  102. package/example/summernote.html +0 -114
  103. package/example/utilities.html +0 -200
@@ -0,0 +1,840 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+
7
+ <!-- CSS dependencies -->
8
+ <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-sRIl4kxILFvY47J16cr9ZwB07vP4J8+LH7qKQnuqkuIAvNWLzeN8tE5YBujZqJLB" crossorigin="anonymous">
9
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.13.1/font/bootstrap-icons.css">
10
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/codemirror@5.65.21/lib/codemirror.min.css">
11
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ckeditor5@48.5.2/dist/browser/ckeditor5.css">
12
+ <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/summernote/0.9.1/summernote-bs5.min.css" />
13
+
14
+ <!-- Javascript dependencies. jQuery is summernote's alone: the editor
15
+ does not need it -->
16
+ <script src="https://code.jquery.com/jquery-4.0.0.min.js"></script>
17
+ <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>
18
+
19
+ <!-- The three text editors, so content_types can choose among them -->
20
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/tinymce/7.9.3/tinymce.min.js"></script>
21
+ <script src="https://cdn.jsdelivr.net/npm/ckeditor5@48.5.2/dist/browser/ckeditor5.umd.js"></script>
22
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/summernote/0.9.1/summernote-bs5.min.js"></script>
23
+
24
+ <!-- CodeMirror 5 and its html mode, for the codemirror plugins -->
25
+ <script src="https://cdn.jsdelivr.net/npm/codemirror@5.65.21/lib/codemirror.min.js"></script>
26
+ <script src="https://cdn.jsdelivr.net/npm/codemirror@5.65.21/mode/xml/xml.min.js"></script>
27
+ <script src="https://cdn.jsdelivr.net/npm/codemirror@5.65.21/mode/javascript/javascript.min.js"></script>
28
+ <script src="https://cdn.jsdelivr.net/npm/codemirror@5.65.21/mode/css/css.min.js"></script>
29
+ <script src="https://cdn.jsdelivr.net/npm/codemirror@5.65.21/mode/htmlmixed/htmlmixed.min.js"></script>
30
+
31
+ <!-- Grid editor -->
32
+ <link rel="stylesheet" type="text/css" href="../dist/grideditor.css" />
33
+ <script src="https://cdn.jsdelivr.net/npm/sortablejs@1.15.6/Sortable.min.js"></script>
34
+ <script src="../dist/grideditor.min.js"></script>
35
+ <script src="../dist/locales/grideditor.es.js"></script>
36
+
37
+ <!-- Every plugin there is. The page loads them all, and the plugins
38
+ setting chooses which of them the editor uses -->
39
+ <script src="../dist/plugins/grideditor.tinymce.min.js"></script>
40
+ <script src="../dist/plugins/grideditor.ckeditor.min.js"></script>
41
+ <script src="../dist/plugins/grideditor.summernote.min.js"></script>
42
+ <script src="../dist/plugins/grideditor.sections.min.js"></script>
43
+ <script src="../dist/plugins/grideditor.tabs.min.js"></script>
44
+ <script src="../dist/plugins/grideditor.accordion.min.js"></script>
45
+ <script src="../dist/plugins/grideditor.popup.min.js"></script>
46
+ <script src="../dist/plugins/grideditor.offcanvas.min.js"></script>
47
+ <script src="../dist/plugins/grideditor.carousel.min.js"></script>
48
+ <script src="../dist/plugins/grideditor.card.min.js"></script>
49
+ <script src="../dist/plugins/grideditor.order.min.js"></script>
50
+ <script src="../dist/plugins/grideditor.alignment.min.js"></script>
51
+ <script src="../dist/plugins/grideditor.gutters.min.js"></script>
52
+ <!-- Float works on elements, so the elements plugin comes first -->
53
+ <script src="../dist/plugins/grideditor.elements.min.js"></script>
54
+ <script src="../dist/plugins/grideditor.inline-style.min.js"></script>
55
+ <script src="../dist/plugins/grideditor.clipboard.min.js"></script>
56
+ <script src="../dist/plugins/grideditor.history.min.js"></script>
57
+ <script src="../dist/plugins/grideditor.autosave.min.js"></script>
58
+ <script src="../dist/plugins/grideditor.codemirror.min.js"></script>
59
+ <script src="../dist/plugins/grideditor.codemirror-inline.min.js"></script>
60
+
61
+ <style>
62
+ .pg-config .card-header { font-weight: 600; font-size: .875rem; }
63
+ .pg-config .form-label, .pg-config .form-check-label { font-size: .8125rem; }
64
+ .pg-config .form-text { font-size: .75rem; margin-top: 0; }
65
+ .pg-config .pg-field { margin-bottom: .5rem; }
66
+ .pg-config .pg-off { opacity: .45; }
67
+ .pg-code { max-height: 22rem; overflow: auto; font-size: .75rem; }
68
+ #log { max-height: 14rem; overflow: auto; font-size: .75rem; }
69
+ .my-app-quote { border-left: 4px solid var(--bs-secondary-border-subtle); padding-left: 12px; font-style: italic; }
70
+ .my-app-highlight { background: var(--bs-warning-bg-subtle); }
71
+ </style>
72
+
73
+ <title>Grid Editor playground</title>
74
+ </head>
75
+ <body>
76
+ <!-- Back to the demo index -->
77
+ <div class="container-fluid pt-3 px-4">
78
+ <a class="link-secondary" href="index.html"><i class="bi bi-arrow-left"></i> All demos</a>
79
+ </div>
80
+
81
+ <div class="container-fluid px-4 py-3 pg-config">
82
+ <div class="d-flex flex-wrap align-items-center gap-2 mb-2">
83
+ <h1 class="h4 mb-0 me-auto">Playground</h1>
84
+ <button class="btn btn-sm btn-outline-secondary" type="button" data-bs-toggle="collapse" data-bs-target="#settings">
85
+ <i class="bi bi-sliders"></i> Settings
86
+ </button>
87
+ <button class="btn btn-sm btn-outline-secondary" type="button" id="showCode"><i class="bi bi-code-slash"></i> Options as code</button>
88
+ <button class="btn btn-sm btn-outline-secondary" type="button" id="showHtml"><i class="bi bi-filetype-html"></i> Html</button>
89
+ <button class="btn btn-sm btn-outline-secondary" type="button" id="openPage"><i class="bi bi-box-arrow-up-right"></i> Open the result</button>
90
+ <button class="btn btn-sm btn-outline-secondary" type="button" id="share"><i class="bi bi-link-45deg"></i> Copy a link</button>
91
+ <div class="dropdown">
92
+ <button class="btn btn-sm btn-outline-danger dropdown-toggle" type="button" data-bs-toggle="dropdown">Reset</button>
93
+ <ul class="dropdown-menu dropdown-menu-end">
94
+ <li><button class="dropdown-item" type="button" id="resetSettings">The settings</button></li>
95
+ <li><button class="dropdown-item" type="button" id="resetContent">The content</button></li>
96
+ </ul>
97
+ </div>
98
+ </div>
99
+ <p class="text-body-secondary small mb-2">
100
+ Everything the library does, on one canvas. Every plugin is loaded; the settings under
101
+ the editor choose what it uses and how, and each change starts the editor again over the
102
+ same content (<code>getHtml()</code>, <code>destroy()</code>, <code>new GridEditor()</code>).
103
+ The settings are kept in this browser and in the link.
104
+ </p>
105
+
106
+ <div class="alert alert-danger small mt-3 d-none" id="error"></div>
107
+ </div>
108
+
109
+ <div class="container py-3">
110
+ <div id="myGrid"></div>
111
+ </div>
112
+
113
+ <div class="container-fluid px-4 pb-3 pg-config">
114
+ <div class="collapse show" id="settings">
115
+ <div class="row row-cols-1 row-cols-md-2 row-cols-xl-4 g-3" id="groups"></div>
116
+ </div>
117
+ </div>
118
+
119
+ <div class="container-fluid px-4 pb-4">
120
+ <div class="card">
121
+ <div class="card-header d-flex align-items-center small">
122
+ <strong class="me-auto">Events</strong>
123
+ <button class="btn btn-sm btn-link p-0" type="button" id="clearLog">Clear</button>
124
+ </div>
125
+ <ul class="list-group list-group-flush font-monospace" id="log"></ul>
126
+ </div>
127
+ </div>
128
+
129
+ <!-- What the code and html buttons show -->
130
+ <div class="modal fade" id="output" tabindex="-1" aria-hidden="true">
131
+ <div class="modal-dialog modal-xl modal-dialog-scrollable">
132
+ <div class="modal-content">
133
+ <div class="modal-header">
134
+ <h5 class="modal-title" id="outputTitle"></h5>
135
+ <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
136
+ </div>
137
+ <div class="modal-body">
138
+ <div class="btn-group btn-group-sm mb-2 d-none" id="htmlKind">
139
+ <input type="radio" class="btn-check" name="htmlKind" id="kindHtml" value="html" checked>
140
+ <label class="btn btn-outline-secondary" for="kindHtml">getHtml()</label>
141
+ <input type="radio" class="btn-check" name="htmlKind" id="kindPlain" value="plain">
142
+ <label class="btn btn-outline-secondary" for="kindPlain">getPlainHtml()</label>
143
+ </div>
144
+ <pre class="pg-code bg-body-tertiary border rounded p-2 mb-0"><code id="outputCode"></code></pre>
145
+ </div>
146
+ <div class="modal-footer">
147
+ <button type="button" class="btn btn-sm btn-primary" id="copyOutput"><i class="bi bi-clipboard"></i> Copy</button>
148
+ </div>
149
+ </div>
150
+ </div>
151
+ </div>
152
+
153
+ <!-- The content the playground starts with. __TEXT__ is the first text
154
+ editor chosen; with none, the texts are the host's plain content -->
155
+ <template id="sample">
156
+ <div class="container">
157
+ <div class="row">
158
+ <div class="col-12">
159
+ <div class="ge-content" data-ge-content-type="__TEXT__">
160
+ <h2>Grid Editor playground</h2>
161
+ <p>This row lives in a <strong>section</strong> (Bootstrap's <code>.container</code>). Drag, resize, copy, delete, and open any gear to see its settings.</p>
162
+ </div>
163
+ </div>
164
+ </div>
165
+ <div class="row">
166
+ <div class="col-md-4 order-md-2">
167
+ <div class="ge-content" data-ge-content-type="__TEXT__"><p>Units: <code>col-md-4</code>, and first on phones but last from tablet up (<code>order-md-2</code>).</p></div>
168
+ </div>
169
+ <div class="col-md">
170
+ <div class="ge-content" data-ge-content-type="__TEXT__"><p>Equal: <code>col-md</code>, an equal share of what is left.</p></div>
171
+ </div>
172
+ <div class="col-md-auto">
173
+ <div class="ge-content" data-ge-content-type="__TEXT__"><p>Auto: <code>col-md-auto</code>.</p></div>
174
+ </div>
175
+ </div>
176
+ </div>
177
+
178
+ <div class="row row-cols-1 row-cols-md-3 g-4">
179
+ <div class="col">
180
+ <div class="ge-content" data-ge-content-type="__TEXT__"><p>A row with <code>row-cols-md-3</code> and wide gutters (<code>g-4</code>).</p></div>
181
+ </div>
182
+ <div class="col">
183
+ <blockquote class="my-app-quote" data-ge-element="quote" data-ge-label="Pull quote">
184
+ <p>An element: one block to move and delete, never part of a text.</p>
185
+ </blockquote>
186
+ </div>
187
+ <div class="col">
188
+ <div class="ge-content p-3 bg-body-tertiary rounded-3 text-center" data-ge-content-type="__TEXT__"><p>Inline style and Bootstrap's classes: <code>p-3 bg-body-tertiary rounded-3 text-center</code>.</p></div>
189
+ </div>
190
+ </div>
191
+
192
+ <div class="row">
193
+ <div class="col-lg-6">
194
+ <div data-ge-container="tabs">
195
+ <ul class="nav nav-tabs" role="tablist">
196
+ <li class="nav-item" role="presentation">
197
+ <button class="nav-link active" type="button" role="tab" data-bs-toggle="tab" data-bs-target="#pg-tab-one" aria-controls="pg-tab-one" aria-selected="true">Tabs</button>
198
+ </li>
199
+ <li class="nav-item" role="presentation">
200
+ <button class="nav-link" type="button" role="tab" data-bs-toggle="tab" data-bs-target="#pg-tab-two" aria-controls="pg-tab-two">Second</button>
201
+ </li>
202
+ </ul>
203
+ <div class="tab-content">
204
+ <div class="tab-pane fade show active" id="pg-tab-one" role="tabpanel" tabindex="0">
205
+ <div class="row"><div class="col-12">
206
+ <div class="ge-content" data-ge-content-type="__TEXT__"><p>Each tab is a region with rows and columns of its own.</p></div>
207
+ </div></div>
208
+ </div>
209
+ <div class="tab-pane fade" id="pg-tab-two" role="tabpanel" tabindex="0">
210
+ <div class="row"><div class="col-12">
211
+ <div class="ge-content" data-ge-content-type="__TEXT__"><p>The second tab.</p></div>
212
+ </div></div>
213
+ </div>
214
+ </div>
215
+ </div>
216
+ </div>
217
+ <div class="col-lg-6">
218
+ <div data-ge-container="accordion">
219
+ <div class="accordion" id="pg-accordion">
220
+ <div class="accordion-item ge-accordion-item">
221
+ <h2 class="accordion-header">
222
+ <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#pg-item-one" aria-expanded="true">An accordion</button>
223
+ </h2>
224
+ <div id="pg-item-one" class="accordion-collapse collapse show" data-bs-parent="#pg-accordion">
225
+ <div class="accordion-body">
226
+ <div class="row"><div class="col-12">
227
+ <div class="ge-content" data-ge-content-type="__TEXT__"><p>Open in the authored page.</p></div>
228
+ </div></div>
229
+ </div>
230
+ </div>
231
+ </div>
232
+ <div class="accordion-item ge-accordion-item">
233
+ <h2 class="accordion-header">
234
+ <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#pg-item-two" aria-expanded="false">Closed</button>
235
+ </h2>
236
+ <div id="pg-item-two" class="accordion-collapse collapse" data-bs-parent="#pg-accordion">
237
+ <div class="accordion-body">
238
+ <div class="row"><div class="col-12">
239
+ <div class="ge-content" data-ge-content-type="__TEXT__"><p>Closed in the authored page.</p></div>
240
+ </div></div>
241
+ </div>
242
+ </div>
243
+ </div>
244
+ </div>
245
+ </div>
246
+ </div>
247
+ </div>
248
+
249
+ <div class="row">
250
+ <div class="col-md-6">
251
+ <div data-ge-container="card">
252
+ <div class="card">
253
+ <div class="card-header">A card</div>
254
+ <div class="card-body">
255
+ <div class="row"><div class="col-12">
256
+ <div class="ge-content" data-ge-content-type="__TEXT__"><p>Its body is one region. Double click the header to rewrite it.</p></div>
257
+ </div></div>
258
+ </div>
259
+ </div>
260
+ </div>
261
+ </div>
262
+ <div class="col-md-3">
263
+ <div data-ge-container="popup" data-ge-popup-id="pg-popup">
264
+ <button type="button" class="btn btn-primary ge-popup-trigger" data-ge-popup-target="pg-popup">A popup</button>
265
+ <div class="modal fade" id="pg-popup" tabindex="-1" aria-hidden="true">
266
+ <div class="modal-dialog">
267
+ <div class="modal-content">
268
+ <div class="modal-header">
269
+ <h5 class="modal-title">A popup</h5>
270
+ <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
271
+ </div>
272
+ <div class="modal-body">
273
+ <div class="row"><div class="col-12">
274
+ <div class="ge-content" data-ge-content-type="__TEXT__"><p>Unfolded in place while editing; press the preview eye to try it closed.</p></div>
275
+ </div></div>
276
+ </div>
277
+ </div>
278
+ </div>
279
+ </div>
280
+ </div>
281
+ </div>
282
+ <div class="col-md-3">
283
+ <div data-ge-container="offcanvas" data-ge-offcanvas-id="pg-offcanvas">
284
+ <button type="button" class="btn btn-primary ge-offcanvas-trigger" data-ge-offcanvas-target="pg-offcanvas">An offcanvas</button>
285
+ <div class="offcanvas offcanvas-end" tabindex="-1" id="pg-offcanvas" aria-labelledby="pg-offcanvas-label">
286
+ <div class="offcanvas-header">
287
+ <h5 class="offcanvas-title" id="pg-offcanvas-label">An offcanvas</h5>
288
+ <button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
289
+ </div>
290
+ <div class="offcanvas-body">
291
+ <div class="row"><div class="col-12">
292
+ <div class="ge-content" data-ge-content-type="__TEXT__"><p>Slides in from the end on the page.</p></div>
293
+ </div></div>
294
+ </div>
295
+ </div>
296
+ </div>
297
+ </div>
298
+ </div>
299
+
300
+ <div class="row">
301
+ <div class="col-12">
302
+ <div data-ge-container="carousel">
303
+ <div class="carousel slide" id="pg-carousel">
304
+ <div class="carousel-indicators">
305
+ <button type="button" data-bs-target="#pg-carousel" data-bs-slide-to="0" class="active" aria-current="true" aria-label="Slide 1"></button>
306
+ <button type="button" data-bs-target="#pg-carousel" data-bs-slide-to="1" aria-label="Slide 2"></button>
307
+ </div>
308
+ <div class="carousel-inner">
309
+ <div class="carousel-item active">
310
+ <div class="row"><div class="col-12">
311
+ <div class="ge-content p-5 text-center bg-body-secondary" data-ge-content-type="__TEXT__"><p>A carousel. Its drawer's arrows change the slide.</p></div>
312
+ </div></div>
313
+ </div>
314
+ <div class="carousel-item">
315
+ <div class="row"><div class="col-12">
316
+ <div class="ge-content p-5 text-center bg-body-secondary" data-ge-content-type="__TEXT__"><p>The second slide.</p></div>
317
+ </div></div>
318
+ </div>
319
+ </div>
320
+ <button class="carousel-control-prev" type="button" data-bs-target="#pg-carousel" data-bs-slide="prev">
321
+ <span class="carousel-control-prev-icon" aria-hidden="true"></span>
322
+ <span class="visually-hidden">Previous</span>
323
+ </button>
324
+ <button class="carousel-control-next" type="button" data-bs-target="#pg-carousel" data-bs-slide="next">
325
+ <span class="carousel-control-next-icon" aria-hidden="true"></span>
326
+ <span class="visually-hidden">Next</span>
327
+ </button>
328
+ </div>
329
+ </div>
330
+ </div>
331
+ </div>
332
+ </template>
333
+
334
+ <script>
335
+ (function() {
336
+ var grid = document.getElementById('myGrid');
337
+ var STORE = 'grideditor.playground';
338
+ var editor = null;
339
+ var lastHtml;
340
+
341
+ var VIEWS = ['all', 'xs', 'sm', 'md', 'lg', 'xl', 'xxl'];
342
+
343
+ /*
344
+ * The settings, as fields. `path` is where the value goes in the
345
+ * options; a value equal to `default` is left out of them, so the
346
+ * code shown is only what differs from the library's defaults.
347
+ * `plugin` greys a field out while that plugin is off.
348
+ */
349
+ var GROUPS = [
350
+ { title: 'Interface', fields: [
351
+ { id: 'locale', label: 'Language', type: 'select', options: [['en', 'English'], ['es', 'Español']], default: 'en' },
352
+ { id: 'settings_panel', label: 'Settings open in', type: 'select', default: 'offcanvas',
353
+ options: [['offcanvas', 'An offcanvas'], ['popover', 'A popover'], ['modal', 'A modal'], ['inline', 'The drawer (inline)'], ['sidebar', 'A sidebar that stays']] },
354
+ { id: 'active_target', label: 'A click makes a node the target', type: 'check', default: false,
355
+ help: 'Where the toolbar adds, and Ctrl+C / X / V. The sidebar turns it on',
356
+ disabled: function(s) { return s.settings_panel === 'sidebar'; } },
357
+ { id: 'confirm_delete', label: 'Ask before deleting', type: 'check', default: true },
358
+ { id: 'edit_source', label: 'Source button on the toolbar', type: 'check', default: true },
359
+ { id: 'toolbar_groups', label: 'Toolbar in categories', type: 'check', default: false },
360
+ { id: 'toolbar_overflow', label: 'Toolbar that does not fit', type: 'select', default: 'menu', options: [['menu', 'A ⋯ menu'], ['wrap', 'Wraps']] },
361
+ { id: 'drawer_overflow', label: 'Drawers that do not fit', type: 'select', default: 'menu', options: [['menu', 'A ⋯ tool'], ['wrap', 'Wrap']] },
362
+ ] },
363
+ { title: 'Grid', fields: [
364
+ { id: 'new_row_layouts', label: 'New row layouts (JSON)', type: 'json', always: true,
365
+ default: [[12], [6, 6], [4, 4, 4], [8, 4], ['auto', 'equal'], { row_cols: { xs: 1, md: 3 }, columns: 3 }] },
366
+ { id: 'default_view', label: 'Starting view', type: 'select', default: 'all', options: VIEWS.map(function(v) { return [v, v === 'all' ? 'All sizes' : v]; }) },
367
+ { id: 'layout_modes', label: 'Views offered', type: 'multi', default: VIEWS.slice(), options: VIEWS },
368
+ { id: 'row_cols', label: 'Columns per row field', type: 'check', default: true },
369
+ { id: 'indent.tools', label: 'Indent tools', type: 'check', default: true },
370
+ { id: 'add_column.size', label: 'Add column adds', type: 'select', default: 12, options: [[12, '12 units'], [6, '6 units'], [4, '4 units'], ['equal', 'Equal'], ['auto', 'Auto']] },
371
+ { id: 'add_column.picker', label: 'Hold add column for a picker', type: 'check', default: true },
372
+ ] },
373
+ { title: 'Drag and resize', fields: [
374
+ { id: 'drag_handle', label: 'A drag starts from', type: 'select', default: 'tool', options: [['tool', 'The move tool'], ['drawer', 'The whole drawer']] },
375
+ { id: 'toolbar_drag', label: 'Drag toolbar buttons onto the canvas', type: 'select', default: 'auto', options: [['auto', 'Auto (with the drawer handle)'], [true, 'Yes'], [false, 'No']] },
376
+ { id: 'drag.animation', label: 'Reorder animation (ms)', type: 'number', default: 150 },
377
+ { id: 'drag.touch_delay', label: 'Touch hold before a drag (ms)', type: 'number', default: 100 },
378
+ { id: 'resize.enabled', label: 'Resize by dragging the edge', type: 'check', default: true },
379
+ { id: 'resize.tools', label: 'The − + tools', type: 'check', default: true },
380
+ { id: 'resize.handles', label: 'Resize handles', type: 'select', default: 'e', options: [['e', 'End'], ['w', 'Start'], ['e, w', 'Both']] },
381
+ { id: 'resize.balance', label: 'On resize', type: 'select', default: 'next', options: [['next', 'The next column makes up'], [false, 'The row wraps']] },
382
+ ] },
383
+ { title: 'Text editors', fields: [
384
+ { id: 'content_types', label: 'Offered, in this order', type: 'multi', always: true, default: ['tinymce'],
385
+ options: [['tinymce', 'TinyMCE'], ['ckeditor', 'CKEditor 5'], ['summernote', 'Summernote']],
386
+ help: 'None leaves the texts as plain content, edited in the source' },
387
+ ] },
388
+ { title: 'Plugins', id: 'plugins', fields: [] },
389
+ { title: 'Plugin options', fields: [
390
+ { id: 'history.buttons', plugin: 'history', label: 'Undo / redo buttons', type: 'check', default: true },
391
+ { id: 'history.shortcuts', plugin: 'history', label: 'Ctrl+Z / Ctrl+Y', type: 'check', default: true },
392
+ { id: 'clipboard.shortcuts', plugin: 'clipboard', label: 'Ctrl+C / X / V', type: 'check', default: true,
393
+ help: 'Only with a target', disabled: function(s) { return !s.active_target && s.settings_panel !== 'sidebar'; } },
394
+ { id: 'autosave.enabled', plugin: 'autosave', label: 'Autosave drafts', type: 'check', default: true },
395
+ { id: 'autosave.storage', plugin: 'autosave', label: 'Drafts kept in', type: 'select', default: 'local', options: [['local', 'localStorage'], ['session', 'sessionStorage']] },
396
+ { id: 'elements.types', plugin: 'elements', label: 'Element buttons on the toolbar', type: 'check', default: false,
397
+ value: function() { return ELEMENT_TYPES; } },
398
+ { id: 'inline_style.visibility.drawer', plugin: 'inline-style', label: 'Eye in the drawers', type: 'check', default: true },
399
+ { id: 'utilities.order.drawer', plugin: 'order', label: 'Order arrows in column drawers', type: 'check', default: true },
400
+ { id: 'sections.widths', plugin: 'sections', label: 'Section widths offered', type: 'multi', default: ['fixed', 'sm', 'md', 'lg', 'xl', 'xxl', 'fluid'],
401
+ options: ['fixed', 'sm', 'md', 'lg', 'xl', 'xxl', 'fluid'] },
402
+ ] },
403
+ { title: 'New containers', fields: [
404
+ { id: 'tabs.variant', plugin: 'tabs', label: 'Tabs', type: 'select', default: 'tabs', options: [['tabs', 'Tabs'], ['pills', 'Pills'], ['underline', 'Underline']] },
405
+ { id: 'tabs.width', plugin: 'tabs', label: 'Tabs width', type: 'select', default: 'natural', options: [['natural', 'Natural'], ['fill', 'Fill'], ['justified', 'Justified']] },
406
+ { id: 'tabs.vertical', plugin: 'tabs', label: 'Tabs vertical', type: 'select', default: false, options: [[false, 'No'], [true, 'Always'], ['md', 'From md'], ['lg', 'From lg']] },
407
+ { id: 'carousel.fade', plugin: 'carousel', label: 'Carousel fades', type: 'check', default: false },
408
+ { id: 'carousel.dark', plugin: 'carousel', label: 'Dark carousel', type: 'check', default: false },
409
+ { id: 'carousel.slides', plugin: 'carousel', label: 'Carousel slides', type: 'number', default: 2 },
410
+ { id: 'offcanvas.placement', plugin: 'offcanvas', label: 'Offcanvas from', type: 'select', default: 'start', options: [['start', 'Start'], ['end', 'End'], ['top', 'Top'], ['bottom', 'Bottom']] },
411
+ { id: 'offcanvas.backdrop', plugin: 'offcanvas', label: 'Offcanvas backdrop', type: 'select', default: true, options: [[true, 'Yes'], [false, 'No'], ['static', 'Static']] },
412
+ ] },
413
+ { title: 'Host extensions', fields: [
414
+ { id: 'presets', label: 'Preset classes in the panels', type: 'check', default: false, help: 'row_classes, col_classes, text_classes' },
415
+ { id: 'tools', label: 'Host tools in the drawers', type: 'check', default: false, help: 'row_tools, col_tools, text_tools, element_tools' },
416
+ { id: 'cancel_delete', label: 'Cancel deleting the first row', type: 'check', default: false, help: 'callbacks.before_delete returning false' },
417
+ ] },
418
+ ];
419
+
420
+ var ELEMENT_TYPES = [
421
+ { type: 'quote', label: 'Quote', iconClass: 'bi bi-quote',
422
+ html: '<blockquote class="my-app-quote"><p>A new quote.</p></blockquote>' },
423
+ { type: 'divider', label: 'Divider', iconClass: 'bi bi-dash-lg', html: '<hr>' },
424
+ { type: 'button', label: 'Button', iconClass: 'bi bi-hand-index', html: '<a class="btn btn-primary" href="#">A button</a>' },
425
+ ];
426
+
427
+ // Every plugin the page loaded, but the text editors: content_types chooses those
428
+ var PLUGINS = [];
429
+ ['containers', 'features', 'utilities'].forEach(function(registry) {
430
+ Object.keys(GridEditor[registry]).forEach(function(name) {
431
+ if (GridEditor[registry][name].always !== true) { PLUGINS.push(name); }
432
+ });
433
+ });
434
+
435
+ var FIELDS = {};
436
+ GROUPS.forEach(function(group) {
437
+ group.fields.forEach(function(field) { FIELDS[field.id] = field; });
438
+ });
439
+
440
+ // ---- state ----------------------------------------------------
441
+
442
+ function defaults() {
443
+ var state = { plugins: PLUGINS.slice() };
444
+ Object.keys(FIELDS).forEach(function(id) { state[id] = FIELDS[id].default; });
445
+ return state;
446
+ }
447
+
448
+ function load() {
449
+ var saved = null;
450
+ try {
451
+ if (location.hash.length > 1) { saved = JSON.parse(decodeURIComponent(escape(atob(location.hash.slice(1))))); }
452
+ } catch (e) { /* a link that is not ours */ }
453
+ if (!saved) {
454
+ try { saved = JSON.parse(localStorage.getItem(STORE)); } catch (e) { /* no storage */ }
455
+ }
456
+ return Object.assign(defaults(), saved || {});
457
+ }
458
+
459
+ function save() {
460
+ var changed = {};
461
+ var base = defaults();
462
+ Object.keys(state).forEach(function(id) {
463
+ if (JSON.stringify(state[id]) !== JSON.stringify(base[id])) { changed[id] = state[id]; }
464
+ });
465
+ try { localStorage.setItem(STORE, JSON.stringify(changed)); } catch (e) { /* no storage */ }
466
+ var hash = Object.keys(changed).length ? '#' + btoa(unescape(encodeURIComponent(JSON.stringify(changed)))) : '';
467
+ history.replaceState(null, '', location.pathname + location.search + hash);
468
+ }
469
+
470
+ var state = load();
471
+
472
+ // ---- the options ----------------------------------------------
473
+
474
+ function setPath(target, path, value) {
475
+ var keys = path.split('.');
476
+ keys.slice(0, -1).forEach(function(key) { target = target[key] = target[key] || {}; });
477
+ target[keys[keys.length - 1]] = value;
478
+ }
479
+
480
+ function pluginOn(name) { return state.plugins.indexOf(name) !== -1; }
481
+
482
+ function isDisabled(field) {
483
+ return (field.plugin && !pluginOn(field.plugin)) || (field.disabled && field.disabled(state));
484
+ }
485
+
486
+ function options() {
487
+ var opts = {};
488
+ var hostOnly = ['presets', 'tools', 'cancel_delete'];
489
+
490
+ Object.keys(FIELDS).forEach(function(id) {
491
+ var field = FIELDS[id];
492
+ if (hostOnly.indexOf(id) !== -1 || isDisabled(field)) { return; }
493
+ var value = state[id];
494
+ if (!field.always && JSON.stringify(value) === JSON.stringify(field.default)) { return; }
495
+ setPath(opts, id, field.value ? field.value() : value);
496
+ });
497
+
498
+ if (state.plugins.length !== PLUGINS.length) { opts.plugins = state.plugins.slice(); }
499
+
500
+ // Both editors are GPL-2.0-or-later, and these accept that licence.
501
+ // A commercial licence passes its own key here instead
502
+ if (state.content_types.indexOf('tinymce') !== -1) { opts.tinymce = { config: { license_key: 'gpl' } }; }
503
+ if (state.content_types.indexOf('ckeditor') !== -1) { opts.ckeditor = { config: { licenseKey: 'GPL' } }; }
504
+
505
+ if (state.presets) {
506
+ opts.row_classes = [{ label: 'Highlight', cssClass: 'my-app-highlight' }];
507
+ opts.col_classes = [{ label: 'Highlight', cssClass: 'my-app-highlight' }, { label: 'Shadow', cssClass: 'shadow' }];
508
+ opts.text_classes = [{ label: 'Lead', cssClass: 'lead' }];
509
+ }
510
+ if (state.tools) {
511
+ var tool = [{ title: 'A host tool', iconClass: 'bi bi-star',
512
+ on: { click: function() { alert('The host decides what this does with ' + this.closest('[class]').className); } } }];
513
+ opts.row_tools = tool;
514
+ opts.col_tools = tool;
515
+ opts.text_tools = tool;
516
+ if (pluginOn('elements')) { opts.element_tools = tool; }
517
+ }
518
+ if (state.cancel_delete) {
519
+ opts.callbacks = {
520
+ before_delete: function(payload) {
521
+ var first = grid.querySelector('.row');
522
+ if (payload.node === first) { alert('The host keeps the first row.'); return false; }
523
+ },
524
+ };
525
+ }
526
+ return opts;
527
+ }
528
+
529
+ // The options as code to paste: functions as they are written
530
+ function toCode(value, indent) {
531
+ indent = indent || '';
532
+ var next = indent + ' ';
533
+ if (typeof value === 'function') { return value.toString().replace(/\n {24}/g, '\n' + indent); }
534
+ // What fits on a line goes on one
535
+ var inline = function(v) {
536
+ if (Array.isArray(v)) { return '[' + v.map(inline).join(', ') + ']'; }
537
+ if (v && typeof v === 'object') {
538
+ return '{ ' + Object.keys(v).map(function(k) { return k + ': ' + inline(v[k]); }).join(', ') + ' }';
539
+ }
540
+ return toCode(v);
541
+ };
542
+ if (value && typeof value === 'object' && JSON.stringify(value).indexOf('"html"') === -1 &&
543
+ !/function/.test(inline(value)) && indent.length + inline(value).length < 90) {
544
+ return inline(value);
545
+ }
546
+ if (Array.isArray(value)) {
547
+ return '[\n' + value.map(function(v) { return next + toCode(v, next); }).join(',\n') + ',\n' + indent + ']';
548
+ }
549
+ if (value && typeof value === 'object') {
550
+ var keys = Object.keys(value);
551
+ if (!keys.length) { return '{}'; }
552
+ return '{\n' + keys.map(function(key) {
553
+ var name = /^[a-z_$][\w$]*$/i.test(key) ? key : JSON.stringify(key);
554
+ return next + name + ': ' + toCode(value[key], next);
555
+ }).join(',\n') + ',\n' + indent + '}';
556
+ }
557
+ return typeof value === 'string' ? "'" + value.replace(/'/g, "\\'") + "'" : String(value);
558
+ }
559
+
560
+ // ---- the editor -----------------------------------------------
561
+
562
+ function sample() {
563
+ var type = state.content_types[0];
564
+ var html = document.getElementById('sample').innerHTML;
565
+ return type ? html.replace(/__TEXT__/g, type) : html.replace(/ data-ge-content-type="__TEXT__"/g, '');
566
+ }
567
+
568
+ function start(html) {
569
+ var error = document.getElementById('error');
570
+ error.classList.add('d-none');
571
+ if (editor) {
572
+ html = html === undefined ? editor.getHtml() : html;
573
+ editor.destroy();
574
+ }
575
+ // After an editor that failed to start, what it was given
576
+ html = html === undefined ? lastHtml : html;
577
+ grid.innerHTML = lastHtml = html === undefined ? sample() : html;
578
+ try {
579
+ editor = new GridEditor(grid, options());
580
+ } catch (e) {
581
+ editor = null;
582
+ error.textContent = e.message;
583
+ error.classList.remove('d-none');
584
+ }
585
+ window.editor = editor; // to try the methods from the console
586
+ }
587
+
588
+ // ---- the settings, drawn --------------------------------------
589
+
590
+ function optionValue(option) { return Array.isArray(option) ? option[0] : option; }
591
+ function optionLabel(option) { return Array.isArray(option) ? option[1] : option; }
592
+
593
+ function fieldNode(field) {
594
+ var wrap = document.createElement('div');
595
+ wrap.className = 'pg-field';
596
+ wrap.dataset.field = field.id;
597
+ var key = 'f-' + field.id.replace(/\W/g, '-');
598
+ var html = '';
599
+
600
+ if (field.type === 'check') {
601
+ html = '<div class="form-check form-switch"><input class="form-check-input" type="checkbox" id="' + key + '">' +
602
+ '<label class="form-check-label" for="' + key + '">' + field.label + '</label></div>';
603
+ } else if (field.type === 'select') {
604
+ html = '<label class="form-label mb-0" for="' + key + '">' + field.label + '</label>' +
605
+ '<select class="form-select form-select-sm" id="' + key + '">' +
606
+ field.options.map(function(o, i) { return '<option value="' + i + '">' + optionLabel(o) + '</option>'; }).join('') +
607
+ '</select>';
608
+ } else if (field.type === 'number') {
609
+ html = '<label class="form-label mb-0" for="' + key + '">' + field.label + '</label>' +
610
+ '<input class="form-control form-control-sm" type="number" min="0" id="' + key + '">';
611
+ } else if (field.type === 'json') {
612
+ html = '<label class="form-label mb-0" for="' + key + '">' + field.label + '</label>' +
613
+ '<textarea class="form-control form-control-sm font-monospace" rows="3" id="' + key + '"></textarea>';
614
+ } else if (field.type === 'multi') {
615
+ html = '<div class="form-label mb-0">' + field.label + '</div><div>' +
616
+ field.options.map(function(o, i) {
617
+ return '<div class="form-check form-check-inline"><input class="form-check-input" type="checkbox" id="' + key + '-' + i + '" value="' + i + '">' +
618
+ '<label class="form-check-label" for="' + key + '-' + i + '">' + optionLabel(o) + '</label></div>';
619
+ }).join('') + '</div>';
620
+ }
621
+ if (field.help) { html += '<div class="form-text">' + field.help + '</div>'; }
622
+ wrap.innerHTML = html;
623
+ wrap.addEventListener('change', function(e) { read(field, wrap, e.target); });
624
+ return wrap;
625
+ }
626
+
627
+ function read(field, wrap, input) {
628
+ if (field.type === 'check') {
629
+ state[field.id] = input.checked;
630
+ } else if (field.type === 'select') {
631
+ state[field.id] = optionValue(field.options[input.value]);
632
+ } else if (field.type === 'number') {
633
+ state[field.id] = input.value === '' ? field.default : Number(input.value);
634
+ } else if (field.type === 'json') {
635
+ try {
636
+ state[field.id] = JSON.parse(input.value);
637
+ input.classList.remove('is-invalid');
638
+ } catch (e) {
639
+ input.classList.add('is-invalid');
640
+ return;
641
+ }
642
+ } else if (field.type === 'multi') {
643
+ // In the order of the options, but content_types in the order ticked
644
+ var ticked = [].slice.call(wrap.querySelectorAll('input:checked')).map(function(box) {
645
+ return optionValue(field.options[box.value]);
646
+ });
647
+ if (field.id === 'content_types') {
648
+ var kept = state.content_types.filter(function(t) { return ticked.indexOf(t) !== -1; });
649
+ ticked = kept.concat(ticked.filter(function(t) { return kept.indexOf(t) === -1; }));
650
+ }
651
+ state[field.id] = ticked;
652
+ }
653
+ changed();
654
+ }
655
+
656
+ function write(field, wrap) {
657
+ var value = state[field.id];
658
+ var input = wrap.querySelector('input, select, textarea');
659
+ var index = function(v) {
660
+ return field.options.findIndex(function(o) { return optionValue(o) === v; });
661
+ };
662
+ if (field.type === 'check') {
663
+ input.checked = field.disabled && field.disabled(state) && field.id === 'active_target' ? true : !!value;
664
+ } else if (field.type === 'select') {
665
+ input.value = String(Math.max(0, index(value)));
666
+ } else if (field.type === 'number') {
667
+ input.value = value;
668
+ } else if (field.type === 'json') {
669
+ if (document.activeElement !== input) { input.value = JSON.stringify(value); }
670
+ } else if (field.type === 'multi') {
671
+ wrap.querySelectorAll('input').forEach(function(box) {
672
+ box.checked = value.indexOf(optionValue(field.options[box.value])) !== -1;
673
+ });
674
+ }
675
+ var off = isDisabled(field);
676
+ wrap.classList.toggle('pg-off', !!off);
677
+ wrap.querySelectorAll('input, select, textarea').forEach(function(i) { i.disabled = !!off; });
678
+ }
679
+
680
+ function pluginsNode() {
681
+ var wrap = document.createElement('div');
682
+ wrap.innerHTML =
683
+ '<div class="d-flex gap-2 mb-1"><button type="button" class="btn btn-link btn-sm p-0" data-all="1">All</button>' +
684
+ '<button type="button" class="btn btn-link btn-sm p-0" data-all="0">None</button></div>' +
685
+ PLUGINS.map(function(name) {
686
+ return '<div class="form-check form-switch"><input class="form-check-input" type="checkbox" id="p-' + name + '" value="' + name + '">' +
687
+ '<label class="form-check-label" for="p-' + name + '">' + name + '</label></div>';
688
+ }).join('') +
689
+ '<div class="form-text">The <code>plugins</code> setting: what is not named is loaded but not used</div>';
690
+ wrap.addEventListener('change', function() {
691
+ state.plugins = [].slice.call(wrap.querySelectorAll('input:checked')).map(function(box) { return box.value; });
692
+ changed();
693
+ });
694
+ wrap.querySelectorAll('[data-all]').forEach(function(button) {
695
+ button.addEventListener('click', function() {
696
+ state.plugins = button.dataset.all === '1' ? PLUGINS.slice() : [];
697
+ changed();
698
+ });
699
+ });
700
+ return wrap;
701
+ }
702
+
703
+ function render() {
704
+ var root = document.getElementById('groups');
705
+ root.innerHTML = '';
706
+ GROUPS.forEach(function(group) {
707
+ var col = document.createElement('div');
708
+ col.className = 'col';
709
+ col.innerHTML = '<div class="card h-100"><div class="card-header py-1">' + group.title + '</div><div class="card-body py-2"></div></div>';
710
+ var body = col.querySelector('.card-body');
711
+ if (group.id === 'plugins') { body.appendChild(pluginsNode()); }
712
+ group.fields.forEach(function(field) { body.appendChild(fieldNode(field)); });
713
+ root.appendChild(col);
714
+ });
715
+ refresh();
716
+ }
717
+
718
+ function refresh() {
719
+ Object.keys(FIELDS).forEach(function(id) {
720
+ write(FIELDS[id], document.querySelector('[data-field="' + id + '"]'));
721
+ });
722
+ PLUGINS.forEach(function(name) {
723
+ document.getElementById('p-' + name).checked = pluginOn(name);
724
+ });
725
+ }
726
+
727
+ var timer;
728
+ function changed() {
729
+ refresh();
730
+ save();
731
+ clearTimeout(timer);
732
+ timer = setTimeout(function() { start(); }, 150);
733
+ }
734
+
735
+ // ---- the buttons ----------------------------------------------
736
+
737
+ var modal = new bootstrap.Modal(document.getElementById('output'));
738
+ var outputCode = document.getElementById('outputCode');
739
+ var htmlKind = document.getElementById('htmlKind');
740
+
741
+ function showHtml() {
742
+ if (!editor) { return; }
743
+ var plain = document.getElementById('kindPlain').checked;
744
+ outputCode.textContent = plain ? editor.getPlainHtml({ keepEditing: true }) : editor.getHtml({ keepEditing: true });
745
+ }
746
+
747
+ document.getElementById('showCode').addEventListener('click', function() {
748
+ document.getElementById('outputTitle').textContent = 'The options';
749
+ htmlKind.classList.add('d-none');
750
+ outputCode.textContent = "var editor = new GridEditor('#myGrid', " + toCode(options()) + ');';
751
+ modal.show();
752
+ });
753
+
754
+ document.getElementById('showHtml').addEventListener('click', function() {
755
+ document.getElementById('outputTitle').textContent = 'The html';
756
+ htmlKind.classList.remove('d-none');
757
+ showHtml();
758
+ modal.show();
759
+ });
760
+ htmlKind.addEventListener('change', showHtml);
761
+
762
+ document.getElementById('copyOutput').addEventListener('click', function() {
763
+ navigator.clipboard.writeText(outputCode.textContent);
764
+ });
765
+
766
+ document.getElementById('openPage').addEventListener('click', function() {
767
+ if (!editor) { return; }
768
+ var html = editor.getPlainHtml({ keepEditing: true });
769
+ var page = window.open('', '_blank');
770
+ // The output in a page with Bootstrap and nothing else: tabs,
771
+ // accordion, popup, offcanvas and carousel run on Bootstrap's own JS
772
+ page.document.write(
773
+ '<!DOCTYPE html><html><head><meta name="viewport" content="width=device-width, initial-scale=1">' +
774
+ '<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css" rel="stylesheet">' +
775
+ '<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/js/bootstrap.bundle.min.js"><\/script>' +
776
+ '<style>' + document.querySelector('style').textContent + '</style>' +
777
+ '</head><body><div class="container py-4">' + html + '</div></body></html>'
778
+ );
779
+ page.document.close();
780
+ });
781
+
782
+ document.getElementById('share').addEventListener('click', function() {
783
+ navigator.clipboard.writeText(location.href);
784
+ this.innerHTML = '<i class="bi bi-check2"></i> Copied';
785
+ var button = this;
786
+ setTimeout(function() { button.innerHTML = '<i class="bi bi-link-45deg"></i> Copy a link'; }, 1500);
787
+ });
788
+
789
+ document.getElementById('resetSettings').addEventListener('click', function() {
790
+ state = defaults();
791
+ changed();
792
+ });
793
+
794
+ document.getElementById('resetContent').addEventListener('click', function() {
795
+ start(sample());
796
+ if (editor && editor.clearDraft) { editor.clearDraft(); }
797
+ if (editor && editor.clearHistory) { editor.clearHistory(); }
798
+ });
799
+
800
+ // ---- the events -----------------------------------------------
801
+
802
+ var log = document.getElementById('log');
803
+ var EVENTS = ['after-add', 'after-delete', 'after-move', 'after-resize', 'after-indent', 'after-utility',
804
+ 'after-convert', 'after-edit-html', 'after-copy', 'view-change', 'preview-change', 'target-change',
805
+ 'after-undo', 'after-redo', 'after-autosave', 'after-restore-draft'];
806
+
807
+ function describe(node) {
808
+ if (!node || !node.tagName) { return node === null ? 'null' : ''; }
809
+ return node.tagName.toLowerCase() + (node.id ? '#' + node.id : '') +
810
+ [].slice.call(node.classList, 0, 3).map(function(c) { return '.' + c; }).join('');
811
+ }
812
+
813
+ EVENTS.forEach(function(name) {
814
+ grid.addEventListener('grideditor:' + name, function(e) {
815
+ var d = e.detail || {};
816
+ var parts = [];
817
+ ['kind', 'source', 'family', 'breakpoint', 'view', 'from', 'to', 'pressed', 'cut'].forEach(function(key) {
818
+ if (d[key] === undefined || (key !== 'from' && key !== 'to' && typeof d[key] === 'object')) { return; }
819
+ parts.push(key + '=' + (typeof d[key] === 'object' ? describe(d[key]) : d[key]));
820
+ });
821
+ if (d.node) { parts.push(describe(d.node)); }
822
+ if (name === 'target-change') { parts.push('→ ' + describe(d.target)); }
823
+ var item = document.createElement('li');
824
+ item.className = 'list-group-item py-1';
825
+ item.innerHTML = '<span class="text-body-secondary">' + new Date().toLocaleTimeString() + '</span> ' +
826
+ '<strong></strong> <span></span>';
827
+ item.querySelector('strong').textContent = name;
828
+ item.lastChild.textContent = parts.join(' ');
829
+ log.prepend(item);
830
+ while (log.children.length > 100) { log.lastChild.remove(); }
831
+ });
832
+ });
833
+ document.getElementById('clearLog').addEventListener('click', function() { log.innerHTML = ''; });
834
+
835
+ render();
836
+ start();
837
+ })();
838
+ </script>
839
+ </body>
840
+ </html>