@fileverse-dev/fortune-core 1.1.45 → 1.1.47

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.
@@ -1,7 +1,7 @@
1
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
2
  import _ from "lodash";
3
3
  import { getFlowdata } from "../context";
4
- import { getSheetIndex, indexToColumnChar, rgbToHex } from "../utils";
4
+ import { getSheetIndex, indexToColumnChar, rgbToHex, processArray, getContentInParentheses } from "../utils";
5
5
  import { checkCF, getComputeMap } from "./ConditionFormat";
6
6
  import { getFailureText, validateCellData } from "./dataVerification";
7
7
  import { genarate, update } from "./format";
@@ -93,7 +93,8 @@ export function getCellValue(r, c, data, attr) {
93
93
  return retv;
94
94
  }
95
95
  export function setCellValue(ctx, r, c, d, v) {
96
- var _a, _b, _c, _d, _e, _f;
96
+ var _a, _b, _c, _d, _e, _f, _g;
97
+ console.log("setCellValue", r, c, v);
97
98
  if (_.isNil(d)) {
98
99
  d = getFlowdata(ctx);
99
100
  }
@@ -127,10 +128,12 @@ export function setCellValue(ctx, r, c, d, v) {
127
128
  vupdate = v;
128
129
  }
129
130
  var commaPresent = false;
131
+ var decimalPresent = false;
130
132
  if (vupdate && typeof vupdate === "string" && vupdate.includes(",")) {
131
133
  commaPresent = vupdate.includes(",");
134
+ decimalPresent = vupdate.includes(".");
132
135
  var removeCommasValidated = function removeCommasValidated(str) {
133
- return /^[\d,]+$/.test(str) ? str === null || str === void 0 ? void 0 : str.replace(/,/g, "") : str;
136
+ return /^[\d,\.]+$/.test(str) ? str === null || str === void 0 ? void 0 : str.replace(/,/g, "") : str;
134
137
  };
135
138
  vupdate = removeCommasValidated(vupdate);
136
139
  }
@@ -271,15 +274,20 @@ export function setCellValue(ctx, r, c, d, v) {
271
274
  }
272
275
  }
273
276
  cell.v = vupdate;
277
+ var strValue = String(vupdate);
274
278
  var format = void 0;
