@themarioga/grid-editor 6.0.0-beta.3 → 6.0.0-beta.5

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 (50) hide show
  1. package/BUILDING.md +3 -1
  2. package/CHANGELOG.md +74 -1
  3. package/README.md +71 -5
  4. package/UPGRADING.md +36 -7
  5. package/dist/grideditor.css +60 -0
  6. package/dist/grideditor.min.css +1 -1
  7. package/dist/grideditor.min.css.map +1 -1
  8. package/dist/jquery.grideditor.bundle.min.js +2 -2
  9. package/dist/jquery.grideditor.js +353 -402
  10. package/dist/jquery.grideditor.min.js +1 -1
  11. package/dist/jquery.grideditor.min.js.map +1 -1
  12. package/dist/locales/grideditor.es.js +7 -0
  13. package/dist/locales/grideditor.es.min.js +1 -1
  14. package/dist/locales/grideditor.es.min.js.map +1 -1
  15. package/dist/plugins/grideditor.ckeditor.js +397 -3
  16. package/dist/plugins/grideditor.ckeditor.min.js +1 -1
  17. package/dist/plugins/grideditor.ckeditor.min.js.map +1 -1
  18. package/dist/plugins/grideditor.codemirror-inline.js +190 -0
  19. package/dist/plugins/grideditor.codemirror-inline.min.js +2 -0
  20. package/dist/plugins/grideditor.codemirror-inline.min.js.map +1 -0
  21. package/dist/plugins/grideditor.codemirror.js +79 -0
  22. package/dist/plugins/grideditor.codemirror.min.js +2 -0
  23. package/dist/plugins/grideditor.codemirror.min.js.map +1 -0
  24. package/dist/plugins/grideditor.summernote.js +397 -3
  25. package/dist/plugins/grideditor.summernote.min.js +1 -1
  26. package/dist/plugins/grideditor.summernote.min.js.map +1 -1
  27. package/dist/plugins/grideditor.tinymce.js +397 -3
  28. package/dist/plugins/grideditor.tinymce.min.js +1 -1
  29. package/dist/plugins/grideditor.tinymce.min.js.map +1 -1
  30. package/dist/plugins/grideditor.visibility.js +1 -1
  31. package/dist/plugins/grideditor.visibility.min.js +1 -1
  32. package/dist/plugins/grideditor.visibility.min.js.map +1 -1
  33. package/docs/events.md +17 -2
  34. package/docs/locale-keys.md +25 -3
  35. package/docs/plugins.md +124 -46
  36. package/example/codemirror.html +103 -0
  37. package/example/custom_editor.html +193 -0
  38. package/example/index.html +16 -0
  39. package/example/wrap_content.html +5 -3
  40. package/package.json +1 -1
  41. package/src/js/jquery.grideditor.js +353 -402
  42. package/src/js/locales/grideditor.es.js +7 -0
  43. package/src/js/plugins/grideditor.ckeditor.js +7 -3
  44. package/src/js/plugins/grideditor.codemirror-inline.js +190 -0
  45. package/src/js/plugins/grideditor.codemirror.js +79 -0
  46. package/src/js/plugins/grideditor.summernote.js +7 -3
  47. package/src/js/plugins/grideditor.tinymce.js +7 -3
  48. package/src/js/plugins/grideditor.visibility.js +1 -1
  49. package/src/js/text/grideditor.text.js +389 -0
  50. package/src/less/grideditor.less +71 -0
@@ -22,6 +22,11 @@
22
22
  'tool.add_text': 'Añadir texto',
23
23
  'tool.add_text_type': 'Añadir texto con {editor}',
24
24
  'tool.delete_text': 'Quitar texto',
25
+ 'tool.delete_plain': 'Quitar contenido',
26
+ 'tool.edit_html': 'Editar html',
27
+ 'codemirror.apply': 'Aplicar',
28
+ 'codemirror.cancel': 'Cancelar',
29
+ 'tool.convert_type': 'Editar como texto de {editor}',
25
30
  'text.add': 'Texto',
