refactor: make the source of univer-instance-type unique (#2073)

This commit is contained in:
#FF0000
2024-04-26 11:01:41 +08:00
committed by GitHub
parent e76fe4e601
commit bee6d9b9cf
218 changed files with 447 additions and 482 deletions
@@ -52,7 +52,7 @@ export const SaveSnapshotOptions: ICommand = {
const exportController = accessor.get(ExportController);
const recordController = accessor.get(RecordController);
const workbook = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!;
const workbook = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;
const worksheet = workbook.getActiveSheet();
const snapshot = resourceLoaderService.saveWorkbook(workbook);
const gitHash = process.env.GIT_COMMIT_HASH;
@@ -34,7 +34,7 @@ export const SetEditable: ICommand = {
} else {
const univerPermissionService = accessor.get(UniverPermissionService);
const univerInstanceService = accessor.get(IUniverInstanceService);
const unitId = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!.getUnitId();
const unitId = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!.getUnitId();
const editable = univerPermissionService.getEditable(unitId);
univerPermissionService.setEditable(unitId, !editable);
}
@@ -31,7 +31,7 @@ export const SidebarOperation: ICommand = {
const sidebarService = accessor.get(ISidebarService);
const editorService = accessor.get(IEditorService);
const univerInstanceService = accessor.get(IUniverInstanceService);
const unit = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!;
const unit = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;
switch (params.value) {
case 'open':
editorService.setOperationSheetUnitId(unit.getUnitId());
@@ -51,7 +51,7 @@ export class E2EMemoryController {
private async _loadAndRelease(id: number): Promise<void> {
const unitId = `e2e${id}`;
this._univerInstanceService.createUnit(UniverInstanceType.SHEET, { ...DEFAULT_WORKBOOK_DATA_DEMO, id: unitId });
this._univerInstanceService.createUnit(UniverInstanceType.UNIVER_SHEET, { ...DEFAULT_WORKBOOK_DATA_DEMO, id: unitId });
await timer(AWAIT_LOADING_TIMEOUT);
this._univerInstanceService.disposeUnit(unitId);
await timer(AWAIT_DISPOSING_TIMEOUT);
@@ -22,7 +22,7 @@ import { interval, takeUntil, throttle } from 'rxjs';
@OnLifecycle(LifecycleStages.Rendered, PerformanceMonitorController)
export class PerformanceMonitorController extends RxDisposable {
private _documentType: UniverInstanceType = UniverInstanceType.UNIVER;
private _documentType: UniverInstanceType = UniverInstanceType.UNIVER_UNKNOWN;
private _hasWatched = false;
private _container!: HTMLDivElement;
private _styleElement!: HTMLStyleElement;
@@ -87,14 +87,14 @@ export class PerformanceMonitorController extends RxDisposable {
this._styleElement = document.createElement('style');
document.head.appendChild(this._styleElement).innerText = style;
if (this._documentType === UniverInstanceType.DOC) {
if (this._documentType === UniverInstanceType.UNIVER_DOC) {
this._docCanvasView.fps$
.pipe(takeUntil(this.dispose$))
.pipe(throttle(() => interval(THROTTLE_TIME)))
.subscribe((fps) => {
container.innerText = `FPS: ${fps}`;
});
} else if (this._documentType === UniverInstanceType.SHEET) {
} else if (this._documentType === UniverInstanceType.UNIVER_SHEET) {
this._injector
.get(SheetCanvasView)
.fps$.pipe(takeUntil(this.dispose$))
@@ -40,7 +40,7 @@ const editorStyle: React.CSSProperties = {
*/
export const TestEditorContainer = () => {
const univerInstanceService = useDependency(IUniverInstanceService);
const workbook = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!;
const workbook = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;
if (workbook == null) {
return;
}
+2 -2
View File
@@ -96,7 +96,7 @@ univer.registerPlugin(UniverSheetsConditionalFormattingUIPlugin);
// create univer sheet instance
if (!IS_E2E) {
univer.createUnit(UniverInstanceType.SHEET, DEFAULT_WORKBOOK_DATA_DEMO);
univer.createUnit(UniverInstanceType.UNIVER_SHEET, DEFAULT_WORKBOOK_DATA_DEMO);
}
// Uncomment the following lines to test if the document is disposed correctly without memory leaks.
@@ -104,7 +104,7 @@ if (!IS_E2E) {
// univer.__getInjector().get(IUniverInstanceService).disposeUnit(DEFAULT_WORKBOOK_DATA_DEMO.id);
// }, 5000);
// setTimeout(() => {
// univer.createUnit(UniverInstanceType.SHEET, DEFAULT_WORKBOOK_DATA_DEMO);
// univer.createUnit(UniverInstanceType.UNIVER_SHEET, DEFAULT_WORKBOOK_DATA_DEMO);
// }, 7000);
+3 -12
View File
@@ -14,21 +14,12 @@
* limitations under the License.
*/
import type { UniverType } from '@univerjs/protocol';
import { Disposable } from '../shared';
/**
* Type of built-in univer document instances.
*/
export enum UniverInstanceType {
UNIVER = 0,
DOC = 1,
SHEET = 2,
SLIDE = 3,
export { UniverType as UniverInstanceType } from '@univerjs/protocol';
UNRECOGNIZED = -1,
}
export type UnitType = UniverInstanceType | number;
export type UnitType = UniverType | number;
export abstract class UnitModel<_D = object, T extends UnitType = UnitType> extends Disposable {
abstract readonly type: T;
@@ -46,8 +46,8 @@ interface IDrawingUpdateConfig {
width: number;
}
class DocumentDataModelSimple extends UnitModel<IDocumentData, UniverInstanceType.DOC> {
override type: UniverInstanceType.DOC = UniverInstanceType.DOC;
class DocumentDataModelSimple extends UnitModel<IDocumentData, UniverInstanceType.UNIVER_DOC> {
override type: UniverInstanceType.UNIVER_DOC = UniverInstanceType.UNIVER_DOC;
override getUnitId(): string {
throw new Error('Method not implemented.');
@@ -167,15 +167,15 @@ export class UniverInstanceService extends Disposable implements IUniverInstance
}
getCurrentUniverDocInstance(): Nullable<DocumentDataModel> {
return this.getCurrentUnitForType(UniverInstanceType.DOC) as Nullable<DocumentDataModel>;
return this.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC) as Nullable<DocumentDataModel>;
}
getUniverDocInstance(unitId: string): Nullable<DocumentDataModel> {
return this.getUnit<DocumentDataModel>(unitId, UniverInstanceType.DOC);
return this.getUnit<DocumentDataModel>(unitId, UniverInstanceType.UNIVER_DOC);
}
getUniverSheetInstance(unitId: string): Nullable<Workbook> {
return this.getUnit<Workbook>(unitId, UniverInstanceType.SHEET);
return this.getUnit<Workbook>(unitId, UniverInstanceType.UNIVER_SHEET);
}
getAllUnitsForType<T>(type: UnitType): T[] {
@@ -183,7 +183,7 @@ export class UniverInstanceService extends Disposable implements IUniverInstance
}
changeDoc(unitId: string, doc: DocumentDataModel): void {
const allDocs = this.getAllUnitsForType<DocumentDataModel>(UniverInstanceType.DOC);
const allDocs = this.getAllUnitsForType<DocumentDataModel>(UniverInstanceType.UNIVER_DOC);
const oldDoc = allDocs.find((doc) => doc.getUnitId() === unitId);
if (oldDoc != null) {
@@ -53,7 +53,7 @@ export class PermissionService extends Disposable implements IPermissionService
// private _init() {
// this.disposeWithMe(
// toDisposable(
// this._univerInstanceService.getTypeOfUnitAdded$<Workbook>(UniverInstanceType.SHEET).subscribe((workbook) => {
// this._univerInstanceService.getTypeOfUnitAdded$<Workbook>(UniverInstanceType.UNIVER_SHEET).subscribe((workbook) => {
// this._resourceManagerService.registerPluginResource(workbook.getUnitId(), resourceKey, {
// onChange: (unitID, value) => {
// (value as PermissionPoint[]).forEach((permissionPoint) => {
@@ -72,7 +72,7 @@ export class PermissionService extends Disposable implements IPermissionService
// );
// this.disposeWithMe(
// toDisposable(
// this._univerInstanceService.getTypeOfUnitDisposed$<Workbook>(UniverInstanceType.SHEET).subscribe((workbook) => {
// this._univerInstanceService.getTypeOfUnitDisposed$<Workbook>(UniverInstanceType.UNIVER_SHEET).subscribe((workbook) => {
// this._resourceManagerService.disposePluginResource(workbook.getUnitId(), resourceKey);
// })
// )
@@ -34,13 +34,13 @@ export class UniverPermissionService extends Disposable {
}
private _init() {
this._univerInstanceService.getTypeOfUnitAdded$(UniverInstanceType.SHEET).subscribe((workbook) => {
this._univerInstanceService.getTypeOfUnitAdded$(UniverInstanceType.UNIVER_SHEET).subscribe((workbook) => {
const univerEditablePermission = new UniverEditablePermission(workbook.getUnitId());
this._permissionService.addPermissionPoint(workbook.getUnitId(), univerEditablePermission);
});
}
getEditable(unitId = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.SHEET)?.getUnitId()) {
getEditable(unitId = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET)?.getUnitId()) {
if (!unitId) {
return;
}
@@ -16,7 +16,6 @@
import type { IDisposable } from '@wendellhu/redi';
import { Inject, Injector } from '@wendellhu/redi';
import type { UniverType } from '@univerjs/protocol';
import { type UnitType, UniverInstanceType } from '../../common/unit';
import { PluginHolder } from './plugin-holder';
import type { Plugin, PluginCtor } from './plugin';
@@ -54,7 +53,7 @@ export class PluginService implements IDisposable {
this._scheduleInitPlugin();
const { type } = plugin;
if (type === UniverInstanceType.UNIVER) {
if (type === UniverInstanceType.UNIVER_UNKNOWN) {
this._pluginHolderForUniver.registerPlugin(plugin, config);
this._pluginHolderForUniver.flush();
} else {
@@ -64,7 +63,7 @@ export class PluginService implements IDisposable {
}
}
startPluginForType(type: UniverType): void {
startPluginForType(type: UniverInstanceType): void {
const holder = this._ensurePluginHolderForType(type);
holder.start();
}
+1 -1
View File
@@ -26,7 +26,7 @@ export type PluginCtor<T extends Plugin> = Ctor<T> & { type: UniverInstanceType;
export abstract class Plugin extends Disposable {
static pluginName: string;
static type: UniverInstanceType = UniverInstanceType.UNIVER;
static type: UniverInstanceType = UniverInstanceType.UNIVER_UNKNOWN;
protected abstract _injector: Injector;
@@ -15,7 +15,6 @@
*/
import { Inject } from '@wendellhu/redi';
import { UniverType } from '@univerjs/protocol';
import type { Workbook } from '../../sheets/workbook';
import type { IWorkbookData } from '../../types/interfaces';
import type { IResourceHook } from '../resource-manager/type';
@@ -39,15 +38,15 @@ export class ResourceLoaderService extends Disposable implements IResourceLoader
const handleHookAdd = (hook: IResourceHook) => {
hook.businesses.forEach((business) => {
switch (business) {
case UniverType.UNRECOGNIZED:
case UniverType.UNIVER_UNKNOWN:
case UniverType.UNIVER_SLIDE:
case UniverType.UNIVER_DOC: {
case UniverInstanceType.UNRECOGNIZED:
case UniverInstanceType.UNIVER_UNKNOWN:
case UniverInstanceType.UNIVER_SLIDE:
case UniverInstanceType.UNIVER_DOC: {
// TODO@gggpound: wait to support.
break;
}
case UniverType.UNIVER_SHEET: {
this._univerInstanceService.getAllUnitsForType<Workbook>(UniverInstanceType.SHEET).forEach((workbook) => {
case UniverInstanceType.UNIVER_SHEET: {
this._univerInstanceService.getAllUnitsForType<Workbook>(UniverInstanceType.UNIVER_SHEET).forEach((workbook) => {
const snapshotResource = workbook.getSnapshot().resources || [];
const plugin = snapshotResource.find((r) => r.name === hook.pluginName);
if (plugin) {
@@ -75,7 +74,7 @@ export class ResourceLoaderService extends Disposable implements IResourceLoader
this.disposeWithMe(
toDisposable(
this._univerInstanceService.getTypeOfUnitAdded$<Workbook>(UniverInstanceType.SHEET).subscribe((workbook) => {
this._univerInstanceService.getTypeOfUnitAdded$<Workbook>(UniverInstanceType.UNIVER_SHEET).subscribe((workbook) => {
this._resourceManagerService.loadResources(workbook.getUnitId(), workbook.getSnapshot().resources);
})
)
@@ -83,7 +82,7 @@ export class ResourceLoaderService extends Disposable implements IResourceLoader
this.disposeWithMe(
toDisposable(
this._univerInstanceService.getTypeOfUnitDisposed$<Workbook>(UniverInstanceType.SHEET).subscribe((workbook) => {
this._univerInstanceService.getTypeOfUnitDisposed$<Workbook>(UniverInstanceType.UNIVER_SHEET).subscribe((workbook) => {
this._resourceManagerService.unloadResources(workbook.getUnitId());
})
)
@@ -17,14 +17,14 @@
import type { IDisposable } from '@wendellhu/redi';
import { createIdentifier } from '@wendellhu/redi';
import type { Observable } from 'rxjs';
import type { UniverType } from '@univerjs/protocol';
import type { UniverInstanceType } from '@univerjs/core';
import type { IWorkbookData } from '../../types/interfaces/i-workbook-data';
type IBusinessName = 'SHEET' | 'DOC';
export type IResourceName = `${IBusinessName}_${string}_PLUGIN`;
export interface IResourceHook<T = any> {
pluginName: IResourceName;
businesses: UniverType[];
businesses: UniverInstanceType[];
onLoad: (unitID: string, resource: T) => void;
onUnLoad: (unitID: string) => void;
toJson: (unitID: string) => string;
+2 -2
View File
@@ -43,8 +43,8 @@ export function getWorksheetUID(workbook: Workbook, worksheet: Worksheet): strin
/**
* Access and create Univer Sheets files
*/
export class Workbook extends UnitModel<IWorkbookData, UniverInstanceType.SHEET> {
override type: UniverInstanceType.SHEET = UniverInstanceType.SHEET;
export class Workbook extends UnitModel<IWorkbookData, UniverInstanceType.UNIVER_SHEET> {
override type: UniverInstanceType.UNIVER_SHEET = UniverInstanceType.UNIVER_SHEET;
private readonly _sheetCreated$ = new Subject<Worksheet>();
readonly sheetCreated$ = this._sheetCreated$.asObservable();
+1 -2
View File
@@ -14,12 +14,11 @@
* limitations under the License.
*/
import { CellValueType } from '@univerjs/protocol';
import type { Nullable } from '../shared';
import { ObjectMatrix, Rectangle, Tools } from '../shared';
import { createRowColIter } from '../shared/row-col-iter';
import type { BooleanNumber } from '../types/enum';
import { type BooleanNumber, CellValueType } from '../types/enum';
import type { ICellData, ICellDataForSheetInterceptor, IFreeze, IRange, IWorksheetData } from '../types/interfaces';
import { ColumnManager } from './column-manager';
import { Range } from './range';
+2 -2
View File
@@ -20,8 +20,8 @@ import { DEFAULT_SLIDE } from '../types/const';
import type { ISlideData, ISlidePage } from '../types/interfaces';
import { PageType } from '../types/interfaces';
export class SlideDataModel extends UnitModel<ISlideData, UniverInstanceType.SLIDE> {
override type: UniverInstanceType.SLIDE = UniverInstanceType.SLIDE;
export class SlideDataModel extends UnitModel<ISlideData, UniverInstanceType.UNIVER_SLIDE> {
override type: UniverInstanceType.UNIVER_SLIDE = UniverInstanceType.UNIVER_SLIDE;
private _snapshot: ISlideData;
+6 -6
View File
@@ -103,27 +103,27 @@ export class Univer {
* @deprecated use `createUnit` instead
*/
createUniverSheet(data: Partial<IWorkbookData>): Workbook {
return this._univerInstanceService.createUnit<IWorkbookData, Workbook>(UniverInstanceType.SHEET, data);
return this._univerInstanceService.createUnit<IWorkbookData, Workbook>(UniverInstanceType.UNIVER_SHEET, data);
}
/**
* @deprecated use `createUnit` instead
*/
createUniverDoc(data: Partial<IDocumentData>): DocumentDataModel {
return this._univerInstanceService.createUnit<IDocumentData, DocumentDataModel>(UniverInstanceType.DOC, data);
return this._univerInstanceService.createUnit<IDocumentData, DocumentDataModel>(UniverInstanceType.UNIVER_DOC, data);
}
/**
* @deprecated use `createUnit` instead
*/
createUniverSlide(data: Partial<ISlideData>): SlideDataModel {
return this._univerInstanceService.createUnit<ISlideData, SlideDataModel>(UniverInstanceType.SLIDE, data);
return this._univerInstanceService.createUnit<ISlideData, SlideDataModel>(UniverInstanceType.UNIVER_SLIDE, data);
}
private _init(injector: Injector): void {
this._univerInstanceService.registerCtorForType(UniverInstanceType.SHEET, Workbook);
this._univerInstanceService.registerCtorForType(UniverInstanceType.DOC, DocumentDataModel);
this._univerInstanceService.registerCtorForType(UniverInstanceType.SLIDE, SlideDataModel);
this._univerInstanceService.registerCtorForType(UniverInstanceType.UNIVER_SHEET, Workbook);
this._univerInstanceService.registerCtorForType(UniverInstanceType.UNIVER_DOC, DocumentDataModel);
this._univerInstanceService.registerCtorForType(UniverInstanceType.UNIVER_SLIDE, SlideDataModel);
const univerInstanceService = injector.get(IUniverInstanceService) as UniverInstanceService;
univerInstanceService.__setCreateHandler(
-3
View File
@@ -67,9 +67,6 @@
"@wendellhu/redi": "^0.13.3",
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/protocol": "^0.1.20"
},
"devDependencies": {
"@univerjs/core": "workspace:*",
"@univerjs/shared": "workspace:*",
@@ -15,9 +15,8 @@
*/
import type { ISheetDataValidationRule } from '@univerjs/core';
import { Disposable, IResourceManagerService, IUniverInstanceService, LifecycleStages, OnLifecycle } from '@univerjs/core';
import { Disposable, IResourceManagerService, IUniverInstanceService, LifecycleStages, OnLifecycle, UniverInstanceType } from '@univerjs/core';
import { Inject } from '@wendellhu/redi';
import { UniverType } from '@univerjs/protocol';
import { DataValidationModel } from '../models/data-validation-model';
type DataValidationJSON = Record<string, ISheetDataValidationRule[]>;
@@ -60,7 +59,7 @@ export class DataValidationResourceController extends Disposable {
this.disposeWithMe(
this._resourceManagerService.registerPluginResource<DataValidationJSON>({
pluginName: DATA_VALIDATION_PLUGIN_NAME,
businesses: [UniverType.UNIVER_SHEET],
businesses: [UniverInstanceType.UNIVER_SHEET],
toJson: (unitID) => toJson(unitID),
parseJson: (json) => parseJson(json),
onUnLoad: (unitID) => {
@@ -40,7 +40,7 @@ export class DataValidationSheetController extends Disposable {
getMutations: (commandInfo) => {
if (commandInfo.id === RemoveSheetCommand.id) {
const params = commandInfo.params as IRemoveSheetCommandParams;
const unitId = params.unitId || this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!.getUnitId();
const unitId = params.unitId || this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!.getUnitId();
const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);
if (!workbook) {
return { redos: [], undos: [] };
@@ -219,7 +219,7 @@ export class DocEditorBridgeController extends Disposable {
// })
// );
const currentUniverSheet = this._univerInstanceService.getAllUnitsForType<Workbook>(UniverInstanceType.SHEET);
const currentUniverSheet = this._univerInstanceService.getAllUnitsForType<Workbook>(UniverInstanceType.UNIVER_SHEET);
currentUniverSheet.forEach((unit) => {
const unitId = unit.getUnitId();
const render = this._renderManagerService.getRenderById(unitId);
@@ -111,7 +111,7 @@ export class DocUIController extends Disposable {
}
private _initDocBackground() {
const firstDocUnitId = this._univerInstanceService.getAllUnitsForType<DocumentDataModel>(UniverInstanceType.DOC)[0].getUnitId();
const firstDocUnitId = this._univerInstanceService.getAllUnitsForType<DocumentDataModel>(UniverInstanceType.UNIVER_DOC)[0].getUnitId();
if (firstDocUnitId == null) {
return;
}
@@ -126,7 +126,7 @@ export class DocUIController extends Disposable {
private _initFocusHandler(): void {
this.disposeWithMe(
this._layoutService.registerFocusHandler(UniverInstanceType.DOC, () => {
this._layoutService.registerFocusHandler(UniverInstanceType.UNIVER_DOC, () => {
const textSelectionManagerService = this._injector.get(ITextSelectionRenderManager);
textSelectionManagerService.focus();
})
+16 -16
View File
@@ -94,7 +94,7 @@ export function BoldMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
return disposable.dispose;
}),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.DOC),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
};
}
@@ -130,7 +130,7 @@ export function ItalicMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
return disposable.dispose;
}),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.DOC),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
};
}
@@ -166,7 +166,7 @@ export function UnderlineMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
return disposable.dispose;
}),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.DOC),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
};
}
@@ -202,7 +202,7 @@ export function StrikeThroughMenuItemFactory(accessor: IAccessor): IMenuButtonIt
return disposable.dispose;
}),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.DOC),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
};
}
@@ -237,7 +237,7 @@ export function SubscriptMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
return disposable.dispose;
}),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.DOC),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
};
}
@@ -272,7 +272,7 @@ export function SuperscriptMenuItemFactory(accessor: IAccessor): IMenuButtonItem
return disposable.dispose;
}),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.DOC),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
};
}
@@ -316,7 +316,7 @@ export function FontFamilySelectorMenuItemFactory(accessor: IAccessor): IMenuSel
subscriber.next(defaultValue);
return disposable.dispose;
}),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.DOC),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
};
}
@@ -361,7 +361,7 @@ export function FontSizeSelectorMenuItemFactory(accessor: IAccessor): IMenuSelec
return disposable.dispose;
}),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.DOC),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
};
}
@@ -397,7 +397,7 @@ export function TextColorSelectorMenuItemFactory(accessor: IAccessor): IMenuSele
subscriber.next(defaultColor);
return disposable.dispose;
}),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.DOC),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
// disabled$: getCurrentSheetDisabled$(accessor),
};
}
@@ -433,7 +433,7 @@ export function AlignLeftMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
return disposable.dispose;
}),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.DOC),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
};
}
@@ -468,7 +468,7 @@ export function AlignCenterMenuItemFactory(accessor: IAccessor): IMenuButtonItem
return disposable.dispose;
}),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.DOC),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
};
}
@@ -503,7 +503,7 @@ export function AlignRightMenuItemFactory(accessor: IAccessor): IMenuButtonItem
return disposable.dispose;
}),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.DOC),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
};
}
@@ -538,7 +538,7 @@ export function AlignJustifyMenuItemFactory(accessor: IAccessor): IMenuButtonIte
return disposable.dispose;
}),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.DOC),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
};
}
@@ -550,7 +550,7 @@ export function OrderListMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
icon: 'OrderSingle',
tooltip: 'toolbar.order',
positions: [MenuPosition.TOOLBAR_START],
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.DOC),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
};
}
@@ -562,7 +562,7 @@ export function BulletListMenuItemFactory(accessor: IAccessor): IMenuButtonItem
icon: 'UnorderSingle',
tooltip: 'toolbar.unorder',
positions: [MenuPosition.TOOLBAR_START],
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.DOC),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
};
}
@@ -607,7 +607,7 @@ export function BackgroundColorSelectorMenuItemFactory(accessor: IAccessor): IMe
subscriber.next(defaultColor);
return disposable.dispose;
}),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.DOC),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
};
}
@@ -182,9 +182,9 @@ export class TextSelectionController extends Disposable {
/**
* The object for selecting data in the editor is set to the current sheet.
*/
const sheetInstances = this._univerInstanceService.getAllUnitsForType<Workbook>(UniverInstanceType.SHEET);
const sheetInstances = this._univerInstanceService.getAllUnitsForType<Workbook>(UniverInstanceType.UNIVER_SHEET);
if (sheetInstances.length > 0) {
const workbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!;
const workbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;
this._editorService.setOperationSheetUnitId(workbook.getUnitId());
// this._editorService.setOperationSheetSubUnitId(workbook.getActiveSheet().getSheetId());
}
@@ -241,7 +241,7 @@ export class TextSelectionController extends Disposable {
}
private _getDocObjectById(unitId: string) {
if (this._univerInstanceService.getUnitType(unitId) !== UniverInstanceType.DOC) {
if (this._univerInstanceService.getUnitType(unitId) !== UniverInstanceType.UNIVER_DOC) {
return null;
}
+1 -1
View File
@@ -59,7 +59,7 @@ import { BackScrollController } from './controllers/back-scroll.controller';
export class UniverDocsUIPlugin extends Plugin {
static override pluginName = DOC_UI_PLUGIN_NAME;
static override type = UniverInstanceType.DOC;
static override type = UniverInstanceType.UNIVER_DOC;
constructor(
private readonly _config: IUniverDocsUIConfig,
@@ -53,11 +53,11 @@ export class DocCanvasView extends RxDisposable {
this._create(unitId);
});
this._univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.DOC).pipe(takeUntil(this.dispose$)).subscribe((documentModel) => {
this._univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_DOC).pipe(takeUntil(this.dispose$)).subscribe((documentModel) => {
this._create(documentModel?.getUnitId());
});
this._univerInstanceService.getAllUnitsForType<DocumentDataModel>(UniverInstanceType.DOC).forEach((documentModel) => {
this._univerInstanceService.getAllUnitsForType<DocumentDataModel>(UniverInstanceType.UNIVER_DOC).forEach((documentModel) => {
this._create(documentModel.getUnitId());
});
}
+1 -1
View File
@@ -27,7 +27,7 @@ export function getDocObject(
univerInstanceService: IUniverInstanceService,
renderManagerService: IRenderManagerService
): Nullable<IDocObjectParam> {
const documentModel = univerInstanceService.getCurrentUnitForType(UniverInstanceType.DOC);
const documentModel = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC);
if (!documentModel) {
return null;
}
@@ -101,7 +101,7 @@ describe('test cases in clipboard', () => {
function getFormatValueAt(key: keyof IStyleBase, pos: number) {
const univerInstanceService = get(IUniverInstanceService);
const docsModel = univerInstanceService.getUnit<DocumentDataModel>('test-doc', UniverInstanceType.DOC);
const docsModel = univerInstanceService.getUnit<DocumentDataModel>('test-doc', UniverInstanceType.UNIVER_DOC);
if (docsModel?.body?.textRuns == null) {
return;
@@ -118,7 +118,7 @@ describe('test cases in clipboard', () => {
function getTextByPosition(start: number, end: number) {
const univerInstanceService = get(IUniverInstanceService);
const docsModel = univerInstanceService.getUnit<DocumentDataModel>('test-doc', UniverInstanceType.DOC);
const docsModel = univerInstanceService.getUnit<DocumentDataModel>('test-doc', UniverInstanceType.UNIVER_DOC);
return docsModel?.body?.dataStream.slice(start, end);
}
@@ -54,7 +54,7 @@ describe('Test inline format commands', () => {
function getFormatValueAt(key: keyof IStyleBase, pos: number) {
const univerInstanceService = get(IUniverInstanceService);
const docsModel = univerInstanceService.getUnit<DocumentDataModel>('test-doc', UniverInstanceType.DOC);
const docsModel = univerInstanceService.getUnit<DocumentDataModel>('test-doc', UniverInstanceType.UNIVER_DOC);
if (docsModel?.body?.textRuns == null) {
return;
@@ -62,7 +62,7 @@ describe('replace or cover content of document', () => {
function getDataStream() {
const univerInstanceService = get(IUniverInstanceService);
const docsModel = univerInstanceService.getUnit<DocumentDataModel>('test-doc', UniverInstanceType.DOC);
const docsModel = univerInstanceService.getUnit<DocumentDataModel>('test-doc', UniverInstanceType.UNIVER_DOC);
if (docsModel?.body?.dataStream == null) {
return '';
+1 -1
View File
@@ -71,7 +71,7 @@ const PLUGIN_NAME = 'docs';
export class UniverDocsPlugin extends Plugin {
static override pluginName = PLUGIN_NAME;
static override type = UniverInstanceType.DOC;
static override type = UniverInstanceType.UNIVER_DOC;
private _config: IUniverDocsConfig;
@@ -84,10 +84,10 @@ export class DocSkeletonManagerService extends RxDisposable {
this._setCurrent(docViewModel);
});
this._univerInstanceService.getTypeOfUnitDisposed$(UniverInstanceType.DOC).pipe(takeUntil(this.dispose$)).subscribe((documentModel) => {
this._univerInstanceService.getTypeOfUnitDisposed$(UniverInstanceType.UNIVER_DOC).pipe(takeUntil(this.dispose$)).subscribe((documentModel) => {
this._docSkeletonMap.delete(documentModel.getUnitId());
this._currentSkeletonUnitId = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.DOC)?.getUnitId() ?? '';
this._currentSkeletonUnitId = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC)?.getUnitId() ?? '';
});
}
@@ -49,16 +49,16 @@ export class DocViewModelManagerService extends RxDisposable {
private _init() {
this._univerInstanceService
.getCurrentTypeOfUnit$<DocumentDataModel>(UniverInstanceType.DOC)
.getCurrentTypeOfUnit$<DocumentDataModel>(UniverInstanceType.UNIVER_DOC)
.pipe(takeUntil(this.dispose$)).subscribe((documentModel) => {
this._create(documentModel);
});
this._univerInstanceService.getAllUnitsForType<DocumentDataModel>(UniverInstanceType.DOC).forEach((documentModel) => {
this._univerInstanceService.getAllUnitsForType<DocumentDataModel>(UniverInstanceType.UNIVER_DOC).forEach((documentModel) => {
this._create(documentModel);
});
this._univerInstanceService.getTypeOfUnitDisposed$(UniverInstanceType.DOC).pipe(takeUntil(this.dispose$)).subscribe((documentModel) => {
this._univerInstanceService.getTypeOfUnitDisposed$(UniverInstanceType.UNIVER_DOC).pipe(takeUntil(this.dispose$)).subscribe((documentModel) => {
this._docViewModelMap.delete(documentModel.getUnitId());
});
}
@@ -234,7 +234,7 @@ export function createCommandTestBed(workbookData?: IWorkbookData, dependencies?
*/
class TestPlugin extends Plugin {
static override pluginName = 'test-plugin';
static override type = UniverInstanceType.SHEET;
static override type = UniverInstanceType.UNIVER_SHEET;
private _formulaDataModel: FormulaDataModel | null = null;
@@ -265,7 +265,7 @@ export function createCommandTestBed(workbookData?: IWorkbookData, dependencies?
logService.setLogLevel(LogLevel.SILENT); // change this to `true` to debug tests via logs
const sheetData: ISheetData = {};
const workbook = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!;
const workbook = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;
const unitId = workbook.getUnitId();
const sheetId = workbook.getActiveSheet().getSheetId();
workbook.getSheets().forEach((sheet) => {
@@ -311,7 +311,7 @@ export function isReferenceStringWithEffectiveColumn(refString: string) {
/**
* implement getSheetIdByName
* function getSheetIdByName(name: string) {
return univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)?.getSheetBySheetName(name)?.getSheetId() || '';
return univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetName(name)?.getSheetId() || '';
}
*/
export function getRangeWithRefsString(refString: string, getSheetIdByName: (name: string) => string): IUnitRangeWithName[] {
@@ -157,7 +157,7 @@ export function createFunctionTestBed(workbookData?: IWorkbookData, dependencies
*/
class TestPlugin extends Plugin {
static override pluginName = 'test-plugin';
static override type = UniverInstanceType.SHEET;
static override type = UniverInstanceType.UNIVER_SHEET;
private _formulaDataModel: FormulaDataModel | null = null;
@@ -213,7 +213,7 @@ export function createFunctionTestBed(workbookData?: IWorkbookData, dependencies
logService.setLogLevel(LogLevel.SILENT); // change this to `true` to debug tests via logs
const sheetData: ISheetData = {};
const workbook = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!;
const workbook = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;
const unitId = workbook.getUnitId();
const sheetId = workbook.getActiveSheet().getSheetId();
workbook.getSheets().forEach((sheet) => {
@@ -60,7 +60,7 @@ export function createCommandTestBed(workbookData?: IWorkbookData, dependencies?
*/
class TestPlugin extends Plugin {
static override pluginName = 'test-plugin';
static override type = UniverInstanceType.SHEET;
static override type = UniverInstanceType.UNIVER_SHEET;
constructor(
_config: undefined,
@@ -257,13 +257,13 @@ export class FormulaDataModel extends Disposable {
initFormulaData() {
// Load formula data from workbook config data.
const allSheets = this._univerInstanceService.getAllUnitsForType<Workbook>(UniverInstanceType.SHEET);
const allSheets = this._univerInstanceService.getAllUnitsForType<Workbook>(UniverInstanceType.UNIVER_SHEET);
if (allSheets.length === 0) {
return;
}
// Since there is at least a sheet, there must be current univer sheet instance.
const workbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!;
const workbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;
const unitId = workbook.getUnitId();
this._formulaData[unitId] = {};
@@ -277,7 +277,7 @@ export class FormulaDataModel extends Disposable {
}
getCalculateData() {
const unitAllSheet = this._univerInstanceService.getAllUnitsForType<Workbook>(UniverInstanceType.SHEET);
const unitAllSheet = this._univerInstanceService.getAllUnitsForType<Workbook>(UniverInstanceType.UNIVER_SHEET);
const allUnitData: IUnitData = {};
@@ -366,9 +366,9 @@ export class FormulaCurrentConfigService extends Disposable implements IFormulaC
}
private _loadSheetData() {
const unitAllSheet = this._univerInstanceService.getAllUnitsForType<Workbook>(UniverInstanceType.SHEET);
const unitAllSheet = this._univerInstanceService.getAllUnitsForType<Workbook>(UniverInstanceType.UNIVER_SHEET);
const workbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!;
const workbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;
const worksheet = workbook?.getActiveSheet();
this._executeUnitId = workbook?.getUnitId();
@@ -87,7 +87,7 @@ export function createTestBed(workbookData?: IWorkbookData, dependencies?: Depen
class TestPlugin extends Plugin {
static override pluginName = 'test-plugin';
static override type = UniverInstanceType.SHEET;
static override type = UniverInstanceType.UNIVER_SHEET;
constructor(
_config: undefined,
+3 -3
View File
@@ -71,7 +71,7 @@ export class FUniver {
* @returns Spreadsheet API instance.
*/
createUniverSheet(data: Partial<IWorkbookData>): FWorkbook {
const workbook = this._univerInstanceService.createUnit<IWorkbookData, Workbook>(UniverInstanceType.SHEET, data);
const workbook = this._univerInstanceService.createUnit<IWorkbookData, Workbook>(UniverInstanceType.UNIVER_SHEET, data);
return this._injector.createInstance(FWorkbook, workbook);
}
@@ -81,7 +81,7 @@ export class FUniver {
* @returns Document API instance.
*/
createUniverDoc(data: Partial<IDocumentData>): FDocument {
const document = this._univerInstanceService.createUnit<IDocumentData, DocumentDataModel>(UniverInstanceType.DOC, data);
const document = this._univerInstanceService.createUnit<IDocumentData, DocumentDataModel>(UniverInstanceType.UNIVER_DOC, data);
return this._injector.createInstance(FDocument, document);
}
@@ -118,7 +118,7 @@ export class FUniver {
* @returns the currently focused Univer spreadsheet.
*/
getActiveWorkbook(): FWorkbook | null {
const workbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!;
const workbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;
if (!workbook) {
return null;
}
@@ -74,7 +74,7 @@ export function createTestBed(workbookData?: IWorkbookData, dependencies?: Depen
class TestPlugin extends Plugin {
static override pluginName = 'test-plugin';
static override type = UniverInstanceType.SHEET;
static override type = UniverInstanceType.UNIVER_SHEET;
constructor(
_config: undefined,
@@ -168,7 +168,7 @@ export class FWorkbook {
onSelectionChange(callback: (selections: IRange[]) => void): IDisposable {
return toDisposable(
this._selectionManagerService.selectionMoveEnd$.subscribe((selections) => {
if (this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!.getUnitId() !== this.id) {
if (this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!.getUnitId() !== this.id) {
return;
}
@@ -32,7 +32,7 @@ export function FindReplaceMenuItemFactory(accessor: IAccessor): IMenuButtonItem
group: MenuGroup.TOOLBAR_OTHERS,
type: MenuItemType.BUTTON,
positions: [MenuPosition.TOOLBAR_START],
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.SHEET),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
disabled$: combineLatest([
contextService.subscribeContextValue$(EDITOR_ACTIVATED),
contextService.subscribeContextValue$(FOCUSING_SHEET),
@@ -74,18 +74,18 @@ export class DataSyncPrimaryController extends RxDisposable {
}
private _init(): void {
this._univerInstanceService.getTypeOfUnitAdded$<Workbook>(UniverInstanceType.SHEET).pipe(takeUntil(this.dispose$)).subscribe((sheet) => {
this._univerInstanceService.getTypeOfUnitAdded$<Workbook>(UniverInstanceType.UNIVER_SHEET).pipe(takeUntil(this.dispose$)).subscribe((sheet) => {
this._syncingUnits.add(sheet.getUnitId());
// If a sheet is created, it should sync the data to the worker thread.
this._remoteInstanceService.createInstance({
unitID: sheet.getUnitId(),
type: UniverInstanceType.SHEET,
type: UniverInstanceType.UNIVER_SHEET,
snapshot: sheet.getSnapshot(),
});
});
this._univerInstanceService.getTypeOfUnitDisposed$<Workbook>(UniverInstanceType.SHEET).pipe(takeUntil(this.dispose$)).subscribe((workbook) => {
this._univerInstanceService.getTypeOfUnitDisposed$<Workbook>(UniverInstanceType.UNIVER_SHEET).pipe(takeUntil(this.dispose$)).subscribe((workbook) => {
this._syncingUnits.delete(workbook.getUnitId());
// If a sheet is disposed, it should sync the data to the worker thread.
this._remoteInstanceService.disposeInstance({
@@ -86,8 +86,8 @@ export class WebWorkerRemoteInstanceService implements IRemoteInstanceService {
const { type, snapshot } = params;
try {
switch (type) {
case UniverInstanceType.SHEET:
this._univerInstanceService.createUnit(UniverInstanceType.SHEET, snapshot);
case UniverInstanceType.UNIVER_SHEET:
this._univerInstanceService.createUnit(UniverInstanceType.UNIVER_SHEET, snapshot);
return true;
default:
throw new Error(
@@ -33,8 +33,8 @@ const createOptionItem = (text: string, localeService: LocaleService) => ({ labe
const TextInput = (props: { id: string; type: CFValueType | 'none';value: number | string;onChange: (v: number | string) => void; className: string }) => {
const { type, className, onChange, id, value } = props;
const univerInstanceService = useDependency(IUniverInstanceService);
const unitId = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!.getUnitId();
const subUnitId = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!.getActiveSheet().getSheetId();
const unitId = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!.getUnitId();
const subUnitId = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!.getActiveSheet().getSheetId();
const formulaInitValue = useMemo(() => {
return String(value).startsWith('=') ? String(value) : '=';
}, [value]);
@@ -33,8 +33,8 @@ const createOptionItem = (text: CFValueType, localeService: LocaleService) => ({
const InputText = (props: { disabled?: boolean; id: string; className: string; type: CFValueType;value: string | number;onChange: (v: string | number) => void }) => {
const { onChange, className, value, type, id, disabled = false } = props;
const univerInstanceService = useDependency(IUniverInstanceService);
const unitId = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!.getUnitId();
const subUnitId = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!.getActiveSheet().getSheetId();
const unitId = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!.getUnitId();
const subUnitId = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!.getActiveSheet().getSheetId();
const _value = useRef(value);
const config = useMemo(() => {
if ([CFValueType.percentile, CFValueType.percent].includes(type)) {
@@ -31,7 +31,7 @@ export const FormulaStyleEditor = (props: IStyleEditorProps) => {
const { onChange, interceptorManager } = props;
const localeService = useDependency(LocaleService);
const univerInstanceService = useDependency(IUniverInstanceService);
const workbook = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!;
const workbook = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;
const worksheet = workbook.getActiveSheet();
const rule = props.rule?.type === CFRuleType.highlightCell ? props.rule : undefined as IRankHighlightCell | IAverageHighlightCell | undefined;
@@ -39,8 +39,8 @@ const getIcon = (iconType: string, iconId: string | number) => {
const TextInput = (props: { id: number; type: CFValueType; value: number | string;onChange: (v: number | string) => void; error?: string }) => {
const univerInstanceService = useDependency(IUniverInstanceService);
const unitId = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!.getUnitId();
const subUnitId = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!.getActiveSheet().getSheetId();
const unitId = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!.getUnitId();
const subUnitId = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!.getActiveSheet().getSheetId();
const className = useMemo(() => {
if (props.error) {
return styles.errorInput;
@@ -47,8 +47,8 @@ interface IRuleEditProps {
onCancel: () => void;
}
const getUnitId = (univerInstanceService: IUniverInstanceService) => univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!.getUnitId();
const getSubUnitId = (univerInstanceService: IUniverInstanceService) => univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!.getActiveSheet().getSheetId();
const getUnitId = (univerInstanceService: IUniverInstanceService) => univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!.getUnitId();
const getSubUnitId = (univerInstanceService: IUniverInstanceService) => univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!.getActiveSheet().getSheetId();
export const RuleEdit = (props: IRuleEditProps) => {
const localeService = useDependency(LocaleService);
@@ -184,7 +184,7 @@ export const RuleEdit = (props: IRuleEditProps) => {
const handleSubmit = () => {
const beforeSubmitResult = interceptorManager.fetchThroughInterceptors(interceptorManager.getInterceptPoints().beforeSubmit)(true, null);
const getRanges = () => {
const worksheet = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!.getActiveSheet();
const worksheet = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!.getActiveSheet();
const ranges = rangeResult.current.map((range) => setEndForRange(range, worksheet.getRowCount(), worksheet.getColumnCount()));
const result = ranges.filter((range) => !(Number.isNaN(range.startRow) || Number.isNaN(range.startColumn)));
return result;
@@ -113,7 +113,7 @@ export const RuleList = (props: IRuleListProps) => {
const localeService = useDependency(LocaleService);
const conditionalFormattingI18nController = useDependency(ConditionalFormattingI18nController);
const workbook = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!;
const workbook = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;
const unitId = workbook.getUnitId();
const worksheet = workbook.getActiveSheet();
const subUnitId = worksheet.getSheetId();
@@ -176,7 +176,7 @@ export const RuleList = (props: IRuleListProps) => {
const commandList = [SetSelectionsOperation.id, AddConditionalRuleMutation.id, SetConditionalRuleMutation.id, DeleteConditionalRuleMutation.id, MoveConditionalRuleMutation.id];
const disposable = commandService.onCommandExecuted((commandInfo) => {
const { id, params } = commandInfo;
const unitId = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!.getUnitId();
const unitId = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!.getUnitId();
if (commandList.includes(id) && (params as { unitId: string }).unitId === unitId) {
commandSubscribe.next(null);
}
@@ -239,8 +239,8 @@ export const RuleList = (props: IRuleListProps) => {
}, []);
const handleDelete = (rule: IConditionFormattingRule) => {
const unitId = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!.getUnitId();
const subUnitId = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!.getActiveSheet().getSheetId();
const unitId = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!.getUnitId();
const subUnitId = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!.getActiveSheet().getSheetId();
commandService.executeCommand(DeleteCfCommand.id, { unitId, subUnitId, cfId: rule.cfId } as IDeleteCfCommandParams);
};
@@ -250,8 +250,8 @@ export const RuleList = (props: IRuleListProps) => {
const handleDragStop = (_layout: unknown, from: { y: number }, to: { y: number }) => {
draggingIdSet(-1);
const unitId = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!.getUnitId();
const subUnitId = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!.getActiveSheet().getSheetId();
const unitId = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!.getUnitId();
const subUnitId = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!.getActiveSheet().getSheetId();
const getSaveIndex = (index: number) => {
const length = ruleList.length;
return Math.min(length - 1, Math.max(0, index));
@@ -51,8 +51,8 @@ export class ConditionalFormattingAutoFillController extends Disposable {
matrixMap: Map<string, ObjectMatrix<1>>,
mapFunc: (row: number, col: number) => ({ row: number; col: number })
) => {
const unitId = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!.getUnitId();
const subUnitId = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!.getActiveSheet().getSheetId();
const unitId = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!.getUnitId();
const subUnitId = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!.getActiveSheet().getSheetId();
const sourceRange = {
startRow: sourceStartCell.row,
startColumn: sourceStartCell.col,
@@ -142,8 +142,8 @@ export class ConditionalFormattingAutoFillController extends Disposable {
};
const generalApplyFunc = (sourceRange: IDiscreteRange, targetRange: IDiscreteRange) => {
const unitId = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)?.getUnitId();
const subUnitId = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)?.getActiveSheet().getSheetId();
const unitId = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)?.getUnitId();
const subUnitId = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)?.getActiveSheet().getSheetId();
const matrixMap: Map<string, ObjectMatrix<1>> = new Map();
const redos: IMutationInfo[] = [];
@@ -46,7 +46,7 @@ export class ConditionalFormattingClearController extends Disposable {
if (!ranges) {
return defaultV;
}
const workbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!;
const workbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;
const worksheet = workbook.getActiveSheet();
const allRules = this._conditionalFormattingRuleModel.getSubunitRules(workbook.getUnitId(), worksheet.getSheetId());
if (!allRules || !allRules.length) {
@@ -123,7 +123,7 @@ export class ConditionalFormattingCopyPasteController extends Disposable {
pasteType: string;
}
) {
const workbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!;
const workbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;
const sheet = workbook.getActiveSheet();
const unitId = workbook.getUnitId();
const subUnitId = sheet.getSheetId();
@@ -94,7 +94,7 @@ export class RefRangeController extends Disposable {
toDisposable(
this._conditionalFormattingRuleModel.$ruleChange.subscribe((option) => {
const { unitId, subUnitId, rule } = option;
const workbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!;
const workbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;
const worksheet = workbook.getActiveSheet();
if (option.unitId !== workbook.getUnitId() || option.subUnitId !== worksheet.getSheetId()) {
return;
@@ -61,7 +61,7 @@ export class RenderController extends Disposable {
this.disposeWithMe(this._renderManagerService.currentRender$.subscribe((renderId) => {
renderId && register(renderId);
}));
const workbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!;
const workbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;
if (workbook) {
register(workbook.getUnitId());
}
@@ -70,13 +70,13 @@ export class RenderController extends Disposable {
_initSkeleton() {
const markDirtySkeleton = () => {
this._sheetSkeletonManagerService.reCalculate();
const unitId = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!.getUnitId();
const unitId = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!.getUnitId();
this._renderManagerService.getRenderById(unitId)?.mainComponent?.makeDirty();
};
// After the conditional formatting is marked dirty to drive a rendering, to trigger the window within the conditional formatting recalculation
this.disposeWithMe(this._conditionalFormattingViewModel.markDirty$.pipe(bufferTime(16), filter((v) => {
const workbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET);
const workbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET);
if (!workbook) return false;
const worksheet = workbook.getActiveSheet();
@@ -85,7 +85,7 @@ export class RenderController extends Disposable {
// Sort and delete does not mark dirty.
this.disposeWithMe(this._conditionalFormattingRuleModel.$ruleChange.pipe(bufferTime(16), filter((v) => {
const workbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET);
const workbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET);
if (!workbook) return false;
const worksheet = workbook.getActiveSheet();
@@ -95,7 +95,7 @@ export class RenderController extends Disposable {
// Once the calculation is complete, a view update is triggered
// This rendering does not trigger conditional formatting recalculation,because the rule is not mark dirty
this.disposeWithMe(this._conditionalFormattingService.ruleComputeStatus$.pipe(bufferTime(16), filter((v) => {
const workbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET);
const workbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET);
if (!workbook) return false;
const worksheet = workbook.getActiveSheet();
@@ -44,7 +44,7 @@ export const FactoryManageConditionalFormattingRule = (componentManager: Compone
new Observable<null>((commandSubscribe) => {
const disposable = commandService.onCommandExecuted((commandInfo) => {
const { id, params } = commandInfo;
const unitId = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)?.getUnitId();
const unitId = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)?.getUnitId();
if (commandList.includes(id) && (params as { unitId: string }).unitId === unitId) {
commandSubscribe.next(null);
}
@@ -53,7 +53,7 @@ export const FactoryManageConditionalFormattingRule = (componentManager: Compone
})
).pipe(debounceTime(16)).subscribe(() => {
const ranges = selectionManagerService.getSelections()?.map((selection) => selection.range) || [];
const workbook = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET);
const workbook = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET);
if (!workbook) return;
const allRule = conditionalFormattingRuleModel.getSubunitRules(workbook.getUnitId(), workbook.getActiveSheet().getSheetId()) || [];
const ruleList = allRule.filter((rule) => rule.ranges.some((ruleRange) => ranges.some((range) => Rectangle.intersects(range, ruleRange))));
@@ -65,7 +65,7 @@ export const FactoryManageConditionalFormattingRule = (componentManager: Compone
new Observable<null>((commandSubscribe) => {
const disposable = commandService.onCommandExecuted((commandInfo) => {
const { id, params } = commandInfo;
const unitId = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)?.getUnitId();
const unitId = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)?.getUnitId();
if (commandList.includes(id) && (params as { unitId: string }).unitId === unitId) {
commandSubscribe.next(null);
}
@@ -73,7 +73,7 @@ export const FactoryManageConditionalFormattingRule = (componentManager: Compone
return () => disposable.dispose();
})
).pipe(debounceTime(16)).subscribe(() => {
const workbook = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET);
const workbook = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET);
if (!workbook) return;
const allRule = conditionalFormattingRuleModel.getSubunitRules(workbook.getUnitId(), workbook.getActiveSheet().getSheetId()) || [];
subscriber.next(!!allRule.length);
@@ -105,7 +105,7 @@ export const FactoryManageConditionalFormattingRule = (componentManager: Compone
icon: key,
tooltip: localeService.t('sheet.cf.title'),
selections: selections$,
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.SHEET),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
} as IMenuSelectorItem;
};
};
@@ -45,7 +45,7 @@ import { ConditionalFormattingClearController } from './controllers/cf.clear.con
export class UniverSheetsConditionalFormattingUIPlugin extends Plugin {
static override pluginName = SHEET_CONDITIONAL_FORMATTING_PLUGIN;
static override type = UniverInstanceType.SHEET;
static override type = UniverInstanceType.UNIVER_SHEET;
static commandList = [
AddAverageCfCommand,
@@ -72,9 +72,6 @@
"dayjs": ">=1.11.0",
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/protocol": "^0.1.20"
},
"devDependencies": {
"@univerjs/core": "workspace:*",
"@univerjs/engine-formula": "workspace:*",
@@ -31,7 +31,7 @@ import { ConditionalFormattingFormulaMarkDirty } from './commands/mutations/form
export class SheetsConditionalFormattingPlugin extends Plugin {
static override pluginName = SHEET_CONDITIONAL_FORMATTING_PLUGIN;
static override type = UniverInstanceType.SHEET;
static override type = UniverInstanceType.UNIVER_SHEET;
static readonly dependencyList: Dependency[] = [[ConditionalFormattingService], [ConditionalFormattingFormulaService], [ConditionalFormattingRuleModel], [ConditionalFormattingViewModel]];
static readonly mutationList = [AddConditionalRuleMutation, DeleteConditionalRuleMutation, SetConditionalRuleMutation, MoveConditionalRuleMutation, ConditionalFormattingFormulaMarkDirty];
@@ -61,7 +61,7 @@ export const createTestBed = (dependencies?: Dependency[]) => {
class TestPlugin extends Plugin {
static override pluginName = 'test-plugin';
static override type = UniverInstanceType.SHEET;
static override type = UniverInstanceType.UNIVER_SHEET;
constructor(
_config: undefined,
@@ -21,7 +21,6 @@ import { InsertColMutation, InsertRowMutation, MoveColsMutation, MoveRangeMutati
import { Inject, Injector } from '@wendellhu/redi';
import { Subject } from 'rxjs';
import { filter } from 'rxjs/operators';
import { UniverType } from '@univerjs/protocol';
import type { IDeleteConditionalRuleMutationParams } from '../commands/mutations/delete-conditional-rule.mutation';
import { DeleteConditionalRuleMutation, DeleteConditionalRuleMutationUndoFactory } from '../commands/mutations/delete-conditional-rule.mutation';
import { ConditionalFormattingRuleModel } from '../models/conditional-formatting-rule-model';
@@ -142,7 +141,7 @@ export class ConditionalFormattingService extends Disposable {
this.disposeWithMe(
this._resourceManagerService.registerPluginResource<IRuleModelJson[keyof IRuleModelJson]>({
pluginName: SHEET_CONDITIONAL_FORMATTING_PLUGIN,
businesses: [UniverType.UNIVER_SHEET],
businesses: [UniverInstanceType.UNIVER_SHEET],
toJson: (unitID) => toJson(unitID),
parseJson: (json) => parseJson(json),
onUnLoad: (unitID) => {
@@ -396,5 +395,5 @@ export class ConditionalFormattingService extends Disposable {
}
}
const getUnitId = (u: IUniverInstanceService) => u.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!.getUnitId();
const getSubUnitId = (u: IUniverInstanceService) => u.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!.getActiveSheet().getSheetId();
const getUnitId = (u: IUniverInstanceService) => u.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!.getUnitId();
const getSubUnitId = (u: IUniverInstanceService) => u.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!.getActiveSheet().getSheetId();
+1 -1
View File
@@ -59,5 +59,5 @@ export const DEFAULT_WORKBOOK_DATA_DEMO: IWorkbookData = {
}
// 加载初始snapshot
univer.createUnit(UniverInstanceType.SHEET, DEFAULT_WORKBOOK_DATA_DEMO);
univer.createUnit(UniverInstanceType.UNIVER_SHEET, DEFAULT_WORKBOOK_DATA_DEMO);
```
+1 -1
View File
@@ -58,5 +58,5 @@ export const DEFAULT_WORKBOOK_DATA_DEMO: IWorkbookData = {
}
// load initial snapshot
univer.createUnit(UniverInstanceType.SHEET, DEFAULT_WORKBOOK_DATA_DEMO);
univer.createUnit(UniverInstanceType.UNIVER_SHEET, DEFAULT_WORKBOOK_DATA_DEMO);
```
@@ -41,7 +41,7 @@ export class DataValidationAlertController extends Disposable {
private _initCellAlertPopup() {
this.disposeWithMe(this._hoverManagerService.currentCell$.subscribe((cellPos) => {
if (cellPos) {
const workbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!;
const workbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;
const worksheet = workbook.getActiveSheet();
const cellData = worksheet.getCell(cellPos.location.row, cellPos.location.col);
@@ -173,7 +173,7 @@ export class DataValidationRenderController extends RxDisposable {
private _initSkeletonChange() {
const markSkeletonDirty = () => {
const workbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET);
const workbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET);
if (!workbook) return;
const unitId = workbook.getUnitId();
@@ -78,7 +78,7 @@ export class DataValidationController extends RxDisposable {
private _initInstanceChange() {
const disposableCollection = new DisposableCollection();
this._univerInstanceService.getCurrentTypeOfUnit$<Workbook>(UniverInstanceType.SHEET).subscribe((workbook) => {
this._univerInstanceService.getCurrentTypeOfUnit$<Workbook>(UniverInstanceType.UNIVER_SHEET).subscribe((workbook) => {
disposableCollection.dispose();
if (!workbook) {
return;
@@ -103,7 +103,7 @@ export class DataValidationController extends RxDisposable {
this._sheetInterceptorService.interceptCommand({
getMutations: (commandInfo) => {
if (commandInfo.id === ClearSelectionAllCommand.id) {
const workbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!;
const workbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;
const unitId = workbook.getUnitId();
const worksheet = workbook.getActiveSheet();
const subUnitId = worksheet.getSheetId();
@@ -31,7 +31,7 @@ export function dataValidationMenuFactory(accessor: IAccessor): IMenuItem {
group: MenuGroup.TOOLBAR_FORMULAS_INSERT,
icon: DataValidationIcon,
tooltip: 'dataValidation.title',
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.SHEET),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
};
}
@@ -37,7 +37,7 @@ import { DataValidationPanelService } from './services/data-validation-panel.ser
export class UniverSheetsDataValidationPlugin extends Plugin {
static override pluginName = DATA_VALIDATION_PLUGIN_NAME;
static override type = UniverInstanceType.SHEET;
static override type = UniverInstanceType.UNIVER_SHEET;
constructor(
_config: unknown,
@@ -137,7 +137,7 @@ export class ListValidator extends BaseDataValidator {
getList(rule: IDataValidationRule, currentUnitId?: string, currentSubUnitId?: string) {
const { formula1 = '' } = rule;
const univerInstanceService = this.injector.get(IUniverInstanceService);
const workbook = (currentUnitId ? univerInstanceService.getUniverSheetInstance(currentUnitId) : undefined) ?? univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET);
const workbook = (currentUnitId ? univerInstanceService.getUniverSheetInstance(currentUnitId) : undefined) ?? univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET);
if (!workbook) return [];
const worksheet = (currentSubUnitId ? workbook.getSheetBySheetId(currentSubUnitId) : undefined) ?? workbook.getActiveSheet();
@@ -150,7 +150,7 @@ export class ListValidator extends BaseDataValidator {
async getListAsync(rule: IDataValidationRule, currentUnitId?: string, currentSubUnitId?: string) {
const { formula1 = '' } = rule;
const univerInstanceService = this.injector.get(IUniverInstanceService);
const workbook = (currentUnitId ? univerInstanceService.getUniverSheetInstance(currentUnitId) : undefined) ?? univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET);
const workbook = (currentUnitId ? univerInstanceService.getUniverSheetInstance(currentUnitId) : undefined) ?? univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET);
if (!workbook) {
return [];
}
@@ -21,7 +21,7 @@ import { getCellValueOrigin } from '../utils/get-cell-data-origin';
export function getSheetRangeValueSet(grid: IUnitRangeName, univerInstanceService: IUniverInstanceService, currUnitId: string, currSubUnitId: string) {
const set = new Set<string>();
const unitId = grid.unitId || currUnitId;
const workbook = univerInstanceService.getUniverSheetInstance(unitId) ?? univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!;
const workbook = univerInstanceService.getUniverSheetInstance(unitId) ?? univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;
const worksheet = workbook.getSheetBySheetName(grid.sheetName) ?? workbook.getSheetBySheetId(currSubUnitId) ?? workbook.getActiveSheet();
Range.foreach(grid.range, (row, col) => {
const data = worksheet.getCellRaw(row, col);
@@ -35,7 +35,7 @@ export const DataValidationList = memo(() => {
const injector = useDependency(Injector);
const dataValidationPanelService = useDependency(DataValidationPanelService);
const workbook = useObservable(
() => univerInstanceService.getCurrentTypeOfUnit$<Workbook>(UniverInstanceType.SHEET),
() => univerInstanceService.getCurrentTypeOfUnit$<Workbook>(UniverInstanceType.UNIVER_SHEET),
undefined,
true,
[]
@@ -84,7 +84,7 @@ function createFilterCommandTestBed() {
class SheetsFilterCommandTestPlugin extends Plugin {
static override pluginName = 'sheets-filter-command-test';
static override type = UniverInstanceType.SHEET;
static override type = UniverInstanceType.UNIVER_SHEET;
constructor(_config: unknown, @Inject(Injector) protected readonly _injector: Injector) {
super();
}
@@ -68,7 +68,7 @@ function createFilterOperationTestBed() {
const get = injector.get.bind(injector);
class SheetsFilterOperationTestPlugin extends Plugin {
static override type = UniverInstanceType.SHEET;
static override type = UniverInstanceType.UNIVER_SHEET;
static override pluginName = 'sheets-filter-operation-test';
constructor(_config: unknown, @Inject(Injector) protected readonly _injector: Injector) {
@@ -37,7 +37,7 @@ export const SmartToggleSheetsFilterCommand: ICommand = {
const commandService = accessor.get(ICommandService);
const undoRedoService = accessor.get(IUndoRedoService);
const currentWorkbook = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET);
const currentWorkbook = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET);
const currentWorksheet = currentWorkbook?.getActiveSheet();
if (!currentWorksheet || !currentWorkbook) return false;
@@ -53,7 +53,7 @@ function createSheetsFilterMenuTestBed() {
const get = injector.get.bind(injector);
class TestPlugin extends Plugin {
static override type = UniverInstanceType.SHEET;
static override type = UniverInstanceType.UNIVER_SHEET;
static override pluginName = 'test-plugin';
constructor(_config: unknown, override readonly _injector: Injector) {
@@ -33,7 +33,7 @@ export function SmartToggleFilterMenuItemFactory(accessor: IAccessor): IMenuSele
icon: 'FilterSingle',
tooltip: 'sheets-filter.toolbar.smart-toggle-filter-tooltip',
positions: [MenuPosition.TOOLBAR_START],
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.SHEET),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
activated$: sheetsFilterService.activeFilterModel$.pipe(map((model) => !!model)),
};
}
@@ -47,7 +47,7 @@ export function ClearFilterCriteriaMenuItemFactory(accessor: IAccessor): IMenuBu
type: MenuItemType.BUTTON,
title: 'sheets-filter.toolbar.clear-filter-criteria',
positions: [SmartToggleSheetsFilterCommand.id],
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.SHEET),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
disabled$: sheetsFilterService.activeFilterModel$.pipe(switchMap((model) => model?.hasCriteria$.pipe(map((m) => !m)) ?? of(true))),
};
}
@@ -61,7 +61,7 @@ export function ReCalcFilterMenuItemFactory(accessor: IAccessor): IMenuButtonIte
type: MenuItemType.BUTTON,
title: 'sheets-filter.toolbar.re-calc-filter-conditions',
positions: [SmartToggleSheetsFilterCommand.id],
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.SHEET),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
disabled$: sheetsFilterService.activeFilterModel$.pipe(switchMap((model) => model?.hasCriteria$.pipe(map((m) => !m)) ?? of(true))),
};
}
+1 -1
View File
@@ -26,7 +26,7 @@ import { SheetsFilterRenderController } from './controllers/sheets-filter-render
const NAME = 'UNIVER_SHEETS_FILTER_UI_PLUGIN';
export class UniverSheetsFilterUIPlugin extends Plugin {
static override type = UniverInstanceType.SHEET;
static override type = UniverInstanceType.UNIVER_SHEET;
static override pluginName = NAME;
constructor(
@@ -47,7 +47,7 @@ function createSheetsFilterPanelServiceTestBed(workbookData: IWorkbookData) {
const get = injector.get.bind(injector);
class SheetsFilterPanelTestPlugin extends Plugin {
static override type = UniverInstanceType.SHEET;
static override type = UniverInstanceType.UNIVER_SHEET;
static override pluginName = 'sheets-filter-panel-test';
constructor(_config: unknown, @Inject(Injector) protected readonly _injector: Injector) {
@@ -48,7 +48,7 @@ function createFilterStorybookBed(workbookData: IWorkbookData, locale: LocaleTyp
const commandService = get(ICommandService);
class TestPlugin extends Plugin {
static override type = UniverInstanceType.SHEET;
static override type = UniverInstanceType.UNIVER_SHEET;
static override pluginName = 'test-plugin';
constructor(_config: unknown, override readonly _injector: Injector) {
@@ -98,7 +98,7 @@ function createFilterMutationTestBed(workbookData?: IWorkbookData) {
const get = injector.get.bind(injector);
class SheetsFilterTestPlugin extends Plugin {
static override type = UniverInstanceType.SHEET;
static override type = UniverInstanceType.UNIVER_SHEET;
static override pluginName = 'SheetsFilterTestPlugin';
constructor(_config: unknown, @Inject(Injector) protected readonly _injector: Injector) {
@@ -162,7 +162,7 @@ function createFilterTestUniver(dependencies?: Dependency[], workbookData?: IWor
* This plugin hooks into Sheet's DI system to expose API to test scripts
*/
class TestPlugin extends Plugin {
static override type = UniverInstanceType.SHEET;
static override type = UniverInstanceType.UNIVER_SHEET;
static override pluginName = 'test-plugin';
constructor(
@@ -131,7 +131,7 @@ describe('Test filter model and related utils', () => {
filterColumn = new FilterColumn(
'test',
'sheet1',
get(IUniverInstanceService).getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!.getActiveSheet()!,
get(IUniverInstanceService).getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!.getActiveSheet()!,
{ colId: 0, customFilters: { customFilters: [{ operator: CustomFilterOperator.LESS_THAN, val: 123 }] } },
{ getAlreadyFilteredOutRows() { return new Set(); } }
);
@@ -151,7 +151,7 @@ describe('Test filter model and related utils', () => {
filterColumn = new FilterColumn(
'test',
'sheet1',
get(IUniverInstanceService).getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!.getActiveSheet()!,
get(IUniverInstanceService).getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!.getActiveSheet()!,
{ colId: 0, customFilters: { customFilters: [{ operator: CustomFilterOperator.LESS_THAN, val: 123 }] } },
{ getAlreadyFilteredOutRows() { return new Set(); } }
);
@@ -169,7 +169,7 @@ describe('Test filter model and related utils', () => {
filterColumn = new FilterColumn(
'test',
'sheet1',
get(IUniverInstanceService).getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!.getActiveSheet()!,
get(IUniverInstanceService).getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!.getActiveSheet()!,
{ colId: 0, customFilters: { customFilters: [{ operator: CustomFilterOperator.LESS_THAN, val: 123 }] } },
{ getAlreadyFilteredOutRows() { return new Set(); } }
);
@@ -190,7 +190,7 @@ describe('Test filter model and related utils', () => {
filterColumn = new FilterColumn(
'test',
'sheet1',
get(IUniverInstanceService).getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!.getActiveSheet()!,
get(IUniverInstanceService).getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!.getActiveSheet()!,
{ colId: 0, customFilters: { customFilters: [{ operator: CustomFilterOperator.LESS_THAN, val: 123 }] } },
{ getAlreadyFilteredOutRows() { return new Set(); } }
);
@@ -205,7 +205,7 @@ describe('Test filter model and related utils', () => {
filterColumn = new FilterColumn(
'test',
'sheet1',
get(IUniverInstanceService).getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!.getActiveSheet()!,
get(IUniverInstanceService).getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!.getActiveSheet()!,
{ colId: 0, customFilters: { customFilters: [{ operator: CustomFilterOperator.LESS_THAN, val: 123 }] } },
{ getAlreadyFilteredOutRows() { return new Set([1]); } }
);
+1 -1
View File
@@ -24,7 +24,7 @@ import { SheetsFilterController } from './controllers/sheets-fiter.controller';
const NAME = 'UNIVER_SHEETS_FILTER_PLUGIN';
export class UniverSheetsFilterPlugin extends Plugin {
static override type = UniverInstanceType.SHEET;
static override type = UniverInstanceType.UNIVER_SHEET;
static override pluginName = NAME;
constructor(_config: unknown, @Inject(Injector) protected readonly _injector: Injector) {
@@ -119,7 +119,7 @@ export class SheetsFilterService extends Disposable {
private _updateActiveFilterModel() {
let workbook: Nullable<Workbook>;
try {
workbook = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.SHEET);
workbook = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
if (!workbook) {
this._activeFilterModel$.next(null);
return;
@@ -148,7 +148,7 @@ export class SheetsFilterService extends Disposable {
.pipe(filter(([command]) => command.type === CommandType.MUTATION && FILTER_MUTATIONS.has(command.id))),
// source2: activte sheet changes
this._univerInstanceService.getCurrentTypeOfUnit$<Workbook>(UniverInstanceType.SHEET)
this._univerInstanceService.getCurrentTypeOfUnit$<Workbook>(UniverInstanceType.UNIVER_SHEET)
.pipe(switchMap((workbook) => workbook?.activeSheet$ ?? of(null)))
).subscribe(() => this._updateActiveFilterModel()));
}
@@ -903,7 +903,7 @@ class SheetsFindReplaceProvider extends Disposable implements IFindReplaceProvid
// NOTE: If there are multi Workbook instances then we should create `SheetFindModel` for each of them.
// But we don't need to implement that in the foreseeable future.
const currentWorkbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!;
const currentWorkbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;
if (currentWorkbook) {
const sheetFind = this._injector.createInstance(SheetFindModel, currentWorkbook);
this._findModelsByUnitId.set(currentWorkbook.getUnitId(), sheetFind);
+1 -1
View File
@@ -24,7 +24,7 @@ const NAME = 'UNIVER_SHEETS_FIND_REPLACE_PLUGIN';
export class UniverSheetsFindReplacePlugin extends Plugin {
static override pluginName = NAME;
static override type = UniverInstanceType.SHEET;
static override type = UniverInstanceType.UNIVER_SHEET;
constructor(
_config: unknown,
+1 -1
View File
@@ -626,7 +626,7 @@ import { CustomFunctionController } from './controllers/custom-function.controll
export class UniverSheetsCustomFunctionPlugin extends Plugin {
static override pluginName = FORMULA_UI_PLUGIN_NAME
static override type = UniverInstanceType.SHEET;
static override type = UniverInstanceType.UNIVER_SHEET;
constructor(@Inject(Injector) override readonly _injector: Injector) {
super();
+1 -1
View File
@@ -626,7 +626,7 @@ import { CustomFunctionController } from './controllers/custom-function.controll
export class UniverSheetsCustomFunctionPlugin extends Plugin {
static override pluginName = FORMULA_UI_PLUGIN_NAME
static override type = UniverInstanceType.SHEET;
static override type = UniverInstanceType.UNIVER_SHEET;
constructor(@Inject(Injector) override readonly _injector: Injector) {
super();
@@ -55,7 +55,7 @@ export function createCommandTestBed(workbookData?: IWorkbookData, dependencies?
*/
class TestPlugin extends Plugin {
static override pluginName = 'test-plugin';
static override type = UniverInstanceType.SHEET;
static override type = UniverInstanceType.UNIVER_SHEET;
constructor(
_config: undefined,
@@ -63,7 +63,7 @@ export function createCommandTestBed(workbookData?: IWorkbookData, dependencies?
class TestPlugin extends Plugin {
static override pluginName = 'test-plugin';
static override type = UniverInstanceType.SHEET;
static override type = UniverInstanceType.UNIVER_SHEET;
private _formulaDataModel: FormulaDataModel | null = null;
@@ -69,7 +69,7 @@ export class DefinedNameController extends Disposable {
private _changeUnitListener() {
toDisposable(
this._univerInstanceService.getCurrentTypeOfUnit$<Workbook>(UniverInstanceType.SHEET).subscribe(() => {
this._univerInstanceService.getCurrentTypeOfUnit$<Workbook>(UniverInstanceType.UNIVER_SHEET).subscribe(() => {
this._unRegisterDescriptions();
this._registerDescriptions();
})
@@ -147,7 +147,7 @@ export class DefinedNameController extends Disposable {
}
private _getUnitIdAndSheetId() {
const workbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!;
const workbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;
if (workbook == null) {
return {};
}
@@ -91,7 +91,7 @@ export class FormulaClipboardController extends Disposable {
};
const pastedRange = pasteTo.range;
const matrix = data;
const workbook = this._currentUniverSheet.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!;
const workbook = this._currentUniverSheet.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;
const unitId = workbook.getUnitId();
const subUnitId = workbook.getActiveSheet().getSheetId();
@@ -61,7 +61,7 @@ export function InsertFunctionMenuItemFactory(accessor: IAccessor): IMenuItem {
icon: 'MinSingle',
},
],
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.SHEET),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
disabled$: getCurrentSheetDisabled$(accessor),
};
}
@@ -343,7 +343,7 @@ export class PromptController extends Disposable {
private _initialChangeEditor() {
this.disposeWithMe(
this._univerInstanceService.getCurrentTypeOfUnit$<DocumentDataModel>(UniverInstanceType.DOC).subscribe((documentDataModel) => {
this._univerInstanceService.getCurrentTypeOfUnit$<DocumentDataModel>(UniverInstanceType.UNIVER_DOC).subscribe((documentDataModel) => {
if (documentDataModel == null) {
return;
}
@@ -1137,7 +1137,7 @@ export class PromptController extends Disposable {
const current = this._sheetSkeletonManagerService.getCurrent();
if (current == null) {
const workbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!;
const workbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;
const worksheet = workbook.getActiveSheet();
return {
unitId: workbook.getUnitId(),
@@ -405,7 +405,7 @@ export class UpdateFormulaController extends Disposable {
toRange: { startRow: toStartRow, endRow: toEndRow },
} = params;
const workbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!;
const workbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;
const unitId = workbook.getUnitId();
const worksheet = workbook.getActiveSheet();
const sheetId = worksheet.getSheetId();
@@ -443,7 +443,7 @@ export class UpdateFormulaController extends Disposable {
toRange: { startColumn: toStartCol, endColumn: toEndCol },
} = params;
const workbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!;
const workbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;
const unitId = workbook.getUnitId();
const worksheet = workbook.getActiveSheet();
const sheetId = worksheet.getSheetId();
@@ -1377,7 +1377,7 @@ export class UpdateFormulaController extends Disposable {
}
private _getCurrentSheetInfo() {
const workbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!;
const workbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;
const unitId = workbook.getUnitId();
const sheetId = workbook.getActiveSheet().getSheetId();

Some files were not shown because too many files have changed in this diff Show More