@fileverse-dev/fortune-core 1.1.53-patch-1 → 1.1.53

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.
@@ -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 { pasteHtmlTableAndAutoFit } from "../paste-table-helpers";
14
13
  import { getFlowdata } from "../context";
14
+ import { locale } from "../locale";
15
15
  import { execfunction, functionCopy } from "../modules/formula";
16
- import { getdatabyselection } from "../modules/cell";
16
+ import { getdatabyselection, getQKBorder } 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,7 +21,8 @@ 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 { CFSplitRange, getCellTextInfo, sanitizeDuneUrl, saveHyperlink } from "../modules";
24
+ import { setRowHeight } from "../api";
25
+ import { CFSplitRange, sanitizeDuneUrl, saveHyperlink } from "../modules";
25
26
  import clipboard from "../modules/clipboard";
26
27
  function postPasteCut(ctx, source, target, RowlChange) {
27
28
  var execF_rc = {};
@@ -1009,75 +1010,9 @@ export function parseAsLinkIfUrl(txtdata, ctx) {
1009
1010
  }
1010
1011
  }
1011
1012
  }
1012
- function autoFitUsingGetCellTextInfo(ctx, sheetId, r1, r2, c1, c2, maxColWidth) {
1013
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
1014
- var _k, _l;
1015
- if (maxColWidth === void 0) {
1016
- maxColWidth = 1200;
1017
- }
1018
- var sheetIdx = getSheetIndex(ctx, sheetId);
1019
- if (sheetIdx == null) return;
1020
- var file = ctx.luckysheetfile[sheetIdx];
1021
- file.config || (file.config = {});
1022
- var rowlen = (_k = file.config).rowlen || (_k.rowlen = {});
1023
- var columnlen = (_l = file.config).columnlen || (_l.columnlen = {});
1024
- var defaultRowH = (_a = file.defaultRowHeight) !== null && _a !== void 0 ? _a : 19;
1025
- var defaultColW = (_b = ctx.defaultcollen) !== null && _b !== void 0 ? _b : 73;
1026
- var d = getFlowdata(ctx) || file.data;
1027
- var measureCtx = ctx.__offscreenMeasureCtx || document.createElement("canvas").getContext("2d");
1028
- ctx.__offscreenMeasureCtx = measureCtx;
1029
- var H_PAD = 8;
1030
- for (var c = c1; c <= c2; c++) {
1031
- var curW = (_c = columnlen[c]) !== null && _c !== void 0 ? _c : defaultColW;
1032
- var wantW = curW;
1033
- for (var r = r1; r <= r2; r++) {
1034
- var cell = (_d = d === null || d === void 0 ? void 0 : d[r]) === null || _d === void 0 ? void 0 : _d[c];
1035
- if ((cell === null || cell === void 0 ? void 0 : cell.mc) && cell.mc.rs == null) continue;
1036
- var tb = cell === null || cell === void 0 ? void 0 : cell.tb;
1037
- if (tb === 2 || tb === "2") continue;
1038
- var info = getCellTextInfo(cell, measureCtx, ctx, {
1039
- r: r,
1040
- c: c
1041
- }, ctx);
1042
- var w = (_e = info === null || info === void 0 ? void 0 : info.textWidthAll) !== null && _e !== void 0 ? _e : 0;
1043
- if (w + H_PAD > wantW) wantW = w + H_PAD;
1044
- }
1045
- if (wantW > curW) {
1046
- columnlen[c] = Math.min(Math.ceil(wantW), maxColWidth);
1047
- }
1048
- }
1049
- var V_PAD = 4;
1050
- for (var r = r1; r <= r2; r++) {
1051
- var curH = (_f = rowlen[r]) !== null && _f !== void 0 ? _f : defaultRowH;
1052
- var needH = curH;
1053
- for (var c = c1; c <= c2; c++) {
1054
- var cell = (_g = d === null || d === void 0 ? void 0 : d[r]) === null || _g === void 0 ? void 0 : _g[c];
1055
- if ((cell === null || cell === void 0 ? void 0 : cell.mc) && cell.mc.rs == null) continue;
1056
- var widthForCell = (_h = columnlen[c]) !== null && _h !== void 0 ? _h : defaultColW;
1057
- var info = getCellTextInfo(cell, measureCtx, ctx, {
1058
- r: r,
1059
- c: c,
1060
- cellWidth: widthForCell,
1061
- cellHeight: curH
1062
- }, ctx);
1063
- var h = (_j = info === null || info === void 0 ? void 0 : info.textHeightAll) !== null && _j !== void 0 ? _j : 0;
1064
- if (h + V_PAD > needH) needH = Math.ceil(h + V_PAD);
1065
- }
1066
- if (needH > curH) {
1067
- rowlen[r] = needH;
1068
- }
1069
- }
1070
- if (typeof window.jfrefreshgrid === "function") {
1071
- window.jfrefreshgrid(ctx, null, [{
1072
- row: [r1, r2],
1073
- column: [c1, c2]
1074
- }], true, undefined, "resize");
1075
- }
1076
- }
1077
1013
  export function handlePaste(ctx, e) {
1078
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
1014
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
1079
1015
  var allowEdit = isAllowEdit(ctx);
1080
- console.log("handlePaste -> allowEdit", "jjjj");
1081
1016
  if (!allowEdit) return;
1082
1017
  if (selectionCache.isPasteAction) {
1083
1018
  ctx.luckysheetCellUpdate = [];
@@ -1161,6 +1096,7 @@ export function handlePaste(ctx, e) {
1161
1096
  }
1162
1097
  }
1163
1098
  }
