@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,921 +7,589 @@
|
|
|
7
7
|
|
|
8
8
|
var global$7 = tinymce.util.Tools.resolve('tinymce.PluginManager');
|
|
9
9
|
|
|
10
|
-
/* eslint-disable @typescript-eslint/no-wrapper-object-types */
|
|
11
10
|
const hasProto = (v, constructor, predicate) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return 'string';
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
return t;
|
|
34
|
-
}
|
|
11
|
+
var _a;
|
|
12
|
+
if (predicate(v, constructor.prototype)) {
|
|
13
|
+
return true;
|
|
14
|
+
} else {
|
|
15
|
+
return ((_a = v.constructor) === null || _a === void 0 ? void 0 : _a.name) === constructor.name;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
const typeOf = x => {
|
|
19
|
+
const t = typeof x;
|
|
20
|
+
if (x === null) {
|
|
21
|
+
return 'null';
|
|
22
|
+
} else if (t === 'object' && Array.isArray(x)) {
|
|
23
|
+
return 'array';
|
|
24
|
+
} else if (t === 'object' && hasProto(x, String, (o, proto) => proto.isPrototypeOf(o))) {
|
|
25
|
+
return 'string';
|
|
26
|
+
} else {
|
|
27
|
+
return t;
|
|
28
|
+
}
|
|
35
29
|
};
|
|
36
|
-
const isType$1 =
|
|
37
|
-
const isSimpleType =
|
|
30
|
+
const isType$1 = type => value => typeOf(value) === type;
|
|
31
|
+
const isSimpleType = type => value => typeof value === type;
|
|
38
32
|
const isString = isType$1('string');
|
|
39
33
|
const isObject = isType$1('object');
|
|
40
34
|
const isArray = isType$1('array');
|
|
41
35
|
const isBoolean = isSimpleType('boolean');
|
|
42
|
-
const isNullable =
|
|
43
|
-
const isNonNullable =
|
|
36
|
+
const isNullable = a => a === null || a === undefined;
|
|
37
|
+
const isNonNullable = a => !isNullable(a);
|
|
44
38
|
const isFunction = isSimpleType('function');
|
|
45
39
|
const isNumber = isSimpleType('number');
|
|
46
40
|
|
|
47
|
-
const noop = () => {
|
|
48
|
-
|
|
49
|
-
const compose1 = (fbc, fab) =>
|
|
50
|
-
const constant =
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
41
|
+
const noop = () => {
|
|
42
|
+
};
|
|
43
|
+
const compose1 = (fbc, fab) => a => fbc(fab(a));
|
|
44
|
+
const constant = value => {
|
|
45
|
+
return () => {
|
|
46
|
+
return value;
|
|
47
|
+
};
|
|
54
48
|
};
|
|
55
49
|
const tripleEquals = (a, b) => {
|
|
56
|
-
|
|
50
|
+
return a === b;
|
|
57
51
|
};
|
|
58
|
-
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
|
|
59
52
|
function curry(fn, ...initialArgs) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
53
|
+
return (...restArgs) => {
|
|
54
|
+
const all = initialArgs.concat(restArgs);
|
|
55
|
+
return fn.apply(null, all);
|
|
56
|
+
};
|
|
64
57
|
}
|
|
65
|
-
const not =
|
|
58
|
+
const not = f => t => !f(t);
|
|
66
59
|
const never = constant(false);
|
|
67
60
|
|
|
68
|
-
/**
|
|
69
|
-
* The `Optional` type represents a value (of any type) that potentially does
|
|
70
|
-
* not exist. Any `Optional<T>` can either be a `Some<T>` (in which case the
|
|
71
|
-
* value does exist) or a `None` (in which case the value does not exist). This
|
|
72
|
-
* module defines a whole lot of FP-inspired utility functions for dealing with
|
|
73
|
-
* `Optional` objects.
|
|
74
|
-
*
|
|
75
|
-
* Comparison with null or undefined:
|
|
76
|
-
* - We don't get fancy null coalescing operators with `Optional`
|
|
77
|
-
* - We do get fancy helper functions with `Optional`
|
|
78
|
-
* - `Optional` support nesting, and allow for the type to still be nullable (or
|
|
79
|
-
* another `Optional`)
|
|
80
|
-
* - There is no option to turn off strict-optional-checks like there is for
|
|
81
|
-
* strict-null-checks
|
|
82
|
-
*/
|
|
83
61
|
class Optional {
|
|
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
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
return this.tag && predicate(this.value);
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* For a given predicate, this function finds out if **all** the values inside
|
|
177
|
-
* this `Optional` object meet the predicate. In practice, this means that
|
|
178
|
-
* for `Optional`s that do not contain a value it returns true (as all 0
|
|
179
|
-
* objects do meet the predicate).
|
|
180
|
-
*/
|
|
181
|
-
forall(predicate) {
|
|
182
|
-
return !this.tag || predicate(this.value);
|
|
183
|
-
}
|
|
184
|
-
filter(predicate) {
|
|
185
|
-
if (!this.tag || predicate(this.value)) {
|
|
186
|
-
return this;
|
|
187
|
-
}
|
|
188
|
-
else {
|
|
189
|
-
return Optional.none();
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
// --- Getters ---
|
|
193
|
-
/**
|
|
194
|
-
* Get the value out of the inside of the `Optional` object, using a default
|
|
195
|
-
* `replacement` value if the provided `Optional` object does not contain a
|
|
196
|
-
* value.
|
|
197
|
-
*/
|
|
198
|
-
getOr(replacement) {
|
|
199
|
-
return this.tag ? this.value : replacement;
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* Get the value out of the inside of the `Optional` object, using a default
|
|
203
|
-
* `replacement` value if the provided `Optional` object does not contain a
|
|
204
|
-
* value. Unlike `getOr`, in this method the `replacement` object is also
|
|
205
|
-
* `Optional` - meaning that this method will always return an `Optional`.
|
|
206
|
-
*/
|
|
207
|
-
or(replacement) {
|
|
208
|
-
return this.tag ? this : replacement;
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* Get the value out of the inside of the `Optional` object, using a default
|
|
212
|
-
* `replacement` value if the provided `Optional` object does not contain a
|
|
213
|
-
* value. Unlike `getOr`, in this method the `replacement` value is
|
|
214
|
-
* "thunked" - that is to say that you don't pass a value to `getOrThunk`, you
|
|
215
|
-
* pass a function which (if called) will **return** the `value` you want to
|
|
216
|
-
* use.
|
|
217
|
-
*/
|
|
218
|
-
getOrThunk(thunk) {
|
|
219
|
-
return this.tag ? this.value : thunk();
|
|
220
|
-
}
|
|
221
|
-
/**
|
|
222
|
-
* Get the value out of the inside of the `Optional` object, using a default
|
|
223
|
-
* `replacement` value if the provided Optional object does not contain a
|
|
224
|
-
* value.
|
|
225
|
-
*
|
|
226
|
-
* Unlike `or`, in this method the `replacement` value is "thunked" - that is
|
|
227
|
-
* to say that you don't pass a value to `orThunk`, you pass a function which
|
|
228
|
-
* (if called) will **return** the `value` you want to use.
|
|
229
|
-
*
|
|
230
|
-
* Unlike `getOrThunk`, in this method the `replacement` value is also
|
|
231
|
-
* `Optional`, meaning that this method will always return an `Optional`.
|
|
232
|
-
*/
|
|
233
|
-
orThunk(thunk) {
|
|
234
|
-
return this.tag ? this : thunk();
|
|
235
|
-
}
|
|
236
|
-
/**
|
|
237
|
-
* Get the value out of the inside of the `Optional` object, throwing an
|
|
238
|
-
* exception if the provided `Optional` object does not contain a value.
|
|
239
|
-
*
|
|
240
|
-
* WARNING:
|
|
241
|
-
* You should only be using this function if you know that the `Optional`
|
|
242
|
-
* object **is not** empty (otherwise you're throwing exceptions in production
|
|
243
|
-
* code, which is bad).
|
|
244
|
-
*
|
|
245
|
-
* In tests this is more acceptable.
|
|
246
|
-
*
|
|
247
|
-
* Prefer other methods to this, such as `.each`.
|
|
248
|
-
*/
|
|
249
|
-
getOrDie(message) {
|
|
250
|
-
if (!this.tag) {
|
|
251
|
-
throw new Error(message !== null && message !== void 0 ? message : 'Called getOrDie on None');
|
|
252
|
-
}
|
|
253
|
-
else {
|
|
254
|
-
return this.value;
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
// --- Interop with null and undefined ---
|
|
258
|
-
/**
|
|
259
|
-
* Creates an `Optional` value from a nullable (or undefined-able) input.
|
|
260
|
-
* Null, or undefined, is converted to `None`, and anything else is converted
|
|
261
|
-
* to `Some`.
|
|
262
|
-
*/
|
|
263
|
-
static from(value) {
|
|
264
|
-
return isNonNullable(value) ? Optional.some(value) : Optional.none();
|
|
265
|
-
}
|
|
266
|
-
/**
|
|
267
|
-
* Converts an `Optional` to a nullable type, by getting the value if it
|
|
268
|
-
* exists, or returning `null` if it does not.
|
|
269
|
-
*/
|
|
270
|
-
getOrNull() {
|
|
271
|
-
return this.tag ? this.value : null;
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* Converts an `Optional` to an undefined-able type, by getting the value if
|
|
275
|
-
* it exists, or returning `undefined` if it does not.
|
|
276
|
-
*/
|
|
277
|
-
getOrUndefined() {
|
|
278
|
-
return this.value;
|
|
279
|
-
}
|
|
280
|
-
// --- Utilities ---
|
|
281
|
-
/**
|
|
282
|
-
* If the `Optional` contains a value, perform an action on that value.
|
|
283
|
-
* Unlike the rest of the methods on this type, `.each` has side-effects. If
|
|
284
|
-
* you want to transform an `Optional<T>` **into** something, then this is not
|
|
285
|
-
* the method for you. If you want to use an `Optional<T>` to **do**
|
|
286
|
-
* something, then this is the method for you - provided you're okay with not
|
|
287
|
-
* doing anything in the case where the `Optional` doesn't have a value inside
|
|
288
|
-
* it. If you're not sure whether your use-case fits into transforming
|
|
289
|
-
* **into** something or **doing** something, check whether it has a return
|
|
290
|
-
* value. If it does, you should be performing a transform.
|
|
291
|
-
*/
|
|
292
|
-
each(worker) {
|
|
293
|
-
if (this.tag) {
|
|
294
|
-
worker(this.value);
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
/**
|
|
298
|
-
* Turn the `Optional` object into an array that contains all of the values
|
|
299
|
-
* stored inside the `Optional`. In practice, this means the output will have
|
|
300
|
-
* either 0 or 1 elements.
|
|
301
|
-
*/
|
|
302
|
-
toArray() {
|
|
303
|
-
return this.tag ? [this.value] : [];
|
|
304
|
-
}
|
|
305
|
-
/**
|
|
306
|
-
* Turn the `Optional` object into a string for debugging or printing. Not
|
|
307
|
-
* recommended for production code, but good for debugging. Also note that
|
|
308
|
-
* these days an `Optional` object can be logged to the console directly, and
|
|
309
|
-
* its inner value (if it exists) will be visible.
|
|
310
|
-
*/
|
|
311
|
-
toString() {
|
|
312
|
-
return this.tag ? `some(${this.value})` : 'none()';
|
|
313
|
-
}
|
|
62
|
+
constructor(tag, value) {
|
|
63
|
+
this.tag = tag;
|
|
64
|
+
this.value = value;
|
|
65
|
+
}
|
|
66
|
+
static some(value) {
|
|
67
|
+
return new Optional(true, value);
|
|
68
|
+
}
|
|
69
|
+
static none() {
|
|
70
|
+
return Optional.singletonNone;
|
|
71
|
+
}
|
|
72
|
+
fold(onNone, onSome) {
|
|
73
|
+
if (this.tag) {
|
|
74
|
+
return onSome(this.value);
|
|
75
|
+
} else {
|
|
76
|
+
return onNone();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
isSome() {
|
|
80
|
+
return this.tag;
|
|
81
|
+
}
|
|
82
|
+
isNone() {
|
|
83
|
+
return !this.tag;
|
|
84
|
+
}
|
|
85
|
+
map(mapper) {
|
|
86
|
+
if (this.tag) {
|
|
87
|
+
return Optional.some(mapper(this.value));
|
|
88
|
+
} else {
|
|
89
|
+
return Optional.none();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
bind(binder) {
|
|
93
|
+
if (this.tag) {
|
|
94
|
+
return binder(this.value);
|
|
95
|
+
} else {
|
|
96
|
+
return Optional.none();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
exists(predicate) {
|
|
100
|
+
return this.tag && predicate(this.value);
|
|
101
|
+
}
|
|
102
|
+
forall(predicate) {
|
|
103
|
+
return !this.tag || predicate(this.value);
|
|
104
|
+
}
|
|
105
|
+
filter(predicate) {
|
|
106
|
+
if (!this.tag || predicate(this.value)) {
|
|
107
|
+
return this;
|
|
108
|
+
} else {
|
|
109
|
+
return Optional.none();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
getOr(replacement) {
|
|
113
|
+
return this.tag ? this.value : replacement;
|
|
114
|
+
}
|
|
115
|
+
or(replacement) {
|
|
116
|
+
return this.tag ? this : replacement;
|
|
117
|
+
}
|
|
118
|
+
getOrThunk(thunk) {
|
|
119
|
+
return this.tag ? this.value : thunk();
|
|
120
|
+
}
|
|
121
|
+
orThunk(thunk) {
|
|
122
|
+
return this.tag ? this : thunk();
|
|
123
|
+
}
|
|
124
|
+
getOrDie(message) {
|
|
125
|
+
if (!this.tag) {
|
|
126
|
+
throw new Error(message !== null && message !== void 0 ? message : 'Called getOrDie on None');
|
|
127
|
+
} else {
|
|
128
|
+
return this.value;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
static from(value) {
|
|
132
|
+
return isNonNullable(value) ? Optional.some(value) : Optional.none();
|
|
133
|
+
}
|
|
134
|
+
getOrNull() {
|
|
135
|
+
return this.tag ? this.value : null;
|
|
136
|
+
}
|
|
137
|
+
getOrUndefined() {
|
|
138
|
+
return this.value;
|
|
139
|
+
}
|
|
140
|
+
each(worker) {
|
|
141
|
+
if (this.tag) {
|
|
142
|
+
worker(this.value);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
toArray() {
|
|
146
|
+
return this.tag ? [this.value] : [];
|
|
147
|
+
}
|
|
148
|
+
toString() {
|
|
149
|
+
return this.tag ? `some(${ this.value })` : 'none()';
|
|
150
|
+
}
|
|
314
151
|
}
|
|
315
|
-
// Sneaky optimisation: every instance of Optional.none is identical, so just
|
|
316
|
-
// reuse the same object
|
|
317
152
|
Optional.singletonNone = new Optional(false);
|
|
318
153
|
|
|
319
|
-
/* eslint-disable @typescript-eslint/unbound-method */
|
|
320
154
|
const nativeSlice = Array.prototype.slice;
|
|
321
155
|
const nativeIndexOf = Array.prototype.indexOf;
|
|
322
156
|
const nativePush = Array.prototype.push;
|
|
323
|
-
/* eslint-enable */
|
|
324
157
|
const rawIndexOf = (ts, t) => nativeIndexOf.call(ts, t);
|
|
325
158
|
const contains$1 = (xs, x) => rawIndexOf(xs, x) > -1;
|
|
326
159
|
const exists = (xs, pred) => {
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
}
|
|
160
|
+
for (let i = 0, len = xs.length; i < len; i++) {
|
|
161
|
+
const x = xs[i];
|
|
162
|
+
if (pred(x, i)) {
|
|
163
|
+
return true;
|
|
332
164
|
}
|
|
333
|
-
|
|
165
|
+
}
|
|
166
|
+
return false;
|
|
334
167
|
};
|
|
335
168
|
const map = (xs, f) => {
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
const
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
}
|
|
344
|
-
return r;
|
|
169
|
+
const len = xs.length;
|
|
170
|
+
const r = new Array(len);
|
|
171
|
+
for (let i = 0; i < len; i++) {
|
|
172
|
+
const x = xs[i];
|
|
173
|
+
r[i] = f(x, i);
|
|
174
|
+
}
|
|
175
|
+
return r;
|
|
345
176
|
};
|
|
346
|
-
// Unwound implementing other functions in terms of each.
|
|
347
|
-
// The code size is roughly the same, and it should allow for better optimisation.
|
|
348
|
-
// const each = function<T, U>(xs: T[], f: (x: T, i?: number, xs?: T[]) => void): void {
|
|
349
177
|
const each$1 = (xs, f) => {
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
178
|
+
for (let i = 0, len = xs.length; i < len; i++) {
|
|
179
|
+
const x = xs[i];
|
|
180
|
+
f(x, i);
|
|
181
|
+
}
|
|
354
182
|
};
|
|
355
183
|
const filter$1 = (xs, pred) => {
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
}
|
|
184
|
+
const r = [];
|
|
185
|
+
for (let i = 0, len = xs.length; i < len; i++) {
|
|
186
|
+
const x = xs[i];
|
|
187
|
+
if (pred(x, i)) {
|
|
188
|
+
r.push(x);
|
|
362
189
|
}
|
|
363
|
-
|
|
190
|
+
}
|
|
191
|
+
return r;
|
|
364
192
|
};
|
|
365
|
-
/*
|
|
366
|
-
* Groups an array into contiguous arrays of like elements. Whether an element is like or not depends on f.
|
|
367
|
-
*
|
|
368
|
-
* f is a function that derives a value from an element - e.g. true or false, or a string.
|
|
369
|
-
* Elements are like if this function generates the same value for them (according to ===).
|
|
370
|
-
*
|
|
371
|
-
*
|
|
372
|
-
* Order of the elements is preserved. Arr.flatten() on the result will return the original list, as with Haskell groupBy function.
|
|
373
|
-
* For a good explanation, see the group function (which is a special case of groupBy)
|
|
374
|
-
* http://hackage.haskell.org/package/base-4.7.0.0/docs/Data-List.html#v:group
|
|
375
|
-
*/
|
|
376
193
|
const groupBy = (xs, f) => {
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
r.push(group);
|
|
396
|
-
}
|
|
397
|
-
return r;
|
|
194
|
+
if (xs.length === 0) {
|
|
195
|
+
return [];
|
|
196
|
+
} else {
|
|
197
|
+
let wasType = f(xs[0]);
|
|
198
|
+
const r = [];
|
|
199
|
+
let group = [];
|
|
200
|
+
for (let i = 0, len = xs.length; i < len; i++) {
|
|
201
|
+
const x = xs[i];
|
|
202
|
+
const type = f(x);
|
|
203
|
+
if (type !== wasType) {
|
|
204
|
+
r.push(group);
|
|
205
|
+
group = [];
|
|
206
|
+
}
|
|
207
|
+
wasType = type;
|
|
208
|
+
group.push(x);
|
|
209
|
+
}
|
|
210
|
+
if (group.length !== 0) {
|
|
211
|
+
r.push(group);
|
|
398
212
|
}
|
|
213
|
+
return r;
|
|
214
|
+
}
|
|
399
215
|
};
|
|
400
216
|
const foldl = (xs, f, acc) => {
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
217
|
+
each$1(xs, (x, i) => {
|
|
218
|
+
acc = f(acc, x, i);
|
|
219
|
+
});
|
|
220
|
+
return acc;
|
|
405
221
|
};
|
|
406
222
|
const findUntil = (xs, pred, until) => {
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
break;
|
|
414
|
-
}
|
|
223
|
+
for (let i = 0, len = xs.length; i < len; i++) {
|
|
224
|
+
const x = xs[i];
|
|
225
|
+
if (pred(x, i)) {
|
|
226
|
+
return Optional.some(x);
|
|
227
|
+
} else if (until(x, i)) {
|
|
228
|
+
break;
|
|
415
229
|
}
|
|
416
|
-
|
|
230
|
+
}
|
|
231
|
+
return Optional.none();
|
|
417
232
|
};
|
|
418
233
|
const find = (xs, pred) => {
|
|
419
|
-
|
|
234
|
+
return findUntil(xs, pred, never);
|
|
420
235
|
};
|
|
421
|
-
const flatten =
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
const r = [];
|
|
427
|
-
for (let i = 0, len = xs.length; i < len; ++i) {
|
|
428
|
-
// Ensure that each value is an array itself
|
|
429
|
-
if (!isArray(xs[i])) {
|
|
430
|
-
throw new Error('Arr.flatten item ' + i + ' was not an array, input: ' + xs);
|
|
431
|
-
}
|
|
432
|
-
nativePush.apply(r, xs[i]);
|
|
236
|
+
const flatten = xs => {
|
|
237
|
+
const r = [];
|
|
238
|
+
for (let i = 0, len = xs.length; i < len; ++i) {
|
|
239
|
+
if (!isArray(xs[i])) {
|
|
240
|
+
throw new Error('Arr.flatten item ' + i + ' was not an array, input: ' + xs);
|
|
433
241
|
}
|
|
434
|
-
|
|
242
|
+
nativePush.apply(r, xs[i]);
|
|
243
|
+
}
|
|
244
|
+
return r;
|
|
435
245
|
};
|
|
436
246
|
const bind = (xs, f) => flatten(map(xs, f));
|
|
437
|
-
const reverse =
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
247
|
+
const reverse = xs => {
|
|
248
|
+
const r = nativeSlice.call(xs, 0);
|
|
249
|
+
r.reverse();
|
|
250
|
+
return r;
|
|
441
251
|
};
|
|
442
252
|
const get$1 = (xs, i) => i >= 0 && i < xs.length ? Optional.some(xs[i]) : Optional.none();
|
|
443
|
-
const head =
|
|
444
|
-
const last =
|
|
253
|
+
const head = xs => get$1(xs, 0);
|
|
254
|
+
const last = xs => get$1(xs, xs.length - 1);
|
|
445
255
|
const unique = (xs, comparator) => {
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
if (!isDuplicated(x)) {
|
|
453
|
-
r.push(x);
|
|
454
|
-
}
|
|
256
|
+
const r = [];
|
|
257
|
+
const isDuplicated = isFunction(comparator) ? x => exists(r, i => comparator(i, x)) : x => contains$1(r, x);
|
|
258
|
+
for (let i = 0, len = xs.length; i < len; i++) {
|
|
259
|
+
const x = xs[i];
|
|
260
|
+
if (!isDuplicated(x)) {
|
|
261
|
+
r.push(x);
|
|
455
262
|
}
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
// There are many variations of Object iteration that are faster than the 'for-in' style:
|
|
460
|
-
// http://jsperf.com/object-keys-iteration/107
|
|
461
|
-
//
|
|
462
|
-
// Use the native keys if it is available (IE9+), otherwise fall back to manually filtering
|
|
463
|
-
const keys = Object.keys;
|
|
464
|
-
const each = (obj, f) => {
|
|
465
|
-
const props = keys(obj);
|
|
466
|
-
for (let k = 0, len = props.length; k < len; k++) {
|
|
467
|
-
const i = props[k];
|
|
468
|
-
const x = obj[i];
|
|
469
|
-
f(x, i);
|
|
470
|
-
}
|
|
471
|
-
};
|
|
472
|
-
const objAcc = (r) => (x, i) => {
|
|
473
|
-
r[i] = x;
|
|
474
|
-
};
|
|
475
|
-
const internalFilter = (obj, pred, onTrue, onFalse) => {
|
|
476
|
-
each(obj, (x, i) => {
|
|
477
|
-
(pred(x, i) ? onTrue : onFalse)(x, i);
|
|
478
|
-
});
|
|
479
|
-
};
|
|
480
|
-
const filter = (obj, pred) => {
|
|
481
|
-
const t = {};
|
|
482
|
-
internalFilter(obj, pred, objAcc(t), noop);
|
|
483
|
-
return t;
|
|
263
|
+
}
|
|
264
|
+
return r;
|
|
484
265
|
};
|
|
485
266
|
|
|
486
|
-
const
|
|
487
|
-
let value = initial;
|
|
488
|
-
const get = () => {
|
|
489
|
-
return value;
|
|
490
|
-
};
|
|
491
|
-
const set = (v) => {
|
|
492
|
-
value = v;
|
|
493
|
-
};
|
|
494
|
-
return {
|
|
495
|
-
get,
|
|
496
|
-
set
|
|
497
|
-
};
|
|
498
|
-
};
|
|
499
|
-
|
|
500
|
-
// Use window object as the global if it's available since CSP will block script evals
|
|
501
|
-
// eslint-disable-next-line @typescript-eslint/no-implied-eval
|
|
502
|
-
const Global = typeof window !== 'undefined' ? window : Function('return this;')();
|
|
503
|
-
|
|
504
|
-
/**
|
|
505
|
-
* **Is** the value stored inside this Optional object equal to `rhs`?
|
|
506
|
-
*/
|
|
507
|
-
const is$2 = (lhs, rhs, comparator = tripleEquals) => lhs.exists((left) => comparator(left, rhs));
|
|
508
|
-
/**
|
|
509
|
-
* Are these two Optional objects equal? Equality here means either they're both
|
|
510
|
-
* `Some` (and the values are equal under the comparator) or they're both `None`.
|
|
511
|
-
*/
|
|
267
|
+
const is$2 = (lhs, rhs, comparator = tripleEquals) => lhs.exists(left => comparator(left, rhs));
|
|
512
268
|
const equals = (lhs, rhs, comparator = tripleEquals) => lift2(lhs, rhs, comparator).getOr(lhs.isNone() && rhs.isNone());
|
|
513
|
-
/*
|
|
514
|
-
Notes on the lift functions:
|
|
515
|
-
- We used to have a generic liftN, but we were concerned about its type-safety, and the below variants were faster in microbenchmarks.
|
|
516
|
-
- The getOrDie calls are partial functions, but are checked beforehand. This is faster and more convenient (but less safe) than folds.
|
|
517
|
-
- && is used instead of a loop for simplicity and performance.
|
|
518
|
-
*/
|
|
519
269
|
const lift2 = (oa, ob, f) => oa.isSome() && ob.isSome() ? Optional.some(f(oa.getOrDie(), ob.getOrDie())) : Optional.none();
|
|
520
270
|
|
|
521
|
-
|
|
522
|
-
const
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
}
|
|
527
|
-
return o;
|
|
528
|
-
};
|
|
529
|
-
/** resolve :: (String, JsObj?) -> JsObj */
|
|
530
|
-
const resolve = (p, scope) => {
|
|
531
|
-
const parts = p.split('.');
|
|
532
|
-
return path(parts, scope);
|
|
533
|
-
};
|
|
534
|
-
|
|
535
|
-
const blank = (r) => (s) => s.replace(r, '');
|
|
536
|
-
/** removes all leading and trailing spaces */
|
|
537
|
-
const trim = blank(/^\s+|\s+$/g);
|
|
538
|
-
const isNotEmpty = (s) => s.length > 0;
|
|
539
|
-
const isEmpty$2 = (s) => !isNotEmpty(s);
|
|
540
|
-
|
|
541
|
-
const zeroWidth = '\uFEFF';
|
|
542
|
-
const isZwsp = (char) => char === zeroWidth;
|
|
271
|
+
const COMMENT = 8;
|
|
272
|
+
const DOCUMENT = 9;
|
|
273
|
+
const DOCUMENT_FRAGMENT = 11;
|
|
274
|
+
const ELEMENT = 1;
|
|
275
|
+
const TEXT = 3;
|
|
543
276
|
|
|
544
277
|
const fromHtml = (html, scope) => {
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
return fromDom$1(div.childNodes[0]);
|
|
278
|
+
const doc = scope || document;
|
|
279
|
+
const div = doc.createElement('div');
|
|
280
|
+
div.innerHTML = html;
|
|
281
|
+
if (!div.hasChildNodes() || div.childNodes.length > 1) {
|
|
282
|
+
const message = 'HTML does not have a single root node';
|
|
283
|
+
console.error(message, html);
|
|
284
|
+
throw new Error(message);
|
|
285
|
+
}
|
|
286
|
+
return fromDom$1(div.childNodes[0]);
|
|
555
287
|
};
|
|
556
288
|
const fromTag = (tag, scope) => {
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
289
|
+
const doc = scope || document;
|
|
290
|
+
const node = doc.createElement(tag);
|
|
291
|
+
return fromDom$1(node);
|
|
560
292
|
};
|
|
561
293
|
const fromText = (text, scope) => {
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
294
|
+
const doc = scope || document;
|
|
295
|
+
const node = doc.createTextNode(text);
|
|
296
|
+
return fromDom$1(node);
|
|
565
297
|
};
|
|
566
|
-
const fromDom$1 =
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
return {
|
|
572
|
-
dom: node
|
|
573
|
-
};
|
|
298
|
+
const fromDom$1 = node => {
|
|
299
|
+
if (node === null || node === undefined) {
|
|
300
|
+
throw new Error('Node cannot be null or undefined');
|
|
301
|
+
}
|
|
302
|
+
return { dom: node };
|
|
574
303
|
};
|
|
575
304
|
const fromPoint = (docElm, x, y) => Optional.from(docElm.dom.elementFromPoint(x, y)).map(fromDom$1);
|
|
576
|
-
// tslint:disable-next-line:variable-name
|
|
577
305
|
const SugarElement = {
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
306
|
+
fromHtml,
|
|
307
|
+
fromTag,
|
|
308
|
+
fromText,
|
|
309
|
+
fromDom: fromDom$1,
|
|
310
|
+
fromPoint
|
|
583
311
|
};
|
|
584
312
|
|
|
585
|
-
const COMMENT = 8;
|
|
586
|
-
const DOCUMENT_FRAGMENT = 11;
|
|
587
|
-
const ELEMENT = 1;
|
|
588
|
-
const TEXT = 3;
|
|
589
|
-
|
|
590
313
|
const is$1 = (element, selector) => {
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
return elem.mozMatchesSelector(selector);
|
|
609
|
-
}
|
|
610
|
-
else {
|
|
611
|
-
throw new Error('Browser lacks native selectors');
|
|
612
|
-
} // unfortunately we can't throw this on startup :(
|
|
613
|
-
}
|
|
314
|
+
const dom = element.dom;
|
|
315
|
+
if (dom.nodeType !== ELEMENT) {
|
|
316
|
+
return false;
|
|
317
|
+
} else {
|
|
318
|
+
const elem = dom;
|
|
319
|
+
if (elem.matches !== undefined) {
|
|
320
|
+
return elem.matches(selector);
|
|
321
|
+
} else if (elem.msMatchesSelector !== undefined) {
|
|
322
|
+
return elem.msMatchesSelector(selector);
|
|
323
|
+
} else if (elem.webkitMatchesSelector !== undefined) {
|
|
324
|
+
return elem.webkitMatchesSelector(selector);
|
|
325
|
+
} else if (elem.mozMatchesSelector !== undefined) {
|
|
326
|
+
return elem.mozMatchesSelector(selector);
|
|
327
|
+
} else {
|
|
328
|
+
throw new Error('Browser lacks native selectors');
|
|
329
|
+
}
|
|
330
|
+
}
|
|
614
331
|
};
|
|
615
332
|
|
|
616
333
|
const eq = (e1, e2) => e1.dom === e2.dom;
|
|
617
|
-
// Returns: true if node e1 contains e2, otherwise false.
|
|
618
|
-
// (returns false if e1===e2: A node does not contain itself).
|
|
619
334
|
const contains = (e1, e2) => {
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
335
|
+
const d1 = e1.dom;
|
|
336
|
+
const d2 = e2.dom;
|
|
337
|
+
return d1 === d2 ? false : d1.contains(d2);
|
|
623
338
|
};
|
|
624
339
|
const is = is$1;
|
|
625
340
|
|
|
341
|
+
const Global = typeof window !== 'undefined' ? window : Function('return this;')();
|
|
342
|
+
|
|
343
|
+
const path = (parts, scope) => {
|
|
344
|
+
let o = scope !== undefined && scope !== null ? scope : Global;
|
|
345
|
+
for (let i = 0; i < parts.length && o !== undefined && o !== null; ++i) {
|
|
346
|
+
o = o[parts[i]];
|
|
347
|
+
}
|
|
348
|
+
return o;
|
|
349
|
+
};
|
|
350
|
+
const resolve = (p, scope) => {
|
|
351
|
+
const parts = p.split('.');
|
|
352
|
+
return path(parts, scope);
|
|
353
|
+
};
|
|
354
|
+
|
|
626
355
|
const unsafe = (name, scope) => {
|
|
627
|
-
|
|
356
|
+
return resolve(name, scope);
|
|
628
357
|
};
|
|
629
358
|
const getOrDie = (name, scope) => {
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
359
|
+
const actual = unsafe(name, scope);
|
|
360
|
+
if (actual === undefined || actual === null) {
|
|
361
|
+
throw new Error(name + ' not available on this browser');
|
|
362
|
+
}
|
|
363
|
+
return actual;
|
|
635
364
|
};
|
|
636
365
|
|
|
637
366
|
const getPrototypeOf = Object.getPrototypeOf;
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
};
|
|
655
|
-
|
|
656
|
-
const name = (element) => {
|
|
657
|
-
const r = element.dom.nodeName;
|
|
658
|
-
return r.toLowerCase();
|
|
659
|
-
};
|
|
660
|
-
const type = (element) => element.dom.nodeType;
|
|
661
|
-
const isType = (t) => (element) => type(element) === t;
|
|
662
|
-
const isComment = (element) => type(element) === COMMENT || name(element) === '#comment';
|
|
663
|
-
const isHTMLElement = (element) => isElement$1(element) && isPrototypeOf(element.dom);
|
|
367
|
+
const sandHTMLElement = scope => {
|
|
368
|
+
return getOrDie('HTMLElement', scope);
|
|
369
|
+
};
|
|
370
|
+
const isPrototypeOf = x => {
|
|
371
|
+
const scope = resolve('ownerDocument.defaultView', x);
|
|
372
|
+
return isObject(x) && (sandHTMLElement(scope).prototype.isPrototypeOf(x) || /^HTML\w*Element$/.test(getPrototypeOf(x).constructor.name));
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
const name = element => {
|
|
376
|
+
const r = element.dom.nodeName;
|
|
377
|
+
return r.toLowerCase();
|
|
378
|
+
};
|
|
379
|
+
const type = element => element.dom.nodeType;
|
|
380
|
+
const isType = t => element => type(element) === t;
|
|
381
|
+
const isComment = element => type(element) === COMMENT || name(element) === '#comment';
|
|
382
|
+
const isHTMLElement = element => isElement$1(element) && isPrototypeOf(element.dom);
|
|
664
383
|
const isElement$1 = isType(ELEMENT);
|
|
665
384
|
const isText = isType(TEXT);
|
|
385
|
+
const isDocument = isType(DOCUMENT);
|
|
666
386
|
const isDocumentFragment = isType(DOCUMENT_FRAGMENT);
|
|
667
|
-
const isTag =
|
|
668
|
-
|
|
669
|
-
const
|
|
670
|
-
const
|
|
671
|
-
const
|
|
672
|
-
const
|
|
387
|
+
const isTag = tag => e => isElement$1(e) && name(e) === tag;
|
|
388
|
+
|
|
389
|
+
const owner = element => SugarElement.fromDom(element.dom.ownerDocument);
|
|
390
|
+
const documentOrOwner = dos => isDocument(dos) ? dos : owner(dos);
|
|
391
|
+
const parent = element => Optional.from(element.dom.parentNode).map(SugarElement.fromDom);
|
|
392
|
+
const parentElement = element => Optional.from(element.dom.parentElement).map(SugarElement.fromDom);
|
|
393
|
+
const nextSibling = element => Optional.from(element.dom.nextSibling).map(SugarElement.fromDom);
|
|
394
|
+
const children = element => map(element.dom.childNodes, SugarElement.fromDom);
|
|
673
395
|
const child = (element, index) => {
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
};
|
|
677
|
-
const firstChild =
|
|
678
|
-
const lastChild =
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
const
|
|
688
|
-
|
|
689
|
-
const
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
396
|
+
const cs = element.dom.childNodes;
|
|
397
|
+
return Optional.from(cs[index]).map(SugarElement.fromDom);
|
|
398
|
+
};
|
|
399
|
+
const firstChild = element => child(element, 0);
|
|
400
|
+
const lastChild = element => child(element, element.dom.childNodes.length - 1);
|
|
401
|
+
|
|
402
|
+
const isShadowRoot = dos => isDocumentFragment(dos) && isNonNullable(dos.dom.host);
|
|
403
|
+
const supported = isFunction(Element.prototype.attachShadow) && isFunction(Node.prototype.getRootNode);
|
|
404
|
+
const getRootNode = supported ? e => SugarElement.fromDom(e.dom.getRootNode()) : documentOrOwner;
|
|
405
|
+
const getShadowRoot = e => {
|
|
406
|
+
const r = getRootNode(e);
|
|
407
|
+
return isShadowRoot(r) ? Optional.some(r) : Optional.none();
|
|
408
|
+
};
|
|
409
|
+
const getShadowHost = e => SugarElement.fromDom(e.dom.host);
|
|
410
|
+
|
|
411
|
+
const inBody = element => {
|
|
412
|
+
const dom = isText(element) ? element.dom.parentNode : element.dom;
|
|
413
|
+
if (dom === undefined || dom === null || dom.ownerDocument === null) {
|
|
414
|
+
return false;
|
|
415
|
+
}
|
|
416
|
+
const doc = dom.ownerDocument;
|
|
417
|
+
return getShadowRoot(SugarElement.fromDom(dom)).fold(() => doc.body.contains(dom), compose1(inBody, getShadowHost));
|
|
418
|
+
};
|
|
419
|
+
|
|
420
|
+
var ClosestOrAncestor = (is, ancestor, scope, a, isRoot) => {
|
|
421
|
+
if (is(scope, a)) {
|
|
422
|
+
return Optional.some(scope);
|
|
423
|
+
} else if (isFunction(isRoot) && isRoot(scope)) {
|
|
424
|
+
return Optional.none();
|
|
425
|
+
} else {
|
|
426
|
+
return ancestor(scope, a, isRoot);
|
|
427
|
+
}
|
|
428
|
+
};
|
|
429
|
+
|
|
430
|
+
const ancestor$3 = (scope, predicate, isRoot) => {
|
|
431
|
+
let element = scope.dom;
|
|
432
|
+
const stop = isFunction(isRoot) ? isRoot : never;
|
|
433
|
+
while (element.parentNode) {
|
|
434
|
+
element = element.parentNode;
|
|
435
|
+
const el = SugarElement.fromDom(element);
|
|
436
|
+
if (predicate(el)) {
|
|
437
|
+
return Optional.some(el);
|
|
438
|
+
} else if (stop(el)) {
|
|
439
|
+
break;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
return Optional.none();
|
|
443
|
+
};
|
|
444
|
+
const closest$2 = (scope, predicate, isRoot) => {
|
|
445
|
+
const is = (s, test) => test(s);
|
|
446
|
+
return ClosestOrAncestor(is, ancestor$3, scope, predicate, isRoot);
|
|
447
|
+
};
|
|
448
|
+
|
|
449
|
+
const ancestor$2 = (scope, selector, isRoot) => ancestor$3(scope, e => is$1(e, selector), isRoot);
|
|
450
|
+
const closest$1 = (scope, selector, isRoot) => {
|
|
451
|
+
const is = (element, selector) => is$1(element, selector);
|
|
452
|
+
return ClosestOrAncestor(is, ancestor$2, scope, selector, isRoot);
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
const closest = target => closest$1(target, '[contenteditable]');
|
|
456
|
+
const isEditable = (element, assumeEditable = false) => {
|
|
457
|
+
if (inBody(element)) {
|
|
458
|
+
return element.dom.isContentEditable;
|
|
459
|
+
} else {
|
|
460
|
+
return closest(element).fold(constant(assumeEditable), editable => getRaw(editable) === 'true');
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
const getRaw = element => element.dom.contentEditable;
|
|
699
464
|
|
|
700
465
|
const before$1 = (marker, element) => {
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
466
|
+
const parent$1 = parent(marker);
|
|
467
|
+
parent$1.each(v => {
|
|
468
|
+
v.dom.insertBefore(element.dom, marker.dom);
|
|
469
|
+
});
|
|
705
470
|
};
|
|
706
471
|
const after = (marker, element) => {
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
});
|
|
713
|
-
}, (v) => {
|
|
714
|
-
before$1(v, element);
|
|
472
|
+
const sibling = nextSibling(marker);
|
|
473
|
+
sibling.fold(() => {
|
|
474
|
+
const parent$1 = parent(marker);
|
|
475
|
+
parent$1.each(v => {
|
|
476
|
+
append$1(v, element);
|
|
715
477
|
});
|
|
478
|
+
}, v => {
|
|
479
|
+
before$1(v, element);
|
|
480
|
+
});
|
|
716
481
|
};
|
|
717
482
|
const prepend = (parent, element) => {
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
483
|
+
const firstChild$1 = firstChild(parent);
|
|
484
|
+
firstChild$1.fold(() => {
|
|
485
|
+
append$1(parent, element);
|
|
486
|
+
}, v => {
|
|
487
|
+
parent.dom.insertBefore(element.dom, v.dom);
|
|
488
|
+
});
|
|
724
489
|
};
|
|
725
490
|
const append$1 = (parent, element) => {
|
|
726
|
-
|
|
491
|
+
parent.dom.appendChild(element.dom);
|
|
727
492
|
};
|
|
728
493
|
|
|
729
494
|
const before = (marker, elements) => {
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
495
|
+
each$1(elements, x => {
|
|
496
|
+
before$1(marker, x);
|
|
497
|
+
});
|
|
733
498
|
};
|
|
734
499
|
const append = (parent, elements) => {
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
500
|
+
each$1(elements, x => {
|
|
501
|
+
append$1(parent, x);
|
|
502
|
+
});
|
|
738
503
|
};
|
|
739
504
|
|
|
740
|
-
const
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
*/
|
|
746
|
-
if (isString(value) || isBoolean(value) || isNumber(value)) {
|
|
747
|
-
dom.setAttribute(key, value + '');
|
|
748
|
-
}
|
|
749
|
-
else {
|
|
750
|
-
// eslint-disable-next-line no-console
|
|
751
|
-
console.error('Invalid call to Attribute.set. Key ', key, ':: Value ', value, ':: Element ', dom);
|
|
752
|
-
throw new Error('Attribute value was not simple');
|
|
753
|
-
}
|
|
505
|
+
const empty = element => {
|
|
506
|
+
element.dom.textContent = '';
|
|
507
|
+
each$1(children(element), rogue => {
|
|
508
|
+
remove(rogue);
|
|
509
|
+
});
|
|
754
510
|
};
|
|
755
|
-
const
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
511
|
+
const remove = element => {
|
|
512
|
+
const dom = element.dom;
|
|
513
|
+
if (dom.parentNode !== null) {
|
|
514
|
+
dom.parentNode.removeChild(dom);
|
|
515
|
+
}
|
|
760
516
|
};
|
|
761
|
-
const clone$1 = (element) => foldl(element.dom.attributes, (acc, attr) => {
|
|
762
|
-
acc[attr.name] = attr.value;
|
|
763
|
-
return acc;
|
|
764
|
-
}, {});
|
|
765
517
|
|
|
766
|
-
|
|
767
|
-
// shortcut "empty node" trick. Requires IE 9.
|
|
768
|
-
element.dom.textContent = '';
|
|
769
|
-
// If the contents was a single empty text node, the above doesn't remove it. But, it's still faster in general
|
|
770
|
-
// than removing every child node manually.
|
|
771
|
-
// The following is (probably) safe for performance as 99.9% of the time the trick works and
|
|
772
|
-
// Traverse.children will return an empty array.
|
|
773
|
-
each$1(children(element), (rogue) => {
|
|
774
|
-
remove(rogue);
|
|
775
|
-
});
|
|
776
|
-
};
|
|
777
|
-
const remove = (element) => {
|
|
778
|
-
const dom = element.dom;
|
|
779
|
-
if (dom.parentNode !== null) {
|
|
780
|
-
dom.parentNode.removeChild(dom);
|
|
781
|
-
}
|
|
782
|
-
};
|
|
518
|
+
var global$6 = tinymce.util.Tools.resolve('tinymce.dom.RangeUtils');
|
|
783
519
|
|
|
784
|
-
|
|
785
|
-
/** Deep clone - everything copied including children */
|
|
786
|
-
const deep = (original) => clone(original, true);
|
|
787
|
-
/** Shallow clone, with a new tag */
|
|
788
|
-
const shallowAs = (original, tag) => {
|
|
789
|
-
const nu = SugarElement.fromTag(tag);
|
|
790
|
-
const attributes = clone$1(original);
|
|
791
|
-
setAll(nu, attributes);
|
|
792
|
-
return nu;
|
|
793
|
-
};
|
|
794
|
-
/** Change the tag name, but keep all children */
|
|
795
|
-
const mutate = (original, tag) => {
|
|
796
|
-
const nu = shallowAs(original, tag);
|
|
797
|
-
after(original, nu);
|
|
798
|
-
const children$1 = children(original);
|
|
799
|
-
append(nu, children$1);
|
|
800
|
-
remove(original);
|
|
801
|
-
return nu;
|
|
802
|
-
};
|
|
803
|
-
|
|
804
|
-
const fromDom = (nodes) => map(nodes, SugarElement.fromDom);
|
|
805
|
-
|
|
806
|
-
// some elements, such as mathml, don't have style attributes
|
|
807
|
-
// others, such as angular elements, have style attributes that aren't a CSSStyleDeclaration
|
|
808
|
-
const isSupported = (dom) =>
|
|
809
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
810
|
-
dom.style !== undefined && isFunction(dom.style.getPropertyValue);
|
|
811
|
-
|
|
812
|
-
// Node.contains() is very, very, very good performance
|
|
813
|
-
// http://jsperf.com/closest-vs-contains/5
|
|
814
|
-
const inBody = (element) => {
|
|
815
|
-
// Technically this is only required on IE, where contains() returns false for text nodes.
|
|
816
|
-
// But it's cheap enough to run everywhere and Sugar doesn't have platform detection (yet).
|
|
817
|
-
const dom = isText(element) ? element.dom.parentNode : element.dom;
|
|
818
|
-
// use ownerDocument.body to ensure this works inside iframes.
|
|
819
|
-
// Normally contains is bad because an element "contains" itself, but here we want that.
|
|
820
|
-
if (dom === undefined || dom === null || dom.ownerDocument === null) {
|
|
821
|
-
return false;
|
|
822
|
-
}
|
|
823
|
-
const doc = dom.ownerDocument;
|
|
824
|
-
return getShadowRoot(SugarElement.fromDom(dom)).fold(() => doc.body.contains(dom), compose1(inBody, getShadowHost));
|
|
825
|
-
};
|
|
520
|
+
var global$5 = tinymce.util.Tools.resolve('tinymce.dom.TreeWalker');
|
|
826
521
|
|
|
827
|
-
|
|
828
|
-
// This is going to hurt. Apologies.
|
|
829
|
-
// JQuery coerces numbers to pixels for certain property names, and other times lets numbers through.
|
|
830
|
-
// we're going to be explicit; strings only.
|
|
831
|
-
if (!isString(value)) {
|
|
832
|
-
// eslint-disable-next-line no-console
|
|
833
|
-
console.error('Invalid call to CSS.set. Property ', property, ':: Value ', value, ':: Element ', dom);
|
|
834
|
-
throw new Error('CSS value must be a string: ' + value);
|
|
835
|
-
}
|
|
836
|
-
// removed: support for dom().style[property] where prop is camel case instead of normal property name
|
|
837
|
-
if (isSupported(dom)) {
|
|
838
|
-
dom.style.setProperty(property, value);
|
|
839
|
-
}
|
|
840
|
-
};
|
|
841
|
-
const set = (element, property, value) => {
|
|
842
|
-
const dom = element.dom;
|
|
843
|
-
internalSet(dom, property, value);
|
|
844
|
-
};
|
|
522
|
+
var global$4 = tinymce.util.Tools.resolve('tinymce.util.VK');
|
|
845
523
|
|
|
846
|
-
const
|
|
847
|
-
const doc = scope || document;
|
|
848
|
-
const fragment = doc.createDocumentFragment();
|
|
849
|
-
each$1(elements, (element) => {
|
|
850
|
-
fragment.appendChild(element.dom);
|
|
851
|
-
});
|
|
852
|
-
return SugarElement.fromDom(fragment);
|
|
853
|
-
};
|
|
524
|
+
const fromDom = nodes => map(nodes, SugarElement.fromDom);
|
|
854
525
|
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
return ancestor(scope, a, isRoot);
|
|
864
|
-
}
|
|
526
|
+
const keys = Object.keys;
|
|
527
|
+
const each = (obj, f) => {
|
|
528
|
+
const props = keys(obj);
|
|
529
|
+
for (let k = 0, len = props.length; k < len; k++) {
|
|
530
|
+
const i = props[k];
|
|
531
|
+
const x = obj[i];
|
|
532
|
+
f(x, i);
|
|
533
|
+
}
|
|
865
534
|
};
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
let element = scope.dom;
|
|
869
|
-
const stop = isFunction(isRoot) ? isRoot : never;
|
|
870
|
-
while (element.parentNode) {
|
|
871
|
-
element = element.parentNode;
|
|
872
|
-
const el = SugarElement.fromDom(element);
|
|
873
|
-
if (predicate(el)) {
|
|
874
|
-
return Optional.some(el);
|
|
875
|
-
}
|
|
876
|
-
else if (stop(el)) {
|
|
877
|
-
break;
|
|
878
|
-
}
|
|
879
|
-
}
|
|
880
|
-
return Optional.none();
|
|
535
|
+
const objAcc = r => (x, i) => {
|
|
536
|
+
r[i] = x;
|
|
881
537
|
};
|
|
882
|
-
const
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
538
|
+
const internalFilter = (obj, pred, onTrue, onFalse) => {
|
|
539
|
+
each(obj, (x, i) => {
|
|
540
|
+
(pred(x, i) ? onTrue : onFalse)(x, i);
|
|
541
|
+
});
|
|
886
542
|
};
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
const is = (element, selector) => is$1(element, selector);
|
|
892
|
-
return ClosestOrAncestor(is, ancestor$2, scope, selector, isRoot);
|
|
543
|
+
const filter = (obj, pred) => {
|
|
544
|
+
const t = {};
|
|
545
|
+
internalFilter(obj, pred, objAcc(t), noop);
|
|
546
|
+
return t;
|
|
893
547
|
};
|
|
894
548
|
|
|
895
|
-
const
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
return closest(element).fold(constant(assumeEditable), (editable) => getRaw(editable) === 'true');
|
|
903
|
-
}
|
|
549
|
+
const rawSet = (dom, key, value) => {
|
|
550
|
+
if (isString(value) || isBoolean(value) || isNumber(value)) {
|
|
551
|
+
dom.setAttribute(key, value + '');
|
|
552
|
+
} else {
|
|
553
|
+
console.error('Invalid call to Attribute.set. Key ', key, ':: Value ', value, ':: Element ', dom);
|
|
554
|
+
throw new Error('Attribute value was not simple');
|
|
555
|
+
}
|
|
904
556
|
};
|
|
905
|
-
const
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
557
|
+
const setAll = (element, attrs) => {
|
|
558
|
+
const dom = element.dom;
|
|
559
|
+
each(attrs, (v, k) => {
|
|
560
|
+
rawSet(dom, k, v);
|
|
561
|
+
});
|
|
562
|
+
};
|
|
563
|
+
const clone$1 = element => foldl(element.dom.attributes, (acc, attr) => {
|
|
564
|
+
acc[attr.name] = attr.value;
|
|
565
|
+
return acc;
|
|
566
|
+
}, {});
|
|
914
567
|
|
|
915
|
-
|
|
568
|
+
const clone = (original, isDeep) => SugarElement.fromDom(original.dom.cloneNode(isDeep));
|
|
569
|
+
const deep = original => clone(original, true);
|
|
570
|
+
const shallowAs = (original, tag) => {
|
|
571
|
+
const nu = SugarElement.fromTag(tag);
|
|
572
|
+
const attributes = clone$1(original);
|
|
573
|
+
setAll(nu, attributes);
|
|
574
|
+
return nu;
|
|
575
|
+
};
|
|
576
|
+
const mutate = (original, tag) => {
|
|
577
|
+
const nu = shallowAs(original, tag);
|
|
578
|
+
after(original, nu);
|
|
579
|
+
const children$1 = children(original);
|
|
580
|
+
append(nu, children$1);
|
|
581
|
+
remove(original);
|
|
582
|
+
return nu;
|
|
583
|
+
};
|
|
916
584
|
|
|
917
585
|
var global$3 = tinymce.util.Tools.resolve('tinymce.dom.DOMUtils');
|
|
918
586
|
|
|
919
587
|
var global$2 = tinymce.util.Tools.resolve('tinymce.util.Tools');
|
|
920
588
|
|
|
921
|
-
const matchNodeName =
|
|
922
|
-
const matchNodeNames =
|
|
923
|
-
const isTextNode$1 =
|
|
924
|
-
const isElement =
|
|
589
|
+
const matchNodeName = name => node => isNonNullable(node) && node.nodeName.toLowerCase() === name;
|
|
590
|
+
const matchNodeNames = regex => node => isNonNullable(node) && regex.test(node.nodeName);
|
|
591
|
+
const isTextNode$1 = node => isNonNullable(node) && node.nodeType === 3;
|
|
592
|
+
const isElement = node => isNonNullable(node) && node.nodeType === 1;
|
|
925
593
|
const isListNode = matchNodeNames(/^(OL|UL|DL)$/);
|
|
926
594
|
const isOlUlNode = matchNodeNames(/^(OL|UL)$/);
|
|
927
595
|
const isOlNode = matchNodeName('ol');
|
|
@@ -929,1616 +597,1576 @@
|
|
|
929
597
|
const isDlItemNode = matchNodeNames(/^(DT|DD)$/);
|
|
930
598
|
const isTableCellNode = matchNodeNames(/^(TH|TD)$/);
|
|
931
599
|
const isBr = matchNodeName('br');
|
|
932
|
-
const isFirstChild =
|
|
600
|
+
const isFirstChild = node => {
|
|
601
|
+
var _a;
|
|
602
|
+
return ((_a = node.parentNode) === null || _a === void 0 ? void 0 : _a.firstChild) === node;
|
|
603
|
+
};
|
|
933
604
|
const isTextBlock = (editor, node) => isNonNullable(node) && node.nodeName in editor.schema.getTextBlockElements();
|
|
934
605
|
const isBlock = (node, blockElements) => isNonNullable(node) && node.nodeName in blockElements;
|
|
935
606
|
const isVoid = (editor, node) => isNonNullable(node) && node.nodeName in editor.schema.getVoidElements();
|
|
936
607
|
const isBogusBr = (dom, node) => {
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
608
|
+
if (!isBr(node)) {
|
|
609
|
+
return false;
|
|
610
|
+
}
|
|
611
|
+
return dom.isBlock(node.nextSibling) && !isBr(node.previousSibling);
|
|
941
612
|
};
|
|
942
|
-
const isEmpty$
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
613
|
+
const isEmpty$2 = (dom, elm, keepBookmarks) => {
|
|
614
|
+
const empty = dom.isEmpty(elm);
|
|
615
|
+
if (keepBookmarks && dom.select('span[data-mce-type=bookmark]', elm).length > 0) {
|
|
616
|
+
return false;
|
|
617
|
+
}
|
|
618
|
+
return empty;
|
|
948
619
|
};
|
|
949
620
|
const isChildOfBody = (dom, elm) => dom.isChildOf(elm, dom.getRoot());
|
|
950
621
|
|
|
951
|
-
const option =
|
|
952
|
-
const register$3 =
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
622
|
+
const option = name => editor => editor.options.get(name);
|
|
623
|
+
const register$3 = editor => {
|
|
624
|
+
const registerOption = editor.options.register;
|
|
625
|
+
registerOption('lists_indent_on_tab', {
|
|
626
|
+
processor: 'boolean',
|
|
627
|
+
default: true
|
|
628
|
+
});
|
|
958
629
|
};
|
|
959
630
|
const shouldIndentOnTab = option('lists_indent_on_tab');
|
|
960
631
|
const getForcedRootBlock = option('forced_root_block');
|
|
961
632
|
const getForcedRootBlockAttrs = option('forced_root_block_attrs');
|
|
962
633
|
|
|
963
|
-
const createTextBlock = (editor, contentNode
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
634
|
+
const createTextBlock = (editor, contentNode) => {
|
|
635
|
+
const dom = editor.dom;
|
|
636
|
+
const blockElements = editor.schema.getBlockElements();
|
|
637
|
+
const fragment = dom.createFragment();
|
|
638
|
+
const blockName = getForcedRootBlock(editor);
|
|
639
|
+
const blockAttrs = getForcedRootBlockAttrs(editor);
|
|
640
|
+
let node;
|
|
641
|
+
let textBlock;
|
|
642
|
+
let hasContentNode = false;
|
|
643
|
+
textBlock = dom.create(blockName, blockAttrs);
|
|
644
|
+
if (!isBlock(contentNode.firstChild, blockElements)) {
|
|
645
|
+
fragment.appendChild(textBlock);
|
|
646
|
+
}
|
|
647
|
+
while (node = contentNode.firstChild) {
|
|
648
|
+
const nodeName = node.nodeName;
|
|
649
|
+
if (!hasContentNode && (nodeName !== 'SPAN' || node.getAttribute('data-mce-type') !== 'bookmark')) {
|
|
650
|
+
hasContentNode = true;
|
|
651
|
+
}
|
|
652
|
+
if (isBlock(node, blockElements)) {
|
|
653
|
+
fragment.appendChild(node);
|
|
654
|
+
textBlock = null;
|
|
655
|
+
} else {
|
|
656
|
+
if (!textBlock) {
|
|
657
|
+
textBlock = dom.create(blockName, blockAttrs);
|
|
977
658
|
fragment.appendChild(textBlock);
|
|
659
|
+
}
|
|
660
|
+
textBlock.appendChild(node);
|
|
978
661
|
}
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
if (isBlock(node, blockElements)) {
|
|
985
|
-
fragment.appendChild(node);
|
|
986
|
-
textBlock = null;
|
|
987
|
-
}
|
|
988
|
-
else {
|
|
989
|
-
if (!textBlock) {
|
|
990
|
-
textBlock = dom.create(blockName, blockAttrs);
|
|
991
|
-
fragment.appendChild(textBlock);
|
|
992
|
-
}
|
|
993
|
-
textBlock.appendChild(node);
|
|
994
|
-
}
|
|
995
|
-
}
|
|
996
|
-
// BR is needed in empty blocks
|
|
997
|
-
if (!hasContentNode && textBlock) {
|
|
998
|
-
textBlock.appendChild(dom.create('br', { 'data-mce-bogus': '1' }));
|
|
999
|
-
}
|
|
1000
|
-
return fragment;
|
|
662
|
+
}
|
|
663
|
+
if (!hasContentNode && textBlock) {
|
|
664
|
+
textBlock.appendChild(dom.create('br', { 'data-mce-bogus': '1' }));
|
|
665
|
+
}
|
|
666
|
+
return fragment;
|
|
1001
667
|
};
|
|
1002
668
|
|
|
1003
669
|
const DOM$2 = global$3.DOM;
|
|
1004
670
|
const splitList = (editor, list, li) => {
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
671
|
+
const removeAndKeepBookmarks = targetNode => {
|
|
672
|
+
const parent = targetNode.parentNode;
|
|
673
|
+
if (parent) {
|
|
674
|
+
global$2.each(bookmarks, node => {
|
|
675
|
+
parent.insertBefore(node, li.parentNode);
|
|
676
|
+
});
|
|
677
|
+
}
|
|
678
|
+
DOM$2.remove(targetNode);
|
|
679
|
+
};
|
|
680
|
+
const bookmarks = DOM$2.select('span[data-mce-type="bookmark"]', list);
|
|
681
|
+
const newBlock = createTextBlock(editor, li);
|
|
682
|
+
const tmpRng = DOM$2.createRng();
|
|
683
|
+
tmpRng.setStartAfter(li);
|
|
684
|
+
tmpRng.setEndAfter(list);
|
|
685
|
+
const fragment = tmpRng.extractContents();
|
|
686
|
+
for (let node = fragment.firstChild; node; node = node.firstChild) {
|
|
687
|
+
if (node.nodeName === 'LI' && editor.dom.isEmpty(node)) {
|
|
688
|
+
DOM$2.remove(node);
|
|
689
|
+
break;
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
if (!editor.dom.isEmpty(fragment)) {
|
|
693
|
+
DOM$2.insertAfter(fragment, list);
|
|
694
|
+
}
|
|
695
|
+
DOM$2.insertAfter(newBlock, list);
|
|
696
|
+
const parent = li.parentElement;
|
|
697
|
+
if (parent && isEmpty$2(editor.dom, parent)) {
|
|
698
|
+
removeAndKeepBookmarks(parent);
|
|
699
|
+
}
|
|
700
|
+
DOM$2.remove(li);
|
|
701
|
+
if (isEmpty$2(editor.dom, list)) {
|
|
702
|
+
DOM$2.remove(list);
|
|
703
|
+
}
|
|
1038
704
|
};
|
|
1039
705
|
|
|
1040
706
|
const isDescriptionDetail = isTag('dd');
|
|
1041
707
|
const isDescriptionTerm = isTag('dt');
|
|
1042
708
|
const outdentDlItem = (editor, item) => {
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
}
|
|
709
|
+
if (isDescriptionDetail(item)) {
|
|
710
|
+
mutate(item, 'dt');
|
|
711
|
+
} else if (isDescriptionTerm(item)) {
|
|
712
|
+
parentElement(item).each(dl => splitList(editor, dl.dom, item.dom));
|
|
713
|
+
}
|
|
1049
714
|
};
|
|
1050
|
-
const indentDlItem =
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
715
|
+
const indentDlItem = item => {
|
|
716
|
+
if (isDescriptionTerm(item)) {
|
|
717
|
+
mutate(item, 'dd');
|
|
718
|
+
}
|
|
1054
719
|
};
|
|
1055
720
|
const dlIndentation = (editor, indentation, dlItems) => {
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
}
|
|
721
|
+
if (indentation === 'Indent') {
|
|
722
|
+
each$1(dlItems, indentDlItem);
|
|
723
|
+
} else {
|
|
724
|
+
each$1(dlItems, item => outdentDlItem(editor, item));
|
|
725
|
+
}
|
|
1062
726
|
};
|
|
1063
727
|
|
|
1064
728
|
const getNormalizedPoint = (container, offset) => {
|
|
1065
|
-
|
|
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
|
-
|
|
729
|
+
if (isTextNode$1(container)) {
|
|
730
|
+
return {
|
|
731
|
+
container,
|
|
732
|
+
offset
|
|
733
|
+
};
|
|
734
|
+
}
|
|
735
|
+
const node = global$6.getNode(container, offset);
|
|
736
|
+
if (isTextNode$1(node)) {
|
|
737
|
+
return {
|
|
738
|
+
container: node,
|
|
739
|
+
offset: offset >= container.childNodes.length ? node.data.length : 0
|
|
740
|
+
};
|
|
741
|
+
} else if (node.previousSibling && isTextNode$1(node.previousSibling)) {
|
|
742
|
+
return {
|
|
743
|
+
container: node.previousSibling,
|
|
744
|
+
offset: node.previousSibling.data.length
|
|
745
|
+
};
|
|
746
|
+
} else if (node.nextSibling && isTextNode$1(node.nextSibling)) {
|
|
747
|
+
return {
|
|
748
|
+
container: node.nextSibling,
|
|
749
|
+
offset: 0
|
|
750
|
+
};
|
|
751
|
+
}
|
|
752
|
+
return {
|
|
753
|
+
container,
|
|
754
|
+
offset
|
|
755
|
+
};
|
|
756
|
+
};
|
|
757
|
+
const normalizeRange = rng => {
|
|
758
|
+
const outRng = rng.cloneRange();
|
|
759
|
+
const rangeStart = getNormalizedPoint(rng.startContainer, rng.startOffset);
|
|
760
|
+
outRng.setStart(rangeStart.container, rangeStart.offset);
|
|
761
|
+
const rangeEnd = getNormalizedPoint(rng.endContainer, rng.endOffset);
|
|
762
|
+
outRng.setEnd(rangeEnd.container, rangeEnd.offset);
|
|
763
|
+
return outRng;
|
|
764
|
+
};
|
|
765
|
+
|
|
766
|
+
const listNames = [
|
|
767
|
+
'OL',
|
|
768
|
+
'UL',
|
|
769
|
+
'DL'
|
|
770
|
+
];
|
|
1099
771
|
const listSelector = listNames.join(',');
|
|
1100
772
|
const getParentList = (editor, node) => {
|
|
1101
|
-
|
|
1102
|
-
|
|
773
|
+
const selectionStart = node || editor.selection.getStart(true);
|
|
774
|
+
return editor.dom.getParent(selectionStart, listSelector, getClosestListHost(editor, selectionStart));
|
|
1103
775
|
};
|
|
1104
776
|
const isParentListSelected = (parentList, selectedBlocks) => isNonNullable(parentList) && selectedBlocks.length === 1 && selectedBlocks[0] === parentList;
|
|
1105
|
-
const findSubLists =
|
|
1106
|
-
const getSelectedSubLists =
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
}
|
|
777
|
+
const findSubLists = parentList => filter$1(parentList.querySelectorAll(listSelector), isListNode);
|
|
778
|
+
const getSelectedSubLists = editor => {
|
|
779
|
+
const parentList = getParentList(editor);
|
|
780
|
+
const selectedBlocks = editor.selection.getSelectedBlocks();
|
|
781
|
+
if (isParentListSelected(parentList, selectedBlocks)) {
|
|
782
|
+
return findSubLists(parentList);
|
|
783
|
+
} else {
|
|
784
|
+
return filter$1(selectedBlocks, elm => {
|
|
785
|
+
return isListNode(elm) && parentList !== elm;
|
|
786
|
+
});
|
|
787
|
+
}
|
|
1117
788
|
};
|
|
1118
789
|
const findParentListItemsNodes = (editor, elms) => {
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
790
|
+
const listItemsElms = global$2.map(elms, elm => {
|
|
791
|
+
const parentLi = editor.dom.getParent(elm, 'li,dd,dt', getClosestListHost(editor, elm));
|
|
792
|
+
return parentLi ? parentLi : elm;
|
|
793
|
+
});
|
|
794
|
+
return unique(listItemsElms);
|
|
1124
795
|
};
|
|
1125
|
-
const getSelectedListItems =
|
|
1126
|
-
|
|
1127
|
-
|
|
796
|
+
const getSelectedListItems = editor => {
|
|
797
|
+
const selectedBlocks = editor.selection.getSelectedBlocks();
|
|
798
|
+
return filter$1(findParentListItemsNodes(editor, selectedBlocks), isListItemNode);
|
|
1128
799
|
};
|
|
1129
|
-
const getSelectedDlItems =
|
|
800
|
+
const getSelectedDlItems = editor => filter$1(getSelectedListItems(editor), isDlItemNode);
|
|
1130
801
|
const getClosestEditingHost = (editor, elm) => {
|
|
1131
|
-
|
|
1132
|
-
|
|
802
|
+
const parentTableCell = editor.dom.getParents(elm, 'TD,TH');
|
|
803
|
+
return parentTableCell.length > 0 ? parentTableCell[0] : editor.getBody();
|
|
1133
804
|
};
|
|
1134
|
-
const isListHost = (schema, node) => !isListNode(node) && !isListItemNode(node) && exists(listNames,
|
|
805
|
+
const isListHost = (schema, node) => !isListNode(node) && !isListItemNode(node) && exists(listNames, listName => schema.isValidChild(node.nodeName, listName));
|
|
1135
806
|
const getClosestListHost = (editor, elm) => {
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
const isListInsideAnLiWithFirstAndLastNotListElement = (list) => parent(list).exists((parent) => isListItemNode(parent.dom)
|
|
1142
|
-
&& firstChild(parent).exists((firstChild) => !isListNode(firstChild.dom))
|
|
1143
|
-
&& lastChild(parent).exists((lastChild) => !isListNode(lastChild.dom)));
|
|
807
|
+
const parentBlocks = editor.dom.getParents(elm, editor.dom.isBlock);
|
|
808
|
+
const parentBlock = find(parentBlocks, elm => isListHost(editor.schema, elm));
|
|
809
|
+
return parentBlock.getOr(editor.getBody());
|
|
810
|
+
};
|
|
811
|
+
const isListInsideAnLiWithFirstAndLastNotListElement = list => parent(list).exists(parent => isListItemNode(parent.dom) && firstChild(parent).exists(firstChild => !isListNode(firstChild.dom)) && lastChild(parent).exists(lastChild => !isListNode(lastChild.dom)));
|
|
1144
812
|
const findLastParentListNode = (editor, elm) => {
|
|
1145
|
-
|
|
1146
|
-
|
|
813
|
+
const parentLists = editor.dom.getParents(elm, 'ol,ul', getClosestListHost(editor, elm));
|
|
814
|
+
return last(parentLists);
|
|
1147
815
|
};
|
|
1148
|
-
const getSelectedLists =
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
816
|
+
const getSelectedLists = editor => {
|
|
817
|
+
const firstList = findLastParentListNode(editor, editor.selection.getStart());
|
|
818
|
+
const subsequentLists = filter$1(editor.selection.getSelectedBlocks(), isOlUlNode);
|
|
819
|
+
return firstList.toArray().concat(subsequentLists);
|
|
1152
820
|
};
|
|
1153
|
-
const getParentLists =
|
|
1154
|
-
|
|
1155
|
-
|
|
821
|
+
const getParentLists = editor => {
|
|
822
|
+
const elm = editor.selection.getStart();
|
|
823
|
+
return editor.dom.getParents(elm, 'ol,ul', getClosestListHost(editor, elm));
|
|
1156
824
|
};
|
|
1157
|
-
const getSelectedListRoots =
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
825
|
+
const getSelectedListRoots = editor => {
|
|
826
|
+
const selectedLists = getSelectedLists(editor);
|
|
827
|
+
const parentLists = getParentLists(editor);
|
|
828
|
+
return find(parentLists, p => isListInsideAnLiWithFirstAndLastNotListElement(SugarElement.fromDom(p))).fold(() => getUniqueListRoots(editor, selectedLists), l => [l]);
|
|
1161
829
|
};
|
|
1162
830
|
const getUniqueListRoots = (editor, lists) => {
|
|
1163
|
-
|
|
1164
|
-
|
|
831
|
+
const listRoots = map(lists, list => findLastParentListNode(editor, list).getOr(list));
|
|
832
|
+
return unique(listRoots);
|
|
1165
833
|
};
|
|
1166
834
|
|
|
1167
|
-
const isCustomList =
|
|
1168
|
-
const inList = (parents, listName) => findUntil(parents, isListNode, isTableCellNode)
|
|
1169
|
-
.exists((list) => list.nodeName === listName && !isCustomList(list));
|
|
1170
|
-
// Advlist/core/ListUtils.ts - Duplicated in Advlist plugin
|
|
835
|
+
const isCustomList = list => /\btox\-/.test(list.className);
|
|
836
|
+
const inList = (parents, listName) => findUntil(parents, isListNode, isTableCellNode).exists(list => list.nodeName === listName && !isCustomList(list));
|
|
1171
837
|
const isWithinNonEditable = (editor, element) => element !== null && !editor.dom.isEditable(element);
|
|
1172
|
-
const selectionIsWithinNonEditableList =
|
|
1173
|
-
|
|
1174
|
-
|
|
838
|
+
const selectionIsWithinNonEditableList = editor => {
|
|
839
|
+
const parentList = getParentList(editor);
|
|
840
|
+
return isWithinNonEditable(editor, parentList);
|
|
1175
841
|
};
|
|
1176
842
|
const isWithinNonEditableList = (editor, element) => {
|
|
1177
|
-
|
|
1178
|
-
|
|
843
|
+
const parentList = editor.dom.getParent(element, 'ol,ul,dl');
|
|
844
|
+
return isWithinNonEditable(editor, parentList);
|
|
1179
845
|
};
|
|
1180
846
|
const setNodeChangeHandler = (editor, nodeChangeHandler) => {
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
const
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
847
|
+
const initialNode = editor.selection.getNode();
|
|
848
|
+
nodeChangeHandler({
|
|
849
|
+
parents: editor.dom.getParents(initialNode),
|
|
850
|
+
element: initialNode
|
|
851
|
+
});
|
|
852
|
+
editor.on('NodeChange', nodeChangeHandler);
|
|
853
|
+
return () => editor.off('NodeChange', nodeChangeHandler);
|
|
854
|
+
};
|
|
855
|
+
|
|
856
|
+
const fromElements = (elements, scope) => {
|
|
857
|
+
const doc = scope || document;
|
|
858
|
+
const fragment = doc.createDocumentFragment();
|
|
859
|
+
each$1(elements, element => {
|
|
860
|
+
fragment.appendChild(element.dom);
|
|
861
|
+
});
|
|
862
|
+
return SugarElement.fromDom(fragment);
|
|
863
|
+
};
|
|
864
|
+
|
|
865
|
+
const fireListEvent = (editor, action, element) => editor.dispatch('ListMutation', {
|
|
866
|
+
action,
|
|
867
|
+
element
|
|
868
|
+
});
|
|
869
|
+
|
|
870
|
+
const blank = r => s => s.replace(r, '');
|
|
871
|
+
const trim = blank(/^\s+|\s+$/g);
|
|
872
|
+
const isNotEmpty = s => s.length > 0;
|
|
873
|
+
const isEmpty$1 = s => !isNotEmpty(s);
|
|
874
|
+
|
|
875
|
+
const isSupported = dom => dom.style !== undefined && isFunction(dom.style.getPropertyValue);
|
|
876
|
+
|
|
877
|
+
const internalSet = (dom, property, value) => {
|
|
878
|
+
if (!isString(value)) {
|
|
879
|
+
console.error('Invalid call to CSS.set. Property ', property, ':: Value ', value, ':: Element ', dom);
|
|
880
|
+
throw new Error('CSS value must be a string: ' + value);
|
|
881
|
+
}
|
|
882
|
+
if (isSupported(dom)) {
|
|
883
|
+
dom.style.setProperty(property, value);
|
|
884
|
+
}
|
|
885
|
+
};
|
|
886
|
+
const set = (element, property, value) => {
|
|
887
|
+
const dom = element.dom;
|
|
888
|
+
internalSet(dom, property, value);
|
|
889
|
+
};
|
|
890
|
+
|
|
891
|
+
const isList = el => is(el, 'OL,UL');
|
|
892
|
+
const isListItem = el => is(el, 'LI');
|
|
893
|
+
const hasFirstChildList = el => firstChild(el).exists(isList);
|
|
894
|
+
const hasLastChildList = el => lastChild(el).exists(isList);
|
|
895
|
+
|
|
896
|
+
const isEntryList = entry => 'listAttributes' in entry;
|
|
897
|
+
const isEntryComment = entry => 'isComment' in entry;
|
|
898
|
+
const isEntryFragment = entry => 'isFragment' in entry;
|
|
899
|
+
const isIndented = entry => entry.depth > 0;
|
|
900
|
+
const isSelected = entry => entry.isSelected;
|
|
901
|
+
const cloneItemContent = li => {
|
|
902
|
+
const children$1 = children(li);
|
|
903
|
+
const content = hasLastChildList(li) ? children$1.slice(0, -1) : children$1;
|
|
904
|
+
return map(content, deep);
|
|
905
|
+
};
|
|
906
|
+
const createEntry = (li, depth, isSelected) => parent(li).filter(isElement$1).map(list => ({
|
|
907
|
+
depth,
|
|
908
|
+
dirty: false,
|
|
909
|
+
isSelected,
|
|
910
|
+
content: cloneItemContent(li),
|
|
911
|
+
itemAttributes: clone$1(li),
|
|
912
|
+
listAttributes: clone$1(list),
|
|
913
|
+
listType: name(list),
|
|
914
|
+
isInPreviousLi: false
|
|
1217
915
|
}));
|
|
1218
916
|
|
|
1219
917
|
const joinSegment = (parent, child) => {
|
|
1220
|
-
|
|
918
|
+
append$1(parent.item, child.list);
|
|
1221
919
|
};
|
|
1222
|
-
const joinSegments =
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
920
|
+
const joinSegments = segments => {
|
|
921
|
+
for (let i = 1; i < segments.length; i++) {
|
|
922
|
+
joinSegment(segments[i - 1], segments[i]);
|
|
923
|
+
}
|
|
1226
924
|
};
|
|
1227
925
|
const appendSegments = (head$1, tail) => {
|
|
1228
|
-
|
|
926
|
+
lift2(last(head$1), head(tail), joinSegment);
|
|
1229
927
|
};
|
|
1230
928
|
const createSegment = (scope, listType) => {
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
929
|
+
const segment = {
|
|
930
|
+
list: SugarElement.fromTag(listType, scope),
|
|
931
|
+
item: SugarElement.fromTag('li', scope)
|
|
932
|
+
};
|
|
933
|
+
append$1(segment.list, segment.item);
|
|
934
|
+
return segment;
|
|
1237
935
|
};
|
|
1238
936
|
const createSegments = (scope, entry, size) => {
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
937
|
+
const segments = [];
|
|
938
|
+
for (let i = 0; i < size; i++) {
|
|
939
|
+
segments.push(createSegment(scope, isEntryList(entry) ? entry.listType : entry.parentListType));
|
|
940
|
+
}
|
|
941
|
+
return segments;
|
|
1244
942
|
};
|
|
1245
943
|
const populateSegments = (segments, entry) => {
|
|
1246
|
-
|
|
1247
|
-
|
|
944
|
+
for (let i = 0; i < segments.length - 1; i++) {
|
|
945
|
+
set(segments[i].item, 'list-style-type', 'none');
|
|
946
|
+
}
|
|
947
|
+
last(segments).each(segment => {
|
|
948
|
+
if (isEntryList(entry)) {
|
|
949
|
+
setAll(segment.list, entry.listAttributes);
|
|
950
|
+
setAll(segment.item, entry.itemAttributes);
|
|
1248
951
|
}
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
setAll(segment.list, entry.listAttributes);
|
|
1252
|
-
setAll(segment.item, entry.itemAttributes);
|
|
1253
|
-
}
|
|
1254
|
-
append(segment.item, entry.content);
|
|
1255
|
-
});
|
|
952
|
+
append(segment.item, entry.content);
|
|
953
|
+
});
|
|
1256
954
|
};
|
|
1257
955
|
const normalizeSegment = (segment, entry) => {
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
956
|
+
if (name(segment.list) !== entry.listType) {
|
|
957
|
+
segment.list = mutate(segment.list, entry.listType);
|
|
958
|
+
}
|
|
959
|
+
setAll(segment.list, entry.listAttributes);
|
|
1262
960
|
};
|
|
1263
961
|
const createItem = (scope, attr, content) => {
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
962
|
+
const item = SugarElement.fromTag('li', scope);
|
|
963
|
+
setAll(item, attr);
|
|
964
|
+
append(item, content);
|
|
965
|
+
return item;
|
|
1268
966
|
};
|
|
1269
967
|
const appendItem = (segment, item) => {
|
|
1270
|
-
|
|
1271
|
-
|
|
968
|
+
append$1(segment.list, item);
|
|
969
|
+
segment.item = item;
|
|
1272
970
|
};
|
|
1273
971
|
const writeShallow = (scope, cast, entry) => {
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
});
|
|
1289
|
-
return newCast;
|
|
972
|
+
const newCast = cast.slice(0, entry.depth);
|
|
973
|
+
last(newCast).each(segment => {
|
|
974
|
+
if (isEntryList(entry)) {
|
|
975
|
+
const item = createItem(scope, entry.itemAttributes, entry.content);
|
|
976
|
+
appendItem(segment, item);
|
|
977
|
+
normalizeSegment(segment, entry);
|
|
978
|
+
} else if (isEntryFragment(entry)) {
|
|
979
|
+
append(segment.item, entry.content);
|
|
980
|
+
} else {
|
|
981
|
+
const item = SugarElement.fromHtml(`<!--${ entry.content }-->`);
|
|
982
|
+
append$1(segment.list, item);
|
|
983
|
+
}
|
|
984
|
+
});
|
|
985
|
+
return newCast;
|
|
1290
986
|
};
|
|
1291
987
|
const writeDeep = (scope, cast, entry) => {
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
988
|
+
const segments = createSegments(scope, entry, entry.depth - cast.length);
|
|
989
|
+
joinSegments(segments);
|
|
990
|
+
populateSegments(segments, entry);
|
|
991
|
+
appendSegments(cast, segments);
|
|
992
|
+
return cast.concat(segments);
|
|
1297
993
|
};
|
|
1298
994
|
const composeList = (scope, entries) => {
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
}
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
head(cast).each((fistCast) => {
|
|
1316
|
-
prepend(fistCast.list, item);
|
|
1317
|
-
});
|
|
995
|
+
let firstCommentEntryOpt = Optional.none();
|
|
996
|
+
const cast = foldl(entries, (cast, entry, i) => {
|
|
997
|
+
if (!isEntryComment(entry)) {
|
|
998
|
+
return entry.depth > cast.length ? writeDeep(scope, cast, entry) : writeShallow(scope, cast, entry);
|
|
999
|
+
} else {
|
|
1000
|
+
if (i === 0) {
|
|
1001
|
+
firstCommentEntryOpt = Optional.some(entry);
|
|
1002
|
+
return cast;
|
|
1003
|
+
}
|
|
1004
|
+
return writeShallow(scope, cast, entry);
|
|
1005
|
+
}
|
|
1006
|
+
}, []);
|
|
1007
|
+
firstCommentEntryOpt.each(firstCommentEntry => {
|
|
1008
|
+
const item = SugarElement.fromHtml(`<!--${ firstCommentEntry.content }-->`);
|
|
1009
|
+
head(cast).each(fistCast => {
|
|
1010
|
+
prepend(fistCast.list, item);
|
|
1318
1011
|
});
|
|
1319
|
-
|
|
1012
|
+
});
|
|
1013
|
+
return head(cast).map(segment => segment.list);
|
|
1320
1014
|
};
|
|
1321
1015
|
|
|
1322
1016
|
const indentEntry = (indentation, entry) => {
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1017
|
+
switch (indentation) {
|
|
1018
|
+
case 'Indent':
|
|
1019
|
+
entry.depth++;
|
|
1020
|
+
break;
|
|
1021
|
+
case 'Outdent':
|
|
1022
|
+
entry.depth--;
|
|
1023
|
+
break;
|
|
1024
|
+
case 'Flatten':
|
|
1025
|
+
entry.depth = 0;
|
|
1026
|
+
}
|
|
1027
|
+
entry.dirty = true;
|
|
1334
1028
|
};
|
|
1335
1029
|
|
|
1336
1030
|
const cloneListProperties = (target, source) => {
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1031
|
+
if (isEntryList(target) && isEntryList(source)) {
|
|
1032
|
+
target.listType = source.listType;
|
|
1033
|
+
target.listAttributes = { ...source.listAttributes };
|
|
1034
|
+
}
|
|
1341
1035
|
};
|
|
1342
|
-
const cleanListProperties =
|
|
1343
|
-
|
|
1344
|
-
entry.listAttributes = filter(entry.listAttributes, (_value, key) => key !== 'start');
|
|
1036
|
+
const cleanListProperties = entry => {
|
|
1037
|
+
entry.listAttributes = filter(entry.listAttributes, (_value, key) => key !== 'start');
|
|
1345
1038
|
};
|
|
1346
|
-
// Closest entry above/below in the same list
|
|
1347
1039
|
const closestSiblingEntry = (entries, start) => {
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1040
|
+
const depth = entries[start].depth;
|
|
1041
|
+
const matches = entry => entry.depth === depth && !entry.dirty;
|
|
1042
|
+
const until = entry => entry.depth < depth;
|
|
1043
|
+
return findUntil(reverse(entries.slice(0, start)), matches, until).orThunk(() => findUntil(entries.slice(start + 1), matches, until));
|
|
1044
|
+
};
|
|
1045
|
+
const normalizeEntries = entries => {
|
|
1046
|
+
each$1(entries, (entry, i) => {
|
|
1047
|
+
closestSiblingEntry(entries, i).fold(() => {
|
|
1048
|
+
if (entry.dirty && isEntryList(entry)) {
|
|
1049
|
+
cleanListProperties(entry);
|
|
1050
|
+
}
|
|
1051
|
+
}, matchingEntry => cloneListProperties(entry, matchingEntry));
|
|
1052
|
+
});
|
|
1053
|
+
return entries;
|
|
1054
|
+
};
|
|
1055
|
+
|
|
1056
|
+
const Cell = initial => {
|
|
1057
|
+
let value = initial;
|
|
1058
|
+
const get = () => {
|
|
1059
|
+
return value;
|
|
1060
|
+
};
|
|
1061
|
+
const set = v => {
|
|
1062
|
+
value = v;
|
|
1063
|
+
};
|
|
1064
|
+
return {
|
|
1065
|
+
get,
|
|
1066
|
+
set
|
|
1067
|
+
};
|
|
1366
1068
|
};
|
|
1367
1069
|
|
|
1368
1070
|
const parseSingleItem = (depth, itemSelection, selectionState, item) => {
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
};
|
|
1415
|
-
return acc.concat(fragment);
|
|
1416
|
-
}
|
|
1417
|
-
}
|
|
1418
|
-
}, []);
|
|
1419
|
-
return parseList(depth, itemSelection, selectionState, list).concat(parsedSiblings);
|
|
1071
|
+
var _a;
|
|
1072
|
+
if (isComment(item)) {
|
|
1073
|
+
return [{
|
|
1074
|
+
depth: depth + 1,
|
|
1075
|
+
content: (_a = item.dom.nodeValue) !== null && _a !== void 0 ? _a : '',
|
|
1076
|
+
dirty: false,
|
|
1077
|
+
isSelected: false,
|
|
1078
|
+
isComment: true
|
|
1079
|
+
}];
|
|
1080
|
+
}
|
|
1081
|
+
itemSelection.each(selection => {
|
|
1082
|
+
if (eq(selection.start, item)) {
|
|
1083
|
+
selectionState.set(true);
|
|
1084
|
+
}
|
|
1085
|
+
});
|
|
1086
|
+
const currentItemEntry = createEntry(item, depth, selectionState.get());
|
|
1087
|
+
itemSelection.each(selection => {
|
|
1088
|
+
if (eq(selection.end, item)) {
|
|
1089
|
+
selectionState.set(false);
|
|
1090
|
+
}
|
|
1091
|
+
});
|
|
1092
|
+
const childListEntries = lastChild(item).filter(isList).map(list => parseList(depth, itemSelection, selectionState, list)).getOr([]);
|
|
1093
|
+
return currentItemEntry.toArray().concat(childListEntries);
|
|
1094
|
+
};
|
|
1095
|
+
const parseItem = (depth, itemSelection, selectionState, item) => firstChild(item).filter(isList).fold(() => parseSingleItem(depth, itemSelection, selectionState, item), list => {
|
|
1096
|
+
const parsedSiblings = foldl(children(item), (acc, liChild, i) => {
|
|
1097
|
+
if (i === 0) {
|
|
1098
|
+
return acc;
|
|
1099
|
+
} else {
|
|
1100
|
+
if (isListItem(liChild)) {
|
|
1101
|
+
return acc.concat(parseSingleItem(depth, itemSelection, selectionState, liChild));
|
|
1102
|
+
} else {
|
|
1103
|
+
const fragment = {
|
|
1104
|
+
isFragment: true,
|
|
1105
|
+
depth,
|
|
1106
|
+
content: [liChild],
|
|
1107
|
+
isSelected: false,
|
|
1108
|
+
dirty: false,
|
|
1109
|
+
parentListType: name(list)
|
|
1110
|
+
};
|
|
1111
|
+
return acc.concat(fragment);
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
}, []);
|
|
1115
|
+
return parseList(depth, itemSelection, selectionState, list).concat(parsedSiblings);
|
|
1420
1116
|
});
|
|
1421
|
-
const parseList = (depth, itemSelection, selectionState, list) => bind(children(list),
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1117
|
+
const parseList = (depth, itemSelection, selectionState, list) => bind(children(list), element => {
|
|
1118
|
+
const parser = isList(element) ? parseList : parseItem;
|
|
1119
|
+
const newDepth = depth + 1;
|
|
1120
|
+
return parser(newDepth, itemSelection, selectionState, element);
|
|
1425
1121
|
});
|
|
1426
1122
|
const parseLists = (lists, itemSelection) => {
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1123
|
+
const selectionState = Cell(false);
|
|
1124
|
+
const initialDepth = 0;
|
|
1125
|
+
return map(lists, list => ({
|
|
1126
|
+
sourceList: list,
|
|
1127
|
+
entries: parseList(initialDepth, itemSelection, selectionState, list)
|
|
1128
|
+
}));
|
|
1433
1129
|
};
|
|
1434
1130
|
|
|
1435
1131
|
const outdentedComposer = (editor, entries) => {
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
const listItemAttrs = isEntryList(entry) ? entry.itemAttributes : {};
|
|
1442
|
-
return SugarElement.fromDom(createTextBlock(editor, content.dom, listItemAttrs));
|
|
1443
|
-
});
|
|
1132
|
+
const normalizedEntries = normalizeEntries(entries);
|
|
1133
|
+
return map(normalizedEntries, entry => {
|
|
1134
|
+
const content = !isEntryComment(entry) ? fromElements(entry.content) : fromElements([SugarElement.fromHtml(`<!--${ entry.content }-->`)]);
|
|
1135
|
+
return SugarElement.fromDom(createTextBlock(editor, content.dom));
|
|
1136
|
+
});
|
|
1444
1137
|
};
|
|
1445
1138
|
const indentedComposer = (editor, entries) => {
|
|
1446
|
-
|
|
1447
|
-
|
|
1139
|
+
const normalizedEntries = normalizeEntries(entries);
|
|
1140
|
+
return composeList(editor.contentDocument, normalizedEntries).toArray();
|
|
1448
1141
|
};
|
|
1449
|
-
const composeEntries = (editor, entries) => bind(groupBy(entries, isIndented),
|
|
1450
|
-
|
|
1451
|
-
|
|
1142
|
+
const composeEntries = (editor, entries) => bind(groupBy(entries, isIndented), entries => {
|
|
1143
|
+
const groupIsIndented = head(entries).exists(isIndented);
|
|
1144
|
+
return groupIsIndented ? indentedComposer(editor, entries) : outdentedComposer(editor, entries);
|
|
1452
1145
|
});
|
|
1453
1146
|
const indentSelectedEntries = (entries, indentation) => {
|
|
1454
|
-
|
|
1147
|
+
each$1(filter$1(entries, isSelected), entry => indentEntry(indentation, entry));
|
|
1455
1148
|
};
|
|
1456
|
-
const getItemSelection =
|
|
1457
|
-
|
|
1458
|
-
|
|
1149
|
+
const getItemSelection = editor => {
|
|
1150
|
+
const selectedListItems = map(getSelectedListItems(editor), SugarElement.fromDom);
|
|
1151
|
+
return lift2(find(selectedListItems, not(hasFirstChildList)), find(reverse(selectedListItems), not(hasFirstChildList)), (start, end) => ({
|
|
1152
|
+
start,
|
|
1153
|
+
end
|
|
1154
|
+
}));
|
|
1459
1155
|
};
|
|
1460
1156
|
const listIndentation = (editor, lists, indentation) => {
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
});
|
|
1468
|
-
before(entrySet.sourceList, composedLists);
|
|
1469
|
-
remove(entrySet.sourceList);
|
|
1157
|
+
const entrySets = parseLists(lists, getItemSelection(editor));
|
|
1158
|
+
each$1(entrySets, entrySet => {
|
|
1159
|
+
indentSelectedEntries(entrySet.entries, indentation);
|
|
1160
|
+
const composedLists = composeEntries(editor, entrySet.entries);
|
|
1161
|
+
each$1(composedLists, composedList => {
|
|
1162
|
+
fireListEvent(editor, indentation === 'Indent' ? 'IndentList' : 'OutdentList', composedList.dom);
|
|
1470
1163
|
});
|
|
1164
|
+
before(entrySet.sourceList, composedLists);
|
|
1165
|
+
remove(entrySet.sourceList);
|
|
1166
|
+
});
|
|
1471
1167
|
};
|
|
1472
1168
|
|
|
1473
1169
|
const selectionIndentation = (editor, indentation) => {
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1170
|
+
const lists = fromDom(getSelectedListRoots(editor));
|
|
1171
|
+
const dlItems = fromDom(getSelectedDlItems(editor));
|
|
1172
|
+
let isHandled = false;
|
|
1173
|
+
if (lists.length || dlItems.length) {
|
|
1174
|
+
const bookmark = editor.selection.getBookmark();
|
|
1175
|
+
listIndentation(editor, lists, indentation);
|
|
1176
|
+
dlIndentation(editor, indentation, dlItems);
|
|
1177
|
+
editor.selection.moveToBookmark(bookmark);
|
|
1178
|
+
editor.selection.setRng(normalizeRange(editor.selection.getRng()));
|
|
1179
|
+
editor.nodeChanged();
|
|
1180
|
+
isHandled = true;
|
|
1181
|
+
}
|
|
1182
|
+
return isHandled;
|
|
1487
1183
|
};
|
|
1488
1184
|
const handleIndentation = (editor, indentation) => !selectionIsWithinNonEditableList(editor) && selectionIndentation(editor, indentation);
|
|
1489
|
-
const indentListSelection =
|
|
1490
|
-
const outdentListSelection =
|
|
1491
|
-
const flattenListSelection =
|
|
1185
|
+
const indentListSelection = editor => handleIndentation(editor, 'Indent');
|
|
1186
|
+
const outdentListSelection = editor => handleIndentation(editor, 'Outdent');
|
|
1187
|
+
const flattenListSelection = editor => handleIndentation(editor, 'Flatten');
|
|
1188
|
+
|
|
1189
|
+
const zeroWidth = '\uFEFF';
|
|
1190
|
+
const isZwsp = char => char === zeroWidth;
|
|
1191
|
+
|
|
1192
|
+
const ancestor$1 = (scope, predicate, isRoot) => ancestor$3(scope, predicate, isRoot).isSome();
|
|
1193
|
+
|
|
1194
|
+
const ancestor = (element, target) => ancestor$1(element, curry(eq, target));
|
|
1492
1195
|
|
|
1493
1196
|
var global$1 = tinymce.util.Tools.resolve('tinymce.dom.BookmarkManager');
|
|
1494
1197
|
|
|
1495
1198
|
const DOM$1 = global$3.DOM;
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
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
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
var _a;
|
|
1542
|
-
let node = (_a = container.parentNode) === null || _a === void 0 ? void 0 : _a.firstChild;
|
|
1543
|
-
let idx = 0;
|
|
1544
|
-
while (node) {
|
|
1545
|
-
if (node === container) {
|
|
1546
|
-
return idx;
|
|
1547
|
-
}
|
|
1548
|
-
// Skip data-mce-type=bookmark nodes
|
|
1549
|
-
if (!isElement(node) || node.getAttribute('data-mce-type') !== 'bookmark') {
|
|
1550
|
-
idx++;
|
|
1551
|
-
}
|
|
1552
|
-
node = node.nextSibling;
|
|
1553
|
-
}
|
|
1554
|
-
return -1;
|
|
1555
|
-
};
|
|
1556
|
-
let container = bookmark[start ? 'startContainer' : 'endContainer'];
|
|
1557
|
-
let offset = bookmark[start ? 'startOffset' : 'endOffset'];
|
|
1558
|
-
if (!container) {
|
|
1559
|
-
return;
|
|
1560
|
-
}
|
|
1561
|
-
if (isElement(container) && container.parentNode) {
|
|
1562
|
-
const node = container;
|
|
1563
|
-
offset = nodeIndex(container);
|
|
1564
|
-
container = container.parentNode;
|
|
1565
|
-
DOM$1.remove(node);
|
|
1566
|
-
if (!container.hasChildNodes() && DOM$1.isBlock(container)) {
|
|
1567
|
-
container.appendChild(DOM$1.create('br'));
|
|
1568
|
-
}
|
|
1569
|
-
}
|
|
1570
|
-
bookmark[start ? 'startContainer' : 'endContainer'] = container;
|
|
1571
|
-
bookmark[start ? 'startOffset' : 'endOffset'] = offset;
|
|
1199
|
+
const createBookmark = rng => {
|
|
1200
|
+
const bookmark = {};
|
|
1201
|
+
const setupEndPoint = start => {
|
|
1202
|
+
let container = rng[start ? 'startContainer' : 'endContainer'];
|
|
1203
|
+
let offset = rng[start ? 'startOffset' : 'endOffset'];
|
|
1204
|
+
if (isElement(container)) {
|
|
1205
|
+
const offsetNode = DOM$1.create('span', { 'data-mce-type': 'bookmark' });
|
|
1206
|
+
if (container.hasChildNodes()) {
|
|
1207
|
+
offset = Math.min(offset, container.childNodes.length - 1);
|
|
1208
|
+
if (start) {
|
|
1209
|
+
container.insertBefore(offsetNode, container.childNodes[offset]);
|
|
1210
|
+
} else {
|
|
1211
|
+
DOM$1.insertAfter(offsetNode, container.childNodes[offset]);
|
|
1212
|
+
}
|
|
1213
|
+
} else {
|
|
1214
|
+
container.appendChild(offsetNode);
|
|
1215
|
+
}
|
|
1216
|
+
container = offsetNode;
|
|
1217
|
+
offset = 0;
|
|
1218
|
+
}
|
|
1219
|
+
bookmark[start ? 'startContainer' : 'endContainer'] = container;
|
|
1220
|
+
bookmark[start ? 'startOffset' : 'endOffset'] = offset;
|
|
1221
|
+
};
|
|
1222
|
+
setupEndPoint(true);
|
|
1223
|
+
if (!rng.collapsed) {
|
|
1224
|
+
setupEndPoint();
|
|
1225
|
+
}
|
|
1226
|
+
return bookmark;
|
|
1227
|
+
};
|
|
1228
|
+
const resolveBookmark = bookmark => {
|
|
1229
|
+
const restoreEndPoint = start => {
|
|
1230
|
+
const nodeIndex = container => {
|
|
1231
|
+
var _a;
|
|
1232
|
+
let node = (_a = container.parentNode) === null || _a === void 0 ? void 0 : _a.firstChild;
|
|
1233
|
+
let idx = 0;
|
|
1234
|
+
while (node) {
|
|
1235
|
+
if (node === container) {
|
|
1236
|
+
return idx;
|
|
1237
|
+
}
|
|
1238
|
+
if (!isElement(node) || node.getAttribute('data-mce-type') !== 'bookmark') {
|
|
1239
|
+
idx++;
|
|
1240
|
+
}
|
|
1241
|
+
node = node.nextSibling;
|
|
1242
|
+
}
|
|
1243
|
+
return -1;
|
|
1572
1244
|
};
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1245
|
+
let container = bookmark[start ? 'startContainer' : 'endContainer'];
|
|
1246
|
+
let offset = bookmark[start ? 'startOffset' : 'endOffset'];
|
|
1247
|
+
if (!container) {
|
|
1248
|
+
return;
|
|
1249
|
+
}
|
|
1250
|
+
if (isElement(container) && container.parentNode) {
|
|
1251
|
+
const node = container;
|
|
1252
|
+
offset = nodeIndex(container);
|
|
1253
|
+
container = container.parentNode;
|
|
1254
|
+
DOM$1.remove(node);
|
|
1255
|
+
if (!container.hasChildNodes() && DOM$1.isBlock(container)) {
|
|
1256
|
+
container.appendChild(DOM$1.create('br'));
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
bookmark[start ? 'startContainer' : 'endContainer'] = container;
|
|
1260
|
+
bookmark[start ? 'startOffset' : 'endOffset'] = offset;
|
|
1261
|
+
};
|
|
1262
|
+
restoreEndPoint(true);
|
|
1263
|
+
restoreEndPoint();
|
|
1264
|
+
const rng = DOM$1.createRng();
|
|
1265
|
+
rng.setStart(bookmark.startContainer, bookmark.startOffset);
|
|
1266
|
+
if (bookmark.endContainer) {
|
|
1267
|
+
rng.setEnd(bookmark.endContainer, bookmark.endOffset);
|
|
1268
|
+
}
|
|
1269
|
+
return normalizeRange(rng);
|
|
1270
|
+
};
|
|
1271
|
+
|
|
1272
|
+
const listToggleActionFromListName = listName => {
|
|
1273
|
+
switch (listName) {
|
|
1274
|
+
case 'UL':
|
|
1275
|
+
return 'ToggleUlList';
|
|
1276
|
+
case 'OL':
|
|
1277
|
+
return 'ToggleOlList';
|
|
1278
|
+
case 'DL':
|
|
1279
|
+
return 'ToggleDLList';
|
|
1280
|
+
}
|
|
1589
1281
|
};
|
|
1590
1282
|
|
|
1591
1283
|
const updateListStyle = (dom, el, detail) => {
|
|
1592
|
-
|
|
1593
|
-
|
|
1284
|
+
const type = detail['list-style-type'] ? detail['list-style-type'] : null;
|
|
1285
|
+
dom.setStyle(el, 'list-style-type', type);
|
|
1594
1286
|
};
|
|
1595
1287
|
const setAttribs = (elm, attrs) => {
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1288
|
+
global$2.each(attrs, (value, key) => {
|
|
1289
|
+
elm.setAttribute(key, value);
|
|
1290
|
+
});
|
|
1599
1291
|
};
|
|
1600
1292
|
const updateListAttrs = (dom, el, detail) => {
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1293
|
+
setAttribs(el, detail['list-attributes']);
|
|
1294
|
+
global$2.each(dom.select('li', el), li => {
|
|
1295
|
+
setAttribs(li, detail['list-item-attributes']);
|
|
1296
|
+
});
|
|
1605
1297
|
};
|
|
1606
1298
|
const updateListWithDetails = (dom, el, detail) => {
|
|
1607
|
-
|
|
1608
|
-
|
|
1299
|
+
updateListStyle(dom, el, detail);
|
|
1300
|
+
updateListAttrs(dom, el, detail);
|
|
1609
1301
|
};
|
|
1610
1302
|
const removeStyles = (dom, element, styles) => {
|
|
1611
|
-
|
|
1303
|
+
global$2.each(styles, style => dom.setStyle(element, style, ''));
|
|
1612
1304
|
};
|
|
1613
1305
|
const isInline = (editor, node) => isNonNullable(node) && !isBlock(node, editor.schema.getBlockElements());
|
|
1614
1306
|
const getEndPointNode = (editor, rng, start, root) => {
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1307
|
+
let container = rng[start ? 'startContainer' : 'endContainer'];
|
|
1308
|
+
const offset = rng[start ? 'startOffset' : 'endOffset'];
|
|
1309
|
+
if (isElement(container)) {
|
|
1310
|
+
container = container.childNodes[Math.min(offset, container.childNodes.length - 1)] || container;
|
|
1311
|
+
}
|
|
1312
|
+
if (!start && isBr(container.nextSibling)) {
|
|
1313
|
+
container = container.nextSibling;
|
|
1314
|
+
}
|
|
1315
|
+
const findBlockAncestor = node => {
|
|
1316
|
+
while (!editor.dom.isBlock(node) && node.parentNode && root !== node) {
|
|
1317
|
+
node = node.parentNode;
|
|
1318
|
+
}
|
|
1319
|
+
return node;
|
|
1320
|
+
};
|
|
1321
|
+
const findBetterContainer = (container, forward) => {
|
|
1322
|
+
var _a;
|
|
1323
|
+
const walker = new global$5(container, findBlockAncestor(container));
|
|
1324
|
+
const dir = forward ? 'next' : 'prev';
|
|
1325
|
+
let node;
|
|
1326
|
+
while (node = walker[dir]()) {
|
|
1327
|
+
if (!(isVoid(editor, node) || isZwsp(node.textContent) || ((_a = node.textContent) === null || _a === void 0 ? void 0 : _a.length) === 0)) {
|
|
1328
|
+
return Optional.some(node);
|
|
1329
|
+
}
|
|
1620
1330
|
}
|
|
1621
|
-
|
|
1331
|
+
return Optional.none();
|
|
1332
|
+
};
|
|
1333
|
+
if (start && isTextNode$1(container)) {
|
|
1334
|
+
if (isZwsp(container.textContent)) {
|
|
1335
|
+
container = findBetterContainer(container, false).getOr(container);
|
|
1336
|
+
} else {
|
|
1337
|
+
if (container.parentNode !== null && isInline(editor, container.parentNode)) {
|
|
1338
|
+
container = container.parentNode;
|
|
1339
|
+
}
|
|
1340
|
+
while (container.previousSibling !== null && (isInline(editor, container.previousSibling) || isTextNode$1(container.previousSibling))) {
|
|
1341
|
+
container = container.previousSibling;
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
if (!start && isTextNode$1(container)) {
|
|
1346
|
+
if (isZwsp(container.textContent)) {
|
|
1347
|
+
container = findBetterContainer(container, true).getOr(container);
|
|
1348
|
+
} else {
|
|
1349
|
+
if (container.parentNode !== null && isInline(editor, container.parentNode)) {
|
|
1350
|
+
container = container.parentNode;
|
|
1351
|
+
}
|
|
1352
|
+
while (container.nextSibling !== null && (isInline(editor, container.nextSibling) || isTextNode$1(container.nextSibling))) {
|
|
1622
1353
|
container = container.nextSibling;
|
|
1354
|
+
}
|
|
1623
1355
|
}
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
};
|
|
1630
|
-
// The reason why the next two if statements exist is because when the root node is a table cell (possibly some other node types)
|
|
1631
|
-
// then the highest we can go up the dom hierarchy is one level below the table cell.
|
|
1632
|
-
// So what happens when we have a bunch of inline nodes and text nodes in the table cell
|
|
1633
|
-
// and when the selection is collapsed inside one of the inline nodes then only that inline node (or text node) will be included
|
|
1634
|
-
// in the created list because that would be one level below td node and the other inline nodes won't be included.
|
|
1635
|
-
// So the fix proposed is to traverse left when looking for start node (and traverse right when looking for end node)
|
|
1636
|
-
// and keep traversing as long as we have an inline or text node (same for traversing right).
|
|
1637
|
-
// This way we end up including all the inline elements in the created list.
|
|
1638
|
-
// For more info look at #TINY-6853
|
|
1639
|
-
const findBetterContainer = (container, forward) => {
|
|
1640
|
-
var _a;
|
|
1641
|
-
const walker = new global$5(container, findBlockAncestor(container));
|
|
1642
|
-
const dir = forward ? 'next' : 'prev';
|
|
1643
|
-
let node;
|
|
1644
|
-
while ((node = walker[dir]())) {
|
|
1645
|
-
if (!(isVoid(editor, node) || isZwsp(node.textContent) || ((_a = node.textContent) === null || _a === void 0 ? void 0 : _a.length) === 0)) {
|
|
1646
|
-
return Optional.some(node);
|
|
1647
|
-
}
|
|
1648
|
-
}
|
|
1649
|
-
return Optional.none();
|
|
1650
|
-
};
|
|
1651
|
-
// Traverse left to include inline/text nodes
|
|
1652
|
-
if (start && isTextNode$1(container)) {
|
|
1653
|
-
if (isZwsp(container.textContent)) {
|
|
1654
|
-
container = findBetterContainer(container, false).getOr(container);
|
|
1655
|
-
}
|
|
1656
|
-
else {
|
|
1657
|
-
if (container.parentNode !== null && isInline(editor, container.parentNode)) {
|
|
1658
|
-
container = container.parentNode;
|
|
1659
|
-
}
|
|
1660
|
-
while (container.previousSibling !== null && (isInline(editor, container.previousSibling) || isTextNode$1(container.previousSibling))) {
|
|
1661
|
-
container = container.previousSibling;
|
|
1662
|
-
}
|
|
1663
|
-
}
|
|
1664
|
-
}
|
|
1665
|
-
// Traverse right to include inline/text nodes
|
|
1666
|
-
if (!start && isTextNode$1(container)) {
|
|
1667
|
-
if (isZwsp(container.textContent)) {
|
|
1668
|
-
container = findBetterContainer(container, true).getOr(container);
|
|
1669
|
-
}
|
|
1670
|
-
else {
|
|
1671
|
-
if (container.parentNode !== null && isInline(editor, container.parentNode)) {
|
|
1672
|
-
container = container.parentNode;
|
|
1673
|
-
}
|
|
1674
|
-
while (container.nextSibling !== null && (isInline(editor, container.nextSibling) || isTextNode$1(container.nextSibling))) {
|
|
1675
|
-
container = container.nextSibling;
|
|
1676
|
-
}
|
|
1677
|
-
}
|
|
1356
|
+
}
|
|
1357
|
+
while (container.parentNode !== root) {
|
|
1358
|
+
const parent = container.parentNode;
|
|
1359
|
+
if (isTextBlock(editor, container)) {
|
|
1360
|
+
return container;
|
|
1678
1361
|
}
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
if (isTextBlock(editor, container)) {
|
|
1682
|
-
return container;
|
|
1683
|
-
}
|
|
1684
|
-
if (/^(TD|TH)$/.test(parent.nodeName)) {
|
|
1685
|
-
return container;
|
|
1686
|
-
}
|
|
1687
|
-
container = parent;
|
|
1362
|
+
if (/^(TD|TH)$/.test(parent.nodeName)) {
|
|
1363
|
+
return container;
|
|
1688
1364
|
}
|
|
1689
|
-
|
|
1365
|
+
container = parent;
|
|
1366
|
+
}
|
|
1367
|
+
return container;
|
|
1690
1368
|
};
|
|
1691
1369
|
const getSelectedTextBlocks = (editor, rng, root) => {
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1370
|
+
const textBlocks = [];
|
|
1371
|
+
const dom = editor.dom;
|
|
1372
|
+
const startNode = getEndPointNode(editor, rng, true, root);
|
|
1373
|
+
const endNode = getEndPointNode(editor, rng, false, root);
|
|
1374
|
+
let block;
|
|
1375
|
+
const siblings = [];
|
|
1376
|
+
for (let node = startNode; node; node = node.nextSibling) {
|
|
1377
|
+
siblings.push(node);
|
|
1378
|
+
if (node === endNode) {
|
|
1379
|
+
break;
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
1382
|
+
global$2.each(siblings, node => {
|
|
1383
|
+
var _a;
|
|
1384
|
+
if (isTextBlock(editor, node)) {
|
|
1385
|
+
textBlocks.push(node);
|
|
1386
|
+
block = null;
|
|
1387
|
+
return;
|
|
1703
1388
|
}
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
block = dom.create('p');
|
|
1727
|
-
(_a = node.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(block, node);
|
|
1728
|
-
textBlocks.push(block);
|
|
1729
|
-
}
|
|
1730
|
-
block.appendChild(node);
|
|
1731
|
-
});
|
|
1732
|
-
return textBlocks;
|
|
1389
|
+
if (dom.isBlock(node) || isBr(node)) {
|
|
1390
|
+
if (isBr(node)) {
|
|
1391
|
+
dom.remove(node);
|
|
1392
|
+
}
|
|
1393
|
+
block = null;
|
|
1394
|
+
return;
|
|
1395
|
+
}
|
|
1396
|
+
const nextSibling = node.nextSibling;
|
|
1397
|
+
if (global$1.isBookmarkNode(node)) {
|
|
1398
|
+
if (isListNode(nextSibling) || isTextBlock(editor, nextSibling) || !nextSibling && node.parentNode === root) {
|
|
1399
|
+
block = null;
|
|
1400
|
+
return;
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
if (!block) {
|
|
1404
|
+
block = dom.create('p');
|
|
1405
|
+
(_a = node.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(block, node);
|
|
1406
|
+
textBlocks.push(block);
|
|
1407
|
+
}
|
|
1408
|
+
block.appendChild(node);
|
|
1409
|
+
});
|
|
1410
|
+
return textBlocks;
|
|
1733
1411
|
};
|
|
1734
1412
|
const hasCompatibleStyle = (dom, sib, detail) => {
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
};
|
|
1740
|
-
/*
|
|
1741
|
-
Find the first element we would transform into a li-element if given no constraints.
|
|
1742
|
-
If the common ancestor is higher up than that provide it as the starting-point for the search for the root instead of the first selected element.
|
|
1743
|
-
This helps avoid issues with divs that should become li-elements are detected as the root when they should not be.
|
|
1744
|
-
*/
|
|
1413
|
+
const sibStyle = dom.getStyle(sib, 'list-style-type');
|
|
1414
|
+
let detailStyle = detail ? detail['list-style-type'] : '';
|
|
1415
|
+
detailStyle = detailStyle === null ? '' : detailStyle;
|
|
1416
|
+
return sibStyle === detailStyle;
|
|
1417
|
+
};
|
|
1745
1418
|
const getRootSearchStart = (editor, range) => {
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
}
|
|
1419
|
+
const start = editor.selection.getStart(true);
|
|
1420
|
+
const startPoint = getEndPointNode(editor, range, true, editor.getBody());
|
|
1421
|
+
if (ancestor(SugarElement.fromDom(startPoint), SugarElement.fromDom(range.commonAncestorContainer))) {
|
|
1422
|
+
return range.commonAncestorContainer;
|
|
1423
|
+
} else {
|
|
1424
|
+
return start;
|
|
1425
|
+
}
|
|
1754
1426
|
};
|
|
1755
1427
|
const applyList = (editor, listName, detail) => {
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1428
|
+
const rng = editor.selection.getRng();
|
|
1429
|
+
let listItemName = 'LI';
|
|
1430
|
+
const root = getClosestListHost(editor, getRootSearchStart(editor, rng));
|
|
1431
|
+
const dom = editor.dom;
|
|
1432
|
+
if (dom.getContentEditable(editor.selection.getNode()) === 'false') {
|
|
1433
|
+
return;
|
|
1434
|
+
}
|
|
1435
|
+
listName = listName.toUpperCase();
|
|
1436
|
+
if (listName === 'DL') {
|
|
1437
|
+
listItemName = 'DT';
|
|
1438
|
+
}
|
|
1439
|
+
const bookmark = createBookmark(rng);
|
|
1440
|
+
const selectedTextBlocks = filter$1(getSelectedTextBlocks(editor, rng, root), editor.dom.isEditable);
|
|
1441
|
+
global$2.each(selectedTextBlocks, block => {
|
|
1442
|
+
let listBlock;
|
|
1443
|
+
const sibling = block.previousSibling;
|
|
1444
|
+
const parent = block.parentNode;
|
|
1445
|
+
if (!isListItemNode(parent)) {
|
|
1446
|
+
if (sibling && isListNode(sibling) && sibling.nodeName === listName && hasCompatibleStyle(dom, sibling, detail)) {
|
|
1447
|
+
listBlock = sibling;
|
|
1448
|
+
block = dom.rename(block, listItemName);
|
|
1449
|
+
sibling.appendChild(block);
|
|
1450
|
+
} else {
|
|
1451
|
+
listBlock = dom.create(listName);
|
|
1452
|
+
parent.insertBefore(listBlock, block);
|
|
1453
|
+
listBlock.appendChild(block);
|
|
1454
|
+
block = dom.rename(block, listItemName);
|
|
1455
|
+
}
|
|
1456
|
+
removeStyles(dom, block, [
|
|
1457
|
+
'margin',
|
|
1458
|
+
'margin-right',
|
|
1459
|
+
'margin-bottom',
|
|
1460
|
+
'margin-left',
|
|
1461
|
+
'margin-top',
|
|
1462
|
+
'padding',
|
|
1463
|
+
'padding-right',
|
|
1464
|
+
'padding-bottom',
|
|
1465
|
+
'padding-left',
|
|
1466
|
+
'padding-top'
|
|
1467
|
+
]);
|
|
1468
|
+
updateListWithDetails(dom, listBlock, detail);
|
|
1469
|
+
mergeWithAdjacentLists(editor.dom, listBlock);
|
|
1470
|
+
}
|
|
1471
|
+
});
|
|
1472
|
+
editor.selection.setRng(resolveBookmark(bookmark));
|
|
1794
1473
|
};
|
|
1795
1474
|
const isValidLists = (list1, list2) => {
|
|
1796
|
-
|
|
1475
|
+
return isListNode(list1) && list1.nodeName === (list2 === null || list2 === void 0 ? void 0 : list2.nodeName);
|
|
1797
1476
|
};
|
|
1798
1477
|
const hasSameListStyle = (dom, list1, list2) => {
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1478
|
+
const targetStyle = dom.getStyle(list1, 'list-style-type', true);
|
|
1479
|
+
const style = dom.getStyle(list2, 'list-style-type', true);
|
|
1480
|
+
return targetStyle === style;
|
|
1802
1481
|
};
|
|
1803
1482
|
const hasSameClasses = (elm1, elm2) => {
|
|
1804
|
-
|
|
1483
|
+
return elm1.className === elm2.className;
|
|
1805
1484
|
};
|
|
1806
1485
|
const shouldMerge = (dom, list1, list2) => {
|
|
1807
|
-
|
|
1808
|
-
// Note: isValidLists will ensure list1 and list2 are a HTMLElement. Unfortunately TypeScript doesn't
|
|
1809
|
-
// support type guards on multiple variables. See https://github.com/microsoft/TypeScript/issues/26916
|
|
1810
|
-
hasSameListStyle(dom, list1, list2) &&
|
|
1811
|
-
hasSameClasses(list1, list2);
|
|
1486
|
+
return isValidLists(list1, list2) && hasSameListStyle(dom, list1, list2) && hasSameClasses(list1, list2);
|
|
1812
1487
|
};
|
|
1813
1488
|
const mergeWithAdjacentLists = (dom, listBlock) => {
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1489
|
+
let node;
|
|
1490
|
+
let sibling = listBlock.nextSibling;
|
|
1491
|
+
if (shouldMerge(dom, listBlock, sibling)) {
|
|
1492
|
+
const liSibling = sibling;
|
|
1493
|
+
while (node = liSibling.firstChild) {
|
|
1494
|
+
listBlock.appendChild(node);
|
|
1495
|
+
}
|
|
1496
|
+
dom.remove(liSibling);
|
|
1497
|
+
}
|
|
1498
|
+
sibling = listBlock.previousSibling;
|
|
1499
|
+
if (shouldMerge(dom, listBlock, sibling)) {
|
|
1500
|
+
const liSibling = sibling;
|
|
1501
|
+
while (node = liSibling.lastChild) {
|
|
1502
|
+
listBlock.insertBefore(node, listBlock.firstChild);
|
|
1503
|
+
}
|
|
1504
|
+
dom.remove(liSibling);
|
|
1505
|
+
}
|
|
1831
1506
|
};
|
|
1832
1507
|
const updateList$1 = (editor, list, listName, detail) => {
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
}
|
|
1508
|
+
if (list.nodeName !== listName) {
|
|
1509
|
+
const newList = editor.dom.rename(list, listName);
|
|
1510
|
+
updateListWithDetails(editor.dom, newList, detail);
|
|
1511
|
+
fireListEvent(editor, listToggleActionFromListName(listName), newList);
|
|
1512
|
+
} else {
|
|
1513
|
+
updateListWithDetails(editor.dom, list, detail);
|
|
1514
|
+
fireListEvent(editor, listToggleActionFromListName(listName), list);
|
|
1515
|
+
}
|
|
1842
1516
|
};
|
|
1843
1517
|
const updateCustomList = (editor, list, listName, detail) => {
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
}
|
|
1518
|
+
list.classList.forEach((cls, _, classList) => {
|
|
1519
|
+
if (cls.startsWith('tox-')) {
|
|
1520
|
+
classList.remove(cls);
|
|
1521
|
+
if (classList.length === 0) {
|
|
1522
|
+
list.removeAttribute('class');
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
});
|
|
1526
|
+
if (list.nodeName !== listName) {
|
|
1527
|
+
const newList = editor.dom.rename(list, listName);
|
|
1528
|
+
updateListWithDetails(editor.dom, newList, detail);
|
|
1529
|
+
fireListEvent(editor, listToggleActionFromListName(listName), newList);
|
|
1530
|
+
} else {
|
|
1531
|
+
updateListWithDetails(editor.dom, list, detail);
|
|
1532
|
+
fireListEvent(editor, listToggleActionFromListName(listName), list);
|
|
1533
|
+
}
|
|
1861
1534
|
};
|
|
1862
1535
|
const toggleMultipleLists = (editor, parentList, lists, listName, detail) => {
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
}
|
|
1536
|
+
const parentIsList = isListNode(parentList);
|
|
1537
|
+
if (parentIsList && parentList.nodeName === listName && !hasListStyleDetail(detail) && !isCustomList(parentList)) {
|
|
1538
|
+
flattenListSelection(editor);
|
|
1539
|
+
} else {
|
|
1540
|
+
applyList(editor, listName, detail);
|
|
1541
|
+
const bookmark = createBookmark(editor.selection.getRng());
|
|
1542
|
+
const allLists = parentIsList ? [
|
|
1543
|
+
parentList,
|
|
1544
|
+
...lists
|
|
1545
|
+
] : lists;
|
|
1546
|
+
const updateFunction = parentIsList && isCustomList(parentList) ? updateCustomList : updateList$1;
|
|
1547
|
+
global$2.each(allLists, elm => {
|
|
1548
|
+
updateFunction(editor, elm, listName, detail);
|
|
1549
|
+
});
|
|
1550
|
+
editor.selection.setRng(resolveBookmark(bookmark));
|
|
1551
|
+
}
|
|
1877
1552
|
};
|
|
1878
|
-
const hasListStyleDetail =
|
|
1879
|
-
|
|
1553
|
+
const hasListStyleDetail = detail => {
|
|
1554
|
+
return 'list-style-type' in detail;
|
|
1880
1555
|
};
|
|
1881
1556
|
const toggleSingleList = (editor, parentList, listName, detail) => {
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
parentList.removeAttribute('class');
|
|
1897
|
-
}
|
|
1898
|
-
}
|
|
1899
|
-
});
|
|
1557
|
+
if (parentList === editor.getBody()) {
|
|
1558
|
+
return;
|
|
1559
|
+
}
|
|
1560
|
+
if (parentList) {
|
|
1561
|
+
if (parentList.nodeName === listName && !hasListStyleDetail(detail) && !isCustomList(parentList)) {
|
|
1562
|
+
flattenListSelection(editor);
|
|
1563
|
+
} else {
|
|
1564
|
+
const bookmark = createBookmark(editor.selection.getRng());
|
|
1565
|
+
if (isCustomList(parentList)) {
|
|
1566
|
+
parentList.classList.forEach((cls, _, classList) => {
|
|
1567
|
+
if (cls.startsWith('tox-')) {
|
|
1568
|
+
classList.remove(cls);
|
|
1569
|
+
if (classList.length === 0) {
|
|
1570
|
+
parentList.removeAttribute('class');
|
|
1900
1571
|
}
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1572
|
+
}
|
|
1573
|
+
});
|
|
1574
|
+
}
|
|
1575
|
+
updateListWithDetails(editor.dom, parentList, detail);
|
|
1576
|
+
const newList = editor.dom.rename(parentList, listName);
|
|
1577
|
+
mergeWithAdjacentLists(editor.dom, newList);
|
|
1578
|
+
editor.selection.setRng(resolveBookmark(bookmark));
|
|
1579
|
+
applyList(editor, listName, detail);
|
|
1580
|
+
fireListEvent(editor, listToggleActionFromListName(listName), newList);
|
|
1581
|
+
}
|
|
1582
|
+
} else {
|
|
1583
|
+
applyList(editor, listName, detail);
|
|
1584
|
+
fireListEvent(editor, listToggleActionFromListName(listName), parentList);
|
|
1585
|
+
}
|
|
1913
1586
|
};
|
|
1914
1587
|
const toggleList = (editor, listName, _detail) => {
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
}
|
|
1588
|
+
const parentList = getParentList(editor);
|
|
1589
|
+
if (isWithinNonEditableList(editor, parentList)) {
|
|
1590
|
+
return;
|
|
1591
|
+
}
|
|
1592
|
+
const selectedSubLists = getSelectedSubLists(editor);
|
|
1593
|
+
const detail = isObject(_detail) ? _detail : {};
|
|
1594
|
+
if (selectedSubLists.length > 0) {
|
|
1595
|
+
toggleMultipleLists(editor, parentList, selectedSubLists, listName, detail);
|
|
1596
|
+
} else {
|
|
1597
|
+
toggleSingleList(editor, parentList, listName, detail);
|
|
1598
|
+
}
|
|
1927
1599
|
};
|
|
1928
1600
|
|
|
1929
1601
|
const DOM = global$3.DOM;
|
|
1930
1602
|
const normalizeList = (dom, list) => {
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
sibling.appendChild(list);
|
|
1950
|
-
}
|
|
1951
|
-
}
|
|
1603
|
+
const parentNode = list.parentElement;
|
|
1604
|
+
if (parentNode && parentNode.nodeName === 'LI' && parentNode.firstChild === list) {
|
|
1605
|
+
const sibling = parentNode.previousSibling;
|
|
1606
|
+
if (sibling && sibling.nodeName === 'LI') {
|
|
1607
|
+
sibling.appendChild(list);
|
|
1608
|
+
if (isEmpty$2(dom, parentNode)) {
|
|
1609
|
+
DOM.remove(parentNode);
|
|
1610
|
+
}
|
|
1611
|
+
} else {
|
|
1612
|
+
DOM.setStyle(parentNode, 'listStyleType', 'none');
|
|
1613
|
+
}
|
|
1614
|
+
}
|
|
1615
|
+
if (isListNode(parentNode)) {
|
|
1616
|
+
const sibling = parentNode.previousSibling;
|
|
1617
|
+
if (sibling && sibling.nodeName === 'LI') {
|
|
1618
|
+
sibling.appendChild(list);
|
|
1619
|
+
}
|
|
1620
|
+
}
|
|
1952
1621
|
};
|
|
1953
1622
|
const normalizeLists = (dom, element) => {
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1623
|
+
const lists = global$2.grep(dom.select('ol,ul', element));
|
|
1624
|
+
global$2.each(lists, list => {
|
|
1625
|
+
normalizeList(dom, list);
|
|
1626
|
+
});
|
|
1958
1627
|
};
|
|
1959
1628
|
|
|
1960
1629
|
const findNextCaretContainer = (editor, rng, isForward, root) => {
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
if (
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
return null;
|
|
1630
|
+
let node = rng.startContainer;
|
|
1631
|
+
const offset = rng.startOffset;
|
|
1632
|
+
if (isTextNode$1(node) && (isForward ? offset < node.data.length : offset > 0)) {
|
|
1633
|
+
return node;
|
|
1634
|
+
}
|
|
1635
|
+
const nonEmptyBlocks = editor.schema.getNonEmptyElements();
|
|
1636
|
+
if (isElement(node)) {
|
|
1637
|
+
node = global$6.getNode(node, offset);
|
|
1638
|
+
}
|
|
1639
|
+
const walker = new global$5(node, root);
|
|
1640
|
+
if (isForward) {
|
|
1641
|
+
if (isBogusBr(editor.dom, node)) {
|
|
1642
|
+
walker.next();
|
|
1643
|
+
}
|
|
1644
|
+
}
|
|
1645
|
+
const walkFn = isForward ? walker.next.bind(walker) : walker.prev2.bind(walker);
|
|
1646
|
+
while (node = walkFn()) {
|
|
1647
|
+
if (node.nodeName === 'LI' && !node.hasChildNodes()) {
|
|
1648
|
+
return node;
|
|
1649
|
+
}
|
|
1650
|
+
if (nonEmptyBlocks[node.nodeName]) {
|
|
1651
|
+
return node;
|
|
1652
|
+
}
|
|
1653
|
+
if (isTextNode$1(node) && node.data.length > 0) {
|
|
1654
|
+
return node;
|
|
1655
|
+
}
|
|
1656
|
+
}
|
|
1657
|
+
return null;
|
|
1990
1658
|
};
|
|
1991
1659
|
const hasOnlyOneBlockChild = (dom, elm) => {
|
|
1992
|
-
|
|
1993
|
-
|
|
1660
|
+
const childNodes = elm.childNodes;
|
|
1661
|
+
return childNodes.length === 1 && !isListNode(childNodes[0]) && dom.isBlock(childNodes[0]);
|
|
1994
1662
|
};
|
|
1995
|
-
const isUnwrappable =
|
|
1996
|
-
.map(SugarElement.fromDom)
|
|
1997
|
-
.filter(isHTMLElement)
|
|
1998
|
-
.exists((el) => isEditable(el) && !contains$1(['details'], name(el)));
|
|
1663
|
+
const isUnwrappable = node => Optional.from(node).map(SugarElement.fromDom).filter(isHTMLElement).exists(el => isEditable(el) && !contains$1(['details'], name(el)));
|
|
1999
1664
|
const unwrapSingleBlockChild = (dom, elm) => {
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
1665
|
+
if (hasOnlyOneBlockChild(dom, elm) && isUnwrappable(elm.firstChild)) {
|
|
1666
|
+
dom.remove(elm.firstChild, true);
|
|
1667
|
+
}
|
|
2003
1668
|
};
|
|
2004
1669
|
const moveChildren = (dom, fromElm, toElm) => {
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
}
|
|
1670
|
+
let node;
|
|
1671
|
+
const targetElm = hasOnlyOneBlockChild(dom, toElm) ? toElm.firstChild : toElm;
|
|
1672
|
+
unwrapSingleBlockChild(dom, fromElm);
|
|
1673
|
+
if (!isEmpty$2(dom, fromElm, true)) {
|
|
1674
|
+
while (node = fromElm.firstChild) {
|
|
1675
|
+
targetElm.appendChild(node);
|
|
2012
1676
|
}
|
|
1677
|
+
}
|
|
2013
1678
|
};
|
|
2014
1679
|
const mergeLiElements = (dom, fromElm, toElm) => {
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
1680
|
+
let listNode;
|
|
1681
|
+
const ul = fromElm.parentNode;
|
|
1682
|
+
if (!isChildOfBody(dom, fromElm) || !isChildOfBody(dom, toElm)) {
|
|
1683
|
+
return;
|
|
1684
|
+
}
|
|
1685
|
+
if (isListNode(toElm.lastChild)) {
|
|
1686
|
+
listNode = toElm.lastChild;
|
|
1687
|
+
}
|
|
1688
|
+
if (ul === toElm.lastChild) {
|
|
1689
|
+
if (isBr(ul.previousSibling)) {
|
|
1690
|
+
dom.remove(ul.previousSibling);
|
|
1691
|
+
}
|
|
1692
|
+
}
|
|
1693
|
+
const node = toElm.lastChild;
|
|
1694
|
+
if (node && isBr(node) && fromElm.hasChildNodes()) {
|
|
1695
|
+
dom.remove(node);
|
|
1696
|
+
}
|
|
1697
|
+
if (isEmpty$2(dom, toElm, true)) {
|
|
1698
|
+
empty(SugarElement.fromDom(toElm));
|
|
1699
|
+
}
|
|
1700
|
+
moveChildren(dom, fromElm, toElm);
|
|
1701
|
+
if (listNode) {
|
|
1702
|
+
toElm.appendChild(listNode);
|
|
1703
|
+
}
|
|
1704
|
+
const contains$1 = contains(SugarElement.fromDom(toElm), SugarElement.fromDom(fromElm));
|
|
1705
|
+
const nestedLists = contains$1 ? dom.getParents(fromElm, isListNode, toElm) : [];
|
|
1706
|
+
dom.remove(fromElm);
|
|
1707
|
+
each$1(nestedLists, list => {
|
|
1708
|
+
if (isEmpty$2(dom, list) && list !== dom.getRoot()) {
|
|
1709
|
+
dom.remove(list);
|
|
1710
|
+
}
|
|
1711
|
+
});
|
|
2047
1712
|
};
|
|
2048
1713
|
const mergeIntoEmptyLi = (editor, fromLi, toLi) => {
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
1714
|
+
empty(SugarElement.fromDom(toLi));
|
|
1715
|
+
mergeLiElements(editor.dom, fromLi, toLi);
|
|
1716
|
+
editor.selection.setCursorLocation(toLi, 0);
|
|
2052
1717
|
};
|
|
2053
1718
|
const mergeForward = (editor, rng, fromLi, toLi) => {
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
}
|
|
1719
|
+
const dom = editor.dom;
|
|
1720
|
+
if (dom.isEmpty(toLi)) {
|
|
1721
|
+
mergeIntoEmptyLi(editor, fromLi, toLi);
|
|
1722
|
+
} else {
|
|
1723
|
+
const bookmark = createBookmark(rng);
|
|
1724
|
+
mergeLiElements(dom, fromLi, toLi);
|
|
1725
|
+
editor.selection.setRng(resolveBookmark(bookmark));
|
|
1726
|
+
}
|
|
2063
1727
|
};
|
|
2064
1728
|
const mergeBackward = (editor, rng, fromLi, toLi) => {
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
1729
|
+
const bookmark = createBookmark(rng);
|
|
1730
|
+
mergeLiElements(editor.dom, fromLi, toLi);
|
|
1731
|
+
const resolvedBookmark = resolveBookmark(bookmark);
|
|
1732
|
+
editor.selection.setRng(resolvedBookmark);
|
|
2069
1733
|
};
|
|
2070
1734
|
const backspaceDeleteFromListToListCaret = (editor, isForward) => {
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
}
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
editor.undoManager.transact(() => {
|
|
2116
|
-
flattenListSelection(editor);
|
|
2117
|
-
});
|
|
2118
|
-
return true;
|
|
2119
|
-
}
|
|
2120
|
-
}
|
|
1735
|
+
const dom = editor.dom, selection = editor.selection;
|
|
1736
|
+
const selectionStartElm = selection.getStart();
|
|
1737
|
+
const root = getClosestEditingHost(editor, selectionStartElm);
|
|
1738
|
+
const li = dom.getParent(selection.getStart(), 'LI', root);
|
|
1739
|
+
if (li) {
|
|
1740
|
+
const ul = li.parentElement;
|
|
1741
|
+
if (ul === editor.getBody() && isEmpty$2(dom, ul)) {
|
|
1742
|
+
return true;
|
|
1743
|
+
}
|
|
1744
|
+
const rng = normalizeRange(selection.getRng());
|
|
1745
|
+
const otherLi = dom.getParent(findNextCaretContainer(editor, rng, isForward, root), 'LI', root);
|
|
1746
|
+
const willMergeParentIntoChild = otherLi && (isForward ? dom.isChildOf(li, otherLi) : dom.isChildOf(otherLi, li));
|
|
1747
|
+
if (otherLi && otherLi !== li && !willMergeParentIntoChild) {
|
|
1748
|
+
editor.undoManager.transact(() => {
|
|
1749
|
+
if (isForward) {
|
|
1750
|
+
mergeForward(editor, rng, otherLi, li);
|
|
1751
|
+
} else {
|
|
1752
|
+
if (isFirstChild(li)) {
|
|
1753
|
+
outdentListSelection(editor);
|
|
1754
|
+
} else {
|
|
1755
|
+
mergeBackward(editor, rng, li, otherLi);
|
|
1756
|
+
}
|
|
1757
|
+
}
|
|
1758
|
+
});
|
|
1759
|
+
return true;
|
|
1760
|
+
} else if (willMergeParentIntoChild && !isForward && otherLi !== li) {
|
|
1761
|
+
editor.undoManager.transact(() => {
|
|
1762
|
+
if (rng.commonAncestorContainer.parentElement) {
|
|
1763
|
+
const bookmark = createBookmark(rng);
|
|
1764
|
+
const oldParentElRef = rng.commonAncestorContainer.parentElement;
|
|
1765
|
+
moveChildren(dom, rng.commonAncestorContainer.parentElement, otherLi);
|
|
1766
|
+
oldParentElRef.remove();
|
|
1767
|
+
const resolvedBookmark = resolveBookmark(bookmark);
|
|
1768
|
+
editor.selection.setRng(resolvedBookmark);
|
|
1769
|
+
}
|
|
1770
|
+
});
|
|
1771
|
+
return true;
|
|
1772
|
+
} else if (!otherLi) {
|
|
1773
|
+
if (!isForward && rng.startOffset === 0 && rng.endOffset === 0) {
|
|
1774
|
+
editor.undoManager.transact(() => {
|
|
1775
|
+
flattenListSelection(editor);
|
|
1776
|
+
});
|
|
1777
|
+
return true;
|
|
1778
|
+
}
|
|
2121
1779
|
}
|
|
2122
|
-
|
|
1780
|
+
}
|
|
1781
|
+
return false;
|
|
2123
1782
|
};
|
|
2124
1783
|
const removeBlock = (dom, block, root) => {
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
1784
|
+
const parentBlock = dom.getParent(block.parentNode, dom.isBlock, root);
|
|
1785
|
+
dom.remove(block);
|
|
1786
|
+
if (parentBlock && dom.isEmpty(parentBlock)) {
|
|
1787
|
+
dom.remove(parentBlock);
|
|
1788
|
+
}
|
|
2130
1789
|
};
|
|
2131
1790
|
const backspaceDeleteIntoListCaret = (editor, isForward) => {
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
1791
|
+
const dom = editor.dom;
|
|
1792
|
+
const selectionStartElm = editor.selection.getStart();
|
|
1793
|
+
const root = getClosestEditingHost(editor, selectionStartElm);
|
|
1794
|
+
const block = dom.getParent(selectionStartElm, dom.isBlock, root);
|
|
1795
|
+
if (block && dom.isEmpty(block)) {
|
|
1796
|
+
const rng = normalizeRange(editor.selection.getRng());
|
|
1797
|
+
const otherLi = dom.getParent(findNextCaretContainer(editor, rng, isForward, root), 'LI', root);
|
|
1798
|
+
if (otherLi) {
|
|
1799
|
+
const findValidElement = element => contains$1([
|
|
1800
|
+
'td',
|
|
1801
|
+
'th',
|
|
1802
|
+
'caption'
|
|
1803
|
+
], name(element));
|
|
1804
|
+
const findRoot = node => node.dom === root;
|
|
1805
|
+
const otherLiCell = closest$2(SugarElement.fromDom(otherLi), findValidElement, findRoot);
|
|
1806
|
+
const caretCell = closest$2(SugarElement.fromDom(rng.startContainer), findValidElement, findRoot);
|
|
1807
|
+
if (!equals(otherLiCell, caretCell, eq)) {
|
|
1808
|
+
return false;
|
|
1809
|
+
}
|
|
1810
|
+
editor.undoManager.transact(() => {
|
|
1811
|
+
const parentNode = otherLi.parentNode;
|
|
1812
|
+
removeBlock(dom, block, root);
|
|
1813
|
+
mergeWithAdjacentLists(dom, parentNode);
|
|
1814
|
+
editor.selection.select(otherLi, true);
|
|
1815
|
+
editor.selection.collapse(isForward);
|
|
1816
|
+
});
|
|
1817
|
+
return true;
|
|
1818
|
+
}
|
|
1819
|
+
}
|
|
1820
|
+
return false;
|
|
2159
1821
|
};
|
|
2160
1822
|
const backspaceDeleteCaret = (editor, isForward) => {
|
|
2161
|
-
|
|
1823
|
+
return backspaceDeleteFromListToListCaret(editor, isForward) || backspaceDeleteIntoListCaret(editor, isForward);
|
|
2162
1824
|
};
|
|
2163
|
-
const hasListSelection =
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
};
|
|
2169
|
-
const backspaceDeleteRange = (editor) => {
|
|
2170
|
-
if (hasListSelection(editor)) {
|
|
2171
|
-
editor.undoManager.transact(() => {
|
|
2172
|
-
// Some delete actions may prevent the input event from being fired. If we do not detect it, we fire it ourselves.
|
|
2173
|
-
let shouldFireInput = true;
|
|
2174
|
-
const inputHandler = () => shouldFireInput = false;
|
|
2175
|
-
editor.on('input', inputHandler);
|
|
2176
|
-
editor.execCommand('Delete');
|
|
2177
|
-
editor.off('input', inputHandler);
|
|
2178
|
-
if (shouldFireInput) {
|
|
2179
|
-
editor.dispatch('input');
|
|
2180
|
-
}
|
|
2181
|
-
normalizeLists(editor.dom, editor.getBody());
|
|
2182
|
-
});
|
|
2183
|
-
return true;
|
|
2184
|
-
}
|
|
2185
|
-
return false;
|
|
1825
|
+
const hasListSelection = editor => {
|
|
1826
|
+
const selectionStartElm = editor.selection.getStart();
|
|
1827
|
+
const root = getClosestEditingHost(editor, selectionStartElm);
|
|
1828
|
+
const startListParent = editor.dom.getParent(selectionStartElm, 'LI,DT,DD', root);
|
|
1829
|
+
return startListParent || getSelectedListItems(editor).length > 0;
|
|
2186
1830
|
};
|
|
2187
|
-
const
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
const setup$2 = (editor) => {
|
|
2193
|
-
editor.on('ExecCommand', (e) => {
|
|
2194
|
-
const cmd = e.command.toLowerCase();
|
|
2195
|
-
if ((cmd === 'delete' || cmd === 'forwarddelete') && hasListSelection(editor)) {
|
|
2196
|
-
normalizeLists(editor.dom, editor.getBody());
|
|
2197
|
-
}
|
|
2198
|
-
});
|
|
2199
|
-
editor.on('keydown', (e) => {
|
|
2200
|
-
if (e.keyCode === global$4.BACKSPACE) {
|
|
2201
|
-
if (backspaceDelete(editor, false)) {
|
|
2202
|
-
e.preventDefault();
|
|
2203
|
-
}
|
|
2204
|
-
}
|
|
2205
|
-
else if (e.keyCode === global$4.DELETE) {
|
|
2206
|
-
if (backspaceDelete(editor, true)) {
|
|
2207
|
-
e.preventDefault();
|
|
2208
|
-
}
|
|
2209
|
-
}
|
|
1831
|
+
const backspaceDeleteRange = editor => {
|
|
1832
|
+
if (hasListSelection(editor)) {
|
|
1833
|
+
editor.undoManager.transact(() => {
|
|
1834
|
+
editor.execCommand('Delete');
|
|
1835
|
+
normalizeLists(editor.dom, editor.getBody());
|
|
2210
1836
|
});
|
|
1837
|
+
return true;
|
|
1838
|
+
}
|
|
1839
|
+
return false;
|
|
2211
1840
|
};
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
1841
|
+
const backspaceDelete = (editor, isForward) => {
|
|
1842
|
+
const selection = editor.selection;
|
|
1843
|
+
return !isWithinNonEditableList(editor, selection.getNode()) && (selection.isCollapsed() ? backspaceDeleteCaret(editor, isForward) : backspaceDeleteRange(editor));
|
|
1844
|
+
};
|
|
1845
|
+
const setup$2 = editor => {
|
|
1846
|
+
editor.on('ExecCommand', e => {
|
|
1847
|
+
const cmd = e.command.toLowerCase();
|
|
1848
|
+
if ((cmd === 'delete' || cmd === 'forwarddelete') && hasListSelection(editor)) {
|
|
1849
|
+
normalizeLists(editor.dom, editor.getBody());
|
|
1850
|
+
}
|
|
1851
|
+
});
|
|
1852
|
+
editor.on('keydown', e => {
|
|
1853
|
+
if (e.keyCode === global$4.BACKSPACE) {
|
|
1854
|
+
if (backspaceDelete(editor, false)) {
|
|
1855
|
+
e.preventDefault();
|
|
1856
|
+
}
|
|
1857
|
+
} else if (e.keyCode === global$4.DELETE) {
|
|
1858
|
+
if (backspaceDelete(editor, true)) {
|
|
1859
|
+
e.preventDefault();
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1862
|
+
});
|
|
1863
|
+
};
|
|
1864
|
+
|
|
1865
|
+
const get = editor => ({
|
|
1866
|
+
backspaceDelete: isForward => {
|
|
1867
|
+
backspaceDelete(editor, isForward);
|
|
1868
|
+
}
|
|
2217
1869
|
});
|
|
2218
1870
|
|
|
2219
1871
|
const updateList = (editor, update) => {
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
1872
|
+
const parentList = getParentList(editor);
|
|
1873
|
+
if (parentList === null || isWithinNonEditableList(editor, parentList)) {
|
|
1874
|
+
return;
|
|
1875
|
+
}
|
|
1876
|
+
editor.undoManager.transact(() => {
|
|
1877
|
+
if (isObject(update.styles)) {
|
|
1878
|
+
editor.dom.setStyles(parentList, update.styles);
|
|
1879
|
+
}
|
|
1880
|
+
if (isObject(update.attrs)) {
|
|
1881
|
+
each(update.attrs, (v, k) => editor.dom.setAttrib(parentList, k, v));
|
|
1882
|
+
}
|
|
1883
|
+
});
|
|
1884
|
+
};
|
|
1885
|
+
|
|
1886
|
+
const parseAlphabeticBase26 = str => {
|
|
1887
|
+
const chars = reverse(trim(str).split(''));
|
|
1888
|
+
const values = map(chars, (char, i) => {
|
|
1889
|
+
const charValue = char.toUpperCase().charCodeAt(0) - 'A'.charCodeAt(0) + 1;
|
|
1890
|
+
return Math.pow(26, i) * charValue;
|
|
1891
|
+
});
|
|
1892
|
+
return foldl(values, (sum, v) => sum + v, 0);
|
|
1893
|
+
};
|
|
1894
|
+
const composeAlphabeticBase26 = value => {
|
|
1895
|
+
value--;
|
|
1896
|
+
if (value < 0) {
|
|
1897
|
+
return '';
|
|
1898
|
+
} else {
|
|
1899
|
+
const remainder = value % 26;
|
|
1900
|
+
const quotient = Math.floor(value / 26);
|
|
1901
|
+
const rest = composeAlphabeticBase26(quotient);
|
|
1902
|
+
const char = String.fromCharCode('A'.charCodeAt(0) + remainder);
|
|
1903
|
+
return rest + char;
|
|
1904
|
+
}
|
|
1905
|
+
};
|
|
1906
|
+
const isUppercase = str => /^[A-Z]+$/.test(str);
|
|
1907
|
+
const isLowercase = str => /^[a-z]+$/.test(str);
|
|
1908
|
+
const isNumeric = str => /^[0-9]+$/.test(str);
|
|
1909
|
+
const deduceListType = start => {
|
|
1910
|
+
if (isNumeric(start)) {
|
|
1911
|
+
return 2;
|
|
1912
|
+
} else if (isUppercase(start)) {
|
|
1913
|
+
return 0;
|
|
1914
|
+
} else if (isLowercase(start)) {
|
|
1915
|
+
return 1;
|
|
1916
|
+
} else if (isEmpty$1(start)) {
|
|
1917
|
+
return 3;
|
|
1918
|
+
} else {
|
|
1919
|
+
return 4;
|
|
1920
|
+
}
|
|
1921
|
+
};
|
|
1922
|
+
const parseStartValue = start => {
|
|
1923
|
+
switch (deduceListType(start)) {
|
|
1924
|
+
case 2:
|
|
1925
|
+
return Optional.some({
|
|
1926
|
+
listStyleType: Optional.none(),
|
|
1927
|
+
start
|
|
2231
1928
|
});
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
const chars = reverse(trim(str).split(''));
|
|
2237
|
-
const values = map(chars, (char, i) => {
|
|
2238
|
-
const charValue = char.toUpperCase().charCodeAt(0) - 'A'.charCodeAt(0) + 1;
|
|
2239
|
-
return Math.pow(26, i) * charValue;
|
|
1929
|
+
case 0:
|
|
1930
|
+
return Optional.some({
|
|
1931
|
+
listStyleType: Optional.some('upper-alpha'),
|
|
1932
|
+
start: parseAlphabeticBase26(start).toString()
|
|
2240
1933
|
});
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
const remainder = value % 26;
|
|
2251
|
-
const quotient = Math.floor(value / 26);
|
|
2252
|
-
const rest = composeAlphabeticBase26(quotient);
|
|
2253
|
-
const char = String.fromCharCode('A'.charCodeAt(0) + remainder);
|
|
2254
|
-
return rest + char;
|
|
2255
|
-
}
|
|
2256
|
-
};
|
|
2257
|
-
const isUppercase = (str) => /^[A-Z]+$/.test(str);
|
|
2258
|
-
const isLowercase = (str) => /^[a-z]+$/.test(str);
|
|
2259
|
-
const isNumeric = (str) => /^[0-9]+$/.test(str);
|
|
2260
|
-
const deduceListType = (start) => {
|
|
2261
|
-
if (isNumeric(start)) {
|
|
2262
|
-
return 2 /* ListType.Numeric */;
|
|
2263
|
-
}
|
|
2264
|
-
else if (isUppercase(start)) {
|
|
2265
|
-
return 0 /* ListType.UpperAlpha */;
|
|
2266
|
-
}
|
|
2267
|
-
else if (isLowercase(start)) {
|
|
2268
|
-
return 1 /* ListType.LowerAlpha */;
|
|
2269
|
-
}
|
|
2270
|
-
else if (isEmpty$2(start)) {
|
|
2271
|
-
return 3 /* ListType.None */;
|
|
2272
|
-
}
|
|
2273
|
-
else {
|
|
2274
|
-
return 4 /* ListType.Unknown */;
|
|
2275
|
-
}
|
|
2276
|
-
};
|
|
2277
|
-
const parseStartValue = (start) => {
|
|
2278
|
-
switch (deduceListType(start)) {
|
|
2279
|
-
case 2 /* ListType.Numeric */:
|
|
2280
|
-
return Optional.some({
|
|
2281
|
-
listStyleType: Optional.none(),
|
|
2282
|
-
start
|
|
2283
|
-
});
|
|
2284
|
-
case 0 /* ListType.UpperAlpha */:
|
|
2285
|
-
return Optional.some({
|
|
2286
|
-
listStyleType: Optional.some('upper-alpha'),
|
|
2287
|
-
start: parseAlphabeticBase26(start).toString()
|
|
2288
|
-
});
|
|
2289
|
-
case 1 /* ListType.LowerAlpha */:
|
|
2290
|
-
return Optional.some({
|
|
2291
|
-
listStyleType: Optional.some('lower-alpha'),
|
|
2292
|
-
start: parseAlphabeticBase26(start).toString()
|
|
2293
|
-
});
|
|
2294
|
-
case 3 /* ListType.None */:
|
|
2295
|
-
return Optional.some({
|
|
2296
|
-
listStyleType: Optional.none(),
|
|
2297
|
-
start: ''
|
|
2298
|
-
});
|
|
2299
|
-
case 4 /* ListType.Unknown */:
|
|
2300
|
-
return Optional.none();
|
|
2301
|
-
}
|
|
2302
|
-
};
|
|
2303
|
-
const parseDetail = (detail) => {
|
|
2304
|
-
const start = parseInt(detail.start, 10);
|
|
2305
|
-
if (is$2(detail.listStyleType, 'upper-alpha')) {
|
|
2306
|
-
return composeAlphabeticBase26(start);
|
|
2307
|
-
}
|
|
2308
|
-
else if (is$2(detail.listStyleType, 'lower-alpha')) {
|
|
2309
|
-
return composeAlphabeticBase26(start).toLowerCase();
|
|
2310
|
-
}
|
|
2311
|
-
else {
|
|
2312
|
-
return detail.start;
|
|
2313
|
-
}
|
|
2314
|
-
};
|
|
2315
|
-
|
|
2316
|
-
const open = (editor) => {
|
|
2317
|
-
// Find the current list and skip opening if the selection isn't in an ordered list
|
|
2318
|
-
const currentList = getParentList(editor);
|
|
2319
|
-
if (!isOlNode(currentList) || isWithinNonEditableList(editor, currentList)) {
|
|
2320
|
-
return;
|
|
2321
|
-
}
|
|
2322
|
-
editor.windowManager.open({
|
|
2323
|
-
title: 'List Properties',
|
|
2324
|
-
body: {
|
|
2325
|
-
type: 'panel',
|
|
2326
|
-
items: [
|
|
2327
|
-
{
|
|
2328
|
-
type: 'input',
|
|
2329
|
-
name: 'start',
|
|
2330
|
-
label: 'Start list at number',
|
|
2331
|
-
inputMode: 'numeric'
|
|
2332
|
-
}
|
|
2333
|
-
]
|
|
2334
|
-
},
|
|
2335
|
-
initialData: {
|
|
2336
|
-
start: parseDetail({
|
|
2337
|
-
start: editor.dom.getAttrib(currentList, 'start', '1'),
|
|
2338
|
-
listStyleType: Optional.from(editor.dom.getStyle(currentList, 'list-style-type'))
|
|
2339
|
-
})
|
|
2340
|
-
},
|
|
2341
|
-
buttons: [
|
|
2342
|
-
{
|
|
2343
|
-
type: 'cancel',
|
|
2344
|
-
name: 'cancel',
|
|
2345
|
-
text: 'Cancel'
|
|
2346
|
-
},
|
|
2347
|
-
{
|
|
2348
|
-
type: 'submit',
|
|
2349
|
-
name: 'save',
|
|
2350
|
-
text: 'Save',
|
|
2351
|
-
primary: true
|
|
2352
|
-
}
|
|
2353
|
-
],
|
|
2354
|
-
onSubmit: (api) => {
|
|
2355
|
-
const data = api.getData();
|
|
2356
|
-
parseStartValue(data.start).each((detail) => {
|
|
2357
|
-
editor.execCommand('mceListUpdate', false, {
|
|
2358
|
-
attrs: {
|
|
2359
|
-
start: detail.start === '1' ? '' : detail.start
|
|
2360
|
-
},
|
|
2361
|
-
styles: {
|
|
2362
|
-
'list-style-type': detail.listStyleType.getOr('')
|
|
2363
|
-
}
|
|
2364
|
-
});
|
|
2365
|
-
});
|
|
2366
|
-
api.close();
|
|
2367
|
-
}
|
|
1934
|
+
case 1:
|
|
1935
|
+
return Optional.some({
|
|
1936
|
+
listStyleType: Optional.some('lower-alpha'),
|
|
1937
|
+
start: parseAlphabeticBase26(start).toString()
|
|
1938
|
+
});
|
|
1939
|
+
case 3:
|
|
1940
|
+
return Optional.some({
|
|
1941
|
+
listStyleType: Optional.none(),
|
|
1942
|
+
start: ''
|
|
2368
1943
|
});
|
|
1944
|
+
case 4:
|
|
1945
|
+
return Optional.none();
|
|
1946
|
+
}
|
|
1947
|
+
};
|
|
1948
|
+
const parseDetail = detail => {
|
|
1949
|
+
const start = parseInt(detail.start, 10);
|
|
1950
|
+
if (is$2(detail.listStyleType, 'upper-alpha')) {
|
|
1951
|
+
return composeAlphabeticBase26(start);
|
|
1952
|
+
} else if (is$2(detail.listStyleType, 'lower-alpha')) {
|
|
1953
|
+
return composeAlphabeticBase26(start).toLowerCase();
|
|
1954
|
+
} else {
|
|
1955
|
+
return detail.start;
|
|
1956
|
+
}
|
|
1957
|
+
};
|
|
1958
|
+
|
|
1959
|
+
const open = editor => {
|
|
1960
|
+
const currentList = getParentList(editor);
|
|
1961
|
+
if (!isOlNode(currentList) || isWithinNonEditableList(editor, currentList)) {
|
|
1962
|
+
return;
|
|
1963
|
+
}
|
|
1964
|
+
editor.windowManager.open({
|
|
1965
|
+
title: 'List Properties',
|
|
1966
|
+
body: {
|
|
1967
|
+
type: 'panel',
|
|
1968
|
+
items: [{
|
|
1969
|
+
type: 'input',
|
|
1970
|
+
name: 'start',
|
|
1971
|
+
label: 'Start list at number',
|
|
1972
|
+
inputMode: 'numeric'
|
|
1973
|
+
}]
|
|
1974
|
+
},
|
|
1975
|
+
initialData: {
|
|
1976
|
+
start: parseDetail({
|
|
1977
|
+
start: editor.dom.getAttrib(currentList, 'start', '1'),
|
|
1978
|
+
listStyleType: Optional.from(editor.dom.getStyle(currentList, 'list-style-type'))
|
|
1979
|
+
})
|
|
1980
|
+
},
|
|
1981
|
+
buttons: [
|
|
1982
|
+
{
|
|
1983
|
+
type: 'cancel',
|
|
1984
|
+
name: 'cancel',
|
|
1985
|
+
text: 'Cancel'
|
|
1986
|
+
},
|
|
1987
|
+
{
|
|
1988
|
+
type: 'submit',
|
|
1989
|
+
name: 'save',
|
|
1990
|
+
text: 'Save',
|
|
1991
|
+
primary: true
|
|
1992
|
+
}
|
|
1993
|
+
],
|
|
1994
|
+
onSubmit: api => {
|
|
1995
|
+
const data = api.getData();
|
|
1996
|
+
parseStartValue(data.start).each(detail => {
|
|
1997
|
+
editor.execCommand('mceListUpdate', false, {
|
|
1998
|
+
attrs: { start: detail.start === '1' ? '' : detail.start },
|
|
1999
|
+
styles: { 'list-style-type': detail.listStyleType.getOr('') }
|
|
2000
|
+
});
|
|
2001
|
+
});
|
|
2002
|
+
api.close();
|
|
2003
|
+
}
|
|
2004
|
+
});
|
|
2369
2005
|
};
|
|
2370
2006
|
|
|
2371
2007
|
const queryListCommandState = (editor, listName) => () => {
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
};
|
|
2375
|
-
const registerDialog =
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
};
|
|
2380
|
-
const register$2 =
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
editor
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
editor
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
editor
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
editor
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
editor.addQueryStateHandler('InsertDefinitionList', queryListCommandState(editor, 'DL'));
|
|
2008
|
+
const parentList = getParentList(editor);
|
|
2009
|
+
return isNonNullable(parentList) && parentList.nodeName === listName;
|
|
2010
|
+
};
|
|
2011
|
+
const registerDialog = editor => {
|
|
2012
|
+
editor.addCommand('mceListProps', () => {
|
|
2013
|
+
open(editor);
|
|
2014
|
+
});
|
|
2015
|
+
};
|
|
2016
|
+
const register$2 = editor => {
|
|
2017
|
+
editor.on('BeforeExecCommand', e => {
|
|
2018
|
+
const cmd = e.command.toLowerCase();
|
|
2019
|
+
if (cmd === 'indent') {
|
|
2020
|
+
indentListSelection(editor);
|
|
2021
|
+
} else if (cmd === 'outdent') {
|
|
2022
|
+
outdentListSelection(editor);
|
|
2023
|
+
}
|
|
2024
|
+
});
|
|
2025
|
+
editor.addCommand('InsertUnorderedList', (ui, detail) => {
|
|
2026
|
+
toggleList(editor, 'UL', detail);
|
|
2027
|
+
});
|
|
2028
|
+
editor.addCommand('InsertOrderedList', (ui, detail) => {
|
|
2029
|
+
toggleList(editor, 'OL', detail);
|
|
2030
|
+
});
|
|
2031
|
+
editor.addCommand('InsertDefinitionList', (ui, detail) => {
|
|
2032
|
+
toggleList(editor, 'DL', detail);
|
|
2033
|
+
});
|
|
2034
|
+
editor.addCommand('RemoveList', () => {
|
|
2035
|
+
flattenListSelection(editor);
|
|
2036
|
+
});
|
|
2037
|
+
registerDialog(editor);
|
|
2038
|
+
editor.addCommand('mceListUpdate', (ui, detail) => {
|
|
2039
|
+
if (isObject(detail)) {
|
|
2040
|
+
updateList(editor, detail);
|
|
2041
|
+
}
|
|
2042
|
+
});
|
|
2043
|
+
editor.addQueryStateHandler('InsertUnorderedList', queryListCommandState(editor, 'UL'));
|
|
2044
|
+
editor.addQueryStateHandler('InsertOrderedList', queryListCommandState(editor, 'OL'));
|
|
2045
|
+
editor.addQueryStateHandler('InsertDefinitionList', queryListCommandState(editor, 'DL'));
|
|
2411
2046
|
};
|
|
2412
2047
|
|
|
2413
2048
|
var global = tinymce.util.Tools.resolve('tinymce.html.Node');
|
|
2414
2049
|
|
|
2415
|
-
const isTextNode =
|
|
2416
|
-
const isEmpty =
|
|
2417
|
-
const wrapInvalidChildren =
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2050
|
+
const isTextNode = node => node.type === 3;
|
|
2051
|
+
const isEmpty = nodeBuffer => nodeBuffer.length === 0;
|
|
2052
|
+
const wrapInvalidChildren = list => {
|
|
2053
|
+
const insertListItem = (buffer, refNode) => {
|
|
2054
|
+
const li = global.create('li');
|
|
2055
|
+
each$1(buffer, node => li.append(node));
|
|
2056
|
+
if (refNode) {
|
|
2057
|
+
list.insert(li, refNode, true);
|
|
2058
|
+
} else {
|
|
2059
|
+
list.append(li);
|
|
2060
|
+
}
|
|
2061
|
+
};
|
|
2062
|
+
const reducer = (buffer, node) => {
|
|
2063
|
+
if (isTextNode(node)) {
|
|
2064
|
+
return [
|
|
2065
|
+
...buffer,
|
|
2066
|
+
node
|
|
2067
|
+
];
|
|
2068
|
+
} else if (!isEmpty(buffer) && !isTextNode(node)) {
|
|
2069
|
+
insertListItem(buffer, node);
|
|
2070
|
+
return [];
|
|
2071
|
+
} else {
|
|
2072
|
+
return buffer;
|
|
2073
|
+
}
|
|
2074
|
+
};
|
|
2075
|
+
const restBuffer = foldl(list.children(), reducer, []);
|
|
2076
|
+
if (!isEmpty(restBuffer)) {
|
|
2077
|
+
insertListItem(restBuffer);
|
|
2078
|
+
}
|
|
2079
|
+
};
|
|
2080
|
+
const setup$1 = editor => {
|
|
2081
|
+
editor.on('PreInit', () => {
|
|
2082
|
+
const {parser} = editor;
|
|
2083
|
+
parser.addNodeFilter('ul,ol', nodes => each$1(nodes, wrapInvalidChildren));
|
|
2084
|
+
});
|
|
2085
|
+
};
|
|
2086
|
+
|
|
2087
|
+
const setupTabKey = editor => {
|
|
2088
|
+
editor.on('keydown', e => {
|
|
2089
|
+
if (e.keyCode !== global$4.TAB || global$4.metaKeyPressed(e)) {
|
|
2090
|
+
return;
|
|
2443
2091
|
}
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
parser.addNodeFilter('ul,ol', (nodes) => each$1(nodes, wrapInvalidChildren));
|
|
2092
|
+
editor.undoManager.transact(() => {
|
|
2093
|
+
if (e.shiftKey ? outdentListSelection(editor) : indentListSelection(editor)) {
|
|
2094
|
+
e.preventDefault();
|
|
2095
|
+
}
|
|
2449
2096
|
});
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
const
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2097
|
+
});
|
|
2098
|
+
};
|
|
2099
|
+
const setup = editor => {
|
|
2100
|
+
if (shouldIndentOnTab(editor)) {
|
|
2101
|
+
setupTabKey(editor);
|
|
2102
|
+
}
|
|
2103
|
+
setup$2(editor);
|
|
2104
|
+
};
|
|
2105
|
+
|
|
2106
|
+
const setupToggleButtonHandler = (editor, listName) => api => {
|
|
2107
|
+
const toggleButtonHandler = e => {
|
|
2108
|
+
api.setActive(inList(e.parents, listName));
|
|
2109
|
+
api.setEnabled(!isWithinNonEditableList(editor, e.element) && editor.selection.isEditable());
|
|
2110
|
+
};
|
|
2111
|
+
api.setEnabled(editor.selection.isEditable());
|
|
2112
|
+
return setNodeChangeHandler(editor, toggleButtonHandler);
|
|
2113
|
+
};
|
|
2114
|
+
const register$1 = editor => {
|
|
2115
|
+
const exec = command => () => editor.execCommand(command);
|
|
2116
|
+
if (!editor.hasPlugin('advlist')) {
|
|
2117
|
+
editor.ui.registry.addToggleButton('numlist', {
|
|
2118
|
+
icon: 'ordered-list',
|
|
2119
|
+
active: false,
|
|
2120
|
+
tooltip: 'Numbered list',
|
|
2121
|
+
onAction: exec('InsertOrderedList'),
|
|
2122
|
+
onSetup: setupToggleButtonHandler(editor, 'OL')
|
|
2463
2123
|
});
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
const setupToggleButtonHandler = (editor, listName) => (api) => {
|
|
2473
|
-
const toggleButtonHandler = (e) => {
|
|
2474
|
-
api.setActive(inList(e.parents, listName));
|
|
2475
|
-
api.setEnabled(!isWithinNonEditableList(editor, e.element) && editor.selection.isEditable());
|
|
2476
|
-
};
|
|
2477
|
-
api.setEnabled(editor.selection.isEditable());
|
|
2478
|
-
return setNodeChangeHandler(editor, toggleButtonHandler);
|
|
2479
|
-
};
|
|
2480
|
-
const register$1 = (editor) => {
|
|
2481
|
-
const exec = (command) => () => editor.execCommand(command);
|
|
2482
|
-
if (!editor.hasPlugin('advlist')) {
|
|
2483
|
-
editor.ui.registry.addToggleButton('numlist', {
|
|
2484
|
-
icon: 'ordered-list',
|
|
2485
|
-
active: false,
|
|
2486
|
-
tooltip: 'Numbered list',
|
|
2487
|
-
onAction: exec('InsertOrderedList'),
|
|
2488
|
-
onSetup: setupToggleButtonHandler(editor, 'OL')
|
|
2489
|
-
});
|
|
2490
|
-
editor.ui.registry.addToggleButton('bullist', {
|
|
2491
|
-
icon: 'unordered-list',
|
|
2492
|
-
active: false,
|
|
2493
|
-
tooltip: 'Bullet list',
|
|
2494
|
-
onAction: exec('InsertUnorderedList'),
|
|
2495
|
-
onSetup: setupToggleButtonHandler(editor, 'UL')
|
|
2496
|
-
});
|
|
2497
|
-
}
|
|
2124
|
+
editor.ui.registry.addToggleButton('bullist', {
|
|
2125
|
+
icon: 'unordered-list',
|
|
2126
|
+
active: false,
|
|
2127
|
+
tooltip: 'Bullet list',
|
|
2128
|
+
onAction: exec('InsertUnorderedList'),
|
|
2129
|
+
onSetup: setupToggleButtonHandler(editor, 'UL')
|
|
2130
|
+
});
|
|
2131
|
+
}
|
|
2498
2132
|
};
|
|
2499
2133
|
|
|
2500
|
-
const setupMenuButtonHandler = (editor, listName) =>
|
|
2501
|
-
|
|
2502
|
-
|
|
2134
|
+
const setupMenuButtonHandler = (editor, listName) => api => {
|
|
2135
|
+
const menuButtonHandler = e => api.setEnabled(inList(e.parents, listName) && !isWithinNonEditableList(editor, e.element));
|
|
2136
|
+
return setNodeChangeHandler(editor, menuButtonHandler);
|
|
2503
2137
|
};
|
|
2504
|
-
const register =
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2138
|
+
const register = editor => {
|
|
2139
|
+
const listProperties = {
|
|
2140
|
+
text: 'List properties...',
|
|
2141
|
+
icon: 'ordered-list',
|
|
2142
|
+
onAction: () => editor.execCommand('mceListProps'),
|
|
2143
|
+
onSetup: setupMenuButtonHandler(editor, 'OL')
|
|
2144
|
+
};
|
|
2145
|
+
editor.ui.registry.addMenuItem('listprops', listProperties);
|
|
2146
|
+
editor.ui.registry.addContextMenu('lists', {
|
|
2147
|
+
update: node => {
|
|
2148
|
+
const parentList = getParentList(editor, node);
|
|
2149
|
+
return isOlNode(parentList) ? ['listprops'] : [];
|
|
2150
|
+
}
|
|
2151
|
+
});
|
|
2518
2152
|
};
|
|
2519
2153
|
|
|
2520
2154
|
var Plugin = () => {
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
});
|
|
2155
|
+
global$7.add('lists', editor => {
|
|
2156
|
+
register$3(editor);
|
|
2157
|
+
setup$1(editor);
|
|
2158
|
+
if (!editor.hasPlugin('rtc', true)) {
|
|
2159
|
+
setup(editor);
|
|
2160
|
+
register$2(editor);
|
|
2161
|
+
} else {
|
|
2162
|
+
registerDialog(editor);
|
|
2163
|
+
}
|
|
2164
|
+
register$1(editor);
|
|
2165
|
+
register(editor);
|
|
2166
|
+
return get(editor);
|
|
2167
|
+
});
|
|
2535
2168
|
};
|
|
2536
2169
|
|
|
2537
2170
|
Plugin();
|
|
2538
|
-
/** *****
|
|
2539
|
-
* DO NOT EXPORT ANYTHING
|
|
2540
|
-
*
|
|
2541
|
-
* IF YOU DO ROLLUP WILL LEAVE A GLOBAL ON THE PAGE
|
|
2542
|
-
*******/
|
|
2543
2171
|
|
|
2544
2172
|
})();
|