@univerjs/core 0.4.1 → 0.4.2-nightly.202410301606

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 (42) hide show
  1. package/lib/es/index.js +2653 -1711
  2. package/lib/types/common/__tests__/interceptor.spec.d.ts +16 -0
  3. package/lib/types/common/const.d.ts +1 -0
  4. package/lib/types/common/interceptor.d.ts +17 -0
  5. package/lib/types/docs/data-model/json-x/json-x.d.ts +2 -2
  6. package/lib/types/docs/data-model/text-x/__tests__/apply.spec.d.ts +16 -0
  7. package/lib/types/docs/data-model/text-x/__tests__/transform-paragraph.spec.d.ts +16 -0
  8. package/lib/types/docs/data-model/text-x/__tests__/transform-textrun.spec.d.ts +16 -0
  9. package/lib/types/docs/data-model/text-x/action-types.d.ts +0 -5
  10. package/lib/types/docs/data-model/text-x/apply-utils/update-apply.d.ts +1 -1
  11. package/lib/types/docs/data-model/text-x/build-utils/custom-range.d.ts +9 -1
  12. package/lib/types/docs/data-model/text-x/build-utils/index.d.ts +3 -3
  13. package/lib/types/docs/data-model/text-x/text-x.d.ts +4 -4
  14. package/lib/types/docs/data-model/text-x/transform-utils.d.ts +7 -1
  15. package/lib/types/docs/data-model/utils.d.ts +20 -0
  16. package/lib/types/facade/f-base.d.ts +26 -0
  17. package/lib/types/facade/f-hooks.d.ts +57 -0
  18. package/lib/types/facade/f-univer.d.ts +76 -0
  19. package/lib/types/index.d.ts +6 -3
  20. package/lib/types/services/config/config.service.d.ts +10 -1
  21. package/lib/types/services/permission/permission.service.d.ts +3 -0
  22. package/lib/types/services/permission/type.d.ts +2 -0
  23. package/lib/types/services/resource-loader/resource-loader.service.d.ts +3 -3
  24. package/lib/types/shared/__tests__/compose.spec.d.ts +16 -0
  25. package/lib/types/shared/command-enum.d.ts +1 -2
  26. package/lib/types/shared/lifecycle.d.ts +1 -1
  27. package/lib/types/shared/r-tree.d.ts +21 -4
  28. package/lib/types/shared/rectangle.d.ts +1 -0
  29. package/lib/types/shared/rxjs.d.ts +1 -0
  30. package/lib/types/shared/tools.d.ts +9 -2
  31. package/lib/types/sheets/column-manager.d.ts +19 -2
  32. package/lib/types/sheets/row-manager.d.ts +22 -4
  33. package/lib/types/sheets/typedef.d.ts +32 -2
  34. package/lib/types/sheets/util.d.ts +35 -0
  35. package/lib/types/sheets/view-model.d.ts +2 -2
  36. package/lib/types/sheets/worksheet.d.ts +84 -2
  37. package/lib/types/types/enum/data-validation-type.d.ts +2 -1
  38. package/lib/types/types/interfaces/i-document-data.d.ts +3 -2
  39. package/lib/umd/index.js +9 -9
  40. package/package.json +10 -13
  41. package/LICENSE +0 -176
  42. package/lib/cjs/index.js +0 -10
@@ -1,5 +1,6 @@
1
1
  import { IObjectArrayPrimitiveType } from '../shared/object-matrix';
2
2
  import { Nullable } from '../shared/types';
3
+ import { IStyleData } from '../types/interfaces';
3
4
  import { IColumnData, IRange, IWorksheetData } from './typedef';
4
5
  /**
5
6
  * Manage configuration information of all columns, get column width, column length, set column width, etc.
@@ -14,6 +15,18 @@ export declare class ColumnManager {
14
15
  */
15
16
  getColumnData(): IObjectArrayPrimitiveType<Partial<IColumnData>>;
16
17
  getColVisible(colPos: number): boolean;
