@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.
Files changed (175) hide show
  1. package/fesm2022/dangl-angular-material-shared-tiny-mce.mjs +29 -35
  2. package/fesm2022/dangl-angular-material-shared-tiny-mce.mjs.map +1 -1
  3. package/fesm2022/dangl-angular-material-shared.mjs +36 -51
  4. package/fesm2022/dangl-angular-material-shared.mjs.map +1 -1
  5. package/package.json +11 -10
  6. package/styles/material-theme.scss +1 -1
  7. package/styles/material-variables.scss +5 -5
  8. package/tinymce-assets/icons/default/icons.js +46 -9
  9. package/tinymce-assets/icons/default/icons.min.js +1 -1
  10. package/tinymce-assets/models/dom/model.js +8198 -7244
  11. package/tinymce-assets/models/dom/model.min.js +1 -4
  12. package/tinymce-assets/plugins/accordion/plugin.js +1174 -879
  13. package/tinymce-assets/plugins/accordion/plugin.min.js +1 -4
  14. package/tinymce-assets/plugins/advlist/plugin.js +412 -200
  15. package/tinymce-assets/plugins/advlist/plugin.min.js +1 -4
  16. package/tinymce-assets/plugins/anchor/plugin.js +189 -166
  17. package/tinymce-assets/plugins/anchor/plugin.min.js +1 -4
  18. package/tinymce-assets/plugins/autolink/plugin.js +310 -220
  19. package/tinymce-assets/plugins/autolink/plugin.min.js +1 -4
  20. package/tinymce-assets/plugins/autoresize/plugin.js +180 -149
  21. package/tinymce-assets/plugins/autoresize/plugin.min.js +1 -4
  22. package/tinymce-assets/plugins/autosave/plugin.js +208 -189
  23. package/tinymce-assets/plugins/autosave/plugin.min.js +1 -4
  24. package/tinymce-assets/plugins/charmap/plugin.js +905 -1566
  25. package/tinymce-assets/plugins/charmap/plugin.min.js +1 -4
  26. package/tinymce-assets/plugins/code/plugin.js +73 -61
  27. package/tinymce-assets/plugins/code/plugin.min.js +0 -3
  28. package/tinymce-assets/plugins/codesample/plugin.js +3593 -2402
  29. package/tinymce-assets/plugins/codesample/plugin.min.js +8 -3
  30. package/tinymce-assets/plugins/directionality/plugin.js +545 -304
  31. package/tinymce-assets/plugins/directionality/plugin.min.js +1 -4
  32. package/tinymce-assets/plugins/emoticons/js/emojiimages.min.js +0 -2
  33. package/tinymce-assets/plugins/emoticons/js/emojis.min.js +0 -1
  34. package/tinymce-assets/plugins/emoticons/plugin.js +702 -488
  35. package/tinymce-assets/plugins/emoticons/plugin.min.js +1 -4
  36. package/tinymce-assets/plugins/fullscreen/plugin.js +1409 -1049
  37. package/tinymce-assets/plugins/fullscreen/plugin.min.js +1 -4
  38. package/tinymce-assets/plugins/help/js/i18n/keynav/ar.js +4 -1
  39. package/tinymce-assets/plugins/help/js/i18n/keynav/bg_BG.js +4 -1
  40. package/tinymce-assets/plugins/help/js/i18n/keynav/ca.js +4 -1
  41. package/tinymce-assets/plugins/help/js/i18n/keynav/cs.js +4 -1
  42. package/tinymce-assets/plugins/help/js/i18n/keynav/da.js +4 -1
  43. package/tinymce-assets/plugins/help/js/i18n/keynav/de.js +4 -1
  44. package/tinymce-assets/plugins/help/js/i18n/keynav/el.js +4 -1
  45. package/tinymce-assets/plugins/help/js/i18n/keynav/en.js +4 -1
  46. package/tinymce-assets/plugins/help/js/i18n/keynav/es.js +4 -1
  47. package/tinymce-assets/plugins/help/js/i18n/keynav/eu.js +4 -1
  48. package/tinymce-assets/plugins/help/js/i18n/keynav/fa.js +4 -1
  49. package/tinymce-assets/plugins/help/js/i18n/keynav/fi.js +4 -1
  50. package/tinymce-assets/plugins/help/js/i18n/keynav/fr_FR.js +4 -1
  51. package/tinymce-assets/plugins/help/js/i18n/keynav/he_IL.js +4 -1
  52. package/tinymce-assets/plugins/help/js/i18n/keynav/hi.js +4 -1
  53. package/tinymce-assets/plugins/help/js/i18n/keynav/hr.js +4 -1
  54. package/tinymce-assets/plugins/help/js/i18n/keynav/hu_HU.js +4 -1
  55. package/tinymce-assets/plugins/help/js/i18n/keynav/id.js +4 -1
  56. package/tinymce-assets/plugins/help/js/i18n/keynav/it.js +4 -1
  57. package/tinymce-assets/plugins/help/js/i18n/keynav/ja.js +4 -1
  58. package/tinymce-assets/plugins/help/js/i18n/keynav/kk.js +4 -1
  59. package/tinymce-assets/plugins/help/js/i18n/keynav/ko_KR.js +4 -1
  60. package/tinymce-assets/plugins/help/js/i18n/keynav/ms.js +4 -1
  61. package/tinymce-assets/plugins/help/js/i18n/keynav/nb_NO.js +4 -1
  62. package/tinymce-assets/plugins/help/js/i18n/keynav/nl.js +4 -1
  63. package/tinymce-assets/plugins/help/js/i18n/keynav/pl.js +4 -1
  64. package/tinymce-assets/plugins/help/js/i18n/keynav/pt_BR.js +4 -1
  65. package/tinymce-assets/plugins/help/js/i18n/keynav/pt_PT.js +4 -1
  66. package/tinymce-assets/plugins/help/js/i18n/keynav/ro.js +4 -1
  67. package/tinymce-assets/plugins/help/js/i18n/keynav/ru.js +4 -1
  68. package/tinymce-assets/plugins/help/js/i18n/keynav/sk.js +4 -1
  69. package/tinymce-assets/plugins/help/js/i18n/keynav/sl_SI.js +5 -2
  70. package/tinymce-assets/plugins/help/js/i18n/keynav/sv_SE.js +4 -1
  71. package/tinymce-assets/plugins/help/js/i18n/keynav/th_TH.js +4 -1
  72. package/tinymce-assets/plugins/help/js/i18n/keynav/tr.js +4 -1
  73. package/tinymce-assets/plugins/help/js/i18n/keynav/uk.js +4 -1
  74. package/tinymce-assets/plugins/help/js/i18n/keynav/vi.js +4 -1
  75. package/tinymce-assets/plugins/help/js/i18n/keynav/zh_CN.js +8 -5
  76. package/tinymce-assets/plugins/help/js/i18n/keynav/zh_TW.js +4 -1
  77. package/tinymce-assets/plugins/help/plugin.js +739 -809
  78. package/tinymce-assets/plugins/help/plugin.min.js +1 -4
  79. package/tinymce-assets/plugins/image/plugin.js +1475 -1291
  80. package/tinymce-assets/plugins/image/plugin.min.js +1 -4
  81. package/tinymce-assets/plugins/importcss/plugin.js +328 -269
  82. package/tinymce-assets/plugins/importcss/plugin.min.js +1 -4
  83. package/tinymce-assets/plugins/insertdatetime/plugin.js +140 -141
  84. package/tinymce-assets/plugins/insertdatetime/plugin.min.js +1 -4
  85. package/tinymce-assets/plugins/link/plugin.js +1419 -1084
  86. package/tinymce-assets/plugins/link/plugin.min.js +1 -4
  87. package/tinymce-assets/plugins/lists/plugin.js +2177 -1805
  88. package/tinymce-assets/plugins/lists/plugin.min.js +1 -4
  89. package/tinymce-assets/plugins/media/plugin.js +1305 -1047
  90. package/tinymce-assets/plugins/media/plugin.min.js +1 -4
  91. package/tinymce-assets/plugins/nonbreaking/plugin.js +93 -88
  92. package/tinymce-assets/plugins/nonbreaking/plugin.min.js +0 -3
  93. package/tinymce-assets/plugins/pagebreak/plugin.js +91 -85
  94. package/tinymce-assets/plugins/pagebreak/plugin.min.js +0 -3
  95. package/tinymce-assets/plugins/preview/plugin.js +742 -74
  96. package/tinymce-assets/plugins/preview/plugin.min.js +1 -4
  97. package/tinymce-assets/plugins/quickbars/plugin.js +582 -375
  98. package/tinymce-assets/plugins/quickbars/plugin.min.js +1 -4
  99. package/tinymce-assets/plugins/save/plugin.js +100 -82
  100. package/tinymce-assets/plugins/save/plugin.min.js +1 -4
  101. package/tinymce-assets/plugins/searchreplace/plugin.js +1183 -906
  102. package/tinymce-assets/plugins/searchreplace/plugin.min.js +1 -4
  103. package/tinymce-assets/plugins/table/plugin.js +3651 -3094
  104. package/tinymce-assets/plugins/table/plugin.min.js +1 -4
  105. package/tinymce-assets/plugins/visualblocks/plugin.js +71 -63
  106. package/tinymce-assets/plugins/visualblocks/plugin.min.js +1 -4
  107. package/tinymce-assets/plugins/visualchars/plugin.js +685 -436
  108. package/tinymce-assets/plugins/visualchars/plugin.min.js +1 -4
  109. package/tinymce-assets/plugins/wordcount/plugin.js +382 -307
  110. package/tinymce-assets/plugins/wordcount/plugin.min.js +1 -4
  111. package/tinymce-assets/skins/content/dark/content.css +9 -0
  112. package/tinymce-assets/skins/content/dark/content.js +10 -2
  113. package/tinymce-assets/skins/content/dark/content.min.css +9 -0
  114. package/tinymce-assets/skins/content/default/content.css +9 -0
  115. package/tinymce-assets/skins/content/default/content.js +10 -2
  116. package/tinymce-assets/skins/content/default/content.min.css +9 -0
  117. package/tinymce-assets/skins/content/document/content.css +9 -0
  118. package/tinymce-assets/skins/content/document/content.js +10 -2
  119. package/tinymce-assets/skins/content/document/content.min.css +9 -0
  120. package/tinymce-assets/skins/content/tinymce-5/content.css +9 -0
  121. package/tinymce-assets/skins/content/tinymce-5/content.js +10 -2
  122. package/tinymce-assets/skins/content/tinymce-5/content.min.css +9 -0
  123. package/tinymce-assets/skins/content/tinymce-5-dark/content.css +9 -0
  124. package/tinymce-assets/skins/content/tinymce-5-dark/content.js +10 -2
  125. package/tinymce-assets/skins/content/tinymce-5-dark/content.min.css +9 -0
  126. package/tinymce-assets/skins/content/writer/content.css +9 -0
  127. package/tinymce-assets/skins/content/writer/content.js +10 -2
  128. package/tinymce-assets/skins/content/writer/content.min.css +9 -0
  129. package/tinymce-assets/skins/ui/oxide/content.css +157 -49
  130. package/tinymce-assets/skins/ui/oxide/content.inline.css +157 -49
  131. package/tinymce-assets/skins/ui/oxide/content.inline.js +10 -2
  132. package/tinymce-assets/skins/ui/oxide/content.inline.min.css +10 -1
  133. package/tinymce-assets/skins/ui/oxide/content.js +10 -2
  134. package/tinymce-assets/skins/ui/oxide/content.min.css +10 -1
  135. package/tinymce-assets/skins/ui/oxide/skin.css +1592 -214
  136. package/tinymce-assets/skins/ui/oxide/skin.js +1 -2
  137. package/tinymce-assets/skins/ui/oxide/skin.min.css +1 -1
  138. package/tinymce-assets/skins/ui/oxide/skin.shadowdom.js +1 -2
  139. package/tinymce-assets/skins/ui/oxide-dark/content.css +157 -42
  140. package/tinymce-assets/skins/ui/oxide-dark/content.inline.css +157 -49
  141. package/tinymce-assets/skins/ui/oxide-dark/content.inline.js +10 -2
  142. package/tinymce-assets/skins/ui/oxide-dark/content.inline.min.css +10 -1
  143. package/tinymce-assets/skins/ui/oxide-dark/content.js +10 -2
  144. package/tinymce-assets/skins/ui/oxide-dark/content.min.css +10 -1
  145. package/tinymce-assets/skins/ui/oxide-dark/skin.css +1595 -217
  146. package/tinymce-assets/skins/ui/oxide-dark/skin.js +1 -2
  147. package/tinymce-assets/skins/ui/oxide-dark/skin.min.css +1 -1
  148. package/tinymce-assets/skins/ui/oxide-dark/skin.shadowdom.js +1 -2
  149. package/tinymce-assets/skins/ui/tinymce-5/content.css +157 -49
  150. package/tinymce-assets/skins/ui/tinymce-5/content.inline.css +157 -49
  151. package/tinymce-assets/skins/ui/tinymce-5/content.inline.js +10 -2
  152. package/tinymce-assets/skins/ui/tinymce-5/content.inline.min.css +10 -1
  153. package/tinymce-assets/skins/ui/tinymce-5/content.js +10 -2
  154. package/tinymce-assets/skins/ui/tinymce-5/content.min.css +10 -1
  155. package/tinymce-assets/skins/ui/tinymce-5/skin.css +1606 -203
  156. package/tinymce-assets/skins/ui/tinymce-5/skin.js +1 -2
  157. package/tinymce-assets/skins/ui/tinymce-5/skin.min.css +1 -1
  158. package/tinymce-assets/skins/ui/tinymce-5/skin.shadowdom.js +1 -2
  159. package/tinymce-assets/skins/ui/tinymce-5-dark/content.css +157 -42
  160. package/tinymce-assets/skins/ui/tinymce-5-dark/content.inline.css +157 -49
  161. package/tinymce-assets/skins/ui/tinymce-5-dark/content.inline.js +10 -2
  162. package/tinymce-assets/skins/ui/tinymce-5-dark/content.inline.min.css +10 -1
  163. package/tinymce-assets/skins/ui/tinymce-5-dark/content.js +10 -2
  164. package/tinymce-assets/skins/ui/tinymce-5-dark/content.min.css +10 -1
  165. package/tinymce-assets/skins/ui/tinymce-5-dark/skin.css +1607 -204
  166. package/tinymce-assets/skins/ui/tinymce-5-dark/skin.js +1 -2
  167. package/tinymce-assets/skins/ui/tinymce-5-dark/skin.min.css +1 -1
  168. package/tinymce-assets/skins/ui/tinymce-5-dark/skin.shadowdom.js +1 -2
  169. package/tinymce-assets/themes/silver/theme.js +32786 -28738
  170. package/tinymce-assets/themes/silver/theme.min.js +1 -4
  171. package/types/dangl-angular-material-shared-tiny-mce.d.ts +12 -13
  172. package/types/dangl-angular-material-shared.d.ts +26 -26
  173. package/tinymce-assets/plugins/template/index.js +0 -7
  174. package/tinymce-assets/plugins/template/plugin.js +0 -567
  175. package/tinymce-assets/plugins/template/plugin.min.js +0 -4
