plugin.js 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948
  1. /**
  2. * TinyMCE version 6.4.2 (2023-04-26)
  3. */
  4. (function () {
  5. 'use strict';
  6. var global$7 = tinymce.util.Tools.resolve('tinymce.PluginManager');
  7. const hasProto = (v, constructor, predicate) => {
  8. var _a;
  9. if (predicate(v, constructor.prototype)) {
  10. return true;
  11. } else {
  12. return ((_a = v.constructor) === null || _a === void 0 ? void 0 : _a.name) === constructor.name;
  13. }
  14. };
  15. const typeOf = x => {
  16. const t = typeof x;
  17. if (x === null) {
  18. return 'null';
  19. } else if (t === 'object' && Array.isArray(x)) {
  20. return 'array';
  21. } else if (t === 'object' && hasProto(x, String, (o, proto) => proto.isPrototypeOf(o))) {
  22. return 'string';
  23. } else {
  24. return t;
  25. }
  26. };
  27. const isType$1 = type => value => typeOf(value) === type;
  28. const isSimpleType = type => value => typeof value === type;
  29. const isString = isType$1('string');
  30. const isObject = isType$1('object');
  31. const isArray = isType$1('array');
  32. const isBoolean = isSimpleType('boolean');
  33. const isNullable = a => a === null || a === undefined;
  34. const isNonNullable = a => !isNullable(a);
  35. const isFunction = isSimpleType('function');
  36. const isNumber = isSimpleType('number');
  37. const noop = () => {
  38. };
  39. const constant = value => {
  40. return () => {
  41. return value;
  42. };
  43. };
  44. const tripleEquals = (a, b) => {
  45. return a === b;
  46. };
  47. const not = f => t => !f(t);
  48. const never = constant(false);
  49. class Optional {
  50. constructor(tag, value) {
  51. this.tag = tag;
  52. this.value = value;
  53. }
  54. static some(value) {
  55. return new Optional(true, value);
  56. }
  57. static none() {
  58. return Optional.singletonNone;
  59. }
  60. fold(onNone, onSome) {
  61. if (this.tag) {
  62. return onSome(this.value);
  63. } else {
  64. return onNone();
  65. }
  66. }
  67. isSome() {
  68. return this.tag;
  69. }
  70. isNone() {
  71. return !this.tag;
  72. }
  73. map(mapper) {
  74. if (this.tag) {
  75. return Optional.some(mapper(this.value));
  76. } else {
  77. return Optional.none();
  78. }
  79. }
  80. bind(binder) {
  81. if (this.tag) {
  82. return binder(this.value);
  83. } else {
  84. return Optional.none();
  85. }
  86. }
  87. exists(predicate) {
  88. return this.tag && predicate(this.value);
  89. }
  90. forall(predicate) {
  91. return !this.tag || predicate(this.value);
  92. }
  93. filter(predicate) {
  94. if (!this.tag || predicate(this.value)) {
  95. return this;
  96. } else {
  97. return Optional.none();
  98. }
  99. }
  100. getOr(replacement) {
  101. return this.tag ? this.value : replacement;
  102. }
  103. or(replacement) {
  104. return this.tag ? this : replacement;
  105. }
  106. getOrThunk(thunk) {
  107. return this.tag ? this.value : thunk();
  108. }
  109. orThunk(thunk) {
  110. return this.tag ? this : thunk();
  111. }
  112. getOrDie(message) {
  113. if (!this.tag) {
  114. throw new Error(message !== null && message !== void 0 ? message : 'Called getOrDie on None');
  115. } else {
  116. return this.value;
  117. }
  118. }
  119. static from(value) {
  120. return isNonNullable(value) ? Optional.some(value) : Optional.none();
  121. }
  122. getOrNull() {
  123. return this.tag ? this.value : null;
  124. }
  125. getOrUndefined() {
  126. return this.value;
  127. }
  128. each(worker) {
  129. if (this.tag) {
  130. worker(this.value);
  131. }
  132. }
  133. toArray() {
  134. return this.tag ? [this.value] : [];
  135. }
  136. toString() {
  137. return this.tag ? `some(${ this.value })` : 'none()';
  138. }
  139. }
  140. Optional.singletonNone = new Optional(false);
  141. const nativeSlice = Array.prototype.slice;
  142. const nativeIndexOf = Array.prototype.indexOf;
  143. const nativePush = Array.prototype.push;
  144. const rawIndexOf = (ts, t) => nativeIndexOf.call(ts, t);
  145. const contains$1 = (xs, x) => rawIndexOf(xs, x) > -1;
  146. const exists = (xs, pred) => {
  147. for (let i = 0, len = xs.length; i < len; i++) {
  148. const x = xs[i];
  149. if (pred(x, i)) {
  150. return true;
  151. }
  152. }
  153. return false;
  154. };
  155. const map = (xs, f) => {
  156. const len = xs.length;
  157. const r = new Array(len);
  158. for (let i = 0; i < len; i++) {
  159. const x = xs[i];
  160. r[i] = f(x, i);
  161. }
  162. return r;
  163. };
  164. const each$1 = (xs, f) => {
  165. for (let i = 0, len = xs.length; i < len; i++) {
  166. const x = xs[i];
  167. f(x, i);
  168. }
  169. };
  170. const filter$1 = (xs, pred) => {
  171. const r = [];
  172. for (let i = 0, len = xs.length; i < len; i++) {
  173. const x = xs[i];
  174. if (pred(x, i)) {
  175. r.push(x);
  176. }
  177. }
  178. return r;
  179. };
  180. const groupBy = (xs, f) => {
  181. if (xs.length === 0) {
  182. return [];
  183. } else {
  184. let wasType = f(xs[0]);
  185. const r = [];
  186. let group = [];
  187. for (let i = 0, len = xs.length; i < len; i++) {
  188. const x = xs[i];
  189. const type = f(x);
  190. if (type !== wasType) {
  191. r.push(group);
  192. group = [];
  193. }
  194. wasType = type;
  195. group.push(x);
  196. }
  197. if (group.length !== 0) {
  198. r.push(group);
  199. }
  200. return r;
  201. }
  202. };
  203. const foldl = (xs, f, acc) => {
  204. each$1(xs, (x, i) => {
  205. acc = f(acc, x, i);
  206. });
  207. return acc;
  208. };
  209. const findUntil = (xs, pred, until) => {
  210. for (let i = 0, len = xs.length; i < len; i++) {
  211. const x = xs[i];
  212. if (pred(x, i)) {
  213. return Optional.some(x);
  214. } else if (until(x, i)) {
  215. break;
  216. }
  217. }
  218. return Optional.none();
  219. };
  220. const find = (xs, pred) => {
  221. return findUntil(xs, pred, never);
  222. };
  223. const flatten = xs => {
  224. const r = [];
  225. for (let i = 0, len = xs.length; i < len; ++i) {
  226. if (!isArray(xs[i])) {
  227. throw new Error('Arr.flatten item ' + i + ' was not an array, input: ' + xs);
  228. }
  229. nativePush.apply(r, xs[i]);
  230. }
  231. return r;
  232. };
  233. const bind = (xs, f) => flatten(map(xs, f));
  234. const reverse = xs => {
  235. const r = nativeSlice.call(xs, 0);
  236. r.reverse();
  237. return r;
  238. };
  239. const get$1 = (xs, i) => i >= 0 && i < xs.length ? Optional.some(xs[i]) : Optional.none();
  240. const head = xs => get$1(xs, 0);
  241. const last = xs => get$1(xs, xs.length - 1);
  242. const unique = (xs, comparator) => {
  243. const r = [];
  244. const isDuplicated = isFunction(comparator) ? x => exists(r, i => comparator(i, x)) : x => contains$1(r, x);
  245. for (let i = 0, len = xs.length; i < len; i++) {
  246. const x = xs[i];
  247. if (!isDuplicated(x)) {
  248. r.push(x);
  249. }
  250. }
  251. return r;
  252. };
  253. const is$2 = (lhs, rhs, comparator = tripleEquals) => lhs.exists(left => comparator(left, rhs));
  254. const equals = (lhs, rhs, comparator = tripleEquals) => lift2(lhs, rhs, comparator).getOr(lhs.isNone() && rhs.isNone());
  255. const lift2 = (oa, ob, f) => oa.isSome() && ob.isSome() ? Optional.some(f(oa.getOrDie(), ob.getOrDie())) : Optional.none();
  256. const ELEMENT = 1;
  257. const fromHtml = (html, scope) => {
  258. const doc = scope || document;
  259. const div = doc.createElement('div');
  260. div.innerHTML = html;
  261. if (!div.hasChildNodes() || div.childNodes.length > 1) {
  262. const message = 'HTML does not have a single root node';
  263. console.error(message, html);
  264. throw new Error(message);
  265. }
  266. return fromDom$1(div.childNodes[0]);
  267. };
  268. const fromTag = (tag, scope) => {
  269. const doc = scope || document;
  270. const node = doc.createElement(tag);
  271. return fromDom$1(node);
  272. };
  273. const fromText = (text, scope) => {
  274. const doc = scope || document;
  275. const node = doc.createTextNode(text);
  276. return fromDom$1(node);
  277. };
  278. const fromDom$1 = node => {
  279. if (node === null || node === undefined) {
  280. throw new Error('Node cannot be null or undefined');
  281. }
  282. return { dom: node };
  283. };
  284. const fromPoint = (docElm, x, y) => Optional.from(docElm.dom.elementFromPoint(x, y)).map(fromDom$1);
  285. const SugarElement = {
  286. fromHtml,
  287. fromTag,
  288. fromText,
  289. fromDom: fromDom$1,
  290. fromPoint
  291. };
  292. const is$1 = (element, selector) => {
  293. const dom = element.dom;
  294. if (dom.nodeType !== ELEMENT) {
  295. return false;
  296. } else {
  297. const elem = dom;
  298. if (elem.matches !== undefined) {
  299. return elem.matches(selector);
  300. } else if (elem.msMatchesSelector !== undefined) {
  301. return elem.msMatchesSelector(selector);
  302. } else if (elem.webkitMatchesSelector !== undefined) {
  303. return elem.webkitMatchesSelector(selector);
  304. } else if (elem.mozMatchesSelector !== undefined) {
  305. return elem.mozMatchesSelector(selector);
  306. } else {
  307. throw new Error('Browser lacks native selectors');
  308. }
  309. }
  310. };
  311. const eq = (e1, e2) => e1.dom === e2.dom;
  312. const contains = (e1, e2) => {
  313. const d1 = e1.dom;
  314. const d2 = e2.dom;
  315. return d1 === d2 ? false : d1.contains(d2);
  316. };
  317. const is = is$1;
  318. var ClosestOrAncestor = (is, ancestor, scope, a, isRoot) => {
  319. if (is(scope, a)) {
  320. return Optional.some(scope);
  321. } else if (isFunction(isRoot) && isRoot(scope)) {
  322. return Optional.none();
  323. } else {
  324. return ancestor(scope, a, isRoot);
  325. }
  326. };
  327. typeof window !== 'undefined' ? window : Function('return this;')();
  328. const name = element => {
  329. const r = element.dom.nodeName;
  330. return r.toLowerCase();
  331. };
  332. const type = element => element.dom.nodeType;
  333. const isType = t => element => type(element) === t;
  334. const isElement$1 = isType(ELEMENT);
  335. const isTag = tag => e => isElement$1(e) && name(e) === tag;
  336. const parent = element => Optional.from(element.dom.parentNode).map(SugarElement.fromDom);
  337. const parentElement = element => Optional.from(element.dom.parentElement).map(SugarElement.fromDom);
  338. const nextSibling = element => Optional.from(element.dom.nextSibling).map(SugarElement.fromDom);
  339. const children = element => map(element.dom.childNodes, SugarElement.fromDom);
  340. const child = (element, index) => {
  341. const cs = element.dom.childNodes;
  342. return Optional.from(cs[index]).map(SugarElement.fromDom);
  343. };
  344. const firstChild = element => child(element, 0);
  345. const lastChild = element => child(element, element.dom.childNodes.length - 1);
  346. const ancestor = (scope, predicate, isRoot) => {
  347. let element = scope.dom;
  348. const stop = isFunction(isRoot) ? isRoot : never;
  349. while (element.parentNode) {
  350. element = element.parentNode;
  351. const el = SugarElement.fromDom(element);
  352. if (predicate(el)) {
  353. return Optional.some(el);
  354. } else if (stop(el)) {
  355. break;
  356. }
  357. }
  358. return Optional.none();
  359. };
  360. const closest = (scope, predicate, isRoot) => {
  361. const is = (s, test) => test(s);
  362. return ClosestOrAncestor(is, ancestor, scope, predicate, isRoot);
  363. };
  364. const before$1 = (marker, element) => {
  365. const parent$1 = parent(marker);
  366. parent$1.each(v => {
  367. v.dom.insertBefore(element.dom, marker.dom);
  368. });
  369. };
  370. const after = (marker, element) => {
  371. const sibling = nextSibling(marker);
  372. sibling.fold(() => {
  373. const parent$1 = parent(marker);
  374. parent$1.each(v => {
  375. append$1(v, element);
  376. });
  377. }, v => {
  378. before$1(v, element);
  379. });
  380. };
  381. const append$1 = (parent, element) => {
  382. parent.dom.appendChild(element.dom);
  383. };
  384. const before = (marker, elements) => {
  385. each$1(elements, x => {
  386. before$1(marker, x);
  387. });
  388. };
  389. const append = (parent, elements) => {
  390. each$1(elements, x => {
  391. append$1(parent, x);
  392. });
  393. };
  394. const empty = element => {
  395. element.dom.textContent = '';
  396. each$1(children(element), rogue => {
  397. remove(rogue);
  398. });
  399. };
  400. const remove = element => {
  401. const dom = element.dom;
  402. if (dom.parentNode !== null) {
  403. dom.parentNode.removeChild(dom);
  404. }
  405. };
  406. var global$6 = tinymce.util.Tools.resolve('tinymce.dom.RangeUtils');
  407. var global$5 = tinymce.util.Tools.resolve('tinymce.dom.TreeWalker');
  408. var global$4 = tinymce.util.Tools.resolve('tinymce.util.VK');
  409. const fromDom = nodes => map(nodes, SugarElement.fromDom);
  410. const keys = Object.keys;
  411. const each = (obj, f) => {
  412. const props = keys(obj);
  413. for (let k = 0, len = props.length; k < len; k++) {
  414. const i = props[k];
  415. const x = obj[i];
  416. f(x, i);
  417. }
  418. };
  419. const objAcc = r => (x, i) => {
  420. r[i] = x;
  421. };
  422. const internalFilter = (obj, pred, onTrue, onFalse) => {
  423. each(obj, (x, i) => {
  424. (pred(x, i) ? onTrue : onFalse)(x, i);
  425. });
  426. };
  427. const filter = (obj, pred) => {
  428. const t = {};
  429. internalFilter(obj, pred, objAcc(t), noop);
  430. return t;
  431. };
  432. const rawSet = (dom, key, value) => {
  433. if (isString(value) || isBoolean(value) || isNumber(value)) {
  434. dom.setAttribute(key, value + '');
  435. } else {
  436. console.error('Invalid call to Attribute.set. Key ', key, ':: Value ', value, ':: Element ', dom);
  437. throw new Error('Attribute value was not simple');
  438. }
  439. };
  440. const setAll = (element, attrs) => {
  441. const dom = element.dom;
  442. each(attrs, (v, k) => {
  443. rawSet(dom, k, v);
  444. });
  445. };
  446. const clone$1 = element => foldl(element.dom.attributes, (acc, attr) => {
  447. acc[attr.name] = attr.value;
  448. return acc;
  449. }, {});
  450. const clone = (original, isDeep) => SugarElement.fromDom(original.dom.cloneNode(isDeep));
  451. const deep = original => clone(original, true);
  452. const shallowAs = (original, tag) => {
  453. const nu = SugarElement.fromTag(tag);
  454. const attributes = clone$1(original);
  455. setAll(nu, attributes);
  456. return nu;
  457. };
  458. const mutate = (original, tag) => {
  459. const nu = shallowAs(original, tag);
  460. after(original, nu);
  461. const children$1 = children(original);
  462. append(nu, children$1);
  463. remove(original);
  464. return nu;
  465. };
  466. var global$3 = tinymce.util.Tools.resolve('tinymce.dom.DOMUtils');
  467. var global$2 = tinymce.util.Tools.resolve('tinymce.util.Tools');
  468. const matchNodeName = name => node => isNonNullable(node) && node.nodeName.toLowerCase() === name;
  469. const matchNodeNames = regex => node => isNonNullable(node) && regex.test(node.nodeName);
  470. const isTextNode$1 = node => isNonNullable(node) && node.nodeType === 3;
  471. const isElement = node => isNonNullable(node) && node.nodeType === 1;
  472. const isListNode = matchNodeNames(/^(OL|UL|DL)$/);
  473. const isOlUlNode = matchNodeNames(/^(OL|UL)$/);
  474. const isOlNode = matchNodeName('ol');
  475. const isListItemNode = matchNodeNames(/^(LI|DT|DD)$/);
  476. const isDlItemNode = matchNodeNames(/^(DT|DD)$/);
  477. const isTableCellNode = matchNodeNames(/^(TH|TD)$/);
  478. const isBr = matchNodeName('br');
  479. const isFirstChild = node => {
  480. var _a;
  481. return ((_a = node.parentNode) === null || _a === void 0 ? void 0 : _a.firstChild) === node;
  482. };
  483. const isTextBlock = (editor, node) => isNonNullable(node) && node.nodeName in editor.schema.getTextBlockElements();
  484. const isBlock = (node, blockElements) => isNonNullable(node) && node.nodeName in blockElements;
  485. const isVoid = (editor, node) => isNonNullable(node) && node.nodeName in editor.schema.getVoidElements();
  486. const isBogusBr = (dom, node) => {
  487. if (!isBr(node)) {
  488. return false;
  489. }
  490. return dom.isBlock(node.nextSibling) && !isBr(node.previousSibling);
  491. };
  492. const isEmpty$2 = (dom, elm, keepBookmarks) => {
  493. const empty = dom.isEmpty(elm);
  494. if (keepBookmarks && dom.select('span[data-mce-type=bookmark]', elm).length > 0) {
  495. return false;
  496. }
  497. return empty;
  498. };
  499. const isChildOfBody = (dom, elm) => dom.isChildOf(elm, dom.getRoot());
  500. const option = name => editor => editor.options.get(name);
  501. const register$3 = editor => {
  502. const registerOption = editor.options.register;
  503. registerOption('lists_indent_on_tab', {
  504. processor: 'boolean',
  505. default: true
  506. });
  507. };
  508. const shouldIndentOnTab = option('lists_indent_on_tab');
  509. const getForcedRootBlock = option('forced_root_block');
  510. const getForcedRootBlockAttrs = option('forced_root_block_attrs');
  511. const createTextBlock = (editor, contentNode) => {
  512. const dom = editor.dom;
  513. const blockElements = editor.schema.getBlockElements();
  514. const fragment = dom.createFragment();
  515. const blockName = getForcedRootBlock(editor);
  516. const blockAttrs = getForcedRootBlockAttrs(editor);
  517. let node;
  518. let textBlock;
  519. let hasContentNode = false;
  520. textBlock = dom.create(blockName, blockAttrs);
  521. if (!isBlock(contentNode.firstChild, blockElements)) {
  522. fragment.appendChild(textBlock);
  523. }
  524. while (node = contentNode.firstChild) {
  525. const nodeName = node.nodeName;
  526. if (!hasContentNode && (nodeName !== 'SPAN' || node.getAttribute('data-mce-type') !== 'bookmark')) {
  527. hasContentNode = true;
  528. }
  529. if (isBlock(node, blockElements)) {
  530. fragment.appendChild(node);
  531. textBlock = null;
  532. } else {
  533. if (!textBlock) {
  534. textBlock = dom.create(blockName, blockAttrs);
  535. fragment.appendChild(textBlock);
  536. }
  537. textBlock.appendChild(node);
  538. }
  539. }
  540. if (!hasContentNode && textBlock) {
  541. textBlock.appendChild(dom.create('br', { 'data-mce-bogus': '1' }));
  542. }
  543. return fragment;
  544. };
  545. const DOM$2 = global$3.DOM;
  546. const splitList = (editor, list, li) => {
  547. const removeAndKeepBookmarks = targetNode => {
  548. const parent = targetNode.parentNode;
  549. if (parent) {
  550. global$2.each(bookmarks, node => {
  551. parent.insertBefore(node, li.parentNode);
  552. });
  553. }
  554. DOM$2.remove(targetNode);
  555. };
  556. const bookmarks = DOM$2.select('span[data-mce-type="bookmark"]', list);
  557. const newBlock = createTextBlock(editor, li);
  558. const tmpRng = DOM$2.createRng();
  559. tmpRng.setStartAfter(li);
  560. tmpRng.setEndAfter(list);
  561. const fragment = tmpRng.extractContents();
  562. for (let node = fragment.firstChild; node; node = node.firstChild) {
  563. if (node.nodeName === 'LI' && editor.dom.isEmpty(node)) {
  564. DOM$2.remove(node);
  565. break;
  566. }
  567. }
  568. if (!editor.dom.isEmpty(fragment)) {
  569. DOM$2.insertAfter(fragment, list);
  570. }
  571. DOM$2.insertAfter(newBlock, list);
  572. const parent = li.parentElement;
  573. if (parent && isEmpty$2(editor.dom, parent)) {
  574. removeAndKeepBookmarks(parent);
  575. }
  576. DOM$2.remove(li);
  577. if (isEmpty$2(editor.dom, list)) {
  578. DOM$2.remove(list);
  579. }
  580. };
  581. const isDescriptionDetail = isTag('dd');
  582. const isDescriptionTerm = isTag('dt');
  583. const outdentDlItem = (editor, item) => {
  584. if (isDescriptionDetail(item)) {
  585. mutate(item, 'dt');
  586. } else if (isDescriptionTerm(item)) {
  587. parentElement(item).each(dl => splitList(editor, dl.dom, item.dom));
  588. }
  589. };
  590. const indentDlItem = item => {
  591. if (isDescriptionTerm(item)) {
  592. mutate(item, 'dd');
  593. }
  594. };
  595. const dlIndentation = (editor, indentation, dlItems) => {
  596. if (indentation === 'Indent') {
  597. each$1(dlItems, indentDlItem);
  598. } else {
  599. each$1(dlItems, item => outdentDlItem(editor, item));
  600. }
  601. };
  602. const getNormalizedPoint = (container, offset) => {
  603. if (isTextNode$1(container)) {
  604. return {
  605. container,
  606. offset
  607. };
  608. }
  609. const node = global$6.getNode(container, offset);
  610. if (isTextNode$1(node)) {
  611. return {
  612. container: node,
  613. offset: offset >= container.childNodes.length ? node.data.length : 0
  614. };
  615. } else if (node.previousSibling && isTextNode$1(node.previousSibling)) {
  616. return {
  617. container: node.previousSibling,
  618. offset: node.previousSibling.data.length
  619. };
  620. } else if (node.nextSibling && isTextNode$1(node.nextSibling)) {
  621. return {
  622. container: node.nextSibling,
  623. offset: 0
  624. };
  625. }
  626. return {
  627. container,
  628. offset
  629. };
  630. };
  631. const normalizeRange = rng => {
  632. const outRng = rng.cloneRange();
  633. const rangeStart = getNormalizedPoint(rng.startContainer, rng.startOffset);
  634. outRng.setStart(rangeStart.container, rangeStart.offset);
  635. const rangeEnd = getNormalizedPoint(rng.endContainer, rng.endOffset);
  636. outRng.setEnd(rangeEnd.container, rangeEnd.offset);
  637. return outRng;
  638. };
  639. const listNames = [
  640. 'OL',
  641. 'UL',
  642. 'DL'
  643. ];
  644. const listSelector = listNames.join(',');
  645. const getParentList = (editor, node) => {
  646. const selectionStart = node || editor.selection.getStart(true);
  647. return editor.dom.getParent(selectionStart, listSelector, getClosestListHost(editor, selectionStart));
  648. };
  649. const isParentListSelected = (parentList, selectedBlocks) => isNonNullable(parentList) && selectedBlocks.length === 1 && selectedBlocks[0] === parentList;
  650. const findSubLists = parentList => filter$1(parentList.querySelectorAll(listSelector), isListNode);
  651. const getSelectedSubLists = editor => {
  652. const parentList = getParentList(editor);
  653. const selectedBlocks = editor.selection.getSelectedBlocks();
  654. if (isParentListSelected(parentList, selectedBlocks)) {
  655. return findSubLists(parentList);
  656. } else {
  657. return filter$1(selectedBlocks, elm => {
  658. return isListNode(elm) && parentList !== elm;
  659. });
  660. }
  661. };
  662. const findParentListItemsNodes = (editor, elms) => {
  663. const listItemsElms = global$2.map(elms, elm => {
  664. const parentLi = editor.dom.getParent(elm, 'li,dd,dt', getClosestListHost(editor, elm));
  665. return parentLi ? parentLi : elm;
  666. });
  667. return unique(listItemsElms);
  668. };
  669. const getSelectedListItems = editor => {
  670. const selectedBlocks = editor.selection.getSelectedBlocks();
  671. return filter$1(findParentListItemsNodes(editor, selectedBlocks), isListItemNode);
  672. };
  673. const getSelectedDlItems = editor => filter$1(getSelectedListItems(editor), isDlItemNode);
  674. const getClosestEditingHost = (editor, elm) => {
  675. const parentTableCell = editor.dom.getParents(elm, 'TD,TH');
  676. return parentTableCell.length > 0 ? parentTableCell[0] : editor.getBody();
  677. };
  678. const isListHost = (schema, node) => !isListNode(node) && !isListItemNode(node) && exists(listNames, listName => schema.isValidChild(node.nodeName, listName));
  679. const getClosestListHost = (editor, elm) => {
  680. const parentBlocks = editor.dom.getParents(elm, editor.dom.isBlock);
  681. const parentBlock = find(parentBlocks, elm => isListHost(editor.schema, elm));
  682. return parentBlock.getOr(editor.getBody());
  683. };
  684. const findLastParentListNode = (editor, elm) => {
  685. const parentLists = editor.dom.getParents(elm, 'ol,ul', getClosestListHost(editor, elm));
  686. return last(parentLists);
  687. };
  688. const getSelectedLists = editor => {
  689. const firstList = findLastParentListNode(editor, editor.selection.getStart());
  690. const subsequentLists = filter$1(editor.selection.getSelectedBlocks(), isOlUlNode);
  691. return firstList.toArray().concat(subsequentLists);
  692. };
  693. const getSelectedListRoots = editor => {
  694. const selectedLists = getSelectedLists(editor);
  695. return getUniqueListRoots(editor, selectedLists);
  696. };
  697. const getUniqueListRoots = (editor, lists) => {
  698. const listRoots = map(lists, list => findLastParentListNode(editor, list).getOr(list));
  699. return unique(listRoots);
  700. };
  701. const isCustomList = list => /\btox\-/.test(list.className);
  702. const inList = (parents, listName) => findUntil(parents, isListNode, isTableCellNode).exists(list => list.nodeName === listName && !isCustomList(list));
  703. const isWithinNonEditable = (editor, element) => element !== null && !editor.dom.isEditable(element);
  704. const selectionIsWithinNonEditableList = editor => {
  705. const parentList = getParentList(editor);
  706. return isWithinNonEditable(editor, parentList);
  707. };
  708. const isWithinNonEditableList = (editor, element) => {
  709. const parentList = editor.dom.getParent(element, 'ol,ul,dl');
  710. return isWithinNonEditable(editor, parentList);
  711. };
  712. const hasNonEditableBlocksSelected = editor => exists(editor.selection.getSelectedBlocks(), not(editor.dom.isEditable));
  713. const setNodeChangeHandler = (editor, nodeChangeHandler) => {
  714. const initialNode = editor.selection.getNode();
  715. nodeChangeHandler({
  716. parents: editor.dom.getParents(initialNode),
  717. element: initialNode
  718. });
  719. editor.on('NodeChange', nodeChangeHandler);
  720. return () => editor.off('NodeChange', nodeChangeHandler);
  721. };
  722. const fromElements = (elements, scope) => {
  723. const doc = scope || document;
  724. const fragment = doc.createDocumentFragment();
  725. each$1(elements, element => {
  726. fragment.appendChild(element.dom);
  727. });
  728. return SugarElement.fromDom(fragment);
  729. };
  730. const fireListEvent = (editor, action, element) => editor.dispatch('ListMutation', {
  731. action,
  732. element
  733. });
  734. const blank = r => s => s.replace(r, '');
  735. const trim = blank(/^\s+|\s+$/g);
  736. const isNotEmpty = s => s.length > 0;
  737. const isEmpty$1 = s => !isNotEmpty(s);
  738. const isSupported = dom => dom.style !== undefined && isFunction(dom.style.getPropertyValue);
  739. const internalSet = (dom, property, value) => {
  740. if (!isString(value)) {
  741. console.error('Invalid call to CSS.set. Property ', property, ':: Value ', value, ':: Element ', dom);
  742. throw new Error('CSS value must be a string: ' + value);
  743. }
  744. if (isSupported(dom)) {
  745. dom.style.setProperty(property, value);
  746. }
  747. };
  748. const set = (element, property, value) => {
  749. const dom = element.dom;
  750. internalSet(dom, property, value);
  751. };
  752. const joinSegment = (parent, child) => {
  753. append$1(parent.item, child.list);
  754. };
  755. const joinSegments = segments => {
  756. for (let i = 1; i < segments.length; i++) {
  757. joinSegment(segments[i - 1], segments[i]);
  758. }
  759. };
  760. const appendSegments = (head$1, tail) => {
  761. lift2(last(head$1), head(tail), joinSegment);
  762. };
  763. const createSegment = (scope, listType) => {
  764. const segment = {
  765. list: SugarElement.fromTag(listType, scope),
  766. item: SugarElement.fromTag('li', scope)
  767. };
  768. append$1(segment.list, segment.item);
  769. return segment;
  770. };
  771. const createSegments = (scope, entry, size) => {
  772. const segments = [];
  773. for (let i = 0; i < size; i++) {
  774. segments.push(createSegment(scope, entry.listType));
  775. }
  776. return segments;
  777. };
  778. const populateSegments = (segments, entry) => {
  779. for (let i = 0; i < segments.length - 1; i++) {
  780. set(segments[i].item, 'list-style-type', 'none');
  781. }
  782. last(segments).each(segment => {
  783. setAll(segment.list, entry.listAttributes);
  784. setAll(segment.item, entry.itemAttributes);
  785. append(segment.item, entry.content);
  786. });
  787. };
  788. const normalizeSegment = (segment, entry) => {
  789. if (name(segment.list) !== entry.listType) {
  790. segment.list = mutate(segment.list, entry.listType);
  791. }
  792. setAll(segment.list, entry.listAttributes);
  793. };
  794. const createItem = (scope, attr, content) => {
  795. const item = SugarElement.fromTag('li', scope);
  796. setAll(item, attr);
  797. append(item, content);
  798. return item;
  799. };
  800. const appendItem = (segment, item) => {
  801. append$1(segment.list, item);
  802. segment.item = item;
  803. };
  804. const writeShallow = (scope, cast, entry) => {
  805. const newCast = cast.slice(0, entry.depth);
  806. last(newCast).each(segment => {
  807. const item = createItem(scope, entry.itemAttributes, entry.content);
  808. appendItem(segment, item);
  809. normalizeSegment(segment, entry);
  810. });
  811. return newCast;
  812. };
  813. const writeDeep = (scope, cast, entry) => {
  814. const segments = createSegments(scope, entry, entry.depth - cast.length);
  815. joinSegments(segments);
  816. populateSegments(segments, entry);
  817. appendSegments(cast, segments);
  818. return cast.concat(segments);
  819. };
  820. const composeList = (scope, entries) => {
  821. const cast = foldl(entries, (cast, entry) => {
  822. return entry.depth > cast.length ? writeDeep(scope, cast, entry) : writeShallow(scope, cast, entry);
  823. }, []);
  824. return head(cast).map(segment => segment.list);
  825. };
  826. const isList = el => is(el, 'OL,UL');
  827. const hasFirstChildList = el => firstChild(el).exists(isList);
  828. const hasLastChildList = el => lastChild(el).exists(isList);
  829. const isIndented = entry => entry.depth > 0;
  830. const isSelected = entry => entry.isSelected;
  831. const cloneItemContent = li => {
  832. const children$1 = children(li);
  833. const content = hasLastChildList(li) ? children$1.slice(0, -1) : children$1;
  834. return map(content, deep);
  835. };
  836. const createEntry = (li, depth, isSelected) => parent(li).filter(isElement$1).map(list => ({
  837. depth,
  838. dirty: false,
  839. isSelected,
  840. content: cloneItemContent(li),
  841. itemAttributes: clone$1(li),
  842. listAttributes: clone$1(list),
  843. listType: name(list)
  844. }));
  845. const indentEntry = (indentation, entry) => {
  846. switch (indentation) {
  847. case 'Indent':
  848. entry.depth++;
  849. break;
  850. case 'Outdent':
  851. entry.depth--;
  852. break;
  853. case 'Flatten':
  854. entry.depth = 0;
  855. }
  856. entry.dirty = true;
  857. };
  858. const cloneListProperties = (target, source) => {
  859. target.listType = source.listType;
  860. target.listAttributes = { ...source.listAttributes };
  861. };
  862. const cleanListProperties = entry => {
  863. entry.listAttributes = filter(entry.listAttributes, (_value, key) => key !== 'start');
  864. };
  865. const closestSiblingEntry = (entries, start) => {
  866. const depth = entries[start].depth;
  867. const matches = entry => entry.depth === depth && !entry.dirty;
  868. const until = entry => entry.depth < depth;
  869. return findUntil(reverse(entries.slice(0, start)), matches, until).orThunk(() => findUntil(entries.slice(start + 1), matches, until));
  870. };
  871. const normalizeEntries = entries => {
  872. each$1(entries, (entry, i) => {
  873. closestSiblingEntry(entries, i).fold(() => {
  874. if (entry.dirty) {
  875. cleanListProperties(entry);
  876. }
  877. }, matchingEntry => cloneListProperties(entry, matchingEntry));
  878. });
  879. return entries;
  880. };
  881. const Cell = initial => {
  882. let value = initial;
  883. const get = () => {
  884. return value;
  885. };
  886. const set = v => {
  887. value = v;
  888. };
  889. return {
  890. get,
  891. set
  892. };
  893. };
  894. const parseItem = (depth, itemSelection, selectionState, item) => firstChild(item).filter(isList).fold(() => {
  895. itemSelection.each(selection => {
  896. if (eq(selection.start, item)) {
  897. selectionState.set(true);
  898. }
  899. });
  900. const currentItemEntry = createEntry(item, depth, selectionState.get());
  901. itemSelection.each(selection => {
  902. if (eq(selection.end, item)) {
  903. selectionState.set(false);
  904. }
  905. });
  906. const childListEntries = lastChild(item).filter(isList).map(list => parseList(depth, itemSelection, selectionState, list)).getOr([]);
  907. return currentItemEntry.toArray().concat(childListEntries);
  908. }, list => parseList(depth, itemSelection, selectionState, list));
  909. const parseList = (depth, itemSelection, selectionState, list) => bind(children(list), element => {
  910. const parser = isList(element) ? parseList : parseItem;
  911. const newDepth = depth + 1;
  912. return parser(newDepth, itemSelection, selectionState, element);
  913. });
  914. const parseLists = (lists, itemSelection) => {
  915. const selectionState = Cell(false);
  916. const initialDepth = 0;
  917. return map(lists, list => ({
  918. sourceList: list,
  919. entries: parseList(initialDepth, itemSelection, selectionState, list)
  920. }));
  921. };
  922. const outdentedComposer = (editor, entries) => {
  923. const normalizedEntries = normalizeEntries(entries);
  924. return map(normalizedEntries, entry => {
  925. const content = fromElements(entry.content);
  926. return SugarElement.fromDom(createTextBlock(editor, content.dom));
  927. });
  928. };
  929. const indentedComposer = (editor, entries) => {
  930. const normalizedEntries = normalizeEntries(entries);
  931. return composeList(editor.contentDocument, normalizedEntries).toArray();
  932. };
  933. const composeEntries = (editor, entries) => bind(groupBy(entries, isIndented), entries => {
  934. const groupIsIndented = head(entries).exists(isIndented);
  935. return groupIsIndented ? indentedComposer(editor, entries) : outdentedComposer(editor, entries);
  936. });
  937. const indentSelectedEntries = (entries, indentation) => {
  938. each$1(filter$1(entries, isSelected), entry => indentEntry(indentation, entry));
  939. };
  940. const getItemSelection = editor => {
  941. const selectedListItems = map(getSelectedListItems(editor), SugarElement.fromDom);
  942. return lift2(find(selectedListItems, not(hasFirstChildList)), find(reverse(selectedListItems), not(hasFirstChildList)), (start, end) => ({
  943. start,
  944. end
  945. }));
  946. };
  947. const listIndentation = (editor, lists, indentation) => {
  948. const entrySets = parseLists(lists, getItemSelection(editor));
  949. each$1(entrySets, entrySet => {
  950. indentSelectedEntries(entrySet.entries, indentation);
  951. const composedLists = composeEntries(editor, entrySet.entries);
  952. each$1(composedLists, composedList => {
  953. fireListEvent(editor, indentation === 'Indent' ? 'IndentList' : 'OutdentList', composedList.dom);
  954. });
  955. before(entrySet.sourceList, composedLists);
  956. remove(entrySet.sourceList);
  957. });
  958. };
  959. const selectionIndentation = (editor, indentation) => {
  960. const lists = fromDom(getSelectedListRoots(editor));
  961. const dlItems = fromDom(getSelectedDlItems(editor));
  962. let isHandled = false;
  963. if (lists.length || dlItems.length) {
  964. const bookmark = editor.selection.getBookmark();
  965. listIndentation(editor, lists, indentation);
  966. dlIndentation(editor, indentation, dlItems);
  967. editor.selection.moveToBookmark(bookmark);
  968. editor.selection.setRng(normalizeRange(editor.selection.getRng()));
  969. editor.nodeChanged();
  970. isHandled = true;
  971. }
  972. return isHandled;
  973. };
  974. const handleIndentation = (editor, indentation) => !selectionIsWithinNonEditableList(editor) && selectionIndentation(editor, indentation);
  975. const indentListSelection = editor => handleIndentation(editor, 'Indent');
  976. const outdentListSelection = editor => handleIndentation(editor, 'Outdent');
  977. const flattenListSelection = editor => handleIndentation(editor, 'Flatten');
  978. const zeroWidth = '\uFEFF';
  979. const isZwsp = char => char === zeroWidth;
  980. var global$1 = tinymce.util.Tools.resolve('tinymce.dom.BookmarkManager');
  981. const DOM$1 = global$3.DOM;
  982. const createBookmark = rng => {
  983. const bookmark = {};
  984. const setupEndPoint = start => {
  985. let container = rng[start ? 'startContainer' : 'endContainer'];
  986. let offset = rng[start ? 'startOffset' : 'endOffset'];
  987. if (isElement(container)) {
  988. const offsetNode = DOM$1.create('span', { 'data-mce-type': 'bookmark' });
  989. if (container.hasChildNodes()) {
  990. offset = Math.min(offset, container.childNodes.length - 1);
  991. if (start) {
  992. container.insertBefore(offsetNode, container.childNodes[offset]);
  993. } else {
  994. DOM$1.insertAfter(offsetNode, container.childNodes[offset]);
  995. }
  996. } else {
  997. container.appendChild(offsetNode);
  998. }
  999. container = offsetNode;
  1000. offset = 0;
  1001. }
  1002. bookmark[start ? 'startContainer' : 'endContainer'] = container;
  1003. bookmark[start ? 'startOffset' : 'endOffset'] = offset;
  1004. };
  1005. setupEndPoint(true);
  1006. if (!rng.collapsed) {
  1007. setupEndPoint();
  1008. }
  1009. return bookmark;
  1010. };
  1011. const resolveBookmark = bookmark => {
  1012. const restoreEndPoint = start => {
  1013. const nodeIndex = container => {
  1014. var _a;
  1015. let node = (_a = container.parentNode) === null || _a === void 0 ? void 0 : _a.firstChild;
  1016. let idx = 0;
  1017. while (node) {
  1018. if (node === container) {
  1019. return idx;
  1020. }
  1021. if (!isElement(node) || node.getAttribute('data-mce-type') !== 'bookmark') {
  1022. idx++;
  1023. }
  1024. node = node.nextSibling;
  1025. }
  1026. return -1;
  1027. };
  1028. let container = bookmark[start ? 'startContainer' : 'endContainer'];
  1029. let offset = bookmark[start ? 'startOffset' : 'endOffset'];
  1030. if (!container) {
  1031. return;
  1032. }
  1033. if (isElement(container) && container.parentNode) {
  1034. const node = container;
  1035. offset = nodeIndex(container);
  1036. container = container.parentNode;
  1037. DOM$1.remove(node);
  1038. if (!container.hasChildNodes() && DOM$1.isBlock(container)) {
  1039. container.appendChild(DOM$1.create('br'));
  1040. }
  1041. }
  1042. bookmark[start ? 'startContainer' : 'endContainer'] = container;
  1043. bookmark[start ? 'startOffset' : 'endOffset'] = offset;
  1044. };
  1045. restoreEndPoint(true);
  1046. restoreEndPoint();
  1047. const rng = DOM$1.createRng();
  1048. rng.setStart(bookmark.startContainer, bookmark.startOffset);
  1049. if (bookmark.endContainer) {
  1050. rng.setEnd(bookmark.endContainer, bookmark.endOffset);
  1051. }
  1052. return normalizeRange(rng);
  1053. };
  1054. const listToggleActionFromListName = listName => {
  1055. switch (listName) {
  1056. case 'UL':
  1057. return 'ToggleUlList';
  1058. case 'OL':
  1059. return 'ToggleOlList';
  1060. case 'DL':
  1061. return 'ToggleDLList';
  1062. }
  1063. };
  1064. const updateListStyle = (dom, el, detail) => {
  1065. const type = detail['list-style-type'] ? detail['list-style-type'] : null;
  1066. dom.setStyle(el, 'list-style-type', type);
  1067. };
  1068. const setAttribs = (elm, attrs) => {
  1069. global$2.each(attrs, (value, key) => {
  1070. elm.setAttribute(key, value);
  1071. });
  1072. };
  1073. const updateListAttrs = (dom, el, detail) => {
  1074. setAttribs(el, detail['list-attributes']);
  1075. global$2.each(dom.select('li', el), li => {
  1076. setAttribs(li, detail['list-item-attributes']);
  1077. });
  1078. };
  1079. const updateListWithDetails = (dom, el, detail) => {
  1080. updateListStyle(dom, el, detail);
  1081. updateListAttrs(dom, el, detail);
  1082. };
  1083. const removeStyles = (dom, element, styles) => {
  1084. global$2.each(styles, style => dom.setStyle(element, style, ''));
  1085. };
  1086. const isInline = (editor, node) => isNonNullable(node) && !isBlock(node, editor.schema.getBlockElements());
  1087. const getEndPointNode = (editor, rng, start, root) => {
  1088. let container = rng[start ? 'startContainer' : 'endContainer'];
  1089. const offset = rng[start ? 'startOffset' : 'endOffset'];
  1090. if (isElement(container)) {
  1091. container = container.childNodes[Math.min(offset, container.childNodes.length - 1)] || container;
  1092. }
  1093. if (!start && isBr(container.nextSibling)) {
  1094. container = container.nextSibling;
  1095. }
  1096. const findBetterContainer = (container, forward) => {
  1097. var _a;
  1098. const walker = new global$5(container, root);
  1099. const dir = forward ? 'next' : 'prev';
  1100. let node;
  1101. while (node = walker[dir]()) {
  1102. if (!(isVoid(editor, node) || isZwsp(node.textContent) || ((_a = node.textContent) === null || _a === void 0 ? void 0 : _a.length) === 0)) {
  1103. return Optional.some(node);
  1104. }
  1105. }
  1106. return Optional.none();
  1107. };
  1108. if (start && isTextNode$1(container)) {
  1109. if (isZwsp(container.textContent)) {
  1110. container = findBetterContainer(container, false).getOr(container);
  1111. } else {
  1112. if (container.parentNode !== null && isInline(editor, container.parentNode)) {
  1113. container = container.parentNode;
  1114. }
  1115. while (container.previousSibling !== null && (isInline(editor, container.previousSibling) || isTextNode$1(container.previousSibling))) {
  1116. container = container.previousSibling;
  1117. }
  1118. }
  1119. }
  1120. if (!start && isTextNode$1(container)) {
  1121. if (isZwsp(container.textContent)) {
  1122. container = findBetterContainer(container, true).getOr(container);
  1123. } else {
  1124. if (container.parentNode !== null && isInline(editor, container.parentNode)) {
  1125. container = container.parentNode;
  1126. }
  1127. while (container.nextSibling !== null && (isInline(editor, container.nextSibling) || isTextNode$1(container.nextSibling))) {
  1128. container = container.nextSibling;
  1129. }
  1130. }
  1131. }
  1132. while (container.parentNode !== root) {
  1133. const parent = container.parentNode;
  1134. if (isTextBlock(editor, container)) {
  1135. return container;
  1136. }
  1137. if (/^(TD|TH)$/.test(parent.nodeName)) {
  1138. return container;
  1139. }
  1140. container = parent;
  1141. }
  1142. return container;
  1143. };
  1144. const getSelectedTextBlocks = (editor, rng, root) => {
  1145. const textBlocks = [];
  1146. const dom = editor.dom;
  1147. const startNode = getEndPointNode(editor, rng, true, root);
  1148. const endNode = getEndPointNode(editor, rng, false, root);
  1149. let block;
  1150. const siblings = [];
  1151. for (let node = startNode; node; node = node.nextSibling) {
  1152. siblings.push(node);
  1153. if (node === endNode) {
  1154. break;
  1155. }
  1156. }
  1157. global$2.each(siblings, node => {
  1158. var _a;
  1159. if (isTextBlock(editor, node)) {
  1160. textBlocks.push(node);
  1161. block = null;
  1162. return;
  1163. }
  1164. if (dom.isBlock(node) || isBr(node)) {
  1165. if (isBr(node)) {
  1166. dom.remove(node);
  1167. }
  1168. block = null;
  1169. return;
  1170. }
  1171. const nextSibling = node.nextSibling;
  1172. if (global$1.isBookmarkNode(node)) {
  1173. if (isListNode(nextSibling) || isTextBlock(editor, nextSibling) || !nextSibling && node.parentNode === root) {
  1174. block = null;
  1175. return;
  1176. }
  1177. }
  1178. if (!block) {
  1179. block = dom.create('p');
  1180. (_a = node.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(block, node);
  1181. textBlocks.push(block);
  1182. }
  1183. block.appendChild(node);
  1184. });
  1185. return textBlocks;
  1186. };
  1187. const hasCompatibleStyle = (dom, sib, detail) => {
  1188. const sibStyle = dom.getStyle(sib, 'list-style-type');
  1189. let detailStyle = detail ? detail['list-style-type'] : '';
  1190. detailStyle = detailStyle === null ? '' : detailStyle;
  1191. return sibStyle === detailStyle;
  1192. };
  1193. const applyList = (editor, listName, detail) => {
  1194. const rng = editor.selection.getRng();
  1195. let listItemName = 'LI';
  1196. const root = getClosestListHost(editor, editor.selection.getStart(true));
  1197. const dom = editor.dom;
  1198. if (dom.getContentEditable(editor.selection.getNode()) === 'false') {
  1199. return;
  1200. }
  1201. listName = listName.toUpperCase();
  1202. if (listName === 'DL') {
  1203. listItemName = 'DT';
  1204. }
  1205. const bookmark = createBookmark(rng);
  1206. const selectedTextBlocks = getSelectedTextBlocks(editor, rng, root);
  1207. global$2.each(selectedTextBlocks, block => {
  1208. let listBlock;
  1209. const sibling = block.previousSibling;
  1210. const parent = block.parentNode;
  1211. if (!isListItemNode(parent)) {
  1212. if (sibling && isListNode(sibling) && sibling.nodeName === listName && hasCompatibleStyle(dom, sibling, detail)) {
  1213. listBlock = sibling;
  1214. block = dom.rename(block, listItemName);
  1215. sibling.appendChild(block);
  1216. } else {
  1217. listBlock = dom.create(listName);
  1218. parent.insertBefore(listBlock, block);
  1219. listBlock.appendChild(block);
  1220. block = dom.rename(block, listItemName);
  1221. }
  1222. removeStyles(dom, block, [
  1223. 'margin',
  1224. 'margin-right',
  1225. 'margin-bottom',
  1226. 'margin-left',
  1227. 'margin-top',
  1228. 'padding',
  1229. 'padding-right',
  1230. 'padding-bottom',
  1231. 'padding-left',
  1232. 'padding-top'
  1233. ]);
  1234. updateListWithDetails(dom, listBlock, detail);
  1235. mergeWithAdjacentLists(editor.dom, listBlock);
  1236. }
  1237. });
  1238. editor.selection.setRng(resolveBookmark(bookmark));
  1239. };
  1240. const isValidLists = (list1, list2) => {
  1241. return isListNode(list1) && list1.nodeName === (list2 === null || list2 === void 0 ? void 0 : list2.nodeName);
  1242. };
  1243. const hasSameListStyle = (dom, list1, list2) => {
  1244. const targetStyle = dom.getStyle(list1, 'list-style-type', true);
  1245. const style = dom.getStyle(list2, 'list-style-type', true);
  1246. return targetStyle === style;
  1247. };
  1248. const hasSameClasses = (elm1, elm2) => {
  1249. return elm1.className === elm2.className;
  1250. };
  1251. const shouldMerge = (dom, list1, list2) => {
  1252. return isValidLists(list1, list2) && hasSameListStyle(dom, list1, list2) && hasSameClasses(list1, list2);
  1253. };
  1254. const mergeWithAdjacentLists = (dom, listBlock) => {
  1255. let node;
  1256. let sibling = listBlock.nextSibling;
  1257. if (shouldMerge(dom, listBlock, sibling)) {
  1258. const liSibling = sibling;
  1259. while (node = liSibling.firstChild) {
  1260. listBlock.appendChild(node);
  1261. }
  1262. dom.remove(liSibling);
  1263. }
  1264. sibling = listBlock.previousSibling;
  1265. if (shouldMerge(dom, listBlock, sibling)) {
  1266. const liSibling = sibling;
  1267. while (node = liSibling.lastChild) {
  1268. listBlock.insertBefore(node, listBlock.firstChild);
  1269. }
  1270. dom.remove(liSibling);
  1271. }
  1272. };
  1273. const updateList$1 = (editor, list, listName, detail) => {
  1274. if (list.nodeName !== listName) {
  1275. const newList = editor.dom.rename(list, listName);
  1276. updateListWithDetails(editor.dom, newList, detail);
  1277. fireListEvent(editor, listToggleActionFromListName(listName), newList);
  1278. } else {
  1279. updateListWithDetails(editor.dom, list, detail);
  1280. fireListEvent(editor, listToggleActionFromListName(listName), list);
  1281. }
  1282. };
  1283. const toggleMultipleLists = (editor, parentList, lists, listName, detail) => {
  1284. const parentIsList = isListNode(parentList);
  1285. if (parentIsList && parentList.nodeName === listName && !hasListStyleDetail(detail)) {
  1286. flattenListSelection(editor);
  1287. } else {
  1288. applyList(editor, listName, detail);
  1289. const bookmark = createBookmark(editor.selection.getRng());
  1290. const allLists = parentIsList ? [
  1291. parentList,
  1292. ...lists
  1293. ] : lists;
  1294. global$2.each(allLists, elm => {
  1295. updateList$1(editor, elm, listName, detail);
  1296. });
  1297. editor.selection.setRng(resolveBookmark(bookmark));
  1298. }
  1299. };
  1300. const hasListStyleDetail = detail => {
  1301. return 'list-style-type' in detail;
  1302. };
  1303. const toggleSingleList = (editor, parentList, listName, detail) => {
  1304. if (parentList === editor.getBody()) {
  1305. return;
  1306. }
  1307. if (parentList) {
  1308. if (parentList.nodeName === listName && !hasListStyleDetail(detail) && !isCustomList(parentList)) {
  1309. flattenListSelection(editor);
  1310. } else {
  1311. const bookmark = createBookmark(editor.selection.getRng());
  1312. updateListWithDetails(editor.dom, parentList, detail);
  1313. const newList = editor.dom.rename(parentList, listName);
  1314. mergeWithAdjacentLists(editor.dom, newList);
  1315. editor.selection.setRng(resolveBookmark(bookmark));
  1316. applyList(editor, listName, detail);
  1317. fireListEvent(editor, listToggleActionFromListName(listName), newList);
  1318. }
  1319. } else {
  1320. applyList(editor, listName, detail);
  1321. fireListEvent(editor, listToggleActionFromListName(listName), parentList);
  1322. }
  1323. };
  1324. const toggleList = (editor, listName, _detail) => {
  1325. const parentList = getParentList(editor);
  1326. if (isWithinNonEditableList(editor, parentList) || hasNonEditableBlocksSelected(editor)) {
  1327. return;
  1328. }
  1329. const selectedSubLists = getSelectedSubLists(editor);
  1330. const detail = isObject(_detail) ? _detail : {};
  1331. if (selectedSubLists.length > 0) {
  1332. toggleMultipleLists(editor, parentList, selectedSubLists, listName, detail);
  1333. } else {
  1334. toggleSingleList(editor, parentList, listName, detail);
  1335. }
  1336. };
  1337. const DOM = global$3.DOM;
  1338. const normalizeList = (dom, list) => {
  1339. const parentNode = list.parentElement;
  1340. if (parentNode && parentNode.nodeName === 'LI' && parentNode.firstChild === list) {
  1341. const sibling = parentNode.previousSibling;
  1342. if (sibling && sibling.nodeName === 'LI') {
  1343. sibling.appendChild(list);
  1344. if (isEmpty$2(dom, parentNode)) {
  1345. DOM.remove(parentNode);
  1346. }
  1347. } else {
  1348. DOM.setStyle(parentNode, 'listStyleType', 'none');
  1349. }
  1350. }
  1351. if (isListNode(parentNode)) {
  1352. const sibling = parentNode.previousSibling;
  1353. if (sibling && sibling.nodeName === 'LI') {
  1354. sibling.appendChild(list);
  1355. }
  1356. }
  1357. };
  1358. const normalizeLists = (dom, element) => {
  1359. const lists = global$2.grep(dom.select('ol,ul', element));
  1360. global$2.each(lists, list => {
  1361. normalizeList(dom, list);
  1362. });
  1363. };
  1364. const findNextCaretContainer = (editor, rng, isForward, root) => {
  1365. let node = rng.startContainer;
  1366. const offset = rng.startOffset;
  1367. if (isTextNode$1(node) && (isForward ? offset < node.data.length : offset > 0)) {
  1368. return node;
  1369. }
  1370. const nonEmptyBlocks = editor.schema.getNonEmptyElements();
  1371. if (isElement(node)) {
  1372. node = global$6.getNode(node, offset);
  1373. }
  1374. const walker = new global$5(node, root);
  1375. if (isForward) {
  1376. if (isBogusBr(editor.dom, node)) {
  1377. walker.next();
  1378. }
  1379. }
  1380. const walkFn = isForward ? walker.next.bind(walker) : walker.prev2.bind(walker);
  1381. while (node = walkFn()) {
  1382. if (node.nodeName === 'LI' && !node.hasChildNodes()) {
  1383. return node;
  1384. }
  1385. if (nonEmptyBlocks[node.nodeName]) {
  1386. return node;
  1387. }
  1388. if (isTextNode$1(node) && node.data.length > 0) {
  1389. return node;
  1390. }
  1391. }
  1392. return null;
  1393. };
  1394. const hasOnlyOneBlockChild = (dom, elm) => {
  1395. const childNodes = elm.childNodes;
  1396. return childNodes.length === 1 && !isListNode(childNodes[0]) && dom.isBlock(childNodes[0]);
  1397. };
  1398. const unwrapSingleBlockChild = (dom, elm) => {
  1399. if (hasOnlyOneBlockChild(dom, elm)) {
  1400. dom.remove(elm.firstChild, true);
  1401. }
  1402. };
  1403. const moveChildren = (dom, fromElm, toElm) => {
  1404. let node;
  1405. const targetElm = hasOnlyOneBlockChild(dom, toElm) ? toElm.firstChild : toElm;
  1406. unwrapSingleBlockChild(dom, fromElm);
  1407. if (!isEmpty$2(dom, fromElm, true)) {
  1408. while (node = fromElm.firstChild) {
  1409. targetElm.appendChild(node);
  1410. }
  1411. }
  1412. };
  1413. const mergeLiElements = (dom, fromElm, toElm) => {
  1414. let listNode;
  1415. const ul = fromElm.parentNode;
  1416. if (!isChildOfBody(dom, fromElm) || !isChildOfBody(dom, toElm)) {
  1417. return;
  1418. }
  1419. if (isListNode(toElm.lastChild)) {
  1420. listNode = toElm.lastChild;
  1421. }
  1422. if (ul === toElm.lastChild) {
  1423. if (isBr(ul.previousSibling)) {
  1424. dom.remove(ul.previousSibling);
  1425. }
  1426. }
  1427. const node = toElm.lastChild;
  1428. if (node && isBr(node) && fromElm.hasChildNodes()) {
  1429. dom.remove(node);
  1430. }
  1431. if (isEmpty$2(dom, toElm, true)) {
  1432. empty(SugarElement.fromDom(toElm));
  1433. }
  1434. moveChildren(dom, fromElm, toElm);
  1435. if (listNode) {
  1436. toElm.appendChild(listNode);
  1437. }
  1438. const contains$1 = contains(SugarElement.fromDom(toElm), SugarElement.fromDom(fromElm));
  1439. const nestedLists = contains$1 ? dom.getParents(fromElm, isListNode, toElm) : [];
  1440. dom.remove(fromElm);
  1441. each$1(nestedLists, list => {
  1442. if (isEmpty$2(dom, list) && list !== dom.getRoot()) {
  1443. dom.remove(list);
  1444. }
  1445. });
  1446. };
  1447. const mergeIntoEmptyLi = (editor, fromLi, toLi) => {
  1448. empty(SugarElement.fromDom(toLi));
  1449. mergeLiElements(editor.dom, fromLi, toLi);
  1450. editor.selection.setCursorLocation(toLi, 0);
  1451. };
  1452. const mergeForward = (editor, rng, fromLi, toLi) => {
  1453. const dom = editor.dom;
  1454. if (dom.isEmpty(toLi)) {
  1455. mergeIntoEmptyLi(editor, fromLi, toLi);
  1456. } else {
  1457. const bookmark = createBookmark(rng);
  1458. mergeLiElements(dom, fromLi, toLi);
  1459. editor.selection.setRng(resolveBookmark(bookmark));
  1460. }
  1461. };
  1462. const mergeBackward = (editor, rng, fromLi, toLi) => {
  1463. const bookmark = createBookmark(rng);
  1464. mergeLiElements(editor.dom, fromLi, toLi);
  1465. const resolvedBookmark = resolveBookmark(bookmark);
  1466. editor.selection.setRng(resolvedBookmark);
  1467. };
  1468. const backspaceDeleteFromListToListCaret = (editor, isForward) => {
  1469. const dom = editor.dom, selection = editor.selection;
  1470. const selectionStartElm = selection.getStart();
  1471. const root = getClosestEditingHost(editor, selectionStartElm);
  1472. const li = dom.getParent(selection.getStart(), 'LI', root);
  1473. if (li) {
  1474. const ul = li.parentElement;
  1475. if (ul === editor.getBody() && isEmpty$2(dom, ul)) {
  1476. return true;
  1477. }
  1478. const rng = normalizeRange(selection.getRng());
  1479. const otherLi = dom.getParent(findNextCaretContainer(editor, rng, isForward, root), 'LI', root);
  1480. if (otherLi && otherLi !== li) {
  1481. editor.undoManager.transact(() => {
  1482. if (isForward) {
  1483. mergeForward(editor, rng, otherLi, li);
  1484. } else {
  1485. if (isFirstChild(li)) {
  1486. outdentListSelection(editor);
  1487. } else {
  1488. mergeBackward(editor, rng, li, otherLi);
  1489. }
  1490. }
  1491. });
  1492. return true;
  1493. } else if (!otherLi) {
  1494. if (!isForward && rng.startOffset === 0 && rng.endOffset === 0) {
  1495. editor.undoManager.transact(() => {
  1496. flattenListSelection(editor);
  1497. });
  1498. return true;
  1499. }
  1500. }
  1501. }
  1502. return false;
  1503. };
  1504. const removeBlock = (dom, block, root) => {
  1505. const parentBlock = dom.getParent(block.parentNode, dom.isBlock, root);
  1506. dom.remove(block);
  1507. if (parentBlock && dom.isEmpty(parentBlock)) {
  1508. dom.remove(parentBlock);
  1509. }
  1510. };
  1511. const backspaceDeleteIntoListCaret = (editor, isForward) => {
  1512. const dom = editor.dom;
  1513. const selectionStartElm = editor.selection.getStart();
  1514. const root = getClosestEditingHost(editor, selectionStartElm);
  1515. const block = dom.getParent(selectionStartElm, dom.isBlock, root);
  1516. if (block && dom.isEmpty(block)) {
  1517. const rng = normalizeRange(editor.selection.getRng());
  1518. const otherLi = dom.getParent(findNextCaretContainer(editor, rng, isForward, root), 'LI', root);
  1519. if (otherLi) {
  1520. const findValidElement = element => contains$1([
  1521. 'td',
  1522. 'th',
  1523. 'caption'
  1524. ], name(element));
  1525. const findRoot = node => node.dom === root;
  1526. const otherLiCell = closest(SugarElement.fromDom(otherLi), findValidElement, findRoot);
  1527. const caretCell = closest(SugarElement.fromDom(rng.startContainer), findValidElement, findRoot);
  1528. if (!equals(otherLiCell, caretCell, eq)) {
  1529. return false;
  1530. }
  1531. editor.undoManager.transact(() => {
  1532. removeBlock(dom, block, root);
  1533. mergeWithAdjacentLists(dom, otherLi.parentNode);
  1534. editor.selection.select(otherLi, true);
  1535. editor.selection.collapse(isForward);
  1536. });
  1537. return true;
  1538. }
  1539. }
  1540. return false;
  1541. };
  1542. const backspaceDeleteCaret = (editor, isForward) => {
  1543. return backspaceDeleteFromListToListCaret(editor, isForward) || backspaceDeleteIntoListCaret(editor, isForward);
  1544. };
  1545. const hasListSelection = editor => {
  1546. const selectionStartElm = editor.selection.getStart();
  1547. const root = getClosestEditingHost(editor, selectionStartElm);
  1548. const startListParent = editor.dom.getParent(selectionStartElm, 'LI,DT,DD', root);
  1549. return startListParent || getSelectedListItems(editor).length > 0;
  1550. };
  1551. const backspaceDeleteRange = editor => {
  1552. if (hasListSelection(editor)) {
  1553. editor.undoManager.transact(() => {
  1554. editor.execCommand('Delete');
  1555. normalizeLists(editor.dom, editor.getBody());
  1556. });
  1557. return true;
  1558. }
  1559. return false;
  1560. };
  1561. const backspaceDelete = (editor, isForward) => {
  1562. const selection = editor.selection;
  1563. return !isWithinNonEditableList(editor, selection.getNode()) && (selection.isCollapsed() ? backspaceDeleteCaret(editor, isForward) : backspaceDeleteRange(editor));
  1564. };
  1565. const setup$2 = editor => {
  1566. editor.on('ExecCommand', e => {
  1567. const cmd = e.command.toLowerCase();
  1568. if ((cmd === 'delete' || cmd === 'forwarddelete') && hasListSelection(editor)) {
  1569. normalizeLists(editor.dom, editor.getBody());
  1570. }
  1571. });
  1572. editor.on('keydown', e => {
  1573. if (e.keyCode === global$4.BACKSPACE) {
  1574. if (backspaceDelete(editor, false)) {
  1575. e.preventDefault();
  1576. }
  1577. } else if (e.keyCode === global$4.DELETE) {
  1578. if (backspaceDelete(editor, true)) {
  1579. e.preventDefault();
  1580. }
  1581. }
  1582. });
  1583. };
  1584. const get = editor => ({
  1585. backspaceDelete: isForward => {
  1586. backspaceDelete(editor, isForward);
  1587. }
  1588. });
  1589. const updateList = (editor, update) => {
  1590. const parentList = getParentList(editor);
  1591. if (parentList === null || isWithinNonEditableList(editor, parentList)) {
  1592. return;
  1593. }
  1594. editor.undoManager.transact(() => {
  1595. if (isObject(update.styles)) {
  1596. editor.dom.setStyles(parentList, update.styles);
  1597. }
  1598. if (isObject(update.attrs)) {
  1599. each(update.attrs, (v, k) => editor.dom.setAttrib(parentList, k, v));
  1600. }
  1601. });
  1602. };
  1603. const parseAlphabeticBase26 = str => {
  1604. const chars = reverse(trim(str).split(''));
  1605. const values = map(chars, (char, i) => {
  1606. const charValue = char.toUpperCase().charCodeAt(0) - 'A'.charCodeAt(0) + 1;
  1607. return Math.pow(26, i) * charValue;
  1608. });
  1609. return foldl(values, (sum, v) => sum + v, 0);
  1610. };
  1611. const composeAlphabeticBase26 = value => {
  1612. value--;
  1613. if (value < 0) {
  1614. return '';
  1615. } else {
  1616. const remainder = value % 26;
  1617. const quotient = Math.floor(value / 26);
  1618. const rest = composeAlphabeticBase26(quotient);
  1619. const char = String.fromCharCode('A'.charCodeAt(0) + remainder);
  1620. return rest + char;
  1621. }
  1622. };
  1623. const isUppercase = str => /^[A-Z]+$/.test(str);
  1624. const isLowercase = str => /^[a-z]+$/.test(str);
  1625. const isNumeric = str => /^[0-9]+$/.test(str);
  1626. const deduceListType = start => {
  1627. if (isNumeric(start)) {
  1628. return 2;
  1629. } else if (isUppercase(start)) {
  1630. return 0;
  1631. } else if (isLowercase(start)) {
  1632. return 1;
  1633. } else if (isEmpty$1(start)) {
  1634. return 3;
  1635. } else {
  1636. return 4;
  1637. }
  1638. };
  1639. const parseStartValue = start => {
  1640. switch (deduceListType(start)) {
  1641. case 2:
  1642. return Optional.some({
  1643. listStyleType: Optional.none(),
  1644. start
  1645. });
  1646. case 0:
  1647. return Optional.some({
  1648. listStyleType: Optional.some('upper-alpha'),
  1649. start: parseAlphabeticBase26(start).toString()
  1650. });
  1651. case 1:
  1652. return Optional.some({
  1653. listStyleType: Optional.some('lower-alpha'),
  1654. start: parseAlphabeticBase26(start).toString()
  1655. });
  1656. case 3:
  1657. return Optional.some({
  1658. listStyleType: Optional.none(),
  1659. start: ''
  1660. });
  1661. case 4:
  1662. return Optional.none();
  1663. }
  1664. };
  1665. const parseDetail = detail => {
  1666. const start = parseInt(detail.start, 10);
  1667. if (is$2(detail.listStyleType, 'upper-alpha')) {
  1668. return composeAlphabeticBase26(start);
  1669. } else if (is$2(detail.listStyleType, 'lower-alpha')) {
  1670. return composeAlphabeticBase26(start).toLowerCase();
  1671. } else {
  1672. return detail.start;
  1673. }
  1674. };
  1675. const open = editor => {
  1676. const currentList = getParentList(editor);
  1677. if (!isOlNode(currentList) || isWithinNonEditableList(editor, currentList)) {
  1678. return;
  1679. }
  1680. editor.windowManager.open({
  1681. title: 'List Properties',
  1682. body: {
  1683. type: 'panel',
  1684. items: [{
  1685. type: 'input',
  1686. name: 'start',
  1687. label: 'Start list at number',
  1688. inputMode: 'numeric'
  1689. }]
  1690. },
  1691. initialData: {
  1692. start: parseDetail({
  1693. start: editor.dom.getAttrib(currentList, 'start', '1'),
  1694. listStyleType: Optional.from(editor.dom.getStyle(currentList, 'list-style-type'))
  1695. })
  1696. },
  1697. buttons: [
  1698. {
  1699. type: 'cancel',
  1700. name: 'cancel',
  1701. text: 'Cancel'
  1702. },
  1703. {
  1704. type: 'submit',
  1705. name: 'save',
  1706. text: 'Save',
  1707. primary: true
  1708. }
  1709. ],
  1710. onSubmit: api => {
  1711. const data = api.getData();
  1712. parseStartValue(data.start).each(detail => {
  1713. editor.execCommand('mceListUpdate', false, {
  1714. attrs: { start: detail.start === '1' ? '' : detail.start },
  1715. styles: { 'list-style-type': detail.listStyleType.getOr('') }
  1716. });
  1717. });
  1718. api.close();
  1719. }
  1720. });
  1721. };
  1722. const queryListCommandState = (editor, listName) => () => {
  1723. const parentList = getParentList(editor);
  1724. return isNonNullable(parentList) && parentList.nodeName === listName;
  1725. };
  1726. const registerDialog = editor => {
  1727. editor.addCommand('mceListProps', () => {
  1728. open(editor);
  1729. });
  1730. };
  1731. const register$2 = editor => {
  1732. editor.on('BeforeExecCommand', e => {
  1733. const cmd = e.command.toLowerCase();
  1734. if (cmd === 'indent') {
  1735. indentListSelection(editor);
  1736. } else if (cmd === 'outdent') {
  1737. outdentListSelection(editor);
  1738. }
  1739. });
  1740. editor.addCommand('InsertUnorderedList', (ui, detail) => {
  1741. toggleList(editor, 'UL', detail);
  1742. });
  1743. editor.addCommand('InsertOrderedList', (ui, detail) => {
  1744. toggleList(editor, 'OL', detail);
  1745. });
  1746. editor.addCommand('InsertDefinitionList', (ui, detail) => {
  1747. toggleList(editor, 'DL', detail);
  1748. });
  1749. editor.addCommand('RemoveList', () => {
  1750. flattenListSelection(editor);
  1751. });
  1752. registerDialog(editor);
  1753. editor.addCommand('mceListUpdate', (ui, detail) => {
  1754. if (isObject(detail)) {
  1755. updateList(editor, detail);
  1756. }
  1757. });
  1758. editor.addQueryStateHandler('InsertUnorderedList', queryListCommandState(editor, 'UL'));
  1759. editor.addQueryStateHandler('InsertOrderedList', queryListCommandState(editor, 'OL'));
  1760. editor.addQueryStateHandler('InsertDefinitionList', queryListCommandState(editor, 'DL'));
  1761. };
  1762. var global = tinymce.util.Tools.resolve('tinymce.html.Node');
  1763. const isTextNode = node => node.type === 3;
  1764. const isEmpty = nodeBuffer => nodeBuffer.length === 0;
  1765. const wrapInvalidChildren = list => {
  1766. const insertListItem = (buffer, refNode) => {
  1767. const li = global.create('li');
  1768. each$1(buffer, node => li.append(node));
  1769. if (refNode) {
  1770. list.insert(li, refNode, true);
  1771. } else {
  1772. list.append(li);
  1773. }
  1774. };
  1775. const reducer = (buffer, node) => {
  1776. if (isTextNode(node)) {
  1777. return [
  1778. ...buffer,
  1779. node
  1780. ];
  1781. } else if (!isEmpty(buffer) && !isTextNode(node)) {
  1782. insertListItem(buffer, node);
  1783. return [];
  1784. } else {
  1785. return buffer;
  1786. }
  1787. };
  1788. const restBuffer = foldl(list.children(), reducer, []);
  1789. if (!isEmpty(restBuffer)) {
  1790. insertListItem(restBuffer);
  1791. }
  1792. };
  1793. const setup$1 = editor => {
  1794. editor.on('PreInit', () => {
  1795. const {parser} = editor;
  1796. parser.addNodeFilter('ul,ol', nodes => each$1(nodes, wrapInvalidChildren));
  1797. });
  1798. };
  1799. const setupTabKey = editor => {
  1800. editor.on('keydown', e => {
  1801. if (e.keyCode !== global$4.TAB || global$4.metaKeyPressed(e)) {
  1802. return;
  1803. }
  1804. editor.undoManager.transact(() => {
  1805. if (e.shiftKey ? outdentListSelection(editor) : indentListSelection(editor)) {
  1806. e.preventDefault();
  1807. }
  1808. });
  1809. });
  1810. };
  1811. const setup = editor => {
  1812. if (shouldIndentOnTab(editor)) {
  1813. setupTabKey(editor);
  1814. }
  1815. setup$2(editor);
  1816. };
  1817. const setupToggleButtonHandler = (editor, listName) => api => {
  1818. const toggleButtonHandler = e => {
  1819. api.setActive(inList(e.parents, listName));
  1820. api.setEnabled(!isWithinNonEditableList(editor, e.element));
  1821. };
  1822. return setNodeChangeHandler(editor, toggleButtonHandler);
  1823. };
  1824. const register$1 = editor => {
  1825. const exec = command => () => editor.execCommand(command);
  1826. if (!editor.hasPlugin('advlist')) {
  1827. editor.ui.registry.addToggleButton('numlist', {
  1828. icon: 'ordered-list',
  1829. active: false,
  1830. tooltip: 'Numbered list',
  1831. onAction: exec('InsertOrderedList'),
  1832. onSetup: setupToggleButtonHandler(editor, 'OL')
  1833. });
  1834. editor.ui.registry.addToggleButton('bullist', {
  1835. icon: 'unordered-list',
  1836. active: false,
  1837. tooltip: 'Bullet list',
  1838. onAction: exec('InsertUnorderedList'),
  1839. onSetup: setupToggleButtonHandler(editor, 'UL')
  1840. });
  1841. }
  1842. };
  1843. const setupMenuButtonHandler = (editor, listName) => api => {
  1844. const menuButtonHandler = e => api.setEnabled(inList(e.parents, listName) && !isWithinNonEditableList(editor, e.element));
  1845. return setNodeChangeHandler(editor, menuButtonHandler);
  1846. };
  1847. const register = editor => {
  1848. const listProperties = {
  1849. text: 'List properties...',
  1850. icon: 'ordered-list',
  1851. onAction: () => editor.execCommand('mceListProps'),
  1852. onSetup: setupMenuButtonHandler(editor, 'OL')
  1853. };
  1854. editor.ui.registry.addMenuItem('listprops', listProperties);
  1855. editor.ui.registry.addContextMenu('lists', {
  1856. update: node => {
  1857. const parentList = getParentList(editor, node);
  1858. return isOlNode(parentList) ? ['listprops'] : [];
  1859. }
  1860. });
  1861. };
  1862. var Plugin = () => {
  1863. global$7.add('lists', editor => {
  1864. register$3(editor);
  1865. setup$1(editor);
  1866. if (!editor.hasPlugin('rtc', true)) {
  1867. setup(editor);
  1868. register$2(editor);
  1869. } else {
  1870. registerDialog(editor);
  1871. }
  1872. register$1(editor);
  1873. register(editor);
  1874. return get(editor);
  1875. });
  1876. };
  1877. Plugin();
  1878. })();