@univerjs-pro/engine-formula-rust 1.0.0-rc.0 → 1.0.0

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.
package/lib/cjs/index.cjs CHANGED
@@ -262,6 +262,11 @@ var XLSX_WORKBOOK_CALCULATION_RESOURCE = "UNIVER_CLI_XLSX_WORKBOOK_CALCULATION_P
262
262
  "sheet.mutation.set-col-visible",
263
263
  "sheet.mutation.set-row-hidden",
264
264
  "sheet.mutation.set-row-visible",
265
+ "sheet.mutation.set-table-filter",
266
+ "sheet.mutation.set-filter-range",
267
+ "sheet.mutation.set-filter-criteria",
268
+ "sheet.mutation.remove-filter",
269
+ "sheet.mutation.re-calc-filter",
265
270
  "sheet.mutation.set-worksheet-name",
266
271
  "sheet.mutation.reorder-range",
267
272
  "sheet.mutation.set-worksheet-row-count",
@@ -335,11 +340,18 @@ function serializeRuntimeWorkbookSnapshots(workbooks) {
335
340
  }
336
341
  function serializeRuntimeWorkbookSnapshot(input) {
337
342
  let { snapshot } = input, sheetOrder = snapshot.sheetOrder?.length > 0 ? snapshot.sheetOrder : Object.keys(snapshot.sheets ?? {}), calculation = serializeCalculation(snapshot), precisionAsDisplayed = calculation?.fullPrecision === !1, sheets = sheetOrder.map(
338
- (sheetId) => serializeSheetSnapshot(sheetId, snapshot.sheets?.[sheetId], snapshot.styles, precisionAsDisplayed)
343
+ (sheetId) => serializeSheetSnapshot(
344
+ sheetId,
345
+ snapshot.sheets?.[sheetId],
346
+ snapshot.styles,
347
+ precisionAsDisplayed,
348
+ input.styleResolver
349
+ )
339
350
  ).filter((sheet) => sheet != null);
340
351
  return {
341
352
  unitId: input.unitId || snapshot.id,
342
353
  name: snapshot.name,
354
+ dateSystem: snapshot.dateSystem,
343
355
  sheets,
344
356
  ...calculation ? { calculation } : {},
345
357
  resources: serializeResources(snapshot),
@@ -407,13 +419,16 @@ function otherFormulaDataToUnitOtherData(otherFormulaData) {
407
419
  if (!colMap) return;
408
420
  let row = Number(rowKey), rowData = {};
409
421
  formulaData[row] = rowData, Object.entries(colMap).forEach(([colKey, value]) => {
410
- rowData[Number(colKey)] = [[cellDataFromRustValue(value)]];
422
+ rowData[Number(colKey)] = otherFormulaResultFromRustValue(value);
411
423
  });
412
424
  });
413
425
  });
414
426
  });
415
427
  }), unitOtherData;
416
428
  }