@@ -1,5 +1,5 @@
1
1
  /**
2
- * TinyMCE version 6.8.3 (2024-02-08)
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
- 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
- }
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
- 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
- }
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
- const compose1 = (fbc, fab) => a => fbc(fab(a));
40
- const constant = value => {
41
- return () => {
42
- return value;
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
- constructor(tag, value) {
49
- this.tag = tag;
50
- this.value = value;
51
- }
52
- static some(value) {
53
- return new Optional(true, value);
54
- }
55
- static none() {
56
- return Optional.singletonNone;
57
- }
58
- fold(onNone, onSome) {
59
- if (this.tag) {
60
- return onSome(this.value);
61
- } else {
62
- return onNone();
63
- }
64
- }
65
- isSome() {
66
- return this.tag;
67
- }
68
- isNone() {
69
- return !this.tag;
70
- }
71
- map(mapper) {
72
- if (this.tag) {
73
- return Optional.some(mapper(this.value));
74
- } else {
75
- return Optional.none();
76
- }
77
- }
78
- bind(binder) {
79
- if (this.tag) {
80
- return binder(this.value);
81
- } else {
82
- return Optional.none();
83
- }
84
- }
85
- exists(predicate) {
86
- return this.tag && predicate(this.value);
87
- }
88
- forall(predicate) {
89
- return !this.tag || predicate(this.value);
90
- }
91
- filter(predicate) {
92
- if (!this.tag || predicate(this.value)) {
93
- return this;
94
- } else {
95
- return Optional.none();
96
- }
97
- }
98
- getOr(replacement) {
99
- return this.tag ? this.value : replacement;
100
- }
101
- or(replacement) {
102
- return this.tag ? this : replacement;
103
- }
104
- getOrThunk(thunk) {
105
- return this.tag ? this.value : thunk();
106
- }
107
- orThunk(thunk) {
108
- return this.tag ? this : thunk();
109
- }
110
- getOrDie(message) {
111
- if (!this.tag) {
112
- throw new Error(message !== null && message !== void 0 ? message : 'Called getOrDie on None');
113
- } else {
114
- return this.value;
115
- }
116
- }
117
- static from(value) {
118
- return isNonNullable(value) ? Optional.some(value) : Optional.none();
119
- }
120
- getOrNull() {
121
- return this.tag ? this.value : null;
122
- }
123
- getOrUndefined() {
124
- return this.value;
125
- }
126
- each(worker) {
127
- if (this.tag) {
128
- worker(this.value);
129
- }
130
- }
131
- toArray() {
132
- return this.tag ? [this.value] : [];
133
- }
134
- toString() {
135
- return this.tag ? `some(${ this.value })` : 'none()';
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
- const len = xs.length;
142
- const r = new Array(len);
143
- for (let i = 0; i < len; i++) {
144
- const x = xs[i];
145
- r[i] = f(x, i);
146
- }
147
- return r;
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
- for (let i = 0, len = xs.length; i < len; i++) {
151
- const x = xs[i];
152
- f(x, i);
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
- const r = [];
157
- for (let i = 0, len = xs.length; i < len; i++) {
158
- const x = xs[i];
159
- if (pred(x, i)) {
160
- r.push(x);
161
- }
162
- }
163
- return r;
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
- const doc = scope || document;
173
- const div = doc.createElement('div');
174
- div.innerHTML = html;
175
- if (!div.hasChildNodes() || div.childNodes.length > 1) {
176
- const message = 'HTML does not have a single root node';
177
- console.error(message, html);
178
- throw new Error(message);
179
- }
180
- return fromDom(div.childNodes[0]);
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
- const doc = scope || document;
184
- const node = doc.createElement(tag);
185
- return fromDom(node);
352
+ const doc = scope || document;
353
+ const node = doc.createElement(tag);
354
+ return fromDom(node);
186
355
  };
187
356
  const fromText = (text, scope) => {
188
- const doc = scope || document;
189
- const node = doc.createTextNode(text);
190
- return fromDom(node);
357
+ const doc = scope || document;
358
+ const node = doc.createTextNode(text);
359
+ return fromDom(node);
191
360
  };
192
- const fromDom = node => {
193
- if (node === null || node === undefined) {
194
- throw new Error('Node cannot be null or undefined');
195
- }
196
- return { dom: node };
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
- fromHtml,
201
- fromTag,
202
- fromText,
203
- fromDom,
204
- fromPoint
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
- const dom = element.dom;
209
- if (dom.nodeType !== ELEMENT) {
210
- return false;
211
- } else {
212
- const elem = dom;
213
- if (elem.matches !== undefined) {
214
- return elem.matches(selector);
215
- } else if (elem.msMatchesSelector !== undefined) {
216
- return elem.msMatchesSelector(selector);
217
- } else if (elem.webkitMatchesSelector !== undefined) {
218
- return elem.webkitMatchesSelector(selector);
219
- } else if (elem.mozMatchesSelector !== undefined) {
220
- return elem.mozMatchesSelector(selector);
221
- } else {
222
- throw new Error('Browser lacks native selectors');
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
- typeof window !== 'undefined' ? window : Function('return this;')();
228
-
229
- const name = element => {
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 owner = element => SugarElement.fromDom(element.dom.ownerDocument);
242
- const documentOrOwner = dos => isDocument(dos) ? dos : owner(dos);
243
- const parent = element => Optional.from(element.dom.parentNode).map(SugarElement.fromDom);
244
- const children$2 = element => map(element.dom.childNodes, SugarElement.fromDom);
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
- if (isString(value) || isBoolean(value) || isNumber(value)) {
248
- dom.setAttribute(key, value + '');
249
- } else {
250
- console.error('Invalid call to Attribute.set. Key ', key, ':: Value ', value, ':: Element ', dom);
251
- throw new Error('Attribute value was not simple');
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
- rawSet(element.dom, key, value);
460
+ rawSet(element.dom, key, value);
256
461
  };
257
462
  const remove = (element, key) => {
258
- element.dom.removeAttribute(key);
463
+ element.dom.removeAttribute(key);
259
464
  };
260
465
 
261
- const isShadowRoot = dos => isDocumentFragment(dos) && isNonNullable(dos.dom.host);
262
- const supported = isFunction(Element.prototype.attachShadow) && isFunction(Node.prototype.getRootNode);
263
- const getRootNode = supported ? e => SugarElement.fromDom(e.dom.getRootNode()) : documentOrOwner;
264
- const getShadowRoot = e => {
265
- const r = getRootNode(e);
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
- const inBody = element => {
271
- const dom = isText(element) ? element.dom.parentNode : element.dom;
272
- if (dom === undefined || dom === null || dom.ownerDocument === null) {
273
- return false;
274
- }
275
- const doc = dom.ownerDocument;
276
- return getShadowRoot(SugarElement.fromDom(dom)).fold(() => doc.body.contains(dom), compose1(inBody, getShadowHost));
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
- const ancestor$1 = (scope, predicate, isRoot) => {
280
- let element = scope.dom;
281
- const stop = isFunction(isRoot) ? isRoot : never;
282
- while (element.parentNode) {
283
- element = element.parentNode;
284
- const el = SugarElement.fromDom(element);
285
- if (predicate(el)) {
286
- return Optional.some(el);
287
- } else if (stop(el)) {
288
- break;
289
- }
290
- }
291
- return Optional.none();
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 ancestor = (scope, selector, isRoot) => ancestor$1(scope, e => is(e, selector), isRoot);
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 get = (element, property) => {
299
- const dom = element.dom;
300
- const styles = window.getComputedStyle(dom);
301
- const r = styles.getPropertyValue(property);
302
- return r === '' && !inBody(element) ? getUnsafeProperty(dom, property) : r;
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 getDirection = element => get(element, 'direction') === 'rtl' ? 'rtl' : 'ltr';
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) => children$1(scope, e => is(e, 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
- const normalizedElement = isListItem ? ancestor(element, 'ol,ul') : Optional.some(element);
315
- return normalizedElement.getOr(element);
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
- each(blocks, block => {
320
- const blockElement = SugarElement.fromDom(block);
321
- const isBlockElementListItem = isListItem(blockElement);
322
- const normalizedBlock = getNormalizedBlock(blockElement, isBlockElementListItem);
323
- const normalizedBlockParent = getParentElement(normalizedBlock);
324
- normalizedBlockParent.each(parent => {
325
- dom.setStyle(normalizedBlock.dom, 'direction', null);
326
- const parentDirection = getDirection(parent);
327
- if (parentDirection === dir) {
328
- remove(normalizedBlock, 'dir');
329
- } else {
330
- set(normalizedBlock, 'dir', dir);
331
- }
332
- if (getDirection(normalizedBlock) !== dir) {
333
- dom.setStyle(normalizedBlock.dom, 'direction', dir);
334
- }
335
- if (isBlockElementListItem) {
336
- const listItems = children(normalizedBlock, 'li[dir],li[style]');
337
- each(listItems, listItem => {
338
- remove(listItem, 'dir');
339
- dom.setStyle(listItem.dom, 'direction', null);
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
- if (editor.selection.isEditable()) {
347
- setDirOnElements(editor.dom, editor.selection.getSelectedBlocks(), dir);
348
- editor.nodeChanged();
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
- editor.addCommand('mceDirectionLTR', () => {
354
- setDir(editor, 'ltr');
355
- });
356
- editor.addCommand('mceDirectionRTL', () => {
357
- setDir(editor, 'rtl');
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
- const nodeChangeHandler = e => {
363
- const element = SugarElement.fromDom(e.element);
364
- api.setActive(getDirection(element) === dir);
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
- editor.ui.registry.addToggleButton('ltr', {
373
- tooltip: 'Left to right',
374
- icon: 'ltr',
375
- onAction: () => editor.execCommand('mceDirectionLTR'),
376
- onSetup: getNodeChangeHandler(editor, 'ltr')
377
- });
378
- editor.ui.registry.addToggleButton('rtl', {
379
- tooltip: 'Right to left',
380
- icon: 'rtl',
381
- onAction: () => editor.execCommand('mceDirectionRTL'),
382
- onSetup: getNodeChangeHandler(editor, 'rtl')
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
- global.add('directionality', editor => {
388
- register$1(editor);
389
- register(editor);
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
  })();