@enos5/enos-vue-default 1.8.16 → 1.8.17
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/dist/code-Ber986DY.js +87 -0
- package/dist/code-Ber986DY.js.map +1 -0
- package/dist/components/TableList.vue.d.ts +11 -0
- package/dist/components/TableListForm.vue.d.ts +11 -0
- package/dist/components/TableSearch.vue.d.ts +11 -0
- package/dist/default-CIJCtYmL.js +276 -0
- package/dist/default-CIJCtYmL.js.map +1 -0
- package/dist/dom-DNRnXSoJ.js +7016 -0
- package/dist/dom-DNRnXSoJ.js.map +1 -0
- package/dist/image-BBEGvs_X.js +1408 -0
- package/dist/image-BBEGvs_X.js.map +1 -0
- package/dist/index.js +2 -62
- package/dist/index.node.js +2 -62
- package/dist/link-BCKWs7cm.js +1421 -0
- package/dist/link-BCKWs7cm.js.map +1 -0
- package/dist/lists-DO3bIHZE.js +496 -0
- package/dist/lists-DO3bIHZE.js.map +1 -0
- package/dist/plugin-DyVd9Eh7.js +6258 -0
- package/dist/plugin-DyVd9Eh7.js.map +1 -0
- package/dist/silver-DMBzT-QW.js +28483 -0
- package/dist/silver-DMBzT-QW.js.map +1 -0
- package/dist/styles.css +1 -0
- package/dist/table-CAjD5lLC.js +3169 -0
- package/dist/table-CAjD5lLC.js.map +1 -0
- package/dist/tinymce-DQF9Ibks.js +33699 -0
- package/dist/tinymce-DQF9Ibks.js.map +1 -0
- package/package.json +1 -1
- package/dist/_commonjsHelpers-CUmg6egw.js +0 -7
- package/dist/_commonjsHelpers-CUmg6egw.js.map +0 -1
- package/dist/index-1G1T4Qrv.js +0 -31373
- package/dist/index-1G1T4Qrv.js.map +0 -1
- package/dist/index-BBGZQp5w.js +0 -7816
- package/dist/index-BBGZQp5w.js.map +0 -1
- package/dist/index-BR_u7CCm.js +0 -3351
- package/dist/index-BR_u7CCm.js.map +0 -1
- package/dist/index-Bsqrrc8R.js +0 -315
- package/dist/index-Bsqrrc8R.js.map +0 -1
- package/dist/index-CiFpmPug.js +0 -122
- package/dist/index-CiFpmPug.js.map +0 -1
- package/dist/index-CuSlJQwq.js +0 -1581
- package/dist/index-CuSlJQwq.js.map +0 -1
- package/dist/index-D72Leh_x.js +0 -573
- package/dist/index-D72Leh_x.js.map +0 -1
- package/dist/index-ukywSRmc.js +0 -1581
- package/dist/index-ukywSRmc.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/index.node.js.map +0 -1
- package/dist/plugin-D1NKz8QO.js +0 -6559
- package/dist/plugin-D1NKz8QO.js.map +0 -1
- package/dist/tinymce-Dg510HCs.js +0 -35756
- package/dist/tinymce-Dg510HCs.js.map +0 -1
|
@@ -0,0 +1,1408 @@
|
|
|
1
|
+
import { at as __commonJSMin } from "./plugin-DyVd9Eh7.js";
|
|
2
|
+
//#endregion
|
|
3
|
+
//#region ../../node_modules/tinymce/plugins/image/index.js
|
|
4
|
+
(/* @__PURE__ */ __commonJSMin((() => {
|
|
5
|
+
/**
|
|
6
|
+
* TinyMCE version 8.6.0 (2026-06-03)
|
|
7
|
+
*/
|
|
8
|
+
(function() {
|
|
9
|
+
"use strict";
|
|
10
|
+
var global$4 = tinymce.util.Tools.resolve("tinymce.PluginManager");
|
|
11
|
+
const getPrototypeOf = Object.getPrototypeOf;
|
|
12
|
+
const hasProto = (v, constructor, predicate) => {
|
|
13
|
+
if (predicate(v, constructor.prototype)) return true;
|
|
14
|
+
else return v.constructor?.name === constructor.name;
|
|
15
|
+
};
|
|
16
|
+
const typeOf = (x) => {
|
|
17
|
+
const t = typeof x;
|
|
18
|
+
if (x === null) return "null";
|
|
19
|
+
else if (t === "object" && Array.isArray(x)) return "array";
|
|
20
|
+
else if (t === "object" && hasProto(x, String, (o, proto) => proto.isPrototypeOf(o))) return "string";
|
|
21
|
+
else return t;
|
|
22
|
+
};
|
|
23
|
+
const isType = (type) => (value) => typeOf(value) === type;
|
|
24
|
+
const isSimpleType = (type) => (value) => typeof value === type;
|
|
25
|
+
const eq = (t) => (a) => t === a;
|
|
26
|
+
const is = (value, constructor) => isObject(value) && hasProto(value, constructor, (o, proto) => getPrototypeOf(o) === proto);
|
|
27
|
+
const isString = isType("string");
|
|
28
|
+
const isObject = isType("object");
|
|
29
|
+
const isPlainObject = (value) => is(value, Object);
|
|
30
|
+
const isArray = isType("array");
|
|
31
|
+
const isNull = eq(null);
|
|
32
|
+
const isBoolean = isSimpleType("boolean");
|
|
33
|
+
const isNullable = (a) => a === null || a === void 0;
|
|
34
|
+
const isNonNullable = (a) => !isNullable(a);
|
|
35
|
+
const isFunction = isSimpleType("function");
|
|
36
|
+
const isNumber = isSimpleType("number");
|
|
37
|
+
const isArrayOf = (value, pred) => {
|
|
38
|
+
if (isArray(value)) {
|
|
39
|
+
for (let i = 0, len = value.length; i < len; ++i) if (!pred(value[i])) return false;
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
return false;
|
|
43
|
+
};
|
|
44
|
+
const noop = () => {};
|
|
45
|
+
/**
|
|
46
|
+
* The `Optional` type represents a value (of any type) that potentially does
|
|
47
|
+
* not exist. Any `Optional<T>` can either be a `Some<T>` (in which case the
|
|
48
|
+
* value does exist) or a `None` (in which case the value does not exist). This
|
|
49
|
+
* module defines a whole lot of FP-inspired utility functions for dealing with
|
|
50
|
+
* `Optional` objects.
|
|
51
|
+
*
|
|
52
|
+
* Comparison with null or undefined:
|
|
53
|
+
* - We don't get fancy null coalescing operators with `Optional`
|
|
54
|
+
* - We do get fancy helper functions with `Optional`
|
|
55
|
+
* - `Optional` support nesting, and allow for the type to still be nullable (or
|
|
56
|
+
* another `Optional`)
|
|
57
|
+
* - There is no option to turn off strict-optional-checks like there is for
|
|
58
|
+
* strict-null-checks
|
|
59
|
+
*/
|
|
60
|
+
class Optional {
|
|
61
|
+
tag;
|
|
62
|
+
value;
|
|
63
|
+
static singletonNone = new Optional(false);
|
|
64
|
+
constructor(tag, value) {
|
|
65
|
+
this.tag = tag;
|
|
66
|
+
this.value = value;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Creates a new `Optional<T>` that **does** contain a value.
|
|
70
|
+
*/
|
|
71
|
+
static some(value) {
|
|
72
|
+
return new Optional(true, value);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Create a new `Optional<T>` that **does not** contain a value. `T` can be
|
|
76
|
+
* any type because we don't actually have a `T`.
|
|
77
|
+
*/
|
|
78
|
+
static none() {
|
|
79
|
+
return Optional.singletonNone;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Perform a transform on an `Optional` type. Regardless of whether this
|
|
83
|
+
* `Optional` contains a value or not, `fold` will return a value of type `U`.
|
|
84
|
+
* If this `Optional` does not contain a value, the `U` will be created by
|
|
85
|
+
* calling `onNone`. If this `Optional` does contain a value, the `U` will be
|
|
86
|
+
* created by calling `onSome`.
|
|
87
|
+
*
|
|
88
|
+
* For the FP enthusiasts in the room, this function:
|
|
89
|
+
* 1. Could be used to implement all of the functions below
|
|
90
|
+
* 2. Forms a catamorphism
|
|
91
|
+
*/
|
|
92
|
+
fold(onNone, onSome) {
|
|
93
|
+
if (this.tag) return onSome(this.value);
|
|
94
|
+
else return onNone();
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Determine if this `Optional` object contains a value.
|
|
98
|
+
*/
|
|
99
|
+
isSome() {
|
|
100
|
+
return this.tag;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Determine if this `Optional` object **does not** contain a value.
|
|
104
|
+
*/
|
|
105
|
+
isNone() {
|
|
106
|
+
return !this.tag;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Perform a transform on an `Optional` object, **if** there is a value. If
|
|
110
|
+
* you provide a function to turn a T into a U, this is the function you use
|
|
111
|
+
* to turn an `Optional<T>` into an `Optional<U>`. If this **does** contain
|
|
112
|
+
* a value then the output will also contain a value (that value being the
|
|
113
|
+
* output of `mapper(this.value)`), and if this **does not** contain a value
|
|
114
|
+
* then neither will the output.
|
|
115
|
+
*/
|
|
116
|
+
map(mapper) {
|
|
117
|
+
if (this.tag) return Optional.some(mapper(this.value));
|
|
118
|
+
else return Optional.none();
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Perform a transform on an `Optional` object, **if** there is a value.
|
|
122
|
+
* Unlike `map`, here the transform itself also returns an `Optional`.
|
|
123
|
+
*/
|
|
124
|
+
bind(binder) {
|
|
125
|
+
if (this.tag) return binder(this.value);
|
|
126
|
+
else return Optional.none();
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* For a given predicate, this function finds out if there **exists** a value
|
|
130
|
+
* inside this `Optional` object that meets the predicate. In practice, this
|
|
131
|
+
* means that for `Optional`s that do not contain a value it returns false (as
|
|
132
|
+
* no predicate-meeting value exists).
|
|
133
|
+
*/
|
|
134
|
+
exists(predicate) {
|
|
135
|
+
return this.tag && predicate(this.value);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* For a given predicate, this function finds out if **all** the values inside
|
|
139
|
+
* this `Optional` object meet the predicate. In practice, this means that
|
|
140
|
+
* for `Optional`s that do not contain a value it returns true (as all 0
|
|
141
|
+
* objects do meet the predicate).
|
|
142
|
+
*/
|
|
143
|
+
forall(predicate) {
|
|
144
|
+
return !this.tag || predicate(this.value);
|
|
145
|
+
}
|
|
146
|
+
filter(predicate) {
|
|
147
|
+
if (!this.tag || predicate(this.value)) return this;
|
|
148
|
+
else return Optional.none();
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Get the value out of the inside of the `Optional` object, using a default
|
|
152
|
+
* `replacement` value if the provided `Optional` object does not contain a
|
|
153
|
+
* value.
|
|
154
|
+
*/
|
|
155
|
+
getOr(replacement) {
|
|
156
|
+
return this.tag ? this.value : replacement;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Get the value out of the inside of the `Optional` object, using a default
|
|
160
|
+
* `replacement` value if the provided `Optional` object does not contain a
|
|
161
|
+
* value. Unlike `getOr`, in this method the `replacement` object is also
|
|
162
|
+
* `Optional` - meaning that this method will always return an `Optional`.
|
|
163
|
+
*/
|
|
164
|
+
or(replacement) {
|
|
165
|
+
return this.tag ? this : replacement;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Get the value out of the inside of the `Optional` object, using a default
|
|
169
|
+
* `replacement` value if the provided `Optional` object does not contain a
|
|
170
|
+
* value. Unlike `getOr`, in this method the `replacement` value is
|
|
171
|
+
* "thunked" - that is to say that you don't pass a value to `getOrThunk`, you
|
|
172
|
+
* pass a function which (if called) will **return** the `value` you want to
|
|
173
|
+
* use.
|
|
174
|
+
*/
|
|
175
|
+
getOrThunk(thunk) {
|
|
176
|
+
return this.tag ? this.value : thunk();
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Get the value out of the inside of the `Optional` object, using a default
|
|
180
|
+
* `replacement` value if the provided Optional object does not contain a
|
|
181
|
+
* value.
|
|
182
|
+
*
|
|
183
|
+
* Unlike `or`, in this method the `replacement` value is "thunked" - that is
|
|
184
|
+
* to say that you don't pass a value to `orThunk`, you pass a function which
|
|
185
|
+
* (if called) will **return** the `value` you want to use.
|
|
186
|
+
*
|
|
187
|
+
* Unlike `getOrThunk`, in this method the `replacement` value is also
|
|
188
|
+
* `Optional`, meaning that this method will always return an `Optional`.
|
|
189
|
+
*/
|
|
190
|
+
orThunk(thunk) {
|
|
191
|
+
return this.tag ? this : thunk();
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Get the value out of the inside of the `Optional` object, throwing an
|
|
195
|
+
* exception if the provided `Optional` object does not contain a value.
|
|
196
|
+
*
|
|
197
|
+
* WARNING:
|
|
198
|
+
* You should only be using this function if you know that the `Optional`
|
|
199
|
+
* object **is not** empty (otherwise you're throwing exceptions in production
|
|
200
|
+
* code, which is bad).
|
|
201
|
+
*
|
|
202
|
+
* In tests this is more acceptable.
|
|
203
|
+
*
|
|
204
|
+
* Prefer other methods to this, such as `.each`.
|
|
205
|
+
*/
|
|
206
|
+
getOrDie(message) {
|
|
207
|
+
if (!this.tag) throw new Error(message ?? "Called getOrDie on None");
|
|
208
|
+
else return this.value;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Creates an `Optional` value from a nullable (or undefined-able) input.
|
|
212
|
+
* Null, or undefined, is converted to `None`, and anything else is converted
|
|
213
|
+
* to `Some`.
|
|
214
|
+
*/
|
|
215
|
+
static from(value) {
|
|
216
|
+
return isNonNullable(value) ? Optional.some(value) : Optional.none();
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Converts an `Optional` to a nullable type, by getting the value if it
|
|
220
|
+
* exists, or returning `null` if it does not.
|
|
221
|
+
*/
|
|
222
|
+
getOrNull() {
|
|
223
|
+
return this.tag ? this.value : null;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Converts an `Optional` to an undefined-able type, by getting the value if
|
|
227
|
+
* it exists, or returning `undefined` if it does not.
|
|
228
|
+
*/
|
|
229
|
+
getOrUndefined() {
|
|
230
|
+
return this.value;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* If the `Optional` contains a value, perform an action on that value.
|
|
234
|
+
* Unlike the rest of the methods on this type, `.each` has side-effects. If
|
|
235
|
+
* you want to transform an `Optional<T>` **into** something, then this is not
|
|
236
|
+
* the method for you. If you want to use an `Optional<T>` to **do**
|
|
237
|
+
* something, then this is the method for you - provided you're okay with not
|
|
238
|
+
* doing anything in the case where the `Optional` doesn't have a value inside
|
|
239
|
+
* it. If you're not sure whether your use-case fits into transforming
|
|
240
|
+
* **into** something or **doing** something, check whether it has a return
|
|
241
|
+
* value. If it does, you should be performing a transform.
|
|
242
|
+
*/
|
|
243
|
+
each(worker) {
|
|
244
|
+
if (this.tag) worker(this.value);
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Turn the `Optional` object into an array that contains all of the values
|
|
248
|
+
* stored inside the `Optional`. In practice, this means the output will have
|
|
249
|
+
* either 0 or 1 elements.
|
|
250
|
+
*/
|
|
251
|
+
toArray() {
|
|
252
|
+
return this.tag ? [this.value] : [];
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Turn the `Optional` object into a string for debugging or printing. Not
|
|
256
|
+
* recommended for production code, but good for debugging. Also note that
|
|
257
|
+
* these days an `Optional` object can be logged to the console directly, and
|
|
258
|
+
* its inner value (if it exists) will be visible.
|
|
259
|
+
*/
|
|
260
|
+
toString() {
|
|
261
|
+
return this.tag ? `some(${this.value})` : "none()";
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
Array.prototype.slice;
|
|
265
|
+
const nativePush = Array.prototype.push;
|
|
266
|
+
const flatten = (xs) => {
|
|
267
|
+
const r = [];
|
|
268
|
+
for (let i = 0, len = xs.length; i < len; ++i) {
|
|
269
|
+
if (!isArray(xs[i])) throw new Error("Arr.flatten item " + i + " was not an array, input: " + xs);
|
|
270
|
+
nativePush.apply(r, xs[i]);
|
|
271
|
+
}
|
|
272
|
+
return r;
|
|
273
|
+
};
|
|
274
|
+
const get = (xs, i) => i >= 0 && i < xs.length ? Optional.some(xs[i]) : Optional.none();
|
|
275
|
+
const head = (xs) => get(xs, 0);
|
|
276
|
+
isFunction(Array.from) && Array.from;
|
|
277
|
+
const findMap = (arr, f) => {
|
|
278
|
+
for (let i = 0; i < arr.length; i++) {
|
|
279
|
+
const r = f(arr[i], i);
|
|
280
|
+
if (r.isSome()) return r;
|
|
281
|
+
}
|
|
282
|
+
return Optional.none();
|
|
283
|
+
};
|
|
284
|
+
const keys = Object.keys;
|
|
285
|
+
const hasOwnProperty = Object.hasOwnProperty;
|
|
286
|
+
const each = (obj, f) => {
|
|
287
|
+
const props = keys(obj);
|
|
288
|
+
for (let k = 0, len = props.length; k < len; k++) {
|
|
289
|
+
const i = props[k];
|
|
290
|
+
const x = obj[i];
|
|
291
|
+
f(x, i);
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
const objAcc = (r) => (x, i) => {
|
|
295
|
+
r[i] = x;
|
|
296
|
+
};
|
|
297
|
+
const internalFilter = (obj, pred, onTrue, onFalse) => {
|
|
298
|
+
each(obj, (x, i) => {
|
|
299
|
+
(pred(x, i) ? onTrue : onFalse)(x, i);
|
|
300
|
+
});
|
|
301
|
+
};
|
|
302
|
+
const filter = (obj, pred) => {
|
|
303
|
+
const t = {};
|
|
304
|
+
internalFilter(obj, pred, objAcc(t), noop);
|
|
305
|
+
return t;
|
|
306
|
+
};
|
|
307
|
+
const has = (obj, key) => hasOwnProperty.call(obj, key);
|
|
308
|
+
const hasNonNullableKey = (obj, key) => has(obj, key) && obj[key] !== void 0 && obj[key] !== null;
|
|
309
|
+
const deep = (old, nu) => {
|
|
310
|
+
return isPlainObject(old) && isPlainObject(nu) ? deepMerge(old, nu) : nu;
|
|
311
|
+
};
|
|
312
|
+
const baseMerge = (merger) => {
|
|
313
|
+
return (...objects) => {
|
|
314
|
+
if (objects.length === 0) throw new Error(`Can't merge zero objects`);
|
|
315
|
+
const ret = {};
|
|
316
|
+
for (let j = 0; j < objects.length; j++) {
|
|
317
|
+
const curObject = objects[j];
|
|
318
|
+
for (const key in curObject) if (has(curObject, key)) ret[key] = merger(ret[key], curObject[key]);
|
|
319
|
+
}
|
|
320
|
+
return ret;
|
|
321
|
+
};
|
|
322
|
+
};
|
|
323
|
+
const deepMerge = baseMerge(deep);
|
|
324
|
+
const isNotEmpty = (s) => s.length > 0;
|
|
325
|
+
const fromHtml = (html, scope) => {
|
|
326
|
+
const div = (scope || document).createElement("div");
|
|
327
|
+
div.innerHTML = html;
|
|
328
|
+
if (!div.hasChildNodes() || div.childNodes.length > 1) {
|
|
329
|
+
const message = "HTML does not have a single root node";
|
|
330
|
+
console.error(message, html);
|
|
331
|
+
throw new Error(message);
|
|
332
|
+
}
|
|
333
|
+
return fromDom(div.childNodes[0]);
|
|
334
|
+
};
|
|
335
|
+
const fromTag = (tag, scope) => {
|
|
336
|
+
return fromDom((scope || document).createElement(tag));
|
|
337
|
+
};
|
|
338
|
+
const fromText = (text, scope) => {
|
|
339
|
+
return fromDom((scope || document).createTextNode(text));
|
|
340
|
+
};
|
|
341
|
+
const fromDom = (node) => {
|
|
342
|
+
if (node === null || node === void 0) throw new Error("Node cannot be null or undefined");
|
|
343
|
+
return { dom: node };
|
|
344
|
+
};
|
|
345
|
+
const fromPoint = (docElm, x, y) => Optional.from(docElm.dom.elementFromPoint(x, y)).map(fromDom);
|
|
346
|
+
const SugarElement = {
|
|
347
|
+
fromHtml,
|
|
348
|
+
fromTag,
|
|
349
|
+
fromText,
|
|
350
|
+
fromDom,
|
|
351
|
+
fromPoint
|
|
352
|
+
};
|
|
353
|
+
const rawSet = (dom, key, value) => {
|
|
354
|
+
if (isString(value) || isBoolean(value) || isNumber(value)) dom.setAttribute(key, value + "");
|
|
355
|
+
else {
|
|
356
|
+
console.error("Invalid call to Attribute.set. Key ", key, ":: Value ", value, ":: Element ", dom);
|
|
357
|
+
throw new Error("Attribute value was not simple");
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
const set = (element, key, value) => {
|
|
361
|
+
rawSet(element.dom, key, value);
|
|
362
|
+
};
|
|
363
|
+
const remove = (element, key) => {
|
|
364
|
+
element.dom.removeAttribute(key);
|
|
365
|
+
};
|
|
366
|
+
var global$3 = tinymce.util.Tools.resolve("tinymce.dom.DOMUtils");
|
|
367
|
+
var global$2 = tinymce.util.Tools.resolve("tinymce.util.URI");
|
|
368
|
+
const option = (name) => (editor) => editor.options.get(name);
|
|
369
|
+
const register$2 = (editor) => {
|
|
370
|
+
const registerOption = editor.options.register;
|
|
371
|
+
registerOption("image_dimensions", {
|
|
372
|
+
processor: "boolean",
|
|
373
|
+
default: true
|
|
374
|
+
});
|
|
375
|
+
registerOption("image_advtab", {
|
|
376
|
+
processor: "boolean",
|
|
377
|
+
default: false
|
|
378
|
+
});
|
|
379
|
+
registerOption("image_uploadtab", {
|
|
380
|
+
processor: "boolean",
|
|
381
|
+
default: true
|
|
382
|
+
});
|
|
383
|
+
registerOption("image_prepend_url", {
|
|
384
|
+
processor: "string",
|
|
385
|
+
default: ""
|
|
386
|
+
});
|
|
387
|
+
registerOption("image_class_list", { processor: "object[]" });
|
|
388
|
+
registerOption("image_description", {
|
|
389
|
+
processor: "boolean",
|
|
390
|
+
default: true
|
|
391
|
+
});
|
|
392
|
+
registerOption("image_title", {
|
|
393
|
+
processor: "boolean",
|
|
394
|
+
default: false
|
|
395
|
+
});
|
|
396
|
+
registerOption("image_caption", {
|
|
397
|
+
processor: "boolean",
|
|
398
|
+
default: false
|
|
399
|
+
});
|
|
400
|
+
registerOption("image_list", {
|
|
401
|
+
processor: (value) => {
|
|
402
|
+
const valid = value === false || isString(value) || isArrayOf(value, isObject) || isFunction(value);
|
|
403
|
+
return valid ? {
|
|
404
|
+
value,
|
|
405
|
+
valid
|
|
406
|
+
} : {
|
|
407
|
+
valid: false,
|
|
408
|
+
message: "Must be false, a string, an array or a function."
|
|
409
|
+
};
|
|
410
|
+
},
|
|
411
|
+
default: false
|
|
412
|
+
});
|
|
413
|
+
};
|
|
414
|
+
const hasDimensions = option("image_dimensions");
|
|
415
|
+
const hasAdvTab = option("image_advtab");
|
|
416
|
+
const hasUploadTab = option("image_uploadtab");
|
|
417
|
+
const getPrependUrl = option("image_prepend_url");
|
|
418
|
+
const getClassList = option("image_class_list");
|
|
419
|
+
const hasDescription = option("image_description");
|
|
420
|
+
const hasImageTitle = option("image_title");
|
|
421
|
+
const hasImageCaption = option("image_caption");
|
|
422
|
+
const getImageList = option("image_list");
|
|
423
|
+
const showAccessibilityOptions = option("a11y_advanced_options");
|
|
424
|
+
const isAutomaticUploadsEnabled = option("automatic_uploads");
|
|
425
|
+
const hasUploadUrl = (editor) => isNotEmpty(editor.options.get("images_upload_url"));
|
|
426
|
+
const hasUploadHandler = (editor) => isNonNullable(editor.options.get("images_upload_handler"));
|
|
427
|
+
const parseIntAndGetMax = (val1, val2) => Math.max(parseInt(val1, 10), parseInt(val2, 10));
|
|
428
|
+
const getImageSize = (url) => new Promise((callback) => {
|
|
429
|
+
const img = document.createElement("img");
|
|
430
|
+
const done = (dimensions) => {
|
|
431
|
+
if (img.parentNode) img.parentNode.removeChild(img);
|
|
432
|
+
callback(dimensions);
|
|
433
|
+
};
|
|
434
|
+
img.addEventListener("load", () => {
|
|
435
|
+
const dimensions = {
|
|
436
|
+
width: parseIntAndGetMax(img.width, img.clientWidth),
|
|
437
|
+
height: parseIntAndGetMax(img.height, img.clientHeight)
|
|
438
|
+
};
|
|
439
|
+
done(Promise.resolve(dimensions));
|
|
440
|
+
});
|
|
441
|
+
img.addEventListener("error", () => {
|
|
442
|
+
done(Promise.reject(`Failed to get image dimensions for: ${url}`));
|
|
443
|
+
});
|
|
444
|
+
const style = img.style;
|
|
445
|
+
style.visibility = "hidden";
|
|
446
|
+
style.position = "fixed";
|
|
447
|
+
style.bottom = style.left = "0px";
|
|
448
|
+
style.width = style.height = "auto";
|
|
449
|
+
document.body.appendChild(img);
|
|
450
|
+
img.src = url;
|
|
451
|
+
});
|
|
452
|
+
const removePixelSuffix = (value) => {
|
|
453
|
+
if (value) value = value.replace(/px$/, "");
|
|
454
|
+
return value;
|
|
455
|
+
};
|
|
456
|
+
const addPixelSuffix = (value) => {
|
|
457
|
+
if (value.length > 0 && /^[0-9]+$/.test(value)) value += "px";
|
|
458
|
+
return value;
|
|
459
|
+
};
|
|
460
|
+
const mergeMargins = (css) => {
|
|
461
|
+
if (css.margin) {
|
|
462
|
+
const splitMargin = String(css.margin).split(" ");
|
|
463
|
+
switch (splitMargin.length) {
|
|
464
|
+
case 1:
|
|
465
|
+
css["margin-top"] = css["margin-top"] || splitMargin[0];
|
|
466
|
+
css["margin-right"] = css["margin-right"] || splitMargin[0];
|
|
467
|
+
css["margin-bottom"] = css["margin-bottom"] || splitMargin[0];
|
|
468
|
+
css["margin-left"] = css["margin-left"] || splitMargin[0];
|
|
469
|
+
break;
|
|
470
|
+
case 2:
|
|
471
|
+
css["margin-top"] = css["margin-top"] || splitMargin[0];
|
|
472
|
+
css["margin-right"] = css["margin-right"] || splitMargin[1];
|
|
473
|
+
css["margin-bottom"] = css["margin-bottom"] || splitMargin[0];
|
|
474
|
+
css["margin-left"] = css["margin-left"] || splitMargin[1];
|
|
475
|
+
break;
|
|
476
|
+
case 3:
|
|
477
|
+
css["margin-top"] = css["margin-top"] || splitMargin[0];
|
|
478
|
+
css["margin-right"] = css["margin-right"] || splitMargin[1];
|
|
479
|
+
css["margin-bottom"] = css["margin-bottom"] || splitMargin[2];
|
|
480
|
+
css["margin-left"] = css["margin-left"] || splitMargin[1];
|
|
481
|
+
break;
|
|
482
|
+
case 4:
|
|
483
|
+
css["margin-top"] = css["margin-top"] || splitMargin[0];
|
|
484
|
+
css["margin-right"] = css["margin-right"] || splitMargin[1];
|
|
485
|
+
css["margin-bottom"] = css["margin-bottom"] || splitMargin[2];
|
|
486
|
+
css["margin-left"] = css["margin-left"] || splitMargin[3];
|
|
487
|
+
}
|
|
488
|
+
delete css.margin;
|
|
489
|
+
}
|
|
490
|
+
return css;
|
|
491
|
+
};
|
|
492
|
+
const createImageList = (editor, callback) => {
|
|
493
|
+
const imageList = getImageList(editor);
|
|
494
|
+
if (isString(imageList)) fetch(imageList).then((res) => {
|
|
495
|
+
if (res.ok) res.json().then(callback);
|
|
496
|
+
});
|
|
497
|
+
else if (isFunction(imageList)) imageList(callback);
|
|
498
|
+
else callback(imageList);
|
|
499
|
+
};
|
|
500
|
+
const waitLoadImage = (editor, data, imgElm) => {
|
|
501
|
+
const selectImage = () => {
|
|
502
|
+
imgElm.onload = imgElm.onerror = null;
|
|
503
|
+
if (editor.selection) {
|
|
504
|
+
editor.selection.select(imgElm);
|
|
505
|
+
editor.nodeChanged();
|
|
506
|
+
}
|
|
507
|
+
};
|
|
508
|
+
imgElm.onload = () => {
|
|
509
|
+
if (!data.width && !data.height && hasDimensions(editor)) editor.dom.setAttribs(imgElm, {
|
|
510
|
+
width: String(imgElm.clientWidth),
|
|
511
|
+
height: String(imgElm.clientHeight)
|
|
512
|
+
});
|
|
513
|
+
selectImage();
|
|
514
|
+
};
|
|
515
|
+
imgElm.onerror = selectImage;
|
|
516
|
+
};
|
|
517
|
+
const blobToDataUri = (blob) => new Promise((resolve, reject) => {
|
|
518
|
+
const reader = new FileReader();
|
|
519
|
+
reader.onload = () => {
|
|
520
|
+
resolve(reader.result);
|
|
521
|
+
};
|
|
522
|
+
reader.onerror = () => {
|
|
523
|
+
reject(reader.error?.message);
|
|
524
|
+
};
|
|
525
|
+
reader.readAsDataURL(blob);
|
|
526
|
+
});
|
|
527
|
+
const isPlaceholderImage = (imgElm) => imgElm.nodeName === "IMG" && (imgElm.hasAttribute("data-mce-object") || imgElm.hasAttribute("data-mce-placeholder"));
|
|
528
|
+
const isSafeImageUrl = (editor, src) => {
|
|
529
|
+
const getOption = editor.options.get;
|
|
530
|
+
return global$2.isDomSafe(src, "img", {
|
|
531
|
+
allow_html_data_urls: getOption("allow_html_data_urls"),
|
|
532
|
+
allow_script_urls: getOption("allow_script_urls"),
|
|
533
|
+
allow_svg_data_urls: getOption("allow_svg_data_urls")
|
|
534
|
+
});
|
|
535
|
+
};
|
|
536
|
+
const DOM = global$3.DOM;
|
|
537
|
+
const getHspace = (image) => {
|
|
538
|
+
if (image.style.marginLeft && image.style.marginRight && image.style.marginLeft === image.style.marginRight) return removePixelSuffix(image.style.marginLeft);
|
|
539
|
+
else return "";
|
|
540
|
+
};
|
|
541
|
+
const getVspace = (image) => {
|
|
542
|
+
if (image.style.marginTop && image.style.marginBottom && image.style.marginTop === image.style.marginBottom) return removePixelSuffix(image.style.marginTop);
|
|
543
|
+
else return "";
|
|
544
|
+
};
|
|
545
|
+
const getBorder = (image) => {
|
|
546
|
+
if (image.style.borderWidth) return removePixelSuffix(image.style.borderWidth);
|
|
547
|
+
else return "";
|
|
548
|
+
};
|
|
549
|
+
const getAttrib = (image, name) => {
|
|
550
|
+
if (image.hasAttribute(name)) return image.getAttribute(name) ?? "";
|
|
551
|
+
else return "";
|
|
552
|
+
};
|
|
553
|
+
const hasCaption = (image) => image.parentNode !== null && image.parentNode.nodeName === "FIGURE";
|
|
554
|
+
const updateAttrib = (image, name, value) => {
|
|
555
|
+
if (value === "" || value === null) image.removeAttribute(name);
|
|
556
|
+
else image.setAttribute(name, value);
|
|
557
|
+
};
|
|
558
|
+
const wrapInFigure = (image) => {
|
|
559
|
+
const figureElm = DOM.create("figure", { class: "image" });
|
|
560
|
+
DOM.insertAfter(figureElm, image);
|
|
561
|
+
figureElm.appendChild(image);
|
|
562
|
+
figureElm.appendChild(DOM.create("figcaption", { contentEditable: "true" }, "Caption"));
|
|
563
|
+
figureElm.contentEditable = "false";
|
|
564
|
+
};
|
|
565
|
+
const removeFigure = (image) => {
|
|
566
|
+
const figureElm = image.parentNode;
|
|
567
|
+
if (isNonNullable(figureElm)) {
|
|
568
|
+
DOM.insertAfter(image, figureElm);
|
|
569
|
+
DOM.remove(figureElm);
|
|
570
|
+
}
|
|
571
|
+
};
|
|
572
|
+
const toggleCaption = (image) => {
|
|
573
|
+
if (hasCaption(image)) removeFigure(image);
|
|
574
|
+
else wrapInFigure(image);
|
|
575
|
+
};
|
|
576
|
+
const normalizeStyle = (image, normalizeCss) => {
|
|
577
|
+
const attrValue = image.getAttribute("style");
|
|
578
|
+
const value = normalizeCss(attrValue !== null ? attrValue : "");
|
|
579
|
+
if (value.length > 0) {
|
|
580
|
+
image.setAttribute("style", value);
|
|
581
|
+
image.setAttribute("data-mce-style", value);
|
|
582
|
+
} else image.removeAttribute("style");
|
|
583
|
+
};
|
|
584
|
+
const setSize = (name, normalizeCss) => (image, name, value) => {
|
|
585
|
+
const styles = image.style;
|
|
586
|
+
if (styles[name]) {
|
|
587
|
+
styles[name] = addPixelSuffix(value);
|
|
588
|
+
normalizeStyle(image, normalizeCss);
|
|
589
|
+
} else updateAttrib(image, name, value);
|
|
590
|
+
};
|
|
591
|
+
const getSize = (image, name) => {
|
|
592
|
+
if (image.style[name]) return removePixelSuffix(image.style[name]);
|
|
593
|
+
else return getAttrib(image, name);
|
|
594
|
+
};
|
|
595
|
+
const setHspace = (image, value) => {
|
|
596
|
+
const pxValue = addPixelSuffix(value);
|
|
597
|
+
image.style.marginLeft = pxValue;
|
|
598
|
+
image.style.marginRight = pxValue;
|
|
599
|
+
};
|
|
600
|
+
const setVspace = (image, value) => {
|
|
601
|
+
const pxValue = addPixelSuffix(value);
|
|
602
|
+
image.style.marginTop = pxValue;
|
|
603
|
+
image.style.marginBottom = pxValue;
|
|
604
|
+
};
|
|
605
|
+
const setBorder = (image, value) => {
|
|
606
|
+
const pxValue = addPixelSuffix(value);
|
|
607
|
+
image.style.borderWidth = pxValue;
|
|
608
|
+
};
|
|
609
|
+
const setBorderStyle = (image, value) => {
|
|
610
|
+
image.style.borderStyle = value;
|
|
611
|
+
};
|
|
612
|
+
const getBorderStyle = (image) => image.style.borderStyle ?? "";
|
|
613
|
+
const isFigure = (elm) => isNonNullable(elm) && elm.nodeName === "FIGURE";
|
|
614
|
+
const isImage = (elm) => elm.nodeName === "IMG";
|
|
615
|
+
const getIsDecorative = (image) => {
|
|
616
|
+
const alt = DOM.getAttrib(image, "alt");
|
|
617
|
+
const role = DOM.getAttrib(image, "role");
|
|
618
|
+
return image.hasAttribute("alt") && alt.length === 0 || role === "presentation" || role === "none";
|
|
619
|
+
};
|
|
620
|
+
const getAlt = (image) => {
|
|
621
|
+
if (getIsDecorative(image)) return "";
|
|
622
|
+
else return getAttrib(image, "alt");
|
|
623
|
+
};
|
|
624
|
+
const defaultData = () => ({
|
|
625
|
+
src: "",
|
|
626
|
+
alt: "",
|
|
627
|
+
title: "",
|
|
628
|
+
width: "",
|
|
629
|
+
height: "",
|
|
630
|
+
class: "",
|
|
631
|
+
style: "",
|
|
632
|
+
caption: false,
|
|
633
|
+
hspace: "",
|
|
634
|
+
vspace: "",
|
|
635
|
+
border: "",
|
|
636
|
+
borderStyle: "",
|
|
637
|
+
isDecorative: false
|
|
638
|
+
});
|
|
639
|
+
const getStyleValue = (normalizeCss, data) => {
|
|
640
|
+
const image = document.createElement("img");
|
|
641
|
+
updateAttrib(image, "style", data.style);
|
|
642
|
+
if (getHspace(image) || data.hspace !== "") setHspace(image, data.hspace);
|
|
643
|
+
if (getVspace(image) || data.vspace !== "") setVspace(image, data.vspace);
|
|
644
|
+
if (getBorder(image) || data.border !== "") setBorder(image, data.border);
|
|
645
|
+
if (getBorderStyle(image) || data.borderStyle !== "") setBorderStyle(image, data.borderStyle);
|
|
646
|
+
return normalizeCss(image.getAttribute("style") ?? "");
|
|
647
|
+
};
|
|
648
|
+
const create = (normalizeCss, data) => {
|
|
649
|
+
const image = document.createElement("img");
|
|
650
|
+
write(normalizeCss, {
|
|
651
|
+
...data,
|
|
652
|
+
caption: false
|
|
653
|
+
}, image);
|
|
654
|
+
setAlt(image, data.alt, data.isDecorative);
|
|
655
|
+
if (data.caption) {
|
|
656
|
+
const figure = DOM.create("figure", { class: "image" });
|
|
657
|
+
figure.appendChild(image);
|
|
658
|
+
figure.appendChild(DOM.create("figcaption", { contentEditable: "true" }, "Caption"));
|
|
659
|
+
figure.contentEditable = "false";
|
|
660
|
+
return figure;
|
|
661
|
+
} else return image;
|
|
662
|
+
};
|
|
663
|
+
const read = (normalizeCss, image) => ({
|
|
664
|
+
src: getAttrib(image, "src"),
|
|
665
|
+
alt: getAlt(image),
|
|
666
|
+
title: getAttrib(image, "title"),
|
|
667
|
+
width: getSize(image, "width"),
|
|
668
|
+
height: getSize(image, "height"),
|
|
669
|
+
class: getAttrib(image, "class"),
|
|
670
|
+
style: normalizeCss(getAttrib(image, "style")),
|
|
671
|
+
caption: hasCaption(image),
|
|
672
|
+
hspace: getHspace(image),
|
|
673
|
+
vspace: getVspace(image),
|
|
674
|
+
border: getBorder(image),
|
|
675
|
+
borderStyle: getBorderStyle(image),
|
|
676
|
+
isDecorative: getIsDecorative(image)
|
|
677
|
+
});
|
|
678
|
+
const updateProp = (image, oldData, newData, name, set) => {
|
|
679
|
+
if (newData[name] !== oldData[name]) set(image, name, String(newData[name]));
|
|
680
|
+
};
|
|
681
|
+
const setAlt = (image, alt, isDecorative) => {
|
|
682
|
+
if (isDecorative) {
|
|
683
|
+
DOM.setAttrib(image, "role", "presentation");
|
|
684
|
+
set(SugarElement.fromDom(image), "alt", "");
|
|
685
|
+
} else {
|
|
686
|
+
if (isNull(alt)) remove(SugarElement.fromDom(image), "alt");
|
|
687
|
+
else set(SugarElement.fromDom(image), "alt", alt);
|
|
688
|
+
if (DOM.getAttrib(image, "role") === "presentation") DOM.setAttrib(image, "role", "");
|
|
689
|
+
}
|
|
690
|
+
};
|
|
691
|
+
const updateAlt = (image, oldData, newData) => {
|
|
692
|
+
if (newData.alt !== oldData.alt || newData.isDecorative !== oldData.isDecorative) setAlt(image, newData.alt, newData.isDecorative);
|
|
693
|
+
};
|
|
694
|
+
const normalized = (set, normalizeCss) => (image, name, value) => {
|
|
695
|
+
set(image, value);
|
|
696
|
+
normalizeStyle(image, normalizeCss);
|
|
697
|
+
};
|
|
698
|
+
const write = (normalizeCss, newData, image) => {
|
|
699
|
+
const oldData = read(normalizeCss, image);
|
|
700
|
+
updateProp(image, oldData, newData, "caption", (image, _name, _value) => toggleCaption(image));
|
|
701
|
+
updateProp(image, oldData, newData, "src", updateAttrib);
|
|
702
|
+
updateProp(image, oldData, newData, "title", updateAttrib);
|
|
703
|
+
updateProp(image, oldData, newData, "width", setSize("width", normalizeCss));
|
|
704
|
+
updateProp(image, oldData, newData, "height", setSize("height", normalizeCss));
|
|
705
|
+
updateProp(image, oldData, newData, "class", updateAttrib);
|
|
706
|
+
updateProp(image, oldData, newData, "style", normalized((image, value) => updateAttrib(image, "style", value), normalizeCss));
|
|
707
|
+
updateProp(image, oldData, newData, "hspace", normalized(setHspace, normalizeCss));
|
|
708
|
+
updateProp(image, oldData, newData, "vspace", normalized(setVspace, normalizeCss));
|
|
709
|
+
updateProp(image, oldData, newData, "border", normalized(setBorder, normalizeCss));
|
|
710
|
+
updateProp(image, oldData, newData, "borderStyle", normalized(setBorderStyle, normalizeCss));
|
|
711
|
+
updateAlt(image, oldData, newData);
|
|
712
|
+
};
|
|
713
|
+
const normalizeCss$1 = (editor, cssText) => {
|
|
714
|
+
const mergedCss = mergeMargins(editor.dom.styles.parse(cssText));
|
|
715
|
+
const compressed = editor.dom.styles.parse(editor.dom.styles.serialize(mergedCss));
|
|
716
|
+
return editor.dom.styles.serialize(compressed);
|
|
717
|
+
};
|
|
718
|
+
const getSelectedImage = (editor) => {
|
|
719
|
+
const imgElm = editor.selection.getNode();
|
|
720
|
+
const figureElm = editor.dom.getParent(imgElm, "figure.image");
|
|
721
|
+
if (figureElm) return editor.dom.select("img", figureElm)[0];
|
|
722
|
+
if (imgElm && (imgElm.nodeName !== "IMG" || isPlaceholderImage(imgElm))) return null;
|
|
723
|
+
return imgElm;
|
|
724
|
+
};
|
|
725
|
+
const splitTextBlock = (editor, figure) => {
|
|
726
|
+
const dom = editor.dom;
|
|
727
|
+
const textBlockElements = filter(editor.schema.getTextBlockElements(), (_, parentElm) => !editor.schema.isValidChild(parentElm, "figure"));
|
|
728
|
+
const textBlock = dom.getParent(figure.parentNode, (node) => hasNonNullableKey(textBlockElements, node.nodeName), editor.getBody());
|
|
729
|
+
if (textBlock) return dom.split(textBlock, figure) ?? figure;
|
|
730
|
+
else return figure;
|
|
731
|
+
};
|
|
732
|
+
const readImageDataFromSelection = (editor) => {
|
|
733
|
+
const image = getSelectedImage(editor);
|
|
734
|
+
return image ? read((css) => normalizeCss$1(editor, css), image) : defaultData();
|
|
735
|
+
};
|
|
736
|
+
const insertImageAtCaret = (editor, data) => {
|
|
737
|
+
const elm = create((css) => normalizeCss$1(editor, css), data);
|
|
738
|
+
editor.dom.setAttrib(elm, "data-mce-id", "__mcenew");
|
|
739
|
+
editor.focus();
|
|
740
|
+
editor.insertContent(elm.outerHTML);
|
|
741
|
+
const insertedElm = editor.dom.select("*[data-mce-id=\"__mcenew\"]")[0];
|
|
742
|
+
editor.dom.setAttrib(insertedElm, "data-mce-id", null);
|
|
743
|
+
if (isFigure(insertedElm)) {
|
|
744
|
+
const figure = splitTextBlock(editor, insertedElm);
|
|
745
|
+
editor.selection.select(figure);
|
|
746
|
+
} else editor.selection.select(insertedElm);
|
|
747
|
+
};
|
|
748
|
+
const syncSrcAttr = (editor, image) => {
|
|
749
|
+
editor.dom.setAttrib(image, "src", image.getAttribute("src"));
|
|
750
|
+
};
|
|
751
|
+
const deleteImage = (editor, image) => {
|
|
752
|
+
if (image) {
|
|
753
|
+
const elm = editor.dom.is(image.parentNode, "figure.image") ? image.parentNode : image;
|
|
754
|
+
editor.dom.remove(elm);
|
|
755
|
+
editor.focus();
|
|
756
|
+
editor.nodeChanged();
|
|
757
|
+
if (editor.dom.isEmpty(editor.getBody())) {
|
|
758
|
+
editor.setContent("");
|
|
759
|
+
editor.selection.setCursorLocation();
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
};
|
|
763
|
+
const writeImageDataToSelection = (editor, data) => {
|
|
764
|
+
const image = getSelectedImage(editor);
|
|
765
|
+
if (image) {
|
|
766
|
+
write((css) => normalizeCss$1(editor, css), data, image);
|
|
767
|
+
syncSrcAttr(editor, image);
|
|
768
|
+
if (isFigure(image.parentNode)) {
|
|
769
|
+
editor.dom.setStyle(image, "float", "");
|
|
770
|
+
const figure = image.parentNode;
|
|
771
|
+
splitTextBlock(editor, figure);
|
|
772
|
+
editor.selection.select(image.parentNode);
|
|
773
|
+
} else {
|
|
774
|
+
editor.selection.select(image);
|
|
775
|
+
waitLoadImage(editor, data, image);
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
};
|
|
779
|
+
const sanitizeImageData = (editor, data) => {
|
|
780
|
+
const src = data.src;
|
|
781
|
+
return {
|
|
782
|
+
...data,
|
|
783
|
+
src: isSafeImageUrl(editor, src) ? src : ""
|
|
784
|
+
};
|
|
785
|
+
};
|
|
786
|
+
const insertOrUpdateImage = (editor, partialData) => {
|
|
787
|
+
const image = getSelectedImage(editor);
|
|
788
|
+
if (image) {
|
|
789
|
+
const data = {
|
|
790
|
+
...read((css) => normalizeCss$1(editor, css), image),
|
|
791
|
+
...partialData
|
|
792
|
+
};
|
|
793
|
+
const sanitizedData = sanitizeImageData(editor, data);
|
|
794
|
+
if (data.src) writeImageDataToSelection(editor, sanitizedData);
|
|
795
|
+
else deleteImage(editor, image);
|
|
796
|
+
} else if (partialData.src) insertImageAtCaret(editor, {
|
|
797
|
+
...defaultData(),
|
|
798
|
+
...partialData
|
|
799
|
+
});
|
|
800
|
+
};
|
|
801
|
+
var global$1 = tinymce.util.Tools.resolve("tinymce.util.ImageUploader");
|
|
802
|
+
var global = tinymce.util.Tools.resolve("tinymce.util.Tools");
|
|
803
|
+
const getValue = (item) => isString(item.value) ? item.value : "";
|
|
804
|
+
const getText = (item) => {
|
|
805
|
+
if (isString(item.text)) return item.text;
|
|
806
|
+
else if (isString(item.title)) return item.title;
|
|
807
|
+
else return "";
|
|
808
|
+
};
|
|
809
|
+
const sanitizeList = (list, extractValue) => {
|
|
810
|
+
const out = [];
|
|
811
|
+
global.each(list, (item) => {
|
|
812
|
+
const text = getText(item);
|
|
813
|
+
if (item.menu !== void 0) {
|
|
814
|
+
const items = sanitizeList(item.menu, extractValue);
|
|
815
|
+
out.push({
|
|
816
|
+
text,
|
|
817
|
+
items
|
|
818
|
+
});
|
|
819
|
+
} else {
|
|
820
|
+
const value = extractValue(item);
|
|
821
|
+
out.push({
|
|
822
|
+
text,
|
|
823
|
+
value
|
|
824
|
+
});
|
|
825
|
+
}
|
|
826
|
+
});
|
|
827
|
+
return out;
|
|
828
|
+
};
|
|
829
|
+
const sanitizer = (extractor = getValue) => (list) => {
|
|
830
|
+
if (list) return Optional.from(list).map((list) => sanitizeList(list, extractor));
|
|
831
|
+
else return Optional.none();
|
|
832
|
+
};
|
|
833
|
+
const sanitize = (list) => sanitizer(getValue)(list);
|
|
834
|
+
const isGroup = (item) => has(item, "items");
|
|
835
|
+
const findEntryDelegate = (list, value) => findMap(list, (item) => {
|
|
836
|
+
if (isGroup(item)) return findEntryDelegate(item.items, value);
|
|
837
|
+
else if (item.value === value) return Optional.some(item);
|
|
838
|
+
else return Optional.none();
|
|
839
|
+
});
|
|
840
|
+
const findEntry = (optList, value) => optList.bind((list) => findEntryDelegate(list, value));
|
|
841
|
+
const ListUtils = {
|
|
842
|
+
sanitizer,
|
|
843
|
+
sanitize,
|
|
844
|
+
findEntry
|
|
845
|
+
};
|
|
846
|
+
const makeTab$2 = (_info) => ({
|
|
847
|
+
title: "Advanced",
|
|
848
|
+
name: "advanced",
|
|
849
|
+
items: [{
|
|
850
|
+
type: "grid",
|
|
851
|
+
columns: 2,
|
|
852
|
+
items: [
|
|
853
|
+
{
|
|
854
|
+
type: "input",
|
|
855
|
+
label: "Vertical space",
|
|
856
|
+
name: "vspace",
|
|
857
|
+
inputMode: "numeric"
|
|
858
|
+
},
|
|
859
|
+
{
|
|
860
|
+
type: "input",
|
|
861
|
+
label: "Horizontal space",
|
|
862
|
+
name: "hspace",
|
|
863
|
+
inputMode: "numeric"
|
|
864
|
+
},
|
|
865
|
+
{
|
|
866
|
+
type: "input",
|
|
867
|
+
label: "Border width",
|
|
868
|
+
name: "border",
|
|
869
|
+
inputMode: "numeric"
|
|
870
|
+
},
|
|
871
|
+
{
|
|
872
|
+
type: "listbox",
|
|
873
|
+
name: "borderstyle",
|
|
874
|
+
label: "Border style",
|
|
875
|
+
items: [
|
|
876
|
+
{
|
|
877
|
+
text: "Select...",
|
|
878
|
+
value: ""
|
|
879
|
+
},
|
|
880
|
+
{
|
|
881
|
+
text: "Solid",
|
|
882
|
+
value: "solid"
|
|
883
|
+
},
|
|
884
|
+
{
|
|
885
|
+
text: "Dotted",
|
|
886
|
+
value: "dotted"
|
|
887
|
+
},
|
|
888
|
+
{
|
|
889
|
+
text: "Dashed",
|
|
890
|
+
value: "dashed"
|
|
891
|
+
},
|
|
892
|
+
{
|
|
893
|
+
text: "Double",
|
|
894
|
+
value: "double"
|
|
895
|
+
},
|
|
896
|
+
{
|
|
897
|
+
text: "Groove",
|
|
898
|
+
value: "groove"
|
|
899
|
+
},
|
|
900
|
+
{
|
|
901
|
+
text: "Ridge",
|
|
902
|
+
value: "ridge"
|
|
903
|
+
},
|
|
904
|
+
{
|
|
905
|
+
text: "Inset",
|
|
906
|
+
value: "inset"
|
|
907
|
+
},
|
|
908
|
+
{
|
|
909
|
+
text: "Outset",
|
|
910
|
+
value: "outset"
|
|
911
|
+
},
|
|
912
|
+
{
|
|
913
|
+
text: "None",
|
|
914
|
+
value: "none"
|
|
915
|
+
},
|
|
916
|
+
{
|
|
917
|
+
text: "Hidden",
|
|
918
|
+
value: "hidden"
|
|
919
|
+
}
|
|
920
|
+
]
|
|
921
|
+
}
|
|
922
|
+
]
|
|
923
|
+
}]
|
|
924
|
+
});
|
|
925
|
+
const AdvTab = { makeTab: makeTab$2 };
|
|
926
|
+
const collect = (editor) => {
|
|
927
|
+
const urlListSanitizer = ListUtils.sanitizer((item) => editor.convertURL(item.value || item.url || "", "src"));
|
|
928
|
+
const futureImageList = new Promise((completer) => {
|
|
929
|
+
createImageList(editor, (imageList) => {
|
|
930
|
+
completer(urlListSanitizer(imageList).map((items) => flatten([[{
|
|
931
|
+
text: "None",
|
|
932
|
+
value: ""
|
|
933
|
+
}], items])));
|
|
934
|
+
});
|
|
935
|
+
});
|
|
936
|
+
const alertErr = (message, callback) => {
|
|
937
|
+
editor.windowManager.alert(message, callback);
|
|
938
|
+
};
|
|
939
|
+
const classList = ListUtils.sanitize(getClassList(editor));
|
|
940
|
+
const hasAdvTab$1 = hasAdvTab(editor);
|
|
941
|
+
const hasUploadTab$1 = hasUploadTab(editor);
|
|
942
|
+
const hasUploadUrl$1 = hasUploadUrl(editor);
|
|
943
|
+
const hasUploadHandler$1 = hasUploadHandler(editor);
|
|
944
|
+
const image = readImageDataFromSelection(editor);
|
|
945
|
+
const hasDescription$1 = hasDescription(editor);
|
|
946
|
+
const hasImageTitle$1 = hasImageTitle(editor);
|
|
947
|
+
const hasDimensions$1 = hasDimensions(editor);
|
|
948
|
+
const hasImageCaption$1 = hasImageCaption(editor);
|
|
949
|
+
const hasAccessibilityOptions = showAccessibilityOptions(editor);
|
|
950
|
+
const automaticUploads = isAutomaticUploadsEnabled(editor);
|
|
951
|
+
const prependURL = Optional.some(getPrependUrl(editor)).filter((preUrl) => isString(preUrl) && preUrl.length > 0);
|
|
952
|
+
return futureImageList.then((imageList) => ({
|
|
953
|
+
alertErr,
|
|
954
|
+
image,
|
|
955
|
+
imageList,
|
|
956
|
+
classList,
|
|
957
|
+
hasAdvTab: hasAdvTab$1,
|
|
958
|
+
hasUploadTab: hasUploadTab$1,
|
|
959
|
+
hasUploadUrl: hasUploadUrl$1,
|
|
960
|
+
hasUploadHandler: hasUploadHandler$1,
|
|
961
|
+
hasDescription: hasDescription$1,
|
|
962
|
+
hasImageTitle: hasImageTitle$1,
|
|
963
|
+
hasDimensions: hasDimensions$1,
|
|
964
|
+
hasImageCaption: hasImageCaption$1,
|
|
965
|
+
prependURL,
|
|
966
|
+
hasAccessibilityOptions,
|
|
967
|
+
automaticUploads
|
|
968
|
+
}));
|
|
969
|
+
};
|
|
970
|
+
const makeItems = (info) => {
|
|
971
|
+
const imageUrl = {
|
|
972
|
+
name: "src",
|
|
973
|
+
type: "urlinput",
|
|
974
|
+
filetype: "image",
|
|
975
|
+
label: "Source",
|
|
976
|
+
picker_text: "Browse files"
|
|
977
|
+
};
|
|
978
|
+
const imageList = info.imageList.map((items) => ({
|
|
979
|
+
name: "images",
|
|
980
|
+
type: "listbox",
|
|
981
|
+
label: "Image list",
|
|
982
|
+
items
|
|
983
|
+
}));
|
|
984
|
+
const imageDescription = {
|
|
985
|
+
name: "alt",
|
|
986
|
+
type: "input",
|
|
987
|
+
label: "Alternative description",
|
|
988
|
+
enabled: !(info.hasAccessibilityOptions && info.image.isDecorative)
|
|
989
|
+
};
|
|
990
|
+
const imageTitle = {
|
|
991
|
+
name: "title",
|
|
992
|
+
type: "input",
|
|
993
|
+
label: "Image title"
|
|
994
|
+
};
|
|
995
|
+
const imageDimensions = {
|
|
996
|
+
name: "dimensions",
|
|
997
|
+
type: "sizeinput"
|
|
998
|
+
};
|
|
999
|
+
const isDecorative = {
|
|
1000
|
+
type: "label",
|
|
1001
|
+
label: "Accessibility",
|
|
1002
|
+
items: [{
|
|
1003
|
+
name: "isDecorative",
|
|
1004
|
+
type: "checkbox",
|
|
1005
|
+
label: "Image is decorative"
|
|
1006
|
+
}]
|
|
1007
|
+
};
|
|
1008
|
+
const classList = info.classList.map((items) => ({
|
|
1009
|
+
name: "classes",
|
|
1010
|
+
type: "listbox",
|
|
1011
|
+
label: "Class",
|
|
1012
|
+
items
|
|
1013
|
+
}));
|
|
1014
|
+
const caption = {
|
|
1015
|
+
type: "label",
|
|
1016
|
+
label: "Caption",
|
|
1017
|
+
items: [{
|
|
1018
|
+
type: "checkbox",
|
|
1019
|
+
name: "caption",
|
|
1020
|
+
label: "Show caption"
|
|
1021
|
+
}]
|
|
1022
|
+
};
|
|
1023
|
+
const getDialogContainerType = (useColumns) => useColumns ? {
|
|
1024
|
+
type: "grid",
|
|
1025
|
+
columns: 2
|
|
1026
|
+
} : { type: "panel" };
|
|
1027
|
+
return flatten([
|
|
1028
|
+
[imageUrl],
|
|
1029
|
+
imageList.toArray(),
|
|
1030
|
+
info.hasAccessibilityOptions && info.hasDescription ? [isDecorative] : [],
|
|
1031
|
+
info.hasDescription ? [imageDescription] : [],
|
|
1032
|
+
info.hasImageTitle ? [imageTitle] : [],
|
|
1033
|
+
info.hasDimensions ? [imageDimensions] : [],
|
|
1034
|
+
[{
|
|
1035
|
+
...getDialogContainerType(info.classList.isSome() && info.hasImageCaption),
|
|
1036
|
+
items: flatten([classList.toArray(), info.hasImageCaption ? [caption] : []])
|
|
1037
|
+
}]
|
|
1038
|
+
]);
|
|
1039
|
+
};
|
|
1040
|
+
const makeTab$1 = (info) => ({
|
|
1041
|
+
title: "General",
|
|
1042
|
+
name: "general",
|
|
1043
|
+
items: makeItems(info)
|
|
1044
|
+
});
|
|
1045
|
+
const MainTab = {
|
|
1046
|
+
makeTab: makeTab$1,
|
|
1047
|
+
makeItems
|
|
1048
|
+
};
|
|
1049
|
+
const makeTab = (_info, onInvalidFiles) => {
|
|
1050
|
+
return {
|
|
1051
|
+
title: "Upload",
|
|
1052
|
+
name: "upload",
|
|
1053
|
+
items: [{
|
|
1054
|
+
type: "dropzone",
|
|
1055
|
+
name: "fileinput",
|
|
1056
|
+
onInvalidFiles
|
|
1057
|
+
}]
|
|
1058
|
+
};
|
|
1059
|
+
};
|
|
1060
|
+
const UploadTab = { makeTab };
|
|
1061
|
+
const createState = (info) => ({
|
|
1062
|
+
prevImage: ListUtils.findEntry(info.imageList, info.image.src),
|
|
1063
|
+
prevAlt: info.image.alt,
|
|
1064
|
+
open: true
|
|
1065
|
+
});
|
|
1066
|
+
const fromImageData = (image) => ({
|
|
1067
|
+
src: {
|
|
1068
|
+
value: image.src,
|
|
1069
|
+
meta: {}
|
|
1070
|
+
},
|
|
1071
|
+
images: image.src,
|
|
1072
|
+
alt: image.alt,
|
|
1073
|
+
title: image.title,
|
|
1074
|
+
dimensions: {
|
|
1075
|
+
width: image.width,
|
|
1076
|
+
height: image.height
|
|
1077
|
+
},
|
|
1078
|
+
classes: image.class,
|
|
1079
|
+
caption: image.caption,
|
|
1080
|
+
style: image.style,
|
|
1081
|
+
vspace: image.vspace,
|
|
1082
|
+
border: image.border,
|
|
1083
|
+
hspace: image.hspace,
|
|
1084
|
+
borderstyle: image.borderStyle,
|
|
1085
|
+
fileinput: [],
|
|
1086
|
+
isDecorative: image.isDecorative
|
|
1087
|
+
});
|
|
1088
|
+
const toImageData = (data, removeEmptyAlt) => ({
|
|
1089
|
+
src: data.src.value,
|
|
1090
|
+
alt: (data.alt === null || data.alt.length === 0) && removeEmptyAlt ? null : data.alt,
|
|
1091
|
+
title: data.title,
|
|
1092
|
+
width: data.dimensions.width,
|
|
1093
|
+
height: data.dimensions.height,
|
|
1094
|
+
class: data.classes,
|
|
1095
|
+
style: data.style,
|
|
1096
|
+
caption: data.caption,
|
|
1097
|
+
hspace: data.hspace,
|
|
1098
|
+
vspace: data.vspace,
|
|
1099
|
+
border: data.border,
|
|
1100
|
+
borderStyle: data.borderstyle,
|
|
1101
|
+
isDecorative: data.isDecorative
|
|
1102
|
+
});
|
|
1103
|
+
const addPrependUrl2 = (info, srcURL) => {
|
|
1104
|
+
if (!/^(?:[a-zA-Z]+:)?\/\//.test(srcURL)) return info.prependURL.bind((prependUrl) => {
|
|
1105
|
+
if (srcURL.substring(0, prependUrl.length) !== prependUrl) return Optional.some(prependUrl + srcURL);
|
|
1106
|
+
return Optional.none();
|
|
1107
|
+
});
|
|
1108
|
+
return Optional.none();
|
|
1109
|
+
};
|
|
1110
|
+
const addPrependUrl = (info, api) => {
|
|
1111
|
+
const data = api.getData();
|
|
1112
|
+
addPrependUrl2(info, data.src.value).each((srcURL) => {
|
|
1113
|
+
api.setData({ src: {
|
|
1114
|
+
value: srcURL,
|
|
1115
|
+
meta: data.src.meta
|
|
1116
|
+
} });
|
|
1117
|
+
});
|
|
1118
|
+
};
|
|
1119
|
+
const formFillFromMeta2 = (info, data, meta) => {
|
|
1120
|
+
if (info.hasDescription && isString(meta.alt)) data.alt = meta.alt;
|
|
1121
|
+
if (info.hasAccessibilityOptions) data.isDecorative = meta.isDecorative || data.isDecorative || false;
|
|
1122
|
+
if (info.hasImageTitle && isString(meta.title)) data.title = meta.title;
|
|
1123
|
+
if (info.hasDimensions) {
|
|
1124
|
+
if (isString(meta.width)) data.dimensions.width = meta.width;
|
|
1125
|
+
if (isString(meta.height)) data.dimensions.height = meta.height;
|
|
1126
|
+
}
|
|
1127
|
+
if (isString(meta.class)) ListUtils.findEntry(info.classList, meta.class).each((entry) => {
|
|
1128
|
+
data.classes = entry.value;
|
|
1129
|
+
});
|
|
1130
|
+
if (info.hasImageCaption) {
|
|
1131
|
+
if (isBoolean(meta.caption)) data.caption = meta.caption;
|
|
1132
|
+
}
|
|
1133
|
+
if (info.hasAdvTab) {
|
|
1134
|
+
if (isString(meta.style)) data.style = meta.style;
|
|
1135
|
+
if (isString(meta.vspace)) data.vspace = meta.vspace;
|
|
1136
|
+
if (isString(meta.border)) data.border = meta.border;
|
|
1137
|
+
if (isString(meta.hspace)) data.hspace = meta.hspace;
|
|
1138
|
+
if (isString(meta.borderstyle)) data.borderstyle = meta.borderstyle;
|
|
1139
|
+
}
|
|
1140
|
+
};
|
|
1141
|
+
const formFillFromMeta = (info, api) => {
|
|
1142
|
+
const data = api.getData();
|
|
1143
|
+
const meta = data.src.meta;
|
|
1144
|
+
if (meta !== void 0) {
|
|
1145
|
+
const newData = deepMerge({}, data);
|
|
1146
|
+
formFillFromMeta2(info, newData, meta);
|
|
1147
|
+
api.setData(newData);
|
|
1148
|
+
}
|
|
1149
|
+
};
|
|
1150
|
+
const calculateImageSize = (helpers, info, state, api) => {
|
|
1151
|
+
const data = api.getData();
|
|
1152
|
+
const url = data.src.value;
|
|
1153
|
+
const meta = data.src.meta || {};
|
|
1154
|
+
if (!meta.width && !meta.height && info.hasDimensions) if (isNotEmpty(url)) helpers.imageSize(url).then((size) => {
|
|
1155
|
+
if (state.open) api.setData({ dimensions: size });
|
|
1156
|
+
}).catch((e) => console.error(e));
|
|
1157
|
+
else api.setData({ dimensions: {
|
|
1158
|
+
width: "",
|
|
1159
|
+
height: ""
|
|
1160
|
+
} });
|
|
1161
|
+
};
|
|
1162
|
+
const updateImagesDropdown = (info, state, api) => {
|
|
1163
|
+
const data = api.getData();
|
|
1164
|
+
const image = ListUtils.findEntry(info.imageList, data.src.value);
|
|
1165
|
+
state.prevImage = image;
|
|
1166
|
+
api.setData({ images: image.map((entry) => entry.value).getOr("") });
|
|
1167
|
+
};
|
|
1168
|
+
const changeSrc = (helpers, info, state, api) => {
|
|
1169
|
+
addPrependUrl(info, api);
|
|
1170
|
+
formFillFromMeta(info, api);
|
|
1171
|
+
calculateImageSize(helpers, info, state, api);
|
|
1172
|
+
updateImagesDropdown(info, state, api);
|
|
1173
|
+
};
|
|
1174
|
+
const changeImages = (helpers, info, state, api) => {
|
|
1175
|
+
const data = api.getData();
|
|
1176
|
+
const image = ListUtils.findEntry(info.imageList, data.images);
|
|
1177
|
+
image.each((img) => {
|
|
1178
|
+
if (data.alt === "" || state.prevImage.map((image) => image.text === data.alt).getOr(false)) if (img.value === "") api.setData({
|
|
1179
|
+
src: img,
|
|
1180
|
+
alt: state.prevAlt
|
|
1181
|
+
});
|
|
1182
|
+
else api.setData({
|
|
1183
|
+
src: img,
|
|
1184
|
+
alt: img.text
|
|
1185
|
+
});
|
|
1186
|
+
else api.setData({ src: img });
|
|
1187
|
+
});
|
|
1188
|
+
state.prevImage = image;
|
|
1189
|
+
changeSrc(helpers, info, state, api);
|
|
1190
|
+
};
|
|
1191
|
+
const changeFileInput = (helpers, info, state, api) => {
|
|
1192
|
+
const data = api.getData();
|
|
1193
|
+
api.block("Uploading image");
|
|
1194
|
+
head(data.fileinput).fold(() => {
|
|
1195
|
+
api.unblock();
|
|
1196
|
+
}, (file) => {
|
|
1197
|
+
const blobUri = URL.createObjectURL(file);
|
|
1198
|
+
const finalize = () => {
|
|
1199
|
+
api.unblock();
|
|
1200
|
+
URL.revokeObjectURL(blobUri);
|
|
1201
|
+
};
|
|
1202
|
+
const updateSrcAndSwitchTab = (url) => {
|
|
1203
|
+
api.setData({ src: {
|
|
1204
|
+
value: url,
|
|
1205
|
+
meta: {}
|
|
1206
|
+
} });
|
|
1207
|
+
api.showTab("general");
|
|
1208
|
+
changeSrc(helpers, info, state, api);
|
|
1209
|
+
api.focus("src");
|
|
1210
|
+
};
|
|
1211
|
+
blobToDataUri(file).then((dataUrl) => {
|
|
1212
|
+
const blobInfo = helpers.createBlobCache(file, blobUri, dataUrl);
|
|
1213
|
+
if (info.automaticUploads) helpers.uploadImage(blobInfo).then((result) => {
|
|
1214
|
+
updateSrcAndSwitchTab(result.url);
|
|
1215
|
+
finalize();
|
|
1216
|
+
}).catch((err) => {
|
|
1217
|
+
finalize();
|
|
1218
|
+
info.alertErr(err, () => {
|
|
1219
|
+
api.focus("fileinput");
|
|
1220
|
+
});
|
|
1221
|
+
});
|
|
1222
|
+
else {
|
|
1223
|
+
helpers.addToBlobCache(blobInfo);
|
|
1224
|
+
updateSrcAndSwitchTab(blobInfo.blobUri());
|
|
1225
|
+
api.unblock();
|
|
1226
|
+
}
|
|
1227
|
+
});
|
|
1228
|
+
});
|
|
1229
|
+
};
|
|
1230
|
+
const changeHandler = (helpers, info, state) => (api, evt) => {
|
|
1231
|
+
if (evt.name === "src") changeSrc(helpers, info, state, api);
|
|
1232
|
+
else if (evt.name === "images") changeImages(helpers, info, state, api);
|
|
1233
|
+
else if (evt.name === "alt") state.prevAlt = api.getData().alt;
|
|
1234
|
+
else if (evt.name === "fileinput") changeFileInput(helpers, info, state, api);
|
|
1235
|
+
else if (evt.name === "isDecorative") api.setEnabled("alt", !api.getData().isDecorative);
|
|
1236
|
+
};
|
|
1237
|
+
const closeHandler = (state) => () => {
|
|
1238
|
+
state.open = false;
|
|
1239
|
+
};
|
|
1240
|
+
const makeDialogBody = (info) => {
|
|
1241
|
+
if (info.hasAdvTab || info.hasUploadUrl || info.hasUploadHandler) return {
|
|
1242
|
+
type: "tabpanel",
|
|
1243
|
+
tabs: flatten([
|
|
1244
|
+
[MainTab.makeTab(info)],
|
|
1245
|
+
info.hasAdvTab ? [AdvTab.makeTab(info)] : [],
|
|
1246
|
+
info.hasUploadTab && (info.hasUploadUrl || info.hasUploadHandler) ? [UploadTab.makeTab(info, () => new Promise((r) => info.alertErr("Selected images do not have allowed extensions", r)))] : []
|
|
1247
|
+
])
|
|
1248
|
+
};
|
|
1249
|
+
else return {
|
|
1250
|
+
type: "panel",
|
|
1251
|
+
items: MainTab.makeItems(info)
|
|
1252
|
+
};
|
|
1253
|
+
};
|
|
1254
|
+
const submitHandler = (editor, info, helpers) => (api) => {
|
|
1255
|
+
const data = deepMerge(fromImageData(info.image), api.getData());
|
|
1256
|
+
const finalData = {
|
|
1257
|
+
...data,
|
|
1258
|
+
style: getStyleValue(helpers.normalizeCss, toImageData(data, false))
|
|
1259
|
+
};
|
|
1260
|
+
editor.execCommand("mceUpdateImage", false, toImageData(finalData, info.hasAccessibilityOptions));
|
|
1261
|
+
editor.editorUpload.uploadImagesAuto();
|
|
1262
|
+
api.close();
|
|
1263
|
+
};
|
|
1264
|
+
const imageSize = (editor) => (url) => {
|
|
1265
|
+
if (!isSafeImageUrl(editor, url)) return Promise.resolve({
|
|
1266
|
+
width: "",
|
|
1267
|
+
height: ""
|
|
1268
|
+
});
|
|
1269
|
+
else return getImageSize(editor.documentBaseURI.toAbsolute(url)).then((dimensions) => ({
|
|
1270
|
+
width: String(dimensions.width),
|
|
1271
|
+
height: String(dimensions.height)
|
|
1272
|
+
}));
|
|
1273
|
+
};
|
|
1274
|
+
const createBlobCache = (editor) => (file, blobUri, dataUrl) => editor.editorUpload.blobCache.create({
|
|
1275
|
+
blob: file,
|
|
1276
|
+
blobUri,
|
|
1277
|
+
name: file.name?.replace(/\.[^\.]+$/, ""),
|
|
1278
|
+
filename: file.name,
|
|
1279
|
+
base64: dataUrl.split(",")[1]
|
|
1280
|
+
});
|
|
1281
|
+
const addToBlobCache = (editor) => (blobInfo) => {
|
|
1282
|
+
editor.editorUpload.blobCache.add(blobInfo);
|
|
1283
|
+
};
|
|
1284
|
+
const normalizeCss = (editor) => (cssText) => normalizeCss$1(editor, cssText);
|
|
1285
|
+
const parseStyle = (editor) => (cssText) => editor.dom.parseStyle(cssText);
|
|
1286
|
+
const serializeStyle = (editor) => (stylesArg, name) => editor.dom.serializeStyle(stylesArg, name);
|
|
1287
|
+
const uploadImage = (editor) => (blobInfo) => global$1(editor).upload([blobInfo], false).then((results) => {
|
|
1288
|
+
if (results.length === 0) return Promise.reject("Failed to upload image");
|
|
1289
|
+
else if (results[0].status === false) return Promise.reject(results[0].error?.message);
|
|
1290
|
+
else return results[0];
|
|
1291
|
+
});
|
|
1292
|
+
const Dialog = (editor) => {
|
|
1293
|
+
const helpers = {
|
|
1294
|
+
imageSize: imageSize(editor),
|
|
1295
|
+
addToBlobCache: addToBlobCache(editor),
|
|
1296
|
+
createBlobCache: createBlobCache(editor),
|
|
1297
|
+
normalizeCss: normalizeCss(editor),
|
|
1298
|
+
parseStyle: parseStyle(editor),
|
|
1299
|
+
serializeStyle: serializeStyle(editor),
|
|
1300
|
+
uploadImage: uploadImage(editor)
|
|
1301
|
+
};
|
|
1302
|
+
const open = () => {
|
|
1303
|
+
collect(editor).then((info) => {
|
|
1304
|
+
const state = createState(info);
|
|
1305
|
+
return {
|
|
1306
|
+
title: "Insert/Edit Image",
|
|
1307
|
+
size: "normal",
|
|
1308
|
+
body: makeDialogBody(info),
|
|
1309
|
+
buttons: [{
|
|
1310
|
+
type: "cancel",
|
|
1311
|
+
name: "cancel",
|
|
1312
|
+
text: "Cancel"
|
|
1313
|
+
}, {
|
|
1314
|
+
type: "submit",
|
|
1315
|
+
name: "save",
|
|
1316
|
+
text: "Save",
|
|
1317
|
+
primary: true
|
|
1318
|
+
}],
|
|
1319
|
+
initialData: fromImageData(info.image),
|
|
1320
|
+
onSubmit: submitHandler(editor, info, helpers),
|
|
1321
|
+
onChange: changeHandler(helpers, info, state),
|
|
1322
|
+
onClose: closeHandler(state)
|
|
1323
|
+
};
|
|
1324
|
+
}).then(editor.windowManager.open);
|
|
1325
|
+
};
|
|
1326
|
+
return { open };
|
|
1327
|
+
};
|
|
1328
|
+
const register$1 = (editor) => {
|
|
1329
|
+
editor.addCommand("mceImage", Dialog(editor).open);
|
|
1330
|
+
editor.addCommand("mceUpdateImage", (_ui, data) => {
|
|
1331
|
+
editor.undoManager.transact(() => insertOrUpdateImage(editor, data));
|
|
1332
|
+
});
|
|
1333
|
+
};
|
|
1334
|
+
const hasImageClass = (node) => {
|
|
1335
|
+
const className = node.attr("class");
|
|
1336
|
+
return isNonNullable(className) && /\bimage\b/.test(className);
|
|
1337
|
+
};
|
|
1338
|
+
const toggleContentEditableState = (state) => (nodes) => {
|
|
1339
|
+
let i = nodes.length;
|
|
1340
|
+
const toggleContentEditable = (node) => {
|
|
1341
|
+
node.attr("contenteditable", state ? "true" : null);
|
|
1342
|
+
};
|
|
1343
|
+
while (i--) {
|
|
1344
|
+
const node = nodes[i];
|
|
1345
|
+
if (hasImageClass(node)) {
|
|
1346
|
+
node.attr("contenteditable", state ? "false" : null);
|
|
1347
|
+
global.each(node.getAll("figcaption"), toggleContentEditable);
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
};
|
|
1351
|
+
const setup = (editor) => {
|
|
1352
|
+
editor.on("PreInit", () => {
|
|
1353
|
+
editor.parser.addNodeFilter("figure", toggleContentEditableState(true));
|
|
1354
|
+
editor.serializer.addNodeFilter("figure", toggleContentEditableState(false));
|
|
1355
|
+
});
|
|
1356
|
+
};
|
|
1357
|
+
const onSetupEditable = (editor) => (api) => {
|
|
1358
|
+
const nodeChanged = () => {
|
|
1359
|
+
api.setEnabled(editor.selection.isEditable());
|
|
1360
|
+
};
|
|
1361
|
+
editor.on("NodeChange", nodeChanged);
|
|
1362
|
+
nodeChanged();
|
|
1363
|
+
return () => {
|
|
1364
|
+
editor.off("NodeChange", nodeChanged);
|
|
1365
|
+
};
|
|
1366
|
+
};
|
|
1367
|
+
const register = (editor) => {
|
|
1368
|
+
editor.ui.registry.addToggleButton("image", {
|
|
1369
|
+
icon: "image",
|
|
1370
|
+
tooltip: "Insert/edit image",
|
|
1371
|
+
onAction: Dialog(editor).open,
|
|
1372
|
+
onSetup: (buttonApi) => {
|
|
1373
|
+
buttonApi.setActive(isNonNullable(getSelectedImage(editor)));
|
|
1374
|
+
const unbindSelectorChanged = editor.selection.selectorChangedWithUnbind("img:not([data-mce-object]):not([data-mce-placeholder]),figure.image", buttonApi.setActive).unbind;
|
|
1375
|
+
const unbindEditable = onSetupEditable(editor)(buttonApi);
|
|
1376
|
+
return () => {
|
|
1377
|
+
unbindSelectorChanged();
|
|
1378
|
+
unbindEditable();
|
|
1379
|
+
};
|
|
1380
|
+
}
|
|
1381
|
+
});
|
|
1382
|
+
editor.ui.registry.addMenuItem("image", {
|
|
1383
|
+
icon: "image",
|
|
1384
|
+
text: "Image...",
|
|
1385
|
+
onAction: Dialog(editor).open,
|
|
1386
|
+
onSetup: onSetupEditable(editor)
|
|
1387
|
+
});
|
|
1388
|
+
editor.ui.registry.addContextMenu("image", { update: (element) => editor.selection.isEditable() && (isFigure(element) || isImage(element) && !isPlaceholderImage(element)) ? ["image"] : [] });
|
|
1389
|
+
};
|
|
1390
|
+
var Plugin = () => {
|
|
1391
|
+
global$4.add("image", (editor) => {
|
|
1392
|
+
register$2(editor);
|
|
1393
|
+
setup(editor);
|
|
1394
|
+
register(editor);
|
|
1395
|
+
register$1(editor);
|
|
1396
|
+
});
|
|
1397
|
+
};
|
|
1398
|
+
Plugin();
|
|
1399
|
+
/** *****
|
|
1400
|
+
* DO NOT EXPORT ANYTHING
|
|
1401
|
+
*
|
|
1402
|
+
* IF YOU DO ROLLUP WILL LEAVE A GLOBAL ON THE PAGE
|
|
1403
|
+
*******/
|
|
1404
|
+
})();
|
|
1405
|
+
})))();
|
|
1406
|
+
//#endregion
|
|
1407
|
+
|
|
1408
|
+
//# sourceMappingURL=image-BBEGvs_X.js.map
|