@leankylin-sheet/core 5.2.70 → 5.2.72

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.
@@ -16,3 +16,4 @@ export declare function calculateSheetByCells(ctx: Context, cells: {
16
16
  c: number;
17
17
  id: string;
18
18
  }[]): void;
19
+ export declare function recalculateVariableCells(ctx: Context, oldVariables: any, newVariables: any): void;
package/dist/index.esm.js CHANGED
@@ -36328,10 +36328,14 @@ function execFunctionGroup(ctx, origin_r, origin_c, value, id, data) {
36328
36328
  var key = "r".concat(origin_r, "c").concat(origin_c, "i").concat(id);
36329
36329
  updateValueOjects[key] = 1;
36330
36330
  } else {
36331
+ if (!_.isNil(origin_r) && !_.isNil(origin_c)) {
36332
+ var _key = "r".concat(origin_r, "c").concat(origin_c, "i").concat(id);
36333
+ updateValueOjects[_key] = 1;
36334
+ }
36331
36335
  for (var x = 0; x < ctx.formulaCache.execFunctionExist.length; x += 1) {
36332
36336
  var cell = ctx.formulaCache.execFunctionExist[x];
36333
- var _key = "r".concat(cell.r, "c").concat(cell.c, "i").concat(cell.i);
36334
- updateValueOjects[_key] = 1;
36337
+ var _key2 = "r".concat(cell.r, "c").concat(cell.c, "i").concat(cell.i);
36338
+ updateValueOjects[_key2] = 1;
36335
36339
  }
36336
36340
  }
36337
36341
  console.time('arrayMatchCache');
