@fileverse-dev/fortune-core 1.1.62-patch-1 → 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,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.calculateRangeCellSize = calculateRangeCellSize;
|
|
7
|
+
exports.updateSheetCellSizes = void 0;
|
|
8
|
+
var _pasteTableHelpers = require("../paste-table-helpers");
|
|
9
|
+
var _utils = require("../utils");
|
|
10
|
+
var _context = require("../context");
|
|
11
|
+
var _api = require("../api");
|
|
12
|
+
var DEFAULT_FONT_FAMILY = "Helvetica Neue, system-ui, Roboto, Lato, Segoe UI, Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Arial, sans-serif";
|
|
13
|
+
var getColumnWidth = function getColumnWidth(colIndex, ctx, sheetFile) {
|
|
14
|
+
var _a, _b, _c, _d;
|
|
15
|
+
var defaultColumnWidth = (_a = ctx.defaultcollen) !== null && _a !== void 0 ? _a : 73;
|
|
16
|
+
return (_d = (_c = (_b = sheetFile.config) === null || _b === void 0 ? void 0 : _b.columnlen) === null || _c === void 0 ? void 0 : _c[colIndex]) !== null && _d !== void 0 ? _d : defaultColumnWidth;
|
|
17
|
+
};
|
|
18
|
+
var isCellWrapped = function isCellWrapped(cell) {
|
|
19
|
+
return Number(cell === null || cell === void 0 ? void 0 : cell.tb) === 1;
|
|
20
|
+
};
|
|
21
|
+
var getCellDisplayText = function getCellDisplayText(cell) {
|
|
22
|
+
var _a, _b;
|
|
23
|
+
var text = (_a = cell === null || cell === void 0 ? void 0 : cell.m) !== null && _a !== void 0 ? _a : cell === null || cell === void 0 ? void 0 : cell.v;
|
|
24
|
+
if (text == null && ((_b = cell === null || cell === void 0 ? void 0 : cell.ct) === null || _b === void 0 ? void 0 : _b.t) === "inlineStr") {
|
|
25
|
+
text = (cell.ct.s || []).map(function (s) {
|
|
26
|
+
return s.v;
|
|
27
|
+
}).join("");
|
|
28
|
+
}
|
|
29
|
+
return text == null ? "" : String(text);
|
|
30
|
+
};
|
|
31
|
+
var applyFontOnMeasurer = function applyFontOnMeasurer(cell, cellSizeMeasurer) {
|
|
32
|
+
var _a, _b;
|
|
33
|
+
var fontSizePx = (_a = cell === null || cell === void 0 ? void 0 : cell.fs) !== null && _a !== void 0 ? _a : _pasteTableHelpers.DEFAULT_FONT_SIZE;
|
|
34
|
+
var fontFamily = (_b = cell === null || cell === void 0 ? void 0 : cell.ff) !== null && _b !== void 0 ? _b : DEFAULT_FONT_FAMILY;
|
|
35
|
+
var fontWeight = (cell === null || cell === void 0 ? void 0 : cell.bl) === 1 ? "700" : "400";
|
|
36
|
+
var fontStyle = (cell === null || cell === void 0 ? void 0 : cell.it) === 1 ? "italic" : "normal";
|
|
37
|
+
cellSizeMeasurer.style.fontSize = "".concat(fontSizePx, "px");
|
|
38
|
+
cellSizeMeasurer.style.fontFamily = fontFamily;
|
|
39
|
+
cellSizeMeasurer.style.fontWeight = fontWeight;
|
|
40
|
+
cellSizeMeasurer.style.fontStyle = fontStyle;
|
|
41
|
+
return fontSizePx;
|
|
42
|
+
};
|
|
43
|
+
function calculateRangeCellSize(ctx, sheetId, startRow, endRow, startCol, endCol, maxColumnWidth) {
|
|
44
|
+
var _a, _b, _c;
|
|
45
|
+
if (maxColumnWidth === void 0) {
|
|
46
|
+
maxColumnWidth = 1200;
|
|
47
|
+
}
|
|
48
|
+
var sheetIndex = (0, _utils.getSheetIndex)(ctx, sheetId);
|
|
49
|
+
var sheetFile = ctx.luckysheetfile[sheetIndex];
|
|
50
|
+
var gridData = (0, _context.getFlowdata)(ctx) || sheetFile.data;
|
|
51
|
+
var maxRowHeights = {};
|
|
52
|
+
var maxColumnWidths = {};
|
|
53
|
+
var cellSizeMeasurer = document.getElementById("fs-cell-measurer");
|
|
54
|
+
if (!cellSizeMeasurer) {
|
|
55
|
+
cellSizeMeasurer = document.createElement("div");
|
|
56
|
+
cellSizeMeasurer.id = "fs-cell-measurer";
|
|
57
|
+
Object.assign(cellSizeMeasurer.style, {
|
|
58
|
+
position: "fixed",
|
|
59
|
+
left: "-99999px",
|
|
60
|
+
top: "-99999px",
|
|
61
|
+
visibility: "hidden",
|
|
62
|
+
lineHeight: "1.3",
|
|
63
|
+
whiteSpace: "normal",
|
|
64
|
+
wordBreak: "normal",
|
|
65
|
+
overflowWrap: "break-word"
|
|
66
|
+
});
|
|
67
|
+
document.body.appendChild(cellSizeMeasurer);
|
|
68
|
+
}
|
|
69
|
+
var defaultRowHeight = (_a = sheetFile.defaultRowHeight) !== null && _a !== void 0 ? _a : 19;
|
|
70
|
+
for (var col = startCol; col <= endCol; col++) {
|
|
71
|
+
var requiredWidth = getColumnWidth(col, ctx, sheetFile);
|
|
72
|
+
for (var row = startRow; row <= endRow; row++) {
|
|
73
|
+
var cell = (_b = gridData === null || gridData === void 0 ? void 0 : gridData[row]) === null || _b === void 0 ? void 0 : _b[col];
|
|
74
|
+
if ((cell === null || cell === void 0 ? void 0 : cell.mc) && cell.mc.rs == null) continue;
|
|
75
|
+
var text = getCellDisplayText(cell);
|
|
76
|
+
applyFontOnMeasurer(cell, cellSizeMeasurer);
|
|
77
|
+
cellSizeMeasurer.style.whiteSpace = "pre";
|
|
78
|
+
cellSizeMeasurer.style.width = "auto";
|
|
79
|
+
cellSizeMeasurer.textContent = text;
|
|
80
|
+
var intrinsicWidth = Math.ceil(cellSizeMeasurer.scrollWidth + 12);
|
|
81
|
+
if (intrinsicWidth > requiredWidth) requiredWidth = intrinsicWidth;
|
|
82
|
+
}
|
|
83
|
+
maxColumnWidths[col] = Math.min(requiredWidth, maxColumnWidth);
|
|
84
|
+
}
|
|
85
|
+
for (var row = startRow; row <= endRow; row++) {
|
|
86
|
+
var requiredHeight = defaultRowHeight;
|
|
87
|
+
for (var col = startCol; col <= endCol; col++) {
|
|
88
|
+
var cell = (_c = gridData === null || gridData === void 0 ? void 0 : gridData[row]) === null || _c === void 0 ? void 0 : _c[col];
|
|
89
|
+
if ((cell === null || cell === void 0 ? void 0 : cell.mc) && cell.mc.rs == null) continue;
|
|
90
|
+
var text = getCellDisplayText(cell);
|
|
91
|
+
var fontSizePx = applyFontOnMeasurer(cell, cellSizeMeasurer);
|
|
92
|
+
if (isCellWrapped(cell)) {
|
|
93
|
+
var finalColumnWidth = Math.max(getColumnWidth(col, ctx, sheetFile), maxColumnWidths[col] || 0);
|
|
94
|
+
cellSizeMeasurer.style.whiteSpace = "normal";
|
|
95
|
+
cellSizeMeasurer.style.width = "".concat(Math.max(5, finalColumnWidth - 8), "px");
|
|
96
|
+
cellSizeMeasurer.textContent = text;
|
|
97
|
+
var wrappedHeight = Math.ceil(cellSizeMeasurer.scrollHeight + 6);
|
|
98
|
+
if (wrappedHeight > requiredHeight) requiredHeight = wrappedHeight;
|
|
99
|
+
} else {
|
|
100
|
+
var singleLineHeight = Math.ceil(fontSizePx * 1.3 + 6);
|
|
101
|
+
if (singleLineHeight > requiredHeight) requiredHeight = singleLineHeight;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
maxRowHeights[row] = requiredHeight;
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
rowMax: maxRowHeights,
|
|
108
|
+
colMax: maxColumnWidths
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
var updateSheetCellSizes = exports.updateSheetCellSizes = function updateSheetCellSizes(ctx, sheetIndex, measurements, maxColumnWidth) {
|
|
112
|
+
var _a;
|
|
113
|
+
if (maxColumnWidth === void 0) {
|
|
114
|
+
maxColumnWidth = 1200;
|
|
115
|
+
}
|
|
116
|
+
var sheetFile = ctx.luckysheetfile[sheetIndex];
|
|
117
|
+
if (!sheetFile) return;
|
|
118
|
+
if (!sheetFile.config) {
|
|
119
|
+
sheetFile.config = {};
|
|
120
|
+
}
|
|
121
|
+
var config = sheetFile.config;
|
|
122
|
+
if (!config.rowlen) {
|
|
123
|
+
config.rowlen = {};
|
|
124
|
+
}
|
|
125
|
+
var rowHeightsConfig = config.rowlen;
|
|
126
|
+
if (!config.columnlen) {
|
|
127
|
+
config.columnlen = {};
|
|
128
|
+
}
|
|
129
|
+
var columnWidthsConfig = config.columnlen;
|
|
130
|
+
var defaultRowHeight = (_a = sheetFile.defaultRowHeight) !== null && _a !== void 0 ? _a : 19;
|
|
131
|
+
Object.entries(measurements.rowMax).forEach(function (_a) {
|
|
132
|
+
var _b;
|
|
133
|
+
var rowIndexString = _a[0],
|
|
134
|
+
requiredHeight = _a[1];
|
|
135
|
+
var rowIndex = Number(rowIndexString);
|
|
136
|
+
var currentHeight = (_b = rowHeightsConfig[rowIndex]) !== null && _b !== void 0 ? _b : defaultRowHeight;
|
|
137
|
+
if (requiredHeight > currentHeight) {
|
|
138
|
+
rowHeightsConfig[rowIndex] = requiredHeight;
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
Object.entries(measurements.colMax).forEach(function (_a) {
|
|
142
|
+
var _b;
|
|
143
|
+
var colIndexString = _a[0],
|
|
144
|
+
requiredWidth = _a[1];
|
|
145
|
+
var colIndex = Number(colIndexString);
|
|
146
|
+
var currentWidth = (_b = columnWidthsConfig[colIndex]) !== null && _b !== void 0 ? _b : 0;
|
|
147
|
+
var cappedWidth = Math.min(requiredWidth, maxColumnWidth);
|
|
148
|
+
if (cappedWidth > currentWidth) {
|
|
149
|
+
columnWidthsConfig[colIndex] = cappedWidth;
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
(0, _api.setRowHeight)(ctx, rowHeightsConfig);
|
|
153
|
+
};
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.DEFAULT_FONT_SIZE = void 0;
|
|
7
|
+
exports.handlePastedTable = handlePastedTable;
|
|
8
|
+
var _lodash = _interopRequireDefault(require("lodash"));
|
|
9
|
+
var _locale = require("./locale");
|
|
10
|
+
var _modules = require("./modules");
|
|
11
|
+
var _format = require("./modules/format");
|
|
12
|
+
var _utils = require("./utils");
|
|
13
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
+
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); }
|
|
15
|
+
var DEFAULT_FONT_SIZE = exports.DEFAULT_FONT_SIZE = 12;
|
|
16
|
+
var parseStylesheetPairs = function parseStylesheetPairs(styleInner) {
|
|
17
|
+
var patternReg = /{([^}]*)}/g;
|
|
18
|
+
var patternStyle = styleInner.match(patternReg);
|
|
19
|
+
var nameReg = /^[^\t].*/gm;
|
|
20
|
+
var patternName = _lodash.default.initial(styleInner.match(nameReg));
|
|
21
|
+
if (_typeof(patternStyle) !== _typeof(patternName) || patternName.length !== (patternStyle === null || patternStyle === void 0 ? void 0 : patternStyle.length)) return {};
|
|
22
|
+
return _lodash.default.fromPairs(_lodash.default.zip(patternName, patternStyle));
|
|
23
|
+
};
|
|
24
|
+
var parseInlineStyleBlock = function parseInlineStyleBlock(block) {
|
|
25
|
+
if (!block) return {};
|
|
26
|
+
var trimmed = block.substring(1, block.length - 1);
|
|
27
|
+
var entries = trimmed.split("\n\t").map(function (s) {
|
|
28
|
+
return s.trim();
|
|
29
|
+
}).filter(Boolean);
|
|
30
|
+
var out = {};
|
|
31
|
+
entries.forEach(function (entry) {
|
|
32
|
+
var _a = entry.split(":"),
|
|
33
|
+
k = _a[0],
|
|
34
|
+
v = _a[1];
|
|
35
|
+
if (k && v) out[k] = v.replace(";", "").trim();
|
|
36
|
+
});
|
|
37
|
+
return out;
|
|
38
|
+
};
|
|
39
|
+
var mapFontFamilyToIndex = function mapFontFamilyToIndex(ff, ctx) {
|
|
40
|
+
var families = ff.split(",");
|
|
41
|
+
var locale_fontjson = (0, _locale.locale)(ctx).fontjson;
|
|
42
|
+
var found = families.map(function (raw) {
|
|
43
|
+
return raw.trim().toLowerCase();
|
|
44
|
+
}).find(function (key) {
|
|
45
|
+
var mapped = locale_fontjson[key];
|
|
46
|
+
return mapped != null;
|
|
47
|
+
});
|
|
48
|
+
if (found != null) return locale_fontjson[found];
|
|
49
|
+
return 0;
|
|
50
|
+
};
|
|
51
|
+
function applyBordersAndMerges(td, startRow, startCol, absRow, absCol, rowSpanCount, colSpanCount, borderInfo, data) {
|
|
52
|
+
var topBorder = td.style.borderTop && !td.style.borderTop.startsWith("0px") ? (0, _modules.getQKBorder)(td.style.borderTopWidth, td.style.borderTopStyle, td.style.borderTopColor) : null;
|
|
53
|
+
var bottomBorder = td.style.borderBottom && !td.style.borderBottom.startsWith("0px") ? (0, _modules.getQKBorder)(td.style.borderBottomWidth, td.style.borderBottomStyle, td.style.borderBottomColor) : null;
|
|
54
|
+
var leftBorder = td.style.borderLeft && !td.style.borderLeft.startsWith("0px") ? (0, _modules.getQKBorder)(td.style.borderLeftWidth, td.style.borderLeftStyle, td.style.borderLeftColor) : null;
|
|
55
|
+
var rightBorder = td.style.borderRight && !td.style.borderRight.startsWith("0px") ? (0, _modules.getQKBorder)(td.style.borderRightWidth, td.style.borderRightStyle, td.style.borderRightColor) : null;
|
|
56
|
+
for (var rowOffset = 0; rowOffset < rowSpanCount; rowOffset++) {
|
|
57
|
+
var relativeRow = startRow + rowOffset;
|
|
58
|
+
for (var colOffset = 0; colOffset < colSpanCount; colOffset++) {
|
|
59
|
+
var relativeCol = startCol + colOffset;
|
|
60
|
+
if (!(rowOffset === 0 && colOffset === 0)) {
|
|
61
|
+
data[relativeRow][relativeCol] = {
|
|
62
|
+
mc: {
|
|
63
|
+
r: absRow,
|
|
64
|
+
c: absCol
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
var isTopEdge = rowOffset === 0;
|
|
69
|
+
var isBottomEdge = rowOffset === rowSpanCount - 1;
|
|
70
|
+
var isLeftEdge = colOffset === 0;
|
|
71
|
+
var isRightEdge = colOffset === colSpanCount - 1;
|
|
72
|
+
if (!(isTopEdge || isBottomEdge || isLeftEdge || isRightEdge)) continue;
|
|
73
|
+
var borderKey = "".concat(relativeRow, "_").concat(relativeCol);
|
|
74
|
+
borderInfo[borderKey] || (borderInfo[borderKey] = {});
|
|
75
|
+
if (isTopEdge && topBorder) {
|
|
76
|
+
borderInfo[borderKey].t = {
|
|
77
|
+
style: topBorder[0],
|
|
78
|
+
color: topBorder[1]
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
if (isBottomEdge && bottomBorder) {
|
|
82
|
+
borderInfo[borderKey].b = {
|
|
83
|
+
style: bottomBorder[0],
|
|
84
|
+
color: bottomBorder[1]
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
if (isLeftEdge && leftBorder) {
|
|
88
|
+
borderInfo[borderKey].l = {
|
|
89
|
+
style: leftBorder[0],
|
|
90
|
+
color: leftBorder[1]
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
if (isRightEdge && rightBorder) {
|
|
94
|
+
borderInfo[borderKey].r = {
|
|
95
|
+
style: rightBorder[0],
|
|
96
|
+
color: rightBorder[1]
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
var HEX_REGEX = /^0x?[a-fA-F0-9]+$/;
|
|
103
|
+
var detectHyperlink = function detectHyperlink(td) {
|
|
104
|
+
var _a, _b;
|
|
105
|
+
var anchor = td.querySelector("a[href]");
|
|
106
|
+
var urlRegex = /^(https?:\/\/[^\s]+)$/i;
|
|
107
|
+
if (anchor) {
|
|
108
|
+
var href = ((_a = anchor.getAttribute("href")) === null || _a === void 0 ? void 0 : _a.trim()) || "";
|
|
109
|
+
var display = ((_b = anchor.textContent) === null || _b === void 0 ? void 0 : _b.trim()) || href;
|
|
110
|
+
if (href && urlRegex.test(href)) return {
|
|
111
|
+
href: href,
|
|
112
|
+
display: display
|
|
113
|
+
};
|
|
114
|
+
} else {
|
|
115
|
+
var raw = (td.textContent || "").trim();
|
|
116
|
+
if (urlRegex.test(raw)) return {
|
|
117
|
+
href: raw,
|
|
118
|
+
display: raw
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
return null;
|
|
122
|
+
};
|
|
123
|
+
var buildCellFromTd = function buildCellFromTd(td, classStyles, ctx) {
|
|
124
|
+
var _a;
|
|
125
|
+
var _b, _c;
|
|
126
|
+
var cell = {};
|
|
127
|
+
var rawText = (td.innerText || td.innerHTML || "").trim();
|
|
128
|
+
if (!rawText) {
|
|
129
|
+
cell.v = undefined;
|
|
130
|
+
cell.m = "";
|
|
131
|
+
} else {
|
|
132
|
+
var mask = (0, _format.genarate)(rawText);
|
|
133
|
+
_a = mask || [], cell.m = _a[0], cell.ct = _a[1], cell.v = _a[2];
|
|
134
|
+
if (HEX_REGEX.test(rawText)) {
|
|
135
|
+
cell.ct = {
|
|
136
|
+
fa: "@",
|
|
137
|
+
t: "s"
|
|
138
|
+
};
|
|
139
|
+
cell.m = rawText;
|
|
140
|
+
cell.v = rawText;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
var styleBlock = typeof classStyles[".".concat(td.className)] === "string" ? classStyles[".".concat(td.className)] : "";
|
|
144
|
+
var styles = parseInlineStyleBlock(styleBlock);
|
|
145
|
+
if (!_lodash.default.isNil(styles.border)) td.style.border = styles.border;
|
|
146
|
+
var bg = td.style.backgroundColor || styles.background;
|
|
147
|
+
if (!bg || bg === "rgba(0, 0, 0, 0)") bg = undefined;
|
|
148
|
+
cell.bg = bg;
|
|
149
|
+
var fontWeight = td.style.fontWeight;
|
|
150
|
+
cell.bl = (fontWeight.toString() === "400" || fontWeight === "normal" || _lodash.default.isEmpty(fontWeight)) && !_lodash.default.includes(styles["font-style"], "bold") && (!styles["font-weight"] || styles["font-weight"] === "400") ? 0 : 1;
|
|
151
|
+
cell.it = (td.style.fontStyle === "normal" || _lodash.default.isEmpty(td.style.fontStyle)) && !_lodash.default.includes(styles["font-style"], "italic") ? 0 : 1;
|
|
152
|
+
cell.un = !_lodash.default.includes(styles["text-decoration"], "underline") ? undefined : 1;
|
|
153
|
+
cell.cl = !_lodash.default.includes(td.innerHTML, "<s>") ? undefined : 1;
|
|
154
|
+
var ff = td.style.fontFamily || styles["font-family"] || "";
|
|
155
|
+
cell.ff = mapFontFamilyToIndex(ff, ctx);
|
|
156
|
+
var fontSize = Math.round(styles["font-size"] ? parseInt(styles["font-size"].replace("pt", ""), 10) : parseInt(td.style.fontSize || "".concat(DEFAULT_FONT_SIZE), 10));
|
|
157
|
+
cell.fs = fontSize;
|
|
158
|
+
cell.fc = td.style.color || styles.color;
|
|
159
|
+
var ht = td.style.textAlign || styles["text-align"] || "left";
|
|
160
|
+
if (ht === "center") {
|
|
161
|
+
cell.ht = 0;
|
|
162
|
+
} else if (ht === "right") {
|
|
163
|
+
cell.ht = 2;
|
|
164
|
+
} else {
|
|
165
|
+
cell.ht = 1;
|
|
166
|
+
}
|
|
167
|
+
var regex = /vertical-align:\s*(.*?);/;
|
|
168
|
+
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";
|
|
169
|
+
var vt = td.style.verticalAlign || styles["vertical-align"] || vtStyle;
|
|
170
|
+
if (vt === "middle") {
|
|
171
|
+
cell.vt = 0;
|
|
172
|
+
} else if (vt === "top" || vt === "text-top") {
|
|
173
|
+
cell.vt = 1;
|
|
174
|
+
} else {
|
|
175
|
+
cell.vt = 2;
|
|
176
|
+
}
|
|
177
|
+
cell.tb = "1";
|
|
178
|
+
if ("mso-rotate" in styles) cell.rt = parseFloat(styles["mso-rotate"]);
|
|
179
|
+
var rowspan = parseInt(td.getAttribute("rowspan") || "1", 10);
|
|
180
|
+
var colspan = parseInt(td.getAttribute("colspan") || "1", 10);
|
|
181
|
+
if (Number.isNaN(rowspan)) rowspan = 1;
|
|
182
|
+
if (Number.isNaN(colspan)) colspan = 1;
|
|
183
|
+
return {
|
|
184
|
+
cell: cell,
|
|
185
|
+
rowspan: rowspan,
|
|
186
|
+
colspan: colspan,
|
|
187
|
+
hyperlink: detectHyperlink(td)
|
|
188
|
+
};
|
|
189
|
+
};
|
|
190
|
+
function handlePastedTable(ctx, html, pasteHandler) {
|
|
191
|
+
var _a;
|
|
192
|
+
if (!html.includes("table")) return;
|
|
193
|
+
var containerDiv = document.createElement("div");
|
|
194
|
+
containerDiv.innerHTML = html;
|
|
195
|
+
var tableRows = containerDiv.querySelectorAll("table tr");
|
|
196
|
+
if (tableRows.length === 0) {
|
|
197
|
+
containerDiv.remove();
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
var totalColumns = 0;
|
|
201
|
+
tableRows[0].querySelectorAll("td, th").forEach(function (cellEl) {
|
|
202
|
+
var tableCell = cellEl;
|
|
203
|
+
var span = Number.isNaN(tableCell.colSpan) ? 1 : tableCell.colSpan;
|
|
204
|
+
totalColumns += span;
|
|
205
|
+
});
|
|
206
|
+
var totalRows = tableRows.length;
|
|
207
|
+
var pastedMatrix = Array.from({
|
|
208
|
+
length: totalRows
|
|
209
|
+
}, function () {
|
|
210
|
+
return new Array(totalColumns);
|
|
211
|
+
});
|
|
212
|
+
var pasteBorderInfo = {};
|
|
213
|
+
var inlineStyleBlock = ((_a = containerDiv.querySelectorAll("style")[0]) === null || _a === void 0 ? void 0 : _a.innerHTML) || "";
|
|
214
|
+
var classStyleMap = parseStylesheetPairs(inlineStyleBlock);
|
|
215
|
+
var sheetIndex = (0, _utils.getSheetIndex)(ctx, ctx.currentSheetId);
|
|
216
|
+
if (_lodash.default.isNil(sheetIndex)) {
|
|
217
|
+
ctx.luckysheet_selection_range = [];
|
|
218
|
+
pasteHandler(ctx, pastedMatrix, pasteBorderInfo);
|
|
219
|
+
containerDiv.remove();
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
var sheetFile = ctx.luckysheetfile[sheetIndex];
|
|
223
|
+
if (!sheetFile.config) sheetFile.config = {};
|
|
224
|
+
if (!sheetFile.config.rowlen) sheetFile.config.rowlen = {};
|
|
225
|
+
var rowHeightsConfig = sheetFile.config.rowlen;
|
|
226
|
+
var localRowIndex = 0;
|
|
227
|
+
tableRows.forEach(function (tr) {
|
|
228
|
+
var _a;
|
|
229
|
+
var localColIndex = 0;
|
|
230
|
+
var anchorRow = ctx.luckysheet_select_save[0].row[0];
|
|
231
|
+
var targetRowIndex = anchorRow + localRowIndex;
|
|
232
|
+
var explicitRowHeightAttr = tr.getAttribute("height");
|
|
233
|
+
if (!_lodash.default.isNil(explicitRowHeightAttr)) {
|
|
234
|
+
var explicitRowHeight = parseInt(explicitRowHeightAttr, 10);
|
|
235
|
+
var hasCustomRowHeight = _lodash.default.has((_a = sheetFile.config) === null || _a === void 0 ? void 0 : _a.rowlen, targetRowIndex);
|
|
236
|
+
var currentRowHeight = hasCustomRowHeight ? sheetFile.config.rowlen[targetRowIndex] : sheetFile.defaultRowHeight;
|
|
237
|
+
if (currentRowHeight !== explicitRowHeight) {
|
|
238
|
+
rowHeightsConfig[targetRowIndex] = explicitRowHeight;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
tr.querySelectorAll("td, th").forEach(function (node) {
|
|
242
|
+
var tdElement = node;
|
|
243
|
+
while (localColIndex < totalColumns && pastedMatrix[localRowIndex][localColIndex] != null) {
|
|
244
|
+
localColIndex++;
|
|
245
|
+
}
|
|
246
|
+
if (localColIndex === totalColumns) return;
|
|
247
|
+
var _a = buildCellFromTd(tdElement, classStyleMap, ctx),
|
|
248
|
+
cell = _a.cell,
|
|
249
|
+
rowspan = _a.rowspan,
|
|
250
|
+
colspan = _a.colspan,
|
|
251
|
+
hyperlink = _a.hyperlink;
|
|
252
|
+
var anchorCol = ctx.luckysheet_select_save[0].column[0];
|
|
253
|
+
var absoluteRow = anchorRow + localRowIndex;
|
|
254
|
+
var absoluteCol = anchorCol + localColIndex;
|
|
255
|
+
pastedMatrix[localRowIndex][localColIndex] = cell;
|
|
256
|
+
if (hyperlink) {
|
|
257
|
+
(0, _modules.saveHyperlink)(ctx, absoluteRow, absoluteCol, hyperlink.href, "webpage", hyperlink.display);
|
|
258
|
+
}
|
|
259
|
+
applyBordersAndMerges(tdElement, localRowIndex, localColIndex, absoluteRow, absoluteCol, rowspan, colspan, pasteBorderInfo, pastedMatrix);
|
|
260
|
+
if (rowspan > 1 || colspan > 1) {
|
|
261
|
+
pastedMatrix[localRowIndex][localColIndex].mc = {
|
|
262
|
+
rs: rowspan,
|
|
263
|
+
cs: colspan,
|
|
264
|
+
r: absoluteRow,
|
|
265
|
+
c: absoluteCol
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
localColIndex++;
|
|
269
|
+
});
|
|
270
|
+
localRowIndex++;
|
|
271
|
+
});
|
|
272
|
+
ctx.luckysheet_selection_range = [];
|
|
273
|
+
pasteHandler(ctx, pastedMatrix, pasteBorderInfo);
|
|
274
|
+
containerDiv.remove();
|
|
275
|
+
}
|