@univerjs/sheets-formula 0.1.6 → 0.1.8

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.
Files changed (33) hide show
  1. package/README.md +25 -18
  2. package/lib/cjs/index.js +8 -8
  3. package/lib/es/index.js +2867 -2890
  4. package/lib/types/commands/mutations/formula.mutation.d.ts +10 -0
  5. package/lib/types/commands/operations/__tests__/create-command-test-bed.d.ts +1 -1
  6. package/lib/types/controllers/__tests__/create-command-test-bed.d.ts +1 -1
  7. package/lib/types/controllers/active-dirty.controller.d.ts +6 -2
  8. package/lib/types/controllers/formula-clipboard.controller.d.ts +5 -4
  9. package/lib/types/controllers/prompt.controller.d.ts +7 -2
  10. package/lib/types/controllers/trigger-calculation.controller.d.ts +9 -1
  11. package/lib/types/controllers/update-formula.controller.d.ts +3 -5
  12. package/lib/types/controllers/utils/offset-formula-data.d.ts +8 -31
  13. package/lib/types/controllers/utils/ref-range-formula.d.ts +33 -5
  14. package/lib/types/formula-ui-plugin.d.ts +5 -5
  15. package/lib/types/index.d.ts +2 -0
  16. package/lib/types/locale/en-US.d.ts +17 -17
  17. package/lib/types/locale/function-list/information/en-US.d.ts +2 -10
  18. package/lib/types/locale/function-list/information/ja-JP.d.ts +2 -10
  19. package/lib/types/locale/function-list/information/zh-CN.d.ts +2 -10
  20. package/lib/types/locale/function-list/statistical/en-US.d.ts +14 -2
  21. package/lib/types/locale/function-list/statistical/ja-JP.d.ts +14 -2
  22. package/lib/types/locale/function-list/statistical/zh-CN.d.ts +14 -2
  23. package/lib/types/locale/function-list/text/en-US.d.ts +1 -5
  24. package/lib/types/locale/function-list/text/ja-JP.d.ts +1 -5
  25. package/lib/types/locale/function-list/text/zh-CN.d.ts +1 -5
  26. package/lib/types/locale/zh-CN.d.ts +17 -17
  27. package/lib/types/services/formula-common.d.ts +19 -0
  28. package/lib/types/services/register-other-formula.service.d.ts +27 -0
  29. package/lib/umd/index.js +8 -8
  30. package/package.json +27 -28
  31. package/lib/types/controllers/numfmt-formula-display.controller.d.ts +0 -14
  32. package/lib/types/controllers/utils/redo-undo-formula-data.d.ts +0 -5
  33. /package/lib/types/controllers/utils/__tests__/{redo-undo-formula-data.spec.d.ts → ref-range-formula.spec.d.ts} +0 -0
package/README.md CHANGED
@@ -617,7 +617,7 @@ In addition to registering through the `UniverFormulaEnginePlugin` configuration
617
617
  First of all, there is no need to register `CustomFunctionController` in `plugin.ts`. Create a new `custom-function-plugin.ts` in the same directory, specifically for registering `CustomFunctionController`.
618
618
 
