@fileverse-dev/fortune-core 1.1.45 → 1.1.46

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";
@@ -127,8 +127,10 @@ export function setCellValue(ctx, r, c, d, v) {
127
127
  vupdate = v;
128
128
  }
129
129
  var commaPresent = false;
130
+ var decimalPresent = false;
130
131
  if (vupdate && typeof vupdate === "string" && vupdate.includes(",")) {
131
132
  commaPresent = vupdate.includes(",");
133
+ decimalPresent = vupdate.includes(".");
132
134
  var removeCommasValidated = function removeCommasValidated(str) {
133
135
  return /^[\d,]+$/.test(str) ? str === null || str === void 0 ? void 0 : str.replace(/,/g, "") : str;
134
136
  };
@@ -274,12 +276,15 @@ export function setCellValue(ctx, r, c, d, v) {
274
276
  var format = void 0;
275
277
  if (String(vupdate).includes(".")) {
276
278
  format = "#,##0.00";
277
- } else if (commaPresent) {
279
+ } else if (commaPresent && decimalPresent) {
278
280
  format = "#,##0.00";
281
+ } else if (commaPresent) {
282
+ format = '#,##0';
279
283
  } else {
280
284
  format = "0";
281
285
  }
282
- cell.m = update(format, cell.v);
286
+ cell.m = v.m ? v.m : update(format, cell.v);
287
+ console.log("cell.m", cell.m, format, vupdate, v);
283
288
  cell.ht = 2;
284
289
  cell.ct = {
285
290
  fa: format,
@@ -592,6 +597,7 @@ export function updateCell(ctx, r, c, $input, value, canvas) {
592
597
  if (!isCurInline) {
593
598
  if (_.isString(value) && value.slice(0, 1) === "=" && value.length > 1) {
594
599
  var v = execfunction(ctx, value, r, c, undefined, undefined, true);
600
+ console.log("v", v, value);
595
601
  isRunExecFunction = false;
596
602
  curv = _.cloneDeep(((_c = d === null || d === void 0 ? void 0 : d[r]) === null || _c === void 0 ? void 0 : _c[c]) || {});
597
603
  curv.v = v[1], curv.f = v[2];
@@ -663,6 +669,21 @@ export function updateCell(ctx, r, c, $input, value, canvas) {
663
669
  v: v[1],
664
670
  f: v[2]
665
671
  };
672
+ if (/^[\d.,]+$/.test(value.v)) {
673
+ var args = getContentInParentheses(value === null || value === void 0 ? void 0 : value.f).split(',');
674
+ var cellRefs = args.map(function (arg) {
675
+ return arg.trim().toUpperCase();
676
+ });
677
+ var formatted = processArray(cellRefs, d, flowdata);
678
+ if (formatted) {
679
+ value.m = update(formatted, value.v);
680
+ value.ct = {
681
+ fa: formatted,
682
+ t: "n"
683
+ };
684
+ }
685
+ value.ht = 2;
686
+ }
666
687
  if (v.length === 4 && v[3].type === "sparklines") {
667
688
  var curCalv = v[3].data;
668
689
  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,91 @@ 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]);
228
+ var col = 0;
229
+ for (var i = 0; i < letters.length; i++) {
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
+ } else {
248
+ return isValidCellReference(cellRef.trim());
249
+ }
250
+ });
251
+ var expandedCellReferences = [];
252
+ validCellReferences.forEach(function (cellRef) {
253
+ if (cellRef.includes(':')) {
254
+ var _a = cellRef.split(':'),
255
+ startCell = _a[0],
256
+ endCell = _a[1];
257
+ var startParsed = parseCellReference(startCell.trim());
258
+ var endParsed = parseCellReference(endCell.trim());
259
+ if (!startParsed || !endParsed) return;
260
+ for (var row = startParsed.number; row <= endParsed.number; row++) {
261
+ for (var col = startParsed.col; col <= endParsed.col; col++) {
262
+ var letters = '';
263
+ var tempCol = col + 1;
264
+ while (tempCol > 0) {
265
+ tempCol--;
266
+ letters = String.fromCharCode('A'.charCodeAt(0) + tempCol % 26) + letters;
267
+ tempCol = Math.floor(tempCol / 26);
268
+ }
269
+ var cellName = letters + row;
270
+ expandedCellReferences.push(cellName);
271
+ }
272
+ }
273
+ } else {
274
+ expandedCellReferences.push(cellRef.toUpperCase());
275
+ }
276
+ });
277
+ var coordinates = [];
278
+ expandedCellReferences.forEach(function (cell) {
279
+ var parsed = parseCellReference(cell);
280
+ if (parsed) {
281
+ coordinates.push([parsed.row, parsed.col]);
282
+ console.log("".concat(cell, " -> [").concat(parsed.row, ", ").concat(parsed.col, "]"));
283
+ }
284
+ });
285
+ var formated;
286
+ coordinates.forEach(function (coord, index) {
287
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
288
+ var row = coord[0],
289
+ col = coord[1];
290
+ if (row >= 0 && row < d.length && col >= 0 && col < d[row].length) {
291
+ 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'))) {
292
+ formated = '#,##0';
293
+ } 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'))) {
294
+ formated = '#,##0.00';
295
+ }
296
+ }
297
+ });
298
+ return formated;
212
299
  }
@@ -157,8 +157,10 @@ function setCellValue(ctx, r, c, d, v) {
157
157
  vupdate = v;
158
158
  }
