1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 |
|
5 | Object.defineProperty(exports, "__esModule", {
|
6 | value: true
|
7 | });
|
8 | exports.createTable = createTable;
|
9 | exports.updateCellContent = updateCellContent;
|
10 | exports.insertRow = insertRow;
|
11 | exports.deleteRow = deleteRow;
|
12 | exports.insertColumn = insertColumn;
|
13 | exports.deleteColumn = deleteColumn;
|
14 |
|
15 | var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
16 |
|
17 | var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
18 |
|
19 | var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread"));
|
20 |
|
21 | var _lodash = require("lodash");
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 | function createTable(_ref) {
|
36 | var rowCount = _ref.rowCount,
|
37 | columnCount = _ref.columnCount;
|
38 | return {
|
39 | body: (0, _lodash.times)(rowCount, function () {
|
40 | return {
|
41 | cells: (0, _lodash.times)(columnCount, function () {
|
42 | return {
|
43 | content: '',
|
44 | tag: 'td'
|
45 | };
|
46 | })
|
47 | };
|
48 | })
|
49 | };
|
50 | }
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 | function updateCellContent(state, _ref2) {
|
65 | var section = _ref2.section,
|
66 | rowIndex = _ref2.rowIndex,
|
67 | columnIndex = _ref2.columnIndex,
|
68 | content = _ref2.content;
|
69 | return (0, _defineProperty2.default)({}, section, state[section].map(function (row, currentRowIndex) {
|
70 | if (currentRowIndex !== rowIndex) {
|
71 | return row;
|
72 | }
|
73 |
|
74 | return {
|
75 | cells: row.cells.map(function (cell, currentColumnIndex) {
|
76 | if (currentColumnIndex !== columnIndex) {
|
77 | return cell;
|
78 | }
|
79 |
|
80 | return (0, _objectSpread2.default)({}, cell, {
|
81 | content: content
|
82 | });
|
83 | })
|
84 | };
|
85 | }));
|
86 | }
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 | function insertRow(state, _ref4) {
|
99 | var section = _ref4.section,
|
100 | rowIndex = _ref4.rowIndex;
|
101 | var cellCount = state[section][0].cells.length;
|
102 | return (0, _defineProperty2.default)({}, section, [].concat((0, _toConsumableArray2.default)(state[section].slice(0, rowIndex)), [{
|
103 | cells: (0, _lodash.times)(cellCount, function () {
|
104 | return {
|
105 | content: '',
|
106 | tag: 'td'
|
107 | };
|
108 | })
|
109 | }], (0, _toConsumableArray2.default)(state[section].slice(rowIndex))));
|
110 | }
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 | function deleteRow(state, _ref6) {
|
123 | var section = _ref6.section,
|
124 | rowIndex = _ref6.rowIndex;
|
125 | return (0, _defineProperty2.default)({}, section, state[section].filter(function (row, index) {
|
126 | return index !== rowIndex;
|
127 | }));
|
128 | }
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 | function insertColumn(state, _ref8) {
|
141 | var section = _ref8.section,
|
142 | columnIndex = _ref8.columnIndex;
|
143 | return (0, _defineProperty2.default)({}, section, state[section].map(function (row) {
|
144 | return {
|
145 | cells: [].concat((0, _toConsumableArray2.default)(row.cells.slice(0, columnIndex)), [{
|
146 | content: '',
|
147 | tag: 'td'
|
148 | }], (0, _toConsumableArray2.default)(row.cells.slice(columnIndex)))
|
149 | };
|
150 | }));
|
151 | }
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 | function deleteColumn(state, _ref10) {
|
164 | var section = _ref10.section,
|
165 | columnIndex = _ref10.columnIndex;
|
166 | return (0, _defineProperty2.default)({}, section, state[section].map(function (row) {
|
167 | return {
|
168 | cells: row.cells.filter(function (cell, index) {
|
169 | return index !== columnIndex;
|
170 | })
|
171 | };
|
172 | }).filter(function (row) {
|
173 | return row.cells.length;
|
174 | }));
|
175 | }
|
176 |
|
\ | No newline at end of file |