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: add Node.js SDK examples (#3708)

Wenzhao Hu5e39aeab8221
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 1694ceddb7..bfc59901a1 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -56,6 +56,20 @@ Please refer to the [architecture doc](https://github.com/dream-num/univer/wiki/
### Source code organization
+The structure of the repository is as follows:
+
+```
+.
+├── common/ shared configuration and utilities
+├── docs/ documentation
+├── e2e/ e2e test cases
+├── examples/ demos running on the web
+├── examples-node/ demos running on Node.js
+├── mockdata/ mock data for development
+├── packages/ Univer core and plugins
+├── packages-experimental/ experimental plugins (not published on npm.com)
+```
+
The file structure of a plugin should be organized as follows:
```
diff --git a/examples-node/.gitignore b/examples-node/.gitignore
new file mode 100644
index 0000000000..849ddff3b7
--- /dev/null
+++ b/examples-node/.gitignore
@@ -0,0 +1 @@
+dist/
diff --git a/examples-node/esbuild.config.mjs b/examples-node/esbuild.config.mjs
new file mode 100644
index 0000000000..33bcaf468b
--- /dev/null
+++ b/examples-node/esbuild.config.mjs
@@ -0,0 +1,37 @@
+import { execSync } from 'node:child_process';
+import process from 'node:process';
+import esbuild from 'esbuild';
+import minimist from 'minimist';
+import './scripts/generate-locales.mjs';
+
+const args = minimist(process.argv.slice(2));
+
+const define = {
+ 'process.env.NODE_ENV': args.watch ? '"development"' : '"production"',
+};
+
+if (!args.watch) {
+ const gitCommitHash = execSync('git rev-parse --short HEAD').toString().trim();
+ const gitRefName = execSync('git symbolic-ref -q --short HEAD || git describe --tags --exact-match').toString().trim();
+
+ define['process.env.GIT_COMMIT_HASH'] = `"${gitCommitHash}"`;
+ define['process.env.GIT_REF_NAME'] = `"${gitRefName}"`;
+ define['process.env.BUILD_TIME'] = `"${new Date().toISOString()}"`;
+}
+
+const ctx = await esbuild[args.watch ? 'context' : 'build']({
+ bundle: true,
+ color: true,
+ sourcemap: args.watch,
+ minify: true,
+ target: 'chrome70',
+ entryPoints: [
+ './src/cases/basic.ts',
+ ],
+ outdir: './dist',
+ define,
+});
+
+if (args.watch) {
+ await ctx.watch();
+}
diff --git a/examples-node/package.json b/examples-node/package.json
new file mode 100644
index 0000000000..235c8a59a9
--- /dev/null
+++ b/examples-node/package.json
@@ -0,0 +1,40 @@
+{
+ "name": "univer-examples-node",
+ "private": true,
+ "description": "Examples run on Node.js",
+ "author": "DreamNum <[email protected]>",
+ "license": "Apache-2.0",
+ "scripts": {
+ "build:demo": "node ./esbuild.config.mjs",
+ "lint:types": "node ./scripts/generate-locales.mjs && tsc --noEmit"
+ },
+ "dependencies": {
+ "@univerjs/core": "workspace:*",
+ "@univerjs/data-validation": "workspace:*",
+ "@univerjs/docs": "workspace:*",
+ "@univerjs/docs-drawing": "workspace:*",
+ "@univerjs/drawing": "workspace:*",
+ "@univerjs/engine-formula": "workspace:*",
+ "@univerjs/engine-render": "workspace:*",
+ "@univerjs/rpc": "workspace:*",
+ "@univerjs/sheets": "workspace:*",
+ "@univerjs/sheets-conditional-formatting": "workspace:*",
+ "@univerjs/sheets-data-validation": "workspace:*",
+ "@univerjs/sheets-drawing": "workspace:*",
+ "@univerjs/sheets-filter": "workspace:*",
+ "@univerjs/sheets-formula": "workspace:*",
+ "@univerjs/sheets-hyper-link": "workspace:*",
+ "@univerjs/sheets-sort": "workspace:*",
+ "@univerjs/thread-comment": "workspace:*",
+ "rxjs": "^7.8.1"
+ },
+ "devDependencies": {
+ "@univerjs-infra/shared": "workspace:*",
+ "esbuild": "^0.24.0",
+ "esbuild-plugin-clean": "^1.0.1",
+ "esbuild-plugin-copy": "^2.1.1",
+ "minimist": "^1.2.8",
+ "typescript": "^5.6.3"
+ }
+}
+
diff --git a/examples-node/scripts/generate-locales.mjs b/examples-node/scripts/generate-locales.mjs
new file mode 100644
index 0000000000..f1f0364fbb
--- /dev/null
+++ b/examples-node/scripts/generate-locales.mjs
@@ -0,0 +1,60 @@
+import fs from 'node:fs';
+import path from 'node:path';
+import { fileURLToPath } from 'node:url';
+
+const __dirname = path.dirname(fileURLToPath(import.meta.url));
+
+/**
+ * Generate locales files
+ */
+async function generateLocales() {
+ const pkg = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../package.json'), 'utf-8'));
+ const output = path.resolve(__dirname, '../src/locales.ts');
+ const locales = ['en-US', 'ru-RU', 'zh-CN', 'zh-TW', 'vi-VN', 'fa-IR'];
+
+ const header = `/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { Tools } from '@univerjs/core';
+`;
+
+ const deps = Object.keys(pkg.dependencies)
+ .filter((dep) => dep.startsWith('@univerjs') && fs.existsSync(path.resolve(__dirname, `../node_modules/${dep}/src/locale`)));
+
+ const importStatements = deps.reduce((acc, dep) => {
+ const formattedDep = dep.replace(/(@univerjs\/|\-)/g, '');
+ locales.forEach((locale) => {
+ acc += `import ${formattedDep}${locale.replace(/-/g, '')} from '${dep}/locale/${locale}';\n`;
+ });
+ return acc;
+ }, '');
+
+ const exportStatements = locales.reduce((acc, locale) => {
+ const formattedLocale = locale.replace(/-/g, '');
+ const depStatements = deps.map((dep) => {
+ return ` ${dep.replace(/(@univerjs\/|\-)/g, '')}${formattedLocale}`;
+ }).join(',\n');
+
+ acc += `export const ${formattedLocale} = Tools.deepMerge(\n {},\n${depStatements}\n);\n`;
+ return acc;
+ }, '');
+
+ const content = `${header}\n${importStatements}\n${exportStatements}`;
+
+ fs.writeFileSync(output, content);
+}
+
+generateLocales();
diff --git a/examples-node/src/cases/basic.ts b/examples-node/src/cases/basic.ts
new file mode 100644
index 0000000000..1fc1625d57
--- /dev/null
+++ b/examples-node/src/cases/basic.ts
@@ -0,0 +1,25 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import type { IWorkbookData, Workbook } from '@univerjs/core';
+import { UniverInstanceType } from '@univerjs/core';
+import { createUniverOnNode } from '../sdk';
+
+const univer = createUniverOnNode();
+
+univer.createUnit<IWorkbookData, Workbook>(UniverInstanceType.UNIVER_SHEET, {});
+
+// TODO: Facade API here
diff --git a/examples-node/src/locales.ts b/examples-node/src/locales.ts
new file mode 100644
index 0000000000..76e38a9078
--- /dev/null
+++ b/examples-node/src/locales.ts
@@ -0,0 +1,61 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { Tools } from '@univerjs/core';
+
+import sheetsenUS from '@univerjs/sheets/locale/en-US';
+import sheetsfaIR from '@univerjs/sheets/locale/fa-IR';
+import sheetsruRU from '@univerjs/sheets/locale/ru-RU';
+import sheetsviVN from '@univerjs/sheets/locale/vi-VN';
+import sheetszhCN from '@univerjs/sheets/locale/zh-CN';
+import sheetszhTW from '@univerjs/sheets/locale/zh-TW';
+import sheetssortenUS from '@univerjs/sheets-sort/locale/en-US';
+import sheetssortfaIR from '@univerjs/sheets-sort/locale/fa-IR';
+import sheetssortruRU from '@univerjs/sheets-sort/locale/ru-RU';
+import sheetssortviVN from '@univerjs/sheets-sort/locale/vi-VN';
+import sheetssortzhCN from '@univerjs/sheets-sort/locale/zh-CN';
+import sheetssortzhTW from '@univerjs/sheets-sort/locale/zh-TW';
+
+export const enUS = Tools.deepMerge(
+ {},
+ sheetsenUS,
+ sheetssortenUS
+);
+export const ruRU = Tools.deepMerge(
+ {},
+ sheetsruRU,
+ sheetssortruRU
+);
+export const zhCN = Tools.deepMerge(
+ {},
+ sheetszhCN,
+ sheetssortzhCN
+);
+export const zhTW = Tools.deepMerge(
+ {},
+ sheetszhTW,
+ sheetssortzhTW
+);
+export const viVN = Tools.deepMerge(
+ {},
+ sheetsviVN,
+ sheetssortviVN
+);
+export const faIR = Tools.deepMerge(
+ {},
+ sheetsfaIR,
+ sheetssortfaIR
+);
diff --git a/examples-node/src/sdk/index.ts b/examples-node/src/sdk/index.ts
new file mode 100644
index 0000000000..e462d3459a
--- /dev/null
+++ b/examples-node/src/sdk/index.ts
@@ -0,0 +1,66 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { Univer } from '@univerjs/core';
+import { UniverDataValidationPlugin } from '@univerjs/data-validation';
+import { UniverDocsPlugin } from '@univerjs/docs';
+import { UniverDocsDrawingPlugin } from '@univerjs/docs-drawing';
+import { UniverDrawingPlugin } from '@univerjs/drawing';
+import { UniverFormulaEnginePlugin } from '@univerjs/engine-formula';
+import { UniverSheetsPlugin } from '@univerjs/sheets';
+import { UniverSheetsConditionalFormattingPlugin } from '@univerjs/sheets-conditional-formatting';
+import { UniverSheetsDataValidationPlugin } from '@univerjs/sheets-data-validation';
+import { UniverSheetsDrawingPlugin } from '@univerjs/sheets-drawing';
+import { UniverSheetsFilterPlugin } from '@univerjs/sheets-filter';
+import { UniverSheetsHyperLinkPlugin } from '@univerjs/sheets-hyper-link';
+import { UniverSheetsSortPlugin } from '@univerjs/sheets-sort';
+import { UniverThreadCommentPlugin } from '@univerjs/thread-comment';
+
+export function createUniverOnNode(): Univer {
+ const univer = new Univer();
+
+ registerBasicPlugins(univer);
+ reigsterSharedPlugins(univer);
+ registerDocPlugins(univer);
+ registerSheetPlugins(univer);
+
+ return univer;
+}
+
+function registerBasicPlugins(univer: Univer): void {
+ univer.registerPlugin(UniverFormulaEnginePlugin, { notExecuteFormula: true });
+}
+
+function reigsterSharedPlugins(univer: Univer): void {
+ univer.registerPlugin(UniverThreadCommentPlugin);
+ univer.registerPlugin(UniverDrawingPlugin);
+}
+
+function registerDocPlugins(univer: Univer): void {
+ univer.registerPlugin(UniverDocsPlugin);
+ univer.registerPlugin(UniverDocsDrawingPlugin);
+}
+
+function registerSheetPlugins(univer: Univer): void {
+ univer.registerPlugin(UniverSheetsPlugin);
+ univer.registerPlugin(UniverSheetsConditionalFormattingPlugin);
+ univer.registerPlugin(UniverDataValidationPlugin);
+ univer.registerPlugin(UniverSheetsDataValidationPlugin);
+ univer.registerPlugin(UniverSheetsFilterPlugin);
+ univer.registerPlugin(UniverSheetsHyperLinkPlugin);
+ univer.registerPlugin(UniverSheetsDrawingPlugin);
+ univer.registerPlugin(UniverSheetsSortPlugin);
+}
diff --git a/examples-node/tsconfig.json b/examples-node/tsconfig.json
new file mode 100644
index 0000000000..cd576687f3
--- /dev/null
+++ b/examples-node/tsconfig.json
@@ -0,0 +1,8 @@
+{
+ "extends": "@univerjs-infra/shared/tsconfigs/base",
+ "compilerOptions": {
+ "allowArbitraryExtensions": true,
+ "outDir": "dist"
+ },
+ "include": ["src"]
+}
diff --git a/examples/esbuild.config.mjs b/examples/esbuild.config.mjs
index 4f3ccae5ba..f2fba761ef 100644
--- a/examples/esbuild.config.mjs
+++ b/examples/esbuild.config.mjs
@@ -138,6 +138,5 @@ if (args.watch) {
const url = `http://localhost:${port}`;
- // eslint-disable-next-line no-console
console.log(`Local server: ${url}`);
}
diff --git a/examples/tsconfig.json b/examples/tsconfig.json
index 6ee2c03d60..a7e6aeac52 100644
--- a/examples/tsconfig.json
+++ b/examples/tsconfig.json
@@ -5,5 +5,5 @@
"allowArbitraryExtensions": true,
"outDir": "local"
},
- "include": ["src", "../mockdata/src/slides", "../mockdata/src/sheets", "../mockdata/src/docs", "../mockdata/src/index.ts"]
+ "include": ["src"]
}
diff --git a/mockdata/package.json b/mockdata/package.json
index bc945044d8..495b264a3d 100644
--- a/mockdata/package.json
+++ b/mockdata/package.json
@@ -62,57 +62,21 @@
"@univerjs/sheets-data-validation": "workspace:*"
},
"dependencies": {
- "@univerjs/action-recorder": "workspace:*",
"@univerjs/core": "workspace:*",
"@univerjs/data-validation": "workspace:*",
- "@univerjs/design": "workspace:*",
"@univerjs/docs": "workspace:*",
"@univerjs/docs-drawing": "workspace:*",
- "@univerjs/docs-drawing-ui": "workspace:*",
- "@univerjs/docs-hyper-link-ui": "workspace:*",
- "@univerjs/docs-mention-ui": "workspace:*",
- "@univerjs/docs-thread-comment-ui": "workspace:*",
- "@univerjs/docs-ui": "workspace:*",
"@univerjs/drawing": "workspace:*",
- "@univerjs/drawing-ui": "workspace:*",
- "@univerjs/engine-formula": "workspace:*",
- "@univerjs/engine-render": "workspace:*",
- "@univerjs/facade": "workspace:*",
- "@univerjs/find-replace": "workspace:*",
- "@univerjs/icons": "^0.1.78",
- "@univerjs/rpc": "workspace:*",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-conditional-formatting": "workspace:*",
- "@univerjs/sheets-conditional-formatting-ui": "workspace:*",
- "@univerjs/sheets-crosshair-highlight": "workspace:*",
"@univerjs/sheets-data-validation": "workspace:*",
"@univerjs/sheets-drawing": "workspace:*",
- "@univerjs/sheets-drawing-ui": "workspace:*",
"@univerjs/sheets-filter": "workspace:*",
- "@univerjs/sheets-filter-ui": "workspace:*",
- "@univerjs/sheets-find-replace": "workspace:*",
"@univerjs/sheets-formula": "workspace:*",
"@univerjs/sheets-hyper-link": "workspace:*",
- "@univerjs/sheets-hyper-link-ui": "workspace:*",
- "@univerjs/sheets-numfmt": "workspace:*",
"@univerjs/sheets-sort": "workspace:*",
- "@univerjs/sheets-sort-ui": "workspace:*",
- "@univerjs/sheets-thread-comment": "workspace:*",
"@univerjs/sheets-thread-comment-base": "workspace:*",
- "@univerjs/sheets-ui": "workspace:*",
- "@univerjs/sheets-zen-editor": "workspace:*",
- "@univerjs/slides": "workspace:*",
- "@univerjs/slides-ui": "workspace:*",
- "@univerjs/thread-comment": "workspace:*",
- "@univerjs/thread-comment-ui": "workspace:*",
- "@univerjs/ui": "workspace:*",
- "@univerjs/uni-docs-ui": "workspace:*",
- "@univerjs/uni-formula": "workspace:*",
- "@univerjs/uni-formula-ui": "workspace:*",
- "@univerjs/uni-sheets-ui": "workspace:*",
- "@univerjs/uni-slides-ui": "workspace:*",
- "@univerjs/uniscript": "workspace:*",
- "@univerjs/uniui": "workspace:*"
+ "@univerjs/thread-comment": "workspace:*"
},
"devDependencies": {
"@univerjs-infra/shared": "workspace:*",
diff --git a/packages-experimental/rpc-node/README.md b/packages-experimental/rpc-node/README.md
new file mode 100644
index 0000000000..3c7a0af2bf
--- /dev/null
+++ b/packages-experimental/rpc-node/README.md
@@ -0,0 +1,16 @@
+# @univerjs/rpc-node
+
+[![npm version](https://img.shields.io/npm/v/@univerjs/rpc-node)](https://npmjs.org/packages/@univerjs/rpc-node)
+[![license](https://img.shields.io/npm/l/@univerjs/rpc-node)](https://img.shields.io/npm/l/@univerjs/rpc-node)
+
+## Introduction
+
+> TODO: Introduction
+
+## Usage
+
+### Installation
+
+```shell
+npm i @univerjs/rpc-node
+```
diff --git a/packages-experimental/rpc-node/package.json b/packages-experimental/rpc-node/package.json
new file mode 100644
index 0000000000..fcea144e83
--- /dev/null
+++ b/packages-experimental/rpc-node/package.json
@@ -0,0 +1,78 @@
+{
+ "name": "@univerjs/rpc-node",
+ "version": "0.0.1",
+ "private": true,
+ "description": "",
+ "author": "DreamNum <[email protected]>",
+ "license": "Apache-2.0",
+ "funding": {
+ "type": "opencollective",
+ "url": "https://opencollective.com/univer"
+ },
+ "homepage": "https://univer.ai",
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/dream-num/univer"
+ },
+ "bugs": {
+ "url": "https://github.com/dream-num/univer/issues"
+ },
+ "keywords": [],
+ "exports": {
+ ".": "./src/index.ts",
+ "./*": "./src/*"
+ },
+ "main": "./lib/cjs/index.js",
+ "module": "./lib/es/index.js",
+ "types": "./lib/types/index.d.ts",
+ "publishConfig": {
+ "access": "public",
+ "main": "./lib/cjs/index.js",
+ "module": "./lib/es/index.js",
+ "exports": {
+ ".": {
+ "import": "./lib/es/index.js",
+ "require": "./lib/cjs/index.js",
+ "types": "./lib/types/index.d.ts"
+ },
+ "./*": {
+ "import": "./lib/es/*",
+ "require": "./lib/cjs/*",
+ "types": "./lib/types/index.d.ts"
+ },
+ "./lib/*": "./lib/*"
+ }
+ },
+ "directories": {
+ "lib": "lib"
+ },
+ "files": [
+ "lib"
+ ],
+ "scripts": {
+ "test": "vitest run",
+ "test:watch": "vitest",
+ "coverage": "vitest run --coverage",
+ "lint:types": "tsc --noEmit",
+ "build": "tsc && vite build"
+ },
+ "peerDependencies": {
+ "@univerjs/core": "workspace:*",
+ "@univerjs/rpc": "workspace:*",
+ "rxjs": ">=7.0.0"
+ },
+ "dependencies": {
+ "@univerjs/core": "workspace:*",
+ "@univerjs/rpc": "workspace:*",
+ "rxjs": ">=7.0.0"
+ },
+ "devDependencies": {
+ "@univerjs-infra/shared": "workspace:*",
+ "@univerjs/core": "workspace:*",
+ "@univerjs/rpc": "workspace:*",
+ "rxjs": "^7.8.1",
+ "typescript": "^5.5.4",
+ "vite": "^5.4.1",
+ "vitest": "^2.0.5"
+ }
+}
diff --git a/packages-experimental/rpc-node/src/index.ts b/packages-experimental/rpc-node/src/index.ts
new file mode 100644
index 0000000000..5153b60daf
--- /dev/null
+++ b/packages-experimental/rpc-node/src/index.ts
@@ -0,0 +1,17 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+export { UniverRPCNodeMainPlugin, UniverRPCNodeWorkerPlugin } from './plugin';
diff --git a/packages-experimental/rpc-node/src/plugin.ts b/packages-experimental/rpc-node/src/plugin.ts
new file mode 100644
index 0000000000..75916acbac
--- /dev/null
+++ b/packages-experimental/rpc-node/src/plugin.ts
@@ -0,0 +1,104 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import type { Dependency } from '@univerjs/core';
+import type { IMessageProtocol } from '@univerjs/rpc';
+import type { Serializable } from 'node:child_process';
+import process from 'node:process';
+import { IConfigService, Inject, Injector, Plugin } from '@univerjs/core';
+import { ChannelService,
+ DataSyncPrimaryController,
+ DataSyncReplicaController,
+ IRemoteInstanceService,
+ IRemoteSyncService,
+ IRPCChannelService,
+ RemoteSyncPrimaryService,
+ WebWorkerRemoteInstanceService,
+} from '@univerjs/rpc';
+import { Observable, shareReplay } from 'rxjs';
+
+export interface IUniverRPCNodeMainConfig {
+ messageProtocol: IMessageProtocol;
+}
+
+const UNIVER_RPC_NODE_MAIN_PLUGIN_CONFIG_KEY = 'node-rpc.main.config';
+
+export class UniverRPCNodeMainPlugin extends Plugin {
+ static override pluginName = 'UNIVER_RPC_NODE_MAIN_PLUGIN';
+
+ constructor(
+ private readonly _config: IUniverRPCNodeMainConfig,
+ @Inject(Injector) protected readonly _injector: Injector,
+ @IConfigService private readonly _configService: IConfigService
+ ) {
+ super();
+
+ this._configService.setConfig(UNIVER_RPC_NODE_MAIN_PLUGIN_CONFIG_KEY, this._config);
+ }
+
+ override onStarting(): void {
+ const dependencies: Dependency[] = [
+ [IRPCChannelService, {
+ useFactory: () => new ChannelService(this._config.messageProtocol),
+ }],
+ [DataSyncPrimaryController],
+ [IRemoteSyncService, { useClass: RemoteSyncPrimaryService }],
+ ];
+
+ dependencies.forEach((dependency) => this._injector.add(dependency));
+
+ this._injector.get(DataSyncPrimaryController);
+ }
+}
+
+export class UniverRPCNodeWorkerPlugin extends Plugin {
+ static override pluginName = 'UNIVER_RPC_NODE_WORKER_PLUGIN';
+
+ constructor(
+ private readonly _config: undefined,
+ @Inject(Injector) protected readonly _injector: Injector
+ ) {
+ super();
+ }
+
+ override onStarting(): void {
+ ([
+ [DataSyncReplicaController],
+ [IRPCChannelService, {
+ useFactory: () => new ChannelService(createNodeWorkerMessageProtocol()),
+ }],
+ [IRemoteInstanceService, { useClass: WebWorkerRemoteInstanceService }],
+ ] as Dependency[]).forEach((d) => this._injector.add(d));
+
+ this._injector.get(DataSyncReplicaController);
+ }
+}
+
+function createNodeWorkerMessageProtocol(): IMessageProtocol {
+ return {
+ send(message) {
+ process.send!(message as Serializable);
+ },
+ onMessage: new Observable<any>((subscriber) => {
+ const handler = (event: unknown) => {
+ subscriber.next(event);
+ };
+
+ process.on('message', handler);
+ return () => process.off('message', handler);
+ }).pipe(shareReplay(1)),
+ };
+}
diff --git a/packages-experimental/rpc-node/src/vite-env.d.ts b/packages-experimental/rpc-node/src/vite-env.d.ts
new file mode 100644
index 0000000000..11f02fe2a0
--- /dev/null
+++ b/packages-experimental/rpc-node/src/vite-env.d.ts
@@ -0,0 +1 @@
+/// <reference types="vite/client" />
diff --git a/packages-experimental/rpc-node/tsconfig.json b/packages-experimental/rpc-node/tsconfig.json
new file mode 100644
index 0000000000..c62210cbad
--- /dev/null
+++ b/packages-experimental/rpc-node/tsconfig.json
@@ -0,0 +1,9 @@
+{
+ "extends": "@univerjs-infra/shared/tsconfigs/base",
+ "compilerOptions": {
+ "rootDir": "src",
+ "outDir": "lib/types"
+ },
+ "references": [{ "path": "./tsconfig.node.json" }],
+ "include": ["src"]
+}
diff --git a/packages-experimental/rpc-node/tsconfig.node.json b/packages-experimental/rpc-node/tsconfig.node.json
new file mode 100644
index 0000000000..50ef1e6862
--- /dev/null
+++ b/packages-experimental/rpc-node/tsconfig.node.json
@@ -0,0 +1,4 @@
+{
+ "extends": "@univerjs-infra/shared/tsconfigs/node",
+ "include": ["vite.config.ts"]
+}
diff --git a/packages-experimental/rpc-node/vite.config.ts b/packages-experimental/rpc-node/vite.config.ts
new file mode 100644
index 0000000000..62c3c4fab3
--- /dev/null
+++ b/packages-experimental/rpc-node/vite.config.ts
@@ -0,0 +1,7 @@
+import createViteConfig from '@univerjs-infra/shared/vite';
+import pkg from './package.json';
+
+export default ({ mode }) => createViteConfig({}, {
+ mode,
+ pkg,
+});
diff --git a/packages/sheets-data-validation/package.json b/packages/sheets-data-validation/package.json
index 81529dd265..a553e1af9b 100644
--- a/packages/sheets-data-validation/package.json
+++ b/packages/sheets-data-validation/package.json
@@ -68,7 +68,6 @@
"@univerjs/engine-render": "workspace:*",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-formula": "workspace:*",
- "@univerjs/sheets-numfmt": "workspace:*",
"clsx": ">=2.0.0",
"dayjs": ">=1.11.0",
"react": "^16.9.0 || ^17.0.0 || ^18.0.0",
@@ -86,7 +85,6 @@
"@univerjs/protocol": "0.1.39-alpha.15",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-formula": "workspace:*",
- "@univerjs/sheets-numfmt": "workspace:*",
"clsx": "^2.1.1",
"dayjs": "^1.11.13"
},
diff --git a/packages/sheets-data-validation/src/plugin.ts b/packages/sheets-data-validation/src/plugin.ts
index f2bcc45f22..99d3cd40c5 100644
--- a/packages/sheets-data-validation/src/plugin.ts
+++ b/packages/sheets-data-validation/src/plugin.ts
@@ -22,7 +22,6 @@ import {
} from '@univerjs/core';
import { type Dependency, Inject, Injector } from '@univerjs/core';
import { UniverDataValidationPlugin } from '@univerjs/data-validation';
-import { UniverSheetsNumfmtPlugin } from '@univerjs/sheets-numfmt';
import {
AddSheetDataValidationCommand,
ClearRangeDataValidationCommand,
@@ -43,7 +42,7 @@ import { DataValidationCustomFormulaService } from './services/dv-custom-formula
import { DataValidationFormulaService } from './services/dv-formula.service';
import { SheetsDataValidationValidatorService } from './services/dv-validator-service';
-@DependentOn(UniverSheetsNumfmtPlugin, UniverDataValidationPlugin)
+@DependentOn(UniverDataValidationPlugin)
export class UniverSheetsDataValidationPlugin extends Plugin {
static override pluginName = DATA_VALIDATION_PLUGIN_NAME;
static override type = UniverInstanceType.UNIVER_SHEET;
diff --git a/packages/sheets-hyper-link/package.json b/packages/sheets-hyper-link/package.json
index 978f2ab132..bea31c17fe 100644
--- a/packages/sheets-hyper-link/package.json
+++ b/packages/sheets-hyper-link/package.json
@@ -60,7 +60,6 @@
"@univerjs/core": "workspace:*",
"@univerjs/engine-formula": "workspace:*",
"@univerjs/sheets": "workspace:*",
- "@univerjs/sheets-hyper-link": "workspace:*",
"rxjs": ">=7.0.0"
},
"dependencies": {
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index d4ad572949..9ebd222da0 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -10,7 +10,7 @@ importers:
devDependencies:
'@antfu/eslint-config':
specifier: 3.7.3
'@commitlint/cli':
specifier: ^19.5.0
version: 19.5.0(@types/[email protected])([email protected])
@@ -416,62 +416,29 @@ importers:
specifier: ^5.6.3
version: 5.6.3
- mockdata:
+ examples-node:
dependencies:
- '@univerjs/action-recorder':
- specifier: workspace:*
- version: link:../packages-experimental/action-recorder
'@univerjs/core':
specifier: workspace:*
version: link:../packages/core
'@univerjs/data-validation':
specifier: workspace:*
version: link:../packages/data-validation
- '@univerjs/design':
- specifier: workspace:*
- version: link:../packages/design
'@univerjs/docs':
specifier: workspace:*
version: link:../packages/docs
'@univerjs/docs-drawing':
specifier: workspace:*
version: link:../packages/docs-drawing
- '@univerjs/docs-drawing-ui':
- specifier: workspace:*
- version: link:../packages/docs-drawing-ui
- '@univerjs/docs-hyper-link-ui':
- specifier: workspace:*
- version: link:../packages/docs-hyper-link-ui
- '@univerjs/docs-mention-ui':
- specifier: workspace:*
- version: link:../packages/docs-mention-ui
- '@univerjs/docs-thread-comment-ui':
- specifier: workspace:*
- version: link:../packages/docs-thread-comment-ui
- '@univerjs/docs-ui':
- specifier: workspace:*
- version: link:../packages/docs-ui
'@univerjs/drawing':
specifier: workspace:*
version: link:../packages/drawing
- '@univerjs/drawing-ui':
- specifier: workspace:*
- version: link:../packages/drawing-ui
'@univerjs/engine-formula':
specifier: workspace:*
version: link:../packages/engine-formula
'@univerjs/engine-render':
specifier: workspace:*
version: link:../packages/engine-render
- '@univerjs/facade':
- specifier: workspace:*
- version: link:../packages/facade
- '@univerjs/find-replace':
- specifier: workspace:*
- version: link:../packages/find-replace
- '@univerjs/icons':
- specifier: ^0.1.78
'@univerjs/rpc':
specifier: workspace:*
version: link:../packages/rpc
@@ -481,96 +448,100 @@ importers:
'@univerjs/sheets-conditional-formatting':
specifier: workspace:*
version: link:../packages/sheets-conditional-formatting
- '@univerjs/sheets-conditional-formatting-ui':
- specifier: workspace:*
- version: link:../packages/sheets-conditional-formatting-ui
- '@univerjs/sheets-crosshair-highlight':
- specifier: workspace:*
- version: link:../packages/sheets-crosshair-highlight
'@univerjs/sheets-data-validation':
specifier: workspace:*
version: link:../packages/sheets-data-validation
'@univerjs/sheets-drawing':
specifier: workspace:*
version: link:../packages/sheets-drawing
- '@univerjs/sheets-drawing-ui':
- specifier: workspace:*
- version: link:../packages/sheets-drawing-ui
'@univerjs/sheets-filter':
specifier: workspace:*
version: link:../packages/sheets-filter
- '@univerjs/sheets-filter-ui':
- specifier: workspace:*
- version: link:../packages/sheets-filter-ui
- '@univerjs/sheets-find-replace':
- specifier: workspace:*
- version: link:../packages/sheets-find-replace
'@univerjs/sheets-formula':
specifier: workspace:*
version: link:../packages/sheets-formula
'@univerjs/sheets-hyper-link':
specifier: workspace:*
version: link:../packages/sheets-hyper-link
- '@univerjs/sheets-hyper-link-ui':
- specifier: workspace:*
- version: link:../packages/sheets-hyper-link-ui
- '@univerjs/sheets-numfmt':
- specifier: workspace:*
- version: link:../packages/sheets-numfmt
'@univerjs/sheets-sort':
specifier: workspace:*
version: link:../packages/sheets-sort
- '@univerjs/sheets-sort-ui':
+ '@univerjs/thread-comment':
specifier: workspace:*
- version: link:../packages/sheets-sort-ui
- '@univerjs/sheets-thread-comment':
+ version: link:../packages/thread-comment
+ rxjs:
+ specifier: ^7.8.1
+ version: 7.8.1
+ devDependencies:
+ '@univerjs-infra/shared':
specifier: workspace:*
- version: link:../packages/sheets-thread-comment
- '@univerjs/sheets-thread-comment-base':
+ version: link:../common/shared
+ esbuild:
+ specifier: ^0.24.0
+ version: 0.24.0
+ esbuild-plugin-clean:
+ specifier: ^1.0.1
+ version: 1.0.1([email protected])
+ esbuild-plugin-copy:
+ specifier: ^2.1.1
+ version: 2.1.1([email protected])
+ minimist:
+ specifier: ^1.2.8
+ version: 1.2.8
+ typescript:
+ specifier: ^5.6.3
+ version: 5.6.3
+
+ mockdata:
+ dependencies:
+ '@univerjs/core':
specifier: workspace:*
- version: link:../packages/sheets-thread-comment-base
- '@univerjs/sheets-ui':
+ version: link:../packages/core
+ '@univerjs/data-validation':
specifier: workspace:*
- version: link:../packages/sheets-ui
- '@univerjs/sheets-zen-editor':
+ version: link:../packages/data-validation
+ '@univerjs/docs':
specifier: workspace:*
- version: link:../packages/sheets-zen-editor
- '@univerjs/slides':
+ version: link:../packages/docs
+ '@univerjs/docs-drawing':
specifier: workspace:*
- version: link:../packages/slides
- '@univerjs/slides-ui':
+ version: link:../packages/docs-drawing
+ '@univerjs/drawing':
specifier: workspace:*
- version: link:../packages/slides-ui
- '@univerjs/thread-comment':
+ version: link:../packages/drawing
+ '@univerjs/engine-render':
specifier: workspace:*
- version: link:../packages/thread-comment
- '@univerjs/thread-comment-ui':
+ version: link:../packages/engine-render
+ '@univerjs/sheets':
specifier: workspace:*
- version: link:../packages/thread-comment-ui
- '@univerjs/ui':
+ version: link:../packages/sheets
+ '@univerjs/sheets-conditional-formatting':
specifier: workspace:*
- version: link:../packages/ui
- '@univerjs/uni-docs-ui':
+ version: link:../packages/sheets-conditional-formatting
+ '@univerjs/sheets-data-validation':
specifier: workspace:*
- version: link:../packages-experimental/uni-docs-ui
- '@univerjs/uni-formula':
+ version: link:../packages/sheets-data-validation
+ '@univerjs/sheets-drawing':
specifier: workspace:*
- version: link:../packages-experimental/uni-formula
- '@univerjs/uni-formula-ui':
+ version: link:../packages/sheets-drawing
+ '@univerjs/sheets-filter':
specifier: workspace:*
- version: link:../packages-experimental/uni-formula-ui
- '@univerjs/uni-sheets-ui':
+ version: link:../packages/sheets-filter
+ '@univerjs/sheets-formula':
specifier: workspace:*
- version: link:../packages-experimental/uni-sheets-ui
- '@univerjs/uni-slides-ui':
+ version: link:../packages/sheets-formula
+ '@univerjs/sheets-hyper-link':
specifier: workspace:*
- version: link:../packages-experimental/uni-slides-ui
- '@univerjs/uniscript':
+ version: link:../packages/sheets-hyper-link
+ '@univerjs/sheets-sort':
specifier: workspace:*
- version: link:../packages/uniscript
- '@univerjs/uniui':
+ version: link:../packages/sheets-sort
+ '@univerjs/sheets-thread-comment-base':
specifier: workspace:*
- version: link:../packages-experimental/uniui
+ version: link:../packages/sheets-thread-comment-base
+ '@univerjs/thread-comment':
+ specifier: workspace:*
+ version: link:../packages/thread-comment
devDependencies:
'@univerjs-infra/shared':
specifier: workspace:*
@@ -693,6 +664,31 @@ importers:
specifier: ^2.1.2
+ packages-experimental/rpc-node:
+ dependencies:
+ '@univerjs/core':
+ specifier: workspace:*
+ version: link:../../packages/core
+ '@univerjs/rpc':
+ specifier: workspace:*
+ version: link:../../packages/rpc
+ rxjs:
+ specifier: '>=7.0.0'
+ version: 7.8.1
+ devDependencies:
+ '@univerjs-infra/shared':
+ specifier: workspace:*
+ version: link:../../common/shared
+ typescript:
+ specifier: ^5.5.4
+ version: 5.6.3
+ vite:
+ specifier: ^5.4.1
+ vitest:
+ specifier: ^2.0.5
+
packages-experimental/uni-docs-ui:
dependencies:
'@univerjs/core':
@@ -2125,9 +2121,6 @@ importers:
'@univerjs/sheets-formula':
specifier: workspace:*
version: link:../sheets-formula
- '@univerjs/sheets-numfmt':
- specifier: workspace:*
- version: link:../sheets-numfmt
clsx:
specifier: ^2.1.1
version: 2.1.1
@@ -2593,9 +2586,6 @@ importers:
'@univerjs/sheets':
specifier: workspace:*
version: link:../sheets
- '@univerjs/sheets-hyper-link':
- specifier: workspace:*
- version: 'link:'
devDependencies:
'@univerjs-infra/shared':
specifier: workspace:*
@@ -10832,7 +10822,7 @@ snapshots:
dependencies:
'@babel/runtime': 7.25.0
dependencies:
'@antfu/install-pkg': 0.4.1
'@clack/prompts': 0.7.0
@@ -10841,7 +10831,7 @@ snapshots:
'@stylistic/eslint-plugin': 2.8.0([email protected]([email protected]))([email protected])
'@typescript-eslint/parser': 8.8.1([email protected]([email protected]))([email protected])
eslint: 9.12.0([email protected])
eslint-config-flat-gitignore: 0.3.0([email protected]([email protected]))
eslint-flat-config-utils: 0.4.0
@@ -12912,7 +12902,7 @@ snapshots:
transitivePeerDependencies:
- supports-color
dependencies:
eslint: 9.12.0([email protected])
optionalDependencies:
diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml
index 785983aa7b..bc7a8af184 100644
--- a/pnpm-workspace.yaml
+++ b/pnpm-workspace.yaml
@@ -1,6 +1,7 @@
packages:
- common/*
- examples
+ - examples-node
- mockdata
- packages-experimental/*
- packages/*