Skip to content

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.

feat(register): add common plugin register

Dushusir1d87389f1714
diff --git a/packages/base-sheets/package.json b/packages/base-sheets/package.json
index 7431651477..906001a80d 100644
--- a/packages/base-sheets/package.json
+++ b/packages/base-sheets/package.json
@@ -52,6 +52,7 @@
"@univer/base-component": "workspace:^0.0.1",
"@univer/base-render": "workspace:^0.0.1",
"@univer/common-plugin-data": "workspace:^0.0.1",
+ "@univer/common-plugin-register": "workspace:^0.0.1",
"@univer/core": "workspace:^0.0.1",
"@univer/sheets-plugin-clipboard": "workspace:^0.0.1",
"@univer/sheets-plugin-formula": "workspace:^0.0.1",
diff --git a/packages/base-sheets/src/Controller/CellEditorController.ts b/packages/base-sheets/src/Controller/CellEditorController.ts
index 52d0c95464..ba5d60750f 100644
--- a/packages/base-sheets/src/Controller/CellEditorController.ts
+++ b/packages/base-sheets/src/Controller/CellEditorController.ts
@@ -1,3 +1,4 @@
+import { RegisterPlugin, REGISTER_PLUGIN_NAME } from '@univer/common-plugin-register';
import { getRefElement, handleDomToJson, handleJsonToDom, handleStyleToString, handleStringToStyle, $$, setLastCaretPosition } from '@univer/base-component';
import { Direction, IDocumentData, IRangeData, IStyleData, Nullable, ICellData, Tools, isKeyPrintable, PLUGIN_NAMES } from '@univer/core';
import { DeviceType, IKeyboardEvent, IMouseEvent, IPointerEvent } from '@univer/base-render';
@@ -160,6 +161,16 @@ export class CellEditorController {
this._plugin.getObserver('onSpreadsheetKeyCompositionUpdateObservable')?.add((evt: IKeyboardEvent) => {});
this._plugin.getObserver('onSpreadsheetKeyCompositionEndObservable')?.add((evt: IKeyboardEvent) => {});
+ this._plugin.getObserver('onSpreadsheetKeyPasteObservable')?.add((e) => {
+ console.log('cell edit onSpreadsheetKeyPasteObservable====', e);
+ const clipboardExtensionManager = this._plugin
+ .getContext()
+ .getPluginManager()
+ .getRequirePluginByName<RegisterPlugin>(REGISTER_PLUGIN_NAME)
+ .getClipboardExtensionManager();
+ // clipboardExtensionManager.handle()
+ });
+
this._cellEditExtensionManager = new CellEditExtensionManager();
}
diff --git a/packages/base-sheets/src/Controller/ToolBarController.ts b/packages/base-sheets/src/Controller/ToolBarController.ts
index 5e007dba77..77adf56209 100644
--- a/packages/base-sheets/src/Controller/ToolBarController.ts
+++ b/packages/base-sheets/src/Controller/ToolBarController.ts
@@ -82,7 +82,7 @@ export class ToolBarController {
const verticalAlignModeItem = this._toolList.find((item) => item.name === 'verticalAlignMode');
if (strikethroughItem) {
- strikethroughItem.active = !!strikeThrough.s;
+ strikethroughItem.active = !!(strikeThrough && strikeThrough.s);
}
if (fontNameItem) {
fontNameItem.children?.forEach((item) => {
@@ -101,7 +101,7 @@ export class ToolBarController {
fontItalicItem.active = !!fontItalic;
}
if (underlineItem) {
- underlineItem.active = !!underline.s;
+ underlineItem.active = !!(underline && underline.s);
}
if (horizontalAlignModeItem) {
horizontalAlignModeItem.children?.forEach((item) => {
@@ -214,7 +214,6 @@ export class ToolBarController {
show: config.fontSize,
name: 'fontSize',
onClick: (fontSize: number) => {
- debugger;
this._plugin.getObserver('onAfterChangeFontSizeObservable')?.notifyObservers(fontSize);
},
onKeyUp: (fontSize: number) => {
diff --git a/packages/base-sheets/src/SheetPlugin.tsx b/packages/base-sheets/src/SheetPlugin.tsx
index 0778f29c01..54282fa097 100644
--- a/packages/base-sheets/src/SheetPlugin.tsx
+++ b/packages/base-sheets/src/SheetPlugin.tsx
@@ -91,7 +91,7 @@ export class SheetPlugin extends Plugin<SheetPluginObserve, SheetContext> {
private _componentList: Map<string, any>;
- protected _namedRangeActionExtensionFactory: NamedRangeInsertRowActionExtensionFactory;
+ private _namedRangeActionExtensionFactory: NamedRangeInsertRowActionExtensionFactory;
constructor(config: Partial<ISheetPluginConfig> = {}) {
super(PLUGIN_NAMES.SPREADSHEET);
diff --git a/packages/base-sheets/src/main.tsx b/packages/base-sheets/src/main.tsx
index 31a37c18e3..da381495fe 100644
--- a/packages/base-sheets/src/main.tsx
+++ b/packages/base-sheets/src/main.tsx
@@ -5,6 +5,7 @@ import { ClipboardPlugin } from '@univer/sheets-plugin-clipboard';
import { NumfmtPlugin } from '@univer/sheets-plugin-numfmt';
import { DEFAULT_FORMULA_DATA, FormulaPlugin } from '@univer/sheets-plugin-formula';
import { DEFAULT_WORKBOOK_DATA, DEFAULT_WORKBOOK_DATA_DOWN } from '@univer/common-plugin-data';
+import { RegisterPlugin } from '@univer/common-plugin-register';
import { SheetPlugin } from './SheetPlugin';
const uiDefaultConfigUp = {
@@ -19,7 +20,7 @@ const uiDefaultConfigUp = {
numberDecrease: false,
numberIncrease: false,
moreFormats: false,
- }
+ },
},
selections: {
'sheet-01': [
@@ -96,8 +97,10 @@ univerSheetUp.installPlugin(new RenderEngine());
univerSheetUp.installPlugin(new UniverComponentSheet());
let sheetPlugin = new SheetPlugin(uiDefaultConfigUp);
+
let clipboardPlugin = new ClipboardPlugin();
univerSheetUp.installPlugin(sheetPlugin);
+univerSheetUp.installPlugin(new RegisterPlugin());
univerSheetUp.installPlugin(clipboardPlugin);
univerSheetUp.installPlugin(new NumfmtPlugin());
FormulaPlugin.create(DEFAULT_FORMULA_DATA).installTo(univerSheetUp);
@@ -129,6 +132,5 @@ univerSheetDown.installPlugin(new RenderEngine());
univerSheetDown.installPlugin(new UniverComponentSheet());
univerSheetDown.installPlugin(new SheetPlugin(uiDefaultConfigDown));
-univerSheetDown.installPlugin(new ClipboardPlugin());
univerSheetDown.installPlugin(new NumfmtPlugin());
// FormulaPlugin.create(DEFAULT_FORMULA_DATA_DOWN).installTo(univerSheetDown);
diff --git a/packages/common-plugin-register/.eslintrc.js b/packages/common-plugin-register/.eslintrc.js
new file mode 100644
index 0000000000..7f4cf3e7ba
--- /dev/null
+++ b/packages/common-plugin-register/.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-register/.gitignore b/packages/common-plugin-register/.gitignore
new file mode 100644
index 0000000000..12e1bd6bec
--- /dev/null
+++ b/packages/common-plugin-register/.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.local
diff --git a/packages/common-plugin-register/.prettierrc.cjs b/packages/common-plugin-register/.prettierrc.cjs
new file mode 100644
index 0000000000..6604107223
--- /dev/null
+++ b/packages/common-plugin-register/.prettierrc.cjs
@@ -0,0 +1,7 @@
+module.exports = {
+ singleQuote: true,
+ trailingComma: 'es5',
+ tabWidth: 4,
+ semi: true,
+ printWidth: 180,
+};
diff --git a/packages/common-plugin-register/README-zh.md b/packages/common-plugin-register/README-zh.md
new file mode 100644
index 0000000000..5edddb534c
--- /dev/null
+++ b/packages/common-plugin-register/README-zh.md
@@ -0,0 +1,55 @@
+# style-universheet
+
+简体中文 | [English](./README.md)
+
+## 介绍
+
+UniverSheet Register插件
+
+### 安装
+
+```bash
+npm i @univer/common-plugin-register
+```
+
+### 使用
+
+```js
+impport {Register} from '@univer/common-plugin-register'
+
+const univerSheet = new UniverSheet();
+univerSheet.installPlugin(new Register());
+```
+
+## 本地开发
+
+### 环境
+
+- [Node.js](https://nodejs.org/en/) Version >= 10
+- [npm](https://www.npmjs.com/) Version >= 6
+
+### 安装
+
+```
+pnpm install
+```
+
+### 开发
+
+```
+# 当前目录 ./packages/common-plugin-register/
+npm run dev
+
+# 或者项目根目录 ./
+pnpm run --filter @univer/common-plugin-register dev
+```
+
+### 打包
+
+```
+# 当前目录 ./packages/common-plugin-register/
+npm run build
+
+# 或者根目录 ./
+pnpm run --filter @univer/common-plugin-register build
+```
diff --git a/packages/common-plugin-register/README.md b/packages/common-plugin-register/README.md
new file mode 100644
index 0000000000..93d5dc081a
--- /dev/null
+++ b/packages/common-plugin-register/README.md
@@ -0,0 +1,55 @@
+# style-universheet
+
+English| [简体中文](./README-zh.md)
+
+## Introduction
+
+UniverSheet Plugin Register
+
+### Installation
+
+```bash
+npm i @univer/common-plugin-register
+```
+
+### Usage
+
+```js
+impport {Register} from '@univer/common-plugin-register'
+
+const univerSheet = new UniverSheet();
+univerSheet.installPlugin(new Register());
+```
+
+## 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-register/
+npm run dev
+
+# Or project root directory ./
+pnpm run --filter @univer/common-plugin-register dev
+```
+
+### Package
+
+```
+# Current directory ./packages/common-plugin-register/
+npm run build
+
+# Or root directory ./
+pnpm run --filter @univer/common-plugin-register build
+```
diff --git a/packages/common-plugin-register/index.html b/packages/common-plugin-register/index.html
new file mode 100644
index 0000000000..87007e935e
--- /dev/null
+++ b/packages/common-plugin-register/index.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<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>Univer</title>
+ <style>
+ html,
+ body {
+ height: 100%;
+ margin: 0;
+ }
+ </style>
+</head>
+
+<body>
+ <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 file
diff --git a/packages/common-plugin-register/jest.config.js b/packages/common-plugin-register/jest.config.js
new file mode 100644
index 0000000000..73ef4bae42
--- /dev/null
+++ b/packages/common-plugin-register/jest.config.js
@@ -0,0 +1,18 @@
+/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
+module.exports = {
+ 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-register/package.json b/packages/common-plugin-register/package.json
new file mode 100644
index 0000000000..0df5d7fe26
--- /dev/null
+++ b/packages/common-plugin-register/package.json
@@ -0,0 +1,61 @@
+{
+ "name": "@univer/common-plugin-register",
+ "version": "0.0.1",
+ "description": "UniverSheet normal common-plugin-register",
+ "keywords": [],
+ "author": "DreamNum <[email protected]>",
+ "license": "MIT",
+ "main": "./lib/univer-common-plugin-register.cjs.js",
+ "module": "./lib/univer-common-plugin-register.es.js",
+ "browser": {
+ "./lib/univer-common-plugin-register.cjs.js": "./src/index.ts",
+ "./lib/univer-common-plugin-register.es.js": "./src/index.ts"
+ },
+ "types": "./src/Types/index.d.ts",
+ "exports": {
+ ".": {
+ "import": {
+ "node": "./lib/univer-common-plugin-register.cjs.js",
+ "default": "./lib/univer-common-plugin-register.es.js"
+ },
+ "require": "./lib/univer-common-plugin-register.cjs.js",
+ "types": "./lib/univer-common-plugin-register.d.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/core": "workspace:^0.0.1"
+ }
+}
diff --git a/packages/common-plugin-register/src/Basic/Const/PLUGIN_NAME.ts b/packages/common-plugin-register/src/Basic/Const/PLUGIN_NAME.ts
new file mode 100644
index 0000000000..003ecdf0da
--- /dev/null
+++ b/packages/common-plugin-register/src/Basic/Const/PLUGIN_NAME.ts
@@ -0,0 +1 @@
+export const REGISTER_PLUGIN_NAME = 'register';
diff --git a/packages/common-plugin-register/src/Basic/Const/index.ts b/packages/common-plugin-register/src/Basic/Const/index.ts
new file mode 100644
index 0000000000..0dc96d927a
--- /dev/null
+++ b/packages/common-plugin-register/src/Basic/Const/index.ts
@@ -0,0 +1 @@
+export * from './PLUGIN_NAME';
diff --git a/packages/common-plugin-register/src/Basic/Enum/index.ts b/packages/common-plugin-register/src/Basic/Enum/index.ts
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/packages/common-plugin-register/src/Basic/Interfaces/IClipboardData.ts b/packages/common-plugin-register/src/Basic/Interfaces/IClipboardData.ts
new file mode 100644
index 0000000000..3b3612ed44
--- /dev/null
+++ b/packages/common-plugin-register/src/Basic/Interfaces/IClipboardData.ts
@@ -0,0 +1,4 @@
+export interface IClipboardData {
+ plain?: string;
+ html?: string;
+}
diff --git a/packages/common-plugin-register/src/Basic/Interfaces/index.ts b/packages/common-plugin-register/src/Basic/Interfaces/index.ts
new file mode 100644
index 0000000000..f1dd2baf98
--- /dev/null
+++ b/packages/common-plugin-register/src/Basic/Interfaces/index.ts
@@ -0,0 +1,3 @@
+// @index(['./*.ts','./**/index.ts'], f => `export * from '${f.path}'`)
+export * from './IClipboardData';
+// @endindex
diff --git a/packages/common-plugin-register/src/Basic/Register/Clipboard/ClipboardExtensionFactory.ts b/packages/common-plugin-register/src/Basic/Register/Clipboard/ClipboardExtensionFactory.ts
new file mode 100644
index 0000000000..175bd08088
--- /dev/null
+++ b/packages/common-plugin-register/src/Basic/Register/Clipboard/ClipboardExtensionFactory.ts
@@ -0,0 +1,55 @@
+import { IClipboardData } from './../../Interfaces/IClipboardData';
+import { IKeyValue, Plugin } from '@univer/core';
+
+/**
+ * 转化table html/json为json
+ */
+export class BaseClipboardExtension {
+ protected _json: IKeyValue;
+ constructor(protected _data: IClipboardData) {}
+
+ getJSON(): IKeyValue {
+ return this._json;
+ }
+
+ /**
+ * Modify the value
+ */
+ setJSON(json: IKeyValue) {
+ this._json = json;
+ }
+
+ /**
+ * Execute the core logic after the check is successful
+ */
+ execute() {}
+}
+
+/**
+ * Determine whether to intercept and create BaseClipboardExtension
+ */
+export class BaseClipboardExtensionFactory<T extends Plugin = Plugin> {
+ constructor(protected _plugin: T) {}
+
+ get zIndex() {
+ return 0;
+ }
+
+ /**
+ * Generate Extension
+ * @param data
+ * @returns
+ */
+ create(data: IClipboardData): BaseClipboardExtension {
+ return new BaseClipboardExtension(data);
+ }
+
+ /**
+ * Check if this cell needs to be intercepted currently
+ * @param data
+ * @returns
+ */
+ check(data: IClipboardData): false | BaseClipboardExtension {
+ return false;
+ }
+}
diff --git a/packages/common-plugin-register/src/Basic/Register/Clipboard/ClipboardExtensionManager.ts b/packages/common-plugin-register/src/Basic/Register/Clipboard/ClipboardExtensionManager.ts
new file mode 100644
index 0000000000..f8e527d0b1
--- /dev/null
+++ b/packages/common-plugin-register/src/Basic/Register/Clipboard/ClipboardExtensionManager.ts
@@ -0,0 +1,55 @@
+import { IClipboardData } from '../../Interfaces/IClipboardData';
+import { BaseClipboardExtension, BaseClipboardExtensionFactory } from './ClipboardExtensionFactory';
+import { ClipboardExtensionRegister } from './ClipboardExtensionRegister';
+
+export class ClipboardExtensionManager {
+ private _clipboardExtensionFactoryList: Array<BaseClipboardExtensionFactory>;
+
+ // mounted on the instance
+ private _register: ClipboardExtensionRegister;
+
+ getRegister(): ClipboardExtensionRegister {
+ return this._register;
+ }
+
+ constructor() {
+ this._register = new ClipboardExtensionRegister();
+ }
+
+ /**
+ * inject all actions
+ * @param command
+ */
+ handle(data: IClipboardData) {
+ const clipboardExtensionFactoryList = this._register?.clipboardExtensionFactoryList;
+ if (!clipboardExtensionFactoryList) return;
+ // get the sorted list
+ // get the dynamically added list
+ this._clipboardExtensionFactoryList = clipboardExtensionFactoryList;
+
+ const extension = this._checkExtension(data);
+ if (extension) {
+ extension.execute();
+ return extension.getJSON();
+ }
+ }
+
+ /**
+ * Execute when the action is matched
+ * @param command
+ * @returns
+ */
+ private _checkExtension(data: IClipboardData) {
+ if (!this._clipboardExtensionFactoryList) return false;
+
+ let extension: BaseClipboardExtension | false = false;
+ for (let index = 0; index < this._clipboardExtensionFactoryList.length; index++) {
+ const extensionFactory = this._clipboardExtensionFactoryList[index];
+ extension = extensionFactory.check(data);
+ if (extension !== false) {
+ break;
+ }
+ }
+ return extension;
+ }
+}
diff --git a/packages/common-plugin-register/src/Basic/Register/Clipboard/ClipboardExtensionRegister.ts b/packages/common-plugin-register/src/Basic/Register/Clipboard/ClipboardExtensionRegister.ts
new file mode 100644
index 0000000000..4e0c100977
--- /dev/null
+++ b/packages/common-plugin-register/src/Basic/Register/Clipboard/ClipboardExtensionRegister.ts
@@ -0,0 +1,21 @@
+import { sortRules } from '@univer/core';
+import { IClipboardData } from '../../Interfaces/IClipboardData';
+import { BaseClipboardExtensionFactory } from './ClipboardExtensionFactory';
+
+export class ClipboardExtensionRegister {
+ private _clipboardExtensionFactoryList: Array<BaseClipboardExtensionFactory> = [];
+
+ get clipboardExtensionFactoryList(): Array<BaseClipboardExtensionFactory> {
+ return this._clipboardExtensionFactoryList;
+ }
+
+ add(...extensionFactoryList: Array<BaseClipboardExtensionFactory>) {
+ this._clipboardExtensionFactoryList.push(...extensionFactoryList);
+ this._clipboardExtensionFactoryList.sort(sortRules);
+ }
+
+ delete(extensionFactory: BaseClipboardExtensionFactory) {
+ const index = this._clipboardExtensionFactoryList.indexOf(extensionFactory);
+ this._clipboardExtensionFactoryList.splice(index, 1);
+ }
+}
diff --git a/packages/common-plugin-register/src/Basic/Register/Clipboard/index.ts b/packages/common-plugin-register/src/Basic/Register/Clipboard/index.ts
new file mode 100644
index 0000000000..208ec47832
--- /dev/null
+++ b/packages/common-plugin-register/src/Basic/Register/Clipboard/index.ts
@@ -0,0 +1,6 @@
+// @index(['./*.ts','./**/index.ts'], f => `export * from '${f.path}'`)
+
+export * from './ClipboardExtensionFactory';
+export * from './ClipboardExtensionManager';
+export * from './ClipboardExtensionRegister';
+// @endindex
diff --git a/packages/common-plugin-register/src/Basic/Register/index.ts b/packages/common-plugin-register/src/Basic/Register/index.ts
new file mode 100644
index 0000000000..d1ac56a376
--- /dev/null
+++ b/packages/common-plugin-register/src/Basic/Register/index.ts
@@ -0,0 +1,3 @@
+// @index(['./*.ts','./**/index.ts'], f => `export * from '${f.path}'`)
+export * from './Clipboard/index';
+// @endindex
diff --git a/packages/common-plugin-register/src/Basic/Shared/index.ts b/packages/common-plugin-register/src/Basic/Shared/index.ts
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/packages/common-plugin-register/src/Basic/index.ts b/packages/common-plugin-register/src/Basic/index.ts
new file mode 100644
index 0000000000..e5d7abda99
--- /dev/null
+++ b/packages/common-plugin-register/src/Basic/index.ts
@@ -0,0 +1,8 @@
+// @index(['./*.ts','./**/index.ts'], f => `export * from '${f.path}'`)
+export * from './Const/index';
+export * from './Enum/index';
+export * from './Interfaces/index';
+export * from './Register/Clipboard/index';
+export * from './Register/index';
+export * from './Shared/index';
+// @endindex
diff --git a/packages/common-plugin-register/src/Locale/en.ts b/packages/common-plugin-register/src/Locale/en.ts
new file mode 100644
index 0000000000..9b93414d00
--- /dev/null
+++ b/packages/common-plugin-register/src/Locale/en.ts
@@ -0,0 +1,8 @@
+export default {
+ register: {
+ tooltip: 'Register',
+ one:'one',
+ two:'two',
+ three:'three',
+ },
+};
diff --git a/packages/common-plugin-register/src/Locale/index.ts b/packages/common-plugin-register/src/Locale/index.ts
new file mode 100644
index 0000000000..3ac4bcd0fd
--- /dev/null
+++ b/packages/common-plugin-register/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-register/src/Locale/zh.ts b/packages/common-plugin-register/src/Locale/zh.ts
new file mode 100644
index 0000000000..fe0cab6665
--- /dev/null
+++ b/packages/common-plugin-register/src/Locale/zh.ts
@@ -0,0 +1,8 @@
+export default {
+ register: {
+ tooltip: 'Register',
+ one:'一',
+ two:'二',
+ three:'三',
+ },
+};
diff --git a/packages/common-plugin-register/src/Model/index.ts b/packages/common-plugin-register/src/Model/index.ts
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/packages/common-plugin-register/src/RegisterPlugin.tsx b/packages/common-plugin-register/src/RegisterPlugin.tsx
new file mode 100644
index 0000000000..2640044635
--- /dev/null
+++ b/packages/common-plugin-register/src/RegisterPlugin.tsx
@@ -0,0 +1,52 @@
+import { Plugin, UniverSheet, UniverDoc, UniverSlide } from '@univer/core';
+import { zh, en } from './Locale';
+import { REGISTER_PLUGIN_NAME } from './Basic/Const/PLUGIN_NAME';
+import { ClipboardExtensionManager } from './Basic/Register';
+
+export class RegisterPlugin extends Plugin {
+ private _clipboardExtensionManager: ClipboardExtensionManager;
+
+ constructor() {
+ super(REGISTER_PLUGIN_NAME);
+ }
+
+ static create() {
+ return new RegisterPlugin();
+ }
+
+ installTo(univerInstance: UniverSheet | UniverDoc | UniverSlide) {
+ univerInstance.installPlugin(this);
+ }
+
+ initialize(): void {
+ const context = this.getContext();
+
+ /**
+ * load more Locale object
+ */
+ context.getLocale().load({
+ en,
+ zh,
+ });
+
+ this.setExtensionManager();
+ }
+
+ setExtensionManager() {
+ this._clipboardExtensionManager = new ClipboardExtensionManager();
+ }
+
+ /**
+ * usage this._clipboardExtensionManager.handle(data);
+ * @returns
+ */
+ getClipboardExtensionManager(): ClipboardExtensionManager {
+ return this._clipboardExtensionManager;
+ }
+
+ onMounted(): void {
+ this.initialize();
+ }
+
+ onDestroy(): void {}
+}
diff --git a/packages/common-plugin-register/src/Service/index.ts b/packages/common-plugin-register/src/Service/index.ts
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/packages/common-plugin-register/src/Types/index.d.ts b/packages/common-plugin-register/src/Types/index.d.ts
new file mode 100644
index 0000000000..91f1f64fc8
--- /dev/null
+++ b/packages/common-plugin-register/src/Types/index.d.ts
@@ -0,0 +1,10 @@
+/// <reference types="vite/client" />
+
+export * from '../index';
+declare module '@univer/common-plugin-register' {}
+
+// use css module
+declare module '*.less' {
+ const resource: { [key: string]: string };
+ export = resource;
+}
diff --git a/packages/common-plugin-register/src/Types/preact.d.ts b/packages/common-plugin-register/src/Types/preact.d.ts
new file mode 100644
index 0000000000..0d092b3751
--- /dev/null
+++ b/packages/common-plugin-register/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-register/src/View/Render/index.ts b/packages/common-plugin-register/src/View/Render/index.ts
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/packages/common-plugin-register/src/View/UI/index.ts b/packages/common-plugin-register/src/View/UI/index.ts
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/packages/common-plugin-register/src/index.ts b/packages/common-plugin-register/src/index.ts
new file mode 100644
index 0000000000..099c04bc67
--- /dev/null
+++ b/packages/common-plugin-register/src/index.ts
@@ -0,0 +1,4 @@
+export * from './Basic';
+import { RegisterPlugin } from './RegisterPlugin';
+
+export { RegisterPlugin };
diff --git a/packages/common-plugin-register/tsconfig.json b/packages/common-plugin-register/tsconfig.json
new file mode 100644
index 0000000000..fc81cbd47e
--- /dev/null
+++ b/packages/common-plugin-register/tsconfig.json
@@ -0,0 +1,31 @@
+{
+ "compilerOptions": {
+ "rootDir": "./",
+ "outDir": "lib",
+ "target": "ESNext",
+
+ "lib": ["ESNext", "DOM", "WebWorker"],
+ "module": "ESNext",
+ "moduleResolution": "Node", //This value is needed for Node.js.
+
+ "declaration": true,
+ "declarationDir": "./lib",
+ "declarationMap": true,
+ "sourceMap": true,
+ "resolveJsonModule": true,
+ "strict": true,
+ "allowJs": true,
+
+ "baseUrl": "./",
+ "skipLibCheck": true,
+ "esModuleInterop": true, // auto allowSyntheticDefaultImports tru
+ "suppressImplicitAnyIndexErrors": true,
+ "experimentalDecorators": true,
+ "jsx": "preserve",
+ "jsxFactory": "h",
+ "jsxFragmentFactory": "Fragment",
+ "strictPropertyInitialization": false,
+ "types": ["jest", "node", "@types/jest"]
+ },
+ "include": ["src/**/*", "test/**/*.test.(ts|tsx|js)"]
+}
diff --git a/packages/common-plugin-register/tsconfig.ref.json b/packages/common-plugin-register/tsconfig.ref.json
new file mode 100644
index 0000000000..0c86b2c554
--- /dev/null
+++ b/packages/common-plugin-register/tsconfig.ref.json
@@ -0,0 +1,7 @@
+{
+ "extends": "./tsconfig.json",
+ "include": ["src/**/*"],
+ "compilerOptions": {
+ "composite": true
+ }
+}
diff --git a/packages/common-plugin-register/tsconfig.test.json b/packages/common-plugin-register/tsconfig.test.json
new file mode 100644
index 0000000000..a2ac02c4ae
--- /dev/null
+++ b/packages/common-plugin-register/tsconfig.test.json
@@ -0,0 +1,7 @@
+{
+ "extends": "./tsconfig.json",
+ "compilerOptions": {
+ "jsx": "react-jsx",
+ "jsxImportSource": "preact"
+ }
+}
diff --git a/packages/common-plugin-register/vite.config.ts b/packages/common-plugin-register/vite.config.ts
new file mode 100644
index 0000000000..020ecd6209
--- /dev/null
+++ b/packages/common-plugin-register/vite.config.ts
@@ -0,0 +1,44 @@
+import { defineConfig } from 'vite';
+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: 'BaseStyleUniver',
+ // formats: ['es', 'umd'],
+ // fileName: 'index',
+ // },
+ // outDir: './lib',
+ },
+ define: {
+ pkgJson: { name, version },
+ },
+ css: {
+ modules: {
+ 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/sheets-plugin-clipboard/package.json b/packages/sheets-plugin-clipboard/package.json
index 55fd53c8c9..1808272486 100644
--- a/packages/sheets-plugin-clipboard/package.json
+++ b/packages/sheets-plugin-clipboard/package.json
@@ -46,6 +46,7 @@
"@univer/base-render": "workspace:^0.0.1",
"@univer/base-sheets": "workspace:^0.0.1",
"@univer/common-plugin-data": "workspace:^0.0.1",
+ "@univer/common-plugin-register": "workspace:^0.0.1",
"@univer/core": "workspace:^0.0.1",
"@univer/sheets-plugin-conditional-format": "workspace:^0.0.1",
"@univer/style-universheet": "workspace:^0.0.1",
diff --git a/packages/sheets-plugin-clipboard/src/Basics/Register/ClipboardExtension.ts b/packages/sheets-plugin-clipboard/src/Basics/Register/ClipboardExtension.ts
new file mode 100644
index 0000000000..e9aead786a
--- /dev/null
+++ b/packages/sheets-plugin-clipboard/src/Basics/Register/ClipboardExtension.ts
@@ -0,0 +1,22 @@
+import { BaseClipboardExtension, BaseClipboardExtensionFactory, IClipboardData } from '@univer/common-plugin-register';
+import { ClipboardPlugin } from '../../ClipboardPlugin';
+
+export class ClipboardExtension extends BaseClipboardExtension {
+ execute() {}
+}
+
+export class ClipboardExtensionFactory extends BaseClipboardExtensionFactory<ClipboardPlugin> {
+ get zIndex(): number {
+ return 1;
+ }
+
+ create(data: IClipboardData): BaseClipboardExtension {
+ return new ClipboardExtension(data);
+ }
+
+ check(data: IClipboardData): false | BaseClipboardExtension {
+ console.log('截获data', data);
+
+ return false;
+ }
+}
diff --git a/packages/sheets-plugin-clipboard/src/ClipboardPlugin.tsx b/packages/sheets-plugin-clipboard/src/ClipboardPlugin.tsx
index 088844f711..73ff938932 100644
--- a/packages/sheets-plugin-clipboard/src/ClipboardPlugin.tsx
+++ b/packages/sheets-plugin-clipboard/src/ClipboardPlugin.tsx
@@ -1,7 +1,9 @@
import { SheetContext, Plugin, UniverSheet } from '@univer/core';
+import { RegisterPlugin, REGISTER_PLUGIN_NAME } from '@univer/common-plugin-register';
import { en, zh } from './Locale';
import { CLIPBOARD_PLUGIN } from './Const';
import { Copy, UniverCopy, Paste, UniverPaste } from './Domain';
+import { ClipboardExtensionFactory } from './Basics/Register/ClipboardExtension';
interface CopyResolver {
name: string;
@@ -18,6 +20,8 @@ export class ClipboardPlugin extends Plugin<any, SheetContext> {
private _pasteResolvers: PasteResolver[] = [];
+ private _clipboardExtensionFactory: ClipboardExtensionFactory;
+
constructor() {
super(CLIPBOARD_PLUGIN);
}
@@ -26,10 +30,26 @@ export class ClipboardPlugin extends Plugin<any, SheetContext> {
return new ClipboardPlugin();
}
+ initialize() {
+ this.registerExtension();
+ }
+
+ registerExtension() {
+ const clipboardRegister = this.getContext().getPluginManager().getRequirePluginByName<RegisterPlugin>(REGISTER_PLUGIN_NAME).getClipboardExtensionManager().getRegister();
+
+ this._clipboardExtensionFactory = new ClipboardExtensionFactory(this);
+ clipboardRegister.add(this._clipboardExtensionFactory);
+ }
+
installTo(universheetInstance: UniverSheet) {
universheetInstance.installPlugin(this);
}
+ onDestroy(): void {
+ const clipboardRegister = this.getContext().getPluginManager().getRequirePluginByName<RegisterPlugin>(REGISTER_PLUGIN_NAME).getClipboardExtensionManager().getRegister();
+ clipboardRegister.delete(this._clipboardExtensionFactory);
+ }
+
onMounted(context: SheetContext): void {
super.onMounted(context);
context.getLocale().load({
@@ -38,6 +58,7 @@ export class ClipboardPlugin extends Plugin<any, SheetContext> {
});
this.installPasteResolver({ name: 'univerPaste', resolver: new UniverPaste(context) });
this.installCopyResolver({ name: 'univerCopy', resolver: new UniverCopy(context) });
+ this.initialize();
}
installCopyResolver(resolver: CopyResolver) {
diff --git a/packages/sheets-plugin-clipboard/src/Domain/Paste.ts b/packages/sheets-plugin-clipboard/src/Domain/Paste.ts
index ca48c45be7..e2ca297168 100644
--- a/packages/sheets-plugin-clipboard/src/Domain/Paste.ts
+++ b/packages/sheets-plugin-clipboard/src/Domain/Paste.ts
@@ -23,7 +23,7 @@ export abstract class Paste {
this.paste(e);
});
- // TODO 注册机制 Paste, PasteManager.handle() 匹配 WPSPaste/GoogleSheetPaste/ExcelPaste
+ // TODO 注册机制 Paste, PasteManager.handle() 匹配 WpsPaste/GooglePaste/OfficePaste
}
getContext() {
diff --git a/packages/sheets-plugin-clipboard/src/main.tsx b/packages/sheets-plugin-clipboard/src/main.tsx
index dbb819df13..cbab74aed1 100644
--- a/packages/sheets-plugin-clipboard/src/main.tsx
+++ b/packages/sheets-plugin-clipboard/src/main.tsx
@@ -1,8 +1,9 @@
import { UniverSheet } from '@univer/core';
import { RenderEngine } from '@univer/base-render';
-import { DEFAULT_WORKBOOK_DATA } from '@univer/common-plugin-data';
+import { DEFAULT_WORKBOOK_DATA, DEFAULT_WORKBOOK_DATA_DOWN } from '@univer/common-plugin-data';
import { SheetPlugin } from '@univer/base-sheets';
import { UniverComponentSheet } from '@univer/style-universheet';
+import { RegisterPlugin } from '@univer/common-plugin-register';
import { ClipboardPlugin } from './ClipboardPlugin';
const uiDefaultConfigUp = {
@@ -14,4 +15,31 @@ const univerSheetUp = UniverSheet.newInstance(DEFAULT_WORKBOOK_DATA);
univerSheetUp.installPlugin(new RenderEngine());
univerSheetUp.installPlugin(new UniverComponentSheet());
univerSheetUp.installPlugin(new SheetPlugin(uiDefaultConfigUp));
+univerSheetUp.installPlugin(new RegisterPlugin());
univerSheetUp.installPlugin(new ClipboardPlugin());
+
+const uiDefaultConfigDown = {
+ container: 'universheet-demo-down',
+ selections: {
+ 'sheet-0001': [
+ {
+ selection: {
+ startRow: 2,
+ endRow: 2,
+ startColumn: 3,
+ endColumn: 3,
+ },
+ cell: {
+ row: 2,
+ column: 3,
+ },
+ },
+ ],
+ },
+};
+
+const univerSheetDown = UniverSheet.newInstance(DEFAULT_WORKBOOK_DATA_DOWN);
+univerSheetDown.installPlugin(new RenderEngine());
+univerSheetDown.installPlugin(new UniverComponentSheet());
+
+univerSheetDown.installPlugin(new SheetPlugin(uiDefaultConfigDown));
diff --git a/packages/sheets-plugin-formula/src/Controller/CellInputHandler.ts b/packages/sheets-plugin-formula/src/Controller/CellInputHandler.ts
index 535ceb353d..b7fa9fe55c 100644
--- a/packages/sheets-plugin-formula/src/Controller/CellInputHandler.ts
+++ b/packages/sheets-plugin-formula/src/Controller/CellInputHandler.ts
@@ -639,7 +639,7 @@ export class CellInputHandler {
lasttxt = txt.substring(anchorOffset - 1, 1);
return anchor.parentNode;
}
- if (anchor!.parentElement!.className === 'universheet-rich-text-editor') {
+ if (anchor?.parentElement?.className === 'universheet-rich-text-editor') {
// const a = anchor.querySelectorAll('span');
// let txt = anchor.parentElement!.querySelectorAll('span')[anchorLength.length - 1].textContent!.trim();
let txt = anchor.textContent?.trim()!;
diff --git a/tsconfig.json b/tsconfig.json
index 649362b77f..cac8646590 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -18,6 +18,7 @@
{ "path": "./packages/sheets-plugin-sort/tsconfig.ref.json" },
{ "path": "./packages/sheets-plugin-filter/tsconfig.ref.json" },
{ "path": "./packages/sheets-plugin-find/tsconfig.ref.json" },
- { "path": "./packages/sheets-plugin-numfmt/tsconfig.ref.json" }
+ { "path": "./packages/sheets-plugin-numfmt/tsconfig.ref.json" },
+ { "path": "./packages/common-plugin-register/tsconfig.ref.json" }
]
}