@fileverse-dev/fortune-core 1.1.62 → 1.1.63
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/es/events/paste.js +25 -267
- package/es/paste-helpers/calculate-range-cell-size.d.ts +9 -0
- package/es/paste-helpers/calculate-range-cell-size.js +146 -0
- package/es/paste-table-helpers.d.ts +3 -0
- package/es/paste-table-helpers.js +267 -0
- package/lib/events/paste.js +24 -266
- package/lib/paste-helpers/calculate-range-cell-size.d.ts +9 -0
- package/lib/paste-helpers/calculate-range-cell-size.js +153 -0
- package/lib/paste-table-helpers.d.ts +3 -0
- package/lib/paste-table-helpers.js +275 -0
- package/package.json +1 -1
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
import _ from "lodash";
|
|
3
|
+
import { locale } from "./locale";
|
|
4
|
+
import { getQKBorder, saveHyperlink } from "./modules";
|
|
5
|
+
import { genarate } from "./modules/format";
|
|
6
|
+
import { getSheetIndex } from "./utils";
|
|
7
|
+
export var DEFAULT_FONT_SIZE = 12;
|
|
8
|
+
var parseStylesheetPairs = function parseStylesheetPairs(styleInner) {
|
|
9
|
+
var patternReg = /{([^}]*)}/g;
|
|
10
|
+
var patternStyle = styleInner.match(patternReg);
|
|
11
|
+
var nameReg = /^[^\t].*/gm;
|
|
12
|
+
var patternName = _.initial(styleInner.match(nameReg));
|
|
13
|
+
if (_typeof(patternStyle) !== _typeof(patternName) || patternName.length !== (patternStyle === null || patternStyle === void 0 ? void 0 : patternStyle.length)) return {};
|
|
14
|
+
return _.fromPairs(_.zip(patternName, patternStyle));
|
|
15
|
+
};
|
|
16
|
+
var parseInlineStyleBlock = function parseInlineStyleBlock(block) {
|
|
17
|
+
if (!block) return {};
|
|
18
|
+
var trimmed = block.substring(1, block.length - 1);
|
|
19
|
+
var entries = trimmed.split("\n\t").map(function (s) {
|
|
20
|
+
return s.trim();
|
|
21
|
+
}).filter(Boolean);
|
|
22
|
+
var out = {};
|
|
23
|
+
entries.forEach(function (entry) {
|
|
24
|
+
var _a = entry.split(":"),
|
|
25
|
+
k = _a[0],
|
|
26
|
+
v = _a[1];
|
|
27
|
+
if (k && v) out[k] = v.replace(";", "").trim();
|
|
28
|
+
});
|
|
29
|
+
return out;
|
|
30
|
+
};
|
|
31
|
+
var mapFontFamilyToIndex = function mapFontFamilyToIndex(ff, ctx) {
|
|
32
|
+
var families = ff.split(",");
|
|
33
|
+
var locale_fontjson = locale(ctx).fontjson;
|
|
34
|
+
var found = families.map(function (raw) {
|
|
35
|
+
return raw.trim().toLowerCase();
|
|
36
|
+
}).find(function (key) {
|
|
37
|
+
var mapped = locale_fontjson[key];
|
|
38
|
+
return mapped != null;
|
|
39
|
+
});
|
|
40
|
+
if (found != null) return locale_fontjson[found];
|
|
41
|
+
return 0;
|
|
42
|
+
};
|
|
43
|
+
function applyBordersAndMerges(td, startRow, startCol, absRow, absCol, rowSpanCount, colSpanCount, borderInfo, data) {
|
|
44
|
+
var topBorder = td.style.borderTop && !td.style.borderTop.startsWith("0px") ? getQKBorder(td.style.borderTopWidth, td.style.borderTopStyle, td.style.borderTopColor) : null;
|
|
45
|
+
var bottomBorder = td.style.borderBottom && !td.style.borderBottom.startsWith("0px") ? getQKBorder(td.style.borderBottomWidth, td.style.borderBottomStyle, td.style.borderBottomColor) : null;
|
|
46
|
+
var leftBorder = td.style.borderLeft && !td.style.borderLeft.startsWith("0px") ? getQKBorder(td.style.borderLeftWidth, td.style.borderLeftStyle, td.style.borderLeftColor) : null;
|
|
47
|
+
var rightBorder = td.style.borderRight && !td.style.borderRight.startsWith("0px") ? getQKBorder(td.style.borderRightWidth, td.style.borderRightStyle, td.style.borderRightColor) : null;
|
|
48
|
+
for (var rowOffset = 0; rowOffset < rowSpanCount; rowOffset++) {
|
|
49
|
+
var relativeRow = startRow + rowOffset;
|
|
50
|
+
for (var colOffset = 0; colOffset < colSpanCount; colOffset++) {
|
|
51
|
+
var relativeCol = startCol + colOffset;
|
|
52
|
+
if (!(rowOffset === 0 && colOffset === 0)) {
|
|
53
|
+
data[relativeRow][relativeCol] = {
|
|
54
|
+
mc: {
|
|
55
|
+
r: absRow,
|
|
56
|
+
c: absCol
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
var isTopEdge = rowOffset === 0;
|
|
61
|
+
var isBottomEdge = rowOffset === rowSpanCount - 1;
|
|
62
|
+
var isLeftEdge = colOffset === 0;
|
|
63
|
+
var isRightEdge = colOffset === colSpanCount - 1;
|
|
64
|
+
if (!(isTopEdge || isBottomEdge || isLeftEdge || isRightEdge)) continue;
|
|
65
|
+
var borderKey = "".concat(relativeRow, "_").concat(relativeCol);
|
|
66
|
+
borderInfo[borderKey] || (borderInfo[borderKey] = {});
|
|
67
|
+
if (isTopEdge && topBorder) {
|
|
68
|
+
borderInfo[borderKey].t = {
|
|
69
|
+
style: topBorder[0],
|
|
70
|
+
color: topBorder[1]
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
if (isBottomEdge && bottomBorder) {
|
|
74
|
+
borderInfo[borderKey].b = {
|
|
75
|
+
style: bottomBorder[0],
|
|
76
|
+
color: bottomBorder[1]
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
if (isLeftEdge && leftBorder) {
|
|
80
|
+
borderInfo[borderKey].l = {
|
|
81
|
+
style: leftBorder[0],
|
|
82
|
+
color: leftBorder[1]
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
if (isRightEdge && rightBorder) {
|
|
86
|
+
borderInfo[borderKey].r = {
|
|
87
|
+
style: rightBorder[0],
|
|
88
|
+
color: rightBorder[1]
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
var HEX_REGEX = /^0x?[a-fA-F0-9]+$/;
|
|
95
|
+
var detectHyperlink = function detectHyperlink(td) {
|
|
96
|
+
var _a, _b;
|
|
97
|
+
var anchor = td.querySelector("a[href]");
|
|
98
|
+
var urlRegex = /^(https?:\/\/[^\s]+)$/i;
|
|
99
|
+
if (anchor) {
|
|
100
|
+
var href = ((_a = anchor.getAttribute("href")) === null || _a === void 0 ? void 0 : _a.trim()) || "";
|
|
101
|
+
var display = ((_b = anchor.textContent) === null || _b === void 0 ? void 0 : _b.trim()) || href;
|
|
102
|
+
if (href && urlRegex.test(href)) return {
|
|
103
|
+
href: href,
|
|
104
|
+
display: display
|
|
105
|
+
};
|
|
106
|
+
} else {
|
|
107
|
+
var raw = (td.textContent || "").trim();
|
|
108
|
+
if (urlRegex.test(raw)) return {
|
|
109
|
+
href: raw,
|
|
110
|
+
display: raw
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
return null;
|
|
114
|
+
};
|
|
115
|
+
var buildCellFromTd = function buildCellFromTd(td, classStyles, ctx) {
|
|
116
|
+
var _a;
|
|
117
|
+
var _b, _c;
|
|
118
|
+
var cell = {};
|
|
119
|
+
var rawText = (td.innerText || td.innerHTML || "").trim();
|
|
120
|
+
if (!rawText) {
|
|
121
|
+
cell.v = undefined;
|
|
122
|
+
cell.m = "";
|
|
123
|
+
} else {
|
|
124
|
+
var mask = genarate(rawText);
|
|
125
|
+
_a = mask || [], cell.m = _a[0], cell.ct = _a[1], cell.v = _a[2];
|
|
126
|
+
if (HEX_REGEX.test(rawText)) {
|
|
127
|
+
cell.ct = {
|
|
128
|
+
fa: "@",
|
|
129
|
+
t: "s"
|
|
130
|
+
};
|
|
131
|
+
cell.m = rawText;
|
|
132
|
+
cell.v = rawText;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
var styleBlock = typeof classStyles[".".concat(td.className)] === "string" ? classStyles[".".concat(td.className)] : "";
|
|
136
|
+
var styles = parseInlineStyleBlock(styleBlock);
|
|
137
|
+
if (!_.isNil(styles.border)) td.style.border = styles.border;
|
|
138
|
+
var bg = td.style.backgroundColor || styles.background;
|
|
139
|
+
if (!bg || bg === "rgba(0, 0, 0, 0)") bg = undefined;
|
|
140
|
+
cell.bg = bg;
|
|
141
|
+
var fontWeight = td.style.fontWeight;
|
|
142
|
+
cell.bl = (fontWeight.toString() === "400" || fontWeight === "normal" || _.isEmpty(fontWeight)) && !_.includes(styles["font-style"], "bold") && (!styles["font-weight"] || styles["font-weight"] === "400") ? 0 : 1;
|
|
143
|
+
cell.it = (td.style.fontStyle === "normal" || _.isEmpty(td.style.fontStyle)) && !_.includes(styles["font-style"], "italic") ? 0 : 1;
|
|
144
|
+
cell.un = !_.includes(styles["text-decoration"], "underline") ? undefined : 1;
|
|
145
|
+
cell.cl = !_.includes(td.innerHTML, "<s>") ? undefined : 1;
|
|
146
|
+
var ff = td.style.fontFamily || styles["font-family"] || "";
|
|
147
|
+
cell.ff = mapFontFamilyToIndex(ff, ctx);
|
|
148
|
+
var fontSize = Math.round(styles["font-size"] ? parseInt(styles["font-size"].replace("pt", ""), 10) : parseInt(td.style.fontSize || "".concat(DEFAULT_FONT_SIZE), 10));
|
|
149
|
+
cell.fs = fontSize;
|
|
150
|
+
cell.fc = td.style.color || styles.color;
|
|
151
|
+
var ht = td.style.textAlign || styles["text-align"] || "left";
|
|
152
|
+
if (ht === "center") {
|
|
153
|
+
cell.ht = 0;
|
|
154
|
+
} else if (ht === "right") {
|
|
155
|
+
cell.ht = 2;
|
|
156
|
+
} else {
|
|
157
|
+
cell.ht = 1;
|
|
158
|
+
}
|
|
159
|
+
var regex = /vertical-align:\s*(.*?);/;
|
|
160
|
+
var vtStyle = typeof classStyles.td === "string" && ((_c = (_b = classStyles.td.match(regex)) === null || _b === void 0 ? void 0 : _b[1]) !== null && _c !== void 0 ? _c : "") || "top";
|
|
161
|
+
var vt = td.style.verticalAlign || styles["vertical-align"] || vtStyle;
|
|
162
|
+
if (vt === "middle") {
|
|
163
|
+
cell.vt = 0;
|
|
164
|
+
} else if (vt === "top" || vt === "text-top") {
|
|
165
|
+
cell.vt = 1;
|
|
166
|
+
} else {
|
|
167
|
+
cell.vt = 2;
|
|
168
|
+
}
|
|
169
|
+
cell.tb = "1";
|
|
170
|
+
if ("mso-rotate" in styles) cell.rt = parseFloat(styles["mso-rotate"]);
|
|
171
|
+
var rowspan = parseInt(td.getAttribute("rowspan") || "1", 10);
|
|
172
|
+
var colspan = parseInt(td.getAttribute("colspan") || "1", 10);
|
|
173
|
+
if (Number.isNaN(rowspan)) rowspan = 1;
|
|
174
|
+
if (Number.isNaN(colspan)) colspan = 1;
|
|
175
|
+
return {
|
|
176
|
+
cell: cell,
|
|
177
|
+
rowspan: rowspan,
|
|
178
|
+
colspan: colspan,
|
|
179
|
+
hyperlink: detectHyperlink(td)
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
export function handlePastedTable(ctx, html, pasteHandler) {
|
|
183
|
+
var _a;
|
|
184
|
+
if (!html.includes("table")) return;
|
|
185
|
+
var containerDiv = document.createElement("div");
|
|
186
|
+
containerDiv.innerHTML = html;
|
|
187
|
+
var tableRows = containerDiv.querySelectorAll("table tr");
|
|
188
|
+
if (tableRows.length === 0) {
|
|
189
|
+
containerDiv.remove();
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
var totalColumns = 0;
|
|
193
|
+
tableRows[0].querySelectorAll("td, th").forEach(function (cellEl) {
|
|
194
|
+
var tableCell = cellEl;
|
|
195
|
+
var span = Number.isNaN(tableCell.colSpan) ? 1 : tableCell.colSpan;
|
|
196
|
+
totalColumns += span;
|
|
197
|
+
});
|
|
198
|
+
var totalRows = tableRows.length;
|
|
199
|
+
var pastedMatrix = Array.from({
|
|
200
|
+
length: totalRows
|
|
201
|
+
}, function () {
|
|
202
|
+
return new Array(totalColumns);
|
|
203
|
+
});
|
|
204
|
+
var pasteBorderInfo = {};
|
|
205
|
+
var inlineStyleBlock = ((_a = containerDiv.querySelectorAll("style")[0]) === null || _a === void 0 ? void 0 : _a.innerHTML) || "";
|
|
206
|
+
var classStyleMap = parseStylesheetPairs(inlineStyleBlock);
|
|
207
|
+
var sheetIndex = getSheetIndex(ctx, ctx.currentSheetId);
|
|
208
|
+
if (_.isNil(sheetIndex)) {
|
|
209
|
+
ctx.luckysheet_selection_range = [];
|
|
210
|
+
pasteHandler(ctx, pastedMatrix, pasteBorderInfo);
|
|
211
|
+
containerDiv.remove();
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
var sheetFile = ctx.luckysheetfile[sheetIndex];
|
|
215
|
+
if (!sheetFile.config) sheetFile.config = {};
|
|
216
|
+
if (!sheetFile.config.rowlen) sheetFile.config.rowlen = {};
|
|
217
|
+
var rowHeightsConfig = sheetFile.config.rowlen;
|
|
218
|
+
var localRowIndex = 0;
|
|
219
|
+
tableRows.forEach(function (tr) {
|
|
220
|
+
var _a;
|
|
221
|
+
var localColIndex = 0;
|
|
222
|
+
var anchorRow = ctx.luckysheet_select_save[0].row[0];
|
|
223
|
+
var targetRowIndex = anchorRow + localRowIndex;
|
|
224
|
+
var explicitRowHeightAttr = tr.getAttribute("height");
|
|
225
|
+
if (!_.isNil(explicitRowHeightAttr)) {
|
|
226
|
+
var explicitRowHeight = parseInt(explicitRowHeightAttr, 10);
|
|
227
|
+
var hasCustomRowHeight = _.has((_a = sheetFile.config) === null || _a === void 0 ? void 0 : _a.rowlen, targetRowIndex);
|
|
228
|
+
var currentRowHeight = hasCustomRowHeight ? sheetFile.config.rowlen[targetRowIndex] : sheetFile.defaultRowHeight;
|
|
229
|
+
if (currentRowHeight !== explicitRowHeight) {
|
|
230
|
+
rowHeightsConfig[targetRowIndex] = explicitRowHeight;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
tr.querySelectorAll("td, th").forEach(function (node) {
|
|
234
|
+
var tdElement = node;
|
|
235
|
+
while (localColIndex < totalColumns && pastedMatrix[localRowIndex][localColIndex] != null) {
|
|
236
|
+
localColIndex++;
|
|
237
|
+
}
|
|
238
|
+
if (localColIndex === totalColumns) return;
|
|
239
|
+
var _a = buildCellFromTd(tdElement, classStyleMap, ctx),
|
|
240
|
+
cell = _a.cell,
|
|
241
|
+
rowspan = _a.rowspan,
|
|
242
|
+
colspan = _a.colspan,
|
|
243
|
+
hyperlink = _a.hyperlink;
|
|
244
|
+
var anchorCol = ctx.luckysheet_select_save[0].column[0];
|
|
245
|
+
var absoluteRow = anchorRow + localRowIndex;
|
|
246
|
+
var absoluteCol = anchorCol + localColIndex;
|
|
247
|
+
pastedMatrix[localRowIndex][localColIndex] = cell;
|
|
248
|
+
if (hyperlink) {
|
|
249
|
+
saveHyperlink(ctx, absoluteRow, absoluteCol, hyperlink.href, "webpage", hyperlink.display);
|
|
250
|
+
}
|
|
251
|
+
applyBordersAndMerges(tdElement, localRowIndex, localColIndex, absoluteRow, absoluteCol, rowspan, colspan, pasteBorderInfo, pastedMatrix);
|
|
252
|
+
if (rowspan > 1 || colspan > 1) {
|
|
253
|
+
pastedMatrix[localRowIndex][localColIndex].mc = {
|
|
254
|
+
rs: rowspan,
|
|
255
|
+
cs: colspan,
|
|
256
|
+
r: absoluteRow,
|
|
257
|
+
c: absoluteCol
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
localColIndex++;
|
|
261
|
+
});
|
|
262
|
+
localRowIndex++;
|
|
263
|
+
});
|
|
264
|
+
ctx.luckysheet_selection_range = [];
|
|
265
|
+
pasteHandler(ctx, pastedMatrix, pasteBorderInfo);
|
|
266
|
+
containerDiv.remove();
|
|
267
|
+
}
|
package/lib/events/paste.js
CHANGED
|
@@ -7,8 +7,8 @@ exports.handlePaste = handlePaste;
|
|
|
7
7
|
exports.handlePasteByClick = handlePasteByClick;
|
|
8
8
|
exports.parseAsLinkIfUrl = parseAsLinkIfUrl;
|
|
9
9
|
var _lodash = _interopRequireDefault(require("lodash"));
|
|
10
|
+
var _pasteTableHelpers = require("../paste-table-helpers");
|
|
10
11
|
var _context = require("../context");
|
|
11
|
-
var _locale = require("../locale");
|
|
12
12
|
var _formula = require("../modules/formula");
|
|
13
13
|
var _cell = require("../modules/cell");
|
|
14
14
|
var _format = require("../modules/format");
|
|
@@ -18,9 +18,9 @@ var _validation = require("../modules/validation");
|
|
|
18
18
|
var _border = require("../modules/border");
|
|
19
19
|
var _sheet = require("../modules/sheet");
|
|
20
20
|
var _refresh = require("../modules/refresh");
|
|
21
|
-
var _api = require("../api");
|
|
22
21
|
var _modules = require("../modules");
|
|
23
22
|
var _clipboard = _interopRequireDefault(require("../modules/clipboard"));
|
|
23
|
+
var _calculateRangeCellSize = require("../paste-helpers/calculate-range-cell-size");
|
|
24
24
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
25
25
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
26
26
|
var __assign = void 0 && (void 0).__assign || function () {
|
|
@@ -1019,8 +1019,21 @@ function parseAsLinkIfUrl(txtdata, ctx) {
|
|
|
1019
1019
|
}
|
|
1020
1020
|
}
|
|
1021
1021
|
}
|
|
1022
|
+
function resizePastedCellsToContent(ctx) {
|
|
1023
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
1024
|
+
var lastSelectedRange = (_a = ctx.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[ctx.luckysheet_select_save.length - 1];
|
|
1025
|
+
if (!lastSelectedRange) return;
|
|
1026
|
+
var startRow = (_d = (_c = (_b = lastSelectedRange.row) === null || _b === void 0 ? void 0 : _b[0]) !== null && _c !== void 0 ? _c : lastSelectedRange.row_focus) !== null && _d !== void 0 ? _d : 0;
|
|
1027
|
+
var endRow = (_g = (_f = (_e = lastSelectedRange.row) === null || _e === void 0 ? void 0 : _e[1]) !== null && _f !== void 0 ? _f : lastSelectedRange.row_focus) !== null && _g !== void 0 ? _g : startRow;
|
|
1028
|
+
var startCol = (_k = (_j = (_h = lastSelectedRange.column) === null || _h === void 0 ? void 0 : _h[0]) !== null && _j !== void 0 ? _j : lastSelectedRange.column_focus) !== null && _k !== void 0 ? _k : 0;
|
|
1029
|
+
var endCol = (_o = (_m = (_l = lastSelectedRange.column) === null || _l === void 0 ? void 0 : _l[1]) !== null && _m !== void 0 ? _m : lastSelectedRange.column_focus) !== null && _o !== void 0 ? _o : startCol;
|
|
1030
|
+
var rangeCellSize = (0, _calculateRangeCellSize.calculateRangeCellSize)(ctx, ctx.currentSheetId, startRow, endRow, startCol, endCol);
|
|
1031
|
+
var sheetIdx = (0, _utils.getSheetIndex)(ctx, ctx.currentSheetId);
|
|
1032
|
+
if (sheetIdx == null) return;
|
|
1033
|
+
(0, _calculateRangeCellSize.updateSheetCellSizes)(ctx, sheetIdx, rangeCellSize);
|
|
1034
|
+
}
|
|
1022
1035
|
function handlePaste(ctx, e) {
|
|
1023
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w
|
|
1036
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
1024
1037
|
var allowEdit = (0, _utils.isAllowEdit)(ctx);
|
|
1025
1038
|
if (!allowEdit) return;
|
|
1026
1039
|
if (_selection.selectionCache.isPasteAction) {
|
|
@@ -1105,7 +1118,6 @@ function handlePaste(ctx, e) {
|
|
|
1105
1118
|
}
|
|
1106
1119
|
}
|
|
1107
1120
|
}
|
|
1108
|
-
var locale_fontjson_1 = (0, _locale.locale)(ctx).fontjson;
|
|
1109
1121
|
if (((_o = (_m = ctx.hooks).beforePaste) === null || _o === void 0 ? void 0 : _o.call(_m, ctx.luckysheet_select_save, txtdata)) === false) {
|
|
1110
1122
|
return;
|
|
1111
1123
|
}
|
|
@@ -1117,267 +1129,11 @@ function handlePaste(ctx, e) {
|
|
|
1117
1129
|
} else {
|
|
1118
1130
|
pasteHandlerOfCopyPaste(ctx, ctx.luckysheet_copy_save);
|
|
1119
1131
|
}
|
|
1132
|
+
resizePastedCellsToContent(ctx);
|
|
1120
1133
|
} else if (txtdata.indexOf("fortune-copy-action-image") > -1) {} else {
|
|
1121
1134
|
if (txtdata.indexOf("table") > -1) {
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
var trList = ele.querySelectorAll("table tr");
|
|
1125
|
-
if (trList.length === 0) {
|
|
1126
|
-
ele.remove();
|
|
1127
|
-
return;
|
|
1128
|
-
}
|
|
1129
|
-
var data_1 = new Array(trList.length);
|
|
1130
|
-
var colLen_1 = 0;
|
|
1131
|
-
_lodash.default.forEach(trList[0].querySelectorAll("td, th"), function (td) {
|
|
1132
|
-
var colspan = td.colSpan;
|
|
1133
|
-
if (Number.isNaN(colspan)) {
|
|
1134
|
-
colspan = 1;
|
|
1135
|
-
}
|
|
1136
|
-
colLen_1 += colspan;
|
|
1137
|
-
});
|
|
1138
|
-
for (var i = 0; i < data_1.length; i += 1) {
|
|
1139
|
-
data_1[i] = new Array(colLen_1);
|
|
1140
|
-
}
|
|
1141
|
-
var r_1 = 0;
|
|
1142
|
-
var borderInfo_1 = {};
|
|
1143
|
-
var styleInner = ((_q = ele.querySelectorAll("style")[0]) === null || _q === void 0 ? void 0 : _q.innerHTML) || "";
|
|
1144
|
-
var patternReg = /{([^}]*)}/g;
|
|
1145
|
-
var patternStyle = styleInner.match(patternReg);
|
|
1146
|
-
var nameReg = /^[^\t].*/gm;
|
|
1147
|
-
var patternName = _lodash.default.initial(styleInner.match(nameReg));
|
|
1148
|
-
var allStyleList_1 = patternName.length === (patternStyle === null || patternStyle === void 0 ? void 0 : patternStyle.length) && _typeof(patternName) === _typeof(patternStyle) ? _lodash.default.fromPairs(_lodash.default.zip(patternName, patternStyle)) : {};
|
|
1149
|
-
var index_1 = (0, _utils.getSheetIndex)(ctx, ctx.currentSheetId);
|
|
1150
|
-
if (!_lodash.default.isNil(index_1)) {
|
|
1151
|
-
if (_lodash.default.isNil(ctx.luckysheetfile[index_1].config)) {
|
|
1152
|
-
ctx.luckysheetfile[index_1].config = {};
|
|
1153
|
-
}
|
|
1154
|
-
if (_lodash.default.isNil(ctx.luckysheetfile[index_1].config.rowlen)) {
|
|
1155
|
-
ctx.luckysheetfile[index_1].config.rowlen = {};
|
|
1156
|
-
}
|
|
1157
|
-
var rowHeightList_1 = ctx.luckysheetfile[index_1].config.rowlen;
|
|
1158
|
-
_lodash.default.forEach(trList, function (tr) {
|
|
1159
|
-
var c = 0;
|
|
1160
|
-
var targetR = ctx.luckysheet_select_save[0].row[0] + r_1;
|
|
1161
|
-
var targetRowHeight = !_lodash.default.isNil(tr.getAttribute("height")) ? parseInt(tr.getAttribute("height"), 10) : null;
|
|
1162
|
-
if (_lodash.default.has(ctx.luckysheetfile[index_1].config.rowlen, targetR) && ctx.luckysheetfile[index_1].config.rowlen[targetR] !== targetRowHeight || !_lodash.default.has(ctx.luckysheetfile[index_1].config.rowlen, targetR) && ctx.luckysheetfile[index_1].defaultRowHeight !== targetRowHeight) {
|
|
1163
|
-
rowHeightList_1[targetR] = targetRowHeight;
|
|
1164
|
-
}
|
|
1165
|
-
_lodash.default.forEach(tr.querySelectorAll("td, th"), function (element) {
|
|
1166
|
-
var _a, _b;
|
|
1167
|
-
var td = element;
|
|
1168
|
-
var className = td.className;
|
|
1169
|
-
var cell = {};
|
|
1170
|
-
var txt = td.innerText || td.innerHTML;
|
|
1171
|
-
if (_lodash.default.trim(txt).length === 0) {
|
|
1172
|
-
cell.v = undefined;
|
|
1173
|
-
cell.m = "";
|
|
1174
|
-
} else {
|
|
1175
|
-
var mask = (0, _format.genarate)(txt);
|
|
1176
|
-
cell.m = mask[0], cell.ct = mask[1], cell.v = mask[2];
|
|
1177
|
-
if (/^0x?[a-fA-F0-9]+$/.test(txt)) {
|
|
1178
|
-
cell.ct = {
|
|
1179
|
-
fa: "@",
|
|
1180
|
-
t: "s"
|
|
1181
|
-
};
|
|
1182
|
-
cell.m = txt;
|
|
1183
|
-
cell.v = txt;
|
|
1184
|
-
}
|
|
1185
|
-
}
|
|
1186
|
-
var pendingLink = null;
|
|
1187
|
-
var anchor = td.querySelector("a[href]");
|
|
1188
|
-
var urlRegex = /^(https?:\/\/[^\s]+)$/i;
|
|
1189
|
-
if (anchor) {
|
|
1190
|
-
var hrefAttr = ((_a = anchor.getAttribute("href")) === null || _a === void 0 ? void 0 : _a.trim()) || "";
|
|
1191
|
-
var display = ((_b = anchor.textContent) === null || _b === void 0 ? void 0 : _b.trim()) || hrefAttr;
|
|
1192
|
-
if (hrefAttr && urlRegex.test(hrefAttr)) {
|
|
1193
|
-
pendingLink = {
|
|
1194
|
-
href: hrefAttr,
|
|
1195
|
-
display: display
|
|
1196
|
-
};
|
|
1197
|
-
}
|
|
1198
|
-
} else {
|
|
1199
|
-
var raw = (td.textContent || "").trim();
|
|
1200
|
-
if (urlRegex.test(raw)) {
|
|
1201
|
-
pendingLink = {
|
|
1202
|
-
href: raw,
|
|
1203
|
-
display: raw
|
|
1204
|
-
};
|
|
1205
|
-
}
|
|
1206
|
-
}
|
|
1207
|
-
var styleString = typeof allStyleList_1[".".concat(className)] === "string" ? allStyleList_1[".".concat(className)].substring(1, allStyleList_1[".".concat(className)].length - 1).split("\n\t") : [];
|
|
1208
|
-
var styles = {};
|
|
1209
|
-
_lodash.default.forEach(styleString, function (s) {
|
|
1210
|
-
var styleList = s.split(":");
|
|
1211
|
-
styles[styleList[0]] = styleList === null || styleList === void 0 ? void 0 : styleList[1].replace(";", "");
|
|
1212
|
-
});
|
|
1213
|
-
if (!_lodash.default.isNil(styles.border)) td.style.border = styles.border;
|
|
1214
|
-
var bg = td.style.backgroundColor || styles.background;
|
|
1215
|
-
if (bg === "rgba(0, 0, 0, 0)" || _lodash.default.isEmpty(bg)) {
|
|
1216
|
-
bg = undefined;
|
|
1217
|
-
}
|
|
1218
|
-
cell.bg = bg;
|
|
1219
|
-
var fontWight = td.style.fontWeight;
|
|
1220
|
-
cell.bl = (fontWight.toString() === "400" || fontWight === "normal" || _lodash.default.isEmpty(fontWight)) && !_lodash.default.includes(styles["font-style"], "bold") && (!styles["font-weight"] || styles["font-weight"] === "400") ? 0 : 1;
|
|
1221
|
-
cell.it = (td.style.fontStyle === "normal" || _lodash.default.isEmpty(td.style.fontStyle)) && !_lodash.default.includes(styles["font-style"], "italic") ? 0 : 1;
|
|
1222
|
-
cell.un = !_lodash.default.includes(styles["text-decoration"], "underline") ? undefined : 1;
|
|
1223
|
-
cell.cl = !_lodash.default.includes(td.innerHTML, "<s>") ? undefined : 1;
|
|
1224
|
-
var ff = td.style.fontFamily || styles["font-family"] || "";
|
|
1225
|
-
var ffs = ff.split(",");
|
|
1226
|
-
for (var i = 0; i < ffs.length; i += 1) {
|
|
1227
|
-
var fa = _lodash.default.trim(ffs[i].toLowerCase());
|
|
1228
|
-
fa = locale_fontjson_1[fa];
|
|
1229
|
-
if (_lodash.default.isNil(fa)) {
|
|
1230
|
-
cell.ff = 0;
|
|
1231
|
-
} else {
|
|
1232
|
-
cell.ff = fa;
|
|
1233
|
-
break;
|
|
1234
|
-
}
|
|
1235
|
-
}
|
|
1236
|
-
var fs = Math.round(styles["font-size"] ? parseInt(styles["font-size"].replace("pt", ""), 10) : parseInt(td.style.fontSize || "13", 10) * 72 / 96);
|
|
1237
|
-
cell.fs = fs;
|
|
1238
|
-
cell.fc = td.style.color || styles.color;
|
|
1239
|
-
var ht = td.style.textAlign || styles["text-align"] || "left";
|
|
1240
|
-
if (ht === "center") {
|
|
1241
|
-
cell.ht = 0;
|
|
1242
|
-
} else if (ht === "right") {
|
|
1243
|
-
cell.ht = 2;
|
|
1244
|
-
} else {
|
|
1245
|
-
cell.ht = 1;
|
|
1246
|
-
}
|
|
1247
|
-
var regex = /vertical-align:\s*(.*?);/;
|
|
1248
|
-
var vt = td.style.verticalAlign || styles["vertical-align"] || !_lodash.default.isNil(allStyleList_1.td) && allStyleList_1.td.match(regex).length > 0 && allStyleList_1.td.match(regex)[1] || "top";
|
|
1249
|
-
if (vt === "middle") {
|
|
1250
|
-
cell.vt = 0;
|
|
1251
|
-
} else if (vt === "top" || vt === "text-top") {
|
|
1252
|
-
cell.vt = 1;
|
|
1253
|
-
} else {
|
|
1254
|
-
cell.vt = 2;
|
|
1255
|
-
}
|
|
1256
|
-
if ("mso-rotate" in styles) {
|
|
1257
|
-
var rt = styles["mso-rotate"];
|
|
1258
|
-
cell.rt = parseFloat(rt);
|
|
1259
|
-
}
|
|
1260
|
-
while (c < colLen_1 && !_lodash.default.isNil(data_1[r_1][c])) {
|
|
1261
|
-
c += 1;
|
|
1262
|
-
}
|
|
1263
|
-
if (c === colLen_1) {
|
|
1264
|
-
return true;
|
|
1265
|
-
}
|
|
1266
|
-
if (_lodash.default.isNil(data_1[r_1][c])) {
|
|
1267
|
-
data_1[r_1][c] = cell;
|
|
1268
|
-
var rowspan = parseInt(td.getAttribute("rowspan"), 10);
|
|
1269
|
-
var colspan = parseInt(td.getAttribute("colspan"), 10);
|
|
1270
|
-
if (Number.isNaN(rowspan)) {
|
|
1271
|
-
rowspan = 1;
|
|
1272
|
-
}
|
|
1273
|
-
if (Number.isNaN(colspan)) {
|
|
1274
|
-
colspan = 1;
|
|
1275
|
-
}
|
|
1276
|
-
var r_ab = ctx.luckysheet_select_save[0].row[0] + r_1;
|
|
1277
|
-
var c_ab = ctx.luckysheet_select_save[0].column[0] + c;
|
|
1278
|
-
if (pendingLink) {
|
|
1279
|
-
(0, _modules.saveHyperlink)(ctx, r_ab, c_ab, pendingLink.href, "webpage", pendingLink.display);
|
|
1280
|
-
}
|
|
1281
|
-
for (var rp = 0; rp < rowspan; rp += 1) {
|
|
1282
|
-
for (var cp = 0; cp < colspan; cp += 1) {
|
|
1283
|
-
if (rp === 0) {
|
|
1284
|
-
var bt = td.style.borderTop;
|
|
1285
|
-
if (!_lodash.default.isEmpty(bt) && bt.substring(0, 3).toLowerCase() !== "0px") {
|
|
1286
|
-
var width = td.style.borderTopWidth;
|
|
1287
|
-
var type = td.style.borderTopStyle;
|
|
1288
|
-
var color = td.style.borderTopColor;
|
|
1289
|
-
var borderconfig = (0, _cell.getQKBorder)(width, type, color);
|
|
1290
|
-
if (!borderInfo_1["".concat(r_1 + rp, "_").concat(c + cp)]) {
|
|
1291
|
-
borderInfo_1["".concat(r_1 + rp, "_").concat(c + cp)] = {};
|
|
1292
|
-
}
|
|
1293
|
-
borderInfo_1["".concat(r_1 + rp, "_").concat(c + cp)].t = {
|
|
1294
|
-
style: borderconfig[0],
|
|
1295
|
-
color: borderconfig[1]
|
|
1296
|
-
};
|
|
1297
|
-
}
|
|
1298
|
-
}
|
|
1299
|
-
if (rp === rowspan - 1) {
|
|
1300
|
-
var bb = td.style.borderBottom;
|
|
1301
|
-
if (!_lodash.default.isEmpty(bb) && bb.substring(0, 3).toLowerCase() !== "0px") {
|
|
1302
|
-
var width = td.style.borderBottomWidth;
|
|
1303
|
-
var type = td.style.borderBottomStyle;
|
|
1304
|
-
var color = td.style.borderBottomColor;
|
|
1305
|
-
var borderconfig = (0, _cell.getQKBorder)(width, type, color);
|
|
1306
|
-
if (!borderInfo_1["".concat(r_1 + rp, "_").concat(c + cp)]) {
|
|
1307
|
-
borderInfo_1["".concat(r_1 + rp, "_").concat(c + cp)] = {};
|
|
1308
|
-
}
|
|
1309
|
-
borderInfo_1["".concat(r_1 + rp, "_").concat(c + cp)].b = {
|
|
1310
|
-
style: borderconfig[0],
|
|
1311
|
-
color: borderconfig[1]
|
|
1312
|
-
};
|
|
1313
|
-
}
|
|
1314
|
-
}
|
|
1315
|
-
if (cp === 0) {
|
|
1316
|
-
var bl = td.style.borderLeft;
|
|
1317
|
-
if (!_lodash.default.isEmpty(bl) && bl.substring(0, 3).toLowerCase() !== "0px") {
|
|
1318
|
-
var width = td.style.borderLeftWidth;
|
|
1319
|
-
var type = td.style.borderLeftStyle;
|
|
1320
|
-
var color = td.style.borderLeftColor;
|
|
1321
|
-
var borderconfig = (0, _cell.getQKBorder)(width, type, color);
|
|
1322
|
-
if (!borderInfo_1["".concat(r_1 + rp, "_").concat(c + cp)]) {
|
|
1323
|
-
borderInfo_1["".concat(r_1 + rp, "_").concat(c + cp)] = {};
|
|
1324
|
-
}
|
|
1325
|
-
borderInfo_1["".concat(r_1 + rp, "_").concat(c + cp)].l = {
|
|
1326
|
-
style: borderconfig[0],
|
|
1327
|
-
color: borderconfig[1]
|
|
1328
|
-
};
|
|
1329
|
-
}
|
|
1330
|
-
}
|
|
1331
|
-
if (cp === colspan - 1) {
|
|
1332
|
-
var br = td.style.borderLeft;
|
|
1333
|
-
if (!_lodash.default.isEmpty(br) && br.substring(0, 3).toLowerCase() !== "0px") {
|
|
1334
|
-
var width = td.style.borderRightWidth;
|
|
1335
|
-
var type = td.style.borderRightStyle;
|
|
1336
|
-
var color = td.style.borderRightColor;
|
|
1337
|
-
var borderconfig = (0, _cell.getQKBorder)(width, type, color);
|
|
1338
|
-
if (!borderInfo_1["".concat(r_1 + rp, "_").concat(c + cp)]) {
|
|
1339
|
-
borderInfo_1["".concat(r_1 + rp, "_").concat(c + cp)] = {};
|
|
1340
|
-
}
|
|
1341
|
-
borderInfo_1["".concat(r_1 + rp, "_").concat(c + cp)].r = {
|
|
1342
|
-
style: borderconfig[0],
|
|
1343
|
-
color: borderconfig[1]
|
|
1344
|
-
};
|
|
1345
|
-
}
|
|
1346
|
-
}
|
|
1347
|
-
if (rp === 0 && cp === 0) {
|
|
1348
|
-
continue;
|
|
1349
|
-
}
|
|
1350
|
-
data_1[r_1 + rp][c + cp] = {
|
|
1351
|
-
mc: {
|
|
1352
|
-
r: r_ab,
|
|
1353
|
-
c: c_ab
|
|
1354
|
-
}
|
|
1355
|
-
};
|
|
1356
|
-
}
|
|
1357
|
-
}
|
|
1358
|
-
if (rowspan > 1 || colspan > 1) {
|
|
1359
|
-
var first = {
|
|
1360
|
-
rs: rowspan,
|
|
1361
|
-
cs: colspan,
|
|
1362
|
-
r: r_ab,
|
|
1363
|
-
c: c_ab
|
|
1364
|
-
};
|
|
1365
|
-
data_1[r_1][c].mc = first;
|
|
1366
|
-
}
|
|
1367
|
-
}
|
|
1368
|
-
c += 1;
|
|
1369
|
-
if (c === colLen_1) {
|
|
1370
|
-
return true;
|
|
1371
|
-
}
|
|
1372
|
-
return true;
|
|
1373
|
-
});
|
|
1374
|
-
r_1 += 1;
|
|
1375
|
-
});
|
|
1376
|
-
(0, _api.setRowHeight)(ctx, rowHeightList_1);
|
|
1377
|
-
}
|
|
1378
|
-
ctx.luckysheet_selection_range = [];
|
|
1379
|
-
pasteHandler(ctx, data_1, borderInfo_1);
|
|
1380
|
-
ele.remove();
|
|
1135
|
+
(0, _pasteTableHelpers.handlePastedTable)(ctx, txtdata, pasteHandler);
|
|
1136
|
+
resizePastedCellsToContent(ctx);
|
|
1381
1137
|
} else if (clipboardData.files.length === 1 && clipboardData.files[0].type.indexOf("image") > -1) {} else {
|
|
1382
1138
|
txtdata = clipboardData.getData("text/plain");
|
|
1383
1139
|
var isExcelFormula = txtdata.startsWith("=");
|
|
@@ -1388,10 +1144,10 @@ function handlePaste(ctx, e) {
|
|
|
1388
1144
|
var _txtdata = clipboardData.getData("text/html") || clipboardData.getData("text/plain");
|
|
1389
1145
|
var embedUrl = (0, _modules.sanitizeDuneUrl)(_txtdata);
|
|
1390
1146
|
if (embedUrl) {
|
|
1391
|
-
var last = (
|
|
1147
|
+
var last = (_q = ctx.luckysheet_select_save) === null || _q === void 0 ? void 0 : _q[ctx.luckysheet_select_save.length - 1];
|
|
1392
1148
|
if (last) {
|
|
1393
|
-
var rowIndex = (
|
|
1394
|
-
var colIndex = (
|
|
1149
|
+
var rowIndex = (_t = (_r = last.row_focus) !== null && _r !== void 0 ? _r : (_s = last.row) === null || _s === void 0 ? void 0 : _s[0]) !== null && _t !== void 0 ? _t : 0;
|
|
1150
|
+
var colIndex = (_w = (_u = last.column_focus) !== null && _u !== void 0 ? _u : (_v = last.column) === null || _v === void 0 ? void 0 : _v[0]) !== null && _w !== void 0 ? _w : 0;
|
|
1395
1151
|
var left = colIndex === 0 ? 0 : ctx.visibledatacolumn[colIndex - 1];
|
|
1396
1152
|
var top_1 = rowIndex === 0 ? 0 : ctx.visibledatarow[rowIndex + 5];
|
|
1397
1153
|
ctx.showDunePreview = {
|
|
@@ -1404,6 +1160,7 @@ function handlePaste(ctx, e) {
|
|
|
1404
1160
|
}
|
|
1405
1161
|
}
|
|
1406
1162
|
}
|
|
1163
|
+
resizePastedCellsToContent(ctx);
|
|
1407
1164
|
}
|
|
1408
1165
|
}
|
|
1409
1166
|
} else if (ctx.luckysheetCellUpdate.length > 0) {
|
|
@@ -1416,6 +1173,7 @@ function handlePaste(ctx, e) {
|
|
|
1416
1173
|
if (text) {
|
|
1417
1174
|
document.execCommand("insertText", false, text);
|
|
1418
1175
|
parseAsLinkIfUrl(text, ctx);
|
|
1176
|
+
resizePastedCellsToContent(ctx);
|
|
1419
1177
|
}
|
|
1420
1178
|
}
|
|
1421
1179
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Context } from "../context";
|
|
2
|
+
export declare function calculateRangeCellSize(ctx: Context, sheetId: string, startRow: number, endRow: number, startCol: number, endCol: number, maxColumnWidth?: number): {
|
|
3
|
+
rowMax: Record<number, number>;
|
|
4
|
+
colMax: Record<number, number>;
|
|
5
|
+
};
|
|
6
|
+
export declare const updateSheetCellSizes: (ctx: Context, sheetIndex: number, measurements: {
|
|
7
|
+
rowMax: Record<number, number>;
|
|
8
|
+
colMax: Record<number, number>;
|
|
9
|
+
}, maxColumnWidth?: number) => void;
|