Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
refactor: move facade test files to each packages (#4808)
wpxp12345699285446106e
diff --git a/examples/package.json b/examples/package.jsonindex 78e4ea5307..8f87d5380b 100644--- a/examples/package.json+++ b/examples/package.json@@ -36,6 +36,7 @@"@univerjs/find-replace": "workspace:*","@univerjs/icons": "0.2.20","@univerjs/mockdata": "workspace:*",+ "@univerjs/network": "workspace:*","@univerjs/rpc": "workspace:*","@univerjs/rpc-node": "workspace:*","@univerjs/sheets": "workspace:*",diff --git a/examples/src/sheets/main.ts b/examples/src/sheets/main.tsindex 34cfdacaa8..016d556bf6 100644--- a/examples/src/sheets/main.ts+++ b/examples/src/sheets/main.ts@@ -25,6 +25,7 @@ import { UniverDocsUIPlugin } from '@univerjs/docs-ui';import { UniverFormulaEnginePlugin } from '@univerjs/engine-formula';import { UniverRenderEnginePlugin } from '@univerjs/engine-render';import { DEFAULT_WORKBOOK_DATA_DEMO } from '@univerjs/mockdata';+import { UniverNetworkPlugin } from '@univerjs/network';import { UniverRPCMainThreadPlugin } from '@univerjs/rpc';import { UniverSheetsPlugin } from '@univerjs/sheets';import { UniverSheetsConditionalFormattingPlugin } from '@univerjs/sheets-conditional-formatting';@@ -67,6 +68,7 @@ import '@univerjs/sheets-source-binding/facade';import '@univerjs/sheets-crosshair-highlight/facade';import '@univerjs/sheets-formula-ui/facade';import '@univerjs/sheets-sort/facade';+import '@univerjs/network/facade';import '../global.css';import './styles';@@ -130,6 +132,7 @@ function createNewInstance() {univer.registerPlugin(UniverSheetsThreadCommentUIPlugin);univer.registerPlugin(UniverSheetsBindingSourcePlugin);univer.registerPlugin(UniverSheetsCustomMenuPlugin);+ univer.registerPlugin(UniverNetworkPlugin);// If we are running in e2e platform, we should immediately register the debugger plugin.if (IS_E2E) {diff --git a/packages/core/src/univer.ts b/packages/core/src/univer.tsindex 0df9ad66a0..b46551a43c 100644--- a/packages/core/src/univer.ts+++ b/packages/core/src/univer.ts@@ -137,7 +137,7 @@ export class Univer implements IDisposable {* @deprecated use `createUnit` instead*/createUniverSheet(data: Partial<IWorkbookData>): Workbook {- this._injector.get(ILogService).warn('[Univer]: Univer.createUniverSheet is deprecated, use createUnit instead');+ this._injector.get(ILogService).warn('[Univer]', 'Univer.createUniverSheet is deprecated, use createUnit instead');return this._univerInstanceService.createUnit<IWorkbookData, Workbook>(UniverInstanceType.UNIVER_SHEET, data);}@@ -145,7 +145,7 @@ export class Univer implements IDisposable {* @deprecated use `createUnit` instead*/createUniverDoc(data: Partial<IDocumentData>): DocumentDataModel {- this._injector.get(ILogService).warn('[Univer]: Univer.createUniverDoc is deprecated, use createUnit instead');+ this._injector.get(ILogService).warn('[Univer]', 'Univer.createUniverDoc is deprecated, use createUnit instead');return this._univerInstanceService.createUnit<IDocumentData, DocumentDataModel>(UniverInstanceType.UNIVER_DOC, data);}@@ -153,7 +153,7 @@ export class Univer implements IDisposable {* @deprecated use `createUnit` instead*/createUniverSlide(data: Partial<ISlideData>): SlideDataModel {- this._injector.get(ILogService).warn('[Univer]: Univer.createUniverSlide is deprecated, use createUnit instead');+ this._injector.get(ILogService).warn('[Univer]', 'Univer.createUniverSlide is deprecated, use createUnit instead');return this._univerInstanceService.createUnit<ISlideData, SlideDataModel>(UniverInstanceType.UNIVER_SLIDE, data);}diff --git a/packages/facade/jest.setup.ts b/packages/docs-ui/jest.setup.tssimilarity index 100%rename from packages/facade/jest.setup.tsrename to packages/docs-ui/jest.setup.tsdiff --git a/packages/docs-ui/package.json b/packages/docs-ui/package.jsonindex 23fd205055..ea1e003a54 100644--- a/packages/docs-ui/package.json+++ b/packages/docs-ui/package.json@@ -85,6 +85,8 @@"devDependencies": {"@univerjs-infra/shared": "workspace:*","@univerjs/docs-drawing": "workspace:*",+ "jest-canvas-mock": "^2.5.2",+ "jsdom": "^24.1.1","less": "^4.2.2","postcss": "^8.5.3","react": "18.3.1",diff --git a/packages/facade/src/apis/docs/__tests__/create-test-bed.ts b/packages/docs-ui/src/facade/__tests__/create-test-bed.tssimilarity index 95%rename from packages/facade/src/apis/docs/__tests__/create-test-bed.tsrename to packages/docs-ui/src/facade/__tests__/create-test-bed.tsindex a9b10fb4ad..b367b45758 100644--- a/packages/facade/src/apis/docs/__tests__/create-test-bed.ts+++ b/packages/docs-ui/src/facade/__tests__/create-test-bed.ts@@ -26,12 +26,12 @@ import {Univer,UniverInstanceType,} from '@univerjs/core';+import { FUniver } from '@univerjs/core/facade';import { DocSelectionManagerService, DocSkeletonManagerService, DocStateEmitService } from '@univerjs/docs';import { DocIMEInputManagerService, DocsRenderService, DocStateChangeManagerService } from '@univerjs/docs-ui';+import enUS from '@univerjs/docs-ui/locale/en-US';+import zhCN from '@univerjs/docs-ui/locale/zh-CN';import { IRenderManagerService, RenderManagerService } from '@univerjs/engine-render';-import enUS from '@univerjs/sheets-formula-ui/locale/en-US';-import zhCN from '@univerjs/sheets-formula-ui/locale/zh-CN';-import { FUniver } from '../../everything';function getTestDocumentDataDemo(): IDocumentData {return {diff --git a/packages/facade/src/apis/docs/__tests__/f-document.spec.ts b/packages/docs-ui/src/facade/__tests__/f-document.spec.tssimilarity index 95%rename from packages/facade/src/apis/docs/__tests__/f-document.spec.tsrename to packages/docs-ui/src/facade/__tests__/f-document.spec.tsindex 64b04f22a9..3e460cc29d 100644--- a/packages/facade/src/apis/docs/__tests__/f-document.spec.ts+++ b/packages/docs-ui/src/facade/__tests__/f-document.spec.ts@@ -15,13 +15,15 @@*/import type { Injector } from '@univerjs/core';-import type { FUniver } from '../../everything';+import type { FUniver } from '@univerjs/core/facade';import { ICommandService } from '@univerjs/core';import { RichTextEditingMutation } from '@univerjs/docs';import { InsertCommand } from '@univerjs/docs-ui';import { beforeEach, describe, expect, it } from 'vitest';import { createTestBed } from './create-test-bed';+import '@univerjs/docs-ui/facade';+describe('Test FDocument', () => {let get: Injector['get'];let commandService: ICommandService;diff --git a/packages/docs-ui/vitest.config.ts b/packages/docs-ui/vitest.config.tsindex af97c6d7a2..0778a36a56 100644--- a/packages/docs-ui/vitest.config.ts+++ b/packages/docs-ui/vitest.config.ts@@ -1,3 +1,12 @@+import path from 'node:path';import createConfig from '@univerjs-infra/shared/vitest';-export default createConfig();+export default createConfig({+ test: {+ setupFiles: [+ path.resolve(__dirname, './jest.setup.ts'),+ path.resolve(__dirname, './vitest.setup.ts'),+ ],+ environment: 'jsdom',+ },+});diff --git a/packages/facade/vitest.setup.ts b/packages/docs-ui/vitest.setup.tssimilarity index 100%rename from packages/facade/vitest.setup.tsrename to packages/docs-ui/vitest.setup.tsdiff --git a/packages/facade/README.md b/packages/facade/README.mddeleted file mode 100644index 9a7fad010a..0000000000--- a/packages/facade/README.md+++ /dev/null@@ -1,31 +0,0 @@-# @univerjs/facade--## Package Overview--| Package Name | UMD Namespace | Version | License | Downloads | Contains CSS | Contains i18n locales |-| --- | --- | --- | --- | --- | :---: | :---: |-| `@univerjs/facade` | `UniverFacade` | [![][npm-version-shield]][npm-version-link] | ![][npm-license-shield] | ![][npm-downloads-shield] | ❌ | ❌ |--## Introduction--In Univer, in addition to using the low-level APIs, you can also use the Facade API provided by `@univerjs/facade`, which is a higher-level abstraction of the low-level APIs, making it easier to use.--You can learn how to use the Facade API by reading [this document](https://univer.ai/guides/sheet/facade/facade/).--## Usage--### Installation--```shell-# Using npm-npm install @univerjs/facade--# Using pnpm-pnpm add @univerjs/facade-```--<!-- Links -->-[npm-version-shield]: https://img.shields.io/npm/v/@univerjs/facade?style=flat-square-[npm-version-link]: https://npmjs.com/package/@univerjs/facade-[npm-license-shield]: https://img.shields.io/npm/l/@univerjs/facade?style=flat-square-[npm-downloads-shield]: https://img.shields.io/npm/dm/@univerjs/facade?style=flat-squarediff --git a/packages/facade/package.json b/packages/facade/package.jsondeleted file mode 100644index 10cb1eafb5..0000000000--- a/packages/facade/package.json+++ /dev/null@@ -1,96 +0,0 @@-{- "name": "@univerjs/facade",- "version": "0.6.4",- "private": true,- "description": "",- "author": "DreamNum <[email protected]>",- "license": "Apache-2.0",- "funding": {- "type": "opencollective",- "url": "https://opencollective.com/univer"- },- "homepage": "https://univer.ai",- "repository": {- "type": "git",- "url": "https://github.com/dream-num/univer"- },- "bugs": {- "url": "https://github.com/dream-num/univer/issues"- },- "keywords": [- "univer"- ],- "exports": {- ".": "./src/index.ts",- "./*": "./src/*"- },- "main": "./src/index.ts",- "types": "./lib/types/index.d.ts",- "publishConfig": {- "access": "public",- "main": "./lib/es/index.js",- "module": "./lib/es/index.js",- "exports": {- ".": {- "import": "./lib/es/index.js",- "require": "./lib/cjs/index.js",- "types": "./lib/types/index.d.ts"- },- "./*": {- "import": "./lib/es/*",- "require": "./lib/cjs/*",- "types": "./lib/types/index.d.ts"- },- "./lib/*": "./lib/*"- }- },- "directories": {- "lib": "lib"- },- "files": [- "lib"- ],- "scripts": {- "test": "vitest run",- "test:watch": "vitest",- "coverage": "vitest run --coverage",- "lint:types": "tsc --noEmit",- "build": "univer-cli build"- },- "peerDependencies": {- "rxjs": ">=7.0.0"- },- "dependencies": {- "@univerjs/core": "workspace:*",- "@univerjs/docs-ui": "workspace:*",- "@univerjs/engine-formula": "workspace:*",- "@univerjs/network": "workspace:*",- "@univerjs/sheets": "workspace:*",- "@univerjs/sheets-conditional-formatting": "workspace:*",- "@univerjs/sheets-data-validation": "workspace:*",- "@univerjs/sheets-filter": "workspace:*",- "@univerjs/sheets-formula": "workspace:*",- "@univerjs/sheets-hyper-link": "workspace:*",- "@univerjs/sheets-hyper-link-ui": "workspace:*",- "@univerjs/sheets-numfmt": "workspace:*",- "@univerjs/sheets-thread-comment": "workspace:*",- "@univerjs/sheets-ui": "workspace:*",- "@univerjs/sheets-zen-editor": "workspace:*",- "@univerjs/ui": "workspace:*"- },- "devDependencies": {- "@univerjs-infra/shared": "workspace:*",- "@univerjs/data-validation": "workspace:*",- "@univerjs/docs": "workspace:*",- "@univerjs/engine-render": "workspace:*",- "@univerjs/sheets-conditional-formatting": "workspace:*",- "@univerjs/sheets-formula-ui": "workspace:*",- "@univerjs/thread-comment": "workspace:*",- "jest-canvas-mock": "^2.5.2",- "jsdom": "^24.1.1",- "rxjs": "^7.8.1",- "typescript": "^5.8.2",- "vite": "^6.2.1",- "vitest": "^3.0.8"- }-}diff --git a/packages/facade/src/apis/__tests__/f-hooks.spec.ts b/packages/facade/src/apis/__tests__/f-hooks.spec.tsdeleted file mode 100644index 5c173aae58..0000000000--- a/packages/facade/src/apis/__tests__/f-hooks.spec.ts+++ /dev/null@@ -1,52 +0,0 @@-/**- * Copyright 2023-present DreamNum Co., Ltd.- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--import type { Injector } from '@univerjs/core';-import type { FUniver } from '../everything';-import { LifecycleService, LifecycleStages } from '@univerjs/core';-import { beforeEach, describe, expect, it, vi } from 'vitest';--import { createFacadeTestBed } from './create-test-bed';--describe('Test FUniver', () => {- let get: Injector['get'];- let univerAPI: FUniver;-- beforeEach(() => {- const testBed = createFacadeTestBed();- get = testBed.get;- univerAPI = testBed.univerAPI;- });-- it('Hooks lifecycle stages', () => {- const lifecycleService = get(LifecycleService);-- const onRendered = vi.fn();- const onSteady = vi.fn();-- const onRenderedDisposable = univerAPI.getHooks().onRendered(onRendered);- const onSteadyDisposable = univerAPI.getHooks().onSteady(onSteady);-- lifecycleService.stage = LifecycleStages.Rendered;- lifecycleService.stage = LifecycleStages.Steady;-- expect(onRendered).toBeCalledTimes(1);- expect(onSteady).toBeCalledTimes(1);-- onRenderedDisposable.dispose();- onSteadyDisposable.dispose();- });-});diff --git a/packages/facade/src/apis/__tests__/facade.spec.ts b/packages/facade/src/apis/__tests__/facade.spec.tsdeleted file mode 100644index fba9e198da..0000000000--- a/packages/facade/src/apis/__tests__/facade.spec.ts+++ /dev/null@@ -1,416 +0,0 @@-/**- * Copyright 2023-present DreamNum Co., Ltd.- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--import type { ICellData, Injector, Nullable } from '@univerjs/core';-import type { FUniver } from '@univerjs/core/facade';-import type { LambdaValueObjectObject, PrimitiveValueType } from '@univerjs/engine-formula';-import type {- ColumnHeaderLayout,- RenderComponentType,- RowHeaderLayout,- SheetComponent,- SpreadsheetColumnHeader,- SpreadsheetRowHeader,-} from '@univerjs/engine-render';--import { ICommandService, IUniverInstanceService } from '@univerjs/core';-import { RegisterFunctionMutation, SetFormulaCalculationStartMutation } from '@univerjs/engine-formula';-import { IRenderManagerService } from '@univerjs/engine-render';-import { SetRangeValuesCommand, SetRangeValuesMutation, SetStyleCommand } from '@univerjs/sheets';-import { IDescriptionService } from '@univerjs/sheets-formula';-import { SHEET_VIEW_KEY } from '@univerjs/sheets-ui';-import { AddCommentCommand, AddCommentMutation, DeleteCommentCommand, DeleteCommentMutation, DeleteCommentTreeCommand, ResolveCommentMutation, UpdateCommentCommand, UpdateCommentMutation, UpdateCommentRefMutation } from '@univerjs/thread-comment';-import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';-import { createFacadeTestBed } from './create-test-bed';-import { COLUMN_UNIQUE_KEY, ColumnHeaderCustomExtension, MAIN_UNIQUE_KEY, MainCustomExtension, ROW_UNIQUE_KEY, RowHeaderCustomExtension } from './utils/sheet-extension-util';--import '../everything';--describe('Test FUniver', () => {- let get: Injector['get'];- let commandService: ICommandService;- let univerAPI: FUniver;- let getValueByPosition: (- startRow: number,- startColumn: number,- endRow: number,- endColumn: number- ) => Nullable<ICellData>;-- let getSheetRenderComponent: (unitId: string, viewKey: SHEET_VIEW_KEY) => Nullable<RenderComponentType>;-- beforeEach(() => {- const testBed = createFacadeTestBed();- get = testBed.get;- univerAPI = testBed.univerAPI;-- commandService = get(ICommandService);- commandService.registerCommand(SetRangeValuesCommand);- commandService.registerCommand(SetRangeValuesMutation);- commandService.registerCommand(RegisterFunctionMutation);- commandService.registerCommand(SetStyleCommand);- commandService.registerCommand(SetFormulaCalculationStartMutation);- [- DeleteCommentCommand,- DeleteCommentTreeCommand,- UpdateCommentCommand,- AddCommentCommand,- AddCommentMutation,- DeleteCommentMutation,- ResolveCommentMutation,- UpdateCommentMutation,- UpdateCommentRefMutation,- ].forEach((command) => commandService.registerCommand(command));-- getValueByPosition = (- startRow: number,- startColumn: number,- endRow: number,- endColumn: number- ): Nullable<ICellData> =>- get(IUniverInstanceService)- .getUniverSheetInstance('test')- ?.getSheetBySheetId('sheet1')- ?.getRange(startRow, startColumn, endRow, endColumn)- .getValue();-- getSheetRenderComponent = (unitId: string, viewKey: SHEET_VIEW_KEY): Nullable<RenderComponentType> => {- const render = get(IRenderManagerService).getRenderById(unitId);- if (!render) {- throw new Error('Render not found');- }-- const { components } = render;-- const renderComponent = components.get(viewKey);-- if (!renderComponent) {- throw new Error('Render component not found');- }-- return renderComponent;- };-- vi.useFakeTimers();- vi.spyOn(window, 'requestAnimationFrame').mockImplementation((callback) => {- return setTimeout(callback, 16);- });- });-- afterEach(() => {- (window.requestAnimationFrame as any).mockRestore();- vi.useRealTimers();- });-- it('Function onBeforeCommandExecute', () => {- const callback = vi.fn();- univerAPI.onBeforeCommandExecute(callback);-- univerAPI.executeCommand(SetRangeValuesCommand.id, {- subUnitId: 'sheet1',- unitId: 'test',- range: {- startRow: 1,- startColumn: 1,- endRow: 2,- endColumn: 2,- },-- value: [- [{ v: 1 }, { v: 2 }],- [{ v: 3 }, { v: 4 }],- ],- });-- expect(callback).toHaveBeenCalled();- });-- it('Function executeCommand', () => {- univerAPI.executeCommand(SetRangeValuesCommand.id, {- subUnitId: 'sheet1',- unitId: 'test',- range: {- startRow: 1,- startColumn: 1,- endRow: 2,- endColumn: 2,- },-- value: [- [{ v: 1 }, { v: 2 }],- [{ v: 3 }, { v: 4 }],- ],- });-- expect(getValueByPosition(1, 1, 1, 1)).toStrictEqual({- v: 1,- t: 2,- });- expect(getValueByPosition(1, 2, 1, 2)).toStrictEqual({- v: 2,- t: 2,- });- expect(getValueByPosition(2, 1, 2, 1)).toStrictEqual({- v: 3,- t: 2,- });- expect(getValueByPosition(2, 2, 2, 2)).toStrictEqual({- v: 4,- t: 2,- });- });-- it('Function createSocket', () => {- expect(() => univerAPI.createSocket('URL')).toThrowError();- });-- it('Function registerFunction', () => {- const funcionName = 'CUSTOMSUM';-- const functionsDisposable = univerAPI.registerFunction({- calculate: [- [function (...variants) {- let sum = 0;-- const last = variants[variants.length - 1] as LambdaValueObjectObject;-- if (last.isLambda()) {- variants.pop();-- const variantsList = variants.map((variant) => Array.isArray(variant) ? variant[0][0] : variant) as PrimitiveValueType[];-- sum += +last.executeCustom(...variantsList).getValue();- }-- for (const variant of variants) {- sum += Number(variant) || 0;- }-- return sum;- }, funcionName, 'Custom sum function'],- ],- });-- const descriptionService = get(IDescriptionService);-- const functionInfo = descriptionService.getFunctionInfo(funcionName);-- expect(functionInfo?.functionName).toBe(funcionName);-- functionsDisposable.dispose();-- const functionInfoAfterDispose = descriptionService.getFunctionInfo(funcionName);-- expect(functionInfoAfterDispose).toBeUndefined();- });-- it('Function registerSheetRowHeaderExtension and unregisterSheetRowHeaderExtension', () => {- const rowHeader = univerAPI.registerSheetRowHeaderExtension('test', new RowHeaderCustomExtension());-- const sheetComponent = getSheetRenderComponent('test', SHEET_VIEW_KEY.ROW) as SheetComponent;-- let rowHeaderExtension = sheetComponent.getExtensionByKey(ROW_UNIQUE_KEY);-- expect(rowHeaderExtension).toBeDefined();-- rowHeader.dispose();-- rowHeaderExtension = sheetComponent.getExtensionByKey(ROW_UNIQUE_KEY);-- expect(rowHeaderExtension).toBeUndefined();- });-- it('Function registerSheetColumnHeaderExtension and unregisterSheetColumnHeaderExtension', () => {- const columnHeader = univerAPI.registerSheetColumnHeaderExtension('test', new ColumnHeaderCustomExtension());-- const sheetComponent = getSheetRenderComponent('test', SHEET_VIEW_KEY.COLUMN) as SheetComponent;-- let columnHeaderExtension = sheetComponent.getExtensionByKey(COLUMN_UNIQUE_KEY);-- expect(columnHeaderExtension).toBeDefined();-- columnHeader.dispose();-- columnHeaderExtension = sheetComponent.getExtensionByKey(COLUMN_UNIQUE_KEY);-- expect(columnHeaderExtension).toBeUndefined();- });-- it('Function registerSheetMainExtension and unregisterSheetMainExtension', () => {- const main = univerAPI.registerSheetMainExtension('test', new MainCustomExtension());-- const sheetComponent = getSheetRenderComponent('test', SHEET_VIEW_KEY.MAIN) as SheetComponent;-- let mainExtension = sheetComponent.getExtensionByKey(MAIN_UNIQUE_KEY);-- expect(mainExtension).toBeDefined();-- main.dispose();-- mainExtension = sheetComponent.getExtensionByKey(MAIN_UNIQUE_KEY);-- expect(mainExtension).toBeUndefined();- });-- it('Function getSheetBySheetId', () => {- const worksheet = univerAPI.getActiveWorkbook()?.getSheetBySheetId('sheet1');- expect(worksheet!.getSheetId()).toBe('sheet1');- });-- it('Function getMaxColumns', () => {- const worksheet = univerAPI.getActiveWorkbook()?.getSheetBySheetId('sheet1');- expect(worksheet!.getMaxColumns()).toBe(100);- });-- it('Function getMaxRows', () => {- const worksheet = univerAPI.getActiveWorkbook()?.getSheetBySheetId('sheet1');- expect(worksheet!.getMaxRows()).toBe(100);- });-- it('Function getSnapshot', () => {- const snapshot = univerAPI.getActiveWorkbook()?.save();- expect(snapshot?.resources).toEqual([- {- data: '{}',- name: 'SHEET_WORKSHEET_PROTECTION_PLUGIN',- },- {- data: '{}',- name: 'SHEET_WORKSHEET_PROTECTION_POINT_PLUGIN',- },- {- name: 'SHEET_CONDITIONAL_FORMATTING_PLUGIN',- data: '{"sheet1":[{"cfId":"AEGZdW8C","ranges":[{"startRow":2,"startColumn":1,"endRow":5,"endColumn":5,"startAbsoluteRefType":0,"endAbsoluteRefType":0,"rangeType":0}],"rule":{"type":"highlightCell","subType":"text","operator":"containsText","style":{"cl":{"rgb":"#2f56ef"},"bg":{"rgb":"#e8ecfc"}},"value":""},"stopIfTrue":false},{"cfId":"4ICEXdJj","ranges":[{"startRow":4,"startColumn":1,"endRow":7,"endColumn":7,"startAbsoluteRefType":0,"endAbsoluteRefType":0,"rangeType":0}],"rule":{"type":"highlightCell","subType":"text","operator":"containsText","style":{"cl":{"rgb":"#2f56ef"},"bg":{"rgb":"#e8ecfc"}},"value":""},"stopIfTrue":false},{"cfId":"geCv018z","ranges":[{"startRow":11,"startColumn":1,"endRow":12,"endColumn":5,"startAbsoluteRefType":0,"endAbsoluteRefType":0,"rangeType":0}],"rule":{"type":"highlightCell","subType":"text","operator":"containsText","style":{"cl":{"rgb":"#2f56ef"},"bg":{"rgb":"#e8ecfc"}},"value":""},"stopIfTrue":false}]}',- },- {- data: '{}',- name: 'SHEET_FILTER_PLUGIN',- },- {- data: '{}',- name: 'SHEET_DATA_VALIDATION_PLUGIN',- },- ]);- });-- it('Function customizeColumnHeader', () => {- const unitId = univerAPI.getActiveWorkbook()?.getId() || '';- const columnRenderComp = getSheetRenderComponent(unitId, SHEET_VIEW_KEY.COLUMN) as SpreadsheetColumnHeader;- if (!columnRenderComp) return;- const columnHeaderExt = columnRenderComp.extensions.get('DefaultColumnHeaderLayoutExtension')! as ColumnHeaderLayout;-- const spy = vi.spyOn(columnHeaderExt, 'draw');-- univerAPI.customizeColumnHeader({ headerStyle: { backgroundColor: 'pink', fontSize: 9 }, columnsCfg: ['ASC', 'MokaII', undefined, { text: 'Size', textAlign: 'left' }, { text: 'MUJI', fontSize: 15, textAlign: 'right' }, { text: 'SRI-RESOLVE', fontSize: 10, textAlign: 'left', fontColor: 'blue', backgroundColor: 'wheat' }, null, null, 'ss', { fontSize: 29, fontColor: 'red', text: 'hash' }] });- univerAPI.customizeColumnHeader({ headerStyle: { backgroundColor: 'pink', fontSize: 9 }, columnsCfg: ['ASC', 'MokaII', undefined, { text: 'Size', textAlign: 'left' }, { text: 'MUJI', fontSize: 15, textAlign: 'right' }, { text: 'SRI-RESOLVE', fontSize: 10, textAlign: 'left', fontColor: 'blue', backgroundColor: 'wheat' }, null, null, 'ss', { fontSize: 29, fontColor: 'red', text: 'hash' }] });- expect(columnHeaderExt.headerStyle.backgroundColor).toBe('pink');- expect(columnHeaderExt.headerStyle.fontSize).toBe(9);- expect(columnHeaderExt.headerStyle.borderColor).toBe('rgb(217,217,217)');- expect(columnHeaderExt.columnsCfg.length).toBe(10);-- vi.advanceTimersByTime(16); // mock time pass by- expect(spy).toHaveBeenCalled();- });-- it('Function customizeRowHeader', () => {- const unitId = univerAPI.getActiveWorkbook()?.getId() || '';- const rowRenderComp = getSheetRenderComponent(unitId, SHEET_VIEW_KEY.ROW) as SpreadsheetRowHeader;- if (!rowRenderComp) return;- const rowHeaderExt = rowRenderComp.extensions.get('DefaultRowHeaderLayoutExtension')! as RowHeaderLayout;-- const spy = vi.spyOn(rowHeaderExt, 'draw');-- univerAPI.customizeRowHeader({ headerStyle: { backgroundColor: 'pink', fontSize: 9 }, rowsCfg: ['ASC', 'MokaII', undefined, { text: 'Size', textAlign: 'left' }, { text: 'MUJI', fontSize: 15, textAlign: 'right' }, { text: 'SRI-RESOLVE', fontSize: 10, textAlign: 'left', fontColor: 'blue', backgroundColor: 'wheat' }, null, null, 'ss', { fontSize: 29, fontColor: 'red', text: 'hash' }] });- univerAPI.customizeRowHeader({ headerStyle: { backgroundColor: 'pink', fontSize: 9 }, rowsCfg: ['ASC', 'MokaII', undefined, { text: 'Size', textAlign: 'left' }, { text: 'MUJI', fontSize: 15, textAlign: 'right' }, { text: 'SRI-RESOLVE', fontSize: 10, textAlign: 'left', fontColor: 'blue', backgroundColor: 'wheat' }, null, null, 'ss', { fontSize: 29, fontColor: 'red', text: 'hash' }] });- expect(rowHeaderExt.headerStyle.backgroundColor).toBe('pink');- expect(rowHeaderExt.headerStyle.fontSize).toBe(9);- expect(rowHeaderExt.headerStyle.borderColor).toBe('rgb(217,217,217)');- expect(rowHeaderExt.rowsCfg.length).toBe(10);-- vi.advanceTimersByTime(16); // mock time pass by- expect(spy).toHaveBeenCalled();- });-- it('Add Comment', async () => {- const worksheet = univerAPI.getActiveWorkbook()?.getActiveSheet();- if (!worksheet) {- return;- }-- const range = worksheet.getRange(1, 1, 1, 1);- await range.addComment({- dataStream: 'test\r\n',- });-- const comment = range.getComment()!;- expect(comment).toBeTruthy();- expect(comment.getContent().dataStream).toBe('test\r\n');- expect(worksheet.getComments().length).toBe(1);-- await range.addComment({- dataStream: 'reply\r\n',- });- const newComment = range.getComment()!;- expect(newComment).toBeTruthy();- expect(newComment.getContent().dataStream).toBe('test\r\n');- expect(newComment.getReplies()?.length).toBe(1);-- await newComment.update({- dataStream: 'test updated\r\n',- });- // expect(worksheet.getComments()).toBe([]);- expect(newComment.getContent().dataStream).toBe('test updated\r\n');- expect(range.getComment()?.getContent().dataStream).toBe('test updated\r\n');-- await newComment.delete();- expect(worksheet.getComments().length).toBe(0);- expect(range.getComment()).toBeNull();- });-- it('Function registerFunction should handle function', () => {- const functionName = 'CUSTOMFUNC';- const functionsDisposable = univerAPI.getFormula().registerFunction(functionName, () => {- return 42;- }, 'Custom function');-- const descriptionService = get(IDescriptionService);- const functionInfo = descriptionService.getFunctionInfo(functionName);-- expect(functionInfo?.functionName).toBe(functionName);-- functionsDisposable.dispose();-- const functionInfoAfterDispose = descriptionService.getFunctionInfo(functionName);- expect(functionInfoAfterDispose).toBeUndefined();- });-- it('Function registerFunction should handle async array function', () => {- const functionName = 'ASYNCARRAY';- const functionsDisposable = univerAPI.getFormula().registerAsyncFunction(functionName, async () => {- return [[1, 2], [3, 4]];- }, 'Async array function');-- const descriptionService = get(IDescriptionService);- const functionInfo = descriptionService.getFunctionInfo(functionName);-- expect(functionInfo?.functionName).toBe(functionName);-- functionsDisposable.dispose();-- const functionInfoAfterDispose = descriptionService.getFunctionInfo(functionName);- expect(functionInfoAfterDispose).toBeUndefined();- });-});diff --git a/packages/facade/src/apis/__tests__/utils/sheet-extension-util.ts b/packages/facade/src/apis/__tests__/utils/sheet-extension-util.tsdeleted file mode 100644index 1bb02a9673..0000000000--- a/packages/facade/src/apis/__tests__/utils/sheet-extension-util.ts+++ /dev/null@@ -1,64 +0,0 @@-/**- * Copyright 2023-present DreamNum Co., Ltd.- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--import type { IScale } from '@univerjs/core';-import type { SpreadsheetSkeleton, UniverRenderingContext } from '@univerjs/engine-render';-import { SheetExtension } from '@univerjs/engine-render';--export const COLUMN_UNIQUE_KEY = 'ColumnHeaderCustomExtension';--export class ColumnHeaderCustomExtension extends SheetExtension {- override uKey = COLUMN_UNIQUE_KEY;-- // Must be greater than 10- override get zIndex() {- return 11;- }-- override draw(ctx: UniverRenderingContext, parentScale: IScale, spreadsheetSkeleton: SpreadsheetSkeleton) {- // empty- }-}--export const ROW_UNIQUE_KEY = 'RowHeaderCustomExtension';--export class RowHeaderCustomExtension extends SheetExtension {- override uKey = ROW_UNIQUE_KEY;-- // Must be greater than 10- override get zIndex() {- return 11;- }-- override draw(ctx: UniverRenderingContext, parentScale: IScale, spreadsheetSkeleton: SpreadsheetSkeleton) {- // empty- }-}--export const MAIN_UNIQUE_KEY = 'MainCustomExtension';--export class MainCustomExtension extends SheetExtension {- override uKey = MAIN_UNIQUE_KEY;-- // Must be greater than 50- override get zIndex() {- return 51;- }-- override draw(ctx: UniverRenderingContext, parentScale: IScale, spreadsheetSkeleton: SpreadsheetSkeleton) {- // empty- }-}diff --git a/packages/facade/src/apis/everything.ts b/packages/facade/src/apis/everything.tsdeleted file mode 100644index 7d807986fd..0000000000--- a/packages/facade/src/apis/everything.ts+++ /dev/null@@ -1,40 +0,0 @@-/**- * Copyright 2023-present DreamNum Co., Ltd.- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--import '@univerjs/sheets/facade';-import '@univerjs/ui/facade';-import '@univerjs/docs-ui/facade';-import '@univerjs/sheets-ui/facade';-import '@univerjs/sheets-zen-editor/facade';-import '@univerjs/sheets-data-validation/facade';-import '@univerjs/engine-formula/facade';-import '@univerjs/sheets-filter/facade';-import '@univerjs/sheets-formula/facade';-import '@univerjs/sheets-numfmt/facade';-import '@univerjs/sheets-hyper-link/facade';-import '@univerjs/sheets-hyper-link-ui/facade';-import '@univerjs/sheets-thread-comment/facade';-import '@univerjs/sheets-conditional-formatting/facade';--export { FHooks, FUniver } from '@univerjs/core/facade';--export { FFormula } from '@univerjs/engine-formula/facade';-export { FConditionalFormattingBuilder } from '@univerjs/sheets-conditional-formatting/facade';-export { FDataValidation, FDataValidationBuilder } from '@univerjs/sheets-data-validation/facade';-export { FFilter } from '@univerjs/sheets-filter/facade';-export { FThreadComment } from '@univerjs/sheets-thread-comment/facade';-export { FSheetHooks } from '@univerjs/sheets/facade';-export { FPermission, FRange, FSelection, FWorkbook, FWorksheet } from '@univerjs/sheets/facade';diff --git a/packages/facade/src/apis/facade.ts b/packages/facade/src/apis/facade.tsdeleted file mode 100644index 0cc366302b..0000000000--- a/packages/facade/src/apis/facade.ts+++ /dev/null@@ -1,91 +0,0 @@-/**- * Copyright 2023-present DreamNum Co., Ltd.- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--import type {- Dependency,- Injector,-} from '@univerjs/core';-import type { ISocket } from '@univerjs/network';-import {- Quantity,- Univer,-} from '@univerjs/core';-import { FUniver } from '@univerjs/core/facade';-import { ISocketService, WebSocketService } from '@univerjs/network';--interface IFUniverLegacy {- /**- * Set WebSocket URL for WebSocketService- *- * @param {string} url WebSocket URL- * @returns {ISocket} WebSocket instance- */- createSocket(url: string): ISocket;-}--class FUniverLegacy extends FUniver implements IFUniverLegacy {- /**- * Get dependencies for FUniver, you can override newAPI to add more dependencies.- *- * @static- * @protected- *- * @param {Injector} injector - The injector instance used to retrieve dependencies.- * @param {Dependency[]} [derivedDependencies] - Optional array of pre-derived dependencies.- * @returns {Dependency[]} - An array of dependencies required by the service.- */- protected static getDependencies(injector: Injector, derivedDependencies?: []): Dependency[] {- const dependencies: Dependency[] = derivedDependencies || [];- // Is unified registration required?- const socketService = injector.get(ISocketService, Quantity.OPTIONAL);- if (!socketService) {- dependencies.push([ISocketService, { useClass: WebSocketService }]);- }- return dependencies;- }-- /**- * Create an FUniver instance, if the injector is not provided, it will create a new Univer instance.- *- * @static- *- * @param {Univer | Injector} wrapped - The Univer instance or injector instance.- * @returns {FUniver} - The FUniver instance.- */- static override newAPI(wrapped: Univer | Injector): FUniver {- const injector = wrapped instanceof Univer ? wrapped.__getInjector() : wrapped;- const dependencies = FUniverLegacy.getDependencies(injector);- dependencies.forEach((dependency) => injector.add(dependency));- return injector.createInstance(FUniver);- }-- override createSocket(url: string): ISocket {- const wsService = this._injector.get(ISocketService);- const ws = wsService.createSocket(url);-- if (!ws) {- throw new Error('[WebSocketService]: failed to create socket!');- }-- return ws;- }-}--FUniver.extend(FUniverLegacy);-declare module '@univerjs/core/facade' {- // eslint-disable-next-line ts/naming-convention- interface FUniver extends IFUniverLegacy {}-}diff --git a/packages/facade/src/apis/hooks/__tests__/f-clipboard-hooks.spec.ts b/packages/facade/src/apis/hooks/__tests__/f-clipboard-hooks.spec.tsdeleted file mode 100644index 7b95ce2d31..0000000000--- a/packages/facade/src/apis/hooks/__tests__/f-clipboard-hooks.spec.ts+++ /dev/null@@ -1,85 +0,0 @@-/**- * Copyright 2023-present DreamNum Co., Ltd.- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--import type { Injector } from '@univerjs/core';-import type { FWorkbook, FWorksheet } from '@univerjs/sheets/facade';-import { ICommandService, IUniverInstanceService, Univer, UniverInstanceType } from '@univerjs/core';-import { UniverRenderEnginePlugin } from '@univerjs/engine-render';-import { UniverSheetsPlugin } from '@univerjs/sheets';-import { CopyCommand, PasteCommand } from '@univerjs/ui';-import { beforeEach, describe, expect, it, vi } from 'vitest';-import { FUniver } from '../../everything';--function createUnitTestBed(): {- univer: Univer;- get: Injector['get'];- univerAPI: FUniver;- injector: Injector;-} {- const univer = new Univer();- const injector = univer.__getInjector();- univer.registerPlugin(UniverSheetsPlugin);- univer.registerPlugin(UniverRenderEnginePlugin);-- const commandService = injector.get(ICommandService);- commandService.registerCommand(PasteCommand);- commandService.registerCommand(CopyCommand);-- const sheet = univer.createUnit(UniverInstanceType.UNIVER_SHEET, {});- const univerInstanceService = injector.get(IUniverInstanceService);- univerInstanceService.focusUnit(sheet.getUnitId());- const univerAPI = FUniver.newAPI(univer);-- return {- univer,- get: injector.get.bind(injector),- univerAPI,- injector,- };-}--describe('Test Clipboard Hooks', () => {- let univerAPI: FUniver;-- beforeEach(() => {- const testBed = createUnitTestBed();- univerAPI = testBed.univerAPI;- });-- it('clipboard normal case', async () => {- const workbook = univerAPI.getActiveWorkbook() as FWorkbook;- const sheet = workbook.getActiveSheet() as FWorksheet;- expect(sheet).not.toBeUndefined();-- const beforeCopyFn = vi.fn();- const afterCopyFn = vi.fn();- const beforePasteFn = vi.fn();- const afterPasteFn = vi.fn();-- univerAPI.getHooks().onBeforeCopy(beforeCopyFn);- univerAPI.getHooks().onCopy(afterCopyFn);- univerAPI.getHooks().onBeforePaste(beforePasteFn);- univerAPI.getHooks().onPaste(afterPasteFn);-- await univerAPI.copy();- await univerAPI.paste();-- expect(beforeCopyFn).toHaveBeenCalledTimes(1);- expect(afterCopyFn).toHaveBeenCalledTimes(1);- expect(beforePasteFn).toHaveBeenCalledTimes(1);- expect(afterPasteFn).toHaveBeenCalledTimes(1);- });-});diff --git a/packages/facade/src/apis/hooks/__tests__/f-undoredo-hooks.spec.ts b/packages/facade/src/apis/hooks/__tests__/f-undoredo-hooks.spec.tsdeleted file mode 100644index b418442fa2..0000000000--- a/packages/facade/src/apis/hooks/__tests__/f-undoredo-hooks.spec.ts+++ /dev/null@@ -1,111 +0,0 @@-/**- * Copyright 2023-present DreamNum Co., Ltd.- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--import type { Injector } from '@univerjs/core';-import type { FWorksheet } from '@univerjs/sheets/facade';-import { IUndoRedoService, IUniverInstanceService, Univer, UniverInstanceType } from '@univerjs/core';-import { UniverRenderEnginePlugin } from '@univerjs/engine-render';-import { UniverSheetsPlugin } from '@univerjs/sheets';-import { beforeEach, describe, expect, it, vi } from 'vitest';-import { FUniver } from '../../everything';--function createUnitTestBed(): {- univer: Univer;- get: Injector['get'];- univerAPI: FUniver;- injector: Injector;-} {- const univer = new Univer();- const injector = univer.__getInjector();- univer.registerPlugin(UniverSheetsPlugin);- univer.registerPlugin(UniverRenderEnginePlugin);-- const sheet = univer.createUnit(UniverInstanceType.UNIVER_SHEET, {});- const univerInstanceService = injector.get(IUniverInstanceService);- univerInstanceService.focusUnit(sheet.getUnitId());- const univerAPI = FUniver.newAPI(univer);-- return {- univer,- get: injector.get.bind(injector),- univerAPI,- injector,- };-}--describe('Test Undo Redo Hooks', () => {- let get: Injector['get'];- let univerAPI: FUniver;-- beforeEach(() => {- const testBed = createUnitTestBed();- get = testBed.get;- univerAPI = testBed.univerAPI;- });-- it('undoredo normal case', async () => {- const sheet = univerAPI.getActiveWorkbook()?.getActiveSheet() as FWorksheet;- expect(sheet).not.toBeUndefined();- const range = sheet.getRange(0, 0);- const emptyFlag = '';- const text = 'Hello World';- await range.setValue(emptyFlag);- await range.setValue(text);- univerAPI.getHooks().onBeforeUndo(() => {- expect(range.getValue()).toBe(text);- });- univerAPI.getHooks().onUndo(() => {- expect(range.getValue()).toBe(emptyFlag);- });- univerAPI.getHooks().onBeforeRedo(() => {- expect(range.getValue()).toBe(emptyFlag);- });- univerAPI.getHooks().onRedo(() => {- expect(range.getValue()).toBe(text);- });- expect(range.getValue()).toBe(text);- await univerAPI.undo();- expect(range.getValue()).toBe(emptyFlag);- await univerAPI.redo();- expect(range.getValue()).toBe(text);- });-- it('undoredo edge case', async () => {- const sheet = univerAPI.getActiveWorkbook()?.getActiveSheet() as FWorksheet;- expect(sheet).not.toBeUndefined();-- // manually construct undo redo service- get(IUndoRedoService);-- const beforeUndoFn = vi.fn();- const afterUndoFn = vi.fn();- const beforeRedoFn = vi.fn();- const afterRedoFn = vi.fn();-- univerAPI.getHooks().onBeforeUndo(beforeUndoFn);- univerAPI.getHooks().onUndo(afterUndoFn);- univerAPI.getHooks().onBeforeRedo(beforeRedoFn);- univerAPI.getHooks().onRedo(afterRedoFn);-- await univerAPI.undo();- await univerAPI.redo();-- expect(beforeUndoFn).toHaveBeenCalledTimes(0);- expect(afterUndoFn).toHaveBeenCalledTimes(0);- expect(beforeRedoFn).toHaveBeenCalledTimes(0);- expect(afterRedoFn).toHaveBeenCalledTimes(0);- });-});diff --git a/packages/facade/src/vite-env.d.ts b/packages/facade/src/vite-env.d.tsdeleted file mode 100644index 11f02fe2a0..0000000000--- a/packages/facade/src/vite-env.d.ts+++ /dev/null@@ -1 +0,0 @@-/// <reference types="vite/client" />diff --git a/packages/facade/tsconfig.json b/packages/facade/tsconfig.jsondeleted file mode 100644index c62210cbad..0000000000--- a/packages/facade/tsconfig.json+++ /dev/null@@ -1,9 +0,0 @@-{- "extends": "@univerjs-infra/shared/tsconfigs/base",- "compilerOptions": {- "rootDir": "src",- "outDir": "lib/types"- },- "references": [{ "path": "./tsconfig.node.json" }],- "include": ["src"]-}diff --git a/packages/facade/tsconfig.node.json b/packages/facade/tsconfig.node.jsondeleted file mode 100644index 76bd0d5500..0000000000--- a/packages/facade/tsconfig.node.json+++ /dev/null@@ -1,4 +0,0 @@-{- "extends": "@univerjs-infra/shared/tsconfigs/node",- "include": ["vitest.config.ts", "build.ts", "jest.setup.ts"]-}diff --git a/packages/facade/vitest.config.ts b/packages/facade/vitest.config.tsdeleted file mode 100644index 0778a36a56..0000000000--- a/packages/facade/vitest.config.ts+++ /dev/null@@ -1,12 +0,0 @@-import path from 'node:path';-import createConfig from '@univerjs-infra/shared/vitest';--export default createConfig({- test: {- setupFiles: [- path.resolve(__dirname, './jest.setup.ts'),- path.resolve(__dirname, './vitest.setup.ts'),- ],- environment: 'jsdom',- },-});diff --git a/packages/network/src/facade/f-univer.ts b/packages/network/src/facade/f-univer.tsindex d2dc26ea6c..477b433709 100644--- a/packages/network/src/facade/f-univer.ts+++ b/packages/network/src/facade/f-univer.ts@@ -14,7 +14,9 @@* limitations under the License.*/+import type { ISocket } from '@univerjs/network';import { FUniver } from '@univerjs/core/facade';+import { WebSocketService } from '@univerjs/network';import { FNetwork } from './f-network';/**@@ -25,12 +27,74 @@ interface IFUniverNetworkMixin {* Get the network API of Univer, with the help of which you can send HTTP requests.*/getNetwork(): FNetwork;++ /**+ * Set WebSocket URL for WebSocketService+ *+ * @param {string} url WebSocket URL+ * @returns {ISocket} WebSocket instance+ * @example+ * ```typescript+ * // Replace the URL with the address of your own WebSocket service+ * const ws = univerAPI.createSocket('ws://47.100.177.253:8449/ws');+ *+ * ws.open$.subscribe(() => {+ * console.log('websocket opened');+ * ws.send('hello');+ * });+ *+ * ws.message$.subscribe((message) => {+ * console.log('websocket message', message);+ * const content = JSON.parse(message.data).content;+ * if (!content.includes('command')) {+ * return;+ * }+ *+ * const commandInfo = JSON.parse(content);+ * const { command, options } = commandInfo;+ * const { id, params } = command;+ *+ * // Upon receiving collaborative data, it is locally saved+ * univerAPI.executeCommand(id, params, options);+ * });+ *+ * ws.close$.subscribe(() => {+ * console.log('websocket closed');+ * });+ *+ * ws.error$.subscribe((error) => {+ * console.log('websocket error', error);+ * });+ *+ * univerAPI.onCommandExecuted((command, options) => {+ * // Only synchronize local mutations+ * if (command.type !== 2 || options?.fromCollab || options?.onlyLocal || command.id === 'doc.mutation.rich-text-editing') {+ * return;+ * }+ *+ * const commandInfo = JSON.stringify({ command, options: { fromCollab: true } });+ * ws.send(commandInfo);+ * });+ * ```+ */+ createSocket(url: string): ISocket;}export class FUniverNetworkMixin extends FUniver implements IFUniverNetworkMixin {override getNetwork(): FNetwork {return this._injector.createInstance(FNetwork);}++ override createSocket(url: string): ISocket {+ const wsService = this._injector.createInstance(WebSocketService);+ const ws = wsService.createSocket(url);++ if (!ws) {+ throw new Error('[WebSocketService]: failed to create socket!');+ }++ return ws;+ }}FUniver.extend(FUniverNetworkMixin);diff --git a/packages/facade/src/apis/__tests__/create-test-bed.ts b/packages/sheets-conditional-formatting/src/facade/__tests__/create-test-bed.tssimilarity index 52%rename from packages/facade/src/apis/__tests__/create-test-bed.tsrename to packages/sheets-conditional-formatting/src/facade/__tests__/create-test-bed.tsindex 9e96b73024..1823efc452 100644--- a/packages/facade/src/apis/__tests__/create-test-bed.ts+++ b/packages/sheets-conditional-formatting/src/facade/__tests__/create-test-bed.ts@@ -16,10 +16,8 @@/* eslint-disable max-lines-per-function */-import type { Dependency, IWorkbookData, Nullable, UnitModel } from '@univerjs/core';+import type { Dependency, IWorkbookData, UnitModel } from '@univerjs/core';import type { IRender } from '@univerjs/engine-render';-import type { ICellPosWithEvent, IHoverCellPosition, IHoverRichTextInfo, IHoverRichTextPosition } from '@univerjs/sheets-ui';-import type { IHoverHeaderPosition } from '@univerjs/sheets-ui/services/hover-manager.service.js';import {ILogService,Inject,@@ -33,39 +31,21 @@ import {Univer,UniverInstanceType,} from '@univerjs/core';-import { UniverDataValidationPlugin } from '@univerjs/data-validation';-import { ActiveDirtyManagerService, DefinedNamesService, FormulaDataModel, FunctionService, IActiveDirtyManagerService, IDefinedNamesService, IFunctionService, LexerTreeBuilder } from '@univerjs/engine-formula';+import { FUniver } from '@univerjs/core/facade';+import { ActiveDirtyManagerService, DefinedNamesService, FormulaDataModel, IActiveDirtyManagerService, IDefinedNamesService, LexerTreeBuilder } from '@univerjs/engine-formula';import { Engine, IRenderingEngine, IRenderManagerService, RenderManagerService } from '@univerjs/engine-render';-import { ISocketService, WebSocketService } from '@univerjs/network';import {- RangeProtectionRuleModel,RefRangeService,SheetInterceptorService,SheetSkeletonService,SheetsSelectionsService,- WorkbookPermissionService,- WorksheetPermissionService,- WorksheetProtectionPointModel,- WorksheetProtectionRuleModel,} from '@univerjs/sheets';import { ConditionalFormattingFormulaService, ConditionalFormattingRuleModel, ConditionalFormattingService, ConditionalFormattingViewModel } from '@univerjs/sheets-conditional-formatting';-import { DataValidationCacheService, DataValidationCustomFormulaService, DataValidationFormulaService, SheetDataValidationModel, SheetsDataValidationValidatorService } from '@univerjs/sheets-data-validation';-import { UniverSheetsFilterPlugin } from '@univerjs/sheets-filter';-import {- DescriptionService,- IDescriptionService,- IRegisterFunctionService,- RegisterFunctionService,- RegisterOtherFormulaService,-} from '@univerjs/sheets-formula';-import enUS from '@univerjs/sheets-formula-ui/locale/en-US';-import zhCN from '@univerjs/sheets-formula-ui/locale/zh-CN';-import { SheetsThreadCommentModel } from '@univerjs/sheets-thread-comment';-import { DragManagerService, HoverManagerService, ISheetSelectionRenderService, SheetRenderController, SheetScrollManagerService, SheetSelectionRenderService, SheetSkeletonManagerService, SheetsRenderService } from '@univerjs/sheets-ui';-import { IThreadCommentDataSourceService, ThreadCommentDataSourceService, ThreadCommentModel } from '@univerjs/thread-comment';-import { IPlatformService, IShortcutService, PlatformService, ShortcutService } from '@univerjs/ui';-import { Subject } from 'rxjs';-import { FUniver } from '../everything';+import enUS from '@univerjs/sheets/locale/en-US';+import zhCN from '@univerjs/sheets/locale/zh-CN';++import '@univerjs/sheets/facade';+import '@univerjs/sheets-conditional-formatting/facade';function getTestWorkbookDataDemo(): IWorkbookData {return {@@ -154,61 +134,13 @@ export function createFacadeTestBed(workbookData?: IWorkbookData, dependencies?:const injector = this._injector;injector.add([SheetsSelectionsService]);injector.add([SheetInterceptorService]);- injector.add([IRegisterFunctionService, { useClass: RegisterFunctionService }]);- injector.add([- IDescriptionService,- {- useFactory: () => this._injector.createInstance(DescriptionService),- },- ]);-- injector.add([IFunctionService, { useClass: FunctionService }]);- injector.add([ISocketService, { useClass: WebSocketService }]);injector.add([IRenderingEngine, { useFactory: () => new Engine() }]);injector.add([IRenderManagerService, { useClass: RenderManagerServiceTestBed }]);- injector.add([ISheetSelectionRenderService, { useClass: SheetSelectionRenderService }]);- injector.add([SheetsRenderService]);- injector.add([IShortcutService, { useClass: ShortcutService }]);- injector.add([IPlatformService, { useClass: PlatformService }]);injector.add([SheetSkeletonService]);- injector.add([SheetSkeletonManagerService]);injector.add([FormulaDataModel]);injector.add([LexerTreeBuilder]);injector.add([RefRangeService]);- injector.add([WorksheetPermissionService]);- injector.add([WorkbookPermissionService]);- injector.add([WorksheetProtectionPointModel]);- injector.add([RangeProtectionRuleModel]);- injector.add([WorksheetProtectionRuleModel]);injector.add([IDefinedNamesService, { useClass: DefinedNamesService }]);- // Create a mock HoverManagerService with currentCell$- const mockHoverManagerService = {- currentCell$: new Subject<Nullable<IHoverCellPosition>>().asObservable(),- currentRichText$: new Subject<Nullable<IHoverRichTextPosition>>().asObservable(),- currentClickedCell$: new Subject<IHoverRichTextInfo>().asObservable(),- currentDbClickedCell$: new Subject<IHoverRichTextInfo>().asObservable(),- currentCellPosWithEvent$: new Subject<Nullable<ICellPosWithEvent>>().asObservable(),- currentPointerDownCell$: new Subject<ICellPosWithEvent>().asObservable(),- currentPointerUpCell$: new Subject<ICellPosWithEvent>().asObservable(),- currentPosition$: new Subject<Nullable<IHoverCellPosition>>().asObservable(),- currentHoveredRowHeader$: new Subject<Nullable<IHoverHeaderPosition>>().asObservable(),- currentHoveredColHeader$: new Subject<Nullable<IHoverHeaderPosition>>().asObservable(),- currentRowHeaderClick$: new Subject<IHoverHeaderPosition>().asObservable(),- currentColHeaderClick$: new Subject<IHoverHeaderPosition>().asObservable(),- currentRowHeaderDbClick$: new Subject<IHoverHeaderPosition>().asObservable(),- currentColHeaderDbClick$: new Subject<IHoverHeaderPosition>().asObservable(),- currentRowHeaderPointerDown$: new Subject<IHoverHeaderPosition>().asObservable(),- currentColHeaderPointerDown$: new Subject<IHoverHeaderPosition>().asObservable(),- currentRowHeaderPointerUp$: new Subject<IHoverHeaderPosition>().asObservable(),- currentColHeaderPointerUp$: new Subject<IHoverHeaderPosition>().asObservable(),- };- injector.add([HoverManagerService, { useValue: mockHoverManagerService as unknown as HoverManagerService }]);- injector.add([DragManagerService, { useValue: mockHoverManagerService as unknown as DragManagerService }]);-- const renderManagerService = injector.get(IRenderManagerService);- renderManagerService.registerRenderModule(UniverInstanceType.UNIVER_SHEET, [SheetSkeletonManagerService] as Dependency);- renderManagerService.registerRenderModule(UniverInstanceType.UNIVER_SHEET, [SheetRenderController] as Dependency);- renderManagerService.registerRenderModule(UniverInstanceType.UNIVER_SHEET, [SheetScrollManagerService] as Dependency);// register feature modules([@@ -217,21 +149,7 @@ export function createFacadeTestBed(workbookData?: IWorkbookData, dependencies?:[ConditionalFormattingFormulaService],[ConditionalFormattingRuleModel],[ConditionalFormattingViewModel],-- // data validation- [DataValidationCacheService],- [DataValidationFormulaService],- [DataValidationCustomFormulaService],- [RegisterOtherFormulaService],[IActiveDirtyManagerService, { useClass: ActiveDirtyManagerService }],- [SheetsDataValidationValidatorService],- [SheetDataValidationModel],-- // sheets filter- // comment- [SheetsThreadCommentModel],- [ThreadCommentModel],- [IThreadCommentDataSourceService, { useClass: ThreadCommentDataSourceService }],] as Dependency[]).forEach((d) => {injector.add(d);});@@ -239,14 +157,12 @@ export function createFacadeTestBed(workbookData?: IWorkbookData, dependencies?:dependencies?.forEach((d) => injector.add(d));this._injector.get(SheetInterceptorService);- this._injector.get(WorkbookPermissionService);- this._injector.get(WorksheetPermissionService);this._injector.get(ConditionalFormattingService);this._injector.get(ConditionalFormattingViewModel);}override onReady(): void {- this._injector.get(SheetsRenderService);+}}@@ -260,8 +176,6 @@ export function createFacadeTestBed(workbookData?: IWorkbookData, dependencies?:// register builtin plugins// note that UI plugins are not registered here, because the unit test environment does not have a UIuniver.registerPlugin(TestPlugin);- univer.registerPlugin(UniverSheetsFilterPlugin);- univer.registerPlugin(UniverDataValidationPlugin);const sheet = univer.createUnit<IWorkbookData, UnitModel<IWorkbookData>>(UniverInstanceType.UNIVER_SHEET, workbookData || getTestWorkbookDataDemo());const univerInstanceService = injector.get(IUniverInstanceService);diff --git a/packages/facade/src/apis/sheets/__tests__/f-conditional-formatting.spec.ts b/packages/sheets-conditional-formatting/src/facade/__tests__/f-conditional-formatting.spec.tssimilarity index 98%rename from packages/facade/src/apis/sheets/__tests__/f-conditional-formatting.spec.tsrename to packages/sheets-conditional-formatting/src/facade/__tests__/f-conditional-formatting.spec.tsindex 2cf7860684..db31fb6ea6 100644--- a/packages/facade/src/apis/sheets/__tests__/f-conditional-formatting.spec.ts+++ b/packages/sheets-conditional-formatting/src/facade/__tests__/f-conditional-formatting.spec.ts@@ -31,7 +31,7 @@ import {SetConditionalRuleMutation,} from '@univerjs/sheets-conditional-formatting';import { beforeEach, describe, expect, it } from 'vitest';-import { createFacadeTestBed } from '../../__tests__/create-test-bed';+import { createFacadeTestBed } from './create-test-bed';describe('Test conditional formatting facade', () => {let get: Injector['get'];diff --git a/packages/sheets-data-validation/src/facade/__tests__/create-test-bed.ts b/packages/sheets-data-validation/src/facade/__tests__/create-test-bed.tsnew file mode 100644index 0000000000..cd3fa5cbca--- /dev/null+++ b/packages/sheets-data-validation/src/facade/__tests__/create-test-bed.ts@@ -0,0 +1,182 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { Dependency, IWorkbookData, UnitModel } from '@univerjs/core';+import {+ ILogService,+ Inject,+ Injector,+ IUniverInstanceService,+ LocaleService,+ LocaleType,+ LogLevel,+ Plugin,+ ThemeService,+ Univer,+ UniverInstanceType,+} from '@univerjs/core';+import { FUniver } from '@univerjs/core/facade';+import { UniverDataValidationPlugin } from '@univerjs/data-validation';+import { ActiveDirtyManagerService, DefinedNamesService, FormulaDataModel, IActiveDirtyManagerService, IDefinedNamesService, LexerTreeBuilder } from '@univerjs/engine-formula';+import {+ RefRangeService,+ SheetInterceptorService,+ SheetSkeletonService,+ SheetsSelectionsService,+} from '@univerjs/sheets';+import { DataValidationCacheService, DataValidationCustomFormulaService, DataValidationFormulaService, SheetDataValidationModel, SheetsDataValidationValidatorService } from '@univerjs/sheets-data-validation';+import { RegisterOtherFormulaService } from '@univerjs/sheets-formula';+import enUS from '@univerjs/sheets/locale/en-US';+import zhCN from '@univerjs/sheets/locale/zh-CN';++import '@univerjs/sheets/facade';+import '@univerjs/sheets-data-validation/facade';++function getTestWorkbookDataDemo(): IWorkbookData {+ return {+ id: 'test',+ appVersion: '3.0.0-alpha',+ sheets: {+ sheet1: {+ id: 'sheet1',+ name: 'sheet1',+ cellData: {+ 0: {+ 3: {+ f: '=SUM(A1)',+ si: '3e4r5t',+ },+ 4: {+ v: 123,+ t: 2,+ },+ },+ 1: {+ 3: {+ f: '=SUM(A2)',+ si: 'OSPtzm',+ },+ },+ 2: {+ 3: {+ si: 'OSPtzm',+ },+ },+ 3: {+ 3: {+ si: 'OSPtzm',+ },+ },+ },+ rowCount: 100,+ columnCount: 100,+ },+ },+ locale: LocaleType.ZH_CN,+ name: '',+ sheetOrder: [],+ styles: {},+ };+}++export interface ITestBed {+ univer: Univer;+ get: Injector['get'];+ sheet: UnitModel<IWorkbookData>;+ univerAPI: FUniver;+ injector: Injector;+}++export function createFacadeTestBed(workbookData?: IWorkbookData, dependencies?: Dependency[]): ITestBed {+ const univer = new Univer();+ const injector = univer.__getInjector();++ class TestPlugin extends Plugin {+ static override pluginName = 'test-plugin';+ static override type = UniverInstanceType.UNIVER_SHEET;++ constructor(+ _config: undefined,+ @Inject(Injector) override readonly _injector: Injector+ ) {+ super();+ }++ override onStarting(): void {+ const injector = this._injector;+ injector.add([SheetsSelectionsService]);+ injector.add([SheetInterceptorService]);+ injector.add([SheetSkeletonService]);+ injector.add([FormulaDataModel]);+ injector.add([LexerTreeBuilder]);+ injector.add([RefRangeService]);+ injector.add([IDefinedNamesService, { useClass: DefinedNamesService }]);++ // register feature modules+ ([+ // data validation+ [DataValidationCacheService],+ [DataValidationFormulaService],+ [DataValidationCustomFormulaService],+ [RegisterOtherFormulaService],+ [IActiveDirtyManagerService, { useClass: ActiveDirtyManagerService }],+ [SheetsDataValidationValidatorService],+ [SheetDataValidationModel],+ ] as Dependency[]).forEach((d) => {+ injector.add(d);+ });++ dependencies?.forEach((d) => injector.add(d));++ this._injector.get(SheetInterceptorService);+ }++ override onReady(): void {++ }+ }++ // load i18n+ injector.get(LocaleService).load({ zhCN, enUS });++ // load theme service+ const themeService = injector.get(ThemeService);+ themeService.setTheme({ colorBlack: '#35322b' });++ // register builtin plugins+ // note that UI plugins are not registered here, because the unit test environment does not have a UI+ univer.registerPlugin(TestPlugin);+ univer.registerPlugin(UniverDataValidationPlugin);++ const sheet = univer.createUnit<IWorkbookData, UnitModel<IWorkbookData>>(UniverInstanceType.UNIVER_SHEET, workbookData || getTestWorkbookDataDemo());+ const univerInstanceService = injector.get(IUniverInstanceService);+ univerInstanceService.focusUnit('test');++ // set log level+ const logService = injector.get(ILogService);+ logService.setLogLevel(LogLevel.SILENT); // NOTE: change this to `LogLevel.VERBOSE` to debug tests via logs++ // init data validation+ const univerAPI = FUniver.newAPI(injector);++ return {+ univer,+ get: injector.get.bind(injector),+ sheet,+ univerAPI,+ injector,+ };+}diff --git a/packages/sheets-data-validation/src/facade/__tests__/create-worksheet-test-bed.ts b/packages/sheets-data-validation/src/facade/__tests__/create-worksheet-test-bed.tsnew file mode 100644index 0000000000..a303f24689--- /dev/null+++ b/packages/sheets-data-validation/src/facade/__tests__/create-worksheet-test-bed.ts@@ -0,0 +1,174 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { Dependency, IWorkbookData, UnitModel } from '@univerjs/core';+import {+ ILogService,+ Inject,+ Injector,+ IUniverInstanceService,+ LocaleService,+ LocaleType,+ LogLevel,+ Plugin,+ ThemeService,+ Univer,+ UniverInstanceType,+} from '@univerjs/core';+import { FUniver } from '@univerjs/core/facade';+import { UniverDataValidationPlugin } from '@univerjs/data-validation';+import { ActiveDirtyManagerService, DefinedNamesService, FormulaDataModel, IActiveDirtyManagerService, IDefinedNamesService, LexerTreeBuilder } from '@univerjs/engine-formula';++import {+ RefRangeService,+ SheetInterceptorService,+ SheetSkeletonService,+ SheetsSelectionsService,+} from '@univerjs/sheets';+import { DataValidationCacheService, DataValidationCustomFormulaService, DataValidationFormulaService, SheetDataValidationModel, SheetsDataValidationValidatorService } from '@univerjs/sheets-data-validation';+import { RegisterOtherFormulaService } from '@univerjs/sheets-formula';+import enUS from '@univerjs/sheets/locale/en-US';+import zhCN from '@univerjs/sheets/locale/zh-CN';++import '@univerjs/sheets/facade';+import '@univerjs/sheets-data-validation/facade';++function getTestWorkbookDataDemo(): IWorkbookData {+ return {+ id: 'test',+ appVersion: '3.0.0-alpha',+ sheets: {+ sheet1: {+ id: 'sheet1',+ name: 'sheet1',+ cellData: {+ 0: {+ 0: {+ v: 1,+ },+ },+ 1: {+ 0: {+ v: 2,+ },+ },+ 2: {+ 0: {+ v: 3,+ },+ },+ 3: {+ 0: {+ v: 4,+ },+ },+ },+ rowCount: 100,+ columnCount: 100,+ },+ },+ locale: LocaleType.ZH_CN,+ name: '',+ sheetOrder: [],+ styles: {},+ };+}++export interface ITestBed {+ univer: Univer;+ get: Injector['get'];+ sheet: UnitModel<IWorkbookData>;+ univerAPI: FUniver;+ injector: Injector;+}++export function createWorksheetTestBed(workbookData?: IWorkbookData, dependencies?: Dependency[]): ITestBed {+ const univer = new Univer();+ const injector = univer.__getInjector();++ class TestPlugin extends Plugin {+ static override pluginName = 'test-plugin';+ static override type = UniverInstanceType.UNIVER_SHEET;++ constructor(+ _config: undefined,+ @Inject(Injector) override readonly _injector: Injector+ ) {+ super();+ }++ override onStarting(): void {+ const injector = this._injector;+ injector.add([SheetsSelectionsService]);+ injector.add([SheetInterceptorService]);+ injector.add([SheetSkeletonService]);+ injector.add([FormulaDataModel]);+ injector.add([LexerTreeBuilder]);+ injector.add([RefRangeService]);+ injector.add([IDefinedNamesService, { useClass: DefinedNamesService }]);++ // register feature modules+ ([+ // data validation+ [DataValidationCacheService],+ [DataValidationFormulaService],+ [DataValidationCustomFormulaService],+ [RegisterOtherFormulaService],+ [IActiveDirtyManagerService, { useClass: ActiveDirtyManagerService }],+ [SheetsDataValidationValidatorService],+ [SheetDataValidationModel],+ ] as Dependency[]).forEach((d) => {+ injector.add(d);+ });++ dependencies?.forEach((d) => injector.add(d));+ }++ override onReady(): void {++ }+ }++ // load i18n+ injector.get(LocaleService).load({ zhCN, enUS });++ // load theme service+ const themeService = injector.get(ThemeService);+ themeService.setTheme({ colorBlack: '#35322b' });++ // register builtin plugins+ // note that UI plugins are not registered here, because the unit test environment does not have a UI+ univer.registerPlugin(TestPlugin);+ univer.registerPlugin(UniverDataValidationPlugin);++ const sheet = univer.createUnit<IWorkbookData, UnitModel<IWorkbookData>>(UniverInstanceType.UNIVER_SHEET, workbookData || getTestWorkbookDataDemo());+ const univerInstanceService = injector.get(IUniverInstanceService);+ univerInstanceService.focusUnit('test');++ // set log level+ const logService = injector.get(ILogService);+ logService.setLogLevel(LogLevel.SILENT); // NOTE: change this to `LogLevel.VERBOSE` to debug tests via logs++ const univerAPI = FUniver.newAPI(injector);++ return {+ univer,+ get: injector.get.bind(injector),+ sheet,+ univerAPI,+ injector,+ };+}diff --git a/packages/facade/src/apis/sheets/__tests__/f-data-validation-builder.spec.ts b/packages/sheets-data-validation/src/facade/__tests__/f-data-validation-builder.spec.tssimilarity index 91%rename from packages/facade/src/apis/sheets/__tests__/f-data-validation-builder.spec.tsrename to packages/sheets-data-validation/src/facade/__tests__/f-data-validation-builder.spec.tsindex f23702185a..350b9a4f09 100644--- a/packages/facade/src/apis/sheets/__tests__/f-data-validation-builder.spec.ts+++ b/packages/sheets-data-validation/src/facade/__tests__/f-data-validation-builder.spec.ts@@ -14,32 +14,19 @@* limitations under the License.*/-import type { Injector } from '@univerjs/core';-import type { FUniver } from '../../everything';-import { DataValidationOperator, DataValidationType, ICommandService } from '@univerjs/core';-import { SetHorizontalTextAlignCommand, SetRangeValuesCommand, SetRangeValuesMutation, SetStyleCommand, SetTextWrapCommand, SetVerticalTextAlignCommand } from '@univerjs/sheets';+import type { FUniver } from '@univerjs/core/facade';+import { DataValidationOperator, DataValidationType } from '@univerjs/core';import { FDataValidationBuilder } from '@univerjs/sheets-data-validation/facade/f-data-validation-builder.js';import { beforeEach, describe, expect, it } from 'vitest';-import { createFacadeTestBed } from '../../__tests__/create-test-bed';+import { createFacadeTestBed } from './create-test-bed';describe('Test FDataValidationBuilder', () => {- let get: Injector['get'];- let commandService: ICommandService;let univerAPI: FUniver;beforeEach(() => {const testBed = createFacadeTestBed();- get = testBed.get;univerAPI = testBed.univerAPI;-- commandService = get(ICommandService);- commandService.registerCommand(SetRangeValuesCommand);- commandService.registerCommand(SetRangeValuesMutation);- commandService.registerCommand(SetStyleCommand);- commandService.registerCommand(SetVerticalTextAlignCommand);- commandService.registerCommand(SetHorizontalTextAlignCommand);- commandService.registerCommand(SetTextWrapCommand);});it('should build checkbox', () => {diff --git a/packages/sheets-data-validation/src/facade/__tests__/f-range.spec.ts b/packages/sheets-data-validation/src/facade/__tests__/f-range.spec.tsnew file mode 100644index 0000000000..9cdad0d894--- /dev/null+++ b/packages/sheets-data-validation/src/facade/__tests__/f-range.spec.ts@@ -0,0 +1,64 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++/* eslint-disable ts/no-non-null-asserted-optional-chain */++import type { Injector } from '@univerjs/core';+import type { FUniver } from '@univerjs/core/facade';+import { DataValidationType, ICommandService } from '@univerjs/core';+import { AddSheetDataValidationCommand } from '@univerjs/sheets-data-validation';+import { beforeEach, describe, expect, it } from 'vitest';+import { createFacadeTestBed } from './create-test-bed';++describe('Test FRange', () => {+ let get: Injector['get'];+ let commandService: ICommandService;+ let univerAPI: FUniver;++ beforeEach(() => {+ const testBed = createFacadeTestBed();+ get = testBed.get;++ univerAPI = testBed.univerAPI;++ commandService = get(ICommandService);+ commandService.registerCommand(AddSheetDataValidationCommand);+ });++ it('Range set data validation', async () => {+ const activeSheet = univerAPI.getActiveWorkbook()?.getActiveSheet()!;+ const range = activeSheet.getRange(0, 0, 10, 10);+ const range2 = activeSheet.getRange(11, 11, 2, 2);+ await range.setDataValidation(univerAPI.newDataValidation().requireCheckbox().build());+ await range2?.setDataValidation(univerAPI.newDataValidation().requireNumberEqualTo(1).build());+ const range3 = activeSheet.getRange(0, 0, 100, 100);++ expect(range.getDataValidation()).toBeTruthy();+ expect(range.getDataValidation()?.rule.ranges).toEqual([{+ unitId: univerAPI.getActiveWorkbook()?.getId(),+ sheetId: activeSheet.getSheetId(),+ startRow: 0,+ endRow: 9,+ startColumn: 0,+ endColumn: 9,+ }]);+ expect(range.getDataValidation()?.getCriteriaType()).toEqual(DataValidationType.CHECKBOX);+ expect(range.getDataValidations().length).toEqual(1);+ expect(range3?.getDataValidations().length).toEqual(2);++ expect(activeSheet?.getDataValidations().length).toEqual(2);+ });+});diff --git a/packages/sheets-data-validation/src/facade/__tests__/f-worksheet.spec.ts b/packages/sheets-data-validation/src/facade/__tests__/f-worksheet.spec.tsnew file mode 100644index 0000000000..4e94487a41--- /dev/null+++ b/packages/sheets-data-validation/src/facade/__tests__/f-worksheet.spec.ts@@ -0,0 +1,38 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { FUniver } from '@univerjs/core/facade';+import { beforeEach, describe, expect, it } from 'vitest';+import { createWorksheetTestBed } from './create-worksheet-test-bed';++describe('Test FWorksheet', () => {+ let univerAPI: FUniver;+ beforeEach(() => {+ const testBed = createWorksheetTestBed();++ univerAPI = testBed.univerAPI;+ });++ it('Worksheet getDataValidations', async () => {+ const activeSheet = univerAPI.getActiveWorkbook()?.getSheetByName('sheet1');+ expect(activeSheet?.getDataValidations()).toBeDefined();+ });++ it('Worksheet getValidatorStatus', async () => {+ const activeSheet = univerAPI.getActiveWorkbook()?.getSheetByName('sheet1');+ expect(activeSheet?.getValidatorStatus()).toBeDefined();+ });+});diff --git a/packages/sheets-filter/src/facade/__tests__/create-test-bed.ts b/packages/sheets-filter/src/facade/__tests__/create-test-bed.tsnew file mode 100644index 0000000000..d385e0d84d--- /dev/null+++ b/packages/sheets-filter/src/facade/__tests__/create-test-bed.ts@@ -0,0 +1,174 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { Dependency, IWorkbookData, UnitModel } from '@univerjs/core';+import {+ ILogService,+ Inject,+ Injector,+ IUniverInstanceService,+ LocaleService,+ LocaleType,+ LogLevel,+ Plugin,+ ThemeService,+ Univer,+ UniverInstanceType,+} from '@univerjs/core';+import { FUniver } from '@univerjs/core/facade';+import { ActiveDirtyManagerService, DefinedNamesService, FormulaDataModel, FunctionService, IActiveDirtyManagerService, IDefinedNamesService, IFunctionService, LexerTreeBuilder } from '@univerjs/engine-formula';+import {+ RefRangeService,+ SheetInterceptorService,+ SheetSkeletonService,+ SheetsSelectionsService,+} from '@univerjs/sheets';+import { UniverSheetsFilterPlugin } from '@univerjs/sheets-filter';+import enUS from '@univerjs/sheets/locale/en-US';+import zhCN from '@univerjs/sheets/locale/zh-CN';++import '@univerjs/sheets/facade';+import '@univerjs/sheets-filter/facade';++function getTestWorkbookDataDemo(): IWorkbookData {+ return {+ id: 'test',+ appVersion: '3.0.0-alpha',+ sheets: {+ sheet1: {+ id: 'sheet1',+ name: 'sheet1',+ cellData: {+ 0: {+ 3: {+ f: '=SUM(A1)',+ si: '3e4r5t',+ },+ 4: {+ v: 123,+ t: 2,+ },+ },+ 1: {+ 3: {+ f: '=SUM(A2)',+ si: 'OSPtzm',+ },+ },+ 2: {+ 3: {+ si: 'OSPtzm',+ },+ },+ 3: {+ 3: {+ si: 'OSPtzm',+ },+ },+ },+ rowCount: 100,+ columnCount: 100,+ },+ },+ locale: LocaleType.ZH_CN,+ name: '',+ sheetOrder: [],+ styles: {},+ };+}++export interface ITestBed {+ univer: Univer;+ get: Injector['get'];+ sheet: UnitModel<IWorkbookData>;+ univerAPI: FUniver;+ injector: Injector;+}++export function createFacadeTestBed(workbookData?: IWorkbookData, dependencies?: Dependency[]): ITestBed {+ const univer = new Univer();+ const injector = univer.__getInjector();++ class TestPlugin extends Plugin {+ static override pluginName = 'test-plugin';+ static override type = UniverInstanceType.UNIVER_SHEET;++ constructor(+ _config: undefined,+ @Inject(Injector) override readonly _injector: Injector+ ) {+ super();+ }++ override onStarting(): void {+ const injector = this._injector;+ injector.add([SheetsSelectionsService]);+ injector.add([SheetInterceptorService]);+ injector.add([IFunctionService, { useClass: FunctionService }]);+ injector.add([SheetSkeletonService]);+ injector.add([FormulaDataModel]);+ injector.add([LexerTreeBuilder]);+ injector.add([RefRangeService]);+ injector.add([IDefinedNamesService, { useClass: DefinedNamesService }]);++ // register feature modules+ ([+ [IActiveDirtyManagerService, { useClass: ActiveDirtyManagerService }],+ ] as Dependency[]).forEach((d) => {+ injector.add(d);+ });++ dependencies?.forEach((d) => injector.add(d));++ this._injector.get(SheetInterceptorService);+ }++ override onReady(): void {++ }+ }++ // load i18n+ injector.get(LocaleService).load({ zhCN, enUS });++ // load theme service+ const themeService = injector.get(ThemeService);+ themeService.setTheme({ colorBlack: '#35322b' });++ // register builtin plugins+ // note that UI plugins are not registered here, because the unit test environment does not have a UI+ univer.registerPlugin(TestPlugin);+ univer.registerPlugin(UniverSheetsFilterPlugin);++ const sheet = univer.createUnit<IWorkbookData, UnitModel<IWorkbookData>>(UniverInstanceType.UNIVER_SHEET, workbookData || getTestWorkbookDataDemo());+ const univerInstanceService = injector.get(IUniverInstanceService);+ univerInstanceService.focusUnit('test');++ // set log level+ const logService = injector.get(ILogService);+ logService.setLogLevel(LogLevel.SILENT); // NOTE: change this to `LogLevel.VERBOSE` to debug tests via logs++ // init data validation+ const univerAPI = FUniver.newAPI(injector);++ return {+ univer,+ get: injector.get.bind(injector),+ sheet,+ univerAPI,+ injector,+ };+}diff --git a/packages/sheets-filter/src/facade/__tests__/create-worksheet-test-bed.ts b/packages/sheets-filter/src/facade/__tests__/create-worksheet-test-bed.tsnew file mode 100644index 0000000000..c4ba598893--- /dev/null+++ b/packages/sheets-filter/src/facade/__tests__/create-worksheet-test-bed.ts@@ -0,0 +1,165 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { Dependency, IWorkbookData, UnitModel } from '@univerjs/core';+import {+ ILogService,+ Inject,+ Injector,+ IUniverInstanceService,+ LocaleService,+ LocaleType,+ LogLevel,+ Plugin,+ ThemeService,+ Univer,+ UniverInstanceType,+} from '@univerjs/core';+import { FUniver } from '@univerjs/core/facade';+import { ActiveDirtyManagerService, DefinedNamesService, FormulaDataModel, FunctionService, IActiveDirtyManagerService, IDefinedNamesService, IFunctionService, LexerTreeBuilder } from '@univerjs/engine-formula';+import {+ RefRangeService,+ SheetInterceptorService,+ SheetSkeletonService,+ SheetsSelectionsService,+} from '@univerjs/sheets';+import { UniverSheetsFilterPlugin } from '@univerjs/sheets-filter';+import enUS from '@univerjs/sheets/locale/en-US';+import zhCN from '@univerjs/sheets/locale/zh-CN';++import '@univerjs/sheets/facade';+import '@univerjs/sheets-filter/facade';++function getTestWorkbookDataDemo(): IWorkbookData {+ return {+ id: 'test',+ appVersion: '3.0.0-alpha',+ sheets: {+ sheet1: {+ id: 'sheet1',+ name: 'sheet1',+ cellData: {+ 0: {+ 0: {+ v: 1,+ },+ },+ 1: {+ 0: {+ v: 2,+ },+ },+ 2: {+ 0: {+ v: 3,+ },+ },+ 3: {+ 0: {+ v: 4,+ },+ },+ },+ rowCount: 100,+ columnCount: 100,+ },+ },+ locale: LocaleType.ZH_CN,+ name: '',+ sheetOrder: [],+ styles: {},+ };+}++export interface ITestBed {+ univer: Univer;+ get: Injector['get'];+ sheet: UnitModel<IWorkbookData>;+ univerAPI: FUniver;+ injector: Injector;+}++export function createWorksheetTestBed(workbookData?: IWorkbookData, dependencies?: Dependency[]): ITestBed {+ const univer = new Univer();+ const injector = univer.__getInjector();++ class TestPlugin extends Plugin {+ static override pluginName = 'test-plugin';+ static override type = UniverInstanceType.UNIVER_SHEET;++ constructor(+ _config: undefined,+ @Inject(Injector) override readonly _injector: Injector+ ) {+ super();+ }++ override onStarting(): void {+ const injector = this._injector;+ injector.add([SheetsSelectionsService]);+ injector.add([SheetInterceptorService]);+ injector.add([IFunctionService, { useClass: FunctionService }]);+ injector.add([SheetSkeletonService]);+ injector.add([FormulaDataModel]);+ injector.add([LexerTreeBuilder]);+ injector.add([RefRangeService]);+ injector.add([IDefinedNamesService, { useClass: DefinedNamesService }]);++ // register feature modules+ ([+ [IActiveDirtyManagerService, { useClass: ActiveDirtyManagerService }],+ ] as Dependency[]).forEach((d) => {+ injector.add(d);+ });++ dependencies?.forEach((d) => injector.add(d));+ }++ override onReady(): void {++ }+ }++ // load i18n+ injector.get(LocaleService).load({ zhCN, enUS });++ // load theme service+ const themeService = injector.get(ThemeService);+ themeService.setTheme({ colorBlack: '#35322b' });++ // register builtin plugins+ // note that UI plugins are not registered here, because the unit test environment does not have a UI+ univer.registerPlugin(TestPlugin);+ univer.registerPlugin(UniverSheetsFilterPlugin);++ const sheet = univer.createUnit<IWorkbookData, UnitModel<IWorkbookData>>(UniverInstanceType.UNIVER_SHEET, workbookData || getTestWorkbookDataDemo());+ const univerInstanceService = injector.get(IUniverInstanceService);+ univerInstanceService.focusUnit('test');++ // set log level+ const logService = injector.get(ILogService);+ logService.setLogLevel(LogLevel.SILENT); // NOTE: change this to `LogLevel.VERBOSE` to debug tests via logs++ const univerAPI = FUniver.newAPI(injector);++ return {+ univer,+ get: injector.get.bind(injector),+ sheet,+ univerAPI,+ injector,+ };+}diff --git a/packages/sheets-filter/src/facade/__tests__/f-range.spec.ts b/packages/sheets-filter/src/facade/__tests__/f-range.spec.tsnew file mode 100644index 0000000000..2c4c79104b--- /dev/null+++ b/packages/sheets-filter/src/facade/__tests__/f-range.spec.ts@@ -0,0 +1,82 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { Injector, IRange } from '@univerjs/core';+import type { FUniver } from '@univerjs/core/facade';+import { ICommandService } from '@univerjs/core';+import { ClearSheetsFilterCriteriaCommand, RemoveSheetFilterCommand, SetSheetFilterRangeCommand, SetSheetsFilterCriteriaCommand } from '@univerjs/sheets-filter';+import { beforeEach, describe, expect, it } from 'vitest';+import { createFacadeTestBed } from './create-test-bed';++describe('Test FRange', () => {+ let get: Injector['get'];+ let commandService: ICommandService;+ let univerAPI: FUniver;++ beforeEach(() => {+ const testBed = createFacadeTestBed();+ get = testBed.get;++ univerAPI = testBed.univerAPI;++ commandService = get(ICommandService);+ });++ describe('FFilter', () => {+ beforeEach(() => {+ commandService.registerCommand(SetSheetsFilterCriteriaCommand);+ commandService.registerCommand(ClearSheetsFilterCriteriaCommand);+ commandService.registerCommand(SetSheetFilterRangeCommand);+ commandService.registerCommand(RemoveSheetFilterCommand);+ });++ it('create, modify and clear filters with Facade API', async () => {+ const activeSheet = univerAPI.getActiveWorkbook()!.getActiveSheet();+ expect(activeSheet.getFilter()).toBeNull();+ expect(activeSheet.getRange(0, 0, 1, 1).getFilter()).toBeNull();++ const range = activeSheet.getRange(0, 0, 10, 10);+ const filter = (await range.createFilter())!;++ expect(filter).not.toBeNull();+ expect(activeSheet.getFilter()).not.toBeNull();+ expect(activeSheet.getRange(0, 0, 1, 1).getFilter()).not.toBeNull();+ expect(filter.getRange().getRange()).toStrictEqual({+ unitId: univerAPI.getActiveWorkbook()?.getId(),+ sheetId: activeSheet.getSheetId(),+ startColumn: 0,+ startRow: 0,+ endColumn: 9,+ endRow: 9,+ } as IRange);++ expect(await filter.setColumnFilterCriteria(1, { colId: 1, filters: { blank: true } })).toBeTruthy();+ expect(filter.getColumnFilterCriteria(1)).toEqual({ colId: 1, filters: { blank: true } });++ expect(await filter.setColumnFilterCriteria(2, { colId: 2, filters: { filters: ['a'] } })).toBeTruthy();+ expect(filter.getColumnFilterCriteria(2)).toEqual({ colId: 2, filters: { filters: ['a'] } });++ expect(await filter.removeColumnFilterCriteria(1)).toBeTruthy();+ expect(filter.getColumnFilterCriteria(1)).toBeFalsy();++ expect(await filter.removeFilterCriteria()).toBeTruthy();+ expect(filter.getColumnFilterCriteria(2)).toBeFalsy();++ expect(await filter.remove()).toBeTruthy();+ expect(activeSheet.getFilter()).toBeNull();+ });+ });+});diff --git a/packages/facade/src/index.ts b/packages/sheets-filter/src/facade/__tests__/f-worksheet.spec.tssimilarity index 52%rename from packages/facade/src/index.tsrename to packages/sheets-filter/src/facade/__tests__/f-worksheet.spec.tsindex 70fd8043df..10effe22d0 100644--- a/packages/facade/src/index.ts+++ b/packages/sheets-filter/src/facade/__tests__/f-worksheet.spec.ts@@ -14,10 +14,21 @@* limitations under the License.*/-import './apis/everything';-import './apis/facade';+import type { FUniver } from '@univerjs/core/facade';+import { beforeEach, describe, expect, it } from 'vitest';+import { createWorksheetTestBed } from './create-worksheet-test-bed';-export * from './apis/everything';+describe('Test FWorksheet', () => {+ let univerAPI: FUniver;-console.error(`[!DEPRECATION WARNING!] @univerjs/facade and @univerjs-pro/facade is deprecated and will be removed in v0.6.0.-Please refer to our official guide to migrate. https://univer.ai/guides/sheet/getting-started/facade`);+ beforeEach(() => {+ const testBed = createWorksheetTestBed();++ univerAPI = testBed.univerAPI;+ });++ it('Worksheet getFilter', async () => {+ const activeSheet = univerAPI.getActiveWorkbook()?.getSheetByName('sheet1');+ expect(activeSheet?.getFilter()).toBeDefined();+ });+});diff --git a/packages/facade/src/apis/sheets/__tests__/create-formula-test-bed.ts b/packages/sheets-formula-ui/src/facade/__tests__/create-formula-test-bed.tssimilarity index 97%rename from packages/facade/src/apis/sheets/__tests__/create-formula-test-bed.tsrename to packages/sheets-formula-ui/src/facade/__tests__/create-formula-test-bed.tsindex 1d1f1e9156..ce904bbd08 100644--- a/packages/facade/src/apis/sheets/__tests__/create-formula-test-bed.ts+++ b/packages/sheets-formula-ui/src/facade/__tests__/create-formula-test-bed.ts@@ -27,9 +27,9 @@ import {Univer,UniverInstanceType,} from '@univerjs/core';+import { FUniver } from '@univerjs/core/facade';import { ActiveDirtyManagerService, AstRootNodeFactory, AstTreeBuilder, CalculateController, CalculateFormulaService, DefinedNamesService, DependencyManagerService, FeatureCalculationManagerService, FormulaCurrentConfigService, FormulaDataModel, FormulaDependencyGenerator, FormulaRuntimeService, FunctionNodeFactory, FunctionService, IActiveDirtyManagerService, ICalculateFormulaService, IDefinedNamesService, IDependencyManagerService, IFeatureCalculationManagerService, IFormulaCurrentConfigService, IFormulaRuntimeService, IFunctionService, Interpreter, IOtherFormulaManagerService, ISuperTableService, LambdaNodeFactory, LambdaParameterNodeFactory, Lexer, LexerTreeBuilder, OperatorNodeFactory, OtherFormulaManagerService, PrefixNodeFactory, ReferenceNodeFactory, SuffixNodeFactory, SuperTableService, UnionNodeFactory, ValueNodeFactory } from '@univerjs/engine-formula';import { IRenderManagerService, RenderManagerService } from '@univerjs/engine-render';-import { ISocketService, WebSocketService } from '@univerjs/network';import { SheetInterceptorService, SheetsSelectionsService } from '@univerjs/sheets';import {DescriptionService,@@ -39,7 +39,10 @@ import {} from '@univerjs/sheets-formula';import enUS from '@univerjs/sheets-formula-ui/locale/en-US';import zhCN from '@univerjs/sheets-formula-ui/locale/zh-CN';-import { FUniver } from '../../everything';++import '@univerjs/engine-formula/facade';+import '@univerjs/sheets/facade';+import '@univerjs/sheets-formula/facade';function getTestWorkbookDataDemo(): IWorkbookData {return {@@ -109,7 +112,6 @@ export function createFormulaTestBed(workbookData?: IWorkbookData, dependencies?injector.add([SheetsSelectionsService]);injector.add([SheetInterceptorService]);injector.add([IRenderManagerService, { useClass: RenderManagerService }]);- injector.add([ISocketService, { useClass: WebSocketService }]);registerFormulaDependencies(injector);diff --git a/packages/facade/src/apis/sheets/__tests__/f-formula.spec.ts b/packages/sheets-formula-ui/src/facade/__tests__/f-formula.spec.tssimilarity index 59%rename from packages/facade/src/apis/sheets/__tests__/f-formula.spec.tsrename to packages/sheets-formula-ui/src/facade/__tests__/f-formula.spec.tsindex 333e91c4fc..4aa2619d71 100644--- a/packages/facade/src/apis/sheets/__tests__/f-formula.spec.ts+++ b/packages/sheets-formula-ui/src/facade/__tests__/f-formula.spec.ts@@ -14,35 +14,19 @@* limitations under the License.*/-import type { ICellData, Injector, IStyleData, Nullable } from '@univerjs/core';+import type { Injector } from '@univerjs/core';import type { FUniver } from '@univerjs/core/facade';import type { IUniverSheetsFormulaBaseConfig } from '@univerjs/sheets-formula';-import { ICommandService, IConfigService, IUniverInstanceService } from '@univerjs/core';-+import { ICommandService, IConfigService } from '@univerjs/core';import { SetArrayFormulaDataMutation, SetFormulaCalculationNotificationMutation, SetFormulaCalculationResultMutation, SetFormulaCalculationStartMutation, SetFormulaCalculationStopMutation } from '@univerjs/engine-formula';-import { SetHorizontalTextAlignCommand, SetRangeValuesCommand, SetRangeValuesMutation, SetStyleCommand, SetTextWrapCommand, SetVerticalTextAlignCommand } from '@univerjs/sheets';import { CalculationMode, PLUGIN_CONFIG_KEY_BASE } from '@univerjs/sheets-formula';import { beforeEach, describe, expect, it } from 'vitest';-import { createFormulaTestBed } from './create-formula-test-bed';-import '../../everything';describe('Test FFormula', () => {let get: Injector['get'];let commandService: ICommandService;let univerAPI: FUniver;- let getValueByPosition: (- startRow: number,- startColumn: number,- endRow: number,- endColumn: number- ) => Nullable<ICellData>;- let getStyleByPosition: (- startRow: number,- startColumn: number,- endRow: number,- endColumn: number- ) => Nullable<IStyleData>;beforeEach(() => {const testBed = createFormulaTestBed();@@ -50,42 +34,11 @@ describe('Test FFormula', () => {univerAPI = testBed.univerAPI;commandService = get(ICommandService);- commandService.registerCommand(SetRangeValuesCommand);- commandService.registerCommand(SetRangeValuesMutation);- commandService.registerCommand(SetStyleCommand);- commandService.registerCommand(SetVerticalTextAlignCommand);- commandService.registerCommand(SetHorizontalTextAlignCommand);- commandService.registerCommand(SetTextWrapCommand);commandService.registerCommand(SetFormulaCalculationStartMutation);commandService.registerCommand(SetFormulaCalculationStopMutation);commandService.registerCommand(SetFormulaCalculationNotificationMutation);commandService.registerCommand(SetFormulaCalculationResultMutation);commandService.registerCommand(SetArrayFormulaDataMutation);-- getValueByPosition = (- startRow: number,- startColumn: number,- endRow: number,- endColumn: number- ): Nullable<ICellData> =>- get(IUniverInstanceService)- .getUniverSheetInstance('test')- ?.getSheetBySheetId('sheet1')- ?.getRange(startRow, startColumn, endRow, endColumn)- .getValue();-- getStyleByPosition = (- startRow: number,- startColumn: number,- endRow: number,- endColumn: number- ): Nullable<IStyleData> => {- const value = getValueByPosition(startRow, startColumn, endRow, endColumn);- const styles = get(IUniverInstanceService).getUniverSheetInstance('test')?.getStyles();- if (value && styles) {- return styles.getStyleByCell(value);- }- };});it('FFormula executeCalculation', () => {diff --git a/packages/sheets-numfmt/src/facade/__tests__/create-test-bed.ts b/packages/sheets-numfmt/src/facade/__tests__/create-test-bed.tsnew file mode 100644index 0000000000..18055741e0--- /dev/null+++ b/packages/sheets-numfmt/src/facade/__tests__/create-test-bed.ts@@ -0,0 +1,146 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { Dependency, IWorkbookData, UnitModel } from '@univerjs/core';+import {+ ILogService,+ Inject,+ Injector,+ IUniverInstanceService,+ LocaleService,+ LocaleType,+ LogLevel,+ Plugin,+ ThemeService,+ Univer,+ UniverInstanceType,+} from '@univerjs/core';+import { FUniver } from '@univerjs/core/facade';++import enUS from '@univerjs/sheets/locale/en-US';+import zhCN from '@univerjs/sheets/locale/zh-CN';++import '@univerjs/sheets/facade';++function getTestWorkbookDataDemo(): IWorkbookData {+ return {+ id: 'test',+ appVersion: '3.0.0-alpha',+ sheets: {+ sheet1: {+ id: 'sheet1',+ name: 'sheet1',+ cellData: {+ 0: {+ 3: {+ f: '=SUM(A1)',+ si: '3e4r5t',+ },+ 4: {+ v: 123,+ t: 2,+ },+ },+ 1: {+ 3: {+ f: '=SUM(A2)',+ si: 'OSPtzm',+ },+ },+ 2: {+ 3: {+ si: 'OSPtzm',+ },+ },+ 3: {+ 3: {+ si: 'OSPtzm',+ },+ },+ },+ rowCount: 100,+ columnCount: 100,+ },+ },+ locale: LocaleType.ZH_CN,+ name: '',+ sheetOrder: [],+ styles: {},+ };+}++export interface ITestBed {+ univer: Univer;+ get: Injector['get'];+ sheet: UnitModel<IWorkbookData>;+ univerAPI: FUniver;+ injector: Injector;+}++export function createFacadeTestBed(workbookData?: IWorkbookData, dependencies?: Dependency[]): ITestBed {+ const univer = new Univer();+ const injector = univer.__getInjector();++ class TestPlugin extends Plugin {+ static override pluginName = 'test-plugin';+ static override type = UniverInstanceType.UNIVER_SHEET;++ constructor(+ _config: undefined,+ @Inject(Injector) override readonly _injector: Injector+ ) {+ super();+ }++ override onStarting(): void {+ dependencies?.forEach((d) => injector.add(d));+ }++ override onReady(): void {++ }+ }++ // load i18n+ injector.get(LocaleService).load({ zhCN, enUS });++ // load theme service+ const themeService = injector.get(ThemeService);+ themeService.setTheme({ colorBlack: '#35322b' });++ // register builtin plugins+ // note that UI plugins are not registered here, because the unit test environment does not have a UI+ univer.registerPlugin(TestPlugin);++ const sheet = univer.createUnit<IWorkbookData, UnitModel<IWorkbookData>>(UniverInstanceType.UNIVER_SHEET, workbookData || getTestWorkbookDataDemo());+ const univerInstanceService = injector.get(IUniverInstanceService);+ univerInstanceService.focusUnit('test');++ // set log level+ const logService = injector.get(ILogService);+ logService.setLogLevel(LogLevel.SILENT); // NOTE: change this to `LogLevel.VERBOSE` to debug tests via logs++ // init data validation+ const univerAPI = FUniver.newAPI(injector);++ return {+ univer,+ get: injector.get.bind(injector),+ sheet,+ univerAPI,+ injector,+ };+}diff --git a/packages/sheets-numfmt/src/facade/__tests__/f-range.spec.ts b/packages/sheets-numfmt/src/facade/__tests__/f-range.spec.tsnew file mode 100644index 0000000000..0ece47a926--- /dev/null+++ b/packages/sheets-numfmt/src/facade/__tests__/f-range.spec.ts@@ -0,0 +1,42 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { FUniver } from '@univerjs/core/facade';+import { LifecycleStages } from '@univerjs/core';+import { beforeEach, describe, expect, it } from 'vitest';+import { createFacadeTestBed } from './create-test-bed';++describe('Test FRange', () => {+ let univerAPI: FUniver;++ beforeEach(() => {+ const testBed = createFacadeTestBed();++ univerAPI = testBed.univerAPI;+ });++ it('Range setNumberFormat', () => {+ univerAPI.addEvent(univerAPI.Event.LifeCycleChanged, ({ stage }) => {+ if (stage === LifecycleStages.Rendered) {+ const activeSheet = univerAPI.getActiveWorkbook()!.getActiveSheet();+ const range = activeSheet.getRange(0, 0, 1, 1);+ range.setValue(1234.5678);+ range.setNumberFormat('#,###');+ expect(range.getValue()).toBe('1,234.5678');+ }+ });+ });+});diff --git a/packages/sheets-ui/src/facade/__tests__/f-range.spec.ts b/packages/sheets-ui/src/facade/__tests__/f-range.spec.tsnew file mode 100644index 0000000000..52a2ddc0e3--- /dev/null+++ b/packages/sheets-ui/src/facade/__tests__/f-range.spec.ts@@ -0,0 +1,62 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++/* eslint-disable ts/no-non-null-asserted-optional-chain */++import type { FUniver } from '@univerjs/core/facade';+import { LifecycleStages } from '@univerjs/core';+import { beforeEach, describe, expect, it } from 'vitest';+import { createFacadeTestBed } from './create-test-bed';++import '@univerjs/sheets/facade';++describe('Test FRange', () => {+ let univerAPI: FUniver;++ beforeEach(() => {+ const testBed = createFacadeTestBed();++ univerAPI = testBed.univerAPI;+ });++ it('Range getCell', () => {+ univerAPI.addEvent(univerAPI.Event.LifeCycleChanged, ({ stage }) => {+ if (stage === LifecycleStages.Steady) {+ const activeSheet = univerAPI.getActiveWorkbook()!.getActiveSheet();+ const range = activeSheet?.getRange(2, 3);+ const cell = range?.getCell()!;+ expect(cell.actualColumn).toBe(3);+ expect(cell.actualRow).toBe(2);+ }+ });+ });++ it('Range getCellRect', () => {+ univerAPI.addEvent(univerAPI.Event.LifeCycleChanged, ({ stage }) => {+ if (stage === LifecycleStages.Steady) {+ const activeSheet = univerAPI.getActiveWorkbook()!.getActiveSheet();+ const range = activeSheet?.getRange(0, 0);+ const cell = range?.getCell()!;+ const rect = range?.getCellRect()!;+ expect(rect.x).toBe(cell.startX);+ expect(rect.y).toBe(cell.startY);+ expect(rect.width).toBe(cell.endX - cell.startX);+ expect(rect.height).toBe(cell.endY - cell.startY);+ expect(rect.toJSON()).toContain(rect.height);+ }+ });+ });+});diff --git a/packages/sheets/package.json b/packages/sheets/package.jsonindex 0403012fb0..a6fd2d4647 100644--- a/packages/sheets/package.json+++ b/packages/sheets/package.json@@ -76,6 +76,8 @@"@univerjs/core": "workspace:*","@univerjs/engine-formula": "workspace:*","@univerjs/engine-numfmt": "workspace:*",+ "@univerjs/engine-render": "workspace:*",+ "@univerjs/network": "workspace:*","@univerjs/protocol": "0.1.43","@univerjs/rpc": "workspace:*"},diff --git a/packages/sheets/src/facade/__tests__/create-test-bed.ts b/packages/sheets/src/facade/__tests__/create-test-bed.tsnew file mode 100644index 0000000000..98f60f5758--- /dev/null+++ b/packages/sheets/src/facade/__tests__/create-test-bed.ts@@ -0,0 +1,190 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { Dependency, IWorkbookData, UnitModel } from '@univerjs/core';+import type { IRender } from '@univerjs/engine-render';+import {+ ILogService,+ Inject,+ Injector,+ IUniverInstanceService,+ LocaleService,+ LocaleType,+ LogLevel,+ Plugin,+ ThemeService,+ Univer,+ UniverInstanceType,+} from '@univerjs/core';+import { FUniver } from '@univerjs/core/facade';+import { DefinedNamesService, FormulaDataModel, FunctionService, IDefinedNamesService, IFunctionService, LexerTreeBuilder } from '@univerjs/engine-formula';+import { Engine, IRenderingEngine, IRenderManagerService, RenderManagerService } from '@univerjs/engine-render';+import { ISocketService, WebSocketService } from '@univerjs/network';+import {+ RangeProtectionRuleModel,+ RefRangeService,+ SheetInterceptorService,+ SheetSkeletonService,+ SheetsSelectionsService,+ WorkbookPermissionService,+ WorksheetPermissionService,+ WorksheetProtectionPointModel,+ WorksheetProtectionRuleModel,+} from '@univerjs/sheets';+import enUS from '@univerjs/sheets/locale/en-US';+import zhCN from '@univerjs/sheets/locale/zh-CN';++import '@univerjs/sheets/facade';++function getTestWorkbookDataDemo(): IWorkbookData {+ return {+ id: 'test',+ appVersion: '3.0.0-alpha',+ sheets: {+ sheet1: {+ id: 'sheet1',+ name: 'sheet1',+ cellData: {+ 0: {+ 3: {+ f: '=SUM(A1)',+ si: '3e4r5t',+ },+ 4: {+ v: 123,+ t: 2,+ },+ },+ 1: {+ 3: {+ f: '=SUM(A2)',+ si: 'OSPtzm',+ },+ },+ 2: {+ 3: {+ si: 'OSPtzm',+ },+ },+ 3: {+ 3: {+ si: 'OSPtzm',+ },+ },+ },+ rowCount: 100,+ columnCount: 100,+ },+ },+ locale: LocaleType.ZH_CN,+ name: '',+ sheetOrder: [],+ styles: {},+ };+}++export interface ITestBed {+ univer: Univer;+ get: Injector['get'];+ sheet: UnitModel<IWorkbookData>;+ univerAPI: FUniver;+ injector: Injector;+}++class RenderManagerServiceTestBed extends RenderManagerService {+ override createRender(unitId: string): IRender {+ const renderer = this._createRender(unitId, new Engine(100, 100));+ return renderer;+ }+}++export function createFacadeTestBed(workbookData?: IWorkbookData, dependencies?: Dependency[]): ITestBed {+ const univer = new Univer();+ const injector = univer.__getInjector();++ class TestPlugin extends Plugin {+ static override pluginName = 'test-plugin';+ static override type = UniverInstanceType.UNIVER_SHEET;++ constructor(+ _config: undefined,+ @Inject(Injector) override readonly _injector: Injector+ ) {+ super();+ }++ override onStarting(): void {+ const injector = this._injector;+ injector.add([SheetsSelectionsService]);+ injector.add([SheetInterceptorService]);++ injector.add([IFunctionService, { useClass: FunctionService }]);+ injector.add([ISocketService, { useClass: WebSocketService }]);+ injector.add([IRenderingEngine, { useFactory: () => new Engine() }]);+ injector.add([IRenderManagerService, { useClass: RenderManagerServiceTestBed }]);+ injector.add([SheetSkeletonService]);+ injector.add([FormulaDataModel]);+ injector.add([LexerTreeBuilder]);+ injector.add([RefRangeService]);+ injector.add([WorksheetPermissionService]);+ injector.add([WorkbookPermissionService]);+ injector.add([WorksheetProtectionPointModel]);+ injector.add([RangeProtectionRuleModel]);+ injector.add([WorksheetProtectionRuleModel]);+ injector.add([IDefinedNamesService, { useClass: DefinedNamesService }]);++ dependencies?.forEach((d) => injector.add(d));++ this._injector.get(SheetInterceptorService);+ this._injector.get(WorkbookPermissionService);+ this._injector.get(WorksheetPermissionService);+ }++ override onReady(): void {++ }+ }++ // load i18n+ injector.get(LocaleService).load({ zhCN, enUS });++ // load theme service+ const themeService = injector.get(ThemeService);+ themeService.setTheme({ colorBlack: '#35322b' });++ // register builtin plugins+ // note that UI plugins are not registered here, because the unit test environment does not have a UI+ univer.registerPlugin(TestPlugin);++ const sheet = univer.createUnit<IWorkbookData, UnitModel<IWorkbookData>>(UniverInstanceType.UNIVER_SHEET, workbookData || getTestWorkbookDataDemo());+ const univerInstanceService = injector.get(IUniverInstanceService);+ univerInstanceService.focusUnit('test');++ // set log level+ const logService = injector.get(ILogService);+ logService.setLogLevel(LogLevel.SILENT); // NOTE: change this to `LogLevel.VERBOSE` to debug tests via logs++ // init data validation+ const univerAPI = FUniver.newAPI(injector);++ return {+ univer,+ get: injector.get.bind(injector),+ sheet,+ univerAPI,+ injector,+ };+}diff --git a/packages/facade/src/apis/sheets/__tests__/create-worksheet-test-bed.ts b/packages/sheets/src/facade/__tests__/create-worksheet-test-bed.tssimilarity index 59%rename from packages/facade/src/apis/sheets/__tests__/create-worksheet-test-bed.tsrename to packages/sheets/src/facade/__tests__/create-worksheet-test-bed.tsindex 956a039800..492382bd1b 100644--- a/packages/facade/src/apis/sheets/__tests__/create-worksheet-test-bed.ts+++ b/packages/sheets/src/facade/__tests__/create-worksheet-test-bed.ts@@ -14,8 +14,6 @@* limitations under the License.*/-/* eslint-disable max-lines-per-function */-import type { Dependency, IWorkbookData, UnitModel } from '@univerjs/core';import type { IRender } from '@univerjs/engine-render';import {@@ -31,7 +29,7 @@ import {Univer,UniverInstanceType,} from '@univerjs/core';-import { UniverDataValidationPlugin } from '@univerjs/data-validation';+import { FUniver } from '@univerjs/core/facade';import { ActiveDirtyManagerService, DefinedNamesService, FormulaDataModel, FunctionService, IActiveDirtyManagerService, IDefinedNamesService, IFunctionService, LexerTreeBuilder } from '@univerjs/engine-formula';import { Engine, IRenderingEngine, IRenderManagerService, RenderManagerService } from '@univerjs/engine-render';import { ISocketService, WebSocketService } from '@univerjs/network';@@ -46,22 +44,10 @@ import {WorksheetProtectionPointModel,WorksheetProtectionRuleModel,} from '@univerjs/sheets';-import { ConditionalFormattingFormulaService, ConditionalFormattingRuleModel, ConditionalFormattingService, ConditionalFormattingViewModel } from '@univerjs/sheets-conditional-formatting';+import enUS from '@univerjs/sheets/locale/en-US';+import zhCN from '@univerjs/sheets/locale/zh-CN';-import { DataValidationCacheService, DataValidationCustomFormulaService, DataValidationFormulaService, SheetDataValidationModel, SheetsDataValidationValidatorService } from '@univerjs/sheets-data-validation';-import { UniverSheetsFilterPlugin } from '@univerjs/sheets-filter';-import {- DescriptionService,- IDescriptionService,- IRegisterFunctionService,- RegisterFunctionService,- RegisterOtherFormulaService,-} from '@univerjs/sheets-formula';-import enUS from '@univerjs/sheets-formula-ui/locale/en-US';-import zhCN from '@univerjs/sheets-formula-ui/locale/zh-CN';-import { ISheetSelectionRenderService, SheetRenderController, SheetSelectionRenderService, SheetSkeletonManagerService, SheetsRenderService } from '@univerjs/sheets-ui';-import { IPlatformService, IShortcutService, PlatformService, ShortcutService } from '@univerjs/ui';-import { FUniver } from '../../everything';+import '@univerjs/sheets/facade';function getTestWorkbookDataDemo(): IWorkbookData {return {@@ -101,12 +87,6 @@ function getTestWorkbookDataDemo(): IWorkbookData {name: '',sheetOrder: [],styles: {},- resources: [- {- name: 'SHEET_CONDITIONAL_FORMATTING_PLUGIN',- data: '{"sheet-0011":[{"cfId":"AEGZdW8C","ranges":[{"startRow":2,"startColumn":1,"endRow":11,"endColumn":5,"startAbsoluteRefType":0,"endAbsoluteRefType":0,"rangeType":0}],"rule":{"type":"highlightCell","subType":"text","operator":"containsText","style":{"cl":{"rgb":"#2f56ef"},"bg":{"rgb":"#e8ecfc"}},"value":""},"stopIfTrue":false},{"cfId":"4ICEXdJj","ranges":[{"startRow":2,"startColumn":1,"endRow":11,"endColumn":5,"startAbsoluteRefType":0,"endAbsoluteRefType":0,"rangeType":0}],"rule":{"type":"highlightCell","subType":"text","operator":"containsText","style":{"cl":{"rgb":"#2f56ef"},"bg":{"rgb":"#e8ecfc"}},"value":""},"stopIfTrue":false},{"cfId":"geCv018z","ranges":[{"startRow":2,"startColumn":1,"endRow":11,"endColumn":5,"startAbsoluteRefType":0,"endAbsoluteRefType":0,"rangeType":0}],"rule":{"type":"highlightCell","subType":"text","operator":"containsText","style":{"cl":{"rgb":"#2f56ef"},"bg":{"rgb":"#e8ecfc"}},"value":""},"stopIfTrue":false}]}',- },- ],};}@@ -144,24 +124,12 @@ export function createWorksheetTestBed(workbookData?: IWorkbookData, dependencieconst injector = this._injector;injector.add([SheetsSelectionsService]);injector.add([SheetInterceptorService]);- injector.add([IRegisterFunctionService, { useClass: RegisterFunctionService }]);- injector.add([- IDescriptionService,- {- useFactory: () => this._injector.createInstance(DescriptionService),- },- ]);injector.add([IFunctionService, { useClass: FunctionService }]);injector.add([ISocketService, { useClass: WebSocketService }]);injector.add([IRenderingEngine, { useFactory: () => new Engine() }]);injector.add([IRenderManagerService, { useClass: RenderManagerServiceTestBed }]);- injector.add([ISheetSelectionRenderService, { useClass: SheetSelectionRenderService }]);- injector.add([SheetsRenderService]);- injector.add([IShortcutService, { useClass: ShortcutService }]);- injector.add([IPlatformService, { useClass: PlatformService }]);injector.add([SheetSkeletonService]);- injector.add([SheetSkeletonManagerService]);injector.add([FormulaDataModel]);injector.add([LexerTreeBuilder]);injector.add([RefRangeService]);@@ -172,28 +140,9 @@ export function createWorksheetTestBed(workbookData?: IWorkbookData, dependencieinjector.add([WorksheetProtectionRuleModel]);injector.add([IDefinedNamesService, { useClass: DefinedNamesService }]);- const renderManagerService = injector.get(IRenderManagerService);- renderManagerService.registerRenderModule(UniverInstanceType.UNIVER_SHEET, [SheetSkeletonManagerService] as Dependency);- renderManagerService.registerRenderModule(UniverInstanceType.UNIVER_SHEET, [SheetRenderController] as Dependency);-// register feature modules([- // conditional formatting- [ConditionalFormattingService],- [ConditionalFormattingFormulaService],- [ConditionalFormattingRuleModel],- [ConditionalFormattingViewModel],-- // data validation- [DataValidationCacheService],- [DataValidationFormulaService],- [DataValidationCustomFormulaService],- [RegisterOtherFormulaService],[IActiveDirtyManagerService, { useClass: ActiveDirtyManagerService }],- [SheetsDataValidationValidatorService],- [SheetDataValidationModel],-- // sheets filter] as Dependency[]).forEach((d) => {injector.add(d);});@@ -202,7 +151,7 @@ export function createWorksheetTestBed(workbookData?: IWorkbookData, dependencie}override onReady(): void {- this._injector.get(SheetsRenderService);+}}@@ -216,8 +165,6 @@ export function createWorksheetTestBed(workbookData?: IWorkbookData, dependencie// register builtin plugins// note that UI plugins are not registered here, because the unit test environment does not have a UIuniver.registerPlugin(TestPlugin);- univer.registerPlugin(UniverSheetsFilterPlugin);- univer.registerPlugin(UniverDataValidationPlugin);const sheet = univer.createUnit<IWorkbookData, UnitModel<IWorkbookData>>(UniverInstanceType.UNIVER_SHEET, workbookData || getTestWorkbookDataDemo());const univerInstanceService = injector.get(IUniverInstanceService);diff --git a/packages/facade/src/apis/sheets/__tests__/f-active-range.spec.ts b/packages/sheets/src/facade/__tests__/f-active-range.spec.tssimilarity index 96%rename from packages/facade/src/apis/sheets/__tests__/f-active-range.spec.tsrename to packages/sheets/src/facade/__tests__/f-active-range.spec.tsindex f76110dec1..fef2bfb442 100644--- a/packages/facade/src/apis/sheets/__tests__/f-active-range.spec.ts+++ b/packages/sheets/src/facade/__tests__/f-active-range.spec.ts@@ -15,11 +15,11 @@*/import type { Injector } from '@univerjs/core';-import type { FUniver } from '../../everything';+import type { FUniver } from '@univerjs/core/facade';import { ICommandService } from '@univerjs/core';import { InsertSheetCommand, InsertSheetMutation, RemoveSheetCommand, RemoveSheetMutation, SetSelectionsOperation, SetWorksheetActiveOperation } from '@univerjs/sheets';import { beforeEach, describe, expect, it } from 'vitest';-import { createFacadeTestBed } from '../../__tests__/create-test-bed';+import { createFacadeTestBed } from './create-test-bed';describe('Test Active Range', () => {let get: Injector['get'];diff --git a/packages/facade/src/apis/sheets/__tests__/f-defined-name.spec.ts b/packages/sheets/src/facade/__tests__/f-defined-name.spec.tssimilarity index 97%rename from packages/facade/src/apis/sheets/__tests__/f-defined-name.spec.tsrename to packages/sheets/src/facade/__tests__/f-defined-name.spec.tsindex 6c1cfce35f..48dbdf415c 100644--- a/packages/facade/src/apis/sheets/__tests__/f-defined-name.spec.ts+++ b/packages/sheets/src/facade/__tests__/f-defined-name.spec.ts@@ -15,12 +15,12 @@*/import type { ICellData, Injector, Nullable } from '@univerjs/core';-import type { FUniver } from '../../everything';+import type { FUniver } from '@univerjs/core/facade';import { ICommandService, IUniverInstanceService } from '@univerjs/core';import { RemoveDefinedNameMutation, SetDefinedNameMutation } from '@univerjs/engine-formula';import { RemoveDefinedNameCommand, SetDefinedNameCommand } from '@univerjs/sheets';import { beforeEach, describe, expect, it } from 'vitest';-import { createFacadeTestBed } from '../../__tests__/create-test-bed';+import { createFacadeTestBed } from './create-test-bed';describe('Test FDefinedName', () => {let get: Injector['get'];diff --git a/packages/facade/src/apis/sheets/__tests__/f-permission.spec.ts b/packages/sheets/src/facade/__tests__/f-permission.spec.tssimilarity index 98%rename from packages/facade/src/apis/sheets/__tests__/f-permission.spec.tsrename to packages/sheets/src/facade/__tests__/f-permission.spec.tsindex 53537b5064..43e09e1de0 100644--- a/packages/facade/src/apis/sheets/__tests__/f-permission.spec.ts+++ b/packages/sheets/src/facade/__tests__/f-permission.spec.ts@@ -15,11 +15,11 @@*/import type { Injector } from '@univerjs/core';-import type { FUniver } from '../../everything';+import type { FUniver } from '@univerjs/core/facade';import { ICommandService, IPermissionService } from '@univerjs/core';import { AddRangeProtectionMutation, AddWorksheetProtectionMutation, DeleteRangeProtectionMutation, DeleteWorksheetProtectionMutation, RangeProtectionPermissionEditPoint, RangeProtectionRuleModel, SetRangeProtectionMutation, WorkbookEditablePermission, WorksheetEditPermission } from '@univerjs/sheets';import { beforeEach, describe, expect, it } from 'vitest';-import { createFacadeTestBed } from '../../__tests__/create-test-bed';+import { createFacadeTestBed } from './create-test-bed';describe('Test FPermission', () => {let get: Injector['get'];diff --git a/packages/facade/src/apis/sheets/__tests__/f-range.spec.ts b/packages/sheets/src/facade/__tests__/f-range.spec.tssimilarity index 85%rename from packages/facade/src/apis/sheets/__tests__/f-range.spec.tsrename to packages/sheets/src/facade/__tests__/f-range.spec.tsindex 704f358781..97d39b7a33 100644--- a/packages/facade/src/apis/sheets/__tests__/f-range.spec.ts+++ b/packages/sheets/src/facade/__tests__/f-range.spec.ts@@ -16,14 +16,12 @@/* eslint-disable ts/no-non-null-asserted-optional-chain */-import type { ICellData, Injector, IRange, IStyleData, Nullable } from '@univerjs/core';-import type { FUniver } from '../../everything';-import { DataValidationType, HorizontalAlign, ICommandService, IUniverInstanceService, LifecycleStages, VerticalAlign, WrapStrategy } from '@univerjs/core';+import type { ICellData, Injector, IStyleData, Nullable } from '@univerjs/core';+import type { FUniver } from '@univerjs/core/facade';+import { HorizontalAlign, ICommandService, IUniverInstanceService, LifecycleStages, VerticalAlign, WrapStrategy } from '@univerjs/core';import { AddWorksheetMergeCommand, SetHorizontalTextAlignCommand, SetRangeValuesCommand, SetRangeValuesMutation, SetStyleCommand, SetTextWrapCommand, SetVerticalTextAlignCommand } from '@univerjs/sheets';-import { AddSheetDataValidationCommand } from '@univerjs/sheets-data-validation';-import { ClearSheetsFilterCriteriaCommand, RemoveSheetFilterCommand, SetSheetFilterRangeCommand, SetSheetsFilterCriteriaCommand } from '@univerjs/sheets-filter';import { beforeEach, describe, expect, it } from 'vitest';-import { createFacadeTestBed } from '../../__tests__/create-test-bed';+import { createFacadeTestBed } from './create-test-bed';describe('Test FRange', () => {let get: Injector['get'];@@ -55,7 +53,6 @@ describe('Test FRange', () => {commandService.registerCommand(SetVerticalTextAlignCommand);commandService.registerCommand(SetHorizontalTextAlignCommand);commandService.registerCommand(SetTextWrapCommand);- commandService.registerCommand(AddSheetDataValidationCommand);commandService.registerCommand(AddWorksheetMergeCommand);getValueByPosition = (@@ -270,26 +267,6 @@ describe('Test FRange', () => {expect(range?.getCellData()?.v).toBe(1);});- it('Range getCell', () => {- const activeSheet = univerAPI.getActiveWorkbook()!.getActiveSheet();- const range = activeSheet?.getRange(2, 3);- const cell = range?.getCell()!;- expect(cell.actualColumn).toBe(3);- expect(cell.actualRow).toBe(2);- });-- it('Range getCellRect', () => {- const activeSheet = univerAPI.getActiveWorkbook()!.getActiveSheet();- const range = activeSheet?.getRange(0, 0);- const cell = range?.getCell()!;- const rect = range?.getCellRect()!;- expect(rect.x).toBe(cell.startX);- expect(rect.y).toBe(cell.startY);- expect(rect.width).toBe(cell.endX - cell.startX);- expect(rect.height).toBe(cell.endY - cell.startY);- expect(rect.toJSON()).toContain(rect.height);- });-it('Range isMerged', () => {const activeSheet = univerAPI.getActiveWorkbook()!.getActiveSheet()!;const range = activeSheet!.getRange(2, 3);@@ -608,79 +585,6 @@ describe('Test FRange', () => {expect(getStyleByPosition(0, 0, 0, 0)?.tb).toBe(WrapStrategy.CLIP);});- it('Range set data validation', async () => {- const activeSheet = univerAPI.getActiveWorkbook()?.getActiveSheet()!;- const range = activeSheet.getRange(0, 0, 10, 10);- const range2 = activeSheet.getRange(11, 11, 2, 2);- await range.setDataValidation(univerAPI.newDataValidation().requireCheckbox().build());- await range2?.setDataValidation(univerAPI.newDataValidation().requireNumberEqualTo(1).build());- const range3 = activeSheet.getRange(0, 0, 100, 100);-- expect(range.getDataValidation()).toBeTruthy();- expect(range.getDataValidation()?.rule.ranges).toEqual([{- unitId: univerAPI.getActiveWorkbook()?.getId(),- sheetId: activeSheet.getSheetId(),- startRow: 0,- endRow: 9,- startColumn: 0,- endColumn: 9,- }]);- expect(range.getDataValidation()?.getCriteriaType()).toEqual(DataValidationType.CHECKBOX);- expect(range.getDataValidations().length).toEqual(1);- expect(range3?.getDataValidations().length).toEqual(2);-- expect(activeSheet?.getDataValidations().length).toEqual(2);- });-- // #region Filter-- describe('FFilter', () => {- beforeEach(() => {- commandService.registerCommand(SetSheetsFilterCriteriaCommand);- commandService.registerCommand(ClearSheetsFilterCriteriaCommand);- commandService.registerCommand(SetSheetFilterRangeCommand);- commandService.registerCommand(RemoveSheetFilterCommand);- });-- it('create, modify and clear filters with Facade API', async () => {- const activeSheet = univerAPI.getActiveWorkbook()!.getActiveSheet();- expect(activeSheet.getFilter()).toBeNull();- expect(activeSheet.getRange(0, 0, 1, 1).getFilter()).toBeNull();-- const range = activeSheet.getRange(0, 0, 10, 10);- const filter = (await range.createFilter())!;-- expect(filter).not.toBeNull();- expect(activeSheet.getFilter()).not.toBeNull();- expect(activeSheet.getRange(0, 0, 1, 1).getFilter()).not.toBeNull();- expect(filter.getRange().getRange()).toStrictEqual({- unitId: univerAPI.getActiveWorkbook()?.getId(),- sheetId: activeSheet.getSheetId(),- startColumn: 0,- startRow: 0,- endColumn: 9,- endRow: 9,- } as IRange);-- expect(await filter.setColumnFilterCriteria(1, { colId: 1, filters: { blank: true } })).toBeTruthy();- expect(filter.getColumnFilterCriteria(1)).toEqual({ colId: 1, filters: { blank: true } });-- expect(await filter.setColumnFilterCriteria(2, { colId: 2, filters: { filters: ['a'] } })).toBeTruthy();- expect(filter.getColumnFilterCriteria(2)).toEqual({ colId: 2, filters: { filters: ['a'] } });-- expect(await filter.removeColumnFilterCriteria(1)).toBeTruthy();- expect(filter.getColumnFilterCriteria(1)).toBeFalsy();-- expect(await filter.removeFilterCriteria()).toBeTruthy();- expect(filter.getColumnFilterCriteria(2)).toBeFalsy();-- expect(await filter.remove()).toBeTruthy();- expect(activeSheet.getFilter()).toBeNull();- });- });-- // #endregion-// #region Merge cellsit('test Merge', async () => {let hasError = false;@@ -810,16 +714,6 @@ describe('Test FRange', () => {]));});- it('Range setNumberFormat', () => {- univerAPI.getHooks().onRendered(() => {- const activeSheet = univerAPI.getActiveWorkbook()!.getActiveSheet();- const range = activeSheet.getRange(0, 0, 1, 1);- range.setValue(1234.5678);- range.setNumberFormat('#,###');- expect(range.getValue()).toBe('1,234.5678');- });- });-it('Range getRawValue and getDisplayValue', () => {univerAPI.addEvent(univerAPI.Event.LifeCycleChanged, ({ stage }) => {if (stage === LifecycleStages.Steady) {diff --git a/packages/facade/src/apis/sheets/__tests__/f-workbook.spec.ts b/packages/sheets/src/facade/__tests__/f-workbook.spec.tssimilarity index 97%rename from packages/facade/src/apis/sheets/__tests__/f-workbook.spec.tsrename to packages/sheets/src/facade/__tests__/f-workbook.spec.tsindex d00ed49717..d9493971e4 100644--- a/packages/facade/src/apis/sheets/__tests__/f-workbook.spec.ts+++ b/packages/sheets/src/facade/__tests__/f-workbook.spec.ts@@ -15,11 +15,11 @@*/import type { ICellData, Injector, Nullable } from '@univerjs/core';-import type { FUniver } from '../../everything';+import type { FUniver } from '@univerjs/core/facade';import { ICommandService, IUniverInstanceService, LocaleType } from '@univerjs/core';import { CopySheetCommand, InsertSheetCommand, InsertSheetMutation, RemoveSheetCommand, RemoveSheetMutation, SetHorizontalTextAlignCommand, SetRangeValuesCommand, SetRangeValuesMutation, SetStyleCommand, SetTextWrapCommand, SetVerticalTextAlignCommand, SetWorksheetActiveOperation, SetWorksheetOrderCommand, SetWorksheetOrderMutation } from '@univerjs/sheets';import { beforeEach, describe, expect, it } from 'vitest';-import { createFacadeTestBed } from '../../__tests__/create-test-bed';+import { createFacadeTestBed } from './create-test-bed';describe('Test FWorkbook', () => {let get: Injector['get'];diff --git a/packages/facade/src/apis/sheets/__tests__/f-worksheet.spec.ts b/packages/sheets/src/facade/__tests__/f-worksheet.spec.tssimilarity index 96%rename from packages/facade/src/apis/sheets/__tests__/f-worksheet.spec.tsrename to packages/sheets/src/facade/__tests__/f-worksheet.spec.tsindex 87d2bbc00d..435dc92e13 100644--- a/packages/facade/src/apis/sheets/__tests__/f-worksheet.spec.ts+++ b/packages/sheets/src/facade/__tests__/f-worksheet.spec.ts@@ -22,8 +22,6 @@ import { AddWorksheetMergeCommand, AddWorksheetMergeMutation, CancelFrozenCommanimport { beforeEach, describe, expect, it } from 'vitest';import { createWorksheetTestBed } from './create-worksheet-test-bed';-import '../../everything';-describe('Test FWorksheet', () => {let get: Injector['get'];let commandService: ICommandService;@@ -153,29 +151,6 @@ describe('Test FWorksheet', () => {expect(activeSheet?.getMaxRows()).toBe(100);});- // #region Data Validation-- it('Worksheet getDataValidations', async () => {- const activeSheet = univerAPI.getActiveWorkbook()?.getSheetByName('sheet1');- expect(activeSheet?.getDataValidations()).toBeDefined();- });-- it('Worksheet getValidatorStatus', async () => {- const activeSheet = univerAPI.getActiveWorkbook()?.getSheetByName('sheet1');- expect(activeSheet?.getValidatorStatus()).toBeDefined();- });-- // #endregion-- // #region Filter-- it('Worksheet getFilter', async () => {- const activeSheet = univerAPI.getActiveWorkbook()?.getSheetByName('sheet1');- expect(activeSheet?.getFilter()).toBeDefined();- });-- // #endregion-// #region Rowit('Worksheet insertRowAfter', async () => {@@ -564,9 +539,4 @@ describe('Test FWorksheet', () => {expect(activeSheet?.getFrozenRows()).toBe(21);expect(activeSheet?.getFrozenColumns()).toBe(9);});-- it('Worksheet refreshCanvas', async () => {- const activeSheet = univerAPI.getActiveWorkbook()?.getActiveSheet();- activeSheet?.refreshCanvas();- });});diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 850ae73dda..e0a3a653b3 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -331,6 +331,9 @@ importers:'@univerjs/mockdata':specifier: workspace:*version: link:../mockdata+ '@univerjs/network':+ specifier: workspace:*+ version: link:../packages/network'@univerjs/rpc':specifier: workspace:*version: link:../packages/rpc@@ -1506,6 +1509,12 @@ importers:'@univerjs/docs-drawing':specifier: workspace:*version: link:../docs-drawing+ jest-canvas-mock:+ specifier: ^2.5.2+ version: 2.5.2+ jsdom:+ specifier: ^24.1.1+ version: 24.1.1less:specifier: ^4.2.2version: 4.2.2@@ -1697,94 +1706,6 @@ importers:specifier: ^3.0.8version: 3.0.8(@types/[email protected])(@types/[email protected])([email protected])([email protected])([email protected])([email protected])([email protected])([email protected])([email protected])([email protected])- packages/facade:- dependencies:- '@univerjs/core':- specifier: workspace:*- version: link:../core- '@univerjs/docs-ui':- specifier: workspace:*- version: link:../docs-ui- '@univerjs/engine-formula':- specifier: workspace:*- version: link:../engine-formula- '@univerjs/network':- specifier: workspace:*- version: link:../network- '@univerjs/sheets':- specifier: workspace:*- version: link:../sheets- '@univerjs/sheets-conditional-formatting':- specifier: workspace:*- version: link:../sheets-conditional-formatting- '@univerjs/sheets-data-validation':- specifier: workspace:*- version: link:../sheets-data-validation- '@univerjs/sheets-filter':- specifier: workspace:*- version: link:../sheets-filter- '@univerjs/sheets-formula':- specifier: workspace:*- version: link:../sheets-formula- '@univerjs/sheets-hyper-link':- specifier: workspace:*- version: link:../sheets-hyper-link- '@univerjs/sheets-hyper-link-ui':- specifier: workspace:*- version: link:../sheets-hyper-link-ui- '@univerjs/sheets-numfmt':- specifier: workspace:*- version: link:../sheets-numfmt- '@univerjs/sheets-thread-comment':- specifier: workspace:*- version: link:../sheets-thread-comment- '@univerjs/sheets-ui':- specifier: workspace:*- version: link:../sheets-ui- '@univerjs/sheets-zen-editor':- specifier: workspace:*- version: link:../sheets-zen-editor- '@univerjs/ui':- specifier: workspace:*- version: link:../ui- devDependencies:- '@univerjs-infra/shared':- specifier: workspace:*- version: link:../../common/shared- '@univerjs/data-validation':- specifier: workspace:*- version: link:../data-validation- '@univerjs/docs':- specifier: workspace:*- version: link:../docs- '@univerjs/engine-render':- specifier: workspace:*- version: link:../engine-render- '@univerjs/sheets-formula-ui':- specifier: workspace:*- version: link:../sheets-formula-ui- '@univerjs/thread-comment':- specifier: workspace:*- version: link:../thread-comment- jest-canvas-mock:- specifier: ^2.5.2- version: 2.5.2- jsdom:- specifier: ^24.1.1- version: 24.1.1- rxjs:- specifier: ^7.8.1- version: 7.8.1- typescript:- specifier: ^5.8.2- version: 5.8.2- vite:- specifier: ^6.2.1- version: 6.2.1(@types/[email protected])([email protected])([email protected])([email protected])([email protected])([email protected])([email protected])- vitest:- specifier: ^3.0.8- version: 3.0.8(@types/[email protected])(@types/[email protected])([email protected])([email protected])([email protected])([email protected])([email protected])([email protected])([email protected])([email protected])-packages/find-replace:dependencies:'@univerjs/core':@@ -1911,6 +1832,12 @@ importers:'@univerjs/engine-numfmt':specifier: workspace:*version: link:../engine-numfmt+ '@univerjs/engine-render':+ specifier: workspace:*+ version: link:../engine-render+ '@univerjs/network':+ specifier: workspace:*+ version: link:../network'@univerjs/protocol':specifier: 0.1.43version: 0.1.43(@grpc/[email protected])([email protected])