@enos5/enos-vue-default 1.8.15 → 1.8.17

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