@univerjs/core 0.2.9 → 0.2.10

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.
@@ -88,13 +88,6 @@ export { SlideDataModel } from './slides/slide-model';
88
88
  export * from './types/const';
89
89
  export * from './types/enum';
90
90
  export * from './types/interfaces';
91
- export { ISnapshotServerService } from './services/snapshot/snapshot-server.service';
92
- export { transformSnapshotToWorkbookData, transformWorkbookDataToSnapshot, transformDocumentDataToSnapshot, transformSnapshotToDocumentData, generateTemporarySnap, generateTempDocumentSnapshot, } from './services/snapshot/snapshot-transform';
93
- export { textEncoder, textDecoder } from './services/snapshot/snapshot-utils';
94
- export { type ILogContext } from './services/log/context';
95
- export { b64DecodeUnicode, b64EncodeUnicode } from './shared/coder';
96
- export { ClientSnapshotServerService } from './services/snapshot/snapshot-server.service';
97
- export { getSheetBlocksFromSnapshot } from './services/snapshot/snapshot-transform';
98
91
  export { isBlackColor, isWhiteColor } from './shared/color/color-kit';
99
92
  export { cellToRange } from './shared/common';
100
93
  export type { IDataValidationRule, IDataValidationRuleBase, IDataValidationRuleInfo, IDataValidationRuleOptions, ISheetDataValidationRule } from './types/interfaces/i-data-validation';
@@ -1,5 +1,5 @@
1
- import { ILogContext } from '@univerjs/core';
2
1
  import { IAllowedRequest, IAllowedResponse, IBatchAllowedResponse, ICreateCollaboratorRequest, ICreateRequest, ICreateResponse, IDeleteCollaboratorRequest, IListCollaboratorRequest, IListCollaboratorResponse, IListPermPointRequest, IListPermPointResponse, IListRolesRequest, IListRolesResponse, IPutCollaboratorsRequest, IUpdateCollaboratorRequest, IUpdatePermPointRequest } from '@univerjs/protocol';