159
159
  var commaPresent = false;
160
+ var decimalPresent = false;
160
161
  if (vupdate && typeof vupdate === "string" && vupdate.includes(",")) {
161
162
  commaPresent = vupdate.includes(",");
163
+ decimalPresent = vupdate.includes(".");
162
164
  var removeCommasValidated = function removeCommasValidated(str) {
163
165
  return /^[\d,]+$/.test(str) ? str === null || str === void 0 ? void 0 : str.replace(/,/g, "") : str;
164
166
  };
@@ -304,12 +306,15 @@ function setCellValue(ctx, r, c, d, v) {
304
306
  var format = void 0;
305
307
  if (String(vupdate).includes(".")) {
306
308
  format = "#,##0.00";
307
- } else if (commaPresent) {
309
+ } else if (commaPresent && decimalPresent) {
308
310
  format = "#,##0.00";
311
+ } else if (commaPresent) {
312
+ format = '#,##0';
309
313
  } else {
310
314
  format = "0";
311
315
  }
312
- cell.m = (0, _format.update)(format, cell.v);
316
+ cell.m = v.m ? v.m : (0, _format.update)(format, cell.v);
317
+ console.log("cell.m", cell.m, format, vupdate, v);
313
318
  cell.ht = 2;
314
319
  cell.ct = {
315
320
  fa: format,
@@ -622,6 +627,7 @@ function updateCell(ctx, r, c, $input, value, canvas) {
622
627
  if (!isCurInline) {
623
628
  if (_lodash.default.isString(value) && value.slice(0, 1) === "=" && value.length > 1) {
624
629
  var v = (0, _formula.execfunction)(ctx, value, r, c, undefined, undefined, true);
630
+ console.log("v", v, value);
625
631
  isRunExecFunction = false;
626
632
  curv = _lodash.default.cloneDeep(((_c = d === null || d === void 0 ? void 0 : d[r]) === null || _c === void 0 ? void 0 : _c[c]) || {});
627
633
  curv.v = v[1], curv.f = v[2];
@@ -693,6 +699,21 @@ function updateCell(ctx, r, c, $input, value, canvas) {
693
699
  v: v[1],
694
700
  f: v[2]
695
701
  };
702
+ if (/^[\d.,]+$/.test(value.v)) {
703
+ var args = (0, _utils.getContentInParentheses)(value === null || value === void 0 ? void 0 : value.f).split(',');
704
+ var cellRefs = args.map(function (arg) {
705
+ return arg.trim().toUpperCase();
706
+ });
707
+ var formatted = (0, _utils.processArray)(cellRefs, d, flowdata);
708
+ if (formatted) {
709
+ value.m = (0, _format.update)(formatted, value.v);
710
+ value.ct = {
711
+ fa: formatted,
712
+ t: "n"
713
+ };
714
+ }
715
+ value.ht = 2;
716
+ }
696
717
  if (v.length === 4 && v[3].type === "sparklines") {
697
718
  var curCalv = v[3].data;
698
719
  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,91 @@ 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]);
296
+ var col = 0;
297
+ for (var i = 0; i < letters.length; i++) {
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
+ } else {
316
+ return isValidCellReference(cellRef.trim());
317
+ }
318
+ });
319
+ var expandedCellReferences = [];
320
+ validCellReferences.forEach(function (cellRef) {
321
+ if (cellRef.includes(':')) {
322
+ var _a = cellRef.split(':'),
323
+ startCell = _a[0],
324
+ endCell = _a[1];
325
+ var startParsed = parseCellReference(startCell.trim());
326
+ var endParsed = parseCellReference(endCell.trim());
327
+ if (!startParsed || !endParsed) return;
328
+ for (var row = startParsed.number; row <= endParsed.number; row++) {
329
+ for (var col = startParsed.col; col <= endParsed.col; col++) {
330
+ var letters = '';
331
+ var tempCol = col + 1;
332
+ while (tempCol > 0) {
333
+ tempCol--;
334
+ letters = String.fromCharCode('A'.charCodeAt(0) + tempCol % 26) + letters;
335
+ tempCol = Math.floor(tempCol / 26);
336
+ }
337
+ var cellName = letters + row;
338
+ expandedCellReferences.push(cellName);
339
+ }
340
+ }
341
+ } else {
342
+ expandedCellReferences.push(cellRef.toUpperCase());
343
+ }
344
+ });
345
+ var coordinates = [];
346
+ expandedCellReferences.forEach(function (cell) {
347
+ var parsed = parseCellReference(cell);
348
+ if (parsed) {
349
+ coordinates.push([parsed.row, parsed.col]);
350
+ console.log("".concat(cell, " -> [").concat(parsed.row, ", ").concat(parsed.col, "]"));
351
+ }
352
+ });
353
+ var formated;
354
+ coordinates.forEach(function (coord, index) {
355
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
356
+ var row = coord[0],
357
+ col = coord[1];
358
+ if (row >= 0 && row < d.length && col >= 0 && col < d[row].length) {
359
+ 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'))) {
360
+ formated = '#,##0';
361
+ } 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'))) {
362
+ formated = '#,##0.00';
363
+ }
364
+ }
365
+ });
366
+ return formated;
276
367
  }
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.46",
4
4
  "main": "lib/index.js",
5
5
  "module": "es/index.js",
6
6
  "typings": "lib/index.d.ts",