Skip to content

Commit 6b9d0fd

Browse files
committed
doc: update README.md
1 parent 6b0d06d commit 6b9d0fd

File tree

14 files changed

+17182
-124
lines changed

14 files changed

+17182
-124
lines changed

.github/workflows/deploy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ concurrency:
1616

1717
env:
1818
VITE_DEFAULT_EXCEL_ID: ${{ vars.VITE_DEFAULT_EXCEL_ID }}
19+
ROOT_BASE_URL: ${{ vars.ROOT_BASE_URL }}
1920

2021
jobs:
2122
deploy:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ uploads
3131
dev.db
3232
dev.db-journal
3333
migrations
34+
.env.development

README.md

Lines changed: 90 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 🌐 Online Collaboration Excel
1+
# Online Collaboration Excel
22

33
[![CI](https://github.com/nusr/excel/actions/workflows/main.yml/badge.svg)](https://github.com/nusr/excel/actions/workflows/main.yml)
44
[![codecov](https://codecov.io/gh/nusr/excel/branch/main/graph/badge.svg?token=ZOC8RHD3Z1)](https://codecov.io/gh/nusr/excel)
@@ -11,19 +11,104 @@ English | [中文](./README_zh.md)
1111

1212
![Demo](./scripts/demo.gif)
1313

14-
## 🚀 Installation
14+
## Installation
1515

1616
```bash
1717
npm i --save excel-collab
1818
```
1919

20-
## 📚 Examples
20+
## Examples
2121

2222
- [Simple Example](https://stackblitz.com/edit/nusr-excel-simple)
2323
- [Custom Example](https://stackblitz.com/edit/nusr-excel-custom)
2424
- [Collaboration Example](https://stackblitz.com/edit/nusr-excel-collaboration)
2525

26-
## 🛠️ Developing
26+
## Quick Start
27+
28+
Create a React app
29+
30+
```bash
31+
npm create vite@latest my-app -- --template react-ts
32+
cd my-app
33+
npm i
34+
```
35+
36+
Install the Required Libraries
37+
38+
```bash
39+
npm i --save excel-collab comlink yjs react@latest react-dom@latest @types/react@latest @types/react-dom@latest
40+
```
41+
42+
Modify the Main File
43+
44+
```ts src/main.tsx
45+
// src/main.tsx
46+
import { createRoot } from 'react-dom/client';
47+
import { StrictMode } from 'react';
48+
import {
49+
initController,
50+
StateContext,
51+
type WorkerMethod,
52+
ExcelEditor,
53+
} from 'excel-collab';
54+
import Worker from './worker?worker';
55+
import 'excel-collab/style.css';
56+
import { wrap } from 'comlink';
57+
import * as Y from 'yjs';
58+
59+
const workerInstance = wrap<WorkerMethod>(new Worker());
60+
61+
const doc = new Y.Doc();
62+
const controller = initController({
63+
worker: workerInstance,
64+
doc,
65+
});
66+
67+
controller.addFirstSheet();
68+
69+
createRoot(document.getElementById('root')!).render(
70+
<StrictMode>
71+
<div style={{ height: '100vh' }}>
72+
<StateContext value={{ controller }}>
73+
<ExcelEditor />
74+
</StateContext>
75+
</div>
76+
</StrictMode>,
77+
);
78+
```
79+
80+
Create the Worker File
81+
82+
```ts src/worker.ts
83+
// src/worker.ts
84+
import { workerMethod } from 'excel-collab';
85+
import { expose } from 'comlink';
86+
87+
expose(workerMethod);
88+
```
89+
90+
Modify the Config File
91+
92+
```ts vite.config.ts
93+
// vite.config.ts
94+
import { defineConfig } from 'vite';
95+
import react from '@vitejs/plugin-react';
96+
97+
export default defineConfig({
98+
plugins: [react()],
99+
worker: {
100+
format: 'es',
101+
},
102+
});
103+
```
104+
105+
Start the app
106+
107+
```bash
108+
npm run dev
109+
```
110+
111+
## Local Developing
27112

28113
```bash
29114
git clone https://github.com/nusr/excel.git
@@ -36,7 +121,7 @@ cd demo/backend && pnpm i && cd -
36121
npm run dev
37122
```
38123

39-
## Supported Features
124+
## Supported Features
40125

41126
- [x] Online Collaboration
42127
- [x] Create File

README_zh.md

Lines changed: 90 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 🌐 在线协作 Excel
1+
# 在线协作 Excel
22

33
[![CI](https://github.com/nusr/excel/actions/workflows/main.yml/badge.svg)](https://github.com/nusr/excel/actions/workflows/main.yml)
44
[![codecov](https://codecov.io/gh/nusr/excel/branch/main/graph/badge.svg?token=ZOC8RHD3Z1)](https://codecov.io/gh/nusr/excel)
@@ -11,19 +11,104 @@
1111

1212
![演示](./scripts/demo.gif)
1313

14-
## 🚀 安装
14+
## 安装
1515

1616
```bash
1717
npm i --save excel-collab
1818
```
1919

20-
## 📚 示例
20+
## 示例
2121

2222
- [简单示例](https://stackblitz.com/edit/nusr-excel-simple)
2323
- [自定义示例](https://stackblitz.com/edit/nusr-excel-custom)
2424
- [协作示例](https://stackblitz.com/edit/nusr-excel-collaboration)
2525

26-
## 🛠️ 开发
26+
## 快速开始
27+
28+
创建 React 应用
29+
30+
```bash
31+
npm create vite@latest my-app -- --template react-ts
32+
cd my-app
33+
npm i
34+
```
35+
36+
安装依赖
37+
38+
```bash
39+
npm i --save excel-collab@latest comlink@latest yjs@latest react@latest react-dom@latest @types/react@latest @types/react-dom@latest
40+
```
41+
42+
修改 main.tsx 文件
43+
44+
```ts src/main.tsx
45+
// src/main.tsx
46+
import { createRoot } from 'react-dom/client';
47+
import { StrictMode } from 'react';
48+
import {
49+
initController,
50+
StateContext,
51+
type WorkerMethod,
52+
ExcelEditor,
53+
} from 'excel-collab';
54+
import Worker from './worker?worker';
55+
import 'excel-collab/style.css';
56+
import { wrap } from 'comlink';
57+
import * as Y from 'yjs';
58+
59+
const workerInstance = wrap<WorkerMethod>(new Worker());
60+
61+
const doc = new Y.Doc();
62+
const controller = initController({
63+
worker: workerInstance,
64+
doc,
65+
});
66+
67+
controller.addFirstSheet();
68+
69+
createRoot(document.getElementById('root')!).render(
70+
<StrictMode>
71+
<div style={{ height: '100vh' }}>
72+
<StateContext value={{ controller }}>
73+
<ExcelEditor />
74+
</StateContext>
75+
</div>
76+
</StrictMode>,
77+
);
78+
```
79+
80+
创建 worker.ts 文件
81+
82+
```ts src/worker.ts
83+
// src/worker.ts
84+
import { workerMethod } from 'excel-collab';
85+
import { expose } from 'comlink';
86+
87+
expose(workerMethod);
88+
```
89+
90+
修改配置文件
91+
92+
```ts vite.config.ts
93+
// vite.config.ts
94+
import { defineConfig } from 'vite';
95+
import react from '@vitejs/plugin-react';
96+
97+
export default defineConfig({
98+
plugins: [react()],
99+
worker: {
100+
format: 'es',
101+
},
102+
});
103+
```
104+
105+
启动应用
106+
107+
```bash
108+
npm run dev
109+
```
110+
111+
## 本地开发
27112

28113
```bash
29114
git clone https://github.com/nusr/excel.git
@@ -36,7 +121,7 @@ cd demo/backend && pnpm i && cd -
36121
npm run dev
37122
```
38123

39-
## 支持的功能
124+
## 支持的功能
40125

41126
- [x] 在线协作
42127
- [x] 创建文件

0 commit comments

Comments
 (0)