619
619
  ```ts
620
- import { Plugin, PluginType } from '@univerjs/core';
620
+ import { Plugin, UniverInstanceType } from '@univerjs/core';
621
621
  import type { Dependency } from '@wendellhu/redi';
622
622
  import { Inject, Injector } from '@wendellhu/redi';
623
623
 
@@ -625,10 +625,11 @@ import { FORMULA_UI_PLUGIN_NAME } from './common/plugin-name';
625
625
  import { CustomFunctionController } from './controllers/custom-function.controller';
626
626
 
627
627
  export class UniverSheetsCustomFunctionPlugin extends Plugin {
628
- static override type = PluginType.Sheet;
628
+ static override pluginName = FORMULA_UI_PLUGIN_NAME
629
+ static override type = UniverInstanceType.UNIVER_SHEET;
629
630
 
630
631
  constructor(@Inject(Injector) override readonly _injector: Injector) {
631
- super(FORMULA_UI_PLUGIN_NAME);
632
+ super();
632
633
  }
633
634
 
634
635
  initialize(): void {
@@ -719,7 +720,7 @@ To implement a formula, you need to add formula description, internationalizatio
719
720
  - Extract the `description` from the content, as some Excel descriptions are lengthy and need simplification.
720
721
  - `abstract` and `links` generally do not need modification.
721
722
  - `aliasFunctionName` is optional; most formulas do not need to be filled (or can be set for aliases in specific countries). Currently, there is no documentation for formula aliases. Currently I have found a function translation plug-in that may provide similar functions [Excel Functions Translator](https://support.microsoft.com/en-us/office/excel-functions-translator-f262d0c0-991c-485b-89b6-32cc8d326889)
722
- - `functionParameter` needs a name for each parameter. We recommend varying names based on the parameter's meaning, e.g., use `number` for a numeric parameter (if there is only one) or `number1`, `number2` for multiple numeric parameters. Use `range` for a range, `criteria` for conditions, and `sum_range` for the sum range (separated by `_` for multiple words).
723
+ - `functionParameter` needs a name for each parameter. We recommend varying names based on the parameter's meaning, e.g., use `number` for a numeric parameter (if there is only one) or `number1`, `number2` for multiple numeric parameters. Use `range` for a range, `criteria` for conditions, and `sumRange` for the sum range, use `camelCase`. For specific parameter content, the English format of `name` uses the underlined format `sum_range`, other languages use the translated text, and `detail` uses all translations.
723
724
  - Some Chinese translations in the Office function documentation are machine-translated and may be unclear. Modify as needed. For example, `单元格参考` (Cell Reference) should be translated as `单元格引用`. Numeric type parameters are uniformly translated as: `数值`.
724
725
  - Do not end `abstract` with a period (used in the search list when users input cells), but end `description` and `detail` with a period (used in descriptions).
725
726
  - Capitalize the first letter of English sentences.
@@ -743,11 +744,11 @@ To implement a formula, you need to add formula description, internationalizatio
743
744
 
744
745
  Location: [packages/engine-formula/src/functions/math/sumif/index.ts](https://github.com/dream-num/univer/blob/dev/packages/engine-formula/src/functions/math/sumif/index.ts).
745
746
 
746
- Create a new folder for the formula under the current formula category, with one folder per formula. Then create an `index.ts` file to write the formula algorithm. Use camel case for the formula `class` name, considering the formula as one word. If a formula contains `_` or `.`, treat it as two words, such as:
747
+ Create a new formula folder under the classification folder of the current formula. The folder name is the same as the formula, named with `kebab-case`, one folder for each formula. Then create a new `index.ts` file to write the formula algorithm. The name of the formula `class` adopts `PascalCase`. The formula is considered to be one word, and the formula with `_` or `.` is considered to be two words such as
747
748
 
748
- - `SUMIF` => `Sumif`
749
- - `NETWORKDAYS.INTL` => `Networkdays_Intl`
750
- - `ARRAY_CONSTRAIN` => `Array_Constrain`
749
+ - `SUMIF` => folder `sumif`, class `Sumif`
750
+ - `NETWORKDAYS.INTL` => folder `networkdays-intl`, class `NetworkdaysIntl`
751
+ - `ARRAY_CONSTRAIN` => folder `array-constrain`, class `ArrayConstrain`
751
752
 
752
753
  Create a `__tests__` folder at the same level to write unit tests. After writing, remember to add the formula algorithm and function name mapping in the `function-map` file in the category directory to register the formula algorithm.
753
754
 
@@ -772,20 +773,26 @@ To implement a formula, you need to add formula description, internationalizatio
772
773
  - After selecting `SUMIF` or entering `=sumif(`, trigger the formula details popup and carefully check the contents.
773
774
  - Select the data range, trigger the calculation, and check if the formula calculation result is correct.
774
775
 
775
- #### Considerations for Formula Implementation
776
+ ### Considerations for Formula Implementation
776
777
 
777
- - Any formula's input and output can be `A1`, `A1:B10`, etc. When researching Excel, consider all cases, such as `=SIN(A1:B10)`, which expands to the calculated range.
778
- - For example, the `XLOOKUP` function requires at least one of the rows or columns of its two inputs to be of equal size for matrix calculation.
779
- - For example, the `SUMIF` function, although commonly used for summation, can expand based on the second parameter.
778
+ - For most formula rules, please refer to the latest version of Excel. If there are any unreasonable rules, please refer to Google Sheets.
779
+ - The input and output parameters of any formula can be `A1`, `A1:B10`, and the cell content may also be numbers, strings, Boolean values, empty cells, error values, arrays, etc., although the formula tutorial explains In order to identify fixed data types, the program implementation needs to be compatible. When researching Excel, consider all cases, such as `=SIN(A1:B10)`, which expands to the calculated range.
780
+ - For example, the `XLOOKUP` function requires at least one of the rows or columns of its two inputs to be of equal size for matrix calculation.
781
+ - For example, the `SUMIF` function, although commonly used for summation, can expand based on the second parameter.
780
782
  ![sumif array](./assets/sumif-array.png)
781
783
  ![sumif array result](./assets/sumif-array-result.png)
782
- - Excel formula calculation is becoming more like numpy, for example:
784
+ - Excel formula calculation is becoming more like numpy, for example:
783
785
  ![numpy](./assets/numpy.png)
784
- - For numerical calculations in formulas, use built-in methods and try to avoid obtaining values for manual calculation. Because formula parameters can be values, arrays, or references. You can refer to existing `sum` and `minus` functions.
785
- - Precision issues: The formula introduces `big.js`, and using built-in methods will call this library. However, it is nearly 100 times slower than native calculations. Therefore, for methods like `sin`, it is advisable to use native implementations.
786
- - For custom calculations, use the `product` function, suitable for calculating two input parameters. Call `map` to iterate over the values for changes to a parameter's own values.
787
-
788
- #### Formula Basic Tools
786
+ - For numerical calculations in formulas, use built-in methods and try to avoid obtaining values for manual calculation. Because formula parameters can be values, arrays, or references. You can refer to existing `sum` and `minus` functions.
787
+ - Precision issues: The formula introduces `big.js`, and using built-in methods will call this library. However, it is nearly 100 times slower than native calculations. Therefore, for methods like `sin`, it is advisable to use native implementations.
788
+ - For custom calculations, use the `product` function, suitable for calculating two input parameters. Call `map` to iterate over the values for changes to a parameter's own values.
789
+ - Formula algorithm supports two configurations `needsExpandParams` and `needsReferenceObject`
790
+ - `needsExpandParams`: Whether the function needs to expand parameters, mainly handles situations where the `LOOKUP` function needs to handle vectors of different sizes
791
+ - `needsReferenceObject`: Whether the function needs to pass in a reference object. After setting, `BaseReferenceObject` will not be converted into `ArrayValueObject` but will be passed directly into the formula algorithm, such as the `OFFSET` function
792
+ - Formula calculation errors will return fixed types of errors, such as `#NAME?`, `#VALUE!`, which need to be aligned with Excel, because there are functions `ISERR`, `ISNA`, etc. that determine the error type. If the type is not specified correctly, the result will be It may be different.
793
+ - In the formula algorithm, even if it is a required parameter, it is necessary to intercept the case of `null` and return the error `#N/A`, because the user may not enter any parameters. This behavior will be intercepted in Excel and `#N/A` will be returned in Google Sheets. We refer to Google Sheets.
794
+
795
+ ### Formula Basic Tools
789
796
 
790
797
  1. `ValueObjectFactory` is used to automatically recognize parameter formats and create a parameter instance. Use `RangeReferenceObject` to create parameter instances for range-type data.
791
798
  2. The array `toArrayValueObject` can be operated directly with values to get a new array.