@dangl/angular-material-shared 2.9.0-beta0037 → 2.9.0-beta0040
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/fesm2022/dangl-angular-material-shared-tiny-mce.mjs +29 -35
- package/fesm2022/dangl-angular-material-shared-tiny-mce.mjs.map +1 -1
- package/fesm2022/dangl-angular-material-shared.mjs +36 -51
- package/fesm2022/dangl-angular-material-shared.mjs.map +1 -1
- package/package.json +11 -10
- package/styles/material-theme.scss +1 -1
- package/styles/material-variables.scss +5 -5
- package/tinymce-assets/icons/default/icons.js +46 -9
- package/tinymce-assets/icons/default/icons.min.js +1 -1
- package/tinymce-assets/models/dom/model.js +8198 -7244
- package/tinymce-assets/models/dom/model.min.js +1 -4
- package/tinymce-assets/plugins/accordion/plugin.js +1174 -879
- package/tinymce-assets/plugins/accordion/plugin.min.js +1 -4
- package/tinymce-assets/plugins/advlist/plugin.js +412 -200
- package/tinymce-assets/plugins/advlist/plugin.min.js +1 -4
- package/tinymce-assets/plugins/anchor/plugin.js +189 -166
- package/tinymce-assets/plugins/anchor/plugin.min.js +1 -4
- package/tinymce-assets/plugins/autolink/plugin.js +310 -220
- package/tinymce-assets/plugins/autolink/plugin.min.js +1 -4
- package/tinymce-assets/plugins/autoresize/plugin.js +180 -149
- package/tinymce-assets/plugins/autoresize/plugin.min.js +1 -4
- package/tinymce-assets/plugins/autosave/plugin.js +208 -189
- package/tinymce-assets/plugins/autosave/plugin.min.js +1 -4
- package/tinymce-assets/plugins/charmap/plugin.js +905 -1566
- package/tinymce-assets/plugins/charmap/plugin.min.js +1 -4
- package/tinymce-assets/plugins/code/plugin.js +73 -61
- package/tinymce-assets/plugins/code/plugin.min.js +0 -3
- package/tinymce-assets/plugins/codesample/plugin.js +3593 -2402
- package/tinymce-assets/plugins/codesample/plugin.min.js +8 -3
- package/tinymce-assets/plugins/directionality/plugin.js +545 -304
- package/tinymce-assets/plugins/directionality/plugin.min.js +1 -4
- package/tinymce-assets/plugins/emoticons/js/emojiimages.min.js +0 -2
- package/tinymce-assets/plugins/emoticons/js/emojis.min.js +0 -1
- package/tinymce-assets/plugins/emoticons/plugin.js +702 -488
- package/tinymce-assets/plugins/emoticons/plugin.min.js +1 -4
- package/tinymce-assets/plugins/fullscreen/plugin.js +1409 -1049
- package/tinymce-assets/plugins/fullscreen/plugin.min.js +1 -4
- package/tinymce-assets/plugins/help/js/i18n/keynav/ar.js +4 -1
- package/tinymce-assets/plugins/help/js/i18n/keynav/bg_BG.js +4 -1
- package/tinymce-assets/plugins/help/js/i18n/keynav/ca.js +4 -1
- package/tinymce-assets/plugins/help/js/i18n/keynav/cs.js +4 -1
- package/tinymce-assets/plugins/help/js/i18n/keynav/da.js +4 -1
- package/tinymce-assets/plugins/help/js/i18n/keynav/de.js +4 -1
- package/tinymce-assets/plugins/help/js/i18n/keynav/el.js +4 -1
- package/tinymce-assets/plugins/help/js/i18n/keynav/en.js +4 -1
- package/tinymce-assets/plugins/help/js/i18n/keynav/es.js +4 -1
- package/tinymce-assets/plugins/help/js/i18n/keynav/eu.js +4 -1
- package/tinymce-assets/plugins/help/js/i18n/keynav/fa.js +4 -1
- package/tinymce-assets/plugins/help/js/i18n/keynav/fi.js +4 -1
- package/tinymce-assets/plugins/help/js/i18n/keynav/fr_FR.js +4 -1
- package/tinymce-assets/plugins/help/js/i18n/keynav/he_IL.js +4 -1
- package/tinymce-assets/plugins/help/js/i18n/keynav/hi.js +4 -1
- package/tinymce-assets/plugins/help/js/i18n/keynav/hr.js +4 -1
- package/tinymce-assets/plugins/help/js/i18n/keynav/hu_HU.js +4 -1
- package/tinymce-assets/plugins/help/js/i18n/keynav/id.js +4 -1
- package/tinymce-assets/plugins/help/js/i18n/keynav/it.js +4 -1
- package/tinymce-assets/plugins/help/js/i18n/keynav/ja.js +4 -1
- package/tinymce-assets/plugins/help/js/i18n/keynav/kk.js +4 -1
- package/tinymce-assets/plugins/help/js/i18n/keynav/ko_KR.js +4 -1
- package/tinymce-assets/plugins/help/js/i18n/keynav/ms.js +4 -1
- package/tinymce-assets/plugins/help/js/i18n/keynav/nb_NO.js +4 -1
- package/tinymce-assets/plugins/help/js/i18n/keynav/nl.js +4 -1
- package/tinymce-assets/plugins/help/js/i18n/keynav/pl.js +4 -1
- package/tinymce-assets/plugins/help/js/i18n/keynav/pt_BR.js +4 -1
- package/tinymce-assets/plugins/help/js/i18n/keynav/pt_PT.js +4 -1
- package/tinymce-assets/plugins/help/js/i18n/keynav/ro.js +4 -1
- package/tinymce-assets/plugins/help/js/i18n/keynav/ru.js +4 -1
- package/tinymce-assets/plugins/help/js/i18n/keynav/sk.js +4 -1
- package/tinymce-assets/plugins/help/js/i18n/keynav/sl_SI.js +5 -2
- package/tinymce-assets/plugins/help/js/i18n/keynav/sv_SE.js +4 -1
- package/tinymce-assets/plugins/help/js/i18n/keynav/th_TH.js +4 -1
- package/tinymce-assets/plugins/help/js/i18n/keynav/tr.js +4 -1
- package/tinymce-assets/plugins/help/js/i18n/keynav/uk.js +4 -1
- package/tinymce-assets/plugins/help/js/i18n/keynav/vi.js +4 -1
- package/tinymce-assets/plugins/help/js/i18n/keynav/zh_CN.js +8 -5
- package/tinymce-assets/plugins/help/js/i18n/keynav/zh_TW.js +4 -1
- package/tinymce-assets/plugins/help/plugin.js +739 -809
- package/tinymce-assets/plugins/help/plugin.min.js +1 -4
- package/tinymce-assets/plugins/image/plugin.js +1475 -1291
- package/tinymce-assets/plugins/image/plugin.min.js +1 -4
- package/tinymce-assets/plugins/importcss/plugin.js +328 -269
- package/tinymce-assets/plugins/importcss/plugin.min.js +1 -4
- package/tinymce-assets/plugins/insertdatetime/plugin.js +140 -141
- package/tinymce-assets/plugins/insertdatetime/plugin.min.js +1 -4
- package/tinymce-assets/plugins/link/plugin.js +1419 -1084
- package/tinymce-assets/plugins/link/plugin.min.js +1 -4
- package/tinymce-assets/plugins/lists/plugin.js +2177 -1805
- package/tinymce-assets/plugins/lists/plugin.min.js +1 -4
- package/tinymce-assets/plugins/media/plugin.js +1305 -1047
- package/tinymce-assets/plugins/media/plugin.min.js +1 -4
- package/tinymce-assets/plugins/nonbreaking/plugin.js +93 -88
- package/tinymce-assets/plugins/nonbreaking/plugin.min.js +0 -3
- package/tinymce-assets/plugins/pagebreak/plugin.js +91 -85
- package/tinymce-assets/plugins/pagebreak/plugin.min.js +0 -3
- package/tinymce-assets/plugins/preview/plugin.js +742 -74
- package/tinymce-assets/plugins/preview/plugin.min.js +1 -4
- package/tinymce-assets/plugins/quickbars/plugin.js +582 -375
- package/tinymce-assets/plugins/quickbars/plugin.min.js +1 -4
- package/tinymce-assets/plugins/save/plugin.js +100 -82
- package/tinymce-assets/plugins/save/plugin.min.js +1 -4
- package/tinymce-assets/plugins/searchreplace/plugin.js +1183 -906
- package/tinymce-assets/plugins/searchreplace/plugin.min.js +1 -4
- package/tinymce-assets/plugins/table/plugin.js +3651 -3094
- package/tinymce-assets/plugins/table/plugin.min.js +1 -4
- package/tinymce-assets/plugins/visualblocks/plugin.js +71 -63
- package/tinymce-assets/plugins/visualblocks/plugin.min.js +1 -4
- package/tinymce-assets/plugins/visualchars/plugin.js +685 -436
- package/tinymce-assets/plugins/visualchars/plugin.min.js +1 -4
- package/tinymce-assets/plugins/wordcount/plugin.js +382 -307
- package/tinymce-assets/plugins/wordcount/plugin.min.js +1 -4
- package/tinymce-assets/skins/content/dark/content.css +9 -0
- package/tinymce-assets/skins/content/dark/content.js +10 -2
- package/tinymce-assets/skins/content/dark/content.min.css +9 -0
- package/tinymce-assets/skins/content/default/content.css +9 -0
- package/tinymce-assets/skins/content/default/content.js +10 -2
- package/tinymce-assets/skins/content/default/content.min.css +9 -0
- package/tinymce-assets/skins/content/document/content.css +9 -0
- package/tinymce-assets/skins/content/document/content.js +10 -2
- package/tinymce-assets/skins/content/document/content.min.css +9 -0
- package/tinymce-assets/skins/content/tinymce-5/content.css +9 -0
- package/tinymce-assets/skins/content/tinymce-5/content.js +10 -2
- package/tinymce-assets/skins/content/tinymce-5/content.min.css +9 -0
- package/tinymce-assets/skins/content/tinymce-5-dark/content.css +9 -0
- package/tinymce-assets/skins/content/tinymce-5-dark/content.js +10 -2
- package/tinymce-assets/skins/content/tinymce-5-dark/content.min.css +9 -0
- package/tinymce-assets/skins/content/writer/content.css +9 -0
- package/tinymce-assets/skins/content/writer/content.js +10 -2
- package/tinymce-assets/skins/content/writer/content.min.css +9 -0
- package/tinymce-assets/skins/ui/oxide/content.css +157 -49
- package/tinymce-assets/skins/ui/oxide/content.inline.css +157 -49
- package/tinymce-assets/skins/ui/oxide/content.inline.js +10 -2
- package/tinymce-assets/skins/ui/oxide/content.inline.min.css +10 -1
- package/tinymce-assets/skins/ui/oxide/content.js +10 -2
- package/tinymce-assets/skins/ui/oxide/content.min.css +10 -1
- package/tinymce-assets/skins/ui/oxide/skin.css +1592 -214
- package/tinymce-assets/skins/ui/oxide/skin.js +1 -2
- package/tinymce-assets/skins/ui/oxide/skin.min.css +1 -1
- package/tinymce-assets/skins/ui/oxide/skin.shadowdom.js +1 -2
- package/tinymce-assets/skins/ui/oxide-dark/content.css +157 -42
- package/tinymce-assets/skins/ui/oxide-dark/content.inline.css +157 -49
- package/tinymce-assets/skins/ui/oxide-dark/content.inline.js +10 -2
- package/tinymce-assets/skins/ui/oxide-dark/content.inline.min.css +10 -1
- package/tinymce-assets/skins/ui/oxide-dark/content.js +10 -2
- package/tinymce-assets/skins/ui/oxide-dark/content.min.css +10 -1
- package/tinymce-assets/skins/ui/oxide-dark/skin.css +1595 -217
- package/tinymce-assets/skins/ui/oxide-dark/skin.js +1 -2
- package/tinymce-assets/skins/ui/oxide-dark/skin.min.css +1 -1
- package/tinymce-assets/skins/ui/oxide-dark/skin.shadowdom.js +1 -2
- package/tinymce-assets/skins/ui/tinymce-5/content.css +157 -49
- package/tinymce-assets/skins/ui/tinymce-5/content.inline.css +157 -49
- package/tinymce-assets/skins/ui/tinymce-5/content.inline.js +10 -2
- package/tinymce-assets/skins/ui/tinymce-5/content.inline.min.css +10 -1
- package/tinymce-assets/skins/ui/tinymce-5/content.js +10 -2
- package/tinymce-assets/skins/ui/tinymce-5/content.min.css +10 -1
- package/tinymce-assets/skins/ui/tinymce-5/skin.css +1606 -203
- package/tinymce-assets/skins/ui/tinymce-5/skin.js +1 -2
- package/tinymce-assets/skins/ui/tinymce-5/skin.min.css +1 -1
- package/tinymce-assets/skins/ui/tinymce-5/skin.shadowdom.js +1 -2
- package/tinymce-assets/skins/ui/tinymce-5-dark/content.css +157 -42
- package/tinymce-assets/skins/ui/tinymce-5-dark/content.inline.css +157 -49
- package/tinymce-assets/skins/ui/tinymce-5-dark/content.inline.js +10 -2
- package/tinymce-assets/skins/ui/tinymce-5-dark/content.inline.min.css +10 -1
- package/tinymce-assets/skins/ui/tinymce-5-dark/content.js +10 -2
- package/tinymce-assets/skins/ui/tinymce-5-dark/content.min.css +10 -1
- package/tinymce-assets/skins/ui/tinymce-5-dark/skin.css +1607 -204
- package/tinymce-assets/skins/ui/tinymce-5-dark/skin.js +1 -2
- package/tinymce-assets/skins/ui/tinymce-5-dark/skin.min.css +1 -1
- package/tinymce-assets/skins/ui/tinymce-5-dark/skin.shadowdom.js +1 -2
- package/tinymce-assets/themes/silver/theme.js +32786 -28738
- package/tinymce-assets/themes/silver/theme.min.js +1 -4
- package/types/dangl-angular-material-shared-tiny-mce.d.ts +12 -13
- package/types/dangl-angular-material-shared.d.ts +26 -26
- package/tinymce-assets/plugins/template/index.js +0 -7
- package/tinymce-assets/plugins/template/plugin.js +0 -567
- package/tinymce-assets/plugins/template/plugin.min.js +0 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* TinyMCE version
|
|
2
|
+
* TinyMCE version 7.9.3 (2026-05-19)
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
(function () {
|
|
@@ -7,389 +7,630 @@
|
|
|
7
7
|
|
|
8
8
|
var global = tinymce.util.Tools.resolve('tinymce.PluginManager');
|
|
9
9
|
|
|
10
|
+
/* eslint-disable @typescript-eslint/no-wrapper-object-types */
|
|
10
11
|
const hasProto = (v, constructor, predicate) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
var _a;
|
|
13
|
+
if (predicate(v, constructor.prototype)) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
// String-based fallback time
|
|
18
|
+
return ((_a = v.constructor) === null || _a === void 0 ? void 0 : _a.name) === constructor.name;
|
|
19
|
+
}
|
|
17
20
|
};
|
|
18
|
-
const typeOf = x => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
21
|
+
const typeOf = (x) => {
|
|
22
|
+
const t = typeof x;
|
|
23
|
+
if (x === null) {
|
|
24
|
+
return 'null';
|
|
25
|
+
}
|
|
26
|
+
else if (t === 'object' && Array.isArray(x)) {
|
|
27
|
+
return 'array';
|
|
28
|
+
}
|
|
29
|
+
else if (t === 'object' && hasProto(x, String, (o, proto) => proto.isPrototypeOf(o))) {
|
|
30
|
+
return 'string';
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
return t;
|
|
34
|
+
}
|
|
29
35
|
};
|
|
30
|
-
const isType$1 = type => value => typeOf(value) === type;
|
|
31
|
-
const isSimpleType = type => value => typeof value === type;
|
|
36
|
+
const isType$1 = (type) => (value) => typeOf(value) === type;
|
|
37
|
+
const isSimpleType = (type) => (value) => typeof value === type;
|
|
32
38
|
const isString = isType$1('string');
|
|
33
39
|
const isBoolean = isSimpleType('boolean');
|
|
34
|
-
const isNullable = a => a === null || a === undefined;
|
|
35
|
-
const isNonNullable = a => !isNullable(a);
|
|
40
|
+
const isNullable = (a) => a === null || a === undefined;
|
|
41
|
+
const isNonNullable = (a) => !isNullable(a);
|
|
36
42
|
const isFunction = isSimpleType('function');
|
|
37
43
|
const isNumber = isSimpleType('number');
|
|
38
44
|
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
return
|
|
43
|
-
|
|
45
|
+
/** Compose two unary functions. Similar to compose, but avoids using Function.prototype.apply. */
|
|
46
|
+
const compose1 = (fbc, fab) => (a) => fbc(fab(a));
|
|
47
|
+
const constant = (value) => {
|
|
48
|
+
return () => {
|
|
49
|
+
return value;
|
|
50
|
+
};
|
|
44
51
|
};
|
|
45
52
|
const never = constant(false);
|
|
46
53
|
|
|
54
|
+
/**
|
|
55
|
+
* The `Optional` type represents a value (of any type) that potentially does
|
|
56
|
+
* not exist. Any `Optional<T>` can either be a `Some<T>` (in which case the
|
|
57
|
+
* value does exist) or a `None` (in which case the value does not exist). This
|
|
58
|
+
* module defines a whole lot of FP-inspired utility functions for dealing with
|
|
59
|
+
* `Optional` objects.
|
|
60
|
+
*
|
|
61
|
+
* Comparison with null or undefined:
|
|
62
|
+
* - We don't get fancy null coalescing operators with `Optional`
|
|
63
|
+
* - We do get fancy helper functions with `Optional`
|
|
64
|
+
* - `Optional` support nesting, and allow for the type to still be nullable (or
|
|
65
|
+
* another `Optional`)
|
|
66
|
+
* - There is no option to turn off strict-optional-checks like there is for
|
|
67
|
+
* strict-null-checks
|
|
68
|
+
*/
|
|
47
69
|
class Optional {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
70
|
+
// The internal representation has a `tag` and a `value`, but both are
|
|
71
|
+
// private: able to be console.logged, but not able to be accessed by code
|
|
72
|
+
constructor(tag, value) {
|
|
73
|
+
this.tag = tag;
|
|
74
|
+
this.value = value;
|
|
75
|
+
}
|
|
76
|
+
// --- Identities ---
|
|
77
|
+
/**
|
|
78
|
+
* Creates a new `Optional<T>` that **does** contain a value.
|
|
79
|
+
*/
|
|
80
|
+
static some(value) {
|
|
81
|
+
return new Optional(true, value);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Create a new `Optional<T>` that **does not** contain a value. `T` can be
|
|
85
|
+
* any type because we don't actually have a `T`.
|
|
86
|
+
*/
|
|
87
|
+
static none() {
|
|
88
|
+
return Optional.singletonNone;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Perform a transform on an `Optional` type. Regardless of whether this
|
|
92
|
+
* `Optional` contains a value or not, `fold` will return a value of type `U`.
|
|
93
|
+
* If this `Optional` does not contain a value, the `U` will be created by
|
|
94
|
+
* calling `onNone`. If this `Optional` does contain a value, the `U` will be
|
|
95
|
+
* created by calling `onSome`.
|
|
96
|
+
*
|
|
97
|
+
* For the FP enthusiasts in the room, this function:
|
|
98
|
+
* 1. Could be used to implement all of the functions below
|
|
99
|
+
* 2. Forms a catamorphism
|
|
100
|
+
*/
|
|
101
|
+
fold(onNone, onSome) {
|
|
102
|
+
if (this.tag) {
|
|
103
|
+
return onSome(this.value);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
return onNone();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Determine if this `Optional` object contains a value.
|
|
111
|
+
*/
|
|
112
|
+
isSome() {
|
|
113
|
+
return this.tag;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Determine if this `Optional` object **does not** contain a value.
|
|
117
|
+
*/
|
|
118
|
+
isNone() {
|
|
119
|
+
return !this.tag;
|
|
120
|
+
}
|
|
121
|
+
// --- Functor (name stolen from Haskell / maths) ---
|
|
122
|
+
/**
|
|
123
|
+
* Perform a transform on an `Optional` object, **if** there is a value. If
|
|
124
|
+
* you provide a function to turn a T into a U, this is the function you use
|
|
125
|
+
* to turn an `Optional<T>` into an `Optional<U>`. If this **does** contain
|
|
126
|
+
* a value then the output will also contain a value (that value being the
|
|
127
|
+
* output of `mapper(this.value)`), and if this **does not** contain a value
|
|
128
|
+
* then neither will the output.
|
|
129
|
+
*/
|
|
130
|
+
map(mapper) {
|
|
131
|
+
if (this.tag) {
|
|
132
|
+
return Optional.some(mapper(this.value));
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
return Optional.none();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
// --- Monad (name stolen from Haskell / maths) ---
|
|
139
|
+
/**
|
|
140
|
+
* Perform a transform on an `Optional` object, **if** there is a value.
|
|
141
|
+
* Unlike `map`, here the transform itself also returns an `Optional`.
|
|
142
|
+
*/
|
|
143
|
+
bind(binder) {
|
|
144
|
+
if (this.tag) {
|
|
145
|
+
return binder(this.value);
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
return Optional.none();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
// --- Traversable (name stolen from Haskell / maths) ---
|
|
152
|
+
/**
|
|
153
|
+
* For a given predicate, this function finds out if there **exists** a value
|
|
154
|
+
* inside this `Optional` object that meets the predicate. In practice, this
|
|
155
|
+
* means that for `Optional`s that do not contain a value it returns false (as
|
|
156
|
+
* no predicate-meeting value exists).
|
|
157
|
+
*/
|
|
158
|
+
exists(predicate) {
|
|
159
|
+
return this.tag && predicate(this.value);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* For a given predicate, this function finds out if **all** the values inside
|
|
163
|
+
* this `Optional` object meet the predicate. In practice, this means that
|
|
164
|
+
* for `Optional`s that do not contain a value it returns true (as all 0
|
|
165
|
+
* objects do meet the predicate).
|
|
166
|
+
*/
|
|
167
|
+
forall(predicate) {
|
|
168
|
+
return !this.tag || predicate(this.value);
|
|
169
|
+
}
|
|
170
|
+
filter(predicate) {
|
|
171
|
+
if (!this.tag || predicate(this.value)) {
|
|
172
|
+
return this;
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
return Optional.none();
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
// --- Getters ---
|
|
179
|
+
/**
|
|
180
|
+
* Get the value out of the inside of the `Optional` object, using a default
|
|
181
|
+
* `replacement` value if the provided `Optional` object does not contain a
|
|
182
|
+
* value.
|
|
183
|
+
*/
|
|
184
|
+
getOr(replacement) {
|
|
185
|
+
return this.tag ? this.value : replacement;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Get the value out of the inside of the `Optional` object, using a default
|
|
189
|
+
* `replacement` value if the provided `Optional` object does not contain a
|
|
190
|
+
* value. Unlike `getOr`, in this method the `replacement` object is also
|
|
191
|
+
* `Optional` - meaning that this method will always return an `Optional`.
|
|
192
|
+
*/
|
|
193
|
+
or(replacement) {
|
|
194
|
+
return this.tag ? this : replacement;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Get the value out of the inside of the `Optional` object, using a default
|
|
198
|
+
* `replacement` value if the provided `Optional` object does not contain a
|
|
199
|
+
* value. Unlike `getOr`, in this method the `replacement` value is
|
|
200
|
+
* "thunked" - that is to say that you don't pass a value to `getOrThunk`, you
|
|
201
|
+
* pass a function which (if called) will **return** the `value` you want to
|
|
202
|
+
* use.
|
|
203
|
+
*/
|
|
204
|
+
getOrThunk(thunk) {
|
|
205
|
+
return this.tag ? this.value : thunk();
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Get the value out of the inside of the `Optional` object, using a default
|
|
209
|
+
* `replacement` value if the provided Optional object does not contain a
|
|
210
|
+
* value.
|
|
211
|
+
*
|
|
212
|
+
* Unlike `or`, in this method the `replacement` value is "thunked" - that is
|
|
213
|
+
* to say that you don't pass a value to `orThunk`, you pass a function which
|
|
214
|
+
* (if called) will **return** the `value` you want to use.
|
|
215
|
+
*
|
|
216
|
+
* Unlike `getOrThunk`, in this method the `replacement` value is also
|
|
217
|
+
* `Optional`, meaning that this method will always return an `Optional`.
|
|
218
|
+
*/
|
|
219
|
+
orThunk(thunk) {
|
|
220
|
+
return this.tag ? this : thunk();
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Get the value out of the inside of the `Optional` object, throwing an
|
|
224
|
+
* exception if the provided `Optional` object does not contain a value.
|
|
225
|
+
*
|
|
226
|
+
* WARNING:
|
|
227
|
+
* You should only be using this function if you know that the `Optional`
|
|
228
|
+
* object **is not** empty (otherwise you're throwing exceptions in production
|
|
229
|
+
* code, which is bad).
|
|
230
|
+
*
|
|
231
|
+
* In tests this is more acceptable.
|
|
232
|
+
*
|
|
233
|
+
* Prefer other methods to this, such as `.each`.
|
|
234
|
+
*/
|
|
235
|
+
getOrDie(message) {
|
|
236
|
+
if (!this.tag) {
|
|
237
|
+
throw new Error(message !== null && message !== void 0 ? message : 'Called getOrDie on None');
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
return this.value;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
// --- Interop with null and undefined ---
|
|
244
|
+
/**
|
|
245
|
+
* Creates an `Optional` value from a nullable (or undefined-able) input.
|
|
246
|
+
* Null, or undefined, is converted to `None`, and anything else is converted
|
|
247
|
+
* to `Some`.
|
|
248
|
+
*/
|
|
249
|
+
static from(value) {
|
|
250
|
+
return isNonNullable(value) ? Optional.some(value) : Optional.none();
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Converts an `Optional` to a nullable type, by getting the value if it
|
|
254
|
+
* exists, or returning `null` if it does not.
|
|
255
|
+
*/
|
|
256
|
+
getOrNull() {
|
|
257
|
+
return this.tag ? this.value : null;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Converts an `Optional` to an undefined-able type, by getting the value if
|
|
261
|
+
* it exists, or returning `undefined` if it does not.
|
|
262
|
+
*/
|
|
263
|
+
getOrUndefined() {
|
|
264
|
+
return this.value;
|
|
265
|
+
}
|
|
266
|
+
// --- Utilities ---
|
|
267
|
+
/**
|
|
268
|
+
* If the `Optional` contains a value, perform an action on that value.
|
|
269
|
+
* Unlike the rest of the methods on this type, `.each` has side-effects. If
|
|
270
|
+
* you want to transform an `Optional<T>` **into** something, then this is not
|
|
271
|
+
* the method for you. If you want to use an `Optional<T>` to **do**
|
|
272
|
+
* something, then this is the method for you - provided you're okay with not
|
|
273
|
+
* doing anything in the case where the `Optional` doesn't have a value inside
|
|
274
|
+
* it. If you're not sure whether your use-case fits into transforming
|
|
275
|
+
* **into** something or **doing** something, check whether it has a return
|
|
276
|
+
* value. If it does, you should be performing a transform.
|
|
277
|
+
*/
|
|
278
|
+
each(worker) {
|
|
279
|
+
if (this.tag) {
|
|
280
|
+
worker(this.value);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Turn the `Optional` object into an array that contains all of the values
|
|
285
|
+
* stored inside the `Optional`. In practice, this means the output will have
|
|
286
|
+
* either 0 or 1 elements.
|
|
287
|
+
*/
|
|
288
|
+
toArray() {
|
|
289
|
+
return this.tag ? [this.value] : [];
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Turn the `Optional` object into a string for debugging or printing. Not
|
|
293
|
+
* recommended for production code, but good for debugging. Also note that
|
|
294
|
+
* these days an `Optional` object can be logged to the console directly, and
|
|
295
|
+
* its inner value (if it exists) will be visible.
|
|
296
|
+
*/
|
|
297
|
+
toString() {
|
|
298
|
+
return this.tag ? `some(${this.value})` : 'none()';
|
|
299
|
+
}
|
|
137
300
|
}
|
|
301
|
+
// Sneaky optimisation: every instance of Optional.none is identical, so just
|
|
302
|
+
// reuse the same object
|
|
138
303
|
Optional.singletonNone = new Optional(false);
|
|
139
304
|
|
|
305
|
+
/* eslint-disable @typescript-eslint/unbound-method */
|
|
306
|
+
const nativeSlice = Array.prototype.slice;
|
|
140
307
|
const map = (xs, f) => {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
308
|
+
// pre-allocating array size when it's guaranteed to be known
|
|
309
|
+
// http://jsperf.com/push-allocated-vs-dynamic/22
|
|
310
|
+
const len = xs.length;
|
|
311
|
+
const r = new Array(len);
|
|
312
|
+
for (let i = 0; i < len; i++) {
|
|
313
|
+
const x = xs[i];
|
|
314
|
+
r[i] = f(x, i);
|
|
315
|
+
}
|
|
316
|
+
return r;
|
|
148
317
|
};
|
|
318
|
+
// Unwound implementing other functions in terms of each.
|
|
319
|
+
// The code size is roughly the same, and it should allow for better optimisation.
|
|
320
|
+
// const each = function<T, U>(xs: T[], f: (x: T, i?: number, xs?: T[]) => void): void {
|
|
149
321
|
const each = (xs, f) => {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
322
|
+
for (let i = 0, len = xs.length; i < len; i++) {
|
|
323
|
+
const x = xs[i];
|
|
324
|
+
f(x, i);
|
|
325
|
+
}
|
|
154
326
|
};
|
|
155
327
|
const filter = (xs, pred) => {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
328
|
+
const r = [];
|
|
329
|
+
for (let i = 0, len = xs.length; i < len; i++) {
|
|
330
|
+
const x = xs[i];
|
|
331
|
+
if (pred(x, i)) {
|
|
332
|
+
r.push(x);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
return r;
|
|
164
336
|
};
|
|
165
|
-
|
|
166
|
-
const DOCUMENT = 9;
|
|
167
|
-
const DOCUMENT_FRAGMENT = 11;
|
|
168
|
-
const ELEMENT = 1;
|
|
169
|
-
const TEXT = 3;
|
|
337
|
+
isFunction(Array.from) ? Array.from : (x) => nativeSlice.call(x);
|
|
170
338
|
|
|
171
339
|
const fromHtml = (html, scope) => {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
340
|
+
const doc = scope || document;
|
|
341
|
+
const div = doc.createElement('div');
|
|
342
|
+
div.innerHTML = html;
|
|
343
|
+
if (!div.hasChildNodes() || div.childNodes.length > 1) {
|
|
344
|
+
const message = 'HTML does not have a single root node';
|
|
345
|
+
// eslint-disable-next-line no-console
|
|
346
|
+
console.error(message, html);
|
|
347
|
+
throw new Error(message);
|
|
348
|
+
}
|
|
349
|
+
return fromDom(div.childNodes[0]);
|
|
181
350
|
};
|
|
182
351
|
const fromTag = (tag, scope) => {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
352
|
+
const doc = scope || document;
|
|
353
|
+
const node = doc.createElement(tag);
|
|
354
|
+
return fromDom(node);
|
|
186
355
|
};
|
|
187
356
|
const fromText = (text, scope) => {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
357
|
+
const doc = scope || document;
|
|
358
|
+
const node = doc.createTextNode(text);
|
|
359
|
+
return fromDom(node);
|
|
191
360
|
};
|
|
192
|
-
const fromDom = node => {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
361
|
+
const fromDom = (node) => {
|
|
362
|
+
// TODO: Consider removing this check, but left atm for safety
|
|
363
|
+
if (node === null || node === undefined) {
|
|
364
|
+
throw new Error('Node cannot be null or undefined');
|
|
365
|
+
}
|
|
366
|
+
return {
|
|
367
|
+
dom: node
|
|
368
|
+
};
|
|
197
369
|
};
|
|
198
370
|
const fromPoint = (docElm, x, y) => Optional.from(docElm.dom.elementFromPoint(x, y)).map(fromDom);
|
|
371
|
+
// tslint:disable-next-line:variable-name
|
|
199
372
|
const SugarElement = {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
373
|
+
fromHtml,
|
|
374
|
+
fromTag,
|
|
375
|
+
fromText,
|
|
376
|
+
fromDom,
|
|
377
|
+
fromPoint
|
|
205
378
|
};
|
|
206
379
|
|
|
380
|
+
const DOCUMENT_FRAGMENT = 11;
|
|
381
|
+
const ELEMENT = 1;
|
|
382
|
+
const TEXT = 3;
|
|
383
|
+
|
|
207
384
|
const is = (element, selector) => {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
385
|
+
const dom = element.dom;
|
|
386
|
+
if (dom.nodeType !== ELEMENT) {
|
|
387
|
+
return false;
|
|
388
|
+
}
|
|
389
|
+
else {
|
|
390
|
+
const elem = dom;
|
|
391
|
+
if (elem.matches !== undefined) {
|
|
392
|
+
return elem.matches(selector);
|
|
393
|
+
}
|
|
394
|
+
else if (elem.msMatchesSelector !== undefined) {
|
|
395
|
+
return elem.msMatchesSelector(selector);
|
|
396
|
+
}
|
|
397
|
+
else if (elem.webkitMatchesSelector !== undefined) {
|
|
398
|
+
return elem.webkitMatchesSelector(selector);
|
|
399
|
+
}
|
|
400
|
+
else if (elem.mozMatchesSelector !== undefined) {
|
|
401
|
+
// cast to any as mozMatchesSelector doesn't exist in TS DOM lib
|
|
402
|
+
return elem.mozMatchesSelector(selector);
|
|
403
|
+
}
|
|
404
|
+
else {
|
|
405
|
+
throw new Error('Browser lacks native selectors');
|
|
406
|
+
} // unfortunately we can't throw this on startup :(
|
|
407
|
+
}
|
|
225
408
|
};
|
|
226
409
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
const r = element.dom.nodeName;
|
|
231
|
-
return r.toLowerCase();
|
|
410
|
+
const name = (element) => {
|
|
411
|
+
const r = element.dom.nodeName;
|
|
412
|
+
return r.toLowerCase();
|
|
232
413
|
};
|
|
233
|
-
const type = element => element.dom.nodeType;
|
|
234
|
-
const isType = t => element => type(element) === t;
|
|
414
|
+
const type = (element) => element.dom.nodeType;
|
|
415
|
+
const isType = (t) => (element) => type(element) === t;
|
|
235
416
|
const isElement = isType(ELEMENT);
|
|
236
417
|
const isText = isType(TEXT);
|
|
237
|
-
const isDocument = isType(DOCUMENT);
|
|
238
418
|
const isDocumentFragment = isType(DOCUMENT_FRAGMENT);
|
|
239
|
-
const isTag = tag => e => isElement(e) && name(e) === tag;
|
|
419
|
+
const isTag = (tag) => (e) => isElement(e) && name(e) === tag;
|
|
240
420
|
|
|
241
|
-
const
|
|
242
|
-
const
|
|
243
|
-
|
|
244
|
-
|
|
421
|
+
const parent = (element) => Optional.from(element.dom.parentNode).map(SugarElement.fromDom);
|
|
422
|
+
const children$2 = (element) => map(element.dom.childNodes, SugarElement.fromDom);
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Is the element a ShadowRoot?
|
|
426
|
+
*
|
|
427
|
+
* Note: this is insufficient to test if any element is a shadow root, but it is sufficient to differentiate between
|
|
428
|
+
* a Document and a ShadowRoot.
|
|
429
|
+
*/
|
|
430
|
+
const isShadowRoot = (dos) => isDocumentFragment(dos) && isNonNullable(dos.dom.host);
|
|
431
|
+
const getRootNode = (e) => SugarElement.fromDom(e.dom.getRootNode());
|
|
432
|
+
/** If this element is in a ShadowRoot, return it. */
|
|
433
|
+
const getShadowRoot = (e) => {
|
|
434
|
+
const r = getRootNode(e);
|
|
435
|
+
return isShadowRoot(r) ? Optional.some(r) : Optional.none();
|
|
436
|
+
};
|
|
437
|
+
/** Return the host of a ShadowRoot.
|
|
438
|
+
*
|
|
439
|
+
* This function will throw if Shadow DOM is unsupported in the browser, or if the host is null.
|
|
440
|
+
* If you actually have a ShadowRoot, this shouldn't happen.
|
|
441
|
+
*/
|
|
442
|
+
const getShadowHost = (e) => SugarElement.fromDom(e.dom.host);
|
|
245
443
|
|
|
246
444
|
const rawSet = (dom, key, value) => {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
445
|
+
/*
|
|
446
|
+
* JQuery coerced everything to a string, and silently did nothing on text node/null/undefined.
|
|
447
|
+
*
|
|
448
|
+
* We fail on those invalid cases, only allowing numbers and booleans.
|
|
449
|
+
*/
|
|
450
|
+
if (isString(value) || isBoolean(value) || isNumber(value)) {
|
|
451
|
+
dom.setAttribute(key, value + '');
|
|
452
|
+
}
|
|
453
|
+
else {
|
|
454
|
+
// eslint-disable-next-line no-console
|
|
455
|
+
console.error('Invalid call to Attribute.set. Key ', key, ':: Value ', value, ':: Element ', dom);
|
|
456
|
+
throw new Error('Attribute value was not simple');
|
|
457
|
+
}
|
|
253
458
|
};
|
|
254
459
|
const set = (element, key, value) => {
|
|
255
|
-
|
|
460
|
+
rawSet(element.dom, key, value);
|
|
256
461
|
};
|
|
257
462
|
const remove = (element, key) => {
|
|
258
|
-
|
|
463
|
+
element.dom.removeAttribute(key);
|
|
259
464
|
};
|
|
260
465
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
const
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
return isShadowRoot(r) ? Optional.some(r) : Optional.none();
|
|
267
|
-
};
|
|
268
|
-
const getShadowHost = e => SugarElement.fromDom(e.dom.host);
|
|
466
|
+
// some elements, such as mathml, don't have style attributes
|
|
467
|
+
// others, such as angular elements, have style attributes that aren't a CSSStyleDeclaration
|
|
468
|
+
const isSupported = (dom) =>
|
|
469
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
470
|
+
dom.style !== undefined && isFunction(dom.style.getPropertyValue);
|
|
269
471
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
472
|
+
// Node.contains() is very, very, very good performance
|
|
473
|
+
// http://jsperf.com/closest-vs-contains/5
|
|
474
|
+
const inBody = (element) => {
|
|
475
|
+
// Technically this is only required on IE, where contains() returns false for text nodes.
|
|
476
|
+
// But it's cheap enough to run everywhere and Sugar doesn't have platform detection (yet).
|
|
477
|
+
const dom = isText(element) ? element.dom.parentNode : element.dom;
|
|
478
|
+
// use ownerDocument.body to ensure this works inside iframes.
|
|
479
|
+
// Normally contains is bad because an element "contains" itself, but here we want that.
|
|
480
|
+
if (dom === undefined || dom === null || dom.ownerDocument === null) {
|
|
481
|
+
return false;
|
|
482
|
+
}
|
|
483
|
+
const doc = dom.ownerDocument;
|
|
484
|
+
return getShadowRoot(SugarElement.fromDom(dom)).fold(() => doc.body.contains(dom), compose1(inBody, getShadowHost));
|
|
277
485
|
};
|
|
278
486
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
487
|
+
/*
|
|
488
|
+
* NOTE: For certain properties, this returns the "used value" which is subtly different to the "computed value" (despite calling getComputedStyle).
|
|
489
|
+
* Blame CSS 2.0.
|
|
490
|
+
*
|
|
491
|
+
* https://developer.mozilla.org/en-US/docs/Web/CSS/used_value
|
|
492
|
+
*/
|
|
493
|
+
const get = (element, property) => {
|
|
494
|
+
const dom = element.dom;
|
|
495
|
+
/*
|
|
496
|
+
* IE9 and above per
|
|
497
|
+
* https://developer.mozilla.org/en/docs/Web/API/window.getComputedStyle
|
|
498
|
+
*
|
|
499
|
+
* Not in numerosity, because it doesn't memoize and looking this up dynamically in performance critical code would be horrendous.
|
|
500
|
+
*
|
|
501
|
+
* JQuery has some magic here for IE popups, but we don't really need that.
|
|
502
|
+
* It also uses element.ownerDocument.defaultView to handle iframes but that hasn't been required since FF 3.6.
|
|
503
|
+
*/
|
|
504
|
+
const styles = window.getComputedStyle(dom);
|
|
505
|
+
const r = styles.getPropertyValue(property);
|
|
506
|
+
// jquery-ism: If r is an empty string, check that the element is not in a document. If it isn't, return the raw value.
|
|
507
|
+
// Turns out we do this a lot.
|
|
508
|
+
return (r === '' && !inBody(element)) ? getUnsafeProperty(dom, property) : r;
|
|
292
509
|
};
|
|
510
|
+
// removed: support for dom().style[property] where prop is camel case instead of normal property name
|
|
511
|
+
// empty string is what the browsers (IE11 and Chrome) return when the propertyValue doesn't exists.
|
|
512
|
+
const getUnsafeProperty = (dom, property) => isSupported(dom) ? dom.style.getPropertyValue(property) : '';
|
|
293
513
|
|
|
294
|
-
const
|
|
295
|
-
|
|
296
|
-
const isSupported = dom => dom.style !== undefined && isFunction(dom.style.getPropertyValue);
|
|
514
|
+
const getDirection = (element) => get(element, 'direction') === 'rtl' ? 'rtl' : 'ltr';
|
|
297
515
|
|
|
298
|
-
const
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
516
|
+
const ancestor$1 = (scope, predicate, isRoot) => {
|
|
517
|
+
let element = scope.dom;
|
|
518
|
+
const stop = isFunction(isRoot) ? isRoot : never;
|
|
519
|
+
while (element.parentNode) {
|
|
520
|
+
element = element.parentNode;
|
|
521
|
+
const el = SugarElement.fromDom(element);
|
|
522
|
+
if (predicate(el)) {
|
|
523
|
+
return Optional.some(el);
|
|
524
|
+
}
|
|
525
|
+
else if (stop(el)) {
|
|
526
|
+
break;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
return Optional.none();
|
|
303
530
|
};
|
|
304
|
-
const getUnsafeProperty = (dom, property) => isSupported(dom) ? dom.style.getPropertyValue(property) : '';
|
|
305
531
|
|
|
306
|
-
const
|
|
532
|
+
const ancestor = (scope, selector, isRoot) => ancestor$1(scope, (e) => is(e, selector), isRoot);
|
|
307
533
|
|
|
308
534
|
const children$1 = (scope, predicate) => filter(children$2(scope), predicate);
|
|
309
535
|
|
|
310
|
-
const children = (scope, selector) =>
|
|
536
|
+
const children = (scope, selector) =>
|
|
537
|
+
// It may surprise you to learn this is exactly what JQuery does
|
|
538
|
+
// TODO: Avoid all the wrapping and unwrapping
|
|
539
|
+
children$1(scope, (e) => is(e, selector));
|
|
311
540
|
|
|
312
|
-
const getParentElement = element => parent(element).filter(isElement);
|
|
541
|
+
const getParentElement = (element) => parent(element).filter(isElement);
|
|
542
|
+
// if the block is a list item, we need to get the parent of the list itself
|
|
313
543
|
const getNormalizedBlock = (element, isListItem) => {
|
|
314
|
-
|
|
315
|
-
|
|
544
|
+
const normalizedElement = isListItem ? ancestor(element, 'ol,ul') : Optional.some(element);
|
|
545
|
+
return normalizedElement.getOr(element);
|
|
316
546
|
};
|
|
317
547
|
const isListItem = isTag('li');
|
|
318
548
|
const setDirOnElements = (dom, blocks, dir) => {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
549
|
+
each(blocks, (block) => {
|
|
550
|
+
const blockElement = SugarElement.fromDom(block);
|
|
551
|
+
const isBlockElementListItem = isListItem(blockElement);
|
|
552
|
+
const normalizedBlock = getNormalizedBlock(blockElement, isBlockElementListItem);
|
|
553
|
+
const normalizedBlockParent = getParentElement(normalizedBlock);
|
|
554
|
+
normalizedBlockParent.each((parent) => {
|
|
555
|
+
// TINY-9314: Remove any inline direction style to ensure that it is only set when necessary and that
|
|
556
|
+
// the dir attribute is favored
|
|
557
|
+
dom.setStyle(normalizedBlock.dom, 'direction', null);
|
|
558
|
+
const parentDirection = getDirection(parent);
|
|
559
|
+
if (parentDirection === dir) {
|
|
560
|
+
remove(normalizedBlock, 'dir');
|
|
561
|
+
}
|
|
562
|
+
else {
|
|
563
|
+
set(normalizedBlock, 'dir', dir);
|
|
564
|
+
}
|
|
565
|
+
// TINY-9314: Set an inline direction style if computed css direction is still not as desired. This can
|
|
566
|
+
// happen when the direction style is derived from a stylesheet.
|
|
567
|
+
if (getDirection(normalizedBlock) !== dir) {
|
|
568
|
+
dom.setStyle(normalizedBlock.dom, 'direction', dir);
|
|
569
|
+
}
|
|
570
|
+
// Remove dir attr and direction style from list children
|
|
571
|
+
if (isBlockElementListItem) {
|
|
572
|
+
const listItems = children(normalizedBlock, 'li[dir],li[style]');
|
|
573
|
+
each(listItems, (listItem) => {
|
|
574
|
+
remove(listItem, 'dir');
|
|
575
|
+
dom.setStyle(listItem.dom, 'direction', null);
|
|
576
|
+
});
|
|
577
|
+
}
|
|
340
578
|
});
|
|
341
|
-
}
|
|
342
579
|
});
|
|
343
|
-
});
|
|
344
580
|
};
|
|
345
581
|
const setDir = (editor, dir) => {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
582
|
+
if (editor.selection.isEditable()) {
|
|
583
|
+
setDirOnElements(editor.dom, editor.selection.getSelectedBlocks(), dir);
|
|
584
|
+
editor.nodeChanged();
|
|
585
|
+
}
|
|
350
586
|
};
|
|
351
587
|
|
|
352
|
-
const register$1 = editor => {
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
588
|
+
const register$1 = (editor) => {
|
|
589
|
+
editor.addCommand('mceDirectionLTR', () => {
|
|
590
|
+
setDir(editor, 'ltr');
|
|
591
|
+
});
|
|
592
|
+
editor.addCommand('mceDirectionRTL', () => {
|
|
593
|
+
setDir(editor, 'rtl');
|
|
594
|
+
});
|
|
359
595
|
};
|
|
360
596
|
|
|
361
|
-
const getNodeChangeHandler = (editor, dir) => api => {
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
597
|
+
const getNodeChangeHandler = (editor, dir) => (api) => {
|
|
598
|
+
const nodeChangeHandler = (e) => {
|
|
599
|
+
const element = SugarElement.fromDom(e.element);
|
|
600
|
+
api.setActive(getDirection(element) === dir);
|
|
601
|
+
api.setEnabled(editor.selection.isEditable());
|
|
602
|
+
};
|
|
603
|
+
editor.on('NodeChange', nodeChangeHandler);
|
|
365
604
|
api.setEnabled(editor.selection.isEditable());
|
|
366
|
-
|
|
367
|
-
editor.on('NodeChange', nodeChangeHandler);
|
|
368
|
-
api.setEnabled(editor.selection.isEditable());
|
|
369
|
-
return () => editor.off('NodeChange', nodeChangeHandler);
|
|
605
|
+
return () => editor.off('NodeChange', nodeChangeHandler);
|
|
370
606
|
};
|
|
371
|
-
const register = editor => {
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
607
|
+
const register = (editor) => {
|
|
608
|
+
editor.ui.registry.addToggleButton('ltr', {
|
|
609
|
+
tooltip: 'Left to right',
|
|
610
|
+
icon: 'ltr',
|
|
611
|
+
onAction: () => editor.execCommand('mceDirectionLTR'),
|
|
612
|
+
onSetup: getNodeChangeHandler(editor, 'ltr')
|
|
613
|
+
});
|
|
614
|
+
editor.ui.registry.addToggleButton('rtl', {
|
|
615
|
+
tooltip: 'Right to left',
|
|
616
|
+
icon: 'rtl',
|
|
617
|
+
onAction: () => editor.execCommand('mceDirectionRTL'),
|
|
618
|
+
onSetup: getNodeChangeHandler(editor, 'rtl')
|
|
619
|
+
});
|
|
384
620
|
};
|
|
385
621
|
|
|
386
622
|
var Plugin = () => {
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
623
|
+
global.add('directionality', (editor) => {
|
|
624
|
+
register$1(editor);
|
|
625
|
+
register(editor);
|
|
626
|
+
});
|
|
391
627
|
};
|
|
392
628
|
|
|
393
629
|
Plugin();
|
|
630
|
+
/** *****
|
|
631
|
+
* DO NOT EXPORT ANYTHING
|
|
632
|
+
*
|
|
633
|
+
* IF YOU DO ROLLUP WILL LEAVE A GLOBAL ON THE PAGE
|
|
634
|
+
*******/
|
|
394
635
|
|
|
395
636
|
})();
|