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.

chore(ui-plugin-sheets): add ui-plugin-sheets

Dushusir06080da66448
diff --git a/packages/ui-plugin-sheets/.eslintrc.js b/packages/ui-plugin-sheets/.eslintrc.js
new file mode 100644
index 0000000000..7f4cf3e7ba
--- /dev/null
+++ b/packages/ui-plugin-sheets/.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/ui-plugin-sheets/.gitignore b/packages/ui-plugin-sheets/.gitignore
new file mode 100644
index 0000000000..12e1bd6bec
--- /dev/null
+++ b/packages/ui-plugin-sheets/.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/ui-plugin-sheets/.prettierrc.cjs b/packages/ui-plugin-sheets/.prettierrc.cjs
new file mode 100644
index 0000000000..6604107223
--- /dev/null
+++ b/packages/ui-plugin-sheets/.prettierrc.cjs
@@ -0,0 +1,7 @@
+module.exports = {
+ singleQuote: true,
+ trailingComma: 'es5',
+ tabWidth: 4,
+ semi: true,
+ printWidth: 180,
+};
diff --git a/packages/ui-plugin-sheets/README-zh.md b/packages/ui-plugin-sheets/README-zh.md
new file mode 100644
index 0000000000..788dfdf9c6
--- /dev/null
+++ b/packages/ui-plugin-sheets/README-zh.md
@@ -0,0 +1,55 @@
+# style-univer
+
+简体中文 | [English](./README.md)
+
+## 介绍
+
+UniverSheet Sheets 插件
+
+### 安装
+
+```shell
+npm i @univerjs/ui-plugin-sheets
+```
+
+### 使用
+
+```js
+import { Sheets } from '@univerjs/ui-plugin-sheets';
+
+const univerSheet = new UniverSheet();
+univerSheet.installPlugin(new Sheets());
+```
+
+## 本地开发
+
+### 环境
+
+- [Node.js](https://nodejs.org/en/) Version >= 10
+- [npm](https://www.npmjs.com/) Version >= 6
+
+### 安装
+
+```
+pnpm install
+```
+
+### 开发
+
+```
+# 当前目录 ./packages/ui-plugin-sheets/
+npm run dev
+
+# 或者项目根目录 ./
+pnpm run --filter @univerjs/ui-plugin-sheets dev
+```
+
+### 打包
+
+```
+# 当前目录 ./packages/ui-plugin-sheets/
+npm run build
+
+# 或者根目录 ./
+pnpm run --filter @univerjs/ui-plugin-sheets build
+```
diff --git a/packages/ui-plugin-sheets/README.md b/packages/ui-plugin-sheets/README.md
new file mode 100644
index 0000000000..e8bbdb93b8
--- /dev/null
+++ b/packages/ui-plugin-sheets/README.md
@@ -0,0 +1,55 @@
+# style-univer
+
+English| [简体中文](./README-zh.md)
+
+## Introduction
+
+UniverSheet Plugin Sheets
+
+### Installation
+
+```shell
+npm i @univerjs/ui-plugin-sheets
+```
+
+### Usage
+
+```js
+import { Sheets } from '@univerjs/ui-plugin-sheets';
+
+const univerSheet = new UniverSheet();
+univerSheet.installPlugin(new Sheets());
+```
+
+## 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/ui-plugin-sheets/
+npm run dev
+
+# Or project root directory ./
+pnpm run --filter @univerjs/ui-plugin-sheets dev
+```
+
+### Package
+
+```
+# Current directory ./packages/ui-plugin-sheets/
+npm run build
+
+# Or root directory ./
+pnpm run --filter @univerjs/ui-plugin-sheets build
+```
diff --git a/packages/ui-plugin-sheets/index.html b/packages/ui-plugin-sheets/index.html
new file mode 100644
index 0000000000..87007e935e
--- /dev/null
+++ b/packages/ui-plugin-sheets/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/ui-plugin-sheets/jest.config.js b/packages/ui-plugin-sheets/jest.config.js
new file mode 100644
index 0000000000..73ef4bae42
--- /dev/null
+++ b/packages/ui-plugin-sheets/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/ui-plugin-sheets/package.json b/packages/ui-plugin-sheets/package.json
new file mode 100644
index 0000000000..ede355d9e9
--- /dev/null
+++ b/packages/ui-plugin-sheets/package.json
@@ -0,0 +1,61 @@
+{
+ "name": "@univerjs/ui-plugin-sheets",
+ "version": "0.0.1",
+ "description": "UniverSheet normal ui-plugin-sheets",
+ "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-ui-plugin-sheets.cjs.js",
+ "module": "./lib/univer-ui-plugin-sheets.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": {
+ "@univerjs/common-plugin-data": "workspace:^0.0.1",
+ "@univerjs/base-component": "workspace:^0.0.1",
+ "@univerjs/base-render": "workspace:^0.0.1",
+ "@univerjs/core": "workspace:^0.0.1",
+ "@univerjs/base-sheets": "workspace:^0.0.1",
+ "@univerjs/style-univer": "workspace:^0.0.1",
+ "preact": "^10.5.14"
+ }
+}
diff --git a/packages/ui-plugin-sheets/src/Basic/Const/PLUGIN_NAME.ts b/packages/ui-plugin-sheets/src/Basic/Const/PLUGIN_NAME.ts
new file mode 100644
index 0000000000..63fff17ab0
--- /dev/null
+++ b/packages/ui-plugin-sheets/src/Basic/Const/PLUGIN_NAME.ts
@@ -0,0 +1 @@
+export const SHEET_UI_PLUGIN_NAME = 'SheetUI';
diff --git a/packages/ui-plugin-sheets/src/Basic/Const/index.ts b/packages/ui-plugin-sheets/src/Basic/Const/index.ts
new file mode 100644
index 0000000000..0dc96d927a
--- /dev/null
+++ b/packages/ui-plugin-sheets/src/Basic/Const/index.ts
@@ -0,0 +1 @@
+export * from './PLUGIN_NAME';
diff --git a/packages/ui-plugin-sheets/src/Basic/Enum/index.ts b/packages/ui-plugin-sheets/src/Basic/Enum/index.ts
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/packages/ui-plugin-sheets/src/Basic/Shared/index.ts b/packages/ui-plugin-sheets/src/Basic/Shared/index.ts
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/packages/ui-plugin-sheets/src/Basic/index.ts b/packages/ui-plugin-sheets/src/Basic/index.ts
new file mode 100644
index 0000000000..640d1bb8b3
--- /dev/null
+++ b/packages/ui-plugin-sheets/src/Basic/index.ts
@@ -0,0 +1,4 @@
+export * from './Const';
+export * from './Enum';
+export * from '../Locale';
+export * from './Shared';
diff --git a/packages/ui-plugin-sheets/src/Controller/SheetUIController.ts b/packages/ui-plugin-sheets/src/Controller/SheetUIController.ts
new file mode 100644
index 0000000000..5c9968261a
--- /dev/null
+++ b/packages/ui-plugin-sheets/src/Controller/SheetUIController.ts
@@ -0,0 +1,9 @@
+import { SheetUIPlugin } from '../SheetUIPlugin';
+
+export class SheetUIController {
+ protected _plugin: SheetUIPlugin;
+
+ constructor(plugin: SheetUIPlugin) {
+ this._plugin = plugin;
+ }
+}
diff --git a/packages/ui-plugin-sheets/src/Controller/index.ts b/packages/ui-plugin-sheets/src/Controller/index.ts
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/packages/ui-plugin-sheets/src/Locale/en.ts b/packages/ui-plugin-sheets/src/Locale/en.ts
new file mode 100644
index 0000000000..796ed2d38d
--- /dev/null
+++ b/packages/ui-plugin-sheets/src/Locale/en.ts
@@ -0,0 +1,8 @@
+export default {
+ SheetUI: {
+ tooltip: 'SheetUI',
+ one: 'one',
+ two: 'two',
+ three: 'three',
+ },
+};
diff --git a/packages/ui-plugin-sheets/src/Locale/index.ts b/packages/ui-plugin-sheets/src/Locale/index.ts
new file mode 100644
index 0000000000..3ac4bcd0fd
--- /dev/null
+++ b/packages/ui-plugin-sheets/src/Locale/index.ts
@@ -0,0 +1,4 @@
+import zh from './zh';
+import en from './en';
+
+export { zh, en };
diff --git a/packages/ui-plugin-sheets/src/Locale/zh.ts b/packages/ui-plugin-sheets/src/Locale/zh.ts
new file mode 100644
index 0000000000..943ed476f8
--- /dev/null
+++ b/packages/ui-plugin-sheets/src/Locale/zh.ts
@@ -0,0 +1,8 @@
+export default {
+ SheetUI: {
+ tooltip: 'SheetUI',
+ one: '一',
+ two: '二',
+ three: '三',
+ },
+};
diff --git a/packages/ui-plugin-sheets/src/Model/index.ts b/packages/ui-plugin-sheets/src/Model/index.ts
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/packages/ui-plugin-sheets/src/Service/index.ts b/packages/ui-plugin-sheets/src/Service/index.ts
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/packages/ui-plugin-sheets/src/SheetUIPlugin.tsx b/packages/ui-plugin-sheets/src/SheetUIPlugin.tsx
new file mode 100644
index 0000000000..b94ecddc70
--- /dev/null
+++ b/packages/ui-plugin-sheets/src/SheetUIPlugin.tsx
@@ -0,0 +1,42 @@
+import { Plugin, UniverSheet, UniverDoc, UniverSlide } from '@univerjs/core';
+import { zh, en } from './Locale';
+import { SHEET_UI_PLUGIN_NAME } from './Basic/Const/PLUGIN_NAME';
+import { SheetUIController } from './Controller/SheetUIController';
+
+export interface ISheetsPluginConfig {}
+
+export class SheetUIPlugin extends Plugin {
+ private _sheetsController: SheetUIController;
+
+ constructor(config?: ISheetsPluginConfig) {
+ super(SHEET_UI_PLUGIN_NAME);
+ }
+
+ static create(config?: ISheetsPluginConfig) {
+ return new SheetUIPlugin(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._sheetsController = new SheetUIController(this);
+ }
+
+ onMounted(): void {
+ this.initialize();
+ }
+
+ onDestroy(): void {}
+}
diff --git a/packages/ui-plugin-sheets/src/Types/index.d.ts b/packages/ui-plugin-sheets/src/Types/index.d.ts
new file mode 100644
index 0000000000..20652e0993
--- /dev/null
+++ b/packages/ui-plugin-sheets/src/Types/index.d.ts
@@ -0,0 +1,10 @@
+/// <reference types="vite/client" />
+
+export * from '../index';
+declare module '@univerjs/ui-plugin-sheets' {}
+
+// use css module
+declare module '*.less' {
+ const resource: { [key: string]: string };
+ export = resource;
+}
diff --git a/packages/ui-plugin-sheets/src/Types/preact.d.ts b/packages/ui-plugin-sheets/src/Types/preact.d.ts
new file mode 100644
index 0000000000..0d092b3751
--- /dev/null
+++ b/packages/ui-plugin-sheets/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/ui-plugin-sheets/src/View/Render/index.ts b/packages/ui-plugin-sheets/src/View/Render/index.ts
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/packages/ui-plugin-sheets/src/View/UI/index.ts b/packages/ui-plugin-sheets/src/View/UI/index.ts
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/packages/ui-plugin-sheets/src/index.ts b/packages/ui-plugin-sheets/src/index.ts
new file mode 100644
index 0000000000..2a03c88802
--- /dev/null
+++ b/packages/ui-plugin-sheets/src/index.ts
@@ -0,0 +1 @@
+export * from './SheetUIPlugin';
diff --git a/packages/ui-plugin-sheets/src/main.tsx b/packages/ui-plugin-sheets/src/main.tsx
new file mode 100644
index 0000000000..b9e85bff0c
--- /dev/null
+++ b/packages/ui-plugin-sheets/src/main.tsx
@@ -0,0 +1,20 @@
+import { UniverSheet, UniverDoc, UniverSlide } from '@univerjs/core';
+import { RenderEngine } from '@univerjs/base-render';
+import { SheetPlugin } from '@univerjs/base-sheets';
+import { UniverComponentSheet } from '@univerjs/style-univer';
+import { DEFAULT_WORKBOOK_DATA } from '@univerjs/common-plugin-data';
+
+import { SheetUIPlugin } from './SheetUIPlugin';
+
+// 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 SheetUIPlugin());
\ No newline at end of file
diff --git a/packages/ui-plugin-sheets/tsconfig.json b/packages/ui-plugin-sheets/tsconfig.json
new file mode 100644
index 0000000000..fc81cbd47e
--- /dev/null
+++ b/packages/ui-plugin-sheets/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/ui-plugin-sheets/tsconfig.ref.json b/packages/ui-plugin-sheets/tsconfig.ref.json
new file mode 100644
index 0000000000..0c86b2c554
--- /dev/null
+++ b/packages/ui-plugin-sheets/tsconfig.ref.json
@@ -0,0 +1,7 @@
+{
+ "extends": "./tsconfig.json",
+ "include": ["src/**/*"],
+ "compilerOptions": {
+ "composite": true
+ }
+}
diff --git a/packages/ui-plugin-sheets/tsconfig.test.json b/packages/ui-plugin-sheets/tsconfig.test.json
new file mode 100644
index 0000000000..a2ac02c4ae
--- /dev/null
+++ b/packages/ui-plugin-sheets/tsconfig.test.json
@@ -0,0 +1,7 @@
+{
+ "extends": "./tsconfig.json",
+ "compilerOptions": {
+ "jsx": "react-jsx",
+ "jsxImportSource": "preact"
+ }
+}
diff --git a/packages/ui-plugin-sheets/vite.config.ts b/packages/ui-plugin-sheets/vite.config.ts
new file mode 100644
index 0000000000..020ecd6209
--- /dev/null
+++ b/packages/ui-plugin-sheets/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'],
+ }),
+ ],
+});