| 1 | efrain | 1 | /**
 | 
        
           | 1441 | ariadna | 2 |  * TinyMCE version 7.7.1 (2025-03-05)
 | 
        
           | 1 | efrain | 3 |  */
 | 
        
           |  |  | 4 |   | 
        
           |  |  | 5 | (function () {
 | 
        
           |  |  | 6 |     'use strict';
 | 
        
           |  |  | 7 |   | 
        
           |  |  | 8 |     var global$6 = tinymce.util.Tools.resolve('tinymce.PluginManager');
 | 
        
           |  |  | 9 |   | 
        
           |  |  | 10 |     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 |       }
 | 
        
           |  |  | 17 |     };
 | 
        
           |  |  | 18 |     const typeOf = x => {
 | 
        
           |  |  | 19 |       const t = typeof x;
 | 
        
           |  |  | 20 |       if (x === null) {
 | 
        
           |  |  | 21 |         return 'null';
 | 
        
           |  |  | 22 |       } else if (t === 'object' && Array.isArray(x)) {
 | 
        
           |  |  | 23 |         return 'array';
 | 
        
           |  |  | 24 |       } else if (t === 'object' && hasProto(x, String, (o, proto) => proto.isPrototypeOf(o))) {
 | 
        
           |  |  | 25 |         return 'string';
 | 
        
           |  |  | 26 |       } else {
 | 
        
           |  |  | 27 |         return t;
 | 
        
           |  |  | 28 |       }
 | 
        
           |  |  | 29 |     };
 | 
        
           |  |  | 30 |     const isType = type => value => typeOf(value) === type;
 | 
        
           |  |  | 31 |     const isString = isType('string');
 | 
        
           |  |  | 32 |     const isObject = isType('object');
 | 
        
           |  |  | 33 |     const isArray = isType('array');
 | 
        
           |  |  | 34 |     const isNullable = a => a === null || a === undefined;
 | 
        
           |  |  | 35 |     const isNonNullable = a => !isNullable(a);
 | 
        
           |  |  | 36 |   | 
        
           |  |  | 37 |     class Optional {
 | 
        
           |  |  | 38 |       constructor(tag, value) {
 | 
        
           |  |  | 39 |         this.tag = tag;
 | 
        
           |  |  | 40 |         this.value = value;
 | 
        
           |  |  | 41 |       }
 | 
        
           |  |  | 42 |       static some(value) {
 | 
        
           |  |  | 43 |         return new Optional(true, value);
 | 
        
           |  |  | 44 |       }
 | 
        
           |  |  | 45 |       static none() {
 | 
        
           |  |  | 46 |         return Optional.singletonNone;
 | 
        
           |  |  | 47 |       }
 | 
        
           |  |  | 48 |       fold(onNone, onSome) {
 | 
        
           |  |  | 49 |         if (this.tag) {
 | 
        
           |  |  | 50 |           return onSome(this.value);
 | 
        
           |  |  | 51 |         } else {
 | 
        
           |  |  | 52 |           return onNone();
 | 
        
           |  |  | 53 |         }
 | 
        
           |  |  | 54 |       }
 | 
        
           |  |  | 55 |       isSome() {
 | 
        
           |  |  | 56 |         return this.tag;
 | 
        
           |  |  | 57 |       }
 | 
        
           |  |  | 58 |       isNone() {
 | 
        
           |  |  | 59 |         return !this.tag;
 | 
        
           |  |  | 60 |       }
 | 
        
           |  |  | 61 |       map(mapper) {
 | 
        
           |  |  | 62 |         if (this.tag) {
 | 
        
           |  |  | 63 |           return Optional.some(mapper(this.value));
 | 
        
           |  |  | 64 |         } else {
 | 
        
           |  |  | 65 |           return Optional.none();
 | 
        
           |  |  | 66 |         }
 | 
        
           |  |  | 67 |       }
 | 
        
           |  |  | 68 |       bind(binder) {
 | 
        
           |  |  | 69 |         if (this.tag) {
 | 
        
           |  |  | 70 |           return binder(this.value);
 | 
        
           |  |  | 71 |         } else {
 | 
        
           |  |  | 72 |           return Optional.none();
 | 
        
           |  |  | 73 |         }
 | 
        
           |  |  | 74 |       }
 | 
        
           |  |  | 75 |       exists(predicate) {
 | 
        
           |  |  | 76 |         return this.tag && predicate(this.value);
 | 
        
           |  |  | 77 |       }
 | 
        
           |  |  | 78 |       forall(predicate) {
 | 
        
           |  |  | 79 |         return !this.tag || predicate(this.value);
 | 
        
           |  |  | 80 |       }
 | 
        
           |  |  | 81 |       filter(predicate) {
 | 
        
           |  |  | 82 |         if (!this.tag || predicate(this.value)) {
 | 
        
           |  |  | 83 |           return this;
 | 
        
           |  |  | 84 |         } else {
 | 
        
           |  |  | 85 |           return Optional.none();
 | 
        
           |  |  | 86 |         }
 | 
        
           |  |  | 87 |       }
 | 
        
           |  |  | 88 |       getOr(replacement) {
 | 
        
           |  |  | 89 |         return this.tag ? this.value : replacement;
 | 
        
           |  |  | 90 |       }
 | 
        
           |  |  | 91 |       or(replacement) {
 | 
        
           |  |  | 92 |         return this.tag ? this : replacement;
 | 
        
           |  |  | 93 |       }
 | 
        
           |  |  | 94 |       getOrThunk(thunk) {
 | 
        
           |  |  | 95 |         return this.tag ? this.value : thunk();
 | 
        
           |  |  | 96 |       }
 | 
        
           |  |  | 97 |       orThunk(thunk) {
 | 
        
           |  |  | 98 |         return this.tag ? this : thunk();
 | 
        
           |  |  | 99 |       }
 | 
        
           |  |  | 100 |       getOrDie(message) {
 | 
        
           |  |  | 101 |         if (!this.tag) {
 | 
        
           |  |  | 102 |           throw new Error(message !== null && message !== void 0 ? message : 'Called getOrDie on None');
 | 
        
           |  |  | 103 |         } else {
 | 
        
           |  |  | 104 |           return this.value;
 | 
        
           |  |  | 105 |         }
 | 
        
           |  |  | 106 |       }
 | 
        
           |  |  | 107 |       static from(value) {
 | 
        
           |  |  | 108 |         return isNonNullable(value) ? Optional.some(value) : Optional.none();
 | 
        
           |  |  | 109 |       }
 | 
        
           |  |  | 110 |       getOrNull() {
 | 
        
           |  |  | 111 |         return this.tag ? this.value : null;
 | 
        
           |  |  | 112 |       }
 | 
        
           |  |  | 113 |       getOrUndefined() {
 | 
        
           |  |  | 114 |         return this.value;
 | 
        
           |  |  | 115 |       }
 | 
        
           |  |  | 116 |       each(worker) {
 | 
        
           |  |  | 117 |         if (this.tag) {
 | 
        
           |  |  | 118 |           worker(this.value);
 | 
        
           |  |  | 119 |         }
 | 
        
           |  |  | 120 |       }
 | 
        
           |  |  | 121 |       toArray() {
 | 
        
           |  |  | 122 |         return this.tag ? [this.value] : [];
 | 
        
           |  |  | 123 |       }
 | 
        
           |  |  | 124 |       toString() {
 | 
        
           |  |  | 125 |         return this.tag ? `some(${ this.value })` : 'none()';
 | 
        
           |  |  | 126 |       }
 | 
        
           |  |  | 127 |     }
 | 
        
           |  |  | 128 |     Optional.singletonNone = new Optional(false);
 | 
        
           |  |  | 129 |   | 
        
           |  |  | 130 |     const nativePush = Array.prototype.push;
 | 
        
           |  |  | 131 |     const each$1 = (xs, f) => {
 | 
        
           |  |  | 132 |       for (let i = 0, len = xs.length; i < len; i++) {
 | 
        
           |  |  | 133 |         const x = xs[i];
 | 
        
           |  |  | 134 |         f(x, i);
 | 
        
           |  |  | 135 |       }
 | 
        
           |  |  | 136 |     };
 | 
        
           |  |  | 137 |     const flatten = xs => {
 | 
        
           |  |  | 138 |       const r = [];
 | 
        
           |  |  | 139 |       for (let i = 0, len = xs.length; i < len; ++i) {
 | 
        
           |  |  | 140 |         if (!isArray(xs[i])) {
 | 
        
           |  |  | 141 |           throw new Error('Arr.flatten item ' + i + ' was not an array, input: ' + xs);
 | 
        
           |  |  | 142 |         }
 | 
        
           |  |  | 143 |         nativePush.apply(r, xs[i]);
 | 
        
           |  |  | 144 |       }
 | 
        
           |  |  | 145 |       return r;
 | 
        
           |  |  | 146 |     };
 | 
        
           |  |  | 147 |   | 
        
           |  |  | 148 |     const Cell = initial => {
 | 
        
           |  |  | 149 |       let value = initial;
 | 
        
           |  |  | 150 |       const get = () => {
 | 
        
           |  |  | 151 |         return value;
 | 
        
           |  |  | 152 |       };
 | 
        
           |  |  | 153 |       const set = v => {
 | 
        
           |  |  | 154 |         value = v;
 | 
        
           |  |  | 155 |       };
 | 
        
           |  |  | 156 |       return {
 | 
        
           |  |  | 157 |         get,
 | 
        
           |  |  | 158 |         set
 | 
        
           |  |  | 159 |       };
 | 
        
           |  |  | 160 |     };
 | 
        
           |  |  | 161 |   | 
        
           |  |  | 162 |     const keys = Object.keys;
 | 
        
           |  |  | 163 |     const hasOwnProperty = Object.hasOwnProperty;
 | 
        
           |  |  | 164 |     const each = (obj, f) => {
 | 
        
           |  |  | 165 |       const props = keys(obj);
 | 
        
           |  |  | 166 |       for (let k = 0, len = props.length; k < len; k++) {
 | 
        
           |  |  | 167 |         const i = props[k];
 | 
        
           |  |  | 168 |         const x = obj[i];
 | 
        
           |  |  | 169 |         f(x, i);
 | 
        
           |  |  | 170 |       }
 | 
        
           |  |  | 171 |     };
 | 
        
           |  |  | 172 |     const get$1 = (obj, key) => {
 | 
        
           |  |  | 173 |       return has(obj, key) ? Optional.from(obj[key]) : Optional.none();
 | 
        
           |  |  | 174 |     };
 | 
        
           |  |  | 175 |     const has = (obj, key) => hasOwnProperty.call(obj, key);
 | 
        
           |  |  | 176 |   | 
        
           |  |  | 177 |     const option = name => editor => editor.options.get(name);
 | 
        
           |  |  | 178 |     const register$2 = editor => {
 | 
        
           |  |  | 179 |       const registerOption = editor.options.register;
 | 
        
           |  |  | 180 |       registerOption('audio_template_callback', { processor: 'function' });
 | 
        
           |  |  | 181 |       registerOption('video_template_callback', { processor: 'function' });
 | 
        
           |  |  | 182 |       registerOption('iframe_template_callback', { processor: 'function' });
 | 
        
           |  |  | 183 |       registerOption('media_live_embeds', {
 | 
        
           |  |  | 184 |         processor: 'boolean',
 | 
        
           |  |  | 185 |         default: true
 | 
        
           |  |  | 186 |       });
 | 
        
           |  |  | 187 |       registerOption('media_filter_html', {
 | 
        
           |  |  | 188 |         processor: 'boolean',
 | 
        
           |  |  | 189 |         default: true
 | 
        
           |  |  | 190 |       });
 | 
        
           |  |  | 191 |       registerOption('media_url_resolver', { processor: 'function' });
 | 
        
           |  |  | 192 |       registerOption('media_alt_source', {
 | 
        
           |  |  | 193 |         processor: 'boolean',
 | 
        
           |  |  | 194 |         default: true
 | 
        
           |  |  | 195 |       });
 | 
        
           |  |  | 196 |       registerOption('media_poster', {
 | 
        
           |  |  | 197 |         processor: 'boolean',
 | 
        
           |  |  | 198 |         default: true
 | 
        
           |  |  | 199 |       });
 | 
        
           |  |  | 200 |       registerOption('media_dimensions', {
 | 
        
           |  |  | 201 |         processor: 'boolean',
 | 
        
           |  |  | 202 |         default: true
 | 
        
           |  |  | 203 |       });
 | 
        
           |  |  | 204 |     };
 | 
        
           |  |  | 205 |     const getAudioTemplateCallback = option('audio_template_callback');
 | 
        
           |  |  | 206 |     const getVideoTemplateCallback = option('video_template_callback');
 | 
        
           |  |  | 207 |     const getIframeTemplateCallback = option('iframe_template_callback');
 | 
        
           |  |  | 208 |     const hasLiveEmbeds = option('media_live_embeds');
 | 
        
           |  |  | 209 |     const shouldFilterHtml = option('media_filter_html');
 | 
        
           |  |  | 210 |     const getUrlResolver = option('media_url_resolver');
 | 
        
           |  |  | 211 |     const hasAltSource = option('media_alt_source');
 | 
        
           |  |  | 212 |     const hasPoster = option('media_poster');
 | 
        
           |  |  | 213 |     const hasDimensions = option('media_dimensions');
 | 
        
           |  |  | 214 |   | 
        
           |  |  | 215 |     var global$5 = tinymce.util.Tools.resolve('tinymce.util.Tools');
 | 
        
           |  |  | 216 |   | 
        
           |  |  | 217 |     var global$4 = tinymce.util.Tools.resolve('tinymce.dom.DOMUtils');
 | 
        
           |  |  | 218 |   | 
        
           |  |  | 219 |     var global$3 = tinymce.util.Tools.resolve('tinymce.html.DomParser');
 | 
        
           |  |  | 220 |   | 
        
           |  |  | 221 |     const DOM$1 = global$4.DOM;
 | 
        
           |  |  | 222 |     const trimPx = value => value.replace(/px$/, '');
 | 
        
           |  |  | 223 |     const getEphoxEmbedData = node => {
 | 
        
           |  |  | 224 |       const style = node.attr('style');
 | 
        
           |  |  | 225 |       const styles = style ? DOM$1.parseStyle(style) : {};
 | 
        
           |  |  | 226 |       return {
 | 
        
           |  |  | 227 |         type: 'ephox-embed-iri',
 | 
        
           |  |  | 228 |         source: node.attr('data-ephox-embed-iri'),
 | 
        
           |  |  | 229 |         altsource: '',
 | 
        
           |  |  | 230 |         poster: '',
 | 
        
           |  |  | 231 |         width: get$1(styles, 'max-width').map(trimPx).getOr(''),
 | 
        
           |  |  | 232 |         height: get$1(styles, 'max-height').map(trimPx).getOr('')
 | 
        
           |  |  | 233 |       };
 | 
        
           |  |  | 234 |     };
 | 
        
           |  |  | 235 |     const htmlToData = (html, schema) => {
 | 
        
           |  |  | 236 |       let data = {};
 | 
        
           |  |  | 237 |       const parser = global$3({
 | 
        
           |  |  | 238 |         validate: false,
 | 
        
           |  |  | 239 |         forced_root_block: false
 | 
        
           |  |  | 240 |       }, schema);
 | 
        
           |  |  | 241 |       const rootNode = parser.parse(html);
 | 
        
           |  |  | 242 |       for (let node = rootNode; node; node = node.walk()) {
 | 
        
           |  |  | 243 |         if (node.type === 1) {
 | 
        
           |  |  | 244 |           const name = node.name;
 | 
        
           |  |  | 245 |           if (node.attr('data-ephox-embed-iri')) {
 | 
        
           |  |  | 246 |             data = getEphoxEmbedData(node);
 | 
        
           |  |  | 247 |             break;
 | 
        
           |  |  | 248 |           } else {
 | 
        
           |  |  | 249 |             if (!data.source && name === 'param') {
 | 
        
           |  |  | 250 |               data.source = node.attr('movie');
 | 
        
           |  |  | 251 |             }
 | 
        
           |  |  | 252 |             if (name === 'iframe' || name === 'object' || name === 'embed' || name === 'video' || name === 'audio') {
 | 
        
           |  |  | 253 |               if (!data.type) {
 | 
        
           |  |  | 254 |                 data.type = name;
 | 
        
           |  |  | 255 |               }
 | 
        
           |  |  | 256 |               data = global$5.extend(node.attributes.map, data);
 | 
        
           |  |  | 257 |             }
 | 
        
           |  |  | 258 |             if (name === 'source') {
 | 
        
           |  |  | 259 |               if (!data.source) {
 | 
        
           |  |  | 260 |                 data.source = node.attr('src');
 | 
        
           |  |  | 261 |               } else if (!data.altsource) {
 | 
        
           |  |  | 262 |                 data.altsource = node.attr('src');
 | 
        
           |  |  | 263 |               }
 | 
        
           |  |  | 264 |             }
 | 
        
           |  |  | 265 |             if (name === 'img' && !data.poster) {
 | 
        
           |  |  | 266 |               data.poster = node.attr('src');
 | 
        
           |  |  | 267 |             }
 | 
        
           |  |  | 268 |           }
 | 
        
           |  |  | 269 |         }
 | 
        
           |  |  | 270 |       }
 | 
        
           |  |  | 271 |       data.source = data.source || data.src || '';
 | 
        
           |  |  | 272 |       data.altsource = data.altsource || '';
 | 
        
           |  |  | 273 |       data.poster = data.poster || '';
 | 
        
           |  |  | 274 |       return data;
 | 
        
           |  |  | 275 |     };
 | 
        
           |  |  | 276 |   | 
        
           |  |  | 277 |     const guess = url => {
 | 
        
           |  |  | 278 |       var _a;
 | 
        
           |  |  | 279 |       const mimes = {
 | 
        
           |  |  | 280 |         mp3: 'audio/mpeg',
 | 
        
           |  |  | 281 |         m4a: 'audio/x-m4a',
 | 
        
           |  |  | 282 |         wav: 'audio/wav',
 | 
        
           |  |  | 283 |         mp4: 'video/mp4',
 | 
        
           |  |  | 284 |         webm: 'video/webm',
 | 
        
           |  |  | 285 |         ogg: 'video/ogg',
 | 
        
           |  |  | 286 |         swf: 'application/x-shockwave-flash'
 | 
        
           |  |  | 287 |       };
 | 
        
           |  |  | 288 |       const fileEnd = (_a = url.toLowerCase().split('.').pop()) !== null && _a !== void 0 ? _a : '';
 | 
        
           |  |  | 289 |       return get$1(mimes, fileEnd).getOr('');
 | 
        
           |  |  | 290 |     };
 | 
        
           |  |  | 291 |   | 
        
           |  |  | 292 |     var global$2 = tinymce.util.Tools.resolve('tinymce.html.Node');
 | 
        
           |  |  | 293 |   | 
        
           |  |  | 294 |     var global$1 = tinymce.util.Tools.resolve('tinymce.html.Serializer');
 | 
        
           |  |  | 295 |   | 
        
           |  |  | 296 |     const Parser = (schema, settings = {}) => global$3({
 | 
        
           |  |  | 297 |       forced_root_block: false,
 | 
        
           |  |  | 298 |       validate: false,
 | 
        
           |  |  | 299 |       allow_conditional_comments: true,
 | 
        
           |  |  | 300 |       ...settings
 | 
        
           |  |  | 301 |     }, schema);
 | 
        
           |  |  | 302 |   | 
        
           |  |  | 303 |     const DOM = global$4.DOM;
 | 
        
           |  |  | 304 |     const addPx = value => /^[0-9.]+$/.test(value) ? value + 'px' : value;
 | 
        
           |  |  | 305 |     const updateEphoxEmbed = (data, node) => {
 | 
        
           |  |  | 306 |       const style = node.attr('style');
 | 
        
           |  |  | 307 |       const styleMap = style ? DOM.parseStyle(style) : {};
 | 
        
           |  |  | 308 |       if (isNonNullable(data.width)) {
 | 
        
           |  |  | 309 |         styleMap['max-width'] = addPx(data.width);
 | 
        
           |  |  | 310 |       }
 | 
        
           |  |  | 311 |       if (isNonNullable(data.height)) {
 | 
        
           |  |  | 312 |         styleMap['max-height'] = addPx(data.height);
 | 
        
           |  |  | 313 |       }
 | 
        
           |  |  | 314 |       node.attr('style', DOM.serializeStyle(styleMap));
 | 
        
           |  |  | 315 |     };
 | 
        
           |  |  | 316 |     const sources = [
 | 
        
           |  |  | 317 |       'source',
 | 
        
           |  |  | 318 |       'altsource'
 | 
        
           |  |  | 319 |     ];
 | 
        
           |  |  | 320 |     const updateHtml = (html, data, updateAll, schema) => {
 | 
        
           |  |  | 321 |       let numSources = 0;
 | 
        
           |  |  | 322 |       let sourceCount = 0;
 | 
        
           |  |  | 323 |       const parser = Parser(schema);
 | 
        
           |  |  | 324 |       parser.addNodeFilter('source', nodes => numSources = nodes.length);
 | 
        
           |  |  | 325 |       const rootNode = parser.parse(html);
 | 
        
           |  |  | 326 |       for (let node = rootNode; node; node = node.walk()) {
 | 
        
           |  |  | 327 |         if (node.type === 1) {
 | 
        
           |  |  | 328 |           const name = node.name;
 | 
        
           |  |  | 329 |           if (node.attr('data-ephox-embed-iri')) {
 | 
        
           |  |  | 330 |             updateEphoxEmbed(data, node);
 | 
        
           |  |  | 331 |             break;
 | 
        
           |  |  | 332 |           } else {
 | 
        
           |  |  | 333 |             switch (name) {
 | 
        
           |  |  | 334 |             case 'video':
 | 
        
           |  |  | 335 |             case 'object':
 | 
        
           |  |  | 336 |             case 'embed':
 | 
        
           |  |  | 337 |             case 'img':
 | 
        
           |  |  | 338 |             case 'iframe':
 | 
        
           |  |  | 339 |               if (data.height !== undefined && data.width !== undefined) {
 | 
        
           |  |  | 340 |                 node.attr('width', data.width);
 | 
        
           |  |  | 341 |                 node.attr('height', data.height);
 | 
        
           |  |  | 342 |               }
 | 
        
           |  |  | 343 |               break;
 | 
        
           |  |  | 344 |             }
 | 
        
           |  |  | 345 |             if (updateAll) {
 | 
        
           |  |  | 346 |               switch (name) {
 | 
        
           |  |  | 347 |               case 'video':
 | 
        
           |  |  | 348 |                 node.attr('poster', data.poster);
 | 
        
           |  |  | 349 |                 node.attr('src', null);
 | 
        
           |  |  | 350 |                 for (let index = numSources; index < 2; index++) {
 | 
        
           |  |  | 351 |                   if (data[sources[index]]) {
 | 
        
           |  |  | 352 |                     const source = new global$2('source', 1);
 | 
        
           |  |  | 353 |                     source.attr('src', data[sources[index]]);
 | 
        
           |  |  | 354 |                     source.attr('type', data[sources[index] + 'mime'] || null);
 | 
        
           |  |  | 355 |                     node.append(source);
 | 
        
           |  |  | 356 |                   }
 | 
        
           |  |  | 357 |                 }
 | 
        
           |  |  | 358 |                 break;
 | 
        
           |  |  | 359 |               case 'iframe':
 | 
        
           |  |  | 360 |                 node.attr('src', data.source);
 | 
        
           |  |  | 361 |                 break;
 | 
        
           |  |  | 362 |               case 'object':
 | 
        
           |  |  | 363 |                 const hasImage = node.getAll('img').length > 0;
 | 
        
           |  |  | 364 |                 if (data.poster && !hasImage) {
 | 
        
           |  |  | 365 |                   node.attr('src', data.poster);
 | 
        
           |  |  | 366 |                   const img = new global$2('img', 1);
 | 
        
           |  |  | 367 |                   img.attr('src', data.poster);
 | 
        
           |  |  | 368 |                   img.attr('width', data.width);
 | 
        
           |  |  | 369 |                   img.attr('height', data.height);
 | 
        
           |  |  | 370 |                   node.append(img);
 | 
        
           |  |  | 371 |                 }
 | 
        
           |  |  | 372 |                 break;
 | 
        
           |  |  | 373 |               case 'source':
 | 
        
           |  |  | 374 |                 if (sourceCount < 2) {
 | 
        
           |  |  | 375 |                   node.attr('src', data[sources[sourceCount]]);
 | 
        
           |  |  | 376 |                   node.attr('type', data[sources[sourceCount] + 'mime'] || null);
 | 
        
           |  |  | 377 |                   if (!data[sources[sourceCount]]) {
 | 
        
           |  |  | 378 |                     node.remove();
 | 
        
           |  |  | 379 |                     continue;
 | 
        
           |  |  | 380 |                   }
 | 
        
           |  |  | 381 |                 }
 | 
        
           |  |  | 382 |                 sourceCount++;
 | 
        
           |  |  | 383 |                 break;
 | 
        
           |  |  | 384 |               case 'img':
 | 
        
           |  |  | 385 |                 if (!data.poster) {
 | 
        
           |  |  | 386 |                   node.remove();
 | 
        
           |  |  | 387 |                 }
 | 
        
           |  |  | 388 |                 break;
 | 
        
           |  |  | 389 |               }
 | 
        
           |  |  | 390 |             }
 | 
        
           |  |  | 391 |           }
 | 
        
           |  |  | 392 |         }
 | 
        
           |  |  | 393 |       }
 | 
        
           |  |  | 394 |       return global$1({}, schema).serialize(rootNode);
 | 
        
           |  |  | 395 |     };
 | 
        
           |  |  | 396 |   | 
        
           |  |  | 397 |     const urlPatterns = [
 | 
        
           |  |  | 398 |       {
 | 
        
           |  |  | 399 |         regex: /youtu\.be\/([\w\-_\?&=.]+)/i,
 | 
        
           |  |  | 400 |         type: 'iframe',
 | 
        
           |  |  | 401 |         w: 560,
 | 
        
           |  |  | 402 |         h: 314,
 | 
        
           |  |  | 403 |         url: 'www.youtube.com/embed/$1',
 | 
        
           |  |  | 404 |         allowFullscreen: true
 | 
        
           |  |  | 405 |       },
 | 
        
           |  |  | 406 |       {
 | 
        
           |  |  | 407 |         regex: /youtube\.com(.+)v=([^&]+)(&([a-z0-9&=\-_]+))?/i,
 | 
        
           |  |  | 408 |         type: 'iframe',
 | 
        
           |  |  | 409 |         w: 560,
 | 
        
           |  |  | 410 |         h: 314,
 | 
        
           |  |  | 411 |         url: 'www.youtube.com/embed/$2?$4',
 | 
        
           |  |  | 412 |         allowFullscreen: true
 | 
        
           |  |  | 413 |       },
 | 
        
           |  |  | 414 |       {
 | 
        
           |  |  | 415 |         regex: /youtube.com\/embed\/([a-z0-9\?&=\-_]+)/i,
 | 
        
           |  |  | 416 |         type: 'iframe',
 | 
        
           |  |  | 417 |         w: 560,
 | 
        
           |  |  | 418 |         h: 314,
 | 
        
           |  |  | 419 |         url: 'www.youtube.com/embed/$1',
 | 
        
           |  |  | 420 |         allowFullscreen: true
 | 
        
           |  |  | 421 |       },
 | 
        
           |  |  | 422 |       {
 | 
        
           |  |  | 423 |         regex: /vimeo\.com\/([0-9]+)\?h=(\w+)/,
 | 
        
           |  |  | 424 |         type: 'iframe',
 | 
        
           |  |  | 425 |         w: 425,
 | 
        
           |  |  | 426 |         h: 350,
 | 
        
           |  |  | 427 |         url: 'player.vimeo.com/video/$1?h=$2&title=0&byline=0&portrait=0&color=8dc7dc',
 | 
        
           |  |  | 428 |         allowFullscreen: true
 | 
        
           |  |  | 429 |       },
 | 
        
           |  |  | 430 |       {
 | 
        
           |  |  | 431 |         regex: /vimeo\.com\/(.*)\/([0-9]+)\?h=(\w+)/,
 | 
        
           |  |  | 432 |         type: 'iframe',
 | 
        
           |  |  | 433 |         w: 425,
 | 
        
           |  |  | 434 |         h: 350,
 | 
        
           |  |  | 435 |         url: 'player.vimeo.com/video/$2?h=$3&title=0&byline=0',
 | 
        
           |  |  | 436 |         allowFullscreen: true
 | 
        
           |  |  | 437 |       },
 | 
        
           |  |  | 438 |       {
 | 
        
           |  |  | 439 |         regex: /vimeo\.com\/([0-9]+)/,
 | 
        
           |  |  | 440 |         type: 'iframe',
 | 
        
           |  |  | 441 |         w: 425,
 | 
        
           |  |  | 442 |         h: 350,
 | 
        
           |  |  | 443 |         url: 'player.vimeo.com/video/$1?title=0&byline=0&portrait=0&color=8dc7dc',
 | 
        
           |  |  | 444 |         allowFullscreen: true
 | 
        
           |  |  | 445 |       },
 | 
        
           |  |  | 446 |       {
 | 
        
           |  |  | 447 |         regex: /vimeo\.com\/(.*)\/([0-9]+)/,
 | 
        
           |  |  | 448 |         type: 'iframe',
 | 
        
           |  |  | 449 |         w: 425,
 | 
        
           |  |  | 450 |         h: 350,
 | 
        
           |  |  | 451 |         url: 'player.vimeo.com/video/$2?title=0&byline=0',
 | 
        
           |  |  | 452 |         allowFullscreen: true
 | 
        
           |  |  | 453 |       },
 | 
        
           |  |  | 454 |       {
 | 
        
           |  |  | 455 |         regex: /maps\.google\.([a-z]{2,3})\/maps\/(.+)msid=(.+)/,
 | 
        
           |  |  | 456 |         type: 'iframe',
 | 
        
           |  |  | 457 |         w: 425,
 | 
        
           |  |  | 458 |         h: 350,
 | 
        
           |  |  | 459 |         url: 'maps.google.com/maps/ms?msid=$2&output=embed"',
 | 
        
           |  |  | 460 |         allowFullscreen: false
 | 
        
           |  |  | 461 |       },
 | 
        
           |  |  | 462 |       {
 | 
        
           |  |  | 463 |         regex: /dailymotion\.com\/video\/([^_]+)/,
 | 
        
           |  |  | 464 |         type: 'iframe',
 | 
        
           |  |  | 465 |         w: 480,
 | 
        
           |  |  | 466 |         h: 270,
 | 
        
           |  |  | 467 |         url: 'www.dailymotion.com/embed/video/$1',
 | 
        
           |  |  | 468 |         allowFullscreen: true
 | 
        
           |  |  | 469 |       },
 | 
        
           |  |  | 470 |       {
 | 
        
           |  |  | 471 |         regex: /dai\.ly\/([^_]+)/,
 | 
        
           |  |  | 472 |         type: 'iframe',
 | 
        
           |  |  | 473 |         w: 480,
 | 
        
           |  |  | 474 |         h: 270,
 | 
        
           |  |  | 475 |         url: 'www.dailymotion.com/embed/video/$1',
 | 
        
           |  |  | 476 |         allowFullscreen: true
 | 
        
           |  |  | 477 |       }
 | 
        
           |  |  | 478 |     ];
 | 
        
           |  |  | 479 |     const getProtocol = url => {
 | 
        
           |  |  | 480 |       const protocolMatches = url.match(/^(https?:\/\/|www\.)(.+)$/i);
 | 
        
           |  |  | 481 |       if (protocolMatches && protocolMatches.length > 1) {
 | 
        
           |  |  | 482 |         return protocolMatches[1] === 'www.' ? 'https://' : protocolMatches[1];
 | 
        
           |  |  | 483 |       } else {
 | 
        
           |  |  | 484 |         return 'https://';
 | 
        
           |  |  | 485 |       }
 | 
        
           |  |  | 486 |     };
 | 
        
           |  |  | 487 |     const getUrl = (pattern, url) => {
 | 
        
           |  |  | 488 |       const protocol = getProtocol(url);
 | 
        
           |  |  | 489 |       const match = pattern.regex.exec(url);
 | 
        
           |  |  | 490 |       let newUrl = protocol + pattern.url;
 | 
        
           |  |  | 491 |       if (isNonNullable(match)) {
 | 
        
           |  |  | 492 |         for (let i = 0; i < match.length; i++) {
 | 
        
           |  |  | 493 |           newUrl = newUrl.replace('$' + i, () => match[i] ? match[i] : '');
 | 
        
           |  |  | 494 |         }
 | 
        
           |  |  | 495 |       }
 | 
        
           |  |  | 496 |       return newUrl.replace(/\?$/, '');
 | 
        
           |  |  | 497 |     };
 | 
        
           |  |  | 498 |     const matchPattern = url => {
 | 
        
           |  |  | 499 |       const patterns = urlPatterns.filter(pattern => pattern.regex.test(url));
 | 
        
           |  |  | 500 |       if (patterns.length > 0) {
 | 
        
           |  |  | 501 |         return global$5.extend({}, patterns[0], { url: getUrl(patterns[0], url) });
 | 
        
           |  |  | 502 |       } else {
 | 
        
           |  |  | 503 |         return null;
 | 
        
           |  |  | 504 |       }
 | 
        
           |  |  | 505 |     };
 | 
        
           |  |  | 506 |   | 
        
           |  |  | 507 |     const getIframeHtml = (data, iframeTemplateCallback) => {
 | 
        
           |  |  | 508 |       if (iframeTemplateCallback) {
 | 
        
           |  |  | 509 |         return iframeTemplateCallback(data);
 | 
        
           |  |  | 510 |       } else {
 | 
        
           |  |  | 511 |         const allowFullscreen = data.allowfullscreen ? ' allowFullscreen="1"' : '';
 | 
        
           |  |  | 512 |         return '<iframe src="' + data.source + '" width="' + data.width + '" height="' + data.height + '"' + allowFullscreen + '></iframe>';
 | 
        
           |  |  | 513 |       }
 | 
        
           |  |  | 514 |     };
 | 
        
           |  |  | 515 |     const getFlashHtml = data => {
 | 
        
           |  |  | 516 |       let html = '<object data="' + data.source + '" width="' + data.width + '" height="' + data.height + '" type="application/x-shockwave-flash">';
 | 
        
           |  |  | 517 |       if (data.poster) {
 | 
        
           |  |  | 518 |         html += '<img src="' + data.poster + '" width="' + data.width + '" height="' + data.height + '" />';
 | 
        
           |  |  | 519 |       }
 | 
        
           |  |  | 520 |       html += '</object>';
 | 
        
           |  |  | 521 |       return html;
 | 
        
           |  |  | 522 |     };
 | 
        
           |  |  | 523 |     const getAudioHtml = (data, audioTemplateCallback) => {
 | 
        
           |  |  | 524 |       if (audioTemplateCallback) {
 | 
        
           |  |  | 525 |         return audioTemplateCallback(data);
 | 
        
           |  |  | 526 |       } else {
 | 
        
           |  |  | 527 |         return '<audio controls="controls" src="' + data.source + '">' + (data.altsource ? '\n<source src="' + data.altsource + '"' + (data.altsourcemime ? ' type="' + data.altsourcemime + '"' : '') + ' />\n' : '') + '</audio>';
 | 
        
           |  |  | 528 |       }
 | 
        
           |  |  | 529 |     };
 | 
        
           |  |  | 530 |     const getVideoHtml = (data, videoTemplateCallback) => {
 | 
        
           |  |  | 531 |       if (videoTemplateCallback) {
 | 
        
           |  |  | 532 |         return videoTemplateCallback(data);
 | 
        
           |  |  | 533 |       } else {
 | 
        
           |  |  | 534 |         return '<video width="' + data.width + '" height="' + data.height + '"' + (data.poster ? ' poster="' + data.poster + '"' : '') + ' controls="controls">\n' + '<source src="' + data.source + '"' + (data.sourcemime ? ' type="' + data.sourcemime + '"' : '') + ' />\n' + (data.altsource ? '<source src="' + data.altsource + '"' + (data.altsourcemime ? ' type="' + data.altsourcemime + '"' : '') + ' />\n' : '') + '</video>';
 | 
        
           |  |  | 535 |       }
 | 
        
           |  |  | 536 |     };
 | 
        
           |  |  | 537 |     const dataToHtml = (editor, dataIn) => {
 | 
        
           |  |  | 538 |       var _a;
 | 
        
           |  |  | 539 |       const data = global$5.extend({}, dataIn);
 | 
        
           |  |  | 540 |       if (!data.source) {
 | 
        
           |  |  | 541 |         global$5.extend(data, htmlToData((_a = data.embed) !== null && _a !== void 0 ? _a : '', editor.schema));
 | 
        
           |  |  | 542 |         if (!data.source) {
 | 
        
           |  |  | 543 |           return '';
 | 
        
           |  |  | 544 |         }
 | 
        
           |  |  | 545 |       }
 | 
        
           |  |  | 546 |       if (!data.altsource) {
 | 
        
           |  |  | 547 |         data.altsource = '';
 | 
        
           |  |  | 548 |       }
 | 
        
           |  |  | 549 |       if (!data.poster) {
 | 
        
           |  |  | 550 |         data.poster = '';
 | 
        
           |  |  | 551 |       }
 | 
        
           |  |  | 552 |       data.source = editor.convertURL(data.source, 'source');
 | 
        
           |  |  | 553 |       data.altsource = editor.convertURL(data.altsource, 'source');
 | 
        
           |  |  | 554 |       data.sourcemime = guess(data.source);
 | 
        
           |  |  | 555 |       data.altsourcemime = guess(data.altsource);
 | 
        
           |  |  | 556 |       data.poster = editor.convertURL(data.poster, 'poster');
 | 
        
           |  |  | 557 |       const pattern = matchPattern(data.source);
 | 
        
           |  |  | 558 |       if (pattern) {
 | 
        
           |  |  | 559 |         data.source = pattern.url;
 | 
        
           |  |  | 560 |         data.type = pattern.type;
 | 
        
           |  |  | 561 |         data.allowfullscreen = pattern.allowFullscreen;
 | 
        
           |  |  | 562 |         data.width = data.width || String(pattern.w);
 | 
        
           |  |  | 563 |         data.height = data.height || String(pattern.h);
 | 
        
           |  |  | 564 |       }
 | 
        
           |  |  | 565 |       if (data.embed) {
 | 
        
           |  |  | 566 |         return updateHtml(data.embed, data, true, editor.schema);
 | 
        
           |  |  | 567 |       } else {
 | 
        
           |  |  | 568 |         const audioTemplateCallback = getAudioTemplateCallback(editor);
 | 
        
           |  |  | 569 |         const videoTemplateCallback = getVideoTemplateCallback(editor);
 | 
        
           |  |  | 570 |         const iframeTemplateCallback = getIframeTemplateCallback(editor);
 | 
        
           |  |  | 571 |         data.width = data.width || '300';
 | 
        
           |  |  | 572 |         data.height = data.height || '150';
 | 
        
           |  |  | 573 |         global$5.each(data, (value, key) => {
 | 
        
           |  |  | 574 |           data[key] = editor.dom.encode('' + value);
 | 
        
           |  |  | 575 |         });
 | 
        
           |  |  | 576 |         if (data.type === 'iframe') {
 | 
        
           |  |  | 577 |           return getIframeHtml(data, iframeTemplateCallback);
 | 
        
           |  |  | 578 |         } else if (data.sourcemime === 'application/x-shockwave-flash') {
 | 
        
           |  |  | 579 |           return getFlashHtml(data);
 | 
        
           |  |  | 580 |         } else if (data.sourcemime.indexOf('audio') !== -1) {
 | 
        
           |  |  | 581 |           return getAudioHtml(data, audioTemplateCallback);
 | 
        
           |  |  | 582 |         } else {
 | 
        
           |  |  | 583 |           return getVideoHtml(data, videoTemplateCallback);
 | 
        
           |  |  | 584 |         }
 | 
        
           |  |  | 585 |       }
 | 
        
           |  |  | 586 |     };
 | 
        
           |  |  | 587 |   | 
        
           |  |  | 588 |     const isMediaElement = element => element.hasAttribute('data-mce-object') || element.hasAttribute('data-ephox-embed-iri');
 | 
        
           |  |  | 589 |     const setup$2 = editor => {
 | 
        
           | 1441 | ariadna | 590 |       editor.on('mousedown', e => {
 | 
        
           |  |  | 591 |         const previewObj = editor.dom.getParent(e.target, '.mce-preview-object');
 | 
        
           |  |  | 592 |         if (previewObj && editor.dom.getAttrib(previewObj, 'data-mce-selected') === '2') {
 | 
        
           |  |  | 593 |           e.stopImmediatePropagation();
 | 
        
           |  |  | 594 |         }
 | 
        
           |  |  | 595 |       });
 | 
        
           | 1 | efrain | 596 |       editor.on('click keyup touchend', () => {
 | 
        
           |  |  | 597 |         const selectedNode = editor.selection.getNode();
 | 
        
           |  |  | 598 |         if (selectedNode && editor.dom.hasClass(selectedNode, 'mce-preview-object')) {
 | 
        
           |  |  | 599 |           if (editor.dom.getAttrib(selectedNode, 'data-mce-selected')) {
 | 
        
           |  |  | 600 |             selectedNode.setAttribute('data-mce-selected', '2');
 | 
        
           |  |  | 601 |           }
 | 
        
           |  |  | 602 |         }
 | 
        
           |  |  | 603 |       });
 | 
        
           |  |  | 604 |       editor.on('ObjectResized', e => {
 | 
        
           |  |  | 605 |         const target = e.target;
 | 
        
           |  |  | 606 |         if (target.getAttribute('data-mce-object')) {
 | 
        
           |  |  | 607 |           let html = target.getAttribute('data-mce-html');
 | 
        
           |  |  | 608 |           if (html) {
 | 
        
           |  |  | 609 |             html = unescape(html);
 | 
        
           |  |  | 610 |             target.setAttribute('data-mce-html', escape(updateHtml(html, {
 | 
        
           |  |  | 611 |               width: String(e.width),
 | 
        
           |  |  | 612 |               height: String(e.height)
 | 
        
           |  |  | 613 |             }, false, editor.schema)));
 | 
        
           |  |  | 614 |           }
 | 
        
           |  |  | 615 |         }
 | 
        
           |  |  | 616 |       });
 | 
        
           |  |  | 617 |     };
 | 
        
           |  |  | 618 |   | 
        
           |  |  | 619 |     const cache = {};
 | 
        
           |  |  | 620 |     const embedPromise = (data, dataToHtml, handler) => {
 | 
        
           |  |  | 621 |       return new Promise((res, rej) => {
 | 
        
           |  |  | 622 |         const wrappedResolve = response => {
 | 
        
           |  |  | 623 |           if (response.html) {
 | 
        
           |  |  | 624 |             cache[data.source] = response;
 | 
        
           |  |  | 625 |           }
 | 
        
           |  |  | 626 |           return res({
 | 
        
           |  |  | 627 |             url: data.source,
 | 
        
           |  |  | 628 |             html: response.html ? response.html : dataToHtml(data)
 | 
        
           |  |  | 629 |           });
 | 
        
           |  |  | 630 |         };
 | 
        
           |  |  | 631 |         if (cache[data.source]) {
 | 
        
           |  |  | 632 |           wrappedResolve(cache[data.source]);
 | 
        
           |  |  | 633 |         } else {
 | 
        
           | 1441 | ariadna | 634 |           handler({ url: data.source }).then(wrappedResolve).catch(rej);
 | 
        
           | 1 | efrain | 635 |         }
 | 
        
           |  |  | 636 |       });
 | 
        
           |  |  | 637 |     };
 | 
        
           |  |  | 638 |     const defaultPromise = (data, dataToHtml) => Promise.resolve({
 | 
        
           |  |  | 639 |       html: dataToHtml(data),
 | 
        
           |  |  | 640 |       url: data.source
 | 
        
           |  |  | 641 |     });
 | 
        
           |  |  | 642 |     const loadedData = editor => data => dataToHtml(editor, data);
 | 
        
           |  |  | 643 |     const getEmbedHtml = (editor, data) => {
 | 
        
           |  |  | 644 |       const embedHandler = getUrlResolver(editor);
 | 
        
           |  |  | 645 |       return embedHandler ? embedPromise(data, loadedData(editor), embedHandler) : defaultPromise(data, loadedData(editor));
 | 
        
           |  |  | 646 |     };
 | 
        
           |  |  | 647 |     const isCached = url => has(cache, url);
 | 
        
           |  |  | 648 |   | 
        
           |  |  | 649 |     const extractMeta = (sourceInput, data) => get$1(data, sourceInput).bind(mainData => get$1(mainData, 'meta'));
 | 
        
           |  |  | 650 |     const getValue = (data, metaData, sourceInput) => prop => {
 | 
        
           |  |  | 651 |       const getFromData = () => get$1(data, prop);
 | 
        
           |  |  | 652 |       const getFromMetaData = () => get$1(metaData, prop);
 | 
        
           |  |  | 653 |       const getNonEmptyValue = c => get$1(c, 'value').bind(v => v.length > 0 ? Optional.some(v) : Optional.none());
 | 
        
           |  |  | 654 |       const getFromValueFirst = () => getFromData().bind(child => isObject(child) ? getNonEmptyValue(child).orThunk(getFromMetaData) : getFromMetaData().orThunk(() => Optional.from(child)));
 | 
        
           |  |  | 655 |       const getFromMetaFirst = () => getFromMetaData().orThunk(() => getFromData().bind(child => isObject(child) ? getNonEmptyValue(child) : Optional.from(child)));
 | 
        
           |  |  | 656 |       return { [prop]: (prop === sourceInput ? getFromValueFirst() : getFromMetaFirst()).getOr('') };
 | 
        
           |  |  | 657 |     };
 | 
        
           |  |  | 658 |     const getDimensions = (data, metaData) => {
 | 
        
           |  |  | 659 |       const dimensions = {};
 | 
        
           |  |  | 660 |       get$1(data, 'dimensions').each(dims => {
 | 
        
           |  |  | 661 |         each$1([
 | 
        
           |  |  | 662 |           'width',
 | 
        
           |  |  | 663 |           'height'
 | 
        
           |  |  | 664 |         ], prop => {
 | 
        
           |  |  | 665 |           get$1(metaData, prop).orThunk(() => get$1(dims, prop)).each(value => dimensions[prop] = value);
 | 
        
           |  |  | 666 |         });
 | 
        
           |  |  | 667 |       });
 | 
        
           |  |  | 668 |       return dimensions;
 | 
        
           |  |  | 669 |     };
 | 
        
           |  |  | 670 |     const unwrap = (data, sourceInput) => {
 | 
        
           |  |  | 671 |       const metaData = sourceInput && sourceInput !== 'dimensions' ? extractMeta(sourceInput, data).getOr({}) : {};
 | 
        
           |  |  | 672 |       const get = getValue(data, metaData, sourceInput);
 | 
        
           |  |  | 673 |       return {
 | 
        
           |  |  | 674 |         ...get('source'),
 | 
        
           |  |  | 675 |         ...get('altsource'),
 | 
        
           |  |  | 676 |         ...get('poster'),
 | 
        
           |  |  | 677 |         ...get('embed'),
 | 
        
           |  |  | 678 |         ...getDimensions(data, metaData)
 | 
        
           |  |  | 679 |       };
 | 
        
           |  |  | 680 |     };
 | 
        
           |  |  | 681 |     const wrap = data => {
 | 
        
           |  |  | 682 |       const wrapped = {
 | 
        
           |  |  | 683 |         ...data,
 | 
        
           |  |  | 684 |         source: { value: get$1(data, 'source').getOr('') },
 | 
        
           |  |  | 685 |         altsource: { value: get$1(data, 'altsource').getOr('') },
 | 
        
           |  |  | 686 |         poster: { value: get$1(data, 'poster').getOr('') }
 | 
        
           |  |  | 687 |       };
 | 
        
           |  |  | 688 |       each$1([
 | 
        
           |  |  | 689 |         'width',
 | 
        
           |  |  | 690 |         'height'
 | 
        
           |  |  | 691 |       ], prop => {
 | 
        
           |  |  | 692 |         get$1(data, prop).each(value => {
 | 
        
           |  |  | 693 |           const dimensions = wrapped.dimensions || {};
 | 
        
           |  |  | 694 |           dimensions[prop] = value;
 | 
        
           |  |  | 695 |           wrapped.dimensions = dimensions;
 | 
        
           |  |  | 696 |         });
 | 
        
           |  |  | 697 |       });
 | 
        
           |  |  | 698 |       return wrapped;
 | 
        
           |  |  | 699 |     };
 | 
        
           |  |  | 700 |     const handleError = editor => error => {
 | 
        
           |  |  | 701 |       const errorMessage = error && error.msg ? 'Media embed handler error: ' + error.msg : 'Media embed handler threw unknown error.';
 | 
        
           |  |  | 702 |       editor.notificationManager.open({
 | 
        
           |  |  | 703 |         type: 'error',
 | 
        
           |  |  | 704 |         text: errorMessage
 | 
        
           |  |  | 705 |       });
 | 
        
           |  |  | 706 |     };
 | 
        
           |  |  | 707 |     const getEditorData = editor => {
 | 
        
           |  |  | 708 |       const element = editor.selection.getNode();
 | 
        
           |  |  | 709 |       const snippet = isMediaElement(element) ? editor.serializer.serialize(element, { selection: true }) : '';
 | 
        
           |  |  | 710 |       const data = htmlToData(snippet, editor.schema);
 | 
        
           |  |  | 711 |       const getDimensionsOfElement = () => {
 | 
        
           |  |  | 712 |         if (isEmbedIframe(data.source, data.type)) {
 | 
        
           |  |  | 713 |           const rect = editor.dom.getRect(element);
 | 
        
           |  |  | 714 |           return {
 | 
        
           |  |  | 715 |             width: rect.w.toString().replace(/px$/, ''),
 | 
        
           |  |  | 716 |             height: rect.h.toString().replace(/px$/, '')
 | 
        
           |  |  | 717 |           };
 | 
        
           |  |  | 718 |         } else {
 | 
        
           |  |  | 719 |           return {};
 | 
        
           |  |  | 720 |         }
 | 
        
           |  |  | 721 |       };
 | 
        
           |  |  | 722 |       const dimensions = getDimensionsOfElement();
 | 
        
           |  |  | 723 |       return {
 | 
        
           |  |  | 724 |         embed: snippet,
 | 
        
           |  |  | 725 |         ...data,
 | 
        
           |  |  | 726 |         ...dimensions
 | 
        
           |  |  | 727 |       };
 | 
        
           |  |  | 728 |     };
 | 
        
           |  |  | 729 |     const addEmbedHtml = (api, editor) => response => {
 | 
        
           |  |  | 730 |       if (isString(response.url) && response.url.trim().length > 0) {
 | 
        
           |  |  | 731 |         const html = response.html;
 | 
        
           |  |  | 732 |         const snippetData = htmlToData(html, editor.schema);
 | 
        
           |  |  | 733 |         const nuData = {
 | 
        
           |  |  | 734 |           ...snippetData,
 | 
        
           |  |  | 735 |           source: response.url,
 | 
        
           |  |  | 736 |           embed: html
 | 
        
           |  |  | 737 |         };
 | 
        
           |  |  | 738 |         api.setData(wrap(nuData));
 | 
        
           |  |  | 739 |       }
 | 
        
           |  |  | 740 |     };
 | 
        
           |  |  | 741 |     const selectPlaceholder = (editor, beforeObjects) => {
 | 
        
           |  |  | 742 |       const afterObjects = editor.dom.select('*[data-mce-object]');
 | 
        
           |  |  | 743 |       for (let i = 0; i < beforeObjects.length; i++) {
 | 
        
           |  |  | 744 |         for (let y = afterObjects.length - 1; y >= 0; y--) {
 | 
        
           |  |  | 745 |           if (beforeObjects[i] === afterObjects[y]) {
 | 
        
           |  |  | 746 |             afterObjects.splice(y, 1);
 | 
        
           |  |  | 747 |           }
 | 
        
           |  |  | 748 |         }
 | 
        
           |  |  | 749 |       }
 | 
        
           |  |  | 750 |       editor.selection.select(afterObjects[0]);
 | 
        
           |  |  | 751 |     };
 | 
        
           |  |  | 752 |     const handleInsert = (editor, html) => {
 | 
        
           |  |  | 753 |       const beforeObjects = editor.dom.select('*[data-mce-object]');
 | 
        
           |  |  | 754 |       editor.insertContent(html);
 | 
        
           |  |  | 755 |       selectPlaceholder(editor, beforeObjects);
 | 
        
           |  |  | 756 |       editor.nodeChanged();
 | 
        
           |  |  | 757 |     };
 | 
        
           |  |  | 758 |     const isEmbedIframe = (url, mediaDataType) => isNonNullable(mediaDataType) && mediaDataType === 'ephox-embed-iri' && isNonNullable(matchPattern(url));
 | 
        
           |  |  | 759 |     const shouldInsertAsNewIframe = (prevData, newData) => {
 | 
        
           |  |  | 760 |       const hasDimensionsChanged = (prevData, newData) => prevData.width !== newData.width || prevData.height !== newData.height;
 | 
        
           |  |  | 761 |       return hasDimensionsChanged(prevData, newData) && isEmbedIframe(newData.source, prevData.type);
 | 
        
           |  |  | 762 |     };
 | 
        
           |  |  | 763 |     const submitForm = (prevData, newData, editor) => {
 | 
        
           |  |  | 764 |       var _a;
 | 
        
           |  |  | 765 |       newData.embed = shouldInsertAsNewIframe(prevData, newData) && hasDimensions(editor) ? dataToHtml(editor, {
 | 
        
           |  |  | 766 |         ...newData,
 | 
        
           |  |  | 767 |         embed: ''
 | 
        
           |  |  | 768 |       }) : updateHtml((_a = newData.embed) !== null && _a !== void 0 ? _a : '', newData, false, editor.schema);
 | 
        
           |  |  | 769 |       if (newData.embed && (prevData.source === newData.source || isCached(newData.source))) {
 | 
        
           |  |  | 770 |         handleInsert(editor, newData.embed);
 | 
        
           |  |  | 771 |       } else {
 | 
        
           |  |  | 772 |         getEmbedHtml(editor, newData).then(response => {
 | 
        
           |  |  | 773 |           handleInsert(editor, response.html);
 | 
        
           |  |  | 774 |         }).catch(handleError(editor));
 | 
        
           |  |  | 775 |       }
 | 
        
           |  |  | 776 |     };
 | 
        
           |  |  | 777 |     const showDialog = editor => {
 | 
        
           |  |  | 778 |       const editorData = getEditorData(editor);
 | 
        
           |  |  | 779 |       const currentData = Cell(editorData);
 | 
        
           |  |  | 780 |       const initialData = wrap(editorData);
 | 
        
           |  |  | 781 |       const handleSource = (prevData, api) => {
 | 
        
           |  |  | 782 |         const serviceData = unwrap(api.getData(), 'source');
 | 
        
           |  |  | 783 |         if (prevData.source !== serviceData.source) {
 | 
        
           |  |  | 784 |           addEmbedHtml(win, editor)({
 | 
        
           |  |  | 785 |             url: serviceData.source,
 | 
        
           |  |  | 786 |             html: ''
 | 
        
           |  |  | 787 |           });
 | 
        
           |  |  | 788 |           getEmbedHtml(editor, serviceData).then(addEmbedHtml(win, editor)).catch(handleError(editor));
 | 
        
           |  |  | 789 |         }
 | 
        
           |  |  | 790 |       };
 | 
        
           |  |  | 791 |       const handleEmbed = api => {
 | 
        
           |  |  | 792 |         var _a;
 | 
        
           |  |  | 793 |         const data = unwrap(api.getData());
 | 
        
           |  |  | 794 |         const dataFromEmbed = htmlToData((_a = data.embed) !== null && _a !== void 0 ? _a : '', editor.schema);
 | 
        
           |  |  | 795 |         api.setData(wrap(dataFromEmbed));
 | 
        
           |  |  | 796 |       };
 | 
        
           |  |  | 797 |       const handleUpdate = (api, sourceInput, prevData) => {
 | 
        
           |  |  | 798 |         const dialogData = unwrap(api.getData(), sourceInput);
 | 
        
           |  |  | 799 |         const data = shouldInsertAsNewIframe(prevData, dialogData) && hasDimensions(editor) ? {
 | 
        
           |  |  | 800 |           ...dialogData,
 | 
        
           |  |  | 801 |           embed: ''
 | 
        
           |  |  | 802 |         } : dialogData;
 | 
        
           |  |  | 803 |         const embed = dataToHtml(editor, data);
 | 
        
           |  |  | 804 |         api.setData(wrap({
 | 
        
           |  |  | 805 |           ...data,
 | 
        
           |  |  | 806 |           embed
 | 
        
           |  |  | 807 |         }));
 | 
        
           |  |  | 808 |       };
 | 
        
           |  |  | 809 |       const mediaInput = [{
 | 
        
           |  |  | 810 |           name: 'source',
 | 
        
           |  |  | 811 |           type: 'urlinput',
 | 
        
           |  |  | 812 |           filetype: 'media',
 | 
        
           |  |  | 813 |           label: 'Source',
 | 
        
           |  |  | 814 |           picker_text: 'Browse files'
 | 
        
           |  |  | 815 |         }];
 | 
        
           |  |  | 816 |       const sizeInput = !hasDimensions(editor) ? [] : [{
 | 
        
           |  |  | 817 |           type: 'sizeinput',
 | 
        
           |  |  | 818 |           name: 'dimensions',
 | 
        
           |  |  | 819 |           label: 'Constrain proportions',
 | 
        
           |  |  | 820 |           constrain: true
 | 
        
           |  |  | 821 |         }];
 | 
        
           |  |  | 822 |       const generalTab = {
 | 
        
           |  |  | 823 |         title: 'General',
 | 
        
           |  |  | 824 |         name: 'general',
 | 
        
           |  |  | 825 |         items: flatten([
 | 
        
           |  |  | 826 |           mediaInput,
 | 
        
           |  |  | 827 |           sizeInput
 | 
        
           |  |  | 828 |         ])
 | 
        
           |  |  | 829 |       };
 | 
        
           |  |  | 830 |       const embedTextarea = {
 | 
        
           |  |  | 831 |         type: 'textarea',
 | 
        
           |  |  | 832 |         name: 'embed',
 | 
        
           |  |  | 833 |         label: 'Paste your embed code below:'
 | 
        
           |  |  | 834 |       };
 | 
        
           |  |  | 835 |       const embedTab = {
 | 
        
           |  |  | 836 |         title: 'Embed',
 | 
        
           |  |  | 837 |         items: [embedTextarea]
 | 
        
           |  |  | 838 |       };
 | 
        
           |  |  | 839 |       const advancedFormItems = [];
 | 
        
           |  |  | 840 |       if (hasAltSource(editor)) {
 | 
        
           |  |  | 841 |         advancedFormItems.push({
 | 
        
           |  |  | 842 |           name: 'altsource',
 | 
        
           |  |  | 843 |           type: 'urlinput',
 | 
        
           |  |  | 844 |           filetype: 'media',
 | 
        
           |  |  | 845 |           label: 'Alternative source URL'
 | 
        
           |  |  | 846 |         });
 | 
        
           |  |  | 847 |       }
 | 
        
           |  |  | 848 |       if (hasPoster(editor)) {
 | 
        
           |  |  | 849 |         advancedFormItems.push({
 | 
        
           |  |  | 850 |           name: 'poster',
 | 
        
           |  |  | 851 |           type: 'urlinput',
 | 
        
           |  |  | 852 |           filetype: 'image',
 | 
        
           |  |  | 853 |           label: 'Media poster (Image URL)'
 | 
        
           |  |  | 854 |         });
 | 
        
           |  |  | 855 |       }
 | 
        
           |  |  | 856 |       const advancedTab = {
 | 
        
           |  |  | 857 |         title: 'Advanced',
 | 
        
           |  |  | 858 |         name: 'advanced',
 | 
        
           |  |  | 859 |         items: advancedFormItems
 | 
        
           |  |  | 860 |       };
 | 
        
           |  |  | 861 |       const tabs = [
 | 
        
           |  |  | 862 |         generalTab,
 | 
        
           |  |  | 863 |         embedTab
 | 
        
           |  |  | 864 |       ];
 | 
        
           |  |  | 865 |       if (advancedFormItems.length > 0) {
 | 
        
           |  |  | 866 |         tabs.push(advancedTab);
 | 
        
           |  |  | 867 |       }
 | 
        
           |  |  | 868 |       const body = {
 | 
        
           |  |  | 869 |         type: 'tabpanel',
 | 
        
           |  |  | 870 |         tabs
 | 
        
           |  |  | 871 |       };
 | 
        
           |  |  | 872 |       const win = editor.windowManager.open({
 | 
        
           |  |  | 873 |         title: 'Insert/Edit Media',
 | 
        
           |  |  | 874 |         size: 'normal',
 | 
        
           |  |  | 875 |         body,
 | 
        
           |  |  | 876 |         buttons: [
 | 
        
           |  |  | 877 |           {
 | 
        
           |  |  | 878 |             type: 'cancel',
 | 
        
           |  |  | 879 |             name: 'cancel',
 | 
        
           |  |  | 880 |             text: 'Cancel'
 | 
        
           |  |  | 881 |           },
 | 
        
           |  |  | 882 |           {
 | 
        
           |  |  | 883 |             type: 'submit',
 | 
        
           |  |  | 884 |             name: 'save',
 | 
        
           |  |  | 885 |             text: 'Save',
 | 
        
           |  |  | 886 |             primary: true
 | 
        
           |  |  | 887 |           }
 | 
        
           |  |  | 888 |         ],
 | 
        
           |  |  | 889 |         onSubmit: api => {
 | 
        
           |  |  | 890 |           const serviceData = unwrap(api.getData());
 | 
        
           |  |  | 891 |           submitForm(currentData.get(), serviceData, editor);
 | 
        
           |  |  | 892 |           api.close();
 | 
        
           |  |  | 893 |         },
 | 
        
           |  |  | 894 |         onChange: (api, detail) => {
 | 
        
           |  |  | 895 |           switch (detail.name) {
 | 
        
           |  |  | 896 |           case 'source':
 | 
        
           |  |  | 897 |             handleSource(currentData.get(), api);
 | 
        
           |  |  | 898 |             break;
 | 
        
           |  |  | 899 |           case 'embed':
 | 
        
           |  |  | 900 |             handleEmbed(api);
 | 
        
           |  |  | 901 |             break;
 | 
        
           |  |  | 902 |           case 'dimensions':
 | 
        
           |  |  | 903 |           case 'altsource':
 | 
        
           |  |  | 904 |           case 'poster':
 | 
        
           |  |  | 905 |             handleUpdate(api, detail.name, currentData.get());
 | 
        
           |  |  | 906 |             break;
 | 
        
           |  |  | 907 |           }
 | 
        
           |  |  | 908 |           currentData.set(unwrap(api.getData()));
 | 
        
           |  |  | 909 |         },
 | 
        
           |  |  | 910 |         initialData
 | 
        
           |  |  | 911 |       });
 | 
        
           |  |  | 912 |     };
 | 
        
           |  |  | 913 |   | 
        
           |  |  | 914 |     const get = editor => {
 | 
        
           |  |  | 915 |       const showDialog$1 = () => {
 | 
        
           |  |  | 916 |         showDialog(editor);
 | 
        
           |  |  | 917 |       };
 | 
        
           |  |  | 918 |       return { showDialog: showDialog$1 };
 | 
        
           |  |  | 919 |     };
 | 
        
           |  |  | 920 |   | 
        
           |  |  | 921 |     const register$1 = editor => {
 | 
        
           |  |  | 922 |       const showDialog$1 = () => {
 | 
        
           |  |  | 923 |         showDialog(editor);
 | 
        
           |  |  | 924 |       };
 | 
        
           |  |  | 925 |       editor.addCommand('mceMedia', showDialog$1);
 | 
        
           |  |  | 926 |     };
 | 
        
           |  |  | 927 |   | 
        
           |  |  | 928 |     const checkRange = (str, substr, start) => substr === '' || str.length >= substr.length && str.substr(start, start + substr.length) === substr;
 | 
        
           |  |  | 929 |     const startsWith = (str, prefix) => {
 | 
        
           |  |  | 930 |       return checkRange(str, prefix, 0);
 | 
        
           |  |  | 931 |     };
 | 
        
           |  |  | 932 |   | 
        
           |  |  | 933 |     var global = tinymce.util.Tools.resolve('tinymce.Env');
 | 
        
           |  |  | 934 |   | 
        
           |  |  | 935 |     const isLiveEmbedNode = node => {
 | 
        
           |  |  | 936 |       const name = node.name;
 | 
        
           |  |  | 937 |       return name === 'iframe' || name === 'video' || name === 'audio';
 | 
        
           |  |  | 938 |     };
 | 
        
           |  |  | 939 |     const getDimension = (node, styles, dimension, defaultValue = null) => {
 | 
        
           |  |  | 940 |       const value = node.attr(dimension);
 | 
        
           |  |  | 941 |       if (isNonNullable(value)) {
 | 
        
           |  |  | 942 |         return value;
 | 
        
           |  |  | 943 |       } else if (!has(styles, dimension)) {
 | 
        
           |  |  | 944 |         return defaultValue;
 | 
        
           |  |  | 945 |       } else {
 | 
        
           |  |  | 946 |         return null;
 | 
        
           |  |  | 947 |       }
 | 
        
           |  |  | 948 |     };
 | 
        
           |  |  | 949 |     const setDimensions = (node, previewNode, styles) => {
 | 
        
           |  |  | 950 |       const useDefaults = previewNode.name === 'img' || node.name === 'video';
 | 
        
           |  |  | 951 |       const defaultWidth = useDefaults ? '300' : null;
 | 
        
           |  |  | 952 |       const fallbackHeight = node.name === 'audio' ? '30' : '150';
 | 
        
           |  |  | 953 |       const defaultHeight = useDefaults ? fallbackHeight : null;
 | 
        
           |  |  | 954 |       previewNode.attr({
 | 
        
           |  |  | 955 |         width: getDimension(node, styles, 'width', defaultWidth),
 | 
        
           |  |  | 956 |         height: getDimension(node, styles, 'height', defaultHeight)
 | 
        
           |  |  | 957 |       });
 | 
        
           |  |  | 958 |     };
 | 
        
           |  |  | 959 |     const appendNodeContent = (editor, nodeName, previewNode, html) => {
 | 
        
           |  |  | 960 |       const newNode = Parser(editor.schema).parse(html, { context: nodeName });
 | 
        
           |  |  | 961 |       while (newNode.firstChild) {
 | 
        
           |  |  | 962 |         previewNode.append(newNode.firstChild);
 | 
        
           |  |  | 963 |       }
 | 
        
           |  |  | 964 |     };
 | 
        
           |  |  | 965 |     const createPlaceholderNode = (editor, node) => {
 | 
        
           |  |  | 966 |       const name = node.name;
 | 
        
           |  |  | 967 |       const placeHolder = new global$2('img', 1);
 | 
        
           |  |  | 968 |       retainAttributesAndInnerHtml(editor, node, placeHolder);
 | 
        
           |  |  | 969 |       setDimensions(node, placeHolder, {});
 | 
        
           |  |  | 970 |       placeHolder.attr({
 | 
        
           |  |  | 971 |         'style': node.attr('style'),
 | 
        
           |  |  | 972 |         'src': global.transparentSrc,
 | 
        
           |  |  | 973 |         'data-mce-object': name,
 | 
        
           |  |  | 974 |         'class': 'mce-object mce-object-' + name
 | 
        
           |  |  | 975 |       });
 | 
        
           |  |  | 976 |       return placeHolder;
 | 
        
           |  |  | 977 |     };
 | 
        
           |  |  | 978 |     const createPreviewNode = (editor, node) => {
 | 
        
           |  |  | 979 |       var _a;
 | 
        
           |  |  | 980 |       const name = node.name;
 | 
        
           |  |  | 981 |       const previewWrapper = new global$2('span', 1);
 | 
        
           |  |  | 982 |       previewWrapper.attr({
 | 
        
           |  |  | 983 |         'contentEditable': 'false',
 | 
        
           |  |  | 984 |         'style': node.attr('style'),
 | 
        
           |  |  | 985 |         'data-mce-object': name,
 | 
        
           |  |  | 986 |         'class': 'mce-preview-object mce-object-' + name
 | 
        
           |  |  | 987 |       });
 | 
        
           |  |  | 988 |       retainAttributesAndInnerHtml(editor, node, previewWrapper);
 | 
        
           |  |  | 989 |       const styles = editor.dom.parseStyle((_a = node.attr('style')) !== null && _a !== void 0 ? _a : '');
 | 
        
           |  |  | 990 |       const previewNode = new global$2(name, 1);
 | 
        
           |  |  | 991 |       setDimensions(node, previewNode, styles);
 | 
        
           |  |  | 992 |       previewNode.attr({
 | 
        
           |  |  | 993 |         src: node.attr('src'),
 | 
        
           |  |  | 994 |         style: node.attr('style'),
 | 
        
           |  |  | 995 |         class: node.attr('class')
 | 
        
           |  |  | 996 |       });
 | 
        
           |  |  | 997 |       if (name === 'iframe') {
 | 
        
           |  |  | 998 |         previewNode.attr({
 | 
        
           |  |  | 999 |           allowfullscreen: node.attr('allowfullscreen'),
 | 
        
           |  |  | 1000 |           frameborder: '0',
 | 
        
           | 1441 | ariadna | 1001 |           sandbox: node.attr('sandbox'),
 | 
        
           |  |  | 1002 |           referrerpolicy: node.attr('referrerpolicy')
 | 
        
           | 1 | efrain | 1003 |         });
 | 
        
           |  |  | 1004 |       } else {
 | 
        
           |  |  | 1005 |         const attrs = [
 | 
        
           |  |  | 1006 |           'controls',
 | 
        
           |  |  | 1007 |           'crossorigin',
 | 
        
           |  |  | 1008 |           'currentTime',
 | 
        
           |  |  | 1009 |           'loop',
 | 
        
           |  |  | 1010 |           'muted',
 | 
        
           |  |  | 1011 |           'poster',
 | 
        
           |  |  | 1012 |           'preload'
 | 
        
           |  |  | 1013 |         ];
 | 
        
           |  |  | 1014 |         each$1(attrs, attrName => {
 | 
        
           |  |  | 1015 |           previewNode.attr(attrName, node.attr(attrName));
 | 
        
           |  |  | 1016 |         });
 | 
        
           |  |  | 1017 |         const sanitizedHtml = previewWrapper.attr('data-mce-html');
 | 
        
           |  |  | 1018 |         if (isNonNullable(sanitizedHtml)) {
 | 
        
           |  |  | 1019 |           appendNodeContent(editor, name, previewNode, unescape(sanitizedHtml));
 | 
        
           |  |  | 1020 |         }
 | 
        
           |  |  | 1021 |       }
 | 
        
           |  |  | 1022 |       const shimNode = new global$2('span', 1);
 | 
        
           |  |  | 1023 |       shimNode.attr('class', 'mce-shim');
 | 
        
           |  |  | 1024 |       previewWrapper.append(previewNode);
 | 
        
           |  |  | 1025 |       previewWrapper.append(shimNode);
 | 
        
           |  |  | 1026 |       return previewWrapper;
 | 
        
           |  |  | 1027 |     };
 | 
        
           |  |  | 1028 |     const retainAttributesAndInnerHtml = (editor, sourceNode, targetNode) => {
 | 
        
           |  |  | 1029 |       var _a;
 | 
        
           |  |  | 1030 |       const attribs = (_a = sourceNode.attributes) !== null && _a !== void 0 ? _a : [];
 | 
        
           |  |  | 1031 |       let ai = attribs.length;
 | 
        
           |  |  | 1032 |       while (ai--) {
 | 
        
           |  |  | 1033 |         const attrName = attribs[ai].name;
 | 
        
           |  |  | 1034 |         let attrValue = attribs[ai].value;
 | 
        
           |  |  | 1035 |         if (attrName !== 'width' && attrName !== 'height' && attrName !== 'style' && !startsWith(attrName, 'data-mce-')) {
 | 
        
           |  |  | 1036 |           if (attrName === 'data' || attrName === 'src') {
 | 
        
           |  |  | 1037 |             attrValue = editor.convertURL(attrValue, attrName);
 | 
        
           |  |  | 1038 |           }
 | 
        
           |  |  | 1039 |           targetNode.attr('data-mce-p-' + attrName, attrValue);
 | 
        
           |  |  | 1040 |         }
 | 
        
           |  |  | 1041 |       }
 | 
        
           |  |  | 1042 |       const serializer = global$1({ inner: true }, editor.schema);
 | 
        
           |  |  | 1043 |       const tempNode = new global$2('div', 1);
 | 
        
           |  |  | 1044 |       each$1(sourceNode.children(), child => tempNode.append(child));
 | 
        
           |  |  | 1045 |       const innerHtml = serializer.serialize(tempNode);
 | 
        
           |  |  | 1046 |       if (innerHtml) {
 | 
        
           |  |  | 1047 |         targetNode.attr('data-mce-html', escape(innerHtml));
 | 
        
           |  |  | 1048 |         targetNode.empty();
 | 
        
           |  |  | 1049 |       }
 | 
        
           |  |  | 1050 |     };
 | 
        
           |  |  | 1051 |     const isPageEmbedWrapper = node => {
 | 
        
           |  |  | 1052 |       const nodeClass = node.attr('class');
 | 
        
           |  |  | 1053 |       return isString(nodeClass) && /\btiny-pageembed\b/.test(nodeClass);
 | 
        
           |  |  | 1054 |     };
 | 
        
           |  |  | 1055 |     const isWithinEmbedWrapper = node => {
 | 
        
           |  |  | 1056 |       let tempNode = node;
 | 
        
           |  |  | 1057 |       while (tempNode = tempNode.parent) {
 | 
        
           |  |  | 1058 |         if (tempNode.attr('data-ephox-embed-iri') || isPageEmbedWrapper(tempNode)) {
 | 
        
           |  |  | 1059 |           return true;
 | 
        
           |  |  | 1060 |         }
 | 
        
           |  |  | 1061 |       }
 | 
        
           |  |  | 1062 |       return false;
 | 
        
           |  |  | 1063 |     };
 | 
        
           |  |  | 1064 |     const placeHolderConverter = editor => nodes => {
 | 
        
           |  |  | 1065 |       let i = nodes.length;
 | 
        
           |  |  | 1066 |       let node;
 | 
        
           |  |  | 1067 |       while (i--) {
 | 
        
           |  |  | 1068 |         node = nodes[i];
 | 
        
           |  |  | 1069 |         if (!node.parent) {
 | 
        
           |  |  | 1070 |           continue;
 | 
        
           |  |  | 1071 |         }
 | 
        
           |  |  | 1072 |         if (node.parent.attr('data-mce-object')) {
 | 
        
           |  |  | 1073 |           continue;
 | 
        
           |  |  | 1074 |         }
 | 
        
           |  |  | 1075 |         if (isLiveEmbedNode(node) && hasLiveEmbeds(editor)) {
 | 
        
           |  |  | 1076 |           if (!isWithinEmbedWrapper(node)) {
 | 
        
           |  |  | 1077 |             node.replace(createPreviewNode(editor, node));
 | 
        
           |  |  | 1078 |           }
 | 
        
           |  |  | 1079 |         } else {
 | 
        
           |  |  | 1080 |           if (!isWithinEmbedWrapper(node)) {
 | 
        
           |  |  | 1081 |             node.replace(createPlaceholderNode(editor, node));
 | 
        
           |  |  | 1082 |           }
 | 
        
           |  |  | 1083 |         }
 | 
        
           |  |  | 1084 |       }
 | 
        
           |  |  | 1085 |     };
 | 
        
           |  |  | 1086 |   | 
        
           |  |  | 1087 |     const parseAndSanitize = (editor, context, html) => {
 | 
        
           |  |  | 1088 |       const getEditorOption = editor.options.get;
 | 
        
           |  |  | 1089 |       const sanitize = getEditorOption('xss_sanitization');
 | 
        
           |  |  | 1090 |       const validate = shouldFilterHtml(editor);
 | 
        
           |  |  | 1091 |       return Parser(editor.schema, {
 | 
        
           |  |  | 1092 |         sanitize,
 | 
        
           |  |  | 1093 |         validate
 | 
        
           |  |  | 1094 |       }).parse(html, { context });
 | 
        
           |  |  | 1095 |     };
 | 
        
           |  |  | 1096 |   | 
        
           |  |  | 1097 |     const setup$1 = editor => {
 | 
        
           |  |  | 1098 |       editor.on('PreInit', () => {
 | 
        
           |  |  | 1099 |         const {schema, serializer, parser} = editor;
 | 
        
           |  |  | 1100 |         const boolAttrs = schema.getBoolAttrs();
 | 
        
           |  |  | 1101 |         each$1('webkitallowfullscreen mozallowfullscreen'.split(' '), name => {
 | 
        
           |  |  | 1102 |           boolAttrs[name] = {};
 | 
        
           |  |  | 1103 |         });
 | 
        
           |  |  | 1104 |         each({ embed: ['wmode'] }, (attrs, name) => {
 | 
        
           |  |  | 1105 |           const rule = schema.getElementRule(name);
 | 
        
           |  |  | 1106 |           if (rule) {
 | 
        
           |  |  | 1107 |             each$1(attrs, attr => {
 | 
        
           |  |  | 1108 |               rule.attributes[attr] = {};
 | 
        
           |  |  | 1109 |               rule.attributesOrder.push(attr);
 | 
        
           |  |  | 1110 |             });
 | 
        
           |  |  | 1111 |           }
 | 
        
           |  |  | 1112 |         });
 | 
        
           |  |  | 1113 |         parser.addNodeFilter('iframe,video,audio,object,embed', placeHolderConverter(editor));
 | 
        
           |  |  | 1114 |         serializer.addAttributeFilter('data-mce-object', (nodes, name) => {
 | 
        
           |  |  | 1115 |           var _a;
 | 
        
           |  |  | 1116 |           let i = nodes.length;
 | 
        
           |  |  | 1117 |           while (i--) {
 | 
        
           |  |  | 1118 |             const node = nodes[i];
 | 
        
           |  |  | 1119 |             if (!node.parent) {
 | 
        
           |  |  | 1120 |               continue;
 | 
        
           |  |  | 1121 |             }
 | 
        
           |  |  | 1122 |             const realElmName = node.attr(name);
 | 
        
           |  |  | 1123 |             const realElm = new global$2(realElmName, 1);
 | 
        
           |  |  | 1124 |             if (realElmName !== 'audio') {
 | 
        
           |  |  | 1125 |               const className = node.attr('class');
 | 
        
           |  |  | 1126 |               if (className && className.indexOf('mce-preview-object') !== -1 && node.firstChild) {
 | 
        
           |  |  | 1127 |                 realElm.attr({
 | 
        
           |  |  | 1128 |                   width: node.firstChild.attr('width'),
 | 
        
           |  |  | 1129 |                   height: node.firstChild.attr('height')
 | 
        
           |  |  | 1130 |                 });
 | 
        
           |  |  | 1131 |               } else {
 | 
        
           |  |  | 1132 |                 realElm.attr({
 | 
        
           |  |  | 1133 |                   width: node.attr('width'),
 | 
        
           |  |  | 1134 |                   height: node.attr('height')
 | 
        
           |  |  | 1135 |                 });
 | 
        
           |  |  | 1136 |               }
 | 
        
           |  |  | 1137 |             }
 | 
        
           |  |  | 1138 |             realElm.attr({ style: node.attr('style') });
 | 
        
           |  |  | 1139 |             const attribs = (_a = node.attributes) !== null && _a !== void 0 ? _a : [];
 | 
        
           |  |  | 1140 |             let ai = attribs.length;
 | 
        
           |  |  | 1141 |             while (ai--) {
 | 
        
           |  |  | 1142 |               const attrName = attribs[ai].name;
 | 
        
           |  |  | 1143 |               if (attrName.indexOf('data-mce-p-') === 0) {
 | 
        
           |  |  | 1144 |                 realElm.attr(attrName.substr(11), attribs[ai].value);
 | 
        
           |  |  | 1145 |               }
 | 
        
           |  |  | 1146 |             }
 | 
        
           |  |  | 1147 |             const innerHtml = node.attr('data-mce-html');
 | 
        
           |  |  | 1148 |             if (innerHtml) {
 | 
        
           |  |  | 1149 |               const fragment = parseAndSanitize(editor, realElmName, unescape(innerHtml));
 | 
        
           |  |  | 1150 |               each$1(fragment.children(), child => realElm.append(child));
 | 
        
           |  |  | 1151 |             }
 | 
        
           |  |  | 1152 |             node.replace(realElm);
 | 
        
           |  |  | 1153 |           }
 | 
        
           |  |  | 1154 |         });
 | 
        
           |  |  | 1155 |       });
 | 
        
           |  |  | 1156 |       editor.on('SetContent', () => {
 | 
        
           |  |  | 1157 |         const dom = editor.dom;
 | 
        
           |  |  | 1158 |         each$1(dom.select('span.mce-preview-object'), elm => {
 | 
        
           |  |  | 1159 |           if (dom.select('span.mce-shim', elm).length === 0) {
 | 
        
           |  |  | 1160 |             dom.add(elm, 'span', { class: 'mce-shim' });
 | 
        
           |  |  | 1161 |           }
 | 
        
           |  |  | 1162 |         });
 | 
        
           |  |  | 1163 |       });
 | 
        
           |  |  | 1164 |     };
 | 
        
           |  |  | 1165 |   | 
        
           |  |  | 1166 |     const setup = editor => {
 | 
        
           |  |  | 1167 |       editor.on('ResolveName', e => {
 | 
        
           |  |  | 1168 |         let name;
 | 
        
           |  |  | 1169 |         if (e.target.nodeType === 1 && (name = e.target.getAttribute('data-mce-object'))) {
 | 
        
           |  |  | 1170 |           e.name = name;
 | 
        
           |  |  | 1171 |         }
 | 
        
           |  |  | 1172 |       });
 | 
        
           |  |  | 1173 |     };
 | 
        
           |  |  | 1174 |   | 
        
           |  |  | 1175 |     const onSetupEditable = editor => api => {
 | 
        
           |  |  | 1176 |       const nodeChanged = () => {
 | 
        
           |  |  | 1177 |         api.setEnabled(editor.selection.isEditable());
 | 
        
           |  |  | 1178 |       };
 | 
        
           |  |  | 1179 |       editor.on('NodeChange', nodeChanged);
 | 
        
           |  |  | 1180 |       nodeChanged();
 | 
        
           |  |  | 1181 |       return () => {
 | 
        
           |  |  | 1182 |         editor.off('NodeChange', nodeChanged);
 | 
        
           |  |  | 1183 |       };
 | 
        
           |  |  | 1184 |     };
 | 
        
           |  |  | 1185 |     const register = editor => {
 | 
        
           |  |  | 1186 |       const onAction = () => editor.execCommand('mceMedia');
 | 
        
           |  |  | 1187 |       editor.ui.registry.addToggleButton('media', {
 | 
        
           |  |  | 1188 |         tooltip: 'Insert/edit media',
 | 
        
           |  |  | 1189 |         icon: 'embed',
 | 
        
           |  |  | 1190 |         onAction,
 | 
        
           |  |  | 1191 |         onSetup: buttonApi => {
 | 
        
           |  |  | 1192 |           const selection = editor.selection;
 | 
        
           |  |  | 1193 |           buttonApi.setActive(isMediaElement(selection.getNode()));
 | 
        
           |  |  | 1194 |           const unbindSelectorChanged = selection.selectorChangedWithUnbind('img[data-mce-object],span[data-mce-object],div[data-ephox-embed-iri]', buttonApi.setActive).unbind;
 | 
        
           |  |  | 1195 |           const unbindEditable = onSetupEditable(editor)(buttonApi);
 | 
        
           |  |  | 1196 |           return () => {
 | 
        
           |  |  | 1197 |             unbindSelectorChanged();
 | 
        
           |  |  | 1198 |             unbindEditable();
 | 
        
           |  |  | 1199 |           };
 | 
        
           |  |  | 1200 |         }
 | 
        
           |  |  | 1201 |       });
 | 
        
           |  |  | 1202 |       editor.ui.registry.addMenuItem('media', {
 | 
        
           |  |  | 1203 |         icon: 'embed',
 | 
        
           |  |  | 1204 |         text: 'Media...',
 | 
        
           |  |  | 1205 |         onAction,
 | 
        
           |  |  | 1206 |         onSetup: onSetupEditable(editor)
 | 
        
           |  |  | 1207 |       });
 | 
        
           |  |  | 1208 |     };
 | 
        
           |  |  | 1209 |   | 
        
           |  |  | 1210 |     var Plugin = () => {
 | 
        
           |  |  | 1211 |       global$6.add('media', editor => {
 | 
        
           |  |  | 1212 |         register$2(editor);
 | 
        
           |  |  | 1213 |         register$1(editor);
 | 
        
           |  |  | 1214 |         register(editor);
 | 
        
           |  |  | 1215 |         setup(editor);
 | 
        
           |  |  | 1216 |         setup$1(editor);
 | 
        
           |  |  | 1217 |         setup$2(editor);
 | 
        
           |  |  | 1218 |         return get(editor);
 | 
        
           |  |  | 1219 |       });
 | 
        
           |  |  | 1220 |     };
 | 
        
           |  |  | 1221 |   | 
        
           |  |  | 1222 |     Plugin();
 | 
        
           |  |  | 1223 |   | 
        
           |  |  | 1224 | })();
 |