@themarioga/grid-editor 6.0.0-beta.5 → 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 +54 -0
  4. package/README.md +140 -89
  5. package/UPGRADING.md +146 -2
  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 -170
  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 +482 -493
  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 +491 -471
  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 +500 -534
  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 +7 -4
  97. package/docs/plugins.md +49 -27
  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 -158
  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 +81 -106
  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
@@ -5,68 +5,85 @@
5
5
  * an accordion. 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.accordion.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_accordion': 'Accordion',
15
16
  'container.add_accordion_item': 'Add item',
16
17
  'container.accordion_label': 'Item {number}',
17
18
  'confirm.delete_accordion_item': 'Delete this item and everything in it?',
18
19
  });
19
20
 
20
- $.fn.gridEditor.containers.accordion = function(ge) {
21
+ GridEditor.containers.accordion = function(ge) {
22
+
23
+ // The buttons whose clicks the editor answers itself, bound once each
24
+ var answered = new WeakSet();
25
+
26
+ function collapseOf(item) {
27
+ return dom.child(item, '.accordion-collapse');
28
+ }
21
29
 
22
30
  function staysOpen(container, ignore) {
23
- var items = container.find('> .accordion > .accordion-item > .accordion-collapse');
31
+ var items = dom.all(container, ':scope > .accordion > .accordion-item > .accordion-collapse');
24
32
 
25
- if (ignore) { items = items.not(ignore.find('> .accordion-collapse')); }
33
+ if (ignore) {
34
+ var ignored = collapseOf(ignore);
35
+ items = items.filter(function(collapse) { return collapse !== ignored; });
36
+ }
26
37
 
27
- return items.length > 0 && !items.filter('[data-bs-parent]').length;
38
+ return items.length > 0 && !items.filter(function(collapse) {
39
+ return collapse.hasAttribute('data-bs-parent');
40
+ }).length;
28
41
  }
29
42
 
30
43
  function addAccordionItemTo(container, options) {
31
44
  options = options || {};
32
45
 
33
- var accordion = container.find('> .accordion');
46
+ var accordion = dom.child(container, '.accordion');
34
47
  var id = ge.containerId('acc-item');
35
- var number = accordion.children('.accordion-item').length + 1;
48
+ var number = dom.children(accordion, '.accordion-item').length + 1;
36
49
  var open = options.open === undefined ? number === 1 : !!options.open;
37
50
  var stayOpen = options.stay_open === undefined ? staysOpen(container) : !!options.stay_open;
38
51
 
39
- var item = $('<div class="accordion-item ge-accordion-item" />').appendTo(accordion);
40
-
41
- $('<h2 class="accordion-header" />')
42
- .append($('<button class="accordion-button" type="button" data-bs-toggle="collapse" />')
43
- .attr('data-bs-target', '#' + id)
44
- .attr('aria-expanded', open ? 'true' : 'false')
45
- .toggleClass('collapsed', !open)
46
- .append($('<span class="ge-pane-label" />')
47
- .text(options.label || ge.t('container.accordion_label', { number: number }))))
48
- .appendTo(item)
49
- ;
50
-
51
- var collapse = $('<div class="accordion-collapse collapse" />')
52
- .attr('id', id)
53
- .attr('data-ge-open', open ? 'true' : 'false')
54
- .toggleClass('show', open)
55
- .appendTo(item)
56
- ;
57
-
58
- if (!stayOpen) { collapse.attr('data-bs-parent', '#' + accordion.attr('id')); }
59
-
60
- return $('<div class="accordion-body" />').append(ge.defaultRegion()).appendTo(collapse);
52
+ var item = accordion.appendChild(dom.element('div', { 'class': 'accordion-item ge-accordion-item' }));
53
+
54
+ var header = item.appendChild(dom.element('h2', { 'class': 'accordion-header' }));
55
+ var button = header.appendChild(dom.element('button', {
56
+ 'class': 'accordion-button',
57
+ type: 'button',
58
+ 'data-bs-toggle': 'collapse',
59
+ 'data-bs-target': '#' + id,
60
+ 'aria-expanded': open ? 'true' : 'false',
61
+ }));
62
+ dom.toggleClass(button, 'collapsed', !open);
63
+ button.appendChild(dom.element('span', { 'class': 'ge-pane-label' },
64
+ options.label || ge.t('container.accordion_label', { number: number })));
65
+
66
+ var collapse = item.appendChild(dom.element('div', {
67
+ 'class': 'accordion-collapse collapse',
68
+ id: id,
69
+ 'data-ge-open': open ? 'true' : 'false',
70
+ }));
71
+ dom.toggleClass(collapse, 'show', open);
72
+
73
+ if (!stayOpen) { collapse.setAttribute('data-bs-parent', '#' + accordion.getAttribute('id')); }
74
+
75
+ var body = collapse.appendChild(dom.element('div', { 'class': 'accordion-body' }));
76
+ body.appendChild(ge.defaultRegion());
77
+ return body;
61
78
  }
62
79
 
63
80
  function toggleAccordionItem(container, item) {
64
- var collapse = item.find('> .accordion-collapse');
65
- var opening = collapse.attr('data-ge-open') !== 'true';
81
+ var collapse = collapseOf(item);
82
+ var opening = collapse.getAttribute('data-ge-open') !== 'true';
66
83
 
67
84
  if (opening && !staysOpen(container)) {
68
- container.find('> .accordion > .accordion-item').not(item).each(function() {
69
- setAccordionItemOpen($(this), false);
85
+ dom.all(container, ':scope > .accordion > .accordion-item').forEach(function(other) {
86
+ if (other !== item) { setAccordionItemOpen(other, false); }
70
87
  });
71
88
  }
72
89
 
@@ -74,26 +91,29 @@ $.fn.gridEditor.containers.accordion = function(ge) {
74
91
  }
75
92
 
76
93
  function setAccordionItemOpen(item, open) {
77
- item.find('> .accordion-collapse')
78
- .attr('data-ge-open', open ? 'true' : 'false')
79
- .toggleClass('show', open)
80
- ;
81
- item.find('> .accordion-header .accordion-button')
82
- .toggleClass('collapsed', !open)
83
- .attr('aria-expanded', open ? 'true' : 'false')
84
- ;
94
+ var collapse = collapseOf(item);
95
+ if (collapse) {
96
+ collapse.setAttribute('data-ge-open', open ? 'true' : 'false');
97
+ dom.toggleClass(collapse, 'show', open);
98
+ }
99
+
100
+ dom.all(item, ':scope > .accordion-header .accordion-button').forEach(function(button) {
101
+ dom.toggleClass(button, 'collapsed', !open);
102
+ button.setAttribute('aria-expanded', open ? 'true' : 'false');
103
+ });
85
104
  }
86
105
 
87
106
  function reparentAccordionItem(container, item) {
88
107
  var accordion = item.closest('.accordion');
89
- var collapse = item.find('> .accordion-collapse');
108
+ var collapse = collapseOf(item);
109
+ if (!collapse) { return; }
90
110
 
91
111
  // The item that just arrived still carries the parent it had
92
112
  // where it came from, so it is not asked what this accordion does
93
113
  if (staysOpen(container, item)) {
94
- collapse.removeAttr('data-bs-parent');
114
+ collapse.removeAttribute('data-bs-parent');
95
115
  } else {
96
- collapse.attr('data-bs-parent', '#' + accordion.attr('id'));
116
+ collapse.setAttribute('data-bs-parent', '#' + accordion.getAttribute('id'));
97
117
  }
98
118
  }
99
119
 
@@ -102,7 +122,7 @@ $.fn.gridEditor.containers.accordion = function(ge) {
102
122
 
103
123
  // Items sort within their accordion and into any other one
104
124
  onSortable: function(sortable) {
105
- sortable(ge.canvas.find('.ge-container-accordion > .accordion'), {
125
+ sortable(dom.all(ge.canvas, '.ge-container-accordion > .accordion'), {
106
126
  draggable: '.ge-accordion-item',
107
127
  group: 'accordion',
108
128
  });
@@ -111,14 +131,11 @@ $.fn.gridEditor.containers.accordion = function(ge) {
111
131
  paneKind: 'accordion-item',
112
132
 
113
133
  create: function(options) {
114
- var container = $('<div />').attr('data-ge-container', 'accordion');
134
+ var container = dom.element('div', { 'data-ge-container': 'accordion' });
115
135
  var labels = options.labels || [];
116
136
  var count = options.items || labels.length || 2;
117
137
 
118
- $('<div class="accordion" />')
119
- .attr('id', ge.containerId('accordion'))
120
- .appendTo(container)
121
- ;
138
+ container.appendChild(dom.element('div', { 'class': 'accordion', id: ge.containerId('accordion') }));
122
139
 
123
140
  for (var i = 0; i < count; i++) {
124
141
  addAccordionItemTo(container, {
@@ -134,39 +151,42 @@ $.fn.gridEditor.containers.accordion = function(ge) {
134
151
  addPane: addAccordionItemTo,
135
152
 
136
153
  mark: function(container) {
137
- container.find('> .accordion > .accordion-item').each(function() {
138
- var item = $(this).addClass('ge-accordion-item');
139
- var collapse = item.find('> .accordion-collapse');
154
+ dom.all(container, ':scope > .accordion > .accordion-item').forEach(function(item) {
155
+ dom.addClass(item, 'ge-accordion-item');
156
+ var collapse = collapseOf(item);
140
157
 
141
158
  // What the author wanted, before Bootstrap's own
142
159
  // toggles get a chance to change it while editing.
143
160
  // Every item is shown while editing (the stylesheet
144
161
  // does that), so this is the only record of it.
145
- if (collapse.attr('data-ge-open') === undefined) {
146
- collapse.attr('data-ge-open', collapse.hasClass('show') ? 'true' : 'false');
162
+ if (collapse && !collapse.hasAttribute('data-ge-open')) {
163
+ collapse.setAttribute('data-ge-open', dom.hasClass(collapse, 'show') ? 'true' : 'false');
147
164
  }
148
165
 
149
- var button = item.find('> .accordion-header .accordion-button');
166
+ var button = dom.one(item, ':scope > .accordion-header .accordion-button');
150
167
 
151
- // Bootstrap's collapse stays out of it, and the editor
152
- // answers the click itself
153
- ge.suspendToggles(button);
154
- ge.makeLabelEditable(ge.labelIn(button));
168
+ if (button) {
169
+ // Bootstrap's collapse stays out of it, and the editor
170
+ // answers the click itself
171
+ ge.suspendToggles(button);
172
+ ge.makeLabelEditable(ge.labelIn(button));
155
173
 
156
- if (!button.data('ge-toggles')) {
157
- button.data('ge-toggles', true).on('click', function(e) {
158
- if (ge.labelIn(button).attr('contenteditable') === 'true') { return; }
174
+ if (!answered.has(button)) {
175
+ answered.add(button);
176
+ button.addEventListener('click', function(e) {
177
+ if (ge.labelIn(button).getAttribute('contenteditable') === 'true') { return; }
159
178
 
160
- e.preventDefault();
161
- toggleAccordionItem(container, item);
162
- });
179
+ e.preventDefault();
180
+ toggleAccordionItem(container, item);
181
+ });
182
+ }
163
183
  }
164
184
 
165
- if (item.find('> .ge-tools-drawer').length) { return; }
185
+ if (dom.child(item, '.ge-tools-drawer')) { return; }
166
186
 
167
187
  ge.createPaneControls(item, 'accordion-item', ge.settings.accordion_tools,
168
188
  ge.t('confirm.delete_accordion_item'), function(removed) {
169
- item.slideUp(200, removed);
189
+ dom.slideUp(item, 200, removed);
170
190
  });
171
191
  });
172
192
  },
@@ -174,13 +194,15 @@ $.fn.gridEditor.containers.accordion = function(ge) {
174
194
  unmark: function(container) {
175
195
  ge.resumeToggles(container);
176
196
 
177
- // What the ge.canvas was showing is what the page ships
178
- container.find('> .accordion > .accordion-item').each(function() {
179
- setAccordionItemOpen($(this),
180
- $(this).find('> .accordion-collapse').attr('data-ge-open') === 'true');
197
+ // What the canvas was showing is what the page ships
198
+ dom.all(container, ':scope > .accordion > .accordion-item').forEach(function(item) {
199
+ var collapse = collapseOf(item);
200
+ setAccordionItemOpen(item, !!collapse && collapse.getAttribute('data-ge-open') === 'true');
181
201
  });
182
202
 
183
- container.find('.ge-accordion-item').removeClass('ge-accordion-item');
203
+ dom.all(container, '.ge-accordion-item').forEach(function(item) {
204
+ dom.removeClass(item, 'ge-accordion-item');
205
+ });
184
206
  ge.unwrapLabels(container);
185
207
  },
186
208
 
@@ -189,5 +211,3 @@ $.fn.gridEditor.containers.accordion = function(ge) {
189
211
  },
190
212
  };
191
213
  };
192
-
193
- })(jQuery);
@@ -7,15 +7,15 @@
7
7
  * align-self-{breakpoint}-* classes. What it can ask the editor for is the
8
8
  * handle its factory is 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.alignment.min.js"></script>
12
12
  *
13
13
  * Fields only, in the settings panels: alignment is set now and then, not
14
14
  * clicked through, and a drawer is short of room.
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.justify_content': 'Justify columns',
20
20
  'utility.align_items': 'Align columns',
21
21
  'utility.align_self': 'Align self',
@@ -40,7 +40,7 @@ var FLEX = {
40
40
  * wider breakpoint's class that is live in a wide window.
41
41
  */
42
42
  function family(definition) {
43
- return $.extend({
43
+ return Object.assign({
44
44
  prefix: definition.name,
45
45
  preview: function(value) {
46
46
  var styles = {};
@@ -50,7 +50,7 @@ function family(definition) {
50
50
  }, definition);
51
51
  }
52
52
 
53
- $.fn.gridEditor.utilities.alignment = function() {
53
+ GridEditor.utilities.alignment = function() {
54
54
  return {
55
55
  families: [
56
56
  family({
@@ -77,5 +77,3 @@ $.fn.gridEditor.utilities.alignment = function() {
77
77
  ],
78
78
  };
79
79
  };
80
-
81
- })(jQuery);
@@ -6,18 +6,24 @@
6
6
  * the editor for is the handle its factory is called with, described in
7
7
  * docs/plugins.md.
8
8
  *
9
- * <script src="dist/jquery.grideditor.min.js"></script>
9
+ * <script src="dist/grideditor.min.js"></script>
10
10
  * <script src="dist/plugins/grideditor.card.min.js"></script>
11
11
  */
12
- (function($) {
12
+ import { GridEditor } from '../grideditor.js';
13
+ import * as dom from '../dom.js';
13
14
 
14
- $.extend($.fn.gridEditor.locales.en, {
15
+ Object.assign(GridEditor.locales.en, {
15
16
  'container.add_card': 'Card',
16
17
  'container.card_title': 'Card title',
17
18
  'container.card_footer': 'Card footer',
18
19
  });
19
20
 
20
- $.fn.gridEditor.containers.card = function(ge) {
21
+ GridEditor.containers.card = function(ge) {
22
+
23
+ /** A header's or a footer's text, editable in place, when the card has one. */
24
+ function editable(part) {
25
+ if (part) { ge.makeLabelEditable(ge.labelIn(part)); }
26
+ }
21
27
 
22
28
  return {
23
29
  labelKey: 'container.add_card',
@@ -29,34 +35,30 @@ $.fn.gridEditor.containers.card = function(ge) {
29
35
  * exactly one region and nests like any other container.
30
36
  */
31
37
  create: function(options) {
32
- var card = $('<div class="card" />');
38
+ var card = dom.element('div', { 'class': 'card' });
33
39
 
34
40
  if (options.header !== false) {
35
- $('<div class="card-header" />')
36
- .append($('<span class="ge-pane-label" />')
37
- .text(options.title || ge.t('container.card_title')))
38
- .appendTo(card)
39
- ;
41
+ var header = card.appendChild(dom.element('div', { 'class': 'card-header' }));
42
+ header.appendChild(dom.element('span', { 'class': 'ge-pane-label' },
43
+ options.title || ge.t('container.card_title')));
40
44
  }
41
45
 
42
- $('<div class="card-body" />').append(ge.defaultRegion()).appendTo(card);
46
+ card.appendChild(dom.element('div', { 'class': 'card-body' })).appendChild(ge.defaultRegion());
43
47
 
44
48
  if (options.footer) {
45
- $('<div class="card-footer text-body-secondary" />')
46
- .append($('<span class="ge-pane-label" />')
47
- .text(typeof options.footer === 'string'
48
- ? options.footer
49
- : ge.t('container.card_footer')))
50
- .appendTo(card)
51
- ;
49
+ var footer = card.appendChild(dom.element('div', { 'class': 'card-footer text-body-secondary' }));
50
+ footer.appendChild(dom.element('span', { 'class': 'ge-pane-label' },
51
+ typeof options.footer === 'string' ? options.footer : ge.t('container.card_footer')));
52
52
  }
53
53
 
54
- return $('<div />').attr('data-ge-container', 'card').append(card);
54
+ var container = dom.element('div', { 'data-ge-container': 'card' });
55
+ container.appendChild(card);
56
+ return container;
55
57
  },
56
58
 
57
59
  mark: function(container) {
58
- ge.makeLabelEditable(ge.labelIn(container.find('> .card > .card-header')));
59
- ge.makeLabelEditable(ge.labelIn(container.find('> .card > .card-footer')));
60
+ editable(dom.one(container, ':scope > .card > .card-header'));
61
+ editable(dom.one(container, ':scope > .card > .card-footer'));
60
62
  },
61
63
 
62
64
  unmark: function(container) {
@@ -64,5 +66,3 @@ $.fn.gridEditor.containers.card = function(ge) {
64
66
  },
65
67
  };
66
68
  };
67
-
68
- })(jQuery);
@@ -7,119 +7,120 @@
7
7
  * factory is called with, described in docs/plugins.md.
8
8
  *
9
9
  * <script src="ckeditor/ckeditor.js"></script>
10
- * <script src="dist/jquery.grideditor.min.js"></script>
10
+ * <script src="dist/grideditor.min.js"></script>
11
11
  * <script src="dist/plugins/grideditor.ckeditor.min.js"></script>
12
12
  *
13
13
  * 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 and the Add text
16
- * tool, createText, 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.
14
+ * loaded on its own, like every plugin. It imports what every text editor
15
+ * shares - text blocks, the Text button, createText, making the host's plain
16
+ * content a text - from src/js/text/grideditor.text.js, which the build puts
17
+ * in its classic script, installed once however many editors a page loads.
19
18
  */
20
- (function($) {
21
-
22
- $.extend($.fn.gridEditor.locales.en, {
23
- 'text.ckeditor': 'CKEditor',
24
- });
25
-
26
- var INITIAL_CONTENT = '<p>Lorem initius... </p>';
27
-
28
- $.fn.gridEditor.texts.ckeditor = function(ge) {
29
-
30
- /**
31
- * The instance editing this content area. Kept in jQuery data when it
32
- * is made, and looked for among CKEditor's own as a fallback, since
33
- * an instance made by another version of this file has no data.
34
- */
35
- function instanceOf(contentArea) {
36
- var kept = contentArea.data('ge-ckeditor');
37
- if (kept) { return kept; }
38
-
39
- var found = null;
40
- $.each(window.CKEDITOR.instances, function(name, instance) {
41
- if (instance.element && instance.element.$ === contentArea[0]) { found = instance; }
42
- });
43
-
44
- return found;
45
- }
46
-
47
- return {
48
- labelKey: 'text.ckeditor',
49
- initialContent: INITIAL_CONTENT,
50
- missingKey: 'error.ckeditor_missing',
51
-
52
- available: function() { return !!window.CKEDITOR; },
53
-
54
- start: function(contentAreas) {
55
- var settings = ge.settings;
19
+ import { GridEditor } from '../grideditor.js';
20
+ import * as dom from '../dom.js';
21
+ import '../text/grideditor.text.js';
22
+
23
+ Object.assign(GridEditor.locales.en, {
24
+ 'text.ckeditor': 'CKEditor',
25
+ });
26
+
27
+ var INITIAL_CONTENT = '<p>Lorem initius... </p>';
28
+
29
+ // The instance each content area is edited with, as this file made it
30
+ var instances = new WeakMap();
31
+
32
+ GridEditor.texts.ckeditor = function(ge) {
33
+
34
+ /**
35
+ * The instance editing this content area. Kept when it is made, and
36
+ * looked for among CKEditor's own as a fallback, since an instance made
37
+ * by another copy of this file is not in this one's record.
38
+ */
39
+ function instanceOf(contentArea) {
40
+ var kept = instances.get(contentArea);
41
+ if (kept) { return kept; }
42
+
43
+ var found = null;
44
+ Object.keys(window.CKEDITOR.instances).forEach(function(name) {
45
+ var instance = window.CKEDITOR.instances[name];
46
+ if (instance.element && instance.element.$ === contentArea) { found = instance; }
47
+ });
48
+
49
+ return found;
50
+ }
51
+
52
+ return {
53
+ labelKey: 'text.ckeditor',
54
+ initialContent: INITIAL_CONTENT,
55
+ missingKey: 'error.ckeditor_missing',
56
+
57
+ available: function() { return !!window.CKEDITOR; },
58
+
59
+ start: function(contentAreas) {
60
+ var settings = ge.settings;
61
+
62
+ contentAreas.forEach(function(contentArea) {
63
+ if (dom.hasClass(contentArea, 'active')) { return; }
64
+
65
+ if (contentArea.innerHTML == INITIAL_CONTENT) {
66
+ // CKEditor kills this '&nbsp' creating a non usable box :/
67
+ contentArea.innerHTML = '&nbsp;';
68
+ }
69
+
70
+ // contenteditable="true", or CKEditor loads readonly
71
+ dom.addClass(contentArea, 'active');
72
+ contentArea.setAttribute('contenteditable', 'true');
73
+
74
+ var configuration = Object.assign(
75
+ {},
76
+ (settings.ckeditor && settings.ckeditor.config ? settings.ckeditor.config : {}),
77
+ {
78
+ // Focus editor on creation
79
+ on: {
80
+ instanceReady: function( evt ) {
81
+ // Call original instanceReady function, if one was passed in the config
82
+ var callback;
83
+ try {
84
+ callback = settings.ckeditor.config.on.instanceReady;
85
+ } catch (err) {
86
+ // No callback passed
87
+ }
88
+ if (callback) {
89
+ callback.call(this, evt);
90
+ }
56
91
 
57
- contentAreas.each(function() {
58
- var contentArea = $(this);
59
- if (contentArea.hasClass('active')) { return; }
92
+ // The editor owns what is inside the
93
+ // content area now, so the grid editor is
94
+ // told to put its own furniture back
95
+ ge.textReady(contentArea);
60
96
 
61
- if (contentArea.html() == INITIAL_CONTENT) {
62
- // CKEditor kills this '&nbsp' creating a non usable box :/
63
- contentArea.html('&nbsp;');
64
- }
65
-
66
- // Add the .attr('contenteditable',''true') or CKEditor loads readonly
67
- contentArea.addClass('active').attr('contenteditable', 'true');
68
-
69
- var configuration = $.extend(
70
- {},
71
- (settings.ckeditor && settings.ckeditor.config ? settings.ckeditor.config : {}),
72
- {
73
- // Focus editor on creation
74
- on: {
75
- instanceReady: function( evt ) {
76
- // Call original instanceReady function, if one was passed in the config
77
- var callback;
78
- try {
79
- callback = settings.ckeditor.config.on.instanceReady;
80
- } catch (err) {
81
- // No callback passed
82
- }
83
- if (callback) {
84
- callback.call(this, evt);
85
- }
86
-
87
- // The editor owns what is inside the
88
- // content area now, so the grid editor is
89
- // told to put its own furniture back
90
- ge.textReady(contentArea);
91
-
92
- instance.focus();
93
- }
97
+ instance.focus();
94
98
  }
95
99
  }
96
- );
97
- var instance = window.CKEDITOR.inline(contentArea.get(0), configuration);
98
- contentArea.data('ge-ckeditor', instance);
99
- });
100
- },
101
-
102
- stop: function(contentAreas) {
103
- contentAreas.filter('.active').each(function() {
104
- var contentArea = $(this);
105
-
106
- // This content area's instance, and no other: up to 5.x
107
- // closing one content area destroyed every CKEditor on
108
- // the page, other editors' and the host's own included
109
- var instance = window.CKEDITOR ? instanceOf(contentArea) : null;
110
- if (instance) { instance.destroy(); }
111
- contentArea.removeData('ge-ckeditor');
112
-
113
- // Cleanup
114
- contentArea
115
- .removeClass('active cke_focus')
116
- .removeAttr('id')
117
- .removeAttr('style')
118
- .removeAttr('spellcheck')
119
- .removeAttr('contenteditable')
120
- ;
100
+ }
101
+ );
102
+ var instance = window.CKEDITOR.inline(contentArea, configuration);
103
+ instances.set(contentArea, instance);
104
+ });
105
+ },
106
+
107
+ stop: function(contentAreas) {
108
+ contentAreas.filter(function(contentArea) {
109
+ return dom.hasClass(contentArea, 'active');
110
+ }).forEach(function(contentArea) {
111
+ // This content area's instance, and no other: up to 5.x
112
+ // closing one content area destroyed every CKEditor on
113
+ // the page, other editors' and the host's own included
114
+ var instance = window.CKEDITOR ? instanceOf(contentArea) : null;
115
+ if (instance) { instance.destroy(); }
116
+ instances.delete(contentArea);
117
+
118
+ // Cleanup
119
+ dom.removeClass(contentArea, 'active cke_focus');
120
+ ['id', 'style', 'spellcheck', 'contenteditable'].forEach(function(name) {
121
+ contentArea.removeAttribute(name);
121
122
  });
122
- },
123
- };
123
+ });
124
+ },
124
125
  };
125
- })(jQuery);
126
+ };