2
+ import { ILogContext } from '../log/context';
3
3
  export interface IAuthzIoService {
4
4
  create(config: ICreateRequest, context?: ILogContext): Promise<ICreateResponse['objectID']>;
5
5
  allowed(config: IAllowedRequest, context?: ILogContext): Promise<IAllowedResponse['actions']>;
@@ -16,4 +16,4 @@ export interface IAuthzIoService {
16
16
  createCollaborator(config: ICreateCollaboratorRequest, context?: ILogContext): Promise<void>;
17
17
  putCollaborators(config: IPutCollaboratorsRequest, context?: ILogContext): Promise<void>;
18
18
  }
19
- export declare const IAuthzIoService: import('@univerjs/core').IdentifierDecorator<IAuthzIoService>;
19
+ export declare const IAuthzIoService: import('../../common/di').IdentifierDecorator<IAuthzIoService>;
@@ -2,106 +2,192 @@ import { IAccessor, IDisposable, Injector } from '../../common/di';
2
2
  import { Disposable } from '../../shared/lifecycle';
3
3
  import { IContextService } from '../context/context.service';
4
4
  import { ILogService } from '../log/log.service';
5
+ /**
6
+ * The type of a command.
7
+ */
5
8
  export declare enum CommandType {
6
- /** Command could generate some operations or mutations. */
9
+ /**
10
+ * Responsible for creating, orchestrating, and executing MUTATION or OPERATION according to specific business
11
+ * logic. For example, a delete row COMMAND will generate a delete row MUTATION, an insert row MUTATION for undo,
12
+ * and a set cell content MUTATION.
13
+ */
7
14
  COMMAND = 0,
8
- /** An operation that do not require conflict resolve. */
15
+ /**
16
+ * MUTATION is the change made to the data saved to snapshot, such as inserting rows and columns,
17
+ * modifying cell content, modifying filter ranges, etc. If you want to add collaborative editing capabilities to
18
+ * Univer, it is the smallest unit of conflict resolution.
19
+ */
9
20
  OPERATION = 1,
10
- /** An operation that need to be resolved before applied on peer client. */
21
+ /**
22
+ * OPERATION is the change made to data that is not saved to snapshot, without conflict resolution,
23
+ * such as modifying scroll position, modifying sidebar state, etc.
24
+ */
11
25
  MUTATION = 2
12
26
  }
27
+ /**
28
+ * In Univer, all data modifications need to be executed through commands. The command-based approach can better track
29
+ * changes in values, implement functions such as undo, redo, and collaborative editing, handle complex associated
30
+ * logic between functions, etc.
31
+ *
32
+ * All commands should implements this interface or related {@link IMutation} or {@link IOperation} interface, and
33
+ * should be registered in the {@link ICommandService}.
34
+ */
13
35
  export interface ICommand<P extends object = object, R = boolean> {
14
36
  /**
15
- * ${businessName}.${type}.${name}
37
+ * Identifier of the command. It should be unique in the application unless it is a {@link IMultiCommand}.
38
+ * Its pattern should be like `<namespace>.<type>.<command-name>`.
39
+ *
40
+ * @example { id: 'sheet.command.set-selection-frozen' }
16
41
  */
17
42
  readonly id: string;
43
+ /**
44
+ * The type of the command.
45
+ */
18
46
  readonly type: CommandType;
19
- handler(accessor: IAccessor, params?: P, options?: IExecutionOptions): Promise<R> | R;
20
47
  /**
21
- * When this command is unregistered, this function would be called.
22
- *
23
- * @deprecated
48
+ * The handler of the command.
49
+ * @param accessor The accessor to the dependency injection container.
50
+ * @param params Params of the command. Params should be serializable.
51
+ * @param options Options of the command.
52
+ * @returns The result of the command. By default it should be a boolean value which indicates the command is
53
+ * executed successfully or not.
24
54
  */
25
- onDispose?: () => void;
55
+ handler(accessor: IAccessor, params?: P, options?: IExecutionOptions): Promise<R> | R;
26
56
  }
57
+ /**
58
+ * A command that may have multiple implementations. Each implementation should have different `priority`
59
+ * and `preconditions` callback to determine which implementation should be executed.
60
+ */
27
61
  export interface IMultiCommand<P extends object = object, R = boolean> extends ICommand<P, R> {
62
+ /** The name of the multi command. It should be unique in the application. */
28
63
  name: string;
64
+ /** @ignore */
29
65
  multi: true;
66
+ /** Priority of this implementation. Implementation with higher priority will be checked first. */
30
67
  priority: number;
68
+ /**
69
+ * A callback function that tells `ICommandService` if this implementation should be executed.
70
+ * @param contextService The context service.
71
+ * @returns If this implementation should be executed, return `true`, otherwise return `false`.
72
+ */
31
73
  preconditions?: (contextService: IContextService) => boolean;
32
74
  }
33
75
  export interface IMutationCommonParams {
76
+ /**
77
+ * It is used to indicate which {@link CommandType.COMMAND} triggers the mutation.
78
+ */
34
79
  trigger?: string;
35
80
  }
36
81
  /**
37
- * Mutation would change the model of Univer applications.
82
+ * {@link CommandType.MUTATION} should implement this interface.
38
83
  */
39
84
  export interface IMutation<P extends object, R = boolean> extends ICommand<P, R> {
40
85
  type: CommandType.MUTATION;
41
86
  /**
42
- * Mutations must be a sync process.
43
- * @param accessor
44
- * @param params Params of the mutation. A mutation must has params.
87
+ * The handler of the mutation.
88
+ * @param accessor The accessor to the dependency injection container.
89
+ * @param params Params of the mutation. Params should be serializable.
90
+ * @returns The result of the mutation. By default it should be a boolean value which indicates the mutation is
91
+ * executed successfully or not.
45
92
  */
46
93
  handler(accessor: IAccessor, params: P): R;
47
94
  }
48
95
  /**
49
- * Operation would change the state of Univer applications. State should only be in memory and does not
50
- * require conflicting resolution.
96
+ * {@link CommandType.OPERATION} should implement this interface.
51
97
  */
52
98
  export interface IOperation<P extends object = object, R = boolean> extends ICommand<P, R> {
53
99
  type: CommandType.OPERATION;
54
100
  /**
55
- * Operations must be a sync process.
56
- * @param accessor
57
- * @param params Params of the operation. A operation must has params.
101
+ * The handler of the operation.
102
+ * @param accessor The accessor to the dependency injection container.
103
+ * @param params Params of the operation. Params should be serializable.
104
+ * @returns The result of the operation. By default it should be a boolean value which indicates the operation is
105
+ * executed successfully or not.
58
106
  */
59
107
  handler(accessor: IAccessor, params: P): R;
60
108
  }
61
109
  /**
62
- * The command info, only a command id and responsible params
110
+ * This object represents an execution of a command.
63
111
  */
64
112
  export interface ICommandInfo<T extends object = object> {
113
+ /**
114
+ * Id of the command being executed.
115
+ */
65
116
  id: string;
117
+ /**
118
+ * Type of the command.
119
+ */
66
120
  type?: CommandType;
67
121
  /**
68
- * Args should be serializable.
122
+ * Parameters of this execution.
69
123
  */
70
124
  params?: T;
71
125
  }
126
+ /** This object represents an execution of a {@link CommandType.MUTATION} */
72
127
  export interface IMutationInfo<T extends object = object> {
73
128
  id: string;
74
129
  type?: CommandType.MUTATION;
75
130
  params: T;
76
131
  }
132
+ /** This object represents an execution of a {@link CommandType.OPERATION} */
77
133
  export interface IOperationInfo<T extends object = object> {
78
134
  id: string;
79
135
  type?: CommandType.OPERATION;
80
136
  params: T;
81
137
  }
82
138
  export interface IExecutionOptions {
83
- /** This mutation should only be executed on the local machine, and not synced to replicas. */
139
+ /** This mutation should only be executed on the local machine, and should not be synced to replicas. */
84
140
  onlyLocal?: boolean;
85
141
  /** This command is from collaboration peers. */
86
142
  fromCollab?: boolean;
143
+ /** @deprecated */
87
144
  fromChangeset?: boolean;
88
145
  [key: PropertyKey]: string | number | boolean | undefined;
89
146
  }
90
147
  export type CommandListener = (commandInfo: Readonly<ICommandInfo>, options?: IExecutionOptions) => void;
148
+ /**
149
+ * The identifier of the command service.
150
+ */
151
+ export declare const ICommandService: import('../../common/di').IdentifierDecorator<ICommandService>;
152
+ /**
153
+ * The service to register and execute commands.
154
+ */
91
155
  export interface ICommandService {
92
156
  /**
93
157
  * Check if a command is already registered at the current command service.
94
- *
95
158
  * @param commandId The id of the command.
159
+ * @returns If the command is registered, return `true`, otherwise return `false`.
96
160
  */
97
161
  hasCommand(commandId: string): boolean;
162
+ /**
163
+ * Register a command to the command service.
164
+ * @param command The command to register.
165
+ */
98
166
  registerCommand(command: ICommand<object, unknown>): IDisposable;
167
+ /**
168
+ * Register a command as a multi command.
169
+ * @param command The command to register as a multi command.
170
+ */
99
171
  registerMultipleCommand(command: ICommand<object, unknown>): IDisposable;
172
+ /**
173
+ * Execute a command with the given id and parameters.
174
+ * @param id Identifier of the command.
175
+ * @param params Parameters of this execution.
176
+ * @param options Options of this execution.
177
+ * @returns The result of the execution. It is a boolean value by default which indicates the command is executed.
178
+ */
100
179
  executeCommand<P extends object = object, R = boolean>(id: string, params?: P, options?: IExecutionOptions): Promise<R>;
101
- hasCommand(id: string): boolean;
180
+ /**
181
+ * Execute a command with the given id and parameters synchronously.
182
+ * @param id Identifier of the command.
183
+ * @param params Parameters of this execution.
184
+ * @param options Options of this execution.
185
+ * @returns The result of the execution. It is a boolean value by default which indicates the command is executed.
186
+ */
102
187
  syncExecuteCommand<P extends object = object, R = boolean>(id: string, params?: P, options?: IExecutionOptions): R;
103
188
  /**
104
189
  * Register a callback function that will be executed after a command is executed.
190
+ * @param listener
105
191
  */
106
192
  onCommandExecuted(listener: CommandListener): IDisposable;
107
193
  /**
@@ -110,11 +196,7 @@ export interface ICommandService {
110
196
  */
111
197
  beforeCommandExecuted(listener: CommandListener): IDisposable;
112
198
  }
113
- export declare const ICommandService: import('../../common/di').IdentifierDecorator<ICommandService>;
114
- /**
115
- * The registry of commands.
116
- */
117
- export declare class CommandRegistry {
199
+ declare class CommandRegistry {
118
200
  private readonly _commands;
119
201
  private readonly _commandTypes;
120
202
  registerCommand(command: ICommand): IDisposable;
@@ -149,3 +231,4 @@ export declare class CommandService extends Disposable implements ICommandServic
149
231
  }
150
232
  export declare function sequenceExecute(tasks: ICommandInfo[], commandService: ICommandService, options?: IExecutionOptions): import('../../common/sequence').ISequenceExecuteResult;
151
233
  export declare function sequenceExecuteAsync(tasks: ICommandInfo[], commandService: ICommandService, options?: IExecutionOptions): Promise<import('../../common/sequence').ISequenceExecuteResult>;
234
+ export {};
@@ -1,2 +1,3 @@
1
- import { default as numfmt } from 'numfmt';
1
+ import { INumfmt } from './types/numfmt.type';
2
+ declare const numfmt: INumfmt;
2
3
  export { numfmt };
@@ -0,0 +1,227 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ type FormatType = 'currency' | 'date' | 'datetime' | 'error' | 'fraction' | 'general' | 'grouped' | 'number' | 'percent' | 'scientific' | 'text' | 'time';
17
+ /**
18
+ * An arbirarty number that represents the format's specificity if you want to compare one to another. Integer comparisons roughly match Excel's resolutions when it determines which format wins out.
19
+ *
20
+ * text: 15
21
+ * datetime: 10.8
22
+ * date: 10.8
23
+ * time: 10.8
24
+ * percent: 10.6
25
+ * currency: 10.4
26
+ * grouped: 10.2
27
+ * scientific: 6
28
+ * number: 4
29
+ * fraction: 2
30
+ * general: 0
31
+ * error: 0
32
+ */
33
+ type Level = 15 | 10.8 | 10.6 | 10.4 | 10.2 | 6 | 4 | 2 | 0;
34
+ interface Info {
35
+ type: FormatType;
36
+ /**
37
+ * Correspond to the output from same named functions found on the formatters.
38
+ */
39
+ isDate: boolean;
40
+ isText: boolean;
41
+ isPercent: boolean;
42
+ /** The maximum number of decimals this format will emit. */
43
+ maxDecimals: number;
44
+ /**
45
+ * 1 if the format uses color on the negative portion of the string, else a 0. This replicates Excel's CELL("color") functionality.
46
+ */
47
+ color: 0 | 1;
48
+ /**
49
+ * 1 if the positive portion of the number format contains an open parenthesis, else a 0. This is replicates Excel's CELL("parentheses") functionality.
50
+ */
51
+ parentheses: 0 | 1;
52
+ /**
53
+ * 1 if the positive portion of the format uses a thousands separator, else a 0.
54
+ */
55
+ grouped: 1;
56
+ /**
57
+ * Corresponds to Excel's CELL("format") functionality. It is should match Excel's quirky behaviour fairly well.
58
+ */
59
+ code: string;
60
+ /**
61
+ * The multiplier used when formatting the number (100 for percentages).
62
+ */
63
+ scale: 1;
64
+ /**
65
+ * An arbirarty number that represents the format's specificity if you want to compare one to another. Integer comparisons roughly match Excel's resolutions when it determines which format wins out.
66
+ */
67
+ level: Level;
68
+ _partitions: Array<{
69
+ color: string;
70
+ tokens: Array<{
71
+ type: 'num';
72
+ num: string;
73
+ } | {
74
+ type: 'point';
75
+ value: string;
76
+ } | {
77
+ type: 'frac';
78
+ num: string;
79
+ }>;
80
+ }>;
81
+ }
82
+ interface DateInfo {
83
+ /** If any `y` or `b` operator was found in the pattern. */
84
+ year: boolean;
85
+ /** If any `m` operator was found in the pattern. */
86
+ month: boolean;
87
+ /** If any `d` operator was found in the pattern (including ones that emit weekday). */
88
+ day: boolean;
89
+ /** If any `h` operator was found in the pattern. */
90
+ hours: boolean;
91
+ /** If any `:m` operator was found in the pattern. */
92
+ minutes: boolean;
93
+ /** If any `s` operator was found in the pattern. */
94
+ seconds: boolean;
95
+ /** Will be set to `12` if AM/PM operators are being used in the formatting string, else it will be set to `24`. */
96
+ clockType: 24 | 12;
97
+ }
98
+ interface Options {
99
+ /**
100
+ * A [BCP 47](https://www.rfc-editor.org/rfc/bcp/bcp47.txt) string tag. Locale default is english with a \u00a0 grouping symbol
101
+ *
102
+ * @default ""
103
+ */
104
+ locale: LocaleTag;
105
+ /**
106
+ * Should the formatter throw an error if a provided pattern is invalid. If not, a formatter will be constructed which only ever outputs an error string (see invalid in this table).
107
+ * @default true
108
+ */
109
+ throws: boolean;
110
+ /**
111
+ * The string emitted when no-throw mode fails to parse a pattern.
112
+ * @default "######"
113
+ */
114
+ invalid: string;
115
+ /**
116
+ * By default the formatters will emit [non-breaking-space](https://en.wikipedia.org/wiki/Non-breaking_space) rather than a regular space when emitting the formatted number. Setting this to false will make it use regular spaces instead.
117
+ * @default true
118
+ */
119
+ nbsp: boolean;
120
+ /**
121
+ * Simulate the Lotus 1-2-3 [1900 leap year bug](https://docs.microsoft.com/en-us/office/troubleshoot/excel/wrongly-assumes-1900-is-leap-year). It is a requirement in the Ecma OOXML specification so it is on by default.
122
+ *
123
+ * @default false
124
+ */
125
+ leap1900: boolean;
126
+ /**
127
+ * Should the formatter throw an error when trying to format a date that is out of bounds?
128
+ *
129
+ * @default false
130
+ */
131
+ dateErrorThrows: boolean;
132
+ /**
133
+ * Should the formatter switch to a General number format when trying to format a date that is out of bounds?
134
+ * @default true
135
+ */
136
+ dateErrorNumber: boolean;
137
+ /**
138
+ * The string emitted when a formatter fails to format a date that is out of bounds.
139
+ * @default "######"
140
+ */
141
+ overflow: string;
142
+ /**
143
+ * Extends the allowed range of dates from Excel bounds (1900–9999) to Google Sheet bounds (0–99999).
144
+ * @default true
145
+ */
146
+ dateSpanLarge: boolean;
147
+ /**
148
+ * Normally when date objects are used with the formatter, time zone is taken into account. This makes the formatter ignore the timezone offset.
149
+ * @default false
150
+ */
151
+ ignoreTimezone: boolean;
152
+ /**
153
+ * when using the numfmt.parseDate, numfmt.parseValue and numfmt.dateFromSerial functions, the output will be a Date object.
154
+ * @default false
155
+ */
156
+ nativeDate: boolean;
157
+ }
158
+ interface LocaleData {
159
+ group: string;
160
+ decimal: string;
161
+ positive: string;
162
+ negative: string;
163
+ percent: string;
164
+ exponent: string;
165
+ nan: string;
166
+ infinity: string;
167
+ ampm: [string, string];
168
+ mmmm: string[];
169
+ mmm: string[];
170
+ dddd: string[];
171
+ ddd: string[];
172
+ mmmm6: string[];
173
+ mmm6: string[];
174
+ }
175
+ interface Formatter {
176
+ isDate(): boolean;
177
+ isPercent(): boolean;
178
+ isText(): boolean;
179
+ color(value: number): string;
180
+ info: Info;
181
+ dateInfo: DateInfo;
182
+ (value: number): string;
183
+ }
184
+ type LocaleTag = 'zh-CN' | 'zh' | 'zh-TW' | 'cs' | 'da' | 'nl' | 'en' | 'fi' | 'fr' | 'de' | 'el' | 'hu' | 'is' | 'id' | 'it' | 'ja' | 'ko' | 'nb' | 'pl' | 'pt' | 'ru' | 'sk' | 'es' | 'sv' | 'th' | 'tr';
185
+ export interface ParsedReturnType {
186
+ /**
187
+ * The parsed value. For dates, this will be an Excel style serial date unless the nativeDate option is used.
188
+ */
189
+ v: number | string | boolean | Date;
190
+ /**
191
+ * (Optionally) the number format string of the input. This property will not be present if it amounts to the General format.
192
+ */
193
+ z?: string;
194
+ }
195
+ type _Year = number;
196
+ type _MonthIndex = number;
197
+ type _Date = number | undefined;
198
+ type _Hours = number | undefined;
199
+ type _Minutes = number | undefined;
200
+ type _Seconds = number | undefined;
201
+ type _Ms = number | undefined;
202
+ type DateValue = [_Year, _MonthIndex, _Date, _Hours, _Minutes, _Seconds, _Ms];
203
+ type ParseValue = number | boolean | DateValue | Date | null;
204
+ export interface INumfmt {
205
+ (value: string, opt?: Options): Formatter;
206
+ format(pattern: string, value: ParseValue, opt?: Partial<Options>): string;
207
+ round(value: number, places?: number): number;
208
+ /**
209
+ * @internal
210
+ */
211
+ parseLocale(tag: LocaleTag): void;
212
+ getLocale(tag: LocaleTag): LocaleData | null;
213
+ addLocale(data: Partial<LocaleData>, tag: LocaleTag): void;
214
+ isDate(format: string): boolean;
215
+ isPercent(format: string): boolean;
216
+ isText(format: string): boolean;
217
+ getInfo(format: string): Info;
218
+ parseValue(value: string, op?: Options): ParsedReturnType;
219
+ parseNumber(value: string, op?: Options): ParsedReturnType;
220
+ parseDate(value: string, op?: Options): ParsedReturnType;
221
+ parseTime(value: string, op?: Options): ParsedReturnType;
222
+ parseBool(value: string, op?: Options): ParsedReturnType;
223
+ dateToSerial(value: Date | [number, number, number], opt?: Options): number | string;
224
+ dateFromSerial(value: number, opt?: Options): Date;
225
+ options(op: Partial<Options>): void;
226
+ }
227
+ export {};
@@ -30,3 +30,6 @@ export interface IKeyValue {
30
30
  export interface IKeyType<T> {
31
31
  [key: string]: T;
32
32
  }
33
+ export type DeepReadonly<T> = {
34
+ readonly [P in keyof T]: DeepReadonly<T[P]>;
35
+ };
@@ -184,7 +184,7 @@ export interface ICellDataForSheetInterceptor extends ICellData {
184
184
  dataValidation?: Nullable<ICellValidationData>;
185
185
  markers?: ICellMarks;
186
186
  customRender?: Nullable<ICellCustomRender[]>;
187
- interceptorAutoHeight?: number;
187
+ interceptorAutoHeight?: () => number | undefined;
188
188
  /**
189
189
  * can cell be covered when sibling is overflow
190
190
  */
@@ -136,3 +136,7 @@ export declare const DEFAULT_SLIDE: {
136
136
  height: number;
137
137
  };
138
138
  };
139
+ /**
140
+ * Univer internal key on cellData.custom to save some internal values
141
+ */
142
+ export declare const UNIVER_INTERNAL = "__univer_internal__";