@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,441 +7,648 @@
|
|
|
7
7
|
|
|
8
8
|
var global$1 = 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 = type => value => typeOf(value) === type;
|
|
31
|
-
const isSimpleType = type => value => typeof value === type;
|
|
36
|
+
const isType = (type) => (value) => typeOf(value) === type;
|
|
37
|
+
const isSimpleType = (type) => (value) => typeof value === type;
|
|
32
38
|
const isString = isType('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
|
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const valid = isBoolean(value) || isString(value);
|
|
43
|
-
if (valid) {
|
|
44
|
-
if (isBoolean(value)) {
|
|
45
|
-
return {
|
|
46
|
-
value: value ? defaultValue : '',
|
|
47
|
-
valid
|
|
48
|
-
};
|
|
49
|
-
} else {
|
|
50
|
-
return {
|
|
51
|
-
value: value.trim(),
|
|
52
|
-
valid
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
} else {
|
|
56
|
-
return {
|
|
57
|
-
valid: false,
|
|
58
|
-
message: 'Must be a boolean or string.'
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
const defaultSelectionToolbar = 'bold italic | quicklink h2 h3 blockquote';
|
|
63
|
-
registerOption('quickbars_selection_toolbar', {
|
|
64
|
-
processor: toolbarProcessor(defaultSelectionToolbar),
|
|
65
|
-
default: defaultSelectionToolbar
|
|
66
|
-
});
|
|
67
|
-
const defaultInsertToolbar = 'quickimage quicktable';
|
|
68
|
-
registerOption('quickbars_insert_toolbar', {
|
|
69
|
-
processor: toolbarProcessor(defaultInsertToolbar),
|
|
70
|
-
default: defaultInsertToolbar
|
|
71
|
-
});
|
|
72
|
-
const defaultImageToolbar = 'alignleft aligncenter alignright';
|
|
73
|
-
registerOption('quickbars_image_toolbar', {
|
|
74
|
-
processor: toolbarProcessor(defaultImageToolbar),
|
|
75
|
-
default: defaultImageToolbar
|
|
76
|
-
});
|
|
44
|
+
const constant = (value) => {
|
|
45
|
+
return () => {
|
|
46
|
+
return value;
|
|
47
|
+
};
|
|
77
48
|
};
|
|
78
|
-
const
|
|
79
|
-
const getInsertToolbarItems = option('quickbars_insert_toolbar');
|
|
80
|
-
const getImageToolbarItems = option('quickbars_image_toolbar');
|
|
49
|
+
const never = constant(false);
|
|
81
50
|
|
|
51
|
+
/**
|
|
52
|
+
* The `Optional` type represents a value (of any type) that potentially does
|
|
53
|
+
* not exist. Any `Optional<T>` can either be a `Some<T>` (in which case the
|
|
54
|
+
* value does exist) or a `None` (in which case the value does not exist). This
|
|
55
|
+
* module defines a whole lot of FP-inspired utility functions for dealing with
|
|
56
|
+
* `Optional` objects.
|
|
57
|
+
*
|
|
58
|
+
* Comparison with null or undefined:
|
|
59
|
+
* - We don't get fancy null coalescing operators with `Optional`
|
|
60
|
+
* - We do get fancy helper functions with `Optional`
|
|
61
|
+
* - `Optional` support nesting, and allow for the type to still be nullable (or
|
|
62
|
+
* another `Optional`)
|
|
63
|
+
* - There is no option to turn off strict-optional-checks like there is for
|
|
64
|
+
* strict-null-checks
|
|
65
|
+
*/
|
|
66
|
+
class Optional {
|
|
67
|
+
// The internal representation has a `tag` and a `value`, but both are
|
|
68
|
+
// private: able to be console.logged, but not able to be accessed by code
|
|
69
|
+
constructor(tag, value) {
|
|
70
|
+
this.tag = tag;
|
|
71
|
+
this.value = value;
|
|
72
|
+
}
|
|
73
|
+
// --- Identities ---
|
|
74
|
+
/**
|
|
75
|
+
* Creates a new `Optional<T>` that **does** contain a value.
|
|
76
|
+
*/
|
|
77
|
+
static some(value) {
|
|
78
|
+
return new Optional(true, value);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Create a new `Optional<T>` that **does not** contain a value. `T` can be
|
|
82
|
+
* any type because we don't actually have a `T`.
|
|
83
|
+
*/
|
|
84
|
+
static none() {
|
|
85
|
+
return Optional.singletonNone;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Perform a transform on an `Optional` type. Regardless of whether this
|
|
89
|
+
* `Optional` contains a value or not, `fold` will return a value of type `U`.
|
|
90
|
+
* If this `Optional` does not contain a value, the `U` will be created by
|
|
91
|
+
* calling `onNone`. If this `Optional` does contain a value, the `U` will be
|
|
92
|
+
* created by calling `onSome`.
|
|
93
|
+
*
|
|
94
|
+
* For the FP enthusiasts in the room, this function:
|
|
95
|
+
* 1. Could be used to implement all of the functions below
|
|
96
|
+
* 2. Forms a catamorphism
|
|
97
|
+
*/
|
|
98
|
+
fold(onNone, onSome) {
|
|
99
|
+
if (this.tag) {
|
|
100
|
+
return onSome(this.value);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
return onNone();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Determine if this `Optional` object contains a value.
|
|
108
|
+
*/
|
|
109
|
+
isSome() {
|
|
110
|
+
return this.tag;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Determine if this `Optional` object **does not** contain a value.
|
|
114
|
+
*/
|
|
115
|
+
isNone() {
|
|
116
|
+
return !this.tag;
|
|
117
|
+
}
|
|
118
|
+
// --- Functor (name stolen from Haskell / maths) ---
|
|
119
|
+
/**
|
|
120
|
+
* Perform a transform on an `Optional` object, **if** there is a value. If
|
|
121
|
+
* you provide a function to turn a T into a U, this is the function you use
|
|
122
|
+
* to turn an `Optional<T>` into an `Optional<U>`. If this **does** contain
|
|
123
|
+
* a value then the output will also contain a value (that value being the
|
|
124
|
+
* output of `mapper(this.value)`), and if this **does not** contain a value
|
|
125
|
+
* then neither will the output.
|
|
126
|
+
*/
|
|
127
|
+
map(mapper) {
|
|
128
|
+
if (this.tag) {
|
|
129
|
+
return Optional.some(mapper(this.value));
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
return Optional.none();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
// --- Monad (name stolen from Haskell / maths) ---
|
|
136
|
+
/**
|
|
137
|
+
* Perform a transform on an `Optional` object, **if** there is a value.
|
|
138
|
+
* Unlike `map`, here the transform itself also returns an `Optional`.
|
|
139
|
+
*/
|
|
140
|
+
bind(binder) {
|
|
141
|
+
if (this.tag) {
|
|
142
|
+
return binder(this.value);
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
return Optional.none();
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
// --- Traversable (name stolen from Haskell / maths) ---
|
|
149
|
+
/**
|
|
150
|
+
* For a given predicate, this function finds out if there **exists** a value
|
|
151
|
+
* inside this `Optional` object that meets the predicate. In practice, this
|
|
152
|
+
* means that for `Optional`s that do not contain a value it returns false (as
|
|
153
|
+
* no predicate-meeting value exists).
|
|
154
|
+
*/
|
|
155
|
+
exists(predicate) {
|
|
156
|
+
return this.tag && predicate(this.value);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* For a given predicate, this function finds out if **all** the values inside
|
|
160
|
+
* this `Optional` object meet the predicate. In practice, this means that
|
|
161
|
+
* for `Optional`s that do not contain a value it returns true (as all 0
|
|
162
|
+
* objects do meet the predicate).
|
|
163
|
+
*/
|
|
164
|
+
forall(predicate) {
|
|
165
|
+
return !this.tag || predicate(this.value);
|
|
166
|
+
}
|
|
167
|
+
filter(predicate) {
|
|
168
|
+
if (!this.tag || predicate(this.value)) {
|
|
169
|
+
return this;
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
return Optional.none();
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
// --- Getters ---
|
|
176
|
+
/**
|
|
177
|
+
* Get the value out of the inside of the `Optional` object, using a default
|
|
178
|
+
* `replacement` value if the provided `Optional` object does not contain a
|
|
179
|
+
* value.
|
|
180
|
+
*/
|
|
181
|
+
getOr(replacement) {
|
|
182
|
+
return this.tag ? this.value : replacement;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Get the value out of the inside of the `Optional` object, using a default
|
|
186
|
+
* `replacement` value if the provided `Optional` object does not contain a
|
|
187
|
+
* value. Unlike `getOr`, in this method the `replacement` object is also
|
|
188
|
+
* `Optional` - meaning that this method will always return an `Optional`.
|
|
189
|
+
*/
|
|
190
|
+
or(replacement) {
|
|
191
|
+
return this.tag ? this : replacement;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Get the value out of the inside of the `Optional` object, using a default
|
|
195
|
+
* `replacement` value if the provided `Optional` object does not contain a
|
|
196
|
+
* value. Unlike `getOr`, in this method the `replacement` value is
|
|
197
|
+
* "thunked" - that is to say that you don't pass a value to `getOrThunk`, you
|
|
198
|
+
* pass a function which (if called) will **return** the `value` you want to
|
|
199
|
+
* use.
|
|
200
|
+
*/
|
|
201
|
+
getOrThunk(thunk) {
|
|
202
|
+
return this.tag ? this.value : thunk();
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Get the value out of the inside of the `Optional` object, using a default
|
|
206
|
+
* `replacement` value if the provided Optional object does not contain a
|
|
207
|
+
* value.
|
|
208
|
+
*
|
|
209
|
+
* Unlike `or`, in this method the `replacement` value is "thunked" - that is
|
|
210
|
+
* to say that you don't pass a value to `orThunk`, you pass a function which
|
|
211
|
+
* (if called) will **return** the `value` you want to use.
|
|
212
|
+
*
|
|
213
|
+
* Unlike `getOrThunk`, in this method the `replacement` value is also
|
|
214
|
+
* `Optional`, meaning that this method will always return an `Optional`.
|
|
215
|
+
*/
|
|
216
|
+
orThunk(thunk) {
|
|
217
|
+
return this.tag ? this : thunk();
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Get the value out of the inside of the `Optional` object, throwing an
|
|
221
|
+
* exception if the provided `Optional` object does not contain a value.
|
|
222
|
+
*
|
|
223
|
+
* WARNING:
|
|
224
|
+
* You should only be using this function if you know that the `Optional`
|
|
225
|
+
* object **is not** empty (otherwise you're throwing exceptions in production
|
|
226
|
+
* code, which is bad).
|
|
227
|
+
*
|
|
228
|
+
* In tests this is more acceptable.
|
|
229
|
+
*
|
|
230
|
+
* Prefer other methods to this, such as `.each`.
|
|
231
|
+
*/
|
|
232
|
+
getOrDie(message) {
|
|
233
|
+
if (!this.tag) {
|
|
234
|
+
throw new Error(message !== null && message !== void 0 ? message : 'Called getOrDie on None');
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
return this.value;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
// --- Interop with null and undefined ---
|
|
241
|
+
/**
|
|
242
|
+
* Creates an `Optional` value from a nullable (or undefined-able) input.
|
|
243
|
+
* Null, or undefined, is converted to `None`, and anything else is converted
|
|
244
|
+
* to `Some`.
|
|
245
|
+
*/
|
|
246
|
+
static from(value) {
|
|
247
|
+
return isNonNullable(value) ? Optional.some(value) : Optional.none();
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Converts an `Optional` to a nullable type, by getting the value if it
|
|
251
|
+
* exists, or returning `null` if it does not.
|
|
252
|
+
*/
|
|
253
|
+
getOrNull() {
|
|
254
|
+
return this.tag ? this.value : null;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Converts an `Optional` to an undefined-able type, by getting the value if
|
|
258
|
+
* it exists, or returning `undefined` if it does not.
|
|
259
|
+
*/
|
|
260
|
+
getOrUndefined() {
|
|
261
|
+
return this.value;
|
|
262
|
+
}
|
|
263
|
+
// --- Utilities ---
|
|
264
|
+
/**
|
|
265
|
+
* If the `Optional` contains a value, perform an action on that value.
|
|
266
|
+
* Unlike the rest of the methods on this type, `.each` has side-effects. If
|
|
267
|
+
* you want to transform an `Optional<T>` **into** something, then this is not
|
|
268
|
+
* the method for you. If you want to use an `Optional<T>` to **do**
|
|
269
|
+
* something, then this is the method for you - provided you're okay with not
|
|
270
|
+
* doing anything in the case where the `Optional` doesn't have a value inside
|
|
271
|
+
* it. If you're not sure whether your use-case fits into transforming
|
|
272
|
+
* **into** something or **doing** something, check whether it has a return
|
|
273
|
+
* value. If it does, you should be performing a transform.
|
|
274
|
+
*/
|
|
275
|
+
each(worker) {
|
|
276
|
+
if (this.tag) {
|
|
277
|
+
worker(this.value);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Turn the `Optional` object into an array that contains all of the values
|
|
282
|
+
* stored inside the `Optional`. In practice, this means the output will have
|
|
283
|
+
* either 0 or 1 elements.
|
|
284
|
+
*/
|
|
285
|
+
toArray() {
|
|
286
|
+
return this.tag ? [this.value] : [];
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Turn the `Optional` object into a string for debugging or printing. Not
|
|
290
|
+
* recommended for production code, but good for debugging. Also note that
|
|
291
|
+
* these days an `Optional` object can be logged to the console directly, and
|
|
292
|
+
* its inner value (if it exists) will be visible.
|
|
293
|
+
*/
|
|
294
|
+
toString() {
|
|
295
|
+
return this.tag ? `some(${this.value})` : 'none()';
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
// Sneaky optimisation: every instance of Optional.none is identical, so just
|
|
299
|
+
// reuse the same object
|
|
300
|
+
Optional.singletonNone = new Optional(false);
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Adds two numbers, and wrap to a range.
|
|
304
|
+
* If the result overflows to the right, snap to the left.
|
|
305
|
+
* If the result overflows to the left, snap to the right.
|
|
306
|
+
*/
|
|
307
|
+
// the division is meant to get a number between 0 and 1 for more information check this discussion: https://stackoverflow.com/questions/58285941/how-to-replace-math-random-with-crypto-getrandomvalues-and-keep-same-result
|
|
308
|
+
const random = () => window.crypto.getRandomValues(new Uint32Array(1))[0] / 4294967295;
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Generate a unique identifier.
|
|
312
|
+
*
|
|
313
|
+
* The unique portion of the identifier only contains an underscore
|
|
314
|
+
* and digits, so that it may safely be used within HTML attributes.
|
|
315
|
+
*
|
|
316
|
+
* The chance of generating a non-unique identifier has been minimized
|
|
317
|
+
* by combining the current time, a random number and a one-up counter.
|
|
318
|
+
*
|
|
319
|
+
* generate :: String -> String
|
|
320
|
+
*/
|
|
82
321
|
let unique = 0;
|
|
83
|
-
const generate = prefix => {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
322
|
+
const generate = (prefix) => {
|
|
323
|
+
const date = new Date();
|
|
324
|
+
const time = date.getTime();
|
|
325
|
+
const random$1 = Math.floor(random() * 1000000000);
|
|
326
|
+
unique++;
|
|
327
|
+
return prefix + '_' + random$1 + unique + String(time);
|
|
89
328
|
};
|
|
90
329
|
|
|
91
330
|
const insertTable = (editor, columns, rows) => {
|
|
92
|
-
|
|
93
|
-
rows,
|
|
94
|
-
columns
|
|
95
|
-
});
|
|
331
|
+
editor.execCommand('mceInsertTable', false, { rows, columns });
|
|
96
332
|
};
|
|
97
333
|
const insertBlob = (editor, base64, blob) => {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
334
|
+
const blobCache = editor.editorUpload.blobCache;
|
|
335
|
+
const blobInfo = blobCache.create(generate('mceu'), blob, base64);
|
|
336
|
+
blobCache.add(blobInfo);
|
|
337
|
+
editor.insertContent(editor.dom.createHTML('img', { src: blobInfo.blobUri() }));
|
|
102
338
|
};
|
|
103
339
|
|
|
104
|
-
const blobToBase64 = blob => {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
340
|
+
const blobToBase64 = (blob) => {
|
|
341
|
+
return new Promise((resolve) => {
|
|
342
|
+
const reader = new FileReader();
|
|
343
|
+
reader.onloadend = () => {
|
|
344
|
+
resolve(reader.result.split(',')[1]);
|
|
345
|
+
};
|
|
346
|
+
reader.readAsDataURL(blob);
|
|
347
|
+
});
|
|
112
348
|
};
|
|
113
349
|
|
|
114
350
|
var global = tinymce.util.Tools.resolve('tinymce.util.Delay');
|
|
115
351
|
|
|
116
|
-
const pickFile = editor => new Promise(resolve => {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
};
|
|
134
|
-
const changeHandler = e => {
|
|
135
|
-
resolveFileInput(Array.prototype.slice.call(e.target.files));
|
|
136
|
-
};
|
|
137
|
-
fileInput.addEventListener('input', changeHandler);
|
|
138
|
-
fileInput.addEventListener('change', changeHandler);
|
|
139
|
-
const cancelHandler = e => {
|
|
140
|
-
const cleanup = () => {
|
|
141
|
-
resolveFileInput([]);
|
|
352
|
+
const pickFile = (editor) => new Promise((resolve) => {
|
|
353
|
+
let resolved = false;
|
|
354
|
+
const fileInput = document.createElement('input');
|
|
355
|
+
fileInput.type = 'file';
|
|
356
|
+
fileInput.accept = 'image/*';
|
|
357
|
+
fileInput.style.position = 'fixed';
|
|
358
|
+
fileInput.style.left = '0';
|
|
359
|
+
fileInput.style.top = '0';
|
|
360
|
+
fileInput.style.opacity = '0.001';
|
|
361
|
+
document.body.appendChild(fileInput);
|
|
362
|
+
const resolveFileInput = (value) => {
|
|
363
|
+
var _a;
|
|
364
|
+
if (!resolved) {
|
|
365
|
+
(_a = fileInput.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(fileInput);
|
|
366
|
+
resolved = true;
|
|
367
|
+
resolve(value);
|
|
368
|
+
}
|
|
142
369
|
};
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
370
|
+
const changeHandler = (e) => {
|
|
371
|
+
resolveFileInput(Array.prototype.slice.call(e.target.files));
|
|
372
|
+
};
|
|
373
|
+
fileInput.addEventListener('input', changeHandler);
|
|
374
|
+
fileInput.addEventListener('change', changeHandler);
|
|
375
|
+
const cancelHandler = (e) => {
|
|
376
|
+
const cleanup = () => {
|
|
377
|
+
resolveFileInput([]);
|
|
378
|
+
};
|
|
379
|
+
if (!resolved) {
|
|
380
|
+
if (e.type === 'focusin') {
|
|
381
|
+
// Chrome will fire `focusin` before the input `change` event
|
|
382
|
+
global.setEditorTimeout(editor, cleanup, 1000);
|
|
383
|
+
}
|
|
384
|
+
else {
|
|
385
|
+
cleanup();
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
editor.off('focusin remove', cancelHandler);
|
|
389
|
+
};
|
|
390
|
+
editor.on('focusin remove', cancelHandler);
|
|
391
|
+
fileInput.click();
|
|
154
392
|
});
|
|
155
393
|
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
394
|
+
const register$1 = (editor) => {
|
|
395
|
+
editor.on('PreInit', () => {
|
|
396
|
+
if (!editor.queryCommandSupported('QuickbarInsertImage')) {
|
|
397
|
+
editor.addCommand('QuickbarInsertImage', () => {
|
|
398
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
399
|
+
pickFile(editor).then((files) => {
|
|
400
|
+
if (files.length > 0) {
|
|
401
|
+
const blob = files[0];
|
|
402
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
403
|
+
blobToBase64(blob).then((base64) => {
|
|
404
|
+
insertBlob(editor, base64, blob);
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
});
|
|
167
409
|
}
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
editor.ui.registry.addButton('quicktable', {
|
|
172
|
-
icon: 'table',
|
|
173
|
-
tooltip: 'Insert table',
|
|
174
|
-
onAction: () => {
|
|
175
|
-
insertTable(editor, 2, 2);
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
const constant = value => {
|
|
181
|
-
return () => {
|
|
182
|
-
return value;
|
|
183
|
-
};
|
|
184
|
-
};
|
|
185
|
-
const never = constant(false);
|
|
186
|
-
|
|
187
|
-
class Optional {
|
|
188
|
-
constructor(tag, value) {
|
|
189
|
-
this.tag = tag;
|
|
190
|
-
this.value = value;
|
|
191
|
-
}
|
|
192
|
-
static some(value) {
|
|
193
|
-
return new Optional(true, value);
|
|
194
|
-
}
|
|
195
|
-
static none() {
|
|
196
|
-
return Optional.singletonNone;
|
|
197
|
-
}
|
|
198
|
-
fold(onNone, onSome) {
|
|
199
|
-
if (this.tag) {
|
|
200
|
-
return onSome(this.value);
|
|
201
|
-
} else {
|
|
202
|
-
return onNone();
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
isSome() {
|
|
206
|
-
return this.tag;
|
|
207
|
-
}
|
|
208
|
-
isNone() {
|
|
209
|
-
return !this.tag;
|
|
210
|
-
}
|
|
211
|
-
map(mapper) {
|
|
212
|
-
if (this.tag) {
|
|
213
|
-
return Optional.some(mapper(this.value));
|
|
214
|
-
} else {
|
|
215
|
-
return Optional.none();
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
bind(binder) {
|
|
219
|
-
if (this.tag) {
|
|
220
|
-
return binder(this.value);
|
|
221
|
-
} else {
|
|
222
|
-
return Optional.none();
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
exists(predicate) {
|
|
226
|
-
return this.tag && predicate(this.value);
|
|
227
|
-
}
|
|
228
|
-
forall(predicate) {
|
|
229
|
-
return !this.tag || predicate(this.value);
|
|
230
|
-
}
|
|
231
|
-
filter(predicate) {
|
|
232
|
-
if (!this.tag || predicate(this.value)) {
|
|
233
|
-
return this;
|
|
234
|
-
} else {
|
|
235
|
-
return Optional.none();
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
getOr(replacement) {
|
|
239
|
-
return this.tag ? this.value : replacement;
|
|
240
|
-
}
|
|
241
|
-
or(replacement) {
|
|
242
|
-
return this.tag ? this : replacement;
|
|
243
|
-
}
|
|
244
|
-
getOrThunk(thunk) {
|
|
245
|
-
return this.tag ? this.value : thunk();
|
|
246
|
-
}
|
|
247
|
-
orThunk(thunk) {
|
|
248
|
-
return this.tag ? this : thunk();
|
|
249
|
-
}
|
|
250
|
-
getOrDie(message) {
|
|
251
|
-
if (!this.tag) {
|
|
252
|
-
throw new Error(message !== null && message !== void 0 ? message : 'Called getOrDie on None');
|
|
253
|
-
} else {
|
|
254
|
-
return this.value;
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
static from(value) {
|
|
258
|
-
return isNonNullable(value) ? Optional.some(value) : Optional.none();
|
|
259
|
-
}
|
|
260
|
-
getOrNull() {
|
|
261
|
-
return this.tag ? this.value : null;
|
|
262
|
-
}
|
|
263
|
-
getOrUndefined() {
|
|
264
|
-
return this.value;
|
|
265
|
-
}
|
|
266
|
-
each(worker) {
|
|
267
|
-
if (this.tag) {
|
|
268
|
-
worker(this.value);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
toArray() {
|
|
272
|
-
return this.tag ? [this.value] : [];
|
|
273
|
-
}
|
|
274
|
-
toString() {
|
|
275
|
-
return this.tag ? `some(${ this.value })` : 'none()';
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
Optional.singletonNone = new Optional(false);
|
|
279
|
-
|
|
280
|
-
typeof window !== 'undefined' ? window : Function('return this;')();
|
|
281
|
-
|
|
282
|
-
const ELEMENT = 1;
|
|
283
|
-
|
|
284
|
-
const name = element => {
|
|
285
|
-
const r = element.dom.nodeName;
|
|
286
|
-
return r.toLowerCase();
|
|
410
|
+
});
|
|
287
411
|
};
|
|
288
412
|
|
|
289
|
-
const
|
|
290
|
-
|
|
291
|
-
|
|
413
|
+
const option = (name) => (editor) => editor.options.get(name);
|
|
414
|
+
const register = (editor) => {
|
|
415
|
+
const registerOption = editor.options.register;
|
|
416
|
+
const toolbarProcessor = (defaultValue) => (value) => {
|
|
417
|
+
const valid = isBoolean(value) || isString(value);
|
|
418
|
+
if (valid) {
|
|
419
|
+
if (isBoolean(value)) {
|
|
420
|
+
return { value: value ? defaultValue : '', valid };
|
|
421
|
+
}
|
|
422
|
+
else {
|
|
423
|
+
return { value: value.trim(), valid };
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
else {
|
|
427
|
+
return { valid: false, message: 'Must be a boolean or string.' };
|
|
428
|
+
}
|
|
429
|
+
};
|
|
430
|
+
const defaultSelectionToolbar = 'bold italic | quicklink h2 h3 blockquote';
|
|
431
|
+
registerOption('quickbars_selection_toolbar', {
|
|
432
|
+
processor: toolbarProcessor(defaultSelectionToolbar),
|
|
433
|
+
default: defaultSelectionToolbar
|
|
434
|
+
});
|
|
435
|
+
const defaultInsertToolbar = 'quickimage quicktable';
|
|
436
|
+
registerOption('quickbars_insert_toolbar', {
|
|
437
|
+
processor: toolbarProcessor(defaultInsertToolbar),
|
|
438
|
+
default: defaultInsertToolbar
|
|
439
|
+
});
|
|
440
|
+
const defaultImageToolbar = 'alignleft aligncenter alignright';
|
|
441
|
+
registerOption('quickbars_image_toolbar', {
|
|
442
|
+
processor: toolbarProcessor(defaultImageToolbar),
|
|
443
|
+
default: defaultImageToolbar
|
|
444
|
+
});
|
|
292
445
|
};
|
|
446
|
+
const getTextSelectionToolbarItems = option('quickbars_selection_toolbar');
|
|
447
|
+
const getInsertToolbarItems = option('quickbars_insert_toolbar');
|
|
448
|
+
const getImageToolbarItems = option('quickbars_image_toolbar');
|
|
293
449
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
450
|
+
const setupButtons = (editor) => {
|
|
451
|
+
editor.ui.registry.addButton('quickimage', {
|
|
452
|
+
icon: 'image',
|
|
453
|
+
tooltip: 'Insert image',
|
|
454
|
+
onAction: () => editor.execCommand('QuickbarInsertImage')
|
|
455
|
+
});
|
|
456
|
+
editor.ui.registry.addButton('quicktable', {
|
|
457
|
+
icon: 'table',
|
|
458
|
+
tooltip: 'Insert table',
|
|
459
|
+
onAction: () => {
|
|
460
|
+
insertTable(editor, 2, 2);
|
|
461
|
+
}
|
|
462
|
+
});
|
|
302
463
|
};
|
|
303
464
|
|
|
304
465
|
const fromHtml = (html, scope) => {
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
466
|
+
const doc = scope || document;
|
|
467
|
+
const div = doc.createElement('div');
|
|
468
|
+
div.innerHTML = html;
|
|
469
|
+
if (!div.hasChildNodes() || div.childNodes.length > 1) {
|
|
470
|
+
const message = 'HTML does not have a single root node';
|
|
471
|
+
// eslint-disable-next-line no-console
|
|
472
|
+
console.error(message, html);
|
|
473
|
+
throw new Error(message);
|
|
474
|
+
}
|
|
475
|
+
return fromDom(div.childNodes[0]);
|
|
314
476
|
};
|
|
315
477
|
const fromTag = (tag, scope) => {
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
478
|
+
const doc = scope || document;
|
|
479
|
+
const node = doc.createElement(tag);
|
|
480
|
+
return fromDom(node);
|
|
319
481
|
};
|
|
320
482
|
const fromText = (text, scope) => {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
483
|
+
const doc = scope || document;
|
|
484
|
+
const node = doc.createTextNode(text);
|
|
485
|
+
return fromDom(node);
|
|
324
486
|
};
|
|
325
|
-
const fromDom = node => {
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
487
|
+
const fromDom = (node) => {
|
|
488
|
+
// TODO: Consider removing this check, but left atm for safety
|
|
489
|
+
if (node === null || node === undefined) {
|
|
490
|
+
throw new Error('Node cannot be null or undefined');
|
|
491
|
+
}
|
|
492
|
+
return {
|
|
493
|
+
dom: node
|
|
494
|
+
};
|
|
330
495
|
};
|
|
331
496
|
const fromPoint = (docElm, x, y) => Optional.from(docElm.dom.elementFromPoint(x, y)).map(fromDom);
|
|
497
|
+
// tslint:disable-next-line:variable-name
|
|
332
498
|
const SugarElement = {
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
499
|
+
fromHtml,
|
|
500
|
+
fromTag,
|
|
501
|
+
fromText,
|
|
502
|
+
fromDom,
|
|
503
|
+
fromPoint
|
|
338
504
|
};
|
|
339
505
|
|
|
506
|
+
const ELEMENT = 1;
|
|
507
|
+
|
|
340
508
|
const is = (element, selector) => {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
509
|
+
const dom = element.dom;
|
|
510
|
+
if (dom.nodeType !== ELEMENT) {
|
|
511
|
+
return false;
|
|
512
|
+
}
|
|
513
|
+
else {
|
|
514
|
+
const elem = dom;
|
|
515
|
+
if (elem.matches !== undefined) {
|
|
516
|
+
return elem.matches(selector);
|
|
517
|
+
}
|
|
518
|
+
else if (elem.msMatchesSelector !== undefined) {
|
|
519
|
+
return elem.msMatchesSelector(selector);
|
|
520
|
+
}
|
|
521
|
+
else if (elem.webkitMatchesSelector !== undefined) {
|
|
522
|
+
return elem.webkitMatchesSelector(selector);
|
|
523
|
+
}
|
|
524
|
+
else if (elem.mozMatchesSelector !== undefined) {
|
|
525
|
+
// cast to any as mozMatchesSelector doesn't exist in TS DOM lib
|
|
526
|
+
return elem.mozMatchesSelector(selector);
|
|
527
|
+
}
|
|
528
|
+
else {
|
|
529
|
+
throw new Error('Browser lacks native selectors');
|
|
530
|
+
} // unfortunately we can't throw this on startup :(
|
|
531
|
+
}
|
|
358
532
|
};
|
|
359
533
|
|
|
360
|
-
const
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
while (element.parentNode) {
|
|
364
|
-
element = element.parentNode;
|
|
365
|
-
const el = SugarElement.fromDom(element);
|
|
366
|
-
if (predicate(el)) {
|
|
367
|
-
return Optional.some(el);
|
|
368
|
-
} else if (stop(el)) {
|
|
369
|
-
break;
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
return Optional.none();
|
|
534
|
+
const name = (element) => {
|
|
535
|
+
const r = element.dom.nodeName;
|
|
536
|
+
return r.toLowerCase();
|
|
373
537
|
};
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
538
|
+
|
|
539
|
+
const has$1 = (element, key) => {
|
|
540
|
+
const dom = element.dom;
|
|
541
|
+
// return false for non-element nodes, no point in throwing an error
|
|
542
|
+
return dom && dom.hasAttribute ? dom.hasAttribute(key) : false;
|
|
377
543
|
};
|
|
378
544
|
|
|
379
|
-
|
|
545
|
+
var ClosestOrAncestor = (is, ancestor, scope, a, isRoot) => {
|
|
546
|
+
if (is(scope, a)) {
|
|
547
|
+
return Optional.some(scope);
|
|
548
|
+
}
|
|
549
|
+
else if (isFunction(isRoot) && isRoot(scope)) {
|
|
550
|
+
return Optional.none();
|
|
551
|
+
}
|
|
552
|
+
else {
|
|
553
|
+
return ancestor(scope, a, isRoot);
|
|
554
|
+
}
|
|
555
|
+
};
|
|
380
556
|
|
|
381
|
-
const ancestor = (scope,
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
557
|
+
const ancestor$1 = (scope, predicate, isRoot) => {
|
|
558
|
+
let element = scope.dom;
|
|
559
|
+
const stop = isFunction(isRoot) ? isRoot : never;
|
|
560
|
+
while (element.parentNode) {
|
|
561
|
+
element = element.parentNode;
|
|
562
|
+
const el = SugarElement.fromDom(element);
|
|
563
|
+
if (predicate(el)) {
|
|
564
|
+
return Optional.some(el);
|
|
565
|
+
}
|
|
566
|
+
else if (stop(el)) {
|
|
567
|
+
break;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
return Optional.none();
|
|
571
|
+
};
|
|
572
|
+
const closest$2 = (scope, predicate, isRoot) => {
|
|
573
|
+
// This is required to avoid ClosestOrAncestor passing the predicate to itself
|
|
574
|
+
const is = (s, test) => test(s);
|
|
575
|
+
return ClosestOrAncestor(is, ancestor$1, scope, predicate, isRoot);
|
|
385
576
|
};
|
|
386
577
|
|
|
387
|
-
const
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
const sugarNode = SugarElement.fromDom(node);
|
|
393
|
-
const textBlockElementsMap = editor.schema.getTextBlockElements();
|
|
394
|
-
const isRoot = elem => elem.dom === editor.getBody();
|
|
395
|
-
return !has$1(sugarNode, 'data-mce-bogus') && closest(sugarNode, 'table,[data-mce-bogus="all"]', isRoot).fold(() => closest$1(sugarNode, elem => name(elem) in textBlockElementsMap && editor.dom.isEmpty(elem.dom), isRoot), never);
|
|
396
|
-
},
|
|
397
|
-
items: insertToolbarItems,
|
|
398
|
-
position: 'line',
|
|
399
|
-
scope: 'editor'
|
|
400
|
-
});
|
|
401
|
-
}
|
|
578
|
+
const ancestor = (scope, selector, isRoot) => ancestor$1(scope, (e) => is(e, selector), isRoot);
|
|
579
|
+
// Returns Some(closest ancestor element (sugared)) matching 'selector' up to isRoot, or None() otherwise
|
|
580
|
+
const closest$1 = (scope, selector, isRoot) => {
|
|
581
|
+
const is$1 = (element, selector) => is(element, selector);
|
|
582
|
+
return ClosestOrAncestor(is$1, ancestor, scope, selector, isRoot);
|
|
402
583
|
};
|
|
403
584
|
|
|
404
|
-
|
|
585
|
+
// IE11 Can return undefined for a classList on elements such as math, so we make sure it's not undefined before attempting to use it.
|
|
586
|
+
const supports = (element) => element.dom.classList !== undefined;
|
|
405
587
|
|
|
406
588
|
const has = (element, clazz) => supports(element) && element.dom.classList.contains(clazz);
|
|
407
589
|
|
|
408
|
-
const
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
590
|
+
const closest = (scope, predicate, isRoot) => closest$2(scope, predicate, isRoot).isSome();
|
|
591
|
+
|
|
592
|
+
const addToEditor$1 = (editor) => {
|
|
593
|
+
const insertToolbarItems = getInsertToolbarItems(editor);
|
|
594
|
+
if (insertToolbarItems.length > 0) {
|
|
595
|
+
editor.ui.registry.addContextToolbar('quickblock', {
|
|
596
|
+
predicate: (node) => {
|
|
597
|
+
const sugarNode = SugarElement.fromDom(node);
|
|
598
|
+
const textBlockElementsMap = editor.schema.getTextBlockElements();
|
|
599
|
+
const isRoot = (elem) => elem.dom === editor.getBody();
|
|
600
|
+
return !has$1(sugarNode, 'data-mce-bogus') && closest$1(sugarNode, 'table,[data-mce-bogus="all"]', isRoot).fold(() => closest(sugarNode, (elem) => name(elem) in textBlockElementsMap && editor.dom.isEmpty(elem.dom), isRoot), never);
|
|
601
|
+
},
|
|
602
|
+
items: insertToolbarItems,
|
|
603
|
+
position: 'line',
|
|
604
|
+
scope: 'editor'
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
};
|
|
608
|
+
|
|
609
|
+
const addToEditor = (editor) => {
|
|
610
|
+
const isEditable = (node) => editor.dom.isEditable(node);
|
|
611
|
+
const isInEditableContext = (el) => isEditable(el.parentElement);
|
|
612
|
+
const isImage = (node) => {
|
|
613
|
+
const isImageFigure = node.nodeName === 'FIGURE' && /image/i.test(node.className);
|
|
614
|
+
const isImage = node.nodeName === 'IMG' || isImageFigure;
|
|
615
|
+
const isPagebreak = has(SugarElement.fromDom(node), 'mce-pagebreak');
|
|
616
|
+
return isImage && isInEditableContext(node) && !isPagebreak;
|
|
617
|
+
};
|
|
618
|
+
const imageToolbarItems = getImageToolbarItems(editor);
|
|
619
|
+
if (imageToolbarItems.length > 0) {
|
|
620
|
+
editor.ui.registry.addContextToolbar('imageselection', {
|
|
621
|
+
predicate: isImage,
|
|
622
|
+
items: imageToolbarItems,
|
|
623
|
+
position: 'node'
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
const textToolbarItems = getTextSelectionToolbarItems(editor);
|
|
627
|
+
if (textToolbarItems.length > 0) {
|
|
628
|
+
editor.ui.registry.addContextToolbar('textselection', {
|
|
629
|
+
predicate: (node) => !isImage(node) && !editor.selection.isCollapsed() && isEditable(node),
|
|
630
|
+
items: textToolbarItems,
|
|
631
|
+
position: 'selection',
|
|
632
|
+
scope: 'editor'
|
|
633
|
+
});
|
|
634
|
+
}
|
|
434
635
|
};
|
|
435
636
|
|
|
436
637
|
var Plugin = () => {
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
638
|
+
global$1.add('quickbars', (editor) => {
|
|
639
|
+
register(editor);
|
|
640
|
+
register$1(editor);
|
|
641
|
+
setupButtons(editor);
|
|
642
|
+
addToEditor$1(editor);
|
|
643
|
+
addToEditor(editor);
|
|
644
|
+
});
|
|
443
645
|
};
|
|
444
646
|
|
|
445
647
|
Plugin();
|
|
648
|
+
/** *****
|
|
649
|
+
* DO NOT EXPORT ANYTHING
|
|
650
|
+
*
|
|
651
|
+
* IF YOU DO ROLLUP WILL LEAVE A GLOBAL ON THE PAGE
|
|
652
|
+
*******/
|
|
446
653
|
|
|
447
654
|
})();
|