18
+ /**
19
+ * Get the column style
20
+ * @param {number} col Column index
21
+ * @returns {string | Nullable<IStyleData>} Style data, may be undefined
22
+ */
23
+ getColumnStyle(col: number): Nullable<string | IStyleData>;
24
+ /**
25
+ * Set the set column default style
26
+ * @param {number} col Column index
27
+ * @param {string | Nullable<IStyleData>} style Style data
28
+ */
29
+ setColumnStyle(col: number, style: string | Nullable<IStyleData>): void;
17
30
  /**
18
31
  * Get all hidden columns
19
32
  * @param start Start index
@@ -43,13 +56,17 @@ export declare class ColumnManager {
43
56
  /**
44
57
  * get given column data
45
58
  * @param columnPos column index
46
- * @returns
47
59
  */
48
60
  getColumn(columnPos: number): Nullable<Partial<IColumnData>>;
61
+ /**
62
+ * Remove column data of given column
63
+ * @param columnPos
64
+ */
65
+ removeColumn(columnPos: number): void;
49
66
  /**
50
67
  * get given column data or create a column data when it's null
51
68
  * @param columnPos column index
52
- * @returns
69
+ * @returns {Partial<IColumnData>} columnData
53
70
  */
54
71
  getColumnOrCreate(columnPos: number): Partial<IColumnData>;
55
72
  }
@@ -1,7 +1,8 @@
1
- import { IObjectArrayPrimitiveType } from '../shared/object-matrix';
2
- import { IRange, IRowData, IWorksheetData } from './typedef';
3
1
  import { Nullable } from '../shared/types';
2
+ import { IStyleData } from '../types/interfaces';
4
3
  import { SheetViewModel } from './view-model';
4
+ import { IObjectArrayPrimitiveType } from '../shared/object-matrix';
5
+ import { IRange, IRowData, IWorksheetData } from './typedef';
5
6
  /**
6
7
  * Manage configuration information of all rows, get row height, row length, set row height, etc.
7
8
  */
