@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
@@ -7,7 +7,7 @@
7
7
  * … classes. What it can ask the editor for is the handle its factory is
8
8
  * called with, described in docs/plugins.md.
9
9
  *
10
- * <script src="dist/jquery.grideditor.min.js"></script>
10
+ * <script src="dist/grideditor.min.js"></script>
11
11
  * <script src="dist/plugins/grideditor.spacing.min.js"></script>
12
12
  *
13
13
  * Fourteen families would be fourteen fields, so the panel has two, padding
@@ -17,9 +17,10 @@
17
17
  * utilities.spacing.scale is what 0 to 5 come to, for a page that changed
18
18
  * Bootstrap's $spacers.
19
19
  */
20
- (function($) {
20
+ import { GridEditor } from '../grideditor.js';
21
+ import * as dom from '../dom.js';
21
22
 
22
- $.extend($.fn.gridEditor.locales.en, {
23
+ Object.assign(GridEditor.locales.en, {
23
24
  'utility.padding': 'Padding',
24
25
  'utility.margin': 'Margin',
25
26
  'utility.side_all': 'All sides',
@@ -63,18 +64,18 @@ function pattern(key) {
63
64
  return new RegExp('^' + key + '[xytbse]?-(?:(?:sm|md|lg|xl|xxl)-)?(?:[0-5]|auto)$');
64
65
  }
65
66
 
66
- $.fn.gridEditor.utilities.spacing = function(ge) {
67
+ GridEditor.utilities.spacing = function(ge) {
67
68
 
68
- var options = $.extend({ values: VALUES, scale: SCALE }, ge.settings.utilities.spacing);
69
+ var options = Object.assign({ values: VALUES, scale: SCALE }, ge.settings.utilities.spacing);
69
70
  var patterns = { p: pattern('p'), m: pattern('m') };
70
71
 
71
72
  function applies(node, kind) {
72
73
  return kind === 'row' || kind === 'column' || kind === 'element' ||
73
- node.is('[data-ge-container]');
74
+ dom.is(node, '[data-ge-container]');
74
75
  }
75
76
 
76
77
  function classes(node) {
77
- return (node.attr('class') || '').split(/\s+/);
78
+ return (node.getAttribute('class') || '').split(/\s+/);
78
79
  }
79
80
 
80
81
  function carries(node, key) {
@@ -106,16 +107,16 @@ $.fn.gridEditor.utilities.spacing = function(ge) {
106
107
  * since that is the only way to ask the browser.
107
108
  */
108
109
  function without(node, key) {
109
- var original = node.attr('class');
110
+ var original = node.getAttribute('class');
110
111
  var style;
111
112
  var bare = {};
112
113
 
113
- node.attr('class', classes(node).filter(function(name) { return !patterns[key].test(name); }).join(' '));
114
- style = getComputedStyle(node[0]);
114
+ node.setAttribute('class', classes(node).filter(function(name) { return !patterns[key].test(name); }).join(' '));
115
+ style = getComputedStyle(node);
115
116
  ['top', 'right', 'bottom', 'left'].forEach(function(side) {
116
117
  bare[side] = style.getPropertyValue(PROPERTIES[key] + '-' + side);
117
118
  });
118
- node.attr('class', original);
119
+ if (original === null) { node.removeAttribute('class'); } else { node.setAttribute('class', original); }
119
120
 
120
121
  return bare;
121
122
  }
@@ -182,26 +183,25 @@ $.fn.gridEditor.utilities.spacing = function(ge) {
182
183
 
183
184
  /** A padding or margin group: its name, the side, and the field of that side's family. */
184
185
  function group(node, key, labelText) {
185
- var box = $('<div class="ge-spacing-group" />').attr('data-ge-spacing', key);
186
- var side = $('<select class="ge-spacing-side form-select form-select-sm" />');
186
+ var box = dom.element('div', { 'class': 'ge-spacing-group', 'data-ge-spacing': key });
187
+ var side = dom.element('select', { 'class': 'ge-spacing-side form-select form-select-sm' });
187
188
 
188
- $('<span class="ge-utility-label" />').text(labelText).appendTo(box);
189
+ box.appendChild(dom.element('span', { 'class': 'ge-utility-label' }, labelText));
189
190
 
190
191
  SIDES.forEach(function(value) {
191
- $('<option />').attr('value', value).text(sideLabel(value)).appendTo(side);
192
+ side.appendChild(dom.element('option', { value: value }, sideLabel(value)));
192
193
  });
193
194
 
194
195
  var field = ge.utilityField(node, key + startingSide(node, key));
195
196
 
196
- side.val(field.attr('data-ge-family').slice(1))
197
- .on('change', function() {
198
- var next = ge.utilityField(node, key + this.value);
199
- field.replaceWith(next);
200
- field = next;
201
- })
202
- .appendTo(box)
203
- ;
204
- field.appendTo(box);
197
+ side.value = field.getAttribute('data-ge-family').slice(1);
198
+ side.addEventListener('change', function() {
199
+ var next = ge.utilityField(node, key + this.value);
200
+ field.replaceWith(next);
201
+ field = next;
202
+ });
203
+ box.appendChild(side);
204
+ box.appendChild(field);
205
205
 
206
206
  return box;
207
207
  }
@@ -216,29 +216,29 @@ $.fn.gridEditor.utilities.spacing = function(ge) {
216
216
  * about what that does to its gutter.
217
217
  */
218
218
  function mark(scope) {
219
- scope.find(NODES).addBack(NODES).each(function() {
220
- var node = $(this);
221
- var drawer = node.children('.ge-tools-drawer');
219
+ dom.selfAndAll(scope, NODES).forEach(function(node) {
220
+ var drawer = dom.child(node, '.ge-tools-drawer');
222
221
 
223
- if (!drawer.length || !applies(node, ge.kindOf(node))) { return; }
222
+ if (!drawer || !applies(node, ge.kindOf(node))) { return; }
224
223
 
225
224
  if (carries(node, 'p')) {
226
- var style = getComputedStyle(node[0]);
225
+ var style = getComputedStyle(node);
227
226
 
228
- drawer.css({
229
- marginTop: '-' + style.paddingTop,
230
- marginLeft: '-' + style.paddingLeft,
231
- marginRight: '-' + style.paddingRight,
227
+ dom.css(drawer, {
228
+ 'margin-top': '-' + style.paddingTop,
229
+ 'margin-left': '-' + style.paddingLeft,
230
+ 'margin-right': '-' + style.paddingRight,
232
231
  width: 'calc(100% + ' + style.paddingLeft + ' + ' + style.paddingRight + ')',
233
232
  });
234
233
  } else {
235
- drawer.css({ marginTop: '', marginLeft: '', marginRight: '', width: '' });
234
+ dom.css(drawer, { 'margin-top': '', 'margin-left': '', 'margin-right': '', width: '' });
236
235
  }
237
236
 
238
- if (node.hasClass('column')) {
239
- drawer.find('.ge-spacing-gutter').toggle(classes(node).some(function(name) {
237
+ if (dom.hasClass(node, 'column')) {
238
+ var padded = classes(node).some(function(name) {
240
239
  return /^p[xse]?-/.test(name) && patterns.p.test(name);
241
- }));
240
+ });
241
+ dom.all(drawer, '.ge-spacing-gutter').forEach(function(note) { dom.toggle(note, padded); });
242
242
  }
243
243
  });
244
244
  }
@@ -268,13 +268,12 @@ $.fn.gridEditor.utilities.spacing = function(ge) {
268
268
  panel: function(node, kind) {
269
269
  if (!applies(node, kind)) { return null; }
270
270
 
271
- var box = $('<div class="ge-spacing" />')
272
- .append(group(node, 'p', ge.t('utility.padding')))
273
- .append(group(node, 'm', ge.t('utility.margin')))
274
- ;
271
+ var box = dom.element('div', { 'class': 'ge-spacing' });
272
+ box.appendChild(group(node, 'p', ge.t('utility.padding')));
273
+ box.appendChild(group(node, 'm', ge.t('utility.margin')));
275
274
 
276
275
  if (kind === 'column') {
277
- $('<small class="ge-spacing-gutter" />').text(ge.t('utility.spacing_gutter')).appendTo(box);
276
+ box.appendChild(dom.element('small', { 'class': 'ge-spacing-gutter' }, ge.t('utility.spacing_gutter')));
278
277
  }
279
278
 
280
279
  return box;
@@ -286,7 +285,7 @@ $.fn.gridEditor.utilities.spacing = function(ge) {
286
285
  var styles = {};
287
286
 
288
287
  ['p', 'm'].forEach(function(key) {
289
- if (carries(node, key)) { $.extend(styles, sides(node, key, breakpoint)); }
288
+ if (carries(node, key)) { Object.assign(styles, sides(node, key, breakpoint)); }
290
289
  });
291
290
 
292
291
  return styles;
@@ -295,5 +294,3 @@ $.fn.gridEditor.utilities.spacing = function(ge) {
295
294
  onRefresh: mark,
296
295
  };
297
296
  };
298
-
299
- })(jQuery);
@@ -6,98 +6,134 @@
6
6
  * summernote in air mode. What it can ask the editor for is the
7
7
  * handle its factory is called with, described in docs/plugins.md.
8
8
  *
9
+ * <script src="jquery/jquery.min.js"></script>
9
10
  * <script src="summernote/summernote-bs5.min.js"></script>
10
- * <script src="dist/jquery.grideditor.min.js"></script>
11
+ * <script src="dist/grideditor.min.js"></script>
11
12
  * <script src="dist/plugins/grideditor.summernote.min.js"></script>
12
13
  *
14
+ * Summernote is a jQuery plugin, so this is the one plugin that needs jQuery
15
+ * on the page: it calls summernote on a content area through it, and
16
+ * nothing else. Towards the editor it is plain DOM, like every plugin, and
17
+ * it needs no jQuery adapter.
18
+ *
13
19
  * Up to 5.x the main bundle carried a copy of this file; since 6.0 it is
14
- * loaded on its own, like every plugin. The built file starts with what
15
- * every text editor shares - text blocks, the Text button, createText,
16
- * making the host's plain content a text - from
17
- * src/js/text/grideditor.text.js, installed once however many editors a
18
- * page loads.
20
+ * loaded on its own, like every plugin. It imports what every text editor
21
+ * shares - text blocks, the Text button, createText, making the host's plain
22
+ * content a text - from src/js/text/grideditor.text.js, which the build puts
23
+ * in its classic script, installed once however many editors a page loads.
24
+ */
25
+ import { GridEditor } from '../grideditor.js';
26
+ import * as dom from '../dom.js';
27
+ import '../text/grideditor.text.js';
28
+
29
+ Object.assign(GridEditor.locales.en, {
30
+ 'text.summernote': 'Summernote',
31
+ });
32
+
33
+ var INITIAL_CONTENT = '<p>Lorem ipsum dolores</p>';
34
+
35
+ function isPlainObject(value) {
36
+ return !!value && Object.prototype.toString.call(value) === '[object Object]';
37
+ }
38
+
39
+ /**
40
+ * `sources` merged into `target`, objects and arrays copied all the way
41
+ * down rather than shared: what jQuery's deep extend did for summernote's
42
+ * options, whose callbacks the host's config and this file both fill in.
19
43
  */
20
- (function($) {
44
+ function deepMerge(target) {
45
+ Array.prototype.slice.call(arguments, 1).forEach(function(source) {
46
+ Object.keys(source || {}).forEach(function(key) {
47
+ var value = source[key];
48
+
49
+ if (value === undefined || value === target) { return; }
21
50
 
22
- $.extend($.fn.gridEditor.locales.en, {
23
- 'text.summernote': 'Summernote',
51
+ if (Array.isArray(value)) {
52
+ target[key] = deepMerge(Array.isArray(target[key]) ? target[key] : [], value);
53
+ } else if (isPlainObject(value)) {
54
+ target[key] = deepMerge(isPlainObject(target[key]) ? target[key] : {}, value);
55
+ } else {
56
+ target[key] = value;
57
+ }
58
+ });
24
59
  });
25
60
 
26
- var INITIAL_CONTENT = '<p>Lorem ipsum dolores</p>';
61
+ return target;
62
+ }
27
63
 
28
- $.fn.gridEditor.texts.summernote = function(ge) {
29
- return {
30
- labelKey: 'text.summernote',
31
- initialContent: INITIAL_CONTENT,
32
- missingKey: 'error.summernote_missing',
64
+ GridEditor.texts.summernote = function(ge) {
65
+ return {
66
+ labelKey: 'text.summernote',
67
+ initialContent: INITIAL_CONTENT,
68
+ missingKey: 'error.summernote_missing',
33
69
 
34
- available: function() { return !!$.fn.summernote; },
70
+ available: function() { return !!(window.jQuery && window.jQuery.fn && window.jQuery.fn.summernote); },
35
71
 
36
- start: function(contentAreas) {
37
- var settings = ge.settings;
72
+ start: function(contentAreas) {
73
+ var settings = ge.settings;
74
+ var $ = window.jQuery;
38
75
 
39
- // Summernote 0.9.1 calls $.now(), which jQuery 4 removed, and
40
- // cannot open without it. Given back only where it is missing,
41
- // and only once summernote is actually used.
42
- if (!$.now) { $.now = Date.now; }
76
+ // Summernote 0.9.1 calls $.now(), which jQuery 4 removed, and
77
+ // cannot open without it. Given back only where it is missing,
78
+ // and only once summernote is actually used.
79
+ if (!$.now) { $.now = Date.now; }
43
80
 
44
- contentAreas.each(function() {
45
- var contentArea = $(this);
46
- if (contentArea.hasClass('active')) { return; }
81
+ contentAreas.forEach(function(contentArea) {
82
+ if (dom.hasClass(contentArea, 'active')) { return; }
47
83
 
48
- if (contentArea.html() == INITIAL_CONTENT) {
49
- contentArea.html('');
50
- }
51
- contentArea.addClass('active');
52
-
53
- var configuration = $.extend(
54
- true, // deep copy
55
- {},
56
- (settings.summernote && settings.summernote.config ? settings.summernote.config : {}),
57
- {
58
- tabsize: 2,
59
- airMode: true,
60
- // Focus editor on creation
61
- callbacks: {
62
- onInit: function() {
63
-
64
- // Call original oninit function, if one was passed in the config
65
- var callback;
66
- try {
67
- callback = settings.summernote.config.callbacks.onInit;
68
- } catch (err) {
69
- // No callback passed
70
- }
71
- if (callback) {
72
- callback.call(this);
73
- }
74
-
75
- // The editor owns what is inside the
76
- // content area now, so the grid editor is
77
- // told to put its own furniture back
78
- ge.textReady(contentArea);
79
-
80
- contentArea.summernote('focus');
84
+ if (contentArea.innerHTML == INITIAL_CONTENT) {
85
+ contentArea.innerHTML = '';
86
+ }
87
+ dom.addClass(contentArea, 'active');
88
+
89
+ var configuration = deepMerge(
90
+ {},
91
+ (settings.summernote && settings.summernote.config ? settings.summernote.config : {}),
92
+ {
93
+ tabsize: 2,
94
+ airMode: true,
95
+ // Focus editor on creation
96
+ callbacks: {
97
+ onInit: function() {
98
+
99
+ // Call original oninit function, if one was passed in the config
100
+ var callback;
101
+ try {
102
+ callback = settings.summernote.config.callbacks.onInit;
103
+ } catch (err) {
104
+ // No callback passed
105
+ }
106
+ if (callback) {
107
+ callback.call(this);
81
108
  }
109
+
110
+ // The editor owns what is inside the
111
+ // content area now, so the grid editor is
112
+ // told to put its own furniture back
113
+ ge.textReady(contentArea);
114
+
115
+ $(contentArea).summernote('focus');
82
116
  }
83
117
  }
84
- );
85
- contentArea.summernote(configuration);
86
- });
87
- },
88
-
89
- stop: function(contentAreas) {
90
- contentAreas.filter('.active').each(function() {
91
- var contentArea = $(this);
92
- contentArea.summernote('destroy');
93
- contentArea
94
- .removeClass('active')
95
- .removeAttr('id')
96
- .removeAttr('style')
97
- .removeAttr('spellcheck')
98
- ;
118
+ }
119
+ );
120
+ $(contentArea).summernote(configuration);
121
+ });
122
+ },
123
+
124
+ stop: function(contentAreas) {
125
+ var $ = window.jQuery;
126
+
127
+ contentAreas.filter(function(contentArea) {
128
+ return dom.hasClass(contentArea, 'active');
129
+ }).forEach(function(contentArea) {
130
+ if ($ && $.fn.summernote) { $(contentArea).summernote('destroy'); }
131
+
132
+ dom.removeClass(contentArea, 'active');
133
+ ['id', 'style', 'spellcheck'].forEach(function(name) {
134
+ contentArea.removeAttribute(name);
99
135
  });
100
- },
101
- };
136
+ });
137
+ },
102
138
  };
103
- })(jQuery);
139
+ };
@@ -5,43 +5,48 @@
5
5
  * a tabs container. What it can ask the editor for is the handle its factory is
6
6
  * called with, described in docs/plugins.md.
7
7
  *
8
- * <script src="dist/jquery.grideditor.min.js"></script>
8
+ * <script src="dist/grideditor.min.js"></script>
9
9
  * <script src="dist/plugins/grideditor.tabs.min.js"></script>
10
10
  */
11
- (function($) {
11
+ import { GridEditor } from '../grideditor.js';
12
+ import * as dom from '../dom.js';
12
13
 
13
- $.extend($.fn.gridEditor.locales.en, {
14
+ Object.assign(GridEditor.locales.en, {
14
15
  'container.add_tabs': 'Tabs',
15
16
  'container.add_tab': 'Add tab',
16
17
  'container.tab_label': 'Tab {number}',
17
18
  'confirm.delete_tab': 'Delete this tab and everything in it?',
18
19
  });
19
20
 
20
- $.fn.gridEditor.containers.tabs = function(ge) {
21
+ GridEditor.containers.tabs = function(ge) {
21
22
 
22
23
  function addTabTo(container, options) {
23
24
  options = options || {};
24
25
 
25
- var strip = container.find('> .nav-tabs');
26
- var content = container.find('> .tab-content');
26
+ var strip = dom.one(container, ':scope > .nav-tabs');
27
+ var content = dom.one(container, ':scope > .tab-content');
27
28
  var id = ge.containerId('tab');
28
- var number = strip.children('.nav-item').length + 1;
29
-
30
- $('<li class="nav-item ge-tab" role="presentation" />')
31
- .append($('<button class="nav-link" type="button" role="tab" data-bs-toggle="tab" />')
32
- .attr('data-bs-target', '#' + id)
33
- .attr('aria-controls', id)
34
- .append($('<span class="ge-pane-label" />')
35
- .text(options.label || ge.t('container.tab_label', { number: number })))
36
- )
37
- .appendTo(strip)
38
- ;
39
-
40
- var pane = $('<div class="tab-pane fade" role="tabpanel" tabindex="0" />')
41
- .attr('id', id)
42
- .append(ge.defaultRegion())
43
- .appendTo(content)
44
- ;
29
+ var number = dom.children(strip, '.nav-item').length + 1;
30
+
31
+ var tab = strip.appendChild(dom.element('li', { 'class': 'nav-item ge-tab', role: 'presentation' }));
32
+ var button = tab.appendChild(dom.element('button', {
33
+ 'class': 'nav-link',
34
+ type: 'button',
35
+ role: 'tab',
36
+ 'data-bs-toggle': 'tab',
37
+ 'data-bs-target': '#' + id,
38
+ 'aria-controls': id,
39
+ }));
40
+ button.appendChild(dom.element('span', { 'class': 'ge-pane-label' },
41
+ options.label || ge.t('container.tab_label', { number: number })));
42
+
43
+ var pane = content.appendChild(dom.element('div', {
44
+ 'class': 'tab-pane fade',
45
+ role: 'tabpanel',
46
+ tabindex: '0',
47
+ id: id,
48
+ }));
49
+ pane.appendChild(ge.defaultRegion());
45
50
 
46
51
  if (options.activate || number === 1) { activatePane(container, pane); }
47
52
 
@@ -49,26 +54,26 @@ $.fn.gridEditor.containers.tabs = function(ge) {
49
54
  }
50
55
 
51
56
  function activatePane(container, pane) {
52
- var id = pane.attr('id');
57
+ var id = pane.getAttribute('id');
53
58
 
54
- container.find('> .tab-content > .tab-pane').removeClass('show active');
55
- pane.addClass('show active');
59
+ dom.all(container, ':scope > .tab-content > .tab-pane').forEach(function(each) {
60
+ dom.removeClass(each, 'show active');
61
+ });
62
+ dom.addClass(pane, 'show active');
56
63
 
57
- container.find('> .nav-tabs .nav-link').each(function() {
58
- var button = $(this);
59
- var active = button.attr('data-bs-target') === '#' + id;
64
+ dom.all(container, ':scope > .nav-tabs .nav-link').forEach(function(button) {
65
+ var active = button.getAttribute('data-bs-target') === '#' + id;
60
66
 
61
- button.toggleClass('active', active).attr('aria-selected', active ? 'true' : 'false');
67
+ dom.toggleClass(button, 'active', active);
68
+ button.setAttribute('aria-selected', active ? 'true' : 'false');
62
69
  });
63
70
  }
64
71
 
65
- function tabOf(container, pane) {
66
- return container.find('> .nav-tabs .nav-link[data-bs-target="#' + pane.attr('id') + '"]')
67
- .closest('.nav-item');
68
- }
69
-
70
72
  function paneOf(container, tab) {
71
- return container.find(tab.find('.nav-link').attr('data-bs-target'));
73
+ var link = dom.one(tab, '.nav-link');
74
+ var target = link ? link.getAttribute('data-bs-target') : null;
75
+
76
+ return target ? dom.one(container, target) : null;
72
77
  }
73
78
 
74
79
  return {
@@ -77,7 +82,7 @@ $.fn.gridEditor.containers.tabs = function(ge) {
77
82
  // A tab strip sorts its own tabs, and the panes follow them. No
78
83
  // group: a tab belongs to the strip it was made in.
79
84
  onSortable: function(sortable) {
80
- sortable(ge.canvas.find('.ge-container-tabs > .nav-tabs'), {
85
+ sortable(dom.all(ge.canvas, '.ge-container-tabs > .nav-tabs'), {
81
86
  draggable: '.ge-tab',
82
87
  });
83
88
  },
@@ -85,12 +90,12 @@ $.fn.gridEditor.containers.tabs = function(ge) {
85
90
  paneKind: 'tab',
86
91
 
87
92
  create: function(options) {
88
- var container = $('<div />').attr('data-ge-container', 'tabs');
93
+ var container = dom.element('div', { 'data-ge-container': 'tabs' });
89
94
  var labels = options.labels || [];
90
95
  var count = options.tabs || labels.length || 2;
91
96
 
92
- $('<ul class="nav nav-tabs" role="tablist" />').appendTo(container);
93
- $('<div class="tab-content" />').appendTo(container);
97
+ container.appendChild(dom.element('ul', { 'class': 'nav nav-tabs', role: 'tablist' }));
98
+ container.appendChild(dom.element('div', { 'class': 'tab-content' }));
94
99
 
95
100
  for (var i = 0; i < count; i++) {
96
101
  addTabTo(container, { label: labels[i] });
@@ -102,27 +107,29 @@ $.fn.gridEditor.containers.tabs = function(ge) {
102
107
  addPane: addTabTo,
103
108
 
104
109
  mark: function(container) {
105
- container.find('> .tab-content > .tab-pane').addClass('ge-tab-pane');
106
-
107
- container.find('> .nav-tabs > .nav-item').each(function() {
108
- var tab = $(this).addClass('ge-tab');
110
+ dom.all(container, ':scope > .tab-content > .tab-pane').forEach(function(pane) {
111
+ dom.addClass(pane, 'ge-tab-pane');
112
+ });
109
113
 
114
+ dom.all(container, ':scope > .nav-tabs > .nav-item').forEach(function(tab) {
115
+ dom.addClass(tab, 'ge-tab');
110
116
 
111
- ge.makeLabelEditable(ge.labelIn(tab.find('.nav-link')));
117
+ var link = dom.one(tab, '.nav-link');
118
+ if (link) { ge.makeLabelEditable(ge.labelIn(link)); }
112
119
 
113
- if (tab.find('> .ge-tools-drawer').length) { return; }
120
+ if (dom.child(tab, '.ge-tools-drawer')) { return; }
114
121
 
115
122
  ge.createPaneControls(tab, 'tab', ge.settings.tab_tools, ge.t('confirm.delete_tab'),
116
123
  function(removed) {
117
124
  var pane = paneOf(container, tab);
118
- var wasActive = pane.hasClass('active');
125
+ var wasActive = dom.hasClass(pane, 'active');
119
126
 
120
- tab.fadeOut(200, function() {
121
- pane.remove();
127
+ dom.fadeOut(tab, 200, function() {
128
+ if (pane) { pane.remove(); }
122
129
  removed();
123
130
 
124
- var first = container.find('> .tab-content > .tab-pane').first();
125
- if (wasActive && first.length) { activatePane(container, first); }
131
+ var first = dom.one(container, ':scope > .tab-content > .tab-pane');
132
+ if (wasActive && first) { activatePane(container, first); }
126
133
  });
127
134
  });
128
135
  });
@@ -130,19 +137,20 @@ $.fn.gridEditor.containers.tabs = function(ge) {
130
137
 
131
138
  unmark: function(container) {
132
139
  ge.resumeToggles(container);
133
- container.find('.ge-tab-pane').removeClass('ge-tab-pane');
140
+ dom.all(container, '.ge-tab-pane').forEach(function(pane) {
141
+ dom.removeClass(pane, 'ge-tab-pane');
142
+ });
134
143
  ge.unwrapLabels(container);
135
144
  },
136
145
 
137
146
  /** Panes read in tab order, whatever order they were dropped in. */
138
147
  afterPaneMove: function(container) {
139
- var content = container.find('> .tab-content');
148
+ var content = dom.one(container, ':scope > .tab-content');
140
149
 
141
- container.find('> .nav-tabs > .nav-item').each(function() {
142
- content.append(paneOf(container, $(this)));
150
+ dom.all(container, ':scope > .nav-tabs > .nav-item').forEach(function(tab) {
151
+ var pane = paneOf(container, tab);
152
+ if (pane) { content.appendChild(pane); }
143
153
  });
144
154
  },
145
155
  };
146
156
  };
147
-
148
- })(jQuery);
@@ -7,15 +7,15 @@
7
7
  * editor for is the handle its factory is called with, described in
8
8
  * docs/plugins.md.
9
9
  *
10
- * <script src="dist/jquery.grideditor.min.js"></script>
10
+ * <script src="dist/grideditor.min.js"></script>
11
11
  * <script src="dist/plugins/grideditor.textalign.min.js"></script>
12
12
  *
13
13
  * The class aligns everything inside the node that does not align itself: a
14
14
  * paragraph the rich text editor gave its own text-align keeps it.
15
15
  */
16
- (function($) {
16
+ import { GridEditor } from '../grideditor.js';
17
17
 
18
- $.extend($.fn.gridEditor.locales.en, {
18
+ Object.assign(GridEditor.locales.en, {
19
19
  'utility.text_align': 'Text alignment',
20
20
  'utility.text_start': 'Start',
21
21
  'utility.text_center': 'Center',
@@ -25,7 +25,7 @@ $.extend($.fn.gridEditor.locales.en, {
25
25
  /** Start and end are left and right: Bootstrap's css is left to right. */
26
26
  var CSS = { start: 'left', center: 'center', end: 'right' };
27
27
 
28
- $.fn.gridEditor.utilities.textalign = function(ge) {
28
+ GridEditor.utilities.textalign = function(ge) {
29
29
 
30
30
  function label(value) {
31
31
  if (value === 'start') { return ge.t('utility.text_start'); }
@@ -56,5 +56,3 @@ $.fn.gridEditor.utilities.textalign = function(ge) {
56
56
  }],
57
57
  };
58
58
  };
59
-
60
- })(jQuery);