plugin.js 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374
  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.10.2 (2021-11-17)
  8. */
  9. (function () {
  10. 'use strict';
  11. var Cell = function (initial) {
  12. var value = initial;
  13. var get = function () {
  14. return value;
  15. };
  16. var set = function (v) {
  17. value = v;
  18. };
  19. return {
  20. get: get,
  21. set: set
  22. };
  23. };
  24. var global$5 = tinymce.util.Tools.resolve('tinymce.PluginManager');
  25. var __assign = function () {
  26. __assign = Object.assign || function __assign(t) {
  27. for (var s, i = 1, n = arguments.length; i < n; i++) {
  28. s = arguments[i];
  29. for (var p in s)
  30. if (Object.prototype.hasOwnProperty.call(s, p))
  31. t[p] = s[p];
  32. }
  33. return t;
  34. };
  35. return __assign.apply(this, arguments);
  36. };
  37. function __spreadArray(to, from, pack) {
  38. if (pack || arguments.length === 2)
  39. for (var i = 0, l = from.length, ar; i < l; i++) {
  40. if (ar || !(i in from)) {
  41. if (!ar)
  42. ar = Array.prototype.slice.call(from, 0, i);
  43. ar[i] = from[i];
  44. }
  45. }
  46. return to.concat(ar || Array.prototype.slice.call(from));
  47. }
  48. var typeOf = function (x) {
  49. var t = typeof x;
  50. if (x === null) {
  51. return 'null';
  52. } else if (t === 'object' && (Array.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'Array')) {
  53. return 'array';
  54. } else if (t === 'object' && (String.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'String')) {
  55. return 'string';
  56. } else {
  57. return t;
  58. }
  59. };
  60. var isType = function (type) {
  61. return function (value) {
  62. return typeOf(value) === type;
  63. };
  64. };
  65. var isString = isType('string');
  66. var isObject = isType('object');
  67. var isArray = isType('array');
  68. var noop = function () {
  69. };
  70. var constant = function (value) {
  71. return function () {
  72. return value;
  73. };
  74. };
  75. var identity = function (x) {
  76. return x;
  77. };
  78. var die = function (msg) {
  79. return function () {
  80. throw new Error(msg);
  81. };
  82. };
  83. var never = constant(false);
  84. var always = constant(true);
  85. var none = function () {
  86. return NONE;
  87. };
  88. var NONE = function () {
  89. var call = function (thunk) {
  90. return thunk();
  91. };
  92. var id = identity;
  93. var me = {
  94. fold: function (n, _s) {
  95. return n();
  96. },
  97. isSome: never,
  98. isNone: always,
  99. getOr: id,
  100. getOrThunk: call,
  101. getOrDie: function (msg) {
  102. throw new Error(msg || 'error: getOrDie called on none.');
  103. },
  104. getOrNull: constant(null),
  105. getOrUndefined: constant(undefined),
  106. or: id,
  107. orThunk: call,
  108. map: none,
  109. each: noop,
  110. bind: none,
  111. exists: never,
  112. forall: always,
  113. filter: function () {
  114. return none();
  115. },
  116. toArray: function () {
  117. return [];
  118. },
  119. toString: constant('none()')
  120. };
  121. return me;
  122. }();
  123. var some = function (a) {
  124. var constant_a = constant(a);
  125. var self = function () {
  126. return me;
  127. };
  128. var bind = function (f) {
  129. return f(a);
  130. };
  131. var me = {
  132. fold: function (n, s) {
  133. return s(a);
  134. },
  135. isSome: always,
  136. isNone: never,
  137. getOr: constant_a,
  138. getOrThunk: constant_a,
  139. getOrDie: constant_a,
  140. getOrNull: constant_a,
  141. getOrUndefined: constant_a,
  142. or: self,
  143. orThunk: self,
  144. map: function (f) {
  145. return some(f(a));
  146. },
  147. each: function (f) {
  148. f(a);
  149. },
  150. bind: bind,
  151. exists: bind,
  152. forall: bind,
  153. filter: function (f) {
  154. return f(a) ? me : NONE;
  155. },
  156. toArray: function () {
  157. return [a];
  158. },
  159. toString: function () {
  160. return 'some(' + a + ')';
  161. }
  162. };
  163. return me;
  164. };
  165. var from = function (value) {
  166. return value === null || value === undefined ? NONE : some(value);
  167. };
  168. var Optional = {
  169. some: some,
  170. none: none,
  171. from: from
  172. };
  173. var nativeSlice = Array.prototype.slice;
  174. var nativeIndexOf = Array.prototype.indexOf;
  175. var rawIndexOf = function (ts, t) {
  176. return nativeIndexOf.call(ts, t);
  177. };
  178. var contains = function (xs, x) {
  179. return rawIndexOf(xs, x) > -1;
  180. };
  181. var map = function (xs, f) {
  182. var len = xs.length;
  183. var r = new Array(len);
  184. for (var i = 0; i < len; i++) {
  185. var x = xs[i];
  186. r[i] = f(x, i);
  187. }
  188. return r;
  189. };
  190. var each = function (xs, f) {
  191. for (var i = 0, len = xs.length; i < len; i++) {
  192. var x = xs[i];
  193. f(x, i);
  194. }
  195. };
  196. var eachr = function (xs, f) {
  197. for (var i = xs.length - 1; i >= 0; i--) {
  198. var x = xs[i];
  199. f(x, i);
  200. }
  201. };
  202. var filter = function (xs, pred) {
  203. var r = [];
  204. for (var i = 0, len = xs.length; i < len; i++) {
  205. var x = xs[i];
  206. if (pred(x, i)) {
  207. r.push(x);
  208. }
  209. }
  210. return r;
  211. };
  212. var foldr = function (xs, f, acc) {
  213. eachr(xs, function (x, i) {
  214. acc = f(acc, x, i);
  215. });
  216. return acc;
  217. };
  218. var foldl = function (xs, f, acc) {
  219. each(xs, function (x, i) {
  220. acc = f(acc, x, i);
  221. });
  222. return acc;
  223. };
  224. var findUntil = function (xs, pred, until) {
  225. for (var i = 0, len = xs.length; i < len; i++) {
  226. var x = xs[i];
  227. if (pred(x, i)) {
  228. return Optional.some(x);
  229. } else if (until(x, i)) {
  230. break;
  231. }
  232. }
  233. return Optional.none();
  234. };
  235. var find = function (xs, pred) {
  236. return findUntil(xs, pred, never);
  237. };
  238. var forall = function (xs, pred) {
  239. for (var i = 0, len = xs.length; i < len; ++i) {
  240. var x = xs[i];
  241. if (pred(x, i) !== true) {
  242. return false;
  243. }
  244. }
  245. return true;
  246. };
  247. var sort = function (xs, comparator) {
  248. var copy = nativeSlice.call(xs, 0);
  249. copy.sort(comparator);
  250. return copy;
  251. };
  252. var get$1 = function (xs, i) {
  253. return i >= 0 && i < xs.length ? Optional.some(xs[i]) : Optional.none();
  254. };
  255. var head = function (xs) {
  256. return get$1(xs, 0);
  257. };
  258. var keys = Object.keys;
  259. var hasOwnProperty = Object.hasOwnProperty;
  260. var has = function (obj, key) {
  261. return hasOwnProperty.call(obj, key);
  262. };
  263. var generate$1 = function (cases) {
  264. if (!isArray(cases)) {
  265. throw new Error('cases must be an array');
  266. }
  267. if (cases.length === 0) {
  268. throw new Error('there must be at least one case');
  269. }
  270. var constructors = [];
  271. var adt = {};
  272. each(cases, function (acase, count) {
  273. var keys$1 = keys(acase);
  274. if (keys$1.length !== 1) {
  275. throw new Error('one and only one name per case');
  276. }
  277. var key = keys$1[0];
  278. var value = acase[key];
  279. if (adt[key] !== undefined) {
  280. throw new Error('duplicate key detected:' + key);
  281. } else if (key === 'cata') {
  282. throw new Error('cannot have a case named cata (sorry)');
  283. } else if (!isArray(value)) {
  284. throw new Error('case arguments must be an array');
  285. }
  286. constructors.push(key);
  287. adt[key] = function () {
  288. var args = [];
  289. for (var _i = 0; _i < arguments.length; _i++) {
  290. args[_i] = arguments[_i];
  291. }
  292. var argLength = args.length;
  293. if (argLength !== value.length) {
  294. throw new Error('Wrong number of arguments to case ' + key + '. Expected ' + value.length + ' (' + value + '), got ' + argLength);
  295. }
  296. var match = function (branches) {
  297. var branchKeys = keys(branches);
  298. if (constructors.length !== branchKeys.length) {
  299. throw new Error('Wrong number of arguments to match. Expected: ' + constructors.join(',') + '\nActual: ' + branchKeys.join(','));
  300. }
  301. var allReqd = forall(constructors, function (reqKey) {
  302. return contains(branchKeys, reqKey);
  303. });
  304. if (!allReqd) {
  305. throw new Error('Not all branches were specified when using match. Specified: ' + branchKeys.join(', ') + '\nRequired: ' + constructors.join(', '));
  306. }
  307. return branches[key].apply(null, args);
  308. };
  309. return {
  310. fold: function () {
  311. var foldArgs = [];
  312. for (var _i = 0; _i < arguments.length; _i++) {
  313. foldArgs[_i] = arguments[_i];
  314. }
  315. if (foldArgs.length !== cases.length) {
  316. throw new Error('Wrong number of arguments to fold. Expected ' + cases.length + ', got ' + foldArgs.length);
  317. }
  318. var target = foldArgs[count];
  319. return target.apply(null, args);
  320. },
  321. match: match,
  322. log: function (label) {
  323. console.log(label, {
  324. constructors: constructors,
  325. constructor: key,
  326. params: args
  327. });
  328. }
  329. };
  330. };
  331. });
  332. return adt;
  333. };
  334. var Adt = { generate: generate$1 };
  335. Adt.generate([
  336. {
  337. bothErrors: [
  338. 'error1',
  339. 'error2'
  340. ]
  341. },
  342. {
  343. firstError: [
  344. 'error1',
  345. 'value2'
  346. ]
  347. },
  348. {
  349. secondError: [
  350. 'value1',
  351. 'error2'
  352. ]
  353. },
  354. {
  355. bothValues: [
  356. 'value1',
  357. 'value2'
  358. ]
  359. }
  360. ]);
  361. var partition = function (results) {
  362. var errors = [];
  363. var values = [];
  364. each(results, function (result) {
  365. result.fold(function (err) {
  366. errors.push(err);
  367. }, function (value) {
  368. values.push(value);
  369. });
  370. });
  371. return {
  372. errors: errors,
  373. values: values
  374. };
  375. };
  376. var value = function (o) {
  377. var or = function (_opt) {
  378. return value(o);
  379. };
  380. var orThunk = function (_f) {
  381. return value(o);
  382. };
  383. var map = function (f) {
  384. return value(f(o));
  385. };
  386. var mapError = function (_f) {
  387. return value(o);
  388. };
  389. var each = function (f) {
  390. f(o);
  391. };
  392. var bind = function (f) {
  393. return f(o);
  394. };
  395. var fold = function (_, onValue) {
  396. return onValue(o);
  397. };
  398. var exists = function (f) {
  399. return f(o);
  400. };
  401. var forall = function (f) {
  402. return f(o);
  403. };
  404. var toOptional = function () {
  405. return Optional.some(o);
  406. };
  407. return {
  408. isValue: always,
  409. isError: never,
  410. getOr: constant(o),
  411. getOrThunk: constant(o),
  412. getOrDie: constant(o),
  413. or: or,
  414. orThunk: orThunk,
  415. fold: fold,
  416. map: map,
  417. mapError: mapError,
  418. each: each,
  419. bind: bind,
  420. exists: exists,
  421. forall: forall,
  422. toOptional: toOptional
  423. };
  424. };
  425. var error$1 = function (message) {
  426. var getOrThunk = function (f) {
  427. return f();
  428. };
  429. var getOrDie = function () {
  430. return die(String(message))();
  431. };
  432. var or = identity;
  433. var orThunk = function (f) {
  434. return f();
  435. };
  436. var map = function (_f) {
  437. return error$1(message);
  438. };
  439. var mapError = function (f) {
  440. return error$1(f(message));
  441. };
  442. var bind = function (_f) {
  443. return error$1(message);
  444. };
  445. var fold = function (onError, _) {
  446. return onError(message);
  447. };
  448. return {
  449. isValue: never,
  450. isError: always,
  451. getOr: identity,
  452. getOrThunk: getOrThunk,
  453. getOrDie: getOrDie,
  454. or: or,
  455. orThunk: orThunk,
  456. fold: fold,
  457. map: map,
  458. mapError: mapError,
  459. each: noop,
  460. bind: bind,
  461. exists: never,
  462. forall: always,
  463. toOptional: Optional.none
  464. };
  465. };
  466. var fromOption = function (opt, err) {
  467. return opt.fold(function () {
  468. return error$1(err);
  469. }, value);
  470. };
  471. var Result = {
  472. value: value,
  473. error: error$1,
  474. fromOption: fromOption
  475. };
  476. var isInlinePattern = function (pattern) {
  477. return pattern.type === 'inline-command' || pattern.type === 'inline-format';
  478. };
  479. var isBlockPattern = function (pattern) {
  480. return pattern.type === 'block-command' || pattern.type === 'block-format';
  481. };
  482. var sortPatterns = function (patterns) {
  483. return sort(patterns, function (a, b) {
  484. if (a.start.length === b.start.length) {
  485. return 0;
  486. }
  487. return a.start.length > b.start.length ? -1 : 1;
  488. });
  489. };
  490. var normalizePattern = function (pattern) {
  491. var err = function (message) {
  492. return Result.error({
  493. message: message,
  494. pattern: pattern
  495. });
  496. };
  497. var formatOrCmd = function (name, onFormat, onCommand) {
  498. if (pattern.format !== undefined) {
  499. var formats = void 0;
  500. if (isArray(pattern.format)) {
  501. if (!forall(pattern.format, isString)) {
  502. return err(name + ' pattern has non-string items in the `format` array');
  503. }
  504. formats = pattern.format;
  505. } else if (isString(pattern.format)) {
  506. formats = [pattern.format];
  507. } else {
  508. return err(name + ' pattern has non-string `format` parameter');
  509. }
  510. return Result.value(onFormat(formats));
  511. } else if (pattern.cmd !== undefined) {
  512. if (!isString(pattern.cmd)) {
  513. return err(name + ' pattern has non-string `cmd` parameter');
  514. }
  515. return Result.value(onCommand(pattern.cmd, pattern.value));
  516. } else {
  517. return err(name + ' pattern is missing both `format` and `cmd` parameters');
  518. }
  519. };
  520. if (!isObject(pattern)) {
  521. return err('Raw pattern is not an object');
  522. }
  523. if (!isString(pattern.start)) {
  524. return err('Raw pattern is missing `start` parameter');
  525. }
  526. if (pattern.end !== undefined) {
  527. if (!isString(pattern.end)) {
  528. return err('Inline pattern has non-string `end` parameter');
  529. }
  530. if (pattern.start.length === 0 && pattern.end.length === 0) {
  531. return err('Inline pattern has empty `start` and `end` parameters');
  532. }
  533. var start_1 = pattern.start;
  534. var end_1 = pattern.end;
  535. if (end_1.length === 0) {
  536. end_1 = start_1;
  537. start_1 = '';
  538. }
  539. return formatOrCmd('Inline', function (format) {
  540. return {
  541. type: 'inline-format',
  542. start: start_1,
  543. end: end_1,
  544. format: format
  545. };
  546. }, function (cmd, value) {
  547. return {
  548. type: 'inline-command',
  549. start: start_1,
  550. end: end_1,
  551. cmd: cmd,
  552. value: value
  553. };
  554. });
  555. } else if (pattern.replacement !== undefined) {
  556. if (!isString(pattern.replacement)) {
  557. return err('Replacement pattern has non-string `replacement` parameter');
  558. }
  559. if (pattern.start.length === 0) {
  560. return err('Replacement pattern has empty `start` parameter');
  561. }
  562. return Result.value({
  563. type: 'inline-command',
  564. start: '',
  565. end: pattern.start,
  566. cmd: 'mceInsertContent',
  567. value: pattern.replacement
  568. });
  569. } else {
  570. if (pattern.start.length === 0) {
  571. return err('Block pattern has empty `start` parameter');
  572. }
  573. return formatOrCmd('Block', function (formats) {
  574. return {
  575. type: 'block-format',
  576. start: pattern.start,
  577. format: formats[0]
  578. };
  579. }, function (command, commandValue) {
  580. return {
  581. type: 'block-command',
  582. start: pattern.start,
  583. cmd: command,
  584. value: commandValue
  585. };
  586. });
  587. }
  588. };
  589. var denormalizePattern = function (pattern) {
  590. if (pattern.type === 'block-command') {
  591. return {
  592. start: pattern.start,
  593. cmd: pattern.cmd,
  594. value: pattern.value
  595. };
  596. } else if (pattern.type === 'block-format') {
  597. return {
  598. start: pattern.start,
  599. format: pattern.format
  600. };
  601. } else if (pattern.type === 'inline-command') {
  602. if (pattern.cmd === 'mceInsertContent' && pattern.start === '') {
  603. return {
  604. start: pattern.end,
  605. replacement: pattern.value
  606. };
  607. } else {
  608. return {
  609. start: pattern.start,
  610. end: pattern.end,
  611. cmd: pattern.cmd,
  612. value: pattern.value
  613. };
  614. }
  615. } else if (pattern.type === 'inline-format') {
  616. return {
  617. start: pattern.start,
  618. end: pattern.end,
  619. format: pattern.format.length === 1 ? pattern.format[0] : pattern.format
  620. };
  621. }
  622. };
  623. var createPatternSet = function (patterns) {
  624. return {
  625. inlinePatterns: filter(patterns, isInlinePattern),
  626. blockPatterns: sortPatterns(filter(patterns, isBlockPattern))
  627. };
  628. };
  629. var get = function (patternsState) {
  630. var setPatterns = function (newPatterns) {
  631. var normalized = partition(map(newPatterns, normalizePattern));
  632. if (normalized.errors.length > 0) {
  633. var firstError = normalized.errors[0];
  634. throw new Error(firstError.message + ':\n' + JSON.stringify(firstError.pattern, null, 2));
  635. }
  636. patternsState.set(createPatternSet(normalized.values));
  637. };
  638. var getPatterns = function () {
  639. return __spreadArray(__spreadArray([], map(patternsState.get().inlinePatterns, denormalizePattern), true), map(patternsState.get().blockPatterns, denormalizePattern), true);
  640. };
  641. return {
  642. setPatterns: setPatterns,
  643. getPatterns: getPatterns
  644. };
  645. };
  646. var Global = typeof window !== 'undefined' ? window : Function('return this;')();
  647. var error = function () {
  648. var args = [];
  649. for (var _i = 0; _i < arguments.length; _i++) {
  650. args[_i] = arguments[_i];
  651. }
  652. var console = Global.console;
  653. if (console) {
  654. if (console.error) {
  655. console.error.apply(console, args);
  656. } else {
  657. console.log.apply(console, args);
  658. }
  659. }
  660. };
  661. var defaultPatterns = [
  662. {
  663. start: '*',
  664. end: '*',
  665. format: 'italic'
  666. },
  667. {
  668. start: '**',
  669. end: '**',
  670. format: 'bold'
  671. },
  672. {
  673. start: '#',
  674. format: 'h1'
  675. },
  676. {
  677. start: '##',
  678. format: 'h2'
  679. },
  680. {
  681. start: '###',
  682. format: 'h3'
  683. },
  684. {
  685. start: '####',
  686. format: 'h4'
  687. },
  688. {
  689. start: '#####',
  690. format: 'h5'
  691. },
  692. {
  693. start: '######',
  694. format: 'h6'
  695. },
  696. {
  697. start: '1. ',
  698. cmd: 'InsertOrderedList'
  699. },
  700. {
  701. start: '* ',
  702. cmd: 'InsertUnorderedList'
  703. },
  704. {
  705. start: '- ',
  706. cmd: 'InsertUnorderedList'
  707. }
  708. ];
  709. var getPatternSet = function (editor) {
  710. var patterns = editor.getParam('textpattern_patterns', defaultPatterns, 'array');
  711. if (!isArray(patterns)) {
  712. error('The setting textpattern_patterns should be an array');
  713. return {
  714. inlinePatterns: [],
  715. blockPatterns: []
  716. };
  717. }
  718. var normalized = partition(map(patterns, normalizePattern));
  719. each(normalized.errors, function (err) {
  720. return error(err.message, err.pattern);
  721. });
  722. return createPatternSet(normalized.values);
  723. };
  724. var getForcedRootBlock = function (editor) {
  725. var block = editor.getParam('forced_root_block', 'p');
  726. if (block === false) {
  727. return '';
  728. } else if (block === true) {
  729. return 'p';
  730. } else {
  731. return block;
  732. }
  733. };
  734. var global$4 = tinymce.util.Tools.resolve('tinymce.util.Delay');
  735. var global$3 = tinymce.util.Tools.resolve('tinymce.util.VK');
  736. var zeroWidth = '\uFEFF';
  737. var nbsp = '\xA0';
  738. var global$2 = tinymce.util.Tools.resolve('tinymce.util.Tools');
  739. var global$1 = tinymce.util.Tools.resolve('tinymce.dom.DOMUtils');
  740. var global = tinymce.util.Tools.resolve('tinymce.dom.TextSeeker');
  741. var point = function (container, offset) {
  742. return {
  743. container: container,
  744. offset: offset
  745. };
  746. };
  747. var isText = function (node) {
  748. return node.nodeType === Node.TEXT_NODE;
  749. };
  750. var cleanEmptyNodes = function (dom, node, isRoot) {
  751. if (node && dom.isEmpty(node) && !isRoot(node)) {
  752. var parent_1 = node.parentNode;
  753. dom.remove(node);
  754. cleanEmptyNodes(dom, parent_1, isRoot);
  755. }
  756. };
  757. var deleteRng = function (dom, rng, isRoot, clean) {
  758. if (clean === void 0) {
  759. clean = true;
  760. }
  761. var startParent = rng.startContainer.parentNode;
  762. var endParent = rng.endContainer.parentNode;
  763. rng.deleteContents();
  764. if (clean && !isRoot(rng.startContainer)) {
  765. if (isText(rng.startContainer) && rng.startContainer.data.length === 0) {
  766. dom.remove(rng.startContainer);
  767. }
  768. if (isText(rng.endContainer) && rng.endContainer.data.length === 0) {
  769. dom.remove(rng.endContainer);
  770. }
  771. cleanEmptyNodes(dom, startParent, isRoot);
  772. if (startParent !== endParent) {
  773. cleanEmptyNodes(dom, endParent, isRoot);
  774. }
  775. }
  776. };
  777. var isBlockFormatName = function (name, formatter) {
  778. var formatSet = formatter.get(name);
  779. return isArray(formatSet) && head(formatSet).exists(function (format) {
  780. return has(format, 'block');
  781. });
  782. };
  783. var isReplacementPattern = function (pattern) {
  784. return pattern.start.length === 0;
  785. };
  786. var getParentBlock = function (editor, rng) {
  787. var parentBlockOpt = Optional.from(editor.dom.getParent(rng.startContainer, editor.dom.isBlock));
  788. if (getForcedRootBlock(editor) === '') {
  789. return parentBlockOpt.orThunk(function () {
  790. return Optional.some(editor.getBody());
  791. });
  792. } else {
  793. return parentBlockOpt;
  794. }
  795. };
  796. var DOM = global$1.DOM;
  797. var alwaysNext = function (startNode) {
  798. return function (node) {
  799. return startNode === node ? -1 : 0;
  800. };
  801. };
  802. var isBoundary = function (dom) {
  803. return function (node) {
  804. return dom.isBlock(node) || contains([
  805. 'BR',
  806. 'IMG',
  807. 'HR',
  808. 'INPUT'
  809. ], node.nodeName) || dom.getContentEditable(node) === 'false';
  810. };
  811. };
  812. var textBefore = function (node, offset, rootNode) {
  813. if (isText(node) && offset >= 0) {
  814. return Optional.some(point(node, offset));
  815. } else {
  816. var textSeeker = global(DOM);
  817. return Optional.from(textSeeker.backwards(node, offset, alwaysNext(node), rootNode)).map(function (prev) {
  818. return point(prev.container, prev.container.data.length);
  819. });
  820. }
  821. };
  822. var textAfter = function (node, offset, rootNode) {
  823. if (isText(node) && offset >= node.length) {
  824. return Optional.some(point(node, offset));
  825. } else {
  826. var textSeeker = global(DOM);
  827. return Optional.from(textSeeker.forwards(node, offset, alwaysNext(node), rootNode)).map(function (prev) {
  828. return point(prev.container, 0);
  829. });
  830. }
  831. };
  832. var scanLeft = function (node, offset, rootNode) {
  833. if (!isText(node)) {
  834. return Optional.none();
  835. }
  836. var text = node.textContent;
  837. if (offset >= 0 && offset <= text.length) {
  838. return Optional.some(point(node, offset));
  839. } else {
  840. var textSeeker = global(DOM);
  841. return Optional.from(textSeeker.backwards(node, offset, alwaysNext(node), rootNode)).bind(function (prev) {
  842. var prevText = prev.container.data;
  843. return scanLeft(prev.container, offset + prevText.length, rootNode);
  844. });
  845. }
  846. };
  847. var scanRight = function (node, offset, rootNode) {
  848. if (!isText(node)) {
  849. return Optional.none();
  850. }
  851. var text = node.textContent;
  852. if (offset <= text.length) {
  853. return Optional.some(point(node, offset));
  854. } else {
  855. var textSeeker = global(DOM);
  856. return Optional.from(textSeeker.forwards(node, offset, alwaysNext(node), rootNode)).bind(function (next) {
  857. return scanRight(next.container, offset - text.length, rootNode);
  858. });
  859. }
  860. };
  861. var repeatLeft = function (dom, node, offset, process, rootNode) {
  862. var search = global(dom, isBoundary(dom));
  863. return Optional.from(search.backwards(node, offset, process, rootNode));
  864. };
  865. var generatePath = function (root, node, offset) {
  866. if (isText(node) && (offset < 0 || offset > node.data.length)) {
  867. return [];
  868. }
  869. var p = [offset];
  870. var current = node;
  871. while (current !== root && current.parentNode) {
  872. var parent_1 = current.parentNode;
  873. for (var i = 0; i < parent_1.childNodes.length; i++) {
  874. if (parent_1.childNodes[i] === current) {
  875. p.push(i);
  876. break;
  877. }
  878. }
  879. current = parent_1;
  880. }
  881. return current === root ? p.reverse() : [];
  882. };
  883. var generatePathRange = function (root, startNode, startOffset, endNode, endOffset) {
  884. var start = generatePath(root, startNode, startOffset);
  885. var end = generatePath(root, endNode, endOffset);
  886. return {
  887. start: start,
  888. end: end
  889. };
  890. };
  891. var resolvePath = function (root, path) {
  892. var nodePath = path.slice();
  893. var offset = nodePath.pop();
  894. var resolvedNode = foldl(nodePath, function (optNode, index) {
  895. return optNode.bind(function (node) {
  896. return Optional.from(node.childNodes[index]);
  897. });
  898. }, Optional.some(root));
  899. return resolvedNode.bind(function (node) {
  900. if (isText(node) && (offset < 0 || offset > node.data.length)) {
  901. return Optional.none();
  902. } else {
  903. return Optional.some({
  904. node: node,
  905. offset: offset
  906. });
  907. }
  908. });
  909. };
  910. var resolvePathRange = function (root, range) {
  911. return resolvePath(root, range.start).bind(function (_a) {
  912. var startNode = _a.node, startOffset = _a.offset;
  913. return resolvePath(root, range.end).map(function (_a) {
  914. var endNode = _a.node, endOffset = _a.offset;
  915. var rng = document.createRange();
  916. rng.setStart(startNode, startOffset);
  917. rng.setEnd(endNode, endOffset);
  918. return rng;
  919. });
  920. });
  921. };
  922. var generatePathRangeFromRange = function (root, range) {
  923. return generatePathRange(root, range.startContainer, range.startOffset, range.endContainer, range.endOffset);
  924. };
  925. var stripPattern = function (dom, block, pattern) {
  926. var firstTextNode = textAfter(block, 0, block);
  927. firstTextNode.each(function (spot) {
  928. var node = spot.container;
  929. scanRight(node, pattern.start.length, block).each(function (end) {
  930. var rng = dom.createRng();
  931. rng.setStart(node, 0);
  932. rng.setEnd(end.container, end.offset);
  933. deleteRng(dom, rng, function (e) {
  934. return e === block;
  935. });
  936. });
  937. });
  938. };
  939. var applyPattern$1 = function (editor, match) {
  940. var dom = editor.dom;
  941. var pattern = match.pattern;
  942. var rng = resolvePathRange(dom.getRoot(), match.range).getOrDie('Unable to resolve path range');
  943. getParentBlock(editor, rng).each(function (block) {
  944. if (pattern.type === 'block-format') {
  945. if (isBlockFormatName(pattern.format, editor.formatter)) {
  946. editor.undoManager.transact(function () {
  947. stripPattern(editor.dom, block, pattern);
  948. editor.formatter.apply(pattern.format);
  949. });
  950. }
  951. } else if (pattern.type === 'block-command') {
  952. editor.undoManager.transact(function () {
  953. stripPattern(editor.dom, block, pattern);
  954. editor.execCommand(pattern.cmd, false, pattern.value);
  955. });
  956. }
  957. });
  958. return true;
  959. };
  960. var findPattern$1 = function (patterns, text) {
  961. var nuText = text.replace(nbsp, ' ');
  962. return find(patterns, function (pattern) {
  963. return text.indexOf(pattern.start) === 0 || nuText.indexOf(pattern.start) === 0;
  964. });
  965. };
  966. var findPatterns$1 = function (editor, patterns) {
  967. var dom = editor.dom;
  968. var rng = editor.selection.getRng();
  969. return getParentBlock(editor, rng).filter(function (block) {
  970. var forcedRootBlock = getForcedRootBlock(editor);
  971. var matchesForcedRootBlock = forcedRootBlock === '' && dom.is(block, 'body') || dom.is(block, forcedRootBlock);
  972. return block !== null && matchesForcedRootBlock;
  973. }).bind(function (block) {
  974. var blockText = block.textContent;
  975. var matchedPattern = findPattern$1(patterns, blockText);
  976. return matchedPattern.map(function (pattern) {
  977. if (global$2.trim(blockText).length === pattern.start.length) {
  978. return [];
  979. }
  980. return [{
  981. pattern: pattern,
  982. range: generatePathRange(dom.getRoot(), block, 0, block, 0)
  983. }];
  984. });
  985. }).getOr([]);
  986. };
  987. var applyMatches$1 = function (editor, matches) {
  988. if (matches.length === 0) {
  989. return;
  990. }
  991. var bookmark = editor.selection.getBookmark();
  992. each(matches, function (match) {
  993. return applyPattern$1(editor, match);
  994. });
  995. editor.selection.moveToBookmark(bookmark);
  996. };
  997. var unique = 0;
  998. var generate = function (prefix) {
  999. var date = new Date();
  1000. var time = date.getTime();
  1001. var random = Math.floor(Math.random() * 1000000000);
  1002. unique++;
  1003. return prefix + '_' + random + unique + String(time);
  1004. };
  1005. var checkRange = function (str, substr, start) {
  1006. return substr === '' || str.length >= substr.length && str.substr(start, start + substr.length) === substr;
  1007. };
  1008. var endsWith = function (str, suffix) {
  1009. return checkRange(str, suffix, str.length - suffix.length);
  1010. };
  1011. var newMarker = function (dom, id) {
  1012. return dom.create('span', {
  1013. 'data-mce-type': 'bookmark',
  1014. id: id
  1015. });
  1016. };
  1017. var rangeFromMarker = function (dom, marker) {
  1018. var rng = dom.createRng();
  1019. rng.setStartAfter(marker.start);
  1020. rng.setEndBefore(marker.end);
  1021. return rng;
  1022. };
  1023. var createMarker = function (dom, markerPrefix, pathRange) {
  1024. var rng = resolvePathRange(dom.getRoot(), pathRange).getOrDie('Unable to resolve path range');
  1025. var startNode = rng.startContainer;
  1026. var endNode = rng.endContainer;
  1027. var textEnd = rng.endOffset === 0 ? endNode : endNode.splitText(rng.endOffset);
  1028. var textStart = rng.startOffset === 0 ? startNode : startNode.splitText(rng.startOffset);
  1029. return {
  1030. prefix: markerPrefix,
  1031. end: textEnd.parentNode.insertBefore(newMarker(dom, markerPrefix + '-end'), textEnd),
  1032. start: textStart.parentNode.insertBefore(newMarker(dom, markerPrefix + '-start'), textStart)
  1033. };
  1034. };
  1035. var removeMarker = function (dom, marker, isRoot) {
  1036. cleanEmptyNodes(dom, dom.get(marker.prefix + '-end'), isRoot);
  1037. cleanEmptyNodes(dom, dom.get(marker.prefix + '-start'), isRoot);
  1038. };
  1039. var matchesPattern = function (dom, block, patternContent) {
  1040. return function (element, offset) {
  1041. var text = element.data;
  1042. var searchText = text.substring(0, offset);
  1043. var startEndIndex = searchText.lastIndexOf(patternContent.charAt(patternContent.length - 1));
  1044. var startIndex = searchText.lastIndexOf(patternContent);
  1045. if (startIndex !== -1) {
  1046. return startIndex + patternContent.length;
  1047. } else if (startEndIndex !== -1) {
  1048. return startEndIndex + 1;
  1049. } else {
  1050. return -1;
  1051. }
  1052. };
  1053. };
  1054. var findPatternStartFromSpot = function (dom, pattern, block, spot) {
  1055. var startPattern = pattern.start;
  1056. var startSpot = repeatLeft(dom, spot.container, spot.offset, matchesPattern(dom, block, startPattern), block);
  1057. return startSpot.bind(function (spot) {
  1058. if (spot.offset >= startPattern.length) {
  1059. var rng = dom.createRng();
  1060. rng.setStart(spot.container, spot.offset - startPattern.length);
  1061. rng.setEnd(spot.container, spot.offset);
  1062. return Optional.some(rng);
  1063. } else {
  1064. var offset = spot.offset - startPattern.length;
  1065. return scanLeft(spot.container, offset, block).map(function (nextSpot) {
  1066. var rng = dom.createRng();
  1067. rng.setStart(nextSpot.container, nextSpot.offset);
  1068. rng.setEnd(spot.container, spot.offset);
  1069. return rng;
  1070. }).filter(function (rng) {
  1071. return rng.toString() === startPattern;
  1072. }).orThunk(function () {
  1073. return findPatternStartFromSpot(dom, pattern, block, point(spot.container, 0));
  1074. });
  1075. }
  1076. });
  1077. };
  1078. var findPatternStart = function (dom, pattern, node, offset, block, requireGap) {
  1079. if (requireGap === void 0) {
  1080. requireGap = false;
  1081. }
  1082. if (pattern.start.length === 0 && !requireGap) {
  1083. var rng = dom.createRng();
  1084. rng.setStart(node, offset);
  1085. rng.setEnd(node, offset);
  1086. return Optional.some(rng);
  1087. }
  1088. return textBefore(node, offset, block).bind(function (spot) {
  1089. var start = findPatternStartFromSpot(dom, pattern, block, spot);
  1090. return start.bind(function (startRange) {
  1091. if (requireGap) {
  1092. if (startRange.endContainer === spot.container && startRange.endOffset === spot.offset) {
  1093. return Optional.none();
  1094. } else if (spot.offset === 0 && startRange.endContainer.textContent.length === startRange.endOffset) {
  1095. return Optional.none();
  1096. }
  1097. }
  1098. return Optional.some(startRange);
  1099. });
  1100. });
  1101. };
  1102. var findPattern = function (editor, block, details) {
  1103. var dom = editor.dom;
  1104. var root = dom.getRoot();
  1105. var pattern = details.pattern;
  1106. var endNode = details.position.container;
  1107. var endOffset = details.position.offset;
  1108. return scanLeft(endNode, endOffset - details.pattern.end.length, block).bind(function (spot) {
  1109. var endPathRng = generatePathRange(root, spot.container, spot.offset, endNode, endOffset);
  1110. if (isReplacementPattern(pattern)) {
  1111. return Optional.some({
  1112. matches: [{
  1113. pattern: pattern,
  1114. startRng: endPathRng,
  1115. endRng: endPathRng
  1116. }],
  1117. position: spot
  1118. });
  1119. } else {
  1120. var resultsOpt = findPatternsRec(editor, details.remainingPatterns, spot.container, spot.offset, block);
  1121. var results_1 = resultsOpt.getOr({
  1122. matches: [],
  1123. position: spot
  1124. });
  1125. var pos = results_1.position;
  1126. var start = findPatternStart(dom, pattern, pos.container, pos.offset, block, resultsOpt.isNone());
  1127. return start.map(function (startRng) {
  1128. var startPathRng = generatePathRangeFromRange(root, startRng);
  1129. return {
  1130. matches: results_1.matches.concat([{
  1131. pattern: pattern,
  1132. startRng: startPathRng,
  1133. endRng: endPathRng
  1134. }]),
  1135. position: point(startRng.startContainer, startRng.startOffset)
  1136. };
  1137. });
  1138. }
  1139. });
  1140. };
  1141. var findPatternsRec = function (editor, patterns, node, offset, block) {
  1142. var dom = editor.dom;
  1143. return textBefore(node, offset, dom.getRoot()).bind(function (endSpot) {
  1144. var rng = dom.createRng();
  1145. rng.setStart(block, 0);
  1146. rng.setEnd(node, offset);
  1147. var text = rng.toString();
  1148. for (var i = 0; i < patterns.length; i++) {
  1149. var pattern = patterns[i];
  1150. if (!endsWith(text, pattern.end)) {
  1151. continue;
  1152. }
  1153. var patternsWithoutCurrent = patterns.slice();
  1154. patternsWithoutCurrent.splice(i, 1);
  1155. var result = findPattern(editor, block, {
  1156. pattern: pattern,
  1157. remainingPatterns: patternsWithoutCurrent,
  1158. position: endSpot
  1159. });
  1160. if (result.isSome()) {
  1161. return result;
  1162. }
  1163. }
  1164. return Optional.none();
  1165. });
  1166. };
  1167. var applyPattern = function (editor, pattern, patternRange) {
  1168. editor.selection.setRng(patternRange);
  1169. if (pattern.type === 'inline-format') {
  1170. each(pattern.format, function (format) {
  1171. editor.formatter.apply(format);
  1172. });
  1173. } else {
  1174. editor.execCommand(pattern.cmd, false, pattern.value);
  1175. }
  1176. };
  1177. var applyReplacementPattern = function (editor, pattern, marker, isRoot) {
  1178. var markerRange = rangeFromMarker(editor.dom, marker);
  1179. deleteRng(editor.dom, markerRange, isRoot);
  1180. applyPattern(editor, pattern, markerRange);
  1181. };
  1182. var applyPatternWithContent = function (editor, pattern, startMarker, endMarker, isRoot) {
  1183. var dom = editor.dom;
  1184. var markerEndRange = rangeFromMarker(dom, endMarker);
  1185. var markerStartRange = rangeFromMarker(dom, startMarker);
  1186. deleteRng(dom, markerStartRange, isRoot);
  1187. deleteRng(dom, markerEndRange, isRoot);
  1188. var patternMarker = {
  1189. prefix: startMarker.prefix,
  1190. start: startMarker.end,
  1191. end: endMarker.start
  1192. };
  1193. var patternRange = rangeFromMarker(dom, patternMarker);
  1194. applyPattern(editor, pattern, patternRange);
  1195. };
  1196. var addMarkers = function (dom, matches) {
  1197. var markerPrefix = generate('mce_textpattern');
  1198. var matchesWithEnds = foldr(matches, function (acc, match) {
  1199. var endMarker = createMarker(dom, markerPrefix + ('_end' + acc.length), match.endRng);
  1200. return acc.concat([__assign(__assign({}, match), { endMarker: endMarker })]);
  1201. }, []);
  1202. return foldr(matchesWithEnds, function (acc, match) {
  1203. var idx = matchesWithEnds.length - acc.length - 1;
  1204. var startMarker = isReplacementPattern(match.pattern) ? match.endMarker : createMarker(dom, markerPrefix + ('_start' + idx), match.startRng);
  1205. return acc.concat([__assign(__assign({}, match), { startMarker: startMarker })]);
  1206. }, []);
  1207. };
  1208. var findPatterns = function (editor, patterns, space) {
  1209. var rng = editor.selection.getRng();
  1210. if (rng.collapsed === false) {
  1211. return [];
  1212. }
  1213. return getParentBlock(editor, rng).bind(function (block) {
  1214. var offset = rng.startOffset - (space ? 1 : 0);
  1215. return findPatternsRec(editor, patterns, rng.startContainer, offset, block);
  1216. }).fold(function () {
  1217. return [];
  1218. }, function (result) {
  1219. return result.matches;
  1220. });
  1221. };
  1222. var applyMatches = function (editor, matches) {
  1223. if (matches.length === 0) {
  1224. return;
  1225. }
  1226. var dom = editor.dom;
  1227. var bookmark = editor.selection.getBookmark();
  1228. var matchesWithMarkers = addMarkers(dom, matches);
  1229. each(matchesWithMarkers, function (match) {
  1230. var block = dom.getParent(match.startMarker.start, dom.isBlock);
  1231. var isRoot = function (node) {
  1232. return node === block;
  1233. };
  1234. if (isReplacementPattern(match.pattern)) {
  1235. applyReplacementPattern(editor, match.pattern, match.endMarker, isRoot);
  1236. } else {
  1237. applyPatternWithContent(editor, match.pattern, match.startMarker, match.endMarker, isRoot);
  1238. }
  1239. removeMarker(dom, match.endMarker, isRoot);
  1240. removeMarker(dom, match.startMarker, isRoot);
  1241. });
  1242. editor.selection.moveToBookmark(bookmark);
  1243. };
  1244. var handleEnter = function (editor, patternSet) {
  1245. if (!editor.selection.isCollapsed()) {
  1246. return false;
  1247. }
  1248. var inlineMatches = findPatterns(editor, patternSet.inlinePatterns, false);
  1249. var blockMatches = findPatterns$1(editor, patternSet.blockPatterns);
  1250. if (blockMatches.length > 0 || inlineMatches.length > 0) {
  1251. editor.undoManager.add();
  1252. editor.undoManager.extra(function () {
  1253. editor.execCommand('mceInsertNewLine');
  1254. }, function () {
  1255. editor.insertContent(zeroWidth);
  1256. applyMatches(editor, inlineMatches);
  1257. applyMatches$1(editor, blockMatches);
  1258. var range = editor.selection.getRng();
  1259. var spot = textBefore(range.startContainer, range.startOffset, editor.dom.getRoot());
  1260. editor.execCommand('mceInsertNewLine');
  1261. spot.each(function (s) {
  1262. var node = s.container;
  1263. if (node.data.charAt(s.offset - 1) === zeroWidth) {
  1264. node.deleteData(s.offset - 1, 1);
  1265. cleanEmptyNodes(editor.dom, node.parentNode, function (e) {
  1266. return e === editor.dom.getRoot();
  1267. });
  1268. }
  1269. });
  1270. });
  1271. return true;
  1272. }
  1273. return false;
  1274. };
  1275. var handleInlineKey = function (editor, patternSet) {
  1276. var inlineMatches = findPatterns(editor, patternSet.inlinePatterns, true);
  1277. if (inlineMatches.length > 0) {
  1278. editor.undoManager.transact(function () {
  1279. applyMatches(editor, inlineMatches);
  1280. });
  1281. }
  1282. };
  1283. var checkKeyEvent = function (codes, event, predicate) {
  1284. for (var i = 0; i < codes.length; i++) {
  1285. if (predicate(codes[i], event)) {
  1286. return true;
  1287. }
  1288. }
  1289. return false;
  1290. };
  1291. var checkKeyCode = function (codes, event) {
  1292. return checkKeyEvent(codes, event, function (code, event) {
  1293. return code === event.keyCode && global$3.modifierPressed(event) === false;
  1294. });
  1295. };
  1296. var checkCharCode = function (chars, event) {
  1297. return checkKeyEvent(chars, event, function (chr, event) {
  1298. return chr.charCodeAt(0) === event.charCode;
  1299. });
  1300. };
  1301. var setup = function (editor, patternsState) {
  1302. var charCodes = [
  1303. ',',
  1304. '.',
  1305. ';',
  1306. ':',
  1307. '!',
  1308. '?'
  1309. ];
  1310. var keyCodes = [32];
  1311. editor.on('keydown', function (e) {
  1312. if (e.keyCode === 13 && !global$3.modifierPressed(e)) {
  1313. if (handleEnter(editor, patternsState.get())) {
  1314. e.preventDefault();
  1315. }
  1316. }
  1317. }, true);
  1318. editor.on('keyup', function (e) {
  1319. if (checkKeyCode(keyCodes, e)) {
  1320. handleInlineKey(editor, patternsState.get());
  1321. }
  1322. });
  1323. editor.on('keypress', function (e) {
  1324. if (checkCharCode(charCodes, e)) {
  1325. global$4.setEditorTimeout(editor, function () {
  1326. handleInlineKey(editor, patternsState.get());
  1327. });
  1328. }
  1329. });
  1330. };
  1331. function Plugin () {
  1332. global$5.add('textpattern', function (editor) {
  1333. var patternsState = Cell(getPatternSet(editor));
  1334. setup(editor, patternsState);
  1335. return get(patternsState);
  1336. });
  1337. }
  1338. Plugin();
  1339. }());