-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
tui-editor-extTable.js
3937 lines (3132 loc) · 124 KB
/
tui-editor-extTable.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*!
* tui-editor
* @version 1.2.2
* @author NHN Ent. FE Development Lab <dl_javascript@nhnent.com> (https://nhnent.github.io/tui.editor/)
* @license MIT
*/
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("jquery"), require("tui-code-snippet"), (function webpackLoadOptionalExternalModule() { try { return require("tui-editor"); } catch(e) {} }()), (function webpackLoadOptionalExternalModule() { try { return require("tui-editor/dist/tui-editor-Viewer"); } catch(e) {} }()), require("to-mark"));
else if(typeof define === 'function' && define.amd)
define(["jquery", "tui-code-snippet", "tui-editor", "tui-editor/dist/tui-editor-Viewer", "to-mark"], factory);
else {
var a = typeof exports === 'object' ? factory(require("jquery"), require("tui-code-snippet"), (function webpackLoadOptionalExternalModule() { try { return require("tui-editor"); } catch(e) {} }()), (function webpackLoadOptionalExternalModule() { try { return require("tui-editor/dist/tui-editor-Viewer"); } catch(e) {} }()), require("to-mark")) : factory(root["$"], (root["tui"] && root["tui"]["util"]), (root["tui"] && root["tui"]["Editor"]), (root["tui"] && root["tui"]["Editor"]), root["toMark"]);
for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
}
})(typeof self !== 'undefined' ? self : this, function(__WEBPACK_EXTERNAL_MODULE_0__, __WEBPACK_EXTERNAL_MODULE_2__, __WEBPACK_EXTERNAL_MODULE_4__, __WEBPACK_EXTERNAL_MODULE_5__, __WEBPACK_EXTERNAL_MODULE_54__) {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "dist/";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 49);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports) {
module.exports = __WEBPACK_EXTERNAL_MODULE_0__;
/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
/**
* @fileoverview Editor/Viewer proxy for extensions
* @author NHN Ent. FE Development Lab <dl_javascript@nhnent.com>
*/
/* eslint global-require: 0 no-empty: 0 */
var Editor = void 0;
try {
Editor = __webpack_require__(4);
} catch (e) {}
if (!Editor) {
try {
Editor = __webpack_require__(5);
} catch (e) {}
}
exports.default = Editor;
/***/ }),
/* 2 */
/***/ (function(module, exports) {
module.exports = __WEBPACK_EXTERNAL_MODULE_2__;
/***/ }),
/* 3 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createTableData = createTableData;
exports.createCellIndexData = createCellIndexData;
var _jquery = __webpack_require__(0);
var _jquery2 = _interopRequireDefault(_jquery);
var _tuiCodeSnippet = __webpack_require__(2);
var _tuiCodeSnippet2 = _interopRequireDefault(_tuiCodeSnippet);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Parse cell like td or th.
* @param {HTMLElement} cell - cell element like td or th
* @param {number} rowIndex - row index
* @param {number} colIndex - column index
* @returns {{
* nodeName: string,
* colspan: number,
* rowspan: number,
* content: string,
* align: ?string
* }}
* @private
*/
/**
* @fileoverview Implements tableDataHandler
* @author NHN Ent. FE Development Lab <dl_javascript@nhnent.com>
*/
function _parseCell(cell, rowIndex, colIndex) {
var $cell = (0, _jquery2.default)(cell);
var colspan = $cell.attr('colspan');
var rowspan = $cell.attr('rowspan');
var nodeName = cell.nodeName;
if (nodeName !== 'TH' && nodeName !== 'TD') {
return null;
}
var cellData = {
nodeName: cell.nodeName,
colspan: colspan ? parseInt(colspan, 10) : 1,
rowspan: rowspan ? parseInt(rowspan, 10) : 1,
content: $cell.html(),
elementIndex: {
rowIndex: rowIndex,
colIndex: colIndex
}
};
if (cell.nodeName === 'TH' && cell.align) {
cellData.align = cell.align;
}
return cellData;
}
/**
* Add merged cell.
* @param {object} base - base table data
* @param {object} cellData - cell data
* @param {number} startRowIndex - start row index
* @param {number} startCellIndex - start cell index
* @private
*/
function _addMergedCell(base, cellData, startRowIndex, startCellIndex) {
var colspan = cellData.colspan,
rowspan = cellData.rowspan,
nodeName = cellData.nodeName;
var colMerged = colspan > 1;
var rowMerged = rowspan > 1;
if (!colMerged && !rowMerged) {
return;
}
var limitRowIndex = startRowIndex + rowspan;
var limitCellIndex = startCellIndex + colspan;
_tuiCodeSnippet2.default.range(startRowIndex, limitRowIndex).forEach(function (rowIndex) {
base[rowIndex] = base[rowIndex] || [];
_tuiCodeSnippet2.default.range(startCellIndex, limitCellIndex).forEach(function (cellIndex) {
var mergedData = {
nodeName: nodeName
};
if (rowIndex === startRowIndex && cellIndex === startCellIndex) {
return;
}
if (colMerged) {
mergedData.colMergeWith = startCellIndex;
}
if (rowMerged) {
mergedData.rowMergeWith = startRowIndex;
}
base[rowIndex][cellIndex] = mergedData;
});
});
}
/**
* Create table data from jQuery table Element.
* @param {jQuery} $table - jQuery table element
* @returns {Array.<Array.<object>>}
* @ignore
*/
function createTableData($table) {
var tableData = [];
$table.find('tr').each(function (rowIndex, tr) {
var stackedColCount = 0;
tableData[rowIndex] = tableData[rowIndex] || [];
(0, _jquery2.default)(tr).children().each(function (colIndex, cell) {
var cellData = _parseCell(cell, rowIndex, colIndex);
if (!cellData) {
return;
}
var dataColIndex = colIndex + stackedColCount;
while (tableData[rowIndex][dataColIndex]) {
dataColIndex += 1;
stackedColCount += 1;
}
tableData[rowIndex][dataColIndex] = cellData;
_addMergedCell(tableData, cellData, rowIndex, dataColIndex);
});
});
if ($table[0].className) {
tableData.className = $table[0].className;
}
return tableData;
}
/**
* Create cell index data of table data.
* @param {Array.<Array.<object>>} tableData - table data
* @returns {Array.<Array.<object>>}
* @ignore
*/
function createCellIndexData(tableData) {
var mappingData = [];
tableData.forEach(function (row, rowIndex) {
var mappingRow = [];
row.forEach(function (cell, colIndex) {
if (_tuiCodeSnippet2.default.isUndefined(cell.colMergeWith) && _tuiCodeSnippet2.default.isUndefined(cell.rowMergeWith)) {
mappingRow.push({
rowIndex: rowIndex,
colIndex: colIndex
});
}
});
mappingData.push(mappingRow);
});
return mappingData;
}
/**
* Get header aligns.
* @param {Array.<Array.<object>>} tableData - table data
* @returns {Array.<?string>}
* @private
*/
function _getHeaderAligns(tableData) {
var headRowData = tableData[0];
return headRowData.map(function (cellData) {
var align = void 0;
if (_tuiCodeSnippet2.default.isExisty(cellData.colMergeWith)) {
align = headRowData[cellData.colMergeWith].align;
} else {
align = cellData.align;
}
return align;
});
}
/**
* Create render data.
* @param {Array.<object>} tableData - table data
* @param {Array.<object>} cellIndexData - cell index data
* @returns {Array.<Array.<object>>}
* @ignore
*/
function createRenderData(tableData, cellIndexData) {
var headerAligns = _getHeaderAligns(tableData);
var renderData = cellIndexData.map(function (row) {
return row.map(function (_ref) {
var rowIndex = _ref.rowIndex,
colIndex = _ref.colIndex;
return _tuiCodeSnippet2.default.extend({
align: headerAligns[colIndex]
}, tableData[rowIndex][colIndex]);
});
});
if (tableData.className) {
renderData.className = tableData.className;
}
return renderData;
}
var BASIC_CELL_CONTENT = _tuiCodeSnippet2.default.browser.msie ? '' : '<br>';
/**
* Create basic cell data.
* @param {number} rowIndex - row index
* @param {number} colIndex - column index
* @param {string} nodeName - node name
* @returns {{
* nodeName: string,
* colspan: number,
* rowspan: number,
* content: string
* }}
* @ignore
*/
function createBasicCell(rowIndex, colIndex, nodeName) {
return {
nodeName: nodeName || 'TD',
colspan: 1,
rowspan: 1,
content: BASIC_CELL_CONTENT,
elementIndex: {
rowIndex: rowIndex,
colIndex: colIndex
}
};
}
/**
* Find element row index.
* @param {jQuery} $cell - cell jQuery element like td or th
* @returns {number}
* @ignore
*/
function findElementRowIndex($cell) {
var $tr = $cell.closest('tr');
var rowIndex = $tr.prevAll().length;
if ($tr.parent()[0].nodeName === 'TBODY') {
rowIndex += 1;
}
return rowIndex;
}
/**
* Find element col index.
* @param {jQuery} $cell - cell jQuery element like td or th
* @returns {number}
* @ignore
*/
function findElementColIndex($cell) {
return $cell.closest('td, th').prevAll().length;
}
/**
* Find indexes of base table data from mappin data.
* @param {Array.<Array.<object>>} cellIndexData - cell index data
* @param {jQuery} $cell - cell jQuery element like td or th
* @returns {{rowIndex: number, cellIndex: number}}
* @ignore
*/
function findCellIndex(cellIndexData, $cell) {
var elementRowIndex = findElementRowIndex($cell);
var elementColIndex = findElementColIndex($cell);
return cellIndexData[elementRowIndex][elementColIndex];
}
/**
* Find last index of col merged cells.
* @param {Array.<Array.<object>>} tableData - tableData data
* @param {number} rowIndex - row index of base data
* @param {number} colIndex - column index of tabld data
* @returns {number}
* @ignore
*/
function findRowMergedLastIndex(tableData, rowIndex, colIndex) {
var cellData = tableData[rowIndex][colIndex];
var foundRowIndex = rowIndex;
if (cellData.rowspan > 1) {
foundRowIndex += cellData.rowspan - 1;
}
return foundRowIndex;
}
/**
* Find last index of col merged cells.
* @param {Array.<Array.<object>>} tableData - tableData data
* @param {number} rowIndex - row index of base data
* @param {number} colIndex - column index of tabld data
* @returns {number}
* @ignore
*/
function findColMergedLastIndex(tableData, rowIndex, colIndex) {
var cellData = tableData[rowIndex][colIndex];
var foundColIndex = colIndex;
if (cellData.colspan > 1) {
foundColIndex += cellData.colspan - 1;
}
return foundColIndex;
}
/**
* Find cell element index.
* @param {Array.<Array.<object>>} tableData - tableData data
* @param {number} rowIndex - row index of base data
* @param {number} colIndex - col index of base data
* @returns {{rowIndex: number, colIndex: number}}
* @ignore
*/
function findElementIndex(tableData, rowIndex, colIndex) {
var cellData = tableData[rowIndex][colIndex];
rowIndex = _tuiCodeSnippet2.default.isExisty(cellData.rowMergeWith) ? cellData.rowMergeWith : rowIndex;
colIndex = _tuiCodeSnippet2.default.isExisty(cellData.colMergeWith) ? cellData.colMergeWith : colIndex;
return tableData[rowIndex][colIndex].elementIndex;
}
/**
* Stuff cells into incomplete row.
* @param {Array.<Array.<object>>} tableData - table data
* @param {number} limitIndex - limit index
* @ignore
*/
function stuffCellsIntoIncompleteRow(tableData, limitIndex) {
tableData.forEach(function (rowData, rowIndex) {
var startIndex = rowData.length;
var nodeName = rowData[0].nodeName;
_tuiCodeSnippet2.default.range(startIndex, limitIndex).forEach(function (colIndex) {
rowData.push(createBasicCell(rowIndex, colIndex, nodeName));
});
});
}
/**
* Add tbody or thead of table data if need.
* @param {Array.<Array.<object>>} tableData - table data
* @returns {boolean}
* @ignore
*/
function addTbodyOrTheadIfNeed(tableData) {
var header = tableData[0];
var cellCount = header.length;
var added = true;
if (!cellCount && tableData[1]) {
_tuiCodeSnippet2.default.range(0, tableData[1].length).forEach(function (colIndex) {
header.push(createBasicCell(0, colIndex, 'TH'));
});
} else if (tableData[0][0].nodeName !== 'TH') {
var _ref2;
var newHeader = _tuiCodeSnippet2.default.range(0, cellCount).map(function (colIndex) {
return createBasicCell(0, colIndex, 'TH');
});
(_ref2 = []).concat.apply(_ref2, tableData).forEach(function (cellData) {
if (cellData.elementIndex) {
cellData.elementIndex.rowIndex += 1;
}
});
tableData.unshift(newHeader);
} else if (tableData.length === 1) {
var newRow = _tuiCodeSnippet2.default.range(0, cellCount).map(function (colIndex) {
return createBasicCell(1, colIndex, 'TD');
});
tableData.push(newRow);
} else {
added = false;
}
return added;
}
exports.default = {
createTableData: createTableData,
createCellIndexData: createCellIndexData,
createRenderData: createRenderData,
findElementRowIndex: findElementRowIndex,
findElementColIndex: findElementColIndex,
findCellIndex: findCellIndex,
createBasicCell: createBasicCell,
findRowMergedLastIndex: findRowMergedLastIndex,
findColMergedLastIndex: findColMergedLastIndex,
findElementIndex: findElementIndex,
stuffCellsIntoIncompleteRow: stuffCellsIntoIncompleteRow,
addTbodyOrTheadIfNeed: addTbodyOrTheadIfNeed
};
/***/ }),
/* 4 */
/***/ (function(module, exports) {
if(typeof __WEBPACK_EXTERNAL_MODULE_4__ === 'undefined') {var e = new Error("Cannot find module \"undefined\""); e.code = 'MODULE_NOT_FOUND'; throw e;}
module.exports = __WEBPACK_EXTERNAL_MODULE_4__;
/***/ }),
/* 5 */
/***/ (function(module, exports) {
if(typeof __WEBPACK_EXTERNAL_MODULE_5__ === 'undefined') {var e = new Error("Cannot find module \"undefined\""); e.code = 'MODULE_NOT_FOUND'; throw e;}
module.exports = __WEBPACK_EXTERNAL_MODULE_5__;
/***/ }),
/* 6 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _jquery = __webpack_require__(0);
var _jquery2 = _interopRequireDefault(_jquery);
var _tableDataHandler = __webpack_require__(3);
var _tableDataHandler2 = _interopRequireDefault(_tableDataHandler);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Create cell html.
* @param {object} cell - cell data of table base data
* @returns {string}
* @private
*/
/**
* @fileoverview Implements tableRenderer
* @author NHN Ent. FE Development Lab <dl_javascript@nhnent.com>
*/
function _createCellHtml(cell) {
var attrs = cell.colspan > 1 ? ' colspan="' + cell.colspan + '"' : '';
attrs += cell.rowspan > 1 ? ' rowspan="' + cell.rowspan + '"' : '';
attrs += cell.align ? ' align="' + cell.align + '"' : '';
return '<' + cell.nodeName + attrs + '>' + cell.content + '</' + cell.nodeName + '>';
}
/**
* Create html for thead or tbody.
* @param {Array.<Array.<object>>} trs - tr list
* @param {string} wrapperNodeName - wrapper node name like THEAD, TBODY
* @returns {string}
* @private
*/
function _createTheadOrTbodyHtml(trs, wrapperNodeName) {
var html = '';
if (trs.length) {
html = trs.map(function (tr) {
var tdHtml = tr.map(_createCellHtml).join('');
return '<tr>' + tdHtml + '</tr>';
}).join('');
html = '<' + wrapperNodeName + '>' + html + '</' + wrapperNodeName + '>';
}
return html;
}
/**
* Create table html.
* @param {Array.<Array.<object>>} renderData - table data for render
* @returns {string}
* @private
*/
function createTableHtml(renderData) {
var thead = [renderData[0]];
var tbody = renderData.slice(1);
var theadHtml = _createTheadOrTbodyHtml(thead, 'THEAD');
var tbodyHtml = _createTheadOrTbodyHtml(tbody, 'TBODY');
var className = renderData.className ? ' class="' + renderData.className + '"' : '';
return '<table' + className + '>' + (theadHtml + tbodyHtml) + '</renderData>';
}
/**
* Replace table.
* @param {jQuery} $table - table jQuery element
* @param {Array.<Array.<object>>} tableData - table data
* @returns {jQuery}
* @ignore
*/
function replaceTable($table, tableData) {
var cellIndexData = _tableDataHandler2.default.createCellIndexData(tableData);
var renderData = _tableDataHandler2.default.createRenderData(tableData, cellIndexData);
var $newTable = (0, _jquery2.default)(createTableHtml(renderData));
$table.replaceWith($newTable);
return $newTable;
}
/**
* Focus to cell.
* @param {squireext} sq - squire instance
* @param {range} range - range object
* @param {HTMLElement} targetCell - cell element for focus
* @ignore
*/
function focusToCell(sq, range, targetCell) {
range.selectNodeContents(targetCell);
range.collapse(true);
sq.setSelection(range);
}
exports.default = {
createTableHtml: createTableHtml,
replaceTable: replaceTable,
focusToCell: focusToCell
};
/***/ }),
/* 7 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _jquery = __webpack_require__(0);
var _jquery2 = _interopRequireDefault(_jquery);
var _tuiCodeSnippet = __webpack_require__(2);
var _tuiCodeSnippet2 = _interopRequireDefault(_tuiCodeSnippet);
var _tableDataHandler = __webpack_require__(3);
var _tableDataHandler2 = _interopRequireDefault(_tableDataHandler);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Find unmerged table range.
* @param {Array.<Array.<object>>} tableData - table data
* @param {jQuery} $start - start talbe cell jQuery element
* @param {jQuery} $end - end table cell jQuery element
* @returns {{
* start: {rowIndex: number, colIndex: number},
* end: {rowIndex: number, colIndex: number}
* }}
* @private
*/
function _findUnmergedRange(tableData, $start, $end) {
var cellIndexData = _tableDataHandler2.default.createCellIndexData(tableData);
var startCellIndex = _tableDataHandler2.default.findCellIndex(cellIndexData, $start);
var endCellIndex = _tableDataHandler2.default.findCellIndex(cellIndexData, $end);
var startRowIndex = void 0,
endRowIndex = void 0,
startColIndex = void 0,
endColIndex = void 0;
if (startCellIndex.rowIndex > endCellIndex.rowIndex) {
startRowIndex = endCellIndex.rowIndex;
endRowIndex = startCellIndex.rowIndex;
} else {
startRowIndex = startCellIndex.rowIndex;
endRowIndex = endCellIndex.rowIndex;
}
if (startCellIndex.colIndex > endCellIndex.colIndex) {
startColIndex = endCellIndex.colIndex;
endColIndex = startCellIndex.colIndex;
} else {
startColIndex = startCellIndex.colIndex;
endColIndex = endCellIndex.colIndex;
}
return {
start: {
rowIndex: startRowIndex,
colIndex: startColIndex
},
end: {
rowIndex: endRowIndex,
colIndex: endColIndex
}
};
}
/**
* Expand table range by row merge properties like rowspan, rowMergeWith.
* @param {Array.<Array.<object>>} tableData - table data
* @param {{
* start: {rowIndex: number, colIndex: number},
* end: {rowIndex: number, colIndex: number}
* }} tableRange - table range
* @param {string} rangeType - range type like start, end
* @private
*/
/**
* @fileoverview Implements tableRangeHandler
* @author NHN Ent. FE Development Lab <dl_javascript@nhnent.com>
*/
function _expandRowMergedRange(tableData, tableRange, rangeType) {
var rowIndex = tableRange[rangeType].rowIndex;
var rowData = tableData[rowIndex];
_tuiCodeSnippet2.default.range(tableRange.start.colIndex, tableRange.end.colIndex + 1).forEach(function (colIndex) {
var cellData = rowData[colIndex];
var rowMergeWith = cellData.rowMergeWith;
var lastRowMergedIndex = -1;
if (_tuiCodeSnippet2.default.isExisty(rowMergeWith)) {
if (rowMergeWith < tableRange.start.rowIndex) {
tableRange.start.rowIndex = rowMergeWith;
}
lastRowMergedIndex = rowMergeWith + tableData[rowMergeWith][colIndex].rowspan - 1;
} else if (cellData.rowspan > 1) {
lastRowMergedIndex = rowIndex + cellData.rowspan - 1;
}
if (lastRowMergedIndex > tableRange.end.rowIndex) {
tableRange.end.rowIndex = lastRowMergedIndex;
}
});
}
/**
* Expand table range by column merge properties like colspan, colMergeWith.
* @param {Array.<Array.<object>>} tableData - table data
* @param {{
* start: {rowIndex: number, colIndex: number},
* end: {rowIndex: number, colIndex: number}
* }} tableRange - table range
* @param {number} rowIndex - row index
* @param {number} colIndex - column index
* @private
*/
function _expandColMergedRange(tableData, tableRange, rowIndex, colIndex) {
var rowData = tableData[rowIndex];
var cellData = rowData[colIndex];
var colMergeWith = cellData.colMergeWith;
var lastColMergedIndex = -1;
if (_tuiCodeSnippet2.default.isExisty(colMergeWith)) {
if (colMergeWith < tableRange.start.colIndex) {
tableRange.start.colIndex = colMergeWith;
}
lastColMergedIndex = colMergeWith + rowData[colMergeWith].colspan - 1;
} else if (cellData.colspan > 1) {
lastColMergedIndex = colIndex + cellData.colspan - 1;
}
if (lastColMergedIndex > tableRange.end.colIndex) {
tableRange.end.colIndex = lastColMergedIndex;
}
}
/**
* Expand table range by merge properties like colspan, rowspan.
* @param {Array.<Array.<object>>} tableData - table data
* @param {{
* start: {rowIndex: number, colIndex: number},
* end: {rowIndex: number, colIndex: number}
* }} tableRange - table range
* @returns {{
* start: {rowIndex: number, colIndex: number},
* end: {rowIndex: number, colIndex: number}
* }}
* @private
*/
function _expandMergedRange(tableData, tableRange) {
var rangeStr = '';
while (rangeStr !== JSON.stringify(tableRange)) {
rangeStr = JSON.stringify(tableRange);
_expandRowMergedRange(tableData, tableRange, 'start');
_expandRowMergedRange(tableData, tableRange, 'end');
_tuiCodeSnippet2.default.range(tableRange.start.rowIndex, tableRange.end.rowIndex + 1).forEach(function (rowIndex) {
_expandColMergedRange(tableData, tableRange, rowIndex, tableRange.start.colIndex);
_expandColMergedRange(tableData, tableRange, rowIndex, tableRange.end.colIndex);
});
}
return tableRange;
}
/**
* Find table range for selection.
* @param {Array.<Array.<object>>} tableData - table data
* @param {jQuery} $start - start jQuery element
* @param {jQuery} $end - end jQuery element
* @returns {{
* start: {rowIndex: number, colIndex: number},
* end: {rowIndex: number, colIndex: number}
* }}
* @ignore
*/
function findSelectionRange(tableData, $start, $end) {
var unmergedRange = _findUnmergedRange(tableData, $start, $end);
return _expandMergedRange(tableData, unmergedRange);
}
/**
* Get table selection range.
* @param {Array.<Array.<object>>} tableData - table data
* @param {jQuery} $selectedCells - selected cells jQuery elements
* @param {jQuery} $startContainer - start container jQuery element of text range
* @returns {{
* start: {rowIndex: number, colIndex: number},
* end: {rowIndex: number, colIndex: number}
*}}
* @ignore
*/
function getTableSelectionRange(tableData, $selectedCells, $startContainer) {
var cellIndexData = _tableDataHandler2.default.createCellIndexData(tableData);
var tableRange = {};
if ($selectedCells.length) {
var startRange = _tableDataHandler2.default.findCellIndex(cellIndexData, $selectedCells.first());
var endRange = _tuiCodeSnippet2.default.extend({}, startRange);
$selectedCells.each(function (index, cell) {
var cellIndex = _tableDataHandler2.default.findCellIndex(cellIndexData, (0, _jquery2.default)(cell));
var cellData = tableData[cellIndex.rowIndex][cellIndex.colIndex];
var lastRowMergedIndex = cellIndex.rowIndex + cellData.rowspan - 1;
var lastColMergedIndex = cellIndex.colIndex + cellData.colspan - 1;
endRange.rowIndex = Math.max(endRange.rowIndex, lastRowMergedIndex);
endRange.colIndex = Math.max(endRange.colIndex, lastColMergedIndex);
});
tableRange.start = startRange;
tableRange.end = endRange;
} else {
var cellIndex = _tableDataHandler2.default.findCellIndex(cellIndexData, $startContainer);
tableRange.start = cellIndex;
tableRange.end = _tuiCodeSnippet2.default.extend({}, cellIndex);
}
return tableRange;
}
exports.default = {
findSelectionRange: findSelectionRange,
getTableSelectionRange: getTableSelectionRange
};
/***/ }),
/* 8 */,
/* 9 */,
/* 10 */,
/* 11 */,
/* 12 */,
/* 13 */,
/* 14 */,
/* 15 */,
/* 16 */,
/* 17 */,
/* 18 */,
/* 19 */,
/* 20 */,
/* 21 */,
/* 22 */,
/* 23 */,
/* 24 */,
/* 25 */,
/* 26 */,
/* 27 */,
/* 28 */,
/* 29 */,
/* 30 */,
/* 31 */,
/* 32 */,
/* 33 */,
/* 34 */,
/* 35 */,
/* 36 */,
/* 37 */,
/* 38 */,
/* 39 */,
/* 40 */,
/* 41 */,
/* 42 */,
/* 43 */,
/* 44 */,
/* 45 */,
/* 46 */,
/* 47 */,
/* 48 */,
/* 49 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var _jquery = __webpack_require__(0);
var _jquery2 = _interopRequireDefault(_jquery);
var _editorProxy = __webpack_require__(1);
var _editorProxy2 = _interopRequireDefault(_editorProxy);
__webpack_require__(50);
var _mergedTableCreator = __webpack_require__(51);
var _mergedTableCreator2 = _interopRequireDefault(_mergedTableCreator);
var _tableUnmergePreparer = __webpack_require__(52);
var _tableUnmergePreparer2 = _interopRequireDefault(_tableUnmergePreparer);
var _toMarkRenderer = __webpack_require__(53);
var _toMarkRenderer2 = _interopRequireDefault(_toMarkRenderer);
var _wwMergedTableManager = __webpack_require__(55);
var _wwMergedTableManager2 = _interopRequireDefault(_wwMergedTableManager);
var _wwMergedTableSelectionManager = __webpack_require__(56);
var _wwMergedTableSelectionManager2 = _interopRequireDefault(_wwMergedTableSelectionManager);
var _mergedTableAddRow = __webpack_require__(57);