tinymce_plugins_image.js 55 KB

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