@leankylin-sheet/core 5.2.71 → 5.2.73

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
@@ -36882,6 +36886,9 @@ function helpFunctionExe($editer, currSelection, ctx) {
36882
36886
  if ($prev == null) {
36883
36887
  return null;
36884
36888
  }
36889
+ if (i < 0 || i >= $span.length || !($span[i] instanceof Element)) {
36890
+ return null;
36891
+ }
36885
36892
  var funcName = null;
36886
36893
  if ($span[i].classList.contains("luckysheet-formula-text-func")) {
36887
36894
  funcName = $span[i].textContent;
@@ -36917,6 +36924,9 @@ function helpFunctionExe($editer, currSelection, ctx) {
36917
36924
  function rangeHightlightselected(ctx, $editor) {
36918
36925
  var currSelection = getrangeseleciton();
36919
36926
  if (!currSelection) return;
36927
+ if (!($editor.contains(currSelection) || $editor === currSelection) || currSelection.nodeType !== Node.ELEMENT_NODE) {
36928
+ return;
36929
+ }
36920
36930
  var currText = _.trimStart(currSelection.textContent || "");
36921
36931
  if (currText === null || currText === void 0 ? void 0 : currText.match(/^[a-zA-Z_]+$/)) {
36922
36932
  searchFunction(ctx, currText.toUpperCase());
@@ -46919,6 +46929,79 @@ function calculateSheetByCells(ctx, cells) {
46919
46929
  }
46920
46930
  console.timeEnd("calculateSheetByCellsTime");
46921
46931
  }
46932
+ function getVariableValue(variables, sheetId, name) {
46933
+ var _variables$sheetId;
46934
+ 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) {
46935
+ return variables[sheetId][name];
46936
+ }
46937
+ return variables === null || variables === void 0 ? void 0 : variables[name];
46938
+ }
46939
+ function recalculateVariableCells(ctx, oldVariables, newVariables) {
46940
+ var fileList = ctx.luckysheetfile;
46941
+ var needUpdateCells = [];
46942
+ var _loop2 = function _loop2() {
46943
+ var file = fileList[fIndex];
46944
+ var sheetId = file.id;
46945
+ var _file$calcChain2 = file.calcChain,
46946
+ calcChain = _file$calcChain2 === void 0 ? [] : _file$calcChain2;
46947
+ for (var index = 0; index < calcChain.length; index += 1) {
46948
+ var _file$data2, _file$data2$_r;
46949
+ var _calcChain$index = calcChain[index],
46950
+ _r3 = _calcChain$index.r,
46951
+ _c3 = _calcChain$index.c;
46952
+ 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];
46953
+ if (!(_cell === null || _cell === void 0 ? void 0 : _cell.f)) {
46954
+ continue;
46955
+ }
46956
+ var varNames = _cell.f.match(/\{\{.*?\}\}/g);
46957
+ if (!varNames) {
46958
+ continue;
46959
+ }
46960
+ var changed = varNames.some(function (name) {
46961
+ return !_.isEqual(getVariableValue(oldVariables, sheetId, name), getVariableValue(newVariables, sheetId, name));
46962
+ });
46963
+ if (changed) {
46964
+ needUpdateCells.push({
46965
+ r: _r3,
46966
+ c: _c3,
46967
+ i: sheetId
46968
+ });
46969
+ }
46970
+ }
46971
+ };
46972
+ for (var fIndex = 0; fIndex < fileList.length; fIndex += 1) {
46973
+ _loop2();
46974
+ }
46975
+ if (needUpdateCells.length === 0) {
46976
+ return;
46977
+ }
46978
+ for (var k = 0; k < needUpdateCells.length; k += 1) {
46979
+ var _file$data, _file$data$r;
46980
+ var _needUpdateCells$k = needUpdateCells[k],
46981
+ r = _needUpdateCells$k.r,
46982
+ c = _needUpdateCells$k.c,
46983
+ id = _needUpdateCells$k.i;
46984
+ var fileIndex = getSheetIndex(ctx, id);
46985
+ if (fileIndex == null) {
46986
+ continue;
46987
+ }
46988
+ var file = ctx.luckysheetfile[fileIndex];
46989
+ 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];
46990
+ if (!(cell === null || cell === void 0 ? void 0 : cell.f)) {
46991
+ continue;
46992
+ }
46993
+ var result = execfunction(ctx, cell.f, r, c, id, false, true);
46994
+ setCellValue(ctx, r, c, file.data, {
46995
+ v: result[1],
46996
+ f: result[2]
46997
+ });
46998
+ }
46999
+ ctx.formulaCache.execFunctionExist = needUpdateCells;
47000
+ ctx.formulaCache.execFunctionExist.reverse();
47001
+ execFunctionGroup(ctx, null, null, null, null, undefined, false, true);
47002
+ groupValuesRefresh(ctx);
47003
+ ctx.formulaCache.execFunctionGlobalData = null;
47004
+ }
46922
47005
 
46923
47006
  var imageProps = {
46924
47007
  defaultWidth: 144,
@@ -48981,6 +49064,8 @@ function autoSelectionFormula(ctx, cellInput, fxInput, formula, cache) {
48981
49064
  execFunctionGroup(ctx, null, null, null, null, flowdata, false, false);
48982
49065
  ctx.formulaCache.execFunctionGlobalData = null;
48983
49066
  updateFunctionGroup(ctx);
49067
+ } else {
49068
+ ctx.formulaCache.execFunctionExist = undefined;
48984
49069
  }
48985
49070
  }
48986
49071
  function cancelPaintModel(ctx) {
@@ -56338,6 +56423,7 @@ function setCellValue$1(ctx, row, column, value, cellInput) {
56338
56423
  var formatList = FORMAT_LIST;
56339
56424
  if (value == null || value.toString().length === 0) {
56340
56425
  delFunctionGroup(ctx, row, column);
56426
+ execFunctionGroup(ctx, row, column, value, sheet.id, data, false, false);
56341
56427
  setCellValue(ctx, row, column, data, value);
56342
56428
  } else if (value instanceof Object) {
56343
56429
  var _data$row;
@@ -56408,6 +56494,7 @@ function setCellValue$1(ctx, row, column, value, cellInput) {
56408
56494
  updateCell(ctx, row, column, cellInput, value);
56409
56495
  } else {
56410
56496
  delFunctionGroup(ctx, row, column);
56497
+ execFunctionGroup(ctx, row, column, value, sheet.id, data, false, false);
56411
56498
  setCellValue(ctx, row, column, data, value);
56412
56499
  }
56413
56500
  }
@@ -57235,6 +57322,7 @@ var index = /*#__PURE__*/Object.freeze({
57235
57322
  updateFunctionGroupBySheetId: updateFunctionGroupBySheetId,
57236
57323
  updateFunctionGroup: updateFunctionGroup,
57237
57324
  calculateSheetByCells: calculateSheetByCells,
57325
+ recalculateVariableCells: recalculateVariableCells,
57238
57326
  addSheet: addSheet$1,
57239
57327
  deleteSheet: deleteSheet$1,
57240
57328
  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
@@ -36892,6 +36896,9 @@ function helpFunctionExe($editer, currSelection, ctx) {
36892
36896
  if ($prev == null) {
36893
36897
  return null;
36894
36898
  }
36899
+ if (i < 0 || i >= $span.length || !($span[i] instanceof Element)) {
36900
+ return null;
36901
+ }
36895
36902
  var funcName = null;
36896
36903
  if ($span[i].classList.contains("luckysheet-formula-text-func")) {
36897
36904
  funcName = $span[i].textContent;
@@ -36927,6 +36934,9 @@ function helpFunctionExe($editer, currSelection, ctx) {
36927
36934
  function rangeHightlightselected(ctx, $editor) {
36928
36935
  var currSelection = getrangeseleciton();
36929
36936
  if (!currSelection) return;
36937
+ if (!($editor.contains(currSelection) || $editor === currSelection) || currSelection.nodeType !== Node.ELEMENT_NODE) {
36938
+ return;
36939
+ }
36930
36940
  var currText = ___default['default'].trimStart(currSelection.textContent || "");
36931
36941
  if (currText === null || currText === void 0 ? void 0 : currText.match(/^[a-zA-Z_]+$/)) {
36932
36942
  searchFunction(ctx, currText.toUpperCase());
@@ -46929,6 +46939,79 @@ function calculateSheetByCells(ctx, cells) {
46929
46939
  }
46930
46940
  console.timeEnd("calculateSheetByCellsTime");
46931
46941
  }
46942
+ function getVariableValue(variables, sheetId, name) {
46943
+ var _variables$sheetId;
46944
+ 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) {
46945
+ return variables[sheetId][name];
46946
+ }
46947
+ return variables === null || variables === void 0 ? void 0 : variables[name];
46948
+ }
46949
+ function recalculateVariableCells(ctx, oldVariables, newVariables) {
46950
+ var fileList = ctx.luckysheetfile;
46951
+ var needUpdateCells = [];
46952
+ var _loop2 = function _loop2() {
46953
+ var file = fileList[fIndex];
46954
+ var sheetId = file.id;
46955
+ var _file$calcChain2 = file.calcChain,
46956
+ calcChain = _file$calcChain2 === void 0 ? [] : _file$calcChain2;
46957
+ for (var index = 0; index < calcChain.length; index += 1) {
46958
+ var _file$data2, _file$data2$_r;
46959
+ var _calcChain$index = calcChain[index],
46960
+ _r3 = _calcChain$index.r,
46961
+ _c3 = _calcChain$index.c;
46962
+ 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];
46963
+ if (!(_cell === null || _cell === void 0 ? void 0 : _cell.f)) {
46964
+ continue;
46965
+ }
46966
+ var varNames = _cell.f.match(/\{\{.*?\}\}/g);
46967
+ if (!varNames) {
46968
+ continue;
46969
+ }
46970
+ var changed = varNames.some(function (name) {
46971
+ return !___default['default'].isEqual(getVariableValue(oldVariables, sheetId, name), getVariableValue(newVariables, sheetId, name));
46972
+ });
46973
+ if (changed) {
46974
+ needUpdateCells.push({
46975
+ r: _r3,
46976
+ c: _c3,
46977
+ i: sheetId
46978
+ });
46979
+ }
46980
+ }
46981
+ };
46982
+ for (var fIndex = 0; fIndex < fileList.length; fIndex += 1) {
46983
+ _loop2();
46984
+ }
46985
+ if (needUpdateCells.length === 0) {
46986
+ return;
46987
+ }
46988
+ for (var k = 0; k < needUpdateCells.length; k += 1) {
46989
+ var _file$data, _file$data$r;
46990
+ var _needUpdateCells$k = needUpdateCells[k],
46991
+ r = _needUpdateCells$k.r,
46992
+ c = _needUpdateCells$k.c,
46993
+ id = _needUpdateCells$k.i;
46994
+ var fileIndex = getSheetIndex(ctx, id);
46995
+ if (fileIndex == null) {
46996
+ continue;
46997
+ }
46998
+ var file = ctx.luckysheetfile[fileIndex];
46999
+ 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];
47000
+ if (!(cell === null || cell === void 0 ? void 0 : cell.f)) {
47001
+ continue;
47002
+ }
47003
+ var result = execfunction(ctx, cell.f, r, c, id, false, true);
47004
+ setCellValue(ctx, r, c, file.data, {
47005
+ v: result[1],
47006
+ f: result[2]
47007
+ });
47008
+ }
47009
+ ctx.formulaCache.execFunctionExist = needUpdateCells;
47010
+ ctx.formulaCache.execFunctionExist.reverse();
47011
+ execFunctionGroup(ctx, null, null, null, null, undefined, false, true);
47012
+ groupValuesRefresh(ctx);
47013
+ ctx.formulaCache.execFunctionGlobalData = null;
47014
+ }
46932
47015
 
46933
47016
  var imageProps = {
46934
47017
  defaultWidth: 144,
@@ -48991,6 +49074,8 @@ function autoSelectionFormula(ctx, cellInput, fxInput, formula, cache) {
48991
49074
  execFunctionGroup(ctx, null, null, null, null, flowdata, false, false);
48992
49075
  ctx.formulaCache.execFunctionGlobalData = null;
48993
49076
  updateFunctionGroup(ctx);
49077
+ } else {
49078
+ ctx.formulaCache.execFunctionExist = undefined;
48994
49079
  }
48995
49080
  }
48996
49081
  function cancelPaintModel(ctx) {
@@ -56348,6 +56433,7 @@ function setCellValue$1(ctx, row, column, value, cellInput) {
56348
56433
  var formatList = FORMAT_LIST;
56349
56434
  if (value == null || value.toString().length === 0) {
56350
56435
  delFunctionGroup(ctx, row, column);
56436
+ execFunctionGroup(ctx, row, column, value, sheet.id, data, false, false);
56351
56437
  setCellValue(ctx, row, column, data, value);
56352
56438
  } else if (value instanceof Object) {
56353
56439
  var _data$row;
@@ -56418,6 +56504,7 @@ function setCellValue$1(ctx, row, column, value, cellInput) {
56418
56504
  updateCell(ctx, row, column, cellInput, value);
56419
56505
  } else {
56420
56506
  delFunctionGroup(ctx, row, column);
56507
+ execFunctionGroup(ctx, row, column, value, sheet.id, data, false, false);
56421
56508
  setCellValue(ctx, row, column, data, value);
56422
56509
  }
56423
56510
  }
@@ -57245,6 +57332,7 @@ var index = /*#__PURE__*/Object.freeze({
57245
57332
  updateFunctionGroupBySheetId: updateFunctionGroupBySheetId,
57246
57333
  updateFunctionGroup: updateFunctionGroup,
57247
57334
  calculateSheetByCells: calculateSheetByCells,
57335
+ recalculateVariableCells: recalculateVariableCells,
57248
57336
  addSheet: addSheet$1,
57249
57337
  deleteSheet: deleteSheet$1,
57250
57338
  updateSheet: updateSheet$1,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leankylin-sheet/core",
3
- "version": "5.2.71",
3
+ "version": "5.2.73",
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.71",
16
+ "@leankylin-sheet/formula-parser": "5.2.73",
17
17
  "dayjs": "^1.11.0",
18
18
  "immer": "^9.0.12",
19
19
  "lodash": "^4.17.21",