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
feat(facade): make facade a separate pacakge (#964)
Wenzhao Hue473dbfda4b3
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.mdindex 77a0ceddc9..9a60c0a137 100644--- a/CONTRIBUTING.md+++ b/CONTRIBUTING.md@@ -56,10 +56,10 @@ The file structure of a plugin should be organized as follows:There are some limits on what paths could a file import from.-* common cannot import file in other folders-* models can only import files from common-* services can only import files from models and common-* commands can only import files from common, models and services+- common cannot import file in other folders+- models can only import files from common+- services can only import files from models and common+- commands can only import files from common, models and servicesDuring the refactoring process, it is recommended to remove legacy folders such as `Enum`, `Interface`, `Basics`, and `Shared`.@@ -69,21 +69,25 @@ Avoid creating barrel imports (index.ts) unless it is the main root index.ts filTo ensure code quality and consistency, please adhere to the following guidelines:-- Use kebab-case for both file names and folder names. If the file contains a React component, it should be in capital camelCase.-- Folder names should be in plural format, e.g. `SheetTab.tsx`.-- Interfaces should be named starting with a capital "I".-- Resolve all ESLint issues that are identified in the code.-- Do use conventional type names including .service, .controller, .menu, .command, .mutation, and .operation. Invent additional type names if you must but take care not to create too many.+- Use kebab-case for both file names and folder names. If the file contains a React component, it should be in capital camelCase.+- Folder names should be in plural format, e.g. `SheetTab.tsx`.+- Interfaces should be named starting with a capital "I".+- Resolve all ESLint issues that are identified in the code.+- Do use conventional type names including .service, .controller, .menu, .command, .mutation, and .operation. Invent additional type names if you must but take care not to create too many.### Submitting pull requestsBefore merging a pull request, please make sure the following requirements are met:-- All tests are passed. ESLint and Prettier errors are fixed.-- Test coverage is not decreased.+- All tests are passed. ESLint and Prettier errors are fixed.+- Test coverage is not decreased.We provide preview deployments for pull requests. You can view the preview deployment by clicking the "Preview" link in the "View Deployment" section.+### Documentation++If you are adding a new feature, please make sure to update the documentation accordingly. Refer to our [documentation repository](https://github.com/dream-num/docs) for more guidance.+### StorybookWe use Storybook to develop and test components in isolation. It is a great tool to develop UI components in isolation, which can improve component reuse, testability, and development efficiency. You can use the following command to start Storybook:@@ -116,8 +120,21 @@ With the help of vscode and its rich ecosystem, you could directly debug unit te### Clean code-> Programs are meant to be ready by humans and only icidentally for computers to execute.+> Programs are meant to be ready by humans and only icidentally for computers to execute. - Harold Abelson++- Do not expose properties or methods those are not necessary to be exposed.+- Group related methods or properties together. Do not always use blank lines to separate them.+- Keep your concepts consistent by naming your variables consistently.++### New Package++Create a new package with our CLI tool:-* Do not expose properties or methods those are not necessary to be public.-* Group related methods or properties together. Do not always use blank lines to separate them.-* Keep your concepts consistent by naming your variables consistently.+```shell+# pnpm+pnpm create @univerjs/cli init <project-name>++# npm+npm create @univerjs/cli init <project-name>++```diff --git a/README.md b/README.mdindex e38ac4c72c..34b0acb964 100644--- a/README.md+++ b/README.md@@ -58,24 +58,25 @@ Univer bases on a plugin architecture. You can install the following packages to### Packages-| Name | Description | Version |-| :----------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------------------------------------- |-| [core](./packages/core) | Implements plugin system and architecture of Univer. It also provides basic services and models of different types of documents. | [](https://npmjs.org/package/@univerjs/core) |-| [design](./packages/design) | Implements the design system on Univer. It provides CSS and a component kit based on React. | [](https://npmjs.org/package/@univerjs/design) |-| [docs](./packages/docs) | Implements basic logics of rich text editing features. It also facilitates text editing in other types of documents. | [](https://npmjs.org/package/@univerjs/docs) |-| [docs-ui](./packages/docs-ui) | Provides user interface of Univer Documents | [](https://npmjs.org/package/@univerjs/docs-ui) |-| [engine-formula](./packages/engine-formula) | It implements a rendering engine based on Canvas and is extensible for | [](https://npmjs.org/package/@univerjs/engine-formula) |-| [engine-numfmt](./packages/engine-numfmt) | It implements a number format engine. | [](https://npmjs.org/package/@univerjs/engine-numfmt) |-| [engine-render](./packages/engine-render) | It implements a rendering engine based on canvas context2d. | [](https://npmjs.org/package/@univerjs/engine-render) |-| [network](./packages/network) | It implements network services based on WebSocket and HTTP. | [](https://npmjs.org/package/@univerjs/network) |-| [rpc](./packages/rpc) | It implements a RPC mechanism and methods to sync data between different replicas of Univer documents. | [](https://npmjs.org/package/@univerjs/rpc) |-| [sheets](./packages/sheets) | Basic logics of spreadsheet features. | [](https://npmjs.org/package/@univerjs/sheets) |-| [sheets-formula](./packages/sheets-formula) | It implements formula in spreadsheets. | [](https://npmjs.org/package/@univerjs/sheets-formula) |-| [sheets-numfmt](./packages/sheets-numfmt) | It implements number format in spreadsheets. | [](https://npmjs.org/package/@univerjs/sheets-numfmt) |-| [sheets-zen-editor](./packages/sheets-zen-editor) | It implements Zen editing mode in spreadsheets. | [](https://npmjs.org/package/@univerjs/sheets-zen-editor) |-| [sheets-ui](./packages/sheets-ui) | Provides user interface of Univer Spreadsheets | [](https://npmjs.org/package/@univerjs/sheets-ui) |-| [ui](./packages/ui) | Implements basic user interactions with Univer and workbench layout based on React. | [](https://npmjs.org/package/@univerjs/ui) |-| [uniscript](./packages/uniscript) (experimental) | Implements a DSL based on Typescript that empowers users to accomplish more sophisticated tasks | [](https://npmjs.org/package/@univerjs/uniscript) |+| Name | Description | Version |+| :------------------------------------------------ | :------------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------------------------------------------- |+| [core](./packages/core) | Implements plugin system and architecture of Univer. It also provides basic services and models of different types of documents. | [](https://npmjs.org/package/@univerjs/core) |+| [design](./packages/design) | Implements the design system on Univer. It provides CSS and a component kit based on React. | [](https://npmjs.org/package/@univerjs/design) |+| [docs](./packages/docs) | Implements basic logics of rich text editing features. It also facilitates text editing in other types of documents. | [](https://npmjs.org/package/@univerjs/docs) |+| [docs-ui](./packages/docs-ui) | Provides user interface of Univer Documents | [](https://npmjs.org/package/@univerjs/docs-ui) |+| [engine-formula](./packages/engine-formula) | It implements a rendering engine based on Canvas and is extensible for | [](https://npmjs.org/package/@univerjs/engine-formula) |+| [engine-numfmt](./packages/engine-numfmt) | It implements a number format engine. | [](https://npmjs.org/package/@univerjs/engine-numfmt) |+| [engine-render](./packages/engine-render) | It implements a rendering engine based on canvas context2d. | [](https://npmjs.org/package/@univerjs/engine-render) |+| [facade](./packages/facade/) | It serves as an API layer to make it easier to use Univer | [](https://npmjs.org/package/@univerjs/facade) |+| [network](./packages/network) | It implements network services based on WebSocket and HTTP. | [](https://npmjs.org/package/@univerjs/network) |+| [rpc](./packages/rpc) | It implements a RPC mechanism and methods to sync data between different replicas of Univer documents. | [](https://npmjs.org/package/@univerjs/rpc) |+| [sheets](./packages/sheets) | Basic logics of spreadsheet features. | [](https://npmjs.org/package/@univerjs/sheets) |+| [sheets-formula](./packages/sheets-formula) | It implements formula in spreadsheets. | [](https://npmjs.org/package/@univerjs/sheets-formula) |+| [sheets-numfmt](./packages/sheets-numfmt) | It implements number format in spreadsheets. | [](https://npmjs.org/package/@univerjs/sheets-numfmt) |+| [sheets-zen-editor](./packages/sheets-zen-editor) | It implements Zen editing mode in spreadsheets. | [](https://npmjs.org/package/@univerjs/sheets-zen-editor) |+| [sheets-ui](./packages/sheets-ui) | Provides user interface of Univer Spreadsheets | [](https://npmjs.org/package/@univerjs/sheets-ui) |+| [ui](./packages/ui) | Implements basic user interactions with Univer and workbench layout based on React. | [](https://npmjs.org/package/@univerjs/ui) |+| [uniscript](./packages/uniscript) (experimental) | Implements a DSL based on Typescript that empowers users to accomplish more sophisticated tasks | [](https://npmjs.org/package/@univerjs/uniscript) |## Contributiondiff --git a/packages/facade/README.md b/packages/facade/README.mdnew file mode 100644index 0000000000..11f90a92e5--- /dev/null+++ b/packages/facade/README.md@@ -0,0 +1,18 @@+# @univerjs/facade++[](https://npmjs.org/packages/@univerjs/facade)+[](https://img.shields.io/npm/l/@univerjs/facade)++## Introduction++Facade works as a API layer over all other Univer packages (expect for Uniscript) so that you can use Univer without knowing the details of the architecture.++Though Facade may suites for most of the use cases, you may find it more powerful and easier to extend Univer by using the packages directly.++## Usage++### Installation++```shell+npm i @univerjs/facade+```diff --git a/packages/facade/package.json b/packages/facade/package.jsonnew file mode 100644index 0000000000..3b65ecad0d--- /dev/null+++ b/packages/facade/package.json@@ -0,0 +1,65 @@+{+ "name": "@univerjs/facade",+ "version": "0.1.0-beta.1",+ "description": "",+ "keywords": [],+ "author": "DreamNum <[email protected]>",+ "license": "Apache-2.0",+ "main": "./lib/cjs/index.js",+ "module": "./lib/esm/index.js",+ "types": "./lib/types/index.d.ts",+ "publishConfig": {+ "access": "public",+ "main": "./lib/cjs/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"+ }+ }+ },+ "exports": {+ ".": "./src/index.ts",+ "./*": "./src/*"+ },+ "directories": {+ "lib": "lib"+ },+ "files": [+ "lib"+ ],+ "private": false,+ "scripts": {+ "test": "vitest run",+ "test:watch": "vitest",+ "coverage": "vitest run --coverage",+ "build": "tsc && vite build"+ },+ "dependencies": {+ "@univerjs/core": "workspace:*",+ "@univerjs/sheets": "workspace:*",+ "@wendellhu/redi": "^0.12.13",+ "rxjs": "^7.8.1"+ },+ "devDependencies": {+ "@vitest/coverage-istanbul": "^1.1.1",+ "typescript": "^5.3.3",+ "vite": "^5.0.10",+ "vite-plugin-dts": "^3.7.0",+ "vite-plugin-externals": "^0.6.2",+ "vitest": "^1.1.1"+ },+ "peerDependencies": {+ "@univerjs/core": "workspace:*",+ "@univerjs/sheets": "workspace:*",+ "@wendellhu/redi": ">=0.12.13",+ "rxjs": ">=7.0.0"+ }+}diff --git a/packages/uniscript/src/facade/facade.ts b/packages/facade/src/apis/facade.tssimilarity index 78%rename from packages/uniscript/src/facade/facade.tsrename to packages/facade/src/apis/facade.tsindex 82cb2e4f63..8162d49178 100644--- a/packages/uniscript/src/facade/facade.ts+++ b/packages/facade/src/apis/facade.ts@@ -14,12 +14,16 @@* limitations under the License.*/+import type { IWorkbookData } from '@univerjs/core';import { IUniverInstanceService } from '@univerjs/core';import { Inject, Injector } from '@wendellhu/redi';import { FWorkbook } from './sheet/f-workbook';export class FUniver {+ /**+ * Create a FUniver instance, if the injector is not provided, it will create a new Univer instance.+ */static newInstance(injector: Injector): FUniver {return injector.createInstance(FUniver);}@@ -29,6 +33,11 @@ export class FUniver {@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService) {}+ createUniverSheet(data: IWorkbookData): FWorkbook {+ const workbook = this._univerInstanceService.createSheet(data);+ return this._injector.createInstance(FWorkbook, workbook);+ }+getCurrentSheet(): FWorkbook | null {const workbook = this._univerInstanceService.getCurrentUniverSheetInstance();if (!workbook) {diff --git a/packages/uniscript/src/facade/sheet/f-range.ts b/packages/facade/src/apis/sheet/f-range.tssimilarity index 100%rename from packages/uniscript/src/facade/sheet/f-range.tsrename to packages/facade/src/apis/sheet/f-range.tsdiff --git a/packages/uniscript/src/facade/sheet/f-selection.ts b/packages/facade/src/apis/sheet/f-selection.tssimilarity index 100%rename from packages/uniscript/src/facade/sheet/f-selection.tsrename to packages/facade/src/apis/sheet/f-selection.tsdiff --git a/packages/uniscript/src/facade/sheet/f-workbook.ts b/packages/facade/src/apis/sheet/f-workbook.tssimilarity index 86%rename from packages/uniscript/src/facade/sheet/f-workbook.tsrename to packages/facade/src/apis/sheet/f-workbook.tsindex 3998bbf31c..bdc7bb5f0a 100644--- a/packages/uniscript/src/facade/sheet/f-workbook.ts+++ b/packages/facade/src/apis/sheet/f-workbook.ts@@ -28,6 +28,10 @@ export class FWorkbook {@ICommandService private readonly _commandService: ICommandService) {}+ /**+ * Get the active sheet of the workbook.+ * @returns The active sheet of the workbook+ */getActiveSheet(): FWorksheet | null {const activeSheet = this._workbook.getActiveSheet();if (!activeSheet) {@@ -37,6 +41,13 @@ export class FWorkbook {return this._injector.createInstance(FWorksheet, this._workbook, activeSheet);}+ /**+ * Create a new worksheet and returns a handle to it.+ * @param name Name of the new sheet+ * @param rows How may rows would the new sheet have+ * @param column How many columns would the new sheet have+ * @returns The new created sheet+ */create(name: string, rows: number, column: number): FWorksheet {const newSheet = Tools.deepClone(DEFAULT_WORKSHEET);newSheet.rowCount = rows;diff --git a/packages/uniscript/src/facade/sheet/f-worksheet.ts b/packages/facade/src/apis/sheet/f-worksheet.tssimilarity index 100%rename from packages/uniscript/src/facade/sheet/f-worksheet.tsrename to packages/facade/src/apis/sheet/f-worksheet.tsdiff --git a/packages/facade/src/index.ts b/packages/facade/src/index.tsnew file mode 100644index 0000000000..16cfe6f06d--- /dev/null+++ b/packages/facade/src/index.ts@@ -0,0 +1,17 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * 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.+ */++export { FUniver } from './apis/facade';diff --git a/packages/facade/tsconfig.json b/packages/facade/tsconfig.jsonnew file mode 100644index 0000000000..ccde33f16e--- /dev/null+++ b/packages/facade/tsconfig.json@@ -0,0 +1,10 @@+{+ "extends": "../../tsconfig.json",+ "compilerOptions": {+ "rootDir": ".",+ "outDir": "lib",+ "esModuleInterop": true,+ "strictPropertyInitialization": false+ },+ "include": ["src/**/*"]+}diff --git a/packages/facade/vite.config.ts b/packages/facade/vite.config.tsnew file mode 100644index 0000000000..f57815db04--- /dev/null+++ b/packages/facade/vite.config.ts@@ -0,0 +1,48 @@+import { resolve } from 'path';+import { defineConfig } from 'vitest/config';+import dts from 'vite-plugin-dts';++import { name } from './package.json';++const libName = name+ .replace('@univerjs/', 'univer-')+ .split('-')+ .map((word) => word.charAt(0).toUpperCase() + word.slice(1))+ .join('');++export default defineConfig(({ mode }) => ({+ plugins: [+ dts({+ entryRoot: 'src',+ outDir: 'lib/types',+ }),+ ],+ define: {+ 'process.env.NODE_ENV': JSON.stringify(mode),+ },+ build: {+ outDir: 'lib',+ lib: {+ entry: resolve(__dirname, 'src/index.ts'),+ name: libName,+ fileName: (format) => `${format}/index.js`,+ formats: ['es', 'umd', 'cjs'],+ },+ rollupOptions: {+ external: ['@univerjs/core', '@univerjs/sheets', '@wendellhu/redi', 'rxjs'],+ output: {+ globals: {+ '@univerjs/core': 'UniverCore',+ '@univerjs/sheets': 'UniverSheets',+ '@wendellhu/redi': '@wendellhu/redi',+ rxjs: 'rxjs',+ },+ },+ },+ },+ test: {+ coverage: {+ provider: 'istanbul',+ },+ },+}));diff --git a/packages/uniscript/package.json b/packages/uniscript/package.jsonindex 4059c95672..cdc5a33c29 100644--- a/packages/uniscript/package.json+++ b/packages/uniscript/package.json@@ -49,6 +49,7 @@"dependencies": {"@univerjs/core": "workspace:*","@univerjs/design": "workspace:*",+ "@univerjs/facade": "workspace:*","@univerjs/sheets": "workspace:*","@univerjs/sheets-ui": "workspace:*","@univerjs/ui": "workspace:*",@@ -70,6 +71,7 @@"peerDependencies": {"@univerjs/core": "workspace:*","@univerjs/design": "workspace:*",+ "@univerjs/facade": "workspace:*","@univerjs/sheets": "workspace:*","@univerjs/sheets-ui": "workspace:*","@univerjs/ui": "workspace:*",diff --git a/packages/uniscript/src/facade/README.md b/packages/uniscript/src/facade/README.mddeleted file mode 100644index 1604f98bfc..0000000000--- a/packages/uniscript/src/facade/README.md+++ /dev/null@@ -1,3 +0,0 @@-# Facade--Facade works as an simplified interface for using Univer, especially via Uniscript.\ No newline at end of filediff --git a/packages/uniscript/src/services/script-execution.service.ts b/packages/uniscript/src/services/script-execution.service.tsindex a4f33ae1ab..8eded3326a 100644--- a/packages/uniscript/src/services/script-execution.service.ts+++ b/packages/uniscript/src/services/script-execution.service.ts@@ -15,10 +15,9 @@*/import { Disposable, ILogService } from '@univerjs/core';+import { FUniver } from '@univerjs/facade';import { Inject, Injector } from '@wendellhu/redi';-import { FUniver } from '../facade/facade';-/*** This service is to*/diff --git a/packages/uniscript/vite.config.ts b/packages/uniscript/vite.config.tsindex 7252fe91b5..ec40a4d4ab 100644--- a/packages/uniscript/vite.config.ts+++ b/packages/uniscript/vite.config.ts@@ -47,6 +47,7 @@ export default defineConfig(({ mode }) => ({external: ['@univerjs/core','@univerjs/design',+ '@univerjs/facade','@univerjs/sheets','@univerjs/sheets-ui','@univerjs/ui',@@ -61,6 +62,7 @@ export default defineConfig(({ mode }) => ({globals: {'@univerjs/core': 'UniverCore','@univerjs/design': 'UniverDesign',+ '@univerjs/facade': 'UniverFacade','@univerjs/sheets': 'UniverSheets','@univerjs/sheets-ui': 'UniverSheetsUi','@univerjs/ui': 'UniverUi',diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex d64ba29651..cd9b341c11 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -578,6 +578,40 @@ importers:specifier: ^1.1.1+ packages/facade:+ dependencies:+ '@univerjs/core':+ specifier: workspace:*+ version: link:../core+ '@univerjs/sheets':+ specifier: workspace:*+ version: link:../sheets+ '@wendellhu/redi':+ specifier: ^0.12.13+ version: 0.12.13+ rxjs:+ specifier: ^7.8.1+ version: 7.8.1+ devDependencies:+ '@vitest/coverage-istanbul':+ specifier: ^1.1.1+ version: 1.1.1([email protected])+ typescript:+ specifier: ^5.3.3+ version: 5.3.3+ vite:+ specifier: ^5.0.10+ version: 5.0.10(@types/[email protected])([email protected])+ vite-plugin-dts:+ specifier: ^3.7.0+ vite-plugin-externals:+ specifier: ^0.6.2+ version: 0.6.2([email protected])+ vitest:+ specifier: ^1.1.1+ version: 1.1.1(@types/[email protected])+packages/image:dependencies:'@univerjs/core':@@ -1277,6 +1311,9 @@ importers:'@univerjs/design':specifier: workspace:*version: link:../design+ '@univerjs/facade':+ specifier: workspace:*+ version: link:../facade'@univerjs/sheets':specifier: workspace:*version: link:../sheetsdiff --git a/tsconfig.json b/tsconfig.jsonindex e5c44054e7..84f3636326 100644--- a/tsconfig.json+++ b/tsconfig.json@@ -46,6 +46,9 @@{"path": "./packages/engine-render"},+ {+ "path": "./packages/facade"+ },{"path": "./packages/image"},