26
31
  'text.add_type': 'Texto ({editor})',
27
32
  'text.no_editor': 'No hay cargado ningún editor de texto "{type}": este texto se puede mover y borrar, pero no editar',
@@ -84,6 +89,7 @@
84
89
  'confirm.delete_row': '¿Seguro que quieres borrar esta fila?',
85
90
  'confirm.delete_column': '¿Seguro que quieres borrar esta columna?',
86
91
  'confirm.delete_text': '¿Seguro que quieres borrar este texto?',
92
+ 'confirm.delete_plain': '¿Seguro que quieres borrar este contenido?',
87
93
  'confirm.delete_element': '¿Seguro que quieres borrar este elemento?',
88
94
  'confirm.delete_container': '¿Seguro que quieres borrar este contenedor y todo su contenido?',
89
95
  'confirm.delete_tab': '¿Seguro que quieres borrar esta pestaña y todo su contenido?',
@@ -158,6 +164,7 @@
158
164
  'warning.setting_removed': 'El ajuste {setting} se eliminó en la 4.0. Usa {replacement} en su lugar.',
159
165
  'error.tinymce_missing': '¡tinyMCE no está disponible! Asegúrate de haber cargado el archivo js de tinyMCE.',
160
166
  'error.ckeditor_missing': '¡CKEditor no está disponible! Asegúrate de haber cargado los archivos js de ckeditor y del adaptador de jQuery.',
167
+ 'error.codemirror_missing': '¡CodeMirror no está disponible! Asegúrate de haber cargado el archivo js de CodeMirror; sin él el código se edita en un textarea normal.',
161
168
  'error.summernote_missing': '¡Summernote no está disponible! Asegúrate de haber cargado el archivo js de Summernote.',
162
169
  };
163
170
 
@@ -2,8 +2,8 @@
2
2
  * CKEditor for grid-editor's content areas.
3
3
  *
4
4
  * A text editor plugin: load this file after the editor, and CKEditor 4
5
- * after or before it, and content_types: ['ckeditor'] edits each content area
6
- * with an inline CKEditor. What it can ask the editor for is the handle its
5
+ * after or before it, and a text of the ckeditor type is edited with an
6
+ * inline CKEditor. What it can ask the editor for is the handle its
7
7
  * factory is called with, described in docs/plugins.md.
8
8
  *
9
9
  * <script src="ckeditor/ckeditor.js"></script>
@@ -11,7 +11,11 @@
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.
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.
15
19
  */
