@univerjs/core 0.1.16 → 0.1.17

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.
@@ -29,3 +29,4 @@ export declare function findLast<T>(arr: T[], callback: (item: T, index: number)
29
29
  */
30
30
  export declare function rotate<T>(arr: Readonly<T[]>, steps: number): readonly T[];
31
31
  export declare function groupBy<T>(arr: Readonly<T[]>, keyFn: (v: T) => string): Map<string, T[]>;
32
+ export declare function makeArray<T>(thing: T | T[]): T[];
@@ -13,8 +13,8 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export declare const DOCS_NORMAL_EDITOR_UNIT_ID_KEY = "__defaultDocumentNormalEditorSpecialUnitId_20231006__";
17
- export declare const DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY = "__defaultDocumentFormulaBarEditorSpecialUnitId_20231012__";
16
+ export declare const DOCS_NORMAL_EDITOR_UNIT_ID_KEY = "__INTERNAL_EDITOR__DOCS_NORMAL";
17
+ export declare const DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY = "__INTERNAL_EDITOR__DOCS_FORMULA_BAR";
18
18
  export declare const DEFAULT_EMPTY_DOCUMENT_VALUE = "\r\n";
19
19
  export declare function createInternalEditorID(id: string): string;
20
20
  export declare function isInternalEditorID(id: string): boolean;
@@ -20,7 +20,7 @@ export { Univer } from './univer';
20
20
  export { shallowEqual, isRangesEqual, isUnitRangesEqual } from './common/equal';
21
21
  export { isNumeric, isSafeNumeric } from './common/number';
22
22
  export { isBooleanString } from './common/boolean';
23
- export { dedupe, remove, rotate, groupBy } from './common/array';
23
+ export { dedupe, remove, rotate, groupBy, makeArray } from './common/array';
24
24
  export { mergeSets } from './common/set';
25
25
  export { DEFAULT_EMPTY_DOCUMENT_VALUE, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, createInternalEditorID, isInternalEditorID, } from './common/const';
26
26
  export { throttle } from './common/function';
@@ -37,7 +37,7 @@ export type { TPriority } from './docs/data-model/text-x/text-x';
37
37
  export { JSONX, JSON1 } from './docs/data-model/json-x/json-x';
38
38
  export type { JSONXActions, JSONXPath } from './docs/data-model/json-x/json-x';
39
39
  export { replaceInDocumentBody } from './docs/data-model/replacement';
40
- export * from './observer';
40
+ export { type IEventObserver, EventState, EventSubject } from './observer/observable';
41
41
  export { Plugin } from './services/plugin/plugin';
42
42
  export { PluginService, DependentOn } from './services/plugin/plugin.service';
43
43
  export { type CommandListener, CommandService, CommandType, type ICommand, type ICommandInfo, ICommandService, type IExecutionOptions, type IMultiCommand, type IMutation, type IMutationCommonParams, type IMutationInfo, type IOperation, type IOperationInfo, NilCommand, sequenceExecute, sequenceExecuteAsync, } from './services/command/command.service';
@@ -105,3 +105,4 @@ export { PermissionService } from './services/permission/permission.service';
105
105
  export { AuthzIoLocalService } from './services/authz-io/authz-io-local.service';
106
106
  export { IAuthzIoService } from './services/authz-io/type';
107
107
  export { createDefaultUser } from './services/user-manager/const';
108
+ export { skipParseTagNames } from './types/const/clipboard';
@@ -1,4 +1,4 @@
1
- import { Nullable } from '../shared/types';
1
+ import { Observer as RxObserver, Subscription, Subject } from 'rxjs';
2
2
 
3
3
  /**
4
4
  * A class serves as a medium between the observable and its observers
@@ -7,145 +7,41 @@ export declare class EventState {
7
7
  /**
8
8
  * An WorkBookObserver can set this property to true to prevent subsequent observers of being notified
9
9
  */
10
- skipNextObservers: boolean | undefined;
10
+ skipNextObservers: boolean;
11
11
  /**
12
12
  * This will be populated with the return value of the last function that was executed.
13
13
  * If it is the first function in the callback chain it will be the event data.
14
14
  */
15
15
  lastReturnValue?: unknown;
16
16
  isStopPropagation: boolean;
17
- /**
18
- * Create a new EventState
19
- * @param skipNextObservers defines a flag which will instruct the observable to skip following observers when set to true
20
- * @param target defines the original target of the state
21
- * @param currentTarget defines the current target of the state
22
- */
23
- constructor(skipNextObservers?: boolean);
24
- /**
25
- * Initialize the current event state
26
- * @param skipNextObservers defines a flag which will instruct the observable to skip following observers when set to true
27
- * @param target defines the original target of the state
28
- * @param currentTarget defines the current target of the state
29
- * @returns the current event state
30
- */
31
- initialize(skipNextObservers?: boolean): EventState;
32
17
  stopPropagation(): void;
33
18
  }
