@fileverse-dev/fortune-core 1.1.62 → 1.1.64
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/modules/toolbar.js +15 -12
- package/es/modules/validation.js +1 -1
- 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/modules/toolbar.js +15 -12
- package/lib/modules/validation.js +1 -1
- 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
package/es/events/paste.js
CHANGED
|
@@ -10,10 +10,10 @@ var __assign = this && this.__assign || function () {
|
|
|
10
10
|
return __assign.apply(this, arguments);
|
|
11
11
|
};
|
|
12
12
|
import _ from "lodash";
|
|
13
|
+
import { handlePastedTable } from "../paste-table-helpers";
|
|
13
14
|
import { getFlowdata } from "../context";
|
|
14
|
-
import { locale } from "../locale";
|
|
15
15
|
import { execfunction, functionCopy } from "../modules/formula";
|
|
16
|
-
import { getdatabyselection
|
|
16
|
+
import { getdatabyselection } from "../modules/cell";
|
|
17
17
|
import { genarate, update } from "../modules/format";
|
|
18
18
|
import { normalizeSelection, selectionCache } from "../modules/selection";
|
|
19
19
|
import { getSheetIndex, isAllowEdit } from "../utils";
|
|
@@ -21,9 +21,9 @@ import { hasPartMC, isRealNum } from "../modules/validation";
|
|
|
21
21
|
import { getBorderInfoCompute } from "../modules/border";
|
|
22
22
|
import { expandRowsAndColumns, storeSheetParamALL } from "../modules/sheet";
|
|
23
23
|
import { jfrefreshgrid } from "../modules/refresh";
|
|
24
|
-
import { setRowHeight } from "../api";
|
|
25
24
|
import { CFSplitRange, sanitizeDuneUrl, saveHyperlink } from "../modules";
|
|
26
25
|
import clipboard from "../modules/clipboard";
|
|
26
|
+
import { calculateRangeCellSize, updateSheetCellSizes } from "../paste-helpers/calculate-range-cell-size";
|
|
27
27
|
function postPasteCut(ctx, source, target, RowlChange) {
|
|
28
28
|
var execF_rc = {};
|
|
29
29
|
ctx.formulaCache.execFunctionExist = [];
|
|
@@ -1010,8 +1010,21 @@ export function parseAsLinkIfUrl(txtdata, ctx) {
|
|
|
1010
1010
|
}
|
|
1011
1011
|
}
|
|
1012
1012
|
}
|
|
1013
|
+
function resizePastedCellsToContent(ctx) {
|
|
1014
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
1015
|
+
var lastSelectedRange = (_a = ctx.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[ctx.luckysheet_select_save.length - 1];
|
|
1016
|
+
if (!lastSelectedRange) return;
|
|
1017
|
+
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;
|
|
1018
|
+
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;
|
|
1019
|
+
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;
|
|
1020
|
+
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;
|
|
1021
|
+
var rangeCellSize = calculateRangeCellSize(ctx, ctx.currentSheetId, startRow, endRow, startCol, endCol);
|
|
1022
|
+
var sheetIdx = getSheetIndex(ctx, ctx.currentSheetId);
|
|
1023
|
+
if (sheetIdx == null) return;
|
|
1024
|
+
updateSheetCellSizes(ctx, sheetIdx, rangeCellSize);
|
|
1025
|
+
}
|
|
1013
1026
|
export function handlePaste(ctx, e) {
|
|
1014
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w
|
|
1027
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
1015
1028
|
var allowEdit = isAllowEdit(ctx);
|
|
1016
1029
|
if (!allowEdit) return;
|
|
1017
1030
|
if (selectionCache.isPasteAction) {
|
|
@@ -1096,7 +1109,6 @@ export function handlePaste(ctx, e) {
|
|
|
1096
1109
|
}
|
|
1097
1110
|
}
|
|
1098
1111
|
}
|
|
1099
|
-
var locale_fontjson_1 = locale(ctx).fontjson;
|
|
1100
1112
|
if (((_o = (_m = ctx.hooks).beforePaste) === null || _o === void 0 ? void 0 : _o.call(_m, ctx.luckysheet_select_save, txtdata)) === false) {
|
|
1101
1113
|
return;
|
|
1102
1114
|
}
|
|
@@ -1108,267 +1120,11 @@ export function handlePaste(ctx, e) {
|
|
|
1108
1120
|
} else {
|
|
1109
1121
|
pasteHandlerOfCopyPaste(ctx, ctx.luckysheet_copy_save);
|
|
1110
1122
|
}
|
|
1123
|
+
resizePastedCellsToContent(ctx);
|
|
1111
1124
|
} else if (txtdata.indexOf("fortune-copy-action-image") > -1) {} else {
|
|
1112
1125
|
if (txtdata.indexOf("table") > -1) {
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
var trList = ele.querySelectorAll("table tr");
|
|
1116
|
-
if (trList.length === 0) {
|
|
1117
|
-
ele.remove();
|
|
1118
|
-
return;
|
|
1119
|
-
}
|
|
1120
|
-
var data_1 = new Array(trList.length);
|
|
1121
|
-
var colLen_1 = 0;
|
|
1122
|
-
_.forEach(trList[0].querySelectorAll("td, th"), function (td) {
|
|
1123
|
-
var colspan = td.colSpan;
|
|
1124
|
-
if (Number.isNaN(colspan)) {
|
|
1125
|
-
colspan = 1;
|
|
1126
|
-
}
|
|
1127
|
-
colLen_1 += colspan;
|
|
1128
|
-
});
|
|
1129
|
-
for (var i = 0; i < data_1.length; i += 1) {
|
|
1130
|
-
data_1[i] = new Array(colLen_1);
|
|
1131
|
-
}
|
|
1132
|
-
var r_1 = 0;
|
|
1133
|
-
var borderInfo_1 = {};
|
|
1134
|
-
var styleInner = ((_q = ele.querySelectorAll("style")[0]) === null || _q === void 0 ? void 0 : _q.innerHTML) || "";
|
|
1135
|
-
var patternReg = /{([^}]*)}/g;
|
|
1136
|
-
var patternStyle = styleInner.match(patternReg);
|
|
1137
|
-
var nameReg = /^[^\t].*/gm;
|
|
1138
|
-
var patternName = _.initial(styleInner.match(nameReg));
|
|
1139
|
-
var allStyleList_1 = patternName.length === (patternStyle === null || patternStyle === void 0 ? void 0 : patternStyle.length) && _typeof(patternName) === _typeof(patternStyle) ? _.fromPairs(_.zip(patternName, patternStyle)) : {};
|
|
1140
|
-
var index_1 = getSheetIndex(ctx, ctx.currentSheetId);
|
|
1141
|
-
if (!_.isNil(index_1)) {
|
|
1142
|
-
if (_.isNil(ctx.luckysheetfile[index_1].config)) {
|
|
1143
|
-
ctx.luckysheetfile[index_1].config = {};
|
|
1144
|
-
}
|
|
1145
|
-
if (_.isNil(ctx.luckysheetfile[index_1].config.rowlen)) {
|
|
1146
|
-
ctx.luckysheetfile[index_1].config.rowlen = {};
|
|
1147
|
-
}
|
|
1148
|
-
var rowHeightList_1 = ctx.luckysheetfile[index_1].config.rowlen;
|
|
1149
|
-
_.forEach(trList, function (tr) {
|
|
1150
|
-
var c = 0;
|
|
1151
|
-
var targetR = ctx.luckysheet_select_save[0].row[0] + r_1;
|
|
1152
|
-
var targetRowHeight = !_.isNil(tr.getAttribute("height")) ? parseInt(tr.getAttribute("height"), 10) : null;
|
|
1153
|
-
if (_.has(ctx.luckysheetfile[index_1].config.rowlen, targetR) && ctx.luckysheetfile[index_1].config.rowlen[targetR] !== targetRowHeight || !_.has(ctx.luckysheetfile[index_1].config.rowlen, targetR) && ctx.luckysheetfile[index_1].defaultRowHeight !== targetRowHeight) {
|
|
1154
|
-
rowHeightList_1[targetR] = targetRowHeight;
|
|
1155
|
-
}
|
|
1156
|
-
_.forEach(tr.querySelectorAll("td, th"), function (element) {
|
|
1157
|
-
var _a, _b;
|
|
1158
|
-
var td = element;
|
|
1159
|
-
var className = td.className;
|
|
1160
|
-
var cell = {};
|
|
1161
|
-
var txt = td.innerText || td.innerHTML;
|
|
1162
|
-
if (_.trim(txt).length === 0) {
|
|
1163
|
-
cell.v = undefined;
|
|
1164
|
-
cell.m = "";
|
|
1165
|
-
} else {
|
|
1166
|
-
var mask = genarate(txt);
|
|
1167
|
-
cell.m = mask[0], cell.ct = mask[1], cell.v = mask[2];
|
|
1168
|
-
if (/^0x?[a-fA-F0-9]+$/.test(txt)) {
|
|
1169
|
-
cell.ct = {
|
|
1170
|
-
fa: "@",
|
|
1171
|
-
t: "s"
|
|
1172
|
-
};
|
|
1173
|
-
cell.m = txt;
|
|
1174
|
-
cell.v = txt;
|
|
1175
|
-
}
|
|
1176
|
-
}
|
|
1177
|
-
var pendingLink = null;
|
|
1178
|
-
var anchor = td.querySelector("a[href]");
|
|
1179
|
-
var urlRegex = /^(https?:\/\/[^\s]+)$/i;
|
|
1180
|
-
if (anchor) {
|
|
1181
|
-
var hrefAttr = ((_a = anchor.getAttribute("href")) === null || _a === void 0 ? void 0 : _a.trim()) || "";
|
|
1182
|
-
var display = ((_b = anchor.textContent) === null || _b === void 0 ? void 0 : _b.trim()) || hrefAttr;
|
|
1183
|
-
if (hrefAttr && urlRegex.test(hrefAttr)) {
|
|
1184
|
-
pendingLink = {
|
|
1185
|
-
href: hrefAttr,
|
|
1186
|
-
display: display
|
|
1187
|
-
};
|
|
1188
|
-
}
|
|
1189
|
-
} else {
|
|
1190
|
-
var raw = (td.textContent || "").trim();
|
|
1191
|
-
if (urlRegex.test(raw)) {
|
|
1192
|
-
pendingLink = {
|
|
1193
|
-
href: raw,
|
|
1194
|
-
display: raw
|
|
1195
|
-
};
|
|
1196
|
-
}
|
|
1197
|
-
}
|
|
1198
|
-
var styleString = typeof allStyleList_1[".".concat(className)] === "string" ? allStyleList_1[".".concat(className)].substring(1, allStyleList_1[".".concat(className)].length - 1).split("\n\t") : [];
|
|
1199
|
-
var styles = {};
|
|
1200
|
-
_.forEach(styleString, function (s) {
|
|
1201
|
-
var styleList = s.split(":");
|
|
1202
|
-
styles[styleList[0]] = styleList === null || styleList === void 0 ? void 0 : styleList[1].replace(";", "");
|
|
1203
|
-
});
|
|
1204
|
-
if (!_.isNil(styles.border)) td.style.border = styles.border;
|
|
1205
|
-
var bg = td.style.backgroundColor || styles.background;
|
|
1206
|
-
if (bg === "rgba(0, 0, 0, 0)" || _.isEmpty(bg)) {
|
|
1207
|
-
bg = undefined;
|
|
1208
|
-
}
|
|
1209
|
-
cell.bg = bg;
|
|
1210
|
-
var fontWight = td.style.fontWeight;
|
|
1211
|
-
cell.bl = (fontWight.toString() === "400" || fontWight === "normal" || _.isEmpty(fontWight)) && !_.includes(styles["font-style"], "bold") && (!styles["font-weight"] || styles["font-weight"] === "400") ? 0 : 1;
|
|
1212
|
-
cell.it = (td.style.fontStyle === "normal" || _.isEmpty(td.style.fontStyle)) && !_.includes(styles["font-style"], "italic") ? 0 : 1;
|
|
1213
|
-
cell.un = !_.includes(styles["text-decoration"], "underline") ? undefined : 1;
|
|
1214
|
-
cell.cl = !_.includes(td.innerHTML, "<s>") ? undefined : 1;
|
|
1215
|
-
var ff = td.style.fontFamily || styles["font-family"] || "";
|
|
1216
|
-
var ffs = ff.split(",");
|
|
1217
|
-
for (var i = 0; i < ffs.length; i += 1) {
|
|
1218
|
-
var fa = _.trim(ffs[i].toLowerCase());
|
|
1219
|
-
fa = locale_fontjson_1[fa];
|
|
1220
|
-
if (_.isNil(fa)) {
|
|
1221
|
-
cell.ff = 0;
|
|
1222
|
-
} else {
|
|
1223
|
-
cell.ff = fa;
|
|
1224
|
-
break;
|
|
1225
|
-
}
|
|
1226
|
-
}
|
|
1227
|
-
var fs = Math.round(styles["font-size"] ? parseInt(styles["font-size"].replace("pt", ""), 10) : parseInt(td.style.fontSize || "13", 10) * 72 / 96);
|
|
1228
|
-
cell.fs = fs;
|
|
1229
|
-
cell.fc = td.style.color || styles.color;
|
|
1230
|
-
var ht = td.style.textAlign || styles["text-align"] || "left";
|
|
1231
|
-
if (ht === "center") {
|
|
1232
|
-
cell.ht = 0;
|
|
1233
|
-
} else if (ht === "right") {
|
|
1234
|
-
cell.ht = 2;
|
|
1235
|
-
} else {
|
|
1236
|
-
cell.ht = 1;
|
|
1237
|
-
}
|
|
1238
|
-
var regex = /vertical-align:\s*(.*?);/;
|
|
1239
|
-
var vt = td.style.verticalAlign || styles["vertical-align"] || !_.isNil(allStyleList_1.td) && allStyleList_1.td.match(regex).length > 0 && allStyleList_1.td.match(regex)[1] || "top";
|
|
1240
|
-
if (vt === "middle") {
|
|
1241
|
-
cell.vt = 0;
|
|
1242
|
-
} else if (vt === "top" || vt === "text-top") {
|
|
1243
|
-
cell.vt = 1;
|
|
1244
|
-
} else {
|
|
1245
|
-
cell.vt = 2;
|
|
1246
|
-
}
|
|
1247
|
-
if ("mso-rotate" in styles) {
|
|
1248
|
-
var rt = styles["mso-rotate"];
|
|
1249
|
-
cell.rt = parseFloat(rt);
|
|
1250
|
-
}
|
|
1251
|
-
while (c < colLen_1 && !_.isNil(data_1[r_1][c])) {
|
|
1252
|
-
c += 1;
|
|
1253
|
-
}
|
|
1254
|
-
if (c === colLen_1) {
|
|
1255
|
-
return true;
|
|
1256
|
-
}
|
|
1257
|
-
if (_.isNil(data_1[r_1][c])) {
|
|
1258
|
-
data_1[r_1][c] = cell;
|
|
1259
|
-
var rowspan = parseInt(td.getAttribute("rowspan"), 10);
|
|
1260
|
-
var colspan = parseInt(td.getAttribute("colspan"), 10);
|
|
1261
|
-
if (Number.isNaN(rowspan)) {
|
|
1262
|
-
rowspan = 1;
|
|
1263
|
-
}
|
|
1264
|
-
if (Number.isNaN(colspan)) {
|
|
1265
|
-
colspan = 1;
|
|
1266
|
-
}
|
|
1267
|
-
var r_ab = ctx.luckysheet_select_save[0].row[0] + r_1;
|
|
1268
|
-
var c_ab = ctx.luckysheet_select_save[0].column[0] + c;
|
|
1269
|
-
if (pendingLink) {
|
|
1270
|
-
saveHyperlink(ctx, r_ab, c_ab, pendingLink.href, "webpage", pendingLink.display);
|
|
1271
|
-
}
|
|
1272
|
-
for (var rp = 0; rp < rowspan; rp += 1) {
|
|
1273
|
-
for (var cp = 0; cp < colspan; cp += 1) {
|
|
1274
|
-
if (rp === 0) {
|
|
1275
|
-
var bt = td.style.borderTop;
|
|
1276
|
-
if (!_.isEmpty(bt) && bt.substring(0, 3).toLowerCase() !== "0px") {
|
|
1277
|
-
var width = td.style.borderTopWidth;
|
|
1278
|
-
var type = td.style.borderTopStyle;
|
|
1279
|
-
var color = td.style.borderTopColor;
|
|
1280
|
-
var borderconfig = getQKBorder(width, type, color);
|
|
1281
|
-
if (!borderInfo_1["".concat(r_1 + rp, "_").concat(c + cp)]) {
|
|
1282
|
-
borderInfo_1["".concat(r_1 + rp, "_").concat(c + cp)] = {};
|
|
1283
|
-
}
|
|
1284
|
-
borderInfo_1["".concat(r_1 + rp, "_").concat(c + cp)].t = {
|
|
1285
|
-
style: borderconfig[0],
|
|
1286
|
-
color: borderconfig[1]
|
|
1287
|
-
};
|
|
1288
|
-
}
|
|
1289
|
-
}
|
|
1290
|
-
if (rp === rowspan - 1) {
|
|
1291
|
-
var bb = td.style.borderBottom;
|
|
1292
|
-
if (!_.isEmpty(bb) && bb.substring(0, 3).toLowerCase() !== "0px") {
|
|
1293
|
-
var width = td.style.borderBottomWidth;
|
|
1294
|
-
var type = td.style.borderBottomStyle;
|
|
1295
|
-
var color = td.style.borderBottomColor;
|
|
1296
|
-
var borderconfig = getQKBorder(width, type, color);
|
|
1297
|
-
if (!borderInfo_1["".concat(r_1 + rp, "_").concat(c + cp)]) {
|
|
1298
|
-
borderInfo_1["".concat(r_1 + rp, "_").concat(c + cp)] = {};
|
|
1299
|
-
}
|
|
1300
|
-
borderInfo_1["".concat(r_1 + rp, "_").concat(c + cp)].b = {
|
|
1301
|
-
style: borderconfig[0],
|
|
1302
|
-
color: borderconfig[1]
|
|
1303
|
-
};
|
|
1304
|
-
}
|
|
1305
|
-
}
|
|
1306
|
-
if (cp === 0) {
|
|
1307
|
-
var bl = td.style.borderLeft;
|
|
1308
|
-
if (!_.isEmpty(bl) && bl.substring(0, 3).toLowerCase() !== "0px") {
|
|
1309
|
-
var width = td.style.borderLeftWidth;
|
|
1310
|
-
var type = td.style.borderLeftStyle;
|
|
1311
|
-
var color = td.style.borderLeftColor;
|
|
1312
|
-
var borderconfig = getQKBorder(width, type, color);
|
|
1313
|
-
if (!borderInfo_1["".concat(r_1 + rp, "_").concat(c + cp)]) {
|
|
1314
|
-
borderInfo_1["".concat(r_1 + rp, "_").concat(c + cp)] = {};
|
|
1315
|
-
}
|
|
1316
|
-
borderInfo_1["".concat(r_1 + rp, "_").concat(c + cp)].l = {
|
|
1317
|
-
style: borderconfig[0],
|
|
1318
|
-
color: borderconfig[1]
|
|
1319
|
-
};
|
|
1320
|
-
}
|
|
1321
|
-
}
|
|
1322
|
-
if (cp === colspan - 1) {
|
|
1323
|
-
var br = td.style.borderLeft;
|
|
1324
|
-
if (!_.isEmpty(br) && br.substring(0, 3).toLowerCase() !== "0px") {
|
|
1325
|
-
var width = td.style.borderRightWidth;
|
|
1326
|
-
var type = td.style.borderRightStyle;
|
|
1327
|
-
var color = td.style.borderRightColor;
|
|
1328
|
-
var borderconfig = getQKBorder(width, type, color);
|
|
1329
|
-
if (!borderInfo_1["".concat(r_1 + rp, "_").concat(c + cp)]) {
|
|
1330
|
-
borderInfo_1["".concat(r_1 + rp, "_").concat(c + cp)] = {};
|
|
1331
|
-
}
|
|
1332
|
-
borderInfo_1["".concat(r_1 + rp, "_").concat(c + cp)].r = {
|
|
1333
|
-
style: borderconfig[0],
|
|
1334
|
-
color: borderconfig[1]
|
|
1335
|
-
};
|
|
1336
|
-
}
|
|
1337
|
-
}
|
|
1338
|
-
if (rp === 0 && cp === 0) {
|
|
1339
|
-
continue;
|
|
1340
|
-
}
|
|
1341
|
-
data_1[r_1 + rp][c + cp] = {
|
|
1342
|
-
mc: {
|
|
1343
|
-
r: r_ab,
|
|
1344
|
-
c: c_ab
|
|
1345
|
-
}
|
|
1346
|
-
};
|
|
1347
|
-
}
|
|
1348
|
-
}
|
|
1349
|
-
if (rowspan > 1 || colspan > 1) {
|
|
1350
|
-
var first = {
|
|
1351
|
-
rs: rowspan,
|
|
1352
|
-
cs: colspan,
|
|
1353
|
-
r: r_ab,
|
|
1354
|
-
c: c_ab
|
|
1355
|
-
};
|
|
1356
|
-
data_1[r_1][c].mc = first;
|
|
1357
|
-
}
|
|
1358
|
-
}
|
|
1359
|
-
c += 1;
|
|
1360
|
-
if (c === colLen_1) {
|
|
1361
|
-
return true;
|
|
1362
|
-
}
|
|
1363
|
-
return true;
|
|
1364
|
-
});
|
|
1365
|
-
r_1 += 1;
|
|
1366
|
-
});
|
|
1367
|
-
setRowHeight(ctx, rowHeightList_1);
|
|
1368
|
-
}
|
|
1369
|
-
ctx.luckysheet_selection_range = [];
|
|
1370
|
-
pasteHandler(ctx, data_1, borderInfo_1);
|
|
1371
|
-
ele.remove();
|
|
1126
|
+
handlePastedTable(ctx, txtdata, pasteHandler);
|
|
1127
|
+
resizePastedCellsToContent(ctx);
|
|
1372
1128
|
} else if (clipboardData.files.length === 1 && clipboardData.files[0].type.indexOf("image") > -1) {} else {
|
|
1373
1129
|
txtdata = clipboardData.getData("text/plain");
|
|
1374
1130
|
var isExcelFormula = txtdata.startsWith("=");
|
|
@@ -1379,10 +1135,10 @@ export function handlePaste(ctx, e) {
|
|
|
1379
1135
|
var _txtdata = clipboardData.getData("text/html") || clipboardData.getData("text/plain");
|
|
1380
1136
|
var embedUrl = sanitizeDuneUrl(_txtdata);
|
|
1381
1137
|
if (embedUrl) {
|
|
1382
|
-
var last = (
|
|
1138
|
+
var last = (_q = ctx.luckysheet_select_save) === null || _q === void 0 ? void 0 : _q[ctx.luckysheet_select_save.length - 1];
|
|
1383
1139
|
if (last) {
|
|
1384
|
-
var rowIndex = (
|
|
1385
|
-
var colIndex = (
|
|
1140
|
+
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;
|
|
1141
|
+
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;
|
|
1386
1142
|
var left = colIndex === 0 ? 0 : ctx.visibledatacolumn[colIndex - 1];
|
|
1387
1143
|
var top_1 = rowIndex === 0 ? 0 : ctx.visibledatarow[rowIndex + 5];
|
|
1388
1144
|
ctx.showDunePreview = {
|
|
@@ -1395,6 +1151,7 @@ export function handlePaste(ctx, e) {
|
|
|
1395
1151
|
}
|
|
1396
1152
|
}
|
|
1397
1153
|
}
|
|
1154
|
+
resizePastedCellsToContent(ctx);
|
|
1398
1155
|
}
|
|
1399
1156
|
}
|
|
1400
1157
|
} else if (ctx.luckysheetCellUpdate.length > 0) {
|
|
@@ -1407,6 +1164,7 @@ export function handlePaste(ctx, e) {
|
|
|
1407
1164
|
if (text) {
|
|
1408
1165
|
document.execCommand("insertText", false, text);
|
|
1409
1166
|
parseAsLinkIfUrl(text, ctx);
|
|
1167
|
+
resizePastedCellsToContent(ctx);
|
|
1410
1168
|
}
|
|
1411
1169
|
}
|
|
1412
1170
|
}
|
package/es/modules/toolbar.js
CHANGED
|
@@ -15,8 +15,8 @@ import { showLinkCard } from "./hyperlink";
|
|
|
15
15
|
import { cfSplitRange } from "./conditionalFormat";
|
|
16
16
|
import { getCellTextInfo } from "./text";
|
|
17
17
|
export function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_st, col_ed, canvas) {
|
|
18
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
|
|
19
|
-
var
|
|
18
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
|
|
19
|
+
var _z;
|
|
20
20
|
if (_.isNil(d) || _.isNil(attr)) {
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
@@ -29,10 +29,13 @@ export function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_
|
|
|
29
29
|
var cell = d[r][c];
|
|
30
30
|
var value = void 0;
|
|
31
31
|
if (_.isPlainObject(cell)) {
|
|
32
|
-
value = (cell === null || cell === void 0 ? void 0 : cell.v) || ((_b = (_a = cell === null || cell === void 0 ? void 0 : cell.ct) === null || _a === void 0 ? void 0 : _a.s[0]) === null ||
|
|
32
|
+
value = (cell === null || cell === void 0 ? void 0 : cell.v) || ((_c = (_b = (_a = cell === null || cell === void 0 ? void 0 : cell.ct) === null || _a === void 0 ? void 0 : _a.s) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.v);
|
|
33
33
|
} else {
|
|
34
34
|
value = cell;
|
|
35
35
|
}
|
|
36
|
+
if (_.isNil(value)) {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
36
39
|
if (foucsStatus !== "@" && isRealNum(value)) {
|
|
37
40
|
value = Number(value);
|
|
38
41
|
}
|
|
@@ -53,12 +56,12 @@ export function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_
|
|
|
53
56
|
cell.ct.fa = foucsStatus;
|
|
54
57
|
cell.ct.t = type;
|
|
55
58
|
cell.v = String(value);
|
|
56
|
-
cell.fc = cell.fc || ((
|
|
57
|
-
cell.bl = cell.bl || ((
|
|
58
|
-
cell.it = cell.it || ((
|
|
59
|
-
cell.un = cell.un || ((
|
|
60
|
-
cell.fs = cell.fs || ((
|
|
61
|
-
cell.cl = cell.cl || ((
|
|
59
|
+
cell.fc = cell.fc || ((_f = (_e = (_d = cell.ct) === null || _d === void 0 ? void 0 : _d.s) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.fc);
|
|
60
|
+
cell.bl = cell.bl || ((_j = (_h = (_g = cell.ct) === null || _g === void 0 ? void 0 : _g.s) === null || _h === void 0 ? void 0 : _h[0]) === null || _j === void 0 ? void 0 : _j.bl);
|
|
61
|
+
cell.it = cell.it || ((_m = (_l = (_k = cell.ct) === null || _k === void 0 ? void 0 : _k.s) === null || _l === void 0 ? void 0 : _l[0]) === null || _m === void 0 ? void 0 : _m.it);
|
|
62
|
+
cell.un = cell.un || ((_q = (_p = (_o = cell.ct) === null || _o === void 0 ? void 0 : _o.s) === null || _p === void 0 ? void 0 : _p[0]) === null || _q === void 0 ? void 0 : _q.un);
|
|
63
|
+
cell.fs = cell.fs || ((_t = (_s = (_r = cell.ct) === null || _r === void 0 ? void 0 : _r.s) === null || _s === void 0 ? void 0 : _s[0]) === null || _t === void 0 ? void 0 : _t.fs);
|
|
64
|
+
cell.cl = cell.cl || ((_w = (_v = (_u = cell.ct) === null || _u === void 0 ? void 0 : _u.s) === null || _v === void 0 ? void 0 : _v[0]) === null || _w === void 0 ? void 0 : _w.cl);
|
|
62
65
|
} else {
|
|
63
66
|
d[r][c] = {
|
|
64
67
|
ct: {
|
|
@@ -124,9 +127,9 @@ export function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_
|
|
|
124
127
|
if (value && _.isPlainObject(value)) {
|
|
125
128
|
updateInlineStringFormatOutside(value, attr, foucsStatus);
|
|
126
129
|
value[attr] = foucsStatus;
|
|
127
|
-
(
|
|
130
|
+
(_z = ctx.luckysheetfile[sheetIndex]).config || (_z.config = {});
|
|
128
131
|
var cfg = ctx.luckysheetfile[sheetIndex].config;
|
|
129
|
-
var cellWidth = ((
|
|
132
|
+
var cellWidth = ((_x = cfg.columnlen) === null || _x === void 0 ? void 0 : _x[c]) || ctx.luckysheetfile[sheetIndex].defaultColWidth;
|
|
130
133
|
if (attr === "fs" && canvas) {
|
|
131
134
|
var textInfo = getCellTextInfo(d[r][c], canvas, ctx, {
|
|
132
135
|
r: r,
|
|
@@ -135,7 +138,7 @@ export function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_
|
|
|
135
138
|
});
|
|
136
139
|
if (!textInfo) continue;
|
|
137
140
|
var rowHeight = _.round(textInfo.textHeightAll);
|
|
138
|
-
var currentRowHeight = ((
|
|
141
|
+
var currentRowHeight = ((_y = cfg.rowlen) === null || _y === void 0 ? void 0 : _y[r]) || ctx.luckysheetfile[sheetIndex].defaultRowHeight || 19;
|
|
139
142
|
if (!_.isUndefined(rowHeight) && rowHeight > currentRowHeight && (!cfg.customHeight || cfg.customHeight[r] !== 1)) {
|
|
140
143
|
if (_.isUndefined(cfg.rowlen)) cfg.rowlen = {};
|
|
141
144
|
_.set(cfg, "rowlen.".concat(r), rowHeight);
|
package/es/modules/validation.js
CHANGED
|
@@ -22,7 +22,7 @@ export function isHexValue(str) {
|
|
|
22
22
|
return /^0x?[a-fA-F0-9]+$/.test(str);
|
|
23
23
|
}
|
|
24
24
|
export function isRealNum(val) {
|
|
25
|
-
if (isHexValue(val.toString())) {
|
|
25
|
+
if (isHexValue(val === null || val === void 0 ? void 0 : val.toString())) {
|
|
26
26
|
return false;
|
|
27
27
|
}
|
|
28
28
|
if (_.isNil(val) || val.toString().replace(/\s/g, "") === "") {
|
|
@@ -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;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { DEFAULT_FONT_SIZE } from "../paste-table-helpers";
|
|
2
|
+
import { getSheetIndex } from "../utils";
|
|
3
|
+
import { getFlowdata } from "../context";
|
|
4
|
+
import { setRowHeight } from "../api";
|
|
5
|
+
var DEFAULT_FONT_FAMILY = "Helvetica Neue, system-ui, Roboto, Lato, Segoe UI, Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Arial, sans-serif";
|
|
6
|
+
var getColumnWidth = function getColumnWidth(colIndex, ctx, sheetFile) {
|
|
7
|
+
var _a, _b, _c, _d;
|
|
8
|
+
var defaultColumnWidth = (_a = ctx.defaultcollen) !== null && _a !== void 0 ? _a : 73;
|
|
9
|
+
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;
|
|
10
|
+
};
|
|
11
|
+
var isCellWrapped = function isCellWrapped(cell) {
|
|
12
|
+
return Number(cell === null || cell === void 0 ? void 0 : cell.tb) === 1;
|
|
13
|
+
};
|
|
14
|
+
var getCellDisplayText = function getCellDisplayText(cell) {
|
|
15
|
+
var _a, _b;
|
|
16
|
+
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;
|
|
17
|
+
if (text == null && ((_b = cell === null || cell === void 0 ? void 0 : cell.ct) === null || _b === void 0 ? void 0 : _b.t) === "inlineStr") {
|
|
18
|
+
text = (cell.ct.s || []).map(function (s) {
|
|
19
|
+
return s.v;
|
|
20
|
+
}).join("");
|
|
21
|
+
}
|
|
22
|
+
return text == null ? "" : String(text);
|
|
23
|
+
};
|
|
24
|
+
var applyFontOnMeasurer = function applyFontOnMeasurer(cell, cellSizeMeasurer) {
|
|
25
|
+
var _a, _b;
|
|
26
|
+
var fontSizePx = (_a = cell === null || cell === void 0 ? void 0 : cell.fs) !== null && _a !== void 0 ? _a : DEFAULT_FONT_SIZE;
|
|
27
|
+
var fontFamily = (_b = cell === null || cell === void 0 ? void 0 : cell.ff) !== null && _b !== void 0 ? _b : DEFAULT_FONT_FAMILY;
|
|
28
|
+
var fontWeight = (cell === null || cell === void 0 ? void 0 : cell.bl) === 1 ? "700" : "400";
|
|
29
|
+
var fontStyle = (cell === null || cell === void 0 ? void 0 : cell.it) === 1 ? "italic" : "normal";
|
|
30
|
+
cellSizeMeasurer.style.fontSize = "".concat(fontSizePx, "px");
|
|
31
|
+
cellSizeMeasurer.style.fontFamily = fontFamily;
|
|
32
|
+
cellSizeMeasurer.style.fontWeight = fontWeight;
|
|
33
|
+
cellSizeMeasurer.style.fontStyle = fontStyle;
|
|
34
|
+
return fontSizePx;
|
|
35
|
+
};
|
|
36
|
+
export function calculateRangeCellSize(ctx, sheetId, startRow, endRow, startCol, endCol, maxColumnWidth) {
|
|
37
|
+
var _a, _b, _c;
|
|
38
|
+
if (maxColumnWidth === void 0) {
|
|
39
|
+
maxColumnWidth = 1200;
|
|
40
|
+
}
|
|
41
|
+
var sheetIndex = getSheetIndex(ctx, sheetId);
|
|
42
|
+
var sheetFile = ctx.luckysheetfile[sheetIndex];
|
|
43
|
+
var gridData = getFlowdata(ctx) || sheetFile.data;
|
|
44
|
+
var maxRowHeights = {};
|
|
45
|
+
var maxColumnWidths = {};
|
|
46
|
+
var cellSizeMeasurer = document.getElementById("fs-cell-measurer");
|
|
47
|
+
if (!cellSizeMeasurer) {
|
|
48
|
+
cellSizeMeasurer = document.createElement("div");
|
|
49
|
+
cellSizeMeasurer.id = "fs-cell-measurer";
|
|
50
|
+
Object.assign(cellSizeMeasurer.style, {
|
|
51
|
+
position: "fixed",
|
|
52
|
+
left: "-99999px",
|
|
53
|
+
top: "-99999px",
|
|
54
|
+
visibility: "hidden",
|
|
55
|
+
lineHeight: "1.3",
|
|
56
|
+
whiteSpace: "normal",
|
|
57
|
+
wordBreak: "normal",
|
|
58
|
+
overflowWrap: "break-word"
|
|
59
|
+
});
|
|
60
|
+
document.body.appendChild(cellSizeMeasurer);
|
|
61
|
+
}
|
|
62
|
+
var defaultRowHeight = (_a = sheetFile.defaultRowHeight) !== null && _a !== void 0 ? _a : 19;
|
|
63
|
+
for (var col = startCol; col <= endCol; col++) {
|
|
64
|
+
var requiredWidth = getColumnWidth(col, ctx, sheetFile);
|
|
65
|
+
for (var row = startRow; row <= endRow; row++) {
|
|
66
|
+
var cell = (_b = gridData === null || gridData === void 0 ? void 0 : gridData[row]) === null || _b === void 0 ? void 0 : _b[col];
|
|
67
|
+
if ((cell === null || cell === void 0 ? void 0 : cell.mc) && cell.mc.rs == null) continue;
|
|
68
|
+
var text = getCellDisplayText(cell);
|
|
69
|
+
applyFontOnMeasurer(cell, cellSizeMeasurer);
|
|
70
|
+
cellSizeMeasurer.style.whiteSpace = "pre";
|
|
71
|
+
cellSizeMeasurer.style.width = "auto";
|
|
72
|
+
cellSizeMeasurer.textContent = text;
|
|
73
|
+
var intrinsicWidth = Math.ceil(cellSizeMeasurer.scrollWidth + 12);
|
|
74
|
+
if (intrinsicWidth > requiredWidth) requiredWidth = intrinsicWidth;
|
|
75
|
+
}
|
|
76
|
+
maxColumnWidths[col] = Math.min(requiredWidth, maxColumnWidth);
|
|
77
|
+
}
|
|
78
|
+
for (var row = startRow; row <= endRow; row++) {
|
|
79
|
+
var requiredHeight = defaultRowHeight;
|
|
80
|
+
for (var col = startCol; col <= endCol; col++) {
|
|
81
|
+
var cell = (_c = gridData === null || gridData === void 0 ? void 0 : gridData[row]) === null || _c === void 0 ? void 0 : _c[col];
|
|
82
|
+
if ((cell === null || cell === void 0 ? void 0 : cell.mc) && cell.mc.rs == null) continue;
|
|
83
|
+
var text = getCellDisplayText(cell);
|
|
84
|
+
var fontSizePx = applyFontOnMeasurer(cell, cellSizeMeasurer);
|
|
85
|
+
if (isCellWrapped(cell)) {
|
|
86
|
+
var finalColumnWidth = Math.max(getColumnWidth(col, ctx, sheetFile), maxColumnWidths[col] || 0);
|
|
87
|
+
cellSizeMeasurer.style.whiteSpace = "normal";
|
|
88
|
+
cellSizeMeasurer.style.width = "".concat(Math.max(5, finalColumnWidth - 8), "px");
|
|
89
|
+
cellSizeMeasurer.textContent = text;
|
|
90
|
+
var wrappedHeight = Math.ceil(cellSizeMeasurer.scrollHeight + 6);
|
|
91
|
+
if (wrappedHeight > requiredHeight) requiredHeight = wrappedHeight;
|
|
92
|
+
} else {
|
|
93
|
+
var singleLineHeight = Math.ceil(fontSizePx * 1.3 + 6);
|
|
94
|
+
if (singleLineHeight > requiredHeight) requiredHeight = singleLineHeight;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
maxRowHeights[row] = requiredHeight;
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
rowMax: maxRowHeights,
|
|
101
|
+
colMax: maxColumnWidths
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
export var updateSheetCellSizes = function updateSheetCellSizes(ctx, sheetIndex, measurements, maxColumnWidth) {
|
|
105
|
+
var _a;
|
|
106
|
+
if (maxColumnWidth === void 0) {
|
|
107
|
+
maxColumnWidth = 1200;
|
|
108
|
+
}
|
|
109
|
+
var sheetFile = ctx.luckysheetfile[sheetIndex];
|
|
110
|
+
if (!sheetFile) return;
|
|
111
|
+
if (!sheetFile.config) {
|
|
112
|
+
sheetFile.config = {};
|
|
113
|
+
}
|
|
114
|
+
var config = sheetFile.config;
|
|
115
|
+
if (!config.rowlen) {
|
|
116
|
+
config.rowlen = {};
|
|
117
|
+
}
|
|
118
|
+
var rowHeightsConfig = config.rowlen;
|
|
119
|
+
if (!config.columnlen) {
|
|
120
|
+
config.columnlen = {};
|
|
121
|
+
}
|
|
122
|
+
var columnWidthsConfig = config.columnlen;
|
|
123
|
+
var defaultRowHeight = (_a = sheetFile.defaultRowHeight) !== null && _a !== void 0 ? _a : 19;
|
|
124
|
+
Object.entries(measurements.rowMax).forEach(function (_a) {
|
|
125
|
+
var _b;
|
|
126
|
+
var rowIndexString = _a[0],
|
|
127
|
+
requiredHeight = _a[1];
|
|
128
|
+
var rowIndex = Number(rowIndexString);
|
|
129
|
+
var currentHeight = (_b = rowHeightsConfig[rowIndex]) !== null && _b !== void 0 ? _b : defaultRowHeight;
|
|
130
|
+
if (requiredHeight > currentHeight) {
|
|
131
|
+
rowHeightsConfig[rowIndex] = requiredHeight;
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
Object.entries(measurements.colMax).forEach(function (_a) {
|
|
135
|
+
var _b;
|
|
136
|
+
var colIndexString = _a[0],
|
|
137
|
+
requiredWidth = _a[1];
|
|
138
|
+
var colIndex = Number(colIndexString);
|
|
139
|
+
var currentWidth = (_b = columnWidthsConfig[colIndex]) !== null && _b !== void 0 ? _b : 0;
|
|
140
|
+
var cappedWidth = Math.min(requiredWidth, maxColumnWidth);
|
|
141
|
+
if (cappedWidth > currentWidth) {
|
|
142
|
+
columnWidthsConfig[colIndex] = cappedWidth;
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
setRowHeight(ctx, rowHeightsConfig);
|
|
146
|
+
};
|