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