429
+ function otherFormulaResultFromRustValue(value) {
430
+ return Array.isArray(value) ? value.map((row) => (Array.isArray(row) ? row : [row]).map((cell) => cellDataFromRustValue(cell))) : [[cellDataFromRustValue(value)]];
431
+ }
417
432
  function createFormulaProjectionDesyncSignal(reason, error, mutationId) {
418
433
  return {
419
434
  reason,
@@ -947,19 +962,19 @@ function extractDefinedNames(snapshot) {
947
962
  }
948
963
  return {};
949
964
  }
950
- function serializeSheetSnapshot(sheetId, sheet, styles, precisionAsDisplayed) {
965
+ function serializeSheetSnapshot(sheetId, sheet, styles, precisionAsDisplayed, styleResolver) {
951
966
  return sheet ? {
952
967
  sheetId: sheet.id ?? sheetId,
953
968
  name: sheet.name,
954
969
  rowCount: sheet.rowCount ?? 0,
955
970
  columnCount: sheet.columnCount ?? 0,
956
971
  transitionEvaluation: sheet.transitionEvaluation === !0,
957
- cellData: serializeCellData(sheet.cellData, styles, precisionAsDisplayed),
972
+ cellData: serializeCellData(sheet.cellData, styles, precisionAsDisplayed, styleResolver),
958
973
  rowData: serializeVisibilityData(sheet.rowData),
959
974
  columnData: serializeVisibilityData(sheet.columnData)
960
975
  } : null;
961
976
  }
962
- function serializeCellData(cellData = {}, styles, precisionAsDisplayed = !1) {
977
+ function serializeCellData(cellData = {}, styles, precisionAsDisplayed = !1, styleResolver) {
963
978
  let result = {}, rawCellData = cellData instanceof import_core.ObjectMatrix ? cellData.getMatrix() : cellData;
964
979
  for (let [rowKey, row] of Object.entries(rawCellData ?? {})) {
965
980
  if (!row)
@@ -968,13 +983,15 @@ function serializeCellData(cellData = {}, styles, precisionAsDisplayed = !1) {
968
983
  for (let [colKey, cell] of Object.entries(row)) {
969
984
  if (!cell || typeof cell != "object")
970
985
  continue;
971
- let cellRecord = cell, value = {};
972
- if ("v" in cellRecord && (value.v = cellRecord.v), typeof cellRecord.t == "number" && (value.t = cellRecord.t), "p" in cellRecord && (value.p = cellRecord.p), typeof cellRecord.f == "string" && (value.f = cellRecord.f), typeof cellRecord.si == "string" && (value.si = cellRecord.si), typeof cellRecord.ref == "string") {
986
+ let cellRecord = cell, resolvedStyle = styleResolver?.getStyleByCell(cell), value = {};
987
+ if ("v" in cellRecord && (value.v = cellRecord.v), typeof cellRecord.t == "number" && (value.t = cellRecord.t), "p" in cellRecord && (value.p = cellRecord.p), typeof cellRecord.f == "string" && (value.f = cellRecord.f), typeof cellRecord.ft == "number" && (value.ft = cellRecord.ft), (cellRecord.fd === import_core.BooleanNumber.FALSE || cellRecord.fd === import_core.BooleanNumber.TRUE) && (value.fd = cellRecord.fd), typeof cellRecord.si == "string" && (value.si = cellRecord.si), typeof cellRecord.ref == "string") {
973
988
  let hasFormula = typeof cellRecord.f == "string" && cellRecord.f.length > 0;
974
989
  typeof cellRecord.si == "string" || hasFormula && isLegacyArrayFormulaCell(cellRecord) ? value.ref = cellRecord.ref : hasFormula && (value.dynamicArrayRef = cellRecord.ref);
975
990
  }
976
- if (typeof cellRecord.xf == "string" && (value.xf = cellRecord.xf), "s" in cellRecord && (value.s = cellRecord.s), precisionAsDisplayed && typeof cellRecord.f == "string") {
977
- let displayPrecision = inferDisplayPrecision(cellRecord.s, styles);
991
+ typeof cellRecord.xf == "string" && (value.xf = cellRecord.xf), "s" in cellRecord && (value.s = cellRecord.s);
992
+ let numberFormat = resolveNumberFormatPattern(cellRecord.s, styles, resolvedStyle);
993
+ if (numberFormat !== void 0 && (value.numberFormat = numberFormat), precisionAsDisplayed && typeof cellRecord.f == "string") {
994
+ let displayPrecision = inferDisplayPrecision(cellRecord.s, styles, resolvedStyle);
978
995
  displayPrecision !== void 0 && (value.displayPrecision = displayPrecision);
979
996
  }
980
997
  Object.keys(value).length > 0 && (serializedRow[Number(colKey)] = value);
@@ -997,23 +1014,19 @@ function serializeCellDataInRanges(cellData, ranges) {
997
1014
  return result;
998
1015
  }
999
1016
  function isLegacyArrayFormulaCell(cell) {
1000
- let custom = cell.custom;
1001
- if (!custom || typeof custom != "object")
1002
- return !1;
1003
- let xlsx = custom._xlsx;
1004
- return xlsx != null && typeof xlsx == "object" && xlsx.legacyArrayFormula === !0;
1017
+ return cell.ft === import_core.FormulaType.ARRAY && cell.fd !== import_core.BooleanNumber.TRUE;
1005
1018
  }
1006
- function inferDisplayPrecision(styleId, styles) {
1007
- if (typeof styleId != "string" || !styles || typeof styles != "object")
1008
- return;
1009
- let style = styles[styleId];
1010
- if (!style || typeof style != "object")
1011
- return;
1019
+ function inferDisplayPrecision(styleId, styles, resolvedStyle) {
1020
+ let pattern = resolveNumberFormatPattern(styleId, styles, resolvedStyle);
1021
+ return pattern === void 0 ? void 0 : inferFixedNumberFormatPrecision(pattern);
1022
+ }
1023
+ function resolveNumberFormatPattern(styleRef, styles, resolvedStyle) {
1024
+ let style = resolvedStyle ?? (typeof styleRef == "string" && styles && typeof styles == "object" ? styles[styleRef] : styleRef);
1025
+ if (!style || typeof style != "object") return;
1012
1026
  let numberFormat = style.n;
1013
- if (!numberFormat || typeof numberFormat != "object")
1014
- return;
1027
+ if (!numberFormat || typeof numberFormat != "object") return;
1015
1028
  let pattern = numberFormat.pattern;
1016
- return typeof pattern == "string" ? inferFixedNumberFormatPrecision(pattern) : void 0;
1029
+ return typeof pattern == "string" ? pattern : void 0;
1017
1030
  }
1018
1031
  function inferFixedNumberFormatPrecision(pattern) {
1019
1032
  let cleaned = (pattern.split(";")[0] ?? pattern).replace(/"[^"]*"/gu, "").replace(/\\./gu, "").replace(/_.|\*./gu, "");
@@ -1289,7 +1302,7 @@ async function analyzeNumberFormatBatch(input) {
1289
1302
  var import_core5 = require("@univerjs/core"), import_engine_formula4 = require("@univerjs/engine-formula"), import_engine_formula5 = require("@univerjs-pro/engine-formula");
1290
1303
 
1291
1304
  // package.json
1292
- var name = "@univerjs-pro/engine-formula-rust", version = "1.0.0-rc.0";
1305
+ var name = "@univerjs-pro/engine-formula-rust", version = "1.0.0";
1293
1306
 
1294
1307
  // src/controllers/rust-same-runtime-projection.controller.ts
1295
1308
  var import_core3 = require("@univerjs/core"), import_engine_formula = require("@univerjs/engine-formula");
@@ -1324,7 +1337,8 @@ var RustSameRuntimeProjectionController = class extends import_core3.Disposable
1324
1337
  this._enqueueProjectionDelta(() => {
1325
1338
  this._rustEngineSyncController.upsertProjectionWorkbook({
1326
1339
  unitId: unit.getUnitId(),
1327
- snapshot: unit.getSnapshot()
1340
+ snapshot: unit.getSnapshot(),
1341
+ styleResolver: unit.getStyles()
1328
1342
  });
1329
1343
  });
1330
1344
  })
@@ -1538,7 +1552,8 @@ var RustSameRuntimeProjectionController = class extends import_core3.Disposable
1538
1552
  async _loadAllWorkbookProjections() {
1539
1553
  let workbooks = this._univerInstanceService.getAllUnitsForType(import_core3.UniverInstanceType.UNIVER_SHEET).map((workbook) => ({
1540
1554
  unitId: workbook.getUnitId(),
1541
- snapshot: workbook.getSnapshot()
1555
+ snapshot: workbook.getSnapshot(),
1556
+ styleResolver: workbook.getStyles()
1542
1557
  })), calculationData = this._formulaDataModel.getCalculateData(), formulaData = this._formulaDataModel.getFormulaData(), baseWorkbooks = this._univerInstanceService.getAllUnitsForType(import_core3.UniverInstanceType.UNIVER_BASE).map(
1543
1558
  (base) => this._createBaseWorkbookProjection(
1544
1559
  base.getUnitId(),
@@ -1854,7 +1869,7 @@ function resultBatchSheetCounts(output) {
1854
1869
  return counts;
1855
1870
  }
1856
1871
  var RustCalculateFormulaService = class extends import_core4.Disposable {
1857
- constructor(_configService, _currentConfigService, _runtimeService, _formulaDependencyGenerator, _featureCalculationManagerService, _otherFormulaManagerService, _commandService, _rustEngineSyncController, _formulaDataModel, _formulaReferenceDataService, _excelExternalReferenceModel, _superTableService) {
1872
+ constructor(_configService, _currentConfigService, _runtimeService, _formulaDependencyGenerator, _featureCalculationManagerService, _otherFormulaManagerService, _commandService, _rustEngineSyncController, _formulaDataModel, _formulaReferenceDataService, _excelExternalReferenceModel, _superTableService, _definedNamesService) {
1858
1873
  super();
1859
1874
  this._configService = _configService;
1860
1875
  this._currentConfigService = _currentConfigService;
@@ -1868,6 +1883,7 @@ var RustCalculateFormulaService = class extends import_core4.Disposable {
1868
1883
  this._formulaReferenceDataService = _formulaReferenceDataService;
1869
1884
  this._excelExternalReferenceModel = _excelExternalReferenceModel;
1870
1885
  this._superTableService = _superTableService;
1886
+ this._definedNamesService = _definedNamesService;
1871
1887
  this._commandService.hasCommand(import_engine_formula2.SetFormulaCalculationResultMutation.id) || this.disposeWithMe(this._commandService.registerCommand(import_engine_formula2.SetFormulaCalculationResultMutation)), this._commandService.hasCommand(import_engine_formula2.SetArrayFormulaDataMutation.id) || this.disposeWithMe(this._commandService.registerCommand(import_engine_formula2.SetArrayFormulaDataMutation));
1872
1888
  }
1873
1889
  _configService;
@@ -1882,6 +1898,7 @@ var RustCalculateFormulaService = class extends import_core4.Disposable {
1882
1898
  _formulaReferenceDataService;
1883
1899
  _excelExternalReferenceModel;
1884
1900
  _superTableService;
1901
+ _definedNamesService;
1885
1902
  _executionInProgressListener$ = new import_rxjs.Subject();
1886
1903
  executionInProgressListener$ = this._executionInProgressListener$.asObservable();
1887
1904
  _executionCompleteListener$ = new import_rxjs.Subject();
@@ -2379,16 +2396,23 @@ var RustCalculateFormulaService = class extends import_core4.Disposable {
2379
2396
  if (!unitData) return result;
2380
2397
  for (let [unitId, sheets] of Object.entries(unitData)) {
2381
2398
  result[unitId] = {};
2399
+ let styles = this._currentConfigService.getUnitStylesData()[unitId], sheetNames = Object.fromEntries(
2400
+ Object.entries(this._currentConfigService.getSheetNameMap()[unitId] ?? {}).map(([name2, id]) => [
2401
+ id,
2402
+ name2
2403
+ ])
2404
+ );
2382
2405
  for (let [sheetId, sheet] of Object.entries(sheets))
2383
2406
  result[unitId][sheetId] = {
2384
- cellData: this._serializeCellData(sheet.cellData),
2407
+ name: sheetNames[sheetId],
2408
+ cellData: this._serializeCellData(sheet.cellData, styles),
2385
2409
  rowCount: sheet.rowCount ?? 0,
2386
2410
  columnCount: sheet.columnCount ?? 0
2387
2411
  };
2388
2412
  }
2389
2413
  return result;
2390
2414
  }
2391
- _serializeCellData(cellData) {
2415
+ _serializeCellData(cellData, styles) {
2392
2416
  let result = {};
2393
2417
  if (!cellData || typeof cellData != "object") return result;
2394
2418
  let data = typeof cellData.getMatrix == "function" ? cellData.getMatrix() : cellData;
@@ -2398,13 +2422,23 @@ var RustCalculateFormulaService = class extends import_core4.Disposable {
2398
2422
  result[row] = {};
2399
2423
  for (let [colStr, cell] of Object.entries(cols)) {
2400
2424
  let col = Number(colStr);
2401
- Number.isFinite(col) && (result[row][col] = {
2425
+ if (!Number.isFinite(col))
2426
+ continue;
2427
+ result[row][col] = {
2402
2428
  v: cell?.v ?? null,
2403
2429
  t: cell?.t ?? void 0,
2404
2430
  p: cell?.p ?? void 0,
2405
2431
  f: cell?.f ?? void 0,
2406
2432
  s: cell?.s ?? void 0
2407
- });
2433
+ };
2434
+ let style = styles?.getStyleByCell(cell);
2435
+ if (style && typeof style == "object") {
2436
+ let numberFormat = style.n;
2437
+ if (numberFormat && typeof numberFormat == "object") {
2438
+ let pattern = numberFormat.pattern;
2439
+ typeof pattern == "string" && (result[row][col].numberFormat = pattern);
2440
+ }
2441
+ }
2408
2442
  }
2409
2443
  }
2410
2444
  }
@@ -2413,7 +2447,9 @@ var RustCalculateFormulaService = class extends import_core4.Disposable {
2413
2447
  _applyRustOutput(_output) {
2414
2448
  }
2415
2449
  async _applyRustDependencyOutput(output) {
2416
- let convertStartedAt = performance.now(), patch = rustExecutionOutputToFormulaCalculationPatch(output), convertMs = performance.now() - convertStartedAt, commandStartedAt = performance.now();
2450
+ let convertStartedAt = performance.now(), patch = rustExecutionOutputToFormulaCalculationPatch(output);
2451
+ this._mergeRuntimeUnitData(patch.unitData);
2452
+ let convertMs = performance.now() - convertStartedAt, commandStartedAt = performance.now();
2417
2453
  return (patch.arrayFormulaRange || patch.arrayFormulaCellData) && (this._formulaDataModel.setArrayFormulaRange(patch.arrayFormulaRange ?? {}), this._formulaDataModel.setArrayFormulaCellData(patch.arrayFormulaCellData ?? {}), await this._commandService.executeCommand(
2418
2454
  import_engine_formula2.SetArrayFormulaDataMutation.id,
2419
2455
  {
@@ -2440,6 +2476,20 @@ var RustCalculateFormulaService = class extends import_core4.Disposable {
2440
2476
  commandMs: performance.now() - commandStartedAt
2441
2477
  };
2442
2478
  }
2479
+ _mergeRuntimeUnitData(unitData) {
2480
+ let runtimeUnitData = this._runtimeService.getUnitData();
2481
+ Object.entries(unitData).forEach(([unitId, sheetMap]) => {
2482
+ if (!sheetMap) return;
2483
+ let runtimeSheetMap = runtimeUnitData[unitId] ??= {};
2484
+ Object.entries(sheetMap).forEach(([sheetId, cellData]) => {
2485
+ if (!cellData) return;
2486
+ let runtimeMatrix = runtimeSheetMap[sheetId] ??= new import_core4.ObjectMatrix();
2487
+ new import_core4.ObjectMatrix(cellData).forValue((row, column, cell) => {
2488
+ runtimeMatrix.setValue(row, column, cell);
2489
+ });
2490
+ });
2491
+ });
2492
+ }
2443
2493
  async calculate(formulaString) {
2444
2494
  this._nativeLoaded || (await loadNativeBinding(), this._nativeLoaded = !0);
2445
2495
  let unitId = "__rust_formula_calculate__", sheetId = "__sheet__", input = {
@@ -2467,13 +2517,25 @@ var RustCalculateFormulaService = class extends import_core4.Disposable {
2467
2517
  }
2468
2518
  async executeFormulas(formulas, rowData) {
2469
2519
  this._nativeLoaded || (await loadNativeBinding(), this._nativeLoaded = !0), this._currentConfigService.loadDataLite(rowData);
2470
- let unitData = this._currentConfigService.getUnitData(), formulaData = this._formulaStringMapToFormulaData(formulas), input = {
2520
+ let unitData = this._currentConfigService.getUnitData(), definedNames = {};
2521
+ for (let [unitId, names] of Object.entries(this._definedNamesService.getAllDefinedNames()))
2522
+ for (let [id, name2] of Object.entries(names))
2523
+ definedNames[JSON.stringify([unitId, id])] = {
2524
+ unitId,
2525
+ localSheetId: name2.localSheetId === "AllDefaultWorkbook" ? void 0 : name2.localSheetId,
2526
+ name: name2.name,
2527
+ formula: name2.formulaOrRefString
2528
+ };
2529
+ let input = {
2471
2530
  config: { maxIteration: 1, intervalCount: DEFAULT_INTERVAL_COUNT },
2472
- formulaData,
2531
+ formulaData: {},
2532
+ queryFormulas: this._formulaStringMapToQueryData(formulas),
2473
2533
  unitData: this._serializeUnitData(unitData),
2474
2534
  dirtyRanges: [],
2475
- definedNames: {}
2535
+ definedNames
2476
2536
  }, output = JSON.parse(executeOnRust(JSON.stringify(input)));
2537
+ if (!output.queryResults)
2538
+ throw new Error("Native formula binding does not support independent formula queries");
2477
2539
  return this._formulaExecutionOutputToResultMap(formulas, output);
2478
2540
  }
2479
2541
  async getAllDependencyJson(_rowData) {
@@ -2516,7 +2578,7 @@ var RustCalculateFormulaService = class extends import_core4.Disposable {
2516
2578
  ]);
2517
2579
  return { dependents, inRanges };
2518
2580
  }
2519
- _formulaStringMapToFormulaData(formulas) {
2581
+ _formulaStringMapToQueryData(formulas) {
2520
2582
  let formulaData = {};
2521
2583
  return Object.entries(formulas).forEach(([unitId, sheetMap]) => {
2522
2584
  sheetMap && (formulaData[unitId] = {}, Object.entries(sheetMap).forEach(([sheetId, rowMap]) => {
@@ -2524,8 +2586,7 @@ var RustCalculateFormulaService = class extends import_core4.Disposable {
2524
2586
  if (!colMap) return;
2525
2587
  let row = Number(rowKey);
2526
2588
  formulaData[unitId][sheetId][row] = {}, Object.entries(colMap).forEach(([colKey, formulaList]) => {
2527
- let formula = Array.isArray(formulaList) ? formulaList[0] : void 0;
2528
- typeof formula == "string" && (formulaData[unitId][sheetId][row][Number(colKey)] = formula);
2589
+ Array.isArray(formulaList) && (formulaData[unitId][sheetId][row][Number(colKey)] = formulaList);
2529
2590
  });
2530
2591
  }));
2531
2592
  }));
@@ -2539,10 +2600,13 @@ var RustCalculateFormulaService = class extends import_core4.Disposable {
2539
2600
  if (!colMap) return;
2540
2601
  let row = Number(rowKey);
2541
2602
  result[unitId][sheetId][row] = {}, Object.entries(colMap).forEach(([colKey, formulaList]) => {
2542
- let col = Number(colKey), formulasForCell = Array.isArray(formulaList) ? formulaList : [], value = normalizeFormulaResultValue(
2543
- output.runtimeData?.[unitId]?.[sheetId]?.[row]?.[col]
2544
- );
2545
- result[unitId][sheetId][row][col] = formulasForCell.map((formula) => ({ formula, value }));
2603
+ let col = Number(colKey), formulasForCell = Array.isArray(formulaList) ? formulaList : [];
2604
+ result[unitId][sheetId][row][col] = formulasForCell.map((formula, index) => ({
2605
+ formula,
2606
+ value: normalizeFormulaResultValue(
2607
+ output.queryResults?.[unitId]?.[sheetId]?.[row]?.[col]?.[index]?.value
2608
+ )
2609
+ }));
2546
2610
  });
2547
2611
  }));
2548
2612
  }));
@@ -2661,7 +2725,8 @@ var RustCalculateFormulaService = class extends import_core4.Disposable {
2661
2725
  import_engine_formula2.FormulaDataModel,
2662
2726
  import_engine_formula3.IFormulaReferenceDataService,
2663
2727
  import_engine_formula3.ExternalReferenceModel,
2664
- import_engine_formula2.ISuperTableService
2728
+ import_engine_formula2.ISuperTableService,
2729
+ import_engine_formula2.IDefinedNamesService
2665
2730
  ]);
2666
2731
  function createRustProductExternalSyntheticUnitId(hostUnitId, referenceId) {
2667
2732
  return `external:product:${encodeURIComponent(hostUnitId)}:${encodeURIComponent(referenceId)}`;
package/lib/es/index.js CHANGED
@@ -176,7 +176,9 @@ import { CommandType, Disposable, ICommandService, setDependencies } from "@univ
176
176
 
177
177
  // src/services/rust-formula-projection.service.ts
178
178
  import {
179
+ BooleanNumber,
179
180
  CellValueType,
181
+ FormulaType,
180
182
  ObjectMatrix
181
183
  } from "@univerjs/core";
182
184
  var XLSX_WORKBOOK_CALCULATION_RESOURCE = "UNIVER_CLI_XLSX_WORKBOOK_CALCULATION_PLUGIN", EXTERNAL_DATA_RESOURCE = "SHEET_EXTERNAL_DATA_PLUGIN", EXTERNAL_DATA_SIGNATURE = "external_data", RUST_UPSERT_REFERENCE_DATA_MUTATION_ID = "formula.mutation.upsert-reference-data", RUST_UPSERT_PROJECTION_WORKBOOK_MUTATION_ID = "formula.mutation.upsert-projection-workbook", RUST_SET_SUPER_TABLES_MUTATION_ID = "formula.mutation.set-super-tables", RUST_FORMULA_RELEVANT_MUTATIONS = /* @__PURE__ */ new Set([
@@ -195,6 +197,11 @@ var XLSX_WORKBOOK_CALCULATION_RESOURCE = "UNIVER_CLI_XLSX_WORKBOOK_CALCULATION_P
195
197
  "sheet.mutation.set-col-visible",
196
198
  "sheet.mutation.set-row-hidden",
197
199
  "sheet.mutation.set-row-visible",
200
+ "sheet.mutation.set-table-filter",
201
+ "sheet.mutation.set-filter-range",
202
+ "sheet.mutation.set-filter-criteria",
203
+ "sheet.mutation.remove-filter",
204
+ "sheet.mutation.re-calc-filter",
198
205
  "sheet.mutation.set-worksheet-name",
199
206
  "sheet.mutation.reorder-range",
200
207
  "sheet.mutation.set-worksheet-row-count",
@@ -268,11 +275,18 @@ function serializeRuntimeWorkbookSnapshots(workbooks) {
268
275
  }
269
276
  function serializeRuntimeWorkbookSnapshot(input) {
270
277
  let { snapshot } = input, sheetOrder = snapshot.sheetOrder?.length > 0 ? snapshot.sheetOrder : Object.keys(snapshot.sheets ?? {}), calculation = serializeCalculation(snapshot), precisionAsDisplayed = calculation?.fullPrecision === !1, sheets = sheetOrder.map(
271
- (sheetId) => serializeSheetSnapshot(sheetId, snapshot.sheets?.[sheetId], snapshot.styles, precisionAsDisplayed)
278
+ (sheetId) => serializeSheetSnapshot(
279
+ sheetId,
280
+ snapshot.sheets?.[sheetId],
281
+ snapshot.styles,
282
+ precisionAsDisplayed,
283
+ input.styleResolver
284
+ )
272
285
  ).filter((sheet) => sheet != null);
273
286
  return {
274
287
  unitId: input.unitId || snapshot.id,
275
288
  name: snapshot.name,
289
+ dateSystem: snapshot.dateSystem,
276
290
  sheets,
277
291
  ...calculation ? { calculation } : {},
278
292
  resources: serializeResources(snapshot),
@@ -340,13 +354,16 @@ function otherFormulaDataToUnitOtherData(otherFormulaData) {
340
354
  if (!colMap) return;
341
355
  let row = Number(rowKey), rowData = {};
342
356
  formulaData[row] = rowData, Object.entries(colMap).forEach(([colKey, value]) => {
343
- rowData[Number(colKey)] = [[cellDataFromRustValue(value)]];
357
+ rowData[Number(colKey)] = otherFormulaResultFromRustValue(value);
344
358
  });
345
359
  });
346
360
  });
347
361
  });
348
362
  }), unitOtherData;
349
363
  }
364
+ function otherFormulaResultFromRustValue(value) {
365
+ return Array.isArray(value) ? value.map((row) => (Array.isArray(row) ? row : [row]).map((cell) => cellDataFromRustValue(cell))) : [[cellDataFromRustValue(value)]];
366
+ }
350
367
  function createFormulaProjectionDesyncSignal(reason, error, mutationId) {
351
368
  return {
352
369
  reason,
@@ -880,19 +897,19 @@ function extractDefinedNames(snapshot) {
880
897
  }
881
898
  return {};
882
899
  }
883
- function serializeSheetSnapshot(sheetId, sheet, styles, precisionAsDisplayed) {
900
+ function serializeSheetSnapshot(sheetId, sheet, styles, precisionAsDisplayed, styleResolver) {
884
901
  return sheet ? {
885
902
  sheetId: sheet.id ?? sheetId,
886
903
  name: sheet.name,
887
904
  rowCount: sheet.rowCount ?? 0,
888
905
  columnCount: sheet.columnCount ?? 0,
889
906
  transitionEvaluation: sheet.transitionEvaluation === !0,
890
- cellData: serializeCellData(sheet.cellData, styles, precisionAsDisplayed),
907
+ cellData: serializeCellData(sheet.cellData, styles, precisionAsDisplayed, styleResolver),
891
908
  rowData: serializeVisibilityData(sheet.rowData),
892
909
  columnData: serializeVisibilityData(sheet.columnData)
893
910
  } : null;
894
911
  }
895
- function serializeCellData(cellData = {}, styles, precisionAsDisplayed = !1) {
912
+ function serializeCellData(cellData = {}, styles, precisionAsDisplayed = !1, styleResolver) {
896
913
  let result = {}, rawCellData = cellData instanceof ObjectMatrix ? cellData.getMatrix() : cellData;
897
914
  for (let [rowKey, row] of Object.entries(rawCellData ?? {})) {
898
915
  if (!row)
@@ -901,13 +918,15 @@ function serializeCellData(cellData = {}, styles, precisionAsDisplayed = !1) {
901
918
  for (let [colKey, cell] of Object.entries(row)) {
902
919
  if (!cell || typeof cell != "object")
903
920
  continue;
904
- let cellRecord = cell, value = {};
905
- if ("v" in cellRecord && (value.v = cellRecord.v), typeof cellRecord.t == "number" && (value.t = cellRecord.t), "p" in cellRecord && (value.p = cellRecord.p), typeof cellRecord.f == "string" && (value.f = cellRecord.f), typeof cellRecord.si == "string" && (value.si = cellRecord.si), typeof cellRecord.ref == "string") {
921
+ let cellRecord = cell, resolvedStyle = styleResolver?.getStyleByCell(cell), value = {};
922
+ if ("v" in cellRecord && (value.v = cellRecord.v), typeof cellRecord.t == "number" && (value.t = cellRecord.t), "p" in cellRecord && (value.p = cellRecord.p), typeof cellRecord.f == "string" && (value.f = cellRecord.f), typeof cellRecord.ft == "number" && (value.ft = cellRecord.ft), (cellRecord.fd === BooleanNumber.FALSE || cellRecord.fd === BooleanNumber.TRUE) && (value.fd = cellRecord.fd), typeof cellRecord.si == "string" && (value.si = cellRecord.si), typeof cellRecord.ref == "string") {
906
923
  let hasFormula = typeof cellRecord.f == "string" && cellRecord.f.length > 0;
907
924
  typeof cellRecord.si == "string" || hasFormula && isLegacyArrayFormulaCell(cellRecord) ? value.ref = cellRecord.ref : hasFormula && (value.dynamicArrayRef = cellRecord.ref);
908
925
  }
909
- if (typeof cellRecord.xf == "string" && (value.xf = cellRecord.xf), "s" in cellRecord && (value.s = cellRecord.s), precisionAsDisplayed && typeof cellRecord.f == "string") {
910
- let displayPrecision = inferDisplayPrecision(cellRecord.s, styles);
926
+ typeof cellRecord.xf == "string" && (value.xf = cellRecord.xf), "s" in cellRecord && (value.s = cellRecord.s);
927
+ let numberFormat = resolveNumberFormatPattern(cellRecord.s, styles, resolvedStyle);
928
+ if (numberFormat !== void 0 && (value.numberFormat = numberFormat), precisionAsDisplayed && typeof cellRecord.f == "string") {
929
+ let displayPrecision = inferDisplayPrecision(cellRecord.s, styles, resolvedStyle);
911
930
  displayPrecision !== void 0 && (value.displayPrecision = displayPrecision);
912
931
  }
913
932
  Object.keys(value).length > 0 && (serializedRow[Number(colKey)] = value);
@@ -930,23 +949,19 @@ function serializeCellDataInRanges(cellData, ranges) {
930
949
  return result;
931
950
  }
932
951
  function isLegacyArrayFormulaCell(cell) {
933
- let custom = cell.custom;
934
- if (!custom || typeof custom != "object")
935
- return !1;
936
- let xlsx = custom._xlsx;
937
- return xlsx != null && typeof xlsx == "object" && xlsx.legacyArrayFormula === !0;
952
+ return cell.ft === FormulaType.ARRAY && cell.fd !== BooleanNumber.TRUE;
938
953
  }
939
- function inferDisplayPrecision(styleId, styles) {
940
- if (typeof styleId != "string" || !styles || typeof styles != "object")
941
- return;
942
- let style = styles[styleId];
943
- if (!style || typeof style != "object")
944
- return;
954
+ function inferDisplayPrecision(styleId, styles, resolvedStyle) {
955
+ let pattern = resolveNumberFormatPattern(styleId, styles, resolvedStyle);
956
+ return pattern === void 0 ? void 0 : inferFixedNumberFormatPrecision(pattern);
957
+ }
958
+ function resolveNumberFormatPattern(styleRef, styles, resolvedStyle) {
959
+ let style = resolvedStyle ?? (typeof styleRef == "string" && styles && typeof styles == "object" ? styles[styleRef] : styleRef);
960
+ if (!style || typeof style != "object") return;
945
961
  let numberFormat = style.n;
946
- if (!numberFormat || typeof numberFormat != "object")
947
- return;
962
+ if (!numberFormat || typeof numberFormat != "object") return;
948
963
  let pattern = numberFormat.pattern;
949
- return typeof pattern == "string" ? inferFixedNumberFormatPrecision(pattern) : void 0;
964
+ return typeof pattern == "string" ? pattern : void 0;
950
965
  }
951
966
  function inferFixedNumberFormatPrecision(pattern) {
952
967
  let cleaned = (pattern.split(";")[0] ?? pattern).replace(/"[^"]*"/gu, "").replace(/\\./gu, "").replace(/_.|\*./gu, "");
@@ -1224,7 +1239,7 @@ import { ICalculateFormulaService } from "@univerjs/engine-formula";
1224
1239
  import { UniverProFormulaEnginePlugin } from "@univerjs-pro/engine-formula";
1225
1240
 
1226
1241
  // package.json
1227
- var name = "@univerjs-pro/engine-formula-rust", version = "1.0.0-rc.0";
1242
+ var name = "@univerjs-pro/engine-formula-rust", version = "1.0.0";
1228
1243
 
1229
1244
  // src/controllers/rust-same-runtime-projection.controller.ts
1230
1245
  import {
@@ -1278,7 +1293,8 @@ var RustSameRuntimeProjectionController = class extends Disposable2 {
1278
1293
  this._enqueueProjectionDelta(() => {
1279
1294
  this._rustEngineSyncController.upsertProjectionWorkbook({
1280
1295
  unitId: unit.getUnitId(),
1281
- snapshot: unit.getSnapshot()
1296
+ snapshot: unit.getSnapshot(),
1297
+ styleResolver: unit.getStyles()
1282
1298
  });
1283
1299
  });
1284
1300
  })
@@ -1492,7 +1508,8 @@ var RustSameRuntimeProjectionController = class extends Disposable2 {
1492
1508
  async _loadAllWorkbookProjections() {
1493
1509
  let workbooks = this._univerInstanceService.getAllUnitsForType(UniverInstanceType.UNIVER_SHEET).map((workbook) => ({
1494
1510
  unitId: workbook.getUnitId(),
1495
- snapshot: workbook.getSnapshot()
1511
+ snapshot: workbook.getSnapshot(),
1512
+ styleResolver: workbook.getStyles()
1496
1513
  })), calculationData = this._formulaDataModel.getCalculateData(), formulaData = this._formulaDataModel.getFormulaData(), baseWorkbooks = this._univerInstanceService.getAllUnitsForType(UniverInstanceType.UNIVER_BASE).map(
1497
1514
  (base) => this._createBaseWorkbookProjection(
1498
1515
  base.getUnitId(),
@@ -1778,6 +1795,7 @@ import {
1778
1795
  FormulaExecuteStageType,
1779
1796
  IFeatureCalculationManagerService,
1780
1797
  IFormulaCurrentConfigService,
1798
+ IDefinedNamesService,
1781
1799
  IFormulaDependencyGenerator,
1782
1800
  IFormulaRuntimeService,
1783
1801
  IOtherFormulaManagerService,
@@ -1834,7 +1852,7 @@ function resultBatchSheetCounts(output) {
1834
1852
  return counts;
1835
1853
  }
1836
1854
  var RustCalculateFormulaService = class extends Disposable3 {
1837
- constructor(_configService, _currentConfigService, _runtimeService, _formulaDependencyGenerator, _featureCalculationManagerService, _otherFormulaManagerService, _commandService, _rustEngineSyncController, _formulaDataModel, _formulaReferenceDataService, _excelExternalReferenceModel, _superTableService) {
1855
+ constructor(_configService, _currentConfigService, _runtimeService, _formulaDependencyGenerator, _featureCalculationManagerService, _otherFormulaManagerService, _commandService, _rustEngineSyncController, _formulaDataModel, _formulaReferenceDataService, _excelExternalReferenceModel, _superTableService, _definedNamesService) {
1838
1856
  super();
1839
1857
  this._configService = _configService;
1840
1858
  this._currentConfigService = _currentConfigService;
@@ -1848,6 +1866,7 @@ var RustCalculateFormulaService = class extends Disposable3 {
1848
1866
  this._formulaReferenceDataService = _formulaReferenceDataService;
1849
1867
  this._excelExternalReferenceModel = _excelExternalReferenceModel;
1850
1868
  this._superTableService = _superTableService;
1869
+ this._definedNamesService = _definedNamesService;
1851
1870
  this._commandService.hasCommand(SetFormulaCalculationResultMutation2.id) || this.disposeWithMe(this._commandService.registerCommand(SetFormulaCalculationResultMutation2)), this._commandService.hasCommand(SetArrayFormulaDataMutation.id) || this.disposeWithMe(this._commandService.registerCommand(SetArrayFormulaDataMutation));
1852
1871
  }
1853
1872
  _configService;
@@ -1862,6 +1881,7 @@ var RustCalculateFormulaService = class extends Disposable3 {
1862
1881
  _formulaReferenceDataService;
1863
1882
  _excelExternalReferenceModel;
1864
1883
  _superTableService;
1884
+ _definedNamesService;
1865
1885
  _executionInProgressListener$ = new Subject();
1866
1886
  executionInProgressListener$ = this._executionInProgressListener$.asObservable();
1867
1887
  _executionCompleteListener$ = new Subject();
@@ -2359,16 +2379,23 @@ var RustCalculateFormulaService = class extends Disposable3 {
2359
2379
  if (!unitData) return result;
2360
2380
  for (let [unitId, sheets] of Object.entries(unitData)) {
2361
2381
  result[unitId] = {};
2382
+ let styles = this._currentConfigService.getUnitStylesData()[unitId], sheetNames = Object.fromEntries(
2383
+ Object.entries(this._currentConfigService.getSheetNameMap()[unitId] ?? {}).map(([name2, id]) => [
2384
+ id,
2385
+ name2
2386
+ ])
2387
+ );
2362
2388
  for (let [sheetId, sheet] of Object.entries(sheets))
2363
2389
  result[unitId][sheetId] = {
2364
- cellData: this._serializeCellData(sheet.cellData),
2390
+ name: sheetNames[sheetId],
2391
+ cellData: this._serializeCellData(sheet.cellData, styles),
2365
2392
  rowCount: sheet.rowCount ?? 0,
2366
2393
  columnCount: sheet.columnCount ?? 0
2367
2394
  };
2368
2395
  }
2369
2396
  return result;
2370
2397
  }
2371
- _serializeCellData(cellData) {
2398
+ _serializeCellData(cellData, styles) {
2372
2399
  let result = {};
2373
2400
  if (!cellData || typeof cellData != "object") return result;
2374
2401
  let data = typeof cellData.getMatrix == "function" ? cellData.getMatrix() : cellData;
@@ -2378,13 +2405,23 @@ var RustCalculateFormulaService = class extends Disposable3 {
2378
2405
  result[row] = {};
2379
2406
  for (let [colStr, cell] of Object.entries(cols)) {
2380
2407
  let col = Number(colStr);
2381
- Number.isFinite(col) && (result[row][col] = {
2408
+ if (!Number.isFinite(col))
2409
+ continue;
2410
+ result[row][col] = {
2382
2411
  v: cell?.v ?? null,
2383
2412
  t: cell?.t ?? void 0,
2384
2413
  p: cell?.p ?? void 0,
2385
2414
  f: cell?.f ?? void 0,
2386
2415
  s: cell?.s ?? void 0
2387
- });
2416
+ };
2417
+ let style = styles?.getStyleByCell(cell);
2418
+ if (style && typeof style == "object") {
2419
+ let numberFormat = style.n;
2420
+ if (numberFormat && typeof numberFormat == "object") {
2421
+ let pattern = numberFormat.pattern;
2422
+ typeof pattern == "string" && (result[row][col].numberFormat = pattern);
2423
+ }
2424
+ }
2388
2425
  }
2389
2426
  }
2390
2427
  }
@@ -2393,7 +2430,9 @@ var RustCalculateFormulaService = class extends Disposable3 {
2393
2430
  _applyRustOutput(_output) {
2394
2431
  }
2395
2432
  async _applyRustDependencyOutput(output) {
2396
- let convertStartedAt = performance.now(), patch = rustExecutionOutputToFormulaCalculationPatch(output), convertMs = performance.now() - convertStartedAt, commandStartedAt = performance.now();
2433
+ let convertStartedAt = performance.now(), patch = rustExecutionOutputToFormulaCalculationPatch(output);
2434
+ this._mergeRuntimeUnitData(patch.unitData);
2435
+ let convertMs = performance.now() - convertStartedAt, commandStartedAt = performance.now();
2397
2436
  return (patch.arrayFormulaRange || patch.arrayFormulaCellData) && (this._formulaDataModel.setArrayFormulaRange(patch.arrayFormulaRange ?? {}), this._formulaDataModel.setArrayFormulaCellData(patch.arrayFormulaCellData ?? {}), await this._commandService.executeCommand(
2398
2437
  SetArrayFormulaDataMutation.id,
2399
2438
  {
@@ -2420,6 +2459,20 @@ var RustCalculateFormulaService = class extends Disposable3 {
2420
2459
  commandMs: performance.now() - commandStartedAt
2421
2460
  };
2422
2461
  }
2462
+ _mergeRuntimeUnitData(unitData) {
2463
+ let runtimeUnitData = this._runtimeService.getUnitData();
2464
+ Object.entries(unitData).forEach(([unitId, sheetMap]) => {
2465
+ if (!sheetMap) return;
2466
+ let runtimeSheetMap = runtimeUnitData[unitId] ??= {};
2467
+ Object.entries(sheetMap).forEach(([sheetId, cellData]) => {
2468
+ if (!cellData) return;
2469
+ let runtimeMatrix = runtimeSheetMap[sheetId] ??= new ObjectMatrix3();
2470
+ new ObjectMatrix3(cellData).forValue((row, column, cell) => {
2471
+ runtimeMatrix.setValue(row, column, cell);
2472
+ });
2473
+ });
2474
+ });
2475
+ }
2423
2476
  async calculate(formulaString) {
2424
2477
  this._nativeLoaded || (await loadNativeBinding(), this._nativeLoaded = !0);
2425
2478
  let unitId = "__rust_formula_calculate__", sheetId = "__sheet__", input = {
@@ -2447,13 +2500,25 @@ var RustCalculateFormulaService = class extends Disposable3 {
2447
2500
  }
2448
2501
  async executeFormulas(formulas, rowData) {
2449
2502
  this._nativeLoaded || (await loadNativeBinding(), this._nativeLoaded = !0), this._currentConfigService.loadDataLite(rowData);
2450
- let unitData = this._currentConfigService.getUnitData(), formulaData = this._formulaStringMapToFormulaData(formulas), input = {
2503
+ let unitData = this._currentConfigService.getUnitData(), definedNames = {};
2504
+ for (let [unitId, names] of Object.entries(this._definedNamesService.getAllDefinedNames()))
2505
+ for (let [id, name2] of Object.entries(names))
2506
+ definedNames[JSON.stringify([unitId, id])] = {
2507
+ unitId,
2508
+ localSheetId: name2.localSheetId === "AllDefaultWorkbook" ? void 0 : name2.localSheetId,
2509
+ name: name2.name,
2510
+ formula: name2.formulaOrRefString
2511
+ };
2512
+ let input = {
2451
2513
  config: { maxIteration: 1, intervalCount: DEFAULT_INTERVAL_COUNT },
2452
- formulaData,
2514
+ formulaData: {},
2515
+ queryFormulas: this._formulaStringMapToQueryData(formulas),
2453
2516
  unitData: this._serializeUnitData(unitData),
2454
2517
  dirtyRanges: [],
2455
- definedNames: {}
2518
+ definedNames
2456
2519
  }, output = JSON.parse(executeOnRust(JSON.stringify(input)));
2520
+ if (!output.queryResults)
2521
+ throw new Error("Native formula binding does not support independent formula queries");
2457
2522
  return this._formulaExecutionOutputToResultMap(formulas, output);
2458
2523
  }
2459
2524
  async getAllDependencyJson(_rowData) {
@@ -2496,7 +2561,7 @@ var RustCalculateFormulaService = class extends Disposable3 {
2496
2561
  ]);
2497
2562
  return { dependents, inRanges };
2498
2563
  }
2499
- _formulaStringMapToFormulaData(formulas) {
2564
+ _formulaStringMapToQueryData(formulas) {
2500
2565
  let formulaData = {};
2501
2566
  return Object.entries(formulas).forEach(([unitId, sheetMap]) => {
2502
2567
  sheetMap && (formulaData[unitId] = {}, Object.entries(sheetMap).forEach(([sheetId, rowMap]) => {
@@ -2504,8 +2569,7 @@ var RustCalculateFormulaService = class extends Disposable3 {
2504
2569
  if (!colMap) return;
2505
2570
  let row = Number(rowKey);
2506
2571
  formulaData[unitId][sheetId][row] = {}, Object.entries(colMap).forEach(([colKey, formulaList]) => {
2507
- let formula = Array.isArray(formulaList) ? formulaList[0] : void 0;
2508
- typeof formula == "string" && (formulaData[unitId][sheetId][row][Number(colKey)] = formula);
2572
+ Array.isArray(formulaList) && (formulaData[unitId][sheetId][row][Number(colKey)] = formulaList);
2509
2573
  });
2510
2574
  }));
2511
2575
  }));
@@ -2519,10 +2583,13 @@ var RustCalculateFormulaService = class extends Disposable3 {
2519
2583
  if (!colMap) return;
2520
2584
  let row = Number(rowKey);
2521
2585
  result[unitId][sheetId][row] = {}, Object.entries(colMap).forEach(([colKey, formulaList]) => {
2522
- let col = Number(colKey), formulasForCell = Array.isArray(formulaList) ? formulaList : [], value = normalizeFormulaResultValue(
2523
- output.runtimeData?.[unitId]?.[sheetId]?.[row]?.[col]
2524
- );
2525
- result[unitId][sheetId][row][col] = formulasForCell.map((formula) => ({ formula, value }));
2586
+ let col = Number(colKey), formulasForCell = Array.isArray(formulaList) ? formulaList : [];
2587
+ result[unitId][sheetId][row][col] = formulasForCell.map((formula, index) => ({
2588
+ formula,
2589
+ value: normalizeFormulaResultValue(
2590
+ output.queryResults?.[unitId]?.[sheetId]?.[row]?.[col]?.[index]?.value
2591
+ )
2592
+ }));
2526
2593
  });
2527
2594
  }));
2528
2595
  }));
@@ -2641,7 +2708,8 @@ setDependencies3(RustCalculateFormulaService, [
2641
2708
  FormulaDataModel2,
2642
2709
  IFormulaReferenceDataService,
2643
2710
  ExternalReferenceModel,
2644
- ISuperTableService2
2711
+ ISuperTableService2,
2712
+ IDefinedNamesService
2645
2713
  ]);
2646
2714
  function createRustProductExternalSyntheticUnitId(hostUnitId, referenceId) {
2647
2715
  return `external:product:${encodeURIComponent(hostUnitId)}:${encodeURIComponent(referenceId)}`;
@@ -1,6 +1,6 @@
1
1
  import { Buffer } from "node:buffer";
2
- import { FormulaDataModel, IAllRuntimeData, ICalculateFormulaService, IExecutionInProgressParams, IFeatureCalculationManagerService, IFeatureDirtyRangeType, IFormulaCurrentConfigService, IFormulaDatasetConfig, IFormulaDependencyGenerator, IFormulaDependencyTreeJson, IFormulaExecuteResultMap, IFormulaRuntimeService, IFormulaStringMap, IOtherFormulaManagerService, IRuntimeUnitDataType, ISetArrayFormulaDataMutationParams, ISetFormulaCalculationResultMutation, ISuperTableService, IUnitRowData, IUniverEngineFormulaConfig } from "@univerjs/engine-formula";
3
- import { Dependency, Disposable, ICommandService, IConfigService, IUnitRange as IUnitRange$1, IWorkbookData, Injector, Nullable } from "@univerjs/core";
2
+ import { FormulaDataModel, IAllRuntimeData, ICalculateFormulaService, IDefinedNamesService, IExecutionInProgressParams, IFeatureCalculationManagerService, IFeatureDirtyRangeType, IFormulaCurrentConfigService, IFormulaDatasetConfig, IFormulaDependencyGenerator, IFormulaDependencyTreeJson, IFormulaExecuteResultMap, IFormulaRuntimeService, IFormulaStringMap, IOtherFormulaManagerService, IRuntimeUnitDataType, ISetArrayFormulaDataMutationParams, ISetFormulaCalculationResultMutation, ISuperTableService, IUnitRowData, IUniverEngineFormulaConfig } from "@univerjs/engine-formula";
3
+ import { BooleanNumber, Dependency, Disposable, FormulaType, ICellData, ICommandService, IConfigService, IUnitRange as IUnitRange$1, IWorkbookData, Injector, Nullable } from "@univerjs/core";
4
4
  import { ExternalReferenceModel, IFormulaReferenceDataService, UniverProFormulaEnginePlugin } from "@univerjs-pro/engine-formula";
5
5
  import { Subject } from "rxjs";
6
6
  import { ISheetBlock, ISnapshot } from "@univerjs/protocol";
@@ -100,8 +100,10 @@ interface IFormulaExecutionInput {
100
100
  unitData: Record<string, Record<string, ISheetData>>;
101
101
  dirtyRanges: IUnitRange[];
102
102
  definedNames: Record<string, IDefinedName>;
103
+ queryFormulas?: Record<string, Record<string, Record<number, Record<number, string[]>>>>;
103
104
  }
104
105
  interface ISheetData {
106
+ name?: string;
105
107
  cellData: Record<number, Record<number, ICellValue>>;
106
108
  rowCount: number;
107
109
  columnCount: number;
@@ -111,11 +113,14 @@ interface ICellValue {
111
113
  t?: number;
112
114
  p?: unknown;
113
115
  f?: string;
116
+ ft?: FormulaType;
117
+ fd?: BooleanNumber;
114
118
  si?: string;
115
119
  ref?: string;
116
120
  dynamicArrayRef?: string;
117
121
  xf?: string;
118
122
  s?: unknown;
123
+ numberFormat?: string;
119
124
  displayPrecision?: number;
120
125
  }
121
126
  interface IUnitRange {
@@ -130,11 +135,17 @@ interface IRange {
130
135
  endColumn: number;
131
136
  }
132
137
  interface IDefinedName {
138
+ unitId?: string;
139
+ localSheetId?: string;
133
140
  name: string;
134
141
  formula?: string;
135
142
  range?: IRange;
136
143
  }
137
144
  interface IFormulaExecutionOutput {
145
+ queryResults?: Record<string, Record<string, Record<number, Record<number, Array<{
146
+ formula: string;
147
+ value: unknown;
148
+ }>>>>>;
138
149
  runtimeData: Record<string, Record<string, Record<number, Record<number, unknown>>>>;
139
150
  arrayFormulaRange: Record<string, Record<string, Record<number, Record<number, IRange>>>>;
140
151
  cycleDependencies: ICycleDependencyInfo[];
@@ -159,6 +170,7 @@ interface IRustEngineSnapshot {
159
170
  interface IRustWorkbookSnapshot {
160
171
  unitId: string;
161
172
  name?: string;
173
+ dateSystem?: 'date1900' | 'date1904';
162
174
  sheets: IRustSheetSnapshot[];
163
175
  calculation?: IRustWorkbookCalculationSnapshot;
164
176
  resources?: Record<string, IRustResourceSnapshot>;
@@ -513,6 +525,9 @@ interface IRustProjectionWorkbookInput {
513
525
  snapshot: IWorkbookData;
514
526
  unitId?: string;
515
527
  definedNames?: Record<string, IRustDefinedNameSnapshot>;
528
+ styleResolver?: {
529
+ getStyleByCell(cell: ICellData): unknown;
530
+ };
516
531
  }
517
532
  interface IFormulaCalculationError {
518
533
  code: string;
@@ -820,6 +835,7 @@ declare class RustCalculateFormulaService extends Disposable implements IRustCal
820
835
  private readonly _formulaReferenceDataService;
821
836
  private readonly _excelExternalReferenceModel;
822
837
  private readonly _superTableService;
838
+ private readonly _definedNamesService;
823
839
  protected readonly _executionInProgressListener$: Subject<IExecutionInProgressParams>;
824
840
  readonly executionInProgressListener$: import("rxjs").Observable<IExecutionInProgressParams>;
825
841
  protected readonly _executionCompleteListener$: Subject<IAllRuntimeData>;
@@ -834,7 +850,7 @@ declare class RustCalculateFormulaService extends Disposable implements IRustCal
834
850
  private _externalRequestGeneration;
835
851
  private readonly _externalInflight;
836
852
  private readonly _externalCompleted;
837
- constructor(_configService: IConfigService, _currentConfigService: IFormulaCurrentConfigService, _runtimeService: IFormulaRuntimeService, _formulaDependencyGenerator: IFormulaDependencyGenerator, _featureCalculationManagerService: IFeatureCalculationManagerService, _otherFormulaManagerService: IOtherFormulaManagerService, _commandService: ICommandService, _rustEngineSyncController: RustEngineSyncController, _formulaDataModel: FormulaDataModel, _formulaReferenceDataService: IFormulaReferenceDataService, _excelExternalReferenceModel: ExternalReferenceModel, _superTableService: ISuperTableService);
853
+ constructor(_configService: IConfigService, _currentConfigService: IFormulaCurrentConfigService, _runtimeService: IFormulaRuntimeService, _formulaDependencyGenerator: IFormulaDependencyGenerator, _featureCalculationManagerService: IFeatureCalculationManagerService, _otherFormulaManagerService: IOtherFormulaManagerService, _commandService: ICommandService, _rustEngineSyncController: RustEngineSyncController, _formulaDataModel: FormulaDataModel, _formulaReferenceDataService: IFormulaReferenceDataService, _excelExternalReferenceModel: ExternalReferenceModel, _superTableService: ISuperTableService, _definedNamesService: IDefinedNamesService);
838
854
  dispose(): void;
839
855
  stopFormulaExecution(): void;
840
856
  setRuntimeFeatureCellData(featureId: string, featureData: IRuntimeUnitDataType): void;
@@ -862,6 +878,7 @@ declare class RustCalculateFormulaService extends Disposable implements IRustCal
862
878
  private _serializeCellData;
863
879
  private _applyRustOutput;
864
880
  private _applyRustDependencyOutput;
881
+ private _mergeRuntimeUnitData;
865
882
  calculate(formulaString: string): Promise<{} | null>;
866
883
  executeFormulas(formulas: IFormulaStringMap, rowData?: IUnitRowData): Promise<IFormulaExecuteResultMap>;
867
884
  getAllDependencyJson(_rowData?: IUnitRowData): Promise<IFormulaDependencyTreeJson[]>;
@@ -888,7 +905,7 @@ declare class RustCalculateFormulaService extends Disposable implements IRustCal
888
905
  dependents: IFormulaDependencyTreeJson[];
889
906
  inRanges: IFormulaDependencyTreeJson[];
890
907
  }>;
891
- private _formulaStringMapToFormulaData;
908
+ private _formulaStringMapToQueryData;
892
909
  private _formulaExecutionOutputToResultMap;
893
910
  private _getRustDependencyGraph;
894
911
  private _getRustInspectGraph;
package/package.json CHANGED
@@ -1,49 +1,38 @@
1
1
  {
2
- "author": "DreamNum Co., Ltd. <developer@univer.ai>",
3
- "dependencies": {
4
- "@univerjs-pro/engine-formula": "1.0.0-rc.0",
5
- "@univerjs-pro/engine-formula-rust-binding": "1.0.0-insiders.20260910-22fe9c7",
6
- "@univerjs/core": "1.0.0-rc.0",
7
- "@univerjs/engine-formula": "1.0.0-rc.0",
8
- "@univerjs/protocol": "1.0.0-rc.0"
9
- },
10
- "description": "Rust-backed formula engine plugin for Univer",
11
- "files": [
12
- "lib"
13
- ],
14
- "name": "@univerjs-pro/engine-formula-rust",
15
- "peerDependencies": {
16
- "rxjs": ">=7.0.0"
17
- },
18
- "repository": {
19
- "type": "git",
20
- "url": "https://github.com/dream-num/univer-rs"
21
- },
22
- "type": "module",
23
- "version": "1.0.0-rc.0",
24
- "main": "./lib/cjs/index.cjs",
25
- "module": "./lib/es/index.js",
26
- "types": "./lib/types/index.d.ts",
27
- "exports": {
28
- ".": {
29
- "types": "./lib/types/index.d.ts",
30
- "import": "./lib/es/index.js",
31
- "require": "./lib/cjs/index.cjs",
32
- "default": "./lib/es/index.js"
33
- }
34
- },
35
- "publishConfig": {
36
- "main": "./lib/cjs/index.cjs",
37
- "module": "./lib/es/index.js",
38
- "types": "./lib/types/index.d.ts",
39
- "exports": {
40
- ".": {
41
- "types": "./lib/types/index.d.ts",
42
- "import": "./lib/es/index.js",
43
- "require": "./lib/cjs/index.cjs",
44
- "default": "./lib/es/index.js"
45
- }
46
- },
47
- "access": "public"
2
+ "author": "DreamNum Co., Ltd. <developer@univer.ai>",
3
+ "dependencies": {
4
+ "@univerjs-pro/engine-formula": "1.0.0",
5
+ "@univerjs-pro/engine-formula-rust-binding": "1.0.0",
6
+ "@univerjs/core": "1.0.0",
7
+ "@univerjs/engine-formula": "1.0.0",
8
+ "@univerjs/protocol": "1.0.0"
9
+ },
10
+ "description": "Rust-backed formula engine plugin for Univer",
11
+ "files": [
12
+ "lib"
13
+ ],
14
+ "name": "@univerjs-pro/engine-formula-rust",
15
+ "peerDependencies": {
16
+ "rxjs": ">=7.0.0"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "https://github.com/dream-num/univer-rs"
21
+ },
22
+ "type": "module",
23
+ "version": "1.0.0",
24
+ "main": "./lib/cjs/index.cjs",
25
+ "module": "./lib/es/index.js",
26
+ "types": "./lib/types/index.d.ts",
27
+ "exports": {
28
+ ".": {
29
+ "types": "./lib/types/index.d.ts",
30
+ "import": "./lib/es/index.js",
31
+ "require": "./lib/cjs/index.cjs",
32
+ "default": "./lib/es/index.js"
48
33
  }
49
- }
34
+ },
35
+ "publishConfig": {
36
+ "access": "public"
37
+ }
38
+ }