| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- import { Inject as u, ICommandService as f, Injector as _, FBase as C, IConfigService as v, FUniver as m } from "@univerjs/core";
- import { LexerTreeBuilder as x, SetFormulaCalculationStartMutation as l, SetFormulaCalculationStopMutation as p, SetFormulaCalculationNotificationMutation as d, ENGINE_FORMULA_CYCLE_REFERENCE_COUNT as S } from "@univerjs/engine-formula";
- var h = Object.defineProperty, E = Object.getOwnPropertyDescriptor, F = (e, t, r, i) => {
- for (var n = i > 1 ? void 0 : i ? E(t, r) : t, a = e.length - 1, c; a >= 0; a--)
- (c = e[a]) && (n = (i ? c(t, r, n) : c(n)) || n);
- return i && n && h(t, r, n), n;
- }, o = (e, t) => (r, i) => t(r, i, e);
- let s = class extends C {
- constructor(e, t, r, i) {
- super(), this._commandService = e, this._injector = t, this._lexerTreeBuilder = r, this._configService = i, this._initialize();
- }
- _initialize() {
- }
- /**
- * The tree builder for formula string.
- * @type {LexerTreeBuilder}
- */
- get lexerTreeBuilder() {
- return this._lexerTreeBuilder;
- }
- /**
- * Offsets the formula
- * @param {string} formulaString
- * @param {number} refOffsetX
- * @param {number} refOffsetY
- * @param {boolean} [ignoreAbsolute] default is false
- * @example
- * const result = moveFormulaRefOffset('sum(a1,b2)',1,1)
- * // result is 'sum(b2,c3)'
- */
- moveFormulaRefOffset(e, t, r, i) {
- return this._lexerTreeBuilder.moveFormulaRefOffset(e, t, r, i);
- }
- /**
- * Resolves the formula string to a 'node' node
- * @param {string} formulaString
- * @returns {*} {((string | ISequenceNode)[])}
- * @memberof FFormula
- */
- sequenceNodesBuilder(e) {
- return this._lexerTreeBuilder.sequenceNodesBuilder(e) || [];
- }
- /**
- * Start the calculation of the formula.
- */
- executeCalculation() {
- this._commandService.executeCommand(l.id, { commands: [], forceCalculation: !0 }, { onlyLocal: !0 });
- }
- /**
- * Stop the calculation of the formula.
- */
- stopCalculation() {
- this._commandService.executeCommand(p.id, {});
- }
- /**
- * Listening calculation starts.
- * @param callback
- */
- calculationStart(e) {
- return this._commandService.onCommandExecuted((t) => {
- if (t.id === l.id) {
- const r = t.params;
- e(r.forceCalculation);
- }
- });
- }
- /**
- * Listening calculation ends.
- * @param callback
- */
- calculationEnd(e) {
- return this._commandService.onCommandExecuted((t) => {
- if (t.id !== d.id)
- return;
- const r = t.params;
- r.functionsExecutedState !== void 0 && e(r.functionsExecutedState);
- });
- }
- onCalculationEnd() {
- return new Promise((e, t) => {
- const r = setTimeout(() => {
- t(new Error("Calculation end timeout"));
- }, 3e4), i = this.calculationEnd(() => {
- clearTimeout(r), i.dispose(), e();
- });
- });
- }
- /**
- * Listening calculation processing.
- * @param callback
- */
- calculationProcessing(e) {
- return this._commandService.onCommandExecuted((t) => {
- if (t.id !== d.id)
- return;
- const r = t.params;
- r.stageInfo !== void 0 && e(r.stageInfo);
- });
- }
- /**
- * When a formula contains a circular reference, set the maximum number of iterations for the formula calculation.
- * @param maxIteration The maximum number of iterations. The default value is 1.
- * @example
- * ```ts
- * // Set the maximum number of iterations for the formula calculation to 5.
- * // The default value is 1.
- * const formulaEngine = univerAPI.getFormula();
- * formulaEngine.setMaxIteration(5);
- * ```
- */
- setMaxIteration(e) {
- this._configService.setConfig(S, e);
- }
- };
- s = F([
- o(0, u(f)),
- o(1, u(_)),
- o(2, u(x)),
- o(3, v)
- ], s);
- class g extends m {
- getFormula() {
- return this._injector.createInstance(s);
- }
- }
- m.extend(g);
- export {
- s as FFormula
- };
|