@@ -36339,7 +36343,7 @@ function execFunctionGroup(ctx, origin_r, origin_c, value, id, data) {
36339
36343
  var arrayMatch = function arrayMatch(formulaArray, _formulaObjects, _updateValueOjects, func) {
36340
36344
  for (var a = 0; a < formulaArray.length; a += 1) {
36341
36345
  var range = formulaArray[a];
36342
- var cacheKey = "r".concat(range.row[0]).concat(range.row[1], "c").concat(range.column[0]).concat(range.column[1], "id").concat(range.sheetId);
36346
+ var cacheKey = "r".concat(range.row[0], "_").concat(range.row[1], "_c").concat(range.column[0], "_").concat(range.column[1], "_id_").concat(range.sheetId);
36343
36347
  if (cacheKey in arrayMatchCache) {
36344
36348
  var amc = arrayMatchCache[cacheKey];
36345
36349
  amc.forEach(function (item) {
@@ -36349,11 +36353,11 @@ function execFunctionGroup(ctx, origin_r, origin_c, value, id, data) {
36349
36353
  var functionArr = [];
36350
36354
  for (var r = range.row[0]; r <= range.row[1]; r += 1) {
36351
36355
  for (var c = range.column[0]; c <= range.column[1]; c += 1) {
36352
- var _key2 = "r".concat(r, "c").concat(c, "i").concat(range.sheetId);
36353
- func(_key2, r, c, range.sheetId);
36354
- if (_formulaObjects && _key2 in _formulaObjects || _updateValueOjects && _key2 in _updateValueOjects) {
36356
+ var _key3 = "r".concat(r, "c").concat(c, "i").concat(range.sheetId);
36357
+ func(_key3, r, c, range.sheetId);
36358
+ if (_formulaObjects && _key3 in _formulaObjects || _updateValueOjects && _key3 in _updateValueOjects) {
36355
36359
  functionArr.push({
36356
- key: _key2,
36360
+ key: _key3,
36357
36361
  r: r,
36358
36362
  c: c,
36359
36363
  sheetId: range.sheetId
@@ -46794,11 +46798,11 @@ function copySheet(ctx, sheetId, hooks) {
46794
46798
  (_hooks$onCopySheet = hooks.onCopySheet) === null || _hooks$onCopySheet === void 0 ? void 0 : _hooks$onCopySheet.call(hooks, sheetId, copyId);
46795
46799
  }
46796
46800
  function calculateSheetFromula(ctx, id, isrefresh) {
46797
- console.time("calcTime:all}");
46801
+ console.time("calcTime:all");
46798
46802
  execFunctionGroup(ctx, null, null, null, undefined, [], true);
46799
46803
  groupValuesRefresh(ctx);
46800
46804
  ctx.formulaCache.execFunctionGlobalData = null;
46801
- console.timeEnd("calcTime:".concat(id));
46805
+ console.timeEnd("calcTime:all");
46802
46806
  }
46803
46807
  function updateFunctionGroupBySheetId(ctx, id) {
46804
46808
  var _ctx$luckysheetfile$i, _ctx$luckysheetfile$i2, _ctx$luckysheetfile$i3;
@@ -46919,6 +46923,79 @@ function calculateSheetByCells(ctx, cells) {
46919
46923
  }
46920
46924
  console.timeEnd("calculateSheetByCellsTime");
46921
46925
  }
46926
+ function getVariableValue(variables, sheetId, name) {
46927
+ var _variables$sheetId;
46928
+ if (sheetId != null && (variables === null || variables === void 0 ? void 0 : (_variables$sheetId = variables[sheetId]) === null || _variables$sheetId === void 0 ? void 0 : _variables$sheetId[name]) !== undefined) {
46929
+ return variables[sheetId][name];
46930
+ }
46931
+ return variables === null || variables === void 0 ? void 0 : variables[name];
46932
+ }
46933
+ function recalculateVariableCells(ctx, oldVariables, newVariables) {
46934
+ var fileList = ctx.luckysheetfile;
46935
+ var needUpdateCells = [];
46936
+ var _loop2 = function _loop2() {
46937
+ var file = fileList[fIndex];
46938
+ var sheetId = file.id;
46939
+ var _file$calcChain2 = file.calcChain,
46940
+ calcChain = _file$calcChain2 === void 0 ? [] : _file$calcChain2;
46941
+ for (var index = 0; index < calcChain.length; index += 1) {
46942
+ var _file$data2, _file$data2$_r;
46943
+ var _calcChain$index = calcChain[index],
46944
+ _r3 = _calcChain$index.r,
46945
+ _c3 = _calcChain$index.c;
46946
+ var _cell = (_file$data2 = file.data) === null || _file$data2 === void 0 ? void 0 : (_file$data2$_r = _file$data2[_r3]) === null || _file$data2$_r === void 0 ? void 0 : _file$data2$_r[_c3];
46947
+ if (!(_cell === null || _cell === void 0 ? void 0 : _cell.f)) {
46948
+ continue;
46949
+ }
46950
+ var varNames = _cell.f.match(/\{\{.*?\}\}/g);
46951
+ if (!varNames) {
46952
+ continue;
46953
+ }
46954
+ var changed = varNames.some(function (name) {
46955
+ return !_.isEqual(getVariableValue(oldVariables, sheetId, name), getVariableValue(newVariables, sheetId, name));
46956
+ });
46957
+ if (changed) {
46958
+ needUpdateCells.push({
46959
+ r: _r3,
46960
+ c: _c3,
46961
+ i: sheetId
46962
+ });
46963
+ }
46964
+ }
46965
+ };
46966
+ for (var fIndex = 0; fIndex < fileList.length; fIndex += 1) {
46967
+ _loop2();
46968
+ }
46969
+ if (needUpdateCells.length === 0) {
46970
+ return;
46971
+ }
46972
+ for (var k = 0; k < needUpdateCells.length; k += 1) {
46973
+ var _file$data, _file$data$r;
46974
+ var _needUpdateCells$k = needUpdateCells[k],
46975
+ r = _needUpdateCells$k.r,
46976
+ c = _needUpdateCells$k.c,
46977
+ id = _needUpdateCells$k.i;
46978
+ var fileIndex = getSheetIndex(ctx, id);
46979
+ if (fileIndex == null) {
46980
+ continue;
46981
+ }
46982
+ var file = ctx.luckysheetfile[fileIndex];
46983
+ var cell = (_file$data = file.data) === null || _file$data === void 0 ? void 0 : (_file$data$r = _file$data[r]) === null || _file$data$r === void 0 ? void 0 : _file$data$r[c];
46984
+ if (!(cell === null || cell === void 0 ? void 0 : cell.f)) {
46985
+ continue;
46986
+ }
46987
+ var result = execfunction(ctx, cell.f, r, c, id, false, true);
46988
+ setCellValue(ctx, r, c, file.data, {
46989
+ v: result[1],
46990
+ f: result[2]
46991
+ });
46992
+ }
46993
+ ctx.formulaCache.execFunctionExist = needUpdateCells;
46994
+ ctx.formulaCache.execFunctionExist.reverse();
46995
+ execFunctionGroup(ctx, null, null, null, null, undefined, false, true);
46996
+ groupValuesRefresh(ctx);
46997
+ ctx.formulaCache.execFunctionGlobalData = null;
46998
+ }
46922
46999
 
46923
47000
  var imageProps = {
46924
47001
  defaultWidth: 144,
@@ -48981,6 +49058,8 @@ function autoSelectionFormula(ctx, cellInput, fxInput, formula, cache) {
48981
49058
  execFunctionGroup(ctx, null, null, null, null, flowdata, false, false);
48982
49059
  ctx.formulaCache.execFunctionGlobalData = null;
48983
49060
  updateFunctionGroup(ctx);
49061
+ } else {
49062
+ ctx.formulaCache.execFunctionExist = undefined;
48984
49063
  }
48985
49064
  }
48986
49065
  function cancelPaintModel(ctx) {
@@ -56338,6 +56417,7 @@ function setCellValue$1(ctx, row, column, value, cellInput) {
56338
56417
  var formatList = FORMAT_LIST;
56339
56418
  if (value == null || value.toString().length === 0) {
56340
56419
  delFunctionGroup(ctx, row, column);
56420
+ execFunctionGroup(ctx, row, column, value, sheet.id, data, false, false);
56341
56421
  setCellValue(ctx, row, column, data, value);
56342
56422
  } else if (value instanceof Object) {
56343
56423
  var _data$row;
@@ -56408,6 +56488,7 @@ function setCellValue$1(ctx, row, column, value, cellInput) {
56408
56488
  updateCell(ctx, row, column, cellInput, value);
56409
56489
  } else {
56410
56490
  delFunctionGroup(ctx, row, column);
56491
+ execFunctionGroup(ctx, row, column, value, sheet.id, data, false, false);
56411
56492
  setCellValue(ctx, row, column, data, value);
56412
56493
  }
56413
56494
  }
@@ -57235,6 +57316,7 @@ var index = /*#__PURE__*/Object.freeze({
57235
57316
  updateFunctionGroupBySheetId: updateFunctionGroupBySheetId,
57236
57317
  updateFunctionGroup: updateFunctionGroup,
57237
57318
  calculateSheetByCells: calculateSheetByCells,
57319
+ recalculateVariableCells: recalculateVariableCells,
57238
57320
  addSheet: addSheet$1,
57239
57321
  deleteSheet: deleteSheet$1,
57240
57322
  updateSheet: updateSheet$1,
package/dist/index.js CHANGED
@@ -36338,10 +36338,14 @@ function execFunctionGroup(ctx, origin_r, origin_c, value, id, data) {
36338
36338
  var key = "r".concat(origin_r, "c").concat(origin_c, "i").concat(id);
36339
36339
  updateValueOjects[key] = 1;
36340
36340
  } else {
36341
+ if (!___default['default'].isNil(origin_r) && !___default['default'].isNil(origin_c)) {
36342
+ var _key = "r".concat(origin_r, "c").concat(origin_c, "i").concat(id);
36343
+ updateValueOjects[_key] = 1;
36344
+ }
36341
36345
  for (var x = 0; x < ctx.formulaCache.execFunctionExist.length; x += 1) {
36342
36346
  var cell = ctx.formulaCache.execFunctionExist[x];
36343
- var _key = "r".concat(cell.r, "c").concat(cell.c, "i").concat(cell.i);
36344
- updateValueOjects[_key] = 1;
36347
+ var _key2 = "r".concat(cell.r, "c").concat(cell.c, "i").concat(cell.i);
36348
+ updateValueOjects[_key2] = 1;
36345
36349
  }
36346
36350
  }
36347
36351
  console.time('arrayMatchCache');
@@ -36349,7 +36353,7 @@ function execFunctionGroup(ctx, origin_r, origin_c, value, id, data) {
36349
36353
  var arrayMatch = function arrayMatch(formulaArray, _formulaObjects, _updateValueOjects, func) {
36350
36354
  for (var a = 0; a < formulaArray.length; a += 1) {
36351
36355
  var range = formulaArray[a];
36352
- var cacheKey = "r".concat(range.row[0]).concat(range.row[1], "c").concat(range.column[0]).concat(range.column[1], "id").concat(range.sheetId);
36356
+ var cacheKey = "r".concat(range.row[0], "_").concat(range.row[1], "_c").concat(range.column[0], "_").concat(range.column[1], "_id_").concat(range.sheetId);
36353
36357
  if (cacheKey in arrayMatchCache) {
36354
36358
  var amc = arrayMatchCache[cacheKey];
36355
36359
  amc.forEach(function (item) {
@@ -36359,11 +36363,11 @@ function execFunctionGroup(ctx, origin_r, origin_c, value, id, data) {
36359
36363
  var functionArr = [];
36360
36364
  for (var r = range.row[0]; r <= range.row[1]; r += 1) {
36361
36365
  for (var c = range.column[0]; c <= range.column[1]; c += 1) {
36362
- var _key2 = "r".concat(r, "c").concat(c, "i").concat(range.sheetId);
36363
- func(_key2, r, c, range.sheetId);
36364
- if (_formulaObjects && _key2 in _formulaObjects || _updateValueOjects && _key2 in _updateValueOjects) {
36366
+ var _key3 = "r".concat(r, "c").concat(c, "i").concat(range.sheetId);
36367
+ func(_key3, r, c, range.sheetId);
36368
+ if (_formulaObjects && _key3 in _formulaObjects || _updateValueOjects && _key3 in _updateValueOjects) {
36365
36369
  functionArr.push({
36366
- key: _key2,
36370
+ key: _key3,
36367
36371
  r: r,
36368
36372
  c: c,
36369
36373
  sheetId: range.sheetId
@@ -46804,11 +46808,11 @@ function copySheet(ctx, sheetId, hooks) {
46804
46808
  (_hooks$onCopySheet = hooks.onCopySheet) === null || _hooks$onCopySheet === void 0 ? void 0 : _hooks$onCopySheet.call(hooks, sheetId, copyId);
46805
46809
  }
46806
46810
  function calculateSheetFromula(ctx, id, isrefresh) {
46807
- console.time("calcTime:all}");
46811
+ console.time("calcTime:all");
46808
46812
  execFunctionGroup(ctx, null, null, null, undefined, [], true);
46809
46813
  groupValuesRefresh(ctx);
46810
46814
  ctx.formulaCache.execFunctionGlobalData = null;
46811
- console.timeEnd("calcTime:".concat(id));
46815
+ console.timeEnd("calcTime:all");
46812
46816
  }
46813
46817
  function updateFunctionGroupBySheetId(ctx, id) {
46814
46818
  var _ctx$luckysheetfile$i, _ctx$luckysheetfile$i2, _ctx$luckysheetfile$i3;
@@ -46929,6 +46933,79 @@ function calculateSheetByCells(ctx, cells) {
46929
46933
  }
46930
46934
  console.timeEnd("calculateSheetByCellsTime");
46931
46935
  }
46936
+ function getVariableValue(variables, sheetId, name) {
46937
+ var _variables$sheetId;
46938
+ if (sheetId != null && (variables === null || variables === void 0 ? void 0 : (_variables$sheetId = variables[sheetId]) === null || _variables$sheetId === void 0 ? void 0 : _variables$sheetId[name]) !== undefined) {
46939
+ return variables[sheetId][name];
46940
+ }
46941
+ return variables === null || variables === void 0 ? void 0 : variables[name];
46942
+ }
46943
+ function recalculateVariableCells(ctx, oldVariables, newVariables) {
46944
+ var fileList = ctx.luckysheetfile;
46945
+ var needUpdateCells = [];
46946
+ var _loop2 = function _loop2() {
46947
+ var file = fileList[fIndex];
46948
+ var sheetId = file.id;
46949
+ var _file$calcChain2 = file.calcChain,
46950
+ calcChain = _file$calcChain2 === void 0 ? [] : _file$calcChain2;
46951
+ for (var index = 0; index < calcChain.length; index += 1) {
46952
+ var _file$data2, _file$data2$_r;
46953
+ var _calcChain$index = calcChain[index],
46954
+ _r3 = _calcChain$index.r,
46955
+ _c3 = _calcChain$index.c;
46956
+ var _cell = (_file$data2 = file.data) === null || _file$data2 === void 0 ? void 0 : (_file$data2$_r = _file$data2[_r3]) === null || _file$data2$_r === void 0 ? void 0 : _file$data2$_r[_c3];
46957
+ if (!(_cell === null || _cell === void 0 ? void 0 : _cell.f)) {
46958
+ continue;
46959
+ }
46960
+ var varNames = _cell.f.match(/\{\{.*?\}\}/g);
46961
+ if (!varNames) {
46962
+ continue;
46963
+ }
46964
+ var changed = varNames.some(function (name) {
46965
+ return !___default['default'].isEqual(getVariableValue(oldVariables, sheetId, name), getVariableValue(newVariables, sheetId, name));
46966
+ });
46967
+ if (changed) {
46968
+ needUpdateCells.push({
46969
+ r: _r3,
46970
+ c: _c3,
46971
+ i: sheetId
46972
+ });
46973
+ }
46974
+ }
46975
+ };
46976
+ for (var fIndex = 0; fIndex < fileList.length; fIndex += 1) {
46977
+ _loop2();
46978
+ }
46979
+ if (needUpdateCells.length === 0) {
46980
+ return;
46981
+ }
46982
+ for (var k = 0; k < needUpdateCells.length; k += 1) {
46983
+ var _file$data, _file$data$r;
46984
+ var _needUpdateCells$k = needUpdateCells[k],
46985
+ r = _needUpdateCells$k.r,
46986
+ c = _needUpdateCells$k.c,
46987
+ id = _needUpdateCells$k.i;
46988
+ var fileIndex = getSheetIndex(ctx, id);
46989
+ if (fileIndex == null) {
46990
+ continue;
46991
+ }
46992
+ var file = ctx.luckysheetfile[fileIndex];
46993
+ var cell = (_file$data = file.data) === null || _file$data === void 0 ? void 0 : (_file$data$r = _file$data[r]) === null || _file$data$r === void 0 ? void 0 : _file$data$r[c];
46994
+ if (!(cell === null || cell === void 0 ? void 0 : cell.f)) {
46995
+ continue;
46996
+ }
46997
+ var result = execfunction(ctx, cell.f, r, c, id, false, true);
46998
+ setCellValue(ctx, r, c, file.data, {
46999
+ v: result[1],
47000
+ f: result[2]
47001
+ });
47002
+ }
47003
+ ctx.formulaCache.execFunctionExist = needUpdateCells;
47004
+ ctx.formulaCache.execFunctionExist.reverse();
47005
+ execFunctionGroup(ctx, null, null, null, null, undefined, false, true);
47006
+ groupValuesRefresh(ctx);
47007
+ ctx.formulaCache.execFunctionGlobalData = null;
47008
+ }
46932
47009
 
46933
47010
  var imageProps = {
46934
47011
  defaultWidth: 144,
@@ -48991,6 +49068,8 @@ function autoSelectionFormula(ctx, cellInput, fxInput, formula, cache) {
48991
49068
  execFunctionGroup(ctx, null, null, null, null, flowdata, false, false);
48992
49069
  ctx.formulaCache.execFunctionGlobalData = null;
48993
49070
  updateFunctionGroup(ctx);
49071
+ } else {
49072
+ ctx.formulaCache.execFunctionExist = undefined;
48994
49073
  }
48995
49074
  }
48996
49075
  function cancelPaintModel(ctx) {
@@ -56348,6 +56427,7 @@ function setCellValue$1(ctx, row, column, value, cellInput) {
56348
56427
  var formatList = FORMAT_LIST;
56349
56428
  if (value == null || value.toString().length === 0) {
56350
56429
  delFunctionGroup(ctx, row, column);
56430
+ execFunctionGroup(ctx, row, column, value, sheet.id, data, false, false);
56351
56431
  setCellValue(ctx, row, column, data, value);
56352
56432
  } else if (value instanceof Object) {
56353
56433
  var _data$row;
@@ -56418,6 +56498,7 @@ function setCellValue$1(ctx, row, column, value, cellInput) {
56418
56498
  updateCell(ctx, row, column, cellInput, value);
56419
56499
  } else {
56420
56500
  delFunctionGroup(ctx, row, column);
56501
+ execFunctionGroup(ctx, row, column, value, sheet.id, data, false, false);
56421
56502
  setCellValue(ctx, row, column, data, value);
56422
56503
  }
56423
56504
  }
@@ -57245,6 +57326,7 @@ var index = /*#__PURE__*/Object.freeze({
57245
57326
  updateFunctionGroupBySheetId: updateFunctionGroupBySheetId,
57246
57327
  updateFunctionGroup: updateFunctionGroup,
57247
57328
  calculateSheetByCells: calculateSheetByCells,
57329
+ recalculateVariableCells: recalculateVariableCells,
57248
57330
  addSheet: addSheet$1,
57249
57331
  deleteSheet: deleteSheet$1,
57250
57332
  updateSheet: updateSheet$1,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leankylin-sheet/core",
3
- "version": "5.2.70",
3
+ "version": "5.2.72",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.esm.js",
6
6
  "typings": "dist/index.d.ts",
@@ -13,7 +13,7 @@
13
13
  "build": "father-build"
14
14
  },
15
15
  "dependencies": {
16
- "@leankylin-sheet/formula-parser": "5.2.70",
16
+ "@leankylin-sheet/formula-parser": "5.2.72",
17
17
  "dayjs": "^1.11.0",
18
18
  "immer": "^9.0.12",
19
19
  "lodash": "^4.17.21",