34
19
  interface INotifyObserversReturn {
20
+ /** If the event has been handled by any event handler. */
21
+ handled: boolean;
35
22
  lastReturnValue: unknown;
36
23
  stopPropagation: boolean;
37
24
  }
38
- export declare function isObserver(value: any): boolean;
39
- /**
40
- * Represent an WorkBookObserver registered to a given Observable object.
41
- * The current implementation of the rendering layer is still in use.
42
- *
43
- * @deprecated use rxjs instead
44
- */
45
- export declare class Observer<T = void> {
46
- /**
47
- * Defines the callback to call when the observer is notified
48
- */
49
- callback: (eventData: T, eventState: EventState) => void;
50
- observable: Observable<T>;
51
- dispose(): void;
52
- /**
53
- * Creates a new observer
54
- * @param callback defines the callback to call when the observer is notified
55
- */
56
- constructor(
57
- /**
58
- * Defines the callback to call when the observer is notified
59
- */
60
- callback: (eventData: T, eventState: EventState) => void, observable: Observable<T>);
25
+ export interface IEventObserver<T> extends Partial<RxObserver<[T, EventState]>> {
26
+ next?: (value: [T, EventState]) => unknown;
27
+ priority?: number;
61
28
  }
62
29
  /**
63
- * The Observable class is a simple implementation of the Observable pattern.
64
- * The current implementation of the rendering layer is still in use.
30
+ * This is a custom implementation of RxJS subject. It handles events on canvas elements.
31
+ * In addition to the event, it also emits a state object that can be used to controls the
32
+ * propagation of the event.
65
33
  *
66
- * @deprecated use rxjs instead
67
- *
68
- * @remarks
69
- * There's one slight particularity though: a given Observable can notify its observer using a particular mask value, only the Observers registered with this mask value will be notified.
70
- * This enable a more fine grained execution without having to rely on multiple different Observable objects.
71
- * For instance you may have a given Observable that have four different types of notifications: Move (mask = 0x01), Stop (mask = 0x02), Turn Right (mask = 0X04), Turn Left (mask = 0X08).
72
- * A given observer can register itself with only Move and Stop (mask = 0x03), then it will only be notified when one of these two occurs and will never be for Turn Left/Right.
73
34
  */
74
- export declare class Observable<T> {
75
- protected _observers: Observer<T>[];
76
- protected _eventState: EventState;
77
- protected _onObserverAdded: Nullable<(observer: Observer<T>) => void> | undefined;
78
- /**
79
- * Creates a new observable
80
- * @param onObserverAdded defines a callback to call when a new observer is added
81
- */
82
- constructor(onObserverAdded?: (observer: Observer<T>) => void);
83
- /**
84
- * Gets the list of observers
85
- */
86
- get observers(): Array<Observer<T>>;
87
- /**
88
- * Create a new WorkBookObserver with the specified callback
89
- * @param callback the callback that will be executed for that WorkBookObserver
90
- * @param insertFirst if true the callback will be inserted at the first position, hence executed before the others ones. If false (default behavior) the callback will be inserted at the last position, executed after all the others already present.
91
- * @param unregisterOnFirstCall defines if the observer as to be unregistered after the next notification
92
- * @returns the new observer created for the callback
93
- */
94
- add(callback: (eventData: T, eventState: EventState) => void, insertFirst?: boolean): Nullable<Observer<T>>;
95
- /**
96
- * Remove an WorkBookObserver from the Observable object
97
- * @param observer the instance of the WorkBookObserver to remove
98
- * @returns false if it doesn't belong to this Observable
99
- */
100
- remove(observer: Nullable<Observer<T>>): boolean;
101
- /**
102
- * Moves the observable to the top of the observer list making it get called first when notified
103
- * @param observer the observer to move
104
- */
105
- makeObserverTopPriority(observer: Observer<T>): void;
106
- /**
107
- * Moves the observable to the bottom of the observer list making it get called last when notified
108
- * @param observer the observer to move
109
- */
110
- makeObserverBottomPriority(observer: Observer<T>): void;
111
- /**
112
- * Notify all Observers by calling their respective callback with the given data
113
- * Will return true if all observers were executed, false if an observer set skipNextObservers to true, then prevent the subsequent ones to execute
114
- * @param eventData defines the data to send to all observers
115
- * @returns false if the complete observer chain was not processed (because one observer set the skipNextObservers to true)
116
- */
117
- notifyObservers(eventData: T): Nullable<INotifyObserversReturn>;
118
- /**
119
- * Calling this will execute each callback, expecting it to be a promise or return a value.
120
- * If at any point in the chain one function fails, the promise will fail and the execution will not continue.
121
- * This is useful when a chain of Events (sometimes async Events) is needed to initialize a certain object
122
- * and it is crucial that all callbacks will be executed.
123
- * The order of the callbacks is kept, callbacks are not executed parallel.
124
- *
125
- * @param eventData The data to be sent to each callback
126
- * @returns {Promise<T>} will return a Promise than resolves when all callbacks executed successfully.
127
- */
128
- notifyObserversWithPromise(eventData: T): Promise<T>;
129
- /**
130
- * Notify a specific observer
131
- * @param observer defines the observer to notify
132
- * @param eventData defines the data to be sent to each callback
133
- */
134
- notifyObserver(observer: Observer<T>, eventData: T): Nullable<INotifyObserversReturn>;
135
- /**
136
- * Gets a boolean indicating if the observable has at least one observer
137
- * @returns true is the Observable has at least one WorkBookObserver registered
138
- */
139
- hasObservers(): boolean;
140
- /**
141
- * Clear the list of observers
142
- */
143
- clear(): void;
144
- /**
145
- * Clone the current observable
146
- * @returns a new observable
147
- */
148
- clone(): Observable<T>;
149
- private _remove;
35
+ export declare class EventSubject<T> extends Subject<[T, EventState]> {
36
+ private _sortedObservers;
37
+ /** @deprecated Use `subscribeEvent` instead. */
38
+ subscribe(): Subscription;
39
+ /** @deprecated Use `emitEvent` instead. */
40
+ next(): void;
41
+ unsubscribe(): void;
42
+ complete(): void;
43
+ subscribeEvent(observer: IEventObserver<T> | ((evt: T, state: EventState) => unknown)): Subscription;
44
+ clearObservers(): void;
45
+ emitEvent(event: T): INotifyObserversReturn;
150
46
  }
151
47
  export {};
@@ -18,7 +18,7 @@ export interface IUniverInstanceService {
18
18
  unitAdded$: Observable<UnitModel>;
19
19
  /** Subscribe to curtain type of units' creation. */
20
20
  getTypeOfUnitAdded$<T extends UnitModel>(type: UnitType): Observable<T>;
21
- /** @interal */
21
+ /** @ignore */
22
22
  __addUnit(unit: UnitModel): void;
23
23
  /** Omits value when a UnitModel is disposed. */
24
24
  unitDisposed$: Observable<UnitModel>;
@@ -21,7 +21,7 @@ export interface IUndoRedoService {
21
21
  pitchTopRedoElement(): Nullable<IUndoRedoItem>;
22
22
  popUndoToRedo(): void;
23
23
  popRedoToUndo(): void;
24
- clearUndoRedo(unitID: string): void;
24
+ clearUndoRedo(unitId: string): void;
25
25
  /**
26
26
  * Batch undo redo elements into a single `IUndoRedoItem` util the returned `IDisposable` is called.
27
27
  *
@@ -1,11 +1,8 @@
1
1
  import { IDisposable } from '@wendellhu/redi';
2
2
  import { Subscription, SubscriptionLike, Subject } from 'rxjs';
3
- import { Nullable } from '../common/type-util';
4
- import { Observer } from '../observer/observable';
5
3
 
6
- type DisposableLike = IDisposable | Nullable<Observer<any>> | SubscriptionLike | (() => void);
4
+ type DisposableLike = IDisposable | SubscriptionLike | (() => void);
7
5
  export declare function toDisposable(disposable: IDisposable): IDisposable;
8
- export declare function toDisposable(observer: Nullable<Observer<any>>): IDisposable;
9
6
  export declare function toDisposable(subscription: SubscriptionLike): IDisposable;
10
7
  export declare function toDisposable(callback: () => void): IDisposable;
11
8
  export declare function toDisposable(v: DisposableLike): IDisposable;
@@ -2,5 +2,14 @@ import { IDisposable } from '@wendellhu/redi';
2
2
  import { Observable } from 'rxjs';
3
3
 
4
4
  type CallbackFn<T extends readonly unknown[]> = (cb: (...args: T) => void) => IDisposable;
5
+ /**
6
+ * Creates an observable from a callback function.
7
+ *
8
+ * @param callback The callback function that will be called when the observable is subscribed to. **Please not that the
9
+ * if the callback function has `this` context, it will be lost when the callback is called. So you probably
10
+ * should bind the callback to the correct context.**
11
+ *
12
+ * @returns The observable that will emit when the callback function gets called.
13
+ */
5
14
  export declare function fromCallback<T extends readonly unknown[]>(callback: CallbackFn<T>): Observable<T>;
6
15
  export {};
@@ -83,6 +83,7 @@ export declare class Workbook extends UnitModel<IWorkbookData, UniverInstanceTyp
83
83
  getSheetBySheetId(sheetId: string): Nullable<Worksheet>;
84
84
  getSheetByIndex(index: number): Nullable<Worksheet>;
85
85
  getHiddenWorksheets(): string[];
86
+ getUnhiddenWorksheets(): string[];
86
87
  load(config: IWorkbookData): void;
87
88
  /**
88
89
  * Check if sheet name is unique
@@ -13,5 +13,4 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export * from './observable';
17
- export * from './observable-hooks';
16
+ export declare const skipParseTagNames: string[];