plugin.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  1. /**
  2. * TinyMCE version 8.0.2 (2025-08-14)
  3. */
  4. (function () {
  5. 'use strict';
  6. var global$1 = tinymce.util.Tools.resolve('tinymce.PluginManager');
  7. /* eslint-disable @typescript-eslint/no-wrapper-object-types */
  8. const eq = (t) => (a) => t === a;
  9. const isUndefined = eq(undefined);
  10. const isNullable = (a) => a === null || a === undefined;
  11. const isNonNullable = (a) => !isNullable(a);
  12. const constant = (value) => {
  13. return () => {
  14. return value;
  15. };
  16. };
  17. const never = constant(false);
  18. /**
  19. * The `Optional` type represents a value (of any type) that potentially does
  20. * not exist. Any `Optional<T>` can either be a `Some<T>` (in which case the
  21. * value does exist) or a `None` (in which case the value does not exist). This
  22. * module defines a whole lot of FP-inspired utility functions for dealing with
  23. * `Optional` objects.
  24. *
  25. * Comparison with null or undefined:
  26. * - We don't get fancy null coalescing operators with `Optional`
  27. * - We do get fancy helper functions with `Optional`
  28. * - `Optional` support nesting, and allow for the type to still be nullable (or
  29. * another `Optional`)
  30. * - There is no option to turn off strict-optional-checks like there is for
  31. * strict-null-checks
  32. */
  33. class Optional {
  34. // The internal representation has a `tag` and a `value`, but both are
  35. // private: able to be console.logged, but not able to be accessed by code
  36. constructor(tag, value) {
  37. this.tag = tag;
  38. this.value = value;
  39. }
  40. // --- Identities ---
  41. /**
  42. * Creates a new `Optional<T>` that **does** contain a value.
  43. */
  44. static some(value) {
  45. return new Optional(true, value);
  46. }
  47. /**
  48. * Create a new `Optional<T>` that **does not** contain a value. `T` can be
  49. * any type because we don't actually have a `T`.
  50. */
  51. static none() {
  52. return Optional.singletonNone;
  53. }
  54. /**
  55. * Perform a transform on an `Optional` type. Regardless of whether this
  56. * `Optional` contains a value or not, `fold` will return a value of type `U`.
  57. * If this `Optional` does not contain a value, the `U` will be created by
  58. * calling `onNone`. If this `Optional` does contain a value, the `U` will be
  59. * created by calling `onSome`.
  60. *
  61. * For the FP enthusiasts in the room, this function:
  62. * 1. Could be used to implement all of the functions below
  63. * 2. Forms a catamorphism
  64. */
  65. fold(onNone, onSome) {
  66. if (this.tag) {
  67. return onSome(this.value);
  68. }
  69. else {
  70. return onNone();
  71. }
  72. }
  73. /**
  74. * Determine if this `Optional` object contains a value.
  75. */
  76. isSome() {
  77. return this.tag;
  78. }
  79. /**
  80. * Determine if this `Optional` object **does not** contain a value.
  81. */
  82. isNone() {
  83. return !this.tag;
  84. }
  85. // --- Functor (name stolen from Haskell / maths) ---
  86. /**
  87. * Perform a transform on an `Optional` object, **if** there is a value. If
  88. * you provide a function to turn a T into a U, this is the function you use
  89. * to turn an `Optional<T>` into an `Optional<U>`. If this **does** contain
  90. * a value then the output will also contain a value (that value being the
  91. * output of `mapper(this.value)`), and if this **does not** contain a value
  92. * then neither will the output.
  93. */
  94. map(mapper) {
  95. if (this.tag) {
  96. return Optional.some(mapper(this.value));
  97. }
  98. else {
  99. return Optional.none();
  100. }
  101. }
  102. // --- Monad (name stolen from Haskell / maths) ---
  103. /**
  104. * Perform a transform on an `Optional` object, **if** there is a value.
  105. * Unlike `map`, here the transform itself also returns an `Optional`.
  106. */
  107. bind(binder) {
  108. if (this.tag) {
  109. return binder(this.value);
  110. }
  111. else {
  112. return Optional.none();
  113. }
  114. }
  115. // --- Traversable (name stolen from Haskell / maths) ---
  116. /**
  117. * For a given predicate, this function finds out if there **exists** a value
  118. * inside this `Optional` object that meets the predicate. In practice, this
  119. * means that for `Optional`s that do not contain a value it returns false (as
  120. * no predicate-meeting value exists).
  121. */
  122. exists(predicate) {
  123. return this.tag && predicate(this.value);
  124. }
  125. /**
  126. * For a given predicate, this function finds out if **all** the values inside
  127. * this `Optional` object meet the predicate. In practice, this means that
  128. * for `Optional`s that do not contain a value it returns true (as all 0
  129. * objects do meet the predicate).
  130. */
  131. forall(predicate) {
  132. return !this.tag || predicate(this.value);
  133. }
  134. filter(predicate) {
  135. if (!this.tag || predicate(this.value)) {
  136. return this;
  137. }
  138. else {
  139. return Optional.none();
  140. }
  141. }
  142. // --- Getters ---
  143. /**
  144. * Get the value out of the inside of the `Optional` object, using a default
  145. * `replacement` value if the provided `Optional` object does not contain a
  146. * value.
  147. */
  148. getOr(replacement) {
  149. return this.tag ? this.value : replacement;
  150. }
  151. /**
  152. * Get the value out of the inside of the `Optional` object, using a default
  153. * `replacement` value if the provided `Optional` object does not contain a
  154. * value. Unlike `getOr`, in this method the `replacement` object is also
  155. * `Optional` - meaning that this method will always return an `Optional`.
  156. */
  157. or(replacement) {
  158. return this.tag ? this : replacement;
  159. }
  160. /**
  161. * Get the value out of the inside of the `Optional` object, using a default
  162. * `replacement` value if the provided `Optional` object does not contain a
  163. * value. Unlike `getOr`, in this method the `replacement` value is
  164. * "thunked" - that is to say that you don't pass a value to `getOrThunk`, you
  165. * pass a function which (if called) will **return** the `value` you want to
  166. * use.
  167. */
  168. getOrThunk(thunk) {
  169. return this.tag ? this.value : thunk();
  170. }
  171. /**
  172. * Get the value out of the inside of the `Optional` object, using a default
  173. * `replacement` value if the provided Optional object does not contain a
  174. * value.
  175. *
  176. * Unlike `or`, in this method the `replacement` value is "thunked" - that is
  177. * to say that you don't pass a value to `orThunk`, you pass a function which
  178. * (if called) will **return** the `value` you want to use.
  179. *
  180. * Unlike `getOrThunk`, in this method the `replacement` value is also
  181. * `Optional`, meaning that this method will always return an `Optional`.
  182. */
  183. orThunk(thunk) {
  184. return this.tag ? this : thunk();
  185. }
  186. /**
  187. * Get the value out of the inside of the `Optional` object, throwing an
  188. * exception if the provided `Optional` object does not contain a value.
  189. *
  190. * WARNING:
  191. * You should only be using this function if you know that the `Optional`
  192. * object **is not** empty (otherwise you're throwing exceptions in production
  193. * code, which is bad).
  194. *
  195. * In tests this is more acceptable.
  196. *
  197. * Prefer other methods to this, such as `.each`.
  198. */
  199. getOrDie(message) {
  200. if (!this.tag) {
  201. throw new Error(message !== null && message !== void 0 ? message : 'Called getOrDie on None');
  202. }
  203. else {
  204. return this.value;
  205. }
  206. }
  207. // --- Interop with null and undefined ---
  208. /**
  209. * Creates an `Optional` value from a nullable (or undefined-able) input.
  210. * Null, or undefined, is converted to `None`, and anything else is converted
  211. * to `Some`.
  212. */
  213. static from(value) {
  214. return isNonNullable(value) ? Optional.some(value) : Optional.none();
  215. }
  216. /**
  217. * Converts an `Optional` to a nullable type, by getting the value if it
  218. * exists, or returning `null` if it does not.
  219. */
  220. getOrNull() {
  221. return this.tag ? this.value : null;
  222. }
  223. /**
  224. * Converts an `Optional` to an undefined-able type, by getting the value if
  225. * it exists, or returning `undefined` if it does not.
  226. */
  227. getOrUndefined() {
  228. return this.value;
  229. }
  230. // --- Utilities ---
  231. /**
  232. * If the `Optional` contains a value, perform an action on that value.
  233. * Unlike the rest of the methods on this type, `.each` has side-effects. If
  234. * you want to transform an `Optional<T>` **into** something, then this is not
  235. * the method for you. If you want to use an `Optional<T>` to **do**
  236. * something, then this is the method for you - provided you're okay with not
  237. * doing anything in the case where the `Optional` doesn't have a value inside
  238. * it. If you're not sure whether your use-case fits into transforming
  239. * **into** something or **doing** something, check whether it has a return
  240. * value. If it does, you should be performing a transform.
  241. */
  242. each(worker) {
  243. if (this.tag) {
  244. worker(this.value);
  245. }
  246. }
  247. /**
  248. * Turn the `Optional` object into an array that contains all of the values
  249. * stored inside the `Optional`. In practice, this means the output will have
  250. * either 0 or 1 elements.
  251. */
  252. toArray() {
  253. return this.tag ? [this.value] : [];
  254. }
  255. /**
  256. * Turn the `Optional` object into a string for debugging or printing. Not
  257. * recommended for production code, but good for debugging. Also note that
  258. * these days an `Optional` object can be logged to the console directly, and
  259. * its inner value (if it exists) will be visible.
  260. */
  261. toString() {
  262. return this.tag ? `some(${this.value})` : 'none()';
  263. }
  264. }
  265. // Sneaky optimisation: every instance of Optional.none is identical, so just
  266. // reuse the same object
  267. Optional.singletonNone = new Optional(false);
  268. const findUntil = (xs, pred, until) => {
  269. for (let i = 0, len = xs.length; i < len; i++) {
  270. const x = xs[i];
  271. if (pred(x, i)) {
  272. return Optional.some(x);
  273. }
  274. else if (until(x, i)) {
  275. break;
  276. }
  277. }
  278. return Optional.none();
  279. };
  280. const find$1 = (xs, pred) => {
  281. return findUntil(xs, pred, never);
  282. };
  283. const findMap = (arr, f) => {
  284. for (let i = 0; i < arr.length; i++) {
  285. const r = f(arr[i], i);
  286. if (r.isSome()) {
  287. return r;
  288. }
  289. }
  290. return Optional.none();
  291. };
  292. const contains = (str, substr, start = 0, end) => {
  293. const idx = str.indexOf(substr, start);
  294. if (idx !== -1) {
  295. return isUndefined(end) ? true : idx + substr.length <= end;
  296. }
  297. else {
  298. return false;
  299. }
  300. };
  301. const cached = (f) => {
  302. let called = false;
  303. let r;
  304. return (...args) => {
  305. if (!called) {
  306. called = true;
  307. r = f.apply(null, args);
  308. }
  309. return r;
  310. };
  311. };
  312. const DeviceType = (os, browser, userAgent, mediaMatch) => {
  313. const isiPad = os.isiOS() && /ipad/i.test(userAgent) === true;
  314. const isiPhone = os.isiOS() && !isiPad;
  315. const isMobile = os.isiOS() || os.isAndroid();
  316. const isTouch = isMobile || mediaMatch('(pointer:coarse)');
  317. const isTablet = isiPad || !isiPhone && isMobile && mediaMatch('(min-device-width:768px)');
  318. const isPhone = isiPhone || isMobile && !isTablet;
  319. const iOSwebview = browser.isSafari() && os.isiOS() && /safari/i.test(userAgent) === false;
  320. const isDesktop = !isPhone && !isTablet && !iOSwebview;
  321. return {
  322. isiPad: constant(isiPad),
  323. isiPhone: constant(isiPhone),
  324. isTablet: constant(isTablet),
  325. isPhone: constant(isPhone),
  326. isTouch: constant(isTouch),
  327. isAndroid: os.isAndroid,
  328. isiOS: os.isiOS,
  329. isWebView: constant(iOSwebview),
  330. isDesktop: constant(isDesktop)
  331. };
  332. };
  333. const firstMatch = (regexes, s) => {
  334. for (let i = 0; i < regexes.length; i++) {
  335. const x = regexes[i];
  336. if (x.test(s)) {
  337. return x;
  338. }
  339. }
  340. return undefined;
  341. };
  342. const find = (regexes, agent) => {
  343. const r = firstMatch(regexes, agent);
  344. if (!r) {
  345. return { major: 0, minor: 0 };
  346. }
  347. const group = (i) => {
  348. return Number(agent.replace(r, '$' + i));
  349. };
  350. return nu$2(group(1), group(2));
  351. };
  352. const detect$3 = (versionRegexes, agent) => {
  353. const cleanedAgent = String(agent).toLowerCase();
  354. if (versionRegexes.length === 0) {
  355. return unknown$2();
  356. }
  357. return find(versionRegexes, cleanedAgent);
  358. };
  359. const unknown$2 = () => {
  360. return nu$2(0, 0);
  361. };
  362. const nu$2 = (major, minor) => {
  363. return { major, minor };
  364. };
  365. const Version = {
  366. nu: nu$2,
  367. detect: detect$3,
  368. unknown: unknown$2
  369. };
  370. const detectBrowser$1 = (browsers, userAgentData) => {
  371. return findMap(userAgentData.brands, (uaBrand) => {
  372. const lcBrand = uaBrand.brand.toLowerCase();
  373. return find$1(browsers, (browser) => { var _a; return lcBrand === ((_a = browser.brand) === null || _a === void 0 ? void 0 : _a.toLowerCase()); })
  374. .map((info) => ({
  375. current: info.name,
  376. version: Version.nu(parseInt(uaBrand.version, 10), 0)
  377. }));
  378. });
  379. };
  380. const detect$2 = (candidates, userAgent) => {
  381. const agent = String(userAgent).toLowerCase();
  382. return find$1(candidates, (candidate) => {
  383. return candidate.search(agent);
  384. });
  385. };
  386. // They (browser and os) are the same at the moment, but they might
  387. // not stay that way.
  388. const detectBrowser = (browsers, userAgent) => {
  389. return detect$2(browsers, userAgent).map((browser) => {
  390. const version = Version.detect(browser.versionRegexes, userAgent);
  391. return {
  392. current: browser.name,
  393. version
  394. };
  395. });
  396. };
  397. const detectOs = (oses, userAgent) => {
  398. return detect$2(oses, userAgent).map((os) => {
  399. const version = Version.detect(os.versionRegexes, userAgent);
  400. return {
  401. current: os.name,
  402. version
  403. };
  404. });
  405. };
  406. const normalVersionRegex = /.*?version\/\ ?([0-9]+)\.([0-9]+).*/;
  407. const checkContains = (target) => {
  408. return (uastring) => {
  409. return contains(uastring, target);
  410. };
  411. };
  412. const browsers = [
  413. // This is legacy Edge
  414. {
  415. name: 'Edge',
  416. versionRegexes: [/.*?edge\/ ?([0-9]+)\.([0-9]+)$/],
  417. search: (uastring) => {
  418. return contains(uastring, 'edge/') && contains(uastring, 'chrome') && contains(uastring, 'safari') && contains(uastring, 'applewebkit');
  419. }
  420. },
  421. // This is Google Chrome and Chromium Edge
  422. {
  423. name: 'Chromium',
  424. brand: 'Chromium',
  425. versionRegexes: [/.*?chrome\/([0-9]+)\.([0-9]+).*/, normalVersionRegex],
  426. search: (uastring) => {
  427. return contains(uastring, 'chrome') && !contains(uastring, 'chromeframe');
  428. }
  429. },
  430. {
  431. name: 'IE',
  432. versionRegexes: [/.*?msie\ ?([0-9]+)\.([0-9]+).*/, /.*?rv:([0-9]+)\.([0-9]+).*/],
  433. search: (uastring) => {
  434. return contains(uastring, 'msie') || contains(uastring, 'trident');
  435. }
  436. },
  437. // INVESTIGATE: Is this still the Opera user agent?
  438. {
  439. name: 'Opera',
  440. versionRegexes: [normalVersionRegex, /.*?opera\/([0-9]+)\.([0-9]+).*/],
  441. search: checkContains('opera')
  442. },
  443. {
  444. name: 'Firefox',
  445. versionRegexes: [/.*?firefox\/\ ?([0-9]+)\.([0-9]+).*/],
  446. search: checkContains('firefox')
  447. },
  448. {
  449. name: 'Safari',
  450. versionRegexes: [normalVersionRegex, /.*?cpu os ([0-9]+)_([0-9]+).*/],
  451. search: (uastring) => {
  452. return (contains(uastring, 'safari') || contains(uastring, 'mobile/')) && contains(uastring, 'applewebkit');
  453. }
  454. }
  455. ];
  456. const oses = [
  457. {
  458. name: 'Windows',
  459. search: checkContains('win'),
  460. versionRegexes: [/.*?windows\ nt\ ?([0-9]+)\.([0-9]+).*/]
  461. },
  462. {
  463. name: 'iOS',
  464. search: (uastring) => {
  465. return contains(uastring, 'iphone') || contains(uastring, 'ipad');
  466. },
  467. versionRegexes: [/.*?version\/\ ?([0-9]+)\.([0-9]+).*/, /.*cpu os ([0-9]+)_([0-9]+).*/, /.*cpu iphone os ([0-9]+)_([0-9]+).*/]
  468. },
  469. {
  470. name: 'Android',
  471. search: checkContains('android'),
  472. versionRegexes: [/.*?android\ ?([0-9]+)\.([0-9]+).*/]
  473. },
  474. {
  475. name: 'macOS',
  476. search: checkContains('mac os x'),
  477. versionRegexes: [/.*?mac\ os\ x\ ?([0-9]+)_([0-9]+).*/]
  478. },
  479. {
  480. name: 'Linux',
  481. search: checkContains('linux'),
  482. versionRegexes: []
  483. },
  484. { name: 'Solaris',
  485. search: checkContains('sunos'),
  486. versionRegexes: []
  487. },
  488. {
  489. name: 'FreeBSD',
  490. search: checkContains('freebsd'),
  491. versionRegexes: []
  492. },
  493. {
  494. name: 'ChromeOS',
  495. search: checkContains('cros'),
  496. versionRegexes: [/.*?chrome\/([0-9]+)\.([0-9]+).*/]
  497. }
  498. ];
  499. const PlatformInfo = {
  500. browsers: constant(browsers),
  501. oses: constant(oses)
  502. };
  503. const edge = 'Edge';
  504. const chromium = 'Chromium';
  505. const ie = 'IE';
  506. const opera = 'Opera';
  507. const firefox = 'Firefox';
  508. const safari = 'Safari';
  509. const unknown$1 = () => {
  510. return nu$1({
  511. current: undefined,
  512. version: Version.unknown()
  513. });
  514. };
  515. const nu$1 = (info) => {
  516. const current = info.current;
  517. const version = info.version;
  518. const isBrowser = (name) => () => current === name;
  519. return {
  520. current,
  521. version,
  522. isEdge: isBrowser(edge),
  523. isChromium: isBrowser(chromium),
  524. // NOTE: isIe just looks too weird
  525. isIE: isBrowser(ie),
  526. isOpera: isBrowser(opera),
  527. isFirefox: isBrowser(firefox),
  528. isSafari: isBrowser(safari)
  529. };
  530. };
  531. const Browser = {
  532. unknown: unknown$1,
  533. nu: nu$1,
  534. edge: constant(edge),
  535. chromium: constant(chromium),
  536. ie: constant(ie),
  537. opera: constant(opera),
  538. firefox: constant(firefox),
  539. safari: constant(safari)
  540. };
  541. const windows = 'Windows';
  542. const ios = 'iOS';
  543. const android = 'Android';
  544. const linux = 'Linux';
  545. const macos = 'macOS';
  546. const solaris = 'Solaris';
  547. const freebsd = 'FreeBSD';
  548. const chromeos = 'ChromeOS';
  549. // Though there is a bit of dupe with this and Browser, trying to
  550. // reuse code makes it much harder to follow and change.
  551. const unknown = () => {
  552. return nu({
  553. current: undefined,
  554. version: Version.unknown()
  555. });
  556. };
  557. const nu = (info) => {
  558. const current = info.current;
  559. const version = info.version;
  560. const isOS = (name) => () => current === name;
  561. return {
  562. current,
  563. version,
  564. isWindows: isOS(windows),
  565. // TODO: Fix capitalisation
  566. isiOS: isOS(ios),
  567. isAndroid: isOS(android),
  568. isMacOS: isOS(macos),
  569. isLinux: isOS(linux),
  570. isSolaris: isOS(solaris),
  571. isFreeBSD: isOS(freebsd),
  572. isChromeOS: isOS(chromeos)
  573. };
  574. };
  575. const OperatingSystem = {
  576. unknown,
  577. nu,
  578. windows: constant(windows),
  579. ios: constant(ios),
  580. android: constant(android),
  581. linux: constant(linux),
  582. macos: constant(macos),
  583. solaris: constant(solaris),
  584. freebsd: constant(freebsd),
  585. chromeos: constant(chromeos)
  586. };
  587. const detect$1 = (userAgent, userAgentDataOpt, mediaMatch) => {
  588. const browsers = PlatformInfo.browsers();
  589. const oses = PlatformInfo.oses();
  590. const browser = userAgentDataOpt.bind((userAgentData) => detectBrowser$1(browsers, userAgentData))
  591. .orThunk(() => detectBrowser(browsers, userAgent))
  592. .fold(Browser.unknown, Browser.nu);
  593. const os = detectOs(oses, userAgent).fold(OperatingSystem.unknown, OperatingSystem.nu);
  594. const deviceType = DeviceType(os, browser, userAgent, mediaMatch);
  595. return {
  596. browser,
  597. os,
  598. deviceType
  599. };
  600. };
  601. const PlatformDetection = {
  602. detect: detect$1
  603. };
  604. const mediaMatch = (query) => window.matchMedia(query).matches;
  605. // IMPORTANT: Must be in a thunk, otherwise rollup thinks calling this immediately
  606. // causes side effects and won't tree shake this away
  607. // Note: navigator.userAgentData is not part of the native typescript types yet
  608. let platform = cached(() => PlatformDetection.detect(window.navigator.userAgent, Optional.from((window.navigator.userAgentData)), mediaMatch));
  609. const detect = () => platform();
  610. const isMacOS = () => detect().os.isMacOS();
  611. const isiOS = () => detect().os.isiOS();
  612. const getPreventClicksOnLinksScript = () => {
  613. const isMacOSOrIOS = isMacOS() || isiOS();
  614. const fn = (isMacOSOrIOS) => {
  615. document.addEventListener('click', (e) => {
  616. for (let elm = e.target; elm; elm = elm.parentNode) {
  617. if (elm.nodeName === 'A') {
  618. const anchor = elm;
  619. const href = anchor.getAttribute('href');
  620. if (href && href.startsWith('#')) {
  621. e.preventDefault();
  622. const targetElement = document.getElementById(href.substring(1));
  623. if (targetElement) {
  624. targetElement.scrollIntoView({ behavior: 'smooth' });
  625. }
  626. return;
  627. }
  628. const isMetaKeyPressed = isMacOSOrIOS ? e.metaKey : e.ctrlKey && !e.altKey;
  629. if (!isMetaKeyPressed) {
  630. e.preventDefault();
  631. }
  632. }
  633. }
  634. }, false);
  635. };
  636. return `<script>(${fn.toString()})(${isMacOSOrIOS})</script>`;
  637. };
  638. var global = tinymce.util.Tools.resolve('tinymce.util.Tools');
  639. const option = (name) => (editor) => editor.options.get(name);
  640. const getContentStyle = option('content_style');
  641. const shouldUseContentCssCors = option('content_css_cors');
  642. const getBodyClass = option('body_class');
  643. const getBodyId = option('body_id');
  644. const getPreviewHtml = (editor) => {
  645. var _a;
  646. let headHtml = '';
  647. const encode = editor.dom.encode;
  648. const contentStyle = (_a = getContentStyle(editor)) !== null && _a !== void 0 ? _a : '';
  649. headHtml += `<base href="${encode(editor.documentBaseURI.getURI())}">`;
  650. const cors = shouldUseContentCssCors(editor) ? ' crossorigin="anonymous"' : '';
  651. global.each(editor.contentCSS, (url) => {
  652. headHtml += '<link type="text/css" rel="stylesheet" href="' + encode(editor.documentBaseURI.toAbsolute(url)) + '"' + cors + '>';
  653. });
  654. if (contentStyle) {
  655. headHtml += '<style type="text/css">' + contentStyle + '</style>';
  656. }
  657. const bodyId = getBodyId(editor);
  658. const bodyClass = getBodyClass(editor);
  659. const directionality = editor.getBody().dir;
  660. const dirAttr = directionality ? ' dir="' + encode(directionality) + '"' : '';
  661. const previewHtml = ('<!DOCTYPE html>' +
  662. '<html>' +
  663. '<head>' +
  664. headHtml +
  665. '</head>' +
  666. '<body id="' + encode(bodyId) + '" class="mce-content-body ' + encode(bodyClass) + '"' + dirAttr + '>' +
  667. editor.getContent() +
  668. getPreventClicksOnLinksScript() +
  669. '</body>' +
  670. '</html>');
  671. return previewHtml;
  672. };
  673. const open = (editor) => {
  674. const content = getPreviewHtml(editor);
  675. const dataApi = editor.windowManager.open({
  676. title: 'Preview',
  677. size: 'large',
  678. body: {
  679. type: 'panel',
  680. items: [
  681. {
  682. name: 'preview',
  683. type: 'iframe',
  684. sandboxed: true,
  685. transparent: false
  686. }
  687. ]
  688. },
  689. buttons: [
  690. {
  691. type: 'cancel',
  692. name: 'close',
  693. text: 'Close',
  694. primary: true
  695. }
  696. ],
  697. initialData: {
  698. preview: content
  699. }
  700. });
  701. // Focus the close button, as by default the first element in the body is selected
  702. // which we don't want to happen here since the body only has the iframe content
  703. dataApi.focus('close');
  704. };
  705. const register$1 = (editor) => {
  706. editor.addCommand('mcePreview', () => {
  707. open(editor);
  708. });
  709. };
  710. const register = (editor) => {
  711. const onAction = () => editor.execCommand('mcePreview');
  712. editor.ui.registry.addButton('preview', {
  713. icon: 'preview',
  714. tooltip: 'Preview',
  715. onAction,
  716. context: 'any'
  717. });
  718. editor.ui.registry.addMenuItem('preview', {
  719. icon: 'preview',
  720. text: 'Preview',
  721. onAction,
  722. context: 'any'
  723. });
  724. };
  725. var Plugin = () => {
  726. global$1.add('preview', (editor) => {
  727. register$1(editor);
  728. register(editor);
  729. });
  730. };
  731. Plugin();
  732. /** *****
  733. * DO NOT EXPORT ANYTHING
  734. *
  735. * IF YOU DO ROLLUP WILL LEAVE A GLOBAL ON THE PAGE
  736. *******/
  737. })();