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