fx-platform-ui 0.0.13-alpha15 → 0.0.13-alpha16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/lib/fx-platform-ui.mjs +21119 -19921
  2. package/lib/fx-platform-ui.umd.js +51 -51
  3. package/lib/packages/components/area/src/index.vue.d.ts +2 -2
  4. package/lib/packages/components/confirm/index.d.ts +2 -0
  5. package/lib/packages/components/confirm/src/confirm.vue.d.ts +2 -0
  6. package/lib/packages/components/confirm/src/index.d.ts +2 -0
  7. package/lib/style.css +1 -1
  8. package/package.json +1 -1
  9. package/packages/.DS_Store +0 -0
  10. package/packages/component.ts +3 -2
  11. package/packages/components/confirm/index.ts +9 -0
  12. package/packages/components/confirm/src/confirm.vue +75 -0
  13. package/packages/components/confirm/src/index.module.less +61 -0
  14. package/packages/components/confirm/src/index.tsx +91 -0
  15. package/packages/components/confirm/src/plat-confirm-props.ts +40 -0
  16. package/packages/components/editor/src/index.vue +1 -0
  17. package/packages/components/table/src/hook/useTableMethods.tsx +1 -1
  18. package/packages/components/table/src/plat-table-emits.ts +1 -1
  19. package/CHANGELOG.md +0 -46
  20. package/lib/tinymce/CHANGELOG.md +0 -2957
  21. package/lib/tinymce/README.md +0 -71
  22. package/lib/tinymce/bower.json +0 -27
  23. package/lib/tinymce/composer.json +0 -52
  24. package/lib/tinymce/icons/default/icons.js +0 -182
  25. package/lib/tinymce/icons/default/icons.min.js +0 -1
  26. package/lib/tinymce/icons/default/index.js +0 -7
  27. package/lib/tinymce/license.txt +0 -21
  28. package/lib/tinymce/models/dom/index.js +0 -7
  29. package/lib/tinymce/models/dom/model.js +0 -7975
  30. package/lib/tinymce/models/dom/model.min.js +0 -4
  31. package/lib/tinymce/package.json +0 -32
  32. package/lib/tinymce/plugins/advlist/index.js +0 -7
  33. package/lib/tinymce/plugins/advlist/plugin.js +0 -246
  34. package/lib/tinymce/plugins/advlist/plugin.min.js +0 -4
  35. package/lib/tinymce/plugins/anchor/index.js +0 -7
  36. package/lib/tinymce/plugins/anchor/plugin.js +0 -195
  37. package/lib/tinymce/plugins/anchor/plugin.min.js +0 -4
  38. package/lib/tinymce/plugins/autolink/index.js +0 -7
  39. package/lib/tinymce/plugins/autolink/plugin.js +0 -232
  40. package/lib/tinymce/plugins/autolink/plugin.min.js +0 -4
  41. package/lib/tinymce/plugins/autoresize/index.js +0 -7
  42. package/lib/tinymce/plugins/autoresize/plugin.js +0 -156
  43. package/lib/tinymce/plugins/autoresize/plugin.min.js +0 -4
  44. package/lib/tinymce/plugins/autosave/index.js +0 -7
  45. package/lib/tinymce/plugins/autosave/plugin.js +0 -232
  46. package/lib/tinymce/plugins/autosave/plugin.min.js +0 -4
  47. package/lib/tinymce/plugins/charmap/index.js +0 -7
  48. package/lib/tinymce/plugins/charmap/plugin.js +0 -1636
  49. package/lib/tinymce/plugins/charmap/plugin.min.js +0 -4
  50. package/lib/tinymce/plugins/code/index.js +0 -7
  51. package/lib/tinymce/plugins/code/plugin.js +0 -85
  52. package/lib/tinymce/plugins/code/plugin.min.js +0 -4
  53. package/lib/tinymce/plugins/codesample/index.js +0 -7
  54. package/lib/tinymce/plugins/codesample/plugin.js +0 -2451
  55. package/lib/tinymce/plugins/codesample/plugin.min.js +0 -4
  56. package/lib/tinymce/plugins/directionality/index.js +0 -7
  57. package/lib/tinymce/plugins/directionality/plugin.js +0 -384
  58. package/lib/tinymce/plugins/directionality/plugin.min.js +0 -4
  59. package/lib/tinymce/plugins/emoticons/index.js +0 -7
  60. package/lib/tinymce/plugins/emoticons/js/emojiimages.js +0 -1
  61. package/lib/tinymce/plugins/emoticons/js/emojiimages.min.js +0 -3
  62. package/lib/tinymce/plugins/emoticons/js/emojis.js +0 -1
  63. package/lib/tinymce/plugins/emoticons/js/emojis.min.js +0 -2
  64. package/lib/tinymce/plugins/emoticons/plugin.js +0 -577
  65. package/lib/tinymce/plugins/emoticons/plugin.min.js +0 -4
  66. package/lib/tinymce/plugins/fullscreen/index.js +0 -7
  67. package/lib/tinymce/plugins/fullscreen/plugin.js +0 -1190
  68. package/lib/tinymce/plugins/fullscreen/plugin.min.js +0 -4
  69. package/lib/tinymce/plugins/help/index.js +0 -7
  70. package/lib/tinymce/plugins/help/plugin.js +0 -848
  71. package/lib/tinymce/plugins/help/plugin.min.js +0 -4
  72. package/lib/tinymce/plugins/image/index.js +0 -7
  73. package/lib/tinymce/plugins/image/plugin.js +0 -1475
  74. package/lib/tinymce/plugins/image/plugin.min.js +0 -4
  75. package/lib/tinymce/plugins/importcss/index.js +0 -7
  76. package/lib/tinymce/plugins/importcss/plugin.js +0 -342
  77. package/lib/tinymce/plugins/importcss/plugin.min.js +0 -4
  78. package/lib/tinymce/plugins/insertdatetime/index.js +0 -7
  79. package/lib/tinymce/plugins/insertdatetime/plugin.js +0 -176
  80. package/lib/tinymce/plugins/insertdatetime/plugin.min.js +0 -4
  81. package/lib/tinymce/plugins/link/index.js +0 -7
  82. package/lib/tinymce/plugins/link/plugin.js +0 -1190
  83. package/lib/tinymce/plugins/link/plugin.min.js +0 -4
  84. package/lib/tinymce/plugins/lists/index.js +0 -7
  85. package/lib/tinymce/plugins/lists/plugin.js +0 -1820
  86. package/lib/tinymce/plugins/lists/plugin.min.js +0 -4
  87. package/lib/tinymce/plugins/media/index.js +0 -7
  88. package/lib/tinymce/plugins/media/plugin.js +0 -1157
  89. package/lib/tinymce/plugins/media/plugin.min.js +0 -4
  90. package/lib/tinymce/plugins/nonbreaking/index.js +0 -7
  91. package/lib/tinymce/plugins/nonbreaking/plugin.js +0 -111
  92. package/lib/tinymce/plugins/nonbreaking/plugin.min.js +0 -4
  93. package/lib/tinymce/plugins/pagebreak/index.js +0 -7
  94. package/lib/tinymce/plugins/pagebreak/plugin.js +0 -105
  95. package/lib/tinymce/plugins/pagebreak/plugin.min.js +0 -4
  96. package/lib/tinymce/plugins/preview/index.js +0 -7
  97. package/lib/tinymce/plugins/preview/plugin.js +0 -97
  98. package/lib/tinymce/plugins/preview/plugin.min.js +0 -4
  99. package/lib/tinymce/plugins/quickbars/index.js +0 -7
  100. package/lib/tinymce/plugins/quickbars/plugin.js +0 -421
  101. package/lib/tinymce/plugins/quickbars/plugin.min.js +0 -4
  102. package/lib/tinymce/plugins/save/index.js +0 -7
  103. package/lib/tinymce/plugins/save/plugin.js +0 -118
  104. package/lib/tinymce/plugins/save/plugin.min.js +0 -4
  105. package/lib/tinymce/plugins/searchreplace/index.js +0 -7
  106. package/lib/tinymce/plugins/searchreplace/plugin.js +0 -1079
  107. package/lib/tinymce/plugins/searchreplace/plugin.min.js +0 -4
  108. package/lib/tinymce/plugins/table/index.js +0 -7
  109. package/lib/tinymce/plugins/table/plugin.js +0 -3393
  110. package/lib/tinymce/plugins/table/plugin.min.js +0 -4
  111. package/lib/tinymce/plugins/template/index.js +0 -7
  112. package/lib/tinymce/plugins/template/plugin.js +0 -548
  113. package/lib/tinymce/plugins/template/plugin.min.js +0 -4
  114. package/lib/tinymce/plugins/visualblocks/index.js +0 -7
  115. package/lib/tinymce/plugins/visualblocks/plugin.js +0 -98
  116. package/lib/tinymce/plugins/visualblocks/plugin.min.js +0 -4
  117. package/lib/tinymce/plugins/visualchars/index.js +0 -7
  118. package/lib/tinymce/plugins/visualchars/plugin.js +0 -506
  119. package/lib/tinymce/plugins/visualchars/plugin.min.js +0 -4
  120. package/lib/tinymce/plugins/wordcount/index.js +0 -7
  121. package/lib/tinymce/plugins/wordcount/plugin.js +0 -404
  122. package/lib/tinymce/plugins/wordcount/plugin.min.js +0 -4
  123. package/lib/tinymce/themes/silver/index.js +0 -7
  124. package/lib/tinymce/themes/silver/theme.js +0 -26184
  125. package/lib/tinymce/themes/silver/theme.min.js +0 -4
  126. package/lib/tinymce/tinymce.d.ts +0 -2895
  127. package/lib/tinymce/tinymce.js +0 -29400
