plugin.min.js 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792
  1. /**
  2. * Copyright (c) Tiny Technologies, Inc. All rights reserved.
  3. * Licensed under the LGPL or a commercial license.
  4. * For LGPL see License.txt in the project root for license information.
  5. * For commercial licenses see https://www.tiny.cloud/
  6. *
  7. * Version: 5.9.2 (2021-09-08)
  8. */
  9. (function () {
  10. 'use strict';
  11. var global$5 = tinymce.util.Tools.resolve('tinymce.PluginManager');
  12. var __assign = function () {
  13. __assign = Object.assign || function __assign(t) {
  14. for (var s, i = 1, n = arguments.length; i < n; i++) {
  15. s = arguments[i];
  16. for (var p in s)
  17. if (Object.prototype.hasOwnProperty.call(s, p))
  18. t[p] = s[p];
  19. }
  20. return t;
  21. };
  22. return __assign.apply(this, arguments);
  23. };
  24. var typeOf = function (x) {
  25. var t = typeof x;
  26. if (x === null) {
  27. return 'null';
  28. } else if (t === 'object' && (Array.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'Array')) {
  29. return 'array';
  30. } else if (t === 'object' && (String.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'String')) {
  31. return 'string';
  32. } else {
  33. return t;
  34. }
  35. };
  36. var isType = function (type) {
  37. return function (value) {
  38. return typeOf(value) === type;
  39. };
  40. };
  41. var isSimpleType = function (type) {
  42. return function (value) {
  43. return typeof value === type;
  44. };
  45. };
  46. var eq = function (t) {
  47. return function (a) {
  48. return t === a;
  49. };
  50. };
  51. var isString = isType('string');
  52. var isObject = isType('object');
  53. var isArray = isType('array');
  54. var isNull = eq(null);
  55. var isBoolean = isSimpleType('boolean');
  56. var isNullable = function (a) {
  57. return a === null || a === undefined;
  58. };
  59. var isNonNullable = function (a) {
  60. return !isNullable(a);
  61. };
  62. var isFunction = isSimpleType('function');
  63. var isNumber = isSimpleType('number');
  64. var noop = function () {
  65. };
  66. var constant = function (value) {
  67. return function () {
  68. return value;
  69. };
  70. };
  71. var identity = function (x) {
  72. return x;
  73. };
  74. var never = constant(false);
  75. var always = constant(true);
  76. var none = function () {
  77. return NONE;
  78. };
  79. var NONE = function () {
  80. var call = function (thunk) {
  81. return thunk();
  82. };
  83. var id = identity;
  84. var me = {
  85. fold: function (n, _s) {
  86. return n();
  87. },
  88. isSome: never,
  89. isNone: always,
  90. getOr: id,
  91. getOrThunk: call,
  92. getOrDie: function (msg) {
  93. throw new Error(msg || 'error: getOrDie called on none.');
  94. },
  95. getOrNull: constant(null),
  96. getOrUndefined: constant(undefined),
  97. or: id,
  98. orThunk: call,
  99. map: none,
  100. each: noop,
  101. bind: none,
  102. exists: never,
  103. forall: always,
  104. filter: function () {
  105. return none();
  106. },
  107. toArray: function () {
  108. return [];
  109. },
  110. toString: constant('none()')
  111. };
  112. return me;
  113. }();
  114. var some = function (a) {
  115. var constant_a = constant(a);
  116. var self = function () {
  117. return me;
  118. };
  119. var bind = function (f) {
  120. return f(a);
  121. };
  122. var me = {
  123. fold: function (n, s) {
  124. return s(a);
  125. },
  126. isSome: always,
  127. isNone: never,
  128. getOr: constant_a,
  129. getOrThunk: constant_a,
  130. getOrDie: constant_a,
  131. getOrNull: constant_a,
  132. getOrUndefined: constant_a,
  133. or: self,
  134. orThunk: self,
  135. map: function (f) {
  136. return some(f(a));
  137. },
  138. each: function (f) {
  139. f(a);
  140. },
  141. bind: bind,
  142. exists: bind,
  143. forall: bind,
  144. filter: function (f) {
  145. return f(a) ? me : NONE;
  146. },
  147. toArray: function () {
  148. return [a];
  149. },
  150. toString: function () {
  151. return 'some(' + a + ')';
  152. }
  153. };
  154. return me;
  155. };
  156. var from = function (value) {
  157. return value === null || value === undefined ? NONE : some(value);
  158. };
  159. var Optional = {
  160. some: some,
  161. none: none,
  162. from: from
  163. };
  164. var keys = Object.keys;
  165. var hasOwnProperty = Object.hasOwnProperty;
  166. var each = function (obj, f) {
  167. var props = keys(obj);
  168. for (var k = 0, len = props.length; k < len; k++) {
  169. var i = props[k];
  170. var x = obj[i];
  171. f(x, i);
  172. }
  173. };
  174. var objAcc = function (r) {
  175. return function (x, i) {
  176. r[i] = x;
  177. };
  178. };
  179. var internalFilter = function (obj, pred, onTrue, onFalse) {
  180. var r = {};
  181. each(obj, function (x, i) {
  182. (pred(x, i) ? onTrue : onFalse)(x, i);
  183. });
  184. return r;
  185. };
  186. var filter = function (obj, pred) {
  187. var t = {};
  188. internalFilter(obj, pred, objAcc(t), noop);
  189. return t;
  190. };
  191. var has = function (obj, key) {
  192. return hasOwnProperty.call(obj, key);
  193. };
  194. var hasNonNullableKey = function (obj, key) {
  195. return has(obj, key) && obj[key] !== undefined && obj[key] !== null;
  196. };
  197. var nativePush = Array.prototype.push;
  198. var flatten = function (xs) {
  199. var r = [];
  200. for (var i = 0, len = xs.length; i < len; ++i) {
  201. if (!isArray(xs[i])) {
  202. throw new Error('Arr.flatten item ' + i + ' was not an array, input: ' + xs);
  203. }
  204. nativePush.apply(r, xs[i]);
  205. }
  206. return r;
  207. };
  208. var get = function (xs, i) {
  209. return i >= 0 && i < xs.length ? Optional.some(xs[i]) : Optional.none();
  210. };
  211. var head = function (xs) {
  212. return get(xs, 0);
  213. };
  214. var findMap = function (arr, f) {
  215. for (var i = 0; i < arr.length; i++) {
  216. var r = f(arr[i], i);
  217. if (r.isSome()) {
  218. return r;
  219. }
  220. }
  221. return Optional.none();
  222. };
  223. typeof window !== 'undefined' ? window : Function('return this;')();
  224. var rawSet = function (dom, key, value) {
  225. if (isString(value) || isBoolean(value) || isNumber(value)) {
  226. dom.setAttribute(key, value + '');
  227. } else {
  228. console.error('Invalid call to Attribute.set. Key ', key, ':: Value ', value, ':: Element ', dom);
  229. throw new Error('Attribute value was not simple');
  230. }
  231. };
  232. var set = function (element, key, value) {
  233. rawSet(element.dom, key, value);
  234. };
  235. var remove = function (element, key) {
  236. element.dom.removeAttribute(key);
  237. };
  238. var fromHtml = function (html, scope) {
  239. var doc = scope || document;
  240. var div = doc.createElement('div');
  241. div.innerHTML = html;
  242. if (!div.hasChildNodes() || div.childNodes.length > 1) {
  243. console.error('HTML does not have a single root node', html);
  244. throw new Error('HTML must have a single root node');
  245. }
  246. return fromDom(div.childNodes[0]);
  247. };
  248. var fromTag = function (tag, scope) {
  249. var doc = scope || document;
  250. var node = doc.createElement(tag);
  251. return fromDom(node);
  252. };
  253. var fromText = function (text, scope) {
  254. var doc = scope || document;
  255. var node = doc.createTextNode(text);
  256. return fromDom(node);
  257. };
  258. var fromDom = function (node) {
  259. if (node === null || node === undefined) {
  260. throw new Error('Node cannot be null or undefined');
  261. }
  262. return { dom: node };
  263. };
  264. var fromPoint = function (docElm, x, y) {
  265. return Optional.from(docElm.dom.elementFromPoint(x, y)).map(fromDom);
  266. };
  267. var SugarElement = {
  268. fromHtml: fromHtml,
  269. fromTag: fromTag,
  270. fromText: fromText,
  271. fromDom: fromDom,
  272. fromPoint: fromPoint
  273. };
  274. var global$4 = tinymce.util.Tools.resolve('tinymce.dom.DOMUtils');
  275. var global$3 = tinymce.util.Tools.resolve('tinymce.util.Promise');
  276. var global$2 = tinymce.util.Tools.resolve('tinymce.util.XHR');
  277. var hasDimensions = function (editor) {
  278. return editor.getParam('image_dimensions', true, 'boolean');
  279. };
  280. var hasAdvTab = function (editor) {
  281. return editor.getParam('image_advtab', false, 'boolean');
  282. };
  283. var hasUploadTab = function (editor) {
  284. return editor.getParam('image_uploadtab', true, 'boolean');
  285. };
  286. var getPrependUrl = function (editor) {
  287. return editor.getParam('image_prepend_url', '', 'string');
  288. };
  289. var getClassList = function (editor) {
  290. return editor.getParam('image_class_list');
  291. };
  292. var hasDescription = function (editor) {
  293. return editor.getParam('image_description', true, 'boolean');
  294. };
  295. var hasImageTitle = function (editor) {
  296. return editor.getParam('image_title', false, 'boolean');
  297. };
  298. var hasImageCaption = function (editor) {
  299. return editor.getParam('image_caption', false, 'boolean');
  300. };
  301. var getImageList = function (editor) {
  302. return editor.getParam('image_list', false);
  303. };
  304. var hasUploadUrl = function (editor) {
  305. return isNonNullable(editor.getParam('images_upload_url'));
  306. };
  307. var hasUploadHandler = function (editor) {
  308. return isNonNullable(editor.getParam('images_upload_handler'));
  309. };
  310. var showAccessibilityOptions = function (editor) {
  311. return editor.getParam('a11y_advanced_options', false, 'boolean');
  312. };
  313. var isAutomaticUploadsEnabled = function (editor) {
  314. return editor.getParam('automatic_uploads', true, 'boolean');
  315. };
  316. var isBase64Enable = function (editor) {
  317. return editor.getParam('base64Encode', false, 'boolean');
  318. };
  319. var isPreviewEnable = function (editor) {
  320. return (editor || tinymce.activeEditor).getParam('enablePreview', true, 'boolean');
  321. };
  322. var parseIntAndGetMax = function (val1, val2) {
  323. return Math.max(parseInt(val1, 10), parseInt(val2, 10));
  324. };
  325. var getImageSize = function (url) {
  326. return new global$3(function (callback) {
  327. var img = document.createElement('img');
  328. var done = function (dimensions) {
  329. img.onload = img.onerror = null;
  330. if (img.parentNode) {
  331. img.parentNode.removeChild(img);
  332. }
  333. callback(dimensions);
  334. };
  335. img.onload = function () {
  336. var width = parseIntAndGetMax(img.width, img.clientWidth);
  337. var height = parseIntAndGetMax(img.height, img.clientHeight);
  338. var dimensions = {
  339. width: width,
  340. height: height
  341. };
  342. done(global$3.resolve(dimensions));
  343. };
  344. img.onerror = function () {
  345. done(global$3.reject('Failed to get image dimensions for: ' + url));
  346. };
  347. var style = img.style;
  348. style.visibility = 'hidden';
  349. style.position = 'fixed';
  350. style.bottom = style.left = '0px';
  351. style.width = style.height = 'auto';
  352. document.body.appendChild(img);
  353. img.src = url;
  354. });
  355. };
  356. var removePixelSuffix = function (value) {
  357. if (value) {
  358. value = value.replace(/px$/, '');
  359. }
  360. return value;
  361. };
  362. var addPixelSuffix = function (value) {
  363. if (value.length > 0 && /^[0-9]+$/.test(value)) {
  364. value += 'px';
  365. }
  366. return value;
  367. };
  368. var mergeMargins = function (css) {
  369. if (css.margin) {
  370. var splitMargin = String(css.margin).split(' ');
  371. switch (splitMargin.length) {
  372. case 1:
  373. css['margin-top'] = css['margin-top'] || splitMargin[0];
  374. css['margin-right'] = css['margin-right'] || splitMargin[0];
  375. css['margin-bottom'] = css['margin-bottom'] || splitMargin[0];
  376. css['margin-left'] = css['margin-left'] || splitMargin[0];
  377. break;
  378. case 2:
  379. css['margin-top'] = css['margin-top'] || splitMargin[0];
  380. css['margin-right'] = css['margin-right'] || splitMargin[1];
  381. css['margin-bottom'] = css['margin-bottom'] || splitMargin[0];
  382. css['margin-left'] = css['margin-left'] || splitMargin[1];
  383. break;
  384. case 3:
  385. css['margin-top'] = css['margin-top'] || splitMargin[0];
  386. css['margin-right'] = css['margin-right'] || splitMargin[1];
  387. css['margin-bottom'] = css['margin-bottom'] || splitMargin[2];
  388. css['margin-left'] = css['margin-left'] || splitMargin[1];
  389. break;
  390. case 4:
  391. css['margin-top'] = css['margin-top'] || splitMargin[0];
  392. css['margin-right'] = css['margin-right'] || splitMargin[1];
  393. css['margin-bottom'] = css['margin-bottom'] || splitMargin[2];
  394. css['margin-left'] = css['margin-left'] || splitMargin[3];
  395. }
  396. delete css.margin;
  397. }
  398. return css;
  399. };
  400. var createImageList = function (editor, callback) {
  401. var imageList = getImageList(editor);
  402. if (isString(imageList)) {
  403. global$2.send({
  404. url: imageList,
  405. success: function (text) {
  406. callback(JSON.parse(text));
  407. }
  408. });
  409. } else if (isFunction(imageList)) {
  410. imageList(callback);
  411. } else {
  412. callback(imageList);
  413. }
  414. };
  415. var waitLoadImage = function (editor, data, imgElm) {
  416. var selectImage = function () {
  417. imgElm.onload = imgElm.onerror = null;
  418. if (editor.selection) {
  419. editor.selection.select(imgElm);
  420. editor.nodeChanged();
  421. }
  422. };
  423. imgElm.onload = function () {
  424. if (!data.width && !data.height && hasDimensions(editor)) {
  425. editor.dom.setAttribs(imgElm, {
  426. width: String(imgElm.clientWidth),
  427. height: String(imgElm.clientHeight)
  428. });
  429. }
  430. selectImage();
  431. };
  432. imgElm.onerror = selectImage;
  433. };
  434. var blobToDataUri = function (blob) {
  435. return new global$3(function (resolve, reject) {
  436. var reader = new FileReader();
  437. reader.onload = function () {
  438. resolve(reader.result);
  439. };
  440. reader.onerror = function () {
  441. reject(reader.error.message);
  442. };
  443. reader.readAsDataURL(blob);
  444. });
  445. };
  446. var isPlaceholderImage = function (imgElm) {
  447. return imgElm.nodeName === 'IMG' && (imgElm.hasAttribute('data-mce-object') || imgElm.hasAttribute('data-mce-placeholder'));
  448. };
  449. var DOM = global$4.DOM;
  450. var getHspace = function (image) {
  451. if (image.style.marginLeft && image.style.marginRight && image.style.marginLeft === image.style.marginRight) {
  452. return removePixelSuffix(image.style.marginLeft);
  453. } else {
  454. return '';
  455. }
  456. };
  457. var getVspace = function (image) {
  458. if (image.style.marginTop && image.style.marginBottom && image.style.marginTop === image.style.marginBottom) {
  459. return removePixelSuffix(image.style.marginTop);
  460. } else {
  461. return '';
  462. }
  463. };
  464. var getBorder = function (image) {
  465. if (image.style.borderWidth) {
  466. return removePixelSuffix(image.style.borderWidth);
  467. } else {
  468. return '';
  469. }
  470. };
  471. var getAttrib = function (image, name) {
  472. if (image.hasAttribute(name)) {
  473. return image.getAttribute(name);
  474. } else {
  475. return '';
  476. }
  477. };
  478. var getStyle = function (image, name) {
  479. return image.style[name] ? image.style[name] : '';
  480. };
  481. var hasCaption = function (image) {
  482. return image.parentNode !== null && image.parentNode.nodeName === 'FIGURE';
  483. };
  484. var updateAttrib = function (image, name, value) {
  485. if (value === '') {
  486. image.removeAttribute(name);
  487. } else {
  488. image.setAttribute(name, value);
  489. }
  490. };
  491. var wrapInFigure = function (image) {
  492. var figureElm = DOM.create('figure', { class: 'image' });
  493. DOM.insertAfter(figureElm, image);
  494. figureElm.appendChild(image);
  495. figureElm.appendChild(DOM.create('figcaption', { contentEditable: 'true' }, 'Caption'));
  496. figureElm.contentEditable = 'false';
  497. };
  498. var removeFigure = function (image) {
  499. var figureElm = image.parentNode;
  500. DOM.insertAfter(image, figureElm);
  501. DOM.remove(figureElm);
  502. };
  503. var toggleCaption = function (image) {
  504. if (hasCaption(image)) {
  505. removeFigure(image);
  506. } else {
  507. wrapInFigure(image);
  508. }
  509. };
  510. var normalizeStyle = function (image, normalizeCss) {
  511. var attrValue = image.getAttribute('style');
  512. var value = normalizeCss(attrValue !== null ? attrValue : '');
  513. if (value.length > 0) {
  514. image.setAttribute('style', value);
  515. image.setAttribute('data-mce-style', value);
  516. } else {
  517. image.removeAttribute('style');
  518. }
  519. };
  520. var setSize = function (name, normalizeCss) {
  521. return function (image, name, value) {
  522. if (image.style[name]) {
  523. image.style[name] = addPixelSuffix(value);
  524. normalizeStyle(image, normalizeCss);
  525. } else {
  526. updateAttrib(image, name, value);
  527. }
  528. };
  529. };
  530. var getSize = function (image, name) {
  531. if (image.style[name]) {
  532. return removePixelSuffix(image.style[name]);
  533. } else {
  534. return getAttrib(image, name);
  535. }
  536. };
  537. var setHspace = function (image, value) {
  538. var pxValue = addPixelSuffix(value);
  539. image.style.marginLeft = pxValue;
  540. image.style.marginRight = pxValue;
  541. };
  542. var setVspace = function (image, value) {
  543. var pxValue = addPixelSuffix(value);
  544. image.style.marginTop = pxValue;
  545. image.style.marginBottom = pxValue;
  546. };
  547. var setBorder = function (image, value) {
  548. var pxValue = addPixelSuffix(value);
  549. image.style.borderWidth = pxValue;
  550. };
  551. var setBorderStyle = function (image, value) {
  552. image.style.borderStyle = value;
  553. };
  554. var getBorderStyle = function (image) {
  555. return getStyle(image, 'borderStyle');
  556. };
  557. var isFigure = function (elm) {
  558. return elm.nodeName === 'FIGURE';
  559. };
  560. var isImage = function (elm) {
  561. return elm.nodeName === 'IMG';
  562. };
  563. var getIsDecorative = function (image) {
  564. return DOM.getAttrib(image, 'alt').length === 0 && DOM.getAttrib(image, 'role') === 'presentation';
  565. };
  566. var getAlt = function (image) {
  567. if (getIsDecorative(image)) {
  568. return '';
  569. } else {
  570. return getAttrib(image, 'alt');
  571. }
  572. };
  573. var defaultData = function () {
  574. return {
  575. src: '',
  576. alt: '',
  577. title: '',
  578. width: '',
  579. height: '',
  580. class: '',
  581. style: '',
  582. caption: false,
  583. hspace: '',
  584. vspace: '',
  585. border: '',
  586. borderStyle: '',
  587. isDecorative: false,
  588. "data-id": '',
  589. "data-orgid": '',
  590. "data-width": '',
  591. "data-height": '',
  592. "onerror": '',
  593. "data-prv": true,
  594. "data-filename": ''
  595. };
  596. };
  597. var getStyleValue = function (normalizeCss, data) {
  598. var image = document.createElement('img');
  599. updateAttrib(image, 'style', data.style);
  600. if (getHspace(image) || data.hspace !== '') {
  601. setHspace(image, data.hspace);
  602. }
  603. if (getVspace(image) || data.vspace !== '') {
  604. setVspace(image, data.vspace);
  605. }
  606. if (getBorder(image) || data.border !== '') {
  607. setBorder(image, data.border);
  608. }
  609. if (getBorderStyle(image) || data.borderStyle !== '') {
  610. setBorderStyle(image, data.borderStyle);
  611. }
  612. return normalizeCss(image.getAttribute('style'));
  613. };
  614. var create = function (normalizeCss, data) {
  615. var image = document.createElement('img');
  616. write(normalizeCss, __assign(__assign({}, data), { caption: false }), image);
  617. setAlt(image, data.alt, data.isDecorative);
  618. if (data.caption) {
  619. var figure = DOM.create('figure', { class: 'image' });
  620. figure.appendChild(image);
  621. figure.appendChild(DOM.create('figcaption', { contentEditable: 'true' }, 'Caption'));
  622. figure.contentEditable = 'false';
  623. return figure;
  624. } else {
  625. return image;
  626. }
  627. };
  628. var read = function (normalizeCss, image) {
  629. var prv = getAttrib(image, 'data-prv');
  630. return {
  631. src: getAttrib(image, 'src'),
  632. alt: getAlt(image),
  633. title: getAttrib(image, 'title'),
  634. width: getAttrib(image, 'data-width') || getSize(image, 'width'),
  635. height: getAttrib(image, 'data-height') || getSize(image, 'height'),
  636. class: getAttrib(image, 'class'),
  637. style: normalizeCss(getAttrib(image, 'style')),
  638. caption: hasCaption(image),
  639. hspace: getHspace(image),
  640. vspace: getVspace(image),
  641. border: getBorder(image),
  642. borderStyle: getStyle(image, 'borderStyle'),
  643. isDecorative: getIsDecorative(image),
  644. "data-id": getAttrib(image, 'data-id'),
  645. "data-orgid": getAttrib(image, 'data-orgid'),
  646. "data-width": getAttrib(image, 'data-width'),
  647. "data-height": getAttrib(image, 'data-height'),
  648. "data-filename": getAttrib(image, 'data-filename'),
  649. "onerror": getAttrib(image, 'onerror'),
  650. "data-prv": (prv !== false && prv !== "false")
  651. };
  652. };
  653. var updateProp = function (image, oldData, newData, name, set) {
  654. if (newData[name] !== oldData[name]) {
  655. set(image, name, newData[name]);
  656. }
  657. };
  658. var setAlt = function (image, alt, isDecorative) {
  659. if (isDecorative) {
  660. DOM.setAttrib(image, 'role', 'presentation');
  661. var sugarImage = SugarElement.fromDom(image);
  662. set(sugarImage, 'alt', '');
  663. } else {
  664. if (isNull(alt)) {
  665. var sugarImage = SugarElement.fromDom(image);
  666. remove(sugarImage, 'alt');
  667. } else {
  668. var sugarImage = SugarElement.fromDom(image);
  669. set(sugarImage, 'alt', alt);
  670. }
  671. if (DOM.getAttrib(image, 'role') === 'presentation') {
  672. DOM.setAttrib(image, 'role', '');
  673. }
  674. }
  675. };
  676. var updateAlt = function (image, oldData, newData) {
  677. if (newData.alt !== oldData.alt || newData.isDecorative !== oldData.isDecorative) {
  678. setAlt(image, newData.alt, newData.isDecorative);
  679. }
  680. };
  681. var normalized = function (set, normalizeCss) {
  682. return function (image, name, value) {
  683. set(image, value);
  684. normalizeStyle(image, normalizeCss);
  685. };
  686. };
  687. var write = function (normalizeCss, newData, image) {
  688. var oldData = read(normalizeCss, image);
  689. updateProp(image, oldData, newData, 'caption', function (image, _name, _value) {
  690. return toggleCaption(image);
  691. });
  692. updateProp(image, oldData, newData, 'src', updateAttrib);
  693. updateProp(image, oldData, newData, 'title', updateAttrib);
  694. updateProp(image, oldData, newData, 'width', setSize('width', normalizeCss));
  695. updateProp(image, oldData, newData, 'height', setSize('height', normalizeCss));
  696. updateProp(image, oldData, newData, 'class', updateAttrib);
  697. updateProp(image, oldData, newData, 'style', normalized(function (image, value) {
  698. return updateAttrib(image, 'style', value);
  699. }, normalizeCss));
  700. updateProp(image, oldData, newData, 'hspace', normalized(setHspace, normalizeCss));
  701. updateProp(image, oldData, newData, 'vspace', normalized(setVspace, normalizeCss));
  702. updateProp(image, oldData, newData, 'border', normalized(setBorder, normalizeCss));
  703. updateProp(image, oldData, newData, 'borderStyle', normalized(setBorderStyle, normalizeCss));
  704. updateAlt(image, oldData, newData);
  705. updateProp(image, oldData, newData, 'data-id', updateAttrib);
  706. updateProp(image, oldData, newData, 'data-orgid', updateAttrib);
  707. updateProp(image, oldData, newData, 'data-width', updateAttrib);
  708. updateProp(image, oldData, newData, 'data-height', updateAttrib);
  709. updateProp(image, oldData, newData, 'onerror', updateAttrib);
  710. updateProp(image, oldData, newData, 'data-prv', updateAttrib);
  711. updateProp(image, oldData, newData, 'data-filename', updateAttrib);
  712. };
  713. var normalizeCss$1 = function (editor, cssText) {
  714. var css = editor.dom.styles.parse(cssText);
  715. var mergedCss = mergeMargins(css);
  716. var compressed = editor.dom.styles.parse(editor.dom.styles.serialize(mergedCss));
  717. return editor.dom.styles.serialize(compressed);
  718. };
  719. var getSelectedImage = function (editor) {
  720. var imgElm = editor.selection.getNode();
  721. var figureElm = editor.dom.getParent(imgElm, 'figure.image');
  722. if (figureElm) {
  723. return editor.dom.select('img', figureElm)[0];
  724. }
  725. if (imgElm && (imgElm.nodeName !== 'IMG' || isPlaceholderImage(imgElm))) {
  726. return null;
  727. }
  728. return imgElm;
  729. };
  730. var splitTextBlock = function (editor, figure) {
  731. var dom = editor.dom;
  732. var textBlockElements = filter(editor.schema.getTextBlockElements(), function (_, parentElm) {
  733. return !editor.schema.isValidChild(parentElm, 'figure');
  734. });
  735. var textBlock = dom.getParent(figure.parentNode, function (node) {
  736. return hasNonNullableKey(textBlockElements, node.nodeName);
  737. }, editor.getBody());
  738. if (textBlock) {
  739. return dom.split(textBlock, figure);
  740. } else {
  741. return figure;
  742. }
  743. };
  744. var readImageDataFromSelection = function (editor) {
  745. var image = getSelectedImage(editor);
  746. return image ? read(function (css) {
  747. return normalizeCss$1(editor, css);
  748. }, image) : defaultData();
  749. };
  750. var insertImageAtCaret = function (editor, data) {
  751. var elm = create(function (css) {
  752. return normalizeCss$1(editor, css);
  753. }, data);
  754. editor.dom.setAttrib(elm, 'data-mce-id', '__mcenew');
  755. editor.focus();
  756. editor.selection.setContent(elm.outerHTML);
  757. var insertedElm = editor.dom.select('*[data-mce-id="__mcenew"]')[0];
  758. editor.dom.setAttrib(insertedElm, 'data-mce-id', null);
  759. if (isFigure(insertedElm)) {
  760. var figure = splitTextBlock(editor, insertedElm);
  761. editor.selection.select(figure);
  762. } else {
  763. editor.selection.select(insertedElm);
  764. }
  765. };
  766. var syncSrcAttr = function (editor, image) {
  767. editor.dom.setAttrib(image, 'src', image.getAttribute('src'));
  768. };
  769. var deleteImage = function (editor, image) {
  770. if (image) {
  771. var elm = editor.dom.is(image.parentNode, 'figure.image') ? image.parentNode : image;
  772. editor.dom.remove(elm);
  773. editor.focus();
  774. editor.nodeChanged();
  775. if (editor.dom.isEmpty(editor.getBody())) {
  776. editor.setContent('');
  777. editor.selection.setCursorLocation();
  778. }
  779. }
  780. };
  781. var writeImageDataToSelection = function (editor, data) {
  782. var image = getSelectedImage(editor);
  783. write(function (css) {
  784. return normalizeCss$1(editor, css);
  785. }, data, image);
  786. syncSrcAttr(editor, image);
  787. if (isFigure(image.parentNode)) {
  788. var figure = image.parentNode;
  789. splitTextBlock(editor, figure);
  790. editor.selection.select(image.parentNode);
  791. } else {
  792. editor.selection.select(image);
  793. waitLoadImage(editor, data, image);
  794. }
  795. };
  796. var insertOrUpdateImage = function (editor, partialData) {
  797. var image = getSelectedImage(editor);
  798. if (image) {
  799. var selectedImageData = read(function (css) {
  800. return normalizeCss$1(editor, css);
  801. }, image);
  802. var data = __assign(__assign({}, selectedImageData), partialData);
  803. if (data.src) {
  804. writeImageDataToSelection(editor, data);
  805. } else {
  806. deleteImage(editor, image);
  807. }
  808. } else if (partialData.src) {
  809. insertImageAtCaret(editor, __assign(__assign({}, defaultData()), partialData));
  810. }
  811. };
  812. var deep = function (old, nu) {
  813. var bothObjects = isObject(old) && isObject(nu);
  814. return bothObjects ? deepMerge(old, nu) : nu;
  815. };
  816. var baseMerge = function (merger) {
  817. return function () {
  818. var objects = [];
  819. for (var _i = 0; _i < arguments.length; _i++) {
  820. objects[_i] = arguments[_i];
  821. }
  822. if (objects.length === 0) {
  823. throw new Error('Can\'t merge zero objects');
  824. }
  825. var ret = {};
  826. for (var j = 0; j < objects.length; j++) {
  827. var curObject = objects[j];
  828. for (var key in curObject) {
  829. if (has(curObject, key)) {
  830. ret[key] = merger(ret[key], curObject[key]);
  831. }
  832. }
  833. }
  834. return ret;
  835. };
  836. };
  837. var deepMerge = baseMerge(deep);
  838. var isNotEmpty = function (s) {
  839. return s.length > 0;
  840. };
  841. var global$1 = tinymce.util.Tools.resolve('tinymce.util.ImageUploader');
  842. var global = tinymce.util.Tools.resolve('tinymce.util.Tools');
  843. var getValue = function (item) {
  844. return isString(item.value) ? item.value : '';
  845. };
  846. var getText = function (item) {
  847. if (isString(item.text)) {
  848. return item.text;
  849. } else if (isString(item.title)) {
  850. return item.title;
  851. } else {
  852. return '';
  853. }
  854. };
  855. var sanitizeList = function (list, extractValue) {
  856. var out = [];
  857. global.each(list, function (item) {
  858. var text = getText(item);
  859. if (item.menu !== undefined) {
  860. var items = sanitizeList(item.menu, extractValue);
  861. out.push({
  862. text: text,
  863. items: items
  864. });
  865. } else {
  866. var value = extractValue(item);
  867. out.push({
  868. text: text,
  869. value: value
  870. });
  871. }
  872. });
  873. return out;
  874. };
  875. var sanitizer = function (extractor) {
  876. if (extractor === void 0) {
  877. extractor = getValue;
  878. }
  879. return function (list) {
  880. if (list) {
  881. return Optional.from(list).map(function (list) {
  882. return sanitizeList(list, extractor);
  883. });
  884. } else {
  885. return Optional.none();
  886. }
  887. };
  888. };
  889. var sanitize = function (list) {
  890. return sanitizer(getValue)(list);
  891. };
  892. var isGroup = function (item) {
  893. return has(item, 'items');
  894. };
  895. var findEntryDelegate = function (list, value) {
  896. return findMap(list, function (item) {
  897. if (isGroup(item)) {
  898. return findEntryDelegate(item.items, value);
  899. } else if (item.value === value) {
  900. return Optional.some(item);
  901. } else {
  902. return Optional.none();
  903. }
  904. });
  905. };
  906. var findEntry = function (optList, value) {
  907. return optList.bind(function (list) {
  908. return findEntryDelegate(list, value);
  909. });
  910. };
  911. var ListUtils = {
  912. sanitizer: sanitizer,
  913. sanitize: sanitize,
  914. findEntry: findEntry
  915. };
  916. var makeTab$2 = function (_info) {
  917. return {
  918. title: 'Advanced',
  919. name: 'advanced',
  920. items: [
  921. {
  922. type: 'input',
  923. label: 'Style',
  924. name: 'style'
  925. },
  926. {
  927. type: 'grid',
  928. columns: 2,
  929. items: [
  930. {
  931. type: 'input',
  932. label: 'Vertical space',
  933. name: 'vspace',
  934. inputMode: 'numeric'
  935. },
  936. {
  937. type: 'input',
  938. label: 'Horizontal space',
  939. name: 'hspace',
  940. inputMode: 'numeric'
  941. },
  942. {
  943. type: 'input',
  944. label: 'Border width',
  945. name: 'border',
  946. inputMode: 'numeric'
  947. },
  948. {
  949. type: 'listbox',
  950. name: 'borderstyle',
  951. label: 'Border style',
  952. items: [
  953. {
  954. text: 'Select...',
  955. value: ''
  956. },
  957. {
  958. text: 'Solid',
  959. value: 'solid'
  960. },
  961. {
  962. text: 'Dotted',
  963. value: 'dotted'
  964. },
  965. {
  966. text: 'Dashed',
  967. value: 'dashed'
  968. },
  969. {
  970. text: 'Double',
  971. value: 'double'
  972. },
  973. {
  974. text: 'Groove',
  975. value: 'groove'
  976. },
  977. {
  978. text: 'Ridge',
  979. value: 'ridge'
  980. },
  981. {
  982. text: 'Inset',
  983. value: 'inset'
  984. },
  985. {
  986. text: 'Outset',
  987. value: 'outset'
  988. },
  989. {
  990. text: 'None',
  991. value: 'none'
  992. },
  993. {
  994. text: 'Hidden',
  995. value: 'hidden'
  996. }
  997. ]
  998. }
  999. ]
  1000. }
  1001. ]
  1002. };
  1003. };
  1004. var AdvTab = { makeTab: makeTab$2 };
  1005. var collect = function (editor) {
  1006. var urlListSanitizer = ListUtils.sanitizer(function (item) {
  1007. return editor.convertURL(item.value || item.url, 'src');
  1008. });
  1009. var futureImageList = new global$3(function (completer) {
  1010. createImageList(editor, function (imageList) {
  1011. completer(urlListSanitizer(imageList).map(function (items) {
  1012. return flatten([
  1013. [{
  1014. text: 'None',
  1015. value: ''
  1016. }],
  1017. items
  1018. ]);
  1019. }));
  1020. });
  1021. });
  1022. var classList = ListUtils.sanitize(getClassList(editor));
  1023. var hasAdvTab$1 = hasAdvTab(editor);
  1024. var hasUploadTab$1 = hasUploadTab(editor);
  1025. var hasUploadUrl$1 = hasUploadUrl(editor);
  1026. var hasUploadHandler$1 = hasUploadHandler(editor);
  1027. var image = readImageDataFromSelection(editor);
  1028. var hasDescription$1 = hasDescription(editor);
  1029. var hasImageTitle$1 = hasImageTitle(editor);
  1030. var hasDimensions$1 = hasDimensions(editor);
  1031. var hasImageCaption$1 = hasImageCaption(editor);
  1032. var hasAccessibilityOptions = showAccessibilityOptions(editor);
  1033. var automaticUploads = isAutomaticUploadsEnabled(editor);
  1034. var prependURL = Optional.some(getPrependUrl(editor)).filter(function (preUrl) {
  1035. return isString(preUrl) && preUrl.length > 0;
  1036. });
  1037. var isBase64Enable$1 = isBase64Enable(editor);
  1038. var isPreviewEnable$1 = isPreviewEnable(editor);
  1039. return futureImageList.then(function (imageList) {
  1040. return {
  1041. image: image,
  1042. imageList: imageList,
  1043. classList: classList,
  1044. hasAdvTab: hasAdvTab$1,
  1045. hasUploadTab: hasUploadTab$1,
  1046. hasUploadUrl: hasUploadUrl$1,
  1047. hasUploadHandler: hasUploadHandler$1,
  1048. hasDescription: hasDescription$1,
  1049. hasImageTitle: hasImageTitle$1,
  1050. hasDimensions: hasDimensions$1,
  1051. hasImageCaption: hasImageCaption$1,
  1052. prependURL: prependURL,
  1053. hasAccessibilityOptions: hasAccessibilityOptions,
  1054. automaticUploads: automaticUploads,
  1055. isBase64Enable: isBase64Enable$1,
  1056. isPreviewEnable: isPreviewEnable$1
  1057. };
  1058. });
  1059. };
  1060. var makeItems = function (info) {
  1061. var imageUrl = {
  1062. name: 'src',
  1063. type: 'urlinput',
  1064. filetype: 'image',
  1065. label: 'Source'
  1066. };
  1067. var imageList = info.imageList.map(function (items) {
  1068. return {
  1069. name: 'images',
  1070. type: 'listbox',
  1071. label: 'Image list',
  1072. items: items
  1073. };
  1074. });
  1075. var imageDescription = {
  1076. name: 'alt',
  1077. type: 'input',
  1078. label: 'Alternative description',
  1079. disabled: info.hasAccessibilityOptions && info.image.isDecorative
  1080. };
  1081. var imageTitle = {
  1082. name: 'title',
  1083. type: 'input',
  1084. label: 'Image title'
  1085. };
  1086. var imageDimensions = {
  1087. name: 'dimensions',
  1088. type: 'sizeinput'
  1089. };
  1090. var isDecorative = {
  1091. type: 'label',
  1092. label: 'Accessibility',
  1093. items: [{
  1094. name: 'isDecorative',
  1095. type: 'checkbox',
  1096. label: 'Image is decorative'
  1097. }]
  1098. };
  1099. var classList = info.classList.map(function (items) {
  1100. return {
  1101. name: 'classes',
  1102. type: 'listbox',
  1103. label: 'Class',
  1104. items: items
  1105. };
  1106. });
  1107. var caption = {
  1108. type: 'label',
  1109. label: 'Caption',
  1110. items: [{
  1111. type: 'checkbox',
  1112. name: 'caption',
  1113. label: 'Show caption'
  1114. }]
  1115. };
  1116. var preview = {
  1117. type: 'label',
  1118. label: '',
  1119. items: [{
  1120. type: 'checkbox',
  1121. name: 'data-prv',
  1122. label: '允许浏览原图'
  1123. }]
  1124. };
  1125. var enableBase64 = {
  1126. type: 'label',
  1127. label: '',
  1128. items: [{
  1129. type: 'checkbox',
  1130. name: 'base64enable',
  1131. label: '存为Base64编码'
  1132. }]
  1133. };
  1134. var getDialogContainerType = function (useColumns) {
  1135. return useColumns ? {
  1136. type: 'grid',
  1137. columns: 2
  1138. } : { type: 'panel' };
  1139. };
  1140. return flatten([
  1141. [imageUrl],
  1142. info.isPreviewEnable ? [preview] : [],
  1143. info.isBase64Enable ? [enableBase64] : [],
  1144. imageList.toArray(),
  1145. info.hasAccessibilityOptions && info.hasDescription ? [isDecorative] : [],
  1146. info.hasDescription ? [imageDescription] : [],
  1147. info.hasImageTitle ? [imageTitle] : [],
  1148. info.hasDimensions ? [imageDimensions] : [],
  1149. [__assign(__assign({}, getDialogContainerType(info.classList.isSome() && info.hasImageCaption)), {
  1150. items: flatten([
  1151. classList.toArray(),
  1152. info.hasImageCaption ? [caption] : []
  1153. ])
  1154. })]
  1155. ]);
  1156. };
  1157. var makeTab$1 = function (info) {
  1158. return {
  1159. title: 'General',
  1160. name: 'general',
  1161. items: makeItems(info)
  1162. };
  1163. };
  1164. var MainTab = {
  1165. makeTab: makeTab$1,
  1166. makeItems: makeItems
  1167. };
  1168. var makeTab = function (_info) {
  1169. var items = [{
  1170. type: 'dropzone',
  1171. name: 'fileinput'
  1172. }];
  1173. return {
  1174. title: 'Upload',
  1175. name: 'upload',
  1176. items: items
  1177. };
  1178. };
  1179. var UploadTab = { makeTab: makeTab };
  1180. var createState = function (info) {
  1181. return {
  1182. prevImage: ListUtils.findEntry(info.imageList, info.image.src),
  1183. prevAlt: info.image.alt,
  1184. open: true
  1185. };
  1186. };
  1187. var fromImageData = function (image) {
  1188. return {
  1189. src: {
  1190. value: image.src,
  1191. meta: {}
  1192. },
  1193. images: image.src,
  1194. alt: image.alt,
  1195. title: image.title,
  1196. dimensions: {
  1197. width: image["data-width"] || image.width,
  1198. height: image["data-height"] || image.height
  1199. },
  1200. classes: image.class,
  1201. caption: image.caption,
  1202. style: image.style,
  1203. vspace: image.vspace,
  1204. border: image.border,
  1205. hspace: image.hspace,
  1206. borderstyle: image.borderStyle,
  1207. fileinput: [],
  1208. isDecorative: image.isDecorative,
  1209. "data-id": image["data-id"],
  1210. "data-orgid": image["data-orgid"],
  1211. "data-width": image["data-width"],
  1212. "data-height": image["data-height"],
  1213. "data-filename": image["data-filename"],
  1214. "onerror": image["onerror"],
  1215. "data-prv": image["data-prv"] !== false && image["data-prv"] !== "false",
  1216. "base64enable": (image.src||'').substring( 0, 5 ) === 'data:'
  1217. };
  1218. };
  1219. var toImageData = function (data, removeEmptyAlt) {
  1220. return {
  1221. src: data.src.value,
  1222. alt: data.alt.length === 0 && removeEmptyAlt ? null : data.alt,
  1223. title: data.title,
  1224. // width: data.dimensions.width,
  1225. // height: data.dimensions.height,
  1226. class: data.classes,
  1227. style: data.style,
  1228. caption: data.caption,
  1229. hspace: data.hspace,
  1230. vspace: data.vspace,
  1231. border: data.border,
  1232. borderStyle: data.borderstyle,
  1233. isDecorative: data.isDecorative,
  1234. "data-id": data["data-id"],
  1235. "data-orgid": data["data-orgid"],
  1236. "data-width": data["data-width"],
  1237. "data-height": data["data-height"],
  1238. "data-filename": data["data-filename"],
  1239. "onerror": data["onerror"],
  1240. "data-prv": data["data-prv"]
  1241. };
  1242. };
  1243. var addPrependUrl2 = function (info, srcURL) {
  1244. if (!/^(?:[a-zA-Z]+:)?\/\//.test(srcURL)) {
  1245. return info.prependURL.bind(function (prependUrl) {
  1246. if (srcURL.substring(0, prependUrl.length) !== prependUrl) {
  1247. return Optional.some(prependUrl + srcURL);
  1248. }
  1249. return Optional.none();
  1250. });
  1251. }
  1252. return Optional.none();
  1253. };
  1254. var addPrependUrl = function (info, api) {
  1255. var data = api.getData();
  1256. addPrependUrl2(info, data.src.value).each(function (srcURL) {
  1257. api.setData({
  1258. src: {
  1259. value: srcURL,
  1260. meta: data.src.meta
  1261. }
  1262. });
  1263. });
  1264. };
  1265. var formFillFromMeta2 = function (info, data, meta) {
  1266. if (info.hasDescription && isString(meta.alt)) {
  1267. data.alt = meta.alt;
  1268. }
  1269. if (info.hasAccessibilityOptions) {
  1270. data.isDecorative = meta.isDecorative || data.isDecorative || false;
  1271. }
  1272. if (info.hasImageTitle && isString(meta.title)) {
  1273. data.title = meta.title;
  1274. }
  1275. if (info.hasDimensions) {
  1276. if (isString(meta.width)) {
  1277. data.dimensions.width = meta.width;
  1278. }
  1279. if (isString(meta.height)) {
  1280. data.dimensions.height = meta.height;
  1281. }
  1282. }
  1283. if (isString(meta.class)) {
  1284. ListUtils.findEntry(info.classList, meta.class).each(function (entry) {
  1285. data.classes = entry.value;
  1286. });
  1287. }
  1288. if (info.hasImageCaption) {
  1289. if (isBoolean(meta.caption)) {
  1290. data.caption = meta.caption;
  1291. }
  1292. }
  1293. if (info.hasAdvTab) {
  1294. if (isString(meta.style)) {
  1295. data.style = meta.style;
  1296. }
  1297. if (isString(meta.vspace)) {
  1298. data.vspace = meta.vspace;
  1299. }
  1300. if (isString(meta.border)) {
  1301. data.border = meta.border;
  1302. }
  1303. if (isString(meta.hspace)) {
  1304. data.hspace = meta.hspace;
  1305. }
  1306. if (isString(meta.borderstyle)) {
  1307. data.borderstyle = meta.borderstyle;
  1308. }
  1309. }
  1310. if (isString(meta["data-id"])) {
  1311. data["data-id"] = meta["data-id"];
  1312. }
  1313. if (isString(meta["data-orgid"])) {
  1314. data["data-orgid"] = meta["data-orgid"];
  1315. }
  1316. if (isString(meta["data-width"])) {
  1317. data["data-width"] = meta["data-width"];
  1318. }
  1319. if (isString(meta["data-height"])) {
  1320. data["data-height"] = meta["data-height"];
  1321. }
  1322. if (isString(meta["data-filename"])) {
  1323. data["data-filename"] = meta["data-filename"];
  1324. }
  1325. if (isString(meta["onerror"])) {
  1326. data["onerror"] = meta["onerror"];
  1327. }
  1328. if (isString(meta["data-prv"])) {
  1329. data["data-prv"] = meta["data-prv"] !== false && meta["data-prv"] !== "false";
  1330. }
  1331. };
  1332. var formFillFromMeta = function (info, api) {
  1333. var data = api.getData();
  1334. var meta = data.src.meta;
  1335. if (meta !== undefined) {
  1336. var newData = deepMerge({}, data);
  1337. formFillFromMeta2(info, newData, meta);
  1338. api.setData(newData);
  1339. }
  1340. };
  1341. var calculateImageSize = function (helpers, info, state, api) {
  1342. var data = api.getData();
  1343. var url = data.src.value;
  1344. var meta = data.src.meta || {};
  1345. if (!meta.width && !meta.height && info.hasDimensions) {
  1346. if (isNotEmpty(url)) {
  1347. helpers.imageSize(url).then(function (size) {
  1348. if (state.open) {
  1349. api.setData({ dimensions: size });
  1350. }
  1351. }).catch(function (e) {
  1352. return console.error(e);
  1353. });
  1354. } else {
  1355. api.setData({
  1356. dimensions: {
  1357. width: '',
  1358. height: ''
  1359. }
  1360. });
  1361. }
  1362. }
  1363. };
  1364. var updateImagesDropdown = function (info, state, api) {
  1365. var data = api.getData();
  1366. var image = ListUtils.findEntry(info.imageList, data.src.value);
  1367. state.prevImage = image;
  1368. api.setData({
  1369. images: image.map(function (entry) {
  1370. return entry.value;
  1371. }).getOr('')
  1372. });
  1373. };
  1374. var changeSrc = function (helpers, info, state, api) {
  1375. addPrependUrl(info, api);
  1376. formFillFromMeta(info, api);
  1377. calculateImageSize(helpers, info, state, api);
  1378. updateImagesDropdown(info, state, api);
  1379. };
  1380. var changeImages = function (helpers, info, state, api) {
  1381. var data = api.getData();
  1382. var image = ListUtils.findEntry(info.imageList, data.images);
  1383. image.each(function (img) {
  1384. var updateAlt = data.alt === '' || state.prevImage.map(function (image) {
  1385. return image.text === data.alt;
  1386. }).getOr(false);
  1387. if (updateAlt) {
  1388. if (img.value === '') {
  1389. api.setData({
  1390. src: img,
  1391. alt: state.prevAlt
  1392. });
  1393. } else {
  1394. api.setData({
  1395. src: img,
  1396. alt: img.text
  1397. });
  1398. }
  1399. } else {
  1400. api.setData({ src: img });
  1401. }
  1402. });
  1403. state.prevImage = image;
  1404. changeSrc(helpers, info, state, api);
  1405. };
  1406. var calcVSpace = function (css) {
  1407. var matchingTopBottom = css['margin-top'] && css['margin-bottom'] && css['margin-top'] === css['margin-bottom'];
  1408. return matchingTopBottom ? removePixelSuffix(String(css['margin-top'])) : '';
  1409. };
  1410. var calcHSpace = function (css) {
  1411. var matchingLeftRight = css['margin-right'] && css['margin-left'] && css['margin-right'] === css['margin-left'];
  1412. return matchingLeftRight ? removePixelSuffix(String(css['margin-right'])) : '';
  1413. };
  1414. var calcBorderWidth = function (css) {
  1415. return css['border-width'] ? removePixelSuffix(String(css['border-width'])) : '';
  1416. };
  1417. var calcBorderStyle = function (css) {
  1418. return css['border-style'] ? String(css['border-style']) : '';
  1419. };
  1420. var calcStyle = function (parseStyle, serializeStyle, css) {
  1421. return serializeStyle(parseStyle(serializeStyle(css)));
  1422. };
  1423. var changeStyle2 = function (parseStyle, serializeStyle, data) {
  1424. var css = mergeMargins(parseStyle(data.style));
  1425. var dataCopy = deepMerge({}, data);
  1426. dataCopy.vspace = calcVSpace(css);
  1427. dataCopy.hspace = calcHSpace(css);
  1428. dataCopy.border = calcBorderWidth(css);
  1429. dataCopy.borderstyle = calcBorderStyle(css);
  1430. dataCopy.style = calcStyle(parseStyle, serializeStyle, css);
  1431. return dataCopy;
  1432. };
  1433. var changeStyle = function (helpers, api) {
  1434. var data = api.getData();
  1435. var newData = changeStyle2(helpers.parseStyle, helpers.serializeStyle, data);
  1436. api.setData(newData);
  1437. };
  1438. var changeAStyle = function (helpers, info, api) {
  1439. var data = deepMerge(fromImageData(info.image), api.getData());
  1440. var style = getStyleValue(helpers.normalizeCss, toImageData(data, false));
  1441. api.setData({ style: style });
  1442. };
  1443. var changeFileInput = function (helpers, info, state, api) {
  1444. var data = api.getData();
  1445. api.block('Uploading image');
  1446. head(data.fileinput).fold(function () {
  1447. api.unblock();
  1448. }, function (file) {
  1449. var blobUri = URL.createObjectURL(file);
  1450. var finalize = function () {
  1451. api.unblock();
  1452. URL.revokeObjectURL(blobUri);
  1453. };
  1454. var updateSrcAndSwitchTab = function (url) {
  1455. api.setData({
  1456. src: {
  1457. value: url,
  1458. meta: {}
  1459. }
  1460. });
  1461. api.showTab('general');
  1462. changeSrc(helpers, info, state, api);
  1463. };
  1464. blobToDataUri(file).then(function (dataUrl) {
  1465. var blobInfo = helpers.createBlobCache(file, blobUri, dataUrl);
  1466. if (info.automaticUploads) {
  1467. helpers.uploadImage(blobInfo).then(function (result) {
  1468. updateSrcAndSwitchTab(result.url);
  1469. finalize();
  1470. }).catch(function (err) {
  1471. finalize();
  1472. helpers.alertErr(err);
  1473. });
  1474. } else {
  1475. helpers.addToBlobCache(blobInfo);
  1476. updateSrcAndSwitchTab(blobInfo.blobUri());
  1477. api.unblock();
  1478. }
  1479. });
  1480. });
  1481. };
  1482. var changeHandler = function (helpers, info, state) {
  1483. return function (api, evt) {
  1484. if (evt.name === 'src') {
  1485. changeSrc(helpers, info, state, api);
  1486. } else if (evt.name === 'images') {
  1487. changeImages(helpers, info, state, api);
  1488. } else if (evt.name === 'alt') {
  1489. state.prevAlt = api.getData().alt;
  1490. } else if (evt.name === 'style') {
  1491. changeStyle(helpers, api);
  1492. } else if (evt.name === 'vspace' || evt.name === 'hspace' || evt.name === 'border' || evt.name === 'borderstyle') {
  1493. changeAStyle(helpers, info, api);
  1494. } else if (evt.name === 'fileinput') {
  1495. changeFileInput(helpers, info, state, api);
  1496. } else if (evt.name === 'isDecorative') {
  1497. if (api.getData().isDecorative) {
  1498. api.disable('alt');
  1499. } else {
  1500. api.enable('alt');
  1501. }
  1502. }
  1503. };
  1504. };
  1505. var closeHandler = function (state) {
  1506. return function () {
  1507. state.open = false;
  1508. tinymce.activeEditor.activeO2ImageDialog = null;
  1509. };
  1510. };
  1511. var makeDialogBody = function (info) {
  1512. if (info.hasAdvTab || info.hasUploadUrl || info.hasUploadHandler) {
  1513. var tabPanel = {
  1514. type: 'tabpanel',
  1515. tabs: flatten([
  1516. [MainTab.makeTab(info)],
  1517. info.hasAdvTab ? [AdvTab.makeTab(info)] : [],
  1518. info.hasUploadTab && (info.hasUploadUrl || info.hasUploadHandler) ? [UploadTab.makeTab(info)] : []
  1519. ])
  1520. };
  1521. return tabPanel;
  1522. } else {
  1523. var panel = {
  1524. type: 'panel',
  1525. items: MainTab.makeItems(info)
  1526. };
  1527. return panel;
  1528. }
  1529. };
  1530. var makeDialog = function (helpers) {
  1531. return function (info) {
  1532. var state = createState(info);
  1533. return {
  1534. title: 'Insert/Edit Image',
  1535. size: 'normal',
  1536. body: makeDialogBody(info),
  1537. buttons: [
  1538. {
  1539. type: 'cancel',
  1540. name: 'cancel',
  1541. text: 'Cancel'
  1542. },
  1543. {
  1544. type: 'submit',
  1545. name: 'save',
  1546. text: 'Save',
  1547. primary: true
  1548. }
  1549. ],
  1550. initialData: fromImageData(info.image),
  1551. onSubmit: helpers.onSubmit(info),
  1552. onChange: changeHandler(helpers, info, state),
  1553. onClose: closeHandler(state),
  1554. onTabChange: function(api, details){
  1555. tinymce.dom.DomQuery(".tox-lock").css("display","none");
  1556. },
  1557. onAction: function(api, details){
  1558. }
  1559. };
  1560. };
  1561. };
  1562. var replaceStyles = function(str, object){
  1563. /*object 参数 {
  1564. "width" : "100px", //添加或替换
  1565. "height": "" //删除
  1566. }*/
  1567. var newArray = [];
  1568. Object.each(object, function (value, key) {
  1569. if(value)newArray.push( key + ":" + value )
  1570. });
  1571. var styles = str.split(/\s*;\s*/gi);
  1572. for(var j=0; j<styles.length; j++){
  1573. var arr = styles[j].split(/\s*:\s*/gi);
  1574. if( !object.hasOwnProperty( arr[0].toLowerCase() ) ){
  1575. newArray.push( styles[j] );
  1576. }
  1577. }
  1578. return newArray.join(";");
  1579. };
  1580. var submitHandler = function (editor) {
  1581. return function (info) {
  1582. return function (api) {
  1583. debugger;
  1584. var data = deepMerge(fromImageData(info.image), api.getData());
  1585. var apiData = api.getData();
  1586. if( apiData.src && apiData.src.meta ){
  1587. var meta = apiData.src.meta;
  1588. for( var key in meta ){
  1589. //if( !data[key] && meta[key] ){
  1590. data[key] = meta[key];
  1591. //}
  1592. }
  1593. }
  1594. if( data.dimensions && data.dimensions.width ){
  1595. data["data-width"] = data.dimensions.width;
  1596. data["style"] = replaceStyles( data["style"] || "", {"width": data["data-width"]+"px"} );
  1597. data.dimensions.width = "";
  1598. }
  1599. if( data.dimensions.height ){
  1600. data["data-height"] = data.dimensions.height;
  1601. data.dimensions.height = "";
  1602. }
  1603. data["data-prv"] = (data["data-prv"] !== false && data["data-prv"] !== "false") ? "true" : "false";
  1604. editor.execCommand('mceUpdateImage', false, toImageData(data, info.hasAccessibilityOptions));
  1605. editor.editorUpload.uploadImagesAuto();
  1606. api.close();
  1607. };
  1608. };
  1609. };
  1610. var imageSize = function (editor) {
  1611. return function (url) {
  1612. return getImageSize(editor.documentBaseURI.toAbsolute(url)).then(function (dimensions) {
  1613. return {
  1614. width: String(dimensions.width),
  1615. height: String(dimensions.height)
  1616. };
  1617. });
  1618. };
  1619. };
  1620. var createBlobCache = function (editor) {
  1621. return function (file, blobUri, dataUrl) {
  1622. return editor.editorUpload.blobCache.create({
  1623. blob: file,
  1624. blobUri: blobUri,
  1625. name: file.name ? file.name.replace(/\.[^\.]+$/, '') : null,
  1626. filename: file.name,
  1627. base64: dataUrl.split(',')[1]
  1628. });
  1629. };
  1630. };
  1631. var addToBlobCache = function (editor) {
  1632. return function (blobInfo) {
  1633. editor.editorUpload.blobCache.add(blobInfo);
  1634. };
  1635. };
  1636. var alertErr = function (editor) {
  1637. return function (message) {
  1638. editor.windowManager.alert(message);
  1639. };
  1640. };
  1641. var normalizeCss = function (editor) {
  1642. return function (cssText) {
  1643. return normalizeCss$1(editor, cssText);
  1644. };
  1645. };
  1646. var parseStyle = function (editor) {
  1647. return function (cssText) {
  1648. return editor.dom.parseStyle(cssText);
  1649. };
  1650. };
  1651. var serializeStyle = function (editor) {
  1652. return function (stylesArg, name) {
  1653. return editor.dom.serializeStyle(stylesArg, name);
  1654. };
  1655. };
  1656. var uploadImage = function (editor) {
  1657. return function (blobInfo) {
  1658. return global$1(editor).upload([blobInfo], false).then(function (results) {
  1659. if (results.length === 0) {
  1660. return global$3.reject('Failed to upload image');
  1661. } else if (results[0].status === false) {
  1662. return global$3.reject(results[0].error.message);
  1663. } else {
  1664. return results[0];
  1665. }
  1666. });
  1667. };
  1668. };
  1669. var Dialog = function (editor) {
  1670. var helpers = {
  1671. onSubmit: submitHandler(editor),
  1672. imageSize: imageSize(editor),
  1673. addToBlobCache: addToBlobCache(editor),
  1674. createBlobCache: createBlobCache(editor),
  1675. alertErr: alertErr(editor),
  1676. normalizeCss: normalizeCss(editor),
  1677. parseStyle: parseStyle(editor),
  1678. serializeStyle: serializeStyle(editor),
  1679. uploadImage: uploadImage(editor)
  1680. };
  1681. var open = function () {
  1682. collect(editor).then(makeDialog(helpers)).then(function (arg) {
  1683. tinymce.activeEditor.activeO2ImageDialog = editor.windowManager.open(arg);
  1684. tinymce.dom.DomQuery(".tox-lock").css("display","none");
  1685. });
  1686. };
  1687. return { open: open };
  1688. };
  1689. var register$1 = function (editor) {
  1690. editor.addCommand('mceImage', Dialog(editor).open);
  1691. editor.addCommand('mceUpdateImage', function (_ui, data) {
  1692. editor.undoManager.transact(function () {
  1693. return insertOrUpdateImage(editor, data);
  1694. });
  1695. });
  1696. };
  1697. var hasImageClass = function (node) {
  1698. var className = node.attr('class');
  1699. return className && /\bimage\b/.test(className);
  1700. };
  1701. var toggleContentEditableState = function (state) {
  1702. return function (nodes) {
  1703. var i = nodes.length;
  1704. var toggleContentEditable = function (node) {
  1705. node.attr('contenteditable', state ? 'true' : null);
  1706. };
  1707. while (i--) {
  1708. var node = nodes[i];
  1709. if (hasImageClass(node)) {
  1710. node.attr('contenteditable', state ? 'false' : null);
  1711. global.each(node.getAll('figcaption'), toggleContentEditable);
  1712. }
  1713. }
  1714. };
  1715. };
  1716. var setup = function (editor) {
  1717. editor.on('PreInit', function () {
  1718. editor.parser.addNodeFilter('figure', toggleContentEditableState(true));
  1719. editor.serializer.addNodeFilter('figure', toggleContentEditableState(false));
  1720. });
  1721. };
  1722. var register = function (editor) {
  1723. editor.ui.registry.addToggleButton('o2image', {
  1724. icon: 'image',
  1725. tooltip: 'Insert/edit image',
  1726. onAction: Dialog(editor).open,
  1727. onSetup: function (buttonApi) {
  1728. return editor.selection.selectorChangedWithUnbind('img:not([data-mce-object],[data-mce-placeholder]),figure.image', buttonApi.setActive).unbind;
  1729. }
  1730. });
  1731. editor.ui.registry.addMenuItem('image', {
  1732. icon: 'image',
  1733. text: 'Image...',
  1734. onAction: Dialog(editor).open
  1735. });
  1736. editor.ui.registry.addContextMenu('image', {
  1737. update: function (element) {
  1738. return isFigure(element) || isImage(element) && !isPlaceholderImage(element) ? ['image'] : [];
  1739. }
  1740. });
  1741. };
  1742. function Plugin () {
  1743. global$5.add('o2image', function (editor) {
  1744. setup(editor);
  1745. register(editor);
  1746. register$1(editor);
  1747. });
  1748. }
  1749. Plugin();
  1750. }());