Fork自 GitCode / 1024程序员开源挑战赛(10.23-11.14)
/*! * Copyright (c) Tiny Technologies, Inc. All rights reserved. * Licensed under the LGPL or a commercial license. * For LGPL see License.txt in the project root for license information. * For commercial licenses see https://www.tiny.cloud/ * * Version: 5.7.0 (2021-02-10) * */ !function(t){var a={};function i(n){if(a[n])return a[n].exports;var e=a[n]={i:n,l:!1,exports:{}};return t[n].call(e.exports,e,e.exports,i),e.l=!0,e.exports}i.m=t,i.c=a,i.d=function(n,e,t){i.o(n,e)||Object.defineProperty(n,e,{configurable:!1,enumerable:!0,get:t})},i.r=function(n){Object.defineProperty(n,"__esModule",{value:!0})},i.n=function(n){var e=n&&n.__esModule?function(){return n["default"]}:function(){return n};return i.d(e,"a",e),e},i.o=function(n,e){return Object.prototype.hasOwnProperty.call(n,e)},i.p="",i(i.s="./src/js/plugins/image/plugin.js")}({"./src/js/plugins/image/plugin.js":function(module,exports){eval("/**\n * Copyright (c) Tiny Technologies, Inc. All rights reserved.\n * Licensed under the LGPL or a commercial license.\n * For LGPL see License.txt in the project root for license information.\n * For commercial licenses see https://www.tiny.cloud/\n *\n * Version: 5.7.0 (2021-02-10)\n */\n (function () {\n 'use strict';\n\n var global = tinymce.util.Tools.resolve('tinymce.PluginManager');\n\n var __assign = function () {\n __assign = Object.assign || function __assign(t) {\n for (var s, i = 1, n = arguments.length; i < n; i++) {\n s = arguments[i];\n for (var p in s)\n if (Object.prototype.hasOwnProperty.call(s, p))\n t[p] = s[p];\n }\n return t;\n };\n return __assign.apply(this, arguments);\n };\n\n var noop = function () {\n };\n var constant = function (value) {\n return function () {\n return value;\n };\n };\n var never = constant(false);\n var always = constant(true);\n\n var none = function () {\n return NONE;\n };\n var NONE = function () {\n var eq = function (o) {\n return o.isNone();\n };\n var call = function (thunk) {\n return thunk();\n };\n var id = function (n) {\n return n;\n };\n var me = {\n fold: function (n, _s) {\n return n();\n },\n is: never,\n isSome: never,\n isNone: always,\n getOr: id,\n getOrThunk: call,\n getOrDie: function (msg) {\n throw new Error(msg || 'error: getOrDie called on none.');\n },\n getOrNull: constant(null),\n getOrUndefined: constant(undefined),\n or: id,\n orThunk: call,\n map: none,\n each: noop,\n bind: none,\n exists: never,\n forall: always,\n filter: none,\n equals: eq,\n equals_: eq,\n toArray: function () {\n return [];\n },\n toString: constant('none()')\n };\n return me;\n }();\n var some = function (a) {\n var constant_a = constant(a);\n var self = function () {\n return me;\n };\n var bind = function (f) {\n return f(a);\n };\n var me = {\n fold: function (n, s) {\n return s(a);\n },\n is: function (v) {\n return a === v;\n },\n isSome: always,\n isNone: never,\n getOr: constant_a,\n getOrThunk: constant_a,\n getOrDie: constant_a,\n getOrNull: constant_a,\n getOrUndefined: constant_a,\n or: self,\n orThunk: self,\n map: function (f) {\n return some(f(a));\n },\n each: function (f) {\n f(a);\n },\n bind: bind,\n exists: bind,\n forall: bind,\n filter: function (f) {\n return f(a) ? me : NONE;\n },\n toArray: function () {\n return [a];\n },\n toString: function () {\n return 'some(' + a + ')';\n },\n equals: function (o) {\n return o.is(a);\n },\n equals_: function (o, elementEq) {\n return o.fold(never, function (b) {\n return elementEq(a, b);\n });\n }\n };\n return me;\n };\n var from = function (value) {\n return value === null || value === undefined ? NONE : some(value);\n };\n var Optional = {\n some: some,\n none: none,\n from: from\n };\n\n var keys = Object.keys;\n var hasOwnProperty = Object.hasOwnProperty;\n var each = function (obj, f) {\n var props = keys(obj);\n for (var k = 0, len = props.length; k < len; k++) {\n var i = props[k];\n var x = obj[i];\n f(x, i);\n }\n };\n var objAcc = function (r) {\n return function (x, i) {\n r[i] = x;\n };\n };\n var internalFilter = function (obj, pred, onTrue, onFalse) {\n var r = {};\n each(obj, function (x, i) {\n (pred(x, i) ? onTrue : onFalse)(x, i);\n });\n return r;\n };\n var filter = function (obj, pred) {\n var t = {};\n internalFilter(obj, pred, objAcc(t), noop);\n return t;\n };\n var has = function (obj, key) {\n return hasOwnProperty.call(obj, key);\n };\n var hasNonNullableKey = function (obj, key) {\n return has(obj, key) && obj[key] !== undefined && obj[key] !== null;\n };\n\n var typeOf = function (x) {\n var t = typeof x;\n if (x === null) {\n return 'null';\n } else if (t === 'object' && (Array.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'Array')) {\n return 'array';\n } else if (t === 'object' && (String.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'String')) {\n return 'string';\n } else {\n return t;\n }\n };\n var isType = function (type) {\n return function (value) {\n return typeOf(value) === type;\n };\n };\n var isSimpleType = function (type) {\n return function (value) {\n return typeof value === type;\n };\n };\n var eq = function (t) {\n return function (a) {\n return t === a;\n };\n };\n var isString = isType('string');\n var isObject = isType('object');\n var isArray = isType('array');\n var isNull = eq(null);\n var isBoolean = isSimpleType('boolean');\n var isNullable = function (a) {\n return a === null || a === undefined;\n };\n var isNonNullable = function (a) {\n return !isNullable(a);\n };\n var isNumber = isSimpleType('number');\n\n var nativePush = Array.prototype.push;\n var flatten = function (xs) {\n var r = [];\n for (var i = 0, len = xs.length; i < len; ++i) {\n if (!isArray(xs[i])) {\n throw new Error('Arr.flatten item ' + i + ' was not an array, input: ' + xs);\n }\n nativePush.apply(r, xs[i]);\n }\n return r;\n };\n var get = function (xs, i) {\n return i >= 0 && i < xs.length ? Optional.some(xs[i]) : Optional.none();\n };\n var head = function (xs) {\n return get(xs, 0);\n };\n var findMap = function (arr, f) {\n for (var i = 0; i < arr.length; i++) {\n var r = f(arr[i], i);\n if (r.isSome()) {\n return r;\n }\n }\n return Optional.none();\n };\n\n var Global = typeof window !== 'undefined' ? window : Function('return this;')();\n\n var rawSet = function (dom, key, value) {\n if (isString(value) || isBoolean(value) || isNumber(value)) {\n dom.setAttribute(key, value + '');\n } else {\n console.error('Invalid call to Attribute.set. Key ', key, ':: Value ', value, ':: Element ', dom);\n throw new Error('Attribute value was not simple');\n }\n };\n var set = function (element, key, value) {\n rawSet(element.dom, key, value);\n };\n var remove = function (element, key) {\n element.dom.removeAttribute(key);\n };\n\n var fromHtml = function (html, scope) {\n var doc = scope || document;\n var div = doc.createElement('div');\n div.innerHTML = html;\n if (!div.hasChildNodes() || div.childNodes.length > 1) {\n console.error('HTML does not have a single root node', html);\n throw new Error('HTML must have a single root node');\n }\n return fromDom(div.childNodes[0]);\n };\n var fromTag = function (tag, scope) {\n var doc = scope || document;\n var node = doc.createElement(tag);\n return fromDom(node);\n };\n var fromText = function (text, scope) {\n var doc = scope || document;\n var node = doc.createTextNode(text);\n return fromDom(node);\n };\n var fromDom = function (node) {\n if (node === null || node === undefined) {\n throw new Error('Node cannot be null or undefined');\n }\n return { dom: node };\n };\n var fromPoint = function (docElm, x, y) {\n return Optional.from(docElm.dom.elementFromPoint(x, y)).map(fromDom);\n };\n var SugarElement = {\n fromHtml: fromHtml,\n fromTag: fromTag,\n fromText: fromText,\n fromDom: fromDom,\n fromPoint: fromPoint\n };\n\n var global$1 = tinymce.util.Tools.resolve('tinymce.dom.DOMUtils');\n\n var global$2 = tinymce.util.Tools.resolve('tinymce.util.Promise');\n\n var global$3 = tinymce.util.Tools.resolve('tinymce.util.XHR');\n\n var hasDimensions = function (editor) {\n return editor.getParam('image_dimensions', true, 'boolean');\n };\n var hasAdvTab = function (editor) {\n return editor.getParam('image_advtab', false, 'boolean');\n };\n var hasUploadTab = function (editor) {\n return editor.getParam('image_uploadtab', true, 'boolean');\n };\n var getPrependUrl = function (editor) {\n return editor.getParam('image_prepend_url', '', 'string');\n };\n var getClassList = function (editor) {\n return editor.getParam('image_class_list');\n };\n var hasDescription = function (editor) {\n return editor.getParam('image_description', true, 'boolean');\n };\n var hasImageTitle = function (editor) {\n return editor.getParam('image_title', false, 'boolean');\n };\n var hasImageCaption = function (editor) {\n return editor.getParam('image_caption', false, 'boolean');\n };\n var getImageList = function (editor) {\n return editor.getParam('image_list', false);\n };\n var hasUploadUrl = function (editor) {\n return isNonNullable(editor.getParam('images_upload_url'));\n };\n var hasUploadHandler = function (editor) {\n return isNonNullable(editor.getParam('images_upload_handler'));\n };\n var showAccessibilityOptions = function (editor) {\n return editor.getParam('a11y_advanced_options', false, 'boolean');\n };\n var isAutomaticUploadsEnabled = function (editor) {\n return editor.getParam('automatic_uploads', true, 'boolean');\n };\n\n var parseIntAndGetMax = function (val1, val2) {\n return Math.max(parseInt(val1, 10), parseInt(val2, 10));\n };\n var getImageSize = function (url) {\n return new global$2(function (callback) {\n var img = document.createElement('img');\n var done = function (dimensions) {\n if (img.parentNode) {\n img.parentNode.removeChild(img);\n }\n callback(dimensions);\n };\n img.onload = function () {\n var width = parseIntAndGetMax(img.width, img.clientWidth);\n var height = parseIntAndGetMax(img.height, img.clientHeight);\n var dimensions = {\n width: width,\n height: height\n };\n done(global$2.resolve(dimensions));\n };\n img.onerror = function () {\n done(global$2.reject('Failed to get image dimensions for: ' + url));\n };\n var style = img.style;\n style.visibility = 'hidden';\n style.position = 'fixed';\n style.bottom = style.left = '0px';\n style.width = style.height = 'auto';\n document.body.appendChild(img);\n img.src = url;\n });\n };\n var removePixelSuffix = function (value) {\n if (value) {\n value = value.replace(/px$/, '');\n }\n return value;\n };\n var addPixelSuffix = function (value) {\n if (value.length > 0 && /^[0-9]+$/.test(value)) {\n value += 'px';\n }\n return value;\n };\n var mergeMargins = function (css) {\n if (css.margin) {\n var splitMargin = String(css.margin).split(' ');\n switch (splitMargin.length) {\n case 1:\n css['margin-top'] = css['margin-top'] || splitMargin[0];\n css['margin-right'] = css['margin-right'] || splitMargin[0];\n css['margin-bottom'] = css['margin-bottom'] || splitMargin[0];\n css['margin-left'] = css['margin-left'] || splitMargin[0];\n break;\n case 2:\n css['margin-top'] = css['margin-top'] || splitMargin[0];\n css['margin-right'] = css['margin-right'] || splitMargin[1];\n css['margin-bottom'] = css['margin-bottom'] || splitMargin[0];\n css['margin-left'] = css['margin-left'] || splitMargin[1];\n break;\n case 3:\n css['margin-top'] = css['margin-top'] || splitMargin[0];\n css['margin-right'] = css['margin-right'] || splitMargin[1];\n css['margin-bottom'] = css['margin-bottom'] || splitMargin[2];\n css['margin-left'] = css['margin-left'] || splitMargin[1];\n break;\n case 4:\n css['margin-top'] = css['margin-top'] || splitMargin[0];\n css['margin-right'] = css['margin-right'] || splitMargin[1];\n css['margin-bottom'] = css['margin-bottom'] || splitMargin[2];\n css['margin-left'] = css['margin-left'] || splitMargin[3];\n }\n delete css.margin;\n }\n return css;\n };\n var createImageList = function (editor, callback) {\n var imageList = getImageList(editor);\n if (typeof imageList === 'string') {\n global$3.send({\n url: imageList,\n success: function (text) {\n callback(JSON.parse(text));\n }\n });\n } else if (typeof imageList === 'function') {\n imageList(callback);\n } else {\n callback(imageList);\n }\n };\n var waitLoadImage = function (editor, data, imgElm) {\n var selectImage = function () {\n imgElm.onload = imgElm.onerror = null;\n if (editor.selection) {\n editor.selection.select(imgElm);\n editor.nodeChanged();\n }\n };\n imgElm.onload = function () {\n if (!data.width && !data.height && hasDimensions(editor)) {\n editor.dom.setAttribs(imgElm, {\n width: String(imgElm.clientWidth),\n height: String(imgElm.clientHeight)\n });\n }\n selectImage();\n };\n imgElm.onerror = selectImage;\n };\n var blobToDataUri = function (blob) {\n return new global$2(function (resolve, reject) {\n var reader = new FileReader();\n reader.onload = function () {\n resolve(reader.result);\n };\n reader.onerror = function () {\n reject(reader.error.message);\n };\n reader.readAsDataURL(blob);\n });\n };\n var isPlaceholderImage = function (imgElm) {\n return imgElm.nodeName === 'IMG' && (imgElm.hasAttribute('data-mce-object') || imgElm.hasAttribute('data-mce-placeholder'));\n };\n\n var DOM = global$1.DOM;\n var getHspace = function (image) {\n if (image.style.marginLeft && image.style.marginRight && image.style.marginLeft === image.style.marginRight) {\n return removePixelSuffix(image.style.marginLeft);\n } else {\n return '';\n }\n };\n var getVspace = function (image) {\n if (image.style.marginTop && image.style.marginBottom && image.style.marginTop === image.style.marginBottom) {\n return removePixelSuffix(image.style.marginTop);\n } else {\n return '';\n }\n };\n var getBorder = function (image) {\n if (image.style.borderWidth) {\n return removePixelSuffix(image.style.borderWidth);\n } else {\n return '';\n }\n };\n var getAttrib = function (image, name) {\n if (image.hasAttribute(name)) {\n return image.getAttribute(name);\n } else {\n return '';\n }\n };\n var getStyle = function (image, name) {\n return image.style[name] ? image.style[name] : '';\n };\n var hasCaption = function (image) {\n return image.parentNode !== null && image.parentNode.nodeName === 'FIGURE';\n };\n var updateAttrib = function (image, name, value) {\n if (value === '') {\n image.removeAttribute(name);\n } else {\n image.setAttribute(name, value);\n }\n };\n var wrapInFigure = function (image) {\n var figureElm = DOM.create('figure', { class: 'image' });\n DOM.insertAfter(figureElm, image);\n figureElm.appendChild(image);\n figureElm.appendChild(DOM.create('figcaption', { contentEditable: 'true' }, 'Caption'));\n figureElm.contentEditable = 'false';\n };\n var removeFigure = function (image) {\n var figureElm = image.parentNode;\n DOM.insertAfter(image, figureElm);\n DOM.remove(figureElm);\n };\n var toggleCaption = function (image) {\n if (hasCaption(image)) {\n removeFigure(image);\n } else {\n wrapInFigure(image);\n }\n };\n var normalizeStyle = function (image, normalizeCss) {\n var attrValue = image.getAttribute('style');\n var value = normalizeCss(attrValue !== null ? attrValue : '');\n if (value.length > 0) {\n image.setAttribute('style', value);\n image.setAttribute('data-mce-style', value);\n } else {\n image.removeAttribute('style');\n }\n };\n var setSize = function (name, normalizeCss) {\n return function (image, name, value) {\n if (image.style[name]) {\n image.style[name] = addPixelSuffix(value);\n normalizeStyle(image, normalizeCss);\n } else {\n updateAttrib(image, name, value);\n }\n };\n };\n var getSize = function (image, name) {\n if (image.style[name]) {\n return removePixelSuffix(image.style[name]);\n } else {\n return getAttrib(image, name);\n }\n };\n var setHspace = function (image, value) {\n var pxValue = addPixelSuffix(value);\n image.style.marginLeft = pxValue;\n image.style.marginRight = pxValue;\n };\n var setVspace = function (image, value) {\n var pxValue = addPixelSuffix(value);\n image.style.marginTop = pxValue;\n image.style.marginBottom = pxValue;\n };\n var setBorder = function (image, value) {\n var pxValue = addPixelSuffix(value);\n image.style.borderWidth = pxValue;\n };\n var setBorderStyle = function (image, value) {\n image.style.borderStyle = value;\n };\n var getBorderStyle = function (image) {\n return getStyle(image, 'borderStyle');\n };\n var isFigure = function (elm) {\n return elm.nodeName === 'FIGURE';\n };\n var isImage = function (elm) {\n return elm.nodeName === 'IMG';\n };\n var getIsDecorative = function (image) {\n return DOM.getAttrib(image, 'alt').length === 0 && DOM.getAttrib(image, 'role') === 'presentation';\n };\n var getAlt = function (image) {\n if (getIsDecorative(image)) {\n return '';\n } else {\n return getAttrib(image, 'alt');\n }\n };\n var defaultData = function () {\n return {\n src: '',\n alt: '',\n title: '',\n width: '',\n height: '',\n class: '',\n style: '',\n caption: false,\n hspace: '',\n vspace: '',\n border: '',\n borderStyle: '',\n isDecorative: false\n };\n };\n var getStyleValue = function (normalizeCss, data) {\n var image = document.createElement('img');\n updateAttrib(image, 'style', data.style);\n if (getHspace(image) || data.hspace !== '') {\n setHspace(image, data.hspace);\n }\n if (getVspace(image) || data.vspace !== '') {\n setVspace(image, data.vspace);\n }\n if (getBorder(image) || data.border !== '') {\n setBorder(image, data.border);\n }\n if (getBorderStyle(image) || data.borderStyle !== '') {\n setBorderStyle(image, data.borderStyle);\n }\n return normalizeCss(image.getAttribute('style'));\n };\n var create = function (normalizeCss, data) {\n var image = document.createElement('img');\n write(normalizeCss, __assign(__assign({}, data), { caption: false }), image);\n setAlt(image, data.alt, data.isDecorative);\n if (data.caption) {\n var figure = DOM.create('figure', { class: 'image' });\n figure.appendChild(image);\n figure.appendChild(DOM.create('figcaption', { contentEditable: 'true' }, 'Caption'));\n figure.contentEditable = 'false';\n return figure;\n } else {\n return image;\n }\n };\n var read = function (normalizeCss, image) {\n return {\n src: getAttrib(image, 'src'),\n alt: getAlt(image),\n title: getAttrib(image, 'title'),\n width: getSize(image, 'width'),\n height: getSize(image, 'height'),\n class: getAttrib(image, 'class'),\n style: normalizeCss(getAttrib(image, 'style')),\n caption: hasCaption(image),\n hspace: getHspace(image),\n vspace: getVspace(image),\n border: getBorder(image),\n borderStyle: getStyle(image, 'borderStyle'),\n isDecorative: getIsDecorative(image)\n };\n };\n var updateProp = function (image, oldData, newData, name, set) {\n if (newData[name] !== oldData[name]) {\n set(image, name, newData[name]);\n }\n };\n var setAlt = function (image, alt, isDecorative) {\n if (isDecorative) {\n DOM.setAttrib(image, 'role', 'presentation');\n var sugarImage = SugarElement.fromDom(image);\n set(sugarImage, 'alt', '');\n } else {\n if (isNull(alt)) {\n var sugarImage = SugarElement.fromDom(image);\n remove(sugarImage, 'alt');\n } else {\n var sugarImage = SugarElement.fromDom(image);\n set(sugarImage, 'alt', alt);\n }\n if (DOM.getAttrib(image, 'role') === 'presentation') {\n DOM.setAttrib(image, 'role', '');\n }\n }\n };\n var updateAlt = function (image, oldData, newData) {\n if (newData.alt !== oldData.alt || newData.isDecorative !== oldData.isDecorative) {\n setAlt(image, newData.alt, newData.isDecorative);\n }\n };\n var normalized = function (set, normalizeCss) {\n return function (image, name, value) {\n set(image, value);\n normalizeStyle(image, normalizeCss);\n };\n };\n var write = function (normalizeCss, newData, image) {\n var oldData = read(normalizeCss, image);\n updateProp(image, oldData, newData, 'caption', function (image, _name, _value) {\n return toggleCaption(image);\n });\n updateProp(image, oldData, newData, 'src', updateAttrib);\n updateProp(image, oldData, newData, 'title', updateAttrib);\n updateProp(image, oldData, newData, 'width', setSize('width', normalizeCss));\n updateProp(image, oldData, newData, 'height', setSize('height', normalizeCss));\n updateProp(image, oldData, newData, 'class', updateAttrib);\n updateProp(image, oldData, newData, 'style', normalized(function (image, value) {\n return updateAttrib(image, 'style', value);\n }, normalizeCss));\n updateProp(image, oldData, newData, 'hspace', normalized(setHspace, normalizeCss));\n updateProp(image, oldData, newData, 'vspace', normalized(setVspace, normalizeCss));\n updateProp(image, oldData, newData, 'border', normalized(setBorder, normalizeCss));\n updateProp(image, oldData, newData, 'borderStyle', normalized(setBorderStyle, normalizeCss));\n updateAlt(image, oldData, newData);\n };\n\n var normalizeCss = function (editor, cssText) {\n var css = editor.dom.styles.parse(cssText);\n var mergedCss = mergeMargins(css);\n var compressed = editor.dom.styles.parse(editor.dom.styles.serialize(mergedCss));\n return editor.dom.styles.serialize(compressed);\n };\n var getSelectedImage = function (editor) {\n var imgElm = editor.selection.getNode();\n var figureElm = editor.dom.getParent(imgElm, 'figure.image');\n if (figureElm) {\n return editor.dom.select('img', figureElm)[0];\n }\n if (imgElm && (imgElm.nodeName !== 'IMG' || isPlaceholderImage(imgElm))) {\n return null;\n }\n return imgElm;\n };\n var splitTextBlock = function (editor, figure) {\n var dom = editor.dom;\n var textBlockElements = filter(editor.schema.getTextBlockElements(), function (_, parentElm) {\n return !editor.schema.isValidChild(parentElm, 'figure');\n });\n var textBlock = dom.getParent(figure.parentNode, function (node) {\n return hasNonNullableKey(textBlockElements, node.nodeName);\n }, editor.getBody());\n if (textBlock) {\n return dom.split(textBlock, figure);\n } else {\n return figure;\n }\n };\n var readImageDataFromSelection = function (editor) {\n var image = getSelectedImage(editor);\n return image ? read(function (css) {\n return normalizeCss(editor, css);\n }, image) : defaultData();\n };\n var insertImageAtCaret = function (editor, data) {\n var elm = create(function (css) {\n return normalizeCss(editor, css);\n }, data);\n editor.dom.setAttrib(elm, 'data-mce-id', '__mcenew');\n editor.focus();\n editor.selection.setContent(elm.outerHTML);\n var insertedElm = editor.dom.select('*[data-mce-id=\"__mcenew\"]')[0];\n editor.dom.setAttrib(insertedElm, 'data-mce-id', null);\n if (isFigure(insertedElm)) {\n var figure = splitTextBlock(editor, insertedElm);\n editor.selection.select(figure);\n } else {\n editor.selection.select(insertedElm);\n }\n };\n var syncSrcAttr = function (editor, image) {\n editor.dom.setAttrib(image, 'src', image.getAttribute('src'));\n };\n var deleteImage = function (editor, image) {\n if (image) {\n var elm = editor.dom.is(image.parentNode, 'figure.image') ? image.parentNode : image;\n editor.dom.remove(elm);\n editor.focus();\n editor.nodeChanged();\n if (editor.dom.isEmpty(editor.getBody())) {\n editor.setContent('');\n editor.selection.setCursorLocation();\n }\n }\n };\n var writeImageDataToSelection = function (editor, data) {\n var image = getSelectedImage(editor);\n write(function (css) {\n return normalizeCss(editor, css);\n }, data, image);\n syncSrcAttr(editor, image);\n if (isFigure(image.parentNode)) {\n var figure = image.parentNode;\n splitTextBlock(editor, figure);\n editor.selection.select(image.parentNode);\n } else {\n editor.selection.select(image);\n waitLoadImage(editor, data, image);\n }\n };\n var insertOrUpdateImage = function (editor, partialData) {\n var image = getSelectedImage(editor);\n if (image) {\n var selectedImageData = read(function (css) {\n return normalizeCss(editor, css);\n }, image);\n var data = __assign(__assign({}, selectedImageData), partialData);\n if (data.src) {\n writeImageDataToSelection(editor, data);\n } else {\n deleteImage(editor, image);\n }\n } else if (partialData.src) {\n insertImageAtCaret(editor, __assign(__assign({}, defaultData()), partialData));\n }\n };\n\n var hasOwnProperty$1 = Object.prototype.hasOwnProperty;\n var deep = function (old, nu) {\n var bothObjects = isObject(old) && isObject(nu);\n return bothObjects ? deepMerge(old, nu) : nu;\n };\n var baseMerge = function (merger) {\n return function () {\n var objects = [];\n for (var _i = 0; _i < arguments.length; _i++) {\n objects[_i] = arguments[_i];\n }\n if (objects.length === 0) {\n throw new Error('Can\\'t merge zero objects');\n }\n var ret = {};\n for (var j = 0; j < objects.length; j++) {\n var curObject = objects[j];\n for (var key in curObject) {\n if (hasOwnProperty$1.call(curObject, key)) {\n ret[key] = merger(ret[key], curObject[key]);\n }\n }\n }\n return ret;\n };\n };\n var deepMerge = baseMerge(deep);\n\n var isNotEmpty = function (s) {\n return s.length > 0;\n };\n\n var global$4 = tinymce.util.Tools.resolve('tinymce.util.ImageUploader');\n\n var global$5 = tinymce.util.Tools.resolve('tinymce.util.Tools');\n\n var getValue = function (item) {\n return isString(item.value) ? item.value : '';\n };\n var getText = function (item) {\n if (isString(item.text)) {\n return item.text;\n } else if (isString(item.title)) {\n return item.title;\n } else {\n return '';\n }\n };\n var sanitizeList = function (list, extractValue) {\n var out = [];\n global$5.each(list, function (item) {\n var text = getText(item);\n if (item.menu !== undefined) {\n var items = sanitizeList(item.menu, extractValue);\n out.push({\n text: text,\n items: items\n });\n } else {\n var value = extractValue(item);\n out.push({\n text: text,\n value: value\n });\n }\n });\n return out;\n };\n var sanitizer = function (extracter) {\n if (extracter === void 0) {\n extracter = getValue;\n }\n return function (list) {\n if (list) {\n return Optional.from(list).map(function (list) {\n return sanitizeList(list, extracter);\n });\n } else {\n return Optional.none();\n }\n };\n };\n var sanitize = function (list) {\n return sanitizer(getValue)(list);\n };\n var isGroup = function (item) {\n return Object.prototype.hasOwnProperty.call(item, 'items');\n };\n var findEntryDelegate = function (list, value) {\n return findMap(list, function (item) {\n if (isGroup(item)) {\n return findEntryDelegate(item.items, value);\n } else if (item.value === value) {\n return Optional.some(item);\n } else {\n return Optional.none();\n }\n });\n };\n var findEntry = function (optList, value) {\n return optList.bind(function (list) {\n return findEntryDelegate(list, value);\n });\n };\n var ListUtils = {\n sanitizer: sanitizer,\n sanitize: sanitize,\n findEntry: findEntry\n };\n\n var makeTab = function (_info) {\n return {\n title: 'Advanced',\n name: 'advanced',\n items: [\n {\n type: 'input',\n label: 'Style',\n name: 'style'\n },\n {\n type: 'grid',\n columns: 2,\n items: [\n {\n type: 'input',\n label: 'Vertical space',\n name: 'vspace',\n inputMode: 'numeric'\n },\n {\n type: 'input',\n label: 'Horizontal space',\n name: 'hspace',\n inputMode: 'numeric'\n },\n {\n type: 'input',\n label: 'Border width',\n name: 'border',\n inputMode: 'numeric'\n },\n {\n type: 'listbox',\n name: 'borderstyle',\n label: 'Border style',\n items: [\n {\n text: 'Select...',\n value: ''\n },\n {\n text: 'Solid',\n value: 'solid'\n },\n {\n text: 'Dotted',\n value: 'dotted'\n },\n {\n text: 'Dashed',\n value: 'dashed'\n },\n {\n text: 'Double',\n value: 'double'\n },\n {\n text: 'Groove',\n value: 'groove'\n },\n {\n text: 'Ridge',\n value: 'ridge'\n },\n {\n text: 'Inset',\n value: 'inset'\n },\n {\n text: 'Outset',\n value: 'outset'\n },\n {\n text: 'None',\n value: 'none'\n },\n {\n text: 'Hidden',\n value: 'hidden'\n }\n ]\n }\n ]\n }\n ]\n };\n };\n var AdvTab = { makeTab: makeTab };\n\n var collect = function (editor) {\n var urlListSanitizer = ListUtils.sanitizer(function (item) {\n return editor.convertURL(item.value || item.url, 'src');\n });\n var futureImageList = new global$2(function (completer) {\n createImageList(editor, function (imageList) {\n completer(urlListSanitizer(imageList).map(function (items) {\n return flatten([\n [{\n text: 'None',\n value: ''\n }],\n items\n ]);\n }));\n });\n });\n var classList = ListUtils.sanitize(getClassList(editor));\n var hasAdvTab$1 = hasAdvTab(editor);\n var hasUploadTab$1 = hasUploadTab(editor);\n var hasUploadUrl$1 = hasUploadUrl(editor);\n var hasUploadHandler$1 = hasUploadHandler(editor);\n var image = readImageDataFromSelection(editor);\n var hasDescription$1 = hasDescription(editor);\n var hasImageTitle$1 = hasImageTitle(editor);\n var hasDimensions$1 = hasDimensions(editor);\n var hasImageCaption$1 = hasImageCaption(editor);\n var hasAccessibilityOptions = showAccessibilityOptions(editor);\n var automaticUploads = isAutomaticUploadsEnabled(editor);\n var prependURL = Optional.some(getPrependUrl(editor)).filter(function (preUrl) {\n return isString(preUrl) && preUrl.length > 0;\n });\n return futureImageList.then(function (imageList) {\n return {\n image: image,\n imageList: imageList,\n classList: classList,\n hasAdvTab: hasAdvTab$1,\n hasUploadTab: hasUploadTab$1,\n hasUploadUrl: hasUploadUrl$1,\n hasUploadHandler: hasUploadHandler$1,\n hasDescription: hasDescription$1,\n hasImageTitle: hasImageTitle$1,\n hasDimensions: hasDimensions$1,\n hasImageCaption: hasImageCaption$1,\n prependURL: prependURL,\n hasAccessibilityOptions: hasAccessibilityOptions,\n automaticUploads: automaticUploads\n };\n });\n };\n\n var makeItems = function (info) {\n var imageUrl = {\n name: 'src',\n type: 'urlinput',\n filetype: 'image',\n label: 'Source'\n };\n var imageList = info.imageList.map(function (items) {\n return {\n name: 'images',\n type: 'listbox',\n label: 'Image list',\n items: items\n };\n });\n var imageDescription = {\n name: 'alt',\n type: 'input',\n label: 'Alternative description',\n disabled: info.hasAccessibilityOptions && info.image.isDecorative\n };\n var imageTitle = {\n name: 'title',\n type: 'input',\n label: 'Image title'\n };\n var imageDimensions = {\n name: 'dimensions',\n type: 'sizeinput'\n };\n var isDecorative = {\n type: 'label',\n label: 'Accessibility',\n items: [{\n name: 'isDecorative',\n type: 'checkbox',\n label: 'Image is decorative'\n }]\n };\n var classList = info.classList.map(function (items) {\n return {\n name: 'classes',\n type: 'listbox',\n label: 'Class',\n items: items\n };\n });\n var caption = {\n type: 'label',\n label: 'Caption',\n items: [{\n type: 'checkbox',\n name: 'caption',\n label: 'Show caption'\n }]\n };\n return flatten([\n [imageUrl],\n imageList.toArray(),\n info.hasAccessibilityOptions && info.hasDescription ? [isDecorative] : [],\n info.hasDescription ? [imageDescription] : [],\n info.hasImageTitle ? [imageTitle] : [],\n info.hasDimensions ? [imageDimensions] : [],\n [{\n type: 'grid',\n columns: 2,\n items: flatten([\n classList.toArray(),\n info.hasImageCaption ? [caption] : []\n ])\n }]\n ]);\n };\n var makeTab$1 = function (info) {\n return {\n title: 'General',\n name: 'general',\n items: makeItems(info)\n };\n };\n var MainTab = {\n makeTab: makeTab$1,\n makeItems: makeItems\n };\n\n var makeTab$2 = function (_info) {\n var items = [{\n type: 'dropzone',\n name: 'fileinput'\n }];\n return {\n title: 'Upload',\n name: 'upload',\n items: items\n };\n };\n var UploadTab = { makeTab: makeTab$2 };\n\n var createState = function (info) {\n return {\n prevImage: ListUtils.findEntry(info.imageList, info.image.src),\n prevAlt: info.image.alt,\n open: true\n };\n };\n var fromImageData = function (image) {\n return {\n src: {\n value: image.src,\n meta: {}\n },\n images: image.src,\n alt: image.alt,\n title: image.title,\n dimensions: {\n width: image.width,\n height: image.height\n },\n classes: image.class,\n caption: image.caption,\n style: image.style,\n vspace: image.vspace,\n border: image.border,\n hspace: image.hspace,\n borderstyle: image.borderStyle,\n fileinput: [],\n isDecorative: image.isDecorative\n };\n };\n var toImageData = function (data, removeEmptyAlt) {\n return {\n src: data.src.value,\n alt: data.alt.length === 0 && removeEmptyAlt ? null : data.alt,\n title: data.title,\n width: data.dimensions.width,\n height: data.dimensions.height,\n class: data.classes,\n style: data.style,\n caption: data.caption,\n hspace: data.hspace,\n vspace: data.vspace,\n border: data.border,\n borderStyle: data.borderstyle,\n isDecorative: data.isDecorative\n };\n };\n var addPrependUrl2 = function (info, srcURL) {\n if (!/^(?:[a-zA-Z]+:)?\\/\\//.test(srcURL)) {\n return info.prependURL.bind(function (prependUrl) {\n if (srcURL.substring(0, prependUrl.length) !== prependUrl) {\n return Optional.some(prependUrl + srcURL);\n }\n return Optional.none();\n });\n }\n return Optional.none();\n };\n var addPrependUrl = function (info, api) {\n var data = api.getData();\n addPrependUrl2(info, data.src.value).each(function (srcURL) {\n api.setData({\n src: {\n value: srcURL,\n meta: data.src.meta\n }\n });\n });\n };\n var formFillFromMeta2 = function (info, data, meta) {\n if (info.hasDescription && isString(meta.alt)) {\n data.alt = meta.alt;\n }\n if (info.hasAccessibilityOptions) {\n data.isDecorative = meta.isDecorative || data.isDecorative || false;\n }\n if (info.hasImageTitle && isString(meta.title)) {\n data.title = meta.title;\n }\n if (info.hasDimensions) {\n if (isString(meta.width)) {\n data.dimensions.width = meta.width;\n }\n if (isString(meta.height)) {\n data.dimensions.height = meta.height;\n }\n }\n if (isString(meta.class)) {\n ListUtils.findEntry(info.classList, meta.class).each(function (entry) {\n data.classes = entry.value;\n });\n }\n if (info.hasImageCaption) {\n if (isBoolean(meta.caption)) {\n data.caption = meta.caption;\n }\n }\n if (info.hasAdvTab) {\n if (isString(meta.style)) {\n data.style = meta.style;\n }\n if (isString(meta.vspace)) {\n data.vspace = meta.vspace;\n }\n if (isString(meta.border)) {\n data.border = meta.border;\n }\n if (isString(meta.hspace)) {\n data.hspace = meta.hspace;\n }\n if (isString(meta.borderstyle)) {\n data.borderstyle = meta.borderstyle;\n }\n }\n };\n var formFillFromMeta = function (info, api) {\n var data = api.getData();\n var meta = data.src.meta;\n if (meta !== undefined) {\n var newData = deepMerge({}, data);\n formFillFromMeta2(info, newData, meta);\n api.setData(newData);\n }\n };\n var calculateImageSize = function (helpers, info, state, api) {\n var data = api.getData();\n var url = data.src.value;\n var meta = data.src.meta || {};\n if (!meta.width && !meta.height && info.hasDimensions) {\n if (isNotEmpty(url)) {\n helpers.imageSize(url).then(function (size) {\n if (state.open) {\n api.setData({ dimensions: size });\n }\n }).catch(function (e) {\n return console.error(e);\n });\n } else {\n api.setData({\n dimensions: {\n width: '',\n height: ''\n }\n });\n }\n }\n };\n var updateImagesDropdown = function (info, state, api) {\n var data = api.getData();\n var image = ListUtils.findEntry(info.imageList, data.src.value);\n state.prevImage = image;\n api.setData({\n images: image.map(function (entry) {\n return entry.value;\n }).getOr('')\n });\n };\n var changeSrc = function (helpers, info, state, api) {\n addPrependUrl(info, api);\n formFillFromMeta(info, api);\n calculateImageSize(helpers, info, state, api);\n updateImagesDropdown(info, state, api);\n };\n var changeImages = function (helpers, info, state, api) {\n var data = api.getData();\n var image = ListUtils.findEntry(info.imageList, data.images);\n image.each(function (img) {\n var updateAlt = data.alt === '' || state.prevImage.map(function (image) {\n return image.text === data.alt;\n }).getOr(false);\n if (updateAlt) {\n if (img.value === '') {\n api.setData({\n src: img,\n alt: state.prevAlt\n });\n } else {\n api.setData({\n src: img,\n alt: img.text\n });\n }\n } else {\n api.setData({ src: img });\n }\n });\n state.prevImage = image;\n changeSrc(helpers, info, state, api);\n };\n var calcVSpace = function (css) {\n var matchingTopBottom = css['margin-top'] && css['margin-bottom'] && css['margin-top'] === css['margin-bottom'];\n return matchingTopBottom ? removePixelSuffix(String(css['margin-top'])) : '';\n };\n var calcHSpace = function (css) {\n var matchingLeftRight = css['margin-right'] && css['margin-left'] && css['margin-right'] === css['margin-left'];\n return matchingLeftRight ? removePixelSuffix(String(css['margin-right'])) : '';\n };\n var calcBorderWidth = function (css) {\n return css['border-width'] ? removePixelSuffix(String(css['border-width'])) : '';\n };\n var calcBorderStyle = function (css) {\n return css['border-style'] ? String(css['border-style']) : '';\n };\n var calcStyle = function (parseStyle, serializeStyle, css) {\n return serializeStyle(parseStyle(serializeStyle(css)));\n };\n var changeStyle2 = function (parseStyle, serializeStyle, data) {\n var css = mergeMargins(parseStyle(data.style));\n var dataCopy = deepMerge({}, data);\n dataCopy.vspace = calcVSpace(css);\n dataCopy.hspace = calcHSpace(css);\n dataCopy.border = calcBorderWidth(css);\n dataCopy.borderstyle = calcBorderStyle(css);\n dataCopy.style = calcStyle(parseStyle, serializeStyle, css);\n return dataCopy;\n };\n var changeStyle = function (helpers, api) {\n var data = api.getData();\n var newData = changeStyle2(helpers.parseStyle, helpers.serializeStyle, data);\n api.setData(newData);\n };\n var changeAStyle = function (helpers, info, api) {\n var data = deepMerge(fromImageData(info.image), api.getData());\n var style = getStyleValue(helpers.normalizeCss, toImageData(data, false));\n api.setData({ style: style });\n };\n var changeFileInput = function (helpers, info, state, api) {\n var data = api.getData();\n api.block('Uploading image');\n head(data.fileinput).fold(function () {\n api.unblock();\n }, function (file) {\n var blobUri = URL.createObjectURL(file);\n var finalize = function () {\n api.unblock();\n URL.revokeObjectURL(blobUri);\n };\n var updateSrcAndSwitchTab = function (url) {\n api.setData({\n src: {\n value: url,\n meta: {}\n }\n });\n api.showTab('general');\n changeSrc(helpers, info, state, api);\n };\n blobToDataUri(file).then(function (dataUrl) {\n var blobInfo = helpers.createBlobCache(file, blobUri, dataUrl);\n if (info.automaticUploads) {\n helpers.uploadImage(blobInfo).then(function (result) {\n updateSrcAndSwitchTab(result.url);\n finalize();\n }).catch(function (err) {\n finalize();\n helpers.alertErr(err);\n });\n } else {\n helpers.addToBlobCache(blobInfo);\n updateSrcAndSwitchTab(blobInfo.blobUri());\n api.unblock();\n }\n });\n });\n };\n var changeHandler = function (helpers, info, state) {\n return function (api, evt) {\n if (evt.name === 'src') {\n changeSrc(helpers, info, state, api);\n } else if (evt.name === 'images') {\n changeImages(helpers, info, state, api);\n } else if (evt.name === 'alt') {\n state.prevAlt = api.getData().alt;\n } else if (evt.name === 'style') {\n changeStyle(helpers, api);\n } else if (evt.name === 'vspace' || evt.name === 'hspace' || evt.name === 'border' || evt.name === 'borderstyle') {\n changeAStyle(helpers, info, api);\n } else if (evt.name === 'fileinput') {\n changeFileInput(helpers, info, state, api);\n } else if (evt.name === 'isDecorative') {\n if (api.getData().isDecorative) {\n api.disable('alt');\n } else {\n api.enable('alt');\n }\n }\n };\n };\n var closeHandler = function (state) {\n return function () {\n state.open = false;\n };\n };\n var makeDialogBody = function (info) {\n if (info.hasAdvTab || info.hasUploadUrl || info.hasUploadHandler) {\n var tabPanel = {\n type: 'tabpanel',\n tabs: flatten([\n [MainTab.makeTab(info)],\n info.hasAdvTab ? [AdvTab.makeTab(info)] : [],\n info.hasUploadTab && (info.hasUploadUrl || info.hasUploadHandler) ? [UploadTab.makeTab(info)] : []\n ])\n };\n return tabPanel;\n } else {\n var panel = {\n type: 'panel',\n items: MainTab.makeItems(info)\n };\n return panel;\n }\n };\n var makeDialog = function (helpers) {\n return function (info) {\n var state = createState(info);\n return {\n title: 'Insert/Edit Image',\n size: 'normal',\n body: makeDialogBody(info),\n buttons: [\n {\n type: 'cancel',\n name: 'cancel',\n text: 'Cancel'\n },\n {\n type: 'submit',\n name: 'save',\n text: 'Save',\n primary: true\n }\n ],\n initialData: fromImageData(info.image),\n onSubmit: helpers.onSubmit(info),\n onChange: changeHandler(helpers, info, state),\n onClose: closeHandler(state)\n };\n };\n };\n var submitHandler = function (editor) {\n return function (info) {\n return function (api) {\n var data = deepMerge(fromImageData(info.image), api.getData());\n editor.execCommand('mceUpdateImage', false, toImageData(data, info.hasAccessibilityOptions));\n editor.editorUpload.uploadImagesAuto();\n api.close();\n };\n };\n };\n var imageSize = function (editor) {\n return function (url) {\n return getImageSize(editor.documentBaseURI.toAbsolute(url)).then(function (dimensions) {\n return {\n width: String(dimensions.width),\n height: String(dimensions.height)\n };\n });\n };\n };\n var createBlobCache = function (editor) {\n return function (file, blobUri, dataUrl) {\n return editor.editorUpload.blobCache.create({\n blob: file,\n blobUri: blobUri,\n name: file.name ? file.name.replace(/\\.[^\\.]+$/, '') : null,\n filename: file.name,\n base64: dataUrl.split(',')[1]\n });\n };\n };\n var addToBlobCache = function (editor) {\n return function (blobInfo) {\n editor.editorUpload.blobCache.add(blobInfo);\n };\n };\n var alertErr = function (editor) {\n return function (message) {\n editor.windowManager.alert(message);\n };\n };\n var normalizeCss$1 = function (editor) {\n return function (cssText) {\n return normalizeCss(editor, cssText);\n };\n };\n var parseStyle = function (editor) {\n return function (cssText) {\n return editor.dom.parseStyle(cssText);\n };\n };\n var serializeStyle = function (editor) {\n return function (stylesArg, name) {\n return editor.dom.serializeStyle(stylesArg, name);\n };\n };\n var uploadImage = function (editor) {\n return function (blobInfo) {\n return global$4(editor).upload([blobInfo], false).then(function (results) {\n if (results.length === 0) {\n return global$2.reject('Failed to upload image');\n } else if (results[0].status === false) {\n return global$2.reject(results[0].error);\n } else {\n return results[0];\n }\n });\n };\n };\n var Dialog = function (editor) {\n var helpers = {\n onSubmit: submitHandler(editor),\n imageSize: imageSize(editor),\n addToBlobCache: addToBlobCache(editor),\n createBlobCache: createBlobCache(editor),\n alertErr: alertErr(editor),\n normalizeCss: normalizeCss$1(editor),\n parseStyle: parseStyle(editor),\n serializeStyle: serializeStyle(editor),\n uploadImage: uploadImage(editor)\n };\n var open = function () {\n collect(editor).then(makeDialog(helpers)).then(editor.windowManager.open);\n };\n return { open: open };\n };\n\n var register = function (editor) {\n editor.addCommand('mceImage', Dialog(editor).open);\n editor.addCommand('mceUpdateImage', function (_ui, data) {\n editor.undoManager.transact(function () {\n return insertOrUpdateImage(editor, data);\n });\n });\n };\n\n var hasImageClass = function (node) {\n var className = node.attr('class');\n return className && /\\bimage\\b/.test(className);\n };\n var toggleContentEditableState = function (state) {\n return function (nodes) {\n var i = nodes.length;\n var toggleContentEditable = function (node) {\n node.attr('contenteditable', state ? 'true' : null);\n };\n while (i--) {\n var node = nodes[i];\n if (hasImageClass(node)) {\n node.attr('contenteditable', state ? 'false' : null);\n global$5.each(node.getAll('figcaption'), toggleContentEditable);\n }\n }\n };\n };\n var setup = function (editor) {\n editor.on('PreInit', function () {\n editor.parser.addNodeFilter('figure', toggleContentEditableState(true));\n editor.serializer.addNodeFilter('figure', toggleContentEditableState(false));\n });\n };\n\n var register$1 = function (editor) {\n editor.ui.registry.addToggleButton('image', {\n icon: 'image',\n tooltip: 'Insert/edit image',\n onAction: Dialog(editor).open,\n onSetup: function (buttonApi) {\n return editor.selection.selectorChangedWithUnbind('img:not([data-mce-object],[data-mce-placeholder]),figure.image', buttonApi.setActive).unbind;\n }\n });\n editor.ui.registry.addMenuItem('image', {\n icon: 'image',\n text: 'Image...',\n onAction: Dialog(editor).open\n });\n editor.ui.registry.addContextMenu('image', {\n update: function (element) {\n return isFigure(element) || isImage(element) && !isPlaceholderImage(element) ? ['image'] : [];\n }\n });\n };\n\n function Plugin () {\n global.add('image', function (editor) {\n setup(editor);\n register$1(editor);\n register(editor);\n });\n }\n\n Plugin();\n\n}());\n\n\n//# sourceURL=webpack:///./src/js/plugins/image/plugin.js?")}});