@@ -1,3393 +0,0 @@
1
- /**
2
- * TinyMCE version 6.1.2 (2022-07-29)
3
- */
4
-
5
- (function () {
6
- 'use strict';
7
-
8
- var global$3 = tinymce.util.Tools.resolve('tinymce.PluginManager');
9
-
10
- const hasProto = (v, constructor, predicate) => {
11
- var _a;
12
- if (predicate(v, constructor.prototype)) {
13
- return true;
14
- } else {
15
- return ((_a = v.constructor) === null || _a === void 0 ? void 0 : _a.name) === constructor.name;
16
- }
17
- };
18
- const typeOf = x => {
19
- const t = typeof x;
20
- if (x === null) {
21
- return 'null';
22
- } else if (t === 'object' && Array.isArray(x)) {
23
- return 'array';
24
- } else if (t === 'object' && hasProto(x, String, (o, proto) => proto.isPrototypeOf(o))) {
25
- return 'string';
26
- } else {
27
- return t;
28
- }
29
- };
30
- const isType$1 = type => value => typeOf(value) === type;
31
- const isSimpleType = type => value => typeof value === type;
32
- const eq$1 = t => a => t === a;
33
- const isString = isType$1('string');
34
- const isArray = isType$1('array');
35
- const isBoolean = isSimpleType('boolean');
36
- const isUndefined = eq$1(undefined);
37
- const isNullable = a => a === null || a === undefined;
38
- const isNonNullable = a => !isNullable(a);
39
- const isFunction = isSimpleType('function');
40
- const isNumber = isSimpleType('number');
41
-
42
- const noop = () => {
43
- };
44
- const compose1 = (fbc, fab) => a => fbc(fab(a));
45
- const constant = value => {
46
- return () => {
47
- return value;
48
- };
49
- };
50
- const identity = x => {
51
- return x;
52
- };
53
- const tripleEquals = (a, b) => {
54
- return a === b;
55
- };
56
- function curry(fn, ...initialArgs) {
57
- return (...restArgs) => {
58
- const all = initialArgs.concat(restArgs);
59
- return fn.apply(null, all);
60
- };
61
- }
62
- const never = constant(false);
63
- const always = constant(true);
64
-
65
- class Optional {
66
- constructor(tag, value) {
67
- this.tag = tag;
68
- this.value = value;
69
- }
70
- static some(value) {
71
- return new Optional(true, value);
72
- }
73
- static none() {
74
- return Optional.singletonNone;
75
- }
76
- fold(onNone, onSome) {
77
- if (this.tag) {
78
- return onSome(this.value);
79
- } else {
80
- return onNone();
81
- }
82
- }
83
- isSome() {
84
- return this.tag;
85
- }
86
- isNone() {
87
- return !this.tag;
88
- }
89
- map(mapper) {
90
- if (this.tag) {
91
- return Optional.some(mapper(this.value));
92
- } else {
93
- return Optional.none();
94
- }
95
- }
96
- bind(binder) {
97
- if (this.tag) {
98
- return binder(this.value);
99
- } else {
100
- return Optional.none();
101
- }
102
- }
103
- exists(predicate) {
104
- return this.tag && predicate(this.value);
105
- }
106
- forall(predicate) {
107
- return !this.tag || predicate(this.value);
108
- }
109
- filter(predicate) {
110
- if (!this.tag || predicate(this.value)) {
111
- return this;
112
- } else {
113
- return Optional.none();
114
- }
115
- }
116
- getOr(replacement) {
117
- return this.tag ? this.value : replacement;
118
- }
119
- or(replacement) {
120
- return this.tag ? this : replacement;
121
- }
122
- getOrThunk(thunk) {
123
- return this.tag ? this.value : thunk();
124
- }
125
- orThunk(thunk) {
126
- return this.tag ? this : thunk();
127
- }
128
- getOrDie(message) {
129
- if (!this.tag) {
130
- throw new Error(message !== null && message !== void 0 ? message : 'Called getOrDie on None');
131
- } else {
132
- return this.value;
133
- }
134
- }
135
- static from(value) {
136
- return isNonNullable(value) ? Optional.some(value) : Optional.none();
137
- }
138
- getOrNull() {
139
- return this.tag ? this.value : null;
140
- }
141
- getOrUndefined() {
142
- return this.value;
143
- }
144
- each(worker) {
145
- if (this.tag) {
146
- worker(this.value);
147
- }
148
- }
149
- toArray() {
150
- return this.tag ? [this.value] : [];
151
- }
152
- toString() {
153
- return this.tag ? `some(${ this.value })` : 'none()';
154
- }
155
- }
156
- Optional.singletonNone = new Optional(false);
157
-
158
- const keys = Object.keys;
159
- const hasOwnProperty = Object.hasOwnProperty;
160
- const each$1 = (obj, f) => {
161
- const props = keys(obj);
162
- for (let k = 0, len = props.length; k < len; k++) {
163
- const i = props[k];
164
- const x = obj[i];
165
- f(x, i);
166
- }
167
- };
168
- const objAcc = r => (x, i) => {
169
- r[i] = x;
170
- };
171
- const internalFilter = (obj, pred, onTrue, onFalse) => {
172
- const r = {};
173
- each$1(obj, (x, i) => {
174
- (pred(x, i) ? onTrue : onFalse)(x, i);
175
- });
176
- return r;
177
- };
178
- const filter$1 = (obj, pred) => {
179
- const t = {};
180
- internalFilter(obj, pred, objAcc(t), noop);
181
- return t;
182
- };
183
- const mapToArray = (obj, f) => {
184
- const r = [];
185
- each$1(obj, (value, name) => {
186
- r.push(f(value, name));
187
- });
188
- return r;
189
- };
190
- const values = obj => {
191
- return mapToArray(obj, identity);
192
- };
193
- const size = obj => {
194
- return keys(obj).length;
195
- };
196
- const get$4 = (obj, key) => {
197
- return has(obj, key) ? Optional.from(obj[key]) : Optional.none();
198
- };
199
- const has = (obj, key) => hasOwnProperty.call(obj, key);
200
- const hasNonNullableKey = (obj, key) => has(obj, key) && obj[key] !== undefined && obj[key] !== null;
201
-
202
- const nativeIndexOf = Array.prototype.indexOf;
203
- const nativePush = Array.prototype.push;
204
- const rawIndexOf = (ts, t) => nativeIndexOf.call(ts, t);
205
- const contains = (xs, x) => rawIndexOf(xs, x) > -1;
206
- const exists = (xs, pred) => {
207
- for (let i = 0, len = xs.length; i < len; i++) {
208
- const x = xs[i];
209
- if (pred(x, i)) {
210
- return true;
211
- }
212
- }
213
- return false;
214
- };
215
- const range = (num, f) => {
216
- const r = [];
217
- for (let i = 0; i < num; i++) {
218
- r.push(f(i));
219
- }
220
- return r;
221
- };
222
- const map = (xs, f) => {
223
- const len = xs.length;
224
- const r = new Array(len);
225
- for (let i = 0; i < len; i++) {
226
- const x = xs[i];
227
- r[i] = f(x, i);
228
- }
229
- return r;
230
- };
231
- const each = (xs, f) => {
232
- for (let i = 0, len = xs.length; i < len; i++) {
233
- const x = xs[i];
234
- f(x, i);
235
- }
236
- };
237
- const eachr = (xs, f) => {
238
- for (let i = xs.length - 1; i >= 0; i--) {
239
- const x = xs[i];
240
- f(x, i);
241
- }
242
- };
243
- const partition = (xs, pred) => {
244
- const pass = [];
245
- const fail = [];
246
- for (let i = 0, len = xs.length; i < len; i++) {
247
- const x = xs[i];
248
- const arr = pred(x, i) ? pass : fail;
249
- arr.push(x);
250
- }
251
- return {
252
- pass,
253
- fail
254
- };
255
- };
256
- const filter = (xs, pred) => {
257
- const r = [];
258
- for (let i = 0, len = xs.length; i < len; i++) {
259
- const x = xs[i];
260
- if (pred(x, i)) {
261
- r.push(x);
262
- }
263
- }
264
- return r;
265
- };
266
- const foldr = (xs, f, acc) => {
267
- eachr(xs, (x, i) => {
268
- acc = f(acc, x, i);
269
- });
270
- return acc;
271
- };
272
- const foldl = (xs, f, acc) => {
273
- each(xs, (x, i) => {
274
- acc = f(acc, x, i);
275
- });
276
- return acc;
277
- };
278
- const findUntil = (xs, pred, until) => {
279
- for (let i = 0, len = xs.length; i < len; i++) {
280
- const x = xs[i];
281
- if (pred(x, i)) {
282
- return Optional.some(x);
283
- } else if (until(x, i)) {
284
- break;
285
- }
286
- }
287
- return Optional.none();
288
- };
289
- const find = (xs, pred) => {
290
- return findUntil(xs, pred, never);
291
- };
292
- const flatten$1 = xs => {
293
- const r = [];
294
- for (let i = 0, len = xs.length; i < len; ++i) {
295
- if (!isArray(xs[i])) {
296
- throw new Error('Arr.flatten item ' + i + ' was not an array, input: ' + xs);
297
- }
298
- nativePush.apply(r, xs[i]);
299
- }
300
- return r;
301
- };
302
- const bind = (xs, f) => flatten$1(map(xs, f));
303
- const forall = (xs, pred) => {
304
- for (let i = 0, len = xs.length; i < len; ++i) {
305
- const x = xs[i];
306
- if (pred(x, i) !== true) {
307
- return false;
308
- }
309
- }
310
- return true;
311
- };
312
- const mapToObject = (xs, f) => {
313
- const r = {};
314
- for (let i = 0, len = xs.length; i < len; i++) {
315
- const x = xs[i];
316
- r[String(x)] = f(x, i);
317
- }
318
- return r;
319
- };
320
- const get$3 = (xs, i) => i >= 0 && i < xs.length ? Optional.some(xs[i]) : Optional.none();
321
- const head = xs => get$3(xs, 0);
322
- const last = xs => get$3(xs, xs.length - 1);
323
- const findMap = (arr, f) => {
324
- for (let i = 0; i < arr.length; i++) {
325
- const r = f(arr[i], i);
326
- if (r.isSome()) {
327
- return r;
328
- }
329
- }
330
- return Optional.none();
331
- };
332
-
333
- const fromHtml = (html, scope) => {
334
- const doc = scope || document;
335
- const div = doc.createElement('div');
336
- div.innerHTML = html;
337
- if (!div.hasChildNodes() || div.childNodes.length > 1) {
338
- const message = 'HTML does not have a single root node';
339
- console.error(message, html);
340
- throw new Error(message);
341
- }
342
- return fromDom$1(div.childNodes[0]);
343
- };
344
- const fromTag = (tag, scope) => {
345
- const doc = scope || document;
346
- const node = doc.createElement(tag);
347
- return fromDom$1(node);
348
- };
349
- const fromText = (text, scope) => {
350
- const doc = scope || document;
351
- const node = doc.createTextNode(text);
352
- return fromDom$1(node);
353
- };
354
- const fromDom$1 = node => {
355
- if (node === null || node === undefined) {
356
- throw new Error('Node cannot be null or undefined');
357
- }
358
- return { dom: node };
359
- };
360
- const fromPoint = (docElm, x, y) => Optional.from(docElm.dom.elementFromPoint(x, y)).map(fromDom$1);
361
- const SugarElement = {
362
- fromHtml,
363
- fromTag,
364
- fromText,
365
- fromDom: fromDom$1,
366
- fromPoint
367
- };
368
-
369
- typeof window !== 'undefined' ? window : Function('return this;')();
370
-
371
- const COMMENT = 8;
372
- const DOCUMENT = 9;
373
- const DOCUMENT_FRAGMENT = 11;
374
- const ELEMENT = 1;
375
- const TEXT = 3;
376
-
377
- const name = element => {
378
- const r = element.dom.nodeName;
379
- return r.toLowerCase();
380
- };
381
- const type = element => element.dom.nodeType;
382
- const isType = t => element => type(element) === t;
383
- const isComment = element => type(element) === COMMENT || name(element) === '#comment';
384
- const isElement = isType(ELEMENT);
385
- const isText = isType(TEXT);
386
- const isDocument = isType(DOCUMENT);
387
- const isDocumentFragment = isType(DOCUMENT_FRAGMENT);
388
- const isTag = tag => e => isElement(e) && name(e) === tag;
389
-
390
- const is$2 = (element, selector) => {
391
- const dom = element.dom;
392
- if (dom.nodeType !== ELEMENT) {
393
- return false;
394
- } else {
395
- const elem = dom;
396
- if (elem.matches !== undefined) {
397
- return elem.matches(selector);
398
- } else if (elem.msMatchesSelector !== undefined) {
399
- return elem.msMatchesSelector(selector);
400
- } else if (elem.webkitMatchesSelector !== undefined) {
401
- return elem.webkitMatchesSelector(selector);
402
- } else if (elem.mozMatchesSelector !== undefined) {
403
- return elem.mozMatchesSelector(selector);
404
- } else {
405
- throw new Error('Browser lacks native selectors');
406
- }
407
- }
408
- };
409
- const bypassSelector = dom => dom.nodeType !== ELEMENT && dom.nodeType !== DOCUMENT && dom.nodeType !== DOCUMENT_FRAGMENT || dom.childElementCount === 0;
410
- const all$1 = (selector, scope) => {
411
- const base = scope === undefined ? document : scope.dom;
412
- return bypassSelector(base) ? [] : map(base.querySelectorAll(selector), SugarElement.fromDom);
413
- };
414
- const one = (selector, scope) => {
415
- const base = scope === undefined ? document : scope.dom;
416
- return bypassSelector(base) ? Optional.none() : Optional.from(base.querySelector(selector)).map(SugarElement.fromDom);
417
- };
418
-
419
- const eq = (e1, e2) => e1.dom === e2.dom;
420
- const is$1 = is$2;
421
-
422
- const owner = element => SugarElement.fromDom(element.dom.ownerDocument);
423
- const documentOrOwner = dos => isDocument(dos) ? dos : owner(dos);
424
- const parent = element => Optional.from(element.dom.parentNode).map(SugarElement.fromDom);
425
- const parents = (element, isRoot) => {
426
- const stop = isFunction(isRoot) ? isRoot : never;
427
- let dom = element.dom;
428
- const ret = [];
429
- while (dom.parentNode !== null && dom.parentNode !== undefined) {
430
- const rawParent = dom.parentNode;
431
- const p = SugarElement.fromDom(rawParent);
432
- ret.push(p);
433
- if (stop(p) === true) {
434
- break;
435
- } else {
436
- dom = rawParent;
437
- }
438
- }
439
- return ret;
440
- };
441
- const prevSibling = element => Optional.from(element.dom.previousSibling).map(SugarElement.fromDom);
442
- const nextSibling = element => Optional.from(element.dom.nextSibling).map(SugarElement.fromDom);
443
- const children$3 = element => map(element.dom.childNodes, SugarElement.fromDom);
444
- const child$3 = (element, index) => {
445
- const cs = element.dom.childNodes;
446
- return Optional.from(cs[index]).map(SugarElement.fromDom);
447
- };
448
- const firstChild = element => child$3(element, 0);
449
-
450
- const isShadowRoot = dos => isDocumentFragment(dos) && isNonNullable(dos.dom.host);
451
- const supported = isFunction(Element.prototype.attachShadow) && isFunction(Node.prototype.getRootNode);
452
- const getRootNode = supported ? e => SugarElement.fromDom(e.dom.getRootNode()) : documentOrOwner;
453
- const getShadowRoot = e => {
454
- const r = getRootNode(e);
455
- return isShadowRoot(r) ? Optional.some(r) : Optional.none();
456
- };
457
- const getShadowHost = e => SugarElement.fromDom(e.dom.host);
458
-
459
- const inBody = element => {
460
- const dom = isText(element) ? element.dom.parentNode : element.dom;
461
- if (dom === undefined || dom === null || dom.ownerDocument === null) {
462
- return false;
463
- }
464
- const doc = dom.ownerDocument;
465
- return getShadowRoot(SugarElement.fromDom(dom)).fold(() => doc.body.contains(dom), compose1(inBody, getShadowHost));
466
- };
467
-
468
- const children$2 = (scope, predicate) => filter(children$3(scope), predicate);
469
- const descendants$1 = (scope, predicate) => {
470
- let result = [];
471
- each(children$3(scope), x => {
472
- if (predicate(x)) {
473
- result = result.concat([x]);
474
- }
475
- result = result.concat(descendants$1(x, predicate));
476
- });
477
- return result;
478
- };
479
-
480
- const children$1 = (scope, selector) => children$2(scope, e => is$2(e, selector));
481
- const descendants = (scope, selector) => all$1(selector, scope);
482
-
483
- var ClosestOrAncestor = (is, ancestor, scope, a, isRoot) => {
484
- if (is(scope, a)) {
485
- return Optional.some(scope);
486
- } else if (isFunction(isRoot) && isRoot(scope)) {
487
- return Optional.none();
488
- } else {
489
- return ancestor(scope, a, isRoot);
490
- }
491
- };
492
-
493
- const ancestor$1 = (scope, predicate, isRoot) => {
494
- let element = scope.dom;
495
- const stop = isFunction(isRoot) ? isRoot : never;
496
- while (element.parentNode) {
497
- element = element.parentNode;
498
- const el = SugarElement.fromDom(element);
499
- if (predicate(el)) {
500
- return Optional.some(el);
501
- } else if (stop(el)) {
502
- break;
503
- }
504
- }
505
- return Optional.none();
506
- };
507
- const child$2 = (scope, predicate) => {
508
- const pred = node => predicate(SugarElement.fromDom(node));
509
- const result = find(scope.dom.childNodes, pred);
510
- return result.map(SugarElement.fromDom);
511
- };
512
-
513
- const ancestor = (scope, selector, isRoot) => ancestor$1(scope, e => is$2(e, selector), isRoot);
514
- const child$1 = (scope, selector) => child$2(scope, e => is$2(e, selector));
515
- const descendant = (scope, selector) => one(selector, scope);
516
- const closest = (scope, selector, isRoot) => {
517
- const is = (element, selector) => is$2(element, selector);
518
- return ClosestOrAncestor(is, ancestor, scope, selector, isRoot);
519
- };
520
-
521
- const rawSet = (dom, key, value) => {
522
- if (isString(value) || isBoolean(value) || isNumber(value)) {
523
- dom.setAttribute(key, value + '');
524
- } else {
525
- console.error('Invalid call to Attribute.set. Key ', key, ':: Value ', value, ':: Element ', dom);
526
- throw new Error('Attribute value was not simple');
527
- }
528
- };
529
- const set$2 = (element, key, value) => {
530
- rawSet(element.dom, key, value);
531
- };
532
- const setAll = (element, attrs) => {
533
- const dom = element.dom;
534
- each$1(attrs, (v, k) => {
535
- rawSet(dom, k, v);
536
- });
537
- };
538
- const get$2 = (element, key) => {
539
- const v = element.dom.getAttribute(key);
540
- return v === null ? undefined : v;
541
- };
542
- const getOpt = (element, key) => Optional.from(get$2(element, key));
543
- const remove$2 = (element, key) => {
544
- element.dom.removeAttribute(key);
545
- };
546
- const clone = element => foldl(element.dom.attributes, (acc, attr) => {
547
- acc[attr.name] = attr.value;
548
- return acc;
549
- }, {});
550
-
551
- const is = (lhs, rhs, comparator = tripleEquals) => lhs.exists(left => comparator(left, rhs));
552
- const cat = arr => {
553
- const r = [];
554
- const push = x => {
555
- r.push(x);
556
- };
557
- for (let i = 0; i < arr.length; i++) {
558
- arr[i].each(push);
559
- }
560
- return r;
561
- };
562
- const lift2 = (oa, ob, f) => oa.isSome() && ob.isSome() ? Optional.some(f(oa.getOrDie(), ob.getOrDie())) : Optional.none();
563
- const flatten = oot => oot.bind(identity);
564
- const someIf = (b, a) => b ? Optional.some(a) : Optional.none();
565
-
566
- const removeFromStart = (str, numChars) => {
567
- return str.substring(numChars);
568
- };
569
-
570
- const checkRange = (str, substr, start) => substr === '' || str.length >= substr.length && str.substr(start, start + substr.length) === substr;
571
- const removeLeading = (str, prefix) => {
572
- return startsWith(str, prefix) ? removeFromStart(str, prefix.length) : str;
573
- };
574
- const startsWith = (str, prefix) => {
575
- return checkRange(str, prefix, 0);
576
- };
577
- const blank = r => s => s.replace(r, '');
578
- const trim = blank(/^\s+|\s+$/g);
579
- const isNotEmpty = s => s.length > 0;
580
- const isEmpty = s => !isNotEmpty(s);
581
- const toFloat = value => {
582
- const num = parseFloat(value);
583
- return isNaN(num) ? Optional.none() : Optional.some(num);
584
- };
585
-
586
- const isSupported = dom => dom.style !== undefined && isFunction(dom.style.getPropertyValue);
587
-
588
- const internalSet = (dom, property, value) => {
589
- if (!isString(value)) {
590
- console.error('Invalid call to CSS.set. Property ', property, ':: Value ', value, ':: Element ', dom);
591
- throw new Error('CSS value must be a string: ' + value);
592
- }
593
- if (isSupported(dom)) {
594
- dom.style.setProperty(property, value);
595
- }
596
- };
597
- const internalRemove = (dom, property) => {
598
- if (isSupported(dom)) {
599
- dom.style.removeProperty(property);
600
- }
601
- };
602
- const set$1 = (element, property, value) => {
603
- const dom = element.dom;
604
- internalSet(dom, property, value);
605
- };
606
- const get$1 = (element, property) => {
607
- const dom = element.dom;
608
- const styles = window.getComputedStyle(dom);
609
- const r = styles.getPropertyValue(property);
610
- return r === '' && !inBody(element) ? getUnsafeProperty(dom, property) : r;
611
- };
612
- const getUnsafeProperty = (dom, property) => isSupported(dom) ? dom.style.getPropertyValue(property) : '';
613
- const getRaw = (element, property) => {
614
- const dom = element.dom;
615
- const raw = getUnsafeProperty(dom, property);
616
- return Optional.from(raw).filter(r => r.length > 0);
617
- };
618
- const remove$1 = (element, property) => {
619
- const dom = element.dom;
620
- internalRemove(dom, property);
621
- if (is(getOpt(element, 'style').map(trim), '')) {
622
- remove$2(element, 'style');
623
- }
624
- };
625
-
626
- const getAttrValue = (cell, name, fallback = 0) => getOpt(cell, name).map(value => parseInt(value, 10)).getOr(fallback);
627
-
628
- const firstLayer = (scope, selector) => {
629
- return filterFirstLayer(scope, selector, always);
630
- };
631
- const filterFirstLayer = (scope, selector, predicate) => {
632
- return bind(children$3(scope), x => {
633
- if (is$2(x, selector)) {
634
- return predicate(x) ? [x] : [];
635
- } else {
636
- return filterFirstLayer(x, selector, predicate);
637
- }
638
- });
639
- };
640
-
641
- const validSectionList = [
642
- 'tfoot',
643
- 'thead',
644
- 'tbody',
645
- 'colgroup'
646
- ];
647
- const isValidSection = parentName => contains(validSectionList, parentName);
648
- const grid = (rows, columns) => ({
649
- rows,
650
- columns
651
- });
652
- const detail = (element, rowspan, colspan) => ({
653
- element,
654
- rowspan,
655
- colspan
656
- });
657
- const extended = (element, rowspan, colspan, row, column, isLocked) => ({
658
- element,
659
- rowspan,
660
- colspan,
661
- row,
662
- column,
663
- isLocked
664
- });
665
- const rowdetail = (element, cells, section) => ({
666
- element,
667
- cells,
668
- section
669
- });
670
- const bounds = (startRow, startCol, finishRow, finishCol) => ({
671
- startRow,
672
- startCol,
673
- finishRow,
674
- finishCol
675
- });
676
- const columnext = (element, colspan, column) => ({
677
- element,
678
- colspan,
679
- column
680
- });
681
- const colgroup = (element, columns) => ({
682
- element,
683
- columns
684
- });
685
-
686
- const lookup = (tags, element, isRoot = never) => {
687
- if (isRoot(element)) {
688
- return Optional.none();
689
- }
690
- if (contains(tags, name(element))) {
691
- return Optional.some(element);
692
- }
693
- const isRootOrUpperTable = elm => is$2(elm, 'table') || isRoot(elm);
694
- return ancestor(element, tags.join(','), isRootOrUpperTable);
695
- };
696
- const cell = (element, isRoot) => lookup([
697
- 'td',
698
- 'th'
699
- ], element, isRoot);
700
- const cells = ancestor => firstLayer(ancestor, 'th,td');
701
- const columns = ancestor => {
702
- if (is$2(ancestor, 'colgroup')) {
703
- return children$1(ancestor, 'col');
704
- } else {
705
- return bind(columnGroups(ancestor), columnGroup => children$1(columnGroup, 'col'));
706
- }
707
- };
708
- const table = (element, isRoot) => closest(element, 'table', isRoot);
709
- const rows = ancestor => firstLayer(ancestor, 'tr');
710
- const columnGroups = ancestor => table(ancestor).fold(constant([]), table => children$1(table, 'colgroup'));
711
-
712
- const fromRowsOrColGroups = (elems, getSection) => map(elems, row => {
713
- if (name(row) === 'colgroup') {
714
- const cells = map(columns(row), column => {
715
- const colspan = getAttrValue(column, 'span', 1);
716
- return detail(column, 1, colspan);
717
- });
718
- return rowdetail(row, cells, 'colgroup');
719
- } else {
720
- const cells$1 = map(cells(row), cell => {
721
- const rowspan = getAttrValue(cell, 'rowspan', 1);
722
- const colspan = getAttrValue(cell, 'colspan', 1);
723
- return detail(cell, rowspan, colspan);
724
- });
725
- return rowdetail(row, cells$1, getSection(row));
726
- }
727
- });
728
- const getParentSection = group => parent(group).map(parent => {
729
- const parentName = name(parent);
730
- return isValidSection(parentName) ? parentName : 'tbody';
731
- }).getOr('tbody');
732
- const fromTable$1 = table => {
733
- const rows$1 = rows(table);
734
- const columnGroups$1 = columnGroups(table);
735
- const elems = [
736
- ...columnGroups$1,
737
- ...rows$1
738
- ];
739
- return fromRowsOrColGroups(elems, getParentSection);
740
- };
741
-
742
- const LOCKED_COL_ATTR = 'data-snooker-locked-cols';
743
- const getLockedColumnsFromTable = table => getOpt(table, LOCKED_COL_ATTR).bind(lockedColStr => Optional.from(lockedColStr.match(/\d+/g))).map(lockedCols => mapToObject(lockedCols, always));
744
-
745
- const key = (row, column) => {
746
- return row + ',' + column;
747
- };
748
- const getAt = (warehouse, row, column) => Optional.from(warehouse.access[key(row, column)]);
749
- const findItem = (warehouse, item, comparator) => {
750
- const filtered = filterItems(warehouse, detail => {
751
- return comparator(item, detail.element);
752
- });
753
- return filtered.length > 0 ? Optional.some(filtered[0]) : Optional.none();
754
- };
755
- const filterItems = (warehouse, predicate) => {
756
- const all = bind(warehouse.all, r => {
757
- return r.cells;
758
- });
759
- return filter(all, predicate);
760
- };
761
- const generateColumns = rowData => {
762
- const columnsGroup = {};
763
- let index = 0;
764
- each(rowData.cells, column => {
765
- const colspan = column.colspan;
766
- range(colspan, columnIndex => {
767
- const colIndex = index + columnIndex;
768
- columnsGroup[colIndex] = columnext(column.element, colspan, colIndex);
769
- });
770
- index += colspan;
771
- });
772
- return columnsGroup;
773
- };
774
- const generate$1 = list => {
775
- const access = {};
776
- const cells = [];
777
- const tableOpt = head(list).map(rowData => rowData.element).bind(table);
778
- const lockedColumns = tableOpt.bind(getLockedColumnsFromTable).getOr({});
779
- let maxRows = 0;
780
- let maxColumns = 0;
781
- let rowCount = 0;
782
- const {
783
- pass: colgroupRows,
784
- fail: rows
785
- } = partition(list, rowData => rowData.section === 'colgroup');
786
- each(rows, rowData => {
787
- const currentRow = [];
788
- each(rowData.cells, rowCell => {
789
- let start = 0;
790
- while (access[key(rowCount, start)] !== undefined) {
791
- start++;
792
- }
793
- const isLocked = hasNonNullableKey(lockedColumns, start.toString());
794
- const current = extended(rowCell.element, rowCell.rowspan, rowCell.colspan, rowCount, start, isLocked);
795
- for (let occupiedColumnPosition = 0; occupiedColumnPosition < rowCell.colspan; occupiedColumnPosition++) {
796
- for (let occupiedRowPosition = 0; occupiedRowPosition < rowCell.rowspan; occupiedRowPosition++) {
797
- const rowPosition = rowCount + occupiedRowPosition;
798
- const columnPosition = start + occupiedColumnPosition;
799
- const newpos = key(rowPosition, columnPosition);
800
- access[newpos] = current;
801
- maxColumns = Math.max(maxColumns, columnPosition + 1);
802
- }
803
- }
804
- currentRow.push(current);
805
- });
806
- maxRows++;
807
- cells.push(rowdetail(rowData.element, currentRow, rowData.section));
808
- rowCount++;
809
- });
810
- const {columns, colgroups} = last(colgroupRows).map(rowData => {
811
- const columns = generateColumns(rowData);
812
- const colgroup$1 = colgroup(rowData.element, values(columns));
813
- return {
814
- colgroups: [colgroup$1],
815
- columns
816
- };
817
- }).getOrThunk(() => ({
818
- colgroups: [],
819
- columns: {}
820
- }));
821
- const grid$1 = grid(maxRows, maxColumns);
822
- return {
823
- grid: grid$1,
824
- access,
825
- all: cells,
826
- columns,
827
- colgroups
828
- };
829
- };
830
- const fromTable = table => {
831
- const list = fromTable$1(table);
832
- return generate$1(list);
833
- };
834
- const justCells = warehouse => bind(warehouse.all, w => w.cells);
835
- const justColumns = warehouse => values(warehouse.columns);
836
- const hasColumns = warehouse => keys(warehouse.columns).length > 0;
837
- const getColumnAt = (warehouse, columnIndex) => Optional.from(warehouse.columns[columnIndex]);
838
- const Warehouse = {
839
- fromTable,
840
- generate: generate$1,
841
- getAt,
842
- findItem,
843
- filterItems,
844
- justCells,
845
- justColumns,
846
- hasColumns,
847
- getColumnAt
848
- };
849
-
850
- var global$2 = tinymce.util.Tools.resolve('tinymce.util.Tools');
851
-
852
- const getTDTHOverallStyle = (dom, elm, name) => {
853
- const cells = dom.select('td,th', elm);
854
- let firstChildStyle;
855
- const checkChildren = (firstChildStyle, elms) => {
856
- for (let i = 0; i < elms.length; i++) {
857
- const currentStyle = dom.getStyle(elms[i], name);
858
- if (typeof firstChildStyle === 'undefined') {
859
- firstChildStyle = currentStyle;
860
- }
861
- if (firstChildStyle !== currentStyle) {
862
- return '';
863
- }
864
- }
865
- return firstChildStyle;
866
- };
867
- return checkChildren(firstChildStyle, cells);
868
- };
869
- const setAlign = (editor, elm, name) => {
870
- global$2.each('left center right'.split(' '), align => {
871
- if (align !== name) {
872
- editor.formatter.remove('align' + align, {}, elm);
873
- }
874
- });
875
- if (name) {
876
- editor.formatter.apply('align' + name, {}, elm);
877
- }
878
- };
879
- const setVAlign = (editor, elm, name) => {
880
- global$2.each('top middle bottom'.split(' '), align => {
881
- if (align !== name) {
882
- editor.formatter.remove('valign' + align, {}, elm);
883
- }
884
- });
885
- if (name) {
886
- editor.formatter.apply('valign' + name, {}, elm);
887
- }
888
- };
889
-
890
- const fireTableModified = (editor, table, data) => {
891
- editor.dispatch('TableModified', {
892
- ...data,
893
- table
894
- });
895
- };
896
-
897
- const toNumber = (px, fallback) => toFloat(px).getOr(fallback);
898
- const getProp = (element, name, fallback) => toNumber(get$1(element, name), fallback);
899
- const calcContentBoxSize = (element, size, upper, lower) => {
900
- const paddingUpper = getProp(element, `padding-${ upper }`, 0);
901
- const paddingLower = getProp(element, `padding-${ lower }`, 0);
902
- const borderUpper = getProp(element, `border-${ upper }-width`, 0);
903
- const borderLower = getProp(element, `border-${ lower }-width`, 0);
904
- return size - paddingUpper - paddingLower - borderUpper - borderLower;
905
- };
906
- const getCalculatedWidth = (element, boxSizing) => {
907
- const dom = element.dom;
908
- const width = dom.getBoundingClientRect().width || dom.offsetWidth;
909
- return boxSizing === 'border-box' ? width : calcContentBoxSize(element, width, 'left', 'right');
910
- };
911
- const getInnerWidth = element => getCalculatedWidth(element, 'content-box');
912
-
913
- const getInner = getInnerWidth;
914
-
915
- var global$1 = tinymce.util.Tools.resolve('tinymce.Env');
916
-
917
- const defaultTableToolbar = 'tableprops tabledelete | tableinsertrowbefore tableinsertrowafter tabledeleterow | tableinsertcolbefore tableinsertcolafter tabledeletecol';
918
- const defaultCellBorderWidths = range(5, i => {
919
- const size = `${ i + 1 }px`;
920
- return {
921
- title: size,
922
- value: size
923
- };
924
- });
925
- const defaultCellBorderStyles = map([
926
- 'Solid',
927
- 'Dotted',
928
- 'Dashed',
929
- 'Double',
930
- 'Groove',
931
- 'Ridge',
932
- 'Inset',
933
- 'Outset',
934
- 'None',
935
- 'Hidden'
936
- ], type => {
937
- return {
938
- title: type,
939
- value: type.toLowerCase()
940
- };
941
- });
942
- const defaultWidth = '100%';
943
- const getPixelForcedWidth = editor => {
944
- var _a;
945
- const dom = editor.dom;
946
- const parentBlock = (_a = dom.getParent(editor.selection.getStart(), dom.isBlock)) !== null && _a !== void 0 ? _a : editor.getBody();
947
- return getInner(SugarElement.fromDom(parentBlock)) + 'px';
948
- };
949
- const determineDefaultStyles = (editor, defaultStyles) => {
950
- if (isResponsiveForced(editor) || !shouldStyleWithCss(editor)) {
951
- return defaultStyles;
952
- } else if (isPixelsForced(editor)) {
953
- return {
954
- ...defaultStyles,
955
- width: getPixelForcedWidth(editor)
956
- };
957
- } else {
958
- return {
959
- ...defaultStyles,
960
- width: defaultWidth
961
- };
962
- }
963
- };
964
- const determineDefaultAttributes = (editor, defaultAttributes) => {
965
- if (isResponsiveForced(editor) || shouldStyleWithCss(editor)) {
966
- return defaultAttributes;
967
- } else if (isPixelsForced(editor)) {
968
- return {
969
- ...defaultAttributes,
970
- width: getPixelForcedWidth(editor)
971
- };
972
- } else {
973
- return {
974
- ...defaultAttributes,
975
- width: defaultWidth
976
- };
977
- }
978
- };
979
- const option = name => editor => editor.options.get(name);
980
- const register = editor => {
981
- const registerOption = editor.options.register;
982
- registerOption('table_border_widths', {
983
- processor: 'object[]',
984
- default: defaultCellBorderWidths
985
- });
986
- registerOption('table_border_styles', {
987
- processor: 'object[]',
988
- default: defaultCellBorderStyles
989
- });
990
- registerOption('table_cell_advtab', {
991
- processor: 'boolean',
992
- default: true
993
- });
994
- registerOption('table_row_advtab', {
995
- processor: 'boolean',
996
- default: true
997
- });
998
- registerOption('table_advtab', {
999
- processor: 'boolean',
1000
- default: true
1001
- });
1002
- registerOption('table_appearance_options', {
1003
- processor: 'boolean',
1004
- default: true
1005
- });
1006
- registerOption('table_grid', {
1007
- processor: 'boolean',
1008
- default: !global$1.deviceType.isTouch()
1009
- });
1010
- registerOption('table_cell_class_list', {
1011
- processor: 'object[]',
1012
- default: []
1013
- });
1014
- registerOption('table_row_class_list', {
1015
- processor: 'object[]',
1016
- default: []
1017
- });
1018
- registerOption('table_class_list', {
1019
- processor: 'object[]',
1020
- default: []
1021
- });
1022
- registerOption('table_toolbar', {
1023
- processor: 'string',
1024
- default: defaultTableToolbar
1025
- });
1026
- registerOption('table_background_color_map', {
1027
- processor: 'object[]',
1028
- default: []
1029
- });
1030
- registerOption('table_border_color_map', {
1031
- processor: 'object[]',
1032
- default: []
1033
- });
1034
- };
1035
- const getTableSizingMode = option('table_sizing_mode');
1036
- const getTableBorderWidths = option('table_border_widths');
1037
- const getTableBorderStyles = option('table_border_styles');
1038
- const hasAdvancedCellTab = option('table_cell_advtab');
1039
- const hasAdvancedRowTab = option('table_row_advtab');
1040
- const hasAdvancedTableTab = option('table_advtab');
1041
- const hasAppearanceOptions = option('table_appearance_options');
1042
- const hasTableGrid = option('table_grid');
1043
- const shouldStyleWithCss = option('table_style_by_css');
1044
- const getCellClassList = option('table_cell_class_list');
1045
- const getRowClassList = option('table_row_class_list');
1046
- const getTableClassList = option('table_class_list');
1047
- const getToolbar = option('table_toolbar');
1048
- const getTableBackgroundColorMap = option('table_background_color_map');
1049
- const getTableBorderColorMap = option('table_border_color_map');
1050
- const isPixelsForced = editor => getTableSizingMode(editor) === 'fixed';
1051
- const isResponsiveForced = editor => getTableSizingMode(editor) === 'responsive';
1052
- const getDefaultStyles = editor => {
1053
- const options = editor.options;
1054
- const defaultStyles = options.get('table_default_styles');
1055
- return options.isSet('table_default_styles') ? defaultStyles : determineDefaultStyles(editor, defaultStyles);
1056
- };
1057
- const getDefaultAttributes = editor => {
1058
- const options = editor.options;
1059
- const defaultAttributes = options.get('table_default_attributes');
1060
- return options.isSet('table_default_attributes') ? defaultAttributes : determineDefaultAttributes(editor, defaultAttributes);
1061
- };
1062
-
1063
- const getNodeName = elm => elm.nodeName.toLowerCase();
1064
- const getBody = editor => SugarElement.fromDom(editor.getBody());
1065
- const getIsRoot = editor => element => eq(element, getBody(editor));
1066
- const removePxSuffix = size => size ? size.replace(/px$/, '') : '';
1067
- const addPxSuffix = size => /^\d+(\.\d+)?$/.test(size) ? size + 'px' : size;
1068
- const getSelectionStart = editor => SugarElement.fromDom(editor.selection.getStart());
1069
- const getSelectionEnd = editor => SugarElement.fromDom(editor.selection.getEnd());
1070
-
1071
- const isWithin = (bounds, detail) => {
1072
- return detail.column >= bounds.startCol && detail.column + detail.colspan - 1 <= bounds.finishCol && detail.row >= bounds.startRow && detail.row + detail.rowspan - 1 <= bounds.finishRow;
1073
- };
1074
- const isRectangular = (warehouse, bounds) => {
1075
- let isRect = true;
1076
- const detailIsWithin = curry(isWithin, bounds);
1077
- for (let i = bounds.startRow; i <= bounds.finishRow; i++) {
1078
- for (let j = bounds.startCol; j <= bounds.finishCol; j++) {
1079
- isRect = isRect && Warehouse.getAt(warehouse, i, j).exists(detailIsWithin);
1080
- }
1081
- }
1082
- return isRect ? Optional.some(bounds) : Optional.none();
1083
- };
1084
-
1085
- const getBounds = (detailA, detailB) => {
1086
- return bounds(Math.min(detailA.row, detailB.row), Math.min(detailA.column, detailB.column), Math.max(detailA.row + detailA.rowspan - 1, detailB.row + detailB.rowspan - 1), Math.max(detailA.column + detailA.colspan - 1, detailB.column + detailB.colspan - 1));
1087
- };
1088
- const getAnyBox = (warehouse, startCell, finishCell) => {
1089
- const startCoords = Warehouse.findItem(warehouse, startCell, eq);
1090
- const finishCoords = Warehouse.findItem(warehouse, finishCell, eq);
1091
- return startCoords.bind(sc => {
1092
- return finishCoords.map(fc => {
1093
- return getBounds(sc, fc);
1094
- });
1095
- });
1096
- };
1097
- const getBox$1 = (warehouse, startCell, finishCell) => {
1098
- return getAnyBox(warehouse, startCell, finishCell).bind(bounds => {
1099
- return isRectangular(warehouse, bounds);
1100
- });
1101
- };
1102
-
1103
- const getBox = (table, first, last) => {
1104
- const warehouse = getWarehouse(table);
1105
- return getBox$1(warehouse, first, last);
1106
- };
1107
- const getWarehouse = Warehouse.fromTable;
1108
-
1109
- const before = (marker, element) => {
1110
- const parent$1 = parent(marker);
1111
- parent$1.each(v => {
1112
- v.dom.insertBefore(element.dom, marker.dom);
1113
- });
1114
- };
1115
- const after$1 = (marker, element) => {
1116
- const sibling = nextSibling(marker);
1117
- sibling.fold(() => {
1118
- const parent$1 = parent(marker);
1119
- parent$1.each(v => {
1120
- append$1(v, element);
1121
- });
1122
- }, v => {
1123
- before(v, element);
1124
- });
1125
- };
1126
- const prepend = (parent, element) => {
1127
- const firstChild$1 = firstChild(parent);
1128
- firstChild$1.fold(() => {
1129
- append$1(parent, element);
1130
- }, v => {
1131
- parent.dom.insertBefore(element.dom, v.dom);
1132
- });
1133
- };
1134
- const append$1 = (parent, element) => {
1135
- parent.dom.appendChild(element.dom);
1136
- };
1137
- const wrap = (element, wrapper) => {
1138
- before(element, wrapper);
1139
- append$1(wrapper, element);
1140
- };
1141
-
1142
- const after = (marker, elements) => {
1143
- each(elements, (x, i) => {
1144
- const e = i === 0 ? marker : elements[i - 1];
1145
- after$1(e, x);
1146
- });
1147
- };
1148
- const append = (parent, elements) => {
1149
- each(elements, x => {
1150
- append$1(parent, x);
1151
- });
1152
- };
1153
-
1154
- const remove = element => {
1155
- const dom = element.dom;
1156
- if (dom.parentNode !== null) {
1157
- dom.parentNode.removeChild(dom);
1158
- }
1159
- };
1160
- const unwrap = wrapper => {
1161
- const children = children$3(wrapper);
1162
- if (children.length > 0) {
1163
- after(wrapper, children);
1164
- }
1165
- remove(wrapper);
1166
- };
1167
-
1168
- const NodeValue = (is, name) => {
1169
- const get = element => {
1170
- if (!is(element)) {
1171
- throw new Error('Can only get ' + name + ' value of a ' + name + ' node');
1172
- }
1173
- return getOption(element).getOr('');
1174
- };
1175
- const getOption = element => is(element) ? Optional.from(element.dom.nodeValue) : Optional.none();
1176
- const set = (element, value) => {
1177
- if (!is(element)) {
1178
- throw new Error('Can only set raw ' + name + ' value of a ' + name + ' node');
1179
- }
1180
- element.dom.nodeValue = value;
1181
- };
1182
- return {
1183
- get,
1184
- getOption,
1185
- set
1186
- };
1187
- };
1188
-
1189
- const api = NodeValue(isText, 'text');
1190
- const get = element => api.get(element);
1191
- const set = (element, value) => api.set(element, value);
1192
-
1193
- var TagBoundaries = [
1194
- 'body',
1195
- 'p',
1196
- 'div',
1197
- 'article',
1198
- 'aside',
1199
- 'figcaption',
1200
- 'figure',
1201
- 'footer',
1202
- 'header',
1203
- 'nav',
1204
- 'section',
1205
- 'ol',
1206
- 'ul',
1207
- 'li',
1208
- 'table',
1209
- 'thead',
1210
- 'tbody',
1211
- 'tfoot',
1212
- 'caption',
1213
- 'tr',
1214
- 'td',
1215
- 'th',
1216
- 'h1',
1217
- 'h2',
1218
- 'h3',
1219
- 'h4',
1220
- 'h5',
1221
- 'h6',
1222
- 'blockquote',
1223
- 'pre',
1224
- 'address'
1225
- ];
1226
-
1227
- var DomUniverse = () => {
1228
- const clone$1 = element => {
1229
- return SugarElement.fromDom(element.dom.cloneNode(false));
1230
- };
1231
- const document = element => documentOrOwner(element).dom;
1232
- const isBoundary = element => {
1233
- if (!isElement(element)) {
1234
- return false;
1235
- }
1236
- if (name(element) === 'body') {
1237
- return true;
1238
- }
1239
- return contains(TagBoundaries, name(element));
1240
- };
1241
- const isEmptyTag = element => {
1242
- if (!isElement(element)) {
1243
- return false;
1244
- }
1245
- return contains([
1246
- 'br',
1247
- 'img',
1248
- 'hr',
1249
- 'input'
1250
- ], name(element));
1251
- };
1252
- const isNonEditable = element => isElement(element) && get$2(element, 'contenteditable') === 'false';
1253
- const comparePosition = (element, other) => {
1254
- return element.dom.compareDocumentPosition(other.dom);
1255
- };
1256
- const copyAttributesTo = (source, destination) => {
1257
- const as = clone(source);
1258
- setAll(destination, as);
1259
- };
1260
- const isSpecial = element => {
1261
- const tag = name(element);
1262
- return contains([
1263
- 'script',
1264
- 'noscript',
1265
- 'iframe',
1266
- 'noframes',
1267
- 'noembed',
1268
- 'title',
1269
- 'style',
1270
- 'textarea',
1271
- 'xmp'
1272
- ], tag);
1273
- };
1274
- const getLanguage = element => isElement(element) ? getOpt(element, 'lang') : Optional.none();
1275
- return {
1276
- up: constant({
1277
- selector: ancestor,
1278
- closest: closest,
1279
- predicate: ancestor$1,
1280
- all: parents
1281
- }),
1282
- down: constant({
1283
- selector: descendants,
1284
- predicate: descendants$1
1285
- }),
1286
- styles: constant({
1287
- get: get$1,
1288
- getRaw: getRaw,
1289
- set: set$1,
1290
- remove: remove$1
1291
- }),
1292
- attrs: constant({
1293
- get: get$2,
1294
- set: set$2,
1295
- remove: remove$2,
1296
- copyTo: copyAttributesTo
1297
- }),
1298
- insert: constant({
1299
- before: before,
1300
- after: after$1,
1301
- afterAll: after,
1302
- append: append$1,
1303
- appendAll: append,
1304
- prepend: prepend,
1305
- wrap: wrap
1306
- }),
1307
- remove: constant({
1308
- unwrap: unwrap,
1309
- remove: remove
1310
- }),
1311
- create: constant({
1312
- nu: SugarElement.fromTag,
1313
- clone: clone$1,
1314
- text: SugarElement.fromText
1315
- }),
1316
- query: constant({
1317
- comparePosition,
1318
- prevSibling: prevSibling,
1319
- nextSibling: nextSibling
1320
- }),
1321
- property: constant({
1322
- children: children$3,
1323
- name: name,
1324
- parent: parent,
1325
- document,
1326
- isText: isText,
1327
- isComment: isComment,
1328
- isElement: isElement,
1329
- isSpecial,
1330
- getLanguage,
1331
- getText: get,
1332
- setText: set,
1333
- isBoundary,
1334
- isEmptyTag,
1335
- isNonEditable
1336
- }),
1337
- eq: eq,
1338
- is: is$1
1339
- };
1340
- };
1341
-
1342
- const all = (universe, look, elements, f) => {
1343
- const head = elements[0];
1344
- const tail = elements.slice(1);
1345
- return f(universe, look, head, tail);
1346
- };
1347
- const oneAll = (universe, look, elements) => {
1348
- return elements.length > 0 ? all(universe, look, elements, unsafeOne) : Optional.none();
1349
- };
1350
- const unsafeOne = (universe, look, head, tail) => {
1351
- const start = look(universe, head);
1352
- return foldr(tail, (b, a) => {
1353
- const current = look(universe, a);
1354
- return commonElement(universe, b, current);
1355
- }, start);
1356
- };
1357
- const commonElement = (universe, start, end) => {
1358
- return start.bind(s => {
1359
- return end.filter(curry(universe.eq, s));
1360
- });
1361
- };
1362
-
1363
- const sharedOne$1 = oneAll;
1364
-
1365
- const universe = DomUniverse();
1366
- const sharedOne = (look, elements) => {
1367
- return sharedOne$1(universe, (_universe, element) => {
1368
- return look(element);
1369
- }, elements);
1370
- };
1371
-
1372
- const lookupTable = container => {
1373
- return ancestor(container, 'table');
1374
- };
1375
- const retrieve$1 = (container, selector) => {
1376
- const sels = descendants(container, selector);
1377
- return sels.length > 0 ? Optional.some(sels) : Optional.none();
1378
- };
1379
- const getEdges = (container, firstSelectedSelector, lastSelectedSelector) => {
1380
- return descendant(container, firstSelectedSelector).bind(first => {
1381
- return descendant(container, lastSelectedSelector).bind(last => {
1382
- return sharedOne(lookupTable, [
1383
- first,
1384
- last
1385
- ]).map(table => {
1386
- return {
1387
- first,
1388
- last,
1389
- table
1390
- };
1391
- });
1392
- });
1393
- });
1394
- };
1395
-
1396
- const retrieve = (container, selector) => {
1397
- return retrieve$1(container, selector);
1398
- };
1399
- const retrieveBox = (container, firstSelectedSelector, lastSelectedSelector) => {
1400
- return getEdges(container, firstSelectedSelector, lastSelectedSelector).bind(edges => {
1401
- const isRoot = ancestor => {
1402
- return eq(container, ancestor);
1403
- };
1404
- const sectionSelector = 'thead,tfoot,tbody,table';
1405
- const firstAncestor = ancestor(edges.first, sectionSelector, isRoot);
1406
- const lastAncestor = ancestor(edges.last, sectionSelector, isRoot);
1407
- return firstAncestor.bind(fA => {
1408
- return lastAncestor.bind(lA => {
1409
- return eq(fA, lA) ? getBox(edges.table, edges.first, edges.last) : Optional.none();
1410
- });
1411
- });
1412
- });
1413
- };
1414
-
1415
- const fromDom = nodes => map(nodes, SugarElement.fromDom);
1416
-
1417
- const strSelected = 'data-mce-selected';
1418
- const strSelectedSelector = 'td[' + strSelected + '],th[' + strSelected + ']';
1419
- const strFirstSelected = 'data-mce-first-selected';
1420
- const strFirstSelectedSelector = 'td[' + strFirstSelected + '],th[' + strFirstSelected + ']';
1421
- const strLastSelected = 'data-mce-last-selected';
1422
- const strLastSelectedSelector = 'td[' + strLastSelected + '],th[' + strLastSelected + ']';
1423
- const ephemera = {
1424
- selected: strSelected,
1425
- selectedSelector: strSelectedSelector,
1426
- firstSelected: strFirstSelected,
1427
- firstSelectedSelector: strFirstSelectedSelector,
1428
- lastSelected: strLastSelected,
1429
- lastSelectedSelector: strLastSelectedSelector
1430
- };
1431
-
1432
- const getSelectionCellFallback = element => table(element).bind(table => retrieve(table, ephemera.firstSelectedSelector)).fold(constant(element), cells => cells[0]);
1433
- const getSelectionFromSelector = selector => (initCell, isRoot) => {
1434
- const cellName = name(initCell);
1435
- const cell = cellName === 'col' || cellName === 'colgroup' ? getSelectionCellFallback(initCell) : initCell;
1436
- return closest(cell, selector, isRoot);
1437
- };
1438
- const getSelectionCellOrCaption = getSelectionFromSelector('th,td,caption');
1439
- const getSelectionCell = getSelectionFromSelector('th,td');
1440
- const getCellsFromSelection = editor => fromDom(editor.model.table.getSelectedCells());
1441
- const getRowsFromSelection = (selected, selector) => {
1442
- const cellOpt = getSelectionCell(selected);
1443
- const rowsOpt = cellOpt.bind(cell => table(cell)).map(table => rows(table));
1444
- return lift2(cellOpt, rowsOpt, (cell, rows) => filter(rows, row => exists(fromDom(row.dom.cells), rowCell => get$2(rowCell, selector) === '1' || eq(rowCell, cell)))).getOr([]);
1445
- };
1446
-
1447
- const verticalAlignValues = [
1448
- {
1449
- text: 'None',
1450
- value: ''
1451
- },
1452
- {
1453
- text: 'Top',
1454
- value: 'top'
1455
- },
1456
- {
1457
- text: 'Middle',
1458
- value: 'middle'
1459
- },
1460
- {
1461
- text: 'Bottom',
1462
- value: 'bottom'
1463
- }
1464
- ];
1465
-
1466
- const hexColour = value => ({ value });
1467
- const shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
1468
- const longformRegex = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i;
1469
- const isHexString = hex => shorthandRegex.test(hex) || longformRegex.test(hex);
1470
- const normalizeHex = hex => removeLeading(hex, '#').toUpperCase();
1471
- const fromString$1 = hex => isHexString(hex) ? Optional.some({ value: normalizeHex(hex) }) : Optional.none();
1472
- const toHex = component => {
1473
- const hex = component.toString(16);
1474
- return (hex.length === 1 ? '0' + hex : hex).toUpperCase();
1475
- };
1476
- const fromRgba = rgbaColour => {
1477
- const value = toHex(rgbaColour.red) + toHex(rgbaColour.green) + toHex(rgbaColour.blue);
1478
- return hexColour(value);
1479
- };
1480
-
1481
- const rgbRegex = /^\s*rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)\s*$/i;
1482
- const rgbaRegex = /^\s*rgba\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d?(?:\.\d+)?)\s*\)\s*$/i;
1483
- const rgbaColour = (red, green, blue, alpha) => ({
1484
- red,
1485
- green,
1486
- blue,
1487
- alpha
1488
- });
1489
- const fromStringValues = (red, green, blue, alpha) => {
1490
- const r = parseInt(red, 10);
1491
- const g = parseInt(green, 10);
1492
- const b = parseInt(blue, 10);
1493
- const a = parseFloat(alpha);
1494
- return rgbaColour(r, g, b, a);
1495
- };
1496
- const fromString = rgbaString => {
1497
- if (rgbaString === 'transparent') {
1498
- return Optional.some(rgbaColour(0, 0, 0, 0));
1499
- }
1500
- const rgbMatch = rgbRegex.exec(rgbaString);
1501
- if (rgbMatch !== null) {
1502
- return Optional.some(fromStringValues(rgbMatch[1], rgbMatch[2], rgbMatch[3], '1'));
1503
- }
1504
- const rgbaMatch = rgbaRegex.exec(rgbaString);
1505
- if (rgbaMatch !== null) {
1506
- return Optional.some(fromStringValues(rgbaMatch[1], rgbaMatch[2], rgbaMatch[3], rgbaMatch[4]));
1507
- }
1508
- return Optional.none();
1509
- };
1510
-
1511
- const anyToHex = color => fromString$1(color).orThunk(() => fromString(color).map(fromRgba)).getOrThunk(() => {
1512
- const canvas = document.createElement('canvas');
1513
- canvas.height = 1;
1514
- canvas.width = 1;
1515
- const canvasContext = canvas.getContext('2d');
1516
- canvasContext.clearRect(0, 0, canvas.width, canvas.height);
1517
- canvasContext.fillStyle = '#FFFFFF';
1518
- canvasContext.fillStyle = color;
1519
- canvasContext.fillRect(0, 0, 1, 1);
1520
- const rgba = canvasContext.getImageData(0, 0, 1, 1).data;
1521
- const r = rgba[0];
1522
- const g = rgba[1];
1523
- const b = rgba[2];
1524
- const a = rgba[3];
1525
- return fromRgba(rgbaColour(r, g, b, a));
1526
- });
1527
- const rgbaToHexString = color => fromString(color).map(fromRgba).map(h => '#' + h.value).getOr(color);
1528
-
1529
- const Cell = initial => {
1530
- let value = initial;
1531
- const get = () => {
1532
- return value;
1533
- };
1534
- const set = v => {
1535
- value = v;
1536
- };
1537
- return {
1538
- get,
1539
- set
1540
- };
1541
- };
1542
-
1543
- const singleton = doRevoke => {
1544
- const subject = Cell(Optional.none());
1545
- const revoke = () => subject.get().each(doRevoke);
1546
- const clear = () => {
1547
- revoke();
1548
- subject.set(Optional.none());
1549
- };
1550
- const isSet = () => subject.get().isSome();
1551
- const get = () => subject.get();
1552
- const set = s => {
1553
- revoke();
1554
- subject.set(Optional.some(s));
1555
- };
1556
- return {
1557
- clear,
1558
- isSet,
1559
- get,
1560
- set
1561
- };
1562
- };
1563
- const unbindable = () => singleton(s => s.unbind());
1564
-
1565
- const onSetupToggle = (editor, formatName, formatValue) => {
1566
- return api => {
1567
- const boundCallback = unbindable();
1568
- const isNone = isEmpty(formatValue);
1569
- const init = () => {
1570
- const selectedCells = getCellsFromSelection(editor);
1571
- const checkNode = cell => editor.formatter.match(formatName, { value: formatValue }, cell.dom, isNone);
1572
- if (isNone) {
1573
- api.setActive(!exists(selectedCells, checkNode));
1574
- boundCallback.set(editor.formatter.formatChanged(formatName, match => api.setActive(!match), true));
1575
- } else {
1576
- api.setActive(forall(selectedCells, checkNode));
1577
- boundCallback.set(editor.formatter.formatChanged(formatName, api.setActive, false, { value: formatValue }));
1578
- }
1579
- };
1580
- editor.initialized ? init() : editor.on('init', init);
1581
- return boundCallback.clear;
1582
- };
1583
- };
1584
- const isListGroup = item => hasNonNullableKey(item, 'menu');
1585
- const buildListItems = items => map(items, item => {
1586
- const text = item.text || item.title;
1587
- if (isListGroup(item)) {
1588
- return {
1589
- text,
1590
- items: buildListItems(item.menu)
1591
- };
1592
- } else {
1593
- return {
1594
- text,
1595
- value: item.value
1596
- };
1597
- }
1598
- });
1599
- const buildMenuItems = (editor, items, format, onAction) => map(items, item => {
1600
- const text = item.text || item.title;
1601
- if (isListGroup(item)) {
1602
- return {
1603
- type: 'nestedmenuitem',
1604
- text,
1605
- getSubmenuItems: () => buildMenuItems(editor, item.menu, format, onAction)
1606
- };
1607
- } else {
1608
- return {
1609
- text,
1610
- type: 'togglemenuitem',
1611
- onAction: () => onAction(item.value),
1612
- onSetup: onSetupToggle(editor, format, item.value)
1613
- };
1614
- }
1615
- });
1616
- const applyTableCellStyle = (editor, style) => value => {
1617
- editor.execCommand('mceTableApplyCellStyle', false, { [style]: value });
1618
- };
1619
- const filterNoneItem = list => bind(list, item => {
1620
- if (isListGroup(item)) {
1621
- return [{
1622
- ...item,
1623
- menu: filterNoneItem(item.menu)
1624
- }];
1625
- } else {
1626
- return isNotEmpty(item.value) ? [item] : [];
1627
- }
1628
- });
1629
- const generateMenuItemsCallback = (editor, items, format, onAction) => callback => callback(buildMenuItems(editor, items, format, onAction));
1630
- const buildColorMenu = (editor, colorList, style) => {
1631
- const colorMap = map(colorList, entry => ({
1632
- text: entry.title,
1633
- value: '#' + anyToHex(entry.value).value,
1634
- type: 'choiceitem'
1635
- }));
1636
- return [{
1637
- type: 'fancymenuitem',
1638
- fancytype: 'colorswatch',
1639
- initData: {
1640
- colors: colorMap.length > 0 ? colorMap : undefined,
1641
- allowCustomColors: false
1642
- },
1643
- onAction: data => {
1644
- const value = data.value === 'remove' ? '' : data.value;
1645
- editor.execCommand('mceTableApplyCellStyle', false, { [style]: value });
1646
- }
1647
- }];
1648
- };
1649
- const changeRowHeader = editor => () => {
1650
- const currentType = editor.queryCommandValue('mceTableRowType');
1651
- const newType = currentType === 'header' ? 'body' : 'header';
1652
- editor.execCommand('mceTableRowType', false, { type: newType });
1653
- };
1654
- const changeColumnHeader = editor => () => {
1655
- const currentType = editor.queryCommandValue('mceTableColType');
1656
- const newType = currentType === 'th' ? 'td' : 'th';
1657
- editor.execCommand('mceTableColType', false, { type: newType });
1658
- };
1659
-
1660
- const getClassList$1 = editor => {
1661
- const classes = buildListItems(getCellClassList(editor));
1662
- if (classes.length > 0) {
1663
- return Optional.some({
1664
- name: 'class',
1665
- type: 'listbox',
1666
- label: 'Class',
1667
- items: classes
1668
- });
1669
- }
1670
- return Optional.none();
1671
- };
1672
- const children = [
1673
- {
1674
- name: 'width',
1675
- type: 'input',
1676
- label: 'Width'
1677
- },
1678
- {
1679
- name: 'height',
1680
- type: 'input',
1681
- label: 'Height'
1682
- },
1683
- {
1684
- name: 'celltype',
1685
- type: 'listbox',
1686
- label: 'Cell type',
1687
- items: [
1688
- {
1689
- text: 'Cell',
1690
- value: 'td'
1691
- },
1692
- {
1693
- text: 'Header cell',
1694
- value: 'th'
1695
- }
1696
- ]
1697
- },
1698
- {
1699
- name: 'scope',
1700
- type: 'listbox',
1701
- label: 'Scope',
1702
- items: [
1703
- {
1704
- text: 'None',
1705
- value: ''
1706
- },
1707
- {
1708
- text: 'Row',
1709
- value: 'row'
1710
- },
1711
- {
1712
- text: 'Column',
1713
- value: 'col'
1714
- },
1715
- {
1716
- text: 'Row group',
1717
- value: 'rowgroup'
1718
- },
1719
- {
1720
- text: 'Column group',
1721
- value: 'colgroup'
1722
- }
1723
- ]
1724
- },
1725
- {
1726
- name: 'halign',
1727
- type: 'listbox',
1728
- label: 'Horizontal align',
1729
- items: [
1730
- {
1731
- text: 'None',
1732
- value: ''
1733
- },
1734
- {
1735
- text: 'Left',
1736
- value: 'left'
1737
- },
1738
- {
1739
- text: 'Center',
1740
- value: 'center'
1741
- },
1742
- {
1743
- text: 'Right',
1744
- value: 'right'
1745
- }
1746
- ]
1747
- },
1748
- {
1749
- name: 'valign',
1750
- type: 'listbox',
1751
- label: 'Vertical align',
1752
- items: verticalAlignValues
1753
- }
1754
- ];
1755
- const getItems$2 = editor => children.concat(getClassList$1(editor).toArray());
1756
-
1757
- const getAdvancedTab = (editor, dialogName) => {
1758
- const emptyBorderStyle = [{
1759
- text: 'Select...',
1760
- value: ''
1761
- }];
1762
- const advTabItems = [
1763
- {
1764
- name: 'borderstyle',
1765
- type: 'listbox',
1766
- label: 'Border style',
1767
- items: emptyBorderStyle.concat(buildListItems(getTableBorderStyles(editor)))
1768
- },
1769
- {
1770
- name: 'bordercolor',
1771
- type: 'colorinput',
1772
- label: 'Border color'
1773
- },
1774
- {
1775
- name: 'backgroundcolor',
1776
- type: 'colorinput',
1777
- label: 'Background color'
1778
- }
1779
- ];
1780
- const borderWidth = {
1781
- name: 'borderwidth',
1782
- type: 'input',
1783
- label: 'Border width'
1784
- };
1785
- const items = dialogName === 'cell' ? [borderWidth].concat(advTabItems) : advTabItems;
1786
- return {
1787
- title: 'Advanced',
1788
- name: 'advanced',
1789
- items
1790
- };
1791
- };
1792
-
1793
- const normal = (editor, element) => {
1794
- const dom = editor.dom;
1795
- const setAttrib = (attr, value) => {
1796
- dom.setAttrib(element, attr, value);
1797
- };
1798
- const setStyle = (prop, value) => {
1799
- dom.setStyle(element, prop, value);
1800
- };
1801
- const setFormat = (formatName, value) => {
1802
- if (value === '') {
1803
- editor.formatter.remove(formatName, { value: null }, element, true);
1804
- } else {
1805
- editor.formatter.apply(formatName, { value }, element);
1806
- }
1807
- };
1808
- return {
1809
- setAttrib,
1810
- setStyle,
1811
- setFormat
1812
- };
1813
- };
1814
- const DomModifier = { normal };
1815
-
1816
- const isHeaderCell = isTag('th');
1817
- const getRowHeaderType = (isHeaderRow, isHeaderCells) => {
1818
- if (isHeaderRow && isHeaderCells) {
1819
- return 'sectionCells';
1820
- } else if (isHeaderRow) {
1821
- return 'section';
1822
- } else {
1823
- return 'cells';
1824
- }
1825
- };
1826
- const getRowType$1 = row => {
1827
- const isHeaderRow = row.section === 'thead';
1828
- const isHeaderCells = is(findCommonCellType(row.cells), 'th');
1829
- if (row.section === 'tfoot') {
1830
- return { type: 'footer' };
1831
- } else if (isHeaderRow || isHeaderCells) {
1832
- return {
1833
- type: 'header',
1834
- subType: getRowHeaderType(isHeaderRow, isHeaderCells)
1835
- };
1836
- } else {
1837
- return { type: 'body' };
1838
- }
1839
- };
1840
- const findCommonCellType = cells => {
1841
- const headerCells = filter(cells, cell => isHeaderCell(cell.element));
1842
- if (headerCells.length === 0) {
1843
- return Optional.some('td');
1844
- } else if (headerCells.length === cells.length) {
1845
- return Optional.some('th');
1846
- } else {
1847
- return Optional.none();
1848
- }
1849
- };
1850
- const findCommonRowType = rows => {
1851
- const rowTypes = map(rows, row => getRowType$1(row).type);
1852
- const hasHeader = contains(rowTypes, 'header');
1853
- const hasFooter = contains(rowTypes, 'footer');
1854
- if (!hasHeader && !hasFooter) {
1855
- return Optional.some('body');
1856
- } else {
1857
- const hasBody = contains(rowTypes, 'body');
1858
- if (hasHeader && !hasBody && !hasFooter) {
1859
- return Optional.some('header');
1860
- } else if (!hasHeader && !hasBody && hasFooter) {
1861
- return Optional.some('footer');
1862
- } else {
1863
- return Optional.none();
1864
- }
1865
- }
1866
- };
1867
-
1868
- const cached = f => {
1869
- let called = false;
1870
- let r;
1871
- return (...args) => {
1872
- if (!called) {
1873
- called = true;
1874
- r = f.apply(null, args);
1875
- }
1876
- return r;
1877
- };
1878
- };
1879
-
1880
- const findInWarehouse = (warehouse, element) => findMap(warehouse.all, r => find(r.cells, e => eq(element, e.element)));
1881
- const extractCells = (warehouse, target, predicate) => {
1882
- const details = map(target.selection, cell$1 => {
1883
- return cell(cell$1).bind(lc => findInWarehouse(warehouse, lc)).filter(predicate);
1884
- });
1885
- const cells = cat(details);
1886
- return someIf(cells.length > 0, cells);
1887
- };
1888
- const onMergable = (_warehouse, target) => target.mergable;
1889
- const onUnmergable = (_warehouse, target) => target.unmergable;
1890
- const onCells = (warehouse, target) => extractCells(warehouse, target, always);
1891
- const isUnlockedTableCell = (warehouse, cell) => findInWarehouse(warehouse, cell).exists(detail => !detail.isLocked);
1892
- const allUnlocked = (warehouse, cells) => forall(cells, cell => isUnlockedTableCell(warehouse, cell));
1893
- const onUnlockedMergable = (warehouse, target) => onMergable(warehouse, target).filter(mergeable => allUnlocked(warehouse, mergeable.cells));
1894
- const onUnlockedUnmergable = (warehouse, target) => onUnmergable(warehouse, target).filter(cells => allUnlocked(warehouse, cells));
1895
-
1896
- const generate = cases => {
1897
- if (!isArray(cases)) {
1898
- throw new Error('cases must be an array');
1899
- }
1900
- if (cases.length === 0) {
1901
- throw new Error('there must be at least one case');
1902
- }
1903
- const constructors = [];
1904
- const adt = {};
1905
- each(cases, (acase, count) => {
1906
- const keys$1 = keys(acase);
1907
- if (keys$1.length !== 1) {
1908
- throw new Error('one and only one name per case');
1909
- }
1910
- const key = keys$1[0];
1911
- const value = acase[key];
1912
- if (adt[key] !== undefined) {
1913
- throw new Error('duplicate key detected:' + key);
1914
- } else if (key === 'cata') {
1915
- throw new Error('cannot have a case named cata (sorry)');
1916
- } else if (!isArray(value)) {
1917
- throw new Error('case arguments must be an array');
1918
- }
1919
- constructors.push(key);
1920
- adt[key] = (...args) => {
1921
- const argLength = args.length;
1922
- if (argLength !== value.length) {
1923
- throw new Error('Wrong number of arguments to case ' + key + '. Expected ' + value.length + ' (' + value + '), got ' + argLength);
1924
- }
1925
- const match = branches => {
1926
- const branchKeys = keys(branches);
1927
- if (constructors.length !== branchKeys.length) {
1928
- throw new Error('Wrong number of arguments to match. Expected: ' + constructors.join(',') + '\nActual: ' + branchKeys.join(','));
1929
- }
1930
- const allReqd = forall(constructors, reqKey => {
1931
- return contains(branchKeys, reqKey);
1932
- });
1933
- if (!allReqd) {
1934
- throw new Error('Not all branches were specified when using match. Specified: ' + branchKeys.join(', ') + '\nRequired: ' + constructors.join(', '));
1935
- }
1936
- return branches[key].apply(null, args);
1937
- };
1938
- return {
1939
- fold: (...foldArgs) => {
1940
- if (foldArgs.length !== cases.length) {
1941
- throw new Error('Wrong number of arguments to fold. Expected ' + cases.length + ', got ' + foldArgs.length);
1942
- }
1943
- const target = foldArgs[count];
1944
- return target.apply(null, args);
1945
- },
1946
- match,
1947
- log: label => {
1948
- console.log(label, {
1949
- constructors,
1950
- constructor: key,
1951
- params: args
1952
- });
1953
- }
1954
- };
1955
- };
1956
- });
1957
- return adt;
1958
- };
1959
- const Adt = { generate };
1960
-
1961
- const adt = Adt.generate([
1962
- { none: [] },
1963
- { only: ['index'] },
1964
- {
1965
- left: [
1966
- 'index',
1967
- 'next'
1968
- ]
1969
- },
1970
- {
1971
- middle: [
1972
- 'prev',
1973
- 'index',
1974
- 'next'
1975
- ]
1976
- },
1977
- {
1978
- right: [
1979
- 'prev',
1980
- 'index'
1981
- ]
1982
- }
1983
- ]);
1984
- ({ ...adt });
1985
-
1986
- const opGetRowsType = (table, target) => {
1987
- const house = Warehouse.fromTable(table);
1988
- const details = onCells(house, target);
1989
- return details.bind(selectedCells => {
1990
- const lastSelectedCell = selectedCells[selectedCells.length - 1];
1991
- const minRowRange = selectedCells[0].row;
1992
- const maxRowRange = lastSelectedCell.row + lastSelectedCell.rowspan;
1993
- const selectedRows = house.all.slice(minRowRange, maxRowRange);
1994
- return findCommonRowType(selectedRows);
1995
- }).getOr('');
1996
- };
1997
- const getRowsType = opGetRowsType;
1998
-
1999
- const rgbToHex = value => startsWith(value, 'rgb') ? rgbaToHexString(value) : value;
2000
- const extractAdvancedStyles = elm => {
2001
- const element = SugarElement.fromDom(elm);
2002
- return {
2003
- borderwidth: getRaw(element, 'border-width').getOr(''),
2004
- borderstyle: getRaw(element, 'border-style').getOr(''),
2005
- bordercolor: getRaw(element, 'border-color').map(rgbToHex).getOr(''),
2006
- backgroundcolor: getRaw(element, 'background-color').map(rgbToHex).getOr('')
2007
- };
2008
- };
2009
- const getSharedValues = data => {
2010
- const baseData = data[0];
2011
- const comparisonData = data.slice(1);
2012
- each(comparisonData, items => {
2013
- each(keys(baseData), key => {
2014
- each$1(items, (itemValue, itemKey) => {
2015
- const comparisonValue = baseData[key];
2016
- if (comparisonValue !== '' && key === itemKey) {
2017
- if (comparisonValue !== itemValue) {
2018
- baseData[key] = '';
2019
- }
2020
- }
2021
- });
2022
- });
2023
- });
2024
- return baseData;
2025
- };
2026
- const getAlignment = (formats, formatName, editor, elm) => find(formats, name => !isUndefined(editor.formatter.matchNode(elm, formatName + name))).getOr('');
2027
- const getHAlignment = curry(getAlignment, [
2028
- 'left',
2029
- 'center',
2030
- 'right'
2031
- ], 'align');
2032
- const getVAlignment = curry(getAlignment, [
2033
- 'top',
2034
- 'middle',
2035
- 'bottom'
2036
- ], 'valign');
2037
- const extractDataFromSettings = (editor, hasAdvTableTab) => {
2038
- const style = getDefaultStyles(editor);
2039
- const attrs = getDefaultAttributes(editor);
2040
- const extractAdvancedStyleData = () => ({
2041
- borderstyle: get$4(style, 'border-style').getOr(''),
2042
- bordercolor: rgbToHex(get$4(style, 'border-color').getOr('')),
2043
- backgroundcolor: rgbToHex(get$4(style, 'background-color').getOr(''))
2044
- });
2045
- const defaultData = {
2046
- height: '',
2047
- width: '100%',
2048
- cellspacing: '',
2049
- cellpadding: '',
2050
- caption: false,
2051
- class: '',
2052
- align: '',
2053
- border: ''
2054
- };
2055
- const getBorder = () => {
2056
- const borderWidth = style['border-width'];
2057
- if (shouldStyleWithCss(editor) && borderWidth) {
2058
- return { border: borderWidth };
2059
- }
2060
- return get$4(attrs, 'border').fold(() => ({}), border => ({ border }));
2061
- };
2062
- const advStyle = hasAdvTableTab ? extractAdvancedStyleData() : {};
2063
- const getCellPaddingCellSpacing = () => {
2064
- const spacing = get$4(style, 'border-spacing').or(get$4(attrs, 'cellspacing')).fold(() => ({}), cellspacing => ({ cellspacing }));
2065
- const padding = get$4(style, 'border-padding').or(get$4(attrs, 'cellpadding')).fold(() => ({}), cellpadding => ({ cellpadding }));
2066
- return {
2067
- ...spacing,
2068
- ...padding
2069
- };
2070
- };
2071
- const data = {
2072
- ...defaultData,
2073
- ...style,
2074
- ...attrs,
2075
- ...advStyle,
2076
- ...getBorder(),
2077
- ...getCellPaddingCellSpacing()
2078
- };
2079
- return data;
2080
- };
2081
- const getRowType = elm => table(SugarElement.fromDom(elm)).map(table => {
2082
- const target = { selection: fromDom(elm.cells) };
2083
- return getRowsType(table, target);
2084
- }).getOr('');
2085
- const extractDataFromTableElement = (editor, elm, hasAdvTableTab) => {
2086
- const getBorder = (dom, elm) => {
2087
- const optBorderWidth = getRaw(SugarElement.fromDom(elm), 'border-width');
2088
- if (shouldStyleWithCss(editor) && optBorderWidth.isSome()) {
2089
- return optBorderWidth.getOr('');
2090
- }
2091
- return dom.getAttrib(elm, 'border') || getTDTHOverallStyle(editor.dom, elm, 'border-width') || getTDTHOverallStyle(editor.dom, elm, 'border');
2092
- };
2093
- const dom = editor.dom;
2094
- const cellspacing = shouldStyleWithCss(editor) ? dom.getStyle(elm, 'border-spacing') || dom.getAttrib(elm, 'cellspacing') : dom.getAttrib(elm, 'cellspacing') || dom.getStyle(elm, 'border-spacing');
2095
- const cellpadding = shouldStyleWithCss(editor) ? getTDTHOverallStyle(dom, elm, 'padding') || dom.getAttrib(elm, 'cellpadding') : dom.getAttrib(elm, 'cellpadding') || getTDTHOverallStyle(dom, elm, 'padding');
2096
- return {
2097
- width: dom.getStyle(elm, 'width') || dom.getAttrib(elm, 'width'),
2098
- height: dom.getStyle(elm, 'height') || dom.getAttrib(elm, 'height'),
2099
- cellspacing,
2100
- cellpadding,
2101
- border: getBorder(dom, elm),
2102
- caption: !!dom.select('caption', elm)[0],
2103
- class: dom.getAttrib(elm, 'class', ''),
2104
- align: getHAlignment(editor, elm),
2105
- ...hasAdvTableTab ? extractAdvancedStyles(elm) : {}
2106
- };
2107
- };
2108
- const extractDataFromRowElement = (editor, elm, hasAdvancedRowTab) => {
2109
- const dom = editor.dom;
2110
- return {
2111
- height: dom.getStyle(elm, 'height') || dom.getAttrib(elm, 'height'),
2112
- class: dom.getAttrib(elm, 'class', ''),
2113
- type: getRowType(elm),
2114
- align: getHAlignment(editor, elm),
2115
- ...hasAdvancedRowTab ? extractAdvancedStyles(elm) : {}
2116
- };
2117
- };
2118
- const extractDataFromCellElement = (editor, cell, hasAdvancedCellTab, column) => {
2119
- const dom = editor.dom;
2120
- const colElm = column.getOr(cell);
2121
- const getStyle = (element, style) => dom.getStyle(element, style) || dom.getAttrib(element, style);
2122
- return {
2123
- width: getStyle(colElm, 'width'),
2124
- height: getStyle(cell, 'height'),
2125
- scope: dom.getAttrib(cell, 'scope'),
2126
- celltype: getNodeName(cell),
2127
- class: dom.getAttrib(cell, 'class', ''),
2128
- halign: getHAlignment(editor, cell),
2129
- valign: getVAlignment(editor, cell),
2130
- ...hasAdvancedCellTab ? extractAdvancedStyles(cell) : {}
2131
- };
2132
- };
2133
-
2134
- const getSelectedCells = (table, cells) => {
2135
- const warehouse = Warehouse.fromTable(table);
2136
- const allCells = Warehouse.justCells(warehouse);
2137
- const filtered = filter(allCells, cellA => exists(cells, cellB => eq(cellA.element, cellB)));
2138
- return map(filtered, cell => ({
2139
- element: cell.element.dom,
2140
- column: Warehouse.getColumnAt(warehouse, cell.column).map(col => col.element.dom)
2141
- }));
2142
- };
2143
- const updateSimpleProps$1 = (modifier, colModifier, data, shouldUpdate) => {
2144
- if (shouldUpdate('scope')) {
2145
- modifier.setAttrib('scope', data.scope);
2146
- }
2147
- if (shouldUpdate('class')) {
2148
- modifier.setAttrib('class', data.class);
2149
- }
2150
- if (shouldUpdate('height')) {
2151
- modifier.setStyle('height', addPxSuffix(data.height));
2152
- }
2153
- if (shouldUpdate('width')) {
2154
- colModifier.setStyle('width', addPxSuffix(data.width));
2155
- }
2156
- };
2157
- const updateAdvancedProps$1 = (modifier, data, shouldUpdate) => {
2158
- if (shouldUpdate('backgroundcolor')) {
2159
- modifier.setFormat('tablecellbackgroundcolor', data.backgroundcolor);
2160
- }
2161
- if (shouldUpdate('bordercolor')) {
2162
- modifier.setFormat('tablecellbordercolor', data.bordercolor);
2163
- }
2164
- if (shouldUpdate('borderstyle')) {
2165
- modifier.setFormat('tablecellborderstyle', data.borderstyle);
2166
- }
2167
- if (shouldUpdate('borderwidth')) {
2168
- modifier.setFormat('tablecellborderwidth', addPxSuffix(data.borderwidth));
2169
- }
2170
- };
2171
- const applyStyleData$1 = (editor, cells, data, wasChanged) => {
2172
- const isSingleCell = cells.length === 1;
2173
- each(cells, item => {
2174
- const cellElm = item.element;
2175
- const shouldOverrideCurrentValue = isSingleCell ? always : wasChanged;
2176
- const modifier = DomModifier.normal(editor, cellElm);
2177
- const colModifier = item.column.map(col => DomModifier.normal(editor, col)).getOr(modifier);
2178
- updateSimpleProps$1(modifier, colModifier, data, shouldOverrideCurrentValue);
2179
- if (hasAdvancedCellTab(editor)) {
2180
- updateAdvancedProps$1(modifier, data, shouldOverrideCurrentValue);
2181
- }
2182
- if (wasChanged('halign')) {
2183
- setAlign(editor, cellElm, data.halign);
2184
- }
2185
- if (wasChanged('valign')) {
2186
- setVAlign(editor, cellElm, data.valign);
2187
- }
2188
- });
2189
- };
2190
- const applyStructureData$1 = (editor, data) => {
2191
- editor.execCommand('mceTableCellType', false, {
2192
- type: data.celltype,
2193
- no_events: true
2194
- });
2195
- };
2196
- const applyCellData = (editor, cells, oldData, data) => {
2197
- const modifiedData = filter$1(data, (value, key) => oldData[key] !== value);
2198
- if (size(modifiedData) > 0 && cells.length >= 1) {
2199
- table(cells[0]).each(table => {
2200
- const selectedCells = getSelectedCells(table, cells);
2201
- const styleModified = size(filter$1(modifiedData, (_value, key) => key !== 'scope' && key !== 'celltype')) > 0;
2202
- const structureModified = has(modifiedData, 'celltype');
2203
- if (styleModified || has(modifiedData, 'scope')) {
2204
- applyStyleData$1(editor, selectedCells, data, curry(has, modifiedData));
2205
- }
2206
- if (structureModified) {
2207
- applyStructureData$1(editor, data);
2208
- }
2209
- fireTableModified(editor, table.dom, {
2210
- structure: structureModified,
2211
- style: styleModified
2212
- });
2213
- });
2214
- }
2215
- };
2216
- const onSubmitCellForm = (editor, cells, oldData, api) => {
2217
- const data = api.getData();
2218
- api.close();
2219
- editor.undoManager.transact(() => {
2220
- applyCellData(editor, cells, oldData, data);
2221
- editor.focus();
2222
- });
2223
- };
2224
- const getData$1 = (editor, cells) => {
2225
- const cellsData = table(cells[0]).map(table => map(getSelectedCells(table, cells), item => extractDataFromCellElement(editor, item.element, hasAdvancedCellTab(editor), item.column)));
2226
- return getSharedValues(cellsData.getOrDie());
2227
- };
2228
- const open$2 = editor => {
2229
- const cells = getCellsFromSelection(editor);
2230
- if (cells.length === 0) {
2231
- return;
2232
- }
2233
- const data = getData$1(editor, cells);
2234
- const dialogTabPanel = {
2235
- type: 'tabpanel',
2236
- tabs: [
2237
- {
2238
- title: 'General',
2239
- name: 'general',
2240
- items: getItems$2(editor)
2241
- },
2242
- getAdvancedTab(editor, 'cell')
2243
- ]
2244
- };
2245
- const dialogPanel = {
2246
- type: 'panel',
2247
- items: [{
2248
- type: 'grid',
2249
- columns: 2,
2250
- items: getItems$2(editor)
2251
- }]
2252
- };
2253
- editor.windowManager.open({
2254
- title: 'Cell Properties',
2255
- size: 'normal',
2256
- body: hasAdvancedCellTab(editor) ? dialogTabPanel : dialogPanel,
2257
- buttons: [
2258
- {
2259
- type: 'cancel',
2260
- name: 'cancel',
2261
- text: 'Cancel'
2262
- },
2263
- {
2264
- type: 'submit',
2265
- name: 'save',
2266
- text: 'Save',
2267
- primary: true
2268
- }
2269
- ],
2270
- initialData: data,
2271
- onSubmit: curry(onSubmitCellForm, editor, cells, data)
2272
- });
2273
- };
2274
-
2275
- const getClassList = editor => {
2276
- const classes = buildListItems(getRowClassList(editor));
2277
- if (classes.length > 0) {
2278
- return Optional.some({
2279
- name: 'class',
2280
- type: 'listbox',
2281
- label: 'Class',
2282
- items: classes
2283
- });
2284
- }
2285
- return Optional.none();
2286
- };
2287
- const formChildren = [
2288
- {
2289
- type: 'listbox',
2290
- name: 'type',
2291
- label: 'Row type',
2292
- items: [
2293
- {
2294
- text: 'Header',
2295
- value: 'header'
2296
- },
2297
- {
2298
- text: 'Body',
2299
- value: 'body'
2300
- },
2301
- {
2302
- text: 'Footer',
2303
- value: 'footer'
2304
- }
2305
- ]
2306
- },
2307
- {
2308
- type: 'listbox',
2309
- name: 'align',
2310
- label: 'Alignment',
2311
- items: [
2312
- {
2313
- text: 'None',
2314
- value: ''
2315
- },
2316
- {
2317
- text: 'Left',
2318
- value: 'left'
2319
- },
2320
- {
2321
- text: 'Center',
2322
- value: 'center'
2323
- },
2324
- {
2325
- text: 'Right',
2326
- value: 'right'
2327
- }
2328
- ]
2329
- },
2330
- {
2331
- label: 'Height',
2332
- name: 'height',
2333
- type: 'input'
2334
- }
2335
- ];
2336
- const getItems$1 = editor => formChildren.concat(getClassList(editor).toArray());
2337
-
2338
- const updateSimpleProps = (modifier, data, shouldUpdate) => {
2339
- if (shouldUpdate('class')) {
2340
- modifier.setAttrib('class', data.class);
2341
- }
2342
- if (shouldUpdate('height')) {
2343
- modifier.setStyle('height', addPxSuffix(data.height));
2344
- }
2345
- };
2346
- const updateAdvancedProps = (modifier, data, shouldUpdate) => {
2347
- if (shouldUpdate('backgroundcolor')) {
2348
- modifier.setStyle('background-color', data.backgroundcolor);
2349
- }
2350
- if (shouldUpdate('bordercolor')) {
2351
- modifier.setStyle('border-color', data.bordercolor);
2352
- }
2353
- if (shouldUpdate('borderstyle')) {
2354
- modifier.setStyle('border-style', data.borderstyle);
2355
- }
2356
- };
2357
- const applyStyleData = (editor, rows, data, wasChanged) => {
2358
- const isSingleRow = rows.length === 1;
2359
- const shouldOverrideCurrentValue = isSingleRow ? always : wasChanged;
2360
- each(rows, rowElm => {
2361
- const modifier = DomModifier.normal(editor, rowElm);
2362
- updateSimpleProps(modifier, data, shouldOverrideCurrentValue);
2363
- if (hasAdvancedRowTab(editor)) {
2364
- updateAdvancedProps(modifier, data, shouldOverrideCurrentValue);
2365
- }
2366
- if (wasChanged('align')) {
2367
- setAlign(editor, rowElm, data.align);
2368
- }
2369
- });
2370
- };
2371
- const applyStructureData = (editor, data) => {
2372
- editor.execCommand('mceTableRowType', false, {
2373
- type: data.type,
2374
- no_events: true
2375
- });
2376
- };
2377
- const applyRowData = (editor, rows, oldData, data) => {
2378
- const modifiedData = filter$1(data, (value, key) => oldData[key] !== value);
2379
- if (size(modifiedData) > 0) {
2380
- const typeModified = has(modifiedData, 'type');
2381
- const styleModified = typeModified ? size(modifiedData) > 1 : true;
2382
- if (styleModified) {
2383
- applyStyleData(editor, rows, data, curry(has, modifiedData));
2384
- }
2385
- if (typeModified) {
2386
- applyStructureData(editor, data);
2387
- }
2388
- table(SugarElement.fromDom(rows[0])).each(table => fireTableModified(editor, table.dom, {
2389
- structure: typeModified,
2390
- style: styleModified
2391
- }));
2392
- }
2393
- };
2394
- const onSubmitRowForm = (editor, rows, oldData, api) => {
2395
- const data = api.getData();
2396
- api.close();
2397
- editor.undoManager.transact(() => {
2398
- applyRowData(editor, rows, oldData, data);
2399
- editor.focus();
2400
- });
2401
- };
2402
- const open$1 = editor => {
2403
- const rows = getRowsFromSelection(getSelectionStart(editor), ephemera.selected);
2404
- if (rows.length === 0) {
2405
- return;
2406
- }
2407
- const rowsData = map(rows, rowElm => extractDataFromRowElement(editor, rowElm.dom, hasAdvancedRowTab(editor)));
2408
- const data = getSharedValues(rowsData);
2409
- const dialogTabPanel = {
2410
- type: 'tabpanel',
2411
- tabs: [
2412
- {
2413
- title: 'General',
2414
- name: 'general',
2415
- items: getItems$1(editor)
2416
- },
2417
- getAdvancedTab(editor, 'row')
2418
- ]
2419
- };
2420
- const dialogPanel = {
2421
- type: 'panel',
2422
- items: [{
2423
- type: 'grid',
2424
- columns: 2,
2425
- items: getItems$1(editor)
2426
- }]
2427
- };
2428
- editor.windowManager.open({
2429
- title: 'Row Properties',
2430
- size: 'normal',
2431
- body: hasAdvancedRowTab(editor) ? dialogTabPanel : dialogPanel,
2432
- buttons: [
2433
- {
2434
- type: 'cancel',
2435
- name: 'cancel',
2436
- text: 'Cancel'
2437
- },
2438
- {
2439
- type: 'submit',
2440
- name: 'save',
2441
- text: 'Save',
2442
- primary: true
2443
- }
2444
- ],
2445
- initialData: data,
2446
- onSubmit: curry(onSubmitRowForm, editor, map(rows, r => r.dom), data)
2447
- });
2448
- };
2449
-
2450
- const getItems = (editor, classes, insertNewTable) => {
2451
- const rowColCountItems = !insertNewTable ? [] : [
2452
- {
2453
- type: 'input',
2454
- name: 'cols',
2455
- label: 'Cols',
2456
- inputMode: 'numeric'
2457
- },
2458
- {
2459
- type: 'input',
2460
- name: 'rows',
2461
- label: 'Rows',
2462
- inputMode: 'numeric'
2463
- }
2464
- ];
2465
- const alwaysItems = [
2466
- {
2467
- type: 'input',
2468
- name: 'width',
2469
- label: 'Width'
2470
- },
2471
- {
2472
- type: 'input',
2473
- name: 'height',
2474
- label: 'Height'
2475
- }
2476
- ];
2477
- const appearanceItems = hasAppearanceOptions(editor) ? [
2478
- {
2479
- type: 'input',
2480
- name: 'cellspacing',
2481
- label: 'Cell spacing',
2482
- inputMode: 'numeric'
2483
- },
2484
- {
2485
- type: 'input',
2486
- name: 'cellpadding',
2487
- label: 'Cell padding',
2488
- inputMode: 'numeric'
2489
- },
2490
- {
2491
- type: 'input',
2492
- name: 'border',
2493
- label: 'Border width'
2494
- },
2495
- {
2496
- type: 'label',
2497
- label: 'Caption',
2498
- items: [{
2499
- type: 'checkbox',
2500
- name: 'caption',
2501
- label: 'Show caption'
2502
- }]
2503
- }
2504
- ] : [];
2505
- const alignmentItem = [{
2506
- type: 'listbox',
2507
- name: 'align',
2508
- label: 'Alignment',
2509
- items: [
2510
- {
2511
- text: 'None',
2512
- value: ''
2513
- },
2514
- {
2515
- text: 'Left',
2516
- value: 'left'
2517
- },
2518
- {
2519
- text: 'Center',
2520
- value: 'center'
2521
- },
2522
- {
2523
- text: 'Right',
2524
- value: 'right'
2525
- }
2526
- ]
2527
- }];
2528
- const classListItem = classes.length > 0 ? [{
2529
- type: 'listbox',
2530
- name: 'class',
2531
- label: 'Class',
2532
- items: classes
2533
- }] : [];
2534
- return rowColCountItems.concat(alwaysItems).concat(appearanceItems).concat(alignmentItem).concat(classListItem);
2535
- };
2536
-
2537
- const styleTDTH = (dom, elm, name, value) => {
2538
- if (elm.tagName === 'TD' || elm.tagName === 'TH') {
2539
- if (isString(name)) {
2540
- dom.setStyle(elm, name, value);
2541
- } else {
2542
- dom.setStyles(elm, name);
2543
- }
2544
- } else {
2545
- if (elm.children) {
2546
- for (let i = 0; i < elm.children.length; i++) {
2547
- styleTDTH(dom, elm.children[i], name, value);
2548
- }
2549
- }
2550
- }
2551
- };
2552
- const applyDataToElement = (editor, tableElm, data) => {
2553
- const dom = editor.dom;
2554
- const attrs = {};
2555
- const styles = {};
2556
- attrs.class = data.class;
2557
- styles.height = addPxSuffix(data.height);
2558
- if (shouldStyleWithCss(editor)) {
2559
- styles.width = addPxSuffix(data.width);
2560
- } else if (dom.getAttrib(tableElm, 'width')) {
2561
- attrs.width = removePxSuffix(data.width);
2562
- }
2563
- if (shouldStyleWithCss(editor)) {
2564
- styles['border-width'] = addPxSuffix(data.border);
2565
- styles['border-spacing'] = addPxSuffix(data.cellspacing);
2566
- } else {
2567
- attrs.border = data.border;
2568
- attrs.cellpadding = data.cellpadding;
2569
- attrs.cellspacing = data.cellspacing;
2570
- }
2571
- if (shouldStyleWithCss(editor) && tableElm.children) {
2572
- for (let i = 0; i < tableElm.children.length; i++) {
2573
- styleTDTH(dom, tableElm.children[i], {
2574
- 'border-width': addPxSuffix(data.border),
2575
- 'padding': addPxSuffix(data.cellpadding)
2576
- });
2577
- if (hasAdvancedTableTab(editor)) {
2578
- styleTDTH(dom, tableElm.children[i], { 'border-color': data.bordercolor });
2579
- }
2580
- }
2581
- }
2582
- if (hasAdvancedTableTab(editor)) {
2583
- styles['background-color'] = data.backgroundcolor;
2584
- styles['border-color'] = data.bordercolor;
2585
- styles['border-style'] = data.borderstyle;
2586
- }
2587
- attrs.style = dom.serializeStyle({
2588
- ...getDefaultStyles(editor),
2589
- ...styles
2590
- });
2591
- dom.setAttribs(tableElm, {
2592
- ...getDefaultAttributes(editor),
2593
- ...attrs
2594
- });
2595
- };
2596
- const onSubmitTableForm = (editor, tableElm, oldData, api) => {
2597
- const dom = editor.dom;
2598
- const data = api.getData();
2599
- const modifiedData = filter$1(data, (value, key) => oldData[key] !== value);
2600
- api.close();
2601
- if (data.class === '') {
2602
- delete data.class;
2603
- }
2604
- editor.undoManager.transact(() => {
2605
- if (!tableElm) {
2606
- const cols = parseInt(data.cols, 10) || 1;
2607
- const rows = parseInt(data.rows, 10) || 1;
2608
- editor.execCommand('mceInsertTable', false, {
2609
- rows,
2610
- columns: cols
2611
- });
2612
- tableElm = getSelectionCell(getSelectionStart(editor), getIsRoot(editor)).bind(cell => table(cell, getIsRoot(editor))).map(table => table.dom).getOrUndefined();
2613
- }
2614
- if (size(modifiedData) > 0) {
2615
- applyDataToElement(editor, tableElm, data);
2616
- const captionElm = dom.select('caption', tableElm)[0];
2617
- if (captionElm && !data.caption || !captionElm && data.caption) {
2618
- editor.execCommand('mceTableToggleCaption');
2619
- }
2620
- setAlign(editor, tableElm, data.align);
2621
- }
2622
- editor.focus();
2623
- editor.addVisual();
2624
- if (size(modifiedData) > 0) {
2625
- const captionModified = has(modifiedData, 'caption');
2626
- const styleModified = captionModified ? size(modifiedData) > 1 : true;
2627
- fireTableModified(editor, tableElm, {
2628
- structure: captionModified,
2629
- style: styleModified
2630
- });
2631
- }
2632
- });
2633
- };
2634
- const open = (editor, insertNewTable) => {
2635
- const dom = editor.dom;
2636
- let tableElm;
2637
- let data = extractDataFromSettings(editor, hasAdvancedTableTab(editor));
2638
- if (insertNewTable === false) {
2639
- tableElm = dom.getParent(editor.selection.getStart(), 'table', editor.getBody());
2640
- if (tableElm) {
2641
- data = extractDataFromTableElement(editor, tableElm, hasAdvancedTableTab(editor));
2642
- } else {
2643
- if (hasAdvancedTableTab(editor)) {
2644
- data.borderstyle = '';
2645
- data.bordercolor = '';
2646
- data.backgroundcolor = '';
2647
- }
2648
- }
2649
- } else {
2650
- data.cols = '1';
2651
- data.rows = '1';
2652
- if (hasAdvancedTableTab(editor)) {
2653
- data.borderstyle = '';
2654
- data.bordercolor = '';
2655
- data.backgroundcolor = '';
2656
- }
2657
- }
2658
- const classes = buildListItems(getTableClassList(editor));
2659
- if (classes.length > 0) {
2660
- if (data.class) {
2661
- data.class = data.class.replace(/\s*mce\-item\-table\s*/g, '');
2662
- }
2663
- }
2664
- const generalPanel = {
2665
- type: 'grid',
2666
- columns: 2,
2667
- items: getItems(editor, classes, insertNewTable)
2668
- };
2669
- const nonAdvancedForm = () => ({
2670
- type: 'panel',
2671
- items: [generalPanel]
2672
- });
2673
- const advancedForm = () => ({
2674
- type: 'tabpanel',
2675
- tabs: [
2676
- {
2677
- title: 'General',
2678
- name: 'general',
2679
- items: [generalPanel]
2680
- },
2681
- getAdvancedTab(editor, 'table')
2682
- ]
2683
- });
2684
- const dialogBody = hasAdvancedTableTab(editor) ? advancedForm() : nonAdvancedForm();
2685
- editor.windowManager.open({
2686
- title: 'Table Properties',
2687
- size: 'normal',
2688
- body: dialogBody,
2689
- onSubmit: curry(onSubmitTableForm, editor, tableElm, data),
2690
- buttons: [
2691
- {
2692
- type: 'cancel',
2693
- name: 'cancel',
2694
- text: 'Cancel'
2695
- },
2696
- {
2697
- type: 'submit',
2698
- name: 'save',
2699
- text: 'Save',
2700
- primary: true
2701
- }
2702
- ],
2703
- initialData: data
2704
- });
2705
- };
2706
-
2707
- const registerCommands = editor => {
2708
- each$1({
2709
- mceTableProps: curry(open, editor, false),
2710
- mceTableRowProps: curry(open$1, editor),
2711
- mceTableCellProps: curry(open$2, editor)
2712
- }, (func, name) => editor.addCommand(name, () => func()));
2713
- editor.addCommand('mceInsertTableDialog', _ui => {
2714
- open(editor, true);
2715
- });
2716
- };
2717
-
2718
- const child = (scope, selector) => child$1(scope, selector).isSome();
2719
-
2720
- const selection = identity;
2721
- const unmergable = selectedCells => {
2722
- const hasSpan = (elem, type) => getOpt(elem, type).exists(span => parseInt(span, 10) > 1);
2723
- const hasRowOrColSpan = elem => hasSpan(elem, 'rowspan') || hasSpan(elem, 'colspan');
2724
- return selectedCells.length > 0 && forall(selectedCells, hasRowOrColSpan) ? Optional.some(selectedCells) : Optional.none();
2725
- };
2726
- const mergable = (table, selectedCells, ephemera) => {
2727
- if (selectedCells.length <= 1) {
2728
- return Optional.none();
2729
- } else {
2730
- return retrieveBox(table, ephemera.firstSelectedSelector, ephemera.lastSelectedSelector).map(bounds => ({
2731
- bounds,
2732
- cells: selectedCells
2733
- }));
2734
- }
2735
- };
2736
-
2737
- const noMenu = cell => ({
2738
- element: cell,
2739
- mergable: Optional.none(),
2740
- unmergable: Optional.none(),
2741
- selection: [cell]
2742
- });
2743
- const forMenu = (selectedCells, table, cell) => ({
2744
- element: cell,
2745
- mergable: mergable(table, selectedCells, ephemera),
2746
- unmergable: unmergable(selectedCells),
2747
- selection: selection(selectedCells)
2748
- });
2749
-
2750
- const getSelectionTargets = editor => {
2751
- const targets = Cell(Optional.none());
2752
- const changeHandlers = Cell([]);
2753
- let selectionDetails = Optional.none();
2754
- const isCaption = isTag('caption');
2755
- const isDisabledForSelection = key => selectionDetails.forall(details => !details[key]);
2756
- const getStart = () => getSelectionCellOrCaption(getSelectionStart(editor), getIsRoot(editor));
2757
- const getEnd = () => getSelectionCellOrCaption(getSelectionEnd(editor), getIsRoot(editor));
2758
- const findTargets = () => getStart().bind(startCellOrCaption => flatten(lift2(table(startCellOrCaption), getEnd().bind(table), (startTable, endTable) => {
2759
- if (eq(startTable, endTable)) {
2760
- if (isCaption(startCellOrCaption)) {
2761
- return Optional.some(noMenu(startCellOrCaption));
2762
- } else {
2763
- return Optional.some(forMenu(getCellsFromSelection(editor), startTable, startCellOrCaption));
2764
- }
2765
- }
2766
- return Optional.none();
2767
- })));
2768
- const getExtractedDetails = targets => {
2769
- const tableOpt = table(targets.element);
2770
- return tableOpt.map(table => {
2771
- const warehouse = Warehouse.fromTable(table);
2772
- const selectedCells = onCells(warehouse, targets).getOr([]);
2773
- const locked = foldl(selectedCells, (acc, cell) => {
2774
- if (cell.isLocked) {
2775
- acc.onAny = true;
2776
- if (cell.column === 0) {
2777
- acc.onFirst = true;
2778
- } else if (cell.column + cell.colspan >= warehouse.grid.columns) {
2779
- acc.onLast = true;
2780
- }
2781
- }
2782
- return acc;
2783
- }, {
2784
- onAny: false,
2785
- onFirst: false,
2786
- onLast: false
2787
- });
2788
- return {
2789
- mergeable: onUnlockedMergable(warehouse, targets).isSome(),
2790
- unmergeable: onUnlockedUnmergable(warehouse, targets).isSome(),
2791
- locked
2792
- };
2793
- });
2794
- };
2795
- const resetTargets = () => {
2796
- targets.set(cached(findTargets)());
2797
- selectionDetails = targets.get().bind(getExtractedDetails);
2798
- each(changeHandlers.get(), handler => handler());
2799
- };
2800
- const setupHandler = handler => {
2801
- handler();
2802
- changeHandlers.set(changeHandlers.get().concat([handler]));
2803
- return () => {
2804
- changeHandlers.set(filter(changeHandlers.get(), h => h !== handler));
2805
- };
2806
- };
2807
- const onSetup = (api, isDisabled) => setupHandler(() => targets.get().fold(() => {
2808
- api.setEnabled(false);
2809
- }, targets => {
2810
- api.setEnabled(!isDisabled(targets));
2811
- }));
2812
- const onSetupWithToggle = (api, isDisabled, isActive) => setupHandler(() => targets.get().fold(() => {
2813
- api.setEnabled(false);
2814
- api.setActive(false);
2815
- }, targets => {
2816
- api.setEnabled(!isDisabled(targets));
2817
- api.setActive(isActive(targets));
2818
- }));
2819
- const isDisabledFromLocked = lockedDisable => selectionDetails.exists(details => details.locked[lockedDisable]);
2820
- const onSetupTable = api => onSetup(api, _ => false);
2821
- const onSetupCellOrRow = api => onSetup(api, targets => isCaption(targets.element));
2822
- const onSetupColumn = lockedDisable => api => onSetup(api, targets => isCaption(targets.element) || isDisabledFromLocked(lockedDisable));
2823
- const onSetupPasteable = getClipboardData => api => onSetup(api, targets => isCaption(targets.element) || getClipboardData().isNone());
2824
- const onSetupPasteableColumn = (getClipboardData, lockedDisable) => api => onSetup(api, targets => isCaption(targets.element) || getClipboardData().isNone() || isDisabledFromLocked(lockedDisable));
2825
- const onSetupMergeable = api => onSetup(api, _targets => isDisabledForSelection('mergeable'));
2826
- const onSetupUnmergeable = api => onSetup(api, _targets => isDisabledForSelection('unmergeable'));
2827
- const onSetupTableWithCaption = api => {
2828
- return onSetupWithToggle(api, never, targets => {
2829
- const tableOpt = table(targets.element, getIsRoot(editor));
2830
- return tableOpt.exists(table => child(table, 'caption'));
2831
- });
2832
- };
2833
- const onSetupTableHeaders = (command, headerType) => api => {
2834
- return onSetupWithToggle(api, targets => isCaption(targets.element), () => editor.queryCommandValue(command) === headerType);
2835
- };
2836
- const onSetupTableRowHeaders = onSetupTableHeaders('mceTableRowType', 'header');
2837
- const onSetupTableColumnHeaders = onSetupTableHeaders('mceTableColType', 'th');
2838
- editor.on('NodeChange ExecCommand TableSelectorChange', resetTargets);
2839
- return {
2840
- onSetupTable,
2841
- onSetupCellOrRow,
2842
- onSetupColumn,
2843
- onSetupPasteable,
2844
- onSetupPasteableColumn,
2845
- onSetupMergeable,
2846
- onSetupUnmergeable,
2847
- resetTargets,
2848
- onSetupTableWithCaption,
2849
- onSetupTableRowHeaders,
2850
- onSetupTableColumnHeaders,
2851
- targets: targets.get
2852
- };
2853
- };
2854
-
2855
- var global = tinymce.util.Tools.resolve('tinymce.FakeClipboard');
2856
-
2857
- const tableTypeBase = 'x-tinymce/dom-table-';
2858
- const tableTypeRow = tableTypeBase + 'rows';
2859
- const tableTypeColumn = tableTypeBase + 'columns';
2860
- const getData = type => {
2861
- var _a;
2862
- const items = (_a = global.read()) !== null && _a !== void 0 ? _a : [];
2863
- return findMap(items, item => Optional.from(item.getType(type)));
2864
- };
2865
- const getRows = () => getData(tableTypeRow);
2866
- const getColumns = () => getData(tableTypeColumn);
2867
-
2868
- const addButtons = (editor, selectionTargets) => {
2869
- editor.ui.registry.addMenuButton('table', {
2870
- tooltip: 'Table',
2871
- icon: 'table',
2872
- fetch: callback => callback('inserttable | cell row column | advtablesort | tableprops deletetable')
2873
- });
2874
- const cmd = command => () => editor.execCommand(command);
2875
- const addButtonIfRegistered = (name, spec) => {
2876
- if (editor.queryCommandSupported(spec.command)) {
2877
- editor.ui.registry.addButton(name, {
2878
- ...spec,
2879
- onAction: isFunction(spec.onAction) ? spec.onAction : cmd(spec.command)
2880
- });
2881
- }
2882
- };
2883
- const addToggleButtonIfRegistered = (name, spec) => {
2884
- if (editor.queryCommandSupported(spec.command)) {
2885
- editor.ui.registry.addToggleButton(name, {
2886
- ...spec,
2887
- onAction: isFunction(spec.onAction) ? spec.onAction : cmd(spec.command)
2888
- });
2889
- }
2890
- };
2891
- addButtonIfRegistered('tableprops', {
2892
- tooltip: 'Table properties',
2893
- command: 'mceTableProps',
2894
- icon: 'table',
2895
- onSetup: selectionTargets.onSetupTable
2896
- });
2897
- addButtonIfRegistered('tabledelete', {
2898
- tooltip: 'Delete table',
2899
- command: 'mceTableDelete',
2900
- icon: 'table-delete-table',
2901
- onSetup: selectionTargets.onSetupTable
2902
- });
2903
- addButtonIfRegistered('tablecellprops', {
2904
- tooltip: 'Cell properties',
2905
- command: 'mceTableCellProps',
2906
- icon: 'table-cell-properties',
2907
- onSetup: selectionTargets.onSetupCellOrRow
2908
- });
2909
- addButtonIfRegistered('tablemergecells', {
2910
- tooltip: 'Merge cells',
2911
- command: 'mceTableMergeCells',
2912
- icon: 'table-merge-cells',
2913
- onSetup: selectionTargets.onSetupMergeable
2914
- });
2915
- addButtonIfRegistered('tablesplitcells', {
2916
- tooltip: 'Split cell',
2917
- command: 'mceTableSplitCells',
2918
- icon: 'table-split-cells',
2919
- onSetup: selectionTargets.onSetupUnmergeable
2920
- });
2921
- addButtonIfRegistered('tableinsertrowbefore', {
2922
- tooltip: 'Insert row before',
2923
- command: 'mceTableInsertRowBefore',
2924
- icon: 'table-insert-row-above',
2925
- onSetup: selectionTargets.onSetupCellOrRow
2926
- });
2927
- addButtonIfRegistered('tableinsertrowafter', {
2928
- tooltip: 'Insert row after',
2929
- command: 'mceTableInsertRowAfter',
2930
- icon: 'table-insert-row-after',
2931
- onSetup: selectionTargets.onSetupCellOrRow
2932
- });
2933
- addButtonIfRegistered('tabledeleterow', {
2934
- tooltip: 'Delete row',
2935
- command: 'mceTableDeleteRow',
2936
- icon: 'table-delete-row',
2937
- onSetup: selectionTargets.onSetupCellOrRow
2938
- });
2939
- addButtonIfRegistered('tablerowprops', {
2940
- tooltip: 'Row properties',
2941
- command: 'mceTableRowProps',
2942
- icon: 'table-row-properties',
2943
- onSetup: selectionTargets.onSetupCellOrRow
2944
- });
2945
- addButtonIfRegistered('tableinsertcolbefore', {
2946
- tooltip: 'Insert column before',
2947
- command: 'mceTableInsertColBefore',
2948
- icon: 'table-insert-column-before',
2949
- onSetup: selectionTargets.onSetupColumn('onFirst')
2950
- });
2951
- addButtonIfRegistered('tableinsertcolafter', {
2952
- tooltip: 'Insert column after',
2953
- command: 'mceTableInsertColAfter',
2954
- icon: 'table-insert-column-after',
2955
- onSetup: selectionTargets.onSetupColumn('onLast')
2956
- });
2957
- addButtonIfRegistered('tabledeletecol', {
2958
- tooltip: 'Delete column',
2959
- command: 'mceTableDeleteCol',
2960
- icon: 'table-delete-column',
2961
- onSetup: selectionTargets.onSetupColumn('onAny')
2962
- });
2963
- addButtonIfRegistered('tablecutrow', {
2964
- tooltip: 'Cut row',
2965
- command: 'mceTableCutRow',
2966
- icon: 'cut-row',
2967
- onSetup: selectionTargets.onSetupCellOrRow
2968
- });
2969
- addButtonIfRegistered('tablecopyrow', {
2970
- tooltip: 'Copy row',
2971
- command: 'mceTableCopyRow',
2972
- icon: 'duplicate-row',
2973
- onSetup: selectionTargets.onSetupCellOrRow
2974
- });
2975
- addButtonIfRegistered('tablepasterowbefore', {
2976
- tooltip: 'Paste row before',
2977
- command: 'mceTablePasteRowBefore',
2978
- icon: 'paste-row-before',
2979
- onSetup: selectionTargets.onSetupPasteable(getRows)
2980
- });
2981
- addButtonIfRegistered('tablepasterowafter', {
2982
- tooltip: 'Paste row after',
2983
- command: 'mceTablePasteRowAfter',
2984
- icon: 'paste-row-after',
2985
- onSetup: selectionTargets.onSetupPasteable(getRows)
2986
- });
2987
- addButtonIfRegistered('tablecutcol', {
2988
- tooltip: 'Cut column',
2989
- command: 'mceTableCutCol',
2990
- icon: 'cut-column',
2991
- onSetup: selectionTargets.onSetupColumn('onAny')
2992
- });
2993
- addButtonIfRegistered('tablecopycol', {
2994
- tooltip: 'Copy column',
2995
- command: 'mceTableCopyCol',
2996
- icon: 'duplicate-column',
2997
- onSetup: selectionTargets.onSetupColumn('onAny')
2998
- });
2999
- addButtonIfRegistered('tablepastecolbefore', {
3000
- tooltip: 'Paste column before',
3001
- command: 'mceTablePasteColBefore',
3002
- icon: 'paste-column-before',
3003
- onSetup: selectionTargets.onSetupPasteableColumn(getColumns, 'onFirst')
3004
- });
3005
- addButtonIfRegistered('tablepastecolafter', {
3006
- tooltip: 'Paste column after',
3007
- command: 'mceTablePasteColAfter',
3008
- icon: 'paste-column-after',
3009
- onSetup: selectionTargets.onSetupPasteableColumn(getColumns, 'onLast')
3010
- });
3011
- addButtonIfRegistered('tableinsertdialog', {
3012
- tooltip: 'Insert table',
3013
- command: 'mceInsertTableDialog',
3014
- icon: 'table'
3015
- });
3016
- const tableClassList = filterNoneItem(getTableClassList(editor));
3017
- if (tableClassList.length !== 0 && editor.queryCommandSupported('mceTableToggleClass')) {
3018
- editor.ui.registry.addMenuButton('tableclass', {
3019
- icon: 'table-classes',
3020
- tooltip: 'Table styles',
3021
- fetch: generateMenuItemsCallback(editor, tableClassList, 'tableclass', value => editor.execCommand('mceTableToggleClass', false, value)),
3022
- onSetup: selectionTargets.onSetupTable
3023
- });
3024
- }
3025
- const tableCellClassList = filterNoneItem(getCellClassList(editor));
3026
- if (tableCellClassList.length !== 0 && editor.queryCommandSupported('mceTableCellToggleClass')) {
3027
- editor.ui.registry.addMenuButton('tablecellclass', {
3028
- icon: 'table-cell-classes',
3029
- tooltip: 'Cell styles',
3030
- fetch: generateMenuItemsCallback(editor, tableCellClassList, 'tablecellclass', value => editor.execCommand('mceTableCellToggleClass', false, value)),
3031
- onSetup: selectionTargets.onSetupCellOrRow
3032
- });
3033
- }
3034
- if (editor.queryCommandSupported('mceTableApplyCellStyle')) {
3035
- editor.ui.registry.addMenuButton('tablecellvalign', {
3036
- icon: 'vertical-align',
3037
- tooltip: 'Vertical align',
3038
- fetch: generateMenuItemsCallback(editor, verticalAlignValues, 'tablecellverticalalign', applyTableCellStyle(editor, 'vertical-align')),
3039
- onSetup: selectionTargets.onSetupCellOrRow
3040
- });
3041
- editor.ui.registry.addMenuButton('tablecellborderwidth', {
3042
- icon: 'border-width',
3043
- tooltip: 'Border width',
3044
- fetch: generateMenuItemsCallback(editor, getTableBorderWidths(editor), 'tablecellborderwidth', applyTableCellStyle(editor, 'border-width')),
3045
- onSetup: selectionTargets.onSetupCellOrRow
3046
- });
3047
- editor.ui.registry.addMenuButton('tablecellborderstyle', {
3048
- icon: 'border-style',
3049
- tooltip: 'Border style',
3050
- fetch: generateMenuItemsCallback(editor, getTableBorderStyles(editor), 'tablecellborderstyle', applyTableCellStyle(editor, 'border-style')),
3051
- onSetup: selectionTargets.onSetupCellOrRow
3052
- });
3053
- editor.ui.registry.addMenuButton('tablecellbackgroundcolor', {
3054
- icon: 'cell-background-color',
3055
- tooltip: 'Background color',
3056
- fetch: callback => callback(buildColorMenu(editor, getTableBackgroundColorMap(editor), 'background-color')),
3057
- onSetup: selectionTargets.onSetupCellOrRow
3058
- });
3059
- editor.ui.registry.addMenuButton('tablecellbordercolor', {
3060
- icon: 'cell-border-color',
3061
- tooltip: 'Border color',
3062
- fetch: callback => callback(buildColorMenu(editor, getTableBorderColorMap(editor), 'border-color')),
3063
- onSetup: selectionTargets.onSetupCellOrRow
3064
- });
3065
- }
3066
- addToggleButtonIfRegistered('tablecaption', {
3067
- tooltip: 'Table caption',
3068
- icon: 'table-caption',
3069
- command: 'mceTableToggleCaption',
3070
- onSetup: selectionTargets.onSetupTableWithCaption
3071
- });
3072
- addToggleButtonIfRegistered('tablerowheader', {
3073
- tooltip: 'Row header',
3074
- icon: 'table-top-header',
3075
- command: 'mceTableRowType',
3076
- onAction: changeRowHeader(editor),
3077
- onSetup: selectionTargets.onSetupTableRowHeaders
3078
- });
3079
- addToggleButtonIfRegistered('tablecolheader', {
3080
- tooltip: 'Column header',
3081
- icon: 'table-left-header',
3082
- command: 'mceTableColType',
3083
- onAction: changeColumnHeader(editor),
3084
- onSetup: selectionTargets.onSetupTableColumnHeaders
3085
- });
3086
- };
3087
- const addToolbars = editor => {
3088
- const isTable = table => editor.dom.is(table, 'table') && editor.getBody().contains(table);
3089
- const toolbar = getToolbar(editor);
3090
- if (toolbar.length > 0) {
3091
- editor.ui.registry.addContextToolbar('table', {
3092
- predicate: isTable,
3093
- items: toolbar,
3094
- scope: 'node',
3095
- position: 'node'
3096
- });
3097
- }
3098
- };
3099
-
3100
- const addMenuItems = (editor, selectionTargets) => {
3101
- const cmd = command => () => editor.execCommand(command);
3102
- const addMenuIfRegistered = (name, spec) => {
3103
- if (editor.queryCommandSupported(spec.command)) {
3104
- editor.ui.registry.addMenuItem(name, {
3105
- ...spec,
3106
- onAction: isFunction(spec.onAction) ? spec.onAction : cmd(spec.command)
3107
- });
3108
- return true;
3109
- } else {
3110
- return false;
3111
- }
3112
- };
3113
- const addToggleMenuIfRegistered = (name, spec) => {
3114
- if (editor.queryCommandSupported(spec.command)) {
3115
- editor.ui.registry.addToggleMenuItem(name, {
3116
- ...spec,
3117
- onAction: isFunction(spec.onAction) ? spec.onAction : cmd(spec.command)
3118
- });
3119
- }
3120
- };
3121
- const insertTableAction = data => {
3122
- editor.execCommand('mceInsertTable', false, {
3123
- rows: data.numRows,
3124
- columns: data.numColumns
3125
- });
3126
- };
3127
- const hasRowMenuItems = [
3128
- addMenuIfRegistered('tableinsertrowbefore', {
3129
- text: 'Insert row before',
3130
- icon: 'table-insert-row-above',
3131
- command: 'mceTableInsertRowBefore',
3132
- onSetup: selectionTargets.onSetupCellOrRow
3133
- }),
3134
- addMenuIfRegistered('tableinsertrowafter', {
3135
- text: 'Insert row after',
3136
- icon: 'table-insert-row-after',
3137
- command: 'mceTableInsertRowAfter',
3138
- onSetup: selectionTargets.onSetupCellOrRow
3139
- }),
3140
- addMenuIfRegistered('tabledeleterow', {
3141
- text: 'Delete row',
3142
- icon: 'table-delete-row',
3143
- command: 'mceTableDeleteRow',
3144
- onSetup: selectionTargets.onSetupCellOrRow
3145
- }),
3146
- addMenuIfRegistered('tablerowprops', {
3147
- text: 'Row properties',
3148
- icon: 'table-row-properties',
3149
- command: 'mceTableRowProps',
3150
- onSetup: selectionTargets.onSetupCellOrRow
3151
- }),
3152
- addMenuIfRegistered('tablecutrow', {
3153
- text: 'Cut row',
3154
- icon: 'cut-row',
3155
- command: 'mceTableCutRow',
3156
- onSetup: selectionTargets.onSetupCellOrRow
3157
- }),
3158
- addMenuIfRegistered('tablecopyrow', {
3159
- text: 'Copy row',
3160
- icon: 'duplicate-row',
3161
- command: 'mceTableCopyRow',
3162
- onSetup: selectionTargets.onSetupCellOrRow
3163
- }),
3164
- addMenuIfRegistered('tablepasterowbefore', {
3165
- text: 'Paste row before',
3166
- icon: 'paste-row-before',
3167
- command: 'mceTablePasteRowBefore',
3168
- onSetup: selectionTargets.onSetupPasteable(getRows)
3169
- }),
3170
- addMenuIfRegistered('tablepasterowafter', {
3171
- text: 'Paste row after',
3172
- icon: 'paste-row-after',
3173
- command: 'mceTablePasteRowAfter',
3174
- onSetup: selectionTargets.onSetupPasteable(getRows)
3175
- })
3176
- ];
3177
- const hasColumnMenuItems = [
3178
- addMenuIfRegistered('tableinsertcolumnbefore', {
3179
- text: 'Insert column before',
3180
- icon: 'table-insert-column-before',
3181
- command: 'mceTableInsertColBefore',
3182
- onSetup: selectionTargets.onSetupColumn('onFirst')
3183
- }),
3184
- addMenuIfRegistered('tableinsertcolumnafter', {
3185
- text: 'Insert column after',
3186
- icon: 'table-insert-column-after',
3187
- command: 'mceTableInsertColAfter',
3188
- onSetup: selectionTargets.onSetupColumn('onLast')
3189
- }),
3190
- addMenuIfRegistered('tabledeletecolumn', {
3191
- text: 'Delete column',
3192
- icon: 'table-delete-column',
3193
- command: 'mceTableDeleteCol',
3194
- onSetup: selectionTargets.onSetupColumn('onAny')
3195
- }),
3196
- addMenuIfRegistered('tablecutcolumn', {
3197
- text: 'Cut column',
3198
- icon: 'cut-column',
3199
- command: 'mceTableCutCol',
3200
- onSetup: selectionTargets.onSetupColumn('onAny')
3201
- }),
3202
- addMenuIfRegistered('tablecopycolumn', {
3203
- text: 'Copy column',
3204
- icon: 'duplicate-column',
3205
- command: 'mceTableCopyCol',
3206
- onSetup: selectionTargets.onSetupColumn('onAny')
3207
- }),
3208
- addMenuIfRegistered('tablepastecolumnbefore', {
3209
- text: 'Paste column before',
3210
- icon: 'paste-column-before',
3211
- command: 'mceTablePasteColBefore',
3212
- onSetup: selectionTargets.onSetupPasteableColumn(getColumns, 'onFirst')
3213
- }),
3214
- addMenuIfRegistered('tablepastecolumnafter', {
3215
- text: 'Paste column after',
3216
- icon: 'paste-column-after',
3217
- command: 'mceTablePasteColAfter',
3218
- onSetup: selectionTargets.onSetupPasteableColumn(getColumns, 'onLast')
3219
- })
3220
- ];
3221
- const hasCellMenuItems = [
3222
- addMenuIfRegistered('tablecellprops', {
3223
- text: 'Cell properties',
3224
- icon: 'table-cell-properties',
3225
- command: 'mceTableCellProps',
3226
- onSetup: selectionTargets.onSetupCellOrRow
3227
- }),
3228
- addMenuIfRegistered('tablemergecells', {
3229
- text: 'Merge cells',
3230
- icon: 'table-merge-cells',
3231
- command: 'mceTableMergeCells',
3232
- onSetup: selectionTargets.onSetupMergeable
3233
- }),
3234
- addMenuIfRegistered('tablesplitcells', {
3235
- text: 'Split cell',
3236
- icon: 'table-split-cells',
3237
- command: 'mceTableSplitCells',
3238
- onSetup: selectionTargets.onSetupUnmergeable
3239
- })
3240
- ];
3241
- if (!hasTableGrid(editor)) {
3242
- editor.ui.registry.addMenuItem('inserttable', {
3243
- text: 'Table',
3244
- icon: 'table',
3245
- onAction: cmd('mceInsertTableDialog')
3246
- });
3247
- } else {
3248
- editor.ui.registry.addNestedMenuItem('inserttable', {
3249
- text: 'Table',
3250
- icon: 'table',
3251
- getSubmenuItems: () => [{
3252
- type: 'fancymenuitem',
3253
- fancytype: 'inserttable',
3254
- onAction: insertTableAction
3255
- }]
3256
- });
3257
- }
3258
- editor.ui.registry.addMenuItem('inserttabledialog', {
3259
- text: 'Insert table',
3260
- icon: 'table',
3261
- onAction: cmd('mceInsertTableDialog')
3262
- });
3263
- addMenuIfRegistered('tableprops', {
3264
- text: 'Table properties',
3265
- onSetup: selectionTargets.onSetupTable,
3266
- command: 'mceTableProps'
3267
- });
3268
- addMenuIfRegistered('deletetable', {
3269
- text: 'Delete table',
3270
- icon: 'table-delete-table',
3271
- onSetup: selectionTargets.onSetupTable,
3272
- command: 'mceTableDelete'
3273
- });
3274
- if (contains(hasRowMenuItems, true)) {
3275
- editor.ui.registry.addNestedMenuItem('row', {
3276
- type: 'nestedmenuitem',
3277
- text: 'Row',
3278
- getSubmenuItems: constant('tableinsertrowbefore tableinsertrowafter tabledeleterow tablerowprops | tablecutrow tablecopyrow tablepasterowbefore tablepasterowafter')
3279
- });
3280
- }
3281
- if (contains(hasColumnMenuItems, true)) {
3282
- editor.ui.registry.addNestedMenuItem('column', {
3283
- type: 'nestedmenuitem',
3284
- text: 'Column',
3285
- getSubmenuItems: constant('tableinsertcolumnbefore tableinsertcolumnafter tabledeletecolumn | tablecutcolumn tablecopycolumn tablepastecolumnbefore tablepastecolumnafter')
3286
- });
3287
- }
3288
- if (contains(hasCellMenuItems, true)) {
3289
- editor.ui.registry.addNestedMenuItem('cell', {
3290
- type: 'nestedmenuitem',
3291
- text: 'Cell',
3292
- getSubmenuItems: constant('tablecellprops tablemergecells tablesplitcells')
3293
- });
3294
- }
3295
- editor.ui.registry.addContextMenu('table', {
3296
- update: () => {
3297
- selectionTargets.resetTargets();
3298
- return selectionTargets.targets().fold(constant(''), targets => {
3299
- if (name(targets.element) === 'caption') {
3300
- return 'tableprops deletetable';
3301
- } else {
3302
- return 'cell row column | advtablesort | tableprops deletetable';
3303
- }
3304
- });
3305
- }
3306
- });
3307
- const tableClassList = filterNoneItem(getTableClassList(editor));
3308
- if (tableClassList.length !== 0 && editor.queryCommandSupported('mceTableToggleClass')) {
3309
- editor.ui.registry.addNestedMenuItem('tableclass', {
3310
- icon: 'table-classes',
3311
- text: 'Table styles',
3312
- getSubmenuItems: () => buildMenuItems(editor, tableClassList, 'tableclass', value => editor.execCommand('mceTableToggleClass', false, value)),
3313
- onSetup: selectionTargets.onSetupTable
3314
- });
3315
- }
3316
- const tableCellClassList = filterNoneItem(getCellClassList(editor));
3317
- if (tableCellClassList.length !== 0 && editor.queryCommandSupported('mceTableCellToggleClass')) {
3318
- editor.ui.registry.addNestedMenuItem('tablecellclass', {
3319
- icon: 'table-cell-classes',
3320
- text: 'Cell styles',
3321
- getSubmenuItems: () => buildMenuItems(editor, tableCellClassList, 'tablecellclass', value => editor.execCommand('mceTableCellToggleClass', false, value)),
3322
- onSetup: selectionTargets.onSetupCellOrRow
3323
- });
3324
- }
3325
- if (editor.queryCommandSupported('mceTableApplyCellStyle')) {
3326
- editor.ui.registry.addNestedMenuItem('tablecellvalign', {
3327
- icon: 'vertical-align',
3328
- text: 'Vertical align',
3329
- getSubmenuItems: () => buildMenuItems(editor, verticalAlignValues, 'tablecellverticalalign', applyTableCellStyle(editor, 'vertical-align')),
3330
- onSetup: selectionTargets.onSetupCellOrRow
3331
- });
3332
- editor.ui.registry.addNestedMenuItem('tablecellborderwidth', {
3333
- icon: 'border-width',
3334
- text: 'Border width',
3335
- getSubmenuItems: () => buildMenuItems(editor, getTableBorderWidths(editor), 'tablecellborderwidth', applyTableCellStyle(editor, 'border-width')),
3336
- onSetup: selectionTargets.onSetupCellOrRow
3337
- });
3338
- editor.ui.registry.addNestedMenuItem('tablecellborderstyle', {
3339
- icon: 'border-style',
3340
- text: 'Border style',
3341
- getSubmenuItems: () => buildMenuItems(editor, getTableBorderStyles(editor), 'tablecellborderstyle', applyTableCellStyle(editor, 'border-style')),
3342
- onSetup: selectionTargets.onSetupCellOrRow
3343
- });
3344
- editor.ui.registry.addNestedMenuItem('tablecellbackgroundcolor', {
3345
- icon: 'cell-background-color',
3346
- text: 'Background color',
3347
- getSubmenuItems: () => buildColorMenu(editor, getTableBackgroundColorMap(editor), 'background-color'),
3348
- onSetup: selectionTargets.onSetupCellOrRow
3349
- });
3350
- editor.ui.registry.addNestedMenuItem('tablecellbordercolor', {
3351
- icon: 'cell-border-color',
3352
- text: 'Border color',
3353
- getSubmenuItems: () => buildColorMenu(editor, getTableBorderColorMap(editor), 'border-color'),
3354
- onSetup: selectionTargets.onSetupCellOrRow
3355
- });
3356
- }
3357
- addToggleMenuIfRegistered('tablecaption', {
3358
- icon: 'table-caption',
3359
- text: 'Table caption',
3360
- command: 'mceTableToggleCaption',
3361
- onSetup: selectionTargets.onSetupTableWithCaption
3362
- });
3363
- addToggleMenuIfRegistered('tablerowheader', {
3364
- text: 'Row header',
3365
- icon: 'table-top-header',
3366
- command: 'mceTableRowType',
3367
- onAction: changeRowHeader(editor),
3368
- onSetup: selectionTargets.onSetupTableRowHeaders
3369
- });
3370
- addToggleMenuIfRegistered('tablecolheader', {
3371
- text: 'Column header',
3372
- icon: 'table-left-header',
3373
- command: 'mceTableColType',
3374
- onAction: changeColumnHeader(editor),
3375
- onSetup: selectionTargets.onSetupTableRowHeaders
3376
- });
3377
- };
3378
-
3379
- const Plugin = editor => {
3380
- const selectionTargets = getSelectionTargets(editor);
3381
- register(editor);
3382
- registerCommands(editor);
3383
- addMenuItems(editor, selectionTargets);
3384
- addButtons(editor, selectionTargets);
3385
- addToolbars(editor);
3386
- };
3387
- var Plugin$1 = () => {
3388
- global$3.add('table', Plugin);
3389
- };
3390
-
3391
- Plugin$1();
3392
-
3393
- })();