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 | 1×
1×
1×
1×
1151×
1151×
1×
1572×
1×
1456×
1×
401×
401×
397×
397×
397×
1×
1×
1×
397×
397×
397×
204×
397×
397×
397×
161×
161×
134×
27×
27×
27×
16×
27×
27×
20×
236×
236×
236×
236×
236×
236×
223×
223×
26×
236×
39×
197×
197×
196×
196×
236×
236×
206×
4×
202×
202×
202×
206×
236×
236×
26×
26×
26×
26×
210×
236×
210×
210×
210×
210×
236×
43×
43×
43×
236×
236×
1×
263×
263×
263×
212×
212×
181×
181×
181×
181×
51×
263×
1×
1151×
1151×
1151×
1×
1151×
27×
27×
27×
1×
1151×
1151×
1×
164194×
1×
1×
| define(["require", "exports", "../../workbook/common/event", "../common/index", "../../workbook/index"], function (require, exports, event_1, index_1, index_2) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var NumberFormat = (function () {
function NumberFormat(parent) {
this.parent = parent;
this.addEventListener();
}
NumberFormat.prototype.refreshCellElement = function (args) {
this.parent.refreshNode(args.td, args);
};
NumberFormat.prototype.getTextSpace = function (args) {
args.width = index_1.getTextWidth(args.char, args.cell.style, this.parent.cellStyle);
};
NumberFormat.prototype.rowFillHandler = function (args) {
var cellElem = args.cellEle;
if (cellElem) {
var repeatCharSpan = void 0;
var endCol = args.colIdx;
if (args.cell.colSpan > 1) {
var mergeArgs = { range: [args.rowIdx, args.colIdx, args.rowIdx, args.colIdx] };
this.parent.notify(index_2.activeCellMergedRange, mergeArgs);
endCol = mergeArgs.range[3];
}
var cellWidth = index_1.getExcludedColumnWidth(this.parent.getActiveSheet(), args.rowIdx, args.colIdx, endCol);
var iconSetSpan = args.iconSetSpan || cellElem.querySelector('.e-iconsetspan');
if (iconSetSpan) {
cellWidth -= iconSetSpan.getBoundingClientRect().width;
}
var filterButton = cellElem.querySelector('.e-filter-btn');
Iif (filterButton) {
cellWidth -= filterButton.getBoundingClientRect().width;
}
if (args.updateFillSize) {
repeatCharSpan = cellElem.querySelector('.e-fill');
if (!repeatCharSpan || !repeatCharSpan.textContent) {
return;
}
args.repeatChar = repeatCharSpan.textContent[0];
var beforeSpan = cellElem.querySelector('.e-fill-before');
if (beforeSpan) {
cellWidth -= index_1.getTextWidth(beforeSpan.textContent, args.cell.style, this.parent.cellStyle);
}
var textSpan = cellElem.querySelector('.e-fill-sec');
if (textSpan) {
cellWidth -= index_1.getTextWidth(textSpan.textContent, args.cell.style, this.parent.cellStyle);
}
}
else {
var noteIndicator = cellElem.querySelector('.e-addNoteIndicator');
var container = cellElem.querySelector('.e-hyperlink');
var isCellElem = void 0;
var cfCurSpan = void 0;
var isDataBar = void 0;
if (!container) {
container = cellElem.querySelector('.e-databar-value');
if (container) {
isDataBar = true;
}
}
if (container) {
cfCurSpan = cellElem.querySelector('.e-cf-currency');
}
else {
container = cellElem.querySelector('.e-wrap-content');
if (!container) {
container = cellElem;
isCellElem = !!filterButton;
}
}
container.innerText = '';
if (args.beforeFillText) {
if (cfCurSpan) {
cfCurSpan.innerText = args.beforeFillText;
}
else {
var beforeSpan = this.parent.createElement('span', { className: 'e-fill-before', styles: "float: " + (this.parent.enableRtl ? 'right' : 'left') });
beforeSpan.innerText = args.beforeFillText;
container.appendChild(beforeSpan);
}
cellWidth -= index_1.getTextWidth(args.beforeFillText, args.cell.style, this.parent.cellStyle);
}
repeatCharSpan = this.parent.createElement('span', { className: 'e-fill' });
if (isDataBar) {
var dataBarEle = cellElem.querySelector('.e-cf-databar');
var repeatSpan = dataBarEle.querySelector('.e-fill');
Iif (repeatSpan) {
repeatSpan.remove();
}
dataBarEle.insertBefore(repeatCharSpan, container);
}
else {
container.appendChild(repeatCharSpan);
}
if (args.afterFillText) {
var textSpan = this.parent.createElement('span', { className: 'e-fill-sec' });
textSpan.innerText = args.afterFillText;
container.appendChild(textSpan);
cellWidth -= index_1.getTextWidth(args.afterFillText, args.cell.style, this.parent.cellStyle);
}
if (iconSetSpan) {
var wrapCnt = cellElem.querySelector('.e-wrap-content');
Iif (wrapCnt) {
wrapCnt.insertBefore(iconSetSpan, wrapCnt.childNodes[0]);
}
else {
cellElem.insertBefore(iconSetSpan, cellElem.childNodes[0]);
}
}
Iif (isCellElem) {
cellElem.insertBefore(filterButton, cellElem.firstChild);
}
if (noteIndicator) {
container.appendChild(noteIndicator);
}
}
var repeatCharWidth = index_1.getTextWidth(args.repeatChar, args.cell.style, this.parent.cellStyle);
var repeatCount = parseInt((cellWidth / repeatCharWidth).toString(), 10);
if (repeatCount > 0) {
args.formattedText = args.repeatChar.repeat(repeatCount);
if (repeatCount > 1 && !args.formattedText.startsWith('#')) {
var totalRepeatWidth = index_1.getTextWidth(args.formattedText, args.cell.style, this.parent.cellStyle);
var leftoverSpace = cellWidth - totalRepeatWidth;
var letterSpacing = leftoverSpace / (repeatCount - 1);
repeatCharSpan.style.letterSpacing = letterSpacing + "px";
}
}
else {
args.formattedText = '';
}
repeatCharSpan.textContent = args.formattedText;
}
};
NumberFormat.prototype.addEventListener = function () {
this.parent.on(event_1.refreshCellElement, this.refreshCellElement, this);
this.parent.on(event_1.rowFillHandler, this.rowFillHandler, this);
this.parent.on(event_1.getTextSpace, this.getTextSpace, this);
};
NumberFormat.prototype.removeEventListener = function () {
if (!this.parent.isDestroyed) {
this.parent.off(event_1.refreshCellElement, this.refreshCellElement);
this.parent.off(event_1.rowFillHandler, this.rowFillHandler);
this.parent.off(event_1.getTextSpace, this.getTextSpace);
}
};
NumberFormat.prototype.destroy = function () {
this.removeEventListener();
this.parent = null;
};
NumberFormat.prototype.getModuleName = function () {
return 'numberFormat';
};
return NumberFormat;
}());
exports.NumberFormat = NumberFormat;
});
|