16
20
  (function($) {
17
21
 
@@ -0,0 +1,190 @@
1
+ /**
2
+ * A block's html, edited in place with CodeMirror.
3
+ *
4
+ * A feature plugin: load this file after the editor, and CodeMirror 5 with
5
+ * its html mode after or before it, and every drawer of a row, a column, a
6
+ * text, the host's plain content, an element, a section or a container has a
7
+ * </> tool. It opens the block's html - the block itself and everything in
8
+ * it, as getHtml would give it - in CodeMirror where the block was, and
9
+ * Apply puts what was written in the block's place. What it can ask the
10
+ * editor for is the handle its factory is called with, described in
11
+ * docs/plugins.md.
12
+ *
13
+ * <link rel="stylesheet" href="codemirror/lib/codemirror.css">
14
+ * <script src="codemirror/lib/codemirror.js"></script>
15
+ * <script src="codemirror/mode/xml/xml.js"></script>
16
+ * <script src="codemirror/mode/javascript/javascript.js"></script>
17
+ * <script src="codemirror/mode/css/css.js"></script>
18
+ * <script src="codemirror/mode/htmlmixed/htmlmixed.js"></script>
19
+ * <script src="dist/jquery.grideditor.min.js"></script>
20
+ * <script src="dist/plugins/grideditor.codemirror-inline.min.js"></script>
21
+ *
22
+ * Without CodeMirror on the page the html is edited in a plain textarea.
23
+ * CodeMirror's options are the codemirror plugin's, codemirror.config.
24
+ */
25
+ (function($) {
26
+
27
+ $.extend($.fn.gridEditor.locales.en, {
28
+ 'tool.edit_html': 'Edit html',
29
+ 'codemirror.apply': 'Apply',
30
+ 'codemirror.cancel': 'Cancel',
31
+ });
32
+
33
+ /** What has html of its own to edit: a pane's is split between its button and its body. */
34
+ var KINDS = ['row', 'column', 'text', 'plain', 'element', 'section'];
35
+
36
+ $.fn.gridEditor.features['codemirror-inline'] = function(ge) {
37
+
38
+ var open = []; // The blocks being edited: { node, kind, from, wrapper, textarea, editor }
39
+
40
+ function options() {
41
+ var own = (ge.settings.codemirror && ge.settings.codemirror.config) || {};
42
+
43
+ return $.extend({
44
+ mode: 'htmlmixed',
45
+ lineNumbers: true,
46
+ lineWrapping: true,
47
+ tabSize: 2,
48
+ indentUnit: 2,
49
+ // As tall as what it holds, up to the css's limit
50
+ viewportMargin: Infinity,
51
+ }, own);
52
+ }
53
+
54
+ /** What stands for the node in its column: a text's text block, or the node. */
55
+ function anchorOf(node) {
56
+ var textBlock = node.parent('.ge-text-block');
57
+ return textBlock.length ? textBlock : node;
58
+ }
59
+
60
+ function entryOf(node) {
61
+ return open.filter(function(entry) { return entry.node[0] === node[0]; })[0] || null;
62
+ }
63
+
64
+ function editable(node, kind) {
65
+ return KINDS.indexOf(kind) !== -1 || node.is('[data-ge-container]');
66
+ }
67
+
68
+ /** The editor where the block was, the block hidden behind it. */
69
+ function show(entry) {
70
+ var anchor = anchorOf(entry.node).addClass('ge-code-hidden');
71
+ entry.wrapper.insertAfter(anchor);
72
+ if (entry.editor) { entry.editor.refresh(); }
73
+ }
74
+
75
+ function hide(entry) {
76
+ entry.wrapper.detach();
77
+ anchorOf(entry.node).removeClass('ge-code-hidden');
78
+ entry.node.removeClass('ge-code-hidden');
79
+ }
80
+
81
+ function close(entry) {
82
+ hide(entry);
83
+ if (entry.editor) { entry.editor.toTextArea(); }
84
+ entry.wrapper.remove();
85
+ open.splice(open.indexOf(entry), 1);
86
+ }
87
+
88
+ function openEditor(node) {
89
+ if (entryOf(node)) { return; }
90
+
91
+ var entry = {
92
+ node: node,
93
+ kind: ge.kindOf(node),
94
+ // As getHtml gives it: no drawers, no editor open in it
95
+ from: ge.nodeHtml(node),
96
+ // A drawer, to the editor: never content, never a block to move
97
+ wrapper: $('<div class="ge-tools-drawer ge-code-inline" />'),
98
+ editor: null,
99
+ };
100
+ entry.textarea = $('<textarea class="ge-code-inline-source" />').val(entry.from).appendTo(entry.wrapper);
101
+
102
+ var bar = $('<div class="ge-code-inline-bar" />').appendTo(entry.wrapper);
103
+ $('<button type="button" class="btn btn-sm btn-primary ge-code-apply" />')
104
+ .text(ge.t('codemirror.apply'))
105
+ .on('click', function() { apply(entry); })
106
+ .appendTo(bar);
107
+ $('<button type="button" class="btn btn-sm btn-outline-secondary ge-code-cancel" />')
108
+ .text(ge.t('codemirror.cancel'))
109
+ .on('click', function() { close(entry); })
110
+ .appendTo(bar);
111
+
112
+ open.push(entry);
113
+ show(entry);
114
+
115
+ if (window.CodeMirror) {
116
+ entry.editor = window.CodeMirror.fromTextArea(entry.textarea[0], options());
117
+ $(entry.editor.getWrapperElement()).addClass('ge-code-editor');
118
+ entry.editor.focus();
119
+ } else {
120
+ entry.textarea.trigger('focus');
121
+ }
122
+ }
123
+
124
+ /**
125
+ * What was written, in the block's place, through the edit-html events.
126
+ * The canvas leaves editing to take it in and comes back, as it does for
127
+ * getHtml, so what was written is read as the editor reads any markup.
128
+ */
129
+ function apply(entry) {
130
+ var to = entry.editor ? entry.editor.getValue() : entry.textarea.val();
131
+ var payload = ge.payloadFor(entry.kind, entry.node, { source: 'tool', from: entry.from, to: to });
132
+
133
+ // Canceled, the editor stays open with what was written in it
134
+ if (!ge.emit('before-edit-html', payload)) { return; }
135
+
136
+ close(entry);
137
+
138
+ var instance = ge.canvas.data('grideditor');
139
+ instance.deinit();
140
+
141
+ var made = $('<div />').html(to).contents();
142
+ entry.node.replaceWith(made);
143
+
144
+ instance.init();
145
+
146
+ ge.emit('after-edit-html', ge.payloadFor(entry.kind, made.filter('*'), {
147
+ source: 'tool',
148
+ from: entry.from,
149
+ to: to,
150
+ }));
151
+ }
152
+
153
+ function tool(drawer, node) {
154
+ ge.createTool(drawer, ge.t('tool.edit_html'), 'ge-edit-html', 'bi bi-code-slash', function() {
155
+ openEditor(node);
156
+ });
157
+ }
158
+
159
+ return {
160
+ drawerTools: function(drawer, node, kind) {
161
+ if (editable(node, kind)) { tool(drawer, node); }
162
+ },
163
+
164
+ // Plain content has no gear, and so none of the drawerTools: its
165
+ // html is what there is to edit about it
166
+ plainTools: tool,
167
+
168
+ // Every deinit - getHtml's among them - takes the editors off the
169
+ // canvas, whatever is in them, and every init puts them back where
170
+ // their block is. A block that is gone takes its editor with it.
171
+ onBeforeDeinit: function() {
172
+ open.forEach(hide);
173
+ },
174
+
175
+ onInit: function() {
176
+ open.slice().forEach(function(entry) {
177
+ if (!$.contains(document.documentElement, entry.node[0])) {
178
+ if (entry.editor) { entry.editor.toTextArea(); }
179
+ entry.wrapper.remove();
180
+ open.splice(open.indexOf(entry), 1);
181
+ return;
182
+ }
183
+
184
+ show(entry);
185
+ });
186
+ },
187
+ };
188
+ };
189
+
190
+ })(jQuery);
@@ -0,0 +1,79 @@
1
+ /**
2
+ * CodeMirror for grid-editor's source view.
3
+ *
4
+ * A feature plugin: load this file after the editor, and CodeMirror 5 with
5
+ * its html mode after or before it, and the toolbar's source button edits the
6
+ * canvas's html in CodeMirror - highlighted, with line numbers - rather than
7
+ * in a plain textarea. What it can ask the editor for is the handle its
8
+ * factory is called with, described in docs/plugins.md.
9
+ *
10
+ * <link rel="stylesheet" href="codemirror/lib/codemirror.css">
11
+ * <script src="codemirror/lib/codemirror.js"></script>
12
+ * <script src="codemirror/mode/xml/xml.js"></script>
13
+ * <script src="codemirror/mode/javascript/javascript.js"></script>
14
+ * <script src="codemirror/mode/css/css.js"></script>
15
+ * <script src="codemirror/mode/htmlmixed/htmlmixed.js"></script>
16
+ * <script src="dist/jquery.grideditor.min.js"></script>
17
+ * <script src="dist/plugins/grideditor.codemirror.min.js"></script>
18
+ *
19
+ * CodeMirror 5 rather than 6: 6 comes as ES modules only, for a bundler,
20
+ * where 5 loads from a script tag like the rest of the page. Without
21
+ * CodeMirror on the page the source view is the textarea, as before, and
22
+ * the console says why.
23
+ */
24
+ (function($) {
25
+
26
+ $.extend($.fn.gridEditor.locales.en, {
27
+ 'error.codemirror_missing': 'CodeMirror not available! Make sure you loaded the CodeMirror js file; the source is edited in a plain textarea without it.',
28
+ });
29
+
30
+ $.fn.gridEditor.features.codemirror = function(ge) {
31
+
32
+ var editor = null;
33
+ var warned = false;
34
+
35
+ function options() {
36
+ var own = (ge.settings.codemirror && ge.settings.codemirror.config) || {};
37
+
38
+ return $.extend({
39
+ mode: 'htmlmixed',
40
+ lineNumbers: true,
41
+ lineWrapping: true,
42
+ tabSize: 2,
43
+ indentUnit: 2,
44
+ }, own);
45
+ }
46
+
47
+ return {
48
+ // Over the textarea the editor fills with the canvas's html: it goes
49
+ // where the textarea was, as tall as the editor made the textarea
50
+ onSourceOpen: function(textarea) {
51
+ if (!window.CodeMirror) {
52
+ if (!warned) {
53
+ warned = true;
54
+ ge.warn(ge.t('error.codemirror_missing'));
55
+ }
56
+ return;
57
+ }
58
+
59
+ var height = textarea.height();
60
+
61
+ editor = window.CodeMirror.fromTextArea(textarea[0], options());
62
+ $(editor.getWrapperElement()).addClass('ge-code-editor');
63
+ editor.setSize(null, height);
64
+ editor.focus();
65
+ },
66
+
67
+ // What it holds goes back in the textarea, which is what the canvas
68
+ // is made of again, and the textarea is left as it found it
69
+ onSourceClose: function() {
70
+ if (!editor) { return; }
71
+
72
+ editor.save();
73
+ editor.toTextArea();
74
+ editor = null;
75
+ },
76
+ };
77
+ };
78
+
79
+ })(jQuery);
@@ -2,8 +2,8 @@
2
2
  * Summernote for grid-editor's content areas.
3
3
  *
4
4
  * A text editor plugin: load this file after the editor, and summernote
5
- * after or before it, and content_types: ['summernote'] edits each content
6
- * area with summernote in air mode. What it can ask the editor for is the
5
+ * after or before it, and a text of the summernote type is edited with
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
9
  * <script src="summernote/summernote-bs5.min.js"></script>
@@ -11,7 +11,11 @@
11
11
  * <script src="dist/plugins/grideditor.summernote.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.
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.
15
19
  */
16
20
  (function($) {
17
21
 
@@ -2,8 +2,8 @@
2
2
  * tinyMCE for grid-editor's content areas.
3
3
  *
4
4
  * A text editor plugin: load this file after the editor, and tinyMCE 6
5
- * after or before it, and content_types: ['tinymce'] edits each content area
6
- * with an inline tinyMCE. What it can ask the editor for is the handle its
5
+ * after or before it, and a text of the tinymce type is edited with an
6
+ * inline tinyMCE. What it can ask the editor for is the handle its
7
7
  * factory is called with, described in docs/plugins.md.
8
8
  *
9
9
  * <script src="tinymce/tinymce.min.js"></script>
@@ -11,7 +11,11 @@
11
11
  * <script src="dist/plugins/grideditor.tinymce.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.
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.
15
19
  */
16
20
  (function($) {
17
21
 
@@ -44,7 +44,7 @@ $.fn.gridEditor.utilities.visibility = function(ge) {
44
44
  }
45
45
 
46
46
  function applies(node, kind) {
47
- return kind === 'row' || kind === 'column' || kind === 'element' || kind === 'text' ||
47
+ return kind === 'row' || kind === 'column' || kind === 'element' || kind === 'text' || kind === 'plain' ||
48
48
  node.is('[data-ge-container]');
49
49
  }
50
50