@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
@@ -0,0 +1,325 @@
1
+ /**
2
+ * The jQuery API of grid-editor 6, on top of the 7.0 editor.
3
+ *
4
+ * grid-editor is plain DOM since 7.0. A page written for 6.x - one that
5
+ * calls $(el).gridEditor(...), listens with $(el).on('grideditor:...') and
6
+ * reads jQuery objects out of the payloads - loads jQuery 4 and this file
7
+ * after grideditor.js, and runs unchanged:
8
+ *
9
+ * <script src="jquery.min.js"></script>
10
+ * <script src="dist/grideditor.min.js"></script>
11
+ * <script src="dist/grideditor.jquery.min.js"></script>
12
+ * <script src="dist/plugins/grideditor.tabs.min.js"></script>
13
+ *
14
+ * What it keeps is the host's side of 6.x. Plugins are not: a plugin
15
+ * written for 6.x registered on $.fn.gridEditor.containers, .features,
16
+ * .utilities or .texts, and is warned about and left out, since the plugin
17
+ * contract hands out elements now. UPGRADING.md says how to port one.
18
+ *
19
+ * Every value 6.x gave host code as a jQuery object is one again: the event
20
+ * payloads and the callbacks' arguments, what the create* methods return,
21
+ * the handle $(el).data('grideditor') gives, the canvas custom_filter gets,
22
+ * and the event a host tool's handler gets. What the host hands in may be a
23
+ * jQuery object wherever 6.x took one.
24
+ */
25
+ import { GridEditor } from './grideditor.js';
26
+
27
+ var $ = window.jQuery;
28
+
29
+ var english = function(key, params) { return GridEditor.t({ locale: 'en' }, key, params); };
30
+
31
+ var warned = {};
32
+
33
+ function warnOnce(key, message) {
34
+ if (warned[key]) { return; }
35
+ warned[key] = true;
36
+ if (window.console && window.console.warn) { window.console.warn('grid-editor: ' + message); }
37
+ }
38
+
39
+ if (!$ || !$.fn) {
40
+ warnOnce('no-jquery', english('warning.adapter_no_jquery'));
41
+ } else {
42
+ install();
43
+ }
44
+
45
+ function install() {
46
+
47
+ /**
48
+ * Every method 6.x dispatched, and which hand back something other than
49
+ * the jQuery set: those run against the first element only, and do not
50
+ * chain.
51
+ */
52
+ var METHODS = {
53
+ getHtml: { value: true },
54
+ getPlainHtml: { value: true },
55
+ init: {},
56
+ deinit: {},
57
+ reset: {},
58
+ destroy: {},
59
+ changeView: {},
60
+ getView: { value: true },
61
+ createRow: { value: true },
62
+ createColumn: { value: true },
63
+ createElement: { value: true },
64
+ createText: { value: true },
65
+ createSection: { value: true },
66
+ createContainer: { value: true },
67
+ addTab: { value: true },
68
+ addAccordionItem: { value: true },
69
+ setLocale: {},
70
+ getUtility: { value: true },
71
+ setUtility: { value: true },
72
+ };
73
+
74
+ /** The *_tools settings, whose handlers 6.x bound with jQuery. */
75
+ var TOOL_SETTINGS = ['row_tools', 'col_tools', 'element_tools', 'container_tools',
76
+ 'tab_tools', 'accordion_tools', 'text_tools'];
77
+
78
+ function isElement(value) {
79
+ return !!value && value.nodeType === 1;
80
+ }
81
+
82
+ /** What the host handed in, as the editor takes it: a jQuery object is its first element. */
83
+ function unwrap(value) {
84
+ if (value instanceof $) { return value[0] || null; }
85
+ return value;
86
+ }
87
+
88
+ /** An argument, and the options object an argument may be, unwrapped one level down. */
89
+ function unwrapArgument(value) {
90
+ if (value instanceof $) { return unwrap(value); }
91
+
92
+ if (value && typeof value === 'object' && !Array.isArray(value) && !isElement(value)) {
93
+ var copy = {};
94
+ Object.keys(value).forEach(function(key) { copy[key] = unwrap(value[key]); });
95
+ return copy;
96
+ }
97
+
98
+ return value;
99
+ }
100
+
101
+ /** What the editor handed back, as 6.x did: an element is a jQuery object. */
102
+ function wrapResult(value) {
103
+ return isElement(value) ? $(value) : value;
104
+ }
105
+
106
+ /**
107
+ * A payload as 6.x built it: its nodes jQuery objects, and an empty set
108
+ * where there is no node - a detached node's parent. The same payload
109
+ * wraps to the same object, so every listener of one notification sees
110
+ * one payload, as they did.
111
+ */
112
+ var wrappedPayloads = new WeakMap();
113
+
114
+ function wrapPayload(payload) {
115
+ if (!payload || typeof payload !== 'object') { return payload; }
116
+ if (wrappedPayloads.has(payload)) { return wrappedPayloads.get(payload); }
117
+
118
+ var copy = Object.assign({}, payload);
119
+
120
+ ['node', 'parent', 'canvas'].forEach(function(key) {
121
+ if (key in payload) { copy[key] = $(payload[key] || []); }
122
+ });
123
+ if (payload.container) { copy.container = $(payload.container); }
124
+ // edit-html writes any number of nodes, which 6.x gave as one set
125
+ if (Array.isArray(payload.nodes)) { copy.node = $(payload.nodes); }
126
+ ['from', 'to'].forEach(function(key) {
127
+ var position = payload[key];
128
+ if (position && typeof position === 'object' && 'parent' in position) {
129
+ copy[key] = Object.assign({}, position, { parent: $(position.parent || []) });
130
+ }
131
+ });
132
+
133
+ wrappedPayloads.set(payload, copy);
134
+ return copy;
135
+ }
136
+
137
+ /**
138
+ * The events, as jQuery handlers had them: (event, payload).
139
+ *
140
+ * The editor dispatches DOM events, which jQuery hands its handlers with
141
+ * no second argument. Its dispatcher is where every one of them passes,
142
+ * delegated ones too, so that is where the payload goes back in: once,
143
+ * for each handler, and preventDefault() on the jQuery event is
144
+ * preventDefault() on the editor's.
145
+ */
146
+ var dispatch = $.event.dispatch;
147
+ $.event.dispatch = function(nativeEvent) {
148
+ if (arguments.length === 1 && nativeEvent instanceof window.CustomEvent &&
149
+ typeof nativeEvent.type === 'string' && nativeEvent.type.indexOf('grideditor:') === 0) {
150
+ return dispatch.call(this, nativeEvent, wrapPayload(nativeEvent.detail));
151
+ }
152
+
153
+ return dispatch.apply(this, arguments);
154
+ };
155
+
156
+ /** A handler of a host's tool, given a jQuery event as 6.x gave it. */
157
+ function jqueryHandler(handler) {
158
+ return function(event) {
159
+ return handler.call(this, $.event.fix(event));
160
+ };
161
+ }
162
+
163
+ function adaptTool(tool) {
164
+ if (!tool || !tool.on) { return tool; }
165
+
166
+ var on;
167
+ if (typeof tool.on === 'function') {
168
+ on = jqueryHandler(tool.on);
169
+ } else {
170
+ on = {};
171
+ Object.keys(tool.on).forEach(function(name) { on[name] = jqueryHandler(tool.on[name]); });
172
+ }
173
+
174
+ return Object.assign({}, tool, { on: on });
175
+ }
176
+
177
+ /** A custom_filter, as a function of a jQuery canvas; a name is looked up when it runs. */
178
+ function adaptFilter(filter) {
179
+ return function(canvas, isInit) {
180
+ var func = typeof filter === 'string' ? window[filter] : filter;
181
+ return func($(canvas), isInit);
182
+ };
183
+ }
184
+
185
+ /** The host's 6.x options, as the editor takes them. */
186
+ function adaptOptions(options) {
187
+ options = Object.assign({}, options || {});
188
+
189
+ if (options.callbacks) {
190
+ var callbacks = {};
191
+ Object.keys(options.callbacks).forEach(function(name) {
192
+ var callback = options.callbacks[name];
193
+ callbacks[name] = typeof callback === 'function'
194
+ ? function(payload) { return callback(wrapPayload(payload)); }
195
+ : callback;
196
+ });
197
+ options.callbacks = callbacks;
198
+ }
199
+
200
+ if (options.custom_filter && options.custom_filter.length) {
201
+ var filters = typeof options.custom_filter === 'string' || typeof options.custom_filter === 'function'
202
+ ? [options.custom_filter]
203
+ : Array.prototype.slice.call(options.custom_filter);
204
+ options.custom_filter = filters.map(adaptFilter);
205
+ }
206
+
207
+ TOOL_SETTINGS.forEach(function(name) {
208
+ if (Array.isArray(options[name])) { options[name] = options[name].map(adaptTool); }
209
+ });
210
+
211
+ options.source_textarea = unwrap(options.source_textarea);
212
+
213
+ return options;
214
+ }
215
+
216
+ /**
217
+ * The handle $(el).data('grideditor') gave in 6.x: the same methods, with
218
+ * jQuery going in and coming out, and the canvas as a jQuery object.
219
+ */
220
+ function handleFor(instance) {
221
+ var handle = { canvas: $(instance.canvas) };
222
+
223
+ Object.keys(METHODS).forEach(function(name) {
224
+ handle[name] = function() {
225
+ var result = instance[name].apply(instance, Array.prototype.map.call(arguments, unwrapArgument));
226
+ return result === instance ? undefined : wrapResult(result);
227
+ };
228
+ });
229
+
230
+ Object.defineProperty(handle, 'settings', {
231
+ enumerable: true,
232
+ get: function() { return instance.settings; },
233
+ });
234
+
235
+ return handle;
236
+ }
237
+
238
+ /**
239
+ * Every editor gets its 6.x handle, whoever made it: $(el).gridEditor()
240
+ * or new GridEditor(el). It goes with the editor.
241
+ */
242
+ GridEditor._created.push(function(instance) {
243
+ $.data(instance.canvas, 'grideditor', handleFor(instance));
244
+
245
+ var destroy = instance.destroy;
246
+ instance.destroy = function() {
247
+ var result = destroy.apply(this, arguments);
248
+ $.removeData(instance.canvas, 'grideditor');
249
+ return result;
250
+ };
251
+ });
252
+
253
+ /** Plugins registered the 6.x way: said once each, and never called. */
254
+ function warnAboutLegacyPlugins() {
255
+ ['containers', 'features', 'utilities', 'texts'].forEach(function(registry) {
256
+ Object.keys(legacy[registry]).forEach(function(name) {
257
+ warnOnce('plugin-6x:' + registry + ':' + name, english('warning.plugin_6x', { name: name }));
258
+ });
259
+ });
260
+ }
261
+
262
+ function dispatchMethod(set, name, args) {
263
+ var descriptor = METHODS[name];
264
+
265
+ if (!descriptor) {
266
+ warnOnce('method:' + name, 'unknown method "' + name + '"');
267
+ return set;
268
+ }
269
+
270
+ args = args.map(unwrapArgument);
271
+
272
+ if (descriptor.value) {
273
+ var element = set.first();
274
+ if (!element.length) { return null; }
275
+
276
+ var instance = GridEditor.get(element[0]);
277
+ if (!instance) {
278
+ if (name === 'getHtml') { return element.html(); }
279
+ if (name === 'getPlainHtml') { return GridEditor._plainHtml(element.html()); }
280
+ return null;
281
+ }
282
+
283
+ return wrapResult(instance[name].apply(instance, args));
284
+ }
285
+
286
+ set.each(function() {
287
+ var found = GridEditor.get(this);
288
+ if (found) { found[name].apply(found, args); }
289
+ });
290
+
291
+ return set;
292
+ }
293
+
294
+ /**
295
+ * $(el).gridEditor(options): an editor on each element that has none.
296
+ * $(el).gridEditor('method', ...): a method, 6.x style.
297
+ */
298
+ $.fn.gridEditor = function(optionsOrMethod) {
299
+ if (typeof optionsOrMethod == 'string') {
300
+ return dispatchMethod(this, optionsOrMethod, Array.prototype.slice.call(arguments, 1));
301
+ }
302
+
303
+ warnAboutLegacyPlugins();
304
+
305
+ var options = adaptOptions(optionsOrMethod);
306
+
307
+ this.each(function() {
308
+ GridEditor.create(this, options);
309
+ });
310
+
311
+ return this;
312
+ };
313
+
314
+ // Where a 6.x plugin registers. Kept, so one does not throw as it
315
+ // loads, and read only to say it is not used.
316
+ var legacy = { containers: {}, features: {}, utilities: {}, texts: {} };
317
+ $.fn.gridEditor.containers = legacy.containers;
318
+ $.fn.gridEditor.features = legacy.features;
319
+ $.fn.gridEditor.utilities = legacy.utilities;
320
+ $.fn.gridEditor.texts = legacy.texts;
321
+
322
+ // Strings are the same thing in both: a 6.x locale file loads unchanged
323
+ $.fn.gridEditor.locales = GridEditor.locales;
324
+ $.fn.gridEditor.t = GridEditor.t;
325
+ }