Skip to content

Commit

Permalink
fix: collab
Browse files Browse the repository at this point in the history
  • Loading branch information
nusr committed Jan 12, 2025
1 parent cdbf605 commit 749335a
Show file tree
Hide file tree
Showing 94 changed files with 1,651 additions and 1,054 deletions.
2 changes: 0 additions & 2 deletions .env

This file was deleted.

7 changes: 4 additions & 3 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install Font
run: npm run install-font
- name: Build
run: |
npm i -g pnpm
pnpm i
npm run build:gh-pages
npm run build
cd demo/frontend
pnpm i
npm run build
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Upload artifact
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ jobs:
npm run type-check
npm run lint
npm run build
npm run build:gh-pages
npm run coverage
- name: Upload coverage
uses: codecov/codecov-action@v4
Expand Down
7 changes: 6 additions & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@ npm run lint
npm run type-check
npm run test
npm run build
npm run build:gh-pages
cd demo/frontend
npm run build
cd -
cd demo/backend
npm run build
cd -
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,42 @@
# Online Collaboration Excel
# 🌐 Online Collaboration Excel

[![CI](https://github.com/nusr/excel/actions/workflows/main.yml/badge.svg)](https://github.com/nusr/excel/actions/workflows/main.yml)
[![codecov](https://codecov.io/gh/nusr/excel/branch/main/graph/badge.svg?token=ZOC8RHD3Z1)](https://codecov.io/gh/nusr/excel)
![GitHub](https://img.shields.io/github/license/nusr/excel.svg)
![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/nusr/excel.svg)

[online demo](https://nusr.github.io/excel)
English | [中文](./README_zh.md)

![demo](./scripts/demo.gif)
[Online Demo](https://nusr.github.io/excel)

## Installation
![Demo](./scripts/demo.gif)

```
## 🚀 Installation

```bash
npm i --save excel-collab
```

## Examples

[Simple Example](https://stackblitz.com/edit/nusr-excel-simple)

[Custom Example](https://stackblitz.com/edit/nusr-excel-custom)
## 📚 Examples

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

## Developing
## 🛠️ Developing

```bash
git clone https://github.com/nusr/excel.git
cd excel

npm i -g pnpm
pnpm i
cd demo/frontend && pnpm i && cd -
cd demo/backend && pnpm i && cd -
npm run dev
```

## Supported Features
## Supported Features

- [x] Online Collaboration
- [x] Create File
Expand Down
127 changes: 127 additions & 0 deletions README_zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# 🌐 在线协作 Excel

[![CI](https://github.com/nusr/excel/actions/workflows/main.yml/badge.svg)](https://github.com/nusr/excel/actions/workflows/main.yml)
[![codecov](https://codecov.io/gh/nusr/excel/branch/main/graph/badge.svg?token=ZOC8RHD3Z1)](https://codecov.io/gh/nusr/excel)
![GitHub](https://img.shields.io/github/license/nusr/excel.svg)
![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/nusr/excel.svg)

[English](./README.md) | 中文

[在线演示](https://nusr.github.io/excel)

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

## 🚀 安装

```bash
npm i --save excel-collab
```

## 📚 示例

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

## 🛠️ 开发

```bash
git clone https://github.com/nusr/excel.git
cd excel

npm i -g pnpm
pnpm i
cd demo/frontend && pnpm i && cd -
cd demo/backend && pnpm i && cd -
npm run dev
```

## ✨ 支持的功能

- [x] 在线协作
- [x] 创建文件
- [x] 更改文件名
- [x] Web Worker 解析公式
- [x] OffScreenCanvas 渲染
- [x] 撤销
- [x] 重做
- [x] 复制
- [x] 剪切
- [x] 粘贴
- [x] 公式
- [x] 字体
- [x] 字号
- [x] 字体颜色
- [x] 填充颜色
- [x] 加粗
- [x] 斜体
- [x] 删除线
- [x] 下划线
- [x] 边框
- [x] 垂直对齐
- [x] 水平对齐
- [x] 文本换行
- [x] 数字格式
- [x] 自动筛选
- [x] 合并单元格
- [x] 图表
- [x] 浮动图片
- [x] 定义名称
- [x] 插入行
- [x] 插入列
- [x] 删除行
- [x] 删除列
- [x] 隐藏行
- [x] 隐藏列
- [x] 行高
- [x] 列宽
- [x] 插入工作表
- [x] 删除工作表
- [x] 重命名工作表
- [x] 隐藏工作表
- [x] 取消隐藏工作表
- [x] 导入 XLSX
- [x] 导出 XLSX
- [x] 导入 CSV
- [x] 导出 CSV
- [x] 暗黑模式
- [x] 国际化

## Supported Formulas

### Math

- [x] ABS
- [x] ACOS
- [x] ACOSH
- [x] ACOT
- [x] ACOTH
- [x] ASIN
- [x] ASINH
- [x] ATAN
- [x] ATAN2
- [x] ATANH
- [x] AVERAGE
- [x] COS
- [x] COT
- [x] EXP
- [x] INT
- [x] PI
- [x] SIN
- [x] SUM

### Text

- [x] CHAR
- [x] CODE
- [x] CONCAT
- [x] CONCATENATE
- [x] LEN
- [x] LOWER
- [x] SPLIT
- [x] T
- [x] TEXT
- [x] TRIM
- [x] UNICHAR
- [x] UNICODE
- [x] UPPER
File renamed without changes.
8 changes: 4 additions & 4 deletions server/package.json → demo/backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "server",
"main": "index.ts",
"private": true,
"scripts": {
"dev": "npx tsx ./src/index.ts",
"build": "npx tsc",
Expand All @@ -12,15 +12,15 @@
"@types/koa__cors": "^5.0.0",
"@types/koa__router": "^12.0.4",
"@types/node": "^22.10.5",
"prisma": "^6.1.0",
"prisma": "^6.2.1",
"ts-node": "^10.9.2",
"tsx": "^4.19.2",
"typescript": "^5.7.2"
"typescript": "^5.7.3"
},
"dependencies": {
"@koa/cors": "^5.0.0",
"@koa/router": "^13.1.0",
"@prisma/client": "^6.1.0",
"@prisma/client": "^6.2.1",
"koa": "^2.15.3",
"koa-body": "^6.0.1"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ CREATE TABLE "document" (
"create_time" TEXT NOT NULL,
"content" TEXT
);

INSERT INTO "document" ("id", "name", "create_time") VALUES ('184858c4-be37-41b5-af82-52689004e605', 'test name', '2025-01-10T08:17:40.106Z');
File renamed without changes.
File renamed without changes.
35 changes: 29 additions & 6 deletions server/src/route.ts → demo/backend/src/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ router.get('/', (ctx: Koa.Context) => {
})
.then(response => response.json())
.then(data => {
console.log(data)
if (data.filePath) {
const img = document.createElement('img');
img.src = data.filePath;
Expand All @@ -77,13 +76,30 @@ router.post('/upload', async (ctx: Koa.Context) => {
if (!fs.existsSync(uploadDir)) {
fs.mkdirSync(uploadDir);
}
const fileName = Date.now() + '-' + (file as any).originalFilename;
const fileName =
Date.now() +
'_' +
Math.floor(Math.random() * 1e9) +
'_' +
(file as any).originalFilename;
const filePath = path.join(uploadDir, fileName);
const stream = fs.createWriteStream(filePath);
reader.pipe(stream);
ctx.body = {
filePath: '/upload/' + encodeURIComponent(fileName),
};
return new Promise<void>((resolve, reject) => {
reader.pipe(stream);

stream.on('finish', () => {
ctx.body = {
filePath: '/upload/' + encodeURIComponent(fileName),
};
resolve();
});

stream.on('error', (err) => {
ctx.status = 500;
ctx.body = { message: err?.message, stack: err?.stack };
reject(err);
});
});
});
router.get('/upload/:fileName', (ctx: Koa.Context) => {
const fileName = ctx.params.fileName;
Expand Down Expand Up @@ -135,6 +151,13 @@ router.get('/document/:id', async (ctx: Koa.Context) => {
ctx.body = result;
});

router.get('/documents', async (ctx: Koa.Context) => {
const result = await prisma.document.findMany({
orderBy: { create_time: 'desc' },
});
ctx.body = result;
});

router.post('/sync', async (ctx: Koa.Context) => {
const { room: id, data } = ctx.request.body;
const content = data?.excel?.content;
Expand Down
Loading

0 comments on commit 749335a

Please sign in to comment.