1099
+ var locale_fontjson_1 = locale(ctx).fontjson;
1164
1100
  if (((_o = (_m = ctx.hooks).beforePaste) === null || _o === void 0 ? void 0 : _o.call(_m, ctx.luckysheet_select_save, txtdata)) === false) {
1165
1101
  return;
1166
1102
  }
@@ -1172,35 +1108,256 @@ export function handlePaste(ctx, e) {
1172
1108
  } else {
1173
1109
  pasteHandlerOfCopyPaste(ctx, ctx.luckysheet_copy_save);
1174
1110
  }
1175
- var last = (_q = ctx.luckysheet_select_save) === null || _q === void 0 ? void 0 : _q[ctx.luckysheet_select_save.length - 1];
1176
- if (last) {
1177
- autoFitUsingGetCellTextInfo(ctx, ctx.currentSheetId, last.row[0], last.row[1], last.column[0], last.column[1]);
1178
- }
1179
1111
  } else if (txtdata.indexOf("fortune-copy-action-image") > -1) {} else {
1180
1112
  if (txtdata.indexOf("table") > -1) {
1181
- pasteHtmlTableAndAutoFit(ctx, txtdata, pasteHandler);
1113
+ var ele = document.createElement("div");
1114
+ ele.innerHTML = txtdata;
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 td = element;
1158
+ var className = td.className;
1159
+ var cell = {};
1160
+ var txt = td.innerText || td.innerHTML;
1161
+ if (_.trim(txt).length === 0) {
1162
+ cell.v = undefined;
1163
+ cell.m = "";
1164
+ } else {
1165
+ var mask = genarate(txt);
1166
+ cell.m = mask[0], cell.ct = mask[1], cell.v = mask[2];
1167
+ if (/^0x?[a-fA-F0-9]+$/.test(txt)) {
1168
+ cell.ct = {
1169
+ fa: "@",
1170
+ t: "s"
1171
+ };
1172
+ cell.m = txt;
1173
+ cell.v = txt;
1174
+ }
1175
+ }
1176
+ var styleString = typeof allStyleList_1[".".concat(className)] === "string" ? allStyleList_1[".".concat(className)].substring(1, allStyleList_1[".".concat(className)].length - 1).split("\n\t") : [];
1177
+ var styles = {};
1178
+ _.forEach(styleString, function (s) {
1179
+ var styleList = s.split(":");
1180
+ styles[styleList[0]] = styleList === null || styleList === void 0 ? void 0 : styleList[1].replace(";", "");
1181
+ });
1182
+ if (!_.isNil(styles.border)) td.style.border = styles.border;
1183
+ var bg = td.style.backgroundColor || styles.background;
1184
+ if (bg === "rgba(0, 0, 0, 0)" || _.isEmpty(bg)) {
1185
+ bg = undefined;
1186
+ }
1187
+ cell.bg = bg;
1188
+ var fontWight = td.style.fontWeight;
1189
+ cell.bl = (fontWight.toString() === "400" || fontWight === "normal" || _.isEmpty(fontWight)) && !_.includes(styles["font-style"], "bold") && (!styles["font-weight"] || styles["font-weight"] === "400") ? 0 : 1;
1190
+ cell.it = (td.style.fontStyle === "normal" || _.isEmpty(td.style.fontStyle)) && !_.includes(styles["font-style"], "italic") ? 0 : 1;
1191
+ cell.un = !_.includes(styles["text-decoration"], "underline") ? undefined : 1;
1192
+ cell.cl = !_.includes(td.innerHTML, "<s>") ? undefined : 1;
1193
+ var ff = td.style.fontFamily || styles["font-family"] || "";
1194
+ var ffs = ff.split(",");
1195
+ for (var i = 0; i < ffs.length; i += 1) {
1196
+ var fa = _.trim(ffs[i].toLowerCase());
1197
+ fa = locale_fontjson_1[fa];
1198
+ if (_.isNil(fa)) {
1199
+ cell.ff = 0;
1200
+ } else {
1201
+ cell.ff = fa;
1202
+ break;
1203
+ }
1204
+ }
1205
+ var fs = Math.round(styles["font-size"] ? parseInt(styles["font-size"].replace("pt", ""), 10) : parseInt(td.style.fontSize || "13", 10) * 72 / 96);
1206
+ cell.fs = fs;
1207
+ cell.fc = td.style.color || styles.color;
1208
+ var ht = td.style.textAlign || styles["text-align"] || "left";
1209
+ if (ht === "center") {
1210
+ cell.ht = 0;
1211
+ } else if (ht === "right") {
1212
+ cell.ht = 2;
1213
+ } else {
1214
+ cell.ht = 1;
1215
+ }
1216
+ var regex = /vertical-align:\s*(.*?);/;
1217
+ 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";
1218
+ if (vt === "middle") {
1219
+ cell.vt = 0;
1220
+ } else if (vt === "top" || vt === "text-top") {
1221
+ cell.vt = 1;
1222
+ } else {
1223
+ cell.vt = 2;
1224
+ }
1225
+ if ("mso-rotate" in styles) {
1226
+ var rt = styles["mso-rotate"];
1227
+ cell.rt = parseFloat(rt);
1228
+ }
1229
+ while (c < colLen_1 && !_.isNil(data_1[r_1][c])) {
1230
+ c += 1;
1231
+ }
1232
+ if (c === colLen_1) {
1233
+ return true;
1234
+ }
1235
+ if (_.isNil(data_1[r_1][c])) {
1236
+ data_1[r_1][c] = cell;
1237
+ var rowspan = parseInt(td.getAttribute("rowspan"), 10);
1238
+ var colspan = parseInt(td.getAttribute("colspan"), 10);
1239
+ if (Number.isNaN(rowspan)) {
1240
+ rowspan = 1;
1241
+ }
1242
+ if (Number.isNaN(colspan)) {
1243
+ colspan = 1;
1244
+ }
1245
+ var r_ab = ctx.luckysheet_select_save[0].row[0] + r_1;
1246
+ var c_ab = ctx.luckysheet_select_save[0].column[0] + c;
1247
+ for (var rp = 0; rp < rowspan; rp += 1) {
1248
+ for (var cp = 0; cp < colspan; cp += 1) {
1249
+ if (rp === 0) {
1250
+ var bt = td.style.borderTop;
1251
+ if (!_.isEmpty(bt) && bt.substring(0, 3).toLowerCase() !== "0px") {
1252
+ var width = td.style.borderTopWidth;
1253
+ var type = td.style.borderTopStyle;
1254
+ var color = td.style.borderTopColor;
1255
+ var borderconfig = getQKBorder(width, type, color);
1256
+ if (!borderInfo_1["".concat(r_1 + rp, "_").concat(c + cp)]) {
1257
+ borderInfo_1["".concat(r_1 + rp, "_").concat(c + cp)] = {};
1258
+ }
1259
+ borderInfo_1["".concat(r_1 + rp, "_").concat(c + cp)].t = {
1260
+ style: borderconfig[0],
1261
+ color: borderconfig[1]
1262
+ };
1263
+ }
1264
+ }
1265
+ if (rp === rowspan - 1) {
1266
+ var bb = td.style.borderBottom;
1267
+ if (!_.isEmpty(bb) && bb.substring(0, 3).toLowerCase() !== "0px") {
1268
+ var width = td.style.borderBottomWidth;
1269
+ var type = td.style.borderBottomStyle;
1270
+ var color = td.style.borderBottomColor;
1271
+ var borderconfig = getQKBorder(width, type, color);
1272
+ if (!borderInfo_1["".concat(r_1 + rp, "_").concat(c + cp)]) {
1273
+ borderInfo_1["".concat(r_1 + rp, "_").concat(c + cp)] = {};
1274
+ }
1275
+ borderInfo_1["".concat(r_1 + rp, "_").concat(c + cp)].b = {
1276
+ style: borderconfig[0],
1277
+ color: borderconfig[1]
1278
+ };
1279
+ }
1280
+ }
1281
+ if (cp === 0) {
1282
+ var bl = td.style.borderLeft;
1283
+ if (!_.isEmpty(bl) && bl.substring(0, 3).toLowerCase() !== "0px") {
1284
+ var width = td.style.borderLeftWidth;
1285
+ var type = td.style.borderLeftStyle;
1286
+ var color = td.style.borderLeftColor;
1287
+ var borderconfig = getQKBorder(width, type, color);
1288
+ if (!borderInfo_1["".concat(r_1 + rp, "_").concat(c + cp)]) {
1289
+ borderInfo_1["".concat(r_1 + rp, "_").concat(c + cp)] = {};
1290
+ }
1291
+ borderInfo_1["".concat(r_1 + rp, "_").concat(c + cp)].l = {
1292
+ style: borderconfig[0],
1293
+ color: borderconfig[1]
1294
+ };
1295
+ }
1296
+ }
1297
+ if (cp === colspan - 1) {
1298
+ var br = td.style.borderLeft;
1299
+ if (!_.isEmpty(br) && br.substring(0, 3).toLowerCase() !== "0px") {
1300
+ var width = td.style.borderRightWidth;
1301
+ var type = td.style.borderRightStyle;
1302
+ var color = td.style.borderRightColor;
1303
+ var borderconfig = getQKBorder(width, type, color);
1304
+ if (!borderInfo_1["".concat(r_1 + rp, "_").concat(c + cp)]) {
1305
+ borderInfo_1["".concat(r_1 + rp, "_").concat(c + cp)] = {};
1306
+ }
1307
+ borderInfo_1["".concat(r_1 + rp, "_").concat(c + cp)].r = {
1308
+ style: borderconfig[0],
1309
+ color: borderconfig[1]
1310
+ };
1311
+ }
1312
+ }
1313
+ if (rp === 0 && cp === 0) {
1314
+ continue;
1315
+ }
1316
+ data_1[r_1 + rp][c + cp] = {
1317
+ mc: {
1318
+ r: r_ab,
1319
+ c: c_ab
1320
+ }
1321
+ };
1322
+ }
1323
+ }
1324
+ if (rowspan > 1 || colspan > 1) {
1325
+ var first = {
1326
+ rs: rowspan,
1327
+ cs: colspan,
1328
+ r: r_ab,
1329
+ c: c_ab
1330
+ };
1331
+ data_1[r_1][c].mc = first;
1332
+ }
1333
+ }
1334
+ c += 1;
1335
+ if (c === colLen_1) {
1336
+ return true;
1337
+ }
1338
+ return true;
1339
+ });
1340
+ r_1 += 1;
1341
+ });
1342
+ setRowHeight(ctx, rowHeightList_1);
1343
+ }
1344
+ ctx.luckysheet_selection_range = [];
1345
+ pasteHandler(ctx, data_1, borderInfo_1);
1346
+ ele.remove();
1182
1347
  } else if (clipboardData.files.length === 1 && clipboardData.files[0].type.indexOf("image") > -1) {} else {
1183
1348
  txtdata = clipboardData.getData("text/plain");
1184
1349
  var isExcelFormula = txtdata.startsWith("=");
1185
1350
  if (isExcelFormula) {
1186
1351
  handleFormulaStringPaste(ctx, txtdata);
1187
- var last = (_r = ctx.luckysheet_select_save) === null || _r === void 0 ? void 0 : _r[ctx.luckysheet_select_save.length - 1];
1188
- if (last) {
1189
- autoFitUsingGetCellTextInfo(ctx, ctx.currentSheetId, last.row[0], last.row[1], last.column[0], last.column[1]);
1190
- }
1191
1352
  } else {
1192
1353
  pasteHandler(ctx, txtdata);
1193
- var last = (_s = ctx.luckysheet_select_save) === null || _s === void 0 ? void 0 : _s[ctx.luckysheet_select_save.length - 1];
1194
- if (last) {
1195
- autoFitUsingGetCellTextInfo(ctx, ctx.currentSheetId, last.row[0], last.row[1], last.column[0], last.column[1]);
1196
- }
1197
1354
  var _txtdata = clipboardData.getData("text/html") || clipboardData.getData("text/plain");
1198
1355
  var embedUrl = sanitizeDuneUrl(_txtdata);
1199
1356
  if (embedUrl) {
1200
- var _last = (_t = ctx.luckysheet_select_save) === null || _t === void 0 ? void 0 : _t[ctx.luckysheet_select_save.length - 1];
1201
- if (_last) {
1202
- var rowIndex = (_w = (_u = _last.row_focus) !== null && _u !== void 0 ? _u : (_v = _last.row) === null || _v === void 0 ? void 0 : _v[0]) !== null && _w !== void 0 ? _w : 0;
1203
- var colIndex = (_z = (_x = _last.column_focus) !== null && _x !== void 0 ? _x : (_y = _last.column) === null || _y === void 0 ? void 0 : _y[0]) !== null && _z !== void 0 ? _z : 0;
1357
+ var last = (_r = ctx.luckysheet_select_save) === null || _r === void 0 ? void 0 : _r[ctx.luckysheet_select_save.length - 1];
1358
+ if (last) {
1359
+ var rowIndex = (_u = (_s = last.row_focus) !== null && _s !== void 0 ? _s : (_t = last.row) === null || _t === void 0 ? void 0 : _t[0]) !== null && _u !== void 0 ? _u : 0;
1360
+ var colIndex = (_x = (_v = last.column_focus) !== null && _v !== void 0 ? _v : (_w = last.column) === null || _w === void 0 ? void 0 : _w[0]) !== null && _x !== void 0 ? _x : 0;
1204
1361
  var left = colIndex === 0 ? 0 : ctx.visibledatacolumn[colIndex - 1];
1205
1362
  var top_1 = rowIndex === 0 ? 0 : ctx.visibledatarow[rowIndex + 5];
1206
1363
  ctx.showDunePreview = {
@@ -28,7 +28,7 @@ import { locale } from "../locale";
28
28
  import { colors } from "./color";
29
29
  import { colLocation, mousePosition, rowLocation } from "./location";
30
30
  import { cancelFunctionrangeSelected, seletedHighlistByindex, spillSortResult } from ".";
31
- import { isLetterNumberPattern, removeLastSpan } from "../utils/index";
31
+ import { isLetterNumberPattern, removeLastSpan } from "./../utils/index";
32
32
  var functionHTMLIndex = 0;
33
33
  var rangeIndexes = [];
34
34
  var operatorPriority = {