updateCell.js
12.7 KB
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
import pivotTable from './pivotTable';
import luckysheetFreezen from './freezen';
import menuButton from './menuButton';
import conditionformat from './conditionformat';
import alternateformat from './alternateformat';
import cellDatePickerCtrl from './cellDatePickerCtrl';
import dataVerificationCtrl from './dataVerificationCtrl';
import {checkProtectionLocked,checkProtectionCellHidden} from './protection';
import { chatatABC } from '../utils/util';
import { isEditMode } from '../global/validate';
import { getcellvalue,getInlineStringStyle } from '../global/getdata';
import { valueShowEs } from '../global/format';
import formula from '../global/formula';
import { luckysheetRangeLast } from '../global/cursorPos';
import cleargridelement from '../global/cleargridelement';
import {isInlineStringCell} from './inlineString';
import Store from '../store';
import server from './server';
import method from '../global/method';
export function luckysheetupdateCell(row_index1, col_index1, d, cover, isnotfocus) {
if(!checkProtectionLocked(row_index1, col_index1, Store.currentSheetIndex)){
$("#luckysheet-functionbox-cell").blur();
return;
}
if(isEditMode() || Store.allowEdit===false){//此模式下禁用单元格编辑
return;
}
// 钩子函数
if(!method.createHookFunction('cellEditBefore',Store.luckysheet_select_save)){return;}
// 编辑单元格时发送指令到后台,通知其他单元格更新为“正在输入”状态
server.saveParam("mv", Store.currentSheetIndex, {op:"enterEdit",range:Store.luckysheet_select_save});
//数据验证
if(dataVerificationCtrl.dataVerification != null && dataVerificationCtrl.dataVerification[row_index1 + '_' + col_index1] != null){
let dataVerificationItem = dataVerificationCtrl.dataVerification[row_index1 + '_' + col_index1];
if(dataVerificationItem.type == 'dropdown'){
dataVerificationCtrl.dropdownListShow();
}
else if(dataVerificationItem.type == 'checkbox'){
return;
}
}
let size = getColumnAndRowSize(row_index1, col_index1, d);
let row = size.row,
row_pre = size.row_pre,
col = size.col,
col_pre = size.col_pre,
row_index = size.row_index,
col_index = size.col_index;
if($("#luckysheet-dropCell-icon").is(":visible")){
$("#luckysheet-dropCell-icon").remove();
}
let winH = $(window).height(), winW = $(window).width();
let container_offset = $("#" + Store.container).offset();
let scrollLeft = $("#luckysheet-cell-main").scrollLeft();
let scrollTop = $("#luckysheet-cell-main").scrollTop();
if (pivotTable.isPivotRange(row_index, col_index)) {
return;
}
let left = col_pre + container_offset.left + Store.rowHeaderWidth - scrollLeft - 2;
if(luckysheetFreezen.freezenverticaldata != null && col_index1 <= luckysheetFreezen.freezenverticaldata[1]){
left = col_pre + container_offset.left + Store.rowHeaderWidth - 2;
}
let top = row_pre + container_offset.top + Store.infobarHeight + Store.toolbarHeight + Store.calculatebarHeight + Store.columnHeaderHeight - scrollTop - 2;
if(luckysheetFreezen.freezenhorizontaldata != null && row_index1 <= luckysheetFreezen.freezenhorizontaldata[1]){
top = row_pre + container_offset.top + Store.infobarHeight + Store.toolbarHeight + Store.calculatebarHeight + Store.columnHeaderHeight - 2;
}
let input_postition = {
"min-width": col - col_pre+ 1- 8,
"min-height": row - row_pre + 1- 4,
"max-width": winW + scrollLeft - col_pre - 20 - Store.rowHeaderWidth,
"max-height": winH + scrollTop - row_pre - 20 - 15 - Store.toolbarHeight - Store.infobarHeight - Store.calculatebarHeight - Store.sheetBarHeight - Store.statisticBarHeight,
"left": left,
"top": top,
}
let inputContentScale = {
"transform":"scale("+ Store.zoomRatio +")",
"transform-origin":"left top",
"width":(100 / Store.zoomRatio) + "%",
"height":(100 / Store.zoomRatio) + "%",
}
Store.luckysheetCellUpdate = [row_index, col_index];
if (!isnotfocus) {
$("#luckysheet-rich-text-editor").focus().select();
}
$("#luckysheet-input-box").removeAttr("style").css({
"background-color": "rgb(255, 255, 255)",
"padding": "0px 2px",
"font-size": "13px",
"right": "auto",
"overflow-y": "auto",
"box-sizing": "initial",
"display":"flex",
});
if(luckysheetFreezen.freezenverticaldata != null || luckysheetFreezen.freezenhorizontaldata != null){
$("#luckysheet-input-box").css("z-index", 10002);
}
$("#luckysheet-input-box-index").html(chatatABC(col_index) + (row_index + 1)).hide();
$("#luckysheet-wa-functionbox-cancel, #luckysheet-wa-functionbox-confirm").addClass("luckysheet-wa-calculate-active");
let value = "", isCenter=false;
if (d[row_index] != null && d[row_index][col_index] != null) {
let cell = d[row_index][col_index];
let htValue = cell["ht"];
let leftOrigin = "left", topOrigin = "top";
if(htValue == "0"){//0 center, 1 left, 2 right
input_postition = {
"min-width": col - col_pre + 1- 8,
"min-height": row - row_pre + 1- 4,
// "transform":"scale("+ Store.zoomRatio +")",
// "transform-origin":"center top",
"max-width": winW*2/3,
"max-height": winH + scrollTop - row_pre - 20 - 15 - Store.toolbarHeight - Store.infobarHeight - Store.calculatebarHeight - Store.sheetBarHeight - Store.statisticBarHeight,
"left": col_pre + container_offset.left + Store.rowHeaderWidth - scrollLeft - 2,
"top": row_pre + container_offset.top + Store.infobarHeight + Store.toolbarHeight + Store.calculatebarHeight + Store.columnHeaderHeight - scrollTop - 2,
}
if(Store.zoomRatio<1){
leftOrigin = "center";
}
isCenter = true;
}
else if(htValue == "2"){
input_postition = {
"min-width": col - col_pre+ 1- 8,
"min-height": row - row_pre + 1- 4,
// "transform":"scale("+ Store.zoomRatio +")",
// "transform-origin":"right top",
"max-width": col + container_offset.left - scrollLeft - 8,
"max-height": winH + scrollTop - row_pre - 20 - 15 - Store.toolbarHeight - Store.infobarHeight - Store.calculatebarHeight - Store.sheetBarHeight - Store.statisticBarHeight,
"right": winW - (container_offset.left + (Store.rowHeaderWidth-1) - scrollLeft) - col,
"top": row_pre + container_offset.top + Store.infobarHeight + Store.toolbarHeight + Store.calculatebarHeight + Store.columnHeaderHeight - scrollTop - 2,
}
if(Store.zoomRatio<1){
leftOrigin = "right";
}
}
if(cell["vt"]=="0"){
topOrigin = "center";
}
else if(cell["vt"]=="2"){
topOrigin = "bottom";
}
inputContentScale["transform-origin"] = leftOrigin +" " + topOrigin;
if (!cover) {
if(isInlineStringCell(cell)){
value = getInlineStringStyle(row_index, col_index, d);
}
else if(cell.f!=null){
value = getcellvalue(row_index, col_index, d, "f");
}
else{
value = valueShowEs(row_index, col_index, d);
if(cell.qp=="1"){
value = value ? ("" + value) : value;
}
}
}
let style = menuButton.getStyleByCell(d, row_index, col_index);
style = $("#luckysheet-input-box").get(0).style.cssText + style;
$("#luckysheet-input-box").get(0).style.cssText = style;
if($("#luckysheet-input-box").get(0).style.backgroundColor == "rgba(0, 0, 0, 0)"){
$("#luckysheet-input-box").get(0).style.background = "rgb(255,255,255)";
}
}
else{
//交替颜色
let af_compute = alternateformat.getComputeMap();
var checksAF = alternateformat.checksAF(row_index, col_index, af_compute);
//条件格式
var cf_compute = conditionformat.getComputeMap();
var checksCF = conditionformat.checksCF(row_index, col_index, cf_compute);
if(checksCF != null && checksCF["cellColor"] != null){
$("#luckysheet-input-box").get(0).style.background = checksCF["cellColor"];
}
else if(checksAF != null){
$("#luckysheet-input-box").get(0).style.background = checksAF[1];
}
}
if(input_postition["min-height"] > input_postition["max-height"]){
input_postition["min-height"] = input_postition["max-height"];
}
if(input_postition["min-width"] > input_postition["max-width"]){
input_postition["min-width"] = input_postition["max-width"];
}
// if((value == null || value.toString() == "") && !cover){
// value = "<br/>";
// }
value = formula.xssDeal(value);
if(!checkProtectionCellHidden(row_index, col_index, Store.currentSheetIndex) && value.length>0 && value.substr(0, 63)=='<span dir="auto" class="luckysheet-formula-text-color">=</span>'){
$("#luckysheet-rich-text-editor").html("");
}
else{
value = formula.ltGtSignDeal(value);
$("#luckysheet-rich-text-editor").html(value);
if (!isnotfocus) {
luckysheetRangeLast($("#luckysheet-rich-text-editor")[0]);
}
}
if(isCenter){
let width = $("#luckysheet-input-box").width();
if(width> input_postition["max-width"]){
width = input_postition["max-width"];
}
if(width< input_postition["min-width"]){
width = input_postition["min-width"];
}
let newLeft = input_postition["left"] - width/2 + (col - col_pre)/2;
if(newLeft<2){
newLeft = 2;
}
input_postition["left"] = newLeft-2;
}
$("#luckysheet-input-box").css(input_postition);
$("#luckysheet-rich-text-editor").css(inputContentScale);
//日期
if(d[row_index1][col_index1] && d[row_index1][col_index1].ct && d[row_index1][col_index1].ct.t == 'd'){
cellDatePickerCtrl.cellFocus(row_index1, col_index1, d[row_index1][col_index1]);
}
formula.rangetosheet = Store.currentSheetIndex;
formula.createRangeHightlight();
formula.rangeResizeTo = $("#luckysheet-rich-text-editor");
cleargridelement();
}
export function setCenterInputPosition(row_index, col_index, d){
if(row_index==null ||col_index==null){
return;
}
let cell = d[row_index][col_index];
if(cell==null){
return;
}
let htValue = cell["ht"];
if(cell!=null && htValue != "0"){//0 center, 1 left, 2 right
return;
}
let size = getColumnAndRowSize(row_index, col_index, d);
let row = size.row, row_pre = size.row_pre, col = size.col, col_pre = size.col_pre;
let winH = $(window).height(), winW = $(window).width();
let container_offset = $("#" + Store.container).offset();
let scrollLeft = $("#luckysheet-cell-main").scrollLeft();
let scrollTop = $("#luckysheet-cell-main").scrollTop();
let input_postition = {
"min-width": col - col_pre + 1 - 8,
"max-width": winW*2/3,
"left": col_pre + container_offset.left + Store.rowHeaderWidth - scrollLeft - 2,
}
let width = $("#luckysheet-input-box").width();
if(width> input_postition["max-width"]){
width = input_postition["max-width"];
}
if(width< input_postition["min-width"]){
width = input_postition["min-width"];
}
let newLeft = input_postition["left"] - width/2 + (col - col_pre)/2;
if(newLeft<2){
newLeft = 2;
}
input_postition["left"] = newLeft-2;
$("#luckysheet-input-box").css(input_postition);
}
export function getColumnAndRowSize(row_index, col_index, d){
let row = Store.visibledatarow[row_index],
row_pre = row_index - 1 == -1 ? 0 : Store.visibledatarow[row_index - 1];
let col = Store.visibledatacolumn[col_index],
col_pre = col_index - 1 == -1 ? 0 : Store.visibledatacolumn[col_index - 1];
if(d == null){
d = Store.flowdata;
}
let margeset = menuButton.mergeborer(d, row_index, col_index);
if(!!margeset){
row = margeset.row[1];
row_pre = margeset.row[0];
row_index = margeset.row[2];
col = margeset.column[1];
col_pre = margeset.column[0];
col_index = margeset.column[2];
}
return {
row: row,
row_pre: row_pre,
row_index: row_index,
col: col,
col_pre: col_pre,
col_index: col_index
}
}