@themarioga/grid-editor 6.0.0-beta.4 → 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.
- package/CHANGELOG.md +24 -0
- package/README.md +57 -2
- package/dist/grideditor.css +46 -0
- package/dist/grideditor.min.css +1 -1
- package/dist/grideditor.min.css.map +1 -1
- package/dist/jquery.grideditor.bundle.min.js +2 -2
- package/dist/jquery.grideditor.js +53 -20
- package/dist/jquery.grideditor.min.js +1 -1
- package/dist/jquery.grideditor.min.js.map +1 -1
- package/dist/locales/grideditor.es.js +4 -0
- package/dist/locales/grideditor.es.min.js +1 -1
- package/dist/locales/grideditor.es.min.js.map +1 -1
- package/dist/plugins/grideditor.codemirror-inline.js +190 -0
- package/dist/plugins/grideditor.codemirror-inline.min.js +2 -0
- package/dist/plugins/grideditor.codemirror-inline.min.js.map +1 -0
- package/dist/plugins/grideditor.codemirror.js +79 -0
- package/dist/plugins/grideditor.codemirror.min.js +2 -0
- package/dist/plugins/grideditor.codemirror.min.js.map +1 -0
- package/docs/events.md +6 -0
- package/docs/locale-keys.md +13 -0
- package/docs/plugins.md +18 -3
- package/example/codemirror.html +103 -0
- package/example/index.html +8 -0
- package/package.json +1 -1
- package/src/js/jquery.grideditor.js +53 -20
- package/src/js/locales/grideditor.es.js +4 -0
- package/src/js/plugins/grideditor.codemirror-inline.js +190 -0
- package/src/js/plugins/grideditor.codemirror.js +79 -0
- package/src/less/grideditor.less +54 -0
|
@@ -23,6 +23,9 @@
|
|
|
23
23
|
'tool.add_text_type': 'Añadir texto con {editor}',
|
|
24
24
|
'tool.delete_text': 'Quitar texto',
|
|
25
25
|
'tool.delete_plain': 'Quitar contenido',
|
|
26
|
+
'tool.edit_html': 'Editar html',
|
|
27
|
+
'codemirror.apply': 'Aplicar',
|
|
28
|
+
'codemirror.cancel': 'Cancelar',
|
|
26
29
|
'tool.convert_type': 'Editar como texto de {editor}',
|
|
27
30
|
'text.add': 'Texto',
|
|
28
31
|
'text.add_type': 'Texto ({editor})',
|
|
@@ -161,6 +164,7 @@
|
|
|
161
164
|
'warning.setting_removed': 'El ajuste {setting} se eliminó en la 4.0. Usa {replacement} en su lugar.',
|
|
162
165
|
'error.tinymce_missing': '¡tinyMCE no está disponible! Asegúrate de haber cargado el archivo js de tinyMCE.',
|
|
163
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.',
|
|
164
168
|
'error.summernote_missing': '¡Summernote no está disponible! Asegúrate de haber cargado el archivo js de Summernote.',
|
|
165
169
|
};
|
|
166
170
|
|
|
@@ -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);
|
package/src/less/grideditor.less
CHANGED
|
@@ -94,6 +94,60 @@
|
|
|
94
94
|
display: none;
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
+
/* A block's html edited in place, with the codemirror-inline plugin: the
|
|
98
|
+
block is hidden behind its editor while it is open */
|
|
99
|
+
.ge-canvas.ge-editing {
|
|
100
|
+
.ge-code-hidden {
|
|
101
|
+
display: none !important;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
.ge-tools-drawer.ge-code-inline {
|
|
105
|
+
position: relative;
|
|
106
|
+
width: 100%;
|
|
107
|
+
margin: 0 0 @editGutter;
|
|
108
|
+
padding: 4px;
|
|
109
|
+
background: #f8f9fa;
|
|
110
|
+
border: 1px solid #ced4da;
|
|
111
|
+
border-radius: 4px;
|
|
112
|
+
cursor: auto;
|
|
113
|
+
-webkit-user-select: text;
|
|
114
|
+
user-select: text;
|
|
115
|
+
|
|
116
|
+
> .ge-code-inline-source {
|
|
117
|
+
width: 100%;
|
|
118
|
+
min-height: 120px;
|
|
119
|
+
font-family: monospace;
|
|
120
|
+
font-size: 13px;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.CodeMirror {
|
|
124
|
+
height: auto;
|
|
125
|
+
border: 1px solid #ced4da;
|
|
126
|
+
font-size: 13px;
|
|
127
|
+
}
|
|
128
|
+
.CodeMirror-scroll {
|
|
129
|
+
min-height: 120px;
|
|
130
|
+
max-height: 60vh;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
> .ge-code-inline-bar {
|
|
134
|
+
display: flex;
|
|
135
|
+
gap: 4px;
|
|
136
|
+
justify-content: flex-end;
|
|
137
|
+
padding-top: 4px;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/* The source view in a code editor, with the codemirror plugin: where the
|
|
143
|
+
textarea was, and as wide */
|
|
144
|
+
.ge-code-editor {
|
|
145
|
+
width: 100%;
|
|
146
|
+
border: 1px solid #ced4da;
|
|
147
|
+
border-radius: 4px;
|
|
148
|
+
font-size: 13px;
|
|
149
|
+
}
|
|
150
|
+
|
|
97
151
|
/* Not editing */
|
|
98
152
|
.ge-canvas {
|
|
99
153
|
.ge-tools-drawer {
|