@univerjs-pro/engine-formula 1.0.0-alpha.6 → 1.0.0-alpha.7

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.
@@ -0,0 +1,66 @@
1
+ import { FormulaReferenceType } from '@univerjs-pro/engine-formula';
2
+ import { FEnum } from '@univerjs/core/facade';
3
+ /** Formula-reference enums exposed through `univerAPI.Enum`. */
4
+ export interface IFFormulaReferenceEnumMixin {
5
+ /**
6
+ * Reference target kinds accepted by `formula.buildReference()`.
7
+ *
8
+ * @example Select a Sheet range target
9
+ * ```ts
10
+ * const workbook = univerAPI.getActiveWorkbook();
11
+ * if (!workbook) throw new Error('No active workbook.');
12
+ * const shape = workbook.getActiveSheet().getShape('formula-shape-1');
13
+ * if (!shape?.isFormulaShape()) throw new Error('Formula Shape not found.');
14
+ * const formula = univerAPI.getFormula();
15
+ * const reference = formula.buildReference({
16
+ * hostUnitId: workbook.getId(),
17
+ * unit: {
18
+ * unitId: workbook.getId(),
19
+ * formulaQualifier: 'Current Workbook',
20
+ * },
21
+ * target: {
22
+ * kind: univerAPI.Enum.FormulaReferenceType.SHEET_RANGE,
23
+ * sheetName: 'Sheet1',
24
+ * range: { startRow: 0, endRow: 9, startColumn: 0, endColumn: 1 },
25
+ * },
26
+ * });
27
+ * shape.setFormula(`=SUM(${reference})`);
28
+ * ```
29
+ *
30
+ * @example Select a Base table-column target
31
+ * ```ts
32
+ * import type { IFormulaReferenceUnit } from '@univerjs-pro/engine-formula';
33
+ *
34
+ * function setSalesBaseFormula(baseUnit: IFormulaReferenceUnit) {
35
+ * const board = univerAPI.getActiveBoard();
36
+ * if (!board) throw new Error('No active board.');
37
+ * const shape = board.getShape('formula-shape-1');
38
+ * if (!shape?.isFormulaShape()) throw new Error('Formula Shape not found.');
39
+ * const reference = univerAPI.getFormula().buildReference({
40
+ * hostUnitId: board.getId(),
41
+ * unit: baseUnit,
42
+ * target: {
43
+ * kind: univerAPI.Enum.FormulaReferenceType.TABLE_COLUMN,
44
+ * tableName: 'SalesTable',
45
+ * columnName: 'Amount',
46
+ * },
47
+ * });
48
+ * shape.setFormula(`=SUM(${reference})`);
49
+ * }
50
+ *
51
+ * setSalesBaseFormula({
52
+ * unitId: 'sales-base',
53
+ * formulaQualifier: 'Sales Base',
54
+ * });
55
+ * ```
56
+ */
57
+ readonly FormulaReferenceType: typeof FormulaReferenceType;
58
+ }
59
+ /** @ignore */
60
+ export declare class FFormulaReferenceEnumMixin extends FEnum implements IFFormulaReferenceEnumMixin {
61
+ get FormulaReferenceType(): typeof FormulaReferenceType;
62
+ }
63
+ declare module '@univerjs/core/facade' {
64
+ interface FEnum extends IFFormulaReferenceEnumMixin {
65
+ }
66
+ }
@@ -0,0 +1,89 @@
1
+ import type { IBuildFormulaReferenceOptions } from '@univerjs-pro/engine-formula';
2
+ import { FFormula } from '@univerjs/engine-formula/facade';
3
+ /** Formula-reference APIs contributed by Univer Pro. */
4
+ export interface IFFormulaReferenceMixin {
5
+ /**
6
+ * Builds a Sheet-range or structured-table reference fragment.
7
+ *
8
+ * This is a pure text helper. It does not add a leading `=`, mutate a Shape,
9
+ * discover or bind external resources, load a Unit, or start formula calculation.
10
+ *
11
+ * @param {IBuildFormulaReferenceOptions} options Host, caller-provided source Unit, and reference target.
12
+ * @returns {string} A formula reference fragment.
13
+ *
14
+ * @example Build a cross-unit Sheet range from an externally supplied Unit
15
+ * ```ts
16
+ * import type { IFormulaReferenceUnit } from '@univerjs-pro/engine-formula';
17
+ *
18
+ * function setSalesFormula(salesUnit: IFormulaReferenceUnit) {
19
+ * const board = univerAPI.getActiveBoard();
20
+ * if (!board) {
21
+ * throw new Error('No active board.');
22
+ * }
23
+ *
24
+ * const shape = board.getShape('formula-shape-1');
25
+ * if (!shape?.isFormulaShape()) {
26
+ * throw new Error('Formula Shape not found.');
27
+ * }
28
+ *
29
+ * const reference = univerAPI.getFormula().buildReference({
30
+ * hostUnitId: board.getId(),
31
+ * unit: salesUnit,
32
+ * target: {
33
+ * kind: univerAPI.Enum.FormulaReferenceType.SHEET_RANGE,
34
+ * sheetName: 'Sales',
35
+ * range: { startRow: 1, endRow: 9, startColumn: 1, endColumn: 1 },
36
+ * },
37
+ * });
38
+ * shape.setFormula(`=SUM(${reference})`);
39
+ * }
40
+ *
41
+ * setSalesFormula({
42
+ * unitId: 'sales-workbook',
43
+ * formulaQualifier: 'Sales Workbook',
44
+ * });
45
+ * ```
46
+ *
47
+ * @example Build a cross-unit Base column from an externally supplied Unit
48
+ * ```ts
49
+ * import type { IFormulaReferenceUnit } from '@univerjs-pro/engine-formula';
50
+ *
51
+ * function setSalesFormula(salesUnit: IFormulaReferenceUnit) {
52
+ * const document = univerAPI.getActiveDocument();
53
+ * if (!document) {
54
+ * throw new Error('No active document.');
55
+ * }
56
+ *
57
+ * const shape = document.getShape('formula-shape-1');
58
+ * if (!shape?.isFormulaShape()) {
59
+ * throw new Error('Formula Shape not found.');
60
+ * }
61
+ *
62
+ * const reference = univerAPI.getFormula().buildReference({
63
+ * hostUnitId: document.getId(),
64
+ * unit: salesUnit,
65
+ * target: {
66
+ * kind: univerAPI.Enum.FormulaReferenceType.TABLE_COLUMN,
67
+ * tableName: 'SalesTable',
68
+ * columnName: 'Amount',
69
+ * },
70
+ * });
71
+ * shape.setFormula(`=SUM(${reference})`);
72
+ * }
73
+ *
74
+ * setSalesFormula({
75
+ * unitId: 'sales-base',
76
+ * formulaQualifier: 'Sales Base',
77
+ * });
78
+ * ```
79
+ */
80
+ buildReference(options: IBuildFormulaReferenceOptions): string;
81
+ }
82
+ /** @ignore */
83
+ export declare class FFormulaReferenceMixin extends FFormula implements IFFormulaReferenceMixin {
84
+ buildReference(options: IBuildFormulaReferenceOptions): string;
85
+ }
86
+ declare module '@univerjs/engine-formula/facade' {
87
+ interface FFormula extends IFFormulaReferenceMixin {
88
+ }
89
+ }
@@ -1,3 +1,7 @@
1
1
  import '@univerjs/engine-formula/facade';
