@themarioga/grid-editor 6.0.0 → 7.1.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.
- package/AUTO_SAVE.md +2 -2
- package/BUILDING.md +45 -29
- package/CHANGELOG.md +59 -0
- package/README.md +163 -87
- package/UPGRADING.md +119 -0
- package/dist/grideditor.bundle.min.js +14 -0
- package/dist/grideditor.d.ts +335 -0
- package/dist/grideditor.esm.js +3977 -0
- package/dist/grideditor.jquery.js +253 -0
- package/dist/grideditor.jquery.min.js +1 -0
- package/dist/grideditor.jquery.min.js.map +7 -0
- package/dist/grideditor.js +3983 -0
- package/dist/grideditor.min.js +6 -0
- package/dist/grideditor.min.js.map +7 -0
- package/dist/locales/grideditor.es.esm.js +158 -0
- package/dist/locales/grideditor.es.js +164 -168
- package/dist/locales/grideditor.es.min.js +6 -2
- package/dist/locales/grideditor.es.min.js.map +7 -1
- package/dist/plugins/grideditor.accordion.esm.js +294 -0
- package/dist/plugins/grideditor.accordion.js +286 -180
- package/dist/plugins/grideditor.accordion.min.js +1 -2
- package/dist/plugins/grideditor.accordion.min.js.map +7 -1
- package/dist/plugins/grideditor.alignment.esm.js +55 -0
- package/dist/plugins/grideditor.alignment.js +58 -77
- package/dist/plugins/grideditor.alignment.min.js +1 -2
- package/dist/plugins/grideditor.alignment.min.js.map +7 -1
- package/dist/plugins/grideditor.card.esm.js +73 -0
- package/dist/plugins/grideditor.card.js +74 -64
- package/dist/plugins/grideditor.card.min.js +1 -2
- package/dist/plugins/grideditor.card.min.js.map +7 -1
- package/dist/plugins/grideditor.ckeditor.esm.js +500 -0
- package/dist/plugins/grideditor.ckeditor.js +484 -449
- package/dist/plugins/grideditor.ckeditor.min.js +1 -2
- package/dist/plugins/grideditor.ckeditor.min.js.map +7 -1
- package/dist/plugins/grideditor.clipboard.esm.js +326 -0
- package/dist/plugins/grideditor.clipboard.js +298 -235
- package/dist/plugins/grideditor.clipboard.min.js +1 -2
- package/dist/plugins/grideditor.clipboard.min.js.map +7 -1
- package/dist/plugins/grideditor.codemirror-inline.esm.js +205 -0
- package/dist/plugins/grideditor.codemirror-inline.js +188 -168
- package/dist/plugins/grideditor.codemirror-inline.min.js +1 -2
- package/dist/plugins/grideditor.codemirror-inline.min.js.map +7 -1
- package/dist/plugins/grideditor.codemirror.esm.js +63 -0
- package/dist/plugins/grideditor.codemirror.js +60 -71
- package/dist/plugins/grideditor.codemirror.min.js +1 -2
- package/dist/plugins/grideditor.codemirror.min.js.map +7 -1
- package/dist/plugins/grideditor.elements.esm.js +271 -0
- package/dist/plugins/grideditor.elements.js +256 -149
- package/dist/plugins/grideditor.elements.min.js +1 -2
- package/dist/plugins/grideditor.elements.min.js.map +7 -1
- package/dist/plugins/grideditor.float.esm.js +34 -0
- package/dist/plugins/grideditor.float.js +37 -52
- package/dist/plugins/grideditor.float.min.js +1 -2
- package/dist/plugins/grideditor.float.min.js.map +7 -1
- package/dist/plugins/grideditor.gutters.esm.js +143 -0
- package/dist/plugins/grideditor.gutters.js +134 -131
- package/dist/plugins/grideditor.gutters.min.js +1 -2
- package/dist/plugins/grideditor.gutters.min.js.map +7 -1
- package/dist/plugins/grideditor.order.esm.js +189 -0
- package/dist/plugins/grideditor.order.js +170 -182
- package/dist/plugins/grideditor.order.min.js +1 -2
- package/dist/plugins/grideditor.order.min.js.map +7 -1
- package/dist/plugins/grideditor.popup.esm.js +187 -0
- package/dist/plugins/grideditor.popup.js +183 -134
- package/dist/plugins/grideditor.popup.min.js +1 -2
- package/dist/plugins/grideditor.popup.min.js.map +7 -1
- package/dist/plugins/grideditor.sections.esm.js +271 -0
- package/dist/plugins/grideditor.sections.js +250 -173
- package/dist/plugins/grideditor.sections.min.js +1 -2
- package/dist/plugins/grideditor.sections.min.js.map +7 -1
- package/dist/plugins/grideditor.spacing.esm.js +318 -0
- package/dist/plugins/grideditor.spacing.js +296 -272
- package/dist/plugins/grideditor.spacing.min.js +1 -2
- package/dist/plugins/grideditor.spacing.min.js.map +7 -1
- package/dist/plugins/grideditor.summernote.esm.js +509 -0
- package/dist/plugins/grideditor.summernote.js +493 -427
- package/dist/plugins/grideditor.summernote.min.js +1 -2
- package/dist/plugins/grideditor.summernote.min.js.map +7 -1
- package/dist/plugins/grideditor.tabs.esm.js +237 -0
- package/dist/plugins/grideditor.tabs.js +233 -139
- package/dist/plugins/grideditor.tabs.min.js +1 -2
- package/dist/plugins/grideditor.tabs.min.js.map +7 -1
- package/dist/plugins/grideditor.textalign.esm.js +40 -0
- package/dist/plugins/grideditor.textalign.js +43 -56
- package/dist/plugins/grideditor.textalign.min.js +1 -2
- package/dist/plugins/grideditor.textalign.min.js.map +7 -1
- package/dist/plugins/grideditor.tinymce.esm.js +519 -0
- package/dist/plugins/grideditor.tinymce.js +502 -490
- package/dist/plugins/grideditor.tinymce.min.js +1 -2
- package/dist/plugins/grideditor.tinymce.min.js.map +7 -1
- package/dist/plugins/grideditor.visibility.esm.js +158 -0
- package/dist/plugins/grideditor.visibility.js +140 -149
- package/dist/plugins/grideditor.visibility.min.js +1 -2
- package/dist/plugins/grideditor.visibility.min.js.map +7 -1
- package/docs/events.md +47 -21
- package/docs/locale-keys.md +6 -0
- package/docs/plugins.md +47 -25
- package/example/adapter.html +112 -0
- package/example/attributes.html +89 -62
- package/example/autocols.html +9 -9
- package/example/autosave.html +18 -16
- package/example/basic.html +8 -6
- package/example/breakpoints.html +5 -6
- package/example/ckeditor.html +4 -5
- package/example/clipboard.html +15 -11
- package/example/codemirror.html +13 -8
- package/example/containers.html +11 -9
- package/example/custom_editor.html +53 -34
- package/example/elements.html +14 -12
- package/example/index.html +16 -2
- package/example/locale.html +6 -7
- package/example/plugins.html +44 -29
- package/example/summernote.html +6 -5
- package/example/utilities.html +17 -13
- package/example/wrap_content.html +13 -10
- package/package.json +44 -12
- package/src/js/dom.js +401 -0
- package/src/js/grideditor.classic.js +16 -0
- package/src/js/grideditor.jquery.js +325 -0
- package/src/js/{jquery.grideditor.js → grideditor.js} +1284 -1124
- package/src/js/locales/grideditor.es.js +163 -156
- package/src/js/plugins/grideditor.accordion.js +97 -77
- package/src/js/plugins/grideditor.alignment.js +5 -7
- package/src/js/plugins/grideditor.card.js +23 -23
- package/src/js/plugins/grideditor.ckeditor.js +107 -106
- package/src/js/plugins/grideditor.clipboard.js +49 -37
- package/src/js/plugins/grideditor.codemirror-inline.js +50 -37
- package/src/js/plugins/grideditor.codemirror.js +9 -10
- package/src/js/plugins/grideditor.elements.js +57 -33
- package/src/js/plugins/grideditor.float.js +4 -6
- package/src/js/plugins/grideditor.gutters.js +20 -15
- package/src/js/plugins/grideditor.order.js +28 -25
- package/src/js/plugins/grideditor.popup.js +63 -51
- package/src/js/plugins/grideditor.sections.js +39 -32
- package/src/js/plugins/grideditor.spacing.js +42 -45
- package/src/js/plugins/grideditor.summernote.js +112 -76
- package/src/js/plugins/grideditor.tabs.js +65 -57
- package/src/js/plugins/grideditor.textalign.js +4 -6
- package/src/js/plugins/grideditor.tinymce.js +148 -140
- package/src/js/plugins/grideditor.visibility.js +24 -25
- package/src/js/register.js +18 -0
- package/src/js/text/grideditor.text.js +77 -56
- package/types/grideditor.d.ts +335 -0
- package/dist/jquery.grideditor.bundle.min.js +0 -10
- package/dist/jquery.grideditor.js +0 -4927
- package/dist/jquery.grideditor.min.js +0 -2
- package/dist/jquery.grideditor.min.js.map +0 -1
|
@@ -0,0 +1,500 @@
|
|
|
1
|
+
// src/js/plugins/grideditor.ckeditor.js
|
|
2
|
+
import { GridEditor as GridEditor2 } from "../grideditor.esm.js";
|
|
3
|
+
|
|
4
|
+
// src/js/dom.js
|
|
5
|
+
function all(root, selector) {
|
|
6
|
+
return root ? Array.prototype.slice.call(root.querySelectorAll(selector)) : [];
|
|
7
|
+
}
|
|
8
|
+
function children(node, selector) {
|
|
9
|
+
if (!node) {
|
|
10
|
+
return [];
|
|
11
|
+
}
|
|
12
|
+
return Array.prototype.filter.call(node.children, function(each) {
|
|
13
|
+
return !selector || each.matches(selector);
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
function child(node, selector) {
|
|
17
|
+
return children(node, selector)[0] || null;
|
|
18
|
+
}
|
|
19
|
+
function closest(node, selector, stopAt) {
|
|
20
|
+
var found = node && node.nodeType === 1 ? node.closest(selector) : null;
|
|
21
|
+
if (found && stopAt && found !== stopAt && !stopAt.contains(found)) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
return found;
|
|
25
|
+
}
|
|
26
|
+
function element(tag, attributes, text) {
|
|
27
|
+
var node = document.createElement(tag);
|
|
28
|
+
Object.keys(attributes || {}).forEach(function(name) {
|
|
29
|
+
var value = attributes[name];
|
|
30
|
+
if (value !== null && value !== void 0 && value !== false) {
|
|
31
|
+
node.setAttribute(name, value);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
if (text !== void 0 && text !== null) {
|
|
35
|
+
node.textContent = text;
|
|
36
|
+
}
|
|
37
|
+
return node;
|
|
38
|
+
}
|
|
39
|
+
function setHtml(node, html) {
|
|
40
|
+
node.innerHTML = html === void 0 || html === null ? "" : String(html);
|
|
41
|
+
return node;
|
|
42
|
+
}
|
|
43
|
+
function addClass(node, names) {
|
|
44
|
+
split(names).forEach(function(name) {
|
|
45
|
+
node.classList.add(name);
|
|
46
|
+
});
|
|
47
|
+
return node;
|
|
48
|
+
}
|
|
49
|
+
function removeClass(node, names) {
|
|
50
|
+
split(names).forEach(function(name) {
|
|
51
|
+
node.classList.remove(name);
|
|
52
|
+
});
|
|
53
|
+
return node;
|
|
54
|
+
}
|
|
55
|
+
function hasClass(node, name) {
|
|
56
|
+
return !!node && node.nodeType === 1 && node.classList.contains(name);
|
|
57
|
+
}
|
|
58
|
+
function split(names) {
|
|
59
|
+
return String(names || "").split(/\s+/).filter(Boolean);
|
|
60
|
+
}
|
|
61
|
+
function hide(node) {
|
|
62
|
+
node.style.display = "none";
|
|
63
|
+
return node;
|
|
64
|
+
}
|
|
65
|
+
function visible(node) {
|
|
66
|
+
return !!(node.offsetWidth || node.offsetHeight || node.getClientRects().length);
|
|
67
|
+
}
|
|
68
|
+
function delegate(root, types, selector, handler, options) {
|
|
69
|
+
var listener = function(event) {
|
|
70
|
+
var match = closest(event.target, selector, root);
|
|
71
|
+
if (match && root.contains(match)) {
|
|
72
|
+
return handler.call(match, event);
|
|
73
|
+
}
|
|
74
|
+
return void 0;
|
|
75
|
+
};
|
|
76
|
+
split(types).forEach(function(type) {
|
|
77
|
+
root.addEventListener(type, listener, options);
|
|
78
|
+
});
|
|
79
|
+
return listener;
|
|
80
|
+
}
|
|
81
|
+
var DEFAULT_DURATION = 400;
|
|
82
|
+
function animateAway(node, frames, duration, done) {
|
|
83
|
+
duration = duration === void 0 ? DEFAULT_DURATION : duration;
|
|
84
|
+
var finish = function() {
|
|
85
|
+
hide(node);
|
|
86
|
+
if (done) {
|
|
87
|
+
done();
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
if (!visible(node) || !node.animate || duration <= 0) {
|
|
91
|
+
window.setTimeout(finish, 0);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
var animation = node.animate(frames(getComputedStyle(node)), {
|
|
95
|
+
duration,
|
|
96
|
+
easing: "ease-in-out"
|
|
97
|
+
});
|
|
98
|
+
var called = false;
|
|
99
|
+
var once = function() {
|
|
100
|
+
if (called) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
called = true;
|
|
104
|
+
finish();
|
|
105
|
+
};
|
|
106
|
+
animation.onfinish = once;
|
|
107
|
+
animation.oncancel = once;
|
|
108
|
+
}
|
|
109
|
+
function slideUp(node, duration, done) {
|
|
110
|
+
if (typeof duration === "function") {
|
|
111
|
+
done = duration;
|
|
112
|
+
duration = void 0;
|
|
113
|
+
}
|
|
114
|
+
node.style.overflow = "hidden";
|
|
115
|
+
animateAway(node, function(style) {
|
|
116
|
+
return [
|
|
117
|
+
{
|
|
118
|
+
height: style.height,
|
|
119
|
+
paddingTop: style.paddingTop,
|
|
120
|
+
paddingBottom: style.paddingBottom,
|
|
121
|
+
marginTop: style.marginTop,
|
|
122
|
+
marginBottom: style.marginBottom
|
|
123
|
+
},
|
|
124
|
+
{ height: "0px", paddingTop: "0px", paddingBottom: "0px", marginTop: "0px", marginBottom: "0px" }
|
|
125
|
+
];
|
|
126
|
+
}, duration, function() {
|
|
127
|
+
node.style.removeProperty("overflow");
|
|
128
|
+
if (done) {
|
|
129
|
+
done();
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// src/js/text/grideditor.text.js
|
|
135
|
+
import { GridEditor } from "../grideditor.esm.js";
|
|
136
|
+
if (!GridEditor.features.text) {
|
|
137
|
+
let attributesOf = function(element2) {
|
|
138
|
+
var found = {};
|
|
139
|
+
Array.prototype.slice.call(element2.attributes).forEach(function(attribute) {
|
|
140
|
+
found[attribute.name] = attribute.value;
|
|
141
|
+
});
|
|
142
|
+
return found;
|
|
143
|
+
}, classesIn = function(value) {
|
|
144
|
+
return (value || "").split(/\s+/).filter(function(name) {
|
|
145
|
+
return name !== "" && !EDITOR_CLASS.test(name);
|
|
146
|
+
});
|
|
147
|
+
}, restoreAttributes = function(block, before, ready, open) {
|
|
148
|
+
var result = Object.assign({}, before);
|
|
149
|
+
Object.keys(Object.assign({}, ready, open)).forEach(function(name) {
|
|
150
|
+
if (name === "class" || EDITOR_ATTRIBUTE.test(name) || ready[name] === open[name]) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (open[name] === void 0) {
|
|
154
|
+
delete result[name];
|
|
155
|
+
} else {
|
|
156
|
+
result[name] = open[name];
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
var readyClasses = classesIn(ready["class"]);
|
|
160
|
+
var openClasses = classesIn(open["class"]);
|
|
161
|
+
var classes = classesIn(before["class"]).filter(function(name) {
|
|
162
|
+
return openClasses.indexOf(name) !== -1 || readyClasses.indexOf(name) === -1;
|
|
163
|
+
});
|
|
164
|
+
openClasses.forEach(function(name) {
|
|
165
|
+
if (readyClasses.indexOf(name) === -1 && classes.indexOf(name) === -1) {
|
|
166
|
+
classes.push(name);
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
if (classes.length) {
|
|
170
|
+
result["class"] = classes.join(" ");
|
|
171
|
+
} else {
|
|
172
|
+
delete result["class"];
|
|
173
|
+
}
|
|
174
|
+
Object.keys(attributesOf(block)).forEach(function(name) {
|
|
175
|
+
block.removeAttribute(name);
|
|
176
|
+
});
|
|
177
|
+
Object.keys(result).forEach(function(name) {
|
|
178
|
+
block.setAttribute(name, result[name]);
|
|
179
|
+
});
|
|
180
|
+
}, textFeature = function(ge) {
|
|
181
|
+
var settings = ge.settings;
|
|
182
|
+
var TEXTS = {};
|
|
183
|
+
var warned = {};
|
|
184
|
+
Object.keys(GridEditor.texts).forEach(function(type) {
|
|
185
|
+
TEXTS[type] = GridEditor.texts[type](ge);
|
|
186
|
+
});
|
|
187
|
+
if (!Array.isArray(settings.content_types)) {
|
|
188
|
+
settings.content_types = Object.keys(TEXTS);
|
|
189
|
+
}
|
|
190
|
+
if (!Array.isArray(settings.text_tools)) {
|
|
191
|
+
settings.text_tools = [];
|
|
192
|
+
}
|
|
193
|
+
if (!Array.isArray(settings.text_classes)) {
|
|
194
|
+
settings.text_classes = [];
|
|
195
|
+
}
|
|
196
|
+
function offeredTexts() {
|
|
197
|
+
return settings.content_types.filter(function(type) {
|
|
198
|
+
return !!TEXTS[type];
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
function textLabel(type) {
|
|
202
|
+
var text = TEXTS[type];
|
|
203
|
+
return text && text.labelKey ? ge.t(text.labelKey) : type;
|
|
204
|
+
}
|
|
205
|
+
function makeText(type, content) {
|
|
206
|
+
var text = TEXTS[type];
|
|
207
|
+
var block = element("div", {
|
|
208
|
+
"class": "ge-content ge-content-type-" + type,
|
|
209
|
+
"data-ge-content-type": type
|
|
210
|
+
});
|
|
211
|
+
if (content && content.nodeType) {
|
|
212
|
+
block.appendChild(content);
|
|
213
|
+
} else {
|
|
214
|
+
setHtml(block, content !== void 0 ? content : text && text.initialContent || "");
|
|
215
|
+
}
|
|
216
|
+
return block;
|
|
217
|
+
}
|
|
218
|
+
function apiCreateText(type, options) {
|
|
219
|
+
if (type && typeof type === "object") {
|
|
220
|
+
options = type;
|
|
221
|
+
type = void 0;
|
|
222
|
+
}
|
|
223
|
+
options = options || {};
|
|
224
|
+
type = type || offeredTexts()[0];
|
|
225
|
+
if (!type || !TEXTS[type]) {
|
|
226
|
+
if (!warned["createText:" + type]) {
|
|
227
|
+
warned["createText:" + type] = true;
|
|
228
|
+
ge.warn('createText: no text editor "' + type + '" is loaded; load its plugin and name it in content_types');
|
|
229
|
+
}
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
232
|
+
return ge.place(makeText(type, options.content), "text", options);
|
|
233
|
+
}
|
|
234
|
+
function isOurs(block) {
|
|
235
|
+
return !!TEXTS[block.getAttribute("data-ge-content-type")];
|
|
236
|
+
}
|
|
237
|
+
function startText(block) {
|
|
238
|
+
if (hasClass(block, "ge-rte-active")) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
if (!visible(block)) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
var text = TEXTS[block.getAttribute("data-ge-content-type")];
|
|
245
|
+
if (!text) {
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
if (text.available && !text.available()) {
|
|
249
|
+
if (text.missingKey) {
|
|
250
|
+
console.error(ge.t(text.missingKey));
|
|
251
|
+
}
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
readBefore.set(block, attributesOf(block));
|
|
255
|
+
readReady.delete(block);
|
|
256
|
+
addClass(block, "ge-rte-active");
|
|
257
|
+
text.start([block]);
|
|
258
|
+
}
|
|
259
|
+
function onClick() {
|
|
260
|
+
startText(this);
|
|
261
|
+
}
|
|
262
|
+
function closeText(block) {
|
|
263
|
+
var text = TEXTS[block.getAttribute("data-ge-content-type")];
|
|
264
|
+
var before = readBefore.get(block);
|
|
265
|
+
var open = before ? attributesOf(block) : null;
|
|
266
|
+
if (text) {
|
|
267
|
+
text.stop([block]);
|
|
268
|
+
}
|
|
269
|
+
removeClass(block, "ge-rte-active");
|
|
270
|
+
if (before) {
|
|
271
|
+
restoreAttributes(block, before, readReady.get(block) || before, open);
|
|
272
|
+
readBefore.delete(block);
|
|
273
|
+
readReady.delete(block);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
function createTextControls(textBlock) {
|
|
277
|
+
var block = child(textBlock, ".ge-content");
|
|
278
|
+
var type = block.getAttribute("data-ge-content-type");
|
|
279
|
+
var drawer = element("div", { "class": "ge-tools-drawer ge-text-drawer" });
|
|
280
|
+
textBlock.insertBefore(drawer, textBlock.firstChild);
|
|
281
|
+
ge.createMoveTool(drawer);
|
|
282
|
+
var details = ge.addSettingsTool(drawer, block, settings.text_classes);
|
|
283
|
+
var general = child(details, ".ge-details-general");
|
|
284
|
+
var editor = element("div", { "class": "ge-field ge-text-editor" });
|
|
285
|
+
editor.appendChild(element("span", { "class": "ge-field-label" }, ge.t("panel.editor")));
|
|
286
|
+
editor.appendChild(element("span", { "class": "ge-field-value" }, textLabel(type)));
|
|
287
|
+
general.insertBefore(editor, general.firstChild);
|
|
288
|
+
settings.text_tools.forEach(function(hostTool) {
|
|
289
|
+
ge.createTool(
|
|
290
|
+
drawer,
|
|
291
|
+
hostTool.title || "",
|
|
292
|
+
hostTool.className || "",
|
|
293
|
+
hostTool.iconClass || "bi bi-wrench",
|
|
294
|
+
hostTool.on
|
|
295
|
+
);
|
|
296
|
+
});
|
|
297
|
+
ge.createTool(drawer, ge.t("tool.delete_text"), "ge-delete-text", "bi bi-trash", function() {
|
|
298
|
+
ge.deleteNode("text", block, ge.t("confirm.delete_text"), function(removed) {
|
|
299
|
+
closeText(block);
|
|
300
|
+
slideUp(textBlock, function() {
|
|
301
|
+
textBlock.remove();
|
|
302
|
+
removed();
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
function markTexts() {
|
|
308
|
+
all(ge.canvas, ".ge-text-block").forEach(function(textBlock) {
|
|
309
|
+
if (child(textBlock, ".ge-tools-drawer")) {
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
var block = child(textBlock, ".ge-content");
|
|
313
|
+
if (!block || !isOurs(block)) {
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
createTextControls(textBlock);
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
var texts = offeredTexts();
|
|
320
|
+
var clicks = null;
|
|
321
|
+
return {
|
|
322
|
+
methods: {
|
|
323
|
+
createText: apiCreateText
|
|
324
|
+
},
|
|
325
|
+
/**
|
|
326
|
+
* The types this plugin edits, for the core: every editor loaded
|
|
327
|
+
* is the owner of its texts, and the ones offered are what the
|
|
328
|
+
* host's plain content can be made.
|
|
329
|
+
*/
|
|
330
|
+
textTypes: function() {
|
|
331
|
+
var offered = offeredTexts();
|
|
332
|
+
var others = Object.keys(TEXTS).filter(function(type) {
|
|
333
|
+
return offered.indexOf(type) === -1;
|
|
334
|
+
});
|
|
335
|
+
return offered.concat(others).map(function(type) {
|
|
336
|
+
var text = TEXTS[type];
|
|
337
|
+
return {
|
|
338
|
+
type,
|
|
339
|
+
label: textLabel(type),
|
|
340
|
+
offered: offered.indexOf(type) !== -1,
|
|
341
|
+
available: text.available ? function() {
|
|
342
|
+
return text.available();
|
|
343
|
+
} : null,
|
|
344
|
+
missingKey: text.missingKey,
|
|
345
|
+
edit: function(block) {
|
|
346
|
+
var textBlock = block.parentElement;
|
|
347
|
+
if (hasClass(textBlock, "ge-text-block") && !child(textBlock, ".ge-tools-drawer")) {
|
|
348
|
+
createTextControls(textBlock);
|
|
349
|
+
}
|
|
350
|
+
startText(block);
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
});
|
|
354
|
+
},
|
|
355
|
+
// A text block of each editor offered. Like a container, it goes
|
|
356
|
+
// into a row of its own when clicked, or where it is dropped
|
|
357
|
+
toolbar: texts.map(function(type) {
|
|
358
|
+
return {
|
|
359
|
+
label: function() {
|
|
360
|
+
return texts.length > 1 ? ge.t("text.add_type", { editor: textLabel(type) }) : ge.t("text.add");
|
|
361
|
+
},
|
|
362
|
+
iconClass: TEXTS[type].iconClass,
|
|
363
|
+
className: "ge-add-text-button",
|
|
364
|
+
kind: "text",
|
|
365
|
+
inColumn: true,
|
|
366
|
+
create: function() {
|
|
367
|
+
return makeText(type);
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
}),
|
|
371
|
+
onInit: function() {
|
|
372
|
+
markTexts();
|
|
373
|
+
if (clicks) {
|
|
374
|
+
ge.canvas.removeEventListener("click", clicks);
|
|
375
|
+
}
|
|
376
|
+
clicks = delegate(ge.canvas, "click", ".ge-content", onClick);
|
|
377
|
+
},
|
|
378
|
+
// While the drawers and the text blocks are still there, as the
|
|
379
|
+
// editors left them
|
|
380
|
+
onBeforeDeinit: function() {
|
|
381
|
+
all(ge.canvas, ".ge-content").forEach(function(block) {
|
|
382
|
+
if (isOurs(block)) {
|
|
383
|
+
closeText(block);
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
},
|
|
387
|
+
onDeinit: function() {
|
|
388
|
+
if (clicks) {
|
|
389
|
+
ge.canvas.removeEventListener("click", clicks);
|
|
390
|
+
}
|
|
391
|
+
clicks = null;
|
|
392
|
+
},
|
|
393
|
+
// The first time only: an undo says ready again, and by then the
|
|
394
|
+
// host may have changed the content area itself
|
|
395
|
+
onContentReady: function(area) {
|
|
396
|
+
if (readBefore.has(area) && !readReady.has(area)) {
|
|
397
|
+
readReady.set(area, attributesOf(area));
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
};
|
|
402
|
+
Object.assign(GridEditor.locales.en, {
|
|
403
|
+
"text.add": "Text",
|
|
404
|
+
"text.add_type": "Text ({editor})",
|
|
405
|
+
"panel.editor": "Editor",
|
|
406
|
+
"panel.kind_text": "Text"
|
|
407
|
+
});
|
|
408
|
+
readBefore = /* @__PURE__ */ new WeakMap();
|
|
409
|
+
readReady = /* @__PURE__ */ new WeakMap();
|
|
410
|
+
EDITOR_CLASS = /^(mce-|cke|note-)|^(active|ge-rte-active)$/;
|
|
411
|
+
EDITOR_ATTRIBUTE = /^(data-mce-|contenteditable$|spellcheck$)/;
|
|
412
|
+
textFeature.always = true;
|
|
413
|
+
GridEditor.features.text = textFeature;
|
|
414
|
+
}
|
|
415
|
+
var readBefore;
|
|
416
|
+
var readReady;
|
|
417
|
+
var EDITOR_CLASS;
|
|
418
|
+
var EDITOR_ATTRIBUTE;
|
|
419
|
+
|
|
420
|
+
// src/js/plugins/grideditor.ckeditor.js
|
|
421
|
+
Object.assign(GridEditor2.locales.en, {
|
|
422
|
+
"text.ckeditor": "CKEditor"
|
|
423
|
+
});
|
|
424
|
+
var INITIAL_CONTENT = "<p>Lorem initius... </p>";
|
|
425
|
+
var instances = /* @__PURE__ */ new WeakMap();
|
|
426
|
+
GridEditor2.texts.ckeditor = function(ge) {
|
|
427
|
+
function instanceOf(contentArea) {
|
|
428
|
+
var kept = instances.get(contentArea);
|
|
429
|
+
if (kept) {
|
|
430
|
+
return kept;
|
|
431
|
+
}
|
|
432
|
+
var found = null;
|
|
433
|
+
Object.keys(window.CKEDITOR.instances).forEach(function(name) {
|
|
434
|
+
var instance = window.CKEDITOR.instances[name];
|
|
435
|
+
if (instance.element && instance.element.$ === contentArea) {
|
|
436
|
+
found = instance;
|
|
437
|
+
}
|
|
438
|
+
});
|
|
439
|
+
return found;
|
|
440
|
+
}
|
|
441
|
+
return {
|
|
442
|
+
labelKey: "text.ckeditor",
|
|
443
|
+
initialContent: INITIAL_CONTENT,
|
|
444
|
+
missingKey: "error.ckeditor_missing",
|
|
445
|
+
available: function() {
|
|
446
|
+
return !!window.CKEDITOR;
|
|
447
|
+
},
|
|
448
|
+
start: function(contentAreas) {
|
|
449
|
+
var settings = ge.settings;
|
|
450
|
+
contentAreas.forEach(function(contentArea) {
|
|
451
|
+
if (hasClass(contentArea, "active")) {
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
if (contentArea.innerHTML == INITIAL_CONTENT) {
|
|
455
|
+
contentArea.innerHTML = " ";
|
|
456
|
+
}
|
|
457
|
+
addClass(contentArea, "active");
|
|
458
|
+
contentArea.setAttribute("contenteditable", "true");
|
|
459
|
+
var configuration = Object.assign(
|
|
460
|
+
{},
|
|
461
|
+
settings.ckeditor && settings.ckeditor.config ? settings.ckeditor.config : {},
|
|
462
|
+
{
|
|
463
|
+
// Focus editor on creation
|
|
464
|
+
on: {
|
|
465
|
+
instanceReady: function(evt) {
|
|
466
|
+
var callback;
|
|
467
|
+
try {
|
|
468
|
+
callback = settings.ckeditor.config.on.instanceReady;
|
|
469
|
+
} catch (err) {
|
|
470
|
+
}
|
|
471
|
+
if (callback) {
|
|
472
|
+
callback.call(this, evt);
|
|
473
|
+
}
|
|
474
|
+
ge.textReady(contentArea);
|
|
475
|
+
instance.focus();
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
);
|
|
480
|
+
var instance = window.CKEDITOR.inline(contentArea, configuration);
|
|
481
|
+
instances.set(contentArea, instance);
|
|
482
|
+
});
|
|
483
|
+
},
|
|
484
|
+
stop: function(contentAreas) {
|
|
485
|
+
contentAreas.filter(function(contentArea) {
|
|
486
|
+
return hasClass(contentArea, "active");
|
|
487
|
+
}).forEach(function(contentArea) {
|
|
488
|
+
var instance = window.CKEDITOR ? instanceOf(contentArea) : null;
|
|
489
|
+
if (instance) {
|
|
490
|
+
instance.destroy();
|
|
491
|
+
}
|
|
492
|
+
instances.delete(contentArea);
|
|
493
|
+
removeClass(contentArea, "active cke_focus");
|
|
494
|
+
["id", "style", "spellcheck", "contenteditable"].forEach(function(name) {
|
|
495
|
+
contentArea.removeAttribute(name);
|
|
496
|
+
});
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
};
|
|
500
|
+
};
|