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(collaboration): add simle collaboration
Dushusir4b44684808ed
diff --git a/examples/univer-preact-ts/package.json b/examples/univer-preact-ts/package.jsonindex 8c0b680263..59d58bba7d 100644--- a/examples/univer-preact-ts/package.json+++ b/examples/univer-preact-ts/package.json@@ -48,6 +48,7 @@"@univer/base-render": "workspace:^0.0.1","@univer/base-sheets": "workspace:^0.0.1","@univer/base-slides": "workspace:^0.0.1",+ "@univer/common-plugin-collaboration": "workspace:^0.0.1","@univer/common-plugin-data": "workspace:^0.0.1","@univer/core": "workspace:^0.0.1","@univer/sheets-plugin-clipboard": "workspace:^0.0.1",diff --git a/examples/univer-preact-ts/src/index.ts b/examples/univer-preact-ts/src/index.tsindex b7665c920e..9ab8e745ef 100644--- a/examples/univer-preact-ts/src/index.ts+++ b/examples/univer-preact-ts/src/index.ts@@ -10,12 +10,14 @@ import { DEFAULT_FORMULA_DATA, FormulaPlugin, IFormulaConfig } from '@univer/sheimport { INumfmtPluginConfig, NumfmtPlugin } from '@univer/sheets-plugin-numfmt';import { ClipboardPlugin } from '@univer/sheets-plugin-clipboard';import { ImportXlsxPlugin } from '@univer/sheets-plugin-import-xlsx';+import { CollaborationPlugin, ICollaborationPluginConfig } from '@univer/common-plugin-collaboration';interface ISheetPropsCustom {coreConfig?: Partial<IWorkbookConfig>;baseSheetsConfig?: ISheetPluginConfig;numfmtConfig?: INumfmtPluginConfig;formulaConfig?: IFormulaConfig;+ collaborationConfig?: ICollaborationPluginConfig;}/**@@ -35,6 +37,7 @@ class UniverSheetCustom {universheet.installPlugin(new ClipboardPlugin());universheet.installPlugin(new ImportXlsxPlugin());+ universheet.installPlugin(new CollaborationPlugin(config.collaborationConfig));return universheet;}diff --git a/examples/univer-preact-ts/src/main.tsx b/examples/univer-preact-ts/src/main.tsxindex 12ea03d16a..21684b30eb 100644--- a/examples/univer-preact-ts/src/main.tsx+++ b/examples/univer-preact-ts/src/main.tsx@@ -2,121 +2,124 @@ import { DEFAULT_WORKBOOK_DATA, DEFAULT_WORKBOOK_DATA_DOWN } from '@univer/commoimport { IWorkbookConfig, IWorksheetConfig, SheetTypes, Tools } from '@univer/core';import { univerSheetCustom } from '.';- const sheetConfig = {- container:'universheet-demo',- layout: {- sheetContainerConfig:{- infoBar:false,- formulaBar:false,- toolBar:false,- sheetBar:false,- countBar:false,- rightMenu:false,- },+const sheetConfig = {+ container: 'universheet-demo',+ layout: {+ sheetContainerConfig: {+ infoBar: false,+ formulaBar: false,+ toolBar: false,+ sheetBar: false,+ countBar: false,+ rightMenu: false,},- selections: {- 'sheet-01': [- {- selection: {- startRow: 0,- endRow: 0,- startColumn: 3,- endColumn: 3,- },- cell: {- row: 0,- column: 3,- },+ },+ selections: {+ 'sheet-01': [+ {+ selection: {+ startRow: 0,+ endRow: 0,+ startColumn: 3,+ endColumn: 3,+ },+ cell: {+ row: 0,+ column: 3,},- ],- },- };-- let columnCount = 8- if(window.innerWidth < 1366){- columnCount = 5;- }- const defaultWorkbookData = Tools.deepClone(DEFAULT_WORKBOOK_DATA);- defaultWorkbookData.id = 'workbook-01';- defaultWorkbookData.styles = null;- defaultWorkbookData.namedRanges = null;- defaultWorkbookData.sheets = {- 'sheet-01':{- type: 0,- id: 'sheet-01',- name: 'sheet1',- columnCount,- status:1,- cellData:{- '0':{- '0':{- m:'',- v:''- }- }- }- }- };-- // univerSheetCustom({- // coreConfig:defaultWorkbookData,- // baseSheetsConfig: sheetConfig,- // });-- const sheetConfigDown = {- container:'universheet-demo-down',- layout: {- sheetContainerConfig:{- infoBar:false,- formulaBar:false,- toolBar:false,- sheetBar:true,- countBar:false,- rightMenu:false,},- },- selections: {- 'sheet-001': [- {- selection: {- startRow: 0,- endRow: 0,- startColumn: 0,- endColumn: 0,- },- cell: {- row: 0,- column: 0,- },+ ],+ },+};++let columnCount = 8;+if (window.innerWidth < 1366) {+ columnCount = 5;+}+const defaultWorkbookData = Tools.deepClone(DEFAULT_WORKBOOK_DATA);+defaultWorkbookData.id = 'workbook-01';+defaultWorkbookData.styles = null;+defaultWorkbookData.namedRanges = null;+defaultWorkbookData.sheets = {+ 'sheet-01': {+ type: 0,+ id: 'sheet-01',+ name: 'sheet1',+ columnCount,+ status: 1,+ cellData: {+ '0': {+ '0': {+ m: '',+ v: '',},- ],+ },},- };-- const defaultWorkbookDataDown = Tools.deepClone(DEFAULT_WORKBOOK_DATA_DOWN);- defaultWorkbookDataDown.id = 'workbook-02';- defaultWorkbookDataDown.styles = null;- defaultWorkbookDataDown.namedRanges = null;- defaultWorkbookDataDown.sheets = {- 'sheet-001':{- type: 0,- id: 'sheet-001',- name: 'sheet001',- columnCount,- status:1+ },+};++univerSheetCustom({+ coreConfig: defaultWorkbookData,+ baseSheetsConfig: sheetConfig,+ collaborationConfig: {+ url: 'ws://localhost:8448/ws',+ },+});++const sheetConfigDown = {+ container: 'universheet-demo-down',+ layout: {+ sheetContainerConfig: {+ infoBar: false,+ formulaBar: false,+ toolBar: false,+ sheetBar: true,+ countBar: false,+ rightMenu: false,},- 'sheet-002':{- type: 0,- id: 'sheet-002',- name: 'sheet002',- columnCount:columnCount+10,- }- };-- univerSheetCustom({- coreConfig:defaultWorkbookDataDown,- baseSheetsConfig: sheetConfigDown,- });+ },+ selections: {+ 'sheet-001': [+ {+ selection: {+ startRow: 0,+ endRow: 0,+ startColumn: 0,+ endColumn: 0,+ },+ cell: {+ row: 0,+ column: 0,+ },+ },+ ],+ },+};++const defaultWorkbookDataDown = Tools.deepClone(DEFAULT_WORKBOOK_DATA_DOWN);+defaultWorkbookDataDown.id = 'workbook-02';+defaultWorkbookDataDown.styles = null;+defaultWorkbookDataDown.namedRanges = null;+defaultWorkbookDataDown.sheets = {+ 'sheet-001': {+ type: 0,+ id: 'sheet-001',+ name: 'sheet001',+ columnCount,+ status: 1,+ },+ 'sheet-002': {+ type: 0,+ id: 'sheet-002',+ name: 'sheet002',+ columnCount: columnCount + 10,+ },+};++univerSheetCustom({+ coreConfig: defaultWorkbookDataDown,+ baseSheetsConfig: sheetConfigDown,+});// run('universheet-demo')// run('universheet-demo-down')@@ -152,7 +155,7 @@ import { univerSheetCustom } from '.';// ],// },// };-+// let columnCount = 8// if(window.innerWidth < 1366){// columnCount = 5;@@ -170,7 +173,7 @@ import { univerSheetCustom } from '.';// status:1// }// };-+// univerSheetCustom({// coreConfig:defaultWorkbookData,// baseSheetsConfig: sheetConfig,diff --git a/packages/base-sheets/src/Controller/SheetContainerController.ts b/packages/base-sheets/src/Controller/SheetContainerController.tsindex 5fb300e999..438b5ad091 100644--- a/packages/base-sheets/src/Controller/SheetContainerController.ts+++ b/packages/base-sheets/src/Controller/SheetContainerController.ts@@ -1,4 +1,4 @@-import { BooleanNumber, CommandManager, ContextBase, ISheetActionData, LocaleType, PLUGIN_NAMES, SheetActionBase, Workbook } from '@univer/core';+import { CommandManager, ContextBase, ISheetActionData, LocaleType, PLUGIN_NAMES, SheetActionBase, Workbook } from '@univer/core';import { BaseComponentSheet, BaseComponentRender, BaseComponentProps, DragManager, getRefElement } from '@univer/base-component';import { CellRangeModal } from '../View/UI/Common/CellRange/CellRangeModal';@@ -108,7 +108,7 @@ export class SheetContainerController {// Only the currently active worksheet needs to be refreshedconst worksheet = action.getWorkBook().getActiveSheet();- if (worksheet.getConfig().status === BooleanNumber.TRUE) {+ if (worksheet) {try {const canvasView = plugin.getCanvasView();if (canvasView) {diff --git a/packages/common-plugin-collaboration/.eslintignore b/packages/common-plugin-collaboration/.eslintignoredeleted file mode 100644index 3d09ffb347..0000000000--- a/packages/common-plugin-collaboration/.eslintignore+++ /dev/null@@ -1,8 +0,0 @@-.eslintrc.js-vite.config.ts-**/*.test.js-dist-lib-node_modules-package.json-tsconfig.jsondiff --git a/packages/common-plugin-collaboration/.eslintrc.js b/packages/common-plugin-collaboration/.eslintrc.jsnew file mode 100644index 0000000000..7f4cf3e7ba--- /dev/null+++ b/packages/common-plugin-collaboration/.eslintrc.js@@ -0,0 +1,51 @@+module.exports = {+ env: {+ browser: true,+ es2021: true,+ node: true,+ },+ parser: '@typescript-eslint/parser',+ extends: [+ 'airbnb-typescript',+ 'prettier',+ 'eslint:recommended',+ 'plugin:import/recommended',+ 'plugin:import/typescript',+ ],+ parserOptions: {+ ecmaVersion: 12,+ sourceType: 'module',+ project: './tsconfig.json',+ },+ plugins: ['@typescript-eslint', 'prettier', 'import'],+ rules: {+ 'prettier/prettier': [+ 'error',+ {+ endOfLine: 'auto',+ },+ ],+ 'import/prefer-default-export': 'off',+ 'import/no-extraneous-dependencies': [+ 'error',+ { devDependencies: true },+ ],+ // turn on errors for missing imports+ 'import/no-unresolved': 'error',+ },+ settings: {+ 'import/parsers': {+ '@typescript-eslint/parser': ['.ts', '.tsx'],+ },+ 'import/resolver': {+ typescript: {+ alwaysTryTypes: true, // always try to resolve config under `<root>@config` directory even it doesn't contain any source code, like `@config/unist`++ // Choose from one of the "project" configs below or omit to use <root>/tsconfig.json by default++ // use <root>/path/to/folder/tsconfig.json+ project: './tsconfig.json',+ },+ },+ },+};diff --git a/packages/common-plugin-collaboration/.gitignore b/packages/common-plugin-collaboration/.gitignorenew file mode 100644index 0000000000..12e1bd6bec--- /dev/null+++ b/packages/common-plugin-collaboration/.gitignore@@ -0,0 +1,101 @@+#ide+*.DS_Store+.idea+.vscode++#npm+package-lock.json++dist+lib+docs/.vuepress/dist++# Logs+logs+*.log+npm-debug.log*+yarn-debug.log*+yarn-error.log*+lerna-debug.log*++# Runtime config+pids+*.pid+*.seed+*.pid.lock++# Directory for instrumented libs generated by jscoverage/JSCover+lib-cov++# Coverage directory used by tools like istanbul+coverage++# nyc test coverage+.nyc_output++# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)+.grunt++# Bower dependency directory (https://bower.io/)+bower_components++# node-waf configuration+.lock-wscript++# Compiled binary addons (https://nodejs.org/api/addons.html)+build/Release++# Dependency directories+node_modules+jspm_packages/++# TypeScript v1 declaration files+typings/++# Optional npm cache directory+.npm++# Optional eslint cache+.eslintcache++# Optional REPL History+.node_repl_history++# Output of 'npm pack'+*.tgz++# Yarn Integrity file+.yarn-integrity++# dotenv environment variables file+.env++# next.js build output+.next++#lerna-changelog+.changelog+++#editor workspace file+.idea/+++.DS_Store++.history+# examples+++# Production+/build++# Generated files+.docusaurus+.cache-loader++# Misc+.env.local+.env.development.local+.env.test.local+.env.production.localdiff --git a/packages/common-plugin-collaboration/.prettierrc.cjs b/packages/common-plugin-collaboration/.prettierrc.cjsnew file mode 100644index 0000000000..6604107223--- /dev/null+++ b/packages/common-plugin-collaboration/.prettierrc.cjs@@ -0,0 +1,7 @@+module.exports = {+ singleQuote: true,+ trailingComma: 'es5',+ tabWidth: 4,+ semi: true,+ printWidth: 180,+};diff --git a/packages/common-plugin-collaboration/README-zh.md b/packages/common-plugin-collaboration/README-zh.mdnew file mode 100644index 0000000000..18f8d5d811--- /dev/null+++ b/packages/common-plugin-collaboration/README-zh.md@@ -0,0 +1,55 @@+# style-universheet++简体中文 | [English](./README.md)++## 介绍++UniverSheet Collaboration插件++### 安装++```bash+npm i @univer/common-plugin-collaboration+```++### 使用++```js+impport {Collaboration} from '@univer/common-plugin-collaboration'++const univerSheet = new UniverSheet();+univerSheet.installPlugin(new Collaboration());+```++## 本地开发++### 环境++- [Node.js](https://nodejs.org/en/) Version >= 10+- [npm](https://www.npmjs.com/) Version >= 6++### 安装++```+pnpm install+```++### 开发++```+# 当前目录 ./packages/common-plugin-collaboration/+npm run dev++# 或者项目根目录 ./+pnpm run --filter @univer/common-plugin-collaboration dev+```++### 打包++```+# 当前目录 ./packages/common-plugin-collaboration/+npm run build++# 或者根目录 ./+pnpm run --filter @univer/common-plugin-collaboration build+```diff --git a/packages/common-plugin-collaboration/README.md b/packages/common-plugin-collaboration/README.mdindex a40351e838..7fcf54e2e9 100644--- a/packages/common-plugin-collaboration/README.md+++ b/packages/common-plugin-collaboration/README.md@@ -1 +1,55 @@-# @univer/core+# style-universheet++English| [简体中文](./README-zh.md)++## Introduction++UniverSheet Plugin Collaboration++### Installation++```bash+npm i @univer/common-plugin-collaboration+```++### Usage++```js+impport {Collaboration} from '@univer/common-plugin-collaboration'++const univerSheet = new UniverSheet();+univerSheet.installPlugin(new Collaboration());+```++## Local development++### Requirements++- [Node.js](https://nodejs.org/en/) Version >= 10+- [npm](https://www.npmjs.com/) Version >= 6++### Installation++```+pnpm install+```++### Development++```+# Current directory ./packages/common-plugin-collaboration/+npm run dev++# Or project root directory ./+pnpm run --filter @univer/common-plugin-collaboration dev+```++### Package++```+# Current directory ./packages/common-plugin-collaboration/+npm run build++# Or root directory ./+pnpm run --filter @univer/common-plugin-collaboration build+```diff --git a/packages/common-plugin-collaboration/index.html b/packages/common-plugin-collaboration/index.htmlindex 9df55fe771..87007e935e 100644--- a/packages/common-plugin-collaboration/index.html+++ b/packages/common-plugin-collaboration/index.html@@ -2,15 +2,25 @@<html lang="en"><head>- <meta charset="UTF-8" />- <link rel="icon" type="image/svg+xml" href="favicon.svg" />- <meta name="viewport" content="width=device-width, initial-scale=1.0" />- <title>UniverSheet</title>+ <meta charset="UTF-8" />+ <link rel="icon" type="image/svg+xml" href="favicon.svg" />+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />+ <title>Univer</title>+ <style>+ html,+ body {+ height: 100%;+ margin: 0;+ }+ </style></head><body>- <div id="app"></div>- <script type="module" src="/src/main.tsx"></script>+ <div id="app" style="position:absolute;z-index: 99999;"></div>+ <div id="universheet" style="height: 30vh;"></div>+ <div id="univerdoc" style="height: 30vh;"></div>+ <div id="universlide" style="height: 30vh;"></div>+ <script type="module" src="/src/main.tsx"></script></body></html>\ No newline at end of filediff --git a/packages/common-plugin-collaboration/jest.config.js b/packages/common-plugin-collaboration/jest.config.jsindex 8cbf8940cc..73ef4bae42 100644--- a/packages/common-plugin-collaboration/jest.config.js+++ b/packages/common-plugin-collaboration/jest.config.js@@ -1,5 +1,18 @@/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */module.exports = {- preset: 'ts-jest',- testEnvironment: 'node',-};\ No newline at end of file+ preset: 'ts-jest',+ testEnvironment: 'jsdom',+ moduleFileExtensions: ['js', 'ts', 'tsx'],++ roots: ['<rootDir>/src'],+ testMatch: ['**/__tests__/**/*.+(ts|tsx|js)', '**/?(*.)+(spec|test).+(ts|tsx|js)'],+ transform: {+ '^.+\\.(ts|tsx)$': 'ts-jest',+ '^.+\\.tsx?$': 'babel-jest', // https://github.com/kulshekhar/ts-jest/issues/937#issuecomment-455431207+ },+ globals: {+ 'ts-jest': {+ tsConfig: 'tsconfig.test.json',+ },+ },+};diff --git a/packages/common-plugin-collaboration/package.json b/packages/common-plugin-collaboration/package.jsonindex 1c9480ee2b..1998e94910 100644--- a/packages/common-plugin-collaboration/package.json+++ b/packages/common-plugin-collaboration/package.json@@ -1,54 +1,63 @@-{- "name": "@univer/common-plugin-collaboration",- "version": "0.0.1",- "description": "",- "author": "",- "main": "./src/index.ts",- "module": "./src/index.ts",- "types": "./src/Types/index.d.ts",- "publishConfig": {- "main": "./lib/univer-common-plugin-collaboration.cjs.js",- "module": "./lib/univer-common-plugin-collaboration.es.js",- "types": "./lib/index.d.ts"- },- "exports": {- ".": "./src/index.ts",- "./*": "./src/*"- },- "directories": {- "lib": "lib"- },- "files": [- "package.json",- "lib"- ],- "scripts": {- "test": "cross-env NODE_ENV=--experimental-vm-modules jest",- "dev": "vite",- "build": "tsc && vite build",- "watch": "vite build",- "link": "pnpm link ./",- "serve": "vite preview"- },- "license": "MIT",- "dependencies": {- "@univer/core": "workspace:^0.0.1"- },- "devDependencies": {- "@types/jest": "^27.5.2",- "@types/node": "^16.4.6",- "@typescript-eslint/eslint-plugin": "^4.28.5",- "@typescript-eslint/parser": "^4.28.5",- "debug": "^4.3.3",- "identity-obj-proxy": "^3.0.0",- "jest": "29.0.0",- "jest-dev-server": "^6.1.1",- "jest-environment-jsdom": "^29.0.3",- "less": "^4.1.1",- "ts-jest": "29.0.1",- "ts-node": "^10.2.1",- "typescript": "^4.4.1-rc",- "vite": "^2.4.4",- "vite-plugin-external": "1.2.3"- }-}+{+ "name": "@univer/common-plugin-collaboration",+ "version": "0.0.1",+ "description": "UniverSheet normal common-plugin-collaboration",+ "keywords": [],+ "author": "DreamNum <[email protected]>",+ "license": "MIT",+ "main": "./src/index.ts",+ "module": "./src/index.ts",+ "types": "./src/Types/index.d.ts",+ "publishConfig": {+ "main": "./lib/univer-common-plugin-collaboration.cjs.js",+ "module": "./lib/univer-common-plugin-collaboration.es.js",+ "types": "./lib/index.d.ts"+ },+ "exports": {+ ".": "./src/index.ts",+ "./*": "./src/*"+ },+ "directories": {+ "lib": "lib"+ },+ "scripts": {+ "test": "jest",+ "dev": "vite",+ "build": "tsc && vite build",+ "watch": "vite build",+ "link": "pnpm link ./",+ "serve": "vite preview"+ },+ "devDependencies": {+ "@preact/preset-vite": "2.0.0",+ "@testing-library/preact": "^2.0.1",+ "@types/jest": "^27.0.1",+ "@types/node": "^16.4.6",+ "@vitejs/plugin-legacy": "^1.5.1",+ "eslint": "^8.22.0",+ "eslint-config-airbnb-typescript": "^17.0.0",+ "eslint-config-prettier": "^8.3.0",+ "eslint-plugin-import": "^2.23.4",+ "eslint-plugin-prettier": "^3.4.0",+ "eslint-plugin-jsx-a11y": "^6.5.1",+ "eslint-plugin-react": "^7.28.0",+ "eslint-plugin-react-hooks": "^4.3.0",+ "less": "^4.1.1",+ "prettier": "^2.3.2",+ "ts-jest": "29.0.1",+ "ts-node": "^10.2.1",+ "typescript": "^4.4.1-rc",+ "vite": "^2.4.4"+ },+ "dependencies": {+ "@univer/common-plugin-data": "workspace:^0.0.1",+ "@univer/base-component": "workspace:^0.0.1",+ "@univer/base-render": "workspace:^0.0.1",+ "@univer/core": "workspace:^0.0.1",+ "@univer/base-sheets": "workspace:^0.0.1",+ "@univer/base-docs": "workspace:^0.0.1",+ "@univer/base-slides": "workspace:^0.0.1",+ "@univer/style-universheet": "workspace:^0.0.1",+ "preact": "^10.5.14"+ }+}diff --git a/packages/common-plugin-collaboration/src/Basic/Const/PLUGIN_NAME.ts b/packages/common-plugin-collaboration/src/Basic/Const/PLUGIN_NAME.tsnew file mode 100644index 0000000000..39bd5b305a--- /dev/null+++ b/packages/common-plugin-collaboration/src/Basic/Const/PLUGIN_NAME.ts@@ -0,0 +1 @@+export const COLLABORATION_PLUGIN_NAME = 'collaboration';diff --git a/packages/common-plugin-collaboration/src/Basic/Const/index.ts b/packages/common-plugin-collaboration/src/Basic/Const/index.tsnew file mode 100644index 0000000000..0dc96d927a--- /dev/null+++ b/packages/common-plugin-collaboration/src/Basic/Const/index.ts@@ -0,0 +1 @@+export * from './PLUGIN_NAME';diff --git a/packages/common-plugin-collaboration/src/Basic/Enum/index.ts b/packages/common-plugin-collaboration/src/Basic/Enum/index.tsnew file mode 100644index 0000000000..e69de29bb2diff --git a/packages/common-plugin-collaboration/src/Basic/Shared/index.ts b/packages/common-plugin-collaboration/src/Basic/Shared/index.tsnew file mode 100644index 0000000000..e69de29bb2diff --git a/packages/common-plugin-collaboration/src/Basic/index.ts b/packages/common-plugin-collaboration/src/Basic/index.tsnew file mode 100644index 0000000000..640d1bb8b3--- /dev/null+++ b/packages/common-plugin-collaboration/src/Basic/index.ts@@ -0,0 +1,4 @@+export * from './Const';+export * from './Enum';+export * from '../Locale';+export * from './Shared';diff --git a/packages/common-plugin-collaboration/src/CollaborationPlugin.tsx b/packages/common-plugin-collaboration/src/CollaborationPlugin.tsxnew file mode 100644index 0000000000..20e11efe12--- /dev/null+++ b/packages/common-plugin-collaboration/src/CollaborationPlugin.tsx@@ -0,0 +1,51 @@+import { Plugin, UniverSheet, UniverDoc, UniverSlide } from '@univer/core';+import { zh, en } from './Locale';+import { COLLABORATION_PLUGIN_NAME } from './Basic/Const/PLUGIN_NAME';+import { CollaborationController } from './Controller/CollaborationController';++export interface ICollaborationPluginConfig {+ url: string;+}++export class CollaborationPlugin extends Plugin {+ private _collaborationController: CollaborationController;+ config: ICollaborationPluginConfig;+ constructor(config?: ICollaborationPluginConfig) {+ super(COLLABORATION_PLUGIN_NAME);+ this.config = config || { url: '' };+ console.log('colla---config---', config);+ }++ static create(config?: ICollaborationPluginConfig) {+ return new CollaborationPlugin(config);+ }++ installTo(univerInstance: UniverSheet | UniverDoc | UniverSlide) {+ univerInstance.installPlugin(this);+ }++ initialize(): void {+ const context = this.getContext();++ /**+ * load more Locale object+ */+ context.getLocale().load({+ en: en,+ zh: zh,+ });++ this._collaborationController = new CollaborationController(this);+ }++ onMounted(): void {+ this.initialize();+ }++ onDestroy(): void {}++ // TODO common function+ getConfig() {+ return this.config;+ }+}diff --git a/packages/common-plugin-collaboration/src/Controller/CollaborationController.ts b/packages/common-plugin-collaboration/src/Controller/CollaborationController.tsnew file mode 100644index 0000000000..cd7139c431--- /dev/null+++ b/packages/common-plugin-collaboration/src/Controller/CollaborationController.ts@@ -0,0 +1,150 @@+import { BaseComponentRender } from '@univer/base-component';+import { SheetPlugin } from '@univer/base-sheets';+import { ACTION_NAMES, CommandManager, HEART_BEAT_MESSAGE, IOSocket, IOSocketListenType, ISheetActionData, PLUGIN_NAMES, SheetActionBase, SheetContext } from '@univer/core';+import { CollaborationPlugin } from '../CollaborationPlugin';++export class CollaborationController {+ protected _plugin: CollaborationPlugin;++ protected _render: BaseComponentRender;++ socket: IOSocket;++ constructor(plugin: CollaborationPlugin) {+ this._plugin = plugin;+ this._initialize();+ }++ private _initialize() {+ const config = this._plugin.getConfig();+ const { url } = config;++ if (url === '') {+ console.warn('url must be input');+ return;+ }++ this._initSocket(url);+ this._initObserver();+ }++ private _initSocket(url: string) {+ this.socket = new IOSocket({ url });+ this.socket.on(IOSocketListenType.MESSAGE, (event: MessageEvent) => {+ this.onMessage(event && event.data);+ });+ this.socket.on(IOSocketListenType.ERROR, (event: MessageEvent) => {+ this.onError(event && event.data);+ });+ this.socket.on(IOSocketListenType.OPEN, (event: MessageEvent) => {+ this.onOpen(event && event.data);+ });+ this.socket.on(IOSocketListenType.CLOSE, (event: MessageEvent) => {+ this.onClose(event && event.data);+ });+ this.socket.on(IOSocketListenType.RETRY, (event: MessageEvent) => {+ this.onRetry(event && event.data);+ });+ this.socket.on(IOSocketListenType.DESTROY, (event: MessageEvent) => {+ this.onDestroy(event && event.data);+ });+ this.socket.link();+ }++ private _initObserver() {+ let timer: NodeJS.Timeout | null = null;+ CommandManager.getCommandObservers().add(({ actions }) => {+ const plugin: CollaborationPlugin = this._plugin;++ if (!plugin) return;+ if (!actions || actions.length === 0) return;+ const action = actions[0] as SheetActionBase<ISheetActionData, ISheetActionData, void>;+ const actionName = action.getDoActionData().actionName;++ if (actionName !== ACTION_NAMES.SET_RANGE_DATA_ACTION) return;++ const context = plugin.context as SheetContext;++ const currentUnitId = context.getWorkBook().getUnitId();+ const actionUnitId = action.getWorkBook().getUnitId();++ if (currentUnitId !== actionUnitId) return;++ // Only the currently active worksheet needs to be refreshed+ const worksheet = action.getWorkBook().getActiveSheet();+ if (worksheet) {+ try {+ if (timer) {+ clearTimeout(timer);+ timer = null;+ }++ timer = setTimeout(() => {+ const config = context.getWorkBook().getConfig();+ const message = {+ type: 'workbookData',+ config,+ };+ console.log('config===', message);+ this.socket.send(JSON.stringify(message));+ }, 100);+ } catch (error) {+ console.info(error);+ }+ }+ });+ }++ onMessage(data) {+ const json = JSON.parse(data);+ const content = json.content;+ if (content === HEART_BEAT_MESSAGE) {+ return;+ }++ try {+ const message = JSON.parse(content);++ if (message && message.type === 'workbookData') {+ this.refresh(message.config);+ }+ } catch (error) {+ console.error(content);+ }+ }+ onError(data) {+ // console.log('onError====', data);+ }+ onOpen(data) {+ // console.log('onOpen====', data);+ }+ onClose(data) {+ // console.log('onClose====', data);+ }+ onRetry(data) {+ // console.log('onRetry====', data);+ }+ onDestroy(data) {+ // console.log('onDestroy====', data);+ }++ refresh(config) {+ // console.log('onMessage===config====', config);+ const context = this._plugin.getContext() as SheetContext;+ context.refreshWorkbook(config);++ const worksheet = context.getWorkBook().getActiveSheet();+ if (worksheet) {+ try {+ const sheetPlugin = context.getPluginManager().getRequirePluginByName<SheetPlugin>(PLUGIN_NAMES.SPREADSHEET);+ const canvasView = sheetPlugin.getCanvasView();+ if (canvasView) {+ canvasView.updateToSheet(worksheet);+ sheetPlugin.getMainComponent().makeDirty(true);+ }+ } catch (error) {+ console.info(error);+ }+ }+ }+}diff --git a/packages/common-plugin-collaboration/src/Controller/index.ts b/packages/common-plugin-collaboration/src/Controller/index.tsnew file mode 100644index 0000000000..e69de29bb2diff --git a/packages/common-plugin-collaboration/src/Locale/en.ts b/packages/common-plugin-collaboration/src/Locale/en.tsnew file mode 100644index 0000000000..591f058faa--- /dev/null+++ b/packages/common-plugin-collaboration/src/Locale/en.ts@@ -0,0 +1,8 @@+export default {+ collaboration: {+ tooltip: 'Collaboration',+ one:'one',+ two:'two',+ three:'three',+ },+};diff --git a/packages/common-plugin-collaboration/src/Locale/index.ts b/packages/common-plugin-collaboration/src/Locale/index.tsnew file mode 100644index 0000000000..3ac4bcd0fd--- /dev/null+++ b/packages/common-plugin-collaboration/src/Locale/index.ts@@ -0,0 +1,4 @@+import zh from './zh';+import en from './en';++export { zh, en };diff --git a/packages/common-plugin-collaboration/src/Locale/zh.ts b/packages/common-plugin-collaboration/src/Locale/zh.tsnew file mode 100644index 0000000000..9b2931c412--- /dev/null+++ b/packages/common-plugin-collaboration/src/Locale/zh.ts@@ -0,0 +1,8 @@+export default {+ collaboration: {+ tooltip: 'Collaboration',+ one:'一',+ two:'二',+ three:'三',+ },+};diff --git a/packages/common-plugin-collaboration/src/Model/index.ts b/packages/common-plugin-collaboration/src/Model/index.tsnew file mode 100644index 0000000000..e69de29bb2diff --git a/packages/common-plugin-collaboration/src/Service/index.ts b/packages/common-plugin-collaboration/src/Service/index.tsnew file mode 100644index 0000000000..e69de29bb2diff --git a/packages/common-plugin-collaboration/src/Types/index.d.ts b/packages/common-plugin-collaboration/src/Types/index.d.tsindex 788ec436c8..89524af5d9 100644--- a/packages/common-plugin-collaboration/src/Types/index.d.ts+++ b/packages/common-plugin-collaboration/src/Types/index.d.ts@@ -1,2 +1,10 @@+/// <reference types="vite/client" />+export * from '../index';-declare module '@univer/common-plugin-collaboration' { }+declare module '@univer/common-plugin-collaboration' {}++// use css module+declare module '*.less' {+ const resource: { [key: string]: string };+ export = resource;+}diff --git a/packages/common-plugin-collaboration/src/Types/preact.d.ts b/packages/common-plugin-collaboration/src/Types/preact.d.tsnew file mode 100644index 0000000000..0d092b3751--- /dev/null+++ b/packages/common-plugin-collaboration/src/Types/preact.d.ts@@ -0,0 +1,4 @@+/// <reference types="enzyme-adapter-preact-pure" />+import JSX = preact.JSX;++declare module 'enzyme';diff --git a/packages/common-plugin-collaboration/src/View/Render/index.ts b/packages/common-plugin-collaboration/src/View/Render/index.tsnew file mode 100644index 0000000000..e69de29bb2diff --git a/packages/common-plugin-collaboration/src/View/UI/index.ts b/packages/common-plugin-collaboration/src/View/UI/index.tsnew file mode 100644index 0000000000..e69de29bb2diff --git a/packages/common-plugin-collaboration/src/index.ts b/packages/common-plugin-collaboration/src/index.tsindex ce3c4dce57..a5ad30b7c6 100644--- a/packages/common-plugin-collaboration/src/index.ts+++ b/packages/common-plugin-collaboration/src/index.ts@@ -1 +1 @@-export * from './Convert';+export * from './CollaborationPlugin';\ No newline at end of filediff --git a/packages/common-plugin-collaboration/src/main.tsx b/packages/common-plugin-collaboration/src/main.tsxnew file mode 100644index 0000000000..4ac6aee7bc--- /dev/null+++ b/packages/common-plugin-collaboration/src/main.tsx@@ -0,0 +1,50 @@+import { UniverSheet, UniverDoc, UniverSlide } from '@univer/core';+import { RenderEngine } from '@univer/base-render';+import { SheetPlugin } from '@univer/base-sheets';+import { DocPlugin } from '@univer/base-docs';+import { SlidePlugin } from '@univer/base-slides';+import { UniverComponentSheet } from '@univer/style-universheet';+import { DEFAULT_WORKBOOK_DATA } from '@univer/common-plugin-data';++import { CollaborationPlugin } from './CollaborationPlugin';++// sheet+const sheetPluginConfig = {+ container: 'universheet',+};++const univerSheet = UniverSheet.newInstance(DEFAULT_WORKBOOK_DATA);++univerSheet.installPlugin(new RenderEngine());+univerSheet.installPlugin(new UniverComponentSheet());++univerSheet.installPlugin(new SheetPlugin(sheetPluginConfig));+univerSheet.installPlugin(new CollaborationPlugin());++// doc++const docPluginConfig = {+ container: 'univerdoc',+};+const univerDoc = UniverDoc.newInstance();++univerDoc.installPlugin(new RenderEngine());+univerDoc.installPlugin(new UniverComponentSheet());++univerDoc.installPlugin(new DocPlugin(docPluginConfig));+univerDoc.installPlugin(new CollaborationPlugin());+++// SlidePlugin++const slidePluginConfig = {+ container: 'universlide',+};++const univerSlide = UniverSlide.newInstance();++univerSlide.installPlugin(new RenderEngine());+univerSlide.installPlugin(new UniverComponentSheet());++univerSlide.installPlugin(new SlidePlugin(slidePluginConfig));+univerSlide.installPlugin(new CollaborationPlugin());diff --git a/packages/common-plugin-collaboration/tsconfig.json b/packages/common-plugin-collaboration/tsconfig.jsonindex 847d073f6d..fc81cbd47e 100644--- a/packages/common-plugin-collaboration/tsconfig.json+++ b/packages/common-plugin-collaboration/tsconfig.json@@ -18,10 +18,12 @@"baseUrl": "./","skipLibCheck": true,- "esModuleInterop": true, // auto allowSyntheticDefaultImports true- "jsx": "preserve",- "experimentalDecorators": true,+ "esModuleInterop": true, // auto allowSyntheticDefaultImports tru"suppressImplicitAnyIndexErrors": true,+ "experimentalDecorators": true,+ "jsx": "preserve",+ "jsxFactory": "h",+ "jsxFragmentFactory": "Fragment","strictPropertyInitialization": false,"types": ["jest", "node", "@types/jest"]},diff --git a/packages/common-plugin-collaboration/tsconfig.ref.json b/packages/common-plugin-collaboration/tsconfig.ref.jsonindex b321caa9ce..0c86b2c554 100644--- a/packages/common-plugin-collaboration/tsconfig.ref.json+++ b/packages/common-plugin-collaboration/tsconfig.ref.json@@ -1,8 +1,7 @@{- "extends": "./tsconfig.json",- "include": ["src/**/*"],- "exclude": ["test/**/*"],- "compilerOptions": {- "composite": true- }+ "extends": "./tsconfig.json",+ "include": ["src/**/*"],+ "compilerOptions": {+ "composite": true+ }}diff --git a/packages/common-plugin-collaboration/tsconfig.test.json b/packages/common-plugin-collaboration/tsconfig.test.jsonnew file mode 100644index 0000000000..a2ac02c4ae--- /dev/null+++ b/packages/common-plugin-collaboration/tsconfig.test.json@@ -0,0 +1,7 @@+{+ "extends": "./tsconfig.json",+ "compilerOptions": {+ "jsx": "react-jsx",+ "jsxImportSource": "preact"+ }+}diff --git a/packages/common-plugin-collaboration/vite.config.ts b/packages/common-plugin-collaboration/vite.config.tsindex 2e70dbe0b0..020ecd6209 100644--- a/packages/common-plugin-collaboration/vite.config.ts+++ b/packages/common-plugin-collaboration/vite.config.ts@@ -1,39 +1,44 @@import { defineConfig } from 'vite';-import { name, version } from './package.json';import path from 'path';+import preact from '@preact/preset-vite';+import legacy from '@vitejs/plugin-legacy';+import { name, version } from './package.json';const resolve = (url: string) => path.resolve(__dirname, url);export default defineConfig({- // build: {- // lib: {- // entry: resolve('src/index.ts'),- // name: 'UniverSheet',- // formats: ['es', 'umd'],- // fileName: 'index',- // },- // outDir: './lib',- // },+ build: {+ // lib: {+ // entry: resolve('src/index.ts'),+ // name: 'BaseStyleUniver',+ // formats: ['es', 'umd'],+ // fileName: 'index',+ // },+ // outDir: './lib',+ },define: {pkgJson: { name, version },},- esbuild: {- jsxFactory: 'DOMcreateElement',- jsxFragment: 'DOMcreateFragment',- jsxInject: "import { DOMcreateElement, DOMcreateFragment } from '@/Common/jsxFactory'",- },- server: {- port: 3102,- open: true, // // Automatically open the app in the browser on server start.- },- resolve: {- alias: {- '@': path.resolve(__dirname, 'src'),- },- },css: {modules: {- localsConvention: 'camelCaseOnly',+ localsConvention: 'camelCaseOnly', // dash to camelCase conversion// .apply-color -> applyColor+ generateScopedName: 'univer-[local]', // custom prefix class name+ },+ preprocessorOptions: {+ less: {+ javascriptEnabled: true,+ },},},+ server: {+ port: 3103,+ open: true, // Automatically open the app in the browser on server start.+ },+ plugins: [+ preact(),+ legacy({+ targets: ['ie >= 11'],+ additionalLegacyPolyfills: ['regenerator-runtime/runtime'],+ }),+ ],});diff --git a/packages/core/src/Shared/IOSocket.ts b/packages/core/src/Shared/IOSocket.tsindex 9d000817d8..1052aa3966 100644--- a/packages/core/src/Shared/IOSocket.ts+++ b/packages/core/src/Shared/IOSocket.ts@@ -47,9 +47,11 @@ export enum IOSocketListenType {const defaultConfig = {url: '',- heartbeatTime: 1000 * 6,+ heartbeatTime: 1000 * 30,};+export const HEART_BEAT_MESSAGE = 'heart_beat_message';+/*** IOSocket send body*/@@ -68,17 +70,18 @@ export class IOSocket {private _socket: WebSocket;constructor(config: IOSocketConfig) {- const setting = extend(- {},- defaultConfig,- config- ) as Required<IOSocketConfig>;+ const setting = Object.assign(defaultConfig, config);+ // const setting = extend(+ // {},+ // defaultConfig,+ // config+ // ) as Required<IOSocketConfig>;if (isBlank(setting.url)) {throw new Error('url must be input');}this._listens = new Map();this._timer = -1;- this._config = config;+ this._config = setting;}private _create(): void {@@ -87,10 +90,34 @@ export class IOSocket {}private _bind(): void {- this._socket.addEventListener(IOSocketListenType.MESSAGE, this._message);- this._socket.addEventListener(IOSocketListenType.OPEN, this._open);- this._socket.addEventListener(IOSocketListenType.CLOSE, this._close);- this._socket.addEventListener(IOSocketListenType.ERROR, this._error);+ this._socket.addEventListener(+ IOSocketListenType.MESSAGE,+ this._message.bind(this)+ );+ this._socket.addEventListener(+ IOSocketListenType.OPEN,+ this._open.bind(this)+ );+ this._socket.addEventListener(+ IOSocketListenType.CLOSE,+ this._close.bind(this)+ );+ this._socket.addEventListener(+ IOSocketListenType.ERROR,+ this._error.bind(this)+ );+ // this._socket.addEventListener(IOSocketListenType.MESSAGE, (event: Event) => {+ // this._message(event);+ // });+ // this._socket.addEventListener(IOSocketListenType.OPEN, (event: Event) => {+ // this._open(event);+ // });+ // this._socket.addEventListener(IOSocketListenType.CLOSE, (event: Event) => {+ // this._close(event);+ // });+ // this._socket.addEventListener(IOSocketListenType.ERROR, (event: Event) => {+ // this._error(event);+ // });}private _message(event: Event): void {@@ -129,18 +156,30 @@ export class IOSocket {clearInterval(this._timer);}this._timer = -1;- this._socket.removeEventListener(IOSocketListenType.MESSAGE, this._message);- this._socket.removeEventListener(IOSocketListenType.OPEN, this._open);- this._socket.removeEventListener(IOSocketListenType.CLOSE, this._close);- this._socket.removeEventListener(IOSocketListenType.ERROR, this._error);- this._socket.close();+ this._socket.removeEventListener(+ IOSocketListenType.MESSAGE,+ this._message.bind(this)+ );+ this._socket.removeEventListener(+ IOSocketListenType.OPEN,+ this._open.bind(this)+ );+ this._socket.removeEventListener(+ IOSocketListenType.CLOSE,+ this._close.bind(this)+ );+ this._socket.removeEventListener(+ IOSocketListenType.ERROR,+ this._error.bind(this)+ );+ // this._socket.close();}private _heartbeat(): void {const { _socket, _config } = this;const { heartbeatTime } = _config;function handle() {- _socket.send('heartbea_message');+ _socket.send(HEART_BEAT_MESSAGE);}this._timer = setInterval(handle, heartbeatTime) as unknown as number;}@@ -173,7 +212,7 @@ export class IOSocket {this._listens.clear();}- on(type: string, listen: Function): void {- this._listens[type] = listen;+ on(type: IOSocketListenType, listen: Function): void {+ this._listens.set(type, listen);}}