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)

Dushusira341315eadf1
diff --git a/.github/contributing-zh.md b/.github/contributing-zh.md
index 54389317c8..e78827e39a 100644
--- a/.github/contributing-zh.md
+++ b/.github/contributing-zh.md
@@ -293,20 +293,41 @@ pnpm install
npm i
```
- 然后再回到主目录运行生成插件的命令
-
2. 运行 cli 命令来选择插件
+ 先确保回到项目主目录
+
+ ```sh
+ cd ..
+ ```
+
+ 再运行生成插件的命令
+
```shell
npm run univer-cli create inner
```
- 其中 create 表示创建一个插件,inner 表示在 Univer 主仓库内部新建插件,也就是放到 packages 文件夹下。如果想在自己电脑的一个空白目录用脚手架新建一个插件,就不用加 inner,运行`npm run univer-cli create`即可。
+ 其中 create 表示创建一个插件,inner 表示在 Univer 主仓库内部新建插件,也就是放到 packages 文件夹下。inner 模式下,还需要项目根目录的 [tsconfig.json](../tsconfig.json) 文件中,增加当前添加插件的引用地址,必须这样写:
+
+ ```json
+ {
+ // 其他配置...
+ "references": [
+ // 已有配置
+ { "path": "./packages/core/tsconfig.ref.json" },
+ { "path": "./packages/base-render/tsconfig.ref.json" },
+ // 新加的配置
+ { "path": "./packages/sheets-plugin-data-validation/tsconfig.ref.json" }
+ ]
+ }
+ ```
+
+ 如果想在自己电脑的一个空白目录用脚手架新建一个插件,就不用加 inner,运行`npm run univer-cli create`即可。
接着选择你想要的模板
- base:基础插件,构建类似 `base-sheets`、`base-docs`、`base-slides` 的插件
- - sheets-plugin:表格插件,构建类似 `sheet-plugin-sort`、`sheet-plugin-data-validation`的插件
+ - sheets-plugin:表格插件,构建类似 `sheets-plugin-sort`、`sheets-plugin-data-validation`的插件
接着再填写你的插件名称,比如填写 `data-validation`,程序将会在 `packages` 文件夹下,生成一个完整的插件模板,比如`packages/sheets-plugin-data-validation`。
diff --git a/examples/univer-vanilla-ts/index.html b/examples/univer-vanilla-ts/index.html
index 80ae2c8850..b3c7260185 100644
--- a/examples/univer-vanilla-ts/index.html
+++ b/examples/univer-vanilla-ts/index.html
@@ -10,9 +10,6 @@
<body>
<div id="universheet-demo-up"></div>
- <!-- <br />
- <hr />
- <br /> -->
<div id="universheet-demo-down"></div>
<div id='app'></div>
<script type="module" src="/src/main.tsx"></script>
diff --git a/examples/univer-vanilla-ts/package.json b/examples/univer-vanilla-ts/package.json
index aab86c9389..7cf30c3d60 100644
--- a/examples/univer-vanilla-ts/package.json
+++ b/examples/univer-vanilla-ts/package.json
@@ -15,11 +15,11 @@
"serve": "vite preview"
},
"devDependencies": {
- "@preact/preset-vite": "^2.1.0",
+ "@preact/preset-vite": "2.0.0",
+ "@testing-library/preact": "^2.0.1",
"@types/jest": "^27.5.2",
"@types/node": "^16.4.6",
"@vitejs/plugin-legacy": "^1.5.1",
- "debug": "^4.3.3",
"enzyme": "^3.11.0",
"enzyme-adapter-preact-pure": "^3.3.0",
"eslint": "^8.22.0",
@@ -35,16 +35,20 @@
"jest-environment-jsdom": "^29.0.3",
"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",
"vite-plugin-external": "1.2.3"
},
"dependencies": {
- "@univer/base-component": "^0.0.1",
"@univer/base-render": "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/common-plugin-data": "workspace:^0.0.1",
- "@univer/core": "^0.0.1",
- "@univer/style-universheet": "^0.0.1",
+ "@univer/core": "workspace:^0.0.1",
+ "@univer/style-universheet": "workspace:^0.0.1",
"preact": "^10.5.14"
}
}
diff --git a/examples/univer-vanilla-ts/src/app.tsx b/examples/univer-vanilla-ts/src/app.tsx
deleted file mode 100644
index e27aded531..0000000000
--- a/examples/univer-vanilla-ts/src/app.tsx
+++ /dev/null
@@ -1,7 +0,0 @@
-export function App() {
- return (
- <>
- <div>按钮</div>
- </>
- )
-}
\ No newline at end of file
diff --git a/examples/univer-vanilla-ts/src/index.ts b/examples/univer-vanilla-ts/src/index.ts
new file mode 100644
index 0000000000..b826f399a5
--- /dev/null
+++ b/examples/univer-vanilla-ts/src/index.ts
@@ -0,0 +1,97 @@
+import { IDocumentData, ISlideData, IWorkbookConfig, UniverDoc, UniverSheet, UniverSlide } from '@univer/core';
+import * as UniverCore from '@univer/core'
+import { RenderEngine } from '@univer/base-render';
+import { UniverComponentSheet } from '@univer/style-universheet';
+import { ISheetPluginConfig, SheetPlugin } from '@univer/base-sheets';
+import { IDocPluginConfig, DocPlugin } from '@univer/base-docs';
+import { ISlidePluginConfig, SlidePlugin } from '@univer/base-slides';
+import { DEFAULT_WORKBOOK_DATA } from '@univer/common-plugin-data';
+
+interface ISheetPropsCustom {
+ coreConfig?: Partial<IWorkbookConfig>;
+ baseSheetsConfig?: ISheetPluginConfig;
+}
+
+/**
+ * Initialize the core and all plugins
+ */
+class UniverSheetCustom {
+ constructor() {}
+ init(config: ISheetPropsCustom = {}): UniverSheet {
+ const universheet = UniverSheet.newInstance(config.coreConfig);
+
+ universheet.installPlugin(new RenderEngine());
+ universheet.installPlugin(new UniverComponentSheet());
+ universheet.installPlugin(new SheetPlugin(config.baseSheetsConfig));
+
+ return universheet;
+ }
+}
+/**
+ * Wrapped into a function,easy to use
+ * @param config
+ * @returns
+ */
+const univerSheetCustom = function (config?: ISheetPropsCustom) {
+ return new UniverSheetCustom().init(config);
+};
+
+interface IDocPropsCustom {
+ coreConfig?: Partial<IDocumentData>;
+ baseDocsConfig?: IDocPluginConfig;
+}
+
+/**
+ * Initialize the core and all plugins
+ */
+class UniverDocCustom {
+ constructor() {}
+ init(config: IDocPropsCustom = {}): UniverDoc {
+ const univerdoc = UniverDoc.newInstance(config.coreConfig);
+
+ univerdoc.installPlugin(new RenderEngine());
+ univerdoc.installPlugin(new UniverComponentSheet());
+ univerdoc.installPlugin(new DocPlugin(config.baseDocsConfig));
+
+ return univerdoc;
+ }
+}
+/**
+ * Wrapped into a function,easy to use
+ * @param config
+ * @returns
+ */
+const univerDocCustom = function (config?: IDocPropsCustom) {
+ return new UniverDocCustom().init(config);
+};
+
+interface ISlidePropsCustom {
+ coreConfig?: Partial<ISlideData>;
+ baseSlidesConfig?: ISlidePluginConfig;
+}
+
+/**
+ * Initialize the core and all plugins
+ */
+class UniverSlideCustom {
+ constructor() {}
+ init(config: ISlidePropsCustom = {}): UniverSlide {
+ const universlide = UniverSlide.newInstance(config.coreConfig);
+
+ universlide.installPlugin(new RenderEngine());
+ universlide.installPlugin(new UniverComponentSheet());
+ universlide.installPlugin(new SlidePlugin(config.baseSlidesConfig));
+
+ return universlide;
+ }
+}
+/**
+ * Wrapped into a function,easy to use
+ * @param config
+ * @returns
+ */
+const univerSlideCustom = function (config?: ISlidePropsCustom) {
+ return new UniverSlideCustom().init(config);
+};
+
+export {UniverCore, univerSheetCustom,univerDocCustom,univerSlideCustom, DEFAULT_WORKBOOK_DATA };
diff --git a/examples/univer-vanilla-ts/src/main.tsx b/examples/univer-vanilla-ts/src/main.tsx
index 051f578391..9c7bcc946a 100644
--- a/examples/univer-vanilla-ts/src/main.tsx
+++ b/examples/univer-vanilla-ts/src/main.tsx
@@ -1,4 +1,38 @@
-import { render } from 'preact'
-import { App } from './app'
+import { univerSheetCustom, DEFAULT_WORKBOOK_DATA } from '.';
-render(<App />, document.getElementById('app')!)
+const sheetConfig = {
+ container: 'universheet-demo',
+ layout: {
+ innerRight: false,
+ outerLeft: false,
+ toolBarConfig: {
+ paintFormat: false,
+ currencyFormat: false,
+ percentageFormat: false,
+ numberDecrease: false,
+ numberIncrease: false,
+ moreFormats: false,
+ },
+ },
+ selections: {
+ 'sheet-01': [
+ {
+ selection: {
+ startRow: 0,
+ endRow: 0,
+ startColumn: 3,
+ endColumn: 3,
+ },
+ cell: {
+ row: 0,
+ column: 3,
+ },
+ },
+ ],
+ },
+};
+
+univerSheetCustom({
+ coreConfig: DEFAULT_WORKBOOK_DATA,
+ baseSheetsConfig: sheetConfig,
+});
\ No newline at end of file
diff --git a/examples/univer-vanilla-ts/tsconfig.json b/examples/univer-vanilla-ts/tsconfig.json
index fcb3d64f3c..c9a567bad1 100644
--- a/examples/univer-vanilla-ts/tsconfig.json
+++ b/examples/univer-vanilla-ts/tsconfig.json
@@ -15,13 +15,18 @@
"resolveJsonModule": true,
"strict": true,
"allowJs": true,
+ "downlevelIteration": true,
"baseUrl": "./",
"skipLibCheck": true,
"esModuleInterop": true, // auto allowSyntheticDefaultImports true
"jsx": "preserve",
"jsxFactory": "h",
- "jsxFragmentFactory": "Fragment"
+ "jsxFragmentFactory": "Fragment",
+ "experimentalDecorators": true,
+ "emitDecoratorMetadata": true,
+ "suppressImplicitAnyIndexErrors": true,
+ "strictPropertyInitialization": false,
},
"include": ["src/**/*", "test/**/*.test.(ts|tsx|js)"]
}
diff --git a/examples/univer-vanilla-ts/vite.config.ts b/examples/univer-vanilla-ts/vite.config.ts
index 2349ac9e77..7baa71322a 100644
--- a/examples/univer-vanilla-ts/vite.config.ts
+++ b/examples/univer-vanilla-ts/vite.config.ts
@@ -1,51 +1,52 @@
import { defineConfig } from 'vite';
import path from 'path';
-import legacy from '@vitejs/plugin-legacy';
-import { name, version } from './package.json';
import preact from '@preact/preset-vite';
+import { name, version } from './package.json';
+import createExternal from 'vite-plugin-external';
const resolve = (url: string) => path.resolve(__dirname, url);
export default defineConfig({
build: {
- // lib: {
- // entry: resolve('src/index.ts'),
- // name: 'BaseWebUI',
- // formats: ['es', 'umd'],
- // fileName: 'index',
- // },
- // outDir: './lib',
+ lib: {
+ entry: resolve('src/index.ts'),
+ name: 'UniverVanillaTs',
+ formats: ['es', 'cjs', 'umd', 'iife'],
+ fileName: 'univer-vanilla-ts',
+ },
+ outDir: './lib',
},
define: {
pkgJson: { name, version },
},
- esbuild: {
- // jsxFactory: 'DOMcreateElement',
- // jsxFragment: 'DOMcreateFragment',
- // jsxInject: `import { DOMcreateElement, DOMcreateFragment } from '@/dom-helper/jsxFactory';`,
- },
- resolve: {
- alias: {
- '@': path.resolve(__dirname, 'src'),
- },
- },
css: {
modules: {
localsConvention: 'camelCaseOnly', // dash to camelCase conversion// .apply-color -> applyColor
+ generateScopedName: 'univer-[local]', // custom prefix class name
+ },
+ preprocessorOptions: {
+ less: {
+ javascriptEnabled: true,
+ },
},
},
server: {
- port: 3101,
+ port: 3103,
open: true, // Automatically open the app in the browser on server start.
},
plugins: [
preact(),
- legacy({
- targets: ['ie >= 11'],
- additionalLegacyPolyfills: ['regenerator-runtime/runtime'],
+ // legacy({
+ // targets: ['ie >= 11'],
+ // additionalLegacyPolyfills: ['regenerator-runtime/runtime'],
+ // }),
+ createExternal({
+ externals: {
+ // '@univer/core': '@univer/core',
+ // '@univer/style-universheet': '@univer/style-universheet',
+ // preact: 'preact',
+ // react: 'react',
+ },
}),
-
- // babel(),
- // babel({ babelHelpers: 'bundled' }),
],
});
diff --git a/examples/univer-vanilla-ts/vite.config.ts.timestamp-1669972110421.js b/examples/univer-vanilla-ts/vite.config.ts.timestamp-1669972110421.js
new file mode 100644
index 0000000000..9d60c2ace5
--- /dev/null
+++ b/examples/univer-vanilla-ts/vite.config.ts.timestamp-1669972110421.js
@@ -0,0 +1,51 @@
+// vite.config.ts
+import { defineConfig } from "vite";
+import path from "path";
+import preact from "@preact/preset-vite";
+
+// package.json
+var name = "univer-vanilla-ts";
+var version = "0.0.1";
+
+// vite.config.ts
+import createExternal from "vite-plugin-external";
+var resolve = (url) => path.resolve("D:\\code\\gogs\\univer\\examples\\univer-vanilla-ts", url);
+var vite_config_default = defineConfig({
+ build: {
+ lib: {
+ entry: resolve("src/index.ts"),
+ name: "UniverVanillaTs",
+ formats: ["es", "cjs", "umd", "iife"],
+ fileName: "univer-vanilla-ts"
+ },
+ outDir: "./lib"
+ },
+ define: {
+ pkgJson: { name, version }
+ },
+ css: {
+ modules: {
+ localsConvention: "camelCaseOnly",
+ generateScopedName: "univer-[local]"
+ },
+ preprocessorOptions: {
+ less: {
+ javascriptEnabled: true
+ }
+ }
+ },
+ server: {
+ port: 3103,
+ open: true
+ },
+ plugins: [
+ preact(),
+ createExternal({
+ externals: {}
+ })
+ ]
+});
+export {
+ vite_config_default as default
+};
+//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsidml0ZS5jb25maWcudHMiXSwKICAic291cmNlc0NvbnRlbnQiOiBbImltcG9ydCB7IGRlZmluZUNvbmZpZyB9IGZyb20gJ3ZpdGUnO1xuaW1wb3J0IHBhdGggZnJvbSAncGF0aCc7XG5pbXBvcnQgcHJlYWN0IGZyb20gJ0BwcmVhY3QvcHJlc2V0LXZpdGUnO1xuaW1wb3J0IHsgbmFtZSwgdmVyc2lvbiB9IGZyb20gJy4vcGFja2FnZS5qc29uJztcbmltcG9ydCBjcmVhdGVFeHRlcm5hbCBmcm9tICd2aXRlLXBsdWdpbi1leHRlcm5hbCc7XG5cbmNvbnN0IHJlc29sdmUgPSAodXJsOiBzdHJpbmcpID0+IHBhdGgucmVzb2x2ZShcIkQ6XFxcXGNvZGVcXFxcZ29nc1xcXFx1bml2ZXJcXFxcZXhhbXBsZXNcXFxcdW5pdmVyLXZhbmlsbGEtdHNcIiwgdXJsKTtcblxuZXhwb3J0IGRlZmF1bHQgZGVmaW5lQ29uZmlnKHtcbiAgICBidWlsZDoge1xuICAgICAgICBsaWI6IHtcbiAgICAgICAgICAgIGVudHJ5OiByZXNvbHZlKCdzcmMvaW5kZXgudHMnKSxcbiAgICAgICAgICAgIG5hbWU6ICdVbml2ZXJWYW5pbGxhVHMnLFxuICAgICAgICAgICAgZm9ybWF0czogWydlcycsICdjanMnLCAndW1kJywgJ2lpZmUnXSxcbiAgICAgICAgICAgIGZpbGVOYW1lOiAndW5pdmVyLXZhbmlsbGEtdHMnLFxuICAgICAgICB9LFxuICAgICAgICBvdXREaXI6ICcuL2xpYicsXG4gICAgfSxcbiAgICBkZWZpbmU6IHt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sU0FBUztBQUFBLElBQ0wsT0FBTztBQUFBLElBS1AsZUFBZTtBQUFBLE1BQ1gsV0FBVyxDQUtYO0FBQUEsSUFDSixDQUFDO0FBQUEsRUFDTDtBQUNKLENBQUM7IiwKICAibmFtZXMiOiBbXQp9Cg==
diff --git a/examples/univer-vanilla-ts/vite.config.ts.timestamp-1669972209915.js b/examples/univer-vanilla-ts/vite.config.ts.timestamp-1669972209915.js
new file mode 100644
index 0000000000..9d60c2ace5
--- /dev/null
+++ b/examples/univer-vanilla-ts/vite.config.ts.timestamp-1669972209915.js
@@ -0,0 +1,51 @@
+// vite.config.ts
+import { defineConfig } from "vite";
+import path from "path";
+import preact from "@preact/preset-vite";
+
+// package.json
+var name = "univer-vanilla-ts";
+var version = "0.0.1";
+
+// vite.config.ts
+import createExternal from "vite-plugin-external";
+var resolve = (url) => path.resolve("D:\\code\\gogs\\univer\\examples\\univer-vanilla-ts", url);
+var vite_config_default = defineConfig({
+ build: {
+ lib: {
+ entry: resolve("src/index.ts"),
+ name: "UniverVanillaTs",
+ formats: ["es", "cjs", "umd", "iife"],
+ fileName: "univer-vanilla-ts"
+ },
+ outDir: "./lib"
+ },
+ define: {
+ pkgJson: { name, version }
+ },
+ css: {
+ modules: {
+ localsConvention: "camelCaseOnly",
+ generateScopedName: "univer-[local]"
+ },
+ preprocessorOptions: {
+ less: {
+ javascriptEnabled: true
+ }
+ }
+ },
+ server: {
+ port: 3103,
+ open: true
+ },
+ plugins: [
+ preact(),
+ createExternal({
+ externals: {}
+ })
+ ]
+});
+export {
+ vite_config_default as default
+};
+//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsidml0ZS5jb25maWcudHMiXSwKICAic291cmNlc0NvbnRlbnQiOiBbImltcG9ydCB7IGRlZmluZUNvbmZpZyB9IGZyb20gJ3ZpdGUnO1xuaW1wb3J0IHBhdGggZnJvbSAncGF0aCc7XG5pbXBvcnQgcHJlYWN0IGZyb20gJ0B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QW9CO0FBRTNCLElBQU0sVUFBVSxDQUFDLFFBQWdCLEtBQUssUUFBUSx1REFBdUQsR0FBRztBQUV4RyxJQUFPLHNCQUFRLGFBQWE7QUFBQSxFQUN4QixPQUFPO0FBQUEsSUFDSCxLQUFLO0FBQUEsTUFDRCxPQUFPLFFBQVEsY0FBYztBQUFBLE1BQzdCLE1BQU07QUFBQSxNQUNOLFNBQVMsQ0FBQyxNQUFNLE9BQU8sT0FBTyxNQUFNO0FBQUEsTUFDcEMsVUFBVTtBQUFBLElBQ2Q7QUFBQSxJQUNBLFFBQVE7QUFBQSxFQUNaO0FBQUEsRUFDQSxRQUFRO0FBQUEsSUFDSixTQUFTLEVBQUUsTUFBTSxRQUFRO0FBQUEsRUFDN0I7QUFBQSxFQUNBLEtBQUs7QUFBQSxJQUNELFNBQVM7QUFBQSxNQUNMLGtCQUFrQjtBQUFBLE1BQ2xCLG9CQUFvQjtBQUFBLElBQ3hCO0FBQUEsSUFDQSxxQkFBcUI7QUFBQSxNQUNqQixNQUFNO0FBQUEsUUFDRixtQkFBbUI7QUFBQSxNQUN2QjtBQUFBLElBQ0o7QUFBQSxFQUNKO0FBQUEsRUFDQSxRQUFRO0FBQUEsSUFDSixNQUFNO0FBQUEsSUFDTixNQUFNO0FBQUEsRUFDVjtBQUFBLEVBQ0EsU0FBUztBQUFBLElBQ0wsT0FBTztBQUFBLElBS1AsZUFBZTtBQUFBLE1BQ1gsV0FBVyxDQUtYO0FBQUEsSUFDSixDQUFDO0FBQUEsRUFDTDtBQUNKLENBQUM7IiwKICAibmFtZXMiOiBbXQp9Cg==
diff --git a/package.json b/package.json
index 48db8a4058..b4a61aadd7 100644
--- a/package.json
+++ b/package.json
@@ -10,6 +10,7 @@
"dev": "node scripts/dev",
"dev:doc": "pnpm run --filter @univer/base-docs dev",
"dev:slide": "pnpm run --filter @univer/base-slides dev",
+ "d": "pnpm run --filter univer-vanilla-ts dev",
"api": "node scripts/api",
"lighthouse-dev": "start /B node scripts/dev && lighthouse http://127.0.0.1:3103 --output html --output-path ./report.html",
"build": "node scripts/build.js",
diff --git a/packages/base-sheets/package.json b/packages/base-sheets/package.json
index 906001a80d..7a67bc42cf 100644
--- a/packages/base-sheets/package.json
+++ b/packages/base-sheets/package.json
@@ -55,6 +55,7 @@
"@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-clipboard-office": "workspace:^0.0.1",
"@univer/sheets-plugin-formula": "workspace:^0.0.1",
"@univer/sheets-plugin-numfmt": "workspace:^0.0.1",
"@univer/style-universheet": "workspace:^0.0.1",
diff --git a/packages/base-sheets/src/Controller/CellEditorController.ts b/packages/base-sheets/src/Controller/CellEditorController.ts
index ba5d60750f..8161d62be3 100644
--- a/packages/base-sheets/src/Controller/CellEditorController.ts
+++ b/packages/base-sheets/src/Controller/CellEditorController.ts
@@ -1,4 +1,3 @@
-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';
@@ -161,15 +160,18 @@ 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._plugin.getObserver('onSpreadsheetKeyPasteObservable')?.add((e) => {
+ // console.log('cell edit onSpreadsheetKeyPasteObservable====', e);
+ // const clipboardExtensionManager = this._plugin
+ // .getContext()
+ // .getPluginManager()
+ // .getRequirePluginByName<RegisterPlugin>(REGISTER_PLUGIN_NAME)
+ // .getClipboardExtensionManager();
+
+ // clipboardExtensionManager.pasteResolver(e).then((data: IClipboardData) => {
+ // clipboardExtensionManager.handle(data);
+ // });
+ // });
this._cellEditExtensionManager = new CellEditExtensionManager();
}
diff --git a/packages/base-sheets/src/main.tsx b/packages/base-sheets/src/main.tsx
index 11df54d38f..60b3c78da2 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_WORKBOOK_DATA, DEFAULT_WORKBOOK_DATA_DOWN } from '@univer/common-plugin-data';
import { RegisterPlugin } from '@univer/common-plugin-register';
+import { ClipboardOfficePlugin } from '@univer/sheets-plugin-clipboard-office';
import { SheetPlugin } from './SheetPlugin';
const uiDefaultConfigUp = {
@@ -12,15 +13,16 @@ const uiDefaultConfigUp = {
layout: {
innerRight: false,
outerLeft: false,
+ toolBarConfig: {
+ paintFormat: false,
+ currencyFormat: false,
+ percentageFormat: false,
+ numberDecrease: false,
+ numberIncrease: false,
+ moreFormats: false,
+ },
},
- toolBarConfig: {
- paintFormat: false,
- currencyFormat: false,
- percentageFormat: false,
- numberDecrease: false,
- numberIncrease: false,
- moreFormats: false,
- },
+
selections: {
'sheet-01': [
{
@@ -97,10 +99,10 @@ 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 ClipboardPlugin());
+univerSheetUp.installPlugin(new ClipboardOfficePlugin());
univerSheetUp.installPlugin(new NumfmtPlugin());
// FormulaPlugin.create(DEFAULT_FORMULA_DATA).installTo(univerSheetUp);
diff --git a/packages/common-plugin-register/src/Basic/Interfaces/PasteType.ts b/packages/common-plugin-register/src/Basic/Interfaces/PasteType.ts
new file mode 100644
index 0000000000..0b412ce90b
--- /dev/null
+++ b/packages/common-plugin-register/src/Basic/Interfaces/PasteType.ts
@@ -0,0 +1,4 @@
+export interface PasteType {
+ type: string;
+ result: string | ArrayBuffer | null;
+}
diff --git a/packages/common-plugin-register/src/Basic/Register/Clipboard/ClipboardExtensionManager.ts b/packages/common-plugin-register/src/Basic/Register/Clipboard/ClipboardExtensionManager.ts
index f8e527d0b1..a4fc250b98 100644
--- a/packages/common-plugin-register/src/Basic/Register/Clipboard/ClipboardExtensionManager.ts
+++ b/packages/common-plugin-register/src/Basic/Register/Clipboard/ClipboardExtensionManager.ts
@@ -1,6 +1,8 @@
import { IClipboardData } from '../../Interfaces/IClipboardData';
+import { PasteType } from '../../Interfaces/PasteType';
import { BaseClipboardExtension, BaseClipboardExtensionFactory } from './ClipboardExtensionFactory';
import { ClipboardExtensionRegister } from './ClipboardExtensionRegister';
+import { Clipboard } from '../../Shared/Clipboard';
export class ClipboardExtensionManager {
private _clipboardExtensionFactoryList: Array<BaseClipboardExtensionFactory>;
@@ -52,4 +54,26 @@ export class ClipboardExtensionManager {
}
return extension;
}
+
+ pasteResolver(e?: ClipboardEvent) {
+ return new Promise((resolve: (value: IClipboardData) => void, reject) => {
+ Clipboard.read(e).then((file: Array<PasteType | null> | null) => {
+ if (!file) return [];
+ const HtmlIndex = file.findIndex((item: PasteType | null, index: number) => item && item.type === 'text/html');
+ const PlainIndex = file.findIndex((item: PasteType | null, index: number) => item && item.type === 'text/plain');
+
+ const data: IClipboardData = {};
+ if (HtmlIndex > -1) {
+ const html = file[HtmlIndex]?.result as string;
+ data.html = html;
+ }
+ if (PlainIndex > -1) {
+ const plain = file[PlainIndex]?.result as string;
+ data.plain = plain;
+ }
+
+ resolve(data);
+ });
+ });
+ }
}
diff --git a/packages/common-plugin-register/src/Basic/Shared/Clipboard.ts b/packages/common-plugin-register/src/Basic/Shared/Clipboard.ts
new file mode 100644
index 0000000000..aac70a9ccf
--- /dev/null
+++ b/packages/common-plugin-register/src/Basic/Shared/Clipboard.ts
@@ -0,0 +1,94 @@
+import { PasteType } from '../Interfaces/PasteType';
+
+export type ClipboardType = {
+ type?: 'text/html' | 'text/plain' | 'image/png';
+ data: string;
+};
+
+export class Clipboard {
+ static clipboard = window.navigator.clipboard;
+
+ static textArea: HTMLTextAreaElement;
+
+ static async writeText(text: string, e?: ClipboardEvent) {
+ if (Clipboard.clipboard) {
+ return Clipboard.clipboard.writeText(text).then(
+ () => true,
+ (err) => console.dir(err)
+ );
+ }
+
+ e?.clipboardData?.setData('text/html', text);
+ }
+
+ static async write(data: ClipboardType, e?: ClipboardEvent) {
+ if (Clipboard.clipboard) {
+ const blob = new Blob([data.data], { type: data.type ?? 'text/html' });
+ const clipboardData = [new ClipboardItem({ 'text/html': blob })];
+
+ return Clipboard.clipboard.write(clipboardData).then(
+ () => true,
+ () => false
+ );
+ }
+
+ e?.clipboardData?.setData(data.type ?? 'text/html', data.data);
+ }
+
+ static async readText() {
+ if (Clipboard.clipboard) {
+ return Clipboard.clipboard.readText().then(
+ (text) => text,
+ () => null
+ );
+ }
+ if (!Clipboard.textArea) return null;
+ return new Promise((resolve, reject) => {
+ resolve(Clipboard.textArea.value);
+ })
+ .then((text) => text)
+ .then(() => null);
+ }
+
+ static async read(e?: ClipboardEvent): Promise<Array<PasteType | null> | null> {
+ if (Clipboard.clipboard) {
+ const clipboardItems = await Clipboard.clipboard.read();
+ const Promises: Array<Promise<PasteType | null>> = [];
+ for (const clipboardItem of clipboardItems) {
+ for (const type of clipboardItem.types) {
+ const blob = await clipboardItem.getType(type);
+ const reader = new FileReader();
+ if (type === 'image/png') {
+ reader.readAsDataURL(blob);
+ } else {
+ reader.readAsText(blob);
+ }
+ const promise: Promise<PasteType | null> = new Promise((resolve: (value: PasteType) => void, reject) => {
+ reader.onload = (e) => {
+ const item: PasteType = { type, result: reader.result };
+ resolve(item);
+ };
+ }).then(
+ (res) => res,
+ () => null
+ );
+ Promises.push(promise);
+ }
+ }
+ return Promise.all(Promises);
+ }
+
+ const result = [];
+ const clipboardData = e?.clipboardData;
+ const types = clipboardData?.types;
+ console.dir(types);
+ if (!types) return null;
+ for (let i = 0; i < types.length; i++) {
+ result.push({
+ type: types[i],
+ result: clipboardData.getData(types[i]),
+ });
+ }
+ return result;
+ }
+}
diff --git a/packages/common-plugin-register/src/Basic/Shared/index.ts b/packages/common-plugin-register/src/Basic/Shared/index.ts
index e69de29bb2..1cb022b779 100644
--- a/packages/common-plugin-register/src/Basic/Shared/index.ts
+++ b/packages/common-plugin-register/src/Basic/Shared/index.ts
@@ -0,0 +1 @@
+export * from './Clipboard';
diff --git a/packages/common-plugin-register/src/RegisterPlugin.tsx b/packages/common-plugin-register/src/RegisterPlugin.tsx
index 2640044635..fa4dbb1b72 100644
--- a/packages/common-plugin-register/src/RegisterPlugin.tsx
+++ b/packages/common-plugin-register/src/RegisterPlugin.tsx
@@ -1,4 +1,4 @@
-import { Plugin, UniverSheet, UniverDoc, UniverSlide } from '@univer/core';
+import { Plugin, UniverSheet, UniverDoc, UniverSlide, PLUGIN_NAMES } from '@univer/core';
import { zh, en } from './Locale';
import { REGISTER_PLUGIN_NAME } from './Basic/Const/PLUGIN_NAME';
import { ClipboardExtensionManager } from './Basic/Register';
diff --git a/packages/sheets-plugin-clipboard-office/.eslintrc.js b/packages/sheets-plugin-clipboard-office/.eslintrc.js
new file mode 100644
index 0000000000..7f4cf3e7ba
--- /dev/null
+++ b/packages/sheets-plugin-clipboard-office/.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/sheets-plugin-clipboard-office/.gitignore b/packages/sheets-plugin-clipboard-office/.gitignore
new file mode 100644
index 0000000000..12e1bd6bec
--- /dev/null
+++ b/packages/sheets-plugin-clipboard-office/.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/sheets-plugin-clipboard-office/.prettierrc.cjs b/packages/sheets-plugin-clipboard-office/.prettierrc.cjs
new file mode 100644
index 0000000000..6604107223
--- /dev/null
+++ b/packages/sheets-plugin-clipboard-office/.prettierrc.cjs
@@ -0,0 +1,7 @@
+module.exports = {
+ singleQuote: true,
+ trailingComma: 'es5',
+ tabWidth: 4,
+ semi: true,
+ printWidth: 180,
+};
diff --git a/packages/sheets-plugin-clipboard-office/README-zh.md b/packages/sheets-plugin-clipboard-office/README-zh.md
new file mode 100644
index 0000000000..97626389bd
--- /dev/null
+++ b/packages/sheets-plugin-clipboard-office/README-zh.md
@@ -0,0 +1,55 @@
+# style-universheet
+
+简体中文 | [English](./README.md)
+
+## 介绍
+
+UniverSheet ClipboardOffice插件
+
+### 安装
+
+```bash
+npm i @univer/sheets-plugin-clipboard-office
+```
+
+### 使用
+
+```js
+impport {ClipboardOffice} from '@univer/sheets-plugin-clipboard-office'
+
+const univerSheet = new UniverSheet();
+univerSheet.installPlugin(new ClipboardOffice());
+```
+
+## 本地开发
+
+### 环境
+
+- [Node.js](https://nodejs.org/en/) Version >= 10
+- [npm](https://www.npmjs.com/) Version >= 6
+
+### 安装
+
+```
+pnpm install
+```
+
+### 开发
+
+```
+# 当前目录 ./packages/sheets-plugin-clipboard-office/
+npm run dev
+
+# 或者项目根目录 ./
+pnpm run --filter @univer/sheets-plugin-clipboard-office dev
+```
+
+### 打包
+
+```
+# 当前目录 ./packages/sheets-plugin-clipboard-office/
+npm run build
+
+# 或者根目录 ./
+pnpm run --filter @univer/sheets-plugin-clipboard-office build
+```
diff --git a/packages/sheets-plugin-clipboard-office/README.md b/packages/sheets-plugin-clipboard-office/README.md
new file mode 100644
index 0000000000..9eb23d8ba3
--- /dev/null
+++ b/packages/sheets-plugin-clipboard-office/README.md
@@ -0,0 +1,55 @@
+# style-universheet
+
+English| [简体中文](./README-zh.md)
+
+## Introduction
+
+UniverSheet Plugin ClipboardOffice
+
+### Installation
+
+```bash
+npm i @univer/sheets-plugin-clipboard-office
+```
+
+### Usage
+
+```js
+impport {ClipboardOffice} from '@univer/sheets-plugin-clipboard-office'
+
+const univerSheet = new UniverSheet();
+univerSheet.installPlugin(new ClipboardOffice());
+```
+
+## 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/sheets-plugin-clipboard-office/
+npm run dev
+
+# Or project root directory ./
+pnpm run --filter @univer/sheets-plugin-clipboard-office dev
+```
+
+### Package
+
+```
+# Current directory ./packages/sheets-plugin-clipboard-office/
+npm run build
+
+# Or root directory ./
+pnpm run --filter @univer/sheets-plugin-clipboard-office build
+```
diff --git a/packages/sheets-plugin-clipboard-office/index.html b/packages/sheets-plugin-clipboard-office/index.html
new file mode 100644
index 0000000000..1fa3bb8e2e
--- /dev/null
+++ b/packages/sheets-plugin-clipboard-office/index.html
@@ -0,0 +1,24 @@
+<!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>UniverSheet</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: 100%;"></div>
+ <script type="module" src="/src/main.tsx"></script>
+</body>
+
+</html>
\ No newline at end of file
diff --git a/packages/sheets-plugin-clipboard-office/jest.config.js b/packages/sheets-plugin-clipboard-office/jest.config.js
new file mode 100644
index 0000000000..73ef4bae42
--- /dev/null
+++ b/packages/sheets-plugin-clipboard-office/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/sheets-plugin-clipboard-office/package.json b/packages/sheets-plugin-clipboard-office/package.json
new file mode 100644
index 0000000000..4d22943090
--- /dev/null
+++ b/packages/sheets-plugin-clipboard-office/package.json
@@ -0,0 +1,62 @@
+{
+ "name": "@univer/sheets-plugin-clipboard-office",
+ "version": "0.0.1",
+ "description": "UniverSheet normal sheets-plugin-clipboard-office",
+ "keywords": [],
+ "author": "DreamNum <[email protected]>",
+ "license": "MIT",
+ "main": "./lib/univer-sheets-plugin-clipboard-office.cjs.js",
+ "module": "./lib/univer-sheets-plugin-clipboard-office.es.js",
+ "browser": {
+ "./lib/univer-sheets-plugin-clipboard-office.cjs.js": "./src/index.ts",
+ "./lib/univer-sheets-plugin-clipboard-office.es.js": "./src/index.ts"
+ },
+ "types": "./src/Types/index.d.ts",
+ "exports": {
+ ".": {
+ "import": {
+ "node": "./lib/univer-sheets-plugin-clipboard-office.cjs.js",
+ "default": "./lib/univer-sheets-plugin-clipboard-office.es.js"
+ },
+ "require": "./lib/univer-sheets-plugin-clipboard-office.cjs.js",
+ "types": "./lib/univer-sheets-plugin-clipboard-office.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/common-plugin-register": "workspace:^0.0.1",
+ "@univer/core": "workspace:^0.0.1"
+ }
+}
diff --git a/packages/sheets-plugin-clipboard-office/src/Basic/Const/PLUGIN_NAME.ts b/packages/sheets-plugin-clipboard-office/src/Basic/Const/PLUGIN_NAME.ts
new file mode 100644
index 0000000000..7e840dba90
--- /dev/null
+++ b/packages/sheets-plugin-clipboard-office/src/Basic/Const/PLUGIN_NAME.ts
@@ -0,0 +1 @@
+export const CLIPBOARD_OFFICE_PLUGIN_NAME = 'clipboardOffice';
diff --git a/packages/sheets-plugin-clipboard-office/src/Basic/Const/index.ts b/packages/sheets-plugin-clipboard-office/src/Basic/Const/index.ts
new file mode 100644
index 0000000000..0dc96d927a
--- /dev/null
+++ b/packages/sheets-plugin-clipboard-office/src/Basic/Const/index.ts
@@ -0,0 +1 @@
+export * from './PLUGIN_NAME';
diff --git a/packages/sheets-plugin-clipboard-office/src/Basic/Enum/index.ts b/packages/sheets-plugin-clipboard-office/src/Basic/Enum/index.ts
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/packages/sheets-plugin-clipboard-office/src/Basic/Register/ClipboardOfficeExtension.ts b/packages/sheets-plugin-clipboard-office/src/Basic/Register/ClipboardOfficeExtension.ts
new file mode 100644
index 0000000000..69453d893c
--- /dev/null
+++ b/packages/sheets-plugin-clipboard-office/src/Basic/Register/ClipboardOfficeExtension.ts
@@ -0,0 +1,22 @@
+import { BaseClipboardExtension, BaseClipboardExtensionFactory, IClipboardData } from '@univer/common-plugin-register';
+import { ClipboardOfficePlugin } from '../../ClipboardOfficePlugin';
+
+export class ClipboardOfficeExtension extends BaseClipboardExtension {
+ execute() {}
+}
+
+export class ClipboardOfficeExtensionFactory extends BaseClipboardExtensionFactory<ClipboardOfficePlugin> {
+ get zIndex(): number {
+ return 1;
+ }
+
+ create(data: IClipboardData): BaseClipboardExtension {
+ return new ClipboardOfficeExtension(data);
+ }
+
+ check(data: IClipboardData): false | BaseClipboardExtension {
+ console.log('截获 office data', data);
+
+ return false;
+ }
+}
diff --git a/packages/sheets-plugin-clipboard-office/src/Basic/Register/index.ts b/packages/sheets-plugin-clipboard-office/src/Basic/Register/index.ts
new file mode 100644
index 0000000000..380a06edd3
--- /dev/null
+++ b/packages/sheets-plugin-clipboard-office/src/Basic/Register/index.ts
@@ -0,0 +1 @@
+export * from './ClipboardOfficeExtension';
diff --git a/packages/sheets-plugin-clipboard-office/src/Basic/Shared/index.ts b/packages/sheets-plugin-clipboard-office/src/Basic/Shared/index.ts
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/packages/sheets-plugin-clipboard-office/src/Basic/index.ts b/packages/sheets-plugin-clipboard-office/src/Basic/index.ts
new file mode 100644
index 0000000000..640d1bb8b3
--- /dev/null
+++ b/packages/sheets-plugin-clipboard-office/src/Basic/index.ts
@@ -0,0 +1,4 @@
+export * from './Const';
+export * from './Enum';
+export * from '../Locale';
+export * from './Shared';
diff --git a/packages/sheets-plugin-clipboard-office/src/ClipboardOfficePlugin.tsx b/packages/sheets-plugin-clipboard-office/src/ClipboardOfficePlugin.tsx
new file mode 100644
index 0000000000..e7ed98a31c
--- /dev/null
+++ b/packages/sheets-plugin-clipboard-office/src/ClipboardOfficePlugin.tsx
@@ -0,0 +1,59 @@
+import { Plugin, SheetContext, UniverSheet } from '@univer/core';
+import { zh, en } from './Locale';
+import { CLIPBOARD_OFFICE_PLUGIN_NAME } from './Basic/Const/PLUGIN_NAME';
+import { ClipboardOfficeController } from './Controller/ClipboardOfficeController';
+import { RegisterPlugin, REGISTER_PLUGIN_NAME } from '@univer/common-plugin-register';
+import { ClipboardOfficeExtensionFactory } from './Basic/Register';
+
+export interface IClipboardOfficePluginConfig {}
+
+export class ClipboardOfficePlugin extends Plugin<any, SheetContext> {
+ private _clipboardOfficeController: ClipboardOfficeController;
+
+ private _clipboardOfficeExtensionFactory: ClipboardOfficeExtensionFactory;
+
+ constructor(config?: IClipboardOfficePluginConfig) {
+ super(CLIPBOARD_OFFICE_PLUGIN_NAME);
+ }
+
+ static create(config?: IClipboardOfficePluginConfig) {
+ return new ClipboardOfficePlugin(config);
+ }
+
+ installTo(universheetInstance: UniverSheet) {
+ universheetInstance.installPlugin(this);
+ }
+
+ initialize(): void {
+ const context = this.getContext();
+
+ /**
+ * load more Locale object
+ */
+ context.getLocale().load({
+ en: en,
+ zh: zh,
+ });
+
+ this._clipboardOfficeController = new ClipboardOfficeController(this);
+
+ this.registerExtension();
+ }
+
+ registerExtension() {
+ const clipboardRegister = this.getContext().getPluginManager().getRequirePluginByName<RegisterPlugin>(REGISTER_PLUGIN_NAME).getClipboardExtensionManager().getRegister();
+
+ this._clipboardOfficeExtensionFactory = new ClipboardOfficeExtensionFactory(this);
+ clipboardRegister.add(this._clipboardOfficeExtensionFactory);
+ }
+
+ onMounted(): void {
+ this.initialize();
+ }
+
+ onDestroy(): void {
+ const clipboardRegister = this.getContext().getPluginManager().getRequirePluginByName<RegisterPlugin>(REGISTER_PLUGIN_NAME).getClipboardExtensionManager().getRegister();
+
+ clipboardRegister.delete(this._clipboardOfficeExtensionFactory);
+ }
+}
diff --git a/packages/sheets-plugin-clipboard-office/src/Controller/ClipboardOfficeController.ts b/packages/sheets-plugin-clipboard-office/src/Controller/ClipboardOfficeController.ts
new file mode 100644
index 0000000000..e9ee83cd56
--- /dev/null
+++ b/packages/sheets-plugin-clipboard-office/src/Controller/ClipboardOfficeController.ts
@@ -0,0 +1,9 @@
+import { ClipboardOfficePlugin } from '../ClipboardOfficePlugin';
+
+export class ClipboardOfficeController {
+ protected _plugin: ClipboardOfficePlugin;
+
+ constructor(plugin: ClipboardOfficePlugin) {
+ this._plugin = plugin;
+ }
+}
diff --git a/packages/sheets-plugin-clipboard-office/src/Controller/index.ts b/packages/sheets-plugin-clipboard-office/src/Controller/index.ts
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/packages/sheets-plugin-clipboard-office/src/Locale/en.ts b/packages/sheets-plugin-clipboard-office/src/Locale/en.ts
new file mode 100644
index 0000000000..6a9f149348
--- /dev/null
+++ b/packages/sheets-plugin-clipboard-office/src/Locale/en.ts
@@ -0,0 +1,8 @@
+export default {
+ clipboardOffice: {
+ tooltip: 'ClipboardOffice',
+ one:'one',
+ two:'two',
+ three:'three',
+ },
+};
diff --git a/packages/sheets-plugin-clipboard-office/src/Locale/index.ts b/packages/sheets-plugin-clipboard-office/src/Locale/index.ts
new file mode 100644
index 0000000000..3ac4bcd0fd
--- /dev/null
+++ b/packages/sheets-plugin-clipboard-office/src/Locale/index.ts
@@ -0,0 +1,4 @@
+import zh from './zh';
+import en from './en';
+
+export { zh, en };
diff --git a/packages/sheets-plugin-clipboard-office/src/Locale/zh.ts b/packages/sheets-plugin-clipboard-office/src/Locale/zh.ts
new file mode 100644
index 0000000000..6372cd0f07
--- /dev/null
+++ b/packages/sheets-plugin-clipboard-office/src/Locale/zh.ts
@@ -0,0 +1,8 @@
+export default {
+ clipboardOffice: {
+ tooltip: 'ClipboardOffice',
+ one:'一',
+ two:'二',
+ three:'三',
+ },
+};
diff --git a/packages/sheets-plugin-clipboard-office/src/Model/index.ts b/packages/sheets-plugin-clipboard-office/src/Model/index.ts
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/packages/sheets-plugin-clipboard-office/src/Service/index.ts b/packages/sheets-plugin-clipboard-office/src/Service/index.ts
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/packages/sheets-plugin-clipboard-office/src/Types/index.d.ts b/packages/sheets-plugin-clipboard-office/src/Types/index.d.ts
new file mode 100644
index 0000000000..c104202495
--- /dev/null
+++ b/packages/sheets-plugin-clipboard-office/src/Types/index.d.ts
@@ -0,0 +1,10 @@
+/// <reference types="vite/client" />
+
+export * from '../index';
+declare module '@univer/sheets-plugin-clipboard-office' {}
+
+// use css module
+declare module '*.less' {
+ const resource: { [key: string]: string };
+ export = resource;
+}
diff --git a/packages/sheets-plugin-clipboard-office/src/Types/preact.d.ts b/packages/sheets-plugin-clipboard-office/src/Types/preact.d.ts
new file mode 100644
index 0000000000..0d092b3751
--- /dev/null
+++ b/packages/sheets-plugin-clipboard-office/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/sheets-plugin-clipboard-office/src/View/Render/index.ts b/packages/sheets-plugin-clipboard-office/src/View/Render/index.ts
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/packages/sheets-plugin-clipboard-office/src/View/UI/index.ts b/packages/sheets-plugin-clipboard-office/src/View/UI/index.ts
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/packages/sheets-plugin-clipboard-office/src/index.ts b/packages/sheets-plugin-clipboard-office/src/index.ts
new file mode 100644
index 0000000000..24191dc326
--- /dev/null
+++ b/packages/sheets-plugin-clipboard-office/src/index.ts
@@ -0,0 +1,3 @@
+import { ClipboardOfficePlugin } from './ClipboardOfficePlugin';
+
+export { ClipboardOfficePlugin };
diff --git a/packages/sheets-plugin-clipboard-office/src/main.tsx b/packages/sheets-plugin-clipboard-office/src/main.tsx
new file mode 100644
index 0000000000..eda94d565d
--- /dev/null
+++ b/packages/sheets-plugin-clipboard-office/src/main.tsx
@@ -0,0 +1,22 @@
+import { UniverSheet } from '@univer/core';
+import { RenderEngine } from '@univer/base-render';
+import { SheetPlugin } from '@univer/base-sheets';
+import { UniverComponentSheet } from '@univer/style-universheet';
+import { DEFAULT_WORKBOOK_DATA } from '@univer/common-plugin-data';
+
+import { ClipboardOfficePlugin } from './ClipboardOfficePlugin';
+import { RegisterPlugin } from '@univer/common-plugin-register';
+
+const uiDefaultConfigUp = {
+ container: 'universheet',
+ layout: 'auto',
+};
+
+const univerSheet = UniverSheet.newInstance(DEFAULT_WORKBOOK_DATA);
+
+univerSheet.installPlugin(new RenderEngine());
+univerSheet.installPlugin(new UniverComponentSheet());
+
+univerSheet.installPlugin(new SheetPlugin(uiDefaultConfigUp));
+univerSheet.installPlugin(new RegisterPlugin());
+univerSheet.installPlugin(new ClipboardOfficePlugin());
diff --git a/packages/sheets-plugin-clipboard-office/tsconfig.json b/packages/sheets-plugin-clipboard-office/tsconfig.json
new file mode 100644
index 0000000000..fc81cbd47e
--- /dev/null
+++ b/packages/sheets-plugin-clipboard-office/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/sheets-plugin-clipboard-office/tsconfig.ref.json b/packages/sheets-plugin-clipboard-office/tsconfig.ref.json
new file mode 100644
index 0000000000..0c86b2c554
--- /dev/null
+++ b/packages/sheets-plugin-clipboard-office/tsconfig.ref.json
@@ -0,0 +1,7 @@
+{
+ "extends": "./tsconfig.json",
+ "include": ["src/**/*"],
+ "compilerOptions": {
+ "composite": true
+ }
+}
diff --git a/packages/sheets-plugin-clipboard-office/tsconfig.test.json b/packages/sheets-plugin-clipboard-office/tsconfig.test.json
new file mode 100644
index 0000000000..a2ac02c4ae
--- /dev/null
+++ b/packages/sheets-plugin-clipboard-office/tsconfig.test.json
@@ -0,0 +1,7 @@
+{
+ "extends": "./tsconfig.json",
+ "compilerOptions": {
+ "jsx": "react-jsx",
+ "jsxImportSource": "preact"
+ }
+}
diff --git a/packages/sheets-plugin-clipboard-office/vite.config.ts b/packages/sheets-plugin-clipboard-office/vite.config.ts
new file mode 100644
index 0000000000..020ecd6209
--- /dev/null
+++ b/packages/sheets-plugin-clipboard-office/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/tsconfig.json b/tsconfig.json
index cac8646590..f7e91e44d8 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -19,6 +19,9 @@
{ "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/common-plugin-register/tsconfig.ref.json" }
+ { "path": "./packages/sheets-plugin-import-xlsx/tsconfig.ref.json" },
+ { "path": "./packages/common-plugin-register/tsconfig.ref.json" },
+ { "path": "./packages/common-plugin-clipboard/tsconfig.ref.json" },
+ { "path": "./packages/common-plugin-clipboard-office/tsconfig.ref.json" }
]
}