275
- if (String(vupdate).includes(".")) {
276
- format = "#,##0.00";
277
- } else if (commaPresent) {
278
- format = "#,##0.00";
279
+ var hasDecimal = strValue.includes(".");
280
+ var hasComma = commaPresent;
281
+ if (hasDecimal) {
282
+ var decimalCount = ((_g = strValue.split(".")[1]) === null || _g === void 0 ? void 0 : _g.length) || 0;
283
+ format = hasComma ? "#,##0.".concat("0".repeat(decimalCount)) : "0.".concat("0".repeat(decimalCount));
284
+ } else if (hasComma) {
285
+ format = "#,##0";
279
286
  } else {
280
287
  format = "0";
281
288
  }
282
- cell.m = update(format, cell.v);
289
+ cell.m = v.m ? v.m : update(format, cell.v);
290
+ console.log("cell.m", cell.m, format, vupdate, v);
283
291
  cell.ht = 2;
284
292
  cell.ct = {
285
293
  fa: format,
@@ -592,6 +600,7 @@ export function updateCell(ctx, r, c, $input, value, canvas) {
592
600
  if (!isCurInline) {
593
601
  if (_.isString(value) && value.slice(0, 1) === "=" && value.length > 1) {
594
602
  var v = execfunction(ctx, value, r, c, undefined, undefined, true);
603
+ console.log("v", v, value);
595
604
  isRunExecFunction = false;
596
605
  curv = _.cloneDeep(((_c = d === null || d === void 0 ? void 0 : d[r]) === null || _c === void 0 ? void 0 : _c[c]) || {});
597
606
  curv.v = v[1], curv.f = v[2];
@@ -663,6 +672,21 @@ export function updateCell(ctx, r, c, $input, value, canvas) {
663
672
  v: v[1],
664
673
  f: v[2]
665
674
  };
675
+ if (/^[\d.,]+$/.test(value.v)) {
676
+ var args = getContentInParentheses(value === null || value === void 0 ? void 0 : value.f).split(",");
677
+ var cellRefs = args.map(function (arg) {
678
+ return arg.trim().toUpperCase();
679
+ });
680
+ var formatted = processArray(cellRefs, d, flowdata);
681
+ if (formatted) {
682
+ value.m = update(formatted, value.v);
683
+ value.ct = {
684
+ fa: formatted,
685
+ t: "n"
686
+ };
687
+ }
688
+ value.ht = 2;
689
+ }
666
690
  if (v.length === 4 && v[3].type === "sparklines") {
667
691
  var curCalv = v[3].data;
668
692
  if (_.isArray(curCalv) && !_.isPlainObject(curCalv[0])) {
@@ -19,3 +19,5 @@ export declare function isAllowEdit(ctx: Context, range?: Sheet["luckysheet_sele
19
19
  export declare function isAllowEditReadOnly(ctx: Context, range?: Sheet["luckysheet_select_save"]): boolean;
20
20
  export declare function isLetterNumberPattern(str: string): boolean;
21
21
  export declare function removeLastSpan(htmlString: string): string;
22
+ export declare function getContentInParentheses(str: string | null): string | null;
23
+ export declare function processArray(cellReferences: any, d: any, flowData: any): undefined;
package/es/utils/index.js CHANGED
@@ -209,4 +209,90 @@ export function removeLastSpan(htmlString) {
209
209
  lastSpan.remove();
210
210
  }
211
211
  return container.innerHTML;
212
+ }
213
+ export function getContentInParentheses(str) {
214
+ if (!str) return null;
215
+ var match = str.match(/\(([^)]+)\)/);
216
+ return match ? match[1] : null;
217
+ }
218
+ export function processArray(cellReferences, d, flowData) {
219
+ function isValidCellReference(cell) {
220
+ var cellPattern = /^[A-Za-z]+\d+$/;
221
+ return cellPattern.test(cell);
222
+ }
223
+ function parseCellReference(cell) {
224
+ var match = cell.match(/^([A-Za-z]+)(\d+)$/);
225
+ if (!match) return null;
226
+ var letters = match[1].toLowerCase();
227
+ var number = parseInt(match[2], 10);
228
+ var col = 0;
229
+ for (var i = 0; i < letters.length; i += 1) {
230
+ col = col * 26 + (letters.charCodeAt(i) - "a".charCodeAt(0) + 1);
231
+ }
232
+ col -= 1;
233
+ var row = number - 1;
234
+ return {
235
+ letters: letters,
236
+ number: number,
237
+ col: col,
238
+ row: row
239
+ };
240
+ }
241
+ var validCellReferences = cellReferences.filter(function (cellRef) {
242
+ if (cellRef.includes(":")) {
243
+ var _a = cellRef.split(":"),
244
+ startCell = _a[0],
245
+ endCell = _a[1];
246
+ return isValidCellReference(startCell.trim()) && isValidCellReference(endCell.trim());
247
+ }
248
+ return isValidCellReference(cellRef.trim());
249
+ });
250
+ var expandedCellReferences = [];
251
+ validCellReferences.forEach(function (cellRef) {
252
+ if (cellRef.includes(":")) {
253
+ var _a = cellRef.split(":"),
254
+ startCell = _a[0],
255
+ endCell = _a[1];
256
+ var startParsed = parseCellReference(startCell.trim());
257
+ var endParsed = parseCellReference(endCell.trim());
258
+ if (!startParsed || !endParsed) return;
259
+ for (var row = startParsed.number; row <= endParsed.number; row += 1) {
260
+ for (var col = startParsed.col; col <= endParsed.col; col += 1) {
261
+ var letters = "";
262
+ var tempCol = col + 1;
263
+ while (tempCol > 0) {
264
+ tempCol -= 1;
265
+ letters = String.fromCharCode("A".charCodeAt(0) + tempCol % 26) + letters;
266
+ tempCol = Math.floor(tempCol / 26);
267
+ }
268
+ var cellName = letters + row;
269
+ expandedCellReferences.push(cellName);
270
+ }
271
+ }
272
+ } else {
273
+ expandedCellReferences.push(cellRef.toUpperCase());
274
+ }
275
+ });
276
+ var coordinates = [];
277
+ expandedCellReferences.forEach(function (cell) {
278
+ var parsed = parseCellReference(cell);
279
+ if (parsed) {
280
+ coordinates.push([parsed.row, parsed.col]);
281
+ console.log("".concat(cell, " -> [").concat(parsed.row, ", ").concat(parsed.col, "]"));
282
+ }
283
+ });
284
+ var formated;
285
+ coordinates.forEach(function (coord) {
286
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
287
+ var row = coord[0],
288
+ col = coord[1];
289
+ if (row >= 0 && row < d.length && col >= 0 && col < d[row].length) {
290
+ if (((_b = (_a = flowData === null || flowData === void 0 ? void 0 : flowData[row][col]) === null || _a === void 0 ? void 0 : _a.ct) === null || _b === void 0 ? void 0 : _b.fa) && ((_e = (_d = (_c = flowData === null || flowData === void 0 ? void 0 : flowData[row][col]) === null || _c === void 0 ? void 0 : _c.ct) === null || _d === void 0 ? void 0 : _d.fa) === null || _e === void 0 ? void 0 : _e.includes("#,##0"))) {
291
+ formated = "#,##0";
292
+ } else if (((_g = (_f = flowData === null || flowData === void 0 ? void 0 : flowData[row][col]) === null || _f === void 0 ? void 0 : _f.ct) === null || _g === void 0 ? void 0 : _g.fa) && ((_k = (_j = (_h = flowData === null || flowData === void 0 ? void 0 : flowData[row][col]) === null || _h === void 0 ? void 0 : _h.ct) === null || _j === void 0 ? void 0 : _j.fa) === null || _k === void 0 ? void 0 : _k.includes("#,##0.00"))) {
293
+ formated = "#,##0.00";
294
+ }
295
+ }
296
+ });
297
+ return formated;
212
298
  }
@@ -123,7 +123,8 @@ function getCellValue(r, c, data, attr) {
123
123
  return retv;
124
124
  }
125
125
  function setCellValue(ctx, r, c, d, v) {
126
- var _a, _b, _c, _d, _e, _f;
126
+ var _a, _b, _c, _d, _e, _f, _g;
127
+ console.log("setCellValue", r, c, v);
127
128
  if (_lodash.default.isNil(d)) {
128
129
  d = (0, _context.getFlowdata)(ctx);
129
130
  }
@@ -157,10 +158,12 @@ function setCellValue(ctx, r, c, d, v) {
157
158
  vupdate = v;
158
159
  }
159
160
  var commaPresent = false;
161
+ var decimalPresent = false;
160
162
  if (vupdate && typeof vupdate === "string" && vupdate.includes(",")) {
161
163
  commaPresent = vupdate.includes(",");
164
+ decimalPresent = vupdate.includes(".");
162
165
  var removeCommasValidated = function removeCommasValidated(str) {
163
- return /^[\d,]+$/.test(str) ? str === null || str === void 0 ? void 0 : str.replace(/,/g, "") : str;
166
+ return /^[\d,\.]+$/.test(str) ? str === null || str === void 0 ? void 0 : str.replace(/,/g, "") : str;
164
167
  };
165
168
  vupdate = removeCommasValidated(vupdate);
166
169
  }
@@ -301,15 +304,20 @@ function setCellValue(ctx, r, c, d, v) {
301
304
  }
302
305
  }
303
306
  cell.v = vupdate;
307
+ var strValue = String(vupdate);
304
308
  var format = void 0;
305
- if (String(vupdate).includes(".")) {
306
- format = "#,##0.00";
307
- } else if (commaPresent) {
308
- format = "#,##0.00";
309
+ var hasDecimal = strValue.includes(".");
310
+ var hasComma = commaPresent;
311
+ if (hasDecimal) {
312
+ var decimalCount = ((_g = strValue.split(".")[1]) === null || _g === void 0 ? void 0 : _g.length) || 0;
313
+ format = hasComma ? "#,##0.".concat("0".repeat(decimalCount)) : "0.".concat("0".repeat(decimalCount));
314
+ } else if (hasComma) {
315
+ format = "#,##0";
309
316
  } else {
310
317
  format = "0";
311
318
  }
312
- cell.m = (0, _format.update)(format, cell.v);
319
+ cell.m = v.m ? v.m : (0, _format.update)(format, cell.v);
320
+ console.log("cell.m", cell.m, format, vupdate, v);
313
321
  cell.ht = 2;
314
322
  cell.ct = {
315
323
  fa: format,
@@ -622,6 +630,7 @@ function updateCell(ctx, r, c, $input, value, canvas) {
622
630
  if (!isCurInline) {
623
631
  if (_lodash.default.isString(value) && value.slice(0, 1) === "=" && value.length > 1) {
624
632
  var v = (0, _formula.execfunction)(ctx, value, r, c, undefined, undefined, true);
633
+ console.log("v", v, value);
625
634
  isRunExecFunction = false;
626
635
  curv = _lodash.default.cloneDeep(((_c = d === null || d === void 0 ? void 0 : d[r]) === null || _c === void 0 ? void 0 : _c[c]) || {});
627
636
  curv.v = v[1], curv.f = v[2];
@@ -693,6 +702,21 @@ function updateCell(ctx, r, c, $input, value, canvas) {
693
702
  v: v[1],
694
703
  f: v[2]
695
704
  };
705
+ if (/^[\d.,]+$/.test(value.v)) {
706
+ var args = (0, _utils.getContentInParentheses)(value === null || value === void 0 ? void 0 : value.f).split(",");
707
+ var cellRefs = args.map(function (arg) {
708
+ return arg.trim().toUpperCase();
709
+ });
710
+ var formatted = (0, _utils.processArray)(cellRefs, d, flowdata);
711
+ if (formatted) {
712
+ value.m = (0, _format.update)(formatted, value.v);
713
+ value.ct = {
714
+ fa: formatted,
715
+ t: "n"
716
+ };
717
+ }
718
+ value.ht = 2;
719
+ }
696
720
  if (v.length === 4 && v[3].type === "sparklines") {
697
721
  var curCalv = v[3].data;
698
722
  if (_lodash.default.isArray(curCalv) && !_lodash.default.isPlainObject(curCalv[0])) {
@@ -19,3 +19,5 @@ export declare function isAllowEdit(ctx: Context, range?: Sheet["luckysheet_sele
19
19
  export declare function isAllowEditReadOnly(ctx: Context, range?: Sheet["luckysheet_select_save"]): boolean;
20
20
  export declare function isLetterNumberPattern(str: string): boolean;
21
21
  export declare function removeLastSpan(htmlString: string): string;
22
+ export declare function getContentInParentheses(str: string | null): string | null;
23
+ export declare function processArray(cellReferences: any, d: any, flowData: any): undefined;
@@ -20,13 +20,16 @@ var _exportNames = {
20
20
  isAllowEdit: true,
21
21
  isAllowEditReadOnly: true,
22
22
  isLetterNumberPattern: true,
23
- removeLastSpan: true
23
+ removeLastSpan: true,
24
+ getContentInParentheses: true,
25
+ processArray: true
24
26
  };
25
27
  exports.chatatABC = chatatABC;
26
28
  exports.columnCharToIndex = columnCharToIndex;
27
29
  exports.escapeHTMLTag = escapeHTMLTag;
28
30
  exports.escapeScriptTag = escapeScriptTag;
29
31
  exports.generateRandomSheetName = generateRandomSheetName;
32
+ exports.getContentInParentheses = getContentInParentheses;
30
33
  exports.getNowDateTime = getNowDateTime;
31
34
  exports.getRegExpStr = getRegExpStr;
32
35
  exports.getSheetByIndex = getSheetByIndex;
@@ -36,6 +39,7 @@ exports.indexToColumnChar = indexToColumnChar;
36
39
  exports.isAllowEdit = isAllowEdit;
37
40
  exports.isAllowEditReadOnly = isAllowEditReadOnly;
38
41
  exports.isLetterNumberPattern = isLetterNumberPattern;
42
+ exports.processArray = processArray;
39
43
  exports.removeLastSpan = removeLastSpan;
40
44
  exports.replaceHtml = replaceHtml;
41
45
  exports.rgbToHex = rgbToHex;
@@ -273,4 +277,90 @@ function removeLastSpan(htmlString) {
273
277
  lastSpan.remove();
274
278
  }
275
279
  return container.innerHTML;
280
+ }
281
+ function getContentInParentheses(str) {
282
+ if (!str) return null;
283
+ var match = str.match(/\(([^)]+)\)/);
284
+ return match ? match[1] : null;
285
+ }
286
+ function processArray(cellReferences, d, flowData) {
287
+ function isValidCellReference(cell) {
288
+ var cellPattern = /^[A-Za-z]+\d+$/;
289
+ return cellPattern.test(cell);
290
+ }
291
+ function parseCellReference(cell) {
292
+ var match = cell.match(/^([A-Za-z]+)(\d+)$/);
293
+ if (!match) return null;
294
+ var letters = match[1].toLowerCase();
295
+ var number = parseInt(match[2], 10);
296
+ var col = 0;
297
+ for (var i = 0; i < letters.length; i += 1) {
298
+ col = col * 26 + (letters.charCodeAt(i) - "a".charCodeAt(0) + 1);
299
+ }
300
+ col -= 1;
301
+ var row = number - 1;
302
+ return {
303
+ letters: letters,
304
+ number: number,
305
+ col: col,
306
+ row: row
307
+ };
308
+ }
309
+ var validCellReferences = cellReferences.filter(function (cellRef) {
310
+ if (cellRef.includes(":")) {
311
+ var _a = cellRef.split(":"),
312
+ startCell = _a[0],
313
+ endCell = _a[1];
314
+ return isValidCellReference(startCell.trim()) && isValidCellReference(endCell.trim());
315
+ }
316
+ return isValidCellReference(cellRef.trim());
317
+ });
318
+ var expandedCellReferences = [];
319
+ validCellReferences.forEach(function (cellRef) {
320
+ if (cellRef.includes(":")) {
321
+ var _a = cellRef.split(":"),
322
+ startCell = _a[0],
323
+ endCell = _a[1];
324
+ var startParsed = parseCellReference(startCell.trim());
325
+ var endParsed = parseCellReference(endCell.trim());
326
+ if (!startParsed || !endParsed) return;
327
+ for (var row = startParsed.number; row <= endParsed.number; row += 1) {
328
+ for (var col = startParsed.col; col <= endParsed.col; col += 1) {
329
+ var letters = "";
330
+ var tempCol = col + 1;
331
+ while (tempCol > 0) {
332
+ tempCol -= 1;
333
+ letters = String.fromCharCode("A".charCodeAt(0) + tempCol % 26) + letters;
334
+ tempCol = Math.floor(tempCol / 26);
335
+ }
336
+ var cellName = letters + row;
337
+ expandedCellReferences.push(cellName);
338
+ }
339
+ }
340
+ } else {
341
+ expandedCellReferences.push(cellRef.toUpperCase());
342
+ }
343
+ });
344
+ var coordinates = [];
345
+ expandedCellReferences.forEach(function (cell) {
346
+ var parsed = parseCellReference(cell);
347
+ if (parsed) {
348
+ coordinates.push([parsed.row, parsed.col]);
349
+ console.log("".concat(cell, " -> [").concat(parsed.row, ", ").concat(parsed.col, "]"));
350
+ }
351
+ });
352
+ var formated;
353
+ coordinates.forEach(function (coord) {
354
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
355
+ var row = coord[0],
356
+ col = coord[1];
357
+ if (row >= 0 && row < d.length && col >= 0 && col < d[row].length) {
358
+ if (((_b = (_a = flowData === null || flowData === void 0 ? void 0 : flowData[row][col]) === null || _a === void 0 ? void 0 : _a.ct) === null || _b === void 0 ? void 0 : _b.fa) && ((_e = (_d = (_c = flowData === null || flowData === void 0 ? void 0 : flowData[row][col]) === null || _c === void 0 ? void 0 : _c.ct) === null || _d === void 0 ? void 0 : _d.fa) === null || _e === void 0 ? void 0 : _e.includes("#,##0"))) {
359
+ formated = "#,##0";
360
+ } else if (((_g = (_f = flowData === null || flowData === void 0 ? void 0 : flowData[row][col]) === null || _f === void 0 ? void 0 : _f.ct) === null || _g === void 0 ? void 0 : _g.fa) && ((_k = (_j = (_h = flowData === null || flowData === void 0 ? void 0 : flowData[row][col]) === null || _h === void 0 ? void 0 : _h.ct) === null || _j === void 0 ? void 0 : _j.fa) === null || _k === void 0 ? void 0 : _k.includes("#,##0.00"))) {
361
+ formated = "#,##0.00";
362
+ }
363
+ }
364
+ });
365
+ return formated;
276
366
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/fortune-core",
3
- "version": "1.1.45",
3
+ "version": "1.1.47",
4
4
  "main": "lib/index.js",
5
5
  "module": "es/index.js",
6
6
  "typings": "lib/index.d.ts",