2
+ import './f-enum';
3
+ import './f-formula';
4
+ export type { IFFormulaReferenceEnumMixin } from './f-enum';
5
+ export type { IFFormulaReferenceMixin } from './f-formula';
2
6
  export { FFormula } from '@univerjs/engine-formula/facade';
3
- export type * from '@univerjs/engine-formula/facade';
7
+ export type { IFUniverEngineFormulaMixin } from '@univerjs/engine-formula/facade';
@@ -14,6 +14,8 @@ export type { IExternalReferencePrefetchLimits, IExternalReferencePrefetchResult
14
14
  export { ExternalFormulaUnitReferenceResolver } from './services/external-unit-reference-resolver.service';
15
15
  export { createUnavailableReferenceDataResponse, FormulaReferenceDataProviderRegistry, IFormulaReferenceDataProviderRegistry, IFormulaReferenceDataService, } from './services/formula-reference-data.service';
16
16
  export type { FormulaReferenceDataFreshness, FormulaReferenceDataSource, IFormulaReferenceDataCell, IFormulaReferenceDataProvider, IFormulaReferenceDataRangeRequest, IFormulaReferenceDataRequest, IFormulaReferenceDataResponse, IFormulaReferenceDataSheet, } from './services/formula-reference-data.service';
17
+ export { buildFormulaReference, FormulaReferenceType, } from './services/formula-reference-unit.service';
18
+ export type { FormulaReferenceTarget, IBuildFormulaReferenceOptions, IFormulaReferenceUnit, IFormulaSheetRangeReferenceTarget, IFormulaTableColumnReferenceTarget, } from './services/formula-reference-unit.service';
17
19
  export { MainFormulaReferenceDataService } from './services/main-formula-reference-data.service';
18
20
  export { RemoveSuperTableMutation, SetFormulaCalculationResultMutation, SetFormulaCalculationStartMutation, SetSuperTableMutation, SetTriggerFormulaCalculationStartMutation, } from '@univerjs/engine-formula';
19
21
  export type { ISetFormulaCalculationResultMutation, ISetFormulaCalculationStartMutation, ISuperTable, } from '@univerjs/engine-formula';
@@ -0,0 +1,43 @@
1
+ import type { IRange } from '@univerjs/core';
2
+ /** The kind of reference text produced by {@link buildFormulaReference}. */
3
+ export declare enum FormulaReferenceType {
4
+ SHEET_RANGE = "sheet-range",
5
+ TABLE_COLUMN = "table-column"
6
+ }
7
+ /** Explicit Unit identity supplied by the caller when serializing a formula reference. */
8
+ export interface IFormulaReferenceUnit {
9
+ /** Name written into a formula unit qualifier. */
10
+ formulaQualifier: string;
11
+ /** Stable Unit identifier used to detect a current-Unit reference. */
12
+ unitId?: string;
13
+ }
14
+ /** Sheet-range reference target accepted by {@link buildFormulaReference}. */
15
+ export interface IFormulaSheetRangeReferenceTarget {
16
+ kind: FormulaReferenceType.SHEET_RANGE;
17
+ sheetName: string;
18
+ range: IRange;
19
+ }
20
+ /** Base/structured-table reference target accepted by {@link buildFormulaReference}. */
21
+ export interface IFormulaTableColumnReferenceTarget {
22
+ kind: FormulaReferenceType.TABLE_COLUMN;
23
+ tableName: string;
24
+ columnName: string;
25
+ /** Optional final column for a contiguous structured-reference range. */
26
+ endColumnName?: string;
27
+ }
28
+ /** A Sheet range or Base structured-reference target serialized by {@link buildFormulaReference}. */
29
+ export type FormulaReferenceTarget = IFormulaSheetRangeReferenceTarget | IFormulaTableColumnReferenceTarget;
30
+ /** Input used to serialize a formula reference fragment. */
31
+ export interface IBuildFormulaReferenceOptions {
32
+ /** Unit that owns the formula. */
33
+ hostUnitId: string;
34
+ /** Unit identity supplied explicitly by the caller. */
35
+ unit: IFormulaReferenceUnit;
36
+ /** Sheet range or structured-table column to serialize. */
37
+ target: FormulaReferenceTarget;
38
+ }
39
+ /**
40
+ * Serializes a formula reference fragment without discovering, mutating, or loading a Unit.
41
+ * The returned text does not include a leading `=` or a wrapping function.
42
+ */
43
+ export declare function buildFormulaReference(options: IBuildFormulaReferenceOptions): string;
package/lib/umd/facade.js CHANGED
@@ -1 +1 @@
1
- (function(_0x37526e,_0x49949e){var _0x2cd36c=_0x42ba,_0x1c230c=_0x37526e();while(!![]){try{var _0x24ce21=-parseInt(_0x2cd36c(0x1bd))/0x1*(-parseInt(_0x2cd36c(0x1c5))/0x2)+parseInt(_0x2cd36c(0x1c1))/0x3+parseInt(_0x2cd36c(0x1c3))/0x4+-parseInt(_0x2cd36c(0x1bb))/0x5*(-parseInt(_0x2cd36c(0x1bc))/0x6)+parseInt(_0x2cd36c(0x1c7))/0x7*(-parseInt(_0x2cd36c(0x1c0))/0x8)+-parseInt(_0x2cd36c(0x1be))/0x9+-parseInt(_0x2cd36c(0x1cb))/0xa;if(_0x24ce21===_0x49949e)break;else _0x1c230c['push'](_0x1c230c['shift']());}catch(_0x5b2744){_0x1c230c['push'](_0x1c230c['shift']());}}}(_0x4657,0x4efb1),function(_0x5c7c5a,_0x1ee934){var _0x404a07=_0x42ba;typeof exports==_0x404a07(0x1ca)&&typeof module<'u'?_0x1ee934(exports,require('@univerjs/engine-formula/facade')):typeof define==_0x404a07(0x1c8)&&define['amd']?define([_0x404a07(0x1c6),'@univerjs/engine-formula/facade'],_0x1ee934):(_0x5c7c5a=typeof globalThis<'u'?globalThis:_0x5c7c5a||self,_0x1ee934(_0x5c7c5a[_0x404a07(0x1ba)]={},_0x5c7c5a[_0x404a07(0x1c9)]));}(this,function(_0x11117c,_0x2e21ce){var _0x4c0648=_0x42ba;Object[_0x4c0648(0x1c2)](_0x11117c,Symbol[_0x4c0648(0x1c4)],{'value':_0x4c0648(0x1cc)}),Object[_0x4c0648(0x1c2)](_0x11117c,_0x4c0648(0x1bf),{'enumerable':!0x0,'get':function(){return _0x2e21ce['FFormula'];}});}));function _0x42ba(_0x39debb,_0xd21eb7){_0x39debb=_0x39debb-0x1ba;var _0x465746=_0x4657();var _0x42ba67=_0x465746[_0x39debb];return _0x42ba67;}function _0x4657(){var _0x2a835c=['exports','1309oCXuon','function','UniverEngineFormulaFacade','object','1628010wNLTqH','Module','UniverProEngineFormulaFacade','5NUPmRo','1922466eUfmQa','546727YmQiTG','2904156KGbaZG','FFormula','18344otEyRq','37998yfomXo','defineProperty','1431908CPVKPs','toStringTag','2eTRUyW'];_0x4657=function(){return _0x2a835c;};return _0x4657();}
1
+ function _0x360e(_0x234ce7,_0x2ae612){_0x234ce7=_0x234ce7-0x174;var _0x59feb1=_0x59fe();var _0x360e2b=_0x59feb1[_0x234ce7];return _0x360e2b;}(function(_0x5c6164,_0x40bb74){var _0x5122ab=_0x360e,_0x1e6079=_0x5c6164();while(!![]){try{var _0x289760=parseInt(_0x5122ab(0x17a))/0x1*(parseInt(_0x5122ab(0x179))/0x2)+-parseInt(_0x5122ab(0x18c))/0x3*(-parseInt(_0x5122ab(0x183))/0x4)+-parseInt(_0x5122ab(0x182))/0x5*(-parseInt(_0x5122ab(0x187))/0x6)+parseInt(_0x5122ab(0x18a))/0x7+parseInt(_0x5122ab(0x176))/0x8+parseInt(_0x5122ab(0x175))/0x9*(-parseInt(_0x5122ab(0x17c))/0xa)+-parseInt(_0x5122ab(0x180))/0xb;if(_0x289760===_0x40bb74)break;else _0x1e6079['push'](_0x1e6079['shift']());}catch(_0xc3f200){_0x1e6079['push'](_0x1e6079['shift']());}}}(_0x59fe,0x985e0),function(_0x557913,_0x16f5d3){var _0x26273d=_0x360e;typeof exports==_0x26273d(0x18f)&&typeof module<'u'?_0x16f5d3(exports,require('@univerjs/engine-formula/facade'),require('@univerjs-pro/engine-formula'),require('@univerjs/core/facade')):typeof define==_0x26273d(0x186)&&define[_0x26273d(0x174)]?define([_0x26273d(0x188),'@univerjs/engine-formula/facade',_0x26273d(0x17f),_0x26273d(0x178)],_0x16f5d3):(_0x557913=typeof globalThis<'u'?globalThis:_0x557913||self,_0x16f5d3(_0x557913[_0x26273d(0x185)]={},_0x557913[_0x26273d(0x18d)],_0x557913[_0x26273d(0x177)],_0x557913[_0x26273d(0x18e)]));}(this,function(_0x40992c,_0x5d11bb,_0x370b12,_0x17a016){var _0x3ff4da=_0x360e;Object[_0x3ff4da(0x17e)](_0x40992c,Symbol[_0x3ff4da(0x17b)],{'value':_0x3ff4da(0x189)});var _0x5235e5=class extends _0x17a016[_0x3ff4da(0x181)]{get[_0x3ff4da(0x184)](){return _0x370b12['FormulaReferenceType'];}};_0x17a016[_0x3ff4da(0x181)]['extend'](_0x5235e5);var _0x2cebcb=class extends _0x5d11bb['FFormula']{[_0x3ff4da(0x17d)](_0x533eb6){return(0x0,_0x370b12['buildFormulaReference'])(_0x533eb6);}};_0x5d11bb['FFormula']['extend'](_0x2cebcb),Object[_0x3ff4da(0x17e)](_0x40992c,_0x3ff4da(0x18b),{'enumerable':!0x0,'get':function(){var _0x22a97e=_0x3ff4da;return _0x5d11bb[_0x22a97e(0x18b)];}});}));function _0x59fe(){var _0x887e35=['Module','6458144QOocmH','FFormula','51KyLhxT','UniverEngineFormulaFacade','UniverCoreFacade','object','amd','3576411jnpOKF','9319768vIRcNv','UniverProEngineFormula','@univerjs/core/facade','1439978XYSlxI','1ZXtbNY','toStringTag','30RmRCok','buildReference','defineProperty','@univerjs-pro/engine-formula','27556463jBYGdI','FEnum','1534325HxfwuH','283988NkoEyw','FormulaReferenceType','UniverProEngineFormulaFacade','function','6ekqkjF','exports'];_0x59fe=function(){return _0x887e35;};return _0x59fe();}