@@ -15,6 +16,18 @@ export declare class RowManager {
15
16
  * @returns
16
17
  */
17
18
  getRowData(): IObjectArrayPrimitiveType<Partial<IRowData>>;
19
+ /**
20
+ * Get the row style
21
+ * @param {number} row Row index
22
+ * @returns {string | Nullable<IStyleData>} Style data, may be undefined
23
+ */
24
+ getRowStyle(row: number): Nullable<string | IStyleData>;
25
+ /**
26
+ * Set row default style
27
+ * @param {number} row The row index
28
+ * @param {string | Nullable<IStyleData>} style The style data
29
+ */
30
+ setRowStyle(row: number, style: string | Nullable<IStyleData>): void;
18
31
  getRowDatas(rowPos: number, numRows: number): IObjectArrayPrimitiveType<Partial<IRowData>>;
19
32
  getRowHeight(rowPos: number): number;
20
33
  getRowHeight(rowPos: number, count: number): number;
@@ -24,10 +37,15 @@ export declare class RowManager {
24
37
  * @returns {Nullable<Partial<IRowData>>} rowData
25
38
  */
26
39
  getRow(rowPos: number): Nullable<Partial<IRowData>>;
40
+ /**
41
+ * Remove row data of given row
42
+ * @param rowPos
43
+ */
44
+ removeRow(rowPos: number): void;
27
45
  /**
28
46
  * Get given row data or create a row data when it's null
29
47
  * @param rowPos row index
30
- * @returns
48
+ * @returns {Partial<IRowData>} rowData
31
49
  */
32
50
  getRowOrCreate(rowPos: number): Partial<IRowData>;
33
51
  /**
@@ -47,7 +65,7 @@ export declare class RowManager {
47
65
  getRowRawVisible(row: number): boolean;
48
66
  /**
49
67
  * Get count of row in the sheet
50
- * @returns
68
+ * @returns {number} row count
51
69
  */
52
70
  getSize(): number;
53
71
  }
@@ -1,4 +1,3 @@
1
- import { BooleanNumber, CellValueType } from '../types/enum';
2
1
  import { IResources } from '../services/resource-manager/type';
3
2
  import { IObjectArrayPrimitiveType, IObjectMatrixPrimitiveType, Nullable } from '../shared';
4
3
  import { LocaleType } from '../types/enum/locale-type';
@@ -6,6 +5,7 @@ import { IDocumentData } from '../types/interfaces';
6
5
  import { ICellCustomRender } from '../types/interfaces/i-cell-custom-render';
7
6
  import { ICellValidationData } from '../types/interfaces/i-cell-validation-data';
8
7
  import { IStyleData } from '../types/interfaces/i-style-data';
8
+ import { BooleanNumber, CellValueType } from '../types/enum';
9
9
  /**
10
10
  * Snapshot of a workbook.
11
11
  */
@@ -43,6 +43,10 @@ export interface IWorkbookData {
43
43
  sheets: {
44
44
  [sheetId: string]: Partial<IWorksheetData>;
45
45
  };
46
+ /**
47
+ * @property {string|Nullable<IStyleData>} [defaultStyle] - Default style id or style data of Workbook.
48
+ */
49
+ defaultStyle?: Nullable<IStyleData> | string;
46
50
  /**
47
51
  * Resources of the Univer Sheet. It is used to store the data of other plugins.
48
52
  */
@@ -85,6 +89,10 @@ export interface IWorksheetData {
85
89
  cellData: IObjectMatrixPrimitiveType<ICellData>;
86
90
  rowData: IObjectArrayPrimitiveType<Partial<IRowData>>;
87
91
  columnData: IObjectArrayPrimitiveType<Partial<IColumnData>>;
92
+ /**
93
+ * @property {string|Nullable<IStyleData>} [defaultStyle] - Default style id or style data of Worksheet.
94
+ */
95
+ defaultStyle?: Nullable<IStyleData> | string;
88
96
  rowHeader: {
89
97
  width: number;
90
98
  hidden?: BooleanNumber;
@@ -96,6 +104,7 @@ export interface IWorksheetData {
96
104
  showGridlines: BooleanNumber;
97
105
  rightToLeft: BooleanNumber;
98
106
  }
107
+ export type CustomData = Nullable<Record<string, any>>;
99
108
  /**
100
109
  * Properties of row data
101
110
  */
@@ -116,6 +125,14 @@ export interface IRowData {
116
125
  * hidden
117
126
  */
118
127
  hd?: BooleanNumber;
128
+ /**
129
+ * style id
130
+ */
131
+ s?: Nullable<IStyleData | string>;
132
+ /**
133
+ * User stored custom fields
134
+ */
135
+ custom?: CustomData;
119
136
  }
120
137
  export interface IRowAutoHeightInfo {
121
138
  row: number;
@@ -133,6 +150,18 @@ export interface IColumnData {
133
150
  * hidden
134
151
  */
135
152
  hd?: BooleanNumber;
153
+ /**
154
+ * style id
155
+ */
156
+ s?: Nullable<IStyleData | string>;
157
+ /**
158
+ * User stored custom fields
159
+ */
160
+ custom?: CustomData;
161
+ }
162
+ export interface IColAutoWidthInfo {
163
+ col: number;
164
+ width?: number;
136
165
  }
137
166
  /**
138
167
  * Cell value type
@@ -165,7 +194,7 @@ export interface ICellData {
165
194
  /**
166
195
  * User stored custom fields
167
196
  */
168
- custom?: Nullable<Record<string, any>>;
197
+ custom?: CustomData;
169
198
  }
170
199
  export interface ICellMarksStyle {
171
200
  color: string;
@@ -185,6 +214,7 @@ export interface ICellDataForSheetInterceptor extends ICellData {
185
214
  markers?: ICellMarks;
186
215
  customRender?: Nullable<ICellCustomRender[]>;
187
216
  interceptorAutoHeight?: () => number | undefined;
217
+ interceptorAutoWidth?: () => number | undefined;
188
218
  /**
189
219
  * can cell be covered when sibling is overflow
190
220
  */
@@ -1,3 +1,38 @@
1
+ import { Nullable } from '../shared';
1
2
  import { IRange, IUnitRange } from './typedef';
3
+ import { DocumentDataModel } from '../docs';
4
+ import { CellValueType, HorizontalAlign, TextDirection, VerticalAlign, WrapStrategy } from '../types/enum';
5
+ import { IPaddingData, IStyleBase, IStyleData, ITextRotation, ITextStyle } from '../types/interfaces';
2
6
  export declare const isRangesEqual: (oldRanges: IRange[], ranges: IRange[]) => boolean;
3
7
  export declare const isUnitRangesEqual: (oldRanges: IUnitRange[], ranges: IUnitRange[]) => boolean;
8
+ export declare const DEFAULT_PADDING_DATA: {
9
+ t: number;
10
+ b: number;
11
+ l: number;
12
+ r: number;
13
+ };
14
+ export declare const getDefaultBaselineOffset: (fontSize: number) => {
15
+ sbr: number;
16
+ sbo: number;
17
+ spr: number;
18
+ spo: number;
19
+ };
20
+ export interface ICellStyle {
21
+ textRotation?: ITextRotation;
22
+ textDirection?: Nullable<TextDirection>;
23
+ horizontalAlign?: HorizontalAlign;
24
+ verticalAlign?: VerticalAlign;
25
+ wrapStrategy?: WrapStrategy;
26
+ paddingData?: IPaddingData;
27
+ cellValueType?: CellValueType;
28
+ }
29
+ export declare const VERTICAL_ROTATE_ANGLE = 90;
30
+ export declare function createDocumentModelWithStyle(content: string, textStyle: ITextStyle, config?: ICellStyle): DocumentDataModel;
31
+ export declare function extractOtherStyle(style?: Nullable<IStyleData>): ICellStyle;
32
+ /**
33
+ * Pick font style from cell style.
34
+ * @param format
35
+ * @returns {IStyleBase} style
36
+ */
37
+ export declare function getFontFormat(format?: Nullable<IStyleData>): IStyleBase;
38
+ export declare function addLinkToDocumentModel(documentModel: DocumentDataModel, linkUrl: string, linkId: string): void;
@@ -1,8 +1,8 @@
1
- import { InterceptorEffectEnum } from '../common/interceptor';
2
- import { Disposable } from '../shared/lifecycle';
3
1
  import { IDisposable } from '../common/di';
4
2
  import { Nullable } from '../shared/types';
5
3
  import { ICellData, ICellDataForSheetInterceptor } from './typedef';
4
+ import { InterceptorEffectEnum } from '../common/interceptor';
5
+ import { Disposable } from '../shared/lifecycle';
6
6
  /**
7
7
  * @internal
8
8
  */
@@ -1,12 +1,38 @@
1
1
  import { Nullable, ObjectMatrix } from '../shared';
2
+ import { IPaddingData, IStyleData, ITextRotation } from '../types/interfaces';
2
3
  import { Styles } from './styles';
3
4
  import { ICellData, ICellDataForSheetInterceptor, IFreeze, IRange, ISelectionCell, IWorksheetData } from './typedef';
4
- import { BooleanNumber } from '../types/enum';
5
+ import { DocumentDataModel } from '../docs';
6
+ import { BooleanNumber, CellValueType, HorizontalAlign, TextDirection, VerticalAlign, WrapStrategy } from '../types/enum';
5
7
  import { ColumnManager } from './column-manager';
6
8
  import { Range } from './range';
7
9
  import { RowManager } from './row-manager';
8
10
  import { SpanModel } from './span-model';
9
11
  import { SheetViewModel } from './view-model';
12
+ export interface IDocumentLayoutObject {
13
+ documentModel: Nullable<DocumentDataModel>;
14
+ fontString: string;
15
+ textRotation: ITextRotation;
16
+ wrapStrategy: WrapStrategy;
17
+ verticalAlign: VerticalAlign;
18
+ horizontalAlign: HorizontalAlign;
19
+ paddingData: IPaddingData;
20
+ fill?: Nullable<string>;
21
+ }
22
+ export interface ICellOtherConfig {
23
+ textRotation?: ITextRotation;
24
+ textDirection?: Nullable<TextDirection>;
25
+ horizontalAlign?: HorizontalAlign;
26
+ verticalAlign?: VerticalAlign;
27
+ wrapStrategy?: WrapStrategy;
28
+ paddingData?: IPaddingData;
29
+ cellValueType?: CellValueType;
30
+ }
31
+ export interface ICellDocumentModelOption {
32
+ isDeepClone?: boolean;
33
+ displayRawFormula?: boolean;
34
+ ignoreTextRotation?: boolean;
35
+ }
10
36
  /**
11
37
  * The model of a Worksheet.
12
38
  */
@@ -33,9 +59,54 @@ export declare class Worksheet {
33
59
  */
34
60
  setMergeData(mergeData: IRange[]): void;
35
61
  getSpanModel(): SpanModel;
62
+ /**
63
+ * Get the style of the column.
64
+ * @param {number} column The column index
65
+ * @param {boolean} [keepRaw] If true, return the raw style data, otherwise return the style data object
66
+ * @returns {Nullable<IStyleData>|string} The style of the column
67
+ */
68
+ getColumnStyle(column: number, keepRaw?: boolean): string | Nullable<IStyleData>;
69
+ /**
70
+ * Set the style of the column.
71
+ * @param {number} column The column index
72
+ * @param {string|Nullable<IStyleData>} style The style to be set
73
+ */
74
+ setColumnStyle(column: number, style: string | Nullable<IStyleData>): void;
75
+ /**
76
+ * Get the style of the row.
77
+ * @param {number} row The row index
78
+ * @param {boolean} [keepRaw] If true, return the raw style data, otherwise return the style data object
79
+ * @returns {Nullable<IStyleData>} The style of the row
80
+ */
81
+ getRowStyle(row: number, keepRaw?: boolean): string | Nullable<IStyleData>;
82
+ /**
83
+ * Set the style of the row.
84
+ * @param {number} row
85
+ * @param {string|Nullable<IStyleData>} style The style to be set
86
+ */
87
+ setRowStyle(row: number, style: string | Nullable<IStyleData>): void;
88
+ /**
89
+ * this function is used to mixin default style to cell raw{number}
90
+ * @param {number} row The row index
91
+ * @param {number} col The column index
92
+ * @param cellRaw The cell raw data
93
+ * @param {boolean} isRowStylePrecedeColumnStyle The priority of row style and column style
94
+ */
95
+ mixinDefaultStyleToCellRaw(row: number, col: number, cellRaw: Nullable<ICellData>, isRowStylePrecedeColumnStyle: boolean): void;
96
+ /**
97
+ * Get the default style of the worksheet.
98
+ * @returns {Nullable<IStyleData>} Default Style
99
+ */
100
+ getDefaultCellStyle(): Nullable<IStyleData> | string;
101
+ getDefaultCellStyleInternal(): Nullable<IStyleData>;
102
+ /**
103
+ * Set Default Style, if the style has been set, all cells style will be base on this style.
104
+ * @param {Nullable<IStyleData>} style The style to be set as default style
105
+ */
106
+ setDefaultCellStyle(style: Nullable<IStyleData> | string): void;
36
107
  /**
37
108
  * Returns WorkSheet Cell Data Matrix
38
- * @returns
109
+ * @returns WorkSheet Cell Data Matrix
39
110
  */
40
111
  getCellMatrix(): ObjectMatrix<Nullable<ICellData>>;
41
112
  /**
@@ -294,6 +365,17 @@ export declare class Worksheet {
294
365
  * parameter is set to `false`, the iterator will return cells in the top row.
295
366
  */
296
367
  iterateByColumn(range: IRange, skipEmpty?: boolean, skipNonTopLeft?: boolean): Iterable<Readonly<ICell>>;
368
+ /**
369
+ * This method generates a document model based on the cell's properties and handles the associated styles and configurations.
370
+ * If the cell does not exist, it will return null.
371
+ * PS: This method has significant impact on performance.
372
+ * @param cell
373
+ * @param options
374
+ */
375
+ private _getCellDocumentModel;
376
+ private _updateConfigAndGetDocumentModel;
377
+ getBlankCellDocumentModel(cell: Nullable<ICellData>): IDocumentLayoutObject;
378
+ getCellDocumentModelWithFormula(cell: ICellData): Nullable<IDocumentLayoutObject>;
297
379
  }
298
380
  /**
299
381
  * A cell info including its span (if it is the top-left cell of a merged cell).
@@ -32,5 +32,6 @@ export declare enum DataValidationType {
32
32
  * decimal number
33
33
  */
34
34
  DECIMAL = "decimal",
35
- CHECKBOX = "checkbox"
35
+ CHECKBOX = "checkbox",
36
+ ANY = "any"
36
37
  }
@@ -330,8 +330,9 @@ export interface IHeaderAndFooterBase {
330
330
  evenAndOddHeaders?: BooleanNumber;
331
331
  }
332
332
  export declare enum DocumentFlavor {
333
- TRADITIONAL = 0,
334
- MODERN = 1
333
+ UNSPECIFIED = 0,
334
+ TRADITIONAL = 1,
335
+ MODERN = 2
335
336
  }
336
337
  /**
337
338
  * Basics properties of doc style