@operato/scene-table 7.3.9 → 7.3.19

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.
package/src/table.ts DELETED
@@ -1,1417 +0,0 @@
1
- /*
2
- * Copyright © HatioLab Inc. All rights reserved.
3
- */
4
-
5
- import { Component, ComponentNature, Container, Control, Layout, State, Style } from '@hatiolab/things-scene'
6
-
7
- import {
8
- above,
9
- after,
10
- array,
11
- before,
12
- below,
13
- buildCopiedCell,
14
- buildNewCell,
15
- CLEAR_STYLE,
16
- columnControlHandler,
17
- isBottomMost,
18
- isLeftMost,
19
- isRightMost,
20
- isTopMost,
21
- rowControlHandler,
22
- setCellBorder,
23
- WHERE
24
- } from './helper-functions'
25
- import TableCell from './table-cell'
26
-
27
- const NATURE: ComponentNature = {
28
- mutable: false,
29
- resizable: true,
30
- rotatable: true,
31
- properties: [
32
- {
33
- type: 'number',
34
- label: 'rows',
35
- name: 'rows',
36
- property: 'rows'
37
- },
38
- {
39
- type: 'number',
40
- label: 'columns',
41
- name: 'columns',
42
- property: 'columns'
43
- },
44
- {
45
- type: 'select',
46
- label: 'data-spread-to',
47
- name: 'spreadTo',
48
- property: {
49
- options: ['', 'text']
50
- }
51
- }
52
- ],
53
- 'value-property': 'data',
54
- help: 'scene/component/table'
55
- }
56
-
57
- export default class Table extends Container {
58
- created() {
59
- var tobeSize = this.rows * this.columns
60
- var gap = this.size() - tobeSize
61
-
62
- if (this.data) {
63
- this.setCellsData()
64
- }
65
-
66
- if (gap == 0) {
67
- return
68
- } else if (gap > 0) {
69
- let removals = this.components.slice(gap)
70
- this.remove(removals)
71
- } else {
72
- let newbies = []
73
-
74
- for (let i = 0; i < -gap; i++) newbies.push(buildNewCell('table-cell', this.app))
75
-
76
- this.add(newbies)
77
- }
78
-
79
- var widths = this.getState('widths')
80
- var heights = this.getState('heights')
81
-
82
- if (!widths || widths.length < this.columns) this.set('widths', this.widths)
83
- if (!heights || heights.length < this.rows) this.set('heights', this.heights)
84
- }
85
-
86
- containable(component: Component) {
87
- return component.getState('type') == 'table-cell'
88
- }
89
-
90
- get focusible() {
91
- /* 이 컨테이너에는 컴포넌트를 임의로 추가 및 삭제할 수 없도록 함 */
92
- return false
93
- }
94
-
95
- get widths() {
96
- var widths = this.getState('widths')
97
-
98
- if (!widths) return array(1, this.columns)
99
-
100
- if (widths.length < this.columns) return widths.concat(array(1, this.columns - widths.length))
101
- else if (widths.length > this.columns) return widths.slice(0, this.columns)
102
-
103
- return widths
104
- }
105
-
106
- get heights() {
107
- var heights = this.getState('heights')
108
-
109
- if (!heights) return array(1, this.rows)
110
-
111
- if (heights.length < this.rows) return heights.concat(array(1, this.rows - heights.length))
112
- else if (heights.length > this.rows) return heights.slice(0, this.rows)
113
-
114
- return heights
115
- }
116
-
117
- buildCells(newrows: number, newcolumns: number, oldrows: number, oldcolumns: number) {
118
- if (newrows < oldrows) {
119
- let removals: TableCell[] = ([] = this.components.slice(oldcolumns * newrows) as TableCell[])
120
-
121
- // 지우려는 셀중에 병합된 셀을 찾는다.
122
- let mergedCells: TableCell[] = []
123
- removals.forEach(cell => {
124
- if (cell.merged === true || cell.rowspan > 1 || cell.colspan > 1) mergedCells.push(cell)
125
- })
126
-
127
- // 병합된 셀 중에서 슈퍼셀을 찾는다.
128
- if (mergedCells.length > 0) {
129
- // 부모 셀을 저장
130
- let superCells: TableCell[] = []
131
- // 부모 셀의 인덱스를 저장
132
- let superCellIndexes: number[] = []
133
- mergedCells.forEach(cell => {
134
- let col, row, index
135
- col = this.components.indexOf(cell) % oldcolumns
136
- row = Math.floor(this.components.indexOf(cell) / oldcolumns)
137
- index = row * oldcolumns + col + 1
138
- while (index) {
139
- --index
140
- let component: TableCell = this.components[index] as TableCell
141
- // 슈퍼셀을 찾고 슈퍼셀의 위치에서 rowspan, colspan 거리만큼 이동하면서 cell이 있는지 검증해야함
142
- if (component.rowspan > 1 || component.colspan > 1) {
143
- let spColStart = this.components.indexOf(component) % oldcolumns
144
- let spColEnd = (this.components.indexOf(component) % oldcolumns) + component.colspan
145
- let spRowStart = Math.floor(this.components.indexOf(component) / oldcolumns)
146
- let spRowEnd = Math.floor(this.components.indexOf(component) / oldcolumns) + component.rowspan
147
- // 슈퍼셀 영역 안에 자식 셀이 있으면 superCells에 부모셀을 추가
148
- if (col >= spColStart && col < spColEnd && row >= spRowStart && row < spRowEnd) {
149
- if (-1 == superCellIndexes.indexOf(index)) {
150
- superCellIndexes.push(index)
151
- superCells.push(component)
152
- }
153
- }
154
- }
155
- }
156
- })
157
- // 슈퍼셀에서 colspan 을 감소시킨다
158
- superCells.forEach(cell => {
159
- // newcolumns < oldcolumns 케이스와 이 부분만 다름
160
- cell.rowspan -= oldrows - newrows
161
- })
162
- }
163
-
164
- this.remove(removals)
165
- }
166
-
167
- var minrows = Math.min(newrows, oldrows)
168
-
169
- if (newcolumns > oldcolumns) {
170
- for (let r = 0; r < minrows; r++) {
171
- for (let c = oldcolumns; c < newcolumns; c++) {
172
- this.insertComponentAt(buildNewCell('table-cell', this.app), r * newcolumns + c)
173
- }
174
- }
175
- } else if (newcolumns < oldcolumns) {
176
- let removals: TableCell[] = []
177
-
178
- for (let r = 0; r < minrows; r++) {
179
- for (let c = newcolumns; c < oldcolumns; c++) {
180
- removals.push(this.components[r * oldcolumns + c] as TableCell)
181
- }
182
- }
183
- // 지우려는 셀중에 병합된 셀을 찾는다.
184
- let mergedCells: TableCell[] = []
185
- removals.forEach(cell => {
186
- if (cell.merged === true || cell.rowspan > 1 || cell.colspan > 1) mergedCells.push(cell)
187
- })
188
-
189
- // 병합된 셀 중에서 슈퍼셀을 찾는다.
190
- if (mergedCells.length > 0) {
191
- // 부모 셀을 저장
192
- let superCells: TableCell[] = []
193
- // 부모 셀의 인덱스를 저장
194
- let superCellIndexes: number[] = []
195
- mergedCells.forEach(cell => {
196
- let col, row, index
197
- col = this.components.indexOf(cell) % oldcolumns
198
- row = Math.floor(this.components.indexOf(cell) / oldcolumns)
199
- index = row * oldcolumns + col + 1
200
- while (index) {
201
- --index
202
- let component = this.components[index] as TableCell
203
- // 슈퍼셀을 찾고 슈퍼셀의 위치에서 rowspan, colspan 거리만큼 이동하면서 cell이 있는지 검증해야함
204
- if (component.rowspan > 1 || component.colspan > 1) {
205
- let spColStart = this.components.indexOf(component) % oldcolumns
206
- let spColEnd = (this.components.indexOf(component) % oldcolumns) + component.colspan
207
- let spRowStart = Math.floor(this.components.indexOf(component) / oldcolumns)
208
- let spRowEnd = Math.floor(this.components.indexOf(component) / oldcolumns) + component.rowspan
209
- // 슈퍼셀 영역 안에 자식 셀이 있으면 superCells에 부모셀을 추가
210
- if (col >= spColStart && col < spColEnd && row >= spRowStart && row < spRowEnd) {
211
- if (-1 == superCellIndexes.indexOf(index)) {
212
- superCellIndexes.push(index)
213
- superCells.push(component)
214
- }
215
- }
216
- }
217
- }
218
- })
219
- // 슈퍼셀에서 colspan 을 감소시킨다
220
- superCells.forEach(cell => {
221
- cell.colspan -= oldcolumns - newcolumns
222
- })
223
- }
224
-
225
- this.remove(removals)
226
- }
227
-
228
- if (newrows > oldrows) {
229
- let newbies = []
230
-
231
- for (let r = oldrows; r < newrows; r++) {
232
- for (let i = 0; i < newcolumns; i++) {
233
- newbies.push(buildNewCell('table-cell', this.app))
234
- }
235
- }
236
- this.add(newbies)
237
- }
238
-
239
- this.set({
240
- widths: this.widths,
241
- heights: this.heights
242
- })
243
- }
244
-
245
- get layout() {
246
- return Layout.get('table')
247
- }
248
-
249
- get rows() {
250
- return Number(this.getState('rows'))
251
- }
252
-
253
- setCellsStyle(cells: TableCell[], style: Style, where: WHERE, clearBefore = true) {
254
- var components = this.components
255
- var total = components.length
256
- var columns = this.getState('columns')
257
-
258
- // 병합된 셀도 포함시킨다.
259
- var _cells: TableCell[] = []
260
- cells.forEach(c => {
261
- _cells.push(c)
262
- if (c.colspan || c.rowspan) {
263
- let col = this.getRowColumn(c).column
264
- let row = this.getRowColumn(c).row
265
- for (let i = row; i < row + c.rowspan; i++)
266
- for (let j = col; j < col + c.colspan; j++)
267
- if (i != row || j != col) _cells.push(this.components[i * this.columns + j] as TableCell)
268
- }
269
- })
270
- var indices = _cells.map(cell => components.indexOf(cell))
271
- indices.forEach(i => {
272
- var cell = components[i]
273
- clearBefore && setCellBorder(cell, CLEAR_STYLE, 'all')
274
-
275
- switch (where) {
276
- case 'all':
277
- setCellBorder(cell, style, where)
278
-
279
- if (isLeftMost(total, columns, indices, i)) setCellBorder(components[before(columns, i)], style, 'right')
280
- if (isRightMost(total, columns, indices, i)) setCellBorder(components[after(columns, i)], style, 'left')
281
- if (isTopMost(total, columns, indices, i)) setCellBorder(components[above(columns, i)], style, 'bottom')
282
- if (isBottomMost(total, columns, indices, i)) setCellBorder(components[below(columns, i)], style, 'top')
283
- break
284
- case 'in':
285
- if (!isLeftMost(total, columns, indices, i)) {
286
- setCellBorder(cell, style, 'left')
287
- }
288
- if (!isRightMost(total, columns, indices, i)) {
289
- setCellBorder(cell, style, 'right')
290
- }
291
- if (!isTopMost(total, columns, indices, i)) {
292
- setCellBorder(cell, style, 'top')
293
- }
294
- if (!isBottomMost(total, columns, indices, i)) {
295
- setCellBorder(cell, style, 'bottom')
296
- }
297
- break
298
- case 'out':
299
- if (isLeftMost(total, columns, indices, i)) {
300
- setCellBorder(cell, style, 'left')
301
- setCellBorder(components[before(columns, i)], style, 'right')
302
- }
303
- if (isRightMost(total, columns, indices, i)) {
304
- setCellBorder(cell, style, 'right')
305
- setCellBorder(components[after(columns, i)], style, 'left')
306
- }
307
- if (isTopMost(total, columns, indices, i)) {
308
- setCellBorder(cell, style, 'top')
309
- setCellBorder(components[above(columns, i)], style, 'bottom')
310
- }
311
- if (isBottomMost(total, columns, indices, i)) {
312
- setCellBorder(cell, style, 'bottom')
313
- setCellBorder(components[below(columns, i)], style, 'top')
314
- }
315
- break
316
- case 'left':
317
- if (isLeftMost(total, columns, indices, i)) {
318
- setCellBorder(cell, style, 'left')
319
- setCellBorder(components[before(columns, i)], style, 'right')
320
- }
321
- break
322
- case 'right':
323
- if (isRightMost(total, columns, indices, i)) {
324
- setCellBorder(cell, style, 'right')
325
- setCellBorder(components[after(columns, i)], style, 'left')
326
- }
327
- break
328
- case 'center':
329
- if (!isLeftMost(total, columns, indices, i)) {
330
- setCellBorder(cell, style, 'left')
331
- }
332
- if (!isRightMost(total, columns, indices, i)) {
333
- setCellBorder(cell, style, 'right')
334
- }
335
- break
336
- case 'middle':
337
- if (!isTopMost(total, columns, indices, i)) {
338
- setCellBorder(cell, style, 'top')
339
- }
340
- if (!isBottomMost(total, columns, indices, i)) {
341
- setCellBorder(cell, style, 'bottom')
342
- }
343
- break
344
- case 'top':
345
- if (isTopMost(total, columns, indices, i)) {
346
- setCellBorder(cell, style, 'top')
347
- setCellBorder(components[above(columns, i)], style, 'bottom')
348
- }
349
- break
350
- case 'bottom':
351
- if (isBottomMost(total, columns, indices, i)) {
352
- setCellBorder(cell, style, 'bottom')
353
- setCellBorder(components[below(columns, i)], style, 'top')
354
- }
355
- break
356
- case 'clear':
357
- setCellBorder(cell, CLEAR_STYLE, 'all')
358
-
359
- if (isLeftMost(total, columns, indices, i))
360
- setCellBorder(components[before(columns, i)], CLEAR_STYLE, 'right')
361
- if (isRightMost(total, columns, indices, i)) setCellBorder(components[after(columns, i)], CLEAR_STYLE, 'left')
362
- if (isTopMost(total, columns, indices, i)) setCellBorder(components[above(columns, i)], CLEAR_STYLE, 'bottom')
363
- if (isBottomMost(total, columns, indices, i)) setCellBorder(components[below(columns, i)], CLEAR_STYLE, 'top')
364
- }
365
- })
366
- }
367
-
368
- setCellsData() {
369
- var data = this.data
370
-
371
- if (!data) return
372
-
373
- data = this.toObjectArrayValue(data) || []
374
-
375
- var cells = this.components as TableCell[]
376
-
377
- var { spreadTo } = this.state
378
-
379
- cells.forEach(cell => {
380
- var dataKey = cell.model.dataKey
381
- var dataIndex = cell.model.dataIndex
382
-
383
- if (dataIndex >= 0) {
384
- const cellData = dataKey ? (data[dataIndex] || {})[dataKey] : data[dataIndex]
385
-
386
- ;(cell as any).data = cellData
387
- if (spreadTo) {
388
- ;(cell as any)[spreadTo] = cellData
389
- }
390
- }
391
- })
392
- }
393
-
394
- getRowColumn(cell: TableCell): { column: number; row: number } {
395
- var idx = this.components.indexOf(cell)
396
-
397
- return {
398
- column: idx % this.columns,
399
- row: Math.floor(idx / this.columns)
400
- }
401
- }
402
-
403
- getCellsByRow(row: number) {
404
- return this.components.slice(row * this.columns, (row + 1) * this.columns)
405
- }
406
-
407
- getCellsByColumn(column: number) {
408
- var cells = []
409
- for (var i = 0; i < this.rows; i++) cells.push(this.components[this.columns * i + column])
410
-
411
- return cells
412
- }
413
-
414
- // 한 개의 행을 매개변수로 받아서 첫 번째 셀부터 우측으로 이동하면서 병합된 셀이 있는지 검사한다.
415
- findMergedCellByX(row: number) {
416
- let mergedCells: TableCell[] = []
417
- let cell: TableCell
418
- for (let i = 0; i < this.columns; i++) {
419
- cell = this.components[row * this.columns + i] as TableCell
420
- if (cell.merged === true || cell.rowspan > 1 || cell.colspan > 1) mergedCells.push(cell)
421
- }
422
- return mergedCells
423
- }
424
-
425
- // 한 개의 열을 매개변수로 받아서 첫 번째 셀부터 아래로 이동하면서 병합된 셀이 있는지 검사한다.
426
- findMergedCellByY(column: number) {
427
- let mergedCells: TableCell[] = []
428
- let cell: TableCell
429
- for (let i = 0; i < this.rows; i++) {
430
- cell = this.components[i * this.columns + column] as TableCell
431
- if (cell.merged === true || cell.rowspan > 1 || cell.colspan > 1) mergedCells.push(cell)
432
- }
433
- return mergedCells
434
- }
435
-
436
- mergeCells(cells: TableCell[]) {
437
- // 선택한 셀이 들어있는 행
438
- let mergeableRows: number[] = []
439
- cells.forEach(cell => {
440
- let row = this.getRowColumn(cell).row
441
- if (-1 == mergeableRows.indexOf(row)) mergeableRows.push(row)
442
- })
443
-
444
- // 선택한 셀의 행이 연속적인 숫자가 아니라면 병합하지 않는다.
445
- if (mergeableRows.length - 1 !== mergeableRows[mergeableRows.length - 1] - mergeableRows[0]) return false
446
-
447
- // 선택한 셀이 들어있는 열
448
- let mergeableColumns: number[] = []
449
- cells.forEach(cell => {
450
- let column = this.getRowColumn(cell).column
451
- if (-1 == mergeableColumns.indexOf(column)) mergeableColumns.push(column)
452
- })
453
-
454
- // 선택한 셀의 열이 연속적인 숫자가 아니라면 병합하지 않는다.
455
- if (mergeableColumns.length - 1 !== mergeableColumns[mergeableColumns.length - 1] - mergeableColumns[0])
456
- return false
457
-
458
- // 병합할 행의 수
459
- let numberOfRows = mergeableRows.length
460
-
461
- // 병합할 열의 수
462
- let numberOfColumns = mergeableColumns.length
463
-
464
- // 선택된 셀의 수
465
- let numberOfCells = cells.length
466
-
467
- // 병합될 조건 검사
468
- // 행과 열의 곱이 셀의 수가 아니거나 셀의 수가 2보다 작은 경우는 병합하지 않는다.
469
- if (numberOfCells !== numberOfRows * numberOfColumns || numberOfCells < 2) return false
470
-
471
- // 선택한 셀들을 index 값이 낮은 것부터 순서대로 재정렬
472
- cells.sort((a, b) => {
473
- return (
474
- this.getRowColumn(a).row * this.columns +
475
- this.getRowColumn(a).column -
476
- (this.getRowColumn(b).row * this.columns + this.getRowColumn(b).column)
477
- )
478
- })
479
-
480
- // 셀을 병합함
481
- let firstCell = cells[0]
482
- firstCell.set({
483
- colspan: numberOfColumns,
484
- rowspan: numberOfRows
485
- })
486
-
487
- // 첫 번째 셀을 제외한 나머지 셀을 true로 지정
488
- for (let i = 1; i < numberOfCells; i++) cells[i].merged = true
489
-
490
- // 병합 후에는 첫 번째 셀을 선택하도록 함
491
- this.root.selected = [firstCell]
492
- }
493
-
494
- splitCells(cells: TableCell[]) {
495
- // 선택한 병합된 셀의 정보를 가져온다.
496
- let firstCellRowColumn = this.getRowColumn(cells[0])
497
- let firstCell = cells[0]
498
- let firstCellIndex = this.components.indexOf(cells[0])
499
- let length = this.components.length
500
- let lastCell = this.components[length - 1] as TableCell
501
- let lastCellRowColumn = this.getRowColumn(lastCell)
502
- let startIndex = length / (lastCellRowColumn.row + 1)
503
-
504
- // 병합된 셀들을 구해서 merged를 false로 설정한다.
505
- // 자식 셀이 갖고 있는 부모 셀의 위치를 초기화 한다.
506
- for (let j = 0; j < firstCell.rowspan; j++) {
507
- let index
508
- let nextCell: TableCell
509
- for (let i = firstCellIndex; i < firstCellIndex + firstCell.colspan; i++) {
510
- index = startIndex * j + i
511
- nextCell = this.components[index] as TableCell
512
- nextCell.merged = false
513
- }
514
- }
515
-
516
- // 첫 번째 셀의 rowspan, colspan = 1로 지정한다.
517
- firstCell.colspan = 1
518
- firstCell.rowspan = 1
519
- }
520
-
521
- deleteRows(cells: TableCell[]) {
522
- // 만약 선택한 셀이 병합된 셀이라면 삭제하지 않는다.
523
- if (cells[0].merged == true) return false
524
- // 먼저 cells 위치의 행을 구한다.
525
- let rows: number[] = []
526
- cells.forEach(cell => {
527
- let row = this.getRowColumn(cell).row
528
- if (-1 == rows.indexOf(row)) rows.push(row)
529
- })
530
- rows.sort((a, b) => {
531
- return a - b
532
- })
533
- rows.reverse()
534
- var heights = this.heights.slice()
535
- rows.forEach(row => {
536
- // rows에서 가로 방향으로 이동하면서 병합된 셀을 찾는다.
537
- let mergedCells = this.findMergedCellByX(row)
538
- // mergedCells.length가 0이면 일반적으로 행을 지운다.
539
- if (mergedCells.length === 0) {
540
- this.remove(this.getCellsByRow(row))
541
- }
542
- // mergedCells.length가 0이 아니면 병합된 셀을 고려하여 행을 지워야 한다.
543
- //
544
- else {
545
- // 삭제할 행에서 병합된 셀을 삭제할 때 해당 셀을 임시로 저장
546
- let temp = []
547
- // 부모 셀을 저장
548
- let superCells = []
549
- // 부모 셀의 인덱스 값을 저장
550
- let superCellIndexes: number[] = []
551
- mergedCells.forEach(cell => {
552
- let col, row, index
553
- col = this.getRowColumn(cell).column
554
- row = this.getRowColumn(cell).row
555
- index = row * this.columns + col + 1
556
- while (index) {
557
- --index
558
- let component = this.components[index] as TableCell
559
- // 슈퍼셀을 찾고 슈퍼셀의 위치에서 rowspan, colspan 거리만큼 이동하면서 cell이 있는지 검증해야함
560
- if (component.rowspan > 1 || component.colspan > 1) {
561
- let spColStart = this.getRowColumn(component).column
562
- let spColEnd = this.getRowColumn(component).column + component.colspan
563
- let spRowStart = this.getRowColumn(component).row
564
- let spRowEnd = this.getRowColumn(component).row + component.rowspan
565
- // 슈퍼셀 영역 안에 자식 셀이 있으면 superCells에 부모셀을 추가
566
- if (col >= spColStart && col < spColEnd && row >= spRowStart && row < spRowEnd) {
567
- if (-1 == superCellIndexes.indexOf(index)) {
568
- superCellIndexes.push(index)
569
- superCells.push(component)
570
- }
571
- }
572
- }
573
- }
574
- })
575
- superCellIndexes.forEach(index => {
576
- let superCellRow = Math.floor(index / this.columns)
577
- // 지우려는 행이 슈퍼셀을 포함한 경우이면서 슈퍼셀이 마지막 행의 셀이 아닌 경우
578
- // 그리고 슈퍼셀의 rowspan이 1보다 큰 경우
579
- let aCell: TableCell = this.components[index + this.columns] as TableCell
580
- let bCell: TableCell = this.components[index] as TableCell
581
- if (row === superCellRow && superCellRow !== this.rows - 1 && bCell.rowspan > 1) {
582
- aCell.rowspan = bCell.rowspan - 1
583
- aCell.colspan = bCell.colspan
584
- aCell.merged = false
585
- aCell.set('text', bCell.getState('text'))
586
- } else {
587
- bCell.rowspan -= 1
588
- }
589
- })
590
- this.remove(this.getCellsByRow(row))
591
- }
592
- })
593
-
594
- rows.forEach(row => heights.splice(row, 1))
595
-
596
- this.model.rows -= rows.length // 고의적으로, change 이벤트가 발생하지 않도록 set(..)을 사용하지 않음.
597
- this.set('heights', heights)
598
- }
599
-
600
- deleteColumns(cells: TableCell[]) {
601
- // 만약 선택한 셀이 병합된 셀이라면 삭제하지 않는다.
602
- if (cells[0].merged == true) return false
603
- // 먼저 cells 위치의 열을 구한다.
604
- let columns: number[] = []
605
- cells.forEach(cell => {
606
- let column = this.getRowColumn(cell).column
607
- if (-1 == columns.indexOf(column)) columns.push(column)
608
- })
609
- columns.sort((a, b) => {
610
- return a - b
611
- })
612
- columns.reverse()
613
-
614
- columns.forEach(column => {
615
- var widths = this.widths.slice()
616
- // columns에서 세로 방향으로 이동하면서 병합된 셀을 찾는다.
617
- let mergedCells = this.findMergedCellByY(column)
618
- // mergedCells.length가 0이면 일반적으로 열을 지운다.
619
- if (mergedCells.length === 0) {
620
- this.remove(this.getCellsByColumn(column))
621
- }
622
- // mergedCells.length가 0이 아니면 병합된 셀을 고려하여 열을 지워야 한다.
623
- else {
624
- // 삭제할 열에서 병합된 셀을 삭제할 때 해당 셀을 임시로 저장
625
- let temp = []
626
- // 부모 셀을 저장
627
- let superCells = []
628
- // 부모 셀의 인덱스를 저장
629
- let superCellIndexes: number[] = []
630
- mergedCells.forEach(cell => {
631
- let col, row, index
632
- col = this.getRowColumn(cell).column
633
- row = this.getRowColumn(cell).row
634
- index = row * this.columns + col + 1
635
- while (index) {
636
- --index
637
- let component = this.components[index] as TableCell
638
- // 슈퍼셀을 찾고 슈퍼셀의 위치에서 rowspan, colspan 거리만큼 이동하면서 cell이 있는지 검증해야함
639
- if (component.rowspan > 1 || component.colspan > 1) {
640
- let spColStart = this.getRowColumn(component).column
641
- let spColEnd = this.getRowColumn(component).column + component.colspan
642
- let spRowStart = this.getRowColumn(component).row
643
- let spRowEnd = this.getRowColumn(component).row + component.rowspan
644
- // 슈퍼셀 영역 안에 자식 셀이 있으면 superCells에 부모셀을 추가
645
- if (col >= spColStart && col < spColEnd && row >= spRowStart && row < spRowEnd) {
646
- if (-1 == superCellIndexes.indexOf(index)) {
647
- superCellIndexes.push(index)
648
- superCells.push(component)
649
- }
650
- }
651
- }
652
- }
653
- })
654
- superCellIndexes.forEach(index => {
655
- let superCellColumn = index % this.columns
656
-
657
- let aCell: TableCell = this.components[index + 1] as TableCell
658
- let bCell: TableCell = this.components[index] as TableCell
659
- // 지우려는 열이 슈퍼셀을 포함한 경우이면서 슈퍼셀이 마지막 열의 셀이 아닌 경우
660
- // 그리고 슈퍼셀의 colspan이 1보다 큰 경우
661
- if (column === superCellColumn && superCellColumn !== this.columns - 1 && bCell.colspan > 1) {
662
- aCell.rowspan = bCell.rowspan
663
- aCell.colspan = bCell.colspan - 1
664
- aCell.merged = false
665
- aCell.set('text', bCell.getState('text'))
666
- } else {
667
- bCell.colspan -= 1
668
- }
669
- })
670
- this.remove(this.getCellsByColumn(column))
671
- }
672
- widths.splice(column, 1)
673
- this.model.columns -= 1 // 고의적으로, change 이벤트가 발생하지 않도록 set(..)을 사용하지 않음.
674
- this.set('widths', widths)
675
- })
676
- }
677
-
678
- insertCellsAbove(cells: TableCell[]) {
679
- // 먼저 cells 위치의 행을 구한다.
680
- let rows: number[] = []
681
- cells.forEach(cell => {
682
- let row = this.getRowColumn(cell).row
683
- if (-1 == rows.indexOf(row)) rows.push(row)
684
- })
685
- rows.sort((a, b) => {
686
- return a - b
687
- })
688
- rows.reverse()
689
- // 행 2개 이상은 추가 안함. 임시로 막아놓음
690
- if (rows.length >= 2) return false
691
- let insertionRowPosition = rows[0]
692
- let newbieRowHeights: number[] = []
693
- let newbieCells: TableCell[] = []
694
- rows.forEach(row => {
695
- // rows에서 가로 방향으로 이동하면서 병합된 셀을 찾는다.
696
- let mergedCells = this.findMergedCellByX(row)
697
- // mergedCells.length가 0이면 일반적으로 행을 위에 추가한다.
698
- if (mergedCells.length === 0) {
699
- for (let i = 0; i < this.columns; i++)
700
- newbieCells.push(buildCopiedCell(this.components[row * this.columns + i].model, this.app))
701
- newbieRowHeights.push(this.heights[row])
702
-
703
- newbieCells.reverse().forEach(cell => {
704
- this.insertComponentAt(cell, insertionRowPosition * this.columns)
705
- })
706
-
707
- let heights = this.heights.slice()
708
- heights.splice(insertionRowPosition, 0, ...newbieRowHeights)
709
- this.set('heights', heights)
710
-
711
- this.model.rows += rows.length
712
-
713
- this.clearCache()
714
- }
715
- // mergedCells.length가 0이 아니면 병합된 셀을 고려하여 행을 추가해야 한다.
716
- else {
717
- // 선택한 행이 2개 이상 있고 그 중에 병합된 셀이 적어도 한 개라도 있으면
718
- // 병합된 셀이 포함된 행의 추가는 무시한다. 임시방편으로 막아놈
719
- if (rows.length > 1) return false
720
- // 추가할 행에서 병합된 셀을 추가할 때 해당 셀을 임시로 저장
721
- let temp = []
722
- // 부모 셀을 저장
723
- let superCells = []
724
- // 부모 셀의 인덱스 값을 저장
725
- let superCellIndexes: number[] = []
726
- mergedCells.forEach(cell => {
727
- let col, row, index
728
- col = this.getRowColumn(cell).column
729
- row = this.getRowColumn(cell).row
730
- index = row * this.columns + col + 1
731
- while (index) {
732
- --index
733
- let component = this.components[index] as TableCell
734
- // 슈퍼셀을 찾고 슈퍼셀의 위치에서 rowspan, colspan 거리만큼 이동하면서 cell이 있는지 검증해야함
735
- if (component.rowspan > 1 || component.colspan > 1) {
736
- let spColStart = this.getRowColumn(component).column
737
- let spColEnd = this.getRowColumn(component).column + component.colspan
738
- let spRowStart = this.getRowColumn(component).row
739
- let spRowEnd = this.getRowColumn(component).row + component.rowspan
740
- // 슈퍼셀 영역 안에 자식 셀이 있으면 superCells에 부모셀을 추가
741
- if (col >= spColStart && col < spColEnd && row >= spRowStart && row < spRowEnd) {
742
- if (-1 == superCellIndexes.indexOf(index)) {
743
- superCellIndexes.push(index)
744
- superCells.push(component)
745
- }
746
- }
747
- }
748
- }
749
- })
750
- superCellIndexes.forEach(index => {
751
- // 추가하려는 셀은 일반 셀인데 그 위치에 다른 병합된 셀이 있는 문제로 임시로 막아 놓음. 수정해야함
752
- if (superCellIndexes.length >= 2) return false
753
- let superCellRow = Math.floor(index / this.columns)
754
- let cell: TableCell = this.components[index] as TableCell
755
-
756
- let superCellObj = {
757
- rowspan: cell.rowspan,
758
- colspan: cell.colspan,
759
- text: cell.getState('text'),
760
- merged: cell.merged
761
- }
762
-
763
- // 추가하려는 행이 슈퍼셀을 포함한 경우
764
- if (superCellRow === row) {
765
- for (let i = 0; i < this.columns; i++) newbieCells.push(buildNewCell('table-cell', this.app))
766
- newbieRowHeights.push(this.heights[row])
767
-
768
- newbieCells.reverse().forEach(cell => {
769
- this.insertComponentAt(cell, insertionRowPosition * this.columns)
770
- })
771
- let addedCell = this.components[index + this.columns] as TableCell
772
-
773
- addedCell.rowspan = superCellObj.rowspan
774
- addedCell.colspan = superCellObj.colspan
775
- addedCell.set('text', superCellObj.text)
776
- addedCell.merged = superCellObj.merged
777
- } else {
778
- for (let i = 0; i < this.columns; i++)
779
- newbieCells.push(buildCopiedCell(this.components[row * this.columns + i].model, this.app))
780
- newbieRowHeights.push(this.heights[row])
781
-
782
- newbieCells.reverse().forEach(cell => {
783
- this.insertComponentAt(cell, insertionRowPosition * this.columns)
784
- })
785
- cell.rowspan += 1
786
- }
787
- let heights = this.heights.slice()
788
- heights.splice(insertionRowPosition, 0, ...newbieRowHeights)
789
- this.set('heights', heights)
790
-
791
- this.model.rows += rows.length
792
-
793
- this.clearCache()
794
- })
795
- }
796
- })
797
- }
798
-
799
- insertCellsBelow(cells: TableCell[]) {
800
- // 먼저 cells 위치의 행을 구한다.
801
- let rows: number[] = []
802
- cells.forEach(cell => {
803
- let row = this.getRowColumn(cell).row
804
- if (-1 == rows.indexOf(row)) rows.push(row)
805
- })
806
- rows.sort((a, b) => {
807
- return a - b
808
- })
809
- rows.reverse()
810
-
811
- // 행 2개 이상은 추가 안함. 임시로 막아놓음
812
- if (rows.length >= 2) return false
813
- let insertionRowPosition = rows[rows.length - 1] + 1
814
- let newbieRowHeights: number[] = []
815
- let newbieCells: TableCell[] = []
816
-
817
- rows.forEach(row => {
818
- // rows에서 가로 방향으로 이동하면서 병합된 셀을 찾는다.
819
- let mergedCells = this.findMergedCellByX(row)
820
- // mergedCells.length가 0이면 일반적으로 행을 아래에 추가한다.
821
- if (mergedCells.length === 0) {
822
- for (let i = 0; i < this.columns; i++)
823
- newbieCells.push(buildCopiedCell(this.components[row * this.columns + i].model, this.app))
824
- newbieRowHeights.push(this.heights[row])
825
-
826
- newbieCells.reverse().forEach(cell => {
827
- this.insertComponentAt(cell, insertionRowPosition * this.columns)
828
- })
829
-
830
- let heights = this.heights.slice()
831
- heights.splice(insertionRowPosition, 0, ...newbieRowHeights)
832
- this.set('heights', heights)
833
-
834
- this.model.rows += 1
835
-
836
- this.clearCache()
837
- }
838
- // mergedCells.length가 0이 아니면 병합된 셀을 고려하여 행을 추가해야 한다.
839
- else {
840
- // 추가할 행에서 병합된 셀을 추가할 때 해당 셀을 임시로 저장
841
- let temp = []
842
- // 부모 셀을 저장
843
- let superCells: TableCell[] = []
844
- // 부모 셀의 인덱스 값을 저장
845
- let superCellIndexes: number[] = []
846
- mergedCells.forEach(cell => {
847
- let col, row, index
848
- col = this.getRowColumn(cell).column
849
- row = this.getRowColumn(cell).row
850
- index = row * this.columns + col + 1
851
- while (index) {
852
- --index
853
- let component = this.components[index] as TableCell
854
- // 슈퍼셀을 찾고 슈퍼셀의 위치에서 rowspan, colspan 거리만큼 이동하면서 cell이 있는지 검증해야함
855
- if (component.rowspan > 1 || component.colspan > 1) {
856
- let spColStart = this.getRowColumn(component).column
857
- let spColEnd = this.getRowColumn(component).column + component.colspan
858
- let spRowStart = this.getRowColumn(component).row
859
- let spRowEnd = this.getRowColumn(component).row + component.rowspan
860
- // 슈퍼셀 영역 안에 자식 셀이 있으면 superCells에 부모셀을 추가
861
- if (col >= spColStart && col < spColEnd && row >= spRowStart && row < spRowEnd) {
862
- if (-1 == superCellIndexes.indexOf(index)) {
863
- superCellIndexes.push(index)
864
- superCells.push(component)
865
- }
866
- }
867
- }
868
- }
869
- })
870
- superCellIndexes.forEach(index => {
871
- // 추가하려는 셀은 일반 셀인데 그 위치에 다른 병합된 셀이 있는 문제로 임시로 막아 놓음. 수정해야함
872
- if (superCellIndexes.length >= 2) return false
873
- let superCellRow = Math.floor(index / this.columns)
874
- let cell = this.components[index] as TableCell
875
-
876
- let superCellObj = {
877
- rowspan: cell.rowspan,
878
- colspan: cell.colspan,
879
- text: cell.getState('text'),
880
- merged: cell.merged
881
- }
882
- // 추가하려는 행이 병합된 셀중 마지막 행인 경우
883
- if (superCellRow + superCellObj.rowspan - 1 === row) {
884
- for (let i = 0; i < this.columns; i++) newbieCells.push(buildNewCell('table-cell', this.app))
885
- newbieRowHeights.push(this.heights[row])
886
-
887
- newbieCells.reverse().forEach(cell => {
888
- this.insertComponentAt(cell, insertionRowPosition * this.columns)
889
- })
890
- } else if (superCellRow === row) {
891
- for (let i = 0; i < this.columns; i++)
892
- newbieCells.push(buildCopiedCell(this.components[row * this.columns + i].model, this.app))
893
- newbieRowHeights.push(this.heights[row])
894
-
895
- newbieCells.reverse().forEach(cell => {
896
- this.insertComponentAt(cell, insertionRowPosition * this.columns)
897
- })
898
-
899
- cell.rowspan += 1
900
-
901
- let newbieCell = this.components[index + this.columns] as TableCell
902
- // 슈퍼셀이 복사됐으므로 그 해당 셀을 병합된 셀로 설정한다.
903
- newbieCell.rowspan = 1
904
- newbieCell.colspan = 1
905
- newbieCell.merged = true
906
- newbieCell.set('text', '')
907
- } else {
908
- for (let i = 0; i < this.columns; i++)
909
- newbieCells.push(buildCopiedCell(this.components[row * this.columns + i].model, this.app))
910
- newbieRowHeights.push(this.heights[row])
911
-
912
- newbieCells.reverse().forEach(cell => {
913
- this.insertComponentAt(cell, insertionRowPosition * this.columns)
914
- })
915
- cell.rowspan += 1
916
- }
917
-
918
- let heights = this.heights.slice()
919
- heights.splice(insertionRowPosition, 0, ...newbieRowHeights)
920
- this.set('heights', heights)
921
-
922
- this.model.rows += 1
923
-
924
- this.clearCache()
925
- })
926
- }
927
- })
928
- }
929
-
930
- insertCellsLeft(cells: TableCell[]) {
931
- // 먼저 cells 위치의 열을 구한다.
932
- let columns: number[] = []
933
- cells.forEach(cell => {
934
- let column = this.getRowColumn(cell).column
935
- if (-1 == columns.indexOf(column)) columns.push(column)
936
- })
937
- columns.sort((a, b) => {
938
- return a - b
939
- })
940
- columns.reverse()
941
- // 열 2개 이상은 추가 안함. 임시로 막아놓음
942
- if (columns.length >= 2) return false
943
- let insertionColumnPosition = columns[0]
944
- let newbieColumnWidths: number[] = []
945
- let newbieCells: TableCell[] = []
946
- columns.forEach(column => {
947
- // columns에서 세로 방향으로 이동하면서 병합된 셀을 찾는다.
948
- let mergedCells = this.findMergedCellByY(column)
949
- // mergedCells.length가 0이면 일반적으로 열을 왼쪽에 추가한다.
950
- if (mergedCells.length === 0) {
951
- for (let i = 0; i < this.rows; i++)
952
- newbieCells.push(buildCopiedCell(this.components[column + this.columns * i].model, this.app))
953
- newbieColumnWidths.push(this.widths[column])
954
-
955
- let increasedColumns = this.columns
956
- let index = this.rows
957
- newbieCells.reverse().forEach(cell => {
958
- if (index == 0) {
959
- index = this.rows
960
- increasedColumns++
961
- }
962
-
963
- index--
964
- this.insertComponentAt(cell, insertionColumnPosition + index * increasedColumns)
965
- })
966
-
967
- let widths = this.widths.slice()
968
- this.model.columns += columns.length // 고의적으로, change 이벤트가 발생하지 않도록 set(..)을 사용하지 않음.
969
-
970
- widths.splice(insertionColumnPosition, 0, ...newbieColumnWidths)
971
-
972
- this.set('widths', widths)
973
- }
974
- // mergedCells.length가 0이 아니면 병합된 셀을 고려하여 열을 추가해야 한다.
975
- else {
976
- // 부모 셀을 저장
977
- let superCells = []
978
- // 부모 셀의 인덱스 값을 저장
979
- let superCellIndexes: number[] = []
980
- mergedCells.forEach(cell => {
981
- let col, row, index
982
- col = this.getRowColumn(cell).column
983
- row = this.getRowColumn(cell).row
984
- index = row * this.columns + col + 1
985
- while (index) {
986
- --index
987
- let component = this.components[index] as TableCell
988
- // 슈퍼셀을 찾고 슈퍼셀의 위치에서 rowspan, colspan 거리만큼 이동하면서 cell이 있는지 검증해야함
989
- if (component.rowspan > 1 || component.colspan > 1) {
990
- let spColStart = this.getRowColumn(component).column
991
- let spColEnd = this.getRowColumn(component).column + component.colspan
992
- let spRowStart = this.getRowColumn(component).row
993
- let spRowEnd = this.getRowColumn(component).row + component.rowspan
994
- // 슈퍼셀 영역 안에 자식 셀이 있으면 superCells에 부모셀을 추가
995
- if (col >= spColStart && col < spColEnd && row >= spRowStart && row < spRowEnd) {
996
- if (-1 == superCellIndexes.indexOf(index)) {
997
- superCellIndexes.push(index)
998
- superCells.push(component)
999
- }
1000
- }
1001
- }
1002
- }
1003
- })
1004
- superCellIndexes.forEach(index => {
1005
- // 추가하려는 셀은 일반 셀인데 그 위치에 다른 병합된 셀이 있는 문제로 임시로 막아 놓음. 수정해야함
1006
- if (superCellIndexes.length >= 2) return false
1007
- let superCellColumn = index % this.columns
1008
- let cell = this.components[index] as TableCell
1009
-
1010
- let superCellObj = {
1011
- rowspan: cell.rowspan,
1012
- colspan: cell.colspan,
1013
- text: cell.getState('text'),
1014
- merged: cell.merged
1015
- }
1016
- // 추가하려는 열이 슈퍼셀을 포함한 경우
1017
- if (superCellColumn === column) {
1018
- for (let i = 0; i < this.rows; i++) newbieCells.push(buildNewCell('table-cell', this.app))
1019
- newbieColumnWidths.push(this.widths[column])
1020
-
1021
- let increasedColumns = this.columns
1022
- let rowIndex = this.rows
1023
- newbieCells.reverse().forEach(cell => {
1024
- if (rowIndex == 0) {
1025
- rowIndex = this.rows
1026
- increasedColumns++
1027
- }
1028
-
1029
- rowIndex--
1030
- this.insertComponentAt(cell, insertionColumnPosition + rowIndex * increasedColumns)
1031
- })
1032
- } else {
1033
- cell.colspan += 1
1034
- for (let i = 0; i < this.rows; i++)
1035
- newbieCells.push(buildCopiedCell(this.components[column + this.columns * i].model, this.app))
1036
- newbieColumnWidths.push(this.widths[column])
1037
-
1038
- let increasedColumns = this.columns
1039
- let rowIndex = this.rows
1040
- newbieCells.reverse().forEach(cell => {
1041
- if (rowIndex == 0) {
1042
- rowIndex = this.rows
1043
- increasedColumns++
1044
- }
1045
-
1046
- rowIndex--
1047
- this.insertComponentAt(cell, insertionColumnPosition + rowIndex * increasedColumns)
1048
- })
1049
- }
1050
- let widths = this.widths.slice()
1051
- this.model.columns += columns.length // 고의적으로, change 이벤트가 발생하지 않도록 set(..)을 사용하지 않음.
1052
-
1053
- widths.splice(insertionColumnPosition, 0, ...newbieColumnWidths)
1054
-
1055
- this.set('widths', widths)
1056
- })
1057
- }
1058
- })
1059
- }
1060
-
1061
- insertCellsRight(cells: TableCell[]) {
1062
- // 먼저 cells 위치의 열을 구한다.
1063
- let columns: number[] = []
1064
- cells.forEach(cell => {
1065
- let column = this.getRowColumn(cell).column
1066
- if (-1 == columns.indexOf(column)) columns.push(column)
1067
- })
1068
- columns.sort((a, b) => {
1069
- return a - b
1070
- })
1071
- columns.reverse()
1072
- // 열 2개 이상은 추가 안함. 임시로 막아놓음
1073
- if (columns.length >= 2) return false
1074
- let insertionColumnPosition = columns[columns.length - 1] + 1
1075
- let newbieColumnWidths: number[] = []
1076
- let newbieCells: TableCell[] = []
1077
- columns.forEach(column => {
1078
- // columns에서 세로 방향으로 이동하면서 병합된 셀을 찾는다.
1079
- let mergedCells = this.findMergedCellByY(column)
1080
- // mergedCells.length가 0이면 일반적으로 열을 오른쪽에 추가한다.
1081
- if (mergedCells.length === 0) {
1082
- for (let i = 0; i < this.rows; i++)
1083
- newbieCells.push(buildCopiedCell(this.components[column + this.columns * i].model, this.app))
1084
- newbieColumnWidths.push(this.widths[column])
1085
-
1086
- let increasedColumns = this.columns
1087
- let index = this.rows
1088
- newbieCells.reverse().forEach(cell => {
1089
- if (index == 0) {
1090
- index = this.rows
1091
- increasedColumns++
1092
- }
1093
-
1094
- index--
1095
- this.insertComponentAt(cell, insertionColumnPosition + index * increasedColumns)
1096
- })
1097
-
1098
- let widths = this.widths.slice()
1099
- this.model.columns += columns.length // 고의적으로, change 이벤트가 발생하지 않도록 set(..)을 사용하지 않음.
1100
-
1101
- widths.splice(insertionColumnPosition, 0, ...newbieColumnWidths)
1102
-
1103
- this.set('widths', widths)
1104
- }
1105
- // mergedCells.length가 0이 아니면 병합된 셀을 고려하여 열을 추가해야 한다.
1106
- else {
1107
- // 부모 셀을 저장
1108
- let superCells = []
1109
- // 부모 셀의 인덱스 값을 저장
1110
- let superCellIndexes: number[] = []
1111
- mergedCells.forEach(cell => {
1112
- let col, row, index
1113
- col = this.getRowColumn(cell).column
1114
- row = this.getRowColumn(cell).row
1115
- index = row * this.columns + col + 1
1116
- while (index) {
1117
- --index
1118
- let component = this.components[index] as TableCell
1119
- // 슈퍼셀을 찾고 슈퍼셀의 위치에서 rowspan, colspan 거리만큼 이동하면서 cell이 있는지 검증해야함
1120
- if (component.rowspan > 1 || component.colspan > 1) {
1121
- let spColStart = this.getRowColumn(component).column
1122
- let spColEnd = this.getRowColumn(component).column + component.colspan
1123
- let spRowStart = this.getRowColumn(component).row
1124
- let spRowEnd = this.getRowColumn(component).row + component.rowspan
1125
- // 슈퍼셀 영역 안에 자식 셀이 있으면 superCells에 부모셀을 추가
1126
- if (col >= spColStart && col < spColEnd && row >= spRowStart && row < spRowEnd) {
1127
- if (-1 == superCellIndexes.indexOf(index)) {
1128
- superCellIndexes.push(index)
1129
- superCells.push(component)
1130
- }
1131
- }
1132
- }
1133
- }
1134
- })
1135
- superCellIndexes.forEach(index => {
1136
- // 추가하려는 셀은 일반 셀인데 그 위치에 다른 병합된 셀이 있는 문제로 임시로 막아 놓음. 수정해야함
1137
- if (superCellIndexes.length >= 2) return false
1138
- let superCellRow = Math.floor(index / this.columns)
1139
- let superCellColumn = index % this.columns
1140
- let cell = this.components[index] as TableCell
1141
-
1142
- let superCellObj = {
1143
- rowspan: cell.rowspan,
1144
- colspan: cell.colspan,
1145
- text: cell.getState('text'),
1146
- merged: cell.merged
1147
- }
1148
- // 추가하려는 열이 병합된 셀중 마지막 열인 경우
1149
- if (superCellColumn + superCellObj.colspan - 1 === column) {
1150
- for (let i = 0; i < this.rows; i++) newbieCells.push(buildNewCell('table-cell', this.app))
1151
- newbieColumnWidths.push(this.widths[column])
1152
-
1153
- let increasedColumns = this.columns
1154
- let rowIndex = this.rows
1155
- newbieCells.reverse().forEach(cell => {
1156
- if (rowIndex == 0) {
1157
- rowIndex = this.rows
1158
- increasedColumns++
1159
- }
1160
-
1161
- rowIndex--
1162
- this.insertComponentAt(cell, insertionColumnPosition + rowIndex * increasedColumns)
1163
- })
1164
- } else if (superCellColumn === column) {
1165
- cell.colspan += 1
1166
- for (let i = 0; i < this.rows; i++)
1167
- newbieCells.push(buildCopiedCell(this.components[column + this.columns * i].model, this.app))
1168
- newbieColumnWidths.push(this.widths[column])
1169
-
1170
- let increasedColumns = this.columns
1171
- let rowIndex = this.rows
1172
- newbieCells.reverse().forEach(cell => {
1173
- if (rowIndex == 0) {
1174
- rowIndex = this.rows
1175
- increasedColumns++
1176
- }
1177
-
1178
- rowIndex--
1179
- this.insertComponentAt(cell, insertionColumnPosition + rowIndex * increasedColumns)
1180
- })
1181
- // 슈퍼셀이 복사됐으므로 그 해당 셀을 병합된 셀로 설정한다.
1182
- let newbieCell = this.components[index + superCellRow + 1] as TableCell
1183
- newbieCell.rowspan = 1
1184
- newbieCell.colspan = 1
1185
- newbieCell.merged = true
1186
- newbieCell.set('text', '')
1187
- } else {
1188
- cell.colspan += 1
1189
- for (let i = 0; i < this.rows; i++)
1190
- newbieCells.push(buildCopiedCell(this.components[column + this.columns * i].model, this.app))
1191
- newbieColumnWidths.push(this.widths[column])
1192
-
1193
- let increasedColumns = this.columns
1194
- let rowIndex = this.rows
1195
- newbieCells.reverse().forEach(cell => {
1196
- if (rowIndex == 0) {
1197
- rowIndex = this.rows
1198
- increasedColumns++
1199
- }
1200
-
1201
- rowIndex--
1202
- this.insertComponentAt(cell, insertionColumnPosition + rowIndex * increasedColumns)
1203
- })
1204
- }
1205
- let widths = this.widths.slice()
1206
- this.model.columns += columns.length // 고의적으로, change 이벤트가 발생하지 않도록 set(..)을 사용하지 않음.
1207
-
1208
- widths.splice(insertionColumnPosition, 0, ...newbieColumnWidths)
1209
-
1210
- this.set('widths', widths)
1211
- })
1212
- }
1213
- })
1214
- }
1215
-
1216
- distributeHorizontal(cells: TableCell[]) {
1217
- var columns: number[] = []
1218
-
1219
- cells.forEach(cell => {
1220
- let rowcolumn = this.getRowColumn(cell)
1221
-
1222
- if (-1 == columns.indexOf(rowcolumn.column)) columns.push(rowcolumn.column)
1223
- })
1224
-
1225
- var sum = columns.reduce((sum, column) => {
1226
- return sum + this.widths[column]
1227
- }, 0)
1228
-
1229
- var newval = Math.round((sum / columns.length) * 100) / 100
1230
- var widths = this.widths.slice()
1231
- columns.forEach(column => {
1232
- widths[column] = newval
1233
- })
1234
-
1235
- this.set('widths', widths)
1236
- }
1237
-
1238
- distributeVertical(cells: TableCell[]) {
1239
- var rows: number[] = []
1240
-
1241
- cells.forEach((cell: TableCell) => {
1242
- let rowcolumn = this.getRowColumn(cell)
1243
-
1244
- if (-1 == rows.indexOf(rowcolumn.row)) rows.push(rowcolumn.row)
1245
- })
1246
-
1247
- var sum: number = rows.reduce((sum, row) => {
1248
- return sum + this.heights[row]
1249
- }, 0)
1250
-
1251
- var newval = Math.round((sum / rows.length) * 100) / 100
1252
- var heights = this.heights.slice()
1253
- rows.forEach(row => {
1254
- heights[row] = newval
1255
- })
1256
-
1257
- this.set('heights', heights)
1258
- }
1259
-
1260
- toObjectArrayValue(array: any[]) {
1261
- if (!array || array.length === 0) return null
1262
-
1263
- if (!array[0].hasOwnProperty('__field1')) {
1264
- return array
1265
- }
1266
-
1267
- let indexKeyMap: { [key: string]: any } = {}
1268
- let value = []
1269
-
1270
- for (let key in array[0]) {
1271
- indexKeyMap[key] = array[0][key]
1272
- }
1273
-
1274
- for (var i = 1; i < array.length; i++) {
1275
- let object: { [key: string]: any } = {}
1276
- let thisObject = array[i]
1277
- for (let key in indexKeyMap) {
1278
- let k = indexKeyMap[key]
1279
- let v = thisObject[key]
1280
- object[k] = v
1281
- }
1282
-
1283
- value.push(object)
1284
- }
1285
-
1286
- return value
1287
- }
1288
-
1289
- get columns() {
1290
- return Number(this.getState('columns'))
1291
- }
1292
-
1293
- get lefts() {
1294
- return this.components.filter((c, i) => {
1295
- return !(i % this.columns)
1296
- })
1297
- }
1298
-
1299
- get centers() {
1300
- return this.components.filter((c, i) => {
1301
- return i % this.columns && (i + 1) % this.columns
1302
- })
1303
- }
1304
-
1305
- get rights() {
1306
- return this.components.filter((c, i) => {
1307
- return !((i + 1) % this.columns)
1308
- })
1309
- }
1310
-
1311
- get tops() {
1312
- return this.components.slice(0, this.columns)
1313
- }
1314
-
1315
- get middles() {
1316
- return this.components.slice(this.columns, this.columns * (this.rows - 1))
1317
- }
1318
-
1319
- get bottoms() {
1320
- return this.components.slice(this.columns * (this.rows - 1))
1321
- }
1322
-
1323
- get widths_sum(): number {
1324
- var widths = this.widths
1325
- return widths
1326
- ? widths
1327
- .filter((width: number, i: number) => i < this.columns)
1328
- .reduce((sum: number, width: number) => sum + width, 0)
1329
- : this.columns
1330
- }
1331
-
1332
- get heights_sum(): number {
1333
- var heights = this.heights
1334
- return heights
1335
- ? heights
1336
- .filter((height: number, i: number) => i < this.rows)
1337
- .reduce((sum: number, height: number) => sum + height, 0)
1338
- : this.rows
1339
- }
1340
-
1341
- get nature(): ComponentNature {
1342
- return NATURE
1343
- }
1344
-
1345
- get controls(): Control[] {
1346
- var widths = this.widths
1347
- var heights = this.heights
1348
- var inside = this.textBounds
1349
-
1350
- var width_unit = inside!.width / this.widths_sum
1351
- var height_unit = inside!.height / this.heights_sum
1352
-
1353
- var x = inside!.left
1354
- var y = inside!.top
1355
-
1356
- var controls: Control[] = []
1357
-
1358
- widths.slice(0, this.columns - 1).forEach((width: number) => {
1359
- x += width * width_unit
1360
- controls.push({
1361
- x: x,
1362
- y: inside!.top,
1363
- handler: columnControlHandler
1364
- })
1365
- })
1366
-
1367
- heights.slice(0, this.rows - 1).forEach((height: number) => {
1368
- y += height * height_unit
1369
- controls.push({
1370
- x: inside!.left,
1371
- y: y,
1372
- handler: rowControlHandler
1373
- })
1374
- })
1375
-
1376
- return controls
1377
- }
1378
-
1379
- onchange(after: State, before: State) {
1380
- if ('rows' in after || 'columns' in after) {
1381
- let { rows, columns } = this
1382
-
1383
- this.buildCells(
1384
- rows,
1385
- columns,
1386
- 'rows' in before ? before.rows : rows,
1387
- 'columns' in before ? before.columns : columns
1388
- )
1389
- }
1390
-
1391
- if ('data' in after) {
1392
- this.setCellsData()
1393
- }
1394
- }
1395
-
1396
- get eventMap() {
1397
- return {
1398
- '(self)': {
1399
- '(descendant)': {
1400
- change: this.oncellchanged
1401
- }
1402
- }
1403
- }
1404
- }
1405
-
1406
- oncellchanged(after: State, before: State) {
1407
- if ('dataKey' in after || 'dataIndex' in after) {
1408
- this.setCellsData()
1409
- }
1410
- }
1411
- }
1412
-
1413
- ;['rows', 'columns', 'widths', 'heights', 'widths_sum', 'heights_sum', 'controls'].forEach(getter =>
1414
- Component.memoize(Table.prototype, getter, false)
1415
- )
1416
-
1417
- Component.register('table', Table)